akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
#include <deque>
#include <queue>
#include <list>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
	int n;
    cin >> n;
    vector <ll> a(n), b(n);
    for (int i = 0 ; i < n ; i++) cin >> a[i];
    b = a;
    sort (b.begin(), b.end());
    int c = (n - 2) / 2;
    for (int i = 0 ; i < n ; i++) {
        if (a[i] <= b[c]) cout << b[c + 1] << endl;
        else cout << b[c] << endl;
    }
}
/*
*/

Measured memory_bytes: 6424
import sys 

def A():
  n = int(sys.stdin.readline().rstrip())
  charge = (n+999)//1000 * 1000 - n
  print(charge)


from collections import Counter
def B():
  n, *s = sys.stdin.read().split() 
  c = Counter(s)
  for v in 'AC, WA, TLE, RE'.split(', '):
    print(f'{v} x {c[v]}')


def C():
  h, w, k = map(int, sys.stdin.readline().split())
  c = [sys.stdin.readline().rstrip() for _ in range(h)]
  tot = 0
  for i in range(1<<h):
    for j in range(1<<w):
      cnt = 0
      for y in range(h):
        for x in range(w):
          if i>>y & 1 or j>>x & 1:
            continue 
          cnt += c[y][x] ==  '#'
      tot += cnt == k
  print(tot)


def D():
  n, *a = map(int, sys.stdin.read().split())
  a.sort(reverse=True)
  res = a[0] + sum(a[1:1+(n-2)//2])*2 + a[1+(n-2)//2]*(n & 1)
  print(res)


def E():
  pass


def F():
  pass

if __name__ == "__main__":
  # A() 
  # B()
  # C()
  D()
  E()
  F()

Measured memory_bytes: 31800
#include <bits/stdc++.h>
using namespace std;
#define R(i,n) for(int i=0;i<n;i++)
using V=vector<int>;

signed main(){
    int n,a=1e9,c[2][20];
    cin>>n;
    R(i,n)cin>>c[0][i];
    R(i,n)cin>>c[1][i];
    vector<V> p(1<<n,V(51,1e9));
    p[0][0]=0;
    R(B,1<<n){
        int o=0,d[n];
        R(i,n)if(!(B&1<<i))d[i]=o++;
        R(i,n){
            int k=abs(i-n+o);
            R(j,c[k%2][i]+1)p[B|1<<i][c[k%2][i]]=min(p[B|1<<i][c[k%2][i]],p[B][j]+d[i]);
        }
    }
    R(i,51)a=min(a,p[(1<<n)-1][i]);
    cout<<(a==1e9?-1:a);
}

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

int main() {

    int N;
    cin >> N;
    string S[N];
    for (int i = 0; i < N; i++) {
        cin >> S[i];
    }

    int C[2][2] = {{0,0},{0,0}};
    for (int i = 0; i < N; i++) {
        if (S[i] == "AC") {
            C[0][0]++;
        } else if (S[i] == "WA") {
            C[0][1]++;
        } else if (S[i] == "TLE") {
            C[1][0]++;
        } else if (S[i] == "RE") {
            C[1][1]++;
        }
    }

    printf("AC x %d\n", C[0][0]);
    printf("WA x %d\n", C[0][1]);
    printf("TLE x %d\n", C[1][0]);
    printf("RE x %d\n", C[1][1]);

}

Measured memory_bytes: 6852
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;

int N;
Graph G;
vector<int> X, Y;

bool dfs(int v) {
    for(auto nv : G[v])
        if(!dfs(nv))
            return false;
    int gsize = G[v].size();
    if(gsize == 0)
        return true;

    // dpを　する
    vector<vector<int>> dp(gsize + 1, vector<int>(X[v] + 3, INF));
    dp[0][0] = 0;
    for(int i = 0; i < gsize; ++i) {
        int nv = G[v][i];
        for(int j = X[v]; j >= 0; --j) {
            if(j >= X[nv])
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - X[nv]] + Y[nv]);
            if(j >= Y[nv])
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - Y[nv]] + X[nv]);
        }
    }
    Y[v] = INF;
    for(int i = X[v]; i >= 0; --i) {
        if(dp[gsize][i] != INF) {
            Y[v] = dp[gsize][i];
            return true;
        }
    }
    return false;
}

int main() {
    cin >> N;
    G.resize(N), X.resize(N), Y.resize(N);
    for(int i = 1; i < N; ++i) {
        int P;
        cin >> P;
        P--;
        G[P].push_back(i);
    }
    for(int i = 0; i < N; ++i)
        cin >> X[i];
    cout << (dfs(0) ? "POSSIBLE" : "IMPOSSIBLE") << endl;
    return 0;
}


Measured memory_bytes: 1352
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
#include <stack>
#include <functional>
using ll = long long;
using namespace std;
int main() {
	ll n, m, l, k;
	cin >> n >> m >> l >> k;
	for (int i = 0; i < k; i++)
		if (max({ n, m, l }) == n)
			n *= 2;
		else if (max({ n, m, l }) == m)
			m *= 2;
		else
			l *= 2;
	cout << n + m + l << endl;
	return 0;
}

Measured memory_bytes: 256
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
#define PI             acos(-1.0)
#define IOS            ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ms(a,b)         memset(a, b, sizeof(a))
#define filein      freopen("input.txt", "r", stdin);
#define fileout     freopen("output.txt", "w", stdout);
#define debug       cout<<"Hello, i am in here."<<endl;
#define bit_cnt(mask) __builtin_popcountll(mask)
#define ll long long int
#define dst(u,v,x,y) sqrt((x*1.0-u*1.0)*(x*1.0-u*1.0)+(y*1.0-v*1.0)*(y*1.0-v*1.0))
using namespace std;
const int MOD = (int)1e9+7;
/*-----------------------Bitmask------------------*/
//int Set(int N,int pos){return N=N | (1<<pos);}
//int reset(int N,int pos){return N= N & ~(1<<pos);}
//bool check(int N,int pos){return (bool)(N & (1<<pos));}
/*------------------------------------------------*/
void solve()
{
  ll a;
  cin>>a;
  cout<<a+(a*a)+(a*a*a)<<endl;
}
int  main()
{
    IOS
    solve();
    return 0;
}


Measured memory_bytes: 3636
n,k = map(int,input().split())
mod = 10**9+7
def cmb(n, r, mod=mod):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % mod

N = 2001  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod mod)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod mod)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    factinv.append((factinv[-1] * inv[-1]) % mod)


move = []
red = n-k
for i in range(1,k+1):
    blue = i
    ans = cmb(red+1,blue)*cmb(k-1,blue-1)
    move.append(ans%mod)

for i in move:
    print(i)

Measured memory_bytes: 42608
#include<bits/stdc++.h>
#define int ll
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
//const int inf = 0x3f3f3f3f;
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define pc putchar
//#define gc getchar
#define fi first
#define se second
#define debug(x) cout << #x" = " << x << endl;
#define pp(x,y) cout << "pp: " << x << " " << y << endl;
#define gc getchar
#define rank __RAmaxnK
inline ll read(){
    register ll x=0,f=1;register char c=gc();
    for(;!isdigit(c);c=gc())if(c=='-')f=-1;
    for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
    return x*f;
}
#define rd read
void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);putchar(x%10+'0');}
void writeln(ll x){write(x);puts("");}
const ll maxn=800010;
pii mx[maxn],mn[maxn],a[10];
ll n,all,ans[maxn];
bool cmp(pii a,pii b){return a.fi==b.fi?(a.se<b.se):(a.fi>b.fi);}
void merge(ll x,ll y){
	a[1]=mx[x];a[2]=mn[x];a[3]=mx[y];a[4]=mn[y];
	sort(a+1,a+5,cmp);
	ll pos=0;
	mx[x]=mn[x]=pii(0,0);
	Rep(i,1,4)if (a[i].se!=a[i-1].se){
		if (pos==0)mx[x]=a[i],pos=1;
		else if (pos==1)return mn[x]=a[i],void(0);
	}
}
signed main(){
	n=read();all=(1<<n)-1;
	Rep(i,0,all)mx[i]=pii(rd(),i+1);
	Rep(i,1,all)rep(j,0,n)if (i>>j&1){
		merge(i,i^(1<<j));
	}
	Rep(i,1,all)ans[i]=max(ans[i-1],mx[i].fi+mn[i].fi);
	Rep(i,1,all)writeln(ans[i]);
}

Measured memory_bytes: 19456
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;

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

ll max(ll a, ll b) {return a > b ? a : b;}
ll max(int a, ll b) {return a > b ? a : b;}
ll max(ll a, int b) {return a > b ? a : b;}
ll max(int a, int b) {return a > b ? a : b;}

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()

int n, m;
double dp[1000];
double dp2[1000];
vector<int> go[1000];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int v, u;
        cin >> v >> u;
        go[v].push_back(u);
    }
    for (int i = n - 1; i >= 1; i--)
    {
        for (auto e : go[i]) dp[i] += dp[e];
        dp[i] /= go[i].size();
        dp[i] += 1;
    }
    double ans = dp[1];
    for (int i = n - 1; i >= 1; i--)
    {
        if (go[i].size() != 1)
        {
            for (int j = 1; j <= i; j++) dp2[j] = 0;
            for (int j = i + 1; j <= n; j++) dp2[j] = dp[j];
            double mx = 0;
            for (auto e : go[i]) dp2[i] += dp[e], mx = std::max(mx, dp[e]);
            dp2[i] -= mx;
            dp2[i] /= (go[i].size() - 1);
            dp2[i] += 1;
            for (int j = i - 1; j >= 1; j--)
            {
                for (auto e : go[j]) dp2[j] += dp2[e];
                dp2[j] /= go[j].size();
                dp2[j] += 1;
            }
            ans = std::min(ans, dp2[1]);
        }
    }
    printf("%.9f", ans);
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
bool dp[88][88][88*176];
ll r[88][88],b[88][88];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll h,w;cin>>h>>w;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      cin>>r[i][j];
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      cin>>b[i][j];
  dp[0][0][0] = true;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      ll sa = abs(r[i][j]-b[i][j]);
      for(int k=0;k<88*176;k++){
	if(dp[i][j][k]){
	  dp[i+1][j][k+sa] = true;
	  dp[i][j+1][k+sa] = true;
	  dp[i+1][j][abs(k-sa)] = true;
	  dp[i][j+1][abs(k-sa)] = true;
	}
      }
    }
  }
  ll ans = llINF;
  ll sa = abs(r[h-1][w-1]-b[h-1][w-1]);
  for(int i=0;i<88*176;i++){
    if(dp[h-1][w-1][i]){
      ans = min(ans,abs(i-sa));
      ans = min(ans,abs(i+sa));
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 107648
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    string s;
    cin>>s;
    ll n=(ll)s.size();

    //できるだけパーを出すのが最善
    //パーでしか勝てるチャンスがないのだからgpgpgp...が最善に見える
    ll ans=0;
    rep(i,n){
        char hand=i%2?'p':'g';
        if(s[i]==hand){
            continue;
        }
        if(hand=='p') ans++;
        else ans--;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
#include<stdio.h>
#include<queue>
#include <cmath>
#include<bits/stdc++.h>
#include<math.h>
//for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<n;i++) cin >> x[i];
#define pi pair<int,int> 
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(){
    ll r,l; cin >> l >> r;
    if((r-l+1)>=2019) cout << '0';

    else {
         int lmod = l % 2019;
         int rmod = r % 2019;
      
         if(lmod >= rmod) cout << '0';

         else{
             int ans = 2020;
             for(int i=lmod;i<rmod;i++){
                 for(int j=i+1;j<=rmod;j++){
                     int k = (i*j) % 2019;
                     chmin(ans,k);
                 }
             }
             cout << ans;
         }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
#include <set>
#include <cmath>
#include <cassert>
using namespace std;

int cumsum[666][666];
int cumsum2[666][666];

int main(){
    int H, W;
    cin >> H >> W;
    vector<string> s(H);
    for(int i=0; i<H; i++)
        cin >> s[i];

    vector<vector<int>> coins(H+W+1);
    vector<vector<int>> coins2(H+W+1);
    for(int i=1; i<=H; i++){
        for(int j=1; j<=W; j++){
            if(s[i-1][j-1] == '#'){
                cumsum[i+j][W+i-j] = 1;
                cumsum2[W+i-j][i+j] = 1;
                coins[i+j].push_back(W+i-j);
                coins2[W+i-j].push_back(i+j);
            }
        }
    }
    for(int i=0; i<=H+W; i++)
        for(int j=1; j<=H+W; j++)
            cumsum[i][j] += cumsum[i][j-1];

    for(int i=0; i<=H+W; i++)
        for(int j=1; j<=H+W; j++)
            cumsum2[i][j] += cumsum2[i][j-1];

    long long ans = 0;
    for(int i=0; i<=H+W; i++){
        int sz = coins[i].size();
        for(int j=0; j<sz; j++){
            for(int k=j+1; k<sz; k++){
                int bot = coins[i][j];
                int top = coins[i][k];
                int dist = top - bot;
                int lef = i - dist;
                if(lef >= 0){
                    ans += cumsum[lef][top] - cumsum[lef][bot-1];
                }
                int rig = i + dist;
                if(rig <= H+W){
                    ans += cumsum[rig][top] - cumsum[rig][bot-1];
                }
            }
        }
    }

    for(int i=0; i<=H+W; i++){
        int sz = coins2[i].size();
        for(int j=0; j<sz; j++){
            for(int k=j+1; k<sz; k++){
                int bot = coins2[i][j];
                int top = coins2[i][k];
                int dist = top - bot;
                int lef = i - dist;
                if(lef >= 0){
                    ans += cumsum2[lef][top-1] - cumsum2[lef][bot];
                }
                int rig = i + dist;
                if(rig <= H+W){
                    ans += cumsum2[rig][top-1] - cumsum2[rig][bot];
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4608
n=0
while True:
    a,b = map(int,raw_input().split())
    if (a,b)==(0,0): break
    if n>0: print ''
    ls=[i for i in range(a,b+1)]
    ans=[]
    for j in ls:
        if j%4==0 and j%100!=0:
            ans.append(j)
        elif j%400==0:
            ans.append(j)
    
    if ans==[]:
        print 'NA'
    else:
        for y in ans:
            print y
    n+=1

Measured memory_bytes: 4372
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int x, y; cin >> x >> y;
    vector<int> a = {0, 0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0};
    string ans = a[x] == a[y] ? "Yes" : "No";
    cout << ans << endl;
    return 0;
}

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

typedef struct restaurant {
	char name[11];
	int P;
	int num;
} restaurant;

int compare_string(const void *a, const void *b) {
  	return strcmp(((restaurant*)a)->name, ((restaurant*)b)->name);
}

int compare_int(const void *a, const void *b) {
	return ((restaurant*)b)->P - ((restaurant*)a)->P;
}

int main() {
	int N;
	scanf("%d",&N);
	restaurant S[N];
	for (int i = 0; i < N; i++) {
		scanf("%s %d",&S[i].name[0],&S[i].P);
		S[i].num = i + 1;
	}
	
	qsort(S, N, sizeof(restaurant), compare_int);
	qsort(S, N, sizeof(restaurant), compare_string);
	
	for (int i = 0; i < N; i++) {
		printf("%d\n",S[i].num);
	}

	return 0;
}

Measured memory_bytes: 128
/*input

*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define int long long
#define N

int n;
int sum = 0;
int diff = 1e18;
signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int t; cin >> t;
		if (t % 10 != 0) {
			diff = min(diff, t);
		}
		sum += t;
	}
	if (sum % 10) {
		cout << sum << endl;
	}
	else {
		if (diff <= 200) {
			cout << sum - diff << endl;
		}
		else cout << 0 << endl;
	}
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;

int main(int argc, const char * argv[]) {
    string a, b, c;
    
    cin >> a >> b >> c;
    
    cout << a[0] << b[0] << c[0] << endl;

    

    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int small(int,int);
int large(int,int);
int main (){
  int a,b,c;
  scanf("%d%d",&a,&b);
  if(b > a){
    c=a;
    a=b;
    b=c;
  }
  while(1){
    if(a%b==0)break;
    c=b;
    b=a%b;
    a=c;
  }
  printf("%d\n",b);
    
  return 0;
}



Measured memory_bytes: 2112
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func powInt(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	if x == 2 {
		return true
	}
	if x%2 == 0 {
		return false
	}

	b := true
	rootx := int(math.Sqrt(float64(x)))
	i := 3
	for i <= rootx {
		if x%i == 0 {
			b = false
			break
		}
		i += 2
	}
	return b
}

func PrimeFactors(n int) (pfs []int) {
	// Get the number of 2s that divide n
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs = append(pfs, n)
	}

	return
}

func sumInts(x []int) int {

	total := 0
	for _, v := range x {
		total += v
	}

	return total
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var X, Y int

func main() {
	sc.Split(bufio.ScanWords)

	X, Y = nextInt(), nextInt()
	a, b := -1, -1

	diff := Y - X*2 //全部鶴だとするとdiff本足りない
	b = diff / 2
	a = X - b

	if a*2+b*4 == Y && a >= 0 && b >= 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define pii pair<int, int>
#define vc vector
#define a first
#define b second
#define pb pusu_back
#define INF (1000000000)
#define MOD (1000000007)
#define MAX (100000)

/////////////////////////////////////////////////////////

class XY{
public:
  ll x, y;
  XY() {x = y = 0;}
  XY(ll u, ll v) {x = u; y = v;}
};

template<typename T1, typename T2>
void chmin(T1 &a, T2 b) {if(a > b) a = b;}
template<typename T1, typename T2>
void chmax(T1 &a, T2 b) {if(a < b) a = b;}

template<typename T1, typename T2>
ll mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  ll tmp = mypow(a, n / 2);
  return tmp * tmp;
}

template<typename T>
int BS(vector<T> &V, int left, int right, T key){
  int mid = (left + right) / 2;
  if(V[mid] <= key) left = mid;
  else right = mid;
  if(right - mid == 1) return left;
  else return BS(V, left, right, key);
}

ll comb(ll n, ll r){
	ll res = 1;
  rep(i, 0, r){
    res *= n - i;
    res /= i + 1;
  }
  return res;
}

template<typename T>
T euclid(T a, T b){
  if(b == 0) return a;
  else return euclid(b, a % b);
}

vector<ll> fact(MAX, 0), fact_inv(MAX, 0);

/////////////////////////////////////////////////////////

//MOD of Combination

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

void prepare_comb_mod(ll n){
	fact[0] = 1LL;
	for(ll i = 0; i < n; i++) fact[i+1] = fact[i] * (i + 1) % MOD;
	fact_inv[n] = pow_mod(fact[n], MOD - 2);
	for(ll i = n - 1; i >= 0; i--) fact_inv[i] = fact_inv[i + 1] * (i + 1) % MOD;
}

ll comb_mod(ll n, ll r){
	return (fact[n] * fact_inv[r]) % MOD * fact_inv[n - r] % MOD;
}

/////////////////////////////////////////////////////////

//Union-Find Tree

int UFT_par[MAX];
int UFT_rank[MAX];

void UFT_init(int n){
  rep(i, 0, n){
    UFT_par[i] = i;
    UFT_rank[i] = 0;
  }
}

int UFT_find(int x){
  if(UFT_par[x] == x){
    return x;
  }else{
    return UFT_par[x] = UFT_find(UFT_par[x]);
  }
}

void UFT_unite(int x, int y){
  x = UFT_find(x);
  y = UFT_find(y);
  if(x == y) return;
  if(UFT_rank[x] < UFT_rank[y]){
    UFT_par[x] = y;
  }else{
    UFT_par[y] = x;
    if(UFT_rank[x] == UFT_rank[y]) UFT_rank[x]++;
  }
}

bool UFT_same(int x, int y){
  return UFT_find(x) == UFT_find(y);
}

/////////////////////////////////////////////////////////

void Main() {
  int N; cin >> N;
  vc<int> A(N);
  rep(i, 0, N) cin >> A[i];
  ll res = 0;
  int l, r;
  l = r = 0;
  int tmp = 0;
  while(l < N){
    while(true){
      if(r != N && (tmp & A[r]) == 0){
        tmp ^= A[r];
        r++;
        res++;
      }else{
        tmp ^= A[l];
        l++;
        res += r - l;
        break;
      }
    }
  }
  cout << res << endl;
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << std::fixed << std::setprecision(15);

  Main();
}


Measured memory_bytes: 2560
#include <cstdio>
#include <iostream>
#include <cstring>

typedef long long ll;

ll a[101000], b[101000], ans = 0;

int main()
{
	int n; scanf("%d", &n);
	for(int i = 0; i <= n; i++) scanf("%lld", &a[i]);
	for(int i = n; i >= 0; i--)
	{
		b[i] = (b[i + 1] + 1) / 2 + a[i];
		ans += b[i];
	}
	if(b[0] > 1) return 0 * puts("-1");
	ll w = 0, cnt = 0; int j = 0;
	for(int i = n; i >= 0; i--)
	{
		while(j < i && w + b[i] / 2 > cnt)
		{
			ans += cnt - w;
			j++;
			cnt = cnt * 2 + (b[j] & 1);
		}
		if(j >= i) break;
		w += b[i] / 2;
		ans += (i - j) * (b[i] / 2);
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 5332
#include "iostream"
#include "iomanip"
#include "vector"
#include "algorithm"

using namespace std;
const int inf = (int)1e9;

int main() {
  int n;
  cin >> n;
  vector<int> t(n), a(n);
  vector<int> rt(n);
  vector<vector<int>> acum(n + 1, vector<int> (8));
  for (int i = 0; i < n; ++i) {
    cin >> t[i] >> a[i];
    if (i == 0) acum[i][a[i]] = 1;
    else {
      for (int j = 0; j < 8; ++j) {
        if (j == a[i]) acum[i][j] = acum[i - 1][j] + 1;
        else acum[i][j] = acum[i - 1][j];
      }
    }
  }
  for (int i = 0; i < 8; ++i) {
    acum[n][i] = acum[n - 1][i];
  }
  for (int i = 0; i < n; ++i) {
    rt[i] = -t[n - i - 1];
  }
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    int itrl = lower_bound(t.begin(), t.end(), l) - t.begin();
    int itrr = lower_bound(rt.begin(), rt.end(), -r) - rt.begin();
    if (itrr == n || itrl == n) {
      cout << inf << endl;
      continue;
    }
    itrr = n - itrr - 1;
    double res = inf;
    for (int i = 1; i < 8; ++i) {
      int cnt = 0;
      if (itrl == 0) {
        cnt = acum[itrr][i];
      } else {
        cnt = acum[itrr][i] - acum[itrl - 1][i];
      }
      double k = 1.0 * (10 - i) / 10;
      while (cnt) {
        if (cnt & 1) res *= k;
        k *= k;
        cnt /= 2;
      }
    }
    cout << setprecision(20) << res << endl;
  }
  return 0;
}


Measured memory_bytes: 11064
#include<bits/stdc++.h>
#define pb push_back
#define int long long
using namespace std;
int f(int x)
{
	if(x%4 == 0) return x;
	if(x%4 == 1) return 1;
	if(x%4 == 2) return x+1;
	if(x%4 == 3) return 0;
}
int32_t main()
{
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int a,b;
    cin >> a >> b;
    cout << (int)(f(b)^f(a-1)) << "\n";
	return 0;
}

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

template <typename T, typename E>
class LazySegTree {
private:
    int n;
    vector<T> data;
    T idT;
    vector<E> lazy;
    E idE;
    function<T(T, T)> merge;
    function<T(T, E)> operate;
    function<E(E, E)> compose;
    function<E(E, int)> power;

    void eval(int k, int len) {
        if(lazy[k] == idE) return;
        if(2 * k + 1 < 2 * n - 1) {
            lazy[2 * k + 1] = compose(lazy[2 * k + 1], lazy[k]);
            lazy[2 * k + 2] = compose(lazy[2 * k + 2], lazy[k]);
        }
        data[k] = operate(data[k], power(lazy[k], len));
        lazy[k] = idE;
    }

    void _update(int a, int b, E x, int k, int l, int r) {
        eval(k, r - l);
        if(r <= a || b <= l) return;
        if(a <= l && r <= b) {
            lazy[k] = compose(lazy[k], x);
            return;
        }
       _update(a, b, x, 2 * k + 1, l, (l + r) / 2);
       _update(a, b, x, 2 * k + 2, (l + r) / 2, r);
    }

    T _query(int a, int b, int k, int l, int r) {
        eval(k, r - l);

        if(r <= a || b <= l) return idT;
        if(a <= l && r <= b) return data[k];
        
        T vl = _query(a, b, 2 * k + 1, l, (l + r) / 2);
        T vr = _query(a, b, 2 * k + 2, (l + r) / 2, r);
        if(2 * k + 1 < 2 * n - 1) data[k] = merge(data[2 * k + 1], data[2 * k + 2]);
        return merge(vl, vr);
    }

    public:
    LazySegTree(int _n, T _idT, E _idE, function<T(T, T)> _merge,
    function<T(T, E)> _operate, function<E(E, E)> _compose, function<E(E, int)> _power)
    : idT(_idT), idE(_idE), merge(_merge), operate(_operate), compose(_compose), power(_power) {
        n = 1;
        while(n < _n) n <<= 1;
        data = vector<T>(2 * n - 1, idT);
        lazy = vector<E>(2 * n - 1, idE);
    }

    void update(int a, int b, E x) {
        _update(a, b, x, 0, 0, n);
    }

    T query(int a, int b) {
        return _query(a, b, 0, 0, n);
    }

    T operator[](int k) {
        return data[k + n - 1];
    }
};

const long long INF = 1001001001001001001;

int main() {
    int N, M; cin >> N >> M;
    vector<int> L(M), R(M);
    vector<long long> C(M);
    for(int i=0; i<M; ++i) {
        cin >> L[i] >> R[i] >> C[i];
        --L[i];
    }
    
    vector<int> order;
    for(int i=0; i<M; ++i) order.push_back(i);
    sort(begin(order), end(order), [&](int a, int b){ return L[a] < L[b]; });

    LazySegTree<long long, long long> tree(N, INF, INF,
    [](long long a, long long b){return min(a, b);}, 
    [](long long a, long long b){return min(a, b);},
    [](long long a, long long b){return min(a, b);},
    [](long long a, long long b){return a;});

    tree.update(0, 1, 0);
    for(int i : order) {
        long long dist = tree.query(L[i], L[i] + 1);
        if(dist == INF) continue;
        tree.update(L[i] + 1, R[i], dist + C[i]);
    }

    long long res = tree.query(N - 1, N);
    if(res == INF) cout << -1 << endl;
    else cout << res << endl;
}

Measured memory_bytes: 6392
#include <stdio.h>
int main(void){
  int N;
  int l[100000],r[100000];
  int i;
  int sum=0;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d%d",&l[i],&r[i]);
    sum+=(r[i]-l[i]+1);
  }
  printf("%d\n",sum);
  return(0);
}

Measured memory_bytes: 128
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N, sum = 0, sum1 = 0, sum2 = 0;
	cin >> N;
	VI A(N);
	REP(i, N) {
		cin >> A[i];
		sum += A[i];
	}
	for (int i = 2; i < N; i += 2) {
		A[i] += A[i - 2];
	}
	for (int i = 3; i < N; i += 2) {
		A[i] += A[i - 2];
	}

	REP(i, N) {
		int a = 0;
		if (i % 2) {
			a += A[N - 1];
			a -= A[i - 1];
			if (i >= 2)a += A[i - 2];
		}
		else {
			a += A[N - 2];
			if(i!=0)a -= A[i - 1];
			if (i >= 2)a += A[i - 2];
		}

		if (i == N - 1) {
			cout << (sum / 2 - a) * 2 << endl;
			break;
		}
		cout << (sum/2-a)*2 <<" ";
	}
	
	return 0;
}



Measured memory_bytes: 2176
#include <iostream>
#include <cstdlib>
#include <cstdio>

using namespace std;

int main(void)
{
	// itoa
	int n;
	while (cin >> n, n){
		char s[20];
		sprintf(s, "%o", n);
		
		string str = s;
		for (int i = 0; i < str.length(); i++){
			if ('4' <= str[i]) str[i]++;
			if ('6' <= str[i]) str[i]++;
		}
		cout << str << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
struct _IO{_IO(){ios::sync_with_stdio(0);cin.tie(0);}}_io;
typedef long long ll; typedef long double db;
const int N = 5e5 + 5, M = 1e9 + 7;

int main() {
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i < s.size(); i++) {
    if (i > 0 && s[i] != s[i-1]) {
      ans++;
    }
  }
  cout << ans;
}


Measured memory_bytes: 3712
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>V[I]
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>V1[I]>>V2[I];
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>V1[I]>>V2[I]>>V3[I];
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T>inline T lcm(T a,T b){return a*b/gcd(b,a%b);}
long N,M,i,ans;
vector<long> X,D;
inline void solve(){
  IN2(N,M);
  X.resize(M);
  INS(i,M,X);
  if(N>=M){
    OUT(0);
    return;
  }
  sort(ALL(X));
  D.resize(M-1);
  REP(i,M-1){
    D[i]=X[i+1]-X[i];
  }
  sort(ALL(D));
  REP(i,M-N){
    ans+=D[i];
  }
  OUT(ans);
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(void)
{
  	int a, b, c, d;
  
	scanf("%d%d%d%d", &a, &b, &c, &d);

	if (a+b<c+d) 
      printf("Right\n");
  	else if (a+b>c+d)
      printf("Left\n");
	else
      printf("Balanced\n");
      
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include<queue>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef pair<double,double> Pdouble;

const int INF = 2000000000;
const int MOD = 1000000007;

vector<string> answer;
ll n;
void dfs(string s, char mx){
  if(s.size()==n){
    answer.push_back(s);
  }else{
    char cs = s.at(s.size()-1);
    if(cs>mx){
      mx = cs;
    }
    char num = mx + 1;
    for(char i='a'; i<=num;i++){
      dfs(s+i,mx);
    }
  }
}

int main() {
  cin >> n ;
  dfs("a", 'a');
  for(int i=0; i<answer.size(); i++){
    cout << answer.at(i) << endl;
  }
}

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

int main() {
    int N,cnt=0,ans=0;
    cin >> N;
    for(int i=2;i<=N;i++){
        if(i%2!=0){
            for(int j=1;j<=i/2;j++){
                if(i%j==0){
                    cnt++;
                }
            }
            if(cnt == 7){
                ans++;
            }
            cnt = 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
# Problem: https://atcoder.jp/contests/abc083/tasks/abc083_b
# Python 3rd Try

import sys
# from collections import defaultdict
# import heapq,copy
# from collections import deque


# int1 = lambda x: int(x) - 1
# p2D = lambda x: print(*x, sep="\n")


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


# def MI1(): return map(int1, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def LLI(rows_number): return [LI() for _ in range(rows_number)]


def sumDigit(inputNum):
    result = 0
    numString = str(inputNum)
    for j in range(0, len(numString), +1):
        result = result + int(numString[j])
    return result


def solver(maxNumber, fromNum, toNum):
    result = 0
    for j in range(1, maxNumber+1, +1):
        nowDigitSum = sumDigit(j)
        if fromNum <= nowDigitSum:
            if nowDigitSum <= toNum:
#                 print("{} is OK!".format(j))
                result = result + j
    return result


if __name__ == "__main__":
    N, A, B, = MI()
    print("{}".format(solver(N, A, B)))


Measured memory_bytes: 3064
#include <stdio.h>

int main(){
	int n,m,i,j;
	char a[10000],b[10000],buf;
	while(1){
		for(i = 0;i < 10000;i++){
			a[i] = 0;
			b[i] = 0;
		}
		scanf("%d\n",&n);
		if(!n) break;
		for(i = 0;i < n;i++) {
			scanf("%c %c\n",&a[i],&b[i]);
		}
		scanf("%d\n",&m);
		for(i = 0;i < m;i++){
			scanf("%c\n",&buf);
			for(j = 0;j < n;j++) if(a[j] == buf) {
				printf("%c",b[j]);
				break;
			}
			if(j == n) printf("%c",buf);
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 612
import java.util.*;
public class Main{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
  int n=sc.nextInt();
  int num[]=new int[n];
  for(int i=0;i<n;i++){
  	num[i]=sc.nextInt();
  }
  Arrays.sort(num);int count=0;
  for(int i=0;i<n;i++){
  count+=(i%2==0)?num[n-1-i]:-num[n-1-i];
  }
  System.out.println(count);
  
  
}
}

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

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define pi 3.14159265358979

int main(){
  double a, rot, tmp = 0;
  double x = 0, y = 0;

  while(1){
    scanf("%lf,%lf", &a, &rot);
    if(a == 0 && rot == 0) break;

    y += a * sin(tmp * pi / 180);
    x += a * cos(tmp * pi / 180);

    tmp += rot;
  }

  printf("%d\n", (int)y);
  printf("%d\n", (int)x);

  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

double dist(pair<ll,ll> a, pair<ll,ll> b){
    return sqrt(pow((double)a.first-b.first,2)+pow((double)a.second-b.second,2));
}

int main(){
    ll xs,ys,xt,yt;
    int N;
    cin >> xs >> ys >> xt >> yt;
    cin >> N;

    pair<ll,ll> V[1002];
    ll R[1002];
    V[0]=make_pair(xs,ys);
    R[0]=0;
    V[1]=make_pair(xt,yt);
    R[1]=0;

    for(int i=0;i<N;i++){
        ll x,y,r;
        cin >> x >> y >> r;
        V[i+2]=make_pair(x,y);
        R[i+2]=r;
    }

    double d[1002];
    d[0]=0.0;
    for(int i=1;i<N+2;i++) d[i]=INFINITY;
    int cnt=N+2;
    bool checked[1002];
    for(int i=0;i<N+2;i++) checked[i]=false;

    while(cnt>0){
        double mn=INFINITY;
        int mi=0;
        for(int i=0;i<N+2;i++){
            if(checked[i]==false && d[i]<mn){
                mn=d[i];
                mi=i;
            }
        }
        checked[mi]=true;
        cnt--;

        for(int i=0;i<N+2;i++){
            d[i]=min(d[i],d[mi]+max(0.0,dist(V[i],V[mi])-(R[i]+R[mi])));
        }
    }
    
    printf("%.12lf\n",d[1]);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric>
#include <regex>
#include <climits>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define RREP(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define forin(i, a) for(auto i: (a))
#define p(...) printf(__VA_ARGS__); cout << endl;
#define in(...) __VA_ARGS__; input__(__VA_ARGS__);
#define input(...) in(__VA_ARGS__)
#define out(...) output__(__VA_ARGS__);
#define output(...) out(__VA_ARGS__)
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](auto const &a, auto const &b){ return c ;}
#define key(t, x, compare) [](const t &a, const t &b){ return a x compare b x ;}
#define unless(a) if(!(a))

using namespace std;

using pii = pair<int, int>;

template <class... T>
void input__(T &...a) {
  for(auto v: {&a...}) {
    cin >> *v;
  }
}

void output__(){
  cout << endl;
}

template <class Head, class... T>
void output__(Head const &v, T const &...a) {
  if(sizeof...(a) == 0) {
    cout << v;
  } else {
    cout << v << " ";
  }
  output__(a...);
}

int main(){
  long in(n);
  long list_input(a, n);

  long cnt = 0;
  forin(v, a) {
    while(true) {
      if(v & 1) {
        break;
      } else {
        v >>= 1;
        cnt++;
      }
    }
  }
  out(cnt);
}


Measured memory_bytes: 384
from __future__ import print_function
from sys import stdin, stdout

try:
    xrange
except NameError:
    pass
else:
    range = xrange

def solve():
    table = []
    for _ in range(9):
        table.append(stdin.readline().split())
    
    check_table = []
    for _ in range(9):
        check_table.append([False] * 9)
    
    # horizontal check
    for i in range(9):
        a = []
        for j in range(9):
            a.append(table[i][j])
        for j in range(9):
            n = table[i][j]
            if a.count(n) > 1:
                check_table[i][j] = True
    
    # vertical check
    for j in range(9):
        a = []
        for i in range(9):
            a.append(table[i][j])
        for i in range(9):
            n = table[i][j]
            if a.count(n) > 1:
                check_table[i][j] = True
    
    # 9x9 check
    for i in range(0, 9, 3):
        for j in range(0, 9, 3):
            a = []
            for di in range(3):
                for dj in range(3):
                    a.append(table[i + di][j + dj])
            for di in range(3):
                for dj in range(3):
                    n = table[i + di][j + dj]
                    if a.count(n) > 1:
                        check_table[i + di][j + dj] = True
    
    for i in range(9):
        for j in range(9):
            if check_table[i][j]:
                stdout.write('*')
            else:
                stdout.write(' ')
            stdout.write(table[i][j])
        stdout.write('\n')

if __name__ == '__main__':
    N = int(stdin.readline())
    for i in range(N):
        if i > 0:
            stdout.write('\n')
        solve()

Measured memory_bytes: 4348
program Project1;
             
{$APPTYPE CONSOLE}
         
uses
  SysUtils,math;
var
  fx,g,r,a,h,w,i,j,count,x,y,sw,m,n,b,c,soeji,sum,max,k,t,z:Integer;
  //l:array of Integer;
  l,l1,l2:int64;
  s,s123,s1,s2,s3:string;
  tf:Boolean;
  //nyu:TStringList;
  c1,c2,c3:char;
begin
  try
    { TODO -oUser -cConsole Main : ここにコードを記述してください }
    Read(c1);
    Read(c2);
    Readln(c3);

    Writeln(StrToInt(c1)+StrToInt(c2)+StrToInt(c3));
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

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

int main(){
    string s;
    cin >> s;
    long long count_n = 0, count_w = 0, count_s = 0, count_e = 0;

    for(long long i = 0; i < s.size(); i++){
        if(s[i] == 'N'){
            count_n++;
        }
        else if(s[i] == 'W'){
            count_w++;
        }
        else if(s[i] == 'S'){
            count_s++;
        }
        else{
            count_e++;
        }
    }

    bool flag_ns = true, flag_we = true;

    if(count_n > 0){
        if(count_s == 0){
            flag_ns = false;
        }
    }

    if(count_w > 0){
        if(count_e == 0){
            flag_we = false;
        }
       
    }

    if(count_e > 0){
        if(count_w == 0){
            flag_we = false;
        }
    }

    if(count_s > 0){
        if(count_n == 0){
            flag_ns = false;
        }
    }

    if(flag_ns == true and flag_we == true){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,k; cin>>n>>k;
    vector<int> l(n,0);
    rep(i,n) cin>>l[i];
    sort(al(l)); reverse(al(l));
    int ans=0;
    rep(i,k) ans+=l[i];
    cout<<ans<<endl;
}


Measured memory_bytes: 3640
#include <stdio.h>
#include <math.h>

int sosu(int);

int main(){

  int i,n,a,cnt=0;

  
  scanf("%d",&n);
 
  for(i=0;i<n;i++){


    //   printf(" i:%d\n",i);
    scanf("%d",&a);
    //  printf(" a:%d\n",a);

    
    if(sosu(a)==1)cnt++;
    
  }
  
  printf("%d\n",cnt);
  
  return 0;
}


int sosu(int x){

  int i;
  
  if (x==2)return 1;
  
  if (x<2 || x%2==0)return -1;

  i = 3;

   while (i <=sqrt(x)){
    if (x%i==0)return -1;
  
  i = i + 2;
   }

  return 1;	   

}



Measured memory_bytes: 2044
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
using namespace std;

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

void sout(string* a, string* b) {
	if (*a > * b) {
		string c = *a;
		*a = *b;
		*b = c;
	}
}

int combination(int n, int k) {
	if (n > k && k > 0) {
		return (combination(n - 1, k) + combination(n - 1, k - 1));
	}
	else
		return 1;
}

int main() {
	string s;
	cin >> s;
	if (s == "Sunny") {
		cout << "Cloudy" << endl;
	}
	else if (s == "Cloudy") {
		cout << "Rainy" << endl;
	}
	else
		cout << "Sunny" << endl;
}


Measured memory_bytes: 256