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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}
ll myceil(ll x,ll y){//yがいくつ集まったらx以上になるか
	if(x<=y) return 1;
	else if(x%y==0) return x/y;
	else return x/y+1;
}

//a,b x
int main(){
	ll N; cin>>N;
	vector<ll> A;
	ll first; cin>>first;
	A.pb(first);
	rep(RE,N-1){
		ll tmp; cin>>tmp;
		if(tmp<=A[A.sz-1]){//追加するしかない
			A.pb(tmp);
		}
		else if(tmp>A[0]) A[0]=tmp;
		else{//おきかえる(A[A.sz-1]<tmp<=A[0])
			ll l=0,r=A.sz-1;
			while(r-l>=1){
				ll i=(l+r)/2;
				if(A[i]>=tmp) l=i+1;
				else r=i;
			}
			A[l]=tmp;
		}
	}
	cout<<A.sz;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
void solve(){
    string s ;
    cin>>s;
    int n = s.size();
    int ans =0;
    for(int i=1;i<n;i++){
        if(s[i]!=s[i-1])ans++;
    }
    cout<<ans<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1;
//	cin>> t;
	while(t--)solve();
	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <iostream>
using namespace std;

int main(){
  double l[10],v[2],time,root;

  while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&l[0],&l[1],&l[2],&l[3],&l[4],&l[5],&l[6],&l[7],&l[8],&l[9],&v[0],&v[1])!=EOF){
    double suml=0,sumv=0;
    for(int i=0;i<10;i++){
      suml+=l[i];
    }
    sumv=v[0]+v[1];

    time=suml/sumv;

    root=v[0]*time;

    for(int i=0;i<10;i++){
      root-=l[i];
      if(root<=0){
	cout << i+1 << endl;
	break;
      }
    }

  }

}

Measured memory_bytes: 1228
from itertools import permutations as perm
n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))
x = [int(x) for x in range(1,n+1)]
lis = list(perm(x,n))

print(abs(lis.index(p) - lis.index(q)))

Measured memory_bytes: 8052
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2000000000;//10^9
ll MOD  = 1000000007;
int N,M;
vector<int> edge[100010];
int memo[100010];
bool visited[100010];

int dfs(int x){
    visited[x] = true;
    if(memo[x] != 0){
        return memo[x];
    }
    int res = 0;
    for(int i = 0; i < edge[x].size(); i++){
        res = max(res, dfs(edge[x][i]) + 1);
    }
    return memo[x] = res;
    
}





int main() {
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int x,y;
        cin >> x >> y;
        x--;
        y--;
        edge[x].push_back(y);
    }
    
    for(int i = 0; i < N; i++){
        if(visited[i])continue;
        else{
            dfs(i);
        }
    }
    int m = 0;
    for(int i = 0; i < N; i++){
        m = max(m, memo[i]);
    }
    cout << m << endl;
    
    
    
}

Measured memory_bytes: 8192
using System;

namespace AtCoder{
    public static class AtCoder{
        public static void Main(){
            var input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int m = int.Parse(input[1]);

            input = Console.ReadLine().Split(' ');
            for(int i = 0; i < m; i++){
                n -= int.Parse(input[i]);
                if (n < 0 ){break;}
            }
            if (n < 0){n = -1;}
            Console.WriteLine(n);
        }
    }
}

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

int main(){
    string s,t;
    cin >> s >> t;

    int num = s.size();
    bool judge = false;
    for ( int i = 0 ; i < num ; i++ ){
        string temp = s.at(num-1) + s.substr(0,num-1);
        if ( temp == t ) judge = true;
      	s = temp;
    }

    string ans;
    if ( judge ) ans = "Yes";
    else ans = "No";

    cout << ans << endl;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<int> p(a), q(b), r(c);
    for (int i = 0; i < a; ++i) {
        cin >> p[i];
    }
    for (int i = 0; i < b; ++i) {
        cin >> q[i];
    }
    for (int i = 0; i < c; ++i) {
        cin >> r[i];
    }
    sort(p.begin(), p.end(), greater<>());
    sort(q.begin(), q.end(), greater<>());
    priority_queue<int> que;
    for (int i = 0; i < x; ++i) {
        que.push(p[i]);
    }
    for (int i = 0; i < y; ++i) {
        que.push(q[i]);
    }
    for (int i = 0; i < c; ++i) {
        que.push(r[i]);
    }

    ll res = 0;
    for (int i = 0; i < x + y; ++i) {
        res += que.top();
        que.pop();
    }
    cout << res << endl;
}

Measured memory_bytes: 6540
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int n = sc.nextInt();
        char[] s = sc.next().toCharArray();

        int[][] a = new int[n][2];
        int maxE = 0;
        int maxW = 0;
        for (int i = 0; i < n; i++) {
            if (i != 0) {
                a[i][0] += a[i - 1][0];
                a[i][1] += a[i - 1][1];
            }
            if (s[i] == 'E') {
                a[i][0]++;
                maxE++;
            } else {
                a[i][1]++;
                maxW++;
            }
        }

        int min = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            int turn;
            if (i == 0)
                turn = maxE - a[i][0];
            else
                turn = a[i-1][1] + maxE - a[i][0];
            min = Math.min(min, turn);
        }

        System.out.println(min);
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 35540
A, B, K = (int(_) for _ in input().split())
C = 0
D = 0
for i in range(1,K+1):
    C = A
    D = B
    if i%2 == 1:
        if C %2 == 1:
            A = A - 1
            A = A // 2
            B = B + A
        if C %2 == 0:
            A = A//2
            B = B + A
    if i%2 == 0:
        if D %2 == 1:
            B = B-1
            B = B//2
            A = A + B
        if D %2 == 0:
            B = B//2
            A = A + B
print(A,B)


Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <climits>
#include <string.h>
#include <algorithm>

using namespace std;
#define fast ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define pb push_back
#define sz(s) (int)s.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = (int) 1e5 + 77;

int main(){
    fast;
    ll n,k;
    cin>>n>>k;
    pll a[N];
    
    forn(i,n){
        cin>>a[i].first>>a[i].second;
    }
    
    sort(a,a+n);
    
    forn(i,n){
        k-=a[i].second;
        if(k<=0){
            cout<<a[i].first<<endl;
            break;
        }
    }
    
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef set<ll> sl;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

const int K = 100;
int A, B;

vector<string> f(int a, char m, char b) {
	int h = a/49 + 1;
	if(a%49 == 0) h = h-1;
	vector<string> ret(h, string(K,b));
	rep(i,0,a) {
		int p = i/49 + 0;
		int q = (i%49)*2 + 1;
		if(p%2) {
			q++;
		}
		ret[p][q] = m;
	}
	ret.pb(string(K,b));
	return ret;
}

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	cin >> A >> B;
	vector<vector<string> > R;
	R.pb(vector<string>(1,string(K,'.')));
	int p = (B-1)/98;
	int q = (B-1)%98;
	rep(i,0,p) {
		R.pb(f(98,'#','.'));
	}
	if(q > 0) {
		R.pb(f(q,'#','.'));
	}
	
	R.pb(vector<string>(1,string(K,'#')));
	p = (A-1)/98;
	q = (A-1)%98;
	rep(i,0,p) {
		R.pb(f(98,'.','#'));
	}
	if(q > 0) {
		R.pb(f(q,'.','#'));
	}

	int h = 0;
	rep(i,0,sz(R)) {
		h += sz(R[i]);
	}
	cout << h << " " << 100 << '\n';
	rep(i,0,sz(R)) {
		rep(j,0,sz(R[i])) {
			cout << R[i][j] << '\n';
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
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; }
vector<int > divisor(int n) {
  vector< int > ret;
  for(int i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
vector <bool>  primes(10000010,1) ;
void Eratosthenes(int n){
    for(int i = 2; i*i <= n; i++){
		if(primes[i]){
			for(int j = 0; i * (j + 2) <= n; j++){
				primes[i *(j + 2)] = 0;
			}
		}
	}
	primes[0] = 0; primes[1] = 0;

	/*for(int i = 0; i <= n; i++){
		if(primes[i]){
			cout << i << endl;
		}
	}*/
}
#include <math.h> 

bool IsPrime(int num)
{
    if (num < 2LL) return false;
    else if (num == 2LL) return true;
    else if (num % 2LL == 0) return false; // 偶数はあらかじめ除く

    long double sqrtNum = sqrtl(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

signed main(void){
    int a,b; cin>>a>>b;
    vector <int> ayaku, byaku;
    ayaku = divisor(a);
    //rep(i, ayaku.size()) cout<<ayaku[i]<<endl;
    byaku = divisor(b);
    vector <int> tmp;
    Eratosthenes(9000000);
    rep(i, ayaku.size()){
        tmp.push_back(ayaku[i]);
    }
    rep(i, byaku.size()){
        tmp.push_back(byaku[i]);
    }
    sort(tmp.begin(),tmp.end());
    int cnt = 0;
    for(int i=1;i< tmp.size();i++){
        
        if(tmp[i]==tmp[i-1]){
        
            if(IsPrime(tmp[i])) cnt++;
        
        }
    }
    
    cout<<cnt+1<<endl;
}


Measured memory_bytes: 1792
x,n=map(int,input().split())
p=sorted(list(map(int,input().split())))
if n==0:
    print(x)
    exit()
q=[0]*(p[-1]+2)
for i in range(n):
    q[p[i]]=1
ans=(1000000,-1)
for i in range(p[-1]+2):
    if q[i]==0:
        if ans[0]>abs(i-x):
            ans=(abs(i-x),i)
print(ans[1])

Measured memory_bytes: 61852
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S; cin >> S;
  int ans=999,N=S.size();
  
  for(int i=0; i<N-2; i++) {
    int num = (S.at(i)-'0')*100 + (S.at(i+1)-'0')*10 + S.at(i+2)-'0';
    ans = min(ans,abs(num-753));
  }
  cout << ans << endl;
}

Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
#include<stdio.h>

using namespace std;

int main() {
    int H, W;

    while (cin >> H >> W) {
        if (H == 0) return 0;

        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (i == 0 || j == 0 || i == H - 1 || j == W - 1) cout << "#";
                else cout << ".";
            }
            cout << endl;
        }
        cout << endl;
    }


}


Measured memory_bytes: 3084
n=int(input())
s=str(input())
s1=''
s2=''
max=0
for i in range(1,n-1):
  count={}
  s1=s[:i]
  s2=s[i:]
  for j in range(len(s1)):
    if s2.count(s1[j]) >= 1:
      count[s1[j]]=1
  data=list(count.keys())
  if len(data) > max:
    max=len(data)
print(max)
  

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,k;
ll a[100100];
int main()
{
    ll ans=0;
    scanf("%lld%lld",&n,&k);
    for(int i=0;i<n;i++)
      scanf("%lld",&a[i]);
      ll te=k;
      for(int i=1;i<42;i++)
     {
            ll x,m;
            m=(1ll<<(i-1))-1;
            m=~m;
            x=k&m;//&运算都是1才为1；^相同为0不同为1
            for(int j=1;j<=(i-1);j++)
            {
                int bit,cn=0;
                for(int l=0;l<n;l++)
                {
                    bit=(a[l]>>(j-1))&1;
                    if(!bit)
                     cn++;
                }
                if (cn > n - cn)
                    x += (1ll << (j - 1));
            }
            if(x>k)
                continue;
                ll tem=0;
            for(int i=0;i<n;i++)
            {
               tem+=(a[i]^x);
            }
            ans=max(ans,tem);
     }
     printf("%lld\n",ans);
}


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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





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






int main()
{
    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    int i,n;
    string s;
    cin >> n >> s;
    for(i=0;i<s.SZ;i++)
    {
        cout << (char)(((s[i]-'A'+n)%26)+'A');
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int 
using namespace std;
#define MOD 1000000007
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int m, n;
	cin >> n >> m;

	char** arr = new char* [m];
	for (int i = 0; i < m; i++) {
		char* temp = new char[n];
		arr[i] = temp;
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			char x;
			cin >> x;
			arr[j][i] = x;
		}
	}

	
	int** str = new int* [m];
	for (int i = 0; i < m; i++) {
		int* temp = new int[n];
		str[i] = temp;
	}

	

	str[m - 1][n - 1] = 1;
	for (int i = m - 2; i >= 0; i--) {
		if (arr[i][n - 1] == '#') {
			str[i][n - 1] = 0;
		
		}

		else {
			str[i][n - 1] = str[i + 1][n - 1];
		}

		
		
	}
	for (int i = n - 2; i >= 0; i--) {
		if (arr[m-1][i] == '#') {
			str[m-1][i] = 0;

		}

		else {
			str[m-1][i] = str[m-1][i+1];
		}



	}


	for (int i = m - 2; i >= 0; i--) {
		for (int j = n - 2; j >= 0; j--) {
			if (arr[i][j] == '#') {
				str[i][j] = 0;
			}
			else {
				str[i][j] = (str[i + 1][j] + str[i][j + 1])%MOD;
			}

		}
	}
	
	cout << str[0][0];
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define INF 10000000000
ll a, b, c, n, m, x, y, z, w, h, ans = 0, cnt = 0, mx = 0, mn = INF;
string s, t;

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

    while(cin >> s){
        map<char, ll> list;
        rep(i, s.size()){
            list[s[i]]++;
        }
        rep(i, s.size()){
            if(list[s[i]] % 2){
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
}



Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char const *argv[]) {
    int A, B;
    //入力
    scanf("%d %d", &A, &B);
    //計算
    int ans;
    ans = A-B;
    if ( (A+B) > ans ) { ans = A + B; }
    if ( (A*B) > ans ) { ans = A*B; }
    //出力
    printf("%d\n", ans );
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<cstdio>
#include<cmath>
using namespace std;
int n, k;
int main()
{
cin>>n>>k;
for(int i=0;;i++)
{
if(i*(k-1)+1>=n)
{
cout<<i<<endl;
return 0;
}
}
return 0;
}

Measured memory_bytes: 256
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::f64::consts::PI;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

const C: [char; 2] = ['.', '#'];

fn dfs(x: usize, y: usize, s: &Vec<Vec<char>>, memo: &mut Vec<Vec<Option<bool>>>, c: usize) -> (u64,u64) {
    if memo[x][y].is_some() {
        return (0,0)
    }
    if s[x-1][y-1] == C[c] {
        let mut ans = [0, 0];
        ans[c] += 1;
        memo[x][y] = Some(true);
        let (w,b) = dfs(x-1, y, s, memo, (c+1)%2);
        ans[0] += w;
        ans[1] += b;
        let (w,b)= dfs(x+1, y, s, memo, (c+1)%2);
        ans[0] += w;
        ans[1] += b;
        let (w,b)= dfs(x, y-1, s, memo, (c+1)%2);
        ans[0] += w;
        ans[1] += b;
        let (w,b)= dfs(x, y+1, s, memo, (c+1)%2);
        ans[0] += w;
        ans[1] += b;
        (ans[0], ans[1])
    } else {
        memo[x][y] = Some(false);
        (0,0)
    }
}

fn main() {
    let line: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let h = line[0];
    let w = line[1];
    let mut s = Vec::with_capacity(h);
    for _ in 0..h {
        let line: Vec<char> = read_line().trim().chars().collect();
        s.push(line);
    }
    let mut memo = vec![vec![None; w+2]; h+2];
    for i in 0..h+2 {
        memo[i][0] = Some(false);
        memo[i][w+1] = Some(false);
    }
    for i in 0..w+2 {
        memo[0][i] = Some(false);
        memo[h+1][i] = Some(false);
    }

    let mut ans = 0;
    for i in 0..h {
        for j in 0..w {
            let (tmp1, tmp2) = dfs(i+1, j+1, &s, &mut memo, (i+j)%2);       
            ans += tmp1 * tmp2;
        }
    }
    let mut memo = vec![vec![None; w+2]; h+2];
    for i in 0..h+2 {
        memo[i][0] = Some(false);
        memo[i][w+1] = Some(false);
    }
    for i in 0..w+2 {
        memo[0][i] = Some(false);
        memo[h+1][i] = Some(false);
    }
    for i in 0..h {
        for j in 0..w {
            let (tmp1, tmp2) = dfs(i+1, j+1, &s, &mut memo, (i+j+1)%2);       
            ans += tmp1 * tmp2;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 31740
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <bitset>
using namespace std;

int n;
bitset<2000001> dp;

int main(void) {
  scanf("%d", &n);
  int all = 0;
  dp[0] = true;
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    all += x;
    dp |= dp << x;
  }
  for (int i = all / 2; i >= 0; --i) {
    if (dp[i]) {
      printf("%d\n", all - i);
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n, jpysum=0;
    double btcsum=0;
    cin >> n;
    vector<double> x(n);
    vector<string> u(n);
    rep(i, n) {
        cin >> x.at(i) >> u.at(i);
        if(u.at(i)=="JPY") jpysum += x.at(i);
        if(u.at(i)=="BTC") btcsum += x.at(i) * 380000.0;
    }
    cout << setprecision(10) << jpysum + btcsum << endl;
}


Measured memory_bytes: 256
from math import sqrt

def center(a,b):
    m = (a+b)/2
    d = abs(a-m)
    vec= complex((b-a).imag,(a-b).real)
    length = sqrt(1-d**2)
    c1,c2 = m+vec*(length/(2*d)),m-vec*(length/(2*d))
    return c1,c2



def check(c):
    cnt = 0
    for loc in location:
        if abs(c-loc) <= 1.0+EPS:
            cnt += 1
    return cnt 

while True:
    n = int(input())
    if n==0:
        break
    location = []
    ans = 1
    EPS = 1e-7
    for _ in range(n):
        a,b = map(float ,input().split())
        location.append(complex(a,b))

    for i in range(n):
        for j in range(i+1,n):
            if abs(location[i]-location[j]) >=1.0*2:
                continue
            c1,c2 = center(location[i],location[j])
            ans = max(ans,check(c1),check(c2))
            
    print(ans)
            
            
        
        


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

 using namespace std;
 typedef struct node {
 	 int a ,b , c;
 };
 queue<node> q;
 int DP[100][100][100];
 int main(){
  	int A , B , C;
	scanf("%d%d%d",&A, &B , &C);
	for(int i = 0 ; i < 100 ; i++){
		for(int j = 0 ; j < 100 ; ++j){	
			for(int k = 0 ;  k < 100 ; ++k){
				DP[i][j][k] = 1e9;
			}
		}
	}
	DP[A][B][C] = 0 ;
	q.push({A,B,C});
	while(not q.empty()){
		A = q.front().a;
		B = q.front().b;
		C = q.front().c;
		q.pop();
		if(A == B and B == C ){
			printf("%d",DP[A][B][C]);
			break;
		}
		if(A >= 100 or B >= 100 or C >= 100 ){
			continue;
		}
		if(A + 1 < 100 and B+ 1 < 100 and DP[A+1][B+1][C] > DP[A][B][C] + 1 ){
			DP[A+1][B+1][C] = DP[A][B][C] + 1;
			q.push({A+1, B + 1 , C});
		}
		if(A + 1 < 100 and C  +1  < 100 and DP[A+1][B][C+1] > DP[A][B][C] + 1){
			DP[A+1][B][C+1] = DP[A][B][C]  +1;
			q.push({A+1 , B , C+1});
		}
		if(B  +1 < 100 and C + 1 < 100 and DP[A][B+1][C+1] > DP[A][B][C] +  1){
			DP[A][B+1][C+1] = DP[A][B][C] + 1 ;
			q.push({A , B  +1 , C+1});
		}
		if(A+ 2  < 100 and DP[A+2][B][C] > DP[A][B][C] + 1) q.push({A+2, B ,C}) , DP[A+2][B][C] = DP[A][B][C]  +1 ;
		if(B+ 2  < 100 and DP[A][B+2][C] > DP[A][B][C] + 1) q.push({A, B+2 ,C}) , DP[A][B+2][C] = DP[A][B][C]  +1 ;
		if(C+ 2  < 100 and DP[A][B][C+2] > DP[A][B][C] + 1) q.push({A, B ,C+2}) , DP[A][B][C+2] = DP[A][B][C]  +1 ;
	}
 }

Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long 
#define reus ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int32_t main()
{
	reus;
	int n;
	string s;
	cin>>n>>s;
	if(s.length()<=n)
	cout<<s<<endl;
	else if(s.length()>n)
	{
		for(int i=0;i<n;i++)
		cout<<s[i];
		cout<<"..."<<endl;
	}
	
	return 0;
}

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

using namespace std;

long xi1(long x, long r, long d) {
    return r*x-d;
}

int main() {
    long r, d, x;
    cin >> r >> d >> x;
    long ans = x;
    for (long i=1; i<=10; ++i) {
        ans = xi1(ans, r, d);
        cout << ans << endl;
    }
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned ll;
using ld = long double;
using pll = pair<ll, ll>;
using pss = pair<string, string>;
using pdd = pair<ld, ld>;
using graph = vector<vector<int>>;

const ll MOD = 1000000007;
const ld EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ex[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int ey[8] = {0, 1, 1, 1, 0, -1, -1, -1};

template <class T>
void chmin(T &a, T b) { a = min(a, b); }
template <class T>
void chmax(T &a, T b) { a = max(a, b); }

ll intabs(ll a)
{
    if (a >= 0)
        return a;
    else
        return -a;
}

ll intpow(ll a, ll b, ll p = LLONG_MAX)
{
    ll ret = 1;
    while (b != 0)
    {
        if ((b & 1) == 1)
            ret *= a;
        a *= a;
        if (a >= p)
            a %= p;
        if (ret >= p)
            ret %= p;
        b = b >> 1;
    }
    return ret;
}

int digit(ll a, ll b = 10)
{
    int ret = 0;
    while (a != 0)
    {
        a /= b;
        ret++;
    }
    return ret;
}

ll gcd(ll x, ll y)
{
    while (y != 0)
    {
        ll cnt = x % y;
        x = y;
        y = cnt;
    }
    return x;
}

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

class UnionFind
{
    vector<int> par, sz;

public:
    UnionFind(int n) : par(n), sz(n)
    {
        for (int i = 0; i < n; i++)
        {
            par[i] = i;
            sz[i] = 1;
        }
    }
    int root(int x)
    {
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }
    void unite(int x, int y)
    {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry)
            return;
        par[rx] = ry;
        sz[ry] += sz[rx];
    }
    bool same(int x, int y)
    {
        return root(x) == root(y);
    }
    int size(int x)
    {
        return sz[root(x)];
    }
};

vector<bool> seen;
void dfs(const graph &g, int v)
{
    seen[v] = true;
    for (auto i : g[v])
    {
        if (seen[i])
            continue;
        dfs(g, i);
    }
}

int main()
{
    int i, j, k, cnt;
    int n, m;
    cin >> n >> m;
    if (n == m)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 256
use std::cmp;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: i32,
        s: chars,
    }
    let mut black_cnt = 0;
    let mut white_cnt = 0;

    for char in &s {
        if *char == '#' {
            black_cnt += 1;
        } else {
            white_cnt += 1;
        }
    }

    let mut fwd_b = 0;
    let mut bwd_w = white_cnt;
    let mut ans = cmp::min(black_cnt, white_cnt);
    for char in &s {
        if *char == '#' {
            fwd_b += 1;
        } else {
            bwd_w -= 1;
        }
        ans = cmp::min(ans, fwd_b + bwd_w);
    }

    println!("{}", ans);

}


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

int main() {
	// your code goes here
	int n;
	cin >> n;
	if(((n/10%111)==0)||((n%1000%111)==0)){
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
	
	
	
	
	
	return 0;
}

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

#define mem( arr, i ) fill( arr, arr + sizeof (arr), i )
typedef unsigned long long ull;
typedef long long lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vcI;
typedef vector<lli> vcL;
typedef vector<pii> vPI;
typedef vector<pll> vPL;
const lli I_MAX = 1LL << 60;
const lli mod = 1000000007;


void solve() {
	lli n, m, q, k;
	cin >> n >> m;

	lli _min = INT_MAX, _max = 0;

	for (int i = 0; i < n; ++i) {
		cin >> q >> k;
		if ( k <= m ) _min = min( _min, q );
	}

//	sort( num.begin(), num.end() );
	
	if ( _min == INT_MAX ) cout << "TLE\n";
	else cout << _min << '\n';
}

int main() {
	int t = 1;
//	cin >> t;
	for (int i = 1; i <= t; ++i) {
//		printf("Case #%d: ", i );
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(b);i>=(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
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>
ll sum(const T& a){return accumulate(all(a),0LL);}

void solve(){
    ll n,q;cin>>n>>q;
    vector<string> name(n);
    vl time(n);
    rep(i,n){
        cin>>name[i];
        cin>>time[i];
    }

    ll sum=0;
    queue<ll> que;
    rep(i,n)que.push(i);
    while(que.size()){
        ll x=que.front();
        que.pop();
        ll tmp=min(time[x],q);
        sum+=tmp;
        time[x]-=tmp;
        if(!time[x])cout<<name[x]<<" "<<sum<<endl;
        else que.push(x);
    }
}

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



Measured memory_bytes: 6572
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())
 
using namespace std;

int main() {
    long long a, x;
    cin >> x >> a;

    if(a > x) {
        cout << "0" << endl;
    } else {
        cout << "10" << endl;
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long long INF = 1e18;
//const ll mod = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S, T;
    cin >> S >> T;
    int ans = 0;
    for(int i = 0; i < S.size(); i++) {
        ans += (S[i] != T[i]);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3792
//control+option+n to run!
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define NEGFOR(i, a, b) for (ll i = (a); i > (b); i--)
#define vll vector<long long>
#define sll set<long long>
#define ld long double
#define inf 1000000000000000000;
#define mll multiset<long long>
#define nn << "\n"
#define F(i, b) for (ll i = 0; i < b; i++)
//10^8 operations per second
//greatest int is 2,147,483,647
//greates long long is 9.22337204e18

//ALL FUNCTIONS SHOULD BE LL!!!!
long long power(long long a, long long b)
{
  if (b == 0)
    return 1;
  long long res = power(a, b / 2);
  if (b % 2)
    return res * res * a;
  else
    return res * res;
}

ll log(ll base, ll number)
{

  int x = base;
  int count = 1;
  while (base < number)
  {
    base *= x;
    count++;
  }
  return count;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  //REMEMBER TO GET RID OF THE "\n"!!!!
  //ifstream cin ("FILE.in");
  //ofstream cout ("FILE.out");
  string s, t;
  cin >> s >> t;
  ll i = 0, j = t.size();
  ll mi = inf;
  while (j <= s.size())
  {
    ll count = 0;
    FOR(x, i, j)
    {
      if (t[x - i] != s[x])
      {
        count++;
      }
    }

    mi = min(count, mi);
    i++;
    j++;
  }
  cout << mi;
  cout << "\n"; //GET RID OF THIS FOR THE ACTUAL PROGRAM!!!!
}


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


using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 1010;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}



// Main Code

int main()
{
	int arr[3];
	rep(i, 0, 3) cin>>arr[i];
	sort(arr, arr+3);
	int ans = arr[2] - arr[1];
	arr[0] += ans;
	arr[1] = arr[2];
	int b = arr[2] - arr[0];
	ans += (b/ 2);
	if(b%2 != 0) ans += 2;
	cout<<ans<<endl;
}


Measured memory_bytes: 256
n = int(input())
lis_d = [list(map(int, input().split())) for _ in range(n)]

for i in range(n-2):
  if lis_d[i][0] == lis_d[i][1] and lis_d[i+1][0] == lis_d[i+1][1] and lis_d[i+2][0] == lis_d[i+2][1]:
    print("Yes")
    exit()

print("No")

Measured memory_bytes: 9052
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var (
	N, M    int
	p       []int
	solved  []bool
	penalty []int
)

func main() {
	readVariables()
	for i := 0; i < M; i++ {
		p, s := nextInt(), nextStr()
		if s == "WA" && !solved[p] {
			penalty[p]++
		} else {
			solved[p] = true
		}
	}
	var solve, pen int
	for i := 1; i < N+1; i++ {
		if solved[i] {
			pen += penalty[i]
			solve++
		}
	}
	fmt.Println(solve, pen)
}

func readVariables() {
	N, M = nextInt(), nextInt()
	solved = make([]bool, N+1)
	penalty = make([]int, N+1)
}

/* Template */

var scanner *bufio.Scanner

func init() {
	Max := 1001001
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 0, Max), Max)
	scanner.Split(bufio.ScanWords)
}

//nextInt converts next token from stdin and returns integer value.
//nextInt panics when conversion into an integer fails.
func nextInt() int {
	if !scanner.Scan() {
		panic("No more token.")
	}
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic("nextInt(): cannot convert to int: " + scanner.Text())
	}
	return num
}

func nextStr() string {
	if !scanner.Scan() {
		panic("No more token.")
	}
	return scanner.Text()
}

// MinInt returns minimum argument
func MinInt(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

//MaxInt returns maximum argument
func MaxInt(x, y int) int {
	if x < y {
		return y
	} else {
		return x
	}
}

//AbsInt returns |x| for x
func AbsInt(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//ModPow calculates integer power with modulo operation
//if modulo <= 1, it powers w/o module operation
//if base < 0, return value might be negative too.
func ModPow(base, exponent, modulo int) (result int) {
	result = 1
	for exponent > 0 {
		if exponent%2 == 1 {
			result *= base
			if modulo > 1 {
				result %= modulo
			}
		}
		base *= base
		if modulo > 1 {
			base %= modulo
		}
		exponent /= 2
	}
	return
}

//Gcd
func Gcd(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = gcd(result, vals[i])
	}
	return
}

func gcd(x, y int) int {
	x, y = AbsInt(x), AbsInt(y)
	for y > 0 {
		x, y = y, x%y
	}
	return x
}

//Lcm
func Lcm(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = lcm(result, vals[i])
	}
	return
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}


Measured memory_bytes: 3200
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>
#include <set>
#include <cmath>
#include <iomanip>
#define REP(i, n) for(int i=0; i<n; i++)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)
#define FORR(i, m, n) for(int i=m; i>=n; i--)
#define INF 999999999
#define llong long long
#define VSORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
31 41 5
)");
#define cin input
#endif

int mx(int x, int y, int z)
{
	if (x>=y && x>=z)
		return x;
	else if (y>=x && y>=z)
		return y;
	else
		return z;
}

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	int count = 0;

	int max;
	if (a%2==0 && b%2==0 && c%2==0)
	{
		max = mx(a, b, c);
		count = (max-a)/2+(max-b)/2+(max-c)/2;
	}
	else if (a%2==0 && b%2==0 && c%2==1)
	{
		a+=1;
		b+=1;
		max = mx(a, b, c);
		count = 1+(max-a)/2+(max-b)/2+(max-c)/2;
	}
	else if (a%2==0 && b%2==1 && c%2==0)
	{
		a+=1;
		c+=1;
		max = mx(a, b, c);
		count = 1+(max-a)/2+(max-b)/2+(max-c)/2;
	}
	else if (a%2==1 && b%2==0 && c%2==0)
	{
		b+=1;
		c+=1;
		max = mx(a, b, c);
		count = 1+(max-a)/2+(max-b)/2+(max-c)/2;
	}
	else if (a%2==0 && b%2==1 && c%2==1)
	{
		b+=1;
		c+=1;
		max = mx(a, b, c);
		count = 1+(max-a)/2+(max-b)/2+(max-c)/2;
	}
	else if (a%2==1 && b%2==0 && c%2==1)
	{
		a+=1;
		c+=1;
		max = mx(a, b, c);
		count = 1+(max-a)/2+(max-b)/2+(max-c)/2;
	}
	else if (a%2==1 && b%2==1 && c%2==0)
	{
		a+=1;
		b+=1;
		max = mx(a, b, c);
		count = 1+(max-a)/2+(max-b)/2+(max-c)/2;
	}
	else if (a%2==1 && b%2==1 && c%2==1)
	{
		max = mx(a, b, c);
		count = (max-a)/2+(max-b)/2+(max-c)/2;
	}

	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import Counter
n=int(input())
A=list(map(int,input().split()))
cnt=Counter(A)
tot=0
dif={}
for k,v in cnt.items():
  tot += v*(v-1)//2
  dif[k]=v-1
ans=[tot-dif[a] for a in A]
print('\n'.join(map(str,ans)))

Measured memory_bytes: 51812
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define sz(x) (int)(x.size())
#define pii pair<int, int>
#define fi first
#define se second
const int N = 1e5 + 1000;

vector<int> par(N, -1);
int root(int v) { return par[v] < 0 ? v : (par[v] = root(par[v])); }
void merge(int a, int b) {
    if ((a = root(a)) == (b = root(b))) return;
    if (par[b] < par[a]) swap(a, b);
    par[a] += par[b];
    par[b] = a;
}

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<pii> v(m);
    for (int i = 0; i < m; i++) {
        cin >> v[i].fi >> v[i].se;
    }
    reverse(v.begin(), v.end());
    int x = n * (n - 1) / 2;
    vector<int> ans;
    for (int i = 0; i < m; i++) {
        ans.push_back(x);
        if (root(v[i].fi) != root(v[i].se))
            x -= par[root(v[i].fi)] * par[root(v[i].se)];
        merge(v[i].fi, v[i].se);
    } 
    reverse(ans.begin(), ans.end());
    for (int i = 0; i < sz(ans); i++) {
        cout << ans[i] << "\n";
    }
}

Measured memory_bytes: 4596
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll f(ll a, ll b) {
    return a * b;
}
int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = max({f(a, c), f(a, d), f(b, c), f(b, d)});
    cout << ans << endl;
}

Measured memory_bytes: 3628
using System;

class Program {
    static void Main( string[] args )
    {
        string[] s = Console.ReadLine().Split();

        int[] a = new int[ 5 ]; ;

        for ( int i = 0; i < a.Length; ++i ) {
            a[ i ] = int.Parse( s[ i ] );
        }

        bool c = false;

        if ( a[ 2 ] - a[ 4 ] < 0 ) { goto SKIP; }
        if ( a[ 2 ] + a[ 4 ] > a[ 0 ] ) { goto SKIP; }
        if ( a[ 3 ] - a[ 4 ] < 0 ) { goto SKIP; }
        if ( a[ 3 ] + a[ 4 ] > a[ 1 ] ) { goto SKIP; }

        c = true;

    SKIP:
        Console.WriteLine( c ? "Yes" : "No" );
    }
}

Measured memory_bytes: 8876
#include<iostream>
#include<cstdio>
#include<string>
#include<cfloat>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<climits>
#include<cstring>
#include<queue>
#include<map>
#include<functional>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
const int mod = 1e9+7;
const int INFINT = INT_MAX/2;
typedef long long ll;
typedef unsigned long long ull;

ull calculateF(ull b, ull n){
    if(n<b) return n;
    return calculateF(b, n/b) + (n%b);
}

ll digitSum(ull n, ull s){
    if(n == s) return n+1;
    if(n < s) return -1;
    ull sqn = sqrt(n);
    for (ull b=2;b<=sqn;b++){
        if(calculateF(b, n) == s) return b;
    }
    for (int p=sqn;p>0;p--){
        if((n-s)%p == 0 && calculateF((n-s)/p + 1, n)==s) return (n-s)/p + 1;
    }
    return -1;
}

int main(){
    ull n,s;
    cin >> n >> s;
    cout << digitSum(n, s) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		var sc = new Scanner(System.in);
		int s = sc.nextInt();
		int w = sc.nextInt();
		if (w >= s) {
			System.out.println("unsafe");
		} else {
			System.out.println("safe");
		}
		sc.close();
	}
}


Measured memory_bytes: 35800
#include <stdio.h>

int main(void) {
	int a, b;
	scanf("%d %d", &a, &b);
	if (a>b) printf("a > b\n");
	else if (a==b) printf("a == b\n");
	else if (a<b) printf("a < b\n");
	
	return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
int ar[10000];
int main()
{
    int n,m;
    cin>>n>>m;
    int pagla=n;
    while(n--)
    {
        int person;
        cin>>person;
        for(int i=0; i<person; i++)
        {
            int temp;
            cin>>temp;
            ar[temp]++;
        }
    }
    int ans=0;
    for(int i=1;i<=m;i++){
        if(ar[i]==pagla) ans+=1;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  string S;
  cin>>S;
  if(S=="Rainy"){
    cout<<"Sunny"<<endl;
  }  else if(S=="Sunny"){
      cout<<"Cloudy"<<endl;
  } else{
    cout<<"Rainy"<<endl;
  }
  return 0;
}

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

#define   ipair         pair<int, int>
#define   pb            push_back
#define   ff            first
#define   ss            second
#define   fr(i, j, k)   for (int i = j; i < k; i++)
#define   rf(i, j, k)   for (int i = j; i >= k;i--)
#define   int           long long
#define   ld            long double
#define   all(x)        x.begin(), x.end()
#define   rall(x)       x.rbegin(),x.rend()
#define   mp            make_pair
#define   inf           INT_MAX
#define   read_file();	freopen("input.txt", "r", stdin);	freopen("output.txt", "w", stdout);
#define   IOS           std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int mod  =  1000000007;
const ld  pi   =  acos(-1);
const int Maxn =  1005;

template<class T> ostream& operator <<(ostream &out,vector<T> &A){for(auto x:A) out<<x<<" ";return out;}
template<class T> ostream& operator <<(ostream &out,set<T> &A){for(auto x:A) out<<x<<" ";return out;}
template <class T1,class T2>T1 powr(T1 a,T2 b){T1 res = 1;fr(i,1,b+1)res = res*a;return res;}


int32_t main(){ IOS;
    int steps, n;   cin>>steps>>n;
    set<int> sy;
    vector<int> dp(steps+1,0);
    dp[0] = 1;
    fr(i,0,n){
        int x;  cin>>x;
        sy.insert(x);
    }
    if(!sy.count(1))    dp[1] = 1;
    for(int i=2;i<=steps;i++){
        if(!sy.count(i))
            dp[i] = (dp[i-1]%mod + dp[i-2]%mod)%mod;
    }
    cout << dp[steps] << endl;
}

Measured memory_bytes: 5760
from itertools import product

N, A, B, C = map(int, input().split(' '))
L = [int(input()) for _ in range(N)]

ans = 10 ** 9
for groups in product(range(4), repeat=N):
    length_a = 0
    length_b = 0
    length_c = 0
    cost_a = -10
    cost_b = -10
    cost_c = -10

    for group, length in zip(groups, L):
        if group == 1:
            length_a += length
            cost_a += 10
        elif group == 2:
            length_b += length
            cost_b += 10
        elif group == 3:
            length_c += length
            cost_c += 10

    if 0 in {length_a, length_b, length_c}:
        continue

    ans = min(ans, sum([
        abs(A - length_a),
        abs(B - length_b),
        abs(C - length_c),
        cost_a,
        cost_b,
        cost_c,
    ]))

print(ans)


Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=500005;

char s[10];

int main(){
    while(~scanf("%s", &s)){
        bool ans=0;
        if(s[1]==s[0]&&s[2]==s[0])ans=1;
        if(s[1]==s[3]&&s[2]==s[3])ans=1;
        printf("%s\n", ans?"Yes":"No");
    }
    return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>
#include <deque>
#include <limits>

using namespace std;

int main()
{
  int64_t N, K;

  cin >> N >> K;

  N %= K;

  if (K < 2 * N) {
    N = K - N;
  }

  cout << N << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/dynamic_bitset.hpp>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

int main() {
	string S;
	cin >> S;

	u64 div_base = 2019;
	u64 ans = 0;
	boost::dynamic_bitset<> search_done(S.size()+1);
	
	for(u64 b=0; b<S.size(); b++) {
		if(search_done[b]) continue;

		u64 tmp_div = 0;
		u64 num_b_variations = 0;
		
		for(u64 e=b; e<S.size(); e++) {
			tmp_div = tmp_div * 10 + S[e] - '0';
			bool is_zero = (tmp_div == 0);
			
			// tmp_div = tmp_div - (tmp_div / div_base) * div_base;
			tmp_div = tmp_div % div_base;

			if(!is_zero && tmp_div == 0) {
				num_b_variations++;
				ans += num_b_variations;	
				
				if(search_done[e+1]) break;
				
				search_done[e+1] = 1;
			}
		}
	}

	cout << ans;

}


Measured memory_bytes: 3752
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int count=0;
		for(int i = 0;i<s.length();i++) {
			if(s.charAt(i) == '1') {
				count++;
			}
		}
		System.out.println(count);

	}
}

Measured memory_bytes: 35572