akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

#define N_MAX 1000

int main(void)
{

	int n;
	int w,h;

	int x,y;

	int s,t;
	int f[N_MAX][N_MAX];

	int count;
	int max;

	int i1,i2,i3,i4;

	while(1){

		cin >> n;
		if(n==0) break;
		cin >> w;
		cin >> h;



		/* syoki*/
		for (i1=0;i1<h;i1++){
			for (i2=0;i2<w;i2++){
				f[i1][i2]=0;
			}
		}

		/* tree */
		for (i1=0;i1<n;i1++){
			cin >> x;
			cin >> y;

			f[y-1][x-1] = 1;

		/*	cout << endl;

			for (i3=0;i3<h;i3++){
				for (i2=0;i2<w;i2++){

					cout << f[i3][i2] << " ";
				}
				cout << endl;
			}*/
		


		}

		cin >> s; 
		cin >> t;

		max = 0;
		
		for(i1=0;i1<=h-t;i1++){
			for(i2=0;i2<=w-s;i2++){


				count = 0;
				for(i3=i1;i3<t+i1;i3++){
					for(i4=i2;i4<s+i2;i4++){
						if (f[i3][i4]==1){
							count++;
						}
					}
				}
				
				//cout << count << " ";

				if (max < count){
					max = count;
				}
			}
		}

		//cout << endl;
		/* print */
		
	/*	for (i1=0;i1<h;i1++){
			for (i2=0;i2<w;i2++){

				cout << f[i1][i2] << " ";
			}
			cout << endl;
		}
	*/	

		cout << max << endl;
	}

	return 0;
}

Measured memory_bytes: 1548
from heapq import heappop, heappush


def solve(field, s, t, k):
    INF = 10 ** 18
    ans = [[INF, INF] for _ in field]
    ans[s][0] = ans[s][1] = 0
    MOVE = [(-w2, 0), (-1, 1), (1, 1), (w2, 0)]

    q = [(0, 0, s, 0)]
    while q:
        cost, straight, v, direction = heappop(q)
        if v == t:
            return (cost - 1) // k + 1

        ceiling = ((cost - 1) // k + 1) * k + 1
        for di, ax in MOVE:
            u = v + di
            if field[u] == '@':
                continue
            if di == direction:
                nc = cost + 1
                ns = straight + 1
                if ns > k:
                    ns -= k
            else:
                nc = ceiling
                ns = 1
            if ans[u][ax] <= nc:
                continue
            ans[u][ax] = nc
            heappush(q, (nc, ns, u, di))

    return -1


h, w, k = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())
h2 = h + 2
w2 = w + 2

field_tmp = [input() for _ in range(h)]
field = ['@' * w2]
for row in field_tmp:
    field.append('@')
    field.append(row)
    field.append('@')
field.append('@' * w2)
field = ''.join(field)
s = x1 * w2 + y1
t = x2 * w2 + y2
print(solve(field, s, t, k))


Measured memory_bytes: 444988
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int A = 0, B = 0, C = 0, D = 0;
  	int L = 0, R = 0;
  
  cin >> A >> B >> C >> D;
  
  L = A + B;
  R = C + D;
  
  if (L == R){
  cout << "Balanced" << endl;
  }
  else if (L > R){
  cout << "Left" << endl;
  }
  else{
  cout << "Right" << endl;
  }
  
}


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

int main() {
	int n; cin >> n;
	map<int, int>a;
	for (int i = 0, tmp; i < n; i++) {
		cin >> tmp; a[tmp]++;
	}
	int ans = 1;
	for (auto&& x : a) {
		if (x.first == 0) {
			if (n % 2 == 0) {
				if (x.second > 0) { cout << 0 << endl; return 0; }
			}
			else {
				if (x.second != 1) { cout << 0 << endl; return 0; }
			}
		}
		else {
			if (x.second != 2) { cout << 0 << endl; return 0; }
			else (ans *= 2) %= (int)1e9 + 7;
		}
	}
	cout << ans << endl;

	return 0;
}

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

int main(){
    int H, W;
    while(true){
        scanf("%d %d", &H, &W);
        if(H == 0 && W == 0) break;
        for(int i = 0; i < H; i++){
            printf("%c", '#');
            for(int j =0; j < W - 2; j++){
                if(i == 0 || i == H - 1) printf("%c", '#');
                else printf("%c", '.');
            } 
            printf("%c\n", '#');
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 1032
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;



#define INF 2000000000
#define MAX_V 10



bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

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

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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;
}
const ll MAX = 5100000;
const ll MOD = 1000000007;
 
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

using graph = vector<vector<ll>>;

string divide[4]={"dream","dreamer","erase","eraser"};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin>>s;
    reverse(ALL(s));
    rep(i,4) reverse(ALL(divide[i]));
    
    bool can=true;
    for(ll i=0;i<s.size();){
        bool can2=false;
        rep(j,4){
            string d=divide[j];
            if(s.substr(i,d.size())==d){
                can2=true;
                i+=d.size();
            }
        }
        if(!can2){
            can=false;
            break;
        }
    }
    cout<<(can ? "YES":"NO")<<endl;
    return 0;
}


Measured memory_bytes: 512
K = 1000000007
S = input()
l = len(S)
li = [1] + [0] * 12
work_lists = [[0] * 13 for i in range(6)]
for i in range(6):
    for x in range(10):
        work_lists[i][(x * (10 ** i)) % 13] = 1
for i in range(l):
    s = S[l - i - 1]
    if s == "?":
        work_li = work_lists[i % 6]
        next_li = [sum([work_li[j] * li[(k - j) % 13] for j in range(13)]) % K for k in range(13)]
    else:
        n = int(s)
        r = (n * (10 ** (i % 6))) % 13
        next_li = [li[(j - r) % 13] for j in range(13)]
    li = next_li
print(li[5])


Measured memory_bytes: 44524
def main():
    from math import ceil
    n, a, b, *k = map(int, open(0).read().split())
    k.sort()

    l = k[-1] // a
    r = k[-1] // b + 1
    m = (l + r) // 2
    while l + 1 < r:
        c = sum(ceil((i - m * b) / (a - b)) if i - m * b > 0 else 0 for i in k)
        (l, r) = (l, m) if c <= m else (m, r)
        m = (l + r) // 2

    print(r)


if __name__ == '__main__':
    main()


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

ll n, k, p, dp[505][505], comb[505][505];

int main() {
	cin >> n >> k >> p;
	for (int i = 0; i < 505; ++i)
		for (int j = 0; j <= i; ++j) {
			if (j == 0)
				comb[i][j] = 1;
			else
				comb[i][j] = (comb[i-1][j] + comb[i-1][j-1])%p;
		}

	for (int i = 1; i <= n+1; ++i)
		for (int j = k; j >= 0; --j) {
			if (i == 1) {
				dp[i][j] = 1 + dp[i][j+1];
				continue;
			}
			dp[i][j] = dp[i][j+1];
			for (int l = 0; l < i-1; ++l) {
				dp[i][j] = (dp[i][j] + comb[i-2][l]*dp[l+1][j+1]%p*(dp[i-l-1][j] + p - dp[i-l-1][j+1]))%p;
			}
		}

	cout << (p + dp[n+1][0] - dp[n+1][1])%p << endl;
}

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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const ll MOD2 = 998244353;
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; }

int main()
{
  //input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int N; cin >> N;
  //main
  set<int> st;
  for(int i=0; i<9; i++){
    for(int j=i; j<9; j++){
      st.insert((i+1)*(j+1));
    }
  }
  
  // output
  if(st.find(N) != st.end()){cout <<  "Yes" << endl;}
  else{cout << "No" << endl;}

  return 0;
}

Measured memory_bytes: 256
MOD = 10 ** 9 + 7
def add(a, b):
  return (a + b) % MOD
def sub(a, b):
  return (a - b) % MOD
def mul(a, b):
  return ((a % MOD) * (b % MOD)) % MOD
def div(a, b):
  return ( (a % MOD) * (power(b, MOD)) ) % MOD
def power(a, b):
  return pow(a, b, MOD)

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
  
N = 2000
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % MOD )
    inverse.append( ( -inverse[MOD % i] * (MOD//i) ) % MOD )
    g2.append( (g2[-1] * inverse[-1]) % MOD )

n, k = map(int, input().split())
for i in range(1, k+1):
  cnt = mul(cmb(n-k+1, i, MOD), cmb(k-1, i-1, MOD))
  print(cnt)


Measured memory_bytes: 3572
#include<stdio.h>
#define ll long long int
int main()
{
    ll a,b,c;
    scanf("%lld %lld %lld",&a,&b,&c);
    ll d,e;
    d=a-b;
    e=c-d;
    if(e<0)
        printf("0\n");
    else
        printf("%lld\n",e);
    return 0;

}


Measured memory_bytes: 128
N = int(input())
L = [i for i in map(int,input().split())]
ans = dict()
for i in range(1,N+1):
    ans[i] = 0
for el in L:
    if el in ans:
        ans[el] += 1
for i in range(1,N+1):
    print(ans[i])

Measured memory_bytes: 38840
#include<bits/stdc++.h>
using namespace std;
const int maxx=2e6+2;
typedef long long ll;
const ll mod=1e9+7;
int a[maxx],bt[maxx];
ll fpow(ll x,ll n){
    ll res=1;
    while(n){
        if(n&1) res=res*x%mod;
        x=x*x%mod;
        n >>=1;
    }
    return res;
}
int lowbit(int x){
    return x&-x;
}
int mx=2000;
void add(int x,int val){
    while(x<=mx){
        bt[x]+=val;
        x+=lowbit(x);
    }
}
int ask(int x){
    int res=0;
    while(x){
        res+=bt[x];
        x-=lowbit(x);
    }
    return res;
}
int main(){
    int n;ll k; cin>>n>>k;
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    ll ans=0;
    ll inv2=fpow(2,mod-2);
    ll res=(k-1)*k%mod*inv2%mod;
    for(int i=1;i<=n;i++){
        add(a[i],1);
        ll x=ask(a[i]);
        x=i-x;
        (ans+=x*k)%mod;
    }
    for(int i=1;i<=n;i++){
        ll x=ask(a[i]);
        x=n-x;
        (ans+=x*res%mod)%=mod;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 2304
import sys
input = lambda: sys.stdin.readline().rstrip() 
import math

def resolve():
    A, B = map(int, input().split())
    ans = -1
    for i in range(2000):
        if math.floor(i*0.08)==A and math.floor(i*0.10)==B:
            ans = i
            break
    print(ans)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=2e5+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
#endif
}
int n,dp[N];
void input()
{
	n=read<int>();
}
int ans;
void work()
{
	int x;
	For(i,1,n)
	{
		x=read<int>();
		cmax(dp[x],dp[x-1]+1);
		cmax(ans,dp[x]);
	}
	write(n-ans,'\n');
}
int main()
{
	//file();
	input();
	work();
	return 0;
}


Measured memory_bytes: 1024
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

ll N, M;
ll A[100001], sum[100001];

int Solve(){
  sort(sum, sum + N + 1);
  ll ans = 0, cnt = 1;
  for (int i = 1; i < N + 1; i++){
    if (sum[i] == sum[i - 1]) cnt++;
    else{
      ans += cnt * (cnt - 1) / 2;
      cnt = 1;
    }
  }
  ans += cnt * (cnt - 1) / 2;
  cout << ans << endl;
  return 0;
}

int main(){
  cin >> N >> M;
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 1; i < N + 1; i++){
    sum[i] = sum[i - 1] + A[i - 1];
    sum[i] %= M;
  }
  
  Solve();
  
  return 0;
}

Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

def solve():
    n, q = MI()
    S = input()
    ats = [0]
    cnt = 0
    for i in range(n-1):
        j = i + 2
        s = S[i:j]
        # print(s)
        if s == 'AC':
            cnt += 1
        ats.append(cnt)
    # print(ats)
    for _ in range(q):
        l, r = MI1()
        # print(S[l:r+1])
        print(ats[r] - ats[l])


if __name__ == '__main__':
    solve()


Measured memory_bytes: 6436
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val H, W = sc.nextLong()

    // 三つのブロックを出来るだけ均等に分割したい
    // 完全に均等に分割できた場合 S_{max} - S_{min} = 0
    // min(S_{max} - S_{min}) を求める
    // しかも、ブロックは長方形に分割する必要がある
    // 明らかにO(HW)では間に合わないので,
    // ブロック上を1つずつ操作したりするのでは通らない
    // 一つ目の長方形の縦幅を全探索する
    // S_A = hWと決まる
    // 縦2つに分割するケースと横2つに分割するケースがある
    // 縦2つに分割するケース
    // h' = (H - h) / 2
    // S_B = h' * W, S_C = (H - h - h') * W
    // 横2つに分割するケース w = [W/2]
    // S_B = (H - h) * w, S_C = (H - h) * (W - w)
    // (S_A max S_B max S_C) - (S_A min S_B min S_C)
    // をそれぞれのケースで求める

    def solve(H: Long, W: Long): Long = {
      def calc(H: Long, W: Long): Long = {

        def case1(S_A: Long, h: Long): Long = {
          val hh = (H - h) / 2L
          val S_B = hh * W
          val S_C = (H - h - hh) * W
          (S_A max S_B max S_C) - (S_A min S_B min S_C)
        }

        def case2(S_A: Long, h: Long): Long = {
          val w = W / 2L
          val S_B = (H - h) * w
          val S_C = (H - h) * (W - w)
          (S_A max S_B max S_C) - (S_A min S_B min S_C)
        }

        def loop(h: Long, min: Long): Long =
          if (h <= H - 1L) {
            val S_A = h * W
            loop(h + 1L, min min {
              if (h < H - 1) case1(S_A, h) else Int.MaxValue
            } min {
              case2(S_A, h)
            })
          } else min
        loop(1L, Int.MaxValue)
      }
      calc(H, W) min calc(W, H)
    }

    println(solve(H,W))
  }

}


Measured memory_bytes: 27448
import java.util.ArrayList;
import java.util.Scanner;
public class Main{
    static Node [] N;
    static boolean [] seen;
    static int [] d;
    static int [] f;
    static int counter = 1;


    static public class Node{
        int id;
        ArrayList<Integer> edges = new ArrayList<>();
        public Node(int id) {
            this.id = id;
        }
        public void add(int e){
            edges.add(e);
        }
    }

    static public void dfs(int i) {
        d[i] = counter;
        seen[i] = true;
        counter++;
        if(N[i].edges.isEmpty()){

        }
        else{

        }
        for (int j : N[i].edges) {
            if (!seen[j - 1]) {
                dfs(j - 1);
            }
        }
        counter++;
        f[i] = counter;
    }

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        N = new Node[n];
        seen = new boolean[n];
        d = new int[n];
        f = new int[n];
        for(int x = 0; x < n; x++){
            int id = scan.nextInt();
            N[x] = new Node(id);
            int ed = scan.nextInt();
            for(int y = 0; y < ed; y++){
                int check = scan.nextInt();
                N[x].add(check);
            }
        }
        for(int x = 0; x < n; x++){
            if(!seen[x]) {
                dfs(x);
            }
        }
        for(int x = 0; x < n; x++){
            System.out.println(N[x].id + " " + d[x] + " " + (f[x] - 1));
        }
    }

}


Measured memory_bytes: 28180
#include <iostream>
#include <vector>
#include <cmath>
#include <utility>
#include <queue>
#include <map>
#include <list>
#include <set>
#include <numeric>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

int h, w, k;
const static int MAX = 1000000;

vector<bool> pattern(int i) {
  vector<bool> ret;
  rep(j, h - 1) {
    ret.push_back(i % 2 == 0);
    i /= 2;
  }
  return ret;
}

int calc(int ip, const vector< vector<int> >& ss) {
  vector<bool> q(pattern(ip));
  vector<int> index(h, 0);
  for (int i = 1; i < h; ++i) index[i] = index[i - 1] + (q[i - 1] ? 1 : 0);
  // cout << "index : ";
  // for (auto ind : index) cout << ind << ",";

  int n = accumulate(q.begin(), q.end(), 0) + 1;// 分割数
  vector< vector<int> > counts(n, vector<int>(w, 0));
  rep(ih, h) {
    rep(iw, w) {
      counts[index[ih]][iw] += ss[ih][iw];
      if (counts[index[ih]][iw] > k) return MAX;
    }
  }
  // cout << endl << "counts : ";
  // for (auto v : counts) for (auto x : v) cout << x << ",";
  // cout << endl;

  int count = n - 1;
  vector<int> current(n, 0);
  rep(ih, n) current[ih] = counts[ih][0];
  rep(iw, w - 1) {
    rep(ih, n) {
      if (current[ih] + counts[ih][iw + 1] <= k) {
        current[ih] += counts[ih][iw + 1];
      }
      else {
        // cout << "counted " << ih << "," << iw << endl;
        ++count;
        rep(ih, n) current[ih] = counts[ih][iw + 1];
        break;
      }
    }    
  }
  return count;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cin >> h >> w >> k;
  vector< vector<int> > ss(h, vector<int>(w));
  rep(i, h) {
    string s;
    cin >> s;
    rep(j, w) ss[i][j] = s[j] - '0';
  }
  int ans = MAX;

  rep(i, pow(2, h - 1)) {    
    // for (auto b : pattern(i)) cout << b << ", ";
    // cout << "cost = ";
    // cout << calc(i, ss) << endl;
    ans = min(ans, calc(i, ss));
  }
  cout << ans << endl;
  return 0;
}




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

int n;
ll d, a, ans = 0, x = 0, k[200010];
struct node {
    ll x, h;
} q[200010];
inline bool cmp(node a, node b) {
    return a.x < b.x;
}
int main() {
	scanf("%d%lld%lld", &n, &d, &a);
    for (register int i=1; i<=n; ++i) {
        scanf("%lld%lld", &q[i].x, &q[i].h);
    }
    std :: sort(q + 1, q + n + 1, cmp);
    for (register int i=1; i<=n; ++i) {
        x += k[i];
        if (q[i].h > x) {
            int cnt = (q[i].h - x - 1) / a + 1;
            ans += cnt;
            int l = i, r = n, s;
            while (l <= r) {
                int mid = (l+r) >> 1;
                if (q[mid].x < q[i].x+d*2) s = mid, l = mid+1;
                    else if (q[mid].x == q[i].x+d*2) { s = mid; break; }
                    else r = mid-1;
            }
            //cout << s << endl;
            k[i+1] += cnt * a;
            k[s+1] -= cnt * a;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 4992
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
now = a[0]
for i in range(n):
    ato_taoseru = b[i]
    if ato_taoseru <= now:
        ans += ato_taoseru
        now = a[i + 1]
    else:
        ans += now
        ato_taoseru -= now
        now = a[i + 1]
        if ato_taoseru <= now:
            ans += ato_taoseru
            now -= ato_taoseru
        else:
            ans += now
            now = 0

print(ans)

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

// iterator
#define REP(i,from, to) for(lli i=from;i<to;i++)
#define REPE(i,from, to) for(lli i=from;i<=to;i++)
#define REP_R(i,from, to) for(lli i=from;i>to;i--)
#define REPE_R(i,from, to) for(lli i=from;i>=to;i--)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;

vector<lli> G[51];
bool done[51][51];

bool rec(lli origin, lli from, lli to) {
    if (done[from][to])
        return false;
    if (to == origin)
        return true;

    done[to][from] = done[from][to] = true;
    REP(i,0,G[to].size()) {
        if (G[to][i] == from)
            continue;
        if (rec(origin, to, G[to][i])) {
            return true;
        }
    }
    return false;

}
int main() {
    lli n,m;
    cin2(n,m);
    REP(i,0,m) {
        lli a,b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    lli ans = 0;
    REPE(i,1,n) {
        REP(j,0,G[i].size()) {
            REPE(k,1,n) {
                REPE(l,1,n) {
                    done[l][k] = done[k][l] = false;
                }
            }

            if (i > G[i][j])
                continue;
            if (rec(i, i,G[i][j])) {
                //cout2(i,G[i][j])
                ans++;
            }
        }
    }
    cout << m - ans << endl;
}


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

using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair<int, int>;

/* [💭] [💡] [🎈] */

int a[200000];

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

    int n;
    cin >> n;
    if (n == 1) {
        cout << 0;
        return 0;
    }
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    ll s = a[n - 1];
    int c = n - 2, i = n - 2;
    while (c) {
        if (c >= 2) {
            s += (ll) a[i] * 2;
            c -= 2;
        } else {
            s += a[i];
            c--;
        }
        i--;
    }
    cout << s;

    return 0;
}

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

void printVectorInt(vector<int> A)
{
    for (int i = 0; i < A.size(); i++)
    {
        cout << A[i];
        if (i == A.size() - 1)
        {
            cout << endl;
        }
        else
        {
            cout << " ";
        }
    }
}

vector<int> insertionSort(vector<int> A, int N)
{
    int v,j;
    for (int i = 1; i < N; i++)
    {
        v = A[i];
        for (j = i - 1; j >= 0 && A[j] > v; j--)
        {
            A[j + 1] = A[j];
        }
        A[j + 1] = v;
        printVectorInt(A);
    }
    return A;
}

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    printVectorInt(a);
    insertionSort(a, n);
    return 0;
}


Measured memory_bytes: 3176
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
using namespace std;

#define rep(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define SZ(x) ((int) (x).size())
typedef long long ll;

int main(){
	string str;
	while(cin >> str) {
		bool f = 1;
		int len = str.length();
		for(;;) {
			len--;
			if(len % 2 == 1) continue;
			if(str.substr(0, len/2) == str.substr(len/2, len/2)) {
				cout << len << endl;
				f = 0;
				break;
			}
		}
		if(f) cout << 0 << endl;
	}
    return 0;
}


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


public class MyProgram
{	
    static int min = 999999999;
    static int G = 0;
    static int D = 0;
    static int[] Q = new int[10];
    static int[] B = new int[10];
    
    public static void Main()
	{
	    int[] n = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
	    D = n[0];
	    G = n[1];
	    
	    for(int i = 0 ; i < D ; i++)
	    {
	        n = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
	        Q[i] = n[0];
	        B[i] = n[1];
	    }
	    string ss = "";
	    tansaku(ss);
	    Console.WriteLine(min);
	}
	
	public static void tansaku(string s)
	{
	    if(s.Length == D)
	    {
	        keisan(s);
	    }
	    else
	    {
	        tansaku(s+"1");
	        tansaku(s+"0");
	    }
	}
	
	public static void keisan(string s)
	{
	    char[] c = s.ToCharArray();
	    int cnt = 0;
	    int a = 0;
	    
	    for(int i = 0 ; i < D ; i++)
	    {
	        if(c[i] == '1')
	        {
	            a += (Q[i] * (i+1) * 100 ) + B[i];
	            cnt += Q[i];
	        }
	    }
	    
	    for(int i = D-1 ; i >= 0 ; i--)
	    {
	        if(c[i] == '0')
	        {
	            int aa = 0;
	            while(G > a && aa < Q[i])
	            {
	                a += ((i+1) * 100);
	                aa ++;
	                cnt++;
	            }
	            break;
	        }
	    }
	    if(min > cnt && G <= a)
	    {
	        min = cnt;
	    }
	}
}

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

int main ()
{
	int i,l;
	while ( cin >> i >> l)
	{
		int array[i+1][l+1],out;
		for ( int zero_i = 0; zero_i < ( i + 1); zero_i++)
		{
			for ( int zero_l = 0; zero_l < ( l + 1); zero_l++)
			{
				array[zero_i][zero_l] = 0;
			}
		}
		
		for ( int in_i = 0; in_i < i; in_i++)
		{
			for ( int in_l = 0; in_l < l; in_l++)
			{
				cin >> array[in_i][in_l];
				array[in_i][l] += array[in_i][in_l];	
			} 
		}
		
		for ( int sum_l = 0; sum_l < ( l + 1 ); sum_l++)
		{
			for ( int sum_i = 0; sum_i < i; sum_i++)
			{
				array[i][sum_l] += array[sum_i][sum_l];
			}
		}
		
		for ( int out_i = 0; out_i <= i; out_i++)
		{
			for ( int out_l = 0; out_l <= l; out_l++)
			{
				if ( out_l != l)
				{
					cout << array[out_i][out_l] << " ";
				}
				else
				{
					cout << array[out_i][out_l] << "\n";
				}
			}
		}
	}
	return 0;
}


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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mem(x,val) memset((x),(val),sizeof(x))
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define PI acos(-1.0) 
#define N 111111

const int INF = 1 << 30 ;
typedef long long ll ;
typedef pair < int , int > pii ;

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

int main() {
  int h, w, count  ;
  scanf("%d %d", &h, &w) ;

  char mat[h+1][w+1] ;

  for(int i = 0 ;i<h ; i++)
    scanf("%s", mat[i]) ;

  for(int i = 0 ;i<h ; i++){
    for(int j = 0 ; j<w ;j++){
      if(mat[i][j] == '.'){
        count = 0 ;
        for(int k = 0 ;k<8 ; k++){
          int x = i +dx[k] ;
          int y = j + dy[k] ;
          if(x < 0 || x >=h || y<0 || y>=w) continue ;
          if(mat[x][y] == '#') count++ ;
        }
        mat[i][j] = count + '0' ;
      }
    }
  }

  for(int i = 0 ;i<h ; i++)
    cout << mat[i] << endl ;


  return 0 ;
}

Measured memory_bytes: 256
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int tmp;
    vector<int> b(3);
    REP(i, 3) cin >> b[i];
    sort(b.begin(), b.end());
    ans = b[0]+b[1];
    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
A = 0
B = 0
for i in range(n):
    A += max(0, (b[i] - a[i]) // 2)
    B += max(0, a[i] - b[i])
if sum(b) >= sum(a):
    if A >= B:
        print("Yes")
        exit()
print("No")

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

int main(){
  int N,C = 0;
  cin >> N >> C;

  int p[C];
  int All_Cake = 0;
  for(int i=0; i<C; i++){
    cin >> p[i];
    All_Cake += p[i];
  }

  N++;
  int A = All_Cake/N;

  if(All_Cake%N>0)
   A++;

  cout << A << endl;

  return 0;
}



Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define all(a) a.begin(), a.end()

signed main() {
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	string x;
	cin >> x;

	int s = 0, t= 0;

	for(int i = 0; i < x.size(); i++) {
		if(x[i] == 'S') {
			s++;
		} else {
			if(s > 0) s--;
			else t++;
		}
	}

	cout << s + t << endl;

	return 0;
}

Measured memory_bytes: 3744
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;

bool minstr(string s1, string s2){ // s1 < s2 かどうか？
	int l1 = (int)s1.length();
  	int l2 = (int)s2.length();
  	int l = min(l1,l2);
  
  	rep(i, l){
		if(s1[i] - s2[i] == 0){
        	;
        }
      	else if(s1[i] - s2[i] > 0){
			return false;
        }
      	else{
          	return true;
        }
    }
  
	if(l1 >= l2){
      	return false;
    }
	else{return true;}
}

void swapstr(string &s1, string &s2){
	string temp;
  	temp = s1;
  	s1 = s2; 
  	s2 = temp;
  	return;
}

void Main()
{
	int N, L;
  	cin >> N >> L;
  	vector<string> S(N);
  	rep(i,N){ cin>>S[i]; }
  	

  	rep3(i,0,N-2){
      	rep3(j,1,N-i-1){
  			if( minstr(S[i], S[i+j]) ){
          		;
            }
         	else{
         		swap(S[i],S[i+j]);
         	}
        }
  	}

      rep(i,N){
      cout << S[i];
      }
      return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  ABC131C
//
//  Created by 佐藤拓朗 on 2019/06/25.
//  Copyright © 2019年 佐藤拓朗. All rights reserved.
//

#include <iostream>
//#include <fstream>

using namespace std;
using ll = long long;


ll gcd(ll a, ll b) {
    if(a < b) return gcd(b, a);
    ll r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

ll lcm(ll number1,ll number2){
    return number1 * number2 / gcd(number1,number2);
}

ll numMultiple(ll A, ll B, ll num)
{
    ll lMultiple = A % num ? (A / num + 1) * num : A;
    if (lMultiple > B)
    {
        return 0;
    }
    ll rMultiple = B % num ? (B / num) * num : B;
    if (rMultiple == lMultiple)
    {
        return 1;
    }
    
    return rMultiple / num - lMultiple / num + 1;
}

int main(int argc, const char * argv[]) {
//    fstream in("input.txt");
//    cin.rdbuf(in.rdbuf());
    
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    
    ll lcmCd = lcm(C, D);
    ll cnt = (B - A + 1) - (numMultiple(A, B, C) + numMultiple(A, B, D) - numMultiple(A, B, lcmCd));
    
    cout << cnt << endl;
    
//    ll cnt = 0;
//
//    for (ll i = A; i <= B; i++)
//    {
//        if (i % C != 0 && i % D != 0)
//        {
//            ++cnt;
//        }
//    }
//
//    cout << cnt << endl;
    
//    cout << numMultiple(A, B, C) << endl;
//    cout << numMultiple(A, B, D) << endl;
//    cout << lcmCd << endl;
//    cout << numMultiple(A, B, lcmCd) << endl;
    
    return 0;
}

Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf = 1e12 ;


vector<ll> daikus(vector<vector<mp> > &g,int s){
	int n = g.size();
	vector<ll> res(n,inf);
	priority_queue<mp,vector<mp>,greater<mp> > q;
	q.push(mp(0,s) );
	while(!q.empty()){
	    mp now = q.top();
	    q.pop();
	    ll nn = now.second;
	    ll cost = now.first;
	    if( res[nn] != inf) continue;
	    res[nn] = cost;
	    for(int i=0;i<g[nn].size();i++){
		ll next = g[nn][i].second;
		ll nc = cost + g[nn][i].first;
		if(res[next] != inf ) continue;
		q.push( mp(nc,next) );
	    }
	}
	return res;
}

int main(){
    ll n,m;
    ll sum = 0;
    cin>>n>>m;
    vector<vector<mp> > g( n );
    vector<ll> deg(n,0);
    vector<ll> odds;
    for(int i=0;i<m;i++){
	ll s,t,d;
	cin>>s>>t>>d;
	g[s].push_back(mp(d,t) );
	g[t].push_back(mp(d,s) );
	sum += d;
	deg[s]++;
	deg[t]++;
    }
    for(int i=0;i<n;i++) if( deg[i] %2 == 1) odds.push_back(i);
    int v = odds.size();
    vector<vector<ll> > G(v,vector<ll>(v));
    for(int i=0;i<v;i++){
	vector<ll> tmp = daikus(g,odds[i]);
	for(int j=0;j<v;j++) G[i][j] = tmp[ odds[j] ];
    }

    vector<ll> dp(1<<v,inf);
    dp[0] = 0;
    for(int k = 0;k< (1<<v);k++){
	for(int i=0;i<v;i++){
	    if(k&(1<<i) ) continue;
	    for(int j=i+1;j<v;j++){
		if(k&(1<<j) ) continue;
		dp[ k | (1<<i) | (1<<j) ] = min( dp[ k | (1<<i) | (1<<j)] , dp[k] + G[i][j] ) ;
	    }
	}
    }
    cout<<sum + dp[ (1<<v)-1 ] <<endl;
    return 0;
}



Measured memory_bytes: 3244
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
typedef long long ll;
ll n,k;
void multiply(ll *a1,ll *b1)
{
    ll mul[n][n];
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<n;j++)
        {
            mul[i][j]=0;
            for(ll k=0;k<n;k++)
            {
                mul[i][j]+=((*((a1+i*n)+k)))*(*((b1+k*n)+j));
                if(mul[i][j]%mod!=0)
                mul[i][j]=mul[i][j]%mod;
            }
        }
    }
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<n;j++)
        (*((a1+i*n)+j))=mul[i][j];
    }
}
int main()
{
    cin>>n>>k;
    ll arr[n][n];
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<n;j++)
        cin>>arr[i][j];
    }
    ll ans[n][n];
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<n;j++)
        {
            if(i==j)
            ans[i][i]=1;
            else
            ans[i][j]=0;
        }
    }
    while(k>0)
    {
        if(k&1)
        multiply((ll*)ans,(ll*)arr);
        multiply((ll*)arr,(ll*)arr);
        k/=2;
    }
    ll kk=0;
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<n;j++)
        kk=(kk+ans[i][j])%mod;
        
    }
    cout<<(kk+mod)%mod<<"\n";
    return 0;
}

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


int main()
{
	string S;
	cin >> S;
	int i = 1;
	int swt = 0;
	for (char c : S)
	{
		if (i % 2)
		{
			if (c == 'L')
				swt = 1;
		}
		else
			if (c == 'R')
				swt = 1;
		i++;
	}
	if (swt == 0)
		cout << "Yes" << "\n";
	else
		cout << "No" << "\n";

}

Measured memory_bytes: 256
#include <iostream>

int main(){
   int A, B, X;
   std::cin >> A >> B >> X;

   if(A>X) std::cout << "NO" << std::endl;
   else if(A+B<X) std::cout << "NO" << std::endl;
   else std::cout << "YES" << std::endl;

   return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
class AC
{
    static void Main(string[] args)
    {
        var S = Cin.Int();
        const int mod = 1000000007;
        long modpow(long x, long n) => n == 0 ? 1 : (n % 2 == 0 ? modpow((x * x) % mod, n / 2) : (x * modpow(x, n - 1)) % mod);
        long[] fac = new long[S + 1], facinv = new long[S + 1];
        fac[0] = 1;
        for (var i = 1; i <= S; i++) fac[i] = (fac[i - 1] * i) % mod;
        facinv[S] = modpow(fac[S], mod - 2);
        for (var i = S; i > 0; i--) facinv[i - 1] = (facinv[i] * i) % mod;

        long ans = 0;
        for(var n = 1; S - 3 * n >= 0; n++)
        {
            ans += ((fac[S - 3 * n + n - 1] * facinv[n - 1]) % mod) * facinv[S - 3 * n];
            ans %= mod;
        }
        Console.WriteLine(ans);
    }
}
static class Cin
{
    public static string Str() => Console.ReadLine();
    public static int Int() => int.Parse(Cin.Str());
    public static long Long() => long.Parse(Cin.Str());
    public static double Double() => double.Parse(Cin.Str());

    private static T Conv<T>(string value) => (T)Convert.ChangeType(value, typeof(T));
    public static (T, U) ReadTuple<T, U>(string[] input) => (Conv<T>(input[0]), Conv<U>(input[1]));
    public static (T, U, V) ReadTuple<T, U, V>(string[] input) => (Conv<T>(input[0]), Conv<U>(input[1]), Conv<V>(input[2]));
    public static (T, U, V, W) ReadTuple<T, U, V, W>(string[] input) => (Conv<T>(input[0]), Conv<U>(input[1]), Conv<V>(input[2]), Conv<W>(input[3]));
    public static (T, U, V, W, X) ReadTuple<T, U, V, W, X>(string[] input) => (Conv<T>(input[0]), Conv<U>(input[1]), Conv<V>(input[2]), Conv<W>(input[3]), Conv<X>(input[4]));

    public static (T, U) Input<T, U>() => ReadTuple<T, U>(ReadSplit());
    public static (T, U, V) Input<T, U, V>() => ReadTuple<T, U, V>(ReadSplit());
    public static (T, U, V, W) Input<T, U, V, W>() => ReadTuple<T, U, V, W>(ReadSplit());
    public static (T, U, V, W, X) Input<T, U, V, W, X>() => ReadTuple<T, U, V, W, X>(ReadSplit());

    public static string[] ReadSplit() => Console.ReadLine().Split();
    public static string[] ReadSplit(char separator) => Console.ReadLine().Split(separator);
    public static int[] ReadSplitInt() => Array.ConvertAll(ReadSplit(), int.Parse);
    public static long[] ReadSplitLong() => Array.ConvertAll(ReadSplit(), long.Parse);
    public static double[] ReadSplit_Double() => Array.ConvertAll(ReadSplit(), double.Parse);
}


Measured memory_bytes: 27256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define INF 110000000000
#define MAX 100000
typedef long long ll;
typedef pair<ll,int> P;

int main(){
  int N,maxA1=0,maxA2=0,A[200000];
  cin>>N;
  for(int i=0;i<N;i++){
    int temp;
    cin>>temp;
    A[i]=temp;
    if(temp>maxA1){
      maxA2=maxA1;
      maxA1=temp;
    }else if(temp>maxA2){
      maxA2=temp;
    }
  }
  for(int i=0;i<N;i++){
    if(A[i]==maxA1) cout<<maxA2<<endl;
    else cout<<maxA1<<endl;
  }
}


Measured memory_bytes: 2432
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define int long long
using namespace std;

int a[200010];

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

inline void read(int& a){
    int s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')w=-1;ch=getchar();
    }
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    a=s*w;
    return;
}

inline void write(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}

inline void writeln(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
    puts("");
}

signed main(){
    int n=read(),k=read();
    
    for(int i=1;i<=n;i++)
        a[i]=read();
        
    for(int i=k+1;i<=n;i++)
        if(a[i]>a[i-k])
            puts("Yes");
        else
            puts("No");
            
    return 0;
}

Measured memory_bytes: 5184
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
#include<cmath>
#include<algorithm>
#define N 2005
#define MOD 998244353
using namespace std;
int k,n;
int a[N];
int d[N][N];
int dy[N][N];
int main() {
	scanf("%d%d", &k,&n);
	int i, j;
	for (i = 1; i <= k; i++) d[1][i] = 1;
	for (i = 2; i <= n; i++) {
		int sum = 0;
		for (j = 1; j <= k; j++) {
			sum += d[i - 1][j]; sum %= MOD;
			d[i][j] = sum;
		}
	}
	dy[0][0] = 1;
	dy[1][0] = k;
	for (i = 1; i <= k; i++) {
		dy[0][i] = 1; dy[1][i] = k;
	}
	for (i = 2; i <= n; i++) {
		for (j = 1; j <= k; j++) {
			dy[i][0] += d[i][j]; dy[i][0] %= MOD;
		}
		for (int ban = 1; ban <= k; ban++) {
			dy[i][ban] = dy[i][ban - 1] - dy[i - 2][ban - 1];
			if (dy[i][ban] < 0) dy[i][ban] += MOD;
		}
	}
	for (i = 2; i <= k+1 ; i++) {
		printf("%d\n", dy[n][i / 2]);
	}
	for (i = k ; i >= 2; i--) printf("%d\n", dy[n][i / 2]);
	return 0;
}

Measured memory_bytes: 31616
import sys
n, y = map(int,input().split())

for i in range(y // 10000 + 1):
    for j in range((y - 10000 * i) // 5000 + 1):
        if y - 10000 * i - 5000 * j == 1000 * (n - i - j):
            print(i, j, n - i - j)
            sys.exit()
print(-1, -1, -1)


Measured memory_bytes: 2940
/*ex5-4
ryo_1129*/

#include <stdio.h>

int main(void){
    //入力の文字列は10文字以下なので\0を含めて11で定義する
    char str[11],*ptr;
    //ACGT配列の長さと、最長の長さをいれる変数
    int length_counter=0,max_length=0;
    scanf("%s",str);
    ptr = str;
    while(*ptr){
        //ACTGが続く間はlength_counterに部分文字列の長さを記録する
        if(*ptr=='A' || *ptr=='G' || *ptr=='C' || *ptr=='T'){
            length_counter++;
        //ACGT以外の文字が出てきたら、部分文字列が最長か比較しlength_counterをリセットする
        }else{
            if(max_length<length_counter){
                max_length = length_counter;
            }
            length_counter=0;
        }
        ptr++;
    }
    //AGCTのみで文字列が構成されていた場合
    if(max_length<length_counter){
        max_length = length_counter;
    }

    printf("%d\n",max_length);
    return 0;
}

Measured memory_bytes: 1708
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define INF 1e9L
#define EPS 1e-9
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define pb push_back
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;

int main(void)
{
    int a,b,c;
    cin >> a >> b >> c;
    int d;
    cin >> d;
    Yes((abs(a-b)<=d&&abs(b-c)<=d)||abs(a-c)<=d);
}

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


int main(){
	int L,A,B,a,b,reA=0,reB=0;
	cin >>L>>A>>B>>a>>b;
	if(A % a != 0){
		reA++;
		A = A-(A%a);
		reA = reA + A/a;
	}else{
		reA = A/a;
	}
	if(B % b != 0){
		reB++;
		B = B-(B%b);
		reB = reB +B/b;
	}else{
		reB = B/b;
	}
	cout << L -max(reA,reB)<<endl;

		return 0;
}

Measured memory_bytes: 3080
#129A
# 1.値を正しく取得
a, b, c = (int(x) for x in input().split())

# 2.正しく処理
gokei1 = a + b
gokei2 = a + c
gokei3 = b + c

resalt=[gokei1,gokei2,gokei3]

print(min(resalt))

Measured memory_bytes: 9148
#include <stdio.h>

main(){
  int l[10],v1,v2,sum1,sum2;
  double t;
  int i;

  while(1){
    if(scanf("%d,", &l[0])==EOF) break;
    for(i=1;i<10;i++){
      scanf("%d,", &l[i]);
    }
    scanf("%d,%d", &v1, &v2);
    
    sum1=sum2=0;
    for(i=0;i<10;i++){
      sum2+=l[i];
    }
    t=(double)sum2/((double)v1+(double)v2)*(double)v1;
    for(i=0;i<10;i++){
      sum1+=l[i];
      if((double)sum1>=t){
	printf("%d\n", i+1);
	break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

int n;

void calculate(int **M, int **cost, int width);

int main(int argc, char *argv[])
{
  int i, j;
  int **M;
  int **cost;

  scanf("%d", &n);
  M = (int **)malloc(sizeof(int *) * (n + 1));
  for (i = 1; i <= n; i++) M[i] = (int *)malloc(sizeof(int) * 2);
  cost = (int **)malloc(sizeof(int *) * (n + 1));
  for (i = 1; i <= n; i++) cost[i] = (int *)malloc(sizeof(int) * (n + 1));

  for (i = 1; i <= n; i++) {
    for (j = 0; j < 2; j++) scanf("%d", &M[i][j]);
    for (j = 1; j <= n; j++) cost[i][j] = 0;
  }
  
  for (i = 1; i <= n; i++) calculate(M, cost, i);

  printf("%d\n", cost[1][n]);

  return 0;
}

void calculate(int **M, int **cost, int width)
{
  int i, j;
  int cost_min, cost_k;

  if (width == 1) {
    for (i = 1; i <= n - width + 1; i++) cost[i][i+width-1] = 0;
  } else if (width == 2) {
    for (i = 1; i <= n - width + 1; i++)
      cost[i][i+width-1] = M[i][0] * M[i][1] * M[i+width-1][1];
  } else {
    for (i = 1; i <= n - width + 1; i++) {
      cost_min = INT_MAX;
      for (j = i + 1; j <= i + width - 1; j++) {
	cost_k =
	  cost[i][j-1] + cost[j][i+width-1] +
	  M[i][0] * M[j][0] * M[i+width-1][1];
	if (cost_k < cost_min) cost_min = cost_k;
      }
      cost[i][i+width-1] = cost_min;
    }
  }
}

Measured memory_bytes: 640
#pragma GCC optimaze("Ofast")
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()

using namespace std;

const int MSIZE = 16;

int g[MSIZE][MSIZE];
long long Precalc[1 << MSIZE];
vector<int> indexes[1 << MSIZE];
long long dp[1 << MSIZE];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> g[i][j];
        }
    }
    for (int mask = 0; mask < (1 << n); mask++) {
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                if ((mask >> i) & (mask >> j) & 1) {
                    Precalc[mask] += g[i][j];
                }
            }
        }
        for (int i = 0; i < n; i++) {
            if (((mask >> i) & 1) == 0) {
                indexes[mask].push_back(i);
            }
        }
    }

    vector<pair<int,int> > masks(1 << n);
    for (int mask = 0; mask < (1 << n); mask++) {
        masks[mask] = make_pair(__builtin_popcount(mask), mask);
    }
    sort(all(masks));

    for (int i = 0; i < (1 << n); i++) {
        int mask = masks[i].second;
        int sz = indexes[mask].size();
        for (int mask2 = 1; mask2 < (1 << sz); mask2++) {
            int curMask = 0;
            for (int i = 0; i < sz; i++) {
                if ((mask2 >> i) & 1) {
                    curMask |= (1 << indexes[mask][i]);
                }
            }
            dp[mask | curMask] = max(dp[mask] + Precalc[curMask], dp[mask | curMask]);
        }
    }
    cout << dp[(1 << n) - 1] << endl;
}


Measured memory_bytes: 9216