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

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define bs(v,val) binary_search(v.begin(),v.end(),val)
#define mod 1e9+7
#define ff first
#define ss second
#define fi(n) for(int i=0;i<n;i++)
#define fj(n) for(int j=0;j<n;j++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define m_p make_pair
#define endl '\n'

ll power(ll x, ll y, ll p)
{  
    ll res = 1;
    x = x % p;  
    if (x == 0) return 0;
    while (y > 0){  
        if (y & 1)  res = (res*x) % p;  
        y = y>>1;
        x = (x*x) % p;  
    }  
    return res;  
}
ll modInverse(ll n, ll p)
{
    return power(n, p-2, p); 
}
// ********** CODE STARTS HERE ****************//



int main()
{
	fastio;
    // int T;
    // cin >> T;
    // while(T--)
    // {

    // }
    int a;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;
}

Measured memory_bytes: 3648
import java.util.*;

/*
問題文

*/

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

        Scanner 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");
        }
    }
}

Measured memory_bytes: 35728
G(int a,int b){
	if(a==0||b==0)return(a>b?a:b);
	if(a%b==0)return b;
	return G(b,a%b);
}
main(){
	int i,n,a[100002],l[100002]={0},r[100002]={0},ans=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++){scanf("%d",&a[i]);l[i+1]=G(a[i],l[i]);}
	for(i=n;i>0;i--)r[i]=G(a[i],r[i+1]);
	for(i=1;i<=n;i++)ans=(ans>G(l[i],r[i+1])?ans:G(l[i],r[i+1]));
	printf("%d",ans);
}

Measured memory_bytes: 1280
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i) 
const int N = 205, mo = 998244353 ;
using namespace std ;

int n, fac[N], G[N][N] ;
struct poi {
	int x, y ;
} a[N] ;

int cross(poi p0, poi p1, poi p2) {
	return (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y) ;
}

int main() {
	scanf("%d", &n) ;
	rep(i, 1, n) scanf("%d%d", &a[i].x, &a[i].y) ;
	fac[0] = 1 ;
	rep(i, 1, n) fac[i] = (ll) fac[i - 1] * 2 % mo ;
	int ans = fac[n] - 1 - n ; ans %= mo ;
	rep(i, 1, n) {
		rep(j, i + 1, n) {
			int cnt = 2, res = 0, w = 1 ;
			rep(k, 1, n) if (!cross(a[i], a[j], a[k]) && k != i && k != j) {
				if (G[k][i] || G[k][j] || G[i][k] || G[j][k]) w = 0 ;
				++ cnt ;
			}
			res = fac[cnt] - 1 - cnt ;
			ans -= res * w, ans %= mo ;
			rep(k, 1, n) if (!cross(a[i], a[j], a[k]) && j != k && i != k) G[i][k] = G[k][i] = G[j][k] = G[k][j] = true ;
		}
	}
	printf("%d\n", (ans + mo) % mo) ;
	return 0 ;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>

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

void empty(int *x,int *y){
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      if(!puzz[i][j]){
	*x = j;
	*y = i;
	return;
      }
    }
  }
}

void swap(int *a,int *b){
  int temp = *a;
  *a = *b;
  *b = temp;
}

int cal(){
  int sum = 0;
  for(int i=0;i<9;++i){
    int a = puzz[i/3][i%3];
    if(a){
      a--;
      sum += abs(i/3 - a/3) + abs(i%3 - a%3);
    }
  }
  return sum;
}

int dfs(int x,int y,int p,int dep,const int lim){
  int h=cal();
  if(h==0)return dep;

  if(dep+h>lim)return -1;

  for(int i=0;i<4;++i){
    int nx=x+dx[i];
    int ny=y+dy[i];

    if(p!=-1 && i==(p+2)%4)continue;
    
    if(0<=nx && nx<3 && 0<=ny && ny < 3){
      swap(&puzz[y][x],&puzz[ny][nx]);
      int res=dfs(nx,ny,i,dep+1,lim);
      if(res!=-1)return res;

      swap(&puzz[y][x],&puzz[ny][nx]);
    }
  }
  return -1;
}

int main(){
  int i,j,l;
  
  for(i=0;i<3;++i){
    for(j=0;j<3;++j)scanf("%d",&puzz[i][j]);
  }

  int x=0,y=0;
  empty(&x,&y);

  for(l=0;l<100;++l){
    for(i=0;i<3;++i){
      for(j=0;j<3;++j)temp[i][j] = puzz[i][j];
    }
 
    int ans = dfs(x,y,-1,0,l);
    if(ans!=-1){
      printf("%d\n",ans);
      break;
    }

    for(i=0;i<3;++i){
      for(j=0;j<3;++j)puzz[i][j] = temp[i][j];
    }

    ans  = -1;
    if(l==99)printf("%d\n",ans);
  }
  return 0;
}





Measured memory_bytes: 2112
/*
Author : Chandan Agrawal
College : Poornima College of Engg. jaipur, Raj
Mail : chandanagrawal23@gmail.com


" when you are not practicing someone else is ,
 and the day u meet them u will lose "

*/
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define MAX 200050

#define ll long long
#define ld long double
#define lli long long int

#define pb push_back
#define INF 1000000000000
#define mod 1000000007

// trignometric function always give value in Radians only
#define PI acos(-1) //3.1415926535897932384626433832795028
#define dsin(degree) sin(degree*(PI/180.0))
#define dcos(degree) cos(degree*(PI/180.0))
#define dtan(degree) tan(degree*(PI/180.0))

#define rsin(radian) sin(radian)
#define rcos(radian) cos(radian)
#define rtan(radian) tan(radian)

#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))

#define loop(i,n)  for (lli i = 0; i < n; i++)
#define FOR(i,a,b) for (lli i = a; i < b; i++)

#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define makeuniq(v) v.resize(unique(all(v)) - v.begin()); //only uniq element in vector after this
#define sz(x) int(x.size())
#define F first
#define S second

#define mii map<lli,lli>

#define pii pair<lli,lli>

#define vi vector<lli>
#define vvi vector<vi>
#define vpi vector<pii>
#define vbool vector<bool>

#define seti set<lli>

#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) (a/gcd(a,b))*b
#define abs(x) ((x < 0)?-(x):x)

#define endl '\n'

template <typename Head>
void print(Head&& head)
{
    cout<<head<<endl;
}
template <typename Head, typename... Tail>
void print(Head&& head, Tail... tail)
{
    cout<<head<<" ";
    print(tail...);
}

#define scanarr(a,n) for(lli i=0;i<n;i++)    cin>>a[i];
#define scanvec(a,n) for(lli i=0;i<n;i++){ lli x ; cin>>x; a.pb(x);}

#define printarr(a,n) for(lli i=0;i<n;i++)   cout<<a[i]<<" "; cout<<endl;
#define printvec(vec) for(auto xt : vec) cout<<xt<<" ";    cout<<"\n";

#define FD(N) fixed<<setprecision(N)

#define deb(x) cout<<#x<<" "<<x<<endl;

/*
1D vector -  vi dp(n,value);
2D vector -  vvi dp(n,vi(n,value));
*/

// chandan1,2
void chandan1(){int y=1;return;}
void chandan2(){
        loop(i,10){
        lli x=1;
    }
    return(chandan1());
}


int main(){
fastio
lli t=1;
//cin>>t;
chandan2();
while(t--) {
      lli n;
      cin>>n;
      print(1-n);
  }
return 0;
}



Measured memory_bytes: 3632
"""
B - Palace
"""
import numpy as np

n = int(input())
t, a = map(int, input().split())
h_list = []
for part in input().split():
    h_list.append(int(part))

temp_list = []
for h in h_list:
    # a度との二乗誤差
    temp_list.append((t - h * 0.006 - a) ** 2)

temp_list = np.array(temp_list, dtype=np.float32)

sort_arg = np.argsort(temp_list)

print(sort_arg[0] + 1)




Measured memory_bytes: 21656
from operator import itemgetter
N,M=map(int,input().split())
AB=[]
for i in range(N):
    ABtmp=list(map(int,input().split()))
    AB.append(ABtmp)
    
AB.sort(reverse=False,key=itemgetter(0))

ans=0
num=M
for i in range(N):
    if AB[i][1]>=M:
        ans+=AB[i][0]*M
        break
    else:
        ans+=AB[i][0]*AB[i][1]
        M-=AB[i][1]

print(ans)

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

#define rep(i, j, n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define Puts(x) puts(x? "Yes":"No")
const int mod = 1e9 + 7;

typedef long long i64;
typedef pair<int, int> pi;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

i64 gcd(int n, int m) {return (m == 0? n : gcd(m, n % m));}
i64 lcm(int n, int m) {return (n / gcd(n, m) * m);}
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};

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

  int x, y;
  cin >> x >> y;
  cout << x + y / 2 << endl;
}


Measured memory_bytes: 892
#include <cstdio>
#include<iostream>
#include<algorithm>

using namespace std ;
int main(){
int n ;
int a[15];
int x[15][15];
bool y[15][15];
int mmax=0;
cin >> n ;
for(int i=0;i<n;i++){
 cin >> a[i];
 for(int j=0;j<a[i];j++){
  cin>>x[i][j]>>y[i][j];
  }
 }
for(int bit=0;bit<(1<<n);bit++){
bool flag=1;
 for(int i=0;i<n;i++){
  for(int j=0;j<a[i];j++){
if(bit&(1<<i) && y[i][j]!= (bool)(bit&(1<<x[i][j]-1)))flag=0;
  }
 }
if(flag)mmax= max(__builtin_popcount(bit),mmax);
}
cout << mmax << endl;
return 0;
}

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

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	int big = max(a, max(b, c));
	int small = min(a, min(b, c));
	int mid = a+b+c-big-small;
	int b_m = big-mid;
	int m_s = mid - small;
	int co =0;
	if(m_s%2 == 0){
		co += m_s/2;
		co += b_m;
	}else{
		co += (m_s+1)/2;
		co += (b_m+1);
	}
	cout << co << endl;
}


Measured memory_bytes: 256
a,b,c,k = map(int,input().split())
ans = 0
v = min(a,k)
k -= v
ans += v
if k==0:
    print(ans)
    exit()
v = min(b,k)
k -= v
if k==0:
    print(ans)
    exit()
v = min(c,k)
ans -= v
print(ans)

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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n, m; cin >> n >> m;
    vector<int> a(n);
    int sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
    }
    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(a[i] * 4 * m >= sum) cnt++;
    }

    if(cnt >= m) cout << "Yes" << endl;
    else cout << "No" << endl;


    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
//30-39
int  main()
{
    int a, b, valid = 0, counter = 0;
    scanf("%d %d", &a, &b);
    char str[a+b+1];
    scanf("%s", str);

    for (int i = 0; i < a + b; i++)
    {
        if ((30 <= str[i] && str[i]<=  39)  || (str[a] == '-'))
        {
            if (str[i] == '-')
            {
                counter++;
            }
            
            valid = 1;
        }
        else
        {
            break;
        }
    }
    
    if (valid == 1 && counter == 1)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    

    return 0;
}

Measured memory_bytes: 1664
S=input()

ans=[]
count=0

for i in range(len(S)):
    if S[i]=="A" or S[i]=="C" or S[i]=="G" or S[i]=="T":
        count+=1
    else:
        ans.append(count)
        count=0

ans.append(count)

print(max(ans))

Measured memory_bytes: 3060
INF = 10 ** 9
MOD = 10 ** 9 + 7
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  math import factorial


def main():
    n = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    if sum(a) < sum(b):
        print(-1)
        return
    c = [p - q for p,q in zip(a,b)]
    c.sort(reverse=True)
    minus = 0
    ans = 0
    for i in range(n - 1,-1,-1):
        if c[i] < 0:
            minus += c[i]
            ans += 1
        else:
            break
    
    for i in range(n):
        if minus >= 0:
            break
        minus += c[i]
        ans += 1
    print(ans)
if __name__ == '__main__':
    main() 

Measured memory_bytes: 19660
#include <bits/stdc++.h>
#define MAXN 200005
#define MAXM 100005
#define from first
#define to second
using namespace std;
struct arm
{
    int x,y;
    bool operator< (const arm &b) const
    {
        return x<b.x;
    }
}arms[MAXM];
int n,m;
pair<int,int> ans[MAXN];

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;++i)
        scanf("%d%d",&(arms[i].x),&(arms[i].y));
    for(int i=1;i<=n;++i)
        ans[i].from=ans[i].to=i;
    sort(arms,arms+m);
    for(int i=0;i<m;++i)
    {
        int y=arms[i].y;
        ans[y].from=ans[y+1].from=min(ans[y].from,ans[y+1].from);
        ans[y].to=ans[y+1].to=max(ans[y].to,ans[y+1].to);
    }
    for(int i=1;i<=n;++i)
    {
        if(i>1)
            printf(" ");
        printf("%d",ans[i].to-ans[i].from+1);
    }
    printf("\n");
}

Measured memory_bytes: 5592
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(i, x.size()) cerr << x[i] << (i == x.size() - 1 ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;
const int FIVE = 101010;

//=============================
int N, M, K;
string S, T;
vector<int> A;
vector<int> B;
//=============================
void input()
{
    cin >> N;
    A.resize(N);
    rep(i, N)
    {
        cin >> A[i];
    }
}
//=============================
void func() {}
//=============================
void solve()
{
    int ans = 0;
    int r = 0;
    int sum = 0;
    rep(l, N)
    {
        for (; (r < N && ((sum & A[r]) ==0)); ++r)
        {
            sum += A[r];
        }
        ans += r - l; // 条件に合致
        if (l == r){
            ++r;
        }
        else
        {
            sum ^= A[l];
        }
    }
    cout << ans << endl;
}
//=============================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 1792
n = input()
a = [int(value) for value in input().split()]

def num_two(input_number):
  number = input_number
  count = 0
  while True:
    if number % 2 == 0:
      count += 1
      number = number / 2
    else:
      break
  return count

num_twos = [num_two(ai) for ai in a]
# print(num_twos)
print(min(num_twos))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=500005;
//i_am_noob
int k,x=-1,ans=0;
string str;
vector<int> vec;
bool flag,flag2=false;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> str >> k;
	rep(sz(str)){
		flag=false;
		if(i==sz(str)-1) flag=true;
		else if(str[i]!=str[i+1]) flag=true;
		if(flag){
			vec.pb(i-x);
			x=i;
		}
	}
	rep(sz(str)-1) if(str[i]!=str[i+1]) flag2=true;
	if(!flag2){
		print1(sz(str)*k/2);
		return 0;
	}
	if(str[0]!=str[sz(str)-1]){
		rep(sz(vec)) ans+=vec[i]/2*k;
	}
	else{
		rep2(i,1,sz(vec)-1) ans+=vec[i]/2*k;
		ans+=vec[0]/2+vec[sz(vec)-1]/2+(vec[0]+vec[sz(vec)-1])/2*(k-1);
	}
	print1(ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n;
   cin>>n;
   vector<int> dp(n+1,0);
  vector<int> a(n+1);
   a[0]=INT_MAX;
   for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=2;i<=n;i++)
     {
       dp[i]=min(dp[i-2]+abs(a[i-2]-a[i]),dp[i-1]+abs(a[i-1]-a[i]));
    }
   cout<<dp[n]<<"\n";
}

Measured memory_bytes: 4052
#pragma GCC optimize "03"
#include "bits/stdc++.h"
using namespace std;
 
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 80005;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
 
int dp[105][N], l[N], r[N];

signed main() {
    IOS;
    #ifdef LOCAL
        freopen("input.txt","r", stdin);
        freopen("output.txt","w",stdout);
    #endif
    int n, k;
    cin >> n >> k;
    int p;
    l[0] = 0, r[0] = 0;
    for(int i = 1; ; i++){
        l[i] = r[i-1] + 1;
        r[i] = n/(n/l[i]);
        dp[1][i] = r[i] - l[i] + 1;
        dp[1][i] += dp[1][i-1];
        dp[1][i] %= mod;
        if(r[i] == n){
            p = i;
            break;
        }
    }
    for(int i = 2; i <= k; i++){
        for(int j = 1; j <= p; j++)
            dp[i][j] = ((r[j]-l[j]+1)*dp[i-1][p - j + 1]) % mod;
        for(int j = 1; j <= p; j++)
            dp[i][j] = (dp[i][j] + dp[i][j-1]) % mod;
    }
    cout << dp[k][p] << endl;
    return 0;
}

Measured memory_bytes: 64896
//PKMKB
#include <bits/stdc++.h>
#define ll long long int
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define scanarr(a,b,c) for( i=b;i<c;i++)cin>>a[i]
#define showarr(a,b,c) for( i=b;i<c;i++)cout<<a[i]<<' '
#define ln cout<<'\n'
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 1000000007
#define MAX 100005
using namespace std;
////////////////////////////////////////////////////////////////CODE STARTS HERE////////////////////////////////////////////////////////////////

void solve(){
	
	vector <int> ans(10005, 0);
	int a, b, c, i;
	int tmp;

	for(a = 1; a < 100; a++){
		for(b = 1; b < 100; b++){
			for(c = 1; c < 100; c++){
				tmp = a*a + b*b + c*c + a*b + b*c +a*c;
				if(tmp < 10001)
					ans[tmp]++;
			}
		}
	}
	int n;
	cin >> n;

	for(i = 1; i <=n; i++)
		cout  << ans[i] << endl;

}
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	#endif
	

		solve();
}

Measured memory_bytes: 3612
n, m, x = map(int, input().split())
A = list(map(int, input().split()))

cnt1, cnt2 = 0, 0
for a in A:
    if a < x:
        cnt1 += 1
    if a > x:
        cnt2 += 1
        
ans = min(cnt1, cnt2)
print(ans)

Measured memory_bytes: 9112
#include<iostream>
#include <string>
using namespace std;
int main(){
string O,E,A,b,c;
cin>>O;
cin>>E;
for(int i=0;O.size() >= i;i++){
 b = O.substr(i,1);
 if(i<=E.size()){c = E.substr(i,1);
 
 }
 A += b+c;
 


}
cout<<A<<endl;
return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
using namespace std;
int main(){
  int a[4],b[4];
  while(cin>>a[0]){
    for(int i=1;i<4;i++){
      cin>>a[i];
    }
    for(int i=0;i<4;i++){
      cin>>b[i];
    }
    int hit=0,brow=0;
    for(int i=0;i<4;i++){
      if(a[i]==b[i]){
	hit++;
      }
    }
    for(int i=0;i<4;i++){
      for(int j=0;j<4;j++){
	if(a[i]==b[j]){
	  brow++;
	}
      }
    }
    cout<<hit<<" "<<brow-hit<<endl;
  }
  return 0;   
}

Measured memory_bytes: 2988
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    ll N, W;
    cin >> N >> W;
    ll w[N], v[N];
    for(int i = 0; i < N; i++) cin >> w[i] >> v[i];

    ll dp[100001];
    for(int i = 0; i <= 100000; i++) dp[i] = inf;
    dp[0] = 0;
    for(int i = 0; i < N; i++) {
        for(int j = 100000; j >= 0; j--) {
            if(dp[j] == inf) continue;
            if(dp[j] + w[i] <= W) dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i]);
        }
    }

    for(int i = 100000; i >= 0; i--) {
        if(dp[i] != inf) {
            cout << i << "\n";
            return 0;
        }
    }
}

Measured memory_bytes: 4464
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        int N = int.Parse(ReadLine());
        List<long> A = new List<long>();
        A.Add(0);
        A.AddRange(ReadLine().Split().Select(long.Parse));
        A.Add(0);

        long sum = 0;

        for (int i = 0; i < A.Count-1; i++)
        {
            sum += Abs(A[i] - A[i + 1]);
        }
        for (int i = 0; i < N; i++)
        {
            long m = Abs(A[i] - A[i + 1]) + Abs(A[i + 1] - A[i + 2]) - Abs(A[i] - A[i + 2]);
            WriteLine(sum-m);
        }
    }
}


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

int main() {
    char S1[52];
    char S2[52];
    unsigned long long int ans = 1;
    int n;

    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> S1[i];
    }

    for (int j = 0; j < n; j++) {
        cin >> S2[j];

    }
    //if (S1[0] == S2[0]) ans = 3;
    //else {ans = 6;}
    //
    //if ( n <= 3) {
    //    cout << ans << endl;
    //    return 0;
    //}
    
    
    for (int i=0; i < n ; i++ ){
        if (i == 0){
            if (S1[i] == S2[i]) ans = 3;
            else {
                ans = 6;
                i++;
            }
        }

        else{

            if (S1[i-1] == S2[i-1])  {
                if (S1[i] == S2[i])  {
                    ans = ans * 2;
                }
                else {
                    ans = ans * 2;
                    i++;
                }

            }
            else {
                if (S1[i] == S2[i])  {
                    ans = ans * 1;
                }
                else {
                    ans = ans * 3;
                    i++;
                }
            }
        }
    } 

    cout << ans % 1000000007 << endl;


    return 0;
}

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

class Main{
    public static void main(String[] args){
        FastScanner fsc=new FastScanner();
        int n=fsc.nextInt();
        ArrayList<Integer> edges[]=new ArrayList[n];
        long[] pairs=new long[n-1];
        int[] pcol=new int[n];
        for(int i=0;i<n-1;i++){
            int a=fsc.nextInt()-1, b=fsc.nextInt()-1;
            if(edges[a]==null) edges[a]=new ArrayList<Integer>();
            edges[a].add(b);
            pairs[i]=(long)a*n+b;
        }
        fsc.close();
        HashMap<Long, Integer> colors=new HashMap<>();
        int dim=0;
        for(int v=0;v<n;v++){
            if(edges[v]==null) continue;
            int c=0;
            for(int u:edges[v]) colors.put((long)v*n+u, pcol[u]=pcol[v]==++c?++c:c);
            if(c>dim) dim=c;
        }
        PrintWriter pw=new PrintWriter(System.out);
        StringBuilder sb=new StringBuilder();
        sb.append(dim).append("\n");
        for(int i=0;i<n-1;i++) sb.append(colors.get(pairs[i])).append("\n");
        pw.print(sb); pw.flush();
    }
}
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte(){
        if(ptr<buflen) return true;
        else{
            ptr = 0;
            try{
                buflen = in.read(buffer);
            }
            catch(IOException e){
                e.printStackTrace();
            }
            if(buflen<=0) return false;
        }
    return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) throw new NumberFormatException();
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }
            else if(b == -1 || !isPrintableChar(b)) return minus ? -n : n;
            else throw new NumberFormatException();
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
    public void close(){
        try{in.close();}
        catch(IOException e){e.printStackTrace();}
    }
}

Measured memory_bytes: 55044
#include <iostream>
using namespace std;
int main(void){
    int A,B,C;
    cin >> A >> B >> C;
    if (A==5 && B==5 && C==7){
        cout << "YES" << endl;
        }else if (A==7 && B==5 && C== 5){
            cout << "YES" << endl;
        }else if (A==5 && B==7 && C==5){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
abs_A = list(map(lambda x: abs(x), A))

pos = []
neg = []
ans = 0

for e in A:
    if e > 0:
        pos.append(e)
    else:
        neg.append(e)
if len(neg) % 2 == 0:
    ans = sum(abs_A)
else:
    """pos.sort(reverse=True)
    neg.sort(reverse=True)
    if len(neg) == N:
        ans = -sum(neg[:-1]) + neg[-1]
    else:"""
    #ans = max(-sum(neg[:-1]) + neg[-1], -sum(neg[:-3]) + sum(neg[-3:]))
    #ans = max(sum(pos[:-1])-pos[-1]-sum(neg), sum(pos) + neg[0] -sum(neg[1:]))
    ans = sum(abs_A)
    ans -= 2 * min(abs_A)
print(ans)

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

int main() {
  int N,
      m = 0,
      i = 1;
  cin >> N;
  vector<int> a(N);
  vector<bool> b(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  while (true) {
    m++;
    i = a.at(i - 1);
    if (i == 2) {
      break;
    }
    if (b.at(i - 1)) {
      m = -1;
      break;
    }
    b.at(i - 1) = true;
  }
  cout << m << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int a,b;
    int c;
    int e;
    cin>>a>>b;
    c=b*2;
    e=a-c;
    if(c>=a)
    {
        cout<<0;
    }
    if(a>c)
    {
        cout<<e;
    }



    return 0;
}


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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)
#define rep1(i,n) for(auto i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;


struct init{ init(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); }; }aaaaaaa;


int main(){
  ll n, m;
  cin >> n >> m;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];


  priority_queue<ll> que;
  rep(i, n) que.push(a[i]);

  rep(i, m){
    ll x = que.top(); que.pop();
    x /= 2;
    que.push(x);
  }

  ll sum = 0;
  rep(i, n) sum += que.top(), que.pop();

  cout << sum << endl;




  return 0;
}


Measured memory_bytes: 2296
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <iostream>
#define maxn 100009
using namespace std;
const int MOD = 1e9 + 7;
int X[maxn], a[maxn];
long long solve(int n){
	for(int i = 1; i <= n; i++)
		scanf("%d", &X[i]);
	for(int i = 1; i < n; i++){
		a[i] = X[i + 1] - X[i];
	}
	n--;
	long long ans = 0;
	for(int i = 1; i <= n; i++){
		ans = ans + 1LL * a[i] * i % MOD * (n - i  + 1) % MOD;
		ans %= MOD;
	}
	return ans;
}
int main(){
	int n, m;
	cin >> n >> m;
	long long ans = solve(n) * solve(m) % MOD;
	cout << ans << endl;
	return 0;
}

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

namespace agc030_a
{
    class Program
    {
        static void Main(string[] args)
        {
            var text = Console.ReadLine();
            var list = text.Split(' ').ToList();

            var r = int.Parse(list[0]);
            var n = int.Parse(list[1]);
            
            Console.WriteLine(r - n + 1);
        }
    }
}


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

int main(void) {
	int x,y;
	
	while (true)
	{
		cin >> x >> y;
		if (x == 0 && y ==0)
		{
			break;
		}

		if (x > y)
		{
			cout << y << " " << x << endl;
		}
		else
		{
			cout << x << " " << y << endl;
		}
	}

	return 0;
}


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

#define rep(i,n)  for(int i=0;i<n;++i)
#define per(i,n)  for(int i=n-1;i>=0;--i)
#define sc1(a)  scanf("%d",&a)
#define sc2(a,b)  scanf("%d %d",&a,&b)
#define sc3(a,b,c)  scanf("%d %d %d",&a,&b,&c)
#define sl1(a)  scanf("%lld",&a)
#define sl2(a,b)  scanf("%lld %lld",&a,&b)
#define sl3(a,b,c)  scanf("%lld %lld %lld",&a,&b,&c)
#define PI 3.1415926535897932

int main(){
    int r,c;
    sc2(r,c);
    int sp[r+1][c+1];
    rep(i,r+1) rep(j,c+1) sp[i][j]=0;
    rep(i,r) rep(j,c) sc1(sp[i][j]);
    rep(i,r+1) {
        rep(j,c) {
            printf("%d ",sp[i][j]);
            sp[i][c]+=sp[i][j];
            if (i<r) sp[r][j]+=sp[i][j];
        }
        printf("%d\n",sp[i][c]);
    }
    return 0;
}



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



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

    rep(i,a) {
        rep(j,b) {
            rep(k,c) {
                int tmp = 500*i+100*j+50*k;
                if(tmp == x) ans++;
            }
        } 
    }

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





Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tii;
#define rep(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

int main(){
  ll N; cin >> N;
  ll A[N];
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  sort(A,A+N);
  ll ans = 0;
  for(int i=1;i<N;i++){
    ll x = i/2;
    ans += A[N-1-x];
  }
  cout << ans << endl;
}



Measured memory_bytes: 5160
n, m = [int(i) for i in input().split()]
a = [0 for i in range(m)]
b = [0 for i in range(m)]
semiGoal = [0 for i in range(n)]
for i in range(m):
    a[i], b[i] = [int(i) - 1 for i in input().split()]
    if b[i] == n-1:
        semiGoal[a[i]] = 1
for i in range(m):
    if a[i] == 0 and semiGoal[b[i]] == 1:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")

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

int A, B, C, X, Y;

int main() {
    cin >> A >> B >> C >> X >> Y;

    long long ans = 1e10;
    for (int i = 0; i <= 1e5; i++) {
        long long tmp = (i * 2 * C) + A * max(X - i, 0) + B * max(Y - i, 0);
        ans = min(tmp, ans);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){

int n;
  cin >> n;
  
long sum=0;
  long a[n];
int counts=0;
long amin;
  
  amin=10000000000;
  
  for(int i=0;i<n;i++){
   cin >> a[i];
    if(a[i]<=0){
    counts++;
    }
   sum+=abs(a[i]);
    amin=min(amin,abs(a[i]));
  }
    
if(counts%2==0){
 cout << sum << endl;
}
else{
 cout << sum-2*amin << endl; 
}


}

Measured memory_bytes: 1024
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll inf = 1e9 + 7;
const ll Mod = 998244353;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

bool flag(int num){
  if (num % 3 == 0) return true;
  while (num > 0){
    if (num % 10 == 3) return true;
    num /= 10;
  }
  return false;  
}

int main(){
  int N; cin >> N;
  for (int i = 1; i <= N; i++){
    if (flag(i)) cout << " " << i;
  }
  cout << endl;
  
  return 0;
}



Measured memory_bytes: 3076
N = int(input())
a = list(map(int, input().split()))

a.sort()
a.reverse()

Alice = 0
Bob  = 0

for i in range(len(a)):
    if i % 2 == 0:
        Alice = Alice + a[i]
    else:
        Bob = Bob + a[i]

print(Alice - Bob)

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

int main() {
  int N;
  cin >> N;
  vector<int> a(3*N);
  for (int i= 0; i < 3*N; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  
  int64_t sum = 0;
  for (int i = 1; i < 2*N; i+=2) {
    sum += a.at(i);
  }
  cout << sum << endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <algorithm>
#define N 102
using namespace std;
typedef long long ll;
const ll mod = 1000000007LL;
int n;
ll k;
vector<pair<int, int>> nums;
int main() {
	cin>>n>>k;
	nums.clear();
	for (int i = 1; i <= n; ++i) {
		int a, b;
		cin>>a>>b;
		nums.push_back(make_pair(a, b));
	}
	sort(nums.begin(), nums.end());
	ll tot=0;
	int i;
	for (i = 0; i < n; ++i) {
		if (tot + nums[i].second >= k) {
			break;
		}
		tot += nums[i].second;
	}
	cout<<nums[i].first<<endl;
	return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	vector<int> b(n);
	for (int i = 0; i < n - 1; i++) {
		cin >> b[i];
	}
	int sum = b[0] + b[n - 2];
	for (int i = 0; i < n - 1; i++) {
		sum += min(b[i], b[i + 1]);
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 256
def f(n):
    return n//2 if n%2==0 else 3*n + 1

s = int(input())
a = {s}
n = s
for i in range(2, 1000000):
    n = f(n)
    if n not in a:
        a.add(n)
    else:
        print(i)
        break

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

int main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == ',') {
			s[i] = ' ';
		}
	}
	
	cout << s << endl;
	
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <assert.h>
long xxx[10][1001][101];

long pattern(int n,int s,int from){
	long i,x=0;
	if(xxx[n][s][from]>=0)x=xxx[n][s][from];
	else{
		for(i=(s-100*(n-1)>from?s-100*(n-1):from); i<100 && i<=s ;i++){x+=pattern(n-1,s-i,i+1);}
		xxx[n][s][from]=x;
	}
	return x;
}

long pattern2(int n,int s,int from){
    if(n>1){
        long i,x=0;
        if(xxx[n][s][from]>=0)x=xxx[n][s][from];
        else{
        for(i=s-100*(n-1)>from?s-100*(n-1):from; i<100 && i<=s ;i++){x+=pattern(n-1,s-i,i+1);}
        xxx[n][s][from]=x;
        }
        return x;
    }
    else{if(from<=s && s<=100)return 1; else return 0;}
}

int main(void){
    int n,s,i,j,k;
	for(j=0;j<1001;j++){for(k=0;k<101;k++){xxx[1][j][k]=( (j<=100 && k<=j)?1:0 );}}
	for(i=2;i<10;i++){for(j=0;j<1001;j++){for(k=0;k<101;k++){xxx[i][j][k]=-1;}}}
    while(scanf("%d %d",&n,&s)*(n+s)){
	if(pattern(n,s,0)!=pattern2(n,s,0)){
		fprintf(stderr,"%d %d\n",n,s);
		assert(0);
	}
	printf("%ld\n",pattern(n,s,0));}
    return 0;
}

Measured memory_bytes: 7712
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

using VLL = vector <long long>;
using VVLL = vector <VLL>;
using VVVLL = vector <VVLL>;

int main() {
    int R;
    int C;
    int K;

    cin >> R >> C >> K;

    VVVLL dp(R, VVLL(C, VLL(4)));
    VVLL val(R, VLL(C, 0));

    for (int k = 0; k < K; ++k) {
        int r;
        int c;
        cin >> r >> c;
        --r;
        --c;
        cin >> val[r][c];
    }

    dp[0][0][0] = 0;
    dp[0][0][1] = val[0][0];

    for (int i = 0; i < R; ++i) {
        for (int j = 0; j < C; ++j) {
            // if (val[i][j] <= 0) {
            //     continue;
            // }

            for (int v = 0; v < 4; ++v) {
                // go down
                if (i+1 < R) {
                    if (val[i+1][j] > 0) {
                        dp[i+1][j][1] = max(dp[i+1][j][1], dp[i][j][v] + val[i+1][j]);
                    }

                    dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][v]);
                }

                // go right
                if (j+1 < C) {
                    if (val[i][j+1] > 0 && v < 3) {
                        dp[i][j+1][v+1] = max(dp[i][j+1][v+1], dp[i][j][v] + val[i][j+1]);
                    }

                    dp[i][j+1][v] = max(dp[i][j+1][v], dp[i][j][v]);
                }
            }
        }
    }

    long long best = 0;

    for (int v = 0; v <= 3; ++v) {
        best = max(best, dp[R-1][C-1][v]);
    }

    cout << best << endl;

    return 0;
}

Measured memory_bytes: 706496
#include<cstdio>

int search(char a[][1000],int next){

  if(a[next][0]==0){
    return next;
  }

  int go = a[next][0]-'a';
  int i;
  for(i=0;a[next][i]!=0;i++){
    a[next][i]=a[next][i+1];
  }
  a[next][i]=0;

  return search(a,go);
}

int main(void){
  char a[3][1000];


  scanf("%s %s %s",a[0],a[1],a[2]);

  int ans = search(a,0);

  printf("%c\n",ans+'A');

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
/* ------------------------------------------------ */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcm(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcm(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcm(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ------------------------------------------------ */

int main() {
    int n;
    cin >> n;
    ll a[110];
    ll mi = 1e14;
    ll ma = -1;
    rep(i, n) {
        cin >> a[i];
        ma = max(ma, a[i]);
        mi = min(mi, a[i]);
    }
    cout << ma - mi << endl;
}

Measured memory_bytes: 3524
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

n,q=nii()
uf=UnionFind(n)
for i in range(q):
  t,u,v=nii()
  if t==0:
    uf.union(u,v)
  else:
    if uf.same(u,v):
      print(1)
    else:
      print(0)

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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

#define LOCAL
#ifdef LOCAL
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else 
#define dump(x) true
#endif

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

string solve(string s) {
	V<int> apos, bpos;
	int n = s.size();
	rep(i, n) {
		if (s[i] == 'a') {
			apos.pb(i);
		} else {
			bpos.pb(i);
		}
	}
	dump(apos);
	dump(bpos);
	string res;

	if (s[0] == 'b') {
		rep(i, apos.size()) {
			string tmp;
			rep(j, n) {
				if (s[j] == 'a' && j >= apos[i]) {
					tmp.pb(s[j]);
				} else if (s[j] == 'b' && j >= bpos[i]) {
					tmp.pb(s[j]);
				}
			}
			chmax(res, tmp);
		}
	} else {
		int p = 0;
		int now = 0;
		while (p < n) {
			while (now < apos.size() && apos[now] < p) {
				++now;
			}
			if (now != apos.size()) {
				res.pb('a');
				res.pb('b');
				p = bpos[now];
			} else {
				break;
			}
		}
	}

	return res;
}

int main() {
	int n;  cin >> n;
	string s; cin >> s;

	string cur;
	int c = 0;
	string ans;

	V<string> cand;

	rep(i, n * 2) {
		if (s[i] == 'a') {
			++c;
			cur.pb(s[i]);
		} else {
			--c;
			cur.pb(s[i]);
		}

		if (c == 0) {
			cand.pb(solve(cur));
			cur = "";
		}
	}

	int sz = cand.size();
	V<string> dp(sz + 1);
	for (int i = sz - 1; i >= 0; --i) {
		dp[i] = max(dp[i+1], cand[i] + dp[i+1]);
	}
	cout << dp[0] << endl;
	return 0;
}

Measured memory_bytes: 10624
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

signed main() {
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    vector<int> v;
    for (int i=0; i<n; i++) {
        int tp;
        cin >> tp;
        v.push_back(tp);

    }
    int sum = accumulate(v.begin(),v.end(),0);
    int ans = 0;
    for (int i=0; i<n; i++) {
        ans += (sum-v[i])*v[i];
    }
    cout << ans/2 << endl;
    return 0;
}


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

public class Main {

	public static void main (String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] ss = br.readLine().split(" ", 2);
		int n = Integer.parseInt(ss[0]);
		int k = Integer.parseInt(ss[1]);
		String[] arr = br.readLine().split(" ", n);
		Arrays.sort(arr);
		ArrayList<Integer> list = new ArrayList<>();
		int count = 0;
		for (int i = 0; i < n; i++) {
			if (i != 0 && !arr[i - 1].equals(arr[i])) {
				list.add(count);
				count = 1;
			} else {
				count++;
			}
		}
		if (count != 0) {
			list.add(count);
		}
		
		Collections.sort(list);
		int total = 0;
		for (int i = 0; i < list.size() - k; i++) {
			total += list.get(i);
		}
		System.out.println(total);
	}
}


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

int N;
LL A[200000];

int main() {
 scanf("%d",&N);
 rep(i,N) scanf("%lld",&A[i]);
 LL ans=0;
 rep(i,N-1){
  LL tmp=max(A[i+1],A[i]);
  ans+=tmp-A[i+1];
  A[i+1]=tmp;
 }
 printf("%lld\n",ans);
 return 0;
}

Measured memory_bytes: 5312
n = int(input())
hs = list(map(int, input().split()))

mstep, step = 0, 0
for i in range(n - 1):
    if hs[i] >= hs[i + 1]:
        step += 1
    else:
        mstep = max(mstep, step)
        step = 0
else:
    mstep = max(mstep, step)
print(mstep)


Measured memory_bytes: 14224
import java.util.Scanner;
public class Main {

    public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
    	// 入力
    	int d = sc.nextInt();
    	String ans ="";

    	if (d==25){
    		ans = "Christmas";
    	} else if (d==24){
    		ans = "Christmas Eve";
    	} else if (d==23){
    		ans = "Christmas Eve Eve";
    	} else if (d==22){
    		ans = "Christmas Eve Eve Eve";
    	}
    	// 出力
    	System.out.println(ans);
    }
}

Measured memory_bytes: 21460
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#define rep(i,m,n) for(int i=m; i<(n); i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int, int> pii;
ll inf=1LL<<60;
double eps=1e-14;

int main()
{
    int x, a;
    cin >> x >> a;
    if(x<a) cout << 0;
    if(x>=a) cout << 10;
}


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

using Lint=long long;

Lint solve(Lint X,Lint Y)
{
    if(X+Y==0) return -1;

    if(X<0) X=-X,Y=-Y;
    if(X==0) return 1;
    else{
        if(X+Y>0) return 0;
        else{
            Lint res=X/abs(X+Y)*2;
            if(X%abs(X+Y)!=0) res++;
            return res;
        }
    }
}

int main()
{
    Lint t[2],a[2],b[2];
    cin>>t[0]>>t[1]>>a[0]>>a[1]>>b[0]>>b[1];

    Lint X=(a[0]-b[0])*t[0];
    Lint Y=(a[1]-b[1])*t[1];
    Lint ans=solve(X,Y);
    if(ans==-1) cout<<"infinity"<<endl;
    else cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i+=1)
#define reps(i,a,b) for(int i=a;i>=b;i-=1)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pi pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define in1(x) int x; cin>>x;
#define in2(x, y) int x, y; cin>>x>>y;
#define in3(x, y, z) int x, y, z; cin>>x>>y>>z;
#define in4(x, y, z, w) int x, y, z, w; cin>>x>>y>>z>>w;
#define mi unordered_map<int,int>
#define mem(x) memset(x, 0, sizeof(x))
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
using namespace std;

//bool primes[1000001];vi prime;
//void seive(){memset(primes, true, sizeof(primes));primes[0] = primes[1] = false;for(int i = 2; i*i<=1000000;i += 1){
//if(primes[i]){for(int j = i*i; j <= 1000000;j += i) primes[j] = false;}}rep(i, 2, 1000001){if(primes[i]) prime.pb(i);}}

//int gcd(int a, int b){return b==0 ? a : gcd(b, a%b);}

int32_t main(void){
	IOS;
	
	in1(n);
	
	int ans = 0;
	
	while(n%((int)pow(2, ans+1)) == 0)
	{
	    n /= pow(2, ans+1);
		ans += 1;
	}
	
	while(n%2 == 0) n/= 2;
// 	cout<<ans<<endl;
	for(int i=3; i*i <= n; i += 2)
	{
		int val = 1;
		while(n%(int)pow(i, val) == 0)
		{
			n /= pow(i, val);
			val+=1;
			ans+=1;
		}
		while(n%i == 0) n/=i;
	}
// 	cout<<n<<endl;
	if(n != 1) ans += 1;
	cout<<ans<<endl;
}


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

int main(){
  vector<vector<char>>c(3,vector<char>(3));
  for(int i = 0;i < 3; i++){
    for(int j = 0;j < 3;j++){
      cin >> c.at(i).at(j);
    }
  }
  for(int i = 0; i < 3; i++){
    cout << c.at(i).at(i);
  }
  cout << endl;
}



Measured memory_bytes: 256
def submit():
    n, k = map(int, input().split())
    treat = {i:False for i in range(1, n + 1)}
    
    for _ in range(k):
        d = int(input())
        a = list(map(int, input().split()))
        for s in a:
            treat[s] = True

    print(n - sum(treat.values()))


submit()

Measured memory_bytes: 9180
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        long sum = 0;
        for(int i = 0; i < N; i++) {
            sum += Integer.parseInt(sc.next()) - 1;
        }
    
        System.out.println(sum);
        
    }
}

Measured memory_bytes: 25300