akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

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

    int n, t;
    cin >> n >> t;
    int a[n], b[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }

    int dp[t][2];
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < n; i++) {
        for (int j = 1; j >= 0; j--) {
            for (int k = t - 1; k >= 0; k--) {
                if (k >= a[i]) {
                    dp[k][j] = max(dp[k][j], dp[k-a[i]][j] + b[i]);
                }
                if (j == 1) {
                    dp[k][1] = max(dp[k][1], dp[k][0] + b[i]);
                }
            }
        }
    }

    cout << dp[t-1][1] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<cstring>
using namespace std;
#define mems(a) (memset(a,0,sizeof(a)))
int grid[102][102];
int height, width, sum, colors, counts;
int main()
{
	cin >> height >> width >> sum;
	mems(grid);
	counts = -1;
	for (int i = 1; i <= sum; i++)
		{
			cin>>colors;
			while (colors--)
			{
				counts++;
				grid[(counts / height) & 1 ? (height - 1 - (counts%height)) : counts % height][counts / height] = i;
			}
		}
		for (int i = 0; i<height; i++)
		{
			for (int j = 0; j<width; j++)
			{
				if (j!=0) cout<<" ";
				cout<<grid[i][j];
			}
			cout << endl;
		}
	
	return 0;
}

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

int main() {
  int h, w, n;
  cin >> h >> w >> n;

  vector<int> a(n);
  for (auto &i : a) cin >> i;

  int idx = 0;
  vector<deque<int>> d(h);
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < a[i - 1]; ++j) {
      if (d[idx].size() == w) idx++;

      if (idx & 1) d[idx].push_back(i);
      else d[idx].push_front(i);
    }
  }

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cout << d[i][j] << (j + 1 == w ? "\n" : " ");
    }
  }
}


Measured memory_bytes: 384
<?php
list($N,$L) = explode(" ",trim(fgets(STDIN)));
$a = explode(" ",trim(fgets(STDIN)));

$sum = array_sum($a);

if($sum < $L){
    echo "Impossible";
}elseif($sum == $L){
    if($N == 2){
        echo "Possible\n";
        echo 1;
    }else{
        echo "Impossible";
    }
}else{
    if(max($a) >= $L){
        echo "Possible\n";
        $num = array_search(max($a),$a);
        if($num == 0){
            for($i = $N - 1;$i > 0;$i--){
                echo $i ."\n";
            }
        }elseif($num == $N - 1){
            for($i = 1;$i < $N;$i++){
                echo $i ."\n";
            }
        }else{
            for($i = 1;$i < $num + 1;$i++){
                echo $i ."\n";
            }
            for($i = $N - 1;$i > $num;$i--){
                echo $i ."\n";
            }
        }
    }else{
        for($i = 0;$i < $N - 1;$i++){
            $sum2[] = $a[$i] + $a[$i + 1];
        }
        if(max($sum2) >= $L){
            echo "Possible\n";
            $num = array_search(max($sum2),$sum2);
            if($num == 0){
                for($i = $N - 1;$i > 0;$i--){
                    echo $i ."\n";
                }
            }elseif($num == $N - 1){
                for($i = 1;$i < $N;$i++){
                    echo $i ."\n";
                }
            }else{
                for($i = 1;$i < $num + 1;$i++){
                    echo $i ."\n";
                }
                for($i = $N - 1;$i > $num;$i--){
                    echo $i ."\n";
                }
            }
        }else{
            echo "Impossible";
        }
    }
}

Measured memory_bytes: 35912
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vvb=vector<vb>;
using vc=vector<char>;
using vvc=vector<vc>;
using pii = pair<int,int>;
using pil = pair<int,ll>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using tiii = tuple<int,int,int>;
using vpii = vector<pii>;
using vpil = vector<pil>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  rep(i,N) cin >> S[i];
  vi count(4);
  rep(i,N) {
    if(S[i]=="AC") count[0]++;
    else if(S[i]=="WA") count[1]++;
    else if(S[i]=="TLE") count[2]++;
    else if(S[i]=="RE") count[3]++;
  }
  
  printf("AC x %d\n",count[0]);
  printf("WA x %d\n",count[1]);
  printf("TLE x %d\n",count[2]);
  printf("RE x %d\n",count[3]);
}

Measured memory_bytes: 6424
#include<bits/stdc++.h>
using namespace std;
struct node
{
	int a,b,c,d;
};
vector<node> v;
int a[600][600];
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i = 1;i <= n;i ++)
		for(int j = 1;j <= m;j ++)
		scanf("%d",&a[i][j]);

	for(int i = 1;i <= n;i ++)
	{
		for(int j = 1;j <= m;j ++)
		{
			if(a[i][j]&1)
			{
                if(j < m)
				{
                    a[i][j] --;
                    a[i][j+1] ++;
                    node z;
                    z.a = i;
                    z.b = j;
                    z.c = i;
                    z.d = j+1;
                    v.push_back(z);
				}else if(i < n)
				{
					a[i][j] --;
					a[i+1][j] ++;
					node z;
					z.a = i;
                    z.b = j;
                    z.c = i+1;
                    z.d = j;
                    v.push_back(z);
				}
			}
		}
	}
	printf("%d\n",v.size());
	for(int i = 0;i < v.size();i ++)
	{
		printf("%d %d %d %d\n",v[i].a,v[i].b,v[i].c,v[i].d);
	}
	return 0;
}


Measured memory_bytes: 5360
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	string s, t;
	cin >> s >> t;
	
	int n = s.size();
	bool yes = false;
	for(int i = 0; i < n; ++i) {
		if( s == t ) { 
			yes = true;
			break;
		}
		
		s = s.back() + s.substr(0, n - 1); 
	}
	
	if( yes ) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

n, k = map(int, input().split())
s = input()
s_list= []
for c in s:
    s_list.append(c)
swapped = s_list[k - 1].swapcase()
s_list[k - 1] = swapped
ret = "".join(s_list)
print(ret)



Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<unordered_map>
#include<set>
#include<stack>
#include<queue>
#include<sstream>
#include<iomanip>

#define reps(i,j,k) for(int i=(j);i<(k);i++)
#define rep(i,j) reps(i,0,j)
#define fs first
#define sc second
#define pb push_back
#define mk make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

template<class S,class T>
ostream &operator<<(ostream &out, const pair<S,T> p){
	return out << "(" << p.fs << ", " << p.sc << ")";
}

template<class T>
ostream &operator<<(ostream &out, const vector<T> &v){
	out << "{";
	rep(i,v.size()) out << v[i] << ", ";
	return out << "}" << endl;
}

int d[15][15];
int INF = 1<<28;
int dp[1<<15][15];

int dist(string &a, string &b){
	string sub = "";
	int res = 0;
	rep(i, min(a.length(), b.length())){
		sub += b[i];
		string sa = a.substr(a.length() - i - 1);
		if(sa == sub) res = max(res, i+1);
	}
	return b.length() - res;
}

// is a in b ?
bool in(const string &a, const string &b){
	if(a.length() > b.length()) return false;
	rep(i, b.length() - a.length() + 1){
		if(b.substr(i, a.length()) == a) return true; 
	}
	return false;
}

int main(){
	int n;
	while(cin >> n, n){
		vector<string> v(n);
		rep(i, n){
			cin >> v[i];
		}
		bool f;
		do{
			f = false;
//			continue;
			rep(i, n){
				if(f) break;
				rep(j,n){
					if(i != j && in(v[i], v[j])){
						v.erase(v.begin() + i);
						n--;
						f=true;
						break;
					}
				}
			}
		}while(f);
		rep(i,n){
			rep(j,n) if(i != j){
				d[i][j] = dist(v[i], v[j]);
//				cout << d[i][j] << ", ";
			}
//			cout << endl;
		}
		fill(dp[0], &dp[(1<<15)-1][14], INF);
		rep(i, n){
//			cout << dp[(1<<n) - 1][i] << ", ";
			dp[1<<i][i] = v[i].length();
		}
		rep(i, 1<<n){
			rep(j, n){ // from
				rep(k, n){ // to
					if((i & (1<<k)) > 0) continue;
					dp[i | (1 << k)][k] = min(dp[i | (1<<k)][k], d[j][k] + dp[i][j]);
				}
			}
		}
		int ans = INF;
		rep(i, n){
			ans = min(ans, dp[(1<<n) - 1][i]);
//			cout << dp[(1<<n) - 1][i] << ", ";
		}

		cout << ans << endl;
	}
	return 0;
}



Measured memory_bytes: 5076
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        int A = Integer.parseInt(scan.next()); 
        int B = Integer.parseInt(scan.next());
        int C = Integer.parseInt(scan.next());
        scan.close();
        
        int res = C - (A - B);
        res = res < 0 ? 0 : res;
        System.out.println(res);
    }
}

Measured memory_bytes: 22868
#include <cmath>
#include <iostream>
#include <vector>

typedef long long ll;

using namespace std;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 2019;
struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

string str;

int main(int argc, char const* argv[]) {
    cin >> str;
    reverse(str.begin(), str.end());
    int n = (int)str.size();
    vector<int> cnt(mod);
    ll ans = 0;
    mint tot = 0;
    mint x = 1;
    for (int i = 0; i < n; i++) {
        cnt[tot.x]++;
        tot += (str[i] - '0') * x.x;
        ans += cnt[tot.x];
        x *= 10;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3352
import math
from functools import reduce
from sys import stdin 
n = int(stdin.readline().rstrip())
def gcd(*numbers):
    return reduce(math.gcd, numbers)
answer = 0
for i in range(n):
    for j in range(n):
        for k in range(n):
            answer += gcd(i+1,j+1,k+1)
print(answer)

Measured memory_bytes: 69500
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define INF 1000000007
//S.size()

using namespace std;


typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<bool> VB;
typedef unsigned long long ll;



int main(void){
  int N;cin>>N;
  VI a(N);rep(i ,N)cin>>a[i];
  int sumA = 0,sumB = 0;

  SORT(a);

  for(int t = 0;t < N;t++){
    if(N % 2 == 0 ){
      if(t % 2 != 0)sumA += a[t];
      else sumB += a[t];
    }
    else {
      if(t % 2 != 0)sumB += a[t];
      else sumA += a[t];
    }

  }
  cout<<sumA - sumB;
}


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

int digit_num(long long x){
    int cnt = 0;
    while(x > 0){
        x /= 10;
        cnt++;
    }
    return cnt;
}

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

    long long n;
    cin >> n;
    
    int ans = digit_num(n);
    for(long long i = 1LL; i * i <= n; i++){
        if(n % i == 0){
            long long b = n / i;
            ans = min(ans, max(digit_num(i), digit_num(b)));
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
a = gets.chomp.split(" ").map(&:to_i)
b = gets.chomp.split(" ").map(&:to_i)

c = Array.new(a[0], 0)
c[a[0]-1] = b[-1]
d = Array.new(a[0],0)

for i in 1..(a[0]-1)
  c[a[0]-i-1] = b[a[0]-i-1] > c[a[0]-i] ? b[a[0]-i-1] : c[a[0]-i]
  d[a[0]-i-1] = c[a[0]-i-1] - b[a[0]-i-1]
end
p d.count(d.max)

Measured memory_bytes: 11020
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;

int n, m;
int trie[400005][26], piv, sum[400005], term[100005];
string s[100005];
char str[400005];
int cnt[100005][26][26];

int main(){
	scanf("%d",&n);
	for(int i=0; i<n; i++){
		scanf("%s", str);
		int p = 0;
		for(int j=0; str[j]; j++){
			if(!trie[p][str[j] - 'a']){
				trie[p][str[j] - 'a'] = ++piv;
			}
			p = trie[p][str[j] - 'a'];
		}
		s[i] = str;
		term[i] = p; 
		sum[p]++;
	}
	for(int i=piv; i>=0; i--){
		for(int j=0; j<26; j++){
			if(trie[i][j]) sum[i] += sum[trie[i][j]];
		}
	}
	for(int i=0; i<n; i++){
		int p = 0;
		for(auto &j : s[i]){
			int nxt = j - 'a';
			for(int k=0; k<26; k++){
				if(k != nxt && trie[p][k]) cnt[i][nxt][k] += sum[trie[p][k]];
			}
			p = trie[p][nxt];
		}
	}
	int q;
	scanf("%d",&q);
	for(int i=0; i<q; i++){
		int pos;
		scanf("%d %s",&pos, str);
		int ans = sum[term[--pos]];
		for(int j=0; j<26; j++){
			for(int k=0; k<j; k++){
				ans += cnt[pos][str[k] - 'a'][str[j] - 'a'];
			}
		}
		printf("%d\n", n+1-ans);
	}
}


Measured memory_bytes: 284032
# -*- coding: utf-8 -*-
from itertools import combinations
 
def inpl(): return list(map(int, input().split()))
 
N = int(input())
res = 0
exist = True
A = []
 
for _ in range(N):
    A.append(inpl())
 
for i, j in combinations(range(N), 2):
    vervose = False
 
    if not exist:
        break
 
    for k in range(N):
        if i == k or j == k:
            pass
        else:
            if A[i][j] < A[i][k] + A[k][j]:
                pass
            elif A[i][j] == A[i][k] + A[k][j]:
                vervose = True
            else:
                exist = False
                break
    if vervose:
        pass
    else:
        res += A[i][j]
 
if exist:
    print(res)
else:
    print(-1)

Measured memory_bytes: 43996
#!/usr/bin/env python3
import numpy as np

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    H, W, M = list(map(int, input().split()))
    h = np.zeros(M, dtype=int)
    w = np.zeros(M, dtype=int)

    sum_h = np.zeros(H, dtype=int)
    sum_w = np.zeros(W, dtype=int)



    for m in range(M):
        tmp = list(map(int, input().split()))
        tmp_h = tmp[0]-1
        tmp_w = tmp[1]-1

        h[m] = tmp_h
        w[m] = tmp_w

        sum_h[tmp_h] += 1
        sum_w[tmp_w] += 1

    if H == 1:
        print(sum_w.sum())
        return
    elif W == 1:
        print(sum_h.sum())
        return

    ans1 = 0

    ans_h = np.argmax(sum_h) # hについては決定
    ans1 += max(sum_h)

    sum_w_copy = sum_w.copy()
    for m in range(M):
        if h[m] == ans_h:
            sum_w_copy[w[m]] -= 1

    ans_w = np.argmax(sum_w_copy)
    ans1 += max(sum_w_copy)

    ans2 = 0

    ans_w = np.argmax(sum_w)
    ans2 += max(sum_w)

    sum_h_copy = sum_h.copy()
    for m in range(M):
        if w[m] == ans_w:
            sum_h_copy[h[m]] -= 1

    ans_h = np.argmax(sum_h_copy)
    ans2 += max(sum_h_copy)

    print(max(ans1, ans2))
    pass


if __name__ == '__main__':
    main()


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

int main(){
    string S, T, U;
    int A, B;
    cin >> S >> T;
    cin >> A >> B;
    cin >> U;
    if (S==U){
        A-=1;
    }else if (T==U){
        B-=1;
    }

    char result[50];
    sprintf(result, "%d %d", A, B);
    cout << result << endl;
}

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

using namespace std;

#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template<class T>
void print(vector<T>& V, bool spaced = true) {
    string space;
    spaced ? space = " " : space = "";
    for(int i = 0; i < V.size(); i++) {
        cout<< V[i] << space;
    }cout<< '\n';
}

template<class T>
void printendl(vector<T>& V) {
    for(int i = 0; i < V.size(); i++) {
        cout<< V[i] << '\n';
    }
}

template<class T>
T gcd(T a, T b) {
    T r;
    while (b != 0) {
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}

template <class T>
T lcm (T a, T b) {
    return a / gcd(a, b) * b;
}

template<class T>
T Max(T a, T b) {
    return (a < b) ? b : a;
}

template<class T>
T Min(T a, T b) {
    return (a < b) ? a : b;
}

//str

bool isPalindrome(string str){
    
    int length = str.length();
 
    for (int i = 0; i < (length / 2); i++)
        if (str[i] != str[length - 1 - i])
            return false;
 
    return true;    
}

void reverseStr(string& str) 
{ 
    int n = str.length(); 
    for (int i = 0; i < n / 2; i++) 
        swap(str[i], str[n - i - 1]); 
}
 

//Read through the messages at the end when you're done

int main() {

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

    
    int n; cin>> n;
    map<ll, ll> m;
    vll v(n);
    vpll p;
    rep(i, 0, n) {
        cin>> v[i];
        m[v[i]]++;
    }

    ll tot = 0;
    for(map<ll, ll>:: iterator it = m.begin(); it != m.end(); ++it) {
        ll x = it->second;
        if(x > 1)
        tot += x*(x-1)/2;
    }

    rep(i, 0, n) {
        ll res = (m[v[i]]-1)*(m[v[i]]-2)/2;
        if (m[v[i]]-1 <= 1) res = 0;
        cout << tot - m[v[i]]*(m[v[i]] - 1)/2 + res << "\n";

    }

    return 0;
}

    //Use long long da5eel rabbak!
    //Dont use endl;
    //DONT SUBMIT IZA UR NOT SURE WALLAHI BTENDAM
    //Dear Amine, just because it worked for the test cases doesnt necessarily mean it is correct.
    //Dear Amine, try it on ur own test cases iza ur not SURE
    //In case u didnt use long long, CHECK FOR POTENTIAL OVERFLOWS
    //DONT FORGET TO MOD EVERYTHING IZA U NEED TO MOD



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

int main() {
  int L, R;
  int l, r, min;
  cin >> L >> R;
  l = L % 2019;
  r = R % 2019;
  if(L-l+2019<=R)
    min = 0;
  else {
    min = l*r%2019;
    for(int i=l; i<r; ++i)
      for(int j=i+1; j<r+1; ++j)
        if(min>i*j%2019)
          min = i*j%2019;
  }
  cout << min << endl;
  return 0;
}

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

int main(){

	double a, tmp, sum;

	while(cin >> a){
		sum = a;
		tmp = a;

		for(int i=2;i<=10;++i){
			if(i%2 == 0)
				a=tmp*2.0;
			else
				a=tmp/3.0;

			tmp = a;

			sum+=a;
		}

		cout << fixed << setprecision(8) << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, int(n) + 1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)
const int MOD = 1000000007;

template <typename T>
void __dump__(std::ostream &os, const T &first) {
    os << first;
}
template <typename First, typename... Rest>
void __dump__(std::ostream &os, const First &first, const Rest &... rest) {
    os << first << ", ";
    __dump__(os, rest...);
}
#define dump(...)                                         \
    do {                                                  \
        std::ostringstream os;                            \
        os << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; \
        __dump__(os, __VA_ARGS__);                        \
        std::cerr << os.str() << std::endl;               \
    } while (0)

using Weight = int;
using Flow = int;
struct Edge {
    int src, dst;
    Weight weight;
    Flow cap;
    Edge() : src(0), dst(0), weight(0) {}
    Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

void add_edge(Graph &g, int a, int b, Weight w = 1) {
    g[a].emplace_back(a, b, w);
    g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); }


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

    int n;
    while(cin >> n){
        vector<ll> a(n*3);
        rep(i, 3*n){
            cin >> a[i];
        }
        sort(all(a));
        ll ans = 0;
        rep(i, n){
            ans += a[n+i*2];
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
using namespace std;
#define i64  long long
#define lint long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807
#define MOD 1000000007

#define int long long

int N_global;



void solve()
{

  int N;
  cin>>N;

  vector<int> factor(N+2,0);
  
  for (int i = 2 ; i <=N; i++)
  {
    int A = i;
    for (int p = 2; p <= sqrt(i) + 1; p++)
    {
      while(A%p == 0)
      {
        A/=p;
        factor[p]++;
      }
    }
    if(A > 0)
    {
      factor[A]++;
    }
  }


  factor[1] = 0;

  //i番目の数までを使って、約数がj個となるものの個数
  vector<vector<int> > DP(N+2,vector<int>(76,0));

  DP[0][1] = 1;
  int suf;
  for (int i = 1; i <= N + 1 ; i++)
  {

    for (int j = 1; j < 76; j++)
    {
      if(factor[i] > 0)
      {
      for (int e = 0; e <= factor[i]; e++)
      {
        if(j %(e + 1) == 0)
        {
          suf = j /(e + 1);
          DP[i][j] += DP[i-1][suf];
        }
      }
      }
      else
      {
        DP[i][j] = DP[i-1][j];
      } 
    }
  }
     

  cout<<DP[N + 1][75]<<endl;
  

}
 
int32_t main(int32_t argc, const char *argv[])
{
 
  solve();
 
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int64_t K;
  cin>>K;
  int64_t a=K/50;
  int64_t b=K%50;
  vector<int64_t>A(50,49+a);
  for(int i=0;i<50-b;i++)
    A.at(i)-=b;
  for(int i=50-b;i<50;i++)
    A.at(i)+=51-b;
  cout<<50<<endl;
  for(int i=0;i<49;i++)
    cout<<A.at(i)<<" ";
  cout<<A.at(49)<<endl;
   return 0;
}


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

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN];
int head,tail,n;

void enqueue(P x){
  Q[tail]=x;
  tail=(tail+1)%LEN;

}

P dequeue(){
  P x=Q[head];
  head=(head+1)%LEN;
  return x;
}

int min(int a,int b){
  return a<b?a:b;
}

int main(){
  int elaps=0,c;
  int i,q;
  P u;
  
  scanf("%d %d",&n,&q);
  
  for(i=1;i<=n;i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
  }
  head=1;
  tail=n+1;

  while(head != tail){
    u=dequeue();
    c=min(q,u.t);
    u.t -= c;
    elaps +=c;
    if(u.t>0) enqueue(u);
    else{
      printf("%s %d\n",u.name,elaps);
    }

  }

  return 0;
}



Measured memory_bytes: 11884
#include <stdio.h>

int main(int argc, const char * argv[]){
    int a[101][101], b[101], c[101];
    int i, j;
    int n, m;
    
    scanf("%d%d", &n, &m);
    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) scanf("%d", &a[i][j]);
    }
    for (j = 0; j < m; j++) scanf("%d", &b[j]);
    
    for (i = 0; i < n; i++) {
        c[i] = 0;
        for (j = 0; j < m; j++) c[i] += a[i][j] * b[j];
    }
    
    for (i = 0; i < n; i++) {
        printf("%d\n", c[i]);
    }
    return 0;
}


Measured memory_bytes: 2124
/// Updated! https://www.youtube.com/watch?v=U07_n9xGIlM
#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define dbug printf("I am here\n");
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int maxn = 2e5+100;

const ll inf = 1e18;

int main()
{
    fast;
    string a;
    cin >> a;
    int n = a.size();
    for(int i = 1; i<=n; i++)cout << 'x';
    return 0;
}
/*



*/



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

int main() {
  	int N, D, X;
	cin >> N >> D >> X;
  	vector<int> A(N);
	rep(i, 0, N) cin >> A[i];

	int ans = X + N;
	for (auto& x : A) {
		ans += (D - 1) / x;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
A=list(map(int,input().split()))
S,T,X=[[int(input()) for i in range(A[j])] for j in range(3)]
def binary(a,l,):
	low=0
	high=len(l)-1
	while high-low>1:
		mid=(low+high)//2
		if l[mid]<a:
			low=mid
		else:
			high=mid
	return [l[high],l[low]]
			
for x in X:
	s=set(binary(x,S))
	t=set(binary(x,T))
	Min=20000000000
	for i in s:
		for j in t:
			Min=min(Min,min(abs(x-i),abs(x-j))+abs(i-j))
	print(Min)
	

Measured memory_bytes: 16144
from collections import defaultdict

n = int(input())
line = defaultdict(list)
row = defaultdict(list)
A = defaultdict(list)  # U,R
B = defaultdict(list)  # L,D
C = defaultdict(list)  # U,L
D = defaultdict(list)  # R,D

for i in range(n):
    x, y, u = input().split()
    x = int(x)
    y = int(y)
    if u == "U":
        row[x].append((y, True))
        A[y + x].append((y - x, True))
        C[y - x].append((y + x, True))
    elif u == "D":
        row[x].append((y, False))
        B[y + x].append((y - x, False))
        D[y - x].append((y + x, False))
    elif u == "L":
        line[y].append((x, False))
        B[y + x].append((y - x, True))
        C[y - x].append((y + x, False))
    else:
        line[y].append((x, True))
        A[y + x].append((y - x, False))
        D[y - x].append((y + x, True))

ans = 10**18
for Z in (line, row, A, B, C, D):
    for z_list in Z.values():
        z_list.sort()
        for i in range(len(z_list) - 1):
            if z_list[i][1] == True and z_list[i + 1][1] == False:
                ans = min(ans, abs(z_list[i][0] - z_list[i + 1][0]) * 5)

if ans >= 10**18:
    print("SAFE")
else:
    print(ans)


Measured memory_bytes: 239128
#-*-coding:utf-8-*-

def main():
    a, b, c = map(int, input().split())

    for i in range(10 ** 6):
        if (a * i - c) % b == 0:
            print('YES')
            exit()
    print('NO')

if __name__ == '__main__':
    main()

Measured memory_bytes: 2940
#include<stdio.h>
int main(){
  long long n,i,j,k,ans;
  scanf("%lld",&n);
  ans=n;
  for(i=1; i*i<=n; i++){
    if(n%i==0){
      j=n/i;
      k=i+j-2;
      if(k<ans){
        ans=k;
      }
    }
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

// *** at 2018/**/**

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

    private void solveA() {
        Scanner sc = new Scanner(System.in);
        String N = sc.nextLine();
        String word = "aiueo";
        if (-1 < word.indexOf(N)) {
            System.out.println("vowel");
        } else {
            System.out.println("consonant");
        }
    }

    private void solveB() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(N);
    }

    private void solveC() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(N);
    }

    private void solveD() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(N);
    }

    private void solveE() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(N);
    }

    private void solveF() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(N);
    }

}

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

using namespace std;

int main(){
	string a,b,c;
	string result="NO";
	while(cin>>a>>b>>c){
		 result="NO";
		if(a.size() > 0 && b.size() > 0 && c.size() > 0){
		   if(  (*(a.end()-1) == *(b.begin())) && (*(b.end()-1) == *(c.begin())))

			   result="YES";
		}
		cout<<result<<endl;
	}
   return 0;
}

Measured memory_bytes: 256
import math

X = int(input())

for i in range(1001):
    f = round((X + i ** 5) ** 0.2)
    if f ** 5 - i ** 5 == X:
        print(int((X + i ** 5) ** 0.2), i)
        exit()

for i in range(1, 1001):
    f = round(abs(X - i ** 5) ** 0.2)
    if X - i ** 5 > 0:
        if f ** 5 - (-i) ** 5 == X:
            print(f, -i)
            exit()
    else:
        if (-f) ** 5 - (-i) ** 5 == X:
            print(-f, -i)
            exit()


Measured memory_bytes: 9468
#include <stdio.h>

int main()
{
int a[4][3][10]={0};
int b,f,r;
int i,n,v,j,k,l;

scanf("%d",&n);

for(i = 0; i < n; i++)
{
	scanf(" %d %d %d %d",&b,&f,&r,&v);
	a[b-1][f-1][r-1]+=v;
}



for(k = 0; k < 4; k++)
{
	for(j = 0; j < 3; j++)
	{
		for(l = 0;l < 10;l++)
		{
			if(a[k][j][l]==0)
		{
			printf(" 0");
		}
			else
			{
				printf(" %d",a[k][j][l]);
			}
		
		}
		printf("\n");
	}
	
	if(k!=3)
	{
		printf("####################\n");
	}
}

return 0;
}

Measured memory_bytes: 612
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

ll n, x;
ll a[2000];

ll m[2000];

int main(int argc, char **argv) {
	cin >> n >> x;
	REP(i, n) cin >> a[i];
	ll res = 0;
	REP(i, n) {
		m[i] = a[i];
		res += m[i];
	}
	REP(i, n) {
		ll t = i * x;
		REP(j, n) {
			m[j] = min(m[j], a[(j - i + n) % n]);
			t += m[j];
		}
		res = min(res, t);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> t(n);
  for(int i=0;i<n;i++){
    cin>>t.at(i);
  }
  int m;
  cin>>m;
  vector<int> p(m),x(m);
  for(int i=0;i<m;i++){
    cin>>p.at(i)>>x.at(i);
  }
  for(int i=0;i<m;i++){
    long long ans=0;
    for(int j=0;j<n;j++){
      if(p.at(i)-1==j){
        ans+=x.at(i);
      }else{
        ans+=t.at(j);
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

namespace ABC166
{
    class B
    {
        static void Main(string[] args)
        {
            //var N = long.Parse(Console.ReadLine());
            var NK = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var N = NK[0]; var K = NK[1];
            //var abcd = Enumerable.Repeat(0, (int)Q).Select(_ => Console.ReadLine().Split().Select(long.Parse).ToArray()).ToArray();
            //var S = Console.ReadLine();

            var res = new int[N];
            for (int i = 0; i < K; i++)
            {
                var d = long.Parse(Console.ReadLine());
                var A = Console.ReadLine().Split().Select(long.Parse).ToArray();
                for (int j = 0; j < d; j++)
                {
                    res[A[j] - 1]++;
                }
            }

            var ans = res.Count(x => x == 0);
            Console.WriteLine(ans);

        }
    }
}


Measured memory_bytes: 28416
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).rbegin(), (x).rend())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
#define SP << " " <<
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    string N;
    cin>>N;
    if(N[0]=='7' or N[1]=='7' or N[2]=='7') cout<< "Yes" <<"\n";
    else cout<< "No" <<"\n";

}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 3612
#include <iostream>
#include <queue>
#include <vector>

using namespace std;
using ll = long long;

template <typename T> using pq_asc = priority_queue<T, vector<T>, greater<T>>;

int main(int argc, char const *argv[]) {
  int v, e, r, s, t, d;
  cin >> v >> e >> r;

  vector<vector<pair<int, int>>> g(v);
  const int kUnvisited = -1;
  vector<int> distance(v, kUnvisited);
  pq_asc<pair<int, int>> q; // (d, i)

  for (int i = 0; i < e; i++) {
    cin >> s >> t >> d;
    g[s].push_back(make_pair(d, t));
    // g[t].push_back(make_pair(d, s));
  }

  q.push(make_pair(0, r));
  for (int j = q.top().second; !q.empty(); j = q.top().second) {
    const int cost = q.top().first;
    q.pop();
    if (distance[j] != kUnvisited){
      continue;
    }

    distance[j] = cost;
    for (auto p : g[j]) {
      if (distance[p.second] == kUnvisited) {
        q.push(make_pair(cost + p.first, p.second));
      }
    }
  }

  for (int i = 0; i < v; i++) {
    cout << (distance[i] == kUnvisited ? "INF" : to_string(distance[i]))
         << endl;
  }

  return 0;
}



Measured memory_bytes: 14076
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int N, W;
const ll NMAX = 100010;
vector<vector<ll>> dp(110, vector<ll>(100010, 0));
vector<int> w(110, 0);
vector<int> v(110, 0);

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

    REP(i, N) cin>>w[i]>>v[i];

    REP(i, N){
        // morau
        for(int wsum=0; wsum<=W; ++wsum){
            if(wsum >= w[i]){
                chmax(dp[i+1][wsum], dp[i][wsum-w[i]]+v[i]);
            }
            chmax(dp[i+1][wsum], dp[i][wsum]);
        }

    }

    cout << dp[N][W] << endl;

    return 0;
}

Measured memory_bytes: 87296
#include<stdio.h>
int main(void)
{
	int a,b,x,c,d;
	scanf("%d %d",&a,&b);
	x=a+b;
	if(x%2==0){
		c=x/2;
		printf("%d\n",c);
	}
	else{
		c=x/2;
		d=c+1;
		printf("%d\n",d);
	}
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<bitset>
#define rep(i,n) for(int i = 0;i < (n); ++i)
using namespace std;

typedef long long LL;
typedef long double LD;
const int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, k;
    LL a[20];
    cin >> n >> k;
    rep(i, n)cin >> a[i];

    LL ans = __LONG_LONG_MAX__;
    for(int i = 0; i < (1 << n - 1); i++){
        bitset<15> bit(i);
        LL border = a[0];
        int count = 1;
        LL cost = 0;
        for(int j = 1; j < n; j++){
            if(border < a[j]){
                border = a[j];
                count++;
            }else{
                if(bit[j - 1] == 1){
                    border++;
                    cost += border - a[j];
                    count++;
                }
            }
        }
        if(count >= k){
            ans = min(ans, cost);
        }
    }

    cout << ans << endl;
}

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

using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf("%.12lf\n",mid);
// __builtin_popcount(int) count 1's in binary
// get decimal pert of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
int mod = 998244353;

long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}

/*string sentence = "And I feel fine...";
    istringstream iss(sentence);
*/  

double eps = .000000001;

int main ()
{
  prep();
  int n;
  cin >> n;
  int nums[n+1];
  int ppl[n];
  for (int i=0; i<n+1; i++){
      cin >> nums[i];
  }
  for (int i=0; i<n; i++){
      cin >> ppl[i];
  }
  long long monsters = 0;
  for (int i=n-1; i>=0; i--){
      if (nums[i+1] > ppl[i]){
          nums[i+1] -= ppl[i];
          monsters += ppl[i];
          ppl[i] = 0;
      }else{
          ppl[i] -= nums[i+1];
          monsters += nums[i+1];
          nums[i+1] = 0;
      }
      if (nums[i] > ppl[i]){
          nums[i] -= ppl[i];
          monsters += ppl[i];
          ppl[i] = 0;
      }else{
          ppl[i] -= nums[i];
          monsters += nums[i];
          nums[i] = 0;
      }
  }
  cout << monsters;
  return 0; 
 
}


Measured memory_bytes: 1024
#light "off"
open System;;
open System.IO;;

let reader = new StreamReader(new BufferedStream(Console.OpenStandardInput ()))
let writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput ()))

let skipSpaces () = while reader.Peek () <= int ' ' do reader.Read () |> ignore done;;
let read f = skipSpaces (); [|while reader.Peek () > int ' ' do yield char (reader.Read ()) done |] |> System.String |> f;;
let readint () = skipSpaces (); let mutable ans = 0 in while reader.Peek () > int ' ' do ans <- ans * 10 + (reader.Read () - int '0'); done; ans;;
let write (s : string) = writer.Write s;;
let writeln (s : string) = writer.WriteLine s;;

let N = readint ();;
let A = Array.init N (fun _ -> readint ());;

A.[0] <- A.[0] - 1;;
let mutable ans = true;;

for i in 1..N-1 do
  if A.[i-1] > A.[i] then
    ans <- false
  elif A.[i-1] < A.[i] then
    A.[i] <- A.[i] - 1
done;;

(if ans then "Yes" else "No") |> printfn "%s";;

reader.Close();;
writer.Close();;

Measured memory_bytes: 14288
n = int(input())
s = input()
# 26(25)
tmp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

a_L = [val for val in tmp]
ans = ""
for val in s:
    i = a_L.index(val)
   
    if i+n >= 26:
        aa = i+n - 26
        #print("aaaa") 
    else:
        aa = i + n
    #print(aa)
    ans += a_L[aa]
print(ans)
#a,b = map(int,input().split())
#a_L = map(int,input().split())



Measured memory_bytes: 40556
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

template <typename T>
int lis(vector<T> &v, T inf) {
    vector<T> a(v.size(), inf);
    for (int i = 0; i < v.size(); ++i) {
        *lower_bound(a.begin(), a.end(), v[i]) = v[i];
    }
    return lower_bound(a.begin(), a.end(), inf) - a.begin();
}

int main() {
    int n;
    cin >> n;
    vl h(n);
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    int ret = 0;
    int temp = 0;
    for (int i = 1; i < n; ++i) {
        if (h[i] <= h[i - 1]) {
            temp++;
        } else {
            chmax(ret, temp);
            temp = 0;
        }
    }
    chmax(ret, temp);
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
  int A,B,C,X,Y,buff,money;
  char str[100],*p;
  
  fgets(str,sizeof(str),stdin);
  p=strtok(str," \n");
  A=atoi(p);
  p=strtok(NULL," \n");
  B=atoi(p);
  p=strtok(NULL," \n");
  C=atoi(p);
  p=strtok(NULL," \n");
  X=atoi(p);
  p=strtok(NULL," \n");
  Y=atoi(p);
  
  if(X<Y){
    buff=A,A=B,B=buff;
    buff=X,X=Y,Y=buff;
  }
  
  if(2*C<=A+B && 2*C>=A){
    money=2*C*Y;
    money+=A*(X-Y);
  }
  if(2*C<=A+B && 2*C<A){
    money=2*C*X;
  }
  if(2*C>A+B){
    money=A*X+B*Y; 
  }
  
  printf("%d",money);
  
 return 0; 
}

Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<cmath>
#include<map> 
#include<string>
#include<queue>
#include<stack> 
#include<bitset>
#include<list>
#include<set>
#include<utility>
#define IO ios::sync_with_stdio(false)
//#define int long long
using namespace std;
string s;
map<string,int>mp;
int main()
{
	IO;
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		string s;
		cin>>s;
		mp[s]++;
	}
	cout<<"AC x "<<mp["AC"]<<endl;
	cout<<"WA x "<<mp["WA"]<<endl;
	cout<<"TLE x "<<mp["TLE"]<<endl;
	cout<<"RE x "<<mp["RE"]<<endl;
}

Measured memory_bytes: 3640
import math
import bisect
import collections
import itertools
def gcd(a,b):return math.gcd #最大公約数
def lcm(a,b):return (a*b) // math.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def imn(): return map(int, input().split()) #整数map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

def is_prime(n):
    if n == 1: return False
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            return False
    return True

X = iin()

while True:
    if is_prime(X):
        print(X)
        break
    X += 1



Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int k,a,b,c;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>a>>b>>c>>k;
	int ans=0;
	if(k<=a) ans=k;
	else if(k<=b) ans=a;
	else ans=a-(k-b-a);
	cout<<ans; 

	return 0;
}

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

using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int MOD = 1000000007;

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	ll Q, H, S, D, N; cin >> Q >> H >> S >> D >> N;
	H = min(H,2*Q);
	S = min(S,2*H);
	D = min(D,2*S);
	ll co = (N/2)*D+(N&1)*S;
	cout << co;
}

// read!
// ll vs. int!

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

using namespace std;

int solve(int n, vector<int> &s, vector<int> &t){
    vector<pair<int,int>> itv(n);
    for (int i = 0; i < n; i++){
        itv[i].first = t[i];
        itv[i].second = s[i];
    }
    
    sort(itv.begin(),itv.end());
    
    int ans = 0;
    int last = -1010101017;
    
    for (int i = 0; i < n; i++){
        if (last <= itv[i].second){
            ans++;
            last = itv[i].first;
        }
    }
    return ans;
}


int main(void){
    int n;
    cin >> n;
    
    vector<int> s(n), t(n);
    
    for (int i = 0; i < n; i++){
        int x, l;
        cin >> x >> l;
        
        s[i] = x - l;
        t[i] = x + l;
    }
    
    cout << solve(n,s,t) << endl;
    
}


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

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

int main() {
    int n;
    scanf("%d", &n);

    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];

    sort(a, a + n);
    int mini = 1000000000;
    for (int i = 0; i < n; i++) {
        mini = min(mini, gcd(a[i], a[0]));
    }

    cout << mini << endl;
}

Measured memory_bytes: 4028
#include <iostream>
#include <climits>

using namespace std;

typedef long long ll;

int N, M;
const ll INF = -(1LL << 50);
ll cost[1001][1001];
ll node[1001];

bool bellman_ford()
{
  for (int i = 0; i < N; i++)
  {
    for (int j = 1; j <= N; j++)
    {
      for (int k = 1; k <= N; k++)
      {
        if (j == k)
          continue;
        ll cost_a = node[j] + cost[j][k];
        if (cost_a > node[k] && node[j] != INF && cost[j][k] != INF)
        {
          node[k] = cost_a;
          if (i == (N - 1) && k == N)
            return true;
        }
      }
    }
  }
  return false;
}

int main()
{
  for (int i = 0; i < 1001; i++)
  {
    for (int j = 0; j < 1001; j++)
    {
      cost[i][j] = INF;
    }
    node[i] = INF;
  }
  node[1] = 0;
  cin >> N >> M;
  for (int i = 0; i < M; i++)
  {
    int a, b;
    cin >> a >> b;
    cin >> cost[a][b];
  }

  if (bellman_ford())
  {
    cout << "inf" << endl;
  }
  else
  {
    if (node[N] != INF)
    {

      cout << node[N] << endl;
    }
    else
    {
      cout << "inf" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 8064
#include <stdio.h>

int primejudge(int);
int main(){
  int n;

  while(scanf("%d",&n) != EOF){
    int i,j,k,l;
    k = n;
    l = n;
    while(k--){
      if (primejudge(k) == 1) break;
    }
    while(l++){
      if(primejudge(l) == 1) break;
    }
    printf("%d %d\n",k,l);
  }
  return 0;
}
int primejudge(int n){
  int i,re;
  re = 1;
  for(i = 2;i*i <= n;i++){
    if(n % i == 0){
      re = 0;
      break;
    }
  }
  return re;
}
  

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

bool compare_by_x(pair<int, int> a, pair<int, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    } else {
        return a.second < b.second;
    }
}

int main() {
    int N;
    cin >> N;
    int x, y;
    vector<pair<int, int> > red, blue;
    for (int i = 0; i < N; ++i) {
        cin >> x >> y;
        red.push_back(make_pair(x, y));
    }
    for (int i = 0; i < N; ++i) {
        cin >> x >> y;
        blue.push_back(make_pair(x, y));
    }
    sort(blue.begin(), blue.end(), compare_by_x);
    int ans = 0;
    for (int i = 0; i < N; ++i) {
        int res = -1;
        for (int j = 0; j < red.size(); ++j) {
            if (red[j].second < blue[i].second && red[j].first < blue[i].first) {
                if (res == -1) {
                    res = j;
                } else {
                    if (red[res].second < red[j].second) { res = j; }
                }
            }
        }
        if (res != -1) {
            red[res] = red.back();
            red.erase(red.end());
            ++ans;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256