akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> 
#define int long long
#define quickie ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rep(i, a, b) for(int i=a; i<b; i++)
#define rep1(i, a, b) for(int i=a; i<=b; i++)
#define repp(i, a, b) for(int i=b-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define db double
#define mi map<int, int>
#define mc map<char, int>
#define ms map<string, int>
#define vi vector<int>
#define qi queue<int>
#define MI(x) power(x, mod-2)
#define test int t; cin >> t;
//#define mod 1000000007LL
#define mod 998244353 
using namespace std;
int power(int x, int y) ;
int gcd(int a, int b) ;

signed main() {
    quickie
    int n ;
    cin >> n ;
    int sum = 0 ;
    rep(i, 1, n+1) {
        rep(j, 1, n+1) {
            rep(k, 1, n+1) {
                sum += gcd(gcd(i, j),k) ;
            }
        }
    }
    cout << sum << endl ;
}

int power(int x, int y) {
    int res = 1; x %= mod;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res%mod;
}
 
int gcd(int a,int b){
    if(a==0) return b;
    return gcd(b%a,a);
}

Measured memory_bytes: 3584
#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ll;

int main(void){
    int A,B,M,a[100000],b[100000],x,y,c;
    cin>>A>>B>>M;
    int a_min,b_min,sum_min;
    a_min=b_min=INT_MAX;

    for(int i=0;i<A;++i){
        cin>>a[i];
        if(a[i]<a_min){
            a_min=a[i];
        }
    }
    for(int i=0;i<B;++i){
        cin>>b[i];
        if(b[i]<b_min){
            b_min=b[i];
        }
    }
    sum_min=a_min+b_min;

    for(int i=0;i<M;++i){
        cin>>x>>y>>c;
        int sum=a[x-1]+b[y-1]-c;
        if(sum<sum_min){
            sum_min=sum;
        }
    }

    cout<<sum_min;

}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(){
  int N,K;
  char S[N];
  cin >> N >> S >> K;
  char a = S[K-1];
  for(int i = 0;i<N;i++){
    if (S[i] != a){
      S[i] = '*';
    }
  }
  std::cout << S << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int n,a,b,ans=0;
	cin >> n >> a >> b;
	for (int i = 1; i <= n; ++i) {
		int num = i;
		int sum = num % 10;
		while ((int)num / 10 > 0) {
			sum += (num/10)%10;
			num /= 10;
		}
		if (a <= sum && sum <= b) {
			ans += i;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
const ll mod=1e+9;
typedef pair<int,int> P;
#define fi first
#define se second
int main(){
    ios::sync_with_stdio(false);
   cin.tie(0);
int n,h;
cin>>n>>h;
vector<int> c(n),t(n);
for(int i=0;i<n;i++){
    int a,b;
    cin>>a>>b;
    c.at(i)=a;
    t.at(i)=b;
}
sort(c.begin(),c.end(),greater<int>());
sort(t.begin(),t.end(),greater<int>());
int ans=0;
for(int i=0;i<n;i++){//切るが上回ったら投げるのをやめる
    if(c.at(0)>t.at(i))break;
    h-=t.at(i);
    ans++;
    if(h<=0)break;
}
if(h>0){
    if(h%c.at(0)==0)ans+=h/c.at(0);
    else ans+=h/c.at(0)+1;
}
cout<<ans<<endl;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
// const ll LLINF = 100;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

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

struct SegTree {
  int size;
  vector<ll> pos;
  SegTree(ll N) { size = 1; while(size<N) size<<=1; pos.resize(2*size,0); }
  ll operator[](const ll &x) const { return pos[x+size]; }

  void build() { per(i,size) operate(i); }
  void set(ll x, const ll v) { pos[x+size] = v; }
  void update(ll x, const ll v) { set(x,v); x+=size; while (x>>=1) operate(x); }
  ll query(ll a, ll b) {
    ll L = LLINF, R = LLINF;
    for (a+=size, b+=size; a<b; a>>=1, b>>=1) {
      if (a&1) { L = q(L,pos[a]); a++; }
      if (b&1) { b--; R = q(pos[b],R); }
    }
    return q(L,R);
  }
  void operate(ll i) { pos[i] = min(pos[i*2], pos[i*2+1]); }
  ll q(ll x, ll y) { return min(x, y); }
};

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


int main() {
  ll N, Q, A, B; cin >> N >> Q >> A >> B; A--; B--;
  ll x[Q+1] = {}; rep(i,Q) { cin >> x[i+1]; x[i+1]--; } x[0] = A;

  SegTree up(N), down(N);
  rep(i,N) {
    if (i!=B) { up.update(i,LLINF+(N-1)-i); down.update(i,LLINF+i); }
    else { up.update(i,(N-1)-i); down.update(i,i); }
  }

  ll result = 0;
  repr(i,1,Q+1) {
    result += abs(x[i]-x[i-1]);
    ll ltor = up.query(0,x[i]) - ((N-1)-x[i]);
    ll rtol = down.query(x[i],N) - x[i];
    ll mi = min(ltor, rtol) - abs(x[i]-x[i-1]);
    up.update(x[i-1],mi+(N-1)-x[i-1]); down.update(x[i-1],mi+x[i-1]);
    // rep(j,N) cout << up[j] - ((N-1)-j) << " "; cout << endl;
    // cout << ltor << " " << rtol << " " << mi << endl;
  }

  ll mv = LLINF; rep(i,N) mv = min(mv, up[i]-((N-1)-i));
  result += mv;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 13036
#include<stdio.h>
int main(void){
    int i,N,k[10000],NA,count;
    while(1){
        scanf("%d",&N);
        if(N==0)break;
        NA=1;
        count=0;
        for(i=0;i<10000;i++){
            if(i<N){
                scanf("%d",&k[i]);
                if(k[i]>=2)NA=0;
            }else{
                k[i]=-1;
            }
        }
        if(NA==1){
            printf("NA\n");
        }else{
            for(i=0;i<10000;i++){
                if(k[i]>=1)count++;
            }
            printf("%d\n",count+1);
        }
    }
    return 0;
}

Measured memory_bytes: 648
n = int(input())
A = list(map(int, input().split()))

A_cum = A

for i in range(1, n):
  A_cum[i] = A_cum[i] + A_cum[i-1]

A_cum_all = A_cum[-1]
ans = float('inf')

for i in range(n-1):
  x = A_cum[i]
  y = A_cum_all - x
  ans = min(ans, abs(x-y))
  
print(ans)

Measured memory_bytes: 24832
#include<stdio.h>

int main(void){
    int n,m,a,i,fibo[100000],b=1000000007;
    scanf("%d %d",&n,&m);
    for(i=0;i<n+1;i++){
        fibo[i]=1;
    }
    for(i=0;i<m;i++){
        scanf("%d",&a);
        fibo[a]=0;
    }
    for(i=2;i<n+1;i++){
        if(fibo[i]!=0){
            fibo[i]=fibo[i-1]+fibo[i-2];
            if(fibo[i]>b){
                fibo[i]%=b;
            }
        }
    }
    printf("%d",fibo[n]);
    return 0;
}


Measured memory_bytes: 512
S=strip(readline())
count=0
for i in 1:length(S)
  if i%2==0
    if S[i]=='R'
      break
    else
      count+=1
    end
  else
    if S[i]=='L'
        break
    else
      count+=1
      end
  end
end

if count==length(S)
  println("Yes")
  else
    println("No")
end

Measured memory_bytes: 166512
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define sz(a) (int)a.size()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a<<" "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int P = 1e9 + 7;
inline int add(int a, int b) {if((a += b) >= P) a -= P; return a;}
inline int sub(int a, int b) {if((a -= b) < 0) a += P; return a;}
inline int mul(int a, int b) {return 1ll * a * b % P;}
inline int kpow(int a, int b) {int r=1;for(;b;b>>=1,a=mul(a,a)) {if(b&1)r=mul(r,a);}return r;}
//----
int n;
set<ll> nine;
bool gao(ll head, ll tail) {
	int s = 0;
	if(nine.count(head))
		return 1;
	ll t = tail;
	while(t) {
		s += t % 10;
		t /= 10;
	}
	t = head;
	while(t) {
		s += t % 10;
		t /= 10;
	}
	ll p = 1;
	t = head;
	while(t) {
		if(t % 10 != 9) break;
		p *= 10;
		t /= 10;
	}
	return p * (tail + 1) * s >= head * (tail + 1) + tail;
}
int main(){
	ll t = 0;
	rep(i, 0, 15) {
		t = t * 10 + 9;
		nine.insert(t);
	}
	scanf("%d", &n);
	int cnt = 0;
	ll tail = 0, head = 0;
	set<ll> ans; 
	rep(i, 0, 14) {
		rep(head, 1, 1000) {
			if(gao(head, tail))
				ans.insert(head * (tail + 1) + tail);
		}
		tail = tail * 10 + 9;
	}
	auto it = ans.begin();
	rep(i, 0, n) {
		printf("%lld\n", *it);
		it++;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
ll fac(ll x){if(x==0) return 1;  return x*fac(x-1);}
//cout << fixed << setprecision(10);

int main(){
  ll a,b; cin>>a>>b;
cout<<LCM(a,b)<<endl;
  
}

Measured memory_bytes: 256
import bisect

s = input()
t = input()

ss = s+s

char = [[] for _ in range(26)]

for i in range(len(ss)):
    char[ord(ss[i])-97].append(i+1)

ans = 0
tmp = 0

for i in range(len(t)):
    if not char[ord(t[i])-97]:
        print(-1)
        break
    
    k = bisect.bisect_right(char[ord(t[i])-97],tmp)
    ans += char[ord(t[i])-97][k]-tmp
    tmp = char[ord(t[i])-97][k]
    if tmp-len(s)>0:
        tmp -= len(s)
    
else:
    print(ans)

Measured memory_bytes: 14068
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int main(){
	int N;
	cin >> N;
	double x[10], y[10];
	for(int i = 0; i < N; i++){
		cin >> x[i] >> y[i];
	}
	double ans = 0;
	for(int i = 0; i < N; i++){
		for(int j = i + 1; j < N; j++){
			ans += sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
		}
	}
	ans *= (N - 1) * 2;
	ans /= N * (N - 1);
	printf("%.10f\n", ans);
	return 0;
}

Measured memory_bytes: 256
n = int(input())

x_org = list(map(int, input().split()))

x = sorted(x_org)

mid = x[n // 2 - 1]
midr = x[n // 2]

for i in range(n) :
    if x_org[i] <= mid :
        print(midr)
    else :
        print(mid)

Measured memory_bytes: 25220
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
#define REP(i,n) for(int i=0;i<(int)n;++i)
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
string num2bit(ll num, ll len){
    string bit = "";
    REP(i, len){
    bit += char('0'+(num>>i & 1));
    }
    return bit;
}

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

    ll a, b, x;
    cin >> a >> b >> x;

    if(a==0){
        cout << (b/x+1) << endl;
    }else{
        cout << (b/x+1) - ((a-1)/x+1) << endl;
    }

    return 0;
}

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

int main(){

  string S,T;
  cin>>S>>T;
  int count=0;
  
  rep(i,3){

    if(S[i]==T[i])count++;
    
  }
  cout<<count;
  
}


Measured memory_bytes: 256
while 1:
	a, op, b = map(str, raw_input().split())
	a = int(a)
	b = int(b)
	if op == "+":
		print a+b
	if op == "-":
		print a-b
	if op == "*":
		print a*b
	if op == "/":
		print a/b
	if op == "?":
		break

Measured memory_bytes: 4204
/* Author: Rennan Rocha
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>
#define vpll vector<pll>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//*find_by_order(); order_of_key();

double dp[301][301][301];
double n;

double solve(int a, int b, int c) {
    if((a == b && b == c && a == 0) || a < 0 || b < 0 || c < 0) return 0;
    if(dp[a][b][c] != 0) return dp[a][b][c];
    double k = a+b+c;
    assert(k > 0);
    return dp[a][b][c] = (n + a * solve(a-1, b, c) + b * solve(a+1, b-1, c) + c * solve(a, b+1, c-1)) / k;
}

int main() {
    ios_base::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    cin >> n;
    int a=0;
    int b=0;
    int c=0;
    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if(x==1) a++;
        else if(x==2) b++;
        else c++;
    }
    cout << solve(a,b,c) << "\n";
}


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

vector<vector<int>> g;
vector<bool> chk;
vector<ll> cnt;

void dfs(int p)
{
  if (chk[p])
    return;
  chk[p] = true;
  cnt[p%2]++;
  for (int i : g[p])
    dfs(i);
}

int main()
{
  int n;
  cin >> n;
  g.resize(200001);
  rep(i, n)
  {
    int x, y;
    cin >> x >> y;
    x = x * 2 - 2;
    y = y * 2 - 1;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  ll ans = 0;
  chk.resize(200001);
  fill(chk.begin(), chk.end(), false);
  cnt.resize(2);
  rep(i, 200001)
  {
    fill(cnt.begin(), cnt.end(), 0);
    dfs(i);
    ans += cnt[0] * cnt[1];
  }
  cout << ans - n << endl;
  return 0;
}

Measured memory_bytes: 11136
// Aizu Vol-1 0179: Mysterious Worm
// 2017.8.22 bal4u@uu

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

#define MAX 0xaaaaa
char chk[MAX+10];
int Q[MAX+10], *top, *end, *qmax = Q + MAX;
int N, K, mask;

int nxt[16] = { 0, 10, 5, 0, 10, 5, 0, 0, 5, 0, 10 };

int main()
{
	int s, r, g, b, step;
	int i, k;
	char buf[15], *bp;

	while (1) {
		scanf("%s", buf); if (buf[0] == '0') break;
		memset(chk, 0, sizeof(chk));
		for (N = s = 0, bp = buf; *bp; bp++, N += 2) {
			if      (*bp == 'r') k = 0;
			else if (*bp == 'g') k = 1;
			else                 k = 2;
			s = (s << 2) | k;
		}
		mask = (1 << N) - 1, r = 0, g = 0x55555 & mask, b = 0xaaaaa & mask;
		top = end = Q;
		*end++ = s, *end++ = -1, chk[s] = 1, step = 0, K = N-4;
		while (top < end) {
			s = *top; if (++top >= qmax) top = Q;
			if (s < 0) { step++, *end = -1; if (++end >= qmax) end = Q; continue; }
			if (s == r || s == g || s == b) { printf("%d\n", step); break; }
			for (i = 0; i <= K; i += 2) {
				int s2, k2;
				k = (s >> i) & 0xf;
				k2 = nxt[k];
				if (k2 == k) continue;
				s2 = (s & ~(0xf << i)) | (k2 << i);
				if (!chk[s2]) { chk[s2] = 1, *end = s2; if (++end >= qmax) end = Q; }
			}
		}
		if (top >= end) puts("NA");
	}
	return 0;
}

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


int main(){
  double long d,t,s;
  cin >> d >> t >> s;
  
  if (d/s <= t){
     cout << "Yes";
  }
  else{
    cout << "No";
  }
  
  return 0;
}

Measured memory_bytes: 3720
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P2;
const int inf=1000000000;
int main() {
	string s;
	cin>>s;
	int ls=s.length();
	int t=0;
	for(int i=1;i<ls-2;i+=2){
		if(s.substr(0,(i+1)/2)==s.substr(i/2+1,(i+1)/2))t=i+1;
	}
	cout<<t<<endl;
	return 0;
}


Measured memory_bytes: 256
program main
    implicit none
    integer n,q,a,b,c,p,x,i
    integer,allocatable::d(:),v(:,:),ans(:)
    type parr
        integer,allocatable::array(:)
    end type
    type(parr),allocatable::g(:)
    logical,allocatable::f(:)
    read *,n,q
    allocate(d(n))
    allocate(v(n-1,2))
    d=0
    do i=1,n-1
        read *,a,b
        d(a)=d(a)+1
        d(b)=d(b)+1
        v(i,1)=a
        v(i,2)=b
    end do
    allocate(g(n))
    do i=1,n
        allocate(g(i)%array(d(i)))
    end do
    d=0
    do i=1,n-1
        a=v(i,1)
        b=v(i,2)
        d(a)=d(a)+1
        d(b)=d(b)+1
        g(a)%array(d(a))=b
        g(b)%array(d(b))=a
    end do
    deallocate(v)
    allocate(ans(n))
    ans=0
    do i=1,q
        read *,p,x
        ans(p)=ans(p)+x
    end do
    allocate(f(n))
    f=.true.
    call dfs(g,d,f,1,ans)
    print '(i0)',ans
contains
    recursive subroutine dfs(g,d,f,v,s)
        type(parr),intent(in)::g(:)
        integer,intent(in)::d(:),v
        integer,intent(inout)::s(:)
        logical,intent(inout)::f(:)
        integer i,u
        f(v)=.false.
        do i=1,d(v)
            u=g(v)%array(i)
            if(f(u))then
                s(u)=s(u)+s(v)
                call dfs(g,d,f,u,s)
            end if
        end do
    end subroutine dfs
end program main

Measured memory_bytes: 95332
#include<list>
#include<map>
#include<vector>
#include<iostream>
using namespace std;
#define df 0
#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
typedef long int li;

int main(){
  if(df) printf("*debug mode*\n");
  int n,m; cin >>n >>m;
  string str; cin >> str;
  vector<int> dp(n+1,-1);
  dp.at(0)=0;
  int j=0;
  rep(i,n+1){
    while(i-j>m)j++;
    if(str.at(i)=='1')continue;
    while(dp.at(j)==-1 and j<i) j++;
    if(j==i)continue;
    dp.at(i)=dp.at(j)+1;
  }
  if(dp.at(n)==-1){
    cout << -1;
    return 0;
  }

  vector<int> dice;
  int i=n;
  while(i>=0){
    if(i<=m){
      dice.push_back(i);
      break;
    }
    int j=i-m;
    while(dp.at(j)==-1)j++;
    dice.push_back(i-j);
    i=j;
  }
  for(int i=dice.size()-1;i>=0;i--){
    printf("%d ",dice.at(i));
  }
}

/// confirm df==0 ///


Measured memory_bytes: 1528
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B;
  cin >> A >> B;
  if((A==1 && B==2) || (A==2 && B==1))
    cout << 3 << endl;
  else if((A==1 && B==3) || (A==3 && B==1))
    cout << 2 << endl;
  else if((A==2 && B==3) || (A==3 && B==2))
    cout << 1 << endl;
}

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

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
        #define eprintf(...) 42
#endif

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define foreach(u,v) for(auto (u) : (v))
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;

const int inf = 1e9;
const ll linf = 1LL<<60;
const ll mod = 1e9 + 7;
const double eps = 1e-9;

/*
*/

int main()
{
  #define int long long 

  int n, m;
  cin >> n >> m;

  vl x(n), y(m);
  rep(i, n) cin >> x[i];
  rep(i, m) cin >> y[i];

  ll sx = 0;
  rep(i, n-1){
    sx += (i+1)*(n-1-i)%mod*(x[i+1]-x[i])%mod;
    sx %= mod;
  }

  ll sy = 0;
  rep(i, m-1){
    sy += (i+1)*(m-1-i)%mod*(y[i+1]-y[i])%mod;
    sy %= mod;
  }

  cout << sx*sy%mod << endl;

  return 0;
}


Measured memory_bytes: 1792
using System;

namespace ITP1_5_B
{
    class Program
    {
        static void Main(string[] args)
        {
            while(true)
            {
                string str = Console.ReadLine();
                string[] parseStr = str.Split((char[])null);
                int H, W;
                H = int.Parse(parseStr[0]);
                W = int.Parse(parseStr[1]);
                if (H == 0 && W == 0)
                    Environment.Exit(0);

                string[,] square = new string[H, W];

                for (int i = 0; i < H; i++)
                {              
                    for (int j = 0; j < W; j++)
                    {
                        if ((i%2==0&&j%2==0)||(i%2!=0&&j%2!=0))
                            Console.Write("#");
                        else
                            Console.Write(".");
                    }
                    Console.Write("\n");
                }
                Console.Write("\n");
            }
        }
    }
}


Measured memory_bytes: 17892
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>

struct node{
	int left;
	int right;
	int id_parent;
};

struct tree{
	int n_nodes;
	node *nodes;
};

void preorder(tree t, int id){
	printf(" %d", id);
	if(t.nodes[id].left != -1) preorder(t, t.nodes[id].left);
	if(t.nodes[id].right != -1) preorder(t, t.nodes[id].right);
}

void inorder(tree t, int id){
	if(t.nodes[id].left != -1) inorder(t, t.nodes[id].left);
	printf(" %d", id);
	if(t.nodes[id].right != -1) inorder(t, t.nodes[id].right);
}

void postorder(tree t, int id){
	if(t.nodes[id].left != -1) postorder(t, t.nodes[id].left);
	if(t.nodes[id].right != -1) postorder(t, t.nodes[id].right);
	printf(" %d", id);
}

int main(void){
	tree t;
	int i,id, n, left, right;
	scanf("%d", &t.n_nodes);
	t.nodes = new node[t.n_nodes];
	
	for(i=0;i<t.n_nodes;i++){
		t.nodes[i].id_parent = -1;
	}
	for(i=0;i<t.n_nodes;i++){
		scanf("%d %d %d",&id, &left, &right);
		t.nodes[id].left = left;
		t.nodes[id].right = right;

		if(left != -1){
			t.nodes[left].id_parent = id;
		}
		if(right != -1){
			t.nodes[right].id_parent = id;
		}
	}

	for (i=0;i<t.n_nodes;i++){
		if(t.nodes[i].id_parent == -1){
			id = i;
			break;
		}
	}
	printf("Preorder\n");
	preorder(t,id);
	printf("\nInorder\n");
	inorder(t, id);
	printf("\nPostorder\n");
	postorder(t, id);
	printf("\n");
	delete []t.nodes;

	return 0;
}

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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(ll i=0;i<(n);i++)


using namespace std;



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

    ll minn = 2;
    ll maxx = 2;

    for(ll i = k-1; 0 <= i; i--){
        ll x = minn;
        ll y = maxx;
        if(x%a[i] != 0) x = (x/a[i])*a[i] + a[i];
        if(y%a[i] != 0) y = (y/a[i])*a[i];

        if(maxx < x || y < minn){
            maxx = -1;
            break;
        }
        minn = x;
        maxx = y + (a[i]-1);
    }
    
    if(maxx < minn) cout << "-1" << endl;
    else            cout << minn << " " << maxx << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main () {
	int a;
	int count1 = 0, count2 = 0;
	
	for (int i = 0; i < 3; i++) {
		scanf("%d", &a);
		
		if (a == 5) {
			count1++;
		}
		if (a == 7) {
			count2++;
		}
	}
	
	if ( count1 == 2 && count2 == 1) {
		puts("YES");
	}
	else {
		puts("NO");
	}
}

Measured memory_bytes: 1660
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

class Program{
    static void Main(string[] args){
        string[] s = Console.ReadLine().Split(' ');
        int problemNum = int.Parse(s[0]);
        int submissionNum = int.Parse(s[1]);
        
        List<List<string>> submissionList = new List<List<string>>(); 
        int[] acList = new int[problemNum]; //正解したらその問題番号の値が1になる　初期値0
        int[] waList = new int[problemNum]; //間違えたらその問題番号の値に今まで間違えた回数が入る　初期値0
        int cAC = 0; //正答数
        int cWA = 0; //誤答数
        for(int i=0;i<submissionNum;i++){
            string[] input = Console.ReadLine().Split(' ');
            int p = int.Parse(input[0]) - 1;
            string r = input[1];
            if(r == "AC"){
                if(acList[p] == 0){
                    //初めての正解だったら
                    //acListを正解に
                    //正答数をカウントアップ
                    //現状の誤答数をカウント
                    acList[p] = 1;
                    cAC++;
                    cWA += waList[p];
                }
            }else{
                if(acList[p] == 0){
                    //まだ正解してなくて間違ったならその問題の誤答数カウントアップ
                    waList[p]++;
                }
            }
        }
        Console.WriteLine(cAC + " " + cWA);
        
    }
}

Measured memory_bytes: 17240
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp;

fn main() {
    input!{
        h: usize,
        w: usize,
        ss: [chars; h],
    }
    let mut numbers = vec![vec![0; w]; h];

    for i in 0..h {
        for j in 0..w {
            if ss[i][j] == '#' {
                for dx in -1i32..2 {
                    for dy in -1i32..2 {
                        if dx == 0 && dy == 0 { continue };
                        let ni = i as i32 + dx;
                        let nj = j as i32 + dy;
                        if ni >= 0 && ni < h as i32 && nj >= 0 && nj < w as i32 {
                            numbers[ni as usize][nj as usize] += 1;
                        }
                    }
                }
            }
        }
    }

    for i in 0..h {
        for j in 0..w {
            if ss[i][j] == '#' {
                print!("{}", '#');
            } else {
                print!("{}", numbers[i][j]);
            }
        }
        println!("{}", "");
    }
}


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

int main(){
	int N,A;
	cin >> N >> A;
	vector<int> x(N);
	for(int i=0;i<N;i++)	cin >> x.at(i);
	
	int X=A;
	vector<int> y(N);
	for(int i=0;i<N;i++)	X=max(X,x.at(i));
	for(int i=0;i<N;i++)	y.at(i)=x.at(i)-A;
	
	vector<vector<long long>> dp(N+1,vector<long long>(2*N*X+1,0));
	dp.at(0).at(N*X)=1;
	for(int i=1;i<N+1;i++){
		for(int j=0;j<2*N*X+1;j++){
			dp.at(i).at(j)+=dp.at(i-1).at(j);
			if(j-y.at(i-1)>=0 && j-y.at(i-1)<=2*N*X){
				dp.at(i).at(j)+=dp.at(i-1).at(j-y.at(i-1));
			}
		}
	}
	cout << dp.at(N).at(N*X)-1 << endl;
	
	return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin() , v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)


int main(){
    string s; cin >> s;
    rep(i, s.length() - 1){
        if(s[i] == 'A' && s[i+1] == 'C'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main()
{
    int N, W;
    cin >> N >> W;
    vector<pair<int, int>> vec(N);
    for (int i=0; i<N; i++) {
        int n, w;
        cin >> n >> w;
        vec[i] = make_pair(n, w);
    }

    vector<vector<int>>dp(N+1, vector<int>(W+1, 0));
    for (int i=1; i<=N; i++) {
        pair<int, int> p = vec[i-1];
        for (int sum_w=0; sum_w <=W; sum_w++) {
            if (sum_w - p.second >= 0) {
                chmax(dp[i][sum_w], dp[i-1][sum_w-p.second] + p.first);
            }
                chmax(dp[i][sum_w], dp[i-1][sum_w]);
        }
    }

    cout << dp[N][W] << endl;
    return 0;
}


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

vector<int> edges[300000];

int main(){
    int n, m;
    cin >> n >> m;
    for(int i=0;i<m;i++){
        int u, v;
        cin >> u >> v;
        edges[3*(u-1)+0].push_back(3*(v-1)+1);
        edges[3*(u-1)+1].push_back(3*(v-1)+2);
        edges[3*(u-1)+2].push_back(3*(v-1)+0);
    }
    int s, t;
    cin >> s >> t;
    s = 3*(s-1)+0;
    t = 3*(t-1)+0;

    static int64_t d[300000];
    for(int i=0;i<3*n;++i) d[i] = INT64_MAX;

    static bool checked[300000] = {false};
    queue<pair<int64_t, int>> q;
    checked[s] = true;
    q.emplace(0, s);
    while(!q.empty()){
        int64_t cost;
        int to;
        tie(cost, to) = q.front();
        q.pop();
        if(to == t){
            cout << cost/3 << endl;
            return 0;
        }
        for(auto nx: edges[to]){
            if(checked[nx]) continue;
            checked[nx] = true;
            q.emplace(cost+1, nx);
        }
    }
    cout << -1 << endl;
    
    return 0;
}

Measured memory_bytes: 16896
#include <iostream>
#include <string>
#include <vector>
#include <sstream>

using namespace std;

int main() {

	string n;
	cin >> n;

	int sz = n.size();
	sz--;
	long long int ans = 0;

	for (long long int i = 0; i < (1 << sz); i++) {
		string s = n;
		for (int j = 0; j < sz; j++) {
			if ((i&(1 << j)) != 0) {
				string s2 = s.substr(0, j + 1);
				stringstream ss;
				long long int p;
				ss << s2;
				ss >> p;
				//cout << p << endl;
				ans += p;
				for (int k = 0; k < j + 1; k++) {
					s[k] = '0';
				}
			}
		}
		stringstream ss2;
		long long int p2;
		ss2 << s;
		ss2 >> p2;
		ans += p2;
		//cout << endl;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>
#include <numeric>
#include <climits>
#define ll long long
#define INF 1000000000
using namespace std;

int main(){
    string s,t;
    cin >> s >> t;
    int r=0;
    string ans;
    reverse(t.begin(),t.end());
    reverse(s.begin(),s.end());
    ans = s;
    for(int i=0;i<s.size()-t.size()+1;i++){
        bool flag = true;
        for(int j=0;j<t.size();j++){
            if(s[j+i] != t[j] && s[j+i] != '?'){
                flag = false;
            }
        }
        if(flag){
            for(int j=0;j<t.size();j++){
                ans[j+i] = t[j]; 
            }
            r++;
            break;
        }
    }
    if(r==0){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    reverse(ans.begin(),ans.end());
    for(int i=0;i<ans.size();i++){
        if(ans[i] == '?') ans[i] = 'a';
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

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

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint X, Y;
    cin >> X >> Y;
    cout << (abs(X - Y) <= 1 ? "Brown" : "Alice") << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

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

    int diff=b-a;
    int sum=0;
    rep(i,diff){
        sum += i+1;
    }
    cout<<sum-b;
}

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

using namespace std;

typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vmi;

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

    vmi a(n, vi(3));
    for (int i = 0; i < n; ++i)
        cin >> a[i][0] >> a[i][1] >> a[i][2];

    vmi dp(n, vi(3));
    dp[0] = a[0];

    for (int i = 1; i < n; ++i)
    {
        dp[i][0] = a[i][0] + max(dp[i - 1][1], dp[i - 1][2]);
        dp[i][1] = a[i][1] + max(dp[i - 1][2], dp[i - 1][0]);
        dp[i][2] = a[i][2] + max(dp[i - 1][0], dp[i - 1][1]);
    }

    cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));
    return 0;
}

Measured memory_bytes: 11136
n = int(input())

kyu = (n-400)//200
if kyu < 1:
    ans = 8
elif kyu < 2:
    ans = 7
elif kyu < 3:
    ans = 6
elif kyu < 4:
    ans = 5
elif kyu < 5:
    ans = 4
elif kyu < 6:
    ans = 3
elif kyu < 7:
    ans = 2
else:
    ans =  1

print(ans)

Measured memory_bytes: 9124
#include<bits/stdc++.h>
using namespace std;
int main() {
	int a,b,i,j,m=3000,x,y;
	cin>>a>>b;
	if(b-a+1>=2019)puts("0");
	else {
		for(i=a; i<b; i++)for(j=i+1; j<=b; j++)x=i%2019,y=j%2019,m=min(m,(x*y)%2019);
		cout<<m;
	}
}

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

int main() {
  int A, B;
  cin >> A >> B;
  cout << A * B << endl;
  return 0;
}


Measured memory_bytes: 3564
# coding: utf-8

a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
b = int(input()) - 1

print(a[b])


Measured memory_bytes: 2940
s = gets.strip
t = gets.strip

arr = Array.new(26) { Array.new }

# 文字ごとに出現位置を配列として持たせる
s.chars.each_with_index do |c, i|
  arr[c.ord - 'a'.ord] << i + 1
end

cur = 0
count = 0

t.chars.each do |c|
  p = c.ord - 'a'.ord

  if arr[p].empty?
    puts -1
    exit
  end

  # 現在位置より後ろに存在する文字cの位置情報
  cur = arr[p].bsearch { |item| item > cur }

  # 後ろになければ文字列全体を連結して位置を更新
  unless cur
    cur = arr[p].first
    count += 1
  end
end

puts s.length * count + cur

Measured memory_bytes: 16508
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

long long a, b;
long long cnt[45];
long long dp[45][2][2];

long long int getBit(long long x, int pos) {
  return (x & (1ll << pos)) > 0 ? 1 : 0;
}

void calc(long long x) {
  for (int i = 40; i >= 0; i--) {
    if (getBit(x, i) != 1) {
      continue;
    }
    for (int j = i - 1; j >= 0; j--) {
      cnt[j] ^= (1ll << (i - 1));
    }
    for (int j = i + 1; j <= 40; j++) {
      if (getBit(x, j) == 1) {
        cnt[j] ^= (1ll << i);
      }
    }
  }
  for (int i = 0; i <= 40; i++) {
    if (getBit(x, i) == 1) {
      cnt[i] ^= 1;
    }
  }
}

int main() { 

  cin >> a >> b;

  calc(b);

  if (a > 0) {
    calc(a - 1);
  }

  long long ans = 0;
  for (int i = 40; i >= 0; i--) {
    if (cnt[i] & 1) {
      ans += 1ll << i;
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
    int n;cin >> n;
    while(true) {
        int f = n % 10;
        int t = n % 100 / 10;
        int h = n/100;

        if (f == t && t == h) {
            cout << n << endl;
            break;
        }

        n++;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define int long long
using namespace std;
const int N = 1e3 + 5;
int read() {
	int x = 0, f = 1; char ch;
	while(! isdigit(ch = getchar())) (ch == '-') && (f = -f);
	for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 3) + (x << 1) + (ch ^ 48));
	return x * f;
}
template <class T> T Max(T a, T b) { return a > b ? a : b; }
template <class T> T Min(T a, T b) { return a < b ? a : b; }
int n, tot, vis[1000005], pri[1000005], a[N][N];
void init(int n) {
	for(int i = 2; i <= n; ++ i) {
		if(vis[i] == 0) pri[++ tot] = i;
		for(int j = 1; j <= tot && i * pri[j] <= n; ++ j) {
			vis[i * pri[j]] = 1;
			if(i % pri[j] == 0) break;
		}
	}
}
int gcd(int x, int y) {return y == 0 ? x : gcd(y, x % y);}
int lcm(int x, int y) {
	if(x == 0 || y == 0) return x + y;
	return x / gcd(x, y) * y;
}
signed main() {
	n = read(); init(1e4);
	if(n == 2) return puts("4 7\n23 10"), 0;
	for(int i = 1; i <= n; ++ i) {
		for(int j = ((i + 1) & 1) + 1; j <= n; j += 2) {
			a[i][j] = pri[(i + j) / 2] * pri[n + (i - j) / 2 + (n + 1) / 2];
		}
	}
	for(int i = 1; i <= n; ++ i) {
		for(int j = (i & 1) + 1; j <= n; j += 2) {
			a[i][j] = lcm(lcm(a[i - 1][j], a[i + 1][j]), lcm(a[i][j - 1], a[i][j + 1])) + 1;
		}
	}
	for(int i = 1; i <= n; ++ i, puts("")) for(int j = 1; j <= n; ++ j) printf("%lld ", a[i][j]);
	return 0;
}


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

long long hikizann(long long a, long long  b){
  if(a>b) return a-b ;
  return b-a ;
}

main(){
  long long n, k ;
  cin >> n >> k ;
  long long next = hikizann(n, k) ;
  while(n > next){
    if(n > k){
      n = n - k*(n/k) ;
      next = hikizann(n, k) ;
    }
    else{
      n = next ;
      next = hikizann(n, k) ;
    }
  }
  cout << n ;
  return 0 ;
}

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

using namespace std;

int main(){
  int n,m,p;
  while(cin>>n,n){
    stack<int> s;
    cin>>p;
    int q=1;
    for(int i=2;i<=n;++i){
      cin>>m;
      if(p==m) ++q;
      else if(p!=m&&i%2){
	s.push(q);q=1;p=m;
      }
      else{
	if(s.empty()){
	  ++q;p=m;continue;
	}
	++q;q+=s.top();s.pop();p=m;
      }
    }
    int a=0;
    if(!m){
      a+=q;s.pop();
    }
    while(!s.empty()){
      a+=s.top();s.pop();
      if(!s.empty()) s.pop();
    }
    cout<<a<<endl;
  }
  return 0;
}

Measured memory_bytes: 1196
#include<stdio.h>
long long R=1,C=1,H[2000010],N[2000010];
//評価関数（いまはMAX）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]<N[H[b]]?1:0;
}
//挿入関数
void hin(long long a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
int PC[200010],P[5][200010]={0};
int D[5][200010]={0};
int Set(int a,int b){
	int i,j;
	for(i=0;i<a;i++){
		for(j=0;j<=b;j++)P[i][j]=j;
		PC[i]=b;
	}
}
int Find(int a,int b,int i){
	int r,n;
	for(r=a ;P[i][r] -r;r=  P[i][r]);
	for( ;(n=P[i][a])-a;a=n)P[i][a]=r;
	for(r=b ;P[i][r] -r;r=  P[i][r]);
	for( ;(n=P[i][b])-b;b=n)P[i][b]=r;
	return a-b?1:0;
}
void Union(int a,int b,int i){
	if(Find(a,b,i)){
		for(;P[i][a]-a;a=P[i][a]);
		for(;P[i][b]-b;b=P[i][b]);
		D[i][a]<D[i][b]?(P[i][a]=b):(P[i][b]=a);
		if(D[i][a]==D[i][b])D[i][a]++;
		PC[i]--;
	}
}
int lb(int l,int r,long long n,long long *d){
  int m=(l+r)/2;
  if(l==r)return m;
  return n<=d[m]?lb(l,m,n,d):lb(m+1,r,n,d);
}
int ub(int l,int r,long long n,long long *d){
  int m=(l+r)/2;
  if(l==r)return m;
  return n<d[m]?ub(l,m,n,d):ub(m+1,r,n,d);
}
long long c[200010],d[200010];
int main(){
	int n,s,t,i,a,b;
	scanf("%d %d %d",&n,&s,&t);
	Set(2,n);
	for(i=0;i<s;i++){
		scanf("%d %d",&a,&b);
		Union(a-1,b-1,0);
	}
	for(i=0;i<t;i++){
		scanf("%d %d",&a,&b);
		Union(a-1,b-1,1);
	}
	for(i=0;i<n;i++){
		for(a=i;P[0][a]-a;a=P[0][a]);
		for(b=i;P[1][b]-b;b=P[1][b]);//printf("%d %d %d\n",i,a,b);
		hin(d[i]=a*1000000LL+b);
	}
	for(i=0;i<n;i++)c[i]=N[hout()];
	//for(i=0;i<n;i++)printf("%lld\n",c[i]);
	for(i=0;i<n;i++){
		//printf(":%d %d\n",ub(0,n,d[i],c),lb(0,n,d[i],c));
		printf("%d",ub(0,n,d[i],c)-lb(0,n,d[i],c));
		printf("%c",i-n-1?' ':'\n');
	}
	return 0;
}

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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int n;
string s;
vector<string> v;
void go(int pos,int mx){
	if(pos==n){
		v.pb(s);
		return ;
	}
	rep(i,0,mx+2){
		s[pos]='a'+i;
		go(pos+1,max(mx,i));
	}
}
void solve(){
    cin>>n;
    rep(i,0,n) s+='a';
    go(1,0);
    for(auto i:v) cout<<i<<endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 7796
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int w = sc.nextInt();
	int n = sc.nextInt();
	int[] values = new int[w];
	for(int i=0;i<values.length;i++){
	    values[i]=i+1;
	}
	for(int i=0;i<n;i++){
	    String str=sc.next();
	    String[] ab =str.split(",");
	    int a =Integer.parseInt(ab[0])-1;
	    int b =Integer.parseInt(ab[1])-1;
	    int work;
            work=values[a];
	    values[a]=values[b];
	    values[b]=work;
	}
	for(int i=0;i<values.length;i++){
            System.out.println(values[i]);
	}
    }
}

Measured memory_bytes: 26352
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  string s; cin >> s;
  ll ans = 0;
  rep(i, 1, s.size()+1) {
    REP(j, s.size()-i+1) {
      ans += stoll(s.substr(j, i)) * (ll)powl((long double)2.0, (long double)(max(0LL, j-1) + max(0LL, (ll)s.size()-i-j-1)));
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#!/usr/bin/env pypy3
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
import queue

def main():
    mod=10**9+7
    N=I()
    adj=[[] for _ in range(N)]
    for i in range(N-1):
        a,b=MI()
        a-=1
        b-=1
        adj[a].append(b)
        adj[b].append(a)
    dL=[[0,0] for _ in range(N)]
    
    q=queue.Queue()
    
    #0,N-1からの距離
    for j in range(2):
        if j==0:
            q.put((0,0,0))#v,pare,d
        else:
            q.put((N-1,N-1,0))#v,pare,d
        while not q.empty():
            v,p,d=q.get()
            dL[v][j]=d
            for i in range(len(adj[v])):
                nv=adj[v][i]
                if nv!=p:
                    q.put((nv,v,d+1))
                    
    s=0
    for i in range(N):
        if dL[i][0]>dL[i][1]:
            s+=1
    
        
    
    if s>=N-s:
        print("Snuke")
    else:
        print("Fennec")
     
        
    
    

main()


Measured memory_bytes: 85148
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <map>

using namespace std;

int main(){
  int i,j,k;
  int n;
  cin >> n;
  int a,b;
  cin >> a >> b;
  int p[n],cnt[3]={};
  for(i=0;i<n;i++){
    cin >> p[i];
    if(p[i]<=a)cnt[0]++;
    else if(a<p[i] && p[i]<=b)cnt[1]++;
    else cnt[2]++;
  }
  cout << min(min(cnt[0],cnt[1]),cnt[2]) << endl;;
  return 0;
}


Measured memory_bytes: 256