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

using namespace std;

const int INF=100000000;

int main(){

	int m;
	cin>>m;
	for(int v = 0; v < m; v++){
		int n;
		cin>>n;
		string str;
		cin>>str;

		int pos=0;
		int cost=0;
		for(int i = 0; i <= 2*n; i+=2){
			if(i==0){
				bool b=false;
				if(str[i]=='Y'){
					cost+=1;
					pos=n+1;
					b=true;
				}
				if(str[2*n]=='Y'){
					if(!b)
						cost+=3;
					else
						cost+=2;
					pos=3*n+3;
				}
			}
			else if(i==2*n){
				if(pos!=0){
					if(str[4*n-1]=='Y'){
						if(pos>=3*n+3&&pos<=4*n+3){
							cost+=(4*n+3-pos)*2+2;
						}
						else{
							cost+=(4*n+3-(pos+2*n+2))*2+2;
						}
						pos=4*n+3;
					}
					if(str[2*n-1]=='Y'){
						if(pos>=n+1&&pos<=2*n+1){
							cost+=(2*n+1-pos)*2+2;
						}
						else{
							cost+=(2*n+1-(pos-2*n-2))*2+2;
						}
						pos=2*n+1;
					}
				}
				else{
					bool b=false;
					if(str[2*n-1]=='Y'){
						cost+=2*n+1;
						b=true;
						pos=2*n+1;
					}
					if(str[4*n-1]=='Y'){
						if(!b)
							cost+=2*n+3;
						else
							cost+=2;
						pos=4*n+3;
					}
				}
			}
			else{
				if(pos!=0){
					if(str[2*n+i]=='Y'||str[2*n+i-1]=='Y'){
						if(pos>=3*n+3&&pos<=4*n+3){
							cost+=(3*n+3+i/2-pos)*2+2;
						}
						else{
							cost+=(3*n+3+i/2-(pos+2*n+2))*2+2;
						}
						pos=3*n+3+i/2;
					}
					if(str[i-1]=='Y'||str[i]=='Y'){
						if(pos>=n+1&&pos<=2*n+1){
							cost+=(n+1+i/2-pos)*2+2;
						}
						else{
							cost+=(n+1+i/2-(pos-2*n-2))*2+2;
						}
						pos=n+1+i/2;
					}
				}
				else{
					bool b=false;
					if(str[i-1]=='Y'||str[i]=='Y'){
						cost+=i+1;
						pos=n+1+i/2;
						b=true;
					}
					if(str[2*n+i]=='Y'||str[2*n+i-1]=='Y'){
						if(!b)
							cost+=i+3;
						else
							cost+=2;
						pos=3*n+3+i/2;
					}
				}
			}
		}

		if(pos>=3*n+3&&pos<=4*n+3){
			cost+=(4*n+3-pos)*2+3;
		}
		else{
			cost+=(4*n+3-(pos+2*n+2))*2+2;
		}

		cout<<(cost)/2<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
function Main(input) {
    var N = parseInt(input[0], 10);
    var S = input[1];
    var sList = S.split('');
    
    var alp = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    var list = alp.split('');

    var result = [];

    for (var i = 0; i < S.length; i++) {
        var index = list.indexOf(sList[i]) + N;
        if (index > 25) {
            index = index - 26;
        }
        result.push(list[index]);
    }

    console.log(result.join(''));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));

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


using LL = long long int;
using uLL = unsigned long long int;
using uint = unsigned int;
using ld = long double;

const int N = 3007;
ld p[N];
ld dp[N][N];

int main(){
    cin.tie(NULL);
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> p[i];
    }
    dp[0][0] = 1;
    for(int i = 1; i <= n; i++){
        dp[i][0] = dp[i-1][0]*(1-p[i]);
        for(int j = 1; j <= i; j++){
            dp[i][j] = dp[i-1][j]*(1-p[i])+dp[i-1][j-1]*p[i];
        }
    }
    ld ans = 0;
    for(int i = n/2+1; i <= n; i++){
        ans += dp[n][i];
    }
    cout << fixed  << setprecision(10) << ans << '\n';
    
    
    return 0;
}

Measured memory_bytes: 139776
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ll long long
typedef pair<int,int> par;
typedef vector<int> vct;
typedef vector<par> vp;
const ll mn=-1e18,mx=1e18;
const int mod=1e9+7;
int color[100007],n,m,f=1,dis[100007];
vp HMS[100007];
void dfs(int u)
{
	for(int i=0;i<HMS[u].size();i++)
	{
		int v=HMS[u][i].fi;
		int w=HMS[u][i].se;
		if(dis[v]==mod)
		{
			dis[v]=dis[u]+w;
			dfs(v);
		}
		else if(dis[v]!=dis[u]+w)
		{
			f=0;
		}
	}
}
int main()
{
	cin>>n>>m;
	while(m--)
	{
		int u,v;
		int w;
		cin>>u>>v>>w;
		HMS[u].pb(mp(v,w));
		HMS[v].pb(mp(u,-w));
	}
	for(int i=1;i<=n;i++)
	{
		dis[i]=mod;
	}
	for(int i=1;i<=n;i++)
	{
		if(dis[i]==mod)
		{
			dis[i]=0;
			dfs(i);
		}
	}
	if(f) cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 15324
#include<iostream>
#include<vector>
using namespace std;
const int Nmax = 100001;
int N, A[Nmax];

int main(){
  int paired[Nmax];
  int ans = 0;
  cin >> N;
  for(int i=1; i<=N; i++){
    cin >> A[i];
    paired[i] = 0;
  }

  for(int i=1; i<=N; i++){
    if(paired[i] == 0 && A[A[i]] == i){
      paired[i] = 1;
      paired[A[i]] = 1;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;
#define MAX_N 100010

string S;

signed main()
{
    cin >> S;
    string ans = "AKIHABARA";
    string cand = "";
    int ans_i = 0, s_i = 0;
    for(;;) {
        if(ans_i >= ans.length()) {
            if(s_i < S.length()) {
                cand += S[s_i];
                s_i++;
                continue;
            }
        }
        if(s_i >= S.length()) { break; }
        if(ans[ans_i] != S[s_i] && ans[ans_i] == 'A') {
            cand += "A";
            ans_i++;
        }
        else if(ans[ans_i] == S[s_i]) {
            cand += ans[ans_i];
            ans_i++; s_i++;
        }
        else {
            printf("NO\n");
            return 0;
        }
    }
    if(cand == ans || cand + 'A' == ans) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }


    return 0;
}


Measured memory_bytes: 256
import collections
n,m = list(map(int,input().split()))
ans = [0]*n
graph = [[] for _ in range(n)]
for i in range(m):
    a,b = list(map(int,input().split()))
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
D = collections.deque([0])
visited = [False]*n
visited[0]=True

while D:
    v = D.popleft()
    for i in graph[v]:
        if visited[i]:continue
        visited[i]=True
        ans[i]=v
        D.append(i)
print("Yes")
for i in ans[1:]:
    print(i+1)

Measured memory_bytes: 35644
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
// #define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    vi p(n);
    rep(i,n)cin>>p[i];
    int ans=0;
    Rep(i,1,n-1){
        ans+=(p[i-1]<p[i]&&p[i]<p[i+1])||(p[i-1]>p[i]&&p[i]>p[i+1]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
//#pragma GCC diagnostic error "-std=c++11"
#include<bits/stdc++.h>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,b,a) for(int i=b;i>=a;--i)
#define gcd(a,b) __gcd(a,b)
#define MEM(a,x) memset(a,x,sizeof(a))
#define VI vector<int>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
const int N=2e5+5;
template<class T>inline void read(T &res)
{
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
int k,n,ans,a[N];
int main(){
    cin>>k>>n;
    rep(i,1,n){
        read(a[i]);
    }
    ans=INF;
    rep(i,1,n){
        if(i==1)
        ans=min(ans,min(a[n]-a[i],k-(a[i+1]-a[i])));
        else if(i==n)
        ans=min(ans,min(a[n]-a[1],k-(a[n]-a[n-1])));
        else ans=min(ans,min(k-(a[i]-a[i-1]),k-(a[i+1]-a[i])));
    }
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
n,*d=map(int,open(0).read().split())
mod=998244353
c=[0]*(max(d)+1)
for i in d:
  c[i]+=1
ans=1
if (not c[0]==1) or (not d[0]==0):
  print(0)
  exit()
for i in range(max(d)):
  ans*=pow(c[i],c[i+1],mod)
  ans%=mod
print(ans)

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

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int gcd(int a,int b){
  while(b!=0){
    a%=b;
    swap(a,b);
  }
  return a;
}

int kaizyou(int N){
  int num=1;
  for(int i=1;i<=N;i++){
  num*=i;
  }
  return num;
}

int dy[]={1,0};
int dx[]={0,1};

signed main() {
  string s;
  cin >> s;
  if(s.at(2)==s.at(3)&&s.at(4)==s.at(5)){
    cout << "Yes" <<endl;
  }
  else{
    cout << "No" << endl;
  }
  
}

  
  
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
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; }
const long double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	int A[N], B[N];
	rep(i,N) cin >> A[i] >> B[i];
	int cnt = 0;
	for(int i=N-1;i>=0;i--){
		A[i] += cnt;
		cnt += ((A[i]/B[i]+1)*B[i]-A[i])%B[i];
	}
	cout << cnt << endl;
}

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

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

int N, D;
vector<int> C;
vector<vector<int>> S;

int ans_score;
vector<int> ans;

void Read(bool local = false) {
  N = 26;
  if (local) {
    D = 365;
  } else {
    cin >> D;
  }
  C.resize(N);
  for (int i = 0; i < N; i++) {
    if (local) {
      C[i] = rnd() % 100;
    } else {
      cin >> C[i];
    }
  }
  S.resize(D);
  for (int i = 0; i < D; i++) {
    S[i].resize(N);
    for (int j = 0; j < N; j++) {
      if (local) {
        S[i][j] = rnd() % 20000;
      } else {
        cin >> S[i][j];
      }
    }
  }
  ans.assign(D, 0);
}

void Write() {
  for (auto i : ans) {
    cout << i + 1 << "\n";
  }
}

int Arithmetic(int n) {
  return n * (n - 1) / 2;
}

vector<set<int>> Build(vector<int> a) {
  vector<set<int>> occ(N);
  for (int i = 0; i < D; i++) {
    occ[a[i]].insert(i);
  }
  for (int i = 0; i < N; i++) {
    occ[i].insert(-1);
    occ[i].insert(D);
  }
  return occ;
}

int Evaluate(vector<int> a) {
  vector<int> last(N, -1);
  int score = 0;
  for (int i = 0; i < D; i++) {
    score += S[i][a[i]];
    last[a[i]] = i;
    for (int j = 0; j < 26; j++) {
      score -= C[j] * (i - last[j]);
    }
  }
  return score;
}

int Evaluate(int init_score, const vector<int> &a, const vector<set<int>> &occ, int d, int q) {
  if (a[d] == q) return init_score;
  const set<int> &cur = occ[a[d]];
  auto pos = cur.lower_bound(d);
  int lst = *prev(pos);
  int nxt = *next(pos);

  int score = init_score;
  score += C[a[d]] * (Arithmetic(nxt - d) + Arithmetic(d - lst) - Arithmetic(nxt - lst));

  pos = occ[q].upper_bound(d);
  lst = *prev(pos);
  nxt = *pos;
  score -= C[q] * (Arithmetic(nxt - d) + Arithmetic(d - lst) - Arithmetic(nxt - lst));

  score -= S[d][a[d]];
  score += S[d][q];

  return score;
}

void Change(int &init_score, vector<int> &a, vector<set<int>> &occ, int d, int q) {
  int new_score = Evaluate(init_score, a, occ, d, q);
  init_score = new_score;
  occ[a[d]].erase(d);
  a[d] = q;
  occ[a[d]].insert(d);
}

void Solve(int t) {
  ans_score = Evaluate(ans);

  vector<int> a(D);
  for (int i = 0; i < D; i++) {
    a[i] = (t == 0 ? i % N : rnd() % N);
  }
  int score = Evaluate(a);
  vector<set<int>> occ = Build(a);

  double temp = 50000;
  double cooling_rate = 0.99997;
  double absolute_zero = 0.001;

  while (temp > absolute_zero) {
    int d = rnd() % D;
    int q = rnd() % N;
    int delta = Evaluate(score, a, occ, d, q) - score;
    if (delta > 0 || exp(delta / temp)) {
      Change(score, a, occ, d, q);
      if (t > 0 && score > ans_score) {
        ans = a;
        ans_score = score;
      }
    }
    temp *= cooling_rate;
  }
  if (ans_score < score) {
    ans = a;
  }
}

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

  Read();
  for (int rep = 0; rep < 10; rep++) {
    Solve(rep);
  }
  Write();
  // cerr << Evaluate(ans) << "\n";
  return 0;
}


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

typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
 
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;

int n;
ll dp[101][4][4][4];
int main() {
    cin >> n;

    int A = 0;
    int C = 1;
    int G = 2;
    int T = 3;
    // initialize
    for (int i=0;i<4;i++) {
        for (int j=0;j<4;j++) {
            for (int k=0;k<4;k++) {
                if (i == A && j == G && k == C) continue;
                if (i == A && j == C && k == G) continue;
                if (i == G && j == A && k == C) continue;
                dp[3][i][j][k] = 1;
            }
        }
    }
    // DP
    for (int i=3;i<n;i++) {
        for (int m=0;m<4;m++) {
            for (int j=0;j<4;j++) {
                for (int k=0;k<4;k++) {
                    for (int l=0;l<4;l++) {
                        if (j == A && k == G && l == C) continue;
                        if (j == A && k == C && l == G) continue;
                        if (j == G && k == A && l == C) continue;
                        if (m == A && k == G && l == C) continue;
                        if (m == A && j == G && l == C) continue;
                        dp[i+1][j][k][l] += dp[i][m][j][k];
                        dp[i+1][j][k][l] %= mod;
                    }
                }
            }   
        }
    }

    ll ans = 0;
     for (int i=0;i<4;i++) {
        for (int j=0;j<4;j++) {
            for (int k=0;k<4;k++) {
                ans += dp[n][i][j][k];
                ans %= mod;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<iomanip>

#define PI 3.14159265358979323846264338

//鈍角鋭角で鋭角じゃないとダメ
int main(){
    int a = 0;
    int b = 0;
    int h = 0;
    int m = 0;

    std::cin >> a >> b >> h >> m;

    double h_angle = 30 * h + 0.5 * m;
    double m_angle = 6 * m;
    double angle = std::max(std::abs(h_angle - m_angle), 360 - std::abs(h_angle - m_angle));

    double c = std::sqrt(a * a + b * b - 2 * a * b * std::cos(angle * PI / 180));

    std::cout << std::fixed << std::setprecision(20) << c << std::endl;

    return 0;
}

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

const double pi  = 2 * acos(0.0);
const double eps = 1e-8;

#define REP(i,a,b) for(int i=(a); i<(b);++i)
#define rep(i,n) REP(i,0,n)
#define INF (1<<29)
#define INFLL (1L<<62LL)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef int Cost;
struct Edge {
  int src, dst; Cost cost;
  Edge(int s, int d, Cost c) : src(s), dst(d), cost(c) {}
};
typedef vector<Edge>  Edges;
typedef vector<Edges> Graph;
typedef vector<Cost>  Array;
typedef vector<Array> Matrix;

int dx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(void) {
  ios_base::sync_with_stdio(false); cin.tie(0);
  string e, o;
  cin >> o >> e;

  int max_size = max(o.size(), e.size());
  for (int i = 0; i < max_size; i++) {
    if (i < o.size()) cout << o[i];
    if (i < e.size()) cout << e[i];
  }

  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
const ll mod = 1e9 + 7;
const ll inf = 9223372036854775807;


ll arr[3000], memo[3000][3000], bl[3000][3000], maxi, n, ans, dif, sum;

ll dp(ll x, ll y){
	ll depan = 0;
	ll belakang = 0;
	if (x == y){
		return arr[x];
	}
	if (x > y){
		return 0;
	}
	if (bl[x][y] == 1){
		return memo[x][y];
	}
	bl[x][y] = 1;
	depan = arr[x] + min(dp(x+2, y), dp(x+1, y-1));
	belakang = arr[y] + min(dp(x, y - 2), dp(x+1, y-1));
	memo[x][y] = max(depan, belakang);
	return memo[x][y];
}

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

	cin >> n;
	for (ll i = 1; i <= n; i++){
		cin >> arr[i];
		sum += arr[i];
	} 
	ans = dp(1, n);
	dif = sum - ans;
	dif = ans - dif;
	cout << dif << '\n';
}
  

Measured memory_bytes: 139904
from sys import stdin
from sys import setrecursionlimit
import math
setrecursionlimit(10 ** 7)

n = int(input())
s = [input() for _ in range(n)]

a = s.count("AC")
b = s.count("WA")
c = s.count("TLE")
d = s.count("RE")

print("AC x {}".format(a))
print("WA x {}".format(b))
print("TLE x {}".format(c))
print("RE x {}".format(d))

Measured memory_bytes: 16216
a,b,c,d = str(input())

if 1<=int(a+b)<=12 and 1<=int(c+d)<=12:
  print("AMBIGUOUS")
elif 1<=int(a+b)<=12: 
  print("MMYY")
elif 1<=int(c+d)<=12: 
  print("YYMM")
else:
  print("NA")


Measured memory_bytes: 2940
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

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

int main() {

	int n, m;
	int k[1234];

	scanf("%d %d", &n, &m);

	REP(i, m) scanf("%d", &k[i]);

	vector<int> c;

	REP(i, 2 * n) c.push_back(i + 1);

	REP(i, m) {
		vector<int> next;
		if (k[i] == 0) {
			REP(j, 2 * n) {
				if (j % 2) {
					next.push_back(c[n + j / 2]);
				}
				else {
					next.push_back(c[j / 2]);

				}
			}
		}
		else {
			REP(j, 2 * n) {
				next.push_back(c[(k[i] + j) % (2 * n)]);
			}
		}
		c = next;
	}

	REP(i, 2 * n) printf("%d\n", c[i]);

	return 0;
}

Measured memory_bytes: 2756
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

struct Node {
    int idx;
    string text;
    vector<Node*> children;
    Node(int idx,string text) :
        idx(idx),text(text){}
    ~Node() {
        for(auto child : children) {
            delete child;
        }
    }
};

Node* find(Node *node,int idx) {
    if(node->idx==idx) return node;
    for(auto child : node->children) {
        return find(child, idx);
    }

    return nullptr;
}

void print(Node *node, int indent) {
    cout<<string(indent,'.');
    cout<<node->text<<endl;
    for(auto child : node->children) {
        print(child,indent+1);
    }
}


int n;
void solve() {
    Node *root;
    map<int,Node*> nodes;
    rep(i,n) {
        int k;
        string m;
        cin>>k>>m;
        if(k==0) {
            root=new Node(i,m);
            nodes[0]=root;
        }
        else {
            k--;
            Node *node=nodes[k];
            nodes[i]=new Node(i,m);
            //cout<<node->text<<", "<<node->idx<<endl;
            node->children.push_back(nodes[i]);
        }
    }
    print(root,0);
}
int main() {
    while(cin>>n) {
        if(n==0) break;
        solve();
    }
    return 0;
}

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

ll f(ll h) { return h ? f(h >> 1) * 2 + 1 : 0; }

int main() {
  ll h;
  cin >> h;
  cout << f(h) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String Nstr = sc.nextLine();
        String S = sc.nextLine();

        int N = Integer.parseInt(Nstr);
        String a = "";
        String b = "";

        for( int i = 0; i < N; i++ ) {
        	if( i < N / 2 ) {
        		a += S.substring(i,i+1);
        	}else {
        		b += S.substring(i,i+1);
        	}
        }
        if(a.equals(b)) {
        	System.out.println("Yes");
        }else {
        	System.out.println("No");
        }
    }
}

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

using namespace std;

typedef long long ll;
typedef vector<int> pi;
typedef pair<int,int> vi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(vi c, vi d){
	return c.S < d.S;
}

int main() {
	ll H, h1;
	cin >> H;
	h1 = H;
	ll c=0, n = 0;
	while(h1 > 0){
		h1 >>= 1;
		n <<= 1;
		n|=1;
		++c;
	}
	//cout << n << " " << pow(2, c+1);
	cout << n << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
using ll = long long;
using namespace std;
int main() {
	bool p =true;
	ll n;
	cin>>n;
	ll a[110000];
	rep(i,0,n)cin>>a[i];
	sort(a,a+n);
	if(n%3==0){
		if(a[0]!=a[n/3-1] || a[n/3]!=a[2*n/3-1] || a[2*n/3]!=a[n-1])p=false;
		ll fuck=a[2*n/3]^a[0];
		if(a[n/3]!=fuck) p=false;
	}
	else if(a[n-1]==0 && n%3!=0) p=true;
	else p=false;

	if(p)cout<<"Yes";
	else cout<<"No";


}
















Measured memory_bytes: 1024
#import collections
#aa = collections.Counter(a) # list to list
def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
    x,y = readInts()
    now = x
    cnt = 0
    while now <= y:
        now *= 2
        cnt += 1
    print(cnt)



if __name__ == '__main__':
  main()


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

typedef long long ll;

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

    int a[3],ma,mid,mi,ans=0;
    for(int i=0;i<3;i++) cin >> a[i];
    sort(a,a+3);
    ma = a[2]; mid = a[1]; mi = a[0];
    ans += ma - mid;
    mi += ma - mid;
    if(mi%2==ma%2) ans += (ma-mi)/2;
    else ans += (ma-mi)/2 + 2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    string a,b,c;
    cin >> a >> b >> c;
    int na,nb;
    na = a.length();
    nb = b.length();
    if(a[na-1] == b[0] && b[nb-1] == c[0]) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=1e6+5;
int tab[MAXN];

bool solve(string s,int a,int b){
	for(int i=0;i<a;i++)
		if(s[i]=='-')
			return false;
	if(s[a]!='-') return false;
	for(int i=a+1;i<a+b+1;i++)
		if(s[i]=='-')
			return false;
	return true;
}

int main(){
    ios::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);
    int a,b;
    string s;
    cin >> a >> b >> s;
    cout << (solve(s,a,b) ? "Yes" : "No");
}


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

using namespace std;

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

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

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

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int n;
vl a;
int main() {
    cin>>n;//n+1はn=1
    a.resize(n+1);
    REP(i,n) cin>>a[i];

    a[n] = a[0];

    vl mts;

    ll x=0; //even only
    FORR(i,0,n){
        if((i+1)%2)
            x+=a[i];//odd
        else
            x-=a[i];//even
    }
    mts.emplace_back(x);

    FOR(i,0,n-1){
        x = mts[mts.size()-1];
        mts.emplace_back((a[i]-x/2)*2);
    }

    //DEBUG_VEC(mts);

    REP(i,mts.size()){
        cout << mts[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3060
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
char in[110];
int main(){
	int a;scanf("%d",&a);
	scanf("%s",in);
	int p=0;
	int q=0;
	for(int i=0;i<a;i++){
		if(in[i]=='R')p++;
		else q++;
	}
	if(p>q)printf("Yes\n");else printf("No\n");
}

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

int main() {
  long X, K, D;
  cin >> X >> K >> D;
  X = abs(X);
  if ((double long) K * D <= X) return cout << X - K * D << "\n", 0;
  long NX = X % D;
  long NK = K - X / D;
  cout << ((NK % 2) ? D - NX : NX) << "\n";
}

Measured memory_bytes: 3592
#include<iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;

long long mul(long long x,long long y){
    long long mod = 1000000007;
    return ((x % mod) * (y % mod)) % mod;
}
long long modinv(long long x, long long y) {
    long long mod = 1000000007;
    long long b = mod, u = 1, v = 0;
    while (b) {
        long long t = y / b;
        y -= t * b;
        swap(y, b);
        u -= t * v;
        swap(u, v);
    }
    u %= mod;
    if (u < 0) u += mod;
    return ((x % mod) * u) % mod;
}

int main(){

    long long x,y;
    long long n;
    long long d;
    long long ans = 1;

    cin >> x >> y;
    if((x + y) % 3 == 0 && x*2 >= y  && x <= y*2){
        n = (x + y)/3;
        d = (n - abs(x-y)) /2 ;
        for(int i = 0;i<d;i++){
            ans = mul(ans,n-i);
        }
        for(int i = 0;i<d;i++){
            ans = modinv(ans,d-i);
        }
        cout << ans << endl;
    }else{
        cout << "0" << endl;
    }
}

Measured memory_bytes: 256
a,b,c,x,y=map(int,input().split())
ans=1000000000
for i in range (0,(max(x,y)*2+1),2):#abピザを何枚買ったか考える。偶数枚しかありえないことに注意
  price=c*i+a*(max(0,(x-int(i/2))))+b*(max(0,(y-int(i/2))))
  ans =min(price,ans)
  #abピザの枚数が決まると残りは単品による購入となるので、
  #自動的に購入枚数は決定する。O(n)全探索で済むので間に合う。
  
print(ans)

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

template <size_t T>
bool prevSubset(bitset<T>& bs, const bitset<T>& mask)
{
    bs = bs.to_ulong() - 1ull;
    bs &= mask;
    if(bs.none())
        return false;
    return true;
}

const int INF = INT_MAX / 2;

int main()
{
    int n;
    cin >> n;
    vector<int> v(3);
    for(int i=0; i<3; ++i)
        cin >> v[i];
    vector<int> l(n);
    for(int i=0; i<n; ++i)
        cin >> l[i];

    vector<vector<int> > cost(3, vector<int>(1<<n));
    for(int a=1; a<(1<<n); ++a){
        bitset<32> bs(a);
        int sum = 0;
        for(int i=0; i<n; ++i){
            if(bs[i])
                sum += l[i];
        }
        for(int i=0; i<3; ++i)
            cost[i][a] = abs(sum - v[i]) + (bs.count() - 1) * 10;
    }

    vector<int> dp(1<<n, INF);
    dp.back() = 0;
    for(int i=0; i<3; ++i){
        vector<int> nextDp(1<<n, INF);
        for(int a=1; a<(1<<n); ++a){
            bitset<32> mask(a);
            bitset<32> bs = mask;
            do{
                int b = (mask ^ bs).to_ulong();
                nextDp[b] = min(nextDp[b], dp[a] + cost[i][bs.to_ulong()]);
            }while(prevSubset(bs, mask));
        }
        dp = move(nextDp);
    }
    int ans = *min_element(dp.begin(), dp.end());
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var (
		c, n int
		s    string
	)
	fmt.Scan(&n)
	fmt.Scan(&s)
	c = 1
	for i := 0; i < n-1; i++ {
		if s[i] != s[i+1] {
			c++
		}
	}
	fmt.Println(c)
}


Measured memory_bytes: 1280
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int res=0,N,L,x,y;
  priority_queue<int,vector<int> > que;
  cin >> N;
  REP(i,2*N){
    cin >> L;
    que.push(L);
  }
  REP(i,N){
    x = que.top();que.pop();
    y = que.top();que.pop();
    res += min(x,y);
  }
  cout << res << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

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



Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

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

typedef long long ll;

const int Inf = 100100100;
const double EPS = 1e-9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    char c;  cin >> c;
    if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
      cout << "vowel" << endl;
    } else {
      cout << "consonant" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
// C - Candies
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
int in(){int x;scanf("%d",&x);return x;}
int A[2][101],ans;

int main(){
	int N=in();
	rp(i,0,2) rp(j,1,N+1) A[i][j] = A[i][j-1] + in();
	rp(i,1,N+1) ans = max(ans, A[0][i] + A[1][N] - A[1][i-1]);
	printf("%d\n",ans);
}

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

bool checkMonth(string s){
  int n = stoi(s);
  if (n>=1&&n<=12) return true;
  else return false;
}

int main() {
  int n,k;
  cin >> n >> k;
  double prob = 0.0;
  rep(i,n){
    int a = i+1;
    double iprob = 1.0;
    while (true){
      if (a>=k) break;
      a *= 2;
      iprob /= 2.0;
    }
    prob += iprob;
  }
  prob /= n;
  
  cout << std::setprecision(12) << prob << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;
typedef long long int ll;
 
//typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 

 
const ll N = 100005;
const ll mod = 10e8+7;
const long long int inf = 10000000000;
#define pp pair<ll,ll>

typedef long double ld;
typedef vector<pp> vpl;
#define MP make_pair
#define endl "\n"
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define repb(i,n) for(ll i=1;i<n-1;i++) 
#define trace(i,a) for(auto i=a.begin();i!=a.end();i++) 
#define mtrace(i,a) for(auto i=a.begin();i!=a.end();i++)  cout<<i->first<<" "<<i->second<<endl;   
 
const ld pi = 3.14159265359;

mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}

 
void fastIO(void);
void decimal(int);
ll modmulti(ll, ll);
ll modadd(ll, ll);
ll modpower(ll, ll);
ll gcd(ll, ll );
ll modinv(ll);


int main()
{
	
	ll n,m;
	cin>>n>>m;
	ll ans = n*(n-1)/2;
	ans += m*(m-1)/2;
	cout<<ans<<endl;


}


	


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
void fastIO(void)
{  ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
}
 
void decimal(int n){
   cout<<fixed;
   cout<<setprecision(n);
}
ll modmulti(ll a, ll b){
   return ((a%mod)*1ll*(b%mod))%mod;
}
ll modadd(ll a, ll b){
   ll asdfgh =  ((a%mod)+(b%mod)+mod+mod)%mod;
   asdfgh = (asdfgh+mod)%mod;
   return asdfgh;
}
ll modpower(ll a, ll n){
   if(n==0) return 1;
   if(n==1) return a%mod;
   ll b = modpower(a,n/2);
   b = modmulti(b,b);
   if(n%2==0) return b;
   return modmulti(a,b);
}
ll gcd(ll a, ll b){
   if(b==0)
      return a;
   return gcd(b,a%b);
}
ll modinv(ll a){
   return modpower(a,mod-2);
}

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

int main(void){
    double a,b;
    scanf("%lf %lf",&a,&b);
    if(a>b)printf("GREATER\n");
    else if(a<b)printf("LESS\n");
    else printf("EQUAL\n");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <stack>
#include <deque>
#include <memory.h>
#include <cassert>
#include <ctime>
#include <climits>
#include <list>
#include <time.h>
#include <unordered_map>
#include <bitset>
#include <exception>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define INPUT "/Users/bekhzodsoliev/Desktop/C++/cp/cp/file.in"
#define OUTPUT "/Users/bekhzodsoliev/Desktop/C++/cp/cp/file.out"
#define lc v << 1
#define rc (v << 1) + 1
#define inf 1e+9
#define linf ll(1e+18)
#define dinf 1e+14

set<string> v;

void solve()
{
    string s;
    cin >> s;
    int n = (int) s.length();
    
    int K;
    cin >> K;
    
    for(int l = 1; l <= K; l++)
    {
        for(int i = 0; i + l - 1 < n; i++)
        {
            int j = i + l - 1;
            string temp = "";
            for(int x = i; x <= j; x++)
            {
                temp += s[x];
            }
            v.insert(temp);
        }
    }
    
    while(K-- > 1)
    {
        v.erase(v.begin());
    }
    
    cout << *v.begin();
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0);
    //freopen(INPUT, "r", stdin);freopen(OUTPUT, "w", stdout);
    int t = 1;
    //cin >> t;
    
    while(t--)
    {
        solve();
    }
    
    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll a,b,c;
    cin >> a >> b >> c;
    if(a+b+c>=22) cout << "bust" << endl;
    else cout << "win" << endl;
}


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

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

    bool ans = false;
    for(int i=0; i<s.size(); i++){
        if(s.at(i) != t.at(i))  ans = true;
    }

    if(ans) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    set<int> st;
    string ans = "YES";
    REP(i,N){
        int A;
        cin >> A;
        if(st.find(A) != st.end()) ans = "NO";
        st.insert(A);
    }
    cout << ans << endl;
}


Measured memory_bytes: 9728
#include <cstdio>
int h, w, fl=1;
char a[55][55];
int main() {
	int i, j;
	scanf("%d%d", &h, &w);
	for(i=1; i<=h; i++) for(j=1; j<=w; j++) a[i][j] = '.';
	for(i=1; i<=h; i++) scanf("%s", &a[i][1]);
	for(i=1; i<=h; i++) for(j=1; j<=w; j++) {
		if(a[i][j]=='#' && a[i-1][j]=='.' && a[i+1][j]=='.' && a[i][j-1]=='.' && a[i][j+1]=='.') fl=0;
	}
	puts(fl ? "Yes":"No");
	return 0;
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>  
#include <stdbool.h>   
#define inf (INT_MAX-1)
#define INF 9223372036854775807;
#define PI 3.14159265358979323846;
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
/*
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r)
*/
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r)
#define TYPE long long
#define ll long long
#define MEMSET(a) memset(a,0,sizeof(a))
#define MEMSET_U(a) memset(a,-1,sizeof(a))
#define bool    _Bool
const int mod = (int)1e09 + 7;

//#define DEBUG1
//#define DEBUG2
//#define DEBUGF
#define DUMMY

int in(void) { int i; scanf("%d", &i); return i; }
long long llin(void) { long long i; scanf("%lld", &i); return i; }
double din(void) { double i; scanf("%lf", &i); return i; }
void chin(char s[]) { scanf("%s", s); }

void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void dprint(double a) { printf("%.10f\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }
int Max(int a, int b) { if (a > b) { return a; }return b; }
int Min(int a, int b) { if (a < b) { return a; }return b; }
long long llmax(long long a, long long b) { return a > b ? a : b; }
long long llmin(long long a, long long b) { return a < b ? a : b; }
double dmax(double a, double b) { return a > b ? a : b; }
double dmin(double a, double b) { return a < b ? a : b; }
//long long llmax(long long a, long long b) { return a > b ? a : b; }
//long long llmin(long long a, long long b) { return a < b ? a : b; }
//double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int char_cmp(const void *a, const void *b) { return strcmp((char *)a, (char *)b); }
int char_cmp_r(const void *a, const void *b) { return strcmp((char *)b, (char *)a); }
void swap(int *a, int *b) { int t = *a; *a = *b; *b = t; }


char S[52], T[52];

int main() {
	int i, k, l, m, n, o;

	scanf("%s%s", S, T);

	int slen = strlen(S);
	int tlen = strlen(T);
	//ans作成
	//for (i = 0; i < slen; i++) {
	//	ans[i] = S[i];
	//}


	//for (k = 0; k <= slen - tlen; k++) {
	for (k = slen - tlen; k >= 0; k--) {
		for (l = 0; l < tlen; l++) {
			if (T[l] != S[l + k] && S[l + k] != '?') {
				break;
			}
		}
		if (l == tlen) {
			break;
		}
	}
	if (k == -1) {
		puts("UNRESTORABLE");
	}
	else{
		for (m = 0; m < tlen; m++) {
			S[m + k] = T[m];
		}
		for (n = 0; n < slen; n++) {
			if (S[n] == '?') {
				S[n] = 'a';
			}
		}
		printf("%s\n", S);
	}

#ifdef DEBUGF
	getch();
#endif
	return 0;
}


Measured memory_bytes: 128
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<cstdint>
#include<cstddef>
#include<vector>
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using usize = uint_fast64_t;
#define rep(i, n) for (usize i = 0; i < (usize)(n); i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64,i64>;
template <typename T>
class UnionFind
{
public:
    vector<T> par;
    UnionFind(T n) : par(n, -1) {}
    void init(T n)
    {
        for (usize i = 0; i < n; i++)
        {
            par[i] = -1;
        }
    }

    i64 root(T x)
    {
        if (par[x] < 0)
            return x;
        else
            return par[x] = root(par[x]);
    }

    bool same(T x, T y)
    {
        return root(x) == root(y);
    }

    bool merge(T x, T y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        if (par[x] > par[y])
            swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    i64 size(T x)
    {
        return -par[root(x)];
    }
};
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
i64 n,m;
cin >> n >> m;
i64 ans = 0;
vector<i64> a(m),b(m);
rep(i,m){
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
}
rep(i,m){
   UnionFind uft(n);
   rep(j,m){
       if(i == j)continue;
       uft.merge(a[j],b[j]);
   }
   bool flag = true;
   rep(j,n){
       if(uft.size(j) != n)flag = false;
   }
   if(!flag)ans++;
}
cout << ans << endl;
}

Measured memory_bytes: 3592
a = []
b = []
c = []
li = []
li2 = []
for i in range (3):
    if i == 0:
        a = list(map(int, input().split(' ')))
    if i == 1:
        b = list(map(int, input().split(' ')))
    if i == 2:
        c = list(map(int, input().split(' ')))
li = a
li.extend(b)
li.extend(c)
li = sorted(li)
for s in range (4):
    li2.append(li.count(s+1))

li2 = sorted(li2)
if li2 == [1, 1, 2, 2]:
    print('YES')
else:
    print('NO')


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

const int MAX_N = 20;
int N;
int a[MAX_N], b[MAX_N], c[MAX_N];

void solve() {
    int ans = 0;
    int prev = 0;

    for(int i = 0; i < N; i++) {
        // i番目にxを食べる
        int x = a[i];
        ans += b[x-1];
        if(prev == x-1) ans += c[prev-1];
        prev = x;
        //cout << x << " " << prev << " " << ans << endl;
    }

    cout << ans << "\n";
    return ;
}

int main() {
    cin >> N;
    for(int i = 0; i < N; i++) cin >> a[i];
    for(int i = 0; i < N; i++) cin >> b[i];
    for(int i = 0; i < N - 1; i++) cin >> c[i];
    //for(int i = 0; i < N - 1; i++) cout << a[i] << " " << b[i] << " " << c[i] << endl;
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<ll> v(n);
    for(auto& i : v){
        cin >> i;
    }
    ll ans = v[0];
    for(auto i : v){
        ans = __gcd(ans, i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;

int main()
{
    int N, K;
    cin >> N >> K;
    ll R, S, P;
    cin >> R >> S >> P;
    string T;
    cin >> T;

    int r = 0, s = 0, p = 0;
    vector<bool> rsp(N, false);
    ll ans = 0;
    rep(i, N) {
        if (i >= K && T[i] == T[i - K]) {
            if (rsp[i - K]) continue;
            if (T[i] == 'r') ans += P;
            else if (T[i] == 's') ans += R;
            else ans += S;
            rsp[i] = true;
        }
        else {
            if (T[i] == 'r') {
                ans += P;
            }
            else if (T[i] == 's') {
                ans += R;
            }
            else {
                ans += S;
            }
            rsp[i] = true;
        }
    }

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

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

result = 0
for i in range(n):
  i = i+1
  if i < 10:
    result += 1
  if 100 <= i and i < 1000:
    result += 1
  if 10000 <= i and i < 100000:
    result += 1
  if 1000000 <= i and i < 10000000:
    result += 1
print(result)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
 
#define ii pair<int,int>
#define fi first
#define sc second
#define lwb lower_bound
#define upb upper_bound
#define uset unordered_set
#define umap unordered_map
#define all(x) (x).begin(),(x).end()
 
int chmin(int &a, int b) { if (a > b) { a = b; return 1; } return 0; }
int chmax(int &a, int b) { if (a < b) { a = b; return 1; } return 0; }
 
int _dp[2000][20000];
int (*dp)[20000] = (int(*)[20000])&_dp[1000][10000];

signed main() {
#ifdef _DEBUG
  freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int h, n; cin >> h >> n;
  vector<ii> v(n);
  for (auto &i : v) cin >> i.fi >> i.sc;
  for (int i = -1; i < n; i++)
  for (int j = 1; j <= h; j++) {
    dp[i][j] = 2e9;
  }
  for (int i = 0; i <  n; i++)
  for (int j = 1; j <= h; j++) {
    dp[i][j] = min(dp[i - 1][j], dp[i][j - v[i].fi] + v[i].sc);
  }
  cout << dp[n - 1][h] << '\n';
}


Measured memory_bytes: 85960
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var A = int.Parse(Console.ReadLine());
            var B = int.Parse(Console.ReadLine());

            int[] AB = new int[2] { A, B };

            if (AB.Contains(1) && AB.Contains(2))
            {
                Console.WriteLine(3);
            }
            else if (AB.Contains(2) && AB.Contains(3))
            {
                Console.WriteLine(1);
            }
            else
            {
                Console.WriteLine(2);
            }


        }
    }
    
}


Measured memory_bytes: 11220