akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main(){
  string S;
	cin >> S;
 
	//初期値は大きい値
	int ans = S.size();
 
	//iは最初に使う色 (0 or 1)
	for (int i = 0; i < 2; i++)
	{
		// iを最初に使った時に変えなければならないタイルの数
		int cnt = 0;
 
		for (int j = 0; j < S.size(); j++)
		{
			if ((j % 2 == 0) ^ (S[j] == (char)(i + '0'))) cnt++;
		}
 
		ans = min(ans, cnt);
	}
 
	cout << ans << endl;
}
      

      


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(void){
 int n,m;
 vector<int> v;
 cin >> n >> m;

 for(int i = 0; i < n; i++){
  int tmp;
  cin >> tmp;
  v.push_back(tmp); 
 }
  
 sort(v.begin(),v.end(),greater<int>());
 double sum = 0.0;
 for(int i = 0; i < n; i++){
	sum += v[i];
 }
 double limit = sum / (4.0 * m);
  
 for(int i = 0; i < m; i++){
   if(limit > (double)v[i]){
   cout << "No" ;
   return 0;
  }
 }
  

  
  cout << "Yes";
  return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int n;
string s[200];

signed main() {
	int i, j, k;
	
	cin >> n;
	rep(i, n) cin >> s[i];
	
	int ans = -1;
	rep(i, n) {
		queue<int> que;
		int dist[200];
		rep(j, n) dist[j] = -1;
		
		que.push(i);
		dist[i] = 0;
		while (!que.empty()) {
			int v = que.front(); que.pop();
			rep(j, n) {
				if (s[v][j] == '1' && dist[j] == -1) {
					dist[j] = dist[v] + 1;
					que.push(j);
				}
			}
		}
		
		rep(j, n) {
			for (k = j + 1; k < n; k++) {
				if (s[j][k] == '0') continue;
				if (abs(dist[j] - dist[k]) != 1) break;
			}
			if (k < n) break;
		}
		if (j == n) {
			int res = 0;
			rep(k, n) res = max(res, dist[k]);
			ans = max(ans, res + 1);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

const int maxn = 510;
int mat[maxn][maxn];

int main()
{
	int H,W,h,w;
	scanf("%d%d%d%d",&H,&W,&h,&w);
	int x = 1500;
	for (int i=1;i<=H;i++)
	{
		for (int j=1;j<=W;j++)
		{
			if (i%h==0 && j%w==0) 
			{
				mat[i][j] = -x-1;
				mat[i-h+1][j-w+1] = x;
			}
		}
	}
	if (H % h == 0 && W % w ==0)
	{
		puts("No");
		return 0;
	}
	else
	{
		if (H%h!=0)
		{
			for (int i=1;i<=W;i++)
			{
				if (i % w == 0) mat[H][i] = x;
			}
		}
		if (W%w!=0)
		{
			for (int i=1;i<=H;i++)
				if (i % h== 0) mat[i-h+1][W] = x;
		}
		puts("Yes");
		for (int i=1;i<=H;i++)
		{
			for (int j=1;j<=W;j++) printf("%d ",mat[i][j]);
			printf("\n");
		}
	}
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
int main() {
    char c;
    cin >> c;
    cout << (char)(c + 1) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

const int MAX_N = 1e5 + 5, BLACK = 0, WHITE = 1, MOD = 1e9 + 7;
vector <int> tree[MAX_N];
long long no_of_ways[MAX_N][2];

long long dfs_count(int parent, int v, int colour)
{
    if(no_of_ways[v][colour] != -1)
    {
        return no_of_ways[v][colour];
    }

    no_of_ways[v][colour] = 1;

    for(int i = 0; i < tree[v].size(); i++)
    {
        int child = tree[v][i];

        if(child == parent) continue;

        long long no_of_subtrees = 1;

        if(colour == BLACK)
        {
            no_of_subtrees = dfs_count(v, child, WHITE);
        }
        else if(colour == WHITE)
        {
            no_of_subtrees = (dfs_count(v, child, BLACK) + dfs_count(v, child, WHITE))%MOD;
        }

        no_of_ways[v][colour] = (no_of_ways[v][colour]*no_of_subtrees)%MOD;
    }

    return no_of_ways[v][colour];
}

int main()
{
    int no_of_vertices;
    cin >> no_of_vertices;

    for(int i = 1; i <= no_of_vertices - 1; i++)
    {
        int x, y;
        cin >> x >> y;

        tree[x].push_back(y);
        tree[y].push_back(x);
    }

    memset(no_of_ways, -1, sizeof(no_of_ways));

    long long answer = (dfs_count(0, 1, BLACK) + dfs_count(0, 1, WHITE))%MOD;

    cout << answer;
    return 0;
}

Measured memory_bytes: 18804
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;
const int INF=1e9;
using namespace std;

int main(){
    string s;
    cin>>s;
    int ans=700;
    for(int i=0; i<3; i++){
        if(s[i]=='o') ans+=100;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD (1000000)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;

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

}
LL exp(int a, int b){
    LL res = 1;
    LL sum = a;
    while(b){
        if(b&1)res = (res * sum) % MOD;
        sum = (sum * sum) % MOD;
        b>>=1;
    }
    return res;
}

vector<vector<vector<int> > > dp;
int N, M;

int func(int p, int h, int up){
    if(p == N){
        if(h == 2)return 1;
        if(h == 1)return 1;
        if(h == 0)return p - up;
    }
    if(up >= 0){
        if(dp[p][up][h]>=0)return dp[p][up][h];
    }
    int res = 0;
    if(h == 0){
        res = func(p+1, 1, p+1);
        res = (res + (p - up) * func(p+1, 2, p)) % MOD;
        res = (res + func(p+1, 0, up)) % MOD;
    }else if(h == 1){
        res = (func(p+1, 0, p) + func(p+1, 2, p) + func(p+1, 1, p+1)) % MOD;
    }else{
        res = func(p+1, 1, p+1);
        res = (res + (p - up) * func(p+1, 0, p)) % MOD;
        res = (res + func(p+1, 2, up)) % MOD;
    }
    if(up<0)return res;
    return dp[p][up][h] = res;
}

int main(){
    cin >> N >> M;
    if(M == 1){
        cout << exp(2, N) << endl;
    }else{
        dp.resize(N, vector<vector<int> >(N, vector<int>(3, -1)));
        cout << func(0, 0, -1) << endl;
    }
    return 0;
}



Measured memory_bytes: 3688
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
	string s;
	cin>>s;
	int a=0,b=0,c=0;
	rep(i,3){
	    if(s[i]=='a')a++;
	    else if(s[i]=='b')b++;
	    else c++;
	}
	if(a*b*c)cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    int n;
    cin>>n;

    int ar[n+1]={0};

    for(int i=1;i<=n;i++)
    {
        int a,b;
        cin>>a>>b;

        if(a==b)
        {
            ar[i]=1;
            ar[i]+=ar[i-1];
            if(ar[i]==3)
            {
                cout<<"Yes\n";
                return 0;
            }
        }
    }
    cout<<"No";
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)x.size())
using namespace std;
typedef long long ll;

int n,m;
map<int,int> w;

int main(){
	scanf("%d",&n);
	fore(i,0,n){
		int x;
		scanf("%d",&x);
		w[x]++;
	}
	bool r=true;
	scanf("%d",&m);
	fore(i,0,m){
		int x;
		scanf("%d",&x);
		if(!w[x])r=false;
		w[x]--;
	}
	puts(r?"YES":"NO");
	return 0;
}

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

int main(){
  string N, check;
  cin >> N;

  if(N[1] != N[2]){
    cout << "No" << endl;
  }
  else if(N[1]==N[0] || N[1]==N[3]){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;

int main(){
	int a,b;
	cin>>a>>b;
	
	double xt;
	xt=(double)(a+b)/2;
	//cout<<xt<<endl;
	
	int x;
	x=(a+b)/2;
	//cout<<x<<endl;
	
	if(x==xt)
		cout<<x<<endl;
	else
		cout<<x+1<<endl;
	
	return 0;
	
	
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define ll          long long
#define ld          long double
#define pb          push_back
#define pf          push_front
#define mp          make_pair
#define pll         pair<ll,ll>
#define vl          vector<ll>
#define sl          set<ll> 
#define vll         vector<pll>
#define ml          map<ll,ll>
#define mll         map<pll,ll>
#define all(a)      a.begin(),a.end()
#define x           first
#define y           second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define mod         (ll)1000000007
#define lp(i,a,b)   for(ll i=a;i<b;++i)
#define lpr(i,a,b)  for(ll i=a;i>=b;i--)
#define lpd(i,x)    for(auto i:x)
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll inf = (ll)1e18;
ld pi = 3.141592653589;
using namespace std;

ll bpow(ll x, ll v) {	
	if (v == 0)
		return 1 % mod;
	if (v % 2 == 1)
		return (x * bpow(x, v - 1)) % mod;
	ll r = bpow(x, v / 2);
	return (r * r) % mod;	
}

ll lcm(ll a,ll b)
{
	ll ret=(a*b)/__gcd(a,b);
	return ret;
} 

ll solve(){ 
	ll h,n,s=0; cin>>n>>h;
	vl a(n); lp(i,0,n) cin>>a[i];
	sort(all(a));
	lp(i,0,n-h)
	s+=a[i];
	cout<<s;
}
int main(){
    ios
    ll t=1; 
    //cin>>t;
    while(t--){
    	solve();
    }
}

Measured memory_bytes: 1792
A,B,C,D=map(int,input().split())
s=0
t=0
while A>0:
  A-=D
  s+=1
  if A<=0:
    break
while C>0:
  C-=B
  t+=1
  if C<=0:
    break
if s>=t:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9184
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  int N, M;
  cin >> N >> M;
  vector<ll> v1(N), v2(N), v3(N), v4(N), v5(N), v6(N), v7(N), v8(N);
  for(int i=0; i<N; i++){
    ll x, y, z;
    cin >> x >> y >> z;
    v1[i] = - x - y - z;    v2[i] = - x - y + z;    v3[i] = - x + y - z;    v4[i] = - x + y + z;
    v5[i] = + x - y - z;    v6[i] = + x - y + z;    v7[i] = + x + y - z;    v8[i] = + x + y + z;
  }
  sort(v1.begin(), v1.end(), greater<ll>());  sort(v2.begin(), v2.end(), greater<ll>());
  sort(v3.begin(), v3.end(), greater<ll>());  sort(v4.begin(), v4.end(), greater<ll>());
  sort(v5.begin(), v5.end(), greater<ll>());  sort(v6.begin(), v6.end(), greater<ll>());
  sort(v7.begin(), v7.end(), greater<ll>());  sort(v8.begin(), v8.end(), greater<ll>());
  ll ans = accumulate(v1.begin(), v1.begin()+M, 0LL);
  ans = max(ans, accumulate(v2.begin(), v2.begin()+M, 0LL));
  ans = max(ans, accumulate(v3.begin(), v3.begin()+M, 0LL));
  ans = max(ans, accumulate(v4.begin(), v4.begin()+M, 0LL));
  ans = max(ans, accumulate(v5.begin(), v5.begin()+M, 0LL));
  ans = max(ans, accumulate(v6.begin(), v6.begin()+M, 0LL));
  ans = max(ans, accumulate(v7.begin(), v7.begin()+M, 0LL));
  ans = max(ans, accumulate(v8.begin(), v8.begin()+M, 0LL));

  cout << ans << endl;
  return 0;
}


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

using namespace std;

#define N 100000

int t[N + 1];
int x[N + 1];
int y[N + 1];

int main(){
	int n, d, i;

	scanf("%d", &n);

	for (i = 1; i <= n; i++){
		scanf("%d%d%d", t + i, x + i, y + i);
	}

	for (i = 1; i <= n; i++){
		if (abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]) <= t[i] - t[i - 1]){
			d = (t[i] - t[i - 1]) - (abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]));

			if (d % 2){
				break;
			}
		}
		else{
			break;
		}
	}

	if (i <= n){
		printf("No\n");
	}
	else{
		printf("Yes\n");
	}

	return 0;
}

Measured memory_bytes: 1408
#include<cstdio>
#include<cstring>
using namespace std;

int main(){
    char c[1001];
    
    while(1){
        scanf("%s",c);

        if(c[0] == '0')break;
        int sum = 0;

        for(int i=0;i<strlen(c);i++){
            sum += (c[i]-'0');
        }
        printf("%d\n",sum);

    }
    return 0;

}



Measured memory_bytes: 2580
# -*- coding: utf-8 -*-

N = int(input())
A = [int(i) for i in input().split()]

summ = sum(A)
average = summ / 2

sum_left = 0
j = 0
while sum_left < average:
    sum_left += A[j]
    j += 1
    
sum_right = sum(A[j:])

d = abs(sum_right - sum_left)

sum_l = sum_left - A[j-1]
sum_r = sum_right + A[j-1]

d2 = abs(sum_r - sum_l)

if d2 < d:
    print(d2)
else:
    print(d)

Measured memory_bytes: 88016
n = int(input())
c_array = list(input())

w_num = c_array.count('W')
r_num = n-w_num
def get_ans(half):
    wl_num = c_array[:half].count('W')
    rr_num = c_array[half:].count('R')
    ans = min(wl_num, rr_num) + abs(wl_num-rr_num)
    return ans

ans = min(get_ans(r_num), w_num, r_num)
print(ans)

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

int main() {
    int X; cin >> X;
    vector<int> primes;
    primes.push_back(2);
    bool flag = true;
    for (int i = 3; i <= 100003; i++){
        for (int j = 0; j < primes.size(); j++){
            if (i % primes[j] == 0){
                flag = false;
                break;
            }
        }
        if (flag) {
            primes.push_back(i);
        }
        flag = true;
    }
    cout << primes[lower_bound(primes.begin(), primes.end(), X) - primes.begin()] << endl;
}


Measured memory_bytes: 384
#include <stdio.h>
#define N 150
int main(void)
{
  char s1[N]={0},s2[N]={0},s3[N]={0};
  scanf("%s",s1);
  scanf("%s",s2);
  scanf("%s",s3);
  printf("%c%c%c\n",s1[0],s2[0],s3[0]);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;
 
#define int long long 
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair
 
static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;
 
template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
    v.assign(a,vector<T>(b,t));
}
 
//v.erase(unique(v.begin(),v.end()),v.end());

signed main(){
	int n;
	int m;
	while(cin>>n>>m,n||m){
		// int n;
		// cin>>n;
		// int m;
		// cin>>m;
		vint v(n);
		rep(i,n){
			cin>>v[i];
		}
		v.PB(0);
		vint tmp;
		rep(i,n+1){
			rep(j,n+1){
				tmp.PB(v[i]+v[j]);
			}
		}
		sort(ALL(tmp));
		int ans=0;
		tmp.erase(unique(ALL(tmp)),tmp.end());
		rep(i,tmp.size()){
			vint::iterator it=upper_bound(ALL(tmp),m-tmp[i]);
			it--;
			if(*it+tmp[i]<=m){
				ans=max(ans,*it+tmp[i]);
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 17452
S = input()
K = int(input())

n = 5 * 10 ** 15
l = 0
ans = 0
for i in S:
  if (int(i) != 1):
    ans = int(i)
    break
  else:
    l += 1
if (l >= K):
  ans = 1

print(ans)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std; void _main(); int main(){cin.tie(0);ios::sync_with_stdio(0);_main();}
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/





int N; string S;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> S;
    int cnt = 0, pre = 0;
    rep(i, 0, N) {
        if (S[i] == '(') cnt++;
        else {
            cnt--;
            if (cnt < 0) pre = max(pre, -cnt);
        }
    }
    rep(i, 0, pre) S = "(" + S;
    N += pre;

    cnt = 0;
    rep(i, 0, N) {
        if (S[i] == '(') cnt++;
        else cnt--;
    }
    rep(i, 0, cnt) S = S + ")";

    cout << S << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
        char s[1201];
        int i=0;

        scanf("%[^\n]",s);

        while(s[i]!='\0' && s[i]!='\0'){
                if(s[i]>96 && s[i]<123)
                        s[i]=s[i]-32;
                else if(s[i]>64 && s[i]<91)
                        s[i]=s[i]+32;
                i++;
        }
        puts(s);
        return 0;
}


Measured memory_bytes: 2064
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] ds = new int[N];
		for(int i=0; i<N; i++) {
			ds[i] = sc.nextInt();
		}
		Arrays.sort(ds);
		int ans = 1;
		for(int i=1; i<N; i++) {
			if(ds[i-1]!=ds[i]) ans++;
		}
		System.out.println(ans);
	}
	
	static int binarySearch(int[] A, int x) {
		int l = 0;
		int r = A.length;
		while(l<r) {
			int mid = (l+r)/2;
			if(A[mid] == x) return mid;
			else if(x<A[mid]) r = mid;
			else l = mid+1;
		}
		return -1;
	}
	
	static long upper_bound(int[] A, int b) {
		// bよりおおきい値がはじめて出てくるindexを返す
		return lower_bound(A, b+1);
	}

	static long lower_bound(int[] A, int b) {
		// b以上の値がはじめて出てくるindexを返す
		int lb=0;
		int ub=A.length;
		while(ub>lb) {
			int mid = (lb+ub)/2;
			if(A[mid]>=b) ub = mid;
			else lb = mid+1;
		}
		return lb;
	}
	
	// union find lib
	// usage:
	// 最初にinitを呼ぶ
	// root: 直接は呼ばないで
	// unite: まとめる
	// same: グループ判定
	static void init(int par[], int N) {
		for(int i=0; i<N; i++) {
			par[i] = i;
		}
	}
	
	static int root(int x, int [] par) {
		if(par[x] == x) {
			return x;
		} else {
			return (par[x] = root(par[x], par));
		}
	}
	
	static boolean same(int x, int y, int[] par) {
		return root(x, par) == root(y, par);
	}
	
	static void unite(int x, int y, int[] par) {
		x = root(x, par);
		y = root(y, par);
		if(x == y) return;
		par[x] = y;
	}
	
	// end union find lib
	
	// number lib
	
	static int max(int...ls) {
		int ans = Integer.MIN_VALUE;
		for(int i=0; i<ls.length; i++) {
			ans = Math.max(ans, ls[i]);
		}
		return ans;
	}
	
	static int min(int...ls) {
		int ans = Integer.MAX_VALUE;
		for(int i=0; i<ls.length; i++) {
			ans = Math.min(ans, ls[i]);
		}
		return ans;
	}
	
	static long lcm(long a, long b) {
		return a*(b/gcd(a, b));
	}
	
	static long gcd(long a, long b) {
		long ta = Math.max(a, b);
		long tb = Math.min(a, b);
		long tmp;
		while((tmp = ta%tb) != 0) {
			ta = tb;
			tb = tmp;
		}
		return tb;
	}
	
	static long modcomb(long n, long k, long mod) {
		if(k==1) {
			return n;
		}
		
		long ans = 1;
		for(long i=n; i>=n-k+1; i--) {
			ans = (ans * i)%mod;
		}
		for(long i=k; 0<i; i--) {
			ans = (ans * modpow(i, mod-2, mod)) % mod;
		}
		return ans;
	}
	
	static long modpow(long a, long b, long mod) {
		if(b==0) return 1;
		if(b%2==0) {
			long d = modpow(a, b/2, mod);
			return (d*d)%mod;
		} else {
			return (a*modpow(a, b-1, mod))%mod;
		}
	}
	
	static int disit(long a, long d) {
		int count = 0;
		while(a!=0) {
			a = a/d;
			count++;
		}
		return count;
	}
	
	// end number lib
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
	int n,m;
	cin>>n>>m;
	vector<string>v;
	for(int i=0;i<n;i++){
		string s;cin>>s;
		bool t=false;
		for(auto u:s){
			if(u=='#'){
				t=true;
			}
		}
		if(t)v.push_back(s);
	}
	set<int>ind;
	for(int j=0;j<m;j++){
		bool t=false;
		for(int i=0;i<v.size();i++){
			if(v[i][j]=='#'){
				t=true;break;
			}
		}
		if(!t)ind.insert(j);
	}
	for(int i=0;i<v.size();i++){
		for(int j=0;j<m;j++){
			if(ind.find(j)==ind.end()){
				cout<<v[i][j];
			}
		}cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 3608
/// In The Name Of God

#include <bits/stdc++.h>

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)

#define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = (int)5e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

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

using namespace std;

int n;
int a[N];
int main() {
	#ifdef wws
		freopen ("in.txt", "r", stdin);
	#endif
	Kazakhstan
	cin >> n;
	map <int, int> cnt;
	ll ans = 0;
	rep(i, 1, n) {
		cin >> a[i];
		cnt[a[i]]++;
		ans += a[i];
	}
	int q;
	cin >> q;
	while (q--) {
		int x, y;
		cin >> x >> y;
		ans -= cnt[x] * 1ll * x;
		ans += cnt[x] * 1ll * y;
		cnt[y] += cnt[x];
		cnt[x] = 0;
		cout << ans << nl;
	}
	ioi
}


Measured memory_bytes: 8508
_, *values = readlines.map(&:chomp).map(&:to_i)

def f(a, b)
  x = a * b
  swap = lambda {|a, b| return b, a}
  a, b = swap.call(a, b) if a < b

  r = a % b
  while(r!=0)
    a = b
    b = r
    r = a % b
  end
  x / b
end

p values[1..-1].reduce(values.first) {|r, e| f(r, e)}

Measured memory_bytes: 1788
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n,k] <- getIntList
    xs <- getIntList
    let (ms,ys) = span (< 0) xs
        (zs,ps) = span (==0) ys
        m = length ms
        z = length zs
        p = length ps
        kp = drop (k-z-m) . (0:) $ take k ps
        km = reverse . drop (k-z-p) . (0:) $ take k (reverse ms)
    print . minimum $ zipWith (\a b -> min (a-2*b) (2*a-b)) kp km

Measured memory_bytes: 15740
#include <bits/stdc++.h>
#include <random>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using Pt = pair<int, int>;


int main()
{
	int X;
	cin >> X;
	if (X >= 30)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <stdio.h>

using namespace std;
 
void solve(long long N){
    
	bool ans = false;
    
    if(N/100 == 7){
        ans = true;
    }
    if((N%100)/10 == 7){
        ans = true;
    }
    if((N%10) == 7){
        ans = true;
    }
 
  	if( ans == true){
    	cout << "Yes" << endl;
    }else{
       	cout << "No" << endl;
    }
 
}
 
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int k, a, b;
    bool ok=false;
    cin >> k;
    cin >> a >> b;
    for (int i=a; i<=b; i++)
        if (i%k==0) {
            ok=true;
            break;
        }
    if (ok)
        cout << "OK";
    else
        cout << "NG";
    cout << endl;
    return 0;
}

Measured memory_bytes: 3616
n,k=map(int,input().split())
mod=10**9+7

MAX_N=10**6
fact=[1]
fact_inv=[0]*(MAX_N+4)
for i in range(MAX_N+3):
  fact.append(fact[-1]*(i+1)%mod)

fact_inv[-1]=pow(fact[-1],mod-2,mod)
for i in range(MAX_N+2,-1,-1):
  fact_inv[i]=fact_inv[i+1]*(i+1)%mod

def f(n,k,mod):
  return fact[n]*fact_inv[k]%mod*fact_inv[n-k] %mod

ans=0
#0人の部屋はmaxいくつできるか
a=min(k,n-1)
ans=0
for i in range(a+1):
  d=f(n,i,mod)*f(n-1,i,mod)
  #print(i,d)
  ans+=d%mod
  ans%=mod

print(ans)

Measured memory_bytes: 88096
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX_N = 1000;

int N;
pair<int, int> p[MAX_N];
int res[MAX_N];

int main(){
	cin >> N;
	for(int i = 0; i < N; i++){
		p[i].first = 0;
		p[i].second = i;
	}
	for(int i = 0; i < N * (N - 1) / 2; i++){
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		a--; b--;
		if(c > d){
			p[a].first += 3;
		}else if(c < d){
			p[b].first += 3;
		}else{
			p[a].first += 1;
			p[b].first += 1;
		}
	}
	sort(p, p + N);
	reverse(p, p + N);
	for(int i = 0; i < N; i++){
		res[p[i].second] = i + 1;
		int t = i;
		while(p[t + 1].first == p[t].first){
			t++;
			res[p[t].second] = i + 1;
		}
		i = t;
	}
	for(int i = 0; i < N; i++){
		cout << res[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 3112
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
int main() {
	int a, b, c;
	while (cin >> a >> b >> c&&a != 0 && b != 0 && c != 0) {
		int d[400];
		for (int i = 0; i < a + b + c; i++) {
			d[i] = 2;
		}
		int n,e,f,g,h;
		int k[1000][4];
		cin >> n;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 4; j++) cin >> k[i][j];
			k[i][0]--;
			k[i][1]--;
			k[i][2]--;
			if (k[i][3] == 1) {
				d[k[i][0]] = 1;
				d[k[i][1]] = 1;
				d[k[i][2]] = 1;
			}
		}
		for (int i = 0; i < n; i++) {
			if (k[i][3] == 0) {
				int sum = 0;
				for (int j = 0; j < 3; j++) {
					if (d[k[i][j]] == 1) sum++;
				}
				if (sum == 2) {
					for (int j = 0; j < 3; j++) {
						if (d[k[i][j]] == 2) d[k[i][j]]=0;
					}
				}
			}
		}
		for (int i = 0; i < a + b + c; i++) {
			cout << d[i] << endl;
		}
	}
}

Measured memory_bytes: 3112
from collections import deque

H, W = map(int, input().split())
A = [[0] * (W + 2)] + [[0] + [H * W] * W + [0] for _ in range(H)] + [[0] * (W + 2)]
que = deque()
for i in range(1, H+1):
    for j, a in enumerate(list(input())):
        if a == '#':
            A[i][j+1] = 0
            que.append((i, j + 1))

step = [(1, 0), (-1, 0), (0, 1), (0, -1)]
res = 0
while que:
    h, w = que.popleft()
    for dh, dw in step:
        nh = h + dh
        nw = w + dw
        if A[h][w] + 1 < A[nh][nw]:
            A[nh][nw] = A[h][w] + 1
            res = max(res, A[nh][nw])
            que.append((nh, nw))
print(res)

Measured memory_bytes: 85852
#include <stdio.h>

const int SIDE_MAX = 6;

class DICE {
public:
	DICE(void) {};
	void ReadSide(void);
	void Roll(char dimension);
	int GetSide(int side);
        int CheckSide(int side1, int side2);
    bool CheckSame(DICE& d1, DICE& d2);
private:
	int m_a_side[SIDE_MAX];
};

void DICE::ReadSide(void) {
	char tmp[2];
	for (int i = 0; i < SIDE_MAX; i++) {
		scanf("%d", &m_a_side[i]);
	}
	scanf("%c", &tmp);
	return;
}

void DICE::Roll(char dimension) {
	int* a_tmp[4 + 1];
	int tmp; a_tmp[0] = &tmp;

	switch (dimension) {
	case 'W':
		a_tmp[1] = &m_a_side[0]; a_tmp[2] = &m_a_side[2];
		a_tmp[3] = &m_a_side[5]; a_tmp[4] = &m_a_side[3];
		break;
	case 'N':
		a_tmp[1] = &m_a_side[0]; a_tmp[2] = &m_a_side[1];
		a_tmp[3] = &m_a_side[5]; a_tmp[4] = &m_a_side[4];
		break;
	case 'E':
		a_tmp[1] = &m_a_side[0]; a_tmp[2] = &m_a_side[3];
		a_tmp[3] = &m_a_side[5]; a_tmp[4] = &m_a_side[2];
		break;
	case 'S':
		a_tmp[1] = &m_a_side[0]; a_tmp[2] = &m_a_side[4];
		a_tmp[3] = &m_a_side[5]; a_tmp[4] = &m_a_side[1];
		break;
	}
	for (int i = 0; i < 4 + 1; i++) {//アドレスを入れ替える
		*a_tmp[i] = *a_tmp[(i + 1) % (1 + 4)];
	}
	return;
}

int DICE::GetSide(int side) {
	return m_a_side[side - 1];
}

int DICE::CheckSide(int side1, int side2){
        for(int i=0;i<=6*4;i++){
                if(m_a_side[0] == side1 && m_a_side[1] == side2) return m_a_side[2];
                Roll(i%4!=3 ? 'S' : ((i+4)/8)%2 ? 'E' : 'W');
        }
        return -1;
}

bool DICE::CheckSame(DICE& d1, DICE& d2){
        if(d1.CheckSide(d2.GetSide(1), d2.GetSide(2)) != d2.GetSide(3)) return false;
        for(int i=0;i<SIDE_MAX;i++){
                if(d1.GetSide(i+1) != d2.GetSide(i+1)) return false;
        }
        return true;
}

int main(void) {
	DICE d1, d2;

        d1.ReadSide();
        d2.ReadSide();
        printf("%s\n", d1.CheckSame(d1, d2) == true ? "Yes" : "No"); 
	return 0;
}


Measured memory_bytes: 2640
import java.util.*;

public class Main {          
    
  public static void main(String[] args) {
   
     Scanner sc = new Scanner(System.in);          
    
     HashSet<Integer> ans = new HashSet<>();
     
     int N = sc.nextInt();
     
     for(int i = 0;i < N;i++){
         int a = sc.nextInt();
         if(ans.contains(a)){
             ans.remove(a);
         }else{
             ans.add(a);
         }         
     }
     
     System.out.println(ans.size());
     
  }                            
}

Measured memory_bytes: 63260
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    string S;
    cin >> S;
    ll n = S.size();
    ll r = 0;
    rep(i, 0, n){
        if(S[i] == '0') r++;
    }
    cout << 2 * min(r, n-r) << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <map>
#include <queue>
#include <string>
using namespace std;

typedef map<int,long long> M;
typedef queue<int> P;

int N[4000];

int main()
{
    int count;
    while (cin >> count, count > 0) {
        M m;
        int t = 1;
        P p;
        for (int i = 0; i < count; i++) {
            int t1;
            long long t2, t3;
            cin >> t1 >> t2 >> t3;
            if (N[t1 - 1] == 0) {
                N[t1 - 1] = t;
                t++;
                p.push(t1);
                m[t1] = 0;
            }
            m[t1] += t2 * t3;
        }

        bool flag = true;
        while (p.size()) {
            t = p.front(); p.pop();
            if (m[t] >= 1000000) {
                cout << t << endl;
                flag = false;
            }
            N[t - 1] = 0;
        }
        if (flag)
            cout << "NA" << endl;
    }

    return 0;
}

Measured memory_bytes: 1300
//Author: AnandRaj uux
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll; 

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test() int t;cin>>t;while(t--)
#define forn(i,f,n) for(int i=f;i<f+n;i++)
#define rforn(i,l,n) for(int i=l;i>l-n;i--)
#define all(v) v.begin(),v.end()
#define prin(V) for(auto v:V) cout<<v<<" ";cout<<endl
#define take(V,f,n) for(int i=f;i<f+n;i++) cin>>V[i]
#define what(x) cerr<<#x<<" = "<<x<<endl
#define KStest() int t,t1;cin>>t;t1=t;while(t--)
#define KScout cout<<"Case #"<<t1-t<<": "

const int MOD = 1e9+7,MAX = 1e5+5;
/////////////////FastExp///////////////////
ll powN(ll a,ll p)
{
	if(p==0) return 1;
	ll z=powN(a,p/2);
	z=(z*z)%MOD;
	if(p%2) z=(z*a)%MOD;
	return z;
}
/////////////////FastExp///////////////////
//////////////////Sieve////////////////////
vector<bool> is_prime(MAX+1, true);
void Sieve()
{
	is_prime[0] = is_prime[1] = false;
	int i,j;
	for (i = 2; i*i <= MAX; i++) 
	{
    	if (is_prime[i]) 
    	{
        	for (j = i * i; j <= MAX; j += i)
            	is_prime[j] = false;
    	}
	}
}
//////////////////Sieve////////////////////

const double pi = 3.1415926;

int main()
{
	double R;
	cin>>R;
	printf("%.6lf\n",2*pi*R);
}		

Measured memory_bytes: 3824
N,M=gets.split.map(&:to_i)

h={}

M.times do
    a,b=gets.split.map(&:to_i)
    h[a] ||= []
    h[a] << b
    h[b] ||= []
    h[b] << a
end

arr = Array.new(N+1,0)
q = [[1,1]]
until q.empty?
    a,b = q.shift
    next if arr[b]!=0
    arr[b] = a
    h[b].each do |c|
        q << [b,c]
    end
end

puts 'Yes'
puts arr[2..-1]

Measured memory_bytes: 57124
N, M = map(int, input().split())
X = list(map(int, input().split()))
X = sorted(X)
Y = [X[i+1]-X[i] for i in range(M-1)] #差のリスト
Y = sorted(Y)
if N >= M:
  print(0)
else:
  print(sum(Y[:(M-N)]))

Measured memory_bytes: 13964
(let((n (read))
     (a 1)
     (b 1)
     temp temp2 temp3)
  (loop repeat n do
        (setf temp (read))
        (setf temp2 (read))
        (setf temp3 (max (ceiling (/ a temp)) (ceiling (/ b temp2))))
        (setf a (* temp temp3))
        (setf b (* temp2 temp3)))
  (format t "~A~%" (+  a b)))


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

int main () {
  int n,m;
  cin >> n >> m;
  vector<int> elects(n);
  for (int i=0;i<n;i++) cin >> elects.at(i);
  
  // sort
  sort(elects.begin(), elects.end());
  
  // total
  double total;
  for (int i=0;i<n;i++) total += elects.at(i);
  
  // conpare elects.at(m-1) and total/4M
  int criteria = 4 * m;
  //cout << elects.at(n-m) << " " << total << " " << criteria << endl; 
  if (elects.at(n-m) >= total / criteria) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;

class UnionFind{
public:
	vector<int> par,g;
	//0-indexed
	void init(int n = 1) {
		par.resize(n);
		g.resize(n,1);
		for (int i = 0; i < n; ++i) par[i] = i;
	}
	int root(int x = 1){
		if(par[x]==x)return x;
		else{
			return par[x] = root(par[x]);
		}
	}
	void unite(int x = 1,int y = 1){
		x = root(x);
		y = root(y);
		if(x==y)return;
		g[y] += g[x];
		g[x] = 0;
		par[x] = y;
	}
	int gsize(int x){
		return g[root(x)];
	}
};

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll N , M;
	cin >> N >> M;
	vector<ll> A(M+1,0),B(M+1,0),ans;
	FOR(i,0,M)cin>>A[i+1]>>B[i+1];
	ll ansp = (N-1)*N/2;
	UnionFind uf;
	uf.init(N+1);
	FORR(i,1,M+1){
		ans.push_back(ansp);
		ll x = uf.gsize(A[i]);
		ll y = uf.gsize(B[i]);
		if(uf.root(A[i])!=uf.root(B[i])){
			ansp -= y*x;
		}
		uf.unite(A[i],B[i]);
	} 
	FORR(i,0,M){
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 4596
package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	var c []int
	c = make([]int, n)

	for i := 0; i < m; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		c[a-1]++
		c[b-1]++
	}

	for i := 0; i < n; i++ {
		fmt.Println(c[i])
	}

}

Measured memory_bytes: 512
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
int main(){
 int n,m;
 cin>>n>>m;
 int l=-1e9,r=1e9;
 for(int i=0,x,y;i<m;i++){
	cin>>x>>y;
	if(x>l) l=x;
	if(y<r) r=y;
 }
 if(l>r) cout<<0<<'\n';
 else cout<<r-l+1<<'\n';
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void) {
	int n, l[100], max = 0, sum = 0;
 
	scanf("%d", &n);
 
	for ( int i = 0; i < n; i++) {
		scanf("%d", &l[i]);
		sum += l[i];
		if (l[i] >= max) max = l[i];
	}
 
	printf( max < sum - max ? "Yes" : "No");
 
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <utility>
using ll = long long int;
using namespace std;
double pi = 3.141592653589793238;

#define FOR(i,N) for(int i=0;i<N;i++)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

int bitcnt(int numofbitcnt) {
	int karibitcnt = 0;
	for (int i = 0; i < 32; i++) {
		if (numofbitcnt & 1 << i)karibitcnt++;
	}
	return karibitcnt;
}

int main() {
	int N, K;
	cin >> N >> K;

	ll a[15] = { 0 };
	FOR(i, N) {
		cin >> a[i];
	}
	ll maxcnt = 1e17;
	FOR(i, 1 << N) {
		ll b[15] = { 0 };
		if (bitcnt(i) < K)continue;
		b[0] = a[0];
		for (int j = 1; j < N; j++) {
			if (!(i & 1 << j)){b[j] = a[j]; continue; }
			else { b[j] = max((*max_element(b,b+j))+1, a[j]); }

		}
		ll ness = 0;
		FOR(j, N) {
			ness = ness + b[j] - a[j];
		}
		maxcnt = min(maxcnt, ness);
	}

	cout << maxcnt << endl;
	return 0;
}

Measured memory_bytes: 256
N = gets.to_i
as = gets.split.map(&:to_i)
current = 0
sums = as.map do |a|
  current += a
  current
end
ans = 1 << 60
sum = sums[-1]
(0...(N - 1)).each do |i|
  a = sums[i]
  b = sum - a
  n = (a - b).abs
  ans = n if n < ans
end
puts ans


Measured memory_bytes: 16772
#include <bits/stdc++.h>
using namespace std;
#define test int t; cin>>t; while (t--)
#define ll long long int
#define fellow_junior  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main()
{
   fellow_junior

   ll a=0,c=0,d=0,e=0,i,j,k,l;
   string x;
   test
   {
       cin>>x;
       if(x[0]=='A') a++;
       if(x[0]=='W') c++;
       if(x[0]=='T') d++;
       if(x[0]=='R') e++;
   }
   cout<<"AC"<<" x "<<a<<endl;
   cout<<"WA"<<" x "<<c<<endl;
   cout<<"TLE"<<" x "<<d<<endl;
   cout<<"RE"<<" x "<<e<<endl;

   return 0;
}


Measured memory_bytes: 3652
def main():
    A, B = input().split()
    A = int(A)
    B_big, B_small = B.split(".")
    B_big = int(B_big)
    B_small = int(B_small)
    print(A*B_big + A*B_small//100)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9152
using System;
using System.Linq;

namespace abc110_a
{
    class program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string T = Console.ReadLine();
            int n = S.Length;
            char k = 'A';
            for (int i = 0; i < n; i++)
            {
                if (char.IsLower(S[i]))
                {
                    char c = S[i];
                    S = S.Replace(c, k);
                }
                k++;
            }
            k = 'A';
            for (int i = 0; i < n; i++)
            {
                if (char.IsLower(T[i]))
                {
                    char c = T[i];
                    T = T.Replace(c, k);
                }
                k++;
            }
            if (S == T)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 25440
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    static final FS sc = new FS();  // 封装输入类
    static final PrintWriter pw = new PrintWriter(System.out);

    public static void main(String[] args) {
        int n = sc.nextInt();
        long res = 0;
        for (int i = 1; i <= n; i++)
            res += (long) i * (i + 1) / 2;
        for (int i = 0; i < n - 1; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            int u = Math.min(a, b);
            int v = Math.max(a, b);
            res -= (long) (u + 1) * (n - v);
        }
        pw.println(res);
        pw.flush();
    }

    static class FS {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");
        String next() {
            while(!st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch(Exception ignored) {}
            }
            return st.nextToken();
        }
        int[] nextArray(int n) {
            int[] a = new int[n];
            for(int i = 0;i < n;i++) {
                a[i] = nextInt();
            }
            return a;
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 55576
<?php
$N = trim(fgets(STDIN));
$S = trim(fgets(STDIN));

$tmp = null;
$tmp2 = null;
for($i = 0; $i < strlen($S); $i++) {
 $tmp = substr($S, 0, $i + 1);
 $tmp2 = substr($S, $i + 1, strlen($S));

 if ($tmp == $tmp2) {
     echo 'Yes';
     exit;
 }
}

echo 'No';
?>

Measured memory_bytes: 4728
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> a(n, 0);
  int x;
  for (int i = 0; i < q; i++) {
    cin >> x;
    x--;
    a[x]++;
  }
  for (int i = 0; i < n; i++) {
    cout << ((q - a[i] < k) ? "Yes" : "No") << '\n';
  }
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD = 1000000007;

vector<pair<ll,ll> > res;

//Nについて素因数分解
void factor(ll N){
    for(ll i=2;i*i <= N;i++){
        
        if(N % i != 0)continue;
        ll count = 0;
        while(N % i == 0){
            count++;
            N /= i;
        }
        res.push_back({i,count});
    }
    if(N !=1)res.push_back({N,1});
}

int main()
{
    ll a,b; cin >> a >> b;
    ll c = __gcd(a,b);
    factor(c);
    cout << res.size()+1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll zero = 0;
const ll INF = 10000000000000000; //10^16
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(void){
    ll N,M;
    cin >> N >> M;
    ll pivot;
    
    if(N%2 == 1){
        for(ll i = 1; i <= M; i++){
            printf("%lld %lld\n", i, N-i);
        }
    }
    else if(N%4 == 0){
        if(M <= N/4){
            for(ll i = 1; i <= M; i++){
                printf("%lld %lld\n", N/4 - i + 1, N/4 + i);
            }
        }
        else{
            for(ll i = 1; i <= N/4; i++){
                printf("%lld %lld\n", N/4 - i + 1, N/4 + i);
            }
            for(ll i = 1; i <= M - N/4; i++){
                printf("%lld %lld\n", 3*N/4 - i, 3*N/4 + i);
            }
        }
    }
    else{
        if(M <= N/4){
            for(ll i = 1; i <= M; i++){
                printf("%lld %lld\n", N/4 - i + 1, N/4 + i);
            }
        }
        else{
            for(ll i = 1; i <= N/4; i++){
                printf("%lld %lld\n", N/4 - i + 1, N/4 + i);
            }      
            pivot = N/2 - 1 + (N - N/2 + 1)/2;
            for(ll i = 1; i <= M - N/4; i++){
                printf("%lld %lld\n", pivot - i, pivot + i);
            }
        }
    }
    
}

Measured memory_bytes: 3804
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string ans, c;
    cin >> ans;
    int query, f, q;
    cin >> q;

    bool is_convert = false;

    string mae, ato;

    REP(i, q) {
        cin >> query;

        if (query == 1) {
            is_convert = !is_convert;
        } else {
            cin >> f >> c;
            if (f == 1) {
                if (is_convert) ato += c;
                else mae += c;
            } else {
                if (is_convert) mae += c;
                else ato += c;
            }
        }
    }

    if (is_convert) {
        reverse(ALL(ato));
        reverse(ALL(ans));
        cout << ato << ans << mae << endl;
    } else {
        reverse(ALL(mae));
        cout << mae << ans << ato << endl;
    }

    return 0;
}


Measured memory_bytes: 1040
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <math.h>
#include <queue>
using namespace std;
typedef long long ll;
#define PI 3.14159265359

int main() {
  ll X, Y;
  cin >> X >> Y;

  ll b = Y - (2*X);
  if (b < 0 || b%2 != 0) {
    cout << "No" << endl;
    return 0;
  }
  b /= 2;
  if (X - b < 0) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 3628
Scanf.scanf "%d" @@ fun n ->
  let rec loop i l n =
    if i=4 then l else loop (i+1) (n mod 10::l) (n/10)
  in
  let ls = loop 0 [] n in
  let ls = List.fold_left (fun l d->
    match l with
    | [] -> [string_of_int d,d]
    | l -> List.fold_left (fun l (x,s) ->
            (Printf.sprintf "%s+%d" x d,s+d)::
            (Printf.sprintf "%s-%d" x d,s-d)::l
           ) [] l
    ) [] ls in
  ls |>List.iter (fun (s,d) -> if d=7 then (Printf.printf "%s=%d\n" s d; exit 0))



Measured memory_bytes: 384
N = int(input())
V = input().split()
C = input().split()
v = [int(V[i]) for i in range(len(V))]
c = [int(C[i]) for i in range(len(C))]

sum = 0
for i in range(N):
    calc = v[i]-c[i]
    if(calc >= 0):
        sum += calc

print(sum)

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

int N,T;
vector<vector<int>> memo(3010,vector<int>(3010,-1));

int dp(int i, int j, vector<pair<int,int>> &F) {
  int res;
  if (memo.at(i+1).at(j+1) != -1)  {  return memo.at(i+1).at(j+1); }
  else if (i == -1) { res = 0; }
  else if (j < F.at(i).first) {
    res = dp(i - 1, j, F);
  } 
  else {
    res = max(
        dp(i - 1, j, F),
        dp(i - 1, j - F.at(i).first, F) + F.at(i).second);
  }
  return memo.at(i+1).at(j+1) = res;
}

int main() {
  cin >> N >> T;
  vector<pair<int,int>> F(N);
  for (int i=0;i<N;i++) {
    cin >> F.at(i).first >> F.at(i).second;
  }
  sort(F.begin(),F.end());
  dp(N-2,T-1,F);
  int ans = -1;
  for (int i=0;i< N-1;i++) {
    ans = max(ans,memo.at(i+1).at(T) + F.at(i+1).second);
  }
  cout << ans << endl;
}

Measured memory_bytes: 35968
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

x = int(input())
if x:
    print("0")
else:
    print("1")

Measured memory_bytes: 10880