akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

const int MOD = 1000000007;

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// ax + by = gcd(a, b) となるような (x, y) を求める
// 多くの場合 a と b は互いに素として ax + by = 1 となる (x, y) を求める
long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a%b, y, x); // 再帰的に解く
    y -= a / b * x;
    return d;
}

// 負の数にも対応した mod (a = -11 とかでも OK) 
inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}

// 逆元計算 (ここでは a と m が互いに素であることが必要)
long long modinv(long long a, long long m) {
    long long x, y;
    extGCD(a, m, x, y);
    return mod(x, m); // 気持ち的には x % m だが、x が負かもしれないので
}

int main(){
    long long n, a, b;
    long long com1 = 1;
    long long com2 = 1;
    long long nibeki = 1;
    cin >> n >> a >> b;
    nibeki = modpow(2, n, MOD);
    for(long long i = 1; i < a + 1; i++){
        com1 = (((com1 *(n - (i - 1))) % MOD) * modinv(i,MOD)) % MOD;
    }
    com2 = com1;
    for(long long i = a + 1; i < b + 1; i++){
        com2 = (((com2 *(n - (i - 1))) % MOD) * modinv(i,MOD)) % MOD;
    }
    if((((nibeki - 1 - com1) % MOD) - com2) % MOD >= 0){
        cout << (((nibeki - 1 - com1) % MOD) - com2) % MOD << endl;
    }
    else{
        cout << ((((nibeki - 1 - com1) % MOD) - com2) % MOD) + MOD << endl;
    }
    return 0;
}

Measured memory_bytes: 384
### SNIPPET
  # n = gets.split.map(&:to_i)
  # array = n.times.map { gets.split.map(&:to_i) }
  # [].all?(&:even?)
  # a = [*1..m].repeated_combination(n).to_a
  # [1,2,3,4,5].select { |num| num.even? }  # => [2, 4]
  # ["a","a","b"].group_by(&:itself).map{|k,v| [k, v.count]}.to_h #=> {"a"=>2, "b"=>1}
  # 切り捨て: .floor(2).to_f ,切り上げ： .ceil(2).to_f,四捨五入: round(2)
  # 3.upto(6) do |i|, 6.downto(3) do |i|
  # 公約数125.gcd(100)、公倍数125.lcm(100)
  # PI = Math::PI
  # 高さ = a * Math.sin(w / 180.0 * Math::PI), 底辺 = a * Math.cos(w / 180.0 * Math::PI)
  # def chmax(a, b) a > b ? a : b end
  # INF = Float::INFINITY
  # def chmin(a, b) a < b ? a : b end

n = gets.to_i

sum = 0
n.times do |i|
  sum += 1 if (i+1) % 2 == 1
end

puts sum / n.to_f

Measured memory_bytes: 14304
N = int(input())

def solve_function(N):
    if N % 2 == 1:
        return 0

    it_can_be_divisible = 10
    ans = 0
    while True:
        if it_can_be_divisible > N:
            break
        ans += N//it_can_be_divisible
        it_can_be_divisible *= 5

    return ans

if solve_function(N):
    print(solve_function(N))
else:
    print(0)

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

ll mod=1e9+7;
ll LLpow(ll a, ll b){
    if(b==0) return 1;
    else{
        if(b&1){
            return a*LLpow(a,b-1)%mod;
        }else{
            ll mul=LLpow(a,b/2)%mod;
            return mul*mul%mod;
        }
    }
}

ll prefix[200010]={0},ori[200010]={0};

int main(){
    ll n,sum=0,res=0;
    scanf("%lld",&n);
    for(ll i=0;i<n;i++){
        ll s;
        scanf("%lld",&s);
        ori[i]=s;
        sum+=s;
        sum%=mod;
        prefix[i]=sum;
        //sum=((sum%mod)*(LLpow(s,i+1)%mod))%mod;
    }
    for(ll i=0;i<n;i++){
        res=(res+((ori[i]%mod)*(prefix[n-1]-prefix[i]+mod)%mod))%mod;
        res%=mod;
    }
    printf("%lld",res);
    return 0;
}


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

const int N = 505;
const int M = 1e5 + 50;

int n, m, s, t, x[N], col[N];
int head[N], nxt[M], ver[M], edge[M], d[N], cur[N], cnt = 1;

inline void add(int u, int v, int w)
{
	nxt[++cnt] = head[u], ver[cnt] = v, edge[cnt] = w, head[u] = cnt;
	nxt[++cnt] = head[v], ver[cnt] = u, edge[cnt] = 0, head[v] = cnt;
}

inline bool bfs()
{
	memset(d, 0, sizeof d); memcpy(cur, head, sizeof head);
	std::queue<int> Q;
	Q.push(s); d[s] = 1;
	while (Q.empty() == false)
	{
		int x = Q.front(); Q.pop();
		for (int i = head[x]; i; i = nxt[i])
		{
			int y = ver[i];
			if (edge[i] && !d[y])
			{
				d[y] = d[x] + 1;
				if (y == t) return true;
				Q.push(y);
			}
		}
	}
	return false;
}

inline int dinic(int x, int flow)
{
	if (x == t) return flow;
	int rest = flow, k = 0;
	for (int &i = cur[x]; i; i = nxt[i])
		if (edge[i] && d[ver[i]] == d[x] + 1)
		{
			k = dinic(ver[i], std::min(rest, edge[i]));
			edge[i] -= k, edge[i ^ 1] += k, rest -= k;
			if (!k) d[ver[i]] = 0;
			if (!rest) break;
		}
	return flow - rest;
}

inline bool isPrime(int x)
{
	if (x == 0 || x == 1) return false;
	if (x == 2) return true;
	if (!(x & 1)) return false;
	for (int i = 3; i * i <= x; i += 2) if (x % i == 0) return false;
	return true;
}

inline char nc()
{
	static char buf[1000000], *p1 = buf, *p2 = buf;
	return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++;
}

inline int read()
{
	int res = 0, neg = 1; char ch;
	do
	{
		ch = nc();
		if (ch == '-') neg = -1;
	} while (ch < 48 || ch > 57);
	do res = res * 10 + ch - 48, ch = nc(); while (ch >= 48 && ch <= 57);
	return res * neg;
}

int main()
{
	n = read();
	static int pos[N], _t;
	for (int i = 1; i <= n; ++i)
	{
		x[i] = read();
		if (i == 1 || x[i] != x[i - 1] + 1) pos[++_t] = x[i];
		if (i != 1 && x[i] != x[i - 1] + 1) pos[++_t] = x[i - 1] + 1;
	}
	pos[++_t] = x[n] + 1;
	s = _t + 1, t = s + 1;
       	int count = 0;
	for (int i = 1; i <= _t; ++i)
		if (pos[i] & 1) add(s, i, 1), ++count;
		else add(i, t, 1);
	for (int i = 1; i <= _t; ++i) if (pos[i] & 1) for(int j = 1; j <= _t; ++j) if (!(pos[j] & 1))
	{
		if (isPrime(abs(pos[i] - pos[j])))
		{
			add(i, j, 1);
		}
	}
	int maxflow = 0, flow = 0;
	while (bfs()) while (flow = dinic(s, 0x3f3f3f3f)) maxflow += flow;
	int Mo = count, Me = _t - Mo, k = maxflow;
	printf("%d\n", k + ((Me - k) / 2 + (Mo - k) / 2) * 2 + ((Me - k) % 2) * 3);
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#define MAX(X, Y) (((X) > (Y))? (X) : (Y))
#define MIN(X, Y) (((X) < (Y))? (X) : (Y))
int compare_int(const void *a, const void *b){
  return *(long int*)b - *(long int*)a; // 大きい順
}
int compare_int_small(const void *a, const void *b){
  return *(long int*)a - *(long int*)b; // 小さい順
}
// 公約数
long long int gcd(long long int a, long long int b){
  if(b == 0){
    return a;
  }else{
    return gcd(b, a % b);
  }
}
// 最小公倍数 = a * b / 最大公約数
// 公倍数
long long int lcm(long long int a, long long int b){
  return a * b / gcd(a, b);
}

#define TRUE 1
#define FALSE 0
#define MAX_NUM 100002
typedef struct pp{
  char c;
  int h;
  int w;
}P;

int top = 0;
P *Stack = NULL;
P *tmp = NULL;


void initialize(){
  Stack = (P *)calloc(MAX_NUM, sizeof(P));
  top = 0;
}

void finalize(){
  if(Stack != NULL){
    free(Stack);
    Stack = NULL;
  }
}

int isEmpty(){
  if(top <= 0){
    return TRUE;
  }else{
    return FALSE;
  }
}

int isFull(){
  if(top > MAX_NUM - 1){
    return TRUE;
  }else{
    return FALSE;
  }
}

int push(P x){
  fprintf(stderr, "pushするのは%c (h, w) = (%d, %d)\n", x.c, x.h, x.w);
  //printf("push x = %d\n",x);
  if(isFull() != FALSE){
    //    fprintf(stderr, "pushしたのは%d top = %d\n", Stack[top], top);
    printf("Error! Overfllow\n");
    return 0;
  }else{
    top++;
    if(Stack != NULL){
      Stack[top] = x;
    }
    return 0;
  }
}

P pop(){
  if(isEmpty() != FALSE){
    printf("Error! Underfllow\n");
    return *tmp;
  }else{
    top--;
    // return では取りだす値を返す
    //    fprintf(stderr, "popしたのは%d top = %d\n", Stack[top + 1], top);
    return Stack[top+1];
  }
}

// min
int main(void){
  int n, d;
  long long ans = 1;
  int *A = NULL;
  long int max = 0;

  scanf("%d", &n);
  //  printf("n = %d\n", n);
  
  A = (int *)calloc(n, sizeof(int));
  if(A == NULL){
    fprintf(stderr, "メモリが確保できません.\n");
    exit(EXIT_FAILURE);
  } 

  //  printf("n = %d\n", n);
  
  for(int i = 0; i < n; i++){
    scanf("%d", &d);
    A[d]++;
    //    printf("d = %d n = %d\n", d, n);
    if(max < d){
      max = d;
    }
    if(i == 0 && d != 0){
      printf("0\n");
      return 0;
    }
  }

  // 0が0はだめ。頂点がない
  if(A[0] <= 0){
    printf("0\n");
    return 0;
  }
  // 0 が2個以上だとだめ。頂点は2つもない
  if(A[0] > 1){
    printf("0\n");
    return 0;
  }
  if(n >= 1){
    for(int i = 1; i <= max; i++){
      if(A[i] == 0){
	printf("0\n");
	return 0;
      }
      for(int j = 0; j < A[i]; j++){
	ans = ans * A[i - 1] % 998244353;
	/*
	if(ans > 998244353){
	  ans %= 998244353;
	}
	*/
	/*
	if(A[i - 1] > 998244353){
	  A[i - 1] %= 998244353;
	}
	*/
      }
  
    }
  }
  /*
  if(ans > 998244353){
    ans %= 998244353;
  }
  */

  printf("%lld\n", ans);
  if(A != NULL){
    free(A);
    A = NULL;
  }
  
  return 0;

}


Measured memory_bytes: 512
#include <iostream>
#include <queue>
using namespace std;
typedef long long int llf;
typedef pair<int,int> pr;
typedef pair<pr,pr> ppr;
typedef pair<pr,ppr> pppr;
const int INF=2<<26;
int DP[13][13][13][13][60]={},maps[11][11]={};
int W,H;
pppr pf(int a,int ab,int b,int c,int d,int e){
	return pppr(pr(a,ab),ppr(pr(b,c),pr(d,e)));
}
int money(int nx,int ny,int sx,int ex){
	if(nx<sx || nx>ex ||(nx==ex && ex==sx))
		if(nx>=0 && nx<W && ny<H && ny>=0 && maps[ny][nx]<0)
			return -maps[ny][nx];
	return 0;
}
int hydro(int nx,int ny,int sx,int ex){
	if(nx<sx || nx>ex ||(nx==ex && ex==sx))	
		if(nx>=0 && nx<W && ny<H && ny>=0&& maps[ny][nx]>=0)
			return maps[ny][nx];
	return 0;
}
int main() {
	// your code goes here
	while(cin >> W >> H && W!=0){
		int f=0,m=0,o=0,ans=INF;
		cin >> f >> m >> o;
		for(int i=0;i<11;i++)
			for(int j=0;j<11;j++)
				maps[i][j]=-INF;
		for(int i=0;i<H;i++)
			for(int j=0;j<W;j++)
				cin >> maps[i][j];
		for(int i=0;i<13;i++)
			for(int j=0;j<13;j++)
				for(int k=0;k<13;k++)
					for(int l=0;l<13;l++)
						for(int h=0;h<60;h++)
							DP[i][j][k][l][h]=INF;
		priority_queue<pppr,vector<pppr> > qu;
		if(o<=1){
			cout << "NA" << endl;
			continue;
		}
		for(int i=0;i<W;i++)
		DP[i][i][i][0][min(m,hydro(i,0,i,i)+o)-1]=money(i,0,i,i);
		for(int i=0;i<=H;i++){
			for(int j=0;j<W;j++)
				for(int k=m;k>=0;k--)
					if( DP[j][j][j][i][k]<DP[j][j][j][i][k+1])
						qu.push(pf(i,DP[j][j][j][i][k],k,j,j,j));
					else
						DP[j][j][j][i][k]=DP[j][j][j][i][k+1];
		while(!qu.empty()){
			int ab=qu.top().first.second,y=qu.top().first.first,hy=qu.top().second.first.first;
			int sx=qu.top().second.second.first,ex=qu.top().second.second.second,nx=qu.top().second.first.second,mo=DP[nx][sx][ex][y][hy];
			qu.pop();
			if(y>=H){
				ans=min(ans,mo);
				continue;
			}
			if(DP[nx][sx][ex][y][hy]==DP[nx][sx][ex][y][hy+2]) continue;
			if(mo!=ab) continue;
			if(hy==0) continue;
			int nh=min(m,hy+hydro(nx-1,y,sx,ex)-1),price=0;
			price=mo+money(nx-1,y,sx,ex);
			if(hy!=1 && nx>0 && DP[nx-1][sx-(nx==sx)][ex][y][nh]>price){
				DP[nx-1][sx-(nx==sx)][ex][y][nh]=price;
				qu.push(pf(y,price,nh,nx-1,sx-(nx==sx),ex));
			}
			nh=min(m,hy+hydro(nx+1,y,sx,ex)-1);
			price=mo+money(nx+1,y,sx,ex);
			if(hy!=1 && nx+1<W && DP[nx+1][sx][ex+(nx==ex)][y][nh]>price){
				DP[nx+1][sx][ex+(nx==ex)][y][nh]=price;
				qu.push(pf(y,price,nh,nx+1,sx,ex+(nx==ex)));
			}
			nh=min(m,hy+hydro(nx,y+1,nx,nx)-1);
			price=mo+money(nx,y+1,nx,nx);
			if(hy!=1 || y==H-1)
			DP[nx][nx][nx][y+1][nh]=min(DP[nx][nx][nx][y+1][nh],price);
		}
		}
		if(ans>f)
			cout <<"NA"<<endl;
		else
			cout << ans <<endl;
	}
	return 0;
}

Measured memory_bytes: 7900
N,K=map(int,input().split())
alist=list(map(int,input().split()))

len_K=40
bin_K_str = format(K, '040b')
#print(bin_K_str)

a0list=[0]*len_K
a1list=[0]*len_K
for a in alist:
  bin_a_str = format(a, '040b')
  
  for i in range(len_K):
    a_bit = bin_a_str[i]
    if a_bit == "0":
      a0list[i] += 1
    elif a_bit == "1":
      a1list[i] += 1
#print(a0list)
#print(a1list)

minor_list = [-1]*len_K
for i in range(len_K):
  if a0list[i] > a1list[i]:
    minor_list[i] = 1
  else:
    minor_list[i] = 0
#print(minor_list)

equal = True
dp = [-1]*len_K
for i in range(len_K):
  if not equal:
    dp[i] = minor_list[i]
  else:
    if bin_K_str[i] == "1":
      if minor_list[i] == 0:
        dp[i] = 0
        equal = False
      else:
        dp[i] = 1
    else:
      dp[i] = 0
#print(dp)

argmax = 0
pow2 = 1
for d in reversed(dp):
  if d == 1:
    argmax += pow2
  pow2 *= 2
#print(argmax)

fmax=0
for a in alist:
  fmax += argmax ^ a
  
print(fmax)

Measured memory_bytes: 14660
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<vector>
#include<complex>
#include<deque>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,b,a) for(int i=b;i>=a;--i)
#define gcd(a,b) __gcd(a,b)
#define MEM(a,x) memset(a,x,sizeof(a))
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
const int N=1e5+5;
template<class T>inline void read(T &res)
{
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
ll n,m;
int main(){
	cin>>n>>m;
	if(n==1||m==1){
		cout<<1<<endl;
		return 0;
	}
	cout<<(n*m+1)/2<<endl;
	return 0;
}


Measured memory_bytes: 256
import itertools
n,m,x= map(int,input().split())
ab = []
for _ in range(n):
    t = list(map(int,input().split()))
    ab.append(t)

ans = 1000000000
for i in range(1,n+1):
    for v in itertools.combinations(ab, i):
        memo = [0]*(m+1)
        for k in v:
            for l in range(m+1):
                memo[l] += k[l]
            flag = True
            for o in range(1,m+1):
                if memo[o] < x:
                    flag = False
        if flag:
            ans=min(memo[0],ans)

if ans == 1000000000:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 68540
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  ll N;
  cin >> N;
  ll ans = 1;
  unordered_map<ll, ll> mp;
  mp[-1] = 3;
  rep (i, N) {
    ll A;
    cin >> A;
    ans *= mp[A-1];
    ans %= MOD;
    mp[A-1]--;
    mp[A]++;
  }
  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 4388
//参考：https://qiita.com/DaikiSuyama/items/9dba963ba74396b9b7fd
//インクルード(アルファベット順)
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define FIR first    //pairの一つ目の要素
#define SEC second   //pairの二つ目の要素

signed main()
{
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;

    ll A[N];
    REP(i, N)
    {
        cin >> A[i];
    }

    ll ans = 0;
    while (true)
    {
        REP(i, N)
        {
            if (A[i] % 2 == 0)
            {
                A[i] /= 2;
            }
            else
            {
                cout << ans << endl;
                return 0;
            }
        }
        ans++;
    }

    cout << ans << endl;

    return 0;
}


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

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

#ifdef LOCAL
  #define eprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define eprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

int ctoi(char c) {
  return c - '0';
}

template <class C>
void printContainer(C &container, const char *delim=",") {
  for(const auto &e : container) {
    std::cout << e << delim;
  }
  std::cout << "\n";
}

// Greatest common divisor
template<class T>
T gcd(T x, T y) {
  if(x < y) {
    std::swap(x, y);
  }
  T r = x % y;
  while(r != 0) {
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

// Least common multiple
template<class T>
T lcm(T x, T y) {
  return (x*y)/gcd(x,y);
}

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if(b - a == c - b) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

        if(a+W < b){
            System.out.println(b-(a+W));
        }else if(b+W < a){
            System.out.println(a-(b+W));
        }else if(a+W>=b || b+W>=a){
            System.out.println("0");
        }
    }
}

Measured memory_bytes: 23764
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())

// code
// ------------------------------------------------
int main() {
  int a,b;
  cin >> a >> b;
  cout << max( max(a + b, a - b) , a * b );
  
  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}
const int INF = 1e18;

signed main() {
    int N;
    cin >> N;
    V(P) res;
    if(N%2) {
        rep(i, N-2) {
            FOR(j, i+1, N-1) {
                if(i+j+2==N) continue;
                res.pb(P(i+1, j+1));
            }
        }
        rep(i, N-1) {
            res.pb(P(i+1, N));
        }
    } else {
        rep(i, N-1) {
            FOR(j, i+1, N) {
                if(i+j+2==N+1) continue;
                res.pb(P(i+1, j+1));
            }
        }
    }

    cout << res.size() << endl;
    rep(i, res.size()) cout << res[i].fi << " " << res[i].se << endl;

    /*vi ch(N, 0);
    rep(i, res.size()) {
        ch[res[i].fi-1] += res[i].se;
        ch[res[i].se-1] += res[i].fi;
    }

    rep(i, N) cout << ch[i] << " ";
    cout << endl;*/

    return 0;
}

Measured memory_bytes: 512
from collections import Counter
n = int(input())
counter = Counter(list(map(int, input().split())))
ans = n
cnt = 0
for v in counter.values():
    if v % 2 == 0:
        if v >= 3:
            ans -= v - 2
        cnt += 1
    else:
        ans -= v - 1

ans -= cnt + cnt % 2
print(ans)


Measured memory_bytes: 18648
const main = stdin => {
  const input = stdin.trim().split('\n')
  const N = parseInt(input[0])
  const [T, A] = input[1].split(' ').map(x => parseInt(x))
  const Hs = input[2].split(' ').map(x => parseInt(x))

  let min = 99999999
  let minIdx = -1
  for (let i = 0; i < N; i++) {
    const temp = T - Hs[i] * 0.006
    const diff = Math.abs(A - temp)
    if (diff < min) {
      min = diff
      minIdx = i
    }
  }

  console.log(minIdx + 1)
}
// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 30516
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = 998244353;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T, class T2> void smin(T& a, T2 val) {if (a > val) a = val;}template<class T, class T2> void smax(T& a, T2 val) {if (a < val) a = val;}
const int N = 3*(int)1e3 + 10;

int n, a[N], s;

int32_t main(){_
   
   cin>>n>>s;

   for (int i = 0; i < n; ++i)
   {
      cin >> a[i];
   }

   vector<int> polynomial(s+1);
   
   polynomial[0] = 2;
   if (a[0] <= s){
      polynomial[a[0]] = 1;
   }

   for (int i = 1; i < n; ++i)
   {
      vector<int> v = polynomial;
      vector<int> t(s+1, 0);
      for(auto &it: v){
         it *= 2;
         it %= mod;
      }
      for (int j = 0; j <= s; ++j)
      {
         if (j + a[i] <= s){
            t[j + a[i]] = polynomial[j];
         }
      }
      for (int j = 0; j <= s; ++j)
      {
         polynomial[j] = v[j] + t[j];
         polynomial[j] %= mod;
      }
   }

   cout<<polynomial[s];

   return 0;
}

Measured memory_bytes: 3752
import java.util.*;
import java.math.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[][] h = new int[N][2];
        long[] a = new long[N];

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

        Arrays.sort(h, (x, y) -> (x[0] - y[0]));

        for (int i = 0; i < N; i++) {
            a[i] = (long) sc.nextInt();
        }
        SegmentTree st = new SegmentTree(N);
        for (int i = 0; i < N; i++) {
            int index = h[i][1];
            st.update(index, st.getMax(index) + a[index]);
        }
        System.out.println(st.getResult());
    }
}

class SegmentTree {
    private long[] maxSegmentTree;
    private int n;
    private int N;

    public SegmentTree(int N) {
        this.N = N;
        this.n = (Integer.highestOneBit(N) << 1);

        this.maxSegmentTree = new long[2 * n];
        /*
        for (int i = n; i < 2 * n; i++) {
            maxSegmentTree[i] = arr[i - n];
        }
        for (int i = n - 1; i > 0; i--) {
            maxSegmentTree[i] = Math.max(maxSegmentTree[2 * i], maxSegmentTree[2 * i + 1]);
        }
        */
    }

    public void update(int i, long val) {
        i += n;
        maxSegmentTree[i] = val;

        while (i > 1) {
            i /= 2;
            maxSegmentTree[i] = Math.max(maxSegmentTree[2 * i], maxSegmentTree[2 * i + 1]);
        }
    }

    public long getMax(int index) {
        int l = n;
        index += n;
        long max = 0;


        while (l < index) {
            if ((index & 1) == 0) {
                max = Math.max(max, maxSegmentTree[index]);
                index--;
            }
            index >>= 1;
            l >>= 1;
        }

        if (l == index) max = Math.max(max, maxSegmentTree[l]);

        return max;
    }

    public long getResult() {
        return maxSegmentTree[1];
    }
}


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

using namespace std;

#define MOD 1000000007
#define ll long long int
#define ld long double
#define pb push_back
#define mkp make_pair
#define pii pair<int, int> 
#define pll pair<long long int, long long int>
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define fi first
#define sc second
#define deb 0

ll pos[100001], mark[100001];
vector<pll > L[100001], R[100001];
queue<ll> q;
set<ll> se;

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

	ll n, m, i, j, k, x, y, z;
	cin >> n >> m;
	for (i = 1; i <= n; ++i) pos[i] = LLONG_MAX;

	ll root = 1;
	for (i = 0; i < m; ++i) {
		cin >> x >> y >> z;
		if (root == -1) {
			root = x;
		}
		L[y].pb(mkp(x, z));
		R[x].pb(mkp(y, z));
		mark[x] = mark[y] = 1;
		se.insert(x);
		se.insert(y);
	}
	while (!se.empty()) {
		root = *se.begin();
		se.erase(se.begin());
		if (pos[root] != LLONG_MAX) continue;
		pos[root] = 0;
		q.push(root);
		while (!q.empty()) {
			x = q.front(); q.pop();
			for (auto it: L[x]) {
				y = it.fi;
				z = it.sc;
				if (pos[y] == LLONG_MAX) {
					pos[y] = pos[x] - z;
					q.push(y);
				} else if (pos[y] != pos[x]-z) {
					cout << "No" << endl; return 0;
				}
			}
			for (auto it: R[x]) {
				y = it.fi;
				z = it.sc;
				if (pos[y] == LLONG_MAX) {
					pos[y] = pos[x] + z;
					q.push(y);
				} else if (pos[y] != pos[x]+z) {
					cout << "No" << endl; return 0;
				}

			}
		}
	}
	for (i = 1; i <= n; ++i) if (!mark[i]) pos[i] = 0;
	sort(pos+1, pos+1+n);
	if (pos[1] != LLONG_MAX && pos[n] != LLONG_MAX && pos[n]-pos[1] <= 1e9) {
		cout << "Yes" << endl;
	} else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 21760
#include <bits/stdc++.h>
 
using namespace std;
 
#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define For(I,N)   for(int I=1;I<=(N);I++)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)
#define SZ(X) ((int)(X.size()))
#define LG(X) ((int)(X.length()))
#define CL(X) (X).clear()
#define MAXEL(A,B) (*max_element(A,B))
#define MINEL(A,B) (*min_element(A,B))
#define ROPEN(X) freopen(X,"r",stdin)
#define WOPEN(X) freopen(X,"w",stdout)
#define BG(X) (X.begin())
#define EN(X) (X.end())
#define VI vector<int>
#define PII pair<int,int>
 
//cout << fixed << setprecision(20) << p << endl;
 
template <class T> inline T bigmod(T p,T e,T M){
    LL ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}


int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n;
	cin>>n;
	vector<tuple<string,int,int> >v(n);
	REP(i,n){
		string s;
		int p;
		cin>>s>>p;
		v[i]=make_tuple(s,-p,i+1);
	}
	vsort(v);
	REP(i,n){
		cout<<get<2>(v[i])<<endl;
	}
	return 0;
}


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

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

    queue<ll> que;
    REP(i,9){
        que.push(i);
    }
    int cnt=1;
    while(cnt!=k){
        ll t=que.front();que.pop();
        cnt++;
        int c=t%10;
        if(c==0){
            que.push(t*10+c);
            que.push(t*10+1+c);
        }else if(c==9){
            que.push(t*10-1+c);
            que.push(t*10+c);
        }else{
            que.push(t*10+c-1);
            que.push(t*10+c);
            que.push(t*10+c+1);
        }
    }
    ll ans = que.front();
    cout<<ans<<endl;
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define print(obj) cout << obj << endl
#define scan(obj) cin >> obj

typedef long long ll;

using namespace std;

int main(void){
    vector<int> n;
    rep(i, 4){
        int temp;
        cin >> temp;
        n.pb(temp);
    }
    sort(ALL(n));
    if(n[0] == 1 && n[1] == 4 && n[2] == 7 && n[3] == 9){
        print("YES");
    } else {
        print("NO");
    }
}

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


int main() {
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	rep(q, k) {
		vector<int> b(n);
		rep(i, n) {
			int l = max(0, i-a[i]);
			int r = min(n, i+a[i]+1);
			b[l]++;
			if (r < n) b[r]--;
		}
		for(int i = 1; i < n; i++) b[i] += b[i-1];
		if (a == b) break;
		a = b;
	}
	rep(i, n) cout << a[i] << ((i == n-1) ? '\n': ' ');
	return 0;
}

Measured memory_bytes: 4840
import sys
 
YES = "Yes"  # type: str
NO = "No"  # type: str
 
def solve(x: int):
    print(x * x * x)
    return
 
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    x = int(next(tokens))  # type: int
  
    solve(x)
 
if __name__ == '__main__':
    main()


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
int main()
{
 char ch;
  cin>>ch;
  if (ch=='A') cout<<'T'<<endl;
  if (ch=='T') cout<<'A'<<endl;
  if (ch=='C') cout<<'G'<<endl;
  if (ch=='G') cout<<'C'<<endl;
  
  
  
  
  
  
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int n;
ll a[200005],sum;

int main(){
	cin >> n;
	repn(i,n){
		cin >> a[i]; sum += a[i];
	}
	ll ans = 1e18, rui = 0;
	repn(i,n-1){
		rui += a[i];
		ans = min(ans, abs(sum-2LL*rui));
	}
	cout << ans << endl;
}

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

int dp[80][80][12801] = {0};
int C[80][80] = {0};

int main(){
    int H, W;
    scanf("%d %d", &H, &W);
    int b;

    for (int i=0;i<H;i++) {
        for (int j=0;j<W;j++) {
            scanf("%d", &b);
            C[i][j] += b;
        }
    }

    for (int i=0;i<H;i++) {
        for (int j=0;j<W;j++) {
            scanf("%d", &b);
            C[i][j] -= b;
            C[i][j] = abs(C[i][j]);
        }
    }

    int vmax = (H+W)*(80);
    dp[0][0][C[0][0]] = 1;

    int k1, k2;
    for (int i=0;i<H;i++) {
        for (int j=0;j<W;j++) {
            for (int k=0;k<vmax+1;k++) {
                if (i+1<H) {
                    k1 = k+C[i+1][j];
                    k2 = abs(k-C[i+1][j]);
                    if (k1<=vmax) {
                        dp[i+1][j][k1] |= dp[i][j][k];
                    }
                    if (k2<=vmax) {
                        dp[i+1][j][k2] |= dp[i][j][k];
                    }
                }
                if (j+1<W) {
                    k1 = k+C[i][j+1];
                    k2 = abs(k-C[i][j+1]);
                    if (k1<=vmax) {
                        dp[i][j+1][k1] |= dp[i][j][k];
                    }
                    if (k2<=vmax) {
                        dp[i][j+1][k2] |= dp[i][j][k];
                    }
                }
            }
        }
    }

    int ans = 0;

    for (int i=0;i<vmax;i++) {
        if(dp[H-1][W-1][i]){
            printf("%d\n", i);
            break;
        }
    }
}

Measured memory_bytes: 320256
#include<bits/stdc++.h>
using std::cout;
using std::cin;
using std::endl;

int main()
{
    double x1, y1, x2, y2;
    double d;

    cin >> x1 >> y1 >> x2 >> y2;
    
    d = sqrt(pow(x1-x2, 2) + pow(y1-y2, 2));

    cout << std::fixed << std::setprecision(8) << d << endl;

    return 0;
}


Measured memory_bytes: 3284
#include <stdio.h>
#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    int N;
    char forecasts[3], real[3];
    scanf("%s", forecasts);
    scanf("%s", real);
    NSInteger hit = 0;
  	int i=0;
    for (i=0;i<3;i++) {
        hit += (forecasts[i] == real[i]) ? 1 : 0;
    }
    printf("%ld", hit);
    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
    return powmod(a, MOD-2);
}
ll f[10000010], invf[10000010];
void fac(int n){
    f[0]=1;
    for(ll i=1; i<=n; i++) f[i]=f[i-1]*i%MOD;
    invf[n]=inv(f[n]);
    for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1)%MOD;
}
ll comb(int x, int y){
    if(!(0<=y && y<=x)) return 0;
    return f[x]*invf[y]%MOD*invf[x-y]%MOD;
}
ll dp[2][2][5050][5050];
int main()
{
    int n, a; cin>>n>>a;
    fac(n);
    ll ans=0;
    dp[0][0][a][0]=dp[1][1][a][0]=1;
    for(int i=a; i>=1; i--){
        for(int j=0; j<=a-i; j++){
            for(int p=0; p<2; p++){
                for(int q=0; q<2; q++){
                    (dp[p][q][i-1][j]+=dp[p][0][i][j]*i)%=MOD;
                    (dp[p][q][i-1][j+q]+=dp[p][1][i][j])%=MOD;
                }
            }
        }
    }
    for(int x=0; x<a; x++){
        for(int i=0; i<=a; i++){
            ll c=(dp[1][0][x+1][i]*(x+1)+dp[1][1][x+1][i])%MOD*f[x+1]%MOD;
            (ans+=c*comb(n-x-i-2, a-x-1)%MOD*f[n-a])%=MOD;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

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

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}



int main(){
    int n,m;
    cin >> n >> m;
    int s[m];
    int c[m];
    int ans[n];
    rep(i,m){
        cin >> s[i] >> c[i];
    }
    //ans syokika
    rep(i,n){
        ans[i]=10;
    }

    if(m==0){
        if(n==1){
            cout << 0 << endl;
            return 0;
        }else if(n==2){
            cout << 10 << endl;
            return 0;
        }else{
            cout << 100 << endl;
            return 0;
        }
    }

    rep(i,m){
        if(ans[s[i]-1]==10){
            ans[s[i]-1]=c[i];
        }else if(ans[s[i]-1]!=c[i]){
            cout << "-1" << endl;
            return 0;
        }
    }

    bool u=true;

    rep(i,n){
        if(ans[i]==10 and n>1 and u and i==0){
            ans[i]=1;
            u=false;
        }else if(ans[i]==10){
            ans[i]=0;
        }
    }

    

    

    if(n==3 and ans[0]==0){
        cout << "-1" << endl;
        return 0;
    }
    if(n==2 and ans[0]==0){
        cout << "-1" << endl;
        return 0;
    }
    
    rep(i,n){
        cout << ans[i];
    }
    cout << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

int v[105], w[105], dp[105][10010];
signed main(void)
{
  int n, W;
  cin >> n >> W;
  REP(i, n) cin >> v[i] >> w[i];
  fill(dp[0], dp[0]+10001, INF);
  dp[0][0] = 0;
  REP(i, n) REP(j, 10001) {
    if(j < v[i]) {
      dp[i+1][j] = dp[i][j];
    } else {
      dp[i+1][j] = min(dp[i][j], dp[i][j-v[i]] + w[i]);
    }
  }
  int ret = 0;
  REP(i, 10001) if(dp[n][i] <= W) ret = i;
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 6992
//Zory-2020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define Debug printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define debug(x) cerr<<#x<<'='<<x<<endl
#define mem(x,val) memset(x,val,sizeof x)
namespace mine
{
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
    template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
    bool IN(ll x,ll l,ll r){return l<=x and x<=r;}

    const int INF=0x3f3f3f3f;
    const int MOD=993244853;
    int mm(const int x){return x>=MOD?x-MOD:x;}
    template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
    ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=4e5+10;

    int n,a[N],b[N],bak[N];
    typedef unsigned long long ull;
    const ull base=131;
    void main()
	{
        n=qread();if(n==1) {write1(0),write(0);return;}
        fo(i,0,n-1) a[i]=a[n+i]=qread();fo(i,0,n-1) b[i]=qread();
        ull aa=0,bb=0;fo(i,1,n-1) aa=aa*base+(a[i-1]^a[i]),bb=bb*base+(b[i-1]^b[i]);
        ull bs=1;fo(i,1,n-2) bs=bs*base;
        fo(k,0,n-1)
        {
            if(aa==bb) write1(k),write2(b[0]^a[k]);
            aa=aa-(a[k]^a[k+1])*bs,aa=aa*base+(a[n+k-1]^a[k]);
        }
	}
};//(ans+MOD)%MOD
signed main()
{
    srand(time(0));
    mine::main();
}


Measured memory_bytes: 6528
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
//ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 998244353;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll c(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }
int t[26];
#define DIV 4
ll dp[10001];
int main(void)
{
	int h, n;
	cin >> h >> n;
	vector<int> a(n), b(n);
	rep(i, 0, n)cin >> a[i] >> b[i];
	rep(i, 1, h + 2)dp[i] = 1ll << 60;
	rep(i2, 0, n) {
		rep(i, 0, h + 1) {
			dp[min(i + a[i2], h)] = min(dp[i] + b[i2], dp[min(i + a[i2], h)]);
		}
	}
	printf("%lld\n", dp[h]);
}

Measured memory_bytes: 384
#include <unordered_map>
#include <iterator>
#include <algorithm>
#include<vector>
#include <string>
#include <iostream>
using namespace std;

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

    char a[10];
    string s;
    long long cou = 0;
    long long ans = 0;
    unordered_map<string, long long> map;

    for(int i = 0; i < n; i++){
        cou = 0;
        s = "";
        for(int j = 0; j < 10; j++){
            cin >> a[j];
        }
        sort(a, a + 10);
        for(int j = 0; j < 10; j++){
            s += a[j];
        }

        //cout << s << endl;

        auto search = map.find(s);
        if (search != map.end()) {
            ans += map[s];
            map[s] += 1;
        } else {
            map[s] = 1;
        }
    }

    //cout << map["aaaaaaaaab"] << endl;

    cout << ans << endl;
}

Measured memory_bytes: 12196
N,C,K=map(int,input().split())
T=sorted([int(input()) for i in range(N)])
lt=T[0]+K
m=0
b=0
for t in T:
    if lt>=t and m<C:
        m+=1
    else:
        m=1
        b+=1
        lt=t+K
if m>=1:
    b+=1
print(b)


Measured memory_bytes: 8280
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector> 
using namespace std;
const int maxn=1e5+10;
int a[maxn];
bool s[maxn];
int pre[maxn];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(a[i]==i) s[i]=true;
		else s[i]=false; 
	}
	if(s[1]) pre[1]=1;
	else pre[1]=0;
	for(int i=2;i<=n;i++){
		if(s[i]) pre[i]=pre[i-1]+1;
		else pre[i]=0;
	}
	int ans=0;
	for(int i=1;i<n;i++){
		if(!pre[i]||pre[i]<pre[i+1]) continue;
		else{
			if(pre[i]&1) ans+=(pre[i]+1)/2;
			else ans+=pre[i]/2;
		}
	}
	if(pre[n]&1){
		ans+=(pre[n]+1)/2;
	}else if(pre[n]){
		ans+=pre[n]/2;
	}
	printf("%d\n",ans);
	return 0;
}
/*
C
const int maxn=1e5+10;
int a[maxn];
int b[maxn];//b[0]代表-1的个数 
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<maxn;i++) a[i]=0;
	b[0]=0;
	int ans=0;
	for(int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		if(x>=1){
			a[x-1]++;
			a[x]++;
			a[x+1]++;
			ans=max(ans,max(a[x-1],max(a[x],a[x+1])));
		}else{
			b[0]++;
			a[x]++;
			a[x+1]++;
			ans=max(ans,max(b[0],max(a[x],a[x+1])));
		} 
	} 
	printf("%d\n",ans);
	return 0;
}

*/

/*
B
int main(){
	scanf("%s",s);
	int len=strlen(s);
	for(int i=0;i<len;i+=2){
		printf("%c",s[i]);
	} printf("\n");
	return 0;
}
*/

/*
A
int main(){
	int n,t;
	scanf("%d%d",&n,&t);
	if(t>=n) printf("0\n");
	else printf("%d\n",n-t);
	return 0;
} 
*/


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

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7


class SegmentTree {
public:
	SegmentTree(){}//一応あるだけ

	//引数：頂点数
	SegmentTree(int size)
	{
		n = 1;
		while(n < size)n *= 2;
		dat.resize(n * 2, 0);
	}

	//k番目の値をaに変更
	void update(int k, ll a)
	{
		//葉の接点
		k += n - 1;
		dat[k] = a;
		//登りながら更新
		while(k > 0) {
			k = (k - 1) / 2;
			dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}

	// [a,b)の最大値を求める
	ll query(int a, int b) {
		return query_impl(a, b, 0, 0, n);
	}

private:
	int n;          //頂点数
	vector<ll> dat;//セグ木の本体

	ll query_impl(int a, int b, int k, int l, int r)
	{
		//　[a,b) と [l,r)　に交差無し
		if(r <= a || b <= l)return 0;
		//[a,b) が [l,r) を完全包含
		if(a <= l && r <= b)return dat[k];
		else {
			//左枝と右枝の最大値
			ll vl = query_impl(a, b, k * 2 + 1, l, (l + r) / 2);
			ll vr = query_impl(a, b, k * 2 + 2, (l + r) / 2, r);
			return max(vl, vr);
		}
	}
};
using ST = SegmentTree;

//メイン関数
int main()
{
	// input
	int N;
	cin >> N;
	vector<ll> h(N), a(N);
	ST st(N + 3);
	REP(i, N)cin >> h[i];
	REP(i, N)cin >> a[i];

	// dp
	ll res = 0;
	REP(i, N)
	{
		ll v = st.query(1, h[i]) + a[i];
		st.update(h[i], v);
		res = max(res, v);
	}
	cout << res << endl;
	cin >> N;

	return 0;
}


Measured memory_bytes: 7552
#include <stdio.h>

char search(unsigned long k,const char s[])
{
  unsigned i=0;
  while(!(s[i] != '1' || k == 1)){
    i++;
    k--;
  }
  fprintf(stderr,"%u",i);
  return(s[i]);
}

int main(void)
{
  char s[101];
  unsigned long k;
  
  scanf("%s",s);
  scanf("%lu",&k);
  
  printf("%c\n",search(k,s));
  
  return(0);
}
  
  

Measured memory_bytes: 128
// #define _GLIBCXX_DEBUG
// #pragma GCC optimize("Ofast")
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define reps(i, s, n) for (int i = s; i < (int)(n); ++i)
using namespace std;
using ll = long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
constexpr int INF = 1e9 + 7;
constexpr ll LINF = 1LL << 60;

void solve() {
    ll n;
    cin >> n;
    V<ll> A(n + 1);
    rep(i, n + 1) cin >> A[i];

    ll ans = 0;

    rep(i, n) {
        ll b;
        cin >> b;
        if (b < A[i]) {
            ans += b;
            // A[i] -= b;
            b = 0;
        } else {
            ans += A[i];
            b -= A[i];
            // A[i] = 0;
            if (b > 0) {
                if (b < A[i + 1]) {
                    ans += b;
                    A[i + 1] -= b;
                    // b = 0;
                } else {
                    ans += A[i + 1];
                    // b -= A[i + 1];
                    A[i + 1] = 0;
                }
            }
        }
    }

    cout << ans << "\n";
}
int main() {
    cin.tie(nullptr);
    // ios_base::sync_with_stdio(false);
    // cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 3968