akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

int A[100050];
Int R[100050], RA[100050];

int main() {
  int N = in() + 1;
  for (int i = 0; i < N; ++i) {
    A[i] = in();
  }

  if (N == 1) {
    printf("%d\n", A[0] == 1 ? 1 : -1);
    return 0;
  }
  if (A[0] != 0) {
    puts("-1");
    return 0;
  }

  for (int i = 0; i < N - 1; ++i) {
    R[i] = 1;
  }
  R[N - 1] = 0;
  --A[N - 1];

  Int res = N;
  int fi = 0;
  for (int i = 1; i < N; ++i) {
    if (A[i] == 0) {
      continue;
    }
    int ad = A[i];
    while (true) {
      if (fi == i) {
        puts("-1");
        return 0;
      }
      const Int t = min((Int)ad, R[fi]);
      res += (i - fi) * t;
      // cerr<<t<<' '<<fi<<' '<<i<<endl;
      R[fi] -= t;
      ad -= t;
      // for (int k = fi + 1; k < i; ++k) R[k] += t;
      RA[fi + 1] += t;
      RA[i] -= t;
      if (R[fi] == 0) {
        RA[fi + 1] += RA[fi];
        R[fi + 1] += RA[fi + 1];
        ++fi;
      }
      if (ad == 0) {
        break;
      }
    }
  }

  printf("%lld\n", res);

  return 0;
}


Measured memory_bytes: 5768
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>

using namespace std;

void solve3() {
	int X;
	cin >> X;
	int t = 0;
	while (1)
	{
		if (t*(t + 1) / 2 >= X) {
			cout << t;
			return;
		}
		t++;
	}
}

int main() {
	solve3();
}

Measured memory_bytes: 256
import numpy as np
 
mod = 10 ** 9 + 7
 
N = int(input())
A = np.array(list(map(int, input().split())))
 
 
ans = 0
for n in range(len(bin(max(A)))):   # 最大桁数は、最も大きい数値の2進数の桁数
    num_1 = np.count_nonzero((A >> n)&1)   # 1の数をカウント
    num_0 = N - num_1                      # 0の数をカウント
    mul = num_1 * num_0   # 0 XOR 1の回数
    ans += ((2 ** n)*mul) % mod
ans %= mod
print(ans)


Measured memory_bytes: 48828
#include<iostream>
using namespace std;
int main(){
    int n[101];
    int i;
    for( i = 0;i < 101;i++){
        n[i] = 0;
        
    }
    for( i = 1;i != 0;i){
        i = 0;
        cin  >> i;
        n[i]++;
    }
    int max = 1;
    for( i = 2;i < 101;i++){
       
        if(n[max] <= n[i]){
            max = i;
            
        }
    }
    for( i = 1;i < 101;i++){
        if(n[i] == n[max]){
            cout << i <<endl;
        }
    }
    return 0;

}


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

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
clock_t startTime;
long double getTime(){
	return (long double)(clock()-startTime)/CLOCKS_PER_SEC;
}
ll n;
string s;
ll mod=1e9+7;


int main(){
	startTime=clock();
	cin >> n ;
	ll ans[26];
	FOR(i,26) ans[i]=1;
	char* c=new char[n];
	FOR(i,n) {
		cin >> c[i];
		ans[c[i]-'a']+=1;
	}
	ll sum=1;
	
	FOR(i,26){
		sum=(sum% mod)*(ans[i]% mod) % mod;

	} 
	cout << (sum-1) % mod;


	return 0;
}

Measured memory_bytes: 3740
def test():
    li = list(map(int, input().split()))
    w = li.pop(0)
    h = li.pop(0)
    if w < li[0] + li[2] or h < li[1] + li[2] or li[0] <= 0 or li[1] <= 0:
        print('No')
    else:
        print('Yes')

if __name__ == '__main__':
    test()



Measured memory_bytes: 5600
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007ll
#define INF 1000000000
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// まずは全探索
int main() {
cin.tie(0);
ios::sync_with_stdio(false);

string s; cin >> s;
if (s[0] == s[1]){
    cout << "1 2\n";
    return 0;
}
else if (s.size() == 2){
    cout << "-1 -1\n";
    return 0;
}

// 3文字ごとに見ていく．
//文字バケット
VI chara(26, 0);
++chara[s[0] - 'a'];
++chara[s[1] - 'a'];

rep(i, 0, s.size()-2){
    if (++chara[s[i + 2] - 'a'] == 2) {
        cout << i+1 << ' ' << i + 3 << "\n";
        return 0;
    }
    else --chara[s[i] - 'a'];
}

cout << "-1 -1\n";

}

// 境界，出力文字列 チェック



Measured memory_bytes: 512
n, m = map(int, input().split())
link = [[] for _ in range(n)]
for i in range(m):
    tmp = list(map(int,input().split()))
    link[tmp[0]-1].append(tmp[1]-1)
    link[tmp[1]-1].append(tmp[0]-1)
lis = list(range(1,n))
ans=0
from itertools import *
for perm in list(permutations(lis)):
    last=0
    ok=1
    for i in range(len(perm)):
        if perm[i] not in link[last]:
            ok=0
        last=perm[i]
    ans+=ok
print(ans)

Measured memory_bytes: 40432
def main():
    n, a, b, c, d = map(int, input().split())
    s = input()
    s = '.' + s

    if '##' in s[a+1:c] or '##' in s[b+1:d]:
        print('No')
    else:
        if c < b:
            print('Yes')
        elif c < d:
            print('Yes')
        else:
            if '...' in s[b-1:d+2]:
                print('Yes')
            else:
                print('No')


if __name__ == '__main__':
    main()


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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cout << fixed << setprecision(12);
  int a,b; cin>>a>>b;
  cout<<max({a+b,a-b,a*b})<<endl;
  

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <bitset>
#include <vector>
#include <queue>
#define PB push_back
#define PII pair<int,int>
#define MP make_pair
#define fir first
#define sec second
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=getchar();}
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int N=1010,M=1003;
vector<int> G[N];
int n,m;
int vis[N][2],cur,tg;
void dfs(int u) {
	if(vis[u][cur]) return;
	vis[u][cur]=tg;
	for(int i=0;i<G[u].size();++i) dfs(G[u][i]);
}
int p1[N][N],p2[N][N],mp[N][N];
void sol(int s) {
	for(int i=1;i<=n;++i) vis[i][0]=vis[i][1]=i==s;
	cur=0; for(int i=1;i<=n;++i) if(mp[s][i]) tg=i,dfs(i);
	cur=1; for(int i=n;i>=1;--i) if(mp[s][i]) tg=i,dfs(i);
	for(int i=1;i<=n;++i) if(s!=i) {
		p1[s][i]=vis[i][0]||vis[i][1];
		p2[s][i]=p1[s][i]&&(vis[i][0]!=i||vis[i][1]!=i);
	}
}
vector<PII> E;
int main() {
	rd(n),rd(m);
	for(int i=1,x,y;i<=m;++i) rd(x),rd(y),G[x].PB(y),mp[x][y]=1,E.PB(MP(x,y));
	for(int i=1;i<=n;++i) sol(i);
	for(int i=0;i<E.size();++i) { 
		int x=E[i].fir,y=E[i].sec,flg;
		if(p1[y][x]) flg=(p2[x][y]==1);
		else flg=(p2[x][y]==0);
		if(flg) printf("same\n");
		else printf("diff\n");
	}
	return 0;
}
	

Measured memory_bytes: 16368
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    s1 = list(input())
    rev1 = s1[::-1]
    n = len(s1)
    s2 = s1[0:(n-1)//2]
    rev2 = s2[::-1]
    s3 = s1[(n+3)//2-1:n]
    rev3 = s3[::-1]
    if s1 == rev1 and s2 == rev2 and s3 == rev3:
        print("Yes")
    else:
        print("No")

    return

#Solve
if __name__ == "__main__":
    solve()

Measured memory_bytes: 3316
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <climits>
using namespace std;
#define MOD int(1e9 + 7)
#define INF (long long)(1e18)

int main()
{
    long long N;
    vector<long long> c(26, 1);

    cin >> N;
    for(long long i = 0; i < N; i++){
        char t;
        cin >> t;
        c[t - 'a']++;
    }

    long long total = 1;
    for(long long i = 0; i < 26; i++){
        total *=  c[i];
        total %= MOD;
    }

    cout << total - 1 << endl;
}

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

int main(){
  int N, M, count, max;
  cin >> N;
  vector<string> s(N);
  for (int i=0; i<N; i++) {
    cin >> s.at(i);
  }
  cin >> M;
  vector<string> t(M);
  for (int i=0; i<M; i++) {
    cin >> t.at(i);
  }
  max = 0;
  for (int i=0; i<N; i++) {
    count = 0;
    for (int j=0; j<N; j++) {
      if (s.at(i) == s.at(j))
        count++;
    }
    for (int j=0; j<M; j++) {
      if (s.at(i) == t.at(j))
        count--;
    }
    if (count > max)
      max = count;
  }
  cout << max << endl;
}

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

#define CIN1(a) long long a;cin >> a;
#define CIN2(a,b) long long a,b;cin >> a >> b;
#define CIN3(a,b,c) long long a,b,c;cin >> a >> b >> c;
#define rep(i,n) for(int i=0,i##_len=(n); i<i##_len; ++i)

int main(){
    CIN2(n,k)
    double ans = 0;
    rep(i,n){
        long long tmp = (long long)i+1;
        double ans_tmp = 1.0;
        while(tmp<k){
            tmp *= 2;//cout << tmp << endl;
            ans_tmp /= 2;
        }
        ans += ans_tmp;
    }
    ans = ans/n;
    printf("%.16f\n",ans);
}





Measured memory_bytes: 256
def f(n):
    if n % 2 == 0:
        return n // 2
    else:
        return 3*n + 1
s = int(input())
a = [0]
a.append(s)
for i in range(2,10**7+1):
    x = a[-1]
    y = f(x)
    if y in a:
        print(i)
        break
    a.append(y)

Measured memory_bytes: 3060
n = int(input())
s = input()

r = [0] * (n)
g = [0] * (n)
b = [0] * (n)
if s[0] == 'R':
  r[0] = 1
elif s[0] == 'G':
  g[0] = 1
else:
  b[0] = 1

for i in range(n-1):
  r[i+1] = r[i]
  g[i+1] = g[i]
  b[i+1] = b[i]
  
  if s[i+1] == 'R':
    r[i+1] += 1
  elif s[i+1] == 'G':
    g[i+1] += 1
  else:
    b[i+1] += 1
    
ans = 0
for i in range(n):
  if s[i] == 'R':
    for j in range(i+1,n):
      if j+1 >= n:
        continue
        
      if s[j] == 'G':
        ans += b[-1] - b[j]
        if j+j-i < n and s[j+j-i] == 'B':
          ans -= 1
          
      if s[j] == 'B':
        ans += g[-1] - g[j]
        if j+j-i < n and s[j+j-i] == 'G':
          ans -= 1        
        
  if s[i] == 'G':
    for j in range(i+1,n):
      if j+1 >= n:
        continue
        
      if s[j] == 'R':
        ans += b[-1] - b[j]
        if j+j-i < n and s[j+j-i] == 'B':
          ans -= 1        
        
      if s[j] == 'B':
        ans += r[-1] - r[j]
        if j+j-i < n and s[j+j-i] == 'R':
          ans -= 1        
        
  if s[i] == 'B':
    for j in range(i+1,n):
      if j+1 >= n:
        continue
        
      if s[j] == 'G':
        ans += r[-1] - r[j]
        if j+j-i < n and s[j+j-i] == 'R':
          ans -= 1        
        
      if s[j] == 'R':
        ans += g[-1] - g[j]
        if j+j-i < n and s[j+j-i] == 'G':
          ans -= 1        

        
print(ans)
        


Measured memory_bytes: 69208
import java.io.IOException;
import java.util.HashMap;

public class Main {

	public static void main(String[] args) {
		while (true) {
			int n = nextInt();
			if (n == 0) {
				break;
			}

			HashMap<Integer, Integer[]> hashMap = new HashMap<Integer, Integer[]>();
			Integer[] zero = { 0, 0 };
			hashMap.put(0, zero);
			int x_max = 0, x_min = 0, y_max = 0, y_min = 0;

			for (int i = 1; i < n; i++) {
				int base = nextInt();
				int x = hashMap.get(base)[0];
				int y = hashMap.get(base)[1];

				int direction = nextInt();
				switch (direction) {
				case 0:
					x--;
					break;
				case 1:
					y--;
					break;
				case 2:
					x++;
					break;
				case 3:
					y++;
					break;
				default:
					break;
				}
				Integer[] axis = { x, y };
				hashMap.put(i, axis);

				x_max = Math.max(x_max, x);
				x_min = Math.min(x_min, x);
				y_max = Math.max(y_max, y);
				y_min = Math.min(y_min, y);
			}

			int width = x_max - x_min + 1;
			int height = y_max - y_min + 1;

			System.out.println(width + " " + height);

		}

	}

	static int nextInt() {
		int c;
		try {
			c = System.in.read();
			while (c != '-' && (c < '0' || c > '9'))
				c = System.in.read();
			if (c == '-')
				return -nextInt();
			int res = 0;
			while (c >= '0' && c <= '9') {
				res = res * 10 + c - '0';
				c = System.in.read();
			}
			return res;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return -1;
	}

}

Measured memory_bytes: 20060
s=input()
n=len(s)
c=[0 for i in range(n)]
d=[0 for i in range(n)]
bc=[0 for i in range(n)]
bd=[0 for i in range(n)]
dc=[0 for i in range(n)]
dd=[0 for i in range(n)]
if s[-1]=="C":
    c[-1]=1
if s[-1]=="?":
    d[-1]=1
for i in range(-2,-n-1,-1):
    c[i]=c[i+1]
    d[i]=d[i+1]
    bc[i]=bc[i+1]
    bd[i]=bd[i+1]
    dc[i]=dc[i+1]
    dd[i]=dd[i+1]
    if s[i]=="B":
        bc[i]+=c[i+1]
        bd[i]+=d[i+1]
    if s[i]=="C":
        c[i]+=1
    if s[i]=="?":
        d[i]+=1
        dc[i]+=c[i+1]
        dd[i]+=d[i+1]
mul=[1,1,1,1]
for i in range(d[0]):
    mul[3]*=3
    mul[3]%=1000000007
for i in range(2,-1,-1):
    if mul[i+1]%3==0:
        mul[i]=mul[i+1]//3
    elif mul[i+1]%3==1:
        mul[i]=(mul[i+1]+1000000007)//3
    else:
        mul[i]=(mul[i+1]+2000000014)//3
res=0
for i in range(n-2):
    if s[i]=="A":
        res+=bc[i+1]*mul[3]+(dc[i+1]+bd[i+1])*mul[2]+dd[i+1]*mul[1]
    if s[i]=="?":
        res+=bc[i+1]*mul[2]+(dc[i+1]+bd[i+1])*mul[1]+dd[i+1]*mul[0]
    res%=1000000007
print(res)


Measured memory_bytes: 50592
#include <bits/stdc++.h>
using namespace std;
#define rep(i,e) for(int i= 0; i< (int)(e); i++)
#define reps(i,s,e) for(int i = s; i < (int)(e); i++)
#define repr(i,s,e) for(int i = s; i > (int)(e); i--)
typedef long long ll;

ll num1(ll n, ll x, vector<ll> &maisu, vector<ll> &patemaisu){
    if(n==0){return 1;}
    else if(x==1){return 0;}
    else if(x==maisu[n]){return patemaisu[n];}
    else if(x<=(maisu[n]-1)/2){return num1(n-1,x-1,maisu,patemaisu);}
    else{return patemaisu[n]-num1(n,maisu[n]-x,maisu,patemaisu);}
}

int main(){
    ll n,x;
    cin >> n >> x;
    vector<ll> maisu(n+1);
    vector<ll> patemaisu(n+1);
    maisu[0] = 1;
    patemaisu[0] = 1;
    reps(i,1,n+1){
        maisu[i] = 2*maisu[i-1]+3;
        patemaisu[i] = 2*patemaisu[i-1]+1;
    }
    cout << num1(n,x,maisu,patemaisu);
}

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

int main(){
	char p[8][9];
	int i,j;
	while(cin>>p[0]>>p[1]>>p[2]>>p[3]>>p[4]>>p[5]>>p[6]>>p[7]){
		for(i=0; i<8 ; ++i){
			for(j=0 ;j < 9 ; ++j){
				if(p[i][j]=='1') goto next; 
			}
		}
		next:
		if (p[i][j+1]=='1' &&p[i+1][j]=='1' && p[i+1][j+1]=='1') cout << 'A' << endl;
		else if (p[i+1][j]=='1' && p[i+2][j]=='1' && p[i+3][j]=='1') cout << 'B' << endl;
		else if (p[i][j+1]=='1' && p[i][j+2]=='1' && p[i][j+3]=='1') cout << 'C' << endl;
		else if (p[i+1][j]=='1' && p[i+1][j-1]=='1' && p[i+2][j-1]=='1' ) cout << 'D' << endl;
		else if (p[i][j+1]=='1' && p[i+1][j+1]=='1' && p[i+1][j+2]=='1' ) cout << 'E' << endl;
		else if (p[i+1][j]=='1' && p[i+1][j+1]=='1' && p[i+2][j+1]=='1' ) cout << 'F' << endl;
		else if (p[i][j+1]=='1' && p[i+1][j]=='1' && p[i+1][j-1]=='1' ) cout << 'G' << endl;
	}
	return 0; 
}

Measured memory_bytes: 1128
#include<stdio.h>

int main(){
  int x,y,r;
  
  scanf("%d %d",&x,&y);
  if(x<y){
    r=x;
    x=y;
    y=r;
  }
  if((1>x || x>1000000000) || (1>y || y>1000000000))return;

  while(y>0){
    r=x%y;
    x=y;
    y=r;
  }
    
  printf("%d\n",x);

  return 0;
}



Measured memory_bytes: 2144
#include <iostream>
using namespace std;
#define M 1000000007
 
int modexp(int x, int e, int m) {
    long long ans = 1, p = x % m;
    while (e > 0) {
        if (e % 2 != 0) ans = ans * p % m;
        p = p * p % m;
        e >>= 1;
    }
    return ans;
}
 
long long fact[200001], facti[200001];
 
long long C(int n, int k) {
    if (n < 0 || k < 0 || k > n) return 0;
    return fact[n] * facti[k] % M * facti[n-k] % M;
}
 
int main(int argc, char** argv) {
    int h, w, a, b; cin >> h >> w >> a >> b;
    fact[0] = 1; facti[0] = 1;
    for (int i = 1; i <= h+w; i++) {
        fact[i] = fact[i-1] * i % M;
        facti[i] = modexp(fact[i], M-2, M);
    }
    long long ans = 0;
    for (int i = 1; i <= h-a; i++) ans += C(i+b-2, i-1) * C(h+w-b-i-1, h-i) % M;
    cout << ans % M << endl;
}

Measured memory_bytes: 3328
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = int;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 30;


void solve(long long N, std::vector<long double> p){
    vector<vector<long double> > dp(N+1, vector<long double>(N+1, 0.));
    dp[0][0] = 1.0;
    REP(i, N){
        REP(k, N+1){
            dp[i+1][k] += dp[i][k] * (1 - p[i]);
            if(k > 0){
                dp[i+1][k] += dp[i][k-1] * p[i];
            }
        }
    }
    long double ans = 0.;
    for(ll k=(N+1)/2; k <= N; k++){
        ans += dp[N][k];
    }
    cout << setprecision(14)<< ans << endl;
}

int main(){
    ll N;
    scanf("%d",&N);
    std::vector<long double> p(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%Lf",&p[i]);
    }
    solve(N, std::move(p));
    return 0;
}


Measured memory_bytes: 141056
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SIZE 200005
#define Z(x) (((x)>0)?(x):0)
#define INF 100000000000000000LL

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

int main(){
    ll K,A,B;
    cin>>K>>A>>B;
    K++;
    if(A+2>=B){
        cout<<K<<endl;
    }else if(K<=A+1){
        cout<<K<<endl;
    }else{
        cout<<A+(K-A)/2*(B-A)+(K-A)%2<<endl;
    }
}


Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

int main()
{	
	string S, T;
	cin >> S >> T;

	cout << T + S << endl;

	return 0;
}

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

//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef set<int> si;
typedef set<ll> sll;

const double pi = acos(-1.0);
const long long INF = 2e18;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define in insert
#define endl "\n"

#define sqr(a) ((a) * (a))
#define jor(a) !(a&1)// jor means EVEN number
#define bjor(a) (a&1)// bjor means ODD number

#define all(a)  a.begin(), a.end()
#define mem(arr, b) memset(arr, b, sizeof(arr)) //memset only for -1 and 0
//fill(a, a+n, 5) //fill for any value

#define for0(i,b) for(int i=0;i<(b);i++)
#define for1(i,b) for(int i=1;i<=(b);i++)
#define forab(i,a,b) for(int i=(a);i<=(b);i++)
#define forba(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))

void print(int a[], int n){ // for testing or debugging
    for(int i=0;i<n;i++)cout<<a[i]<<" "; cout<<endl;
}
//_____________________________________________________\\

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    int t = 1;
    //cin>>t;
    while(t--)
    {
        int n; cin>>n; ll a[n];
        ll ans=1;
        ll most=1e18;
        bool z=0;
        for0(i,n) {
            cin>>a[i];
            if(a[i]==0) z=1;
        }
        if(z) {cout<<0; return 0;}
        
        bool brk=0;
        for0(i,n){
            if(log10(ans) + log10(a[i]) >18) {brk =1; break;}
            else ans*=a[i];
        }
        
        if(brk) cout<<-1;
        else if(ans>most) cout<<-1;
        else cout<<ans;
    }
}

Measured memory_bytes: 4764
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static final int MOD = 1000000007;
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int x = parseInt(sc.next());
		int y = parseInt(sc.next());
		sc.close();
		out.println((4*x>=y && y>=2*x && y%2==0)?"Yes":"No");
	}
}


Measured memory_bytes: 26972
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

vector<int> v[101010];
int dfs(int x,int p){
    int ret=0;
    for(auto to:v[x]){
        if(to==p)continue;
        ret^=dfs(to,x)+1;
    }
    return ret;
}

int main(){
    int n;
    cin>>n;
    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        --a;--b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    cout<<(dfs(0,-1)?"Alice":"Bob")<<endl;
    return 0;
}

Measured memory_bytes: 10368
progression = list(map(int,input().split()))
order = input()

dice = progression
order_list = list(order)
direction = [0,"S","E","W","N",0]
up_down_0 = [0,0]
up_down_1 = [0,0]
up_down_2 = [0,0]


up_down_0[0],up_down_0[1] = progression[0],progression[5]
up_down_1[0],up_down_1[1] = progression[2],progression[3]
up_down_2[0],up_down_2[1] = progression[1],progression[4]

num_under = 0
num_upper = 0


for i in order_list:
    
    if i == "N":
        num_under = direction.index("N")

    elif i == "E":
        num_under = direction.index("E")
        
    elif i == "S":
        num_under = direction.index("S")
        
    elif i == "W":
        num_under = direction.index("W")
        
    dice[num_under],dice[5] =dice[5],dice[num_under]

    if dice[5] == up_down_0[0]:
        num_upper = dice.index(up_down_0[1])
        dice[num_upper],dice[0] = dice[0],dice[num_upper]

    elif dice[5] == up_down_0[1]:
        num_upper = dice.index(up_down_0[0])
        dice[num_upper],dice[0] = dice[0],dice[num_upper]

    elif dice[5] == up_down_1[0]:
        num_upper = dice.index(up_down_1[1])
        dice[num_upper],dice[0] = dice[0],dice[num_upper]

    elif dice[5] == up_down_1[1]:
        num_upper = dice.index(up_down_1[0])
        dice[num_upper],dice[0] = dice[0],dice[num_upper]

    elif dice[5] == up_down_2[0]:
        num_upper = dice.index(up_down_2[1])
        dice[num_upper],dice[0] = dice[0],dice[num_upper]


    elif dice[5] == up_down_2[1]:
        num_upper = dice.index(up_down_2[0])
        dice[num_upper],dice[0] = dice[0],dice[num_upper]

    
    direction[num_under],direction[num_upper] = direction[num_upper],direction[num_under]
    
    
print(dice[0])


Measured memory_bytes: 5628
#include <iostream>
 
using namespace std;
 
int main(){
  int l,i;
  //cin >> n;
  
  int a[2];
  
  for(i =0; i<2;i++){
    cin >> l;
    a[i] = l;
    //cout << a[i] << endl;
  }
  
  int result=0;
  result = max(a[0],a[1]);
  if(result == a[0]){
    a[0]--;
    //cout << a[0] << endl;
  }else{
    a[1]--;
    //cout << a[1] << endl;
  }
  result += max(a[0],a[1]);
	
  
  cout << result <<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int D, T, S;
    scanf("%d%d%d", &D, &T, &S);
    if(S*T>=D)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 1660
#ifdef MY_LOCAL
#define MY_NAMESPACE(ns) namespace ns {
#define MY_NAMESPACE_    }
#define MY_DEBUG(s)      s
#else
#define MY_NAMESPACE(ns) 
#define MY_NAMESPACE_    
#define MY_DEBUG(s)      
#endif

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

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

#define EPS (1e-7)
#define IINF ((int)1e9)


MY_NAMESPACE(testbed)
bool ABC167F_order(pll const& lhs, pll const& rhs)
{
	// first:  open
	// second: close

	int lhs_sign = 0;
	if (lhs.first > lhs.second)
		lhs_sign = 1;  // more open
	else if (lhs.first < lhs.second)
		lhs_sign = -1;  // more close

	int rhs_sign = 0;
	if (rhs.first > rhs.second)
		rhs_sign = 1;
	else if (rhs.first < rhs.second)
		rhs_sign = -1;

	if (lhs_sign != rhs_sign)
		return lhs_sign > rhs_sign;

	if (lhs_sign >= 0)
	{
		//if (lhs.second != rhs.second)
			return lhs.second < rhs.second;  // use the smallest close at the first (because the restriction is toughest at the first)
		//else
//			return lhs.first > rhs.first;
	}
	else
	{
		//if (lhs.first != rhs.first)
			return lhs.first > rhs.first;  // leave the smallest open for the last (because the restriction is toughest at the last)
		//else
			//return lhs.second < rhs.second;
	}
}

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

	int n;
	cin >> n;
	vector<pll> num_live_open_and_close(n);
	for (int i = 0; i < n; i++)
	{
		string s;
		cin >> s;
		for (auto it = s.begin(); it != s.end(); it++)
		{
			if (*it == '(')
			{
				num_live_open_and_close[i].first++;
			}
			else  // *it==')'
			{
				if (num_live_open_and_close[i].first > 0)
					num_live_open_and_close[i].first--;
				else
					num_live_open_and_close[i].second++;
			}
		}
	}

	sort(num_live_open_and_close.begin(), num_live_open_and_close.end(), ABC167F_order);

	ll level = 0;
	for (auto it = num_live_open_and_close.begin(); it != num_live_open_and_close.end(); it++)
	{
		level -= it->second;
		if (level < 0)
		{
			cout << "No" << "\n";
			return 0;
		}
		level += it->first;
	}
	if (level == 0)
		cout << "Yes" << "\n";
	else
		cout << "No" << "\n";
	return 0;
}
MY_NAMESPACE_

Measured memory_bytes: 18664
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll rwpw(ll a, ll p=MOD-2){
	ll ret = 1ll;
	while(p){
		if(p%2){
			mul_mod(ret,a);
		}
		mul_mod(a,a);
		p /= 2;
	}
	return ret;
}

ll x[100100];

int main(void){
	int n,i,j,m;
	ll ans=0ll,tmp;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> x[i];
	}
	for(i=1; i<n; ++i){
		tmp = x[n-1] - x[i-1];
		mul_mod(tmp,rwpw(i));
		add_mod(ans,tmp);
	}
	for(i=1; i<n; ++i){
		mul_mod(ans,i);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
//
// Created by yamunaku on 2019/08/04.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

int main(){
    int n;
    cin >> n;
    vi a(n);
    rep(i,n){
        cin >> a[i];
    }
    a[0]--;
    repl(i,1,n){
        if(a[i]>a[i-1]){
            a[i]--;
        }else if(a[i]<a[i-1]){
            CNO;
            return 0;
        }
    }
    CYES;
    return 0;
}


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

int N;
void print(int *array){
    for(int i = 0; i < N; i++){
        if(i != N-1) cout << array[i] << " ";
        else cout << array[i] << endl;
    }
}

void insertion_sort(int *array){
    print(array);
    for(int i = 1; i < N; i++){
        int key = array[i];
        int j = i-1;
        while(j >= 0 && array[j] > key){
            array[j+1] = array[j];
            j--;
        }
        
        array[j+1] = key;
        print(array);
    }
}

int main(void){
    // Your code here!
    
    cin >> N;
    int arr[N];
    for(int i =0;  i < N; i++) cin >> arr[i];
    
    insertion_sort(arr);
}




Measured memory_bytes: 3092
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val N = sc.nextInt()
  val d = List.fill(N)(sc.nextInt())

  println(calc(N, d))

  def calc(N: Int, d: List[Int]) : Int = {
    d.toSet.size
  }
}


Measured memory_bytes: 55648
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
  ios::sync_with_stdio(0);
  int a,b,h,m;
  cin >> a >> b >> h >> m;
  double hour = h * 30.0;
  hour += (m/60.0) * 30;

  double minute = m * 6.0;
  double ang = abs(hour - minute);
  ang = min(ang, 360 - ang);
  ang = ang * M_PI / 180.0;
  double cSq = a*a + b*b - ((2*a*b) * cos(ang));
  cout << fixed << setprecision(10) <<  sqrt(cSq) << endl;
  return 0;
}

Measured memory_bytes: 4148
n=int(input())
s=list(str(input()))
if n % 2 ==0:
    ans=0
    for i in range(n//2):
        if s[i]==s[n//2+i]:
            ans+=1
        else:
            ans+=0

    if ans==n//2:
        print('Yes')
    else:
        print('No')   

else:
    print('No')


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll> > vvl;
typedef vector<vector<P> > vvp;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  ll now=100;
  ll x;
  cin >> x;
  exrep(i,1,4000){
    now*=1.01;
    if(now>=x){
      cout << i << endl;
      return 0;
    }
  }
  return 0;     
}


Measured memory_bytes: 3652
import java.util.*

fun main(args: Array<String>) {
val read = Scanner(System.`in`)
    val a = read.nextInt()
    val b = read.nextInt()

    if (a == b) println("IMPOSSIBLE")
    if ((a + b) % 2 != 0 ) println("IMPOSSIBLE") else println((a + b) / 2)
}

Measured memory_bytes: 31264
#include <stdio.h>
#include <algorithm>

using namespace std;

int n, q, r, a[100000];

int main()
{
    scanf("%d", &n);
    
    for(int i = 0; i < n; i++) scanf("%d", &a[i]);
    
    scanf("%d", &q);
    
    int ret = 0;
    
    for(int i = 0; i < q; i++)
    {
        scanf("%d", &r);
        
        ret += binary_search(a, a + n, r) ? 1 : 0;
    }
    
    printf("%d\n", ret);
    
    return 0;
}

Measured memory_bytes: 3072
#include <iostream>
using namespace std;
int main(){
    int n,l,i,k,s;
    char m;
    int x[4][14]={};
    cin>>s;
    x[0][0]='S';
    x[1][0]='H';
    x[2][0]='C';
    x[3][0]='D';
    for(k=0;k<s;k++){
        cin>>m>>n;
        if(m=='S'){
            x[0][n]=1;
        }else if(m=='H'){
            x[1][n]=1;
        }else if(m=='C'){
            x[2][n]=1;
        }else if(m=='D'){
            x[3][n]=1;
        }
    }
    for(l=1;l<14;l++){
           if(x[0][l]!=1){
               cout<<"S"<<" "<<l<<endl;
           }
       }
    for(l=1;l<14;l++){
           if(x[1][l]!=1){
               cout<<"H"<<" "<<l<<endl;
           }
       }
    for(l=1;l<14;l++){
           if(x[2][l]!=1){
               cout<<"C"<<" "<<l<<endl;
           }
       }
    for(l=1;l<14;l++){
           if(x[3][l]!=1){
               cout<<"D"<<" "<<l<<endl;
           }
       }
    return 0;
}


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

int main() {
    int n;
    cin>>n;
    for (int i=0; 4*i<=n; i++) {
        for (int j=0; 7*j<=n; j++) {
            if (4*i+7*j==n) {
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
}   


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
long dp[900][900];
int n;
long c[900],s[900],f[900];
main()
{
	cin>>n;
	for(int i=0;i<n-1;i++)cin>>c[i]>>s[i]>>f[i];
	for(int i=0;i<n-1;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			dp[i][j]=max(s[j-1],(dp[i][j-1]+f[j-1]-1)/f[j-1]*f[j-1])+c[j-1];
		}
	}
	for(int i=0;i<n;i++)cout<<dp[i][n-1]<<endl;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i< (n); ++i)
const long long INF = 1LL<<58;

/*
 *
 * 最適解は以下のいずれかの形であることはわかる

    まずいずれかの「神社」を訪れて、そこから最も近い「寺」に訪れる
    まずいずれかの「寺」を訪れて、そこから最も近い「神社」に訪れる
    ここで、1 個目の場合について、最初に訪れる神社が必ずしも初期位置から最も近い位置がよいわけではないことに注意する。なぜなら、初期位置から最も近い神社に行っても、そこから最寄りの寺がすごく遠いかもしれない！！！！！！！！

    しかしそれでも、

    初期位置から前方の最寄りの神社
    初期位置から後方の最寄りの神社
    以外を狙う意味はないことがわかる。何故なら、これら以外の神社に行こうと思うと、「前方最寄り」「後方最寄り」のうちのいずれか一方には既に通りかかることになるからだ。

    というわけで初回の行動は以下の 4 パターンで、2 回目の行動はそこから最寄りの「寺」か「神社」に行けばよい。

    最初に前方最寄りの神社に行く
    最初に後方最寄りの神社に行く
    最初に前方最寄りの寺に行く
    最初に後方最寄りの寺に行く
 *
 * */


// aを常に小さい値にする
template<class T> void chmin(T &a, T b){
    if(a>b) a = b;
}

// 二分探索 前方のindexを返すもの（自分自身を含む） 前方: -INF側のこと
template<class T> int former(const vector<T> &v, T x){
    return upper_bound(v.begin(), v.end(), x) - v.begin() -1; // upper_bound : keyより大きい要素の内の一番左側のイテレータを返す
}
// 二分探索 後方のindexを返すもの（自分自身を含む）後方: INF側のこと
template<class T> int latter(const vector<T> &v, T x){
    return lower_bound(v.begin(), v.end(), x) - v.begin(); // lower_bound : key以上の要素の内の一番左側のイテレータを返す
}

int main() {

    int A, B, Q;
    cin >> A >> B >> Q;
    vector<ll> s(A), t(B);
    rep(i,A) cin >> s[i];
    rep(i,B) cin >> t[i];

    // 二分探索は配列外の目盛にアクセスする場合はあるので、番兵をいれておく
    s.push_back(INF); s.push_back(-INF); sort(s.begin(), s.end());
    t.push_back(INF); t.push_back(-INF); sort(t.begin(), t.end());

    rep(_,Q) {
        ll x;
        cin >> x;

        // かかる距離を保持する変数 resultの略
        ll res = INF;

        // 最初に s に訪れる（前方にいくか、後方に行くかで場合分け）
        for (int i = 0; i < 2; ++i) {
            ll first;
            if(i){
                first = s[former(s,x)];
            }else{
                first = s[latter(s,x)];
            }
            // 次に t (現在地の前後を調べて近い方に行く)
            for (int j = 0; j < 2; ++j) {
                ll second;
                if(j){
                    second = t[former(t,first)];
                }else{
                    second = t[latter(t,first)];
                }
                chmin(res, abs(x-first) + abs(first - second));
            }
        }

        // 最初に s に訪れる（前方にいくか、後方に行くかで場合分け）
        for (int i = 0; i < 2; ++i) {
            ll first;
            if(i){
                first = t[former(t,x)];
            }else{
                first = t[latter(t,x)];
            }
            // 次に t (現在地の前後を調べて近い方に行く)
            for (int j = 0; j < 2; ++j) {
                ll second;
                if(j){
                    second = s[former(s,first)];
                }else{
                    second = s[latter(s,first)];
                }
                chmin(res, abs(x-first) + abs(first - second));
            }
        }
        cout << res << endl;
    }
}

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

#define ll long long
#define F first
#define S second
#define ii pair < int , int >
#define ever (;;)

const int N = 3010;

int n,m,dp[N][N];
char A[N],B[N];
string s,t,ans;

int main()
{
    scanf("%s%s",&A,&B);
    s = A;
    t = B;
    n = s.length();
    m = t.length();

    for(int i=n-1;i>=0;i--)
        for(int j=m-1;j>=0;j--)
            if( s[i] == t[j] )
                dp[i][j] = 1 + dp[i+1][j+1];
            else
                dp[i][j] = max( dp[i+1][j] , dp[i][j+1] );

    int p1 = 0,p2 = 0;

    while( p1 != n && p2 != m )
    {
        if( s[p1] == t[p2] )
        {
            ans += s[p1];
            p1++;
            p2++;
            continue;
        }

        if( dp[p1+1][p2] > dp[p1][p2+1] )
            p1++;
        else
            p2++;
    }

    printf("%s\n",ans.c_str());
}


Measured memory_bytes: 38904
#include <iostream>
#include <algorithm>
#include <vector>
typedef long long ll;
using namespace std;


int main(void) {
    ll X,K,D;
    cin >> X >> K >> D;
    ll ans;
    X = abs(X);
    if (X / D > K) {
        ans = X - (K * D);
    }else{
        ll e = (X / D);
        K -= e;
        X -= e * D;
        if (K % 2 == 1) X = abs(X - D);
        ans = X;
    }
    cout << ans << endl;;
    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
const int M = 110;
const int INF = 1e9 + 7;
int dp[N][M],v[N];

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	for(int i=0;i<N;++i)
		for(int j=0;j<M;++j)
			dp[i][j] = INF;

	int n,k;
	cin>>n>>k;

	for(int i=1;i<=n;++i) cin>>v[i];

	dp[1][0] = 0;

	for(int i=1;i<=n;++i){
		for(int j=1;j<=k;++j)
		{
			dp[i][j] = min(dp[i][j],dp[i][j-1]);
			int id = i - j;
			if(id < 0) continue;

			int x = abs(v[id] - v[i]);
			dp[i][j] = min(dp[i][j],dp[id][k] + x);
		}
	}
	cout<<dp[n][k]<<"\n";
}

Measured memory_bytes: 43648
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
ll digitsum(ll x, ll d) {
	ll res = 0;
	while (x) {
		res += x % d; x /= d;
	}
	return res;
}
int main() {
	ll n, s; cin >> n >> s;
	ll out = INF;
	if (n < s) {
		cout << -1 << endl; return 0;
	}
	if (n == s) {
		out = n + (ll)1;
	}
	ll x = min(n, (ll)1000000);
	queue<ll> q; q.push(2); q.push(n - s + (ll)1);
	for (ll i = 2; i <= x; i++) {
		if ((n-s)%i == 0) {
			q.push(i + (ll)1); q.push((n-s) / i+(ll)1);
		}
		if (digitsum(n, i) == s) {
			out = min(out, i);
		}
	}
	while (!q.empty()) {
		ll i = q.front(); q.pop();
		if (i == 1)continue;
		if (digitsum(n, i) == s) {
			out = min(out, i);
		}
	}
	if (out != INF) {
		cout << out << endl;
	}
	else {
		cout << -1 << endl;
	}
	return 0;
}

Measured memory_bytes: 16564
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	int s[15],c[15],a[4]={0},b[4]={0},p[4]={0};
	cin>>n>>m;
	int f1=0;
	for(int i=0;i<m;i++){
		cin>>s[i]>>c[i];
		if((b[s[i]]!=c[i]&&p[s[i]])||(s[i]==1&&c[i]==0&&n>1)){
			f1=1;
		}
		a[s[i]]=c[i];
		b[s[i]]=c[i];
		p[s[i]]=1;
	}
	int f2=1;
	if(f1){
		cout<<-1;
	}
	else{
		if(a[1]==0&&n>1)a[1]=1;
		for(int i=1;i<=n;i++)cout<<a[i];
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
#define debug(x) cerr << x << "\n"
#define all(x) (x).begin(),(x).end()
#define exist(s, e)((s).find(e) != (s).end())

void selectionSort(vector<int>&, int&);

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, tmp, i, c = 0;
    vector<int> a;
    
    cin >> n;
    for (i=0;i<n;i++) {
        cin >> tmp;
        a.push_back(tmp);
    }
    
    selectionSort(a, c);
    for (i=0;i<n;i++) cout << a[i] << ((i==n-1) ? '\n' : ' ');
    cout << c << '\n';

    return 0;
}

void selectionSort(vector<int>& a, int& c) {
    size_t N = a.size();
    int minj;
    for (int i = 0;i < N;i++) {
        minj = i;
        for (int j = i;j < N;j++) {
            if (a[j] < a[minj]) minj = j;
        }
        using std::swap;
        swap(a[minj], a[i]);
        if(minj != i)c++;
    }
}


Measured memory_bytes: 3212
n, p = map(int ,input().split())
a = list(map(int ,input().split()))
flg_lst = []
for i in range(n):
    if a[i] % 2 == 0:
        flg_lst.append(True)
    else:
        flg_lst.append(False)
if False in flg_lst:
    print(2 ** (n - 1))
else:
    if p == 0:
        print(2 ** n)
    else:
        print(0)


Measured memory_bytes: 9116
#include <iostream>

using namespace std;

int main() {
    int P, Q, R;
    cin >> P >> Q >> R;
    int total;
    total += min(P, Q);
    if(total == P) {
        total += min(Q, R);
    } else {
        total += min(P, R);
    }
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int[] top3 = new int[3];
        for(int i=0; i<10; i++){
            try {
                String line = br.readLine();
                if(line != null){
                    int tmp = Integer.parseInt(line.trim());
                    if(tmp>top3[0]){
                        top3[2] = top3[1];
                        top3[1] = top3[0];
                        top3[0] = tmp;
                    } else if(tmp>top3[1]){
                        top3[2] = top3[1];
                        top3[1] = tmp;
                    } else if(tmp>top3[2]){
                        top3[2] = tmp;
                    }
                }
            } catch (IOException e) {
            }

        }
        for(int i=0; i<3; i++) {
            System.out.println(top3[i]);
        }
    }
}

Measured memory_bytes: 17048
#include <stdio.h>

int main(void)
{
  int n;
  scanf("%d", &n);
  int a[n];
  int i = 0;
  while (i < n)
  {
    scanf("%d", &a[i]);
    i++;
  }
  
  int ans[n];
  i = 0;
  int k;
  while (i < n)
  {
    k = a[i];
    ans[k - 1] = i + 1;
    i++;
  }
  
  i = 0;
  while (i < n)
  {
    printf("%d ", ans[i]);
    i++;
  }
  return 0;
}

Measured memory_bytes: 1536
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <numeric>
using namespace std;
#define MAX_N 200000

template<class T> inline bool chmax(T& a, T b) { if(a < b) {a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if(a > b) {a = b; return true; } return false; }
const long long INF = 1LL << 60;

// Input
long long N;

int main() {
  cin >> N;
  switch (N % 10) {
  case 2:
  case 4:
  case 5:
  case 7:
  case 9:
    cout << "hon" << endl;
    break;
  case 0:
  case 1:
  case 6:
  case 8:
    cout << "pon" << endl;
    break;
  default:
    cout << "bon" << endl;
    break;
  }
  return 0;
}


Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	static int[] S ;
	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();

		int N = Integer.parseInt(W);

		W = in.readLine();
		String[] Ws = W.split(" ");
		int[] A = new int[N+1];
		A[0]=0;
		int[] X = new int[N+1];
		Arrays.fill(X, 0);
		for(int i=0;i<Ws.length;i++){
			A[i+1] = Integer.parseInt(Ws[i]);
			X[A[i+1]]++;
		}
		long[] C = new long[N+1];
		long All = 0;
		for(int i=1;i<A.length;i++){
			C[i] = calcConbi2(X[i]);
			All += C[i];
		}


		for(int i=1;i<A.length;i++){
			System.out.println(All-C[A[i]]+calcConbi2(X[A[i]]-1));
		}

	}

		public static long calcConbi2(long n ){
			if(n <= 0){
				return 0;
			}
			return (n*(n-1))/2;
		}

}


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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

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

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

bool u[200020];
bool v[200020];

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n, m;
  cin >> n >> m;

  rep(i, m) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    if(a == 0) u[b] = true;
    if(b == n-1) v[a] = true;
  }
  rep(i, n) {
    if(u[i] && v[i]) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;

  return 0;
}


Measured memory_bytes: 640