akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#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++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBUG
const int inf=1e9+7;

vin h(1510);
vin w(1510);
map<int,int> hh;

int route(int n,int m){
    rep(i,n)cin>>h[i];
    rep(i,m)cin>>w[i];
    hh.clear();
    rep(i,n){
        int sumh=0;
        rep2(j,i,n){
            sumh+=h[j];
            hh[sumh]++;
        }
    }
    int tmp=0;
    rep(i,m){
        int sumw=0;
        rep2(j,i,m){
            sumw+=w[j];
            tmp+=hh[sumw];
        }
    }
    return tmp;
}

int main(){
    vin ans(1000,-1);
    int i=0;
    int n,m;
    while(1){
        cin>>n>>m;
        if(n==0&&m==0)break;
        ans[i]=route(n,m);
        i++;
    }
    rep(j,i)cout<<ans[j]<<endl;
}


Measured memory_bytes: 20960
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int n;
    cin >> n;
    int ans = 0, cnt = 0, pre = -1;
    for(int i = 0; i < n; i++){
        int h;
        cin >> h;
        if(pre >= h){
            cnt++;
            ans = max(ans, cnt);
        }
        else{
            cnt = 1;
        }
        ans = max(ans, cnt);
        pre = h;
    }
    cout << ans - 1 << endl;
}


Measured memory_bytes: 256
S = input()
ans = 0
#print(S[0:2], S[2:], int(S[0:2]), int(S[2:]))
if(0 < int(S[0:2]) and int(S[0:2]) <= 12) and (0 <= int(S[2:]) and (int(S[2:]) <= 99)):
    ans += 1
if(0 < int(S[2:]) and int(S[2:]) <= 12) and (0 <= int(S[0:2]) and (int(S[0:2]) <= 99)):
    ans += 2

if ans == 1:
    print('MMYY')
if ans == 2:
    print('YYMM')
if ans == 3:
    print('AMBIGUOUS')
if ans == 0:
    print('NA')


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

int main(void) {
    ll N, K;
    cin >> N >> K;
    vector<int> A(N, 0);
    for (int i=0; i<N; i++) {
        int tmp;
        cin >> tmp;
        A[tmp-1]++;
    }
    sort(A.begin(),A.end(),std::greater<int>());
    int rem = 0;
    for (int i=0; i<K; i++) rem += A[i];
    cout << N - rem << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
int n,first[26],last[26],mx,cnt;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>n>>s;
    rep(i,0,n){
        if(!first[s[i]-'a'])first[s[i]-'a']=i+1;
        last[s[i]-'a']=i+1;
    }
    rep(i,1,n){
        cnt=0;
        rep(j,0,26)if(first[j]<=i&&i<last[j])cnt++;
        if(mx<cnt)mx=cnt;
    }
    cout<<mx<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int m,f,r;
    int x=0;
    while(1){
        cin>>m>>f>>r;
        x++;
        char seiseki;
        if(m+f>=80){
            seiseki='A';
        }else if(65<=m+f&&m+f<80){
            seiseki='B';
        }else if(50<=m+f&&m+f<65){
            seiseki='C';
        }else if(30<=m+f&&m+f<50){
            if(r>=50){
                seiseki='C';
            }else if(m==-1||f==-1){
                seiseki='F';
            }else{
                seiseki='D';
            }
        }else if(m==-1&&f==-1&&r==-1){
            break;
        }else{
            seiseki='F';
        }
        
        if(m==-1&&f==-1&&r==-1){
            break;
        }else{
            cout<<seiseki;
        }
        cout<<endl;
    }
    return 0;
}



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

#define ll long long int

ll dp[100005];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, W;
    cin >> N >> W;
    dp[0] = 0;
    for (int i = 1; i <= 100000; i++) dp[i] = -1;
    for (int i = 0; i < N; i++)
    {
        int w, v;
        cin >> w >> v;
        for (int j = 100000; j >= 0; j--) if (dp[j] >= 0 && dp[j] + w <= W && (dp[j + v] == -1 || dp[j + v] > dp[j] + w)) dp[j + v] = dp[j] + w;
    }
    for (int i = 100000; i; i--) if (dp[i] >= 0)
    {
        cout << i << '\n';
        break;
    }
    return(0);
}

Measured memory_bytes: 1024
n,m = map(int,input().split())
ab=[0]*n
for i in range(n):
    ab[i] = list(map(int,input().split()))

ab.sort(key = lambda x:x[0])

now=0
yen=0
for i in range(n):
    if now + ab[i][1]<=m:
        now+=ab[i][1]
        yen+=ab[i][0] * ab[i][1]
    else:
        break
print( yen+(m-now)*ab[i][0] )

Measured memory_bytes: 60748
def main():
    W, H, x, y = map(int, input().split())
    barycente = [W/2, H/2]
    num = ""
    if barycente[0] == x and barycente[1] == y:
        num = "1"
    else:
        num = "0"
    print(barycente[0]*H, num)
main()


Measured memory_bytes: 2940
class Dice(object):
    
    def __init__(self, line):
        self.top = 1
        self.bottom = 6
        self.south = 2
        self.east = 3
        self.west = 4
        self.north = 5
        self.convert = line.split()
    
    def move(self, direction):
        if 'N' == direction:
            self.top, self.north, self.bottom, self.south = self.south, self.top, self.north, self.bottom
        elif 'S' == direction:
            self.top, self.north, self.bottom, self.south = self.north, self.bottom, self.south, self.top
        elif 'W' == direction:
            self.top, self.east, self.bottom, self.west = self.east, self.bottom, self.west, self.top
        elif 'E' == direction:
            self.top, self.east, self.bottom, self.west = self.west, self.top, self.east, self.bottom
    
    def result(self):
        return self.convert[self.top - 1]
    
dice = Dice(input())
for direction in input():
    dice.move(direction)

print(dice.result())

Measured memory_bytes: 7632
while True :
    m,f,r = map(int,input().split(" "))

    if (m == -1) and (f == -1) and (r == -1):
        break
    goukei = m + f

    if (m == -1) or (f == -1) or (goukei < 30):
        print("F")
    elif goukei >= 80 :
        print("A")
    elif goukei >= 65 :
        print("B")
    elif goukei >= 50 :
        print("C")
    elif goukei >= 30 :
        if r >= 50 :
            print("C")
        else :
            print("D")



Measured memory_bytes: 5592
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
#include <queue>
#include <set>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define REP(i,a) for(int i=0;i<(a);i++)
#define REPR(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
// using ll = long long;
// using vi = vector<int>;
// using vvi = vector<vi>;
// using vl = vector<long long>;
// using vvl = vector<vl>;
// using vs = vector<string>;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

int main () {
  int a,b;
  cin >> a >> b;
  int c = max(max(a*b,a-b),a+b);
  cout << c << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) //fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

const int N=10,P=1e9+7;

int mul(int a,int b){ return 1ll*a*b%P; }
int add(int a,int b){ a+=b; return a>=P?a-P:a; }
int sub(int a,int b){ a-=b; return a<0?a+P:a; }

int n,m,x,y,L[N],R[N];
char a[N][N]; 

int main(int argc,char *argv[]){
#ifdef GCURIOUSCAT
	freopen("dat.in","r",stdin);
	freopen("my.out","w",stdout);
#endif
	read(n),read(m); 
	bool suc=true;
	rep(i,1,n){
		scanf("%s",a[i]+1); 
		L[i]=m+1,R[i]=0; 
		rep(j,1,m)if(a[i][j]=='#'){
			cmin(L[i],j); 
			cmax(R[i],j); 
		}
		if(i>1)suc&=L[i]>=R[i-1]; 
	}
	suc&=L[1]==1&&R[n]==m;
	puts(suc?"Possible":"Impossible"); 
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define MAX 100000

int N, k;
double T[MAX];

int check(double);
int solve(void);


int main(void){
  int i;
  double a;
  scanf("%d%d", &N, &k);
  for( i = 0 ; i < N ; i++) scanf("%lf", &T[i]);
  a = solve();
  printf("%d\n", (int)a);

  return 0;
}



int check(double a){
  int i = 0, j;
  double s;
  for( j = 0 ; j < k ; j++){
    s = 0.0;
    while( s + T[i] <= a){
      s += T[i];
      i++;
      if( i == N ) return N;
    }
  }
  return i;
}

int solve(void){
  double left = 0.0;
  double right = 100000*10000;
  double mid;
  int v;

  while( right - left > 1){
    mid = ( left + right ) / 2;
    v = check(mid);
    if( v >= N ) right = mid;
    else left = mid;
  }
  return right;
}



Measured memory_bytes: 2532
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//孤立した'#'がなければ描ける

int main(void) {
	int i, j;
	int H, W;
	char **s;
	int possibility;
	int loneliness;
	char buf[128], *ch;

	fgets(buf, sizeof(buf), stdin);
	ch = strtok(buf, " ");
	H = atoi(ch);
	ch = strtok(NULL, " ");
	W = atoi(ch);

	s = (char **)calloc(H, sizeof(char *));
	for(i = 0; i < H; i += 1) {
		s[i] = (char *)calloc(W + 2, sizeof(char));
	}

	for(i = 0; i < H; i += 1) {
		fgets(s[i], sizeof(buf), stdin);
	}

	possibility = 1;
	for(i = 0; i < H; i += 1) {
		for(j = 0; j < W; j += 1) {
			if(s[i][j] == '#') {
				loneliness = 4;
				if(i == 0) {//top
					loneliness -= 1;
				} else {
					if(s[i - 1][j] == '.') {//above
						loneliness -= 1;
					}
				}
				if(i == H - 1) {//bottom
					loneliness -= 1;
				} else {
					if(s[i + 1][j] == '.') {//below
						loneliness -= 1;
					}
				}
				if(j == 0) {//leftest
					loneliness -= 1;
				} else {
					if(s[i][j - 1] == '.') {//left
						loneliness -= 1;
					}
				}
				if(j == W - 1){//rightest
					loneliness -= 1;
				} else {
					if(s[i][j + 1] == '.') {//right
						loneliness -= 1;
					}
				}
				if(loneliness == 0) {
					possibility = 0;
					break;//end j loop
				}
			}
		}
		if(possibility == 0) {
			break;//end i loop
		}
	}
	if(possibility == 1) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}

	for(i = 0; i < H; i += 1) {
		free(s[i]);
	}
	free(s);
	return 0;
}


Measured memory_bytes: 2024
#include<iostream>
#include<cstring>
#define ll long long
using namespace std;
int main()
{
char ss[1000];
ll p=0,res=0,q;
cin>>ss;
int k=strlen(ss);
for(int i=0;i<k;i++){
   p+=ss[i]-'0';
   q=ss[i]-'0';
   res*=10;
   res+=q;
}
if(res%p==0) cout<<"Yes"<<'\n';
else cout<<"No"<<'\n';
return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <string.h>
int main(void){
  int i,j,to,sum;
  char x[10010];
  char cmp[2][4]={"JOI","IOI"};
 
  while(scanf("%s",x) != EOF){
    to = strlen(x)-2;
    for(i=0;i<2;i++){
      for(j=sum=0;j<to;j++){
    if(!strncmp(&x[j],cmp[i],3)) sum++;
      }
      printf("%d\n",sum);
    }
  }
  return 0;
}


Measured memory_bytes: 2656
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;

int main(){
      int n, i;
      n = 0;
      cin >> n;

      int a[n];
      cin >> a[0];
      int tmp = a[0];
      for(i=1; i<n; i++){
         cin >> a[i];
         if(a[i] - a[i-1] > 0){tmp=a[i];}
         if(tmp-a[i] > 1){
              cout << "No";
              return 0;
         }
      }
      cout << "Yes";
	return 0;
}

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

int main() {
	int A, B, C, D;
    cin >> A >> B >> C >> D;
	if(A+B > C+D)
	{
	
	cout << "Left" << endl;
	
	}
	else if (A+B < C+D)
	{
	
	cout << "Right" <<endl;
	
	}
	else
	{
	
	cout << "Balanced" <<endl;

	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(){
  ll n,a,b;//aあお bあか
  cin >> n >> a >> b;
  ll ans=0;
  ll temp = n/(a+b);
  ans += temp*a;
  ans += min(n%(a+b),a);
  cout << ans << endl;
  return 0;
}

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

int main(){
    string s, t, u;
    int a, b;
    cin >> s >> t;
    cin >> a >> b;
    cin >> u;
    if(s == u){
        a--;
    }else if(t == u){
        b--;
    }
    cout << a << " " << b << endl;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int, input().split()))
mod=10**9+7
c=[0]*n
c[0]=a[0]
for i in range(1,n):
    c[i]=c[i-1]+a[i]
ans=0
for i in range(n-1):
    tmp=(c[-1]-c[i])*a[i]%mod
    ans=(ans+tmp)%mod
print(ans)

Measured memory_bytes: 31512
def resolve():
    N, T = list(map(int, input().split()))
    AB = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[0])
    dp = [[0 for _ in range(T)] for __ in range(N)]
    for i in range(1, N):
        time, value = AB[i-1]
        for j in range(T-1, -1, -1):
            dp[i][j] = dp[i-1][j]
            if j >= time:
                dp[i][j] = max(dp[i][j], dp[i-1][j-time]+value)
    print(max(dp[i][T-1]+AB[i][1] for i in range(N)))
    
if __name__ == "__main__":
    resolve()



Measured memory_bytes: 153244
#include <bits/stdc++.h>
using namespace std;
int main (){
  int a,b,c,d=1;
  cin>>a>>b>>c;
  if(a==1 || b==1){
    cout<<"YES";
    return 0;
  }
  for(int i=2;i<min(a,b)+1;++i){
    if(a%i==0 && b%i==0){
      d = i;
    }
  }
  if(d==1){
    cout<<"YES";
    return 0;
  }
  if(c%d==0){
    cout<<"YES";
    return 0;
  }
  else{
    cout<<"NO";
    return 0;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <set>
#include <string.h>
using namespace std;

int main()
{
  int n = 0;
  scanf("%d", &n);
  vector<int> a(n, 0);
  vector<long long> sum_a(n+1, 0);
  for(int i=0; i<n; i++){
    scanf("%d", &a[i]);
  }
  long long arr[n][n];
  long long curr_best = 0;
  memset(arr, 0, sizeof arr);
  for (int i=0; i<n; i++){
//    arr[i][i] = a[i];
    sum_a[i+1] = sum_a[i] + a[i];
  }
  for (int j=1; j<n; j++){
    for (int i=0; i+j<n; i++){
      curr_best = arr[i][i] + arr[i+1][i+j];        
      for (int k=i+1; k<i+j; k++){
        if(arr[i][k] + arr[k+1][i+j] < curr_best){
          curr_best = arr[i][k] + arr[k+1][i+j];
        }
      }
      arr[i][i+j] = curr_best + sum_a[i+j+1] - sum_a[i];
    }
  }
  printf("%lld\n", arr[0][n-1]);
  

//  for(int i=0; i<n; i++){
//    for(int j=0; j<n; j++){
//      printf("%lld ", arr[i][j]);
//    }
//    printf("\n");
//  }
}


Measured memory_bytes: 5016
use std::cmp::min;

fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: usize = read(&mut stdin_lock, &mut buf, b'\n');
    let mut hv = vec![0i32; n];
    for i in 0..n - 1 {
        hv[i] = read(&mut stdin_lock, &mut buf, b' ');
    }
    hv[n - 1] = read(&mut stdin_lock, &mut buf, b'\n');

    let mut cv = vec![0; n];
    cv[0] = 0;
    cv[1] = (hv[1] - hv[0]).abs();
    for i in 2..n {
        let c2 = cv[i - 2] + (hv[i] - hv[i - 2]).abs();
        let c1 = cv[i - 1] + (hv[i] - hv[i - 1]).abs();
        cv[i] = min(c1, c2);
    }
    println!("{}", cv[n - 1]);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define PI 3.141592653589
#define ll long long
using namespace std;

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

int  main(){
  int a, b, c;
  cin >> a >> b >> c;
  
  int na=0, nb=0, nc=0;
  int cnt = 0;
  bool flag = false;
  while(a%2==0 && b%2==0 && c%2==0){
    ++cnt;
    na += (b+c)/2;
    nb += (a+c)/2;
    nc += (a+b)/2;
    
    a = na;
    b = nb;
    c = nc;
    if(a==b && b==c){
      flag = true;
      break;
    }
  }
  if(flag) cout << -1 << endl;
  else cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()
AB = [chr(ord('A') + i) for i in range(26)]
R = ""

for i in range(len(S)):
    for j in range(26):
        if S[i] == AB[j]:
            m = j
    m = m + N
    if m >= 26:
        m = m - 26
    R = R + AB[m]
print(R)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define mat(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define each(x,y) for(auto &(x):(y))
#define var(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { cin >> first; Scan(rest...); }
#define vec(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pb pop_back
#define fi first
#define se second
#define get(a, i) get<i>(a)
#define bit_count __builtin_popcount
#define mt make_tuple
inline string zero(int a,string s,char c='0'){return string(a-len(s),c)+s;}
inline string zero(int a,int t,char c='0'){return zero(a, to_string(t), c);}
inline string zero(int a,ll t,char c='0'){return zero(a, to_string(t), c);}
#define mini min_element
#define maxi max_element
#define sum accumulate
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(a>b)a=b
template <class T> inline void print(T t){cout << t << '\n';}
template <class H, class... T> inline void print(H h, T... t){cout << h << " ";print(t...);}
const constexpr ll INF = 1LL<<55;
ll solve() {
	var(int, n);
	vec(ll, a, n);
	unordered_map<ll, vll> m;
	unordered_map<ll, ll> len_m;
	ll cnt = 0;
	rep(i, 0, n) {
		cnt += a[i];
		m[cnt].eb(i);
		++len_m[cnt];
	}
	each(b, m) {
		m[b.fi].eb(INF);
	}
	ll ans = 0;
	cnt = 0;
	rep(i, 0, n) {
		if (m.find(cnt) != m.end()) {
			ans += len_m[cnt] - (lower_bound(all(m[cnt]), i) - m[cnt].begin());
		}
		cnt += a[i];
	}
	return ans;
}
int main() {
	print(solve());
	return 0;
}


Measured memory_bytes: 27664
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

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

        int a = sc.nextInt();
        int b = sc.nextInt();
        int mass = a * b;

        if (mass % 2 == 0) {
            System.out.println("Even");
        } else {
            System.out.println("Odd");
        }

    }
}






Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int a[] = new int [100];
		int N = scan.nextInt();

		for(int i = 0; i < N; i++) {
			a[i] = scan.nextInt();
		}

		for(int i = 0; i < N; i++) {

			// 偶数だけど3でも5でも割り切れない
			if(a[i] % 2 == 0 && a[i] % 3 != 0 && a[i] % 5 != 0) {
				System.out.println("DENIED");
				return;
			}
		}

		System.out.println("APPROVED");


	}
}

Measured memory_bytes: 21716
from functools import lru_cache

N = int(input())
K = int(input())

@lru_cache(None)
def rec(n, k):
    if k == 0:
        return 1
    if n < 10:
        if k == 1:
            return n
        else:
            return 0


    m,d = divmod(n,10)

    ret = 0
    ret += d * rec(m,k-1) # 最後の桁は1~dの数字。それより上は再帰
    ret += (9-d)*rec(m-1,k-1) # 最後の桁は(d+1)~9，N以下を守るため最後から2番目の桁から1引く
    ret += rec(m,k) # 最後の桁は0，それより上は再帰

    return ret

print(rec(N,K))

Measured memory_bytes: 38640
def readinput():
    n=int(input())
    return n

def main(n):
    x7=int(n/1.07)+1
    x9=int(n/1.09)-1
    n100=n*100
    for x in range(max(1,x9),x7+1):
        xx=x*108//100
        #print(x,xx)
        if xx==n:
            print(x)
            break
    else:
        print(':(')

        

if __name__=='__main__':
    n=readinput()
    main(n)


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

#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) \
  for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define rep(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) \
  for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define rep_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int;  // 多倍長整数（任意精度）
typedef pair<int, int> P;

// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll MOD = ll(1e9) + 7;
const ll INF = ll(1e10);
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";
const double PI = acos(-1);

// define methods
// 最大公約数
ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector<pair<ll, ll>> prime_factorize(ll n) {
  vector<pair<ll, ll>> p;
  for (ll i = 2; i * i <= n; i++) {
    if ((n % i) != 0) continue;
    pair<ll, ll> a = make_pair(i, 0);
    while ((n % i) == 0) {
      n /= i;
      a.second += 1;
    }
    p.push_back(a);
  }

  if (n != 1) p.push_back(make_pair(n, 1));
  return p;
}
// 組み合わせの整合性を保つ（後ほど解析する）
ll modinv(ll a) {
  ll b = MOD, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= MOD;
  if (u < 0) {
    u += MOD;
  }
  return u;
}
// 順列
ll permutation(const ll n, const ll m) {
  ll result = 1;
  for (ll i = n; i > n - m; i--) {
    result = (result * i) % MOD;
  }
  return result;
}

// 繰り返し n 乗法
ll repeat_square(const ll n, const ll x) {
  if (x == 0) return 1;
  ll res = repeat_square(n, x / 2);
  res = res * res % MOD;
  if ((x % 2) == 1) res = res * n % MOD;
  return res;
}
// 組み合わせ nCm
ll combination(ll n, ll m) {
  ll p = permutation(n, m);
  ll div = 1;
  for (ll i = 2; i <= m; i++) {
    div = (div * i) % MOD;
  }
  return (p * modinv(div)) % MOD;
}

// アルファベットの取得
string get_alphabet(ll n) {
  n--;
  return string(1, 'a' + (n % 26));
}

int calc(string s) {
  bool is_zero = false;
  rep(i, s.length()) {
    if (s.substr(i, 1) == "0") is_zero = true;
  }
  return (is_zero) ? 0 : 1;
}

int main() {
  int N;
  ll K;
  cin >> N >> K;
  vector<ll> x(100001, 0);

  rep(i, N) {
    int a, b;
    cin >> a >> b;
    x[a] += b;
  }

  int ans = 0;
  rep(i, 1, x.size()) {
    if (K <= x[i]) {
      ans = i;
      break;
    }

    K -= x[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4012
#include <iostream>
#include <string>
#include <algorithm>
#include <unordered_map>
using namespace std;

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

	unordered_map<string, int> c;
	int n;
	long long r = 0;
	for (cin >> n; n--;) {
		string s;
		cin >> s;
		sort(begin(s), end(s));
		r += c[s]++;
	}
	cout << r << '\n';
	return 0;
}


Measured memory_bytes: 10660
#include <iostream>
#include <cstdlib>
#include <utility>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <numeric>

using namespace std;
using ll = long long;
using vi = vector<int>;

#define loopi(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define loop(i, n) for (int i = 0; i < (int)n; i++)
#define loopeq(i, n) for (int i = 0; i <= (int)n; i++)
#define loopll(i, n) for (ll i = 0; i < (ll)n; i++)
#define looplleq(i, n) for (ll i = 0; i <= (ll)n; i++)

int main() {
    int k; cin >> k;
    string s; cin >> s;
    if (s.size() <= k) {
        cout << s << endl;
        return 0;
    }
    else {
        string t = "";
        loop(i, k) {
            t += s[i];
        }
        t.append("...");
        cout << t << endl;
    }
}


Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int n;
int a[200010];

void solve(){
    cin >> n;
    rep(i,n){
        cin >> a[i];
    }
    int k=0;
    rep(i,n){
        if(a[i]==k+1){
            k++;
        }
    }
    if(k==0) cout << -1 << endl;
    else cout << n-k << endl;
}

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

Measured memory_bytes: 1024
/*
 * d.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_K = 100000;

/* typedef */

/* global variables */

int wis[MAX_N], wsums[MAX_N + 1];

/* subroutines */

bool ok(int n, int k, int p) {
  int prvsum = 0, c = 0;
  for (int i = 1; i <= n; i++) {
    if (wsums[i] - prvsum > p) {
      prvsum = wsums[i - 1];
      if (++c >= k) return false;
    }
  }
  return true;
}

/* main */

int main() {
  int n, k;
  cin >> n >> k;

  int maxwi = 0;
  wsums[0] = 0;

  for (int i = 0; i < n; i++) {
    cin >> wis[i];
    if (maxwi < wis[i]) maxwi = wis[i];
    wsums[i + 1] = wsums[i] + wis[i];
  }
  //printf("maxwi=%d\n", maxwi);

  int p0 = maxwi - 1, p1 = wsums[n] + 1;
  while (p0 + 1 < p1) {
    int p = (p0 + p1) / 2;
    if (ok(n, k, p)) p1 = p;
    else p0 = p;
  }

  printf("%d\n", p1);
  return 0;
}

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair

int main() {
  int n;
  cin >> n;
  vi h(n);
  rep (i, n) {
    cin >> h[i];
  }
  vi dp(n);
  dp[0] = 0;
  rep1 (i, n - 1) {
    if (i == 1) {
      dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
    }
    else {
      dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
    }
  }
  cout << dp[n - 1] << endl;
}
  


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

int main() {
    string s;
    cin >> s;
    if(s.at(0) == '1')s.at(0) ='9';
    else if(s.at(0) == '9')s.at(0) ='1';
    if(s.at(1) == '1')s.at(1) ='9';
    else if(s.at(1) == '9')s.at(1) ='1';
    if(s.at(2) == '1')s.at(2) ='9';
    else if(s.at(2) == '9')s.at(2) ='1';
    cout << s << endl;
}

Measured memory_bytes: 3612
import java.util.Scanner

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val k = sc.nextInt()

    val a = IntArray(n)
    var minIndex: Int = -1
    for (i in 0 until n) {
        a[i] = sc.nextInt()
        if (a[i] == 1) {
            minIndex = i
        }
    }

    println(replaceLeft(minIndex, minIndex, n, k))
}

fun replaceLeft(leftIndex: Int, rightIndex: Int, n: Int, k: Int): Int {
    if (leftIndex - k + 1 <= 0) {
        val right = rightIndex - (leftIndex - k + 1)
        return replaceRight(right, n, k) + 1
    }
    return replaceLeft(leftIndex - k + 1, rightIndex, n, k) + 1
}

fun replaceRight(rightIndex: Int, n: Int, k: Int): Int {
    if (rightIndex >= n - 1) {
        return 0
    }
    return replaceRight(rightIndex + k - 1, n, k) + 1
}

Measured memory_bytes: 52192
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(), (x).end()
typedef long long int ll;
using namespace std;
int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  int ans = c - (a - b);
  if (ans < 0)
  {
    cout << 0 << endl;
  }
  else
  {
    cout << ans << endl;
  }
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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

int mp[22][22];
ll dp[22][1<<22];

int main(){
	
	int n;cin >> n;
	REP(i,n)REP(j,n)cin >> mp[i][j];
	dp[0][0] = 1;
	
	REP(i,n){
		REP(j,1<<n)if(dp[i][j]){
			REP(ii,n)if(!(j & (1<<ii)) && mp[i][ii]){
				dp[i+1][j | (1<<ii)] += dp[i][j];
				dp[i+1][j | (1<<ii)] %= MOD;
			}
		}
	}
	
	cout << dp[n][(1<<n)-1] << endl;
	
	return 0;
}


Measured memory_bytes: 321792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AOZ
{
	class MainClass
	{
		static void Main(string[] args)
		{
			int h, w;
			StringBuilder ans = new StringBuilder();
			do
			{
				var input_arr = Console.ReadLine().Split(' ');
				h = int.Parse(input_arr[0]); w = int.Parse(input_arr[1]);
				if (h == 0 && w == 0)
					break;
				else
				{
					StringBuilder sb = new StringBuilder();
					for (int h_i = 0; h_i < h; h_i++)
					{
						for (int w_i = 0; w_i < w; w_i++)
						{
							if (h_i % 2 == 0)
							{
								if (w_i % 2 == 0)
									sb.Append("#");
								else
									sb.Append(".");
							}
							else
							{
								if (w_i % 2 == 0)
									sb.Append(".");
								else
									sb.Append("#");
							}
						}
						sb.AppendLine();
					}
					ans.AppendLine(sb.ToString());
				}
			} while (true);
			Console.Write(ans.ToString());
		}
	}
}



Measured memory_bytes: 17996
N=int(input())
n=0
for i in range(1,15):
   if N<=(n+26**i):
       break
   else:
       n+=26**i
#print(i)

N-=n
N-=1
#print(N)
A=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
ans=""
for j in range(i):
    ans+=A[N//(26**(i-1-j))]
    N%=(26**(i-1-j))
print(ans)

Measured memory_bytes: 61732
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
int main()
{
    int x,a,b,c,sum;
    while(cin>>a>>b>>c>>x)
    {
        sum=0;
       for(int i=0;i<=a;i++)
        for(int j=0;j<=b;j++)
            for(int k=0;k<=c;k++)
        if(x==i*500+j*100+k*50)
       {
           sum++;
       }
       cout<<sum<<endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=4000+10,maxm=2000+10,mod=998244353;
int ksm(int x,int y){
	int res=1;
	while(y){
		if(y&1) res=(ll)res*x%mod;
		x=(ll)x*x%mod;
		y>>=1;
	}
	return res;
}
int fac[maxn],ifac[maxn],dp[maxm][maxm],sum[maxm][maxm];
void init(int n=maxn-10){
	fac[0]=1;
	REP(i,1,n) fac[i]=(ll)i*fac[i-1]%mod;
	ifac[n]=ksm(fac[n],mod-2);
	DREP(i,n,1) ifac[i-1]=(ll)i*ifac[i]%mod;
}
inline int comb(int x,int y){
	if(x<0 || y<0 || x<y) return 0;
	return (ll)fac[x]*ifac[x-y]%mod*ifac[y]%mod;
}
int calc(int x,int y){
	if(x==0 && y==0) return 1;
	return comb(x+y-1,y-1);
}
int main(){
	init();
	int m=read(),n=read();
	dp[0][0]=1;
	REP(j,0,n-1) sum[0][j]=1;
	REP(i,1,m)
		REP(j,0,n){
			dp[i][j]=dp[i-1][j];
			if(j) dp[i][j]=(2ll*sum[i-1][j-1]+dp[i][j])%mod;
			sum[i][j]=dp[i][j];
			if(j) sum[i][j]=(sum[i][j]+sum[i][j-1])%mod;
		}
	REP(i,2,2*m){
		int u=min(m,i-1)-max(i-m,1)+1,ans=0;
		REP(j,0,n) ans=(ans+(ll)calc(n-j,m-u)*dp[u/2][j])%mod;
		if(i%2==0) REP(j,0,n-1) ans=(ans+(ll)calc(n-j-1,m-u)*dp[u/2][j])%mod;
		printf("%d\n",ans);
	}
	return 0;
}


Measured memory_bytes: 31872
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
using namespace std;

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

using ll = long long;
using Pii = pair<int, int>;

const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;

int dy[] = { 0, 0, 1, -1, 0 };
int dx[] = { 1, -1, 0, 0, 0 };

using MIte = multimap<long, long, greater<long> >::iterator;


//1618

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

	// long long?
	long long N;
	cin >> N;

	vector<ll> vA(N, 0);
	vector<ll> vSum(N, 0);

	rep(i, N) cin >> vA[i];
	vSum[0] = vA[0];
	rep(i, N - 1) {
		vSum[i + 1] = vSum[i] + vA[i+1];
	}

	map<ll, ll> mnum;
	rep(i, N) {
		mnum[vSum[i]]++;
	}

	long long ans = 0;
	for (map<ll, ll>::iterator it = mnum.begin(); it != mnum.end(); ++it) {
		if (it->first == 0) {
			ans += (it->second + 1) * it->second / 2;
		}
		else {
			ans += (it->second) * (it->second - 1) / 2;
		}
	}

	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

using namespace std;
using ll = long long;

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

    ll x=0;
    cin >> x;
    vector<int> ret;
    while(x > 26){
        int q = x%26;
        if(q == 0) q = 26;
        ret.push_back(q);
        ll p = (x - q)/26;
        x = p;
    }
    ret.push_back(x);
    rep(i,ret.size()){
        char c = 'a' + ret[(ret.size()-1) -i] -1;
        printf("%c",c);
    }
    printf("\n");
    return 0;
}


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

using namespace std;

const int LIM = 2016;

vector<vector<int>> g(LIM);
int ans = 0;
int n, k;

int dfs(int u, int d, int p = -1) {
  if (d < 0)
    return 0;
  if (d == 0)
    return 1;

  int res = 1;
  for (int to : g[u]) {
    if (to == p)
      continue;
    res += dfs(to, d - 1, u);
  }
  return res;
}

int main() {
  cin >> n >> k;
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    --u;
    --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }

  int _min = k / 2 - 1;
  int _max = k / 2 - 1;
  if (k & 1)
    ++_max;
  for (int i = 0; i < n; ++i) {
    vector<int> cnt;
    vector<int> cnt2;
    int sum = 1;
    for (int to : g[i]) {
      cnt.push_back(dfs(to, _min, i));
      cnt2.push_back(dfs(to, _max, i));
      sum += cnt.back();
    }
    ans = max(ans, sum);
    for (int j = 0; j < (int) g[i].size(); ++j)
      ans = max(ans, sum - cnt[j] + cnt2[j]);
  }

  cout << n - ans << endl;

  return 0;
}


Measured memory_bytes: 384
open class Type(private val value:Int){
    override fun equals(other: Any?): Boolean {
        return when(other){
            is Type -> value and other.value != 0
            else -> super.equals(other)
        }
    }
    operator fun plus(other: Type): Type{
        return Type(value or other.value)
    }
    override fun toString(): String {
        return "Type($value)"
    }
}
object None: Type(0)
object A: Type(1)
object B: Type(2)
object C: Type(4)
fun main(args:Array<String>): Unit {
    val n = readLine()!!.toInt()
    val allMember = Array(n){None as Type}
    val memberA = readLine()!!.trim().split(' ').map(String::toInt).drop(1)
    val memberB = readLine()!!.trim().split(' ').map(String::toInt).drop(1)
    val memberC = readLine()!!.trim().split(' ').map(String::toInt).drop(1)
    for (a in memberA) allMember[a - 1] += A
    for (b in memberB) allMember[b - 1] += B
    for (c in memberC) allMember[c - 1] += C
    println(
            allMember.count{
                (it == C) && ((it != A) || (it == B))
            }
    )
}


Measured memory_bytes: 33964
#include<stdio.h>

	int main(){
	
	int i,n,m,x=0,y=0,s=0,z,Z,w;
	
	
	while( scanf("%d,%d",&n,&m) != EOF){
		x=x+n*m;
		y=y+m;
		s++;
	}
		Z=y*10/s;
		Z=Z%10;
	
		if(Z>=5){
			z=y/s+1;
		}
		else if(Z<5){
			z=y/s;
		}
		
		printf("%d\n%d\n",x,z);
	
	return 0;
}

Measured memory_bytes: 588
#!/usr/bin/env python3

def main():
    N, K = map(int, input().split())
    d = []
    A = []
    for i in range(K):
        d.append(int(input()))
        A.append(input().split())
    all_A = sum(A, [])
    all_A = [int(i) for i in all_A]
    M = [i for i in range(1, N + 1)]
    print(len(set(M) - set(all_A)))


main()

Measured memory_bytes: 9808
import heapq
n,m = map(int,input().split())
a = [(-1)*int(i) for i in input().split()]
heapq.heapify(a)
while m >= 1:
	k = heapq.heappop(a)
	k *= -1
	k //= 2
	k *= -1
	heapq.heappush(a, k)
	m -= 1
print(-sum(a))

Measured memory_bytes: 14180
#include<bits/stdc++.h>
#define INF (1e9)
#define N 1005
using namespace std;
typedef complex<double> P; //Point
typedef pair<P,P> L; //Line, Segment
typedef pair<double,int> Pair;
const double EPS = 1e-8;

double dot(P a, P b){ return real(conj(a)*b); }

double cross(P a, P b){ return imag(conj(a)*b); }

int ccw(P a, P b, P c){
  b -= a;
  c -= a;
  if(cross(b,c) > EPS) return 1;   // ????????????(b-a)????????´???????????????(c-a)????????¨?????????
  if(cross(b,c) < -EPS) return -1; // ????????????(b-a)????????´???????????????(c-a)????????¨?????????
  if(dot(b,c) < -EPS) return 2;
  if(norm(b) < norm(c)) return -2;
  return 0;
}

bool isIntersect(L s1, L s2){
  return ( ccw(s1.first,s1.second,s2.first) * ccw(s1.first,s1.second,s2.second) <= 0 &&
           ccw(s2.first,s2.second,s1.first) * ccw(s2.first,s2.second,s1.second) <= 0 );
}

int S[2],x,y;
P G[2][N];

double getDistancePP(P A,P B){
  return abs(P(A.real()-B.real(),A.imag()-B.imag()));
}

double dijkstra(int idx){
  L base=L(P(G[!idx][0].real(),G[!idx][0].imag()),P(G[!idx][1].real(),G[!idx][1].imag()));
  priority_queue<Pair,vector<Pair>,greater<Pair> > q;
  double d[N];
  for(int i=0;i<S[idx];i++)d[i]=INF;
  d[0]=0;
  q.push(Pair(0,0));
  while(!q.empty()){
    Pair t=q.top(); q.pop();
    double cost=t.first;
    int node=t.second;
    if(d[node]<cost)continue;
    for(int i=0;i<S[idx];i++){
      if(i==node)continue;
      if(isIntersect(base,L(P(G[idx][node].real(),G[idx][node].imag()),P(G[idx][i].real(),G[idx][i].imag()))))continue;
      double ncost=cost+getDistancePP(G[idx][node],G[idx][i]);
      if(d[i]>ncost){
	d[i]=ncost;
	q.push(Pair(ncost,i));
      }
    }
  }
  return min(INF,d[1]+getDistancePP(G[!idx][0],G[!idx][1]));
}

int main(){
  cin>>S[0]>>S[1];
  for(int i=0;i<S[0];i++)
    cin>>x>>y,G[0][i]=P(x,y);
  for(int i=0;i<S[1];i++)
    cin>>x>>y,G[1][i]=P(x,y);
  double ans=INF;
  ans=min(ans,dijkstra(0));
  ans=min(ans,dijkstra(1));
  if(ans==INF)cout<<-1<<endl;
  else printf("%.10f\n",ans);
  return 0;
}

Measured memory_bytes: 3344
#include <iostream>
#include <fstream>
#include <algorithm>
#include <set>
//#define LOCAL
#define be(n) n.begin(), n.end()
using namespace std;
typedef long long ll;
set<ll>a, b;


int main() {
#ifdef LOCAL
ifstream fin("1.txt");
streambuf*p;
p=cin.rdbuf(fin.rdbuf());
#endif // LOCAL
ll n;
cin>>n;
for(ll i=0;i<n;i++){
    ll v;
    cin>>v;
    a.insert(v);
}

ll m;
cin>>m;
for(ll i=0;i<m;i++){
    ll v;
    cin>>v;
    b.insert(v);
}
set<ll>c;
set_difference(be(a), be(b), inserter(c, c.begin()));
for(set<ll>::iterator it=c.begin();it!=c.end();it++){
    cout<<*it<<endl;
}

#ifdef LOCAL
fin.close();
#endif // LOCAL
}



Measured memory_bytes: 31124
def pale(string):
    return 1 if string==string[::-1] else 0

S = (input())
N = len(S)
tmp1 = S[:(N-1)//2]
##print(tmp1)
tmp2 = S[(N+3)//2-1:]
##print(tmp2)
if pale(S) and pale(tmp1) and pale(tmp2):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    string S; cin >> S;
    vector<int> N;
    rep(i,S.size()) {
        int cnt = 1;
        int j = i + 1;
        while (j < S.size() && S[i] == S[j]) j++, cnt++;
        N.push_back(cnt);
        i = j - 1;
    }
    bool less = (S[0] == '<');
    int i = 0;
    while (i < N.size()-1) {
        if (less) {
            if (N[i] < N[i+1]) N[i]--;
            else N[i+1]--;
        }
        less = !less;
        i++;
    }
    ll sum = 0;
    rep(i,N.size()) sum += ((ll)N[i] * (N[i]+1))/2;
    cout << sum << endl;
}


Measured memory_bytes: 5224
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))  // xが範囲内か
#define sort_u(x) sort((x).begin(),(x).end())
#define sort_d(x) sort((x).begin(),(x).end(), greater<int>())
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()  // 配列のサイズ
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cerr<<#x<<" = "<<x<<endl;  // 確認したいとき
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))  // 切り上げたいとき
#define newline puts("")
#define v(T) vector<T>  // Tはどんな型でもいい
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;  // ******
typedef vector<vi> vvi;
typedef vector<ll> vl;  // ******
typedef vector<P> vp;
typedef vector<T> vt;
int getInt(){int x;scanf("%d",&x);return x;}
template<typename T>istream& operator>>(istream&i,v(T)&v){rep(j,sz(v))i>>v[j];return i;}  // vi a(n); cin>>a;
template<typename T>string join(const v(T)&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}  // 
template<typename T>ostream& operator<<(ostream&o,const v(T)&v){if(sz(v))o<<join(v);return o;}  // cout<<a;  aの中身全部出す
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.fi<<","<<v.se;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const v(T)&a){ll res(0);for(auto&&x:a)res+=x;return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame1 { puts("-1"); return 0;}
#define dame0 { puts("0"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define out cout << ans << endl;
//mins(ans,now);  ansに最小値が入る
//if(max(ans,now)) ansが小さければ更新して実行。cnt++とか。
//ll sum = suma(a);  aの累積和
//int vec[3][4];

int main() {
    int n; cin >> n;
    string s; cin >> s;
    int ans = 0;
    rep(i,1000){
        string b;
        if(i<10) {b = "00"; b += to_string(i);}
        else if(i<100) {b = "0"; b += to_string(i);}
        else b = to_string(i);
        int k = 0;
        rep(j,n){
            if(s[j]==b[k]) k++;
            if(k == 3) break;
        }
        if(k == 3) ans++;
    }
    out;
}

/*
g++ a.cpp
./a.out

oj d
oj t

debug:ctrl+shift+B+./problem.exe
problem.in+f5

*/


Measured memory_bytes: 3760