akhauriyash/Code-Regression huggingface dataset:
import math
n=int(input())
x=list(map(int,input().split()))
sum2 = 0
s=sum(x)
for i in x:
    sum2 += i**2

p1= math.floor(s/n)
p2= math.ceil(s/n)

ans1= sum2 -2*p1*s + n*p1**2
ans2= sum2 -2*p2*s + n*p2**2

print(min(ans1,ans2))


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

double xa1, ya1, xa2, ya2, xb1, yb1, xb2, yb2;

int main()
{
	while (cin>>xa1>>ya1>>xa2>>ya2>>xb1>>yb1>>xb2>>yb2)
	{
		if (xb2 < xa1 || xa2 < xb1 || ya2 < yb1 || yb2 < ya1)
		{
			cout << "NO" << endl;
		} else {
			cout << "YES" << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1220
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class ADiagonalString {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    string c;
	    for(int i=0; i<3; i++){
	        in >> c;
	        out << c[i];
	    }
	}
};


int main() {
	ADiagonalString solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

int main(){
   int x1, y1, x2, y2;
   std::cin >> x1 >> y1 >> x2 >> y2;

   int x3, y3, x4, y4;
   int dx, dy;
   if ((x2 >= x1) && (y2 >= y1)){
      x3 = x2 - (y2 - y1);
      y3 = y2 + (x2 - x1);
      x4 = x3 - (x2 - x1);
      y4 = y3 - (y2 - y1);
   } else if ((x1 > x2) && (y2 >= y1)){
      x3 = x2 - (y2 - y1);
      y3 = y2 - (x1 - x2);
      x4 = x3 + (x1 - x2);
      y4 = y3 - (y2 - y1);
   } else if ((x1 > x2) && (y1 > y2)){
      x3 = x2 + (y1 - y2);
      y3 = y2 - (x1 - x2);
      x4 = x3 + (x1 - x2);
      y4 = y3 + (y1 - y2);
   } else if ((x2 >= x1) && (y1 > y2)){
      x3 = x2 + (y1 - y2);
      y3 = y2 + (x2 - x1);
      x4 = x3 - (x2 - x1);
      y4 = y3 + (y1 - y2);
   }
   std::cout << x3 << " " << y3 << " " << x4 << " " << y4 << std::endl;
}



Measured memory_bytes: 256
from collections import deque
n, m, *AB = map(int, open(0).read().split())
g = [[] for _ in range(n + 1)]
s, t = AB[:2]
for a, b in zip(*[iter(AB)] * 2):
	g[a] += [b]
	g[b] += [a]
vis = [0] * (n + 1)
vis[s] = vis[t] = 1
ans = deque([s, t])
q = [s]
while q:
	cur = q.pop()
	for nxt in g[cur]:
		if not vis[nxt]:
			q += [nxt]
			vis[nxt] = 1
			ans.appendleft(nxt)
			break
q = [t]
while q:
	cur = q.pop()
	for nxt in g[cur]:
		if not vis[nxt]:
			q += [nxt]
			vis[nxt] = 1
			ans.append(nxt)
			break
print(len(ans))
print(*ans)


Measured memory_bytes: 27116
// In the name of ALlah //
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
typedef long long ll;
// tamam tarif ha inja //
//{
string s;





//}
int main()
{
    cin >> s;
    int ans = 0 , cnt = 0;
    for (int i = 0; i < s.size(); i ++){
        if (s[i] == 'R')
            cnt ++;
        else
            cnt = 0;
        ans = max (ans , cnt);
    }
    cout << ans <<endl;
     
     
    
    return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
using namespace std;
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int k; cin >> k;
  int ans = -1, num = 0;
  rep(i,k) {
    num = (num*10+7)%k;
    if(num == 0){
      ans = i+1;
      break;
    }
  }
  cout << ans;
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1000000007;
int k[100100];
int p(int A,int B){
  if(!B)return 1;
  if(B%2)return p(A,B-1)*A%mod;
  int C=p(A,B/2);
  return C*C%mod;
}
int c(int A,int B){
  if(A<B)return 0;
  return k[A]*p(k[A-B]*k[B]%mod,mod-2)%mod;
}
signed main(){
  k[0]=1;
  for(int i=1;i<=100000;i++)k[i]=k[i-1]*i%mod;
  int N,K;
  cin>>N>>K;
  vector<int> A(N);
  for(int &i:A)cin>>i;
  sort(A.begin(),A.end());
  int ans=0;
  for(int i=0;i<N;i++)ans=(ans+A[i]*((c(i,K-1)-c(N-i-1,K-1)+mod)%mod)%mod+mod)%mod;
  cout<<ans<<endl;
}

Measured memory_bytes: 4772
#include <bits/stdc++.h>

#define rep(i, n) for(int (i) = 0; i < (n); ++(i))

typedef long long ll;
const ll MOD = 1e9 + 7;

struct Sieve {
  int n;
  std::vector<int> f, primes;
  Sieve(int n = 1):n(n), f(n + 1) {
    f[0] = f[1] = -1;
    for(ll i = 2; i <= n; ++i) {
      if(f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for(ll j = i * i; j <= n; j += i) {
        if(!f[j]) f[j] = i;
      }
    }
  }

  bool isPrime(int x) {
    return f[x] == x;
  }
  std::vector<int> factorList(int x) {
    std::vector<int> res;
    while(x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }

  std::vector<std::pair<int, int>> factor(int x) {
    std::vector<int> fl = factorList(x);

    if(fl.size() == 0) return {};
    std::vector<std::pair<int, int>> res(1, std::make_pair(fl[0], 0));
    for(int p : fl) {
      if(res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

ll modpow(ll a, ll n) {
  ll ret = 1LL;
  while(n > 0) {
    if(n & 1) ret = a * ret % MOD;
    a = a * a % MOD;
    n >>= 1;
  }

  return ret;
}

ll modinv(ll a) {
    ll b = MOD, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; std::swap(a, b);
        u -= t * v; std::swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;

    return u;
}

int main() {
  Sieve sieve(1e6);

  int N;
  std::cin >> N;
  std::vector<ll> A(N);
  rep(i, N) {
    std::cin >> A[i];
  }

  std::map<int, int> mp;
  rep(i, N) {
    auto f = sieve.factor(A[i]);
    for(auto p : f) {
      mp[p.first] = std::max(mp[p.first], p.second);
    }
  }

  ll L = 1;
  for(auto p : mp) {
    rep(i, p.second) {
      L *= p.first;
      L %= MOD;
    }
  }

  ll ans = 0;
  rep(i, N) {
    ll B = (L * modinv(A[i])) % MOD;
    ans += B;
    ans %= MOD;
  }

  std::cout << ans << '\n';
}


Measured memory_bytes: 4984
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  string s;
  cin>>s;
  s[3]='8';
  cout<<s<<endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
V = list(map(int,input().split()))
A = []
B = []
for i in range(n):
    if i%2==0:
        A.append(V[i])
    else:
        B.append(V[i])
from collections import Counter
NA = len(A)
NB = len(B)
Ac = dict(Counter(A))
Bc = dict(Counter(B))
Am = max(Ac.values())
Ak = max(Ac, key=Ac.get)
Bm = max(Bc.values())
Bk = max(Bc, key=Bc.get)
if len(Ac.keys())==1 and len(Bc.keys())==1 and A[0]==B[0]:
    print(NB)
else:
    if Ak!=Bk:
        print(NA-Am+NB-Bm)
    else:
        Ac[Ak] = 0
        Bc[Bk] = 0
        Am2 = max(Ac.values())
        Ak2 = max(Ac, key=Ac.get)
        Bm2 = max(Bc.values())
        Bk2 = max(Bc, key=Bc.get)
        print(min(NA-Am2+NB-Bm,NA-Am+NB-Bm2))

Measured memory_bytes: 67692
#include <bits/stdc++.h>
using namespace std;

int main() {

int n,m;
cin>>n>>m;
vector<int> high(n);
for(int i=0;i<n;i++){
    cin>>high[i];
}
vector<int> vec(n,0);
for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    int x,y;
    x=high[a-1];
    y=high[b-1];
    if(x<y){
        vec[a-1]++;
    }
    else if(x==y){
        vec[a-1]++;
        vec[b-1]++;
    }
    else{
        vec[b-1]++;
    }
}
int count=0;
for(int i=0;i<n;i++){
   if(vec[i]==0){
       count++;
   }
}
cout<<count<<endl;

}


Measured memory_bytes: 3988
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		System.out.println(a < b && b < c ? "Yes" : "No" );
		sc.close();
	}
}


Measured memory_bytes: 26140
/*
    
*/
#include<bits/stdc++.h>
using namespace std;
#define CoDeFoRcEs_and_ChIlL ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
#define fl(i,a,b) for(ll i=a;i<b;i++)
#define rfl(i,a,b) for(ll i=a;i>b;i--)
#define pb push_back
#define mp make_pair
#define test ll t;cin>>t;while(t--)
#define lld long double
#define vpp vector<pair<ll,ll>>
#define pii pair<ll,ll>
#define ff first
#define ss second
#define endl '\n'
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
const ll M =1000000007;
const double pi  =acos(-1);
const int N = 2e5 + 10;
int main()
{  
    CoDeFoRcEs_and_ChIlL;
    ll s,w;
    cin>>s>>w;
    if(w>=s)cout<<"unsafe";
    else cout<<"safe";
} 

Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <memory.h>
#include <algorithm>
#define case        printf("Case %d: ",++tc);
#define read        freopen("tst.txt","r",stdin)
#define write       freopen("out.txt","w",stdout)
typedef long long ll;
using namespace std;
#define pi acos(-1)
#define mx 100001
ll ar[4][mx];
ll n;
ll dp[mx][4];
ll fn(ll pos,ll id){
    if(pos==n)  return 0;

    ll &ans = dp[pos][id];
    if(ans!=-1) return ans;
    ans = 0;
    for(ll i = 0; i<3; i++){
        if(i==id)   continue;
        ll x = ar[i][pos];
        ans = max(ans,x+fn(pos+1,i));
    }
    return ans;
}

int main(){
int t,tc = 0;
scanf("%lld",&n);
memset(dp,-1,sizeof dp);
for(ll i = 0; i<n; i++){
    for(ll j = 0; j<3; j++) scanf("%lld",&ar[j][i]);
}

ll ans = fn(0,3);
printf("%lld\n",ans);

return 0;
}


Measured memory_bytes: 14208
import sys
import math
import heapq
from collections import defaultdict, deque
from decimal import *
def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

l,r,d=rm()
cnt=0
for i in range(l,r+1):
    if i%d==0:
        cnt+=1
print(cnt)


Measured memory_bytes: 71044
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextLine()) {
			String s = sc.nextLine();
			if(s.equals("-"))	break;
			int m = Integer.parseInt(sc.nextLine());
			for(int i=0; i < m; i++) {
				int h = Integer.parseInt(sc.nextLine());
				String head = s.substring(0, h);
				String tail = s.substring(h);
				s = tail + head;
			}
			System.out.printf("%s\n", s);
		}
	}
}



Measured memory_bytes: 26656
#include<bits/stdc++.h>
using namespace std;

typedef long long LL;

int n,a;
int li[55];

LL memo[55][3005][55];

LL dp(int id, int sisa, int buang){
	if(sisa < 0) return 0;
	if(sisa == 0 && buang == 0) return 1LL;
	if(buang == 0 || sisa == 0) return 0LL;
	if(id > n) return 0LL;
	LL &ret = memo[id][sisa][buang];
	if(ret!=-1) return ret;
	ret = dp(id+1,sisa-li[id],buang-1)+dp(id+1,sisa,buang);
	return ret;
}

int main(){
	memset(memo,-1,sizeof(memo));
	cin >> n >> a;
	int tot = 0;
	for(int i=1;i<=n;i++) cin >> li[i], tot+=li[i];
	LL ans = 0LL;
	for(int i=0;i<n;i++){
		int mau = (n-i)*a;
		int sisa = tot-mau;
		ans += dp(1,sisa,i);
	}
//	cout << sisa << endl;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 71296
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()

int main() {
    int h,w,a,b;
    cin>>h>>w>>a>>b;
    if(h%a==0&&w%b==0){
        cout<<"No";
        return 0;
    }
    cout<<"Yes"<<endl;
    if(w%b){
        rep(i,h){
            rep(j,w){
                if(j%b==0)cout<<(b-1)*10000-1<<' ';
                else cout<<-10000<<' ';
            }
            cout<<endl;
        }
    }
    else{
        rep(i,h){
            rep(j,w){
                if(i%a==0)cout<<(a-1)*10000-1<<' ';
                else cout<<-10000<<' ';
            }
            cout<<endl;
        }
    }
	return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5;
int n,m,u,v,cnt=0,tmp=0,ans,s[maxn],du[maxn];
bool flag=true,vis[maxn],p[maxn];
vector <int> to[maxn];
queue <int> q;
int Go_tree(int now,int fa,int opt){
	int siz=to[now].size(),sum=opt;
	for(int i=0;i<siz;i++){
		if(to[now][i]==fa) continue;
		sum+=Go_tree(to[now][i],now,-opt);
	}
	ans+=abs(sum);
	return sum;
}
void Tree(){flag=(Go_tree(1,0,1)==0);}
void tp_sort(){
	for(int i=1;i<=n;i++){if(du[i]==1) q.push(i);}
	while(!q.empty()){
		int now=q.front(),siz;q.pop();
		vis[now]=true;siz=to[now].size();
		for(int i=0;i<siz;i++){
			du[to[now][i]]-=1;
			if(du[to[now][i]]==1){q.push(to[now][i]);}
		}
	}
}
int dfs0(int now,int fa,int opt){
	int siz=to[now].size(),sum=opt;
	for(int i=0;i<siz;i++){
		if(to[now][i]==fa||to[now][i]==u||(now==u&&to[now][i]==v)) continue;
		sum+=dfs0(to[now][i],now,-opt);
	}
	p[fa]|=p[now];
	if(p[now]==false){ans+=abs(sum);}
	if(p[now]==true){s[++tmp]=sum;}
	return sum;
}
int dfs1(int now,int fa,int opt){
	int siz=to[now].size(),sum=opt;
	for(int i=0;i<siz;i++){
		if(to[now][i]==fa||to[now][i]==u||(now==u&&to[now][i]==v)) continue;
		sum+=dfs1(to[now][i],now,-opt);
	}
	return sum;
}
int dfs2(int now,int fa,int opt){
	int siz=to[now].size(),sum=opt;
	if(now==u||now==v){sum+=(-tmp/2);}
	for(int i=0;i<siz;i++){
		if(to[now][i]==fa||to[now][i]==u||(now==u&&to[now][i]==v)) continue;
		sum+=dfs2(to[now][i],now,-opt);
	}
	ans+=abs(sum);
	return sum;
}
void Cir_tree(){
	tp_sort();
	for(int i=1;i<=n;i++){if(!vis[i]) u=i,cnt++;}
	int siz=to[u].size();
	for(int i=0;i<siz;i++){if(!vis[to[u][i]]) v=to[u][i];}
	switch(cnt%2){
		case 0:{
			p[v]=true;
			flag=(dfs0(u,0,1)==0);
			sort(s+1,s+tmp+1);
			for(int i=1;i<=tmp;i++){ans+=abs(s[i]-s[tmp/2]);}
			break;
		}
		case 1:{
			tmp=dfs1(u,0,1);
			ans=abs(tmp)/2;
			flag=(dfs2(u,0,1)==0);
			break;
		}
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%d%d",&u,&v);
		du[u]++;du[v]++;
		to[u].push_back(v);
		to[v].push_back(u);
	}
	if(m==(n-1)){ans=0;Tree();}
	if(m==n){ans=0;Cir_tree();}
	if(flag){printf("%d\n",ans);}
	else{printf("-1\n");}
	return 0;
}

Measured memory_bytes: 17408
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,a,b,c,d;
  cin>>n;
  a=n/1000;
  b=n%1000/100;
  c=n%100/10;
  d=n%10;
  if (((a==b) && (b==c)) || ((b==c) && (c==d))) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
void read(int &a){
	a=0;
	char c=getchar();
	while(c<'0'||c>'9'){
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		a=(a<<1)+(a<<3)+(c^48);
		c=getchar();
	}
}
const int Maxn=100000;
int n;
int head[Maxn+5],arrive[Maxn<<1|5],nxt[Maxn<<1|5],tot;
void add_edge(int from,int to){
	arrive[++tot]=to;
	nxt[tot]=head[from];
	head[from]=tot;
}
int sg[Maxn+5];
void dfs(int u,int fa){
	for(int i=head[u];i;i=nxt[i]){
		int v=arrive[i];
		if(v==fa){
			continue;
		}
		dfs(v,u);
		sg[u]^=(sg[v]+1);
	}
}
int main(){
	read(n);
	for(int i=1;i<n;i++){
		int u,v;
		read(u),read(v);
		add_edge(u,v);
		add_edge(v,u);
	}
	dfs(1,0);
	if(sg[1]){
		puts("Alice");
	}
	else{
		puts("Bob");
	}
	return 0;
}


Measured memory_bytes: 11544
#include <iostream>
#include <vector>
#include<map>
#include<string>
#include<algorithm>
#include<sstream>
using namespace std;


int main() {
	int x;
	cin >> x;
	vector<int> a(4);
	 a[3]=x%10;
	 a[2]=(x/10)%10;
	 a[1] = (x / 100) % 10;
	 a[0] = (x / 1000) % 10;
	string st;
	int n = 3;
	for (int bit = 0; bit< (1 << n); bit++) {
		int sum = a[0];
		for (int i = 0; i < n; i++) {
			if (bit & (1 << i)) {
				sum += a[i + 1];
				st.push_back('+');
			}
			else {
				sum -= a[i + 1];
				st.push_back('-');
			}			
		}
		if (sum == 7) {
			break;
		}
		st.erase(0);
	
	}
	for (int i = 0; i < n; i++) {
		cout << a[i] << st[i];
	}
	cout << a[3] << '=' << 7;
}

Measured memory_bytes: 256
import sys
from heapq import heappush, heappop

def main():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    heap = []
    ans = 0
    for a in map(int, input().split()):
        heappush(heap, a)
        ans += a

    BC = []
    for _ in range(M):
        B, C = map(int, input().split())
        BC.append((B, C))

    BC = sorted(BC, key=lambda x: -x[1])
    for B, C in BC:
        for _ in range(B):
            a = heappop(heap)
            if a < C:
                heappush(heap, C)
                ans += C - a
            else:
                heappush(heap, a)
                break

    return ans


if __name__ == '__main__':
    print(main())



Measured memory_bytes: 74392
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int x, y, z;
  cin >> x >> y >> z;
  cout << z << " " << x << " " << y << endl;
  return 0;
}

Measured memory_bytes: 3612
h,w = map(int, input().split())
list_pic = []
for i in range(h):
    list_pic.append(list(str(input())))
ans = "Yes"
for i in range(h):
    for j in range(w):
        if list_pic[i][j] == "#":
            check = "NO"
            try:
                if list_pic[i+1][j] == "#":
                    check = "OK"
            except IndexError:
                pass
            try:
                if list_pic[i-1][j] == "#":
                    check = "OK"
            except IndexError:
                pass
            try:
                if list_pic[i][j+1] == "#":
                    check = "OK"
            except IndexError:
                pass
            try:
                if list_pic[i][j-1] == "#":
                    check = "OK"
            except IndexError:
                pass

            if check != "OK":
                ans = "No"
                break
        else:
            pass
    else:
        continue
    break

print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"
#define debug cout<<"Reached\n";

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

int main()
{    
    

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    li a,b,c,k;

    cin>>a>>b>>c>>k;

    if(k>a)
    {
        li ans=a;

        k-=a;

        if(k>b)
        {
            k-=b;

            ans-=k;

            cout<<ans;
        }
        else
        {
            cout<<ans;
        }
    }   
    else
    {
        cout<<k;
    }

    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define LL long long
#define maxn 100005
using namespace std;
typedef struct node{
  int a;
  int b;
}node;
int cmp(node n1,node n2)
{
    return n1.a<n2.a;
}
int main()
{
    int n;
    cin>>n;
    node a[n];
    for(int i=0;i<n;i++)
    {
        int k1,k2;
        cin>>k1>>k2;
        a[i].a=k1-k2;
        a[i].b=k1+k2;
    }
    sort(a,a+n,cmp);
    /*for(int i=0;i<n;i++)
    {
        cout<<a[i].a<<"  "<<a[i].b<<endl;
    }*/
    int tmp=a[0].a;
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(a[i].a>=tmp)
        {
            ans++;
            tmp=a[i].b;
        }
        else
        {
            tmp=min(tmp,a[i].b);
        }
    }
    cout<<ans;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define MOD 1000000007

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll m=1;
    cin >> n;
    for(int i=1;i<=n;i++) {
        m*=i;
        m%=MOD;
    }
    cout << m << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
typedef long long ll;
using namespace std;

ll sa[200010], wa[200010];

int main() {
	int N;
	cin >> N;
	for(int i=0; i<N; ++i){
		ll x, y;
		cin >> x >> y;
		sa[i]=x-y, wa[i]=x+y;
	}
	sort(sa, sa+N);
	sort(wa, wa+N);
	cout << max(sa[N-1]-sa[0], wa[N-1]-wa[0]) << endl;
	return 0;
}

Measured memory_bytes: 6740
N,M = gets.split.map(&:to_i)
$es = {}
M.times{
  a,b = gets.split.map(&:to_i)
  $es[a] ||= {}; $es[b] ||= {}
  $es[a][b] = $es[b][a] = 1
}

def r(a,n = 0)
  if a == N
    puts "POSSIBLE"; exit
  end
  return if n >= 2
  $es[a].keys.each{ |b|
    r(b, n+1)
  }
end

r(1)
puts "IMPOSSIBLE"

Measured memory_bytes: 85244
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define rep(i, init, n) for(int i = init; i <(int)(n); i++)

int main() {
    int N;
    cin >> N;
    vector<int> A(9, 0);
    int a;
    REP(i, N){
        cin >> a;
        a = min(a, 3200);
        a /= 400;
        A[a]++;
    }
    int ans = 0;
    REP(i, 8) if(A[i] > 0) ans++;
    if (ans == 0) {ans = 1; A[8]--;}
    cout << ans << " " << (ans + A[8]) << endl;
    

    return 0;
}


Measured memory_bytes: 256
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

TLong v[53][53];
TLong nCr(TLong n, TLong r){
	for(TLong i = 0; i <= n; ++i){
		for(TLong j = 0; j <= i; ++j){
			if(j == 0)  v[i][j] = 1;
			else  v[i][j] = v[i - 1][j - 1] + v[i - 1][j];
		}
	}
	return v[n][r];
}

int main(int argc, char const *argv[])
{
	TLong n,p,a[50];
	TLong ans = 0;
	TLong odd = 0,even = 0;
	scanf("%lld%lld",&n,&p);
	for (TLong i = 0; i < n; ++i){
		scanf("%lld",&a[i]);
		if(a[i] % 2)	++odd;
		else ++even;
	}
	for (TLong i = p; i <= odd; i += 2)
	{
		for (TLong j = 0; j <= even; ++j)	ans += nCr(odd, i) * nCr(even, j);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

N = int(input())
num = 1
mod = 10**9+7
l = [0]*(N+1)
for n in range(2,N+1):
  F = factorization(n)
  for a,b in F:
    l[a] += b
count = 1
for i in range(2,N+1):
  if l[i] != 0:
    count *= (1+l[i])
print(count%mod)

Measured memory_bytes: 3188
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000

typedef long long ll;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int K, R, L;
double P, E, T;

// 残り日数がk日で左端と右端がlの時、理想的な睡眠時間になる確率
double dfs(double r, double l, int k) {
    // 残り日数0
    if (k == 0) {
        if (abs((r+l)/2 - T) <= E) return 1;
        else return 0;
    }
    // すでに外れてたらどうしようもない
    if (l + E < T || r - E > T) return 0;
    // ちゃんとやる
    double TT = (r+l) / 2;
    if (TT > T) {
        return (1.0-P) * dfs(r, (r+l)/2, k-1) + P * dfs((r+l)/2, l, k-1);
    } else {
        return P * dfs(r, (r+l)/2, k-1) + (1.0-P) * dfs((r+l)/2, l, k-1);
    }
}

int main(void) {
    cin >> K >> R >> L;
    cin >> P >> E >> T;
    printf("%.15f\n", dfs(R, L, K));
    return 0;
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
using namespace std;


#define LL long long

int main(){
  int n; cin >> n;
  vector<int> v(n);
  for(int i=0; i<n; i++){
    int a; cin >> v[i];
  }
  LL int min = *min_element(v.begin(), v.end());
  LL int max = *max_element(v.begin(), v.end());
  LL int sum = accumulate(v.begin(), v.end(), 0LL);

  cout << min << " " << max << " " << sum <<endl;
 
  return 0;
}

Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;

//#define Fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
typedef vector<int>Vl;
typedef pair<int,int>PII;
typedef vector<PII>Vll;
typedef vector<pair<int,pair<int,int> > >Vlll;
typedef priority_queue<int>PQL;
typedef map<int,int>MP;
#define S second
#define F first
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define sl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)
const int mod=1e9+7;
const int sze=1e5+2;
signed main(){
  int n;
  sl(n);
  int p[n+1];
  for(int i=1;i<=n;i++)sl(p[i]);
  int cnt=0;
  int min_so=mod;
  for(int i=1;i<=n;i++){
	  if(p[i]<=min_so)cnt++;
	  min_so=min(min_so,p[i]);  
   }
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long int n, a, b, c, d, e, k;
  cin >> n >> a >> b >> c >> d >> e;
  k = min({a,b,c,d,e});
  
  cout << (n+(k-1))/k + 4;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(void) {
  int N, X;
  cin >> N >> X;

  int lastTime = 0;
  int count = 1, L;

  for(int i = 0; i < N; i++) {
    cin >> L;
    if(lastTime + L <= X) {
      count += 1;
      lastTime = L + lastTime;
    } else {
      break;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>

using namespace std;

const int N     =   100005  ;

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    string s; cin >> s      ;
    int n   ; n = s.size()  ;
    s = ' '  + s;
    int ans[N], pos = 1;
    memset(ans, 0, sizeof ans);
    for (int i = pos; i <= n - 1; i++) {
        if (s[i] != 'R' || s[i + 1] != 'L') continue;
        int r = i, l = i + 1, R = i, L = i + 1, ansA = 1, ansB = 1;

        while (R && s[R - 1] == 'R') {
            --R;
            if ((i - R) % 2) ansB++;
            else ansA++;
        }
        while (L <= n && s[L + 1] == 'L') {
            ++L;
            if ((L - i - 1) % 2) ansA++;
            else ansB++;
        }
        ans[i] = ansA;
        ans[i + 1] = ansB;
        i = L;
    }
    for (int i = 1; i <= n; i++) cout << ans[i] << ' ';
    return 0;
}


Measured memory_bytes: 1024
//abc129_d.cpp
//Sun Sep 22 08:12:59 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int h,w;
	cin >> h >> w;

	string s[h];
	for (int i=0;i<h;i++){
		cin >> s[i];
	}

	int l[h][w];
	for (int i=0;i<h;i++){
		for (int j=0;j<w;j++){
			if (s[i][j]=='#'){
				l[i][j] = 0;
			}else if (j==0){
				l[i][j] = 1;
			}else {
				l[i][j] = l[i][j-1]+1;
			}
		}
	}

	int r[h][w];
	for (int i=0;i<h;i++){
		for (int j=w-1;j>=0;j--){
			if (s[i][j]=='#'){
				r[i][j] = 0;
			}else if (j==w-1){
				r[i][j] = 1;
			}else {
				r[i][j] = r[i][j+1]+1;
			}
		}
	}

	int u[h][w];
	for (int j=0;j<w;j++){
		for (int i=0;i<h;i++){
			if (s[i][j]=='#'){
				u[i][j] = 0;
			}else if (i==0){
				u[i][j] = 1;
			}else {
				u[i][j] = u[i-1][j]+1;
			}
		}
	}

	int d[h][w];
	for (int j=0;j<w;j++){
		for (int i=h-1;i>=0;i--){
			if (s[i][j]=='#'){
				d[i][j] = 0;
			}else if (i==h-1){
				d[i][j] = 1;
			}else {
				d[i][j] = d[i+1][j]+1;
			}
		}
	}

	int ans = 0;
	for (int i=0;i<h;i++){
		for (int j=0;j<w;j++){
			ans = max(ans, u[i][j]+d[i][j]+l[i][j]+r[i][j]-3);
		}
	}

	cout << ans << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 66816
input_line = input()
data = input_line.split(" ")
x = abs(int(data[0]))
k = int(data[1])
d = int(data[2])
a = x // d
b = x % d
res = abs(a)
if res >= k :
  ans = x - k * d
else :
  num = k - res
  if num % 2 == 1 :
    ans = abs(b - d)
  else :
    ans = b
print(ans)

Measured memory_bytes: 9228
N, M = map(int, input().split())

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 998244353
n = 10**6*3
g1 = [1, 1]
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, n + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans = cmb(M*3+N-1, N-1, mod)
for i in range(M*2+1, M*3+1):
    ans -= cmb(M*3-i+(N-1)-1, N-2, mod) * N - mod*mod
    ans = (ans+mod)%mod

for i in range(M+1, min(N, 3*M)+1):
    if (3*M - i) % 2 == 0:
        two = (3*M - i) // 2
        ans -= cmb(two+N-1, N-1, mod) * cmb(N, i, mod) - mod*mod
        ans = (ans+mod)%mod
print(ans)


Measured memory_bytes: 172696
#include<stdio.h>
#include<iostream>
using namespace std;
int main(void){
	int n=0;
	int x=0,a[100]={0};
	int y=0,b[100]={0};
	int z=0,c[100]={0};
	bool count[101]={};
	int cnt=0;
	cin>>n;
	cin>>x;
	for(int i=0;i<x;i++){
		cin>>a[i];
	}
	cin>>y;
	for(int i=0;i<y;i++){
		cin>>b[i];
	}
	cin>>z;
	for(int i=0;i<z;i++){
		cin>>c[i];
	}
	if(x<1){
		x=1;
	}
	if(y<1){
		y=1;
	}
	//finished input. 
	for(int k=0;k<z;k++){
		for(int j=0;j<y;j++){	
			for(int i=0;i<x;i++){
				if(((c[k]!=b[j])&&(c[k]==a[i]))||count[c[k]]){
					break;
				}
				if(i==x-1){
					count[c[k]]=true;
					cnt++;
				}
			}
		}
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 3096
if __name__ == '__main__':
    N = int(input())
    a_list = list(map(int, input().split()))

    a_list = sorted(a_list, reverse=True)

    answer = 0
    for i in range(len(a_list)):
        if i % 2 == 0:
            if i + 1 <= len(a_list) - 1:
                answer += a_list[i] - a_list[i+1]
            else:
                answer += a_list[i]

    print(answer)


Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
vector<int> g[100002];
bool used[100002];
int ct;
void dfs(int x){
	used[x]=1;
	for(auto y:g[x]){
		if(!used[y]) dfs(y);
	}
}
int main()
{
	int n; cin>>n;
	int a[100002], b[100002], as[100002], bs[100002], s=0;
	map<int, int> mp;
	for(int i=0; i<n; i++){
		cin>>a[i]; as[i]=a[i];
		s^=a[i];
	}
	as[n]=a[n]=s;
	sort(as, as+n+1);
	s=0;
	int ans=0;
	for(int i=0; i<n; i++){
		cin>>b[i]; bs[i]=b[i];
		s^=b[i];
		if(a[i]!=b[i]) mp[b[i]]=0, ans++;
	}
	bs[n]=b[n]=s;
	mp[a[n]]=mp[b[n]]=0;
	sort(bs, bs+n+1);
	for(int i=0; i<=n; i++){
		if(as[i]!=bs[i]){
			cout<<-1<<endl;
			return 0;
		}
	}
	int c=0;
	for(auto& p:mp){
		p.second=c; c++;
	}
	for(int i=0; i<n; i++){
		int x=mp[a[i]], y=mp[b[i]];
		g[x].push_back(y); g[y].push_back(x);
	}
	for(int i=0; i<c; i++){
		if(!used[i]){
			dfs(i); ct++;
		}
	}
	ans+=(ct-1);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 15232
<?php
  fscanf(STDIN,"%d%d%d%d", $a,$b,$h,$m);
  
  $arg1 = 6*$m;
  $arg2 = (30*$h)+(0.5*$m);
  //echo $arg1."\n".$arg2."\n";

  if($arg1 != $arg2){
    $arg = abs($arg1 - $arg2);
    //echo $arg."\n";
    if($arg > 180){
      $arg = 360 - $arg;;
      //echo $arg."\n";
    }else if($arg == 180){
      echo $a+$b;
      exit;
    }
    $dis2 = ($a*$a)+($b*$b)-(2*$a*$b*cos(deg2rad($arg)));
    echo sqrt($dis2);
  }else{
    echo abs($a-$b);
  }

Measured memory_bytes: 16388
#include <bits/stdc++.h>
using namespace std;

int main() {
    string n; cin >> n;
    
    bool flg = 1;
    if (n[0] == '1') {
        for (int i = 1; i < n.size(); i++) {
            if (n[i] != '0') flg = 0;
        }
    }
    else flg = 0;
    
    int ans = 0;
    if (flg) cout << 10 << endl;
    else {
        for (int i = 0; i < n.size(); i++) {
            ans += (n[i] - '0');
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
# coding: utf-8
A, B, C, D = map(int, input().split())
time = [0 for i in range(100)]
for i in range(A, B):
    time[i] += 1
for i in range(C, D):
    time[i] += 1
ans = 0
for i in range(len(time)):
    if time[i] == 2:
        ans += 1
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

#define ll long long

void swap (int *x, int *y) {
  int temp;

  temp = *x;
  *x = *y;
  *y = temp;

  return;
}


long int gcd(long int a, long int b){
  long int c;

  while (b > 0){
    c = a % b;
    a = b;
    b = c;
  }

  return a;
}

int upll(const void*a, const void*b){
  return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;
}

int downll(const void*a, const void*b){
  return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;
}

void sortup(ll*a,int n){
  qsort(a,n,sizeof(ll),upll);
}

void sortdown(ll*a,int n){
  qsort(a,n,sizeof(ll),downll);
}

long int modpow(long int a,long int n,long int mod){
  long int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}

long int modinv(long int a,long int mod){
  return modpow(a,mod-2,mod);
}

int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}

int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}

void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }

  return;
}

void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }

  return;
}


int main(void){
  char s[1010];
  scanf("%s",s);
  int ncount=0,wcount=0,ecount=0,scount=0;
  int l=strlen(s);
  for(int i=0;i<l;i++){
    if(s[i]=='N'){
      ncount++;
    }
    if(s[i]=='S'){
      scount++;
    }
    if(s[i]=='E'){
      ecount++;
    }
    if(s[i]=='W'){
      wcount++;
    }
  }
  if((ecount!=0&&wcount==0)||(ecount==0&&wcount!=0)||(ncount!=0&&scount==0)||(ncount==0&&scount!=0)){
    printf("No\n");
  }else{
    printf("Yes\n");
  }
  return 0;
}

Measured memory_bytes: 1616
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}

//-----------------------ここから-----------

int main(void){
    vector<int> a(3);
    for(int i = 0; i < 3; i++) cin >> a[i];
    sort(a.begin(), a.end());

    do{
        if(a[0] == 5 && a[1] == 7 && a[2] == 5){
            cout << "YES" << endl;
            return 0;
        }
    } while(next_permutation(a.begin(), a.end())); 

    cout << "NO" << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> graph[55];
bool used[55];
vector<vector<int>> comps;
int x = 0, y = 0;
void dfs(int v) {
    used[v] = true;
    comps.back().push_back(v);

    for (int u: graph[v]) {
    	if (v == x && u == y) continue;
        if (!used[u]) {
            dfs(u);
        }
    }
}
int main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		--u, --v;
		graph[u].push_back(v);
		graph[v].push_back(u);
	}
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		for (auto f : graph[i]) {
			comps.clear();
			x = i;
			y = f;
			for (int i = 0; i < n; i++) {
				used[i] = false;
			}
			for (int i = 0; i < n; i++) {
        		if (!used[i]) {
            		comps.push_back(vector<int>());   //добавляем в comps новый пустой вектор,
            		dfs(i);
        		}
    		}
    		if (comps.size() > 1) {
    			cnt++;
    		}
		}
	}
	cout << cnt;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl
#define Vecpr(K,L1,L2,N) vector<pair<L1,L2>> K(N)
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,R) vector<vector<L>> K(N, vector<L>(M,R))
#define pint pair<int,int>
#define Lower(v,X) lower_bound(v.begin(),v.end(),X)-v.begin();
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main(){
   lli A,B,C,L,R,N,M,K,X=0,Y=0,W,H=INF,sum=0,num=0,flag=0;string S,T,O;
   cin >> N;
   Vec(P,int,N,0);
   Vec(Q,int,N,0);
   rep(i,0,N){
      cin >> P[i];
      Q[i]=P[i];
   }
   Sort(Q);
   K=N/2-1;
   rep(i,0,N){
      if(P[i]<=Q[K])Out(Q[K+1]);
      else Out(Q[K]);
   }
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define ll long long
#define MAX_N 51
using namespace std;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    string ss;
    cin>>ss;
    ll n = ss.length();
    int dp[33][n+100];
    int ans[n+100];
    for(int i = 0; i<n; ++i){
        char sss = ss[i];
        if(sss == 'R') dp[0][i] = i+1;
        else dp[0][i] = i-1;
    }
    for(int p =0; p<32; ++p){
        for(int i= 0; i<=n; i++){
            dp[p+1][i] = dp[p][dp[p][i]];
        }
    }
    for(int i = 0; i<n; ++i){
        ans[dp[32][i]]++;
    }
    for(int i = 0; i<n; ++i){
        if(i) cout<<" ";
        int a = ans[i];
        cout<<a;
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 14032
import sys
from math import gcd

N = int(input())
if N == 2:
    print(1)
    sys.exit()

"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])

    return arr


factors = factorization(N)
ans = 0

# K^i
tmp = factors[0][1]
for k, i in factors:
    tmp = gcd(tmp, i)
ptn = 1
if tmp != 1:
    for k, i in factorization(tmp):
        ptn *= i+1
ans += ptn

# ak+1
ptn = 1
for k, i in factorization(N-1):
    ptn *= i+1
ptn -= 1  # k=1のときを除外
ans += ptn

# (ak+1)*k^i
ptn = 0
for f, n in factors:
    for i in range(1, n+1):
        k = f**i
        tmp = N
        while True:
            if tmp%k!=0:
                break
            tmp = tmp/k
        ptn += ((tmp-1)%k==0 and tmp!=1)
ans += ptn

print(ans)


Measured memory_bytes: 9436
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  vl A(N);
  REP(i, N) cin >> A[i];
  ll a = 0;
  ll ans = 0;
  REP(i, N) {
    if (a == 0) {
      ans += A[i] / 2;
      a = A[i] % 2;
    } else if (A[i] == 0) {
      a = 0;
    } else {
      ans += (a + A[i]) / 2;
      a = (a + A[i]) % 2;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
def main():
    N, M, V, P = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    A.sort(reverse=True)

    def is_ok(mid):
        if mid <= P-1:
            return False  # 採用可能
        if A[mid] + M < A[P-1]:
            return True  # 採用不可能
        votable = M + (P-1) * M + (N - (mid + 1))*M
        for i in range(P-1, mid):
            votable += min(M, max(0, A[mid] + M - A[i]))
        if M*V <= votable:
            return False
        else:
            return True

    def binary_search_meguru():
        left = -1
        right = N
        while right - left > 1:
            mid = left + ((right - left) // 2)
            if is_ok(mid):
                right = mid
            else:
                left = mid
        return right
    print(binary_search_meguru())


if __name__ == '__main__':
    main()


Measured memory_bytes: 62772
#include <bits/stdc++.h>

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
	ll l, r;
	cin >> l >> r;
	if (r - l >= 2019)
	{
		cout << 0;
		return;
	}
	l %= 2019LL;
	r %= 2019LL;
	if (l >= r) r += 2019LL;
	// cout << l << " " << r << endl;

	int ans = (l * r) % 2019;
	for(int i = l; i <= r - 1; ++i)
	{
		for(int j = i + 1; j <= r; ++j)
		{
			ans = min(ans, (i * j) % 2019);
		}
	}
	cout << ans;
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
const int MAX_A = 3e5 + 5;
int op(int a, int b) { return max(a, b); }
int e() { return 0; }

int main() {
	int n, k; cin >> n >> k;
	segtree<int, op, e> dp(MAX_A);
	while (n--) {
		int a; cin >> a;
		int l = max(0, a - k);
		int r = min(a + k + 1, MAX_A);
		int now = dp.prod(l, r) + 1;
		dp.set(a, now);
	}
	cout << dp.all_prod() << '\n';
	return 0;
}

Measured memory_bytes: 8480
MOD = 10**9 + 7
N = int(input())
*A, = map(int, input().split())
ans = 0
for i in range(60):
    bit_0, bit_1 = 0, 0
    for a in A:
        if (a >> i) & 1: 
            bit_1 += 1
        else:
            bit_0 += 1
    ans += bit_1 * bit_0 * pow(2, i, MOD)
    ans %= MOD
print(ans)

Measured memory_bytes: 122936
#include <iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    int p[n];
    for(int i=0; i<n; i++){
        cin >> p[i];
    }
    int ans=0;
    for(int i=1; i<n-1; i++){
        if(p[i-1] < p[i]) {
            if(p[i] <= p[i+1]) ans++;
        }
        else if(p[i-1] == p[i]) {
            if(p[i] > p[i+1]) ans++;
        }
        else {
            if(p[i] >= p[i+1]) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
def gcd(a, b)
  while a != 0
    a, b = b%a, a
  end
  return b
end

readlines.map(&:chomp).each{|l|
  a, b = l.split.map(&:to_i).sort
  gcd = gcd(a, b)
  lcm = a * b / gcd
  puts [gcd, lcm].join(" ")
}

Measured memory_bytes: 8524
#include<iostream>
#include<string.h>
#include<string>
#include<cstdio>
#include<stdlib.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> pii;

int main()
{
  int a[10];
  cin>>a[0]>>a[1]>>a[2];
  sort(a,a+3);
  if(a[0]+a[1]==a[2])
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}


Measured memory_bytes: 256