akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

    int n;
    cin >> n;
    vector <int> cords(n);
    int sum = 0;
    for(int i = 0; i < n; i++){
        cin >> cords[i];
        sum += cords[i];
    }
    int med1 = sum/n, med2 = sum/n + 1;
    int stamina1 = 0, stamina2 = 0;
    for(auto x : cords){
        stamina1 += (x-med1) * (x-med1);
        stamina2 += (x-med2) * (x-med2);
    }
    cout << min(stamina2, stamina1) << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main() {
    int N, M, sum = 0;
    cin >> N;
    vector<int> T(N);
    for (auto& i : T) {
        cin >> i;
        sum += i;
    }
    cin >> M;
    for (int i = 0, P, X; i < M; i++) {
        cin >> P >> X;
        cout << sum - T[P - 1] + X << endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
 
		long a,b;
 
		Scanner sc = new Scanner(System.in);
 
		a = sc.nextLong();
		b = sc.nextLong();
 
		long ans = 2018;
 
		if (b - a >= 2019) {
			ans = 0;
		} else {
 
			for (long i = a; i < b; ++i) {
				for (long j = i+1; j <= b; ++j) {
					ans = Math.min(ans, (i * j) % 2019);
				}
 
			}
  
		}
 
			System.out.println(ans);
 	}
  
}

Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

int main() {
    ll N; cin >> N;
    ll K = 1;
    bool exist = false;
    for (K = 1; K <= N; ++K) {
        if (K * (K+1) / 2 == N) {
            exist = true;
            break;
        }
    }
        
    if (!exist) No
    else {
        puts("Yes");
        cout << K+1 << endl;
        vvl res(K+1, vl());
        ll sum = 1;
        for (int k = K; k >= 1; --k) {
            for (int i = 0; i < k; ++i) {
                res[K-k].pb(sum + i);
                res[K-k + i + 1].pb(sum + i);
            }
            sum += k;
        }
            
        for (int i = 0; i < K+1; ++i) {
            cout << res[i].size();
            for (int j = 0; j < res[i].size(); ++j) cout << " " << res[i][j];
            cout << endl;
        }
    }
}

Measured memory_bytes: 3200
#include <stdio.h>
#include <algorithm>
 
using namespace std;
 
int main(){
    int H,W;
    while(true){
        scanf("%d %d",&H,&W);
        if(H == 0 && W == 0) break;
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                if((i+j)%2 == 0) printf("#");
                else{
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
}


Measured memory_bytes: 2600
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>
#include <queue>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

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

    vector<char> vec;
    for (int i = 0; i < s.size(); i++)
    {
        auto result = find(vec.begin(), vec.end(), s[i]);
        if (result != vec.end())
        {
            cout << "no" << endl;
            return 0;
        }
        vec.push_back(s[i]);
    }
    
    cout << "yes" << endl;
}

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


int main() {
    int n;
    cin >> n;
    vector< vector<int> > d(n, vector<int>(2));
    for (int i = 0; i < n; i++)
    {
        cin >> d[i][0] >> d[i][1];
    }

    int counter = 0;
    bool ans = false;
    for (int i = 0; i < n; i++)
    {
        if(d[i][0] == d[i][1]) counter++;
        else counter = 0;
        if(counter == 3){
            ans = true;
            break;
        }
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<LL> A(N, 0), B(N, 0);
	for(int i=0; i<N; i++) scanf("%lld", &A[i]);
	for(int i=0; i<N; i++) scanf("%lld", &B[i]);
	LL sum = 0;
	LL ans = 0;
	stack<LL> data;
	for(int i=0; i<N; i++) {
		sum += A[i] - B[i];
		data.push(sum);
		ans += abs(sum);
	}
	data.pop();
	ans -= sum;
	priority_queue<LL> pq;
	while(!data.empty()) {
		LL cur = data.top();
		data.pop();
		if(cur <= 0) pq.push(0);
		if(cur > 0) {
			if(cur > sum) cur = sum;
			pq.push(-cur);
			pq.push(-cur);
			ans += pq.top();
			pq.pop();
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3636
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

string s;
int p;
map<string, int> table;

int Molecule();
int Atom();
int Number();

int Molecule() {
	int value = 0, result = 0;
	while(p < s.length() && s[p] != ')') {
		if(s[p] == '(') {
			p++;
			value = Molecule();
			if(value == -1) {
				return -1;
			}
			p++;
			result += value * Number();
		} else {
			value = Atom();
			if(value == -1) {
				return -1;
			}
			result += value * Number();
		}
	}

	return result;
}

int Atom() {
	string tmp;
	if(isalpha(s[p])) {
		tmp += s[p];
		p++;
		if(islower(s[p])) {
			tmp += s[p];
			p++;
		}
		if(table[tmp]) {
			return table[tmp];
		}
	}

	return -1;
}

int Number() {
	int value = 0;
	while(isdigit(s[p])) {
		value = value*10 + s[p]-'0';
		p++;
	}
	
	return (value == 0 ? 1 : value);
}

int main() {
	while(cin >> s) {
		if(s == "END_OF_FIRST_PART") {
			break;
		} else {
			cin >> p;
			table[s] = p;
		}
	}

	while(cin >> s, s != "0") {
		p = 0;
		int ans = Molecule();
		if(ans == -1) {
			cout << "UNKNOWN" << endl;
		} else {
			cout << ans << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1232
import itertools
N,C = map(int,input().split())
imos = [0]*(10**6)
info = [list(map(int,input().split())) for i in range(N)]
info = sorted(info,key=lambda x:(x[2],x[0]))
note = -1
before_t = -1
for i in range(N):
    s,t,c = info[i]
    s -= 1
    if c == note and s < before_t:
        s = before_t
    imos[s] += 1
    imos[t] -= 1
    note = c
    before_t = t
acc_sum = list(itertools.accumulate(imos))
ans = max(acc_sum)
print(ans)

Measured memory_bytes: 50964
#include<bits/stdc++.h>
using namespace std;
const int maxn=100100;
int n;
int t[maxn],x[maxn],y[maxn];
void no()
{
    puts("No");
    exit(0);
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
    {
        scanf("%d%d%d",&t[i],&x[i],&y[i]);
        if(abs(x[i]-x[i-1])+abs(y[i]-y[i-1])>t[i]-t[i-1]) no();
        int g=(abs(x[i]-x[i-1])+abs(y[i]-y[i-1]))&1;
        if(g!=((t[i]-t[i-1])&1)) no();
    }
    puts("Yes");
    return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
//#define int long long
#define loop(i, a, b) for(int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int MOD = 1e9 + 7, INF = 1e9;
using vi = vector <int>;
using vvi = vector <vi>;
//g++ -std==c++14
 
signed main(){
    int n, k;
    cin >> n >> k;
    vector <char> dislike(k);
    rep(i, k)cin >> dislike[i];
    while(1){
        string va = to_string(n);
        rep(i, va.size())
            rep(j, k)
                if(va[i] == dislike[j])
                    goto koko;
        break;
        koko:;
        n++;
    }
    cout << n << endl;

}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	string s;
	cin>>n>>s;
	if(n%2){
		cout<<"No";
		return 0;
	}
	bool correct=true;
	for(int i=0;i<n/2;i++)
		if(s[i]!=s[i+n/2])
			correct=false;
	cout<<(correct?"Yes":"No");
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>

using namespace std;
//100000000000000
int main(){
	string S;
	long long int K;
	cin>>S;
	cin>>K;
	int non_one=-1;
	char ans;
	for(int i=0;i<S.size();i++){

		if(S[i]!='1'){
			ans=S[i];
			break;
		}
		non_one=i+1;
		
	}
	
	if(non_one!=-1 && non_one>=K){
		cout<<'1'<<endl;
	}else{
		cout<<ans<<endl;
	}
	return 0;
}

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

long long a,b,c,d;

int main(){
	scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
	printf("%lld\n",max(a*c,max(a*d,max(b*c,b*d))));
}

Measured memory_bytes: 3824
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>

using namespace std;

int main()
{
    int N, M, t, x, y;   cin >> N >> M;
    long long ans;
    vector<int> a(N), c(31,0);
    priority_queue<int> que;
    for(int i=0; i<N; i++){
        cin >> x;
        que.push(x);
    }
    ans = 0;
    t = 0;
    while(!que.empty()){
        x = que.top();
        que.pop();
        que.push(x/2);
        t++;
        if(t >= M || x == 0)   break;
    }
    for(int i=0; i<N; i++){
        x = que.top();
        ans += x;
        que.pop();
    }
    cout << ans;
}

Measured memory_bytes: 4236
#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

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


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

  if(a+b<10){ cout<<a+b<<endl; } else { cout << "error" << endl;}
 
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<class T>//ex) auto dp = make_vec(4,4,4,INF);
vector<T> make_vec(size_t s, T val) { return vector<T>(s, val); }
template<class... Size>
auto make_vec(size_t s, Size... tail) {
	return vector<decltype(make_vec(tail...))>(s, make_vec(tail...));
}

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int H, W;
	cin >> H >> W;

	vector<vector<Int>> A(H+1, vector<Int>(W+1));
	vector<vector<Int>> B(H+1, vector<Int>(W+1));
	for (Int i = 0; i < H; i++) {
		for (Int j = 0; j < W; j++) {
			cin >> A[i][j];
		}
	}
	for (Int i = 0; i < H; i++) {
		for (Int j = 0; j < W; j++) {
			cin >> B[i][j];
		}
	}

	auto dp = make_vec(H+1, W+1, 13000, 0);
	dp[0][0][abs(A[0][0]-B[0][0])] = 1;

	
	for (Int i = 0; i < H; i++) {
		for (Int j = 0; j < W; j++) {
			for (Int k = 0; k < 13000; k++) {
				if (dp[i][j][k]) {
					dp[i + 1][j][k + abs(A[i + 1][j] - B[i + 1][j])] = 1;
					dp[i + 1][j][abs(k - abs(A[i + 1][j] - B[i + 1][j]))] = 1;//kが負になる場合は正に切り返す

					dp[i][j + 1][k + abs(A[i][j + 1] - B[i][j + 1])] = 1;
					dp[i][j + 1][abs(k - abs(A[i][j + 1] - B[i][j + 1]))] = 1;//kが負になる場合は正に切り返す

				}
			}
		}
	}

	Int ans;
	for (Int k = 0; k < 13000; k++) {
		if (dp[H-1][W-1][k]) {
			cout << k << "\n";
			return 0;
		}
	}

}


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


def main():
    A, B, K = map(int, input().split())

    cnt = 0
    for i in reversed(range(1, min(A, B)+1)):
        if A%i==0 and B%i==0:
            cnt += 1
        if cnt==K:
            print(i)
            return
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
)

func main() {
	N, M := ReadInt(), ReadInt()
	h := Heapq{}
	for i := 0; i < N; i++ {
		h.push(ReadInt())
	}
	for i := 0; i < M; i++ {
		h.push(h.pop() / 2)
	}
	ans := 0
	for _, ai := range h {
		ans += ai
	}
	fmt.Println(ans)
}

type Heapq []int

func (q Heapq) Less(i, j int) bool    { return q[i] > q[j] }
func (q Heapq) Len() int              { return len(q) }
func (q Heapq) Swap(i, j int)         { q[i], q[j] = q[j], q[i] }
func (q *Heapq) Push(x interface{})   { *q = append(*q, x.(int)) }
func (q *Heapq) Pop() (x interface{}) { *q, x = (*q)[:len(*q)-1], (*q)[len(*q)-1]; return }
func (q *Heapq) push(v int)           { heap.Push(q, v) }
func (q *Heapq) pop() int             { return heap.Pop(q).(int) }

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 7172
/*
 * PrintAChessboard.cpp
 *
 *  Created on: 2014/07/21
 *      Author: WanWan1985
 */
#include <iostream>
#include <vector>
using namespace std;

typedef struct {
	int a_H, a_W;
}DataSet;

int main(void) {

	vector<DataSet> vecDataSet;
	while (1) {
		DataSet data;
		int H, W = 0;
		cin >> H >> W;
		if ((0 == H) && (0 == W)) {
			break;
		}
		data.a_H = H;
		data.a_W = W;
		vecDataSet.push_back(data);
	}

	for (unsigned int i = 0; i < vecDataSet.size(); i++) {
		DataSet data = vecDataSet.at(i);
		for (int i = 0; i < data.a_H; i++) {
			for (int j = 0; j < data.a_W; j++) {
				if ( (i % 2 == 0) && (j % 2 == 0) ) {
					cout << "#";
				} else if ( (i % 2 == 0) && (j % 2 != 0) ) {
					cout << ".";
				} else if ( (i % 2 != 0) && (j % 2 == 0) ) {
					cout << ".";
				} else {
					cout << "#";
				}
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}

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

using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n); i > 0; i--)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl
const int MAX = 200001;
const int MOD = 1000000007;

vector<ll> fac(MAX), finv(MAX), inv(MAX);

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(ll n, ll 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(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    ll n,k,ans=0;
    cin >> n >> k;
    COMinit();
    rep(i,min(n-1,k)+1) ans = (ans + COM(n,i) * COM(n-1,n-1-i) % MOD) % MOD;
    print(ans);
    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
using namespace std;
#include<string.h>
#include<set>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include <cstdio>
#include <cstdlib>
#include<stack>
#include<vector>
int main()
{
    int n,a,b;
    cin>>n>>a>>b;
    if(abs(a-b)%2==0)
        cout<<"Alice"<<endl;
    else
        cout<<"Borys"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b,c,i,n=0;
  scanf("%d %d %d",&a,&b,&c);
  for(i=a;i<=b;i++){
    if(c%i==0){
      n++;
    }
  }
  printf("%d\n",n);
  return(0);
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;

namespace AOJ_Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());

            var dataList = new List<int[]>();

            for (int i = 0; i < n; i++)
            {
                // 0:棟番号, 1:階数, 2:部屋Index, 3:入居人数
                var oneLine = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                dataList.Add(oneLine);
            }

            // rank1:棟番号, rank2:階数, rank3:部屋番号
            var allRidgeList = new List<List<List<int>>>();
            for (int i = 0; i < 4; i++)
            {
                var aRidgeList = new List<List<int>>();
                for (int j = 0; j < 3; j++)
                {
                    var aFloorList = new List<int>(Enumerable.Repeat<int>(0, 10));
                    aRidgeList.Add(aFloorList);
                }
                allRidgeList.Add(aRidgeList);
            }

            foreach (var datum in dataList)
            {
                int ridgeIndex = datum[0] - 1;
                int floorIndex = datum[1] - 1;
                int roomIndex = datum[2] - 1;
                int entriedNum = datum[3];
                allRidgeList[ridgeIndex][floorIndex][roomIndex] += entriedNum;
            }

            for (int i = 0; i < allRidgeList.Count; i++)
            {
                foreach (var aFloor in allRidgeList[i])
                {
                    Console.WriteLine(" " + string.Join(" ", aFloor));
                }

                if (i + 1 != allRidgeList.Count)
                {
                    Console.WriteLine(new string('#', 20));
                }
            }

        }
    }
}



Measured memory_bytes: 18380
#include<cstdio>
#include<iostream>

int A[2000],n;

bool solve(int i,int m){
  if(i==n) return m==0;
  if( solve(i+1,m) ) return true;
  if( solve(i+1,m-A[i]) ) return true;
  return false;

}

int main(){

  int m,q;
  scanf("%d",&n);
  for(int i=0;i<n;i++)
    scanf("%d",&A[i]);
  scanf("%d",&m);
  for(int i=0;i<m;i++){
    scanf("%d",&q);
    if(solve(0,q)==true) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}

Measured memory_bytes: 1172
#include <iostream>
#include <cassert>
#include <iomanip>
#include <utility>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#include <string>

using namespace std;

typedef long long ll;
typedef pair<int, int> p_i;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repext(i, a, b) for (int i = a; i < b; i++)
#define reprev(i, n) for (int i = n - 1; i >= 0; i--)
#define repextrev(i, a, b) for (int i = b - 1; i >= a; i--)

#define repv(v, values) for (auto v : values)

#define vec_all(vec) vec.begin(), vec.end()
#define sum(vec) accumulate(vec_all(vec), 0LL)
#define srt(vec) sort(vec_all(vec))
#define rev(vec) reverse(vec_all(vec))
#define revsrt(vec) \
    srt(vec);       \
    rev(vec)

// vectorデバッグ
template <typename T>
void dump_vec(vector<T> vec)
{
    rep(i, vec.size())
    {
        cout << i << ": " << vec[i] << endl;
    }
}

template <typename T, typename S>
void dump_dic(map<T, S> dic)
{
    for (auto v : dic)
    {
        cout << v.first << ": " << v.second << endl;
    }
}

template <typename T>
T ceil_div(T a, T b)
{
    if (a % b != 0)
    {
        return a / b + 1;
    }
    else
    {
        return a / b;
    }
}

// --- notice ---
// intの和はllにしろ

int main()
{
    int n;
    cin >> n;
    vector<int> c(n - 1);
    vector<int> s(n - 1);
    vector<int> f(n - 1);

    rep(i, n - 1) {
        cin >> c[i] >> s[i] >> f[i];
    }

    int arrive;
    int departure;
    int current;
    int times;
    rep(i, n - 1) {
        arrive = s[i];
        current = i;
        while(current < n - 1) {
            if (arrive < s[current]) {
                arrive = s[current];
            }
            times = ceil_div<int>(arrive - s[current], f[current]);
            departure = s[current] + f[current] * times;
            arrive = departure + c[current];
            current++;
        }
        cout << arrive << endl;
    }

    cout << 0 << endl;

    return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
mod=10**9+7
ans=0
fac=[1]
for i in range(n+1):
	r=fac[i]*(i+1)%mod
	fac.append(r)
def c(x,y):
	if x<y:
		return 0
	r=pow(fac[y]*fac[x-y]%mod,mod-2,mod)
	return r*fac[x]%mod
for i in range(min(k,n)+1):
	kari=c(n,i)
	kari*=c(n-1,i)
	ans+=kari
	ans%=mod
print(ans)





Measured memory_bytes: 52720
# -*- coding:utf-8 -*-
n = int(input())
a = [int(i) for i in input().split()]
dp = [[x, 0] for x in range(0, len(a))]
 
 
def ins(x, i):
    if x in dp[i]:
        return
    if dp[i][0] != x and a[dp[i][0]] < a[x]:
        dp[i][1] = dp[i][0]
        dp[i][0] = x
    elif dp[i][1] != x and a[dp[i][1]] < a[x]:
        dp[i][1] = x
 
 
def mix(i, j):
    ins(dp[i][0], j)
    ins(dp[i][1], j)
 
 
for i in range(0, len(a)):
    for j in range(0, n):
        if i & (1 << j) == 0:
            mix(i, i | (1 << j))
 
 
ans = 0
for i in range(1, len(a)):
    u = a[dp[i][0]]+a[dp[i][1]]
    ans = max(ans, u)
    print(ans)

Measured memory_bytes: 129356
H, W = gets.split.map(&:to_i)

c = Array.new(10)
10.times do |i|
  c[i] = gets.split.map(&:to_i)
end

A = Array.new(H)
H.times do |i|
  A[i] = gets.split.map(&:to_i)
end

10.times do |k|
  10.times do |i|
    10.times do |j|
      c[i][j] = [c[i][j], c[i][k] + c[k][j]].min
    end
  end
end

ans = 0
H.times do |i|
  W.times do |j|
    ans += c[A[i][j]][1] if A[i][j] != -1
  end
end

p ans

Measured memory_bytes: 2556
#include<iostream>
using namespace std;
int A[25];
int n;
int solve(int i ,int tmp) {
	if (tmp == 0)
		return 1;
	if (i >= n)
		return false;
	int res = solve(i + 1, tmp) || solve(i + 1, tmp - A[i]);
	return res;
}
int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> A[i];
	int t; cin >> t;
	while (t--) {
		int tmp; cin >> tmp;
		if (solve(0, tmp))
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}
}


Measured memory_bytes: 3112
// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
//
// See the bottom of file for solution.
// -----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let S = rl().chars().collect::<Vec<_>>();
    let N = S.len();
    let M = S.iter().filter(|&&c| c == '0').count();
    println!("{}", min(N - M, M) * 2);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
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: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)

struct st {
  string name;
  int point,idx;
};

int main() {
  int N; cin >> N;
  vector<st> A;
  rep(i, 0, N) {
    string s;
    int a;
    cin >> s >> a;
    A.push_back({s, a, i + 1});
  }
  sort(A.begin(), A.end(), [](const st &a, const st &b) {
    if(a.name == b.name) return a.point > b.point;
    return a.name < b.name;
  });
  for(auto p : A) cout << p.idx << endl;
  return 0;
}


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

using namespace std;

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

static int speedUp = []() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    return 0;
}();

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int dp[1000005][2];
const ll INF = 1e9;

int main() {
  // 一桁目から桁dp、dp[i][j]：i桁目まで決めた時の最小値、繰り上がりが起きているならj=1
  string S;
  cin >> S;
  reverse(S.begin(), S.end());
  S += '0';
  int N = sz(S);
  rep(i, N+1) rep(j, 2) dp[i][j] = INF;
  dp[0][0] = 0;
  rep(i, N) rep(j, 2) {
    rep(a, 10) {
      // aはその桁で払うお金、bはお釣り
      int cur = S[i] - '0';
      int ni = i+1, nj = 0;
      cur += j; // 繰り上がり
      int b = a - cur;
      if (b < 0) {
        nj = 1;
        b += 10;
      }
      dp[ni][nj] = min(dp[ni][nj], dp[i][j] + a + b);
    }
  }
  cout << dp[N][0] << '\n';
  return 0;
}

Measured memory_bytes: 12156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

int main() {
  ll n, k, r, s, p, ans = 0;
  string t, t2 = "";
  cin >> n >> k >> r >> s >> p >> t;
  REP(i, n) {
    bool f = false;
    if (i - k >= 0) {
      if (t[i] == 'r' && t2[i - k] != 'p') {
        t2 += "p";
        ans += p;
        f = true;
      }
      if (t[i] == 'p' && t2[i - k] != 's') {
        t2 += "s";
        ans += s;
        f = true;
      }
      if (t[i] == 's' && t2[i - k] != 'r') {
        t2 += "r";
        ans += r;
        f = true;
      }
    } else {
      if (t[i] == 'r') {
        t2 += "p";
        ans += p;
        f = true;
      }
      if (t[i] == 'p') {
        t2 += "s";
        ans += s;
        f = true;
      }
      if (t[i] == 's') {
        t2 += "r";
        ans += r;
        f = true;
      }
    }
    if (!f) t2 += " ";
  }
  cout << ans << "\n";
  return 0;
}


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

#define MAX_INT 0x3f3f3f3f 
#define acc(x) setprecision(x)
#define boost ios_base::sync_with_stdio(false); 	cin.tie(NULL);

int main()
{
	boost;
	long long int n,x,p;
	cin >> n >> x >> p;
	long long int ans = p*ceil((n/(double)x));
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3652
# coding: utf-8
# Your code here!

# coding: utf-8
# Your code here!
import sys

n,m = map(int,input().split())
al = list(map(int,input().split()))

while True:
    al.sort(reverse=True)
    for idx, i in enumerate(al):
        if al[0] == 0:
            print("0")
            sys.exit()
        if al[0] // i >= 2:
            for j in range(idx):
                al[j] = al[j] // 2
            m = m - idx
            break
        if idx + 1 == m:
            for j in range(idx + 1):
                al[j] = al[j] // 2
            print(sum(al))
            sys.exit()
    else:
        for j in range(n):
            al[j] = al[j] // 2
        m = m - n

Measured memory_bytes: 14428
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 string weather;
 cin >> weather;
  
  if(weather == "RRR"){
    cout << "3" << endl;}
  else if(weather == "SRR" || weather == "RRS"){
    cout << "2" << endl;}
  else if(weather == "RSR" || weather == "SSR" || weather == "SRS" || weather == "RSS"){
    cout << "1" << endl;}
  else{ cout << "0" << endl;}
  
}

Measured memory_bytes: 3584
MAX_A = 10**6 + 1
is_prim = [True] * MAX_A
is_prim[0] = is_prim[1] = False
for i in range(2, MAX_A):
    if not is_prim[i]: continue
    for j in range(i+i, MAX_A, i): is_prim[j] = False

def solve():
    C = [0] * MAX_A
    for a in A: C[a] += 1
    pairwise = True
    for p in [i for i in range(MAX_A) if is_prim[i]]:
        if sum(C[p::p]) > 1: pairwise = False
    if pairwise: return 'pairwise'
    from math import gcd
    g = 0
    for a in A: g = gcd(g, a)
    if g == 1: return 'setwise'
    return 'not'


n = int(input())
A = [*map(int, input().split())]
print(solve(), 'coprime')


Measured memory_bytes: 134792
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"-----------------"#x"-----------------\n"
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
                    For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> pii;
LL read(){
    LL x=0,f=0;
    char ch=getchar();
    while (!isdigit(ch))
        f=ch=='-',ch=getchar();
    while (isdigit(ch))
        x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return f?-x:x;
}
const int N=300005;
int n;
int a[N],b[N];
int check(int L,int R){
	For(i,L,R)
		b[i]=a[i];
	sort(b+L,b+R+1);
	For(i,L,R)
		if (b[i]!=i)
			return 0;
	int lv=0;
	For(i,L,R)
		if ((i-L)%2==0&&a[i]<i){
			if (a[i]<lv)
				return 0;
			lv=a[i];
		}
	int rv=n+1;
	Fod(i,R,L)
		if ((i-L)%2==0&&a[i]>i){
			if (a[i]>rv)
				return 0;
			rv=a[i];
		}
	return 1;
}
int main(){
	n=read();
	For(i,1,n)
		a[i]=read();
	int i=1;
	while (i<=n){
		while (i<=n&&a[i]==i)
			i++;
		if (i>n)
			break;
		int j=i;
		while (j<=n-2&&a[j+1]==j+1&&a[j+2]!=j+2)
			j+=2;
		if (!check(i,j))
			return puts("No"),0;
		i=j+1;
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>

int main(void){
  int n,x,i;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    x=i;
    if(x%3==0)
      printf(" %d",i);
    else{
      do{
	if(x%10==3){
	  printf(" %d",i);
	  break;
	}else x /= 10;
      }while(x != 0);
    }
  }
  puts("");
  return 0;
}

Measured memory_bytes: 608
def function(n):
    if n%2 == 0:
        return n//2
    else:
        return 3*n+1
s = int(input())
a = []
a.append(s)
i = 0
while len(a) == len((set(a))):
    a.append(function(a[i]))
    i += 1
print(i+1)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rrep(i, n) for(ll i = n - 1; i > -1; i--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
const ll INF = (1LL << 61) - 1;
const ll MOD = 1000000007 /*998244353*/;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, h, x, y, z, p, q, n, t, r, k, w, l, ans, i, j, u, v;
string S, T;
vl A, B;
void input() { cin >> x; }
void solve() { cout << x * x * x + x * x + x << endl; }
int main() {
    // cout<<fixed<<setprecision(15);
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    solve();
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define ld long double
#define vii vector<ii>
#define vll vector<ll>
#define maxn 111

template<typename T>
void trace(T a){ cout << a << '\n';}
template<typename T, typename... Args>
void trace(T a, Args ...args){ cout << a << ' '; trace(args...);}

ii a[maxn];
ii op = {0, 10000000};

int cross(ii a, ii b) {
	return a.fi*b.se - a.se*b.fi;
}

bool cmp (ii x, ii y) {
	return atan2(x.second, x.first) < atan2(y.second, y.first);
}

int32_t main(){
	int n,x,y;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> x >> y;
		a[i] = {y, x};
	}
	sort(a,a+n, cmp);
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		int j = i, left = n, dx = 0, dy = 0;
		while (left--) {
			dx += a[j].fi;
			dy += a[j].se;
			ans = max(ans, dx*dx + dy*dy);
			j = (j+1) % n;
		}
	}
	cout << fixed << setprecision(40) << sqrt(ans) << '\n';
 	return 0;
}



Measured memory_bytes: 256
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N = int(input())

mod = 10**9+7
# dp[i][a][b][c] : 左からi番目まで文字を決めたときの右端から3文字をc,b,aとしたときの場合の数
dp = [[[[0 for _ in range(4)] for _ in range(4)] for _ in range(4)] for _ in range(N+1)]
# a,b,cについて : 0 -> "T", 1 -> "A", 2 -> "G", 3 -> "C"
# 初期値はTTTが左にあると考えても影響はない
dp[0][0][0][0] = 1

for i in range(N):
    for a in range(4):
        for b in range(4):
            for c in range(4):
                for d in range(4):
                    # AG*C or A*CG
                    if (a==1 and b==2 and d==3) or (a==1 and c==2 and d==3):
                        continue
                    # *AGC
                    if (b==1 and c==2 and d==3):
                        continue
                    # *GAC or *ACG
                    if (b==2 and c==1 and d==3) or (b==1 and c==3 and d==2):
                        continue
                    dp[i+1][b][c][d] += dp[i][a][b][c]
                    dp[i+1][b][c][d] %= mod

ans = 0
for i in range(4):
    for j in range(4):
        for k in range(4):
            ans += dp[N][i][j][k]

print(ans%mod)


Measured memory_bytes: 3316
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define fore(e, u, v) for (int p = e(u), v = e[p].y; p; v = e[p = e[p].nxt].y)
#define ri rd<int>
using namespace std;
const int maxN = 1e5 + 7;

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

inline void TAK() { puts("First"); exit(0); }
inline void NIE() { puts("Second"); exit(0); }

int n;
int deg[maxN], sz[maxN];

struct vec {
	static const int maxE = maxN;
	int g[maxN], te;
	struct edge {int y, nxt;} e[maxE << 1];
	inline void push(int x, int y) {e[++te] = (edge){y, g[x]}; g[x] = te;}
	inline void link(int x, int y) {push(x, y), push(y, x); ++deg[x], ++deg[y];}
	inline int& operator () (int x) {return g[x];}
	inline edge& operator [] (int x) {return e[x];}
}e;

void dfs(int x, int fa) {
	sz[x] = 1;
	int f = 0;
	fore (e, x, y) if (y != fa) {
		dfs(y, x);
		sz[x] += sz[y];
		if (sz[y] & 1) ++ f;
	}
	if (f > 1) TAK();
}

int main() {

	n = ri();
	For (i, 1, n) e.link(ri(), ri());
	if (n & 1) TAK();
	if (n == 2) NIE();
	rep (i, 1, n) if (deg[i] > 1) {
		dfs(i, 0);
		break;
	}

	NIE();
	return 0;
}

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

int main() {
    bool yfl = true;
    int N;
    cin >> N;
    set<string> st;
    char tmp = 0;
    for(int i = 0; i < N; ++i) {
        string W;
        cin >> W;
        if(tmp != 0 && tmp != W[0])
            yfl = false;
        tmp = W[W.length() - 1];
        if(st.find(W) != st.end())
            yfl = false;
        st.insert(W);
    }
    cout << (yfl ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.*;

public class Main {
	public static void main(String[] args) {
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			int x = Integer.parseInt(br.readLine());
			System.out.println((int) Math.pow(x, 3.0));
		} catch (NumberFormatException | IOException e) {
			e.printStackTrace();
		}
	}
}


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

using namespace std;
#define NIL -1
#define ll long long
#define MAX 100
#define pb push_back

int main()
{
	int n;
	cin >> n;
	int arr[n];
	for(int i=0; i<n; i++) cin >> arr[i];
	sort(arr, arr+n);
	ll s1=0, s2=0;
	for(int i=0; i<n; i++) {
		if(i%2) s2+=arr[i];
		else s1+=arr[i];
	}
	//cout << s1 <<  " " << s2 << endl;
	cout << abs(s1-s2) << endl;
	return 0;
}


Measured memory_bytes: 3616
#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else
#define DMP(...) ((void)0)
#endif

#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

template<class T>
inline bool chmax(T& a, const T b) { return a < b && (a = b, true); }

int main() {

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

	int ans = 0;
	for (int i = 0; i <= s.size() - t.size(); i++) {
		int cnt = 0;
		for (int j = 0; j < t.size(); j++) {
			cnt += s[i + j] == t[j];
		}
		chmax(ans, cnt);
	}

	cout << t.size() - ans << "\n";

	return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

#define ll long long
const long long llINF = 1LL << 60;
const int iINF = 1LL << 20;
template<class T> inline bool chmin(T& a, T b) { if (b < a) { 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; }

void execute();
int main() 
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);// cin と scanfの併用禁止
    cout << fixed << setprecision(15);
    execute();
    return 0;
}


void execute()
{
    int A, B, C, K;
    cin >> A >> B >> C >> K;

    int score = 0;
    score += (A < K) ? A : K;
    K -= A;
    if(K < 0) K = 0;

    K -= B;
    if(K < 0) K = 0;

    score -= K;

    cout << score << endl; 
}


Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
string a,b;
long long dp[3005][3005];
void lcs(int n, int m)
{
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=m;j++)
        {
            if(i==0||j==0)
            {
                dp[i][j]=0;
            }
            else if(a[i-1]==b[j-1])
            dp[i][j]=dp[i-1][j-1]+1;
            else
            {
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }    
        }
    }
    int ans=dp[n][m];
    char lcs[ans+1]; 
    lcs[ans]='\0';
  
   int i = n, j = m; 
   while (i > 0 && j > 0) 
   { 
      if (a[i-1] == b[j-1]) 
      { 
          lcs[ans-1] = a[i-1];
          i--; j--; ans--;    
      } 
      else if (dp[i-1][j] > dp[i][j-1]) 
         i--; 
      else
         j--; 
   } 
   cout<<lcs<<endl;
}

int main()
{
    cin>>a>>b;
    int n=a.length();
    int m=b.length();
    lcs(n,m);  

    return 0;
}

Measured memory_bytes: 70784
#include <stdio.h>

int main(){
   int a,b,i,k;
    
   scanf("%d%d%d",&a,&b,&k);
   for (i=0;i<k;i++)
      if (i%2==0)  {
        if (a%2==1) a--;
        b+=(a=a/2);
      } else {
        if (b%2==1) b--;
        a+=(b=b/2);
      }               
   printf("%d %d\n",a,b);
   return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#define INF long long int(1e18+1)
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;



int main() {
	string s, t, u;
	int x, y;
	cin >> s >> t;
	cin >> x >> y >> u;
	if (u == s)cout << x - 1 << " " << y << endl;
	else cout << x << " " << y - 1 << endl;
}




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

#define MAXINF 1000000005
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define repc(it, x) for(auto it = (x).begin(); it != (x).end(); ++it)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rrepc(it, x) for(auto it = (x).rbegin(); it != (x).rend(); ++it)
#define all(x) (x).begin(), (x).end()
#define P pair<int, int>

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, c;
    cin >> a >> b >> c;
    bool left = (c-a-b) > 0;
    bool right = 4*a*b < (c-a-b)*(c-a-b);
    if(left && right) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
from copy import deepcopy as copy
from operator import itemgetter

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.par = [-1]*(n+1)#それぞれの要素がどの要素の子であるか

    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]#それぞれの要素の根を再帰的に求める

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.par[x] > self.par[y]:
            x, y = y, x
        
        self.par[x] += self.par[y]
        self.par[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)#x,yが同じ集合に属するかどうか
    
    def size(self, x):
        return -self.par[self.find(x)]
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if root == self.find(i)]        

def main():
    n = int(input())
    bridge = [None]*n
    for i in range(n):
        bridge[i] = [int(x) for x in input().split()]+[i]

    judge = []

    bridge.sort()
    for i in range(n-1):
        judge.append((bridge[i+1][0]-bridge[i][0], bridge[i][2], bridge[i+1][2]))

    bridge.sort(key=itemgetter(1))
    for i in range(n-1):
        judge.append((bridge[i+1][1]-bridge[i][1], bridge[i][2], bridge[i+1][2]))
    
    judge.sort()
    union = UnionFind(n)
    count = 0
    cost = 0
    for k in range(2*n):
        c, i, j = judge[k]
        if union.same(i, j):
            continue
        union.union(i, j)
        cost += c
        count += 1
        if count == n-1:
            break
    
    print(cost)

if __name__ == "__main__":
    main()

Measured memory_bytes: 50564
#include <iostream>
using namespace std;
static const int MAX=10;
int c[MAX][MAX];
int d[MAX][MAX];

void warshall_floyd() {
    int i,j,k;
    for (k = 0; k < MAX; k++) {
        for (i = 0; i < MAX; i++) {
            for (j = 0; j < MAX; j++) {
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }
}


int main() {
    int H,W,i,j,k,a;
    cin >> H >> W;
    for (i = 0; i < MAX; i++) {
        for (j = 0; j < MAX; j++) {
            cin >> c[i][j];
        }
    }
    warshall_floyd();
    int ans = 0;
    for (i = 0; i < H; i++) {
        for (j = 0; j < W; j++) {
            cin >> a;
            if (a == -1 or a == 1) {
                continue;
            } else {
                ans += c[a][1];
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int x,y,t,i;
    for(i=0;i<3000;i++){
        scanf("%d %d",&x,&y);
        if(x==0&&y==0) break;
        if(x>y){
            t=x;
            x=y;
            y=t;
        }
        printf("%d %d\n",x,y);
    }
    return 0;
}


Measured memory_bytes: 2608
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,M,R;
    cin >> N >> M >> R;
    vector<int> V(R);
    rep(i,0,R){
        cin >> V[i];
        V[i]--;
    }
    int dist[N][N];
    rep(i,0,N)rep(j,0,N)dist[i][j] = INF;
    rep(i,0,N)dist[i][i] = 0;
    rep(i,0,M){
        int a,b,c;
        cin >> a >> b >> c;
        a--;b--;
        dist[a][b] = dist[b][a] = c;
    }
    rep(i,0,N)rep(j,0,N)rep(k,0,N)dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
    sort(V.begin(), V.end());
    int mini = INF;
    do{
        int sum = 0;
        rep(i,0,R-1){
            sum += dist[V[i]][V[i+1]];
        }
        mini = min(mini, sum);
    }while(next_permutation(V.begin(), V.end()));
    cout << mini << endl;
}

Measured memory_bytes: 384
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func scanInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func main() {
	sc.Split(bufio.ScanWords)
	n, m := scanInt(), scanInt()
	p := make([]int, m)
	s := make([]string, m)

	for i := 0; i < m; i++ {
		p[i] = scanInt()
		s[i] = scanText()
	}

	allwa := 0
	allac := 0
	wa := make([]int, n+1)
	for i := 0; i < m; i++ {
		if s[i] == "WA" && wa[p[i]] != -1 {
			wa[p[i]]++
		} else if wa[p[i]] != -1 {
			allwa += wa[p[i]]
			wa[p[i]] = -1
			allac++
		}
	}
	fmt.Println(allac, allwa)
}


Measured memory_bytes: 4736