akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
	
#define roop(i, start, end) for(int i=start;i<end;i++)
	
using namespace std;
using ll = long long int;
using ull = unsigned long long;
	
float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

bool isPrime(int x) {
    if (x <= 1) return false;
    for (int i = 2; i*i <= x; i++) {
        if (x % i == 0) {
            return false;
        }
    }
    return true;
}
	
int main() {
    ll a;
    cin >> a;
    ll r = a;
    while(!isPrime(r)) {
        r++;
    }
    cout << r << endl;
	return 0;
}

Measured memory_bytes: 256
<?php
$n=trim(fgets(STDIN));
$d=explode(" ",trim(fgets(STDIN)));
$e=array_count_values($d);
sort($d);
$i=0;
$j=0;
while($i<$n){
  $j+=$e[$d[$i]];
  if($j==$n/2){
    echo $d[$i+$e[$d[$i]]]-$d[$i];
    exit;
  }elseif($j>$n/2){
    echo 0;
    exit;
  }
  $i+=$e[$d[$i]];
}

Measured memory_bytes: 16884
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    String str = br.readLine();
	    StringTokenizer st = new StringTokenizer(str, " ");

		int a  = Integer.parseInt(st.nextToken());
		int b  = Integer.parseInt(st.nextToken());
		int c  = Integer.parseInt(st.nextToken());

		if(a < b && b < c) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

	}

}

Measured memory_bytes: 24240
#include <stdio.h>

int main() {
  char top = 0;
  char in[4];
  scanf("%s", in);
  // printf("%s\n", in);
  for (int i = 0; i < 4; i++) {
    if (*(in + i * sizeof(char)) == 'o') top++;
  }
  printf("%d\n", 700 + top * 100);
  return 0;
}


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

using namespace std;

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

  int64_t a, b, x;
  cin >> a >> b >> x;

  bool bo = false;
  if (a == 0) bo = true;
  a = (a - 1 + bo) / x;
  b = b / x + bo;
  b -= a;

  cout << b << '\n';

  return 0;
}


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

int main() {
	int h, w;
	cin >> h >> w;

	string c[h];
	for (int i = 0; i < h; i++) {
		cin >> c[i];
	}

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

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

int main(){

  int N1,N2,a;
  cin >> N1;
  N2 = N1;
  while(0 < N1){
  	a += N1 % 10;
    N1 /= 10;
  }
  if(N2 % a == 0){
  cout << "Yes";
  }else{
  cout << "No";
  }
}



Measured memory_bytes: 256
n=int(input())
p=[2]
d=[0 for i in range(n+1)]
for i in range (2,n+1):
    j=0
    t=i
    while len(p)>j:
        a=p[j]
        if(t%a==0):
            d[a]+=1
            t//=a
        else:
            j+=1
    else:
        if(t==i):
            d[t]+=1
            p.append(i)
ans=1
for i in d[2:]:
    ans*=i+1
print(ans%1000000007)

Measured memory_bytes: 3064
def factorize(n):
    fct = []
    
    for i in range(2, int(n**0.5)+1):
        c = 0
        
        while n%i==0:
            n //= i
            c += 1
            
        if c>0:
            fct.append((i, c))
    
    if n>1:
        fct.append((n, 1))
    
    return fct

MAX = 10**5+100
MOD = 10**9+7
fact = [0]*MAX #fact[i]: i!
inv = [0]*MAX #inv[i]: iの逆元
finv = [0]*MAX #finv[i]: i!の逆元
fact[0] = 1
fact[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
    
for i in range(2, MAX):
    fact[i] = fact[i-1]*i%MOD
    inv[i] = MOD-inv[MOD%i]*(MOD//i)%MOD
    finv[i] = finv[i-1]*inv[i]%MOD

def C(n, r):
    if n<r:
        return 0
    if n<0 or r<0:
        return 0
    return fact[n]*(finv[r]*finv[n-r]%MOD)%MOD

N, M = map(int, input().split())
fct = factorize(M)
ans = 1

for _, c in fct:
    ans *= C(N-1+c, c)
    ans %= MOD

print(ans)

Measured memory_bytes: 41328
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,d;
    cin>>n>>d;
    int x = (2*d+1);
    PUTS(n % x == 0 ? n/x : n/x + 1);
}

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

struct era {
    char era_name[8];
    int era_year;
};

void trans(int year, int month, int day);

int main(void)
{
    int year, month, day;
    while (scanf("%d %d %d", &year, &month, &day) != EOF) {
	trans(year, month, day);
    }
    return 0;
}


void trans(int year, int month, int day)
{
    int n = 0;
    struct era data;
    if (year - 1989 > 1) {
	strcpy(data.era_name, "heisei");
	data.era_year = year - 1989 + 1;
    } else if (year -1989 == 0) {
	if (month - 1 > 0) {
	    strcpy(data.era_name, "heisei");
	    data.era_year = 1;
	} else if (month - 1 == 0) {
	    if (day - 8 >= 0) {
		strcpy(data.era_name, "heisei");
		data.era_year = 1;
	    } else {
		strcpy(data.era_name, "showa");
		data.era_year = 64;
	    }
	}
    } else if (year - 1926 > 0) {
	strcpy(data.era_name, "showa");
	data.era_year = year - 1926 + 1;
    } else if (year - 1926 == 0) {
	if (month - 12 == 0) {
	    if (day - 25 >= 0){
		strcpy(data.era_name, "showa");
		data.era_year = 1;
	    } else {
		strcpy(data.era_name, "taisho");
		data.era_year = 15;
	    }
	} else {
	    strcpy(data.era_name, "taisho");
	    data.era_year = 15;
	}
    } else if (year - 1912 > 0) {
	strcpy(data.era_name, "taisho");
	data.era_year = year - 1912 + 1;
    } else if (year - 1912 == 0) {
	if (month - 7 > 0) {
	    strcpy(data.era_name, "taisho");
	    data.era_year = 1;
	} else if (month - 7 == 0) {
	    if (day - 30 >= 0) {
		strcpy(data.era_name, "taisho");
		data.era_year = 1;
	    } else {
		strcpy(data.era_name, "meiji");
		data.era_year = 45;
	    }
	} else {
	    strcpy(data.era_name, "meiji");
	    data.era_year = 45;
	}
    } else if (year - 1868 > 0) {
	strcpy(data.era_name, "meiji");
	data.era_year = year - 1868 + 1;
    } else if (year - 1868 == 0) {
	if (month - 9 > 0) {
	    strcpy(data.era_name, "meiji");
	    data.era_year = 1;
	} else if (month - 9 == 0) {
		if (day - 8 >= 0) {
		    strcpy(data.era_name, "meiji");
		    data.era_year = 1;
		} else {
		    n += 1;
		}
	} else {
	    n += 1;
	}
    } else {
	n += 1;
    }
    if (n == 1) {
	printf("pre-meiji\n");
    } else {
	printf("%s %d %d %d\n", data.era_name, data.era_year, month, day);
    }
}
		
	    
   	    

Measured memory_bytes: 1036
n,m = map(int,input().split())


matrix = [[0]*m for i in range(n)]
mtx = []

for i in range(n):
    mtx = input().split()
    for j in range(m):
        matrix[i][j] = int(mtx[j])

vector =[0]*m

for a in range(m):
    vector[a] = int(input())

answer = [0]*n
    
for b in range(n):
    for c in range(m):
        answer[b] += matrix[b][c] * vector[c]
    print(answer[b])
    


Measured memory_bytes: 6016
N, M = map(int, input().split())
set_a, set_b = set(), set()

for i in range(M):
    a, b = map(int, input().split())
    if a == 1:
        set_a.add(b)
    if b == N:
        set_b.add(a)

if set_a & set_b:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 19024
import sys


def part(s, links):
    grp = [set(), set()]
    q = [(s, -1, 0)]
    while q:
        v, p, g = q.pop()
        grp[g].add(v)
        for u in links[v]:
            if u == p:
                continue
            q.append((u, v, g ^ 1))
    return grp


def solve(n, links):
    grp = part(0, links)
    can = [[], [], []]
    for i in range(1, n + 1):
        can[i % 3].append(i)
    # print(grp)
    # print(can)

    if len(grp[0]) > len(grp[1]):
        grp[0], grp[1] = grp[1], grp[0]
    if len(can[1]) > len(can[2]):
        can[1], can[2] = can[2], can[1]

    ans = [0] * n

    if len(grp[0]) <= len(can[0]):
        for i, v in enumerate(grp[0]):
            ans[v] = can[0].pop()
        can = can[0] + can[1] + can[2]
        for i, v in enumerate(grp[1]):
            ans[v] = can.pop()
        return ans

    for i, v in enumerate(grp[0]):
        if can[1]:
            ans[v] = can[1].pop()
        else:
            ans[v] = can[0].pop()
    for i, v in enumerate(grp[1]):
        if can[2]:
            ans[v] = can[2].pop()
        else:
            ans[v] = can[0].pop()
    return ans


n = int(input())
links = [set() for _ in range(n)]
for line in sys.stdin:
    a, b = map(int, line.split())
    a -= 1
    b -= 1
    links[a].add(b)
    links[b].add(a)
print(*solve(n, links))


Measured memory_bytes: 84056
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
#define sz(x) (int)(x).size();
inline int in(){int x;scanf("%d",&x);return x;}
vector<int> siz;
vector<int> par;
vector<set<int>> f;
vector<int> b;
int find(int node)
{
	while(node!=par[node])
	node=par[node];
	
	return node;
}
void uni(int a,int b)
{
	a=find(a);
	b=find(b);
	if(a==b)return;
	if(siz[a]<siz[b])
	{
		par[a]=b;
		siz[b]+=siz[a];
	}
	else
	{
		par[b]=a;
		siz[a]+=siz[b];
	}
}
int32_t main()
{
	int n=in();int m=in();int k=in();
	siz=vector<int>(n,1);
	par=vector<int>(n);b=siz;
	f=vector<set<int>>(n);
	
	iota(par.begin(),par.end(),0);
	int u,v;
	for(int i=0;i<m;i++)
	{
		cin>>u>>v;
		u--;v--;
		uni(u,v);
		f[u].insert(v);f[v].insert(u);
	}
	for(int i=0;i<k;i++)
	{
		cin>>u>>v;
		u--;v--;
		if(find(u)==find(v))
		{
			if(f[u].find(v)!=f[u].end())
			{
				f[v].erase(u);
				f[u].erase(v);
			}
			b[u]++;b[v]++;
			
		}
	}
	for(int i=0;i<n;i++)
	{
		cout<<siz[find(i)]-(f[i].size()+b[i])<<" ";
	}
	
	
}

Measured memory_bytes: 18496
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

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

    vector<int> v(N, 0);
    for(int i=0;i<M;i++){
        int a, b;
        cin >> a >> b;
        if(a > b) swap(a, b);
        v[a-1]++;
        v[b-1]--;
    }
    for(int i=0;i<N-1;i++){
        if(v[i] % 2 == 1){
            cout << "NO" << endl;
            return 0;
        }
        v[i+1] += v[i];
    }
    cout << "YES" << endl;
    return 0;
}

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

int main(void) {
  char S[101];
  long long int K;
  scanf("%s%d", S, &K);
  int i;
  int r = 1;
  if(strlen(S) < K) {
    for(i = 0; i < strlen(S); i++) {
      if(S[i] != '1') {
        r = S[i]-48;
        break;
      }
    }
  }
  else {
    for(i = 0; i < K; i++) {
      if(S[i] != '1') {
        r = S[i]-48;
        break;
      }
    }
  }
  printf("%d\n", r);
  return 0;
}

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

#define M 1046527
#define NIL (-1)
#define L 14
char H[M][L];

int getChar(char c){
	if(c == 'A') return 1;
	if(c == 'C') return 2;
	if(c == 'G') return 3;
	if(c == 'T') return 4;
	return 0;
}
long long getKey(char s[]){
	long long sum = 0,p = 1;
	int i , l=strlen(s);
	for(i = 0;i < l;i++){
		sum+=p*getChar(s[i]);
		p*=5;
	}
	return sum;
}

long long h1(long long key){ return key % M; }
long long h2(long long key){ return 1 + (key % (M - 1)); }

int insert(char s[]){
	long long key, i, h;
	key = getKey(s);
	for(i=0;;i++){
		h = (h1(key) + i*h2(key)) % M;
		if(strcmp(H[h],s) == 0 ) return 1;
		else if( strlen(H[h]) == 0 ){
			strcpy(H[h], s);
			return 0;
		}
	}
	return 0;
}

int find(char s[]){
	long long key, i, h;
	key = getKey(s);
	for(i = 0;;i++){
		h = (h1(key) + i * h2(key)) % M;
		if( strcmp(H[h],s) == 0) return 1;
		else if(strlen(H[h]) == 0) return 0;
	}
	return 0;
}

int main(){
	int i,n,j,k;
	char s[L],c[9];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s %s", c, s);
		if(c[0] == 'i') insert(s);
		else{
			if(find(s)) printf("yes\n");
			else printf("no\n");
		}
	}
	return 0;
} 


Measured memory_bytes: 17048
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
cnt = 0
lack = 0

for i in range(n):
    if a[i] < b[i]:
        cnt += 1
        lack += b[i] - a[i]
    elif a[i] > b[i]:
        c.append(a[i] - b[i])

c = sorted(c)[::-1]
asum = sum(a)
bsum = sum(b)

if asum < bsum:
    print(-1)
    exit()
if cnt == 0:
    print(0)
    exit()

for i in c:
    lack -= i
    cnt += 1
    if lack <= 0:
        break

print(cnt)

Measured memory_bytes: 24224
#include <stdio.h>

int main(void){

  int n,m;
  scanf("%d %d", &n, &m);
  int eveneven;
  int oddodd;
  eveneven = n*(n-1)/2;
  oddodd = m*(m-1)/2;
  int answer = eveneven+oddodd;
  printf("%d\n", answer);

  return 0;
}

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

int main(){
  int n;
  cin>>n;
  
  int t[n+1], x[n+1], y[n+1];
  t[0]=x[0]=y[0]=0;
  for(int i=1;i<=n;i++){
    cin>>t[i] >>x[i] >>y[i];
  }
  
  bool ok=true;
  for(int i=0;i<n;i++){
    int dt=t[i+1]-t[i], dx=abs(x[i+1]-x[i]), dy=abs(y[i+1]-y[i]);
    
    if(dt<(dx+dy)){ok=false;break;}
    if((dx+dy-dt)%2!=0){ok=false;break;}
  }
  
  cout<<(ok ? "Yes":"No")<<endl;
  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr int MOD = 1000000007;
constexpr int MAX = 2000005;

ll f[MAX];
void init() {
    f[0] = 1;
    for (int i = 1; i < MAX; i++)
        f[i] = (f[i - 1] * i) % MOD;
}

ll inv(ll x) {
    ll res = 1;
    ll k = MOD - 2;
    ll y = x;
    while (k) {
        if (k & 1) res = (res * y) % MOD;
        y = (y * y) % MOD;
        k /= 2;
    }
    return res;
}

ll C(int n, int k) {
    ll a = f[n];
    ll b = f[n-k];
    ll c = f[k];
    ll bc = (b * c) % MOD;
    return (a * inv(bc)) % MOD;
}

ll powmod(ll a, ll n, ll m = MOD) {
    ll ret = 1;
    for (; n > 0; n >>= 1, a = a * a % m) {
        if (n % 2 == 1) {
          ret = ret * a % m;
        }
    }
    return ret;
}

int main() {
    init();
    int k;
    cin >> k;
    string s;
    cin >> s;
    
    int n = s.size() + k, m = s.size();
    
    ll ans = 0;
    for (int i = m; i <= n; i++) {
        ll d = C(i-1, m-1) * powmod(25, i-m);
        d %= MOD;
        d *= powmod(26, n-i);
        d %= MOD;
        ans += d;
        ans %= MOD;
        //cout << i << " " << d << " " << ans << endl;
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 20944
#include <iostream>
#include <limits>
#include <utility>
#include <vector>

void merge(std::vector<std::pair<char, int> > &s, int left, int mid, int right)
{
    int n1 = mid - left;
    int n2 = right - mid;
    std::vector<std::pair<char, int> > L(n1+1);
    std::vector<std::pair<char, int> > R(n2+1);

    for (int i = 0; i < n1; i++) {
        L[i] = s[left + i];
    }
    for (int i = 0; i < n2; i++) {
        R[i] = s[mid + i];
    }
    L[n1] = std::pair<char, int>('L', std::numeric_limits<int>::max());
    R[n2] = std::pair<char, int>('R', std::numeric_limits<int>::max());

    int i = 0;
    int j = 0;
    for (int k = left; k < right; k++) {
        if (L[i].second <= R[j].second) {
            s[k] = L[i];
            i++;
        }
        else {
            s[k] = R[j];
            j++;
        }
    }

}

void mergesort(std::vector<std::pair<char, int> > &s, int left, int right)
{
    if (left + 1 < right) {
        int mid = left + (right - left) / 2;
        mergesort(s, left, mid);
        mergesort(s, mid, right);
        merge(s, left, mid, right);
    }
}

int partition(std::vector<std::pair<char, int> > &v, int left, int right)
{
    std::pair<char, int> pivot = v[right];
    int index = left - 1;
    std::pair<char, int> tmp;

    for (int i = left; i < right; i++) {
        if (v[i].second <= pivot.second) {
            index++;
            tmp = v[i];
            v[i] = v[index];
            v[index] = tmp;
        }
    }

    tmp = v[index + 1];
    v[index + 1] = v[right];
    v[right] = tmp;

    return index + 1;
}

void quicksort(std::vector<std::pair<char, int> > &v, int left, int right)
{
    if (left < right) {
        int pivot = partition(v, left, right);
        quicksort(v, left, pivot - 1);
        quicksort(v, pivot + 1, right);
    }
}

bool isstable(std::vector<std::pair<char, int> > &stable, std::vector<std::pair<char, int> > &array)
{
    for (int i = 0; i < array.size(); i++) {
        if (stable[i].first != array[i].first)
            return false;
    }

    return true;
}

int main(int argc, char const *argv[])
{
    int n;
    std::cin >> n;
    std::vector<std::pair<char, int> > vq(n);
    for (int i = 0; i < n; i++) {
        std::cin >> vq[i].first >> vq[i].second;
    }

    std::vector<std::pair<char, int> > vm = vq;

    quicksort(vq, 0, n - 1);
    mergesort(vm, 0, n);

    // judge stability
    if (isstable(vm, vq))
        std::cout << "Stable" << std::endl;
    else
        std::cout << "Not stable" << std::endl;

    for (int i = 0; i < n; i++) {
        std::cout << vq[i].first << " " << vq[i].second << std::endl;
    }

    return 0;
}

Measured memory_bytes: 3356
#pragma GCC optimize("Ofast")
#include <stdio.h>
//#include <string>
#include <vector>
#include <algorithm>
//#include <cmath>
#include <utility>

using namespace std;


int main() {

	int n, a, b, time = 0;
	bool finished = true;
	vector<pair<int, int>> work;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d%d", &a, &b);
		work.emplace_back(b, a);
	}
	sort(work.begin(), work.end());

	for (int i = 0; i < n && finished; ++i) {
		time += work.at(i).second;
		if (time > work.at(i).first)finished = false;
		//work.erase(work.begin());
	}

	if (finished)printf("Yes\n");
	else printf("No\n");

	return 0;
}

Measured memory_bytes: 2420
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
B.sort()
C.sort()

def bin_serch(array,num):
    head = 0
    tail = len(array)
    while head < tail:
        center = (head + tail) // 2
        if num < array[center]:
            tail = center
        else:
            head = center + 1
    return head

BC = [0 for _ in range(len(B))]
for i in range(len(B)):
    BC[i] = len(C) - bin_serch(C,B[i])
    
s = 0
for i in range(len(BC)-1, -1, -1):
    s += BC[i]
    BC[i] = s

ans = 0
for a in A:
    b = bin_serch(B,a)
    if b < len(B):
        ans += BC[b]
    
print(ans)

Measured memory_bytes: 105644
//
//  main.cpp
//
// https://atcoder.jp/contests/abc132/tasks/abc132_d

#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

// 重み付き有向グラフ、隣接リスト表現
struct ListCostGraph {
    // 辺構造体
    struct Edge {
        size_t from;
        size_t to;
        int cost;
    };
    // 辺のリスト
    vector<vector<Edge>> edges;
    // コンストラクタ
    ListCostGraph(size_t size) {
        edges.resize(size);
    }
    // 辺を追加する
    void add_edge(size_t from, size_t to, int cost) {
        edges[from].push_back(Edge{from, to, cost});
    }
    // ダイクストラ法 O(E logV)
    vector<int> dijkstra(size_t s) {
        vector<int> dist(edges.size(), numeric_limits<int>::max());
        using P = pair<int, size_t>;
        constexpr size_t DISTANCE = 0;
        constexpr size_t VERTEX = 1;
        priority_queue<P, vector<P>, greater<P>> que;
        dist[s] = 0;
        que.push(P(0, s));
        while (!que.empty()) {
            P p = que.top();
            que.pop();
            size_t v = get<VERTEX>(p);
            int d = get<DISTANCE>(p);
            if (dist[v] < d) {
                continue;
            }
            for (int i = 0; i < edges[v].size(); i++) {
                const Edge& e = edges[v][i];
                int new_dist = dist[v] + e.cost;
                if (dist[e.to] <= new_dist) { // eを使っても最短経路が改善しないとき
                    continue;
                }
                dist[e.to] = new_dist;
                que.push(P(new_dist, e.to));
            }
        }
        return dist;
    }
};

int main(int argc, char* argv[]) {
    int N, M;
    cin >> N >> M;
    ListCostGraph graph(3 * N);
    for (int i = 0; i < M; i++) {
        int ui, vi;
        cin >> ui >> vi;
        ui--;
        vi--;
        for (int j = 0; j < 3; j++) {
            graph.add_edge(3 * ui + j, 3 * vi + (j + 1) % 3, 1);
        }
    }
    int S, T;
    cin >> S >> T;
    S--;
    T--;
    S *= 3;
    T *= 3;
    int dist = graph.dijkstra(S)[T];
    if (dist == numeric_limits<int>::max()) {
        cout << -1 << endl;
    } else {
        cout << dist / 3 << endl;
    }
}



Measured memory_bytes: 17792
n=int(input())
tou=[[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for _ in range(n):
    b,f,r,v=map(int, input().split())
    tou[b-1][f-1][r-1]+=v
 
for i in range(4):
    for j in range(3):
        print(' ', end='')
        print(*tou[i][j])
    if i!=3: print('#'*20)


Measured memory_bytes: 5628
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define N 100000
int n,k;
int w[105],v[105];
ll dp[N+5];
int main() {
    cin>>n>>k;
    for(int i=1;i<=n;i++) {cin>>w[i]>>v[i];}
    for(int i=1;i<=N;i++) {dp[i]=int(2e9);}
    for(int i=1;i<=n;i++) {
       for(int j=N;j>=v[i];j--)
       	{dp[j]=min(dp[j],dp[j-v[i]]+w[i]);}
    }
    int ans=0;
    for(int i=0;i<=N;i++) {
       if(dp[i]<=k) {ans=max(ans,i);}
    }
    cout<<ans<<endl;
}


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

typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string str1,str2;
    cin>>str1>>str2;
    if(str1.size()>str2.size())
    {
        cout<<"GREATER"<<endl;
    }
    else if(str1.size()<str2.size())
    {
        cout<<"LESS"<<endl;
    }
    else
    {
        if(str1>str2)
        {
            cout<<"GREATER"<<endl;
        }
        else if(str1<str2)
        {
            cout<<"LESS"<<endl;
        }
        else
        {
            cout<<"EQUAL"<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int dx[] = {0, 0, 1, -1};
constexpr int dy[] = {1, -1, 0, 0};

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

    int x;
    cin >> x;

    if (x == 3 || x == 5 || x == 7)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}

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

int main(){
	int a,b,k;
	cin>>a>>b>>k;
	int cnt = 0;
	for(int i=min(a,b);i>=1;i--){
		if(a%i==0&&b%i==0)cnt++;
		if(cnt==k){
			cout<<i<<endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  vector<bool> c(8, false);
  int res = 0;
  rep(i, n) {
    if (a[i] >= 3200) res++;
    else c[a[i] / 400] = true;
  }

  int ans = 0;
  rep(i, 8) {
    if (c[i]) ans++;
  }
  cout << max(1, ans) << " " << ans + res << endl;



  
  return 0;
}

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

public class MainClass
{
	public const long Giri = 1000000007;

	
	public static void Main(string[] args)
	{
		var n = Console.ReadLine().ToInt();
		var s = Input().ToInt();
		long wa = 0;
		for(int i = 0; i < n; i++)
		{
			wa += s[i]-1;
		}
		Console.WriteLine(wa);
		
	}


	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}


Measured memory_bytes: 11200
import java.util.Arrays;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		int n=sc.nextInt();
		int[] h=new int[n+1];
		int[] preh=new int[n+1];
		for(int i=1;i<=n;i++) {
			int buf=sc.nextInt();
			h[i]=buf;
			preh[i]=buf;
		}
		Arrays.sort(h);

		for(int i=1;i<=n;i++) {
			if(preh[i]>h[(n+1)/2]) {
				System.out.println(h[(n+1)/2]);
			}else {
				System.out.println(h[(n+1)/2+1]);
			}

		}
	}
}

Measured memory_bytes: 89204
import java.util.*;
public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int P = sc.nextInt();
    int Q = sc.nextInt();
    int R = sc.nextInt();
    int max = Math.max(Math.max(P, Q), R);
    int ans = P + Q + R - max;
    System.out.println(ans);
  }  
}

Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <map>
#include <cassert>

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

struct Network {
private:
    vector<map<ll, ll>> adj;
    bool directed;
public:
    explicit Network(bool directed) : directed(directed) {}

    void add_edge(ll from, ll to, ll weight){
        assert(from >= 0);
        assert(to >= 0);
        assert(weight >= 0);
        if(adj.size() < max(from, to) + 1){
            adj.resize(max(from, to) + 1);
        }
        adj.at(from)[to] = weight;

        if(!directed){
            adj.at(to)[from] = weight;
        }
    }

    ll get_weight(ll from, ll to) const {
        return adj.at(from).at(to);
    }

    void floyd_warhsall(vector<vector<ll>>& out){
        const ll n = adj.size();
        out.resize(adj.size(), vector<ll>(n, -1));
        for(ll i = 0; i < n; ++i){
            for(auto p : adj.at(i)){
                out.at(i).at(p.first) = p.second;
            }
            out.at(i).at(i) = 0;
        }

        for(ll k = 0; k < n; ++k){
            for(ll i = 0; i < n; ++i){
                if(out.at(i).at(k) == -1){
                    continue;
                }
                const ll dik = out.at(i).at(k);
                for(ll j = 0; j < n; ++j){
                    if(out.at(k).at(j) == -1){
                        continue;
                    }
                    const ll dkj = out.at(k).at(j);
                    const ll dij = out.at(i).at(j);

                    if(dij == -1 || dij > dik + dkj){
                        out.at(i).at(j) = dik + dkj;
                    }
                }
            }
        }
    }
};

int main(){
    ll n, m, l;
    cin >> n >> m >> l;

    Network net1(false);
    REP(i, m){
        ll ai, bi, ci;
        cin >> ai >> bi >> ci;
        ai--; bi--;
        net1.add_edge(ai, bi, ci);
    }

    vector<vector<ll>> dist1;
    net1.floyd_warhsall(dist1);

    Network net2(false);
    for(ll i = 0; i < dist1.size(); ++i){
        for(ll j = i + 1; j < dist1.size(); ++j){
            if(dist1.at(i).at(j) != -1 && dist1.at(i).at(j) <= l){
                net2.add_edge(i, j, 1);
            }
        }
    }

    vector<vector<ll>> dist2;
    net2.floyd_warhsall(dist2);

    ll q;
    cin >> q;
    vector<ll> ans(q, 0);
    REP(i, q){
        ll si, ti;
        cin >> si >> ti;
        si--; ti--;

        if(si >= dist2.size() || ti >= dist2.size()){
            ans.at(i) = -1;
        }else{
            ans.at(i) = dist2.at(si).at(ti);
        }
    }

    REP(i, q){
        cout << max(-1LL, ans.at(i) - 1) << endl;
    }
    return 0;
}


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

unsigned long long n,m,tr=1;

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

    cin>>n>>m;

    for(int i=0;i<m;i++)
        tr*=2;

    cout<<(m*1900+(n-m)*100)*tr<<endl;

    return 0;
}


Measured memory_bytes: 3580
from copy import deepcopy
import itertools

h, w, k = map(int, input().split())

maps = [list(input()) for _ in range(h)]
ans = 0

for i in range(2 ** h):
    for j in range(2 ** w):
        tmp_maps = deepcopy(maps)
        for x in range(h):
            if (i >> x) & 1:
                tmp_maps[x] = list('.' * w)
        for y in range(w):
            if (j >> y) & 1:
                for l in range(h):
                    tmp_maps[l][y] = '.'
        #print(i, j)
        #for map in tmp_maps:
        #    print(map)
        #print('')
        #print(list(itertools.chain.from_iterable(tmp_maps)))
        cnt = list(itertools.chain.from_iterable(tmp_maps)).count('#')
        if cnt == k:
            ans += 1

print(ans)


Measured memory_bytes: 9352
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    String S = sc.next();
    String T = sc.next();
    int gcd = calcGcd(N, M);
    long lcm = (long)gcd*(N/gcd)*(M/gcd);
    long ans = lcm;
    long step = ((long)N/gcd)*((long)M/gcd);
    for (long i = 0; i < lcm; i+=step) {
      if (S.charAt((int)(i*gcd/M)) != T.charAt((int)(i*gcd/N))) {
        ans = -1;
        break;
      }
    }
    System.out.println(ans);
  }
  
  private static int calcGcd(int n, int m) {
    int gcd = 1;
    for (int i = 1; i <= n && i <= m; i++) {
      if (n%i == 0 && m%i == 0) {
        gcd = i;
      }
    }
    return gcd;
  }
}

Measured memory_bytes: 27220
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define LL_MAX LLONG_MAX
#define ULL_MAX ULLONG_MAX
#define ull unsigned long long
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb(x) push_back(x)
#define re() pop_back()
#define eb(x) emplace_back(x)
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define all(a) a.begin(),a.end()
#define msort(a) sort(a.begin(),a.end())
#define pii pair<int,int>
#define sz(x) int(x.size())
#define mk make_pair
#define endl '\n'

void solve()
{
    int x;
    cin>>x;
    if(x>=30) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

int main()
{
    IOS;
    ll t=1; //cin>>t;
    while (t--)
    {
        solve();
    }
}

Measured memory_bytes: 3648
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<iomanip>
#include<cmath>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
	ll N,M; cin >> N >> M;
	ll all = N*M;
	if(N == 1 && M == 1){
		cout << 1 << endl;
		return 0;
	}
	if(N == 1 || M == 1){
		cout << all-2 << endl;
		return 0;
	}
	ll white = (N-1) * 2 + (M-1) * 2;
	ll ans = all - white;
	cout << ans << endl;
  
}


Measured memory_bytes: 256
using System;
class Program{
	static int[][] a=new int[10][];
	static int[] h=new int[10];
	static void Main(){
		int[] s=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		int ans=0;
		for(int i=0;i<10;i++){
			a[i]=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
			h[i]=a[i][1];
		}
		for(int i=0;i<10;i++){
			if(i!=1){fu(i,h[i]);}
		}
		for(int i=0;i<s[0];i++){
			int[] q=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
			for(int j=0;j<s[1];j++){
				ans+=q[j]==-1?0:h[q[j]];
			}
		}
		Console.WriteLine("{0}",ans);
	}
	static void fu(int n,int c){
		for(int i=0;i<10;i++){
			if(a[i][n]+c<h[i]){
				h[i]=a[i][n]+c;
				fu(i,h[i]);
			}
		}
	}
}

Measured memory_bytes: 15316
#include<stdio.h>
 int main(void)
 {
  int n,a,b,r=0,i,j;
  scanf("%d%d%d",&n,&a,&b);
  for(i=1; i<=n; i++){
     int s=0;
     j=i;
     for(;j;j/=10)s+=j%10;
     if(a<=s&&s<=b)r+=i;
      }
      printf("%d\n",r);
      return 0;
     }



Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		
		final int a = sc.nextInt() - 1;
		final int b = sc.nextInt() - 1;
		final int c = sc.nextInt() - 1;
		final int d = sc.nextInt() - 1;
		
		int min = Integer.MAX_VALUE;
		
		for(int w = 1; w <= 100; w++){
			final int a_x = a % w;
			final int a_y = a / w;
			final int b_x = b % w;
			final int b_y = b / w;
			final int c_x = c % w;
			final int c_y = c / w;
			final int d_x = d % w;
			final int d_y = d / w;
			
			int dist1 = Math.abs(a_x - b_x) + Math.abs(a_y - b_y);
			int dist2 = Math.abs(c_x - d_x) + Math.abs(c_y - d_y);
			
			//System.out.println(w + " " + dist1 + " " + dist2);
			
			min = Math.min(min, dist1 + dist2);
		}
		
		System.out.println(min);
	}

}

Measured memory_bytes: 17348
n, m = map(int, input().split())

peoples = []
checkpoints = []

for i in range(n):
    array = list(map(int, input().split()))
    peoples.append(array)

for j in range(m):
    array = list(map(int, input().split()))
    checkpoints.append(array)

for i in range(n):
    min_dist = 1000000000
    index = 0
    for j in range(m):
        dist = abs(checkpoints[j][0] - peoples[i][0]) + abs(checkpoints[j][1] - peoples[i][1])
        if dist < min_dist:
            min_dist = dist
            index = j
    print(index+1)


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

int main()
{
 int A,B,C;
 int caneat = 0;
 cin >> A >> B >> C;
 if(A + B >= C) caneat += B + C;
 else caneat += (A  + B + 1) + B;
 cout << caneat;
 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
signed main(){
  int x=0,y=0,z=0;
  string s;
  std::cin >> s>>x;
  rep(i,s.size()){
    if(i*x>s.size()-1)return 0;
    std::cout << s[i*x];
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

struct S{
    int a,b,c,d;
    S(int a,int b,int c,int d) : a(a),b(b),c(c),d(d){}
};

int main(){
    int H,W; cin >> H >> W;
    vector<vector<int>> a(H,vector<int>(W));
    rep(i,H){
        rep(j,W){
            cin >> a[i][j];
        }
    }

    vector<S> ans;
    for(int i=0;i<H;i++){
        for(int l=0;l<W;l++){
            if(a[i][l]%2==0) continue;
            int r = l+1;
            while(r<W and a[i][r]%2==0) r++;
            if(r == W){
                for(int now=l;now+1<W;now++){
                    ans.push_back(S(i,now,i,now+1));
                }
                a[i][l]--;
                a[i][r-1]++;
                break;
            }

            for(int now=l;now<r;now++){
                ans.push_back(S(i,now,i,now+1));
            }
            a[i][l]--;
            a[i][r]++;
            l = r;
        }
    }



    const int w = W-1;
    for(int l=0;l<H;l++){
        if(a[l][w]%2==0) continue;

        int r = l+1;
        while(r<H and a[r][w]%2==0) r++;
        if(r==H) continue;

        for(int now=l;now<r;now++){
            ans.push_back(S(now,w,now+1,w));
        }
        a[l][w]--;
        a[r][w]++;
    }


    cout << ans.size() << endl;
    for(const auto& p : ans){
        cout << p.a + 1 << " " << p.b +1 << " " << p.c +1 << " " << p.d +1 << endl;
    }
}


Measured memory_bytes: 5232
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long N;
    cin >> N;
    long long l=1,r=26;
    long long tmp = 1;
    while(1)
    {
        if(l <= N && r >= N)
        {
            break;
        }
        tmp++;
        l = r+1;
        r = pow(26,tmp) + r;
    }
    N = N - l;
    vector<int> ans;
    while(N >= 26)
    {
        long long amari  = N % 26;
        ans.push_back(amari);
        N /= 26;
    }
    ans.push_back(N);
    for (int i = 0; i < tmp - ans.size(); i++)
    {
        cout << 'a';
    }
    
    for (int i = ans.size()-1; i >= 0; i--)
    {
       cout << (char)('a' + ans[i]);
    }

}

Measured memory_bytes: 4084
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt(),X=sc.nextInt();
		int ans=1;
		double D=0;

		for(int i=0;i<N;i++) {
			int L=sc.nextInt();
			D+=L;
			if(D<=X) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<int>;
using A = array<int, 2>;
constexpr int MOD{1000000000 + 7};
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
constexpr array<int, 4> dx{1, 0, -1, 0};
constexpr array<int, 4> dy{0, 1, 0, -1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
constexpr int div_roundup(int a, int b)
{
    return (a + b - 1) / b;
}
// power with modulo
ll powMod(ll b, ll e, const ll m = MOD)
{
    ll r = 1;
    for (; e > 0; e >>= 1)
    {
        if (e & 1)
            r = (r * b) % m;
        b = (b * b) % m;
    }
    return r;
}
// factrial with modulo
ll factMod(const ll n, const ll m = MOD)
{
    ll x = 1;
    for (ll i = 1; i <= n; ++i)
        x = (x * i) % m;
    return x;
}
class Combi
{
private:
    const int n_;
    const int mod_;
    vector<ll> fac_, finv_;

public:
    Combi(int n = 10000, int mod = MOD);
    ll count(int n, int k);
};

Combi::Combi(int n, int mod) : n_(n), mod_(mod)
{
    fac_.resize(n_);
    finv_.resize(n_);
    vector<ll> inv(n_);

    fac_[0] = fac_[1] = 1;
    finv_[0] = finv_[1] = 1;
    inv[1] = 1;

    for (int i = 2; i < n_; i++)
    {
        fac_[i] = fac_[i - 1] * i % mod_;
        inv[i] = mod_ - inv[mod_ % i] * (mod_ / i) % mod_;
        finv_[i] = finv_[i - 1] * inv[i] % mod_;
    }
}

ll Combi::count(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac_[n] * (finv_[k] * finv_[n - k] % mod_) % mod_;
}

// vector<vector<int>> vec(n_rows, vector<int>(n_cols, value));

// *****************************************************************************

void solve()
{
    Combi c(2000 + 10);

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

    rep(i, k)
    {
        const ll a = c.count(n - k + 1, i + 1);
        const ll b = c.count(k - 1, i);

        const ll ans = a*b%MOD;
        cout << ans << endl;
    }
}

// *****************************************************************************

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

    solve();
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 11 15:57:04 2018
ABC046D
@author: maezawa
"""
import collections

s = input()
n = len(s)
np = n // 2
ng = n - np

c = collections.Counter(s)
#print(c)
win = (c['g'] - ng -(c['p'] - np))//2
print(win)

Measured memory_bytes: 3572
#include <iostream>
using namespace std;
int cnt,w,h;
int map[51][51];
void check(int i,int j){
	if(map[i][j]!=1)return;
	map[i][j]=2;
	if(i>0)check(i-1,j);
	if(i<h-1)check(i+1,j);
	if(j>0)check(i,j-1);
	if(j<w-1)check(i,j+1);
	if(i>0&&j>0)check(i-1,j-1);
	if(i>0&&j<w-1)check(i-1,j+1);
	if(i<h-1&&j>0)check(i+1,j-1);
	if(i<h-1&&j<w-1)check(i+1,j+1);
}


int main(){
	while(1){
		cin >>w >>h;
		if(!(w||h))break;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				cin >>map[i][j];
			}
		}
		cnt=0;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(map[i][j]==1){
					cnt++;
					check(i,j);
				}
			}
		}
	cout << cnt<<endl; 

	}
}

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

int N;
int a[100];

int main(){
    int sum = 0;
    cin >> N;
    for(int i=0;i<N;i++) cin >> a[i];
    for(int i=0;i<N;i++) sum += a[i];
    int x = round((double)sum/N);
    long long cost = 0;
    for(int i=0;i<N;i++) cost += (long long)(x-a[i]) * (x-a[i]);
    cout << cost << endl;
    return 0;
}

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

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

#define POS(i,j) ((i)*100+(j))

void run(void){
  int a,b;
  scanf("%d%d",&a,&b);
  int board[10000];
  const int l=100;
  int i,j;
  for(i=0;i<l/2;i++) for(j=0;j<l;j++) board[POS(i,j)]=0;
  for(i=l/2;i<l;i++) for(j=0;j<l;j++) board[POS(i,j)]=1;

  i=0;
  j=0;
  while(b>1){
    if(j>=l){
      i+=2;
      j=0;
    }
    board[POS(i,j)]=1;
    j+=2;
    b--;
  }
  i=l-1;
  j=0;
  while(a>1){
    if(j>=l){
      i-=2;
      j=0;
    }
    board[POS(i,j)]=0;
    j+=2;
    a--;
  }
  printf("%d %d\n",l,l);
  for(i=0;i<l;i++){
    for(j=0;j<l;j++){
      printf("%c",board[POS(i,j)]==0?'.':'#');
    }
    printf("\n");
  }
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return ~n & 1; }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

main {
  while (true) {
    int n, w, d;
    cin >> n >> w >> d;
    if (n == 0 && w == 0 && d == 0) break;
    vector<pair<int, int>> cs;
    cs.emplace_back(w, d);
    rep(i, n) {
      int p, s;
      cin >> p >> s;
      --p;
      int w = cs[p].first, d = cs[p].second;
      s %= (w + d);
      cs.erase(cs.begin() + p);
      if (s < w) {
        cs.emplace_back(s, d);
        cs.emplace_back(w - s, d);
      } else {
        cs.emplace_back(w, s - w);
        cs.emplace_back(w, d + w - s);
      }
      sort(cs.end() - 2, cs.end(), [](auto &p, auto &q) { return p.first * p.second < q.first * q.second; });
    }
    vector<int> s(n + 1);
    rep(i, n + 1) s[i] = cs[i].first * cs[i].second;
    sort(all(s));
    cout << s << endl;
  }
}



Measured memory_bytes: 3096