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

#include <atcoder/twosat>
using namespace atcoder;

const string YES = "Yes";
const string NO = "No";

void solve(long long N, long long D, std::vector<long long> X, std::vector<long long> Y){
    // select X = true, select Y = false
    two_sat ts(N);
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            if (abs(X[i] - X[j]) < D) {
                ts.add_clause(i, 0, j, 0);
            }
            if (abs(X[i] - Y[j]) < D) {
                ts.add_clause(i, 0, j, 1);
            }
            if (abs(Y[i] - X[j]) < D) {
                ts.add_clause(i, 1, j, 0);
            }
            if (abs(Y[i] - Y[j]) < D) {
                ts.add_clause(i, 1, j, 1);
            }
        }
    }
    bool result = ts.satisfiable();
    if (!result) {
        cout << NO << endl;
        return;
    }
    cout << YES << endl;
    auto answer = ts.answer();
    for (int i = 0; i < N; i++) {
        if (answer[i]) {
            cout << X[i] << endl;
        } else {
            cout << Y[i] << endl;
        }
    }
}

// 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)
int main(){
    long long N;
    scanf("%lld",&N);
    long long D;
    scanf("%lld",&D);
    std::vector<long long> X(N);
    std::vector<long long> Y(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&X[i]);
        scanf("%lld",&Y[i]);
    }
    solve(N, D, std::move(X), std::move(Y));
    return 0;
}


Measured memory_bytes: 3772
#include <stack>
#include <queue>
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
 
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
#define INF (1<<29)
#define test cout << "test" << endl;
#define NNN_MAX 100010

int NNN,MMM;
int par[NNN_MAX];
int ran[NNN_MAX];

void init(int n){
	rep(i,n){
		par[i]=i;
		ran[i]=0;
	}
}

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(x==y){
		return ;
	}

	if(ran[x]<ran[y]){
		par[x] = y;
	}
	else{
		par[y] = x;
		if(ran[x]== ran[y]){
			ran[x]++;
		}
	}
}

bool same(int x,int y){
	return find(x)==find(y);
}

int main (){
	cin >> NNN;
	cin >>MMM;
	int p[NNN];
	rep(i,NNN){
		cin >> p[i];
		p[i]--;
	}
	init(NNN);
	int tx,ty;
	rep(i,MMM){
		cin >> tx >> ty;
		unite(--tx,--ty);
		}
	int count =0;
	rep(i,NNN){
		if(same(p[i],i)==true)count ++;
	}
	cout << count << endl;

	return 0;
}


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

int main(){
  int a;
  scanf("%d",&a);
  if (a < 3200){
    printf("%s\n", "red");
    return 0;
  }
  char s[11];
  scanf("%s", s);
  printf("%s\n", s);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define f first
#define s second

using namespace std;
typedef long long ll;

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

	ll x,k,d;
	cin >> x >> k >> d;
	x = abs(x);
	ll div = x/d;
	if(div >= k){
		cout << x-k*d;
	}else{
		x %= d;
		k -= div;
		if(k&1){
			cout << abs(x-d) << '\n';
		}else{
			cout << x << '\n';
		}
	}

	return 0;
}

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

int main()
{
	int N;
	cin >> N;
	vector<int> A( N );
	for( int i = 0; i < N; i++ ) {
		cin >> A[i];
	}

	vector<int> B( N );
	vector<int> C( N );
	for( int i = 0; i < N; i++ ) {
		B[i] = A[i] - 1;
		C[i] = A[i] + 1;
	}
	int ans = 0;
	int ma = pow( 3, N );
	for( int mask = 0; mask < ma; mask++ ) {
		int mul = 1;
		for( int i = 0; i < N; i++ ) {
			int p = pow( 3, i + 1 );
			int b = mask % p / (p / 3);
			if( b == 0 ) mul *= A[i];
			else if( b == 1 ) mul *= B[i];
			else mul *= C[i];
		}
		if( mul % 2 == 0 ) ans++;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
T = [int(i) for i in input().split()]
M = int(input())
P = []
X = []
for i in range(M):
    p, x = map(int, input().split())
    P.append(p)
    X.append(x)

all = sum(T)
for i in range(M):
    print(all - T[P[i]-1] + X[i])


Measured memory_bytes: 3060
n = gets.chomp.to_i
arr = gets.chomp.split(' ').map(&:to_i)

def bubble_sort(arr, n)
  swap_times = 0
  flag = true
  i = 0
  while flag && i < n - 1
    flag = false
    j = n - 1
    while j >= i + 1
      if arr[j] < arr[j - 1]
        swap_times += 1
        tmp = arr[j]
        arr[j] = arr[j - 1]
        arr[j - 1] = tmp
        flag = true
      end
      j -= 1
    end
    i += 1
  end
  print "#{arr.join(' ')}\n#{swap_times}\n"
end

bubble_sort(arr, n)



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

int main(){
    int n;
    cin >> n;
    vector<int> x(n),y(n),h(n);
    for(int i = 0; i < n; i++)
    {
        cin >> x[i] >> y[i] >> h[i];
    }
    for(int X = 0; X <= 100; X++)
    {
        for(int Y = 0; Y <= 100; Y++)
        {
            int H;
            for(int i = 0; i < n; i++)
            {
                if (h[i] != 0) {
                      H = h[i]+abs(x[i]-X)+abs(y[i]-Y);
                      break;
                }
            }
            bool flag = true;
            for(int i = 0; i < n; i++)
            {
                int tmp = max(H-abs(x[i]-X)-abs(y[i]-Y), 0);
                if (h[i] != tmp) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                cout << X << " " << Y << " " << H << endl;;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
import math
import itertools
import statistics
#import numpy as np
import collections

a = int(input())
b = int(input())
c = int(input())
x = int(input())

count = 0

for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i + 100*j + 50*k == x:
                count += 1
print(count)

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

int main(){
char a,b,c;
cin >> a >> b >>c;
if (a=='1')
{
cout << 9;
}else{
  cout << 1;
}
if (b=='1')
{
cout << 9;
}else{
  cout << 1;
}
if (c=='1')
{
cout << 9 << endl;;
}else{
  cout << 1 << endl;
}
}

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

int main(){
    int N,X; //N+1回跳ねる、X以下の領域で跳ねる回数を
    cin >> N >> X;
    vector<int> L(N);
    for(int i=0; i<N; i++){
        cin >> L.at(i);
    }
    int D=0;
    int count=1;
    for(int i=0; i<N; i++){
        D = D + L.at(i);
        if(D <= X){
            count ++;
        }else{
            break;
        }
    }
    cout << count;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	
	register long long n,x=1,ans=0;
	cin>>n;
	while(n>0){
		ans+=x;n/=2;x*=2;
	}
	cout<<ans<<endl;	
	return 0;
}

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

using namespace std;
 
#define MD 1000000007
typedef long long int ll;

int main(){
    ll N,X;
    cin>>N>>X;
    vector<ll> v(N+1);
    v[0]=X;
    for(ll i=1;i<N+1;i++){
        cin>>v[i];
    }
    
    sort(v.begin(),v.end());
    
    ll ans=v[1]-v[0];
    for(ll i=1;i<N;i++){
        ans=__gcd(ans,v[i+1]-v[i]);
    }
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
N, M = map(int, input().split())
edges = []
G = [[10**8]*N for _ in range(N)]   # 1-indexed
for _ in range(M):
    A, B, C = map(int, input().split())
    # 無向グラフ
    G[A-1][B-1] = C
    G[B-1][A-1] = C
    edges.append((A-1, B-1, C))

for k in range(N):
    for i in range(N):
        for j in range(N):
            if i == j:
                G[i][j] = 0
            if G[i][j] > G[i][k]+G[j][k]:
                G[i][j] = G[i][k]+G[j][k]

ans = 0
for A, B, C in edges:
    flg = False
    for i in range(N):
        for j in range(N):
            if G[i][A]+C+G[B][j] == G[i][j]:
                flg = True
    if flg is False:
        ans += 1
print(ans)


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

ll dp[2][100005];

int main() {
  int n; ll w;
  cin >> n >> w;
  rep(i, 100005) {dp[0][i] = 1000000005; dp[1][i] = 1000000005;}
  dp[0][0] = 0;
  ll wi; int vi;
  rep(i, n) {
    cin >> wi >> vi;
    rep(j, 100001) {
      if (j <= vi) dp[1][j] = min(dp[0][j], wi);
      else dp[1][j] = min(dp[0][j-vi] + wi, dp[0][j]);
    }
    rep(j, 100001) dp[0][j] = dp[1][j];
  }
  int j = 0;
  while ((dp[1][j] <= w) && (j <= 100002)) j++;
  cout << --j << endl;
}


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

int main()
{
    int n;
    cin >> n;
    map<int, int> mp;
    for(int i = 0; i < n; i++){
        int d;
        cin >> d;
        mp[d]++;
    }
    int m;
    cin >> m;
    for(int i = 0; i < m; i++){
        int t;
        cin >> t;
        if(mp[t] <= 0){
            cout << "NO" << endl;
            return 0;
        }
        mp[t]--;
    }
    cout << "YES" << endl;
}

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

int arr[100003] , N , M , V , P;

bool check(int mid){
	long long all = 1ll * M * (V - 1);
	while(mid < N && arr[mid] == arr[mid + 1]) ++mid;
	if(mid > N - P) return 1;
	int lst = arr[mid] + M; if(lst < arr[N - P + 1]) return 0;
	for(int i = 1 ; i < P ; ++i) all -= M;
	for(int i = 1 ; all > 0 && i <= N - P + 1 ; ++i) if(i != mid) all -= min(M , max(0 , lst - arr[i]));
	return all <= 0;
}

int main(){
	cin >> N >> M >> V >> P; for(int i = 1 ; i <= N ; ++i) cin >> arr[i];
	sort(arr + 1 , arr + N + 1); int L = 1 , R = N + 1;
	while(L < R){int mid = (L + R) >> 1; check(mid) ? R = mid : L = mid + 1;}
	cout << N + 1 - L << endl; return 0;
}

Measured memory_bytes: 640
n = int(input())
csf = [list(map(int, input().split())) for _ in range(n-1)]

for i in range(n):
    ans = 0
    for j in range(i, n-1):
        if csf[j][1] >= ans:
            ans = csf[j][0] + csf[j][1]
        else:
            ans = csf[j][0] + -(-ans //csf[j][2]) * csf[j][2]
    print(ans)

Measured memory_bytes: 43500
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main(void){
  int A, B, H, M;
  cin >> A >> B >> H >> M;
  double deg1, deg2;
  deg1 =  M_PI * ((double)H  + (double)M / 60.0) / 6.0;
  deg2 = M_PI * ((double)M / 30.0);
  double x1, y1;
  x1 = A * sin(deg1); y1 = A * cos(deg1);
  double x2, y2;
  x2 = B * sin(deg2); y2 = B * cos(deg2);
  cout << fixed << setprecision(20)  << sqrt((x1 - x2) * (x1 - x2) + (y1- y2) * (y1 - y2)) << endl;
  return 0;
}


Measured memory_bytes: 3972
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)

    val n = sc.nextInt()
    val c = sc.nextInt()
    val k = sc.nextInt()
    val t = Array(n) { sc.nextInt() }

    var ans = 0
    var waitStart = 0
    var waitPeople = 0

    for (ti in t.sorted()) {
        if (ti - waitStart > k || waitPeople == c) {
            waitPeople = 0
        }
        waitPeople++

        if (waitPeople == 1) {
            waitStart = ti
            ans++
        }
    }
    println(ans)
}


Measured memory_bytes: 54188
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n); std::vector<i64> d(n);
	for(int i = 0; i < n; i++) scanf("%lld", &d[i]);

	i64 ans = 0;
	for(int i = 0; i < n; i++) {
		for(int j = i + 1; j < n; j++) {
			ans += d[i] * d[j];
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    int answer = 0;
    cin >> s;
    if(s.compare("RRR")==0){
        answer = 3;
    }else if(s.compare("RRS")==0 || s.compare("SRR")==0){
        answer = 2;
    }else if(s.compare("SSS")!=0){
        answer = 1;
    }
    cout << answer << endl;
}

Measured memory_bytes: 3620
# coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)
#from heapq import heappop, heappush
#from collections import defaultdict
# import math
# from itertools import product, accumulate, combinations, product
# import bisect# lower_bound etc
#import numpy as np
# from copy import deepcopy
#from collections import deque
#import numba
#import math

def run():
    X, Y = map(int, input().split())
    if (Y - 2 * X) >= 0 and (Y - 2 * X) % 2 == 0 and 4 * X >= Y:
        print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    run()

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

using namespace std;

#define long long long
#define INF 1e18
#define MOD (long) (1e9 + 7)

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

    vector<long> a(n);
    for (auto &x : a) cin >> x;

    long total = 1000;
    long stocks = 0;
    for (long i = 0; i < n-1; i++) {
        for (long j = i+1; j < n; j++) {
            if (a[j] > a[i]) {
                long y = total / a[i];
                stocks += y;
                total -= y * a[i];
                break;
            }
            if (a[j] < a[i]) {
                total += stocks * a[i];
                stocks = 0;
                break;
            }
        }
    }
    total += stocks * a[n-1];
    printf("%lld\n", total);
}


Measured memory_bytes: 3724
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
using namespace std;
int main(){
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int count = 0;

    for(int i = 0; i < a+1; i++){
        for(int j = 0; j < b+1; j++){
            for(int k = 0; k < c+1; k++){
                if(500*i + 100*j + 50*k == x) count++;
            }
        }
    } 
    cout << count << endl;
}

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const int MAX = 200010;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<'\n'


int main(){
    int n,k;
    cin >> n >> k;
    ll ans = 0;
    if(n<k){
        COUT(1);
        return 0;
    }
    int a[n+1];
    int b[n+1];
    ll ans1=0,ans2=0;
    vector<ll> vec1(n+1,0);
    vector<ll> vec2(n+1,0);
    for(int i=0;i<n+1;i++){
        a[i] = i;
        b[i] = n-i;
        ans1 += i;
        ans2 += n-i; 
        vec1[i] = ans1;
        vec2[i] = ans2;
    }
    for(int t=k-1;t<n+1;t++){
        ans += vec2[t]-vec1[t]+1;
        if(ans%MOD)ans%=MOD;    
    }
    COUT(ans);
    return 0;
}


Measured memory_bytes: 7840
#include <bits/stdc++.h>
using namespace std;
const int N = 200000;
const int INF = 1<<30;

int n, ans = INF;
string s;

inline void ck_min( int &a, int b ) { if( a > b ) a = b; }

int main()
{
	cin >> s;
	n = s.length();
	
	for( int i = 1; i <= n; i ++ )
	{
		if( s[i-1] == s[i-2] ) continue;
		
		if( i-1 < n-i+1 ) {
			ck_min( ans, n-i+1 ); continue;
		}
		ck_min( ans, i-1 ); break;
	}
	
	printf( "%d\n", ans );
	
	return 0;
} 

Measured memory_bytes: 512
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    long long C;
    cin >> n >> C;

    vector<long long> X(n + 1, 0);
    vector<long long> V(n + 1, 0);
    for (int i = 0; i < n;++i) {
        cin >> X[i + 1] >> V[i + 1];
    }
    ++n;
    
    vector<long long> A(n * 2 + 1, 0);
    vector<long long> B(n * 2, 0);
    for (int i = 0; i < 2 * n; ++i) {
        A[i + 1] = A[i] + V[i % n];
    }
    for (int i = 0; i < 2 * n; ++i) {
        B[i] = (i >= n ? 1 : 0) * C + X[i % n];
    }

    const long long INF = 1LL << 60;
    long long res = 0;

    for (int i = 0; i <= n; ++i) {
        res = max(res, A[i + 1] - A[0] - (B[i] - B[0]));
        res = max(res, A[n + 1] - A[i] - (B[n] - B[i]));
        // cout << i << " " << res << endl;
    }

    deque<pair<long long,int>> que1;
    deque<pair<long long,int>> que2;

    auto push = [&](deque<pair<long long, int>>& que, long long val, int pos) -> long long {
        while (!que.empty()) {
            int l = que.front().second;
            if (l + n <= pos) {
                que.pop_front();
            } else {
                break;
            }
        }

        while (!que.empty()) {
            if (que.back().first <= val) {
                que.pop_back();
            } else {
                break;
            }
        }

        long long res = 0;
        if (!que.empty()) {
            res = max(res, que.front().first);
        }
        que.emplace_back(val, pos);
        return res;
    };

    for (int i = 0; i <= n; ++i) {
        push(que1, A[n + 1] - A[i] - 2 * (B[n] - B[i]), i);
        push(que2, A[n + 1] - A[i] - (B[n] - B[i]), i);
        // cout << i << " " << A[n + 1] - A[i] << " " << A[n + 1] - A[i] - 2 * (B[n] - B[i]) <<  "  " << A[n + 1] - A[i] - (B[n] - B[i]) << endl;
    }

    for (int i = 1; i < n; ++i) {
        {
            long long ans = push(que1, -INF, i + n);
            ans += A[i + n + 1] - A[n] - (B[i + n] - B[n]);
            res = max(res, ans);
        }
        {
            long long ans = push(que2, -INF, i + n);
            // cout << "   " << ans << endl;
            ans += A[i + n + 1] - A[n] - 2 * (B[i + n] - B[n]);
            res = max(res, ans);
            // cout << i << " " << ans << endl;
        }
    }

    cout << res << '\n';
    return 0;
}

Measured memory_bytes: 8192
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define IP pair<int,int>
#define enld endl
#define MOD  998244353

lint power(lint x, lint n, lint m) {
	//(x^n)%mを返す
	lint res = 1;
	x %= m;
	while (n > 0) {
		if (n % 2 == 1) {
			res = res * x % m;
		}
		x = x * x % m;
		n /= 2;
	}
	return res;
}

lint invmod(lint n, lint m) {
	//nの逆元を返す
	lint ret = 0;
	ret = power(n, m - 2, m);
	return ret;
}

/*lint comb(lint n, lint k, lint m) {
	//nCk%MODを返す
	//O(k)
	lint ans = 1;
	rep(i, k) {
		ans *= n - i;
		ans %= m;
		ans *= invmod(k - i, m);
		ans %= m;
	}
	return ans;
}*/
const lint MAX = 500000;
//const int MOD = 1000000007;

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

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

// 二項係数計算
lint COM(lint n, lint k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {
	COMinit();
	lint N, M, K;
	cin >> N >> M >> K;
	lint ans = 0;
	for (lint i = N - 1 - K; i <= N - 1; i++) {
		ans += COM(N-1, i) * M%MOD * power(M - 1, i, MOD);
		ans %= MOD;
		//cout << '!';
	}
	cout << ans << endl;
}

Measured memory_bytes: 15356
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;
import java.io.*;

public class Main {

	void solve() {
		long N = sc.nextLong();
		long X = sc.nextLong();
		
		long ans = N;
		long a = Math.min(X, N - X);
		long b = Math.max(X, N - X);
		while (true) {
			ans += (b / a * 2 * a);
			long na = b % a;
			long nb = a;
			if (na == 0) {
				ans -= a;
				break;
			}
			a = na;
			b = nb;
		}
		out.println(ans);
	}
	
	static void tr(Object... os) { System.err.println(deepToString(os)); }
	static void tr(int[][] as) { for (int[] a : as) tr(a); }

	void print(int[] a) {
		out.print(a[0]);
		for (int i = 1; i < a.length; i++) out.print(" " + a[i]);
		out.println();
	}

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

	MyScanner sc = null;
	PrintWriter out = null;
	public void run() throws Exception {
		sc = new MyScanner(System.in);
		out = new PrintWriter(System.out);
		for (;sc.hasNext();) {
			solve();
			out.flush();
		}
		out.close();
	}

	class MyScanner {
		String line;
		BufferedReader reader;
		StringTokenizer tokenizer;

		public MyScanner(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}
		public void eat() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					line = reader.readLine();
					if (line == null) {
						tokenizer = null;
						return;
					}
					tokenizer = new StringTokenizer(line);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
		}
		public String next() {
			eat();
			return tokenizer.nextToken();
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		public boolean hasNext() {
			eat();
			return (tokenizer != null && tokenizer.hasMoreElements());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
	}
}

Measured memory_bytes: 8020
const isBelow= (v) => {
    if(v%2==0){
        v%3==0
    }

};


const main =(input)=>{
    const args = input.split('\n')
    const nums = args[1].split(' ')
    var mes ='APPROVED'

    nums.forEach(el=>{

        if(el%2==0){

            if(!((el%3==0)||(el%5==0)))
                mes ='DENIED'
                return 0;
        }
    })
    console.log(mes)


}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }

}


use std::cmp::{max, min};
use std::collections::BinaryHeap;

fn zalgorithm(s: &str) -> Vec<usize> {
    let s_char: Vec<char> = s.chars().collect();
    let mut a = vec![0; s_char.len()];

    a[0] = s_char.len();
    let mut i = 1;
    let mut j = 0;

    while i < s_char.len() {
        while i + j < s_char.len() && s_char[j] == s_char[i + j] {
            j += 1;
        }
        a[i] = j;
        if j == 0 {
            i += 1;
            continue;
        }
        let mut k = 1;
        while i + j < s_char.len() && k + a[k] < j {
            k += 1;
        }
        i += k;
        j -= k;
    }

    return a;
}


fn main() {
    let n: usize = read();
    let s: String = read();

    let mut ans = 0;


    for i in 0..n {
        let a = zalgorithm(&s[i..]);
        let mut maybeMax = 0;
        for (idx, ai) in a.iter().enumerate() {
            if idx >= *ai {
                maybeMax = max(maybeMax, *ai)
            }
        }
        ans = max(ans, maybeMax)
    }

    println!("{}", ans);

}


Measured memory_bytes: 4352
#include <iostream>

using namespace std;

int solve(int n)
{
    int sum[3] = {1, 1, 1};
    if (n < 2)
        return 1;
    for (int i = 1; i < n; i++)
    {
        sum[2] = sum[1] + sum[0];
        sum[0] = sum[1];
        sum[1] = sum[2];
    }
    return sum[2];
}

int main()
{
    int n;
    scanf("%d", &n);
    printf("%d\n", solve(n));
}


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

public class Main {
	
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(in.readLine());
		StringTokenizer st = new StringTokenizer(in.readLine());
		String s = st.nextToken(), t = st.nextToken();
		String r = "";
		for(int i = 0; i < n; i++) {
			r += s.charAt(i);
			r += t.charAt(i);
		}
		System.out.println(r);
	}
	
}





Measured memory_bytes: 23124
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#define MOD 1000000007
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;

signed main(){
    int n;
    cin>>n;
    int cnt=0;
    vector<int> prime;
    vector<int> ans;
    int now=2;
    while(cnt<n){
        bool p=true;
        for(int i=0;i<prime.size();i++)if(now%prime[i]==0)p=false;
        if(p==true)prime.push_back(now);
        if(p==true&&now%5==1){
            ans.push_back(now);
            cnt++;
        }
        now++;
    }
    for(int i=0;i<n-1;i++)cout<<ans[i]<<" ";
    cout<<ans[n-1]<<endl;
    return 0;
}


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

int main()
{
    int n;
    char s;
    bool ans = false;

    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        if(s == 'Y')ans = true;
    }
    
    if(ans)cout << "Four" << endl;
    else cout << "Three" << endl;
}

Measured memory_bytes: 256
//       In the name of         ****                      God                     ****

/*

Copyright (C)          JadedBeast

                                   Morocco

created : 8/3/2019

*/

#include <bits/stdc++.h>
using namespace std;
#define time cout << "\ntime: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
#define W 100001
inline void Boost() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
}
static	int n,w;
long long DP[101][W],knap[101][2];

long long dp(int i,int weight){
	if(weight<0)
		return -6969696969;
	if (weight==0 || i==n)
		return 0;
	if(DP[i][weight]!=-1)
		return DP[i][weight];

	return DP[i][weight]=max(knap[i][1]+dp(i+1,weight-knap[i][0]),dp(i+1,weight));


}



int main(void){
	//Boost();
	cin >>n >> w;
	
	for(int i=0 ;i<n ;i++)
		for(int j=0 ; j<2 ;j++)
			cin >>knap[i][j];

	memset(DP,-1,sizeof(DP));

	

	cout <<dp(0,w)<<endl;

   return 0;
}


Measured memory_bytes: 79232
///**Bismillahir Rahmanir Rahim.**
 
#include <bits/stdc++.h>
#define clr(a, v)             memset(a, v, sizeof a)
#define all(v)                v.begin(), v.end()
#define ast(v)                sort(v.begin(),v.end())
#define dst(v)                sort(v.begin(),v.end(), greater <int> ())
#define fast ios_base::       sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ass(cur, v)           cur.assign(v.begin(), v.end())
#define rep(i, l, r)          for (int i = l; i <= r; i++)
#define rep2(i, l, r)         for (int i = l; i >= r; i--)
#define sfs(s)                scanf("%s", s)
#define sfl(n)                scanf("%lld", &n)
#define sffl(n, m)            scanf("%lld %lld",&n,&m)
#define sfffl(n, m, o)        scanf("%d %d %d",&n,&m, &o)
#define pf(n)                 printf("%d", n)
#define debug                 printf(" debug\n")
#define yes                   printf("YES\n")
#define no                    printf("NO\n")
#define sp                    printf(" ")
#define nl                    printf("\n")
#define prln(n)               printf("%d\n", n)
#define pfl(n)                printf("%lld\n", n)
#define I(n)                  cin >> n
#define II(n, m)              cin >> n >> m
#define III(a, b, c)          cin >> a >> b >> c
#define P(n)                  cout << n
#define PP(n, m)              cout << n << " " << m << "\n"
#define PPP(a, b, c)          cout << a << " " << b << " " << c << "\n"
#define R(n)                  return n
#define mid(b, e)             (b+e)/2
#define left(node)            node*2
#define right(node)           node*2+1
#define pii                   pair<int,int>
#define mp                    make_pair
#define pb                    push_back
#define S                     second
#define F                     first
#define PI                    3.1415926
 
struct greaters{
    bool operator()(const long& a, const long& b) const{
        return a > b;
    }
};
 
//-----------------------------------***********************----------------------------------------------//
 
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;
const int N = 2e5+5;
const int mod = 1e9+7;
 
void reset(){
 
}
 
int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    int tc = 1, cas = 0;
    while(tc--){
        reset();
        ll n; I(n);
      	ll ans = (n*n*n);
     	P(ans);
    }
    return 0;
 
}
 
//-----------------------------------***********************----------------------------------------------//


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

using namespace std;

uint64_t N;
vector<uint64_t> As;
vector<uint64_t> Ss;

uint64_t count() {
  for (uint64_t i = 1; i<N; ++i) {
    uint64_t j = N - i - 1;
    if (2 * Ss[j] < As[j + 1])
      return i;
  }

  return N;
}

int main() {
  cin >> N;

  As.reserve(N);
  Ss.reserve(N);

  for (uint64_t i = 0; i < N; ++i) {
    uint64_t n;
    cin >> n;
    As.push_back(n);
  }
  sort(As.begin(), As.end());

  uint64_t s = 0;
  for (auto a : As) {
    s += a;
    Ss.push_back(s);
  }

  cout << count() << endl;

  return 0;
}


Measured memory_bytes: 1920
#include <stdio.h>
int main(){
  long long int a,at,b,bt,c,d,i;
  while(scanf("%lld %lld",&a,&b)!=EOF){
    at=a;
    bt=b;
    while(1){
      if(at==bt){
	c=at;
	break;
      }
      else if(at>bt)at-=bt;
      else if(at<bt)bt-=at;
    }
    if(a>b)at=a;
    else at=b;
    for(i=at;i<=a*b;i++){
      if(a*b==c*i){
      //if(i%a==0&&i%b==0){
	printf("%lld %lld\n",c,i);
	break;
      }
    }
  }
  return 0;
}

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

using namespace std;

bool check(string s1, string s2)
{
    for(int i = 0; i < s1.size(); i++) {
        if(s1[i] != s2[i]) {
            return false;
        }
    }
    
    return true;
}

int main()
{
    string s1, s2;
    cin >> s1 >> s2;

    if(check(s1, s2)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3596
K=int(input())
S=input()
N=len(S)

F = 2*10**6+5
mod = 10**9+7
fact = [1]*F
inv = [1]*F
for i in range(2,F):
    fact[i]=(fact[i-1]*i)%mod
inv[-1]=pow(fact[-1],mod-2,mod)
for i in range(F-2,1,-1):
    inv[i] = (inv[i+1]*(i+1))%mod

def comb(n,k):
    ans=(fact[n]*inv[n-k])%mod
    return (ans*inv[k])%mod

ans=0

select=pow(25,K,mod)
inv25=inv[25]*fact[24]

for i in range(K+1):
    ans+=select*comb(N-1+K-i,N-1)
    ans%=mod
    select*=inv25*26
    select%=mod

print(ans)



Measured memory_bytes: 122468
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;
using ll = long long int;

int main(){
    int a, b, h;
    cin >> a >> b >> h;
    cout << (a+b)*h/2 << endl;
 }


Measured memory_bytes: 256
using System;
class Program {
    static void Main (string[] args) {
        int i, j, k, n = 0;
        int N = int.Parse (Console.ReadLine ());
        string[] input = Console.ReadLine ().Split (' ');
        int[] L = new int[N];
        for (i = 0; i < N; i++)
            L[i] = int.Parse (input[i]);
        for (i = 0; i < N; i++)
            for (j = 0; j < N; j++)
                for (k = 0; k < N; k++)
                    if (i < j && j < k)
                        if (L[i] > 0 && L[j] > 0 && L[k] > 0)
                            if (i != j && j != k && k != i)
                                if (L[i] != L[j] && L[j] != L[k] && L[k] != L[i])
                                    if (L[i] + L[j] > L[k] && L[j] + L[k] > L[i] && L[k] + L[i] > L[j])
                                        n++;
        Console.WriteLine (n);
    }
}

Measured memory_bytes: 27440
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000007;
constexpr int INF = 2000000000;
using namespace std;

int main() {
	int h, w;
	while (cin >> h >> w&&h != 0 && w != 0) {
		char maze[101][101];
		bool data[101][101] = { false };
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cin >> maze[i][j];
			}
		}
		int posh = 0, posw = 0;
		bool isloop = false;
		while (maze[posh][posw] != '.') {
			if (data[posh][posw]) {
				isloop = true;
				break;
			}
			data[posh][posw] = true;
			if (maze[posh][posw] == '>')posw++;
			else if (maze[posh][posw] == '<')posw--;
			else if (maze[posh][posw] == '^')posh--;
			else posh++;
		}
		if (isloop) {
			cout << "LOOP" << endl;
		}
		else {
			cout << posw << " " << posh << endl;
		}
	}
}

Measured memory_bytes: 3056
#include <stdio.h>

int main(void)
{
	int i,a[32768],b[32768],c;
	for(i=1;i<=32768;i++){
		scanf("%d %d",&a[i],&b[i]);
		if(a[i]==0&&b[i]==0){
			break;
		}
	}
	for(i=1;i<=32768;i++){
		if(a[i]==0&&b[i]==0){
			break;
		}
		else{
			if(a[i]>b[i]){
				c=a[i];
				a[i]=b[i];
				b[i]=c;
				printf("%d %d\n",a[i],b[i]);
			}
			else{
				printf("%d %d\n",a[i],b[i]);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 624
//#include "IntMod.h"
//typedef IntMod<1000000007> MInt;

//#include "Union_Find.h"

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>

using namespace std;
#define REP(i,a,n) for(int i = a; i < n; ++i)
#define REPM(i,n,a) for(int i = n - 1; i >= a; --i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFF3FFFFFFF
#define INFD 1.0e+308
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;

#if 1
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;
#endif

int R, C, N;
int X1, Y1, X2, Y2;
vector<PP> vec;
int p(int x, int y) {
	if (y == 0) return x;
	if (x == C) return C + y;
	if (y == R) return C + R + (C - x);
	return C + R + C + (R - y);
}

int main() {
	cin >> C >> R >> N;
	int k = 0;
	REP(i, 0, N) {
		cin >> X1 >> Y1 >> X2 >> Y2;
		if ((X1 == 0 || X1 == C || Y1 == 0 || Y1 == R) && (X2 == 0 || X2 == C || Y2 == 0 || Y2 == R)) {
			vec.push_back(make_pair(p(X1, Y1), k));
			vec.push_back(make_pair(p(X2, Y2), k));
			++k;
		}
	}
	sort(vec.begin(), vec.end());

	stack<int> s;
	REP(i, 0, vec.size()) {
		if (!s.empty() && s.top() == vec[i].second) {
			s.pop();
		} else {
			s.push(vec[i].second);
		}
	}
	cout << (s.empty() ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 6384
import java.util.Scanner;

public class Main{
	class item{
		String str;
		private int cost;
		private String[] mate;
		private int n;
		
		item(){
			str = "";
			cost = 0;
			n = 0;
		}
		
		item(String str, int cost){
			this.str = str;
			this.cost = cost;
			n = 0;
		}
		
		void setMat(String[] mate, int n){
			this.mate = mate;
			this.n = n;
		}
		
		int getCost(item[] list, int m){
			if(n == 0){
				return cost;
			}
			int v = 0;
			for(int i = 0; i < n; i++){
				for(int j = 0; j < m; j++){
					if(mate[i].equals(list[j].str)){
						v += list[j].getCost(list, m);
						break;
					}
				}
			}
			
			if(v < cost){
				return v;
			} else {
				return cost;
			}
		}
	}
	
	Main(){
		Scanner sc = new Scanner(System.in);
		String str;
		
		while(true){
			int n = sc.nextInt();
			if(n == 0){
				break;
			}
			item[] ilist = new item[n+1];
			for(int i = 0; i < n; i++){
				str = sc.next();
				int cost = sc.nextInt();
				ilist[i] = new item(str, cost);
			}
			
			int m = sc.nextInt();
			for(int i = 0; i < m; i++){
				str = sc.next();
				int l = sc.nextInt();
				String[] st = new String[l+1];
				for(int j = 0; j < l; j++){
					st[j] = sc.next();
				}
				for(int j = 0; j < n; j++){
					if(str.equals(ilist[j].str)){
						ilist[j].setMat(st, l);
						break;
					}
				}
			}
			str = sc.next();
			
			for(int i = 0; i < n; i++){
				if(str.equals(ilist[i].str)){
					System.out.println(Integer.toString(ilist[i].getCost(ilist, n)));
					break;
				}
			}
		}
	}
	
	public static void main(String[] args){
		new Main();
	}
}

Measured memory_bytes: 12000
import sys
import heapq, functools, collections
import math, random
from collections import Counter, defaultdict

# available on Google, not available on Codeforces
# import numpy as np
# import scipy


def solve(k):  # fix inputs here
    console("----- solving ------")

    dp = [0 for _ in range(k+1)]

    for i in range(1,k+1):
        for j in range(i,k+1,i):
            dp[j] += 1
    
    return sum(dp[:-1])


def console(*args):  # the judge will not read these print statement
    print('\033[36m', *args, '\033[0m', file=sys.stderr)
    return

# fast read all
# sys.stdin.readlines()

for case_num in [1]:
    # read line as a string
    # strr = input()

    # read line as an integer
    k = int(input())
    
    # read one line and parse each word as a string
    # lst = input().split()

    # read one line and parse each word as an integer
    # lst = list(map(int,input().split()))

    # read matrix and parse as integers (after reading read nrows)
    # lst = list(map(int,input().split()))
    # nrows = lst[0]  # index containing information, please change
    # grid = []
    # for _ in range(nrows):
    #     grid.append(list(map(int,input().split())))

    res = solve(k)  # please change
    
    # Google - case number required
    # print("Case #{}: {}".format(case_num+1, res))

    # Codeforces - no case number required
    print(res)


Measured memory_bytes: 152056
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define ull unsigned long long
#define pii pair<int,int>
#define pb(x) push_back(x)
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define drep(i,a,b) for(int i=(a); i>=(b);i--)
 
const int maxn = 1e6 + 5;
const int maxm = 5000 + 5;
const int MOD = 1e9 + 7;

 double a[110];


int main()
{
   //ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
   //#ifndef ONLINE_JUDGE 
   //freopen("input.txt", "r", stdin);
   //#endif // ONLINE_JUDGE  
   int n; 
   cin >> n;
   rep(i,1,n) {
      cin >> a[i];
   }
   sort(a + 1, a + n + 1);
   double sum = (a[1] + a[2]) / 2.0;
   rep(i,3,n) sum = (sum + a[i]) / 2.0;
   printf("%.5lf",sum);
   return 0;
}

Measured memory_bytes: 256
// luogu-judger-enable-o2
#include <iostream>
using namespace std;
long long 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;
int main()
{
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a>>b;
		c+=b-a+1;
	}
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
	string s;
	int i;
	int cnt;
	int x;
	cin>>s;
	cnt=1;
	for(i=0;i<s.size()-1;i++){
		if(s[i]!=s[i+1])	cnt++;
	}
	cout<<cnt-1<<endl;
	return 0;
}
	
	
	
	
	

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 20000;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k,a;
    cin >> n >> k;
    vector<ll> p,m;
    p.push_back(0);
    m.push_back(0);
    rep(i,n){
        cin >> a;
        if (a == 0) k--;
        else if (a > 0) p.push_back(a);
        else m.push_back(abs(a));
    }
    p.resize(n+1,INF);
    m.resize(n+1,INF);
    SORT(p);
    SORT(m);
    ll ans = INF;
    rep(i,k+1){
        chmin(ans,min(2*p[i]+m[k-i],p[i]+2*m[k-i]));
    }
    PRINT(ans);
}



Measured memory_bytes: 2412
N,M=map(int,input().split())
invs = []
for _ in range(M):
    L,R = map(int,input().split())
    invs.append((L,R-1)) #R<N
invs.sort(key=lambda inv: inv[0])
x = N
ans = 0
#walls = []
for (a,b) in invs:
    if a > x:
        ans += 1
        #walls.append(x)
        x = b
    else:
        x = min(x,b)
#walls.append(x)
ans += 1
#print(walls)
print(ans)

Measured memory_bytes: 18248
import java.util.*;

public class Main {
	  public static void main(String args[]){
      	Scanner scan = new Scanner(System.in);
            
        String a = scan.next();
        String b = scan.next();
        String c = scan.next();
        String cnt ;
        
        String a_bottom = a.substring( a.length()-1 , a.length() );
        String b_top    = b.substring( 0 , 1 );
        String b_bottom = b.substring( b.length()-1 , b.length() );
        String c_top    = c.substring( 0 , 1 );
        
        //ここで気を付けなければならないが、
        //String a ="a", String b = "a"であっても
        // a==bの判定はfalseになる
        //
        //この問題を解決するため、char型にわざわざ変換を行っている
        
        if( a_bottom.charAt(0) == b_top.charAt(0) &&
            b_bottom.charAt(0) == c_top.charAt(0)){
          cnt = "YES";
        }
        else cnt = "NO";
            
        System.out.println(cnt);
	  }
}

Measured memory_bytes: 21840
n, k, q = gets.chomp.split.map(&:to_i)
ans = [0]*n
 
q.times do
    ans[gets.to_i - 1] += 1
end
 
n.times do |i|
    sum = k - (q - ans[i])
    if sum > 0
        puts 'Yes'
    else
        puts 'No'
    end
end

Measured memory_bytes: 3196
#include<iostream>
#include<cmath>
#include<stack>
#include<vector>
#include<cstring>
#include<algorithm>
#include<set>
#include<queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long ll;
const ll inf =1e17;
#define scn(a) scanf("%d",&a)
#define scd(a) scanf("%lf",&a)
#define scl(a) scanf("%lld",&a)
#define ptf(a) printf("%d\n",&a)
#define mes(a,b) memset(a,b,sizeof(a))
#define fon(s,n) for(int i=s;i<=n;i++)
#define range(i,a,b) for(int i=a;i<=b;++i)
#define rerange(i,a,b) for(int i=a;i>=b;--i)
//#define N 100010
const int S=20;
ll gcd(ll a,ll b) { return b>0 ? gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll q_pow(ll a,ll b,ll mod)
{
	ll ans=1,res=a;
	while(b){
		if(b&1) ans=ans*res%mod;
		res=res*res%mod;
		b>>=1;
	}
	return ans%mod;
}
 bool cmp(const pair<string,int> &p1, const pair<string,int> &p2) {
    return p1.second > p2.second;
}

int main()
{
    string s1;
    cin>>s1;
    if(s1=="ABC") printf("ARC");
    else printf("ABC");
}

Measured memory_bytes: 3644
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())



int n;
int x[100001];
int y[100001];

vector<int> xs[100001], ys[100001];
unordered_set<int> visited[100001];


int dfs(int y, int x, unordered_set<int> &vy, unordered_set<int> &vx) {
	if (!visited[y].insert(x).second) return 0;

	int ret = 1;
	if (vy.insert(y).second) {
		for (int nx : ys[y]) {
			ret += dfs(y, nx, vy, vx);
		}
	}
	if (vx.insert(x).second) {
		for (int ny : xs[x]) {
			ret += dfs(ny, x, vy, vx);
		}
	}

	return ret;
}


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


	cin >> n;
	rep(i, n)cin >> x[i] >> y[i];

	rep(i,n) {
		xs[x[i]].push_back(y[i]);
		ys[y[i]].push_back(x[i]);
	}

	long long ans = 0;
	rep(i,n) {
		unordered_set<int> vx, vy;
		int m = dfs(y[i], x[i], vy, vx);
		ans += (long long)vy.size() * vx.size() - m;
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 31640
#include <stdio.h>

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



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

int main(){
    ll a,b;
    cin >> a >> b;
    if(a<b) swap(a,b);
    rep(i,a){
        cout << b;
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256