akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define rrep(i, a, b) for (int i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using tl = tuple<ll, ll, ll>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n, ma, mb;
    cin>>n>>ma>>mb;
    vvl abc(n, vl(3)); cin>>abc;

    vector<vvl> dp(n + 1, vvl(410, vl(410, LINF)));
    dp[0][0][0] = 0;
    rep(i, n) {
        ll a = abc[i][0];
        ll b = abc[i][1];
        ll c = abc[i][2];
        rep(j, 410) rep(k, 410) {
            chmin(dp[i + 1][j][k], dp[i][j][k]);
            if (j + a < 410 && k + b < 410)
                chmin(dp[i + 1][j + a][k + b], dp[i][j][k] + c);
        }
    }

    ll ans = LINF;
    int i = ma, j = mb;
    while (i < 410 && j < 410) {
        chmin(ans, dp[n][i][j]);
        i += ma;
        j += mb;
    }
    if (ans == LINF) cout<<-1<<endl;
    else cout<<ans<<endl;
}

Measured memory_bytes: 56064
#include <iostream>
using namespace std;
typedef long long ll;
int main(void) {
  ll x, y;
  cin >> x >> y;
  int ans = 0;
  for (ll i = y / x; i > 0; i /= 2) {
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
As = [int(i) for i in input().split()]
Bs = [int(i) for i in input().split()]
ABs = [a - b for a, b in zip(As, Bs)]
if sum(As) < sum(Bs):
    print(-1)
    exit()
mABs = [ab for ab in ABs if ab < 0]
ans, t = len(mABs), sum(mABs)
for ab in sorted(ABs, reverse=True):
    if t >= 0:
        break
    ans += 1
    t += ab
print(ans)

Measured memory_bytes: 19292
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
const int mod = 1000000007;
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")


P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}


int gcd(int a,int b){
  if(a%b)return gcd(b,a%b);
  else return b;
}
int a[30];
int main(){
  int n,m;cin>>n>>m;
  
  for(int i = 0; n > i; i++){
    int k;cin>>k;
    for(int j = 0; k > j; j++){
      int t;cin>>t;
      a[t-1]++;
    }
  }
  int z = 0;
  for(int i = 0; m > i; i++){
    if(n==a[i])z++;
  }
  cout << z << endl;
}


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

int main()
{
    int A, B;
    cin >> A >> B;

    int coin=0;

    for (int i = 0; i < 2; ++i){
        if (A < B){
            coin += B;
            --B;
        }else{
            coin += A;
            --A;
        }
    }

    cout << coin << endl;

    return 0;
}

Measured memory_bytes: 256
import numpy as np
import math


N, K = map(int, input().split())
ina = list(map(int, input().split()))

X = np.zeros(N, dtype=int)

for n in range(N):
    X[n] = ina[n]


D = np.zeros(N - K+1, dtype=int)

for i in range(N-K+1):
    if X[i] > 0:
        D[i] = X[i+K-1]
    elif X[i+K-1] < 0:
        D[i] = abs(X[i])
    else:
        D[i] = min(abs(X[i]), abs(X[i+K-1])) + X[i+K-1] - X[i]

# print(D)
        
print(min(D))


Measured memory_bytes: 23044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef pair<string , int> s_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}

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

    string s; cin >> s; 
    string cs = s;
    string temp; rep(i,cs.size()) temp += s[0];
    if(temp == s) { cout << 0 << endl; return 0; }
    
    int ans = 100000;
    rep(i,26) {
        int cnt = 0;
        while(true){
            string t;
            rep(j,cs.size()-1) {
                if(cs[j] == i + 'a' or cs[j+1] == i + 'a') t += (i + 'a');
                else t += '#';
            }
            cnt++;
            string cmp; rep(j,cs.size()-1) cmp += (i + 'a');
            if(t == cmp) break;
            cs = t;
        }
        ans = min(ans, cnt);
        cs = s;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = [];
var reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
reader.on('line', (line) => {
    // ここで入力を処理する
    lines.push(line);
});
reader.on('close', () => {
    // ここで出力する
    var n = Number(lines[0]);
	var result = 
    lines[1].split(" ").map((x, index) => { return {order: Number(x), id: index + 1}})
  	.sort((a, b) => {return a.order - b.order}).map(x => x.id).join(" ");
    
    console.log(result);
    //for(var i =0; i<lines.length; i++){
    //  console.log(lines[i]);
    //}
});

Measured memory_bytes: 37392
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <string>
#include <tuple>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <random>
//#include "toollib.h"
//#include "puzzle.h"
#define INT_MAX 2147483647
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#pragma warning (disable:4018)
#pragma warning (disable:4244)

using namespace std;
typedef long long int lint;


//***** Main Program *****

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	Loop(i, N) cin >> A[i];
	int ret = 0;
	Loop(i, N - 1) {
		int x = i;
		for (int j = i + 1; j < N; j++) {
			if (A[j] < A[x]) x = j;
		}
		if (x != i) {
			ret++;
			int pass = A[x];
			A[x] = A[i];
			A[i] = pass;
		}
	}
	cout << A[0];
	for (int i = 1; i < N; i++) cout << " " << A[i];
	cout << endl << ret << endl;
	return 0;
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
int main() {
    string s;
    string t;
    cin>>s;
    cin>>t;
    int n= s.length();
    int ans=0;
    for(int i=0;i<n;i++) {
        if(s[i]!=t[i]) ans++;
    }
    cout<<ans<<'\n';
}

Measured memory_bytes: 3908
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<utility>
#include<random>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-2;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int a[1 << 17];
bool used[1 << 17];
vector<int> v;
int c[1 << 17];
int inv[1 << 17];
int main() {
	int n, m, q;
	cin >> n >> m >> q;
	rep(i, q) {
		cin >> a[i];
	}
	per(i, q) {
		if (used[a[i]])continue;
		used[a[i]] = true;
		v.push_back(a[i]);
	}
	rep1(i, m) {
		if (used[i])continue;
		v.push_back(i);
	}
	int ri = 0;
	rep(i, m - 1) {
		if (v[i] > v[i + 1]) {
			ri = i + 1;
		}
	}
	rep(i, m) {
		inv[v[i]] = i;
	}
	bool f = true;
	per(i, q) {
		int id = inv[a[i]];
		if (id >= ri)continue;
		if (id > 0) {
			if (c[id - 1] > c[id]) {
				c[id]++;
			}
		}
		else c[id]++;
	}
	rep(i, ri) {
		if (c[i] < n)f = false;
	}
	if (f)cout << "Yes" << endl;
	else cout << "No" << endl;
	//stop
	return 0;
}


Measured memory_bytes: 2040
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstring>
#include <set>
#include <utility>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <unordered_map>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#define ll long long
#define read(x) scanf("%d",&x);
#define readll(x) cin>>x;
#define FOR(x,a,b) for(int x=a;x<b;x++)
#define MP make_pair
#define PB push_back
#define pii pair<int,int>
#define readN(N,X) for(int i=0;i<N;i++) cin>>X[i];
#define pff pair<double,double>
using namespace std;

void no(){
	cout<<"NO"<<endl;
	exit(0);
}


void yes(){
	cout<<"YES"<<endl;
	exit(0);
}

int N;
int main(){
	ios_base::sync_with_stdio(false);
	cin>>N;
	int ret = 0;

	int last = -1;
	for (int i=0;i<N;i++) {
		int x;
		cin>>x;
		if (last == x){
			last = -1;
			ret++;
		} else last = x;
	}
	
	cout<<ret<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, x) for(ll i = 0; i < x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;

ll test[1234567], imos[12345678];
signed main() {
	ll n, ans = 0; cin >> n; map<ll, ll> m;
	vector<ll> high, v;
	ll cnt = 0;
	rep(i, n) {
		cin >> test[i];
		if (test[i] != 0) { cnt++; }
	}
	if (cnt == 0) { cout << 0 << endl; return 0; }
	rep(i, n) {
		cnt = 0;
		if (i != 0 && i != n - 1) {
			if (test[i - 1] != test[i] && test[i] != test[i + 1]) {
				if (max(test[i - 1], max(test[i], test[i + 1])) == test[i]) {
					high.push_back(test[i]); v.push_back(test[i]); cnt++;
				}
				else if (min(test[i - 1], min(test[i], test[i + 1])) == test[i]) {
					high.push_back(test[i]); v.push_back(test[i]); cnt++;
				}
			}
		}
		else {
			high.push_back(test[i]); v.push_back(test[i]); cnt++;
		}
		if (cnt == 0) {//選ばれてない
			test[i] = test[i - 1];
		}
	}
	sort(all(v)); n = high.size();
	ll z = 1;
	rep(i, n) {
		if (m[v[i]] == 0) {
			m[v[i]] = z; z += 2;
		}
	}
	rep(i, n) {
		high[i] = m[high[i]];
		//cout << high[i] << ' ';
	}
	//cout << endl;
	rep(i, n) {
		if (i != 0 && i != n - 1) {
			if (high[i - 1] > high[i] && high[i] < high[i + 1]) {
				imos[high[i]] += 2; imos[high[i - 1]]--; imos[high[i + 1]]--;
			}
		}
	}
	rep(i, 1000000) {
		if (i != 0) { imos[i] += imos[i - 1]; ans = max(ans, (imos[i] / 2) + 1); }
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 16656
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using str = string;
using ll = long long;
using vi = vector<int>;
using vii = vector<vi>;

int main() {
    str S;
    cin >> S;
    if(S[2] == S[3] && S[4] == S[5]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

#define task "E" // ABC134
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define pb push_back
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;

typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;

// Limit

// Struct

// Variables
int n,a[100005];
multiset<int> s;
// Function

int main()
{
	//freopen(task".in","r",stdin);
	//freopen(task".out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	cin >> n;
	rep(i,1,n) cin >> a[i];
	rep(i,1,n)
	{
	    multiset<int>::iterator it=s.lower_bound(a[i]);
	    if (it==s.begin()) s.insert(a[i]);
	    else
        {
            it--;
            s.erase(it);
            s.insert(a[i]);
        }
	}
	cout << s.size();
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> A(n);
  for (int i = 0; i < n; i++){
    cin >> A[i];
  }
  vector<int> C(10001, 0);
  for (int i = 0; i < n; i++){
    C[A[i]]++;
  }
  int v = 0;
  for (int i = 0; i < n; i++){
    while (C[v] == 0){
      v++;
    }
    cout << v;
    C[v]--;
    if (i < n - 1){
      cout << ' ';
    }
  }
  cout << endl;
}


Measured memory_bytes: 10640
import sys
cakes = 4
donuts = 7
amount = int(input())

if amount < 4 :
    print('No')
    sys.exit()

for i in range( int( amount / 4 ) +1 ):
    if amount == i * cakes:
        print('Yes')
        sys.exit()

    for x in range( int( amount / 7 ) +1 ):
        if amount - (i * cakes ) == x * donuts:
            print('Yes')
            sys.exit()

print('No')

Measured memory_bytes: 3064
N = int(input())
B = list(map(int, input().split()))
A_sum = 0
for i in range(N):
    if i == 0:
        A_sum += B[i]
    elif i == N-1:
        A_sum += B[i-1]
    else:
        A_sum += min(B[i], B[i-1])
print(A_sum)




Measured memory_bytes: 3060
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    int N; long K;
    scan(N, K);
    auto a = readln.split.to!(long[]).sort();

    bool check(long x) {
        long cnt;

        foreach (i ; 0 .. N) {
            if (a[i] > 0) {
                auto y = x / a[i];
                if (x < 0 && x % a[i] != 0) y--;
                auto j = a[i + 1 .. $].lowerBound(y + 1).length.to!int;
                cnt += j;
            }
            else if (a[i] < 0) {
                auto y = x / a[i];
                if (x < 0 && x % a[i] != 0) y++;
                auto j = a[i + 1 .. $].upperBound(y - 1).length.to!int;
                cnt += j;
            }
            else {
                assert(a[i] == 0);
                cnt += x >= 0 ? N - 1 - i : 0;
            }
        }

        return cnt >= K;
    }

    long ng = -infl, ok = infl;
    while (abs(ok - ng) > 1) {
        auto mid = (ok + ng) / 2;
        (check(mid) ? ok : ng) = mid;
    }

    writeln(ok);
}



void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


Measured memory_bytes: 11352
use proconio::input;
fn main() {
    input! {
        n: usize,
        t: u128
    }

    let mut res = t;
    for _ in 0..n - 1 {
        input! {
            t: u128
        }
        res = lcm(res, t);
    }

    println!("{}", res);
}

fn gcd(a: u128, b: u128) -> u128 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

fn lcm(a: u128, b: u128) -> u128 {
    a / gcd(a, b) * b
}


Measured memory_bytes: 2144
import collections
N, K, Q = map(int, input().split())
a = []
for _ in range(Q):
    a.append(int(input()))
    
a = collections.Counter(a)

for i in range(1, N + 1):
    if i in a.keys():
        if K - (Q - a[i]) > 0:
            print("Yes")
        else:
            print("No")
    else:
        if K - Q > 0:
            print("Yes")
        else:
            print("No")

Measured memory_bytes: 11900
use std::*;

fn main() {
    let _s = read::<String>();
    let _t = read::<String>();
    let s = _s.as_bytes();
    let t = _t.as_bytes();
    let l = t.len();
    let mut ans = i32::MAX;
    for i in 0..(s.len() - l + 1) {
        let mut c = 0;
        for j in 0..l {
            if s[i + j] != t[j] {
                c += 1;
            }
        }
        ans = cmp::min(c, ans);
    }
    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: str::FromStr>() -> T {
    let mut _in = String::new();
    io::stdin().read_line(&mut _in).ok();
    _in.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: str::FromStr>() -> Vec<T> {
    read::<String>().split(' ').map(|w| w.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 2164
def selectionSort(A):
    cnt = 0

    for i in range(len(A)):
        minj = i

        for j in range(i + 1, len(A)):
            if A[j] < A[minj]:
                minj = j

        if minj != i:
            A[i], A[minj] = A[minj], A[i]

            cnt += 1

    return A, cnt


N = int(input())
A = list(map(int, input().split()))

A_sorted, cnt = selectionSort(A)

print(*A_sorted)
print(cnt)



Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*

*/
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  string S,T; cin>>S>>T;
  ll ssz=S.size(), tsz=T.size(), ans=100000;
  for(ll i=0; i<=ssz-tsz; i++){
    ll tmp = 0;
    for(ll j=0; j<tsz; j++){
      if (S[i+j] != T[j])
        tmp++;
    }
    chmin(ans,tmp);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3632
from collections import*
import itertools

n, m = map(int, input().split())

posi = [[] for _ in range(n)]

for _ in range(m):
    ai, bi = map(int, input().split())
    posi[ai - 1] += [bi - 1]
    posi[bi-1] += [ai - 1]


# print(posi)

p = [0]*n
q = deque([0])
while q:
    v = q.popleft()
    for c in posi[v]:
        if p[c] < 1:
            p[c] = v + 1
            q.append(c)

# print(p)

if 0 in p:
    print('No')
else:
    print('Yes', *p[1:], sep='\n')


Measured memory_bytes: 39036
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		int[][] a = new int[n][m];
		for (int i = 0; i < n; i++) {
			sa = br.readLine().split(" ");
			for (int j = 0; j < m; j++) {
				a[i][j] = Integer.parseInt(sa[j]);
			}
		}
		br.close();

		int ans = 300;
		int[] idx = new int[n];
		Set<Integer> rem = new HashSet<>();
		for (int j = 0; j < m; j++) {
			Map<Integer, Integer> map = new HashMap<>();
			for (int i = 0; i < n; i++) {
				while (rem.contains(a[i][idx[i]])) {
					idx[i]++;
				}
				putCntMap(map, a[i][idx[i]]);
			}
			int max = 0;
			int num = 0;
			for (Integer i : map.keySet()) {
				int val = map.get(i);
				if (val > max) {
					max = val;
					num = i;
				}
			}
			ans = Math.min(ans, max);
			rem.add(num);
		}
		System.out.println(ans);
	}

	static void putCntMap(Map<Integer, Integer> map, Integer key) {
		if (map.containsKey(key)) {
			map.put(key, map.get(key) + 1);
		} else {
			map.put(key, 1);
		}
	}
}


Measured memory_bytes: 34192
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    int N, K; cin >> N >> K;
    string S; cin >> S;

    vector<int> nums;
    if (S[0] == '0') nums.push_back(0);
    for (int i = 0; i < N;){
        int j = i;
        while (j < N && S[i] == S[j]) { ++j; }
        nums.push_back(j - i);
        i = j;
    }
    if (S.back() == '0') nums.push_back(0);

    vector<int> sums(nums.size() + 1, 0);
    for (int i = 0; i < nums.size(); ++i) sums[i + 1] = sums[i] + nums[i];

    int res = 0;
    for (int left = 0; left < sums.size(); left += 2){
        int right = left + 2*K+1;
        if (right >= sums.size()) right = sums.size() - 1;
        res = max(res, sums[right] - sums[left]);

    }
    cout << res << endl;
}


Measured memory_bytes: 1272
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

vector<int> init(int size){
  vector<int> par(size,-1);
  return par;
}

int root(int x, vector<int>& par){
  if(par[x] < 0){
    return x;
  }else{
    return par[x] = root(par[x],par);
  }
}

bool same(int x, int y, vector<int>& par){
  return root(x, par) == root(y, par);
}

void unite(int x, int y, vector<int>& par){
  x = root(x, par), y = root(y, par);
  if(same(x,y, par))return;
  par[x] += par[y];
  par[y] = x;
}

int size(int x, vector<int>& par){
  return -par[root(x, par)];
}

int pow(int x, int n){
  if(n == 0)return 1;
  if(n % 2 == 0)return pow(x * x % MOD, n/2);
  else return x * pow(x, n-1) % MOD;
}

signed main(){
  string s;cin>>s;int n = s.length();
  int ans[110000];rep(i,110000)ans[i] = 0;
  int rind = -1, lind = -1, rcnt = 0, lcnt = 0;
  rep(i,n){
    if(s[i] == 'R'){
      if(rind >= 0){
        ans[rind] = rcnt - (rcnt/2) + lcnt / 2;
        ans[lind] = rcnt/2 + lcnt - lcnt/2;
        rind = -1;lind = -1;rcnt = 0;lcnt = 0;
      }
      rcnt++;
    }else{
      if(rind < 0){
        rind = i-1;lind = i;
        //cout << i << " " << rind << " " << lind << endl;
      }
      lcnt++;
    }
  }
  ans[rind] = rcnt - (rcnt/2) + lcnt / 2;
  ans[lind] = rcnt/2 + lcnt - lcnt/2;
  //cout << rind << " " << lind << endl;
  rep(i,n){
    cout << ans[i] << (i == n-1 ? '\n' : ' ');
  }
}


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

class Main{
 
    public static void main(String[] args)throws IOException{
 
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String str = br.readLine();
    String[] numList = str.split(" ");
    int a = Integer.parseInt(numList[0]);
    int b = Integer.parseInt(numList[1]);
    int c = Integer.parseInt(numList[2]);
    
    int count = 0;
     
    for(int i = a; i < (b+1); i++){
        if(c % i == 0){
        count++;
        }
    }
 
    System.out.println(count);
     
    }
}
 

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

int main(){
    int n;
    cin >> n;
    ll a[n], odd = 0, n4 = 0;
    rep(i, n) cin >> a[i];    
    rep(i, n){
        if (a[i] % 2 == 1) odd ++;
        else if (a[i] % 4 == 0) n4 ++;
    }

    if (n%2 == 0 && odd <= n4) cout << "Yes" << endl;
    else if (n%2 != 0 && odd <= n4 + 1) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(void)
{
    int m,d;
    cin >> m >> d;
    
    int ans = 0;
    for (int i = 4; i <= m; i++)
    {
        for (int j=22; j <= d;j++)
        {
            int d1 = j % 10;
            int d10 = j / 10;
            if (d1 >= 2 && d10 >= 2 && d1*d10 == i) ans++;
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 888
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <tuple>
#include <cmath>
#include <map>

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define F first
#define S second

#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 rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

constexpr ll MOD = 1000000007LL;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

template<typename T = ll> class UnionFind {
public:
	UnionFind( T n ) { rep( i, n ) { par[i] = i; siz[i] = 1; } }
	T find( T x ) { if ( x == par[x] ) return ( x ); else return( par[x] = find( par[x] ) ); }
	void unite( T x, T y ) { T xx = find( x ); T yy = find( y ); if ( xx == yy ) return;
		if ( siz[xx] <= siz[yy] ) swap( xx, yy ); par[yy] = xx; siz[xx] += siz[yy]; }
private:
	vector<T> par, siz;
};

template<typename T = ll> T power( T a, T b, T m = MOD ) {
	T res = 1;
	while ( b > 0 ) { if ( b & 1 ) res = res * a % m;
		a = a * a % m; b >>= 1; }
	return ( res );
}

/*
constexpr ll MAX = 500010;
ll fact[MAX];
ll inv[MAX];
ll inv_fact[MAX];

template<typename T> void initComb( T n, T m = MOD )
{
	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	inv[1] = 1;
	for ( int i = 2; i < n; i++ ) {
		fact[i] = ( fact[i - 1] * i ) % m;
		inv[i] = m - inv[m % i] * ( m / i ) % m;
		inv_fact[i] = inv_fact[i - 1] * inv[i] % m;
	}
}

template<typename T> T comb( T n, T r, T m = MOD )
{
	if ( n < r ) return ( 0 );
	if ( n < 0 || r < 0 ) return ( 0 );
	return ( fact[n] * ( inv_fact[r] * inv_fact[n - r] % m ) % m );
}
*/

void replace( string &s, string t, string r ) {
	string::size_type p = 0;
	while ( ( p = s.find( t, p ) ) != string::npos ) {
		s.replace( p, t.length(), r );
		p += r.length();
	}
}


int main()
{
	int N;
	string S;
	cin >> N >> S;

	vector<int> v( N );
	vector<int> vv( N + 1 );
	vv[0] = 0;
	rep( i, N )
	{
		v[i] = ( S[i] == 'E' ? 1 : 0 );
		vv[i + 1] = vv[i] + v[i];	//	東を向いている人数の累計
	}

	int cnt = 1 << 20;
	rep( i, N + 1 )
	{
		// i番目の人をリーダーにする時
		int tmp1 = i - vv[i];		//	i-1番目までの人は東向きにする
		int tmp2 = vv[N] - vv[i];	//	i+1番目以降の人は西向きにする

		chmin( cnt, tmp1 + tmp2 );
	}

	cout << cnt << endl;

	return ( 0 );
}


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

#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,lessl<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define int long long
#define double long double

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

#define ff first
#define ss second
#define mp make_pair

#define pb push_back
#define endl "\n"

#define f(i,l,r) for(int i=l;i<=r;i++)
#define rf(i,r,l) for(int i=r;i>=l;i--)

#define bp __builtin_popcountll
#define inf 1e18

const int N=2e3+5;
const int M=1e9+7;
void solve()
{
	int n;
	cin>>n;
	int last=0;
	int a[n];
	int ans=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		if(a[i]<last)
		{
			ans+=(last-a[i]);
			
		}
		last=max(last,a[i]);
	}
	cout<<ans<<endl;
}

signed main()
{
	FAST
    int t=1;
    // cin>>t;
    for(int tc=1;tc<=t;tc++)
    {
    	// cout<<"Case #"<<tc<<": ";
    	solve();
    }
}


Measured memory_bytes: 5200
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
const int mod=1e9+7;
int a[110];
long long dp[110][N];
long long ps[110][N];
int main(){
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    dp[0][0]=1;
    for(int i=1;i<=n;i++)
        for(int j=0;j<=k;j++){
            ps[i - 1][j] = dp[i - 1][j];
            if (j)
                ps[i - 1][j] = (ps[i - 1][j] + ps[i - 1][j - 1]) % mod;
            dp[i][j] = ps[i - 1][j];
            if (j - a[i] - 1 >= 0)
                dp[i][j] += mod - ps[i - 1][j - a[i] - 1];
            dp[i][j] %= mod;
        }

    cout<<dp[n][k];

    return 0;
}

Measured memory_bytes: 162048
package main

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

func main() {
	n := getInt()
	as := make([]int, n)
	for i := range as {
		as[i] = getInt() - (i + 1)
	}
	sort.Ints(as)

	b := as[n/2]
	ans := 0
	for _, a := range as {
		ans += abs(a - b)
	}

	fmt.Println(ans)
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
}

func getInt() int {
	i, err := strconv.Atoi(getString())
	if err != nil {
		panic(err)
	}
	return i
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}


Measured memory_bytes: 5120
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

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

int main(int argc, char **argv)
{
    int A, B, C;
    cin >> A >> B >> C;
    if (A >= B + C) cout << 0 << endl;
    else cout << C - (A - B) << endl;
    return 0;
}


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

int main(void){
	int n;
	int _t, t, _x, x, _y, y;
	cin >> n;
	t=x=y=0;
	for(int i=0; i<n; i++){
		_t = t, _x = x, _y = y;
		cin >> t >> x >> y;
		if(t-_t<abs(x+y-_x-_y) || ((abs(t-_t) % 2 == 1) ^ (abs(x+y-_x-_y)%2 == 1))){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#define N 5500
using namespace std;
typedef long long ll;
ll ct,cnt; 
ll fac[N],num[N],ans;
const int BASE[]={2,3,5,7,11,13,17,19,23};
ll gcd(ll a,ll b)
{
	return !b?a:gcd(b,a%b);
}
ll Quick_Mul(ll a,ll p,ll MOD)
{
    if(!p){
        return 0;
    }
    ll ans=Quick_Mul(a,p>>1,MOD);
    ans=(ans+ans)%MOD;
    if((p&1ll)==1ll){
        ans=ans+a%MOD%MOD;
    }
    return ans;
}
ll Quick_Pow(ll a,ll p,ll MOD)
{
    if(!p){
        return 1;
    }
    ll ans=Quick_Pow(a,p>>1,MOD);
    ans=Quick_Mul(ans,ans,MOD);
    if((p&1ll)==1ll){
        ans=a%MOD*ans%MOD;
    }
    return ans;
}
bool test(ll n,ll a,ll d){
    if(n==2){
        return 1;
    }
    if(n==a){
        return 0;
    }
    if(!(n&1)){
        return 0;
    }
    while(!(d&1ll)){
        d>>=1;
    }
    ll t=Quick_Pow(a,d,n);
    if(t==1){
        return 1;
    }
    while(d!=n-1ll && t!=n-1ll && t!=1ll){
        t=Quick_Mul(t,t,n);
        d<<=1;
    }
    return t==n-1ll;
}
bool Miller_Rabin(ll n){
    if(n==1 || n==3825123056546413051ll){
        return 0;
    }
    for(int i=0;i<9;++i){
        if(n==(ll)BASE[i]){
            return 1;
        }
        if(!test(n,(ll)BASE[i],n-1ll)){
            return 0;
        }
    }
    return 1;
}
ll pollard_rho(ll n,ll c){
    ll i=1,k=2;
    ll x=rand()%(n-1)+1;
    ll y=x;
    while(1){
        i++;
        x=(Quick_Mul(x,x,n)+c)%n;
        ll d=gcd((y-x+n)%n,n);
        if(1ll<d &&d<n){
            return d;
        }
        if(y==x){
            return n;
        }
        if(i==k){
            y=x;
            k<<=1;
        }
    }
}
void find(ll n,int c){
    if(n==1){
        return;
    }
    if(Miller_Rabin(n)){
        fac[ct++]=n;
        return;
    }
    ll p=n;
    ll k=c;
    while(p>=n){
        p=pollard_rho(p,c--);
    }
    find(p,k);
    find(n/p,k);
}
ll n;
int main(){
    srand(233);
    scanf("%lld",&n);
    if(n==1)
    {
    	printf("0\n");
    	return 0;
	}
    ct=0;
    find(n,120);
    sort(fac,fac+ct);
    num[0]=1;
    int k=1;
    for(int i=1;i<ct;++i)
        if(fac[i]==fac[i-1])
            ++num[k-1];
            else
			{
                num[k]=1;
                fac[k++]=fac[i];
            }
    cnt=k;
    for(int i=0;i<cnt;++i)
    {
    	int now=1,res=0;
		for(;num[i]-now>=0;num[i]-=now,now++,res++);
		ans+=res;
	} 
        
	printf("%lld",ans);
    return 0; 
}

Measured memory_bytes: 3244
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

m=0
c=0
for i in range(N):
    if B[i]>A[i]:
        m+=B[i]-A[i]
        c+=1

li=[]
for i in range(N):
    if B[i]<A[i]:
        li.append(A[i]-B[i])
li.sort(reverse=True)
for k in li:
    if m==0:
        break
    m-=min(m,k)
    c+=1
print(c if m==0 else -1)

Measured memory_bytes: 24108
import scala.annotation.tailrec
import scala.collection.{immutable, mutable}
object Main extends App {
  import scala.io.StdIn._
  val n = readInt
  val numbers = readLine.trim.split(' ').map(_.toInt)
  val indices = numbers.indices.groupBy(numbers).toArray.map(_._2.sorted.toArray)
  val longest = indices.map(_.length).foldLeft(n)(gcd)
  println(Some((2 to longest).filter(k ⇒ n % k == 0).filter{k ⇒
    val t = n / k
    indices.forall{index ⇒
      binarySearch(index, index.head + t) match {
        case Some(j) ⇒ (0 until index.length - j).forall(i ⇒ index(i) + t == index(i + j))
        case None ⇒ false
      }
    }
  }).filter(_.nonEmpty).getOrElse(List(1)).reduce(lcm))
  def lcm(a: Int, b: Int): Int = a / gcd(a, b) * b
  @tailrec def gcd(a: Int, b: Int): Int =  b match {
    case 0 ⇒ a
    case _ ⇒ gcd(b, a % b)
  }
  def binarySearch(array: Array[Int], target: Int): Option[Int] = {
    var left = 0
    var right = array.length
    while(left < right){
      val mid = (left + right) / 2
      if (array(mid) < target) left = mid + 1
      else right = mid
    }
    if (right < array.length && array(right) == target) Some(right)
    else None
  }
}


Measured memory_bytes: 214212
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = list()
for _ in range(n):
    a.append(list(map(int, input().split())))

ans = 0

for i in range(n):
    tmp = c
    for j in range(m):
        tmp = tmp + b[j] * a[i][j]
    if(tmp > 0):
        ans += 1
print(ans)


Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return map(int,input().split())
def LI(): return list(map(int,input().split()))

#引数nが素数かどうかを判定
def is_prime(n):
    for i in range(2, n + 1):
        if i * i > n:
            break
        if n % i == 0:
            return False
    return n != 1


## エラトステネス のふるい(n以下の素数全列挙)
# O(NloglogN)
def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [i for i in range(1, n+1) if is_prime[i-1]]
    return table,is_prime

def main():
    Q = INT()
    N = 10**5
    table,is_prime = sieve(N)
    is_like_number = [0]*(N+1)
    from itertools import accumulate
    for prime in table:
        if prime == 2:
            continue
        if is_prime[(prime+1)//2-1]:
            is_like_number[prime] = 1
    accum_like_number = list(accumulate(is_like_number))
    for _ in range(Q):
        l,r = MAP()
        print(accum_like_number[r]-accum_like_number[l-1])

    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 8780
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n);
	std::string s; cin >> s;

	for(int latte = 0; latte < 4; latte++) {
		std::string t(n, ' ');
		t[0] = (latte % 2 ? 'S' : 'W');
		t[1] = (latte / 2 ? 'S' : 'W');

		auto flip = [](char c) {
			if(c == 'S') return 'W';
			return 'S';
		};

		std::string u = t;
		for(int i = 1; i < n; i++) {
			if(s[i] == 'o') {
				if(t[i] == 'S') t[(i + 1) % n] = t[(i - 1 + n) % n];
				if(t[i] == 'W') t[(i + 1) % n] = flip(t[(i - 1 + n) % n]);
			} else {
				if(t[i] == 'W') t[(i + 1) % n] = t[(i - 1 + n) % n];
				if(t[i] == 'S') t[(i + 1) % n] = flip(t[(i - 1 + n) % n]);
			}
		}

		bool f = (t.substr(0, 2) == u.substr(0, 2));
		if(s[0] == 'o') {
			if(t[0] == 'S') f &= (t[n - 1] == t[1]);
			if(t[0] == 'W') f &= (t[n - 1] != t[1]);
		} else {
			if(t[0] == 'W') f &= (t[n - 1] == t[1]);
			if(t[0] == 'S') f &= (t[n - 1] != t[1]);	
		}
		if(!f) continue;
		
		cout << t << endl;
		return 0;
	}
	printf("-1\n");
	return 0;
}


Measured memory_bytes: 640
package main

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

func main() {
        var n int
        fmt.Scan(&n)
        sc := bufio.NewScanner(os.Stdin)
        sc.Split(bufio.ScanWords)
        oddNum := 0
        for i := 0; i < n; i++ {
                sc.Scan()
                a, _ := strconv.Atoi(sc.Text())
                if a%2 == 1 {
                        oddNum++
                }
        }
        if oddNum%2 == 0 {
                fmt.Println("YES")
        } else {
                fmt.Println("NO")
        }
}

Measured memory_bytes: 2176
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class C
{
	public static void Main() => (new Solver()).Solve();
}

public class Solver
{
	public void Solve()
	{
		int N = GetInt();
		string P = string.Concat(GetInts(N));
		string Q = string.Concat(GetInts(N));

		var list = new List<string>();
		int[] perm = Enumerable.Range(1, N).ToArray();
		do
		{
			list.Add(string.Concat(perm));

		} while (nextPermutation(ref perm));

		list.Sort();
		int a = -1;
		int b = -1;
		for(int i = 0; i < list.Count; i++)
		{
			if(list[i].Equals(P))
				a = i;
		
			if(list[i].Equals(Q))
				b = i;
		}
		WriteLine(Abs(a - b));
	}
	
	private static bool nextPermutation(ref int[] array)
	{
		int len = array.Length;
		int i = len - 2;
		while((i >= 0) && (array[i] > array[i + 1]))
			i--;
		if(i < 0)
			return false;

		int pivot = array[i];
		int j = i + 1;
		while((j < len - 1) && (array[j + 1] > pivot))
			j++;
		
		int tmp = array[i];
		array[i] = array[j];
		array[j] = tmp;
		
		Array.Reverse(array, i + 1, len - i - 1);

		return true;
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray();
	public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray();
	public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}

Measured memory_bytes: 19928
let split_string ?(pattern="") = Str.split @@ Str.regexp pattern
let (h, w, k) = Scanf.sscanf (read_line ()) "%d %d %d" @@ fun h w k -> (h, w, k)
let s = Array.init h @@ fun _ -> read_line () |> split_string |> Array.of_list

let row_count = Array.map (fun arr -> Array.fold_left (fun sum ch -> sum + if ch = "#" then 1 else 0) 0 arr) s

let fill_raw arr row v = 
  arr.(0) <- v + if s.(row).(0) = "#" then 1 else 0;
  for i = 1 to w - 1 do
    arr.(i) <- arr.(i - 1) + if s.(row).(i) = "#" then 1 else 0
  done;
  for i = w - 1 downto 0 do
    if arr.(i) = v then arr.(i) <- arr.(i + 1)
  done;
  arr.(w - 1)

let () =
  let ans = Array.init h @@ fun _ -> Array.make w 0 in
  let v = ref 0 in
  Array.iteri (fun i arr -> if row_count.(i) > 0 then v := fill_raw arr i !v) ans;
  for i = 1 to h - 1 do
    for j = 0 to w - 1 do
      if ans.(i).(j) = 0 then ans.(i).(j) <- ans.(i - 1).(j);
    done
  done;
  for i = h - 1 downto 0 do
    for j = 0 to w - 1 do
      if ans.(i).(j) = 0 then ans.(i).(j) <- ans.(i + 1).(j);
    done
  done;
  Array.iter (fun arr ->
    arr |> Array.map string_of_int |> Array.to_list |> String.concat " " |> print_endline
  ) ans

Measured memory_bytes: 7440
import sys
readline = sys.stdin.readline

N = int(readline())
S = readline().rstrip()

ans = 0
for i in range(1000):
  target = str(i).zfill(3)
  ind = 0
  tar_ind = 0
  while ind < N:
    if S[ind] == target[tar_ind]:
      tar_ind += 1
      if tar_ind == 3:
        ans += 1
        break
    ind += 1
  
print(ans)

Measured memory_bytes: 73632
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello{
    private static long gcd(long a,long b){
        return (a % b == 0) ? b : gcd(b,a % b);
    }
    public static void Main(){
        var N = int.Parse(Console.ReadLine());
        var nums = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        var ans = nums[0];
        
        for(var i = 1;i < N;i++){
            ans = gcd(ans,nums[i]);
        }
        
        Console.WriteLine(ans);
        
    }
}


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

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

constexpr int INF = 1e9;

int main() {
    vector<pll> v(4);
    ll l = 1;
    for(int i = 0; i < 4; ++i) {
        cin >> v[i].first;
        v[i].second = l;
        l *= 2;
    }
    ll N;
    cin >> N;
    N = 4 * N;
    for(auto it = v.begin(); it != v.end() - 1;) {
        if(it->first * ((it + 1)->second / it->second) <= (it + 1)->first) {
            v.erase(it + 1);
        } else {
            it++;
        }
    }
    ll res = 0;
    for(int i = v.size() - 1; i >= 0; --i) {
        res += N / v[i].second * v[i].first;
        N = N % v[i].second;
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n;
  while(cin>>n){
    if(n==0) break;
    int a[2*n+1],b;
    bool t = true;
    int tt = n,ht = n;
    for(int i=1;i<=2*n;i++) a[i] = 1;
    for(int i=0;i<n;i++){
      cin >> b;
      a[b] = 0;
    }
    while(tt!=0&&ht!=0){
      for(int i=1;i<=2*n;i++){
	if(t&&a[i]==0){
	  a[i] = 2;
	  tt--;
	  t = false;
	}
	else if(!t&&a[i]==1){
	  a[i] = 2;
	  ht--;
	  t = true;
	}
	if(tt==0||ht==0) break;
      }
      if(t) t = false;
      else t = true;
    }
    cout << ht << endl;
    cout << tt << endl;
  }
  return 0;
}

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

using namespace std;

#define ll long long

ll N;
vector <ll> a;

int main(){
  ll inp;
  ll q,c;
  ll result = 0;
  
  cin >> N;
  for(ll i =0;i<N;i++){
    cin >> inp;
    a.push_back(inp);
  }

  while(true){
    sort(a.begin(),a.end());
    if(a[N-1]<N) break;
    q = a[N-1]/N;//何回操作したか
    a[N-1]%=N;
    for(ll i = 0;i<N-1;i++){
      a[i] += q;
    }
    result += q;
  }
  
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
use std::io::{stdin, Read};
use std::str::FromStr;

// https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn main() {
    let mut a = read::<usize>();
    let mut b = read::<usize>();
    if a == 0 {
        println!("{}", f(b));
    } else {
        println!("{}", f(a - 1) ^ f(b));
    }

    fn f(x: usize) -> usize {
        if x % 2 == 0 {
            count_odd(x) % 2 ^ x
        } else {
            count_odd(x) % 2
        }
    }

    fn count_odd(n: usize) -> usize {
        if n % 2 == 0 {
            n / 2
        } else {
            n / 2 + 1
        }
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Itr(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define setp(n) fixed << setprecision(n)
#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>
#define All(a) (a.begin()),(a.end())
#define rAll(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vll l(n);
	ll sum=0;
	rep(i,n){
		cin>>l[i];
		sum += l[i];
	}
	sort(rAll(l));
	sum -= l[0];
	if(sum>l[0])
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256