akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){

   string s,t;
   cin >> s >> t;

   char tmp;
   int ans = -1;
   rep(i,s.size()){
         tmp = s[0];
       rep(j,s.size()-1){
         s[j]=s[j+1];
      }
      s[s.size()-1] = tmp;
      if(s==t) {
       ans = 1;
       break;  
      }
   }

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





   return 0;
}

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

map<int, int> mp;

int main()
{
    int n, m, k, a, ans = 0;
    
    cin >> n >> m;
    
    int tmp = n;
    while(tmp--)
    {
        cin >> k;
        while(k--)
        {
            cin >> a;
            ++mp[a];
        }
    }
    
    for(int i = 1; i <= m; ++i) 
        if(mp[i] == n) ++ans;
    
    cout << ans;
    
    return 0;
}

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

int main(){
    int w;
    cin >> w;
    int a,b;
    cin >> a >> b;
    if(a<b){
        if(a+w>=b)
        cout << 0 << endl;
        else
        cout << b-a-w << endl;
    }
    else{
        if(b+w>=a)
        cout << 0 << endl;
        else
        cout << a-b-w << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
	int n;
  cin >> n;
  vector <int> v;
  for(int i=0;i<n;i++) {
   int x;
    cin >> x;
    v.push_back(x);
    //copy.push_back(x);
  }
 
  int c = 0,d=0;
  for(int i=0;i<n;i++) {
  		if(v[i] != i+1)
        {
          	c++;
  	}
  }
  if(c<=2)
    cout << "YES" << '\n';
  else
    cout << "NO" << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    int N;
    cin >> N;
    int res{};
    REP2( i, 1, N + 1 )
    {
        REP2( j, 2, 1000 )
        {
            int tmp = pow( i, j );
            if( tmp > N ) break;
            if( tmp <= N )
            {
                res = max( res, tmp );
            }
        }
    }
    cout << res << endl;
    return 0;
}

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

int main() {
	int n, ans = 0;
	cin >> n;
	vector<int> l(n + 10);
	rep(i, n) cin >> l[i];
	rep(i, n) REP(j, i + 1, n) REP(k, j + 1, n)
		if (!(l[i] == l[j] || l[j] == l[k] || l[k] == l[i]))
			if (l[i] + l[j] > l[k] && l[j] + l[k] > l[i] && l[k] + l[i] > l[j]) ans++;
	cout << ans << endl;
}

Measured memory_bytes: 3460
#include<algorithm>
#include<iostream>
#include<string.h>

int n;
int ans;

int main()
{
	while( 1 ){
		std::cin >> n;
		
		if( !n ) break;
		
		ans = 1;
		
		int num[6] = { 1, 2, 3, 5, 4, 6 };
		int num2[6] = { 1, 2, 3, 5, 4, 6 };
		
		while( n-- ){
			std::copy( num, num + 6, num2 );
			
			char str[10];
		 	std::cin >> str;
			
			if( !strcmp( str, "North" ) ){
			 	num[0] = num2[1];
				num[1] = num2[5];
				num[5] = num2[3];
				num[3] = num2[0];
			}
			else if( !strcmp( str, "East" ) ){
			 	num[2] = num2[0];
				num[0] = num2[4];
				num[4] = num2[5];
				num[5] = num2[2];
			}
			else if( !strcmp( str, "West" ) ){
			 	num[0] = num2[2];
				num[2] = num2[5];
				num[5] = num2[4];
				num[4] = num2[0];
			}
			else if( !strcmp( str, "South" ) ){
			 	num[0] = num2[3];
				num[3] = num2[5];
				num[5] = num2[1];
				num[1] = num2[0];
			}
			else if( !strcmp( str, "Right" ) ){
			 	num[1] = num2[2];
				num[2] = num2[3];
				num[3] = num2[4];
				num[4] = num2[1];
			}
			else if( !strcmp( str, "Left" ) ){
			 	num[2] = num2[1];
				num[1] = num2[4];
				num[4] = num2[3];
				num[3] = num2[2];
			}
			
			ans += num[0];
		}
		
		std::cout << ans << std::endl;
	}

 	return 0;
}

Measured memory_bytes: 1164
N = int(input())
a = list(map(int, input().split()))

cnt = 0
for i in range(N):
    if a[i]%2 == 1:
        continue
    else:
        while True:
            if a[i]%2 == 1:
                break
            else:
                a[i] //= 2
                cnt += 1
print(cnt)

Measured memory_bytes: 4148
// ALDS1_12_B.cpp
// Graph II - Single Source Shortest Path I
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;

struct Node {
    int v;
    int c;
    Node(int v, int c): v(v), c(c) {}
};

const int maxN = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int INF = (1<<21);
vector<Node> G[maxN];
vector<int> dist(maxN, INF);
vector<int> p(maxN);
vector<int> color(maxN, WHITE);
int n;
int cnt = 0;
void dijkstra(int x)
{
    dist[x] = 0;
    p[x] = -1;
    while(++cnt != n) {
        int u = 0;
        int mindist = INF;
        for (int i = 0; i < n; i++) {
            if (color[i] != BLACK && dist[i] < mindist) {
                mindist = dist[i];
                u = i;
            }
        }

        for (int i = 0; i < G[u].size(); i++) {
            if (color[u] == BLACK) continue;
            int v = G[u][i].v;
            int c = G[u][i].c;
            if (dist[u] + c < dist[v]) {
                dist[v] = dist[u] + c;
                p[v] = u;
                color[v] = GRAY;
            }
        }
        color[u] = BLACK;
    }
}

int main()
{
    cin >> n;
    int u, k;
    int v, c;
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            cin >> v >> c;
            G[i].push_back(Node(v, c));
        }
    }
    dijkstra(0);
    for (int i = 0; i < n; i++) {
        printf("%d %d\n", i, dist[i]);
    }
    return 0;
}

Measured memory_bytes: 3236
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << a << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  lvector A(n+1,0);
  rep(i,n) cin>>A[i+1];
  vector<lvector> dp(3,lvector(n+2,-1e18));
  dp[0][0]=0;
  rep(i,n+1) {
    rep(j,3) if(i) dp[j][i+1]=max(dp[j][i+1],dp[j][i-1]+A[i]);
    rep(j,2) dp[j+1][i+1]=max(dp[j+1][i+1],dp[j][i]);
  }
  print(dp[1+n%2].back());
  return 0;
}

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

using namespace std;
using ll = long long;
using pint = pair<int, int>;

int main() {
    constexpr int MAX = 101010;
    vector<int> is_prime(MAX, 1);
    is_prime.at(0) = 0, is_prime.at(1) = 0;
    for(int i = 2; i < MAX; ++i) {
        if (!is_prime.at(i)) continue;
        for(int j = i * 2; j < MAX; j += i) is_prime.at(j) = 0; 
    } 

    // 2017-like数かどうか
    vector<int> a(MAX, 0);
    for(int i = 0; i < MAX; ++i) {
        if (i % 2 == 0) continue;
        if (is_prime.at(i) && is_prime.at((i + 1) / 2)) a.at(i) = 1;
    }

    // 累積和
    vector<int> s(MAX + 1, 0);
    for(int i = 0; i < MAX; ++i) s.at(i + 1) = s.at(i) + a.at(i);

    int Q;
    cin >> Q;
    vector<pint> v(Q);
    for(int i = 0; i < Q; ++i) {
        int l, r;
        cin >> l >> r;
        ++r;
        v.at(i).first = l;
        v.at(i).second = r;
    }
    for(int i = 0; i < Q; ++i) cout << s.at(v.at(i).second) - s.at(v.at(i).first) << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
    
#define int long long
    
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define FORR(i,m,n) for(int i=m;i>=n;i--)
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 99999999999
#define MOD (int)(1e9)+7
    
using namespace std;
    
int dy[4]={1, 0, -1, 0};
int dx[4]={0, 1, 0, -1};
    
bool check(int a, int b){
    if((a<=0 && b>0) || (a>=0 && b<0)) return true;
    return false;
}
    
int32_t main(){
    int n, m;
    cin >> n >> m;

    int cnt=0;
    int mini = min(n, m/2);
    cnt += mini;
    n -= mini;
    m -= 2*mini;

    cnt += m/4;
    cout << cnt << endl;
}

Measured memory_bytes: 384
using System;
using System.IO;

namespace AtCoder
{
    class Program
    {
        private long A, B, C, D;
        static void Main(string[] args)
        {
            new Program().Solve();
        }

        public void Solve()
        {
            var sc = new Scanner();
            A = sc.NextLong();
            B = sc.NextLong();

            C = sc.NextInt();
            D = sc.NextInt();

            Console.WriteLine(Count(B)-Count(A-1));
        }

        // [1,n]でCでもDでも割り切れない物の個数
        private long Count(long n)
        {
            // Cで割り切れる
            long cc = n / C;
            // D
            long dd = n / D;

            // CでもDでも
            long lcmCount = n / Algorithm.LCM(C, D);

            return n - (cc + dd - lcmCount);
        }
    }
}


class Algorithm
{
    #region GCD
    static public long GCD(long a, long b)
    {
        while (a % b != 0)
        {
            long t = a % b;
            a = b;
            b = t;
        }

        return b;
    }
    #endregion
    #region LCM
    static public long LCM(long a, long b)
    {
        return a * b / GCD(a, b);
    }

    #endregion
}

class Scanner
{
    public Scanner()
    {
        _stream = new StreamReader(Console.OpenStandardInput());
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private readonly StreamReader _stream;
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = _stream.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = _stream.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}


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

int main() {
    int N;
    string S;
    cin >> N >> S;
    int ans = 0;

    for (int i = 1; i < N-1; i++) {
        int cnt = 0;
        for (int j = 0; j < i; j++) {
            bool frag = true;
            for (int k = 0; k < j; k++){
                if (S[k] == S[j]) {
                    frag = false;
                }
            }
            if (frag) {
                for (int k = i; k < N; k++){
                    if (S[k] == S[j]) {
                        cnt++;
                        break;
                    }
                }
            }
        }
        ans = max(ans,cnt);
    }
    cout << ans << endl;
}


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

typedef long long int64;

map< pair< int, int >, int64 > mp; 

int main()
{
  int64 H, W, N;
  cin >> H >> W >> N;
  vector< int64 > a(N);
  vector< int64 > b(N);
  for (int i = 0; i < N; ++i) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    for (int64 hi = -1; hi <= 1; ++hi) {
      for (int64 wi = -1; wi <= 1; ++wi) {
	if (0 < a[i] + hi && a[i] + hi < H - 1 &&
	    0 < b[i] + wi && b[i] + wi < W - 1) {
	  mp[make_pair(a[i] + hi, b[i] + wi)]++;
	}
      }
    }
  }

  vector< int64 > ans(10, 0ll);
  ans[0] = (H - 2) * (W - 2);
  
  for (auto&& mi : mp) {
    if (0 <= mi.second && mi.second <= 9) {
      ans[mi.second]++;
      ans[0]--;
    }
  }

  for (int i = 0; i <= 9; ++i) {
    cout << ans[i] << endl;
  }
  
  return 0;
}


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

int asc(const void *a, const void *b) {
  return *(long long int *)a - *(long long int *)b;
}

int main()
{
  int ret, i;
  int N, K;
  long long int H[200000], total = 0;

  ret = scanf("%d %d", &N, &K);
  for ( i=0; i<N; i++ )
    ret = scanf("%lld", &(H[i]));

  qsort( H, N, sizeof(long long int), asc );

  for ( i=0; i<N-K; i++ )
    total += H[i];
  printf("%lld\n", total);

  return 0;
}



Measured memory_bytes: 3324
#include<cstdio>
#include<cstdlib>

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

using namespace std;

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

int h,w;
char B[12][13],gy,gx;

bool vis[12][12];

int ice[12][12],ice_sz[144];
void predfs(int i,int j,int id){
	vis[i][j]=true;
	ice[i][j]=id;
	ice_sz[id]++;
	rep(k,4){
		int y=i+dy[k],x=j+dx[k];
		if(0<=y && y<h && 0<=x && x<w && B[y][x]=='X' && !vis[y][x]) predfs(y,x,id);
	}
}

int ans;
int step[144]; // ツ氷ツづーツ督・ツづアツつセツ嘉アツ青?
void dfs(int i,int j,int now){
	if(B[i][j]=='X') if(ice_sz[ice[i][j]]/2<step[ice[i][j]]+1) return;

	if(ans<=now+abs(i-gy)+abs(j-gx)) return; // Manhattan ツ仰猟猟」ツづ?A*
	if(B[i][j]=='G'){
		ans=now;
		return;
	}

	vis[i][j]=true;
	if(B[i][j]=='X') step[ice[i][j]]++;

	rep(k,4){
		int y=i+dy[k],x=j+dx[k];
		if(0<=y && y<h && 0<=x && x<w && B[y][x]!='#' && !vis[y][x]){
			// ツつアツづェツづ慊づ?づ可津環づ?つスツ督ケツつゥツづァ (y,x) ツづ可シツδ?ーツトツカツッツトツつオツづ?猟按づェツづゥツ湘ェツ債?づ債枝ツ環?づィ
			bool ok=true;
			rep(l,4){
				int yy=y+dy[l],xx=x+dx[l];
				if((yy!=i || xx!=j) && 0<=yy && yy<h && 0<=xx && xx<w && vis[yy][xx]) ok=false;
			}
			if(ok) dfs(y,x,now+1);
		}
	}

	vis[i][j]=false;
	if(B[i][j]=='X') step[ice[i][j]]--;
}

int main(){
	for(;scanf("%d%d",&w,&h),w;){
		rep(i,h) scanf("%s",B[i]);

		rep(i,h) rep(j,w) vis[i][j]=false;
		int ice_id=0;
		rep(i,h) rep(j,w) if(B[i][j]=='X' && !vis[i][j]) {
			ice_sz[ice_id]=0;
			predfs(i,j,ice_id++);
		}

		int sx,sy;
		rep(i,h) rep(j,w) {
			if(B[i][j]=='S') sx=j, sy=i;
			if(B[i][j]=='G') gx=j, gy=i;
		}

		rep(i,h) rep(j,w) vis[i][j]=false;
		ans=h*w;
		dfs(sy,sx,0);
		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using P = pair<int,int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;

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

int main(){
	int n, m;
	cin >> n >> m;
	
	vector<vector<int>> mp(n, vector<int>());
	rep(i, m){
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		mp[a].push_back(b);
		mp[b].push_back(a);
	}
	
	vector<int> dist(n, INF);
	dist[0] = 0;
	queue<int> q;
	q.push(0);
	while(!q.empty()){
		int tmp = q.front();
		q.pop();
		for(auto itr : mp[tmp]){
			if(dist[itr] != INF) continue;
			dist[itr] = dist[tmp] + 1;
			q.push(itr);
		}
	}
	if(2 < dist[n-1]) cout << "IMPOSSIBLE" << endl;
	else cout << "POSSIBLE" << endl;
	return 0;
}



Measured memory_bytes: 13168
#include <stdio.h>
#include <string.h>

int main(void){
    
    int i,j,k,l;
    int num;
    int count[4]={0};
    char data[3];
    char blood[4][3]={"A","B","AB","O"};
    
    while(1){
        scanf("%d,%s",&num,data);
        if(feof(stdin))break;
        for(i=0;i<4;i++){
            if(strcmp(data,blood[i])==0){
                count[i]++;
            }
        }
    }
    for(i=0;i<4;i++){
        printf("%d\n",count[i]);
    }
    return(0);
}

Measured memory_bytes: 608
let x = Int(readLine()!)!

switch x {
  case 400..<600:
  	print("8")
  case 600..<800:
    print("7")
  case 800..<1000:
    print("6")
  case 1000..<1200:
    print("5")
  case 1200..<1400:
    print("4")
  case 1400..<1600:
    print("3")
  case 1600..<1800:
    print("2")
  case 1800..<2000:
    print("1")
  default:()
}

Measured memory_bytes: 7664
n = int(input())
x = list(map(int, input().split()))
count = 0
for i in range(n-2):
  a, b, c = x[i], x[i+1], x[i+2]
  x2 = [a, b, c]
  x2 = sorted(x2)
  if b==x2[1]:
    count += 1
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int mod=1e9+7;

void solve(){
	int x;
	cin>>x;
	int l,h,m,ans;
	l=1;h=1e9;
	while(l<=h){
		m=l+(h-l)/2;
		ll t=m*1LL*(m+1)/2-x;
		if(t>=0){
			ans=m;
			h=m-1;
		}
		else l=m+1;
	}
	cout<<ans;
}

int main(){
int test=1;
// cin>>test;
while(test--){
	solve();
	cout<<endl;
}

return 0;
}


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

int main() {
	char b;
	cin >> b;
	char k;
	if(b == 'A')
	{
		k = 'T';
	}
	else if(b == 'T')
	{
		k = 'A';
	}
	else if(b == 'C')
	{
		k = 'G';
	}
	else
	{
		k = 'C';
	}
	cout << k << endl;
	return 0;
}


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


int main()
{
  int x1,y1,x2,y2;
  cin >> x1 >> y1 >> x2 >> y2;

  int dx = x2 - x1;
  int dy = y2 - y1;

  int x3 = x2 - dy;
  int y3 = y2 + dx;
  int x4 = x1 - dy;
  int y4 = y1 + dx;

  cout << x3 << " " << y3 << " " << x4 << " " << y4;

  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=100005,MAXM=200005;
int n,m;
struct edge
{
	int v,nxt;
	edge(){}
	edge(int vv,int nn)
	{
		v=vv,nxt=nn;
	}
}E[MAXM];
int w[MAXN],ncnt,ans[2][MAXN];
bool vis[MAXN];
void addedge(int u,int v)
{
	E[++ncnt]=edge(v,w[u]);
	w[u]=ncnt;
	E[++ncnt]=edge(u,w[v]);
	w[v]=ncnt;
}
void dfs(int u,int id)
{
	vis[u]=1;
	ans[id][++ans[id][0]]=u;
	for(int i=w[u];i;i=E[i].nxt)
	{
		int v=E[i].v;
		if(!vis[v])
		{
			dfs(v,id);
			return ;
		}
	}
}
int main()
{
	//freopen("path.in","r",stdin);
	//freopen("path.out","w",stdout);
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int u,v;
		scanf("%d %d",&u,&v);
		addedge(u,v);
	}
	dfs(1,0);
	dfs(1,1);
	
	int zans=ans[1][0]+ans[0][0]-1;
	printf("%d\n",zans);
	int key=0;
	for(int i=ans[1][0];i>=2;i--)
	{
		if(key)
			printf(" ");
		printf("%d",ans[1][i]);
		key=1;
	}
	for(int i=1;i<=ans[0][0];i++)
	{
		if(key)
			printf(" ");
		printf("%d",ans[0][i]);
		key=1;
	}
	printf("\n");
	fclose(stdin);
	fclose(stdout);
}

Measured memory_bytes: 3072
#include <functional>
#include <iostream>
#include <vector>

#include <cstddef>
#include <cstdint>

constexpr std::size_t popcount32(std::uint_fast32_t c) noexcept {
#ifdef _GNUC_
  return __builtin_popcount(c);
#else
  c -= c >> 1 & 0x55555555;
  c = (c & 0x33333333) + (c >> 2 & 0x33333333);
  c = (c + (c >> 4)) & 0x0F0F0F0F;
  return c * 0x01010101 >> 24 & 0x3F;
#endif
}

int main() {
  int n;
  std::cin >> n;
  std::vector<std::vector<int>> t(n);
  for (int i = 0; i != n - 1; i += 1) {
    int a, b;
    std::cin >> a >> b;
    a -= 1;
    b -= 1;
    t[a].push_back(b);
    t[b].push_back(a);
  }
  int m;
  std::cin >> m;
  const int s = 1 << m;
  std::vector<int> z(s, 0);
  {
    std::vector<int> x(n, 0);
    for (int i = 0; i != m; i += 1) {
      int u, v;
      std::cin >> u >> v;
      u -= 1;
      v -= 1;
      x[u] ^= 1 << i;
      x[v] ^= 1 << i;
    }
    std::function<void(int, int)> dfs = [&](int v, int p) {
      for (int e : t[v]) {
        if (e == p)
          continue;
        dfs(e, v);
        z[x[e]] += 1;
        x[v] ^= x[e];
      }
    };
    dfs(0, n);
  }
  for (int w = 1; w != s; w <<= 1) {
    for (int i = 0; i != s; i += w << 1) {
      for (int j = 0; j != w; j += 1) {
        z[i + j + w] += z[i + j];
      }
    }
  }

  long long ans = 0;
  for (int i = 0; i != 1 << m; i += 1) {
    auto res = 1LL << z[s - 1 ^ i];
    if (popcount32(i) % 2)
      res = -res;
    ans += res;
  }
  std::cout << ans << std::endl;
}

Measured memory_bytes: 4352
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i) 
const int N = 200005, mo = 1000000007 ;
using namespace std ;

int n, a[N], fac[N], inv[N], h[N] ;

int mul(int a, int b) {
    int ans = 1, w = a % mo ;
    for ( ; b; b /= 2) {
        if (b & 1) ans = (ll) ans * w % mo ;
        w = (ll) w * w % mo ; 
    }
    return ans ;
}

int calc(int x, int y) {
    if (x < y) return 0 ; 
    return (ll) fac[x] * inv[y] % mo * inv[x - y] % mo ;
}

int main() {
    scanf("%d", &n) ;
    ++ n ;
    int x, y ; 
    rep(i, 1, n) {
        scanf("%d", &a[i]) ;
        if (h[a[i]]) {
            x = h[a[i]] ;
            y = i ;
        }
        h[a[i]] = i ;
    }
    fac[0] = inv[0] = 1 ;
    rep(i, 1, n) {
        fac[i] = (ll) fac[i - 1] * i % mo ; 
    }
    inv[n] = mul(fac[n], mo - 2) ;
    for (int i = n - 1; i; -- i) {
        inv[i] = (ll) inv[i + 1] * (i + 1) % mo ;
    }
    rep(i, 1, n) {
        int res = calc(n, i) ;
        res -= calc(n - (y - x + 1), i - 1) ;
        res %= mo ;
        printf("%d\n", (res + mo) % mo) ;
    }
    return 0 ;  
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int N;
map<P,P> fie;

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

bool solve(int x,int y){
  P now = fie[P(x,y)];
  // cout << x << " " << y << " " << now.first << " "<< now.second << endl;
  int dr[4]={};
  for(int i=0;i<4;i++){
    if( fie.count(P(x+dx[i],y+dy[i])) == 0 ) continue;
    P &st = fie[P(x+dx[i],y+dy[i])];
    if( st.first == now.first ){
      if( st.second == 0 ){
        st.second = now.second==1?2:1;    
        dr[i] = 1;
      }
      else if( st.second == now.second )
        return false;
    } else {
      if( st.second == 0 ){
        st.second = now.second == 1?1:2;        
        dr[i] = 1;
      } else if( st.second != now.second )
        return false;             
    }
  }

  for(int i=0;i<4;i++)
    if( dr[i] == 1 )
     if( !solve( x + dx[i] , y + dy[i] ) ) return false;    
  
  return true;
}

int main(){
  while( cin >> N && N){
    fie.clear();
    bool f = true;
    for(int i=0;i<N;i++){
      int x,y;char c;
      cin >> x >> y >> c;
      if( fie.count(P(x,y)) ) f = false;
      fie[P(x,y)] = P(i,0);
      if( c == 'x' ){
        if( fie.count(P(x+1,y)) ) f = false;
        fie[P(x+1,y)] = P(i,0);
      } else {
        if( fie.count(P(x,y+1)) ) f = false;
        fie[P(x,y+1)] = P(i,0);
      }
    }



    for(map<P,P>::iterator it = fie.begin(); it != fie.end() && f; it++){
      int x = it->first.first;
      int y = it->first.second;
  
      if( it->second.second == 0 ){
        it->second.second = 1;
        if( !solve(x,y) ) {
          f = false;
          //    cout << x << " "<< y <<" "<<it->second.first << " "<<it->second.second<< endl;
          break;
        }
      }
      // cout << x << " "<< y <<" "<<it->second.first << " "<<it->second.second<< endl;
    }
    if( f ) cout << "Yes" << endl;
    else cout << "No" << endl;

  }
}

Measured memory_bytes: 7432
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define UP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define UU(a,b,c) for(ll (a)=(b);(a)<=(c);(a)++)
#define DN(a,b,c) for(ll (a)=(b);(a)>(c);(a)--)
#define DU(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)

int k;

void reset()
{
}

void input()
{
	cin>>k;
}

void solve()
{
	if(k % 2 == 0 || k % 10 == 5)
	{
		cout<<-1<<endl;
		return ;
	}
	
	ll temp = 0, v = k, cnt = 0;
	
	while(v > 0)
	{
		temp *= 10;
		temp += 7;
		v/=10;
		cnt++;
	}
	temp %= k;
	while(true)
	{
		if(temp == 0)
		{
			cout<<cnt<<endl;
			return ;
		}
		
		temp *= 10;
		temp += 7;
		
		temp %= k;
		
		cnt++;
	}
}

void LetsRock()
{
	solve();	
}

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

	input();
	reset();
	LetsRock();
	
	return 0;
}


Measured memory_bytes: 3644
# coding: utf-8

n,x = map(int, input().split())

l,p = [1],[1]
for i in range(n):
    l.append(l[i]*2+3)
    p.append(p[i]*2+1)

def f(n,x):
    if n == 0:
        return 0 if x <= 0 else 1
    elif x <= 1 + l[n-1]:
        return f(n-1,x-1)
    else:
        return p[n-1]+1+f(n-1,x-2-l[n-1])

print(f(n,x))


Measured memory_bytes: 3064
h,w = gets.split.map(&:to_i)
a = h.times.map{gets.split.map(&:to_i)}
ans = []
for i in 0..h-1
    for j in 1..w-1
        if a[i][j-1].odd?
            ans << "#{i+1} #{j} #{i+1} #{j+1}"
            a[i][j] += 1
        end
    end
end
for i in 1..h-1
    if a[i-1][-1].odd?
        ans << "#{i} #{w} #{i+1} #{w}"
        a[i][-1] += 1
    end
end
puts ans.size,ans

Measured memory_bytes: 18684
import java.util.*;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[]a = new int[n];
    
    for(int i=0; i<n; i++){
        a[i] = sc.nextInt();
}
    Arrays.sort(a); 

        System.out.print(a[n-1]-a[0]);
    }
}


Measured memory_bytes: 35688
#include"bits/stdc++.h"
#include<math.h>
#include<vector>
using namespace std;
int64_t i,j,k,l;//preparation for
int main(){
    int n,m,l;
    cin>>n>>m;

    if(n<=m){
        cout<<"unsafe";
    }
    else{
        cout<<"safe";
    }

    return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define int   long long
#define N 666666
#define inf 999999999999999999
int arr[N];int n,m,q;
int res,ans;
struct str{
	int a,b,c,d;
}st[N];
void dfs(int pre,int sum){
	if(sum==n){
		int add=0;
	/*	for(int i=1;i<=n;i++) cout<<arr[i]<<" ";
		cout<<'\n';*/
		for(int i=1;i<=q;i++){
			if(arr[st[i].b]-arr[st[i].a]==st[i].c){
				add+=st[i].d;
			} 
		}
		res=max(res,add);
		return ;
	} 
	for(int i=pre;i<=m;i++){
		arr[sum+1]=i;
		dfs(i,sum+1);
	}
}
signed main(){
	
	cin>>n>>m>>q;
	for(int i=1;i<=q;i++) cin>>st[i].a>>st[i].b>>st[i].c>>st[i].d;
	
	for(int i=1;i<=m;i++){
			arr[1]=i;
			dfs(i,1);
	}
	cout<<res;
 	return 0;
}
/**/

Measured memory_bytes: 3640
#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstring>
#include <functional>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <istream>

#include <map>
#include <math.h>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <stdint.h>

namespace asl
{
    template <typename T>
    using vec = std::vector<T>;

    class DisjointSet
    {
    public:
        std::vector<int> ds;

        DisjointSet(int n)
        {
            ds = std::vector<int>(n, -1);
        }

        int root(int a)
        {
            return ds[a] < 0 ? a : ds[a] = root(ds[a]);
        }

        bool join(int u, int v)
        {
            u = root(u), v = root(v);

            if (u == v)
                return false;

            if (ds[u] < ds[v])
                std::swap(u, v);

            ds[v] += ds[u];
            ds[u] = v;

            return true;
        }

        int size(int a)
        {
            return -ds[root(a)];
        }
    };
} 

#include <experimental/optional>

#include <tuple>

#include <random>

#include <utility>

#define endl '\n'

using namespace std;
using namespace asl;

void solve()
{
    int n;
    cin >> n;

    vec<int> x(n), y(n);
    for (int i = 0; i < n; ++i)
        cin >> x[i] >> y[i];

    DisjointSet ds(n);

    vec<int> order(n);
    iota(order.begin(), order.end(), 0);
    sort(order.begin(), order.end(), [&](int u, int v) { return x[u] < x[v]; });

    stack<int> s;

    for (int i = 0; i < n; ++i)
    {
        int ini = order[i];

        while (!s.empty() && y[s.top()] < y[order[i]])
        {
            if (y[s.top()] < y[ini])
                ini = s.top();

            ds.join(order[i], s.top());
            s.pop();
        }

        s.push(ini);
    }

    for (int i = 0; i < n; ++i)
        cout << ds.size(i) << endl;
}

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

    int t = 1;

    for (int i = 1; i <= t; ++i)
    {
        solve();
    }

    return 0;
}




Measured memory_bytes: 6348
#include <bits/stdc++.h>
using namespace std;
#define lint long long
#define P pair<int, int>


int main(){
    int N;
    cin >> N;
    
    map<int, int> cnt;
    
    for(int i = 0; i < N; ++i){
        int a;
        cin >> a;
        cnt[a]++;
    }
    
    int ans = 0;
    for(auto e : cnt){
        if(e.second >= e.first){
            ans += e.second - e.first;
        } else {
            ans += e.second;
        }
    }
    
    cout << ans << endl;
    
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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; }
template<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N, M;
        cin >> N >> M;
        vll foods(M+10, 0);
        vllvll A(N);
        rep(i, 0, N) {
                ll k;
                cin >> k;
                rep(j, 0, k) {
                        ll a;
                        cin >> a;
                        A[i].push_back(a);
                        foods[a]++;
                }
        }
        cout << count(all(foods), N) << endl;       
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

	ll A=in<ll>(),B=in<ll>(),C=in<ll>(),X=in<ll>(),Y=in<ll>();
	ll minXY=min(X,Y),maxXY=max(X,Y);
	ll cost = 0;
	if((A+B)>2*C){
		cost += 2*C*minXY;
		if(minXY==X){
			if(B>2*C){
				cost += 2*C*(Y-X);
			}
			else{
				cost += B*(Y-X);
			}
		}
		else{
			if(A>2*C){
				cost += 2*C*(X-Y);
			}
			else{
				cost += A*(X-Y);
			}
		}
	}
	else{
		cost += A*X+B*Y;
	}

	cout << cost << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

template<class T, class U> void chmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> void chmin(T &a, U b) { if (a > b) a = b; }

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

constexpr ll MOD = 1000000007;

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

  int n; cin >> n;

  if (n == 1) cout << "Hello World" << endl;
  else {
    int a, b; cin >> a >> b;
    cout << a + b << endl;
  }

  return (0);
}


Measured memory_bytes: 3588
#include<stdio.h>
#include<string.h>

int main(void)
{
	int i,j,k,n,b,f,r,v;
	int a[4][3][10];

	for(i=0;i<4;i++)
		for(j=0;j<3;j++)
			for(k=0;k<10;k++)
				a[i][j][k]=0;

	scanf("%d",&n);

	for(i=0;i<n;i++)
	{
		scanf("%d %d %d %d",&b,&f,&r,&v);

		a[b-1][f-1][r-1]+=v;

	}

	for(i=0;i<4;i++)
	{
		for(j=0;j<3;j++)
		{
			for(k=0;k<10;k++)
			{
				printf(" ");
				if(a[i][j][k]!=0)
					printf("%d",a[i][j][k]);
				else 
					printf("0");
			}
			printf("\n");
		}
		if(i!=3)
			printf("####################\n");
	}
		
}



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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }

ll gcd(ll x, ll y)
{
    ll r;
    while((r = x % y) != 0)  
    {
        x = y;
        y = r;
    }
    return y;
}

int main(){
  ll i, j;
  ll n;
  cin >> n;
  vector<ll> a(n);
  for(i = 0; i < n; i++)
    cin >> a[i];
  
  vector<ll> b(n);
  b[0] = a[0];
  for(i = 1; i < n; i++)
    b[i] = gcd(b[i - 1], a[i]);
  
  ll result = b[n - 2];
 // cout << result << endl;
  ll buf = a[n - 1];
  chmax(result, gcd(buf, b[n - 3]));
  for(i = n - 2; i >= 2; i--){
    buf = gcd(buf, a[i]);
    //cout << buf << endl;
    chmax(result, gcd(buf, b[i - 2]));
  }
  chmax(result, gcd(buf, a[1]));
          

  cout << result << endl;

  return 0;
}

Measured memory_bytes: 1792
/*input
async layered coding
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
int main()
{
	IOS;
	int a,b,c;
	cin>>a>>b>>c;
	c+=10*b;
	if(c%4==0) cout<<"YES\n";
	else cout<<"NO";
	return 0;
}


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

using namespace std;
using ll = long long;

int main() {
    string a, b;
    cin >> a >> b;
    ll n = stoi(a + b);

    if (n == (ll)sqrt(n) * (ll)sqrt(n)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int i,N;
  int64_t sum=0;
  cin >> N ;
  for (i=1;i<N+1;i++){
    if(i%3==0)
      continue;
    if(i%5==0)
      continue;
    else{
      sum=sum+i;
    }
  }
    cout << sum <<endl;
}  

Measured memory_bytes: 3636
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
const int mod = 1000000007;
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")


P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}



int main(){
  
  int a;cin>>a;
  cout << a*a*a << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <assert.h>
#include <memory.h>
#include <queue>
#include <string.h>
using namespace std;

#define N 5002
#define inf 4000000000000000000LL
int p[N];

long long dp[N][N];
long long leftMoveCost,rightMoveCost;

void solve() {
  int n;
  long long A,B;
  scanf("%d %lld %lld ", &n,&A,&B);
  leftMoveCost = B;
  rightMoveCost = A;
  for(int i=1;i<=n;++i) {
    int num;
    scanf("%d ",&num);
    p[num] = i;
  }
  fill((long long*)dp,(long long*)dp+N*N,inf);
  dp[0][0] = 0;
  for(int i=1;i<=n;++i) {
    int curInd = p[i];
    long long mini = inf;
    for(int j=0;j<=n;++j) {
      mini = min(mini, dp[i-1][j]);
      long long cost;
      if(j+1==curInd) {
        cost = 0;
      } else if(j+1<curInd) {
        cost = leftMoveCost;
      } else {
        cost = rightMoveCost;
      }
      dp[i][j] = cost + mini;
    }
  }
  long long ret = inf;
  for(int i=0;i<=n;++i) {
    ret = min(ret, dp[n][i]);
  }
  printf("%lld\n", ret);
}

int main() {
  //freopen("input.txt","r",stdin);
  solve();
  return 0;
}


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

int compare(const void *a, const void *b){
    return *(int*)a - *(int*)b;
}

int main(){
	int N, i, j;
	scanf("%d", &N);
	int v[N];
	double V[N];
	for(i=0; i<N; i++){
		scanf("%d", &v[i]);
	}

    qsort(v, N, sizeof(int), compare);
	for(i=0; i<N; i++){
		V[i] = (double)v[i];
	}

	for(i=0; i<N-1; i++){
		V[i+1] = (V[i] + V[i+1])/2.0;
	}

	printf("%f", V[N-1]);

	return 0;
}

Measured memory_bytes: 128
import heapq

q = int(input())
big, small = [], []
heapq.heapify(big)
heapq.heapify(small)
sumb = 0
sumdist = 0
i = 0
for _ in range(q):
    query = list(map(int, input().split()))
    if query[0] == 1:
        i += 1
        a, b = query[1], query[2]
        sumb += b
        if i % 2 == 1:
            if i == 1:
                median = a
            else:
                if big[0] <= a:
                    median = heapq.heappushpop(big, a)
                    sumdist += abs(a - median)
                elif a <= -small[0]:
                    median = -heapq.heappushpop(small, -a)
                    sumdist += abs(a - median)
                else:
                    median = a
        else:
            sumdist += abs(a - median)
            heapq.heappush(big, max(a, median))
            heapq.heappush(small, -min(a, median))
            median = -small[0]
    else:
        print(median, sumdist + sumb)

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

int main() {
  //Nを代入
  int N;
  cin >> N;
  
  //2の累乗と比較
  int comparison = 1;

  while (comparison <= N) {
    comparison *= 2;
  }
  
  cout << comparison / 2 << endl;
}



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

class Program
{

    static void Main(string[] args)
    {
        var n = Console.ReadLine();
        var ans = new System.Text.StringBuilder();
        foreach (var c in n)
        {
            if (c == '1')
            {
                ans.Append('9');
            }
            else
            {
                ans.Append('1');
            }
        }

        Console.WriteLine(ans.ToString());

    }



}



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

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

    int t = N;
    int s = 0;
    while (t > 0) {
        s += t % 10;
        t /= 10;
    }

    if (N % s == 0)
        puts("Yes");
    else
        puts("No");
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
	int n, count;

	while ( cin >> n )
	{
		bool table[1000000];
		count = 0;

		for ( int i = 0; i <= n; i++ )
		{
			table[i] = true;
		}

		for ( int i = 2; i <= n; i++ )
		{
			if ( table[i] )
			{
				count++;
				for ( int j = 2; i * j <= n; j++ )
				{
					table[i*j] = false;
				}
			}
		}

		printf("%d\n", count );
	}

	return 0;
}

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

#define PI 3.14159265359

//2の累乗数かどうか
bool hantei(int N) {
	bool flag = false;
	while (1) {
		if (N % 2 == 0) N /= 2;
      	else break;
	}
	if (N == 1) flag = true;

	return flag;
}
int main() {
	int N;
  	cin >> N;
	if (N == 1) cout << 1 << endl;
	else {
		for (int i = N; i >= 1; i--) {
			if (hantei(i)) {
				cout << i << endl;
				break;
			}
		}
	}
}


Measured memory_bytes: 256
package main

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

//=====I/O=====

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInt64() int64 {
	sc.Scan()
	a,_ := strconv.ParseInt(sc.Text(),10,64)
	return a
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//=====main=====

func main() {
	sc.Split(bufio.ScanWords)

	a,b := scanInt(), scanInt()

	if a+a-1 >= a+b && a+a-1 >= b+b-1 {
		fmt.Println(a+a-1)
	} else if a+b >= a+a-1 && a+b >= b+b-1 {
		fmt.Println(a+b)
	} else {
		fmt.Println(b+b-1)
	}
}


Measured memory_bytes: 640
#include <stdio.h>

int main()
{
    char s[100001]={0};
    int i;
    scanf("%s",s);
    
    for(i=0;s[i]!=0;i=i+2)
    {
        printf("%c",s[i]);
    }
    
    printf("\n");
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <set>
#include <iterator>
#include <algorithm>

template <class T>
T abs(T a) { return (a < 0 ? -a : a); }

int main() {
    int n, k, q;
    auto ret = 100000000000ll;
    std::cin >> n >> k >> q;
    std::vector<long long> v(n);
    for (auto i = 0; i < n; i++) std::cin >> v[i];

    for (auto i = 0; i < n; i++) {
        auto x = v[i];
        std::deque<long long> que;
        auto curr = std::find_if(v.begin(), v.end(), [&](auto el) { return el >= x; });
        while (curr != v.end()) {
            auto next = std::find_if(curr, v.end(), [&](auto el) { return el < x; });
            if (next - curr >= k) {
                auto sub = std::vector<long long>(curr, next);
                std::sort(sub.begin(), sub.end());
                std::copy_n(sub.begin(), sub.size() - k + 1, std::back_inserter(que));
            }
            curr = std::find_if(next, v.end(), [&](auto el) { return el >= x; });
        }
        
        if (que.size() < q) continue;
        
        std::sort(que.begin(), que.end());

        if (que[0] != x) continue;

        ret = std::min(ret, que[q - 1] - x);
    }

    std::cout << ret << std::endl;

    return 0;
}

Measured memory_bytes: 256
package main

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

func gcd(x, y int) int {
	if x < y {
		x, y = y, x
	}
	for y > 0 {
		x, y = y, x%y
	}
	return x
}

func primeFactorize(n int) [][2]int {
	var result [][2]int
	rn := int(math.Sqrt(float64(n)))
	for i := 2; i < rn+1; i++ {
		if n%i != 0 {
			continue
		}
		t := [2]int{i, 0}
		for n%i == 0 {
			n /= i
			t[1]++
		}
		result = append(result, t)
	}
	if n != 1 {
		result = append(result, [2]int{n, 1})
	}
	return result
}

func main() {
	A := readInt()
	B := readInt()

	fmt.Println(len(primeFactorize(gcd(A, B))) + 1)
}

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

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

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

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


Measured memory_bytes: 1820
#include <iostream>
using namespace std;
typedef long long ll;
ll k, num;
string str;
int main(void){
    // Your code here!
    cin >> str >> k;
    for (ll i = 0; i < str.length(); i++){
        if (str[i] == '1') num++;
        else break;
    }
    if (k <= num){
        cout << 1 << endl;
    } else {
        cout << str[num] << endl;
    }
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn main() {
    let d: u32 = read();
    if d == 25 {
        println!("Christmas");
    } else if d == 24 {
        println!("Christmas Eve");
    } else if d == 23 {
        println!("Christmas Eve Eve")
    } else if d == 22 {
        println!("Christmas Eve Eve Eve")
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


Measured memory_bytes: 4352
#include<stdio.h>
int b(int x){return x<0?-x:x;}
int main(){
  int a[100002]={0},i,n,c=0;
  scanf("%d",&n);
  for(i=1;i<=n;i++){scanf("%d",&a[i]);c+=b(a[i]-a[i-1]);}
  c+=b(a[n+1]-a[n]);
  for(i=1;i<=n;i++)printf("%d\n",c-b(a[i]-a[i-1])-b(a[i+1]-a[i])+b(a[i+1]-a[i-1]));
}


Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V))

vector<string> split(string,string);

//template<typename T>
//void swap(T*,T*);
//char ToUpper (char cX) { return toupper(cX); }

int main()
{
    int X,t;
    cin >> X >> t;
    cout << (X - t > 0 ? X - t : 0);
}


Measured memory_bytes: 256