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

int main(){
  int W, H, mas[16][16];
  while( cin >> W >> H, W){
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
        cin >> mas[i][j];
      }
    }
    vector< vector< int > > dp( H + 1, vector< int >(W, 0));
    for(int i = 0; i < W; i++){
      if(mas[0][i] != 1) dp[0][i] = 1;
    }
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
        if(dp[i][j] == 0) continue;
        if(mas[i][j] == 0){
          for(int k = -1; k <= 1; k++){
            if(j + k < 0 || j + k >= W) continue;
            if((i == H - 1 && k == 0) || (i != H - 1 && k == 0 && mas[i + 1][j + k] == 2) || (i != H - 1 && mas[i + 1][j + k] == 0)){
              dp[i + 1][j + k] += dp[i][j];
            }
          }
        } else if(mas[i][j] == 2){
          if(i >= H - 2 || mas[i + 2][j] != 1){
            dp[min(H, i + 2)][j] += dp[i][j];
          }
        }
      }
    }

    int ret = 0;
    for(int i = 0; i < W; i++){
      ret += dp[H][i];
    }
    cout << ret << endl;
  }
}

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

int main (){
	int n;
	while ( cin >> n){
		
		int a[n];
	
		for ( int i = 0; i < n; i++){
			cin >> a[i];
		}
		for ( int o = n-1; o >= 1; o--){
			cout << a[o] << " ";
		}
		cout << a[0] << endl;
	}
}


Measured memory_bytes: 3112
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n - 1);
  for (int i = 0; i < n; ++i) cin >> a.at(i);
  for (int i = 0; i < n; ++i) cin >> b.at(i);
  for (int i = 0; i < n - 1; ++i) cin >> c.at(i);

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += b.at(a.at(i) - 1);
    if (i > 0 && a.at(i - 1) + 1 == a.at(i))
      ans += c.at(a.at(i - 1) - 1);
  }

  cout << ans << endl;
  return 0;

}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  vector<vector<int> > d(n, vector<int>(2));
  for (int i = 0; i < n; ++i) {
    cin >> d[i][0] >> d[i][1];
  }
  int cnt = 0;
  bool ok = false;
  for (int i = 0; i < n; ++i) {
    if (d[i][0] == d[i][1]) {
      cnt++;
    } else {
      cnt = 0;
    }
    if (cnt == 3) {
      ok = true;
    }
  }
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 3632
import sys
import numpy as np
from itertools import accumulate

input = sys.stdin.readline

N, M, Q = map(int, input().split())

lines = np.zeros((501, 501), np.int32)

for _ in range(M):
    l, r = map(int, input().split())
    lines[l, r] += 1

lines = np.cumsum(lines, axis = 0)
lines = np.cumsum(lines, axis = 1)


for _ in range(Q):
    p, q = map(int, input().split())
    print(lines[-1, q] - lines[p-1, q])

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

int main(int argc , char **argv)
{
	(void)argc;
	(void)argv;

	char S[201] = {};
	cin >> S;
	size_t lng = strlen(S);
	for(int i=lng-1;2<=i;i--){
		if (i%2 != 0){continue;}
		int n = i/2;
		if( 0 == strncmp( S , S+n , n ) ){
			printf("%d\n",i);
			break;
		}
	}
	return 0;
}


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

void main()
{
    auto N = readln.chomp.to!int;
    auto ps = readln.split.to!(int[]);

    int d;
    foreach (i, p; ps) {
        if (i.to!int+1 != p) ++d;
    }
    writeln(d <= 2 ? "YES" : "NO");
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int N;
	cin >> N;
	int cont = 0, ans = 0;
	for (int i = 0; i < N + 2; ++i) {
		int X;
		if (1 <= i && i <= N) cin >> X;
		else X = 0;
		if (X == 0) cont = 0;
		++cont;
		ans = max(ans, cont);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3092
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
#define llMAX 9223372036854775807
#define llMIN -9223372036854775808
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,m,x,y;

int main(){
  ll ans=0;
  cin >> n >> m;
  vi a(m);
  REP(i,m){
    cin>>a[i];
    ans+=a[i];
  }

  ans=n-ans;
  if (ans<-1)ans=-1;

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


Measured memory_bytes: 3656
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstring>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map> //pair is also included in this library
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define fst first
#define snd second
#define MP make_pair //incase c++11 or later is not available

using namespace std;

typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//prefer define statement
//for reason that const int ver. of INF will raise a silly warning (unused variable)
#define INF (INT_MAX/3)
#define LIM_INF (INT_MAX)
//const int INF = INT_MAX/3;

/*------------------------------------------------------------------------------*/

bool solve(const VI v){
  int head = v[0];
  int right_head = -1;
  REP(i, 1, 10){
    if(head >= v[i]){
      if(right_head < v[i]){
        right_head = v[i];
      } else {
        return false;
      }
    } else {
      head = v[i];
    }
  }

  return true;
}

int main(){
  int num;

  scanf("%d\n", &num);

  REP(i, 0, num){
    VI v;
    REP(j, 0, 10){
      int tmp;
      scanf("%d ", &tmp);
      v.push_back(tmp);
    }
    if(solve(v)){
      printf("YES\n");
    } else {
      printf("NO\n");
    }
  }  

  return 0;
}

Measured memory_bytes: 3140
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

def main():
    n,m,R = i_map()
    r = i_list()
    c = [[INF]*n for i in range(n)]
    for i in range(n):
        c[i][i] = 0

    for _ in range(m):
        a,b,d = i_map()
        a -= 1
        b -= 1
        c[a][b] = c[b][a] = d

    for k in range(n): # 経由
        for i in range(n): # 始点
            for j in range(n): # 終点
                c[i][j] = min(c[i][j], c[i][k] + c[k][j])

    r = list(itertools.permutations(r, R))

    ans = INF
    for i in r:
        trial = 0
        for k in range(len(i)-1):
            a = i[k] - 1
            b = i[k+1] - 1
            trial += c[a][b]
        ans = min(ans,trial)
    print(ans)




if __name__=="__main__":
    main()


Measured memory_bytes: 81728
#include <iostream>
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef long long ll;

#define pb push_back
#define fst first
#define snd second
#define FOR(i,S,E) for(int i=S; i<E; i++)
#define ri(x) scanf("%d", &x)
#define rii(x,y) scanf("%d%d", &x, &y)

const int MAXN = 200010;
int N, K, oc[MAXN];

int main() {
    rii(N, K);
    int count = 0;
    FOR(i,0,N) {
        int inp;
        ri(inp);
        if (!oc[--inp]) count++;
        oc[inp]++;
    }
    if (count <= K) {
        printf("0\n");
        return 0;
    }
    sort(oc, oc+N);
    int ans=0;
    for(int i=0; i<N && count>K; i++) {
        if (oc[i]) {
            ans += oc[i];
            count--;
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int n;
vector<int> num;
int main()
{
	cin>>n;
	for(int i=0;i<n*2;i++)
	{
		int x;
		cin>>x;
		num.push_back(x);
	}
	sort(num.begin(),num.end());
	int ans=0;
	for(int i=0;i<n*2-1;i+=2)
		ans+=min(num[i],num[i+1]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <assert.h>
#define N_MAX (100000)
#define min(a,b) (((a)<(b))?(a):(b))
typedef struct {
	int pos,value;
} Info;

signed main(){
	long long damage_total[N_MAX]={};
	Info deque[N_MAX];
	int head=0,tail=0;
	int N,H;
	long long answer = 0;

	scanf("%d%d",&N,&H);	
	int currentHP = H;
	for(int i = 0 ; i < N-1 ; i++){
		int d,h;
		scanf("%d%d",&d,&h);
		while( head != tail && deque[tail-1].value <= h ) tail--;

		deque[tail++] = (Info){i,h};
		/*while( head != tail ){
			int maximumRecover = H - (damage_total[i] - damage_total[deque[head].pos]);
			if( maximumRecover > 0 ) break;
			head++;
		}*/

		for(int j = head ; j < tail && currentHP <= d ; j++){
			// ????????§???????????§????????????
			long long maximumRecover = H - (damage_total[i] - damage_total[deque[j].pos]);
			// ??¨???????????§????????????????£???°???
			if( maximumRecover <= currentHP) continue;

			// j??????????????§?????????????????? needRecover ????¨????
			int needRecover = min( maximumRecover - currentHP , d - currentHP + 1);  
			// ???????????? needRecover ?????????????????????????????° useCount ????±????????????????????????????
			int useCount = (needRecover+deque[j].value-1) / deque[j].value - 1;
			answer += useCount;
			currentHP += useCount*deque[j].value;

			// ???j?????????????????§????°???????????????????j????????£?????´?????¨???j+1????????£?????´?????????????????????j+1????????£????????????????????????j?????????????????????
			// ??¨) ???????????¶???????????\??£?????????????????¨???????????? currentHP > d ???????????????
			if( j+1 ==  tail || maximumRecover > currentHP + deque[j+1].value ){
				currentHP = min(currentHP+deque[j].value,maximumRecover);
				answer++;
			}
		}
		currentHP -= d;
		damage_total[i+1] = damage_total[i] + d;
	}
	printf("%lld\n",answer);

}

Measured memory_bytes: 1804
import java.util.Scanner;

public class Main {

	static final int INF = 10000;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int[][] cost = new int[10][10];
		int H = sc.nextInt();
		int W = sc.nextInt();
		int[] num = new int[10];
		int ans = 0;

		for(int i = 0; i < 10; i++) {
			for(int j = 0; j < 10; j++) {
				cost[i][j] = sc.nextInt();
			}
		}

		for(int i = 0; i < 10; i++) {
			for(int j = 0; j < 10; j++) {
				for(int k = 0; k < 10; k++) {
					cost[j][k] = Math.min(cost[j][k], cost[j][i]+cost[i][k]);
				}
			}
		}

		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				int b = sc.nextInt();
				if(b != -1) num[b]++;
			}
		}

		for(int i = 0; i < 10; i++) {
			ans += num[i] * cost[i][1];
		}

		System.out.println(ans);

		sc.close();
	}
}

Measured memory_bytes: 43304
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#define ll long long
#define fr(i,l,r) for(i=(l);i<(r);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000//10^12




int main(void)
{
	//変数の宣言
	ll int n,q,h,s,d;
	
	//よく使う変数
	int i,j,k,l;
	int flag=0;
	ll int ans=0;
	int count=0;
	int temp,temp1,temp2;
	int max,min;
	int len;
	int sum=0;
	
	
	//データの読み込み
	scanf("%lld %lld %lld %lld %lld",&q,&h,&s,&d,&n);
//	scanf_s("%lld %lld %lld %lld %lld",&q,&h,&s,&d,&n);



	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理
	
	s=min(q*4,min(h*2,s));

	if(d<2*s){
		ans=n/2*d+n%2*s;
	}else{
		ans=n*s;
	}

	//	printf("計算部分終了\n");
	
	//出力
	
	printf("%lld",ans);
	
	//	printf("結果の出力終了\n");
	
	return 0;
}



Measured memory_bytes: 128
def get_input():
    X, Y, Z, K = [int(_) for _ in raw_input().split()]
    A = [int(_) for _ in raw_input().split()]
    B = [int(_) for _ in raw_input().split()]
    C = [int(_) for _ in raw_input().split()]
    return X, Y, Z, K, A, B, C

def solve2():
    X, Y, Z, K, A, B, C = get_input()
    A.sort(reverse = True)
    B.sort(reverse = True)
    C.sort(reverse = True)
    sumABC = []
    for i in range(X):
        for j in range(Y):
            for k in range(Z):
                if (i + 1) * (j + 1) * (k + 1) > K:
                    break
                sumABC.append(A[i] + B[j] + C[k])
    sumABC.sort(reverse = True)
    for i in range(K):
        print sumABC[i]

if __name__ == '__main__':
    solve2()


Measured memory_bytes: 36764
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define st(vvv) sort(vvv.begin(),vvv.end())
#define rvs(vvv) reverse(vvv.begin(),vvv.end())
int inf = 1000000007;
i64 giant = 4000000000000000000;

using namespace std;


int main() {
	int x, a;
	cin >> x >> a;
	int ans;
	if (x >= a)ans = 10;
	else ans = 0;
	cout << ans << endl;
}

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

int main(){
    int n; cin >> n;
    vector<int> s(100);
    int nten=100;
    bool flg =false;
    int sum =0;
    for(int i=0; i<n; i++){
        cin >> s[i];
        sum += s[i];
        if(s[i]%10 != 0){
            flg =true; 
            nten = min(nten, s[i]);
        }
    }
    if(flg){
        if(sum%10 != 0){
            cout << sum << endl;
        }else{
            cout << (sum - nten) << endl;
        }
    }else{
        cout << "0" << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
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(): return list(sys.stdin.readline())[:-1]
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(n):
    b = LIR(n)
    if b[0][0] > b[0][1]:
        print("NG 1")
        return
    dp = [[float("inf") for j in range(4)] for i in range(n)]
    dp[0][1] = b[0][0]
    for i in range(n-1):
        ni = i+1
        x,t = b[i]
        for a in range(4):
            nx,nt = b[ni]
            if a < 3:
                na = a+1
                T = t+na*abs(nx-x)
                if T <= nt:
                    nd = dp[i][a]+abs(nx-x)
                    if nd < dp[ni][na]:
                        dp[ni][na] = nd
            na = 1
            T = t+(a+1)*x+nx
            if T > nt:
                continue
            nd = dp[i][a]+nx+x
            if nd < dp[ni][na]:
                dp[ni][na] = nd
    ans = float("inf")
    for i in range(4):
        ans = min(ans, dp[-1][i]+b[-1][0])
    if ans == float("inf"):
        for i in range(n):
            if min(dp[i]) == float("inf"):
                print("NG",i+1)
                return
    print("OK",ans)
    return

#Solve
if __name__ == "__main__":
    while 1:
        n = I()
        if n == 0:
            break
        solve(n)



Measured memory_bytes: 8192
x = input()
y = input()

n_num = int(x.split()[0])
m_num = int(x.split()[1])
y = y.split()
sum = 0
count = 0

for i in range(0, n_num):
    y_num = int(y[i])
    sum = sum + y_num

for i in range(0, n_num):
    y_num = int(y[i])
    rate = 1 / (4 * m_num)
    if y_num < sum * rate:
        count = count + 1
    else:
        count

if (n_num - m_num) < count:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>	
#include <cmath>
#include <string>
#include<math.h>
#include<sstream>//���炵���̂Œ���
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define Cout(s) cout<<s<<endl
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
string Yes(bool b) { if (b) { return "Yes"; } else { return "No"; } }
string YES(bool b) { if (b) { return "YES"; } else { return "NO"; } }
//================================================
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int a = 1, b = 0, c, d, n, k = 0, ans = 0;
string s, t;
int mod = 1000000007;
int x[100050][2];

int main()
{
	int n, m; cin >> n >> m;
	int pn = 0, ac = 0;
	rep(i, m) {
		cin >> a >> s;
		if (s == "AC" && x[a][0] != 1) { x[a][0] = 1; pn += x[a][1]; ac++; }
		else if (s == "WA" && x[a][0] != 1)x[a][1] += 1;
	}
	cout << ac <<" "<< pn << endl;	

	return 0;
}


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


int main()
{
  int n;
  cin >> n;
  
  vector<pair<ll,ll>> task(n);
  for(int i=0;i<n;i++){
    cin >> task.at(i).second >> task.at(i).first;
  }
  //sort(ALL(task),compare_by_b);
  sort(task.begin(),task.end());
  /*for(int i=0;i<n;i++){
    cout << task.at(i).first << task.at(i).second << endl;
  }*/
  ll timecount=0;
  ll tasks=0;
  int flag=0;
  for(int i=0;i<n;i++){
    timecount+=task.at(i).second;
    //cout << timecount << endl;
    if(timecount<=task.at(i).first){
      continue;
    }
    else if(timecount>task.at(i).first){
      flag=1;
      break;
    }
    
  }
  if(flag==0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 3328
#include <iostream>
#include <queue>
using namespace std;
static const int N=100;
static const int INFTY=(1<<21);

int n,M[N][N];
int d[N];//通过距离管理访问状态(color)

void bfs(int s){
    queue<int> q;//使用标准库中的queue
    q.push(s);
    for(int i=0; i<n; i++) d[i] = INFTY;
    d[s] = 0;
    int u;
    while(!q.empty()){
        u = q.front();
        q.pop();
        for(int v=0; v<n; v++){
            if(M[u][v]==0) continue;
            if(d[v]!=INFTY) continue;
            d[v] = d[u]+1;
            q.push(v);
        }
    }

    for(int i=0; i<n; i++){
        cout<<i+1<<" "<<((d[i] == INFTY) ? (-1) : d[i])<<endl;
    }
}



int main(){
    int u,k,v;

    cin>>n;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++) M[i][j] = 0;
    }

    for(int i=0; i<n; i++){
        cin>>u>>k;
        u--;
        for(int j=0; j<k; j++){
            cin>>v;
            v--;
            M[u][v] = 1;
        }
    }

    bfs(0);
    return 0;
}


Measured memory_bytes: 3136
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)
// cout << setprecision(10)

using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

int N, M;
vector<int> s[10];
int p[10];
int main(void){
    cin >> N >> M;
    int k, t;
    REP(i, M) {
        cin >> k;
        REP(j, k){
            cin >> t;
            s[t-1].push_back(i);
        }
    }
    REP(i, M) cin >> p[i];

    int count = 0;
    int p1[10];
    REP(i, pow(2, N)){
        REP(j,M) p1[j] = 0;
        REP(j,N){
            if(((i>>j)&1)==1){
                for(int k=0;k<s[j].size();k++){
                    p1[s[j][k]]++;
                }
            }
        }
        bool b = true;
        REP(j,M) b&=(p1[j]%2 == p[j]);
        count += int(b);
    }
    cout << count << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>

int main() {
    std::string S;
    std::cin >> S;
    std::vector<char> characters;
    for (int i = 0; i < S.size(); ++i) {
        characters.push_back(S[i]);
    }
    std::sort(characters.begin(), characters.end());
    characters.erase(std::unique(characters.begin(), characters.end()), characters.end());

    if (characters.size() == 26) {
        std::cout << "None" << std::endl;
    } else {
        for (int i = 0; i < characters.size(); ++i) {
            if (characters[i] - 'a' > i) {
                std::cout << (char)('a' + i) << std::endl;
                return 0;
            }
        }
        std::cout << (char)('a' + characters.size()) << std::endl;
    }

    return 0;
}


Measured memory_bytes: 640
#include <iostream>


using namespace std;


int main(){
	int m, f, r;

	while (1){
		cin >> m >> f >> r;
		if (m == -1 && f == -1 && r == -1) break;

		else if (m == -1 || f == -1){
			cout << "F";
		}
		else if (m + f >= 80){
			cout << "A";
		}
		else if (m + f >= 65){
			cout << "B";
		}
		else if (m + f >= 50){
			cout << "C";
		}
		else if (m + f >= 30){
			if (r >= 50){
				cout << "C";
			}
			else {
				cout << "D";
			}
		}
		else {
			cout << "F";
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define fo(i,a,b)for(int i=a,_e=b;i<=_e;++i)
#define NO return printf("No"),0
#define Y return printf("Yes"),0
using namespace std;
const int N=1e5+5;
int n,m,x,y,du[N],cnt,s,t;
vector<int>e[N];
bool bz[N];
bool go(int x,int no){
	if(x==s&&no)return 1;
	bz[x]=1;
	for(int i:e[x])if(i!=no&&i!=t&&go(i,x))return 1;
	return 0;
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>m;
	fo(i,1,m)cin>>x>>y,++du[x],++du[y],e[x].push_back(y),e[y].push_back(x);
	fo(i,1,n)if(du[i]&1)NO;
	fo(i,1,n){
		if(du[i]==6)Y;
		cnt+=du[i]==4;
	}
	if(cnt>=3)Y;
	if(cnt==1)NO;
	fo(i,1,n)if(du[i]==4)s?t=i:s=i;
	if(go(s,0))Y;else NO;
}

Measured memory_bytes: 7424
from functools import lru_cache


@lru_cache(maxsize=None)
def fact(n):
    ret = 1
    MOD = 10**9 + 7
    for i in range(1, n + 1):
        ret = ret * i % MOD
    return ret


N, M = map(int, input().split())
MOD = 10**9 + 7
diff = abs(N - M)


if diff == 0:
    ans = (fact(N) * fact(M)) * 2
elif diff == 1:
    ans = fact(N) * fact(M)
else:
    ans = 0


ans %= MOD
print(ans)

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);
    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


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

    ll n, k; cin >> n >> k;
    vector<ll> h(n, 0);
    rep(i, n) cin >> h[i];
    sort(h.begin(), h.end());

    ll sum = 0;
    rep(i, n-k) sum += h[i];
    cout << sum << endl;
    
    return 0;
}



Measured memory_bytes: 1792
#include <iostream>
#include <vector>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

// ベル数は、写像12相のうち以下に相当する
//  ・玉の区別をする
//  ・箱の区別をしない
//  ・箱に入る玉の数に制限はない

// 単純に考えると、スターリング数をS(n,k)として、
// B(n,k) = S(n,0) + S(n,1) + ... + S(n,k)

// 計算方法: O(min(N,K)lon(N))
//  B(n,k) = Σ(0<=i<=k) i^n / i! * (Σ(0<=j<=k-i) (-1)^j / j!)
//  Σ(0<=j<=k-i) (-1)^j / j! が事前計算可能なので、O(min(N,K)lon(N))になる
//  cf: https://qiita.com/drken/items/f2ea4b58b0d21621bd51

// B(n,n) = B(n) をベル数と呼ぶこともある。以下の漸化式でO(N^2)
// B(n+1) = Σ(0<=i<=n) nCi * B(n) : 要素n+1と同じグループにならない要素数をiとするとわかる

class Combination {
public:
    vector <ll> fac, inv, fiv;
    Combination(int N) : fac(N + 1), inv(N + 1), fiv(N + 1) {
        fac[0] = inv[0] = fiv[0] = fac[1] = inv[1] = fiv[1] = 1;
        for (ll i = 2; i <= N; i++) {
            fac[i] = fac[i - 1] * i % MOD; // n!
            inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD; // n^-1
            fiv[i] = fiv[i - 1] * inv[i] % MOD; // (n!)^-1
        }
    }
};

ll pow_mod(ll num, ll pow, ll mod) {
    ll prod = 1;
    num %= mod;
    while (pow > 0) { if (pow & 1) prod = prod * num % mod; num = num * num % mod; pow >>= 1; }
    return prod;
}

ll bell_number(int n, int k) {
    if (n == 0) return 1;
    k = min(k, n);
    Combination com(k);
    ll ret = 0;
    vector <ll> pre(k + 1, 1);
    for (int i = 1; i <= k; i++) {
        if (i & 1) pre[i] = pre[i - 1] - com.fiv[i];
        else pre[i] = pre[i - 1] + com.fiv[i];
    }
    for (int i = 1; i <= k; i++) {
        ret += pow_mod(i, n, MOD) * com.fiv[i] % MOD * pre[k - i];
        ret %= MOD;
    }
    return ret;
}


// verified
//   https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/5/DPL_5_G
void AOJ_DPL_5_G() {
    int n, k;
    cin >> n >> k;
    cout << bell_number(n, k) << '\n';
}

int main() {
    AOJ_DPL_5_G();
    return 0;
}


Measured memory_bytes: 3124
n = int(input())
H = list(map(int, input().split()))

counter = 0
max_counter = 0
for i in range(n-1):
  if H[i] >= H[i+1]:
    counter += 1
  else:
    max_counter = max(max_counter, counter)
    counter = 0
else:
    max_counter = max(max_counter, counter)
print(max_counter)

Measured memory_bytes: 63984
n,m=map(int,input().split())
a=[map(int,input().split())for _ in range(m)]
g=[list(map(int,'0'*n))for _ in range(n)]
for x,y in a:
  g[x-1][y-1]+=1
  g[y-1][x-1]+=1
for i in range(n):
  print(sum(g[i]))

Measured memory_bytes: 3060
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int k,x;
    scanf("%d%d",&k,&x);
    for(int i=x-k+1;i<=x+k-1;i++)
    {
        printf("%d",i);
        if(i!=x+k-1)
        {
            printf(" ");
        }
    }
}

Measured memory_bytes: 128
//https://atcoder.jp/contests/abc137/tasks/abc137_d
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
struct Info{
    ll A;
    ll B; //day
};
int main() {
#if LOCAL&01
    std::ifstream in("./test/sample-1.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#endif
    ll N, M; cin>>N>>M;    
    vector<Info> tbl(N);
    //unordered_map<ll,ll> cntd;
    unordered_map<ll,deque<Info*>> daytbl;
    for(auto&& t: tbl){
        cin>>t.A>>t.B;
        daytbl[t.A].push_back(&t);
        //cntd[t.A]++;
    }

    ll ans=0;
    priority_queue<ll> candidate;
    for(ll i=1;i<=M;++i){
        for(const auto& d:daytbl[i]){
            candidate.push(d->B);
        }
        if(!candidate.empty()){
            ans+=candidate.top();
            candidate.pop();
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 75428
from itertools import combinations
s = input()
ans = 0
for i in range(len(s)):
    for ind in combinations(range(1, len(s)), i):
        c = 0
        st = s
        for j in ind:
            st = st[:j+c] + '+' +st[j+c:]
            c += 1
        ans += eval(st)
print(ans)

Measured memory_bytes: 3060
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;


int main(){
  int n;
  cin >> n;
  int v[n];
  int c[n];
  rep(i,n) cin >> v[i];
  rep(i,n) cin >> c[i];
  int ans = 0;
  rep(i,n){
    if(v[i]-c[i] > 0){
      ans += v[i] - c[i];
    }
  }
  printf("%d\n", ans);
  return 0;
}


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

#define fi first
#define se second
#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define pb push_back

const int N = 705;
const int MOD = 1e9 +7 ;
const int oo = 1e9;

typedef pair<int, int> ii;

int n, cnt, m;
ii sz[N];
int visit[N];
bool vi[N][N], rev[N][N], f[N][N][N];

void solve(int u, int pos)  {
    if(pos == 0) sz[cnt].fi ++;
    else sz[cnt].se ++;
    visit[u] = pos;
    int nex = 1 - pos;
    FOR(i, 1, n) if(rev[u][i])  {
        if(visit[i] == -1) solve(i, nex);
        else    if(visit[i] != nex) {
            cout << "-1"; exit(0);
        }
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n >> m;
    FOR(i, 1, m) {
        int u, v; cin >> u >> v;
        vi[u][v] = vi[v][u] = true;
    }
    FOR(i, 1, n)    FOR(j, 1, n) if(!vi[i][j] && i != j) rev[i][j] = rev[j][i] = true;
    memset(visit, -1, sizeof visit);
    FOR(i, 1, n) if(visit[i] == -1) {
        cnt ++;
        solve(i, 0);
    }
    // :D Now we have done the calc all the val
    f[0][0][0] = true;
    FOR(i, 0, cnt - 1) FOR(j, 0, n) FOR(t, 0, n)    if(f[i][j][t] == true)  {
        ii val = sz[i + 1];
        f[i + 1][j + val.fi][t + val.se] = true;
        f[i + 1][j + val.se][t + val.fi] = true;
    }
    int ans = oo;
    FOR(i, 0, n) FOR(j, 0, n) if(f[cnt][i][j]) ans = min(ans, i * (i - 1) / 2 + (j - 1) * j / 2);
    cout << ans;
}


Measured memory_bytes: 338688
#include <bits/stdc++.h>
using namespace std; 
const int dx[]={1,0,-1,0,1,-1,-1,1}; 
const int dy[]={0,1,0,-1,1,1,-1,-1}; 
const int INF = 1e9; 
const long long LINF = 1e18; 
const double EPS = 1e-8; 
#define pb push_back
#define mk make_pair 
#define fr first 
#define sc second 
#define ll long long 
#define reps(i,j,k) for(int i = (j); i < (k); ++i) 
#define rep(i,j) reps(i,0,j) 
#define all(a) (a).begin(),(a).end() 
#define MOD 1000000007 
typedef pair<int,int> Pii;
typedef vector<int> vi;
int main(){
    ll n;
    vector<ll> a;
    vector<ll> b;
    cin >> n;
    rep(i,n){
        ll c,d;
        cin >> c >> d;
        a.pb(c);
        b.pb(d);
    }
    ll cnt = 0;
    for(int i = n-1; i >= 0; --i){
        a[i] += cnt;
        if(a[i] == 0){
            continue;
        }
        else if(a[i] <= b[i]){
            //cout <<"[" <<  b[i]-a[i] << "] ";
            cnt += b[i]-a[i];
        }
        else{
            ll t = 0;

            ll tmp = a[i]/b[i];
            ++tmp;
            t = b[i]*tmp-a[i];
            if(a[i]%b[i] == 0){
                t = 0;
            }
            cnt += t;
            //cout << "[" << t  << "] ";
        }
        //cout << cnt << endl;
        
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 1001001001001001001;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main(){
    ll A,B,C,X,Y;
    cin >> A >> B >> C >> X >> Y;
    if(X < Y){
        swap(A,B);
        swap(X,Y);
    }
    ll ans = INF;
    ans = min({ans,Y * C * 2 + (X - Y) * A,X * C * 2,A * X + B * Y});
    cout << ans << endl;
}


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll n,x;
ll a[100];

int main(){
  cin>>n>>x;
  rep(i,n)cin>>a[i];
  sort(a,a+n);
  ll res=0;
  ll sum=0;
  rep(i,n-1){
    if(sum+a[i]>x)break;
    sum+=a[i]; res++;
  }
  if(sum+a[n-1]==x)cout<<n<<endl;
  else cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>

int memo[100005];

int rec(int n){
  if(n == 0) return 0;
  if(memo[n] != -1) return memo[n];
  int res = n;
  for(int pow6 = 1; pow6 <= n; pow6 *= 6) res = min(res, rec(n - pow6) + 1);
  for(int pow9 = 1; pow9 <= n; pow9 *= 9) res = min(res, rec(n - pow9) + 1);
  return memo[n] = res;
}

int main(){
  ll N;  cin >> N;
  rep(i,0,100005) memo[i] = -1;
  cout << rec(N) << endl;
  return 0;
}

/*
#include <iostream>
using namespace std;
const int MAX_N = 110000;
int dp[MAX_N]; // dp[i] が i についての答え

int main() {
  int N;
  cin >> N;
  // 初期化
  for (int i = 0; i < MAX_N; ++i) dp[i] = N; // INF の気持ち
  dp[0] = 0;
  // 貰う DP --- dp[n] に遷移を集める
  for (int n = 1; n <= N; ++n) {
    for (int pow6 = 1; pow6 <= n; pow6 *= 6) {
      dp[n] = min(dp[n], dp[n - pow6] + 1);
    }
    for (int pow9 = 1; pow9 <= n; pow9 *= 9) {
      dp[n] = min(dp[n], dp[n - pow9] + 1);
    }
  }
  cout << dp[N] << endl;
}
*/

/*
#include <iostream>
using namespace std;
const int MAX_N = 110000;
int dp[MAX_N]; // dp[i] が i についての答え

int main() {
    int N;    cin >> N;
    // 初期化
    for (int i = 0; i < MAX_N; ++i) dp[i] = N; // INF の気持ち
    dp[0] = 0;
    // 配る DP --- dp[n] から遷移を出して行く
    for (int n = 0; n < N; ++n) {
        for (int pow6 = 1; n + pow6 <= N; pow6 *= 6) {
            dp[n + pow6] = min(dp[n + pow6], dp[n] + 1);
        }
        for (int pow9 = 1; n + pow9 <= N; pow9 *= 9) {
            dp[n + pow9] = min(dp[n + pow9], dp[n] + 1);
        }
    }
    cout << dp[N] << endl;
}
*/

Measured memory_bytes: 7080
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>

using namespace std;

typedef long long ll;

#define int long long

signed main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  int a, b, c, d, e, f, g;
  cin >> a >> b >> c >> d >> e >> f >> g;
  int ans = 0;
  int tk = min(a, min(d, e));
  for (int go = max(0LL, tk - 1); go <= tk; ++go) {
    ans = max(ans, ((a - go) / 2) * 2 + b + 3 * go + ((d - go) / 2) * 2 + ((e - go) / 2) * 2); 
  }
  cout << ans << '\n';
}



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

int main() {
    int n;
    cin >> n;
    int sum = 0;
    for(int i = 1; i <= n; i += 2)
    {
        int cnt = 0;
        for(int j = 1; j <= i; j++) {
            if (i % j == 0) cnt++;
        }
        if (cnt == 8) sum++;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
n = int(input())
li = list(map(int, input().split()))
ans = 1
flg = 0
for i in range(n):
  if flg==1 and li[i]!=0:
    continue
  elif li[i]==0:
    ans = 0
    break
  else:
    ans *= li[i]
  if(ans>1000000000000000000):
    flg = 1
if flg==1 and ans==0:
  print(ans)
elif flg==1:
  print(-1)
else:
  print(ans)

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

using namespace std;

long long int gcd(long long int a,long long int b)
{
    if(b==0)
       return a;
       
    else
       return gcd(b,a%b);
}

int main()
{
  
    long long int x,i,y,ans=0;
    scanf("%lld%lld",&x,&y);
    if(x==y ||((x>y) && (gcd(x,y)==y)))
       printf("-1");
    
    else
    {
          ans=(x*y)/(gcd(x,y));
          printf("%lld",ans-x);
         
    }
   
     
    
}

Measured memory_bytes: 256
// Let's bring the sky down :)
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 3e5 + 5;
ll a[N];
int main()
{
    ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    multiset<double> s;
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        double x;
        cin >> x;
        s.insert(x);
    }
    while(s.size() > 1){
        double yo = *(s.begin());
        s.erase(s.begin());
        double go = *(s.begin());
        s.erase(s.begin());
        s.insert((yo + go) / 2.0);
    }
    cout << fixed << setprecision(10) << *(s.begin());
return 0;
}


Measured memory_bytes: 256
n = gets.to_i
ans = Array.new(n, 0)
(n - 1).times do |i|
  c, s, f = gets.split.map(&:to_i)
  0.upto(i) do |j|
    if j == i
      ans[j] = s + c
    elsif ans[j] <= s
      ans[j] = s + c
    else
      x = (ans[j] - s + f  - 1)  / f
      ans[j] = s + f * x + c
    end
  end
end

ans.each do |x|
  puts x
end


Measured memory_bytes: 1788
n,m = map(int, input().split())
xyz = [list(map(int, input().split())) for i in range(n)]
max_list = [list() for i in range(8)]
MAX = 0
for x,y,z in xyz:
  max_list[0].append(x+y+z)
  max_list[1].append(x+y-z)
  max_list[2].append(x-y+z)
  max_list[3].append(x-y-z)
  max_list[4].append(-x+y+z)
  max_list[5].append(-x+y-z)
  max_list[6].append(-x-y+z)
  max_list[7].append(-x-y-z)
for i in range(8):
  max_list[i].sort(reverse = True)
for i in max_list:
  MAX = max(MAX,sum(i[:m]))
print(MAX)
    

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

int main(){
    while(1){
        int n; cin>>n;
        if(n == 0) return 0;

        vector<vector<int>> t(n, vector<int>(n+1));
        for(int i=0; i<n; i++){
            for(int j=0; j<=n; j++){
                cin>>t[i][j];
            }
        }

        vector<int> dp((1<<n), 1e8);
        dp[0] = 0;

        for(int bit=0; bit<(1<<n); bit++){
            for(int i=0; i<n; i++){
                if((1 << i) & bit) continue;

                int nbit = (1 << i) | bit;

                int tmin = t[i][0];
                for(int j=0; j<n; j++){
                    if((1 << j) & bit){
                        tmin = min(tmin, t[i][j+1]);
                    }
                }

                dp[nbit] = min(dp[nbit], dp[bit] + tmin);
            }
        }

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


Measured memory_bytes: 3400
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

int main() {
    int n; cin >> n;
    int m; cin >> m;
    int ans = 1;
    for (int i = 1; i < m; ++i) {
        if (i * i > m) break;
        if (m % i == 0 && m / i >= n) ans = max(ans, i);
        if (m % i == 0 && i >= n) ans = max(ans, m / i);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,i,s;
string a,b,c;
set<char> aa; 
int main()
{
	cin>>n>>a>>b>>c;
	for (i=0;i<n;i++)
	{
		aa.clear();aa.insert(a[i]);aa.insert(b[i]);aa.insert(c[i]);s+=aa.size()-1;
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
signed main(){
  int N,M,Q; cin>>N>>M>>Q;
  vi A(N),B(M);
  rep(i,0,N) cin>>A[i];
  rep(i,0,M) cin>>B[i];
  A.pb(MOD);
  B.pb(MOD);
  vi C(N),D(M);
  rep(i,0,N){
    int K=dislow(B,A[i]);
    C[i]=B[K]-A[i];
    if(K>0)
      C[i]=min(C[i],A[i]-B[K-1]);
  }
  rep(i,0,M){
    int K=dislow(A,B[i]);
    D[i]=A[K]-B[i];
    if(K>0)
      D[i]=min(D[i],B[i]-A[K-1]);
  }
  rep(_,0,Q){
    int X; cin>>X;
    int Y=dislow(A,X);
    int ans=A[Y]-X+C[Y];
    if(Y>0)
      ans=min(ans,X-A[Y-1]+C[Y-1]);
    Y=dislow(B,X);
    ans=min(ans,B[Y]-X+D[Y]);
    if(Y>0)
      ans=min(ans,X-B[Y-1]+D[Y-1]);
    cout<<ans<<endl;
  }
  }


Measured memory_bytes: 4448
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	vector<int>a(n), b(n),c(m),d(m),manD;
	for (int i = 0; i < n; i++)cin >> a[i] >> b[i];
	for (int i = 0; i < m; i++)cin >> c[i] >> d[i];

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			manD.push_back(abs(a[i] - c[j]) + abs(b[i] - d[j]));
		}
		vector<int>::iterator iter = min_element(manD.begin(),manD.end());
		size_t index = distance(manD.begin(),iter);
		cout << index+1 << endl;
		manD.erase(manD.begin(), manD.end());
	}
}


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

using namespace std;

int main()
{
   int x;
   cin >> x;
   vector<int> poss(x+200);
   poss[0] = 1;
   for(int i = 0; i < x+1; i++){
        if(poss[i]){
            for(int j = 0; j < 6; j++){

                poss[i+100+j] = 1;
            }
        }
   }
   cout << poss[x] << endl;
   return 0;
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	
	public static int[] readInts(String cad) {
		String read[] = cad.split(" ");
		int res[] = new int[read.length];
		for (int i = 0; i < read.length; i++) {
			res[i] = Integer.parseInt(read[i]);
		}
		return res;
	}
	
	public static void main(String[] args) throws IOException {
		StringBuilder out = new StringBuilder();
		BufferedReader in;
		
			in = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(in.readLine());
		int hi[] = readInts(in.readLine());
		int dp[] = new int[n];
		
		dp[0] = 0;
		dp[1] = Math.abs(hi[0] - hi[1]);
		for( int i = 2; i < n; i++ ) 
			dp[i] = Math.min(Math.abs(hi[i-1] - hi[i]) + dp[i-1], Math.abs(hi[i-2] - hi[i]) + dp[i-2]);
		
		System.out.print(dp[n-1]);

	}
	
}


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

#define INF (int)1e9+7
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define N 100005
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795

ll no_of_div(ll a)
{
  ll cnt=0,i;
  if (a==2)return 1;
  for(i=2;i*i<a;i++)
  {
if(a%i==0)cnt+=2;
  }
  if(i*i==a)cnt++;
  return cnt;
}

//vl a(1001);

ll powM(ll a,ll b)
{ 
  ll ans=1;
  while(b>0)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }

return ans;
}

ll abc(ll x)
{
  ll cnt_f=0,cnt_s=0;
  while(x)
  {
    ll dig=x%10;
    if(dig==4)cnt_f++;
    else cnt_s++;
    x/=10;
  }
  return (cnt_f==cnt_s);
}





int main()
{
   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
ll a,b;cin>>a>>b;

if(a==1||b==1)cout<<1<<"\n";
else
cout<<(a*b+1)/2<<"\n";


  return 0;

}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DHandstand2 solver = new DHandstand2();
        solver.solve(1, in, out);
        out.close();
    }

    static class DHandstand2 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int h[] = new int[100];
            long ans = 0;
            for (int i = 1; i <= n; i++) {
//            out.println((Integer.toString(i).charAt(0)-'0') * 10 + i%10);
                h[(Integer.toString(i).charAt(0) - '0') * 10 + i % 10]++;
                if ((((i % 10) * 10) + Integer.toString(i).charAt(0) - '0') % 10 != (((i % 10) * 10) + Integer.toString(i).charAt(0) - '0') / 10) {
                    ans += 2 * h[((i % 10) * 10) + Integer.toString(i).charAt(0) - '0'];
//                out.println(i + " " + 2 *h[((i % 10) * 10) + Integer.toString(i).charAt(0) - '0']);
                } else {
                    ans += 2 * (h[((i % 10) * 10) + Integer.toString(i).charAt(0) - '0'] - 1) + 1;
//                out.println(i + " " + h[((i%10)*10) + Integer.toString(i).charAt(0)-'0']);
                }
//            out.println(i + " " + h[((i%10)*10) + Integer.toString(i).charAt(0)-'0']);
            }
            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 43172
import java.util.Deque;
import java.util.LinkedList;
import java.util.Scanner;

class Main {
	static final String YES = "YES";
	static final String NO = "NO";

	public static void main(String[] args) {
		Scanner sc = null;
		try {
			sc = new Scanner(System.in);
			int countDataset = sc.nextInt();
			int[] ballNums = new int[10];

			for (int i = 0; i < countDataset; i++) {
				for (int j = 0; j < 10; j++) {
					ballNums[j] = sc.nextInt();
				}

				System.out.println(push(ballNums) ? YES : NO);
			}
		} finally {
			sc.close();
		}
	}

	public static boolean push(int[] nums) {
		Deque<Integer> list1 = new LinkedList<Integer>();
		Deque<Integer> list2 = new LinkedList<Integer>();
		list1.add(0);
		list2.add(0);
		for (int number : nums) {
			if (list1.peek() < number) {
				list1.push(number);
			} else if (list2.peek() < number) {
				list2.push(number);
			} else {
				return false;
			}
		}
		return true;
	}
}

Measured memory_bytes: 26012
#include<iostream>
#include<algorithm>
using namespace std;
int main (void)
{
  int i,a[5],b[5],ans=650,sum,aa=0;
  for(i=0;i<5;i++)
  {
    cin>>a[i];
  }
  for(i=0;i<5;i++)
  {
    b[i]=a[i]%10;
    if(b[i]==0)b[i]=10;
    if(ans>b[i])ans=b[i],sum=i;
    
    a[i]=a[i]+10-b[i];
  }
  for(i=0;i<5;i++)
  {
    aa+=a[i];
    if(i==sum){aa+=b[i];}
  }
  aa-=10;
  cout<<aa<<endl;
  
  
}

Measured memory_bytes: 3640
import math
N, M = map(int, input().split())
S = input()
T = input()
X = {}
for i in range(N):
    X[M*i] = S[i]
for i in range(M):
    if N*i in X and X[N*i] != T[i]:
        print(-1)
        exit()
print(N*M//math.gcd(N,M))


Measured memory_bytes: 91652