akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int main(){
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    struct G{
        int to, cost;
    };
    vector<vector<G>> g(n);
    rep(i,m) {
        int a,b;
        cin >> a >> b;
        a--;b--;
        g[a].push_back({b,1});
        g[b].push_back({a,1});
    }

    using P = pair<ll,ll>;
    const ll INF = INT64_MAX>>2;
    priority_queue<P, vector<P>, greater<P>> pq;
    vector<ll> d(n,INF);
    vector<ll> prev(n,INF);
    d[0] = 0;
    pq.emplace(make_pair(0,0));
    while(!pq.empty()) {
        P now = pq.top();
        pq.pop();
        int v = now.second;
        if(d[v] < now.first) continue;
        for(auto next: g[v]) {
            if(d[next.to] > d[v] + next.cost) {
                d[next.to] = d[v] + next.cost;
                prev[next.to] = v;
                pq.emplace(make_pair(d[next.to], next.to));
            }
        }
    }
    bool ok = true;
    rep(i,n) if(d[i] == INF) ok = false;
    if(ok) {
        cout << "Yes" << endl;
        for(int i = 1; i < n; i++) {
            cout << prev[i]+1 << endl;
        }
    } else {cout << "No" << endl;}
}


Measured memory_bytes: 14992
#include<bits/stdc++.h>
//#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define bug1( x ) {cerr << (#x) <<"="<< x << endl;}
#define bug2( x , y ) {cerr << (#x) <<"="<< (x) << "    " << (#y) << "="<< (y) << endl;}
#define bug3( x , y , z ) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << endl;}
#define bug4( x , y , z , w) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << endl;}
#define bug5( x , y , z , w ,p) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << endl;}
#define bug6( x , y , z , w ,p , q) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << "    " << (#q) <<"="<< q << endl;}
#define bugn( x , n ) {cerr << (#x) <<":";for(int i=0;i<n;i++)cerr << x[i] <<"  "; cerr << endl;}
#define bugnm( x , n , m ) {cerr << (#x)<<endl;for(int i=0;i<n;i++){cerr << "Row #" << i<< ":";for(int j=0;j<m;j++)cerr << x[i][j] << "   ";cerr << endl;}}
typedef long long ll;
typedef long double ld;
using namespace std;

const int maxn = 1e6+10;
int dp[maxn][10];
string s;
int n;
int solve(int i,int carry){
	//bug2(i,carry);
	if( i >= n )return carry;
	int & ans = dp[i][carry%10];
	if( ans != -1 )return carry/10 + ans;
	ans = 1e8;
	carry += ( i < n ? s[i]-'0' : 0 );
	ans = min( ans , carry % 10 + solve(i+1,carry/10) );
	if( carry%10 ){
		ans = min( ans , 10-(carry%10) + solve(i+1,carry/10 + 1));
	}
	return ans;
}
int32_t main(){
	IOS	
	memset(dp,-1,sizeof(dp));
	cin >> s; reverse(s.begin(),s.end());
	n = s.length();
	cout << solve(0,0) ;
	
}
/*
 * long long or int?
 * index out of bound? 
 * Tested on own test case?corner?
 * Make more general solution.
 * Read Read Read Read ....
 */


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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug if(true)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

int main(){
	ll n,k;
	scanf("%lld %lld",&n,&k);
	ll mod = n % k;
	ll absDiff = abs(mod - k);
	printf("%lld\n",min(mod, absDiff));
	return 0;
};

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

from heapq import heappop,heappush

n = int(input())
p = []
for i in range(n):
    x,y = map(int,input().split())
    p.append((i,x,y))

e = [[] for _ in range(n)]

p = sorted(p,key=lambda x:x[1])
n0,x0,y0 = p[0]
for i in range(n-1):
    n1,x1,y1 = p[i+1]
    e[n0].append((min(abs(x1-x0),abs(y1-y0)),n1))
    e[n1].append((min(abs(x1-x0),abs(y1-y0)),n0))
    n0,x0,y0 = n1,x1,y1

p = sorted(p,key=lambda x:x[2])
n0,x0,y0 = p[0]
for i in range(n-1):
    n1,x1,y1 = p[i+1]
    e[n0].append((min(abs(x1-x0),abs(y1-y0)),n1))
    e[n1].append((min(abs(x1-x0),abs(y1-y0)),n0))
    n0,x0,y0 = n1,x1,y1

def Prim(n,edge):
    #edge[source] = [(cost_1,target_1),(cost_2,target_2),...]
    used = [False] * n
    q = []
    #e = [cost,target]
    for e in edge[0]:
        heappush(q,e)
    used[0] = True
    res = 0
    while q:
        c,v = heappop(q)
        if used[v]:
            continue
        used[v] = True
        for e in edge[v]:
            if not used[e[1]]:
                heappush(q,e)
        res += c
    return res

print(Prim(n,e))

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

typedef vector< vector<int> > vvi;
typedef vector< vector<bool> > vvb;
typedef vector< vector<char> > vvc;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;

int main(){
    int N;
    cin >> N;
    vi a(N);
    for(int i=0;i<N;i++) cin >> a[i];
    int all=0;
    for(int i=0;i<N;i++) all^=a[i];
    for(int i=0;i<N;i++){
        int c=all^a[i];
        cout << c << endl;
    }
    return 0;
}

Measured memory_bytes: 3976
#pragma comment(linker, "/stack:200000000")
 #pragma GCC optimize("Ofast")
 #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define int long long 
using namespace std;


signed main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);  
//  #ifndef ONLINE_JUDGE
//     freopen ("INPUT.txt" , "r" , stdin);
//     freopen ("OUTPUT.txt" , "w" , stdout);
//  #endif


// -------------------------------------Code starts here--------------------------------------------------------------------- 

    map<string,int>mm;
    mm["SUN"]=1;
    mm["MON"]=2;
    mm["TUE"]=3;
    mm["WED"]=4;
    mm["THU"]=5;
    mm["FRI"]=6;
    mm["SAT"]=7;
    string s;
    cin>>s;
    int z=8-mm[s];
    cout<<z;

// -------------------------------------Code ends here------------------------------------------------------
     clock_t clk;
 	clk = clock();
 
     clk = clock() - clk;
 	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
 	return 0;
 }

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;

const ll mod = 1e9+7;
const ll inf = 1e16;

#define loop(i,m,n) for(ll i=m;i<n;i++)
#define vloop(it,x) for(auto it=x.begin(); it!=x.begin(); it++)
#define all(x) x.begin(),x.end()
#define debug(x) cout << #x <<":"<< x <<endl	
#define showll(x) printf("%lld\n",x)
#define test(t) ll t;cin >> t;while(t--)
#define showc(x) printf("%c\n",x)
#define show(x) cout << x << endl
#define read(x) cin >> x
#define yes printf("YES\n")
#define no printf("NO\n")
#define pb push_back
#define mp make_pair

void fast()
{
ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
}

#define MAXN 60000001
int spf[MAXN];//smallest prime factor 
  
void sieve() 
{ 
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++) 
    {
        spf[i] = i; 
    }
   
    for (int i=4; i<MAXN; i+=2) 
    {
        spf[i] = 2; 
    }
  
    for (int i=3; i*i<MAXN; i++) 
    {  
        if (spf[i] == i) 
        {  
            for (int j=i*i; j<MAXN; j+=i) 
  			{
                if (spf[j]==j) 
                {	
                	spf[j] = i;
                }
            } 
        } 
    } 
}

//////////////////////////////// - _ - \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 
  
const int maxi = 1005;
char sl[maxi][maxi];

int main()
{
	ll h,w,i,j,a,b;
	ll ans = 0;
	read(h);read(w);
	loop(i,0,h)
	{
		scanf("%s",sl[i]);
	}
	vector< vector <ll> > dp(h, vector <ll> (w));
	dp[0][0]=1;
	loop(i,0,h)
	{
		loop(j,0,w)
		{
			if(i+1<h && sl[i+1][j]=='.')
			{
				dp[i+1][j] = (dp[i+1][j] + dp[i][j])%mod; 
			}
			else if(i+1<h && sl[i+1][j]=='#')
			{
				dp[i+1][j] = 0;	
			}

			if(j+1<w && sl[i][j+1]=='.')
			{
				dp[i][j+1] = (dp[i][j+1] + dp[i][j])%mod;	
			}
			else if(j+1<w && sl[i][j+1]=='#')
			{
				dp[i][j+1] = 0;	
			}

		}
	}
	

	printf("%lld\n",dp[h-1][w-1]);

}

Measured memory_bytes: 9088
//O(mn)の全探索解法
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
	int n;
	cin >> n;
	string *registeredID = new string[n];//登録されているID
	for(int i=0;i<n;i++){
		cin >> registeredID[i];
	}
	int m;
	cin >> m;
	string *cardID = new string[m];//扉にかざすID
	for(int i=0;i<m;i++){
		cin >> cardID[i];
	}
	//入力終わり
	bool isOpen = false;
	for(int i=0;i<m;i++){
		bool contains = false;//登録されているかどうか
		for(int j=0;j<n;j++){
			if(cardID[i] == registeredID[j]){
				contains = true;
				break;
			}
		}
		if(contains==true){
			if(isOpen == true){
				cout << "Closed by " << cardID[i] << endl;
			}else{
				cout << "Opened by " << cardID[i] << endl;
			}
			isOpen = !isOpen;//trueとfalseを入れ替える
		}else{
			cout << "Unknown " << cardID[i] << endl;
		}
	}
	delete []cardID;
	delete []registeredID;
	return 0;
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n; cin>>n;
	long double a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	vector<vector<long double>>dp(n+1,vector<long double>(n+1,0));
	dp[0][0]=0;
	dp[0][1]=a[0];
	dp[1][0]=1-a[0];
	for(int i=2;i<=n;i++)
	dp[0][i]=dp[0][i-1]*a[i-1];
	for(int i=2;i<=n;i++)
	dp[i][0]=dp[i-1][0]*(1-a[i-1]);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n-i;j++)
		{
			dp[i][j]=dp[i-1][j]*(1-a[i+j-1])+dp[i][j-1]*a[i+j-1];
		}
	}

	long double r=0;
	for(int i=n;i>=(n+1)/2;i--)
	r+=dp[n-i][i];
	cout<<fixed<<setprecision(12)<<r;

}

Measured memory_bytes: 141056
N=int(input())
B=input().split()
B=[int(n) for n in B]
A=[]
A.append(B[0])
last=0
for i in range(N-2):
    last=B[i]
    if last>B[i+1]:
        A.append(B[i+1])
    else:
        A.append(last)
    last=B[i+1]
A.append(last)
if N>2:
    print(sum(A))
else:
    print(sum(B)*2)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
#define int long long
using namespace std;

const int MOD = ((int)1e9) + 7;

int invmod(int n, int m) {
	int res = 1;
	int k = m - 2;
	while(k > 0) {
		if(k & 1) {
			res *= n;
			res %= m;
		}
		k >>= 1;
		n *= n;
		n %= m;
	}
	return res;
}

int comb(int n, int m) {
	int res = 1;
	for(int i = n; i > 0; --i) {
		res = (res * i) % MOD;
	}
	for(int i = m; i > 0; --i) {
		res = (res * invmod(i, MOD)) % MOD;
	}
	for(int i = n-m; i > 0; --i) {
		res = (res * invmod(i, MOD)) % MOD;
	}
	return res;
}

vector<int> calc(int w, int h) {
	int n = 1;
	vector<int> res(w + 1);

	for(int i = 0; i < w; ++i) {
		//int tmp = comb(i + h, i);
		//assert(tmp == n);
		res[i] = n;
		n = (n * (i + h + 1)) % MOD;
		n = (n * invmod(i + 1, MOD)) % MOD;
	}
	res[w] = comb(w + h, w);
	res[w] = n;
	return res;
}

signed main(){
	int H, W, A, B;
	cin >> H >> W >> A >> B;
	H--; W--;
	if(H - A > W - B) {
		swap(H, W);
		swap(A, B);
	}
	vector<int> a, b;
	a = calc(W, H - A);
	b = calc(W - B, A - 1);
	reverse(ALL(b));
	int res = 0;
	for(int i = B; i <= W; ++i) {
		//cout << a[i] << "," << b[i-B] << endl;
		res += a[i] * b[i - B] % MOD;
		res %= MOD;
		// cout << res << endl;
	}
	cout << res << endl;
	return 0;
}


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

using namespace std;

int main(){
	long long  n,k;
	cin>>n>>k;
	if(k == 1){
		cout<<"0"<<endl;
		return 0;
	}
	if(n>=k){
		long long res  = n % k;
		n = n% k;
	}
long  long  ans = min(abs(n-k),n);
	cout<<ans<<endl;
	return 0;
}

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

int main(){
  int E, Y;
  cin >> E >> Y;

  if(E==0){
    if(1868<=Y&&Y<=1911){
      cout << 'M' << Y-1867 << endl;
    }
    if(1912<=Y&&Y<=1925){
      cout << 'T' << Y-1911 << endl;
    }
    if(1926<=Y&&Y<=1988){
      cout << 'S' << Y-1925 << endl;
    }
    if(1989<=Y&&Y<=2016){
      cout << 'H' << Y-1988 << endl;
    }
  }

  if(E==1){
    cout << Y+1867 << endl;
  }

  if(E==2){
    cout << Y+1911 << endl;
  }

  if(E==3){
    cout << Y+1925 << endl;
  }

  if(E==4){
    cout << Y+1988 << endl;
  }
  return 0;
}



Measured memory_bytes: 3096
let [| N; M |] = stdin.ReadLine().Split() |> Array.map int

let waas = Array.zeroCreate<int> N
let flags = Array.zeroCreate<bool> N

let rec resolver ac wa n =
    if n = M then [| ac; wa |]
    else
        let input = stdin.ReadLine().Split()
        let p = input.[0] |> int
        let S = input.[1]

        if not flags.[p - 1] then
            if S = "WA" then
                waas.[p - 1] <- waas.[p - 1] + 1
                resolver ac wa (n + 1)
            else
                flags.[p - 1] <- true
                resolver (ac + 1) (wa + waas.[p - 1]) (n + 1)
        else resolver ac wa (n + 1)

resolver 0 0 0 |> Array.iter (printf "%d ")


Measured memory_bytes: 18504
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        
        int[] a = new int[N];
        
        Map<Integer, Integer> map = new HashMap<>();
        for(int i=0; i<N; i++) {
            a[i] = Integer.parseInt(sc.next());
            if(map.containsKey(a[i])) {
                map.put(a[i], map.get(a[i])+1);
            }else {
                map.put(a[i], 1);
            }
        }
        int count = 0;
        int max = 0;
        for(int key : map.keySet()) {
            count = map.get(key);
            if(map.containsKey(key-1)) count += map.get(key-1);
            if(map.containsKey(key+1)) count += map.get(key+1);
            if(max < count) max = count;
            
        }
        
        System.out.println(max);
    }
}


Measured memory_bytes: 48880
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;

int a, b, x;
static const double pi = acos(-1.0);
static const double eps = 1e-9;

double GetArea(double angle)
{
	double h1 = a * sin(angle);
	double h2 = b * cos(angle);
	double ret = 0;
	if (h1 < h2)
		ret = a * a * tan(angle) / 2 + a / cos(angle) * (h2 - h1);
	else ret = b * b / (2 * tan(angle));
	return ret;
}

int main()
{
	scanf("%d%d%d", &a, &b, &x);
	double area = double(x) / a;
	double l = 0, r = pi / 2;
	while (l + eps < r)
	{
		double mid = (l + r) / 2;
		if (GetArea(mid) >= area)
			l = mid;
		else r = mid;
	}
	printf("%.7f\n", l / pi * 180);
	return 0;
}


Measured memory_bytes: 128
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>

#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>

using namespace std;

int main()
{
    int64_t N, M;
    std::cin >> N >> M;

    std::unordered_map<int64_t, std::vector<int64_t>> v;

    for (int64_t i = 0; i < M; ++i) {
        int64_t a, b;
        std::cin >> a >> b;
        a--;
        b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }

    for (auto& l: v[0]) {
        if (l == N - 1) {
            //ok
            std::cout << "POSSIBLE" << std::endl;
            return 0;
        }
        for (auto& ll: v[l]) {
            if (ll == N - 1) {
                //ok
                std::cout << "POSSIBLE" << std::endl;
                return 0;
            }
        }
    }
    std::cout << "IMPOSSIBLE" << std::endl;

    return 0;
}


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

int N, M, Q;
vector<int> a, b, c, d;
int ans = 0;

void dfs(vector<int> A) {
  if (A.size() == N + 1) {
    int now = 0;
    for (int i = 0; i < Q; i++) {
      if (A.at(b.at(i)) - A.at(a.at(i)) == c.at(i)) now += d.at(i);
    }
    ans = max(ans, now);
    return;
  }
  
  A.push_back(A.back());
  while (A.back() <= M) {
    dfs(A);
    A.back()++;
  }
}

int main() {
  cin >> N >> M >> Q;
  a.resize(Q);
  b.resize(Q);
  c.resize(Q);
  d.resize(Q);
  for (int i = 0; i < Q; i++) {
    cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
  }
  
  dfs({1});
  cout << ans << endl;
}

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

using namespace std;
#define INF 1000007
#define MOD 1000000007
#define ll long long
#define maxn 100
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)

typedef std::pair<int, int> P;

vector<bool> prime(maxn + 1, true); //素数テーブル
void prime_table(void) {
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i * i <= maxn; i++) {
        if (!prime[i]) {
            continue;
        }
        for (int j = i + i; j <= maxn; j += j + i) {
            prime[j] = false;
        }
    }
}

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

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

bool IsPrime(int num) //素数判定
{
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) {
            return false;
        }
    }

    return true;
}

vector<int> divisor(int n) //約数列挙
{
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i - 1);
            if (i * i != n) {
                ret.push_back((n / i) - 1);
            }
        }
    }
    sort(ret.begin(), ret.end());
    return (ret);
}

int a, b;

void f(ll x) {
    while (x) {
        a++;
        b = x;
        x /= 10;
    }
}

signed main() {
    ll N;
    cin >> N;
    ll b = 2;
    ll ans = 0;
    if (N % 2 == 1) {
        cout << "0" << endl;
        return 0;
    }
    do {
        b *= 5;
        ans += N / b;
    } while (b <= N / 5);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<int,int>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }

const ll INF=1e18;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int h,w;
    cin>>h>>w;
    int a[h][w];
    rep(i,h)rep(j,w)cin>>a[i][j];
    V<pair<P,P>> ans;
    rep(i,w){
        rep(j,h-1){
            if(a[j][i]%2==1){
                ans.push_back(make_pair(make_pair(j+1,i+1),make_pair(j+2,i+1)));
                a[j][i]--;
                a[j+1][i]++;
            }
        }
    }
    rep(i,w-1){
        if(a[h-1][i]%2==1){
            ans.push_back(make_pair(make_pair(h,i+1),make_pair(h,i+2)));
            a[h-1][i]--;
            a[h-1][i+1]++;
        }
    }
    cout<<ans.size()<<endl;
    rep(i,ans.size())printf("%d %d %d %d\n",ans[i].ft.ft,ans[i].ft.sc,ans[i].sc.ft,ans[i].sc.sc);
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
*/

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

using namespace std;
#define ll long long 
int main()
{
	int n,x;
	cin>>n>>x;
	
	if(n*500>=x)
	{
		cout<<"Yes"<<endl;
	}
	else 
	{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	string n;
	cin >> n;

	for (int i = 0; i < n.length(); i++) {
		if (n[i] == '1') {
			cout << "9";
		}
		else if (n[i] == '9') {
			cout << "1";
		}
		else {
			cout << n[i];
		}
	}
	cout << endl;
}





Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  vector<int > vec(5);
  vec[0]=a;vec[1]=b;vec[2]=c;vec[3]=d;vec[4]=e;int k=0;int l=100;
  for(int i=0;i<5;i++){
  if(vec[i]%10 == 0){k += vec[i];}
    else{k+= (vec[i]/10 + 1 ) * 10;
        l =min(l,vec[i]%10);
        }
  }
if(l==100)l=10;  
  cout << k -10 + l <<endl;  
}


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

int main()
{
    int n,d,x,a,i;

    while(scanf("%d %d %d",&n,&d,&x)!=EOF)
    {
        int ans=n+x;

        while(n--)
        {
            scanf("%d",&a);

            int j=1;

            for(i=j*a+1;i<=d;)
            {
                ans++;

                j++;
                i=j*a+1;
            }
        }

        printf("%d\n",ans);
    }
    return 0;
}



Measured memory_bytes: 256
import math

def plot(x,y):
    print(f'{x:.8f} {y:.8f}')
    
def koch(n,x1,y1,x2,y2):
    if n==0:
        plot(x1,y1)
        return
    
    sx=(2*x1+x2)/3
    sy=(2*y1+y2)/3
    tx=(x1+2*x2)/3
    ty=(y1+2*y2)/3
    
    ux=(tx-sx)*(1/2)-(ty-sy)*(math.sqrt(3)/2)+sx
    uy=(tx-sx)*(math.sqrt(3)/2)+(ty-sy)*(1/2)+sy
    koch(n-1,x1,y1,sx,sy)
    koch(n-1,sx,sy,ux,uy)
    koch(n-1,ux,uy,tx,ty)
    koch(n-1,tx,ty,x2,y2)
    
n=int(input())
koch(n,0,0,100,0)
plot(100,0)


Measured memory_bytes: 5748
#include <stdio.h>
#include <stdlib.h>
#define N 100

int top, S[N];
void initialize(void);
void push(int);
int pop(void);

int main(){
  int a, b, x;
  char s[N];
  initialize();
  while(scanf("%s",s) != EOF){
    if(s[0] == '+'){
      a = pop();
      b = pop();
      push(a+b);
    }
    else if(s[0] == '-'){
      a = pop();
      b = pop();
      push(b-a);
    }
    else if(s[0] == '*'){
      a = pop();
      b = pop();
      push(a*b);
    }
    else{
      x = atoi(s);
      push(x);
    }
  }
  printf("%d\n",pop());
  
  return 0;
}

void initialize(void){
  top = 0;
}

void push(int x){
  top++;
  S[top] = x;
}

int pop(void){
  top--;
  return S[top+1];
}

Measured memory_bytes: 548
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, int> pli;
typedef complex<double> xy_t;
typedef vector<lint> poly;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

const lint mod = 1e9+7;
const int INF = mod;
const int MAX = 100010;

int main(){
    int n;
    scanf("%d", &n);
    int a[n], b[n];
    pii p[n];
    rep(i, n) scanf("%d", &a[i]);
    rep(i, n) scanf("%d", &b[i]);
    rep(i, n) p[i]=pii(a[i], b[i]);

    sort(a, a+n);
    sort(b, b+n);
    sort(p, p+n, [](const pii &s, const pii &t){return s.se<t.se;});
    rep(i, n)if(a[i]>b[i]){
        printf("No\n");
        return 0;
    }

    int idx[n];
    set<pii> S;
    rep(i, n) S.insert(pii(p[i].fi, i));
    rep(i, n){
        auto it=S.lower_bound(pii(a[i], -1));
        idx[i]=it->se;
        S.erase(it);
    }
    int cnt=0, cur=0;
    do{
        cur=idx[cur];
        ++cnt;
    }while(cur!=0);
    if(cnt<n){
        printf("Yes\n");
        return 0;
    }

    rep(i, n-1)if(a[i]<=b[i+1] && a[i+1]<=b[i]){
        printf("Yes\n");
        return 0;
    }
    printf("No\n");
}

Measured memory_bytes: 6912
import sys; sys.setrecursionlimit(2147483647); input = sys.stdin.readline
from math import floor, ceil, sqrt, factorial, log
from collections import Counter, defaultdict, deque
from operator import itemgetter
INF = float('inf'); MOD = 10**9+7
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(MI())
def LIR(n): return [LI() for i in range(n)]
def IS(): return input().rstrip()

def main():
    X = I()
    a = 0
    if X >= 500:
        a += (X//500)*1000
        X = X%500
    if X >= 5:
        a += (X//5)*5
    print(a)

if __name__ == '__main__':
    main()

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

using namespace std;

int main() {
  int k, a, b;
  cin >> k >> a >> b;
  for (int i = a; i <= b; i++) {
    if (i % k == 0) {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;

  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
using namespace std;

int main(){
int a,b,c,d;
cin>>a>>b>>c>>d;
if(a+b<c+d)cout<<"Right";
else if(a+b>c+d)cout<<"Left";
else cout<<"Balanced";

    
}

Measured memory_bytes: 256
#-*- using:utf-8 -*-

N, M = map(int, input().split())
H = list(map(int, input().split()))
S = [True] * N
cnt = 0
while cnt < M:
    A, B = map(int, input().split())
    if(H[A-1] < H[B-1]):
        S[A-1] = False
    elif(H[A-1] > H[B-1]):
        S[B-1] = False
    elif(H[A-1] == H[B-1]):
        S[A-1] = False
        S[B-1] = False
    cnt += 1
a = sum(x==True for x in S)
print(a)

Measured memory_bytes: 20132
import heapq
n,m = [int(i) for i in input().split()]

l = [list(map(int, input().split())) for _ in range(n)]
l.sort(reverse = True)

# 昇順降順のキー指定する方法
#l = sorted(l,key = lambda x :(-x[1],-x[0]))

ret = 0
pay = []
for d in range(1,m+1):
    while l and l[-1][0] <= d:
        tmp = l.pop()
        #最大値から取り出したいので-1をかけている
        heapq.heappush(pay,-tmp[1])
    if pay:
        ret -= heapq.heappop(pay) 

print(ret)

Measured memory_bytes: 28068
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
// #define int ll
using namespace std;
const int INF (1 << 30);
const ll LLINF (1LL << 55LL);
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,a[100010],M=-1,m=LLINF;
    cin>>n;
    rep(i,n){
        cin>>a[i];
        M=max(M,a[i]);
        m=min(m,a[i]);
    }
    cout<<M-m<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int n,k;
    cin >> n >> k;
    if (n%k == 0) {
        cout << 0 << endl;
    }else{
        cout << 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<string>
#include<iomanip>
#include<vector>
using namespace std;

int main(){
    long long int A, B, K;
    cin >> A >> B >> K;

    if( K > A){
        K -= A;
        A = 0;
        B -= K;
        if(B < 0){
            B = 0;
        }
    } else {
        A -= K;
    }

    cout << A << " " << B << endl;
}


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

constexpr int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
constexpr int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	while (cin >> n, n) {
		vvi color(4);
		vi x(n), y(n), r(n), c(n);
		REP(i, n) {
			cin >> x[i] >> y[i] >> r[i] >> c[i];
			c[i]--;
			color[c[i]].push_back(i);
		}
		vi b(1 << n, 0);
		b[(1 << n) - 1] = 1;
		vvi g(n);
		vi d(n, 0);
		REP(i, n)FOR(j, i + 1, n) {
			if ((x[i] - x[j])*(x[i] - x[j]) + (y[i] - y[j])*(y[i] - y[j]) < (r[i] + r[j])*(r[i] + r[j])) {
				g[i].push_back(j);
				d[j]++;
			}
		}
		queue<int> q;
		q.push((1 << n) - 1);
		while (!q.empty()) {
			int bit = q.front(); q.pop();

			vi a = d;
			REP(i, n) {
				if ((bit&(1 << i)) == 0) {
					REP(j, g[i].size()) {
						a[g[i][j]]--;
					}
				}
			}
			REP(i, n)FOR(j, i + 1, n) {
				if (c[i] == c[j] && (bit&(1 << i)) && (bit&(1 << j)) && a[i] == 0 && a[j] == 0) {
					if (b[bit ^ (1 << i) ^ (1 << j)] == 0)q.push(bit ^ (1 << i) ^ (1 << j));
					b[bit ^ (1 << i) ^ (1 << j)] = 1;
				}
			}
		}
		int ans = 0;
		REP(i, 1 << n) {
			if (b[i] == 0)continue;
			int cnt = n;
			REP(j, n)if (i&(1 << j))cnt--;
			chmax(ans, cnt);
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 69648
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int D = sc.nextInt();
		int N = sc.nextInt();
		
		int[] A = new int[N + 2];
		
		for(int i = 1; i <= N + 1; i++) {
			if(i < 100) {
				A[i] = (int)(Math.pow(100, D) * i);
			} else if( i == 101) {
				A[i - 1] = (int)(Math.pow(100, D) * i);
			}
		}
		System.out.println(A[N]);
	}
}


Measured memory_bytes: 22868
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<algorithm>
using namespace std;

int n,k;
vector<int> list;
void init(){
  list.clear();
}

bool input(){
  cin>>n;
  cin>>k;
  int pre;
  cin>>pre;
  for(int i=1;i<n;i++){
    int tmp;
    cin>>tmp;
    list.push_back(tmp-pre);
    pre=tmp;
  }
  return true;
}



int solve(){
  int res=0;
  sort(list.begin(),list.end());
  for(int i=0;i<n-k;i++){
    res+=list[i];
  }
  return res;
}


int main(){
  int t;
  cin>>t;
  for(int i=0;i<t;i++){
    init(),input();
    cout<<solve()<<endl;
  }
}

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

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main () {
  int N, K;
  cin >> N >> K;
  COMinit();
  for(int i = 1; i <= K; i++){
    if(i - 1 <= N - K){
      cout << (COM(K - 1, i - 1) * COM(N - K + 1, i)) % MOD << endl;
    } else {
      cout << 0 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 12160
import java.util.*;
import java.io.*;

public class Main {

	void solve() {
		long x = in.nextInt(), y = in.nextInt();
		if (x % y == 0) {
			out.println("-1");
			return;
		}
		out.println(x);
	}

	FastScanner in;
	PrintWriter out;

	void run() {
		in = new FastScanner();
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

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

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

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

		public int nextInt() {
			return Integer.parseInt(nextToken());
		}

		public long nextLong() {
			return Long.parseLong(nextToken());
		}

		public double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  vector<int> a(3);
  rep(i,3) cin >> a[i];
  sort(a);
  if(a[0]+a[1] == a[2] || a[0] == a[1] + a[2]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char *argv[]) {
  int sur[8][8];
  int x, y;
  string s;

  while (true) {
    bool isGetted = false;
    for (int i = 0; i < 8; i++) {
      getline(cin, s);
      for (int j = 0; j < 8; j++) {
        if (s[j] == '1' && !isGetted) {
          x = j;
          y = i;
          isGetted = true;
        }
        sur[i][j] = s[j] - '0';
      }
    }

    if (x+1 < 8 && y+1 < 8 &&
        sur[y][x+1] && sur[y+1][x] && sur[y+1][x+1])
      cout << "A" << endl;
    else if (y+3 < 8 &&
             sur[y+1][x] && sur[y+2][x] && sur[y+3][x])
      cout << "B" << endl;
    else if (x+3 < 8 &&
             sur[y][x+1] && sur[y][x+2] && sur[y][x+3])
      cout << "C" << endl;
    else if (x-1 >= 0 && y+2 < 8 &&
             sur[y+1][x] && sur[y+1][x-1] && sur[y+2][x-1])
      cout << "D" << endl;
    else if (x+2 < 8 && y+1 < 8 &&
             sur[y][x+1] && sur[y+1][x+1] && sur[y+1][x+2])
      cout << "E" << endl;
    else if (x+1 < 8 && y+2 < 8 &&
             sur[y+1][x] && sur[y+1][x+1] && sur[y+2][x+1])
      cout << "F" << endl;
    else
      cout << "G" << endl;

    if (!getline(cin, s))
      break;
  }
  return 0;
}

Measured memory_bytes: 1168
#include<iostream>
using namespace std;
#define pi 3.14159

int main(){
  int n,m,sum = 0;
  cin >> n >> m;
  int a[m];
  for(int i = 0 ; i < m;i++){
    cin >> a[i];
  }
  for(int i = 0 ; i < m;i++){
    sum += a[i];
  }
  if(n - sum >= 0){
    cout << n - sum << endl;
  }
  else{
    cout << -1 << endl;
  }
}

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

int gcd(int a, int b) { if (!b)return a; return gcd(b, a%b); }
int lcm(int a, int b) {
	int g = gcd(max(a, b), min(a, b));
	return a / g*b / g*g;
}
int main() {
	int n; cin >> n;
	int ans = 1;
	rep(i, n) {
		int a; cin >> a;
		ans = lcm(ans, a);
	}
	cout << ans << endl;
}

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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;


int main() {
    
    int n; cin >> n;
    if(n == 1) {
        cout << 1 << endl;
        return 0;
    }

    vector<int> x, y;
    rp(i, 0, n) {
        int a, b;
        cin >> a >> b;
        x.emplace_back(a);
        y.emplace_back(b);
    }
    
    vector<int> P, Q;

    rp(i, 0, n){
        rp(j, i+1, n){
            P.emplace_back(x[i] - x[j]);
            Q.emplace_back(y[i] - y[j]);
        }
    }
    int cost = n;
    int size = P.size();
    rp(i, 0, size){
        int p = P[i];
        int q = Q[i];
        int count = 0;
        rp(j, 0, size){
            if(p == P[j] && q == Q[j]) count ++;
            if(p == -P[j] && q == -Q[j]) count ++;
        }
        chmin(cost, n-count);
    }
    cout << cost << endl;
    return 0;
}

Measured memory_bytes: 3644
#include<stdio.h>
main()
{
    int n,s;
    scanf("%d",&n);
    s=n%10;
    if(s==3)
    printf("bon\n");
    else if(s==0 || s==1 || s==6 || s==8)
    printf("pon\n");
    else
     printf("hon\n");
}

Measured memory_bytes: 1660
sa = list(input())
sb = list(input())
sc = list(input())

def game(s):
    if s == 'a':
        if len(sa) == 0:
            print('A')
            exit()
        else:
            game(sa.pop(0))
    if s == 'b':
        if len(sb) == 0:
            print('B')
            exit()
        else:
            game(sb.pop(0))
    if s == 'c':
        if len(sc) == 0:
            print('C')
            exit()
        else:
            game(sc.pop(0))
game('a')

Measured memory_bytes: 3188
#include <cstdio>
using namespace std;
int main(){
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	if(b-a+1>=n||a%n>b%n||a%n==0){
		printf("OK\n");
	}else{
		printf("NG\n");
	}
	return 0;
}


Measured memory_bytes: 1616
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<utility>//swapでaとbの値を入れ替える
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
#define sort(s) sort(s.begin(),s.end())
#define r(s) reverse(s.begin(),s.end())
using namespace std;


int main() {
  int a,b,c,d;
  int ans=0;
  cin>>a>>b>>c>>d;
  int x=a-b;
  if(x<0){
  ans=a*c;
  }
  else {
  ans=b*c+(a-b)*d;
  }
  cout<<ans<<endl;
  

  return 0;
  }
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;


#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define pii pair<int,int>
#define pf push_front
#define mp make_pair
#define vi vector<int>
#define vip vector<pair<int,int> >
#define ff first
#define ss second
#define int long long
#define mod 1000000007
#define BIG 998244353
#define s(t) scanf("%lld",&t)
#define p(t) printf("%lld\n",t)
#define mii map<int,int>
#define MSET(table,i) memset(table, i, sizeof(table))
#define endl '\n'
#define tc int t;cin>>t;while(t--)
#define pi  3.1415926358
#define bits(x) __builtin_popcount(x)
#define minimum(a,n) min_element(a,a+n)-a
#define maximum(a,n) max_element(a,a+n)-a
#define pqbig priority_queue<pii>
#define pqsmall priority_queue<pair<int,pii>,vector<pair<int,pii> >,greater<pair<int,pii> > >
#define all(v) v.begin(),v.end()
#define sitr set<int>:: iterator
#define spitr set<pii>:: iterator
#define mitr map<string,int>:: iterator

int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ) {stringstream ss; ss << number; return ss.str();}

typedef tree<pii, null_type, less<pii>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;

#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl


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

    int sum=0;
    for(int i=1;i<n;i++)
        sum+=arr[i]-arr[i-1];

    sum+=(arr[0]+k-arr[n-1]);

    int ans=1e18;
    for(int i=0;i<n;i++)
    {
        int val1,val2;
        if(i==n-1)
            val1=arr[0]+k-arr[i];
        else
            val1=arr[i+1]-arr[i];
        if(i==0)
            val2=arr[0]+k-arr[n-1];
        else
            val2=arr[i]-arr[i-1];

        int num=max(val1,val2);
        ans=min(ans,sum-num);
    }
    cout<<ans;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>

template <class T>
using vec = std::vector<T>;

constexpr int nil = -1;

class DisjointSet
{
public:

    DisjointSet(int n)
        : rank(n, 0)
        , p(n, nil)
    {}

    void unite(int x, int y)
    {
        if (same(x, y))
            return;

        int rx = root(x);
        int ry = root(y);

        if (rank[rx] == rank[ry])
        {
            p[rx] = ry;
            ++rank[ry];
        }
        else if (rank[rx] < rank[ry])
        {
            p[rx] = ry;
        }
        else
        {
            p[ry] = rx;
        }
    }

    bool same(int x, int y)
    {
        int rx = root(x);
        int ry = root(y);
        if (rx == nil)
            return false;
        return rx == ry;
    }

    int root(int x)
    {
        int i = x;
        while (true)
        {
            if (p[i] == nil)
                break;
            i = p[i];
        }
        return i;
    }

private:

    vec<int> rank, p;

};

void solve()
{
    using namespace std;

    int n, q;
    cin >> n >> q;

    DisjointSet ds {n};

    for (int i = 0, com, x, y; i < q; ++i)
    {
        cin >> com >> x >> y;
        
        if (com == 0)
            ds.unite(x, y);
        else
            cout << (ds.same(x, y) ? 1 : 0) << endl;
    }
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
using lli=long long int;
using vi=vector<int>;  using vs=vector<string>; using gi=greater<int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define soao(c) sort((c).begin(),(c).end()) //昇順
#define sodo(c) sort((c).begin(),(c).end(),gi()) //降順
#define rev(c) reverse((c).begin(), (c).end())



int main(){
    int r,g,b; cin>>r>>g>>b;
    if((g*10+b)%4==0) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


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

using namespace std;

#define ll long long
#define vi vector<int>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

int N, M, a, b, cnt = 0;
bool T[13][13];
vector<bool> visited;

int dfs(int u, int N, vector<bool> visited){
    bool all_visited = true;

    rep(i,N)
        if(!visited[i]) all_visited = false;

    if(all_visited) return 1;

    int ret = 0;
    
    rep(i,N){
        //パスがないまたは訪問済みなら飛ばす
        if(!T[u][i] || visited[i])
            continue; 
        // printf("Path from %d to %d exists\n", u, i);
        visited[i] = true;
        ret += dfs(i,N,visited); //iを訪問したことにしてdfs
        visited[i] = false; //戻して他の道でも試す
    }
    return ret;
}

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

    rep(i, M){
        cin >> a >> b; //0-indexに
        T[a-1][b-1] = T[b-1][a-1] = true;
    }
    visited.resize(N,false);
    visited[0] = true;
    cout << dfs(0, N, visited) << endl;
}


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

#define pb            push_back
#define mp            make_pair
#define all(x)        x.begin(),x.end()
#define debug(X)      { cerr<<'\n'<<(#X)<<" = "<<(X)<<'\n'; }
//#define cerr if(0)cerr

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

ll gcd(ll a, ll b) {
    while (b) b^=a^=b^=a%=b;
    return a;

}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    ll k, res=0;

    cin>>k;
    for (int i=1; i<=k; ++i)
        for (int j=1; j<=k; ++j)
            for (int h=1; h<=k; ++h)
                res += gcd(i,gcd(j,h));
    cout<<res<<'\n';

}



Measured memory_bytes: 3652
package main

import "fmt"

func main() {
	var n, m uint
	fmt.Scan(&n)
	fmt.Scan(&m)

	cache := (1 << m) - 1

	for i := uint(0); i < n; i++ {
		var k uint
		fmt.Scan(&k)
		like := 0
		for j := uint(0); j < k; j++ {
			var t uint
			fmt.Scan(&t)
			like |= (1 << (t - 1))
		}
		cache = cache & like
	}

	res := 0
	for i := uint(0); i < m; i++ {
		if cache&(1<<i) != 0 {
			res++
		}
	}

	fmt.Println(res)
}


Measured memory_bytes: 512
#include<iostream>
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<algorithm>
using namespace std;

int main(){
	string str;
	int q;

	cin>>str>>q;
	int len=str.size();

	for(int i=0; i<q; i++){
		string od, p, tmp;
		int a,b;
		cin>>od;
		if(od=="print"){
			cin>>a>>b;
			cout<<str.substr(a,b-a+1)<<endl;
		}else if(od=="reverse"){
			cin>>a>>b;
			reverse(str.begin()+a, str.begin()+b+1);
			
		}else if(od=="replace"){
			string p;
			cin>>a>>b>>p;
			if(a==0){
				str=p+str.substr(b+1,len-b-1);
			}
			else{
				str=str.substr(0,a)+p+str.substr(b+1,len-b-1);
			}
		}
		
	}

	
	return 0;
}


Measured memory_bytes: 3224
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	if a <= 5 {
		fmt.Println(0)
	} else if 6 <= a && a <= 12 {
		fmt.Println(b/2)
	} else {
		fmt.Println(b)
	}
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define pb push_back
#define mp make_pair
#ifndef ONLINE_JUDGE
#define deb(x) cout<<#x<<" : "<<x<<"\n";
#define debug(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\n";
#define deb_arr(a,n) {cout<<#a<<":";for(int i=0;i<n;i++) {cout<<a[i]<<" ";} cout<<'\n';}
#define deb_mat(dist,n,m) {cout<<#dist<<"\n";for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<dist[i][j]<<" ";}cout<<'\n';}}
#else
#define deb(x) ;
#define debug(x,y) ;
#define deb_arr(a,n) ;
#define deb_mat(dist,n,m) ;
#endif
#define ff first
#define ss second
#define ub upper_bound
#define lb lower_bound
#define all(a) (a).begin(),(a).end()
#define bs binary_search
#define sz size()
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ld long double
#define clr fflush(stdout);
//#define clr cout.flush();
#define N 200001
#define fpr(i,a,b) for(int i=a;i<b;i++)
#define fdr(i,a,b) for(int i=a;i>b;i--)
#define repp(i,a,b,d) for(int i=a;i<b;i+=d)
#define repd(i,a,b,d) for(int i=a;i>b;i-=d)
#define LLMIN LLONG_MIN
#define LLMAX LLONG_MAX
#define AKASH_PATEL ios_base::sync_with_stdio(false);
#define SVNIT_SURAT cin.tie(NULL);cout.tie(NULL);
#define mset(x,a) memset(x,a,sizeof(x));
#define nl cout<<'\n';
#define print(c) cout<<c<<'\n';
#define setp(n) cout << fixed << setprecision(n)
#define take_arr(a,n) fpr(i,0,n) cin>>a[i];
#define print_arr(a,n) for(int i=0;i<n;i++) {cout<<a[i]<<" ";} cout<<'\n';
#define take_mat(mat,n,m) fpr(i,0,n) fpr(j,0,m) cin>>mat[i][j];
#define set_mat(mat,n,m,k) fpr(i,0,n) fpr(j,0,m) mat[i][j]=k;
#define print_mat(dist,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<dist[i][j]<<" ";}cout<<'\n';}
template< class T > bool inside(T a, T b, T c) { return a<=b && b<=c; }
template< class T > bool odd(T a) { return a&1; }
template< class T > bool even(T a) { return !(a&1); }
int main()
{
//#ifndef ONLINE_JUDGE
//    freopen("../ip.txt", "r", stdin);
//    freopen("../op.txt", "w", stdout);
//#endif
    AKASH_PATEL;
    SVNIT_SURAT;
    int t=1;
//    cin>>t;
    while(t--)
    {
        ll n,k;
        cin>>n>>k;
        ll n2=((-n)%k+k)%k;
        print(min(n%k,n2%k))
    }
    return 0;
}





Measured memory_bytes: 256