akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

static const int INF = (1 << 29);

int N;
int dp[10001][3];
char book[10001][2];

int solve(){
  for(int j = 0 ; j < 3 ; j++) dp[0][j] = j;
   
  for(int i = 1 ; i <= N ; i++){
    if(book[i-1][0]=='N' && book[i-1][1]=='N'){
      dp[i][0] = min(dp[i-1][0]+1, min(dp[i-1][1]+2, dp[i-1][2]+3));
      dp[i][1] = min(dp[i-1][0]+2, min(dp[i-1][1]+1, dp[i-1][2]+2));
      dp[i][2] = min(dp[i-1][0]+3, min(dp[i-1][1]+2, dp[i-1][2]+1));
    }
    else if(book[i-1][0]=='Y' && book[i-1][1]=='Y'){
      dp[i][0] = min(dp[i-1][0]+4, min(dp[i-1][1]+3, dp[i-1][2]+3));
      dp[i][1] = min(dp[i-1][0]+3, min(dp[i-1][1]+3, dp[i-1][2]+3));
      dp[i][2] = min(dp[i-1][0]+3, min(dp[i-1][1]+3, dp[i-1][2]+4));
    }
    else if(book[i-1][0]=='Y'){
      dp[i][0] = min(dp[i-1][0]+2, min(dp[i-1][1]+2, dp[i-1][2]+3));
      dp[i][1] = min(dp[i-1][0]+2, min(dp[i-1][1]+2, dp[i-1][2]+3));
      dp[i][2] = min(dp[i-1][0]+3, min(dp[i-1][1]+3, dp[i-1][2]+4));
    }
    else if(book[i-1][1]=='Y'){
      dp[i][0] = min(dp[i-1][0]+4, min(dp[i-1][1]+3, dp[i-1][2]+3));
      dp[i][1] = min(dp[i-1][0]+3, min(dp[i-1][1]+2, dp[i-1][2]+2));
      dp[i][2] = min(dp[i-1][0]+3, min(dp[i-1][1]+2, dp[i-1][2]+2));
    }
    else return INF;
      
    if(i==N){
      if(book[i][0]=='N' && book[i][1]=='N'){
        dp[i][0] = min(dp[i][0], min(dp[i][1]+1, dp[i][2]+2));
      }
      else if(book[i][0]=='Y' && book[i][1]=='Y'){
        dp[i][0] = min(dp[i][0]+3, min(dp[i][1]+2, dp[i][2]+2));
      }
      else if(book[i][0]=='Y'){
        dp[i][0] = min(dp[i][0]+1, min(dp[i][1]+1, dp[i][2]+2));
      }
      else if(book[i][1]=='Y'){
        dp[i][0] = min(dp[i][0]+3, min(dp[i][1]+2, dp[i][2]+2));
      }
      else return INF;
    }
      
    else{
      dp[i][0] = min(dp[i][0], min(dp[i][1]+1, dp[i][2]+2));
      dp[i][1] = min(dp[i][1], min(dp[i][0]+1, dp[i][2]+1));
      dp[i][2] = min(dp[i][2], min(dp[i][0]+2, dp[i][1]+1));
    }
  }
   
  return dp[N][0];
}

int main(){
  int T;
  cin >> T;
  while(T--){
    cin >> N;
    for(int j = 0 ; j < 2 ; j++){
      for(int i = 0 ; i <= N ; i++){
        if(i==0 || i==N)cin >> book[i][j];
        else{
          char a,b;
          cin >> a >> b;
          if(a=='Y' || b=='Y')book[i][j] = 'Y';
          else book[i][j] = 'N';
        }
      }
    }
    cout << solve() << endl;
  }
  return 0;
}

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





int main(){
    string S;
    cin >> S;
    rep(i,S.length()) cout << "x";
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
// C++ program to find the longest repeated 
// non-overlapping substring 
#include<cmath>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<algorithm>
#include<list>
#include<cstring>
#define TakeInput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
using namespace std; 

// Returns the longest repeating non-overlapping 
// substring in str 
string longestRepeatedSubstring(string str) 
{ 
    int n = str.length(); 
    int LCSRe[n+1][n+1]; 

    // Setting all to 0 
    memset(LCSRe, 0, sizeof(LCSRe)); 

    string res; // To store result 
    int res_length = 0; // To store length of result 

    // building table in bottom-up manner 
    int i, index = 0; 
    for (i=1; i<=n; i++) 
    { 
        for (int j=i+1; j<=n; j++) 
        { 
            // (j-i) > LCSRe[i-1][j-1] to remove 
            // overlapping 
            if (str[i-1] == str[j-1] && 
                LCSRe[i-1][j-1] < (j - i)) 
            { 
                LCSRe[i][j] = LCSRe[i-1][j-1] + 1; 

                // updating maximum length of the 
                // substring and updating the finishing 
                // index of the suffix 
                if (LCSRe[i][j] > res_length) 
                { 
                    res_length = LCSRe[i][j]; 
                    index = max(i, index); 
                } 
            } 
            else
                LCSRe[i][j] = 0; 
        } 
    } 

    // If we have non-empty result, then insert all 
    // characters from first character to last 
    // character of string 
    if (res_length > 0) 
        for (i = index - res_length + 1; i <= index; i++) 
            res.push_back(str[i-1]); 

    return res; 
} 

// Driver program to test the above function 
int main() 
{ 
    #ifndef ONLINE_JUDGE 
    //TakeInput
    #endif
    int n;
    cin>>n;
    string a;
    cin>>a;
    cout<<longestRepeatedSubstring(a).length();
} 


Measured memory_bytes: 97920
x, n = map(int, input().split())
plis = list(map(int, input().split()))

if not x in plis:
    print(x)
    exit()

flag = True
i=1
while flag:
    if not x-i in plis:
        print(x-i)
        exit()
    elif not x+i in plis:
        print(x+i)
        exit()
    else:
        i += 1


Measured memory_bytes: 9184
n, m = map(int, input().split())

from collections import defaultdict

cb = defaultdict(int)

for a in input().split():
    cb[int(a)] += 1

for _ in range(m):
    b, c = map(int, input().split())
    cb[c] += b

cbl = sorted(cb.items())

res = n

ans = 0

while res > 0:
    c, b = cbl.pop()
    ncount = min(res, b)
    ans += c * ncount
    res -= ncount

print(ans)

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

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

using namespace std;

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

int main( ){
  int answer = 0;
  cin >> n >> m >> t;
  rep(i,n) cin >> a[i];
  // 0
  answer += ( a[0] - m );
  
  // 1..n-1
  rep(i,n) if( a[i+1] - a[i] > m * 2 ) {
      answer += ( a[i+1] - a[i] - m * 2 );
  }

  if( t - ( a[n-1] + m ) > 0 ) answer += ( t - ( a[n-1] + m ) );
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 3092
from itertools import accumulate
import bisect
N,M,K = map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

Asum = [0] + list(accumulate(A))
Bsum = [0] + list(accumulate(B))
ans=0
#print(Asum)
#print(Bsum)
for i in range(len(Asum)):
    if K >= Asum[i]:
        #print("a=",i)
        #print("b=",bisect.bisect_right(Bsum, K-Asum[i])-1)
        ans=max(ans,i-1+bisect.bisect_right(Bsum, K-Asum[i]))
print(ans)

Measured memory_bytes: 50756
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;

const int maxn = 200009;
char s[maxn]; int Next[maxn], n, m;
LL l, r, w[26];

void solve(LL k){
	if (k <= n){
		for (int i=0; i<k; i++) w[s[i]-'a']++;
		return;
	}
	LL S = 1, T = 0, _s = 0, _t = 1;
	while (S*n + T*m < k) { S += _s; T += _t; _s = S - _s; _t = T - _t; }
	solve(k - _s*n - _t*m);
	for (int i=0; i<n; i++) w[s[i]-'a'] += _s;
	for (int i=0; i<m; i++) w[s[i]-'a'] += _t;
}

int main(){
	scanf("%s", &s); scanf("%lld%lld", &l, &r);
	n = strlen(s)/2;
	int k = 0; Next[0] = 0;
	for (int i=1; i<n; i++){
		while (k && s[k] != s[i]) k = Next[k-1];
		if (s[k] == s[i]) k++; Next[i] = k;
	}
	m = n-Next[n-1];
	solve(l-1); for (int i=0; i<26; i++) w[i] = -w[i];
	solve(r); for (int i=0; i<26; i++) printf("%lld ", w[i]);
	return 0;
}

Measured memory_bytes: 768
import sys

def main():
    input = sys.stdin.readline
    S = list(map(str, input().strip()))

    S = S[:-2]
    while len(S) >= 2:
        n = len(S) // 2
        a = ''.join(S[:n])
        b = ''.join(S[n:])

        if a == b:
            return 2 * n
        else:
            S = S[:-2]


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a != b && a != c){
        cout << a << endl;
    }else if(b != a && b != c){
        cout << b << endl;
    }else{
        cout << c << endl;
    }
}

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

int main(){
  int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin >> k;
  cout << a[k-1] << endl;
  return 0;
}


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

using namespace std;

typedef pair<int, int> P;

const int MAX_N = 50;

class UnionFindTree {
private:
	int par[MAX_N];
	int rank[MAX_N];
	int siz[MAX_N];

public:
	void init(int n) {
		for (int i = 0; i<n; i++) {
			par[i] = i;
			rank[i] = 0;
			siz[i] = 1;
		}
	}

	int find(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;

		if (rank[x] < rank[y]) {
			par[x] = y;
			siz[y] += siz[x];
		}
		else {
			par[y] = x;
			if (rank[x] == rank[y])rank[x]++;
			siz[x] += siz[y];
		}
	}

	bool same(int x, int y) {
		return find(x) == find(y);
	}

	int size(int x) {
		x = find(x);
		return siz[x];
	}
};

int main() {
	int n, m, ans = 0;
	vector<P> es;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		P ed;
		cin >> ed.first >> ed.second;
		ed.first--; ed.second--;
		es.push_back(ed);
	}
	for (int i = 0; i < es.size(); i++) {
		UnionFindTree g;
		g.init(n);
		for (int j = 0; j < es.size(); j++) {
			if (i == j)continue;
			g.unite(es[j].first, es[j].second);
		}
		if (!g.same(es[i].first, es[i].second))ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int search(int A[], int n, int key)
{
	int i = 0;
	A[n] = key;
	while( A[i] != key ) i++;
	return i != n;
}

int main()
{
	int i, n, A[10000+1], q, key, sum = 0;

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

	scanf("%d", &q);
	for (i = 0; i < q; i++)
	{
		scanf("%d", &key);
		if( search(A, n, key) ) sum++;
	}

	printf("%d\n", sum);

	return 0;
}


Measured memory_bytes: 2776
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<utility>
#include<string.h>
#include<set>
#include<stdlib.h>
#include<string>
#include<utility>
#include<stack>
using namespace std;

int main(){
	int n;
	cin>>n;
	int tmp=n;
	if(tmp%10==1 || tmp%10==9) n+=(10-2*(tmp%10));
	tmp/=10;
	if(tmp%10==1 || tmp%10==9) n+=(100-20*(tmp%10));
	tmp/=10;
	if(tmp%10==1 || tmp%10==9) n+=(1000-200*(tmp%10));
	cout<<n;
	return 0;
}

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

using namespace std;
using namespace __gnu_cxx;

typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;

#define F          first
#define S          second
#define pnl        printf("\n")
#define sz(x)      (int)x.size()
#define sf(x)      scanf("%d",&x)
#define pf(x)      printf("%d\n",x)
#define all(x)     x.begin(),x.end()
#define rall(x)    x.rbegin(),x.rend()
#define rep(i, n)  for(int i = 0; i < n; ++i)

const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;

int n, m;
char arr[1010][1010];
int dp[1010][1010];

int solve(int i, int j) {
    if (i == n || j == m) return 0;
    if (arr[i][j] == '#') return 0;
    if (i == n - 1 && j == m - 1) return 1;
    int &ret = dp[i][j];
    if (~ret) return ret;
    ret = solve(i + 1, j) + solve(i, j + 1);
    if (ret >= mod) ret -= mod;
    return ret;
}

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
            scanf(" %c", &arr[i][j]);
    memset(dp, -1, sizeof dp);
    printf("%d\n", solve(0, 0));
    return 0;
}


Measured memory_bytes: 5248
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(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))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }

int main() {
	int N; int M;
	while (~scanf("%d%d", &N, &M)) {
		vector<int> deg(N, 0);
		rep(i, M) {
			int A; int B;
			scanf("%d%d", &A, &B), -- A, -- B;
			++ deg[A];
			++ deg[B];
		}
		bool ans = true;
		rep(i, N)
			ans &= deg[i] % 2 == 0;
		puts(ans ? "YES" : "NO");
	}
	return 0;
}


Measured memory_bytes: 640
N = int(input())
nums = list(map(int, input().split()))
 
set_nums = sorted(list(set(nums)))
set_dup = set_nums.copy()
 
if N <= 2:
    print(0)
else:
    for i, d in enumerate(set_dup):
        count = 0
        for n in nums:
            if n == d:
                count += 1
        set_dup[i] = count
 
    count = 0
    for a in range(len(set_nums)):
        for b in range(a+1, len(set_nums)):
            for c in range(b+1, len(set_nums)):
                if set_nums[a] + set_nums[b] > set_nums[c]:
                    count += set_dup[a] * set_dup[b] * set_dup[c]
    print(count)

Measured memory_bytes: 9204
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
aa=[0]*(n+1)
bb=[0]*(n+1)
for i in range(1,n+1):
    aa[i]=aa[i-1]+a[i-1]
for i in range(n-1,-1,-1):
    bb[i]=bb[i+1]+b[i]
l=[]
for i in range(n):
    l.append(aa[i+1]+bb[i])
print(max(l))


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

#define int long long int
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define lb lower_bound
#define ub upper_bound
#define srt(a) sort(a.begin(),a.end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
#define mxe(a) *max_element(a.begin(),a.end())
#define mne(a) *min_element(a.begin(),a.end())
#define endl '\n'
#define mod 1000000007
#define INF64 1e18

/*int power(int a,int b){
  int res=1;
  while(b>0){
    if(b&1)(res*=a)%=mod;
    (a*=a)%=mod;
    b>>=1;
  }
  return res;
}*/
const int N=100005;
vi g[N];
vi dp(N);
int dfs(int u){
  if(dp[u])return dp[u];
  for(int v:g[u])
    dp[u]=max(dp[u],dfs(v)+1);
  return dp[u];
}
void solve(){
  int n,m;cin>>n>>m;
  for(int i=0;i<m;i++){
    int a,b;cin>>a>>b;
    g[a].pb(b);
  }
  int ans=0;
  for(int i=1;i<=n;i++)
    ans=max(ans,dfs(i));
  cout<<ans;
  
}

int32_t main(){
  #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
  #endif
  
  ios_base::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);

  int T=1;
  //cin>>T;
  for(int TT=1;TT<=T;TT++){
    solve();
  }
}

Measured memory_bytes: 11564
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
#include <list>
#include <iomanip>
#include <cctype>

using namespace std;

#define Int int64_t

void printVec(std::vector<int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

int vector_finder(std::vector<string> vec, string number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

#include <sstream> 
std::vector<std::string> StringSplit(const std::string& str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a * b / gcd(a, b);
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

int main() {
	int n; cin >> n;
	int cnt = 0;

	vector<int> base(n), p(n);

	for (int i = 0; i < n; i++) cin >> p[i];
	for (int i = 0; i < n; i++) base[i] = i + 1;

	for (int i = 0; i < n; i++) {
		if (p[i] != base[i]) cnt++;
	}
	if (cnt==0||cnt==2) cout << "YES";
	else cout << "NO";

	cout << endl;
	return 0;
}

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

int main() {
    int n; scanf("%d", &n);
    int a[n]; for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    auto end = unique(a, a + n);
    
    printf("%d", a[0]);
    auto itr = a; ++itr;
    for (; itr != end; ++itr) printf(" %d", *itr);
    printf("\n");
    return 0;
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {
   int r; cin >> r;
   long double ans = 2 * r * M_PI;
   cout << setprecision(20) << ans << endl;

}


Measured memory_bytes: 3784
########関数部分##############
def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out
############################
 
#####関数をつかってみる．#####
######今回は二進数に変換######
N, K = list(map(int,input().split()))
x2 = Base_10_to_n(N, K)
print( len(x2) )#"100011"が表示される．

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

#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;
typedef long long ll;

int main(){

    int n;
    cin >> n;

    vector<int> count(n + 1);

    rep(i, n - 1){
        int tmp;
        cin >> tmp;
        count[tmp]++;
    }

    rep(i, n){
        cout << count[i + 1] << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 3996
def solve(string):
    h, w, d, *a = map(int, string.split())
    n = h * w
    a, q, lr = a[:n], a[n], a[n + 1:]
    index = [0] * n
    for i, _a in enumerate(a):
        index[_a - 1] = i
    diff = [0] * d + [
        abs(i0 // w - i1 // w) + abs(i0 % w - i1 % w) for i0, i1 in zip(index, index[d:])
    ]
    for i in range(d, n):
        diff[i] += diff[i - d]
    return "\n".join([str(diff[r - 1] - diff[l - 1]) for l, r in zip(lr[::2], lr[1::2])])


if __name__ == '__main__':
    n, m, d = map(int, input().split())
    ins = '{} {} {}\n'.format(n, m, d) + '\n'.join([input() for _ in range(n)])
    n = int(input())
    print(solve(ins + '\n{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))


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

int main() {
    int n;
    cin >> n;
    vector<tuple<string, int, int>> q(n);
    rep(i, n) {
        string s;
        int p;
        cin >> s >> p;
        get<0>(q[i]) = s;
        get<1>(q[i]) = -p;
        get<2>(q[i]) = i + 1;
    }
    sort(q.begin(), q.end());
    rep(i, n) cout << get<2>(q[i]) << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)

int main(){
 ll N;
 string s,t;
 cin>>N>>s>>t;
 string ans((2*N),'a');
ll c=0;
 for(ll i=0;i<N;i++){
   ans[c] = s[i];
   c++;
   ans[c] = t[i];
   c++;
 }
cout<<ans<<endl;
}








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

int main() {
  int N, M; cin >> N >> M;
  auto A = vector<int>(N);
  for (int i = 0; i < N; ++i) cin >> A[i];
  auto S = vector<int>(N + 1, 0);
  for (int i = 0; i < N; ++i) S[i + 1] = (S[i] + A[i]) % M;

  ll ans = 0;
  auto mp = map<int, int>{{0, 1}};
  for (int i = 0; i < N; ++i) {
    ans += mp[S[i + 1]];
    ++mp[S[i + 1]];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3968
import std.stdio;
import std.ascii;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

struct MLong {
    bool overflow;
    long value;
}

const LIMIT = 1_000_000_000;

MLong pow(long x, long n) {
    //writeln("pow: ", [x, n]);
    if (n == 0) return MLong(false, 1);
    if (n % 2 == 1) {
        MLong ret = pow(x, n - 1);
        if (ret.overflow) return ret;
        if (x * ret.value > LIMIT) return MLong(true, 0);
        return MLong(false, x * ret.value);
    } else {
        if (x * x > LIMIT) return MLong(true, 0);
        return pow(x * x, n / 2);
    }
}
 
void main() {
    long N, T; scanf("%d %d\n", &N, &T);
    string s = readln.chomp;
    
    MLong parse() {
        int index = 0;
        long num() {
            long ret;
            while (index < s.length && s[index].isDigit) {
                ret = ret * 10 + (s[index] - '0');
                index++;
            }
            return ret;
        }
        MLong mono() {
            assert(s[index] == 'n'); index++;
            assert(s[index] == '^'); index++;
            long n = num;
            return pow(N, n);
        }
        MLong poly() {
            long ret = 0;
            while (true) {
                MLong m = mono;
                if (m.overflow) return MLong(true, 0);
                ret += m.value;
                if (ret > LIMIT) return MLong(true, 0);
                if (index == s.length) break;
                assert(s[index] == '+'); index++;
            }
            return MLong(false, ret);
        }
        return poly;
    }

    MLong ans = parse;
    if (ans.overflow || ans.value * T > LIMIT) {
        writeln("TLE");
    } else {
        writeln(ans.value * T);
    }
}

Measured memory_bytes: 1064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef int64_t lint;
constexpr double PI=3.14159265358979323846;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;

int main() {
	int N;
	cin >> N;
	if (N%1000 == 0) std::cout << "0" << '\n';
	else std::cout << 1000-N%1000 << '\n';
}


Measured memory_bytes: 3636
# include <iostream>
# include <cmath>
using namespace std;

long long A, B, C, K;
long long limit=1000000000000000000ll;
long long ans;

int main()
{
    cin>>A>>B>>C>>K;
    if (K%2==0)
    {
        ans=A-B;
    }

    else
    {
        ans=B-A;
    }

    if (abs(ans)>limit)
    {
        cout<<-1<<endl;
    }

    else
    {
        cout<<ans<<endl;
    }
}

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

#define ll long long

using namespace std;

int par[10001];
int rank_aa[10001];

void init(int n)
{
	for(int i=0;i<n;i++){
		par[i] = i;
		rank_aa[i] = 0;
	}
}

int find(int x)
{
	if (par[x]==x){
		return x;
	}else{
		return par[x] = find(par[x]);
	}
}

void unite(int x, int y)
{
	x = find(x);
	y = find(y);
	if (x == y) return;
	if (rank_aa[x] < rank_aa[y]){
		par[x] = y;
	}else{
		par[y] = x;
		if (rank_aa[x] == rank_aa[y]) rank_aa[x]++;
	}
}

bool same(int x, int y)
{
	return find(x) == find(y);
}

struct edge{ll u, v, cost;};

bool comp(const edge& x, const edge& y){
	return x.cost < y.cost;
}

edge es[10001];
ll V, E;

int main() {
	while(cin>>V>>E, V>0){
		for(int i=0; i<E; i++){
			int s, t, c; cin>>s>>t>>c;
			es[i].u = s-1;
			es[i].v = t-1;
			es[i].cost = c;
		}
		sort(es, es+E, comp);
		init(V);
		vector<int> ans;
		for(int i=0; i<E; i++){
			edge e = es[i];
			if (!same(e.u, e.v)){
				unite(e.u, e.v);
				ans.push_back(e.cost);
			}
		}
		ll mid;
		mid = ans[ans.size()/2];
		cout << mid << "\n";
	}
	return 0;
}


Measured memory_bytes: 3276
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ull unsigned long long
#define mp make_pair
#define F first
#define S second
#define mod 1000000007

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

    cout << 1-x << endl;


}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define gcd __gcd
#define all(x) (x).begin(), (x).end()
template<class T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<class T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
const int INF = 1e18, MOD = 1e9 + 7;
signed main() {
    INCANT;
    string s;
    cin>>s;
    int a[555555] = {};
    rep(i, s.size()){
        if(s[i] == '<'){
            chmax(a[i + 1], a[i] + 1);
        }
    }
    rev(i, s.size()){
        if(s[i] == '>'){
            chmax(a[i], a[i + 1] + 1);
        }
    }
    cout<<accumulate(a, a + s.size() + 1, 0ll)<<endl;
}


Measured memory_bytes: 5276
import Data.List

main = do
  (n:y:_) <- getLine >>= return . map read . words :: IO [Int]

  let d = [(i,j,k) | i<-[0..n], j<-[0..n-i], let k=n-i-j]

  putStrLn $ f (find (\(i,j,k) -> (i*10000+j*5000+k*1000) == y) d)
  where
    f Nothing = "-1 -1 -1"
    f (Just (i,j,k)) = unwords (map show [i,j,k])


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

typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

ld const inf = 1e18;
ll const maxn = 1e6+5;
ll const mod = 1e9+7l;

// code begins here

int main(){
    fast;
    
    ll n;
    cin>>n;
    
    vector<ll> arr(n), brr(n);
    
    for(ll i=0;i<n;i++)
        cin>>arr[i]>>brr[i];
    
    sort(arr.begin(), arr.end());
    sort(brr.begin(), brr.end());
    
    ll x,y;
    
    if(n%2){
        x = arr[n/2];
        y = brr[n/2];
    } else {
        x = arr[n/2] + arr[n/2 - 1];
        y = brr[n/2] + brr[n/2 - 1];
    }
    
    cout<<y-x+1<<endl;
    
    return 0;
}

Measured memory_bytes: 6352
def minimum_cost(N, M, X, gates):
    left = range(X, -1, -1)
    right = range(X, N + 1)

    left_cost = right_cost = 0
    for i in left:
        if i in gates:
            left_cost += 1
    
    for i in right:
        if i in gates:
            right_cost += 1

    min_cost = left_cost
    if min_cost > right_cost:
        min_cost = right_cost

    return min_cost


if __name__ == "__main__":
    N, M, X = list(map(int, input().rstrip().split(" ")))
    gates = [int(x) for x in input().rstrip().split(" ")]

    print(minimum_cost(N, M, X, gates))

Measured memory_bytes: 3064
import sys
import bisect
from collections import deque
import copy
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    plus_list = []
    minus_list = []
    for i in range(N):
        plus_list.append((i+1) + A[i])
        minus_list.append((i+1) - A[i])
    plus_list.sort()
    minus_list.sort()
    count = 0
    for i in range(N):
        count += bisect.bisect_right(minus_list, plus_list[i]) - bisect.bisect_left(minus_list, plus_list[i])
    print(count)

if __name__ == '__main__':
    main()


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

using namespace std;

void solve(int d, int i, int64_t current, vector<int64_t>& nums) {
  if (d == 0) {
    nums.push_back(current * 10 + i);
    return;
  }

  for (int diff = -1; diff <= 1; diff++) {
    int j = i + diff;
    if (0 <= j && j <= 9) {
      int64_t next = current * 10 + i;
      solve(d - 1, j, next, nums);
    }
  }
}

int main() {
  int K;
  cin >> K;
  vector<int64_t> nums;
  for (int d = 0; d < 1000; d++) {
    for (int i = 1; i <= 9; i++) {
      solve(d, i, 0, nums);
    }
    if ((int)nums.size() >= K) break;
  }
  cout << nums[K - 1] << endl;

  return 0;
}


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

using namespace std;

template <class M, class N>
common_type_t<M, N> gcd(M a, N b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}

using ll = long long;
vector<pair<ll, ll>> prime_factorize(ll n) {
  vector<pair<ll, ll>> cnts{{1, 1}};
  ll org_n = n;
  for (ll i = 2; i * i <= org_n; i++) {
    if (n % i != 0) {
      continue;
    }

    ll cnt = 0;
    while (n % i == 0) {
      n /= i;
      cnt++;
    }

    cnts.push_back({i, cnt});
  }

  if (n != 1) {
    cnts.push_back({n, 1});
  }

  return cnts;
}

int main(int argc, const char *argv[]) {
  ll a, b;
  cin >> a >> b;
  ll ab_gcd = gcd(a, b);
  auto prime_facts = prime_factorize(ab_gcd);
  cout << prime_facts.size() << '\n';
  return 0;
}

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

using namespace std;

int main(void) {
	int n;

	cin >> n;

	vector<int> a(n);

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

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

	if (a.size() % 2 == 0) {
		cout << a.size()-1 << endl;
	}
	else {
		cout << a.size() << endl;
	}
	return 0;
}

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

using ll = long long;
using namespace std;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;


int main() {
  string s,t;
  cin>>s>>t;
  int sn = int(s.size()),tn = int(t.size());
  int dp[3001][3001] = {0};
  for(int i(1);i<=sn;i++){
    for(int j(1);j<=tn;j++){
      if(s[i-1] == t[j-1]){
        dp[i][j] = dp[i-1][j-1] + 1;
      }else{
        dp[i][j] = max(dp[i][j-1],dp[i-1][j]);
      }
    }
  }
  for(int i(0);i<=sn;i++){
    for(int j(0);j<=tn;j++){
   //   cout << dp[i][j] << " ";
    }
    //cout << endl;
  }
  int i = sn,j = tn;
  string ans;
  while(i > 0 && j > 0){
    if (dp[i][j] == dp[i-1][j]) {
      --i;
    }else if (dp[i][j] == dp[i][j-1]) {
      --j;
    }else{
      ans = s[i-1] + ans; // このとき s[i-1] == t[j-1] なので、t[j-1] + res でも OK
      --i, --j; // DP の遷移を遡る
    }
  }
  //cout << dp[sn][tn] << endl;
  cout << ans << endl;
}

Measured memory_bytes: 35456
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
int a[20];
int main()
{     int n,m,i,j,k=0,sum=0,be=-10;
      cin>>n;
      if(n<1000||n>9999){
      	puts("No");
      	return 0;
      }
      while(n){
      	if(n%10!=be)k++,be=n%10;
      	a[k]++;
      	//cout<<n%10<<' '<<k<<' '<<a[k]<<endl;
      	n/=10;
      }
      sort(a+1,a+k+1);
      //cout<<a[9]<<endl;
      if(a[k]>=3)puts("Yes");
        else puts("No");
	  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){

  long x;
  long a,b;
  long happy;
  
  scanf("%ld", &x);
  
  a = x/500;
  b = (x % 500) / 5;
  
  happy = (1000*a) + (5*b);
  
  printf("%ld", happy);
    
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
	int a[32], b[32],c;
	int d = 0;
	a[0] = 1; a[1] = 1; a[2] = 2;
	b[0] = 1; b[1] = 1; b[2] = 1;
	for (int x = 3; x <= 30; x++){
		a[x] = a[x - 1] + a[x - 2] + a[x - 3];
		if (a[x] % 3650 == 0)b[x]=a[x]/3650;
		else b[x]=a[x]/3650+1;
	}
	while (1){
		cin >> d;
		if (d == 0)break;
		cout << b[d]<<endl;

	}
	return 0;
}


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




int N;
int A[101010];
//-----------------------------------------------------------------
#define INF 10101010;
vector<int> E[101010];
int dp[101010];
void dfs(int cur) {
	dp[cur] = 0;

	vector<int> v;
	for (int to : E[cur]) {
		dfs(to);
		v.push_back(dp[to]);
	}
	sort(v.begin(), v.end(), greater<int>());
	rep(i, 0, v.size()) dp[cur] = max(dp[cur], i + 1 + v[i]);
}
//-----------------------------------------------------------------
int main() {
	cin >> N;
	rep(i, 1, N) scanf("%d", &A[i]), A[i]--;

	rep(i, 1, N) E[A[i]].push_back(i);
	dfs(0);

	//rep(i, 0, N) printf("dp[%d] = %d\n", i, dp[i]);

	printf("%d\n", dp[0]);
}

Measured memory_bytes: 14336
#045b
from collections import deque

card = dict()
card["a"] = deque(input())
card["b"] = deque(input())
card["c"] = deque(input())

#print(card)

next_person = card["a"].popleft()

while True:
    #print(next_person,card)
    if len(card[next_person]) == 0:
        print(next_person.upper())
        break
    else:
        next_person = card[next_person].popleft()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
	int a,b;
	cin >> a >> b;
	int c = 1;
	int ans = 0;
	while(c<b){
		c+=a-1;
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3528
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

int main(){
  int n,m;
  cin>>n>>m;
  cout<<(n-1)*(m-1)<<endl;

  return 0;
}


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

int main(){
    string s;
    cin >> s;
    for(int i=1; i<s.size(); i++){
        if(s[i] == s[i-1]){
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[100001];
int main()
{
	int n,i,j,s=0,x;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&x);
		if(x<=100000&&a[x]<x)
		{
			a[x]++;
			if(a[x]>=x)
			s+=x;
		}
	}
	printf("%d\n",n-s);
}

Measured memory_bytes: 256
<?php
  $n = trim(fgets(STDIN));
  $yen = 0;
  $btc = 0;
  for($i=0; $i<$n; $i++){
      fscanf(STDIN, "%f %s", $x, $u);
      if($u == "JPY"){
          $yen += $x;
      }else{
        //   echo $x;
          $btc += $x;
      }
  }
//   echo $btc;
  echo $yen+($btc*380000);

Measured memory_bytes: 16192
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int dx[] = {0, 0, 1, -1};
constexpr int dy[] = {1, -1, 0, 0};

V g[112345];
int n, k;
int res = 0;
bool d[112345];

int dfs(int p)
{
    int rnk = 1;
    for (int i : g[p])
        rnk = max(rnk, dfs(i) + 1);

    if (d[p])
        return 0;

    if (rnk == k)
    {
        res++;
        rnk = 0;
    }

    return rnk;
}

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

    cin >> n >> k;

    fill(d, d + n, false);

    REP(i, n)
    {
        int a;
        cin >> a;
        if (i == 0)
            res += a != 1;
        else
        {
            g[a].push_back(i + 1);
            if (a == 1)
                d[i + 1] = true;
        }
    }

    d[1] = true;

    dfs(1);

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 10752
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<cmath>
#include<sstream>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<utility>
#include<iomanip>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<list>
#include<set>
#include<stdlib.h>
#include<time.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,k,n) for(int i=k;i<(int)n;i++)
using namespace std;
const int dx[4] = { 0, 1, 0, -1 }, dy[4] = { 1, 0, -1, 0 };
const int dX[8] = { 0, 1, 1, 1, 0, -1, -1, -1 }, dY[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
struct XY
{
	int x;
	int y;
};
vector<long long> Prime;
void SieveOfEratosthenes(long long e) //setup vector<long long>Prime(~x)
{
	bool *x=new bool[e];
	for (long long i = 0; i <= e; i++)x[i] = false;
	for (long long i = 2; i <= e; i++)
	{
		if (x[i]);
		else
		{
			Prime.push_back(i);
			for (long long l = i; l <= e; l += i)x[l] = true;
		}
	}
	return;
}
int StringToInt(string a)
{
	stringstream ss;
	int x;
	ss << a;
	ss >> x;
	return x;
}
string IntToString(int a)
{
	stringstream ss;
	string x;
	ss << a;
	ss >> x;
	return x;
}
int GetRandom(int MIN, int MAX)
{
	static int flag=0;
	if (flag == 0)
	{
		srand((unsigned int)time(NULL));
		flag = 1;
	}
	return MIN + (int)(rand()*(MAX - MIN + 1.0) / (1.0 + RAND_MAX));
}
int in()
{
	int x;
	cin >> x;
	return x;
}
void outl(string a)
{
	cout << a << endl;
	return;
}
void outl(int a)
{
	cout << a << endl;
	return;
}
void out(string a)
{
	cout << a;
	return;
}
void out(int a)
{
	cout << a;
	return;
}
/*
(char)'1' - (int)48 = (int)1;
???1111181
 (char)A=(int)65
 (char)a=(int)97
*/
////////////////////////////////////////////////////

int main()
{
	int n;
	while (cin >> n&&n)
	{
		int num[20];
		rep(i, 20)num[i] = i;
		vector<pair<int, int> > a;
		string na[20];
		for (int i = 0; i < n; i++)
		{
			cin >> na[i];
			pair<int, int> z;
			z.first = 0;
			z.second = 0;
			a.push_back(z);
			for (int j = 0; j < n - 1; j++)
			{
				int g = in();
				if (g == 0)a[i].first++;
				else if (g == 1)a[i].second++;
			}
		}

		bool end = true;
		while (end)
		{
			end = false;
			for (int i = 1; i < a.size(); i++)
			{
				if (a[i].first > a[i - 1].first)
				{
					end = true;
					swap(a[i], a[i - 1]);
					swap(num[i], num[i - 1]);
				}
				else if (a[i].first == a[i - 1].first&&a[i].second < a[i-1].second)
				{
					end = true;
					swap(a[i], a[i - 1]);
					swap(num[i], num[i - 1]);
				}
				else if (a[i].first == a[i - 1].first&&a[i].second == a[i - 1].second&&num[i] < num[i - 1])
				{
					end = true;
					swap(a[i], a[i - 1]);
					swap(num[i], num[i - 1]);
				}

			}
		}

		for (int i = 0; i < a.size(); i++)
		{
			cout << na[num[i]] << endl;


		}



	}
}

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


static const int N=100;

int main()
{
    int M[N][N];//0 origin Adjacency matrix
    int n,u,k,v;

    cin >> n;

    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++) M[i][j]=0;
    }

    for(int i = 0; i < n; i++)
    {
        cin>>u>>k;
        u--; //0 origin
        for(int j = 0; j < k; j++)
        {
            cin>>v;
            v--; //0 origin
            M[u][v]=1;//uとvの間に辺を張る
        }
    }


    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            if(j) cout << " ";
            cout<<M[i][j];
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3132
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int[] num = new int[3];

    num[0] = a + b;
    num[1] = a - b;
    num[2] = a * b;

    Arrays.sort(num);

    System.out.println(num[2]);
  }
}

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

int main() {
  int a,b;
  cin>>a>>b;
  if((b-1)%(a-1)==0){
    cout<<(b-1)/(a-1)<<endl;
  }
  else{
    cout<<(b-1)/(a-1)+1<<endl;
  }
  
}

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

int main() {
    int n;
    cin >> n;
    string s = "No";

    for(int i= 0; i <= n/4; i++) {
        for(int j = 0; j <= n/7; j++) {
            if(i*4 + j*7 == n) {
                s = "Yes";
            }
        }
    }
    cout << s << endl;
}

Measured memory_bytes: 384
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#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 <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=998244353;
const int MAXN=600005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	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<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
int f[1<<18][55];
PR a[MAXN];
int main()
{
	int n=read();
	for (int i=1;i<=n;i++) a[i].fi=read();
	for (int i=1;i<=n;i++) a[i].se=read();
	for (int i=0;i<1<<n;i++)
		for (int j=0;j<=50;j++) f[i][j]=INF; 
	f[0][1]=0;
	for (int i=1;i<1<<n;i++)
	{
		int t=__builtin_popcount(i);
		for (int p=1;p<=n;p++)
		if ((i>>(p-1))&1)
		{
			int j=(abs(t-p)&1)?a[p].se:a[p].fi,num=0;
			for (int k=p+1;k<=n;k++) if ((i>>(k-1))&1) num++;  
			for (int k=1;k<=j;k++) upmin(f[i][j],f[i^(1<<(p-1))][k]+num);
		}
	}
	int ans=INF;
	for (int i=1;i<=50;i++) upmin(ans,f[(1<<n)-1][i]);
	printf("%d\n",ans==INF?-1:ans);
	return 0;
}


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

int main() {
int a,b,c,d;
cin >> a >> b >> c >> d;
  //直接的に会話できない　かつ　関節的にも会話できないときNo
 if( abs(a-c) >d && !(abs(a-b)<=d && abs(b-c)<=d)) cout << "No" << endl;
  else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    string s;cin>>s;
    int n=s.size();
    rep(i,n) cout<<'x';
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int a,b,c,d,count;
    char e;
  count =0;
  	string s;
  	cin>>a>>b>>c;
  if(a+b<=c||a>c)  
     cout<<"NO"<<endl;
  else
    cout<<"YES"<<endl;
  
  return 0;
}

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


int ASC(const void *a, const void *b) {
	return *(int *)b - *(int *)a;//降順
}
int GCD(int a, int b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
long long a[200000];
int main(void)
{
	int s, w;
	scanf("%d%d",&s,&w);
	if (s <= w)
		printf("unsafe");
	else
		printf("safe");
	return 0;
}

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

int main(){
    string str,order,p;
    int q,a,b,i,j;
    char swap;

    cin >> str;
    cin >> q;
    for(i=0;i<q;i++){
        cin >> order >> a >> b;
        if(order == "print"){
            for(j=a;j<=b;j++){
                cout << str[j];
            }
            cout << endl;
        }else if(order == "reverse"){
            for(j=0;j<(b-a)/2+1;j++){
                swap = str[a+j];
                str[a+j] = str[b-j];
                str[b-j] = swap;
            }
        }else if(order == "replace"){
            cin >> p;
            for(j=0;j<b-a+1;j++){
                str[j+a] = p[j];
            }
        }
    }
    return 0;
}



Measured memory_bytes: 3172
#include <math.h>

#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, x, t;
  cin >> n >> x >> t;

  cout << (n % x == 0 ? t * (n / x) : t * (1 + (n / x)));
  return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
using namespace std;                       
typedef long long ll;
  int main()
  {  int n,m;
     cin>>n>>m;
     if(n>m)
      cout<<"safe"<<endl;
      else
      cout<<"unsafe"<<endl;
  }

Measured memory_bytes: 3632