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

using namespace std;
#define sf(n) scanf("%d", &n)
#define pd(n) printf("%.12lf", n)
#define pf(n) printf("%d", n)
#define p() printf("\n")
#define ps() printf(" ")
#define ll long long
#define ull unsigned long long
#define MAX 1e9
#define mod 1000 * 1000 * 1000 + 7
#define pi 3.1415926536
#define ex 1e18
#define dbl 2e09
#define qu(q) queue<int> q
#define pqu(q) priority_queue<int> q
#define len(s) s.length()
#define sz(x) int(x.size())
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fir first
#define sec second

const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

int main()
{
    int a, b, t;
    cin >> a >> b >> t;
    cout << (t / a) * b << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    D, N = map(int, input().split())
    if D == 0:
        if N <= 99:
            print(N)
        else:
            print(N+1)
    elif D == 1:
        if N <= 99:
            print(100*N)
        else:
            print(101*N)
    else:
        if N <= 99:
            print(10000*N)
        else:
            print(10100*N)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9072
#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

vector<int> d(13,0);
vector<bool> e(25,false);

int search( int hour ){
    if( hour == 13 ){
        int cnt = 123;
        int ret = 10200;
        Rep(i,80){
            if( e[i%24] ){
                ret = min( cnt, ret );
                cnt = 0;
            }
            cnt++;
        }
        return ret;
    }
    if( d[hour] > 2 ) return 0;
    if( d[hour] == 0 ) return search( hour+1 );
    if( d[hour] == 1){
        if( hour == 12 ) {
            e[0] = true;
            int plus = search( hour+1 );
            e[0] = false;
            return plus;
        }
        e[12+hour] = true;
        int plus = search( hour+1 );
        e[12+hour] = false;
        e[12-hour] = true;
        int minus = search( hour+1 );
        e[12-hour] = false;
        return max( plus , minus );
    }
    if( d[hour] == 2 ){
        if( hour == 0 || hour == 12 ) return 0;
        e[12+hour] = true;
        e[12-hour] = true;
        return search( hour+1 );
    }
}

int main() {

    int N;
    Scd(N);
    d[0] = 1;
    e[12] = 1;

    int a;
    Rep(i,N){
        Scd(a);
        d[a]++;
    }

    int ans = search(0);

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

    return 0;
}



Measured memory_bytes: 256
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors
n=int(input())
nlist=make_divisors(n)
n1list=make_divisors(n-1)
# print(nlist)
# print(n1list)
answer=len(n1list)-1#1を除きます
for i in nlist[1:len(nlist)]:
    pra=n
    while (pra%i==0):
        pra=pra/i
    if pra%i==1:
        answer+=1
print(answer)


Measured memory_bytes: 3316
import java.io.*;
  
class Main{
	public static void main(String[] args) throws IOException{

		int x,
		max=-1000000,
		min=1000000,
		temp;
		long sum=0;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		x = Integer.parseInt(br.readLine());
		String[] str = br.readLine().split(" ");

		for(int i = 0; i < x; i ++){
			temp = Integer.parseInt(str[i]);
			if(temp>max){
				max = temp;
			}
			if(temp<min){
				min = temp;
			}
		sum = sum + temp;
		}
		System.out.println(min + " " + max + " " +sum);
  	}
}

Measured memory_bytes: 25700
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	
	//配列の要素数
	Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
	
	//配列の要素
	int A[] = new int[n];	
	for(int i=0;i<A.length;i++){
	    A[i]= scanner.nextInt();
	}
	Sort(A,n);
	Print(A,n);
    }
    //並べ替え
    private static void Sort(int A[], int n){
	for(int i=1; i < n; i++){
	    int v = A[i];
	    int j = i-1;
	    Print(A,n);
	    while(j >= 0 && A[j] > v){
		A[j+1] = A[j];
		j--;
	    }                                            
	    A[j+1] = v;
	}
    }
    //表示
    private static void Print(int A[], int n){
	for(int k=0;k<A.length;k++){
	    System.out.print(A[k]);
	    if(k < (n-1)){
		System.out.print(" ");
	    }
	}
	System.out.println();
    }
}



Measured memory_bytes: 34040
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

typedef int Weight;
struct Edge {
  int src, dst;
  Weight capacity, cost;
  int rev;
  Edge(int src, int dst, Weight capacity, Weight cost) :
    src(src), dst(dst), capacity(capacity), cost(cost) { }
  Edge(int src, int dst, Weight capacity, Weight cost, int rev) :
    src(src), dst(dst), capacity(capacity), cost(cost), rev(rev) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.cost != f.cost ? e.cost > f.cost : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void add_edge(Graph &g, int s, int d, Weight cap, Weight cost) {
  g[s].push_back(Edge(s,d,cap,cost,g[d].size()));
  g[d].push_back(Edge(d,s,0,-cost,g[s].size()-1));
}

pair<Weight, Weight> minimumCostFlow3(Graph g, int s, int t) {
  const int n = g.size();
  pair<Weight, Weight> total; // (cost, flow)
  
  vector<Weight> h(n,INF);
  h[s] = 0;
  REP(k, n) REP(i, n) FOR(e,g[i]) if (e->capacity)
    h[e->dst] = min(h[e->dst], h[e->src] + e->cost);
  
  for (int F = INF; F > 0;) { // residual flow
    vector<Weight> d(n, INF); d[s] = 0;
    vector<int> pv(n,-1), pe(n);
    priority_queue<Edge> Q;
    for (Q.push(Edge(-2,s,0,0)); !Q.empty(); ) {
      Edge e = Q.top(); Q.pop();
      if (pv[e.dst] != -1) continue;
      pv[e.dst] = e.src;
      pe[e.dst] = e.rev;
      REP(i, g[e.dst].size()) {
        Edge &f = g[e.dst][i];
        if (f.capacity > 0 && d[f.dst] > d[f.src] + f.cost + h[f.src] - h[f.dst]) {
          d[f.dst] = d[f.src] + f.cost + h[f.src] - h[f.dst];
          Q.push(Edge(f.src, f.dst, 0, d[f.dst], i));
        }
      }
    }
    if (pv[t] == -1) break;
    Weight f = F;
    for (int u = t; u != s; u = pv[u])
      f = min(f, g[pv[u]][pe[u]].capacity);
    if (!f) break;
    for (int u = t; u != s; u = pv[u]) {
      total.first += f * g[pv[u]][pe[u]].cost;
      g[pv[u]][pe[u]].capacity -= f;
      g[u][g[pv[u]][pe[u]].rev].capacity += f;
    }
    F -= f;
    total.second += f;
    REP(u,n) if (h[u] != INF) h[u] += d[u];
  }
  return total;
}

int main() {
  int n;
  while(cin >> n, n) {
    Graph g(367);
    
    REP(i, n) {
      int a, b, w;
      cin >> a >> b >> w;
      add_edge(g, a-1, b, 1, -w);
    }
    REP(i, 366) {
      add_edge(g, i, i+1, 2, 0);
    }
    cout << -minimumCostFlow3(g, 0, 366).first << endl;
  }
}

Measured memory_bytes: 0
#include <stdio.h>

int main(void){
    int l, r, d;
    scanf("%d", &l);
    scanf("%d", &r);
    scanf("%d", &d);
    int n = 0;

    while(l <= r){
        int s = l % d;
        if(s == 0){
            n++;
        }
        l++;
    }

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


Measured memory_bytes: 1724
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<(int)N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=0;i--)
#define p(s) cout<<(s)<<endl
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const int inf=1e9;

int N,M,R;
int ans;
int dp[1<<8][210];
int r[10];
int edge[210][210];

int main() {
	cin>>N>>M>>R;
	REP(i,0,R) {
		cin>>r[i];
		r[i]--;
	}
	REP(i,1,1<<R) REP(j,0,200) dp[i][j]=inf;
	REP(i,0,N) REP(j,0,N) if(i!=j)edge[i][j]=inf;
	REP(i,0,M){
		int a,b,c;
		cin>>a>>b>>c;
		a--;b--;
		edge[a][b]=c;
		edge[b][a]=c;
	}
	REP(k,0,N){
		REP(i,0,N){
			REP(j,0,N){
				edge[i][j]=min(edge[i][j],edge[i][k]+edge[k][j]);
			}
		}
	}


	REP(i,0,R){
		dp[1<<i][r[i]]=0;
	}
	REP(i,0,1<<R){
		REP(j,0,R){
			REP(k,0,R){
				if((i&(1<<k))==0&&(i&(1<<j))){
					dp[i|(1<<k)][r[k]] = min(dp[i][r[j]]+edge[r[j]][r[k]],dp[i|(1<<k)][r[k]]);

				}
			}
		}

	}

	p(*min_element(dp[((1<<R)-1)],dp[((1<<R)-1)]+200));
	return 0;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main(){
  int n;
  cin >> n;
  int a[n],b[n-1];
  for(int i=0;i<n-1;i++){
    cin >> b[i];
  }
  a[0] = a[1] = b[0];
  for(int i=1;i<n-1;i++){
    a[i] = min(b[i-1],b[i]);
  }
  a[n-1] = b[n-2];
  int ret = 0;
  for(int i=0;i<n;i++) ret += a[i];
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
#define rep(i, n) for (i32 i = 0; i < (i32)(n); i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64,i64>;

int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
string s;
cin >> s;
i64 ans = 0;
rep(i,s.size()){
    ans += s[i] - '0';
}
cout << (ans % 9 ? "No" : "Yes") << endl;
}

Measured memory_bytes: 3772
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define MAX 200002
#define max( a, b ) ( a > b? a:b )
#define min( a, b ) ( a < b? a:b )
void show( char *s, int Len ){
		for( int i = 0; i < Len; i++ )printf("%c%c", s[i], " \n"[i == Len-1]);
}

int main(){
		int N, A, B, C, D;scanf("%d%d%d%d%d", &N, &A, &B, &C, &D);
		char s[MAX];scanf("%s", s);
		//show( s, N );
		// A < B, if A can reacher, so do B
		// if A can go to D, B can to D too

		//station = ...
		int ptr = B-2;
		int end_ptr = D;
		int station = 0;
		while( ptr < end_ptr ){	
				int counter = 0;
				while( ptr < end_ptr && s[ptr] == '.' ){
						counter++;
						ptr++;	
				}
				ptr++;
				station = max( counter, station );
		}
		//if station == 3
		if( station >= 3 ){
				int start = min(A, B)-1;
				int end = max(C, D)-1;
				if( C > D ){
				}
				for( int i = start; i < end; i++ )
						if( s[i] == '#' && s[i+1] == '#' ){
								puts("No");
								return 0;
						}
		}
		else{
				if( D > C ){
						for( int i = A-1; i < C; i++ ){
								if( s[i] == '#' && s[i+1] == '#' ){
										puts("No");
										return 0;
								}
						}
						for( int i = B-1; i < D; i++ ){
								if( s[i] == '#' && s[i+1] == '#' ){
										puts("No");
										return 0;
								}
						}
				}
				else{// C > D
						if( s[D-1-1] == '#' || s[D-1+1] == '#' ){
								puts("No");
								return 0;
						}
						for( int i = A-1; i < C; i++ ){
								if( s[i] == '#' && s[i+1] == '#' ){
										puts("No");
										return 0;
								}
						}
				}
		}
		puts("Yes");

}

Measured memory_bytes: 384
#include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define pb push_back
    #define printV(v) for(int i=0;i<v.size();i++){cout << v[i]<< " ";} cout << endl
    #define printRev(v) for(int i=v.size()-1;i >= 0;i--){cout << v[i] << " ";} cout << endl
    #define sortV(v) sort(v.begin(),v.end())
    #define revV(v) reverse(v.begin(),v.end())
    #define FOR(i,n) for(int i=0;i<n;i++)
    ll a,b,c,d,e,f,g,n,m,k,t,p,x,y;
 
    ll mod = 998244353;
    
    void solve(){
        int n,x,y;
        cin >> n >> x >> y;
        ll ans[n];
        for(int i=0;i<n;i++) ans[i] = 0;
        for(int i=1; i < n; i++){
            for(int j=i+1; j <= n; j++){
                if(i >= y){
                    ans[j-i]++;
                }else if(i <= x){
                    if(j <= x){
                        ans[j-i]++;
                    }else if( j <= y){
                        int dist = min(j-i,x-i + 1 + (y-j));
                        ans[dist]++;
                    }else{
                        int dist = x - i + 1 + j - y;
                        ans[dist]++;
                    }
                }else{
                    int dist = min(i-x + 1 + abs(y-j),j-i);
                    ans[dist]++;
                }
            }
        }
        for(int i=1;i<n;i++){
            cout << ans[i] << endl;
        }

    }
 
    int main(){
        ios_base::sync_with_stdio(false);

        int cases = 1; 
        //cin >> cases;
       
        while(cases--){
            solve();
        }
        return 0;
 
    }

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 7)
h, w = [int(i) for i in sys.stdin.readline().split()]
MAP = []
memo_ls = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
    inp = [0 if i == "." else 1 for i in input()]
    MAP.append(inp)


memo_ls[h-1][w-1] = 1
for _h in range(h-1,-1,-1):
    for _w in range(w-1,-1,-1):
        if MAP[_h][_w] == 1:
            continue
        if _w < w - 1:
            memo_ls[_h][_w] += memo_ls[_h][_w+1]
        if _h < h - 1:
            memo_ls[_h][_w] += memo_ls[_h+1][_w]
        memo_ls[_h][_w] %= (1e9+7)
print(int(memo_ls[0][0] % (1e9+7)))

Measured memory_bytes: 85340
#include<stdio.h>
int main(void)
{
	int i, n, a;
	double ans;
	scanf("%d", &n);
	if (n % 2 == 0)
	{
		ans = 0.5;
		
	}
	else {
		ans = (double)((n / 2) + 1) / n;
		
	}
	printf("%.8lf", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int arr[3005][3005];
string s1 , s2;
int main() {
	cin>>s1>>s2;
	for(int i = 0 ; i <s1.size(); i++){
		for(int j = 0; j < s2.size() ; j++){
			if(s1[i]==s2[j]){
				arr[i+1][j+1] = arr[i][j]+ 1;
			}
			else
				arr[i+1][j+1] = max(arr[i][j+1] , arr[i+1][j]);
		}
	}
	string ans = "";
	int x = s1.size() , y = s2.size();
	while(x&&y){
		if(arr[x-1][y-1]==arr[x][y]){
			x--;y--;
		}
		else if(arr[x-1][y]>arr[x][y-1]){
			x--;
		}else if(arr[x][y-1]>arr[x-1][y])
			y--;
		else if(arr[x-1][y]==arr[x][y-1]&&arr[x-1][y]==arr[x][y])
			x--;
		else if(arr[x][y]==arr[x-1][y-1]+1){
			x--;
			y--;
			ans+=s1[x];
		}
	}
	reverse(ans.begin(),ans.end());
	cout<<ans;
	return 0;
}


Measured memory_bytes: 35456
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
int main(int argc, char* argv[])
{
  int n;
  std::cin >> n;

  std::vector< int > vd(n, 0);
  for (int i = 0; i < n; i++) {
    int tmp;
    std::cin >> tmp;
    vd[i] = tmp;
  }

  std::sort(vd.begin(), vd.end());
  vd.erase(std::unique(vd.begin(), vd.end()), vd.end());

  std::cout << vd.size() << std::endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 2005
using namespace std;
int c[N][N],s[N][N],w[N][N];
const int p = 1000000007;
int A,B;
int main()
{
    for(int i=0;i<N;i++)
    {
        c[i][0]=s[i][0]=1;
        w[i][0]=i+1;
        for(int j=1;j<=i;j++)
        {
            c[i][j]=(c[i-1][j]+c[i-1][j-1])%p;
            s[i][j]=(s[i][j-1]+c[i][j])%p;
            w[i][j]=1LL*c[i][j]*(i-j+1)%p;
            (w[i][j]+=w[i][j-1])%=p;
        }
    }
    cin>>A>>B;
    int ans=1;
    for(int i=0;i<A;i++)
    {
        // t=A-i
        for(int j=0;j<=A-i;j++)
        {
            // j red A-i-j green
            if(A-i-j==0){ans++;continue;}
            if(j+B-1<A-i)continue;
            int q=0;
            if(j>=A-i-j-1)
            {
                q=w[A-i-j-1][A-i-j-1]+1LL*(j-A+i+j+1)*s[A-i-j-1][A-i-j-1]%p;
                q%=p;
            }
            else
            {
                q=w[A-i-j-1][j]-1LL*(A-i-j-1-j)*s[A-i-j-1][j]%p;
                q=(q+p)%p;
            }
            ans=(ans+1LL*c[B-1][A-i-j]*q%p)%p;
        }
    }
    cout<<ans%p<<endl;
    return 0;
}


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

int main(){
  int N,T;
  cin >> N >> T;
  vector<int> t(N);
  for (int i=0;i<N;++i) cin >> t[i];
  
  int ans=T;
  for (int i=0;i<N;++i){
    ans+=min(T, t[i]-t[i-1]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K , S , i , j , k, cnt=0;
  
  cin >> K >> S;

  for( i = 0 ; i <= K ; i++ ){
    for( j = 0 ; j <= K ; j++ ){
       if ( S-(i+j) <= K ){
         if(S-(i+j) >= 0){
           cnt++;
         } else {
           break;
         }
       }
    }
  }
  
  cout << cnt << endl;
  

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 double dp[3001][3001];
 double fun(int i, int x, double *arr){
        if(x > i){
            return 0;
        }
    
        if(x <= 0 && i >= 0)
           return 1;
        
        if(dp[i][x] > -0.9){
            return dp[i][x];
        }   
           

        dp[i][x] = fun(i-1,x,arr)*(1.0-arr[i]) + fun(i-1,x-1,arr)*(arr[i]);
        return dp[i][x];
 }
void solve(){
    int n;
    cin >> n;
    double *arr = new double[n+1];
    for(int i =1 ; i<=n; i++){
        cin >> arr[i];
    }
    for(int i=0; i< 3001; i++){
         for(int j=0; j<3001; j++){
              dp[i][j]  = -1.0;
         }
    }
     cout << fixed << setprecision(10)<<fun(n,(n+1)/2,arr);
}
int main(){
//  #ifndef ONLINE_JUDGE
//   freopen("input.txt", "r", stdin);
//   freopen("output.txt", "w", stdout);
// #endif 

solve();
return 0;
}

Measured memory_bytes: 70784
#include <stdio.h>
int main(void){
	long long n,i,a[100001],b[100001];
	scanf("%lld",&n);
	for(i=0;i<=100000;i++){a[i]=0;b[i]=0;}
	for(i=0;i<n/2;i++){
		long long x,y;
		scanf("%lld%lld",&x,&y);
		a[x]++;
		b[y]++;
	}
	long long a1=0,a2=0,b1=0,b2=0,c,d;
	for(i=1;i<100001;i++){
		if(a[i]>=a1){
			a2=a1;
			a1=a[i];
			c=i;
		}else if(a[i]>a2)a2=a[i];
		
		if(b[i]>=b1){
			b2=b1;
			b1=b[i];
			d=i;
		}else if(b[i]>b2)b2=b[i];
	}
	if(c!=d){
		printf("%lld",n-a1-b1);
	}else{
		if(a1>b1)printf("%lld",n-a1-b2);
		else if(a1<b1) printf("%lld",n-b1-a2);
		else{
			if(a2>b2)printf("%lld",n-a2-a1);
			else printf("%lld",n-b2-b1);
		}
	}
	
	
	return 0;
}

Measured memory_bytes: 1664
M = 10**9+7
n,a,b = map(int,input().split())

def nCr(n,r,m):
    a = b = 1
    for i in range(r):
        a = a * (n-i) % m
        b = b * (r-i) % m
    return a * pow(b, m-2, m) % m

ans = pow(2,n,M) - 1
ans -= nCr(n,a,M)
ans -= nCr(n,b,M)
ans %= M
if ans<0: ans += M
print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#define int long long

using namespace std;

const int N=109,INF=1<<30;
int flag[N],head[N],cnt,deg[N],n;
struct Tree
{
	int head[N],cnt,F[N],x[N],y[N];
	struct Edge
	{
		int nxt,to;
	}g[N*2];
	
	void add(int from,int to)
	{
		g[++cnt].nxt=head[from];
		g[cnt].to=to;
		head[from]=cnt;
	}
	
	void clear()
	{
		cnt=0;
		memset(head,0,sizeof(head));
	}
	
	void dfs(int x,int fa)
	{
		for (int i=head[x];i;i=g[i].nxt)
		{
			int v=g[i].to;
			if(v==fa)
				continue;
			F[v]=x,dfs(v,x);
		}
	}
}A,B,C;

void DFS_A(int x,int fa)
{
	for (int i=A.head[x];i;i=A.g[i].nxt)
	{
		int v=A.g[i].to;
		if(v==fa)
			continue;
		if(flag[v]&&flag[x])
			C.add(v,x);
		DFS_A(v,x);
	}
}

void DFS_B(int x,int fa)
{
	for (int i=B.head[x];i;i=B.g[i].nxt)
	{
		int v=B.g[i].to;
		if(v==fa)
			continue;
		if(flag[x]&&flag[v])
			C.add(x,v);
		DFS_B(v,x);
	}
}

void init()
{
	B.clear();
	memset(deg,0,sizeof(deg));
	scanf("%lld",&n);
	for (int i=1;i<n;i++)
		scanf("%lld %lld",&A.x[i],&A.y[i]),deg[A.x[i]]++,deg[A.y[i]]++;
	for (int i=1,x,y;i<n;i++)
		scanf("%lld %lld",&x,&y),B.add(x,y),B.add(y,x);
}

bool TP_sort()
{
	int ans=n;
//	for (int i=1;i<=n;i++)
//		if(flag[i]) ans++;
	queue <int> q;
	static int Deg[N];
	memset(Deg,0,sizeof(Deg));
	for (int i=1;i<=n;i++)
		for (int j=C.head[i];j;j=C.g[j].nxt)
		{
			int v=C.g[j].to;
			Deg[v]++;
		}
//	puts("!!!");
//	for (int i=1;i<=n;i++)
//		for (int j=C.head[i];j;j=C.g[j].nxt)
//			printf("%lld %lld\n",i,C.g[j].to);
	for (int i=1;i<=n;i++)
		if(Deg[i]==0) ans--,q.push(i);
	while(!q.empty())
	{
		int x=q.front();q.pop();
		for (int i=C.head[x];i;i=C.g[i].nxt)
		{
			int v=C.g[i].to;
			Deg[v]--;
			if(Deg[v]==0)
				ans--,q.push(v);
		}
	}
//	printf("ans:%lld\n",ans);
	return !ans;
}

void work()
{
	int ans=INF;
	for (int i=1;i<=n;i++)
	{
		if(deg[i]!=1) continue;
		for (int j=1;j<=n;j++)
		{
			if(i==j) continue;
			int qwq=1;
			for (int k=1;k<n;k++)
				if((A.x[k]==i&&A.y[k]==j)||(A.x[k]==j&&A.y[k]==i))
				{
					qwq=0;
					break;
				}
			A.clear();
			for (int k=1;k<n;k++)
				if(A.x[k]!=i&&A.y[k]!=i)
					A.add(A.x[k],A.y[k]),A.add(A.y[k],A.x[k]);
			A.add(i,j),A.add(j,i);
			A.dfs(i,A.F[i]=-1),B.dfs(i,B.F[i]=-1);
			int tmp=0;
			for (int k=1;k<=n;k++)
				tmp+=(flag[k]=!(A.F[k]==B.F[k]));
			int qaq=1;
			for (int k=1;k<=n;k++)
				if(k!=i&&flag[B.F[k]]&&!flag[k])
				{
					qaq=0;
					break;
				}
			if(!qaq) continue;
			C.clear();
			DFS_A(i,-1),DFS_B(i,-1);
//			printf("i,j:%lld %lld\n",i,j);
//			for (int i=1;i<=n;i++)
//				printf("%lld ",flag[i]);puts("");
			ans=min(ans,TP_sort()?tmp+qwq:INF);
		}
	}
	if(ans==INF)
		printf("-1\n");
	else
		printf("%lld\n",ans);
}

signed main()
{
	int T;
	scanf("%lld",&T);
	while(T--)
	{
		init();
		work();
	}
	return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

using namespace std;

int main(){
  int N;
  cin >> N;
  rep(i,N){
    char x;
    cin >> x;
    if(x == 'Y'){
      cout << "Four" << endl;
      return 0;
    }
  }
  cout << "Three" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int a, b;
	cin >> a >> b;
	if (a >= 13) {
		cout << b << '\n';
	} else if (a >= 6) {
		cout << b / 2 << '\n';
	} else {
		cout << 0 << '\n';
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
   int n,count=0;
   scanf("%d",&n);
   char s[n];
   scanf("%s",s);
   int i;
   for(i=0;i<n;i++){
      if(i<n-2){
         if(s[i]=='A'){
            if(s[i+1]=='B'){
               if(s[i+2]=='C'){
                  count++;
               }
            }
         }
      }
   }
   printf("%d",count);
   return 0;
}


Measured memory_bytes: 3204
#!/usr/bin/env python3
from collections import deque
import sys
sys.setrecursionlimit(700000)

NIL = -1
N, M, K = map(int, input().split())
relation = [deque() for i in range(N)]
prefriends = [deque() for i in range(N)]

for i in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    relation[A].append(B)
    relation[B].append(A)

def dfs(x, y):
    for i in relation[y]:
        if check[i] == None:
            #print(i)
            prefriends[x].append(i)
            #print(set(prefriends[x]))
            check[i] = x
            dfs(x, i)

#print(prefriends)
j = 0
check = [None]*N
while j < N:
    if check[j] == None:
        #print(prefriends[j])
        prefriends[j].append(j)
        check[j] = j
        dfs(j, j)
        #print(check)
    j += 1
    #print(set(prefriends[j]))
    #print(set(friends[j]))
    #print(set(block[j]))
    #print((set(prefriends[j]) - set(friends[j])) - set(block[j]))

for i in range(K):
    C, D = map(int, input().split())
    C -= 1
    D -= 1
    if check[C] == check[D]:
        relation[C].append(D)
        relation[D].append(C)
ans = [0]*N
for j in range(N):
    ans[j] = len(prefriends[check[j]]) - len(relation[j]) - 1
    #print(ans[j])
    #print()
print(*ans)

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


int main() {
	//code
	int a,b;
	cin>>a>>b;
	if(b%2!=0){
        cout<<"No";
        return 0;}
	int x,y;
	x=(b-(2*a))/2;
	y=a-x;
	if(x>=0 && y>=0) cout<<"Yes";
	else cout<<"No";
	return 0;
}


Measured memory_bytes: 3632
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial
from heapq import heappop, heappush, heappushpop
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    from functools import reduce
    from fractions import gcd
    N = I()
    A = LI()
    GCD = reduce(gcd, A)
    ans=0
    while GCD % 2 == 0:
        ans += 1
        GCD //= 2
    print(ans)

if __name__ == '__main__':
    main()

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

int main() {
	int a, b, c, d = 0;
	cin >> a >> b >> c >> d;
	while (a > 0 || c > 0) {
		c -= b;
		if (c < 1) {
			cout << "Yes" << endl;
			break;
		}
		a -= d;
		if (a < 1) {
			cout << "No" << endl;
			break;
		}
	}
}

Measured memory_bytes: 3636
let lines = [];
let reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});

// 標準入力の読み込み
reader.on('line', function(line) {
    lines.push(line);
});

reader.on('close', function() {
    let d1 = [];
    let d2 = [];
    // 処理の記述
    const n = lines[0];
    
    let zorome = 'No';
    for (let i = 1; i < n; i++) {
        d1.push(lines[i].split(' ')[0]);
        d2.push(lines[i].split(' ')[1]);
    }
    for (let i = 0; i < n - 2; i++) {
        if (d1[i] == d2[i]) {
            if (d1[i+1] == d2[i+1]) {
                if (d1[i+2] == d2[i+2]) {
                    zorome = 'Yes';
                    break;
                }
            }
        }

    }

    // 表示
    console.log(zorome);
});

Measured memory_bytes: 30164
import heapq
n, m = map(int, input().split())
a = list(map(lambda x: int(x) * (-1), input().split()))
heapq.heapify(a)

for i in range(m):
    x = heapq.heappop(a)
    heapq.heappush(a, -1 * ((-x) // 2))
print(-sum(a))

Measured memory_bytes: 14180
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <random>
#include <tuple>

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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const ll INF = 1e18;
struct LazySegmentTree {
private:
    int n;
    vector<ll> node, lazy;

public:
    LazySegmentTree(vector<ll> v) {
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, INF);

        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }

    void eval(int k, int l, int r) {
        if(lazy[k] != INF) {
            node[k] = lazy[k];
            if(r-l > 1) {
                lazy[2*k+1] = lazy[k];
                lazy[2*k+2] = lazy[k];
            }
            lazy[k] = INF;
        }
    }

    void update(int a, int b, ll x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] = x;
            eval(k, l, r);
        }
        else {
            update(a, b, x, 2*k+1, l, (l+r)/2);
            update(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = min(node[2*k+1], node[2*k+2]);
        }
    }

    ll getmin(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return INF;
        if(a <= l && r <= b) return node[k];
        ll vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
    }

};


int main() {
    int n, m;
    cin >> n >> m;
    vector<pair<int, pair<int,ll> > > query;
    rep(i, m){
        int l_, r_;
        ll c;
        cin >> l_ >> r_ >> c;
        l_--;
        r_--;
        query.push_back(make_pair(l_, make_pair(r_, c)));
    }

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

    LazySegmentTree seg(vector<ll> (n, INF));
    seg.update(0, 1, 0);

    rep(i, m) {
        int l_ = query[i].first;
        int r_ = query[i].second.first;
        ll c = query[i].second.second;
        ll mind = seg.getmin(l_, n);
        if (mind+c < seg.getmin(r_, r_+1)) seg.update(r_, r_+1, mind+c);
    }

    if (seg.getmin(n-1, n) == INF) cout << -1 << endl;
    else cout << seg.getmin(n-1, n) << endl;
    

    return 0;
}

Measured memory_bytes: 8176
import sys
input=sys.stdin.readline
n,u,v = map(int, input().split())
link = [[] for _ in range(n)]
for i in range(n-1):
    tmp = list(map(int,input().split()))
    link[tmp[0]-1].append(tmp[1]-1)
    link[tmp[1]-1].append(tmp[0]-1)

from collections import deque
Q = deque()
Q.append([v-1,0])
visited=[-1]*n
visited[v-1]=0
while Q:
    now,cnt = Q.popleft()
    for nxt in link[now]:
        if visited[nxt]!=-1:
            continue
        visited[nxt]=cnt+1
        Q.append([nxt,cnt+1])
Q = deque()
Q.append([u-1,0])
v_taka=[-1]*n
v_taka[u-1]=0
while Q:
    now,cnt = Q.popleft()
    for nxt in link[now]:
        if v_taka[nxt]!=-1:
            continue
        if visited[nxt] <= cnt+1:
            continue
        v_taka[nxt]=cnt+1
        Q.append([nxt,cnt+1])
ans=-1
for i in range(n):
    if v_taka[i] == -1:
        continue
    if ans < visited[i]:
        ans=visited[i]
print(ans-1)

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

int main() {
	int n, m;

	while (cin >> n >> m, !(n == 0 && m == 0)) {
		vector<int> ts(100, 0), hs(100, 0);
		int tsum = 0, hsum = 0;
		for (int i = 0; i < n; ++i) {
			cin >> ts[i];
			tsum += ts[i];
		}
		for (int i = 0; i < m; ++i) {
			cin >> hs[i];
			hsum += hs[i];
		}
		sort(ts.begin(), ts.begin()+n);
		sort(hs.begin(), hs.begin()+m);
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < m; ++j) {
				if (tsum + hs[j] - ts[i] == hsum + ts[i] -hs[j]) {
					cout << ts[i] << " " << hs[j] << endl;
					goto escape;
				}
			}
		}
		cout << -1 << endl;
	escape:;
	}
	return 0;
}

Measured memory_bytes: 1216
#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++)
using Graph = vector<vector<int>>;
using ll = long long;


int main() {
    ll n;
    cin>>n;
    vector<char> c(n);
    rep(i,n){
        cin>>c[i];
    }
    int rcount=0;
    rep(i,n){
        if(c[i]=='R'){
            rcount++;
        }
    }
    int wcount=0;
    rep(i,rcount){
        if(c[i]=='W'){
            wcount++;
        }
    }
    cout<<wcount<<endl;
}

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

int main()
{
    int n,ans=0,mans=0;
    cin>>n;
    int a[2][n];
    for (int i=0; i<2; i++)
    {
        for (int j=0; j<n; j++)
        {
            cin>>a[i][j];
        }
    }
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<=i; j++) ans+=a[0][j]; //upper
        for (int j=i; j<n; j++) ans+=a[1][j]; //lower
        mans=max(mans,ans);
        ans=0;
    }
    cout<<mans;
    return 0;
}


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

#define int long long
typedef vector<int> vec;
typedef vector<vec> mat;
#define N 3

int po[N*N+10];
int m2i(mat m){
  int res=0;
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      res+=m[i][j]*po[i*N+j];
  return res;
}
mat i2m(int x){
  mat res(N,vec(N));;
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      res[i][j]=(x%po[i*N+j+1])/po[i*N+j];
  return res;
}

signed main(){
  po[0]=1;
  for(int i=0;i<N*N;i++) po[i+1]=po[i]*10;
  mat p(N,vec(N));
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      cin>>p[i][j];
  mat e(p);
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      e[i][j]=i*N+j+1;
  e[N-1][N-1]=0;
  int ans=m2i(e);
  queue<int> q;
  map<int,int> m;
  q.push(m2i(p));
  m[m2i(p)]=0;
  int ax[]={1,0,-1,0};
  int ay[]={0,1,0,-1};
  while(!q.empty()){
    int x=q.front();q.pop();
    if(x==ans) break;
    p=i2m(x);
    int zy,zx;
    for(int i=0;i<N;i++)
      for(int j=0;j<N;j++)
        if(p[i][j]==0) zy=i,zx=j;
    for(int k=0;k<4;k++){
      int ny=zy+ay[k],nx=zx+ax[k];
      if(ny<0||N<=ny||nx<0||N<=nx) continue;
      swap(p[zy][zx],p[ny][nx]);
      int t=m2i(p);
      if(!m.count(t)){
        m[t]=m[x]+1;
        q.push(t);
      }
      swap(p[zy][zx],p[ny][nx]);
    }
  }
  cout<<m[ans]<<endl;
  return 0;
}



Measured memory_bytes: 14552
#include<bits/stdc++.h>
using namespace std;
#define IOS std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define FRE freopen("in.txt", "r", stdin);
#define endl "\n"
#define PI acos(-1.0)
typedef long long LL;
typedef pair<int, int> PII;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
const int N = 3010, M = 1010;


void solve() {
	double r;
	cin >> r;
	cout << 2 * PI * r << endl;
}

int main() {
	//FRE;
	int t;
	solve();
	return 0;
}

Measured memory_bytes: 3780
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>

using namespace std;
using namespace __gnu_pbds;

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define F first
#define S second
#define vec(x) vector<x> 
#define pi(x,y) pair<x,y>
#define pqq(x) priority_queue<x> 
#define min_heap(x) priority_queue<x, vector<x>, greater<x> >
#define all(x) x.begin(),x.end()
#define rep(i,x,y) for(int i=x;i<y;i++)
#define repd(i,x,y,k) for(int i=x;i<y;i+=k)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define rev(x) reverse(all(x))
#define full(x,a) memset(x,a,sizeof(x))
#define lcm(x,y) ((x*y)/__gcd(x,y))
#define mod 1000000007
#define bitcount __builtin_popcountll
#define pb push_back
#define indexof order_of_key
#define valueat find_by_order

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


main(){
	fastio;
	int k;
	cin>>k;
	int ans=0;
	for(int a=1;a<=k;a++){
		for(int b=1;b<=k;b++){
			for(int c=1;c<=k;c++){
				ans=ans+__gcd(__gcd(a,b),c);
			}
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3640
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W;
typedef long long ll;
typedef pair<ll, ll> Pa;

int main()
{
    cin >> N >> M;
    cout << (1900*M+100*(N-M))*(1<<M);
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(c) c.begin(), c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main() {
    int A, B;
    char op;
    cin >> A >> op >> B;

    if (op == '+') {
        cout << A + B;
    } else {
        cout << A - B;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		@SuppressWarnings("resource")
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] p = new int[n];
		for (int i = 0; i < n; i++) {
			p[i] = scanner.nextInt();
		}
		int count = 0;
		for (int i = 1; i < n - 1; i++) {
			if (p[i - 1] < p[i] && p[i] < p[i + 1]) {
				count++;
				continue;
			}
			if (p[i + 1] < p[i] && p[i] < p[i - 1]) {
				count++;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n, k, a = 1;
    cin >> n >> k;
    rep(i, n)a = min(a*2, a+k);
    cout << a << endl;
}


Measured memory_bytes: 256
#include <cstdio>
int N,A[10];
bool dfs(int x,int B,int C) {
	bool ans=false;
	if(x==10) return true;
	if(B<A[x])ans=dfs(x+1,A[x],C);
	if(C<A[x])ans=ans||dfs(x+1,B,A[x]);
	return ans;
}
int main() {
	scanf("%d",&N);
	for(int i=0;i<N;i++) {
		for(int j=0;j<10;j++)
			scanf("%d",&A[j]);
		printf("%s\n",dfs(0,0,0)?"YES":"NO");
	}
}

Measured memory_bytes: 1008
#include<stdio.h>
#include<math.h>
int min(int a, int b)
{
    if (a < b)
        return a;
    else
        return b;
}
int main()
{
    int n, k;
    scanf("%d %d", &n, &k);
    int i, j;
    int h[100005];
    for (i = 0; i < n; i++)
        scanf("%d", &h[i]);
    int dp[100005];
    for (i = 0; i < n; i++)
        dp[i] = 2000000000;
    dp[0] = 0;
    for (i = 0; i < n - 1; i++)
        for (j = i + 1; j <= min(n - 1, i + k); j++)
            dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
    printf("%d\n", dp[n - 1]);
    return 0;
}

Measured memory_bytes: 896
#![allow(non_snake_case)]
#[allow(unused_imports)]
use std::io::{self, Write};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, char) => {
        read_value!($next, String).chars().collect::<Vec<char>>()[0]
     };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
     };
    ($next:expr, isize1) => {
        read_value!($next, isize) - 1
    };
     ($next:expr, $t:ty) => {
         $next().parse::<$t>().expect("Parse error")
    };
}
macro_rules! printvec {
    ( $item:expr ) => {
        for &i in &$item {
            print!("{} ", i);
        }
        println!("");
    }
}
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}
#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);
impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}
impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}
#[derive(PartialEq, PartialOrd, Clone, Debug)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}
#[allow(dead_code)]
const MOD: usize = 1000000007;


fn main() {
    input!{
        N: usize,
        H: [usize; N],
    }
    let mut ans = 0;
    let mut tmp = 0;
    for i in 0..N-1 {
        if H[i] >= H[i+1] {
            tmp += 1;
        } else {
            ans = max(ans, tmp);
            tmp = 0;
        }
    }
    ans = max(ans, tmp);
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

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

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

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

  vector<int> a(N);
  rep(i,N) cin>>a[i];

  sort(a.begin(),a.end(),greater<int>());

  int S=0,T=0;

  rep(i,N){
  if(i%2==0){S+=a[i];}
  else{T+=a[i];}
  }

cout<<S-T<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int parity(int A) {
  return __builtin_popcount(A) % 2;
}

int bit(int A, int i) {
  return (A >> i) & 1;
}

int extract(int A, int i) {
  int up = A >> (i + 1);
  int bt = A & ((1 << i) - 1);
  return (up << i) | bt;
}

int embed(int A, int i, int b) {
  int up = A >> i;
  int bt = A & ((1 << i) - 1);
  return (((up << 1) | b) << i) | bt;
}

vector<int> solve(int A, int B, int N) {
  if (N == 1) return {A, B};
  int k;
  for (int i = 0; i < N; i++) {
    if (bit(A, i) != bit(B, i)) {
      k = i;
      break;
    }
  }
  int X = extract(A, k);
  int Y = X ^ 1;
  int Z = extract(B, k);
  vector<int> res;
  for (int m : solve(X, Y, N - 1)) res.push_back(embed(m, k, bit(A, k)));
  for (int m : solve(Y, Z, N - 1)) res.push_back(embed(m, k, bit(B, k)));
  return res;
}

int main() {
#ifdef DEBUG
  ifstream cin("in.txt");
#endif
  int N, A, B;
  while (cin >> N >> A >> B) {
    if (parity(A) == parity(B)) {
      cout << "NO" << endl;
      continue;
    }
    cout << "YES" << endl;
    for (int m : solve(A, B, N)) {
      cout << m << " ";
    }
    cout << endl;
  }
  return 0;
}


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

int main() {
  string s, t;
  cin >> s >> t;
  vector<char> vecs(26,-1);
  vector<char> vect(26,-1);
  bool ok = true;
  rep(i,s.size()) {
    if(vecs.at((int)s.at(i)-97)<0) vecs.at((int)s.at(i)-97) = t.at(i);
    else {
      if(vecs.at((int)s.at(i)-97) != t.at(i)) ok = false;
    }
  }
  rep(i,t.size()) {
    if(vect.at((int)t.at(i)-97)<0) vect.at((int)t.at(i)-97) = s.at(i);
    else {
      if(vect.at((int)t.at(i)-97) != s.at(i)) ok = false;
    }
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 776
#include<bits/stdc++.h> 
using namespace std; 
 
int main() { 
  int n, tmp, even[100003], odd[100003] = {0}, mode_e, mode_o, mode_e_count = 0, 
                                                       mode_o_count = 0; 
  cin >> n; 
  for (int i = 0; i < n; i++) { 
    cin >> tmp; 
    if (i % 2 == 0) { 
      even[tmp]++; 
      if (even[tmp] > mode_e_count) { 
        mode_e = tmp; 
        mode_e_count = even[tmp]; 
      } 
    } else { 
      odd[tmp]++; 
      if (odd[tmp] > mode_o_count) { 
        mode_o = tmp; 
        mode_o_count = odd[tmp]; 
      } 
    } 
  } 
  sort(even, even + 100003); 
  sort(odd, odd + 100003); // odd has to be initialized explicitly?
 
  if (mode_e != mode_o) { 
    cout << n - mode_o_count - mode_e_count; 
  } else { 
    cout << n - max(even[100001] + mode_o_count, odd[100001] + mode_e_count); 
  } 
}



Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(void)
{
    int P, Q, R;
    cin >> P >> Q >> R;
    cout << (P + Q + R - max(P, max(Q, R))) << endl;
    return 0;
}

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

const int N = 1e3+100;

int A[N];
int main(){
  int n , k;
  cin >>n >> k;
  for(int i = 0;i < n;  ++i)
    cin >> A[i];
  sort(A, A+n);
  int ans = 0;
  for(int i = 0;i < k ; ++i)
    ans += A[i];
  cout << ans << endl;
  return 0;

}


Measured memory_bytes: 3652