akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
const int N=1e6;
const int mo=1e9+7;
int n,f[N+10],max0[N+10],min0[N+10],sum[N+10];
struct data {
    int x,v,numv;
}a[N+10];
int Sum(int x,int y) {
    x+=y;
    return (x>=mo)?x-mo:x;
}
int Sub(int x,int y) {
    x-=y;
    return (x<0)?x+mo:x;
}
bool cmpx(data p,data q) {
    return p.x<q.x;
}
bool cmpv(data p,data q) {
    return p.v<q.v;
}
int main() {
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
        scanf("%d%d",&a[i].x,&a[i].v);
    sort(a+1,a+n+1,cmpv);
    for (int i=1;i<=n;i++) a[i].numv=i;
    sort(a+1,a+n+1,cmpx);
    max0[0]=0;
    for (int i=1;i<=n;i++) max0[i]=max(max0[i-1],a[i].numv);
    min0[n+1]=1e9;
    for (int i=n;i>=1;i--) min0[i]=min(min0[i+1],a[i].numv);
    f[0]=sum[0]=1;
    int ans=0;
    for (int i=1;i<=n;i++) {
        int lx=0,rx=i;
        while (lx<rx) {
            int mid=(lx+rx)/2;
            if (max0[mid]<min0[i]-1) lx=mid+1;
            else rx=mid;
        }
        f[i]=Sub(sum[i-1],sum[lx-1]);
        if (max0[i]==n) ans=Sum(ans,f[i]);
        sum[i]=Sum(sum[i-1],f[i]);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 16640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int len(pint i, pint j) {
    return (i.first - j.first) * (i.first - j.first) + (i.second - j.second) * (i.second - j.second);
}

signed main() {
    int n;
    cin >> n;
    int x[n], y[n];
    pint p[n];
    rep(i, 0, n) cin >> p[i].first >> p[i].second;
    sort(p, p + n);
    double sum = 0;
    do {
        rep(i, 1, n) sum += sqrt(len(p[i], p[i - 1]));

    } while (next_permutation(p, p + n));
    rep(i, 1, n + 1) sum /= i;
    cout << fixed << setprecision(10) << sum << "\n";
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
int n,a,s[1000],b[1000];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>s[i];
		b[s[i]]=1;
	}
	for(int i=1;i<=100;i++)  a+=b[i];
	cout<<a;
	return 0;
}

Measured memory_bytes: 256
import itertools

N, M, Q = map(int, input().split())
abcd = [tuple(map(int, input().split())) for _ in range(Q)]

Max = 0
for C in itertools.combinations_with_replacement(range(1, M + 1), N):
  score = sum([d for a, b, c, d in abcd if C[b-1] - C[a-1] == c])
  Max = max(Max, score)
print(Max)

Measured memory_bytes: 9196
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;

class Main {
	public static void main(String args[]) throws IOException {
		@SuppressWarnings("resource")
		Scanner cin = new Scanner(System.in);
		ArrayList<String> inLines = new ArrayList<String>();
		for (; cin.hasNext();) {
			inLines.add(cin.nextLine());
		}
		Solver solver = new Solver();
		solver.solve(inLines);
	}
}

class Solver {
	class Path {
		int a;
		int b;

		Path(int a, int b) {
			this.a = a;
			this.b = b;
		}
	}

	class Vertex {
		int Num;
		HashSet<Integer> Link;
		boolean pathed;

		Vertex(int n) {
			this.Num = n;
			Link = new HashSet<Integer>();
			pathed = false;
		}

		void cnt(int len) {
			if (len == N) {
				CNT++;
				return;
			}
			pathed = true;
			for (Integer v : Link) {
				if (!VertexMap.get(v).pathed) {
					VertexMap.get(v).cnt(len + 1);
				}
			}
			pathed = false;
		}

		void addLink(Path p) {
			if (p.a == Num)
				Link.add(p.b);
			else if (p.b == Num)
				Link.add(p.a);
		}
	}

	int N;
	int M;
	HashMap<Integer, Vertex> VertexMap;
	int CNT;

	public void solve(ArrayList<String> inLines) {
		String[] strArr = inLines.get(0).split(" ");
		N = Integer.parseInt(strArr[0]);
		M = Integer.parseInt(strArr[1]);

		ArrayList<Path> pathList = new ArrayList<Path>();
		for (int i = 0; i < M; i++) {
			String[] strPath = inLines.get(i + 1).split(" ");
			int a = Integer.parseInt(strPath[0]);
			int b = Integer.parseInt(strPath[1]);
			pathList.add(new Path(a, b));
		}

		// System.out.println("N=" + N + " M=" + M);
		// for (Path p : pathList) {
		// System.out.println(" " + p.a + " " + p.b);
		// }

		VertexMap = new HashMap<Integer, Vertex>();
		for (int i = 1; i <= N; i++)
			VertexMap.put(i, new Vertex(i));
		for (Path p : pathList) {
			VertexMap.get(p.a).addLink(p);
			VertexMap.get(p.b).addLink(p);
		}

		CNT = 0;
		VertexMap.get(1).cnt(1);
		System.out.println(CNT);
	}
}


Measured memory_bytes: 10320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
#define INF (1e9)

int main() {
  ll X;
  cin >> X;
  ll N;
  cin >> N;
  vector<bool> nonp(102, true);
  for (ll i = 0; i < N; i++) {
    ll p;
    cin >> p;
    nonp[p] = false;
  }

  ll m = INF, ans = 0;
  for (ll i = 0; i < 102; i++) {
    if (nonp[i] && m > abs(X - i)) {
      ans = i;
      m = min(m, abs(X - i));
    }
  }

  cout << ans << endl;
}


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

int main() {
  char c;
  cin >> c;
  int cint = c-'0';
  char ans;
  if (cint >= 17 && cint <= 42) ans = 'A';
  else ans = 'a';
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;

/*
*/

ll r,d,x;

void init(){
	cin>>r>>d>>x;
}

int main(void){
	init();
	reg(i,2001,2010){
		x=r*x-d;
		cout<<x<<endl;
	}
	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++)
#define all(v) v.begin(), v.end()

struct dyse{

    vector<int> x = {0,0,0,0,0,0};

    void set_dyse(){
        rep(i,6) cin >> x.at(i);
    }

    void ido(char dir){
        if(dir == 'N'){
            int tmp = x.at(0);
            x.at(0) = x.at(1);
            x.at(1) = x.at(5);
            x.at(5) = x.at(4);
            x.at(4) = tmp;
        }else if(dir == 'S'){
            int tmp = x.at(0);
            x.at(0) = x.at(4);
            x.at(4) = x.at(5);
            x.at(5) = x.at(1);
            x.at(1) = tmp;
        }else if(dir == 'W'){
            int tmp = x.at(0);
            x.at(0) = x.at(2);
            x.at(2) = x.at(5);
            x.at(5) = x.at(3);
            x.at(3) = tmp;
        }else if(dir == 'E'){
            int tmp = x.at(0);
            x.at(0) = x.at(3);
            x.at(3) = x.at(5);
            x.at(5) = x.at(2);
            x.at(2) = tmp;
        }
    }

    void ue(){
        cout << x.at(0) << endl;
    }
};

int main(){
    dyse d;
    d.set_dyse();

    string S;
    cin >> S;

    for(char ch:S){
        d.ido(ch);
    }

    d.ue();
}   


Measured memory_bytes: 3232
/*
　　　　 ∧＿∧　にっぽんちゃちゃちゃ
　／＼（　・∀・）／ヽ
（ ●　と　　　つ　● ）　にっぽんちゃちゃちゃ
　＼/⊂、 ノ　　＼ノ
　　　　　し'
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define MOD 1000000007
#define INF 9223372036854775807

signed main(){
int x=0,y=0,z=0,w=0,a=0,b=0;
std::vector<int> v(7);
rep(i,7){
  std::cin >> x>>y;
  v[i]=x-y;
}
rep(i,7)
std::cout << v[i] << '\n';
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define MAX 1000000
#define For(i, a, b) for( int i = (a); i < (b); i++ )
#define ll long long
using namespace std;

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

    map<ll,ll> m;
    map<ll, pair<ll, ll>> mpp;
    ll arr[MAX];
    ll n;
    cin>>n;

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

    for(int i=0; i< n; i++){
        ll temp = m[arr[i]];
        ll co1 = temp * (temp-1) * 0.5;
        ll co2 = (temp-1)*(temp-2)*0.5;
        mpp[arr[i]] = make_pair(co1, co2);
    }
    
    // for(auto a: mpp){
    //     cout<<a.first<<" "<<a.second.first<<" "<<a.second.second<<endl;
    // }
    ll sum1;
    sum1 = 0;
    
    for(auto a: mpp){
        sum1 += a.second.first;
    }

    for(int i=0; i< n; i++){
        ll e = sum1 - mpp[arr[i]].first + mpp[arr[i]].second; 
        cout<<e<<endl;
    }


    return 0;
}

Measured memory_bytes: 20608
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = map(int, input().split())


def binarySearch(A, key):
    left = 0
    right = len(A)
    while left < right:
        mid = (left + right) // 2
        if A[mid] == key:
            return True
        elif key < A[mid]:
            right = mid
        else:
            left = mid + 1
    return False


a = 0
for t in T: a += binarySearch(S, t)
print(a)

Measured memory_bytes: 18664
#include<iostream>
#include<string>
using namespace std;
string s;
bool flag = false;
int main(){
	cin >> s;
	if(s[2] == s[3] && s[4] == s[5]) flag = true;
	else flag = false;
	if(flag) cout << "Yes" << endl;
	else cout << "No" << endl;
}



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

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

	int x = a * b;
	int y = c * d;

	if (x > y) cout << x << endl;
	else if (x == y) cout << x << endl;
	else cout << y << endl;

}

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

int main(){
    char S[300];
    char T[300];

    scanf("%s",S);
    strcpy(T,S);
    strcat(S,T);
    scanf("%s",T);
    int l=strlen(T);

    int i,rt=0;
    puts(strstr(S,T)==NULL?"No":"Yes");
    return 0;
}


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

int N, A, B, C;
int score = 1000000000;

void dfs(int i, vector<int> &L, int a, int b, int c, int point) {
    if (i == L.size()) {
        if (a == 0 || b == 0 || c == 0) return;
        point += abs(a - A) + abs(b - B) + abs(c - C);
        score = min(score, point);
        return;
    }
    dfs(i + 1, L, a, b, c, point);
    if (a == 0) {
        dfs(i + 1, L, a + L[i], b, c, point);
    } else {
        dfs(i + 1, L, a + L[i], b, c, point + 10);
    }
    if (b == 0) {
        dfs(i + 1, L, a, b + L[i], c, point);
    } else {
        dfs(i + 1, L, a, b + L[i], c, point + 10);
    }
    if (c == 0) {
        dfs(i + 1, L, a, b, c + L[i], point);
    } else {
        dfs(i + 1, L, a, b, c + L[i], point + 10);
    }
}

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

    cin >> N >> A >> B >> C;
    vector<int> L(N);
    for (int i = 0; i < N; i++) cin >> L[i];
    dfs(0, L, 0, 0, 0, 0);
    cout << score << endl;

    return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    vector<P> v;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i] >> b[i];
        v.push_back(P(a[i] + b[i], a[i]));
    }
    sort(v.rbegin(), v.rend());
    ll asum = 0, bsum = 0;
    for (int i = 0; i < n; i++)
    {
        ll p = v[i].second, q = v[i].first - p;
        if (i % 2 == 0)
            asum += p;
        else
            bsum += q;
    }
    cout << asum - bsum << endl;
}


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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define debug(i) cout << i << endl;
#define debugarr(a) for(auto i : a) cout << i << " ";

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);

    string s;
    string t;
    cin >> s >> t;

    int ans = 0;
    for(int i = 0; i < 3; i++) {
        if(s[i] == t[i]) ans++;
    }

    cout << ans << endl;
}


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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF 1000000000 //
#define LINF (ll)4000000000000000000 //
#define MOD (ll)1000000007
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define PI 3.1415926535898
#define NP(v) next_permutation(v.begin(),v.end())

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

bool check(string s) {
    int l = s.length();

    rep(i, l / 2) {
        if (s[i] != '#' && s[l - 1 - i] != '#' && s[i] != s[l - 1 - i]) return true;
    }
    return false;
}

int main() {
    string s;
    cin >> s;
    rep(i, 8) s.erase(s.end() - 1);
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String t = s.replace("/","");

    if(t.compareTo("20190430") <= 0) {
      System.out.println("Heisei");
    } else {
      System.out.println("TBD");
    }

  }

}


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

int main() {
    string s,c;
    int q,t,f,rev=0;
    cin>>s>>q;
    deque<string> ans(s.size());
    rep(i,s.size()) ans[i]=s[i];
    rep(i,q) {
        cin>>t;
        if (t==1) rev=1-rev;
        else {
            cin>>f>>c;
            if (rev) f=3-f;
            if (f==1) ans.push_front(c); 
            else ans.push_back(c);
        }
    }
    if (rev) reverse(ans.begin(),ans.end());
    for (auto it : ans) {
        cout<<it;
    }
    printf("\n");
}


Measured memory_bytes: 17152
# https://atcoder.jp/contests/abc112/tasks/abc112_c


# ピラミッドの中心は必ず0-100の中にある
# Hは1以上
# 与えられる情報だけで一意に定まる

# 中心座標をa,bと置いたとき、ある点x,yにおける高さは
# h(x,y; a,b)=max(H-|x-a|-|y-b|,0)である。
# ここで、真の高さとの誤差としてe(x,y;a,b)=|h(x,y;a,b) - h(x,y;Cx,Cy)|とすると。
# 任意のx,yでe=0となるa,bが答え。しかしHはわからないので0とする。
# そうすると任意のx,yでe(x,y;a,b)=constとなるa,bが答え。(ただしmaxの扱いが面倒なのでh==0は無視して処理を行う)
# またその定数constはHである

# 座標は10**4点。Nはたかだか100なので 最悪10**6回計算。間に合う。
# あー結局全探索してるんだから問題の定義を借りて素直に実装すればバグらせずに済んだな

import numpy as np
from itertools import product

N = int(input())
X, Y, H = [], [], []
for n in range(N):
    x, y, h = list(map(int, input().split()))
    X.append(x)
    Y.append(y)
    H.append(h)

if N == 1:
    print(x, y, h)
    exit()

X = np.array(X)
Y = np.array(Y)
H = np.array(H)


def is_eq_loss(X, Y, H, a, b):
    loss = np.abs(- np.abs(X - a) - np.abs(Y - b) - H)
    mask = (H == 0)  # 高さがない疑いのところは最小値に合わせる
    if np.any(mask):
        loss[mask] = loss.min()
    if (loss[-1] == loss).all():
        return True, loss[-1]
    else:
        return False, False


# for a, b in product(range(101), range(101)):
#     flg, ansH = is_eq_loss(X, Y, H, a, b)
#     if flg:
#         ans = (a, b, ansH)

# print(*ans)

# バグらせずに実装したい


def is_ok(X, Y, H, a, b):
    height = H + np.abs(X - a) + np.abs(Y - b)  # minの扱いどうする?
    if (height == height[-1]).all():
        return True, height[-1]
    else:
        return False, False


for a, b in product(range(101), range(101)):
    flg, ansH = is_eq_loss(X, Y, H, a, b)
    if flg:
        ans = (a, b, ansH)

print(*ans)


Measured memory_bytes: 12464
#include <iostream>
#include <cstdio>
#include <map>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <list>
#include <stack>
#include <queue>
#include <cstdlib>
#include <tuple>
#define INF 1000000000
#define EPS 1e-9
using namespace std;

typedef list<int> L;
typedef pair <int,int> P;
typedef vector<int> V;
typedef queue<int> Q;
typedef stack<int> S;
typedef map<string,int> M;

int sum(V v, int num) {
    int res = 0;
    for (int i = 0; i < v.size(); i++)
        res += v[i];

    return res - num;
}

int main()
{
    int N, M;
    while (cin >> N >> M, (N && M)) {
        V n, m;
        for (int i = 0; i < N; i++) {
            int tmp;
            cin >> tmp;
            n.push_back(tmp);
        }
        for (int i = 0; i < M; i++) {
            int tmp;
            cin >> tmp;
            m.push_back(tmp);
        }

        P res = P(1000, 1000);
        for (int i = 0; i < m.size(); i++) {
            for (int j = 0; j < n.size(); j++) {
                if (sum(m, m[i] - n[j]) - sum(n, n[j] - m[i]) == 0)
                    if (res.first + res.second > n[j] + m[i])
                        res = P(n[j], m[i]);
            }
        }
        if (res.first == 1000)
            cout << -1 << endl;
        else
            cout << res.first << " " << res.second << endl;
    }

    return 0;
}

Measured memory_bytes: 1220
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()

int main() {
  //
  int n;
  cin >> n;
  vi t(n), x(n), y(n);
  rep(i, n) { cin >> t[i] >> x[i] >> y[i]; }
  if (abs(x[0]) + abs(y[0]) != t[0]) {
    cout << "No" << endl;
    return 0;
  }
  REP(i, 1, n) {
    if (abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]) > (t[i] - t[i - 1])) {
      cout << "No" << endl;
      return 0;
    }
    if (((abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1])) & 1) !=
        ((t[i] - t[i - 1]) & 1)) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>

#define REP(i,x) for(int i=0 ; i<(int)(x) ; i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

LL MOD = 1000000007LL;

LL inv(LL a, LL p){
    LL res = 1;
    while(p>0){
        if(p&1)res = (res*a)%MOD;
        a = (a*a)%MOD;
        p >>= 1;
    }
    return res;
}

int main(){
    int H, W, A, B;
    cin >> H >> W >> A >> B;
    H--;
    W--;
    int C = H-A;
    int D = W-B;
    int M = min(C, D);
    LL res = 0LL;
    //cout << C << "," << D << endl;
    int Z = max(B+C, A+D) + 1;
    vector<LL> X(B+C+1, 1);
    vector<LL> Y(A+D+1, 1);
    REP(i, B+C){
        X[i+1] = X[i] * (B+C-i);
        X[i+1] %= MOD;
        X[i+1] *= inv(i+1, MOD-2);
        X[i+1] %= MOD;
    }
    REP(i, A+D){
        Y[i+1] = Y[i] * (A+D-i);
        Y[i+1] %= MOD;
        Y[i+1] *= inv(i+1, MOD-2);
        Y[i+1] %= MOD;
    }

    REP(i, M+1){
        //cout << X[B+i] << "," << Y[A+i] << endl;
        res += (X[B+i] * Y[A+i]);
        res %= MOD;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        int[] num = new int[n];
        for (int i = 0; i < n - 1; i++) {
            if(s.substring(i, i + 2).equals("AC")) {
                num[i + 1] = num[i] + 1;
            } else {
                num[i + 1] = num[i];
            }
        }
        for (int i = 0; i < q ; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            int ans = num[r - 1] - num[l - 1];
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 63236
#include<stdio.h>

#define HEAP_SIZE 500000
long int heap[HEAP_SIZE+1];
int heap_size;

void maxHeapify(long int heap[], int i)
{
	int l = i * 2;
	int r = i * 2 + 1;
	int largest;
	long int w;

	if((l <= heap_size) && (heap[l] > heap[i])){
		largest = l;
	}else{
		largest = i;
	}
	if((r <= heap_size) && (heap[r] > heap[largest])){
		largest = r;
	}
	if(largest != i){
		w = heap[i];
		heap[i] = heap[largest];
		heap[largest] = w;
		maxHeapify(heap, largest);
	}

	return;
}

void buildMaxHeap(long int heap[])
{
	int i;
	for(i = heap_size / 2; 1 <= i; i--){
		maxHeapify(heap, i);
	}
	return;
}

int main()
{
	int i;

	scanf("%d", &heap_size);
	for(i = 1; i <= heap_size; i++){
		scanf("%ld", &heap[i]);
	}

	buildMaxHeap(heap);

	for(i = 1; i < heap_size; i++){
		printf(" %ld", heap[i]);
	}
	printf(" %ld\n", heap[i]);

	return(0);
}

Measured memory_bytes: 4500
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    cout << N * N * N << endl;
}

Measured memory_bytes: 256
import sys
import heapq
import random
import collections
import math

# available on Google, not available on Codeforces
# import numpy as np
# import scipy

def prime_factors(nr):
    i = 2
    factors = []
    while i <= nr:
        if i > math.sqrt(nr):
            i = nr
        if (nr % i) == 0:
            factors.append(i)
            nr = nr / i
        else:
            i = i + 1
    return factors


def solve(nums):  # fix inputs here

    c = collections.Counter(prime_factors(nums))
    res = 0
    for _,v in c.items():
        res += int((-1+math.sqrt(1+4*2*v))//2)    
    return res

def console(*args):  # the judge will not read these print statement
    print('\033[36m', *args, '\033[0m', file=sys.stderr)
    return


# for case_num in range(int(input())):
    # read line as a string
    # strr = input()

    # read line as an integer
inn = int(input())

# read one line and parse each word as a string
# lst = input().split()

# read one line and parse each word as an integer
# lst = list(map(int,input().split()))

# read matrix and parse as integers (after reading read nrows)
# lst = list(map(int,input().split()))
# nrows = lst[0]  # index containing information, please change
# grid = []
# for _ in range(nrows):
#     grid.append(list(map(int,input().split())))

res = solve(inn)  # please change

# Google - case number required
# print("Case #{}: {}".format(case_num+1, res))

# Codeforces - no case number required
print(res)


Measured memory_bytes: 9876
N, X = map(int, input().split())
m = list()
for i in range(N):
    x = int(input())
    m.append(x)

ans = 0
ans += len(m)
X -= sum(m)

m.sort()
while X >= m[0]:
    ans += 1
    X -= m[0]

print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5,M=1e6+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a) memset(a,0,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first 
#define se second
int main(){
	int n;
	ll a,b,c=0;
	scanf("%d%lld%lld",&n,&a,&b);
	for(int i=3;i<=n;i++){
		ll x;
		scanf("%lld",&x);
		c^=x;
	} 
	ll s=a+b,d=(s-c),ans=d/2;
	if((d&1)||d<0||ans>a||(ans&c)) return puts("-1"),0;
	for(ll i=(1LL<<61);i;i>>=1){
		if((i&c)&&ans+i<=a) ans+=i; 
	}
	printf(ans?"%lld\n":"-1\n",a-ans);
	return 0;
}

Measured memory_bytes: 3764
#include <iostream>
#include<algorithm>
#include<map>
using namespace std;
map< long long  , char > mp;
int main() {
    long long  a, b;
    cin >> a >> b;
    string s1 , s2 ;
    cin>>s1>>s2 ;
    long long  lc = a*b / ( __gcd(a ,b)) ;
    long long  y = lc / a ;
    long long  x = lc / b ;
    if(s1[0] != s2[0]){
        cout<<-1 ;
        return  0 ;
    }
    for(int  i=1 ; i<a; i++){
      mp[y*i] = s1[i] ;
    } 
    for(int  i=1 ; i<b; i++){
      if(mp.find(x*i)!=mp.end()){
        
       if(mp[i*x] !=s2[i]){
           cout<<-1;
           return  0;
       }   
      }
    } 
    cout<<lc ;
    return 0;
}

Measured memory_bytes: 6144
from collections import deque
h,w=map(int,input().split())
field=[["*" for i in range(w+2)]]+[["*"]+list(input())+["*"] for i in range(h)]+[["*"]*(w+2)]
dx=[-1,0,1,0]
dy=[0,-1,0,1]
visited=[[False for i in range(w+2)] for j in range(h+2)]
s={"#":0,".":1}
ans=0
def bfs(a,b):
    if visited[a][b] or field[a][b]=="*":return 0
    D=deque([(a,b)])
    visited[a][b]=True
    cnt=[0,0]
    while D:
        pos=D.popleft()
        cnt[s[field[pos[0]][pos[1]]]]+=1
        for i,j in zip(dx,dy):
            if field[pos[0]+i][pos[1]+j] == "*" or visited[pos[0]+i][pos[1]+j] or field[pos[0]+i][pos[1]+j]==field[pos[0]][pos[1]]:
                continue
            visited[pos[0]+i][pos[1]+j]=True
            D.append((pos[0]+i,pos[1]+j))
    return cnt[0]*cnt[1]
for i in range(h+2):
    for j in range(w+2):
        ans += bfs(i,j)
print(ans)

Measured memory_bytes: 5996
#include<bits/stdc++.h>
using namespace std;
char s[5];
typedef long long ll;
int main(){
	ll n,a,b;
	scanf("%lld %lld %lld",&n,&a,&b);
	ll res = 0;
	if(n <= a+b)
		res = min(n,a);
	else{
		res = n/(a+b)*a + min(n%(a+b),a);
	}
	printf("%lld",res);
	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() {
  string a, b, c;
  cin >> a >> b >> c;
  if(a[a.size()-1] == b[0] && b[b.size()-1] == c[0]) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
string s,ans;
int n;

P getNum(string str,int x){
  int r=0;
  while('0'<=str[x]&&str[x]<='9')
    r=r*10+str[x]-'0',x++;
  return P(x,r);
}

void dfs(int b,int e){
  int p=b;
  while(p<=e&&ans.size()<=n){
    while('0'<=s[p]&&s[p]<='9'){
      P r=getNum(s,p);
      int x=r.first,num=r.second;
      int y=r.first,z=r.first;
      if(s[x]=='('){
	int c=1;
	y=x+1;
	for(z=y;z<=e&&c;z++){
	  if(s[z]=='(')c++;
	  if(s[z]==')')c--;
	}
	p=z;
	z-=2;
	while(num--)dfs(y,z);
      }else{
	while(num--)ans+=s[x];
	p=x+1;
      }
    }
    while('A'<=s[p]&&s[p]<='Z')ans+=s[p++];
  }
}

int main(){
  while(1){
    cin>>s>>n;
    if(s=="0"&&!n)break;
    dfs(0,s.size()-1);
    if(ans.size()>=n+1)cout<<ans[n]<<endl;
    else cout<<0<<endl;
    ans.clear();
  }
  return 0;
}

Measured memory_bytes: 2116
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::cout.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::setprecision(15);}}fIO;
template<typename T> using V = std::vector<T>;
template<typename T> void fill(V<T>&v) { for(T&e:v) std::cin >> e; }
/*-*/

inline lnt ceildiv(lnt a, lnt b) { return (a+b-1)/b; }


int main() {
	lnt n,x,t;
	std::cin >> n >> x >> t;
	print(ceildiv(n,x)*t);
}


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

int main(){
    int n;
    cin >> n;
    int w[n];
    for(int i=0;i<n;i++)
        cin >> w[i];

    int sum = 0;
    int sum2 = 0;
    for(int i=0;i<n;i++)
        sum += w[i];
    for(int i=0;i<n;i++){
        sum2 += w[i];
        if(sum2 == sum/2)
            break;
        else if(sum2 > sum/2){
            if(sum2-sum/2 > sum/2-sum2+w[i]){
                sum2 -= w[i];
            }
            break;
        }
    }
    cout << abs(sum - 2*sum2) << endl;
}

Measured memory_bytes: 256
package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	H := sc.NextIntArray()

	mx := H[0]
	count := 1
	for i := 1; i < N; i++ {
		if mx <= H[i] {
			mx = H[i]
			count++
		}
	}
	fmt.Println(count)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>

using namespace std;

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

	vector<int> v = {a, b, c};
	sort(v.begin(), v.end());
	while (k > 0) {
		v[2] *= 2;
		k--;
	}

	int ans = v[0] + v[1] + v[2];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<cctype>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    string S;
    cin >> S;
    ll N=S.size();
    ll tmp=0,ans=0;
    ll i;
    for(i=0;i<N;i++){
        if(S[i]=='W'){
            ans+=i-tmp;
            tmp++;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main(){
  string s, max("");
  map<string, int> w; // stringÅsort³êé
  map<int, string, greater<int> > x; // int Åsort³êé = ÅÌÆ±ÉÅåo»ñ

  while(cin >> s){
    //Åå·Ì¶ðXV
    if(s.size() > max.size()) max = s;
    w[s]++;
  }
  
  for(map<string, int>::iterator it = w.begin() ; it != w.end() ; it++){
    x[(*it).second] = (*it).first;
    //cout << "first = " << (*it).first << ", second =  " << (*it).second << endl;
  }

  /*for(map<int, string>::iterator it = x.begin() ; it != x.end() ; it++){
    x[(*it).second] = (*it).first;
    cout << "first = " << (*it).first << ", second =  " << (*it).second << endl;
  }*/
  
  cout << (*x.begin()).second << " " << max << endl;
  return 0;
}

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

#define read(num1,num2) scanf("%d %d", &num1, &num2)

int main()
{
    int n,l;

    while(read(n,l) != EOF)
    {
        vector<string>s;

        for(int i=0; i<n; i++)
        {
            string str; cin >> str;
            s.push_back(str);
        }
        sort(s.begin(), s.end());
        for(int i=0; i<s.size(); i++) cout << s[i];
        cout << endl;
    }

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1e9+7
typedef long long ll; 
 
 int main(){
  ios_base::sync_with_stdio(false); 
  ll a,b,c,k;
   cin>>a>>b>>c;
   cin>>k;
   while(k--){
   if(c<=a||c<=b) c=c*2;
    else{
    if(b<=a) b=b*2;
      else c=c*2;
    }
   }
   if(c>b&&c>a&&b>a) cout<<"Yes";
   else cout<<"No";
    return 0;
}

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

int main() {
	string s,t;
	cin>>s>>t;
	for (int i=0; i<s.size(); i++) {
		if (s == t) {
			cout<<"Yes"<<endl;
			return 0;
		}
		s = s.substr(1) + s.substr(0,1);
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <limits>
using namespace std;
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define lli long long int
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define um unordered_map
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define mem(data_structure, val) memset(data_structure, val, sizeof(data_structure))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define endl "\n"
const ll mod = 1e9+7;
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vll;
typedef vector<pii>		vpii;
typedef vector<pll>		vpll;
typedef vector<vi>		vvi;
typedef vector<vll>		vvll;

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
}; 
um<pii, int, hash_pair> map_with_pair{};
priority_queue <int, vector<int>, greater<int> > pq_desc; // decreasing order


int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	lli n;
	cin >> n;
	lli a[n];
	multiset<lli, greater<lli>> g;
	fo(i, n) {
		cin >> a[i];
		g.insert(a[i]);
	}

	fo(i, n) {
		auto f_id = g.find(a[i]);
		g.erase(f_id);
		auto it = g.begin();
		cout << *it << endl;
		g.insert(a[i]);
	}

	return 0;
}

Measured memory_bytes: 12544
N = int(input())
info = [0]
for _ in range(N):
    A = int(input())
    tmp = []
    for i in range(A):
        x, y = map(int, input().split())
        tmp.append((x, y))
    info.append(tmp)

ans = 0
for i in range(2**N):
    i_bin = list(map(int, bin(i)[2:].zfill(N)))
    ok = 1
    for j in range(1, N+1):
        for x, y in info[j]:
            if i_bin[j-1] == 1:
                if i_bin[x-1] != y:
                    ok = 0
    if ok:
        ans = max(ans, sum(i_bin))
print(ans)


Measured memory_bytes: 43884
MOD = 10 ** 9 + 7


def main():
    h, w, k = map(int, input().split())

    dp = [[0 for j in range(w)] for i in range(h+1)]
    dp[0][0] = 1
    for i in range(h):
        for j in range(w):
            for l in range(2**(w-1)):
                for m in range(w-2):
                    if (l >> m) & 1 and (l >> (m+1) & 1):
                        break
                else:
                    if j < w - 1 and (l >> j) & 1:
                        dp[i+1][j+1] += dp[i][j]
                        dp[i+1][j+1] %= MOD
                    elif 0 < j and (l >> (j-1)) & 1:
                        dp[i+1][j-1] += dp[i][j]
                        dp[i+1][j-1] %= MOD
                    else:
                        dp[i+1][j] += dp[i][j]
                        dp[i+1][j] %= MOD

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


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
      int n =sc.nextInt();
      long k = sc.nextLong();
      Long arr[] = new Long[n];
      for(int i=0;i<n;i++){
        arr[i]  = sc.nextLong();
      }
      Arrays.sort(arr);long sum =0;
      for(int i=0;i<(n-k);i++){
          sum += arr[i];
      }
      System.out.println(sum);
  }
}


Measured memory_bytes: 87476
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(in);
    int n = Integer.parseInt(sc.next());
    int m = Integer.parseInt(sc.next());
int[] a=new int[m];
int[] b=new int[m];
HashMap<Integer,Integer> map=new HashMap<>();
for (int i = 0; i < m; i++) {
    a[i]=Integer.parseInt(sc.next());
    b[i]=Integer.parseInt(sc.next());
}
    for (int i = 1; i <= n; i++) {
        map.put(i, 0);
    }
    for (int i = 0; i < m; i++) {
        int c=map.get(a[i])+1;
        map.put(a[i], c);
        c=map.get(b[i])+1;
        map.put(b[i], c);
    }
    for (int i = 1; i <= n; i++) {
        out.println(map.get(i));
    }
}
}


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


/*
    Weighted Union Find Tree
        difference manegement
*/


template<class Abel> struct WeightedUnionFind {
    vector<int> data; vector<Abel> cost; int sz;
    WeightedUnionFind(int sz, Abel unit = 0) : data(sz,-1), cost(sz,unit), sz(sz) { }
    bool unionSet(int x, int y, Abel w) {
        w += (weight(x) - weight(y));
        if ((x = root(x)) == (y = root(y))) { return false; }
        if (data[x] > data[y]) { swap(x, y); w = -w; }
        data[x] += data[y]; data[y] = x; cost[y] = w; sz--; return true;
    }
    bool findSet(int x, int y) { return root(x) == root(y); }
    int root(int x) {
        if (data[x] < 0) return x;
        int r = root(data[x]); cost[x] += cost[data[x]]; return data[x] = r;
    }
    Abel weight(int x) { root(x); return cost[x]; }
    Abel diff(int x, int y) { return weight(y) - weight(x); }
    int size(int x) { return -data[root(x)]; }
    int size() { return sz; }
};



int main() {
    int N, M;
    cin >> N >> M;
    bool judge = true;
    WeightedUnionFind<int> uf(N);
    
    for (int i = 0; i < M; i++) {
        int L, R, D;
        cin >> L >> R >> D;
        L--; R--;
        if (!uf.unionSet(L, R, D)) {
            int diff = uf.diff(L, R);
            if (D != diff) judge = false;
        }
    }
    
    cout << ((judge) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define OUT(x) cout << (x) << endl;
#define OUTA(a, n) \
    REP(i, n) { cout << (a[i]) << (i == n - 1 ? "\n" : " "); }
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

int main()
{
    ll N, A, B;
    cin >> N >> A >> B;
    ll ans = (N / (A + B)) * A + min(A, (N % (A + B)));
    OUT(ans);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <map>
#include <math.h>
#include <algorithm> // std::sort, std::min
#include <iomanip> // std::setprecision
#include <cmath>

int main() {
  long int A, B;
  std::cin >> A >> B;
  double x, y;
  x = static_cast<double>(A)*12.5; // /0.08 
  y = static_cast<double>(B)*10;  //  /.1
  int priceA = static_cast<int>(std::ceil(x));
  int priceB = static_cast<int>(y);
  
  for(int i=0; i<10; ++i) {
    int priceB_ = priceB + i;
    for(int j=0; j<12; ++j) {
      int priceA_ = priceA + j;
      if (priceB_==priceA_) {
        std::cout << priceB_ << std::endl;
        return 0;
      }
    }
  }
  std::cout << "-1" << std::endl;
  return 0;
}

Measured memory_bytes: 256
import numpy as np
N = list(map(int, input().split()))[0]
A = np.array(list(map(int, input().split())))
def get_result(ary):
    cumsum_left = np.cumsum(ary)
    cumsum_right = np.cumsum(ary[::-1])
    d = np.abs(cumsum_left[:-1] - cumsum_right[::-1][1:])
    return np.min(d)
print(get_result(A))

Measured memory_bytes: 34216
#include<iostream>

using namespace std;

int main()
{
    int a,n,b=0,c=1,s[a];
    cin>>a>>n;
    for(int i=0;i<a;i++)
    {
        cin>>s[i];
        b=b+s[i];
        if(b<=n)
            c++;
    }
    cout<<c;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a[4],e,f,i,j,k,sum,max,max2;
	for(i=0;i<4;i++){
		scanf("%d",&a[i]);
	}
	scanf("%d",&e);
	scanf("%d",&f);
	for(j=0;j<4-1;j++){
		for(k=j+1;k<4;k++){
			if(a[j]<a[k]){
				sum=a[j];
				a[j]=a[k];
				a[k]=sum;
			}
		}
	}
	max=a[0]+a[1]+a[2];
	if(e<=f){
		max2=f;
	}
	else{
		max2=e;
	}
	printf("%d\n",max+max2);
	return 0;
}


Measured memory_bytes: 2040
participants,p,quiz=map(int,input().split())
answer_lst = [0 for _ in range(participants+1)]

for _ in range(quiz):
    answer = int(input())
    answer_lst[answer] = answer_lst[answer]+1

for i in range(1,len(answer_lst)):
    if p-(quiz-answer_lst[i]) > 0:
        print("Yes")
    else:
        print("No")


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

int main(){
    int N; cin >> N;
    int a[200200], b[200200];
    for(int i=0; i<N; i++){
        cin >> a[i];
    }
    for(int i=0; i<N; i++){
        cin >> b[i];
    }
    ll ans=0;
    for(int i=0; i<31; i++){
    //まず,i桁目で0+1となるのと1+0となるのを数える
        int num_a_0=0, num_a_1=0, num_b_0=0, num_b_1=0;
        for(int j=0; j<N; j++){
            if(a[j]%( 1<<(i+1) ) >= (1<<i) ) num_a_1++;
            else num_a_0++;
            if(b[j]%( 1<<(i+1) ) >= (1<<i) ) num_b_1++;
            else num_b_0++;
        }
        if(i==0){
            ans += ( (ll) num_a_0*num_b_1+ (ll) num_a_1*num_b_0)%2LL;
            continue;
        }
    //一個下の桁からの繰り上がりを考える
        int a1[200200], b1[200200]; //aとかの下i-1桁を入れる
        for(int j=0; j<N; j++){
            a1[j] = a[j] % (1<< (i) );
            b1[j] = b[j] % (1<< (i) );
        }
        sort(a1,a1+N);
        sort(b1,b1+N);
        ll num_kuri=0;
        int r=N-1;
        for(int j=0; j<N; j++){
            while(r>=0 && a1[j]+b1[r] >=(1<<i) ){
                r--;
            }
            num_kuri +=N-1-r;
        }
        ans +=( (ll) num_a_0*num_b_1+ (ll) num_a_1*num_b_0 + num_kuri) %2LL *(1<<i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N,M;
std::tuple<int64_t, int64_t, int64_t> operator+(const std::tuple<int64_t, int64_t, int64_t>& a, const std::tuple<int64_t, int64_t, int64_t>& b) {
	return { std::get<0>(a) + std::get<0>(b), std::get<1>(a) + std::get<1>(b), std::get<2>(a) + std::get<2>(b) };
}

std::tuple<int64_t, int64_t, int64_t> xyz[1000];
bool used[1000][1001][3][3][3];
std::tuple<int64_t, int64_t, int64_t> DP[1000][1001][3][3][3];
std::tuple<int64_t, int64_t, int64_t> func(int i, int m, int n1, int n2, int n3)
{
	if (m == 0) {
		return { 0 ,0,0 };
	}
	if (i == N) {
		return { n1*-100000000000000 ,n2*-100000000000000,n3*-100000000000000 };
	}
	if (used[i][m][n1 + 1][n2 + 1][n3 + 1]) {
		return DP[i][m][n1 + 1][n2 + 1][n3 + 1];
	}
	used[i][m][n1 + 1][n2 + 1][n3 + 1] = true;
	auto a = func(i + 1, m, n1, n2, n3);
	auto b = func(i + 1, m - 1, n1, n2, n3) + xyz[i];

	auto a_score = n1 * std::get<0>(a) + n2 * std::get<1>(a) + n3 * std::get<2>(a);
	auto b_score = n1 * std::get<0>(b) + n2 * std::get<1>(b) + n3 * std::get<2>(b);

	if (a_score > b_score) {
		return DP[i][m][n1 + 1][n2 + 1][n3 + 1]=a;
	}
	else {
		return DP[i][m][n1 + 1][n2 + 1][n3 + 1] = b;
	}
}

template<typename T, typename U>
std::enable_if_t<std::rank<T>::value == 0> fill_all(T& arr, const U& v) {
	arr = v;
}
template<typename ARR, typename U>
std::enable_if_t<std::rank<ARR>::value != 0> fill_all(ARR& arr, const U& v) {
	for (auto& i : arr) {
		fill_all(i, v);
	}
}
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);
	in >> N >> M;
	for (size_t i = 0; i < N; i++)
	{
		in >> std::get<0>(xyz[i]) >> std::get<1>(xyz[i]) >> std::get<2>(xyz[i]);
	}
	int64_t score = 0;
	for (int i = -1; i <= 1; i+=2)
		for (int j = -1; j <= 1; j += 2)
			for (int k = -1; k <= 1; k += 2)
	{
		auto a = func(0, M, i, j, k);
		auto score_TMP = i * std::get<0>(a) + j * std::get<1>(a) + k * std::get<2>(a);
		if (score_TMP > score) {
			score = score_TMP;
		}
	}
	out << score << endl;

	return 0;
}
#endif


Measured memory_bytes: 658688
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).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; }
typedef long long ll;
const long long INF = 1LL << 60;
int main()
{
    int N;
    cin >> N;
    vector<int> ans(N);

    rep(i, N) {
        int A;
        cin >> A;
        ans[A - 1] = i + 1;
    }

    rep(i, N - 1) {
        cout << ans[i] << " ";
    }
    cout << ans[N - 1] << endl;
    return 0;
}

Measured memory_bytes: 1152
#include<cstdio>
#include<cctype>
#include<bits/stdc++.h>
#define For(i,a,b) for(i=(a);i<=(b);++i)
#define Forward(i,a,b) for(i=(a);i>=(b);--i)
#define Rep(i,a,b) for(register int i=(a);i<=(b);++i)
#define Repe(i,a,b) for(register int i=(a);i>=(b);--i)
#define Chkmax(a,b) a=a>b?a:b
#define Chkmin(a,b) a=a<b?a:b
using namespace std;
template<typename T>inline void read(T &x)
{
	T s=0,f=1;static char c;
	for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
	for(;isdigit(c);c=getchar())s=s*10+(c^48);
	x=s*f;
}
const int MAXN=1e5+7;
static int n;
static long long c,x[MAXN],v[MAXN];
inline void init()
{
	read(n);read(c);
	Rep(i,1,n)read(x[i]),read(v[i]);
}
static long long ans,p[MAXN],bac[MAXN],bp[MAXN],fp[MAXN];
inline void solve()
{
	bp[n+1]=fp[0]=-10000000000000000ll;
	Rep(i,1,n)
	{
		p[i]=p[i-1]+v[i];
		fp[i]=max(fp[i-1],p[i]-x[i]);
	}
	Repe(i,n,1)
	{
		bac[i]=bac[i+1]+v[i];
		bp[i]=max(bp[i+1],bac[i]-c+x[i]);
	}
	Rep(i,1,n)
	{
		Chkmax(ans,p[i]-x[i]);
		Chkmax(ans,p[i]-x[i]*2+bp[i+1]);
	}
	Repe(i,n,1)
	{
		Chkmax(ans,bac[i]-c+x[i]);
		Chkmax(ans,bac[i]-c*2+x[i]*2+fp[i-1]);
	}
	printf("%lld\n",ans);
}
int main()
{
	init();
	solve();
	return 0;
}



Measured memory_bytes: 4992
s = list(map(int,list(input())))
a = s.pop(0)

bit_n = 3
for i in range(2**bit_n):
    sign = ['+']*3
    tmp = a
    for j in range(bit_n):
        if ((i>>j)&1):
            tmp+=s[j]
        else:
            tmp-=s[j]
            sign[j]='-'
    if tmp==7:
        print("{0}{1[0]}{2[0]}{1[1]}{2[1]}{1[2]}{2[2]}=7".format(a,sign,s));exit()

Measured memory_bytes: 3064