akhauriyash/Code-Regression huggingface dataset:
import java.util.*

class Scanner(`in`: java.io.InputStream) {
    private val reader = java.io.BufferedReader(java.io.InputStreamReader(`in`))
    private var tokenizer: StringTokenizer? = null

    fun next(): String {
        if (tokenizer?.hasMoreTokens() != true) {
            tokenizer = StringTokenizer(reader.readLine())
        }
        return tokenizer!!.nextToken()
    }

    fun nextLine(): String {
        return if (tokenizer?.hasMoreTokens() != true) {
            reader.readLine()
        } else tokenizer!!.nextToken("\n")
    }
}

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val K = sc.next().toLong()
        val A = IntArray(N) { sc.next().toInt() - 1 }
        val to = Array(N) { IntArray(60) }
        for (i in 0 until N) to[i][0] = A[i]
        repeat(59) { r ->
            repeat(N) { i ->
                to[i][r + 1] = to[to[i][r]][r]
            }
        }
        //to.forEach { println(it.joinToString(" "))}

        var k = K
        var ans = 0
        for (r in 59 downTo 0) {
            val l = 1L shl r
            if (k >= l) {
                ans = to[ans][r]
                k -= l
            }
        }
        pw.println(ans + 1)
    }
}


Measured memory_bytes: 104268
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

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

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

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

class UnionFind {
    private:
        vi par;    // x の親ノード
        vi rank;   // 木の高さ
        vi mem;    // メンバの数
        int sz;             // 集合の個数
    public:
        UnionFind(int n) :
            par(n, -1), rank(n, 0), mem(n, 1), sz(n) {
            REP(i,n) par[i] = i;
        }
    
    int size() { return sz; }

    // 集合の追加
    void makeset() {
        par.pb(par.size());
        rank.pb(0);
        mem.pb(1);
        sz++;
    }

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

    int member(int x){
        x = find(x);
        return mem[x];
    }

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

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

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

int n,m,p[100010],x,y;
signed main(){
    I(n); I(m);
    REP(i,n) { I(p[i]); p[i]--; }
    UnionFind uf = UnionFind(n);
    REP(i,m){
        I(x); I(y);
        x--; y--;
        uf.unite(x,y);
    }
    int ret = 0;
    REP(i,n){
        ret += uf.same(i,p[i]) ? 1 : 0;
    }
    cout << ret << endl;
}

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

#define EB emplace_back
#define int long long
#define F first
#define S second
#define N 500005
#define all(x) x.begin(),x.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)


using namespace std;


int32_t main()
{
    IOS;

    int tt=1;
	//cin >> tt;
	while (tt--)
	{
		int n; cin >> n;
		string s; cin >> s;
		if(s.size() > n) cout << s.substr(0,n ) <<"...";
		else cout << s;
	}
    return 0;
}


Measured memory_bytes: 3656
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

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

template <class T>
inline vector<T> make_v(const T &initvalue, intmax_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, intmax_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}} End

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

    size_t N; cin >> N;

    vector<intmax_t> t(N), a(N);
    for (size_t i = 0; i < N; ++i) {
        cin >> t[i] >> a[i];
    }

    const auto updiv = [&](intmax_t n, intmax_t d) { return (n + d - 1) / d; };
    intmax_t now_t = t[0], now_a = a[0];
    for (size_t i = 1; i < N; ++i) {
        intmax_t valid1 = updiv(now_t, t[i]);
        intmax_t valid2 = updiv(now_a, a[i]);
        intmax_t mul = max(valid1, valid2);
        now_t = t[i] * mul, now_a = a[i] * mul;
    }

    cout << now_t + now_a << "\n";

    return 0;
}


Measured memory_bytes: 256
import sys
f = sys.stdin


while True:
    t = int(f.readline())
    if t == 0:
        break
    n = int(f.readline())
    sf = (map(int, f.readline().split()) for _ in range(n))
    
    rest = t - sum(f - s for s, f in sf)
    print('OK' if rest <= 0 else rest)

Measured memory_bytes: 6724
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int Number = int.Parse(Console.ReadLine());
            if (Number<1200)
            {
                Console.WriteLine("ABC");
            }
            else
            {
                Console.WriteLine("ARC");
            }
        }  
    }
}

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

std::string answer;
std::vector<int> input;

void dfs(int i, std::vector<int> L, std::vector<int> R){
	int L_flag, R_flag;
	std::vector<int> Add_L, Add_R;

	if(answer.compare("YES")==0 || i > 9) return;

	std::copy(L.begin(), L.end(), std::back_inserter(Add_L));
	std::copy(R.begin(), R.end(), std::back_inserter(Add_R));

	Add_L.insert(Add_L.end(), input[i]);
	Add_R.insert(Add_R.end(), input[i]);
	i++;

	L_flag = R_flag = 0;

	if(Add_L.size()>1){
		for(unsigned int j=0; j<Add_L.size()-1; j++){
			if(Add_L[j]>Add_L[j+1]){
				L_flag = 1;
				break;
			}
		}
	}
	if(Add_R.size()>1){
		for(unsigned int j=0; j<Add_R.size()-1; j++){
			if(Add_R[j]>Add_R[j+1]){
				R_flag = 1;
				break;
			}
		}
	}
	
	if(L_flag>0 && R_flag>0) { return; }
	if(L_flag==0) {
		if(i==10){
			answer = "YES";
			return;
		}
		else{
			dfs(i, Add_L, R);
		}
	}
	else if(R_flag==0){
		if(i==10){
			answer = "YES";
			return;
		}
		else{
			dfs(i, L, Add_R);
		}
	}
}

int main(void){
	int n, number;
	std::cin >> n;

	for(int i=0;i<n;i++){
		input.clear();
		
		for(int j=0;j<10;j++){
			std::cin >> number;
			input.insert(input.end(), number);
		}
		std::vector<int> left, right;

		answer = "CHECK";
		
		dfs(0, left, right);
		if(answer.compare("CHECK")==0) answer="NO";
		std::cout << answer << std::endl;
	}
	return 0;
}



Measured memory_bytes: 3084
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,x;
    cin >> a >> b >> c >> x;
    int ans = 0;
    REP(i,a+1){
        REP(j,b+1){
            REP(k,c+1){
                if((i*500+j*100+k*50)==x){
                    ans++;
                }
            }
        }
    } 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        char[] c = sc.next().toCharArray();
        int[] map = new int[n+1];
        map[n] = n;
        for(int i=n-1; i>=0; i--) {
            if(c[i] == '0') {
                map[i] = i;
            } else {
                map[i] = map[i+1];
            }
        }
        List<Integer> path = new ArrayList<>();

        int pos = n;
        while(true) {
            if(pos <= m) {
                path.add(pos);
                break;
            }
            int npos = map[pos - m];
            if(npos == pos) {
                System.out.println(-1);
                return;
            }
            path.add(pos - npos);
            pos = npos;
        }

        int l = path.size();
        for(int i=l-1; i>=0; i--) {
            if(i < l-1) {
                System.out.print(" ");
            }
            System.out.print(path.get(i));
        }
        System.out.println();
    }


}


Measured memory_bytes: 41324
#include<algorithm>
#include<functional>
using namespace std;
#include<stdio.h>
int main(void)
{
	//ソート（並び替え）
	int N,a[100];
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &a[i]);
	}
	sort(a, a + N,greater<int>());//小さい順に並び変えられる
	int suma = 0, sumb = 0;
	
	for (int j = 0; j < N; j++) {
		if (j % 2 == 1) {
			sumb = sumb + a[j];
		}
		else
			suma = suma + a[j];
	}

	if (suma >= sumb) {
		printf("%d", suma - sumb);
	}
	else
		printf("%d", sumb - suma);

	return 0;

}

Measured memory_bytes: 888
import java.io.*;
import java.util.*;
public class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
		//Scanner reader=new Scanner(System.in);
		String s;
		
		boolean[] num=new boolean[1000000];
		for(int i=3;i<1000000;i+=2){
			if(num[i]==true)continue;
			for(int j=3*i;j<1000000;j+=i*2)
				num[j]=true;
		}
		for(int i=4;i<1000000;i+=2)num[i]=true;
		
		while((s=reader.readLine())!=null){
			int in=Integer.parseInt(s);
			int co=0;
			for(int i=2;i<=in;i++){
				if(num[i]!=true)co++;
			}
			System.out.println(co);
		}

	}
}

Measured memory_bytes: 22420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n)  for(int i=0;i<(n);++i)
#define ALL(x) (x).begin(),(x).end()
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  REP(i, N) {
    cin >> p.at(i);
  }
  sort(ALL(p));
  reverse(ALL(p));
  int sum = 0;
  REP(i, N) {
    if (i == 0) {
      sum += p.at(i) / 2;
    }
    else {
      sum += p.at(i);
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> P;
 
constexpr int INF = 1e9;
constexpr int MOD = 1e9+7;
 
int main() {
    ll x,k,d;
    cin >> x >> k >> d;
    ll num = abs(x)/d;
    if(k < num){
        if(x > 0) cout << abs(x-k*d) << endl;
        else cout << abs(x+k*d) << endl;
    }else{
        ll z = k-num;
        if(x > 0){
            if(z%2 == 0) cout << abs(x%d) << endl;
            else cout << abs(x%d-d) << endl;
        }else{
            if(z%2 == 0) cout << abs(x%d) << endl;
            else cout << abs(x%d+d) << endl;
        }
    }
	return 0;
}

Measured memory_bytes: 3624
// traP is kyopuro circle
// -> true

#include <stdio.h>
#include <algorithm>
using namespace std;

int dfs(int p[30],int cnt){
  // check
  {
    bool flag = true;
    int a;
    a = p[0];
    for(int i=0;i<9;i++)if(p[i]!=a){
      flag = false;
      break;
    }
    a = p[9];
    for(int i=9;i<12;i++)if(p[i]!=a){
      flag = false;
      break;
    }
    a = p[12];
    for(int i=12;i<15;i++)if(p[i]!=a){
      flag = false;
      break;
    }
    a = p[15];
    for(int i=15;i<18;i++)if(p[i]!=a){
      flag = false;
      break;
    }
    a = p[18];
    for(int i=18;i<21;i++)if(p[i]!=a){
      flag = false;
      break;
    }
    a = p[21];
    for(int i=21;i<30;i++)if(p[i]!=a){
      flag = false;
      break;
    }
    if(flag)return cnt;
  }
  if(cnt>=8)return 2521;
  int ans = 2521;
  // pat 1
  {
    int next[30];
    for(int i=0;i<30;i++)
      next[i]=p[i];
    swap(next[15],next[14]);
    swap(next[0],next[27]);
    swap(next[1],next[28]);
    swap(next[2],next[29]);
    swap(next[18],next[20]);
    ans = min(ans,dfs(next,cnt+1));
  }
  // pat 2
  {
    int next[30];
    for(int i=0;i<30;i++)
      next[i]=p[i];
    swap(next[17],next[12]);
    swap(next[6],next[21]);
    swap(next[7],next[22]);
    swap(next[8],next[23]);
    swap(next[9],next[11]);
    ans = min(ans,dfs(next,cnt+1));
  }
  // pat 3
  {
    int next[30];
    for(int i=0;i<30;i++)
      next[i]=p[i];
    swap(next[20],next[9]);
    swap(next[0],next[23]);
    swap(next[3],next[26]);
    swap(next[6],next[29]);
    swap(next[15],next[17]);
    ans = min(ans,dfs(next,cnt+1));
  }
  // pat 4
  {
    int next[30];
    for(int i=0;i<30;i++)
      next[i]=p[i];
    swap(next[11],next[18]);
    swap(next[2],next[21]);
    swap(next[5],next[24]);
    swap(next[8],next[27]);
    swap(next[12],next[14]);
    ans = min(ans,dfs(next,cnt+1));
  }
  return ans;
}

int main(){
  int n;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    int p[30];
    for(int j=0;j<30;j++){
      scanf("%d",&p[j]);
    }
    int ans = dfs(p,0);
    printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 1024
k = int(input())
n = []

def dfs(num, A):
  A.append(num)

  if(len(str(num)) == 10):
    return 0

  for i in range(-1, 2):
    s = num%10 + i
    if(s >= 0 and s <= 9):
      dfs(num * 10 + s, A)

  return 0

for i in range(1, 10):
  dfs(i, n)

n = sorted(n)

print(n[k - 1])


Measured memory_bytes: 20820
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>

#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,n) for(int i=0;i<(n); i++)

using namespace std;
typedef long long ll;
const int MAX_N = 100;
const int MAX_W = 100000;
static const int INF = 1<<29;

struct Item{
    int value,weight;
};
ll C[MAX_N+1][MAX_W+1]={0}; //mainの外に置かないとセグフォ

int main(){
cin.tie(0);
ios::sync_with_stdio(0); //この2行はより速度を向上させる
// 追加２, 以降 cin の入力元が 'input.txt' になる
//提出時に消す！！

int N,W;
cin >> N >> W;

Item items[MAX_N+1];


for(int i=1;i<=N;i++){
    cin >> items[i].weight >> items[i].value;
}

for(int i=1;i<=N;i++){
    for(int j=1;j<=W;j++){
        if(items[i].weight <= j){
            C[i][j]=max(C[i-1][j], C[i-1][j-items[i].weight]+items[i].value);
        }
        else{
            C[i][j]=C[i-1][j];
        }
    }
}


cout << C[N][W] << endl;

return 0;
}


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

int binpow(int a, int b) {
	int res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a;
		a = a * a;
		b = b >> 1;
	}
	return res;

}

int32_t main() {
	int x;
	cin >> x;
	int a, b;
	for (int i = 0; i < 150; ++i) {
		for (int j = -150; j < 150; ++j) {
			a = binpow(i, 5);
			b = binpow(j, 5);
			if (a - b == x) {
				cout << i << " " << j;
				return 0;
			}

		}

	}
}


Measured memory_bytes: 3600
n,k = map(int,input().split())
a_ls = list(map(int, input().split()))
a_ls = [0] + a_ls

visited_ls = [0] * (n+1)
tour_ls = []
now = 1
times = 1
while True:
    # 現在地についての処理
    tour_ls.append(now)
    visited_ls[now] += 1

    nex = a_ls[now]
    if visited_ls[nex]:
        first_ind = tour_ls.index(nex)
        before_loop = first_ind
        loop_ls = tour_ls[first_ind:times]
        break
    # 現在地を更新
    now = nex
    times += 1
if k - before_loop >= 0:
    ind = (k - before_loop) % len(loop_ls)
    print(loop_ls[ind])
else:
    print(tour_ls[k])

Measured memory_bytes: 32244
#include <iostream>
using namespace std;
int main(void){
    long int N;
    long int sum = 0;
  	scanf("%ld", &N);
	if(0<N && N<1000001){
	    for(long int i = 1; i < N+1; i++){
	        if(i%3!=0&&i%5!=0){
	            sum = sum+i;
	        }
	    }
	    printf("%ld", sum);
	}
}

Measured memory_bytes: 3812
using System;
using System.Collections.Generic;
using System.Linq;

class MainClass {

  public static void Main (string[] args) {
    var temp = Console.ReadLine().Split(' ').Select(int.Parse);
    var N = temp.ElementAt(0);
    var K = temp.ElementAt(1);
    var list = Console.ReadLine().Split(' ').Select(int.Parse);
    var c = 0;
    var i = K;
    var ans = 0;

    while(i < N){
        i += K - 1;
        c++;
    }

    ans = c + 1;
    Console.WriteLine(ans);
  }
}

Measured memory_bytes: 18144
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
int main(){
    string s;
    cin>>s;
    string s1;
    
    rep(i,s.size()){
        if(s[i]!='x'){s1+=s[i];}
    }
    string s2=s1;
    reverse(s1.begin(),s1.end());
    if(s2!=s1){
        cout<<-1<<endl;return 0;
    }
    int ans=0;
    int f=0;int b=s.size()-1;
    while(f<=b){
        if(s[f]!=s[b]){
            ans++;
            if(s[f]=='x'){
                f++;
            }else{
                b--;
            }
        }else{
            f++;b--;
        }
    }
    
    
    cout<<ans<<endl;
return 0;
}


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

const int N  = 1e6 + 10;

vector<int> v[N];
int visited[N];
map<pair<int ,int > ,int > mm;

int depth[N] = {0};

int dep(int i) {
	if(depth[i] > 0) return depth[i];
	
	depth[i] = 1;
	for(int j : v[i]) {
		depth[i] = max(depth[i] ,dep(j) + 1);
	}
	return depth[i];
}


int dfs(int i) {
	if(visited[i] == 1) return 1;
	if(visited[i] == 2) return 0;
	visited[i] = 1;
	for(auto j : v[i]) if(dfs(j)) return 1;
	visited[i] = 2;
	return 0;
}

int check(int n ) {
	for(int i = 1 ; i< n ;i ++ ){
		if(!visited[i] && dfs(i))  return 1;
	}
	return 0;
}

int main() {
	int n ; cin >> n;
	vector<int> match[n + 1];
	for(int i = 1 ; i <= n ; i ++ ) {
		for(int j = 1 ; j < n ; j ++) {
			int x ; cin >> x;
			match[i].push_back(x);
		}
	}
	int k = 1;
	for(int i = 1 ; i <= n ; i ++ ) {
		for(int j = i + 1 ;j <= n ;j ++ ) {
			mm[{i , j}] = k;
			mm[{j , i}] = k;
			k++;
		}
	}
	
	for(int i = 1 ; i <= n; i ++) {
		for(auto j = 1 ; j < (int)match[i].size() ; j ++ ){
			int a = mm[{i , match[i][j]}] , b = mm[{i , match[i][j - 1]}];
			//~ cout << a << " " << b << endl;
			v[b].push_back(a);
		}
	}
	//~ cout << endl;
	if(check(k)) {
		cout << -1;
		return 0;
	}
	
	memset(visited , 0 , sizeof visited);
	int ans = 0 ;
	for(int i = 1 ;i <= k ;i ++ ) {
		ans = max(ans , dep(i));
	}
	cout << ans;
	
	
}


Measured memory_bytes: 113536
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
//#define int   long long
#define ll   long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<61)
#define vi vector<int>
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define cd complex<double>
#define PI 4*atan(1)
#define mod %1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double

ll o[100001];

int main()
{
	FAST;
	ll n, m, i, j;
	cin >> n >> m;
	pair <ll, ll> p[n];
	fr(i,0,n)
		cin >> p[i].ss >> p[i].ff;
	map <ll, ll> mp;
	fr(i,0,m+2)
		mp[i] = 1;
	sort(p, p+n);
	ll ans = 0;
	for(i = n-1; i >= 0; i--)
	{
		if(p[i].ss <= m)
		{
			ll st = p[i].ss;
//			trace1(st);
			if(mp.find(st) != mp.end())
			{
				ans += p[i].ff;
				mp.erase(st);
			}
			else
			{
				ll k = mp.upper_bound(st) -> ff;
				if(k <= m)
				{
					ans += p[i].ff;
					mp.erase(k);
				}
			}
		}
//		trace1(ans);
	}
	cout << ans;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
const int INF=1e9+5;
const int N=2e5+5;
const int mod=998244353;

int n;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	vector<int> a(n);
	vector<int> cnt(N,0);
	vector<int> num;
	for(int i=0;i<n;++i){
		cin>>a[i];
		if(!cnt[a[i]]) num.push_back(a[i]);
		++cnt[a[i]];
	}
	ll ans=0;
	for(int x:num){
		int cntx=cnt[x];
		ll res=1ll*cntx*(cntx-1)/2;
		ans+=res;
	}
	for(int i=0;i<n;++i){
		int cur=cnt[a[i]]	;
		cout<<ans-(cur-1)<<endl;
	}
	return 0;
}


Measured memory_bytes: 4224
#include <iostream>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<iomanip>
using namespace std;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)

int retl(int K,int L){
    int tmp=0;
    while(pow(2,tmp) * L < K){
        tmp++;
    }
    return tmp;
}

struct A{
    string s;
    int p;
    int order;
};


int main(){
    int P,Q,R;
    cin  >> P>>Q>>R;
  

    
    int ans=min(P+Q,min(P+R,Q+R));
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
// 153 A

#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;

int main(){
    long long int n, k, tmp, sum;
    vector<long long int> h;
    cin >> n >> k;
    for(int i=0; i<n; i++){
        cin >> tmp;
        h.push_back(tmp);
    }
    if(n <= k){
        cout << 0 << endl;
        return 0;
    }
    sort(h.begin(), h.end(), greater<int>());
    auto s = h.begin();
    s += k;
    sum = accumulate(s, h.end(), 0ll);
    cout << sum << endl;
    return 0;
}


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

const int MOD = 1000000007;

int main() {
    string s;
    cin >> s;
    int t;
    t = s.size();
    if (s.at(t-1) == 's') {
        cout << s << "es" << endl;
    }
    else {
        cout << s << "s" << endl;
    }
    return 0;
}

Measured memory_bytes: 3596
import java.util.*;

public class Main {

    static final long MOD = 1000000007L;

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        long result = Math.abs(n - m) <= 1 ? factorial(n) * factorial(m) % MOD : 0;
        if ((n + m) % 2 == 0) {
            result *= 2;
            result %= MOD;
        }

        // 出力
        System.out.println(result);
    }

    public static long factorial(long n) {
        long x = 1;
        for (long i = 2; i <= n; i++) {
            x *= i;
            x %= MOD;
        }
        return x;
    }
}


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

int main()
{
    int w,h,n;
    cin >> w >> h >> n;
    int x,y,sx = 0,sy = 0,lx = w,ly = h,a;
    for(int i = 0; i < n; i++){
        cin >> x >> y >> a;
        if(a == 1) sx = max(sx,x);
        if(a == 2) lx = min(lx,x);
        if(a == 3) sy = max(sy,y);
        if(a == 4) ly = min(ly,y);
    }

    cout << (lx - sx < 0 || ly - sy < 0 ? 0 : (lx - sx) * (ly - sy)) << endl;
    
    return 0;
}

Measured memory_bytes: 256
n = int(input())
N = str(n)

if n <= 9:
    print(n)
    exit()
ans = "9"*(len(N)-1)
for i in (9, 8, 7, 6, 5, 4, 3, 2, 1):
    if int(str(i)+ans) <= n:
        print(i+9*(len(N)-1))
        exit()
print(9*(len(N)-1))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const auto INF = (ll)1e9;
using v = vector<int>;
int n,a,b;
int f(int i){
          	if(i==0) return 0;
          	auto sum = f(i/10)+i%10;
        	return sum;
        }

int main(){
	cin >> n >> a >> b;	
	
	auto sum=0;
	for (int i = 0; i <= n; i++)
	{  

      	auto num = f(i);
      	
		if(a<=num&&num<=b){
			sum += i;
		}
	}
	
	cout << sum;
}


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

using lint = long long;

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

  vector<lint> a(n);
  for (auto &i : a) cin >> i;

  lint cnt = 0, sum = 0;
  for (int i = 0; i < n; ++i) {
    sum += a[i];
    if (i & 1 && sum <= 0) {
      cnt += abs(sum) + 1;
      sum = 1;
    }
    if (!(i & 1) && sum >= 0) {
      cnt += sum + 1;
      sum = -1;
    }
  }

  lint ans = cnt;
  cnt = 0, sum = 0;
  for (int i = 0; i < n; ++i) {
    sum += a[i];
    if (!(i & 1) && sum <= 0) {
      cnt += abs(sum) + 1;
      sum = 1;
    }
    if (i & 1 && sum >= 0) {
      cnt += sum + 1;
      sum = -1;
    }
  }

  ans = min(ans, cnt);

  cout << ans << endl;
}


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

int main(){
  ll n, m;
  cin >> n >> m;

  priority_queue<ll> a;
  ll goods = 0;
  for(int i = 0; i < n; i++){
    cin >> goods;
    a.push(goods);
  }

  ll discount = 0;
  for(int i = 0; i < m; i++){
    discount = a.top(); a.pop();
    discount /= 2;
    a.push(discount);
  }

  ll ans = 0;
  for(int i = 0; i < n; i++){
    ans += a.top();
    a.pop();
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1400
/*g++ file.cpp -o file.out*/
/*./file.out*/

#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define LL long long
#define Mod 1000000007
#define L_Mod 17100000013

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))

char f[105][105],s[105][105];

int main()
{
    int n,m,cnt=1;
    scanf("%d%d",&n,&m);
    rep(i,n)scanf("%s",f[i]);
    rep(i,m)scanf("%s",s[i]);
    rep(i,n)rep(j,n)
    {

        if(f[i][j]==s[0][0])
        {
            cnt=0;
            rep(x,m)rep(y,m)if(f[i+x][j+y]!=s[x][y])
            {
                cnt=1;
                break;
            }
        }
        if(cnt==0)
        {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 256
import           Control.Monad                  ( forM_ )
import           Data.List                      ( sort )

main = do
    l  <- read <$> getLine
    xs <- map (read :: String -> Int) . words <$> getLine
    let
        s = sort xs
        (m1, m2) = (s !! (l `div` 2), s !! (l `div` 2 - 1))
    forM_ xs $ \val ->
        if val < m1 then print m1 else print m2

Measured memory_bytes: 106876
//Author:xht37
#include <bits/stdc++.h>

#define ui unsigned int
#define ll long long
#define ul unsigned ll
#define ld long double

#define pi pair <int, int>
#define fi first
#define se second
#define mp make_pair

#define ls (p << 1)
#define rs (ls | 1)
#define md ((t[p].l + t[p].r) >> 1)

#define vi vector <int>
#define pb push_back
#define pq priority_queue

#define dbg(x) cerr << #x" = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)

#define fl(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)

using namespace std;

namespace io {
	const int SI = 1 << 21 | 1;
	char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100];
	int f, t;
	#define gc() (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin), IS == IT ? EOF : *IS++) : *IS++)
	inline void flush() {
		fwrite(OB, 1, OS - OB, stdout), OS = OB;
	}
	inline void pc(char x) {
		*OS++ = x;
		if (OS == OT) flush();
	}

	template <class I>
	inline void rd(I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + (c & 15), c = gc());
		x *= f;
	}
	template <class I>
	inline void rd(I &x, I &y) {
		rd(x), rd(y);
	}
	template <class I>
	inline void rd(I &x, I &y, I &z) {
		rd(x), rd(y), rd(z);
	}
	template <class I>
	inline void rda(I *a, int n) {
		for (int i = 1; i <= n; i++) rd(a[i]);
	}
	inline void rdc(char &c) {
		for (c = gc(); c < 33 || c > 126; c = gc());
	}
	inline void rds(char *s, int &n) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (n = 0; c >= 33 && c <= 126; s[++n] = c, c = gc());
		s[n+1] = '\0';
	}
	inline void rds(string &s) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (s.clear(); c >= 33 && c <= 126; s.pb(c), c = gc());
	}

	template <class I>
	inline void print(I x, char k = '\n') {
		if (!x) pc('0');
		if (x < 0) pc('-'), x = -x;
		while (x) ch[++t] = x % 10 + '0', x /= 10;
		while (t) pc(ch[t--]);
		pc(k);
	}
	template <class I>
	inline void print(I x, I y) {
		print(x, ' '), print(y);
	}
	template <class I>
	inline void print(I x, I y, I z) {
		print(x, ' '), print(y, ' '), print(z);
	}
	template <class I>
	inline void printa(I *a, int n) {
		for (int i = 1; i <= n; i++) print(a[i], " \n"[i==n]);
	}
	inline void printc(char c) {
		pc(c);
	}
	inline void prints(char *s, int n) {
		for (int i = 1; i <= n; i++) pc(s[i]);
		pc('\n');
	}
	inline void prints(string s) {
		int n = s.length();
		while (t < n) pc(s[t++]);
		pc('\n'), t = 0;
	}
	struct Flush {
		~Flush() {
			flush();
		}
	} flusher;
}
using io::rd;
using io::rda;
using io::rdc;
using io::rds;
using io::print;
using io::printa;
using io::printc;
using io::prints;

int main() {
	ll n, a, b;
	rd(n, a, b);
	if ((a ^ b) & 1) print(min((a + b - 1) >> 1, (n - a + n - b + 1) >> 1));
	else print((b - a) >> 1); 
	return 0;
}

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,X,Y=MI()
    X-=1
    Y-=1
    
    ##########################################
    import heapq
    class Dijkstra():
        """
        ・有向 / 無向は問わない(無向の場合は，逆向きの辺もたす)
        ・負のコストがない場合のみ
        ・計算量はO(E log|V|)　
        ・heapを使うことで頂点を走査する必要がなくなる（代わりに，距離更新したものは確定でなくともqueに入れておく）
        """
        
        #最短のpathをたす
        
        
        class Edge():
            #重み付き有向辺
            
            def __init__(self, _to, _cost):
                self.to =_to
                self.cost = _cost
        
        def __init__(self, V):
            #引数Vは頂点数
            self.G = [[] for _ in range(V)] #隣接リストG[u][i]が頂点uのi番目の辺
            self. _E = 0 #辺の数
            self._V = V #頂点数
        
        #proparty - 辺の数
        def E(self):
            return self._E
        
        #proparty - 頂点数
        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 add2(self, _from, _to, _cost):
            #2頂点と辺のコスト（無向）を追加
            self.G[_from].append(self.Edge(_to, _cost))
            self.G[_to].append(self.Edge(_from, _cost))
            self._E +=1
            
        def shortest_path(self,s):
            #始点sから頂点iまでの最短経路長のリストを返す
            
            que = [] #priority queue
            d = [float("inf")] * self.V()
            prev = [None]*self.V() #prev[j]は，sからjへ最短経路で行くときのjの一つ前の場所
            d[s] = 0
            heapq.heappush(que,(0,s)) #始点の距離と頂点番号をヒープに追加
            
            while len(que)!=0:
                #キューに格納されてある中で一番コストが小さい頂点を取り出す
                cost,v = heapq.heappop(que)
                
                #キューに格納された最短経路長候補がdの距離よりも大きい場合に処理をスキップ
                if d[v] < cost:
                    continue
                    
                #頂点vに隣接する各頂点iに対して，vを経由した場合の距離を計算して，これがd[i]よりも小さい場合に更新
                for i in range(len(self.G[v])):
                    e = self.G[v][i] #vのi個目の隣接辺
                    if d[e.to] > d[v] + e.cost:
                        d[e.to] = d[v] + e.cost #更新
                        prev[e.to] = v
                        heapq.heappush(que,(d[e.to],e.to)) #queに新たな最短経路長候補を追加
            
                        
            return d
    ########################
        
    djk = Dijkstra(N)        
    for i in range(N-1):
        djk.add2(i,i+1,1)
    djk.add2(X,Y,1)
    
    ans=[0]*(N+1)
    
    for i in range(N):
        d=djk.shortest_path(i)
        for j in range(N):
            ans[d[j]]+=1
            
    for i in range(N-1):
        print(ans[i+1]//2)
        
    

main()


Measured memory_bytes: 89180
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
/*#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")*/

using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
#define mp make_pair
#define what_is(x) cerr << #x << " is " << x << endl;

typedef tree<
        int,
        null_type,
        less<int>,
        rb_tree_tag,
        tree_order_statistics_node_update>
        ordered_set;


const int p = 1e9 + 7;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}

vector<int> Z(vector<int> s)
{
    int n = s.size();
    vector<int> z(n);
    int L = 0, R = 0;
    for (int i = 1; i < n; i++) {
        if (i > R) {
            L = R = i;
            while (R < n && s[R-L] == s[R]) R++;
            z[i] = R-L; R--;
        } else {
            int k = i-L;
            if (z[k] < R-i+1) z[i] = z[k];
            else {
                L = i;
                while (R < n && s[R-L] == s[R]) R++;
                z[i] = R-L; R--;
            }
        }
    }
    return z;
}

mt19937 rnd(time(0));
/*
struct Line {
    mutable ll k, m, p;
    bool operator<(const Line& o) const { return k < o.k; }
    bool operator<(ll x) const { return p < x; }
};

struct CHT : multiset<Line, less<>> {
    // (for doubles, use inf = 1/.0, div(a,b) = a/b)
    const ll inf = LLONG_MAX;
    ll div(ll a, ll b) { // floored division
        return a / b - ((a ^ b) < 0 && a % b); }
    bool isect(iterator x, iterator y) {
        if (y == end()) { x->p = inf; return false; }
        if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
        else x->p = div(y->m - x->m, x->k - y->k);
        return x->p >= y->p;
    }
    void add(ll k, ll m) {
        auto z = insert({k, m, 0}), y = z++, x = y;
        while (isect(y, z)) z = erase(z);
        if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
        while ((y = x) != begin() && (--x)->p >= y->p)
            isect(x, erase(y));
    }
    ll query(ll x) {
        assert(!empty());
        auto l = *lower_bound(x);
        return l.k * x + l.m;
    }
};
*/

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

    int n;
    cin>>n;
    vector<int> b(n-1);
    for (int i = 0; i<n-1; i++) cin>>b[i];
    if (n==2) {cout<<2*b[0]; return 0;}
    int total = b[0] + b[n-2];
    for (int i = 0; i<n-2; i++) total+=min(b[i], b[i+1]);
    cout<<total;

}

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

const int N = 1000010;

char s[N], tmp[N];

int ct[3], fucked[N];

vector<int> pos, pos2;

int main() {
    int n, tp = 0; scanf("%s", tmp + 1); n = strlen(tmp + 1);
    for (int i = 1; i <= n; i++) 
        if (tp == 0 || s[tp] != tmp[i]) s[++tp] = tmp[i];
    n = tp;
    for (int i = 1; i <= n; i++) ct[s[i] - 'A']++;
    int mn = 0, mx = 0;
    for (int i = 1; i < 3; i++) {
        if (ct[mn] > ct[i]) mn = i;
        if (ct[mx] <= ct[i]) mx = i;
    }
    int diff = ct[mx] - (n - ct[mx] - ct[mn]);
    for (int i = 0, j = 0; i < n; i = j) if (i == 0 || s[i] == 'A' + mn) {
        j = i + 1;
        while (j <= n && s[j] != 'A' + mn) j++;
        if (j == i + 1) continue;
        if (j == i + 2 && j <= n && i) {
            if (s[i + 1] == 'A' + mx) pos2.push_back(i + 1);
        } else {
            if (s[i + 1] == 'A' + mx) pos.push_back(i + 1);
            if (j - 1 != i + 1 && s[j - 1] == 'A' + mx) pos.push_back(j - 1);
        }
    }
    int pos1 = 0, pos3 = 0;
    for (int i = 1; i <= diff; i++) {
        if (pos1 < pos.size()) fucked[pos[pos1]] = 1, pos1++;
        else fucked[pos2[pos3]] = fucked[pos2[pos3] - 1] = 1, pos3++;
    }
    tp = ct[0] = ct[1] = ct[2] = 0;
    for (int i = 1; i <= n; i++) if (!fucked[i]) 
        tmp[++tp] = s[i], ct[s[i] - 'A']++;
    diff = ct[mx] - ct[mn];
    ct[0] = ct[1] = ct[2] = 0;
    for (int i = 1; i <= tp; i++) {
        if (diff && i < tp && tmp[i] != mn + 'A' && tmp[i + 1] != mn + 'A' && tmp[i] != tmp[i + 1] && (i + 2 > tp || tmp[i + 2] != mn + 'A'))
            diff--, i++;
        else putchar(tmp[i]), ct[tmp[i] - 'A']++;
    }
    return 0;
}

Measured memory_bytes: 7412
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int check=s.length()/2;
    int c=s.length()-1;
    int ans=0;
    for(int i=0;i<check;i++)
    {
        if(s[i]!=s[c])
            ans++;

            c--;



    }
    cout<<ans<<endl;

    return 0;

}




Measured memory_bytes: 256
import sys
n, m = [int(i) for i in sys.stdin.readline().split()]
ls = []
ans = ["x"] * (n)
for i in range(m):
    s, c = [int(i) for i in sys.stdin.readline().split()]
    s -= 1
    if ans[s] != "x" and ans[s] != str(c):
        ans = -1
        break
    else:
        ans[s] = str(c)
if ans == -1 or (ans[0] == "0" and n > 1):
    print(-1)
else:
    if ans[0] == "x":
        if n == 1:
            ans[0] = "0"
        else:
            ans[0] = "1"
    ans = "".join(ans)
    ans = ans.replace("x", "0")
    print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FI first
#define SE second
#define endl "\n"
#define ciosup cin.tie(0);ios::sync_with_stdio(false);
#define eb emplace_back
constexpr ll INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;

int main()
{
    ciosup;
    int n,k;
    cin >> n >> k;
    if (k == 1)
        cout << 0 << endl;
        else
        {
            cout << n - k << endl;
        }
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()

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

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using DoP = pair<double, double>;
using edge = struct { int to; double cost;}; // edge x = {to, cost}

const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1<<29;
const ll INF64 = 1ll << 45;
const int mod = 1000000007;

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};
// h(n, r) = c(n+r-1, r)
struct combination
{
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1)
  {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i)
      fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i)
      ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k)
  {
    if (k < 0 || k > n)
      return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

int n;
vector<P> x;
vector<vector<ll>> dp;

ll rec(int l = 0, int r = n) {
  if(r-l <= 1) dp[l][r] = 0;
  if(r-l==2) dp[l][r] = x[l].first*x[l].second*x[l+1].second;
  if(dp[l][r] != INF64) return dp[l][r];
  for(int mid = l+1; mid < r; ++mid) chmin(dp[l][r], rec(l, mid)+rec(mid, r)+x[l].first*x[mid].first*x[r-1].second);
  return dp[l][r];
}

int main(){
  cin >> n;
  x.resize(n);
  dp.assign(n+1, vector<ll>(n+1, INF64));
  rep(i, n) cin >> x[i].first >> x[i].second;
  cout << rec() << endl;
}


Measured memory_bytes: 3184
#include <stdio.h>

int main(){
	int A, B, C;
	scanf("%d %d %d", &A, &B, &C);
	
	if (A==B&&B!=C){
		printf("Yes");
	}else if (A==C&&C!=B){
		printf("Yes");
	}
	else if (B==C&&C!=A){
		printf("Yes");
	}else{
		printf("No");
	}
	
	
	
	
	return 0;
}

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

using ll    = long long;
using ull   = unsigned long long;
using veci  = vector<int>;
using vecll = vector<ll>;
#define EPS (1e-7)
#define INF (1e9)
#define PI  (acos(-1))
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define REP(i,n) for(int i= 0;i<(int)(n);++i)
#define pb push_back

veci enum_div(int n){
	veci ret;
	ret.pb(1);
	for(int i=1;i*i<n;i++){
		if(n%i==0){
			ret.pb(i);
			if(i != n/i){ret.pb(n/i);}
		}
	}
	ret.pb(n);
	return ret;
}
int gcb(int a,int b){return ((b == 0)? a : gcb(b,a%b));}
int gcd(int a,int b){return (a*b) / gcb(a,b);}

int main(){
    ll x,a,b;
    cin >> x >> a >> b;
    ll after = b-a;
    if(after > x){
        cout << "dangerous" << endl;
    }else if(after > 0){
        cout << "safe" << endl;
    }else{
        cout << "delicious" << endl;
    }
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#define REP(i, x, n) for(int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
typedef long long int lli;
typedef pair<lli, lli> Pii;
const int INF = 193499;
int main(){
    unsigned long long int ans;
    lli N;
    cin >> N;
    if(N == 1){
        cout << 0 <<endl;
    }
    else{
        ans = N * (N-1) /2;
        cout << ans<<endl;
        return 0;
    }

    
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        int coinNumber = 0;
        
        for(int i = 0; i < 2; i++){
            if(a > b){
                coinNumber += a;
                a--;
            }else{
                coinNumber += b;
                b--;
            }
        }
        
        System.out.println(coinNumber);
        
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

int main() {
	vector<int> v(3);
	for (int i = 0; i < 3; i++) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	
	cout << 10 * v[2] + v[1] + v[0] << endl;
}

Measured memory_bytes: 3640
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
n = I()
ans = 0
for i in range(n):
    a,b = readInts()
    if a == b:
        ans += 1
    else:
        ans = 0
    if ans >= 3:
        break
print('Yes' if ans >= 3 else 'No')


Measured memory_bytes: 10356