akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#define MAX 10000
#define NIL -1

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

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

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

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

// 節点uの兄弟を返す
int getSibling(int u) {
    if (T[u].parent == NIL) return NIL;
    if (T[T[u].parent].left != u && T[T[u].parent].left != NIL) return T[T[u].parent].left;
    if (T[T[u].parent].right != u && T[T[u].parent].right != NIL) return T[T[u].parent].right;
    return NIL;
}

void print(int u) {
    printf("node %d: ", u);
    printf("parent = %d, ", T[u].parent);
    printf("sibling = %d, ", getSibling(u));
    int deg = 0;
    if (T[u].left != NIL) deg++;
    if (T[u].right != NIL) deg++;
    printf("degree = %d, ", deg);
    printf("depth = %d, ", D[u]);
    printf("height = %d, ", H[u]);

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

int main() {
    int v, l, r, root = 0;
    scanf("%d", &n);

    for (int i = 0; i < n; i++) T[i].parent = NIL;

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

    for (int i = 0; i < n; i++) if (T[i].parent == NIL) root = i;

    setDepth(root, 0);
    setHeight(root);

    for (int i = 0; i < n; i++) print(i);

    return 0;
}


Measured memory_bytes: 2740
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ans = 0;
  string s;

  cin >> s;

  for(int i = 0;i < 4;i++){
    if(s[i] == '-'){
      ans --;
    }else{
      ans ++;
    }
  }

  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
nm = input().split()
n = int(nm[0])
m = int(nm[1])

ablist = []
for i in range(m):
    ab = input().split()
    ablist.append((int(ab[0]), int(ab[1])))
ablist.reverse()

class Group:
    def __init__(self):
        self.count = 1
        self.ptr = None
        self.depth = 0

    def get_top_group(self):
        group = self
        while True:
            if not group.ptr:
                return group
            group = group.ptr


vertexes = {}
for i in range(n):
    vertexes[i + 1] = Group()


count_history = [(n * (n - 1)) // 2]

for a, b in ablist:
    group_a = vertexes[a].get_top_group()
    group_b = vertexes[b].get_top_group()
    depth_a = group_a.depth
    depth_b = group_b.depth
    count_a = group_a.count
    count_b = group_b.count

    if group_a == group_b:
        count_history.append(count_history[-1])
        continue

    prev = count_history[-1]
    count_history.append(prev - count_a * count_b)

    if depth_a < depth_b:
        group_a.ptr = group_b
        group_b.count += group_a.count
    if depth_a > depth_b:
        group_b.ptr = group_a
        group_a.count += group_b.count
    if depth_a == depth_b:
        group_a.ptr = group_b
        group_b.depth += 1
        group_b.count += group_a.count


count_history.reverse()
count_history.pop(0)
for count in count_history:
    print(count)


Measured memory_bytes: 47596
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    int res = 0;
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    for (int i = 1; i < s.size(); i++) {
        if (s[i - 1] == s[i]) res++;
    }
    cout << (res == 0 ? "yes" : "no") << endl;
}


Measured memory_bytes: 256
def solve():
    N, M = list(map(int, input().split()))
    H = list(map(int, input().split()))
    R = []
    for _ in range(M):
        R.append(list(map(int, input().split())))
    Check_array = [1 for _ in range(N)]
    for r in R:
        if(H[r[0]-1] < H[r[1]-1]):
            Check_array[r[0] - 1] = 0
        elif (H[r[0]-1] > H[r[1]-1]):
            Check_array[r[1] - 1] = 0
        else:
            Check_array[r[0] - 1] = 0
            Check_array[r[1] - 1] = 0
    print(sum(Check_array))


if __name__ == "__main__":
    solve()


Measured memory_bytes: 101492
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math") 
///#pragma GCC target("avx2")
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <functional>
#include <ctime>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <climits>
#include <numeric>

using namespace std;
#define open_streams ifstream fin("olympiad.in");ofstream fout("olympiad.out")
#define close_streams fin.close();fout.close()
#define speed cout.tie(0);cin.tie(0);ios_base::sync_with_stdio(0)
#define ll long long
#define ull unsigned long long
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define UNIQ(a) a.resize(unique(all(a)) - a.begin())
#define eps 1e-6
//const double PI = M_PI;
const int INF = INT_MAX;
const ll limit = 1LL * 4e18;
const int MOD = 1e9 + 711;
const int MOD2 = 1e9 + 933;
//---------------------------------------------------------------------------
const int mod = 1e9 + 7;
const int maxn = 1e5 + 100;



signed main() {
	speed;
	bool ok = true;
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int x;
		cin >> x;
		if (x % 2 == 0) {
			if (x % 3 && x % 5) {
				ok = false;
			}
		}
	}
	cout << (ok ? "APPROVED" : "DENIED");
	return 0;
}

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

#define ll long long
#define f first
#define s second

int main() {
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < s.size(); i++) {
        if (s == t) {
            cout << "Yes";
            return 0;
        }
        string c;
        c += s[s.size() - 1];
        s.erase(s.end() - 1);
        s.insert(0, c);
    }
    cout << "No";
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n=I()
if n<105:
    ans=0
elif n<135:
    ans=1
elif n<165:
    ans=2
elif n<189:
    ans=3
elif n<195:
    ans=4
else:
    ans=5
print(ans)

Measured memory_bytes: 3316
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    String c = sc.next();
   
        System.out.print(a.charAt(0));
        System.out.print(b.charAt(1));
        System.out.print(c.charAt(2));
    }
}

Measured memory_bytes: 35628
import java.util.Scanner;

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

        int a = sc.nextInt();
        sc.nextLine();
        String s = sc.nextLine();
        sc.close();

        System.out.println(a < 3200 ? "red" : s);
    }
}

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

int main(){
  string S; cin >> S;
  int k=S.size();
  if(k%2!=0){
    cout << "No" << endl;
    return 0;
  }
  for(int i=0;i<k;i+=2){
    if(S[i]!='h' || S[i+1]!='i'){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int na, nt, ng, nc;
vector<string> str;
map<string, vector<string> > dict;
map<string, vector<string> > dict0;

int dp[55][55][55][55];
bool used[55][55][55][55];

void fail() {
  cout << 0 << endl;
  exit(0);
}

void solve(const string& sa) {
  if(dict0.count(sa)) return;
  for(const string& s : dict[sa]) {
    if(s[0] == '[') dict0[sa].push_back(s);
    else {
      solve(s);
      auto v = dict0[s];
      dict0[sa].insert(dict0[sa].end(), v.begin(), v.end());
      if((int)dict0[sa].size() > na+nt+ng+nc) fail();
    }
  }
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> na >> nt >> ng >> nc;
  int m;
  cin >> m;
  resz(str, m);
  cin.ignore();
  rep(i, m) {
    string buf;
    getline(cin, buf);
    stringstream ss(buf);
    ss >> str[i];
    str[i].pop_back();
    string tmp;
    while(ss >> tmp) dict[str[i]].push_back(tmp);
  }
  solve(str[0]);
  auto v = dict0[str[0]];
  if((int)v.size() != na+nt+ng+nc) fail();
  struct State {
    int a, t, g, c;
    State(){}
    State(int a, int t, int g, int c):a(a), t(t), g(g), c(c){}
  };
  str.clear();
  dict.clear();
  dict0.clear();
  queue<State> que;
  que.emplace(0, 0, 0, 0);
  dp[0][0][0][0] = 1;
  while(!que.empty()) {
    State st = que.front(); que.pop();
    int idx = st.a+st.t+st.g+st.c;
    if(idx >= (int)v.size()) continue;
    const string& s = v[idx];
    //cout<<s<<endl;
    reps(i, 1, (int)s.size()-1) {
      State nxt = st;
      if(s[i] == 'A') ++nxt.a;
      else if(s[i] == 'T') ++nxt.t;
      else if(s[i] == 'G') ++nxt.g;
      else if(s[i] == 'C') ++nxt.c;
      else continue;
      if(nxt.a > na || nxt.t > nt || nxt.g > ng || nxt.c > nc) continue;
      (dp[nxt.a][nxt.t][nxt.g][nxt.c] += dp[st.a][st.t][st.g][st.c]) %= mod;
      if(used[nxt.a][nxt.t][nxt.g][nxt.c]) continue;
      used[nxt.a][nxt.t][nxt.g][nxt.c] = true;
      que.push(nxt);
    }
  }
  cout << dp[na][nt][ng][nc] << endl;

  return 0;
}



Measured memory_bytes: 71804
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <functional>
#include <set>
#include <tuple>
#include <map>
#include <numeric>

using namespace std;
#define PI 3.14159265359
#define ll long long int

int main(void)
{
    ll H, N;
    cin >> H >> N;
    vector<ll> A;
    for(ll i = 0; i < N; i++){
        ll temp;
        cin >> temp;
        A.push_back(temp);
    }

    ll total = accumulate(A.begin(), A.end(), 0);

    if(total >= H) cout << "Yes" << endl;
    else cout << "No" << endl;



    return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
using namespace std;

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

int main(){
    int n;
    cin >> n;
    vector<pii> v[n];
    for(int i = 0; i < n-1; i++){
        int a, b;
        cin >> a >> b;
        a--, b--;
        v[a].push_back({b, i});
        v[b].push_back({a, i});
    }
    
    ll num[n][n];
    for(int i = 0; i < n; i++){
        vector<bool> vis(n, 0);
        num[i][i] = 0;
        queue<int> q;
        q.push(i);
        vis[i] = true;
        while(!q.empty()){
            int x = q.front();  q.pop();
            for(pii p : v[x]){
                if(vis[p.first])    continue;
                vis[p.first] = true;
                num[i][p.first] = num[i][x] + (1ll<<p.second);
                q.push(p.first);
            }
        }
    }
    int m;
    cin >> m;
    vector<pii> vp(m);
    for(int i = 0; i < m; i++){
        cin >> vp[i].first >> vp[i].second;
        vp[i].first--, vp[i].second--;
    }
    ll ans = 1ll<<(n-1);
    for(int i = 1; i < 1<<m; i++){
        int popcnt = 0;
        ll allwhite = 0;
        for(int j = 0; j < m; j++){
            if((i>>j&1) == 0)    continue;
            popcnt++;
            allwhite |= num[vp[j].first][vp[j].second];
        }
        ll ppcnt = 0;
        for(int j = 0; j < n; j++)  ppcnt += (allwhite>>j)&1;
        ans += (popcnt%2 == 0 ? 1 : -1)*(1ll<<(n-1-ppcnt));
    }
    cout << ans << endl;
    return 0;
}

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

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

 for(int i=0;i<N;i++){
	int x,y,b,p;
	cin>>x>>y>>b>>p;

	int f1=x*b+y*p;

	if(b<5){
		b=5;
	}
	if(p<2){
		p=2;
	}
	int f2=(x*b+y*p)*4/5;

	if(f1<f2){
		cout<<f1<<endl;
	}
	else{
		cout<<f2<<endl;
	}
 }
 return 0;
}

Measured memory_bytes: 3112
#include<iostream>
using namespace std;
int main(){
    int N,M;
    int i,total=0;
    int P,X;
    int *T;
    cin >> N;
    T = new int[N];
    for(i=0;i<N;i++){
        cin >> T[i];
        total += T[i];
    }
    cin >> M;
    for(i=0;i<M;i++){
        cin >> P >> X;
        cout << total + X - T[P-1] <<endl;
    }
    delete[] T;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
map<ll int,ll int> m;
int main()
{
	ll int n;
	cin>>n;
	ll int a[n];
	for (ll int i = 0; i < n; ++i)
	{
		cin>>a[i];
		m[a[i]]++;
	}
	ll int sum=0;
	for(auto x : m){
		if(x.second > 1){
			sum+=(x.second)*(x.second-1);
		}
	}
	sum/=2;
	for (ll int i = 0; i < n; ++i)
	{
		if(m[a[i]] > 1)
			cout<<sum-m[a[i]]+1;
		else
			cout<<sum;
		cout<<"\n";
	}
}

Measured memory_bytes: 11008
D = int(input())
c_list = list(map(int,input().split(' ')))
s_list = []
for i in range(D):
    s_list.append(list(map(int,input().split(' '))))
minc = c_list.index(min(c_list))
for day in range(D):
    maxs = s_list[day].index(max(s_list[day]))
    print(maxs+1)


Measured memory_bytes: 9336
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
typedef long long int lli;

int main(void){
	lli a,b,c;
	scanf("%lld%lld%lld",&a,&b,&c);
	if(!(a%2) || !(b%2) || !(c%2)){
		printf("%d\n", 0);
	}else{
		if(a >= b && a >= c){
			printf("%lld\n",b*c);
		}else if(b >= a && b >= c){
			printf("%lld\n", a*c);
		}else if(c >= a && c >= b){
			printf("%lld\n", a*b);
		}
	}
	return 0;
}

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

pair<long long,long long> cost_bottle[100010];
int main() {
	long long n, m, a, b;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		cost_bottle[i].first = a, cost_bottle[i].second = b;
	}
	sort(cost_bottle, cost_bottle + n);
	long long bottle = 0, cost = 0;
	for (int i = 0; i < n; i++) {
		bottle += cost_bottle[i].second;
		if (bottle > m) {
			bottle -= cost_bottle[i].second;
			cost += (m-bottle)*cost_bottle[i].first;
			break;
		}
		cost += cost_bottle[i].first*cost_bottle[i].second;
	}
	cout << cost << endl;
	return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
#define fir first
#define sec second

const int INF = 1e9 + 10;
//const ll INF = 1e18 + 10LL;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
const double EPS = 1e-10;
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)
ll MOD = 1e9 + 7;

string S;
int a[100010];

void solve() {
	char c = S[0];
	int sz = S.size();
	int idx = 0;
	for (int s = 0; s < sz;) {
		while (idx < sz && S[idx] == c) idx++;
		int r = idx - s;

		if (c == 'R') {
			a[idx - 1] += (r + 1) / 2;
			a[idx]     += r / 2;
		} else {
			a[s - 1]   += r / 2;
			a[s]	   += (r + 1) / 2;
		}

		s = idx;
		c = (c == 'L' ? 'R' : 'L');
	}

	for (int i = 0; i < sz; i++) {
		cout<< a[i] << " ";
	}cout<<endl;
}

int main(void){
	cin>>S;

	solve();
	
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void)
{
	int i,n,t,a,h,m,s,sum,max;
	scanf("%d",&n);
	scanf("%d",&t);
	scanf("%d",&a);
	a=a*1000;
	max=1000000000;
	for(i=1;i<=n;i++){
		scanf("%d",&h);
		m=1000*t-h*6;
		sum=m-a;
		if(sum<0){
			sum=-sum;
		}
		if(sum<max){
			max=sum;
			s=i;
		}
	}
	printf("%d\n",s);
	return 0;
}

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

void solve(long long X)
{
    ll deposit = 100;
    ll ans = 0;
    while (deposit < X) {
        ans++;
        deposit = deposit * 101.0 / 100;
    }
    cout << ans << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
// clang-format off
int main(){
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 3664
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int N, M;
int b[100000];
bool f[100000];

int main(int argc, char **argv) {
	cin >> N >> M;
	REP(i, N) {
		b[i] = 1;
		f[i] = false;
	}
	f[0] = true;
	REP(i, M) {
		int x, y;
		cin >> x >> y;
		--x; --y;
		--b[x]; ++b[y];
		f[y] |= f[x];
		if (b[x] == 0) f[x] = false;
	}
	int res = 0;
	REP(i, N) if (f[i]) ++res;
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 768
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    int p;

    int[][] a = new int[3][3];
    boolean[][] b = new boolean[3][3];

    for(int i=0; i<3; i++){
      for(int j=0; j<3; j++){
        a[i][j] = sc.nextInt();
      }
    }
    int n = sc.nextInt();
    for(int i=0; i<n; i++){
      p = sc.nextInt();
      for(int j=0; j<3;j++){
        for(int k=0; k<3;k++){
          if(a[j][k]==p){
            b[j][k] = true;
          }
        }
      }
    }

    for(int i=0; i<3; i++){
      if(b[i][0] && b[i][1] && b[i][2] == true){
        System.out.println("Yes");
        System.exit(0);
      }
    }
    for(int i=0; i<3; i++){
      if(b[0][i] && b[1][i] && b[2][i] == true){
        System.out.println("Yes");
        System.exit(0);
      }
    }
    if(b[0][0]&&b[1][1]&&b[2][2]==true){
      System.out.println("Yes");
      System.exit(0);
    }
    if(b[0][2]&&b[1][1]&&b[2][0]==true){
      System.out.println("Yes");
      System.exit(0);
    }

    System.out.println("No");


  }

}

Measured memory_bytes: 23636
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iostream>
#include<cstring>
using namespace std;
template<class _T>inline void read(_T &_a)
{
    bool f=0; char _c=getchar(); _a=0;
    while(_c<'0'||_c>'9'){ if(_c=='-') f=1; _c=getchar(); }
    while(_c>='0'&&_c<='9'){ _a=(_a<<3)+(_a<<1)-'0'+_c; _c=getchar(); }
    if(f) _a=-_a;
}

double a,b,h,m,ans,degm,degh,deltadeg;

int main()
{
    scanf("%lf%lf%lf%lf",&a,&b,&h,&m);
    degm=m*6;
    degh=h*30+(m/2);
    if(degm>degh) deltadeg=degm-degh;
    else deltadeg=degh-degm;
    if(deltadeg>180) deltadeg=360-deltadeg;
    ans=sqrt(a*a+b*b-2*a*b*cos(deltadeg*acos(-1)/180));
    printf("%.20lf",ans);
    return 0;
}

Measured memory_bytes: 4152
#include <iostream> // cout, endl, cin
#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
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif


int main(void) {
    int num;
    cin >> num;
    vector<int> arr(num);
    cins(arr);

    vector<int> map(2);
    for(int i = 0; i < num; i++) {
        map[arr[i]%2]++;
    }
    cout << (map[1]%2==0 ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 3708
#include <stdio.h>
#define N 200
      
int main(){
int a[N][3],b[N][3],n,i,j,k;
int kekka[N];
scanf("%d",&n);
for(i=0;i<n;i++){
kekka[i]=0;
for(j=0;j<3;j++){
scanf("%d",&a[i][j]);
b[i][j]=a[i][j];
}
}
for(j=0;j<3;j++){
for(i=0;i<n;i++){
for(k=0;k<n;k++){
if(i==k) continue;
if(a[i][j]==b[k][j]){
a[i][j]=0;
break;
}
}
}
}
for(i=0;i<n;i++){
kekka[i]=a[i][0]+a[i][1]+a[i][2];
printf("%d\n",kekka[i]);
}
return 0;
}

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

// region template
#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 sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

const int nmax = (1 << 15) + 5;

int cnt[nmax];

double l[25], a[25], b[25];
double sqr(double x) { return x * x; }

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    int n, m; cin >> n >> m;

    rep(i, 0, n) cin >> l[i] >> a[i] >> b[i];

    double maxv = 0;
    rep(mask, 0, (1 << n)) if (__builtin_popcount(mask) == m) {
        double v = 0;
        rep(i, 0, n) rep(j, i + 1, n) if ((mask & (1 << i)) && (mask & (1 << j)))
            v += sqr(l[i] - l[j]) + sqr(a[i] - a[j]) + sqr(b[i] - b[j]);
        maxv = max(maxv, v);
    }
    cout << fixed << setprecision(12) << maxv << endl;
}


Measured memory_bytes: 3312
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int solve(const vecint& ary) {
  bool parity = false;
  int n = ary.size();
  int n1 = n-1;
  REP(i,n) {
    if (ary[i] == 1) {
      if ((n1&i) == i) parity = !parity;
    }
  }
  return parity ? 1 : 0;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin>>n;
  string s;
  cin>>s;
  vector<int> ary(n);
  REP(i,n) ary[i] = s[i] - '1';
  bool ex1 = false;
  REP(i,n) if (ary[i] == 1) ex1 = true;
  if (!ex1) {
    REP(i,n) ary[i] >>= 1;
    cout << solve(ary) * 2 << endl;
  } else {
    cout << solve(ary) << endl;
  }
  return 0;
}


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

using namespace std;

#define REP(var, n)  for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

#define all(c) begin(c),end(c)

template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}

const int INF = 1 << 29;

auto solve() {
    int N;
    cin >> N;

    vector<vi> edges(N);
    REP(i, N - 1) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }

    // kind of dijkstra
    vi d(N, INF);
    d[0] = 0;
    vi bef(N, -1);
    function<void(int, int)> best_route = [&](int n, int v) {
        d[n] = v;
        for (auto &&e : edges[n]) {
            if (d[e] == INF) {
                bef[e] = n;
                best_route(e, v + 1);
            }
        }
    };

    best_route(0, 0);

    // traverse
    vi route;
    {
        int v = N - 1;
        while (v != 0) {
            route.push_back(v);
            v = bef[v];
        }
        route.push_back(0);
        reverse(all(route));
    }

    // find #way
    function<int(int, int, int)> num_way = [&](int n, int next, int prev) {
        int v = 1;
        for (auto &&e : edges[n]) {
            if (e != next && e != prev) {
                v += num_way(e, -1, n);
            }
        }
        return v;
    };

    int fen_res = 0;
    REP(i, (route.size() + 1) / 2) {
        int cur, prev, nex;
        cur = route[i];
        if (i == 0)
            prev = -1;
        else
            prev = route[i - 1];
        nex = route[i + 1];

        fen_res += num_way(cur, nex, prev);
    }

    int snuke_res = 0;
    FOR(i, (route.size() + 1) / 2, route.size()) {
        int cur, prev, nex;
        cur = route[i];
        prev = route[i - 1];
        if(i == route.size()-1) nex = -1;
        else nex = route[i + 1];

        snuke_res += num_way(cur, nex, prev);
    }

    if(fen_res > snuke_res) {
        return "Fennec";
    } else {
        return "Snuke";
    }
}


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

    cout << solve() << endl;
//    solve();
    return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define ford(i, a, n) for (int i = (int)(n - 1); i >= (int)(a); --i)
#define fore(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

template<typename T>
inline void setmax(T& a, T b) {
    if (a < b) a = b;
}

template<typename T>
inline void setmin(T& a, T b) {
    if (a > b) a = b;
}

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

void win() {
    cout << "Yes\n";
    exit(0);
}

void fail() {
    cout << "No\n";
    exit(0);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(3);
    forn(i, 0, n) {
        int x;
        cin >> x;
        if (x % 4 == 0) ++a[2];
        else if (x % 2 == 0) ++a[1];
        else ++a[0];
    }
    if (a[1] == n) win(); 
    if (a[1]) ++a[0];
    if (a[2] == 0) fail();
    if (a[2] >= a[0] - 1) win();
    fail();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll unsigned long long int
using namespace std;
ll inf=1000000000000000000;
int main()
{	
	ll n;
	cin>>n;
	if(n&1)
	{cout<<0;
	return 0;
	}
	ll c=0;
	for(ll i=5;2*i<=n;i*=5)
		c+=n/(2*i);
	cout<<c<<endl;
	
	
		
}


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

typedef long long ll;

#define FOR(i,s,e) for(int i = (s);i <= (e);i++)
#define MOD(N) ((N) % 1000000007LL)

string U;
string D;

int N;

ll result;

int types[52];
int types_end = 0;


int main()
{
	cin >> N;
	cin >> U;
	cin >> D;

	FOR(i,0,N - 1)
	{
		if(U[i] == D[i])
		{
			types[types_end] = 1;
		}
		else
		{
			types[types_end] = 2;
			i++;
		}
		types_end++;
	}

	result = 3;
	if(types[0] == 1) result *= 1;
	else result *= 2;
	FOR(i,1,types_end - 1)
	{
		int b = types[i - 1];
		int n = types[i];
		if(b == 1)
		{

			result = MOD(result * 2);
		}
		else
		{
			if(n == 2)
			{
				result = MOD(result * 3);
			}
		}
	}

	cout << result << endl;
	return 0;
}


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

int main() {
  int n, i, ans = 0;
  cin >> n;
  
  while(n > 0){
    ans += n % 10;
    n /= 10;
  }
  
  if(ans == 1) cout << 10 << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        double dMax = Double.MIN_VALUE;
        double dMin = Double.MAX_VALUE;
        //
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int a[] = new int[n];
        double fm = 0;
        for (int i=0;i<n;++i)
        {
            int aa = sc.nextInt();
            fm += aa;
            a[i] = aa;
        }
        double kyokai = fm/(4*m);

        for (int i=0;i<n;++i) if (a[i] >= kyokai) ++count;
        System.out.println(count >= m ? "Yes" : "No");
        sc.close();
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<string>
#include<climits>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<queue>
 
 
int main(){
	int n, k;
	long long ans= 0; 
	std::vector<long long> vList;

	std::cin>>n>>k;
	vList.resize(n);

	for(int i=0; i<n; i++)
		std::cin>>vList[i];

	int maxIter= std::min(n, k);

	for(int iter=0; iter<=maxIter; iter++){
		for(int left=0; left<=iter; left++){
			std::priority_queue<long long, std::vector<long long>, std::greater<long long>> q;
			long long sum= 0;

			for(int i=0; i<left; i++){
				q.push(vList[i]);
				sum+= vList[i];
			}

			for(int i=0; i<iter-left; i++){
				q.push(vList[n-i-1]);
				sum+= vList[n-i-1];
			}

			for(int i=0; i<k-iter; i++){
				if(q.empty() || q.top()>0 )
					break;

				sum-= q.top();
				q.pop();
			}

			ans= std::max(ans, sum);
		}
	}


	std::cout<<ans<<std::endl;
 
	return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  zero
//
//  Created by 叶金炜 on 2019/4/2.
//  Copyright © 2019 okstal. All rights reserved.
//

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string.h>
#define pi acos(-1)
using namespace std;
int main()
{
    int n,m;
    int a[107][107];
    memset(a, 0, sizeof(a));
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        {
            cin>>a[i][j];
            a[i][m+1]+=a[i][j];
            a[n+1][j]+=a[i][j];
        }
    for(int j=1;j<=m;j++)a[n+1][m+1]+=a[n+1][j];
    for(int i=1;i<=n+1;i++)
        for(int j=1;j<=m+1;j++)
        {
            if(j==m+1)cout<<a[i][j]<<endl;
            else cout<<a[i][j]<<" ";
        }
    return 0;
}



Measured memory_bytes: 3120
#include <iostream>
#include <stdio.h>
#include <map>
#include <vector>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
#define lowbit(k) k&-k
#define pi	3.1415926535
const int INF = 0x3f3f3f3f;
string s[101];
int len[101];
int main()
{
	int t;
	cin >> t;
	for (int i = 0; i < t; i++)
	{
		cin >> s[i];
		len[i] = s[i].size();
	}
	int flag = 1;
	for (int i = 1; i < t; i++)
	{
		if (s[i][0] != s[i - 1][len[i - 1] - 1])
		{
			flag = 0;
			break;
		}
		for (int j = 0; j < i; j++)
		{
			if (s[i] == s[j])
			{
				flag = 0;
				break;
			}
		}
	}
	if (!flag)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mp make_pair
typedef pair<int,int> pii;
ll a[200009];
ll n;ll k;
int main()
{
    scanf("%d%lld",&n,&k);
    for(int i=0;i<n;i++)scanf("%lld",&a[i]);
    sort(a,a+n);
    ll l=-1e18,r=1e18;
    ll answer;
    while(l<=r)
    {
        ll mid=(l+r)/2;ll cnt=0;
        for(int i=0;i<n;i++)
        {
            if(a[i]>0){
                cnt+=upper_bound(a,a+n,(long double)mid/a[i])-a;
            }
            else if(a[i]<0){
                cnt+=n-(lower_bound(a,a+n,(long double)mid/a[i])-a);
            }
            else if(mid>=0)cnt+=n;
            if(a[i]*a[i]<=mid)cnt--;
        }
        if(cnt>=k*2)answer=mid,r=mid-1;
        else l=mid+1;
    }
    cout<<answer<<endl;
    return 0;
}

Measured memory_bytes: 1792
// +build ignore
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []byte {
	return []byte(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

func gcd(x, y int) int {
	if x%y != 0 {
		return gcd(y, x%y)
	}
	return y
}

func run(input io.Reader, output io.Writer) int {
	sc := NewScanner()
	x := sc.nextInt()

	if x < 1200 {
		fmt.Println("ABC")
	} else {
		fmt.Println("ARC")
	}

	return 0
}

func main() {
	os.Exit(run(os.Stdin, os.Stdout))
}


Measured memory_bytes: 640
#include<iostream>

using namespace std;;

int main(){
    int a,b,i,d=0,count=0;
    cin >> a;
    int c[a];
    for(i=0;i<a;i++){
      cin >> c[i];
    }
  
  while(1){
    for(i=0;i<a;i++){
      if(c[i]%2==1){
        d=1;
        break;
      }
      c[i]=c[i]/2;
    }
    
    if(d==1){
      break;
    }
    count++;
  }
  cout<<count;
}

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

int N,Q,D;
int d[500010];
int can[500010];
int im[500010];

int main()
{
    scanf("%d%d",&N,&D);
    for(int i = 0; i < N; i++)scanf("%d",&d[i]);
    can[0] = D;
    for(int i = 1; i < N; i++)
        can[i] = min(can[i - 1],abs(can[i - 1] - d[i - 1]));
    d[N] = 0;
    im[N] = 1;
    for(int i = N - 1; i >= 0; i--)
    {
        if(abs(im[i + 1] - d[i + 1]) < im[i + 1])im[i] = im[i + 1] + d[i + 1];
        else im[i] = im[i + 1];
    }
    scanf("%d",&Q);
    for(int i = 0; i < Q; i++)
    {
        int q;
        scanf("%d",&q);
        if(can[q - 1] >= im[q - 1])printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}


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

int main()
{
    int n;          //データセットの数
    int a, b, c;    //各辺の長さ
    cin >> n;

    priority_queue<int> *qs = new priority_queue<int>[n];

    for(int i = 0; i < n; ++i){
        cin >> a >> b >> c;
        qs[i].push(a);
        qs[i].push(b);
        qs[i].push(c);
    }

    for(int i = 0; i < n; ++i){
        c = qs[i].top();
        qs[i].pop();
        a = qs[i].top();
        qs[i].pop();
        b = qs[i].top();
        if(pow(c, 2) == pow(a, 2) + pow(b, 2))
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 1268
import java.util.*;
import static java.lang.Math.*;
public class Main {
	final Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main().init();
	}
	void init(){
		new AOJ1141();
	}
	
	class AOJ1141{
		boolean[] isNotPrime;
		AOJ1141(){
			isNotPrime=sieve(1000000);
			while(sc.hasNext()){
				int a=sc.nextInt(),d=sc.nextInt(),n=sc.nextInt();
				if((a|(d|n))==0)	break;
				solve(a,d,n);
			}
		}
		void solve(int a,int d,int n){
			int cnt=0;
			for(int i=a; i<=1000000; i+=d){
				if(!isNotPrime[i])	++cnt;
				if(cnt==n){
					System.out.println(i);
					break;
				}
				
			}
		}
		boolean[] sieve(int MAX){
			boolean[] isNotPrime=new boolean[MAX+1];
			isNotPrime[1]=true;
			for(int i=2; i*i<=MAX; ++i){
				if(!isNotPrime[i])for(int j=i+i; j<=MAX; j+=i)	isNotPrime[j]=true;
			}
			return isNotPrime;
		}
	}
	
	class AOJ1142{
		AOJ1142(){
			int n=sc.nextInt();
			while(--n>=0)	solve();
		}
		void solve(){
			StringBuilder line=new StringBuilder(sc.next());
			HashSet<String> set=new HashSet<String>();
			set.add(line.toString());
			for(int i=1; i<=line.length(); ++i){
				String s1=line.substring(0, i),
						s2=line.substring(i, line.length());
				String s1r=new StringBuilder(s1).reverse().toString(),
						s2r=new StringBuilder(s2).reverse().toString();
				set.add(s1+s2r);
				set.add(s1r+s2);
				set.add(s1r+s2r);
				set.add(s2+s1);
				set.add(s2+s1r);
				set.add(s2r+s1);
				set.add(s2r+s1r);
			}
//			System.out.println(set);
			System.out.println(set.size());
		}
	}
	
	class AOJ1144{
		AOJ1144(){
			while(sc.hasNext()){
				w=sc.nextInt();
				h=sc.nextInt();
				if((w|h)==0)	break;
				solve(w,h);
			}
		}
		final int INF=Integer.MAX_VALUE/4;
		final int[] vx={0,1,0,-1},vy={-1,0,1,0};
		int w,h;
		int sx,sy,ex,ey;
		void solve(int w,int h){
			boolean[][] b=new boolean[w][h];
			sx=0;	sy=0;	ex=0;	ey=0;
			for(int y=0; y<h; ++y)for(int x=0; x<w; ++x){
				int tmp=sc.nextInt();
				b[x][y]=(tmp!=1);
				if(tmp==2){
					sx=x;	sy=y;
				}else if(tmp==3){
					ex=x;	ey=y;
				}
			}
			
			int ans=-1;
			for(int cnt=0; cnt<=10; ++cnt){
				boolean[][] bc=new boolean[w][h];
				for(int x=0; x<w; ++x)for(int y=0; y<h; ++y)	bc[x][y]=b[x][y];
				int ret=DFS(sx,sy,0,cnt,bc);
				if(ret<INF){
					ans=ret;
					break;
				}
			}
			System.out.println(ans);
		}
		int DFS(int x,int y,int depth,int limit,boolean[][] b){
//			System.out.println(x+" "+y+" "+depth+" "+limit);
			if(depth>=limit)	return INF;
			if(x==ex&&y==ey)	return depth;
			
			int ret=INF;
			for(int v=0; v<4; ++v){
				int xx=x+vx[v],yy=y+vy[v];
				if(!(0<=xx&&xx<w && 0<=yy&&yy<h))	continue;
				if(!b[xx][yy])	continue;
				if(xx==ex&&yy==ey){
					ret=min(ret,depth+1);
					continue;
				}
				while(true){
					xx+=vx[v];
					yy+=vy[v];
					if(!(0<=xx&&xx<w && 0<=yy&&yy<h))	break;
					if(xx==ex&&yy==ey){
						ret=min(ret,depth+1);
						break;
					}
					if(!b[xx][yy]){
						xx-=vx[v];
						yy-=vy[v];
						b[xx+vx[v]][yy+vy[v]]=true;
						ret=min(ret, DFS(xx,yy,depth+1,limit,b));
						b[xx+vx[v]][yy+vy[v]]=false;
						break;
					}
				}
			}
			return ret;
			
		}
	}

}

Measured memory_bytes: 23232
#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <algorithm>
#include <ctime>
#include <vector>
#include <set>
#include <queue>
using namespace std;

#define PI 3.14159265358979323846264338327950L

long long int res;

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

    long long int N,A,B;
    cin >> N >> A >> B;
    long long int q = N / (A+B);
    long long int r = N % (A+B);
    res = q * A + min(A, r);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

int main() {
    int N, A, B, C;
    cin >> N >> A >> B >> C;
    vector<string> s(N);
    for (int i = 0; i < N; i++) {
        cin >> s.at(i);
    }
    vector<char> ans;
    for (int i = 0; i < N; i++) {
        if (s[i] == "AB") {
            if (A == 0 && B == 0) {
                cout << "No\n";
                return 0;
            }
            if (A == B) {
                if (i + 1 < N && s[i + 1][0] != 'B' && s[i + 1][1] != 'B') {
                    ans.push_back('A');
                    A++;
                    B--;
                } else {
                    ans.push_back('B');
                    B++;
                    A--;
                }
            } else if (A < B) {
                ans.push_back('A');
                A++;
                B--;
            } else {
                ans.push_back('B');
                B++;
                A--;
            }
        } else if (s[i] == "BC") {
            if (C == 0 && B == 0) {
                cout << "No\n";
                return 0;
            }
            if (C == B) {
                if (i + 1 < N && s[i + 1][0] != 'B' && s[i + 1][1] != 'B') {
                    ans.push_back('C');
                    C++;
                    B--;
                } else {
                    ans.push_back('B');
                    B++;
                    C--;
                }
            } else if (C < B) {
                ans.push_back('C');
                C++;
                B--;
            } else {
                ans.push_back('B');
                B++;
                C--;
            }
        } else if (s[i] == "AC") {
            if (C == 0 && A == 0) {
                cout << "No\n";
                return 0;
            }
            if (C == A) {
                if (i + 1 < N && s[i + 1][0] != 'A' && s[i + 1][1] != 'A') {
                    ans.push_back('C');
                    C++;
                    A--;
                } else {
                    ans.push_back('A');
                    A++;
                    C--;
                }
            } else if (C < A) {
                ans.push_back('C');
                C++;
                A--;
            } else {
                ans.push_back('A');
                A++;
                C--;
            }
        }
    }
    cout << "Yes\n";
    for (auto a : ans) {
        cout << a << "\n";
    }
}


Measured memory_bytes: 6704
#include <bits/stdc++.h>
using namespace std;;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin >>n;
  priority_queue<P> q;
  rep(i,n){
    ll x,l;cin >> x >> l;
    q.push(mp(-(x+l), -(x-l)));
  }
  ll ans = 0;
  ll pos = -LINF;
  while(q.size()){
    auto tmp = q.top();
    q.pop();
    ll r = -tmp.first;
    ll l = -tmp.second;
    if(pos<=l){
      ans++;
      pos = r;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

vector<int> fact;
vector<int> ifact;
vector<int> inv;
vector<int> pow2;
const int MOD = (1e9 + 7);
int add(int a, int b)
{
	a+=b;
	while(a>=MOD) a-=MOD;
	return a;
}
void radd(int &a, int b)
{
	a=add(a,b); 
}
int mult(int a, int b)
{
	return (a*1LL*b)%MOD;
}
void rmult(int &a, int b)
{
	a=mult(a,b);
}
int modpow(int a, int b)
{
	int r=1;
	while(b)
	{
		if(b&1) r=mult(r,a);
		a=mult(a,a);
		b>>=1;
	}
	return r;
}
int choose(int a, int b)
{
	if(a<b) return 0;
	if(b==0) return 1;
	if(a==b) return 1;
	return mult(fact[a],mult(ifact[b],ifact[a-b]));
}
int inverse(int a)
{
	return modpow(a,MOD-2);
}
void init(int _n)
{
	fact.clear(); ifact.clear(); inv.clear(); pow2.clear();
	fact.resize(_n+1);
	ifact.resize(_n+1);
	inv.resize(_n+1);
	pow2.resize(_n+1);
	pow2[0]=1;
	ifact[0]=1;
	fact[0]=1;
	for(int i=1;i<=_n;i++)
	{
		pow2[i]=add(pow2[i-1],pow2[i-1]);
		fact[i]=mult(fact[i-1],i);
		//ifact[i]=mult(ifact[i-1],inv[i]);
	}
	ifact[_n] = inverse(fact[_n]);
	for(int i=_n-1;i>=1;i--)
	{
		ifact[i] = mult(ifact[i + 1], i + 1);
	}
	for(int i=1;i<=_n;i++)
	{
		inv[i] = mult(fact[i-1],ifact[i]);
	}
}
	
int f[5555]; //1s and consecutive 0s of length >= a, ending at 1
int g[5555][2];
int f2[5555];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	init(5555);
	int n,a,b; cin>>n>>a>>b;
	if(a>b) swap(a,b);
	f[1]=1; 
	for(int i=2;i<=n;i++)
	{
		f[i]=f[i-1]; 
		for(int j=a;j<=i;j++)
		{
			if(i>=j+1) 
			{
				radd(f[i],f[i-j-1]);
			}
			if(i>=j) radd(f2[i],f[i-j]); //end with j 0s
		}
		//cerr<<i<<' '<<f[i]<<' '<<f2[i]<<'\n';
	}
		
	g[0][0]=g[0][1]=1;
	//start with run of 1s, but with 0
	for(int i=1;i<b;i++)
	{
		g[i][1]=f2[i];
	}
	for(int i=1;i<=n;i++)
	{
		//run of small 0s
		for(int j=1;j<a;j++)
		{
			if(i>=j) radd(g[i][0],g[i-j][1]);
		}
		//run of 1s
		for(int j=1;j<min(i+1,b);j++)
		{
			radd(g[i][1],mult(g[i-j][0],f[j]));
		}
		//cerr<<i<<' '<<g[i][0]<<' '<<g[i][1]<<'\n';
	}
	int ans = add(g[n][0],g[n][1]);
	//end with run of 1s, but with 0
	for(int i=1;i<b;i++)
	{
		//cerr<<i<<' '<<f2[i]<<'\n';
		if(n>=i) radd(ans,mult(g[n-i][0],f2[i]));
	}
	cout<<add(pow2[n],MOD-ans)<<'\n';
}


Measured memory_bytes: 3780
/**
 *   author:  cryforthemoon46
 *   created: 25.05.2020 13:56:56
**/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll A, B; cin >> A >> B;
    ll ans = 0;
    while(1 + (A - 1) * ans < B) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

N = int(input())
A = list(map(int, input().split()))

cnt = 0
abs_A = []
for i in range(N):
    if A[i] < 0:
        cnt += 1
        abs_A.append(-A[i])
    else:
        abs_A.append(A[i])
ans = sum(abs_A)
if cnt % 2 != 0:
    ans -= 2*min(abs_A)

print(ans)

Measured memory_bytes: 14332