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

using namespace std;

template<typename S, typename T>
ostream& operator<<(ostream& out, const pair<S, T> p) {
    out << "(" << p.first << "," << p.second << ")";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
    for (auto a: v)
        out << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const set<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const multiset<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename S, typename T>
ostream& operator<<(ostream& out, const map<S, T>& M) {
    for (auto m: M)
        cout << "(" << m.first << "->" << m.second << ") ";
    return out;
}

template<typename S, typename T>
pair<S, T> operator+(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

template<typename S, typename T>
pair<S, T> operator-(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first - b.first, a.second - b.second);
}

int solve(vector<int>& A, long long m) {
    int n = A.size();
    map<int, int> M;
    vector<int> B;
    int s = 0;
    while (M.count(s) == 0) {
        M[s] = M.size();
        B.push_back(s);
        s = A[s];
    }
    int period = B.size() - M[s];
    /*
    cout << "A: " << A << endl;
    cout << "B: " << B << endl;
    cout << "M: " << M << endl;
    cout << "m: " << m << endl;
    cout << "period: " << period << endl;
    cout << "M[" << s << "]: " << M[s] << endl;
    */
    if (m < M[s]) {
        return B[m];
    } else {
        int t = M[s] + (m - M[s]) % period;
        return B[t];
    }
    return -1;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    long long m;
    vector<int> A;
    cin >> n >> m;
    A.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> A[i];
        A[i]--;
    }
    cout << solve(A, m) + 1 << endl;
    return 0;
}


Measured memory_bytes: 13820
#include <iostream>

using namespace std;

int main(int argc, const char *argv[]) {
  int N;
  cin >> N;
  
  if(N == 2){
    int A, B;
    cin >> A >> B;
    cout << A + B << endl;
    return 0;
  }

  cout << "Hello World" << endl;
  return 0;
}


Measured memory_bytes: 256
def projecter(x, y, xp, yp)
  return (xp * x + yp * y) / (x ** 2 + y ** 2)
end
def main(input = STDIN)
  x1, y1, x2, y2 = input.gets.split(" ").map(&:to_r)
  q = input.gets.to_i
  x, y = (x2 - x1), (y2 - y1)
  q.times do
    xp, yp = input.gets.split(" ").map(&:to_r)
    a = projecter(x, y, xp - x1, yp - y1)
    puts "#{((x1 + a * x) * 2 - xp).to_f} #{((y1 + a * y) * 2 - yp).to_f}"
  end
end
main

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

struct Query {
    ll t, f;
    char c;
};
Query Q[200005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    ll q;
    cin >> q;
    REP(i, q) {
        cin >> Q[i].t;
        if (Q[i].t == 2) {
            cin >> Q[i].f >> Q[i].c;
        }
    }

    string pre = "", suf = "";
    ll rev = 0;
    REP(i, q) {
        auto qe = Q[q - 1 - i];
        if (qe.t == 1) {
            rev++;
            continue;
        }

        if (qe.f == 1) {
            if (rev % 2 == 0)
                pre.push_back(qe.c);
            else
                suf.push_back(qe.c);
        }
        else {
            if (rev % 2 == 1)
                pre.push_back(qe.c);
            else
                suf.push_back(qe.c);
        }
    }

    REP(i, pre.length()) {
        cout << pre[i];
    }

    if (rev % 2 == 1)
        reverse(S.begin(), S.end());
    cout << S;

    REP(i, suf.length()) {
        cout << suf[suf.size() - 1 - i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 5712
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a:A) cin >> a;}


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

int X, Y, Z; cin >> X >> Y >> Z;

swap(X, Y);
swap(X, Z);

cout << X << ' ' << Y << ' ' << Z << "\n";

return 0;
}
// コンテスト前はtemplate振り返り。
// 書いて考える．場合分け．情報整理．
// 問題文から考える。自分ができることから考える。
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索。逆から考える。
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。数表出力プログラム作る
// 実行エラー：vector添え字超え．0割り．



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

using namespace std;

int main()
{   
    // 練習でやった問題, 逆から探索する
    string s;
    cin >> s;
    reverse(s.begin(), s.end()); // 反転
    // string tmp_list[4] = ["dream", "dreamer", "erase", "eraser"];
    string tmp_list[4] = {"maerd", "remaerd", "esare", "resare"};

    string ans = "YES";
    int count = 0; 
    for(int i=0; i<s.length(); ++i){
        // cout << count << endl;
        if(s.substr(count, 5)==tmp_list[0] || s.substr(count, 5)==tmp_list[2]){
            count += 5;
        }
        else if(s.substr(count, 7)==tmp_list[1]){
            count += 7;
        }
        else if(s.substr(count, 6)==tmp_list[3]){
            count += 6;
        }
        else{
            if(count != s.length()){
                ans = "NO";
            }
            break;
        }
    }

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

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long ans=0,a,cnt=0;
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        if(a)cnt+=a;
        else{
            ans+=cnt/2;
            cnt=0;
        }
    }
    cout<<ans+(cnt/2)<<endl;
    return 0;
}


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

int main() {
	int A, B, C, X;
	cin >> A >> B >> C >> X;
	int count = 0;
	for (int a = 0; a <= A; a++) {
		for (int b = 0; b <= B; b++) {
			for (int c = 0; c <= C; c++) {
				int total = 500 * a + 100 * b + 50 * c;
				if (total == X) count++;
			}
		}
	}

	cout << count << endl;
}

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

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

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

    int *dp = new int[n + 10];
    for (int i = 0; i <= n; i++) {
        dp[i] = INT_MAX;
    }
    dp[0] = 0;

    for (int i = 0; i <= n; i++) {
        int nine = 9, six = 6;
        while (i >= nine) {
            dp[i] = min(dp[i], dp[i - nine] + 1);
            nine *= 9;
        }
        while (i >= six) {
            dp[i] = min(dp[i], dp[i - six] + 1);
            six *= 6;
        }
        dp[i] = min(dp[i], dp[i - 1] + 1);
    }

    cout << dp[n] << endl;
    return 0;
}

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

int main() {
    int a, b, c, d;
    std::cin >> a >> b >> c >> d;
    int left = a + b, right = c + d;
    if (left > right){
        std::cout << "Left" << std::endl;
    }
    else if(left == right){
        std::cout << "Balanced" << std::endl;
    }
    else{
        std::cout << "Right" << std::endl;
    }
}

Measured memory_bytes: 256
n=int(input())
s=input()
c=[0]*26
x=10**9+7

ans=0
for chr in range(n):
    c[ord(s[chr])-97]+=1
for i in range(26):
    ans=((ans%x)*((c[i]+1)%x))%x
    ans+=c[i]
    ans%=x
print(ans)

Measured memory_bytes: 3188
#include<stdio.h>
#include<string.h>
int main(void){
    char s[101];
    scanf("%s",s);
    int ans=0;
    for(int i=0;strlen(s)>i;++i){
        if(((i+1)%2==1)==(s[i]=='R'||s[i]=='U'||s[i]=='D'))
        ++ans;
        else if(((i+1)%2==0)==(s[i]=='L'||s[i]=='U'||s[i]=='D'))
        ++ans;
    }
    if(ans==strlen(s))
    printf("Yes");
    else
    {printf("No");}
    return 0;
}

Measured memory_bytes: 128
import java.io.PrintWriter;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner stdin = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		
		int N = Integer.parseInt(stdin.next());
		int A[] = new int[N+10];
		int B[] = new int[N+10];
		int C[] = new int[N];
		int sum = 0;
		
		for(int i=1;i<=N;i++) {
			A[i] = Integer.parseInt(stdin.next());
		}
		for(int i=1;i<=N;i++) {
			B[i] = Integer.parseInt(stdin.next());
		}
		for(int i=1;i<=N-1;i++) {
			C[i] = Integer.parseInt(stdin.next());
		}
		
		for(int i=1;i<=N;i++) {
			sum+=B[A[i]];
			if(A[i] + 1 == A[i+1]) {
				sum+=C[A[i]];
			}
		}
		out.println(sum);
		out.flush();
	}
	
}

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

int main() {
  int l, r, d;
  cin >> l >> r >> d;
  int ans = 0;
  for (int i = l; i <= r; i++) {
    if (i % d == 0) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}
/*
*/


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

int main(){
	int n,m,p;
	while(cin>>n>>m>>p, n||m||p){
		int sum=0, atari=0;

		int x;
		for(int i=1;i<=n;i++){
			cin>>x;
			sum+=x;
			if(i==m) atari=x;
		}
		sum*=(100-p);
		if(atari)cout<<sum/atari<<endl;
		else cout<<"0"<<endl;
	}

	return 0;
}



Measured memory_bytes: 3036
/*input
311114770564041497
*/
#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;
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld long double
#define pii pair<int,int>
#define f first
#define s second
#define pb emplace_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define sz(_a) (ll)(_a.size())
#define FILL(n) memset(n,0,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
const ll maxn=100005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=INT_MAX;
const ll MOD=998244353;
const ld PI=acos(-1);
const ld eps=1e-9;
ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
int main(){
	long long s;
	cin>>s;
	const int v=1000000000;
	
	int x=(v-s%v)%v;
	int y=(s+x)/v;
	
	cout<<"0 0 1000000000 1 "<<x<<" "<<y<<endl;
}

Measured memory_bytes: 256
#include <iostream>

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

using namespace std;

using ll = long long;

int main() {
	int n;
	cin >> n;
	
	int i;
	ll res = 0;
	rep(i, n) {
		if (i % 3 == 0 || i % 5 == 0) continue;
		res += i;
	}
	
	cout << res << '\n';
	
	return 0;
}

Measured memory_bytes: 3636
import java.util.*;
import java.io.*;
import java.text.*;
import java.math.*;
import static java.lang.Integer.*;
import static java.lang.Double.*;
import java.lang.Math.*;

public class Main {

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

	public void run() throws Exception {
		FastIO file = new FastIO();
		int n = file.nextInt();
		int k = file.nextInt() - 1;
		String s = file.next();
		System.out.println(s.substring(0, k) + s.substring(k, k + 1).toLowerCase() + s.substring(k + 1));
	}

	public static class FastIO {
		BufferedReader br;
		StringTokenizer st;

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

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

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	public static long pow(long n, long p, long mod) {
		if (p == 0)
			return 1;
		if (p == 1)
			return n % mod;
		if (p % 2 == 0) {
			long temp = pow(n, p / 2, mod);
			return (temp * temp) % mod;
		} else {
			long temp = pow(n, (p - 1) / 2, mod);
			temp = (temp * temp) % mod;
			return (temp * n) % mod;

		}
	}

	public static long pow(long n, long p) {
		if (p == 0)
			return 1;
		if (p == 1)
			return n;
		if (p % 2 == 0) {
			long temp = pow(n, p / 2);
			return (temp * temp);
		} else {
			long temp = pow(n, (p - 1) / 2);
			temp = (temp * temp);
			return (temp * n);

		}
	}

	public static long gcd(long x, long y) {
		if (x == 0)
			return y;
		else
			return gcd(y % x, x);
	}

	public static boolean isPrime(int n) {
		if (n <= 1)
			return false;
		if (n <= 3)
			return true;

		if (n % 2 == 0 || n % 3 == 0)
			return false;

		for (int i = 5; i * i <= n; i = i + 6)
			if (n % i == 0 || n % (i + 2) == 0)
				return false;

		return true;
	}
}


Measured memory_bytes: 19668
#include <bits/stdc++.h>
#define N 6000
using namespace std;
typedef long long ll;
pair <int,int> p[N];
int n;
ll F[N];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&p[i].first,&p[i].second),p[i].first+=p[i].second;
	sort(p+1,p+1+n);
	for(int i=1;i<=n;i++) F[i]=1000000000000000000ll;
	F[0]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=n;j>=0;j--) if(p[i].first-p[i].second>=F[j])
			F[j+1]=min(F[j]+p[i].second,F[j+1]);
	}
	for(int i=n;i>=0;i--) 
		if(F[i]!=1000000000000000000ll)
		{
			printf("%d\n",i);
			return 0;
		}
	return 0;
}

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

A, B, C, D, E, F =  MAP()
A *= 100
B *= 100
# 溶ける最大濃度
limit = E / (100+E)

# dp[i][j] := 水i、砂糖jの状態を実施可能か
dp = list2d(F+1, F+1, 0)
dp[0][0] = 1
for i in range(F+1):
    for j in range(F+1):
        # 枝刈り
        if i+j > F:
            continue
        # 実施可能な状態なら、4つの行動を遷移させる
        if dp[i][j]:
            if i+A <= F:
                dp[i+A][j] = 1
            if i+B <= F:
                dp[i+B][j] = 1
            if j+C <= F:
                dp[i][j+C] = 1
            if j+D <= F:
                dp[i][j+D] = 1

ans1 = ans2 = mx = 0
for a in range(F+1):
    for b in range(F+1):
        if a+b > F:
            break
        if a == b == 0:
            continue
        if dp[a][b]:
            x = b / (a+b)
            # 濃度が濃すぎて溶け切らない
            if x > limit:
                continue
            # 最大濃度の更新
            if mx <= x:
                mx = x
                ans1 = a + b
                ans2 = b
print(ans1, ans2)


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

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

    int n, k, q;
    cin >> n >> k >> q;
    vector<int> score(n, k - q);
    for (int i = 0; i < q; i++) {
        int a;
        cin >> a;
        a--;
        score[a]++;
    }
    for (int i = 0; i < n; i++) {
        cout << (score[i] > 0 ? "Yes" : "No") << '\n';
    }
}


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

using namespace std;
  
int main() {
  int N,K;
  int c;
  cin >> N >> K;
  
  for(int i=0; i<N; i++){
    int h;
    cin >> h;
    if(h >= K) {
      c++;
    }
  }
  cout << c;

 }

Measured memory_bytes: 256
#require 'prime'
#require 'openssl'
MOD=10**9+7;  cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def ar2(s1,s2,de=nil) Array.new(s1){Array.new(s2,de)} end
def ar3(s1,s2,s3,de=nil) Array.new(s1){Array.new(s2){Array.new(s3,de)}} end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+).to_i end
def ceil(a,b) (a.to_f/b).ceil end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def pu(h) begin; require './../nemi_lib/debug.rb'; puts_val(h); rescue LoadError; end; end
########### ( ˘ω˘ )ｽﾔｧ… ###########
x,y=gsmi
max=4*x
min=2*x
puts_yesno min<=y&&y<=max && y.even?

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

using namespace std;

typedef long long ll;

const int mod = 1e9+7;

int main(){
	vector<int> v(3);
	for(int i=0;i<3;i++) cin >> v[i];
	sort(v.begin(),v.end());
	cout << v[0]+v[1] << "\n";
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
inline long long read(){
	register long long x=0;
	register bool f=0;
	register char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-') f=1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<3)+(x<<1)+c-48;
		c=getchar();
	}
	return f?-x:x;
}
char cr[200];int tt;
inline void print(register long long x,register char k='\n') {
    if(!x) putchar('0');
    if(x < 0) putchar('-'),x=-x;
    while(x) cr[++tt]=x%10+'0',x/=10;
    while(tt) putchar(cr[tt--]);
    putchar(k);
}
long long n,m;
bool flag;
void dfs(int now,int c,int lim){
	m=m*10+now;
	//cout<<now<<" "<<c<<" "<<lim<<" "<<m<<endl;
	if(flag) return;
	if(c>lim){
		n--;
		if(!n){
			flag=1;
			print(m);
			return;
		}
		m/=10;
		return;
	}
	if(flag) return;
	if(now!=0) dfs(now-1,c+1,lim);
	if(flag) return;
	dfs(now,c+1,lim);
	if(flag) return;
	if(now!=9)dfs(now+1,c+1,lim);
	m/=10;
}
int main(){
	n=read();
	for(int lim=0;lim<=20;lim++){
		if(flag) return 0;
		for(int i=1;i<=9;i++){
			if(flag) return 0;
			dfs(i,1,lim);
		}
	}
	return 0;
}


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

int main()
{
	int N, L;
	cin >> N >> L;
	int original = N*L - N + N*(N+1)/2;
	if (L+N-1 < 0)
		cout << original - (L+N-1);
	else if (L > 0)
		cout << original - L;
	else
		cout << original;
	cout << '\n';
}


Measured memory_bytes: 256
#coding:utf-8

import sys

def gcd(n):
    x = n[0]
    y = n[1]

    while y:
        x, y = y, x % y

    return x


def lcm(n):
    return int(n[0] * n[1] / gcd(n))


if __name__ == '__main__':

    lines = []

    for line in sys.stdin:
        if line == "\n":
            break
        else :
            lines.append([int(item) for item in line.split(" ")])

    for n in lines:
        print(str(gcd(n)) + " " + str(lcm(n))) 

Measured memory_bytes: 7616
N=int(input())
K=int(input())
X=int(input())
Y=int(input())
ans=0
if N>K:
    for i in range(K):
        ans+=X
    for j in range(N-K):
        ans+=Y
if N<=K:
    for i in range(N):
        ans+=X
print(ans)

Measured memory_bytes: 3064
# Author: cr4zjh0bp
# Created: Sat Mar 14 09:09:09 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self._size = [1 for _ in range(n)]
        self._edges = 0

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
        
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self._size[y] += self._size[x]
            self._edges += 1
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self._size[x] += self._size[y]
            self._edges += 1
    
    def size(self, x):
        x = self.find(x)
        return self._size[x]
    
    def trees(self):
        return self.n - self._edges

    def same(self, x, y):
        return self.find(x) == self.find(y)

n, m = na()
p = na()
uf = UnionFind(n)
for i in range(m):
    x, y = na()
    x -= 1
    y -= 1
    uf.unite(x, y)

d = dict()
for i in range(n):
    d[p[i] - 1] = i

ans = 0
for i in range(n):
    if uf.same(i, d[i]):
        ans += 1

print(ans)

Measured memory_bytes: 28960
H,W = map(int,input().split())
n = int(input())
a = list(map(int,input().split()))

def print_ans(ans):
  for i in ans:
    for j in i:
      print(str(j) + ' ',end='')
    print()
  
ans = [[0 for i in range(W)] for j in range(H)]
ans[0][0] = 1
a[0] -= 1
color = 1
if a[0] == 0:
  color += 1
r,c = 0,0
direction = 0
for i in range(H*W-1):
  if direction ==0:
    if r >= H-1 or ans[r+1][c] != 0:
      direction = 1
      c += 1
    else:
      r+= 1
  elif direction == 1:
    if c >= W-1 or ans[r][c+1] != 0:
      direction = 2
      r -= 1
    else:
      c += 1
  elif direction == 2:
    if r == 0 or ans[r-1][c] != 0:
      direction = 3
      c -= 1
    else:
      r -= 1
  elif direction == 3:
    if c == 0 or ans[r][c-1] != 0:
      direction = 0
      r += 1
    else:
      c -= 1
  ans[r][c] = color
  a[color-1] -= 1
  if a[color-1] == 0:
    color += 1
print_ans(ans)

Measured memory_bytes: 3956
num, deathblow = map(int, input().split())
enemy_table = list(map(int, input().split()))
list.sort(enemy_table, reverse=True)
sum = 0
if num <= deathblow:
    print(0)
else:
    for i in range(deathblow):
        enemy_table[i] = 0
    for j in range(num):
        sum += enemy_table[j]
    print(sum)

Measured memory_bytes: 31364
use v5.18; # strict say state
use warnings;
use List::Util qw(reduce first max min sum0);

chomp (my $n = <STDIN>);
chomp (my @a = split / /, <STDIN>);
my $ans = (grep{$_ % 2 > 0} @a) % 2;
say "YES" if $ans == 0;
say "NO" unless $ans == 0;

Measured memory_bytes: 17572
#include <iostream>
#include <queue>
#include <cassert>
#include <map>
#include <vector>
using namespace std;

char c[12][12];

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

int memo[12][12][12][1024];

struct NODE{
	int next;
	int x,y,prev;
	int cost;
	NODE(int x,int y,int prev,int next,int cost) : x(x) , y(y) , prev(prev) , next(next), cost(cost) {}
};

int dir(pair<int,int> a,pair<int,int> b){
	int ddx = a.first - b.first;
	int ddy = a.second - b.second;
	if( ddx == 0 ) return ddy < 0 ? 3 : 1;
	else if( ddy == 0 ) return ddx < 0 ? 0 : 2;
	else assert(0);
}

int atamaga[12][12];
int main(){
	for(int i = 0 ; i < 12 ; i++)
		for(int j = 0 ; j < 12 ; j++)
			c[i][j] = '#';

	int H,W,N;
	cin >> H >> W >> N;
	for(int i = 0 ; i < H ; i++){
		for(int j = 0 ; j < W ; j++){
			cin >> c[i+1][j+1];
		}
	}
	map<char,pair<int,int> >tmp;
	for(int i = 1 ; i <= H ; i++){
		for(int j = 1 ; j <= W ; j++){
			tmp[c[i][j]] = make_pair(j,i);
		}
	}
	string table = "edcbaS";
	int initdir = 0;
	for(int i = 0 ; i+1 < table.size() ; i++){
		initdir = initdir * 4 + dir(tmp[table[i+1]],tmp[table[i]]);
	}
	for(int i = 0 ; i < table.size() ; i++){
		int x = tmp[table[i]].first;
		int y = tmp[table[i]].second;
		c[y][x] = '.';
	}
	for(int i = 1 ; i <= N ; i++){
		int x = tmp['0'+i].first;
		int y = tmp['0'+i].second;
		atamaga[y][x] = i;
		c[y][x] = '.';
	}
	queue<NODE> Q;
	Q.push(NODE(tmp['S'].first,tmp['S'].second,initdir,1,0));
	while(Q.size()){
		NODE q = Q.front(); Q.pop();
		if( memo[q.y][q.x][q.next][q.prev]++ ) continue;
		if( q.next > N ){
			cout << q.cost << endl;
			return 0;
		}
		vector< pair<int,int> > dont;
		int tx = q.x , ty = q.y;
		int oo = q.prev;
		dont.push_back(make_pair(tx,ty));
		for(int i = 0 ; i < 4 ; i++){

			int dirdir = (oo+2) % 4;
			oo /= 4;
			tx += dx[dirdir];
			ty += dy[dirdir];
			dont.push_back(make_pair(tx,ty));
		}
		
		for(int i = 0 ; i < 4 ; i++){
			int tx = q.x + dx[i] , ty = q.y + dy[i];
			if( c[ty][tx] == '#' ) continue;
			int flag = 1;
			for(int j = 0 ; j < dont.size() ; j++)
				if( dont[j] == make_pair(tx,ty) ){
					flag = 0; break;
				}
			if(!flag) continue;
			Q.push(NODE(tx,ty,(q.prev*4+(i))%1024,q.next+(q.next==atamaga[ty][tx]),q.cost+1));
		}
		
	}
	cout << -1 << endl;
	
	
	
}


Measured memory_bytes: 6368
//#include <tourist>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
struct edge
{
    int to, cost;
};
ll n, k;
int a[10000];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    vector<ll> a(n);
    vector<ll> s(n + 1);
    map<ll, ll> m;
    m[0] = 1;
    ll ans = 0;
    s[0] = 0;
    //A[i]の和をx個分取ってKで割るとx余るということは、x＜Kでかる(A[i]-1)をx個とってK
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        s[i + 1] = s[i] + a[i] - 1;
        if (i + 1 - k >= 0)
            m[s[i + 1 - k] % k]--; //k個より前のものを消す
        ans += m[s[i + 1] % k];
        m[s[i + 1] % k]++;
    }
    cout << ans << "\n";
}


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

#define ll long long
#define pb push_back
#define INF 1'000'000'007
#define cases int t;cin>>t;while(t--)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define ff first
#define ss second

#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;

int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	ll n,W;
	cin>>n>>W;
	ll w[n],v[n],sum=0;
	rep(i,0,n){
		cin>>w[i]>>v[i];
		sum+=v[i];
	}
	ll dp[sum+1][n+1];
	rep(i,0,sum+1){
		dp[i][0]=INF;
	}
	dp[0][0]=0;
	rep(i,0,sum+1){
		rep(j,1,n+1){
			if(i==0){
				dp[i][j]=0;
				continue;
			}
			if(v[j-1]<=i){
				dp[i][j]=min(w[j-1]+dp[i-v[j-1]][j-1],dp[i][j-1]);
			}
			else
				dp[i][j]=dp[i][j-1];
		}
	}
	ll cnt=0;
	rep(i,0,sum+1){
		if(dp[i][n]<=W)
			cnt=max(cnt,i);
	}
	cout<<cnt;
	
	
	
	return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/21  Problem: ABC 060 A / Link: http://abc060.contest.atcoder.jp/tasks/abc060_a  ----- */


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

	string A, B, C; cin >> A >> B >> C;
	LL ans = (A.back()==B.front())&&(B.back()==C.front());
	
	
	cout << (ans?"YES":"NO") << "\n";

	return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"

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

int main()
{
  int n, k;
  cin >> n >> k;
  cout << n - k + 1 << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PDD pair<double, double>
#define MOD ((int)2e9 + 7)
#define INF ((int)2e9)
#define INFLL ((LL)2e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (2 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 2, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 1) u += MOD;
    return u;

}

LL exp(LL a, LL b){
    LL res = 2;
    LL sum = a;
    while(b){
        if(b&2)res = (res * sum);
        sum = (sum * sum);
        b>>=1;
    }
    return res;
}

double exp(double a, LL b){
    double res = 1;
    double sum = a;
    while(b){
        if(b&1)res = (res * sum);
        sum = (sum * sum);
        b>>=1;
    }
    return res;
}

PII operator+(const PII &a, const PII &b){
    return PII(a.first + b.first, a.second + b.second);
}

vector<vector<int> > xc(100001), yc(100001);

PII func(PII p){
    PII res(0, 0);
    if(!xc[p.first].empty()){
        vector<int> line = xc[p.first];
        xc[p.first].clear();
        ++res.first;
        for(auto &i:line){
            res = res + func(PII(p.first, i));
        }
    }
    if(!yc[p.second].empty()){
        vector<int> line = yc[p.second];
        yc[p.second].clear();
        ++res.second;
        for(auto &i:line){
            res = res + func(PII(i, p.second));
        }
    }
    return res;
}

signed  main(){
    int N, K, X, Y;
    cin >> N >> K >> X >> Y;
    cout << (N <= K ? N * X : X * K + (N - K) * Y) << endl;
    return 0;
}



Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define MOD 1000000007
#define INF 1e9
#define F first
#define S second
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int main(void){
    int N,cnt=0,ans=INF;
    cin>>N;
    VI p(N);
    REP(i,N){
        cin>>p[i];
    }
    REP(j,p[0]+1){
        cnt=0;
        cnt+=j;
        int now=p[0]-j;
        int next=max(0,p[1]-now);
        cnt+=now*2;
        FOR(i,1,N-1){
            now=next;
            next=max(0,p[i+1]-now);
            cnt+=now*2;
        }
        cnt+=next;
        ans=min(ans,cnt);
    }
    cout<<ans<<endl;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    reverse(all(a));
    vector<int> dp(n, INF);
    for (int i = 0; i < n; ++i) {
        *upper_bound(all(dp), a[i]) = a[i];
    }
    cout << lower_bound(all(dp), INF) - dp.begin() << endl;
}

Measured memory_bytes: 4032
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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;}


int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (c >= a && c <= b) Yes;
  else No;
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
//ll dx[4] = {1, 0, -1, 0};
//ll dy[4] = {0, 1, 0, -1};

vector<ll> g[114514];
vector<ll> h[114514];
bool used[114514] = {};
ll d[114514];
void dfs(int from, int now, int cnt) {
	if (cnt == 0) {
		if (from != now) h[from].push_back(now);

		return;
	}
	for (int i = 0; i < g[now].size(); i++) {
		dfs(from, g[now][i], cnt - 1);
	}
	return;
}

int main() {
	IOS();
	ll n;
	cin >> n;
	vector<ll> d(n);
	for (int i = 0; i < n; i++) {
		cin >> d[i];
	}
	sort(d.begin(), d.end());
	ll ans = d[n / 2] - d[n / 2 - 1];

	dump(ans);
	return 0;
}


Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 10;
long long d[maxN], ans[maxN];
int sz[maxN], sz_2[maxN];
int n;
vector<int> g[maxN];

void dfs(int x, int p = 0) {
	sz[x] = 1;
	ans[x] = 0;
	for (int v : g[x]) {
		if (v == p) continue;
		dfs(v, x);
		sz[x] += sz[v];
		ans[x] += sz[v] + ans[v];
	}
}

void dfs_2(int x, int p = 0) {
	if (p) {
		ans[x] += sz[p] - 2*sz[x] + ans[p] - ans[x];
		sz[x] = sz[p];
	}
	for (int v : g[x]) {
		if (v == p) continue;
		dfs_2(v, x);
	}
}


int main() {
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> d[i];
	for (int i = 1; i <= n; ++i) sz_2[i] = 1;
	map<long long, int, greater<long long>> p;
	for (int i = 1; i <= n; ++i) p[d[i]] = i;
	bool fun = 1;
	while (p.size() > 1) {
		auto f = p.begin(); p.erase(f);
		long long d_p = (f->first + 2*sz_2[f->second] - n);
		fun &= p.count(d_p);
		if (not fun) break;
		int r = p[d_p];
		sz_2[r] += sz_2[f->second];
		g[r].push_back(f->second);
		g[f->second].push_back(r);
	}
	dfs(1);
	dfs_2(1);
	for (int i = 1; i <= n; ++i) fun &= d[i] == ans[i];
	if (fun) {
		for (int i = 1; i <= n; ++i) {
			for (int v : g[i])
				if (i < v) cout << i << " " << v << endl;
		}
	} else puts("-1");
	return 0;
}

Measured memory_bytes: 18560
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
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; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

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

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;


int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll h;
    cin >> h;
    ll ans = 1;
    ll tmp = 1;
    while(h > 1){
        h /= 2;
        tmp *= 2;
        ans += tmp;
    }
    print(ans);

}


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

#ifdef __WIN32
#define LLFORMAT "I64"
#else
#define LLFORMAT "ll"
#endif

using namespace std;

struct segment_tree {
	segment_tree() {}
	segment_tree(int _n) {
		n = _n;
		N = 1; while(N - 1 <= n) N <<= 1;
		a = vector<int>(N << 1, 0);
	}

	void M(int i, int x) {
		a[i |= N] = x;
		for (i >>= 1; i; i >>= 1) a[i] = max(a[i << 1], a[(i << 1) | 1]);
		return;
	}

	int Q(int i) {
		int x = 0;
		for (int s = (i | N) - 1, t = (n | N) + 1; s ^ t ^ 1; s >>= 1, t >>= 1) {
			if(~s & 1) x = max(x, a[s ^ 1]);
			if(t & 1) x = max(x, a[t ^ 1]);
		}
		return x;
	}
	private :
	vector<int> a;
	int n, N;
};

int main() {
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<int> a(n), s(n, 0);
	vector<bool> h(n);
	for (int mx = 0, i = 0; i < n; ++i) cin >> a[i], h[i] = (a[i] > mx), mx = max(mx, a[i]);
	for (int i = n - 1; i; --i) s[i - 1] = s[i] + h[i];
	array<segment_tree, 2> seg = {segment_tree(n), segment_tree(n)};
	for (int i = n - 1; ~i; --i) {
		array<int, 2> g = {seg[0].Q(a[i]), seg[1].Q(a[i])};
		if(h[i]) {
			seg[0].M(a[i], g[0] + 2);
			if(g[1] & 1) seg[1].M(a[i], g[1] + 2);
		}
		else {
			seg[1].M(a[i], g[0] + 1);
			if(g[1] & 1) seg[0].M(a[i], g[1] + 1);
		}
	}

	int max0(0), max1(0), cnt0(0), cnt1(0);
	string ans("");
	for (int x, i = 0; i < n; ++i) {
		x = a[i];
		seg[0].M(x, 0); seg[1].M(x, 0);

		auto check = [&](int max0, int cnt0, int max1, int cnt1) {
			static array<int, 2> g;
			g = {seg[0].Q(max0), seg[1].Q(max0)};
			if(cnt0 + cnt1 + s[i] & 1) {
				if(g[1] & 1) {
					if(cnt0 + 1 <= cnt1 + s[i] && cnt0 + g[1] >= cnt1 + s[i]) return true;
				}
			}
			else {
				if(cnt0 <= cnt1 + s[i] && cnt0 + g[0] >= cnt1 + s[i]) return true;
			}
			g = {seg[0].Q(max1), seg[1].Q(max1)};
			if(cnt0 + cnt1 + s[i] & 1) {
				if(g[1] & 1) {
					if(cnt1 + 1 <= cnt0 + s[i] && cnt1 + g[1] >= cnt0 + s[i]) return true;
				}
			}
			else {
				if(cnt1 <= cnt0 + s[i] && cnt1 + g[0] >= cnt0 + s[i]) return true;
			}
			return false;
		};

		if(check(max(max0, x), cnt0 + (x > max0), max1, cnt1)) { ans += "0"; max0 = max(max0, x); cnt0 += (x == max0); }
		else { ans += "1"; max1 = max(max1, x); cnt1 += (x == max1); }
	}
	if(cnt0 == cnt1) cout << ans << endl;
	else cout << "-1\n";
	return 0;
}

Measured memory_bytes: 6532
from array import array

N = int(input())
A = list(map(int, input().split()))

i_of_minimum_abs = 0
minimum_abs = 10**9
Aarray = array('l', A)

for i in range(N):
    a = Aarray[i]
    if abs(a) < minimum_abs:
        minimum_abs = min(minimum_abs, abs(a))
        i_of_minimum_abs = i

for i in range(i_of_minimum_abs):
    if Aarray[i] < 0:
        Aarray[i] = -Aarray[i]
        Aarray[i+1] = -Aarray[i+1]
        
for i in reversed(list(range(i_of_minimum_abs+1,N))):
    if Aarray[i] < 0:
        Aarray[i] = -Aarray[i]
        Aarray[i-1] = -Aarray[i-1]

print(sum(Aarray))


Measured memory_bytes: 64752
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<algorithm>
#define N 200010
using namespace std;
int a[N];
map<int,int>mp;
int main(){
    //x+y=a
    //2x+4y=b
    int n;

    while (scanf("%d",&n)!=EOF) {
        for (int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
        }
        sort(a,a+n);
        mp.clear();
        for (int i=0;i<n;i++) {
            if (i!=0&&a[i]==a[i-1]) {
                mp[a[i]] = 1;
                continue;
            }
            if (!mp[a[i]])
                for (int j=a[i]+a[i];j<=a[n-1];j+=a[i])
                    mp[j]=1;
        }
        int ans=0;
        for (int i=0;i<n;i++)
        {
            if (!mp[a[i]])
                ans++;
        }
        printf("%d\n",ans);
    }
    return 0;
}



Measured memory_bytes: 50752
#include<iostream>
#include<algorithm>
#define rep(i,s,n) for(int i=s;i<n;i++)
using namespace std;
int d[10010],n,m,k,r,l;
int main(){
	while(true){
		cin>>n>>k>>m>>r;
		if(!(n+m+k+r))break;
		rep(i,0,r+9)d[i]=0;k=1,l=n;
		rep(i,0,r+9)d[i]+=k/l,k%=l,k*=10;
		if(m)rep(i,1,n){k=1,l=i*n;rep(j,0,r+9)d[j]+=k/l,k%=l,k*=10;}
		for(int i=r+9;i>0;i--)d[i-1]+=d[i]/10,d[i]%=10;
		cout<<d[0]<<".";
		rep(i,1,r+1)cout<<d[i];
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 3104
N,D = map(int,input().split())
x_list = [0] * N
y_list = [0] * N
for i in range(N):
    x_list[i],y_list[i] = map(int,input().split())
cnt = 0
for x,y in zip(x_list,y_list):
    if x ** 2 + y ** 2 <= D ** 2:
        cnt += 1
print(cnt)

Measured memory_bytes: 73080
#include <stdio.h>

int main(void){
    int h, w;
    char a[110][110]={};
    scanf("%d%d", &h, &w);
    for(int j=0; j<w+2; j++) a[0][j] = '#', a[h+1][j] = '#';
    for(int i=1; i<h+1; i++){
        scanf("%s", &a[i][1]);
        a[i][0] = '#', a[i][w+1] = '#';
    }
    for(int i=0; i<h+2; i++) printf("%s\n", a[i]);
    return 0;
}

Measured memory_bytes: 1676
#include<iostream>
using namespace std;
int main(){
	int n,i,i2,match[101],point[101],team[101],lunk[101],ans[101],cnt=1,cntout=0,j=0,a,b,c,d,toread;
	cin>>n;
	for(i=0;i<=n;i++){
		point[i]=0;
		match[i]=0;
		team[i]=i;
	}
	while(j!=n){
		cin>>a>>b>>c>>d;
		match[a]++;
		match[b]++;
		if(c>d){
			point[a]+=3;
		}
		else if(c<d){
			point[b]+=3;
		}
		else{
			point[a]++;
			point[b]++;
		}
		j=0;
		for(i=1;i<=n;i++){
			if(match[i]==n-1){
				j++;
			}
		}
	}
	for(i=1;i<=n;i++){
		for(i2=1;i2<=n;i2++){
			if(point[i]>point[i2]){
				toread=point[i];
				point[i]=point[i2];
				point[i2]=toread;
				toread=team[i];
				team[i]=team[i2];
				team[i2]=toread;
			}
		}
	}
	for(i=1;i<n;i++){
		lunk[i]=cnt;
		if(point[i]==point[i+1]){
			cntout++;
		}
		else{
			cnt+=cntout+1;
			cntout=0;
		}
	}
	lunk[i]=cnt;
	for(i=1;i<=n;i++){
		ans[team[i]]=lunk[i];
	}
	for(i=1;i<=n;i++){
		cout<<ans[i]<<endl;
	}
}

Measured memory_bytes: 3080
k,n = map(int, input().split());
A = list(map(int, input().split()))
B = [0 for i in range(len(A))]
for i in range(len(A)):
    if i == 0:
        B[i] = k-A[len(A)-1]+A[i]
    else:
        B[i] = A[i]-A[i-1]
print(k-max(B))


Measured memory_bytes: 26436
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
       
		String k=sc.next();
       

  		
    
 	if(k.equals("A")){
    		System.out.println("T");
    	}else if(k.equals("T")){
     		System.out.println("A");
   	 }else if(k.equals("C")){
      	System.out.println("G");
    }else{

    	System.out.println("C");
    }
    }
}

Measured memory_bytes: 19796
# abc044_a
# https://atcoder.jp/contests/abc044/tasks/abc044_a

# 最初のK泊までは、X円
# K＋1泊目以降は、Y円

# N泊連続で宿泊した際の宿泊費

# 入力
n = int(input())
k = int(input())
x = int(input())
y = int(input())

# 処理

# x円とy円
if n > k:
    answer = k * x + (n - k) * y
# x円のみ
else:
    answer = n * x

print(answer)


Measured memory_bytes: 9164
while True:
    n = int(input())
    if n==0:
        break
    l = list([0] * 10)
    for i in range(n):
        c = int(input())
        l[c] += 1
    for i in range(10):
        if l[i]==0:
            print("-")
        else:
            print("*"*l[i])
            
    
    


    
    


Measured memory_bytes: 5624
#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
#include<vector>
#include<cstring>
#define INF 1e10
using namespace std;
struct edge{
  int to,limit;
  double dist;
};
struct Point{
  int speed,prev,v;
  double cost;
  Point(){}
  Point(int speed_,int prev_,int v_,double cost_)
    :speed(speed_),prev(prev_),v(v_),cost(cost_){}
  bool operator>(const Point &a)const{
    return cost > a.cost;
  }
};
vector<edge> G[100];
double d[40][40][40];//speed,pos,prev

double dikstra(int s,int g){
  int ds[3]={-1,0,1};
  priority_queue<Point,vector<Point>,greater<Point> > que;
  
  for(int i=0;i<40;i++)
    for(int j=0;j<40;j++)
      for(int k=0;k<40;k++)
	d[i][j][k]=INF;
  
  d[0][s][0]=0;
  Point tmp(0,0,s,0);
  que.push(tmp);
  
  while(!que.empty()){
    Point p=que.top();que.pop();
    if(d[p.speed][p.v][p.prev]<p.cost)continue;
    if(p.speed==1 && p.v==g)return p.cost;

    for(int i=0;i<G[p.v].size();i++){
	edge e=G[p.v][i];
      for(int j=0;j<3;j++){
	int ns=p.speed+ds[j];
	if(1<=ns && ns<= e.limit &&
	   e.to!=p.prev && 
	   d[ns][e.to][p.v]>p.cost+e.dist/ns){

	  Point tmp(ns,p.v,e.to,p.cost+e.dist/ns);
	  que.push(tmp);
	  d[ns][e.to][p.v]=p.cost+e.dist/ns;
	  //cout << "d[" << ns << "][" << e.to << "][" << p.v << "]:" << d[ns][e.to][p.v] << endl;
	}
      }
    }
  }
  return -1;
}

int main(){
  int n,m,s,g;
  while(cin>>n>>m,n){
    for(int i=0;i<100;i++)G[i].clear();
    cin>>s>>g;
    for(int i=0;i<m;i++){
      int x,y,d,c;
      cin>>x>>y>>d>>c;
      G[x].push_back((edge){y,c,d});
      G[y].push_back((edge){x,c,d});
    }
    double ans=dikstra(s,g);
    if(ans==-1)cout << "unreachable" << endl;
    else printf("%.5lf\n",ans);
  }
  return 0;
}

Measured memory_bytes: 2276