akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void p(vector<int> A){rep(i,A.size()){cout << A[i] << " ";}cout << "\n";}

int main(){
    string S;
    cin >> S;
    bool n = false,e = false,w = false,s = false;
    rep(i,S.size()){
        if(S[i] == 'N'){
            n = true;
        }
        if(S[i] == 'E'){
            e = true;
        }
        if(S[i] == 'W'){
            w = true;
        }
        if(S[i] == 'S'){
            s = true;
        }
    }
    if(n && s && w && e)cout << "Yes";
    else if(n && s && (!w && !e))cout << "Yes";
    else if(w && e && (!n && !s))cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,a[10]={0},x,ans=0;
	for(cin>>n;n--;a[min(8,x/400)]++) cin>>x;
	for(int i=0;i<8;ans+=!!a[i++]);
	cout<<max(ans,1)<<" "<<ans+a[8];
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[11];
int main()
{
    gets(a);
    if(a[0]=='Y'&&a[1]=='A'&&a[2]=='K'&&a[3]=='I')printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 256
from collections import deque
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,M,*ab = map(int, read().split())

    E = [[] for _ in range(N+1)]
    for a, b in zip(*[iter(ab)]*2):
        E[a].append(b)
        E[b].append(a)

    par = [0] * (N+1)
    seen = [-1] * (N+1)
    seen[1] = 0
    queue = deque([1])

    while queue:
        v = queue.popleft()
        for e in E[v]:
            if seen[e] == -1:
                seen[e] = seen[v] + 1
                par[e] = v
                queue.append(e)
    
    for i in range(1, N+1):
        if seen[i] == -1:
            print("No")
            exit()
    
    print("Yes")
    print("\n".join(map(str, par[2:])))

    

if __name__ == "__main__":
    main()


Measured memory_bytes: 54268
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
using namespace std;
int main() {
	string s, t;
	cin >> s >> t;
	bool ans = false;
	rep(i, s.size()) {
		if (s == t) {
			ans = true;
			break;
		}
		s = s.back() + s.substr(0, s.size() - 1);
	}
	if (ans) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace ABC150
{
    class B
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();

            int res = 0;
            for (int i = 0; i < N - 3 + 1; i++)
            {
                string tmp = S[i].ToString() + S[i + 1].ToString() + S[i + 2].ToString();
                if (tmp == "ABC") res++;
            }
            Console.WriteLine(res);
        }
    }
}


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

int main() {

	ll n, a, b; cin >> n >> a >> b;
	vector<ll> x(n);
	for (ll i = 0; i < n; i++) {
		cin >> x[i];
	}
	ll ans = 0;
	vector<ll> diff(n - 1);
	for (ll i = 0; i < n - 1; i++) {
		diff[i] = x[i + 1] - x[i];
		ans += min(a * diff[i], b);
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

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

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

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

ll A[200010];
vector<ll> V[200010];
bool U[200010];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    REP(i, N) {
        cin >> A[i];
        V[A[i]].push_back(i);
    }
    REP(i, N) {
        if (V[A[i]].back() < INF)
            V[A[i]].push_back(INF);
    }

    vector<ll> v;
    v.push_back(0);
    ll index = 0;
    ll cnt = 1;
    do {
        ll n = A[index];
        ll nxt = upper_bound(V[n].begin(), V[n].end(), index) - V[n].begin();
        if (nxt == V[n].size() - 1) {
            cnt++;
            nxt = 0;
            v.push_back(V[n][nxt] + 1);
        }
        index = V[n][nxt] + 1;
    } while (index < N);
    ll s = v[(cnt - 1 + (K % cnt)) % cnt];
    deque<ll> ans;
    FOR(i, N, s) {
        ll n = A[i];
        if (U[n]) {
            while (!ans.empty()) {
                ll m = ans.back();
                ans.pop_back();
                U[m] = false;
                if (m == n)
                    break;
            }
            continue;
        }
        U[n] = true;
        ans.push_back(n);
    }

    while (!ans.empty()) {
        ll n = ans.front();
        ans.pop_front();
        cout << n << " ";
    }
    cout << endl;
    return 0;
}

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

using ll = long long;
#define MOD 1000000007

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

    int n;
    cin>>n;

    ll ans=1;

    for(int i=1;i<=n;i++)
    {
        ans*=i;
        ans%=MOD;
    }

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end()) // ユニークなvectorにする。連続した値を除去して切り出す。
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  int sumOfUnderX = 0;
  int sumOfUpperX = 0;

  rep (i, M) {
    int ai;
    cin >> ai;
    if (ai >= X) {
      sumOfUpperX++;
    } else {
      sumOfUnderX++;
    }
  }

  cout << min(sumOfUpperX, sumOfUnderX) << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

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

    int max;
    max = 10 * a + b + c;
    if (max < a + (10 * b + c)) {
        max = a + 10 * b + c;
    }
    if (max < a + b + 10 * c)
        max = a + b + 10 * c;

    cout << max << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner stdIn = new Scanner(System.in);
		String S = stdIn.next();
		if(!S.substring(S.length() - 1, S.length()).equals("s")) {
			System.out.println(S + "s");
		}else {
			System.out.println(S + "es");
		}
	}
}

Measured memory_bytes: 38456
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <stdlib.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
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; }

int main(void){

    int N;
    string s;
    cin >> N;
    cin >> s;

    if(N%2 == 1){
        cout << "No" << endl;
        return 0;
    }

    int half = N/2;
    
    REP(i,half){
        if(s.at(i) != s.at(half+i)){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin>>n;
    vector<int> s(n),t(n),u(n);
    for(int i=0;i<n;i++)cin>>s[i];
    for(int i=0;i<n;i++)cin>>t[i];
    for(int i=0;i<n;i++)cin>>u[i];
    sort(s.begin(),s.end());
    sort(u.begin(),u.end());
    long long ans=0;
    for(int x:t){
        ans+=(lower_bound(s.begin(),s.end(),x)-s.begin())*(n-(upper_bound(u.begin(),u.end(),x)-u.begin()));
    }
    cout<<ans<<endl;
}


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

int N, i;
vector<int> a;

int main(){
    scanf("%d", &N);
    while(N){
        i = int(sqrt(N * 2));
        if(i * (i + 1) / 2 < N)i++;
        a.push_back(i);
        N -= i;
    }
    reverse(a.begin(), a.end());
    for(i = 0; i < a.size(); ++i){
        cout << a[i] << endl;
    }
    return 0;
}


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

#define rep(i, n) for (ll i = 0; i < n; i++)
class UnionFind
{
    vector<int> par;
    vector<int> siz;

public:
    UnionFind(int n) : par(n), siz(n, 1)
    {
        for (int i = 0; i < n; i++)
        {
            par[i] = i;
        }
    }
    int root(int x)
    {
        if (par[x] == x)
        {
            return x;
        }
        else
        {
            return par[x] = root(par[x]);
        }
    }
    bool same(int x, int y)
    {
        return root(x) == root(y);
    }
    bool unite(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
        {
            return 0;
        }
        if (siz[x] == siz[y])
        {
            swap(x, y);
        }
        siz[x] += siz[y];
        par[y] = x;
        return 1;
    }
    int size(int x)
    {
        return siz[root(x)];
    }
};
int main()
{
    int n, q, a, b;
    cin >> n >> q;
    int ans = n - 1;
    UnionFind uf(n);
    rep(i, q)
    {
        cin >> a >> b;
        a--;
        b--;
        if (uf.unite(a, b))
        {
            ans--;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3936
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
#from scipy.misc import comb

N = int(input())
Map = []
for i in range(N):
    m = tuple(map(int, input().split()))
    Map.append(m)

for X in range(101):
    for Y in range(101):
        for m in Map:
            if m[2] != 0:
                H = abs(X-m[0])+abs(Y-m[1])+m[2]
                break
        flg = 1
        for m in Map:
            if m[2] != max(H-abs(X-m[0])-abs(Y-m[1]),0):
                flg = 0
                break
        if flg:
            print(X,Y,H)

Measured memory_bytes: 12080
import Control.Monad
import Data.List

bil n = replicateM n [1,0]

chk [] = True
chk [_] = True
chk (a:b:r) | a==1 && b==1 = False
chk (_:r) = chk r

ami1 ([],_) = Nothing
ami1 ([a],_) = Just(a, ([],[]))
ami1 (a:b:u, 1:r) = Just(b, (a:u,r))
ami1 (a:u, _:r) = Just(a, (u,r))

amitr pr = map (unfoldr ami1 . (,) pr)

amisum = foldl' (\al bl->map (\(a,b)->(a+b)`mod`1000000007) $ zip al bl)

amih n bl ac = amisum (replicate n 0) $ amitr ac bl

main = do
    (h:w:k:_)<-map read.words<$>getLine::IO[Int]
    let bl = filter chk $ bil $ w-1
    print $ (!! (k-1)) $ (!! h) $ iterate (amih w bl) $ 1:replicate (w-1) 0


Measured memory_bytes: 2300
def main():
    a,b,c = map(int,input().split())
    target = c
    daily_coin = a
    weekly_coin = b
    weekly_daily_total_coin = 7 * a + b
    counter = 0

    counter += (target // weekly_daily_total_coin) * 7
    target %= weekly_daily_total_coin
    #print(counter,target)
    temp = 0
    if target % daily_coin != 0 :
        temp += 1
    counter += min(target // daily_coin + temp,7)
    print(counter)



if __name__ == '__main__':
    main()



Measured memory_bytes: 5600
import sys
input = sys.stdin.readline

N = int(input())

def f(n):
    prime = [i for i in range(2, 1000)]
    
    index = 0
    while True:
        p = prime[index]
        
        prime = [v for v in prime if v == p or v % p != 0]
        index += 1
        
        if len(prime) <= index:
            break
    
    return prime

prime = f(N)

def f2(n):
    l = {}
    
    for v in prime:
        while n % v == 0:
            n = n // v
            if l.get(v) == None:
                l[v] = 0
            l[v] += 1
    return l
            
re = {}

for i in range(2, N + 1):
    for k, v in f2(i).items():
        if re.get(k) == None:
            re[k] = 0
        re[k] += v
        
result = 1
for _, v in re.items():
    result *= v + 1
print(result % (10 ** 9 + 7))

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

int main(){

    int A,B,C,K;
    cin >> A >> B >> C >> K;

   int ans = 0;
    if (A>=K){
        ans = K;
    }else if (A+B>=K){
        ans = A;
    }else{
        ans = A-(K-A-B);
    }

        cout << ans << endl;

}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n; cin >> n;
  vector<int> l(n);
  for (int i=0; i<n; i++){
    cin >> l.at(i);
  }
  int cnt=0;
  for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){
      if (l.at(i)==l.at(j)){continue;}
      for(int k=0; k<n; k++){
        if(l.at(i)==l.at(k)){continue;}
        else if (l.at(j)==l.at(k)){continue;}
        else {
          if (l.at(i)+l.at(j)>l.at(k) && l.at(i)+l.at(k)>l.at(j) && l.at(j)+l.at(k)>l.at(i)){
            cnt++;
          }
        }
      }
    }
  }
  cout << cnt/6 << endl;
}

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> nums(N);
    for(int i = 0; i < N; i++)
    {
        cin >> nums.at(i);
    }
    sort(nums.begin(), nums.end());
    string answer = "YES";
    for(int i = 0; i < N - 1; i++){
        if(nums.at(i) == nums.at(i + 1)){
            answer = "NO";
            break;
        }
    }
    cout << answer << endl;
    return 0;
}


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

pair<int, int> a[100005];
int main(){
	int n, k;
	cin >> n >> k;
	if(n % 2 == 1){
		int m = n / 2;
		int len = 0;
		int k1 = 0, k2 = 0;
		for(int i = 2 * n - 1; i >= n; i --){
			if(i % 2 == 1){
				a[len].first = i; a[len ++].second = m + k1;
				k1 ++;
			}
			else {
				a[len].first = i, a[len ++].second = k2;
				k2 ++;
			}
		}
		if(2 * n - 1 + m + k > 3 * n - 1) cout << -1 << '\n';
		else {
			int cur = k + 3 * n - 1;
			for(int i = 0; i < len; i ++) {
				if(i % 2 == 0) cout << a[i].first + k << ' ' << a[i].second + k << ' ' << cur -- << '\n';
			}
			for(int i = 0; i < len; i ++){
				if(i % 2 == 1) cout << a[i].first + k << ' ' << a[i].second + k << ' ' << cur -- << '\n';
			}
		}
	}
	else {
		int m = n / 2;
		int len = 0;
		int k1 = 0, k2 = 0;
		for(int i = 2 * n - 1; i >= n; i --){
			if(i % 2 == 1){
				a[len].first = i; a[len ++].second = m + k1;
				k1 ++;
			}
			else {
				a[len].first = i, a[len ++].second = k2;
				k2 ++;
			}
		}
		if(2 * n - 1 + m + k > 3 * n - 1) cout << -1 << '\n';
		else {
			int cur = k + 3 * n - 1;
			for(int i = 0; i < len; i ++) {
				if(i % 2 == 0) cout << a[i].first + k << ' ' << a[i].second + k << ' ' << cur -- << '\n';
			}
			for(int i = 0; i < len; i ++){
				if(i % 2 == 1) cout << a[i].first + k << ' ' << a[i].second + k << ' ' << cur -- << '\n';
			}
		}
	}
}

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

        using namespace std;
        typedef long long ll;
        void __print(int x) {cerr << x;}
        void __print(long x) {cerr << x;}
        void __print(long long x) {cerr << x;}
        void __print(unsigned x) {cerr << x;}
        void __print(unsigned long x) {cerr << x;}
        void __print(unsigned long long x) {cerr << x;}
        void __print(float x) {cerr << x;}
        void __print(double x) {cerr << x;}
        void __print(long double x) {cerr << x;}
        void __print(char x) {cerr << '\'' << x << '\'';}
        void __print(const char *x) {cerr << '\"' << x << '\"';}
        void __print(const string &x) {cerr << '\"' << x << '\"';}
        void __print(bool x) {cerr << (x ? "true" : "false");}

        template<typename T, typename V>
        void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
        template<typename T>
        void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
        void _print() {cerr << "]\n";}
        template <typename T, typename... V>
        void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
        #ifndef ONLINE_JUDGE
        #define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
        #else
        #define debug(x...)
        #endif
        const long long INF  = 1e18;
        int md = 1e9+7;
   
        int main()
        {
            ios_base::sync_with_stdio(false);
            cin.tie(NULL);
            int n;
            cin>>n;
            vector<pair<int,int>>points(n);
            for(int i=0;i<n;i++)
            {
                int x,y;
                cin>>x>>y;
                points[i].first = x;
                points[i].second = y;
            }

            sort(points.begin(),points.end());
            int minsum = INT_MAX;
            int mindiff = INT_MAX;
            int ans = INT_MIN;
            for(int i=0;i<n;i++)
            {
                int x = points[i].first;
                int y = points[i].second;

                int sum = x + y;
                int diff= x-y;
                if(i>0)
                {
                    ans = max(ans,sum - minsum);
                    ans = max(ans,diff-mindiff);
                }
                minsum = min(minsum,sum);
                mindiff = min(mindiff,diff);
                
            }
            cout<<ans;
            
        }
        //https://www.youtube.com/watch?v=ZQqccia8bVo

Measured memory_bytes: 4772
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << setprecision(9);

	int N;
	cin >> N;
	vector<pair<int,int> > red,blue;
	for(int i=0; i<N; i++){
		int x,y;
		cin >> x >> y;
		red.push_back(MP(x,y));
	}
	for(int i=0; i<N; i++){
		int x,y;
		cin >> x >> y;
		blue.push_back(MP(x,y));
	}
	sort(red.begin(), red.end());
	red.push_back(MP(INT_MAX,INT_MAX));
	sort(blue.begin(), blue.end());

	int ans = 0;
	int b = 0;
	vector<int> h;
	for(int i=0; i<N; i++){
		h.push_back(red[i].second);
		sort(h.begin(), h.end());
		vector<int> koho;
		while(b < N && blue[b].first <= red[i+1].first){
			if(blue[b].first > red[i].first) koho.push_back(blue[b].second);
			b++;
		}
		sort(koho.begin(), koho.end());
		for(int j=h.size()-1; j>=0; j--){
			if(j >= h.size()) continue;
			for(int k=koho.size()-1; k>=0; k--){
				if(h[j] < koho[k]){
					koho.erase(koho.begin()+k);
					h.erase(h.begin()+j);
					j++;
					ans++;
					break;
				}
			}
		}
		//cout << ans << endl;
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

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

    int n, m;
    cin >> n >> m;
    vector<P> v[100010];
    for (int i = 0; i < m; i++)
    {
        ll x, y;
        cin >> x >> y;
        v[x - 1].push_back(P{y, i});
    }
    for (int i = 0; i < n; i++)
        sort(v[i].begin(), v[i].end());
    vector<P> ans;
    for (ll i = 0; i < n; i++)
    {
        for (ll j = 0; j < v[i].size(); j++)
        {
            ans.push_back(P{v[i][j].second, 1000000 * (i + 1) + j + 1});
        }
    }
    sort(ans.begin(), ans.end());
    for (int i = 0; i < ans.size(); i++)
    {
        int a = ans[i].second % 1000000, b = ans[i].second / 1000000;
        printf("%06d%06d\n", b, a);
    }
}

Measured memory_bytes: 8688
#include <iostream>
#include <string>
using namespace std;

int main()
{
    int n;
    cin >> n;
    string x;
    cin >> x;
    int k = 0;
    for(int i = 0; i < n; i++) k += x[i] - '0';
    int l = max(k - 1, 1), r = k + 1;
    int s = 0, t = 0;
    int d = 1, e = 1;
    for(int i = n - 1; i >= 0; i--){
        s = (s + d * (x[i] - '0')) % l;
        t = (t + e * (x[i] - '0')) % r;
        d = d * 2 % l;
        e = e * 2 % r;
    }
    int p[200005];
    d = 1;
    e = 1;
    for(int i = n - 1; i >= 0; i--){
        if(x[i] == '0'){
            p[i] = (t + e) % r;
        }
        else{
            p[i] = (s + l - d) % l;
        }
        d = d * 2 % l;
        e = e * 2 % r;
    }
    for(int i = 0; i < n; i++){
        int ans = 1;
        if(x[i] == '1' && r == 2){
            cout << 0 << endl;
            continue;
        }
        while(p[i]){
            int c = 0;
            for(int j = 0; j <= 20; j++){
                if((p[i] >> j) & 1) c++;
            }
            p[i] %= c;
            ans++;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 4488
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline LL gl()
{
	LL f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int INF = 0x3f3f3f3f;

int main()
{
	//File("");
	LL a, b, n;
	n = gl(), a = gl(), b = gl();
	LL x = n / (a + b) * a, y = n - n / (a + b) * (a + b);
	if (y > a) x += a;
	else x += y;
	cout << x << endl;
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int N, K;

int main() {
	cin >> N >> K;
	if ((N - 1) * (N - 2) / 2 < K) {
		cout << -1 << endl;
		return 0;
	}

	ll rest = (N - 1) * (N - 2) / 2 - K;
	cout << N - 1 + rest << endl;

	for (int i = 2; i <= N; i++) {
		cout << i << " " << 1 << endl;
	}
	if (rest != 0) {
		for (int i = 2; i <= N; i++) {
			for (int j = i + 1; j <= N; j++) {
				cout << i << " " << j << endl;
				rest--;
				if (rest == 0)goto end;
			}
		}
	}
end:;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

const int MAX =100;

int main(){
    int A, B; cin >> A >> B;
    char grid[100][100];

    for(int i=0;i<MAX;i++){
        for(int j=0;j<MAX;j++){
            grid[i][j] = i<50 ? '.' : '#';
        }
    }

    int x = 0, y = 0;
    for(int i=0;i<B-1;i++){
        grid[x][y] = '#';
        y+=2;
        if(y >= MAX){
            x += 2;
            y = 0;
        }
    }

    x = MAX-1; y = 0;
    for(int i=0;i<A-1;i++){
        grid[x][y] = '.';
        y += 2;
        if(y >= MAX){
            x -= 2;
            y = 0;
        }
    }
    cout << MAX << " " << MAX << endl;

    for(int i=0;i<MAX;i++){
        for(int j=0;j<MAX;j++){
            cout << grid[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
// Last Change:    12/16/2018 14:11:58.
#include <algorithm>
#include <array>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int N, L;
  multiset<string> S;
  cin >> N >> L;
  string input;
  for (int i = 0; i < N; i++) {
    cin >> input;
    S.insert(input);
  }
  for (auto itr = S.begin(); itr != S.end(); ++itr) {
    cout << *itr;
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int main()
{
    int s,w;
    cin >> s >> w;
    /*
    int a[n];
    std::vector<int> v;
    for(int i=0; i<n; i++){
        int tmp;
        cin >> tmp;
        v.push_back(tmp);
    }
    */
    if(s<=w){
        cout << "unsafe" << endl;
    }else{
        cout << "safe" << endl;
    }
    
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}

using vd=vector<double>;
using data=tuple<double,int,int>;

double hypot3(double x,double y,double z){
	return sqrt(x*x+y*y+z*z);
}
double dist(vd a, vd b){
	auto d=hypot3(a[0]-b[0],a[1]-b[1],a[2]-b[2]);
	return max(d-a[3]-b[3],0.0);
}

struct UnionFind{
	vi p;
	UnionFind(int s):p(s,-1){}
	void unite(int a,int b){
		a=root(a);b=root(b);
		if(a!=b){
			if(p[b]<p[a])swap(a,b);
			p[a]+=p[b];p[b]=a;
		}
	}
	bool same(int a,int b){return root(a)==root(b);}
	int root(int a){return p[a]<0?a:p[a]=root(p[a]);}
};

int main(){
	int n;
	while(cin>>n,n){
		vector<vd> cell(n,vd(4));
		vector<data> edge;
		rep(i,n) {
			rep(j,4) cin>>cell[i][j];
			rep(j,i) edge.emplace_back(dist(cell[i],cell[j]),i,j);
		}
		sort(all(edge),[](data a,data b){return get<0>(a)<get<0>(b);});

		UnionFind uf(n);
		double ans=0;
		for(auto e:edge){
			double d; int a,b;
			tie(d,a,b)=e;
			if(!uf.same(a,b)){
				ans+=d;
				uf.unite(a,b);
			}
		}
		cout.precision(3);
		cout<<fixed<<ans<<endl;
	}
	return 0;
}



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

A = [int(input()) for _  in range(N)]

A.sort()

xor_val =  0

last = 0
for i,a in enumerate(A):
    if i< N -1 and A[i]==A[i+1]:
        continue
    num = a-last
    if num%2:
        xor_val = xor_val ^ num

if xor_val:
    print("first")
else:
    print("second")

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

#ifdef LOCAL

template<class T, class U>
ostream& operator<<(ostream& os, pair<T, U> p) {
	os << "(" << p.first << ", " << p.second << ")";
	return os;
}

template<template<class, class...> class C, class... A>
typename enable_if<!is_same<C<A...>, string>::value, ostream&>::type
operator<<(ostream& os, class C<A...> c) {
	auto i = c.begin();
	while (i != c.end()) {
		os << " {"[i == c.begin()] << *i;
		os << ",}"[++i == c.end()];
	}
	return os;
}

#define debug(x) cerr << #x << " = " << x << endl;
#else
#define debug(...) {}
#endif

const int N = 2005;
long long infLL = 1e18;
int inf = 1e9;

vector<int> G[N];

vector<pair<int,pair<int,int>>> kra;

vector<pair<int,pair<int,int>>> mstowe;
vector<pair<int,pair<int,int>>> inne;

int fuf(int x, vector<int>& fu) {
	if (fu[x] == x) return x;
	return fu[x] = fuf(fu[x], fu);
}

void fuu(int a, int b, vector<int>& fu) {
	debug(a);
	debug(b);
	debug(fuf(a, fu));
	debug(fuf(b, fu));
	fu[fuf(a, fu)] = fuf(b, fu);
	debug(fu);
}

long long int mod = 1000 * 1000 * 1000 + 7;

int pot(int a, int k) {
	if (k == 0) return 1;
	long long b = pot(a, k / 2);
	b = (b * b) % mod;
	if (k % 2) b = (b * a) % mod;
	return b;
}

int n;

int szukaj(int a, int b) {
	vector<int> fu(n+1);
	for (int i = 1; i <= n; i ++) fu[i] = i;
	for (auto p : mstowe) {
		fuu(p.second.first, p.second.second, fu);
		if (fuf(a, fu) == fuf(b, fu)) {
			return p.first;
		}
	}
	assert(false);
}

vector<int> fu;

int main() {
	ios_base::sync_with_stdio(false);
	int m;
	cin >> n >> m;
	long long X;
	cin >> X;
	fu.resize(n+1);
	for (int i = 1; i <= n; i ++) fu[i] = i;
	for (int i = 0; i < m; i ++) {
		int a, b, c;
		cin >> a  >> b >> c;
		kra.emplace_back(c, make_pair(a, b));
	}
	sort(kra.begin(), kra.end());
	long long MST = 0;
	for (int i = 0; i < kra.size();) {
		int j = i + 1;
		while (j < kra.size()&& kra[j].first == kra[i].first) {
			j ++;
		}
		debug(i);
		debug(j);
		for (int k = i; k < j; k ++) {
			if (fuf(kra[k].second.first, fu) != fuf(kra[k].second.second, fu)) {
				mstowe.push_back(kra[k]);
			} else {
				inne.push_back(kra[k]);
			}
		}
		for (int k = i; k < j; k ++) {
			if (fuf(kra[k].second.first, fu) != fuf(kra[k].second.second, fu)) {
				fuu(kra[k].second.first, kra[k].second.second, fu);
				debug(fu);
				MST += kra[k].first;
			}
		}
		i = j;
	}
	debug(MST);
	if (X < MST) {
		cout << "0\n";
		return 0;
	}
	if (X == MST) {
		cout << (pot(2, m) - pot(2, m - mstowe.size() + 1) +  mod) % mod << "\n";
		return 0;
	}
	int dowolne = 0;
	int czarne = 0;
	int nasze = 0;
	for (auto p : inne) {
		long long drz = MST + p.first - szukaj(p.second.first, p.second.second);
		if (drz == X) nasze ++;
		if (drz < X) czarne ++;
		if (drz > X) dowolne ++;
	}
	if (nasze == 0) cout << 0 <<"\n";
	else cout << (2 * (pot(2, dowolne + nasze) - pot(2, dowolne) + mod)) % mod<< "\n";
}


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

#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define REP(i, n) for (long long i = 0; i < (n); i++)
const ll INF = 1LL << 60;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
};
signed main() {
    int a, b;
    cin >> a >> b;
    if ((a + b) % 2 == 0) {
        cout << (a + b) / 2 << endl;
        return 0;
    }
    cout << (a + b) / 2 + 1 << endl;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


string s;

int main() {
    cin >> s;

    i64 cnt = 0;
    REP(i, s.length()) {
        if (i == 0) continue;
        if (s[i] == s[i - 1]) {
            s[i] = '0' + ((s[i] - '0') + 1) % 2;
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

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

const int MAX_M = 200000;

int main() {
	int N, M;
	bool fromOne[MAX_M + 1] = {}, toN[MAX_M + 1] = {};

	std::cin >> N >> M;
	for(int i = 0; i < M; ++i) {
		int a, b;
		std::cin >> a >> b;
		if(a == 1) fromOne[b] = true;
		if(b == N) toN[a] = true;
	}

	for(int i = 0; i < N; ++i) {
		if(fromOne[i] and toN[i]) {
			std::cout << "POSSIBLE" << std::endl;
			return 0;
		}
	}
	std::cout << "IMPOSSIBLE" << std::endl;
}

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

const int N = 2e5 + 5;
typedef long long LL;

int n, m, a[N], t[N];

int Lowbit(int x) {
	return x&(-x);
}

void update(int x, int k) {
	while(x <= n) {
		t[x] += k;
		x += Lowbit(x);
	}
}

int query(int x) {
	int res = 0;
	while(x) {
		res += t[x];
		x -= Lowbit(x);
	}
	return res;
}

int main() {
	cin>>n>>m;
	for(int i = 1; i <= n; i++)
		cin>>a[i];
	while(m--) {
		for(int i = 1; i <= n; i++) t[i] = 0;
		for(int i = 1; i <= n; i++) {
			int l = max(1, i - a[i]), r = min(n, i + a[i]);
			update(l, 1);
			update(r + 1, -1);
		}
		int mi = n;
		for(int i = 1; i <= n; i++) {
			a[i] = query(i);
			mi = min(a[i], mi);
		}
		if(mi == n) break;
	}
	for(int i = 1; i <= n; i++)
		cout<<a[i]<<" ";
	return 0;
}

Measured memory_bytes: 5156
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>

using namespace std;

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

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

const int Maxn = 20010;

int a[Maxn], b[Maxn];

int n;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        a[i] = b[n - 1 - i] = (i + 1) * n;
    }
    int x;
    cin >> x;
    for (int i = 0; i < n - 1; ++i) {
        cin >> x;
        --x;
        a[x] += i + 1;
    }
    for (int i = 0; i < n; ++i) {
        if (i != 0) cout << " ";
        cout << a[i];
    }
    cout << endl;
    for (int i = 0; i < n; ++i) {
        if (i != 0) cout << " ";
        cout << b[i];
    }
    cout << endl;
}


Measured memory_bytes: 768
def num():
    x, y = map(int, input().split())
    dp = [0]*(y+1)

    for i in range(x):
        w, v = map(int, input().split())
        for j in range(y, w-1, -1):
            num = dp[j-w]+v
            if num > dp[j]:
                dp[j] = num
    print(dp[-1])

num()


Measured memory_bytes: 14396
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define lb lower_bound
#define ub upper_bound
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  int a,b;cin>>a>>b;

    if(a<=b){
      rep(i,0,b)cout<<a;
      cout<<ENDL;
    }else{
      rep(i,0,a)cout<<b;
      cout<<ENDL;
    }
  
}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

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

int q(const void *a,const void *b)
{
    return *(int*)a-*(int*)b;
}

int gcd(int x,int y)
{
    int r;
    if(y>x){
        r=x;
        x=y;
        y=r;
    }
    while(y>0){
        r=x%y;
        x=y;
        y=r;
    }
    return x;
}

int main(void)
{
    int n,x,a[100000],i;
    scanf("%d%d",&n,&x);
    for(i=0;i<n;++i)scanf("%d",&a[i]);
    for(i=0;i<n;++i)a[i]=abs(x-a[i]);
    for(i=1;i<n;++i)a[i]=gcd(a[i-1],a[i]);
    printf("%d",a[n-1]);
    return 0;
}

Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>

using namespace std;

typedef complex<double> xy_t;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF= 1 << 30;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;

int main(){
	int cost;
	int books;
	int num;
	while(cin >> cost && cost){
		books = 0;
	for(int i = 0; i < 9; i++){
		cin >> num;
		books += num;
	}
	cout << cost - books << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;


int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, a, b, c; cin >> n >> a >> b >> c;
  V<> l(n); for (auto&& e : l) cin >> e;
  int res = 1e9;
  for (int bit = 0; bit < 1 << 2 * n; ++bit) {
    int t = bit;
    VV<> idx(4);
    for (int i = 0; i < n; ++i) {
      idx[t & 3].push_back(i);
      t >>= 2;
    }
    if (idx[0].size() == 0) continue;
    if (idx[1].size() == 0) continue;
    if (idx[2].size() == 0) continue;
    auto f = [&](int i, int x) -> int {
      int s = 0;
      for (int j : idx[i]) s += l[j];
      return 10 * (idx[i].size() - 1) + abs(s - x);
    };
    int curr = f(0, a) + f(1, b) + f(2, c);
    res = min(res, curr);
  }
  cout << res << '\n';
}

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

struct Node
{
	int key;
	Node *pre,*nex;
};

Node *null;

void init() {
	null = (Node *)malloc(sizeof(Node));
	null->nex = null;
	null->pre = null;
}

void insert(int key) {
	Node *x;
	x = (Node *)malloc(sizeof(Node));
	x->key = key;

	x->nex = null->nex;
	null->nex->pre = x;
	null->nex = x;
	x->pre = null;
}

Node* search(int key) {
	Node *cur = null->nex;
	while (cur != null && cur->key != key)cur = cur->nex;
	return cur;
}

void del(Node *t) {
	if (t == null)return;
	t->pre->nex = t->nex;
	t->nex->pre = t->pre;
	free(t);
}
void del_f() {
	del(null->nex);
}
void del_l() {
	del(null->pre);
}
void del_search(int key) {
	del(search(key));
}


int main() {
	int n, key;
	cin >> n;
	char com[15];
	init();

	for (int i = 0; i < n; i++) {
		scanf("%s", com);
		if (strlen(com) > 6) {
			if (com[6] == 'F')del_f();
			else if (com[6] == 'L')del_l();
		}
		else {
			scanf("%d", &key);
			if (com[0] == 'i')insert(key);
			if (com[0] == 'd')del_search(key);
		}
	}

	Node *cur = null->nex;
	while (cur != null) {
		cout << cur->key;
		if (cur->nex == null)cout << endl;
		else cout << " ";
		cur = cur->nex;
	}
}



Measured memory_bytes: 34424
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <iomanip>
#include <cmath>

using ll = long long;

using namespace std;

int main() {
    int a, b, x;
    cin >> a >> b >> x;
    double ans;
    if (a * a * b >= 2 * x) {
        double side = (double)x * 2 / (a * b);
        ans = atan(b / side);
    } else {
        double up = (double)x * 2 / (a * a) - b;
        ans = atan((b - up) / a);
    }
    cout << setprecision(15) << ans * 180 / M_PI << '\n';
    return 0;
}

Measured memory_bytes: 512
import sys
import time
def solve(matrix):
    N = len(matrix)
    #print  matrix
    day = 0
    worst = N * (N-1) / 2
    remaining = worst
    start = time.time()
    while remaining:
        prev = remaining
        day+=1
        #print "day %d" % day
        #print "matrix: %r" % matrix
        #print "remaining:%d" % remaining
        match = {}
        for i, order in enumerate(matrix):
            me = i+1
            if match.get(me) and order and order[0] in match[me]:
                x = matrix[order[0]-1].pop(0)
                y = order.pop(0)
                remaining -= 1
                #print "%d and %d" % (x, y)
                #print "matrix: %r" % matrix
            elif order:
                if match.get(order[0]):
                    match[order[0]].append(me)
                else:
                    match[order[0]] = [me]
                #print 'match: %r' % match
        if time.time() - start > 1.5:
            print worst
            return
        if remaining  == prev:
            print -1
            return
    print day



N = raw_input()
N = int(N)

matrix = [] 
for x in range(N):
    matrix.append([int(b) for b in raw_input().split()])
solve(matrix)

Measured memory_bytes: 31700
#include<iostream>
#include<iomanip>
#include<vector>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;
const int MAX = 0;
const int INF = 100000000;

bool solve(int N) {
	while (N) {
		int n = N % 10;
		if (n == 9)return true;
		N /= 10;
	}
	return false;
}

int main() {
	int N;
	cin >> N;
	if (solve(N)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    cout << 180*(n-2) << endl;
    return 0;
}

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

int main(int argc, char const *argv[])
{
	int n, k; cin >> n >> k;
	int ans = 0;
	while (n > 0) {
		n /= k;
		ans++;
	}
	cout << ans << endl;
	return 0;
}


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

int main()
{
  //int A, B, C, X, Y;
//  int m[101]={};
  int A, B, C, D;
  //int ans=1;
  char comp[6]={};
//  int sosu[20000]={};
  char s[5001]={};
  char x[5001]={};
  char y[5001]={};
  char z[5001]={};
  int cnt=0;
  int len;
  int ans[2]={};
  int i,j,k,l;
  int flag=0;  
//    int k=0;

  scanf("%d", &A);
  scanf("%s", &s);

  for(i=1;i<A;i++){
    strncpy(x,s,i);
    strncpy(y,&s[i],A-i);  
    x[i+1] = '\0';
    y[A-i] = '\0';
    //printf("%s\n", x);
    //printf("%s\n", y);
    for(j=0;j<26;j++){
      for(k=0;k<i;k++){
        if(x[k] == (0x61 + j)){
          for(l=0;l<A-i;l++){
            if(y[l] == (0x61 + j)){
              cnt++;
              flag=1;
              break;
            }
          }
        }
        if(flag==1){
          flag=0;
          break;
        }
      }
    }
    if(ans[0]<cnt) ans[0] = cnt;
    cnt=0;
  }


  printf("%d\n", ans[0]);
  
//  printf("%d\n", &ans[0]);
  
return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(), greater<int>());
	long long sum = 0;
	for (int i = 0; i < n - 1; i++) {
		if (i % 2 == 0) {
			sum += a[(i / 2)];
		}
		else {
			sum += a[(i + 1) / 2];
		}
	}
	cout << sum << endl;
	return 0;
}

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

using namespace std;

int main(void) {
    constexpr long MOD = 1e9 + 7;

    int n, k;
    cin >> n >> k;

    vector<vector<int>> G(n);
    for(int i=0; i<n-1; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;

        G[a].push_back(b);
        G[b].push_back(a);
    }

    auto inv = [&](long x) {
        long b = MOD-2;
        long r = 1;
        while(b) {
            if(b&1) r*=x;
            r %= MOD;
            x *= x;
            x %= MOD;
            b >>= 1;
        }
        return r;
    };

    auto perm = [&](long n, long k) {
        if(n < k) return 0L;

        long r = 1;
        for(long i=0; i<k; i++)
            r *= n-i, r %= MOD;
        return r;
    };

    auto dfs = [&] (auto dfs, int p, int cur) -> long {
        long r = 1;
        if(p == -1)
            r *= perm(k-1, G[cur].size());
        else
            r *= perm(k-2, G[cur].size()-1);
        r %= MOD;

        for(auto v: G[cur]) {
            if(v == p) continue;
            r *= dfs(dfs, cur, v);
            r %= MOD;
        }
        /* cout << p << ' ' << cur << ' ' << r << endl; */
        return r;
    };

    auto r = dfs(dfs, -1, 0) % MOD;
    cout << (k * r) % MOD << endl;
}


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

using namespace std;

int bit_count(int m){
  int count = 0;
  while(m != 0){
    if(m % 2 == 1){
      count++;
    }
    m /= 2;
  }
  
  return count;
}

int main(){
  int n;
  cin >> n;
  
  vector<int> f(n, 0);
  vector<vector<int>> p(n, vector<int>(11));
  
  for(int i = 0; i < n; i++){
    for(int j = 0; j < 10; j++){
      int in;
      cin >> in;
      f[i] = f[i] * 2 + in;
    }
  }
  
  for(int i = 0; i < n; i++){
    for(int j = 0; j <= 10; j++){
      cin >> p[i][j];
    }
  }
  
  int prof = 0;
  for(int b = 1; b < (1<<10); b++){
    int now_prof = 0;
    for(int i = 0; i < n; i++){
      now_prof += p[i][bit_count(b & f[i])];
    }
    if(b == 1 || now_prof > prof) prof = now_prof;
  }
  
  cout << prof << endl;
  
  return 0;
}

Measured memory_bytes: 256