akhauriyash/Code-Regression huggingface dataset:
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val a = scanner.nextInt()

    if (a % 2 == 0) {
        println(0.5)
        return
    }

    val i = a / 2
    println((i + 1).toDouble() / a)
}

Measured memory_bytes: 31260
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
/*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
int main() {
    ll n,a,b;
    cin >> n >> a >>b;
    ll sum =a+b;
    ll ans = n/sum*a+min(n%sum,a);
    cout << ans << endl;
}
    



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

#define pb push_back
#define all(a) (a).begin(), (a).end()

using ll = long long;
using pii = pair<int, int>;

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int x, y, z; cin >> x >> y >> z;
    cout << z << ' ' << x << ' ' << y << '\n';
}

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

int main(void){
    int height,width;
    vector<int> vec_height,vec_width;
    cin >> height >> width;
    vec_height.push_back(height);
    vec_width.push_back(width);

    for(int i = 0;height + width;i++){
        cin >> height >> width;
        vec_height.push_back(height);
        vec_width.push_back(width);
    }
    for(int i = 0;vec_height[i] + vec_width[i];i++){
        for (int j=0;j < vec_height[i];j++){
           for(int k=0;k < vec_width[i];k++){
               if( !((j+k)%2) )
                   printf("#");
               else
                  printf(".");
           }
        printf("\n");
        }
        printf("\n");
    }
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL read(){
	LL x=0,f=1;
	char ch=getchar();
	while (!isdigit(ch)&&ch!='-')
		ch=getchar();
	if (ch=='-')
		f=0,ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?x:-x;
}
const int N=2005;
int n,d;
int v[N][N];
int s[4][N][N];
#define y1 __zzd001
int sum(int x1,int y1,int x2,int y2,int t){
	return s[t][x2][y2]-s[t][x2][y1-1]-s[t][x1-1][y2]+s[t][x1-1][y1-1];
}
int check(int x){
	int r=x%d;
	for (int i=1;i<=d;i++)
		for (int j=1;j<=d;j++){
			int x1=i,y1=j;
			int x2=x1+r,y2=y1+r;
			int x3=x1+d-1,y3=y1+d-1;
			if (!sum(x1,y2+1,x3,y3,3)
			  &&!sum(x2+1,y1,x3,y3,3)
			  &&!sum(x2+1,y2+1,x3,y3,2))
				return 1;
		}
	return 0;
}
int main(){
	n=read(),d=read();
	memset(v,0,sizeof v);
	while (n--){
		int x=read(),y=read();
		v[x%d+1][y%d+1]++;
	}
	for (int i=1;i<=d;i++)
		for (int j=1;j<=d;j++)
			v[i+d][j]=v[i][j+d]=v[i+d][j+d]=v[i][j];
	int Mx=0;
	for (int i=1;i<=d;i++)
		for (int j=1;j<=d;j++)
			Mx=max(Mx,v[i][j]);
	int t;
	for (t=0;(t+1)*(t+1)<Mx;t++);
	int l[5]={0,0,t*t+1,t*(t+1)+1,(int)1e9};
	for (int i=1;i<=d*2;i++)
		for (int j=1;j<=d*2;j++)
			for (int t=1;t<=3;t++){
				s[t][i][j]=s[t][i-1][j]+s[t][i][j-1]-s[t][i-1][j-1];
				if (l[t]<=v[i][j]&&v[i][j]<l[t+1])
					s[t][i][j]++;
			}
	int L=t*d,R=t*d+d-1,ans=R;
	while (L<=R){
		int mid=(L+R)>>1;
		if (check(mid))
			R=mid-1,ans=mid;
		else
			L=mid+1;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 64384
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int x;
	cin >> x;
	cout << a[x-1] << endl;
}


Measured memory_bytes: 256
n = int(input())
P = list(map(int, input().split()))

ans = 0
for i in range(1, len(P)-1):
    if P[i-1] < P[i] < P[i+1]:
        ans += 1
    elif P[i+1] < P[i] < P[i-1]:
        ans += 1
print(ans)

Measured memory_bytes: 3060
N = int(input())
A = [int(_) for _ in input().split()]


t = sum(A) 
x = [0] * N

x[0] = t - 2 * sum([A[i] for i in range(1, N, 2)])

for i in range(1, N):
    x[i] = 2 * A[i - 1] - x[i - 1]

print(*x)


Measured memory_bytes: 65124
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n, m,k = map(int, input().split())


def nCr_mod_p(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 998244353
N = 2*10 ** 5  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p), 0! = 1! = 1
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p), 0! = 1! = 1
inv = [0, 1]  # inv[n] = n^(-1) mod p, 0! = 1　だけど便宜上inv[0]=0にしてる

for i in range(2, N + 2):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

ans =0

for i in range(k+1):
    ans += m*pow(m-1,n-i-1,p)%p * nCr_mod_p(n-1,i,p)%p
print(ans%p)


Measured memory_bytes: 117976
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define PII         pair<int, int>
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for(auto &x : a){
        cin >> x;
    }
    vector<int> t = a;
    sort(ALL(t), greater<int>());
    int mx1 = t[0], mx2 = t[1];
    for(int i = 0; i < n; i++){
        if(a[i] != mx1){
            cout << mx1 << nl;
        }else{
            cout << mx2 << nl;
        }
    }
    return 0;
}


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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> dp(n + 1, 1000000);
    dp[0] = 0;
    dp[1] = 1;
    for (int i = 2; i <= n; ++i)
    {
        dp[i] = min(dp[i], dp[i - 1] + 1);
        for (int p = 6; p <= i; p *= 6)
            dp[i] = min(dp[i], dp[i - p] + 1);
        for (int p = 9; p <= i; p *= 9)
            dp[i] = min(dp[i], dp[i - p] + 1);
    }
    cout << dp[n];
    return 0;
}


Measured memory_bytes: 640
s=raw_input().split(' ')
n=int(s[0])
y=int(s[1])

k=y-1000*n
#print(k)
f=0;
for a in range(0,1000001):
	l=k-9000*a;
	if l<0:
		f=0
		break;
	
	if l%4000==0:
		b=l//4000;
		c=n-a-b;
		if c>=0:
			f=1;
			break;

if f==1:
	c=n-a-b;
	print(str(a)+" "+str(b)+" "+str(c))
else:
	print("-1 -1 -1")


Measured memory_bytes: 34436
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
using ll = long long;
int main() {
ll n;
cin >> n;
ll a[3*n];
for (ll i = 0; i < 3 * n; i++) cin >> a[i];
sort(a, a + 3 * n, greater<ll>());
ll ans = 0;
for (ll i = 0; i < n;i++){
    ans += a[2 * i + 1];
}
cout << ans << endl;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

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

  ll N, M, C;
  cin >> N >> M >> C;
  vector<ll> B(M);
  rep(i, M) cin >> B[i];
  ll ans = 0;
  rep(i, N) {
    ll cnt = 0;
    rep(j, M) {
      int a;
      cin >> a;
      cnt += a*B[j];
    }
    if (cnt + C > 0) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define dbg(x) cout<<"( "<<#x<<" -> "<<x<<" )"<<endl;
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    string s;
    cin>>s;
    s=s.append("#");
    int c=0;
    for (int i=1;i<=n;i++)
    {
        if (s.at(i)!=s.at(i-1))
        c++;
    }
    printf("%d\n",c);
    return 0;
}

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

int main()
{
    long double a,b,n,t,l=0.0;
    long long i;
    cin>>a>>b>>n;
   // for(i=1;i<=n;i++){
   if(n>=b)
        t=floor((a*(b-1))/b)-(a*floor(1.0*(b-1)/b));
      //          t=floor((a*i)/b)-(a*floor((1.0*i)/b));
        //cout<<i<<" "<<t<<" "<<l<<endl;
else
    t=floor((a*n)/b)-(a*floor(1.0*n/b));

   //     l=max(t,l);
    //}
    cout<<t;
}


Measured memory_bytes: 3840
"""
重さと価値がそれぞれw_i,v_iであるようなn個の品物がある.
これらの品物の中から, 重さの総和がWを超えないように選んだ時の,
価値の総和の最大値を求めよ.
1<=n<=100, 1<=w_i<=10^7, 1<=v_i<=100, 1<=limit_w<=10^9
"""
#-------------------------------------------------------------------------------

#入力
INF = 2000000000
"""
メモ : Pythonでは無限大を表す float('inf') があるが, 処理がかなり重たいので
       代わりにsum(v)より真に大きい 2*10^9 を INFとする.
       (https://atcoder.jp/contests/dp/tasks/dp_e において,PyPyを使用して,
        前者だと1060ms, 後者だと570msで2倍近く差が出ている.)
"""
n ,limit_w = map(int, input().split())
w = [0]*n
v = [0]*n
for i in range(n):
    w[i], v[i] = map(int, input().split())
sum_v = sum(v)
dp = [[INF for i in range(sum_v + 1)] for j in range(n + 1)] 
# dp[i][j]には重さが入る.
# dp[i][j]=(i番目までの品物から価値がちょうどｊになるための重さの最小値)

# ここからメイン
dp[0][0] = 0
for i in range(n):
    for j in range(sum_v + 1):
        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])
            
# n個まで使って,重さがlimit_wを超えないで価値が最大のものを求める.
ans = 0
for i in range(sum_v + 1):
    if dp[n][i] <= limit_w:
        ans = i
print(ans)


Measured memory_bytes: 171120
import java.util.Scanner;

public class Main {
	
	Scanner sc = new Scanner(System.in);
	public void run() {
		while(sc.hasNext()){
			int n = sc.nextInt();
			int m = sc.nextInt();
			int a = sc.nextInt();
			if(n == 0 && m == 0 && a == 0) break;
			calc(n, m, a);
		}
	}
	public void calc(int n, int m, int a){
		int[][] amida = new int[1001][n+1];
		int height = 0;
		
		for(int i = 0; i < m; i++){
			int h = sc.nextInt();
			int p = sc.nextInt();
			int q = sc.nextInt();
			amida[h][p] = q;
			amida[h][q] = p;
			if(height < h) height = h;
		}
		
		for(int i = height; i >0; i--){
			if(amida[i][a] != 0) a = amida[i][a];
		}
		System.out.println(a);
	}

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

Measured memory_bytes: 72872
#!/bin/bash

read x_1 y_1 x_2 y_2;
x=$(($x_2 - $x_1))
y=$(($y_2 - $y_1))
echo $(($x_2 - $y)) $(($y_2 + $x)) $(($x_2 - $y - $x)) $(($y_2 + $x - $y))
# echo ${s:0:1}$((${#s}-2))${s:$((${#s}-1)):$((${#s}-1))}
exit 0

Measured memory_bytes: 376
object Main extends App {

  val Array(n, m, l) = io.StdIn.readLine().split(" ").map(_.toInt)

  val a = Array.ofDim[Long](n,m)
  val b = Array.ofDim[Long](m,l)
  for(i <- 0 until n)
    a(i) = io.StdIn.readLine().split(" ").map(_.toLong)
  for(i <- 0 until m)
    b(i) = io.StdIn.readLine().split(" ").map(_.toLong)

  val ans = Array.ofDim[Long](n,l)
  for(i <- 0 until n; j <- 0 until l; k <- 0 until m)
    ans(i)(j) += a(i)(k) * b(k)(j)

  val sb = StringBuilder.newBuilder
  for(e <- ans)
    sb.append(e.mkString(" ")).append("\n")
  print(sb)
}


Measured memory_bytes: 55316
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int maxn=2e5+100;
long long int fac[maxn];
void init()
{
    fac[0]=1;
    for(int i=1;i<=200000;++i)
    {
        fac[i]=fac[i-1]*i%mod;
    }
}
long long int quick_pow(int n,long long int base)
{
    long long int ans=1;
    while(n)
    {
        if(n&1)
        {
            ans*=base;
            ans%=mod;
        }
        base*=base;
        base%=mod;
        n>>=1;
    }
    return ans;
}
long long int C(int a,int b)
{
    long long int fz=fac[b];
    long long int fm=fac[a]*fac[b-a]%mod;
    return fz*quick_pow(mod-2,fm)%mod;
}
int main()
{
    int n,k;
    init();
    cin>>n>>k;
    k=min(n-1,k);
    long long int ans=1;
    if(k==1)
        ans=0;
    for(int i=1; i<=k; ++i)
    {
        ans+=C(i,n)*C(n-i-1,n-1)%mod;
        //cout<<C(i,n)<<" "<<quick_pow(i,n-i)<<" "<<endl;
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}


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

char getGrade(int m, int f, int r){
    int sum = m + f;
    char grade;
    if(m==-1 || f==-1) grade = 'F';
    else if(80<=sum) grade = 'A';
    else if(65<=sum) grade = 'B';
    else if(50<=sum) grade = 'C';
    else if(30<=sum){
        if(r>=50) grade = 'C';
        else grade = 'D';
    }
    else grade = 'F';
    return grade;
}

int main(){
    int m,f,r;
    while(1){
        cin >> m >> f >> r;
        if(m==-1 && f==-1 && r==-1) break;
        cout << getGrade(m,f,r) << endl;
    }
    return 0;
}


Measured memory_bytes: 3108
N = int(input())
P = list(map(float, input().split()))


def solve():
    dp = [[0]*(i+3) for i in range(N+1)]
    dp[0][1] = 1
    for i in range(1,N+1):
        for j in range(1,i+2):
            dp[i][j] = dp[i-1][j-1]*P[i-1]+dp[i-1][j]*(1-P[i-1])
    ans = sum(dp[-1][(N+3)//2:])
    return ans
print(solve())

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

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD = 1e9 + 7;

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

    string s;cin>>s;
    int len=s.length();
    vector<int> res;
    for(int i=1;i<len;i++){
        if(s[i]==s[i-1]) continue;
        res.push_back(max(i,len-i)); 
    }
    if(res.size()==0){
        cout<<len<<endl;
        return 0;
    }
    sort(res.begin(),res.end());
    cout<<res[0]<<endl;
}


Measured memory_bytes: 720
using System;

namespace Atcoder_20190413_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string inputa = Console.ReadLine();
            int a = int.Parse(inputa.Split(' ')[0]);
            int b = int.Parse(inputa.Split(' ')[1]);
            int result = 0;

            if (a >= b)
            { result += a; a--; }
            else
            {
                result += b; b--;
            }

            if (a >= b)
            { result += a; a--; }
            else
            {
                result += b; b--;
            }

            Console.WriteLine(result);

        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
using namespace std;
int main(){
int H,W;
while(1){
cin >>H >>W;
if (H==0&&W==0) break;
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
if(i==0||i==H-1||j==0||j==W-1){
cout <<'#';
}
else cout <<'.';
}
cout <<"\n";
}
cout <<endl;
}
return 0;
}

Measured memory_bytes: 3056
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
#include<stack>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------
int dp[100005];
int main(){
  int N,M;
  cin >> N >> M;
  queue<int> que;
  for(int i=0; i<M; i++){
    int a;
    cin >> a;
    que.push(a);
  }
  for(int i=0; i<=N; i++) dp[i] = 0;
  dp[0] = 1;
  for(int i=0; i<=N; i++){
    if(que.size() && que.front() == i){
      que.pop();
      continue;
    }
    if(i-1 >= 0){
      dp[i] += dp[i-1];
    }
    if(i-2 >= 0){
      dp[i] += dp[i-2];
    }
    dp[i] %= mod;
  }
  cout << dp[N] << endl;
  return 0;
}


Measured memory_bytes: 1024
N, K, Q = map(int, raw_input().split())

S = [0 for i in range(N)]

for i in range(Q):
    Ai = int(raw_input()) -1
    S[Ai] = S[Ai] + 1

for i in range(N):
    S[i] = K - (Q - S[i])


#print S                                                                                               
for i in range(N):
    if S[i] > 0:
        print "Yes"
    else:
        print "No"

Measured memory_bytes: 9340
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


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

    const ll INF=1LL<<60;
    vector<vector<ll>> dp(110,vector<ll>(100010,INF));
    vector<ll> w(110), v(110);
    REP(i, N){
        cin>>w[i]>>v[i];
    }
    dp[0][0]=0;
    REP(i, N){
        REP(vsum, 100010){
            if(vsum>=v[i]) chmin(dp[i+1][vsum], dp[i][vsum-v[i]]+w[i]);
            chmin(dp[i+1][vsum], dp[i][vsum]);
        }
    }

    ll ans = 0;
    REP(i, 100010){
        if(dp[N][i]<=W){
            ans=i;
        }
    }
    
    cout << ans << endl;    return 0;
}

Measured memory_bytes: 87296
#include<math.h>
#include<map>
#include<iostream>
#include <algorithm>
#include <string>
#include<vector>
#include<array>
#include<tuple>
#include<queue>
#include<stack>
#include<iomanip>
#include<bitset>
#include <list>
//AtCoderC++.cpp

using namespace std;


inline int ceileing(int a, int b) {
	return a % b == 0 ? a / b : a / b + 1;
}
int main() {
	int N; cin >> N;
	int prev = 0;
	int next;
	for (size_t i = 0; i < N; i++) {
		cin >> next;
		if (next <prev) {
			cout << "No" << endl;
			return 0;
		}
		prev = prev < next ? next - 1 : next;
	}
	cout << "Yes" << endl;
}

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

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define PI 3.141592653589793238
#define INF 1050000000

using vi = vector<int>;


int main() {


	char X, Y;

	cin >> X >> Y;

	if (X < Y)
	{

		cout << '<' << endl;
	}
	else if (X > Y)
	{

		cout << '>' << endl;
	}
	else {

		cout << '=' << endl;
	}

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Linq.Enumerable;
using static System.Math;

class Program
{
    static void Main()
    {
        var (A, B) = ReadLine().Split(' ').Select(int.Parse).ToArray();

        static bool IsPalindromicNumber(int n)
        {
            var s1 = n.ToString();
            var s2 = new string(s1.Reverse().ToArray());
            return s1 == s2;
        }

        var ans = Range(A, B - A + 1).Count(i => IsPalindromicNumber(i));

        WriteLine(ans);
    }
}

static class ArrayDeconstructExtensions
{
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2) => (i1, i2) = (a[0], a[1]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3) => (i1, i2, i3) = (a[0], a[1], a[2]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4) => (i1, i2, i3, i4) = (a[0], a[1], a[2], a[3]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4, out T i5) => (i1, i2, i3, i4, i5) = (a[0], a[1], a[2], a[3], a[4]);
}


Measured memory_bytes: 46956
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define PER(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define all(S) (S).begin(), (S).end()
#define pf push_front
#define pb push_back
#define mk make_pair
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<int, int> ii;
const int MAX = 2e5+5;

int main(int argc, char** argv) {
	int a; scanf("%d", &a);
	printf("%d\n", a + a*a + a*a*a);
	return 0;
}


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

#define DEBUG 1
#define LENGTH 5

void sort(int in[LENGTH]);

main()
{
	int input[LENGTH];
	int i;
	for(i = 0; i < LENGTH; i++)
	{
		 scanf("%d", &input[i]);
	}
	
	sort(input);
	
#ifdef DEBUG
	for(i = 0; i < LENGTH; i++)
	{
		printf("%d", input[i]);
		if(i < LENGTH - 1)
		{
			printf(" ");
		}
	}
	printf("\n");
#endif
	return 0;
}

void sort(int in[LENGTH])
{
	int i, j;
	for(i = 0; i < LENGTH; i++)
	{
		for(j = i + 1; j< LENGTH; j++)
		{
			if(in[i] < in[j])
			{
				int temp = in[j];
				in[j] = in[i];
				in[i] = temp;
			}
		}
	}
}

Measured memory_bytes: 600
#include<cstdio>
#include<iostream>
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        char moneywrite[2][1000];
        int money[2][1000];
        int stl[2]={0,0};
        int stlstl;
        int sum[81];
        scanf("%s",moneywrite[0]);
        scanf("%s",moneywrite[1]);
        for(int j=0;moneywrite[0][j]!='\0';j++){
            money[0][j]=moneywrite[0][j]-'0';
            stl[0]++;
        }
        for(int j=0;moneywrite[1][j]!='\0';j++){
            money[1][j]=moneywrite[1][j]-'0';
            stl[1]++;
        }
        if(stl[0]>stl[1]){
            stlstl=stl[0];
            int p;
            p=stl[0]-stl[1];
            for(int j=0;j<stl[0];j++){
                money[1][stl[0]-j]=money[1][stl[0]-j-p];
            }
            for(int k=0;k<p;k++)
                money[1][k]=0;
        }
        else if(stl[1]>stl[0]){
            stlstl=stl[1];
            int p;
            p=stl[1]-stl[0];
            for(int j=0;j<stl[1];j++){
                money[0][stl[1]-j]=money[0][stl[1]-j-p];
            }
            for(int k=0;k<p;k++)
                money[0][k]=0;
        }
        else{
            stlstl=stl[1];
        }
/*
        for(int j=0;j<stlstl;j++)
            printf("[%d][%d]\n",money[0][j],money[1][j]);
*/
        if(81<=stlstl){
            printf("overflow");
            goto exit;
        }
        for(int j=stlstl-1;0<=j;j--){
            sum[j]=money[0][j]+money[1][j];
            if(10<=sum[j]){
                if(stlstl==80&&j==0){
                    printf("overflow");
                    goto exit;
                }
                else if(j==0){
                    printf("1");
                    sum[j]%=10;
                }
                else{
                    money[0][j-1]++;
                    sum[j]%=10;
                }
            }
        }
        for(int j=0;j<stlstl;j++)
            printf("%d",sum[j]);
exit:
        puts("");
    }
    return 0;
}

Measured memory_bytes: 1208
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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; }

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e12;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n, k, q;
  cin >> n >> k >> q;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a[i];
  }

  ll ans = INF;
  rep(i, n) {
    // Here, a[i] is min
    vector<ll> small; // small emenents in each region

    ll pre = -1; // prev one.
    ll j = 0;
    while (j < n) {
      while (j < n && a[j] >= a[i]) { ++j; }
      // Here, j == n or a[j] < a[i]
      vector<ll> now; // elements in this region
      for (int k = pre + 1; k < j; ++k) {
        now.push_back(a[k]);
      }
      ll cnt = now.size()-k+1; // maximum trial in this region
      if (cnt > 0) {
        sort(all(now));
        rep(k, cnt) {
          small.push_back(now[k]);
        }
      }
      pre = j;
      ++j;
    }

    if (small.size() < q) { continue; } // inavalid
    sort(all(small));
    ans = min(ans, small[q-1] - small[0]);
  }

  cout << ans << endl;
}


Measured memory_bytes: 384
n, m = map(int, input().split())
c = [int(i) for i in input().split()]
dp = [[-1 for _ in range(m + 1)] for _ in range(n + 1)]
for i in range(1, n + 1):
    dp[i][1] = i
for j in range(1, m + 1):
    dp[0][j] = 0
    # dp[1][j] = 1
for i in range(n + 1):
    for j in range(1, m):
        if c[j] > i:
            dp[i][j + 1] = dp[i][j]
        else:
            dp[i][j + 1] = min(dp[i][j], dp[i - c[j]][j + 1] + 1)
print(dp[n][m])



Measured memory_bytes: 49108
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define mod 1000000007
#define vll vector<ll>
#define pll vector<pair<ll,ll>>



int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	//cin>>t;
	t=1;
	start:
	while(t--){

     ll n,m,to;
     cin>>n>>m>>to;

      ll arrx[to+1],arry[to+1];
     for(ll i=1;i<=to;i++)
        cin>>arrx[i]>>arry[i];

    map<ll,ll> x,y;
    for(ll i=1;i<=to;i++){
        x[arrx[i]]++;
        y[arry[i]]++;
    }

    ll mx=0,my=0,ansx=-1,ansy=-1;

    for(auto i:x){
        if(i.s>mx){
            mx=i.s;
            ansx=i.f;
        }
    }
    for(auto i:y){
        if(i.s>my){
            my=i.s;
            ansy=i.f;
        }
    }

    if(mx>my)
    {
       // cout<<mx<<endl;
        my=0;ansy=-1;
        map<ll,ll> temp;
       for(ll i=1;i<=to;i++){
            if(arrx[i]!=ansx){
                    temp[arry[i]]++;
            }
       }
               for(auto i:temp){
               if(i.s>my) {
                my=i.s;
                ansy=i.f;
               }
               }
        cout<<mx+my<<endl;
    }
    else{
        mx=0;ansx=-1;
        map<ll,ll> temp;
       for(ll i=1;i<=to;i++){
            if(arry[i]!=ansy){
                    temp[arrx[i]]++;
            }
       }
               for(auto i:temp){
               if(i.s>mx) {
                mx=i.s;
                ansx=i.f;
               }
               }
        cout<<mx+my<<endl;

    }


	}
	return 0;
}


Measured memory_bytes: 64592
#include <cstdio>
#include <set>
using namespace std;

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

int main() {
	int n,a,num;
	num=0;
	set<int> card;
	scanf("%d",&n);
	REP(i,n){
		scanf("%d",&a);
		if(card.count(a)==0){
			card.insert(a);
			num++;
		}
		else{
			card.erase(a);
			num--;
		}
	}
	printf("%d\n",num);
	return 0;
}


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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  if(A + B == C + D) cout << "Balanced" << endl;
  else if(A + B > C + D) cout << "Left" << endl;
  else cout << "Right" << endl;
}


Measured memory_bytes: 3612
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

#[allow(dead_code)]
fn with_stdout_lock<F: FnOnce(std::io::BufWriter<std::io::StdoutLock>)>(f: F) {
    let out = std::io::stdout();
    let w = std::io::BufWriter::new(out.lock());
    f(w);
}

#[allow(unused_macros)]
macro_rules! debug {
    ($var:expr) => {
        match &$var { v => eprintln!(concat!(stringify!($var), "={:?}"), v) }
    };
    ($var:expr, $($vars:expr),*) => {
        match &$var { v => eprint!(concat!(stringify!($var), "={:?} "), v) }
        debug!($($vars),*);
    };
}

fn main() {
    let n: usize = input();
    let mut a: Vec<i32> = (0..n).map(|_| input()).collect();

    for i in 0..n {
        a[i] -= i as i32;
    }
    a.sort();
    let b = a[n / 2];
    let sum: i64 = a.iter().map(|&a| (a - b).abs() as i64).sum();
    println!("{}", sum);
}


Measured memory_bytes: 4352
#include <iostream>
int gcd(int x, int y) {
    if (y == 0) {
        return x;
    } else {
        return gcd(y, x % y);
    }
}
int main() {
    int n;
    std::cin >> n;
    int a0;
    std::cin >> a0;
    for (int i = 1; i < n; i++) {
        int a1;
        std::cin >> a1;
        a0 = gcd(a0, a1);
    }
    std::cout << a0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include<iomanip>

using namespace std;
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define i64 int64_t
#define tos(x) to_string(x)

int main() {
	int a, b;
	cin >> a >> b;
	string n;
	cin >> n;
	int ans = 0;
	ff(i, 0, n.size()-1) {
		if (n[i] == n[i + 1])ans++;
	}
	ff(i, 0, b) {
		ans += 2;
	}
	ans = min(a - 1, ans);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
import sys

for i in sys.stdin.readlines():
    n = int(i[:-1])
    cnt = 0
    for a in range(10):
        for b in range(10):
            for c in range(10):
                for d in range(10):
                    if a + b + c + d == n:
                        cnt += 1
    print(cnt)

Measured memory_bytes: 7508
import java.util.Scanner;
import java.util.Set;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());
        long x = Long.parseLong(sc.next());
        long low = (a+x-1)/x;
        long high = b/x;
        long result = Math.max(0, high-low+1);
        System.out.println(result);
    }
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;

// 最大公約数
ll gcd(ll a, ll b)
{
   if (a%b == 0) {
       return(b);
   } else {
       return(gcd(b, a%b));
   }
}

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

//素数判定
bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された
    if(n % 2 == 0 || n % 3 == 0) return false;
    for(unsigned i = 5; i * i <= n; i += 6) {
        if(n % i     == 0) return false; // (6の倍数)-1
        if(n % (i+2) == 0) return false; // (6の倍数)+1
    }
    return true;
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

/*   *   *   *   *   *   *   *   *   *   *   */

//配るdp
void solve() {
    ll n; cin >> n;
    ll h[100100];
    Rep(i, 1 ,n) cin >> h[i];

    ll dp[100100];
    Rep(i, 1, 100100) dp[i] = INF;
    dp[1] = 0;
    rep(i, 1, n){
        chmin(dp[i+1], dp[i]+abs(h[i]-h[i+1]));
        chmin(dp[i+2], dp[i]+abs(h[i]-h[i+2]));
    }
    cout << dp[n] << endl;
}

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

    solve();
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#define mod 1000000007
using namespace std;
//123,132,213
int dp[105][4][4][4];
int main(int argc, char** argv) {
	dp[0][0][0][0]=1;
	int n;
	cin >> n;
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<4;j++)
		{
			for(int k=0;k<4;k++)
			{
				for(int l=0;l<4;l++)
				{
					dp[i][k][l][0]+=dp[i-1][j][k][l];
					dp[i][k][l][1]+=dp[i-1][j][k][l];
					dp[i][k][l][2]+=dp[i-1][j][k][l];
					if((j!=1||l!=2)&&(j!=1||k!=2))dp[i][k][l][3]+=dp[i-1][j][k][l];
					dp[i][k][l][0]%=mod;
					dp[i][k][l][1]%=mod;
					dp[i][k][l][2]%=mod;
					dp[i][k][l][3]%=mod;
				}
				/*dp[i][k][0]+=dp[i-1][j][k];
				dp[i][k][1]+=dp[i-1][j][k];
				if(j!=1||k!=3) dp[i][k][2]+=dp[i-1][j][k];
				if((j!=1||k!=2)&&(j!=2||k!=1)) dp[i][k][3]+=dp[i-1][j][k];
				dp[i][k][0]%=mod;
				dp[i][k][1]%=mod;
				dp[i][k][2]%=mod;
				dp[i][k][3]%=mod;*/
			}
		}
		dp[i][1][2][3]=dp[i][1][3][2]=dp[i][2][1][3]=0;
		for(int j=0;j<4;j++)
			for(int k=0;k<4;k++)
				for(int l=0;l<4;l++)
					if(i==n) ans+=dp[i][j][k][l],ans%=mod; 
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main() {
  ll n;
  scanf("%lld", &n);
  ll a[n];
  for (int i = 0; i < n; ++i) {
    scanf("%lld", &a[i]);
  }
  ll ansa = 0;
  ll ansb = 0;

  sort(a,a+n);
  // FOR(i,0,n-1) cout << a[i] << endl;

  int x = ((n-2)+1)/2;
  // cout << x << endl;

  FOR(i,0,x-1){
    ansa += a[i]*(-2);
  }
  // cout << ansa << endl;
  if(n%2==0) ansa -= a[x];
  else ansa += a[x];
  ansa += a[x+1];
  // cout << ansa << endl;
  FOR(i,x+2,n-1){
    ansa += a[i]*2;
  }
  // cout << ansa << endl;

  sort(a,a+n,greater<ll>());

  FOR(i,0,x-1){
    ansb += a[i]*(2);
  }
  FOR(i,x,x+1){
    ansb -= a[i];
  }
  if(n%2==0) ansb += a[x+1]*2;
  FOR(i,x+2,n-1){
    ansb += a[i]*(-2);
  }


  // cout << ansa << " " << ansb << endl;
  cout << max(ansa,ansb) << endl;


}



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

int main(){
  l N,K,k,a; cin>>N>>K;
  k=N/K;
  a=k*k*k;
  if(K%2==0){
    k=(N-K/2);
    if(k>=0){
      k=k/K+1;
      a+=k*k*k;
    }
  }
  cout<<a;
}

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

class Point {
public:
    double x, y;
};

double dotProduct(Point p1, Point p2) {
    return p1.x * p2.y - p1.y * p2.x;
}

int main () {
    double x[4], y[4];
    while (cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2] >> x[3] >> y[3]) {
        double dp[3];
        for (int i = 0; i < 3; i++) {
            Point p[2];
            p[0].x = x[(i+1) % 3] - x[i];
            p[0].y = y[(i+1) % 3] - y[i];
            p[1].x = x[3] - x[i];
            p[1].y = y[3] - y[i];
            dp[i] = dotProduct(p[0], p[1]);
        }
        if ((dp[0] > 0 && dp[1] > 0 && dp[2] > 0)
            || (dp[0] < 0 && dp[1] < 0 && dp[2] < 0)) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}

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

void findRequiredProb(vector < double > prob) {
  int n = prob.size();
  vector < vector < double > >dp(n + 1, vector < double >(n + 1, 0.0));
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    dp[i][0] = dp[i - 1][0] * (1 - prob[i - 1]);
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      dp[i][j] = dp[i - 1][j] * (1.0 - prob[i - 1]) + (dp[i - 1][j - 1] * prob[i - 1]);
    }
  }

  double ans = 0.0;
  for (int i = (n + 1) / 2; i <= n; i++) {
    ans += dp[n][i];
  }

  printf("%0.10lf\n", ans);
}


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

  findRequiredProb(probs);

  return 0;
}


Measured memory_bytes: 73804
package main

import "fmt"

func main() {
	var x, n, tmp, diff int
	fmt.Scan(&x, &n)
	p := make(map[int]bool, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&tmp)
		p[tmp] = true
	}
	for {
		if !p[x-diff] {
			fmt.Println(x - diff)
			return
		}
		if !p[x+diff] {
			fmt.Println(x + diff)
			return
		}
		diff++
	}
}


Measured memory_bytes: 1840
#include <iostream>
#include <string>
#include <set>

using namespace std;

int main() {
  int N;
  string W1, W2;
  set<string> word;
  cin >> N;

  string ans = "Yes";
  for (int i = 0; i < N; i++) {
    cin >> W1;
    if (i > 0) {
      if (W1[0] != W2[W2.size() - 1]) ans = "No";
    }
    W2 = W1;
    word.insert(W1);
  }

  if (word.size() != N) ans = "No";

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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
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(a > b){ a = b; return 1; } return 0; }
int main()
{
  int a,b; cin >> a >> b;
  int c[100000000][1900000000];
  cout << max(a - 2*b, 0) << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    //4 1-4, 3-2
    if (n % 2 == 0)
    {
        //(n-2*n)/2
        cout << (n * 1LL * (n - 2)) / 2 << endl;
        int sum = n + 1;
        for (int i = 1; i <= n; i++)
        {
            int pair = sum - i;
            for (int j = i + 1; j <= n; j++)
            {
                if (j == pair)
                    continue;
                cout << i << " " << j << endl;
            }
        }
    }
    else
    {
        int sum = n;
        cout << ((n - 1) * 1LL * (n - 1)) / 2 << endl;
        for (int i = 1; i <= n; i++)
        {
            int pair = sum - i;
            for (int j = i + 1; j <= n; j++)
            {
                if (j == pair)
                    continue;
                cout << i << " " << j << endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P  = pair<int,int>;
using v  = vector<int>;
using vv = vector<v>;
const int MOD = 1000000007;

//editorialのサンプルコードをお手本に再帰関数dfsで

ll dfs(vv &graph, int i, int m, int k){
    //大祖先: 自身がK通り.
    //子の数をcとしてK-1 P c通り
    //それ以外: 自身は既に数えられている(1通り).
    //子の数をcとしてK-2 P c通り
    ll rtn;
    int num = k-1;
    if(m==-1){
        rtn = k;
    }else{
        rtn = 1;
        num--;
    }
    
    for(auto d : graph[i]){
        if(d==m)continue;
        rtn *= num;
        rtn %= MOD;
        num--;
        rtn *= dfs(graph, d, i, k);
        rtn %= MOD;
    }
    return rtn;
}

int main(){
    int n,k;
    cin >> n >> k;
    
    vv graph(n);
    
    int a,b;
    rep(i,n-1){
        cin >> a >> b;
        a--;b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    
    ll ans = dfs(graph, 0, -1, k);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11520
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define YESNO(i) puts((i)?"YES":"NO");
#define YesNo(i) puts((i)?"Yes":"No");
#define yesno(i) puts((i)?"yes":"no");
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;cin>>s;
  if(s[s.length()-1]=='s') s+="es";
  else s+='s';
  print(s); 
  return 0;
}

Measured memory_bytes: 3660
s = input()
n = len(s) - 1

ans = 0
for i in range(2 ** n):
    op = [""] * n
    for j in range(n):
        if (i >> j) & 1:
            op[j] = "+"
    formula = ""
    for p_n, p_o in zip(s, op + [""]):  # 少々モヤッとする
        formula += (p_n + p_o)
    ans += eval(formula)
print(ans)

Measured memory_bytes: 3060
from itertools import combinations as ic
S = list(input())
pos = [i for i in range(1, len(S))]
total = 0
for p in range(len(S)):
  combs = ic(pos, p)
  for comb in combs:
    ans = ''
    for j, n in enumerate(S):
      if j in comb:
        ans += '+' + n
      else:
        ans += n
    total += eval(ans)
print(total)

Measured memory_bytes: 3064
a = [int(i) for i in input().split()] 
N = a[0]
X = a[1]
b = [int(i) for i in input().split()]
count = 0
for i in range(N):
  count += b[i]
  if count > X:
    print(i + 1)
    break
  if i+1 == N:
    print(N + 1)
    

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

bool cnt[1000005];

int main() {
	int n; cin >> n;
	vector<int> a(n);
	for (int& e : a) cin >> e;
	int t = a[0];
	for (int i = 1; i < n; ++i) t = gcd(t, a[i]);
	if (t != 1) {
		cout << "not coprime" << endl;
		return 0;
	}
	
	for (int i = 0; i < n; ++i) {
		int t = a[i];
		for (long long j = 2; j * j <= t; ++j) {
			if (t % j) continue;
			while (t % j == 0) t /= j;
			if (cnt[j]) {
				cout << "setwise coprime" << endl;
				return 0;
			}
			cnt[j] = true;
		}
		if (t != 1) {
			if (cnt[t]) {
				cout << "setwise coprime" << endl;
				return 0;
			}
			cnt[t] = true;
		}
	}
	cout << "pairwise coprime" << endl;

	return 0;
}

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

const int maxn = (int)2e5 + 3;
int n;
char buf[maxn];
struct Segment {
	int cnt, val[2];
	void merge(Segment const &lft, Segment const &rht) {
		cnt = lft.cnt + rht.cnt;
		val[0] = lft.val[0] + rht.val[lft.cnt & 1];
		val[1] = lft.val[1] + rht.val[!(lft.cnt & 1)];
	}
} seg[maxn << 1 | 1];

inline int seg_idx(int L, int R) {
	return (L + R) | (L < R);
}
int seg_init(int L, int R) {
	int rt = seg_idx(L, R);
	if(L < R) {
		int M = (L + R) >> 1;
		int lch = seg_init(L, M);
		int rch = seg_init(M + 1, R);
		seg[rt].merge(seg[lch], seg[rch]);
	} else {
		seg[rt] = (Segment){0, 0, 0};
	}
	return rt;
}
int seg_upd(int L, int R, int x, int v) {
	int rt = seg_idx(L, R);
	if(x < L || x > R)
		return rt;
	if(L == R) {
		seg[rt] = (Segment){1, v, 0};
	} else {
		int M = (L + R) >> 1;
		int lch = seg_upd(L, M, x, v);
		int rch = seg_upd(M + 1, R, x, v);
		seg[rt].merge(seg[lch], seg[rch]);
	}
	return rt;
}

int main() {
	scanf("%s", buf);
	n = strlen(buf);
	int rt = seg_init(0, n - 1);
	LL ans = 0;
	for(int i = 0; i < n; ++i)
		if(buf[i] == '1') {
			seg_upd(0, n - 1, i, 1);
			ans += seg[rt].val[0];
		}
	int odd = 0;
	for(int i = 0; i < n; ++i)
		if(buf[i] == '1') {
			odd ^= 1;
		} else if(odd) {
			seg_upd(0, n - 1, i, 0);
			ans += seg[rt].val[0];
			buf[i] = '.';
			odd = 0;
		}
	for(int i = n - 1; i >= 0; --i)
		if(buf[i] == '0') {
			seg_upd(0, n - 1, i, 0);
			ans += seg[rt].val[0];
		}
	printf("%lld\n", ans);
	return 0;
}

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

int main() {
  char A,B;
  cin>>A;
  B=A+1;
cout<<B<<endl;
}


Measured memory_bytes: 3532
//#include<bits/stdc++.h> using namespace std;
#include<iostream>
using namespace std;
#include<algorithm>
#include<map>
#include<vector>
#include<set>
#include<stack>
#include<queue> //priority_queue inside queue
#include<deque>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define nl '\n'
typedef long long ll;
typedef unsigned long long ull;
#define f(i,start,end) for(i=start;i<=end;i++)
#define min_heap priority_queue<int, vector<int>, greater<int> >
#define max_heap priority_queue<int>

bool isPrime(int n)
{
    for(int i=2; i*i<=n; i++)
    {
        if(n%i==0) return false;
    }
    return true;
} //returns true if prime!


int main()
{
fast;
//int t=0,tc=0; cin >> tc; f(t,1,tc) //testcases
{
   int i=0, j=0, k=0, n=0, tmp=0;
   cin >> n;
   map<ll,ll> m;
   f(i, 0, n-1)
   {
     cin >> tmp;
     m[tmp]++;
   }
   ll sum=0;
   for(auto it: m)
   {
      sum += it.first*it.second;
   }

   int q=0; cin >> q;
   while(q--)
   {
      ll a,b; cin >> a >> b;
      sum -= (a * m[a]);
      sum += (m[a] * b);
      m[b] += m[a];
      m.erase(a);
      cout << sum << nl;
   }
   
}
return 0;
}
    

Measured memory_bytes: 7508
#include<bits/stdc++.h>
using namespace std;
const int a[6]={0,1,2,3,4,5};
int main(){
	int x;
	cin>>x;
	int n=x/100;
	x=x%100;
	int cnt=0;
	for(int i=5;i>=0;i--){
		cnt+=(x/a[i]);
		x=x-a[i]*(x/a[i]);
		if(x==0) break;
	}
	if(cnt>n){
		printf("0\n");
		return 0;
	}
	if(x==0){
		printf("1\n");
	}else{
		printf("0\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <functional>
using namespace std;

int main() {
  string S;
  cin >> S;
  std::sort(S.begin(),S.end());
  if (S.at(0)==S.at(1)&&S.at(2)==S.at(3)&&S.at(0)!=S.at(2)) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256