akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
string s1,s2;
int main(){
	cin>>s1>>s2;
	if(s1[0]==s2[2]&&s1[1]==s2[1]&&s1[2]==s2[0]) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

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

#define ALL(V) (V).begin(), (V).end()

template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

int main() {
    ll N, A, B, C;
    cin >> N >> A >> B >> C;
    V<ll> L(N);
    for(ll &l : L) cin >> l;
    ll upper = 1;
    for(ll i = 0; i < N; i++) upper *= 4;
    ll ans = 5e15;
    for(ll i = 0; i < upper; i++) {
        V<ll> sum(3, 0);
        V<ll> cnt(3, 0); 
        ll used = 0;
        ll cpy = i;
        for(ll j = 0; j < N; j++) {
            ll tmp = cpy % 4;
            cpy /= 4;
            if(tmp == 3) continue;
            cnt[tmp]++;
            sum[tmp] += L[j];
        }
        bool suc = 1;
        for(ll j = 0; j < 3; j++) {
            if(cnt[j] == 0) suc = 0;
            used += 10 * (cnt[j] - 1);
        }
        for(ll j = 0; j < 3; j++) {
            ll po = (j == 0 ? A : (j == 1 ? B : C));
            used += abs(po - sum[j]);
        }
        if(suc) ans = min(ans, used);
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main(){
  int H,W;
  cin>>H>>W;
  vector<vector<char>>vec(H, vector<char>(W));
  vector<vector<char>>vec2(H+2, vector<char>(W+2,'#'));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>vec.at(i).at(j);
    }
  }
  /*
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cout<<vec.at(i).at(j)<<" ";
    }
    cout<<endl;
  }
  for(int i=0;i<H+2;i++){
    for(int j=0;j<W+2;j++){
      cout<<vec2.at(i).at(j)<<" ";
    }
    cout<<endl;
  }
  */
  
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      vec2.at(i+1).at(j+1)=vec.at(i).at(j);
    }
  }
  
  for(int i=0;i<H+2;i++){
    for(int j=0;j<W+2;j++){
      cout<<vec2.at(i).at(j);
    }
    cout<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

const int N=(1<<18)+5,M=1e5+5;
int halfn,n,a[N],b[N],f[(1<<9)+5][M],q,p[15];

signed main(){
	read(n);halfn=min(n,(1<<9)-1);
	for(int i=1;i<=n;i++) read(a[i],b[i]);
	for(int i=1;i<=halfn;i++) for(int j=0;j<=100000;j++) f[i][j]=max(f[i>>1][j],j>=b[i]?f[i>>1][j-b[i]]+a[i]:0);
	read(q);
	while(q--){
		int x,y;
		read(x,y);
		if(x<=halfn) write(f[x][y]);
		else{
			int m=0,ans=0;
			for(;x>halfn;x>>=1) p[m++]=x;
			for(int s=0;s<(1<<m);s++){
				int cnt1=0,cnt2=0;
				for(int i=0;i<m;i++) if(s>>i&1) cnt1+=a[p[i]],cnt2+=b[p[i]];
				if(cnt2>y) continue;
				ans=max(ans,cnt1+f[x][y-cnt2]);
			}
			write(ans);
		}
		puts("");
	}
}

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

int main() {
  int x, n;
  cin >> x >> n;
  int p[n];
  bool end = false;
  if (n == 0) {
    cout << x << endl;
    end = true;
  }
  else {
    for (int i = 0; i < n; i++) {
      cin >> p[i];
    }
    bool end2 = false;
    int cnt = 0;
    while (n) {
      int cnt2 = 0;
      for (int i = 0; i < n; i++) {
        if (p[i] == x) break;
        else cnt2++;
      }
      if (cnt2 == n) {
        cout << x << endl;
        break;
      }
      cnt++;
      if (cnt%2 == 0) x += cnt;
      else x -= cnt;
    }
  }
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <queue>

using namespace std;


long long func(long long n,long long a,vector<long long> &dp,long long sum,long long nowsum){
    if(n==0) return sum+nowsum;
    a++;
    return func(n-1,a,dp,sum,nowsum*10+dp[a]) + func(n-1,a,dp,nowsum+sum,0);
}

int main(){
    long long S;
    vector<long long> NS;
    cin>>S;
    while(S){
        NS.push_back(S%10);
        S/=10;
    }
    reverse(NS.begin(),NS.end());
    int digit=NS.size();
    cout<<func(digit,-1,NS,0,0)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long INF = 100000000000000;
int main(){
  int N, M, K;
  cin >> N >> M >> K;
  vector<long long> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  vector<vector<long long>> dp(K, vector<long long>(N, -INF));
  for (int i = 0; i < N; i++){
    dp[0][i] = A[i];
  }
  for (int i = 1; i < K; i++){
    int L = 0, R = 0;
    deque<pair<long long, int>> dq;
    for (int j = i; j < N; j++){
      while (R < j){
        //push dp[i-1][R]
        if (!dq.empty()){
          while (dq.back().first <= dp[i - 1][R]){
            dq.pop_back();
            if (dq.empty()){
              break;
            }
          }
        }
        dq.push_back(make_pair(dp[i - 1][R], R));
        R++;
      }
      while (L <= max(j - M, 0)){
        if (!dq.empty()){
          while (dq.front().second < L){
            dq.pop_front();
            if (dq.empty()){
              break;
            }
          }
        }
        L++;
      }
      dp[i][j] = dq.front().first + A[j] * (i + 1);
    }
  }
  long long ans = 0;
  for (int i = 0; i < N; i++){
    ans = max(ans, dp[K - 1][i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 240056
S = input()

index1 = (len(S)-1)//2
index2 = (len(S)+3)//2
S_sub1 = S[:index1]
S_sub2 = S[index2-1:]

if S == S[::-1] and S_sub1 == S_sub1[::-1] and S_sub2 == S_sub2[::-1]:
    print('Yes')
else:
    print('No')


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

int main() {
	string s,str;
	cin>>s>>str;
	
	int m=s.size();
	int n=str.size();
	int f=0;
	if(n-m!=1){
		cout<<"No"<<endl;
	}
	else if(n-m==1){
		for(int i=0;i<m;i++){
			if(s[i]!=str[i]){
				f=1;
				break;
			}
			
		}
	}

	if(f==1)cout<<"No"<<endl;
	else
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
    #include <algorithm>
    #include <vector>
    #include <map>
    #include <set>
    #include <string>
    #include <cmath>
    #include <iomanip>
    #include <queue>
    #include <unordered_map>
    #include <unordered_set>
    #include <bitset>
    #include <cassert>
    #include <cstring>
    #include <climits>
     
    using namespace std;
     
    #define FOR(i, a, b) for (int i = (a); i < (b); i++)
    #define REP(i, n) FOR(i, 0, n)
    #define SORT(c) sort((c).begin(), (c).end())
    #define mp make_pair
    #define fi first
    #define se second
    #define pb push_back
     
    typedef long long ll;
    typedef pair<int, int> P;
    typedef vector<int> V;
    typedef map<int, int> M;
     
    constexpr ll INF = 1e18;
    constexpr ll MOD = 1e9 + 7;
    constexpr double PI = 3.14159265358979323846;
    constexpr int di[] = {0, 0, 1, -1};
    constexpr int dj[] = {1, -1, 0, 0};
     
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        string s;
        cin >> s;
        int n = s.size();
        string ans = "AC";
        if(s[0]!='A')
            ans = "WA";
        int cnt = 0;
        for (int i = 1; i < n;i++){
            if(isupper(s[i])){
                if(i==1||i==n-1||s[i]!='C'){
                    ans = "WA";
                }
                cnt++;
            }
        }
        if(cnt!=1)
            ans = "WA";
        cout << ans << endl;
        return 0;
    }

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

using ll = long long;
using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(false)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define YN(x)         cout << ((x) ? "YES" : "NO") << endl
#define Yn(x)         cout << ((x) ? "Yes" : "No") << endl
#define yn(x)         cout << ((x) ? "yes" : "no") << endl
#define absi(x)       ( ((x) >= 0) ? (x) : (-(x)) )
#define debugvec(v)   rep(i, v.size()) cerr << "L" << __LINE__ << ": " << #v << "[" << i << "] = " << v[i] << endl;
#define debugvec2(v)  cerr << "L" << __LINE__ << ": " << #v << " = { "; rep(i, v.size()) cerr << v[i] << (i + 1 == v.size() ? "" : ", "); cerr << " }" << endl;

ll gcd(ll a, ll b) { return __gcd(a, b); }
ll lcm(ll a, ll b) { return (a == 0 || b == 0) ? 0 : (a / __gcd(a, b) * b); }

int main(int argc, const char* argv[]) {
	ll n;
	cin >> n;
	cout << (n*n*n) << endl;

	return 0;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }

struct Edge { int to; ll len; };
struct Hist {
	int at; ll dist;
	bool operator<(const Hist &h) const { return dist > h.dist; }
};

const ll inf = 0x3f3f3f3f3f3f3f3fll;
vector<Edge> g[100005];
priority_queue<Hist> pq;
vector<ll> mindist(100005, inf);

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n, m; read(n, m);
	rep(i, 1, n) g[i + 1].push_back(Edge {i, 0});
	rep(i, 0, m) {
		int u, v, l; read(u, v, l);
		g[u].push_back(Edge {v, l});
	}

	mindist[1] = 0;
	pq.push({ 1, 0 });

	while (!pq.empty()) {
		int at; ll dist;
		at = pq.top().at, dist = pq.top().dist;
		pq.pop();
		if (dist > mindist[at]) continue;
		for (auto e : g[at]) if (mindist[e.to] > dist + e.len) {
			mindist[e.to] = dist + e.len;
			pq.push(Hist { e.to, mindist[e.to] });
		}
	}

	die(mindist[n] == inf ? -1 : mindist[n]);
}


Measured memory_bytes: 10232
X = int(input())-1

if X==1:
  print(X+1)
  
else:
  while True:
    X+=1
    R = int(X/2)+1 if X>5 else X
    for i in range(2, R):
      if X % i == 0:
        break

    if i==R-1:
      break

  print(X)

Measured memory_bytes: 9128
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define vi vector<int>
#define sort_v(a) sort(a.begin(), a.end())

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

int main()
{
    int n;
    cin >> n;
    if (n < 1200)
        cout << "ABC" << endl;
    else if (n < 2800)
        cout << "ARC" << endl;
    else
        cout << "AGC" << endl;
}


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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;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 (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int q,h,s,d,n;
cin>>q>>h>>s>>d>>n;
ll res=0;
while(n>0){
    if(2<=n){
        ll min_cost=min(min(8*q,4*h),min(2*s,d));
        res+=min_cost*(n/2);
        n%=2;
    }
    else{
        ll min_cost=min(min(4*q,2*h),s);
        res+=min_cost*n;
        n%=1;
    }
}
cout<<res<<endl;
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T = int> void print(vector<T> v){for(auto a:v)cout<<a<<" ";cout<<endl;}

/*
どの数の倍数でもないものを探す。
ソートして、小さいやつから見て、その数の倍数を順次消していく。
*/

ll n,a[200010],b[1000010]={},ans=0;
ll dp[1000010]={};

int main(void){
	cin>>n;
	rep(i,n)cin>>a[i];
	rep(i,n)b[a[i]]++;
	sort(a,a+n);
	rep(i,n){
		if(b[a[i]]==0)continue;
		if(dp[a[i]]==0){
			dp[a[i]]=1;  // 同じ要素があったときに繰り返しやらないように
			if(b[a[i]]==1)ans++;  // 同じ要素があったら絶対に性質を満たさない。
			for(ll j=2; a[i]*j<=1000000; j++){
				dp[a[i]*j]=1;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 20536
import java.util.*;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int k = sc.nextInt();
        int mod = 1000000007;

        if(w == 1){
            System.out.println("1");
            System.exit(0);
        }

        long[][] dp = new long[h+1][w];

        dp[0][0] = 1;
        for(int i = 0;i < w;i++){
            dp[0][w-1] = 0;
        }

        int[] p = new int[w-1];
        int sum = 0;
        for(int i =0;i < Math.pow(2, w-1);i++){
            if((i & (i << 1)) != 0){
                continue;
            }
            sum++;
            for(int j = 0;j < w;j++){
                if((i & (1 << j)) != 0){
                    p[j]++;
                }
            }
        }

        for(int i = 1;i <= h;i++){
            dp[i][0] = (dp[i-1][0] * (sum-p[0]) + dp[i-1][1] * p[0])%mod;
            dp[i][w-1] = (dp[i-1][w-1] * (sum-p[w-2]) + dp[i-1][w-2] * p[w-2])%mod;
            for(int j = 1;j < w-1;j++){
                dp[i][j] = (dp[i-1][j-1]*p[j-1] + dp[i-1][j] * (sum-p[j-1]-p[j]) + dp[i-1][j+1]*p[j])%mod;
            }
        }
        System.out.println(dp[h][k-1]);
    }

}


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

int main(void) {
  int N, K;
  cin >> N >> K;
  int a, b;
  int count = 0;

  vector<int> v(N);
  for (int i = K; i > 0; i--) {
    cin >> a;
    //cout << a;
    for (int j = a; j > 0; j--) {
      cin >> b;
      v.at(b - 1) += 1;
      //cout << b;
    }
  }
  for (int i = 0; i < N; i++) {
    if (0 == v.at(i)) {
      count++;
    }
  }
  cout << count << endl;
}


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

A, B, Q = mi()

S = [ii() for _ in range(A)]
T = [ii() for _ in range(B)]

S_ = [S[0]] + S + [S[A-1]]
T_ = [T[0]] + T + [T[B-1]]

for _ in range(Q):
    f = ii()
    to_s = bisect.bisect_left(S, f)
    to_t = bisect.bisect_left(T, f)

    ans = float('inf')

    for i in [S_[to_s], S_[to_s+1]]:
        for j in [T_[to_t], T_[to_t+1]]:
            tmp = min(abs(i - f), abs(j - f)) + abs(i - j)
            ans = min(ans, tmp)
    '''
    ans = min(abs(S_[to_s+1] - f) + abs(S_[to_s+1] - T_[to_t+1]), float('inf'))
    ans = min(abs(S_[to_s+1] - T_[to_t+1]) + abs(f - T_[to_t+1]), ans)
    ans = min(abs(S_[to_s+1] - f) + abs(S_[to_s+1] - T_[to_t]), ans)
    ans = min(abs(S_[to_s+1] - T_[to_t]) + abs(f - T_[to_t]), ans)
    ans = min(abs(S_[to_s] - f) + abs(S_[to_s] - T_[to_t+1]), ans)
    ans = min(abs(S_[to_s] - T_[to_t+1]) + abs(f - T_[to_t+1]), ans)
    ans = min(abs(S_[to_s] - f) + abs(S_[to_s] - T_[to_t]), ans)
    ans = min(abs(S_[to_s] - T_[to_t]) + abs(f - T_[to_t]), ans)
    '''
    print(ans)

Measured memory_bytes: 14380
#include<iostream>
using namespace std;
int main()
{

    char s[3];
    cin>>s;
    int Count=0;
    for(int i=0; i<3; i++)
    {
        if(s[i]=='R')
        {
            Count++;
            if(s[i]!=s[i+1])
            {
                break;
            }
        }
    }
    cout<<Count<<endl;
    return 0;
}

Measured memory_bytes: 3524
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        int K = sc.nextInt();

        char tar = S.charAt(K - 1);
        char[] res = new char[S.length()];

        for (int i = 0; i < S.length(); i++) {
            if (tar != S.charAt(i)) {
                res[i] = '*';
            } else {
                res[i] = S.charAt(i);
            }
        }
        System.out.println(res);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const double PI  =3.141592653589793238463;
long long MOD = 1000000007;
int stringToInteger(string x){
    int gg=0;
    stringstream geek(x);
    geek >> gg;
    return gg;
}

ll powmod(ll a,ll b,ll m)
{
    ll ans=1;
    while(b>0){ if(b%2)
        {ans*=a; ans%=m;}
         b/=2; a=a*a; a=a%m;
        }
        return ans%m;
}
ll gcd(ll a,ll b)
{

    return __gcd(a,b);
}
ll mulmod(ll a,ll b,ll m)
{  ll ans=0;
    a %=m;
    while (b>0)
    {       if(b&1) ans = (ans + a) % m;
        a = (a * 2)%m;
        b /= 2;
    }
    return ans % m;
}


ll f[5000001];

ll pow(ll a, ll b, ll MOD)
{
 ll x=1,y=a;
 while(b > 0)
 	{
 		if(b%2 == 1)
 	{
 		x=(x*y);
 		if(x>MOD) x%=MOD;
 	}
 	y = (y*y);
 	if(y>MOD) y%=MOD;
 	b /= 2;
 	}
 return x;
}

/* Modular Multiplicative Inverse
 Using Euler's Theorem
 a^(phi(m)) = 1 (mod m)
 a^(-1) = a^(m-2) (mod m) */
ll InverseEuler(ll n, ll MOD)
{
 return pow(n,MOD-2,MOD);
}

ll C(ll n, ll r, ll MOD)
{

 return (f[n]*((InverseEuler(f[r], MOD) * InverseEuler(f[n-r], MOD)) % MOD)) % MOD;
}

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


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    heights = list(map(int, input().split()))
    heights = heights[:n]

    if n < 1:
        print(0)
        return

    total = 1
    max_h = heights[0]
    for h in heights[1:]:
        if max_h <= h:
            total += 1
            max_h = h

    print(total)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater(){
    #ifndef ONLINE_JUDGE
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
    #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
#define fastio  cin.sync_with_stdio(0); cin.tie(0);cin.exceptions(cin.failbit);
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a,v) memset(a, v, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=1e9+7;
const int N=2e5+5;
int main() {
    
   
    fastio;
    int T=1;
    // cin>>T;
    while(T--){
        int n;cin>>n;
        int y=1000;
        while(y<n){
            y=y+1000;
        }
        cout<<(y-n);
    }   
    timecalculater();
    return 0;   
} 

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

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

	int N;
	cin >> N;

	vector<int> a( 3*N );
	for( int i = 0; i < 3*N; ++i ) {
		cin >> a[i];
	}

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

	int64_t result = 0;
	for( int i = N; i < 3*N; i += 2 ) {
		result += a[i];
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 1408
# 2019/06/15
# Educational DP Contest - A

# Input
n = int(input())
h = list(map(int, input().split()))

dpl = [0] * n
dpl[0] = 0
dpl[1] = abs(h[1] - h[0])

for i in range(2, n):
    hop1 = dpl[i-1] + abs(h[i] - h[i-1])
    hop2 = dpl[i-2] + abs(h[i] - h[i-2])

    if hop1 < hop2:
        dpl[i] = hop1
    else:
        dpl[i] = hop2
print(dpl[n-1])


Measured memory_bytes: 13980
import java.util.Scanner;

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

        int sum = 700;
        for (int i = 0; i < 3; i++) {
            if (line.charAt(i) == 'o') {
                sum += 100;
            }
        }

        System.out.print(sum);
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>

using namespace std;

int p[10000];
bool isPrime[1000000];

int main(void){
  int pnum=0;
  //但多
  fill(isPrime,isPrime+1000000,true);
  for(int i=2;pnum<10000;i++){
     if(isPrime[i] == true){
      p[pnum++] = i;
      for(int j=2;i*j<1000000;j++){
	isPrime[i*j] = false;
      }
    }
  }

  int tmp;
  while(cin >> tmp){
    int ret=0;
    if(!tmp) break;
    for(int i=0;i<tmp;i++) ret+=p[i];
    cout << ret << endl;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define INF 0x7FFFFFFF
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll X, Y, A, B, C, ans = 0;
  cin >> X >> Y >> A >>  B >> C;
  vector<ll> p(A,0), q(B,0), r(C,0);
  REP(i,A) cin >> p[i];
  REP(i,B) cin >> q[i];
  REP(i,C) cin >> r[i];
  sort(ALL(p),greater<ll>());
  sort(ALL(q),greater<ll>());
  sort(ALL(r),greater<ll>());
  REP(i,X) r.push_back(p[i]);
  REP(i,Y) r.push_back(q[i]);
  sort(ALL(r),greater<ll>());
  REP(i,X+Y) ans += r[i];

  cout << ans;
  return 0;
}

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

#include <algorithm>
#include <array>
#include <chrono>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

#define ll long long
#define ld long double
#define P pair<ll, ll>
#define FOR(i, n, m) for (ll i = n; i < (ll)m; i++)
#define FORr(i, m, n) for (ll i = n; i >= (ll)m; i--)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define sortAl(v) sort(v.begin(), v.end())
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())
#define cout(n) cout << fixed << setprecision(n)

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

  string s;
  cin >> s;

  if (s[0] != 'A') {
    cout << "WA" << endl;
    return 0;
  }
  if (s[1] < 'a' || s[1] > 'z') {
    cout << "WA" << endl;
    return 0;
  }
  int c_cnt = 0;
  for (auto it = s.begin() + 2; it != s.end() - 1; it++) {
    if (*it == 'C') {
      c_cnt++;
    } else if (*it < 'a' || *it > 'z') {
      cout << "WA" << endl;
      return 0;
    }
  }

  if (s[s.size() - 1] < 'a' || s[s.size() - 1] > 'z') {
    cout << "WA" << endl;
    return 0;
  }

  if (c_cnt == 1) {
    cout << "AC" << endl;
  } else {
    cout << "WA" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N = int(input())
S = [input() for _ in range(N)]

import collections
name_frq_dict = collections.defaultdict(int)
for s in S:
    if s[0] in ['M', 'A', 'R', 'C', 'H']:
        name_frq_dict[s[0]] += 1


len_name_frq_dict = len(name_frq_dict)

if len_name_frq_dict < 3:
    print(0)
else:
    import itertools

    ans = 0
    names = list(name_frq_dict.keys())
    for part_names in itertools.permutations(names, 3):
        a = 1
        for n in part_names:
            a *= name_frq_dict[n]
        ans += a

    print(ans//6)




Measured memory_bytes: 57944
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#include <deque>
#define pb push_back
#define make make_pair
#define kaku(a) cout << a << endl
#define isort(a) sort(a.begin(),a.end())

using namespace std;

#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}

typedef pair<ll,ll> Pair;
typedef vector<ll> vecll;
const ll inf =1000000007;

auto compare = [](int a, int b) {
    return a < b;
};

void solve(){
    ll n,q;
    cin >> n >>q;
    priority_queue<pair<ll,Pair>> event;
    rep(i,n){
        ll s,t,x;
        cin >> s >> t >> x;
        event.push(make(inf-s+x,make(1,x)));
        event.push(make(inf-t+x,make(-1,x)));
    }

    ll hito[q];
    rep(i,q){
        cin >> hito[i];
    }
    ll r=event.size();
    multiset<ll> stop;
    map<ll,ll> mp;
    for(ll i=0;i<q;i++){
        //hito[i]について
        for(ll j=0;j<r;j++){
            pair<ll,Pair> b;
            if(event.empty()){
                break;
            }
            else{
                b=event.top();
                //cout <<"b.first="<< b.first << endl;
                if(inf-b.first>hito[i]){
                    break;
                }
                else{
                    if(b.second.first==1){
                        stop.insert(b.second.second);
                    }
                    else{
                        stop.erase(stop.find(b.second.second));
                        //cout << i <<" " << b.second.second<< endl;
                    }
                    event.pop();
                }
            }
        }
        if(stop.empty()){
            mp[i]=-1;
        }
        else{
            mp[i]=*stop.begin();
            //cout << i << " " <<*stop.begin() << endl;
        }
    }
    rep(i,q){
        cout << mp[i] << endl;
    }
}

int main(){
    solve();
}

Measured memory_bytes: 28136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define rep(i,n) for (int i=0; i<(n); i++)
#define reps(i,s,n) for (int i=(s); i<(n); i++)
#define rep1(i,n) for (int i=1; i<=(n); i++)
#define repr(i,s,n) for (int i=(s)-1; i>=(n); i--)
#define print(a) cout << (a) << endl
#define all(v) v.begin(), v.end()
#define rsort(v) sort(v.rbegin(), v.rend())


int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  bool c1 = (A<B);
  while (K>0) {
    if (c1) {
      C *= 2;
    } else {
      B *= 2;
      c1 = (A<B);
    }
    K--;
  }
  print((A<B&&B<C)?"Yes":"No");
  return 0;
}

Measured memory_bytes: 3596
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  auto n = readln.chomp.to!int;
  auto a = readln.chomp.split.to!(int[]);
  auto m = a.filter!("a % 2").array;
  if (m.length % 2) {
    writeln("NO");
  } else {
    writeln("YES");
  }
}


Measured memory_bytes: 4280
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int l = 4;
	int r = 317;
	int a, b;
	cin >> a >> b;
	int sum = a * pow(10, (to_string(b)).l_ength()) + b;
	for( int i = l; i < r; ++i ){
		if( sum == i*i ){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
program cm
   implicit none
   integer::N,M,Q
   integer,allocatable,dimension(:)::a,b,c,d
   integer,allocatable,dimension(:)::X
   integer::i
   integer::ans=0
   read*,N,M,Q
   allocate(a(Q),b(Q),c(Q),d(Q))
   do i=1,Q
      read*,a(i),b(i),c(i),d(i)
   end do
   allocate(X(1:N))
   X(1)=1
   call DFS(2)
   print"(I0)",ans
contains
recursive subroutine DFS(K)
   integer::K
   integer::i
   if(K==N+1)then
      ans=max(ans,calc())
      return
   endif
   do i=X(K-1),M
      X(K)=i
      call DFS(K+1)
   end do
end subroutine
integer function calc()
   integer::i
   calc=0
   do i=1,Q
      if(X(B(i))-X(A(i))==c(i))calc=calc+d(i)
   end do
end function
end program cm

Measured memory_bytes: 2872
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;
#define REP(i,n) for (int i = 0; i <(n); ++i)
//debug 
#ifdef _DEBUG
#define debug(var)  do{cout << #var << " :";view(var);}while(0)
#else
#define debug(...)
#endif
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vector<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vector<vector<T> >& vv){ for(const auto& v : vv){ view(v); } }


int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int l, r;
  l = max(a, c);
  r = min(b, d);

  int ans = r - l;
  if(ans <= 0) cout << 0 << endl;
  else cout << ans << endl;
  return 0;

}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int h,w;cin>>h>>w;
  ll c[10][10];
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++) cin>>c[i][j];
  }
  int a[h][w];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++) cin>>a[i][j];
  }
  for(int y=0;y<2;y++){
    for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      for(int k=0;k<10;k++){
        if(c[i][j]+c[j][k]<c[i][k]){
          c[i][k]=c[i][j]+c[j][k];
        }
      }
    }
  }
  }
  vector<ll>v(10);
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      for(int k=0;k<10;k++){
        if(a[i][j]==k) v[k]++;
      }
    }
  }
  ll sum=0;
  for(int i=0;i<10;i++)
    sum+=v[i]*c[i][1];
  cout<<sum<<endl;
}
  

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(){
  int x, y = 0;
  while(true){
    cin >> x >> y;
    if(!x){
      break;
    }
    for(int i = 0; x > i; i++){
      for(int j = 0; y > j; j++){
        cout << "#";
      }
      cout << endl;
    }
    cout << endl;
  }
}


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

int main(){
  int N;
  cin >> N;
  if(N%10 == 3){
    cout << "bon" <<endl;
  }
  else if(N%10 == 0 || N%10 == 1 || N%10 == 6 || N%10 == 8){
    cout << "pon" <<endl;
  }
  else{
    cout << "hon" <<endl;
  }
    
  
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;

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

  if(a == b) cout << c << endl;
  if(b == c) cout << a << endl;
  if(c == a) cout << b << endl;

  return 0;
}


Measured memory_bytes: 256
import logging

logging.basicConfig(level=logging.INFO)
logging.info('info')


def main():
    S = input()
    T = input()
    logging.info("hello")

    counter = 0

    for (s, t) in zip(S, T):
        if s != t:
            counter += 1

    print(counter)

if __name__ == "__main__":
    main()

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

using namespace std;

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

	vector <int> v;

	for (int i = 0; i < n; i++)
	{
		int input;
		cin >> input;
		v.push_back(input);
	}

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

	long long ans = 0;

	for (int i = 0; i < n-k; i++)
	{
		ans += v[i];
	}
	
	cout << ans;
	return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	map<tuple<int, int, int>, int> m;
	int count = 0, na = a, nb = b, nc = c;
	int ta, tb, tc;
	while(1)
	{
		if(m[make_tuple(na, nb, nc)])
		{
			cout << -1 << endl;
			break;
		}
		if(na % 2 == 1 || nb % 2 == 1 || nc % 2 == 1)
		{
			cout << count << endl;
			return 0;
		}
		m[make_tuple(na, nb, nc)] = 1;
		int ta = na;
		int tb = nb;
		int tc = nc;
		ta = nc / 2 + nb / 2;
		tb = na / 2 + nc / 2;
		tc = na / 2 + nb / 2;
		na = ta;
		nb = tb;
		nc = tc;
		++count;
	}
	return 0;
}

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

void solve(long long N, long long D, std::vector<long long> X, std::vector<long long> Y)
{

    ll ans = 0;
    for (ll i = 0; i < N; i++)
    {
        if (X[i] * X[i] + Y[i] * Y[i] <= D * D)
        {
            ans++;
        }
    }
    cout << ans << endl;
}

signed 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: 6424
function Main(input) {
    // N X T
    const [N, X, T] = input
        .trim()
        .split(' ')
        .map((v) => Number(v));

    const result = Math.ceil(N / X) * T;

    console.log(result);
    return;
}
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 29652
//AT-143-F-Distinct Numbers
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5+10;
const long long INF = 1e9+10;
typedef long long ll;
int n,cnt[maxn],ans[maxn],s;
ll prefix[maxn];
vector<int>mul;
inline int idxUB(ll x){
	return upper_bound(mul.begin(),mul.end(),x) - mul.begin();
}
bool judge(ll x,ll k){
	int idx = idxUB(x);
	return (prefix[idx-1]+(long long)x*(s-idx) >= x*k);
}
int main(){
	scanf("%d",&n);
	for(int i = 1;i <= n;i++){
		int tmp;
		scanf("%d",&tmp);
		cnt[tmp]++;
	}
	mul.push_back(0);
	for(int i = 1;i <= n;i++){
		mul.push_back(cnt[i]);
	}
	s = mul.size();
	sort(mul.begin(),mul.end());
	for(int i = 1;i <= s;i++)prefix[i] += (prefix[i-1] + mul[i]);
	ll now = 0;
	for(int k = n; k >= 1; --k) {
		while(now < n and judge(now+1,k))now++;
		ans[k] = now;
	}
	for(int i = 1;i <= n;i++)printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 6896
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String input = sc.next();
		if((input).equals("SAT")) {
			System.out.println("1");
			
		}else if((input).equals("SUN")){
			System.out.println("7");
			
		}else if((input).equals("MON")){
			System.out.println("6");
			
		}else if((input).equals("TUE")){
			System.out.println("5");
			
		}
		else if((input).equals("WED")){
			System.out.println("4");
			
		}else if((input).equals("THU")){
			System.out.println("3");
			
		}else if((input).equals("FRI")){
			System.out.println("2");
			
		}
	}
}
		

Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int N;
const int MAX_N = 100000;
char str[MAX_N+1];
char ans[MAX_N+2];

int solve(int N) {
    for (int i = 1; i <= N; i++) {
        if (ans[i] == 'S') {
            if (str[i] == 'o') ans[i+1] = ans[i-1];
            else {
                if(ans[i-1] == 'S') ans[i+1] = 'W';
                else ans[i+1] = 'S';
            }
        }
        else {
            if (str[i] == 'x') ans[i+1] = ans[i-1];
            else {
                if (i == 0) ans[i+1] = 'S';
                else if(ans[i-1] == 'S') ans[i+1] = 'W';
                else ans[i+1] = 'S';
            }
        }
    }
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    rep(i ,N) cin >> str[i+1];
    ans[0] = 'S';
    ans[1] = 'S';
    solve(N);
    /*
    dump(ans[0]);
    dump(ans[N]);
    rep(i, N) cout << ans[i+1];
    cout << endl;
    */
    if (ans[0] == ans[N] && ans[1] == ans[N+1]) {
        rep(i, N) cout << ans[i+1];
        cout << endl;
        return 0;
    }
    ans[0] = 'S';
    ans[1] = 'W';
    solve(N);
    if (ans[0] == ans[N] && ans[1] == ans[N+1]) {
        rep(i, N) cout << ans[i+1];
        cout << endl;
        return 0;
    }
    ans[0] = 'W';
    ans[1] = 'S';
    solve(N);
    if (ans[0] == ans[N] && ans[1] == ans[N+1]) {
        rep(i, N) cout << ans[i+1];
        cout << endl;
        return 0;
    }
    ans[0] = 'W';
    ans[1] = 'W';
    solve(N);
    if (ans[0] == ans[N] && ans[1] == ans[N+1]) {
        rep(i, N) cout << ans[i+1];
        cout << endl;
    } else {
        cout << "-1" << endl;
    }

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using lint = long long;
using namespace std;
const int MAXN = 2005;

int n, k;

int main(){
	string s;
	cin >> s;
	int ans = count(s.begin(), s.end(), 'o') + (15 - s.size());
	puts(ans >= 8 ? "YES" : "NO");
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <queue>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

int main(){
    ll N, X;
    cin >> N >> X;

    ll n = N-X;
    ll x = X;
    ll sum = N;
    ll remain = N-X;
    while(true){
        ll nnext = n % x; 
        sum += n/x * x * 2;
        if(nnext == 0){
            sum -= x; 
            break;
        }

        ll xnext = x % nnext;
        sum += x/nnext * nnext * 2;
        if(xnext == 0){
            sum -= nnext; 
            break;
        }

        x = xnext;
        n = nnext;
    }

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>
#include <functional>
#include <string>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <nmmintrin.h>
#include <chrono>
const double EPS = 1e-8;
#define Scan(a) int a;scanf("%d", &a);
#define ScanS(a) char a[500];scanf("%s", a);
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#ifdef _MSC_VER
#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}


signed main() {
	int n;
	cin >> n;
	vector<ll> a(n + 1);

	REP(i, n)
		scanf("%lld", &a[i + 1]);

	REP(i, n) {
		a[i + 1] += a[i];
	}
	ll ans = LLONG_MAX;
	REP(i, n - 1) {
		ans = min(ans, abs(a[n] - a[i + 1] * 2));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int r = Integer.parseInt(sc.next());
        int answer = 0;
        if (n >= 10) {
            answer = r;
        } else {
            answer = r + (100 * (10 - n));
        }
        System.out.println(answer);
        sc.close();
    }
}


Measured memory_bytes: 35552
#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"
//#include <intrin.h>  //AtCoder (gcc) 上ではこれがあると動かない。__popcnt用のincludeファイル。
using namespace std;
using Graph = vector<vector<int>>;

typedef long long ll;
typedef long double ld;


#define int long long
#define rep(i, n) for(long long i = 0; i < (n); i++)
#define sqrt(d) pow((long double) (d), 0.50)

const int INF = 2e9;
const ll large_P = 1e9 + 7;



//繰り返し2乗法
//N^aの、Mで割った余りを求める。
ll my_pow(ll N, ll a, ll M) {
	ll tempo;
	if (a == 0) {
		return 1;
	}
	else {
		if (a % 2 == 0) {
			tempo = my_pow(N, a / 2, M);
			return (tempo * tempo) % M;
		}
		else {
			tempo = my_pow(N, a - 1, M);
			return (tempo * N) % M;
		}
	}
}



//N_C_a を M で割った余り
ll my_combination(ll N, ll a, ll M) {
	ll answer = 1;

	rep(i, a) {
		answer *= (N - i);
		answer %= M;
	}

	rep(i, a) {
		answer *= my_pow(i + 1, M - 2, M);
		answer %= M;
	}

	return answer;
}



ll my_gcd(ll& a, ll& b) {
	if (b == 0) return a;
	ll temp = a % b;
	return my_gcd(b, temp);
}



// long long型 n を、base 進法での、i 桁目の数が入った vector にする。
void ll_to_vector(ll base, ll n, vector<ll>& v) {
	ll tempo = n;

	ll n_digit = floor(log10(n) / log10(base)) + 1;
	v.assign(n_digit, 0);

	//ll n_digit = v.size();

	for (ll i = 0; i < n_digit; i++) {
		v.at(i) = tempo / pow(base, n_digit - 1 - i);
		tempo -= v.at(i) * pow(base, n_digit - 1 - i);
	}
}



int char_to_int(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4;
	case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9;
	default: return 0;
	}
}


//target が素数かどうか判定する。
void prime_judge(vector<bool>& prime_or_not) {

	prime_or_not.at(0) = false;
	prime_or_not.at(1) = false;

	ll n = prime_or_not.size() - 1;
	ll region = sqrt(n) + 1;

	for (ll i = 2; i <= n / 2; i++) {
		prime_or_not.at(2 * i) = false;
	}


	for (ll i2 = 1; i2 < n / 2; i2++) {
		ll i = 2 * i2 + 1;  //ここからは奇数のみ探索
		if (i < region && prime_or_not.at(i)) {
			ll j = i * i;
			while (j < n + 1) {
				prime_or_not.at(j) = false;
				j += 2 * i;
			}
		}
	}
};


const int max_D = 200;
const int max_N = 200;

//派手さの差の絶対値を保持。
//第一変数は、最後に着た服の種類。第二変数は、日付。
int dp[max_N+1][max_D+1];


void solve(vector<int> A, vector<int> B, vector<int> C, vector<int> T) {
	int N = A.size();
	int D = T.size();

	rep(j, D) {
		rep(i, N) {
			if (T.at(j) < A.at(i) || B.at(i) < T.at(j)) dp[i][j] = -INF;  // j 日目に i 番目の服は着られない。
			else if (j != 0) {
				int tempo = dp[0][j - 1] + abs(C.at(0) - C.at(i));
				rep(k, N) {
					if (tempo < dp[k][j - 1] + abs(C.at(k) - C.at(i))) {
						tempo = dp[k][j - 1] + abs(C.at(k) - C.at(i));
					}
				}
				dp[i][j] = tempo;
			}
		}
	}
}



signed main() {
	int D, N;
	cin >> D >> N;

	vector<int> T(D);
	rep(i, D) cin >> T.at(i);

	vector<int> A(N), B(N), C(N);
	rep(i, N) cin >> A.at(i) >> B.at(i) >> C.at(i);

	solve(A, B, C, T);

	int res = dp[0][D-1];
	rep(i, N) {
		if (res < dp[i][D-1]) res = dp[i][D-1];
	}

	cout << res << endl;

	//rep(i, N) {
		//rep(j, D) {
			//cout << dp[i][j] << " ";
		//}
		//cout << endl;
	//}

}


Measured memory_bytes: 3460
#include <stdio.h>
#include <string.h>

char tar[][11] = {
    "KIHBR",
    "KIHBRA",
    "KIHBAR",
    "KIHABR",
    "AKIHBR",
    "KIHBARA",
    "KIHABRA",
    "KIHABAR",
    "AKIHBRA",
    "AKIHBAR",
    "AKIHABR",
    "KIHABARA",
    "AKIHABAR",
    "AKIHABRA",
    "AKIHBARA",
    "AKIHABARA",
    };

int main() {

    int i;
    char str[100];

    scanf("%s",str);

    for(i = 0;i < 16;i++){
        if(strcmp(tar[i],str) == 0) {
            puts("YES");
            return 0;
        }
    }

    puts("NO");
    return 0;
}

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

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

		while (true) {
			final int m = sc.nextInt();
			final int f = sc.nextInt();
			final int r = sc.nextInt();
			
			if(m == -1 && f == -1 && r == -1){
				break;
			}
			
			if (m == -1 || f == -1) {
				System.out.println("F");
			} else if (m + f >= 80) {
				System.out.println("A");
			} else if (m + f >= 65) {
				System.out.println("B");
			} else if (m + f >= 50) {
				System.out.println("C");
			} else if (m + f >= 30) {
				if (r >= 50) {
					System.out.println("C");
				} else {
					System.out.println("D");
				}
			} else {
				System.out.println("F");
			}
		}
	}

}

Measured memory_bytes: 19220
use std::io::*;

fn reads<T: std::str::FromStr>(i: &mut StdinLock) -> Vec<T> {
    let mut s = String::new();
    i.by_ref().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn abs(val: i64) -> i64 {
    std::cmp::max(-1 * val, val)
}

fn main() {
    // initialize stdin
    let sin = std::io::stdin();
    let mut sin = sin.lock();
    let sin = &mut sin;

    let mut inputs: Vec<i64> = reads(sin);

    inputs.sort();

    let mut inputs: Vec<i64> = inputs.into_iter().rev().collect();

    let first = inputs.pop().unwrap();

    let ans = inputs
        .into_iter()
        .rev()
        .fold((0, first), |(total, hitotsumae), x| {
            (total + abs(hitotsumae - x), x)
        });

    println!("{}", ans.0);
}


Measured memory_bytes: 4352