akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    string s;
    cin >> s;
    int cnt = 0;
    rep(i, s.size() - 1)
    {
        if (s[i] != s[i + 1])
            cnt++;
    }
    cout << cnt << endl;
}

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

const int MOD = 2019;

int pow(int x, int n)
{
    if (n == 0)
    {
        return 1;
    }
    if (n == 1)
    {
        return x % MOD;
    }
    if (n & 1)
    {
        int tmp = pow(x, (n - 1) / 2);
        return tmp * tmp % MOD * x % MOD;
    }
    else
    {
        int tmp = pow(x, n / 2);
        return tmp * tmp % MOD;
    }
}

int main()
{
    string s;
    cin >> s;

    int n = s.size();
    vector<int> t(n + 1, 0);
    for (int i = n - 1; i >= 0; i--)
    {
        t.at(i) = (t.at(i + 1) + pow(10, n - 1 - i) * (s.at(i) - '0') % MOD) % MOD;
    }

    vector<int> m(2019);
    for (int i = 0; i < n + 1; i++)
    {
        m.at(t.at(i)) += 1;
    }
    int res = 0;
    for (int i = 0; i < 2019; i++)
    {
        int mi = m.at(i);
        res += mi * (mi - 1) / 2;
    }
    cout << res << endl;
}

Measured memory_bytes: 4444
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
typedef long long int ld;
typedef unsigned long long int lu;
typedef vector< int > vi;
typedef vector < ld > vd;
typedef set <ld> sd;
typedef vector< vi > vvi;
typedef vector< vd > vvd;
typedef pair< int,int > ii;
typedef pair< ld,ld > id;
#define sz(a) ld((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())

#define rep(i,a,b) for(i=a;i<b;i++)
#define REP(i,a,b) for(i=a;i<=b;i++)
#define reprev(i,a,b) for(i=a;i>=b;i--)


#define Vi vector
#define pr pair
#define isnum(a) (a>=48 && a<=57)
#define isS(a) (a>='a' && a<='z')
#define isU(a) (a>='A' && a<='Z')
#define toS(a) (isU(a)?a+32:a)
#define toU(a) (isS(a)?a-32:a)
#define toC(a) a&15

vector<char> prime (10000000+1, true);
void sieve(ld n)
{	
	//O(nloglogn) time
	prime[0] = prime[1] = false;
	for (ld i=2; i<=n; ++i)
		if (prime[i])
			if (i * 1ll * i <= n)
				for (ld j=i*i; j<=n; j+=i)
					prime[j] = false;
}


vd v1;
vector <bool> visit;
vvd g;
vvd g1;
vd ar;
vvd final;
//ld mind = 1000000006;
vd mind;
ld c;

//for topological sort of a graph
void dfs(ld i,ld n)
{
	visit[i] = true;
	ld j,k;
	for(j=0;j<g[i].size();j++)
	{
		if(!visit[g[i][j]])
		{
			dfs(g[i][j],n);
		}
	}
	v1.pb(i);
}
//next step
//from transposed graph g1,get strongly connected components
void dfs1(ld i,ld n,ld len)
{
	visit[i] = true;
	ld j,k;
	final[len].pb(i);
	mind[len] = min(mind[len],ar[i]);
	rep(j,0,g1[i].size())
	{
		if(!visit[g1[i][j]])
		{
			dfs1(g1[i][j],n,len);
		}
	}
}

int main(){
	ld n,i,j,k;
	cin >> n;
	ld ar[n][3];
	rep(i,0,n)
	{
		rep(j,0,3)
		{
			cin >> ar[i][j];
		}
	}
	ld maxs = 0;
	ld dp[n][3] = {0};
	dp[0][0]=ar[0][0];
	dp[0][1]=ar[0][1];
	dp[0][2]=ar[0][2]; 
	rep(i,1,n)
	{
		rep(j,0,3)
		{
			dp[i][j] = max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3]) + ar[i][j];
		}
	}
	cout << max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2])) << endl;
}	

Measured memory_bytes: 14720
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
#define INF (1 << 29)
using namespace std;

int main(){
    string s;
    int k;
    cin >> s >> k;
    rep(i,s.size()){
        if(s[i] == 'a') continue;
        int c = abs(s[i] - 'a' - 26);
        if(c <= k){
            s[i] = 'a';
            k-=c;
        }
    }
    if(k > 0){
        //while(k > 26) k-=25;
        s[s.size() - 1] += k % 26;
    }
    cout << s << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=b-1; (ll)(a)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};


int main(){
    ll n;   cin >> n;
    ll res=0, bef=0;
    rep(i, n){
        ll x;   cin >> x;
        if(x<bef) res += bef-x;
        bef = max(bef, x);
    }
    cout << res << endl;
}


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

int main () {
    string str;
    cin >> str;

    vector<int> s(256,0);
    for (int i = 0; i < str.size(); i++) {
        s[str[i]]++;
    }

    int res = 0;
    bool fg = true;
    while (fg) {
        fg = false;
        int count = 0;
        for (int i = '0'; i <= '9'; i++) {
            if (s[i] > 0) count++;
            else {
                if (count > 3) {
                    for (int j = 1; j <= count; j++) {
                        s[i - j]--;
                    }
                    fg = true;
                    res += 3;
                }
                count = 0;
            }
        }
        if (count > 3) {
            for (int j = 1; j <= count; j++) {
                s['9' - j + 1]--;
            }
            fg = true;
            res += 3;
        }

        count = 0;
        for (int i = 'a'; i <= 'z'; i++) {
            if (s[i] > 0) count++;
            else {
                if (count > 3) {
                    for (int j = 1; j <= count; j++) {
                        s[i - j]--;
                    }
                    fg = true;
                    res += 3;
                }
                count = 0;
            }
        }
        if (count > 3) {
            for (int j = 1; j <= count; j++) {
                s['z' - j + 1]--;
            }
            fg = true;
            res += 3;
        }
    }

    for (int i = 0; i < 256; i++) {
        if (s[i] > 0) res += s[i];
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 1192
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

ll leap(ll n, ll sz) {
	ll cln = n / sz;
	ll pre = cln * (cln + 1) / 2;
	return pre * sz;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	ll n;
	cin >> n;
	cout << leap(n, 1) - leap(n, 3) - leap(n, 5) + leap(n, 15) << '\n';
}


Measured memory_bytes: 3624
function main(input) {
  const X = BigInt(input)
  let y = 0
  for(let i = 100; i < X;) {
    i = Math.floor(i * 1.01)
    y++
  }
  console.log(y)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 29608
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[10001];
int main(){
    int n,m;
    int sum = 0;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        scanf("%d",&a[i]);
        sum += a[i];
    }
    if(sum>n){
        printf("-1\n");
    }
    else if(sum==n){
        printf("0\n");
    }else{
        printf("%d\n",n-sum);
    }
    return 0;
}


Measured memory_bytes: 1704
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
ll n,t,x,y,m,q,k;
ll dp[3001][3001][4];
int main(){
      ios_base::sync_with_stdio(false); cin.tie(NULL);
      cin>>n>>m>>k;
      memset(dp,0,sizeof(dp));
      for(int i=0;i<k;i++){
        cin>>x>>y>>q;
        dp[x][y][1]=q;
      }
      for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
          ll tmp=max(dp[i-1][j][0],max(dp[i-1][j][1],max(dp[i-1][j][2],dp[i-1][j][3])));
          dp[i][j][3]=max(dp[i][j-1][3],dp[i][j-1][2]+dp[i][j][1]);
          dp[i][j][2]=max(dp[i][j-1][2],dp[i][j-1][1]+dp[i][j][1]);
          dp[i][j][1]=max(tmp+dp[i][j][1],max(dp[i][j-1][1],dp[i][j-1][0]+dp[i][j][1]));
          dp[i][j][0]=max(tmp,dp[i][j-1][0]);
        }
      }
      cout<<max(dp[n][m][0],max(dp[n][m][1],max(dp[n][m][2],dp[n][m][3])));
}

Measured memory_bytes: 285068
#include <bits/stdc++.h>
using namespace std;
int pos(int t){
    if(t<0) return -t;
    return t;
}
int main(){
cin.tie(NULL);
cout.tie(NULL);
ios_base::sync_with_stdio(false);
int n,k; cin>>n>>k;
vector<int> a(n+1),dp(n+1,INT_MAX);
for(int i=0;i<n;i++)cin>>a[i];
dp[0]=0;
for(int i=0;i<n;i++){
    for(int j=i+1;j<=i+k&&j<n;j++){
        dp[j]=min(dp[j],pos(a[i]-a[j])+dp[i]);
    }
}
cout<<dp[n-1]<<'\n';
return 0;
}



Measured memory_bytes: 3956
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#define scanf(...) scanf(__VA_ARGS__)+1
using namespace std;

int main(){
	char b;

	scanf("%c", &b);

	if (b == 'A') {
		printf("T");
	} else if (b == 'T') {
		printf("A");
	} else if (b == 'G') {
		printf("C");
	} else if (b == 'C') {
		printf("G");
	}

	return 0;
}


Measured memory_bytes: 128
#!/usr/bin/env python

from collections import deque
import itertools as ite
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N = input()
A = map(int, raw_input().split())
x1 = 0
for i in range(N):
    if i % 2 == 0:
        x1 += A[i]
    else:
        x1 -= A[i]
X = [x1]
for i in range(N - 1):
    X += [2 * A[i] - X[i]]
print " ".join(map(str, X))

Measured memory_bytes: 47912
program five_transportations
    implicit none
    integer(8):: n,a,b,c,d,e

    read*, n
    read*, a
    read*, b
    read*, c
    read*, d
    read*, e

    print*, ceiling(dble(n)/dble(minval([a,b,c,d,e])),kind=8) + 4
end program five_transportations

Measured memory_bytes: 384
#ifdef DEBUG
#include "redirect.h"
#endif

#include<bits/stdc++.h>
#define N 1000
using namespace std;

int f[N][N],g[N][N],n;

int upd(int i,int j) {
    int tmp=f[i][j];
    if (i==0 || i==n+1 || j==0 || j==n+1) return 0;
    f[i][j]=min(f[i][j],f[i-1][j]+g[i-1][j]);
    f[i][j]=min(f[i][j],f[i+1][j]+g[i+1][j]);
    f[i][j]=min(f[i][j],f[i][j-1]+g[i][j-1]);
    f[i][j]=min(f[i][j],f[i][j+1]+g[i][j+1]);
    if (f[i][j]<tmp) return 1; else return 0;
}

void dfs(int i,int j) {
    if (upd(i-1,j)) dfs(i-1,j);
    if (upd(i+1,j)) dfs(i+1,j);
    if (upd(i,j-1)) dfs(i,j-1);
    if (upd(i,j+1)) dfs(i,j+1);
}

int main(int argc, char *argv[]) {
#ifdef DEBUG
    init(argc, argv);
#endif
    register int i,j,k,p,ans=0;
    scanf("%d",&n);
    for (i=1;i<=n;i++)
    for (j=1;j<=n;j++) f[i][j]=N,g[i][j]=1;
    for (k=1;k<=n;k++) {
        for (i=1;i<=n;i++)
        for (j=1;j<=n;j++) upd(i,j);
    }

    for (k=1;k<=n*n;k++) {
        scanf("%d",&p); p--;
        i=p/n+1; j=p %n+1;
        ans+=f[i][j];
        g[i][j]=0;
        dfs(i,j);
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 18904
from sys import stdin
from itertools import combinations

s = stdin.readline().rstrip()

li = ["A","T","C","G"]

count = 0
saikou = 0

for i in s:
    if i in li:
        count += 1
        saikou = max(saikou,count)
    else:
        count = 0
        
print(saikou)

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

#define endl "\n"

int main(){
    //enable fast I/O
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int x,y;
    cin >> x >> y;

    int a=0, b = x;

    bool result = false;

    while(a<=x){
        if(a*2 + b*4 == y){
            result = true;
            break;
        }
        a++;
        b--;
    }

    if(result){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>
using namespace std;
 
long long mod = 1000000007;
const long long N=2e5+10;

long long a[N];

long long sum=0;
int main() {
    
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    sum %= mod;
    
    long long ans=0;
    
    for(int i=1;i<=n;i++){
        sum-=a[i];
        if(sum<0)sum+=mod;
        ans+=(a[i] * sum);
        ans%=mod;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 5108
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>
#include<map>

using ll = long long;

using namespace std;

long long x = 1000000007;

ll n_pow(ll a, ll n) {
	if (n == 0)return 1;
	ll t = n_pow(a, n / 2);
	t *= t;
	t %= x;
	if (n % 2 == 1)t *= a;
	return t % x;
}

int main() {
	int n;
	ll k;
	cin >> n >> k;
	vector<ll>a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	ll l = -1000000000000000000, r = 1000000000000000000;
	while (l + 1 < r) {
		ll x = (l + r) / 2;
		bool ok = [&] {
			ll tot = 0;
			for (int i = 0; i < n; i++) {
				if (a[i] < 0) {
					int l = -1, r = n;
					while (l + 1 < r) {
						int c = (l + r) / 2;
						if (a[c] * a[i] < x) r = c; else l = c;
					}
					tot += n - r;
				}
				else {
					int l = -1, r = n;
					while (l + 1 < r) {
						int c = (l + r) / 2;
						if (a[c] * a[i] < x) l = c; else r = c;
					}
					tot += r;
				}
				if (a[i] * a[i] < x) tot--;
			}
			tot /= 2;
			return tot < k;
		}();
		if (ok) l = x; else r = x;
	}
	cout << l << endl;
	return 0;
}


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

int main (){

 int A, B, C, X;
  cin >> A >> B >> C >> X;
  int count =0;
  for(int i=0; i<(A+1); i++){
  	 for(int j=0; j<(B+1); j++){
  	 	for(int k=0; k<(C+1); k++){
  			if(500*i + 100*j + 50*k == X){
            	count++;
            }
  		}
  	}
  }
  cout << count << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		if (n == 1) {
			System.out.println("Hello World");
		} else {
			int A = sc.nextInt();
			int B = sc.nextInt();
			System.out.println(A+B);
		}
	}

	static class FastReader { 
      BufferedReader br; 
      StringTokenizer st; 
  
      public FastReader() { 
        br = new BufferedReader(new InputStreamReader(System.in)); 
      } 

      String next() { 
        while (st == null || !st.hasMoreElements()) { 
          try { 
            st = new StringTokenizer(br.readLine()); 
          } catch (IOException  e) { 
            e.printStackTrace(); 
          } 
       } 
       return st.nextToken(); 
      } 
  
      int nextInt() { 
        return Integer.parseInt(next()); 
      } 
 
      long nextLong() { 
        return Long.parseLong(next()); 
      } 
  
      double nextDouble() { 
        return Double.parseDouble(next()); 
      } 
  
      String nextLine() { 
        String str = ""; 
        try{ 
          str = br.readLine(); 
        } catch (IOException e) { 
          e.printStackTrace(); 
        } 
        return str; 
      } 
    } 
}


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

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

#define rep(i,N) for(int i=0; i < (int)N; i++)
#define all(v) (v).begin(),(v).end()
#define chmax(x,y) x = max(x,y)

const int INF = 1001001001;

int main(){
	int n; cin>> n;
	vector<vector<vector<int>>> d(n, vector<vi>(2));
	rep(i,n){
		int a; cin >> a;
		rep(j,a){
			int x, y; cin >> x >> y;
			x--;
			d[i][y].push_back(x);
		}
	}
	int ans = 0;
	for(unsigned int b=0; b < (1<<n); b++){
		vector<int> j(n, 0);
		bool ok = true;
		int cnt = 0;
		// cout << bitset<15> (b) <<endl;
		rep(i,n){
			if(b & (1<<i)){
				cnt ++;
				for(auto x : d[i][0]){
					if(j[x]!=1) j[x] = -1;
					else ok = false;

					if(b & (1<<x)) ok =false;
				}
				for(auto x : d[i][1]){
					if(j[x]!=-1) j[x] = 1;
					else ok = false;

					if(!(b & (1<<x))) ok =false; 
				}
			}
			
			// cout << i << " " << ok << endl;
		}
		if(ok) chmax(ans, cnt);
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll x;
	cin >> x;
	ll res = x / 11 * 2;
	x %= 11;
	if (x > 6) res += 2;
	else if (x != 0) res++;
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include <cmath>
#include <math.h>

using namespace std;
const long long INF = (long long) (1e18)+1;

int main() {
  int l, r, d;
  cin >> l >> r >> d;
  if (l%d == 0) {
    cout << (r/d - l/d)+1 << endl;
  } else {
    cout << (r/d - l/d) << endl;
  }

  return 0;
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int n;
string s;
i64 a,b,c;
void solve(){
	cin >> n >> s;
	for(int i = 0; i < n; i++){
		if(s[i] == 'R') a++;
		if(s[i] == 'G') b++;
		if(s[i] == 'B') c++;
	}
	i64 ans = a*b*c;
	for(int i = 0; i < n; i++){
		for(int j = 1; i+j*2 < n; j++){
			set<char> st;
			st.insert(s[i]);
			st.insert(s[i+j]);
			st.insert(s[i+j*2]);
			if(st.size() == 3) ans--;
		}
	}
	cout << ans << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


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

int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	string s;
	cin>>s;
	int cnt=0;
	for(int i=1;i<s.size();i++){
		if(s[i]!=s[i-1])cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 512
#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 REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
#define MAX_N 200002
using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
typedef pair<int,ll> Pil;
typedef pair<ll,ll> Pll;

const int inf=1000000000;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int f[MAX_N]={};
int b[MAX_N]={};

int main() {
    int n,m;
    vector<ll> a;
    cin>>n>>m;
    ll a1;
    rep(i,n){
        cin>>a1;
        a.push_back(a1);
    }
    sort(a.begin(),a.end());
    vector<Pll> b;
    rep(i,m){
        ll b1,b2;
        cin>>b1>>b2;
        b.push_back(Pll(b2,b1));
    }
    int lnum=0;
    sort(b.begin(),b.end());
    rep(i,m){
        if(lnum>=n)break;
        ll b1=b[m-i-1].first;
        ll b2=b[m-i-1].second;
        for(ll j=0;j<b2;j++){
            if(a[lnum]<b1){
                a[lnum]=b1;
                lnum++;
            }else{
                break;
            }
            if(lnum>=n)break;
        }
    }
    ll r=0;
    rep(i,n)r+=a[i];
    cout<<r<<endl;
    
	return 0;
}


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

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

int main() {
int a,b;
  cin >> a >>b;

  int ans = max({a + b, a - b, a * b});
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>

using namespace std;
#define int long  long int
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main()
{
	string S, T;
	cin >> S >> T;
	cout << T << S;
}


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

int main() {
  string s,t;
  cin>>s>>t;
  int n=s.length();
  map<char,char> v,w;
  for (size_t i = 0; i < n; i++) {
//    if(s[i]<t[i])swap(s[i],t[i]);
//    cout<<s[i]<<t[i]<<endl;
    if(v.find(s[i])==v.end()&&w.find(t[i])==w.end()){
      v.insert(make_pair(s[i],t[i]));
      w.insert(make_pair(t[i],s[i]));
    }else if(v[s[i]]!=t[i]||w[t[i]]!=s[i]){
      cout<<"No";
      return 0;
    }
  }
  cout<<"Yes";
}


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

int main() {
    int n,a;
    cin>>n>>a;
    
    if(a>=n%500)cout<<"Yes";
    else cout<<"No";
    
    return 0;
    }
    


Measured memory_bytes: 3572
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <utility>
#include <set>
#include <unordered_map>

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define IPSILON 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0; i<N;i++){
    cin >> A[i];
  }
  vector<size_t> indices(A.size());
  iota(indices.begin(), indices.end(),0);
  std::sort(indices.begin(), indices.end(), [&A](size_t i1, size_t i2) {
        return A[i1] < A[i2];
    });
  for(auto e: indices){
    cout << e+1 << endl;
  }
  return 0;
}


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

int main(){
	int N; cin >> N;
	for(int i=1; i<=N; i++){
		double x = (double)i * 1.08;
		if((int)x == N){
			cout << i << endl;
			return 0;
		}
	}
	cout << ":(" << endl;
	return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/arc084/tasks/arc084_c
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn gen(i: usize, n: usize, k: usize, history: Vec<usize>, all: &mut Vec<Vec<usize>>) {
    if history.len() >= 1 {
        all.push(history.clone());
    }
    if i == n {
        return;
    }
    for x in 1..k+1 {
        let mut th = history.clone();
        th.push(x);
        gen(i+1, n, k, th, all);
    }
}

fn rollback(a: &mut Vec<usize>, k: usize, n: usize) {
    let last = a.len()-1;
    if a[last] == 1 {
        a.pop();
    } else {
        a[last] -= 1;
        while a.len() < n {
            a.push(k);
        }
    }
}

fn main() {
    input! {
        k: usize, n: usize
    };

    let mut ans = vec![];
    if k % 2 == 0 {
        ans.push(k/2);
        for i in 1..n {
            ans.push(k);
        }
    } else {
        for i in 0..n {
            ans.push((k+1)/2);
        }
        let back = n/2;
        for i in 0..back {
            rollback(&mut ans, k, n);
        }
    }

    // let mut a = vec![];
    // gen(0, n, k, vec![], &mut a);
    // a.sort();

    // let len = a.len();
    // debug!(len, a[(len+1)/2-1]);
    // assert_eq!(ans, a[(len+1)/2-1]);

    let line = ans.iter().map(|x| x.to_string()).collect::<Vec<_>>().join(" ");
    println!("{}", line);
}


Measured memory_bytes: 22772
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int map[2001][2001];
int rui[2001][2001], rx[2001][2001], ry[2001][2001];
int main()
{
	int mx, my, query;
	scanf("%d%d%d", &mx, &my, &query);
	for (int i = 0; i < mx; i++)for (int j = 0; j < my; j++)scanf(" %c", &map[i][j]), map[i][j] -= '0';
	for (int i = 0; i < mx; i++)for (int j = 0; j < my; j++)rui[i + 1][j + 1] = rui[i + 1][j] + rui[i][j + 1] - rui[i][j] + map[i][j];
	for (int i = 0; i < mx; i++)for (int j = 0; j < my - 1; j++)rx[i + 1][j + 1] = rx[i + 1][j] + rx[i][j + 1] - rx[i][j] + (map[i][j] && map[i][j + 1]);
	for (int i = 0; i < mx - 1; i++)for (int j = 0; j < my; j++)ry[i + 1][j + 1] = ry[i + 1][j] + ry[i][j + 1] - ry[i][j] + (map[i][j] && map[i + 1][j]);
	for (int i = 0; i < query; i++)
	{
		int lx, ly, ux, uy;
		scanf("%d%d%d%d", &lx, &ly, &ux, &uy);
		lx--, ly--, ux--, uy--;
		int a = rui[ux + 1][uy + 1] - rui[ux + 1][ly] - rui[lx][uy + 1] + rui[lx][ly];
		int b = rx[ux + 1][uy] - rx[ux + 1][ly] - rx[lx][uy] + rx[lx][ly];
		int c = ry[ux][uy + 1] - ry[ux][ly] - ry[lx][uy + 1] + ry[lx][ly];
		printf("%d\n", a - b - c);
	}
}

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

#define N 1000

int lcs(char*,char*);
int max(int,int);

int main(void){
  int n;
  int i;
  char s1[N+1],s2[N+1];

  scanf(" %d",&n);
  for(i = 0; i < n; i++){
    scanf(" %s %s",s1,s2);
    printf("%d\n",lcs(s1,s2));
  }
  
  return 0;
}

int lcs(char *X, char *Y){
  int c[N+1][N+1];
  int m,n,maxl=0;
  int i,j;

  m = strlen(X);
  n = strlen(Y);

  for(i = 0; i <= m; i++){
    c[i][0] = 0;
  }
  for(j = 1; j <= n; j++){
    c[0][j] = 0;
  }

  for(i = 0; i < m; i++){
    for(j = 0; j < n; j++){
      if(X[i] == Y[j]){
	c[i+1][j+1] = c[i][j] +1;
      }
      else if(c[i][j+1] >= c[i+1][j]){
	c[i+1][j+1] = c[i][j+1];
      }
      else{
	c[i+1][j+1] = c[i+1][j];
      }
      maxl = max(maxl,c[i+1][j+1]);
    }
  }

  return maxl;
}

int max(int a, int b){
  if(a > b){
    return a;
  }
  else{
    return b;
  }
}



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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = GetLongNum();
            var input = GetLongNumArray();
            var ansList = new List<long>();

            for (int i = 1; i < N + 1; i++)
            {
                if (i % 2 == 0) continue;
                if (input[i - 1] % 2 == 0) continue;
                ansList.Add(input[i - 1]);
            }

            Console.WriteLine(ansList.Count);
        }

        private static long[] GetLongNumArray()
        {
            var input = Console.ReadLine().Split(' ');
            return input.Select(x => long.Parse(x)).ToArray();
        }

        private static long GetLongNum()
        {
            return long.Parse(Console.ReadLine());
        }

        private static string[] GetStringArray()
        {
            return Console.ReadLine().Split(' ');
        }

        private static string GetString()
        {
            return Console.ReadLine();
        }
    }
}


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



int main() {
  int tab[100007][3];
  int dp[100007][3];
  int n;
  cin >> n;

  for(int i=1;i<=n;i++){
      for(int j=0;j<3;j++){
          cin >> tab[i][j];
      }
  }
for(int j=0;j<3;j++){
    dp[1][j] = tab[1][j];
}
for(int i=2;i<=n;i++){
    for(int j=0;j<3;j++){
        dp[i][j] = max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3]) + tab[i][j];
    }
}

int ans = max(max(dp[n][0],dp[n][1]),dp[n][2]);

cout << ans << endl;
 



}

Measured memory_bytes: 2560
#include<iostream>
#include<string>


using namespace std;


int main() {
    string S;
    cin >> S;
    
    int num = 0,max = 0;

    for (int i = 0; i < S.length(); i++) {
        if (S[i] == 'A' || S[i] == 'T' || S[i] == 'C' || S[i] == 'G') {
            num++;
        }
        else {
            num = 0;
        }

        if (max < num) max = num;
    }

    cout << max;

    return 0;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007
#define INF 1000000000000000000

int main(){
  int N;
  cin>>N;
  vector<int> a(N);
  bool zero=true;
  for(int i=0;i<N;i++){
    cin>>a.at(i);
    if(a.at(i)!=0){
      zero=false;
    }
  }
  if(zero){
    cout<<"Yes"<<endl;
  }else if(N%3!=0){
    cout<<"No"<<endl;
  }else{
    bool flag=true;
    for(int i=0;i<32;i++){
      int counter=0;
      for(int j=0;j<N;j++){
        counter+=a.at(j)%2;
        a.at(j)/=2;
      }
      if(counter!=0&&counter!=(2*N/3)){
        flag=false;
        break;
      }
    }
    if(flag){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }
}


Measured memory_bytes: 640
A = int(input())
B = int(input())
C = int(input())
X = int(input())
ans = 0

for a in range(A+1):
  for b in range(B+1):
    for c in range(C+1):
      money = 500 * a + 100 * b + 50 * c
      if money == X:
        ans += 1

print(ans)

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

signed main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
    //int t=1 ; cin>>t ; while(t--)
    {
        int n, ans = 0;
        cin >> n;
        int a[n], b[n];
        for(int i=0;i<n;i++)
        {
            cin >> a[i];
            if(i)
                b[i] = min(b[i-1], a[i]);
            else
                b[i] = a[i];

            if(b[i] == a[i])
                ans++;
        }

        cout << ans << '\n';


    }
    
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}



Measured memory_bytes: 3328
use std::io::stdin;

fn read_line() -> Vec<String> {
    let mut line = String::new();
    stdin().read_line(&mut line).expect("Failed to read line");
    return line.trim().split_whitespace().map(|s| s.to_string()).collect();
}

struct Reader {
    v: Vec<String>,
    n: usize,
}

impl Reader {
    fn new() -> Reader {
        let v = read_line();
        return Reader { v: v, n: 0 };
    }
    fn next<T>(&mut self) -> T where T: std::str::FromStr, T::Err: std::fmt::Debug {
        if self.n == self.v.len() {
            self.v = read_line();
            self.n = 0;
        }
        let x = self.v[self.n].parse().expect(&self.v[self.n]);
        self.n += 1;
        return x;
    }
    fn nexts<T>(&mut self, n: usize) -> Vec<T>
    where T: std::str::FromStr, T::Err: std::fmt::Debug {
        let mut v = Vec::with_capacity(n);
        for _ in 0..n {
            v.push(self.next());
        }
        return v;
    }
}

fn main() {
    let mut r = Reader::new();
    let n: usize = r.next();
    let a: Vec<usize> = r.nexts(n);

    let sum_a: usize = a.iter().sum();
    let sum_i = n * (n+1) / 2;
    if sum_a % sum_i > 0 {
        println!("NO");
        return;
    }
    let k = sum_a / sum_i;

    if (0..n).all(|i| (a[i]+k-a[(i+1)%n])%n == 0) {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 11768
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
int main()
{
    ll s,w;
    while(cin>>s>>w)
    {
        if(w>=s)
        {
            cout<<"unsafe"<<endl;
        }
        else
        {
            cout<<"safe"<<endl;
        }
    }
    return 0 ;
}


Measured memory_bytes: 3636
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys

sys.setrecursionlimit(1000000)

N = 250000

isprime = [False, False] + [True for i in range(N)]

for i in range(N):
    if isprime[i]:
        for j in range(i * 2, N, i):
            isprime[j] = False

for i in range(1, N):
    isprime[i] += isprime[i - 1]

while True:
    n = input()
    if n == 0:
        break
    print isprime[2 * n] - isprime[n]


Measured memory_bytes: 20776
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define FOR(i, x, y) for(int i = x; i < y; i++)
typedef long long ll;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b, c, n;
    cin >> a >> b >> c >> n;
    int cnt = 0;
    for (int i = 0; i * a <= n; i++) {
        for (int j = 0; j * b <= n - a * i; j++) {
            if ((n - a * i - b * j) % c == 0) cnt++;
        }
    }
    cout << cnt << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;




int main(void) {
    
    int n;
    cin>>n;
    vpii v(n);
    rep(i,n){
        int a,b;
        cin>>a>>b;
        v[i]=mp(b,a);
    }
    Sort(v);
    ll sum=0;
    rep(i,n){
        sum+=v[i].second;
        if(sum<=v[i].first)continue;
        else {
            fin("No");
            return 0;
        }
    }
    fin("Yes");
}


Measured memory_bytes: 1792
// C++ program to find Excel 
// column name from a given 
// column number 
#include <bits/stdc++.h> 
#define ll long long int
#define MAX 70 
using namespace std; 

// Function to print Excel column name for a given column number 
void printString(ll n) 
{ 
	char str[MAX]; // To store result (Excel column name) 
	ll i = 0; // To store current index in str which is result 

	while (n > 0) { 
		// Find remainder 
		int rem = n % 26; 

		// If remainder is 0, then a 'Z' must be there in output 
		if (rem == 0) { 
			str[i++] = 'z'; 
			n = (n / 26) - 1; 
		} 
		else // If remainder is non-zero 
		{ 
			str[i++] = (rem - 1) + 'a'; 
			n = n / 26; 
		} 
	} 
	str[i] = '\0'; 

	// Reverse the string and print result 
	reverse(str, str + strlen(str)); 
	cout << str << endl; 

	return; 
} 

// Driver program to test above function 
int main() 
{ 
	ll n;
  cin>>n;
  printString(n);
} 


Measured memory_bytes: 3620
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    A = [tuple(map(int, input().split())) for _ in range(3)]
    N = int(input())
    B = [int(input()) for _ in range(N)]

    ans = [[[] for _ in range(3)] for _ in range(3)]
    for i, A_ in enumerate(A):
        for j, a in enumerate(A_):
            ans[i][j] = a in B

    if (all(ans[0]) or all(ans[1]) or all(ans[2])
        or all([ans[0][0], ans[1][0], ans[2][0]])
        or all([ans[0][1], ans[1][1], ans[2][1]])
        or all([ans[0][2], ans[1][2], ans[2][2]])
        or all([ans[0][0], ans[1][1], ans[2][2]])
        or all([ans[2][0], ans[1][1], ans[0][2]])):
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) {
            os << ',';
        }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __Setup;

using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    int n;
    cin >> n;
    vector<ll> a(n + 1), b(n);
    for(int i = 0; i < n + 1; i++) {
        cin >> a[i];
    }
    for(int i = 0; i < n; i++) {
        cin >> b[i];
    }
    ll ans = accumulate(ALL(a), 0LL);
    for(int i = 0; i < n; i++) {
        int mn = min(a[i], b[i]);
        a[i] -= mn;
        b[i] -= mn;
        mn = min(a[i + 1], b[i]);
        a[i + 1] -= mn;
        b[i] -= mn;
    }
    ans -= accumulate(ALL(a), 0LL);
    cout << ans << endl;
}

Measured memory_bytes: 4752
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <iomanip>
#include <cstdlib>
using namespace std;

int main() {
    int n;
    cin >> n;
    int p[100], q[100];
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        q[i] = p[i];
    }
    sort(q, q + n);

    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (p[i] != q[i]) cnt++;
    }

    if (cnt == 2 || cnt == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
  int x;
  cin >>x;
  if(x>=30)cout <<"Yes"<<endl;
  else cout <<"No"<<endl;
}

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

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  int a, b;
  cin >> a >> b;

  int tmp = 1;
  int cnt = 0;
  while (tmp < b) {
    tmp += a - 1;
    cnt++;
  }

  cout << cnt << endl;
  return 0;
}


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

int main() {
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;

	vector<int> v;
	int a = 0;
	char nowlooking = '1';
	for (int i = 0; i < n; i++) {

		if (s[i] == nowlooking) {
			a++;
		}
		else
		{
			v.push_back(a);
			a = 1;
			if (nowlooking == '1') nowlooking = '0';
			else nowlooking = '1';
		}
		if (i == n - 1) v.push_back(a);
	}
	if (v.size() % 2 == 0) v.push_back(0);

	int sum = 0;
	int ans = 0;
	int vs = v.size();
	if (vs < 2 * k + 1) {
		for (int i = 0; i < vs; i++) { ans += v[i]; }
	}
	else {
		for (int i = 0; i + 2 * k < vs; i += 2) {
			sum = 0;
			for (int j = i; j <= i + 2 * k; j++) {
				sum += v[j];
			}
			if (sum > ans) ans = sum;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1020
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
//#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define SZ(X) ((int64_t)((X).size()))
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define intmax (std::numeric_limits<int64_t>::max() / 4)
#define doublemax (std::numeric_limits<double>::max() / 4)
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);

//sort(ALL(v),greater<int>());


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

	/*string s;
	cin >> s;
	s[5] = ' ';
	s[13] = ' ';
	cout << s << endl;*/
	int K, S;
	cin >> K >> S;
	int ans = 0;
	rep(X, K + 1) {
		if (0 <= S - X && S - X <= 2 * K) {
			int YZ = S - X;
			ans += min(YZ, 2 * K - YZ) + 1;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
HW = input().split()
H = int(HW[0])
W = int(HW[1])


tmp = H // 2
tmp2 = H - tmp
wt = W // 2
wt2 = W - wt
ans = tmp * wt + tmp2 * wt2

if H == 1:
  ans = 1
elif W == 1:
  ans = 1

print(ans)


Measured memory_bytes: 3060
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//math.factorial(n-r)*math.factorial(r)


a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
# 最後に注文する料理は調理時間そのままの時間がかかるので「（x以上最小の10の倍数）とxの差」が最大になるような料理を選ぶと最短の時間になる


def maxtime(x):
    # 調理時間x分の料理について,注文してから次の注文までの時刻は「x以上最小の10の倍数分」
    return int(-(-x//10)*10)


def remtime(x):
    return int(maxtime(x)-x)


sum = 0
sum = int(maxtime(a)+maxtime(b)+maxtime(c)+maxtime(d)+maxtime(e))
sum -= int(max({remtime(a), remtime(b), remtime(c), remtime(d), remtime(e)}))
print(sum)


Measured memory_bytes: 3892
import sys

sys.setrecursionlimit(1000000)


def main():
    x = int(input())

    for i in range(-119, 121):
        a5 = i**5
        for j in range(-120, 120):
            b5 = j ** 5
            if a5 - b5 == x:
                print(str(i) + " " + str(j))
                return


main()


Measured memory_bytes: 9076
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {

	nums := inputLineAsNumArray(3)
	A := nums[0]
	B := nums[1]
	C := nums[2]
	if A+B >= C {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func inputLineAsNumArray(length int) []int {
	line := strings.Split(readLine(), " ")
	var nums []int
	for i := 0; i < length; i++ {
		num, _ := strconv.Atoi(line[i])
		nums = append(nums, num)
	}
	return nums
}

func readLine() string {
	sc.Scan()
	return sc.Text()
}


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

const int maxN = 1e5 + 10;

vector<int> g[maxN];

int vis[maxN];

void dfs(int cur,int par){
  vis[cur] =1;
  for(auto i: g[cur]){
    if(!vis[i])
      dfs(i,cur);
  }
}



int main() {
   
    int n,m;
    cin >> n >> m;
    
    for(int i=0;i<m;i++){
       int u,v,z;
       cin >> u >> v>>z;
       g[u].push_back(v);
       g[v].push_back(u);
    }

   int ans =0;
   for(int i=1;i<=n;i++){
     if(!vis[i]) {
       dfs(i,-1);
       ans++;
     }
   }
   cout << ans << endl; 

}

Measured memory_bytes: 9216
#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;
const int MAX_N = 100005;
int x[MAX_N];

int main()
{
	int N,K,minus = 0,plus = 0,zero = 0;
	cin >> N >> K;
	for (int i = 0; i < N; ++i)
	{
		cin >> x[i];
		if (x[i] > 0)
		{
			plus++;
		}
		else if (x[i] < 0)
		{
			minus++;
		}
		else
		{
			zero++;
		}
	}

	int ans = 1e9;
	int loop = min(minus+1,N-K+1);
	//cout << "loop:" << loop << endl;

	for (int i = 0; i < loop; ++i)
	{
		if (x[i] <= 0 && x[K-1+i] <= 0)
		{
			ans = min(ans, -1 * x[i]);
		}
		else if (x[i] <= 0 && x[K-1+i] >= 0)
		{
			ans = min(ans, min(-2 * x[i] + x[K-1+i], -1 * x[i] + x[K-1+i] * 2));
		}
		else
		{
			ans = min(ans, x[K-1+i]);
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  int n;
  int n1 = 0;
  int n9 = 0;
  int n7 = 0;
  int n4 = 0;

  scanf("%d",&n);
  if(n==1) {
    n1++;
  }
  if(n==9) {
    n9++;
  }
  if(n==7) {
    n7++;
  }
  if(n==4) {
    n4++;
  }
  scanf("%d",&n);
  if(n==1) {
    n1++;
  }
  if(n==9) {
    n9++;
  }
  if(n==7) {
    n7++;
  }
  if(n==4) {
    n4++;
  }
  scanf("%d",&n);
  if(n==1) {
    n1++;
  }
  if(n==9) {
    n9++;
  }
  if(n==7) {
    n7++;
  }
  if(n==4) {
    n4++;
  }
  scanf("%d",&n);
  if(n==1) {
    n1++;
  }
  if(n==9) {
    n9++;
  }
  if(n==7) {
    n7++;
  }
  if(n==4) {
    n4++;
  }

  if((n1-1)*(n1-1)+(n9-1)*(n9-1)+(n7-1)*(n7-1)+(n4-1)*(n4-1)==0) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }
  return 0;
}


Measured memory_bytes: 128