akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <map>

using namespace std;

template< typename T >
T mod_pow(T x, T n, const T &p) {
    T ret = 1;
    while(n > 0) {
        if(n & 1) (ret *= x) %= p;
        (x *= x) %= p;
        n >>= 1;
    }
    return ret;
}

int main(void) {
    int N, P;
    string S;
    cin >> N >> P >> S;
    
    int64_t ans = 0;
    if(P ==2) {
        for(int i=0; i<N; i++) {
            if((S[i]-'0') % 2 == 0) {
                ans += i+1;
            }
        }
    } else if(P == 5) {
        for(int i=0; i<N; i++) {
            if((S[i]-'0') % 5 == 0) {
                ans += i+1;
            }
        }
    } else {
        reverse(S.begin(), S.end());
        map<int,int64_t> mp;
        int t = 0;
        for(int i=0; i<N; i++) {
            t += (S[i]-'0') * mod_pow(10, i, P);
            t %= P;
            mp[t]++;
        }
        for(auto e: mp) {
            ans += e.second * (e.second-1) / 2;
        }
        ans += mp[0];
    }

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


Measured memory_bytes: 1028
#include <stdio.h>

int main()
{
	int N;
	char S[5001];
	scanf("%d", &N);
	scanf("%s", S);
	
	char flag[5001][5001] = {};
	int i, j, k, len = 0;
	for (i = 0; i < N - 1; i++) {
		for (j = i + 1; j < N; j++) {
			if (S[i] == S[j] && flag[i][j] == 0) {
				flag[i][j] = 1;
				for (k = 1; S[i+k] == S[j+k] && i + k < j; k++) flag[i+k][j+k] = 1;
				if (k > len) len = k;
			}
		}
	}

	printf("%d\n", len);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 26164
#include<iostream>
#include<string>
using namespace std;
int main(){
	string s,ss;
	cin>>s>>ss;
	int flag=0;
	for(int i=0;i<s.size();i++){
		if(s[i]!=ss[i]){
			flag=1;
			break;
		}
	}
	if(flag||s.size()+1!=ss.size()){
		cout<<"No"<<endl;
	}
	else{
		cout<<"Yes"<<endl;
	}
} 

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
template<class T>using vv = vector<vector<T>>;

#define in(v) v; cin >> v;
// #define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define repi(i,a,b) for(int i=(a),_i=(b);i<_i;++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
const int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};
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(b<a){a=b;return 1;}return 0;}

// debug
template<class T>ostream& operator<<(ostream& os,const vector<T>& vec){os<<"{";for(size_t i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
ostream& operator<<(ostream& os,const vector<char>&v){for(size_t i=0;i<v.size();++i)os<<v[i];return os;}
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>& rhs){os<<"("<<rhs.first<<", "<<rhs.second<<")";return os;}


#ifdef LOCAL
void debug() {cerr << "\n";}
template<class First> void debug(const First& first) {cerr<<first<<"\n";}
template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
#else
#define debug(...) 42
#endif

int main() {
  int in(N);

  int v[N];
  rep(i, N) 
    v[i] = 0;
  rep(i, N - 1) {
    int in(a);
    --a;
    ++v[a];
  }
  rep(i, N) cout << v[i] << endl;
  

  return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define vi vector<ll>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define el printf("\n")
#define pb push_back
#define f first
#define s second
#define arrondi(a) (long long)floor(a+0.5);
#define NIL -1
ll N=500005;
ll MAX=9223372036854775807;
ll MOD=1000000007;
long double PI =4*atan(1);

int main()
{
	IOS;
    cout.precision(30);
    int n; cin >> n; vector<ll> A(n,0),B; unordered_map<ll,ll> mp;
    for (int i=0;i<n;i++)
    {
        cin >> A[i]; mp[A[i]]++;
    }
    B=A;
    sort(A.begin(),A.end());
    ll mmi=A[n-2];
    ll mi=A[n-1];
    if (mp[mi]>1)
    {
        for (int i=0;i<n;i++)
            cout << mi << "\n";
    }
    else
    {
        for (int i=0;i<n;i++)
        {
            if (B[i]==mi)
                cout << mmi << "\n";
            else cout << mi << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 9380
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cassert>
#include <functional>
#include <string>
#include <sstream>
#include <cctype>
using namespace std;


int main(){
  char A, B; cin >> A >> B;
  char ans = 'D';
  if((A == 'H' && B == 'H') || (A == 'D' && B == 'D')) ans = 'H';
  cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using static MyIO;


public class A
{
	public static void Main()
	{
		int a = GetInt();
		int b = GetInt();
		int c = GetInt();

		Console.WriteLine(((b-a)  == (c - b)) ? "YES" : "NO");
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}

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

int n;
int a[200000];

int main() {
	int i;
	
	cin >> n;
	for (i = 0; i < n; i++) cin >> a[i];
	
	int all = 0;
	for (i = 0; i < n; i++) all ^= a[i];
	
	for (i = 0; i < n; i++) {
		int b = (all ^ a[i]);
		cout << b;
		if (i + 1 < n) cout << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <unordered_map>
using namespace std;

#define ll long long
#define DB 0

int main () {
	int T;
	cin >> T;
	while (T--) {
		long long N, A, B, C, D;
		cin >> N;
		cin >> A >> B >> C >> D;

		unordered_map<ll, ll> dp;

		priority_queue<pair<ll, ll>> pq;

		pq.push({0, N});
		while (!pq.empty()) {
			ll dist = -pq.top().first;
			ll x = pq.top().second;
			pq.pop();
			if (DB) cout << "State = " << x << " " << dist << endl;
			if (x == 0) {
				break;
			}

			if (1.0 * x * D < 1e18 && (dp.count(0) == 0 || dist + x * D < dp[0])) {
				pq.push({-(dist + x*D), 0});
				dp[0] = dist + x * D;
			}

			if (x % 2 == 0) {
				if (dp.count(x/2) == 0 || dist + A < dp[x/2]) {
					pq.push({-(dist+A), x/2});
					dp[x/2] = dist + A;
				}
			}

			if (x % 3 == 0) {
				if (dp.count(x/3) == 0 || dist + B < dp[x/3]){
					pq.push({-(dist+B), x/3});
					dp[x/3] = dist + B;
				}
			}
			if (x % 5 == 0) {
				if (dp.count(x/5) == 0 || dist + C < dp[x/5]){
					pq.push({-(dist+C), x/5});
					dp[x/5] = dist + C;
				}
			}
			if (x % 30 != 0) {
				if (dp.count(x-1) == 0 || dist + D < dp[x-1]){
					pq.push({-(dist+D), x-1});
					dp[x-1] = dist + D;
				}
				if (dp.count(x+1) == 0 || dist + D < dp[x+1]){
					pq.push({-(dist+D), x+1});
					dp[x+1] = dist + D;
				}
			}
		}

		cout << dp[0] << endl;
	}
}

Measured memory_bytes: 7536
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
vector<int>v[100100];
int n,m,siz[100100],Ans;
inline void dfs(int x,int fa){
	siz[x]=1;
	for(int i=0;i<v[x].size();i++)
	  if(v[x][i]!=fa){
	  	dfs(v[x][i],x);
	  	siz[x]=max(siz[x],siz[v[x][i]]+1);
	  }
	if(fa!=1&&siz[x]==m)siz[x]=0,Ans++;
}
int main(){
    int i,j,k;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++){
      int x;
      scanf("%d",&x);
      if(i==1&&x!=1)Ans=1;
      if(i>1)v[x].push_back(i),v[i].push_back(x);
    }
    for(i=0;i<v[1].size();i++)dfs(v[1][i],1);
    printf("%d\n",Ans);
	return 0;
}

Measured memory_bytes: 10624
def appear_twice(L):
	return len(L) == len(set(L))

def f(a):
	if a%2 == 0:
		return int(a/2)
	else:
		return 3*a + 1

s = int(input())
a_seq = [s]

i = 1
while appear_twice(a_seq):
	a_seq.append(f(a_seq[-1]))
	i = i + 1

print(i)

Measured memory_bytes: 3060
//B - Snake Toy: 
//Assunto: 
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100050
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int n, k, ans = 0;
    cin >> n >> k;
    vector<int> sticks(n);
    loop(i, 0, n) cin >> sticks[i];
    sort(rall(sticks));
    loop(i, 0, k) ans += sticks[i];
    cout << ans << "\n";
}

Measured memory_bytes: 256
lis = [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]
K = int(input())
print(lis[K-1])

Measured memory_bytes: 3060
K = int(input())
Ans = 0
if K == 4 or K == 6 or K == 9 or K == 10 or K == 14 or K == 21 or K == 22 or K == 25 or K == 26:
  Ans = 2
elif K == 28 or K == 30:
  Ans = 4
elif K == 8 or K == 12 or K == 18 or K == 20 or K == 27:
  Ans = 5
elif K == 16:
  Ans = 14
elif K == 24:
  Ans = 15
elif K == 32:
  Ans = 51
else:
  Ans = 1
  
print(Ans)

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

long long int n,x,ans,i;
string s;

signed main()
{
    ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n;
	for (i=1;i<n+1;i++) if (i%3!=0 && i%5!=0) ans=ans+i;
	cout<<ans;
}


Measured memory_bytes: 3640
x, k, d = map(int, input().split())

n = x // d

if abs(n) > k:
    if x < 0:
        print(abs(x+k*d))
        exit()
    elif x > 0:
        print(x-k*d)
        exit()

if abs(x-d*n) > abs(x-d*(n+1)):
    a = abs(x-d*(n+1))
    b = n+1
else:
    a = abs(x-d*n)
    b = n

if (k-b) % 2 == 0:
    print(a)
else:
    print(min(abs(a-d),abs(a+d)))




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

using namespace std;
typedef long long ll;

int main() {
    int x1, x2, x3, x4, x5;
    cin >> x1 >> x2 >> x3 >> x4 >> x5;
    if (x1 == 0) cout << 1 << endl;
    else if (x2 == 0) cout << 2 << endl;
    else if (x3 == 0) cout << 3 << endl;
    else if (x4 == 0) cout << 4 << endl;
    else if (x5 == 0) cout << 5 << endl;
}


Measured memory_bytes: 3616
nn = 2002002
P = 10**9+7

fa = [1] * (nn+1)
fainv = [1] * (nn+1)
for i in range(nn):
    fa[i+1] = fa[i] * (i+1) % P
fainv[-1] = pow(fa[-1], P-2, P)
for i in range(nn)[::-1]:
    fainv[i] = fainv[i+1] * (i+1) % P

f = lambda a, b: fa[a+b+2] * fainv[a+1] * fainv[b+1] % P
r1, c1, r2, c2 = map(int, input().split())
print((f(r2, c2) - f(r2, c1-1) - f(r1-1, c2) + f(r1-1, c1-1)) % P)

Measured memory_bytes: 71660
N = int(input())
abc = [list(map(int,input().split())) for _ in range(N)]
#print(abc)
DP = [ [0] * (N + 1) for _ in range(3)]
#print(DP)
for i in range(N):
    DP[0][i+1] = max(DP[1][i], DP[2][i]) + abc[i][0]
    DP[1][i+1] = max(DP[0][i], DP[2][i]) + abc[i][1]
    DP[2][i+1] = max(DP[0][i], DP[1][i]) + abc[i][2]

print(max(DP[0][N],DP[1][N],DP[2][N]))

Measured memory_bytes: 66800
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<list>
using namespace std;

long long p[1] = {};

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

	int sum = A*X + B*Y;

	if (A + B > 2 * C)
	{
		int minimum = min(X,Y);
		sum = sum - A*minimum - B*minimum + 2 * C*minimum;
		X -= minimum;
		Y -= minimum;
	
		int maximum = max(X, Y);
		if (maximum != 0)
		{
			int left_pizza_value = (X != 0) ? A : B;
			if (left_pizza_value > 2 * C)
			{
				sum = sum - left_pizza_value*(X + Y) + 2 * C*(X + Y);
			}

		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 888
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main() {
    int n, h, w; cin >> n >> h >> w;
    int cnt = 0;
    rep(i, n){
        int a, b; cin >> a >> b;
        if(a >= h && b >= w) cnt++;
    }
    cout << cnt << endl;
    return;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define bb begin()
#define ee end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);
#define eps 1e-9



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;


int power(int a,int b){
    int r=1;
    while(b){
        if(b & 1){
            r=r*a;
            b--;
        }
        a=a*a;
        b>>=1;
    }
    return r;
}


int arr[g_size];



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

	int n,m,T,res;

	int maxi=-mx,mini=mx,count=0;

	int i,j,k;

	bool flag;

	string s1,s2;

	char s[100000];

	int ara[n_size],ara2[n_size];

	cin>>k;

	vi v;

	f(i,1,32){
        f(j,2,10){
            res=power(i,j);
            if(res>k) break;
            v.pb(res);
        }

	}

	auto x=max_element(v.bb,v.ee);

	cout<<*x<<endl;
}


Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <list>
#include <stack>
#include <unordered_set>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1LL << 50;
static const int NIL = -1;
static const int MOD = 1000000007;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue
 
int gcd(int a, int b) { int c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
int lcm(int a, int b) { int c = gcd(a, b); a /= c; return a*b; }
int nCr(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
int pow(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llpow(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llgcd(long long a, long long b) { long long c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
long long lllcm(long long a, long long b) { long long c = llgcd(a, b); a /= c; return a*b; }
long long llnCr(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
 
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
 
struct edge{
    int from, to; ll cost;
};

int main(){
    ll n, h;
    cin >> n >> h;
    ll maxa = 0;
    vector<ll> b;
    REP(i, n){
        ll at, bt;
        cin >> at >> bt;
        maxa = max(at, maxa);
        b.pb(bt);
    }
    sort(b.begin(), b.end(), greater<ll>());
    ll ans = 0;
    int k = 0;
    while(1){
        if(maxa >= b[k] || h <= 0){
            break;
        }else{
            h -= b[k];
            ans++;
            k++;
        }
    }
    if(h > 0){
        ans += h / maxa;
        if(h % maxa) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1400
#include<set>
#include <unordered_set>
#include <unordered_map>
#include<map>
#include<list>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include<math.h>
#include <string.h>
#include <strings.h>


#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lp(i,a,n) for(int i=(a);i<=(int)(n);++i)
#define lpd(i,a,n) for(int i=(a);i>=(int)(n);--i)
#define clr(a,b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define println(a) cout <<(a) <<endl
#define sz(x) ((int)(x).size())
#define readi(x) scanf("%d",&x)
#define read2i(x,y) scanf("%d%d",&x,&y)
#define read3i(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define readll(x) scanf("%I64d",&x)
#define mod 1000000007
#define eps 1e-10
#define infi  1000000000ll
#define infll 1000000000000000000ll


using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef set<int> si;
typedef unordered_set<int> usi;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef unordered_map<ll,ll> umll;


const int N = 200003;
int n,a[N],b[N];
int main(){
    scanf("%d",&n);
    lp(i, 1, n) scanf("%d",&a[i]);
    if(n&1) {
        b[n/2 + 1] = a[1];
        lp(i, 1, n/2) b[n/2+1+i] = a[2*i], b[n/2+1-i] = a[2*i+1];
        
    } else  {
        lp(i, 1, n/2) b[n/2-i+1] = a[2*i];
        lp(i, 1, n/2) b[n/2+i] = a[2*i-1];

     }
    
    lp(i, 1, n) printf("%d ",b[i]);
    printf("\n");
    return 0;
}



/*
 */

//ios::sync_with_stdio(0);cin.tie(0);

Measured memory_bytes: 3712
/*
 * N
 * H1 H2 ... Hn
*/


#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <cassert>

using namespace std;

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

  vector< long long > v(N);

  for (int i = 0; i < N; i++) {
    long long l;
    cin >> l;
    v.at(i) = l;
  }

  // 下げない時の高さ, 下げた時の高さ
  // -1は存在しないをあらわす
  pair<long long, long long> p = make_pair(v.at(0), v.at(0) - 1);

  for (int i = 1; i < N; i++) {
    long long p1 = v.at(i);
    long long p2 = v.at(i) - 1;

    long long min = (p.second == -1) ? p.first : p.second;

    if (min <= p1) {
      p.first = p1;
    }
    else {
      p.first = -1;
    }

    if (min <= p2) {
      p.second = p2;
    }
    else {
      p.second = -1;
    }

    if (p.first == -1 && p.second == -1) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
}


Measured memory_bytes: 1024
using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;


class Program {

	const long mod = 1000000007;
	//public static int[] max;

	static void Main(string[] args) {

		char[] cs = new char[] { ' ', ',' };
		//int val = int.Parse(Console.ReadLine());
		//int[] vals = parseAry(Console.ReadLine().Split(cs));
		//string str = Console.ReadLine();
		//string[] strs = Console.ReadLine().Split(cs);

		//string res="";
		//int res = 0; ;
		int n = int.Parse(Console.ReadLine());
		//string str = Console.ReadLine();
		int[] vals = parseAry(Console.ReadLine().Split(cs));
		//int n = int.Parse(Console.ReadLine());

		//int num = vals[0];



		int res = 0;		
		for ( int i = 1; i < n-1; i++ ) {
			if ( vals[i - 1] == vals[i] && vals[i] == vals[i + 1] ) {
				vals[i] = -1;
				res++;
			}
			//Console.Write(str[i]);
		}
		for ( int i = 0; i < n - 1; i++ ) {
			if (vals[i] == vals[i + 1] ) {
				vals[i] = -1;
				res++;
			}
			//Console.Write(str[i]);
		}



		Console.WriteLine(res);

		return;
	}


	//　String[]  ----->  int[]
	static int[] parseAry(string[] str) {
		int[] nums = new int[str.Length];
		for (int i = 0; i < str.Length; i++) { nums[i] = int.Parse(str[i]); }
		return nums;
	}
	//　String[]  ----->  long[]
	static long[] parseAryL(string[] str) {
		long[] nums = new long[str.Length];
		for (int i = 0; i < str.Length; i++) { nums[i] = long.Parse(str[i]); }
		return nums;
	}
	
	//文字列を1文字ずつString[]に入れる
	static string[] strAry(String str) {
		string[] re = new string[str.Length];
		for (int i = 0; i < str.Length; i++) { re[i] = str[i].ToString(); }
		return re;
	}

}

Measured memory_bytes: 13140
fun solve() {
    val n = readLine()!!.toInt()
    val mm: MutableMap<String, String> = mutableMapOf<String, String>()
    for (i in 0 until n) {
        mm[readLine()!!] = ""
    }
    println(mm.size)
}

fun main(args: Array<String>) {
    solve()
}

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

using ll = long long int;
using P = std::pair<int, int>;

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

ll dp[3005][3005][4];

int main()
{
    int r, c, K;

    std::cin >> r >> c >> K;

    std::vector<std::vector<ll>> dat(r + 1, std::vector<ll>(c + 1, 0));

    rep(i, K)
    {
        int x, y, v;
        std::cin >> x >> y >> v;
        dat[x][y] = v;
    }

    rep(i, r)
    {
        rep(j, c)
        {
            for (int k = 0; k <= 3; ++k)
            {
                dp[i][j][k] = std::max(dp[i - 1][j][3], dp[i][j - 1][k]);
                if (dat[i][j] > 0 && k > 0)
                {
                    dp[i][j][k] = std::max({dp[i][j][k], dp[i - 1][j][3] + dat[i][j], dp[i][j - 1][k - 1] + dat[i][j]});
                }
                if (k > 0)
                    dp[i][j][k] = std::max(dp[i][j][k], dp[i][j][k - 1]);
            }
        }
    }

    std::cout << dp[r][c][3] << std::endl;

    return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for (int i = 0; i < n; i++){
    cin >> h.at(i);
  }
  
  int inf = 1000000007;
  vector<int> dp(n, inf);
  
  for (int i = 0; i < n; i++){
    if (i == 0){
      dp.at(i) = 0;
    }
    else if (i == 1){
      dp.at(i) = abs(h.at(1)-h.at(0));
    }
    else{
      int z = max(0, i-k);
      for (int j = z; j < i; j++){
        dp.at(i) = min(dp.at(i), dp.at(j)+abs(h.at(i)-h.at(j)));
      }
    }
  }
  cout << dp.at(n-1) << endl;
}



Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
using ll = long long;

string S;
char Sl[5];

int main(void){

    cin >> S;

    for (int i = 1; i <= 3; i++){
        Sl[i] = S[i-1]; //chは[0]から始まるので注意！
    }

    ll ans = 0;
    ll longest = 0;

    for(int i = 1;i <=3; i++){
        if (Sl[i] == 'R'){
            ans++;
        } else {
        if (longest < ans){
            longest = ans;
        }
            ans = 0;
        }
    }

    if (ans > 0){
        if (longest < ans){
            longest = ans;
        }
    }

    cout << longest << endl;
    
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int INF = 1e9+7;

class unionfind {
public:
	vector<int> par;
	vector<int> rnk;

	unionfind(int N) :par(N),rnk(N) {//コンストラクタ
		for (int i = 0; i < N; i++) {
			par[i] = i;
			rnk[i] = 0;
		}
	}

	int root(int x) {//データｘが属する木の根を再帰で得る:root(x)={ｘの木の根}
		if (par[x] == x)return x;
		return par[x] = root(par[x]);

	}

	void unite(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		if (rx == ry)return;//ｘとｙの根が同じ（＝同じ木にある）時はそのまま
		if (rnk[rx] < rnk[ry]) {
			par[rx] = ry;//xとyの根が同じでない（＝同じ木にない）時：ｘの根をｒｘをｙの根につける
		}
		else if (rnk[rx] > rnk[ry]) {
			par[ry] = rx;
		}
		else {
			par[rx] = ry;
			rnk[ry]++;
		}
	}

	bool same(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}

};

bool edge[51][51];
pair<int, int>P[51];

int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	
	int N, M;
	int ans = 0;
	cin >> N >> M;

	FOR(i, 0, M) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		P[i] = make_pair(a, b);
	}
	FOR(i, 0, M) {
		unionfind U(N);

		FOR(j, 0, M) {
			if(i!=j){
				U.unite(P[j].first, P[j].second);
			}
		}
		if (U.root(P[i].first) != U.root(P[i].second)) {
			ans++;
		}
	}




	cout << ans << endl;


	return 0;
}


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

int main() {
int a,b;
cin >> a>> b;
if(a%3 == 0||b %3 == 0||(a+b)%3 == 0){
	cout << "Possible" << endl;
}
else{
	cout << "Impossible" << endl;
}
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int N,Y;
    int x,y,z;
    int sum;

    scanf("%d %d",&N,&Y);
    Y=Y/1000;

    for (int i=0;i<=N;i++){
	for (int j=0;j<=N-i;j++){
	    x=i;
	    y=j;
	    z=N-(x+y);
	    sum=x*10+y*5+z;

	    if (sum == Y){
		printf("%d %d %d\n",x,y,z);
		return 0;
	    }
	}
    }

    printf("-1 -1 -1\n");

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define ll long long
  #define int long long
  #define double long double
  #define max(a,b) (a>b?a:b)
  #define min(a,b) (a<b?a:b)
  #define mp make_pair
  #define pb push_back
  #define inf INT_MAX
  #define f first
  #define s second
  #define all(v) v.begin(), v.end()
  #define mod 1000000007
  //direction arrays
  int dx[8]={0,0,-1,+1,+1,-1,+1,-1};
  int dy[8]={+1,-1,0,0,+1,-1,-1,+1};
  int modexp(int x, int y)
  {
      int res = 1;
      x = (x % mod + mod) % mod;
      while(y)
      {
          if(y & 1)
              res = (res*x) % mod;
          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); 
 } 
  
  int32_t main()
  { 
    /*#ifndef ONLINE_JUDGE
       freopen("in.txt","r",stdin);
       freopen("out.txt","w",stdout);
    #endif*/
    
    IOS
    int n;
    cin>>n;
    int rem=n%10;
    if(rem==2 or rem==4 or rem==5 or rem==7 or rem==9)
      cout<<"hon";
    else if(rem==3)
      cout<<"bon";
    else
      cout<<"pon";
  return 0;
}

Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int k = scan.nextInt();
		int x = scan.nextInt();
		int y = scan.nextInt();

		int a = k * x;
		int b = 0;

		if (n > k) {
			b = (n - k) * y;
			System.out.println(a+b);

		} else {
			b = n * x;
			System.out.println(b);
		}

		//System.out.println(a + b);

	}

}

Measured memory_bytes: 21844
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;//998244353;

template<class _T> static void get(_T& a) {
	std::cin >> a;
}
template<class _T> static void get(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void get(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}
template<class _T> static void getint(_T& a) {
	if (sizeof(_T) > sizeof(int)) {
		scanf("%lld", &a);
	}
	else {
		scanf("%d", &a);
	}
}
template <class _T> static _T tp_abs(_T a) {
	if (a < (_T)0) {
		a *= (_T)-1;
	}
	return a;
}

static void exec();

int main()
{
	exec();
	fflush(stdout);
	return 0;
}

static void exec()
{
	int N, X;
	get(N, X);

	std::vector<int> ai(N);
	get(ai[0]);
	LLONG ans = 0;
	for (int i = 1; i < N; i++) {
		get(ai[i]);
		if (ai[i - 1] + ai[i] > X) {
			ans += (LLONG)(ai[i] - (X - ai[i - 1]));
			ai[i] = std::max(0, X - ai[i - 1]);
		}
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 3732
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;

int main(){
	int c, d;
	int n, m;
	bool v = true;
	int x, y, z;
	int k, s, ans;
	k = 0;
	s = 0;
	ans = 0;
	scanf("%d %d", &n, &k);
	k = k / 1000;
	z = k % 5;
	k = k - z;
	y = k % 10;
	k = k - y;
	y = y / 5;
	x = k / 10;
	if (x + y + z > n){
		printf("-1 -1 -1\n");
		return 0;
	}
	else{
		s = n - x - y - z;
		c = s / 4;
		d = s % 4;
		if (d > x){
			printf("-1 -1 -1\n");
			return 0;
		}
		else s = (x - d) / 4;
		s = min(s, c);
		c -= s;
		x -=  (4 * s) + d;
		y += (8 * s) + (2 * d);
		if (c > y){
			printf("-1 -1 -1\n");
			return 0;
		}
		else{
			y -= c;
			z += (c * 5);
		}
	}

	printf("%d %d %d\n", x, y, z);

	return 0;
}

Measured memory_bytes: 128
import java.io.PrintWriter

val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val d = nextInt()
    println(when (d) {
        22 -> "Christmas Eve Eve Eve"
        23 -> "Christmas Eve Eve"
        24 -> "Christmas Eve"
        25 -> "Christmas"
        else -> ""
    })
}

fun next() = readLine()!!
fun nextInt() = next().toInt()

fun println(value : Any) {
    pw.println(value)
}

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

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

#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define mp1(a,b,c) P1(a,P(b,c))
#define get_arsize(a) (sizeof(a)/sizeof(a[0]))
#define PI 3.14159265359
const ll MOD = 1000000007;
const double EPS = 1e-10;
const int MAX = 200000;
// 20 mins delayed
int main() {
  double n;
  cin >> n;

  cout << setprecision(10) << n * (double)2 * PI << endl;
  return 0;
}


Measured memory_bytes: 3784
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

#define FOR(i,b,n) for(int i=b;i<n;i++)
#define RFOR(i,b,n) for(int i=n-1;i>=b;i--)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))

using namespace std;

static const double EPS = 1e-9;
typedef long long ll;
typedef pair<int, int> paii;

int a, b, n;
bool con[100][100] = {0};

int solve()
{
	int dp[100][100];
	CLR(dp);
	dp[1][1] = 1;
	
	FOR(j, 1, b+1)
		FOR(i, 1, a+1)
		{
			if( con[j][i] == true )
			{
				dp[j][i] = 0;
			}
			else
			{
				dp[j][i] += dp[j-1][i] + dp[j][i-1];
			}
		}
	
	return dp[b][a];
}
	
int main()
{
	while(cin >> a >> b, (a||b))
	{
		CLR(con);
		cin >> n;
		
		FOR(i, 0, n)
		{
			int x, y;
			cin >> x >> y;
			con[y][x] = true;
		}
			
		cout << solve() << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <vector>
#include <map>
#include <cstring>
#include <algorithm>
#include <cstdio>

#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; i++)

using namespace std;

string a, b, c;

int main() {
  ios::sync_with_stdio(false);
  while (cin >> a >> b >> c) {
    if (a[a.length() - 1] == b[0] && b[b.length() - 1] == c[0]) cout << "YES";
      else cout << "NO";
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
    Scanner s=new Scanner(System.in);
    int X=s.nextInt();
    int A=s.nextInt();
    if(X<A){
        System.out.print(0);
    }
   if(X>=A){
        System.out.print(10);
    }
    }
}

Measured memory_bytes: 21716
n, m = map(int, input().split())
s = list(str(input()))
s = list(reversed(s))
#print(s)

ds = []
d = 1
for i in range(1, n+1):
    if s[i] == '0':
        ds.append(d)
        d = 1
    else:
        d += 1
#print(ds)

temp0 = 0
ans = []
for i in range(len(ds)):
    if ds[i] > m:
        print(-1)
        exit()
    temp1 = temp0 + ds[i]
    #print(temp1)
    if temp1 > m:
        ans.append(temp0)
        temp0 = ds[i]
    elif temp1 == m:
        ans.append(temp1)
        temp0 = 0
    else:
        temp0 = temp1
else:
    if temp0 != 0:
        ans.append(temp0)
ans = list(reversed(ans))
print(*ans)

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

using namespace std;

typedef pair<int, int> II;
typedef pair<long long, int> LLI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<II> VII;

#define For(i,a,b) for(int i = a;i <= b; i++)
#define Rep(i,a,b) for(int i = a;i >= b; i--)
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, f) for(auto i : f)
#define fi first
#define se second
#define pb push_back
#define sz(s) int(s.size())
#define reset(f, x) memset(f, x, sizeof(f))
#define all(x) x.begin(), x.end()
#define two(x) (1LL << x)
#define getbit(x, i) ((x >> (i-1)) & 1LL)
#define onbit(x, i) (x | (1LL << (i-1)))
#define offbit(x, i) (x & ~(1 << (i-1)))

const int N = 1e5+10;

int n;
LL x[2][N], v[N], s[2][N], f[2][N], res, C;

int main() {
    ios_base::sync_with_stdio(false);
    //freopen("in.txt","r",stdin);
    //freopen("","w",stdout);
    cin >> n >> C;
    For(i, 1, n) cin >> x[0][i] >> v[i];
    For(i, 1, n) x[1][i] = C - x[0][i];
    For(i, 1, n) {
        s[0][i] = s[0][i-1] + v[i];
        f[0][i] = max(f[0][i-1], s[0][i] - x[0][i]);
        res = max(res, f[0][i]);
    }
    Rep(i, n, 1) {
        s[1][i] = s[1][i+1] + v[i];
        f[1][i] = max(f[1][i+1], s[1][i] - x[1][i]);
        res = max(res, f[1][i]);
        res = max(res, s[1][i] - 2LL*x[1][i] + f[0][i-1]);
        res = max(res, s[0][i] - 2LL*x[0][i] + f[1][i+1]);
    }
    cout << res << "\n";
    //For(i, 1, n) cout << f[1][i] << ' ';
}




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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=1;i<n;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) REP(i,v.size())cout<<#v<<"["<<i<<"]: "<<v[i]<<endl
#define ALL(a) (a).begin(),(a).end()

int main(){
  int n;
  string S,T;
  cin >> n >> S >> T;
  int scnt[26],tcnt[26];
  REP(i,26)scnt[i]=tcnt[i]=0;
  REP(i,n){
    scnt[S[i]-'a']++;
    tcnt[T[i]-'a']++;
  }
  sort(scnt,scnt+26);
  sort(tcnt,tcnt+26);
  int rest = 0;
  int result = 0;
  REP(i,26){
    int sc = scnt[i], tc = tcnt[i];
    if(sc==tc)continue;
    if(sc>tc){
      result += (sc-tc);
    }
  }
  cout << result << endl;
  return 0;
}

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

int main() {
	int n;cin>>n;
	long long W;cin>>W;
	vector<long long> w(n),v(n);
	vector<vector<long long>> a(4,vector<long long>(0));
	for(int i=0;i<n;i++){
		cin>>w[i]>>v[i];
		a[w[i]-w[0]].push_back(v[i]);
	}
	for(int i=0;i<4;i++){
		sort(a[i].begin(),a[i].end(),greater<long long>());
		for(int j=1;j<a[i].size();j++){
			a[i][j]+=a[i][j-1];
		}
	}
	long long ans=0;
	for(int i=0;i<=a[0].size();i++){
		for(int j=0;j<=a[1].size();j++){
			for(int k=0;k<=a[2].size();k++){
				for(int l=0;l<=a[3].size();l++){
					int b[4];
					b[0]=i;
					b[1]=j;
					b[2]=k;
//					int l=n-i-j-k;
					b[3]=l;
//					if(l<0)continue;
//					if(l>a[3].size())continue;
					long long wsum=0;
					long long vsum=0;
					for(int m=0;m<4;m++){
						wsum+=b[m]*(w[0]+m);
						if(b[m]){
						vsum+=a[m][b[m]-1];
						}
					}
//					cout<<i<<' '<<j<<' '<<k<<' '<<wsum<<' '<<vsum<<endl;
					if(wsum<=W){
						if(ans<vsum)ans=vsum;
					}
				}

			}
		}
	}
//	for(int i=0;i<4;i++){
//		for(int j=0;j<a[i].size();j++){
//			cout<<a[i][j]<<' ';
//		}
//		cout<<endl;
//	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
M=10**9+7
n=gets.to_i
h=Hash.new 0
ans=1
n.times{
  a,b=gets.split.map &:to_i
  g=a.gcd(b)
  r=b==0 ? a==0 ? :nan : :inf
         : a==0 ? :zero : Rational(a,b)
  h[r]+=1
}
ps=[]
h.each{|r,c|
  if r==:nan
  elsif r==:inf
    q=:zero
    if h[q]==0
      ps<<[h[r],h[q]]
    end
  elsif r==:zero
    q=:inf
    ps<<[h[r],h[q]]
  else
    q=-1/r
    if r>0||(r<0&&h[q]==0)
      ps<<[h[r],h[q]]
    end
  end
}
#p h
#p ps
ps.each{|a,b|
  ans*=(2.pow(a,M)+2.pow(b,M)-1)
  ans%=M
}
ans+=h[:nan]
p (ans-1)%M

Measured memory_bytes: 48484
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;
 
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }


vector<int> to[200010];
vector<int> ans;

void dfs(int v, int p=-1){
  for(int u: to[v]){
    if(u == p) continue;
    ans[u]+=ans[v];
    dfs(u,v);
  }
}

signed main()
{
  int n,q; cin>>n>>q;
  rep(i,n-1){
    int a,b;cin>>a>>b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a); // a[i] < b[i] であるが、これは各iについてaがbの親であることを意味するわけではない
  }
  ans.resize(n);
  rep(i,q){
    int p, x;
    cin>>p>>x;
    --p;
    ans[p]+=x;
  }
  dfs(0);
  rep(i,n){
    cout<<ans[i]<<endl;
  }
}

Measured memory_bytes: 23552
#include <stdio.h>

#define SIZE 10
int main(void){
    int w;
    int tmp;
    int first;

    while (scanf("%d", &w)!= EOF){
        tmp = 1;
        first = 1;
        while (w){
            if (w & 1){
                printf(first?"%d":" %d", tmp);
                first = 0;
            }
            tmp <<= 1;
            w >>= 1;
        }
        printf("\n");
    }

    return 0;
}

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

int abs(int x, int y) {
  if (x < y) {
    return y-x;
  }
  else{
    return x-y;
  }
}
int main(){
  int X,A;
  cin >>X>>A;
  if(X<A){
    cout << 0 <<endl;
  }
  else{
    cout<<10<<endl;
  }

}

Measured memory_bytes: 256
from sys import stdin, setrecursionlimit

setrecursionlimit(10 ** 9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


def main():
    N, K = map(int, input().split())
    A = [int(s) for s in input().split()]

    v = 1
    s = []
    order = [-1] * (N + 1)
    while order[v] == -1:
        order[v] = len(s)
        s.append(v)
        v = A[v - 1]
    l = order[v]
    c = len(s) - order[v]

    if K < l:
        print(s[K])
    else:
        print(s[l + (K - l) % c])

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 32276
#include <iostream>

using namespace std;

int main(void) {
	int a, b, c;

	cin >> a >> b >> c;

	if (a < b && a < c && b < c) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <locale>
#include <iomanip>

#define nl '\n';

using namespace std;

string s;

int main(){

    cin >> s;

    string t = "abc";

    vector<char> v;

    for(int i = 0; i < s.length(); i++){
        v.push_back(s[i]);
    }

    sort(v.begin(), v.end());

    for(int i = 0; i < v.size(); i++){
        if(v[i] != t[i]){
            cout << "No";
            return 0;
        }
    }

    cout << "Yes";
}

//g++ -std=c++14 comp.cpp -o b; ./b.exe
//g++ -std=c++14 comp.cpp && ./a.out

// char** arr = new char*[r];
// for(long long i = 0; i < r; i++) arr[i] = new char[c];

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

using namespace std;

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

	int ans = 0;
	for (auto c : s) {
		if (c == '+') { ++ans; }
		else { --ans; }
	}
	cout << ans << endl;

	return 0;
}


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

int main(){
    int a;
    int b;
    cin >> a >>b;
    if (a>b){
        cout << "a > b" << endl;
    }else if(a<b){
        cout << "a < b" << endl;
    }else{
        cout << "a == b" << endl;
    }   
    return 0;
}

Measured memory_bytes: 3096
#include<iostream>
using namespace std;
int main(){
    int N;
    string S;
    cin >> N;
    cin >> S;
    int ans=1;
    for(int i=1;i<N;i++){
        if(S.at(i-1)!=S.at(i)) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
times = [int(raw_input()) for i in range(5)]
dists = [(i % 10 or 10) for i in times]
last_index = dists.index(min(dists))
print sum([(time / 10 + (1 if time % 10 else 0)) * 10 for ind, time in enumerate(times) if ind != last_index] + [times[last_index]])

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

typedef long long int ll;

int main()
{
    ll n, l;
    cin >> n >> l;
    ll m = 1000, ans = 0;

    for(ll i = l;i < n + l;i++){
        m = min(m, abs(i));
        ans += i;
    }
    if(ans < 0){
        cout << ans + m;
    }
    else{
        cout << ans - m;
    }
    return 0;
}


Measured memory_bytes: 256
a = [input().split() for i in range(3)]
for i in range(3):
  a[i] = [int(a[i][j]) for j in range(3)]

buf = [[-1,-1,-1] for i in range(3)]
n = int(input())
for i in range(n):
  b = int(input())
  for j in range(3):
    for k in range(3):
      if b==a[j][k]:
        buf[j][k]=1

bingo = buf
for i in range(3):
	bingo = bingo+[[buf[0][i],buf[1][i],buf[2][i]]]
bingo = bingo + [[buf[0][0],buf[1][1],buf[2][2]]] + [[buf[2][0],buf[1][1],buf[0][2]]]
flag = False
for i in range(8):
  if bingo[i]==[1,1,1]:
    flag = True
    print("Yes")
    break
if flag==False:
  print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define endl '\n'
#define pi 3.1415926535897932384626433832
#define ll long long
using namespace std;
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / __gcd(a, b); }
bool isPrime(int n) {if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false;
return true;}

void lok(){
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int h,v,k;
	cin>>h>>v>>k;
	vector<vector<bool>> sef(h,vector<bool>(v,0));
	vector<int> def(h);
	vector<int> mou(v);
	char p;
	int lak=0;
	int ans=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<v;j++){
			cin>>p;
			if(p=='#'){
				sef[i][j]=true;
				def[i]++;
				mou[j]++;
				lak++;
			}
		}
	}
	for(int i=0;i<1<<h;i++){
		for(int j=0;j<1<<v;j++){
			int sum=lak;
			for(int ip=0;ip<h;ip++){
				if(i&1<<ip){
					sum-=def[ip];
				}
			}
			for(int jp=0;jp<v;jp++){
				if(j&1<<jp){
					sum-=mou[jp];
				}
			}
			for(int  ip=0;ip<h;ip++){
				for(int jp=0;jp<v;jp++){
					if(j&1<<jp && i&1<<ip){
						sum+=sef[ip][jp];
					}
				}
			}
			if(sum==k){
				ans++;
			}
		}
	}

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


Measured memory_bytes: 3684
/*
 * Author : Sadi
 * Wed 22/07/2020
 * 16:21:25.98
 */
#include <bits/stdc++.h>

using namespace std;

#define    watch(x); cout << "\n" <<  #x << " is: " << x << "\n";
#define    all(a) (a).begin(), (a).end()
#define    fi first
#define    se second

template<class A, class B>
ostream& operator << (ostream& output, const pair<A, B>& p) {
    output << "(" << p.first << ", " << p.second << ")";
    return output;
}

template<class A>
ostream& operator << (ostream& output, const vector<A>& a) {
    output << "[";
    for(auto it = a.begin(); it != a.end(); ++it) {
        if(it != a.begin()) {
            output << ", ";
        }
        output << *it;
    }
    output << "]";
    return output;
}

using lld = long long;
using pii = pair<int, int>;
using pll = pair<lld, lld>;

//const int inf = 1e9;
//const int mod = 1e9 + 7;
//const double PI = acos(-1.0);
//const int mx = 1e5 + 5;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

    int x, n;
    cin >> x >> n;
    // vector<int> v(n);
    set<int> s;
    for(int i = 0; i < n; ++i) {
        // cin >> v[i];
        int num;
        cin >> num;
        s.insert(num);
    }
    if(s.find(x) == s.end()) {
        cout << x << endl;
    }
    else {
        int a = x - 1; 
        int b = x + 1;
        while(1) {
            if(s.find(a) == s.end()) {
                cout << a << '\n';
                return 0;
            }
            else if(s.find(b) == s.end()) {
                cout << b << '\n';
                return 0;
            }
            a--;
            b++;
        }
        
    }
    return 0;
}


Measured memory_bytes: 3600
#include<stdio.h>

int main() {
	int a, b, c = 0;
	int x, y = 0;

	scanf("%d %d %d",&a,&b,&c);
    
	x = b - a;
	y = c - b;

	if (x==y) {
		printf("YES");
	}
	else {
		printf("NO");
	}
	return 0;
}

Measured memory_bytes: 128
#include<cstdio>
int m,n,a[220000];
int main() {
	scanf("%d%d",&m,&n);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]);
	int max=0;
	for (int i=2;i<=n;++i) if (max<a[i]-a[i-1]) max=a[i]-a[i-1];
	if (max<a[1]+m-a[n]) max=a[1]+m-a[n];
	printf("%d",m-max);
	return 0;
} 

Measured memory_bytes: 896