akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

//#define _USE_MATH_DEFINES
//#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>
#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef int long long i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 1000000007; // 10000000000000007ll;

const double eps = 1e-8;

const i64 MAXN = 300004;

i64 n, a, b;
map<i64, i64> f;

i64 binpow(i64 a, i64 n) {
    i64 res = 1;
    while (n) {
        if (n & 1) {
            res *= a;
            res %= mod;
        }
        a *= a;
        a %= mod;
        n >>= 1;
    }
    return res;
}

i64 factmod(i64 n, i64 p) {
    i64 res = 1;
    while (n > 1) {
        res = (res * ((n / p) % 2 ? p - 1 : 1)) % p;
        for (i64 i = 2; i <= n%p; ++i)
            res = (res * i) % p;
        n /= p;
    }
    return res % p;
}

void fact() {
    i64 R = 1;
    set<i64> q = { n, a, b, n - a, n - b };
    for (i64 i = 1; i <= n; i++) {
        R *= i;
        R %= mod;
        if (q.count(i)) {
            f[i] = R;
        }
    }
}

void fact2() {
    set<i64> q = { n, a, b, n - a, n - b };
    for (auto v : q) {
        f[v] = factmod(n, mod);
    }

}

i64 gcdex(i64 a, i64 b, i64 & x, i64 & y) {
    if (a == 0) {
        x = 0; y = 1;
        return b;
    }
    i64 x1, y1;
    i64 d = gcdex(b%a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}

i64 rev(i64 a) {
    i64 x, y;
    i64 g = gcdex(a, mod, x, y);
    return (x % mod + mod) % mod;
}

i64 cnk(i64 n, i64 k) {
    i64 R = f[n];
    R *= rev(f[k]);
    R %= mod;
    R *= rev(f[n - k]);
    R %= mod;
    return R;
}

i64 fcnk(i64 n, i64 k) {
    i64 R = 1;
    for (i64 i = 1; i <= k; i++) {
        R *= (n - i + 1);
        R %= mod;
        R *= rev(i);
        R %= mod;
    }
    return R;
}

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> n >> a >> b;
    //fact();

    i64 R = binpow(2, n);
    R -= fcnk(n, a);
    R = (R % mod + mod) % mod;

    R -= fcnk(n, b);
    R = (R % mod + mod) % mod;

    R -= 1;
    R = (R % mod + mod) % mod;

    cout << R << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String args[]) {

    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();

    if (A > 9 || B > 9) {
      System.out.println(-1);
    } else {
      System.out.println(A * B);
    }

    sc.close();
  }
}


Measured memory_bytes: 21844
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>
#include <cassert>

using namespace std;
typedef long long ll;
ll score[5000][5000];

int main()
{
   ll N, K;
   cin >> N >> K;
   vector<int> P(N);
   for (int i = 0; i < N; i++)
   {
      cin >> P[i];
      P[i]--;
   }
   vector<ll> C(N);
   ll Csum = 0;
   for (int i = 0; i < N; i++)
   {
      cin >> C[i];
   }
   ll ans = -LLONG_MAX;
   vector<ll> L(N);
   vector<ll> Ls(N, 0);

   for (int i = 0; i < N; i++)
   {
      Ls[i] = C[i];
      L[i] = 1;
      int cur = P[i];
      while (cur != i)
      {
         L[i]++;
         Ls[i] += C[cur];
         cur = P[cur];
      }
      //cout << endl;
   }

   for (int i = 0; i < N; i++)
   {
      int cur = i;
      ll tmp = 0;
      //cout << i << " " << L[i] << endl;
      for (int j = 1; j <= min(L[i], K); j++)
      {
         cur = P[cur];
         tmp += C[cur];
         ll t = (K - j) / L[i];
         //cout << tmp << " " << t << "* " << Ls[i] << "=" << tmp + t * max(0LL, Ls[i]) << endl;
         ans = max(ans, tmp + t * max(0LL, Ls[i]));
      }
   }
   cout << ans << endl;
}

Measured memory_bytes: 3764
import sys
from collections import deque
input = sys.stdin.readline

def main():
    n = int(input())
    tree = [[] for _ in range(n)]
    for i in range(n-1):
        a, b = map(int, input().split())
        tree[a-1].append(b-1)
        tree[b-1].append(a-1)
    
    not_yet = deque([0])
    already = [False]*n
    already[0] = True
    dist = [0]*n

    while not_yet:
        value = not_yet.popleft()
        for v in tree[value]:
            if already[v]:
                continue
            already[v] = True
            dist[v] = (dist[value] + 1) % 2
            not_yet.append(v)
    
    zero = dist.count(0)
    one = dist.count(1)

    ans = [0]*n
    already = [False]*n
    if zero >= one:
        if one <= n//3:
            ind = 1
            for i in range(n):
                if dist[i] == 1:
                    ans[i] = ind*3
                    already[ind*3-1] = True
                    ind += 1
            ind = 0
            for i in range(n):
                if ans[i] == 0:
                    while already[ind]:
                        ind += 1
                    ans[i] = ind + 1
                    already[ind] = True
    
        else:
            c0, c1, c2 = 0, 0, 1
            z, o = n//3 + bool(n%3), n//3 + bool(n%3==2)
            for i in range(n):
                if dist[i] == 0:
                    if c0 >= z:
                        ans[i] = c2*3
                        c2 += 1
                        continue
                    ans[i] = c0*3 + 1
                    c0 += 1
                else:
                    if c1 >= o:
                        ans[i] = c2*3
                        c2 += 1
                        continue
                    ans[i] = c1*3 + 2
                    c1 += 1
    else:
        if zero <= n//3:
            ind = 1
            for i in range(n):
                if dist[i] == 0:
                    ans[i] = ind*3
                    already[ind*3-1] = True
                    ind += 1
            ind = 0
            for i in range(n):
                if ans[i] == 0:
                    while already[ind]:
                        ind += 1
                    ans[i] = ind + 1
                    already[ind] = True
    
        else:
            c0, c1, c2 = 0, 0, 1
            z, o = n//3 + bool(n%3), n//3 + bool(n%3==2)
            for i in range(n):
                if dist[i] == 1:
                    if c0 >= z:
                        ans[i] = c2*3
                        c2 += 1
                        continue
                    ans[i] = c0*3 + 1
                    c0 += 1
                else:
                    if c1 >= o:
                        ans[i] = c2*3
                        c2 += 1
                        continue
                    ans[i] = c1*3 + 2
                    c1 += 1

    print(*ans)

            



    
if __name__ == "__main__":
    main()



Measured memory_bytes: 123100
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <cassert>
//#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

int a[80][80];
int b[80][80];
int c[80][80];
ll dp[80][80][6401];

void solve()
{
    int h, w;
    scanf("%d%d", &h, &w);
    int i, j;
    for (i = 0; i < h; i++) {
        for (j = 0; j < w; j++) {
            scanf("%d", &a[i][j]);
        }
    }

    for (i = 0; i < h; i++) {
        for (j = 0; j < w; j++) {
            scanf("%d", &b[i][j]);
            c[i][j] = abs(b[i][j] - a[i][j]);
        }
    }

    dp[0][0][c[0][0]] =1 ;
    int k;
    for (i = 0; i < h; i++) {
        for (j = 0; j < w; j++) {
            for (k = 0; k <= 6400; k++) {
                if (dp[i][j][k]) {
                    if (i < h - 1) {
                        int k2=abs(c[i + 1][j] - k);
                        if (k2 <= 6400) {
                            dp[i + 1][j][k2] = 1;                        
                        }
                        k2=abs(c[i + 1][j] + k);
                        if (k2 <= 6400) {
                            dp[i + 1][j][k2] = 1;                        
                        }
                    }
                    if (j < w - 1) {
                        int k2=abs(c[i][j+1] - k);
                        if (k2 <= 6400) {
                            dp[i][j+1][k2] = 1;                        
                        }
                        k2=abs(c[i][j+1] + k);
                        if (k2 <= 6400) {
                            dp[i][j+1][k2] = 1;                        
                        }
                    }
                }
            }
        }
    }

    ll ans = LINF;
    for (k = 6400; k >= 0; k--) {
        if (dp[h-1][w-1][k]) {
            ans = k;
        }
    }
    printf("%lld\n", ans);

    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}



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

int main()
{
	int n,m;
	int in;
	int out;
	int r=0, l=0;

	cin >> n;
	cin >> m;
	for (int i = 0; i < n; i++) {
		cin >> in >> out;
		m = m + in - out;
		r = max(r, m);
		l = min(l, m);
	}
	if (l < 0) {
		cout << 0 << endl;
	}
	else {
		cout << r << endl;
	}

	return 0;

}


Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;int count=1;cin>>n;
  	vector<int >df(n*100000,0);
  	df[n]=1;
  	while(df[n]!=2){
    	if(n%2==0){
          n=n>>1;
        }
      else{
      	n = 3*n+1;
      }
      df[n]+=1;
      count+=1;
    }
  	cout<<count;
}

Measured memory_bytes: 39296
#include<bits/stdc++.h>
using namespace std;
//第n行を0にして和を更新
void change_update(vector<vector<int>> &v ,int H, int W ,int n){
    for(int i=0;i<W;i++){
        v.at(i).at(n)=0;
    }
    for(int i=0;i<W;i++){
        int sum=0;
        for(int j=0;j<H;j++){
            sum+=v.at(i).at(j);
        }
        v.at(i).at(H)=sum;
    }
}

int main(){
    int H,W,K;
    int sum=0,SUM=0;
    cin>>H>>W>>K;
    vector<int>Hsec(H);
  	vector<vector<int>>Wsec(W,vector<int>(H+1));
   
  	
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        char letter;
        cin>>letter;
     
        if(letter=='#'){
            sum+=1;
            Hsec.at(i)+=1;
            Wsec.at(j).at(i)+=1;
            Wsec.at(j).at(H)+=1;
        }
        
       
      }
    
    
    }//入力終了

    vector<vector<int>> memory=Wsec;
    int ks=sum-K;
    int current=0;
  	
    for(int tmp=0;tmp<(1<<H);tmp++){
        bitset<6>hbit(tmp);
        for(int i=0;i<H;i++){
            if(hbit.test(i)){
                current+=Hsec.at(i);
                change_update(Wsec,H,W,i);
            }   
        }
       
      	if(current<=ks){
            ks-=current;
            for(int pat=0;pat<(1<<W);pat++){
                bitset<6>wbit(pat);
                current=0;
                for(int i=0;i<W;i++){
                    if(wbit.test(i)){
                        current+=Wsec.at(i).at(H);
                    }       
                }
                if(current==ks){
                    SUM+=1;
                }
				
            }

        }
        ks=sum-K;
        Wsec=memory;
        current=0;
      
    }
    //列のみ
    
	cout<<SUM<<endl;

}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
    int N, C;
    cin >> N >> C;
    ll mi = 1e18;
    int D[35][35], c[3][35];
    for (int i = 0; i < C; i++)
    {
        for (int j = 0; j < C; j++)
        {
            cin >> D[i][j];
        }
    }
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            int x;
            cin >> x;
            x--;
            c[(i + j) % 3][x]++;
        }
    }
    for (int i = 0; i < C; i++)
    {
        for (int j = 0; j < C; j++)
        {
            for (int k = 0; k < C; k++)
            {
                ll ans = 0;
                if (i == k || i == j || j == k)
                {
                    continue;
                }
                for (int l = 0; l < C; l++)
                {
                    ans += D[l][i] * c[0][l];
                    ans += D[l][j] * c[1][l];
                    ans += D[l][k] * c[2][l];
                }
                mi = min(ans, mi);
            }
        }
    }
    cout << mi << endl;
}

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

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

using namespace std;
using ll = long long;

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

void solve()
{
	string s;
	cin >> s;
	if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3])
	{
		cout << "Bad";
	}
	else
	{
		cout << "Good";
	}
	
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 3608
from bisect import bisect_left


def solve(string):
    a, b, q, *stx = map(int, string.split())
    s = [-10**10] + stx[:a] + [2 * 10**10]
    t = [-10**10] + stx[a:a + b] + [2 * 10**10]
    # x = dict([])
    ans = []
    i_s = 0
    i_t = 0
    for _x in stx[-q:]:
        """
        while s[i_s] < _x:
            i_s += 1
        while t[i_t] < _x:
            i_t += 1
        """
        i_s, i_t = bisect_left(s, _x), bisect_left(t, _x)
        ls, rs = _x - s[i_s - 1], s[i_s] - _x
        lt, rt = _x - t[i_t - 1], t[i_t] - _x
        r_max = max(rs, rt)
        l_max = max(ls, lt)
        """
        x[_x] = min([
            r_max - _x, _x - l_min, rt - ls + min(rt - _x, _x - ls),
            rs - lt + min(rs - _x, _x - lt)
        ])
        """
        ans.append(str(min([r_max, l_max, rt + ls + min(rt, ls), rs + lt + min(rs, lt)])))
    # return "\n".join([str(x[_x]) for _x in stx[-q:]])
    return "\n".join(ans)


if __name__ == '__main__':
    n, m, l = map(int, input().split())
    print(solve('{} {} {}\n'.format(n, m, l) + '\n'.join([input() for _ in range(n + m + l)])))


Measured memory_bytes: 39508
import itertools

n,d=map(int,input().split())
x=[]
for i in range(n):
    x.append(list(map(int,input().split())))
cnt=0
for k in itertools.combinations(x,2):
    tmp=0
    for m in range(d):
        tmp+=(k[0][m]-k[1][m])**2
    for l in range(200):
        if l**2==tmp:
            cnt+=1
            break
        else:
            pass
print(cnt)


Measured memory_bytes: 3064
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
const double pi=acos(-1);





int main() 
{
  ll x,y; cin>>x>>y;
  ll ans=abs(abs(x)-abs(y));
  if(0<=x&&x<y) {cout<<ans<<endl; return 0;}
  if(x<0&&0<y) {cout<<ans+1<<endl; return 0;}
  if(x<y&&y<=0) {cout<<ans<<endl; return 0;}
  if(0<y&&y<x) {cout<<ans+2<<endl; return 0;}
  if(y<=0&&0<=x) {cout<<ans+1<<endl; return 0;}
  if(y<x&&x<0) {cout<<ans+2<<endl; return 0;}
}


Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int D, N;
    cin >> D >> N;
    if (N == 100) N++;
    cout << N;
    rep(i, D) cout << "00";
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
	set<char> s;
	rep(i, 3){
		char a;
		cin >> a;
		s.insert(a);
	}
	if(s.size() == 1) cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
n, w = [int(i) for i in input().split()]
import numpy as np
dp = np.zeros(w+1, np.int64)
for i in range(n):
    wi, vi = [int(i) for i in input().split()]
    np.maximum(dp[:-wi]+vi, dp[wi:], out=dp[wi:])
print(max(dp))

Measured memory_bytes: 14648
while 1:
    n=int(input())
    if n==0:break
    a={};c=[]
    for _ in range(n):
        b=list(map(int,input().split()))
        if b[0] in a:a[b[0]]+=b[1]*b[2]
        else:a[b[0]]=b[1]*b[2];c.append(b[0])
    if max(a.values())<=999999:print('NA' )
    for i in c:
        if a[i]>999999:print(i)

Measured memory_bytes: 7844
#include<stdio.h>
int A[100000];
int partition(int,int);
int main() {
	
	int n,i,p;
	
	scanf ("%d",&n);

for(i=0;i<n;i++) {
	scanf("%d",&A[i]);
	}
	p=partition(0,n-1);
	for(i=0;i<n;i++) {
		if(i==p) { printf("[%d] ",A[i]); continue; }
	printf("%d",A[i]);
	if(i!=n-1) printf(" ");
	}
	printf("\n");
	return 0;
}
	
	
	int partition(int p, int r) {
		int x,i,j,d;
		
		x= A[r];
		i=p-1;
		
		for(j=p;j<r;j++) {
			if(A[j]<=x) {
				i++;
				d=A[i];
				A[i]=A[j];
				A[j]=d;
			}
		}
				d=A[i+1];
				A[i+1]=A[r];
				A[r]=d;
				
		
				return i+1;
				}


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

#define infi            2e9
#define infl            5e18
#define MX              100005
#define pi              2*acos(0.0)
#define ll              long long int
#define rr              read()
#define ff              first
#define ss              second
#define pb              push_back
#define pii             pair<int,int>
#define ms(a,b)         memset(a, b, sizeof(a))
#define loop(i,n)       for(register int i=0;i<n;i++)
#define pool(i,n)       for(register int i=n-1;i>=0;i--)
#define loop1(i,n)      for(register int i=1;i<=n;i++)
#define pool1(i,n)      for(register int i=n;i>0;i--)

using namespace std;

inline ll read(){char c=getchar();ll num,sign=1;for(;c<'0'||c>'9';c=getchar())if(c=='-')sign=-1;for(num=0;c>='0'&&c<='9';){c-='0';num=num*10+c;c=getchar();}return num*sign;}
// inline ll pw(ll b, ll p){ll ans=1;while(p>0){if(p&1)ans*=b;p>>=1;b*=b;}return ans;}
// inline bool isPrime(ll n){if(n==1)return false;if(n==2)return true;if(!(n%2))return false;for(ll i=3;i<=sqrt(n);i+=2)if(!(n%i))return false;return true;}
// inline ll gcd(ll a, ll b){if(a==0)return b;return gcd(b%a,a);}

// //*************************************  Bitmask Opereations  **********************************//
// int Set(int N,int pos){return N=N | (1<<pos);}
// int reset(int N,int pos){return N= N & ~(1<<pos);}
// bool check(int N,int pos){return (bool)(N & (1<<pos));}
// //********************************************************************************************//


int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    //#ifdef rid.dle
    //freopen("in.txt", "r", stdin);
    //#endif
    
    int n=rr;
    int ar[200005];
    int b[200005];

    loop(i,n){
        ar[i]=rr;
        b[i]=ar[i];
    }

    sort(b, b+n);

    loop(i,n){
        if(b[n-1]==ar[i])cout << b[n-2] << endl;
        else cout << b[n-1] << endl;
    }

    return 0;
}

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

int main() {
  int A, B;
  int count = 0;
  cin >> A >> B;

  // ここにプログラムを追記
  for( int i = A; i < (B + 1); i++){
    int scope = i;
    int n1 = scope / 10000; scope %= 10000;
    int n2 = scope / 1000;  scope %= 1000;
    int n3 = scope / 100;   scope %= 100;
    int n4 = scope / 10;    scope %= 10;
    int n5 = scope;

    if( (n1 == n5) && (n2 == n4) ){
      count++;
    }
    
  }
  
  cout << count << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<chrono>
#include<random>
#include<cstdio>
#include<set>
#include<map>
#include<numeric>
#include<cfenv>
#include<cmath>
#define MAX_N 100
#define MAX_M 100
#define INF 10000000
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
    int N;
    cin>>N;
    int X1=N/1.08;
    int X2=X1+1;
    //cout<<"\nX1"<<X1;
    //cout<<"\nX2"<<X2;
    int a=X1*1.08;
    int b=X2*1.08;
    if(a==N){
        cout<<X1;
    }else if(b==N){
        cout<<X2;
    }else{
        cout<<":(";
        //cout<<"\nY*1.08"<<Y*1.08;
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

// union - find tree !!!!!!!!!!!!!!!!!!!!!!!!!
vector<int> par; //oya
vector<int> rnk; //ki no hu ka sa
// n????´???§?????????
void init(int n){
    par.resize(n);rnk.resize(n);
    FOR(i, 0, n){par[i] = i;rnk[i] = 0;}
}
//??¨??????????±???????
int find(int x){
    if(par[x] == x) return x;
    else return par[x] = find(par[x]);
}
//x??¨y????±??????????????????????
void Merge(int x, int y){
    x = find(x);y = find(y);
    if(x == y) return;
    if(rnk[x] < rnk[y])par[x] = y;
    else{par[y] = x;if(rnk[x] == rnk[y]) rnk[x]++;}
    return;
}

int main(){
  int n, m; cin >> n >> m;
  init(n);
  FOR(i,0,m){
    int a, b;
    cin >> a >> b;
    Merge(a, b);
  }
  int q;
  cin >> q;
  FOR(i,0,q){
    int a, b;
    cin >> a >> b;
    if(find(a) == find(b)){
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }
  return 0;
}

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

int main() {
  string s;
  cin >> s;
  while (true) {
    s = s.substr(0, s.size() - 2);
    if (s.substr(0, s.size() / 2) == s.substr(s.size() / 2, s.size() / 2)) {
      cout << s.size() << endl;
      break;
    }
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
int N;
string s;
int K;
cin>>N>>s>>K;
for(int i=0;i<N;i++){
	if(s[i]!=s[K-1])
	s[i] = '*';
}
cout<< s <<endl;


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
 
int main(){
  int n;
  double ax,ay,bx,by,cx,cy,dx,dy;
  scanf("%d",&n);
  while(n--){
    scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&ax,&ay,&bx,&by,&cx,&cy,&dx,&dy);
    P k=P(bx-ax,by-ay)*P(dx-cx,cy-dy);
    if(k.imag()==0)printf("2\n");
    else if(k.real()==0)printf("1\n");
    else printf("0\n");
  }
  return 0;
}

Measured memory_bytes: 3240
#include<iostream>
    using namespace std;
    bool inside(int n,int a,int b){
      int s=0;
    while(n){
    s+=n%10;
    n/=10;
    }
    if(s<=b&&s>=a)
    return true;
    else
    return false;
    }
     
    int main(){
      long long sum=0;
    int n,a,b;
    cin>>n>>a>>b;
    for(int i=1;i<=n;i++)
    if(inside(i,a,b))
    sum+=i;
cout<<sum;
    return 0;
    }

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i; i<N; i++){
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  
  int Alice = 0;
  int Bob = 0;
  for (int i; i<N; i++){
    if (i % 2 == 0)	Alice += a.at(i);
    else Bob += a.at(i);
  }
  
  cout << Alice - Bob << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int N,A[200000],B[200000];
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>A[i];
		B[i]=A[i];
	}
	sort(A,A+N);
	for(int i=0;i<N;i++){
		if(B[i]==A[N-1])cout<<A[N-2];
		else cout<<A[N-1];
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 3200
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End

/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template

signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cins(s);
    if(s=="ABC") cout << "ARC"<< endl;
    else cout << "ABC" << endl;
    return 0;
}

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

const int INF = 1000000000;

int main()
{
	while(true){
		int n, m;
		cin >> n >> m;

		if(n==0 && m==0)
			break;

		int C[100][100];
		int T[100][100];
		for(int i=0; i<m; i++){
			for(int j=0; j<m; j++){
				if(i==j){
					C[i][j] = T[i][j] = 0;
				}
				else{
					C[i][j] = T[i][j] = INF;
				}
			}
		}

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

			C[a-1][b-1] = C[b-1][a-1] = c;
			T[a-1][b-1] = T[b-1][a-1] = t;

		}
/*
for(int i=0; i<m; i++){
for(int j=0; j<m; j++){
cout<<T[i][j]<<"     ";
}
cout <<endl;
}
for(int i=0; i<m; i++){
for(int j=0; j<m; j++){
cout<<T[i][j]<<"     ";
}
cout <<endl;
}
*/
		int minC[100][100];
		int minT[100][100];
		for(int i=0; i<m; i++){
			for(int j=0; j<m; j++){
				minC[i][j]=C[i][j];
				minT[i][j]=T[i][j];
			}
		}

		for(int k=0; k<m; k++){
			for(int i=0; i<m; i++){
				for(int j=0; j<m; j++){

					if(minC[i][j]>minC[i][k]+minC[k][j])
						minC[i][j]=minC[i][k]+minC[k][j];

					if(minT[i][j]>minT[i][k]+minT[k][j])
						minT[i][j]=minT[i][k]+minT[k][j];
				}
			}
		}
/*		
for(int i=0; i<m; i++){
for(int j=0; j<m; j++){
cout<<minC[i][j]<<"     ";
}
cout <<endl;
}
for(int i=0; i<m; i++){
for(int j=0; j<m; j++){
cout<<minT[i][j]<<"     ";
}
cout <<endl;
}
*/
		int k;
		cin >>k;	
		for(int i=0;i<k;i++){
			int p, q, r;
			cin >> p >> q >> r;
			
			if(r==0)
				cout << minC[p-1][q-1]<<endl;
			else
				cout << minT[p-1][q-1]<<endl;

		}
	}
	return 0;	
}

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

int main() {
  string s;
  bool result;
  cin>>s;
  
  if(s.at(0)==s.at(1)){
    if(s.at(0)==s.at(2) || s.at(0)==s.at(3) || s.at(2)==s.at(3)){
      result=true;
    }else{
      result=false;
    }
  }else if(s.at(0)==s.at(2)){
    if(s.at(0)==s.at(3) || s.at(1)==s.at(2) || s.at(1)==s.at(3)){
      result=true;
    }else{
      result=false;
    }
  }else if(s.at(0)==s.at(3)){
    if(s.at(0)==s.at(1) || s.at(0)==s.at(2) || s.at(1)==s.at(2)){
      result=true;
    }else{
      result=false;
    }
  }
  
  if(s.at(0)==s.at(1) && s.at(0)==s.at(2) && s.at(0)==s.at(3)){
    result=false;
  }
  
  if (result) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
typedef pair<int, int> pint;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin>>s;
    int ans=0;
    for(int i=0; i<(int)s.size(); i++){
        if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T'){
            int cnt=0;
            while(s[i+cnt]=='A'||s[i+cnt]=='C'||s[i+cnt]=='G'||s[i+cnt]=='T'){
                cnt++;
            }
            ans=max(ans,cnt);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3632
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 305
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef long double db;
int n,k,a[MAXN];
db dp[MAXN][MAXN][MAXN];
int cnt1,cnt2,cnt3;
db solve(int cnt1,int cnt2,int cnt3)
{
    if(cnt1<0||cnt2<0||cnt3<0) return 0;
    if(cnt1==0&&cnt2==0&&cnt3==0) return 0;
    if(dp[cnt1][cnt2][cnt3]!=-1.0) return dp[cnt1][cnt2][cnt3];
    db res=cnt1*solve(cnt1-1,cnt2,cnt3)+cnt2*solve(cnt1+1,cnt2-1,cnt3)+cnt3*solve(cnt1,cnt2+1,cnt3-1);
    return dp[cnt1][cnt2][cnt3]=(res+n)/(cnt1+cnt2+cnt3);
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        int x;scanf("%d",&x);
        if(x==1) cnt1++; else if(x==2) cnt2++; else cnt3++;
    }
    for(int i=0;i<=n;i++)
        for(int j=0;j<=n;j++)
            for(int k=0;k<=n;k++)
                dp[i][j][k]=-1;
    printf("%.15Lf\n",solve(cnt1,cnt2,cnt3));
    return 0;
}



Measured memory_bytes: 438656
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char const *argv[])
{
    int N, M;
    cin >> N >> M;
    vector<int> A(10000);
    int sum = 0;
    for (int i = 0; i < M; i++)
    {
        cin >> A[i];
        sum += A[i];
    }
    if (sum > N)
    {
        cout << "-1" << endl;
    }else{
        cout << (N - sum) << endl;
    }

    
    return 0;
}

Measured memory_bytes: 3168
#include<iostream>
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>

using namespace std;

string s;



int main() {
	cin >> s;
	int ans = s.size(), cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'S')
			cnt++;
		if (cnt > 0 && s[i] == 'T') {
			cnt--;
			ans -= 2;
		}
	}
	cout << ans << endl;
//	cin >> s;

	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int s;
  cin >> s;
  vector<int> A;
  int i=1;
  int count=0;
  while(1){
    if(i==1)
      A.push_back(s);
    else if(A.at(A.size()-1)%2==0)
      A.push_back(A.at(A.size()-1)/2);
    else if(A.at(A.size()-1)%2!=0)
      A.push_back(3*A.at(A.size()-1)+1);
    for(int j=0; j<A.size()-1; j++){
      if(A.at(j)==(A.at(A.size()-1))){
        count++;
      }
    }
  if(count>0)
    break;
  i++;
  }
  cout << i << endl;
}


Measured memory_bytes: 256
package main

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

func solve() {
	n := getInt()
	as := getSortedInts(n)
	bs := getSortedInts(n)
	cs := getSortedInts(n)

	ans := 0
	for _, b := range bs {
		cntA := func() int {
			l, r := -1, n
			for (r - l) > 1 {
				c := (r + l) / 2
				if as[c] < b {
					l = c
				} else {
					r = c
				}
			}
			return l + 1
		}()
		cntC := func() int {
			l, r := -1, n
			for (r - l) > 1 {
				c := (r + l) / 2
				if cs[c] > b {
					r = c
				} else {
					l = c
				}
			}
			return n - r
		}()
		ans += cntA * cntC
	}

	fmt.Fprintln(wr, ans)
}

func getSortedInts(n int) []int {
	ret := getIntSlice(n)
	sort.Ints(ret)
	return ret
}

// -----------------------------------------

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func getRunes() []rune {
	return []rune(getString())
}


Measured memory_bytes: 6400
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		int  l = sc.nextInt();
		int  a = sc.nextInt();
		int  b = sc.nextInt();
		int  c = sc.nextInt();
		int  d = sc.nextInt();
		int ave;
		if(a<40) a=40;
		if(b<40) b=40;
		if(c<40) c=40;
		if(d<40) d=40;
		if(l<40) l=40;
		ave=(a+b+c+d+l)/5;
		System.out.println(ave);
	}
}

Measured memory_bytes: 25980
#include <bits/stdc++.h>
#include <set>
#define rep(i,n) for (int i=0; i < (n); ++i)
#define all(a) a.begin(), a.end()
using ll = long long;
using namespace std;

// long long l[100];

int main() {
  string s,t;
  cin >> s >> t;
  reverse(t.begin(),t.end());
  if (s==t) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
N = gets.to_i
robots = N.times.map { gets.split.map(&:to_i) }.sort_by { |x, l| x + l }

ans = 0

current = -Float::INFINITY

robots.each do |x, l|
  if x - l < current
    ans += 1
  else
    current = x + l
  end
end

puts N - ans


Measured memory_bytes: 12664
N,D = map(int,input().split())
X = [0]*N
Y = [0]*N
ans = 0
for i in range(N):
    X[i],Y[i] = map(int,input().split())
    if X[i]**2 + Y[i]**2 <= D**2:
        ans += 1
print(ans)


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

int main(){
    string s;
    vector<bool> box(26);

    cin >> s;

    for(int i = 0; i < 26; i++){
        box.at(i) = false;
    }

    for(int i = 0; i < s.size(); i++){
        box.at(s.at(i) - 'a') = true;
    }

    for(int i = 0; i < 26; i++){
        if(!box.at(i)){
            cout << (char)(i + 'a') << endl;
            return 0;
        }
    }

    cout << "None" << endl;
}

Measured memory_bytes: 512
R,C = map(int,input().split())
table = [[0]*(C+1) for i in range(R+1)]
#table

for row in range(R):
  data = list(map(int,input().split()))
  for col in range(C):
    table[row][col]=data[col]
#table

for row in range(R):
  for col in range(C):
    table[row][C] += table[row][col]
    table[R][col] += table[row][col]
    table[R][C] += table[row][col]

for row in range(0,R+1):
  for col in range(0,C+1):
    if col==C:
      print("{:d}".format(table[row][col]))
    else:
      print("{:d}".format(table[row][col]),end=" ")


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

int main() {
  int a, b;
  cin >> a >> b;
  
  int c = a/10 + b/10;
  if (c > 0) { 
    cout << "-1" << endl;
    return 0;
  }
  
  cout << a*b << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int s = sc.nextInt();
    Set<Integer> set = new HashSet<>();
    set.add(s);

    for(int i = 2 ; i < 1000001 ; ++i){
      if(s%2 == 0){
        s = s/2;
      }else{
        s = s*3 + 1;
      }
      if(set.add(s)){
        set.add(s);
      }else{
        System.out.println(i);
        break;
      }
    }
    
  }
}

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

int main() {
  int N, K;
  cin >> N >> K;
  int L = 0;
  for (int i = 0; i < N; i++){
    int x;
    cin >> x;
    if (2 * x <= K){
      L += 2 * x;
    }
    else {
      L += 2 * (K - x);
    }
  }
  cout << L << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
#define ck(a,b) (0<=(a)&&(a)<(b))
#define INF 10000
using namespace std;

int crdx[4]={1,0,-1,0};
int crdy[4]={0,1,0,-1};
int crdp[31][31][4];
int crmap[31][31];
int crcost[4];
int crw,crh,crmin;

void crdfs(int x,int y,int muki){//muki:0-> clockwise
	//cout<<y<<":"<<x<<":"<<muki<<" "<<crdp[y][x][muki]<<endl;
	if(x==crw-1&&y==crh-1) crmin=min(crmin,crdp[y][x][muki]);
	else {

		int nmuki=(crmap[y][x]+muki)%4;
		if(crmap[y][x]==4) nmuki=4;
		REP(k,0,4){
			int nx=x+crdx[k],ny=y+crdy[k];
			if(!ck(ny,crh)||!ck(nx,crw)) continue;
			if(crdp[y][x][muki]>=crmin) continue;

			if(nmuki==k)	{
				if(crdp[ny][nx][nmuki]>crdp[y][x][muki]){
					crdp[ny][nx][nmuki]=crdp[y][x][muki];
					crdfs(nx,ny,k);
				}
			}
			else	{
				int cost;
				if(k>=muki) cost=crcost[k-muki];
				else        cost=crcost[4-(muki-k)];
				if(crdp[ny][nx][k]>crdp[y][x][muki]+cost){
					crdp[ny][nx][k]=crdp[y][x][muki]+cost;
					crdfs(nx,ny,k);
				}
			}


		}
	}
}

int main(){
	while(cin>>crw>>crh,crw){
		memset(crdp,INF,sizeof(crdp));
		crmin=INF;
		REP(i,0,crh){
			REP(j,0,crw){
				cin>>crmap[i][j];
			}
		}
		cin>>crcost[0]>>crcost[1]>>crcost[2]>>crcost[3];
		crdp[0][0][0]=0;
		crdfs(0,0,0);

		p(crmin);
	}

	return 0;
}

Measured memory_bytes: 3112
#include<bits/stdc++.h>
#define inf 0x7f7f7f7f
using namespace std;
const int MOD=1000000007;
typedef long long ll;
typedef unsigned long long ull;
void read(int &x) {
    int f = 1; x = 0;
    char ch = getchar();

    while (ch < '0' || ch > '9')   {if (ch == '-') f = -1; ch = getchar();}
    while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    x *= f;
}

inline void write(int x)
{
    char F[200];
    int tmp=x>0?x:-x ;
    if(x<0)putchar('-') ;
    int cnt=0 ;
       while(tmp>0)
       {
           F[cnt++]=tmp%10+'0';
           tmp/=10;
       }
       while(cnt>0)putchar(F[--cnt]) ;
}
string s;int flag=0;
int main(){
	cin>>s;
	int l=s.size();
	for(int i=0;i<=l;i++){
		if(s[i]=='C'){
			flag=1;
		}
		if(s[i]=='F'&&flag==1){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            bool ret = false;
            var sin = Console.ReadLine();
            var lst = sin.Split(' ').Select(x=>c2i(x)).ToList();
            if (lst.Count > 1)
            {
                if (lst[0] <= lst[1]) ret = true;
            }
            var retstr = ret ? "Yes" : "No";
            Console.WriteLine(retstr);
        }

        static int c2i(string c) { return int.Parse(c); }
    }
}


Measured memory_bytes: 13268
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

func parseProblem() int {
	return scanInt(sc)
}

func resolve(s int) int {
	exists := map[int]struct{}{}
	v := s
	exists[v] = struct{}{}
	for i := 2; i <= 1000000; i++ {
		v = next(v)
		if _, ok := exists[v]; ok {
			return i
		}
		exists[v] = struct{}{}
	}
	// no path
	return -1
}

func next(n int) int {
	if n%2 == 0 {
		return n / 2
	}
	return 3*n + 1
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}

Measured memory_bytes: 1828
import sys
input = sys.stdin.buffer.readline


class UnionFind:
    """素集合を木構造として管理する。"""
    def __init__(self, n):
        self.parent = [-1] * n
        self.next = [i for i in range(n)]
        self.n = n
        self.cnt = n

    def root(self, x):
        """要素xの代表元を求める。O(α(N))"""
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.root(self.parent[x])
            return self.parent[x]

    def merge(self, x, y):
        """要素xを含む集合と要素yを含む集合を併合する。O(α(N))"""
        rx = self.root(x)
        ry = self.root(y)
        if rx == ry:
            return False
        self.next[x], self.next[y] = self.next[y], self.next[x]
        if self.parent[rx] > self.parent[ry]:
            rx, ry = ry, rx
        self.parent[rx] += self.parent[ry]
        self.parent[ry] = rx
        self.next[rx]
        self.cnt -= 1
        return True

    def is_same(self, x, y):
        """要素x, yが同じ集合に属するかどうかを求める。O(α(N))"""
        return self.root(x) == self.root(y)

    def size(self, x):
        """要素xを含む集合の要素数を求める。O(α(N))"""
        return -self.parent[self.root(x)]

    def count(self):
        """集合の個数を求める。O(1)"""
        return self.cnt

    def enumerate(self):
        """集合を列挙する。list[list]で返す。O(N)"""
        groups = []
        used = [False] * n
        for x in range(n):
            if used[x]:
                continue
            grp = []
            while not used[x]:
                used[x] = True
                grp.append(x)
                x = self.next[x]
            groups.append(grp)
        return groups


n, q = map(int, input().split())
queries = [list(map(int, input().split())) for _ in range(q)]


uf = UnionFind(n)
for flag, u, v in queries:
    if flag:
        print(int(uf.is_same(u, v)))
    else:
        uf.merge(u, v)

Measured memory_bytes: 110968
import java.util.*;

public class Main {
	static ArrayList<Integer>[] g;

	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int m = sc.nextInt();
			int n = sc.nextInt();
			if (m == 0 && n == 0)
				break;
			int[] b = new int[m];
			int[] r = new int[n];
			for (int i = 0; i < m; ++i) {
				b[i] = sc.nextInt();
			}
			for (int i = 0; i < n; ++i) {
				r[i] = sc.nextInt();
			}

			g = new ArrayList[n + m];
			for (int i = 0; i < n + m; ++i) {
				g[i] = new ArrayList<>();
			}

			for (int i = 0; i < m; ++i) {
				for (int j = 0; j < n; ++j) {
					if (gcd(b[i], r[j]) > 1) {
						g[i].add(m + j);
						g[m + j].add(i);
					}
				}
			}
			vis = new boolean[n + m];
			matchTo = new int[n + m];
			Arrays.fill(matchTo, -1);
			int match = 0;
			for (int i = 0; i < m; ++i) {
				Arrays.fill(vis, false);
				if (dfs(i)) {
					++match;
				}
			}
			System.out.println(match);
		}
		sc.close();
	}

	static boolean[] vis;
	static int[] matchTo;

	static boolean dfs(int v) {
		if (v < 0)
			return true;
		for (int dst : g[v]) {
			if (vis[dst])
				continue;
			vis[dst] = true;
			if (dfs(matchTo[dst])) {
				matchTo[v] = dst;
				matchTo[dst] = v;
				return true;
			}
		}
		return false;
	}

	static int gcd(int a, int b) {
		if (a > b) {
			int d = a;
			a = b;
			b = d;
		}
		if (a == 0)
			return b;
		else
			return gcd(b % a, a);
	}

}

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

int main(){
  string s;
  cin>>s;
  if(s=="SUN"){
    cout<<7<<endl;
  }
   if(s=="MON"){
    cout<<6<<endl;
  }
   if(s=="TUE"){
    cout<<5<<endl;
  }
   if(s=="WED"){
    cout<<4<<endl;
  }
  if(s=="THU"){
    cout<<3<<endl;
  }
   if(s=="FRI"){
    cout<<2<<endl;
  }
   if(s=="SAT"){
    cout<<1<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws NumberFormatException 
	 */
	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
//		String[] tmpArray = br.readLine().split(" ");
//		int n = Integer.parseInt(br.readLine());
//		int b = Integer.parseInt(tmpArray[1]);
//		int c = Integer.parseInt(tmpArray[2]);
//		int y = Integer.parseInt(tmpArray[3]);
//		int r = Integer.parseInt(tmpArray[4]);

//		String[] tmpArray = br.readLine().split(" ");
//		int[] input = new int[n];
//		long sum = 0;
//		for(int i = 0; i < n; i++){
//			input[i] = Integer.parseInt(tmpArray[i]);
//			sum += input[i];
//		}
//		
//		Arrays.sort(input);
//		System.out.printf("%d %d %d\n", input[0], input[input.length - 1], sum);
//		
		while(true){
			String[] tmpArray = br.readLine().split(" ");
			int a = Integer.parseInt(tmpArray[0]);
			int b = Integer.parseInt(tmpArray[1]);
			if(a == 0 && b == 0){
				break;
			}
			
			for(int i = 0; i < a; i++){
				for(int j = 0; j < b; j++){
					System.out.print("#");
				}
				System.out.println();
			}
			System.out.println();
		}

		//		int[] array = new int[3];
//		array[0] = a; array[1] = b; array[2] = c;
//
//		Arrays.sort(array);
//		System.out.printf("%d %d %d\n", array[0], array[1], array[2]);
		/*
		if(a < b && b < c){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}*/
	}

}

Measured memory_bytes: 30836
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    ll w,h,x,y;
    cin >> w >> h >> x >> y;
    double cx = (double)w/2;
    double cy = (double)h/2;
    if(x==cx && y==cy){
        cout << fixed << setprecision(9) << (double)h*w/2 << " " << 1 << endl;
    }else{
        cout << fixed << setprecision(9) << (double)h*w/2 << " " << 0 << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

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

int main(void) {
    int i,j;
    int a, b;
    cin >> a >> b;
    ll x = b-a;
    cout << x*(1+x)/2 - b << endl; 

}


Measured memory_bytes: 256