akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(ll i=0;i<(n);++i)
#define Fr(i,n) for(long long i=1;i<=(n);++i)
#define ifr(i,n) for(long long i=(n)-1;i>=0;--i)
#define iFr(i,n) for(long long i=(n);i>0;--i)
using Graph = vector<vector<int>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll a,b,ans;
  cin>>a>>b;
  if(a%2==0){
    if(b%2==1){
      cout<<(b-a+1)/2%2;
    }
    else{
      ans=b ^ ((b-a)/2%2);
      cout<<ans;
    }
  }
  else{
    if(b%2==1){
      ans=a ^ (b-a+1)/2%2;
      cout<<ans;
    }
    else{
      ans=a^b^(b-a)/2%2;
      cout<<ans;
    }
  }
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >>n;
  long long k;
  cin >>k;
  vector<int> v(n);
  for(int i=0; i <n ; i++){
    int x;
    cin >> x;
    v.at(i) = x-1;
  }
  vector<int> w(0);
  int place=0;
  int memo = -1;
  for(int i =0; i <n; i++){
    w.push_back(place);
    place = v.at(place);
  }
  for(int i =0; i<n; i++){
    if(place == w.at(i)){
      memo = i;
      break;
    }
  }
  if(k>=memo){
    int roop;
    roop = n-memo;
    k = (k - memo)%roop ;
    cout <<w.at(k+memo)+1 << endl;
  }
  else{
    cout << w.at(k) +1 << endl;
  }
}

Measured memory_bytes: 5048
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define deb(x) cout<<#x<<" : "<<x<<"\n";
#define debug(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\n";
#define deb_arr(a,n) {cout<<#a<<":";for(int i=0;i<n;i++) {cout<<a[i]<<" ";} cout<<'\n';}
#define deb_mat(dist,n,m) {cout<<#dist<<"\n";for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<dist[i][j]<<" ";}cout<<'\n';}}
#define ff first
#define ss second
#define ub upper_bound
#define lb lower_bound
#define all(a) (a).begin(),(a).end()
#define bs binary_search
#define sz size()
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ld long double
#define clr fflush(stdout);
//#define clr cout.flush();
#define N 200001
#define fpr(i,a,b) for(int i=a;i<b;i++)
#define fdr(i,a,b) for(int i=a;i>b;i--)
#define repp(i,a,b,d) for(int i=a;i<b;i+=d)
#define repd(i,a,b,d) for(int i=a;i>b;i-=d)
#define LLMIN LLONG_MIN
#define LLMAX LLONG_MAX
#define AKASH_PATEL ios_base::sync_with_stdio(false);
#define SVNIT_SURAT cin.tie(NULL);cout.tie(NULL);
#define mset(x,a) memset(x,a,sizeof(x));
#define nl cout<<'\n';
#define print(c) cout<<c<<'\n';
#define setp(n) cout << fixed << setprecision(n)
#define take_arr(a,n) fpr(i,0,n) cin>>a[i];
#define print_arr(a,n) for(int i=0;i<n;i++) {cout<<a[i]<<" ";} cout<<'\n';
#define take_mat(mat,n,m) fpr(i,0,n) fpr(j,0,m) cin>>mat[i][j];
#define set_mat(mat,n,m,k) fpr(i,0,n) fpr(j,0,m) mat[i][j]=k;
#define print_mat(dist,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<dist[i][j]<<" ";}cout<<'\n';}
template< class T > bool inside(T a, T b, T c) { return a<=b && b<=c; }
template< class T > bool odd(T a) { return a&1; }
template< class T > bool even(T a) { return !(a&1); }
int main()
{
//#ifndef ONLINE_JUDGE
//    freopen("../ip.txt", "r", stdin);
//    freopen("../op.txt", "w", stdout);
//#endif
    AKASH_PATEL;
    SVNIT_SURAT;
    int t=1;
    //cin>>t;
    while(t--)
    {
        double r;
        cin>>r;
        setp(6)<<2*M_PI*r<<'\n';
    }
    return 0;
}





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

int main(){
    ll x;
    cin >> x;
    ll limit = (ll)ceil(sqrt(x));
    for(ll i=0;i<=limit;i++) {
        ll a = pow(i,5);
        ll complement = a - x;
        ll val = pow(abs(complement), 1.0/5.0);
        if(complement < 0) val *= -1;
        if(pow(val, 5) == complement) {
            printf("%lld %lld\n", i, val);
            break;
        }
    }
}


Measured memory_bytes: 4200
N=int(input())

D={}
D["M"]=0
D["A"]=0
D["R"]=0
D["C"]=0
D["H"]=0

for i in range(N):
    S=input()
    if S[0]=="M":
        D["M"]+=1
    elif S[0]=="A":
        D["A"]+=1
    elif S[0]=="R":
        D["R"]+=1
    elif S[0]=="C":
        D["C"]+=1
    elif S[0]=="H":
        D["H"]+=1

import itertools
l=["M","A","R","C","H"]
a=list(itertools.combinations(l,3)) #Lの中から2個

ANS=0
for i in range(len(a)):
    ANS+=(D[a[i][0]]*D[a[i][1]]*D[a[i][2]])
print(ANS)

Measured memory_bytes: 44520
N, M = map(int,input().split())                                         # N:ノード数、M:エッジ数
visited = [False for i in range(N)]                                     # ノードの訪問済みフラグ
edges = [[i-1 for i in map(int,input().split())] for j in range(M)]     # エッジ情報のインプット
graph = [[False for i in range(N)] for j in range(N)]                   # 接続行列の入れ物

# 各エッジについて、情報を接続行列に埋め込む
for edge in edges:
    graph[edge[0]][edge[1]] = True
    graph[edge[1]][edge[0]] = True

# dfs:ノードvについて、エッジで接続した未訪問のノードを即時訪問する(再帰処理)
def dfs(v):
    visited[v] = True
    for next in range(N):
        if graph[v][next] == False:continue
        if visited[next] == True:continue
        dfs(next)

ans = 0

# 各エッジを取り除いたとき、dfsして未訪問のノードが残っていれば、そのエッジは橋
for i in range(M):
    graph[edges[i][0]][edges[i][1]] = False
    graph[edges[i][1]][edges[i][0]] = False

    for j in range(N):
        visited[j] = False

    dfs(0)

    bridge = False
    for j in range(N):
        if visited[j] == False:
            bridge = True
    if bridge:
        ans += 1

    graph[edges[i][0]][edges[i][1]] = True
    graph[edges[i][1]][edges[i][0]] = True

print(ans)


Measured memory_bytes: 3064
from math import gcd
def solve(i,j,k):
    return gcd(gcd(i,j),k)
n = int(input())
ans = 0
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            ans+=solve(i,j,k)
print(ans)

Measured memory_bytes: 68000
N = int(input())
d = list(map(int, input().split()))
LEN = int(((N*(N-1))/2))


ans = []

for i in range(N):
    for j in range(N):
        if i != j:
            ANS = (d[i]*d[j])
            ans.append(ANS)
            
        
        
print(int(sum(ans)/2))

Measured memory_bytes: 3060
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans=0
for i in range(N):
    ans+=B[A[i]-1]
    if i!=N-1:
        if A[i]+1==A[i+1]:
            ans+=C[A[i]-1]
print(ans)

Measured memory_bytes: 3064
<?php
$cards = array('S' => array_fill(1, 13, false),
               'H' => array_fill(1, 13, false),
               'C' => array_fill(1, 13, false),
               'D' => array_fill(1, 13, false));
$n = (int)fgets(STDIN);
$res = '';
while (--$n >= 0) {
  $set = explode(' ', trim(fgets(STDIN)));
  $cards[$set[0]][$set[1]] = true;
}
foreach($cards as $key => $val) {
  for ($i = 1; $i <= 13; $i++) {
    if (!$cards[$key][$i]) $res = $res."$key $i".PHP_EOL;
  }
}
echo $res;

Measured memory_bytes: 15332
n = int(input())
lstA = list(map(int, input().split()))
cntCase1, cntCase2 = 0, 0


# 偶数番目を正、奇数番目を負とする場合
accum = 0
for i in range(n):
    ai = lstA[i]
    tmpSum = accum
    tmpSum += ai
    if i % 2 == 0:
        if tmpSum <= 0:
            cntCase1 += abs(tmpSum) + 1
            accum = 1
        else:
            accum = tmpSum
    else:
        if tmpSum >= 0:
            cntCase1 += abs(tmpSum) + 1
            accum = -1
        else:
            accum = tmpSum


# 偶数番目を負、奇数番目を正とする場合
accum = 0
for i in range(n):
    ai = lstA[i]
    tmpSum = accum
    tmpSum += ai
    if i % 2 == 0:
        if tmpSum >= 0:
            cntCase2 += abs(tmpSum) + 1
            accum = -1
        else:
            accum = tmpSum
    else:
        if tmpSum <= 0:
            cntCase2 += abs(tmpSum) + 1
            accum = 1
        else:
            accum = tmpSum


ans = min(cntCase1, cntCase2)
print(ans)

Measured memory_bytes: 14468
#include <iostream>
#include <vector>
#include <queue>

using namespace std;
int main(){
  int N;
  cin >> N;
  int a, b, c;
  vector< vector< pair<int, int> > > G(N);
  for(int i = 0; i < N-1; ++i){
    cin >> a >> b >> c;
    --a;--b;
    G[a].emplace_back(c, b);
    G[b].emplace_back(c, a);
  }
  int Q, K;
  cin >> Q >> K;
  --K;
  const long long int INF = 1e15;
  vector<long long int> D(N, INF);
  D[K] = 0;
  queue<int> wait;
  wait.emplace(K);
  while(!wait.empty()){
    int v = wait.front();
    wait.pop();
    for(int i = 0; i < G[v].size(); ++i){
      int v_ = G[v][i].second;
      if(D[v_] < INF) continue;
      D[v_] = D[v] + G[v][i].first;
      wait.emplace(v_);
    }
  }
  int x, y;
  for(int i = 0; i < Q; ++i){
    cin >> x >> y;
    --x;--y;
    cout << D[x] + D[y] << endl;
  }
  return 0;
}


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

struct Edge{
  int to;
  int weigh;
  Edge(int t, int w) : to(t), weigh(w){ };
};

using Graph = vector<vector<Edge>>;
int n;
vector<int> color; //頂点の色 1か0 未訪問は-1

void dfs(const Graph &G, int v, int c){
  color[v] = c;
  for(auto next_v : G[v]){
    if(next_v.weigh % 2){
      if(color[next_v.to] == -1) dfs(G, next_v.to, 1-c);
    }
    else{
      if(color[next_v.to] == -1) dfs(G, next_v.to, c);
    }
  }
  return;
}

int main(){
  cin >> n;
  Graph G(n);
  int u, v, w;
  for(int i=0; i<n-1; ++i){
    cin >> u >> v >> w;
    G[u-1].push_back(Edge(v-1, w));
    G[v-1].push_back(Edge(u-1, w));
  }

  color.assign(n, -1);
  for(int i=0; i<n; ++i){
    if(color[i] == -1){
      dfs(G, i, 1);
    }
  }
  for(int i=0; i<n; ++i){
    cout << color[i] << "\n";
  }
}

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

//区間加算、区間和, 0オリジン

template<typename D = long long, int useAssert = 1>
class BIT{
public:
  int n;
  vector<D> bit0, bit1;
  BIT(){n = -1;}
  BIT(int n_){
    n = 1;
    while(n < n_) n *= 2;
    bit0.resize(n+1, 0);
    bit1.resize(n+1, 0);
  }

  D sum(vector<D> &b, int i){
    D s = 0;
    while(i > 0){
      s = (s + b[i]);// % mod;
      i -= i & -i;
    }
    return s;
  }

  void add(vector<D> &b, int i, D v){
    // v = (mod + v % mod) % mod;
    while(i <= n){
      b[i] = (b[i] + v);//% mod;
      i += i & -i;
    }
  }

  //[a,b)にxを加算 0オリジン
  void add (int a, int b, D x){
    // x = (mod + x % mod) % mod;
    if(a == b) return;
    a++;
    if(useAssert) assert(a <= b && 1 <= a && b <= n);
    add(bit0, a, -x*(a-1));
    add(bit1, a, x);
    add(bit0, b+1, x*b);
    add(bit1, b+1, -x);
  }

  //[a,b)のsumを得る 0オリジン
  D sum(int a, int b){
    if(a == b) return 0;
    a++;
    if(useAssert) assert(a <= b && 1 <= a && b <= n);
    D s = sum(bit0, b);
    D t = sum(bit1, b) * b;
    D u = sum(bit0, a-1);
    D v = sum(bit1, a-1) * (a-1);
    return s + t - u - v;
    //return ((s + t) + (mod - u%mod) + (mod - v%mod)) % mod;
  }
};

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

  BIT <> bit(n);

  for(int i=0;i<q;i++){
    int cmd;
    cin>>cmd;
    if(cmd == 0){
      int s, t, x;
      cin>>s>>t>>x; s--, t--;
      bit.add(s, t+1, x);
    }
    else {
      int s, t;
      cin>>s>>t; s--, t--;
      long long ans = bit.sum(s, t+1);
      cout<<ans<<endl;
    }
  }

}



Measured memory_bytes: 4944
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
using P=pair<int,int>;
P f(int x){
    int fst;
    string s=to_string(x);
    fst=s[0]-'0';
    int last=x%10;
    return P(fst,last);
}
int main() {
    int n;cin>>n;
    int si=to_string(n).size();
    if(si==1){
        cout<<n<<endl;
    }else{
        map<P,int> num;
        for(int i=1;i<=n;i++){
            P p=f(i);
            num[p]++;
        }
        int ans=0;
        for(int i=1;i<=n;i++){
            P p=f(i);
            P q(p.second,p.first);
            ans+=num[q];

        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 256
/*
ID: jerrywcy
TASK: AtCoder ABC 100 Problem B
LINK: https://abc102.contest.atcoder.jp/tasks/abc102_b
LANG: C++
*/
#include <bits/stdc++.h>

using namespace std;

int n;
int ans;
 
int main(){
	cin>>n;
	int i,j;
	for (i=1;i<=n;i++){
		int a;
		cin>>a;
		while (a%2==0){
			a/=2;
			ans++;
		}
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>
#include<list>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

ll mypow(ll x,ll n,ll mod = MOD){
    ll ret = 1;
    while(n > 0){
        if(n&1){
            ret = (ret*x)%mod;
        }
        x = (x*x)%mod;
        n >>= 1;
    }
    return ret;
}

ll mygcd(ll a,ll b){
    if(b == 0)return a;
    return mygcd(b,a%b);
}

ll twoPow(ll shiftNum){
    return (1LL << (shiftNum - 1));
}

class Combination{
    long long int maxn;
    long long int mod;
    std::vector<long long int> factorial;
    std::vector<long long int> inverse;

    public:

    Combination(long long int n,long long int m):maxn(n),mod(m){
        factorial.push_back(1);
        inverse.push_back(1);

        for(long long int i = 1; i <= n; i++){
            factorial.push_back((factorial.back()*i)%mod);
            inverse.push_back([&](long long int x,long long int n) -> long long int{
                long long int ret = 1;
                while(n > 0){
                    if(n&1)ret = (ret*x)%mod;
                    x = (x*x)%mod;
                    n >>= 1;
                }
                return ret;
            }(factorial.back(),mod-2));
        }
    }

    long long int getFactorial(int idx){
        if(idx > maxn || idx < 0)return -1;
        return factorial[idx];
    }

    long long int getInverse(int idx){
        if(idx > maxn || idx < 0)return -1;
        return inverse[idx];
    }

    long long int comb(long long int n,long long int r){
        return (((factorial[n]*inverse[n-r])%mod)*inverse[r])%mod;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    ll n,k;
    cin >> n >> k;

    vector<ll> a(n);

    for(auto &x : a){
        cin >> x;
    }

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

    Combination cb = Combination(n+1,MOD);

    ll ans = 0;
    for(int i = 0; i < n; i++){
        if(i >= k-1){
            if(i == 0){
                ans += a[i];
                ans %= MOD;
            }else{
                ans += (((a[i] + MOD)%MOD)*cb.comb(i,k-1))%MOD;
                ans %= MOD;
            }
        }
        auto num = n - i - 1;
        if(num >= k-1){
            if(num == 0){
                ans += (MOD - a[i]);
                ans %= MOD;
            }else{
                ans += (((MOD - a[i])%MOD)*cb.comb(num,k-1))%MOD;
                ans %= MOD;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2804
#include <iostream>
#include <vector>

using namespace std;

vector<vector<bool> > P;
vector<vector<int> > Ways;

void init(int m) {
	P.clear();
	vector<bool> a(2 * m + 1, false);
	for (int i = 0; i < 2 * m + 1; i++)
		P.push_back(a);	
}

void input_ways(int m) {
	Ways.clear();
	Ways.push_back({0, 1});
	int s, d;
	for (int i = 0; i < m; i++) {
		cin >> s >> d;
		Ways.push_back({s, d});
		Ways.push_back({d, s});
	}
	for (int i = 0; i < 2 * m + 1; i++)
		for (int j = 0; j < 2 * m + 1; j++)
			if (Ways[i][1] == Ways[j][0] && Ways[i][0] != Ways[j][1])
				P[i][j] = true;
}

vector<vector<bool> > product(vector<vector<bool> > a, vector<vector <bool> > b) {
	vector<vector<bool> > result(a.size(), vector<bool>(a[0].size(), false));
	for (int i = 0; i < a.size(); i++)
		for (int j = 0; j < a[0].size(); j++)
			for (int k = 0; k < a[0].size(); k++)
				result[i][j] = result[i][j] || a[k][j] && b[i][k];
	return result;
}

vector<bool> product(vector<vector<bool> > a, vector<bool> b) {
	vector<bool> result(a.size(), 0);
	for (int i = 0; i < a.size(); i++)
		for (int j = 0; j < a[0].size(); j++)
			result[i] = result[i] || a[j][i] && b[j];
	return result;
}

vector<vector<bool> > pow(vector<vector<bool> > matrix, int n) {
	if (n == 1)
		return matrix;
	else if (n % 2 == 0)
		return pow(product(matrix, matrix), n / 2);
	else
		return product(matrix, pow(matrix, n - 1));
}

bool eval(int n, int m, int z) {
	bool result = false;
	vector<bool> start(2 * m + 1, false);
	start[0] = true;
	vector<bool> v = product(pow(P, z), start);
	for (int i = 0; i < v.size(); i++){
		if (v[i] && Ways[i][1] == n)
			result = true;
	}

	return result;
}

int main(){
	int n, m, z;
	while (cin >> n >> m >> z)
		if (n == 0 && m == 0 && z == 0)
			return 0;
		else {
			init(m);
			input_ways(m);
			cout << (eval(n, m, z) ? "yes" : "no") << endl;
		}
}

Measured memory_bytes: 2056
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

int main(){
    string s;
    cin >> s;

    map<char,vector<int>> m;
    rep(i,s.size()){ m[s[i]].emplace_back(i); }

    vector<int> v;
    set<char> st;
    for(auto it = s.rbegin(); it != s.rend(); it++){
        st.insert(*it);
        if(st.size() == 26){
            v.emplace_back(s.rend() - it - 1);
            st.clear();
            //show(v.back())
        }
    }
    reverse(all(v));

    string ans;
    int cur = -1;
    rep(i,v.size() + 1){
        for(char j = 'a'; j != 'z' + 1; j++){
            auto p = lower_bound(all(m[j]), cur);
            if(p == m[j].end()){
                ans += j;
                break;
            }
            //show(*p)
            //    show(v.size() - distance(v.begin(), lower_bound(all(v), cur)))
            //    show(v.size() - distance(v.begin(), lower_bound(all(v), *p + 1)))
            if(v.size() - distance(v.begin(), lower_bound(all(v), cur)) == 
                    v.size() - distance(v.begin(), lower_bound(all(v), *p + 1)) + 1){
                ans += j;
                cur = *p + 1;
                break;
            }
        }
    }
    //if(ans.size() == 0) rep(i,v.size() + 1) ans += 'a';
    cout << ans << endl;
}


Measured memory_bytes: 1412
X, Y = list(map(int, input().split()))

if (X+Y)%3!=0 or Y<X//2 or Y>X*2:
    print(0)
    exit()

n = (X+Y)//3
k = Y-n  # k = 0...n

mod = 10**9+7

def modpow(n,p,mod):
    retval = 1
    i=0
    while p>>i:
        if (p>>i)&1 : retval = retval*n%mod
        n=n*n%mod
        i+=1
        
    return retval

modfacts = [1]
pre = 1
for i in range(1,n+1):
    pre = pre*i%mod
    modfacts.append(pre)

ans = modfacts[n] * modpow(modfacts[n-k], mod-2, mod) * modpow(modfacts[k], mod-2, mod)
print(ans%mod)

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

const int N = (3e5) + 5;
int n, a[N];
int freq[N];
int ac[N];

int f(int x, int& pos) {
  while (pos >= 0) {
    if (freq[pos] < x) break;
    pos--;
  }
  return (pos >= 0? ac[pos] : 0) + x * (n - pos - 1);
}

int main() { // claudio van
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    freq[a[i] - 1]++;
  }
  sort(freq, freq + n);
  partial_sum(freq, freq + n, ac);
  int ans = n, pos = n - 1;
  for (int k = 1; k <= n; ++k) {
    while (ans > 0) {
      if (k <= f(ans, pos) / ans) break;
      ans--;
    }
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
int main() {
  int  N, K = 0;
  cin >> N >> K;
  vector<int> h(N), dif(N-K+1);
  for (int i = 0; i < N; i++) {
    cin >> h.at(i);
  }

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

  for (int i = 0; i < N-K+1; i++) {
    dif.at(i) = h.at(i+K-1) - h.at(i);
  }

  sort(dif.begin(), dif.end());
  
  cout << dif.at(0) << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
using ld=long double;
using VI=vector<ll>;
using VD=vector<ld>;
using VVI=vector<VI>;
using VC=vector<char>;
using VVC=vector<VC>;
using VS=vector<string>;
using PLL =pair<ll,ll>;
using PLD=pair<ld,ld>;
using VPLL=vector<PLL>;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element((x).begin(),(x).end())
#define MIN(x) *min_element((x).begin(),(x).end())
#define SORTR(x) sort((x).rbegin(),(x).rend())
#define SORT(x) sort((x).begin(),(x).end())
#define SUM(x) accumulate((x).begin(),(x).end(), 0)
#define FILL(x,a) fill(x.begin(),x.end(),a)
#define EACH(i,x) for(typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)

const long long  int INF = 1e18;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;
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; }
template <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first, BidirectionalIterator middle,BidirectionalIterator last){reverse(middle, last); return next_permutation(first , last);}
#define COUT(x) cout<<x<<"\n"

void Main()
{
	ll N;
	ll result=0;

	cin>>N;
	result=180*(N-2);
	cout << result << "\n";
	return;
}

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


Measured memory_bytes: 256
import java.util.Scanner;
     
    public class Main {
    	public static void main(String[] args) {
    		Scanner scan = new Scanner(System.in);
    		int a = scan.nextInt();
			int b = scan.nextInt();
			int r = 2*b;
			if(a>r)
			{
				System.out.println(a-r);
			}
			else
				System.out.println("0");
    	}
    }

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

using namespace std;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int tturn = (c + b - 1) / b;
    int aturn = (a + d - 1) / d;
    cout << (tturn <= aturn ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define mk make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e16;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N; cin >> N;
    int A[N]; rep(i,N) cin >> A[i];
    rep(i,N-1){
        A[i+1]+=A[i];
    }
    int ans = INF;
    rep(i,N-1){
        ans=min(abs(A[N-1]-2*A[i]),ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
n = int(input())
S = [0]*14
H = [0]*14
C = [0]*14
D = [0]*14
for _ in range(n):
    a, b = input().split()
    b = int(b)
    if a == "S":
        S[b] = 1
    elif a == "H":
        H[b] = 1
    elif a == "C":
        C[b] = 1
    else:
        D[b] = 1
        
for i in range(1, 14):
    if S[i] == 0:
        print("S", i)
for i in range(1, 14):
    if H[i] == 0:
        print("H", i)
for i in range(1, 14):
    if C[i] == 0:
        print("C", i)
for i in range(1, 14):
    if D[i] == 0:
        print("D", i)


Measured memory_bytes: 5608
(let* ((a (write-to-string (read)))
       (b (write-to-string (read)))
       (x (parse-integer (concatenate 'string a b)))
       (root (sqrt x))
       (iroot (isqrt x)))

  (format t "~A~%"
          (if (= root iroot)
            "Yes"
            "No")))


Measured memory_bytes: 24208
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		const long MOD = 1000000007;
		static int[,] ans;
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			int n = cin.Int();

			ans = new int[n, n];
			Calc(1, 0, n);

			StringBuilder sb = new StringBuilder();
			for (int i = 0; i < n; i++) {
				for (int j = i + 1; j < n; j++) {
					sb.Append($"{ans[i, j] } ");
				}

				sb.AppendLine(" ");
			}

			Console.WriteLine(sb.ToString());
		}

		static void Calc(int level, int s, int e)
		{
			int c = (e - s) / 2 + s;
			for (int i = s; i < c; ++i) {
				for (int j = c; j < e; ++j) {
					ans[i, j] = level;
				}
			}

			if (c - s > 1) {
				Calc(level + 1, s, c);
			}

			if (e - c > 1) {
				Calc(level + 1, c, e);
			}
		}
	}

	public class Scanner
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private string[] buf_;
		private int index_;

		public Scanner()
		{
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = Console.ReadLine();
			while (st == "") {
				st = Console.ReadLine();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int()
		{
			return int.Parse(Next());
		}
		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long Long()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double Double()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 19800
#include <iostream>
#include <cmath>
#include <algorithm>
#define N  4
#define N2 16
#define LIMIT 100
using namespace std;
static const int dx[4]={0,-1,0,1};
static const int dy[4]={1,0,-1,0};
static const char dir[4]={'r','u','l','d'};
int MDT[N2][N2];

struct Puzzle { int f[N2], space, MD; };

Puzzle state;
int limit;
int path[LIMIT];

int getAllMD(Puzzle pz)
{
	int sum = 0;
	for (int i = 0; i < N2; ++i)
	{
		if (pz.f[i] == N2) continue;
		sum += MDT[i][pz.f[i] - 1];
	}
	return sum;
}

bool isSolved(Puzzle in)
{
	for (int i = 0; i < N2; ++i)
	{
		if (in.f[i] != i+1) return false;
	}
	return true;
}

bool dfs(int depth, int prev)
{
	// cout<<state.MD<<endl;
	if (state.MD == 0) return true;

	if(depth + state.MD > limit) return false;

	int sx = state.space / N;
	int sy = state.space % N;
	Puzzle tmp;

	for (int r = 0; r < 4; ++r)
	{
		int tx = sx + dx[r];
		int ty = sy + dy[r];
		if (tx < 0 || ty < 0 || tx >= N || ty >= N) continue;
		if (max(prev , r) - min(prev, r) == 2) continue;
		tmp = state;
		
		state.MD += MDT[sx * N + sy][state.f[tx * N + ty] - 1];
		state.MD -= MDT[tx * N + ty][state.f[tx * N + ty] - 1];
		swap(state.f[tx * N + ty], state.f[sx * N + sy]);
		state.space = tx * N + ty;
		if (dfs(depth + 1, r)) { path[depth] = r; return true; }
		state = tmp;
 	}
 	return false;
}

string iterative_deepening(Puzzle in)
{	
	in.MD = getAllMD(in);

	for (limit = in.MD; limit <= LIMIT; ++limit)
	{
		state = in;
		if(dfs(0, -100))
		{
			string ans = "";
			for (int i = 0; i < limit; ++i) ans += dir[path[i]];
			return ans;
		}
	}
	return "unsolvable";
}

int main()
{
	//freopen("in3.txt","r",stdin);
	for (int i = 0; i < N2; ++i)
	{
		for (int j = 0; j < N2; ++j)
		{
			MDT[i][j] = abs(i / N - j / N) + abs(i % N - j % N);
		}
	}
	Puzzle in;
	for (int i = 0; i < N2; ++i)
	{
		cin >> in.f[i];
		if (in.f[i] == 0)
		{
			in.f[i] = N2;
			in.space = i;
		}
	}

	string ans = iterative_deepening(in);
	cout<<ans.size()<<endl;
	return 0;
}

Measured memory_bytes: 3156
def suki(input, index)
  input[index]
end

gets
input = gets.chomp.split(' ').map{ |i| i.to_i - 1 }

sum = 0
input.each_with_index do |i, index|
  sum += 1 if suki(input, suki(input, index)) == index
end
puts sum / 2


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

using namespace std;

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

  int answer = 0;
  for (int i = 0; i < (1 << (H + W)); i++) {
    vector<string> D = C;
    for (int y = 0; y < H; y++) {
      if (i & (1 << y)) {
	for (int x = 0; x < W; x++) {
	  D[y][x] = '.';
	}
      }
    }
    for (int x = 0; x < W; x++) {
      if (i & (1 << (H + x))) {
	for (int y = 0; y < H; y++) {
	  D[y][x] = '.';
	}
      }
    }

    int count = 0;
    for (int y = 0; y < H; y++) {
      for (int x = 0; x < W; x++) {
	if (D[y][x] == '#') count++;
      }
    }
    if (count == K) answer++;
  }

  cout << answer << endl;

  return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
/* ちゃんと考えてわかって実装 */

int main(void){
    double l;
    cin >> l;
    double l3 = l / 3.0;
    double ans = l3 * l3 * l3;
    cout << setprecision(20) << ans << endl;
    return 0;
}

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

int main()
{
  int n,m;cin>>n>>m;
  vector<int> c(m);
  for (int i = 0; i < m; i++) cin >> c.at(i);
  sort(c.begin(),c.end(),greater<int>());
  
  int dp[50005];
  fill_n(dp,50005,INT32_MAX);
  dp[0] = 0;
  for (int i = 0; i < m; i++)
  {
    for (int j = c.at(i); j <= n; j++)
    {
      if (dp[j - c.at(i)] != INT32_MAX)
      dp[j] = min( dp[j - c.at(i)] + 1, dp[j] );
      

      
    }
    /*
    for (int k = 0; k <= n; k++)
    {
      if (dp[k] != INT32_MAX)
      cout << dp[k] << " ";
      else
      cout << "M" << " ";
      
    }
    cout << endl;
    */
  }
  

  cout << dp[n] << endl;
  

}



Measured memory_bytes: 3352
#include <bits/stdc++.h>
 #include <math.h>
 using namespace std;
 
 int main(){
    int N;
    int P[240000];
    int i;
    int ans = 0;
    int min = 0;

    cin >> N;

    for (i=0; i<N; i++)
        cin >> P[i];

    min = P[0];

    for (i=0; i<N; i++){
        if(P[i] <= min){
            min = P[i];
            ans++;
            }
        }
    cout << ans << endl;
    return 0;
 }
 


Measured memory_bytes: 1024
#!/usr/bin/env python3
mod = 10**9 + 7
s = input()
n = len(s)
# [a + b < s, a + b == s] * (# of digits)
dp = [[0, 0] for _ in range(10**5 + 2)]
dp[0][1] = 1
for i in range(n):
    dp[i + 1][0] += dp[i][0] * 3
    if s[i] == '0':
        dp[i + 1][1] += dp[i][1]
    else:
        dp[i + 1][0] += dp[i][1]
        dp[i + 1][1] += dp[i][1] * 2
    dp[i + 1][0] %= mod
    dp[i + 1][1] %= mod

ans = (dp[n][0] + dp[n][1]) % mod
print(ans)


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

#define fi first
#define se second

const int N = 2020;
const long long mod = 1e9 + 7;

using namespace std;

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(0);

        int n, k;
        cin >> n >> k;
        int cnt = 0;
        vector < int > a(k);
        for(int i = 0; i < k; i++){
                cin >> a[i];
                cnt += a[i] & 1;
        }
        if(cnt > 2){
                cout << "Impossible" << "\n";
                return 0;
        }
        for(int i = 0; i < k; i++){
                if(a[i] & 1){
                        if(cnt == 2){
                                swap(a[0], a[i]);
                                cnt = 0;
                        } else{
                                swap(a[k - 1], a[i]);
                        }
                }
        }
        vector < int > res;
        res.push_back(a[0] - 1);
        if(res[0] == 0){
                res.pop_back();
        }
        for(int i = 1; i < k - 1; i++){
                res.push_back(a[i]);
        }
        if(k > 1){
                res.push_back(a[k - 1] + 1);
        } else{
                res.push_back(1);
        }
        for(int i = 0; i < k; i++){
                cout << a[i] << " \n"[i + 1 == k];
        }
        cout << res.size() << "\n";
        for(int x: res){
                cout << x << " ";
        }
}


Measured memory_bytes: 256
import numpy as np

n, m = map( int, input().split() )
#print( n, m )

h = input().split()
h = [ int( hi ) for hi in h ]
#print( h )
goodt = [ int( 0 ) ] * n

for i in range( m ):
    a, b = map( int, input().split() )
    a = a - 1
    b = b - 1
    if h[ a ] > h[ b ]:
        goodt[ b ] += 1
    elif h[ a ] < h[ b ]:
        goodt[ a ] += 1
    elif h[ a ] == h[ b ]:
        goodt[ a ] += 1
        goodt[ b ] += 1

sumg = int( 0 )
for ig in goodt:
    if ig == 0:
        sumg += 1

print( sumg )




Measured memory_bytes: 38252
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,m,a,b,t,tt,s;
    while(~scanf("%d%d%d%d",&n,&m,&a,&b))
    {
        tt=a-b;
        t=n-m;
        if(t<0)
        {
            t=0;
        }
        s=n*a-tt*t;
        printf("%d\n",s);
    }
    return 0;
}

Measured memory_bytes: 128
import math
def lcm(a):
    LCM = a[0]
    for i in range(1, len(a)):
        LCM = LCM * a[i] // math.gcd(LCM, a[i])
    return LCM

def f(k):
    return b//k - (a-1)//k

a, b, c, d = map(int, input().split())
ALL = b - a + 1
ans = ALL - (f(c) + f(d) - f(lcm([c,d])))
print(ans)

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

const ll MOD=1000000007;

void solve(){
    int n;
    scanf("%d",&n);
    ll ans=1;
    multiset<int> st;
    st.insert(-1);
    st.insert(-1);
    st.insert(-1);

    for(int i=1;i<=n;i++){
        int x;
        scanf("%d",&x);
        int c=st.count(x-1);
        if(c==0) {ans=0;break;}
        ans=ans*c%MOD;
        st.erase(st.lower_bound(x-1));
        st.insert(x);
    }
    printf("%lld\n",ans);
}

int main(){

    solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
	int H, W;
	std::cin >> H >> W;

	while (H != 0 || W != 0) {
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				std::cout << "#";
			}
			std::cout << std::endl;
		}
		std::cout << std::endl;
		std::cin >> H >> W;
	}

}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n;
   cin >> n;
   int ans = 0;
   f(i,1,n+1){
      if(i%3 == 0 or i%5 == 0) continue;
      ans += i;
   }
   cout << ans << '\n';
   return 0;
} 

Measured memory_bytes: 3652
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
 
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)

typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
//ll MOD = 1000000007;
ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
int n;
vi hoge[214514];
int a,b,c,d;
int main(){
	string S;
	cin>>S;
	int n=S.size();
	int cnt=0;
	for(int i=0;i<n;i++){
		if(i<n-1&&S[i]=='B'&&S[i+1]=='C'){
			i++;
			hoge[cnt].pb(1);
		}else if(S[i]=='A'){
			hoge[cnt].pb(0);
		}else{
			if(hoge[cnt].size()!=0)cnt++;
		}
	}
	/*rep(i,cnt+1){
		rep(j,hoge[i].size())cout<<hoge[i][j]<<" ";
		cout<<endl;
	}*/
	ll ans=0;
	rep(i,cnt+1){
		int num=0;
		rep(j,hoge[i].size()){
			if(hoge[i][j]==1)num++;
		}
		int num2=0;
		rep(j,hoge[i].size()){
			if(hoge[i][j]==1){
				ans+=(ll)(j-num2);
				num2++;
			}
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 7044
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long i=0;i<n;i++)
int main(){
  long n; cin>>n; long memo,count; memo=0; count=0;
  long c[n];
  rep(i,n) cin>>c[i];
  
  rep(j,n-1){
    if(c[j] >= c[j+1]) { count++; }
    else { memo=max(memo,count); count=0; }    
  }
  
  memo=max(memo,count);
  
  cout<<memo<<endl;
}

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

#define MAX 100000
#define inf 1000000000

void merge(int *A, int *idx, int left, int mid, int right)
{
    int n1 = mid - left;
    int n2 = right - mid;
    int L[n1 + 1], idx_L[n1 + 1];
    int R[n2 + 1], idx_R[n2 + 1];
    int i, j;

    for (i = 0; i < n1; i++)
    {
        L[i] = A[left + i];
        idx_L[i] = idx[left + i];
    }
    for (i = 0; i < n2; i++)
    {
        R[i] = A[mid + i];
        idx_R[i] = idx[mid + i];
    }
    L[n1] = inf;
    R[n2] = inf;
    i = 0;
    j = 0;
    for (int k = left; k < right; k++)
    {
        if (L[i] <= R[j])
        {
            A[k] = L[i];
            idx[k] = idx_L[i];
            i += 1;
        }
        else
        {
            A[k] = R[j];
            idx[k] = idx_R[j];
            j += 1;
        }
    }
}

void mergeSort(int *A, int *idx, int left, int right)
{
    int mid;
    if (left + 1 < right)
    {
        mid = (left + right) / 2;
        mergeSort(A, idx, left, mid);
        mergeSort(A, idx, mid, right);
        merge(A, idx, left, mid, right);
    }
}

int partition(int *A, int *idx, int p, int r)
{
    int x = A[r];
    int i, j;
    int tmp, tmp_s;

    i = p - 1;
    for (j = p; j < r; j++)
    {
        if (A[j] <= x)
        {
            i += 1;
            tmp = A[i];
            A[i] = A[j];
            A[j] = tmp;

            tmp_s = idx[i];
            idx[i] = idx[j];
            idx[j] = tmp_s;
        }
    }
    tmp = A[i + 1];
    A[i + 1] = A[r];
    A[r] = tmp;

    tmp_s = idx[i + 1];
    idx[i + 1] = idx[r];
    idx[r] = tmp_s;

    return i + 1;
}

void quickSort(int *A, int *idx, int p, int r)
{
    int q;
    if (p < r)
    {
        q = partition(A, idx, p, r);
        quickSort(A, idx, p, q - 1);
        quickSort(A, idx, q, r);
    }
}


int main(void)
{
    int n;
    int A[MAX], B[MAX];
    int idx_A[MAX], idx_B[MAX];
    char design[MAX], design_A[MAX], design_B[MAX];
    int stable = 0;

    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%s%d", &design[i], &A[i]);
        design_A[i] = design[i];
        design_B[i] = design[i];
        B[i] = A[i];
        idx_A[i] = i;
        idx_B[i] = i;
    }

    quickSort(A, idx_A, 0, n - 1);
    mergeSort(B, idx_B, 0, n);

    for (int i = 0; i < n; i++)
    {
        design_A[i] = design[idx_A[i]];
        design_B[i] = design[idx_B[i]];
        if (design_A[i] != design_B[i])
        {
            stable += 1;
        }
    }

    if (stable == 0)
    {
        printf("Stable\n");
    }
    else
    {
        printf("Not stable\n");
    }

    for (int i = 0; i < n; i++)
    {
        printf("%c% d\n", design_A[i], A[i]);
    }

    return 0;
}


Measured memory_bytes: 4324
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdio>
#include <algorithm>

using namespace std;

typedef vector< vector<double> > Matrix;

Matrix mul(Matrix A, Matrix B){
	int n = A.size();
	Matrix res(n, vector<double>(n,0));
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			for(int k=0;k<n;k++)
				res[i][j] += A[i][k]*B[k][j];
	return res;
}

Matrix pow(Matrix A, int p){
	if(p==1) return A;
	Matrix res = pow(A, p/2);
	res = mul(res, res);
	if(p%2) res = mul(res, A);
	return res;
}

void gaussianElimination(Matrix &a){
	int n = a.size();
	for(int i=0;i<n;i++){
		int pivot = i;
		for(int j=i+1;j<n;j++)
			if(abs(a[j][i])>abs(a[pivot][i])) pivot = j;
		swap(a[i], a[pivot]);
		double div = a[i][i];
		for(int j=0;j<=n;j++) a[i][j] /= div;
		for(int j=i+1;j<n;j++){
			double mul = a[j][i];
			for(int k=0;k<=n;k++)
				a[j][k] -= a[i][k]*mul;
		}
	}
	for(int i=n-1;i>=0;i--)
		for(int j=0;j<i;j++)
			a[j][n] -= a[j][i]*a[i][n];
}

int main(){
	int S, N, K;
	double prob[11][100];
	while(cin >> S >> N >> K){
		S = abs(S);
		if(N==1){
			if(S%K==0) cout << S/K << endl;
			else       cout << -1 << endl;
			continue;
		}
		for(int i=0;i<=K;i++)
			for(int j=0;j<=N*K;j++) prob[i][j] = 0;
		prob[0][0] = 1.0;
		for(int i=0;i<K;i++)
			for(int j=0;j+N<=N*K;j++)
				for(int k=1;k<=N;k++)
					prob[i+1][j+k] += prob[i][j]/N;
		vector< vector<double> > a(N*K, vector<double>(N*K+1, 0));
		a[0][0] = 1;
		for(int i=1;i<N*K;i++){
			a[i][i] = a[i][N*K] = 1.0;
			for(int j=1;j<=N*K;j++){
				int next = abs(i-j);
				a[i][next] -= prob[K][j];
			}
		}
		gaussianElimination(a);
		if(S < N*K) printf("%.6lf\n", a[S][N*K]);
		else {
			Matrix A(N*K+1, vector<double>(N*K+1,0));
			for(int i=0;i<N*K;i++) A[0][i] = prob[K][i+1];
			A[0][N*K] = 1.0;
			for(int i=1;i<N*K;i++) A[i][i-1] = 1.0;
			A[N*K][N*K] = 1.0;
			A = pow(A, S-N*K+1);
			double res = A[0][N*K];
			for(int i=0;i<N*K;i++) res += A[0][i]*a[N*K-1-i][N*K];
			printf("%.6lf\n", res);
		}
	}
}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

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

int main(void){
    pair<int, int> zero = make_pair(0, 0);
    vector<pair<int, int>> ans;
    while(true){
        int N; cin >> N;
        if(N == 0) break;
        vector<pair<int, int>> A(N);
        A[0] = zero;
        rep(i, N-1){
            int a, b; cin >> a >> b;
            A[i+1] = make_pair(A[a].first + dx[b], A[a].second + dy[b]);
        }
        int mx_x=-mod, mn_x=mod, mx_y=-mod, mn_y=mod;
        rep(i, N){
            //cout << A[i].first << " " << A[i].second << endl;
            mx_x = max(mx_x, A[i].first);
            mn_x = min(mn_x, A[i].first);
            mx_y = max(mx_y, A[i].second);
            mn_y = min(mn_y, A[i].second);
        }
        ans.push_back(make_pair(mx_x - mn_x + 1, mx_y - mn_y + 1));
    }
    rep(i, ans.size()) cout << ans[i].first << " " << ans[i].second << endl;
    return 0;
}


Measured memory_bytes: 3096
from sys import stdin, stdout
from collections import defaultdict
def readLine_int_list():return list(map(int, stdin.readline().split()))
def main():
    n,k = readLine_int_list()
    
    l = defaultdict(lambda: 0)
    for i in range(n):
        a,b =readLine_int_list()
        l[a] += b
    
    cnt = 0
    for key in sorted(l.keys()):
        val = l[key]
        cnt += val
        if cnt >= k:
            print(key)
            break


if __name__ == "__main__":
    main()

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,w,mi=2000000000002,x,y;
	cin>>n;
	w=pow(n,0.5)*5;
	for(long double i=1;i<w;i++){
			if(i*(n/i)==n && fmod(n,i)==0){
				if(mi>=i+(n/i)){
					mi=i+(n/i);
					x=i;y=(n/i);
				}
			}
	}
	cout<<x+y-2<<endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
const ll mod = 1e9+7;
const ll INF = 2e9;
const double PI = 3.1415926535;


int main(void){
    int n; cin >> n;
    if(n == 100000)printf("90909\n");
    else if(n >= 10000)printf("%d\n", n - 9090);
    else if(n >= 1000)printf("909\n");
    else if(n >= 100)printf("%d\n", n - 90);
    else if(n >= 10)printf("9\n");
    else printf("%d\n", n);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define QOEINDIEDIS freesteed
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
void solve(){
	int n,k;
	cin>>n>>k;
	vector<VI> g(n+1); 
	rep(i,0,n-1){
		int x,y;
		cin>>x>>y;
		g[x].pb(y);
		g[y].pb(x);
	}
	queue<int> q;
	q.push(1);
	int lev = 1;
	ll ans = k;
	VI vis(n+1,0);
	vis[1] = 1;
	while(!q.empty()){
		int m = q.size();
		lev++;
		//cout<<"levet:"<<lev<<endl;
		for(int i=0;i<m;i++){
			int st = k-(lev==2?1:2);
			int v = q.front();q.pop();
			for(auto u:g[v]){
				if(vis[u])continue;
				q.push(u);
				vis[u] = 1;
				if(st<=0){
					cout<<0;
					return ;
				}
		//		cout<<st<<" ";
				ans*=st;
				ans%=mod;
				st--;
			}
		}
	//	cout<<endl;
	} 
	cout<<ans;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}






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

#define int long long int
#define MOD 1000000007

void solve()
{
    int a, b, k ;
    cin >> a >> b >> k ;
    int sub = min(a, k) ;
    a = a - sub ;
    k -= sub ;
    b = b - min(b, k) ;
    cout << a << " " << b << endl ;
    
}

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

    int t = 1 ;
    //cin >> t ;
    while(t--)
    {
        solve() ;
    }
    return 0 ;
}

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

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

    vector<long long int> h(n);
    for(int i=0; i<n; i++){
        cin >> h[i];
    }
    sort(h.begin(),h.end());

    vector<long long int> diff(n-k+1);
    for(int i=0; i<n-k+1; i++){
        diff[i] = h[i+k-1] - h[i];
    }
    sort(diff.begin(),diff.end());
    cout << diff[0] << endl;
    return 0;
}

Measured memory_bytes: 1792