akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

"""Minimum Spanning Tree"""

import sys
import os
import pprint

DEBUG = False

#fd = os.open('ALDS1_12_A.txt', os.O_RDONLY)
#os.dup2(fd, sys.stdin.fileno())

n = int(input())

# n x n matrix
M = []
for i in range(n):
    l = list(map(int, input().split()))
    M.append(l)

# Prim's Algorithm
INF = 1000000
visited = [False] * n
parent = [None] * n

# 0 is in T (Tree)
parent[0] = None

# distance between T and T-V
distance = [INF] * n
distance[0] = 0

while True:
    min_dist = INF
    candidate_index = None
    for i in range(n):
        if not visited[i] and distance[i] < min_dist:
            min_dist = distance[i]
            candidate_index = i

    if candidate_index is None:
        break

    if DEBUG:
        print('accepted i', candidate_index)
    visited[candidate_index] = True
    distance[candidate_index] = -1  # done

    for i in range(n):
        if not visited[i] and M[candidate_index][i] != -1 and distance[i] > M[candidate_index][i]:
            distance[i] = M[candidate_index][i]
            parent[i] = candidate_index


# Trees length
_sum = 0
for i in range(n):
    if parent[i] is not None:
        d = M[i][parent[i]]
        _sum += d
print(_sum)

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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end



int main(){
   int k; cin>>k;
   string s; cin>>s;
   if(s.size()<=k)cout<<s<<endl;
   else cout<<s.substr(0,k)+"..."<<endl;
   return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i,N) cin >> a.at(i);
    int ans = 0;
    for (int i = 0; i * 2 < N; ++i) {
        if (a.at(i * 2) % 2 == 1) ++ans;
    }
    cout << ans << endl;
}


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

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

    int n;
    cin >> n;
    long long H[n];
    set<long long> st;
    for(int i = 0; i < n; i++){
        cin >> H[i];
        st.insert(H[i]);
    }

    if(st.size() == 1){
        cout << H[0] << endl;
        return 0;
    }

    long long ans = 0, bl = 0;
    for(int i = 1; i < n; i++){
        if(H[i - 1] > H[i]){
            ans += H[i - 1] - bl;
            bl = H[i];
        }else if(H[i - 1] < H[i]){
            ans += H[i] - bl;
            bl = H[i];
        }
        //cout << ans << ' ';
    }
    //cout << endl;

    cout << ans << endl;



    return 0;
}

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

#define reps(i,j,k) for(int i=(j); i<(k); i++)
#define rep(i,j) reps(i,0,j)
#define fs first
#define fr fs
#define sc second
#define pb push_back
#define mk make_pair

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
char moth[] = {'a','i','u','e','o'};
int main(){
	int N;
	while(cin >> N,N){
		string str[100];
		int mx = -1;
		rep(i,N){
			cin >> str[i];
			mx = max(mx,(int)str[i].size());
		}
		string splited[100];
		rep(i,N){
			string tmp = "";
			tmp += str[i][0];
			reps(j,1,str[i].size()){
				rep(q,5){
					if(str[i][j-1] == moth[q]){
						tmp += str[i][j];
					}
				}
			}
			splited[i] = tmp;
		}
		int ans = -1;
		reps(k,1,mx+1){
			string strtmp[100];
			rep(i,N){
				strtmp[i] = "";
				rep(j,min(k,(int)splited[i].size())){
					strtmp[i] += splited[i][j];
				}
			}
			bool flg = false;
			rep(i,N){
				rep(j,N){
					if(i == j)continue;
					if(strtmp[i] == strtmp[j]){
						flg = true;
						break;
					}
				}
				if(flg)break;
			}
			if(!flg){
				ans = k;
				break;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3168
n = int(input())
if n < 600:
    print(8)
elif n < 800:
    print(7)
elif n < 1000:
    print(6)
elif n < 1200:
    print(5)
elif n < 1400:
    print(4)
elif n < 1600:
    print(3)
elif n < 1800:
    print(2)
elif n < 2000:
    print(1)

Measured memory_bytes: 9176
from copy import deepcopy
from functools import reduce

class Divisor:
    def __init__(self, n):
        """ make divisors list and prime factorization list of n"""
        number = n
        if number == 1:
            self.primeFactorization = {1: 1}
        else:
            self.primeFactorization = {}
            for i in range(2, int(n**0.5)+1):
                cnt = 0
                while number % i == 0:
                    cnt += 1;
                    number //= i
                if cnt > 0:
                    self.primeFactorization[i] = cnt
            if number > 1:
                self.primeFactorization[number] = 1

    def primeFactors(self):
        return deepcopy(self.primeFactorization)

    def numDivisors(self):
        """ the number of divisors """
        if self.primeFactorization.get(1, 0) == 1:
            return 1
        numDiv = 1
        for _, cnt in self.primeFactorization.items():
            numDiv *= cnt+1
        return numDiv

    def sumDivisors(self):
        return reduce(lambda x, y: x * y, [sum(p**i for i in range(n+1)) for p, n in self.primeFactorization.items()])

def divisorsList(n):
    divsList = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divsList.append(i)
            if n // i != i:
                divsList.append(n//i)
    return sorted(divsList)

N = int(input())
p = Divisor(N)
print('{}: '.format(N), end='')
ans = []
print(*[d for d, cnt in sorted(p.primeFactors().items()) for i in range(cnt)])

Measured memory_bytes: 7376
#coding:utf-8
import sys,os
from collections import defaultdict, deque
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    N = II()
    S1 = input()
    S2 = input()

    pre_s1 = S1[0]
    pre_s2 = S2[0]
    if pre_s1 == pre_s2:
        ans = 3
        i = 1
    else:
        ans = 6
        i = 2

    while i < N:
        if pre_s1 == pre_s2:
            ans *= 2
            ans %= MOD
            if S1[i] == S2[i]:
                d = 1
            else:
                d = 2
        else:
            if S1[i] == S2[i]:
                d = 1
            else:
                ans *= 3
                ans %= MOD
                d = 2
        pre_s1 = S1[i]
        pre_s2 = S2[i]
        i += d
                
    print(ans)
    

    

if __name__ == '__main__':
    main()

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

using namespace std;

int solve(vector<int> a) {
    int n = a.size();
    int sum = 0;
    for (auto x: a) sum += x;
    int mn = 100000;
    int idx = 0;
    for (int i = 0; i < n; i++) {
        int x = a[i];
        if (abs(x * n - sum) < mn) {
            mn = abs(x * n - sum);
            idx = i;
        }
    }
    return idx;
}

void process() {
    int n;
    vector<int> a;
    cin >> n;
    a.resize(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    cout << solve(a);
}

int main() {
    process();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <bitset>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>
#include <sstream>
#include <math.h>

using namespace std;

#define ll long long int
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecchar vector<char>
#define vecstr vector<string>
#define vecbool vector<bool>
#define vec2bool vector<vector<bool>>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(ll s = a;s < b;s++)
#define forllde(s,a) for(ll s = a;s > 0;s--)

#define Pi 3.1415926535897932384626

int main() {
	ll n, q, ans = 0;
	string s;
	bool flag = false;

	cin >> n;

	vecll a(n);

	forll(i, 0, n)
		cin >> a[i];

	cin >> q;

	vecpairll x(q);

	forll(i, 0, q)
		cin >> x[i].first >> x[i].second;

	vec2ll list(100000);

	forll(i, 0, n)
	{
		list[a[i] - 1].push_back(i);
	}

	forll(i, 0, n)
	{
		ans += a[i];
	}

	forll(i, 0, q)
	{
		ll diff = x[i].second * list[x[i].first - 1].size() - x[i].first * list[x[i].first - 1].size();
		ll count = list[x[i].first - 1].size();
		forll(j, 0, count)
		{
			list[x[i].second - 1].push_back(list[x[i].first - 1][count - j - 1]);
			list[x[i].first - 1].pop_back();
		}
		ans += diff;

		cout << ans << "\n";
	}
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

#define MAXV 100

int main(){
  int v,e;cin>>v>>e;
  ll g[MAXV][MAXV];
  rep(i,v)rep(j,v)g[i][j]=INF;
  rep(i,v)g[i][i]=0;
  rep(i, e){
    int s,t,d;cin>>s>>t>>d;
    g[s][t]=d;
  }

  rep(k, v)rep(i, v)rep(j, v)if(g[i][k]!=INF && g[k][j]!=INF)g[i][j] = min(g[i][j], g[i][k]+g[k][j]);

  rep(i, v)if(g[i][i]<0){cout<<"NEGATIVE CYCLE"<<endl; return 0;}

  rep(i, v){
    rep(j, v){
      if(g[i][j]==INF)cout<<"INF";
      else cout<<g[i][j];
      if(j<v-1)cout<<' ';
    }
    cout<<endl;
  }

  return 0;
}



Measured memory_bytes: 3156
'''catupper
ポイントA.再帰DFSで全ての頂点というか、辺をチェック。
ポイントB.入力に注意。頂点の連結が辺になっている。
辺は頂点を結ぶので(a[i], b[i])で表現され、対応する色を
color_dict[(a[i], b[i])]としている。
配列が二重配列になっているので、注意。
ポイントC.色を頂点の順番で辺毎に出力する。辺の数は頂点-1個。
for i in range(n-1):  
    print(color_dict[(a[i], b[i])])
疑問点：色が新しくなるのは分かるけど、
色が1から再び使えるようになる仕組みは下の通りで良いのか？
'''

import sys
sys.setrecursionlimit(1000000)#DFSは再帰の上限回数に注意

n = int(input())
edge = [[] for i in range(n)]
#どの頂点とどの頂点が繋がっているかを格納しておく配列
a = [0] * n#頂点aに繋がっている頂点bの番号を格納しておく配列
b = [0] * n

color_dict = {}#色を覚えておく
k = 0

def dfs(x, last = -1, ban_color = -1):
#lastは、どこから来たか、逆走を防ぐ。使っちゃいけない色も引数
#最初は、どこからも来ないし、どの色もOK
    global k#グローバル変数、宣言を忘れない
    color = 1#次の頂点については、再び1からチェックする
    #但し、繋がっている前の頂点と結ばれている辺の色は使えない
    for to in edge[x]:
    #このfor文はある頂点から繋がる次の頂点への辺の色を次々と決めている
    #同じ頂点に繋がる辺は同じ色に出来ないので、次々、色を新しくする
    #配列edgeに格納されている次の頂点toを順番にチェック。
    #全ての頂点をチェックすればオシマイ。
        if to == last:continue
        #来た頂点に戻ろうとしたら、何もしない(条件1)
        if color == ban_color:color += 1
        #いま見ている頂点へ来た辺に使っている色なら、
        #新しい色にする(条件2)
        color_dict[(x, to)] = color
        #使う色をタプルで配列に格納する(作業)
        dfs(to, x, color)
        #深さ優先探索なので深く探索できる限り次から次へと探索する。
        #イメージ的には一つ下の階層の頂点を探索する。
        #次の頂点toについてDFS。来たのはxから。前の頂点で使った色はダメ。
        color += 1#いま見ている頂点から繋がる他の頂点へ行く辺の色として
        #新しい色を用意しておく(注意)
    k = max(k, color-1)    #何色を使ったか、覚えておく。
    #用意した新しい色(上記の注意)は、まだ使っていないからcolor-1。

for i in range(n-1):
    a[i], b[i] = map(int, input().split())
    a[i] -= 1#0-indexにする
    b[i] -= 1
    edge[a[i]].append(b[i])#無向グラフとして入力する
    edge[b[i]].append(a[i])

dfs(0)#最初の頂点をDFSに入れてスタート
#print(color_dict)　　DFSして始めて、color_dictが出来る

print(k)#まず、必要となる色数を出力
for i in range(n-1):#辺の色を1から頂点番号-1まで出力
    print(color_dict[(a[i], b[i])])
'''  以下の場合分けは不要。
    if (a[i], b[i]) in color_dict:#辞書から答を出力
        print(color_dict[(a[i], b[i])])
    else:
        print(color_dict[(b[i], a[i])])
'''

Measured memory_bytes: 84516
#include <bits/stdc++.h>
#define int int64_t
using namespace std;

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int k,n;
	cin >> k >> n;
	for (int i=n-k+1; i<=n+k-1; ++i){
		cout << i << ' ';	
	}
	return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

// NextLine reads a line text from stdin, and then returns its string.
func NextLine() string {
	sc.Scan()
	return sc.Text()
}

// NextIntsLine reads a line text, that consists of **ONLY INTEGERS DELIMITED BY SPACES**, from stdin.
// And then returns intergers slice.
func NextIntsLine() []int {
	ints := []int{}
	intsStr := NextLine()
	tmp := strings.Split(intsStr, " ")
	for _, s := range tmp {
		integer, _ := strconv.Atoi(s)
		ints = append(ints, integer)
	}
	return ints
}

// NextRunesLine reads a line text, that consists of **ONLY CHARACTERS ARRANGED CONTINUOUSLY**, from stdin.
// Ant then returns runes slice.
func NextRunesLine() []rune {
	return []rune(NextLine())
}

// -----------------------------------

var h, w int
var S [][]rune
var memo [60][60]int

const inf = 1000000

type node [3]int

func main() {
	tmp := NextIntsLine()
	h, w = tmp[0], tmp[1]
	for i := 0; i < h; i++ {
		row := NextRunesLine()
		S = append(S, row)
	}

	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			memo[i][j] = inf
		}
	}

	delta := [4][2]int{
		[2]int{0, 1},
		[2]int{1, 0},
		[2]int{0, -1},
		[2]int{-1, 0},
	}

	queue := []node{}
	queue = append(queue, node{0, 0, 0})
	memo[0][0] = 0
	for len(queue) > 0 {
		now := queue[0]
		queue = queue[1:]
		ny, nx := now[0], now[1]

		if ny == h-1 && nx == w-1 {
			break
		}

		for _, d := range delta {
			dy, dx := ny+d[0], nx+d[1]
			if 0 <= dx && dx < w && 0 <= dy && dy < h {
				if memo[dy][dx] == inf && S[dy][dx] == '.' {
					queue = append(queue, node{dy, dx, now[2] + 1})
					memo[dy][dx] = now[2] + 1
				}
			}
		}
	}

	if memo[h-1][w-1] == inf {
		fmt.Println(-1)
	} else {
		x := memo[h-1][w-1] + 1
		b := 0
		for i := 0; i < h; i++ {
			for j := 0; j < w; j++ {
				if S[i][j] == '#' {
					b++
				}
			}
		}
		answer := h*w - x - b
		fmt.Println(answer)
	}
}


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

using namespace std;

#define PI          3.1415926535897932384626433832795l

#define pb push_back
#define mp make_pair
#define lb lower_bound // First element which is not less than val
#define ub upper_bound // First element greater than val
#define f first
#define s second

#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vpii = vector<pair<int,int>>;
using vpll = vector<pair<ll,ll>>;

using pii = pair<int,int>;
using pll = pair<ll,ll>;

#define endl '\n'
#define re return

#define rep(i,a,b) for (ll i = (a); i < (b); i++)
#define repz(i, a) for (ll i = 0; i < (a); i++)
#define repd(i,a,b) for (ll i = (a); i >= b; i--)
#define repdz(i,a) for (ll i = a; i >=0; i--)
#define trav(a, x) for (auto& a : x)

#define vecin(n,v) for(ll i = 0; i < n; i++) cin>>v[i];
#define llin(a) ll a; cin>>a;
#define llin2(a,b) ll a,b; cin >>a>>b;
#define llin3(a,b,c) ll a,b,c; cin>>a>>b>>c;
#define full(v) v.begin(),v.end()

void solve()
{
    int n,x;
    cin >> x >> n;

    set<int> s;

    repz(i,n)
    {
        int y;
        cin >> y;
        s.insert(y);
    }

    int l = -1,r = -1;
    for (int i = x; i < 107; i++)
    {
        if (!s.count(i))
        {
            l = i;
            break;
        }
    }

    for (int i = x; i >= 0; i--)
    {
        if (!s.count(i))
        {
            r = i;
            break;
        }
    }


    if (abs(x-r) < abs(x-l))
    {
        cout << r << endl;
    }
    else if (abs(x-l) < abs(x-r))
    {
        cout << l << endl;
    }
    else
    {
        cout << r << endl;
    }

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //llin(t);
    //while (t--)
    //{
        solve();
    //}
}


Measured memory_bytes: 3664
#include<iostream>
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
int main(){
	unsigned int a,b;
	unsigned int c,d;
	int area2=0;
	int area1=0;
	scanf("%d %d",&a,&b);
	area1=a*b;
	scanf("%d %d",&c,&d);
	area2=c*d;
	if(area1>area2)
	printf("%d",area1);
	else if(area2>area1)
	printf("%d",area2);
	else
	printf("%d",area1);
	return 0;
}

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

int main() {
  int N, H, W;
  cin >> N >> H >> W;

  int ans = 0;
  for (int i = 0; i < N; i++) {
    int A, B;
    cin >> A >> B;
    if (A >= H && B >= W) ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define M 100000
#define N -1

struct A{ int parent, left, right;};

struct A B[M];

int  C[M];

int get(int z){
  
  int x=0;
  
  while(B[z].parent!=N){
    
    z=B[z].parent;
    
    x++;
  }
  return x;
}

void pr(int z){
  
  int i, c;
  
  printf("node %d: ", z);
  
  printf("parent = %d, ", B[z].parent);
  
  printf("depth = %d, ", C[z]);

  if ( B[z].parent == N) printf("root, [");
  
  else if ( B[z].left == N) printf("leaf, [");
  
  else printf("internal node, [");

  for(i = 0, c = B[z].left; c != N; i++, c = B[c].right){
    
    if (i) printf(", ");
    
    printf("%d", c);
  }
  printf("]\n");
}



int main(){
  
  int i,j,n,a,b,c,d,e;
  
  scanf("%d", &n);
  
  for ( i = 0; i < n; i++ ){
    
    B[i].parent = B[i].left = B[i].right = N;
    
  }
  
  for ( i = 0; i < n; i++ ){
    
    scanf("%d%d",&b,&c);
    
    for ( j = 0; j < c; j++ ){
      
      scanf("%d", &e);
      
      if ( j == 0 ) B[b].left = e;
      
      else B[d].right = e;
      
      d = e;
      
      B[e].parent =b;
    }
  }
  
  a=0;
  
  for ( i = 0; i < n; i++ ){
    
    C[i] = get(i);
    
    if ( C[i] > a ){
      
      a = C[i];
    }
  }

  for ( i = 0; i < n; i++ ){
    
    pr(i);
    
  }
  
  return 0;
}





Measured memory_bytes: 3348
#include <iostream>
using namespace std;
int main(){
    int a,b ;
    cin >> a >> b;
    while(a != 0 || b != 0){
        for(int i=1;i<=a;i++){
            if(i%2==1){
                for(int h=1;h<=b;h++){
                    if(h%2==1){
                        cout <<"#";
                    } else {
                        cout <<".";
                    }
                }
                cout << endl;
            } else {
                for(int h=1;h<=b;h++){
                    if(h%2==1){
                        cout <<".";
                    } else {
                        cout <<"#";
                    }
                }
                cout << endl;
            }
        }
        cout << endl;
        cin >> a >> b;
    }
}


Measured memory_bytes: 3104
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll x, y;
    cin >> x >> y;

    if(x%y == 0) {
        out(-1);
    }
    else {
        out(x);
    }
    
    re0;
}

Measured memory_bytes: 256
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        S: chars,
    }
    let mut dict = HashMap::new();
    for c in S.iter() {
        *dict.entry(c).or_insert(0) += 1;
    }
    let mut flag = true;
    for (k, v) in dict.iter() {
        if *v != 2 {
            flag = false
        }
    }

    println!("{}", if flag == true {"Yes"} else {"No"});
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <climits>
//#include "h.h"
using namespace std;

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(first, second) pb(mp(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()

int main(){

	while(true){
		int W, H;
		cin >> W >> H;
		if(W == 0 && H == 0)break;
		vector<string> S(H);
		queue<pair<int, int>> Q;
		for(int i = 0; i < H; i ++){
			cin >> S[i];
			for(int j = 0; j < W; j ++){
				if(S[i][j] == '@')Q.push(mp(i, j));
			}
		}
		pair<int, int> P;
		while(!Q.empty()){
			P = Q.front();
			Q.pop();
			S[P.first][P.second] = '@';
			if(P.first > 0 && S[P.first - 1][P.second] == '.')Q.push(mp(P.first - 1, P.second));
			if(P.first < H - 1 && S[P.first + 1][P.second] == '.')Q.push(mp(P.first + 1, P.second));
			if(P.second > 0 && S[P.first][P.second - 1] == '.')Q.push(mp(P.first, P.second - 1));
			if(P.second < W - 1 && S[P.first][P.second + 1] == '.')Q.push(mp(P.first, P.second + 1));
		}
		int ans = 0;
		for(int i = 0; i < H; i ++){
			for(int j = 0; j < W; j ++){
				if(S[i][j] == '@')ans ++;
			}
		}
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 6056
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)){
			int n = sc.nextInt();
			long [] array = new long [n];
			for (int i=0; i<n; i++) {
				 array[i] = sc.nextLong();
			}
			int times = sc.nextInt();
			for (int i=0; i<times; i++) {
				int b = sc.nextInt();
				int e = sc.nextInt();
				int t = sc.nextInt();
				for (int k=0; k< e - b; k++) {
					long temp = array[b+k];
					array[b+k] = array[t+k];
					array[t+k] = temp;
				}
			}
			for (int i=0; i<n - 1; i++) System.out.print(array[i] + " ");
			System.out.println(array[n - 1]);
		}
	}
}



Measured memory_bytes: 37008
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define bg begin()
#define end end()
#define sz size()
#define vi vector<int>
#define vl vector<long long int>
int main(){
	fast;
	string val;
	cin>>val;
	int f[26]={0};
	for(int i=0;i<val.length();i++)
		f[val[i]-97]++;
	for(int i=0;i<val.length();i++)
		if(f[i]>1)
		{
			cout<<"no";
			return 0;
		}
	cout<<"yes";
	return 0;
}



Measured memory_bytes: 3648
///*
#include<iostream>
#include<string>
using namespace std;

int main() {

	string name;
	cin >> name;

	if (name[0] == name[1] && name[1] == name[2] && name[2] == name[0]) {
		cout << name;
		//cout << "case1";
	}
	else if (name[0] != name[1]) {
		if (name[0] > name[1]) {
			for (int i = 0; i < 3; i++) {
				cout << name[0];
			}
			//cout << "case2";
		}
		else {
			for (int i = 0; i < 3; i++) {
				cout << char(name[0] + 1);
			}
			//cout << "case3";
		}
	}
	else {
		if (name[0] > name[2]) {
			for (int i = 0; i < 3; i++) {
				cout << name[0];
			}
			//cout << "case4";
		}
		else {
			for (int i = 0; i < 3; i++) {
				cout << char(name[0] + 1);
			}
			//cout << "case5";
		}
	}
	

	return 0;
}
//*/

Measured memory_bytes: 256
//file_name:ABC67_A.cpp
#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 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 sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<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 vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Possible");}else{puts("Impossible");}
const int MX = 200005;

    // int scan
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // matrix scan
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // string scan
    /*
    string s;
    cin >> s;
    */


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


    if(a%3==0||b%3==0||(a+b)%3==0)yn;

    //cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>

#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
#define rep_r(i,s,n)for(int i = n-1;i>=0;i--)
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_M = 100001;

int main() {
	ll n, m; cin >> n >> m;
	vector<ll> v;
	for (int i = 1; i*i <= m; i++) {
		if (!(m % i)) {
			v.push_back(i);
			if (i*i != m) v.push_back(m / i);
		}
	}
	ll d = m / n;

	ll ans = 0;
	rep(i, 0, v.size()) {
		if (v[i] <= d && v[i] > ans) {
			ans = v[i];
		}
	}
	cout << ans << endl;

	return 0;
}

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

int main(){
    int n, l; cin >> n >> l;
    map<string,int> mp;
    rep(i,n){
        string s;
        cin >> s;
        mp[s]++;
    }

    for(auto a:mp){
        if(a.second == 1) cout << a.first;
        else{
            rep(i,a.second){
                cout << a.first;
            }
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

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

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

ll dp[100001];
ll n;
ll ans;
void rec(ll counter, ll amount) {

}

int main() {
    
    cin >> n;
    ans = n;
    memset(dp, 0, sizeof(dp)); 
    dp[0] = 0;

    FOR(i, 1, n+1) {
        dp[i] = dp[i-1] + 1;
        ll temp = 6;
        while((i-temp)>=0) {
            chmin(dp[i], dp[i-temp]+1);
            temp *=6 ;
        }
        temp = 9;
        while((i-temp)>=0) {
            chmin(dp[i], dp[i-temp]+1);
            temp *= 9;
        }
    }

    print(dp[n]);
    return 0;
}


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

using namespace std;

bool isMonth(char a,char b){
	if(a >= '2')return false;
	if(a == '0' && b == '0')return false;
	if(a == '1' && b > '2')return false;
	return true;
}


int main(){
	#ifdef EVAL
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	string S;
	cin >> S;
	bool mmyy = isMonth(S[0],S[1]),yymm = isMonth(S[2],S[3]);
	if(yymm && mmyy){
		cout << "AMBIGUOUS";
	}else{
		if(!yymm && !mmyy){
			cout << "NA";
		}else{
			if(yymm){
				cout << "YYMM";
			}else{
				cout << "MMYY";
			}
		}
	}
	// mmyy ? 
	
}



Measured memory_bytes: 256
# AOJ 1172: Chebyshev's Theorem
# Python3 2018.7.14 bal4u

from bisect import bisect_left

MAX = 250000
SQRT = 500     # sqrt(MAX)

f = [True]*MAX
prime = [2]
def sieve():
#	for i in range(2, MAX, 2): f[i] = False
	for i in range(3, MAX, 2):
		if f[i]:
			prime.append(i)
			for j in range(i*i, MAX, i): f[j] = False
			
sieve()
while True:
	n = int(input())
	if n == 0: break
	if n == 1: print(1)
	else : print(bisect_left(prime, n<<1)-bisect_left(prime, n+1))


Measured memory_bytes: 8392
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;

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

	if(x == 1 || x == 2 * N - 1){
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;

	if(N == 2){
		cout << 1 << endl << 2 << endl << 3 << endl;
		return 0;
	}

	vector<int> p(4);
	int l, u;
	if(x > 2){
		p[0] = x - 1;
		p[1] = x;
		p[2] = x + 1;
		p[3] = x - 2;
		l = x-2;
		u = x+1;
	}
	else{
		p[0] = x + 1;
		p[1] = x;
		p[2] = x - 1;
		p[3] = x + 2;
		l = x-1;
		u = x+2;
	}
	int cnt = 1;
	for(int i = 0; i < 2 * N - 1; ++i){
		if(N-2 <= i && i <= N + 1){
			cout << p[i-(N-2)] << endl;
		}
		else{
			while(l <= cnt && cnt <= u) ++cnt;
			cout << cnt << endl;
			cnt ++;
		}
	}
	/*
	vector<int> v(2 * N - 1);
	for(int i = 1; i <= 2*N-1; ++i)
		v[i-1] = i;
	do{
		vector<int> w = v;
		for(int i = N-1; i >= 0; --i){
			for(int j = 0; j < i * 2 - 1; ++j){
				vector<int> u(3);
				for(int k = 0; k < 3; ++k){
					u[k] = w[j+k];
				}
				sort(ALL(u));
				w[j] = u[1];
			}
		}
		if(w[0] != N){
			for(auto i:v)
				cout << i;
			cout << " " << w[0] << endl;
		}
	}while(next_permutation(ALL(v)));
	*/
	return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define int long long int
mt19937 rng(std::chrono::duration_cast<std::chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int N=10000005;
#define M 1000000007
#define double long double
#define BINF 10000000000000000
#define init(arr,val) memset(arr,val,sizeof(arr))
#define MAXN 15000001
#define deb(x) cout << #x << " " << x << "\n";
const int LG = 22;

int n;
double x[1005], y[1005], X, Y, d, e;
double dist(double a, double b) {
    return a*a + b*b;
}

#undef int 
int main() {
#define int long long int
ios_base::sync_with_stdio(false); 
cin.tie(0); 
cout.tie(0);
 


    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
        X += x[i]; Y += y[i];
    }
    X /= n; Y /= n;
    double P = 0.1;
    for (int i = 0; i < 40000; i++) {
        int f = 0;
        d = dist(X - x[0], Y - y[0]);
        for (int j = 1; j < n; j++) {
            e = dist(X - x[j], Y - y[j]);
            if (d < e) { d = e; f = j; }
        }
        X += (x[f] - X)*P;
        Y += (y[f] - Y)*P;
        P *= 0.999;
    }

    double ans = sqrt(d);
    cout << fixed << setprecision(12) << ans << endl;
    
    


return 0;
}




Measured memory_bytes: 256
using System;

public class p0056{
	const int l = 50001;
	p0056 ()
	{
		string str;
		int cnt, n;
		bool[] prime = new bool[l];
		for (int i = 0; i < l; ++i)
			prime [i] = true;
		prime [0] = prime [1] = false;
		
		for (int i = 2; i < l; ++i)
			if (prime [i])
				for (int j = i+i; j < l; j+=i)
					prime [j] = false;
		
		
		while ((str=Console.ReadLine()) != null) {
			cnt = 0;
			n = int.Parse (str);
			
			if (n == 0)
				break;
			for (int i = 1; i <= n/2; ++i)
				if (prime [i] && prime [n - i])
					++cnt;
			
			Console.WriteLine ("{0}", cnt);
		}
	}
	
	public static int Main(string[] args){
		new p0056();
		return 0;
	}
}

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

using namespace std;

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

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

    vector<long long> m_asc(0), p_asc(0);
    for (int i = 0; i < n; i++) {
        if (a[i] < 0) {
            m_asc.push_back(a[i]);
        } else if (a[i] > 0) {
            p_asc.push_back(a[i]);
        }
    }

    sort(m_asc.begin(), m_asc.end());
    sort(p_asc.begin(), p_asc.end());

    vector<long long> m_desc(m_asc), p_desc(p_asc);
    reverse(m_desc.begin(), m_desc.end());
    reverse(p_desc.begin(), p_desc.end());

    long long m_size = m_asc.size();
    long long p_size = p_asc.size();
    long long z_size = n - m_size - p_size;

    long long left = -(1LL << 61), right = 1LL << 61;
    while (left < right) {
        long long mid = (left + right) / 2;
        if (left + right < 0) {
            mid = (left + right - 1) / 2;
        }

        long long m_cnt_rev = 0;
        for (int i = 0, j = -1; i < m_size; i++) {
            while (j < p_size - 1 && m_desc[i] * p_desc[j + 1] < mid) {
                j++;
            }
            m_cnt_rev += j + 1;
        }
        long long m_cnt = m_size * p_size - m_cnt_rev;

        long long z_cnt = 0;
        if (mid <= 0) {
            z_cnt = z_size * (m_size + p_size) + z_size * (z_size - 1) / 2;
        }

        long long p_cnt = 0;
        for (int i = 0, j = -1; i < m_size; i++) {
            while (j < m_size - 1 && m_desc[i] * m_asc[j + 1] >= mid) {
                j++;
            }
            if (m_desc[i] * m_desc[i] >= mid) {
                p_cnt--;
            }
            p_cnt += j + 1;
        }
        for (int i = 0, j = -1; i < p_size; i++) {
            while (j < p_size - 1 && p_asc[i] * p_desc[j + 1] >= mid) {
                j++;
            }
            if (p_asc[i] * p_asc[i] >= mid) {
                p_cnt--;
            }
            p_cnt += j + 1;
        }
        p_cnt /= 2;

        if (n * (n - 1) / 2 - (m_cnt + z_cnt + p_cnt) < k) {
            left = mid + 1;
        } else {
            right = mid;
        }
    }

    cout << left - 1 << endl;
}


Measured memory_bytes: 4844
#include <bits/stdc++.h>
using namespace std;
#define Maxn 100007
int n,k;
int p[Maxn],q[Maxn];
int a[Maxn],b[Maxn],tmp1[Maxn],tmp2[Maxn];
int ans[Maxn],r[Maxn];
int main()
{
    scanf("%d%d",&n,&k);
    for (int i=1;i<=n;i++)
        scanf("%d",&p[i]);
    for (int i=1;i<=n;i++)
        scanf("%d",&q[i]);
    if (k%6==1)
    {
        for (int i=1;i<=n;i++)
            b[i]=p[i];
    } else if (k%6==2)
    {
        for (int i=1;i<=n;i++)
            b[i]=q[i];
    } else if (k%6==3)
    {
        for (int i=1;i<=n;i++)
            b[p[i]]=q[i];
    } else if (k%6==4)
    {
        for (int i=1;i<=n;i++)
            b[p[i]]=i;
    } else if (k%6==5)
    {
        for (int i=1;i<=n;i++)
            b[q[i]]=i;
    } else
    {
        for (int i=1;i<=n;i++)
            tmp2[q[i]]=i;
        for (int i=1;i<=n;i++)
            b[i]=tmp2[p[i]];
    }
    for (int i=1;i<=n;i++)
        ans[i]=i;
    if (k>1)
    {
        --k;
        int c=(k-1)/6;
        k%=6;
        for (int i=1;i<=n;i++)
            tmp1[q[i]]=i;
        for (int i=1;i<=n;i++)
            r[i]=p[tmp1[i]];
        for (int i=1;i<=n;i++)
            tmp1[i]=r[i];
        for (int i=1;i<=n;i++)
            r[i]=q[tmp1[i]];
        for (int i=1;i<=n;i++)
            tmp1[p[i]]=i;
        for (int i=1;i<=n;i++)
            tmp2[i]=r[i];
        for (int i=1;i<=n;i++)
            r[i]=tmp1[tmp2[i]];
        while (c>0)
        {
            if (c%2==1)
            {
                for (int i=1;i<=n;i++)
                    tmp2[i]=ans[i];
                for (int i=1;i<=n;i++)
                    ans[i]=r[tmp2[i]];
            }
            c/=2;
            for (int i=1;i<=n;i++)
                tmp1[i]=r[i];
            for (int i=1;i<=n;i++)
                r[i]=tmp1[tmp1[i]];
        }
        if (k%6==3)
        {
            for (int i=1;i<=n;i++)
                tmp1[q[i]]=i;
            for (int i=1;i<=n;i++)
                tmp2[i]=ans[i];
            for (int i=1;i<=n;i++)
                ans[i]=tmp1[tmp2[i]];
        } else if (k%6==4||k%6==5)
        {
            for (int i=1;i<=n;i++)
                tmp1[q[i]]=i;
            for (int i=1;i<=n;i++)
                tmp2[i]=ans[i];
            for (int i=1;i<=n;i++)
                ans[i]=tmp1[tmp2[i]];
            for (int i=1;i<=n;i++)
                tmp2[i]=ans[i];
            for (int i=1;i<=n;i++)
                ans[i]=p[tmp2[i]];
        } else if (k%6==0)
        {
            for (int i=1;i<=n;i++)
                tmp1[q[i]]=i;
            for (int i=1;i<=n;i++)
                tmp2[i]=ans[i];
            for (int i=1;i<=n;i++)
                ans[i]=tmp1[tmp2[i]];
            for (int i=1;i<=n;i++)
                tmp2[i]=ans[i];
            for (int i=1;i<=n;i++)
                ans[i]=q[p[tmp2[i]]];
        }
    }
    for (int i=1;i<=n;i++)
        a[ans[i]]=i;
    for (int i=1;i<=n;i++)
        tmp2[i]=ans[i];
    for (int i=1;i<=n;i++)
        ans[i]=b[tmp2[i]];
    for (int i=1;i<=n;i++)
        tmp2[i]=ans[i];
    for (int i=1;i<=n;i++)
        ans[i]=a[tmp2[i]];
    for (int i=1;i<=n;i++)
        printf("%d ",ans[i]);
    printf("\n");
    return 0;
}

Measured memory_bytes: 6904
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr ll INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// ----------------------------------------------------------------------------

int main(){
  int N,K,S;
  cin >> N >> K >> S;
  for(int i=0; i<K; i++){
    cout << S << " ";
  }
  for(int i=K; i<N; i++){
    if(S == 1000000000){
      cout << 1 << " ";
    }else{
      cout << 1000000000 << " ";
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 1280
import java.util.*;

import static java.lang.System.*;

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

        Integer[] L = new Integer[2*N];
        for (int i = 0; i < 2*N; i++) {
            L[i] = sc.nextInt();
        }

        Arrays.sort(L, Collections.reverseOrder());

        int ans = 0;
        for(int i = 0; i < N; i++){
            ans += Math.min(L[2*i],L[2*i+1]);
        }

        out.println(ans);
    }
}


Measured memory_bytes: 22612
import sys,math,copy,queue,itertools
sys.setrecursionlimit(10**7)
#input = sys.stdin.readline
def LI(): return [int(x) for x in sys.stdin.readline().split()]
INF = 10000
MOD = 10**9 + 7
DD = ((1,0),(0,1),(-1,0),(0,-1))
H,W,K = LI()
C = [[int(x) for x in input()] for _ in range(H)]

min_cnt = INF
for y in range(2**H):
    cnt = 0
    bit = 1
    shikiri = [False] * H
    for b in range(H):
        if y & bit:
            shikiri[b] = True     #仕切り
            cnt +=1
        bit = bit << 1
    ct = [0] * H
    x = 0
    bx = 0
    while x < W:
        ix = 0
        for i in range(H):
            ct[ix] += C[i][x]
            if shikiri[i] : ix = i+1
        if max(ct) > K:
            if x != bx:
                cnt += 1
                ct = [0] * H
                bx = x
            else:
                cnt = INF
                break
        else:
            x = x + 1

    min_cnt = min(min_cnt,cnt)
print (min_cnt)


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

namespace BResale
{
    class Program
    {
        static void Main(string[] args)
        {
            // 入力の取得
            var n = int.Parse(Console.ReadLine());
            var values = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var costs = Console.ReadLine().Split().Select(int.Parse).ToArray();

            // 転売時の最大利益を計算
            var maxSum = values.Zip(costs, (v, c) => v - c).Where(diff => diff > 0).Sum();

            // 解答の出力
            Console.WriteLine(maxSum);
        }
    }
}


Measured memory_bytes: 13396
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#include<queue>
#include<cstring>
#include<set>
using namespace std;

int main(){
    int n,a;
    multiset<int> s;
    scanf("%d",&n);
    scanf("%d",&a);
    s.insert(a);
    for(int i=1;i<n;i++){
        scanf("%d",&a);
        decltype(s)::iterator it = s.lower_bound(a);
        if(it==s.begin()){
            s.insert(a);
        }
        else{
            it--;
            s.erase(it);
            s.insert(a);
        }
    }
    printf("%ld\n",s.size());
}

Measured memory_bytes: 4864
S = input()
N = len(S)
for i in range(2**(N-1)):
    sum = int(S[0])
    f = S[0]
    for j in range(N-1):
        if (i >> j) & 1:
            f += '+'
            sum += int(S[j+1])
        else:
            f += '-'
            sum -= int(S[j+1])
        f += S[j+1]
    # calc
    if sum == 7:
        print('{}=7'.format(f))
        break


Measured memory_bytes: 61904
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
typedef pair<int, int> P;
int main()
{
    int n;
    cin >> n;
    int k;
    cin >> k;
    string s;
    cin >> s;

    int cnt = 0;
    int lr = 0, rl = 0, hybrid = 0;
    bool bef = false;
    rep(i, n)
    {
        string t = s.substr(i, 2);

        if (t == "LR")
        {
            if (!bef)
            {
                bef = true;
                lr++;
            }
            else
            {
                hybrid++;
                rl--;
            }
        }
        else if (t == "RL")
        {
            if (!bef)
            {
                bef = true;
                rl++;
            }
            else
            {
                hybrid++;
                lr--;
            }
        }
        else if (t == "RR" or t == "LL")
        {
            bef = false;
            cnt++;
        }
        else
        {
            bef = false;
        }
        
    }
   if (s[n - 1] == 'R')
    {
        if(lr==1&&rl==0&&hybrid==0){
            cnt++;
        }
    }
    else if (s[n - 1] == 'L')
    {
        if(lr==0&&rl==1&&hybrid==0){
            cnt++;
        }
    }
    while (k > 0)
    {
            int be=cnt;
            if (rl > 0 && hybrid > 0)
            {
                k--;
                rl--;
                cnt += 2;
            }
            else if (lr > 0 && hybrid > 0)
            {
                k--;
                lr--;
                cnt += 2;
            }
            else if (rl > 0 && lr > 0)
            {
                k--;
                rl--;
                lr--;
                cnt += 2;
            }
            else if (hybrid > 1)
            {
                k--;
                cnt += 2;
            }
            if(be==cnt){break;}
    }
    cout << min(cnt,n-1) << endl;
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
const long long mod = 2019;
int main(){
  long long l,r;
  cin >> l >> r;
  if (r-l>=2019 || r%mod < l%mod ){
    cout << 0 << endl;
    return 0;
  }
  long long ans=2018*2018;
  for (long long i=l%mod; i <= r%mod; i++){
    for (long long j=i+1; j<=r%mod; j++){
      if ((i*j)%mod < ans) ans=(i*j)%mod;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
from collections import deque
n = int(input())
s = list(input())
#print(s)
ans = deque(s)
cnt = 0
for i in range(n):
    if s[i] == ')':
        if cnt == 0:
            ans.appendleft('(')
        else:
            cnt -= 1
    else:
        cnt += 1

s.reverse()
cnt = 0
for i in range(n):
    if s[i] == '(':
        if cnt == 0:
            ans.append(')')
        else:
            cnt -= 1
    else:
        cnt += 1

print(''.join(ans))

Measured memory_bytes: 3316