akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

int N;
int A[100001];
int B[100000];

int main(){
    cin>>N;
    rep(i,N+1) cin>>A[i];
    rep(i,N) cin>>B[i];

    ll ans=0;
    rep(i,N){
        if(A[i]>=B[i]){
            ans+=B[i];
            A[i]-=B[i];
        }else{
            ans+=min(B[i],A[i]+A[i+1]);
            A[i+1]=max(A[i]+A[i+1]-B[i],0);
            A[i]=0;
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

string a,b,c;
int main(){
    cin >> a >> b >> c;
    int A = sz(a), B = sz(b), C = sz(c);
    char turn = 'a';
    int i = 0, j = 0, k = 0;
    while(1){
        if(turn == 'a') turn = a[i++];
        else if(turn == 'b') turn = b[j++];
        else turn = c[k++];
        
        if(i == A+1){pr('A'); break;}
        if(j == B+1){pr('B'); break;}
        if(k == C+1){pr('C'); break;}
    }
}

Measured memory_bytes: 256
#include<cstdio>

	int main(){
		int a, b, c, d;
		d = 0;
		scanf("%d %d %d", &a, &b, &c);
		if(a == 5 && b== 7 && c == 5) d = 1;
		if(a == 5 && b== 5 && c == 7) d = 1;
		if(a == 7 && b ==5 && c == 5) d = 1;
		if(d == 1) printf("YES\n");
		else printf("NO\n");
		return 0;
		
		
		}

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

 using namespace std;

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

   if (N % 2 == 0) {
     if (K <= N / 2) cout << "YES" << endl;
     else cout << "NO" << endl;
   }

   else {
     if (K <= (N + 1) / 2) cout << "YES" << endl;
     else cout << "NO" << endl;
   }
 }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define bs binary_search
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ipr pair<ll,ll>
#define ps push_back
#define fs first
#define sc second
#define endl "\n"
#define mod 1000000007
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	char c;
	map<char,char> mp;
	cin>>c;
	mp['A']='T';
	mp['T']='A';
	mp['C']='G';
	mp['G']='C';
	cout<<mp[c];
	return 0;
}


Measured memory_bytes: 256
use std::{io::{self, prelude::*}, *};

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    let mut scan = Scanner::new(stdin.lock());
    let mut w = io::BufWriter::new(stdout.lock());
    

    let t:String = scan.next();

    if *t.as_bytes().last().unwrap() == b's' {
        writeln!(w, "{}es", t);
    }
    else {
        writeln!(w, "{}s", t);
    }
    
 
}
 
 
pub struct Scanner<B> {
    reader: B,
    buf_str: Vec<u8>,
    buf_iter: std::str::SplitWhitespace<'static>,
}
impl<B: BufRead> Scanner<B> {
    pub fn new(reader: B) -> Self {
        Self {
            reader,
            buf_str: Vec::new(),
            buf_iter: "".split_whitespace()
        }
    }
    pub fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buf_iter.next() {
                return token.parse().ok().expect("Failed parse");
            }
            self.buf_str.clear();
            self.reader.read_until(b'\n', &mut self.buf_str).expect("Failed read");
            self.buf_iter = unsafe {
                let slice = std::str::from_utf8_unchecked(&self.buf_str);
                std::mem::transmute(slice.split_whitespace()) }
        }
    }
}

Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,n) (int i=a;i<n;i++)
#define per(i,a,n,s) (int i=n-1;i>=a;i--)
#define range(...) _overload3(__VA_ARGS__,per,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define vecin(x) for(auto&youso_: (x) ) cin >>  youso_
#define vecout(x) for(auto&youso_: (x) ) cout << youso_ << " " ; cout << endl
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; }
const int inf = 1e9+10;
const int mod = 1e9+7;
const long long llinf = 1e18;
#define _GLIBCXX_DEBUG
// head

int main(){
    int a,b,c;
    a=b=c=0;
    int n;
    long long tmp;
    cin  >> n;
    for range(i,n){
        cin >> tmp;
        if (tmp%4==0)  { c++; }
        else if (tmp%2==0) { b++; }
        else { a++; }
    }
    string ans;
    c-=a;
    if (c==-1 && b==0) { ans = "Yes"; }
    else if (c>=0) { ans = "Yes"; }
    else { ans = "No"; }
    cout <<  ans << endl;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int ans = 0;
    for(int i = 1;i <= n;i++){
      if(i < 10 || i >= 100 && i < 1000 || i >= 10000 && i < 100000) ans++;   
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 21844
N = int(input())
L = []
oldword = input()
L.append(oldword)
for i in range(N-1):
    newword = input()
    if newword[0] == oldword[-1] and newword not in L:
        ans = 'Yes'
        L.append(newword)
        oldword = newword
    else:
        ans = 'No'
        break

print(ans)

Measured memory_bytes: 3064
N = gets.to_i
S = gets.chomp

s_array = S.split("")
s_array = s_array.map do |s|
  N.times do |i|
    if s == "Z"
      s = "A"
    else
      s.succ!
    end
  end

  s
end
s = s_array.join
puts s

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

#define ll long long int
#define str string

ll MOD = 1000000007,INFL = 1ll << 60,INF = 1 << 30;
ll Y[10000000] = {}, X[10000000] = {};
int dy[]={0, 0, 1, -1},dx[]={1, -1, 0, 0};
vector <ll> v;
ll a = 0,b = 0,c = 0,n = 0,sum = 0, max = INF;
str S;
int ans = 0;
int main(){
        cin.tie(0);
        ios::sync_with_stdio(false);
        //Code Line
cin >> n;
for(int i = 0;i < n;i++)cin >> X[i];
sort(X,X + n);
cout << X[n - 1] - X[0] << endl;

        //Code Line
        return 0;
}


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

S = list(input())

t = 0
s = 0

for i in S:
    if i == 'c':
        print("No")
    elif i == 'a' and t < a + b:
        print("Yes")
        t += 1
    elif i == 'b' and t < a + b and s < b:
        print("Yes")
        t += 1
        s += 1
    else:
        print("No")

Measured memory_bytes: 57976
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;	cin>>n>>k;

	vector<int> v(n+1,0), dp(n+1,INT_MAX);	dp[0]=dp[1]=0;

	for(int i=1;i<=n;++i)	cin>>v[i];

	for(int i=2;i<=n;++i)
	{
		int j=1;
		while( i - j > 0 && i - j >= i - k){

			dp[i] = min(dp[i], dp[i-j] + abs(v[i] - v[i-j])),
			j++;
		}

	}

	// for(auto i:dp)
	// 	cout<<i<<" ";

	cout<<dp[n]<<endl;
}

Measured memory_bytes: 4032
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max({a*c,a*d,b*c,b*d})<<endl;
}

Measured memory_bytes: 3648
#include <stdio.h>
#define N 8
int A[N][N]={-1};
int row[N]={-1}; 
int col[N]={-1}; 
int dpos[15]={-1};
int dneg[15]={-1}; 
void putQueen(int i);
void print();     
int main(){
  int i,j,k,l;
  scanf("%d",&k);
  for(l=0;l<k;l++){
    scanf("%d%d",&i,&j);
    A[i][j]=1;
  }
   putQueen(0);
  return 0;
}
 
void putQueen(int i){
  int j;
  //printf(" %d",i);
  if (i == N){
    print();
    return;
  }
  for (j=0;j<N;j++){
    if (col[j] ==1 ||dpos[i+j] == 1 || dneg[i-j+N-1] == 1) continue;
    // put a queen at (i, j)
      row[i] = j;
      col[j] = dpos[i+j] = dneg[i-j+N-1] = 1;
      putQueen(i+1);
       row[i]=col[j] = dpos[i+j] = dneg[i-j+N-1] = -1;
  }
}
void print(){
  int i,j;
  for(i = 0;i<N;i++) {
    for(j = 0;j<N;j++) {
      if(A[i][j]==1) {
        if(row[i] != j) return;
      }
    }
  }
   
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j)printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}



Measured memory_bytes: 2108
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=233333;
typedef long long LL;
char s[N];
int n,B[N];
inline void add(int i,int x){for(;i<=n;i+=i&-i)B[i]+=x;}
inline int ask(int i){int x=0;for(;i;i&=i-1)x+=B[i];return x;}
vector<int>pos[26];
bool vis[N];
LL ans;
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	int zt=0;
	for(int i=1;i<=n;++i)zt^=1<<(s[i]-'a'),pos[s[i]-'a'].push_back(i),add(i,1);
	if(__builtin_popcount(zt)>1)return puts("-1"),0;
	int ln=0;
	for(int i=1;i<=n;++i)if(!vis[i]){
		vis[i]=1;
		++ln;
		int c=s[i]-'a';
		if(pos[c].back()==i)ans+=(n+1)/2-ln;else{
			int t=pos[c].back();
			pos[c].pop_back();
			add(t,-1);
			ans+=ask(n)-ask(t);
			vis[t]=1;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 5148
import sys

S=sys.stdin.readline()
y=int(S[:4])
m=int(S[5:7])-1
d=int(S[8:])-1
H='Heisei'
O='TBD'
v=y*400+m*32+d
t=2019*400+3*32+29
if v<=t:
    print(H)
else:
    print(O)


Measured memory_bytes: 3060
from collections import defaultdict
N = int(input())
dic = defaultdict(int)
for n in range(2, N + 1):
    for i in range(2, n):
        if i * i > n:
            break
        while n % i == 0:
            dic[i] += 1
            n //= i
    if n > 1:
        dic[n] += 1
ans, MOD = 1, 10 ** 9 + 7
for key in dic:
    ans = ans * (dic[key] + 1) % MOD
print(ans)


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

using namespace std;

int main()
{
    string s; cin>>s;
    int x = 0, y = 0;
    int n = s.length();
    for (int i=0; i<n; i++)
    {
        if (i == 2){
            
            
            if (s[i] == s[i+1])
            {
                
                x = 1;
            }else x = 0;
        }
        
        if (i == 4)
        {
            
            if (s[i] == s[i+1]){
                
                y = 1;
            }else y = 0;
        }
    }
    
    if (x+y == 2) cout<<"Yes\n";
    else cout<<"No\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
#define pb push_back

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;
const double PI = acos(-1.0);


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * b / g;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

using Graph = vector<VE>;

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, k; cin >> n >> k;
	VE a(n); rep(i, n)cin >> a[i];
	int ans = 0;
	rep(i, n) {
		if (a[i] >= k)ans++;
	}
	cout << ans << endl;
	return 0;
}

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

int main(void){
	int n, i;
	int x;
	int a, b;
	long ans=0;
	scanf("%d%d", &n, &x);
	b=0;
	for(i=0; i<n; i++){
		scanf("%d", &a);
		if(a+b>x){
			ans += a+b-x;
			a -= a+b-x;
		}
		b = a;
	}
	printf("%ld\n", ans);
}


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

#define FOR(i,a,n) for (int i = a; i < (int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define whole(f,x,...) ([&](decltype((x)) whole) { \
    return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
template<typename T> bool chmin(T &a, const T &b) {if (a > b) { a = b; return true; }return false;}
template<typename T> bool chmax(T &a, const T &b) {if (a < b) { a = b; return true; }return false;}

using ll = int_fast64_t;

constexpr ll INF = (1e9);
constexpr ll MOD = (1e9+7);

int main() {
  int N, C; cin >> N >> C;
  vector<vector<int>> D(C, vector<int>(C)); REP(i,C) REP(j,C) cin >> D[i][j];
  vector<vector<int>> c(N, vector<int>(N)); REP(i,N) REP(j,N) cin >> c[i][j];

  vector<vector<int>> cnt(3, vector<int>(C));
  REP(i,N) REP(j,N) {
    cnt[(i+j)%3][c[i][j]-1]++;
  }

  int res = INF;
  REP(i,C) REP(j,C) if (i != j) REP(k,C) {
    if (j == k || k == i) continue;
    int t = 0;
    REP(l,C) t += D[l][i]*cnt[0][l];
    REP(l,C) t += D[l][j]*cnt[1][l];
    REP(l,C) t += D[l][k]*cnt[2][l];
    chmin(res, t);
  }
  cout << res << endl;
  return 0;
}


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

int main() {
  int H, W;

  while (true) {
    cin >> H >> W;

    if (H == 0 && W == 0) {
      break;
    }

    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        cout << "#";
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1152
#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--)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    ll n;
    cin >> n;
    ll ans = 0;

    if (n%2 == 1){
        cout << ans << endl;
        return 0;
    }
    ll p = 10;
    while(true){
        if (n >= p){
            ans += n / p;
            p *= 5;
        }
        else break;
    }

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

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

#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define DECIMAL(n)  std::cout << std::fixed;std::cout << std::setprecision(n);
#define hell 1000000007
#define PI 3.14159265358979323844
#define mp make_pair
#define pb push_back
#define fi first 
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))  
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define maxc(v) max_element(all(v))
#define minc(v) min_element(all(v))
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define initarr(a,n,x) for (int i=0;i<n;++i) a[i]=x
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.insert(tmp);commands}
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

#define ll long long
#define ld long double 
#define pii std::pair<int, int> 
#define pll std::pair<ll, ll>  
#define vi vector<int>  
#define vvi vector<vi > 
#define vii vector<pii >

pii operator+(pii a, pii b)
{
    return {a.fi+b.fi,a.se+b.se};
}
pll operator+(pll a, pll b)
{
    return {a.fi+b.fi,a.se+b.se};
}
std::ostream& operator<<(std::ostream& out,pii a)
{
    out<<a.fi<<" "<<a.se<<endl;
    return out;
}
std::ostream& operator<<(std::ostream& out,pll a)
{
    out<<a.fi<<" "<<a.se<<endl;
    return out;
}
std::istream& operator>>(std::istream& in,pii &a)
{
    in>>a.fi>>a.se;
    return in;
}
std::istream& operator>>(std::istream& in,pll &a)
{
    in>>a.fi>>a.se;
    return in;
}

using namespace std;

int main()
{
    FAST;
    int n;
    cin>>n;
    int a[n],b[n],c[n];
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    ll dp[n][3];
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];
    for (int i = 1; i < n; ++i)
    {
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
        dp[i][2]=max(dp[i-1][1],dp[i-1][0])+c[i];
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}

Measured memory_bytes: 3840
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

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

	cin >> N >> M;
	vector<int>p(N+1);
	vector<int>w(N+1);
	for (int i = 1; i <= N; i++) {
		cin >> p[i] >> w[i];
	}
	int ans = MOD;
	for (int i = 0; i < 1 << N; i++) {
		int cnt = 0;
		int box = 0;
		for (int j = 0; j < N; j++) {
			if ((i >> j) & 1) {
				box += p[j + 1] * (j + 1) * 100;
				box += w[j + 1];
				cnt += p[j + 1];
			}
		}
		for (int j = N - 1; j >= 0; j--) {
			if ((i >> j) & 1)continue;
			int ccnt = 0;
			while (box < M&&ccnt + 1 < p[j + 1]) {
				box += (j + 1) * 100;
				cnt++;
				ccnt++;
			}
		}
		if (box >= M) {
			ans = min(ans, cnt);
		}
	}
	cout << ans << endl;
	return 0;
}

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

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

  vector <tuple<string, int, int>> A;

  for( int i=1; i<=N; i++){
    string S;
    int P;
    cin >> S >> P;
    P = -P;
    
    A.push_back(tie(S, P, i));
  }

  sort(A.begin(), A.end());

  rep(i, N){
    cout << get<2>(A[i]) << endl;
  }
}


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

const int inf = 1e9;
const ll linf = 1e18;
const ll mod = 1e9 + 7;
 
int main()
{
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;

    vector<int> x(N);
    for (int i = 0; i < N; i++) cin >> x[i];
    vector<int> y(M);
    for (int i = 0; i < M; i++) cin >> y[i];

    int xm = *max_element(x.begin(), x.end());
    int ym = *min_element(y.begin(), y.end());

    if (xm < ym && xm < Y && ym > X) cout << "No War" << endl;
    else cout << "War" << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		// standard input
		int height = sc.nextInt();
		int width = sc.nextInt();

		// solve
		String result = null;
		for (int i = 0; i < height; i++) {
			for (int j = 0; j < width; j++) {
				if ("snuke".equals(sc.next())) {
					result = Character.toString((char) (j + 65)) + (i + 1);
				}
			}
		}

		// standard output
		System.out.println(result);
	}
}

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

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	c := a + b
	d := a - b
	e := a * b
	m := c
	if m < d {
		m = d
	}
	if m < e {
		m = e
	}

	fmt.Println(m)
}


Measured memory_bytes: 512
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <complex>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define EPS 1e-8
#define DEB 1


int main(){
	int n,m;
	int data[1024];
	while(scanf("%d%d",&n,&m),n|m){
		int sum = 0;
		rep(i,n){
			scanf("%d",data+i);
			sum += data[i];
		}
		sort(data,data+n);
		int i;
		for(i=n-m; i>=0; i-=m){
			sum -= data[i];
			//printf("i:%d  data:%d\n",i,data[i]);
		}
		printf("%d\n",sum);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
char map[101][101],type[4] = "@#*";
int h,w;
void f(int y,int x,char t){
	int i,dy[4] = {-1,0,0,1},dx[4] = {0,-1,1,0},nx,ny;
	map[y][x] = '.';
	for(i = 0;i < 4;i++){
		ny = y + dy[i];
		nx = x + dx[i];
		if(0 <= nx && nx < w && 0 <= ny && ny < h && map[ny][nx] == t){
			f(ny,nx,t);
		}
	}
	return;
}
int main(){
	int i,j,count,k;
	while(cin >> h >> w && (h != 0 && w != 0)){
		count = 0;
		for(i = 0;i < h;i++){
			cin >> map[i];
		}
		for(i = 0;i < h;i++){
			for(j = 0;j < w;j++){
				for(k = 0;k < 3;k++){
					if(map[i][j] == type[k]){
						f(i,j,type[k]);
						count++;
					}
				}
			}
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 0
Scanf.scanf "%d %d %d %d" (fun n a b k ->
    let extgcd x y =
        let rec eg r0 r1 a0 a1 b0 b1 =
            if r1 = 0 then a0 else
                let q1 = r0 / r1 in
                eg r1 (r0 mod r1) a1 (a0 - q1 * a1) b1 (b0 - q1 * b1)
        in
        eg x y 1 0 0 1
    in
    let inv x y = (* 1/x in mod y *)
        let c = extgcd x y in
        if c < 0 then c + y else c
    in
    let z = 998244353 in
    let ( +@) a b = (a + b) mod z in
    let ( *@) a b = (a * b) mod z in
    let ( /@) a b = a *@ inv b z in
    let fact = Array.make 300001 1 in
    for i = 1 to 300000 do fact.(i) <- fact.(i - 1) *@ i done;
    let binomial n k = fact.(n) /@ (fact.(k) *@ fact.(n - k)) in
    let rec loop b0 acc =
        if b0 * b > k || b0 > n then acc else
            let r = k - b0 * b in
            if r mod a <> 0 then loop (b0 + 1) acc else
                let a0 = r / a in
                if a0 > n then loop (b0 + 1) acc else
                    let acc = acc +@ binomial n a0 *@ binomial n b0 in
                    loop (b0 + 1) acc
    in
    loop 0 0 |> Printf.printf "%d\n"
)

Measured memory_bytes: 6172
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long int
#define pb push_back
#define mk make_pair
#define flp(i, k, n) for(int i=k; i<n; i++)
#define rev(i, k) for(int i=k; i>=0; i--)
#define F first
#define S second
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int dx[4] = {-1,1,0,0};
int dy[4] = {0,0,-1,1};

int32_t main(void)
{
    int n, k, ans=0;
    cin>>n>>k;
    flp(i, k, n+2)
    {
        int s1=(i*(i-1)/2)%mod;
        int m=(n-i);
        int s2=(n*(n+1)/2 - m*(m+1)/2%mod);
        ans=(ans+s2-s1+1)%mod;
    }
    cout<<ans<<"\n";
    return 0;



}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
using ll = long long;


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

    for (int i = 1; i < 10; ++i) {
        for (int j = 1; j < 10; ++j) {
            if (i * j == N) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = sorted(inpl())
now = 0 if n%2 else -1
for i in range(n):
    if i%2 == n%2:
        now += 2
    if a[i] != now:
        print(0)
        quit()
print(pow(2,n//2)%mod)

Measured memory_bytes: 79788
#include<iostream>
main(){int a,b,c,d,e,f,g,h[]={0,0,31,59,90,120,151,181,212,243,273,304,334};for(;std::cin>>a>>b>>c>>d>>e>>f,a+1;std::cout<<g<<"\n"){g=f-c+h[e]-h[b]+(d-a)*365;e<3?d--:d;b<3?a--:a;g+=d/4-a/4-d/100+a/100+d/400-a/400;}}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int cnt100(int n){
    int cnt = 0;

    while(n % 100 == 0){
        n /= 100;
        cnt++;
    }
    return cnt;
}

int main(void){
    int d, n;
    cin >> d >> n;

    int cnt = 0;
    int i = 1;

    while(i >= 1){
        if(cnt100(i) == d){
            cnt++;
            if(cnt == n){
                printf("%d", i);
                break;
            }
        }
      i++;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
n = int(input()) 

a = list(map(int, input().split()))

ans = 1;
for i in range(n):
  if (a[i] == 0):
    print('0')
    sys.exit()
 
for i in range(n):
    
  ans *= a[i]
  if (ans > 1000000000000000000):
    print('-1')
    sys.exit()
  

print(ans)

Measured memory_bytes: 84760
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
struct node{
    int x,y;
}no[10005];
struct edge{
    int from,to;
    double dis;
}ed[200000];
bool cmp(const edge &a,const edge &b){
    return a.dis>b.dis;
}
int father[10005];
int find(int who){
    if(who==father[who]) return who;
    else return father[who]=find(father[who]);
}
int main(void){
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>no[i].x>>no[i].y;
        father[i]=i;
    }
    double ans=0;
    for(int i=1;i<=m;i++){
        int a,b;
        cin>>a>>b;
        ed[i].from=a;
        ed[i].to=b;
        ed[i].dis= pow(pow(no[a].x-no[b].x,2)+pow(no[a].y-no[b].y,2),0.5);
        ans+=ed[i].dis;
    }
    //cout<<ans<<endl;
    sort(ed+1,ed+1+m,cmp);
    for(int i=1;i<=m;i++){
        int x=find(ed[i].from);
        int y=find(ed[i].to);
        if(x!=y){
            if(x<y)
                father[x]=father[y];
            else
                father[y]=father[x];
            ans-=ed[i].dis;
            //cout<<ed[i].dis<<":  "<<ed[i].from<<"---"<<ed[i].to<<endl;
            //for(int j=1;j<=n;j++)
            //    cout<<father[j]<<" ";
            //cout<<endl;
        }
    }
    printf("%.3lf",ans);
    return 0;
}

Measured memory_bytes: 3908
#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 ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  string o, e;
  cin >> o >> e;

  REP(i, o.size() + e.size()){
    if(i % 2) cout << e[i / 2];
    else cout << o[i / 2];
  }
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, islice
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')

N, W = MAP()
w, v = ZIP(N)

dp = [[0]*(W+1) for _ in range(N+1)]

for i in range(N):
	for j in range(W+1):
		if j-w[i] >= 0:
			dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]]+v[i])
		else:
			dp[i+1][j] = dp[i][j]
print(dp[N][W])


Measured memory_bytes: 123756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

string s;

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

    int a,b; cin >>a>>b;
    cout << max(a - 2*b, 0) << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

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

  REP(i,s.size()) {
    int x = s[i]-'0';
    if (x==1) continue;

    if (i+1 <= k) {
      COUT(x);
      return 0;
    }
  }
  COUT(1);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){

  vector <int> a;
  int n,i,b=0,test;
  cin>>n;
  if(n%2==0) b=1;
  for(i=0;i<n;i++){
    cin>>test;
    if(i%2==b) a.insert(a.begin(),test);
    else a.push_back(test);
  }

  for(i=0;i<a.size()-1;i++) cout<<a[i]<<" ";
  cout<<a[a.size()-1]<<endl;
  return 0;
}








Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0;i--)
using namespace std;

int main(){
  int x;
  cin >> x;
  if(x < 1200){
    cout << "ABC" << endl;
  }else{
    cout << "ARC" << endl;
  }
  
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

vector<vector<int>> G;
vector<LL> dp_b, dp_w;

void mul(LL& a, LL b) { a = (a * b) % kMod; }

void dfs(int v, int parent) {
  for (int u : G[v]) {
    if (u == parent) continue;
    dfs(u, v);
    mul(dp_w[v], dp_w[u] + dp_b[u]);
    mul(dp_b[v], dp_w[u]);
  }
}

int main() {
  int N; cin >> N;
  G.resize(N), dp_b.resize(N, 1), dp_w.resize(N, 1);
  for (int i = 0; i < N-1; ++i) {
    int x, y; cin >> x >> y; --x, --y;
    G[x].push_back(y);
    G[y].push_back(x);
  }

  dfs(0, -1);
  cout << (dp_b[0] + dp_w[0]) % kMod  << endl;
}


Measured memory_bytes: 17024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define DEBUG
#ifdef DEBUG
#define debug_printf printf
#else
#define debug_printf 1 ? 0 : printf
#endif

using namespace std;
typedef long long int ll;
typedef vector<ll> Vl;
typedef vector<int> Vi;
typedef pair<int, int> Pi;

#define FST first
#define SND second

#define MAX_N   (2000)                  // 10^3
#define MAX_Q   (200000)                  // 10^5
// #define MAX_N   (1000000000)              // 10^9
// #define MAX_N   (1000000000000000000)     // 10^18
#define BASE    (1000000000 + 7)          // 10^9 + 7
#define INFI    (1000000000 + 7)          // 10^9 + 7
#define INFL    (1000000000000000000 + 7) // 10^18 + 7

ll A, B;
string S[MAX_N];

ll calc() {
  ll r = 1L << 61;
  while (r > 0) {
    ll da = A & r;
    ll db = B & r;
    if (da != db) break;
    r >>= 1;
  }
  if (r == 0) return 1;

  if (A > B) swap(A, B);
  ll mask = (r << 1) - 1;
  A &= mask; B &= mask;

  ll k = r >> 1;
  while (k > 0) {
    ll db = B & k;
    if (db != 0) break;
    k >>= 1;
  }
  r <<= 1; k <<= 1;
  if (k == 0) k = 1;

  ll l1 = A, r1 = (r >> 1) + k;
  ll l2 = A + (r >> 1), r2 = r;
  if (l2 <= r1) {
    return max(r1, r2) - min(l1, l2);
  } else {
    return (r1 - l1) + (r2 - l2);
  }
}

void solve() {
  ll ans = calc();

  cout << ans << endl;
}

int main() {
  cin >> A >> B;

  solve();

  return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(m), c(m);
  vector<pair<int, int>> bc(m), cb(m);
  int i, j;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < m; i++) {
    cin >> b[i] >> c[i];
    bc[i] = make_pair(b[i], c[i]);
    cb[i] = make_pair(c[i], b[i]);
  }

  sort(a.begin(), a.end());
  sort(cb.begin(), cb.end());


  int chenge_index = 0;
  for (i = cb.size() - 1; i >= 0; i--) {
    if (chenge_index >= a.size()) {
      break;
    }
    if (a[chenge_index] >= cb[i].first) {
      break;
    }
    for (j = 0; j + chenge_index < a.size() && j < cb[i].second; j++) {
      a[chenge_index + j] = max(a[chenge_index + j], cb[i].first);
    }
    chenge_index += cb[i].second;
  }

  long long result = 0;
  for (i = 0; i < a.size(); i++) {
    result += a[i];
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 2944
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n,k,q = MAP()
lst = [0]*n
for i in range(q):
    lst[INT()-1]+=1

x = sum(lst)
for i in lst:
    if x-i>=k:
        print("No")
    else:
        print("Yes")

Measured memory_bytes: 4680
#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>;
const ll INF=1000000007;

ll fnc(int x) {
  ll y=1;
  for(int i=x; i>0; i--) {
    y*=i;
    y%=INF;
  }
  return y;
}

int main() {
  int n, m;
  cin >> n >> m;
  if(n<m) swap(n,m);
  if(n-m>1) {
    cout << 0 << endl;
    return 0;
  }
  if(n==m) cout << 2*fnc(n)*fnc(m)%INF << endl;
  else cout << fnc(n)*fnc(m)%INF << endl;
}


Measured memory_bytes: 256
import Data.List

calc :: Int -> String -> Int -> Int
calc c s m
  | c == length s = m
  | otherwise = calc (c + 1) s nm
    where
      (a, b) = splitAt c s
      cm = length $ intersect (nub a) (nub b)
      nm = max cm m

main = do
  n <- readLn :: IO Int
  s <- getLine
  print $ calc 1 s 0
  

Measured memory_bytes: 4900
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <cassert>
#include <bitset>
#include <cmath>
#include <iomanip>

using namespace std;

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////
int N, M;
vector<vector<int>> g;
vector<int> cache;

int rec (int x) {
    int & res = cache[x];
    if (res != -1)
        return res;
    res = 0;
    for (auto v : g[x])
        res = max(res, rec(v) + 1);
    return res;
}

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

    cin >> N >> M;
    g.resize(N);
    for (int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        g[x].push_back(y);
    }

    cache.assign(N, -1);
    int ans = 0;

    for (int i = 0; i < N; i++) {
        ans = max(ans, rec(i));
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 7552
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
const int maxn=300005;
int nxt[maxn],n,k;
char s[maxn];
inline i64 calc(int c,i64 r){
	i64 res=0;
	if(r<=n){
		rep(i,1,r)res+=s[i]==c;
		return res;
	}
	i64 ca=0,cb=0;
	rep(i,1,n-k)ca+=s[i]==c;
	rep(i,n-k+1,n)cb+=s[i]==c;
	if(k%(n-k)==0){
		i64 cc=0;
		rep(i,n-k+1,n-k+(r-(n-k))%k)cc+=s[i]==c;
		return ca+cb*((r-(n-k))/k)+cc;
	}else{
		i64 a=n-k,b=k;
		for(;a+b<=r;b+=a,swap(a,b),cb+=ca,swap(ca,cb));
		return ca+calc(c,r-a);
	}
}
int main(){
	scanf("%s",s+1);
	n=strlen(s+1)/2;
	rep(i,2,n){
		int p=nxt[i-1];
		while(p&&s[p+1]!=s[i])p=nxt[p];
		if(s[p+1]==s[i])p++;
		nxt[i]=p;
	}
	k=nxt[n];
	if(k==0)k=n,n+=n;
	i64 l,r;
	cin>>l>>r;
	rep(i,0,25)cout<<calc(i+'a',r)-calc(i+'a',l-1)<<' ';
	return 0;
}


Measured memory_bytes: 896
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main() {
	ll n;
	cin>>n;
	vector<ll> v;
	rep(i,0,n){
		ll a;
		cin>>a;
		v.pb(a);
	}
	sort(all(v));
	ll a = v[(n-1)/2];
	ll b = v[(n-1)/2+1];
	if(a==b){
		cout << 0 << endl;
	}
	else{
		cout << b-a << endl;
	}
	return 0;
}

Measured memory_bytes: 1400
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

fn main() {
    input!{
        c: [[i32; 3]; 3],
    }
    for a1 in 0..101 {
        for a2 in 0..101 {
            for a3 in 0..101 {
                let b1res = (c[0][0] - a1) == (c[0][1] - a2) && (c[0][1] - a2) == (c[0][2] - a3);
                let b2res = (c[1][0] - a1) == (c[1][1] - a2) && (c[1][1] - a2) == (c[1][2] - a3);
                let b3res = (c[2][0] - a1) == (c[2][1] - a2) && (c[2][1] - a2) == (c[2][2] - a3);
                if b1res && b2res && b3res {
                    println!("Yes");
                    return;
                }
            }
        }
    }
    println!("No");
}


Measured memory_bytes: 4352
def main():
    H,N = map(int, input().split())
    A,B = [0]*N,[0]*N
    for i in range(N): A[i],B[i]=map(int, input().split())
    # dp[h] := モンスターの体力をh削るための最小合計魔力
    INF = float('inf')
    dp = [INF]*(H+1)
    dp[0] = 0
    for h in range(1,H+1):
        # h削る最小コストを探す
        for a,b in zip(A,B):
            if h-a>=0:
                dp[h]=min(dp[h],dp[h-a]+b)
            else:
                dp[h]=min(dp[h],b)
    print(dp[H])

main()


Measured memory_bytes: 42348
k=int(input())
a,b=map(int,input().split())
if k!=1:
	x=a//k
	y=b//k
	if x!=y:
		print("OK",end="")
	elif x==y and a!=b and a%k!=0 and b%k!=0:
		print("NG",end="")
	elif x==y and a==b and a%k!=0:
		print("NG",end="")
	else:
		print("OK",end="")
else:
	print("OK",end="")

Measured memory_bytes: 9204