akhauriyash/Code-Regression huggingface dataset:
sa = input()
sb = input()
sc = input()
lena = len(sa)
lenb = len(sb) 
lenc = len(sc)
turn = 'a'
cnta = 0
cntb = 0
cntc = 0
while(1>0):
  if turn == 'a':
    if lena == cnta:
      print('A')
      exit()
    else:
      turn = sa[cnta]
      cnta += 1
  elif turn == 'b':
    if lenb == cntb:
      print('B')
      exit()
    else:
      turn = sb[cntb]
      cntb += 1
  elif turn == 'c':
    if lenc == cntc:
      print('C')
      exit()
    else:
      turn = sc[cntc]
      cntc += 1

Measured memory_bytes: 3064
use proconio::input;

// https://atcoder.jp/contests/abc168

fn main() {
    input! {
        nm: (usize, usize),
        ab: [(usize, usize); nm.1],
    }
    let mut cave = vec![vec![]; nm.0+1];
    for p in ab {
        cave[p.0].push(p.1);
        cave[p.1].push(p.0);
    }
    for i in 1..cave.len() {
        cave[i].sort();
    }

    let mut check = vec![0; nm.0+1];
    check[1] = 1;
    let mut que = vec![];
    que.push(1);

    while que.len() > 0 {
        let v = que.remove(0);

        for &i in &cave[v] {
            if check[i] != 0 {
                continue;
            }
            check[i] = v;
            que.push(i);
        }
    }
    
    println!("Yes");
    for i in 2..check.len() {
        println!("{}", check[i]);
    }
}


Measured memory_bytes: 16072
import sys
from io import StringIO
import unittest

from itertools import combinations

def resolve():
    # s = input()
    n = int(input())
    # a, b = map(int, input().split())
    l = list(map(int, input().split()))
    cnt = 0

    for ll in combinations(l, 3):
        if ll.count(ll[0]) > 1 or ll.count(ll[1]) > 1 or ll.count(ll[2]) > 1:
            pass
        elif ll[0] + ll[1] > ll[2] and ll[1] + ll[2] > ll[0] and ll[0] + ll[2] > ll[1]:
            cnt += 1

    print(cnt)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """5
4 4 9 7 5"""
        output = """5"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """6
4 5 4 3 3 5"""
        output = """8"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """10
9 4 6 1 9 6 10 6 6 8"""
        output = """39"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """2
1 1"""
        output = """0"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16328
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    LL A, B, K;
    cin >> A >> B >> K;

    LL eatA = min(A, K);
    LL eatB = min(B, K-eatA);
    

    cout << (A-eatA) << ' ' << (B-eatB) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>

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

void check(int W, int H, int x, int y, int r) {
if (x - r < 0 || x + r > W || y - r < 0 || y + r > H) {
cout << "No" << endl;
return;
}
cout << "Yes" << endl;
return;
}

int main(void) {
int W;
int H;
int x;
int y;
int r;
cin >> W >> H >> x >> y >> r;
check(W,H,x,y,r);

return 0;
}

Measured memory_bytes: 3048
#include <iostream>
#include <string>

using namespace std;

long long mpow(int a, int b);

int main()
{
	int n;
	cin >> n;
	
	string s = "";
	if (n == 0) {
		s = '0';
	}
	while (n != 0) {
		if (n % 2 != 0) {
			n--;
			s = "1" + s;
		}
		else {
			s = "0" + s;
		}
		n /= -2;
	}
	
	cout << s << endl;

	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		if(a < b) {
			System.out.println("a < b");
		}
		else if(a > b){
			System.out.println("a > b");
		}
		else {
			System.out.println("a == b");
		}
	}
}


Measured memory_bytes: 26136
import math

N=int(input())


ans=0

i=1
ans=0
while i<=N:
    j=1
    while j<=N:
        k=1
        while k<=N:
            ans+=math.gcd(math.gcd(i,j),k)
            k+=1
        j+=1
    i+=1
print(ans)



Measured memory_bytes: 66600
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    int s, k; cin >> s >> k;
    vector<string> str(100);
    repeat (i, 100) str[i] = string(100, '.');
    
    bool isreversed = false;
    if (s > k+1) {
        swap(s, k);
        isreversed = true;
    }
    
    auto getpos = [](int n) -> pair<int, int> {
        int a = n / 25;
        int b = n % 25;
        return pair<int, int> {a, b};
    };
    
    repeat (i, k) {
        int a, b;
        tie(a, b) = getpos(i);
        vector<int> dx {0, 1, 2, 0, 1, 2, 0, 1, 2};
        vector<int> dy {0, 0, 0, 1, 1, 1, 2, 2, 2};
        repeat (j, 9) {
            str[a*4+dx[j]][b*4+dy[j]] = '#';
        }
    }
    
    repeat (i, s - 1) {
        int a, b;
        tie(a, b) = getpos(i);
        str[a*4+1][b*4+1] = '.';
    }
    
    if (isreversed) {
        repeat (i, 100) {
            repeat (j, 100) {
                str[i][j] = (str[i][j] == '.' ? '#' : '.');
            }
        }
    }
    
    cout << 100 << " " << 100 << endl;
    repeat (i, 100) cout << str[i] << endl;
    
}

Measured memory_bytes: 256
<?php
  while (true) {
    list($n, $x) = explode(" ", trim(fgets(STDIN)));
    if (($n == "0") && ($x == "0")) {
      return;
    }
    $i = 0;
    for ($a=1; $a<=$n; $a++) {
      for ($b=($a+1); $b<=$n; $b++) {
        for ($c=($b+1); $c<=$n; $c++) {
          if ((($a + $b + $c) == $x) && ($a != $b) && ($b != $c)) {
            $i++;
          }
        }
      }
    }
    print($i."\n");
  }
?>

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

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

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

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
using u64 = uint64_t;

int main(void) {
    u64 N;
    cin >> N;

    vector<u64> ans(N);
    u64 lim = (u64)sqrt(N);

    for(u64 x=1; x<=lim; x++) {
        u64 x_ans = x*x;
        if(x_ans > N) break;

        for(u64 y=1; y<=lim; y++) {
            u64 xy_ans = x_ans + y*y + x*y;
            if(xy_ans> N) break;

            for(u64 z=1; z<=lim; z++) {
                u64 xyz_ans = xy_ans+ z*z + y*z + z*x; 
                if(xyz_ans > N) break;

                ans[xyz_ans-1]++;
            }
        }
    }

    for(u64 cnt : ans) {
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 3540
#include <iostream>
using namespace std;
int main(void){
    
    int W, H, x, y, r;
    
    cin >> W >> H >> x >> y >> r;
    
    if(W >= x+r && H >= y+r && x-r >= 0 && y-r >= 0){
        
        cout <<"Yes"<< endl;
    }
    
    else{
        
        cout <<"No"<< endl;
    
    }
}


Measured memory_bytes: 3092
import java.util.*;

class Main {
    public static void main(String[] args) {
	Scanner s = new Scanner(System.in);
	int[] d = new int[10001];
	d[0]=1;
	d[1]=2;
	for(int i=2 ; i<10001 ; i++)
	    d[i] = d[i-1]+i;
	while(s.hasNext())
	    System.out.println(d[s.nextInt()]);
    }
}

Measured memory_bytes: 12000
N, M, K = map(int, input().split())
MOD = 998244353
n = N
fac = [1]
caf = [1]


def pow(n, p):
    res = 1
    while p > 0:
        if p % 2 == 0:
            n = n ** 2 % MOD
            p //= 2
        else:
            res = res * n % MOD
            p -= 1
    return res % MOD


for i in range(1, n):
    fac.append((fac[i - 1] * i) % MOD)
    caf.append(pow(fac[i], MOD - 2))


def ncr(n, r):
    if n < r or r < 0:
        return 0
    return fac[n] * caf[r] * caf[n - r]


res = 0
for i in range(K + 1):
    tres = M
    tres *= pow(M - 1, N - i - 1)
    tres %= MOD
    tres *= ncr(N - 1, i)
    tres %= MOD
    res += tres
    res %= MOD
print(res)


Measured memory_bytes: 96956
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  int cc = 0;
  set<string> se;
  char mae = 'a';
  while(1) {
    printf("?%c%c%ca\n",mae, 'a' + cc%26, 'b' + cc/26);fflush(stdout);
    cc++;
    char str[5];
    scanf("%s",str);
    string s(str);
    if (s[0] != 'a' || se.count(s)) {
      printf("!OUT\n");
      break;
    }
    se.insert(s);
    mae = s[s.size()-1];
  }
}

Measured memory_bytes: 0
N=int(input())
A=list(map(int,input().split(' ')))
import math
import collections
import operator as op
from functools import reduce
def nCr(n,r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer / denom if n>1 else 0
counter=collections.Counter(A)
penult=0
for i in range(1,N+1):
    penult=penult+nCr(counter[i],2)
for i in range(0,N):
    print(int(penult-(counter[A[i]]-1)))

Measured memory_bytes: 26140
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

int N;
vector<vector<int>> g(100000);
vector<vector<ll>> dp(100000, vector<ll>(2, 0));

P dfs(int cur, int pre)
{
    dp[cur][0] = dp[cur][1] = 1;
    for (auto v : g[cur])
    {
        if (v == pre)
            continue;
        P p = dfs(v, cur);
        dp[cur][0] *= (p.first + p.second);
        dp[cur][0] %= MOD;
        dp[cur][1] *= p.first;
        dp[cur][1] %= MOD;
    }
    return P(dp[cur][0], dp[cur][1]);
}

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

    cin >> N;
    for (int i = 0; i < N - 1; i++)
    {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    P p = dfs(0, -1);
    cout << (p.first + p.second) % MOD << endl;
}


Measured memory_bytes: 16768
#081-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n,k=IL()
A=IL()
Ad={}
for a in A:
    if a in Ad:
        Ad[a]+=1
    else:
        Ad[a]=1
Add=sorted(Ad.items(), key=lambda x: x[1])
ans=0
for i in range(len(Add)-k):
    ans+=Add[i][1]
print(ans)

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

int a[200001];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long sum = 0;
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) cin >> a[i];
    int high = a[0];
    for (int i = 1; i < N; i++){
        if (a[i] < high){
            sum += high - a[i];
        }else{
            high = a[i];
        }
    }
    cout << sum << "\n";
}

//      *   *  *****  *   *  *   *   ****  ****    ****     **  ***
//     *   *  *      **  *  *   *  *      *   *  *        * *  *  *
//    *****  *****  * * *  *   *  *      ****   *       *  *    *
//   *   *      *  *  **  *   *  *      *  *   *       *****  *
//  *   *  *****  *   *   ***    ****  *   *   ****      *  ****

//     ****   *****   ****         *   *  *****  *   *   ****
//    *   *    *    *             ** **    *    **  *  *
//   ****     *    * ***  *****  * * *    *    * * *  * ***
//  *   *    *    *   *         *   *    *    *  **  *   *
// ****   *****   ****         *   *  *****  *   *   ****



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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<pair<int, ll>> ab(n);
    for (int i=0; i<n; ++i) cin >> ab.at(i).first >> ab.at(i).second;

    ll res = 0;
    int mask = (1<<30) - 1;
    for (int i=29; i>=0; --i) {
        mask -= 1<<i;
        if (k & (1<<i)) {
            ll tmp = 0;
            for (auto p : ab) {
                int a = p.first;
                ll b = p.second;
                if ((a | mask) == mask) tmp += b;
            }
            chmax(res, tmp);
            mask += 1<<i;
        }
    }
    ll tmp = 0;
    for (auto p : ab) {
        int a = p.first;
        ll b = p.second;
        if ((a | k) == k) tmp += b;
    }
    chmax(res, tmp);
    cout << res << '\n';
}

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

    solve();

    return 0;
}


Measured memory_bytes: 1792
H, W, K = map(int, input().split())
SW = [input() for i in range(H)]

ans = [[]]*(H+1)
cur = 1
first = True

for h in range(H):
    row = []
    ind = 0
    while True:
        cnt = SW[h][ind:].count('#')
        if cnt == 1:
            row.extend([cur]*(W-ind))
            cur += 1
            break
        elif cnt > 1:
            ind = SW[h].find('#', ind)
            ind += 1
            row.extend([cur]*(ind-len(row)))
            cur += 1
        elif cnt == 0:
            row = []
            break
    ans[h+1] = row
    if first and row != []:
        ans[0] = row
        first = False

for h in range(H+1):
    if ans[h] == []:
        ans[h] = ans[h-1]
    if h > 0:
        print(*ans[h])


Measured memory_bytes: 45276
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 105;

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

int dp[2][MAX_N];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vvi a(2,vi(n,0));
    rep(i,2){
        rep(j,n){
            cin >> a[i][j];
        }
    }
    queue<P> que;
    dp[0][0] = a[0][0];
    que.push(P(0,0));
    while(!que.empty()){
        P p = que.front();
        que.pop();
        rep(i,2){
            int nx = p.fi+dx[i],ny = p.se+dy[i];
            if(nx < 2 && ny < n){
                cmx(dp[nx][ny],dp[p.fi][p.se]+a[nx][ny]);
                que.push(P(nx,ny));
            }
        }
    }
    cout << dp[1][n-1] << "\n";
    return 0;
}


Measured memory_bytes: 256
//
//  main.cpp
//  Exercise
//
//

#include <algorithm>
#include <iostream>
#include <limits>
#include <math.h>
#include <tuple>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include "string.h"
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <set>

using namespace std;

using int_t = long long;

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2012

int main() {
    vector<int> es;
    while (true) {
        int e;
        scanf("%d", &e);
        if (e == 0) {
            break;
        }
        es.push_back(e);
    }
    for (auto e : es) {
        int sumMin = numeric_limits<int>::max();
        for (int y = 0; y * y <= e; y++) {
            for (int z = 0; z * z * z <= e - y * y; z++) {
                int x = e - y * y - z * z * z;
                sumMin = min(sumMin, x + y + z);
            }
        }
        printf("%d\n", sumMin);
    }
    return 0;
}



Measured memory_bytes: 3212
#include <iostream>
#include <iomanip>
using namespace std;
long double ev[305][305][305];
 
int main()
{
	int n, a = 0, b = 0, c = 0, temp;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> temp;
		if (temp == 1) 
			a++;
		else if (temp == 2) 
			b++;
		else 
			c++;
	}
	
	ev[0][0][0] = 0;
	
	for (int k = 0; k <= n; k++)
		for (int j = 0; j <= n - k; j++)
			for (int i = 0; i <= n - j - k; i++)
			{
				if (!i && !j && !k) 
					continue;
				ev[i][j][k] = n;
				if (i) ev[i][j][k] += i * ev[i - 1][j][k];
				if (j) ev[i][j][k] += j * ev[i + 1][j - 1][k];
				if (k) ev[i][j][k] += k * ev[i][j + 1][k - 1];
				ev[i][j][k] /= (i + j + k);
			}
			
	cout << fixed << setprecision(10) << ev[a][b][c];
}

Measured memory_bytes: 436480
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (ll)(n); ++i)
#define repk(i,k, n) for (int i = k; i < (ll)(n); ++i)
#define MAX 50000001
#define MOD 1000000007
typedef long long  ll;

using namespace std;

ll ans, cnt;


int main() {
	int N, M;
	cin >> N >> M;
	vector<int> p(M);
	vector<string> S(M);
	rep(i, M) {
		cin >> p[i] >> S[i];
	}
	
	vector<bool> acflg(N + 10, false);
	vector<int>	waflg(N + 10, 0);
	int waans = 0;

	rep(i, M) {
		if (S[i] == "AC") {
			if (acflg[p[i]] == false) {
				acflg[p[i]] = true;
				waans += waflg[p[i]];
			}
		}
		else if (S[i] == "WA") {
			waflg[p[i]]++;
		}
	}

	int acans = 0;
	rep(i, N+1) {
		if (acflg[i] == true) acans++;
	}

	cout << acans << " " << waans << endl;

	return 0;
}


Measured memory_bytes: 6528
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize ("Ofast")
//#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define d long double
#define pii pair<int,int>
#define pb push_back
#define pf push_front
#define cases int t;cin>>t;while(t--)
#define N 100003
#define M 1003
#define inf LLONG_MAX
//int mod=1e9+7;
//int mod=998244353;

signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    int n;
    cin>>n;
    int i,j;
    vector<pii> ans;    ans.clear();
    if(n%2)
    {
        for(i=1;i<=n;++i)
        {
            for(j=i+1;j<=n;++j)
            {
                if(j!=n-i)
                    ans.pb({i,j});
            }
        }
    }
    else
    {
        for(i=1;i<=n;++i)
        {
            for(j=i+1;j<=n;++j)
            {
                if(j!=n+1-i)
                    ans.pb({i,j});
            }
        }
    }
    cout<<ans.size()<<"\n";
    for(auto it:ans)
        cout<<it.first<<" "<<it.second<<"\n";

    return 0;
}


Measured memory_bytes: 512
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.util.Arrays;

public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        boolean control = false;
        int num;

        while((num = Integer.valueOf(br.readLine())) != 0){
            
            if(control) System.out.println();

            Table[] table = new Table[num];

            for(int i = 0; i < num; i++){
                String[] input = br.readLine().split(" " , 4);
                
                String country = input[0];
                int score = Integer.valueOf(input[1]) * 3 + Integer.valueOf(input[3]);

                table[i] = new Table(country , score);
            }

            Arrays.sort(table);

            for(Table a : table){
                System.out.println(a);
            }

            control = true;
        }

    }
}

class Table implements Comparable{
        String country;
        int score;
        Table(String c , int s){
            this.country = c;
            this.score = s;
        }

        public String toString(){
            return this.country + "," + this.score;
        }

        public int compareTo(Object object){
            Table comp = (Table)object;
            if(this.score < comp.score) return 1;
            else if(this.score > comp.score) return -1;
            else return 0;
        }

}

Measured memory_bytes: 24192
import java.util.Scanner;

public class Main {

	/*
	 * 1 から n までの数の中から、重複無しで３つの数を選びそれらの合計が x となる組み合わせの数を求めるプログラムを作成して下さい。
	 * 
	 * 例えば、1 から 5 までの数から３つを選んでそれらの合計が 9 となる組み合わせは、
	 * 
	 * 1 + 3 + 5 = 9 2 + 3 + 4 = 9 の２通りがあります。
	 * 
	 * Input 複数のデータセットが入力として与えられます。各データセットでは、空白で区切られた n、x が 1 行に与えられます。
	 * 
	 * n、x がともに 0 のとき入力の終わりとします。
	 * 
	 * n は 3 以上 100　以下とします。
	 * 
	 * Output 各データセットについて、組み合わせの数を１行に出力して下さい。
	 */
	public static void main(String[] args) throws Exception {

		Scanner sc = new Scanner(System.in);
		while (true) {

			int count = 0;
			int n = sc.nextInt();
			int x = sc.nextInt();

			if (n == 0 && x == 0) {

				break;

			} else {

				for (int i = 1; i <= n; i++) {
					for (int j = i + 1; j <= n; j++) {
						for (int j2 = j + 1; j2 <= n; j2++) {
							if (i + j + j2 == x) {
								count++;
							}
						}
					}
				}
				System.out.println(count);
			}

		}
		sc.close();

	}
}

Measured memory_bytes: 19608
#include <iostream>

using namespace std;

long long gcd(long long a, long long b) {
	if (b == 0) {
		return a;
	}

	return gcd(b, a % b);
}
long long lcm(long long a, long long b) {

	return a * b / gcd(a, b);
}

int main() {
	long long a, b;
	cin >> a >> b;
	long long ans=lcm(a, b);
	cout << ans;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>

using namespace std;

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, a, b; cin >> n >> a >> b;
    
    cout << min(n * a, b) << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
    long int a,b,i,c=1;
    cin>>a>>b;
    if(a<2 || a>20 || b<1 || b>20)
        {
            cout<<"-1";
            exit(0);
        }
    for(i=a;i<b;c++)
    {
        i=i+a-1;
    }
    if(b==1)
    {
        c=0;
    }
    cout<<c;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define MAX 2000000
#define MIN -1

void maxHeapify(int *,int);
int heapExtractMax(void);
void heapIncreaseKey(int *,int,int);
void insert(int);


int H, a[MAX+1];
int main(){
  int n;
  char com[20];
  
  while(1){
    scanf("%s", com);
    if ( com[0] == 'e'&&com[1]=='n' ) break;
    if(com[0]=='i'){
      scanf("%d", &n);
      insert(n);
    } else {
      printf("%d\n",heapExtractMax());
    }
  }
  
  return 0;
}

void maxHeapify(int a[],int i){
  int l, r, largest, x;
  l = 2*i;
  r = 2*i+1;
  if ( l <= H && a[l] > a[i] ){
    largest = l;
  }
  else {
    largest = i;
  }
  if ( r <= H && a[r] > a[largest] ) {
    largest = r;
  }
  if ( largest != i ){
    x = a[i];
    a[i] = a[largest];
    a[largest] = x;
    maxHeapify(a,largest);
  }
}

int heapExtractMax(){
  int x;
  if ( H < 1 ) return MIN;
  x = a[1];
  a[1] = a[H];
  H--;
  maxHeapify(a,1);
  return x;
}

void heapIncreaseKey(int a[],int i, int n){
  int y;
  if ( n < a[i] ) return;
  a[i] = n;
  while ( i > 1 && a[i/2] < a[i] ){
    y = a[i];
    a[i] = a[i/2];
    a[i/2] = y;
    i = i/2;
  }
}

void insert(int n){
  H++;
  a[H] = -100000000000;
  heapIncreaseKey(a,H,n);
}



Measured memory_bytes: 5708
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line = read_as_vec::<usize>();
    let (n, a, b) = (line[0], line[1], line[2]);

    if (b-a)%2 == 0{
        println!("Alice");
    }else{
        println!("Borys");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
  int N; cin >> N;
  vector<int> W(N, 0), X(N, 0);
  for(int i=0; i<N; i++){
    cin >> W[i];

    for(int j=0; j<=i; j++){
      X[i] += W[j];
    }
  }

  int ans = 100000000;
  for(int i=0; i<N-1; i++){
    ans = min(ans, abs(2 * X[i] - X[N-1]));
  }

  cout << ans << endl;

  return 0;
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

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

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, k;
    cin >> n >> k;
    vector<bool> b(n);
    rep(i, k) {
        int d;
        cin >> d;
        rep(j, d) {
            int ai;
            cin >> ai;
            b[ai-1] = true;
        }
    }
    int ans = 0;
    rep(i, n) {
        if (!b[i]) ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
def main():

    K = int(input())
    a = "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"
    b = a.split(", ")
    print(b[K-1])
    

    return

if __name__ == '__main__':
    main()

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

int main(){
  int n, m, a, b;
  cin >> n >> m;
  vector<int> city(n,0);
  
  for(int i = 0; i < m; i++){
    cin >> a >> b;
    city.at(a-1)++;
    city.at(b-1)++;
  }
  for(int i = 0; i < n; i++){
    cout << city.at(i) << endl;
  }
}

Measured memory_bytes: 256
import copy

n = int(input())
t = list(map(int, input().split()))
m = int(input())
px = []
for i in range(0, m):
    px.append(list(map(int, input().split())))

t_ = copy.deepcopy(t)
for i in range(0, m):
    t_[px[i][0] - 1] = px[i][1]
    print(sum(t_))
    t_ = copy.deepcopy(t)

Measured memory_bytes: 4084
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

int main() {
	vector<int> num(100001,0);
	vector<long long> ans;
	int n,k,q,b,c;
	long long sum=0;
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> k;
		num[k]++;
		sum += k;
	}

	cin >> q;
	for (int i = 0;i < q;i++) {
		cin >> b >> c;
		k = num[b];
		num[b] = 0;
		num[c] += k;
		sum += (long long)((long long)c - (long long)b) * (long long)k;
		ans.emplace_back(sum);
	}

	for (int i = 0;i < ans.size();i++) {
		cout << ans[i] << "\n";
	}

	return 0;
}

Measured memory_bytes: 4704
class Dijkstra():
    """ ダイクストラ法
    重み付きグラフにおける単一始点最短路アルゴリズム

    * 使用条件
        - 負のコストがないこと
        - 有向グラフ、無向グラフともにOK

    * 計算量はO(E*log(V))

    * ベルマンフォード法より高速なので、負のコストがないならばこちらを使うとよい
    """
    class Edge():
        """ 重み付き有向辺 """
        def __init__(self, _to, _cost):
            self.to = _to
            self.cost = _cost

    def __init__(self, V):
        """ 重み付き有向辺
        無向辺を表現したいときは、_fromと_toを逆にした有向辺を加えればよい

        Args:
            V(int): 頂点の数
        """
        self.G = [[] for i in range(V)]  # 隣接リストG[u][i] := 頂点uのi個目の隣接辺
        self._E = 0  # 辺の数
        self._V = V  # 頂点の数

    @property
    def E(self):
        """ 辺数
        無向グラフのときは、辺数は有向グラフの倍になる
        """
        return self._E

    @property
    def V(self):
        """ 頂点数 """
        return self._V

    def add(self, _from, _to, _cost):
        """ 2頂点と、辺のコストを追加する """
        self.G[_from].append(self.Edge(_to, _cost))
        self._E += 1

    def shortest_path(self,s):
        import heapq
        que=[]
        d=[10**15]*self.V
        d[s]=0
        last=-1
        heapq.heappush(que,(0,s))

        while len(que)!=0:
            cost,v=heapq.heappop(que)

            if d[v]<cost:continue

            for i in range(last+1,v+1):
                d[i]=cost
                for j in range(len(self.G[i])):
                    e=self.G[i][j]
                    if d[e.to]>d[i]+e.cost:
                        d[e.to]=d[i]+e.cost
                        heapq.heappush(que,(d[e.to],e.to))
            last=v
        return d


import sys

N,M=map(int,input().split())
pro=Dijkstra(N)
for i in range(M):
    l,r,c=map(int,input().split())
    pro.add(l-1,r-1,c)

ans=pro.shortest_path(0)[-1]
if ans==10**15:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 83492
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

ll power(ll n, ll k);
ll inv(ll n);
ll genfact(ll n, ll k);
ll fact(ll n);
ll nck(ll n, ll k);

int main(void){
  int n, m;
  cin >> n >> m;
  vector<vector<int>> edge(3*n, vector<int>(0));

  int u, v;
  for (int i = 0; i < m; i++){
    cin >> u >> v;
    u--; v--;
    edge[3*u].push_back(3*v + 1);
    edge[3*u + 1].push_back(3*v + 2);
    edge[3*u + 2].push_back(3*v);
  }

  int s, t;
  cin >> s >> t;
  s--; t--;


  vector<bool> visited(3*n, false);
  queue<pair<int, int>> q;
  q.push(pair<int, int>(3*s, 0));
  int d, ok = 0;
  while (!q.empty()){
    const pair<int, int> cur = q.front();
    q.pop();
    d = cur.second;
    u = cur.first;

    visited[u] = true;
    for (int i = 0; i < edge[u].size(); i++){
      if (edge[u][i] == 3*t){
        ok = 1;
        d++;
        break;
      }
      if (!visited[edge[u][i]]){
        visited[edge[u][i]] = true;
        q.push(pair<int, int>(edge[u][i], d + 1));
      }
    }
    if (ok)
      break;
  }


  cout << (ok == 1 ? d/3 : - 1) << endl;

  return 0;
}


ll power(ll n, ll k){
  ll res = 1;
  while(k > 0){
    if (k & 1) 
      res = res * n % MOD;
    n = n * n % MOD;
    k >>= 1;
  }
  return res;
}

ll genfact(ll n, ll k){

  ll res = 1;
  while (k >= 0){
    res = (res * (n - k)) % MOD;
    k--;
  }

  return res;
}

ll inv(ll n){
  return power(n, MOD - 2);
}

ll fact(ll n){
  return genfact(n, n - 1);
}

ll nck(ll n, ll k){
  if (k == 0)
    return 1;
  if (n <= 0)
    return 0;

  return ((genfact(n, k) % MOD) * inv(fact(k))) % MOD;
} 


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

int main() {
  int n; cin>>n;
  vector<int> s(n);
  vector<string> t(n);
  rep(i, n) cin>>t[i]>>s[i];
  string T; cin>>T;

  int cnt=0;
  bool frag=false;
  rep(i, n) {
    bool tmp=true;
    if (frag) cnt+=s[i];
    rep(j, T.size()) {
      if (j>=t[i].size()) break;
      if (t[i][j]!=T[j]) tmp=false;
    }
    if (t[i].size()!=T.size()) tmp=false;
    if (tmp) frag=true;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int height[3]={0,0,0};
    int i=0;

    while(i<10){
        int input;
        scanf("%d",&input);

        if(input>=height[0]){
            height[2]=height[1];
            height[1]=height[0];
            height[0]=input;
        }else if(input>=height[1]){
            height[2]=height[1];
            height[1]=input;
        }else if(input>=height[2]){
            height[2]=input;
        }

        i++;
    }

    for(i=0;i<3;i++){
        printf("%d\n",height[i]);
    }

    return 0;
}

Measured memory_bytes: 600
#include <iostream>

using namespace std;

int
main()
{
  long long N, M;
  cin >> N >> M;

  if (M <= N * 2) {
    cout << M / 2 << "\n";
    return 0;
  }
  cout << N + (M - N * 2) / 4 << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
int main()
{
	std::string s;
	std::cin >> s;
	if (s == "A")
	{
		std::cout << "T" << "\n";
	}
	else if (s == "C")
	{
		std::cout << "G" << "\n";
	}
	else if (s == "G")
	{
		std::cout << "C" << "\n";
	}
	else if (s == "T")
	{
		std::cout << "A" << "\n";
	}
    return 0;
}



Measured memory_bytes: 256
// Package main provides
//
// File:  b.go
// Author: ymiyamoto
//
// Created on Sun Dec 16 19:34:40 2018
//
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var N string
	fmt.Scan(&N)

	divider := 0
	for _, c := range N {
		divider += int(c - '0')
	}

	n, _ := strconv.Atoi(N)

	if n%divider == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
  static final int INF = 1100000000;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int T = sc.nextInt();
    int[] A = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
    }

    int max_benefit = -1;
    int min_A = INF;
    int ans = 0;
    for (int i = 0; i < N; i++) {
      min_A = Math.min(min_A, A[i]);

      int benefit = A[i] - min_A;
      if (benefit == max_benefit) {
        ans++;
      } else if (benefit > max_benefit) {
        ans = 1;
        max_benefit = benefit;
      }
    }
    System.out.println(ans);
  }
}

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

using namespace std;

typedef long long int ll;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int n, k;
    string str;

    cin >> n;
    cin >> str;
    cin >> k;

    str = str;

    for(int i = 0; i < n; i++){
        if(str[i] != str[k - 1]){
            str[i] = '*';
        }
    }

    cout << str << endl;

    return 0;
}



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

using namespace std;

#define int long long

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

template <typename T> T gcd(T m, T n) { return n == 0 ? m : gcd(n, m % n); }
template <typename T> T lcm(T m, T n) { return n * m / gcd(n, m); }
template <typename T> T fact(T n) { return (n == 0 ? 1 : n * fact(n - 1)); }
template <typename T> T modpow(T a, T e, T m) { return (e == (T)0 ? 1 : ((a % m) * modpow((a % m), e - 1, m)) % m); }

constexpr int MOD = 1e9 + 7;

signed main(void) {

  char c;
  cin >> c;
  cout << (char)((int)c + 1) << endl;
}


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

using namespace std;

class Point {
public:
	int id, x, y;
	Point(int id, int x, int y) :
			id(id), x(x), y(y) {
	}
	Point() {
	}
	bool operator <(const Point& p) const {
		return id < p.id;
	}
	void print() {
		printf("%d\n", id);
	}
};
class Node {
public:
	int location, l, r;
};
bool lessX(const Point &p1, const Point &p2) {
	return p1.x < p2.x;
}
bool lessY(const Point &p1, const Point &p2) {
	return p1.y < p2.y;
}

const int MAX = 500000;
const int NIL = -1;
int np = 0;
Point P[MAX];
Node T[MAX];
int makeKdTree(int l, int r, int depth) {
	if (!(l < r))
		return NIL;

	if (depth % 2 == 0) {
		sort(P + l, P + r, lessX);
	} else {
		sort(P + l, P + r, lessY);
	}
	int t = np++;
	int mid = (l + r) / 2;
	T[t].location = mid;
	T[t].l = makeKdTree(l, mid, depth + 1);
	T[t].r = makeKdTree(mid + 1, r, depth + 1);

	return t;
}

void find(int v, int sx, int tx, int sy, int ty, int depth, vector<Point> &ans) {
	int x = P[T[v].location].x;
	int y = P[T[v].location].y;
	if (sx <= x && x <= tx && sy <= y && y <= ty) {
		ans.push_back(P[T[v].location]);
	}
	if (depth % 2 == 0) {
		if (T[v].l != NIL && sx <= x)
			find(T[v].l, sx, tx, sy, ty, depth + 1, ans);
		if (T[v].r != NIL && x <= tx)
			find(T[v].r, sx, tx, sy, ty, depth + 1, ans);
	} else {
		if (T[v].l != NIL && sy <= y)
			find(T[v].l, sx, tx, sy, ty, depth + 1, ans);
		if (T[v].r != NIL && y <= ty)
			find(T[v].r, sx, tx, sy, ty, depth + 1, ans);
	}
}

int main() {

	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		int x, y;
		scanf("%d %d", &x, &y);
		P[i] = Point(i, x, y);
		T[i].location = T[i].l = T[i].r = NIL;
	}

	int root = makeKdTree(0, n, 0);

	int q;
	scanf("%d", &q);
	vector<Point> ans;
	for (int i = 0; i < q; ++i) {
		int sx, tx, sy, ty;
		scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
		ans.clear();
		find(root, sx, tx, sy, ty, 0, ans);
		sort(ans.begin(), ans.end());
		for (int i = 0; i < ans.size(); ++i) {
			ans[i].print();
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 13928
#include <stdio.h>

int main(){
  int n;
  scanf("%d",&n);
  
  switch(n%10){
    case 0:
    case 1:
    case 6:
    case 8:
      printf("pon");
      break;
    case 3:
      printf("bon");
      break;
    default:
      printf("hon");
      break;
  }
  return(0);
}

Measured memory_bytes: 1724
/* ALDS1_2_A: Bubble Sort - http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_A

Bubble Sort
Write a program of the Bubble Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode:

BubbleSort(A)
1 for i = 0 to A.length-1
2     for j = A.length-1 downto i+1
3         if A[j] < A[j-1]
4             swap A[j] and A[j-1]
Note that, indices for array elements are based on 0-origin.

Your program should also print the number of swap operations defined in line 4 of the pseudocode.

Input
The first line of the input includes an integer N, the number of elements in the sequence.

In the second line, N elements of the sequence are given separated by spaces characters.

Output
The output consists of 2 lines.

In the first line, please print the sorted sequence. Two contiguous elements of the sequence should be separated by a space character.

In the second line, please print the number of swap operations.

Constraints
1 ≤ N ≤ 100

Sample Input 1
5
5 3 2 4 1
Sample Output 1
1 2 3 4 5
8

Sample Input 2
6
5 2 4 6 1 3
Sample Output 2
1 2 3 4 5 6
9
*/
use std::io::*;

pub trait BSort {
    fn buble_sort(&mut self) -> i32;
}
impl BSort for Vec<i32> {
    fn buble_sort(&mut self) -> i32 {
        let n = self.len();
        let mut no_swaps = 0;
        // Bubble sort an array and returns the number of swaps 
        // necessary to complete the sort.
        for i in 0..n {
            for j in ((i+1)..n).rev() {
                if self[j] < self[j-1] {
                    let temp = self[j];
                    self[j] = self[j-1];
                    self[j-1] = temp;
                    no_swaps += 1;
                }
            }
        }
        return no_swaps;
    }
}

fn main() {
    let stdin = stdin();
    let mut lines = stdin.lock().lines().map(|l| l.unwrap());

    let n: i32 = lines.next().unwrap().parse().unwrap();
    let mut seq: Vec<i32> = lines.next().unwrap()
        .trim()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();

    //let mut R = lines.take(n).map(|s| s.parse::<i32>().unwrap()).collect();

    let no_swaps = seq.buble_sort();
    let mut ans = array_to_str(&seq);
    ans.push_str(&format!("\n{}", no_swaps));
    println!("{}", ans);
}

// ------------------------------------------------------------------
// Auxiliary methods.
fn array_to_str(arr: &Vec<i32>) -> String {
    // Converts a numerical array to a string for output purposes.
    let mut ans = String::new();
    for a in arr {
        ans.push_str(&format!("{} ", *a));
    }
    return ans.trim().to_string();
}



Measured memory_bytes: 5032
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;

int n;

void solve()
{
    cin>>n;
    if(n%1000==0)
        cout<<0<<endl;
    else{
        int rem=n%1000;
        cout<<1000-rem<<endl;
    }
}

int main()
{
    solve();
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n = 1e6;
int t[5][5];
ll h,a,b,c,d,e;
int ans = 1;
bool memo[15][15] = {0};
int main(){
  int n;
  cin >> n;
  ll a[n];
  map<ll,ll> ma;
  for(int i=0 ; i<n ; i++){
    cin >> a[i];
    ma[a[i]]++;
  }
  ll cnt = 0;
  for(auto ite=begin(ma);ite!=end(ma); ite++){
    ll s = ite->second, f = ite->first;
    if(s<f){
      cnt += s;
    }else{
      cnt += s - f;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 7040
from collections import deque

N, M = map(int, input().split())
edge = [[] for _ in range(N)]
for _ in range(M):
    A,B = map(int, input().split())
    edge[A - 1].append(B - 1)

ans = []
for sta in range(N):
    prev = [-1] * N
    que = deque([sta])

    while que:
        v = que.popleft()
        for w in edge[v]:
            if w == sta:
                path = []
                while v != -1:
                    path.append(v+1)
                    v = prev[v]
                if (not ans) or (len(ans) > len(path)):
                    ans = path
                break

            if prev[w] != -1: continue

            prev[w] = v
            que.append(w)

if ans:
    print(len(ans))
    print(*ans, sep='\n')
else:
    print(-1)


Measured memory_bytes: 3700
a=[]
for i in range(3):
    a.append(list(map(int,input().split())))
b=[[0 for i in range(3)] for j in range(3)]
n=int(input())
for i in range(n):
    p=int(input())
    for j in range(3):
        for k in range(3):
            if p==a[j][k]:
                b[j][k]=1
for i in range(3):
    x=0
    y=0
    for j in range(3):
        if b[i][j]==1:
            x+=1
        if b[j][i]==1:
            y+=1
    if x==3 or y==3:
        print('Yes')
        exit()
if b[0][0]==b[1][1]==b[2][2]==1:
    print('Yes')
    exit()
if b[2][0]==b[1][1]==b[0][2]==1:
    print('Yes')
    exit()
print('No')


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

vvl C;

void comb_table(int N) {
  C.resize(N + 1, vll(N + 1));
  rep(i, N + 1) rep(j, i + 1) {
    if (j == 0 || j == i) {
      C[i][j] = 1LL;
    } else {
      C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
    }
  }
}

main() {
  int N, A, B; cin >> N >> A >> B;
  vll v(N); rep(i, N) cin >> v[i];

  comb_table(N);
  sort(v.begin(), v.end(), greater<ll>());

  double maxave = 0.0;
  rep(i, A) maxave += v[i];
  maxave /= A;

  int x = 0, y = 0;
  rep(i, N) {
    if (v[i] == v[A - 1]) {
      x++;
      if (i < A) {
        y++;
      }
    }
  }

  ll cnt = 0LL;
  if (y == A) {
    for (int i = A; i <= B; i++) cnt += C[x][i];
  } else {
    cnt += C[x][y];
  }

  cout << fixed << setprecision(6) << maxave << endl;
  cout << cnt << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
const int man = 2e5+10;
#define IOS ios::sync_with_stdio(0)
template <typename T>
inline T read(){T sum=0,fl=1;int ch=getchar();
for(;!isdigit(ch);ch=getchar())if(ch=='-')fl=-1;
for(;isdigit(ch);ch=getchar())sum=sum*10+ch-'0';
return sum*fl;}
template <typename T>
inline void write(T x) {static int sta[35];int top=0;
do{sta[top++]= x % 10, x /= 10;}while(x);
while (top) putchar(sta[--top] + 48);}
template<typename T>T gcd(T a, T b) {return b==0?a:gcd(b, a%b);}
template<typename T>T exgcd(T a,T b,T &g,T &x,T &y){if(!b){g = a,x = 1,y = 0;}
else {exgcd(b,a%b,g,y,x);y -= x*(a/b);}}
#ifndef ONLINE_JUDGE
#define debug(fmt, ...) {printf("debug ");printf(fmt,##__VA_ARGS__);puts("");}
#else
#define debug(fmt, ...)
#endif
typedef long long ll;
const ll mod = 1e9+7;

int main() {
	#ifndef ONLINE_JUDGE
		//freopen("in.txt", "r", stdin);
		//freopen("out.txt","w",stdout);
	#endif
	int n;
	cin >> n;
	bool f = 0;
	while(n){
		int tp = n % 10;
		if(tp==7)f = 1;
		n /= 10;
	}	
	if(f)cout << "Yes\n";
	else cout <<"No\n";
	return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
using ll = int64_t;
constexpr ll mod = ll(1e9 + 7);
#define endl '\n'
 
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
 
  int TT = 1;
  // cin >> TT;
  while (TT--) {
    ll R,G,B,K;
    cin >> R >> G >> B >> K;
    while (K && R >= G) {
      G *= 2;
      --K;
    }
    while (K && G >= B) {
      B *= 2;
      --K;
    }
    if (G > R && B > G) {
      cout << "Yes" << endl;
    }else {
      cout << "No" << endl;
    }

  }
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  string S;
  int Q;
  int rev = 0;
  cin >> S >> Q;

  deque<char> q;
  rep(i, S.length()){
    q.push_back(S[i]);
  }

  rep(i,Q) {
    int t;
    cin >> t;
    if(t==1) rev++;
    else {
      int f; char c;
      cin >> f >> c;
      if(rev%2==1 && f==1 || rev%2==0 && f==2) q.push_back(c);
      else q.push_front(c);
    }
  }

  if(rev%2) reverse(q.begin(), q.end());

  while(q.size()){
    cout << q.front();
    q.pop_front();
  }
  cout << endl;
}


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

int main() {
  int n,m,x;cin>>n>>m>>x;
  vector<int> c(n);
  vector<vector<int>> a(n,vector<int>(m));
  long long mini=1e8;
  
  for(int i=0;i<n;i++){
    cin>>c[i];
    for(int j=0;j<m;j++) cin>>a[i][j];
  }
  
  for(int bit=0;bit<(1<<n);++bit){
    vector<int> skill(m,0);
    vector<bool> flag(m,false);
    long long cost=0;
    for(int i=0;i<n;i++){
      if(bit & (1 << i)){
        cost+=c[i];
        for(int j=0;j<m;j++){
          skill[j]+=a[i][j];
          if(skill[j]>=x) flag[j]=true;
        }
      }
    }
    bool check=true;
    for(int j=0;j<m;j++){
      if(!flag[j]){check=false;break;}
    }
    if(check){
      mini=min(mini,cost);
      //cout<<bit<<' '<<cost<<endl;
    }
  }
  if(mini==1e8)cout<<-1<<endl;
  else cout<<mini<<endl;
}


Measured memory_bytes: 3636