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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

constexpr int64 P = 1000000007;

struct FiniteField {
 private:
  int64 x;
  static inline int64 Normalize(int64 x) {
    if (0 <= x && x < P) return x; x %= P; if (x < 0) x += P; return x;
  }
 public:
  FiniteField(int64 x) : x(Normalize(x)) {}
  FiniteField() : x(0) {}
  int64 Value() const { return x; }
  inline FiniteField operator+(FiniteField o) const {
    FiniteField r(*this); r += o; return r;
  }
  inline FiniteField operator-(FiniteField o) const {
    FiniteField r(*this); r -= o; return r;
  }
  inline FiniteField operator* (FiniteField o) const {
    FiniteField r(*this); r *= o; return r;
  }
  inline FiniteField operator/ (FiniteField o) const {
    FiniteField r(*this); r /= o; return r;
  }
  inline void operator+= (FiniteField o) { x = (x + o.x) % P; }
  inline void operator-= (FiniteField o) { x = (x + P - o.x) % P; }
  inline void operator*= (FiniteField o) { x = (x * o.x) % P; }
  void operator/=(FiniteField o) {
    int64 p = P - 2; while (p) { if (p % 2) { *this *= o; } o *= o; p /= 2; }
  }
};

ostream& operator<<(ostream& s, const FiniteField& v) { s << v.Value(); return s; }

tuple<vector<FiniteField>, vector<FiniteField>> MakeFactorialTables(int n) {
  vector<FiniteField> factorials(n + 1);
  vector<FiniteField> inverse_factorials(n + 1);
  factorials[0] = 1;
  for (int i = 1; i <= n; i++) {
    factorials[i] = factorials[i - 1] * i;
  }
  inverse_factorials[n] = FiniteField(1) / factorials[n];
  for (int i = n; i >= 1; i--) {
    inverse_factorials[i - 1] = inverse_factorials[i] * i;
  }
  return make_tuple(factorials, inverse_factorials);
}

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

  int h, w, a, b;
  cin >> h >> w >> a >> b;

  vector<FiniteField> fs, i_fs;
  tie(fs, i_fs) = MakeFactorialTables(h + w);

  auto c_fn = [&](int a, int b) -> FiniteField {
    return fs[a] * i_fs[b] * i_fs[a - b];
  };

  FiniteField ans = 0;
  for (int k = 0; k <= h - a - 1; k++) {
    ans += c_fn(b - 1 + k, k) * c_fn(w - b - 1 + h - 1 - k, h - 1 - k);
  }
  cout << ans << endl;
}

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

using namespace std;
const long long mod = 1000000007;
const long long max_size = 1000000;

vector<long long> fac(max_size+1), ifac(max_size+1);

long long pow_mod(long long x, long long n){
    long long ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % mod;
        x = x*x % mod;
        n = n >> 1;
    }
    return ans;
}

long long comb(long long a, long long b){
    if(a == 0 && b == 0) return 1;
    if(a < b || a < 0) return 0;
    long long tmp = ifac[a-b] * ifac[b] % mod;
    return tmp * fac[a] % mod;
}
int main(){
    int n,m;
    cin >> n >> m;
    fac[0] = 1;
    ifac[0] = 1;
    for(long long i = 0; i < max_size; i++){
        fac[i+1] = fac[i]*(i+1) % mod;
        ifac[i+1] = ifac[i]*pow_mod(i+1,mod-2) % mod;
    }
    long long ans = 1;
    long long c = m;
    while(c != 1){
        for(long long i = 2; i <= c; i++){
            if(c%i) continue;
            long long b = 0;
            while(c % i == 0){
                c /= i;
                b++;
            }
            ans = ans * comb(b+n-1,b) % mod;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 16000
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[] num = {1, 4, 8, 16, 32, 64, 128, 256, 512,  9, 27, 81, 243, 729,  16, 64, 256, 1024, 25, 125, 625,  36, 216,  49, 343,  64, 512,  81, 729,  100, 1000, 121,  144,  169,  196,  225,  256,  289,  324,  361,  400, 441, 484,  529,  576,  625,  676,  729,  784,  841, 900,  961};
        Arrays.sort(num);
        int X = sc.nextInt();
        int max = -1;
        for(int i = num.length; i > 0; i--){
            int n = num[i - 1];
            if(n <= X){
                max = Math.max(max, n);
                break;
            }
        }
        System.out.println(max);
    }
}


Measured memory_bytes: 21204
#! ruby -Ks

#配列の生成
height = []

10.times{
    #標準入力を整数に変換して配列に格納
    height.push(STDIN.gets.to_i)
}

#配列の並び替え
height.sort!

puts height[-1]
puts height[-2]
puts height[-3]

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

vector<int> tree[100005];
vector<long long int> cost[100005];
vector<int> ans;

void dfs(int v, int p = -1){
  rep(i, tree[v].size()){
    int u = tree[v][i];
    if(u == p) continue;
    if(cost[v][i] == 0) ans[u] = ans[v];
    else ans[u] = ans[v] + 1;
    dfs(u, v);
  }
}
    
int main(){
  long n;
  cin >> n;
  long a, b;
  long long int c;
  
  rep(i, n-1){
    cin >> a >> b >> c;
    a--;
    b--;
    c %= 2;
    tree[a].push_back(b);
    tree[b].push_back(a);
    cost[a].push_back(c);
    cost[b].push_back(c);
  }
  ans.resize(n);
  dfs(0, -1);
  rep(i, n){
    cout << ans[i] % 2 << endl;
  }
}

Measured memory_bytes: 15232
// Garden

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>
#include <numeric>

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    cout << a*b - a - b + 1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long MOD = 998244353;
const long long INF = 1LL << 60;
const int inf = pow(10, 9) + 7;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, int B) {return (A + (B - 1)) / B;}
long long divCeil(int A, long long B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

int main()
{
  int N;
  cin >> N;
  vector<int>V(N), C(N);
  for (int i = 0; i < N; i++) cin >> V.at(i);
  for (int i = 0; i < N; i++) cin >> C.at(i);
  
  int X = 0, Y = 0;
  for (int i = 0; i < N; i++)
  {
    if (V.at(i) > C.at(i)) 
    {
      X += V.at(i);
      Y += C.at(i);
    }
  }
  
  int ans = X - Y;
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
////////////////////////////////////////

int main() {
	int N, K; cin >> N >> K;
	cout << N - K + 1 << endl;
	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    P a, b, c, d;
    cin >> a.first >> a.second;
    cin >> b.first >> b.second;

    c.first = b.first - (b.second - a.second);
    c.second = b.second + (b.first - a.first);

    d.first = a.first - (b.second - a.second);
    d.second = (b.first - a.first) + a.second;

    cout << c.first << ' ' << c.second << ' ' << d.first << ' ' << d.second << endl; 

    return 0;
}

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

import sys


class Die:
    def __init__(self, pips):
        self.pips = pips

    def move_die(self, direction):
        if direction == 'N':
            tmp = self.pips[0]
            self.pips[0] = self.pips[1]
            self.pips[1] = self.pips[5]
            self.pips[5] = self.pips[4]
            self.pips[4] = tmp
            del tmp
        elif direction == 'S':
            tmp = self.pips[0]
            self.pips[0] = self.pips[4]
            self.pips[4] = self.pips[5]
            self.pips[5] = self.pips[1]
            self.pips[1] = tmp
            del tmp
        elif direction == 'E':
            tmp = self.pips[0]
            self.pips[0] = self.pips[3]
            self.pips[3] = self.pips[5]
            self.pips[5] = self.pips[2]
            self.pips[2] = tmp
            del tmp
        elif direction == 'W':
            tmp = self.pips[0]
            self.pips[0] = self.pips[2]
            self.pips[2] = self.pips[5]
            self.pips[5] = self.pips[3]
            self.pips[3] = tmp
            del tmp

    def spin_die_clockwise(self):
        tmp = self.pips[1]
        self.pips[1] = self.pips[2]
        self.pips[2] = self.pips[4]
        self.pips[4] = self.pips[3]
        self.pips[3] = tmp
        del tmp


def init_die():
    pips = [int(pip) for pip in sys.stdin.readline().strip('\n').split()]
    die = Die(pips)

    return die


def roll_die(die):
    directions = list(sys.stdin.readline().strip('\n'))

    for direction in directions:
        die.move_die(direction)

    return die


def question_rightside(die):
    q = int(sys.stdin.readline().strip('\n'))
    rightsides = []

    for question in range(q):
        q_pips = [int(pip) for pip in sys.stdin.readline().strip('\n').split()]

        if q_pips[0] == die.pips[1]:
            die.move_die('N')
        elif q_pips[0] == die.pips[2]:
            die.move_die('W')
        elif q_pips[0] == die.pips[3]:
            die.move_die('E')
        elif q_pips[0] == die.pips[4]:
            die.move_die('S')
        elif q_pips[0] == die.pips[5]:
            die.move_die('N')
            die.move_die('N')

        while die.pips[1] != q_pips[1]:
            die.spin_die_clockwise()

        rightsides.append(die.pips[2])

    return rightsides


def main():
    die = init_die()
    rightsides = question_rightside(die)
    for rightside in rightsides:
        print(rightside)


if __name__ == '__main__':
    main()

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

using namespace std;

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

vector<vector<ll>> G(310, vector<ll>(310, INF)), G2(310, vector<ll>(310, INF));

int main() {
    ll n, m, i, j, k, l;
    cin >> n >> m >> l;
    for(i = 0; i < m; i++) {
        ll x, y, w;
        cin >> x >> y >> w;
        G[x][y] = w;
        G[y][x] = w;
    }
    for(i = 0; i <= n; i++) {
        G[i][i] = 0;
    }

    for(k = 0; k <= n; ++k) {
        for(i = 0; i <= n; ++i) {
            for(j = 0; j <= n; ++j) {
                if(G[i][k] != INF && G[k][j] != INF) {
                    G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
                }
            }
        }
    }

    for(i = 0; i <= n; i++) {
        for(j = 0; j <= n; j++) {
            if(G[i][j] <= l) G2[i][j] = 1;
        }
        G[i][i] = 0;
    }

    for(k = 0; k <= n; ++k) {
        for(i = 0; i <= n; ++i) {
            for(j = 0; j <= n; ++j) {
                if(G2[i][k] != INF && G2[k][j] != INF) {
                    G2[i][j] = min(G2[i][j], G2[i][k] + G2[k][j]);
                }
            }
        }
    }
    ll Q;
    cin >> Q;
    for(i = 0; i < Q; i++) {
        ll s, t;
        cin >> s >> t;
        cout << (G2[s][t] == INF ? -1 : G2[s][t]-1) << endl;
    }
    return 0;
}

Measured memory_bytes: 2048
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

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

    int max = 0;
    for (int i = 0; i <= k && i <= n; i++) {
        for (int j = 0; j <= i; j++) {
            vector<int> d(0);
            int sum = 0;
            for (int kk = 0; kk < j; kk++) {
                sum += v[kk];
                d.push_back(v[kk]);
            }
            for (int kk = n - i + j; kk < n; kk++) {
                sum += v[kk];
                d.push_back(v[kk]);
            }

            sort(d.begin(), d.end());

            for (int kk = 0; kk < k - i && kk < d.size() && d[kk] < 0; kk++) {
                sum -= d[kk];
            }

            if (max < sum) {
                max = sum;
            }
        }
    }

    cout << max << endl;
}


Measured memory_bytes: 256
N = int(input())
ans = ""
al = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
while(True):
  if N <= 26:
    ans = al[N-1] + ans
    break
  tmp = N%26    
  ans = al[tmp-1] + ans
  N = N//26
  if tmp == 0:
    N -= 1
print(ans)

Measured memory_bytes: 9104
// AOJ 408 Cave for Cats		
// 2019.9.29

#include <stdio.h>

#define gc() getchar_unlocked()

int in() {  // 整数の入力
	int n = 0, c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

int stack[1005]; int top;
char f[105];

int main()
{
	int i, c, L;

	L = in();
	for (i = 1; i <= L; i++) {
		c = in();
		if (c > 0) {
			if (f[c]) break;
			f[c] = 1, stack[top++] = c;
		} else {
			c = -c;
			if (f[c] == 0) break;
			if (stack[--top] != c) break;
			f[c] = 0;
		}
	}
	if (i > L) puts("OK");
	else printf("%d\n", i);
	return 0;
}


Measured memory_bytes: 2100
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>

using namespace std;

int main()
{
	int N, M;
	cin >> N >> M;
	
	int A[N];
	double sum = 0;
	for(int n = 0; n < N; n++){
		cin >> A[n];
		sum += A[n];
	}
	
	sort(A, A + N, greater<int>());
	for(int m = 0; m < M; m++){
		if(A[m] < sum /(4 * M)){
			cout << "No" << endl;
			return 0;
		} 
	}
	
	cout << "Yes" << endl;
	return 0;

}

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

int main () {
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;
  
  if( x >= r && y >= r && W-x >= r && H-y >= r ) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 3124
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const int MOD = 998244353;
const ll INF = 1000000000000000000;


int main()
{
	string S, T;
	cin >> S >> T;
	int ans = mod;
	for (int i = 0; i <= S.size() - T.size(); i++) {
		int cnt = 0;
		for (int j = 0; j < T.size(); j++) {
			if (S[i + j] != T[j])  cnt++;
		}
		ans = min(ans, cnt);
	}
	cout << ans << endl;
}

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

using namespace std;
#define lint long long
#define P pair<lint, int>


int main() {
    int N, T, A;
    cin >> N >> T >> A;
    int H[N];
    
    for(int i = 0; i < N ; ++i){
        cin >> H[i];
    }
    int ans = 0;
    float dif = 100000;
    for(int i = 0; i < N; ++i){
        if(abs(T - (float)H[i] * 0.006 - A) < dif){
            ans = i + 1;
            dif = abs(T - (float)H[i] * 0.006 - A);
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
N=int(input())
soinsu=[]
ans = 1

if N==1:
    print(1)
    exit()

for i in range(2,N+1):
    num_tmp = i
    for j in range(2,i+1):
        while num_tmp%j==0 and num_tmp!=1:
            num_tmp /= j
            soinsu.append(j)

for i in range(2,N+1):
    cnt_tmp = soinsu.count(i)
    if cnt_tmp>0:
        ans *= cnt_tmp+1

print(ans%(10**9+7))

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(){
    int N,cnt = 0;
    string S;
    cin >> N >> S;
    for(int i = 0; i < N; i++)
        S[i] = toupper(S[i]);
    for(int i = 0; i < N; i++) {
        if(S[i] == 'B') {
            if((S[i-1] == 'A') && (S[i+1] == 'C'))
                cnt++;
        }
    }
        cout << cnt;
        return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc089/tasks/abc089_d
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w, d, t, q;
    cin >> h >> w >> d;
    vector<pii> v(h * w * 2);
    vector<vector<int>> disp(h, vector<int>(w));
    REP(i, h) REP(j, w) {
        cin >> t;
        v[t] = {i, j};
        disp[i][j] = t;
    }
    vector<ll> memo(h * w + 1, 0);
    REP(i, d) {
        int start = i;
        int goal = h * w;
        ll sum = 0;
        while (start < goal) {
            pii posNow = v[start];
            pii posNext = v[start + d];
            int diff = abs(posNow.first - posNext.first) +
                       abs(posNow.second - posNext.second);
            sum += diff;
            start += d;
            if (start > h * w)
                break;
            memo[start] = sum;
        }
    }
    cin >> q;
    vector<pii> s(q);
    REP(i, q) cin >> s[i].first >> s[i].second;
    REP(i, q) cout << memo[s[i].second] - memo[s[i].first] << "\n";

    return 0;
}


Measured memory_bytes: 4352
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using P = pair<int,int>;
typedef long long ll;
string S;

const int mod=2019; 
ll num[mod];
ll numnew[mod];
void solve(){
    ll ans = 0;
    rep(i,mod) num[i]=0;
    rep(i,S.length()){
        // cout << S[i] << endl;
        int x;
        x = S[i] - '0';
        // cout << x << endl;
        rep(j,mod) numnew[j]=0;
        rep(j,mod){
            int newx;
            newx = (j * 10 + x ) % mod;
            numnew[newx] += num[j];
        }
        numnew[x] = numnew[x] + 1; 
        rep(j,mod){
            num[j] = numnew[j];
            //if (num[j] !=0){
            //    cout << i << "," << x << "," << j << "," << num[j] << endl; 
            //}
        }
        ans += num[0];
    }
    cout << ans << endl;
}


int main() {
    int i,j; 
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> S; 
    //cout << S << endl;
    solve();
}



Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


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

    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    set<ll> s;
    for(int i = 0; i < n; i++){
        s.insert(a[i]);
    }
    if(s.size()==n){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }


    return 0;

}


Measured memory_bytes: 11136
import java.util.*;
public class Main {
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int N=sc.nextInt();
        int[] A=new int[N];
        for(int i=0;i<N;i++){
            A[i]=sc.nextInt()-1;
        }
        int frag=0;
        for(int i=0;i<N;i++){
            if(A[i]!=i){

                if(frag>=2||A[A[i]]!=i){
                    System.out.println("NO");
                    return;

                }else{
                    frag++;
                }
            }
        }
        System.out.println("YES");







    }
    static int gcd (int a, int b) {
        int temp;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return b;
    }
}


Measured memory_bytes: 21844
n, x, y = map(int, input().split())

ans = [0 for _ in range(n - 1)]
for i in range(1, n):
    for j in range(i + 1, n + 1):
        d = min(j - i, abs(x - i) + 1 + abs(y - j))
        ans[d - 1] += 1
print('\n'.join(map(str, ans)))

Measured memory_bytes: 43740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{

	ios::sync_with_stdio(false);cin.tie(0);
	int n;
	scanf("%d",&n);
	cout<<fixed<<setprecision(10);
	vector<double> dp(n+1);
	dp[0]=1;
	for(int coins=1;coins<=n;coins++){
		double p_head;
		scanf("%lf",&p_head);
		for(int i=coins;i>=0;i--){
			dp[i]=(i==0 ? 0:dp[i-1]*p_head)+dp[i]*(1-p_head);
		}
	}
	double ans=0;
	for(int heads=0;heads<=n;heads++){
		int tails=n-heads;
		if(heads>tails){
			ans+=dp[heads];
		}
	}
	cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define ALL(vec) vec.begin(), vec.end()
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define repc(bit, k, n) for (ll bit = (1 << k) - 1; bit < (1 << n); bit = next_combination(bit))
#define repi(itr, vec) for (auto itr = vec.begin(); itr != vec.end(); ++itr)
using namespace std;

ll solve(ll n, ll x)
{
  if (x == 0)
    return 0;
  return n - n % x + solve(x, n % x);
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n, x;
  cin >> n >> x;
  cout << 3 * (x * (n / x - 1) + solve(x, n % x)) << endl;

  return 0;
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int ans = 0;
        ans = (n * a) <= b ? n * a : b;
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep( i, n ) for (long long i = 0; i < ( long long )(n); i++)

using namespace std;
typedef long long ll;
typedef pair< ll , string > P;

int main(){
	ll n, k;
	ll ans = 0;
	cin >> n >> k;
	
	vector < ll > h ( n ); 
	rep( i , n ){
		cin >> h[ i ];
	}
	sort(h.begin() ,h.end() );
	reverse( h.begin() ,h.end() );
	
	for(ll i = k ; i < n ; i++){
		ans += h[ i ];
	}
	cout << ans;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <array>
#include <bitset>
#include <chrono>
#include <cmath>
#include <functional>
#include <iostream>
#include <list>
#include <numeric>
#include <random>
#include <set>
#include <unordered_set>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

#define pv(val) cerr << #val << " = " << (val) << endl
#define pvn(name, val) cerr << name << " = " << (val) << endl
#define pl cerr << '@' << __LINE__ << endl

template <class T>
ostream& operator<<(ostream& os, vector<T> const& vec) {
  if (vec.empty()) {
    os << "{}";
  } else {
    os << '{';
    for (size_t i = 0; i < vec.size() - 1; i++) os << vec[i] << ", ";
    os << vec.back() << '}';
  }
  return os;
}

template <class T, size_t S>
ostream& operator<<(ostream& os, array<T, S> const& arr) {
  if (arr.empty()) {
    os << "{}";
  } else {
    os << '{';
    for (size_t i = 0; i < arr.size() - 1; i++) os << arr[i] << ", ";
    os << arr.back() << '}';
  }
  return os;
}

template <class T, class U>
ostream& operator<<(ostream& os, pair<T, U> const& p) {
  os << '(' << p.first << ", " << p.second << ')';
  return os;
}

template <class T, class U>
pair<T, U> operator+(pair<T, U> const& lhs, pair<T, U> const& rhs) {
  return {lhs.first + rhs.first, lhs.second + rhs.second};
}

template <class T, class U>
pair<T, U> operator-(pair<T, U> const& lhs, pair<T, U> const& rhs) {
  return {lhs.first - rhs.first, lhs.second - rhs.second};
}


template <class F, class T, class U>
U hoge(F f, T const& val, U l, U r) {
  while (l < r) {
    auto m = l + (r - l) / 2;
    auto fm = f(m);
    if (fm < val) {
      l = m + 1;
    } else {
      r = m;
    }
  }
  return l;
}

int ketaWa(int a) {
  int ans = 0;
  while (a > 0) {
    ans += a % 10;
    a /= 10;
  }

  return ans;
}

int main(void) {
  int N;
  cin >> N;
  int ans = numeric_limits<int>::max();
  for(int A = 1; A < N; A++){
    ans = min(ans, ketaWa(A) + ketaWa(N - A));
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 888
def d_cake_123_binary_search(X, Y, Z, K, A, B, C):
    # editionalの解法4 O(K^2log(max(P))
    # 参考: https://atcoder.jp/contests/abc123/submissions/4871511
    import bisect
    ab = sorted([e1 + e2 for e2 in B for e1 in A])  # A, Bの要素は全部調べる

    # rejected 以上の値は、美味しさの合計がそれ以上である個数がK個未満である
    accepted, rejected = -1, 10**11
    while abs(accepted - rejected) > 1:
        mid = (accepted + rejected) // 2
        count = sum([len(ab) - bisect.bisect_left(ab, mid - e) for e in C])
        if count >= K:
            accepted = mid
        else:
            rejected = mid

    ans = []
    for e in C:
        idx = bisect.bisect_left(ab, accepted - e)
        for i in range(idx, len(ab)):
            ans.append(e + ab[i])
    ans.sort(reverse=True)
    return '\n'.join(map(str, ans[:K]))

X, Y, Z, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
print(d_cake_123_binary_search(X, Y, Z, K, A, B, C))

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

int main() {
	int b, r, g, c, s, t;
	while (cin >> b >> r >> g >> c >> s >> t, b | r | g | c | s | t) {
		cout << 100 + b * 5 * 13 + r * 3 * 13 + b * 15 + r * 15 + g * 4 + c*-1 - 3 * (t - b * 5 - r * 3 - g - c - s) << endl;
	}
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<int, int>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

template <typename T>
struct SegTree {
    typedef function<T(T, T)> F;
    int n;
    F f;
    T ti;
    vector<T> dat;
    SegTree(){}
    SegTree(F f, T ti): f(f), ti(ti){}

    void init(int n_) {
        n = 1;
        while(n < n_) n <<= 1;
        dat.assign(n<<1, ti);
    }

    void build(const vector<T> &v) {
        int n_ = v.size();
        init(n_);
        for(int i = 0; i < n_; ++i) dat[n+i] = v[i];
        for(int i = n-1; i; --i) dat[i] = f(dat[(i<<1)|0], dat[(i<<1)|1]);
    }

    void set_val(int k, T x) {
        dat[k += n] = x;
        while(k >>= 1) dat[k] = f(dat[(k<<1)|0], dat[(k<<1)|1]);
    }

    T query(int a, int b) {
        if(a >= b) return ti;
        T vl = ti, vr = ti;
        for(int l = a+n, r = b+n; l < r; l >>= 1, r >>= 1) {
            if(l&1) vl = f(vl, dat[l++]);
            if(r&1) vr = f(dat[--r], vr);
        }
        return f(vl, vr);
    }

    template <typename C>
    int find(int st, C &check, T &acc, int k, int l, int r) {
        if(l+1 == r) {
            acc = f(acc, dat[k]);
            return check(acc) ? k-n : -1;
        }
        int m = (l+r)>>1;
        if(m <= st) return find(st, check, acc, (k<<1)|1, m, r);
        if(st <= 1 && !check(f(acc, dat[k]))) {
            acc = f(acc, dat[k]);
            return -1;
        }
        int vl = find(st, check, acc, (k<<1)|0, l, m);
        if(~vl) return vl;
        return find(st, check, acc, (k<<1)|1, m, r);
    }

    template <typename C>
    int find(int st, C &check) {
        T acc = ti;
        return find(st, check, acc, 1, 0, n);
    }
};

const ll INF = (1LL<<31) - 1;

int main() {
    int n, q; cin >> n >> q;
    auto f = [](ll a, ll b) { return min(a, b); };

    SegTree<ll> seg(f, INF);
    seg.build(vector<ll>(n, INF));
    for(int i = 0; i < q; ++i) {
        int c, x, y; cin >> c >> x >> y;
        if(c) {
            cout << seg.query(x, y+1) << endl;
        }else {
            seg.set_val(x, y);
        }
    }
}


Measured memory_bytes: 5748
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
typedef pair<int,int>P;
 
int dp[200001];
 
signed main(){
	r(i,100009)dp[i]=1e15;
	int n,k;
	cin>>n;//>>k;
	int a[n];
	r(i,n)cin>>a[i];
	dp[0]=0;
	r(i,n){
		r(j,2){
			dp[i+j+1]=min(dp[i+j+1],dp[i]+abs(a[i]-a[i+j+1]));
		}
	}
	cout<<dp[n-1]<<endl;
}

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

int main()
{
	string s;
	int a = 0, b = 0;

	cin >> s;

	for (unsigned int i = 0; i < s.size(); i++) {
		if (i % 2 == 0) {
			if (s[i] == '0')
				a++;
			else
				b++;
		}
		else {
			if (s[i] == '0')
				b++;
			else
				a++;
		}
	}

	cout << min(a, b) << endl;
	
	return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  long M;
  cin >> M;
  cout << 24 + 24 - M << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
const ll BIG=1e15;

int main(){
  string S;
  cin>>S;
  int ans=1;
  if(S=="SUN") ans=7;
  if(S=="MON") ans=6;
  if(S=="TUE") ans=5;
  if(S=="WED") ans=4;
  if(S=="THU") ans=3;
  if(S=="FRI") ans=2;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))
'''
N, M = mi()
P = li()
tmp = []


for i in range(M):
    x, y = mi()
    x, y = x-1, y-1
    if x > y:
        x, y = y, x
    tmp.append([x, y])

xy = []

sorted(tmp, key=lambda x : x[0])
print(tmp)
now = tmp[0][0]
flag = [0] * N
tmp2 = [now]
num = 1
flag[tmp[0][0]] = num
for x, y in tmp:
    if x != now:
        xy.append(tmp2)
        tmp2 = [x]
        now = x
        num += 1
        flag[x] = num
    tmp2.append(y)
    flag[y] = num

if tmp2:
    xy.append(tmp2)

print(flag)
print(xy)

for i in range(N):
'''
class UnionFind:
    def __init__(self, n):
        self.d = [-1]*n
    
    def find(self, x):
        if self.d[x] < 0:
            return x
        else:
            self.d[x] = self.find(self.d[x])
            return self.find(self.d[x])
    
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return False
        if self.d[x] > self.d[y]:
            x, y = y, x
        self.d[x] += self.d[y]
        self.d[y] = x
        return True
    
    def same(self, x, y):
        if self.find(x)==self.find(y):
            return True
        return False
    
    def size(self, x):
        return (-1) * self.d[self.find(x)]

N, M = mi()
P = li()
G = UnionFind(N)
ans = 0

for i in range(M):
    x, y = mi()
    G.unite(x-1, y-1)
    
for i in range(N):
    if G.same(P[i]-1, i):
        ans += 1

print(ans)
    





Measured memory_bytes: 20400
// 26
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fors(_, x, n, s) for (int _ = x; _ < n; _ += s)
#define forn(_, x, n) fors(_, x, n, 1)
#define rep(_, n) forn(_, 0, n)
#define forrs(_, x, n, s) for (int _ = x; _ > n; _ -= s)
#define forrn(_, x, n) forrs(_, x, n, 1)
#define rrep(_, n) forrn(_, n - 1, -1)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#define lli __int128_t
#define li long long int
#define ld double
#ifdef LOCAL
#define debug(e) cerr << "\033[48;5;196m\033[38;5;15m" << e << "\033[0m";
#else
#define debug(e)
#endif
// 4
template <class A, class B>
ostream &operator<<(ostream &os, pair<A, B> &p) {
  return os << "(" << p.fi << " " << p.se << ")";
}
// 8
template <class T>
ostream &operator<<(ostream &os, vector<T> &v) {
  rep(i, (int)v.size()) os << setw(7) << left << v[i];
  return os << endl;
}
// 6
template <class A, class B>
ostream &operator<<(ostream &os, map<A, B> &m) {
  for (auto &kv : m) os << "{" << kv.fi << " " << kv.se << "}";
  return os;
}
// 3
void _main(int tc) {
  int n;
  cin >> n;
  vector<ld> p(n);
  rep(i, n) cin >> p[i];
  /************* Recursive *************
  vector<vector<ld>> mem(n, vector<ld>(n + 1, -1));
  function<ld(int, int)> f = [&](int i, int c) -> ld {
    if (n - i + c <= i - c) return 0;
    if (i == n) return 1;
    if (mem[i][c] != -1) return mem[i][c];
    return mem[i][c] = p[i] * f(i + 1, c) + (1 - p[i]) * f(i + 1, c - 1);
  };
  cout << setprecision(10) << f(0, n) << endl;
  *********** End Recursive ***********/
  vector<vector<ld>> mem(n + 1, vector<ld>(n + 1));

  int mid = n & 1 ? (n + 1) / 2 : n / 2 + 1;
  forn(i, mid, n + 1) mem[n][i] = 1;

  rrep(i, n) {
    forn(c, 1, n + 1) {
      mem[i][c] = p[i] * mem[i + 1][c] + (1 - p[i]) * mem[i + 1][c - 1];
    }
  }

  debug(mem);
  
  cout << setprecision(10) << mem[0][n] << endl;
}
// 7
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0), exit(0);
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

Measured memory_bytes: 70784
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int [][]c = new int [3][3];
		int []a = new int [3];
		int []b = new int [3];
		int []sum = new int [3];
		
		for(int i = 0; i < 3 ;i++) {
			for(int j = 0; j < 3;j++) {
				c[i][j] = sc.nextInt();
			}
		}
		
		boolean jdg = true;
		
		b[0] = c[0][0];
		b[1] = c[0][1];
		b[2] = c[0][2];
		a[0] = 0;
		a[1] = c[1][0] - c[0][0];
		a[2] = c[2][0] - c[0][0];
		
		for(int i = 0; i < 3 ;i++) {
			for(int j = 0; j < 3 ;j++) {
				if(c[i][j] != a[i] + b[j]) {
					jdg =false;
					break;
				}
			}
		}
		
				
		if(jdg) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}

	}

}


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

using namespace std;

int main() {
    int k, a, b;
    cin >> k >> a >> b;
    if (b / k - (a - 1) / k > 0) {
        cout << "OK" << endl;
    } else {
        cout << "NG" << endl;
    }
    return 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n;
    cin >> n;
    vector<ll> arr(n, 0);
    for(auto& val: arr)
        cin >> val;
    if (arr[0] != 0) {
        cout << -1 << endl;
    } else {
        for(int i = 1; i < n; i++) {
            if (arr[i] - arr[i-1] > 1) {
                cout << -1 << endl;
                return 0;
            }
        }
        ll ans = 0;
        for(int i = n-1; i >= 0; i--) {
            if (i != n-1 && arr[i]+1 == arr[i+1])
                continue;
            ans += arr[i];
        }
        cout << ans << endl;
    }
    return 0;
}




Measured memory_bytes: 1792
#include <iostream>
#include <math.h>
using namespace std;

int abs(int a){
 int b;
 if(a<0) b = -a;
 else b = a;
 return b;
}

int main(){
 long long n,d,count=0,i;
 cin >> n;
 cin >> d;
 for(i=0;i<n;i++){
  int x,y;
  cin >> x;
  cin >> y;
  x=abs(x);
  y=abs(y);
  if(x<=d && y<=d){
   if((double)x <= sqrt((d-y)*(d+y))) count++;
  }
 }
 cout << count << endl;
 return 0;
}

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

int main() {

	int k, n; cin >> k >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	vector<int> d(n - 1, 0);
	d[0] = k - a[n - 1] + a[0];
	for (int i = 1; i < n - 1; i++) {
		d[i] = a[i + 1] - a[i];
	}
	sort(d.rbegin(), d.rend());
	cout << k - d[0] << endl;
	return 0;
}

Measured memory_bytes: 4844
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define PER(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define all(S) (S).begin(), (S).end()
#define pf push_front
#define pb push_back
#define mk make_pair
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<int, int> ii;
const int MAX = 1e5+5;
int a[MAX], pd[MAX];
int N, K;

int main(int argc, char ** argv) {
	scanf("%d%d", &N, &K);
	REP(i, 1, N) scanf("%d", &a[i]);
	REP(i, 2, N) {
		pd[i] = (1 << 30);
		rep(j, max(1, i-K), i)
			pd[i] = min(pd[i], pd[j] + abs(a[i]-a[j]));
	}
	printf("%d\n", pd[N]);
	return 0;
}


Measured memory_bytes: 1024
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    private static final PrintStream so = System.out;
    private static final Scanner     sc = new Scanner(System.in);

    public static void main(String[] args) {
        int K = ni();
        int A = ni();
        int B = ni();
        
        if (A >= K) {
            println(K+1);
            return;
        }
        
        long bis = A;
        long k = K - (A-1);
        if (k % 2 == 1) {
            k--;
            bis++;
        }
        
        long d = - A + B;
        if (d <= 2) {
            println(bis + k);
        } else {
            println(bis + d*(k/2));
        }
    }

    static int    ni() { return sc.nextInt(); }
    static long   nl() { return sc.nextLong(); }
    static String n()  { return sc.next(); }
    
    static char[] nChars() { return n().toCharArray(); }
    static int[] nInts(int n) { 
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = ni();
        return a;
    }
    static void println(Object o)  { so.println(o);}
    static void println(long l)    { so.println(l);}
    static void println(char c)    { so.println(c);}
    static void println(double d)  { so.println(d);}
    static void println(boolean b) { so.println(b);}
    
    static void print(Object o)  { so.print(o);}
    static void print(long l)    { so.print(l);}
    static void print(char c)    { so.print(c);}
    static void print(double d)  { so.print(d);}
    static void print(boolean b) { so.print(b);}
}


Measured memory_bytes: 23636
#include<stdio.h>

int main()
{
	int dice[]={1,2,3},aa,x,t;
	char a[10];
	while(1){
		dice[0]=1;
		dice[1]=2;
		dice[2]=3;
	scanf("%d",&aa);
	if(aa==0) break;
	t=1;
	for(int i=0;i<aa;i++)
	{
		scanf("%s",&a);
		if(a[0]=='N'){
			x=dice[0];
			dice[0]=dice[1];
			dice[1]=7-x;
		}
		if(a[0]=='S'){
			x=dice[0];
			dice[0]=7-dice[1];
			dice[1]=x;
		}
		if(a[0]=='E'){
			x=dice[0];
			dice[0]=7-dice[2];
			dice[2]=x;
		}
		if(a[0]=='W'){
			x=dice[0];
			dice[0]=dice[2];
			dice[2]=7-x;
		}
		if(a[0]=='L'){
			x=dice[1];
			dice[1]=7-dice[2];
			dice[2]=x;
		}
		if(a[0]=='R'){
			x=dice[1];
			dice[1]=dice[2];
			dice[2]=7-x;
		}
		t=t+dice[0];
	}
	printf("%d\n",t);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define R register
#define mp make_pair
#define ll long long
#define pii pair<int, int>
using namespace std;
const int N = 20;

int n, g[N][N];

template <class T>
inline void read(T &x) {
    x = 0;
    char ch = getchar(), w = 0;
    while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    x = w ? -x : x;
    return;
}

int main() {
    int x, y, w;
    read(n);
    for (R int i = 1; i <= n; ++i) {
        read(x);
        while (x--) read(y), read(w), g[i][y] = w + 1;
    }
    int ans = 0;
    for (R int i = 0; i < 1 << n; ++i) {
        int num = 0, flag = 1;
        for (R int j = 0; j < n; ++j) {
            if (~i & (1 << j)) continue;
            ++num;
            for (R int k = 0; k < n; ++k) {
                if (!g[j + 1][k + 1]) continue;
                if (g[j + 1][k + 1] == 1 && i & (1 << k)) flag = 0;
                if (g[j + 1][k + 1] == 2 && ~i & (1 << k)) flag = 0;
            }
        }
        if (flag) ans = max(ans, num);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int V,E;
int par[10000],rnk[10000];

int find(int x){
    if(par[x]==x)return x;
    else return par[x]=find(par[x]);
}
void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(rnk[x]<rnk[y])par[x]=y;
    else{
        par[y]=x;
        if(rnk[x]==rnk[y])rnk[x]++;
    }
}
bool same(int x,int y){
    return find(x)==find(y);
}
class edge{
    public:
    int s,t,cost;
    bool operator <(const edge&n)const{
        return cost<n.cost;
    }
    
};

int main(void){
  cin>>V>>E;
  edge x[E];
  for(int i=0;i<V;i++){
      par[i]=i;
      rnk[i]=0;
  }
  int ans=0;
  for(int i=0;i<E;i++){
      cin>>x[i].s>>x[i].t>>x[i].cost;
  }
  sort(x,x+E);
  for(int i=0;i<E;i++){
      if(!same(x[i].s,x[i].t)){
          unite(x[i].s,x[i].t);
          ans+=x[i].cost;
      }
  }
  cout<<ans<<endl;
    
}

Measured memory_bytes: 4328
int main(){
  char S[20];
  char N[3];
  while(scanf("%s",S)==0);
  S[20]='\0';
  N[0]=S[0];
  N[1]=S[1];
  N[2]=S[2];
  N[3]='\0';
  
  printf("%s\n",N);
  
  return 0;
}

Measured memory_bytes: 1656
import qualified Data.IntMap as M
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
 
main = B.getContents >>= print . solve . tail . map readB . B.words

readB = fst . fromJust . B.readInt
 
solve = calc . count
 
count as = M.fromListWith (+) $ zip as (repeat 1)
 
calc = M.foldrWithKey op 0
 
op k v s
  | k <= v = s + v - k
  | otherwise = s + v


Measured memory_bytes: 15356
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,k,s; cin>>n>>k>>s;
	vi vec;
	if(s==int(1e9))
	{
		for(int i=0;i<k;i++) vec.pb(s);
		for(int i=k;i<n;i++) vec.pb(s-1);
	}
	else
	{
		for(int i=0;i<k;i++) vec.pb(s);
		for(int i=k;i<n;i++) vec.pb(int(1e9));
	}
	for(int i=0;i<n;i++)
	{
		cout<<vec[i];
		if(i+1<n) cout<<' ';
	}
	cout<<'\n';
}


Measured memory_bytes: 1912
while 1:
 H, W = map(int, input().split())
 if H == 0 and W == 0:
  break
 print("#"*W)
 line = '#' + ('.' * (W - 2)) + '#'
 for i in range(0, H - 2):
  print(line)
 print("#"*W)
 print()

Measured memory_bytes: 7624
K,X=map(int,input().split())
Ma=X+K-1
mi=X-K+1
if Ma>1000000:
  M=1000000
else:
  M=Ma
if mi<-1000000:
  m=-1000000
else:
  m=mi
ls=[str(i) for i in range(m,M+1)]
print(' '.join(ls))

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int ans = INF<int>;
    string s;
    cin >> s;
    for (int i = 0; i < s.length()-2; ++i) {
        ans = min(ans, abs((s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0')-753));
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
typedef long long int ll;
using namespace std;
#define P 1000000007
#define rep(i,n) for(i=0;i<n;++i)
#define repp(i,a,n) for(i=a;i<n;++i)
#define repr(i,a,n) for(i=a;i>=n;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

ll binpowmod(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

ll modInverse(ll n, ll p)
{
    return binpowmod(n, p-2, p);
}

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t,m,n,i,f=0,j,ans=0,k,x,r;
    string s;
    ll a,b,c,d;
    cin >> a >>b >> c >> d ;
    while(a>0&&c>0)
    {
        c-=b;
        if(c<=0)
        {
            cout << "Yes" ;
            return 0;
        }
        a-=d;
        if(a<=0)
        {
            cout << "No" ;
            return 0;
        }
    }
    
    return 0;
}

Measured memory_bytes: 3648
from copy import copy
N = int(input())
X = list(map(int,input().split()))
sortX = copy(X)
sortX.sort(reverse = True)
median1 = sortX[N // 2 - 1]
median2 = sortX[N // 2]
for i in X:
  if i >= median1: print(median2)
  else: print(median1)  

Measured memory_bytes: 93128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        siz.assign(sz_, 1LL);  // assign: 再代入
        par.resize(sz_);  // resize: 再確保
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main() {
    int n,m;
    cin >> n >> m;
    int cnt=0;
    vector<pii> pe(m);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        pe[i]=mp(a,b);
    }
    rep(i,m){
        UnionFind tree(n);
        rep(j,m){
            if(i==j)continue;
            tree.merge(pe[j].F,pe[j].S);
        }
        if(tree.size(0)!=n)cnt++;
    }
    cout << cnt;
    


}

/*



 */



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

using namespace std;

int main(int argc, const char * argv[]) {
    string str;
    cin >> str;
    int len = int(str.size());
    int half = len / 2;
    
    int ans = 0;
    
    for (int i = half-1; i > 0; i--) {
        bool is_even_str = true;
        for (int n = 0; n < i; n++) {
            if (str[n] != str[n+i]) is_even_str = false;
        }
        if (is_even_str) {
            ans = i * 2;
            break;
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int K; cin >> K;
  queue<long long> lunlun;
  for(int i = 1; i < 10; i++) lunlun.push(i);
  for(int i = 0; i < K - 1; i++) {
    long long x = lunlun.front();
    lunlun.pop();
    if(x % 10 != 0) lunlun.push(10 * x + x % 10 - 1);
    lunlun.push(10 * x + x % 10);
    if(x % 10 != 9) lunlun.push(10 * x + x % 10 + 1);
  }
  cout << lunlun.front() << endl;
}

Measured memory_bytes: 1792