akhauriyash/Code-Regression huggingface dataset:
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }

void main()
{
	auto N = RD;
	auto M = RD;
	auto A = RDA;

	long cnt = A.sum;
	
	writeln(cnt > N ? -1 : N - cnt);
	stdout.flush;
	debug readln;
}

Measured memory_bytes: 3000
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>

using namespace std;

#define all(c) c.begin(),c.end()
#define repeat(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")"<< endl

typedef long long ll;
typedef vector<int> vi;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec){
    os << "[";
    for(int i = 0; i < vec.size(); i++){
        os << vec[i] << ",";
    }
    os << "]";
    return os;
}

template<typename T>
T input(){
    T t;
    cin >> t;
    return t;
}

template<typename T>
vector<T> input(const int N){
    vector<T> v(N);
    repeat(i,N) cin >> v[i];
    return v;
}

long long gcd(long long a, long long b){
    if(b == 0){
        return a;
    }
    return gcd(b, a % b);
}

long long lcm(long long a, long long b){
    return (a / gcd(a, b)) * b;
}

int main(){
    string postfix = "FESTIVAL";
    string name;
    cin >> name;
    size_t pos = name.rfind(postfix);
    cout << name.substr(0, pos) << endl;
    return 0;
}

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

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


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

int main() {
	ll w1,w2;
	vector<ll>v(3);
	for(int i=0;i<3;i++){
		cin>>v.at(i);
	}
	sort(v.begin(),v.end(),greater<ll>());
	if(v.at(0)%2==0){
		cout<<0<<endl;
	}else{
		w1=v.at(0)/2+1;
		w2=v.at(0)/2;
		cout<<v.at(1)*v.at(2)*(w1-w2)<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 
 
 
  int main(){
   lint n;
   cin>>n;
   lint b[10005];
   fill(b,b+10005,0);
    repp(i,1,sqrt(n+1)){
        repp(j,1,sqrt(n+1)){
            repp(k,1,sqrt(n+1)){
                lint a=i*i+j*j+k*k+i*j+j*k+i*k;
                if(a>n)break;
               b[a-1]++;
            
        }
    }
    
   }
   rep(i,n)cout<<b[i]<<endl;
     }
  
     
 

Measured memory_bytes: 3648
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

K, X = MAP()

for i in range(X-K+1, X+K):
	if -1000000 <= i <= 1000000:
		print(i, end=" ")
print()


Measured memory_bytes: 5204
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;



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


Measured memory_bytes: 3616
#include <stdio.h>
#define N 1000
#define INF 1000000
 int main(){
   int n,i,j,u,k,v,mincost;
    int d[N],color[N],G[N][N];
     
    scanf("%d",&n);
     
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            G[i][j]=INF;
        }
    }
     
    for(i=0;i<n;i++){
        d[i]=INF;
        color[i]=0;
        scanf("%d %d",&u,&k);
        for(j=0;j<k;j++){
            scanf("%d",&v);
            scanf("%d",&G[u][v]);
        }
    }
    d[0]=0;
     
    while(1){
        mincost=INF;
        for(i=0;i<n;i++){
            if(d[i]<mincost && color[i]==0){
                mincost=d[i];
                u=i;
            }
        }
         
        if(mincost==INF)break;
        color[u]=1;
         
	 for(v=0;v<n;v++){
            if(d[v]>d[u]+G[u][v]){
                d[v]=d[u]+G[u][v];
            }
        }
    }
    for(i = 0;i < n; i++){
        printf("%d %d\n", i, d[i]);
    }
    return 0;
}

Measured memory_bytes: 2728
#include<bits/stdc++.h>
using namespace std;
  int n,m;

int aaa(int l,int r){
  return r-l>=0 ? r-l : m-l+r;
}

int main(){
  cin>>n>>m;
  vector<int> a(n);
  vector<vector<int>> basho(m);
  for(int i=0;i<n;i++){
    cin>>a[i];
    a[i]--;
    basho[a[i]].push_back(i);
  }

  //x=0;
  long long int res=0;
  for(int i=1;i<n;i++){
    res+=min(aaa(a[i-1],a[i]),aaa(0,a[i])+1);

  }
  long long int pre=res;
  int otoku=0;

  for(int i=1;i<n;i++){
    if(aaa(a[i-1],a[i])==aaa(a[i-1],0)+aaa(0,a[i])){
      otoku++;
    }
    if(a[i-1]==0){
      pre++;
    }
  }

  for(int x=1;x<=m-1;x++){
    for(int i=0;i<basho[x-1].size();i++){
      if(basho[x-1][i]!=0){
	int inde=basho[x-1][i];
	pre+=aaa(a[inde-1],a[inde])-1;
	otoku--;
      }
    }
    res=min(res,pre-otoku);
    pre=pre-otoku;
    for(int i=0;i<basho[x].size();i++){
      if(basho[x][i]!=n-1){
	pre++;
	otoku++;
      }
    }
  }
  cout<<res<<endl;
  
  
  
  
  return 0;
}


Measured memory_bytes: 5376
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
s = input()
ans = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
memo = ''
for i in range(len(s)):
    memo += ans[ans.index(s[i]) + n]
print(memo)


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

int digit_sum(int x){

  int counter  = 0;

  while(x >= 1){
    counter += x % 10;
    x /= 10;
  }
  return counter;
}

int main() {
  int N;
  cin >> N;
  int counter = 0;
  int digit_min = 100000;

  for(int i = 1;i < N;i++){
      int x = digit_sum(i);
      int y = digit_sum(N - i);
      digit_min = min(x + y,digit_min);
  }

  cout << digit_min << 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 all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  /*
  if(a == c){
    if(b < d) cout << a + b-d << " " << d <<" "<< a + b-d <<" "<< b << endl; 
    else cout << a - b+d << " " << b <<" "<< a - b+d <<" "<< d << endl; 
  }
  if(b == d){
    if(a > c) cout << c << " " << b-a+c <<" "<< a<<" "<< b-a+c << endl; 
    else cout << c <<" "<< d+a-c <<" "<< a <<""<< d+c-a << endl; 
  }
  */
  int dx = c - a;
  int dy = d - b;
  cout << c - dy <<" ";
  cout << d + dx <<" ";
  cout << a - dy <<" ";
  cout << b + dx <<" ";
  cout << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using P=pair<int,int>;
int main(){
    int N,a=0,b=0,A,B;
    cin>>N;
    vector<P> Bracketfirst(0);
    vector<P> Bracketsecond(0);
    for(int i=0;i<N;i++){
        A=0,B=0;
        string S;
        cin>>S;
        for(int j=0;j<(int)S.size();j++){
            if(S.at(j)=='('){
                A++;
            }
            else{
                if(A>0){
                    A--;
                }
                else{
                    B++;
                }
            }
        }
        if(A>=B){
            Bracketfirst.push_back(make_pair(B,A));
        }
        else{
            Bracketsecond.push_back(make_pair(A,B));
        }
    }
    sort(Bracketfirst.begin(),Bracketfirst.end());
    sort(Bracketsecond.begin(),Bracketsecond.end());
    reverse(Bracketsecond.begin(),Bracketsecond.end());
    for(int i=0;i<(int)Bracketfirst.size();i++){
        for(int j=0;j<Bracketfirst.at(i).first;j++){
            b++;
        }
        if(a<b){
            cout<<"No"<<endl;
            return 0;
        }
        for(int j=0;j<Bracketfirst.at(i).second;j++){
            a++;
        }
    }
    for(int i=0;i<(int)Bracketsecond.size();i++){
        for(int j=0;j<Bracketsecond.at(i).second;j++){
            b++;
        }
        if(a<b){
            cout<<"No"<<endl;
            return 0;
        }
        for(int j=0;j<Bracketsecond.at(i).first;j++){
            a++;
        }
    }
    if(a==b){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 11144
#include <iostream>
#include <set>
#include <algorithm>
#include <string>
int main()
{
	int64_t A;
	std::string Bstr;
	std::cin >> A >> Bstr;
	auto pos = Bstr.find(".");
	size_t col = 0;
	if (pos != std::string::npos) {
		Bstr.erase(pos, 1);
		col = Bstr.size() - pos;
	}
	else {
	}
	int64_t B = strtoll(Bstr.c_str(), nullptr, 10);
	int64_t ans = A * B;
	for (int i = 0; i < col; ++i)
	{
		ans /= 10;
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#define inf 1e9

using namespace std;
typedef pair<int, int> P;

struct edge{
	int u, v;
	int cost;
	edge(){}
	edge(int a, int b, int c){
		u = a, v = b, cost = c;
	}
	int get(int a)
	{
		if(u == a) return v;
		else return u;
	}
};

int N;
vector<int> G[100005];
edge E[100005];
int cnt[16];

int V = 1 << 16, S;
int dist[1<<16];

void bfs(){
	for(int i = 0; i < V; i++) dist[i] = inf;
	dist[S] = 0;
	
	priority_queue<P, vector<P>, greater<P> > Q;
	Q.push(make_pair(0, S));
	int d, v, nv;
	while(Q.size()){
		v = Q.top().second;
		d = Q.top().first;
		Q.pop();
		if(dist[v] < d) continue;
		if(v == 0) break;
		for(int i = 1; i < 16; i++){
			if((v & (1<<i)) == 0) continue;
			for(int j = 1; j < 16; j++){
				if((v & (1<<j)) == 0) continue;
				if(i == j) continue;
				nv = v;
				nv &= ~(1<<i);
				nv &= ~(1<<j);
				nv ^= 1<<(i^j);
				int nd = dist[v] + 1;
				if((nv & (1<<(i^j))) == 0) nd++;
				if(dist[nv] > nd){
					dist[nv] = nd;
					Q.push(make_pair(dist[nv], nv));
				}
				//cout << i << " " << j << " " << v << " " << nv << endl;
			}
		}
	}
}

void dfs(int v, int prev)
{
	int val = 0;
	for(int i = 0; i < G[v].size(); i++) val ^= E[G[v][i]].cost;
	cnt[val]++;
	
	for(int i = 0; i < G[v].size(); i++){
		if(E[G[v][i]].get(v) == prev) continue;
		dfs(E[G[v][i]].get(v), v);
	}
}

int main(void)
{
	cin >> N;
	int x, y, a;
	for(int i = 0; i < N-1; i++){
		cin >> x >> y >> a;
		G[x].push_back(i);
		G[y].push_back(i);
		E[i] = edge(x, y, a);
	}
	
	dfs(0, -1);
	//for(int i = 0; i < 16; i++) cout << cnt[i] << " "; cout << endl;
	
	int ans = 0;
	for(int i = 1; i < 16; i++){
		ans += cnt[i] / 2;
		cnt[i] %= 2;
	}
	cnt[0] = 0;
	for(int i = 0; i < 16; i++) if(cnt[i]) S += (1<<i);
	
	bfs();
	ans += dist[0];
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 11648
n = int(input())
a = [int(i) for i in input().split()]

b1 = b2 = b4 = 0
for i in range(n):
    if a[i]%4 == 0:
        b4 += 1
    elif a[i] %2 == 0:
        b2 += 1
    else:
        b1 += 1

if b2 == 0:
    ans = "Yes" if b4 + 1 >= b1 else "No"
else:
    ans = "Yes" if b4 >= b1 else "No"

print(ans)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define N 1000000007
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,m,i,ans,x;
    string s;
    cin>>n>>m>>s;
    deque <pair<ll,ll>> dq;
    ll j[n+1] = {0};
    dq.pb(mp(n,0));
    for(i=n-1;i>=0;i--)
    {
        if(s[i] == '1')
            continue;
        while(dq.size() and dq.back().ff > i+m)
            dq.pop_back();
        while(dq.size())
        {
            auto ele = dq.back();
            dq.pop_back();
            if(dq.size() and dq.back().ss == ele.ss)
                continue;
            dq.push_back(ele);
            break;
        }
        if(dq.size() == 0)
        {
            cout<<-1;
            return 0;
        }
        dq.push_front(mp(i, dq.back().ss+1));
        j[i] = dq.back().ff;
    }
    i = 0;
    while(i < n)
    {
        x = i;
        i = j[i];
        cout<<i-x<<" ";
    }
    return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <cctype>
#include <map>
#include <vector>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main() {
	int k, n;
	cin >> k >> n;
	vector<int> a(n);
	int sum = 0, maxv=0;
	rep(i, 0, n) {
		cin >> a[i];
	}
	a.push_back(k + a[0]);
	int l = 0;
	rep(i, 0, n) {
		l = max(l, a[i + 1] - a[i]);

	}
	cout << k - l << endl;
	return 0;
}

Measured memory_bytes: 1920
import Foundation
 
let input_line = readLine()!
 
let split = input_line.componentsSeparatedByString(" ") //components(separatedBy:)と実質同じ
let N = Int(split[0])!
let X = Int(split[1])!
 
var Li = [Int]()
let input_line2 = readLine()!

for i in 0..<N {
    let splits = input_line2.componentsSeparatedByString(" ") //components(separatedBy:)と実質同じ
	Li = splits.map {Int($0)!}
}

var counter = 1
var boundPosition = 0

for j in 0..<N {
    boundPosition += Li[j]
    if X < boundPosition {
        break
    }
    counter += 1
}

print(counter)

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

const long long int MOD = 1000000007;

int main(){
    int n, m;
    cin >> n >> m;

    vector<int> a(m+1,0);
    queue<int> q;
    for(int i=0; i<m; i++){
        cin >> a[i];
    }

    vector<long long int> dp(n+1,0);
    int broken = 0;
    dp[0] = 1;
    if(a[broken] != 1){
        dp[1] = 1;
    }else{
        broken += 1;
    }
    for(int i=2; i<n+1; i++){
        if(i != a[broken]){
            dp[i] = (dp[i-1] + dp[i-2]) % MOD;
        }else{
            broken += 1;
        }
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <numeric>
#include <iostream>
#include <sstream>
#include <vector>
#include <cstdio>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <string>
#include <bitset>
#include <cassert>
#include <algorithm>
#include <cmath>
#include <set>
#include <algorithm>
#include <tuple>
#include <sstream>

using namespace std;

#ifdef LOCAL
#define logv(a) {cerr << #a << " = "; for (auto& e : a) {cerr << e << " ";} cerr << "\n";}
#define logvp(a) {cerr << #a << " = "; for (auto& e : a) {cerr << "(" << e.first << ", " << e.second << ") ";} cerr << "\n";}
#define logvv(a) {cerr << #a << " = \n"; for (auto& r : a) { for (auto& e : r) {cerr << e << " ";} cerr << "\n";} }
#define logvf(a, field) {cerr << #a"."#field << " = \n"; for (auto& e : a) { cerr << e.field << " ";} cerr << "\n"; }
#define logs(a) cerr << #a << " = " << (a) << "\n";
#define logss(a, b) cerr << #a << " = " << (a) << ", " << #b << " = " << (b) << "\n";
#define logp(a) cerr << #a << " = " << "(" << a.first << ", " << a.second << ")" << "\n";
#define cond(pred, stmt) if (pred) { stmt }
#else
#define logv(a)
#define logvp(a)
#define logvv(a)
#define logvf(a, field)
#define logs(a)
#define logss(a, b)
#define logp(a)
#define cond(pred, stmt)
#endif

#define forn(a, e) for (int a = 0; a < (int)e; a++)
#define forr(a, s, e) for (int a = s; a < (int)e; a++)

using i64 = long long;

template<typename T>
using Pair = array<T, 2>;

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

    int a, b;
    while (cin >> a >> b) {
        int cur = 1;
        int ans = 0;
        while (cur < b) {
            cur += a;
            cur--;
            ans++;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc095/tasks/arc096_a

A,B,C,X,Y = map(int,input().split())

ans = 0

# MINXY個ずつ買う
MINXY = min(X,Y)
if A+B <= 2 * C:
    ans += (A+B) * MINXY
else:
    ans += (2 * C) * MINXY

X -= MINXY
Y -= MINXY

# 買い忘れを買う
if X == 0:
    if B <= 2 * C:
        ans += B * Y
    else:
        ans += (2 * C) * Y
else:
    if A <= 2 * C:
        ans += A * X
    else:
        ans += (2 * C) * X

print(ans)

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

namespace ABC121
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] strs = Console.ReadLine().Split(' ');
            int H = int.Parse(strs[0]);
            int W = int.Parse(strs[1]);

            string[] strs_ = Console.ReadLine().Split(' ');
            int h = int.Parse(strs_[0]);
            int w = int.Parse(strs_[1]);

            Console.WriteLine("{0}", (H - h) * (W - w));
        }
    }
}


Measured memory_bytes: 13268
A, B, C, D = map(int, input().split())
def gcd(a, b):
    while b != 0:
        a, b = b, a%b
    return a 

def lcm(a, b):
    return (a * b) // gcd(a, b)

print((B - (A-1)) - (
    (B//C + B//D - B//lcm(C, D)) - ((A-1)//C + (A-1)//D - (A-1)//lcm(C, D))
    ))

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <assert.h>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,a) for(ll i=ll(a-1);i>=0;--i)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}

const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll EPS = 1e-10;
int sgn(const double a){
    return (a < -EPS ? -1 : (a > EPS ? +1 : 0));
}
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> tri;
typedef pair<double,double> point;
typedef complex<double> Point;
const ll MAX = 30000;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    //cin.tie(0);
    //ios::sync_with_stdio(false);
    ll x,k,d;
    cin >> x >> k >> d;
    x = abs(x);
    ll c = x/d;
    if (k <= c){
        PRINT(x-k*d);
    }
    else{
        x -= c*d;
        k -= c;
        if (k%2){
            PRINT(abs(x-d));
        }
        else{
            PRINT(x);
        }
    }
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

const int MAX_V = 200;
vi G[MAX_V];
vi color(MAX_V,0);
bool dfs(int v, int c){
  color[v] = c;
  rep(i,sz(G[v])){
    if(color[G[v][i]] == c)return false;
    if(color[G[v][i]] == 0 && !dfs(G[v][i],-c))return false;
  }
  return true;
}

int d[MAX_V][MAX_V];

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i,n) cin>>s[i];

  rep(i,n){
    rep(j,n){
      if(s[i][j] == '1'){
        G[i].push_back(j);
        d[i][j] = d[j][i] = 1;
      }
      else if(i == j){
        d[i][j] = d[j][i] = 0;
      }
      else d[i][j] = d[j][i] = 10010010;
    }
  }

  rep(i,n){
    if(color[i] == 0){
      if(!dfs(i,1)){
        cout<<-1<<endl;
        return 0;
      }
    }
  }
  rep(k,n){
    rep(i,n){
      rep(j,n){
        mins(d[i][j],d[i][k] + d[k][j]);
      }
    }
  }
  int ans = 0;
  rep(i,n){
    rep(j,n)maxs(ans,d[i][j]);
  }
  print(ans+1);
  return 0;
}

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

int main(){

    int q;
    cin >> q;
    set<int> st;
    for(int i = 0; i < q; ++i){
        int com, x;
        cin >> com >> x;
        if(com == 0){
            st.insert(x);
            cout << st.size() << endl;
        }
        else{
            cout << (st.find(x) != st.end()) << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 12432
#include<bits/stdc++.h>
#include<iomanip>
#define mins(a,b) a=min(a,b)
#define maxs(a,b) a=max(a,b)
template < typename T > std::string to_string( const T& n )
  {
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
  }
using namespace std;

const long long INF=9000000000000000;
typedef long long ll;

int main(){
  ll a,x,b,c,d,e;
  cin>>x>>b>>c>>d;
  ll ans=0,aans=0;
  a=x-1;
  e=__gcd(c,d);
  ans+=b/d+b/c;
  ans-=b/(e*(c/e)*(d/e));
  ans=b-ans;
  aans+=a/d+a/c;
  aans-=a/(e*(c/e)*(d/e));
  aans=a-aans;
  cout<<ans-aans<<endl;
}
/*int main(){
int n,m,ans=0,nn=0;
cin>>n>>m;
int x[n];
for(int i=m;i<m+n;i++){
  ans+=i;
  x[nn]=abs(i);
  nn++;
}
sort(x,x+n);
if(n+m>=0)
cout<<ans-x[0]<<endl;
else
cout<<ans+x[0]<<endl;
}*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

#define MOD 1000000007

int main(){
  ll N;
  cin >> N;
  vll prime(1000, 0);
  if(N==1){
    cout << 1 << endl;
    return 0;
  }
  for(int i = 2; i <= N; i++){
    ll NN = i;
    for(int j = 2; j*j <= NN; j++){
      if(NN % j == 0){
        ll counter = 0;
        while(NN % j == 0){
          NN /= j;
          counter++;
        }
        prime.at(j)+=counter;
      }
    }
    if(NN != 1){
      prime.at(NN)++;
    }
  }
  ll ans = 1;
  for(int i = 2; i < 1000; i++){
    ans *= prime.at(i) + 1;
    ans %= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+10;
int A[maxn];
int n;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){ scanf("%d",A+i); A[i] -= i; }
	sort(A+1,A+n+1);
	int b = A[(n+1)/2];
	long long int ans = 0;
	for(int i=1;i<=n;++i) ans = ans + abs(A[i]-b);
	cout << ans << endl;
	return 0;
}

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

int n, x, y, a, m1, m2, m3, m4;
int main()
{
	cin >> m2 >> m4 >> n;
	while (n--) {
		scanf("%d %d %d", &x, &y, &a);
		if (a == 1) m1 = max(m1, x);
		else if (a == 2) m2 = min(m2, x);
		else if (a == 3) m3 = max(m3, y);
		else m4 = min(m4, y);
	}
    cout << max(0, m2 - m1) * max(0, m4 - m3) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';

const int mx=100010;
const ll mod=1e9+7;


int main(){
  ll n,x,d;
  cin >> n >> x >> d;
  if(d==0){
    if(x==0){
      cout << 1 << ln; return 0;
    } else {
      cout << n+1 << ln; return 0;
    }
  }

  map<ll,vector<pair<ll,ll>>> mp;
  for(ll k=0; k<=n; k++){
    ll kx = k*x;
    ll l = k*(k-1)/2;
    ll r = k*(2*n-k-1)/2;
    ll ck = kx+l*d;
    ll rk = r-l;
    mp[(ck+(d<<30))%d].emplace_back(ck,rk);
  }

  ll ans = 0;
  for(auto it:mp){
    auto a = it.S;
    int m = a.size();
    rep(i,m){
      a[i].F = (a[i].F-it.F)/d;
    }
    vector<pair<ll,ll>> ev;
    rep(i,m){
      ev.emplace_back(a[i].F,1);
      ev.emplace_back(a[i].F+a[i].S+1, -1);
    }
    sort(ev.begin(),ev.end());
    ll cnt = 0;
    ll pre = -longinf;
    for(auto e:ev){
      ll len = e.F - pre;
      if(cnt>0){
        ans += len;
      }
      cnt += e.S;
      pre = e.F;
    }
  }
  cout << ans << ln;
  return 0;
}

Measured memory_bytes: 22144
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
const int aoi=2018;
int a[aoi];

int main(){
int n=read(),i,z=read(),w=read();
for (i=1;i<=n;++i) a[i]=read();
write(n==1?abs(a[n]-w):max(abs(a[n]-w),abs(a[n-1]-a[n])));
}

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

if a == 0 or b == 0 or (a <0 and b > 0):
    print("Zero")
elif a > 0:
    print("Positive")
else:
    if  (b - a) % 2 == 0:
        print("Negative")
    elif (b - a) % 2 == 1: 
        print("Positive")


Measured memory_bytes: 2940
#include <iostream>

using namespace std;

int main()
{
	int x[5];
	for (int i = 0; i < 5; i++)
	{
		cin >> x[i];
	}
	int ans = 0;
	for (int i = 0; i < 5; i++)
	{
		if (x[i] == 0) {
			ans = i + 1;
			break;
		}
	}
	if (ans == 0) cout << "error" << endl;
	else cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3624
import fractions

N = int(input())
l = list(map(int,input().split()))

L = [0]
R = [0]

gl = 0
gr = 0
for i in range(N):
    gl = fractions.gcd(gl,l[i])
    L.append(gl)
    gr = fractions.gcd(gr,l[N-1-i])
    R.append(gr)

M = []
for i in range(N+1):
    M.append(fractions.gcd(L[i-1],R[N-i]))

print(max(M))

Measured memory_bytes: 16140
import java.io.*;
import java.util.*;
import java.lang.*;

public class Main {

	public static void main(String[] args) {
		FastReader in = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		int D  = in.nextInt(), T  = in.nextInt(), S = in.nextInt();
		double timeRequired = (double)D/S;
		if(timeRequired<=(double)T) out.println("Yes");
		else out.println("No");
		out.close();
	}

	static final Random random=new Random();
	//	static void ruffleSort(Pair[] a) {
	//		int n=a.length;//shuffle, then sort 
	//		for (int i=0; i<n; i++) {
	//			int oi=random.nextInt(n);
	//			Pair temp=a[oi];
	//			a[oi]=a[i]; a[i]=temp;
	//		}
	//		Arrays.sort(a);
	//	}
	static void ruffleSort(int[] a) {
		int n=a.length;//shuffle, then sort 
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n), temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}
	static void ruffleSort(char[] a) {
		int n=a.length;//shuffle, then sort 
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n);
			char temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}
	static class FastReader 
	{ 
		BufferedReader br; 
		StringTokenizer st; 

		public FastReader() 
		{ 
			br = new BufferedReader(new
					InputStreamReader(System.in)); 
		} 

		String next() 
		{ 
			while (st == null || !st.hasMoreElements()) 
			{ 
				try
				{ 
					st = new StringTokenizer(br.readLine()); 
				} 
				catch (IOException  e) 
				{ 
					e.printStackTrace(); 
				} 
			} 
			return st.nextToken(); 
		} 

		int nextInt() 
		{ 
			return Integer.parseInt(next()); 
		} 

		long nextLong() 
		{ 
			return Long.parseLong(next()); 
		} 

		double nextDouble() 
		{ 
			return Double.parseDouble(next()); 
		} 

		String nextLine() 
		{ 
			String str = ""; 
			try
			{ 
				str = br.readLine(); 
			} 
			catch (IOException e) 
			{ 
				e.printStackTrace(); 
			} 
			return str; 
		} 

		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
	}
}

//class Pair implements Comparable<Pair>{
//    int a;
//    int b;
//    public Pair(int a, int b) {
//        this.a = a;
//        this.b = b;
//    }
//    public int compareTo(Pair o) {
//        if(this.a==o.a)
//            return this.b - o.b;
//        return this.a - o.a;
//    }   
//}

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

int main() {
	int a, b, output;
	char op;

	cin >> a >> op >> b ;

	while (1) {
		if (op == '?')break;
		
		if (op == '+') {
			output = a + b;
		}
		else if (op == '-') {
			output = a - b;
		}
		else if (op == '*') {
			output = a * b;
		}
		else if (op == '/') {
			output = a / b;
		}

		if (op == '+' || op == '-' || op == '*' || op == '/') {
			cout << output << endl;
		}
		cin >> a >> op >> b ;
	}
	return 0;
}


Measured memory_bytes: 3088
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(container) container.begin(),container.end()
#define fast ios::sync_with_stdio(0); cin.tie(0)
#ifndef ONLINE_JUDGE
#include "debug.cpp"
#endif
#define int unsigned long long
const int mod = 1e9+7;  
int power(int a,int b) { if(b==0) return 1; int res = power(a,b/2); if(b&1) return res * res * a; else return res * res; }


int32_t main(){
    
  fast;
  int n,k; cin >> n >> k;
  int ar[n];
  for(int i=0;i<n;i++) cin >> ar[i];

  for(int i=k;i<n;i++){
    if(ar[i]>ar[i-k]) cout << "Yes\n";
    else cout << "No\n";
  }

  return 0;
}

Measured memory_bytes: 5148
N = int(input())
AC = 0
WA = 0
TLE = 0
RE = 0
for i in range(N):
    new = input()
    if new == "AC":
        AC += 1
    elif new == "WA":
        WA += 1
    elif new == "TLE":
        TLE += 1
    else:
        RE += 1
        
print("AC x", AC)
print("WA x", WA)
print("TLE x", TLE)
print("RE x", RE)

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

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  ll n, a, b; cin >> n >> a >> b;
  vector<ll> x;
  for(int i = 0; i < n; i++) {
    int t; cin >> t;
    x.emplace_back(t);
  }
  ll ok = 1e9, ng = 0;
  while(ok - ng > 1) {
    ll mid = (ok + ng) / 2;
    ll k = 0;
    for(int i = 0; i < n; i++) {
      k += (max(0ll, x[i] - b * mid) + (a-b) - 1) / (a-b);
    }
    if(k <= mid) ok = mid;
    else ng = mid;
  }
  cout << ok << endl;
  return 0;
}


Measured memory_bytes: 1400
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ASomethingOnIt solver = new ASomethingOnIt();
        solver.solve(1, in, out);
        out.close();
    }

    static class ASomethingOnIt {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            out.println(700 + in.next().chars().filter(c -> c == 'o').count() * 100);
        }

    }
}



Measured memory_bytes: 28244
#include <cstdio>
#include <vector>
#include <iostream>
#include <cmath>
#define INF 500000+500
#define Max 0x3f3f3f3f
#define Mod 1000000007
typedef long long int ll;
using namespace std;
int main() 
{
	ll n,m;
    cin >> n >> m;
    ll l=min(n,m);
    ll r=max(n,m);
    for(int i=l+1; i<r; i++) {
    	ll t1 = abs(l-i);
    	ll t2 = abs(r-i);
    	if(t1==t2) {
    		cout << i << endl;
    		return 0;
		}
	}
	
	cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 256
// Package main provides
//
// File:  d.go
// Author: ymiyamoto
//
// Created on Wed Jan  2 22:09:57 2019
//
package main

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

type route struct {
	to, weight int
}

type node struct {
	routes []route
}

var nodes []node
var nums []int
var sc = bufio.NewScanner(os.Stdin)

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

func dfs(top int, num int) bool {
	if nums[top] == 1<<60 {
		nums[top] = num
	} else {
		return nums[top] == num
	}

	for _, r := range nodes[top].routes {
		if !dfs(r.to, num+r.weight) {
			return false
		}
	}

	return true
}

func main() {
	var N, M int
	fmt.Scan(&N, &M)

	nodes = make([]node, N+1)
	for i := 0; i < M; i++ {
		s := nextLine()
		var l, r, d int
		fmt.Sscan(s, &l, &r, &d)
		nodes[l].routes = append(nodes[l].routes, route{to: r, weight: d})
		nodes[r].routes = append(nodes[r].routes, route{to: l, weight: -d})
	}

	nums = make([]int, N+1)
	for i := range nums {
		nums[i] = 1 << 60
	}

	for i := range nodes {
		if nums[i] == 1<<60 && !dfs(i, 0) {
			fmt.Println("No")
			return
		}
	}

	fmt.Println("Yes")
}


Measured memory_bytes: 39552
#include <stdio.h>

void Quicksort(char *,int *,int,int);
void Bublesort(char *,int *,int);
int Check(char *,char *,int *,int *,int);
int Partition(char *,int *,int,int);
void swap(char *,int *,int,int);
void margesort(char *,int *,int,int);
void marge(char *,int *,int,int,int);


int num[100000],num2[100000];
char mark[100000],mark2[100000];
int numL[50001],numR[500001];
char markL[50001],markR[50001];



int main(){
  int i,j,n;
  char kaigyo;  //改行打消用

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%c",&kaigyo); //改行のscanfをなかったことにするための犠牲
    scanf("%c%d",&mark[i],&num[i]);
  }

    for(i=0;i<n;i++){
    mark2[i]=mark[i];
    num2[i]=num[i];
  }
  
   Quicksort(mark,num,0,n-1);
  
   margesort(mark2,num2,0,n);
  
   if(Check(mark,mark2,num,num2,n) == 1) printf("Stable\n");
  else printf("Not stable\n");
   
  for(i=0;i<n;i++) printf("%c %d\n",mark[i],num[i]);

  return 0;
}

void Quicksort(char *m,int *n,int p,int r){
  int q;
  if(p < r){
    q = Partition(m,n,p,r);
    Quicksort(m,n,p,q-1);
    Quicksort(m,n,q+1,r);
  }

}

int Partition(char *m,int *n,int p,int r){
  int i,j,x,box;
  
  x=n[r];
  j=p-1;
  
  for(i=p;i<r;i++){
    if( n[i] <= x){
      j++;
      swap(m,n,j,i);
    }
  }
  swap(m,n,j+1,r);
  
  return j+1;
}

void swap(char *m,int *n,int p,int q){
  int box;
  char box2;
  
  box2 = m[p];
  m[p]=m[q];
  m[q]=box2;
  
  box = n[p];
  n[p]=n[q];
  n[q]=box;
}


int Check(char *m,char *m2,int *n,int *n2,int a){
  int flg=1,i;

  for(i=0;i<a;i++){
    if(m[i] != m2[i] || n[i] != n2[i]){
      flg = 0;
      break;
    }
  }
  return flg;
}


void margesort(char *m2,int *n2,int left,int right){
  int mid;
  if(left+1 < right){ 
    mid = (left + right)/2;
    margesort(m2,n2,left,mid);
    margesort(m2,n2,mid,right);
    marge(m2,n2,left,mid,right);
  }
}

void marge(char *m2,int *n2,int left,int mid,int right){
  int nl,nr;
  int i,j=0,k;

  nl = mid - left;
  nr = right - mid;

  for(i=0;i<nl;i++){
    markL[i] = m2[left+i];
    numL[i] = n2[left+i];
  }
  numL[nl]=1000000001;
  for(i=0;i<nr;i++){
    markR[i] = m2[mid+i];
    numR[i] = n2[mid+i];
  }
  numR[nr]=1000000001;

  i=0;
  for(k=left;k<right;k++){
  if(numL[i] <= numR[j]){  
    m2[k] = markL[i];
    n2[k] = numL[i];
    i++;
  }
  else{
    m2[k] = markR[j];
    n2[k] = numR[j];
    j++;
  }
  }
}

Measured memory_bytes: 2076
#include <stdio.h>
#include <stdlib.h>

int **G;
int *u, *k, **v;
int n;

void initG() {
	int i, j;

	G = (int **)malloc(sizeof(int *) * (n + 1));

	for (i = 1; i <= n; i++) {
		G[i] = (int *)malloc(sizeof(int) * (n + 1));	
		for (j = 1; j <= n; j++) {
			G[i][j] = 0;
		}
	}
}

void input() {
	int i, j;

	scanf("%d", &n);
	initG();

	k = (int *)malloc(sizeof(int) * (n + 1));
	u = (int *)malloc(sizeof(int) * (n + 1));
	v = (int **)malloc(sizeof(int *) * (n + 1));

	for (i = 1; i <= n; i++) {
		scanf("%d%d", &u[i], &k[i]);
		v[i] = (int *)malloc(sizeof(int) * (k[i] + 1));
		for (j = 1; j <= k[i]; j++) {
			scanf("%d", &v[i][j]);
		}
	}

}

void createAdjacencyMatrix(int a) {
	int i, j;
	for (i = 1; i <= k[a]; i++) {
		for (j = 1; j <= n; j++) {
			if (u[j] == v[a][i])
				G[a][u[j]] = 1;
		}
	}
}

void output() {
	int i, j;
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= n; j++) {
			createAdjacencyMatrix(i);
			if (j != 1) printf(" ");
			printf("%d", G[i][j]);
		}
		puts("");
		free(G[i]);
		free(v[i]);
	}
	free(G);
	free(u);
	free(k);
	free(v);
}

main () {

	input();
	output();

	return 0;
}

Measured memory_bytes: 656
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <cctype>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 1001001001001001001;  // > 10^18
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main () {
    
    ll n,m; cin >>n>>m;
    vector<ll> a(n); vector<ll> b(n);
    REP(i,n) cin >> a[i] >> b[i];
    vector<ll> c(m); vector<ll> d(m);
    REP(i,m) cin >> c[i] >> d[i];

    for (ll i = 0; i < n; i++) {
        ll point = 0;
        ll len = INFLL;
        for (ll j = 0; j < m; j++) {
            if (len > abs(a[i]-c[j]) + abs(b[i]-d[j])) {
                point = j;
                len = abs(a[i]-c[j]) + abs(b[i]-d[j]);
            } 
        }
        cout << ++point << endl;
    }

    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define hi cout<<'h'<<'i'<<'\n' 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define mod2 998244353
#define space 100005
//<<fixed << setprecision(9)

int main()
{
	int n,i,j,t;
	boost;

	cin>>n;
	int arr[n];
	rep(i,0,n)cin>>arr[i];
	sort(arr,arr+n);
	int ans=0;
	rep(i,0,n)
	{
		rep(j,i+1,n)
		{
			int sum=arr[i]+arr[j];
			ans+=lower_bound(arr,arr+n,sum)-arr-j-1;
		}
	}
	cout<<ans;
	return 0;
}



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

using namespace std;

using ll = long long;

int gcd(int a, int b) {
    return b ? gcd(b, a%b) : a;
}

template <typename T>
struct SegmentTree {
    int n;
    vector<T> data;
    T INITIAL_VALUE;

    //使うときは、この2つを適宜変更する
    static T merge(T x, T y);
    void updateNode(int k, T x);

    SegmentTree(int size, T initial_value) {
        n = 1;
        INITIAL_VALUE = initial_value;
        while (n < size) n *= 2;
        data.resize(2 * n - 1, INITIAL_VALUE);
    }

    SegmentTree(const vector<T>& v, T initial_value) {
        int size = v.size();
        n = 1;
        INITIAL_VALUE = initial_value;
        while (n < size) n *= 2;
        data.resize(2 * n - 1, INITIAL_VALUE);

        for (int i = 0; i < size; i++) data[i + n - 1] = v[i];
        for (int i = n - 2; i >= 0; i--) data[i] = merge(data[i * 2 + 1], data[i * 2 + 2]);
    }

    T getLeaf(int k) {
        return data[k + n - 1];
    }

    void update(int k, T x) {
        k += n - 1; //葉の節点
        updateNode(k, x);
        while (k > 0) {
            k = (k - 1) / 2;
            data[k] = merge(data[k * 2 + 1], data[k * 2 + 2]);
        }
    }

    //区間[a, b)に対するクエリに答える
    //k:節点番号, [l, r):節点に対応する区間
    T query(int a, int b, int k, int l, int r) {
        //[a, b)と[l, r)が交差しない場合
        if (r <= a || b <= l) return INITIAL_VALUE;
        //[a, b)が[l, r)を含む場合、節点の値
        if (a <= l && r <= b) return data[k];
        else {
            //二つの子をマージ
            T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return merge(vl, vr);
        }
    }

    //外から呼ぶ用
    T query(int a, int b) {
        return query(a, b, 0, 0, n);
    }

    //非再帰版: バグってるかもしれないので定数倍高速化する時以外使わないで
    //区間[a, b)に対するクエリに答える
    T query_fast(int a, int b) {
        T vl = INITIAL_VALUE, vr = INITIAL_VALUE;
        for (int l = a + n, r = b + n; l != r; l >>= 1, r >>= 1) {
            if (l & 1) vl = merge(vl, data[l++ - 1]);
            if (r & 1) vr = merge(data[--r - 1], vr);
        }
        return merge(vl, vr);
    }
};

//使うときは以下2つを変更
//非可換の場合は順序に注意！！！
template <typename T>
T SegmentTree<T>::merge(T x, T y) {
    return gcd(x, y);
}

template <typename T>
void SegmentTree<T>::updateNode(int k, T x) {
    data[k] = x;
}

const int MAXV = 200000;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    SegmentTree<int> st(a, 0);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans = max(ans, gcd(st.query_fast(0, i), st.query_fast(i + 1, n)));
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

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

  int ans = (b % a == 0)? a + b: b - a;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256