akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n) { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x) { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};
set<int> stamp;
vector<int> tar(3);
set<int> exist;

int main() {
	int n;
	cin >> n;
	REP(i, n) {
		int h, w;
		cin >> h >> w;
		REP(l, h + 3)
			REP(m, w + 3) {
			int add = 0;
			REP(k, h)
				REP(j, w) {
				int y = l - h + 1 + k;
				int x = m - w + 1 + j;
				if (0 <= y&&y <= 3 && 0 <= x&&x <= 3) {
					add |= 1 << (y * 4 + x);
				}
			}
			stamp.insert(add);
		}
	}
	REP(i, 4) {
		string s;
		cin >> s;
		REP(j, 4) {
			if (s[j] == 'R')
				tar[0] |= 1 << (i * 4 + j);
			if (s[j] == 'G')
				tar[1] |= 1 << (i * 4 + j);
			if (s[j] == 'B')
				tar[2] |= 1 << (i * 4 + j);
		}
	}
	exist.insert(0);
	queue<pii> Q;
	Q.push({ 0,0 });
	int ans = 17;
	while (!Q.empty()) {
		pii state = Q.front();
		Q.pop();
		if (state.first == (1 << 16) - 1) {
			ans = min(ans, state.second);
			break;
		}
		for (auto x : stamp) {
			REP(w, 3) {
				int copy = state.first;
				copy = copy&(((1 << 16) - 1) - x);
				copy |= x&tar[w];
				if (exist.find(copy) == exist.end()) {
					exist.insert(copy);
					Q.push({ copy, state.second + 1 });
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 6244
object Main extends App {
	val N = scala.io.StdIn.readLine.toArray

	val a1 = N(0).toInt - 48
	val a2 = N(1).toInt - 48
	val a3 = N(2).toInt - 48
	val a4 = N(3).toInt - 48

	if(a1 + a2 + a3 + a4 == 7){
		println(s"$a1+$a2+$a3+$a4=7")
	}else if(a1 + a2 + a3 - a4 == 7){
		println(s"$a1+$a2+$a3-$a4=7")
	}else if(a1 + a2 - a3 + a4 == 7){
		println(s"$a1+$a2-$a3+$a4=7")
	}else if(a1 + a2 - a3 - a4 == 7){
		println(s"$a1+$a2-$a3-$a4=7")
	}else if(a1 - a2 + a3 + a4 == 7){
		println(s"$a1-$a2+$a3+$a4=7")
	}else if(a1 - a2 + a3 - a4 == 7){
		println(s"$a1-$a2+$a3-$a4=7")
	}else if(a1 - a2 - a3 + a4 == 7){
		println(s"$a1-$a2-$a3+$a4=7")
	}else if(a1 - a2 - a3 - a4 == 7){
		println(s"$a1-$a2-$a3-$a4=7")
	}
}

Measured memory_bytes: 25420
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#define FOR(x, z, y) for(int x = (z); y; x++)
#define rep(x, y) for(int x = 0; x < (y); x++)
#define REP(x, z, y) for(int x = (z); x < (y); x++)
#define all(x) x.begin(), x.end()
#define len(x) (sizeof(x) / sizeof(x[0]))
#define split_str(str, sp_word) istringstream stream(str); string res; FOR(cnt, 0, getline(stream,res,sp_word))
#define scanln(x) fgets(x, sizeof x, stdin)
#define down_queue(x) priority_queue<x>
#define up_queue(x) priority_queue<x, vector<x>, greater<x>>
#define i_str(x) atoi(x.c_str())
typedef long long ll;
using namespace std;

int main(){
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  if((b - a) == (c - b))puts("YES");
  else puts("NO");
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define repr(i,a,n) for(ll i = n-1;i >= a;i--)
#define LINF (ll)1e17
#define INF (int)1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
	
}

ll lcm(ll a,ll b){
	return a * b / gcd(a,b);
}





signed main(){
	ll n,ans = LINF;
	cin >> n;

	rep(i,1,sqrt(n)+1){
		if(n % i == 0){
			ans = min(ans,(n/i - 1)+(i - 1));
		}
	}

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

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  int N;

  cin >> N;

  int xmax = 0;
  vector<int> x(N);
  for(int i = 0; i < N; i++){
    cin >> x[i];
    xmax=max(xmax, x[i]);
  }

  int ans = 1000000;
  int xs = x.size();
  int tmp = 0;
  for(int i = 0; i < (xmax+1); i++){
    for(int j = 0; j < xs; j++){
      tmp += (int)pow((double)(x[j]-i), 2.0);
      // cout << "tmp " << j << " = " << tmp << endl;
    }
    ans = min(ans, tmp);
    // cout << " ans " << i << " = " << ans << endl;
    tmp = 0;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
def inpl():
    return list(map(int, input().split()))


def func(n):
    # print(n)
    tmp = n + n
    a = 0
    while tmp <= N:
        a += ans[tmp - 1]
        tmp += n
    return a % 2


N = int(input())
A = inpl()
ans = [0 for i in range(N)]

for i in reversed(range(N)):
    if func(i + 1) != A[i]:
        ans[i] = 1

# print(ans)
B = []
for i in range(N):
    if ans[i] == 1:
        B.append(i + 1)

print(len(B))
if len(B) > 0:
    print(" ".join(map(str, B)))


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define CHMIN(a, b) (a) = min((a), (b))
#define CHMAX(a, b) (a) = max((a), (b))

#define DEBUG(x) cout << #x << ": " << (x) << endl

int main() {
  int a[5];
  int k;
  FOR(i, 0, 5) { cin >> a[i]; }
  cin >> k;
  string rep = "Yay!";

  FOR(i, 0, 5) {
    FOR(j, i, 5) {
      if (a[j] - a[i] > k) rep = ":(";
    }
  }

  cout << rep << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        int N = ni();
        String s = ns();
        int numw = 0;
        int numb = 0;
        for (int i = 0; i < N; i++) {
            if(s.charAt(i)=='#')numb++;
            if(s.charAt(i)=='.')numw++;
        }
        int leftblack = 0;
        int rightwhite = numw;
        ArrayList<Integer> nchange = new ArrayList<>();
        nchange.add(leftblack+rightwhite);
        for (int i = 0; i <N; i++) {
            if(s.charAt(i)=='.'){
                rightwhite--;
            }else{
                leftblack++;
            }
            // System.out.println(leftblack);
            // System.out.println(rightwhite);
            nchange.add(rightwhite+leftblack);
        }
        int ans = Collections.min(nchange);
        out.println(ans);
    }

    final int mod = 1000000007;
    int mul(int x, int y){
        return (int)((x * 1L * y) % mod);
    }
    int add(int x, int y) {
        x += y;
        return x >= mod ? (x - mod) : x;
    }
    int sub(int x, int y){
        x = add(x,mod-y);
        return x >= mod ? (x - mod) : x;
    }
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 42840
// ?????±???????????????????????? 2015-1
#include<cstdio>
#include<algorithm>
using namespace std;
 
 
int main(){
  int a[4],b[2];
  for(int i=0;i<4;i++) scanf("%d",a+i);
  for(int i=0;i<2;i++) scanf("%d",b+i);
  sort(a,a+4);
  sort(b,b+2);
  int ans = 0;
  for(int i=3;i>0;i--) ans+=a[i];
  ans+=b[1];
  printf("%d\n",ans);
  return 0;
}

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

using namespace std;

const int MAX_N = 2e3 + 10;

int N, M, pa[MAX_N][MAX_N], depth[MAX_N], prefix[MAX_N][MAX_N], LCA[MAX_N][MAX_N];
bool vis[MAX_N];

vector<int> edgeT[MAX_N], edgeG[MAX_N];

void dfs0(int x, int y, int z) {
    depth[x] = z;
    for (int i : edgeT[x]) {
        if (i == y) continue;
        dfs0(i, x, z + 1);
    }
}

void dfs1(int x, int y, int z) {
    pa[x][y] = z;
    for (int i : edgeT[y]) {
        if (i == z) continue;
        dfs1(x, i, y);
    }
}

void dfs2(int a, int b, int x, vector<pair<int, int>> &cut) {
    if (prefix[a][x]) cut.emplace_back(b, x);
    else {
        prefix[a][x] = b;
        for (int i : edgeT[x]) {
            if (i == pa[a][x]) continue;
            dfs2(a, b, i, cut);
        }
    }
}

void decomposite(int a, int b) {
    if (prefix[a][b] == b || prefix[b][a] == a)
        return;
    else if (prefix[a][b])
        decomposite(prefix[a][b], b);
    else if (prefix[b][a])
        decomposite(prefix[b][a], a);
    else {
        vector<pair<int, int>> cut;
        dfs2(a, b, b, cut);
        dfs2(b, a, a, cut);
        for (pair<int, int> i : cut)
            decomposite(i.first, i.second);
    }
}

int calcLCA(int x, int y) {
    int &res = LCA[x][y];
    if (res) return res;
    if (x == y) return res = x;
    if (depth[x] > depth[y]) return res = calcLCA(pa[1][x], y);
    if (depth[y] > depth[x]) return res = calcLCA(x, pa[1][y]);
    return res = calcLCA(pa[1][x], pa[1][y]);
}

int dist(int x, int y) {
    return depth[x] + depth[y] - 2 * depth[LCA[x][y]];
}

bool straight(int a, int b, int c) {
    vector<int> dis = {dist(a, b), dist(a, c), dist(b, c)};
    sort(dis.begin(), dis.end());
    return dis[0] + dis[1] == dis[2];
}

void dfs3(int x, int y, int &ans) {
    if (vis[x]) return;
    vis[x] = true; ans++;
#ifdef DEBUG
    printf("%d ", x);
#endif
    for (int i : edgeG[x])
        if (y == 0 || straight(x, y, i))
            dfs3(i, x, ans);
}

int main() {
    scanf("%d%d", &N, &M);

    for (int i = 1; i < N; i++) {
        int a, b; scanf("%d%d", &a, &b);
        edgeT[a].push_back(b);
        edgeT[b].push_back(a);
    }

    dfs0(1, 0, 1);

    for (int i = 1; i <= N; i++)
        dfs1(i, i, 0);

    for (int i = 1; i <= N; i++)
        for (int j = 1; j <= N; j++)
            calcLCA(i, j);

    for (int i = 1; i <= M; i++) {
        int a, b; scanf("%d%d", &a, &b);
        decomposite(a, b);
    }

    for (int i = 1; i <= N; i++)
        for (int j = 1; j <= N; j++)
            if (prefix[i][j] == j && !prefix[i][pa[i][j]]) {
                edgeG[i].push_back(j);
#ifdef DEBUG
                printf("* %d %d\n", i, j);
#endif
            }


    int ans = 0; 
    for (int i = 1; i <= N; i++) {
        fill_n(vis + 1, N, false);
#ifdef DEBUG
        printf("#%d :", i);
#endif
        dfs3(i, 0, ans);
#ifdef DEBUG
        printf("\n");
#endif
    }
    ans = (ans - N) / 2;
    printf("%d\n", ans);
}


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

int main() {
  int n;
  cin >> n;
  int m[100010] = {0};
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    m[a]++;
  }
  bool flag = true;
  long long ans = 1;
  if (n%2 == 0) {
    if (m[0] != 0) {
      flag = false;
    }
    for (int i = 1; i <= n - 1; i += 2) {
      if (m[i] != 2) {
        flag = false;
      }
    }
  }
  else {
    if (m[0] != 1) {
      flag = false;
    }
    for (int i = 2; i <= n - 1; i += 2) {
      if (m[i] != 2) {
        flag = false;
      }
    }
  }
  if (flag) {
    for (int i = 0; i < n/2; i++) {
      ans *= 2;
      ans %= 1000000007;
    }
  }
  else {
    ans = 0;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
using namespace std;
using ll = long long;
#define out(S) cout<<(S)<<endl;

int getGroup(int x) {
	if (x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12) return 1;
	if (x == 2) return 3;
	return 2;
}

int main()
{
	int x, y;
	cin >> x >> y;
	if (getGroup(x) == getGroup(y)) {
		out("Yes");
		return 0;
	}
	out("No");
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

unsigned int n, v;
unsigned int cnt = 0;
unsigned int min = 1U << 30;

unsigned int read(void){
  char c;
  while(1){
    c = getchar();
    if(c >= '0') break;
  }
  unsigned int res = c - '0';
  while(1){
    c = getchar();
    if(c < '0') break;
    res = 10 * res + (c - '0');
  }
  return res;
}

int main(void){
  n = read();
  while(n--){
    v = read();
    if(v < min){
      min = v; cnt++;
    }
  }
  printf("%u\n", cnt);
  return 0;
}

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

const int N = 55;
vector<int> adj[N];
int cnt[N], par[N], level[N];

void dfs(int u, int p) {
    par[u] = p;
    if (p!= -1) level[u] = level[p] + 1; 
    for (int v: adj[u]) {
        if (v == p) continue;
        dfs(v, u);
    }
}

int black = 0;

void inc(int u, int x) {
    if (cnt[u])    black--;
    cnt[u]+=x;
    if (cnt[u])    black++;
}


void add(int u, int v, int x) {
    if (level[u] > level[v])    swap(u, v);
    while (level[u] < level[v]) {
        inc(v, x);
        v = par[v];
    }

    while (u != v) {
        inc(u, x);
        inc(v, x);
        u = par[u];
        v = par[v];
    }
    return;
}

int m, n;
const int K = 20;
int u[K], v[K];

long long ways[1<<K];

void go(int i, int mask) {
    if (i == m)     {
        cerr<<mask<<" "<<black<<endl;
        ways[mask] = 1LL<<(n-1-black);
        return;
    }
    go(i+1, mask);
    add(u[i], v[i], 1);
    go(i+1, mask|(1<<i));
    add(u[i], v[i], -1);
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin>>n;

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

    dfs(1, -1);
    cin>>m;

    for (int i=0; i<m; i++) {
        cin>>u[i]>>v[i];
    }

    go(0, 0);
    
    unsigned long long ans = 0;
    for (int i=0; i<(1<<m); i++) {
        if (__builtin_popcount(i)%2==0)    ans += ways[i];
        else                            ans -= ways[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 8576
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        int[] q = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt()-1;
            q[p[i]] = i;
        }
        int ans = 0;
        int tmp = 1;
        for (int i = 1; i < n; i++) {
            if(q[i-1] < q[i]) tmp++;
            else{
                if(ans < tmp) ans = tmp;
                tmp = 1;
            }
        }
        if(ans < tmp) ans = tmp;
        System.out.println(n-ans);
        sc.close();

    }

}


Measured memory_bytes: 86604
def main():
    K,N = [int(i) for i in input().split()]
    A = [int(i) for i in input().split()]
    res = A[-1] - A[0]
    for i in range(N-1):
        res = min(res, K - A[i+1] + A[i])
    print(res)
main()

Measured memory_bytes: 78284
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void){
  string s;
  cin >> s;
  
  vector<string>test(16);
  test[0] = "AKIHABARA";
  test[1] = "KIBAHARA";
  test[2] = "AKIHBARA";
  test[3] = "AKIHABRA";
  test[4] = "AKIHABAR";
  test[5] = "KIHBARA";
  test[6] = "KIHABRA";
  test[7] = "KIHABAR";
  test[8] = "AKIHBRA";
  test[9] = "AKIHBAR";
  test[10] = "AKIHABR";
  test[11] = "KIHBRA";
  test[12] = "KIHBAR";
  test[13] = "KIHABR";
  test[14] = "AKIHBR";
  test[15] = "KIHBR";
  
  bool can = false;
  for(int i=0;i<16;i++){
    if(s == test[i])
      can = true;
  }
  
  if(can)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  
  return 0;
}


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

struct pz{
	int a[9];
	int t;

	bool operator < (const pz &p) const {
		for (int i = 0; i < 9; i++) {
			if (a[i] == p.a[i])
				continue;
			return a[i] > p.a[i];
		}
		return false;
	}
};

int main()
{
	pz p;
	int n = -1;
	map<pz, bool> v;

	for (int i = 0; i < 9; i++)
		cin >> p.a[i];

	p.t = 0;

	queue<pz> que;
	que.push(p);
	v[p] = true;

	while (!que.empty()) {
		pz g = que.front();
		que.pop();

		bool f = 1;

		for (int i = 0; i < 8; i++) {
			if (g.a[i] != (i + 1)) {
				f = 0;
				break;
			}
		}

		if (f == 1) {
			n = g.t;
			break;
		}

		for (int i = 0; i < 9; i++) {
			if (g.a[i] == 0) {
				if(i % 3 != 0){
					g.t++;
					swap(g.a[i], g.a[i - 1]);
					if (!v[g]) {
						v[g] = true;
						que.push(g);
					}
					swap(g.a[i], g.a[i - 1]);
					g.t--;
				}
				if (i % 3 != 2) {
					g.t++;
					swap(g.a[i], g.a[i + 1]);
					if (!v[g]) {
						v[g] = true;
						que.push(g);
					}
					swap(g.a[i], g.a[i + 1]);
					g.t--;
				}
				if (i / 3 != 0) {
					g.t++;
					swap(g.a[i], g.a[i - 3]);
					if (!v[g]) {
						v[g] = true;
						que.push(g);
					}
					swap(g.a[i], g.a[i - 3]);
					g.t--;
				}
				if (i / 3 != 2) {
					g.t++;
					swap(g.a[i], g.a[i + 3]);
					if (!v[g]) {
						v[g] = true;
						que.push(g);
					}
					swap(g.a[i], g.a[i + 3]);
					g.t--;
				}
			}
		}
	}

	cout << n << endl;

	return 0;
}


Measured memory_bytes: 20484
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<size_t I,class H,class...T>struct TupleReaderWriter{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple_cat(tuple<H>(v),TupleReaderWriter<sizeof...(T)-1,T...>::r(i));}static void w(ostream&o,tuple<H,T...>&t,string d){TupleReaderWriter<I-1,H,T...>::w(o,t,d);o<<d<<get<I>(t);}};
template<class H,class...T>struct TupleReaderWriter<0,H,T...>{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple<H>(v);}static void w(ostream&o,tuple<H,T...>&t,string d){o<<get<0>(t);}};
template<class...T>istream&operator>>(istream&i,tuple<T...>&t){t=TupleReaderWriter<sizeof...(T),T...>::r(i);return i;}
template<class...T>ostream&operator<<(ostream&o,tuple<T...>&t){string delim=" ";TupleReaderWriter<sizeof...(T)-1,T...>::w(o,t,delim);return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(auto&x:v)i>>x;return i;}
template<class T>ostream&operator<<(ostream&o,vector<T>&v){string delim="";for(auto&x:v)o<<delim<<x,delim=" ";return o;}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int x;fixprec(int d):x(d){}};
ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.x);}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }
/*!* [binsearch] *!*/
/*+* 二分探索 *+*/
// judge を満たすような下限を求める
// l:[X] 定義域外部の上限
// r:[X] 定義域外部の下限
// judge:[X -> bool] X を評価する関数
// lower:[bool] falseにすると代わりに上限を求める
// eps:[X] 終了距離

template <typename X>
X BinSearch(X l, X r, function<bool(X)> judge, bool lower = true, X eps = 1) {
    while (r - l > eps) {
        X m = (r + l) / 2;
        if (judge(m) == lower) {
            r = m;
        } else {
            l = m;
        }
    }
    return lower ? r : l;
}

int main() {
    // O(N(log N)^2)
    int N, L, Q;
    cin >> N;
    vector<int> X(N);
    for(int &x : X) cin >> x;
    cin >> L >> Q;
    int D = int(ceil(log2(N)));
    vector2d<int> seg(D, vector<int>(N));
    for (int d = 0; d < D; d++) {
        for (int i = 0; i < N; i++) {
            if(d == 0) {
                seg[d][i] = BinSearch<int>(i - 1, N, [&](int k) -> bool {
                    // 一日でk番までいけるか
                    return X[k] - X[i] <= L;
                }, false);
            } else {
                seg[d][i] = seg[d - 1][seg[d - 1][i]];
            }
        }
    }
    // O(N(log N)^2)
    for(int q = 0; q < Q; q++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        if(a > b) swap(a, b);
        // O((log N)^2)
        cout << BinSearch<int>(0, N, [&](int k) -> bool {
            // O(log N)
            // k日で到達できるか
            int x = a;
            for(int d = 0; d < D; d++) {
                if(k & (1 << d)) {
                    x = seg[d][x];
                }
            }
            return x >= b;
        }) << endl;
    }
    return 0;
}



Measured memory_bytes: 7928
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define endl '\n'
#define mod 1000000007
#define inf 1000000000000000000
#define pii pair<ll, vector<ll>>
const double pi = acos(-1);
ll n;
void solve() {
	cin>>n;
	cout<<(n >= 30 ? "Yes" : "No")<<endl;
}
int main() {
	io
	int t = 1;
	//cin>>t;
	while(t--) {
		solve();
	}
}






Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+5;
ll n,q,a[N],prfx[N],prfx1[N],prfx2[N];
bool chk(ll x,ll k){
    ll cnt = upper_bound(a+1,a+n+1,x+k) - lower_bound(a+1,a+n+1,x-k);
    ll have = n+1 - ( upper_bound(a+1,a+n+1,x+k) - a );
    return have>=cnt;
}
ll func(ll x){
    ll s=0,e=1e9;
    while(s<e){
        ll mid=(s+e+1)/2;
        if(chk(x,mid))s=mid;
        else e=mid-1;
    }
    return s;
}
void solve(){
    ll x;cin>>x;
    if(x>=a[n]){
        if(n%2==0)cout<<prfx2[n]<<"\n";
        else cout<<prfx1[n]<<"\n";
        return;
    }
    if(x<=a[1]){
        cout<<prfx[n] - prfx[n-(n+1)/2]<<"\n";
        return;
    }
    ll k = func(x);
    ll u = upper_bound(a+1,a+n+1,x+k) - (a+1);
    ll v = lower_bound(a+1,a+n+1,x-k) - (a+1);
    ll have = n+1 - ( upper_bound(a+1,a+n+1,x+k) - a);
    ll cnt = upper_bound(a+1,a+n+1,x+k) - lower_bound(a+1,a+n+1,x-k);
    while(have>cnt)v--,have--;
    ll ans = prfx[n]-prfx[u];
    if(v%2)ans+=prfx1[v];
    else ans+=prfx2[v];
    cout<<ans<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>q;
    for(ll i=1;i<=n;i++){
        cin>>a[i];
        prfx[i]=prfx[i-1]+a[i];
        prfx1[i]=prfx1[i-1]+(i%2==1)*a[i];
        prfx2[i]=prfx2[i-1]+(i%2==0)*a[i];
    }
    while(q--)solve();
}

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

using namespace std;

#define MOD 1000000007
#define N 100005
#define M 30
#define ll long long 
#define ld long double
#define pb push_back
#define ff first
#define ss second

int dp[N], a[N];

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n, K, i, j;
    cin>>n>>K;
    for(i=0; i<n; i++){
        cin>>a[i];
    }
    for(i=0; i<K; i++){
        if(dp[i] == 0){
            for(j=0; j<n; j++){
                if(i + a[j] <= K) dp[i + a[j]] = 1;
            }
        }
    }
    cout<<(dp[K] ? "First" : "Second");
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  char c1, c2, c3, c4; std::cin >> c1 >> c2 >> c3 >> c4;
  int a = (c1-'0')*10 + (c2-'0'), b = (c3-'0')*10+(c4-'0');
  int mm = std::min(a, b), yy = std::max(a, b);
  // MM: [1,12] YY: no limits
  if(mm == 0) std::swap(mm, yy);
  if(mm == 0 || mm > 12) fin("NA");
  if(1 <= yy && yy <= 12) fin("AMBIGUOUS");
  if(a == mm) fin("MMYY");
  fin("YYMM");
  return 0;
}


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

lli n;

int main(void){
	cin >> n;
	vector<lli> a(n);
	rep(i, n) cin >> a[i];
	lli p, q, r;
	p = q = r = 0;
	rep(i, n){
		lli d = 0;
		lli tmp = a[i];
		while(tmp%2 == 0){
			d++;
			tmp/=2;
		}
		if(d == 0) p++;
		else if(d == 1) q++;
		else r++;
	}
	if(q == 0) r++;
	if(p <= r) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3964
#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
#include <sstream>

using namespace std;

int main() {
    const int INF = 1001001001;
    int n, m, x;
    cin >> n >> m >> x;

    vector<int> c(n);
    vector<vector<int>> a(n, vector<int>(m));
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
        for (int j = 0; j < m; ++j) {
            cin >> a[i][j];
        }
    }

    int iter = 1;
    for (int i = 0; i < n; i++) {
        iter *= 2;
    }


    
    int ans = INF;

    for (int i = 0; i < iter; i++) {
        vector<int> u(m);
        int cost = 0;

        stringstream ss;
        ss << bitset<12>(i);
        string s = ss.str();

        for (int j = 0; j < n; j++) {
            if (s[11-j] - '0') {
                for (int k = 0; k < m; ++k) {
                    u[k] += a[j][k];
                }
                cost += c[j];
            }
        }
        int min_u = *min_element(u.begin(), u.end());
        if ( min_u >= x) {
            ans = min(ans, cost);
        }
    }

    if (ans == INF) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <utility>
#include <vector>

using namespace std;

typedef long long Long;
#define whole(xs) xs.begin(), xs.end()

template<class T>
ostream& operator<<(ostream& os, const vector<T>& vs) {
    os << vs[0];
    for (int i = 1; i < vs.size(); i++) {
        os << ' ' << vs[i];
    }
    return os;
}

const int MAX_N = 5001;

int N, M;
vector<int> G[MAX_N];
void input() {
    cin >> N >> M;
    for (int i = 0; i < N; i++) { G[i].clear(); }
    for (int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        G[x].push_back(y);
    }
    for (int i = 1; i <= N; i++) {
        G[0].push_back(i);
    }
}

void dfs(vector<int>& result, vector<bool>& used, int v) {
    if (used[v]) return;
    used[v] = true;
    for (int i = 0; i < G[v].size(); i++) {
        int u = G[v][i];
        if (used[u]) continue;
        dfs(result, used, u);
    }
    result.push_back(v);
}
void tsort(vector<int>& res) {
    vector<bool> used(N, false);
    dfs(res, used, 0);
    reverse(whole(res));
}

int dfs1(int v, vector<int>& cache) {
    if (G[v].empty()) return v;
    if (cache[v] >= -1) return cache[v];
    int x = dfs1(G[v][0], cache);
    for (int i = 1; i < G[v].size(); i++) {
        int u = G[v][i];
        if (x == dfs1(u, cache)) continue;
        return cache[v] = -1;
    }
    return cache[v] = x;
}

void solve() {
    vector<int> res;
    tsort(res);
    for (int i = 1; i <= N; i++) {
        cout << res[i] << endl;
    }
    vector<int> cache(N + 1, -2);
    cout << (dfs1(0, cache) == -1) << endl;
}

int main() {
    input(); solve();
    return 0;
}

Measured memory_bytes: 2060
#include <iostream>
#include <fstream>

#include <vector>

using namespace std;

typedef vector<int> vi;

void pushBack(vi *v, int x){
    v->push_back(x);
    return;
}

int randomAccess(vector<int> *v, int p){
    try{
        return v->at(p);
    } catch (out_of_range &e){
        throw e;
    }
}

void popBack(vector<int> *v){
    v->pop_back();
}

int main(){

    vector<int> vec;

    int q;
    cin >> q;
    for(int i=0;i<q;i++){
        int op, operand;
        cin >> op;
        switch (op){
        case 0:
            cin >> operand;
            pushBack(&vec, operand);
            break;
        case 1:
            cin >> operand;
            cout << randomAccess(&vec, operand) << endl;
            break;
        case 2:
            popBack(&vec);
            break;
        default:
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3880
l = input()
n = int(input())
for i in range(n):
    s = input().split()
    if s[0] == 'replace':
        l=l[0:int(s[1])] + s[3] + l[int(s[2])+1:len(l)]
    elif s[0] == 'reverse':
        l = l[0:int(s[1])] + l[int(s[1]):int(s[2])+1][::-1] + l[int(s[2])+1:len(l)]
    else:
        print(f"{l[int(s[1]):int(s[2])+1]}")


Measured memory_bytes: 5620
use std::io;
use std::str::FromStr;

fn get_line() -> String {
  let mut line = String::new();
  io::stdin()
    .read_line(&mut line)
    .unwrap();
  line
}

fn parse<T: FromStr>(line: &str) -> T {
  line
    .trim().parse::<T>()
    .ok().unwrap()
}

fn line_to_vec<T: FromStr>(line: &str) -> Vec<T> {
  line
    .trim().split_whitespace()
    .map(|val| parse(val))
    .collect()
}

fn matrix_multiple(vec1: &Vec<i64>, vec2: &Vec<i64>) -> i64 {
  let len = vec1.len();
  let mut v: Vec<i64> = Vec::with_capacity(len);
  for i in 0..len {
    v.push(vec1[i] * vec2[i]);
  }
  v.iter().sum()
}

fn main() {
  let l: Vec<usize> = line_to_vec(&get_line());
  let (n, m) = (l[0], l[1]);
  let mut a: Vec<Vec<i64>> = Vec::with_capacity(n);
  for i in 0..n {
    a.push(Vec::with_capacity(m));
    let l: Vec<i64> = line_to_vec(&get_line());
    for j in 0..m {
      a[i].push(l[j]);
    }
  }
  let mut b: Vec<i64> = Vec::with_capacity(m);
  for _ in 0..m {
    let elem: i64 = line_to_vec(&get_line())[0];
    b.push(elem);
  }
  for i in 0..n {
    println!("{}", matrix_multiple(&a[i], &b));
  }
}



Measured memory_bytes: 5052
N = int(input())
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
total = []
for i in range(N):
    total.append([sum(A1[:i+1]), sum(A2[i:])])
ans = 0
for i in range(N):
    ans = max(ans, sum(total[i]))
print(ans)


Measured memory_bytes: 3060
M = 1000000007

N, K = [int(s) for s in input().split()]

def f(k):
    l = k * (k - 1) / 2
    r = (2 * N - k + 1) * k // 2
    return r - l + 1

s = 0
for k in range(K, N+2):
    s = (s + f(k)) % M

print(int(s))


Measured memory_bytes: 9192
#include <iostream>

using namespace std;
typedef long long ll;

ll x;

void solve() {
  ll cnt = (x / 11) * 2;
  if (x % 11 > 6) {
    cnt += 2;
  } else if (x % 11 > 0) {
    cnt++;
  }
  cout << cnt << endl;
}

int main() {
  cin >> x;
  solve();
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <algorithm>

using namespace std;

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

    map<int, vector<int> > mp;
    for(int i = 0; i < n; i++){
        int tmp;
        cin >>tmp;

        map<int, vector<int> >::iterator it = mp.find(tmp);
        if(it == mp.end()){
            mp[tmp] = vector<int>(1, i);
        }else{
            mp[tmp].push_back(i);
        }
    }

    map<int, vector<int> >::reverse_iterator rit = mp.rbegin();
    bool maxElementDuplicate = ((*rit).second.size() > 1);
    int maxElement = (*rit).first;
    int maxElementIndex = (*rit).second[0];
    for(int i = 0; i < n; i++){
        if(maxElementDuplicate){
            printf("%d\n", maxElement);
        }else{
            if(i == maxElementIndex){
                rit++;
                printf("%d\n", (*rit).first);
            }else{
                printf("%d\n", maxElement);
            }
        }
    }

    return 0;
}

Measured memory_bytes: 14592
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n)
{
  int i;

  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main()
{
  int n, i, j, key;
  int A[N+1];

  scanf("%d", &n);
  
  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);

  trace(A, n);

  for(i = 2; i <= n; i++){
    key = A[i];
    j = i -1;
    while(j >= 0 && A[j] > key){
      A[j+1] = A[j];
      j--;
      A[j+1] = key;
    }
    trace(A, n);
  }

  return 0;
}

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

#define ll long long

using namespace std;

int main(void) {
	ll X, Y;
	cin >> X >> Y;
	int ans = 0;
	while (Y >= X) {
		ans++;
		X *= 2;
	}
	cout << ans << endl;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	m, _ := strconv.Atoi(sc.Text())

	al := make([]int, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		a, _ := strconv.Atoi(sc.Text())
		al[i] = a
	}

	bcm := make(map[int]int, m)
	for i := 0; i < m; i++ {
		sc.Scan()
		b, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		c, _ := strconv.Atoi(sc.Text())
		bcm[c] += b
	}

	cl := make([]int, m)
	for k := range bcm {
		cl = append(cl, k)
	}
	sort.Sort(sort.Reverse(sort.IntSlice(cl)))

	last := 0
	sort.Ints(al)
	for _, c := range cl {
		for i := 0; i < bcm[c]; i++ {
			if i+last == len(al) || al[i+last] >= c {
				goto G
			}
			al[i+last] = c
		}
		last += bcm[c]
	}

G:

	t := 0
	for _, a := range al {
		t += a
	}
	fmt.Println(t)
}


Measured memory_bytes: 12032
#include <iostream>
#include <algorithm>

using namespace std;
int main(void){
    int N;
    cin>>N;
    pair<int,int> red[N];
    for(int i=0;i<N;i++){
        int a,b;
        cin>>a>>b;
        red[i].first=a; red[i].second=b;
    }
    pair<int,int> blue[N];
    for(int i=0;i<N;i++){
        int a,b;
        cin>>a>>b;
        blue[i].first=a; blue[i].second=b;
    }
    sort(red,red+N);
    sort(blue,blue+N);
    bool check[N];
    fill(check,check+N,true);
    int ans=0;
    for(int i=0;i<N;i++){
        int max=-1; int maxj=-1;
        for(int j=0;j<N;j++){
            if(blue[i].first>red[j].first&&blue[i].second>red[j].second&&check[j]&&max<red[j].second){max=red[j].second; maxj=j;}
        }
       if(maxj!=-1){check[maxj]=false; ans++; }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
A = [int(x) for x in input().split()]

def cost(A, i, j, k):
    return abs(A[i] - A[j])+ abs(A[j] - A[k])

print(min(
    cost(A, 0, 1, 2),
    cost(A, 0, 2, 1),
    cost(A, 1, 0, 2),
    cost(A, 1, 2, 0),
    cost(A, 2, 1, 0),
    cost(A, 2, 0, 1)
))
    


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int n;
    char s[99999];
    int ans=0;
    int a[10]={};
    int tmp=0;
    int p=0;
    int q=0;
    int b[10]={};
    int x=0;
    
    cin >> n;
    cin >> s;
    
    for(int t=0; t<=n-1; t++){
        
        tmp = (int)(s[t]-'0');
        a[tmp] += 1;
        
    }
    
    for(int i=0; i<=9; i++){
        
        if(a[i]<=0){
            
            continue;
            
        }
        
        for(p=0; p<=n-3; p++){
            
            if((int)(s[p]-'0')==i){
                
                break;
                
            }
            
        }
        
        for(int j=0; j<=9; j++){
            
            if(a[j]<=0){
                
                continue;
                
            }
            
            for(q=p+1; q<=n-2; q++){
                
                if((int)(s[q]-'0')==j){
                    
                    break;
                    
                }
                
            }
            
            for(int k=0; k<=9; k++){
                
                b[k] = 0;
                
            }
            
            x = 0;
            
            for(int r=q+1; r<=n-1; r++){
                
                tmp = (int)(s[r]-'0');
                
                if(b[tmp]==0){
                    
                    b[tmp] = 1;
                    x += 1;
                    ans += 1;
                    
                    if(x>=10){
                        
                        break;
                        
                    }
                    
                }
                
            }
            
        }
        
    }
    
    cout << ans << endl;
    
    return 0;
    
}

Measured memory_bytes: 256
<?php
list($n) = ints();
for ($i = 0; $i < $n - 1; ++$i) {
    list($a, $b) = ints();
    --$a;
    --$b;
    $g[$a][] = $b;
    $g[$b][] = $a;
}
$dist[0] = bfs(0);
$dist[$n - 1] = bfs($n - 1);
// 黒く塗れるマスが過半数の場合はFennecの勝ち
$cnt = 1; // 最初の自分のマス
for ($i = 1; $i < $n - 1; ++$i)
    if ($dist[0][$i] <= $dist[$n - 1][$i]) ++$cnt;
echo 2 * $cnt > $n ? 'Fennec' : 'Snuke';
// BFS（幅優先探索）：最短経路アルゴリズムとして活用
function bfs($s)
{
    global $n, $g;
    $q = new SplQueue(); // キューを用意
    $dist = array_fill(0, $n, INF); // 距離を格納する配列

    $dist[$s] = 0; // 始点からの距離格納配列
    $q->enqueue($s); // キューに始点を追加

    while (!$q->isEmpty()) {
        $v = $q->dequeue();

        foreach ($g[$v] as $next_v) {
            if ($dist[$next_v] !== INF) continue; // 発見済み
            if ($next_v === 0 || $next_v === $n - 1) continue; // 初期状態で塗られているマス
            $dist[$next_v] = $dist[$v] + 1;
            $q->enqueue($next_v);
        }
    }
    return $dist;
}
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


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

int main() {
    int N,count,minl=101,last;
    cin >> N;
    vector<int> length(N),flag(N-1);
    
    

    for (int i = 0; i < N; ++i){
        cin >> length.at(i);
        minl = min(minl,length.at(i));
    }

    count = minl;
    /*
    for (int i = 0; i < N; ++i){
        length.at(i) -= minl;
    }
    */
    count += length.at(0)-minl;

    for (int i = 1; i <N; ++i ){
        count += max(0,length.at(i)-length.at(i-1));
    }
    cout << count << endl;
        
}

Measured memory_bytes: 256
n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
ans=0
for i in range(n):
    m=min(a[i],b[i])
    ans+=m
    a[i]-=m
    b[i]-=m
    m=min(a[i+1],b[i])
    a[i+1]-=m
    b[i]-=m
    ans+=m
print(ans)
        


Measured memory_bytes: 18468
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		sc.close();
		StringBuilder sb = new StringBuilder(S);
		sb.replace(3, 4, "8");
		System.out.println(sb.toString());
	}
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int a,b; cin>>a>>b;
    cout<<a*b<<endl;
}

Measured memory_bytes: 3592
#include<iostream>
#include<string>
using namespace std;
int n;
string s[100000];
int cnt[5]={0};
long long cal_ans(){
    long long ans(0);
    for(int i(0);i<3;i++){
        for(int j(i+1);j<4;j++){
            for(int k(j+1);k<5;k++){
                ans += (long long)cnt[i] * cnt[j] * cnt[k];
            }
        }
    }
    return ans;
}
int main(void){
    cin>>n;
    for(int i(0);i<n;i++){
        cin>>s[i];
    }
    for(int i(0);i<n;i++){
        if(s[i][0] == 'M')cnt[0]++;
        else if(s[i][0] == 'A')cnt[1]++;
        else if(s[i][0] == 'R')cnt[2]++;
        else if(s[i][0] == 'C')cnt[3]++;
        else if(s[i][0] == 'H')cnt[4]++;
    }
    cout<<cal_ans()<<endl;
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
    int N, sum = 0;
    cin >> N;
    vector<int> w(N);
    REP(i, N)
    {
        cin >> w[i];
        sum += w[i];
    }
    int val = 0, ans = 0;
    REP(i, N)
    {
        if (val + w[i] > sum / 2)
        {
            int v0 = (sum - val) - val;
            int v1 = val + w[i] - (sum - (val + w[i]));
            ans = min(v0, v1);
            break;
        }
        val += w[i];
    }
    cout << ans << "\n";
}

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;

const long long INF = 1LL << 60;

int main()
{
    string S;
    ll K;

    cin >> S >> K;
    ll cnt = 0;
    rep(i, S.size()) {
        if (S[i] == '1') cnt++;
        else break;
    }

    if (cnt >= K) cout << 1 << endl;
    else cout << S[cnt] << endl;
    return 0;
}

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

int main() {
	
	long long a, b, c;
	cin >> a >> b >> c;
	if (c == 1) {
		cout << b - a + 1 << endl;
		exit(0);
	}
	else {
		if (a == 0) {
			cout << b / c + 1 << endl;
		}
		else {
			cout << b / c - (a - 1) / c << endl;
		}
	}
	
}


Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
        int programcount = inpt[0];
        int channelCount = inpt[1];

        List<TVProgram> list = new List<TVProgram>();

        for (int i = 0; i < programcount; i++) {
            inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
            list.Add(new TVProgram(inpt[0], inpt[1], inpt[2]));
        }
        this.TimeTable = list.OrderBy(a => a.Begin).ToArray();

        int current = 0;
        int ans = 0;
        for (int i = 0; i < this.TimeTable.Length; i++) {
            int time = this.TimeTable[i].Begin;
            while (this.Recorder.Count>0 && time > Recorder.First().Key) {
                int key = Recorder.First().Key;
                current -= Recorder[key].Count;
                Recorder.Remove(key);
            }

            int endTime = this.TimeTable[i].End;
            if (Recorder.Count > 0) {
                int key = Recorder.First().Key;
                if(key == time) {
                    if (Recorder[key].Count(a=>a.Channel == this.TimeTable[i].Channel) > 0) {
                        Recorder[key].Remove(Recorder[key].Find(a => a.Channel == this.TimeTable[i].Channel));
                        current--;
                    }
                }
            }
            if(!Recorder.ContainsKey(endTime)) {
                Recorder.Add(endTime, new List<TVProgram>());
            }
            Recorder[endTime].Add(this.TimeTable[i]);
            current++;
            ans = Math.Max(ans, current);
        }
        Console.WriteLine(ans);
    }

    private TVProgram[] TimeTable;

    private SortedDictionary<int, List<TVProgram>> Recorder = new SortedDictionary<int, List<TVProgram>>();

    private class TVProgram {
        public int Begin;
        public int End;
        public int Channel;
        public TVProgram(int begin, int end, int channel) {
            this.Begin = begin;
            this.End = end;
            this.Channel = channel;
        }
    }


    public class Reader
    {
        private static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"




3 2
1 7 2
7 8 1
8 12 1

";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}


Measured memory_bytes: 31492
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
  long long int n,i,line,count=0;
  cin >> n;
  //vector <long long int> d(n);
 // for(i=0;i<n;i++)
  //{
   // cin >> d[i];
  //}
  //sort(d.begin(), d.end());
  if(n == 1)
  {
    cout << "0";
  }
  else if(n == 0)
  {
    cout << "1";
  }
  return 0;
}

Measured memory_bytes: 3592
#include<cstdio>

using namespace std;
int N;
int A[200000];

int main() {
    scanf("%d", &N);
    for(int i = 0; i < N; ++i) {
        scanf("%d", A+i);
    }

    long long result = 0;
    int left = 1;
    long long current = A[0];
    int cxor = A[0];
    for(int i = 0; i < N; ++i) {
        while(cxor == current && left < N) {
            cxor ^= A[left];
            current += A[left];
            ++left;
        }
        if(cxor != current) {
            result += left - i - 1;
        }
        else {
            result += left - i;
        }
        cxor ^= A[i];
        current -= A[i];
    }

    printf("%lld\n", result);
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
using namespace std;
int main(){
    int r=0,g=0,b=0,sum=0,judge=0;
    cin>>r;
    cin>>g;
    cin>>b;
    r=r*100;
    g=g*10;
    sum=r+g+b;
    judge=sum%4;
    if(judge==0){
        cout<<"YES";
    }else{
        cout<<"NO";
    }
    cout<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int main(void) {
    int K;
    cin>>K;

    queue<Int> Q;
    for(Int i = 1;i < 10;i++) {
        Q.push(i);
    }

    Int x;
    while(K--) {
        x = Q.front();Q.pop();
        Int y = x % 10;
        if(y != 9 && y != 0) {
            Q.push(10*x+y-1);
            Q.push(10*x+y);
            Q.push(10*x+y+1);
        } else if(y == 0){
            Q.push(10*x+y);
            Q.push(10*x+y+1);
        } else {
            Q.push(10*x+y-1);
            Q.push(10*x+y);
        }
    }

    cout<<x<<endl;

    return 0;
}




Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;

int main() {
  int a,b,c;
  cin >> a >> b >> c;

  cout << a*b/2 << endl;  


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <limits.h>
#include <vector>
#include <numeric>

using namespace std;



bool gooddis(long long int n) {

	long long int a = 0;

	while (n >= a * a) {
		if (n == a * a)return true;
		a++;
	}

	return false;
}


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

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

	for (int i = 0; i < a.size(); i++) {
		a[i] -= i + 1;
	}

	sort(a.begin(), a.end());
	int mid = (a.size() + 1) / 2;
	mid--;

	long long int ans = 0;
	long long int ave = a[mid];

	for (auto& i : a) {
		ans += abs(i - ave);
	}

	cout << ans << endl;

	return 0;

}




Measured memory_bytes: 1024