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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; i++) {
    cin >> d.at(i);
  }
  if (N == 1) {
    cout << "Yes" << endl;
  }
  else if (N == 2) {
    if (d.at(0) - d.at(1) >= 2) {
      cout << "No" <<endl;
    }
    else {
      cout << "Yes" << endl;
    }
  }
  else {
    int m = max(d.at(0), d.at(1));
    for (int i = 2; i < N; i++) {
      if (m - d.at(i) >= 2) {
        cout << "No" <<endl;
        break;
      }
      else {
        m = max(m, d.at(i));
      }
      if (i == N -1) {
        cout << "Yes" << endl;
      }
    }
  }
}

Measured memory_bytes: 640
#include <stdio.h>
int main(void){
	int n[100];
	int i;
	int m = 0;
	
	for(i = 0;i < 100;i++)n[i] = 0;
	while(scanf("%d",&i) != EOF)n[i]++;
	for(i = 0;i < 100;i++)if(m < n[i])m = n[i];
	for(i = 0;i < 100;i++)if(n[i] == m)printf("%d\n",i);
	
	return 0;
}

Measured memory_bytes: 596
BTC_PER_YEN = 380000.0
N = int(input())
Y_sum = 0
for n in range(N):
  s = input()
  x,u = s.split(" ")
  if u == "BTC":
    Y_sum += BTC_PER_YEN * float(x)
  else:
    Y_sum += float(x)
print(Y_sum)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i < n; i++)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = 1e15;

int main(){
    int N;
    cin >> N;
    int a[N+1];
    vector<int> edge[N+1];
    rep2(i, 2, N+1){
        cin >> a[i];
        edge[a[i]].push_back(i);
    }
    queue<int> que;
    int dep[N+1];
    bool lost[N+1];
    fill_n(lost, N+1, false);
    rep2(i, 1, N+1){
        if(edge[i].size() == 0){
            dep[i] = 0;
            lost[i] = true;
            que.push(i);
        }
    }
    int count[N+1]; //iに負ける人が何回出たか
  	rep(i,N+1)
    	count[i]=0;
    while(!que.empty()){
        int i = que.front();
        que.pop();
        if(i == 1) break;
        int j = a[i];
        int n = edge[j].size();
        bool update = true;
      	count[j]++;
      	if(count[j]<n) //まだn人出ていなかったら更新しない
        	update=false;
        if(!update) continue;
        lost[j] = true;
        int d[n];
        rep(k, n) d[k] = dep[edge[j][k]];
        sort(d, d+n, greater<int>());
        dep[j] = 0;
        rep(k, n){
            dep[j] = max(dep[j], d[k]+k+1);
        }
        que.push(j);
    }
    cout << dep[1] << endl;
}


Measured memory_bytes: 7040
#include<stdio.h>
int main(){
	int field[8][8];
	int a,b;
	for(;;){
		for(b=0;b<8;b++){
			for(a=0;a<8;a++){if(scanf("%1d",&field[a][b]) == EOF){break;}}
			if(a!=8){break;}
		}
		if(b!=8){break;}
		for(b=0;b<8;b++){
			for(a=0;a<8;a++){
				if(field[a][b] == 1){
					if(field[a][b] == 1 && field[a+1][b] == 1 && field[a][b+1] == 1 && field[a+1][b+1] == 1){printf("A\n");break;}
					else if(field[a][b] == 1 && field[a][b+1] == 1 && field[a][b+2] == 1 && field[a][b+3] == 1){printf("B\n");break;}
					else if(field[a][b] == 1 && field[a+1][b] == 1 && field[a+2][b] == 1 && field[a+3][b] == 1){printf("C\n");break;}
					else if(field[a][b] == 1 && field[a][b+1] == 1 && field[a-1][b+1] == 1 && field[a-1][b+2] == 1){printf("D\n");break;}
					else if(field[a][b] == 1 && field[a+1][b] == 1 && field[a+1][b+1] == 1 && field[a+2][b+1] == 1){printf("E\n");break;}
					else if(field[a][b] == 1 && field[a][b+1] == 1 && field[a+1][b+1] == 1 && field[a+1][b+2] == 1){printf("F\n");break;}
					else if(field[a][b] == 1 && field[a+1][b] == 1 && field[a][b+1] == 1 && field[a-1][b+1] == 1){printf("G\n");break;}
				}
			}
			if(a!=8){break;}
		}
	}
	return 0;
}

Measured memory_bytes: 0
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    ret = sys.stdin.readline().rstrip()
    Q = int(sys.stdin.readline().rstrip())
    m = ""
    u = ""
    r = 0
    for q in range(Q):
        line = sys.stdin.readline().split()
        if line[0] == '1':
            m, u = u, m
            r ^= 1
        elif line[0] == '2' and line[1] == '1':
            m += line[2]
        else:
            u += line[2]

    if r == 0:
        print(m[::-1] + ret[::1] + u)
    else:
        print(m[::-1] + ret[::-1] + u)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4468
//Awwawa! Dis cold yis ratten buy tEMMIE!
#include <bits/stdc++.h>
#define ll long long
#define maxn 1000005 /*rem*/
#define mod 998244353
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second

template <typename T> bool chkmax(T &x,T y){return x<y?x=y,true:false;}
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,true:false;}

using namespace std;
ll ksm(ll a, ll b) {
   if (!b) return 1;
   ll ns = ksm(a, b >> 1);
   ns = ns * ns % mod;
   if (b & 1) ns = ns * a % mod;
   return ns;
}
char s[maxn];
int n;
bool check(int x) {
	pi r[2] = {mp(0, x), mp(0, x)};
	for (int i = 1; i <= n; i++) {
		pi cur[2] = {mp(maxn * 10, -maxn * 10), mp(maxn * 10, -maxn * 10)};
		pi fr[2] = {r[0], r[1]};	
		for (int i = 0; i < 2; i++) {
			if (fr[i].se % 2 != i) fr[i].se--;
			if (fr[i].fi % 2 != i) fr[i].fi++;
		}
		for (int j = 0; j < 2; j++) {
			int tp = j * 2 - 1;
			if (s[i] != '0' + j) {
				for (int s = 0; s < 2; s++) {
					pi ed = mp(fr[s].fi + tp, fr[s].se + tp);
					chkmax(ed.fi, 0), 
					chkmin(ed.se, x);
					if (ed.fi > ed.se) continue;
					chkmin(cur[s ^ 1].fi, ed.fi);
					chkmax(cur[s ^ 1].se, ed.se);
				}
			} 
		}
	//	cout << i << ' ' << r[0].fi << ' ' << r[1].fi << ' ' << r[0].se << ' ' << r[1].se << endl;
		r[0] = cur[0];
		r[1] = cur[1];
		for (int i = 0; i < 2; i++) {
			if (r[i].se % 2 != i) r[i].se--;
			if (r[i].fi % 2 != i) r[i].fi++;
		}
	}
	if (r[0].fi <= r[0].se || (r[1].fi <= r[1].se)) return 1;
	return 0;
}
int main() {
	scanf("%s", s + 1);
	n = strlen(s + 1);
	int l = 0, r = n;
	check(1);
//	while (1);
	while (l < r) {
		int mid = (l + r) >> 1;
		if (check(mid)) r = mid;
		else l = mid + 1;
	}
	cout << l << endl;
	return 0;
}


Measured memory_bytes: 4748
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int a[5];
  int i,t;
  for(i=0;i<5;i++)
  cin>>a[i];
  for(i=0;i<5;i++)
  {
    if(a[i]==0)
    t=i+1;
  }
  cout<<t;
  return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>

int main(){
 int x,a,b,la,lb;
 scanf("%d %d %d",&x,&a,&b);
 la=x-a;
if(la<0)la=-1*la;
lb=x-b;
if(lb<0)lb=-1*lb;
if(la>lb){
printf("B");
}else{
printf("A");
}
return 0;
}

Measured memory_bytes: 128
N = int(input())
lst_A = list(map(int, input().split()))
lst_cnt = [0] * (10**6)
ans = 0


for a in lst_A:
    lst_cnt[a - 1] += 1
    lst_cnt[a] += 1
    lst_cnt[a + 1] += 1
ans = max(lst_cnt)


print(ans)

Measured memory_bytes: 15996
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cstdio>
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define RREP(i,x) for(int i=(x);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();++i)

const int INF = 500000000;
int n, m;
int dp[10005];
main(){
	int i,j;
	while(cin >> m >> n){
		vector<int> man(m);
		REP(i, m) cin >> man[i];
		sort(man.rbegin(), man.rend());
		REP(i, m+1) dp[i] = INF;
		dp[0] = 0;
		REP(i, n){
			int c, x;
			cin >> c >> x;
			for(int j=m-1;j>=0;j--){
				int t = j+c>m ? m : j+c;
				dp[t] = min(dp[t], dp[j] + x);
			}
		}
		int sum = 0, ans = 0;
		REP(i, m){
			sum += man[i];
			ans = max(ans, sum - dp[i+1]);
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main(){
  int A,B,K;
  cin >> A >> B >> K;
  int m = min(A, B);
  
  vector<int> CM = {0};
  for(int i = 1; i <= m; i++){
    if(A%i == 0 && B%i == 0){
      CM.push_back(i);
    }
  }
  sort(CM.begin(), CM.end());
  reverse(CM.begin(), CM.end());
  cout << CM[K-1] << endl;
}


Measured memory_bytes: 256
import java.util.*;
    public class Main {
     
    	public static void main(String[] args) {
    			
    		Scanner scan =new Scanner(System.in);
    		String upper=scan.next();
    		String middle=scan.next();
    		String lower=scan.next();
    		
    		System.out.print(upper.charAt(0));
    		System.out.print(middle.charAt(1));
    		System.out.print(lower.charAt(2));
;
    		
     
    }
    }
// end 

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

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

Measured memory_bytes: 764
def solve():
    N, Ma, Mb = map(int, input().split())
    a, b, c = [], [], []

    for i in range(N):
        ai, bi, ci = map(int, input().split())
        a.append(ai)
        b.append(bi)
        c.append(ci)

    nvals = 99 * N * 2 + 1
    inf = 40 * 100 + 1
    dp = [[inf] * nvals for i in range(N)]

    for i in range(N):
        v = Mb * a[i] - Ma * b[i]

        if i == 0:
            dp[i][v] = c[i]
            continue

        for j in range(-99 * N, 99 * N + 1):
            if -99 * N <= j - v <= 99 * N:
                dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v] + c[i])

        dp[i][v] = min(dp[i][v], c[i])

    ans = dp[N - 1][0]

    if ans < inf:
        print(ans)
    else:
        print(-1)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 5752
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <regex>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF=1<<29;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,x,tmp=0,ans=0;
	cin>>n>>x;
	vector<int> L(n);
	for(int i=0;i<n;i++) cin>>L[i];
	for(int i=0;i<n;i++){
		if(tmp<=x) ans++;
		tmp+=L[i];
	}
	if(tmp<=x) ans++;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct P{
	int x,y;
};
int n,m,dis[1005][1005],sx,sy,tx,ty,is[1005][1005];
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
char str[1005][1005];
int main() {
	cin>>n>>m,memset(dis,0x3f,sizeof(dis));
	cin>>sx>>sy>>tx>>ty;
	for(int i=1;i<=n;i++)scanf("%s",str[i]+1);
	deque<P> q;
	q.push_back({sx,sy}),dis[sx][sy]=0;
	while(!q.empty()){
		P o=q.front();
		q.pop_front();
		if(is[o.x][o.y])continue;
		is[o.x][o.y]=1;
		for(int i=0;i<4;i++){
			P oo={o.x+dx[i],o.y+dy[i]};
			if(oo.x<1||oo.x>n||oo.y<1||oo.y>m)continue;
			if(str[oo.x][oo.y]=='#')continue;
			if(dis[oo.x][oo.y]<dis[o.x][o.y])continue;
			dis[oo.x][oo.y]=dis[o.x][o.y];
			q.push_front(oo);
		}
		for(int i=-2;i<=2;i++){
			for(int j=-2;j<=2;j++){
			
			P oo={o.x+i,o.y+j};
			if(oo.x<1||oo.x>n||oo.y<1||oo.y>m)continue;
			if(str[oo.x][oo.y]=='#')continue;
			if(dis[oo.x][oo.y]<dis[o.x][o.y]+1)continue;
			dis[oo.x][oo.y]=dis[o.x][o.y]+1;
			q.push_back(oo);
		}}
	}
	if(dis[tx][ty]<1e9)cout<<dis[tx][ty];
	else puts("-1");
}

Measured memory_bytes: 12848
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll inf = 1e18;
ll mod=1e9+7;
//LLONG_MIN

/*
*/

ll n,m,ans=0;
mp a[100010];

int main(void){
	cin>>n>>m;
	rep(i,n){
		ll x,y;
		cin>>x>>y;
		a[i]={x,y};
	}
	sort(a,a+n);
	rep(i,n){
		if(m>a[i].second){
			ans+=a[i].first*a[i].second;
			m-=a[i].second;
		}else{
			ans+=a[i].first*m;
			m-=m;
		}
		if(m==0)break;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)

int main(){
	int h,w;
	cin>>h>>w;
	vector<string> v(h);
	rep(i,h)cin>>v[i];
	
	int sum=0;
	rep(i,h)rep(j,w)if(v[i][j]=='#')sum++;
	
	int c=1;
	int x=0,y=0;
	while(x!=w-1||y!=h-1){
		if(y+1<h && v[y+1][x]=='#'){
			y++;
		}
		else if(x+1<w && v[y][x+1]=='#'){
			x++;
		}else{
			cout<<"Impossible"<<endl;
			return 0;
		}
		c++;
	}
	if(c!=sum)cout<<"Impossible"<<endl;
	else cout<<"Possible"<<endl;
}

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

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

  vector<int> dp(n);
  dp[0] = 0;
  dp[1] = abs(a[1] - a[0]);
  for (int i = 2; i < n; i ++) {
    dp[i] = min(dp[i-1] + abs(a[i] - a[i-1]), dp[i-2] + abs(a[i] - a[i-2]));
  }

  cout << dp[n-1] << endl;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
using namespace std;

int main(void)
{
	char buf[201],b[101];
	int i,a,flg;
	char moji[5][6]={{'a','f','k','p','u','z'},
					{'b','g','l','q','v','.'},
					{'c','h','m','r','w','?'},
					{'d','i','n','s','x','!'},
					{'e','j','o','t','y',' '}};
	int len;
	int su1,su2;

	while(scanf("%s",buf)!=EOF)	{
		flg=1;
		len=strlen(buf);
		if(len%2==1)	flg=0;
		else {
			for(i=0;i<len/2;i++)	{
				su1=buf[i*2]-'0';
				su2=buf[i*2+1]-'0';
				if(su1<=0 || su1>6 || su2<=0 || su2>5)	{
					flg=0;
					break;
				}
//				printf("su2=%d su2=%d\n",su2,su1);
				b[i]=moji[su2-1][su1-1];
			}
			b[len/2]='\0';
		}
		if(flg==1)	{
			printf("%s\n",b);
		}
		else {
			printf("NA\n");
		}
	}
	return 0;
}


Measured memory_bytes: 952
from collections import deque
H, W = [int(i) for i in input().split()]
A = [input() for _ in range(H)]
seen = [[False]*W for _ in range(H)]
ans = 0
dq = deque([])
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            dq.append((i, j, 0))
            seen[i][j] = True
while len(dq):
    x, y, d = dq.popleft()
    ans = max(ans, d)
    for nx, ny in [(x-1, y), (x+1, y), (x, y+1), (x, y-1)]:
        if 0 <= nx < H and 0 <= ny < W:
            if not seen[nx][ny]:
                dq.append((nx, ny, d+1))
                seen[nx][ny] = True
print(ans)


Measured memory_bytes: 134876
#include<stdio.h>
int main(void){
  char s[10];
  int num[10];
  int i,count=0;
  int tmp=0;
  scanf("%s",s);
  
  for(i=0;i<10;i++){
  	switch(s[i]){
    	case 'A': num[i]=1; break;
    	case 'T': num[i]=1; break;
    	case 'C': num[i]=1; break;
    	case 'G': num[i]=1; break;
      default: num[i]=0; break;
  	}
  }
  
  for(i=0;i<10;i++){
  	if(num[i]==1){
    	count++;
    }else{
      if(tmp<=count){
        tmp=count;
    	count=0;
      }else{
        count=0;
      }
    }
  }
  if(count>=tmp) printf("%d",count);
  else           printf("%d",tmp);
  
  
  return 0;
}

Measured memory_bytes: 128
# AOJ 0231: Dangerous Bridge
# Python3 2018.6.25 bal4u
# 時間昇順ソート

while True:
	n = int(input())
	if n == 0: break
	tbl = []
	for i in range(n):
		m, a, b = map(int, input().split())
		tbl.append((a, m))
		tbl.append((b, -m))
	tbl.sort()
	sum, t, s = 0, -1, 0
	for i in range(len(tbl)):
		if t != tbl[i][0]:
			if (sum + s) > 150: break
			sum += s
			t, s = tbl[i][0], tbl[i][1]
		else: s += tbl[i][1]
	print("OK" if sum+s <= 150 else "NG")


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)

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

signed main() {
  int d, n;
  cin >> d >> n;
  if(d == 0) {
    if(n == 100) cout << 101 << endl;
    else cout << n << endl;
  }else if(d == 1) {
    if(n == 100) cout << 10100 << endl;
    else cout << n * 100 << endl;
  }else {
    if(n == 100) cout << 1010000 << endl;
    else cout << n * 10000 << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	string s;
	cin>>s;
	int sum = 0;
	for(int i = 0; i < s.length() ;i++){
		if(s[i] == 'x')
			sum++;
	}
	if(sum<=7)
		cout<<"YES\n";
	else
		cout<<"NO\n";
	return 0;
}

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

int N,H,W;
int getId(int r,int c){
  return W * r + c;
}
vector<int> X;
vector<int> V;

vector<int> calc( const vector<int>& a, const vector<int>& b ){
  vector<int> c(H*W);
  for(int i=0;i<H*W;i++){
    c[i] = b[a[i]];
  }
  return c;
}

bool check(int h){
  vector<int> res(H*W);
  for(int i=0;i<H*W;i++) res[i] = i;
  vector<int> x = X;
  while( h ) {
    if( h&1 ) res = calc( res, x );
    x = calc( x, x );
    h>>=1;
  }
  bool F[H*W] = {};
  for(int id : V ){
    if( F[res[id]] ) return true;
    F[res[id]] = true;
  }
  return false;
}

int main() {
  scanf("%d%d%d",&H,&W,&N);
  X.resize(H*W);
  V.resize(N);
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      int r,c;
      scanf("%d%d",&r,&c);
      X[getId(i,j)] = getId(r,c);
    }
  }
  for(int i=0;i<N;i++){
    int r,c; scanf("%d%d",&r,&c);
    V[i] = getId(r,c);
  }

  int st = 0, ed = H*W+500;
  int res = -1;
  while( st <= ed ) {
    int h = (st+ed)/2;
    if( check( h ) ) {
      res = h;
      ed = h-1;
    } else {
      st = h+1;
    }
  }
  cout << res << endl;

}

Measured memory_bytes: 7884
#include<bits/stdc++.h>
using namespace std ;
int a[55] ;
int b[15] ;
int q[100] , r[100] ;
int ans , cnt ;
void dfs( int k ){
     if ( k == 13 ){
         for( int i = 1 ; i <= cnt ; i++ )
             r[i] = q[i] ;
         sort( r + 1 , r + 1 + cnt ) ;
         int minx = 10086 ;
         for( int i = 1 ; i <= cnt - 1 ; i++ )
             minx = min( minx , r[i + 1] - r[i] ) ;
         minx = min( minx , 24 - r[cnt] + r[1] ) ;
         ans = max ( ans , minx ) ;
         return ;
     }
     if ( b[k] == 0 ) dfs( k + 1 );
     if ( b[k] == 1 ){
         cnt++ ; q[cnt] = k ; dfs( k + 1 ) ; cnt-- ;
         cnt++ ; q[cnt] = 24 - k ; dfs( k + 1 ) ; cnt-- ;
     }
     if ( b[k] == 2 ){
         cnt++ ; q[cnt] = k ; cnt++ ;
         q[cnt] = k ; dfs( k + 1 ) ; cnt -= 2 ;
         cnt++ ; q[cnt] = 24 - k ; cnt++ ;
         q[cnt] = k ; dfs( k + 1 ) ; cnt -= 2 ;
         cnt++ ; q[cnt] = 24 - k ; cnt++ ;
         q[cnt] = 24 - k ; dfs( k + 1 ) ; cnt -= 2 ;
     }
}
int main(){
    int N ;
    cin >> N ;
    for( int i = 1 ; i <= N ; i++ ){
        cin >> a[i] ;
        b[a[i]]++ ;
    }
    for( int i = 0 ; i <= 12 ; i++ ){
        if ( b[i] > 2 ){
            cout << 0 << endl ;
            return 0 ;
        }
    }
    cnt = 1 ; q[1] = 0 ;
    if ( b[0] ){
        cout << 0 << endl ;
        return 0 ;
    }
    dfs( 1 ) ;
    cout << ans << endl ;
    return 0 ;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int ms = 1000;
char matrix[ms][ms];

int n,m;

int main(){
	cin >> n >> m;
	for(int i = 1;i<=n;i++)
		for(int j = 1;j<=m;j++)
			cin >> matrix[i][j];
	
	for(int j = 0;j<=m+1;j++){
		matrix[0][j] = '#';
		matrix[n+1][j] = '#';	
	}
	for(int j  = 0;j<=n+1;j++){
		matrix[j][0] = '#';
		matrix[j][m+1] = '#';
	}
	
	for(int i = 0;i<=n+1;i++){
		for(int j = 0;j<=m+1;j++){
			cout<<matrix[i][j];
		}
		cout<<endl;
	}

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

template<class T> inline bool chmin(T &a,T b){
    if (a>b){a=b; return true;}
    return false;
}
template<class T> inline bool chmax(T &a,T b){
    if (a<b){a=b; return true;}
    return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> v(N),p(N),q(N);
    rep(i,N) cin >> p[i];
    rep(i,N) cin >> q[i];
    rep(i,N) v[i]=i+1;
    int a,b,cnt=0;
    do {
        rep(i,N){
            if (v[i]!=p[i]) break;
            if (i==N-1) a=cnt;
        }
        rep(i,N){
            if (v[i]!=q[i]) break;
            if (i==N-1) b=cnt;
        }
        ++cnt;
    } while(next_permutation(all(v)));
    cout << abs(a-b) << endl;
}

Measured memory_bytes: 256
#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>;
template<typename T> void chmax(T &a, T b) { a = max(a, b); }
template<typename T> void chmin(T &a, T b) { a = min(a, b); }

const ll INF = 1e15;

int main() {
    ll x, y;
    cin >> x >> y;

    ll ans = INF;
    if (x <= y) ans = min(ans, y - x);
    if (-x <= y) ans = min(ans, y+x+1);
    if (x <= -y) ans = min(ans, -y-x+1);
    if (-x <= -y) ans = min(ans, -y+x+2);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3540
using System;

namespace _075_BMI
{
	class Program
	{
		static void Main ( string[] args )
		{
			string inputStr;

			while ((inputStr = Console.ReadLine ()) != null)
			{
				decimal[] num = Array.ConvertAll (inputStr.Split (','), decimal.Parse);

				decimal bmi = num[1] / (num[2] * num[2]);

				if (25m <= bmi)
				{
					Console.WriteLine (num[0]);
				}
			}
		}
	}
}

Measured memory_bytes: 9444
N = int(input())
A = sorted((map(int,input().split())))
a_Max = A[-1]
B = [0]*a_Max
ans =0
for a in A:
    if B[a-1] == 0:
        B[a-1] = 1
        ans += 1
        for j in range(a*2-1,a_Max,a):
            B[j] = 2
    elif B[a-1] == 1:
        B[a-1] = 2
        ans -= 1
print(ans)


Measured memory_bytes: 32176
#include<cstdio>
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;

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


int main()
{
    int n, k;
    cin >>n>>k;
    long long res =k * pow(k-1,n-1);
    cout << res << endl;
    return 0;
} 

Measured memory_bytes: 384
n, g = gets.chomp.split.map(&:to_i)
a = Array.new(n) { Array.new }

n.times do |i|
  a[i] = gets.chomp.split
end

sum = 0
a.each do |a|
  if a[1] == 'JPY'
    sum += a[0].to_i
  else
    sum += a[0].to_f * 380000.0
  end

end
puts sum

Measured memory_bytes: 1916
n,x,y=map(int,input().split())
x-=1;y-=1
ans=[0]*(n)
for i in range(n-1):
    for j in range(i,n):
        dist=min(j-i,abs(x-i)+1+abs(y-j))
        ans[dist]+=1
for i in range(1,n):
    print(ans[i])

Measured memory_bytes: 47196
N = int(input())
S = input()

import numpy as np

N = np.zeros((len(S),2))
B,W = 0,1
# 左から.W 右へ#B
for idx,s in enumerate(S):
  if s is "#":
    N[idx,B] = N[idx-1,B] + 1
    N[idx,W] = N[idx-1,W]
  else:
    N[idx,B] = N[idx-1,B]
    N[idx,W] = N[idx-1,W] + 1

print(int(min([N[i,B]+N[-1,W]-N[i,W] for i in range(len(S)-1)]+[N[-1,W],N[-1,B]]   )))

Measured memory_bytes: 25096
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 17;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

int in[2][2050];
int cnt[2][2050][4050];

int dp[2050][2050];
int main() {
	int N, i, j, k;
	scanf("%d", &N);
	for (i = 1; i <= 2 * N; i++) {
		char c[2];
		int t1, t2;
		scanf("%s %d", c, &t2);
		if (c[0] == 'W') t1 = 0;
		else t1 = 1;

		in[t1][t2] = i;
	}

	for (i = 0; i < 2; i++) {
		for (j = 1; j <= N; j++) {
			for (k = 1; k <= 2 * N; k++) cnt[i][j][k] = cnt[i][j - 1][k];
			for (k = 1; k <= in[i][j]; k++) cnt[i][j][k]++;
		}
	}

	memset(dp, 0x3f, sizeof(dp));
	dp[0][0] = 0;
	for (i = 0; i <= N; i++) {
		for (j = 0; j <= N; j++) {
			if (i != N) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + cnt[0][i][in[0][i + 1]] + cnt[1][j][in[0][i + 1]]);
			if (j != N) dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + cnt[0][i][in[1][j + 1]] + cnt[1][j][in[1][j + 1]]);
		}
	}
	return !printf("%d\n", dp[N][N]);
}

Measured memory_bytes: 80768
#include<stdio.h>
int main(void){
    int t[4][14];
    char m,d;
    int n,i,j,c;
    for(i=0;i<4;i++){
        for(j=0;j<14;j++){
            t[i][j]=0;
        }
    }
    scanf("%d",&c);
    for(i=0;i<c;i++){
        scanf("%c",&d);
    scanf("%c %d",&m,&n);
    if(m=='S'){
        t[0][n]=1;
    }else if(m=='H'){
        t[1][n]=1;
    }else if(m=='C'){
        t[2][n]=1;
    }else if(m=='D'){
        t[3][n]=1;
    }
    }
    for(j=1;j<14;j++){
        if(t[0][j]!=1){
            printf("S %d\n",j);
        }
    }
    for(j=1;j<14;j++){
        if(t[1][j]!=1){
            printf("H %d\n",j);
        }
    }
    for(j=1;j<14;j++){
        if(t[2][j]!=1){
            printf("C %d\n",j);
        }
    }
    for(j=1;j<14;j++){
        if(t[3][j]!=1){
            printf("D %d\n",j);
        }
    }
    return 0;
}


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

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

fn main() {
    let k: i32 = read();
    let x: i32 = read();

    let mut anss: Vec<String> = Vec::new();
    let mut i: i32 = x - k + 1;
    while i < x + k {
        anss.push(i.to_string());
        i += 1;
    }
    println!("{}", anss.join(" "));
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FT first
#define SC second

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int, int> pint;
const int INF = 1e9;
const double EPS = 1e-9;



int main()
{
  int a, b, k ;
  cin >> a >> b >> k ;
  
  if(a+k>(a+b)/2){
    FOR(i,a,b+1){
      cout << i <<endl ;
    }
  }
  else{
    FOR(i,a,a+k){
      cout << i <<endl ;
    }
    FOR(i,b-k+1,b+1){
      cout << i <<endl ;
    }
  }

  return 0 ;
}



Measured memory_bytes: 256
n = ARGF.gets
l = ARGF.gets.split.map(&:to_i).sort

num = 0
(2 .. l.size-1).each do |i|
  half = l[i]/2
  j1 = l[0...i].bsearch_index {|x| x > half}
  next if j1 == nil
  (j1 .. i-1).each do |j|
    diff = l[i] - l[j]
    k = l[0...j].bsearch_index {|x| x > diff}
#    $stderr.puts "i,j=#{l[i]},#{l[j]}, diff=#{diff}, l=#{l[0...j]} k=#{k}"
    num += j-k unless k == nil
  end
end

puts num


Measured memory_bytes: 1912
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

using ll = long long;
constexpr int MAX = 2010;

int N, M, L;
ll memo[MAX][MAX];
vector<ll> K, sum;

ll calc(int l, int r)
{
    return (sum[K[r] + 1] - sum[K[l]]) / L;
}

ll solve(int l, int r)
{    
    ll& res = memo[l][r];
    if (res != -1) return res;

    int n = max(l, r) + 1;
    if (n == N - 1) {
        return calc(l, n) + calc(r, n);
    }
    res = min(solve(n, r) + calc(l, n),
              solve(l, n) + calc(r, n));    
    return res;
}

int main()
{    
    cin >> N >> M >> L;
    K.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> K[i]; K[i]--;
    }
    sort(K.begin(), K.end());
    
    vector<int> S(M);
    for (int i = 0; i < M; i++) {
        cin >> S[i];
    }
    
    sum.resize(M + 1);
    for (int i = 0; i < M; i++) {
        sum[i + 1] = sum[i] + S[i];
    }
    
    memset(memo, -1, sizeof(memo));
    cout << solve(0, 0) << endl;
    return 0;
}

Measured memory_bytes: 35880
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

template<class T> inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
void cmps(vector<int>&v,int &i){
	i=lower_bound(all(v),i)-v.begin();
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;


signed main(){
	string s;
	cin>>s;
	if(s=="ABC")cout<<"ARC\n";
	else cout<<"ABC\n";
}


Measured memory_bytes: 3624
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	vi a;
	a.pb(0);
	repn(i, 1, n + 1){
		int x;
		cin >> x;
		a.pb(x);
	}	
	a.pb(0);
	int sum = 0;
	repn(i, 1, n + 2) sum += abs(a[i] - a[i - 1]);
	repn(i, 1, n + 1){
		int nw = sum;
		nw -= abs(a[i] - a[i - 1]);
		nw -= abs(a[i] - a[i + 1]);
		nw += abs(a[i - 1] - a[i + 1]);
		cout << nw << endl;
	}
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 1784
#include <bits/stdc++.h>
#define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T>
T sq(T x){
  return x * x;
}

signed main (){
  string s;
cin >> s;
for(auto c : s){

if(c == ','){
cout << " ";
}else{
cout << c;
}
}
    return 0;
}


Measured memory_bytes: 256
from bisect import bisect_left
class SEGTree:
    def __init__(self,n):
        self.Unit=0
        i=1
        while(i<n):
            i*=2
        self.SEG=[self.Unit]*(2*i-1)
        self.d=i
    def update(self,i,x):
        i+=self.d-1
        self.SEG[i]+=x
        while i>0:
            i=(i-1)//2
            self.SEG[i]=self.SEG[i*2+1]+self.SEG[i*2+2]
    def find(self,a,b,k,l,r):
        if r<=a or b<=l:
            return self.Unit
        if a<=l and r<=b:
            return self.SEG[k]
        else:
            c1=self.find(a,b,2*k+1,l,(l+r)//2)
            c2=self.find(a,b,2*k+2,(l+r)//2,r)
            return c1+c2
    def get(self,a,b):
        return self.find(a,b,0,0,self.d)
N,K=map(int,input().split())
a=[int(input()) for i in range(N)]
cum=[0]*(N+1)
for i in range(N):
    cum[i+1]=cum[i]+a[i]
B=[cum[i]-i*K for i in range(N+1)]

dic={}
li=sorted(B)
for i in range(N+1):
    dic[B[i]]=bisect_left(li,B[i])
seg=SEGTree(N+1)
ans=0
for i in range(N+1):
    ans+=seg.get(0,dic[B[i]]+1)
    seg.update(dic[B[i]],1)
print(ans)

Measured memory_bytes: 117796
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout<< setprecision(20);

    int N;cin >> N;
    vector<pair<int, int>> vec;
    for(int i = 0;i < N;i++){
        int b;cin >> b;
        vec.push_back({b, i});
    }
    sort(vec.begin(), vec.end(), greater<pair<int,int>>());
    multiset<int> multi;
    multi.insert(-1);
    multi.insert(-1);
    multi.insert(N);
    multi.insert(N);

    ll ans = 0;

    for(int i = 0;i < N;i++){
        ll w = vec.at(i).second;
        int r1 = *multi.lower_bound(w);
        int rr = *next(multi.lower_bound(w));
        int l1 = *prev(multi.lower_bound(w));
        int ll = *prev(multi.lower_bound(w), 2);

        ans += ((rr - r1) * (w - l1) + (l1 - ll) * (r1 - w)) * vec.at(i).first;
        multi.insert(w);
    }
    cout<<ans<<endl;
}


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

int main() {
  int N;
  cin>>N;
  
  bool can=true;
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    if(a%2==1) continue;
    if(a%3!=0&&a%5!=0){
      can=false;
      break;
    }
  }
  if(can) cout<<"APPROVED"<<endl;
  else cout<<"DENIED"<<endl;
    
  
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<pair<ll, ll>> pll;
 
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}

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

  ll n, m;
  cin >> n >> m;

  ll ans = 0;
  ans += (n*(n-1))/2;
  ans += (m*(m-1))/2;
  cout << ans << endl;
  return 0;
}

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

int main()
{
    char s[4];
    scanf("%s", s);
    if (strlen(s) == 2) {
        printf("%s\n", s);
    } else {
        printf("%c", s[2]);
        printf("%c", s[1]);
        printf("%c", s[0]);
        printf("\n");
    }
    return 0;
}


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

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

#define mod 1000000007



using namespace std;

class CompareFirst

{

public:

  bool operator()(pair<int,int> n1,pair<int,int> n2) {

    return n1.first>n2.first; //>:desc <:asc

  }

};





int main(){
  string s,t,ss;
  int i,j,k,l,n,ans;
  vector<string> vs;
  vector<int> v[26];
  pair<int,int> pr;
  //unordered_map<string,int> mp;
  //priority_queue<int> pq; // default ‘å‚«‚¢‡
  //priority_queue<pair<int,int>,vector<pair<int,int>>,CompareFirst> pq

  int d;
  cin >> n >> d;
  
  if(n % (2*d+1) == 0)ans = n / (2*d+1);
  else ans = (n / (2*d+1)) + 1;
  
  cout << ans << endl;

  return 0;

}

Measured memory_bytes: 256
import std.stdio, std.string, std.array, std.algorithm, std.conv, std.typecons, std.numeric, std.math;

void main()
{
    auto N = readln.chomp.to!int;
    int[][] G;
    G.length = N;
    foreach (i; 0..N) {
        auto ukv = readln.split.to!(int[]);
        if (ukv[1] > 0) G[i] = ukv[2..$];
    }

    auto rr = new int[](N);
    rr[] = -1;
    rr[0] = 0;
    auto ss = [[0, 1]];
    while (!ss.empty) {
        auto s = ss[0];
        ss = ss[1..$];
        foreach (j; G[s[0]]) {
            --j;
            if (rr[j] == -1) {
                rr[j] = s[1];
                ss ~= [j, s[1]+1];
            }
        }
    }

    foreach (i; 0..N) {
        writefln("%d %d", i+1, rr[i]);
    }
}


Measured memory_bytes: 2512
#include <iostream>
#include <string>

using namespace std;

int main() {
    int h, w;
    cin >> h >> w;
    string s[h+10];
    for (int i = 1; i <= h; i++)
    {
        cin >> s[i];
    }
    for (int i = 1; i <= h; i++)
    {
        for (int j = 0; j < s[i].size(); j++)
        {
            if (s[i][j] == '.')
            {
                int sum = 0;
                if (j > 0)
                {
                    if (s[i][j-1] == '#')
                        sum++;
                    if (i > 1 && s[i-1][j-1] == '#')
                        sum++;
                    if (i < h && s[i+1][j-1] == '#')
                        sum++;
                } 
                if (j < s[i].size() - 1)
                {
                    if (s[i][j+1] == '#')
                        sum++;
                    if (i > 1 && s[i-1][j+1] == '#')
                        sum++;
                    if (i < h && s[i+1][j+1] == '#')
                        sum++;
                }
                if ( i > 1 && s[i-1][j] == '#')
                    sum++;
                if ( i < h && s[i+1][j] == '#')
                    sum++;
                s[i][j] = sum + '0';
            }
        }
    }
    for (int i = 1; i <= h; i++)
        cout << s[i] << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a,b;
while(cin>>a>>b)
{
    if((a+b)%3==0)cout<<"Possible"<<endl;
    else if(a%3==0)cout<<"Possible"<<endl;
    else if(b%3==0) cout<<"Possible"<<endl;
    else cout<<"Impossible"<<endl;
}
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 2000001

int p=0,A[N];

int max_index(int a,int b){
  
  if(A[a]>A[b])return a;
  
  else return b;
  
}

void swap(int a,int b){
  
  int tmp;
  tmp=A[a];
  A[a]=A[b];
  A[b]=tmp;
}


void insert(int k){
  int i,j;
  p++;
  A[p]=k;
  i=p;
  
  while(A[i]>A[i/2] && i>1){
    
    swap(i,i/2);
    i=i/2;
  }
}
int extract(){
  int res=A[1],i,sum;
  
  A[1]=A[p];
  p--;
  i=1;
  
  while(i*2 <= p ){
    
    if(i*2+1 <= p)
      
      sum=max_index(i*2,i*2+1);
    else sum=i*2;
    
    if(max_index(sum,i)==sum){
      
      swap(sum,i);
      i=sum;
    }
    else break;
     
  }
  
  return res;
}
int main(){
  char B[10];
  int i,j,k;
  
  while(1){
    
    scanf("%s",B);
    if(B[0]=='i'){
      scanf("%d",&k);
      insert(k);
    }
    
    if(B[0]=='e'){
      if(B[1]=='x')
	
    printf("%d\n",extract());
      if(B[1]=='n') break;
    }
  }
  
  return 0;
}



Measured memory_bytes: 5568
#include <bits/stdc++.h>
using namespace std;
 int main() {vector<int> vec={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
};
             int k;
             cin>>k;
             cout<<vec.at(k-1)<<endl;
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define minl(x, y) ((x) < (y) ? (x) : (y))
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll LINF = 2e18;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n+1);
    for(int i = 0; i < n + 1; i++)
        cin >> a[i];
    
    vector<ll> bn(n+1);
    if ((n != 0 && a[0] == 1) || (n == 0 && a[0] > 1) ) {
        cout << -1 << endl;
        return 0;
    }
    bn[0] = 1 - a[0];
    for (int i = 1; i < n + 1; i++) {
        ll pre = bn[i-1];
        if (pre > LINF) {
            bn[i] = LINF;
        }
        else
            bn[i] = pre * 2 - a[i];
        if (bn[i] < 0) {
            cout << -1 << endl;
            return 0;
        }
    }
    ll now = 0;
    ll ans = 0;
    for (int i = n; i >= 0; i--) {
        now += a[i];
        if (bn[i] != LINF)
            ans += minl(now, bn[i] + a[i]);
        else
            ans += now;
        //cout << bn[i] << ", +" << now << ", " << ans << endl;
    }

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


Measured memory_bytes: 4792
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=100005;
const int Mod=1000000007;
int a[MAXN];
bool check(int n)
{
    sort(a+1,a+n+1);
    if(n%2==0)
    {
        for(int i=1;i<=n;i++)
            if(a[i]!=2*((i+1)/2)-1)return 0;
    }
    if(n%2==1)
    {
        if(a[1]!=0)return 0;
        for(int i=2;i<=n;i++)
            if(a[i]!=2*(i/2))return 0;
    }
    return 1;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    if(check(n))
    {
        int res=1;
        for(int i=2;i<=n;i+=2)
            res=res*2%Mod;
        printf("%d\n",res);
    }
    else printf("0\n");
    return 0;
}

Measured memory_bytes: 640
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

(deftype int32 () '(signed-byte 32))
(deftype int64 () '(signed-byte 64))


;;macros
(defmacro println (n)
  `(format t "~a~%" ,n))
(defmacro vint-out (vec)
  `(progn
     (rep i (length ,vec)
          (princ (vref ,vec i))
          (princ " "))
     (fresh-line)))


;;vector
(defmacro vec (type &optional (num 100) (val 0))
  (let* ((g (gensym)))
    `(let* ((,g ,num))
       (make-array ,g :element-type ',type :initial-element ,val
                   :adjustable nil :fill-pointer ,g))))

(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))
  `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))

(defmacro vint (&optional (num 0) (val 0))
  `(vec int32 ,num ,val))

(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))
  `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))

(defmacro vref (vector pos &optional value)
  (let ((g (gensym)))
    `(let ((,g ,value))
       (if ,g
           (setf (aref ,vector ,pos) ,g)
           (aref ,vector ,pos)))))

(defmacro chvar (sym comp predicate)
  (let ((g (gensym)))
    `(let ((,g ,comp))
       (if (or (null ,sym) (not (funcall ,predicate ,sym ,g)))
           (setf ,sym ,g)))))

(defmacro chmax (sym comp &optional (predicate #'>))
  `(chvar ,sym ,comp ,predicate))

(defmacro chmin (sym comp &optional (predicate #'<))
  `(chvar ,sym ,comp ,predicate))

(defmacro defchangef (name op default-val)
  `(defmacro ,name (var &optional (val ,default-val))
     `(setq ,var (,',op ,val ,var))))

;;本体
(defun read1 (str)
  (cond
    ((= (length str) 1) (if (char= #\1 (aref str 0)) 1 0))
    ((char= (aref str 0) #\1) (1+ (read1 (subseq str 1))))
    (t 0)))


(defun main ()
  (let* ((s (write-to-string (read))) (k (read)) (one (read1 s)))
    (println
     (cond ((<= k one) 1)
           ((= (length s) one) 1)
           (t (aref s one))))))

#-swank(main)


Measured memory_bytes: 10600
package main

import (
	"fmt"
	"strings"
)

func main() {
	var S, T string
	fmt.Scan(&S, &T)

	N1, N2 := len(S), len(T)
	for i := (N1 - N2); i >= 0; i-- {
		flg := true
		for j, s := range S[i : i+N2] {
			if s == '?' {
				continue
			}
			if s != rune(T[j]) {
				flg = false
				break
			}
		}

		if flg {
			ans := S[:i] + T + S[i+N2:]
			ans = strings.Replace(ans, "?", "a", -1)
			fmt.Println(ans)
			return
		}
	}

	fmt.Println("UNRESTORABLE")
}


Measured memory_bytes: 1840
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;

int binarySearch(int A[],int key,int n){
    int left=0;
    int right=n;
    int mid;
    while(left<right){
        mid=(left+right)/2;
        if(A[mid]==key){
            return 1;
        }else if(A[mid]>key){
            right=mid;
        }else{
            left=mid+1;
        }
    }
    return 0;
}


int main(void){
    int n,t,temp;
    int cnt=0;
    scanf("%d",&n);
    int A[n];
    for(int i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
    scanf("%d",&t);
    for(int i=0;i<t;i++){
        scanf("%d",&temp);
        if(binarySearch(A,temp,n))cnt++;
    }
    printf("%d\n",cnt);
    return 0;
}



Measured memory_bytes: 3592
k=int(input())

l=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(l[k-1])

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

using namespace std;

//container util
#define SORT(c) sort((c).begin(),(c).end())

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


int main(void){


	int n; cin >> n;
	vector<int> a(n);
	REP(i,n) cin >> a[i];

	vector<int> b;

	REP(i,n){
		if(n%2 == 0){
			if(i%2 == 0){
				b.push_back(a[i]);
			}else{
				b.insert(b.begin(), a[i]);
			}
		}else{
			if(i%2 == 0){
				b.insert(b.begin(), a[i]);
			}else{
				b.push_back(a[i]);
			}
		}
	}

	REP(i,n-1){
		cout << b[i] << " ";
	}
	cout << b[n-1] << endl;

	return 0;

}


Measured memory_bytes: 3828
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

const int N = 50;

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll k;
  cin >> k;
  cout << N << "\n";
  int r = (50 - k % 50) % 50;
  ll q = (k + r) / 50;
  VL a(N);
  REP(i, 0, r) {
    a[i] = r - 2 + q;
  }
  REP(i, r, N) {
    a[i] = N - 1 + r + q;
  }
  REP(i, 0, N) {
    cout << a[i] << (i == N - 1 ? "\n" : " ");
  }
}


Measured memory_bytes: 256
(defun f(a b n)
  (max
	(if(>(expt a b)n)1(expt a b))
	(if(>(expt(1+ a)b)n)0(f(1+ a)b n))
	(if(>(expt a(1+ b))n)0(f a(1+ b)n))))
(princ(f 2 2(read)))

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

array<array<int, 2048>, 2048> nCr_dp;
ll nCr(ll n, ll r, ll mod = 1e9 + 7)
{
    if (nCr_dp[0][0] == 0) {
        nCr_dp[0][0] = 1;
        for (ll i = 1; i < 2048; i++) {
            nCr_dp[i][0] = 1;
            for (ll j = 1; j <= i; j++) {
                nCr_dp[i][j] = (nCr_dp[i - 1][j] + nCr_dp[i - 1][j - 1]) % mod;
            }
        }
    }
    return nCr_dp[n][r];
}

void main_()
{
    ll N, K;
    cin >> N >> K;

    const ll MOD = 1e9 + 7;

    for (ll i = 1; i <= K; i++) {
        cout << (nCr(N - K + 1, i, MOD) * nCr(K - 1, i - 1, MOD)) % MOD << "\n";
    }
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 15616
# AtCoder
S = input()
N = len(S)

ans = [1]*N
ans_n = len(ans)

for i in range(N-2):
    if S[i:i+2] == "RR":
        ans[i+2] += ans[i]
        ans[i] = 0

for i in range(ans_n-1, 1, -1):
    if S[i-1:i+1] == "LL":
        ans[i-2] += ans[i]
        ans[i] = 0

print(" ".join(map(str, ans)))


Measured memory_bytes: 83832
#include <stdio.h>
typedef long long ll;

ll min(ll a, ll b) {
  return a < b ? a : b;
}

int main(void) {
  ll i, j, k, n, a, b;
  scanf("%lld%lld%lld", &n, &a, &b);
  if((a + b) & 1) printf("%lld", min(a + b - 1, 2 * n - a - b + 1) >> 1);
  else printf("%lld", (b - a) >> 1);
  return 0;
}

Measured memory_bytes: 256