akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(b)-1;i>=(a);--i)
#define ALL(a) a.begin(),a.end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
    if (a < b) { a = b; return true; }
    return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
    if (a > b) { a = b; return true; }
    return false;
}
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "{";
    int a = 0;
    for (auto &tp : mp) {
        if (a) os << ", ";
        a = 1;
        os << tp;
    }
    return os << "}";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << p.first << ":" << p.second;
    return os;
}

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

    const int MAX_N = 1000000;
    vi dp(MAX_N, INF), odd(MAX_N, INF);
    dp[0] = odd[0] = 0;
    for (int i = 1; i*(i+1)*(i+2)/6 < MAX_N; ++i) {
        int d = i*(i+1)*(i+2)/6;
        for (int j = 0; j + d < MAX_N; ++j) {
            if (dp[j] != INF) chmin(dp[j+d], dp[j] + 1);
            if (odd[j] != INF and d & 1) chmin(odd[j+d], odd[j] + 1);
        }
    }

    for (;;) {
        int n; cin >> n;
        if (n == 0) break;

        cout << dp[n] << ' ' << odd[n] << endl;
    }

    return 0;
}



Measured memory_bytes: 10636
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        int ans = 0;
        for (int i = 0; i < s.length; i++) {
            if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') {
                int temp = 0;
                for (int j = i; j < s.length; j++) {
                    if (s[j] == 'A' || s[j] == 'C' || s[j] == 'G' || s[j] == 'T') {
                        temp += 1;
                    } else {
                        break;
                    }
                } ans = Math.max(ans, temp);
            }
        } System.out.println(ans);
    }
}


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

bool isBalanced(string s){
	stack<char> acc;
	for(int unsigned i=0;i<s.size();i++){
		if(s[i] == '[') acc.push(']');
		if(s[i] == '(') acc.push(')');
		if(s[i] == ']' || s[i] == ')'){
			if(acc.empty()) return false;
			if(s[i] == acc.top()){
				acc.pop();
			} else {
				return false;
			}
		}
	}
	return acc.empty();
}

int main(){
	string s;
	string left("([");
	string right(")]");
	while(getline(cin,s),s!="."){
		stack<char> acc;
		if(isBalanced(s)){
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3132
n = gets.chomp.to_i

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]
puts a[n-1]


Measured memory_bytes: 1788
import math
import numpy as np
a,b,h,m = list(map(int, input().split()))
a_radian = math.radians(h * 30 + m / 2)
a_ = np.array([a * math.cos(a_radian), a * math.sin(a_radian)])

b_radian = math.radians(6 * m)
b_ = np.array([b * math.cos(b_radian), b * math.sin(b_radian)])

print(np.linalg.norm(a_ - b_))

Measured memory_bytes: 27216
#include <iostream>

using namespace std;

int main()
{
    string a;
    cin>>a;
    for(int i=0; i<a.size(); i+=2){
        if(a[i]=='L'){
            cout<<"No";
            return 0;
        }
    }
    for(int i=1; i<a.size(); i+=2){
        if(a[i]=='R'){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<cmath>
using namespace std;
int A, B;
int main() {
	scanf("%d%d", &A, &B);
	int i;
	for (i = 0; i <= 1250; i++) {
		if (floor(i * 0.08) == A && floor(i * 0.10) == B)break;
	}
	printf("%d", i == 1251 ? -1 : i);
	return 0;
}

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

def p_f(n):
    L = []
    c = 2
    while c <= n:
        if n%c == 0:
            L.append(c)
            n /= c
        else:
            c += 1
    return L


if N == 1:
    print(0)
else:
    dic = {}
    for i in range(2, N+1):
        L = p_f(i)
        for j in range(len(L)):
            if L[j] in dic:
                dic[L[j]] += 1
            else:
                dic[L[j]] = 1
    num3 = 0
    num5 = 0
    num15 = 0
    num25 = 0
    num75 = 0
    for key in dic:
        if dic[key] >= 2:
            num3 += 1
            if dic[key] >= 4:
                num5 += 1
                if dic[key] >= 14:
                    num15 += 1
                    if dic[key] >= 24:
                        num25 += 1
                        if dic[key] >= 74:
                            num75 += 1
    ans = num75 + num25*(num3-1) + num15*(num5-1) + num5*(num5-1)//2*(num3-2)
    print(ans)

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

int main() 
{
    int N;
    cin >> N;
    
    vector<int>DP(110000, 10e5);
    DP[0] = 0;
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= i; j *= 6) {
            DP[i] = min(DP[i], DP[i-j]+1);
        }
        for (int j = 1; j <= i; j *= 9) {
            DP[i] = min(DP[i], DP[i-j]+1);
        }
    }
    cout << DP[N] << endl;
}

Measured memory_bytes: 640
n = int(input())
a = list(map(int,input().split()))
list_S = [0]
ans = 0
for i in range(n):
    list_S.append(list_S[i] + a[i])

list_S.sort()
pre = list_S[0]
acc = 1
for i in range(1,n+1):
    if list_S[i] == pre:
        acc += 1
    else:
        ans += acc * (acc-1) // 2
        pre = list_S[i]
        acc = 1

ans += acc * (acc-1) // 2

    
print(ans)


Measured memory_bytes: 26720
#include <stdio.h>
#include <iostream>

#include <vector>
#include <algorithm>
#include <string>
#include <map>

using namespace std;

int main() {
  int N;
  char S[300000];
  int result[300000];

  scanf("%d", &N);
  scanf("%s", S);

  int ans = 0;

  for(int i = 1; i < N; i++){
    if(S[i] == 'E'){
      ans++;
    }
  }
  result[0] = ans;

  for(int i = 1; i < N; i++){
    result[i] = result[i - 1];

    if(S[i] == 'E'){
      result[i]--;
    }

    if(S[i - 1] == 'W'){
      result[i]++;
    }

    if(result[i] < ans){
      ans = result[i];
    }
  }

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

  return 0;
}


Measured memory_bytes: 1664
import collections
n = int(raw_input())
s = raw_input()

def f(k, s):	
	if k == 0:
		return True
 	cc = collections.Counter()
	q = collections.deque()
	for j in range(k - 1, len(s)):
		q.append(s[j - k + 1:j+1])
		if len(q) == k + 1:
			u = q.popleft()
			cc[u] += 1
		if s[j- k+1:j+1] in cc:
			return True	
	return False
lo,hi = 0, n/2 + 1
while(lo < hi):
	med = (lo + hi + 1) / 2
	if f(med, s):
		lo = med
	else:
		hi = med - 1

print lo

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

using namespace std;
typedef long long ll;
ll MOD = 1e9 + 7;
int X[10][10];
int main() {
	int N, D;
	cin >> N >> D;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < D; j++) cin >> X[i][j];
	}
	int ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			int sum = 0;
			for (int k = 0; k < D; k++) {
				sum += (X[i][k] - X[j][k])*(X[i][k] - X[j][k]);
			}
			int k = 0;
			while (k*k < sum) k++;
			if (k*k == sum) ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i=0; i < (n); ++i)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool change(T& a, T b) { if (a != b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;

int main(){
    int n; cin >> n;
    if(n>=30) cout << "Yes" <<endl;
    else cout << "No" <<endl;
}

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

void trace (vector<int> A, int N) {
    int i;
    for (i = 0; i < N; i++) {
        if (i > 0){
            cout << " ";
        }
        cout << A.at(i);
    }
    cout << endl;
}

void insertionSort (vector<int> A, int N){
    int v, j;
    for (int i = 1; i < N; i++){
        v = A.at(i);
        j = i - 1;
        while (j >= 0 && A.at(j) > v){
            A.at(j + 1) = A.at(j);
            j--;
        }
        A.at(j + 1) = v;
        trace(A, N);
    }
}

int main() {
    int N;
    cin >> N;
    vector<int> A(100);

    for (int i = 0; i < N; i++){
        cin >> A.at(i);
    }
    trace(A, N);
    insertionSort(A, N);
    
    return 0;
}


Measured memory_bytes: 3156
#include<stdio.h>
int gcd(int a,int b,int c){
    int i,gcd=1;
    for(i=1;i<=a&&i<=b&&i<=c;i++){
        if(a%i==0&&b%i==0&&c%i==0)
            gcd=i;
    }
    return gcd;
}
int main()
{
    int n,i,j,k,total=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            for(k=1;k<=n;k++){
                total+=gcd(i,j,k);
            }
        }
    }
    printf("%d",total);
    return 0;
}


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

// # DEFINES # //
#define ll long long
#define M (ll)1e9+7
#define EPS 1e-9

using namespace std;


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

    ll n;

    cin >> n;

    vector<int> arr(n);

    for(int i = 0; i < n; i++)
        cin >> arr[i];
    
    ll count = 0;
    bool maior;
    for(int i = arr.size()-1; i >= 0; i--) {
        maior = false;
        for(int j = i; j >= 0; j--) {
            if(arr[i] < arr[j])
                maior = true;
        }
        if(maior == false)
            count++;
    }
    cout << count << endl;
    

    return 0;
}

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

int main()
{int N, M;
 cin >> N >> M;
 int x = 1900 * M + 100 * (N - M);
 int y = 1;
 rep(i, M){
   y *= 2;
 }
 cout << x*y << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main(){
  int n, d;
  cin >> n >> d;
  int x[11][11];
  int cnt = 0;
  for(int i=0; i<n; i++)for(int j=0; j<d; j++)cin >> x[i][j];
  for(int i=0; i<n-1; i++){
    for(int j=i+1; j<n; j++){
      int tmp = 0;
      for(int k=0; k<d; k++)tmp += pow(x[i][k] - x[j][k], 2);
      double t = sqrt(tmp);
      if(ceil(t) == floor(t))cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, m, k int
	fmt.Scan(&n, &m, &k)
	ok := false
	if k%n == 0 || k%m == 0 {
		ok = true
	} else {
		for i := 1; i < n; i++ {
			for j := 1; j < m; j++ {
				if k == i*(m-j)+j*(n-i) {
					// fmt.Printf("(%d,%d) -> i*(m-i) %d, j*(n-j) %d\n", i, j, i*(m-i), j*(n-j))
					ok = true
				}
			}
		}
	}
	if ok {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
from heapq import heappush, heappop

N, M, S = map(int, input().split())
mxCost = 0

edges = [[] for _ in range(N)]
for _ in range(M):
    fr, to, cost, dist = map(int, input().split())
    mxCost = max(mxCost, cost)
    fr -= 1
    to -= 1
    edges[fr].append((to, dist, cost))
    edges[to].append((fr, dist, cost))

for i in range(N):
    C, D = map(int, input().split())
    edges[i].append((i, D, -C))

que = [(0, S, 0)]
mxCost *= (N - 1)
minDsit = [[10**18] * (mxCost + 1) for _ in range(N)]
minDsit[0][0] = 0

while que:
    dist, s, now = heappop(que)

    for to, d, c in edges[now]:
        cost = min(mxCost, s - c)
        if cost < 0 or minDsit[to][cost] <= dist + d:
            continue
        minDsit[to][cost] = dist + d
        heappush(que, (dist + d, cost, to))

for dist in minDsit[1:]:
    print(min(dist))


Measured memory_bytes: 25864
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

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

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}


// ダブリング
// cost 0 での遷移を書いてからpreCalcする！
// verify 
//  getCost ARC060E
namespace Doubling {
    using NODE_TYPE = int;
    using COST_TYPE = long long;
    // d[i][0]はあらかじめ計算しておく！
    void preCalc(vector<vector<NODE_TYPE>>& d) {
        int n = d.size();
        int m = d[0].size();
        REP(j, 1, m) rep(i, n) {
            d[i][j] = d[d[i][j-1]][j-1];
        }
    }
    // 頂点uからcostでいける頂点を求める
    NODE_TYPE getNode(NODE_TYPE u, COST_TYPE cost, const vector<vector<NODE_TYPE>>& d) {
        int n = d.size();
        int m = d[0].size();
        NODE_TYPE cur = u;
        repr(j, m) {
            if(cost&(COST_TYPE(1)<<j)) {
                cur = d[cur][j];
            }
        }
        return cur;
    }
    // 頂点uから頂点vまでのコストを求める(iはトポロジカルソート後のidx)
    COST_TYPE getCost(NODE_TYPE u, NODE_TYPE v, const vector<vector<NODE_TYPE>>& d) {
        if(u >= v) assert(false);
        int n = d.size();
        int m = d[0].size();
        int cur = u;
        COST_TYPE ret = 0;
        while(cur < v) {
            if(d[cur][0] >= v) {
                ret += 1;
                break;
            }
            int j = lower_bound(all(d[cur]), v) - d[cur].begin() - 1;
            cur = d[cur][j];
            ret+= COST_TYPE(1) << j;
        }
        return ret;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    vector<vi> d(n, vi(62, -1));
    rep(i, n) d[i][0] = (s[i] == 'L' ? i-1 : i+1);
    Doubling::preCalc(d);
    vi cnt(n);
    rep(i, n) cnt[Doubling::getNode(i, 2e5, d)]++;
    rep(i, n) {
        cout << cnt[i] << (i == n-1 ? '\n' : ' ');
    }
    return 0;
}

Measured memory_bytes: 28368
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {//
        a:usize,b:usize,c:usize,
        k:usize,
    }
    let mut a = a;
    let mut b = b;
    let mut c = c;
    for _ in 0..k {
        if b <= a {
            b *= 2;
        } else if c <= b {
            c *= 2;
        }
    }
    if a < b && b < c {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2156
class Array
  def cumsum(s = 0); map{|k| s += k } end
end

n, m, k = gets.to_s.split.map{|t|t.to_i}
a = gets.to_s.split.map{|t|t.to_i}
b = gets.to_s.split.map{|t|t.to_i}

ac = a.cumsum.unshift(0)
bc = b.cumsum.unshift(0)

j = m
ans = 0
ac.each_with_index do |t, i|
  while t + bc[j] > k && j > 0
    j -= 1
  end
  ans = [ans, i + j].max if t + bc[j] <= k
end

puts ans

Measured memory_bytes: 46524
N, K = map(int, input().split())
D = list(map(int, input().split()))
E = [x for x in range(10) if x not in D]
# print(N, K, D, E)

def is_valid(n):
    while n > 0:
        d = n % 10
        if d in D:
            return False
        n //= 10
    return True

ans = N
while not is_valid(ans):
    ans += 1

print(ans)


Measured memory_bytes: 41632
import java.io.*;
import java.util.*;

class FastReader 
{ 
    BufferedReader br; 
    StringTokenizer st; 
    
    public FastReader() 
    { 
        br = new BufferedReader(new InputStreamReader(System.in)); 
    } 
    
    String next() 
    { 
        while (st == null || !st.hasMoreElements()) 
        { 
            try
            { 
                st = new StringTokenizer(br.readLine()); 
            } 
            catch (IOException  e) 
            { 
                e.printStackTrace(); 
            } 
        } 
        return st.nextToken(); 
    } 
    
    int nextInt() 
    { 
        return Integer.parseInt(next()); 
    } 
    
    long nextLong() 
    { 
        return Long.parseLong(next()); 
    } 
    
    double nextDouble() 
    { 
        return Double.parseDouble(next()); 
    } 
    
    String nextLine() 
    { 
          String str = ""; 
        try
        { 
            str = br.readLine(); 
        } 
        catch (IOException e) 
        { 
            e.printStackTrace(); 
        } 
        return str; 
    } 
} 

class Solution
{
    void solve()
    {
        FastReader s = new FastReader();
        
        int N = s.nextInt(),count = 0;

        int arr[] = new int[N];

        for(int i = 0 ; i < N; i++)
            arr[i] = s.nextInt();

        Arrays.sort(arr);

        int index1 = N/2 - 1;
        int index2 = N/2;

        int num1 = arr[index1], num2 = arr[index2];

        System.out.println(num2 - num1);

    }
}
  
public class Main 
{ 
    public static void main(String[] args) 
    { 
        Solution ob = new Solution();

        ob.solve();
    } 
} 

Measured memory_bytes: 43920
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	public static void main (String[] args) {

		Integer[] mountainHigh = new Integer[10];
		Scanner stdin = new Scanner(System.in);
		for(int i = 0; i < 10; i++) {
			mountainHigh[i] = stdin.nextInt();
		}
		Arrays.sort(mountainHigh,Comparator.reverseOrder());

		for(int high = 0; high < 3; high++) {
			System.out.println(mountainHigh[high]);
		}

	}

}

Measured memory_bytes: 26164
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Move {
 public:
  int x1;
  int y1;
  int x2;
  int y2;
} move;
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<int>> A(H, vector<int>(W));
  REP(i, H) REP(j, W) cin >> A[i][j];
  queue<Move> Q{};
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (i == H - 1 && j == W - 1) break;
      int div = i % 2 == 0 ? 1 : -1;
      int tmp = i % 2 == 0 ? j : W - 1 - j;
      if (A[i][tmp] % 2 == 1) {
        Move m;
        m.x1 = tmp, m.y1 = i;
        m.x2 = tmp;
        m.y2 = i;
        if (j == W - 1) {
          m.y2 += 1;
        } else {
          m.x2 += div;
        }
        Q.push(m);
        A[m.y1][m.x1] -= 1, A[m.y2][m.x2] += 1;
      }
    }
  }
  cout << Q.size() << endl;
  while (!Q.empty()) {
    Move m = Q.front();
    Q.pop();
    cout << m.y1 + 1 << " " << m.x1 + 1 << " " << m.y2 + 1 << " " << m.x2 + 1
         << endl;
  }
}

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

int main(){
    string s,t;
    cin>>s>>t;
    int n=s.size(),m=t.size();
    if(n==m-1){
        for(int i=0;i<n;i++)
            if(s[i]!=t[i]){
                cout<<"No\n";
                return 0;
            }
    }
    
    cout<<"Yes\n";
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
typedef vector<int> vec;
typedef vector<int64> vec64;
#define db(x) cout << "> " << #x << ": " << x << "\n";
#define ss cout << " ";
#define ct(x) cout << x;
#define nn cout << "\n";
#define cts(x) cout << x << " ";
#define ctn(x) cout << x << "\n";
#define qr queries();
void solve();
void YN(bool b){if (b){ctn("YES");}else{ctn ("NO");}};
void yn(bool b){if (b){ctn("Yes");}else{ctn ("No");}};
void queries(){int n;cin >> n;while (n--)solve();}
// // // // // // // // // // // // // // // // // // // // // // 
/*                  TEMPLATE - VANILLA                         */
// // // // // // // // // // // // // // // // // // // // // //
int64 q, n;

void solve(){

    return;
}


int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin >> n;
    vec arr (n);
    for (int i = 0; i < n; i++){
        cin >> arr[i];
    }
    int64 tovisit = 1;
    int64 rs = 0;
    bool one = 0;
    int last = 0;
    for (int i = 0; i < n; i++){
        if (arr[i] == 1){
            one = 1;
        }
        if (arr[i] != tovisit){
            last++;
        }
        else{
            tovisit++;
            rs+=last;
            last = 0;
        }
    }
    rs+=last;
    if (!one){
        ctn(-1);
        return 0;
    }
    ctn(rs);
    return 0;
}


Measured memory_bytes: 3992
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

//#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define mkt make_tuple
#define no {cout << "No"; return;}

void solve() {
    int n; cin >> n;
    vector <int> a(n), b(n), c(n);
    loop(i, n) {
        cin >> a[i];
        --a[i];
    }
    loop(i, n)
        cin >> b[i];
    loop(i, n - 1)
        cin >> c[i];
    int ans = 0;
    loop(i, n)
        ans += b[a[i]] + (i && a[i] == a[i - 1] + 1 ? c[a[i] - 1] : 0);
    cout << ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

Measured memory_bytes: 3544
#include <iostream>
#include <string.h>
using namespace std;

int main() {
	int n;
	string name[55];
	int time[55];

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

	string x;
	cin >> x;

	int spot;
	for (int i = 0; i < n; i++) {
		if (name[i] == x) {
			spot = i;
			break;
		}
	}

	int result = 0;
	for (int i = spot + 1; i < n; i++) {
		result += time[i];
	}

	cout << result << "\n";

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n,c,i,j,k,h,w,a,b;
string s;
int main(){
  cin>>s>>k;
  for(i=0;i<s.size();i++)if(s[i]!='1')break;
  if(k<=i)cout<<1;
  else cout<<s[i];
}

Measured memory_bytes: 256
#include<iostream>
#include<set>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include <algorithm>
using namespace std;


int main(){
  int N,K;
  cin >> N>>K;
  int A[200010];
  int count[200010] = {0};
  set<int> values;

  for(int i= 0;i<N;i++){
    cin>>A[i];
    count[A[i]-1]++;

  }

  sort(count,count+N );
  int ans = 0;
  for(int i=0;i<N-K;i++){
      ans+=count[i];


  }
  cout<<ans<<endl;



  return 0;
}


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

struct edge {
  int x, y, flow;
};

const int INF = 1e9 + 69 * 69;
const int N = 100 * 100 + 5;

int i, j, k, n, m, source, sink, ptr[10005 + N], d[10005 + N], q[10005 + N];
string a[105];
vector<edge> e;
vector<int> lde[10005 + N];

int getNod(int x, int y) { return x * m + y; }

void addEdge(int x, int y, int flow) {
  edge e1 = {x, y, flow};
  edge e2 = {y, x, 0};

  lde[x].push_back((int)e.size());
  e.push_back(e1);
  lde[y].push_back((int)e.size());
  e.push_back(e2);
}

bool bfs() {
  int qh, qt, to;

  memset(d, -1, sizeof(d));
  d[source] = 0; q[1] = source;

  for(qt = qh = 1; qh <= qt && d[sink] == -1; ++qh)
    for(auto id : lde[q[qh]]) {
      to = e[id].y;
      if(d[to] == -1 && e[id].flow > 0) q[++qt] = to, d[to] = d[q[qh]] + 1;
    }

  return d[sink] != -1;
}

int dfs(int x, int flow) {
  if(!flow) return 0;
  if(x == sink) return flow;

  for(; ptr[x] < (int)lde[x].size(); ++ptr[x]) {
    int id = lde[x][ptr[x]], to = e[id].y;
    if(d[to] != d[x] + 1) continue;

    int pushed = dfs(to, min(flow, e[id].flow));

    if(pushed) {
      e[id].flow -= pushed;
      e[id ^ 1].flow += pushed;
      return pushed;
    }
  }

  return 0;
}

int dinic() {
  int flow, ans = 0;

  while(bfs()) {
    memset(ptr, 0, sizeof(ptr));
    while((flow = dfs(source, INF))) ans += flow;
  }

  if(ans > 1e9) ans = -1;

  return ans;
}

int main() {
  ios_base::sync_with_stdio(0);

  cin >> n >> m;
  for(i = 0; i < n; ++i) cin >> a[i];

  for(i = 0; i < n; ++i)
    for(j = 0; j < m; ++j) {
      if(a[i][j] == 'S') source = getNod(i, j);
      if(a[i][j] == 'T') sink = getNod(i, j);
      if(a[i][j] == 'o') addEdge(N + getNod(i, j), getNod(i, j), 1);
    }

  for(i = 0; i < n; ++i)
    for(j = 0; j < m; ++j) {
      if(a[i][j] == '.') continue;
      if(a[i][j] == 'T') continue;

      for(k = 0; k < m; ++k)
        if(a[i][k] != '.' && k != j) addEdge(getNod(i, j), (getNod(i, k) == sink ? 0 : 1) * N + getNod(i, k), getNod(i, j) == source ? INF : 1);

      for(k = 0; k < n; ++k)
        if(a[k][j] != '.' && k != i) addEdge(getNod(i, j), (getNod(k, j) == sink ? 0 : 1) * N + getNod(k, j), getNod(i, j) == source ? INF : 1);
    }

  cout << dinic() << '\n';

  return 0;
}

Measured memory_bytes: 69920
import heapq

class ShortestPath:
    def __init__(self, V, E, start, INF = float('inf')):
        self.V = V
        self.E = E 
        self.dijkstra(start, INF)

    def dijkstra(self, start, INF):
        que = list()
        self.distance = [INF] * self.V
        self.prev = [-1] * self.V
        self.distance[start] = 0
        heapq.heappush(que, (0, start))

        while len(que) > 0:
            dist, fr = heapq.heappop(que)
            if self.distance[fr] < dist:
                continue
            for to, cost in self.E[fr]:
                if self.distance[fr] + cost < self.distance[to]:
                    self.distance[to] = self.distance[fr] + cost
                    heapq.heappush(que, (self.distance[to], to))
                    self.prev[to] = fr 


V = int(input())
edge = [[] for _ in range(V)]
for _ in range(V):
    u, _, *e = map(int, input().split())
    for t, d in zip(e[::2], e[1::2]):
        edge[u].append((t, d))

sp = ShortestPath(V, edge, 0)
for i, d in enumerate(sp.distance):
    print(i, d)



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

typedef long long ll;
int main(){
  ll N;
  cin >> N;
  ll power = 1;
  ll mod = 1000000000 + 7;
  for(int i = 1; i <= N;i++){
    power = power * i;
    power = power % mod;
  }
  cout << power << endl;
  

}

Measured memory_bytes: 256
n = int(input())
t = list(map(int, input().split()))
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

tmax, amax = max(t), max(a)
if not any(ti == ai == tmax == amax for ti, ai in zip(t, a)):
    print(0)
    exit()

ans = 1
for i in range(1, n - 1):
    if ((t[i - 1] < t[i] and t[i] > a[i])
        or (a[i] > a[i + 1] and t[i] < a[i])):
            print(0)
            break
    elif t[i - 1] == t[i] and a[i] == a[i + 1]:
        ans = ans * min(t[i], a[i]) % mod
else:
    print(ans)


Measured memory_bytes: 97772
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223372036854775807
#define INF 2147483647
#define MOD 1000000007
using namespace std;

ll func( ll xx[40][2], ll* a, long num )
{
    ll sum=0;
    long i;
    for(i=0; i<40; i++) {
        ll curr= (i<num? a[i]: 0);
        sum += (xx[i][1-curr]<<i);
    }
    return sum;
}

ll value( ll* a, long num )
{
    ll sum=0;
    long i;
    for(i=0; i<num; i++) {
        sum += ((ll)a[i]<<i);
    }
    return sum;
}

int main(int argc, char* argv[])
{
    long n,k;
    scanf("%ld%ld", &n, &k);

    vector<ll> a(n);
    long i, j;
    for(i=0; i<n; i++) {
        scanf("%lld", &a[i]);
    }

    vector<ll> kk;
    long tmp = k;
    while( tmp>0 ) {
        kk.push_back(tmp%2);
        tmp /= 2;
    }

    ll xx[40][2]={0};
    long c[40]={0};
    for(j=0; j<40; j++) {
        for(i=0; i<n; i++) {    
            xx[j][(a[i]>>j)&1]++;
        }
        c[j]=(xx[j][0]<=xx[j][1]? 0: 1);
    }

    ll max=-1;
    long len=(long)kk.size();
    for(i=0; i<len; i++) {
        vector<ll> kk2=kk;
        long m;
        for(m=0; m<=i; m++) {
            kk2[m]=c[m];
        }
        if ( value( &(kk2[0]), len ) <= k ) {
            ll tmp = func( xx, &(kk2[0]), len );
            max = MAX(max, tmp);
        }
        if( i<len-1 && kk2[i+1]==1 ) {
            kk2[i+1]=0;
            ll tmp = func( xx, &(kk2[0]), len );
            max = MAX(max, tmp);
        }
    }
    if(len==0) {
        ll a = 0;
        ll tmp = func( xx, &a, 0 );
        max = MAX(max, tmp);
    }
    else {
        ll tmp = func( xx, &(kk[0]), len );
        max = MAX(max, tmp);
    }

    printf("%lld\n", max);

    return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using static System.Math;
using static System.Console;
class Simple
{
    int N, M;
    int[] L, R, D;

    List<Edge>[] adj;
    bool[] isVisited;
    long[] dis;

    void Solve() {
        //input
        N = io.Int;
        M = io.Int;
        L = new int[M];
        R = new int[M];
        D = new int[M];
        for(int i = 0; i < M; ++i) {
            L[i] = io.Int;
            R[i] = io.Int;
            D[i] = io.Int;
        }
        //cal
        adj = new List<Edge>[N + 1];
        for(int i = 0; i < adj.Count(); ++i) {
            adj[i] = new List<Edge>();
        }
        for(int i = 0; i < M; ++i) {
            adj[L[i]].Add(new Edge(R[i],  D[i]));
            adj[R[i]].Add(new Edge(L[i], -D[i]));
        }
        dis = new long[N + 1];
        isVisited = new bool[N + 1];

        for(int i = 1; i <= N; ++i) {
            if (!isVisited[i]) {
                isVisited[i] = true;
                dfs(i, 0);
            }
        }
        //ret
        WriteLine("Yes");
    }

    void dfs(int cur,int pre) {
        foreach(var e in adj[cur]) {
            var next = e.To;
            var cost = e.Cost;
            if (isVisited[next]) {
                var pred = dis[next] - cost;
                if(dis[cur]!= pred) {
                    WriteLine("No");
                    io.writeFlush();
                    Environment.Exit(0);
                }
            } else {
                isVisited[next] = true;
                dis[next] = dis[cur] + cost;
                dfs(next, cur);
            }
        }
    }

    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) => new Simple().Stream(); 
    void Stream() { Solve(); io.writeFlush(); }
}
public struct Edge : IComparable<Edge>
{
    public int To;
    public long Cost;
    public Edge(int to, long cost) {
        this.To = to;
        this.Cost = cost;
    }
    public int CompareTo(Edge e) => Cost.CompareTo(e.Cost);
}

class SimpleIO
{
    string[] nextBuffer;
    int BufferCnt;
    char[] cs = new char[] { ' ' };
    StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    public SimpleIO() {
        nextBuffer = new string[0];
        BufferCnt = 0;
        Console.SetOut(sw);
    }
    public string Next() {
        if (BufferCnt < nextBuffer.Length)
            return nextBuffer[BufferCnt++];
        string st = Console.ReadLine();
        while (st == "")
            st = Console.ReadLine();
        nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        BufferCnt = 0;
        return nextBuffer[BufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void writeFlush() { Console.Out.Flush(); }
}


Measured memory_bytes: 49276
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		String S = sc.next();
		int K = Integer.parseInt(sc.next());
		String s = S.substring(K - 1, K);
		for(int i = 0; i < S.length(); i++) {
			if(S.substring(i, i + 1).equals(s)) {
				System.out.print(s);
			} else {
				System.out.print("*");
			}
		}
		System.out.println();
	}
}


Measured memory_bytes: 21844
N,A,B,C,D=map(int, raw_input().split())
S=raw_input()

if C<D:
	if "##"  in S[B-1:D]:
		print "No"
		quit()
	if "##" in S[A-1:C]:
		print "No"
		quit()
	print "Yes"
elif D<C:
	if "##" in S[A-1:C]:
		print "No"
		quit()

	if "..." in S[B-2:D+1]:
		print "Yes"
		quit()
	print "No"

Measured memory_bytes: 29036
#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define endl        "\n"

const int mod = 1e9+7;

inline int add(int a, int b) { int res = a + b; if(res >= mod) res -= mod;  return res; }
inline int sub(int a, int b) { int res = a - b; if(res < 0) res += mod; return res;}
inline int mul(int a, int b) { return (a * b)%mod; }

void solve() {
    int n, a, b; cin >> n >> a >> b;
    if(a+b-1 > n or a*b<n) {
        cout << -1 << endl;
        return;
    }
    if(b==1) {
        for(int i=1; i<=n; i++) cout << i << " ";
        return;
    }
    vector<int> ans;
    int st = n - a + 1;
    for(int i=st; i<=n; i++) ans.push_back(i);
    int div = (n - a)/(b - 1);
    int rem = n - a;
    int ex = rem - div*(b - 1);
    for(int i=0; i<ex; i++) {
        // Add extra in then
        vector<int> v;
        for(int j=0; j<div+1; j++) v.push_back(rem - j);
        rem -= (div + 1);
        reverse(v.begin(), v.end());
        for(int x : v) ans.push_back(x);
    }
    for(int i=0; i < (b - 1 - ex); i++) {
        vector<int>v;
        for(int j=0; j<div; j++) v.push_back(rem - j);
        rem -= div;
        reverse(v.begin(), v.end());
        for(int x : v) ans.push_back(x);
    }
    for(int x : ans) cout << x << " ";
    cout << endl;
}

signed main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(12);

    int T = 1;
    //cin >> T;

    while(T--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 6256
local mce, mfl, msq, mmi, mma = math.ceil, math.floor, math.sqrt, math.min, math.max

local function getprimes(x)
  local primes = {}
  local allnums = {}
  for i = 1, x do allnums[i] = true end
  for i = 2, x do
    if(allnums[i]) then
      table.insert(primes, i)
      local lim = mfl(x / i)
      for j = 2, lim do
        allnums[j * i] = false
      end
    end
  end
  return primes
end

local function getdivisorparts(x, primes)
  local prime_num = #primes
  local tmp = {}
  local lim = mce(msq(x))
  local primepos = 1
  local dv = primes[primepos]
  while(primepos <= prime_num and dv <= lim) do
    if(x % dv == 0) then
      local asdf = {}
      asdf.p = dv
      asdf.cnt = 1
      x = x / dv
      while(x % dv == 0) do
        x = x / dv
        asdf.cnt = asdf.cnt + 1
      end
      table.insert(tmp, asdf)
      lim = mce(msq(x))
    end
    if(primepos == prime_num) then break end
    primepos = primepos + 1
    dv = primes[primepos]
  end
  if(x ~= 1) then
    local asdf = {}
    asdf.p, asdf.cnt = x, 1
    table.insert(tmp, asdf)
  end
  return tmp
end
local n, p = io.read("*n", "*n")
local primes = getprimes(mce(msq(p)))
local divp = getdivisorparts(p, primes)
local ret = 1
for i = 1, #divp do
  local v = divp[i]
  local mul = mfl(v.cnt / n)
  for j = 1, mul do
    ret = ret * v.p
  end
end
print(ret)


Measured memory_bytes: 10240
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
#include <stack>
#include <queue>
using namespace std;
#define lol long long


int main()
{
	int A, B, C;
	cin >> A >> B >> C;
	if (A == B && B == C) {
		cout << "Yes" << endl;
 	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <string.h>
using namespace std;
int main(){
    int s = 0;
    int ans = 0;
    int fh = 0,fy = 0;

    cin>>s;

    for (int i = 0; i*500 <= s; i++){
        fh = i;
    }
    for (int i = 0; i*5 <= s-fh*500; i++){
        fy = i;
    }

    ans = fh*1000 + fy*5;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
A_ary, B_ary, C_ary = [str(input()) for _ in range(3)]

tmp = A_ary[0]
A_ary = A_ary[1:]
while True:
    if tmp == 'a':
        if A_ary:
            tmp = A_ary[0]
            A_ary = A_ary[1:]
        else:
            print('A')
            break
    elif tmp == 'b':
        if B_ary:
            tmp = B_ary[0]
            B_ary = B_ary[1:]
        else:
            print('B')
            break
    else:
        if C_ary:
            tmp = C_ary[0]
            C_ary = C_ary[1:]
        else:
            print('C')
            break

Measured memory_bytes: 3064
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    
    int i = 0;
    int x = 0;
    while (x < X) {
      i++;
      x += i;
    }
    
    System.out.println(i);
  }
}

Measured memory_bytes: 23636
# -*- coding: utf-8 -*-

import sys
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, X = MAP()

print((N-gcd(N, X))*3)


Measured memory_bytes: 5556
import heapq
X,Y,A,B,C = map(int,input().split())
Plist = list(map(int,input().split()))
Qlist=  list(map(int,input().split()))
Rlist  = list(map(int,input().split()))
Plist.sort(reverse = True)
Qlist.sort(reverse = True)
Rlist.sort(reverse = True)
i,j,k = 0,0,0
pmax = Plist[i]
qmax = Qlist[i]
rmax = Rlist[i]
Ans = 0
for _ in range(2*10**5):
    Ans += max(pmax,qmax,rmax)
    if pmax == max(pmax,qmax,rmax):
        i += 1
        if i != X:
            pmax = Plist[i]
        else:
            pmax = -1
    elif qmax == max(pmax,qmax,rmax):
        j += 1
        if j != Y:
            qmax = Qlist[j]
        else:
            qmax = -1
    else:
        k += 1
        try:
            rmax = Rlist[k]
        except:
            rmax = -1
    if i+j+k == X+Y:
        break
print(Ans)

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

int N,A,B,C,l[10];

int rec(int cur, int a, int b, int c){
    if(cur == N){
        if(!a || !b || !c)return pow(10,9);
        return abs(a-A)+abs(b-B)+abs(c-C);
    }

    int res=rec(cur+1,a,b,c);

    res=min(res,rec(cur+1,a+l[cur],b,c) + (a ? 10:0));
    res=min(res,rec(cur+1,a,b+l[cur],c) + (b ? 10:0));
    res=min(res,rec(cur+1,a,b,c+l[cur]) + (c ? 10:0));

    return res;
}

int main(){
    cin >> N >> A >> B >> C;
    for(int i=0;i<N;i++){
        cin >> l[i];
    }
    cout << rec(0,0,0,0);
}

Measured memory_bytes: 256
//url:
//problem name:

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long,long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long,long>>;

int main() {
    int N; cin >> N;
    string S;
    cin >> S;
    int ans = 0;
    int x = 0;
    REP(i,N) {
        if(S[i] == 'I') x++;
        else x--;
        chmax(ans,x);
    }
    cout << ans << endl;
}

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

struct Graph
{
    int n;
    vector<vector<int>> g;
    
    Graph(int n) : n(n){
        g.resize(n);
    }
    
    void init(int n_){
        n = n_;
        g.resize(n_);
    }
    
    void add_edge(int from, int to){
        g[from].push_back(to);
    }
};

int main()
{
    int n, m;
    cin >> n >> m;
    Graph g(n);
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        g.add_edge(a, b);
        g.add_edge(b, a);
    }
    int ans[100005];
    for(int i = 0; i < n; i++) ans[i] = -2;
    queue<int> que;
    ans[0] = -1;;
    que.push(0);
    while(que.size()){
        int u = que.front();
        que.pop();
        for(int v : g.g[u]){
            if(ans[v] != -2) continue;
            ans[v] = u;
            que.push(v);
        }
    }
    cout << "Yes" << endl;
    for(int i = 1; i < n; i++) cout << ans[i] + 1 << endl;
}


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

int main(){
  string X; cin >> X;
  bool del=true;
  while(X.size()>0&&del==true){
    del=false;
    int pos=-1,slen=0,tlen=0;
    for(int i=0; i<X.size(); i++){
      if(pos<0){
        if(X[i]=='S'){
          pos=i;
          slen++;
        }
      }else{
        if(tlen==0&&X[i]=='S'){
          slen++;
        }else if(X[i]=='T'){
          tlen++;
        }else{
          break;
        }
      }
    }
    if(slen*tlen!=0){
      del=true;
      if(slen>=tlen){
        X=X.substr(0,pos+slen-tlen)
          +((pos+slen+tlen<X.size())?X.substr(pos+slen+tlen):"");
      }else{
        X=X.substr(0,pos)+X.substr(pos+slen*2);
      }
    }
  }
  cout << X.size() << endl;
}

Measured memory_bytes: 1136
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int mod = 1e9 + 7;
const int inf = 2e18;

signed main() {
    int N, W;
    cin >> N >> W;
    vector<int> w(N + 1), v(N + 1);
    for (int i = 1; i <= N; i++) {
        cin >> w[i] >> v[i];
    }
    vector<vector<int>> dp(N + 1, vector<int>(1e5 + 10, inf));
    dp[0][0] = 0;
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= 1e5 + 10; j++) {
            if (j < v[i]) dp[i][j] = min(dp[i][j], dp[i - 1][j]);
            else dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i]);
        }
    }
    int ans = 0;
    for (int i = 0; i < 1e5 + 10; i++) {
        if (dp[N][i] <= W) ans = i;
    }
    cout << ans << endl;
}



Measured memory_bytes: 80256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MODk = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};
#define P pair<LL,LL>
#define I vector<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
#define ENDL cout<<endl
#define FOREACH(x,a) for(auto& (x) : (a) )

std::vector<LL> dijkstra(int s,int N,vector<Edge> E){
    std::vector<LL> ans(N,LINF);
    std::vector<std::vector<Edge>> Edges(N);
    FOREACH(e,E){
        Edges.at(e.from).push_back(e);
    }
    priority_queue<P, std::vector<P>, greater<P>> que;
    ans.at(s)= 0;
    que.push(make_pair(0,s));
    while(!que.empty()){
        P p = que.top();que.pop();
        if(ans.at(p.second) < p.first)continue;
        for(int i = 0;i < Edges.at(p.second).size();i++){
                if(ans.at(p.second) + Edges.at(p.second).at(i).value < ans.at(Edges.at(p.second).at(i).to)){
                ans.at(Edges.at(p.second).at(i).to) = ans.at(p.second) + Edges.at(p.second).at(i).value;
                que.push(make_pair(ans.at(Edges.at(p.second).at(i).to),Edges.at(p.second).at(i).to));
            }
        }
    }
    return ans;
}
int main(){

    int N;cin >> N;
    vector<Edge> vec;
    for(int a = 0;a < N-1;a++){
        int b,c;cin >> b >> c;
        b--,c--;
        vec.push_back(Edge(b,c,1));
        vec.push_back(Edge(c,b,1));
    }
    vector<LL> ans = dijkstra(0, N, vec);
    vector<pair<LL,LL>> indexs;
    for(int a = 0;a < N;a++){
        indexs.push_back({ans.at(a),a});
    }
    sort(indexs.begin(),indexs.end());
    vector<LL> anses(N);
    vector<int> w;
    for(int a = 0;a < N;a++){
        int b;cin >> b;
        w.push_back(b);
    }
    sort(w.begin(),w.end());
    reverse(w.begin(),w.end());
    LL ans1= 0;
    for(int a = 0;a < N;a++){
        anses.at(indexs.at(a).second) = w.at(a);
        if(a != 0)ans1 += w.at(a);
    }
    cout<<ans1<<endl;
    for(int a = 0;a < N;a++){
        cout<<anses.at(a)<<" ";
    }
    cout<<endl;
}


Measured memory_bytes: 1916
package main

import (
	"fmt"
	"strings"
)

func main() {
	var N, cnt int
	fmt.Scan(&N)
	A := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&A[i])
	}
	A, cnt = selectionSort(A, N)
	fmt.Println(strings.Trim(fmt.Sprint(A), "[]"))
	fmt.Println(cnt)
}

func selectionSort(A []int, N int) ([]int, int) {
	var cnt int
	for i := 0; i < N; i++ {
		minj := i
		for j := i; j < N; j++ {
			if A[j] < A[minj] {
				minj = j
			}
		}
		if A[i] != A[minj] {
			A[i], A[minj] = A[minj], A[i]
			cnt++
		}
	}
	return A, cnt
}



Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
using graph = vector<vector<int>>;

vector<int> topo_sort(const graph& G) {
	int n = G.size();
	vector<int> used(n), idx; idx.reserve(n);
	function<void(int)> dfs = [&](int v) {
		used[v] = true;
		for (int w : G[v]) if (!used[w]) dfs(w);
		idx.push_back(v);
	};
	for (int i = n - 1; i >= 0; i--) {
		if (!used[i]) dfs(i);
	}
	reverse(idx.begin(), idx.end());
	return idx;
}

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, m;
	cin >> n >> m;
	graph G(n);
	for (int i = 0; i < m; i++) {
		int s, t;
		cin >> s >> t;
		G[s].push_back(t);
	}
	auto ts = topo_sort(G);
	for (int i = 0; i < n; i++) {
		printf("%d\n", ts[i]);
	}
	return 0;
}



Measured memory_bytes: 3616
#include<stdio.h>
int max(int x,int y, int z){
  int M = 10*x + y + z;
  if(10*y + x + z > M) M = 10*y + x + z;
  if(10*z + x + y > M) M = 10*z + x + y;
  return M;
}
int main(){
  int x,y,z;
  scanf("%d %d %d",&x,&y,&z);
  printf("%d",max(x,y,z));
  return 0;
}


Measured memory_bytes: 128