akhauriyash/Code-Regression huggingface dataset:
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█
 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long lo;
typedef pair< lo,lo > PII;
 
#define fi first
#define se second
#define mp make_pair
#define int long long
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
 
const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 5000005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t,fact[li];
int cev;
string s;
vector<int> v;

inline int mul(int x,int y){
	return (x%mod)*(y%mod)%mod;
}

inline int fp(int x,int y){
	if(y==0)return 1;
	if(y==1)return x;
	t=fp(x,y/2);
	t=mul(t,t);
	if(y%2==1)t=mul(t,x);
	return t;
}

main(void){
	scanf("%lld %lld",&n,&m);
	if(n==m && n%2==0){printf("0\n");return 0;}
	if(n>m)swap(n,m);
	cev=m-n;
	int cev1=cev;
	if(cev>n || cev*2>m){printf("0\n");return 0;}
	m-=cev*2;
	n-=cev;
	//~ cout<<m<<" "<<m%3<<endl;
	if(m%3!=0){printf("0\n");return 0;}
	cev=m/3;
	int iki=cev+cev1;
	int bir=cev;
	fact[0]=1;
	for(int i=1;i<=3000000;i++){
		fact[i]=mul(fact[i-1],i);
	}
	cev=mul(fact[bir+iki],fp(mul(fact[bir],fact[iki]),mod-2));
	printf("%lld\n",cev);
	return 0;
}



Measured memory_bytes: 26880
/* One original thought is worth a thousand mindless quotings */

#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<bitset>
#include<queue>
#define ll long long
#define ld long double
#define ull unsigned long long
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout.precision(10);cout << fixed;
#define dbset(x) for(int i=0 ; i<x.size(); i++) cerr << x[i] << " "; cerr << endl;
#define inf 1000000007
#define INF 1000000000000000000LL
#define PI 3.14159265358979323846
#define mod 1000000007
#define mod1 1000696969
#define flusz fflush(stdout);
#define VI vector<int>
#define VPI vector < pair<int,int> >
#define PII pair<int, int>
#define BIT bitset<N>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define REP(x, y) for(int x = 0; x < (y); ++x)
#define FOR(x, y, z) for(int x = y; x <= (z); ++x)
#define FORR(x, y, z) for(int x = y; x >= (z); --x)
using namespace std;

template<class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<","; _dbg(sdbg+1, a...);
}
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)

#define int long long
const int N = 5 * 100*1000 + 7;

int test;

int n;

int t[N][2];

void solve()
{
    cin >> n;

    FOR(i,1,n){
        cin >> t[i][0];

        t[i][0] += t[i-1][0];
    }

    FOR(i,1,n){
        cin >> t[i][1];

        t[i][1] += max(t[i-1][1],t[i][0]);
    }

    cout << t[n][1];

    return;
}

int32_t main()
{
    boost

    test=1;

    while(test--)
    {
        solve();
    }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define int long long int
#define pb push_back
#define f first
#define s second
const int MOD=1000000007;
int cnt[1000005];

int add(int x, int y)
{
	return (x + y) % MOD;
}

int sub(int x, int y)
{
	return add(x, MOD - y);
}

int mul(int x, int y)
{
	return (x * 1ll * y) % MOD;
}

int binpow(int x, int y)
{
	int z = 1;
	while(y > 0)
	{
		if(y % 2 == 1)
			z = mul(z, x);
		x = mul(x, x);
		y /= 2;
	}
	return z;
}

int inv(int x)
{
	return binpow(x, MOD - 2);
}


main() {
	int n;
	cin>>n;
	int arr[n];
	for(int i=0; i<n; i++){
		cin>>arr[i];
	}
	
	for(int i=0; i<n; i++){
		int num=arr[i];
		vector<pair<int, int>>fac;
		for(int x=2; x*x<=num; x++){
			int cnt=0;
			while(num%x==0){
				cnt++;
				num=num/x;
			}
			if(cnt>0){
				fac.pb({x, cnt});
			}
		}
		if(num>1){
			fac.pb({num, 1});
		}
		for(auto u:fac){
			cnt[u.f]=max(cnt[u.f], u.s);
		}
	}
	int ans=1;
	for(int i=2; i<=1000000; i++){
		for(int j=0; j<cnt[i]; j++){
			ans=(ans*i)%MOD;
		}
	}
	int num=0;
	for(int i=0; i<n; i++){
		num=add(num, inv(arr[i]));
	}
	cout<<mul(ans, num);
	return 0;
}

Measured memory_bytes: 7256
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	m := nextInt()
	mark := make([]int, n)
	mapper := make([][]int, n)
	for i := 1; i < n; i++ {
		mark[i] = -1
		mapper[i] = make([]int, 0)
	}
	for i := 0; i < m; i++ {
		a := nextInt() - 1
		b := nextInt() - 1
		mapper[a] = append(mapper[a], b)
		mapper[b] = append(mapper[b], a)
	}

	mark[0] = 0
	nextHop := []int{0}
	for {
		if len(nextHop) == 0 {
			break
		}
		tempHop := make([]int, 0)
		for i := 0; i < len(nextHop); i++ {
			nextNode := mapper[nextHop[i]]
			for j := 0; j < len(nextNode); j++ {
				if mark[nextNode[j]] == -1 {
					mark[nextNode[j]] = nextHop[i]
					tempHop = append(tempHop, nextNode[j])
				}
			}
		}
		nextHop = tempHop
	}

	ans := func() bool {
		for i := 1; i < n; i++ {
			if mark[i] == -1 {
				return false
			}
		}
		return true
	}()

	if ans {
		fmt.Println("Yes")
		for i := 1; i < n; i++ {
			fmt.Println(mark[i] + 1)
		}
	} else {
		fmt.Println("No")
	}

}


Measured memory_bytes: 18368
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B;
  cin >> A >> B;
  int q = A * B;
  int w = A - B;
  int e = A + B;
  int r = max(q, w);
  int o = max(r, e);
  cout << o << endl;
}

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

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

	int n;
	cin >> n;
	int a[8] = {0};
	int  b = 0;
	for(int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if(x >= 3200) b++;
		else a[x / 400]++;
	}
	int c = 0;
	for(int i = 0; i < 8; i++) {
		if(a[i]) c++;
	}
	if(c == 0) {
		cout << 1 << " " << b << endl;
	} else {
		cout << c << " " << c + b << endl;
	}
	return 0;
}


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

neg = [0] * n

for i in range(q):
    neg[a[i] - 1] += 1

# print(neg)


for i in range(n):
    if k - q + neg[i] <= 0:
        print('No')
    else:
        print('Yes')


Measured memory_bytes: 56664
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
const int mx=1e5+10;
int a[mx];
int main(){
  int n;
  scanf("%d",&n);
  for(int i=0;i<n;i++)scanf("%d",a+i),--a[i];
  int ans=0;
  for(int i=0;i<n;i++){
    if(i==a[i]){
      swap(a[i],a[i+1]);
      ans++;
    }
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF LLONG_MAX
#define eps LDBL_EPSILON
#define moder 1000000007
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue
using namespace std;
int n,m,k,a;
int ans[31];
signed main(){
	cin>>n>>m;
	rep(i,n){
		cin>>k;
		rep(i,k){
			cin>>a;
			ans[a]++;
		}
	}
	int res=0;
	for(int i=1;i<=m;i++){
		if(ans[i]==n)res++;
	}
	cout<<res<<endl;
	return 0;
}

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

int main(){
    int W,N;
    int cnt=1;
    while(true){
        cin>>W;
        if(W==0)break;
        cin>>N;
        int treasure[N+1][2];
        for(int i=1;i<N+1;i++)
            scanf("%d,%d",&treasure[i][0],&treasure[i][1]);
        
        int table[N+1][W+1];
        for(int i=0;i<N+1;i++)
            for(int j=0;j<W+1;j++)
                table[i][j]=0;
        
        for(int i=1;i<N+1;i++){
            for(int j=1;j<W+1;j++){
                if(j<treasure[i][1]){table[i][j] = table[i-1][j];continue;}
                int new_value = table[i-1][j-treasure[i][1]] + treasure[i][0];
                table[i][j] = max(new_value,table[i-1][j]);
            }
        }

        int m=0,w=0;
        for(int i=0;i<W+1;i++){
            if(table[N][i]>m){m=table[N][i];w=i;}
        }
        cout<<"Case "<<cnt<<":"<<endl;
        cout<<m<<endl<<w<<endl;
        cnt++;
    }
    return 0;
}


Measured memory_bytes: 7060
#include <bits/stdc++.h>
#include <stdio.h>
typedef long long int LL;
#define fr(i,p,n) for(LL i=p;i<n;i++)
#define fr1(i,p,n) for(LL i=p;i>=n;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define PI 3.14159265358979323846
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define precise cout << std::setprecision(10) << std::fixed;

using namespace std;

int main()
{
        LL n;
        cin>>n;
        if(n%2==0){
            cout<<-1<<endl;
        }
        else{ 
            map<int,int> mp;
            LL mod=0;
            LL cnt=1;
            bool f=false;
           while(1){
               mod = mod * 10 + 7;
               mod = mod % n;
               if(mp[mod]>0){
                   f=true;
                   break;
               }
               mp[mod]++;
              if(mod==0){
                 cout<<cnt<<endl;
                 break; 
              }
              cnt++;     
           }
           if(f) cout<<-1<<endl;
        }
    return 0;
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, a[4][3][10] = {}, b, f, r, v;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> b >> f >> r >> v;
    a[b - 1][f - 1][r - 1] += v;
  }
  for (int i = 0; i < 16; i++) {
    for (int j = 0; j < 21; j++) {
      if (i == 0) {
        continue;
      } else if (j == 20) {
        cout << '\n';
      } else if (i % 4 == 0) {
        cout << '#';
      } else if (j % 2 != 0) {
        cout << a[i / 4][i % 4 - 1][j / 2];
      } else {
        cout << ' ';
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3188
N,M = map(int,input().split())
a = [0]*N
b = [0]*N
c = [0]*M
d = [0]*M
for i in range(N):
  a[i],b[i] = map(int, input().split())
for i in range(M):
  c[i],d[i] = map(int,input().split())
for i in range(N):
  L = 2*10**8+1
  n = 0
  for p in range(M):
    if abs(a[i]-c[p]) + abs(b[i]-d[p]) < L:
      n = p
      L = abs(a[i]-c[p]) + abs(b[i]-d[p])
    if p == M-1:
      print(n + 1)      

Measured memory_bytes: 39664
#include<iostream>
using namespace std;
int main(){
	int H, W, J;
	while (1){
		cin >> H >> W;
		if (H == 0 && W == 0) break;
		for (int i = 0; i < H; i++){
			for (int k = 0; k < W; k++){
				J = i + k;
				if (J % 2 == 0){
					cout << "#";
				}
				else if (J % 2 != 0){
					cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3100
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
int N, h[100001];
int dp[100001];
int main(void){
    cin >> N;
    rep(i,N) scanf("%d",&h[i+1]);
    dp[2] = abs(h[2]-h[1]);
    for(int i=3;i<=N;i++){
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout << dp[N] << endl;
    return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,d,count=0;
  cin>>n>>d;
  while(n--){
    long long x,y;
    cin>>x>>y;
    long long b=x*x;
    long long c=y*y;
    long e=b+c;
    long  double a=sqrt(e);
    if(a<=d)count++;
  }
  cout<<count<<endl;
}
    
    

Measured memory_bytes: 3680
/*
请问你们见到过我家梨花么？
非常可爱，简直是小天使！
不不不，没失踪也没怎么样，只是觉得你们都该看一下~~ 
*/
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <cstdlib>
#include <utility>
#include <cmath>
using namespace std;
#define ll long long
#define ull unsigned long long
#define all(x) (x).begin(), (x).end() 
#define ayacin ios::sync_with_stdio(false);
#define yukari (~0uLL>>1LL) 
#define yukari2 (~0u>>1) 
#define M_PI12 3.141592653
#define Parsee long double
#define reimu iterator 
#define mokou __builtin_popcount
#define __sum accumulate
#define rep(i,a,b) for(i=a;i<=b;i++)
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define ls rt<<1
#define rs rt<<1|1 
#define eps 1e-10  
#define zero(a) fabs(a)<eps  
#define x first
#define y second
#define read(a) a=in<int>()
using namespace std;
const int MAXN=1e6+6;
//template <typename T> T in(){char ch;T n = 0;bool ng = false;while (1){ch = getchar();if (ch == '-'){ng = true;ch = getchar();break;}if (ch>='0' && ch<='9')     break;}while (1){n = n*10 + (ch - '0');ch = getchar();if (ch<'0' || ch>'9')   break;}return (ng?-n:n);}
char a[55][55];
int m,n;
void cover(int x,int y){
	if(x>m||y>n) return ;
	a[x][y]='.';
	if(a[x+1][y]=='#'){
		cover(x+1,y);
		return ;
	}
	if(a[x][y+1]=='#'){
		cover(x,y+1);
		return ;
	}
	return ;
}
int main(){
	int i,j,k,v;
	while(cin>>m>>n){
		rep(i,0,50) rep(j,0,50) a[i][j]='.';
	rep(i,1,m){
		rep(j,1,n) cin>>a[i][j];
	}
	cover(1,1);
	rep(i,1,m){
		rep(j,1,n){
			if(a[i][j]!='.'){
				puts("Impossible");
				goto l;
			}
		}
	}
	puts("Possible");
	l:; 
	}
}








Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		
		System.out.println((n%100 <= (n/100)*11)? (n/100)*111 : ((n/100)+1)*111);
		
	}
}


Measured memory_bytes: 35840
#include <stdio.h>
#include <math.h>
int IsPrime(int);
int main()
{
  int n,a,cnt = 0;
  scanf("%d",&n);
  for(int i = 0; i < n; i++){
    scanf("%d",&a);
    if(IsPrime(a) == 1) cnt++;
  }
  printf("%d\n",cnt);
  return 0;
}

int IsPrime(int x)
{
  if(x < 2) return 0;
  if(x == 2) return 1;
  else if(x % 2 == 0) return 0;
  for(int i = 3; i <= sqrt(x); i+=2){
    if(x % i == 0) return 0;
  }
  return 1;
}



Measured memory_bytes: 2036
#include<bits/stdc++.h>
using namespace std;
using Graph=vector<vector<int64_t>>;
int main(){
  int64_t N;cin>>N;
  Graph G(N);
  for(int i=0;i<N-1;i++){
  int64_t u,v;cin>>u>>v;u--;v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }vector<int64_t>C(N);C.at(0)=1;
  for(int i=1;i<N;i++){
  int64_t a=C.at(i-1)+i+1;
    for(auto v:G[i]){
    if(v<i)
      a-=(v+1);
    }C[i]=a;
   }int64_t ans=0;
  for(int i=0;i<N;i++)
    ans+=C.at(i);
  cout<<ans<<endl;
  return 0;
}

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

int main()
{
  int a,b,c;
  cin >> a >> b >> c;
  if(b >= c) cout << "delicious" << endl;
  else if((a+b) >= c) cout << "safe" << endl;
  else cout << "dangerous" << endl;
}


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

int main(){
int A, B, C; cin >> A >> B >> C;
int c0 = A % B;
int c = A % B;
int n = 1;
while (c != C) {
    n++;
    c = n*A % B;
    if (c == c0) {
        cout << "NO" << endl;
        return 0;
    }
}
cout << "YES" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define o_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define double long double
#define mod 1000000007
#define iP pair<int,int>
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define inf 1e15
#define mod1 998244353
#define pi 3.141592653589793238
#define lcm(a,b) a*b/__gcd(a,b)
#define sz(x) (int)x.size()
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define cmp complex<double>
int power(int x,int y){
    int res=1;
    while(y>0){
        if(y&1)res=(res*x)%mod;
        x=(x*x)%mod;
        y/=2;
    }
    return res;
}
class segtree{
    public:
    vector<int> tree;
    int sz;
    void init(int n){
        sz=1;
        while(n>0){
            sz*=2;
            n/=2;
        }
        tree.resize(2*sz,0);
    }
    void build(vector<int> &v,int idx,int lx,int rx){
        if(rx-lx==1){
            if(lx<(int)v.size())tree[idx]=v[lx];
            return;
        }
        build(v,2*idx+1,lx,(lx+rx)/2);
        build(v,2*idx+2,(lx+rx)/2,rx);
        tree[idx]=max(tree[2*idx+1],tree[2*idx+2]);
    }
    void build(vector<int> &v){
        build(v,0,0,sz);
    }
    void update(int i,int x,int idx,int l,int r){
        if(r-l==1){
            tree[idx]=x;
            return;
        }
        int mi=(l+r)/2;
        if(i<mi)update(i,x,2*idx+1,l,mi);
        else update(i,x,2*idx+2,mi,r);
        tree[idx]=max(tree[2*idx+1],tree[2*idx+2]);
    }
    void update(int i,int x){
        update(i,x,0,0,sz);
    }
    int add(int lx,int rx,int idx,int l,int r){
        if(lx>=r || rx<=l)return 0;
        if(l>=lx && r<=rx)return tree[idx];
        return max(add(lx,rx,2*idx+1,l,(l+r)/2),add(lx,rx,2*idx+2,(l+r)/2,r));
    }
    int add(int lx,int rx){
        return add(lx,rx,0,0,sz);
    }
};
void precompute(){
}
const int nm=3e5+1;
void solve(int tc){
    int n,k;
    cin>>n>>k;
    vector<int> v(n);
    for(int i=0;i<n;i++)cin>>v[i];
    segtree st;
    st.init(nm);
    int ans=0;
    for(int i=0;i<n;i++){
        int val=st.add(max(0ll,v[i]-k),min(nm,v[i]+k+1));
        // cerr<<val<<"\n";
        st.update(v[i],val+1);
        ans=max(ans,val+1);
    }
    cout<<ans;
}
int32_t main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);cout<<fixed;cerr.tie(NULL);cout.precision(12);
    int t=1,ctr=0;
    // precompute();
    // cin>>t;
    while(t--){
        solve(ctr+1);
        ctr++;
    }
}

Measured memory_bytes: 13776
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Itr(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define setp(n) fixed << setprecision(n)
#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>
#define All(a) (a.begin()),(a.end())
#define rAll(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,k,ans=0;
	cin>>n>>k;
	ll A[n][40],o[40],K[40];
	ll m[40][2];
	rep(i,n){
		ll a; cin>>a;
		rep(j,40) A[i][j]=a%2, a=a>>1;
	}
	rep(i,40) K[i]=k%2, k=k>>1;
	rep(i,40){
		ll cnt=0;
		rep(j,n) if (A[j][i]==0) cnt++;
		ll rcnt=n-cnt;
		m[i][0]=rcnt*(1ll<<i);
		m[i][1]=cnt*(1ll<<i);
		if (2*cnt<=n)
			o[i]=0;
		else
			o[i]=1;
	}
	rep(i,40){
		ans+=m[i][K[i]*o[i]];
	}
	rep(i,40){
		if (K[i]==0) continue;
		ll sum=0;
		rep(j,40){
			if (j<i) sum+=m[j][1*o[j]];
			else if (j==i) sum+=m[j][0];
			else sum+=m[j][K[j]*o[j]];
		}
		ans=max(ans,sum);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 31488
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue> //priority_queue 优先队列
#include <map>
#include <set> //multiset  set<int>::reverse_iterator rit; for(rit=s.rbegin();rit!=s.rend();rit++)
#include <vector>
#include <stack>
#include <cmath>
#include <utility>
#include <sstream>
#include <string>
#define mod 1000000007
typedef unsigned long long ull;
typedef long long ll;
typedef double db;
const db eps=1e-6;
const int INF = 0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int N=1e6+5;
using namespace std;

int n,m,ans,x,a,b;
vector<int > v;
vector<int> ::iterator it;

int main(){
	scanf("%d%d",&a,&b);
	printf("%d\n",max(a+b,max(a*b,a-b)));
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define upd(x, y) x=max(x, (short)(y))

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod=1000000007;
const int N=105;

int n, m, k, u, v, x, y, t, ex, ey, ans;
char A[N][N];
short cnt[N][N];
short dp[N][N][N][N];

inline short get(int x, int y, int xx, int yy){
	return cnt[xx][yy]-cnt[x-1][yy]-cnt[xx][y-1]+cnt[x-1][y-1];
}

inline pii f(pii i, pii j){
	int l=max(i.first, j.first), r=min(i.second, j.second);
	if (l>r) r=l-1;
	return {l, r};
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n>>m;
	for (int i=1; i<=n; i++) for (int j=1; j<=m; j++){
		cin>>A[i][j];
		if (A[i][j]=='E') ex=i, ey=j;
		cnt[i][j]=(A[i][j]=='o')+cnt[i][j-1]+cnt[i-1][j]-cnt[i-1][j-1];
	}
//	debug2(ex, ey)
	for (int a=0; a<ey; a++)
		for (int b=0; ey+b<=m; b++)
			for (int c=0; c<ex; c++)
				for (int d=0; ex+d<=n; d++){
					pii px=f({1+d, n-c}, {ex-c, ex+d});
					pii py=f({1+b, m-a}, {ey-a-1, ey-a-1});
					upd(dp[a+1][b][c][d], dp[a][b][c][d] + get(px.first, py.first, px.second, py.second));
					
					px=f({1+d, n-c}, {ex-c, ex+d});
					py=f({1+b, m-a}, {ey+b+1, ey+b+1});
					upd(dp[a][b+1][c][d], dp[a][b][c][d] + get(px.first, py.first, px.second, py.second));
					
					px=f({1+d, n-c}, {ex-c-1, ex-c-1});
					py=f({1+b, m-a}, {ey-a, ey+b});
					upd(dp[a][b][c+1][d], dp[a][b][c][d] + get(px.first, py.first, px.second, py.second));
					
					px=f({1+d, n-c}, {ex+d+1, ex+d+1});
					py=f({1+b, m-a}, {ey-a, ey+b});
					upd(dp[a][b][c][d+1], dp[a][b][c][d] + get(px.first, py.first, px.second, py.second));
				}
	
	ans=dp[ey-1][m-ey][ex-1][n-ex];
	cout<<ans<<"\n";
	
	return 0;
}
/*
1 2
oE

*/

Measured memory_bytes: 57336
fun main(args: Array<String>) = abc160c()

fun abc160c() {
    val (k, n) = readLine()!!.split(' ').map { it.toInt() }
    val aList = readLine()!!.split(' ').map { it.toLong() }

    val diff = LongArray(n)
    diff[0] = k - aList.last() + aList.first()

    for (i in 0 until n - 1) {
        diff[i + 1] = aList[i + 1] - aList[i]
    }

    val answer = diff.sum() - diff.max()!!

    println(answer)
}


Measured memory_bytes: 82532
#include <bits/stdc++.h>
 
using namespace std;
 
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int d,g,a,b;
	vector <pair<int,int>> v;

	cin >> d >> g;

	for(int i=0;i<d;i++)
	{
		cin >> a >> b;
		v.push_back(make_pair(a,b));
	}

	int res = 1000000000;

	for(int i=1;i<(1<<d);i++)
	{
		vector <int> sel;
		int idx = 0;
		int n = i;
		while(n>0)
		{
			if(n%2==1)
			{
				sel.push_back(idx);
			}
			idx++;
			n/=2;
		}

		int count = 0;
		int score = g;
		for(int i=sel.size()-1;i>=0;i--)
		{
			int num = ceil((score*1.0)/((sel[i]+1)*100));
			if(num<v[sel[i]].first)
			{
				score-=((num)*(sel[i]+1)*100);
				count+=num;
			}
			else
			{
				score-=((v[sel[i]].first)*(sel[i]+1)*100);
				score-=(v[sel[i]].second);
				count+=v[sel[i]].first;
			}
			if(score<=0)
			{
				break;
			}
		}
		if(score<=0)
		{
			res = min(res,count);
		}
	}

	cout << res << '\n';
	
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    string ans;
    for(int i=0; i<3; ++i){
        string s;
        cin >> s;
        ans += s[0] - 'a' + 'A';
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int n,k,i;
	char c[50];
	scanf("%d %d",&n,&k);
	scanf("%s",&c[0]);
	for(i=0;i<n;i++){
		if(i==k-1)
			printf("%c",c[i]+32);
		else
			printf("%c",c[i]);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

#define SIZE 2000000

int main() {
  int A[SIZE];
  int H=0;
  int i, l, largest, tmp, n;
  char com[21], buf[20];
  buf[19]='\n';
  char *p;
  do {
    fgets(com, 20, stdin);
    if (*com == 'i') {
      A[++H] = 0;
      p = com+7;
      while (*p!='\n') {
        A[H] = A[H]*10+*p-'0';
        p++;
      }

      for (i=H; i>1 && A[i>>1]<A[i];i>>=1) {
        tmp = A[i>>1];
        A[i>>1] = A[i];
        A[i] = tmp;
      }

    } else if (com[1]=='x') { // extract
      n = A[1];
      for (i=18; n>0; n/=10) buf[i--]=(n%10)+'0';
      fputs_unlocked(buf+i+1, stdout);
      A[1] = A[H];
      i = 1;
      while (1) {
        l = i<<1;
        if (l < H && A[l] > A[i])        largest = l;
        else         largest = i;
        if (l+1 < H && A[l+1] > A[largest])  largest = l+1;
        if (largest == i) break;
        tmp = A[i];
        A[i] = A[largest];
        A[largest] = tmp;
        i = largest;
      }
      H--;
    }
  } while (com[2]!='d');
  return 0;
}



Measured memory_bytes: 5472
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>

using namespace std;

int main(){
  int N; cin >> N;
  
  vector <int> H(N);
  for(int i = 0; i < N; i++) cin >> H[i];

  vector <int> DP(N);

  DP[0] = 0;
  DP[1] = abs(H[1] - H[0]);
  for (int i = 2; i < N; i++){
    DP[i] = min(DP[i - 1] + abs(H[i - 1] - H[i]), DP[i - 2] + abs(H[i - 2] - H[i]));
  }
  cout << DP[N - 1] << endl;
  
  

  return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <iomanip>
using namespace std;

typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
const long double M_PI = 3.14159265358979323846265;
const ll INFL = 1LL << 60;//10^18 = 2^60
//ll MOD = 998244353;
void pres(long double A, ll x = 10){cout << fixed << setprecision(x) << A << endl;}


//Union Find
const ll MAX_V = 1000010;

ll par[MAX_V];//
ll Rank[MAX_V];
ll child[MAX_V];

void init_UF(){
  for(ll i = 0; i < MAX_V; i++){
    par[i] = i;
    Rank[i] = 1;
    child[i] = 1;
  }
}

ll find(ll x){
  if(par[x] == x) return x;
  else{
    return par[x] = find(par[x]);
  }
}

bool same(ll x, ll y){
  return find(x) == find(y);
}

void unite(ll x, ll y){
  ll rx = find(x), ry = find(y);
  if(rx != ry){
    if(Rank[rx] >= Rank[ry]){
      par[ry] = rx;
      if(Rank[rx] == Rank[ry]) Rank[rx]++;
      child[rx] += child[ry];
    }else{
      par[rx] = ry;
      child[ry] += child[rx];
    }
  }
}

void compress(vector<ll> &S){
  vector<ll> xs;
  rep(i, S.size()) xs.push_back(S[i]);
  sort(xs.begin(), xs.end());
  xs.erase(unique(xs.begin(), xs.end()), xs.end());
  rep(i, S.size()){
    S[i] = lower_bound(xs.begin(), xs.end(), S[i]) - xs.begin();
  }
}



int main(){
  init_UF();
  ll N;
  cin >> N;
  vector<ll> A(N), B(N);
  ll Axor = 0, Bxor = 0;
  rep(i, N){
    cin >> A[i];
    Axor ^= A[i];
  }
  rep(i, N){
    cin >> B[i];
    Bxor ^= B[i];
  }


  map<ll, ll> b;
  rep(i, N){
    b[B[i]]++;
  }
  b[Bxor]++;
  rep(i, N){
    b[A[i]]--;
  }
  b[Axor]--;
  rep(i, N){
    if(b[B[i]]){
      cout << -1 << endl;
      return 0;
    }
  }


  vector<ll> X, Y;
  rep(i, N){
    if(A[i] != B[i]){
      X.pb(A[i]);
      Y.pb(B[i]);
    }
  }

  //Axor, Bxor, X, Y;
  X.pb(Axor);
  Y.pb(Bxor);
  compress(X);
  compress(Y);
  N = X.size();

  rep(i, N){
    unite(X[i], Y[i]);
  }

  ll con = 0;
  set<ll> used;
  rep(i, N){
    ll x = find(X[i]);
    if(used.count(x)) continue;
    used.insert(x);
    con++;
  }
  cout << N - 1 + con - 1 << endl;

}


Measured memory_bytes: 35404
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

int main()
{
  int n;
  while (scanf("%d", &n) != EOF)
  {
    lli a[n], b[n];
    for (int i = 0; i < n; i++)
      scanf("%lld %lld", &a[i], &b[i]);

    sort(a, a+n), sort(b, b+n);

    if (n & 1) printf("%lld\n", b[n >> 1] - a[n >> 1] + 1);
    else printf("%lld\n", (b[n >> 1] + b[(n - 1) >> 1]) - (a[n >> 1] + a[(n - 1) >> 1]) + 1);
  }
  return 0;
}

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

bool match(string s, string t){
    int l = s.length();
    for (int i = 0; i < l; ++i){
        if (s[i] != '?' && s[i] != t[i]){
            return false;
        }
    }
    return true;
}

int main() {
    string S, T, ans = "UNRESTORABLE";
    cin >> S >> T;
    int sl = S.length();
    int tl = T.length();
    for (int i = sl-tl; i >= 0; --i){
        string s = S.substr(i, tl);
        if (match(s, T)){
            ans = S.substr(0, i) + T + S.substr(i + tl, sl - tl - i);
            for (int j = 0; j < ans.length(); j++){
                if (ans[j] == '?') ans[j] = 'a';
            }
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    Vec v(4);
    cin>>v[0]>>v[1]>>v[2]>>v[3];
    ll n;
    cin>>n;
    n *= 4;
    ll ans=INF;

    ll x = 1LL<<4;
    REP(i,1,x){
        if(!(i & 1LL<<0))continue;
        ll m = n;
        ll tans = 0;
        per(j,3){
            if(!(i & 1LL<<j))continue;
            if(m==0)break;
            ll c = pow(2,j);
            ll d = v[j];
            tans += m/c * d;
            m -= (m/c) * c;
        }
        ans = min(ans,tans);
    }

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


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
int n,q,k;
long long dt[101010];
vector<pair<int,int> >e[101010];
void dfs(int x,int y)
{
	for(int i=0;i<e[x].size();i++)
	{
		pair<int,int>p=e[x][i];
		if(p.first==y)
		{
			continue;
		}
		dt[p.first]=dt[x]+p.second;
		dfs(p.first,x);
	}
}
int main()
{
	cin>>n;
	for(int i=0;i<n-1;i++)
	{
		int a,b,c;
		cin>>a>>b>>c;
		e[a].push_back(make_pair(b,c));
		e[b].push_back(make_pair(a,c));
	}
	cin>>q>>k;
	dfs(k,0);
	for(int i=0;i<q;i++)
	{
		int a,b;
		cin>>a>>b;
		cout<<dt[a]+dt[b]<<endl;
	}
	return 0;
}


Measured memory_bytes: 14336
#include <stdio.h>
#define N 100

int main(){
  int i=0,j,n,minj,temp,count=0,flag=0;
  int A[N];
  
  scanf("%d",&n);
  while(i < n){
    scanf("%d",&A[i]);
    if(A[i]>=0 && A[i]<=100)i++;
  }
  
  for(i=0; i < n; i++){
    minj = i;   
    for(j=i; j<n; j++){
      if(A[j] < A[minj]){
	minj = j;
	flag = 1;
      }
    }
    if(flag == 0)continue;
    flag = 0;   
    temp = A[i];
    A[i] = A[minj];
    A[minj] = temp;
    count++;
  }
  
  for(i=0; i<n-1; i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[n-1]);
  printf("%d\n",count);
  
  return 0;
}



Measured memory_bytes: 2144
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	arr, flags := make([]int, n + 1), make([]bool, n + 1)
	for i := 1; i <= n; i++ {
		var tmp int
		fmt.Scan(&tmp)
		arr[i] = tmp
	}
	flags[1] = true
	now := 1
	count := 1
	for true {
		next := arr[now]
		if next == 2 {
			fmt.Println(count)
			break
		} else if flags[next] {
			fmt.Println(-1)
			break
		}
		now = next
		flags[now] = true
		count++
	}
}

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

using namespace std;




int main() {
    int N;
    cin>>N;
    int res = 0;
    for(int c=1;c<=N;c++) {
        int z;
        cin>>z;
        if(z%2==1&&c%2==1) res++;
    }
    cout<<res;
}


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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, l, r)  (a).begin()+(l),(a).begin()+(r)

int main() {
	int n;
	cin >> n;
	map<string, int> mp;
	string s;
	FOR(i, 1, n) {
		cin >> s;
		mp[s] = 1;
	}
	pv(mp.size())
	return(0);
}

Measured memory_bytes: 19176
/*
     Author:Raghav Bansal
     IIIT Una
                  */
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define BOLT ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define X first
#define Y second
#define endl "\n"
using namespace std;
void solve() {
	int n, m, x;
	cin >> n >> m >> x;
	int cases = (1 << n);
	int ans = 1e15;
	vector<vector<int>> v(n, vector<int>(m + 2));
	for (int i = 0; i < n; i++) {
		cin >> v[i][0];
		for (int j = 1; j <= m; j++) {
			cin >> v[i][j];
		}
	}
	for (int i = 1; i < cases; i++) {
		vector<int> standing(m + 1);
		int cost = 0;
		for (int j = 0; j < n; j++) {
			if (i & (1ll << j)) {
				cost += v[j][0];
				for (int k = 1; k <= m; k++) {
					standing[k] += v[j][k];
				}
			}
		}
		bool check = true;
		for (int i = 1; i <= m; i++) {
			if (standing[i] < x) {
				check = false;
				break;
			}
		}
		if (check) {
			ans = min(ans, cost);
		}
	}
	if (ans != 1e15)
		cout << ans << endl;
	else
		cout << -1 << endl;
}
int32_t main() {
	BOLT;
	solve();
}

Measured memory_bytes: 3652
using System;

namespace _522_JOIandIOI
{
	class Program
	{
		static void Main ( string[] args )
		{
			while (true)
			{
				//input
				string inputStr = Console.ReadLine ();

				if (inputStr == null)
				{
					break;
				}

				//process
				int joiCount = 0;
				int ioiCount = 0;

				int index = 0;

				while (index <= inputStr.Length - 3)
				{
					//J????????????
					if (inputStr[index] == 'J')
					{
						//O????????????
						index++;
						if (inputStr[index] == 'O')
						{
							//I????????????
							index++;
							if (inputStr[index] == 'I')
							{
								//????????????????¢???????
								joiCount++;
							}
						}
					}

					//I????????????
					if (inputStr[index] == 'I')
					{
						//OI?????¢????¶???????
						while (index + 2 < inputStr.Length)
						{
							if (inputStr[index + 1] == 'O' && inputStr[index + 2] == 'I')
							{
								//????????????????¢???????
								ioiCount++;
								index += 2;
							}
							else
							{
								break;
							}
						}
					}

					//?????????????????????????????°
					if (inputStr[index] != 'J')
					{
						index += 1;
					}
				}

				//output
				Console.WriteLine (joiCount);
				Console.WriteLine (ioiCount);
			}
		}
	}
}

Measured memory_bytes: 9024
//https://atcoder.jp/contests/abc157/tasks/abc157_d
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int pre[100005];
int cnt[100005];
int boom[100005];
int boom2[100005];
int getf(int a)
{
    return pre[a]==a?a:pre[a]=getf(pre[a]);
}
void merg(int a,int b)
{
    int f1=getf(a),f2=getf(b);
    if(f1!=f2)
        pre[f2]=f1;
}
int main()
{
    int n,m,k;
    cin>>n>>m>>k;
    int a,b;
    for(int i=1; i<=n; i++)
        pre[i]=i;
    for(int i=1; i<=m; i++)
    {
        cin>>a>>b;
        cnt[a]++,cnt[b]++;
        merg(a,b);
    }
    for(int i=1;i<=n;i++) getf(i);
    for(int i=1; i<=n; i++)
        boom[pre[i]]++;
    for(int i=1; i<=k; i++)
    {
        cin>>a>>b;
        if(pre[a]==pre[b])
            boom2[a]++,boom2[b]++;
    }

    for(int i=1; i<=n; i++)
    {
        cout<<boom[pre[i]]-cnt[i]-boom2[i]-1<<" ";
    }
}


Measured memory_bytes: 6044
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <utility>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cassert>
#include <string.h>

using namespace std;
#define  rep(i,n) for(int i=0;i<n;i++)
#define  rrep(i,n) for(int i=n;i>0;i--)
#define  REP(i,a,b) for(int i=a;i<b;i++)
typedef long long int lld;
typedef vector<lld> vl;
typedef vector<int> vi;
typedef vector<string> vs;



//int arr[N]
////sort(arr,arr +N)

//vector <int> hoge
////sort(hoge.begin(),hoge.end());
///min_element(hoge.begin(),hoge.end();　最小値　　　最大値はmax_element();

int main() {

	int n;
	cin>>n;
	vi prime{2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,87,89,97};
	vi factor(25,0);
	int p;
	int p2=0,p4=0,p14=0,p24=0,p74=0;
	for(int i=0;i<25;i++){
		p=prime[i];
		while(n/p>=1){
			factor[i]+=n/p;
			p*=prime[i];

		}
	}
	int ans=0;
	int f1=0,f2=0,f3=0,f4=0;
	rep(i,25){
		int f;f=factor[i];
		if(f==2 ||f==3){
			f1++;
		}
		if(f>=4 &&f<14){
			f2++;
		}
		if(f>=14 && f<24)
			f3++;
		if(f>=24)
			f4++;
	}
	/*rep(i,n){
		cout<<factor[i]<<endl;
	}
	 */
	//printf("f1=%d; f2=%d; f3=%d; f4=%d\n",f1,f2,f3,f4);
	if(factor[0]>=74)////////p^75の倍数
		ans=1;

	//cout<<"74 "<<ans<<endl;

	int tmp1;////4-4-2
	tmp1=(f1*(f2+f3+f4)*((f2+f3+f4)-1)/2)+(f2+f3+f4)*((f2+f3+f4)-1)*((f2+f3+f4)-2)/2;
	//cout<<"4-4-2 "<<tmp1<<endl;

	int tmp2;////14-4;
	tmp2=f2*(f3+f4)+(f3+f4)*(f3+f4-1);
	//cout<<"14-4 "<<tmp2<<endl;

	int tmp3;////24-2;
	tmp3=f4*(f1+f2+f3)+f4*(f4-1);
	//cout<<"24-2 "<<tmp3<<endl;

	cout<<ans+tmp1+tmp2+tmp3;







	return 0;

}


Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 1e5 + 5;
int n;
int a[maxn];

int read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  return true;
}

void solve() {
  long long l = 2, r = 2;
  for (int i = n - 1; i >= 0; i--) {
    long long x = a[i];
    long long nl = ((l + x - 1) / x) * x, nr = (r / x) * x;
    if (nl > nr) {
      printf("-1\n");
      return;
    }
    l = nl;
    r = nr + x - 1;
  }
  printf("%lld %lld\n", l, r);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


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

#define max_N 200010

int color[max_N];
vector<int> edges[max_N];
vector<int> sub_child[max_N];
long sub_size[max_N];
int parent[max_N];
int last_v[max_N];
long no_samecolor_vertex[max_N];
long ans[max_N];

long non_dupcount(int x){
	return (long) x * (x-1) / 2 + x;
}

void dfs(int v, int last = -1){
	parent[v] = last_v[color[v]];
	last_v[color[v]] = v;
	sub_size[v] = 1;
	if(parent[v] != -1) sub_child[parent[v]].push_back(v);
	for(auto x: edges[v]) {
		if(x == last) continue;
		dfs(x, v);
		long t_size = sub_size[x];
		sub_size[v] += t_size;
		for(auto child: sub_child[v])
			t_size -= sub_size[child];
		sub_child[v].clear();
		ans[color[v]] -= non_dupcount(t_size);
	}
	if(parent[v] == -1)
		no_samecolor_vertex[color[v]] -= sub_size[v];
	last_v[color[v]] = parent[v];
}

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		scanf("%d", &color[i]);
		color[i]--;
	}
	for(int i = 0; i < n-1; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		edges[x-1].push_back(y-1);
		edges[y-1].push_back(x-1);
	}
	for(int i = 0; i < n; i++) {
		no_samecolor_vertex[i] = n;
		last_v[i] = -1;
		ans[i] = non_dupcount(n);
	}
	dfs(0);
	for(int i = 0; i < n; i++) {
		ans[i] -= non_dupcount(no_samecolor_vertex[i]);
		printf("%ld\n", ans[i]);
	}
}


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

int main(){
    int mod = 110;
    int X, N;
    cin >> X >> N;

    vector<int> p(N);
    for(int i=0; i<N; ++i) cin >> p.at(i);
    sort(p.begin(),p.end());

    bool flg = true;

    for(int j=0; j<=101; ++j){
        for(int i=0; i<N; ++i){
            if(j == p.at(i)){
                flg = false;
                break;
            }
        }
        if(flg) mod = min(mod, abs(j - X));
        flg = true;
    }

    bool flg1 = true;
    bool flg2 = false;

    for(int j=0; j<=101; ++j){
        for(int i=0; i<N; ++i){
            if(j == p.at(i)){
                flg1 = false;
                break;
            }
        }
        if(flg1){
            if(abs(j-X) == mod){
                cout << j << endl;
                flg2 = true;
                break;
            }
        }
    flg1 = true;
    if(flg2) break;
    }
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define int long long
using namespace std;

signed main()
{
    int n;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    map<int,int> umap;
    for(int i=0;i<n;i++)
    {
        umap[v[i]]++;
    }

    int ans =0;

    for(auto it = umap.begin();it!=umap.end();++it)
    {
       if(it->first==it->second)
            continue;
       else
          {
              if(it->second<it->first)
                ans += it->second;
              else if(it->second>it->first)
                ans += it->second-it->first;
          }
    }
    cout<<ans;
}


Measured memory_bytes: 7040
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

const int INF = 1000000000;
const ll M = 1000000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},
                         {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/*----------------------------------------------/
/- char         : %c  | char *       : %s  | short        : %hd
/- int          : %d  | long         : %ld | long long    : %lld
/- unsigned short:%hu | unsigned int : %u  | unsigned long: %lu
/- u_long long  : %llu| (octal)      : %o  | (hexadecimal): %x
/- float        : %f  | double       : %lf |
/----------------------------------------------*/

/*----------------------------------------------/
/- INT_MAX, LONG_MAX   : 1<<15 = 2.1*pow(10, 9)       (= 2147483647)
/- UINT_MAX, ULONG_MAX : 1<<16 = 4.2*pow(10, 9)       (= 4294967295)
/- LLONG_MAX           : 1<<63 = 9.2*pow(10, 18)      (= 9223372036854775807)
/- ULLONG_MAX          : 1<<64 = 1.8*pow(10, 19)      (= 18446744073709551615)
/----------------------------------------------*/

string s;
int main() {
    cin >> s;
    int cnt = 0;
    int siz = s.size();
    for (int i = 0; i < siz - 1; i++) {
        if (s[i] != s[i + 1]) {
            cnt++;
            s.erase(i, 2);
            siz -= 2;
            i -= 2;
            i = max(-1, i);
        }
    }

    cout << cnt * 2;
    /* ====================================== */
    cout << endl;
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

int search(int A[], int n, int key){
	int i = 0;
	A[n] = key;
	while ( A[i] != key )i++;
	return i != n;
}

int main(){
	int i, n, A[10000+1], q, key, sum = 0;
	
	scanf("%d", &n);
	for ( i = 0; i < n; i++ ) scanf("%d", &A[i]);
	
	scanf("%d", &q);
	for ( i = 0; i < q; i++ ){
		scanf("%d", &key);
		if ( search(A, n, key)) sum++;
	}
	printf("%d\n", sum);
	
	return 0;
}



Measured memory_bytes: 2772
#include<iostream>

const int coins[] = {500, 100, 50, 10, 5, 1};
//int nums[] = {0, 0, 0, 0, 0, 0};

int run(){
	int x, x2, num = 0, t;
	int M = sizeof(coins) / sizeof(int);
	std::cin >> x;
	if( x == 0 ){ return 0; }
	x2 = 1000 - x;
	for( int i = 0; i < M; i++ ){
		t = x2 / coins[i];
		x2 -= t * coins[i];
		num += t;
	}
	std::cout << num << std::endl;
	return 1;
}

int main(){
	while( run() );
	return 0;
}

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

using namespace std;

using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int mx = (int)1e6 + 1;
  vector<int> a(n), cnt(mx);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  vector<bool> ok(mx, 1);
  for (int i = 1; i < mx; i++) {
    if (cnt[i] != 0) {
      for (int j = i + i; j < mx; j += i) {
        ok[j] = 0;
      }
    }
  }
  int ans = 0;
  for (int i = 1; i < mx; i++) {
    if (cnt[i] == 1 && ok[i]) {
      ans++;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 8208