akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef long long ll;

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 int INF = 1001001001;
const ll INFL = 1LL<<60;

void warshall_floyd(const int& V, vector<vector<int>>& d) {
  rep(k, V) rep(i, V) rep(j, V) chmin(d[i][j], d[i][k] + d[k][j]);
}

int main() {
  int n, m, l;
  cin >> n >> m >> l;
  vector<vector<int>> d(n, vector<int>(n,INF));
  rep(i,n) d[i][i] = 0;
  rep(i,m) {
    int a, b, c;
    cin >> a >> b >> c;
    --a; --b;
    d[a][b] = d[b][a] = c;
  }
  rep(k,n)rep(i,n)rep(j,n) chmin(d[i][j], d[i][k]+d[k][j]);

  // warshall_floyd(n, d);  // 各町の間の最短間距離を求める
/*
  vector<vector<int>> dd(n, vector<int>(n, INF));
  rep(i, n) rep(j, n) {
    if (d[i][j] <= l) dd[i][j]  = 1;  // 補給無しで行ける経路間に重さ1の辺を張る
  }

  warshall_floyd(n, dd);  // 各町の間の最小補給回数を求める
*/
  vector<vector<int>> dd(n, vector<int>(n,INF));
  rep(i,n)rep(j,n) {
    if (d[i][j] <= l) dd[i][j] = 1;
  }
  rep(k,n)rep(i,n)rep(j,n) chmin(dd[i][j], dd[i][k]+dd[k][j]);
/*
  int q;
  cin >> q;
  rep(i, q) {
    int s, t;
    cin >> s >> t;
    s--; t--;
    if (dd[s][t] == INF) {
      cout << -1 << endl;
    } else {
      cout << dd[s][t] - 1 << endl;  // -1 はスタート時に補給無しで満タンだから
    }
  }
*/
  int q;
  cin >> q;
  rep(qi,q) {
    int s, t;
    cin >> s >> t;
    --s; --t;
    int ans = dd[s][t]-1;
    if (dd[s][t] == INF) ans = -1;
    cout << ans << endl;
  }
  return 0;
}


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

//1 0 0 0 2

int ab(int x){
	if(x<0) return -1*x;
	return x;
}

int main(){
	int n,a,b; cin>>n>>a>>b;
	if(ab(a-b)%2) cout<<"Borys"<<endl;
	else cout<<"Alice"<<endl;
	return 0;
}

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

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

int main(){
    int N;
    cin>>N;
    int A;
    int P[N]={};
    rep(i,N-1){
        cin>>A;
        P[A]++;
    }
    for(int i=1;i<N;i++){
        cout<<P[i]<<endl;
    }
    cout<<"0"<<endl;
    return 0;
}

Measured memory_bytes: 4420
#include <cstdio>
using ll = long long;
constexpr int MOD = 1e9 + 7, lim = 2e7;
int inv[20000005];
int main()
{
	// freopen("keyence2019-F.in", "r", stdin);
	inv[1] = 1;
	for (int i = 2; i <= lim; i++)
		inv[i] = MOD - (ll)(MOD / i) * inv[MOD % i] % MOD;
	int n, m, k;
	scanf("%d%d%d", &n, &m, &k);
	int a = k, b = (ll)k * (k + 1) / 2 % MOD * inv[n + m] % MOD;
	int c = (ll)k * (k - 1) % MOD * (k - 2) % MOD *
			inv[n + m] % MOD * inv[n + m - 1] % MOD * inv[n + m - 2] % MOD *
			inv[3] % MOD * (n + m - 2) % MOD;
	c = (c + (ll)k * (k - 1) % MOD * inv[n + m] % MOD * inv[n + m - 1]) % MOD;
	int ans = 1;
	for (int i = n + m - k + 1; i <= n + m; i++)
		ans = (ll)ans * i % MOD;
	printf("%lld\n", (a + (ll)b * (n + m) + (ll)c * n % MOD * m) % MOD * ans % MOD);
	return 0;
}


Measured memory_bytes: 78336
import math

a, b, h, m = map(int, input().split())

def cosine(a, b, theta):
  return math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(math.radians(theta)))


hour_theta = h * 30 + m * 0.5
min_theta = m * 6

if hour_theta - min_theta < 180:
  theta = hour_theta - min_theta
  print(cosine(a, b, theta))
elif hour_theta - min_theta > 180:
  theta = min_theta - hour_theta
  print(cosine(a, b, theta))
else:
  print(a+b)

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

int main(){
    int n;
    cin >> n;
    vector<int> ans(n,0);

    rep(i, 101) {
        rep(j, 101){
            rep(k, 101){
                int t = i*i + j*j + k*k + i*j + j*k + k*i;
                if(t <= n) ans[t-1] += 1;
            }
        }
    }

    for (int i = 0; i < (n); ++i) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 3564
def main():
    def count(x):
        ret = 0
        while x % 2 == 0:
            x //= 2
            ret += 1
        return ret

    N = int(input())
    a = map(int, input().split())
    ans = sum(map(count, a))
    print(ans)


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()


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

int main(){
  int n, k; cin >> n >> k;
  int mi = 1e9;
  int count = 0;
  int ma = 0;
  for (int i = 0; i < n; i++) {
    int c; cin >> c;
    if (ma < c - mi) {
      ma = c - mi;
      count = 1;
    } else if (ma == c - mi) count++;
    mi = min(c, mi);
  }
  cout << count << endl;
  return 0;
}


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

using namespace std;

int n;

int main()
{
    cin>>n;
    int a = 0,b = 0;
    for(int i=0;i<n;i++)
    {
        int x;scanf("%d",&x);
        if(x%4==0)
        {
            a++;
        }
        else if(x%2==0)
        {
            b++;
        }
    }
    a = a*2+1;
    if(a>=n)
    {
        printf("Yes\n");
    }
    else
    {
        a--;
        a+=b;
        if(a>=n)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }


    return 0;
}

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

int main()
{
	string a;
	int hold,cp;
	while(cin>>a)
	{
		cp=1000;
		for(int i=0;i<a.length()-2;i++)
		{
			hold=(a[i]-'0')*100+(a[i+1]-'0')*10+a[i+2]-'0';
			cp=min(cp,abs(753-hold));
		}
		cout<<cp<<endl;
	}
}

Measured memory_bytes: 256
local ior = io.read
local n, a, b = ior("*n", "*n", "*n")

local function getsum(x)
  local r = 0
  while(0 < x) do
    r = r + x % 10
    x = x // 10
  end
  return r
end

local ret = 0
for i = 1, n do
  local z = getsum(i)
  if(a <= z and z <= b) then ret = ret + i end
end
print(ret)


Measured memory_bytes: 508
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <iterator>
#pragma warning(disable:4996)

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

    printf("%ld\n", n/3);

    return 0;
}


Measured memory_bytes: 128
import sys
import numpy as np


def main():
    n, a, b, c, d = [int(x) for x in input().split()]
    nv = np.insert(np.array([1 if char == '#' else 0 for char in input()]), 0, 0)
    nv1 = nv[1:] + nv[:-1]
    nv2 = nv[2:] + nv[1:-1] + nv[:-2]
    if np.any(nv1[a:max(c, d)] == 2):
        print("No")
    elif c < d:
        print("Yes")
    elif np.any(nv2[b-1:d] == 0):
        print("Yes")
    else:
        print("No")


main()


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

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(int i=(b); i >= (e); --i)
#define SIZE(c) (int) (c).size()
#define FORE(i,c) FOR(i,0,SIZE(c)-1)
#define FORDE(i,c) FORD(i,SIZE(c)-1,0)

#define pb push_back
#define mp make_pair
#define st first
#define nd second


using namespace std;

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

typedef vector <int> VI;
typedef vector <bool> VB;
typedef vector <pii> VP;
typedef vector <ll> VL;
typedef vector <pll> VPL;

typedef vector <VI> VVI;
typedef vector <VL> VVL;
typedef vector <VB> VVB;
typedef vector <VP> VVP;

const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000000000000001LL;


/*************************************************************************/
ll ans=0;
int main()
{
    ios_base::sync_with_stdio(0);

    int n;
    cin >> n;

    VVI tab(n, VI(n));
    FOR(i,0,n-1) FOR(j,0,n-1)
    {
        cin >> tab[i][j];
        ans+=tab[i][j];
    }

    FOR(i,0,n-1) FOR(j,0,n-1) FOR(k,0,n-1)
    {
        if (tab[i][k] > tab[i][j] + tab[j][k])
        {
            cout << -1;
            return 0;
        }
    }

    ll total = 0;
    FOR(k,0,n-1) FOR(i,0,n-1)
    {
        bool found = false;

        FOR(j,0,n-1) if (j != i && j != k && tab[i][k] == tab[i][j] + tab[j][k])
        {
            found = true;
        }

        if (found)
        {
            total += tab[i][k];
        }
    }

    cout << ans/2-total / 2;

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int Max_N=15;
const long long Mod=(1e9)+7;
int n,m,a[Max_N+10][Max_N+10],P[1<<Max_N][Max_N+5];
long long f[1<<Max_N];
inline long long Mul(int x,int y){
	long long a=1,b=x;
	for(;y;y>>=1,b=b*b%Mod) if(y&1) a=a*b%Mod;
	return a;
}
int main(){
	scanf("%d%d",&n,&m);
	int all=(1<<n)-1;
	for(int i=1;i<=m;i++){
		int x,y; scanf("%d%d",&x,&y);
		a[x][y]=1;
	}
	for(int i=0;i<=all;i++)
	 for(int j=1;j<=n;j++)
	  if(!((1<<j-1)&i))
	   for(int k=1;k<=n;k++)
		if(((1<<k-1)&i)&&a[j][k])
		 ++P[i][j];
	for(int i=1;i<=all;i++){
		long long tot=1;
		for(int j=(i-1)&i;j;j=(j-1)&i){
		 	if((1&j)&&(2&(i^j))) continue;
		 	if((2&j)&&(1&(i^j))) continue;
			long long sum=1; int e=0;
		 	for(int k=1;k<=n;k++)
		 	 if((1<<k-1)&(i^j))
		 	  sum=sum*((Mul(2,P[j][k])-1+Mod)%Mod)%Mod;
		 	for(int k=1;k<=n;k++)
		 	 if((1<<k-1)&j)
		 	  e+=P[i^j][k]; 
		 	tot+=sum*f[i^j]%Mod*Mul(2,e)%Mod,tot%=Mod;
		 }
		f[i]=tot;
	}
	printf("%lld\n",(Mul(2,m)-f[(1<<n)-1]+Mod)%Mod);
	return 0;
}

Measured memory_bytes: 6604
// AOJ 2253 "ブレイブ・フォース・ストーリー" (ICPC模擬国内予選 2011 Problem B)
import java.util.Scanner;
import java.util.Queue;
import java.util.LinkedList;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        while (true) {
            int t = sc.nextInt();
            int n = sc.nextInt();
            if (t == 0) {
                break;
            }
            
            int[][] field = new int[121][121];
            for (int i = 0; i < n; i++) {
                int x = sc.nextInt();
                int y = sc.nextInt();
                field[y+60][x+60] = -1;
            }
            int sx = sc.nextInt() + 60;
            int sy = sc.nextInt() + 60;
            int[] dx = {0, 1, 1, 0, -1, -1};
            int[] dy = {1, 1, 0, -1, -1, 0};
            Queue<Field> que = new LinkedList<Field>();
            que.offer(new Field(sx, sy));
            while (que.peek() != null) {
                Field tmp = que.poll();
                int tmpx = tmp.x;
                int tmpy = tmp.y;
                if (field[tmpy][tmpx] == t) {
                    continue;
                }
                for (int i = 0; i < dx.length; i++) {
                    int nx = tmpx + dx[i];
                    int ny = tmpy + dy[i];
                    if (0 <= ny && ny < field.length && 0 <= nx && nx < field[ny].length
                        && field[ny][nx] == 0 && !(nx == sx && ny == sy)) {
                        que.offer(new Field(nx, ny));
                        field[ny][nx] = field[tmpy][tmpx] + 1;
                    }
                }
            }
            
            int count = 0;
            for (int i = 0; i < field.length; i++) {
                for (int j = 0; j < field[i].length; j++) {
                    if (field[i][j] > 0 && field[i][j] <= t) {
                        count++;
                    }
                }
            }
            System.out.println(count + 1);
        }
    }
    
    static void debug(int[][] field) {
        for (int i = 0; i < field.length; i++) {
            for (int j = 0; j < field[i].length; j++) {
                System.out.print(field[i][j] + " ");
            }
            System.out.println();
        }
    }
}

class Field {
    int x;
    int y;
    Field(int x, int y) {
        this.x = x;
        this.y = y;
    }
}

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

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

using namespace std;

typedef long long ll;
typedef pair<ll, int> P;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll X, Y, A, B, C; cin >> X >> Y >> A >> B >> C;
    vector<ll> red(A); rep(i, A) cin >> red[i];
    vector<ll> green(B); rep(i, B) cin >> green[i];
    vector<ll> nocolor(C); rep(i, C) cin >> nocolor[i];

    vector<pair<ll, int>> apples(A+B+C); //0 -> red, 1 -> green, 2 -> nocolor
    rep(i, A) apples[i] = P(red[i], 0);
    rep(i, B) apples[i+A] = P(green[i], 1);
    rep(i, C) apples[i+A+B] = P(nocolor[i], 2);
    sort(apples.rbegin(), apples.rend());

    ll sum[3] = {};
    ll cnt[3] = {};
    for(int i = 0; i < X+Y; i++){
        int color = apples[i].second;
        if(color == 0){
            if(cnt[0] < X){
                cnt[0]++;
                sum[0]+=apples[i].first;
            }
        }
        else if(color == 1){
            if(cnt[1] < Y){
                cnt[1]++;
                sum[1]+=apples[i].first;
            }
        }
        else{
            cnt[2]++;
            sum[2]+=apples[i].first;
        }
    }
    if(cnt[0] < X && cnt[1] < Y) cout << sum[0]+sum[1]+sum[2] << endl;
    else if(cnt[0] == X){
        //greenが少ない
        ll rem = Y - cnt[1] - cnt[2]; //rem個の緑or無色を取る
        ll ans = sum[0] + sum[1] + sum[2];
        for(int i = X+Y; i < A+B+C; i++){
            if(rem == 0) break;
            if(apples[i].second != 0){
                ans += apples[i].first;
                rem--;
            }
        }
        cout << ans << endl;
    }
    else{
        //redが少ない
        ll rem = X - cnt[0] - cnt[2];
        ll ans = sum[0] + sum[1] + sum[2];
        for(int i = X+Y; i < A+B+C; i++){
            if(rem == 0) break;
            if(apples[i].second != 1){
                ans += apples[i].first;
                rem--;
            }
        }
        cout << ans << endl;
    }
    //rep(i, A+B+C) cout << apples[i].first << " "; cout << endl;

    return 0;
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,M;
    cin >> N >> M;
    vector<int> V(M),dif(M-1),used(M-1);
    rep(i,0,M)cin >> V[i];
    if(N >= M){
        cout << 0 << endl;
        return 0;
    }
    sort(V.begin(), V.end());
    int sum = V[M-1] - V[0];
    rep(i,0,M-1)dif[i] = V[i+1] - V[i];
    sort(dif.rbegin(), dif.rend());
    rep(i,0,N-1)sum -= dif[i];
    cout << sum << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll =long long;
const ll INF =99999999999;

//最大公約数
ll gcd(ll a, ll b){
   if (a%b==0){
       return(b);
   }else{
       return(gcd(b,a%b));
   }
}
//最小公倍数
ll lcm(ll a, ll b){
   return a*b/gcd(a,b);
}

//素数判定
ll isprime(ll n){
  bool prime=true;
  for(int i=2;i<n;i++){
    if(n%i==0){
      prime=false; break;
    }
  }
if(prime){cout<<n<<" is prime"<<endl;
         }else{cout<<n<<" is not prime"<<endl;}

}
//階乗　20くらいが限界
ll factorial(ll n){
  ll a=1;ll b=n;
  for(int i=0;i<n;i++){
    a*=b;
    b--;
  }
  return a;
}

//組み合わせ　nCr
ll comb(ll a,ll b){
  ll c;
  c=factorial(a)/(factorial(a-b)*factorial(b));
  return c; 
}




//10億7。　　　100000007
//2*2行列 H*W
//vector<vector<int>> vec(H,vector<int>(W));
//for(int i=0;i<H;i++){
//for(int j=0;j<W;j++){
//cin>>vec[i][j];
//  }
//}

//文字列→数列
//string S;int A=atoi(S.c_str());
//数列→文字列
//int A;string S=to_string(A);
//数字判定　isdigit(a)
//pair宣言　pair<int,int> p(5,7);
//ソート　sort(vec.begin(),vec.end());



int main(){
cout<<fixed<<setprecision(10);

  int A,B;
  cin>>A>>B;
  if(A>8||B>8){
    cout<<":("<<endl;
  }else{
    cout<<"Yay!"<<endl;
  }

  
}


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

int main()
{
    char c[2][3];
    for(int i=0; i<2; i++){
        for(int j=0; j<3; j++){
            cin >> c[i][j];
        }
    }
    if(c[0][0] == c[1][2] && c[0][1] == c[1][1] && c[0][2] == c[1][0]){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

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

int main(){
  int n;
  while(cin>>n,n!=0){
    n = 1000-n;
    const vector<int> list = {500,100,50,10,5,1};
    int ans = 0;
    for(int i=0;i<list.size();i++){
      ans += n / list[i];
      n = n % list[i];
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1e18;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main(){
	int h, w, k; cin >> h >> w >> k;
	vector<vector<bool>> f(h,vector<bool>(w,0));
	char c;
	REP(i,h)REP(j,w){
		cin >> c;
		if(c=='#')
			f[i][j]=1;
	}
	int ans=0;
	REP(p,1<<(h+w)){
		int co=0;
		REP(i,h)REP(j,w){
			if(p>>i&1||p>>(h+j)&1)
				continue;
			if(f[i][j])
				co++;
		}
		if(co==k)
			ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
//#define int long long
using namespace std;

const int N = 1e6 + 7, offset = 2e5;

vector <int> up[2][N], down[2][N], U[N], D[N], L[N], R[N];


char typ[N];


int xx[N], yy[N];

int32_t main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, ptr = 0; cin >> n;
	for(int i = 1; i <= n; i++) {
		int x, y; char ch; cin >> x >> y >> ch;
		if(ch == 'U') {
			up[0][x + y + offset].push_back(x);
			up[1][x - y + offset].push_back(x);
		} else if(ch == 'D') {
			down[0][x + y + offset].push_back(x);
			down[1][x - y + offset].push_back(x);
		} else {
			++ptr;
			xx[ptr] = x;
			yy[ptr] = y;
			typ[ptr] = ch;
		}
		if(ch == 'U') {
			U[x].push_back(y);
		}
		if(ch == 'D') {
			D[x].push_back(y);
		}
		if(ch == 'L') {
			L[y].push_back(x);
		}
		if(ch == 'R') {
			R[y].push_back(x);
		}
	}
	for(int i = 0; i < N; i++) {
		sort(up[0][i].begin(), up[0][i].end());
		sort(up[1][i].begin(), up[1][i].end());
		sort(down[0][i].begin(), down[0][i].end());
		sort(down[1][i].begin(), down[1][i].end());
		sort(U[i].begin(), U[i].end());
		sort(D[i].begin(), D[i].end());
		sort(L[i].begin(), L[i].end());
		sort(R[i].begin(), R[i].end());
	}
	int ans = 1e9;

	for(int i = 0; i < N; i++) {
		for(int y: U[i]) {
			auto l = lower_bound(D[i].begin(), D[i].end(), y);
			if(l != D[i].end()) {
				ans = min(ans, (*l - y) * 5);
			}
		}
		for(int x: R[i]) {
			auto l = lower_bound(L[i].begin(), L[i].end(), x);
			if(l != L[i].end()) {
				ans = min(ans, (*l - x) * 5);
			}
		}
	}
	for(int i = 1; i <= ptr; i++) { 
		int x = xx[i], y = yy[i]; 
		if(typ[i] == 'L') {
			vector <int> &p = down[0][x + y + offset];
			int l = lower_bound(p.begin(), p.end(), x) - p.begin() - 1;
			if(l >= 0 && l < p.size()) {
				ans = min(ans, (x - p[l]) * 10);
			}
			vector <int> &q = up[1][x - y + offset];
			int r = lower_bound(q.begin(), q.end(), x) - q.begin() - 1;
			if(r >= 0 && r < q.size()) {
				ans = min(ans, (x - q[r]) * 10);
			}
		} else { 
			vector <int> &p = down[1][x - y + offset];
			int l = lower_bound(p.begin(), p.end(), x) - p.begin();
			if(l >= 0 && l < p.size()) {
				ans = min(ans, (p[l] - x) * 10);
			}
			vector <int> &q = up[0][x + y + offset];
			int r = lower_bound(q.begin(), q.end(), x) - q.begin();
			if(r >= 0 && r < q.size()) {
				ans = min(ans, (q[r] - x) * 10);
			}
		}
	}
	if(ans == 1e9) {
		cout << "SAFE" << endl;
	} else {
		cout << ans << endl;
	}
}

Measured memory_bytes: 209724
(N, K), As = readlines.map{|l| l.split.map(&:to_i)}
M = 10**9 + 7

as = [nil] + As.sort
fac, inv, fiv = [1, 1], [1, 1], [1, 1]
(2 .. N).each do |i|
  fac[i] = fac[i - 1]*i % M
  inv[i] = M - inv[M % i]*(M/i) % M
  fiv[i] = fiv[i - 1]*inv[i] % M
end
bnm = ->(n, k){fac[n] * fiv[n - k] * fiv[k] % M}
puts (1 .. N - K + 1).inject(0){|s, i| (s + bnm[N - i, K - 1]*(as[N - i + 1] - as[i])) % M}

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


int main(){
   int a,b,c; cin>>a>>b>>c;
   if(a==b&&b!=c) cout<<"Yes"<<endl;
   else if(a==c&&a!=b) cout<<"Yes"<<endl;
   else if(b==c&&a!=b) cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
   return 0;
}

   


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(c) begin(c), end(c)
using namespace std;
using ll = long long;
using ld = long double;

const int N = 1e6+6;


int main(){
    //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout);
    ios::sync_with_stdio(0);cin.tie(0);//cout.precision(12);cout<<fixed;
    
    int n,m;
    
    
    cin>>n>>m;
    vector<int> a(m);
    for(auto &_ : a) cin>>_;
    
    ll s = accumulate(ALL(a), 0LL);
    
    if(s > n) cout<<-1<<endl;
    else cout<<n-s<<endl;
    
    
    
    return 0;
}


Measured memory_bytes: 3660
// g++ -std=c++14

/*

Today might be the chance to grasp the chance to let your talent bloom.
May be tomorrow, the day after, or next year...
May be even when you are 30. I'm not sure if physique has anything to do with it
but if you think that it will never come, it probably never will.

- Tooru Oikawa.

*/


#include<bits/stdc++.h>

typedef long long ll;
typedef long double lld;
using namespace std;

#define endl "\n"
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define all(c) c.begin(),c.end()
#define inf 1000000000000000001
#define pii pair<int, int>
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)

template<typename S, typename T>
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.fi<<", "<<p.se<<')';return out;}

template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
ll l=v.size();for(ll i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}

template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

#define int ll
int g[405][405];
void solve() {
    for(int i = 0 ; i < 401 ; i++) {
        for(int j = 0 ; j < 401 ; j++) {
            g[i][j] = inf;
        }
        g[i][i] = 0;
    }
    int h,w;
    cin >> h >> w;
    char arr[h][w];
    map<pair<int,int>, int> ma;
    int ind = 0;
    for(int i = 0 ; i < h ; i++) {
        for(int j = 0 ; j < w ; j++) {
            cin >> arr[i][j];
            if(arr[i][j] == '.') {
                ma[{i,j}] = ind++;
                if(j-1 >= 0) {
                    if(arr[i][j-1] == '.') {
                        int u = ma[{i, j-1}];
                        int v = ma[{i,j}];
                        g[u][v] = 1;
                        g[v][u] = 1;
                    }
                }
                if(i-1 >= 0) {
                    if(arr[i-1][j] == '.') {
                        int u = ma[{i-1, j}];
                        int v = ma[{i,j}];
                        g[u][v] = 1;
                        g[v][u] = 1;
                    }
                }
            }
        }
    }
    for(int i = 0 ; i < ind ; i++) {
        for(int j = 0 ; j < ind ; j++) {
            for(int k = 0 ; k < ind ; k++) {
                g[j][k] = min(g[j][k], g[j][i] + g[i][k]);
            }
        }
    }
    int ans = -1;
    for(int i = 0 ; i < ind ; i++) {
        for(int j = 0 ; j < ind ; j++) {
            ans = max(ans, g[i][j]);
        }
    }
    cout << ans << endl;


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

Measured memory_bytes: 1536
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readNInts = readInt >>= flip replicateM readInt

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ n, k ] <- readInts
	s <- getLine
	let
		ps = map ( head &&& length ) $ group s
		k' = min k $ length $ filter ( ( == '0' ) . fst ) ps
		r = sum $ map snd $ take ( k' * 2 ) ps
	print $ maximum $ solve r ps $ drop ( k' * 2 ) ps

solve res _ [] = [ res ]
solve res ( p : ps ) ( q : qs )
	| fst p == '1' = res + snd q : solve res' ps qs
	| otherwise = res : solve res' ps qs
	where
		res' = res - snd p + snd q

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

int main(void){
    int N;
    int a[200000];
    int r[300000];
    vector<int> result;

    cin >> N;
    for(int i=0; i<N; ++i){
        cin >> a[i] ;
    }

    for(int i=N-1; i>=0; --i){
        int tmp=0;

        for(int j=2; j*(i+1)-1<N; ++j){
            tmp += r[j*(i+1)-1];
        }
        if(tmp%2 != a[i]){
            r[i] = 1;
            result.insert(result.begin(),i+1);
        }
    }

    if(result.size()==0){
        cout << 0 << endl;
        return 0;
    }
    
    cout << result.size() << endl;
    for(auto i=result.begin(); i!=result.end(); ++i){
        cout << *i;
        if(i+1!=result.end())
            cout << " ";
        else
            cout << endl;
    }
    return 0;
}


Measured memory_bytes: 2936
#include <stdio.h>
int main(void){
    int a,b;
    scanf("%d %d",&a,&b);
    if(a==b)
        printf("%d",2*a);
    if(a>b)
        printf("%d",2*a-1);
    if(b>a)
        printf("%d",2*b-1);

    return 0;
}


Measured memory_bytes: 128
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  vector<vector<int>> a(3, vector<int>(3));//int型の2次元配列(3×4要素の)の宣言
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin >> a.at(i).at(j);
    }
  }
  if(abs(a.at(0).at(0) - a.at(0).at(1)) == abs(a.at(1).at(0) - a.at(1).at(1)) &&
     abs(a.at(0).at(0) - a.at(0).at(1)) == abs(a.at(2).at(0) - a.at(2).at(1)) &&
     abs(a.at(0).at(1) - a.at(0).at(2)) == abs(a.at(1).at(1) - a.at(1).at(2)) &&
     abs(a.at(0).at(1) - a.at(0).at(2)) == abs(a.at(2).at(1) - a.at(2).at(2)) )cout << "Yes"<<endl;
  else cout << "No"<<endl;
 
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
   int tate,yoko,shuu,menseki;
   scanf("%d %d", &tate, &yoko);
   menseki = tate * yoko;
   shuu = tate * 2 + yoko * 2;
   printf("%d %d\n", menseki, shuu);

   return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    int N, M;
    read(N, M);

    vector<int> cnt(M);
    rep(i, N) {
        int K; read(K);
        rep(j, K) {
            int a; read(a); --a;
            cnt[a] += 1;
        }
    }

    print(count(all(cnt), N));

    return 0;
}


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

int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    if(n>=400&&n<=599)
        cout<<"8"<<endl;
    if(n>=600&&n<=799)
        cout<<"7"<<endl;
    if(n>=800&&n<=999)
        cout<<"6"<<endl;
    if(n>=1000&&n<=1199)
        cout<<"5"<<endl;
    if(n>=1200&&n<=1399)
        cout<<"4"<<endl;
    if(n>=1400&&n<=1599)
        cout<<"3"<<endl;
    if(n>=1600&&n<=1799)
        cout<<"2"<<endl;
    if(n>=1800&&n<=1999)
        cout<<"1"<<endl;
    return 0;
}       

Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
using namespace std;
int main() {
  int a,b,c;
  cin >> a >> b >> c;
  int ans1 = b-a;
  int ans2 = c-b;
  if (ans1 == ans2) cout << "YES" << endl;
  else cout << "NO" << endl;
} 
  

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

int main() {
  int n;
  cin >> n;
  ll ans = 0;
  for(int i=1; i<=n; ++i) {
    ans = 0;
    for(int x=1; x*x<=n; ++x) {
      for(int y=1; y<=x; ++y) {
        int a = i - (x*x + y*y + x*y);
        int b = x+y;
        if ( a <= 0 ) continue;
//        cout << x << " " << y << " : " << a << " " << b << endl;
        for(int z=1; z<=y; ++z) {
          if ( a == z*z + b*z ) {
            if ( x == y && y == z ) ans++;
            else if ( x == y || y == z || x == z ) ans += 3;
            else ans += 6;
          }
        }
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			if (1 == n) {
				System.out.println("Hello World");
			} else {
				int a = scanner.nextInt(), b = scanner.nextInt();
				System.out.println(a + b);
			}
		}
	}
}


Measured memory_bytes: 35580
#include<iostream>
using namespace std;
int main()
{
    long long a,b,c,d;
    cin>>a>>b>>c;
    if(a>1 && c>=b || a==1 && c==b)
        cout<<(a-2)*(c-b)+1;
    else
        cout<<0;
    return 0;
}

Measured memory_bytes: 256
S = int(input())

ue2keta = S // 100
shita2keta = S % 100

if (0 < ue2keta < 13) & ((shita2keta == 0) | (shita2keta > 12)):
    print("MMYY")
elif (0 < shita2keta < 13) & ((ue2keta == 0) | (ue2keta > 12)):
    print("YYMM")
elif (0 < ue2keta < 13) & (0 < shita2keta < 13):
    print("AMBIGUOUS")
else:
    print("NA")



Measured memory_bytes: 3060
gets.to_i.times do
  out = 0
  point = 0
  runner = 0

  loop do
    case gets.chomp
    when 'HIT'
      runner += 1

      if runner > 3
        runner -= 1
        point += 1
      end
    when 'OUT'
      out += 1
    when 'HOMERUN'
      point += 1 + runner
      runner = 0
    end

    break if out == 3
  end

  puts point
end

Measured memory_bytes: 8648
#include <bits/stdc++.h>
using namespace std; 
const int maxn = 1e5 + 100;
int  s[500];
int t[50];
bool cmp(int a,int b) {
return a<b;
}
int main(){
int n,sum=0;
cin>>n;
for(int i=0;i<n;i++){
cin>>s[i];
sum+=s[i];
}
sort(s,s+n,cmp);
if(sum%10!=0){
cout<<sum<<endl;
return 0;
}
for(int i=0;i<n;i++){
if((sum-s[i])%10!=0){
cout<<sum-s[i]<<endl;
return 0;
}
}
cout<<0<<endl;
system ("pause"); 
return 0;
}

Measured memory_bytes: 504
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
C = 0
for s in S:
    for i in range(q):
        if s == T[i]:
            C += 1
            del T[i]
            q += -1
            break
print(C)


Measured memory_bytes: 6316
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
using ll = long long;
int MOD = 1e9 + 7;
using namespace std;
struct UnionFind
{
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N)
    { //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++)
            par[i] = i;
    }

    int root(int x)
    { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y)
    {                     // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry)
            return;   //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y)
    { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
int main()
{
    int n;
    cin >> n;
    vector<int> vec(n);
    ll sum = 0;
    for (int i = 0; i < n;i++){
        cin >> vec[i];
        sum += vec[i];
    }
    int dist = 1e9;
    int res;
    for (int i = 0; i < n;i++){
        if(abs(n*vec[i]-sum)<dist){
            res = i;
            dist = abs(n * vec[i] - sum);
        }
    }
    cout << res << endl;
}


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

int main() {
  int A,B,x;
  char op;
  
  cin >> A >> op >> B;
  
  if ( op == '+') {
    x = A + B;
  } else {
    x = A - B;
  }
  
  cout << x << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,a,i,ans=500,tmp;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a);
    tmp=0;
    while(a%2==0){
      a/=2;
      tmp++;
    }
    if(tmp<ans)ans=tmp;
  }
  printf("%d\n",ans);
  return 0;
}

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

#define ll long long int
#define pi pair<int,int> 
#define mp make_pair

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);	cout.tie(0);
	int n,k;
	cin >> n;
	vector<pi> v(n);
	for(int i=0;i<n;i++){
		cin >> v[i].first;
		v[i].second = i+1;	
	}

	sort(v.begin(), v.end());
	for(int i=0;i<n;i++)
		cout << v[i].second << ' ';
	cout << '\n';

	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#define ll long long
#define f(i, n) for (int i=1; i <= n; i++)
// sort(bb, bb+n);

using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);
    string s;
    bool isP = true;
    int n;
    cin >>s;

    n = s.size();

    f(i,n){
        int a = ((n-1)/2)-i;
        int b = ((n+3)/2)+(i-2);

        if(s[i-1] != s[n-i]){
            isP = false;
        }
        if(i <= a){
            if(s[i-1] != s[a]){
                isP=false;
            }
        }
        if(b <= n-i){
            if(s[b] != s[n-i]){
                isP=false;
            }
        }

    }

    if(isP) cout <<"Yes";
    else cout <<"No";

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

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

using namespace std;

int main() {
  while(1) {
    int n;
    cin>>n;
    if(!n)break;
    int w,h;
    cin>>w>>h;
    vector<vector<int>> tb(h,vector<int>(w,0));
    REP(i,n){
      int x,y;
      cin>>x>>y;
      --y;--x;
      tb[y][x] = 1;
    }
    vector<vector<int>> sum(h,vector<int>(w+1,0));
    REP(i,h){
      partial_sum(begin(tb[i]),end(tb[i]),begin(sum[i])+1);
    }
    int s,t;
    cin>>s>>t;
    int mx = 0;
    REP(i,h){
      REP(j,w){
        if(i+t > h || j+s > w) break;
        int rng = 0;
        REP(k,t){
          rng += sum[i+k][j+s] - sum[i+k][j];
        }
        mx=max(mx,rng);
      }
    }
    cout << mx << endl;
  }
  return 0;
}

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

std::vector<bool> IsPrime;

void sieve(size_t max) {
  if (max + 1 > IsPrime.size()) {
    IsPrime.resize(max + 1, true);
  }
  IsPrime[0] = false;
  IsPrime[1] = false;

  for (size_t i = 2; i * i <= max; ++i) {
    if (IsPrime[i]) {
      for (size_t j = 2; i * j <= max; ++j) {
        IsPrime[i * j] = false;
      }
    }
  }
}

int main() {
  sieve(100005);

  ll Q;
  scanf("%lld", &Q);

  vll a = vll(100005);

  for (ll i = 1; i <= 100000; i++) {
    if (IsPrime[i] && IsPrime[(i + 1) / 2]) {
      a[i] = 1;
    } else {
      a[i] = 0;
    }
  }

  vector<ll> csum(100005);
  for (ll i = 1; i < a.size() + 1; i++) {
    csum[i] = csum[i - 1] + a[i - 1];
  }

  // // [2] + [3] + [4]
  // cout << (csum[4 + 1] - csum[2]) << endl;
  // // [1] + [2] + [3]
  // cout << (csum[3 + 1] - csum[1]) << endl;

  for (ll i = 0; i < Q; i++) {
    ll l, r;
    scanf("%lld %lld", &l, &r);

    // // [2] + [3] + [4]
    cout << (csum[r + 1] - csum[l]) << endl;
  }
}


Measured memory_bytes: 4864
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

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



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;



int main() {
	int n, x;
	cin >> n >> x;
	vector<int> l(n);
	for (int i = 0; i < n; i++) {
		cin >> l[i];
	}

	int d = 0;
	int cnt = 1;
	for (int i = 0; i < n; i++) {
		d += l[i];
		if (d <= x) {
			cnt++;
		}
		else {
			cout << cnt << endl;
			return 0;
		}
	}

	cout << cnt << endl;
}


Measured memory_bytes: 3560
#include <cstdio>
int a[100];
int main()
{
    int n, pos = 0;
    scanf("%d", &n);
    while (n--)
    {
        int flag = 1;
        for (int i = 0; i < pos; i++)
        {
            if (a[i] <= a[i + 1] && a[i] < 9)
            {
                a[i]++;
                for (int j = i - 1; j > -1; j--)
                {
                    a[j] = a[j + 1] - 1;
                    if (a[j] < 0)
                        a[j] = 0;
                }
                flag = 0;
                break;
            }
        }
        if (flag)
        {
            if (a[pos] < 9)
            {
                a[pos]++;
                for (int i = pos - 1; i > -1; i--)
                {
                    a[i] = a[i + 1] - 1;
                    if (a[i] < 0)
                        a[i] = 0;
                }
            }
            else
            {
                a[++pos] = 1;
                for (int i = 0; i < pos; i++)
                    a[i] = 0;
            }
        }
        // for (int i = pos; i > -1; i--)
        //     printf("%d", a[i]);
        // printf("\n");
    }
    for (int i = pos; i > -1; i--)
        printf("%d", a[i]);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)

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;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////

int main() {
    int n; cin >> n;
    vector<vector<ll>> a(10, vector<ll>(10));
    repf(i,1,n+1) {
        int d = i;
        int b = d%10;
        while (d >= 10) {
            d /= 10;
        }
        int c = d;
        a[b][c]++;
    }
    ll ans = 0;
    repf(i,1,10) repf(j,1,10) {
        ans += a[i][j]*a[j][i];
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main(){
    int n, ans = 0;
    cin >> n;
    vector<int> a(n + 1);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int t = a[0], cnt = 1;
    for(int i = 1; i <= n; i++){
        if(a[i] == t){
            cnt++;
        }else{
            ans += cnt / 2;
            cnt = 1;
            t = a[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
using System;

namespace SelectionSort
{
	class MainClass
	{
		public static void trace(ref int[] arr) {
			for (int i = 0; i < arr.Length; ++i) {
				if (i > 0)
					Console.Write (" ");
				Console.Write (arr [i]);
			}
			Console.WriteLine ();
		}

		public static void Main (string[] args)
		{
			int n = int.Parse (Console.ReadLine ());
			string[] nums = (Console.ReadLine ()).Split (' ');
			int[] arr = new int[n];
			for (int i = 0; i < n; ++i)
				arr [i] = int.Parse (nums [i]);

			selectionSort (ref arr);

		}

		public static void selectionSort(ref int[] arr) {

			int numSwap = 0;
			for (int i = 0; i < arr.Length; ++i) {
				int minj = i;
				for (int j = i; j < arr.Length; ++j) {
					if (arr [j] < arr [minj])
						minj = j;
				}

				if (i != minj) {
					int tmp = arr [i];
					arr [i] = arr [minj];
					arr [minj] = tmp;
					++numSwap;
				}
			}

			trace (ref arr);
			Console.WriteLine (numSwap);

		}
	}
}

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

int main()
{
  int n, l;
  cin >> n >> l;
  vector<string> s(n);
  for (int i=0; i<n; i++)
    cin >> s.at(i);
  
  sort(s.begin(), s.end());
  
  for (int i=0; i<n; i++)
    cout << s.at(i);
  cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define ll long long
#define int long long
ll k,len,tmp,ans=0;
char s[105];
using namespace std;
bool check(int sta) {//sta=0代表无限制，sta=1代表第一个被修改.
    tmp=0;
    for(int i=1;i<=len;i++) {
        if(sta){tmp++;sta=0;continue;}
        if(i==len) {
            if(s[1]==s[len])return 1;
        }
        if(s[i]==s[i+1]) {
            tmp++;i++;
        }
    }
    return 0;
}//返回值为1代表修改第一个，否则代表不修改第一个,次数存入tmp（不包括修改第一个）。
signed main() {
    scanf("%s%lld",s+1,&k);len=strlen(s+1);
    if(!check(0)) {
        printf("%lld",tmp*k);
        return 0;
    }
    ans=tmp;
    if(check(1)) {
        k--;ans+=k*tmp;
        printf("%lld",ans);
        return 0;
    }
    ans+=tmp;
    ans*=k/2;
    check(0);
    if(k&1)ans+=tmp;
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 256
import math
import collections
#2,4,5,7,9 hon
#0,1,6,8 pon
#3, bon
N = int(input())
a = N%10
B = [0,1,6,8]
if a == 3:
  print('bon')
elif a in B:
  print('pon')
else:
  print('hon')

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

int gcd(int a, int b) { return b?gcd(b,a%b):a;}

int main() {
  int K;
  cin >> K;
  int sum=0;
  for(int i=1;i<=K;i++){
    for(int j=1;j<=K;j++){
      for(int k=1;k<=K;k++){
        sum += gcd(i,gcd(j,k));
      }
    }
  }
  cout << sum << endl;
  return 0;
}

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

#if DEBUG
template <typename Iter>
void debug_iter(Iter begin, Iter end);
template <typename T>
void debug(const T& value) {
  std::cerr << value;
}
template <typename T, size_t N>
void debug(const std::array<T, N>& a) {
  debug_iter(a.begin(), a.end());
}
template <typename T>
void debug(const std::vector<T>& v) {
  debug_iter(v.begin(), v.end());
}
template <typename T>
void debug(const std::set<T>& s) {
  debug_iter(s.begin(), s.end());
}
template <typename T, typename U>
void debug(const std::map<T, U>& m) {
  debug_iter(m.begin(), m.end());
}
template <typename T, typename U>
void debug(const std::pair<T, U>& p) {
  std::cerr << "{";
  debug(p.first);
  std::cerr << ", ";
  debug(p.second);
  std::cerr << "}";
}
template <typename T, typename... Ts>
void debug(const T& value, const Ts&... args) {
  debug(value);
  std::cerr << ", ";
  debug(args...);
}
template <typename Iter>
void debug_iter(Iter begin, Iter end) {
  std::cerr << "{";
  for (Iter it = begin; it != end; ++it) {
    if (it != begin) std::cerr << ", ";
    debug(*it);
  }
  std::cerr << "}";
}
#define dbg(...)                        \
  do {                                  \
    cerr << #__VA_ARGS__ << ": ";       \
    debug(__VA_ARGS__);                 \
    cerr << " (L" << __LINE__ << ")\n"; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define rd(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << '\n';
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define wt(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& v) {
  for (T& vi : v) is >> vi;
  return is;
}

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

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

#include <boost/hana/functional/fix.hpp>
auto Fix = [](auto&& f) { return boost::hana::fix(f); };

using ll = long long;

template <typename T>
using low_priority_queue =
    std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <typename T>
using V = std::vector<T>;
template <typename T>
using VV = V<V<T>>;

using namespace std;

int main() {
  rd(int, n);
  V<int> l(n);
  cin >> l;
  sort(all(l));
  int ans = 0;
  rep(i, n) rep(j, i) rep(k, j) {
    int I = l[i], J = l[j], K = l[k];
    if (I != J && J != K && K != I && I < (J + K)) ++ans;
  }
  wt(ans);
}


Measured memory_bytes: 3636
#include <stdio.h>

int main() {
    int i=0,x;
    
    while(i<=10000){
        i++;
        scanf("%d",&x);
        if(x==0){
            break;
        }else{
            printf("Case %d: %d\n",i,x);
        }
        
        
    }
    return 0;
}



Measured memory_bytes: 2024