akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e13;
const int mod = 1e9+7;
#define ll long long
map<char, int> m;
signed main() {
    string s;
    cin >> s;
    s = ">"+s+"<";
    vector<int> a(s.length()-1,-1);
    FOR(i,1,s.length()) {
        if(s[i-1]=='>'&&s[i]=='<') {
            a[i-1]=0;
        }
    }
    FOR(i,1,a.size()) {
        if(a[i-1]==0&&s[i]=='<'||s[i]=='<') {
            a[i]=max(a[i-1]+1,a[i]);
        }
        //cout << s[i]<<a[i] << flush;
    }

       // cout << "" << endl;
    RFOR(i,a.size()-2,0) {
        if(a[i+1]==0&&s[i+1]=='>'||s[i+1]=='>') {
            a[i]=max(a[i],a[i+1]+1);

        }
                   // cout << a[i] << s[i+2]<< flush;
 
    }
       // cout << "" << endl;
    int ans = 0;
    rep(i,a.size()) {
        ans += a[i];
       // cout << a[i] << flush;
    }
    //cout << "" << endl;
    cout << ans << endl; 
  return 0;
}



Measured memory_bytes: 7716
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
using namespace std;
const ll N=100010;

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

    ll x;
    cin>>x;
    ll lol=x/500;
    ll ans=1000*lol;
    x-=500*lol;
    ans+=5*(x/5);
    cout<<ans;

    return (0);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int a, b, c;
int main() {
  cin >> a >> b >> c;
  if (a == b && b == c) cout << 1 << "\n";
  else if (a != b && b != c && a != c) cout << 3 << "\n";
  else cout << 2 << "\n";
  return 0;
}



Measured memory_bytes: 256
import fractions
a,b=map(int,input().split())
g=fractions.gcd(a,b)

import math
def findFactors(n):
    now=n
    f=[]
    while now%2==0:
        now//=2
        f.append(2)
    p=3
    while p<=math.sqrt(n):
        while now%p==0:
            now//=p
            f.append(p)
        p+=2
        if now==1:
            break
    if now>math.sqrt(n):
        f.append(now)
    return f

if g==1:
    print(1)
else:
    f=set(findFactors(g))
    print(len(f)+1)

Measured memory_bytes: 5564
N=int(input())
S=input()
F=[]
B=[]
max=0

for i in range(1,N):
	F=S[0:i]
	B=S[i:N]
	tmp=set(F)&set(B)
	if tmp=='set()': tmp=0
	else: tmp=len(list(tmp))
	if max<tmp:
		max=tmp
print(max)

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int n;
ll k;
vector<int> a, f;

bool check(ll x) {
  ll res = 0;
  for (int i = 0; i < n; ++i) {
    res += max(0ll, 1ll * (a[i] - (x / f[i])));
  }
  return res <= k;
}

int main() {
  cin >> n >> k;
  a.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  f.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> f[i];
  }
  sort(a.begin(), a.end());
  sort(f.rbegin(), f.rend());
  ll mx_a = *max_element(a.begin(), a.end());
  ll mx_f = *max_element(f.begin(), f.end());
  ll ok = 1ll * mx_a * mx_f, ng = -1;
  while (1 < abs(ok - ng)) {
    ll mid = (ok + ng) / 2;
    if (check(mid)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  cout << ok << endl;
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)n; i++)
const int MOD = 1000000007;
// long long a;
int main(){
  int a;
  cin >> a;
  cout << a*(a + 1)/2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

struct Mod {
    static constexpr auto kMod = 1000000007L;

    Mod() : n(0) {}
    // can be implicitly converted
    Mod(int64_t n) : n(n) {}

    Mod operator*(Mod m) const { return (n * (m.n % kMod)) % kMod; }

    Mod& operator*=(Mod m) {
        *this = *this * m;
        return *this;
    }

    Mod pow(int64_t p) {
        if (p == 0) {
            return 1;
        }
        if (p == 1) {
            return n;
        }

        int64_t r = this->pow(p / 2).n;
        if (p % 2 == 0) {
            return r * r % kMod;
        } else {
            return (r * r % kMod) * n % kMod;
        }
    }

    Mod operator/(Mod m) const {
        if (n == 0) {
            return 0;
        }

        return *this * m.pow(kMod - 2);
    }

    Mod& operator/=(Mod m) {
        *this = *this / m;
        return *this;
    }

    Mod operator+(Mod m) const { return (n + m.n) % kMod; }

    Mod& operator+=(Mod m) {
        *this = *this + m;
        return *this;
    }

    Mod operator-(Mod m) const { return (kMod + n - m.n) % kMod; }

    Mod& operator-=(Mod m) {
        *this = *this - m;
        return *this;
    }

    int64_t n;
};

int main() {
    int64_t n, k;
    cin >> n >> k;

    k = min(n - 1, k);

    vector<Mod> fact(n + 1);
    fact[0] = 1;
    for (auto i : irange(1L, n + 1)) {
        fact[i] = fact[i - 1] * i;
    }

    Mod ans;
    for (auto i : irange(0L, k + 1)) {
        ans += fact[n] / fact[n - i] / fact[i] * fact[n - 1] / fact[i] /
               fact[n - 1 - i];
    }

    cout << ans.n << endl;
}

Measured memory_bytes: 1792
N=int(input())
import math
def isprime(x):
  for i in range(2,math.floor(math.sqrt(x))+2):
    if x%i==0:
      return False
      break
  return True

               
L=[]
one=11
while len(L)<N:
  if isprime(one):
    L.append(one)
  one+=10
print(*L)  

Measured memory_bytes: 62460
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	static long MIN = Long.MIN_VALUE;

	public static void main(String[] args){
		Scanner io = new Scanner(System.in);
		int N = io.nextInt();
		PriorityQueue<Integer> que1 = new PriorityQueue<Integer>();
		int[] center = new int[N];
		PriorityQueue<Integer> que2 = new PriorityQueue<Integer>(new Bigger());
		long sum1=0,sum2=0;
		
		int a;
		for (int i = 0; i < N; i++) {
			a = io.nextInt();
			sum1 += a;
			que1.offer(a);
		}
		for (int i = 0; i < N; i++) {
			a = io.nextInt();
			center[i] = a;
		}
		for (int i = 0; i < N; i++) {
			a = io.nextInt();
			sum2 += a;
			que2.offer(a);
		}
		
		long[] max = new long[N+1];
		long[] min = new long[N+1];
		
		max[0] = sum1;
		for(int i=0;i<N;i++){
			if(que1.peek()<center[i]){
				sum1 += center[i]-que1.poll();
				que1.offer(center[i]);
			}
			max[i+1] = sum1;
		}
		
		min[N] = sum2;
		for(int i=N-1;i>=0;i--){
			if(que2.peek()>center[i]){
				sum2 -= que2.poll()-center[i];
				que2.offer(center[i]);
			}
			min[i] = sum2;
		}
		long ans = Long.MIN_VALUE;
		for(int i=0;i<N+1;i++){
			ans = Math.max(ans,max[i]-min[i]);
		}
		System.out.println(ans);
	}
}

class Bigger implements Comparator<Integer>{

	@Override
	public int compare(Integer o1, Integer o2) {
		return Integer.compare(o2, o1);
	}
	
}

Measured memory_bytes: 100068
#include <iostream>
#include <map>

using namespace std;
map<int,int> mp,ind;
typedef long long ll;
ll imos[400010] = {};
int main(){
    ll i,n,d,a;
    cin >> n >> d >> a;
    for(i=0;i<n;i++){
        int x,h; cin >> x >> h;
        mp[x] += h; mp[x + 2*d + 1] += 0;
    }
    int now = 0;
    for(auto x:mp){
        ind[x.first] = now; now++;
    }
    ll ans = 0,dm = 0;
    for(auto x:mp){
        dm += imos[ind[x.first]];
        if(x.second<=dm) continue;
        ll t = (x.second - dm + a - 1)/a;
        ans += t;
        dm += a*t;
        imos[ind[x.first + 2*d + 1]] -= a*t;
    }
    cout << ans << endl;
}

Measured memory_bytes: 40832
#include <algorithm>
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <math.h>
using namespace std;

int main(){
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());

    long double N;
    long double M;
    cin >> N>>M;

    long double ans=N*M;
    long long aa;
    aa=std::floor(ans);
    cout << aa << endl;

}


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

int main() {
    ll h;
    cin >> h;
    ll adder = 1;
    ll tot = 0;
    while (h) {
        h /= 2;
        tot += adder;
        adder *= 2;
    }
    cout << tot << '\n';
}

Measured memory_bytes: 3640
import java.util.Arrays;
import java.util.Scanner;

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

            Arrays.sort(a);

            int Alice = 0;
            int Bob = 0;
            boolean isAlice = true;
            for (int i = N - 1; i >= 0; i--, isAlice = !isAlice) {
                if (isAlice) {
                    Alice += a[i];
                } else {
                    Bob += a[i];
                }
            }

            System.out.println(Alice - Bob);
        }
    }
}


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

int main()
{
  int n;
  string s, t;
  cin >> n;
  cin >> s >> t;
  
  for (int i = 0; i < n; i ++)
  {
    cout << s.at(i) << t.at(i);
  }
  cout << endl;
  
  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
long long f(long long b,long long x){return x<b?x:f(b,x/b)+x%b;}
long long g(){
	long long n,s,b=2,r=-1,z;
	scanf("%lld%lld",&n,&s);
	if(n<s)return -1;
	if(n==s)return n+1;
	for(;b*b<=n;b++)if(f(b,n)==s)return b;
	for(b=1;b*b<=n;b++)if((n-s)%b==0&&f(z=(n-s)/b+1,n)==s)r=z;
	return r;
}
int main(){printf("%lld\n",g());}

Measured memory_bytes: 128
// abc.cpp :
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

#define MOD 1000000007
#define rp(i,n) for(int i=0;i<(n);i++)
#define irp(i,n) for(int i=(n);i>=0;i--)
#define up(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define dw(i,s,e,d) for(int i=(s);i>(e);i-=(d))
#define in(x) cin>>(x)
#define ot(x) cout<<(x)
#define ote(x) cout<<(x)<<endl
void bye(auto x, int code=0){cout<<(x)<<endl;exit(code);}

void p1(vi v){
  for(auto a: v){ot(a);ot(",");}
}
void p2(vvi &x){
  for(auto v: x){ot("[");p1(v);ot("]\n");}
}

int main(){
	int a,b;cin>>a>>b;
	int ans = a+b;
	if(ans<a-b) ans = a-b;
	if(ans<a*b) ans = a*b;
	ote(ans);

}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>

#define rep(i,a,b) for(int (i) = (a) ; (i) < (b) ; (i) ++)
#define anin(a) printf("%d\n",a);
#define ando(a)printf("%lf\n",a);

int main(void){
	int N,ans(0),i;
	scanf("%d",&N);
	int B[N - 1];
	rep(i,0,N - 1){
		scanf("%d",&B[i]);
	}
	for(i = N - 1 ; i >= 0 ; i --){
		if(i == N - 1){
			ans += B[i - 1];
		}
		if(i == 0){
			ans += B[0];
		} 
		if(i > 0 && i < N - 1){
			if(B[i] > B[i - 1]){
				ans += B[i - 1];
			} else {
				ans += B[i];
			}
		}
	}
	anin(ans);
	return 0;
}

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

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);


  int h,a;cin>>h>>a;
  int cnt=0;
  while(h>0){
    h-=a;
    cnt++;
  }
  cout<<cnt<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <cstdio>
using namespace std;
typedef complex<double> P;
#define X real()
#define Y imag()

double dot(P a, P b){
  return (a.X * b.X + a.Y * b.Y);
}

P projection(P a, P b){
  //a???????????????b??????????????????????????£?°???±?????????????????????
  return dot(a,b)/abs(b)/abs(b)*b;
}

int main(){
  P p1, p2;
  double x1, x2, y1, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  p1 = P(x1,y1);
  p2 = P(x2,y2);
  p2 -= p1;
  int q;
  cin >> q;
  for(int i = 0; i < q; ++i){
    P p;
    cin >> x1 >> y1;
    p = P(x1,y1) - p1;
    p += p1 + (double)2*(projection(p,p2)-p);
    printf("%.9lf %.8lf\n",p.X,p.Y);
  }
  return 0;
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    int ans[4][3][10] = {};
    for (int i = 0; i < n; i++) {
        int b, f, r, v;
        cin >> b >> f >> r >> v;
        ans[b - 1][f - 1][r - 1] += v;
    }
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 10; k++) {
                cout << " " << ans[i][j][k];
            }
            cout << endl;
        }
        for (int j = 0; j < 20; j++) {
            cout << "#";
        }
        cout << endl;
    }
    for (int j = 0; j < 3; j++) {
        for (int k = 0; k < 10; k++) {
            cout << " " << ans[3][j][k];
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 3104
#include<iostream>
#include<cmath>
using namespace std;
int f(int n){
  return n*n;
}

int main(){
  int d;
  while( cin>>d){
    int sum=0;
    for(int i=d;i<600;i+=d){
      sum+=f(i)*d;
    }
    cout<<sum<<endl;
  }
}

Measured memory_bytes: 1160
N = int(input())
A = list(map(int, input().split()))
count = 0
for i in range(N):
    if A[i] <= 0:
        count += 1
ans = 0
if count%2 == 0 or 0 in A:
    for i in range(N):
        ans += max(A[i],-A[i])
else:
    tmp = -1000000000
    c = 0
    for i in range(N):
        if tmp < min(A[i],-A[i]) < 0:
            tmp = min(A[i],-A[i])
            c = i
    if tmp == -1000000000 and c == 0:
        if tmp != A[0]:
            tmp = 0
            c = A.index(0)
    
    for i in range(N):
        if i != c:
            ans += max(A[i],-A[i])
        else:
            ans += tmp
print(ans)

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

int numofbits5(long bits) {
  bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
  bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
  bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
  bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
  return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main(){
	int n,k,ret,sum;
	string b;
	while(cin >> n >> k && n || k){
		ret = 0;
		set<string> ret;
		vector<string> v,item(n);
		
		for(int i=0;i < n ; i++){
			cin >> item[i];
		}
		sort(item.begin(),item.end());
		for(int i=0;i < (1<<n);i++){
			sum = 0;v.clear();
			if(numofbits5(i) != k)continue;
			for(int j=0;j<n;j++){
				if( (1<<j) & i ){
					v.push_back(item[j]);
				}
			}
			do{
				b.clear();
				for(size_t i=0; i<v.size(); ++i){
					b += v[i];
				}
				ret.insert(b);
								
			}while(next_permutation(v.begin(),v.end()));
		}
		cout << ret.size() << endl;
	}
}

Measured memory_bytes: 0
using namespace std;
 
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#define all(x) (x).begin(),(x).end()
 
void solve(){
 
}
int main(){
    int h,w;
 
    cin >> h >> w;
	vector<string> s(h);
    for (int i = 0; i < h; i++){ cin >> s[i]; }
 
    const int dx[4] = {0,0,1,-1};
    const int dy[4] = {1,-1,0,0};
 
    bool can = true;
    for (int i = 0; i < h; i++){
        for (int k = 0; k < w; k++){
            if (s[i][k] != '#'){
                continue;
            }
            int cnt = 0;
            bool found = false;
            for (int p = 0; p < 4; p++){
                const int x = k + dx[p];
                const int y = i + dy[p];
                if (x >= 0 && x < w && y >= 0 && y < h){
                    if (s[y][x] == '#'){
                        found = true;
                    }
                }
            }
            if (found != true){
                cout << "No" << endl;
                exit(0);
            }
        }
    }
 
    cout << "Yes" << endl;
    /*if (can) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    */
}


Measured memory_bytes: 256
from sys import stdin
import sys
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7
input = stdin.readline

H, W, A, B = [int(x) for x in input().rstrip().split()]

factorial = [1]
for i in range(1, H+W):
	factorial.append(factorial[i-1] * i % mod)

def power(x, y):
	if y == 0:
		return 1
	elif y == 1:
		return x % mod
	elif y % 2 == 0:
		return power(x, int(y/2)) ** 2 % mod
	else:
		return power(x, int((y-1)/2)) ** 2 * x % mod
def C(n, r):
	return (((factorial[n] * x_inv[r]) % mod) * x_inv[n-r]) % mod
# x_inv = []
# for i in range(H+W):
# 	x_inv.append(power(factorial[i], mod-2))

x_inv = [0] * (H+W)
x_inv[-1] = power(factorial[-1], mod-2)
for i in range(H+W-2, -1, -1):
	x_inv[i] = x_inv[i+1] * (i+1) % mod

sum = 0
for i in range(B, W):
	sum += C(i+H-A-1, i) * C(A+W-i-2, A-1) % mod
print(sum%mod)


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

typedef unsigned long long ll;  
int main(){
	ll n,a,b;
	cin>>n>>a>>b;
	ll ans=n/(a+b)*a;
	if(a<=n-n/(a+b)*(a+b)) ans+=a;
	else ans+=n-n/(a+b)*(a+b);
	cout<<ans;
}

Measured memory_bytes: 384
#include <iostream>

 

using namespace std;

 

int main()
{
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;
    
    if(x-r >= 0 && y-r >= 0 && x+r <= w && y+r <= h)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


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

using namespace std;
using ll = long long;

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

    if (a + b == c || a + c == b || b + c == a) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main(){
  vector<int> arr(3);
  for(int i = 0; i < 3;i++) cin >> arr.at(i);
  sort(arr.begin(), arr.end());
  cout << arr.at(2) * 10 + arr.at(1) + arr.at(0);
  
}

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

int main(){
    std::string a, b;
    std::cin >> a >> b;
    std::string c = a + b;
    int hoge = std::stoi(c);

    int foo = (int)std::sqrt((double)hoge);
    if(foo * foo == hoge) std::cout << "Yes" << std::endl;
    else std::cout << "No" << std::endl;
    return 0;
}


Measured memory_bytes: 256
N, T = map(int, input().split())
A = list(map(int, input().split()))

min_num = 10 ** 9 + 7
diff = 0
count = 0
for i in range(N):
    min_num = min(min_num, A[i])
    if diff == A[i] - min_num:
        count += 1
    elif A[i] - min_num > diff:
        count = 1
        diff = A[i] - min_num
    else:
        continue

print(count)


Measured memory_bytes: 20480
n=list(map(int,list(input())))
l=len(n)
s=0
for i in range(l-1,0,-1):
  if n[i]<9:
    s+=9
    if n[i-1]!=0:
      n[i-1]-=1
  else:
    s+=n[i]
print(s+n[0])

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <sstream>
#include <iomanip>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int iINF = 100100100;
const ll llINF = 1LL << 60;
ll chmin(ll a, ll b)
{
	return a > b ? b : a;
}
int main()
{
	int n, m;
	cin >> n >> m;
	vector<P> p(m), sortp(m);
	map<P, int> mp;
	rep(i, m) {
		cin >> p[i].first >> p[i].second;
	}
	sortp = p;
	sort(sortp.begin(), sortp.end());
	rep(i, m) {
		mp[sortp[i]] = i;
	}
	vector<string> ans(m);
	int oldYear = sortp[0].first;
	int order = 0;
	rep(i, m) {
		if (oldYear == sortp[i].first)	order++;
		else {
			oldYear = sortp[i].first;
			order = 1;
		}
		ostringstream ss1;
		ss1 << setw(6) << setfill('0') << sortp[i].first;
		string s1(ss1.str());

		ostringstream ss2;
		ss2 << setw(6) << setfill('0') << order;
		string s2(ss2.str());

		ans[i] = s1 + s2;
	}
	rep(i, m)	cout << ans[mp[p[i]]] << endl;
	return 0;
}


Measured memory_bytes: 14340
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream cin("in.txt");
#endif
  int A, B;
  while (cin >> A >> B) {
    int res = max({A + B, 2 * A - 1, 2 * B - 1});
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;
/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
*/

#define MAX 10000
#define NIL -1

struct Node { int parent, left, right; };

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d) {
    if (u == NIL) return;
    D[u] = d;
    setDepth(T[u].left, d+1);
    setDepth(T[u].right, d+1);
}

int setHeight(int u) {
    int h1 = 0, h2 = 0;
    if (T[u].left != NIL)
        h1 = setHeight(T[u].left) + 1;
    if (T[u].right != NIL)
        h2 = setHeight(T[u].right) + 1;
    return H[u] = (h1 > h2 ? h1 : h2);
}

int getSibling(int u) {
    if (T[u].parent == NIL) return NIL;
    if (T[T[u].parent].left != u && T[T[u].parent].left != NIL)
        return T[T[u].parent].left;
    if (T[T[u].parent].right != u && T[T[u].parent].right != NIL)
        return T[T[u].parent].right;
    return NIL;
}

void print(int u) {
    printf("node %d: ", u);
    printf("parent = %d, ", T[u].parent);
    printf("sibling = %d, ", getSibling(u));
    int deg = 0;
    if (T[u].left != NIL) deg++;
    if (T[u].right != NIL) deg++;
    printf("degree = %d, ", deg);
    printf("depth = %d, ", D[u]);
    printf("height = %d, ", H[u]);

    if (T[u].parent == NIL) {
        printf("root\n");
    } else if (T[u].left == NIL && T[u].right == NIL) {
        printf("leaf\n");
    } else {
        printf("internal node\n");
    }
}

int main()
{
    int n;
    cin >> n;
    REP(i, n) T[i].parent = NIL;
    REP(i, n) {
        int v, l, r;
        cin >> v >> l >> r;
        T[v].left = l;
        T[v].right = r;
        if (l != NIL) T[l].parent = v;
        if (r != NIL) T[r].parent = v;
    }

    int root = 0;
    REP(i, n) if (T[i].parent == NIL) root = i;

    setDepth(root, 0);
    setHeight(root);

    REP(i, n) print(i);

    return 0;
}


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

#define debug(x) cerr<<#x<<'='<<x<<endl
#define set0(x) memset(x,0,sizeof(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
template<typename T> void read(T &x){
	x = 0;char ch = getchar();ll f = 1;
	while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
	while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}

ll l = 2,r = 2;

int k,a[100010];

int main() {
	read(k);
	for(int i=0;i<k;i++){
		read(a[i]);
	}
	for(int i=k-1;i>=0;i--){
		l = (l+a[i]-1)/a[i];
		r = r/a[i];
		
		if(l>r){
			cout<<-1<<endl;
			return 0;
		}else{
			l = l*a[i];
			r = r*a[i]+a[i]-1;
		}
	}
	cout<<l<<' '<<r<<endl;
	return 0;
}


Measured memory_bytes: 640
/*
    ____        __
   / __ \____  / /_  ____ _____ ___
  / /_/ / __ \/ __ \/ __ `/ __ `__ \
 / _, _/ /_/ / / / / /_/ / / / / / /
/_/ |_|\____/_/ /_/\__,_/_/ /_/ /_/
*/
#include<bits/stdc++.h>

typedef long long ll ;

#define X   first
#define Y   second
#define mp  make_pair
#define pii pair<int , int>
#define vec vector
#define vpii vector<pair<int , int>>
#define i_n   int i = 0 ; i< n ; i++
#define cn  int n ; cin>>n
#define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define cina int a[n] ; for(int i = 0 ; i < n ; i++) cin>>a[i]
#define pb push_back
#define SZ(x) ll(x.size())

using namespace std;
const int maxn = 1000*100+5 ;

string rotate(string s )
{
	string t ; 
	t += s[s.size()-1] ; 
	for(int i = 0 ; i < s.size() - 1 ; i++)
	{
		t += s[i] ; 
	}
	return t ; 
}

int main()
{
	migmig ;
	string s  ,t ; 
	cin>>s>>t ; 
	for(int i = 0 ; i < t.size() + 2 ; i ++)
	{
		t= rotate(t) ; 
		if(s == t) 
		{
			cout<<"Yes" ; 
			return  0 ; 
		}
	}
	cout<<"No" ; 
}
//////
////////
///////////



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 = Integer.parseInt(sc.next());

        // int ans = A < 10 && B < 10 ? A * B : -1;

        Boolean flg = false;
        for (int i = 9; i >= 1; i--) {
            if (N % i == 0 && N / i <= 9) {
                flg = true;
                break;
            }
        }

        if (flg) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }
}

Measured memory_bytes: 22612
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
using namespace std;
int main(void){
    int n;
    double x;
    int m[6];
    cin >> n;
    for(int i=0;i<6;i++)m[i]=0;
    for(int i=0;i<n;i++){
        scanf("%lf",&x);
        if(x<165.0)m[0]++;
        else if(165.0<=x && x<170.0)m[1]++;
        else if(170.0<=x && x<175.0)m[2]++;
        else if(175.0<=x && x<180.0)m[3]++;
        else if(180.0<=x && x<185.0)m[4]++;
        else m[5]++;
    }
    for(int i=0;i<6;i++){
        cout << i+1 << ":";
        for(int j=0;j<m[i];j++){
            cout << "*";
        }
        cout << endl;
    }
    return 0;
}


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

using namespace std;

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

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

    vector<int>ans(n);
    ans[0] = 0;
    for(int i = 1; i < n+1; i++) {
        ans[i] = ans[i-1] + L[i-1];
    }
    int count = 0;
    for(int i = 0; i < n+1; i++) {
        if(x >= ans[i]){
            count++;
        }
        else{
            break;
        }
    }
    cout << count << endl;
    
    return 0;
}

Measured memory_bytes: 256
//c
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef pair<int, int> pii;

int N;

int solve(vector<pii> v){
	
	sort(v.begin(), v.end());
	
	int rl, rs = 0, ws = 0;
	bool dp[1010] = {0};
	
	rl = v[N-1].first;
	
	for(int i=0; i<N; ++i){
		rs += v[i].first;
		ws += v[i].second;
	}
	
	rs -= rl;
	
	if(rs >= rl){
		return rs + rl + ws;
	}
	
	dp[0] = true;
	
	for(int i = 0; i < N-1; ++i){
		for(int j=rl-rs; j >=0; --j){
			
			if( dp[j] && j + v[i].second <= rl - rs )
				dp[j + v[i].second] = true;
				
		}
	}
	
	for(int i = rl - rs; i >= 0; --i){
	
		if(dp[i])
			return 2*rl + ws - i;
	}
}

int main(){
	
	while(cin>>N, N){
		
		vector<pii> v;
		int r, w;
		
		for(int i=0; i<N; ++i){
			
			cin >> r >> w;
			v.push_back(make_pair(r, w));
		}
		
		cout << solve(v) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
#define REP(i,u) for(int i=hd[u],v;v=to[i],i;i=nxt[i])
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
using namespace std;
typedef long long ll;
const int N=int(1e5)+10;

int n,m,len,x,y,tot; int dep[N],sm[N],K[N],q[N]; ll res;
int hd[N],to[N*2],nxt[N*2],ct;
void addE(int u,int v){ to[++ct]=v,nxt[ct]=hd[u],hd[u]=ct; }
void dae(int u,int v){ addE(u,v),addE(v,u); }

void dfs1(int p,int fa=0,int c=1,int d=1){
	dep[p]=d,sm[p]=c;
	REP(i,p) if(v!=fa){
		if(!dep[v]) dfs1(v,p,-c,d+1);
		else x=p,y=v,len=dep[p]-dep[v]+1;
	}
}

bool pre(){
	FOR(i,1,n) tot+=sm[i];
	if(!(len&1) && tot) return 0;
	if(len&1 && abs(tot)&1) return 0;
	return 1;
}

void dfs2(int p,int fa=0){
	if(!fa) memset(dep,0,sizeof(dep));
    dep[p]=1;
    REP(i,p) if(!dep[v])
		dfs2(v,p),sm[p]+=sm[v],K[p]+=K[v];
}

int main(){
//	freopen("father.in","r",stdin);
//	freopen("father.out","w",stdout);
	
	scanf("%d%d",&n,&m);
	for(int i=1,u,v;i<=m;i++)
		scanf("%d%d",&u,&v),dae(u,v);
	dfs1(1);
	
	if(!pre()) return cout<<-1,0;
	if(len&1) sm[x]-=(tot/=2),sm[y]-=tot,res+=abs(tot);
	else K[x]++,K[y]--;
	
	dfs2(1); int len=1;
	FOR(i,1,n)
		if(!K[i]) res+=abs(sm[i]);
		else q[++len]=K[i]*sm[i];
	sort(q+1,q+len+1);
	FOR(i,1,len) res+=abs(q[i]-q[(len+1)/2]);
	
	return cout<<res,0;
} 

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


#define long long long int

using namespace std;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef pair<int, int> pi;


int main() {
    std::ios_base::sync_with_stdio(false);

    string s;
    cin >> s;
    int n = s.size();
    while (n-- > 0){
        cout << 'x';
    }

    return 0;
}

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

int main()
{
	long long a, b, c, d;
	cin >> a >> b >> c >> d;
	long long ans1 = a * c, ans2 = a * d, ans3 = b * c, ans4 = b * d;
	long long lol = max(ans1, ans2);
	long long kek = max(ans3, ans4);
	long long ans = max(lol, kek);
	cout << max(lol,kek);
}

Measured memory_bytes: 3624
#include <iostream>
#include <map>
using namespace std;
typedef long long ll;
ll A[200005];
int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  for (int i=1; i<=N; i++) {
    cin >> A[i];
  }
  map<ll, int> m;
  ll ret = 0;
  for (ll i=1; i<=N; i++) {
    ll a = i - A[i];
    ret += m[a];
    m[A[i] + i]++;
  }
  cout << ret << endl;
}

Measured memory_bytes: 27924
package main

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

// S
var (
	S []string
	t [][]int
	H int
	W int
)

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func printIntln(v ...int) {
	if len(v) == 0 {
		return
	}
	b := make([]byte, 0, 4096)
	for i := 0; i < len(v)-1; i++ {
		b = append(b, strconv.Itoa(v[i])...)
		b = append(b, " "...)
	}
	b = append(b, strconv.Itoa(v[len(v)-1])...)
	fmt.Println(string(b))
}

func dfs(q [][2]int) [][2]int {
	warpq := make([][2]int, 0)
	for len(q) != 0 {
		h, w := q[0][0], q[0][1]
		warpq = append(warpq, [2]int{h, w})
		q = q[1:]
		if h-1 >= 0 && t[h-1][w] > t[h][w] {
			q = append(q, [2]int{h - 1, w})
			warpq = append(warpq, [2]int{h - 1, w})
			t[h-1][w] = t[h][w]
		}
		if h+1 < H && t[h+1][w] > t[h][w] {
			q = append(q, [2]int{h + 1, w})
			warpq = append(warpq, [2]int{h + 1, w})
			t[h+1][w] = t[h][w]
		}
		if w-1 >= 0 && t[h][w-1] > t[h][w] {
			q = append(q, [2]int{h, w - 1})
			warpq = append(warpq, [2]int{h, w - 1})
			t[h][w-1] = t[h][w]
		}
		if w+1 < W && t[h][w+1] > t[h][w] {
			q = append(q, [2]int{h, w + 1})
			warpq = append(warpq, [2]int{h, w + 1})
			t[h][w+1] = t[h][w]
		}
	}
	return warpq
}

func main() {
	defer flush()

	H = readInt()
	W = readInt()
	Ch := readInt() - 1
	Cw := readInt() - 1
	Dh := readInt() - 1
	Dw := readInt() - 1
	S = make([]string, H)
	for i := 0; i < H; i++ {
		S[i] = readString()
	}

	t = make([][]int, H)
	for i := 0; i < H; i++ {
		t[i] = make([]int, W)
		for j := 0; j < W; j++ {
			if S[i][j] == '#' {
				t[i][j] = -1
			} else {
				t[i][j] = math.MaxInt64
			}
		}
	}

	t[Ch][Cw] = 0
	q := make([][2]int, 0)
	q = append(q, [2]int{Ch, Cw})
	warpq := dfs(q)
	if t[Dh][Dw] != math.MaxInt64 {
		println(t[Dh][Dw])
		return
	}

	for {
		q := make([][2]int, 0)
		for len(warpq) != 0 {
			h, w := warpq[0][0], warpq[0][1]
			warpq = warpq[1:]
			for i := max(0, h-2); i <= min(H-1, h+2); i++ {
				for j := max(0, w-2); j <= min(W-1, w+2); j++ {
					if t[i][j] <= t[h][w]+1 {
						continue
					}
					t[i][j] = t[h][w] + 1
					q = append(q, [2]int{i, j})
				}
			}
		}
		if len(q) == 0 {
			break
		}
		warpq = dfs(q)
		if t[Dh][Dw] != math.MaxInt64 {
			break
		}
	}

	if t[Dh][Dw] == math.MaxInt64 {
		println(-1)
	} else {
		println(t[Dh][Dw])
	}
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

var stdoutWriter = bufio.NewWriter(os.Stdout)

func flush() {
	stdoutWriter.Flush()
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdoutWriter, args...)
}


Measured memory_bytes: 38412
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long

const int N = 300030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    1e9+7;
int a[5];
int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int mx=0;
for(int i=0;i<6;i++)
{
	int x;
	cin>>x;
	a[x]++;
	if(a[x]>mx)
	mx=a[x];
}
if(mx<=2)

cout<<"YES";
else
cout<<"NO";


}

Measured memory_bytes: 256
def solve(N, K):
    M = (N - 1) * (N - 2) // 2 - K
    if M < 0:
        return '-1'

    pairs = []

    for i in range(2, N + 1):
        pairs.append(('1', str(i)))

    m = M
    for i in range(2, N):
        if m == 0:
            break;
        for j in range(i + 1, N + 1):
            if m == 0:
                break;
            m -= 1
            pairs.append((str(i), str(j)))

    return str(len(pairs)) + '\n' + '\n'.join([' '.join(pair) for pair in pairs])


if __name__ == '__main__':
    N, K = map(int, input().split())
    print(solve(N, K))


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

using namespace std;
int main(){
	long long x[3005], y[3005];
	int a,n=1;
	cin>>x[n]>>y[n];
	while( x[n]!=0 || y[n]!=0 ){
		if(x[n]>y[n]){	
		a=x[n];
		x[n]=y[n];
		y[n]=a;
	}
		cout<<x[n]<<' '<<y[n]<<endl;
		n++;
		cin>>x[n]>>y[n];
	}
}



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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define FOR(NAME, START, NUM) for (ll NAME = START; NAME < (NUM); NAME++)
#define REP(NAME, NUM) for (ll NAME = 0; NAME < (NUM); NAME++)
#define BREP(NAME, NUM) for (ll NAME = (NUM)-1; NAME >= 0; NAME--)
#define ALL(NAME) (NAME).begin(), (NAME).end()
const ll INF =1000000000000000;

ll f357(ll x){
  string s=to_string(x);
  if(s[s.size()-1]!='3')return x-2;
  string t="";
  BREP(i,s.size()){
    ll a=s[i]-'0';
    if(a!=3){
      REP(j,i)t+=s[j];
      t+=((s[i]-'0')-2)+'0';
      FOR(k,i+1,s.size())t+='7';
      return stoll(t);
    }
  }
  REP(i,s.size()-1)t+='7';
  return stoll(t);
}

ll start357(ll x){
  string s=to_string(x);
  string t="";
  REP(i,s.size())t+='7';
  int y=stoll(t);
  while(y>x){
    y=f357(y);
  }
  return y;
}

bool cnt357(ll x){
  string s=to_string(x);
  bool b3=0,b5=0,b7=0;
  REP(i,s.size()){
    ll a=s[i]-'0';
    if(a==3)b3=1;
    if(a==5)b5=1;
    if(a==7)b7=1;
  }
  if(b3*b5*b7==1)return true;
  else return false;
}
int main(){
  ll n,strat;
  cin >> n;  
  if(n<3){
    cout<<0<<endl;
    return 0;
  }
  ll z=start357(n),cnt=0;
  while(z>=77){
    if(cnt357(z)==true)cnt++;
    z=f357(z);
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int X,N,Y;
  int M=0;
  bool E=false;
  bool F=false;
  cin>>X>>N;
  int A=X;
  int B=X;
  vector<int>vec(N);
  for (Y=0; Y<N; Y++){
    cin >>vec.at(Y);
    if (vec.at(Y)==X){
      M=1;
    }
  }
  if (M==0){
    cout << X << endl;
  }
  else {
    for (Y=0; Y<100; Y++){
      E=false;
      F=false;
      A-=1;
      B+=1;
      for (int C=0; C<N; C++){
        if (vec.at(C)==A){
          E=true;
        }
      }
      for (int D=0; D<N; D++){
        if (vec.at(D)==B){
          F=true;
        }
      }
      if (E==false){
        break;
      }
      if (F==false){
        break;
      }
    }
    if(E==false){
      cout << A << endl;
    }
    else if(F==false){
      cout << B << endl;
    }
  }
}

Measured memory_bytes: 3644
n = int(input())
tree = [[] for _ in range(n)]
for _ in range(n-1):
    u, v, w = map(int, input().split())
    tree[u-1].append((v-1, w))
    tree[v-1].append((u-1, w))

stack = [0]
color = [-1] * n
color[0] = 0
while stack:
    v = stack.pop()
    for child, w in tree[v]:
        if color[child] < 0:
            color[child] = (color[v] + w) % 2
            stack.append(child)
for i in color:
    print(i)

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

int main()
{
	int n ,t,a,x,q= 0;
	float c, d = 1000000;
		cin >>n>> t>>a;
		for (int i = 1; i < n + 1;i++) {
		cin >> x;
		c = (t - x * 0.006)-a;
		if (c < 0)c = -c;
		if (c<d) {
			q = i;
			d = c;
		}
	}
	cout << q; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (2e9)

int cnt = 0;

void merge(int A[], int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;
  int L[n1+1], R[n2+1];
  for(int i = 0; i < n1; i++) L[i] = A[left + i];
  for(int i = 0; i < n2; i++) R[i] = A[mid + i];
  L[n1] = R[n2] = INF;
  int i = 0;
  int j = 0;
  for(int k = left; k < right; k++) {
    if(L[i] <= R[j]) {
      A[k] = L[i];
      i++;
    } else {
      A[k] = R[j];
      j++;
    }
    cnt++;
  }
}

void mergeSort(int A[], int left, int right) {
  if(left + 1 < right) {
    int mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int main() {
  int n, A[1000000];
  cin >> n;
  for(int i = 0; i < n; i++) cin >> A[i];

  mergeSort(A, 0, n);
  
  cout << A[0];
  for(int i = 1; i < n; i++) cout << " " << A[i];
  cout << endl;
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 7004
#include <iostream>
using namespace std;
int main(void){
    // Here your code !
    string number;
    
    while(1){
    cin>>number;
    if(number=="0")break;
    int num;
    int k=0;
    for(int i=0;number[i];i++){
        num=number[i]-'0';
        k=num+k;
    }
    cout<<k<<endl;
    }
}

Measured memory_bytes: 1188
#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn = 100005;

struct Edge
{
	int to, nxt;
} e[maxn << 1];

int first[maxn];

inline void add_edge(int from, int to)
{
	static int cnt = 0;
	e[++cnt].nxt = first[from];
	first[from] = cnt;
	e[cnt].to = to;
	e[++cnt].nxt = first[to];
	first[to] = cnt;
	e[cnt].to = from;
}

int sg[maxn];
int n;

inline void dfs(int now, int fa)
{
	for (int i = first[now]; i; i = e[i].nxt)
	{
		register int to = e[i].to;
		if (to != fa)
		{
			dfs(to, now);
			sg[now] ^= sg[e[i].to];
		}
	}
	if(now != 1)
		sg[now]++;
}

int main()
{
	scanf("%d", &n);
	for(int i = 1, f, t; i < n; ++i)
	{
		scanf("%d%d", &f, &t);
		add_edge(f, t);
	}
	dfs(1, 0);
	puts(sg[1] ? "Alice" : "Bob");
	return 0;
}

Measured memory_bytes: 4736
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll nCm(ll n, ll m){
    if(m == 0 || m == n){
        return 1;
    } else if(m == 1){
        return n;
    }
    return (nCm(n - 1, m) + nCm(n - 1, m - 1));
}

//-----------------------ここから-----------


int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        a[i]--;
    }
    
    int now = 0;
    int next = a[0];
    bool ok = false;
    int ans = 0;
    while(ans <= n){
        ans++;
        now = next;
        next = a[now];
        if(now == 1){
            ok = true;
            break;
        }
    }

    if(ok){
        cout << ans << endl;
    } else {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define forr(i,p,n) for(ll i=p;i<n;i++)
#define tam 410000
#define offset 8010
using namespace std;
typedef long long  ll;
typedef pair<int,int> ii;
typedef pair<ll,ii> iii;
typedef pair<map<ll,ll> ,ll> mi;
typedef pair<ii,ii> iiii;
typedef vector<ll> vi;
const ll MOD=1e9+7;
set<int> s[12345];
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    string s2,t;
    cin>>s2>>t;

    forr(i,0,s2.size())
    {
        s[s2[i]].insert(i);
    }
    int antpos=-1;
    bool nop=false;
    set<int>::iterator ite;
    ll tot=0;
    forr(i,0,t.size())
    {
        if (s[t[i]].size()==0)
            nop=1;
        if (nop)continue;
        ite=s[t[i]].upper_bound(antpos);
        if (ite==s[t[i]].end())
        {
            tot+=s2.size()-1-antpos;
            ite=s[t[i]].begin();
            tot+=*ite+1;
            antpos=*ite;
        }
        else
        {
            tot+=*ite-antpos;
            antpos=*ite;
        }
    }
    if (nop==false)
    cout<<tot<<endl;
    else
    cout<<-1<<endl;
}


Measured memory_bytes: 5712
#include <iostream>
#include <utility>
using namespace std;
	int a[200],b[200];int n,m,k;
void cut(){
	cin>>k;
	if(k == 0){
		for(int s = 0;s<n;s++){
			b[2*s] = a[s];
			b[2*s+1] = a[s+n];
		}
	}
	else{
		for(int i = 0;i < 2*n;i++){
			if(i<k){
				b[2*n-k+i]=a[i];
			}
			else{
				b[i-k]=a[i];
			}
		}
	}
	for(int i = 0;i<2*n;i++){
		swap(a[i],b[i]);
	}
}
 
int main() {
	cin >> n;
	for(int i = 0;i<2*n;i++){
		a[i]=i+1;
	}
	cin >> m;
	for(int i = 0;i<m;i++){
		cut();
	}
for(int i = 0;i<2*n;i++){
	cout<<a[i]<<endl;
}
	return 0;
}

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

int main()
{
    int m,f,r;
    char ans;

    while(1){
        cin>>m>>f>>r;
        if(m==-1&&f==-1&&r==-1)break;

        if(m==-1||f==-1){
            ans='F';
        }else if(m+f>=80){
            ans='A';
        }else if(m+f>=65){
            ans='B';
        }else if(m+f>=50){
            ans='C';
        }else if(m+f>=30){
            if(r>=50){
                ans='C';
            }else{
                ans='D';
            }
        }else{
            ans='F';
        }

        cout<<ans<<endl;
    }

    return 0;
}


Measured memory_bytes: 3088
#include<stdio.h>

int main(void){

int a,b,c,x;
scanf("%d %d %d",&a,&b,&c);
 
if(a>b){
x=a;
a=b;
b=x;
}
 
if(b>c){
x=b;
b=c;
c=x;
}
 
if(a>b){ 
x=a;
a=b;
b=x;
}
 
printf("%d %d %d\n",a,b,c);
 
return 0;
}

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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


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

  int d[101];
  REP(i, 101) d[i] = 0;

  FOR (i, 1, n + 1) {
    int p = i;
    int j = 2;
    while(true) {
      if (p == 1) break;
      if (p % j == 0) {
        p /= j;
        d[j]++;
        continue;
      }
      j++;
    }
  }

  int four = 0;
  int tt = 0;
  int sev = 0;
  int tf = 0;
  int ff = 0;
  REP (i, 101) {
    if (d[i] >= 74) sev++;
    else if (d[i] >= 24) tf++;
    else if (d[i] >= 14) ff++;
    else if (d[i] >= 4) four++;
    else if (d[i] >= 2) tt++;
  }

  int a = four + ff + tf + sev;
  int all = tt + a;
  int b = ff + tf + sev;
  int c = tf + sev;

  LL ans = ((a * (a - 1)) / 2) * (tt + a - 2);
  ans += b * (a - 1);
  ans += c * (all - 1);
  ans += sev;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>

using namespace std;

#define FOR(x) for(int i = 0; i < x; i++)


stack<short> x, y;
short a[10], n, j, i;

bool solve(short c, bool judge){
	if(c == 10) return true;
	if(x.top() < a[c]){
		x.push(a[c]);
		if(solve(c + 1, true)) return true;
	}
	if(y.top() < a[c]){
		y.push(a[c]);
		if(solve(c + 1, false)) return true;
	}
	if(judge) x.pop();
	else y.pop();
	return false;
}

int main(){
	scanf("%d", &n);
	for(i = 0; i < n; i++){
		x.push(0);
		y.push(0);
		for(j = 0; j < 10; j++)
			scanf("%d", &a[j]);
		if(solve(0, true)) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 1016
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,0,-1}, dy[4]={1,0,-1,0};
long double eps = 1e-9;
long double pi = acos(-1);

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    ll n;
    cin>>n;
    ll a[n];
    ll now = 1e18;
    ll ans = 1;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i] == 0){
            cout << 0 << endl;
            return 0;
        }
        now /= a[i];
        ans *= a[i];
    }
    if(now == 0) cout << -1 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 4392
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
int a[101];
int main(){
    cin>>N;
    int ma=0;
    int maind=-1;
    int mi=0;
    int miind=-1;
    REP(i,N){
        cin>>a[i];
        if(ma<=a[i]){
           ma=a[i];
           maind=i;
        }
        if(mi>=a[i]){
           mi=a[i];
           miind=i;
        }
    }
    cout<<2*N<<endl;
    if(abs(ma)>abs(mi)){
       REP(i,N){
           cout<<(maind+1)<<" "<<(i+1)<<endl;
       }
       cout<<maind+1<<" "<<1<<endl;
       REP(i,N){
           if(i==0)continue;
           cout<<i<<" "<<i+1<<endl;
       }
    }else{
       REP(i,N){
           cout<<(miind+1)<<" "<<(i+1)<<endl;
       }
       cout<<miind+1<<" "<<N<<endl;
       for(int i=N-1;i>0;i--){
           if(i==0)continue;
           cout<<i+1<<" "<<i<<endl;
       }
    }
    
    
    
    
    return(0);
}

Measured memory_bytes: 256