akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;/*10^12*/
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}

////////////////////////////////////////

bool che[26];
int cou;
void init(){
    memset(che,false,sizeof(che));
    cou=0;
}

int main(){
    string s;cin>>s;
    int n=s.size();
    vector<int>v;
    v.pb(n);
    int pos=n-1;
    while(pos>=0){
        if(!che[s[pos]-'a']){
            cou++;
            che[s[pos]-'a']=true;
        }
        if(cou==26){
            init();
            v.pb(pos);
        }
        pos--;
    }
    reverse(v.begin(),v.end());
    string ans;
    
    pos=0;
    for(auto y:v){
        int x=pos;
        init();
        rep(i,x,y-1){
            che[s[i]-'a']=true;
        }
        int t;
        for(t=0;t<=25;t++){
            if(!che[t])break;
        }
        ans+=('a'+t);
        
        while(y<=n-1){
            if(s[y]-'a'==t)break;
            y++;
        }
        pos=y+1;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N, T;
	cin >> N >> T;
	vector<int> c(N), t(N);
	for (int i = 0; i < N; i++) {
		cin >> c.at(i) >> t.at(i);
	}
	int cost = 10000;
	for (int j = 0; j < N; j++) {
		if (t.at(j) <= T) {
			cost = min(cost, c.at(j));
		}
	}
	if (cost == 10000)cout << "TLE" << endl;
	else cout << cost << endl;
}

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

#define boost ios::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define F first
#define S second

int main()
{
    boost;
    if(fopen("inp.txt", "r")) {
      freopen("inp.txt", "r", stdin);
      freopen("outp.txt", "w", stdout);
    }

    string s;
    cin>>s;

    if (s.length()<4)
        cout<<"No\n";
    else {
        if (s[0]=='Y' && s[1]=='A' && s[2]=='K' && s[3]=='I')
            cout<<"Yes\n";
        else
            cout<<"No\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <cmath>
#include <set>
#include <queue>
#include <string>
#include <iostream>
#include <stack>
#include <bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,int> pii;
const ll mod = 1e9+7;
const int inf  = 0x3f3f3f3f;

struct cmp
{
	bool operator()(const pii & a, const pii & b)
	{
		return a.second > b.second;
	}
};

const int maxn = 8005;


int main()
{
	
		string a;
		cin>>a;
		if(a == "ABC")
			cout<<"ARC"<<endl;
		else
			cout<<"ABC"<<endl;
}

Measured memory_bytes: 3104
Q=->{$><<:No;exit};
(R,C),_,*A=$<.map{|l|l.split.map &:to_i};
e={};
A.map{|y,x,a|(e[y-=1]||=[])<<[a,x+=R-1];(e[x]||=[])<<[a,y]};
v=[];
R.times{|z|
c,*d=[],9e9
v[z]||(
q=[[z,0,c,d]];
(
z,b,c,d=q.pop;
c<<b;
v[z]?v[z]==b||Q[]:(v[z]=b;e[z]&.map{|a,w|q<<[w,a-b,d,c]})
)while q[0];
c.min+d.min<0&&Q[]
)
};
$><<:Yes


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

int main() {
  int n;
  cin >> n;
  int a[n];
  int a_max = 0, a_min = 100000000;
  int i;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    a_max = max(a_max, a[i]);
    a_min = min(a_min, a[i]);
  }
  cout << a_max - a_min << endl;
  return 0;
}


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

class Program
{
	public static void Main()
	{
		var n = ReadLine().Split().Select(int.Parse).ToArray();
		if(Max(n[0], n[2]) >= Min(n[1], n[3]))
			WriteLine(0);
		else
			WriteLine(Min(n[1], n[3]) - Max(n[0], n[2]));
	}
}


Measured memory_bytes: 19036
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {
	string str;
	int a[11]={},b=0;
	int total=1000;

	cin>>str;

	rep(i,str.size()){
		if(str[i]=='1'){
			a[i]=1;
		}
		if(str[i]=='2'){
			a[i]=2;
		}
		if(str[i]=='3'){
			a[i]=3;
		}
		if(str[i]=='4'){
			a[i]=4;
		}
		if(str[i]=='5'){
			a[i]=5;
		}
		if(str[i]=='6'){
			a[i]=6;
		}
		if(str[i]=='7'){
			a[i]=7;
		}
		if(str[i]=='8'){
			a[i]=8;
		}
		if(str[i]=='9'){
			a[i]=9;
		}
	}
	rep(i,str.size()-2){
		b=a[i]*100+a[i+1]*10+a[i+2];
		total=min(total,abs(753-b));
	}
	cout<<total<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
using i64 = long long;

std::vector<std::vector<int>> g;
std::vector<int> a, ret, dp;

void dfs(const int v, const int p) {
    ret[v] = dp.size() - 1;
    for (const int to : g[v]) {
        if (to == p) continue;
        const int k = std::lower_bound(dp.begin(), dp.end(), a[to]) - dp.begin();
        if (k == dp.size()) {
            dp.push_back(a[to]);
            dfs(to, v);
            dp.pop_back();
        } else {
            std::swap(a[to], dp[k]);
            dfs(to, v);
            std::swap(a[to], dp[k]);
        }
    }
}

int main() {
    int n;
    std::cin >> n;
    g.resize(n + 1); a.resize(n + 1); ret.resize(n + 1);
    for (int i = 1; i <= n; i++) std::cin >> a[i];
    for (int i = 1; i < n; i++) {
        int u, v;
        std::cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    dp.push_back(0);
    dp.push_back(a[1]);
    dfs(1, 0);

    for (int i = 1; i <= n; i++) std::cout << ret[i] << '\n';

    return 0;
}


Measured memory_bytes: 30156
#include<stdio.h>
#include<stdlib.h>
int partition(int*, int, int);
main() {
  int n,i,j,q,x;
  int *A;

  scanf("%d",&n);
  A = (int*)malloc(sizeof(int)*n);
  for(i = 0; i < n; i++) {
    scanf("%d",&A[i]);
  }

  q = partition(A, 0, n-1);

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

int partition(int* A, int p, int r) {
  int x,i,j,c;
  x = A[r];
  i = p-1;
  for(j = p; j < r; j++) {
    if(A[j] <= x) {
      i = i + 1;

      c = A[i];
      A[i] = A[j];
      A[j] = c;
    }
  }
      c = A[i+1];
      A[i+1] = A[r];
      A[r] = c;
      return i+1;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll mod = 1e9 +7;
const ll MAXN = 2e5 + 5;

set<ll>ss;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;cin>>n;
	bool flag=false;
	for(int i=1;i<=n;i++){
		int x;cin>>x;
		if(ss.find(x)==ss.end()) ss.insert(x);
		else{
			flag=1;
		}
	} 
	cout<<(flag?"NO":"YES");
	return 0;
}


Measured memory_bytes: 9600
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
from functools import partial, reduce
from operator import mul
prod = partial(reduce, mul)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

fibo = [1, 1]
for i in range(2, 9):
    fibo.append(fibo[i - 1] + fibo[i - 2])

def main():
    a, b = LS()
    if a == 'H':
        ans = b
    else:
        if b == 'H':
            ans = 'D'
        else:
            ans = 'H'
    return ans

print(main())

Measured memory_bytes: 3572
#include<stdio.h>
#define SIZE 4
int main()
{
  int a[SIZE],b[SIZE];
  int i,j;
  int hit,blow;
  while(scanf("%d",&a[0])!=EOF)
    {
      for(i=1;i<SIZE;i++) scanf("%d",&a[i]);
      for(i=0;i<SIZE;i++) scanf("%d",&b[i]);
      hit=0;
      blow=0;
      for(i=0;i<SIZE;i++)
	{
	  if(a[i]==b[i]) hit++;
	}
      for(i=0;i<SIZE;i++)
	{
	  for(j=0;j<SIZE;j++)
	    {
	      if(a[i]==b[j]) blow++;
	    }
	}
      blow-=hit;
      printf("%d %d\n",hit,blow);
    }
  return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<string>
#include<regex>
 
int main(void){
  std::string input;
  std::regex re("(hi)+");
  
  std::cin >> input;
  
  if(regex_match(input,re)){
    std::cout << "Yes";
  }
  else{
  	std::cout << "No";
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char* argv[]){
  long int a, b, c;
  scanf("%ld %ld %ld", &a, &b, &c);
  long int ans;
  if(a%2==0 || b%2==0 || c%2==0){
    ans = 0;
  }else{
    if(a>=b && a>=c){
      ans = b * c;
    }else if(b>=a && b>=c){
      ans = a * c;
    }else{
      ans = a * b;
    }
  }
  printf("%ld\n",ans);
  return 0;
}

Measured memory_bytes: 128
n,m,l = map(int,input().split())
a=[list(map(int,list(input().split()))) for i in range(n)]
b=[list(map(int,list(input().split()))) for i in range(m)]

result=[[0]*l for i in range(n)]

for i in range(n):
    for j in range(m):
        for k in range(l):
            result[i][k] += a[i][j]*b[j][k]

for i in result:print(*i, sep=' ')


Measured memory_bytes: 7040
w = input()
dic = {}
for i in range(len(w)):
    dic[w[i]] = w.count(w[i])

a = list(dic.values())
a = [n%2 for n in a]
c = 0
for i in range(len(a)):
    c += a[i]
print("Yes" if c == 0 else "No")


Measured memory_bytes: 3060
#include <stdio.h>

int main() {
  int N,result=0;
  scanf("%d",&N);
  int A[N];
  for(int i=0;i<N;i++) {
    scanf("%d",&A[i]);
  }
  for(int i=0;i<N;i++) {
    if(A[i]%2==0) {
      if(A[i]%3!=0 && A[i]%5!=0) {
	printf("DENIED");
	result++;
	break;
      }
    }
  }
   if(result==0) {
     printf("APPROVED");
   }
   return 0;
}
  

Measured memory_bytes: 1736
#include<stdio.h>
#include<math.h>
typedef long long int lli;
int main() {
    int k,x;
    scanf("%d %d", &k, &x);
    if(k*500>=x){
      printf("Yes\n");
    }
    else{
      printf("No\n");
    }
  return 0;
}



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

public class Main {
    static int k;
    static int[] heights;
    static int[] dp;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //BufferedReader br = new BufferedReader(new FileWriter("frog2.in");
        //StringTokenizer st = new StringTokenizer(br.readLine());
        //PrintWriter pw = new PrintWriter("frog2.out");

        int n = sc.nextInt();
        k = sc.nextInt();

        heights = new int[n+1];
        dp = new int[n+1];
        Arrays.fill(dp, -1);
        for(int x = 1; x<=n; x++){
            heights[x] = sc.nextInt();
        }
        System.out.println(jump(n));
        //System.out.println(Arrays.toString(heights));


    }

    public static int jump(int n){
        if(dp[n] != -1)
            return dp[n];
        if(n == 1)
            return dp[n] = 0;
        int min = Integer.MAX_VALUE;
        for(int x = k; x >= 1; x--){
            if(n - x >= 1){
                min = Math.min(min, jump(n - x) + Math.abs(heights[n] - heights[n - x]));
            }
        }

        return dp[n] = min;
    }
}


Measured memory_bytes: 62816
#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>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];

  vector<P> job(n);
  rep(i, n) job[i] = make_pair(b[i], a[i]);
  sort(job.begin(), job.end());
  ll s = 0;
  bool ok = true;
  rep(i, n) {
    s += job[i].second;
    if (s > job[i].first) ok = false;
  }
  if (ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 6392
#include<iostream>
#include<cstdint>
#include<algorithm>
using namespace std;

int binarySearch(int64_t sum) {
	int ok = 1, ng = 1000000000;
	int64_t mid;
	while (ng - ok > 1) {
		mid = ok + ((ng - ok) >> 1);
		if (mid * mid < sum) ok = mid;
		else ng = mid;
	}
	return ok;
}
int main() {
	int Q, A, B;
	cin >> Q;
	int64_t sum;
	for (int i = 0;i < Q;i ++) {
		cin >> A >> B;
		sum = (int64_t)A * B;
		int64_t n = binarySearch(sum);
		int ans = n << 1;
		if (n * (n + 1) >= sum) ans --;
		if (n >= min(A, B)) ans --;
		cout << ans;
		if (i < Q - 1) cout << endl;
	}
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

まず、10^10^10はバカでかい数なので実質無限人でも変わらない
重要なのは、各クエリに対しA*B以下になるx,yが何通りあるかだけである
ただし、ここで各xに対しyがあるかどうかさえ知れば良い
まず、x=1の時、y=A*B-1まで考えられる
x=2のとき、y=A*B/2-1まで考えられる
また、x<=sqrt(A*B)としておく
これにより、おおよそ2sqrt(A*B)個の答えが持てることが分かる
ただし、n>=min(A, B)なら1個取れないので1引く
また、sqrt(A*B)*(sqrt(A*B)+1)>=A*Bでも1個反対側が無いので1引く
sqrt(A*B)は二分探索で求まる
よってO(Qlog(sqrt(A*B))、あっという間じゃん
*/

Measured memory_bytes: 256
#include <iostream>
using namespace std;
main () {
	int n, b;
	cin>>n;
	int a[8] = {0, 0, 0, 0, 0, 0, 0, 0}, hitung = 0, result = 0;
	while (n--)
	{
		cin>>b;
		if (b >= 1 && b <= 399)
		{
		a[0] = 1;
		} else if (b >= 400 && b <= 799)
		{
		a[1] = 1;
		} else if (b >= 800 && b <= 1199)
		{
			a[2] =1;
		} else if (b >= 1200 && b <= 1599)
		{
			a[3] = 1;
		} else if (b >= 1600 && b <= 1999)
		{
			a[4] = 1;
		} else if (b >= 2000 && b <= 2399)
		{
			a[5] = 1;
		} else if (b >= 2400 && b <= 2799)
		{
			a[6] = 1;
		} else if (b >= 2800 && b <= 3199)
		{
			a[7] = 1;
		}else if (b >= 3200)
		{
			hitung++;
		}
	}
for (int i=0;i<8;i++)
{
	if (a[i] == 1)
	{
		result++;
	}
}
if (result == 0)
{
	result = 1;
	hitung--;
}
		cout<<result<<" "<<result+hitung;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }

const ll mod = 998244353;

int cnt[100005], t[100005];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n; read(n);
	int mx = 0;

	rep(i, 0, n) {
		read(t[i]);
		chmax(mx, t[i]);
		cnt[t[i]]++;
	}

	if (t[0] != 0 || cnt[0] != 1)
		die(0);

	ll ans = 1;

	rep(i, 1, mx + 1) {
		rep(j, 0, cnt[i])
			ans = ans * cnt[i - 1] % mod;
	}

	die(ans);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define popcnt(a) __builtin_popcount(a)
#define FastIO() ios::sync_with_stdio(false), cin.tie(0);
#define IO() freopen("palindrome.in","rw",stdin)
#define error(args...)                       \
{                                            \
    cerr<<"LINE "<<__LINE__;                 \
    string _s = #args;                       \
    replace(_s.begin(), _s.end(), ',', ' '); \
    stringstream _ss(_s);                    \
    istream_iterator<string> _it(_ss);       \
    err(_it, args);                          \
    cerr<<endl;                              \
}
void err(istream_iterator<string> it)
{
} 
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
  cerr<<' '<< *it << " = " << a ;
  err(++it, args...);
} 
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e6+9, M = (1<<31), OO = 0x3f3f3f3f;
int arr[N];
int vis[N];
vector<int> adj[N];
void dfs(int p=1,int sum=arr[1])
{
  if(vis[p]) return ;
  vis[p]=1;
  for(auto ch : adj[p])
  {
    if(!vis[ch])
    {
      arr[ch]+=sum;
      dfs(ch,arr[ch]);
    }
  }
}
int main()
{
  LL n;
  scanf("%lld",&n);
  LL sum = ((n)*(n-1))/2;
  sum += (n%1);
  printf("%lld\n",sum);
  #ifdef _LOCAL_DEFINE
  cerr << (double)clock() * 1.0 / CLOCKS_PER_SEC << endl;
  #endif
  return 0; 
}

Measured memory_bytes: 24960
n, k = map(int, input().split())
from math import ceil

p = 0
uncounted = n

for i in range(18):
    lb = ceil(k * 2 ** -i)
    if lb <= uncounted:
        p += (uncounted - lb + 1) * 2 ** -i
        uncounted = lb - 1
        
print(p / n)


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

int main()
{
	string S,T;
	cin >> S >> T;
	int ans = 0;
	rep(i,S.size())
	{
		if (S[i] != T[i]) ans++;
	}
	cout << ans << endl;
	return 0;
}

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

int main( void )
{
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  int ans = 0;
  
  if( C <= B && B <= D )
    ans = B - C;
  if( C <= A && A <= D )
    ans = D - A;
  if( C <= A && B <= D )
    ans = B - A;
  if( A <= C && D <= B )
    ans = D - C;

  cout << ans << endl;
}

Measured memory_bytes: 3620
#%%
n = int(input())
A = list(map(int, input().split()))

#%%
hai = 0
cha = 0
midori = 0
mizu = 0
ao = 0
ki = 0
dai = 0
aka = 0
above = 0
for a in A:
    if 1 <= a <= 399:
        hai = 1
    elif 400 <= a <= 799:
        cha = 1
    elif 800 <= a <= 1199:
        midori = 1
    elif 1200 <= a <= 1599:
        mizu = 1
    elif 1600 <= a <= 1999:
        ao = 1
    elif 2000 <= a <= 2399:
        ki = 1
    elif 2400 <= a <= 2799:
        dai = 1
    elif 2800 <= a <= 3199:
        aka = 1
    else:
        above += 1

n_rate = 8
total = hai + cha + midori + mizu + ao + ki + dai + aka

if total != 0:
    ans_min = total
else:
    ans_min = 1

ans_max = total+above

print(ans_min, ans_max)

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

int main() {
  int a,b;
  cin>>a>>b;
  if(a>0)cout<<"Positive";
  else{
    if(a==0)cout<<"Zero";
    if(a<0&&b>=0)cout<<"Zero";
    if(a<0&&b<0){
      if((b-a)%2==0)cout<<"Negative";
      else cout<<"Positive";
    }
  }
  cout<<endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>

/*
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };
*/

using namespace std;

bool isPrime(unsigned x)
{
    if (x == 1)
        return false;
    if (x == 2)
        return true;
    if (x % 2 == 0)
        return false;
    for (int i = 3; i <= sqrt(x); i += 2)
    {
        if (x % i == 0)
            return false;
    }
    return true;
}

int main()
{
    int n;
    cin >> n;
    int x;
    int ans = 0;
    while (n--)
    {
        cin >> x;
        if (isPrime(x))
            ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3056
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;

const int N = 100000 + 7;

int n;
int a[N];
int k;

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf("%d", a + i);
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; ++i)
		k += a[i] == a[i - 1];
	k = n - k - (k & 1);
	printf("%d", k);
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n;
  cin >> n;
  vector<ll> l(n);
  REP(i, n) cin >> l[i];

  sort(ALL(l));
  ll ans = 0;
  REP(i, n - 1) FOR(j, i + 1, n) {
    // a<=b<=c, a=l[i], b=l[j]
    // --> c<a+b
    auto it = --lower_bound(ALL(l), l[i] + l[j]);
    ll t = it - (l.begin() + j);
    ans += max(t, 0LL);
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
IDENTIFICATION DIVISION.
       PROGRAM-ID. test1.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 INP PIC X(20).
       01 N PIC 9999999.
       01 Y PIC 99999999.
       01 temp1 PIC 999999999.
       01 S PIC 99999999.
       01 T PIC 99999999.
       01 temp2 PIC 99999999.
       01 temp3 PIC 99999999.
       01 RE1 PIC ZZZZZZZ9.
       01 RE2 PIC ZZZZZZZ9.
       01 RE3 PIC ZZZZZZZ9.
       PROCEDURE DIVISION.
       MAIN.
      	ACCEPT INP.
      	PERFORM VARYING S FROM 1 BY 1 UNTIL INP(S:1)=SPACE
      	END-PERFORM.
      	SUBTRACT 1 FROM S.
      	MOVE INP(1:S) TO N.
      	ADD 2 TO S.
      	PERFORM VARYING temp1 FROM S BY 1 UNTIL INP(temp1:1)=SPACE
      	END-PERFORM.
      	COMPUTE temp1 = temp1 - S.
      	MOVE INP(S:temp1) TO Y.
      	COMPUTE Y = Y / 1000 .
      	PERFORM VARYING S FROM 0 BY 1 UNTIL S > N
      		COMPUTE temp1 = N - S
      		PERFORM VARYING T FROM 0 BY 1 UNTIL T > temp1
      			COMPUTE temp2 = temp1 - T
      			COMPUTE temp3 = S * 10 + T * 5
      			COMPUTE temp3 = temp3 + temp2
      			IF temp3 = Y THEN
      				MOVE S TO RE1
      				MOVE T TO RE2
      				MOVE temp2 TO RE3
      				DISPLAY RE1 " " RE2 " " RE3
      				STOP RUN
      			END-IF
      		END-PERFORM
      	END-PERFORM.
      	DISPLAY "-1 -1 -1".
      	STOP RUN.




Measured memory_bytes: 384
import numpy as np

N = int(input())
testimony = [[0] * N for i in range(N)]
A = []

for i in range(N):
    a = int(input())
    A.append(a)
    for j in range(a):
        x, y = map(int, input().split())
        testimony[i][x-1] = 2 * y - 1

testimony = np.array(testimony)

A = np.array(A)
ans = 0

for i in range(2 ** N):
    honesty = [-1] * N
    h = 0
    for j in range(N):
        if (i >> j) & 1:
            honesty[j] = 1
            h += 1
    honesty = np.array(honesty)
    B = np.dot(testimony,honesty) - A
    if any(honesty[j] == 1 and B[j] != 0 for j in range(N)):
        continue

    ans = max(ans, h)

print(ans)

Measured memory_bytes: 12536
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define lg length()
#define pb push_back
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005

int n,t;

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n >> t;
    cout << n*n-t;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>
#include <utility>
#include <climits>
#include <numeric>
#define ll long long
#define INF INT_MAX 
using namespace std;
int main(){
	int h,w;
	cin >> h >> w;
	char a[h+2][w+2];
	for(int i=0;i<h+2;i++){
		for(int j=0;j<w+2;j++){
			a[i][j] = '#';
		}
	}
	for(int i=1;i<h+1;i++){
		for(int j=1;j<w+1;j++){
			cin >> a[i][j];
		}
	}
	for(int i=0;i<h+2;i++){
		for(int j=0;j<w+2;j++){
			cout << a[i][j];
		}
		cout << endl;
	}
}


Measured memory_bytes: 256
#include<stdio.h>

int a[50];

int fibonacchi(int b){
  if(b == 0 || b == 1)return a[b] = 1;
  if(a[b] != -1)return a[b];
  return a[b] = fibonacchi(b - 1) + fibonacchi(b - 2);
}

int main(){
  int c, i;
  for(i = 0; i < 50; i++)a[i] = -1;

  scanf("%d",&c);
  printf("%d\n",fibonacchi(c));

  return 0;
}



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

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

    long long x, k, d;
    cin >> x >> k >> d;

    x = abs(x);
    long long f = min(k,x/d);
    k -= f;
    x -= f * d;
    if (k % 2 == 0)
        cout << x << endl;
    else
        cout << d - x << endl;
}



Measured memory_bytes: 3640
import sys
readline = sys.stdin.readline

N,M,Q = map(int,readline().split())

train = [[0] * (N + 1) for i in range(N + 1)]

for i in range(M):
  L,R = map(int,readline().split())
  train[L][R] += 1
  
for i in range(N + 1):
  for j in range(1, N + 1):
    train[i][j] += train[i][j - 1]
    
for j in range(N + 1):
  for i in range(1, N + 1):
    train[i][j] += train[i - 1][j]

for i in range(Q):
  p,q = map(int,readline().split())
  print(train[q][q] - train[p - 1][q] - train[q][p - 1] + train[p - 1][p - 1])


Measured memory_bytes: 18672
#include <iostream>
#include <cstring>
using namespace std;
char s[100000000];
int main()
{
	int n, m, i, j, k;
	char a[80], b[80], c;
	bool f = false;
	while (cin >> n && n)
	{
		for (i = 0; i < n; i++)
		{
			cin >> a[i] >> b[i];
		}
		cin >> m;
		strcpy(s, "");
		for (i = k = 0; i < m; i++)
		{
			cin >> c;
			for (j = f = 0; j < n && !f; j++)
			{
				if (c == a[j])
				{
					s[i] = b[j];
					f = true;
				}
			}
			if (!f)
				s[i] = c;
		}
		s[m] = '\0';
		cout << s << endl;
	}
	return 0;
}

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

map<int, int> cnt;

int main()
{

    int n, x;

    scanf("%d", &n);

    int res = 0;

    while(n--){

        scanf("%d", &x);
        cnt[x]++;
    }

    for(map<int, int> ::iterator it = cnt.begin(); it!=cnt.end(); it++){

        int occ = it->second;

        int key = it->first;

        if(occ>key) res += (occ-key);
        else if(occ<key) res += occ;

    }

    cout<<res<<endl;



}


Measured memory_bytes: 4736
/*
 * Author : Sadi
 * Thu 02/07/2020
 * 18:18:56.64
 */
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <cassert>

using namespace std;

#define    watch(x); cout << "\n" <<  #x << " is: " << x << "\n";
#define    all(a) (a).begin(), (a).end()
#define    fi first
#define    se second

template<class A, class B>
ostream& operator << (ostream& output, const pair<A, B>& p) {
    output << "(" << p.first << ", " << p.second << ")";
    return output;
}

template<class A>
ostream& operator << (ostream& output, const vector<A>& a) {
    output << "[";
    for(auto it = a.begin(); it != a.end(); ++it) {
        if(it != a.begin()) {
            output << ", ";
        }
        output << *it;
    }
    output << "]";
    return output;
}

using lld = long long;
using pii = pair<int, int>;
using pll = pair<lld, lld>;

//const int inf = 1e9;
//const int mod = 1e9 + 7;
//const double PI = acos(-1.0);
const int mx = 1e5 + 5;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

    int n;
    cin >> n;
    int arr[mx];
    for(int i = 1; i <= n; ++i) {
        cin >> arr[i];
    }
    map<int, int> even, odd;
    for(int i = 1; i <= n; ++i) {
        if(i & 1) {
            odd[arr[i]]++;
        }
        else {
            even[arr[i]]++;
        }
    }
    int numeven = 0, numodd = 0;
    int maxeven1 = 0, maxeven2 = 0, maxodd1 = 0, maxodd2 = 0;
    for(auto it = even.begin(); it != even.end(); ++it) {
        if(it->se >= maxeven1) {
            numeven = it->fi;
            maxeven2 = maxeven1;
            maxeven1 = it->se;
        }
        else if(it->se > maxeven2) {
            maxeven2 = it->se;
        }
    }
    for(auto it = odd.begin(); it != odd.end(); ++it) {
        if(it->se >= maxodd1) {
            numodd = it->fi;
            maxodd2 = maxodd1;
            maxodd1 = it->se;
        }
        else if(it->se > maxodd2) {
            maxodd2 = it->se;
        }
    }
    if(numeven == numodd) {
        cout << min((n - maxeven1 - maxodd2), (n - maxeven2 - maxodd1)) << endl;
//        if(maxeven1 <= maxodd1) {
//            maxeven1 = maxeven2;
//        }
//        else {
//            maxodd1 = maxodd2;
//        }
    }
    else {
        cout << n - maxeven1 - maxodd1 << endl;
    }

    return 0;
}


Measured memory_bytes: 8536
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cmath>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	int n,sum=0;
	cin>>n;
	vector<int>v(n);
	for(int i=0;i<n;i++){
		cin>>v.at(i);
	}
	sort(v.begin(),v.end(),greater<int>());
	for(int i=1;i<n;i++){
		sum+=v.at(i);
	}
	cout<<v.at(0)/2+sum<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s; cin >> s;
	int ans = 0;
	for (int i = 0; i < s.size(); ) {
		if (s[i] == 'S') {
			++i;
			continue;
		}
		int j = i + 1;
		while (j < s.size() and s[j] == s[i]) ++j;
		ans = max(ans, j - i);
		i = j;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 3600
n=int(input())
a=list(map(int,input().split()))
flag = 1
b=0
while flag:
    flag = 0
    for i in range(n-1,0,-1):
        if a[i]<a[i-1]:
            tmp=a[i-1]
            a[i-1]=a[i]
            a[i]=tmp
            b+=1
            flag=1
a=" ".join(map(str,a))
print(a)
print(b)


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

using namespace std;

int main(){
	int n, i;
	cin >> n >> i;
	int mid = (n % 2 == 0 ? n / 2 : n / 2 + 1);
	if(n % 2 == 0){
		cout << n - i + 1;   
	}
	else{
		if(i == mid)
			cout << i;
		else
			cout << n - i + 1;
	}
    return 0;
}

Measured memory_bytes: 256
N, Q = map(int, input().split())
# print(N, Q)
S = input()
lr_array = [list(map(int, input().split())) for i in range(Q)]
AC_array = []
AC_count = 0

# print(S)
for i, s in enumerate(S):
    if i == 0:
        s_old = s
        continue
    if s_old == "A" and s == "C":
        AC_count += 1
    AC_array.append(AC_count)
    s_old = s

# print(lr_array)
# print(AC_array)
ans = ""
for lr in lr_array:
    print(AC_array[lr[1] - 2] - (AC_array[lr[0] - 2] if lr[0] > 1 else 0))


Measured memory_bytes: 30632
use input::*;
use std::cmp::*;
use std::io::*;
use std::num::*;
use std::str::*;

mod input {
    use super::*;
    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }
    pub fn string() -> String {
        read()
    }
    pub fn int() -> i64 {
        read()
    }
    pub fn char() -> char {
        read::<String>().pop().unwrap()
    }
    pub fn vecchar() -> Vec<char> {
        string().chars().collect()
    }
    pub fn vecint(n: i64) -> Vec<i64> {
        let mut vec = Vec::new();
        for i in 0..n {
            vec.push(int())
        }
        vec
    }
}
fn main() {
    let (h, w) = (int() as usize, int() as usize);
    let mut a = Vec::new();
    for _ in 0..h {
        a.push(vecchar());
    }
    let mut count: Vec<usize> = vec![0; 26];
    for row in a {
        for ch in row {
            count[ch as usize - 'a' as usize] += 1;
        }
    }
    count.sort();
    if h % 2 == 0 && w % 2 == 0 {
        for c in count {
            if c % 4 != 0 {
                println!("No");
                return;
            }
        }
        println!("Yes");
    } else if h % 2 == 0 {
        let mut v = 0;
        for c in count {
            if c % 4 != 0 {
                if c % 2 != 0 {
                    println!("No");
                    return;
                }
                v += 1;
            }
        }
        if v <= h / 2 {
            println!("Yes");
        } else {
            println!("No");
        }
    } else if w % 2 == 0 {
        let mut v = 0;
        for c in count {
            if c % 4 != 0 {
                if c % 2 != 0 {
                    println!("No");
                    return;
                }
                v += 1;
            }
        }
        if v <= w / 2 {
            println!("Yes");
        } else {
            println!("No");
        }
    } else {
        let mut two = 0;
        let mut one = 0;
        for c in count {
            if c % 4 != 0 {
                match c % 4 {
                    1 => {
                        one += 1;
                    }
                    2 => {
                        two += 1;
                    }
                    3 => {
                        one += 1;
                        two += 1;
                    }
                    _ => (),
                }
            }
        }
        if one > 1 || two > (h - 1) / 2 + (w - 1) / 2 {
            println!("No");
        } else {
            println!("Yes");
        }
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;

    int res = N;
    int sle=0, slw=0, sre=0, srw=0;

    for (char c: S) {
        if (c == 'E') sre++;
        else srw++;
    }

    for (char c : S) {
        if (c == 'E') {
            res = min(res, slw+sre-1);
            sle++, sre--;
        }
        else {
            res = min(res, slw+sre);
            slw++, srw--;
        }
    }
    cout << res << endl;

}


Measured memory_bytes: 900
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using ll = long long int;
using ul = unsigned long long int;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    ll a, b;
    cin >> a >> b;
    if (a+b <= 23)
        cout << a + b << endl;
    else
    {
        cout << a+b-24 << endl;
    }

    return 0;
}


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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 100005;

/* ...o(^-^)o... */
int main(){
    ii3(a, b, c);
    bool f = false;
    if((a-b)*(b-c)*(c-a) == 0){
        if(a!=b || b!=c || c!=a) f = true;
    }
    yn(f);
}

Measured memory_bytes: 256
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.List (sort)
import qualified Data.Vector.Unboxed as VU
import Data.Bool (bool)

main :: IO ()
main = do
  n <- unsafeTextToInt <$> T.getLine :: IO Int
  ls <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    ls' = VU.fromList . sort $ls :: VU.Vector Int
    m = VU.length ls' :: Int
    xs = do
      i <- [0..(m - 3)]
      j <- [(i + 1)..(m - 2)]
      k <- [(j + 1)..(m - 1)]
      let
        li = ls' VU.! i
        lj = ls' VU.! j
        lk = ls' VU.! k
      bool [] [()] $ li < lj && lj < lk && ls' VU.! k < ls' VU.! i + ls' VU.! j
  print . length $ xs

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


Measured memory_bytes: 4304
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
typedef pair<int,int> pii; typedef queue<int> qi; typedef vector<pii> vii; typedef long long ll;
#define fi first
#define se second
#define pb push_back
const ll inf = 4485090715960753727;
int N,M,P,vis[2501]; bool inq[2501]; qi q; vii adj[2501]; ll dis[2501];
int main() {
    scanf("%d%d%d",&N,&M,&P);
    for (int i = 0,A,B,C;i < M;i++) scanf("%d%d%d",&A,&B,&C),C-=P,adj[A].pb({B,C});
    memset(dis,-0x3f,sizeof dis); dis[1] = 0; q.push(1); inq[1] = 1;
    while (!q.empty()) {
        int cur = q.front(); q.pop(); inq[cur] = 0; vis[cur]++;
        if (vis[cur] > N<<1) break;
        for (pii nxt : adj[cur]) if (dis[cur]+nxt.se > dis[nxt.fi]) {
            dis[nxt.fi] = dis[cur]+nxt.se;
            if (!inq[nxt.fi]) q.push(nxt.fi),inq[nxt.fi] = 1;
        }
    }
    if (vis[N] >= N || dis[N] == -inf) printf("-1\n");
    else printf("%lld\n",max(0LL,dis[N]));
}


Measured memory_bytes: 384
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <cstring>
using namespace std;
#define mst(a,b) memset((a),(b),sizeof(a))
#define rush() int T;scanf("%d",&T);while(T--)

typedef long long  ll;
const int maxn = 105;
const ll mod = 998244353;
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;

map<int,int>mp;
vector<int>vec;
set<int>s;

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        mp.clear();
        vec.clear();
        for(int i=0;i<n;i++)
        {
            int x;
            scanf("%d",&x);
            vec.push_back(x);
            if(mp[x]==0) mp[x]=x;
            else if(mp[x]) mp[x]=0;
        }
        for(int i=0;i<n;i++)
        {
            //printf("%d %d\n",vec[i],mp[vec[i]]);
            if(mp[vec[i]])
                s.insert(vec[i]);
        }
        printf("%d\n",s.size());
    }
}


Measured memory_bytes: 9976
n,m,k = gets.chomp.split(' ').map(&:to_i)
A = gets.chomp.split.map(&:to_i)
B = gets.chomp.split.map(&:to_i)

sa = [0]
sb = [0]

n.times do |i|
  sa << sa[i] + A[i]
end

m.times do |i|
  sb << sb[i] + B[i]
end
ans = 0
j = m
(n+1).times do |i|
  if sa[i] > k
    break
  end

  while j >= 0
    if sa[i] + sb[j] > k
      j -= 1
    else
      break
    end
  end

  if ans < i+j
    ans = i+j
  end
end

puts ans


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

#define lli long long int

int main()
{
   lli a,b;
   cin>>a>>b;
   if(abs(a-b) >=2)
   {
       cout<<max(a,b) +max(a,b)-1;
   }
   else
    cout<<a+b;


    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const ll MOD = 1e9+7;
const double EPS = 1e-9;


int main(int argc, const char * argv[]) {
  int N; cin >> N;
  vector<ll> A(N+1), B(N);
  for(int i=0; i<=N; i++)
    cin >> A[i];
  for(int i=0; i<N; i++)
    cin >> B[i];
  
  ll Ar, Br, ans, kill1, kill2;
  ans = 0;
  Ar = A[0];
  for(int i=0; i<N; i++){
    kill1 = min(Ar, B[i]);
    Br = max(0LL, B[i] - kill1);
    kill2 = min(A[i+1], Br);
    Ar = max(0LL, A[i+1] - kill2);
    ans += kill1 + kill2;
  }
  cout << ans << endl;
  return 0;
}


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

ll mincost(ll arr[],ll n)
    {
        if(n==2)
            return abs(arr[2]-arr[1]);
        else
            {
                ll dp[n+1];
                dp[1]=0;
                dp[2]=abs(arr[2]-arr[1]);
                
                for(ll i=3;i<=n;i++)
                {
                    dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
                }
                
                return dp[n];
            }    
        
    }


int main() {
	ll n;
	cin>>n;
	ll arr[n+1];
	for(ll i=1;i<=n;i++)
	    cin>>arr[i];
    cout<<mincost(arr,n);
	return 0;
}

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

using namespace std;

#define fo(i,CApiTaL_N) for(int i=0; i<CApiTaL_N; i++)
#define Fo(i,k,CApiTaL_N) for(int i=k; i<CApiTaL_N; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define tr(it, a) for(auto it=a.begin(); it!=a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;

int t=1;
const int mxN=1e3, mod=1e9+7;
int h,w;
vector<vector<char>>grid(mxN+1,vector<char>(mxN+1));
vvl dp(mxN+1,vl(mxN+1));

void test_case(){
    cin>>h>>w;
    fo(i,h){
        fo(j,w){
            cin>>grid[i+1][j+1];
        }
    }
    dp[0][1]=1;
    Fo(i,1,h+1){
        Fo(j,1,w+1){
            if(grid[i][j]=='#')continue;
            dp[i][j]=(dp[i][j]+dp[i-1][j])%mod;
            dp[i][j]=(dp[i][j]+dp[i][j-1])%mod;
        }
    }
    cout<<dp[h][w]<<endl;
}

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

    // cin>>t;
    while(t--){
        test_case();
    }
    
    return 0;
}

Measured memory_bytes: 12560
#include<iostream>
#include <algorithm>
#include<string>
#include <numeric>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;

int main(void) {
    int a,b;
    cin>>a>>b;
    if(a+b<24)cout<<a+b<<endl;
    else cout<<(a+b)-24<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int ans[500005],cf[500005],l[500005],r[500005];
const int bl=530;
int main(int argc, char** argv) {
	int n,m,t;
	ios::sync_with_stdio(false);
	cin >> n >> m;
	t=m/bl;
	for(int i=1;i<=n;i++)
		cin >> l[i] >> r[i];
	for(int i=1;i<=n;i++)
	{
		int lst=t;
		for(int j=bl;j>=1;j--)
		{
			int L=(l[i]-1)/j+1,R=r[i]/j;
			L=max(L,lst+1);
			if(R<L) continue;
			++cf[L],--cf[R+1];
			lst=max(lst,R);
		}
	}
	for(int i=1;i<=t;i++)
	{
		int ans=0;
		for(int j=1;j<=n;j++)
			ans+=(l[j]-1)/i!=r[j]/i;
		cout << ans << "\n";
	}
	for(int i=t+1;i<=m;i++)
	{
		cf[i]+=cf[i-1];
		cout << cf[i] << "\n";
	}
	return 0;
}
//dlstxdy

Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

// retun n の約数の集合 O(sqrt(n))
vector<ll> yakusuu(ll n){
      vector<ll> y;
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0) y.push_back(i);
    }
      ll len = y.size();
      REP(i, len){
        if(y[i] == n / y[i]) continue;
        y.push_back(n / y[i]);
    }
    return y;
}

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

    ll n, k;
    cin >> n >> k;

    vll a(n);
    ll s = 0;
    REP(i, n){
        cin >> a[i];
        s += a[i];
    }
    vll y = yakusuu(s);
    VSORTR(y);
    // s_x <= k -> x を公約数にできる
    ll len = y.size();
    ll res = 1;
    REP(i, len) {
        vll mi;
        ll ms = 0, ps = 0;
        REP(j, n){
            // + と - が等しくなる必要がある
            // そのような操作は必ず実現できる
            if (a[j] % y[i] == 0) continue;
            ll mmm = a[j] % y[i];
            mi.push_back(mmm);
            ms += mmm;
        }
        VSORTR(mi);
        REP(j, n){
            if (ms == ps) break;
            ms -= mi[j];
            ps += (y[i] - mi[j]);
        }
        ll cnt = ms;
        if (cnt <= k) {
            res = y[i];
            break;
        }
    }
    cout << res << endl;
    return 0;
}

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

int main(){
	int a,p;
  	cin >> a >> p;
  
  if(a % 2 == 0){
    cout << a + a/2 + p/2 << endl;
  }else{
   p++;
    cout << a+a/2 + p/2 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
_ = gets
nt,nx,ny = 0,0,0
ans = "Yes"
readlines.each do |s|
  t,x,y = s.split.map(&:to_i)
  d = (x - nx).abs + (y - ny).abs
  if d.odd? == (t - nt).odd? && d <= t - nt
    nt,nx,ny = t,x,y
  else
    ans = "No"
    break
  end
end
puts ans

Measured memory_bytes: 10108
require 'prime'
memo = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]
n = gets.to_i
nums = []
n.times do
  # 小数点の前、後ろで分ける
  former, latter = gets.chomp.split('.')
  latter = '' unless latter
  latter_size = latter.size
  # 分数で表した時、分母に含まれる 10 の数
  bunbo_10 = latter_size
  bunshi = former.to_i * memo[latter_size] + latter.to_i
  # 分子に含まれる 2 の数
  bunshi_2 = 0
  copy = bunshi
  loop do
    div, mod = copy.divmod(2)
    if mod > 0
      break
    else
      bunshi_2 += 1
    end
    copy = div
  end
  bunshi_5 = 0
  copy = bunshi
  loop do
    div, mod = copy.divmod(5)
    if mod > 0
      break
    else
      bunshi_5 += 1
    end
    copy = div
  end
  min = bunshi_2
  min = bunshi_5 if min > bunshi_5
  bunshi_2 -= min
  bunshi_5 -= min
  bunbo_10 -= min
  # [分母に含まれる 10 の数、分子に含まれる 2 の数, 分子に含まれる 5 の数]
  # 7.5 は [1, 0, 2] となる
  nums << [bunbo_10, bunshi_2, bunshi_5]
end

# 分子に 2 を含む数字を bunbo_10 ごとにメモ
# bunbo_10[-4, -3, ....... 8, 9]
# bunshi_2[0, 1, 2 .... 43, 44] の累積和とする（右から）
memo_inc_2 = Array.new(14) { Array.new(45, 0) }

# 分子に 5 を含む数字を bunbo_10 ごとにメモ
# bunbo_10[-4, -3, ....... 8, 9]
# bunshi_5[0, 1, 2 .... 43, 44] の累積和とする（右から）
memo_inc_5 = Array.new(14) { Array.new(45, 0) }

# どちらも含まない数字のメモ
# bunbo_10[-4, -3, ... 8, 9] の累積和とする（左から）
memo_inc_0 = Array.new(14, 0)

nums.each do |bunbo_10, bunshi_2, bunshi_5|
  if bunshi_2 > 0
    memo_inc_2[bunbo_10 + 4][bunshi_2] += 1
  elsif bunshi_5 > 0
    memo_inc_5[bunbo_10 + 4][bunshi_5] += 1
  else
    memo_inc_0[bunbo_10 + 4] += 1
  end
end

# 累積和を算出
14.times do |row|
  43.downto(0) do |i|
    memo_inc_2[row][i] += memo_inc_2[row][i + 1]
    memo_inc_5[row][i] += memo_inc_5[row][i + 1]
  end
end
1.upto(13) do |i|
  memo_inc_0[i] += memo_inc_0[i - 1]
end

ans = 0

nums.each do |bunbo_10, bunshi_2, bunshi_5|
  memo_inc_2.each_with_index do |row, index|
    # 自身の bunbo_10 と相手の bunbo_10 を足した分だけ 2 * 5 を作る必要がある
    requirement = bunbo_10 + index - 4
    requirement = 0 if requirement < 0
    # bunshi_5 が requirement 以上であれば、bunshi_2 が requirement 以上の数を足す
    if bunshi_5 >= requirement
      ans += row[requirement]
    end
  end

  memo_inc_5.each_with_index do |row, index|
    requirement = bunbo_10 + index - 4
    requirement = 0 if requirement < 0
    if bunshi_2 >= requirement
      ans += row[requirement]
    end
  end

  ans += memo_inc_0[4 - bunbo_10] if 4 - bunbo_10 >= 0

  # 自身の bunbo_10 が 0 以下の場合、自身との組み合わせもカウントしているので -1
  ans -= 1 if bunbo_10 <= 0
end

puts ans / 2


Measured memory_bytes: 29596
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC134C
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] A = new int[N];
            int max = 0;
            int maxi = -1;
            for(int i = 0; i < N; i++)
            {
                A[i] = int.Parse(Console.ReadLine());
                if (A[i] > max)
                {
                    max = A[i];
                    maxi = i;
                }
            }
            Array.Sort(A);
            int second = A[N - 2];
            for(int i = 0; i < N; i++)
            {
                if (i == maxi) Console.WriteLine(second);
                else Console.WriteLine(max);
            }

        }
    }
}


Measured memory_bytes: 43840