akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
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; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y) {
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}

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

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
  return modpow(a, mod - 2, mod);
}

ll calc(ll k){
  ll sum = 0;
  while(k % 2 == 0){
    sum++;
    k /= 2;
  }
  return sum;
}


int main(){
  ll n;
  cin >> n;
  vector<ll> com(n+1,0);
  vector<ll> div(n+1,true);
  vector<ll> vec(n);
  string str;
  cin >> str;
  ll sum = 0;
  ll ans = 0;
  ll cou = 0;

  ll t1 = 2;
  while(t1 <= n){
    t2 = t1;
    while(t2 <= n){
      com[t2]++;
      t2 += t1;
    }
    t1 *= 2;
  }
  t1 = 0;
  rep(i,n){
    t1 += com[i];
    com[i] = t1;
    //cout << com[i] << " ";
  }

  rep(i,n){
    t1 = com[n-1] - com[n-1-i] - com[i];
    //cout << t1 << " ";
    if(t1 > 0){
      div[i] = false;
    }
  }
  bool can = true;
  rep(i,n){
    vec[i] = str[i] - 49;
    if(vec[i] % 2 != 0){
      can = false;
    }else if(vec[i] == 2){
      cou++;
    }
    sum += div[i] * vec[i];
    //cout << com[i] << " " << vec[i] << endl;
  }
  if(sum % 2 == 0){
    if(can){
      rep(i,n){
        vec[i] /= 2;
      }
      sum = 0;
      rep(i,n){
        sum += div[i] * vec[i];
        //cout << com[i] << " " << vec[i] << endl;
      }
      if(sum % 2 != 0){
        ans = 2;
      }else{
        ans = 0;
      }
    }else{
      ans = 0;
    }
  }else{
    ans = 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 24836
#include<bits/stdc++.h>
using namespace std;
#define NL            "\n"
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
int a[206],b[206];
int main()
{
    _SAD()
    int x,y;
    cin>>x>>y;
    a[1]=300000;
    b[1]=300000;
    a[2]=200000;
    b[2]=200000;
    a[3]=100000;
    b[3]=100000;
    if(x==1&&y==1)
    {
        cout<<"1000000"<<NL;
    }
    else
    {
        cout<<a[x]+b[y]<<NL;
    }
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from operator import itemgetter

def gcd(a, b):
	if b % a == 0:
		return a
	else:
		return gcd(b % a, a)

def gcd_ary(ary, n):
	for i in range(n-1):
		ary[i+1] = gcd(ary[i], ary[i+1])
	return ary[n-1]

def main():
	n, x = map(int, input().strip().split())
	v = list(map(int, input().strip().split()))
	d = [0] * n
	for i in range(n):
		d[i] = abs(x - v[i])
	print(gcd_ary(d, n))

if __name__ == '__main__':
	main()


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

int main() {
    string t;
    cin >> t;
    
    for (int i = 0; i < t.size(); i++) {
        if (t[i] == '?') {
            t[i] = 'D';
        }
    }
    
    cout << t << endl;
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define pb(a) push_back(a)
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll MAX = 510000;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
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;}
ll fact[210000], invfact[210000];

ll invmod(ll a, ll p)
{ // a^-1 mod p
    ll b = p, u = 1, v = 0;
    while (b)
    {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= p;
    if (u < 0)
        u += p;
    return u;
}

void factmod(ll m)
{
    fact[0] = invfact[0] = 1;
    for (ll i = 1; i < 210000; i++)
    {
        fact[i] = (fact[i - 1] * i) % m;
        invfact[i] = (invfact[i - 1] * invmod(i, m)) % m;
    }
}

ll nCrmod(ll n, ll r, ll m)
{
    return (((fact[n] * invfact[r]) % m) * invfact[n - r]) % m;
}

ll powmod(ll a, ll p, ll m)
{
    ll res = 1, tmp = a;
    while (p != 0)
    {
        if (p % 2)
            res = (res * tmp) % m;
        tmp = (tmp * tmp) % m;
        p /= 2;
    }
    return res;
}
int main()
{
    ll n;ll k;
    cin >> n >> k;
    chmin(k,n);
    ll ans=1;
    factmod(MOD);
    REP(i,k){
        ll tmp=nCrmod(n-1,i+1,MOD)*nCrmod(n,i+1,MOD);
        tmp%=MOD;
        ans+=tmp;
        ans%=MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 6824
#include <iostream>
using namespace std;
int main(){
	int N,K;
	int M = 1;
	cin >> N >> K;
	for(int i = 0; i < 100 ; i++){
		M *= K;
		if(M > N){
			cout << i+1 << "\n";
			break;
		}
	}

	return 0;
}

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

using namespace std;
const int MOD = 2019;

int main(){
    int l, r; cin >> l >> r;
    if (l/MOD < r/MOD){
        cout << "0\n";
        return 0;
    }

    int mn = MOD;
    for (int i = l; i <= r; ++ i)
    for (int j = i+1; j <= r; ++ j)
        mn = min((long long)mn, (i*1LL*j)%MOD);
    cout << mn << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int A, B, K;cin>>A>>B>>K;
    for(int i=min(A, B);i>0;i--){
        if(A % i == 0 && B % i == 0){
            --K;
            if(K == 0){
                cout << i << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	defer writer.Flush()
	H := ReadInt()
	A := make([]int, H+1)
	for i := 1; i <= H; i++ {
		A[i] = ReadInt()
	}
	for i := H / 2; i >= 1; i-- {
		maxHeapify(A, i)
	}
	for _, v := range A[1:] {
		Printf(" %d", v)
	}
	Printf("\n")
}

func maxHeapify(A []int, i int) {
	largest := i
	left := i * 2
	right := i*2 + 1
	if left < len(A) && A[left] > A[largest] {
		largest = left
	}
	if right < len(A) && A[right] > A[largest] {
		largest = right
	}
	if i != largest {
		A[i], A[largest] = A[largest], A[i]
		maxHeapify(A, largest)
	}
}

var (
	reader = bufio.NewReader(os.Stdin)
	writer = bufio.NewWriter(os.Stdout)
)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }

func Printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }



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

int main() {
  int N, M;
  cin >> N >> M;
  
  priority_queue<ll> q;
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ll A;
    cin >> A;
    
    q.push(A);
    ans += A;
  }
  
  while (M > 0) {
    ll x = q.top();
    q.pop();
    
    q.push(x - (x + 1) / 2);
    ans -= (x + 1) / 2;
    M--;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 1400
n=int(input())
m=[{}for i in range(n+1)]
w=10**9+7
def f(s):
    for i in range(4):
        t=list(s)
        if i>=1:
            t[i-1],t[i]=t[i],t[i-1]
        if "".join(t).count("AGC")>0:
            return False
    return True
def a(p,q):
    if q in m[p]:
        return m[p][q]
    if p==n:
        return 1
    r=0
    for i in "AGCT":
        if f(q+i):
            r=(r+a(p+1,q[1:]+i))%w
    m[p][q]=r
    return r
print(a(0,"WHY"))



Measured memory_bytes: 3884
import sys
import queue

H,W = map(int,input().split())


white = 0
	
maze = []

for y in range(H):
	li = list(input())
	white += li.count('.')
	maze.append(li)

if maze[0][0] == '#' or maze[H-1][W-1] == '#':
	print (-1)
	sys.exit()

	
maze[H-1][W-1] =	'g'
	
q = queue.Queue()
q.put([0,0,0])

def check(x,y,n):
	if 0 <= x < W and 0 <= y < H:
		if maze[y][x] == 'g':
			print (white - n - 1)
			sys.exit()
		elif maze[y][x] == '.':
			maze[y][x] = n
			q.put([x-1,y,n+1])
			q.put([x+1,y,n+1])
			q.put([x,y-1,n+1])
			q.put([x,y+1,n+1])
		else:
			return
	else:
		return


while not q.empty():
	x,y,n = q.get()
	check(x,y,n)
	
print(-1)

Measured memory_bytes: 3952
import sys
input = sys.stdin.readline


n = int(input())
INF = 10 ** 9
info = [list(input().split()) for i in range(2 * n)]

ind = {}
for i in range(2 * n):
    if info[i][0] == "B":
        info[i] = (0, int(info[i][1]))
    else:
        info[i] = (1, int(info[i][1]))
    ind[info[i][0] * 10 ** 5 + info[i][1]] = i

ru_b = [[0] * (2 * n + 1) for i in range(n + 1)]
ru_w = [[0] * (2 * n + 1) for i in range(n + 1)]
for i in range(n + 1):
    for j in range(2 * n):
        col, num = info[j]
        if col == 0 and num > i:
            ru_b[i][j + 1] += 1
        elif col == 1 and num > i:
            ru_w[i][j + 1] += 1
    for j in range(2 * n):
        ru_b[i][j + 1] += ru_b[i][j]
        ru_w[i][j + 1] += ru_w[i][j]    


dp = [[INF] * (n + 1) for i in range(n + 1)]
dp[0][0] = 0
for i in range(n + 1):
    for j in range(n + 1):
        if i + 1 <= n and j <= n:
            bi = ind[i + 1]
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + ru_b[i][bi] + ru_w[j][bi])
        if i <= n and j + 1 <= n:
            wi = ind[10 ** 5 + j + 1]
            dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + ru_w[j][wi] + ru_b[i][wi])

print(dp[-1][-1])

Measured memory_bytes: 195720
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
	int n,ans = 0;
	cin >> n;
	rep(i,  sqrt(n)+1) {
		if (i* i <= n) {
			ans = i*i;
		}
	}

	cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import Control.Applicative 
import Data.List

sum' 0 y = 0
sum' x (y:yy:ys) =sum' (x-1) ys + yy;   

main = do
	n <- fmap(read::String ->Int) . words<$>getLine
	l <- fmap(read::String ->Int) . words<$>getLine
	print  $ sum' (n !! 0) (reverse (sort l))
 
		






Measured memory_bytes: 1020
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	var t int
	fmt.Fscan(r, &n)
	fmt.Fscan(r, &t)
	ts := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &ts[i])
	}

	sum := 0
	start := 0
	end := t
	for i := 1; i < n; i++ {
		if ts[i] > end {
			sum += end - start
			start = ts[i]
		}
		end = ts[i] + t

	}
	sum += end - start

	fmt.Println(sum)
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}


Measured memory_bytes: 4992
/*
https://atcoder.jp/contests/dp/tasks/dp_d
*/
#include<bits/stdc++.h>
#define ll long long int
using namespace std;

ll dp[101][100001];

ll solve(ll n, ll w, ll wt[], ll val[]){

    /// Base Case
    if(n <= 0){
        return 0;
    }

    /// Lookup
    if(dp[n][w] != -1){
       return dp[n][w];
    }

    if(wt[n-1] > w){ /// if weight is greater than capacity
        return dp[n][w] = solve(n-1,w,wt,val);
    }

    /// Two choices either to choose or not choose

    ll op1 = solve(n-1,w-wt[n-1],wt,val) + val[n-1];
    ll op2 = solve(n-1,w,wt,val);

    return dp[n][w] = max(op1,op2);

}


int main(){

    ll n,w;  cin>>n>>w;

    ll wt[n],val[n];

    for(int i=0;i<n;i++){
        cin>>wt[i]>>val[i];
    }

    memset(dp,-1,sizeof(dp));

    ll ans = solve(n,w,wt,val);

    cout<<ans<<"\n";

return 0;
}


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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;

  vll as(n), bs(n), cs(n);
  rep(i,n) cin >> as[i];
  rep(i,n) cin >> bs[i];
  rep(i,n) cin >> cs[i];

  Sort(as), Sort(bs), Sort(cs);

  vll bsum(n+1, 0);
  rep(i, n) {
    ll idx = Upper_bound(cs, bs[i]);
    bsum[i+1] = n - idx + bsum[i];
  }

  ll ans = 0;
  rep(i, n) {
    ll idx = Upper_bound(bs, as[i]);
    ans += bsum[n] - bsum[idx];
  }
  
  cout << ans << endl;

  return 0;
}


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

using namespace std;
typedef long long ll;
//ループ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//コンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define D()
//定数
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

//2値の最大公約数(順序関係なし・0はダメ)
int gcd(int a, int b){
    return b ? gcd(b, a%b) :a;
}

//n個の最大公約数
int ngcd(vector<int>& a){
    int res;
    res = a.at(0);
    for(int i = 1; i< a.size() && res != 1; i++){
        res = gcd(a.at(i), res);
    }
    return res;
}

//2値の最小公倍数
int lcm(int a, int b) {
    return a / gcd(a, b) * b;
}

//n個の最小公倍数
int nlcm(vector<int> numbers){
    int res;
    res = numbers.at(0);
    for(int i = 0; i< numbers.size();i++){
        res = lcm(res, numbers[i]);
    }
    return res;
}

//素数判定O(√N)
bool isPrime(int x){
    if(x<2) return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(int i = 3; i*i <= x; i+=2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(int n){
    int res = 0;
    while(n>0){
        res += n%10;
        n /= 10;
    }
    return res;
}

//約数全列挙
vector<int> enum_div(int n){
    vector<int> ret;
    for(int i = 1 ; i*i <= n ; ++i){
        if(n%i == 0){
            ret.push_back(i);
            if(i != 1 && i*i != n){
                ret.push_back(n/i);
            }
        }
    }
    return ret;
}

//繰り返し自乗法
long long int mod_pow(long long int x, long long int n, long long int mod){
    long long int res = 1;
    while(n > 0){
        if(n & 1) res = res*x%mod;
        x = x*x%mod;
        n >>= 1;
    }
    return res;
}

//文字列の中で何回文字が出てきたのかを数える
int stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c); //覚える
}

int main(){
    ll N; cin >> N;
    deque<ll> deq;
    ll buf;

    while(N>0){
        N--;
        buf = N % 26;
        N /= 26;
        deq.push_front(buf);
    }

    string ans;

    for(auto i: deq){
        ans += 'a'+ i;
    }

    cout << ans << endl;
}

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

#define ll long long
#define ld long double
#define pb push_back
#define mod 1000000007
#define mk make_pair
#define sz size

ll find(ll x,vector<ll> &root){
    while(root[x]!=x){
        root[x]=root[root[x]];
        x=root[x];
    }
    return x;
}

ll union_find(ll x,ll y,vector<ll>&root,vector<ll> &arr){
    ll r1=find(x,root);
    ll r2=find(y,root);
    if(arr[r1]>arr[r2]){
        root[r2]=r1;
    }else if(arr[r1]<arr[r2]){
        root[r1]=r2;
    }
}

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

    ll i,n,k;
    cin>>n>>k;
    vector<ll> v(n);
    ll ans=0;
    for(i=0;i<n;i++)
    {    cin>>v[i];
        if(v[i]>=k)ans++;
    }
    cout<<ans;
    return 0;  
}

Measured memory_bytes: 1024
from collections import deque
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, d=DVSR): return pow(x, d - 2, d)
def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())


N,K=LI()
mp = {}

if N == 1:
    print(K)
    exit()

for i in range(N-1):
    a,b = LI()
    if not a in mp: mp[a] = []
    if not b in mp: mp[b] = []
    mp[a].append(b)
    mp[b].append(a)

QU = deque([])
visited = set([1])

fact=[1]*(max(N,K)+1)
for i in range(1, max(N,K)+1):
    fact[i] = fact[i-1]*i%DVSR

def ncr(n,r):
    return fact[n]*INV(fact[r])*INV(fact[n-r])%DVSR

pat = ncr(K, len(mp[1])+1)*fact[len(mp[1])+1]%DVSR
for i in mp[1]:
    visited.add(i)
    QU.append(i)

# print("initial {}".format(pat))
while QU:
    vx = QU.popleft()
    # print(vx)
    nxcnt = len(mp[vx])
    if (nxcnt+1) > K:
        print(0)
        exit()
    notvisited = 0
    for nx in mp[vx]:
        if not nx in visited:
            QU.append(nx)
            visited.add(nx)
    pat = pat*fact[nxcnt-1]*ncr(K-2, nxcnt-1)%DVSR

print(pat)


Measured memory_bytes: 85464
//
//  main.cpp
//  AC
//
//  Created by makinofuya on 2019/07/08.
//  Copyright © 2019 makinofuya. All rights reserved.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
typedef long long ll;
using namespace std;
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define out(s) cout << s << endl

int main(){
    ll n,m;cin >>n >> m;
    vector<pair<ll,ll>>a(n,pair<ll,ll>(n,n));
    rep(i,n){
        cin >> a[i].first >> a[i].second;
    }
    sort(a.begin(),a.end());
    ll cost=0;
    ll i=0;
    while(m!=0){
        if(m<a[i].second){
            
            cost+=a[i].first*m;
            m-=m;
        }
        else{
            m-=a[i].second;
            cost+=a[i].first*a[i].second;
        }
        i++;
    }
    out(cost);
    return 0;
}



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

int main(){
    string s[5];
    for(int i=0;i<3;i++) cin>>s[i];
    int t=0;
    while(1){
        if(s[t].empty()){
            cout<<char('A'+t)<<endl;
            return 0;
        }
        char c=s[t][0];
        s[t].erase(s[t].begin()); 
        t=c-'a';
    }
    return 0;
}


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

int main()
{
//    string  n;
//    int cot=0;
//    cin>>n;
//    for(int j=0; j<n.size()-1; j++)
//    {
//        if(n[j] == 'A' || n[j]== 'C' || n[j] =='G' || n[j] =='T')
//        {
//            cot++;
//        }
////        else if(n =="--X" || n=="X--")
////        {
////            flag++;
////        }
//    }
//    cout<<cot<<endl;
//    return 0;
//}
string S;
cin>>S;
int count=0;
int ans=0;
for(int i=0; i<=(int)S.length()-1; i++)
{

    if(S[i]=='A'||S[i]=='T'||S[i]=='C'||S[i]=='G')
    {

        count++;
    }
    else
    {

        if(count>ans)ans=count;
        count=0;
    }
}
if(ans<count)ans=count;
cout<<ans;
return 0;
}


Measured memory_bytes: 3604
n, m = map(int, input().split())
A = [0] * n
B = [0] * n
C = [0] * m
D = [0] * m
for i in range(n):
  A[i], B[i] = map(int, input().split())
for i in range(m):
  C[i], D[i] = map(int, input().split())
for i in range(n):
  min_len = 10**8 * 2 + 1
  min_j = 0
  for j in range(m):
    if abs(A[i] - C[j]) + abs(B[i] - D[j]) < min_len:
      min_len = abs(A[i] - C[j]) + abs(B[i] - D[j])
      min_j = j
  print(min_j + 1)

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

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

int findMin(int a, int b)
{
	if (a <= b) return a;
	else return b;
}

int main()
{
	long long sum = 0;
	int n,max = -1000001,min = 1000001;
	int a[10001];
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		sum += a[i];
		max = findMax(max, a[i]);
		min = findMin(min, a[i]);
	}
	cout << min << " " << max << " " << sum << endl;
}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
#define ll long long int
const int mx = 200010;
int a[mx], b[mx];
void solve()
{
	int n, k;
	cin>>n>>k;
	for(int i=1; i<=n; i++)
		cin>>a[i];
	REP(T, k)
	{
		memset(b, 0, sizeof(b));
		for(int i=1; i<=n; i++)
		{
			int l = max(1, i-a[i]);
			int r = min(n+1, i+a[i]+1);
			b[l]++;
			b[r]--;
		}
		bool pos = true;
		for(int i=1; i<=n; i++)
		{
			b[i]+=b[i-1];
			if(b[i]<n)
			{
				pos = false;
			}
		}
		swap(a,b);
		if(pos)
			break;
	}
	for(int i=1; i<=n; i++)
	{
		cout<<a[i]<<" ";
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 5216
N = int(input())
S = list(input())

flag=0
if N%2==0:
    for i in range(N//2):
        if S[i]==S[i+N//2]:
            continue
        else:
            flag=1

else:
    flag=1

if flag==0:
    print("Yes")
else:
    print("No")


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

int main(){
int a,b;
cin>>a>>b;
if(a%3==0||b%3==0||(a+b)%3==0){
  cout<<"Possible"<<endl;
}
else{
  cout<<"Impossible"<<endl;
}
return 0;
}

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

int main() {
  int n, t, a;
  cin >> n >> t >> a;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  int ans = 0;
  int mn = 1 << 30;
  rep(i, n) {
    int c = t * 1000 - h[i] * 6;
    int dc = abs(1000 * a - c);
    if (dc < mn)  {
      mn = dc;
      ans = i;
    }
  }
  cout << ans + 1 << endl;
  return 0;
}

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

using namespace std;

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

  int n, k;
  cin >> n >> k;
  vector<int> L(n);
  for (auto &l : L) cin >> l;
  sort(L.begin(), L.end());
  int res = 0; 
  for (int i = n-k; i < n; ++i) 
    res += L[i];
  cout << res << endl;

  return 0;
}



Measured memory_bytes: 256
using System;
class MainClass {
	public static void Main(string[] args){
    	int a = int.Parse(Console.ReadLine());
      	int b = int.Parse(Console.ReadLine());
      	int[] ans = { 1,2,3 };
		foreach(var i in ans){
          if(i != a && i != b){
            Console.WriteLine(i);
            break;
          }
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define _C ios::sync_with_stdio(false);cin.tie(0);
#define xx first
#define yy second
#define ERR 0.00000001
#define INF (ll)1<<62
#define nSize 1000000
#define forn for(int i = 0 ; i < n ; i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef complex<double> cp;
typedef vector<cp> polinomio;
typedef long double ld;
const ld PI = acos(-1);


int main()
{_C
	ll n , k;
	ll mx = INF;
	cin >> n >> k;
	vll v(n);
	forn
		cin >> v[i];
	sort(v.begin(),v.end());
	for(int i = k-1 ; i < n ; i++)
	{
		mx = min(v[i]-v[i-k+1],mx);
	}
	cout << mx << '\n';
	
	return 0;
}

Measured memory_bytes: 1024
use std::io::{self, Read};
use std::cmp;

macro_rules! input {
    ($it: expr) => ($it.next().unwrap().parse().unwrap());
    ($it: expr, $T: ty) => ($it.next().unwrap().parse::<$T>().unwrap());
}

fn main() {
    let mut buf = String::new();
    let mut it = {
        io::stdin().read_to_string(&mut buf).unwrap();
        buf.split_whitespace()
    };

    let a: i64 = input!(it);
    let b: i64 = input!(it);
    let c: i64 = input!(it);
    let k: i64 = input!(it);

    let mut ans: i64 = 0;
    let mut r: i64 = k;

    ans += cmp::min(a, r);
    r -= cmp::min(a, r);

    r -= cmp::min(b, r);

    ans -= cmp::min(c, r);

    println!("{}", ans);
}

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

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a.at(i);

    int total = 0;
    for (int i = 0; i < N; i++) total ^= a.at(i);
    for (int i = 0; i < N; i++) {
        int ans = a.at(i) ^ total;
        cout << ans << " ";
    }
    
}


Measured memory_bytes: 4016
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int arare;
  bool isY = false;
  cin >> arare;
  for(int i=0;i<arare;i++){
    char color;
    cin >> color;
    if(color == 'Y'){
      isY = true;
      break;
    }
  }
  if(isY == true){
    cout << "Four" << endl;
  } else {
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

char str[500010];

int main() {
	int ans = 0;
	scanf("%s", str);
	int sp1 = 0, sp2 = strlen(str) - 1;
	while (sp1 < sp2) {
		int t1 = 0, t2 = 0;
		while (str[sp1] == 'x') ++t1, ++sp1;
		while (str[sp2] == 'x') ++t2, --sp2;
		if (str[sp1] != str[sp2]) {
			puts("-1");
			return 0;
		}
		ans += t1 > t2 ? t1 - t2 : t2 - t1;
		++sp1, --sp2;
	}
	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 1808
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <queue>
#include <cmath>
#include <cstdio>

using namespace std;

int main(){
    int h, n; cin >> h >> n;
    int sum=0;
    for(int i=0; i<n; ++i){
        int a; cin >> a;
        sum+=a;
    }
    cout << (sum>=h ? "Yes" : "No") << endl;
    return 0;
}


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

int main(int argc, char *argv[])
{
    int m;
    string line, fr, sc;
    cin >> m;
    while (m--) {
        cin >> line;
        set<string> s;
        s.insert(line);
        for (int i = 1; i < line.size(); ++i) {
            fr = line.substr(0, i);
            sc = line.substr(i, line.size());
            for (int j = 0; j < 2; ++j) {
                for (int k = 0; k < 4; ++k) {
                    s.insert(fr + sc);
                    if (k % 2)
                        reverse(fr.begin(), fr.end());
                    else
                        reverse(sc.begin(), sc.end());
                    s.insert(fr + sc);
                }
                fr.swap(sc);
            }
        }
        cout << s.size() << endl;
    }
    return 0;
}

Measured memory_bytes: 1292
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

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


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

    int dir = 1;
    deque<char> que;
    for(int i = 0; i < s.size(); i++){
        que.push_back(s[i]);
    }

    for(int i = 0; i < q; i++){
        int p;  cin >> p;
        if(p == 1){
            dir = -dir;
        }
        else{
            int f; char c;
            cin >> f >> c;
            if(f == 2){
                f = -1;
            }
            if(f * dir == 1){
                que.push_front(c);
            }
            else{
                que.push_back(c);
            }
        }
    }

    if(dir == 1) {
        while (!que.empty()) {
            cout << que.front();
            que.pop_front();
        }
    }
    else{
        while (!que.empty()) {
            cout << que.back();
            que.pop_back();
        }
    }
    cout << endl;


    return 0;
}


Measured memory_bytes: 896
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define SIZE(x) ((int)(x).size())
#define UQ(v) v.erase(unique(v,begin(),v,end()),v.end());
ll INF = 1LL <<30;
#define pb push_back 
int dxy4[5] = { 0,1,0,-1,0 };
int dxy8[9] = { 0,1,1,0,-1,1,-1,-1,0 };
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
ll mod7 = 1000000007;
ll mod9 = 1000000009;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define FOR(i,x,n) for(int i=x;i<n;++i)
//vector< vector<int> > v (max1, vector<in t>(max2) );

int a[31] = {};


int main() {
	int a;
	cin >> a;
	int b = a,c=0;
	while (a) {
		c += a % 10;
		a /= 10;
	}
	if (b % c==0)cout << "Yes" << endl;
	else cout << "No" << endl;
	int n;
	cin >> n;
	
	return 0;
}

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

const int MAX = 2e5;
const ll mod = 1e9+7;

ll 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] * (ll)i % mod;
        inv[i] = mod - inv[mod%i] * (mod/(ll)i) % mod;
        finv[i] = finv[i-1] * inv[i] % mod;
    }
}

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

int main(){
    COMinit();
    int n;
    cin >> n;
    vector<int> v(n+1,-1);
    int p, q;
    rep(i,n+1) {
        int a;
        cin >> a;
        if(v[a] == -1) v[a] = i+1;
        else {
            p = v[a]; q = i+1;
        }
    }
    for(int i = 1; i <= n+1; i++){
        ll ans = (COM(n+1,i) - COM(n-q+p,i-1) + mod) % mod;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 6272
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let x1 = v[0];
	let y1 = v[1];
	let x2 = v[2];
	let y2 = v[3];
	println!("{} {} {} {}", x2 - (y2 - y1), y2 + (x2 - x1), x1 - (y2 - y1), y1 + (x2 - x1));
}

Measured memory_bytes: 4352
from collections import defaultdict
from string import ascii_uppercase
import sys, bisect, math
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N = read_int()[0]
H = read_int()

def solve():
    ans = 1
    mh = H[0]
    for i in range(1, N):
        cansee = True
        for j in range(0, i):
            if H[j] > H[i]:
                cansee = False
                break
        if cansee:
            ans += 1
    return ans

if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 4016
import copy

s = input()
dp = [0 for i in range(13)]
dp[0] = 1
num = 0
c = 1000000007
mul = 1
for i in range(len(s) - 1, -1, -1):
    nextdp = [0 for i in range(13)]
    if s[i] == '?':
        for j in range(10):
            for k in range(13):
                nextdp[(j * mul + k) % 13] += dp[k]
                nextdp[(j * mul + k) % 13] %= c
    else:
        j = int(s[i])
        for k in range(13):
            nextdp[(j * mul + k) % 13] += dp[k]
            nextdp[(j * mul + k) % 13] %= c
    dp = copy.copy(nextdp)
    mul *= 10
    mul %= 13

print(dp[5])


Measured memory_bytes: 44524
#include <bits/stdc++.h>
using namespace std;
int times2(int n) {
    int num = 1;
    for (int i = 0; i < n; i++) {
        num *= 2;
    }
    return num;
}

int main() {
    int N;
    int maximum = 0; // 2で割り切れる最大回数
    cin >> N;
    for (int i = 1; i <= N; i++) {
        int count = 0; // 2で割り切れる回数
        int tmp = i;
        while (tmp % 2 == 0) { // 2で何回割り切れるか
            tmp /= 2;
            count++;
        }

        maximum = max(maximum, count);
    }

    cout << times2(maximum) << endl;
    return 0;
}

Measured memory_bytes: 256
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
vector<ll> tree[200010];
vector<int> euler;
int v_begin[200010] = {}, v_end[200010] = {};
int idx = 0;

// void dfs(int cur, int par){
//     v_begin[cur] = idx;
//     euler.push_back(cur);
//     idx++;
//     for(auto &e: tree[cur]){
//         if(e == par) continue;
//         dfs(e, cur);
//         euler.push_back(cur);
//         idx++;
//     }
//     v_end[cur] = idx;
// }

ll ans[200010] = {};
ll dp[200010];
ll a[200010];
ll N;

void dfs2(ll cur, ll par){
    ll pos = lower_bound(dp, dp+N, a[cur]) - dp;
    ll prev_val = dp[pos];
    // if(cur == 8) printa(dp, N);
    dp[pos] = a[cur];
    // ans[cur] = pos+1;
    // if(cur == 8) printa(dp, N);
    int lv = 0, rv = N+1;
    while(rv - lv > 1){
        int mid = (rv + lv) / 2;
        if(dp[mid] == INF){
            rv = mid;
        }else{
            lv = mid;
        }
    }
    ans[cur] = lv + 1;

    for(auto &e: tree[cur]){
        if(e == par) continue;
        dfs2(e, cur);
    }
    dp[pos] = prev_val;
}



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    rep(i,0,N) cin >> a[i];
    vector<ll> v;
    v.push_back(-INF);
    v.push_back(INF);
    rep(i,0,N) v.push_back(a[i]);
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    rep(i,0,N){
        a[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin();
    }
    rep(i,0,N-1){
        ll u,v;
        cin >> u >> v;
        u--; v--;
        tree[u].push_back(v);
        tree[v].push_back(u);
    }
    // dfs(0,-1);
    // ll sz = euler.size();
    // printa(euler, sz);
    rep(i,0,N+10) dp[i] = INF;
    dfs2(0, -1);
    rep(i,0,N) print(ans[i]);




    

}

Measured memory_bytes: 34796
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define FORN(i, x, y) for (int i = x; i <= y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define scan1(X) scanf("%d", &X)
#define scan2(X, Y) scanf("%d%d", &X, &Y)
#define scan3(X, Y, Z) scanf("%d%d%d", &X, &Y, &Z)
#define scan4(X, Y, Z, W) scanf("%d%d%d%d", &X, &Y, &Z, &W)
#define scanl1(X) scanf("%lld", &X);
#define scanl2(X, Y) scanf("%lld%lld", &X, &Y)
#define scanl3(X, Y, Z) scanf("%lld%lld%lld", &X, &Y, &Z)
#define scanl4(X, Y, Z, W) scanf("%lld%lld%lld%lld", &X, &Y, &Z, &W)
#define print1(X) printf("%d\n", X);
#define print2(X, Y) printf("%d %d\n", X, Y);
#define print3(X, Y, Z) printf("%d %d %d\n", X, Y, Z);
#define print4(X, Y, Z, W) printf("%d %d %d %d\n", X, Y, Z, W);
#define printl1(X) printf("%lld\n", X);
#define printl2(X, Y) printf("%lld %lld\n", X, Y);
#define printl3(X, Y, Z) printf("%lld %lld %lld\n", X, Y, Z);
#define printl4(X, Y, Z, W) printf("%lld %lld %lld %lld\n", X, Y, Z, W);
#define max3(X, Y, Z) max(X, max(Y, Z))
#define max4(X, Y, Z, W) max(max(X, Y), max(Z, W))
#define min3(X, Y, Z) min(X, min(Y, Z))
#define min4(X, Y, Z, W) min(min(X, Y), min(Z, W))
#define popcount(X) __builtin_popcount(X)
#define all(x) x.begin(), x.end()
#define size(X) (int)X.size()
#define mp make_pair
#define pb push_back
#define fr first
#define sc second
#define lc(x) 2 * x
#define rc(x) 2 * x + 1
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<ld, ld> pldld;
const long long l_inf = numeric_limits<long long>::max();
const long long l_ninf = numeric_limits<long long>::min();
const int inf = numeric_limits<int>::max();
const int ninf = numeric_limits<int>::min();
const double pi = 1.00 * acos(-1.00);
const double eps = 1e-8;
void cio(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
ll gcd(ll a, ll b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return (a * (b / gcd(a, b))); }
int sq( int x ) {return x * x;}
////////////////////////////////////////////////////////////////////Header
const int maxn = 1e5 + 5;
int dist[maxn], indeg[maxn];
int n, m;
vector<int> graph[maxn];

int main () {
    scan2(n, m);
    FORN(i, 1, m) {
        int u, v;
        scan2(u, v);
        indeg[v]++;
        graph[u].pb(v);
    }
    queue<int> q;
    FORN(i, 1, n) if ( !indeg[i] ) q.push(i);
    int ans = 0;
    while ( !q.empty() ) {
        int u = q.front();
        q.pop();
        ans = max(ans, dist[u]);
        for ( auto v : graph[u] ) {
            dist[v] = dist[u] + 1;
            if ( --indeg[v] == 0 ) q.push(v);
        }
    }  
    print1(ans);
}

Measured memory_bytes: 9856
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <tuple>
#include <cassert>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define mp(a,b) make_pair((a), (b))
#define mt(a,b,c) make_tuple((a),(b),(c))

typedef long long ll;

int main(){
    int h,w,n;
    cin >> h >> w >> n;
    if(h < w) swap(h,w);

    if(n % h == 0) cout  << n / h << endl;
    else cout << n / h + 1 << endl;
    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    string s,t;
    cin >> s >> t;
    int cnt = 0;
    for(int i = 0;i < s.size();i++){
        if(s[i] == t[i]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <tuple>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(perm),end(perm)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
    int n;cin>>n;
    int ans;
    REP(i,9){
        if(111*i>=n){ans = 111*i; break;}
    }
    cout<<ans<<endl; return 0;
}


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


int main()
{
	string s;
	cin >> s;
	int max_ = 0;
	int i = 0;
	int idx=0;
	while (i < s.size())
	{
		if (s[i] == 'R')
		{
			idx++;
			i++;
		}
		else
		{
			if (max_ < idx) max_ = idx;
			idx = 0;
			i++;
		}
	}
	if (max_ < idx) max_ = idx;
	cout << max_;
	return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>

using namespace std;


int main() {
  int n;

  std::cin >> n;

  long long q, a, b, m;
  m = 0;
  multiset<long long> l, r;

  std::cin >> q >> a >> b;
  m += b;
  r.insert(a);
  l.insert(a);

  for (int i = 0; i < n-1; i++) {
    std::cin >> q;
    if (q == 1) {
      std::cin >> a >> b;
      m += b;
      if (*(--(l.end())) > a) {
        m += *(--(l.end())) - a;
        r.insert(*(--(l.end())));
        l.erase(--(l.end()));
        l.insert(a);
        l.insert(a);
      } else if (*(r.begin()) > a) {
        r.insert(a);
        l.insert(a);
      } else {
        m += a - *(r.begin());
        l.insert(*(r.begin()));
        r.erase(r.begin());
        r.insert(a);
        r.insert(a);
      }
    } else {
      std::cout << *(--(l.end())) << " " << m << std::endl;
    }
  }

  return 0;
}


Measured memory_bytes: 18944
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <set>
#include <bitset>
typedef long long ll;
typedef long double ld;
#define PI  3.14159265358979323846

#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
    ll N, M;
    vector<ll>A;
    cin >> N >> M;
    string ans = "Yes";
    ld all = 0;
    rep(i,N) {
        ll a;
        cin >>a;
        all += a;
        A.push_back(a);
    }
    sort(A.begin(),A.end(),std::greater<ll>());
    rep(i,M) {
        if (A[i]<(all/(4.0*(ld)M))) {
            ans = "No";
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;

#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])

#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

#define ALL(obj) (obj).begin(),(obj).end()

#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
cin>>head;
CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision; // cpp_int

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define L list<int>

#define pb(a) push_back(a)
#define mp make_pair

int main(){
  CIN(n);V a(n);V b(n);VECCIN(a);VECCIN(b);
  
  bool flag=true;
  ll stock=0;
  if(accumulate(ALL(a),0LL)>accumulate(ALL(b),0LL))flag=false;
  REP(i,n){
    if(a[i]<b[i])stock+=(b[i]-a[i])/2;
    else if(a[i]>b[i])stock-=a[i]-b[i];
  }
  if(stock<0)flag=false;

  Yes(flag);

  return 0;
}


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

void solve(long long N, std::vector<long long> a){
    ll ans =0;
    for(int i=0;i<N;i++){
        if(i%2==0){
            if(a[i]%2==1){
                ans ++;
            }
        }
    }
    cout << ans << endl;

}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 3688
import java.util.Scanner;

public class Main {
  public static void main(String[] args){
    new Main();
  }
  public Main(){
    Scanner sc = new Scanner(System.in);
    while(true){
      int w = sc.nextInt();
      int h = sc.nextInt();
      if(h==0 && w==0)break;
      int[][] dp = new int[h][w];
      dp[0][0] = 1;
      int n = sc.nextInt();
      while(n-->0){
        int x = sc.nextInt();
        int y = sc.nextInt();
        dp[y-1][x-1] = -1;
      }
      for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
          if(dp[i][j]==-1)continue;
          if(i<h-1 && dp[i+1][j]!=-1) dp[i+1][j] += dp[i][j];
          if(j<w-1 && dp[i][j+1]!=-1) dp[i][j+1] += dp[i][j];
        }
      }
      System.out.println(dp[h-1][w-1]);
    }
  }
}

Measured memory_bytes: 26408
const input = require('fs').readFileSync('/dev/stdin', 'utf8').split(/\n/);
let [a, b] = input[0].split(' ').map(Number);
let bmat = [];
 for (let j = a + 1; j <= (a+b); j++) {
    bmat.push(Number(input[j]));
 }
 
 for (let i = 1; i <= a; i++) {
     let tmp = [];
     let matrix = input[i].split(' ').map(Number);
     for (let j = 0; j < b; j++) {
        tmp.push(matrix[j] * bmat[j]);
     }
    sum = tmp.reduce((a,x) => a+=x,0);
     console.log(sum);
 }
     


Measured memory_bytes: 17548
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input())
    A = int(input())
    
    print(N*N - A)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572