akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#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++)

int main() {
    int N, ans = 0;
    double M, wa = 0;
    cin >> N >> M;
    vector<int> A(N);
    rep(i, N){
        cin >> A.at(i);
        wa += A.at(i);
    }
    rep(i, N){
        if(A.at(i) >= wa / (4.0 * M)){
            ans++;
        }
    }
    if(ans >= M){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    char a,b,c;
    cin >> a >> b >> c;
    int D = (a - '0')*100 + (b - '0')*10 + (c - '0');
    if(D%4 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  int x, a, b;
  cin >> x >> a >> b;
  if (abs(x - a) < abs(x - b)) {
    cout << "A" << endl;
  } else {
    cout << "B" << endl;
  }
  return 0;
}

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

int main(void){
  int a,b = 0;
  scanf("%d %d", &a, &b);

  if(a>12) printf("%d", b);
   if(a<=12 && a>=6) printf("%d", b/2);
  if(a<6) printf("0");



  
  return 0;
}

  

Measured memory_bytes: 1712
#include<iostream>
using namespace std;
#define reps(i,b,n) for(int i = b ; i < (int)n ; ++i )
#define rep(i,n) reps(i,0,n)
int main(){
  string str;
  long long f[21]={1},ans,dat[26] = {},sum = 0,cnt = 0;
  cin >> str;
  rep(i,str.size()) dat[str[i]-'a']++;
  rep(i,26) cnt += dat[i] % 2 , dat[i] /= 2 , sum += dat[i];
  if(cnt > 1) cout << 0 << endl;
  else{
    reps(i,1,21) f[i] = f[i-1] * i;
    ans = f[sum];
    rep(i,26) ans /= f[dat[i]];
    cout << ans << endl;
  }
}

Measured memory_bytes: 1184
X, N= list(map(int, input().split()))
P = list(map(int, input().split()))
for i in range(0, 51):
    try:
        P.index(X - i)
    except Exception:
        print(X - i)
        break

    try:
        P.index(X + i)
    except Exception:
        print(X + i)
        break

Measured memory_bytes: 9212
#include<stdio.h>
int MAX(int a,int b){return a<b?b:a;}
int main(){
  int a,b,m,i,j,max;
  while(scanf("%d %d %d",&a,&b,&m),a||b||m){
    for(i=max=1;i<m;i++){
      for(j=i;j<m;j++){
	if(i*(100+a)/100+j*(100+a)/100-m)continue;
	max=MAX(max,i*(100+b)/100+j*(100+b)/100);
      }
    }
    printf("%d\n",max);
  }
  return 0;
}

Measured memory_bytes: 600
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

last = -1

sum = sum(b) 

for i in range(n):
    if last == a[i]-1:
        sum += c[last-1]
    last = a[i]
print(sum)


Measured memory_bytes: 38384
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
F = []
for i in range(N):
    f = list(map(str, input().split()))
    bi = ''.join(f)
    F.append(int(bi, 2))
P = []
for i in range(N):
    p = getList()
    P.append(p)

# -modに!!
ans = -mod
for bit in range(1, 1 << 10):
    cnt = 0
    for j in range(N):
        open = bit & F[j]
        index = str(bin(open)).count('1')
        # print(P[i][index])
        cnt += P[j][index]
    ans = max(ans, cnt)
print(ans)


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

int main ()
{
    int a, b, c;
    while (cin >> a >> b >> c) {
        int sum1 = a + b, sum2 = c;
        vector<bool> v(11, true);
        v[a] = v[b] = v[c] = false;
        int res1 = 0, res2 = 0;
        for (int i = 0; i < 11; i++) {
            if (v[i]) {
                for (int j = 1; j < 11; j++) {
                    for (int k = 0; k < 11; k++) {
                        if (v[j] && v[k] && k != j && i != j && i != k) {
                            if (sum1 + j <= 20) res1++;
                            else res2++;
                        }
                    }
                }
            }
        }
        if ((double)res1 / (double)(res2 + res1) >= 0.50) cout << "YES" << endl;
        else cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 1184
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}


signed main(void) {
    int n,m;
    cin >> n >> m;
    vi v(n+1,0);
    rep(i,m){
        int l,r;
        cin >> l >> r;
        v[l-1]++;
        v[r]--;
    }
    rep(i,n)v[i+1] += v[i];
    int ans = 0;
    rep(i,n)if(v[i] == m)ans++;
    cout << ans << endl;

}


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

using namespace std;

using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k;
    cin >> n >> k;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (x >= k) {
            cnt++;
        }
    }
    cout << cnt;
    return 0;
}


Measured memory_bytes: 256
//In The Name Of Allah
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define sz(x) (int)(x).size()
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define fi first
#define se second
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> M;

const int mod = 1e9 + 7;

M mul(M &a, M b) {
	int n = sz(a), l = sz(b), m = sz(b[0]);
	M c(n, vi(m, 0));
	rep(i, 0, n) {
		rep (j, 0, m) {
			rep (k, 0, l) c[i][j] += a[i][k] % mod * b[k][j] % mod;
			c[i][j] %= mod;
		}
	}
	return c;
}

M mpow (M &a, int b) {
	if (b == 0) {
		M v(sz(a), vi(sz(a[0]), 0));
		rep (i, 0, sz(a)) v[i][i] = 1;
		return v;
	}
	M nesf = mpow(a, b / 2);
	if (b % 2 == 0) {
		return mul(nesf, nesf);
	} else {
		return mul(nesf, mul(nesf, a));
	}
}

signed main() {
	cin.sync_with_stdio(0); cin.tie(0);
	int n, k;
	cin >> n >> k;
	M g(n, vi(n));
	rep (i, 0, n) {
		rep (j, 0, n) {
			cin >> g[i][j];
		}
	}
	auto res = mpow(g, k);
	int ans = 0;
	trav (row, res) {
		trav (cell, row) {
			ans += cell % mod;
			ans %= mod;
		}
	}
	cout << ans << "\n";

}



Measured memory_bytes: 384
n = int(input())
s = input()

e = [0]
ei = 0

for c in s:
    if c == "E":
        ei += 1
    e.append(ei)

ans = n
for i in range(n):
    cand = i - e[i] + e[-1] - e[i+1]
    ans = min(ans, cand)
print(ans)


Measured memory_bytes: 59096
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<map>
#define int long long
using namespace std;
inline int read() {
	int x=0,f=1; char ch=getchar();
	while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<3)+(x<<1)+(ch^48); ch=getchar(); }
	return x * f;
}
const int N = 1e5+7;
map<string,int> mp;
string name[N];
int n,cnt,ans;
signed main()
{
	cin>>n;
	int len = 10;
	for(int i=1;i<=n;++i) {
		char s[15];
		cin>>s;
		sort(s,s+strlen(s));
		if(!mp[s]) name[++cnt] = s;
		mp[s]++;
	}
	for(int i=1;i<=cnt;++i) {
		int num = mp[name[i]];
		num--; ans += ( (1+num)*num ) / 2;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 16640
/*  ex7_3
    Graku   */
#include<stdio.h>
#include<stdlib.h>

int main(void) {
    int height, width;
    char **table;
    int *blank_rows, *blank_cols;

    scanf("%d %d", &height, &width); //input
    table = (char**)malloc(sizeof(char*) * height); //table[height]
    for (int i = 0; i < height; ++i) { //table[height][width]
        table[i] = (char*)malloc(width * sizeof(char));
    }
    blank_rows = (int*)calloc(height, sizeof(int));
    blank_cols = (int*)calloc(width, sizeof(int));

    for (int row = 0; row < height; ++row) { //input
        for (int col = 0; col < width; ++col) {
            scanf(" %c", &table[row][col]);
        }
    }
 
    for (int row = 0; row < height; ++row) { //find blank rows
        int flag = 0;
        for (int col = 0; col < width; ++col) {
            if ('#' == table[row][col]) { //not blank
                flag = 1;
                break;
            }
        }
        blank_rows[row] = flag;
    }
    for (int col = 0; col < width; ++col) { //find blank columns
        int flag = 0;
        for (int row = 0; row < height; ++row) {
            if ('#' == table[row][col]) { //not blank
                flag = 1;
                break;
            }
        }
        blank_cols[col] = flag;
    }

    //output
    for (int row = 0; row < height; row++) {
        if (blank_rows[row]) { //if row is not blank
            for (int col = 0; col < width; ++col) {
                if (blank_cols[col]) { //if column is not blank
                    printf("%c", table[row][col]);
                }
            }
            printf("\n");
        }
    }

    //free memory
    for (int i = 0; i < height; ++i) {
        free(table[i]);
    }
    free(table);
    free(blank_cols);
    free(blank_rows);

    return 0;
}


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

int main() {
  vector<int> abc(3);
  rep(i, 3) cin >> abc.at(i);
  if (abc.at(0) == abc.at(1)) {
    if (abc.at(0) == abc.at(2)) cout << 1 << endl;
    else cout << 2 << endl;
  }
  else {
    if (abc.at(0) == abc.at(2) || abc.at(1) == abc.at(2)) cout << 2 << endl;
    else cout << 3 << endl;
  }
}

Measured memory_bytes: 256
def solve():
    n,x = map(int,input().split())
    if n==0 and x==0:
        return False
    ans = 0
    s = set()
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            it = x-i-j
            v = [it,i,j]
            v = sorted(v)
            val = v[0]*1000000+v[1]*1000+v[2]
            if 0<it<=n and it!=i and it!=j and (not val in s):
                s.add(val)
                ans+=1
    print(ans)
    return True
if __name__ == "__main__":
    while(solve()):
        pass


Measured memory_bytes: 5628
n = int(input())
numbers = list(map(int, input().split()))

def checkCondition():
  for i in range(n-1):
    if numbers[i] > numbers[i+1] + 1:
      return False
  for i in range(-1, -n, -1):
    if numbers[i-1] - numbers[i] == 1:
      numbers[i-1] -= 1
    elif numbers[i-1] - numbers[i] > 1:
      return False
  return True

if n == 1:
  print('Yes')
else:
  if checkCondition():
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 14396
//abc140_a.cpp
//Wed Oct  9 23:40:14 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	cout << pow(n,3)<< endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
#define NIL -2000000001
#define MAX 2000000000000

int main() {
  char str[1001];
  scanf("%s", str);
  int w;
  scanf("%d", &w);
  int len;
  for(len=0; str[len]!='\0'; ++len);
  int i = 0;
  while (i < len) {
    printf("%c", str[i]);
    i += w;
  }

  printf("\n");

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll              long long int
#define int             ll
#define ff              first
#define ss              second
#define pb              push_back
#define mpair           make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define sbits(x)      __builtin_popcountll(x)
#define zbits(x)      __builtin_popcountlliltin_ctzll(x)
#define w(t)            int t;cin>>t;while(t--)
#define uset            unordered_set
#define en              cout<<endl
using namespace std;
void fast(){ios_base::sync_with_stdio(false);cin.tie(NULL);cout<<fixed<<setprecision(10);}
int max2(int a,int b){ if(a>b) return a;return b;}
int min2(int a,int b){ if(a<b)return a;return b;}
int max3(int a,int b,int c){ return max2(a,max2(b,c));}
int min3(int a,int b,int c){ return min2(a,min2(b,c));}
void system_output(){
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
   #endif
}
void solve(){
   int x;
   cin>>x;
   if(x==1)
   {
     cout<<1<<" "<<0<<endl;
     return;
   }
   map<int,int>mp;
   int k;
   for(int  i = -3980;i<=3980;i++)
   {
         k = i*i*i*i*i;
         mp[k] = i;  
   }
   // int tot = 1000000000000000000;
   for(int  i = -3980;i<=3980;i++){
        k = i*i*i*i*i;
        if(mp.find((k+x))!=mp.end()){

          cout<<mp[(k+x)]<<" "<<i<<endl;
          break;
        }
   }

}
signed main(void)
{
      fast();
      //w(t)
      solve();
}


Measured memory_bytes: 4128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> a(M), b(M);
  for (int i = 0; i < M; i++) cin >> a.at(i) >> b.at(i);
  
  for (int i = 0; i < N; i++)
  {
    int count = 0;
  	for (int j = 0; j < M; j++)
    {
    	if (a.at(j) == i+1 || b.at(j) == i+1) count++;
    }
    cout << count << endl;
  }
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int a, b;
    cin >> a >> b;
    if (a <= b)
        OP(a);
    else
        OP(a - 1);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
using ulong = unsigned long;
using ll = long long;

int main(){
	int a, b;
	cin >> a >> b;
	if(a == 0 || b == 0 || (a < 0 && b > 0)){
		cout << "Zero" << endl;
		return 0;
	}
	if(a > 0){
		cout << "Positive" << endl;
		return 0;
	}
	cout << ((b - a) % 2  ? "Positive" : "Negative") << endl;
	return 0;
}



Measured memory_bytes: 888
#include<cstdio>
using namespace std;
double a[4][4];
int main()
{
    for(int i=1;i<=3;i++)
    {
        for(int j=1;j<=3;j++)
        {
            scanf("%lf",&a[i][j]);
        }
    }
    if(a[1][2]+a[2][3]+a[3][1]+a[1][3]+a[2][1]+a[3][2]==(a[1][1]+a[2][2]+a[3][3])*2)
    printf("Yes\n");
    else
    printf("No\n");
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>
const int mod=1e9+7;
using LL=long long;
using std::cout;using std::endl;using std::cin;
using std::vector;using std::string;using std::set;using std::multiset;
using std::pair;using std::map;
using std::min;using std::max;

namespace ndifix{
}

int main(){
  int n;cin>>n;
  vector<pair<string,pair<int,int>>> spi(n);

  string s;int p;
  for(int i=0;i<n;i++){
    cin>>s>>p;p*=(-1);
    spi[i]=std::make_pair(s,std::make_pair(p,i+1));
  }
  std::sort(spi.begin(),spi.end());
  for(int i=0;i<n;i++)cout<<spi[i].second.second<<endl;
  



  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
        if(a==0)return b;
        else return gcd(b%a,a);
}

int main(){
        vector<int> a(3);
        cin>>a[0]>>a[1]>>a[2];
        sort(a.begin(),a.end() ) ;
        if(a[2] == a[0] ) {
                cout<<"Yes"<<endl;
        }else{
                cout<<"No"<<endl;
        }

        return 0;
}
       

Measured memory_bytes: 256
from bisect import bisect_right, bisect_left
from collections import Counter, deque
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import groupby, permutations, combinations, product
from sys import stdin, stderr


# 最大公約数（ユークリッドの互除法）
# Python3.5 で math.gcd()が追加され、
# AtCoder環境と最新環境でパッケージが分かれてしまったので、自分で書いておく
def gcd(x, y):
    return x if y == 0 else gcd(y, x % y)


# 拡張ユークリッド互除法
# 正整数x, y について、a*x + b*y == gcd(x,y)なるa,bを返す。
# 特に、互いに素なるx, yについては a*x + b*y == 1 となる a, b。
def exgcd(x, y):
    if y == 0:
        return 1, 0
    a, b = exgcd(y, x % y)
    return b, a - (x // y) * b


# 最小公倍数
def lcm(x, y):
    m = gcd(x, y)
    return (x // m) * (y // m)


def main():
    s = input()
    ret = "x" * len(s)
    return ret


if __name__ == "__main__":
    print(main())

Measured memory_bytes: 3812
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int i=0;
  while(a<=b){
    b=b-a;
    i++;
    if(i==c){
      break;
    }
  }
  cout<<i<<endl;
}

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

using namespace std;


int bfs(const vector<vector<int>>& ADJ, int S, int G){
	int result;
	int n = ADJ.size();
	queue<int> Q;
	vector<bool> status(n, false);
	vector<int> dist(n, 1000000);
	Q.push(S);
	dist[S] = 0;
	int current_node, next_node;
	
	while(!Q.empty()){
		current_node = Q.front();
		Q.pop();		
		for(int i = 0; i < ADJ[current_node].size(); i++){
			next_node =  ADJ[current_node][i];
			if(status[next_node] == false){
				dist[next_node] = dist[current_node] + 1;
				status[next_node] = true;				
				Q.push(next_node);
			}			
		}		
	}
	
	if(status[G] == false) return -1;	
	
    result = dist[G] / 3;	
	return result;
}


int main()
{
	int N, M;	  
	cin >> N >> M;
	vector<vector<int>> ADJ(3*N);
	int s1, t1, s2, t2, s3, t3;
	
	for(int i = 0; i < M; i++){
		cin >> s1 >> t1;
		s1 -= 1;
		t1 -= 1;
		s2 = s1 + N;
		t2 = t1 + N;
		s3 = s2 + N;
		t3 = t2 + N;
		ADJ[s1].push_back(t2);
		ADJ[s2].push_back(t3);
		ADJ[s3].push_back(t1);
	}	
	
	int S, G;
	cin >> S >> G;
	cout << bfs(ADJ, S - 1, G - 1) << endl;	 
    return 0;
}

Measured memory_bytes: 17792
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,*a = map(int,read().split())

res = [0]*3

for x in a:
    if x%4==0: res[2] += 1
    elif x%2==0: res[1] += 1
    else: res[0] += 1

#print(res)

ans = ""
if res[0]==0:
    ans = "Yes"
else:
    if res[1]==0:
        if res[2]+1 >= res[0]:
            ans = "Yes"
        else:
            ans = "No"
    else:
        if res[2] >= res[0]:
            ans = "Yes"
        else:
            ans = "No"
        

print(ans)




Measured memory_bytes: 19936
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

template<typename T> class segtree {
private:
    int n,sz;
    vector<pair<T, int> > node;
public:
    segtree(const vector<T>& v) : n(1), sz((int)v.size()){
        while(n < sz) n *= 2;
        node.resize(2*n, make_pair(numeric_limits<T>::max(), sz));
        for(int i = 0; i < sz; i++){
            node[i+n] = make_pair(v[i], i);
        }
        for(int i=n-1; i>=1; i--){
            node[i] = min(node[2*i], node[2*i+1]);
        }
    }
    void update(int k, T a)
    {
        node[k+n] = make_pair(a, k);
        k += n;
        while(k>>=1){
            node[k] = min(node[2*k], node[2*k+1]);
        }
    }
    pair<T, int> query(int a,int b,int k=0,int l=0,int r=-1)
    {
        pair<T, int> res1 = make_pair(numeric_limits<T>::max(), sz);
        pair<T, int> res2 = make_pair(numeric_limits<T>::max(), sz);
        a += n, b += n;
        while(a != b){
            if(a % 2) res1 = min(res1, node[a++]);
            if(b % 2) res2 = min(res2, node[--b]);
            a >>= 1, b>>= 1;
        }
        return min(res1, res2);
    }
    void _print()
    {
        for(int i = 0; i < sz; i++){
            pair<T, int> p;
            p = query(i,i+1);
            cout << "st[" << i << "]: " << p.first << " " << p.second << endl;
        }
    }
};

vector<int> p;
vector<vector<int>> pr;
vector<segtree<int>> sg;
vector<P> res;

void dfs(int l, int r, int from){
    if(r <= l)return;

    auto lmin = sg[l%2].query(l, r);
    int li = lmin.second;
    auto rmin = sg[1-l%2].query(li+1, r);
    int ri = rmin.second;

    int at = res.size();
    res.push_back(P(lmin.first, rmin.first));
    if(from != -1)
        pr[from].push_back(at);
    
    dfs(l, li, at);
    dfs(li+1, ri, at);
    dfs(ri+1, r, at);
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    
    int n; cin >> n;
    p.resize(n); zep(i, 0, n)cin >> p[i];

    vector<int> v(n, n+1), w(n, n+1);
    zep(i, 0, n){
        if(i%2){
            w[i] = p[i];
        }
        else{
            v[i] = p[i];
        }
    }

    sg.push_back(segtree<int>(v));
    sg.push_back(segtree<int>(w));

    pr.resize(n/2);
    dfs(0, n, -1);

    vector<P> ans;
    priority_queue<pair<P, int>, vector<pair<P, int>>, greater<pair<P, int>>> q;
    q.push(make_pair(res[0], 0));
    while(!q.empty()){
        auto k = q.top(); q.pop();
        ans.push_back(k.first);
        zep(i, 0, pr[k.second].size()){
            int nx = pr[k.second][i];
            q.push(make_pair(res[nx], nx));
        }
    }

    zep(i, 0, n/2){
        cout << ans[i].first << " " << ans[i].second << " ";
    }cout << endl;
    return 0;
}

Measured memory_bytes: 30196
A=input()

A=list(A)

B=input()

B=list(B)

C=input()

C=list(C)

move = A.pop(0)

while True:
    if move == 'a':
        if len(A)==0:
            print('A')
            break
        else:
            move = A.pop(0)
    elif move == 'b':
        if len(B)==0:
            print('B')
            break
        else:
            move = B.pop(0)
    elif move == 'c':
        if len(C)==0:
            print('C')
            break
        else:
            move = C.pop(0)


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
long double const pi = std::acos(-1.0L);
typedef pair<int,int> P;

int main() {
  string s; cin >> s;
  string a = "CODEFESTIVAL2016";
  int cnt = 0;
  rep(i,s.size()){
    if(s[i]!=a[i]) cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <algorithm>
#include <iostream>
#include <math.h>
using namespace std;

int main(){
    int d;
    while(cin){
        cin >> d;
        if(!cin) break;
        int itg=0;
        for(int i=1;i*d<600;i++) itg+=pow(i*d,2)*d;
        cout << itg << endl;
    }
}

Measured memory_bytes: 3080
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys  # {{{
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
# }}}

# pre-defined{{{
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  # can also use string module
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
from inspect import currentframe
# }}}

def solve():
    s = input()
    if s == "ABC":
        print("ARC")
    else:
        print("ABC")

    return 0

if __name__ == "__main__":# {{{
    solve()

# vim: set foldmethod=marker: }}}


Measured memory_bytes: 79692
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
print(sum(LI()) - n)

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  int h;
  int count=0,ans=0;
  bool update=false;
  int now,num,pos;
  while(1){
    cin >> h;
    if(h==0){
      return 0;
    }
    vector<vector<int> > field = vector<vector<int> >(h,vector<int>(5,0));
    for(int i=0;i<h;i++){
      for(int j=0;j<5;j++){
        cin >> field[h-i-1][j];
      }
    }
    ans=0;
    pos=0;
    while(1){
      update=false;
      for(int i=0;i<h;i++){
        num=field[i][0];
        count=1;
        pos=0;
        for(int j=1;j<5;j++){
          if(num==field[i][j]){
            count++;
          }else{
            if(count<3){
              num=field[i][j];
              pos=j;
              count=1;
            }else{
              break;
            }
          }
        }
        if(count>=3&&num!=0){
          ans+=num*count;
          for(int j=pos;j<pos+count;j++){
            field[i][j]=0;
          }
          update=true;
        }
      }
      if(!update){
        cout << ans << endl;
        break;
      }
      for(int j=0;j<5;j++){
        now=0;
        for(int i=0;i<h;i++){
          if(field[i][j]>0){
            field[now][j]=field[i][j];
            now++;
          }
        }
        for(int i=now;i<h;i++){
          field[i][j]=0;
        }
      }
    }
  }
  return 0;
}



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

int main() {
 int a,b,c,d;
 cin >> a >> b >> c >> d;
int count1 = 0;
 while(a>0){//高橋を倒すのにかかる回数
   a -= d;
   count1++;
 }
 int count2 = 0;
 while(c>0){//あおきを倒すのにかかる回数
   c -= b;
   count2++;
 }
 if(count1<count2){//高橋のほうが青木を倒すのに時間がかかる＝負ける時
   cout << "No" << endl;
 }
 else if(count1>count2){//青木のほうがじかんがかかるとき
   cout << "Yes" << endl;
}
else if(count1 == count2){//同じときは高橋のほうが順番速いので
  cout << "Yes" << endl;
}


}


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

int main(){
  string S;
  cin>>S;
  string A[100]={"SAT","FRI","THU","WED","TUE","MON","SUN"};
  for(int i=0;i<7;i++){
    if(S==A[i]){
      cout<<i+1;
      break;
    }
  }
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int a[10],i,j,v,b,q,w;
	j=v=b=0;
	for(i=0;i<10;i++){
	scanf("%d",&a[i]);
	}
    for(i=0;i<10;i++){
		if(a[i]>j){
			j=a[i];
		    q=i;
		}
	}
		for(i=0;i<10;i++){
		if((i!=q)&&(a[i]>v)){
			v=a[i];
		    w=i;
		}
		}
		for(i=0;i<10;i++){
		if((i!=q)&&(i!=w)&&(a[i]>b))
			b=a[i];
		}
		printf("%d\n%d\n%d\n",j,v,b);
	return 0;
}

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

int main() {
  string t;
  cin >> t;
  int L = t.size();
  for(int i = 0; i < L; i++) {
    if(t[i]=='?') t[i] = 'D';
  }
  cout << t << "\n";
}

Measured memory_bytes: 3752
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
  vector<ll>to[1000005];
int main(){
  ll a,b=0;cin>>a;
  vector<ll>c(a*2-1),d(a);
  rep(i,a)cin>>d[i];
  sort(d.begin(),d.end());
  reverse(d.begin(),d.end());
  c[0]=d[0];
  for(ll i=1;i<a*2-1;i++){
    c[i]=d[i/2+1];
    i++;
    c[i]=d[i/2];
  }
  rep(i,a-1){
    b+=c[i];
  }
   cout<<b;
}



Measured memory_bytes: 31428
#include <iostream>
#include <cstdio>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());
vector<vint> vv;
int R,C;

int foo2(){
	int ret=0;
	rep(i,C){
		int a=0,b=0;
		rep(j,R){
			if(vv[j][i]==0) a++;
			else b++;
		}
		ret+=max(a,b);
	}
	return ret;
}

int foo1(int r){
	int ret;
	if(r==R){
		return foo2();
	}
	ret = foo1(r+1);
	rep(i,C){
		vv[r][i]=1-vv[r][i];
	}
	ret=max(foo1(r+1),ret);
	rep(i,C){
		vv[r][i]=1-vv[r][i];
	}
	return ret;
}



int main(){
	
	while(cin>>R>>C,R||C){
		initvv(vv,R,C);
		rep(i,R){
			rep(j,C){
				cin>>vv[i][j];
			}
		}
		cout<<foo1(0)<<endl;
	}
}

Measured memory_bytes: 1536
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main(){

    input!{
        x: [usize;5],
    }

    for i in 0..5 {
        if x[i] == 0 {
            println!("{}", i+1);
            return;
        }
    }

}

Measured memory_bytes: 2056
#include<bits/stdc++.h>
using namespace std;
#define MAX_V 25
#define INF 1<<21

int d[MAX_V][MAX_V];	//d[u][v]は辺e=(u,v)のコスト(存在しない場合はINF、ただしd[i][i]=0とする)
int n, m;	//頂点数

void warshall_floyd(){
	for(int k = 0; k < n; k++){
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}




int main(){
	for(int i = 0; i < MAX_V; i++){
		for(int j = 0; j < MAX_V; j++){
			d[i][j] = INF;
		}
	}


	cin >> n >> m;
	char c;
	for(int i = 0; i < m; i++){
		int a1, b1, c1, d1;
		cin >> a1 >> c >> b1 >> c >> c1 >> c >> d1;
		d[a1-1][b1-1] = c1;
		d[b1-1][a1-1]	= d1;	
	}
	int x1, x2, y1, y2;
	cin >> x1 >> c >> x2 >> c >> y1 >> c >> y2;
	
	warshall_floyd();
	cout << y1 - y2 - d[x1-1][x2-1] - d[x2-1][x1-1] << endl;
}
/*
ワーシャルフロイド法
*/

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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;

#define MAX_NUM (1000000007)
#define PI 3.14159265358979323846

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

template <typename T>
static inline T ArraySum(vector<T>& A) {
  T res = 0;
  for (auto itr = A.begin(); itr < A.end(); ++itr) res += *itr;
  return res;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first > b.first;
  }
}

u64 dec_dig(u64 num) {
  u64 res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}

i64 modinv(i64 a, i64 m) {
  i64 b = m, u = 1, v = 0;
  while (b) {
    i64 t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

u64 gcd(u64 a, u64 b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

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

i64 My_Comb(u64 n, u64 k, i64 m) {
  if (n < k) return 0;
  if (k == 0 || n == k) return 1;
  u64 res = 1;
  k = (n / 2 < k) ? n - k : k;
  for (u64 i = 1; i <= k; ++i)
    res = (((res * (n + 1 - i)) % m) * modinv(i, m)) % m;
  return res;
}

i64 My_Pow(u64 a, u64 n, i64 m) {
  u64 tmp = n, calc = 1;
  while (tmp > 0) {
    if (tmp % 2) {
      tmp--;
      calc *= a;
      calc %= m;
    } else {
      a *= a;
      a %= m;
      tmp /= 2;
    }
  }
  return calc;
}

class UnionFind {
 public:
  vector<u64> Par;
  vector<u64> sz;

  UnionFind(u64 n);
  u64 root(u64 x);
  bool same(u64 x, u64 y);
  void unite(u64 x, u64 y);
  u64 size(u64 x);
};

UnionFind::UnionFind(u64 n) {
  Par.resize(n);
  sz.assign(n, 1);
  for (u64 i = 0; i < n; ++i) Par[i] = i;
}

u64 UnionFind::root(u64 x) {
  if (Par[x] == x) {
    return x;
  } else {
    return Par[x] = root(Par[x]);
  }
}

bool UnionFind::same(u64 x, u64 y) { return root(x) == root(y); }

u64 UnionFind::size(u64 x) { return sz[root(x)]; }

void UnionFind::unite(u64 x, u64 y) {
  x = root(x);
  y = root(y);
  if (x == y) return;
  if (sz[x] < sz[y]) swap(x, y);
  sz[x] += sz[y];
  Par[y] = x;
}

template <typename T>
i64 BinSearch(vector<T>& V, i64 comp) {
  i64 l = 0, r = V.size() - 1;
  if (V[l] > V[r]) swap(l, r);
  if (V[l] >= comp) return l;
  if (V[r] <= comp) return r;
  while (abs(r - l) > 1) {
    i64 index = (l + r) / 2;
    if (V[index] == comp)
      return index;
    else if (V[index] > comp)
      r = index;
    else
      l = index;
  }
  if (abs(V[l] - comp) < abs(V[r] - comp))
    return l;
  else
    return r;
}
bool isPrime(u32 n) {
  if (n == 2) return true;
  if (n % 2) return false;
  for (u32 i = 3; i * i <= n; i += 2) {
    if (n % i == 0) return false;
  }
  return true;
}

int main() {
  cout << setprecision(18);
  u64 a;
  cin >> a;
  cout << a + a * a + a * a * a << endl;

  return 0;
}


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

template <typename T,typename E>
struct SegmentTree{
  using F = function<T(T,T)>;
  using G = function<T(T,E)>;
  using H = function<E(E,E)>;
  int n,height;
  F f;
  G g;
  H h;
  T ti;
  E ei;
  vector<T> dat;
  vector<E> laz;
  SegmentTree(int n_,F f,G g,H h,T ti,E ei):
    f(f),g(g),h(h),ti(ti),ei(ei){init(n_);}
  void init(int n_){
    n=1;height=0;
    while(n<n_) n<<=1,height++;
    dat.assign(2*n,ti);
    laz.assign(2*n,ei);
  }
  void build(int n_, vector<T> v){
    for(int i=0;i<n_;i++) dat[n+i]=v[i];
    for(int i=n-1;i;i--)
      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
  }
  inline T reflect(int k){
    return g(dat[k],laz[k]);
  }
  inline void eval(int k){
    if(laz[k]==ei) return;
    laz[(k<<1)|0]=h(laz[(k<<1)|0],laz[k]);
    laz[(k<<1)|1]=h(laz[(k<<1)|1],laz[k]);
    dat[k]=reflect(k);
    laz[k]=ei;
  }
  inline void thrust(int k){
    for(int i=height;i;i--) eval(k>>i);    
  }
  inline void recalc(int k){    
    while(k>>=1)
      dat[k]=f(reflect((k<<1)|0),reflect((k<<1)|1));
  }
  void update(int a,int b,E x){
    thrust(a+=n);
    thrust(b+=n-1);
    for(int l=a,r=b+1;l<r;l>>=1,r>>=1){
      if(l&1) laz[l]=h(laz[l],x),l++;
      if(r&1) --r,laz[r]=h(laz[r],x);
    }
    recalc(a);
    recalc(b);
  }
  void set_val(int a,T x){
    thrust(a+=n);
    dat[a]=x;laz[a]=ei;
    recalc(a);
  }
  T query(int a,int b){
    thrust(a+=n);
    thrust(b+=n-1);
    T vl=ti,vr=ti;
    for(int l=a,r=b+1;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,reflect(l++));
      if(r&1) vr=f(reflect(--r),vr);
    }
    return f(vl,vr);
  }
};

//INSERT ABOVE HERE
char buf[314514];
signed main(){
  int n,q;
  scanf("%d %d",&n,&q);
  scanf("%s",buf);
  string s(buf);
  
  set<int> pos;
  for(int i=0;i<n;i++)
    if(s[i]==')') pos.emplace(i);

  auto f=[](int a,int b){return min(a,b);};
  auto g=[](int a,int b){return a+b;};
  const int INF = 1e7;
  SegmentTree<int, int> seg(n,f,g,g,INF,0);

  int h=0;
  vector<int> v(n);
  for(int i=0;i<n;i++){
    if(s[i]=='(') h++;
    if(s[i]==')') h--;
    v[i]=h;
  }
  seg.build(n,v);
  
  for(int i=0;i<q;i++){
    int p;
    scanf("%d",&p);
    p--;
    if(s[p]=='('){
      s[p]=')';      
      pos.emplace(p);
      seg.update(p,n,-2);
      int a=*pos.begin();
      s[a]='(';
      pos.erase(a);
      seg.update(a,n,2);
      printf("%d\n",a+1);
    }else{
      s[p]='(';
      pos.erase(p);
      seg.update(p,n,2);
      int l=0,r=p;
      while(l+1<r){
	int m=(l+r)>>1;
	if(seg.query(m,n)>=2) r=m;
	else l=m;       
      }      
      s[r]=')';
      pos.emplace(r);
      seg.update(r,n,-2);
      printf("%d\n",r+1);
    }    
  }
  return 0;
}



Measured memory_bytes: 21176
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr ll INF = 1ll << 55;

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

// multi-dimensional vector (require c++14)
template <typename T, typename U>
static inline vector<U> make_nd_vector(T &&n, U &&val) noexcept {
  static_assert(is_integral<T>::value,
                "[make_nd_vector] 1st argument must be an integer type");
  return vector<U>(forward<T>(n), forward<U>(val));
}
template <typename T, typename... Args>
static inline decltype(auto) make_nd_vector(T &&n, Args &&... args) noexcept {
  static_assert(is_integral<T>::value,
                "[make_nd_vector] 1st argument must be an integer type");
  return vector<decltype(make_nd_vector(forward<Args>(args)...))>(
      forward<T>(n), make_nd_vector(forward<Args>(args)...));
}
//
// Print from Iterator
template <typename ite>
void print_ite(ite start, ite end, char sp = ' ', char en = '\n') {
  for (auto i = start; i != end; i++)
    cout << *i << sp;
  cout << en;
}
//
inline void Yes(bool condition) { cout << (condition ? "Yes\n" : "No\n"); }

int n;
int a[200005];
vector<int> g[200005];
int len[200005];

void dfs(int v, vector<int> &vec, int from = -1) {
  len[v] = vec.size();
  for (auto ch : g[v]) {
    if (ch != from) {
      if (a[ch] > vec.back()) {
        vec.push_back(a[ch]);
        dfs(ch, vec, v);
        vec.pop_back();
      } else {
        int idx = lower_bound(all(vec), a[ch]) - vec.begin();
        int tem = vec[idx];
        vec[idx] = a[ch];
        dfs(ch, vec, v);
        vec[idx] = tem;
      }
    }
  }
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  auto v = vector<int>({a[0]});
  dfs(0, v);
  for (int i = 0; i < n; i++) {
    cout << len[i] << '\n';
  }
}


Measured memory_bytes: 32936
n, m, x = map(int, input().split())
C = []
A = []
for _ in range(n):
    c, *a = map(int, input().split())
    C.append(c)
    A.append(a)
ans = float("inf")
for i in range(2**n):
    res = 0
    D = [0]*m
    for j in range(n):
        if i >> j & 1:
            res += C[j]
            for k, a in enumerate(A[j]):
                D[k] += a
    for d in D:
        if d < x:
            break
    else:
        ans = min(ans, res)
if ans == float("inf"):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9136
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = a[0]
small_idx = 1
small_idx_count = 0
for i in range(2, n):
    ans += a[small_idx]
    small_idx_count += 1
    if small_idx_count == 2:
        small_idx += 1
        small_idx_count = 0
    #print("small_idx is", small_idx)
    #print("small_idx_count is", small_idx_count)
print(ans)

Measured memory_bytes: 94280
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 c = sc.nextInt();

        if(a<b){
            if(b<c)System.out.printf("%d %d %d\n",a,b,c);
            else if(c<a)System.out.printf("%d %d %d\n",c,a,b);
            else System.out.printf("%d %d %d\n",a,c,b);
        }else{
            if(a<c)System.out.printf("%d %d %d\n",b,a,c);
            else if(c<b)System.out.printf("%d %d %d\n",c,b,a);
            else System.out.printf("%d %d %d\n",b,c,a);
        }
    }
}


Measured memory_bytes: 26364
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

void bfs(ll h, ll w, vector<string> &grid, vector<vll> &cnt, ll ny, ll nx) {
  if (ny + 1 < h) {
    if (grid[ny + 1][nx] == '#') {
      cnt[ny + 1][nx] = min(cnt[ny + 1][nx], cnt[ny][nx] + 1);
    }
    else {
      cnt[ny + 1][nx] = min(cnt[ny + 1][nx], cnt[ny][nx]);
    }
    bfs(h, w, grid, cnt, ny + 1, nx);
  }
  if (nx + 1 < w) {
    if (grid[ny][nx + 1] == '#') {
      cnt[ny][nx + 1] = min(cnt[ny][nx + 1], cnt[ny][nx] + 1);
    }
    else {
      cnt[ny][nx + 1] = min(cnt[ny][nx + 1], cnt[ny][nx]);
    }
    bfs(h, w, grid, cnt, ny, nx + 1);
  }
  return;
}

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

  vector<string> grid(h);
  for (ll i = 0; i < h; i++) cin >> grid[i];

  vector<vll> cnt(h, vll(w, inf));
  if (grid[0][0] == '#') cnt[0][0] = 1;
  else cnt[0][0] = 0;
  for (ll i = 0; i < h; i++) {
    for (ll j = 0; j < w; j++) {
      if (h == 0 && w == 0) continue;
      if (grid[i][j] == '#') {
        if (i > 0 && grid[i - 1][j] == '.') {
          cnt[i][j] = min(cnt[i][j], cnt[i - 1][j] + 1);
        }
        else if (i > 0) {
          cnt[i][j] = min(cnt[i][j], cnt[i - 1][j]);
        }
        if (j > 0 && grid[i][j - 1] == '.') {
          cnt[i][j] = min(cnt[i][j], cnt[i][j - 1] + 1);
        }
        else if (j > 0) {
          cnt[i][j] = min(cnt[i][j], cnt[i][j - 1]);
        }
      }
      else {
        if (i > 0) cnt[i][j] = min(cnt[i][j], cnt[i - 1][j]);
        if (j > 0) cnt[i][j] = min(cnt[i][j], cnt[i][j - 1]);
      }
    }
  }

  cout << cnt[h - 1][w - 1] << endl;
  cerr << "fuck you" << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M, C;
  cin >> N >> M >> C;
  vector<int>  B(M);
  vector<vector<int>>  A(N, vector<int>(M));
  for (int i = 0; i < M; i++){
    cin >> B.at(i);
  }
  for (int i = 0; i < N; i++){
    for (int j = 0; j < M; j++){
      cin >> A.at(i).at(j);
    }
  }
  int sum;
  int number = 0;
  for (int i = 0; i < N; i++){
    sum = 0;
    for (int j = 0; j < M; j++){
      sum += A.at(i).at(j) * B.at(j);
    }
    if (sum + C >0){
      number++;
    }
  }
  cout << number << endl;
}

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


using namespace std;

int main(int argc, char** argv) {
	string name,num;
	cin>>name;
	
	for(int i=0;i<name.length();i++)
	{
		if(name[i]=='0')
		 num.push_back('0');
		else if(name[i]=='1')
		 num.push_back('1');
		else if(name[i]='B'&& num.empty()!=true)
		 num.pop_back();
		 
	}
	cout<<num<<endl;
	
	return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int f(int n){
    	for(int i=0;i<1000;i++){
        	if(n%2==1) return i;
            else n/=2;
        }
   
}
int main(){
	int n,a,ans=100000;
    cin>>n;
    for(int i=0;i<n;i++){
    	cin>>a;
        ans=min(ans,f(a));
    }
  cout<<ans;
}

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

int main() {
  int n;
  std::cin >> n;

  std::vector<int> hn(n);
  for (auto &h : hn) {
    std::cin >> h;
  }

  std::string result = "Yes";

  for (int i = 0; i < n - 1; ++i) {
    if (hn[i] <= hn[i + 1]) {
      if (i > 0) {
        if (hn[i - 1] < hn[i]) {
          --hn[i];
        }
      }
      continue;
    }

    if ((hn[i] - 1) <= hn[i + 1]) {
      if (i > 0) {
        if (hn[i - 1] <= (hn[i] - 1)) {
          --hn[i];
        } else {
          result = "No";
          break;
        }
      } else {
        --hn[i];
      }
      continue;
    } else {
      result = "No";
      break;
    }
  }

  std::cout << result << std::endl;

  return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <stack>
#include <vector>
using namespace std;

int main() { 
  int s = 0;
  char c;
  stack<int> S1;
  stack<pair<int, int> > S2;
  for (int i = 0; (c = getchar()) != EOF; i++) {
    switch (c) {
      case '\\':
        S1.push(i);
        break;
      case '/':
        if (S1.empty()) {
          break;
        } else {
          int j = S1.top(); S1.pop();
          s += i - j;
          int a = i - j;
          while (!S2.empty() &&S2.top().first > j) {
            a += S2.top().second; S2.pop();
          }
          S2.push(make_pair(j, a));
        } 
    }
  }
  printf("%d\n%d", s, (int)S2.size());
  vector<int> ans;
  while (!S2.empty()) {ans.push_back(S2.top().second); S2.pop();}
  while (!ans.empty()) {printf(" %d", ans.back()); ans.pop_back();}
  printf("\n");
  return 0;
}

Measured memory_bytes: 2784