akhauriyash/Code-Regression huggingface dataset:
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007ll //998244353ll
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second 
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)    
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const long long N=200005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }
int par[N],siz[N];

int findset(int a)
{
    if(par[a]==a)
    return a;
    return par[a]=findset(par[a]);
}

void unionset(int a, int b)
{
    a=findset(a);
    b=findset(b);
    if(a==b)
    return;
    if(siz[a]>siz[b])
    swap(a, b);
    par[a]=b;
    siz[b]+=siz[a];
}

int32_t main()
{
    IOS;
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        par[i]=i;
        siz[i]=1;
    }
    while(m--)
    {
        int a,b;
        cin>>a>>b;
        unionset(a, b);
    }
    set <int> s;
    for(int i=1;i<=n;i++)
    s.insert(findset(i));
    int ans=s.size();
    cout<<ans-1;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    
    int dist = 0;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        dist += 2 * min(x, k - x);
    }

    cout << dist << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(n * a < b) System.out.println(n * a);
		else System.out.println(b);
		sc.close();
	}
}

Measured memory_bytes: 21972
#include<stdio.h>
#include<math.h>
int find_group(long int num){
	int len = 1;
	while(num > (pow(26, len) - 1) * 26 / 25)
		len++;
	return len;
}
int find_subgroup(long int num, int len){
	int q = 1;
	while(num > pow(26, len-1) * q)
		q++;
	return q - 1;
}
int main(){
	long int num;
    int len;
	scanf("%ld", &num);
	len = find_group(num);
	num = num - (pow(26, len - 1) - 1) * 26 / 25;
	while(len > 1){
		int n_subgroup = find_subgroup(num, len);
		printf("%c", 'a' + n_subgroup);
		num = num - pow(26, len-1) * n_subgroup;
		len--;
	}
	printf("%c", 'a' + num - 1);
	return 0;
}

Measured memory_bytes: 2508
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] t= new int[N+10];
		int[] x= new int[N+10];
		int[] y= new int[N+10];
		for (int i=0;i<N;i++) {
			t[i] = sc.nextInt();
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
		}

		int X=0;
		int Y=0;
		int T=0;
		int flag=0;

		for (int i=0;i<N;i++) {
			if (((Math.abs(x[i]-X)+Math.abs(y[i]-Y))<=(t[i]-T))&&(((t[i]-T)-(Math.abs(x[i]-X)+Math.abs(y[i]-Y)))%2==0)) {
				X=x[i];
				Y=y[i];
				T=t[i];
			}else {
				flag=1;
				break;
			}
		}

		if (flag==0) {
			System.out.println("Yes");
		}else if (flag==1) {
			System.out.println("No");
		}
	}
}

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

int a[100010];

int main(){
	int n, ans=0, c=1;
	cin >> n;
	for(int i=0; i<n; i++) cin >> a[i];
	sort(a, a+n);
	for(int i=0; i<n-1; i++){
		if(a[i]==a[i+1]){
			c++;
		}else{
			if(c>a[i]) ans += c-a[i];
			else if(c<a[i]) ans += c;
			c=1;
		}
	}
	if(a[n-1]>c) ans += c;
	else ans += c-a[n-1];
	cout << ans << endl;
}


Measured memory_bytes: 640
import sys
input = sys.stdin.readline

H, W = (int(i) for i in input().split())
A = [[int(i) for i in input().split()] for j in range(H)]

reslis = []
flag = False
for i in range(H):
    if i % 2 == 0:
        for j in range(W):
            if j == W-1:
                ne = (i + 1, j)
            else:
                ne = (i, j + 1)

            if A[i][j] % 2 == 1:
                if flag:
                    flag = False
                else:
                    flag = True
            
            if flag and ne[0] <= H - 1:
                reslis.append("{} {} {} {}".format(i+1,j+1,ne[0]+1,ne[1]+1))

    else:
        for j in range(W-1, -1, -1):
            if j == 0 :
                ne = (i + 1, j)
            else:
                ne = (i, j - 1)

            if A[i][j] % 2 == 1:
                if flag:
                    flag = False
                else:
                    flag = True

            if flag and ne[0] <= H - 1:
                reslis.append("{} {} {} {}".format(i+1,j+1,ne[0]+1,ne[1]+1))

print(len(reslis))
for st in reslis:
    print(st)

Measured memory_bytes: 70108
#include <iostream>
#include <set>
using namespace std;
int main()
{
    int a, n;
    set<int> st;
    cin >> n;
    for(int i = 0; i < n; i++) {
        scanf("%d", &a);
        st.insert(a);
    }
    cout << (n == st.size() ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;


long long N, A[1000000], B[1000000], i;

int main() {

	cin >> N;
	vector<pair<int, int>>pairs(N);
	for (i = 0; i < N; i++) {
		cin >> A[i] >> B[i];
		swap(A[i], B[i]);
		pairs[i] = make_pair(A[i], B[i]);
	}
	sort(pairs.begin(), pairs.end());

	int judge = 0, J = 0;

	for (i = 0; i < N; i++){
		judge += pairs[i].second;
		if (pairs[i].first < judge) {
			cout << " No" << endl;
			J = 1;
			break;
		}
	}
	if (J == 0)
		cout << "Yes" << endl;
}

Measured memory_bytes: 7424
def array_converter(i)
  num_array=[]
  for num in 1..i
    line = readline.split(/[[:space:]]/)
    if judge_key_and_calc(num_array,line[0],line[1])
      num_array.unshift line[1]
    end
  end
  num_array
end

def judge_key_and_calc(array,key,val)
  if key == "delete"
    if array.index(val) != nil
      array.delete_at(array.index(val))
    end
    false
  elsif key == "deleteFirst"
    array.shift
    false
  elsif key == "deleteLast"
    array.pop
    false
  else
    true
  end
end

def queue_calc
  num = readline.to_i
  array_converter(num).join(" ")
end

puts queue_calc

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

int main() {
  string s;
  cin >> s;
  int n = s.size(), a = 0, tmp = 0;
  rep(i, n){
    if(i < n-1 && ('9' - s[n-i-1]) + 1 - tmp == (s[n-i-1] - '0') + tmp){
      if(s[n-i-2] > '4'){
        a += ('9' - s[n-i-1]) + 1 - tmp;
        tmp = 1;
      }
      else{
         a += (s[n-i-1] - '0') + tmp;
      tmp = 0;
      }
    }
    else if(('9' - s[n-i-1]) + 1 - tmp < (s[n-i-1] - '0') + tmp){
      a += ('9' - s[n-i-1]) + 1 - tmp;
      tmp = 1;
      if(i == n-1) ++a;
    }
    else{
      a += (s[n-i-1] - '0') + tmp;
      tmp = 0;
    }
  }
  cout << a << endl;
  return 0;
}

Measured memory_bytes: 1540
using System;
using System.Text;

public class Test
{
	static public void Main( )
	{
		StringBuilder output = new StringBuilder();
		string strs;
		while( "0" != (strs = Console.ReadLine()) ) {
			int sum = 0;
			for( var i=0; i<strs.Length; i++ ) {
				sum += int.Parse( strs[i].ToString() );
			}
			output.AppendLine( sum.ToString() );
		}
		Console.Write( output );
	}
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s,t;
  cin>>s>>t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end(),greater<int>());
  if(t>s){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}


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

using namespace std;

bool is_753_num(int num, int limit) {
    if (num > limit) {
        return false;
    }

    int q = num;
    int mod = 0;
    int num_of_3 = 0;
    int num_of_5 = 0;
    int num_of_7 = 0;

    while (q != 0) {
        mod = q % 10;
        switch (mod) {
        case 3:
            num_of_3++;
            break;
        case 5:
            num_of_5++;
            break;
        case 7:
            num_of_7++;
            break;
        }
        q /= 10;
    }

    if (num_of_3 >= 1 && num_of_5 >= 1 && num_of_7 >= 1) {
        return true;
    }    
    return false;
}

int traverse_tree_by_dfs(int start, int limit) {
    int result = 0;

    stack<int64_t> st;
    st.push(0);  // 樹形図の root は0から

    while(!st.empty()) {
        int64_t cur = st.top();
        st.pop();

        if (is_753_num(cur, limit)) {
            result++;
        }

        if (cur < limit) {
            st.push(3 + (cur * 10));
            st.push(5 + (cur * 10));
            st.push(7 + (cur * 10));
        }
    }

    return result;
}

int main(int argc, char *argv[]) {
    int N;
    cin >> N;

    cout << traverse_tree_by_dfs(0, N) << endl;
    return 0;
}


Measured memory_bytes: 256
h,w = map(int,input().split())

grid = []

for i in range(h):
    grid.append(list(input()))

dir = [[0,1],[-1,0],[0,-1],[1,0]]

for i in range(h):
    for j in range(w):
        flg = 0
        if grid[i][j] == '#':
            for k in range(4):
                if 0 <= i + dir[k][0] <= h-1 and 0 <= j + dir[k][1] <= w-1:
                    if grid[i + dir[k][0]][j + dir[k][1]] == '#':
                        flg = 0
                        break
                    flg = 1
        if flg == 1:
            break
    if flg == 1:
        break

if flg == 1:
    print("No")
else:
    print("Yes")


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

using namespace std;

int main()
{
    string s ;
    cin>>s ;
    int ans = 0 ;
    for(int i = 0 ; i < s.size() ; ++i)
        if(s[i] == '+')
         ans++;
        else
         ans--;
    cout<<ans;
    return 0 ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;

int main()
{
    long long x, ans;
    cin >> x;
    int count = 0;
    while (count != 2)
    {
        count = 0;
        int i = 1;
        while (i != x + 1)
        {
            if (x % i == 0)
            {
                count++;
            }
            i++;
        }
        x++;
    }
    ans = x - 1;
    cout << ans << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <string>
#include <utility>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstring>
#include <complex>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

int pow(int x, int n) {
  int ans = 1;
  while (n > 0) {
    if ((n & 1) == 1) {
      ans = ans * x;
    }
    x = x * x;
    n >>= 1;
  }
  return ans;
}

void run(){
  int n,p;
  cin>>n>>p;
  if(n==1){
    cout<<p<<endl;
    return;
  }
  if(n>60){
    cout<<1<<endl;
    return;
  }
  int ans=1;
  int t;
  for(int i=2;(t=pow(i,n))<=p;i++){
    while(p%t==0){
      ans*=i;
      p/=t;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
main = do
  getLine
  hs <- map read . words <$> getLine :: IO [Int]
  print $ dp hs [] []

dp :: [Int] -> [Int] -> [Int] -> Int
dp []  _ zs = head zs 
dp (x:xs) [] _ = dp xs [x] [0]
dp (x:xs) [y] _ = dp xs [x,y] [abs (y-x),0]
dp (x:xs) (y1:y2:ys) (z1:z2:zs) = 
  let 
    m = min (z1 + abs (y1-x)) (z2 + abs (y2-x))
  in
    dp xs (x:y1:y2:ys) (m:z1:z2:zs)

Measured memory_bytes: 50428
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <limits>
#include <vector>

using namespace std;

int main() {
  constexpr int64_t zero{0};
  int n, k;
  cin >> n >> k;
  vector<int64_t> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int64_t> sa(n + 1);
  vector<int64_t> sb(n + 1);
  for (int i = 0; i < n; i++) {
    sa[i + 1] = sa[i] + a[i];
    sb[i + 1] = sb[i] + max(a[i], zero);
  }
  int64_t ans = numeric_limits<int64_t>::lowest();
  for (int i = 0; i <= n - k; i++) {
    int64_t sum = sb[n] - (sb[i + k] - sb[i]) + max(zero, sa[i + k] - sa[i]);
    ans = max(ans, sum);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    vector<ll> cnt(61, 0);
    rep(i,n){
        ll a;
        cin >> a;
        rep(j,61){
            if(a>>j & 1) ++cnt[j];
        }
    }
    ll ans = 0;
    for(int i = 60; i >= 0; --i){
        ll two = 1LL;
        rep(j,i) two *= 2;
        if(k >= two){
            if(n - cnt[i] >= cnt[i]){
                k -= two;
                ans += (n - cnt[i]) * two;
                continue;
            }
        }
        ans += cnt[i] * two;
    }
    cout << ans << endl;
    return 0;
}


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

int main(void) {
  int n;
  int day;
  cin >> n >> day;
  if (day < n) {
    cout << n - 1 << endl;
  } else {
    cout << n << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];
    int cnt = 0, pre = 0, ans = 0;
    bool f = true;
    while(f){
        f = false;
        cnt = 0;
        rep(i, 0, n){
            a[i] += pre;
            if(a[i] >= n){
                f = true;
                int t = a[i] / n;
                a[i] %= n;
                a[i] -= t;
                cnt += t;
            }
        }
        pre = cnt;
        ans += cnt;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
void read(int &a){
	a=0;
	char c=getchar();
	while(c<'0'||c>'9'){
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		a=(a<<1)+(a<<3)+(c^48);
		c=getchar();
	}
}
int max(int a,int b){
	return a>b?a:b;
}
const int Maxn=200000;
const int Mod=1000000007;
int f_0[Maxn+5],f_1[Maxn+5],f_2[Maxn+5];
int n;
int fa[Maxn+5];
int head[Maxn+5],arrive[Maxn+5],nxt[Maxn+5],tot;
void add_edge(int from,int to){
	arrive[++tot]=to;
	nxt[tot]=head[from];
	head[from]=tot;
}
int dep[Maxn+5],max_dep[Maxn+5],son[Maxn+5];
int num[Maxn+5],pow_2[Maxn+5];
void init_dfs(int u){
	dep[u]=dep[fa[u]]+1;
	num[dep[u]]++;
	max_dep[u]=1;
	for(int i=head[u];i;i=nxt[i]){
		int v=arrive[i];
		init_dfs(v);
		if(max_dep[v]+1>max_dep[u]){
			son[u]=v;
			max_dep[u]=max_dep[v]+1;
		}
	}
}
void work_dfs(int u,int *f_0,int *f_1,int *f_2){
	f_0[1]=1;
	f_1[1]=1;
	if(son[u]==0){
		return;
	}
	work_dfs(son[u],f_0+1,f_1+1,f_2+1);
	int maxn=0;
	for(int i=head[u];i;i=nxt[i]){
		int v=arrive[i];
		if(v==son[u]){
			continue;
		}
		maxn=max(maxn,max_dep[v]);
		work_dfs(v,f_0+max_dep[u],f_1+max_dep[u],f_2+max_dep[u]);
		int *g_0=f_0+max_dep[u],*g_1=f_1+max_dep[u],*g_2=f_2+max_dep[u];
		int len=max_dep[v];
		for(int j=1;j<=len;j++){
			int tmp_0=f_0[j+1],tmp_1=f_1[j+1],tmp_2=f_2[j+1];
			g_0[j]=(g_0[j]+g_2[j])%Mod;
			g_2[j]=0;
			f_0[j+1]=(1ll*tmp_0*g_0[j])%Mod;
			f_1[j+1]=(1ll*tmp_1*g_0[j]+1ll*tmp_0*g_1[j])%Mod;
			f_2[j+1]=(1ll*tmp_0*g_2[j]+1ll*tmp_1*g_1[j]+1ll*tmp_1*g_2[j]+1ll*tmp_2*g_0[j]+1ll*tmp_2*g_1[j]+1ll*tmp_2*g_2[j])%Mod;
			g_0[j]=g_1[j]=g_2[j]=0;
		}
	}
	for(int i=1;i<=maxn;i++){
		f_0[i+1]=(f_0[i+1]+f_2[i+1])%Mod;
		f_2[i+1]=0;
	}
}
int main(){
	read(n);
	n++;
	for(int i=2;i<=n;i++){
		read(fa[i]);
		fa[i]++;
		add_edge(fa[i],i);
	}
	init_dfs(1);
	work_dfs(1,f_0,f_1,f_2);
	pow_2[0]=1;
	for(int i=1;i<=n;i++){
		pow_2[i]=(pow_2[i-1]<<1)%Mod;
	}
	int ans=0;
	for(int i=1;i<=max_dep[1];i++){
		ans=(ans+1ll*pow_2[n-num[i]]*f_1[i])%Mod;
	}
	printf("%d\n",ans);
	return 0;
}


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

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

    int ans[n + 1] = {0}, l = sqrt(n);

    for (int i = 1; i <= l; i++)
        for (int j = 1; j <= l; j++)
            for (int k = 1; k <= l; k++) {
                int temp = i * i + j * j + k * k + i * j + i * k + j * k;
                if (temp <= n)
                    ans[temp]++;
            }

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

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

int main() {
  string s;
  cin >> s;
  int ans=0;
  for(int i=0 ; i <(s.size()/2) ; i++){
    if(s.at(i)!=s.at(s.size()-1-i)){
		ans++;
    }
  }
       cout << ans << endl;
}


Measured memory_bytes: 256
A, B, C, X, Y = map(int, input().split())
min_price = A * X + B * Y
cnt = max(X, Y)

if cnt == X:
    for i in range(Y + 1):
        p = A * (X - i) + B * (Y -i) + C * i * 2
        if p < min_price:
            min_price = p
    for i in range(Y + 2, cnt + 1):
        p = A * (X - i) + C * i * 2
        if p < min_price:
            min_price = p
elif cnt == Y:
    for i in range(X + 1):
        p = A * (X - i) + B * (Y -i) + C * i * 2
        if p < min_price:
            min_price = p
    for i in range(X + 2, cnt + 1):
        p = B * (Y - i) + C * i * 2
        if p < min_price:
            min_price = p                   

print(min_price)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <unordered_map>
#include <cmath>
using namespace std;

typedef long long llong;
typedef unsigned long long ullong;
// -2.1e-9 <= int <= 2.1e9
// 0 <= unsigned int <= 4.2e9

int main()
{
    ullong N, A, B;
    cin >> N >> A >> B;
    if (A == 0) {
        cout << 0 << endl;
        return 0;
    }
    ullong q1 = N / (A + B);
    q1 = q1 * A;
    ullong r1 = N % (A + B);
    r1 = min(A, r1);
    ullong ans = q1 + r1;
    cout << ans << endl;
}


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

int main(){
  int s;
  cin>>s;
  vector<int> a(1);
  a.at(0)=s;
  bool flag=false;
  
  for(int i=0;flag==false;i++){
  	if(a.at(i)%2==0){
    	a.push_back(a.at(i)/2);
  	}else if(a.at(i)%2==1){
    	a.push_back(a.at(i)*3+1);
  	}else{
    	cout<<"予期せぬ出力"<<endl;
    	return 0;
  	}
    for(int j=0;j<i+1;j++){
      if(a.at(j)==a.at(i+1)){
        cout<<i+1+1<<endl;	//a.at(i+1)ハi+2バンメノカズ        
        flag=true;	//forから抜け出すフラグ
      }
    }
  }
  return 0;
}
    


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include<iostream>
//#include<cstdio>
//#include<cstring>
//#include<string>
//#include<queue>
//#include<cmath>
//#include<algorithm>
#define debug1 cout<<"?"<<endl;
#define debug2 cout<<"?"<<i<<endl;
#define PII pair<int,int>
typedef long long ll;
const int maxn=1e5+9;
const double pi=acos(-1);
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
const double ep=1e-7;
using namespace std;
int main()
{
	int h,a;
	scanf("%d%d",&h,&a);
	int ans=h/a;
	if(h%a)ans++;
	printf("%d\n",ans);
}

Measured memory_bytes: 256
var a,b,c,c1,c2:longint;
begin
    readln(a,b,c);
    if a=7 then c1:=c1+1
    else if a=5 then c2:=c2+1;
    if b=7 then c1:=c1+1
    else if b=5 then c2:=c2+1;
    if c=7 then c1:=c1+1
    else if c=5 then c2:=c2+1;
    if (c1+c2 <> 3) or (c1<> 1) or (c2 <> 2) then writeln('NO')
    else writeln('YES');
end.

Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n, x;
    cin >> n >> x;
    x = 2 * x + 1;
    cout << (n + x - 1) / x << endl;
    return 0;
}


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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr long double PI = 3.1415926535897932384626433832795028L;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N, M;
int A[110000], B[110000];
int L[220000], R[220000];
pint AB[110000];
vpint G[110000];
bool sw[220000], visited[110000];
bool dfs(int cur, bool drop) {
    if (visited[cur]) { return drop; }
    visited[cur] = true;
    drop ^= AB[cur].second;
    rep(i, G[cur].size()) {
        sw[G[cur][i].second] ^= drop;
        drop = dfs(G[cur][i].first, drop);
        sw[G[cur][i].second] ^= drop;
    }
    return drop;
}
signed main() {
    cin >> N >> M;
    rep(i, N) {
        cin >> A[i] >> B[i];
        AB[i] = {A[i], B[i]};
    }
    sort(AB, AB + N);
    AB[N] = {LLONG_MAX, 0};
    for (int i = N; i > 0; i--) { AB[i].second ^= AB[i - 1].second; }
    rep(i, M) {
        cin >> L[i] >> R[i];
        int l = lower_bound(AB, AB + N + 1, pint(L[i], 0)) - AB;
        int r = upper_bound(AB, AB + N + 1, pint(R[i], LLONG_MAX)) - AB;
        if (l < r) { G[l].push_back({r, i}), G[r].push_back({l, i}); }
    }
    rep(i, N + 1) {
        if (dfs(i, false)) { fin(-1); }
    }
    vint ans;
    rep(i, M) { if (sw[i]) { ans.push_back(i + 1); }}
    cout << ans.size() << endl;
    rep(i, ans.size()) { cout << ans[i] << " "; }
    cout << endl;

}

Measured memory_bytes: 24572
use proconio::{fastout, input};
use std::cmp::max;

#[fastout]
fn main() {
    input! {
        a: i64,
        b: i64,
        c: i64,
        d: i64,
    }
    println!("{}", max(a * c, max(a * d, max(b * c, b * d))));
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int D;
    cin >> D;
    vector<int>c(26);
    for(int i = 0; i < 26; i++) {
        cin >> c[i];
    }
    vector<vector<int>>s(D,vector<int>(26));
    for(int i = 0; i < D; i++) {
        for(int j = 0; j < 26; j++) {
            cin >> s[i][j];
        }
    }
    vector<int>t(D);
    for(int i = 0; i < D; i++) {
        t[i] = rand()%26+1;
    }
    int ans = 0;
    vector<int>Last(26);
    for(int i = 0; i < D; i++) {
        ans+=s[i][t[i]-1];
        Last[t[i]-1] = i+1;
        for(int j = 0; j < 26; j++) {
            ans-=c[j]*(i+1-Last[j]);
        }
    }
    int M = 3003333;
    vector<P>horyuu;
    int cnt = 0;
    for(int i = 0; i < M; i++) {
        int d = rand()%D+1;
        int q = rand()%26+1;
        int ord = ans;
        int X = 0;
        int Y = 0;
        int A = 0;
        int B = 0;
        ans+=s[d-1][q-1]-s[d-1][t[d-1]-1];
        for(int j = 0; j < D; j++) {
            if(t[j] == t[d-1]) {
                if(j == d-1) {
                    Y = j+1;
                }
                else {
                    X = j+1;
                }
                A = j+1;
            }
            if(t[j] == q) {
                Y = j+1;
                B = j+1;
            }
            ans-=c[t[d-1]-1]*(j+1-X)-c[t[d-1]-1]*(j+1-A);
            ans+=c[q-1]*(j+1-B)-c[q-1]*(j+1-Y);
        }
        if(ans >= ord) {
            ord = ans;
            horyuu.push_back({d,q});
            cnt++;
        }
        else {
            ans = ord;
        }
        if(cnt == 2) {
            cnt = 0;
            t[horyuu[1].first-1] = horyuu[1].second;
            horyuu = {};
        }
    }
    for(int i = 0; i < D; i++) {
        cout << t[i] << "\n";
    }
}

Measured memory_bytes: 3728
#include <iostream>
#include <algorithm>
#include <set>
#include <string>
#include <vector>

int main(void){
    int x,a,b;
    std::cin >> x >> a >> b;

    std::cout << (abs(x-a) < abs(x-b) ? 'A' : 'B');
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
#define nl '\n'
 
#define y1 aza_ibagaliev
 
#define f first
#define s second
	
#define ed end()
#define bg begin()
#define rbg rbegin()
 
#define rv reverse
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define ppf pop_front
 
#define sz size()
#define all(x) x.bg, x.ed
 
#define pll pair < ll, ll >
#define pii pair < int, int >
 
#define sqr(x) ((x) * 1ll * (x))
#define sqrd(x) ((x) * 1.0 * (x))
 
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
 
#define rnl cout << "----------------------------------------" << nl
 
#define bit __builtin_popcount
 
inline ll bip(ll x, ll n, ll mod){ll res=1;while(n){if(n & 1){res=(res*x)%mod;}x=(x*x)%mod;n>>=1;}return res;}
        	
const int ppr = 257;
const ll INF = 2e18;
const int inf = 2e9;
const int mod = 1e9 + 7;
const int N = 1e6 + 123;
const ld pi = acos(-1.0);
 
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

int n, m, u[N], ans;
vector<int>g[N];

void dfs(int v) {
	u[v] = 1;
	for(int to : g[v])
		if(!u[to]) dfs(to);
}
 
main() {             	
//  freopen(".in", "r", stdin);
//  freopen(".out", "w", stdout);
 
//	srand(time(NULL));

//	speed;

	cin >> n >> m;

	while(m--) {
		int x, y, w;
		cin >> x >> y >> w;

		g[x].pb(y);
		g[y].pb(x);
	}

	for(int i = 1; i <= n; i++) 
		if(!u[i]) ans++, dfs(i);

	cout << ans;

    return 0;                                        
}

Measured memory_bytes: 31104
#include <bits/stdc++.h>
#define int long long
#define INT_MAX INT64_MAX
#define INT_MIN INT64_MIN
#define PI 3.14159265358979323846
#define CLK clock_t clk = clock();//Start of main
#define OCLK cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';//End of main
#define MOD 1000000007
/* DEFINE cout */
#define pln cout << "===============================\n"
#define on cout<<"\n"
#define os cout<<" "
#define o2(a,b) cout<<a<<" "<<b
#define o(a) cout << a
#define bitcount __builtin_popcount
/* DEFINE cout */
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);//fastio
using namespace std;
struct hash_pair { // use pair as key in unordered_map<pair<int,int>,int,hash_pair>;
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
bool prime[10000001];
int P=MOD-2;
int factorial[10000001]={0};
int powerFunction(int x,int y){
    int res = 1;
    int p = MOD;
    x = x % p;
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
void sieveFunction(int maxLimit){
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1]=false;
    for(int i=2; maxLimit >= i ; i++){
        if(prime[i]){
            for(int j=2*i ; maxLimit >= j ; j+=i)
                prime[j]=false;
        }
    }
}
void factorialFunction(int maxLimit){
    factorial[0]=1;
    for(int i=1 ; i <= maxLimit ; i++)
        factorial[i]=(factorial[i-1]*i)%MOD;
    return;
}
int gcd(int a, int b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
signed main(){
    int n;
    cin >> n;
    int arr[n+1];
    int ans = 0;
    for(int i=0; n>i; i++){
        cin >> arr[i];
        if(arr[i]%2 == 1 && i%2 == 0){
            ans++;
        }
    }
    cout << ans << endl;
}






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

int main(){
    
    int x,y;
    while(1){
        cin>>x>>y;
        if(x==0&&y==0)break;
        
        if(x<y){
            cout<<x<<" "<<y<<endl;
        }else{
            cout<<y<<" "<<x<<endl;
        }
    }
    return 0;
}


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

using namespace std;
const int N=2e5+5;
pair<int,int> F(int x)
{
    int s=x%10;
    int f;
    while(x)
    {
        f=x%10;
        x/=10;
    }
    return {f,s};
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    map< pair<int,int> , int > cnt;
    int n;cin>>n;
    long long ans=0;
    for(int i=1;i<=n;i++)
    {
        pair<int,int>P=F(i);
        ans+=cnt[P]*2;
        if(P.first==P.second) ans++;
        swap(P.first,P.second);
        cnt[P]++;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> H(N + K), DP(N + K, 1e9);
  for (int i = 0; i < N; i++) cin >> H.at(i);
  DP.at(0) = 0;
  for (int i = 0; i < N; i++)
    for (int j = i + 1; j < i + 1 + K; j++)
      DP.at(j) = min(DP.at(j), DP.at(i) + abs(H.at(i) - H.at(j)));
  cout << DP.at(N - 1) << "\n";
}

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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
  const char* c = strchr(na + 1, ',');
  cerr.write(na, c - na) << " : " << arg1 << " , ";
  __f(c + 1, args...);
}
#define endl "\n"
#define all(v) v.begin(), v.end()
#define UNIQUE(v) sort(all(v)),v.erase(unique(all(v)),v.end())
typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int inf = 1e9;
const LL INF = 1e18;
const int N = 1e5 + 5;

LL bigmod(LL b, LL p, LL mod) {
  LL res = 1%mod, x = b%mod;
  while (p) {
    if (p&1) res = (res * x)%mod;
    x = (x * x)%mod;
    p >>= 1;
  }
  return res%mod;
}

LL modinv(LL x, int mod) {
  return bigmod(x, mod - 1, mod);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("input.txt", "r", stdin);
  #endif // LOCAL
  string s;
  cin >> s;

  int len = s.size();
  reverse(s.begin(), s.end());

  int pref = 0;
  LL ans = 0;
  vector <int> dp (2019, 0);
  dp[0] = 1;

  for (int i = 0; i < len; i++) {
    pref = pref + (s[i] - '0') * bigmod(10, i, 2019);
    pref %= 2019;
    ans += dp[pref];
    dp[pref]++;
  }

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



Measured memory_bytes: 3704
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <stdlib.h>
#include <vector>
#include <map>
#include <unordered_map>
#include <algorithm>
using namespace std;

//最大公倍数算出関数
long long gcd(long long a, long long b) {

	//余りが0の時（ｂ＝＝0）はｂで再度割らないようにする
	if (b==0) {
		return a;
	}
	return gcd(b, a%b);
}

//最小公倍数算出関数
long long lcm(long long a, long long b) {

	return a/ gcd(a, b) * b ; //a * b / gcd(a,b)だとオバーフローする
}


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

	long long time[100];
	for (int i = 0; i < num;i++) {
		cin >> time[i];
	}

	long long ans = 1; //最小公倍数の初期値

	for (int i = 0; i < num;i++) {
		ans = lcm(ans, time[i]);
	}
	
	cout << ans;

    return 0;
}


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

using namespace std;

int main() {
    int N;
    long long score[100000];
    long long A[100000], B[100000];
    int index[100000];
    cin >> N;
    for (int i=0; i<N; i++) {
        long long a, b;
        cin >> A[i] >> B[i];
        score[i] = A[i] + B[i];
        index[i] = i;
    }
    sort(index, index+N, [&score](int i1, int i2){
        return score[i1] > score[i2];
    });

    long long allscore = 0;
    for (int i=0; i<N; i++) {
        if (i % 2 == 0) allscore += A[index[i]];
        else allscore -= B[index[i]];
    }
    cout << allscore << endl;
    return 0;
}

Measured memory_bytes: 2944
// Aizu Vol-10 1085: Spellcasters
// 2017.8.19 bal4u@uu

#include <stdio.h>
#include <string.h>

int c[105];

int main()
{
	int n, S, r;
	int i, j, ans;

	while (scanf("%d%d", &n, &S) && n) {
		memset(c, 0, sizeof(c));
		for (i = 0; i < n; i++) scanf("%d", &r), c[r]++;
		for (ans = i = 0; i < S; i++) {
			if (!c[i]) continue;
			if (i + i <= S) ans += c[i] * (c[i]-1) / 2;
			for (j = i + 1; j < S; j++)
				if (c[j] && i + j <= S) ans += c[i] * c[j];
		}
		printf("%d\n", n*(n-1) / 2 - ans);
	}
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
#define fi first
#define se second
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	vector<int>v1(n + 1), v2(n + 1);
	for (int i = 0; i < n; i++)v1[i] = i + 1;
	for (int i = 0; i < n; i++) {
		cin >> v2[i];
	}
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (v1[i] != v2[i])cnt++;
	}
	if (cnt > 2)
		cout << "NO" << endl;
	else
		cout << "YES" << endl;




}

Measured memory_bytes: 3632
digit, constraints_count = [int(num) for num in input().split(' ')]

constraints = [-1, -1, -1]

for i in range(constraints_count):
    const_digit, const_num = [int(num) for num in input().split(' ')]
    if const_digit <= digit and constraints[const_digit - 1] != -1 and constraints[const_digit - 1] != const_num:
        print(-1)
        exit()
    if digit != 1 and const_digit == 1 and const_num == 0:
        print(-1)
        exit()

    constraints[const_digit - 1] = const_num


if constraints[0] == -1:
    if digit != 1:
        constraints[0] = 1
    else:
        constraints[0] = 0

for i in range(3):
    if constraints[i] == -1:
        constraints[i] = 0

num_str = ""
for i in range(digit):
    num_str += str(constraints[i])

print(num_str)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int ans;
  if(a==b && b==c) {ans=1;}
  else if((a==b && b!=c) || (a==b&&a!=c) || (a==c && a!=b) || (a==c&&b!=c)||(b==c&&a!=b)||(b==c&&a!=c)) 
  {ans=2;}
  else{ans=3;}
  
  cout << ans <<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    int N = 0;
    int X = 0;
    int L[100]={0};
    int result[100] = {0};
    int resultCount = 0;
    
    scanf("%d",&N);
    scanf("%d",&X);
    
    for (int i=0; i<N; i++) {
        scanf("%d",&L[i]);
    }
    
    result[0] = 0;
    for (int i = 0; i<N; i++) {
        result[i+1] = result[i]+L[i];
    }
    for (int i=0; i<N+1; i++) {
        if (result[i] <= X) {
            resultCount++;
        }
    }
    printf("%d",resultCount);
}


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

typedef long long ll;

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

	if (!t.length()) {
		cout << 0 << endl;
		return 0;
	}

	ll ans = 1e10;

	for (int i = 0; i <= (s.length() - t.length()); ++i) {
		ll cnt = 0;
		for (int j = 0; j < t.length(); ++j)
			if (s[i + j] != t[j]) ++cnt;
		ans = min(ans, cnt);
	}

	cout << ans << endl;

	return 0;
}


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

int main(){
  string S; cin>>S;
  int cnt = 0;
  for(int i=0;i<S.size();i++){
    if(S[i] == '0') cnt++;
    else cnt--;
  }
  cout<<S.size()- abs(cnt)<<endl;
  return 0;
}


Measured memory_bytes: 512
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

n,a,b = nm()
mod = 10**9 + 7
s = pow(2,n,mod) - 1

def fur(n,r):
    p,q = 1,1
    for i in range(r):
        p = p*(n-i)%mod
        q = q*(i+1)%mod
    return p * pow(q,mod-2,mod) % mod

print((s - fur(n,a) - fur(n,b)) % mod)


Measured memory_bytes: 38768
#include <bits/stdc++.h>
#define ll long long
#define uint unsigned long long
#define db double
#define ls x << 1
#define rs x << 1 | 1
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define eps 1e-9
using namespace std;
inline int read()
{
	int x = 0, f = 1; 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(); }
	return x * f;
}
const int mod = 1e9 + 7;
int n;
int u[200005], v[200005];
ll jc[8010], ny[84010];
ll cnt[4010][4010];
 
ll qpow(ll x, ll y)
{
	ll res = 1;
	while(y)
	{
		if(y & 1) res = (res * x) % mod; 
		x = x * x % mod;
		y = y >> 1;
	}
	return res;
}
 
ll C(int x,int y)
{
	return ((jc[x + y] * ny[x]) % mod * ny[y]) % mod;
}

int main()
{
	jc[0] = 1;
	rep(i, 1, 8000)
	{
		jc[i] = (jc[i - 1] * i) % mod;
		ny[i] = qpow(jc[i], mod - 2);
	}
    n = read();
	memset(cnt, 0, sizeof(cnt));
	
	rep(i, 1, n)
	{
		u[i] = read();
		v[i] = read();
		cnt[2000 - u[i]][2000 - v[i]] ++;
	}
	rep(i, 0, 4000)
		rep(j, 0, 4000)
		{
			if(i > 0) cnt[i][j] = (cnt[i][j] + cnt[i - 1][j]) % mod;
			if(j > 0) cnt[i][j] = (cnt[i][j] + cnt[i][j - 1]) % mod;
		}
	ll r = 0;
	rep(i, 1, n)
	{
		r = (r + cnt[2000 + u[i]][2000 + v [i]]) % mod;
		r = ((r - C(2 * u[i], 2 * v[i])) % mod + mod) % mod;
	}
	r = (r * qpow(2, mod - 2) ) % mod;
	printf("%lld\n", r);
    
    return 0;
}


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

int main(){
  ll n; cin >> n;
  vl a(n); rep(i,n)cin >> a[i];
  int i = 1;
  rep(j,n){
    if(a[j] == i)i++;
  }
  ll ans = n - i + 1;
  if(ans == n)cout << -1 << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000000LL;
constexpr int inf = 1000000000;

int main() {
    ll a, b;
    cin >> a >> b;
    if (a > b)
        swap(a, b);

    vector<ll> s;
    for (ll i = 2; i <= (ll)sqrt(a) + 1; ++i) {
        int cnt = 0;
        while (a % i == 0) {
            a /= i;
            ++cnt;
        }

        if (cnt > 0 && b % i == 0)
            s.push_back(i);
    }

    if (a > 1 && b % a == 0)
        s.push_back(a);

    cout << s.size() + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;
const int INF = 1001001001;
 
int main()
{
  int n;
  cin >> n;
  vector<int> b(n+1);
  b[0] = INF;
  b[n] = INF;
  rep(i, n-1) cin >> b[i+1];
  int ans = 0;
  rep(i, n) {
    ans += min(b[i], b[i+1]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}
bool is_prime(const unsigned n) {
    switch (n) {
    case 0: // fall-through
    case 1: return false;
    case 2: // fall-through
    case 3: return true;
    } // n > 3 が保証された

    if (n % 2 == 0 || n % 3 == 0) return false;
    // n は 2 と 3 のいずれの倍数でもないことが保証された
    // これより n は (6の倍数)-1 か (6の倍数)+1 である
    // 6の倍数前後の数を使って試し割りをする
    for (unsigned i = 5; i * i <= n; i += 6) {
        if (n % i == 0) return false; // (6の倍数)-1
        if (n % (i + 2) == 0) return false; // (6の倍数)+1
    }
    return true;
}
string e, o;
int main(void){
    cin >> e >> o;
    rep(i, e.size()) {
        cout << e[i];
        if (i < o.size()) cout << o[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3572
N = int(input())
S = input()
res = ""
s = ""
t = ""
if len(S) % 2 == 1:
  res = "No"
else:
  s = S[0:len(S)//2]
  t = S[len(S)//2: len(S)]
  if s ==t:
    res = "Yes"
  else:
    res = "No"
print(res)

Measured memory_bytes: 9040
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
using namespace std;

#define REP(i,n) for(int i=0;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"

typedef long long ll;
typedef tuple<int,int,bool> Tb;

int atcoder(){
    int n;
    cin >> n;
    int f[n][10];
    REP(i,n){
        REP(j,10){
            cin >> f[i][j];
        }
    }
    ll p[n][11];
    REP(i,n){
        REP(j,11) cin >> p[i][j];
    }
    ll ans = LLONG_MIN;
    
    for(int i=1; i<(1<<10); ++i){
        ll tmpans=0;
        REP(j,n){
            int cnt = 0;
            REP(k,10){
                if((i>>k)&1 & f[j][k]) cnt++;
            }
            tmpans +=p[j][cnt];
        }
        ans = max(ans,tmpans);
    }
    
    cout << ans << ENT;
    return 0;
}

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


Measured memory_bytes: 256
def main():
    X = input_ints()

    print(10 - (X // 200))


def input_ints():
    line_list = input().split()

    if len(line_list) == 1:
        return int(line_list[0])
    else:
        return map(int, line_list)


def input_int_list_in_line():
    return list(map(int, input().split()))


def input_int_tuple_list(n: int):
    return [tuple(map(int, input().split())) for _ in range(n)]


main()


Measured memory_bytes: 9184
WHITE = '.'
BLACK = '#'

N = gets.chomp.to_i
S = gets.chomp

whites = S.count(WHITE)


# 全部白パターンの要変更数
cumulative = [whites]

N.times do |i|
  if S[i] == BLACK
    cumulative[i + 1] = cumulative[i] + 1
  else
    cumulative[i + 1] = cumulative[i] - 1
  end
end

puts cumulative.min


Measured memory_bytes: 3912