akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define int long long
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))

vector<int> anschar('z'+1, INT_MAX);

void update(vector<int> &v){
    reps(i,'a','z'){
        anschar[i] = min(anschar[i], v[i]);
    }
}

signed main() {
    int n; cin >> n;
    while(n--){
        string s; cin >> s;
        vector<int> v('z'+1, 0);
        for(char c : s){
            v[c]++;
        }
        update(v);
    }
    
    reps(i,'a','z'){
        rep(_,anschar[i]) cout << (char) i;
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int yu(int a, int b){
 int r, tmp;
 if(a < b){
     tmp = a;
     a = b;
     b = tmp;
 }
 r = a % b;
 while(r != 0){
     a = b;
     b = r;
     r = a % b;
 }

 return b;

}

int main(void){
    int a, b, g;
    scanf("%d%d", &a, &b);

    g = yu(a, b);

    long aa;
    aa = a / g;
    long bb;
    bb = b / g;

    long l;
    l = aa * bb * g;

    printf("%lld", l);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))
 
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;
 
#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))
 
int F()
{
    char ch;
    int x, a;
    while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
    if (ch == '-') ch = getchar(), a = -1;
    else a = 1;
    x = ch - '0';
    while (ch = getchar(), ch >= '0' && ch <= '9')
        x = (x << 1) + (x << 3) + ch - '0';
    return a * x;
}
 
int n;
char str[2333];
bool t[4];
 
int main()
{
    scanf("%s", str + 1); n = strlen(str + 1);
    for (int i = 1; i <= n; ++i)
    {
        if (str[i] == 'W') t[0] = 1;
        if (str[i] == 'E') t[1] = 1;
        if (str[i] == 'N') t[2] = 1;
        if (str[i] == 'S') t[3] = 1;
    }
    puts(t[0] == t[1] && t[2] == t[3] ? "Yes" : "No");
}

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

using namespace std;
using namespace std::chrono;

int main() {
  auto start = high_resolution_clock::now();

  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  string s;
  cin >> s;
  cout << (s[0] == '9' || s[1] == '9' ? "Yes" : "No") << endl;

  cerr << "Total execution time : " << duration_cast<milliseconds>(high_resolution_clock::now() - start).count() << " ms" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a, b, c;
    cin >> a >> b >> c;
    
    if(a == b && b == c && c == a){
        cout << 1 << endl;
    }else if(a != b && b != c && c != a){
        cout << 3 << endl;
    }else{
        cout << 2 << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
     if(abs(a-c)<=d)
    {
        cout<<"Yes"<<endl;
    }
    else if(abs(a-b)<=d && abs(b-c)<=d)
    {
         cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }

}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n;
     cin>>n;

        vector<pair<long long int,long long int>>vect;

        for(int i=1;i<=n;i++)
        {
           long long int x,y;
             cin>>x>>y;

             vect.push_back(make_pair(x+y,x-y));
        }
       sort(vect.begin(),vect.end());

       long long int value=-1000000000;
         int ans=0;

         for(int i=0;i<n;i++)
         {
              if(value <= vect[i].second)
              {
                 ans++;
                 value = vect[i].first;
              }
         }
         cout<<ans;
}


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


for i in range(h):
    s=list(map(str,input().split()))
    if 'snuke' in s:
        su=i+1
        break
a=s.index('snuke')
al=list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
print(al[a]+str(su))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
// type
typedef long long ll;
typedef long double ld;
// loop
//#define For(i, l, r, x)     for (int i = l; i < r; i+=x)
//#define ForE(i, l, r, x)    for (int i = l; i <= r; i+=x)
//#define Ford(i, r, l)       for (int i = r; i > l; i--)
//#define FordE(i, r, l)      for (int i = r; i >= l; i--)
//#define Fora(i, a)          for (auto i : a)
// I/O 
#define FAST_IO             std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
//#define PrintV(a)           Fora(ii, a) cout << ii << ' '; cout << endl;
//#define PrintVl(a)          Fora(ii, a) cout << ii << endl;
//#define PrintA(a, l, r)     for (int ii = l; ii <= r; ii++) cout << a[ii] << ' '; cout << endl;
//#define PrintAl(a, l, r)    for (int ii = l; ii <= r; ii++) cout << a[ii] << endl;
//#define Ptest(x)            return cout << x, 0;
#define setpre(n)           fixed << setprecision(n)
// pair
#define F                   first
#define S                   second
#define pii                 pair<int, int>
#define pll                 pair<ll, ll>
#define pdd                 pair<ld, ld>
// vector & !!?(string)
#define eb                  emplace_back
#define pb                  push_back
#define all(a)              a.begin(), a.end()
#define rall(a)             a.rbegin(), a.rend()
#define sz(a)               a.size()
#define len(a)              a.length()
// geometry calc    
#define pi                  acos(-1.0)
#define g_sin(a)            sin(a*pi/180)
#define g_cos(a)            cos(a*pi/180)
#define g_tan(a)            tan(a*pi/180)
// set val
#define ms0(a)              memset(a,        0, sizeof(a));
#define ms1(a)              memset(a,        1, sizeof(a));
#define msn1(a)             memset(a,       -1, sizeof(a));
#define msinf(a)            memset(a, 0x3f3f3f, sizeof(a));
// constant
const int mod1 = 998244353, mod2 = 1e9+7;
const int MAX_N = 100005, MAX_M = 200010;
//
ll a, b;

ll f(ll n){
    if (n < 0){
        return 0;
    }else if (n%4 == 0){
        return n;
    }else if (n%4 == 2){
        return n+1;
    }else if (n%4 == 3){
        return 0;
    }else{
        return 1;
    }
}
void Solve() {
    cin >> a >> b;
    //cout << f(a-1) << endl;
    ll res = (f(b) ^ f(a-1));
    cout << res;
}

signed main(){
    FAST_IO;
    int TC = 1; 
	// cin >> TC;
    while(TC--) Solve();
    return 0;
}
// 1 -> 0 0 0 0 1
// 2 -> 0 0 0 1 0
// 


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

//ABC110D
long long gya(long long a) { //逆元を求める
  long long m=1000000007, b=m, u=1, v=0, c, t;
  while(b){
    t=a/b, a-=t*b, u-=t*v; //何これ
    c=a, a=b, b=c, c=u, u=v, v=c; //swap
  }
  return (u+m)%m;
}
long long com(long long b, long long d) { //bCd
  long long i, mod=1000000007, ret=1, re2=1;
  for(i=1; i<=d; i++)
    ret=ret*(b-d+i)%mod, re2=re2*i%mod;
  return ret*gya(re2%mod)%mod;
}
int main(void) {
  long long n, m, i, cou=0, size=1000, memo[size], sum=1, mod=1e9+7;
  scanf("%lld %lld", &n, &m);
  int sqm=sqrt(m);

  for(i=0; i<size; i++)
    memo[i]=0;

  for(i=2; i<=sqm; i++){
    while(m%i==0)
      m/=i, memo[cou]++;
    if(memo[cou]!=0) cou++;
    if(m==1) break;
  }
  if(m>sqm) memo[cou++ ]++;
  for(i=0; i<cou; i++)
    sum=sum*com(n-1+memo[i], memo[i])%mod;
  printf("%lld", sum);
  return 0;
}


Measured memory_bytes: 128
using System;

namespace B___Good_Distance
{
    class Program
    {
        static void Main (string[] args)
        {
            var input = Console.ReadLine ().Split (' ');
            var n = int.Parse (input[0]);
            var d = int.Parse (input[1]);
            var a = new int[n, d];
            for (var i = 0; i < n; i++)
            {
                input = Console.ReadLine ().Split (' ');
                for (var j = 0; j < d; j++)
                {
                    a[i, j] = int.Parse (input[j]);
                }
            }
            var c = 0.0;
            var ans = 0;
            for (var i = 0; i < a.GetLength (0); i++)
            {
                for (var j = i + 1; j < a.GetLength (0); j++)
                {
                    var b = 0.0;
                    for (var k = 0; k < a.GetLength (1); k++)
                    {
                        b += Math.Pow (a[i, k] - a[j, k], 2);
                        if (k == a.GetLength (1) - 1)
                        {
                            c = Math.Sqrt (b);
                            if (c % 1 == 0)
                            {
                                ans++;
                            }
                        }
                    }
                }
            }
            Console.WriteLine (ans);
        }
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
char s[50],a[9]={6,8,6,8,8};
main(){for(int i,j,p,n,q;scanf("%d\n",&n),n;){for(i=0;i<n;s[i++]=strlen(gets(s+i)));
for(i=j=0;j<6;i++)for(p=i,j=q=0;q>=0;)for(q=a[j++]-1;q>0;q-=s[p++]);
printf("%d\n",i);
}}

Measured memory_bytes: 1200
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>

using namespace std;



int main() {
	ios::sync_with_stdio(false);

	int a, b;
	cin >> a >> b;

	int start = 1, ans = 0;

	while (start < b) {
		++ans;
		start += a - 1;
	}

	cout << ans;

	return 0;
}

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

int main()
{
    int n,r;
    scanf("%d %d",&n,&r);
    if(n>10)
    {
        cout << r << endl;
    }
    else
        cout << 100*(10-n)+r<< endl;
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
//by NeighThorn
using namespace std;
const int maxn=100000+5;
int n,q,hd[maxn],to[maxn*2],nxt[maxn*2],cnt,vis[maxn],fa[maxn],ans[maxn];
struct M{
	int y,id;
	M(int a=0,int b=0){
		y=a,id=b;
	}
};
vector<M> v[maxn];
inline int find(int x){
	return fa[x]==x?x:fa[x]=find(fa[x]);	
}
inline void add(int x,int y){
	to[cnt]=y;nxt[cnt]=hd[x];hd[x]=cnt++;	
}
inline void tarjan(int root){
	vis[root]=1;
	for(int i=0;i<(int)v[root].size();i++)
		if(vis[v[root][i].y])
			ans[v[root][i].id]=find(v[root][i].y);
	for(int i=hd[root];i!=-1;i=nxt[i])
		if(!vis[to[i]])
			tarjan(to[i]),fa[to[i]]=root;
}
signed main(void){
	scanf("%d",&n);cnt=0;
	memset(hd,-1,sizeof(hd));
	for(int i=0,k;i<n;i++){
		scanf("%d",&k);
		for(int j=1,x;j<=k;j++)
			scanf("%d",&x),add(i,x),add(x,i);
	}scanf("%d",&q);
	for(int i=0;i<n;i++)
		fa[i]=i,vis[i]=0;
	for(int i=1,x,y;i<=q;i++)
		scanf("%d%d",&x,&y),v[x].push_back(M(y,i)),v[y].push_back(M(x,i));
	tarjan(0);
	for(int i=1;i<=q;i++)
		printf("%d\n",ans[i]);
	return 0;	
}

Measured memory_bytes: 15024
S = input()
T = input()
t = len(T)
indices = []
for i in range(len(S) - t + 1):
    for j, s in enumerate(S[i:i+t]):
        if s == '?':
            continue
        if s != T[j]:
            break
    else:
        indices.append(i)
if len(indices) == 0:
    print('UNRESTORABLE')
else:
    cand = []
    for ind in indices:
        ans = ''
        for i, s in enumerate(S):
            if i == ind:
                ans += T
            elif ind < i < ind + t:
                continue
            elif s == '?':
                ans += 'a'
            else:
                ans += s
        cand.append(ans)
    cand = sorted(cand)
    print(cand[0])

Measured memory_bytes: 3064
#include        "algorithm"
#include        "iostream"
#include        "numeric"
#include        "iomanip"
#include        "cstring"
#include        "math.h"
#include        "bitset"
#include        "string"
#include        "vector"
#include        "random"
#include        "chrono"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"

#include        "ext/pb_ds/assoc_container.hpp" // Common file
#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
#include        "ext/pb_ds/detail/standard_policies.hpp"

using namespace std;
using namespace __gnu_pbds;


#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          pb push_back
#define          N (int)2e5+5
#define          PI acos(-1.0)
#define          int long long 
#define          vi vector<int>
#define          mod 1000000007
#define          ld long double
#define          eb emplace_back
#define          mii map<int,int>
#define          vpii vector<pii>
#define          pii pair<int,int>
#define          pq priority_queue
#define          BLOCK (int)sqrt(N)
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) x.rbegin(),x.rend()
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define          bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > 
OS ;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n,m,k,q;
string s;
set<int> adj[N];
int vis[N],par[N],a[N];

void dfs( int i )
{
    vis[i] = 1;
    k += 1;
    for( auto j: adj[i] )
    {
        if( !vis[j] ) dfs( j );
    }
}

void go()
{
    cin >> n >> m;

    fo(i,0,m)
    {
        int u , v;
        cin >> u >> v;

        adj[u].insert( v );
        adj[v].insert( u );
    }

    set< int > st;
    for( int i = 1; i <= n; i++)
    {
        k = 0;
        if( !vis[i] ) dfs(i );
        st.insert( k );
    }

    cout << *st.rbegin() << endl;

}

int32_t main()
{
    FAST;     
    int t=1; 
    // cin>>t;
    test(t) go();
}

 

Measured memory_bytes: 39512
#include <stdio.h>
long a[100][100],b[100][100],c[100][100];

int main(void) {
    int n,m,l;
    scanf( "%d %d %d", &n, &m, &l );
    for( int i=0; i<n; i++ ) {
        for( int j=0; j<m; j++ ) {
            scanf( "%ld", &a[i][j] );
        }
    }
    for( int i=0; i<m; i++ ) {
        for( int j=0; j<l; j++ ) {
            scanf( "%ld", &b[i][j] );
        }
    }
    for( int i=0; i<n; i++ ) {
        for( int j=0; j<l; j++ ) {
            for( int k=0; k<m; k++ ){
                c[i][j]+=a[i][k]*b[k][j];
            }
        }
    }
    for( int i=0; i<n; i++ ) {
        for( int j=0; j<l; j++ ) {
            if( j ) printf( " " );
            printf( "%ld", c[i][j] );
        }
        printf( "\n" );
    }
    return 0;
}


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

int hmap[101][101];
vector< pair<int, int> > vs;

int main(void) 
{
  int n;
  cin >> n;
  int maxh = 0;
  int limit = 0;
  for (int i = 0; i < n; i++) {
    int x, y, h;
    cin >> x >> y >> h;
    
    pair<int, int> t = make_pair(x, y);
    vs.push_back(t);
    hmap[x][y] = h;

    if (maxh < h)
    {
      maxh = h;
      limit = h + max(max(x, 101 - x), max(y, 101 - y)) + 1;
    }
  }

  for (int i = 0; i < 101; i++) {
    for(int j = 0; j < 101; j++) {
      for(int h = maxh; h < limit; h++)
      {
        bool flag = true;
        for (int k = 0; k < vs.size(); k++)
        { 
          int x = vs[k].first, y = vs[k].second;
          int vh = hmap[x][y];
          if (vh != max(h - abs(i - x) - abs(j - y), 0)) {
            flag = false;
          }
        }
        if (flag){
          cout << i << " " << j << " " << h << endl;
          return 0;
        }
      }    
    }    
  }
  return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main()
{
  int i,j,n;
  int val[50];
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&val[i]);
  int ans=0;
  for(i=0;i<n;i++)
    for(j=i+1;j<n;j++)
      ans+=val[i]*val[j];
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;
const int maxn = 2000100;



int main(){
        _
        vll a(3);
        cin >> a[0] >> a[1] >> a[2];
        sort(all(a));
        int res =(a[2] - a[1] + (a[1] + 1 - a[0]) / 2 + (a[1] - a[0]) % 2);
        cout<<res<<endl;



return 0;
}




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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int main(){
    int n;cin>>n;
    cout<<24+(24-n)<<endl;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド
		Scanner sc = new Scanner(System.in);

		for(int i = 0;;i++) {
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a == 0&&b == 0)
			break;
		for(int j = 0;j < a; j++) {
			for(int k = 0; k < b; k++) {
				System.out.print("#");
			}
			System.out.println("");

		 }
		System.out.println("");
		}
	}
}



Measured memory_bytes: 35348
#include<bits/stdc++.h>
using namespace std;
using LL=int64_t;
const int INF=0x3f3f3f3f;
const int maxn=1e6+5;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    LL a,b;
    cin>>a>>b;
    if((a*b)%2) cout<<"Odd\n";
    else cout<<"Even\n";
    return 0;
}


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

using namespace std;

const int MAXN = 2*(1e5 + 100);

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

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
bitset<5000000> bit;
int main()
{
ll n ;
cin >> n ;
vector<vector<ll>> g(n);
rep(i,n-1){
  ll p ;
  cin >> p ;
  g[i+1].push_back(p-1);
  g[p-1].push_back(i+1);
}
vector<pair<ll,ll>> x(n);
rep(i, n){
  cin >> x[i].first;
}
ll root=0;
vector<vector<ll>> child(n);
vector<ll> par(n);
queue<ll> q;
queue<ll> qq;
q.push(root);
par[root]=-1;
//親の定義と葉を見つける
while(!q.empty()){
  ll p=q.front();
  q.pop();
  if(g[p].size()==1 && p!=root){qq.push(p);}
  for(auto r:g[p]){
    if(r==par[p])continue;
    par[r]=p;
    q.push(r);
  }
}
while(!qq.empty()){
  ll p=qq.front();
  qq.pop();
  child[par[p]].push_back(p);//親に値を追加する
  //根の時は例外処理
  if(child[par[p]].size()==g[par[p]].size()){
    //child[par[p]]に子の値が入ってる
    ll sum=0;
    for(auto r:child[par[p]]){
      sum+=x[r].first+x[r].second;
    }
    bit.reset();
    bit[0]=1;
    for(auto r:child[par[p]]){
      bit=(bit<<x[r].first)|(bit<<x[r].second);
    }
    ll mx=-1;
    rep(i,x[par[p]].first+1){
      if(bit[i])mx=i;
    }
    if(mx==-1){
      cout << "IMPOSSIBLE" << endl;
      return 0;
    }
    else{
      x[par[p]].second=sum-mx;
    }
  }
  //全ての葉が親に追加し終わった
  if(child[par[p]].size()==g[par[p]].size()-1 && par[p]!=root){
    //child[par[p]]に子の値が入ってる
    ll sum=0;
    for(auto r:child[par[p]]){
      sum+=x[r].first+x[r].second;
    }
    bit.reset();
    bit[0]=1;
    for(auto r:child[par[p]]){
      bit=(bit<<x[r].first)|(bit<<x[r].second);
    }
    ll mx=-1;
    rep(i,x[par[p]].first+1){
      if(bit[i])mx=i;
    }
    if(mx==-1){
      cout << "IMPOSSIBLE" << endl;
      return 0;
    }
    else{
      x[par[p]].second=sum-mx;
    }
    qq.push(par[p]);
  }
}
cout << "POSSIBLE" << endl;
return 0;
}

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


int main()
{
	int n;
	cin >> n;
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		int p_in;
		cin >> p_in;
		if (p_in != i + 1) {
			cnt++;
		}
	}

	string ans = "YES";
	if (cnt > 2) {
		ans = "NO";
	}

	cout << ans << endl;
}


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


int M, K;

int main(){
    cin >> M >> K;
    if(K >= (1 << M)){
        cout << -1 << endl;
        return 0;
    }

    if(M == 0){
        cout << "0 0" << endl;
        return 0;
    }
    if(M == 1 && K == 1){
        cout << -1 << endl;
        return 0;
    }
    if(M == 1 && K == 0){
        cout << "0 0 1 1" << endl;
        return 0;
    }

    for(int i = 0; i < (1 << M); i++){
        if(i != K){
            cout << i << " ";
        }
    }
    cout << K << " ";
    for(int i = (1 << M) - 1; i >= 0; i--){
        if(i != K){
            cout << i << " ";
        }
    }
    cout << K << endl;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		//????????£?????????????????????
		Scanner sc = new Scanner(System.in);
		//??°??????????????°?????????
		int n = sc.nextInt();
		//??°?????????	0?????¨?????????????????? ??\???????????°????????§??¨????????????
		for(int i = 1; i<= n; i++){
		//?????¶??? 3???????????°??????????????¨??? contains??????????????????????????????????????§?????????????????????String????????´???????????¨??????????????????toString????????´
			if(i % 3 ==0 || Integer.toString(i).contains("3")){
				//???????????°??????????????¨?????????????????´?????????
				//if(0 < i){
					//?????????????¬?
					System.out.print(" " + i);
				//}else{
					//?????????????¬???????
					//System.out.print(i);
				//}
			}
		}
		//??????
		System.out.println();
	}
}

Measured memory_bytes: 29320
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	int n;
	vector<int> arr, sum;
	int cur = 0;
	int input;
	int i;
	int lmin = 10001;

	scanf("%d", &n);

	for (i = 0; i < n; i++)
	{
		scanf("%d", &input);

		arr.push_back(input);

		cur += input;

		sum.push_back(cur);
	}

	for (i = 0; i < n - 1; i++)
	{
		if (abs((sum[n - 1] - sum[i]) - sum[i]) < lmin)
		{
			lmin = abs((sum[n - 1] - sum[i]) - sum[i]);
		}
	}

	printf("%d\n", lmin);

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int A = sc.nextInt();
		int B = sc.nextInt();
		int K = sc.nextInt();
		
		int a = A;
		int b = B;
		
		for(int i = 1; i <= K; i++) {
			if(i % 2 != 0) {
				if(a % 2 == 0) {
					a = a / 2;
					b = b + a;
					
				} else {
					a = a - 1;
					a = a / 2;
					b = b + a;
				}
			} else {
				if(b % 2 == 0) {
					b = b / 2;
					a = a + b;
					
				} else {
					b = b - 1;
					b = b / 2;
					a = a + b;
				}			
			}
		}
		
		System.out.println(a + " " + b);
		
	}
}


Measured memory_bytes: 22996
def str_find(S, target, start):
    for i in range(start, len(S)):
        if S[i] == target:
            return i

    return 10**9+7

N = int(raw_input())
S = str(raw_input())

candidates = []

for i in range(10):
    for j in range(10):
        for k in range(10):
            candi = str(i)+str(j)+str(k)
            candidates.append(candi)


ans = 0
for candi in candidates:
    x = candi[0]
    i = str_find(S, x, 0)

    y = candi[1]
    j = str_find(S, y, i+1)

    z = candi[2]
    k = str_find(S, z, j+1)

    if i+j+k< 10**8:
        ans = ans + 1

print ans


Measured memory_bytes: 3616
// https://abc043.contest.atcoder.jp/tasks/arc059_b
#include <iostream>

using namespace std;

int main() {
	int c[26];
	for (int i = 0; i < 26; i++) c[i] = 0;
	string s;
	cin >> s;
	for (int i = 0; i < s.size() - 2; i++) {
		if (s[i] == s[i + 1]) {
			cout << i + 1 << " " << i + 2 << endl;
			return 0;
		}
		if (s[i] == s[i + 2]) {
			cout << i + 1 << " " << i + 3 << endl;
			return 0;
		}
	}
	if (s[s.size() - 2] == s[s.size() - 1]) {
		cout << s.size() - 1 << " " << s.size() << endl;
	} else {
		cout << "-1 -1\n";
	}
}


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

using namespace std;

/* MEMO
 * スライド最小値(スライドしてくやつ)
 * BIT(セグ木の進化系みたいなやつ)
 * DP(ダイナミックP)
 * ダイクストラ(グラフ)
 * 座標圧縮(zip)
 * イモス法(なんかドンッてするやつ)
 */

// アルファベットから整数へ ( 小文字 -> [0, 26), 大文字 -> [32, 58) )
#define table_of_alphabet_to_number(t) map<char, int> t = { make_pair('a',  0) , make_pair('b',  1) , make_pair('c',  2), make_pair('d',  3), make_pair('e',  4), make_pair('f',  5), make_pair('g',  6), make_pair('h',  7), make_pair('i',  8), make_pair('j',  9), make_pair('k', 10), make_pair('l', 11), make_pair('n', 12), make_pair('m', 13), make_pair('o', 14), make_pair('p', 15), make_pair('q', 16), make_pair('r', 17), make_pair('s', 18), make_pair('t', 19), make_pair('u', 20), make_pair('v', 21), make_pair('w', 22), make_pair('x', 23), make_pair('y', 24), make_pair('z', 25), make_pair('A',  0 + 32), make_pair('B',  1 + 32), make_pair('C',  2 + 32), make_pair('D',  3 + 32), make_pair('E',  4 + 32), make_pair('F',  5 + 32), make_pair('G',  6 + 32), make_pair('H',  7 + 32), make_pair('I',  8 + 32), make_pair('J',  9 + 32), make_pair('K', 10 + 32), make_pair('L', 11 + 32), make_pair('N', 12 + 32), make_pair('M', 13 + 32), make_pair('O', 14 + 32), make_pair('P', 15 + 32), make_pair('Q', 16 + 32), make_pair('R', 17 + 32), make_pair('S', 18 + 32), make_pair('T', 19 + 32), make_pair('U', 20 + 32), make_pair('V', 21 + 32), make_pair('W', 22 + 32), make_pair('X', 23 + 32), make_pair('Y', 24 + 32), make_pair('Z', 25 + 32) }

// 多次元 std::array
template <typename T, std::size_t... Ns>
    struct index_reverse_for_array;
template <typename T, std::size_t N, std::size_t... Ns>
    struct index_reverse_for_array<T, N, Ns...> { using type = std::array< typename index_reverse_for_array<T, Ns...>::type, N>; };
template <typename T, std::size_t N>
    struct index_reverse_for_array<T, N> { using type = std::array<T, N>; };
template <class T, std::size_t... Ns> using mul_array = typename index_reverse_for_array<T, Ns...>::type;

// 型確認用
template <class T> struct template_assert;


int main() {
    string S;
    int N, K;
    string s;

    cin >> N >> K >> S;

    auto a = S[K - 1];
    if (a == 'A')
        a = 'a';
    if (a == 'B')
        a = 'b';
    if (a == 'C')
        a = 'c';

    S[K-1] = a;

    cout << S << endl;

    return 0;
}



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

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; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

int main() {
  ll N,D,A;
  cin>>N>>D>>A;
  vector<vector<ll>> v(N,vector<ll>(2));
  for(ll i = 0LL; i < N; i++){
    ll X,H;
    cin>>X>>H;
    H=((H-1)/A) + 1;
    v[i][0]=X;
    v[i][1]=H;
  }
  sort(v.begin(),v.end());
  ll ans = 0LL;
  vector<ll> dam(N+1,0LL);
  ll d = 0LL;
  for(ll i = 0LL; i < N; i++) {
    if(i!=0) d=d+dam[i];
    if(v[i][1]<=d)continue;
    v[i][1]-=d;
    vector<ll> s = {v[i][0]+2LL*D,INF};
    auto ite = upper_bound(v.begin(),v.end(),s);
    ans+=v[i][1];
    dam[i]+=v[i][1];
    d+=v[i][1];
    dam[(int)(ite-v.begin())]-=v[i][1];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 12800
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;

vector<vector<int>> G(100+1,vector<int>(100+1,0));

int main(void) {

    int n; cin>>n;

    for (int i = 1; i <= n; ++i) {
        int u,k; cin>>u>>k;
        for (int j = 1; j <= k; ++j) {
            int v; cin>>v;
            G[u][v]=1;
        }
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            cout<<G[i][j];
            if(j!=n) cout<<" "; 
        }
        cout<<endl;
    }

    return 0;
}


Measured memory_bytes: 3212
const main = (standardInput) => {
    const lengthList = standardInput.split(' ');
    const varticalLength = Number.parseInt(lengthList[0]);
    const horizonLength = Number.parseInt(lengthList[1]);

    console.log(`${varticalLength * horizonLength} ${2 * (varticalLength + horizonLength)}`);
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8'));


Measured memory_bytes: 15100
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
using namespace std;
const int mo=1000000007;
const int N=1005;
int n,X,x,ans;
int cnt[N],a[N];
int C[N][N],f[N][N];
int inv[N];
void init(){
	inv[0]=inv[1]=1;
	For(i,2,N-1) inv[i]=1ll*inv[mo%i]*(mo-mo/i)%mo;
	For(i,1,N-1) inv[i]=1ll*inv[i-1]*inv[i]%mo;
	For(i,0,N-1) C[i][0]=1;
	For(i,1,N-1) For(j,1,i)
		C[i][j]=(C[i-1][j]+C[i-1][j-1])%mo;
}
int power(int x,int y){
	int s=1;
	for (;y;y/=2,x=1ll*x*x%mo)
		if (y&1) s=1ll*s*x%mo;
	return s;
}
int main(){
	init();
	scanf("%d%d",&n,&X);
	For(i,1,n) scanf("%d",&x),++cnt[x]; 
	f[0][0]=1;
	Rep(i,X,1){
		Rep(j,X/i,0) For(k,1,X/i-j) For(L,0,X-k*i)
			f[j+k][L+k*i]=(f[j+k][L+k*i]+1ll*f[j][L]*C[j+k][k])%mo;
		For(j,0,X/i) For(k,j*i,X){
			int v=k-j*(i-1);
			f[j][k]=1ll*f[j][k]*power(v,cnt[i])%mo;
		}
	}
	For(i,1,X) For(j,0,X){
		int tr=C[X-j+1][i];
		//if (tr) printf("%d %d %d\n",i,j,f[i][j]);
		if ((X-j)&1) tr=(mo-tr);
		ans=(ans+1ll*tr*f[i][j])%mo;	
	}
	printf("%d\n",ans);
}
/*
18 500
324 31 27 227 9 21 41 29 50 34 2 362 92 11 13 17 183 119
*/

Measured memory_bytes: 8064
s=input()
ans=[0]
for i in range(len(s)):
    for j in range(i,len(s)):
        st=s[i:j+1]
        if st.count("A")+st.count("G")+st.count("C")+st.count("T")==len(st):
            ans.append(len(st))
print(max(ans))

Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <utility>
using namespace std;

#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)

string a, b;
string ans;

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

  int n = stoi(a+b);
  int rn = (int)sqrt(n);
  if (rn*rn == n) {
    ans = "Yes";
  } else {
    ans = "No";
  }

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


Measured memory_bytes: 256
def main():
    x, y = map(int, input().split())

    ans = f(x, y)
    print(ans)


def f(x, y):
    if x == y:
        ans = 0
    elif x >= 0 and y >= 0:
        if x < y:
            # x:0, y:3
            ans = y - x
        elif y == 0:
            # x:3, y:0 -> x:-3,-2,-1,0
            ans = 1 + x
        else:
            # x:3, y:1 -> x:-3,-2,-1,1
            ans = 1 + abs(y - x) + 1
    elif x < 0 and y < 0:
        if x < y:
            # x:-3, y:0
            ans = y - x
        else:
            # x:-2, y:-3 -> x:  2,3,-3
            ans = 1 + abs(y - x) + 1
    elif x < 0 and y == 0:
        # x:-5, y:0 -> x:-4,-3,-2,-1,0
        ans = abs(x)
    elif x < 0 < y:
        if abs(x) <= y:
            # x:-1, y:4 -> x:1,2,3,4
            ans = 1 + y + x
        else:
            # x:-5, y:4 -> x:-4,4
            ans = abs(y + x) + 1
    elif x == 0 and y < 0:
        # x:0, y:-4 -> x:1,2,3,4,-4
        ans = abs(y) + 1
    elif x > 0 > y:
        if x >= abs(y):
            # x:3, y:-1 -> x:-3,-2,-1
            ans = 1 + x + y
        else:
            # x:3, y:-4 -> x:      4,-4
            ans = abs(y + x) + 1

    return ans


def note():
    """
    x,yについて =0,<0,0> の全列挙
    3*3=9
    例外:x == y

    x == 0 and y == 0(例外に含まれる)
    x == 0 and y >  0
    x == 0 and y <  0

    x >  0 and y == 0
    x >  0 and y >  0
    x >  0 and y <  0

    x <  0 and y == 0
    x <  0 and y >  0
    x <  0 and y <  0

    実装しやすさによって、<=,>=を変更
    """


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import bisect

N,M = map(int,input().split())
A = sorted(list(map(int,input().split())))
BC = []
for i in range(M):
  B,C = map(int,input().split())
  BC.append([B,C])
BC.sort(key = lambda val: val[1], reverse = True)
#print(A)
#print(BC)

ans = 0
j = 0
count = BC[j][0]
for i in range(N):
  #print(ans)
  if A[i] < BC[j][1]:
    ans += BC[j][1]
    count -= 1
    if count == 0:
      j += 1
      if j >= M:
        if i < N-1:
          ans += sum(A[i+1:])
        break
      count = BC[j][0]
  else:
    ans += sum(A[i:])
    break
print(ans)


Measured memory_bytes: 80920
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <tuple>

using namespace std;

int main()
{  
    int A,B;
    cin >> A >> B;
    if(A % 2 != B % 2){
        cout << "IMPOSSIBLE" << endl;
    }else{
        cout << (A+B)/2 << endl;
    }
}

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


int main() {
    int n;
    double m;
    cin >> n >> m;
    vector<int> vec(n);
    double sum;
    rep(i,n) {
        cin >> vec.at(i);
        sum += vec.at(i);
    }
    sort(vec.begin(), vec.end());
    if (vec.at(n - m) >= sum/(4*m)) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3744
#include<vector>
#include<iostream>
using namespace std;
#define df 0
typedef long int li;
const li MOD=1e9+7;

int main(){
  if(df) printf("*debug mode*\n");
  int n; cin>>n;
  string s; cin >>s;
  if(df)cout << s;
  vector<li> dp(1,1);  // N==0,|s|==0
  if(df){
    for(li x: dp)printf("%ld ",x);
    printf(":dp\n");
  }
  for(int i=1;i<=n;i++){
    //    dp.push_front(*(dp.begin()));
    dp.push_back(dp.at(i-1));
    for(int j=i-1;j>0;j--){
      dp.at(j)=dp.at(j-1);
    }
    for(int j=0;j<i-1;j++){
      (dp.at(j)+=2*dp.at(j+2))%=MOD;
    }
    if(df){
      for(li x: dp)printf("%ld ",x);
      printf(":dp[%d]\n",i);
    }
  }
  cout << *(dp.begin()+s.size());
}

/// confirm df==0 ///


Measured memory_bytes: 384
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD (1000003LL)
typedef long long Int;

int n, mi, memo[60000*4], cs[60000][2];
vector<int> g[60000];
bool has[60000];

void add(int p, int q) {
    if (p > q) swap(p, q);
    g[p].push_back(q);
}

int pre(int p, int q) {
    if (p+1 == q) return -1;
    const int k = mi++;
    has[k] = false;
    if (g[p].back() == q) {
        has[k] = true;
        g[p].pop_back();
    }
    const int r = g[p].back();
    rep (b, 4) memo[k*4|b] = -1;
    cs[k][0] = pre(p, r);
    cs[k][1] = pre(r, q);
    return k;
}

int rec(int k, int x, int y) {
    if (k == -1) return x == y;
    const int sig = k*4|x*2|y;
    if (memo[sig] != -1) return memo[sig];
    const int p = cs[k][0], q = cs[k][1];
    Int ans = 0;
    ans += (Int)rec(p, x, 0) * rec(q, 1, y);
    ans += (Int)rec(p, x, 1) * rec(q, 0, y);
    if (x && y && has[k]) {
        ans += (Int)rec(p, 0, 0) * rec(q, 1, 0);
        ans += (Int)rec(p, 0, 1) * rec(q, 0, 0);
    }
    return memo[sig] = ans % MOD;
}

int main() {
    for (;;) {
        int m, a, b;
        scanf("%d%d", &n, &m);
        if (n == 0) return 0;
        rep (_, m) {
            scanf("%d%d", &a, &b);
            add(a-1, b-1);
        }
        rep (i, n) add(i, (i+1)%n);
        rep (i, n) sort(g[i].begin(), g[i].end());
        mi = 0;
        pre(0, n-1);
        printf("%d\n", rec(0, 1, 1));
    }
}

Measured memory_bytes: 11812
#include<bits/stdc++.h>
using namespace std;
int n,m,a[301][301],ans=0x3f3f3f3f,x[301];
bool use[301],pd=0;
int clac()
{
    int maxx=0,re;
    pd=1;
    memset(x,0,sizeof(x));
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(use[a[i][j]]==0)
            {
                x[a[i][j]]++;
                pd=0;
                break;
            }
        }
    }
    if(pd==1)
        return 0;
    for(int i=1;i<=m;i++)
    {
        if(x[i]>maxx)
        {
            maxx=x[i];
            re=i;
        }
    }
    ans=min(ans,maxx);
    return re;
}
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            cin>>a[i][j];
    while(pd==0)
        use[clac()]=1;
    cout<<ans;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        //緑のカードに書かれている整数は、赤のカードに書かれている整数より真に大きい。
        //青のカードに書かれている整数は、緑のカードに書かれている整数より真に大きい。
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt(); //赤
        int B = sc.nextInt(); //緑
        int C = sc.nextInt(); //青
        int K = sc.nextInt();
        boolean flag = false;
        for(int i = 0; i < K; i ++){
                if (B <= A){
                    B = B * 2;
                } else if (C <= B){
                    C = C * 2;
                }
                if(A < B && B < C){
                    flag = true;
                    break;
                }
        }
        if (flag) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35356
#include <iostream>
#include <cstdio>
#include <math.h>
#include <cstring>
using namespace std;
 
int main(){
	int n;
	long long ans=1;
	char s[55],t[55];
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> s[i];
	}
	for(int i=0;i<n;i++){
		cin >> t[i];
	}
	for(int i=0;i<n;i++){
		if(s[i]==t[i]){
			if(i==0){
				ans*=3;
			}else{
				if(s[i-1]==t[i-1]){
					ans*=2;
				}
			}
		}else{
			if(i==0){
				ans*=6;
			}else{
				if(s[i-1]==t[i-1]){
					ans*=2;
				}else{
					ans*=3;
				}
			}
			i++;
		}
	}
	ans%=1000000007;
	cout << ans << endl;
	return 0;
} 

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

ok = [False for i in range(2505)]
def Bellmanford(edges, n, s):
    d = [float("inf") for i in range(n)]
    d[s] = 0


    for i in range(n):
        for x, y, z in edges:
            if not ok[x] or not ok[y]:#0からn-1へ到達できない点は無視
                continue
            if d[y] > d[x] + z:
                d[y] = d[x] + z
                if i == n - 1:
                    print(-1)
                    exit()
    print(max(0, -d[n - 1]))


def main():
    n, m, p = map(int, input().split())

    to = [[] for i in range(n + 1)]
    rto = [[] for i in range(n + 1)]
    e = []
    for i in range(m):
        a, b, c = map(int, input().split())
        to[a - 1].append(b - 1)
        rto[b - 1].append(a - 1)
        e.append((a - 1, b - 1, p - c))

    #0 から n-1にたどり着けるか調べる
    can_reach_to = [False for i in range(n+1)]
    can_reach_rto = [False for i in range(n+1)]
    def todfs(i):
        if can_reach_to[i]:
            return 0
        can_reach_to[i] = True
        for v in to[i]:
            todfs(v)
    def rtodfs(i):
        if can_reach_rto[i]:
            return 0
        can_reach_rto[i] = True
        for v in rto[i]:
            rtodfs(v)
    todfs(0)
    rtodfs(n-1)
    for i in range(n):
        ok[i] = (can_reach_to[i] & can_reach_rto[i])

    d = Bellmanford(e, n, 0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61404
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

int main(){
  int n;
  string s;
  cin >> n >> s;
  if(n%2 != 0) {
    cout << "No" << endl;
  } else if(s.substr(0, n/2) ==
            s.substr(n/2, n)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3524
#include <stdio.h>
#include <math.h>
#define A (a%3)
#define B ((a+1)%3)
#define C ((a+2)%3)

/*
(x1,y1),(x2,y2)ðñ¾¼üF
	a=(y2-y1)/(x2-x1)
	b=y1-a*x1

ªÌ¼ñªüF
	a=(x1-x2)/(y2-y1)
	b=(y1+y2)/2-a*(x1+x2)/2
	
QÂÌ¼üax+bÆcx=dÌð_F
	ax+b=cx+dðð¢Ä
	x=(d-b)/(a-c)
	y=ax+b
*/

int main(void){
	double l[2], m[2], x[3], xp, y[3], yp, r; int a, N;
	scanf("%d",&N);
	
	for(;N>0;N--){
		scanf("%lf %lf %lf %lf %lf %lf",&x[0],&y[0],&x[1],&y[1],&x[2],&y[2]);
		/* ÇÌQ¼üðg¤©iX«³ÀÉÈé_ðð¯éj */
		a=0; if(y[0]==y[1]) a=1; else if(y[1]==y[2]) a=2;
		/* ¼ñªü */
		l[0]=(x[A]-x[B])/(y[B]-y[A]); l[1]=(y[A]+y[B])/2-l[0]*(x[A]+x[B])/2;
		m[0]=(x[B]-x[C])/(y[C]-y[B]); m[1]=(y[B]+y[C])/2-m[0]*(x[B]+x[C])/2;
		/* ð_ */
		xp=(m[1]-l[1])/(l[0]-m[0]);
		yp=l[0]*xp+l[1];
		/* ¼a */
		r=sqrt(pow(xp-x[0],2)+pow(yp-y[0],2));
		
		printf("%.3lf %.3lf %.3lf\n",xp,yp,r);
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

int main(){
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    rep(i, n-2) {
        if(s.substr(i,3) == "ABC") ans++;
    }
    cout << ans << endl;

    return 0;
}

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

namespace D
{
    class Program
    {
        static int n, maxK;
        static Dictionary<string, int> memo;

        static void Main(string[] args)
        {

            int[] nk = RArInt();
            n = nk[0];
            maxK = nk[1];
            int[] vs = RArInt();
            memo = new Dictionary<string, int>();

            int res = 0;
            int opeCnt = Math.Min(maxK, n);

            for (int lCnt = 0; lCnt <= opeCnt; lCnt++)
            {
                for (int rCnt = 0; rCnt <= opeCnt; rCnt++)
                {
                    if (lCnt + rCnt > opeCnt) continue;

                    var l = vs.Take(lCnt);
                    var r = vs.Skip(vs.Length - rCnt).Take(rCnt);

                    List<int> li = new List<int>();
                    foreach (var item in l) li.Add(item);
                    foreach (var item in r) li.Add(item);
                    li = li.OrderBy(x => x).ToList();

                    for (int i = 0; i < maxK - (lCnt + rCnt); i++)
                    {
                        if (i > li.Count - 1) break;
                        if (li[i] < 0) li[i] = 0;
                        else break;
                    }
                    res = Math.Max(res, li.Sum());
                }

            }
            Console.WriteLine(res < 0 ? 0 : res);

        }


        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RArSt(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RArInt(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RArLong(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RArDouble(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}


Measured memory_bytes: 15456
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define eb emplace_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef vector<char> vc;
typedef vector<vector<char> > vvc;
typedef vector<double> vd;
typedef vector<vector<double> > vvd;
template<class T> using vv=vector<vector< T > >;
typedef deque<int> di;
typedef deque<deque<int> > ddi;

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

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

int main() {
    int n;
    cin >> n;
    vi a(n);
    rep (i, n) { cin >> a[i]; }
    ll ans = 0;
    rep (i, n) {
        if ( a[i] >= 3 ) {
            int r;
            if ( a[i] % 2 == 0 ) {
                r = 2;
            } else {
                r = 1;
            }
            ans += (a[i] - r) / 2;
            a[i] = r;
        }
    }
    ll temp = 0;
    int ptr = 0;
    while ( ptr < n ) {
        if ( a[ptr] == 0 ) {
            ans += temp / 2;
            temp = 0;
        } else {
            temp += a[ptr];
        }
        ptr += 1;
    }
    ans += temp / 2;
    printf("%lld\n", ans);

    return 0;
}


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

int main(void){

   int X,Y,Z,sum=0,ans=1;
   cin >> X >> Y >> Z;
   
   sum += (Y + 2 * Z);
   while(1){
       if(sum + (Y + Z) > X) break;
       sum += (Y + Z);
       ans++;
   }
   cout << ans << endl;
}

Measured memory_bytes: 3636