akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#define MAX 100005
#define NIL -1

struct Node {
  int parent,left,right;
};

struct Node T[MAX];
int n,D[MAX],H[MAX];

void setDepth(int a,int b){
  if(a==NIL)return;
  D[a]=b;
  setDepth(T[a].left,b+1);
  setDepth(T[a].right,b+1);
}

int setHeight(int n){
  int h1=0,h2=0;
  if(T[n].left!=NIL) h1=setHeight(T[n].left)+1;
  if(T[n].right!=NIL) h2=setHeight(T[n].right)+1;
  return H[n]=(h1>h2?h1:h2);
}

int getSibling(int n){
  if(T[n].parent==NIL)return NIL;
  if(T[T[n].parent].left!=n&&T[T[n].parent].left!=NIL)return T[T[n].parent].left;
  if(T[T[n].parent].right!=n&&T[T[n].parent].right!=NIL)return T[T[n].parent].right;
 return NIL;
}


void print(int u){
  int i,c;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].parent);
  printf("sibling = %d, ",getSibling(u));

  int deg=0;
  if(T[u].left!=NIL)deg++;
  if(T[u].right!=NIL)deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);

  if(T[u].parent==NIL)printf("root\n");
  else if(T[u].left==NIL&&T[u].right==NIL) printf("leaf\n");
  else  printf("internal node\n");
}

int main(){

  int v,l,r,root=0,i;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].parent=NIL;
  }

  for(i=0;i<n;i++){
     scanf("%d",&v);
     scanf("%d",&l);
     scanf("%d",&r);
     T[v].left=l;
     T[v].right=r;
     if(l!=NIL)T[l].parent=v;
     if(r!=NIL)T[r].parent=v;
  }

  for(i=0;i<n;i++){
    if(T[i].parent==NIL)root=i;
  }
  setDepth(root,0);
  setHeight(root);
  for(i=0;i<n;i++)print(i);
  return 0;
}


Measured memory_bytes: 2104
y1, m1, d1 = gets.chomp.split.map(&:to_i)
y2, m2, d2 = gets.chomp.split.map(&:to_i)
arr = [[y1, m1, d1], [y2, m2, d2]].sort_by{|y, m, d| [y, m, d]}
y3, m3, d3 = arr[0]
y4, m4, d4 = arr[1]
arr_md = [[m3, d3, 0], [m4, d4, 1]].sort_by{|m, d, i| [m, d]}
diff = y4 - y3
diff += 1 if [m3, d3] != [m4, d4] && arr_md[0][2] == 0
puts diff



Measured memory_bytes: 6876
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

int n;
int table[15]={0};
vector<pair<int,int> >p[15];

int solve(int x){
  int ans=0;
  int cnt=0;
  if(x==n){
    rep(i,n){
      if(table[i]==1){
	rep(j,p[i].size() ){
	  if(table[p[i][j].fst]!=p[i][j].scd) return 0;
	}
	cnt++;
      }
    }
    return cnt;
  }
  table[x]=1;
  ans=max(ans,solve(x+1));
  table[x]=0;
  ans=max(ans,solve(x+1));
  return ans;
}

signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  cin>>n;
  rep(i,n){
    int x;
    cin>>x;
    int a,b;
    rep(j,x){
      cin>>a>>b;
      a--;
      p[i].push_back(make_pair(a,b));
    }
  }
  cout<<solve(0)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b;
    c=b;
    while(c!=0)
    {
        c=c/10;
        a=a*10;
    }
    a=a+b;
    int d=sqrt(a);
    double n=sqrt(a);
    if(d==n) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}



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

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

cnt = 0
for i in range(n):
    diff = B[i] - A[i]
    if diff > 0:
        cnt += A[i]
        if diff >= A[i+1]:
            cnt += A[i+1]
            A[i+1] = 0
        else:
            cnt += diff
            A[i+1] -= diff
    else:
        cnt += B[i]

print(cnt)



Measured memory_bytes: 18624
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    N = NI()
    trains = [NLI() for _ in range(N-1)]
    if N == 1:
        print(0)
        exit()

    for start in range(N-1):
        t = 0
        for now in range(start, N-1):
            C, S, F = trains[now]
            if t < S:
                t = S + C
            else:
                k = math.ceil((t-S)/F)
                t = S + k * F + C
        print(t)

    print(0)


if __name__ == "__main__":
    main()

Measured memory_bytes: 9576
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

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

    if (N >= 10) 
        cout << R << endl;
    else {
        int tmp = 100 * (10 - N);
        cout << R + tmp << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int  main(void){
         int h,w,i,j;
          while(1){
          scanf("%d %d",&h,&w);
           if( h==0 && w==0)
              break;
           for(i=1; i<=h; i++){
            for(j=1; j<=w; j++){
              if(i==1 || i==h || j==1 || j==w)
              printf("#");
             else
              printf(".");
             }printf("\n");
            }printf("\n");
           }
            return 0;
}



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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> P;

const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

template<typename T> struct BIT {
	vector<T> bit;
	int n;
	
	BIT() {}
	BIT(int n) : bit(vector<T>(n + 2, 0)), n(n) {}
	
	T sum(int i) {
		i++;
		T s = 0;
		while (i > 0) {
			s += bit[i];
			i -= i & -i;
		}
		return s;
	}
	
	void add(int i, T x) {
		i++;
		while (i <= n) {
			bit[i] += x;
			i += i & -i;
		}
	}
	
	T pquery(int i) {
		return sum(i) - sum(i - 1);
	}
	
	int lower_bound(T x) {
		int l = -1, r = bit.size();
		while (r - l > 1) {
			int m = (l + r) / 2;
			
			if (sum(m) >= x) r = m;
			else l = m;
		}
		if (r == bit.size()) r = -1;
		
		return r;
	}
};

ll N, K;
ll a[212345], ord[212345];
pll sum[212345];

int main() {
	cin >> N >> K;
	REP(i, N) scanf("%lld", a + i);
	
	REP(i, N) a[i] -= K;
	
	sum[0] = pll(a[0], 0);
	FOR(i, 1, N) sum[i] = pll(sum[i - 1].fi + a[i], i);
	
	sort(sum, sum + N);
	
	REP(i, N) ord[sum[i].se] = i;
	
	BIT<int> bit(212345);
	
	ll ans = 0, mi = 0;
	REP(i, N) {
		int idx = lower_bound(sum, sum + N, pll(mi, 0)) - sum;
		int cnt = N - idx;
		
		ans += cnt - (bit.sum(212345) - bit.sum(idx - 1));
		
		mi += a[i];
		
		bit.add(ord[i], 1);
	}
	
	
	
	cout << ans << endl;
	
	return 0;
}

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

int main(){
    int A, B, X;
    cin >> A >> B >> X;
    if(A > X){
        cout << "NO" << endl;
    }else if(A + B > X){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from sys import stdin
# import numpy as np
# import sys
# sys.setrecursionlimit(10**4)

def _li(): return list(map(int, stdin.readline().split()))
def _li_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def _lf(): return list(map(float, stdin.readline().split()))
def _ls(): return stdin.readline().split()
def _i(): return int(stdin.readline())
def _f(): return float(stdin.readline())
def _s(): return stdin.readline()[:-1]


N, M = _li()
if N == M:
    print("Yes")
else:
    print("No")


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


void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

int a[200010];
 int ans[200010];



int main()
{
    init();

 int n;
 scanf("%d",&n);
 for(int i=2;i<=n;i++)scanf("%d",&a[i]);
for(int i=2;i<=n;i++)ans[a[i]]++;
for(int i=1;i<=n;i++)printf("%d\n",ans[i]);
}




Measured memory_bytes: 5340
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input, "index" : 0, "max" : input.length,
  "hasNext" : function(){return (this.index < this.max);},
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  }
}
Main();
function next(){return obj.next();}
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var one = nextIntArray();
  var x = one[0];
  var y = one[1];
  var output = 0;
  if(x == 3){
     output += 100000;
  }else if(x == 2){
           output += 200000;
           }else if(x == 1){
                    output += 300000;
                    }
  if(y == 3){
     output += 100000;
  }else if(y == 2){
           output += 200000;
           }else if(y == 1){
                    output += 300000;
                    }
  
  if(x == 1 && y == 1){
     output += 400000;
     }
  myout(output);
}

Measured memory_bytes: 22964
N = int(input())
S = input()
ne_r = S.count('E')
nw_l = 0
ans = N
for i,c in enumerate(S):
    if c=='E': ne_r-=1
    ans = min(ans, ne_r + nw_l)
    if c=='W': nw_l+=1
print(ans)

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

string s;
string t;
int main()
{
    cin >> t;
    cin >> s;
    int cnt = 0;
    for (int i = 0; i < t.size(); i++)
    {
        if (s[i] == t[i])
        {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

int main(){
	string chg[] = {".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
	int n;
	cin >> n;
	for(int i = 0;i < n;i++){
		string s;
		cin >> s;
		int now = -1,num = -1;
		for(int j = 0;j < s.length();j++){
			if(s[j] == '0'){
				if(now == -1 && num == -1) continue;
				cout << chg[now][num % chg[now].length()];
				num = -1;
				now = -1;
			}else{
				now = s[j] - '1';
				num++;
			}
		}
		cout << endl;
	}
	return 0;
}

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

using namespace std;

char p[3][3][4];
char pz[9][5];

bool check(char a,char b){
    return (a-32 == b || b-32 == a);
}

int rec(int now,int S){
    if(now == 9) return 1;
    int res = 0;
    int X = now%3, Y = now/3;
    for(int s = 0 ; s < 9 ; s++){
        if(S >> s & 1) continue;
        for(int i = 0 ; i < 4 ; i++){
            for(int j = 0 ; j < 4 ; j++){
                p[Y][X][j] = pz[s][(i+j)%4];
            }
            bool can = true;    
            if(X > 0 && !check(p[Y][X][0],p[Y][X-1][2])){
                can = false;
            }
            if(Y > 0 && !check(p[Y][X][1],p[Y-1][X][3])){
                can = false;            
            }
            if(can) res += rec(now+1,S|(1<<s));
        }
    }
    return res;
}

int main(){
    int Tc;
    cin >> Tc;
    while(Tc--){
        for(int i = 0 ; i < 9 ; i++){
            for(int j = 0 ; j < 4 ; j++){
                cin >> pz[i][j];
            }
        }
        cout << rec(0,0) << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while (sc.hasNext()) {
            int[][] map = new int[28][28];

            for (int i = 0; i < 28; i++) {
                for (int j = 0; j < 28; j++) {
                    map[i][j] = -1;
                }
            }

            for (int i = 10; i < 18; i++) {
                String S = sc.next();

                int index = 0;
                for (int j = 10; j < 18; j++) {
                    map[i][j] = Integer.parseInt(S.split("")[index]);
                    index++;
                }
            }

            System.out.println(check(map));
        }
    }

    private static String check(int[][] map) {
        for (int i = 10; i < 18; i++) {
            for (int j = 10; j < 18; j++) {
                if (map[i][j] == 1) {
                    if (map[i][j+1] == 1 && map[i+1][j] == 1 && map[i+1][j+1] == 1) {
                        return "A";
                    }

                    if (map[i+1][j] == 1 && map[i+2][j] == 1 && map[i+3][j] == 1) {
                        return "B";
                    }

                    if (map[i][j+1] == 1 && map[i][j+2] == 1 && map[i][j+3] == 1) {
                        return "C";
                    }

                    if (map[i+1][j] == 1 && map[i+1][j-1] == 1 && map[i+2][j-1] == 1) {
                        return "D";
                    }

                    if (map[i][j+1] == 1 && map[i+1][j+1] == 1 && map[i+1][j+2] == 1) {
                        return "E";
                    }

                    if (map[i+1][j] == 1 && map[i+1][j+1] == 1 && map[i+2][j+1] == 1) {
                        return "F";
                    }

                    if (map[i][j+1] == 1 && map[i+1][j] == 1 && map[i+1][j-1] == 1) {
                        return "G";
                    }
                }
            }
        }
        return "Z";
    }
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,x; cin>>a>>b>>x;
    if (a==0){
        cout<<b/x+1<<endl;
        return 0;
    }
    cout<<b/x-(a-1)/x<<endl;
    return 0;
}


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

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

using namespace std;

int main() {
    string S;
    cin >> S;
    cout << S.replace(0, 4, "2018") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a,b,c;
long long d;
int main(){
	scanf("%d%d%d%lld",&a,&b,&c,&d);
	if (d&1){
		printf("%d\n",b-a);
	}
	else printf("%d\n",a-b);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int x,k;
cin>>x>>k;
int a[111111];
for(int i=0;i<x;i++)cin>>a[i];
sort(a,a+x);
long long s=0;
for(int i=0;i<k;i++)s+=a[i];
cout<<s;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
using ll=long long;
using P=pair<int,int>;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010;
ll a[1010];
vector<ll> v;
int main(){
    int n,k;cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        ll sum=0;
        for(int j=i;j<n;j++){
            sum+=a[j];
            v.push_back(sum);
        }
    }
    ll ans=0;
    for(int i=40;i>=0;i--){
        int co=0;
        for(int j=0;j<v.size();j++){
            if(v[j]&(1LL<<i)){
                co++;
            }
        }
        if(co<k)continue;
        ans|=(1LL<<i);
        vector<ll> vv;
        for(int j=0;j<v.size();j++){
            if(v[j]&(1LL<<i)){
                vv.push_back(v[j]);
            }
        }
        v.clear();
        for(int j=0;j<vv.size();j++)v.push_back(vv[j]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 6384
N = int(input())
L = list(map(int,input().split()))
ave = int(sum(L)/len(L))
ave2 = ave + 1
Answer = 0
Answer2 = 0
for i in range(N):
  Answer += (ave-L[i])**2
  Answer2 += (ave2-L[i])**2
if Answer <= Answer2:
  print(Answer)
else:
  print(Answer2)

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


using namespace std;

int main() {
//    freopen("test.txt", "r", stdin);
    int n, tmp;
    scanf("%d", &n);
    vector<int> ret(n, 0);
    int index = n/2;
    for (int i = 0; i < n; i++) {
        scanf("%d", &tmp);
        ret[index] = tmp;
        if (index > (n-1)/2) {
            index = n-1 - index;
        }
        else {
            index = n - 1 - ((n-i-1)/2-1);
        }
    }
    for (int num : ret) printf("%d ", num);
    cout << endl;
    return 0;
}

Measured memory_bytes: 2944
#include<iostream>
#include<algorithm>
#include<vector>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
int main(){
    int64_t x,k,d;
    cin >> x >> k >> d;
    x = abs(x);

    int64_t down=min(k,x/d);
    k -= down;
    x -= down*d;

    if(k%2==0){
        cout << x << endl;
    }else{
        cout << d-x << endl;
    }
}

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

int main(){
  
  string a;
  cin >> a;
  
  if( a == "AAA" || a == "BBB" ){
    
    cout << "No" << endl;
    
  }
  
  else{
    
    cout << "Yes" << endl;
    
  }
  
}


Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    int x, a; scan(x, a);
    if (x < a) writeln(0);
    else writeln(10);
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//
//    #pragma GCC optimize("unroll-loops")
//    #pragma GCC optimize("Ofast")
//    #pragma GCC optimize("-O3")
//    #pragma GCC optimize("no-stack-protector")
//    #pragma GCC optimize("fast-math")
//#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fi first
#define f first
#define se second
#define s second
#define vi_a vector<int>a;
#define p_b push_back
////////////////////////////////???????????????CHECK THIS OUT???????????????//////////////////////////////
#define ll long long
////////////////////////////////???????????????CHECK THIS OUT???????????????//////////////////////////////
#define ld long double
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define fast_io cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
#define all(x) x.begin(),x.end()
#define getfiles    ifstream cin("input.txt");ofstream cout("output.txt");
#define pw(x) (1ll << x)
#define sz(x) (ll)x.size()
#define endl "\n"
#define rall(x) x.rbegin(),x.rend()
#define len(a) (ll)a.size()
#define rep(x,l,r) for(ll x=l;x<r;x++)

//using namespace __gnu_pbds;
ld eps = (ld)1 / 1e6;
const ld pi=3.14159265359;
ll inf = 1e18,mod1=1e9+7;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const ll R=1e4;
const ll tx[4]={0,0,-1,1};
const ll ty[4]={-1,1,0,0};
const char rev_to[4]={'E','W','N','S'};
const int N=1e5+1;
const int M=1e9+7;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> st;
int n,m,k;
int a[N],b[N];
int f[N],cnt[26],dp[N];
signed main()
{
    ll a,b,c;
    cin>>a>>b>>c;
    cout<<b/c-(a-1)/c;
    return 0;
}
/*
    4 4
    1 2 a
    3 2 a
    1 4 a
    3 4 b




*/


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


void solve(std::string S){
    vector<string> yobi = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    for(int i = 0; i < yobi.size(); ++i){
        if(yobi[i] == S){
            cout << 7 - i << endl;
            break;
        }
    }
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


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

using namespace std;

const int md = 1000000007;

int main() {
  int n;
  scanf("%d", &n);
  int ans = 1;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    if (x <= 2 * i) {
      ans = (long long) ans * (i + 1) % md;
      n--;
      i--;
    }
  }
  for (int i = 1; i <= n; i++) {
    ans = (long long) ans * i % md;
  }
  printf("%d\n", ans);
  return 0;
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll S[105];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    memset(S, 0, sizeof(S));
    REP(i, K) {
        ll d;
        cin >> d;
        REP(j, d) {
            ll a;
            cin >> a;
            S[a - 1]++;
        }
    }

    ll ans = 0;
    REP(i, N) {
        if (S[i] == 0)
            ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef priority_queue<int> p_que;
typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev;
// const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};


int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    int ans = 0;
    ans = a + a - 1;
    ans = max(ans, a + b);
    ans = max(ans, b + b - 1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define irep(i,a,b) for(typeof(i) i = (a); i < (b); ++i)
#define itrep(it,c) for(auto it = (c).begin(); it != (c).end(); ++it)


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

	ll A;
	double B;
	cin >> A;
	cin >> B;
	
	ll C = (A * ((ll)floor(B * 100.0 + 0.5))) / 100;
	cout << C << endl;
	return(0);
}


Measured memory_bytes: 3860
program color
  implicit none
  character s*100000
  integer leng,i,count,flag,ans

  flag = 0
  ans = 0
  read *, s
  leng = len_trim(s)
  do i = 1, leng
    if (flag == 0) then
      if (s(i:i) == "0") ans = ans +1
      flag = 1
    else 
      if (s(i:i) == "1") ans = ans + 1
      flag = 0
    end if
  end do
  if (ans > leng/2) ans = leng - ans
  print '(i0)', ans
  stop
end program color

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

using namespace std;

void solve() {
    int H, W, A, B; cin >> H >> W >> A >> B;
    for (int j=0; j < H; j++) {for (int i=0; i < W; i++){
            if ((i < A && j < B) || (i >= A && j >= B)) {
                cout << "1";
            }else{
                cout << "0";
            }
        }
        cout << endl;
    }
}

int main() {
    int n; n = 1 ;
    while (n--) {
        solve();
    }
}

Measured memory_bytes: 1280
#include<stdio.h>
int main(){
	int S[13]={0},H[13]={0},C[13]={0},D[13]={0},i,x,y;
	char G;
	scanf("%d",&x);
	for(i=0;i<x;i++){
		scanf(" %c %d",&G,&y);
		if(G=='S')
		S[y-1]=1;
		else if(G=='H')
		H[y-1]=1;
		else if(G=='C')
		C[y-1]=1;
		else if(G=='D')
		D[y-1]=1;
	}
	for(i=0;i<13;i++){
			if(S[i]==0)
		printf("S %d\n",i+1);
	}
		for(i=0;i<13;i++){
	if(H[i]==0)
		printf("H %d\n",i+1);}
			for(i=0;i<13;i++){
		if(C[i]==0)
		printf("C %d\n",i+1);}
	for(i=0;i<13;i++){
		if(D[i]==0)
		printf("D %d\n",i+1);
	}
	
	
	return 0;
		
}

Measured memory_bytes: 596
//{
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FILL(i,n) memset(i,n,sizeof i)
#define X first
#define Y second
#define SZ(_a) (int)_a.size()
#define ALL(_a) _a.begin(),_a.end()
#define pb push_back
#ifdef brian
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // brian
//}


const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=ll(1e15);

int main()
{
    IOS();
    ll A,B;
    cin>>A>>B;
    cout<<A * B - A - B + 1<<endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);

    long n = scan.nextLong(), x = scan.nextLong();

    System.out.println(n+calc(x,n-x));
  }

  static long calc(long a,long b) {
    if(b%a==0) {
      return b*2L-a;
    }else {
      return (b/a)*a*2L+calc(b%a,a);
    }
  }
}


Measured memory_bytes: 9936
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#define repp(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define repm(i,a,b) for(int i=(int)a;i>(int)b;--i)
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<string>s(n);
	vector<int>p(n);
	vector <tuple<string, int,int>>pp(n);
	repp(i, 0, n) {
		cin >> s[i] >> p[i];
		pp[i] = make_tuple (s[i], p[i],i+1);
	}
	sort(pp.begin(), pp.end());
	repp(j, 0, n) {
		repp(i, 0, n - 1) {
			if (get<0>(pp[i]) == get<0>(pp[i + 1])) {
				if (get<1>(pp[i]) < get<1>(pp[i + 1])) {
					swap(pp[i], pp[i + 1]);
				}
			}
		}
	}
	for (int i = 0; i < n; ++i)cout << get<2>(pp[i]) << endl;
}

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

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
*/

using namespace std;

#if DEBUG && !ONLINE_JUDGE
    #include "debug.h"
#else
    #define debug(...)
#endif

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

#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define fill(a,x) memset(a,x,sizeof(a))
#define ff first
#define ss second
#define trav(a, x) for(auto& a : x) 
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
const ll INF = 1e18;
const int mod =  1e9 + 7;
const int N = 1e6;
ll gcd(ll a,ll b){if (a==0) return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return a*(b/gcd(a,b));}
ll Abs(ll a){if(a>0)return a;return -a;}
ll Ceil(ll a,ll b){if(a%b==0)return a/b;else return a/b+1;}
double Abs(double a){if(a>0)return a;return -a;}

//*X.find_by_order(2) element at index=2
//X.order_of_key(1) how many elements strictly less than 1

/*
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
    tree_order_statistics_node_update>;
*/

inline int pow_(ll x, ll y,ll p){
  int r = 1; while(y){if(y & 1) r = r * x % p; y >>= 1; x = x * x % p;} return r;
}
inline int inv_(int x){return pow_(x, mod - 2, mod);}
inline int add(int a, int b){a += b; if(a >= mod) a -= mod; return a;}
inline int mul(int a, int b){return a * 1LL * b % mod;}
inline int sub(int a, int b){a -= b; if(a < 0) a += mod; return a;}

ll dp[100005][105][2];
ll n;
ll d;
string s;

ll rec(int pos,int f,int rem)
{
	if(pos == n)
	{
		if(rem==0) return 1;
		else return 0;
	}

	if(dp[pos][rem][f]!=-1)return dp[pos][rem][f];
	else
	{
		dp[pos][rem][f] = 0;
		if(f==0)
		{
			for(int i=0;i<=9;i++)
			{
				int r = (rem + i)%d;
				dp[pos][rem][f] = (dp[pos][rem][f] + rec(pos+1,0,r))%mod;
			}
		}
		else
		{
			int val = s[pos] - '0';
			for(int i=0;i<=val;i++)
			{
				int r = (rem+i)%d;
				if(i < val)
				{
					dp[pos][rem][f] = (dp[pos][rem][f] + rec(pos+1,0,r))%mod;
				}
				else
				{
					dp[pos][rem][f] = (dp[pos][rem][f] + rec(pos+1,1,r))%mod;
				}
			}
		}
	}

	return dp[pos][rem][f];
}

int main()
{
	#ifdef LOCAL_TEST
    freopen("in.txt","r",stdin);
    //freopen("out.txt", "w", stdout);
    #else
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    #endif
    cin>>s;
    n = s.size();
    cin>>d;
    fill(dp,-1);
    cout << ((rec(0,1,0)-1)%mod + mod)%mod << "\n";
    return 0;
}

Measured memory_bytes: 165120
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int main() {
    string T;
    cin >> T;
    int n = T.size();
    if (T.size() == 0) {
        if (T[0] == '?')
            cout << "P" << endl;
        else
            cout << T << endl;
        return 0;
    }
    T = 'D' + T + 'P';
    rep(i, T.size()) {
        if (T[i] == '?') {
            if (T[i - 1] == 'P') T[i] = 'D';
            if (T[i - 1] == 'D') {
                if (T[i + 1] == 'D')
                    T[i] = 'P';
                else if (T[i + 1] == '?')
                    T[i] = 'P';
                else
                    T[i] = 'D';
            }
        }
    }
    T = T.substr(1, n);
    cout << T << endl;
    return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const R INF = 1E40L;
const R PI = acos(-1.0L);
using P=complex<R>;
const P O=0.0L;
using L=struct{P s,t;};
using VP=vector<P>;
using C=struct{P p;R c;};

inline R dot(P o,P a,P b){return real(conj(a-o)*(b-o));}
inline R det(P o,P a,P b){return imag(conj(a-o)*(b-o));}
inline int sdot(P o,P a,P b){return sgn(dot(o,a,b));}
inline int sdet(P o,P a,P b){return sgn(det(o,a,b));}

//projection verify AOJ CGL_1_A
P proj(L l,P p){ R u=real((p-l.s)/(l.t-l.s)); return (1-u)*l.s+u*l.t;}

istream& operator >> (istream& is,P& p){ R x,y;is >> x >> y; p=P(x,y); return is;}
ostream& operator << (ostream& os,P& p){ os << real(p) << " " << imag(p); return os;}

int main(void){
	P a,b,p;
	int n;
	cin >> a >> b >> n;
	L l={a,b};
	cout.precision(20);
	rep(i,n){
		cin >> p;
		P ans=proj(l,p);
		cout << fixed << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3224
import java.util.*;

public class Main {
    final static int MOD = 1000000007;
    
    public static void main(String[] args) {
        MyScanner in = new MyScanner();
        int n = in.nextInt();
        int[] l = in.nextIntArray(n);
        Arrays.sort(l);
        int count = 0;
        boolean frag = true;
        
        for (int i = 0; i < n - 2; i++) {
            for (int j = i+1; j < n - 1; j++) {
                for (int k = j+1; k < n; k++) {
                    if (l[k] < l[i] + l[j]) {
                        count++;
                    } else {
                            break;
                    }
                }
            }
        }
    
        System.out.println(count);
        
        
        
    }
    
    static class MyScanner {
        static Scanner sc = new Scanner(System.in);
        
        String next() {
            return sc.next();
        }
        
        String nextLine() {
            return sc.nextLine();
        }
        
        int nextInt() {
            return Integer.parseInt(sc.next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextInt();
            }
            return array;
        }
        
        double[] nextDoubleArray(int n) {
            double[] array = new double[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextDouble();
            }
            return array;
        }
        
        long[] nextLongArray(int n) {
            long[] array = new long[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextLong();
            }
            return array;
        }
        
        String[] nextLineArray(int n) {
            String[] array = new String[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextLine();
            }
            return array;
        }
        
        int[][] nextIntMatrix(int n, int m) {
            int[][] matrix = new int[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    matrix[i][j] = nextInt();
                }
            }
            return matrix;
        }
        
        double[][] nextDoubleMatrix(int n, int m) {
            double[][] matrix = new double[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    matrix[i][j] = nextDouble();
                }
            }
            return matrix;
        }
        
        long[][] nextLongMatrix(int n, int m) {
            long[][] matrix = new long[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    matrix[i][j] = nextLong();
                }
            }
            return matrix;
        }
    }
}

Measured memory_bytes: 25792
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0503
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int MAX_N = 15000000;
int m, n;

int main(){
    int j, k;
    n = 1;
    m = 1;
    vector<int> c(16);
    while(true){
        cin >> n >> m;
        if(n == 0 && n == 0) break;
        rep(i, 3){
            for(cin >> j; j > 0; --j){
                cin >> k;
                c.at(n-k) = i;
            }
        }

        int p = 0;
        int x = 0;
        for(int i = n-1; i >= 0; i--){
            int d = abs(p - c.at(i));
            x += pow(3,i) * d;
            if(d == 1) p = 2 - p;
        }

        int y = pow(3,n) - 1 - x;
        int answer = min(x, y);
        if(answer <= m) cout << answer << endl;
        else cout << -1 << endl;
    }
}


Measured memory_bytes: 3252
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n,x;cin>>n>>x;
	int a[100000];
	for(int i=0;i<n;i++)cin>>a[i];
	long long int all=0;
	if(a[0]>x)
	{
		all+=a[0]-x;
		a[0]=x;
	}
	for(int i=1;i<n;i++)
	{
		if(a[i]+a[i-1]>x)
		{
			all+=a[i]+a[i-1]-x;
			a[i]=x-a[i-1];
		}
	}
	cout<<all<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
typedef long long ll;
#define INF 1000000000 // 1 billion, safer than 2B for Floyd Warshall’s
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pcont(x) for(auto i: x){cout << i << " ";} cout << "\n";

int main(){
    IOS;
    int n;
    cin >> n;
    cout << (n==0?1:0) << "\n";

    return 0;
}

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

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

signed main(){

  int n;
  cin>>n;
  vector<ll> a(n);
  for(auto&ai:a)cin>>ai;

  vector dp1(n+1,pair(0ll,0ll));
  vector dp2(n+1,pair(0ll,0ll));
  dp1[0] = {1000,0};
  dp2[0] = {0,1000};

  rep(i,n){
    auto& ai = a[i];
    auto& [x,y] = dp1[i];
    auto& [w,z] = dp2[i];
    dp1[i+1] = max(dp1[i],make_pair(w*ai+z,0ll));
    dp2[i+1] = max(dp2[i],make_pair(x/ai,x%ai));
  }

  ll ans = 0;
  for(auto&[kane,kabu]:dp1)ans=max<ll>(ans,kane);
  for(auto&[kabu,kane]:dp2)ans=max<ll>(ans,kane);
  cout<<(ans)<<endl;

}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;

//int型vectorを出力
void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

//LLi型vectorを出力
void PVL(vector<LLi> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

	long long int a, v, b, w, t;
	cin>> a >> v >> b >> w >> t;

	if(v<=w){
		cout<< "NO" << endl;
		return 0;
	}

	if(abs(a-b)<=(v-w)*t){
		cout<< "YES" << endl;
	}else{
		cout<< "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 3600
num=input()
a=eval(num[0])*10+eval(num[1])
b=eval(num[2])*10+eval(num[3])
if 1<=a<=12:
    if 1<=b<=12:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if 1<=b<=12:
        print("YYMM")
    else:
        print("NA")

Measured memory_bytes: 3060
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	int MOD = 1000000007;

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();

		long ans = 1;
		for(int i=2; i*i<=m; i++) {
			if(m%i==0) {
				int cnt=0;
				while(m%i==0) {
					m /= i;
					cnt++;
				}
				ans *= combi(cnt + (n-1), n-1) ;
				ans = ans % MOD;
			}
		}
		if(m != 1) {
			ans *= combi(1+(n-1), n-1);
			ans = ans % MOD;
		}
		System.out.println(ans);

		sc.close();
	}

	private long modpow(long a, int p) {
		if(p==0)return 1;
		if(p%2==0) {
			long x = modpow(a, p/2) % MOD;
			return x * x %MOD;
		}else {
			return a * modpow(a, p-1) % MOD;
		}
	}

	private long combi(int n, int k) {
		long x = 1;
		long y = 1;
		for(int i=0; i<k; i++) {
			x *= (n-i);
			y *= (i+1);
			x %= MOD;
			y %= MOD;
		}
		return x * modpow(y, MOD-2) % MOD;
	}
}




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

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

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

    int N;
    std::cin >> N;

    vector<int> P(N);
    REP(i, N) {
        std::cin >> P[i];
    }

    auto max  = *max_element(ALL(P));
    auto ans  = 0;
    auto flag = true;
    REP(i, N) {
        if(flag && P[i] == max) {
            ans += P[i] / 2;
            flag = false;
        }
        else {
            ans += P[i];
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())
N = 0
for j in range(A + 1):
  for k in range(B + 1):
    for l in range(C + 1):
      if 500 * (j) + 100 * (k) + 50 * (l) == X:
        N += 1
print(N)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
struct vektor{
	int t;//縦
	int y;//横
	int m;//右斜め
	int h;//左斜め
};
int main(){
	while(true){
		int n;
		cin>>n;
		if(n==0){
			break;
		}
		vektor tebl[n+2][n+2]={};
		char l;
		int ans=0;
		for(int p=1;p<n+1;p++){
			for(int k=1;k<n+1;k++){
				cin>>l;
				if(l=='1'){
					tebl[p][k].t=tebl[p-1][k].t+1;
					tebl[p][k].y=tebl[p][k-1].y+1;
					tebl[p][k].m=tebl[p-1][k+1].m+1;
					tebl[p][k].h=tebl[p-1][k-1].h+1;
					if(tebl[p][k].t>ans){
						ans=tebl[p][k].t;
					}
					if(tebl[p][k].y>ans){
						ans=tebl[p][k].y;
					}
					if(tebl[p][k].m>ans){
						ans=tebl[p][k].m;
					}
					if(tebl[p][k].h>ans){
						ans=tebl[p][k].h;
					}
				}else{
					tebl[p][k].t=0;
					tebl[p][k].y=0;
					tebl[p][k].m=0;
					tebl[p][k].h=0;
					}
			}
		}
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 4108
#include<stdio.h>
#include<math.h>
int distance(int a,int b){
  return (a-b)*(a-b);
}
int main (void)
{
  int n,d,i,j,k;
  int cnt=0;
  scanf("%d%d",&n,&d);
  int x[n][d];
  long long int dis[n][n+1];
  for(i=0;i<n;i++){
    for(j=0;j<d;j++){
      scanf("%d",&x[i][j]);
    }
  }
  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      dis[i][j]=0;
    }
  }


  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      for(k=0;k<d;k++){
        dis[i][j]+=distance(x[i][k],x[j][k]);
      }
    }
  }
  /*
  *for(i=0;i<n;i++){
  *  for(j=0;j<d;j++){
  *    printf("x[%d][%d]= %3d   ",i,j,x[i][j]);
  *  }
  *  putchar('\n');
  *}
  */
  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      //printf("dis[%d][%d]=%4d ",i,j,dis[i][j]);
      k=(int) sqrt(dis[i][j]);
      if(k*k==dis[i][j]){
        cnt++;
      }
    }
    putchar('\n');
  }
  printf("%d",cnt);
  return 0;
}


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

#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mod 1000000007
#define ll long long
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define PI 3.14159265358979323

using namespace std;



ll solve(vector<vector<ll> > &dp, vector< pair<ll,ll> > &v, ll n, ll mv)
{
    if(mv==0) return 0;
    if(n==0) return 9999999999999;
    if(dp[n][mv]!=-1) return dp[n][mv];

    ll one=9999999999999,two=9999999999999;
    if(mv>=v[n-1].S)  one=v[n-1].F+solve(dp, v, n-1, mv-v[n-1].S);
    two = solve(dp, v, n-1, mv);

    return dp[n][mv]=min(one,two);
}


int main()
{
    ll x,y,n,w,ans=0,mv=0,kk;
    cin>>n>>w;
    vector< pair<ll,ll> > v(n);
    for(ll i=0;i<n;i++){
        cin>>x>>y;
        mv+=y;
        v[i]=mp(x,y);
    }
    vector<vector<ll> > dp( 110 , vector<ll> (mv+2,-1));

    for(ll i=mv;i>=0;i--){
        kk=solve(dp,v,n,i);
        if(kk<=w) { ans=i;  break;  }
    }
    cout<<ans<<"\n";

return 0;
}

Measured memory_bytes: 90140
#include <functional>
#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include <numeric>
using ll = long long;
using namespace std;
# define maxn 50
# define maxm 50

int main() {
  int n,sum(0);
  vector<int> l;
  cin>>n;
  for (int i(0);i<2*n;i++){
    int li;
    cin>>li;
    l.push_back(li);
  }
  sort(l.begin(),l.end());
  for (int i(0);i<n;i++){
    sum+=l[2*i];
  }
  cout<<sum;
}

Measured memory_bytes: 512
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)

	count := 0
	for i := 0; i < N; i++ {
		var x int
		fmt.Scan(&x)

		for j := 2; j*j <= x; j++ {
			if x%j == 0 {
				count++
				break
			}
		}
	}

	fmt.Println(N - count)
}



Measured memory_bytes: 1724
def main():
    import sys
    input = sys.stdin.readline
    
    S = input().rstrip()

    limit = len(S)//5

    while limit>0 and len(S)>0:
        if S.endswith('dreamer'):
            S = S[:len(S)-7]
        elif S.endswith('eraser'):
            S = S[:len(S)-6]
        elif S.endswith('dream'):
            S = S[:len(S)-5]
        elif S.endswith('erase'):
            S = S[:len(S)-5]
        limit-=1
    
    print('NO' if S else 'YES')

if __name__=='__main__':
    main()

Measured memory_bytes: 9204