akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int board[1500][1500];
int dp[1500][1500];

signed main() {
    int n, m; cin >> n >> m;
    memset(board, 0, sizeof(board));
    memset(dp, 0, sizeof(dp));
    repq(i,0,m) board[0][i] = 1;
    repq(i,0,n) board[i][0] = 1;
    repq(i,1,n) repq(j,1,m) cin >> board[i][j];

    int ans = 0;
    repq(i,1,n) {
        repq(j,1,m) {
            if(board[i][j] == 1) {
                dp[i][j] = 0;
            }
            else {
                int d = min(dp[i-1][j-1], min(dp[i-1][j], dp[i][j-1])) + 1;
                dp[i][j] = d;
                ans = max(ans, dp[i][j] * dp[i][j]);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

const int P = 1000000007;

int power(int a, int x) {
	int ans = 1;
	for (; x; x >>= 1, a = 1ll * a * a % P)
		if (x & 1) ans = 1ll * ans * a % P;
	return ans;
}

int n, m, fa[20], dep[20], a[190], b[190], se[190], fac[191], ifac[191], sos[19][1 << 19];
vector<int> g[20];

struct info {
	int l, l0, cnt, sum;
} dp[1 << 19];
void insert_0(info &a) {
	++a.l, ++a.l0;
	a.sum = (a.sum + 1ll * a.l0 * a.cnt) % P;
}
void insert_1(info &a, int k) {
	a.cnt = 1ll * a.cnt * fac[a.l + k] % P * ifac[a.l] % P;
	a.sum = 1ll * a.sum * fac[a.l + k + 1] % P * ifac[a.l + 1] % P;
	a.l += k;
}
void merge(info &a, const info &b) {
	a.l = b.l;
	a.l0 = b.l0;
	a.cnt = (a.cnt + b.cnt) % P;
	a.sum = (a.sum + b.sum) % P;
}

void dfs(int u) {
	for (int e : g[u])
		if (e != fa[u]) {
			int v = a[e] + b[e] - u;
			fa[v] = e;
			dep[v] = dep[u] + 1;
			dfs(v);
		}
}
int get(int u, int v) {
	int s = 0;
	while (u != v) {
		if (dep[u] < dep[v])
			swap(u, v);
		s |= 1 << fa[u];
		int p = a[fa[u]] + b[fa[u]] - u;
		u = p;
	}
	return s;
}

void foo(int *f) {
	for (int d = 1; d < 1 << n - 1; d <<= 1)
		for (int i = 0; i < 1 << n - 1; i += d << 1)
			for (int j = 0; j < d; ++j)
				f[i + d + j] += f[i + j];
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; ++i) {
		scanf("%d%d", a + i, b + i), --a[i], --b[i];
		if (i < n - 1)
			g[a[i]].push_back(i), g[b[i]].push_back(i);
	}
	fac[0] = 1;
	for (int i = 1; i <= m; ++i)
		fac[i] = 1ll * fac[i - 1] * i % P;
	ifac[m] = power(fac[m], P - 2);
	for (int i = m; i; --i)
		ifac[i - 1] = 1ll * ifac[i] * i % P;
	fa[0] = -1;
	dfs(0);
	for (int i = n - 1; i < m; ++i) {
		int s = get(a[i], b[i]);
		for (int j = 0; j < n - 1; ++j)
			if (s >> j & 1)
				++sos[j][s];
	}
	for (int x = 0; x < n - 1; ++x)
		foo(sos[x]);
	dp[0] = (info){0, 0, 1, 0};
	for (int s = 0; s < 1 << n - 1; ++s)
		for (int e = 0; e < n - 1; ++e)
			if (!(s >> e & 1)) {
				auto z = dp[s];
				insert_1(z, sos[e][(1 << n - 1) - 1 - s]);
				insert_0(z);
				merge(dp[s | 1 << e], z);
			}
	printf("%d\n", dp[(1 << n - 1) - 1].sum);
	return 0;
}

Measured memory_bytes: 47360
/// Kazuki Hoshino


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
//#define endl '\n'
typedef tree<
int,
null_type,less<int>,
rb_tree_tag,tree_order_statistics_node_update>
ordered_set;
typedef long long LL;

struct Edge {
  int u, v;
  LL cap, flow;
  Edge() {}
  Edge(int u, int v, LL cap): u(u), v(v), cap(cap), flow(0) {}
};

struct Dinic {
  int N;
  vector<Edge> E;
  vector<vector<int>> g;
  vector<int> d, pt;

  Dinic(int N): N(N), E(0), g(N), d(N), pt(N) {}

  void AddEdge(int u, int v, LL cap) {
    if (u != v) {
      E.emplace_back(u, v, cap);
      g[u].emplace_back(E.size() - 1);
      E.emplace_back(v, u, 0);
      g[v].emplace_back(E.size() - 1);
    }
  }

  bool BFS(int S, int T) {
    queue<int> q({S});
    fill(d.begin(), d.end(), N + 1);
    d[S] = 0;
    while(!q.empty()) {
      int u = q.front(); q.pop();
      if (u == T) break;
      for (int k: g[u]) {
        Edge &e = E[k];
        if (e.flow < e.cap && d[e.v] > d[e.u] + 1) {
          d[e.v] = d[e.u] + 1;
          q.emplace(e.v);
        }
      }
    }
    return d[T] != N + 1;
  }

  LL DFS(int u, int T, LL flow = -1) {
    if (u == T || flow == 0) return flow;
    for (int &i = pt[u]; i < g[u].size(); ++i) {
      Edge &e = E[g[u][i]];
      Edge &oe = E[g[u][i]^1];
      if (d[e.v] == d[e.u] + 1) {
        LL amt = e.cap - e.flow;
        if (flow != -1 && amt > flow) amt = flow;
        if (LL pushed = DFS(e.v, T, amt)) {
          e.flow += pushed;
          oe.flow -= pushed;
          return pushed;
        }
      }
    }
    return 0;
  }

  LL MaxFlow(int S, int T) {
    LL total = 0;
    while (BFS(S, T)) {
      fill(pt.begin(), pt.end(), 0);
      while (LL flow = DFS(S, T))
        total += flow;
    }
    return total;
  }
};

int h,w,t,ss;
string s[105];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);

#ifndef ONLINE_JUDGE
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif

cin >> h >> w;
int src = h+w;
int dest = h+w+1;
Dinic d (h+w+5);
for(int i=0;i<h;i++){
	cin >> s[i];
	for(int j=0;j<w;j++){
		if(s[i][j]=='S'){
			d.AddEdge(src,i,1000000000);
         d.AddEdge(src,h+j,1000000000);
		}
		if(s[i][j]=='T'){
			d.AddEdge(i,dest,1000000000);
			d.AddEdge(h+j,dest,1000000000);
		}
		if(s[i][j]=='o'){
         d.AddEdge(i,h+j,1);
         d.AddEdge(h+j,i,1);
		}
	}
}

int ans = d.MaxFlow(src,dest);
if(ans>=1000000000)ans = -1;
cout << ans << endl;

return 0;}
///....


Measured memory_bytes: 2676
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

// 最大公約数
long long gcd(long long a, long long b){
    while(b != 0){
        long long tmp = a % b;
        a = b;
        b = tmp;
    }
    return a;
}

// 最小公倍数
long long lcm(long long a, long long b){
    return a / gcd(a, b) * b;
}

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

    long long ans = 1;
    for(int i=0; i<n; ++i){
        long long t;
        cin >> t;
        ans = lcm(ans, t);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
s = input()
s1, s2 = s[::2], s[1::2]
bwr1, bwr2 = (s1.count('0'), s1.count('1')), (s2.count('0'), s2.count('1'))
print(min(bwr1[1] + bwr2[0], bwr1[0] + bwr2[1]))


Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N=sc.nextInt();
        int MAX = 100001;
        int[] counter = new int[MAX];
        long total=0;
        for(int i=0;i<N;i++) {
            int num = sc.nextInt();
            counter[num]++;
            total+=num;
        }

        int Q=sc.nextInt();
        long[] answers = new long[Q];
        for(int i=0;i<Q;i++) {
            int B=sc.nextInt();
            int C=sc.nextInt();
            total+=(C-B)*counter[B];
            answers[i] = total;
            counter[C] += counter[B];
            counter[B]=0;
        }
        for(long inside:answers) {
            System.out.println(inside);
        }
    }
}

Measured memory_bytes: 61672
import sys
import queue

h, w = list(map(int, input().split()))
l = [input() for _ in range(h)]
checked = [[False for _ in range(w)] for __ in range(h)]

q = queue.Queue()
q.put((0, 0, 1))
while not q.empty():
    x, y, count = q.get()
    if checked[y][x]:
        continue
    checked[y][x] = True
    if x == w-1 and y == h-1:
        ans = 0
        for i in range(h):
            for j in range(w):
                if l[i][j] == ".":
                    ans += 1
        print(ans-count)
        sys.exit(0)
    if x > 0 and l[y][x-1] == "." and not checked[y][x-1]:
        q.put((x-1, y, count+1))
    if y > 0 and l[y-1][x] == "." and not checked[y-1][x]:
        q.put((x, y-1, count+1))
    if x < w-1 and l[y][x+1] == "." and not checked[y][x+1]:
        q.put((x+1, y, count+1))
    if y < h-1 and l[y+1][x] == "." and not checked[y+1][x]:
        q.put((x, y+1, count+1))
print(-1)

Measured memory_bytes: 46056
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;
 
#define Pr(f,...) //printf(f,##__VA_ARGS__),fflush(stdout)
 
typedef long long ll;
 
const int N=50;
 
bool vis[N+1];
long long ans;
int cur,n,a[N+1],b[N+1],c[N+1],m;
 
void dfs(int x){
	vis[x]=true;
	for(int y=x+1;y<=cur&&x+y<=N;++y){
		for(int j=y;x+j<=N;j+=y){
			if(!vis[x+j])dfs(x+j);
		}
	}
	rep(z,1,m){
		if(c[z]>=x+1) for (int j=c[z];x+j<=N;j+=c[z]){
			if(!vis[x+j])dfs(x+j); 
		}
	}
}
 
bool chk(){
	rep(i,1,n){
		mem(vis,0);
		dfs(b[i]);
		if(!vis[a[i]]){
			return false;
		}
	}
	return true;
}
 
int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	freopen("dat.in","r",stdin);
	freopen("my.out","w",stdout);
#endif
	cin>>n;
	rep(i,1,n)cin>>a[i];
	rep(i,1,n)cin>>b[i];
	while(true){
		for(cur=0;cur<=N;++cur){
			if(chk()){
				if(cur){
					//rep(i,1,n)a[i]%=cur;
					c[++m]=cur;
					ans+=1ll<<cur;
					//rep(i,1,n)Pr("now:(%d,%d)\n",a[i],b[i]); 
				}
				break;
			}
		}
		if(cur==N+1||cur==0)break;
	}
	printf("%lld\n",cur==N+1?-1ll:ans);
	return 0 ;
}

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

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

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

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

using namespace std;

ll h, w; 
char c[1000][1000];

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

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> h >> w;

	queue<tuple<ll, ll, ll>> q;
	ll cnt=0;
	rep(i, h){
		rep(j, w){
			cin >> c[i][j];
			if (c[i][j] == '#')
				q.push(make_tuple(i, j, 1));
			else
				cnt++;
		}
	}

	ll ans=0;

	while(q.size() && cnt){
		tuple<ll, ll, ll> p = q.front(); q.pop();
		rep(i, 4){
			ll tx = get<1>(p) + dx[i];
			ll ty = get<0>(p) + dy[i];
			ll tnum = get<2>(p);
			if (!(0<=tx && tx<w && 0<=ty && ty<h)) continue;
			if (c[ty][tx] == '.'){
				c[ty][tx] = '#';
				q.push(make_tuple(ty, tx, tnum+1));
				cnt--;
				if (cnt == 0){
					ans = tnum;
					break;
				}
			}
		}
	}

	cout << ans << "\n";

	return 0;
}


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

#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define MAX 100

int n, G[MAX + 1][MAX + 1];
int col[MAX + 1];
int d[MAX + 1], f[MAX + 1];
int t;
stack<int> S;

void init(int n) {
	for (int i = 1; i <= n; i++) {
		col[i] = WHITE;
		for (int j = 1; j <= n; j++)
			G[i][j] = 0;
	}
	t = 0;
}

void dfsvisit(int u) {
	col[u] = GRAY;
	d[u] = ++t;
	for (int v = 1; v <= n; v++)
		if (col[v] == WHITE && G[u][v])
			dfsvisit(v);
	col[u] = BLACK;
	f[u] = ++t;
}

void dfs() {
	for (int i = 1; i <= n; i++)
		if (col[i] == WHITE) dfsvisit(i);
}

void input() {
	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int v;
			cin >> v;
			G[u][v] = 1;
		}
	}
}

void output() {
	for (int i = 1; i <= n; i++)
		cout << i << " " << d[i] << " " << f[i] << endl;
}

int main() {
	cin >> n;
	init(n);
	input();
	dfs();
	output();
}



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

ai = list(map(int, input().split())) 

bi = [0] * n
ci = [0] * n

for i, aa in enumerate(ai):
    bi[i] = aa + i
    ci[i] = aa - i

# print(bi)

bi_dict = {}
ci_dict = {}
for i in range(n):
    bi_dict[bi[i]] = bi_dict.get(bi[i], 0) + 1
    ci_dict[ci[i]] = ci_dict.get(ci[i], 0) + 1

ans = 0
for b in bi_dict:
    ans += bi_dict[b] * ci_dict.get(-b, 0)
print(ans)


Measured memory_bytes: 58400
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(){
		final long STACK=8*1024*1024;
		new Thread(null, new AOJ0180(), "RUN!", STACK).start();
	}
	
	class AOJ0180 implements Runnable{
		AOJ0180(){}
		@Override public void run(){
			while(sc.hasNext()){
				int N=sc.nextInt(),E=sc.nextInt();
				if((N|E)==0)	break;
				solve(N,E);
			}
		}
		void solve(int N,int E){
			int[][] g=new int[N][N];
			for(int i=0; i<N; i++)for(int j=0; j<N; j++)g[i][j]=1<<29;
			for(int i=0; i<E; i++){
				int u=sc.nextInt(),v=sc.nextInt(),c=sc.nextInt();
				g[u][v]=c;
				g[v][u]=c;
			}
			System.out.println(prim(g,N));
		}
		
		final int INF=1<<29;
		int prim(int[][] g,int N){
			int[] mincost=new int[N];
			boolean[] used=new boolean[N];
			for(int i=0; i<N; i++)	mincost[i]=INF;
			
			mincost[0]=0;
			int ret=0;
			
			while(true){
				int v=-1;
				for(int u=0; u<N; u++){
					if(!used[u] && (v==-1 || mincost[u] < mincost[v]))	v=u;
				}
				if(v < 0)	break;
				used[v]=true;
				ret+=mincost[v];
				
				for(int u=0; u<N; u++)	mincost[u]=min(mincost[u], g[v][u]);
			}
			return ret;
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define all(x) x.begin(), v.end()
#define rall(x) x.rbegin(), x.rend()
#define PB push_back
#define F first
#define S second

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

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

	string s; cin >> s;
	int n = (int) s.size();
	int k; cin >> k;
	ll ans = 0;
	if(k == 1){
		ans = 9*(n-1);
		ans += s[0]-'0';
		cout << ans << '\n';
	}else if(k == 2){
		ans = 81*(n-2)*(n-1)/2;
		string aux(n,'0');
		for(int i = 1; i <= s[0]-'0'; i++){
			aux[0] = i+'0';
			for(int j = 1; j < n; j++){
				aux[j]='1';
				while(aux <= s && aux[j] <= '9'){
					//cout << aux << '\n';
					ans++;
					aux[j]++;
				}
				aux[j] ='0';
			}
		}
		cout << ans << '\n';
	}else{
		for(int i = 0; i < n-3; i++)
			ans += 729*(i+1)*(i+2)/2;
		
		string aux(n,'0');
		for(int i = 1; i <= s[0]-'0'; i++){
			aux[0] = i+'0';
			for(int j = 1; j < n-1; j++){
				aux[j]='1';
				while(aux <= s && aux[j] <= '9'){
					for(int k = j+1; k < n; k++){
						aux[k]='1';
						while(aux <= s && aux[k] <= '9'){
							//cout << aux << '\n';
							ans++;
							aux[k]++;
						}
						aux[k] ='0';
					}
					aux[j]++;
				}
				aux[j] ='0';
			}
		}
		cout << ans << '\n';
	}

	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#define RG register
#define IL inline
#define inf 2147483640
#define LL long long
#define pi acos(-1.0)
#define db double
using namespace std;
IL int gi()
{
	RG int res=0,w=1;
	RG char ch;
	for(ch=getchar();(ch<'0'||ch>'9')&&ch!='-';ch=getchar());
	if(ch=='-') w=-1,ch=getchar();
	for(;ch>='0'&&ch<='9';ch=getchar()) res=10*res+ch-48;
	return res*w;
}
int n;
int a1=0,a2=0;
LL ans=0;
int a[100005]={0};
int main()
{
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	n=gi();
	for(RG int i=1;i<=n;++i) a[i]=gi();
	sort(a+1,a+n+1);
	for(RG int i=n;i>1;)
		{
			if(a[i-1]==a[i])
				{
					if(a1==0) {a1=a[i];i-=1;}
					else {a2=a[i];break;}
				}
			i-=1;
		}
	printf("%lld\n",(LL)a1*(LL)a2);
	//fclose(stdin);fclose(stdout);
	return 0;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 998244353
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li q;

inline li solve() {
    li a, b;
    cin >> a >> b;

    if (a < b)swap(a, b);
    if (a == b) {
        return (a - 1) * 2;
    }
    if (a == b + 1) {
        return (b - 1) * 2;
    }
    li c = sqrt(a * b);
    if (c * c == a * b) {
        c--;
    }
    if (c * (c + 1) >= a * b) {
        return 2 * c - 2;
    }
    return 2 * c - 1;
}

int main() {
    cin >> q;
    rep(i, q) {
        cout << solve() << endl;;
    }

    return 0;
}

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



int main(){
	int n,a=0;
	string s;
	cin >> n >> s;
	for(int i=0;i<n;i++){
		if(s[i]=='R') a++;
	}
	if(n-a<a) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

int main() {
  
  //初期宣言
  int H,W;
  //HとWを読み込み
  cin >> H >>W;

  //H×Wのdataとout用の行列を定義する
  vector<vector<char>>data(H,vector<char>(W));
  
  for(int i = 0; i < H; i++ ){
    for(int j = 0; j < W; j++){
		cin >> data.at(i).at(j);      
    }
  }
  
  //判定用
  for(int i = 0; i < H; i++ ){
        
    for(int j = 0; j < W; j++){
       
       //地雷かどうかの判定
       if( data.at(i).at(j) == '#'){
         cout << '#' ;
       }
       
       //地雷出ない場合の周りの地雷の数を数えるプログラム
       else if( data.at(i).at(j) == '.' ){
         
         //回答用のdataを宣言
         int A=0;
               
      	//左上用
		if(i != 0 && j != 0){
          if(data.at(i-1).at(j-1)=='#'){
           	A++; 
          }
        }
         
        //真ん中上用
		if(i != 0){
          if(data.at(i-1).at(j)=='#'){
           	A++; 
          }
        }
         
        //右上用
		if(i != 0 && j != W-1){
          if(data.at(i-1).at(j+1) == '#'){
           	A++; 
          }
        }
         
        //左横用
		if(j != 0){
          if(data.at(i).at(j-1) == '#'){
           	A++; 
          }
        }
         
        //右横用
		if(j != W-1){
          if(data.at(i).at(j+1)=='#'){
           	A++; 
          }
        }
         
        //左下用
		if(i != H-1 && j != 0){
          if(data.at(i+1).at(j-1) == '#'){
           	A++; 
          }
        }
         
        //真ん中下用
		if(i != H-1){
          if(data.at(i+1).at(j) == '#'){
           	A++; 
          }
        }
        
        //右下用
		if(i != H-1 && j != W-1){
          if(data.at(i+1).at(j+1) == '#'){
           	A++; 
          }
        }
         
        //結果を出力 
        cout << A ;
       }
      
     else{
       cout << "error" << endl;
     }
      
    }
    //改行用
    cout << endl;
  }
  
  
}


Measured memory_bytes: 3588
import java.util.*;
import java.io.*;

public class Main {

	void solve() {
		int n = in.nextInt();
		int max = (int) 1e6;
		int[] cnt=  new int[max];
		for (int i = 0; i < n; i++) {
			int x=  in.nextInt() + 1;
			cnt[x - 1]++;
			cnt[x]++;
			cnt[x + 1]++;
		}
		int mx = 0;
		for (int i : cnt) {
			mx = Math.max(mx, i);
		}
		out.println(mx);
	}

	FastScanner in;
	PrintWriter out;

	void run() {
		in = new FastScanner();
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		public String nextToken() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextToken());
		}

		public long nextLong() {
			return Long.parseLong(nextToken());
		}

		public double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

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


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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
typedef long long ll;

int main(){
  int n,k,x,y;
  int ans = 0;
  cin >> n >> k >> x >> y;
  if(n<=k)cout << n*x << endl;
  else cout << k*x+(n-k)*y << endl;
}


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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	long long N, A, B;
	cin >> N >> A >> B;
	long long C = A + B;
	long long ans = A * (N / C);
	ans += min(N % C, A);
	cout << ans << endl;



	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
using ll = int64_t;
using Graph = vector<vector<int> >;
const ll M = 1000000007;

int main(){
    int n;
    cin >> n;
    vector<ll> x(100001,0);
    for(int i=0;i<n;i++){
        ll a;
        cin >> a;
        x.at(a)++;
    }

    ll sum=0;
    for(int i=1;i<x.size();i++){
        sum+=(i*x.at(i));
    }

    int q;
    cin >> q;
    vector<ll> ans;

    for(int i=0;i<q;i++){
        ll b,c;
        cin >> b >> c;
        x.at(c)+=x.at(b);
        sum+=(c-b)*x.at(b);
        x.at(b)=0;
        ans.push_back(sum);
    }

    for(int i=0;i<ans.size();i++) cout << ans.at(i) << endl;
}

Measured memory_bytes: 5076
#include <stdio.h>
#include <math.h>

int main(){

	int a,b,x;

	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&x);


	double rad=0.f;
	int maxV=a*a*b;

	if(x*2>maxV){
		double t=(double)2*((double)maxV-(double)x)/(double)a/(double)a;
      //printf("%lf",t);
		rad=atan2(t, a);
	}else{
		double t=2*((double)x)/a/b;
		rad=atan2(b,t);
	}
	
	printf("%lf",(rad*180.f/M_PI));
	
	return 0;

}

Measured memory_bytes: 128
#include <stdio.h>

int main(){

  int n;
  int tunnel;
  int i;
  int max;
  int incar;
  int outcar;
  char check=1;
  
  scanf("%d",&n);
  scanf("%d",&tunnel);

  max=tunnel;

  for(i=0;i<n;i++){
    scanf("%d %d",&incar,&outcar);
    tunnel+=incar;
    tunnel-=outcar;
    if(tunnel<0){
      check=0;
    }
    else if(tunnel>max){
      max=tunnel;
    }
  }

  if(check==1){
    printf("%d\n",max);
  }
  else{
    printf("0\n");
  }

  return 0;
}
    

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n; cin >> n;
	map<int, int> cnt;
	rep(i, n) ++cnt[abs(n - 2 * i - 1)];
	rep(i, n){
		int a; cin >> a; --cnt[a];
	}
	for(auto p : cnt) if(p.second){
		cout << 0 << endl;
		return 0;
	}
	ll ans = 1;
	rep(i, n / 2) ans = ans * 2 % (ll)(1e9 + 7);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4096
n,k=map(int,input().split())
def find_power(n,mod):
    # 0!からn!までのびっくりを出してくれる関数(ただし、modで割った値に対してである）
    powlist=[0]*(n+1)
    powlist[0]=1
    powlist[1]=1
    for i in range(2,n+1):
        powlist[i]=powlist[i-1]*i%(mod)
    return powlist

def find_inv_power(n):
    #0!からn!までの逆元を素数10**9+7で割ったあまりリストを作る関数
    powlist=find_power(n,10**9+7)
    check=powlist[-1]
    first=1
    uselist=[0]*(n+1)
    secondlist=[0]*30
    secondlist[0]=check
    secondlist[1]=check**2
    for i in range(28):
        secondlist[i+2]=(secondlist[i+1]**2)%(10**9+7)
    a=format(10**9+5,"b")
    for j in range(30):
        if a[29-j]=="1":
            first=(first*secondlist[j])%(10**9+7)
    uselist[n]=first
    for i in range(n,0,-1):
        uselist[i-1]=(uselist[i]*i)%(10**9+7)
    return uselist
mod=10**9+7
a=find_power(4*10**5+100,mod)
b=find_inv_power(4*10**5+100)
def combi(n,r,mod):
    if n<r:
        return 0
    elif n>=r:
        return (a[n]*b[r]*b[n-r])%(mod)
if n<=k:
    K=combi(2*n-1,n-1,mod)
    print(K)
    
else:
    K=combi(2*n-1,n-1,mod)
    for i in range(k+1,n):
        K-=combi(n-1,n-i-1,mod)*combi(n,i,mod)
    print(K%mod)
    
    

Measured memory_bytes: 50420
#include <stdio.h>
#include <string.h>

#define MAP_MIN		(2)
#define MAP_MAX		(50)

int minRoute( int upperRoute, int leftRoute );

int main(void)
{
	int h = 0;
	int w = 0;
	int cicadaCount[51][51] = {0};	// (x, y)までの蝉の最小値	TODO動的に確保したい
	int i,j;
	char inputString[51][51] = {};	// 動的に確保したい
					//[単語数][文字幅]
	// HとWを入力
	scanf("%d%d", &h, &w );
	scanf("%*c");	// バッファに残った改行の読み飛ばし
	if(( h < MAP_MIN ) ||( h > MAP_MAX ))
	{	// hが入力制限違反
		return 0;
	}
	if(( w < MAP_MIN ) ||( w > MAP_MAX ))
	{	// wが入力制限違反
		return 0;
	}
	
	// 蝉の数を入力
	for( i = 0; i < h; i++ )
	{
		scanf("%s", inputString[i]);
		scanf("%*c");
	}
	
	// 座標(0, 0)の時の蝉の数は0
	cicadaCount[0][0] = 0;
	
	// MAPの上辺にいる蝉の数をカウント
	for( i = 1; i < w; ++i )
	{
		cicadaCount[0][i] = cicadaCount[0][i-1] + (inputString[0][i]-'0');
	}
	
	// MAPの左辺にいる蝉の数をカウント
	for( i = 1; i < h; ++i )
	{
		cicadaCount[i][0] = cicadaCount[i-1][0] + (inputString[i][0]-'0');
	}
	
	// 上辺、左辺以外の蝉の数をカウント
	for( i = 1; i < h ; i++ )
	{
		for( j = 1; j < w; j++ )
		{
			cicadaCount[i][j] = minRoute( cicadaCount[i-1][j], cicadaCount[i][j-1] ) + (inputString[i][j]-'0');
		}
	}
	
	printf("%d\n", cicadaCount[h-1][w-1]);
	return 0;
}

// 上側から来るルートと左側から来るルートの、どちらがより蝉が少ないか判断する関数
int minRoute( int upperRoute, int leftRoute )
{
	if( upperRoute > leftRoute )
	{
		return leftRoute;
	}
	else
	{
		return upperRoute;
	}
}



Measured memory_bytes: 2080
#include <iostream>
#include <cstdio>

using namespace std;

int N;
int m[10][10];
long long cnt;

int main()
{
	cin >> N;
	for (int i=1; i<=N; i++)
	{
		char tmp[10];
		sprintf(tmp,"%d",i);
		string s(tmp);
		m[s[0]-'0'][s.back()-'0']++;
	}
	for (int i=1; i<=9; i++) for (int j=1; j<=9; j++) cnt+=1LL*m[i][j]*m[j][i];
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
s = input()

while len(s) > 4:
    if s[-5:] == 'dream' or s[-5:] == 'erase':
        s = s[:-5]
        continue
    elif s[-6:] == 'eraser':
        s = s[:-6]
        continue
    elif s[-7:] == 'dreamer':
        s = s[:-7]
        continue
    else:
        break
        
if len(s) == 0:
    print('YES')
else:
    print('NO')
    

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    array<int, 5> a;
    rep(i, 0, 5) cin >> a[i];
    array<int, 5> order = {0, 1, 2, 3, 4};
    int ans = INT_MAX;
    do
    {
        int time = 0;
        rep(i, 0, 5)
        {
            time += a[order[i]];
            if (i < 4)
            {
                while (time % 10 != 0) ++time;
            }
        }
        chmin(ans, time);
    }
    while (next_permutation(order.begin(), order.end()));
    cout << ans << endl;
}


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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define fst first
#define snd second
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e20;
const int INF = 1e9;
const double EPS = 0.000000001;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string l;
  cin >> l;
  ll n = l.size();
  VL dp1(n+1), dp2(n+1);
  dp1[0] = 1;
  dp2[0] = 2;
  REP(i, n-1){
    if(l[i+1] == '1'){
      dp1[i+1] = dp1[i] * 3 % MOD + dp2[i] % MOD;
      dp2[i+1] = dp2[i] * 2 % MOD;
      dp1[i+1] = dp1[i+1] % MOD;
      dp2[i+1] = dp2[i+1] % MOD;
    }
    else {
      dp1[i+1] = dp1[i] * 3 % MOD;
      dp2[i+1] = dp2[i] % MOD;
      dp1[i+1] = dp1[i+1] % MOD;
      dp2[i+1] = dp2[i+1] % MOD;
    }

  }
  out((dp1[n-1] + dp2[n-1]) % MOD);

  return 0;
}


Measured memory_bytes: 2000
using System;
using System.Linq;
using static System.Console;

namespace Contest
{
    class Program
    {
        public static void Main(string[] args)
        {
            var n = int.Parse(ReadLine());
            int[][] data = new int[n][];
            for (int i = 0; i < n; i++)
            {
                data[i] = ReadLine().Split().Select(int.Parse).ToArray();
            }

            for (int i = 0; i < n - 1; i++)
            {
                for (int j = i + 1; j < n; j++)
                {
                    var dice = new Dice(data[i]);
                    int top = data[j][0], forward = data[j][1];
                    SearchNumber(dice, top, forward);
                    if (dice.Data.SequenceEqual(data[j]))
                    {
                        WriteLine("No");
                        return;
                    }
                }
            }

            WriteLine("Yes");
        }

        public static void SearchNumber(Dice dice, int top, int forward)
        {
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    if (dice.GetNumber() == top && dice.GetNumber(1) == forward) return;
                    if (dice.GetNumber(1) == forward) break;
                    dice.RollDice('N');
                }
                dice.RollDice('W');
            }
        }
    }

    class Dice
    {
        public int[] Data { get; set; }
        public int X { get; set; } = 0;
        public int Y { get; set; } = 0;
        public Dice(int[] data)
        {
            Data = data;
        }

        public void RollDice(char c)
        {
            // 0: Top
            // 5: Bottom
            // 1: Forward
            // 4: Back
            // 3: Left
            // 2: Right
            int tmp;
            switch (c)
            {
                case 'N': { tmp = Data[0]; Data[0] = Data[1]; Data[1] = Data[5]; Data[5] = Data[4]; Data[4] = tmp; break; }
                case 'S': { tmp = Data[0]; Data[0] = Data[4]; Data[4] = Data[5]; Data[5] = Data[1]; Data[1] = tmp; break; }
                case 'W': { tmp = Data[0]; Data[0] = Data[2]; Data[2] = Data[5]; Data[5] = Data[3]; Data[3] = tmp; break; }
                case 'E': { tmp = Data[0]; Data[0] = Data[3]; Data[3] = Data[5]; Data[5] = Data[2]; Data[2] = tmp; break; }
                default: break;
            }
        }

        public int GetNumber(int number = 0)
        {
            return Data[number];
        }

    }
}


Measured memory_bytes: 18348
N = int(input())
A = list(map(int, input().split()))
m = max(A)+10
dp = [0] * m

for x in A:
    dp[x] += 1

ans = 0
for i in range(1, m):
    if dp[i]:
        if dp[i] == 1:
            ans += 1
        for j in range(i, m, i):
            dp[j] = 0
print(ans)



Measured memory_bytes: 106040
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 503;

int n;
int a[N];
int num[N];
int id[N*N];

bool cmp(int x,int y){return a[x]<a[y];}

int main(){
	n=get();
	fo(i,1,n)a[i]=get();
	fo(i,1,n)num[i]=i,id[a[i]]=i;
	sort(num+1,num+1+n,cmp);
	fo(i,1,n){
		int cnt=num[i]-1;
		fo(j,1,a[num[i]])
		if (!id[j]&&cnt){
			id[j]=num[i];
			cnt--;
			if (!cnt)break;
		}
	}
	fd(i,n,1){
		int cnt=n-num[i];
		fd(j,n*n,a[num[i]])
		if (!id[j]&&cnt){
			id[j]=num[i];
			cnt--;
			if (!cnt)break;
		}
	}
	bool ans=1;
	fo(i,1,n*n)if (!id[i])ans=0;
	if (ans){
		printf("Yes\n");
		fo(i,1,n*n)printf("%d%c",id[i],i<n*n?' ':'\n');
	}
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <stdio.h>

using namespace std;

int main(){
   int n, x;
   int cnt=0;
   
   while(true){
      cnt=0;
      cin >> n >> x;
      
      if(n==0 && x==0) break;
      
      for(int i=1;i<=n;i++){
          for(int j=i+1;j<=n;j++){
              for(int k=j+1;k<=n;k++){
                  if(i+j+k==x){ cnt++; }
              }
          }
      }
      
      cout << cnt << endl;
   }
   
   return 0;
}


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

int main(){
    int s=0,t=0,a,b;
    cin>>a>>b;
    for(int i=0;i<1000;i++){
        s+=i;
        t+=i+1;
        if(s-a==t-b) cout<<s-a<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int dp[2001],n,m,a;
int main(void){
    cin>>n;
    dp[0]=1;
    for(int i=0;i<n;i++){
        cin>>a;
        for(int j=2000-a;j>=0;j--){
            if(dp[j]==1)dp[j+a]=1;
        }
    }
    cin>>m;
    for(int i=0;i<m;i++){
        cin>>a;
        if(dp[a]==1)cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
}



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

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> ps(n);
  for (int i = 0; i < n; ++i) {
    cin >> ps[i];
  }

  sort(ps.begin(), ps.end());

  int result = 0;
  for (int i = 0; i < k; ++i) {
    result += ps[i];
  }

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 3624
n = int(input().strip())
s = [input().strip() for _ in range(n)]
m = int(input().strip())
t = [input().strip() for _ in range(m)]
ans = 0

for i in range(n):
    tmp = s[i]
    cnt = 0
    for j in range(n):
        if s[j] == tmp:
            cnt += 1

    for j in range(m):
        if t[j] == tmp:
            cnt -= 1
    ans = max(ans, cnt)
print(ans)


Measured memory_bytes: 38768
import re
N,Q=[int(e) for e in input().split(' ')]
S=input()
qs=[]
for i in range(Q):
    qs.append([int(e) for e in input().split(' ')])

sts=[0]*N
for i in range(N):
    if i>0:
        if S[i-1:i+1]=='AC':
            sts[i]=sts[i-1]+1
        else:
            sts[i]=sts[i-1]
for q in qs:
    print(sts[q[1]-1]-sts[q[0]-1])


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define sz(X) (int)(X).size()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define forab(i, a, b) for(int i = int(a); i < int(b); i++)
#define all(X) X.begin(), X.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef double dbl;
typedef long double ld;
typedef vector<int> vi;
typedef vector<pair<ll, ll>> vpll;

mt19937 tw(566);
uniform_int_distribution<ll> ll_distr;

ll rnd(ll a, ll b) {
    return ll_distr(tw) % (b - a + 1) + a;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll r, g, b;
    cin >> r >> g >> b;
    ll k;
    cin >> k;
    while (k > 0 && g <= r) g *= 2, k--;
    while (k > 0) b *= 2, k--;
    if (b > g && g > r) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 3656
#include <stdio.h>
int main(void)
{
	long long int dp[51][5001] = {{0}};		// i個から0枚以上選んで合計をt - 50 * 50にする選び方の総数(負数を考慮)
	int i, t, A, N, x, y;

	dp[0][2500] = 1;
	scanf("%d%d", &N, &A);
	for (i = 1; i <= N; i++) {
		scanf("%d", &x);
		y = x - A;
		for (t = 0; t <= 5000; t++) {
			if (t - y < 0 || t - y > 5000)
				dp[i][t] = dp[i - 1][t];
			else
				dp[i][t] = dp[i - 1][t] + dp[i - 1][t - y];
		}
	}

	// 一枚も選ばないパターンを除く
	printf("%lld\n", dp[N][2500] - 1);

	return 0;
}

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

ll n,k,A[100010];

ll check(ll mid){
  int i=0;
  for(int j=0;j<k;j++){
    ll s=0;
    while(s+A[i]<=mid){
      s+=A[i];
      if(i>=n){return n;}
      i++;
    }
  }
  return i;
}


ll search(){
  ll left=0;
  ll right=100010*10000;
  ll mid;
  while(left<right){
    mid=(left+right)/2;
    if(check(mid)>=n){right=mid;}
    else{
      left=mid+1;
    }
  }
  return right;
}

int main(){
  cin>> n>>k;
  for(int i=0;i<n;i++){
    cin>>A[i];
  }
  cout << search()<<endl;
}


Measured memory_bytes: 3856
A=int(input())
B=int(input())
C=int(input())
X=int(input())
ans=0
for i in range(0,A+1):
    for j in range(0,B+1):
        for k in range(0,C+1):
            if 500*i+100*j+50*k==X:
                ans+=1

print(ans)

Measured memory_bytes: 9192
import java.util.*;

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

      int N=sc.nextInt();

      int[] A = new int[N+1];
      int[] B = new int[N];

      for(int i=0;i<N+1;i++){
        A[i]=sc.nextInt();
      }
      for(int i=0;i<N;i++){
        B[i]=sc.nextInt();
      }

      long cnt=0;

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

if(A[i]>=B[i]){
//////////////////////////////////
cnt = cnt + B[i];
/////////////////////////////////
}

if(A[i]<B[i]){
//////////////////////////////////
cnt = cnt + A[i];
B[i] = B[i] - A[i];
  if(A[i+1]>=B[i]){
    cnt = cnt + B[i];
    A[i+1] = A[i+1] - B[i];
  }
  else{
    cnt = cnt + A[i+1];
    A[i+1] = 0;
  }
/////////////////////////////////
}

}

System.out.println(cnt);


    }
}


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

const ll INF = 1e11;
const int MAX_V = 10;

// dp[i][j]: iから（kを通って）jまでの最短距離
// kの次元は使い回せるので省略できる
int dp[MAX_V][MAX_V];

void wf() {
  rep(i, 10) rep(j, 10) rep(k, 10) {
    dp[j][k] = min(dp[j][k], dp[j][i] + dp[i][k]);
  }
}

int main() {
  int H, W;
  cin >> H >> W;

  rep(i, 10) rep(j, 10) cin >> dp[i][j];
  wf();

  int ans = 0;
  rep(i, H) rep(j, W) {
    int a;
    cin >> a;
    if (a != -1) ans += dp[a][1];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
typedef long long int ll;

int main(){
	int cnt[4]={};
	for(int i=0;i<6;i++){
		int t ;cin >> t;
		cnt[t-1]++;
	}
	if(cnt[0]*cnt[1]*cnt[2]*cnt[3]>0&&cnt[0]<3&&cnt[1]<3&&cnt[2]<3&&cnt[3]<3){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
import java.io.*;

class Main{
	public static void main(String[]args)throws IOException{
		
		BufferedReader br=
			new BufferedReader(new InputStreamReader(System.in));
		
		String str=br.readLine();
		
		int x =Integer.parseInt(str);
		
		System.out.println(x*x*x);
	}
}

Measured memory_bytes: 24260
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    set<char> st;
    rep(i, 3) {
        char c; cin >> c;
        st.insert(c);
    }

    cout << (st.size() > 1 ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(" ").Select(int.Parse).ToArray();
        var N = input[0];
        var M = input[1];

        var E = new int[N + 1];

        for (var i = 0; i < M; i++)
        {
            var AB = Console.ReadLine().Split(" ").Select(int.Parse).ToArray();

            E[AB[0]] += 1;
            E[AB[1]] += 1;
        }

        for (var i = 1; i <= N; i++)
        {
            Console.WriteLine(E[i]);
        }
    }
}


Measured memory_bytes: 28204
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include<bits/stdc++.h>

using namespace std;

typedef long long  ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;

#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define ins insert
#define pi  3.14159265359
#define mod 1000000007
#define si(x) int(x.size())
#define FOOR(i, a, b)  for (int i=a; i<=(b); i++)
#define FOR(i, a)  for (int i=0; i<(a); i++)
#define FOORd(i,a,b)  for (int i = (b)-1; i >= a; i--)
#define FORd(i,a)  for (int i = (a)-1; i >= 0; i--)

int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    int n;
    cin>>n;
    string s;
    cin>>s;
    vector<int>w;
    vector<int>r;
    for(int i=0;i<si(s);i++)
    {
        if(s[i]=='R')
            r.push_back(i+1);
        else
            w.push_back(i+1);
    }
    int ans=0;
    sort(all(r),greater<int>());
    for(int i=0;i<min(si(r),si(w));i++)
    {
            if(r[i]>w[i]){
             ans++;
            }

    }
        cout<<ans<<endl;
}



















Measured memory_bytes: 4656
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define l_cin2(X,Y) scanf("%ld %ld",&X,&Y)
#define s_cin(X) scanf("%s",&X)

#define  i_cout(X) printf("%d\n",X)
#define  i_cout2(X,Y) printf("%d %d\n",X,Y)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)
#define  ll_cout(X) printf("%lld\n",X)

typedef long long int lli;
#define rept(x, s, n) for (int x = s; x < n; x++)


int i_cins(int n, int* A);
int l_cins2(int n, long* A,long* B);
int s_dsort(const void* a, const void* b);

int main(void) {
	int   N,L[50],K,max=0,i;

	i_cin2(N,K);
	i_cins(N, L);
	
	qsort((void*)L, N, sizeof(L[0]), s_dsort);
	rept(i, 0, K)
		max+=L[i];

	i_cout(max);

	return 0;
}

//降順
int s_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
//
int l_cins2(int n, long* a, long* b) {
	int i;
	rept(i, 0, n) {
		l_cin2(*(a + i), *(b + i));
	}
	return 0;
}
int i_cins(int n, int* a) {
	int i;
	rept(i, 0, n) {
		i_cin(*(a + i));
	}
	return 0;
}



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

int A[51];

void func(int n){
  if(n==50) return;
  A[n]=A[n-1]+A[n-2];
  func(n+1);
}

int main(){
  int n;
  cin >> n;
  A[0]=1; A[1]=1;
  func(2);

  cout << A[n] << endl;
}

Measured memory_bytes: 3080
#include "bits/stdc++.h"
using namespace std;
#define REP(m,n) for(int i=m;i<n;i++)
#define REPj(m,n) for(int j=m;j<n;j++)
#define MOD 1000000007
#define INF 10000000000000000
#define ll long long
#define mp make_pair

vector<string>v;

int main(){
	int x,y,a,b;
	cin>>x>>y;
	switch(x){
	case 2:a=1;break;
	case 4:a=2;break;
	case 6:a=2;break;
	case 9:a=2;break;
	case 11:a=2;break;
	default:a=3;break;
	}
	switch(y){
	case 2:b=1;break;
	case 4:b=2;break;
	case 6:b=2;break;
	case 9:b=2;break;
	case 11:b=2;break;
	default:b=3;break;
	}
	if(a==b){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256