akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc044/tasks/arc060_a

"""
import sys
from sys import stdin
input = stdin.readline


def solve(N, A, cards):
    ans = 0
    cards.append(0)
    cards.sort()
    W = sum(cards)

    # dp[j][k][s]: j番目までのカードをk枚使って合計をsにする組み合わせ
    dp = [[[0] * (W+1) for _ in range(N+1)] for _ in range(N+1)]
    for j in range(N+1):
        dp[j][0][0] = 1

    for j in range(1, N+1):
        card = cards[j]
        for k in range(1, N+1):
            for s in range(1, W+1):
                if s < card:
                    dp[j][k][s] = dp[j-1][k][s]
                else:
                    dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-card]

    for k in range(1, N+1):
        if k*A <= W:
            ans += dp[N][k][k*A]
    return ans


def main(args):
    N, A = map(int, input().split())
    cards = [int(x) for x in input().split()]
    ans = solve(N, A, cards)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


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

using namespace std;

int main(){
  int N;
  cin >> N;
  
  vector<int> X(N);
  for(int i = 0; i < N; i++){
    cin >> X[i];
  }
  
  int a = 1000000000;
  for(int i = 0; i < 100; i++){
    int s = 0;
    for(int j = 0; j < N; j++){
      s += (X[j] - i) * (X[j] - i);
    }
    a = min(s, a);
  }
  
  cout << a << endl;
  
  return 0;
}

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

const int A = 1000005;

int gcd(int x, int y){
    int r;
    if(x<y) swap(x,y);
    while(y>0){
        r = x % y;
        x = y;
        y = r;
    }
    return x;
}

int main(void){
    // Your code here!
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> c(A);
    for(int i=0;i<n;i++){
        cin >> a.at(i);
        c[a[i]]++;
    }
    bool pairwise = true;
    for(int i=2;i<A;i++){
        int cnt = 0;
        for(int j=i;j<A;j+=i){
            cnt += c[j];
        }
        if(cnt>1){
            pairwise = false;
        }
    }
    if(pairwise){
        cout << "pairwise coprime" << endl;
        return 0;
    }
    
    int g = 0;
    for(int i=0;i<n;i++){
        g = gcd(g, a[i]);
    }
    if(g==1){
        cout << "setwise coprime" << endl;
        return 0;
    }
    cout << "not coprime" << endl;
    return 0;
}


Measured memory_bytes: 11176
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f first
#define s second

#define files1 freopen("input.txt","r",stdin)
#define files2 freopen("output.txt","w",stdout)
#define files files1;files2
#define files3 freopen("input.txt","r",stdin)
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0)

#define mp make_pair
#define pb push_back

#define vi vector<int>
#define pii pair<int,int>

#define all(x) (x).begin(), (x).end()
#define fill(x) memset((x), 0, sizeof((x)))

#define ii input<int>()
#define ill input<ll>()
#define endl '\n'

using namespace std;

void bad(string mes = "impossible"){cout << mes;exit(0);}

template<typename T>
string bin(T x, int st = 2){
	string ans = "";
	while (x > 0){
	    ans += char('0' + x % st);
	    x /= st;
	}
	reverse(ans.begin(), ans.end());
	return ans.empty() ? "0" : ans;
}

template<typename T>
T dcm(string & s)
{
	T x = 0;
	for (int i = 0; i < s.size(); i++){
	    x = (x * 2) + (s[i] == '1');
	}
	return x;
}
template<typename T>
T input(){
	T ans = 0, m = 1;
	char c = ' ';
	while (c == ' ' || c == '\n')
	    c = getchar();
	if (c == '-')
	    m = -1, c = getchar();
	while (c >= '0' && c <= '9'){
	    ans = ans * 10 + int(c - '0'), c = getchar();
	}
	return ans * m;
}
template<typename T>
T binpow(T n, T s)
{
	if (s <= 0)
	    return 1LL;
	if (s % 2 == 0){
	    T b = binpow(n, s / 2);
	    return ( 1LL * b * b );
	} else {
	    return (1LL* binpow(n, s - 1) * n);
	}
}

const int inf = 2e9;
const double eps = 1e-9;
const int maxn = 4000, base = 1e9 + 7;
const ll llinf = 1e18;
int main(){
	//files1;
	string s;
	cin>>s;
	for(int i=0;i<((int)s.size()-8);i++)
		cout<<s[i];
	return 0;
}


Measured memory_bytes: 256
open System.Collections.Generic

type Scanner() = class
    let mutable hold = [||]
    let mutable index = 0
    member public this.Next() =
        if hold.Length > index
        then 
            index <- index + 1
            hold.[index - 1]
        else
            let mutable st = stdin.ReadLine()
            while st = "" do st <- stdin.ReadLine()
            hold <- st.Split(' ')
            if hold.Length = 0
            then
                this.Next()
            else
                index <- 1
                hold.[index - 1]
            
    member public this.NextI32() =
        this.Next() |> int

    member public this.ArrayI32(n: int) =
        [|for _ in 0 .. n - 1 -> this.NextI32()|]

    member public this.IArrayI32(n: int) =
        [|for i in 0 .. n - 1 -> this.NextI32(), i|]

    member public this.NextI64() =
        this.Next() |> int64
    
    member public this.ArrayI64(n: int) =
        [|for _ in 0 .. n - 1 -> this.NextI64()|]

    member public this.IArrayI64(n: int) =
        [|for i in 0 .. n - 1 -> this.NextI64(), i|]

    member public this.NextF32() =
        this.Next() |> float32
    
    member public this.ArrayF32(n: int) =
        [|for _ in 0 .. n - 1 -> this.NextF32()|]

    member public this.IArrayF32(n: int) =
        [|for i in 0 .. n - 1 -> this.NextF32(), i|]

    member public this.NextF64() =
        this.Next() |> double
    
    member public this.ArrayF64(n: int) =
        [|for _ in 0 .. n - 1 -> this.NextF64()|]

    member public this.IArrayF64(n: int) =
        [|for i in 0 .. n - 1 -> this.NextF64(), i|]

    member public __.Tuple2Array n (f : int -> 'a list) =
        [|for _ in 0 .. n - 1 -> f 2 |> fun x -> x.[0], x.[1]|]
    
    member public __.Tuple3Array n (f : int -> 'a list) =
        [|for _ in 0 .. n - 1 -> f 3 |> fun x -> x.[0], x.[1], x.[2]|]

    member public __.CountDic n (f : unit -> 'a) =
        let seqs = seq {for _ in 0 .. n - 1 -> f()}
        let dic = new Dictionary<'a, int64>();
        for i in seqs do
            if dic.ContainsKey(i)
            then dic.[i] <- dic.[i] + 1L
            else dic.Add(i, 1L)
        dic

end

[<EntryPoint>]
let main _ =
#if DEBUG
    printfn "debuged"
#endif

    let scanner = Scanner()
    let n = scanner.NextI32()
    let arr = scanner.ArrayI32(n)
    arr
    |> Array.where (fun x -> x % 2 = 0)
    |> Array.where (fun x -> x % 3 <> 0 && x % 5 <> 0)
    |> Array.length
    |> fun x -> if x = 0 then "APPROVED" else "DENIED"
    |> printfn "%s"

    0


Measured memory_bytes: 14044
use std::io::*;
use std::str::*;
use std::collections::HashMap;

fn main() {
    let mut map = HashMap::new();
    map.insert("Sunny".to_string(), "Cloudy".to_string());
    map.insert("Cloudy".to_string(), "Rainy".to_string());
    map.insert("Rainy".to_string(), "Sunny".to_string());
    let key: String = read();
    println!("{}", map.get(&key).unwrap());
}

fn read<T: FromStr>() -> T {
    let mut line: String = String::new();
    stdin().read_line(&mut line).ok();
    line.trim().parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;

int a, b;

int main(){
    cin >> a >> b;
    vector<int> v;

    v.push_back(a+b);
    v.push_back(a-b);
    v.push_back(a*b);

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

    cout << *(v.end()-1);


}

//g++ -std=c++14 comp.cpp; ./a.exe


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


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

    if(a <= b){
        if(a+W < b){
            cout << b - a - W << endl;
            return 0;
        }else{
            cout << 0 << endl;
        }
    }else{
        if(b+W < a){
            cout << a - b - W << endl;
            return 0;
        }else{
            cout << 0 << endl;
        }
    }

}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
long long nCr(long long n,long long r){
    long long ans=1;
    rep(i,r) ans=ans*(n-i)/(i+1);
    return ans;
}
int main(){
    long long n,a,b,c,v[50],ans=0;
    double ave=0,x;
    map<long long,int> num;
    cin>>n>>a>>b;
    rep(i,n) cin>>v[i],num[v[i]]++;
    sort(v,v+n,greater<long long>());
    rep(i,a) ave+=v[i];
    ave=ave/a;
    for(int i=a;i<=b;i++){
        if(i>a&&v[0]!=v[i-1]) break;
        c=0;
        rep(j,i) if(v[j]==v[i-1]) c++;
        ans+=nCr(num[v[i-1]],c);
    }
    cout<<setprecision(10)<<ave<<endl<<ans;
}

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

using namespace std;

int N, M;
vector<vector<int>> G;
vector<int> dp;

int f(int u) {
  if (dp[u] != -1) return dp[u];

  int res = 0;
  for (int v : G[u]) {
    res = max(res, f(v) + 1);
  }

  return dp[u] = res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  G.resize(N), dp.resize(N, -1);
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    G[x].emplace_back(y);
  }

  int res = 0;
  for (int i = 0; i < N; i++) {
    res = max(res, f(i));
  }

  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    string s; cin>>s;
    int n=s.size();
    int64_t ans=0,a=0;
    for(int i=0;i<n-1;i++){
        if(s[i]=='A') a++;
        else if(s[i]=='B'&&s[i+1]=='C'){
            ans+=a;
            i++;
        }
        else a=0;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
#include <numeric>
#include <iterator>
typedef long long int ll;
using namespace std;
int main(){
	vector<int> x,y;
	int n,m,s;
	
	cin >> n>>m;
	for(int i=0;i<m;i++){
		cin>>s;
		x.push_back(s);
	}
	sort(x.begin(),x.end());
	for(int i=0;i<m-1;i++){
		y.push_back(x[i+1]-x[i]);
	}
	sort(y.begin(),y.end());
	if(n>=m){
		cout<<0<<endl;
	}else{
		cout<<accumulate(y.begin(),prev(y.end(),n-1),0)<<endl;
	}
}

Measured memory_bytes: 1400
#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 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 ps push_back
#define fs first
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
ll v=-1;
void dfs(vector< pair<ll,ll> > vc[],ll i,ll fl[]){
	fl[i]=1;

	ll j,k=0;
	for(j=0;j<vc[i].size();j++){
		if(fl[vc[i][j].fs]==0){
			k++;
			dfs(vc,vc[i][j].fs,fl);
		}
	}
	if(k==0){
		if(v==-1) v=i;
	}
}
ll cl[100001];
void dfs2(vector< pair<ll,ll> > vc[],ll i,ll fl[],ll s){
	fl[i]=1;

	if(s%2==0){
		cl[i]=0;
	}
	else {
		cl[i]=1;
	}
	ll j;
	for(j=0;j<vc[i].size();j++){
		if(fl[vc[i][j].fs]==0){
			dfs2(vc,vc[i][j].fs,fl,s+vc[i][j].sc);
		}
	}
}
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n;
	cin>>n;

	vector< pair<ll,ll> > vc[n+1];
	ll a,b,c;
	for(i=1;i<n;i++){
		cin>>a>>b>>c;
		vc[a].ps({b,c});
		vc[b].ps({a,c});
	}
	
	ll fl[n+1]={0};
	dfs(vc,1,fl);

	memset(fl,0,sizeof(fl));
	dfs2(vc,v,fl,0);

	for(i=1;i<=n;i++){
		cout<<cl[i]<<endl; 
	}
	return 0;
}


Measured memory_bytes: 11008
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
char hoge[]="abcdefghijklmnopqrstuvwxyz";
int main(){
    int n; cin>>n;
    vector<string>s;
    rep(i,n){
        string t; cin>>t;
        s.push_back(t);
    }
    vvi v(n,vi(29,0));
    rep(i,n)rep(j,s[i].size()){
        v[i][s[i][j]-'a']++;
    }
    string ans;
    for(int i=0; i<27; i++){
        int j=0;
        int cnt=v[j][i];
        for(; j<n;j++){
            cmin(cnt,v[j][i]);
        }
        if(!cnt)continue;
        rep(k,cnt)
        ans.push_back(hoge[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    cin >> N;
    int A[N];
    rep(i,N) {
        cin >> A[i];
    }
    sort(A,A+N);
    reverse(A,A+N);
    long long ans=1;
    int cou=0;
    for(int i=0;i<N;i++){
        if(A[i]==A[i+1]){
            ans*=A[i];
            cou++;
            i++;
        }
        if(cou==2) break;
    }
    if(cou<2) ans=0;
    cout << ans<< endl;


}


Measured memory_bytes: 640
import sys

input=sys.stdin.readline

N=int(input())
edge=[]
ans=0
for i in range(N-1):
    u,v=map(int,input().split())
    u,v=min(u-1,v-1),max(u-1,v-1)
    ans-=(u+1)*(N-v)

for i in range(1,N+1):
    ans+=(N-i+1)*(N-i+2)//2

print(ans)


Measured memory_bytes: 73836
#include <bits/stdc++.h> 
using namespace std;
 
int main() {
  
  double w,h,x,y;
  cin>>w>>h>>x>>y;
 
  cout<<w*h/2.0<<endl;
  
  if (w/2==x && h/2==y) {
	cout<<1<<endl;
  }
  else {
	cout<<0<<endl;
  }
  
}

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

int main(){
	int a,b,c,buf;
	cin >> a >> b >> c;
	if(a>b){
		buf=a;
		a=b;
		b=buf;
	}
	if(b>c){
		buf=b;
		b=c;
		c=buf;
	}
	if(a>b){
		buf=a;
		a=b;
		b=buf;
	}
	cout << a << " "<< b << " " << c << endl;
	
	return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e4;

vector<vector<int>> graph;
vector<int> d;

void DFS(int v, int prev_v, int c){
    if(d[v] < c) return ;
    d[v] = c;

    for(int next_v : graph[v]){
        if(next_v != prev_v){
            DFS(next_v, v, c+1);
        }
    }
    return ;
}

int main(){
    int n, x, y;
    cin >> n >> x >> y;
    graph.resize(n);
    x -= 1;
    y -= 1;

    for(int i=0; i<n; i++){
        if(i+1 <  n) graph[i].push_back(i+1);
        if(i-1 >= 0) graph[i].push_back(i-1);
    }
    graph[x].push_back(y);
    graph[y].push_back(x);

    vector<int> ans(n);
    for(int i=0; i<n; i++){
        d.assign(n, INF);
        DFS(i, -1, 0);
        for(int j=0; j<n; j++){
            ans[d[j]] += 1;
        }
    }

    for(int i=1; i<n; i++){
        cout << ans[i] / 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll a,b,c;
	cin>>a>>b;
	if(a%3==0 || b%3==0 ||(a+b)%3==0)cout<<"Possible"<<endl;
	else cout<<"Impossible"<<endl;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int n;
	
	cin >> n;
	
	for (int i = 0; i < n; i++){
		int c, a, n;
		int team = 0;
		
		cin >> c >> a >> n;
		while (c > 0){
			if (n > 0 && a > 0 && c > 0){
				team++;
				n--;
				a--;
				c--;
			}
			else if (c > 1 && a > 0){
				team++;
				c -= 2;
				a--;
			}
			else {
				team += c / 3;
				c = 0;
			}
		}
		cout << team << endl;
	}
	
	return (0);
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
typedef pair<pll, pll> P;
const ll INF = 1ll<<30;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int N;
vector<int> b;

int main() {
	cin >> N;
	b.resize(N);
	REP(i, N) scanf("%d", &b[i]);
	
	vector<int> ans;
	while (ans.size() < N) {
		bool ok = false;
		for (int i = (int)b.size() - 1; i >= 0; i--) {
			if (b[i] == i + 1) {
				ans.push_back(b[i]);
				b.erase(b.begin() + i);
				ok = true;
				break;
			}
		}
		
		if (!ok) break;
	}
	
	if (ans.size() == N) {
		reverse(ALL(ans));
		REP(i, N) printf("%d\n", ans[i]);
	}
	else puts("-1");
	
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int L = sc.nextInt();
        String[] S = new String[N];
        for (int i = 0; i < N; ++i) {
            S[i] = sc.next();
        }
        sc.close();

        Arrays.sort(S);
        String ans = "";
        for (int i = 0; i < N; ++i) {
            ans += S[i];
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 24276
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a[200009],b[200009];
main(){
    ll n,m,k;
    cin >> n>>m>>k;
    for(ll i =1; i <= n; i++)
        cin >> a[i],
        a[i] += a[i-1];
    for(ll i= 1; i <= m; i++)
        cin >> b[i],
        b[i] += b[i-1];
    ll lo = 0, hi = n + m;
    while(lo < hi){
        ll mid = (lo + hi+1)/2;
        ll x = k+1;
        for(ll i = 0; i <= n; i++)
            if(i <= mid && mid - i <= m)
                x = min(x, a[i] + b[mid - i]);
        if(x <= k) lo = mid;
        else hi = mid-1;

    }
    cout<<lo<<endl;
}


Measured memory_bytes: 6740
#include<bits/stdc++.h>
#define lli long long
#define all(i) i.begin(),i.end()
#define rep0(i,j) for(int i=0;i<j;i++)
#define rep1(i,j) for(int i=1;i<=j;i++)
using namespace std;
bool cmpf(const pair<lli, lli> left, const pair<lli, lli> right) {
  	return left.first< right.first;
}

int main(){
  int n;
  cin >> n;
  vector<lli> vec(n), base(n);
  rep0(i,n)cin >> vec[i];
  base = vec;
  sort(all(vec));
  vector<pair<lli, lli>> veccount;
  veccount.emplace_back(vec[0], 1);
  sort(all(veccount), cmpf);
  rep1(i,n-1){
    if(veccount.back().first == vec[i]){
      veccount.back().second++;
    }else {
      veccount.emplace_back(vec[i], 1);
    }
  }
  lli num=0;
  for(auto e:veccount){
    num += e.second*(e.second-1)/2;
  }

  rep0(i,n){
    auto place = lower_bound(all(veccount), make_pair(base[i],0), cmpf);
    printf("%lld\n", num-(*place).second*((*place).second-1)/2+((*place).second-1)*((*place).second-2)/2);
  }

  return 0;

}

Measured memory_bytes: 6896
a,b,o,x;main(){char s[9];for(;~scanf("%d,%s",s,s);)s[0]-'B'?s[0]-'O'?s[1]-'B'?a++:x++:o++:b++;printf("%d\n%d\n%d\n%d\n",a,b,x,o);exit(0);}

Measured memory_bytes: 0
S = input()
gx, gy = map(int, input().split())

Move = [len(s) for s in S.split('T')]
Move_X = Move[::2]
Move_Y = Move[1::2]


reached_X = {Move_X[0]}
for mx in Move_X[1:]:
    tmp = set()
    for rx in reached_X:
        tmp.add(rx + mx)
        tmp.add(rx - mx)
    reached_X = tmp

reached_Y = {0}
for my in Move_Y:
    tmp = set()
    for ry in reached_Y:
        tmp.add(ry + my)
        tmp.add(ry - my)
    reached_Y = tmp


print('Yes' if ((gx in reached_X) and (gy in reached_Y)) else 'No')


Measured memory_bytes: 48860
main = do
  s <- getLine
  let n = length s
  let s_1 = take (ceiling ((fromIntegral n - 1) / 2)) s
  let s_2 = drop (ceiling ((fromIntegral n + 3) / 2) - 1) s
  if ck s s_1 s_2 == True
    then putStrLn "Yes"
    else putStrLn "No"

ck :: String -> String -> String -> Bool
ck s1 s2 s3 = and [s1 == reverse s1, s2 == reverse s2, s3 == reverse s3]

Measured memory_bytes: 508
n,k,q=map(int,input().split())
a=[]
[a.append(int(input())-1) for _ in range(q)]
i=[k-q]*n

for l in range(q):
    i[a[l]] += 1

for l in range(n):
    if i[l] <= 0:
        print("No")
    else:
        print("Yes")


Measured memory_bytes: 61784
#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[i];
  long ans=10000000;
  for(int i=1;i<=100;i++){
    long dis=0;
    for(int j=0;j<N;j++){
	dis+=(A[j]-i)*(A[j]-i);
    }
    ans=min(ans,dis);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
/*----------------by syr----------------*/
/*

         iii                  ii
     rBQBBBBBBE       BBR iBBBBQBBL     XBBBBBBQBBBBB
   iBBQJ    7BBB      BBsSBBr   BBQ      i      cBBB
  rBBU       iBBw     BBBQi     HBBi           KBBi
  BBH         BB5    iBBB       isL          wBB5
 GBB         iBBi    6BB                   iBBB
 BBQ         BQB     BBD                  QBBi
 BBB        BQB     iQBi                1BBv
 sBBg     wBBB      QBB               iBBB
  7BBBBBBBBBi       BBR              wBBBBBBBBBBBBB
     irvi           ii               ii    i i iii
                i5U
               BBB
               BB7
              1BB
      iPBBBBBKBBR    JBR1       rQBO   BR  UBQP  iBBQi
    7BBBGs7sXBBBi     QBBr     gBBE   rBB BB2BB7HBZQBB
   QBBi      sBQ       BBB   iBBB     SQBBR  BBBB  cBQ
  gBQ        BBg        BBB KBBi      MBBH   BBB   BBs
 iBBv       iBBi         QBBBL        BBR   pBB   iBB
 pBB        BBB         iBBBB        iBB    BBL   KBB
 MBB       BBBR        BBB JBBi      DBR   iBQ    BBL
 GBB     7BBBB2      PBBH   BBBi     BQr   DBB   iBB
  BQBXwgBBP BB7    1BBB      BBQ7   1BB    BBc   BBB
   2BBBBw   BB    EBBS        QBBi  HBa   iBB    BB7
*/
#include<bits/stdc++.h>

using namespace std;

#define PH push
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define x0 x0123456789
#define y0 y0123456789
#define x1 x1234567890
#define y1 y1234567890
#define x2 x2345678901
#define y2 y2345678901
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9 + 7;
const int maxn = 2e5 + 5;

int n;
int dp[maxn];
ll ans;
char s[maxn];

int main(){
	scanf("%s", s);
	n = strlen(s);
	dp[n] = 0;
	for(int i = n - 1; i >= 0; --i){
		if(i + 1 < n && s[i] == 'B' && s[i + 1] == 'C')
			dp[i] = max(dp[i], dp[i + 2] + 1);
		else if(s[i] == 'A')
			dp[i] = max(dp[i], dp[i + 1]);
	}
/*	FOR(i, 0, n)
		printf("%d ", dp[i]);
	puts("");
*/	FOR(i, 0, n) if(s[i] == 'A')
		ans += dp[i];
	printf("%lld\n", ans);
	return 0;
}



Measured memory_bytes: 1280
#include<iostream>

using namespace std;

int main()
{
 int A,B,C;
 cin >> A >> B >> C;
 if(A>=B){
	if(B>C) cout << A*10+B+C <<endl;
	if(C>A) cout << C*10+A+B <<endl;
	if(A>=C&&C>=B) cout << A*10+C+B<<endl;
 }
 if(B>A){
	if(A>C) cout << B*10+A+C <<endl;
	if(C>B) cout << C*10+B+A <<endl;
	if(B>=C&&C>=A) cout <<B*10+C+A<<endl;
 }
 return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cerr<<' ';cerr<<elem;}cerr<<endl;}

struct Edge{int to,w;};

vector<vector<Edge> > e;
vi ans;

void dfs(int v){//vのお隣さんを更新.
	//debug(v);
	for(auto elem:e[v]){
		int to=elem.to;
		int w=elem.w;
		//debug(to);
		if(ans[to]==-1){
			ans[to]=(w&1?(ans[v]+1)%2:ans[v]);
			dfs(to);
		}
	}
}

int main(){
	int n;
	cin>>n;
	
	e.resize(n);
	REP(i,n-1){
		int u,v,w;
		cin>>u>>v>>w;
		u--, v--;
		e[u].push_back({v,w});
		e[v].push_back({u,w});
	}
	
	ans.assign(n,-1);
	ans[0]=0;
	dfs(0);
	
	for(auto elem:ans) cout<<elem<<endl;
}

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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }

struct rule {
  int l, x;
};

void solve() {
  int N, M;
  cin >> N >> M;
  vector<vector<rule>> R(N + 1);
  for (int i = 0; i < M; i++) {
    int l, r, x;
    cin >> l >> r >> x;
    R[r].push_back({l, x});
  }
  
  const int mod = 1e9 + 7;
  vector<vector<vector<ll>>> dp(N + 1, vector<vector<ll>>(N + 1, vector<ll>(N + 1, 0)));
  dp[0][0][0] = 1;
  for(int i = 0; i <= N; i++) {
    for(int j = 0; j <= N; j++) {
      for(int k = 0; k <= N; k++) {
        int m = max({i, j, k});
        vector<int> c{i, j, k};
        sort(all(c));
        bool flag = true;
        for(int p = 0; p < R[m].size(); p++) {
          int l = R[m][p].l;
          int x = R[m][p].x;

          int cnt;
          if (l > c[1]) cnt = 1;
          else if (l > c[0]) cnt = 2;
          else cnt = 3;

          if (cnt != x) {
            flag = false;
            break;
          }
        }
        if (!flag) {
          dp[i][j][k] = 0;
          continue;
        }

        int m_ = m + 1;
        if (m_ > N) continue;
        dp[m_][j][k] += dp[i][j][k]; dp[m_][j][k] %= mod;
        dp[i][m_][k] += dp[i][j][k]; dp[i][m_][k] %= mod;
        dp[i][j][m_] += dp[i][j][k]; dp[i][j][m_] %= mod;
      }
    }
  }
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      ans += dp[N][i][j]; ans %= mod;
      ans += dp[i][N][j]; ans %= mod;
      ans += dp[i][j][N]; ans %= mod;
    }
  }
  cout << ans << endl;

}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(16);
  solve();
  return 0;
}

Measured memory_bytes: 218880
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        Queue<Long> q = new PriorityQueue<>(Comparator.reverseOrder());
        for (int i = 0; i < n; i++) {
            q.offer(sc.nextLong());
        }
        for (int i = 0; i < m; i++) {
            q.offer(q.poll() / 2);
        }
        System.out.println(q.stream().mapToLong(Long::longValue).sum());
    }
}


Measured memory_bytes: 62348
s = input()[::-1]
current = 0
a = [0] * 2019
a[0] = 1
digit = 1
for i in s:
  current += int(i) * digit
  digit *= 10
  digit %= 2019
  current %= 2019
  a[current] += 1
ans = 0
for i in a:
  ans += i * (i - 1) // 2
print(ans)

Measured memory_bytes: 9228
#include <iostream>
    using namespace std;
     
    int main() {
    	int i , j;
        cin >> i >> j;
        if (j == 1){
          cout << 0;
        }else if (i==j){
          cout << 0;
        }else{  
          cout << i - j;
    	  return 0;
          }
    }

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
typedef string::const_iterator State;
int p;
bool flag;
int number(char* &begin);
int term(char* &begin);
int factor(char* &begin);
int expression(char* &begin);

int mod_pow(int x,int n){
	int res=1;
	while(n>0){
		if(n&1)res=res*x%p;
		x=x*x%p;
		n>>=1;
	}
	return res;
}

int number(char* &begin){
	int ret=0;
	while(isdigit(*begin)){
		ret*=10;
		ret+=*begin-'0';
		begin++;
	}
	ret%=p;
	return ret;
}

int term(char* &begin){
	int ret=factor(begin);
	while(1){
		if(*begin=='*'){
			begin++;
			ret=ret*factor(begin)%p;
		}else if(*begin=='/'){
			begin++;
			int da=factor(begin);
			if(da==0)flag=false;
			int k=mod_pow(da,p-2);
			ret=ret*k%p;
		}else break;
	}
	return ret;
}

int factor(char* &begin){
	if(*begin=='('){
		begin++;
		int ret=expression(begin);
		begin++;
		return ret;
	}else return number(begin);
}

int expression(char* &begin){
	int ret=term(begin);
	while(1){
		if(*begin=='+'){
			begin++;
			ret=(ret+term(begin))%p;
		}else if(*begin=='-'){
			begin++;
			ret=(ret+p-term(begin))%p;
		}else break;
	}
	return ret;
}

char str[2][100001];

int main(void){
	while(1){
		scanf("%d:",&p);
		if(p==0)break;
		flag=true;
		int len=0;
		fgets(str[0],100000,stdin);
		for(int i=0;i<100000;i++){
			if(str[0][i]!=' ' && str[0][i]!='\n'){
				str[1][len]=str[0][i];
				len++;
			}
		}
		char* v=str[1];
		int res=expression(v);
		if(!flag)printf("NG\n");
		else printf("%s = %d (mod %d)\n",str[1],res,p);
	}
	return 0;
}

Measured memory_bytes: 1376
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll ans = INF;
    string S;
    cin >> S;
    ll sn = S.size();
    if(sn==1){
        cout << 0 << endl;
        return 0;
    }
    
    rep(i,26){
        if (S.find('a' + i) == string::npos) continue;
        string tmp = S;
        char c = 'a' + i;
        rep(i,sn-1){
            bool isok = true;
            rep(j, sn - i) if (tmp[j] != c) isok = false;
            if(isok){
                chmin(ans, i);
                break;
            }

            rep(j,sn-i-1){
                if (tmp[j] == c or tmp[j + 1] == c) tmp[j] = c;
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
robo = [None] * N
for i in range(N):
    x, l = map(int, input().split())
    robo[i] = (x - l, x + l)

robo.sort(key=lambda x: x[1])


t = robo[0][1]
cnt = 1

for i in range(1, N):
    j = robo[i]
    if j[0] >= t:
        t = j[1]
        cnt += 1

print(cnt)


Measured memory_bytes: 18216
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[])
{
    string s;
    cin >> s;
    cout << s[0] << s.size() - 2 << *(s.end() - 1) << endl;
}

Measured memory_bytes: 256
import numpy as np

D = int(input())
c = list(map(int, input().split()))
c = np.array(c)
S = np.zeros([D, 26], dtype=int)
for i in range(D):
  S[i, :] = list(map(int, input().split()))

T = []
last = np.zeros(26)

for i in range(D):
  down = ((i+1-last)*np.array(c)).sum()
  score = S[i, :] - down
  argmax = score.argmax()
  t = argmax+1
  last[t-1] = i+1
  print(t)

Measured memory_bytes: 27300
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define FOR(i, b, n) for (ll i = b; i < n; ++i)

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

void solve(ll K, ll A, ll B) {
  if (B - A <= 2 || K < A + 1) {
    cout << K + 1 << endl;
    return;
  }
  K -= (A + 1);
  ll ans = B;
  ans += (K / 2) * (B - A) + (K % 2);
  cout << ans << endl;
}

int main(){
  // int 3E4  long 2E9  ll 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll K;
  cin >> K;
  ll A;
  cin >> A;
  ll B;
  cin >> B;

  solve(K, A, B);

  return 0;
}


Measured memory_bytes: 3588
<?php
//error_reporting(0);
$N = trim(fgets(STDIN));
//list($A,$B,$C) =  explode(" ",trim(fgets(STDIN)));
$H =  explode(" ",trim(fgets(STDIN)));

$hi = 0;
for($i=0;$i<$N;$i++) {
  if ($H[$i]>$hi) {
    $hi = $H[$i];
    continue;
  }
  if ($hi - $H[$i]>1) {
    printf("No\n");
    exit;
  }

}
printf("Yes\n");


Measured memory_bytes: 14840
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
    int x;
    cin >> x;
    while(1){
        if(x == 2 || x == 3 || x == 5 || x == 7){
            cout << x;
            return 0;
        }
        if(x%2 == 1){
          for(int i=3; i<x/2; i+=2){
              if(x%i == 0) break;
              if(i==((x/2)-2) || i==((x/2)-1)){
                  cout << x;
                  return 0;
              }
          }
        }
        else{
          x++;
          continue;
        }
        x += 2;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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 MM = 1000000000; ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
int dh[4] = {-1, 0, 0, 1};
int dw[4] = {0, -1, 1, 0}; 
using P = pair<int, int>;
const double pi = acos(-1.0);

using Graph = vector<vector<ll>>;

int main(){
  int x,a,b;
  cin>>x>>a>>b;
  if(abs(x-a)<abs(x-b))cout<<"A"<<endl;
  else cout<<"B"<<endl;
    
    
  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define N 200005

using namespace std;

int n, m;
int head[N], nex[N << 1], to[N << 1], eid[N << 1], ecnt;
int p[N], s[N];

struct light {
	int pos, state;
}lig[N];

bool cmpLight(const light &lhs, const light &rhs) { return lhs.pos < rhs.pos; }

inline int read() {
	int x = 0; char ch = getchar();
	while(!isdigit(ch)) ch = getchar();
	while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	return x;
}
inline void addE(int u, int v, int id) {
	to[++ecnt] = v, eid[ecnt] = id;
	nex[ecnt] = head[u], head[u] = ecnt;
}

int cntOne;
int dif[N], fa[N], fe[N];
bool vis[N];

void dfs(int u) {
	if(s[u]) ++dif[u], ++cntOne;
	for(int i = head[u], v; i; i = nex[i]) {
		v = to[i];
		if(fa[v]) continue;
		fa[v] = u, fe[v] = eid[i], dfs(v);
		dif[u] += dif[v];
	}
}

int main() {
	n = read(), m = read();
	for(int i = 1; i <= n; ++i)
		lig[i].pos = read(), lig[i].state = read();
	
	sort(lig + 1, lig + n + 1, cmpLight);
	for(int i = 1; i <= n; ++i)
		p[i] = lig[i].pos, s[i] = lig[i].state;
	for(int i = n + 1; i >= 1; --i)
		s[i] = s[i] ^ s[i - 1];
		
	for(int i = 1, l, r; i <= m; ++i) {
		l = read(), r = read();
		l = lower_bound(p + 1, p + n + 1, l) - p;
		r = upper_bound(p + 1, p + n + 1, r) - p - 1;
		if(l <= r) {
			addE(l, r + 1, i), addE(r + 1, l, i);
		}
	}
	
	for(int i = 1; i <= n + 1; ++i)
		if(!fa[i]) {
			fa[i] = i;
			dfs(i);
			if(cntOne & 1) {
				puts("-1");
				return 0;
			}
		}
	
	int cnt = 0;
	for(int i = 1; i <= n + 1; ++i)
		if(dif[i] & 1)
			vis[fe[i]] = true, ++cnt;
	
	printf("%d\n", cnt);
	for(int i = 1; i <= m; ++i)
		if(vis[i])
			printf("%d ", i);
	putchar('\n');
	return 0;
}

Measured memory_bytes: 16496
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline

    from collections import defaultdict

    NIL = -1

    m = int(input())

    root = NIL

    def insert(k):
        global root
        y = NIL
        x = root
        z = {'key':k, 'left':NIL, 'right':NIL}
        while x != NIL:
            y = x
            if z['key'] < x['key']:
                x = x['left']
            else:
                x = x['right']
        z['parent'] = y

        if y == NIL:
            root = z
        elif z['key'] < y['key']:
            y['left'] = z
        else:
            y['right'] = z

    def inorder(u):
        if u == NIL:
            return
        inorder(u['left'])
        print(' ' + str(u['key']), end='')
        inorder(u['right'])

    def preorder(u):
        if u == NIL:
            return
        print(' ' + str(u['key']), end='')
        preorder(u['left'])
        preorder(u['right'])

    for _ in range(m):
        command = input()
        if command[:5] == 'print':
            inorder(root)
            print('')
            preorder(root)
            print('')
        else:

            _, k = command.split()
            k = int(k)
            insert(k)



Measured memory_bytes: 141336
#include<stdio.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<deque>
#include<stack>
using namespace std;

int n,l,ans;
vector<int> nei[2005];

int dfs(int x,int p,int d,int mx){
	int res=1;
	if(d!=mx) for(int i=0;i<nei[x].size();i++) if(nei[x][i]!=p) res+=dfs(nei[x][i],x,d+1,mx);
	return res;
}

int main(){
	cin>>n>>l;
	for(int i=0;i<n-1;i++){
		int x,y;
		cin>>x>>y;
		nei[x].push_back(y);
		nei[y].push_back(x);
	}
	if(l%2==0) for(int i=1;i<=n;i++) ans=max(ans,dfs(i,-1,0,l/2));
	else for(int i=1;i<=n;i++) for(int j=0;j<nei[i].size();j++) ans=max(ans,dfs(i,nei[i][j],0,l/2)+dfs(nei[i][j],i,0,l/2));
	cout<<n-ans<<endl;
	return 0;
}

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

int main(){
  bool grid[1000][1000];
  int num[1001][1001],i,j,h,w,n,t;
  while(scanf("%d%d%d",&h,&w,&n) && (h||w||n)){
    for(i=0;i<h;i++)
      for(j=0;j<w;j++){
	scanf("%d",&t);
	grid[i][j] = t?true:false;
	num[i][j] = 0;
      }

    num[0][0] = n-1;
    for(i=0;i<h;i++)
      for(j=0;j<w;j++){
	int N=num[i][j];
	if(grid[i][j]){
	  num[i+1][j] += N/2;
	  num[i][j+1] += N-N/2;
	}else{
	  num[i][j+1] += N/2;
	  num[i+1][j] += N-N/2;
	}
	if(N&1)grid[i][j] = !grid[i][j];
      }

    i=j=0;
    while(i<h && j<w)grid[i][j]?j++:i++;
    printf("%d %d\n",i+1,j+1);
  }
}

Measured memory_bytes: 5656
// Contest.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>
#include <map>
#include <math.h>

using namespace std;

int dp[200][3];
int a[200][3];

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i][0];
	for (int i = 0; i < n; i++)cin >> a[i][1];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= 1; j++){
			if (i == 0 && j == 0)dp[i][j] = a[i][j];
			else dp[i][j] = max(dp[i - 1][j],dp[i][j - 1])+a[i][j];
		}
	}
	cout << dp[n-1][1];
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  
  int a[n];
  for (int i = 0; i < n; ++i) {
  	cin >> a[i];
  }
  
  int cnt = 0;
  bool flg = false;
  while (true) {
  	for (int i = 0; i < n; ++i) {
      if (a[i] % 2 == 0) { a[i] /= 2; }
      else { flg = true; break; }
    }
    if (flg) { break; }
    ++cnt;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h> 
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 998244353;//1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=1e6+5;
int cnt[N];
int dp[N];
int add(int a,int b)
{
      a+=b;
      if(a>=MOD) a-=MOD;
      return a;
}
int sub(int a,int b)
{
      a-=b;
      if(a<0) a+=MOD;
      return a;
}
int mul(int a,int b)
{     
      return ((long long)a*b)%MOD;
}
int rev(int a)
{
	return mpow(a,MOD-2);
}
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i],cnt[a[i]]++;
	int ans=0;
	for(int i=N-1;i>=1;i--)
	{
		int an=0;
		int s1=0;
		int s2=0;
		for(int j=i;j<N;j+=i)
		{
			an=add(an,dp[j]);
			s1=add(s1,mul(cnt[j],j));
			s2=add(s2,mul(cnt[j],mul(j,j)));
		}
		int an1=sub(mpow(s1,2),s2);
		an1=mul(an1,rev(2));
		dp[i]=sub(an1,an);
		ans=add(ans,mul(dp[i],rev(i)));
	}
	cout<<ans;
}
// Don't be afraid to fail. Be afraid not to try.
// "Become grindian instead of greendian" - aryanc403
// When you want to succeed as bad as you want to breathe, only then you’ll Be Successful!
// No Matter,How Fast You Are Driving If You Are Driving in a Wrong Direction You Will Never Reach Your Destination
// When failures hit you, you hit the failures back with Bounce Back!
// When you face failures, Don’t change your goal, Change your strategy!

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

int main(void){
  	int n,r,s;
	scanf("%d",&n);
  	scanf("%d",&r);
  	s=0;
  	if(n<10){
      s=10-n;      
            } 
    printf("%d",r+s*100);
    return 0;
}

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

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

  int64_t N, K;
  cin >> N >> K;
  pair<int64_t, int64_t> P[N];
  rep(i, N){
    cin >> P[i].first >> P[i].second;
  }
  sort(P, P+N);
  int64_t ans = 0;
  for(int i=0;i<N;i++){
    ans += P[i].second;
    if(K <= ans){
      cout << P[i].first << endl;
      break;
    }
  }
}

Measured memory_bytes: 1792
#include <stdio.h>

int main() {
	int n;
	int x[100];
	scanf("%d", &n);
	
	for (int i = 0; i < n; i++) {
		scanf("%d",&x[i]);
	}
	for (int p = n-1; p > 0; p--) {
			printf("%d ",x[p]);
	}
	printf("%d\n", x[0]);
}



Measured memory_bytes: 2680
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MAX 1000005

int factor[MAX] = { 0 };

inline void generatePrimeFactors() 
{ 
    factor[1] = 1;

    for (int i = 2; i < MAX; i++) 
        factor[i] = i;
  
    for (int i = 4; i < MAX; i += 2) 
        factor[i] = 2; 

    for (int i = 3; i * i < MAX; i++) 
    { 
        if (factor[i] == i) 
        { 
            for (int j = i * i; j < MAX; j += i) 
            { 
                if (factor[j] == j) factor[j] = i; 
            } 
        } 
    } 
} 

int calculateNoOFactors(int n) 
{ 
    if (n == 1) return 1;
  
    int ans = 1; 
    int dup = factor[n]; 
    int c = 1;  
    int j = n / factor[n]; 
  
    while (j != 1) 
    {
        if (factor[j] == dup) c += 1; 
        else 
        { 
            dup = factor[j]; 
            ans = ans * (c + 1); 
            c = 1; 
        } 
        j = j / factor[j]; 
    } 
    ans = ans * (c + 1);
    return ans; 
} 

int32_t main()
{
	//freopen("input.txt", "r", stdin);
	IOS;
	
	generatePrimeFactors();

	int n; cin >> n;
	int count = 0;
	for(int c = 1 ; c < n ; c++)
	{
		count += calculateNoOFactors(c);
	}
	cout << count << '\n';
	return 0;
}

Measured memory_bytes: 11464
from math import factorial
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N, K = map(int, input().split())
        M = N - K
        for i in range(1, K + 1):
            if M + 1 < i:
                print(0)
            else:
                a = self.combinations_count(M + 1, i)
                b = self.grouping_0_ng(K, i)
                print((b * a) % (10 ** 9 + 7))

    # 組み合わせの数
    def combinations_count(self, n, r):
        n = n
        return factorial(n) // (factorial(n - r) * factorial(r))

    # x 個のものを y 個のグループに分ける場合の数(全グループに１個以上)
    def grouping_0_ng(self, x, y):
        return self.groupint_0_ok(x - y, y)

    def groupint_0_ok(self, x, y):
        return self.combinations_count(x + y - 1, y - 1)


# Run main
if __name__ == '__main__':
    AtCoder().main()


Measured memory_bytes: 65880
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(a) a.begin(), a.end()
using namespace std;

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

    int n, m;
    cin >> n >> m;

    int p[100000], y[100000];
    vector<int> yd[100001];
    REP(i, m) {
        cin >> p[i] >> y[i];
        yd[p[i]].push_back(y[i]);
    }

    REP(i, n) { SORT(yd[i + 1]); }
    REP(i, m) {
        cout << setfill('0') << setw(6) << p[i];
        cout << setfill('0') << setw(6)
             << lower_bound(ALL(yd[p[i]]), y[i]) - yd[p[i]].begin() + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 7808
#include<stdio.h>
#include<math.h>

int main(void){
    int x[4], i, index, max;
    int y=0;

    for(i=0; i<4; i++){
        scanf("%d", &x[i]);
    }
    index = 0; max = x[0];
    for(i=0; i<3; i++){
        if(max < x[i]){
            index = i;  max = x[i];
        }
        y = y + x[i];
    }
    y = y - x[index] + x[index]*pow(2,x[3]);
    printf("%d\n", y);
    return 0;
}

Measured memory_bytes: 2528
x,y,z,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
AB=[]
for a in A:
    for b in B:
        AB.append(a+b)
AB.sort(reverse=True)
AB=AB[:k]
ABC=[]
for ab in AB:
    for c in C:
        ABC.append(ab+c)
ABC.sort(reverse=True)
for i in range(k):
    print(ABC[i])

Measured memory_bytes: 148588