akhauriyash/Code-Regression huggingface dataset:
#include <functional>
#include <utility>
#include <numeric>
#include<set>
#include<map>
#include<list>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<valarray>
using namespace std;


int main(){
	bool check;
	string S,T;
	cin>>S>>T;
	
int 	sz1=S.size(),sz2=T.size();
if(sz1!=sz2)
{
	cout<<"No"<<endl;
}
else
{
for(int i=0;i<sz1;i++)
{
	rotate(T.begin(),T.begin()+1,T.end());
	if(T==S){
		check=true;
		break;
	}
	else{
			check=false;
		continue;
	}
	
}
if(check)
	cout<<"Yes"<<endl;

else
cout<<"No"<<endl;

}
return 0;







}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

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

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  string s;
  cin >> s;
  set<char> d;
  for (char c = 'a'; c <= 'z'; c++) d.insert(c);
  for (auto &i : s) d.erase(i);
  if (d.empty()) cout << "None" << '\n';
  else cout << *d.begin() << '\n';
}


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

immutable long MOD = 10^^9 + 7;
immutable int M = 62;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!long).array;
    auto B = new long[][](N, M);

    foreach (i; 0..N) foreach (j; 0..M) {
        B[i][j] = (A[i] >> j) & 1;
    }

    auto S = new long[](M);
    foreach (j; 0..M) foreach (i; 0..N) S[j] += B[i][j];
    long ans = 0;

    foreach (i; 0..N) {
        long cnt = N - i - 1;
        long carry = 0;

        foreach (j; 0..M) {
            S[j] -= B[i][j];

            long one = S[j];
            long zero = cnt - S[j];
            if (B[i][j]) swap(one, zero);

            long s = one + carry;
            if (s & 1) ans += powmod(2, j, MOD) % MOD;
            ans %= MOD;

            carry = s >> 1;
        }

        int j = M;
        while (carry) {
            if (carry & 1) ans += powmod(2, j, MOD) % MOD;
            j += 1;
            carry >>= 1;
        }
    }

    ans.writeln;
}

long powmod(long a, long x, long m) {
    long ret = 1;
    while (x) {
        if (x % 2) ret = ret * a % m;
        a = a * a % m;
        x /= 2;
    }
    return ret;
}


Measured memory_bytes: 179380
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int A,B,C,D,E,F;
int ansi,ansj;
bool f[3010][3010];
int main()
{
    scanf("%d%d%d%d%d%d",&A,&B,&C,&D,&E,&F);
    f[0][0]=true;
    for(int i=0;i<=F;i++)
        for(int j=0;j<=F;j++)
            if(f[i][j])
            {
                if(i+100*A+j<=F) f[i+100*A][j]=true;
                if(i+100*B+j<=F) f[i+100*B][j]=true;
                if(i+j+C<=F) f[i][j+C]=true;
                if(i+j+D<=F) f[i][j+D]=true;
            }
    ansi=1;
    for(int i=0;i<=F;i++)
        for(int j=0;j<=F;j++)
            if(f[i][j]&&j*(ansi+ansj)>=ansj*(i+j)&&j*100<=E*i&&(i!=0||j!=0)) ansi=i,ansj=j;
    printf("%d %d\n",ansi+ansj,ansj);
    return 0;
}


Measured memory_bytes: 6400
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<valarray>//なんとなく追加
//#include<windows.h>

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
//#define view Sleep(2000)


signed main() {

	int a, b;
	cin >> a >> b;
	a = a*b;
	if (a % 2 == 0) {
		cout << "Even" << endl;
	}
	else cout << "Odd" << endl;

}

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

int main() {
  ll s; cin >> s;
  ll dp[2010];
  dp[0] = 1;

  for(int i = 0; i <= s; i++){
    if(i >= 3) dp[i] = dp[i-1] + dp[i-3];
    dp[i] %= mod;
  }

  cout << dp[s] << endl;
}


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


int main() {
    string n;
    cin >> n;
    int num[3]={0,0,0};
    //sort(n[0],n[2]);
    for(int i=0;i<3;i++){
        if(n[i]!='a' && n[i]!='b'&& n[i]!='c'){
            cout<<"No\n"<<endl;
            return 0;
        }
        if(n[i]=='a' && num[0]==1){
            cout<<"No\n"<<endl;
            return 0;
        }
        else if(n[i]=='a')num[0]=1;
        if(n[i]=='b' && num[1]==1){
            cout<<"No\n"<<endl;
            return 0;
        }
        else if(n[i]=='b')num[1]=1;
        if(n[i]=='c' && num[2]==1){
            cout<<"No\n"<<endl;
            return 0;
        }
        else if(n[i]=='c')num[2]=1;
    }
    cout<<"Yes\n"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<bitset>
#define lson node<<1,st,mid
#define rson node<<1|1,mid+1,ed
#define mem(a,x) memset(a,x,sizeof(a))
#define me(a) memset(a,0,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) x&(-x)
#define up(i,x,y) for(long long i=x;i<y;i++)
#define down(i,x,y) for(long long i=x;i>=y;i--)
#define in freopen("in.txt","r",stdin)
#define out freopen("out.txt","w",stdout)   
typedef long long ll;
const ll mod = 1e9+7;
const ll INF = 0x3f3f3f3f;
const ll maxn = 1e6+5;
const ll N = 1e3+5;
const double pi = acos(-1.0);
const double eps=1e-9;
using namespace std;

ll a[maxn];
int main(){
    // in;
    // out;
    ll n,m;
    cin>>n>>m;
    for(ll i=0;i<=n;i++){
        a[i]=i;
    }
    ll sum=0;
    for(ll i=m;i<=n+1;i++){
        ll minn=(i-1)*i/2;
        ll maxx=(n)*(n+1)/2;
        ll hh=(n-i)*(n-i+1)/2;
        if(n-i+1<0) hh=0;
        maxx-=hh;
        // cout<<minn<<" "<<maxx<<endl;
        // cout<<maxx-minn+1<<endl;
        sum+=maxx-minn+1;
        sum%=mod;
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 5156
import java.util.Scanner;

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

		int a = sc.nextInt();
		int b = sc.nextInt();
		int ans = a-b*2;

		if(ans < 0) {
			System.out.println(0);
		} else {
			System.out.println(ans);
		}

	}

}


Measured memory_bytes: 24020
#ifdef __GNUG__
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <iomanip>
#include <functional>
#endif

//#pragma optimize GCC("O3")
typedef long long ll;
typedef long double ld;
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n, k;
	cin >> n >> k;
	vector<ll>p(n), c(n);
	for (int i = 0; i < n; i++)
	{
		cin >> p[i];
		p[i]--;
	}
	for (int i = 0; i < n; i++)
		cin >> c[i];
	vector<vector<ll> > kam(n, vector<ll>(1));
	vector<vector<ll> > val(n, vector<ll>(1, 0));
	for (int i = 0; i < n; i++)
		kam[i][0] = i;
	ll ans = c.back();
	for (int i = 0; i < n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			val[i].push_back(val[i][j - 1] + c[p[kam[i][j - 1]]]);
			kam[i].push_back(p[kam[i][j - 1]]);
			if (kam[i][j] == i) break;
		}
		ll cely = max(0ll, val[i].back());
		for (ll j = 1; j < val[i].size(); j++)
		{
			if (k < j) break;
			ans = max(ans, (k - j) / ((ll)(kam[i].size()) - 1) * cely + val[i][j]);
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e6 + 100;
vector<pair<ll, ll>> bst[SIZE];
vector<ll> pref;

int main()
{
    fastInp;

    ll n;
    cin >> n;
    ll sz = (1ll << n);
    vector<ll> vec(sz);
    for (int i = 0; i < vec.size(); i++) {
        cin >> vec[i];
        bst[i].push_back({vec[i], i});
    }

    pref.resize(sz);
    for (int i = 1; i < sz; i++) {
        for (int j = 0; j < n; j++) {
            if ((i >> j) & 1) {
                ll xr = (i) ^ (1ll << j);
                for (auto cur : bst[xr]) bst[i].push_back(cur);
            }
        }
        sort(bst[i].rbegin(), bst[i].rend());
        auto it = unique(bst[i].begin(), bst[i].end());
        bst[i].erase(it, bst[i].end());
        bst[i].resize(2);
        pref[i] = bst[i][0].first + bst[i][1].first;
    }

    for (int i = 2; i < pref.size(); i++) pref[i] = max(pref[i], pref[i - 1]);

    for (int i = 1; i < pref.size(); i++) cout << pref[i] << "\n";
    return 0;    
}

Measured memory_bytes: 150580
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n,m;
	cin>>n>>m;
	vector<long long> a(n),b(n),c(n),d(n);
	for(int i=0;i<n;i++){
		long long x,y,z;
		cin>>x>>y>>z;
		a[i]=x+y+z;
		b[i]=x+y-z;
		c[i]=x-y+z;
		d[i]=x-z-y; 
	}
	sort(a.begin(),a.end());sort(b.begin(),b.end());
	sort(c.begin(),c.end());sort(d.begin(),d.end());
	vector<long long> s(8);
	for(int i=0;i<m;i++){
		s[0]-=a[i];s[1]-=b[i];
		s[2]-=c[i];s[3]-=d[i];
		s[4]+=a[n-1-i];s[5]+=b[n-1-i];
		s[6]+=c[n-1-i];s[7]+=b[n-1-i];
	}
	sort(s.begin(),s.end());
	cout<<s[7];
}

Measured memory_bytes: 3660
import itertools
import collections
h,w = map(int,input().split())
c = [list(map(int,input().split())) for _ in range(10)]
a = [list(map(int,input().split())) for _ in range(h)]
a = list(itertools.chain.from_iterable(a))
b = collections.Counter(a)
ans = 0

def bfs(x):
    if x[-1]==1:
        global s
        buf = 0
        for i in range(len(x)-1):
            buf += c[x[i]][x[i+1]]
        s = min(s,buf)
    else:
        for i in range(10):
            if not i in x:
                bfs(x+[i])

for i in b:
    if not i in [1,-1]:
        s = 10**9
        bfs([i])
        ans += s*b[i]
print(ans)

Measured memory_bytes: 45532
#include <bits/stdc++.h>
using namespace std;
#define N 100001

int main() {
    int n, a, b, c;

    cin >> n;

    int mass[N][3];

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

        mass[i][0] = a; mass[i][1] = b; mass[i][2] = c;
    }

    //cout << ans[0][0] << " " << ans[0][1] << " " << ans[0][2] << endl;

    for (int i = 1;i < n;i++) {
        mass[i][0] = max(mass[i - 1][1], mass[i - 1][2]) + mass[i][0];
        mass[i][1] = max(mass[i - 1][0], mass[i - 1][2]) + mass[i][1];
        mass[i][2] = max(mass[i - 1][0], mass[i - 1][1]) + mass[i][2];

        //cout << ans[i][0] << " " << ans[i][1] << " " << ans[i][2] << endl;
    }

    cout << max(max(mass[n - 1][0], mass[n - 1][1]), mass[n - 1][2]);
}

Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF (long long)(1e18)
#define EPS (1e-20)
#define MOD (int)(1e9+7)

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX 110000

signed main(){
	cout<<fixed<<setprecision(7);
	
	int n, m, w = 0, h = 0, x, y;
	
	cin>>n>>m;
	
	for(int i = 0, s = n-1, b = 0, bx; i < n; i++){
		cin>>x;
		if(i){
			w += (b = b + s)%MOD*(x-bx)%MOD; w %= MOD;
			s -= 2;
		}
		bx = x;
	}
	for(int i = 0, s = m-1, b = 0, by; i < m; i++){
		cin>>y;
		if(i){
			h += (b = b + s)%MOD*(y-by)%MOD; h%=MOD;
			s -= 2;
		}
		by = y;
	}
	
	cout<<(w*h)%MOD<<endl;
	
	
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<algorithm>
#include<map>
#pragma warning(disable: 4996)
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;


int main() {
	
	int N;
	cin >> N;
	vector<int> x(N);
	int num = 1000000, sum = -1;
	rep(i, N) {
		cin >> x[i];
		if (x[i] < num) {
			num = x[i];
		}
		if (x[i] > sum) {
			sum = x[i];
		}
	}

	int d = (num + sum) / 2;
	int ans;
	if (sum - d >= d - num) {
		 ans = sum - d;
	}
	else {  ans = d - num; }

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3116
import itertools

N = int(input())
eigyo = []
for i in range(N):
    eigyo.append(list(map(int, input().split())))
uriage = []
for i in range(N):
    uriage.append(list(map(int, input().split())))
# print(eigyo)
# print(uriage)

def get_kaburi(decide, i):
    kaburi = 0
    for j in range(10):
        if (decide[j] == 1) and (eigyo[i][j] == 1):
            kaburi += 1
    return kaburi

infinity = 10**10

def get_score(decide):
    if sum(decide) == 0:
        return -infinity
    score = 0
    total_kaburi = 0
    for i in range(N):
        kaburi = get_kaburi(decide, i)
        score += uriage[i][kaburi]
    return score

scores = map(get_score, itertools.product([0,1], repeat=10))
print(max(scores))


Measured memory_bytes: 3188
N,K = [int(i) for i in input().split()]
AAA = [int(i) for i in input().split()]
 
count = [0 for i in range(200010)]
for A in AAA:
    count[A]+=1
ans=0
count=sorted([i for i in count if i!=0])
 
if len(count)<=K:
    print("0")
    exit()
else:
    print(sum(count[:-K]))

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

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

int main() {
    int N;
    cin >> N;
    int r = N%10;
    if(r==2||r==4||r==5||r==7||r==9){
        cout << "hon" << endl;
    }
    else if(r==0||r==1||r==6||r==8){
        cout << "pon" << endl;
    }
    else{
        cout << "bon" << endl;
    }
}


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

int main(){
    int n;
    cin>>n;
    vector<int> a(n),b(n);
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i];
    long long int dist=0;
    for(int i=0;i<n;i++){
        if(b[i]-a[i]>0) dist+=(b[i]-a[i])/2;
        else dist+=b[i]-a[i];
    }
    if(dist>=0 && accumulate(b.begin(),b.end(),0LL)>=accumulate(a.begin(),a.end(),0LL)){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 384
let n, m, c = Scanf.scanf " %d %d %d" @@ fun a b c -> a, b, c
let bs = Array.init m @@ fun _ -> Scanf.scanf " %d" (+) 0
let a_ss = Array.init n @@ fun _ -> Array.init m @@ fun i -> Scanf.scanf " %d" @@ fun a -> a * bs.(i)
let _ = Array.fold_left (fun s a_s -> s + if Array.fold_left (+) c a_s > 0 then 1 else 0) 0 a_ss |> Printf.printf "%d\n"

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>

#define STACK_MAX 1000
#define STACK_INIT 0
#define FORM_MAX 100
#define FORM_INIT 0
#define VER_INIT 0
#define FIRST_ITEM 0
#define SECOND_ITEM 1
#define EXIT_SUCCESS 0
#define NEXT_ITEM( x ) ( ( x ) + 1 )

signed long aslG_Dstack[ STACK_MAX ] = { STACK_INIT };
unsigned long pulG_Dstack_p = VER_INIT;

static void push( signed long slW_Dpush_calc ){
	pulG_Dstack_p++;
	aslG_Dstack[ pulG_Dstack_p ] = slW_Dpush_calc;
}

static signed long pop( void ){
	pulG_Dstack_p--;
	return aslG_Dstack[ NEXT_ITEM( pulG_Dstack_p ) ];
}

static void plus( void ){
	signed long slW_Dcalc_first = VER_INIT;
	signed long slW_Dcalc_second = VER_INIT;
	signed long slW_Dver_throw = VER_INIT;

	slW_Dcalc_first = pop();
	slW_Dcalc_second = pop();
	slW_Dver_throw = slW_Dcalc_second + slW_Dcalc_first;
	push( slW_Dver_throw );
}

static void minus( void ){
	signed long slW_Dcalc_first = VER_INIT;
	signed long slW_Dcalc_second = VER_INIT;
	signed long slW_Dver_throw = VER_INIT;

	slW_Dcalc_first = pop();
	slW_Dcalc_second = pop();
	slW_Dver_throw = slW_Dcalc_second - slW_Dcalc_first;
	push( slW_Dver_throw );
}

static void multi( void ){
	signed long slW_Dcalc_first = VER_INIT;
	signed long slW_Dcalc_second = VER_INIT;
	signed long slW_Dver_throw = VER_INIT;

	slW_Dcalc_first = pop();
	slW_Dcalc_second = pop();
	slW_Dver_throw = slW_Dcalc_second * slW_Dcalc_first;
	push( slW_Dver_throw );
}

int main( void ){
	unsigned char aulW_Dform[ FORM_MAX ] = { FORM_INIT };
	signed long slW_Dcalc = VER_INIT;

	while( scanf( "%s", aulW_Dform ) != EOF ){
		if( aulW_Dform[ FIRST_ITEM ] == '+' ){
			plus();
		}
		else if( aulW_Dform[ FIRST_ITEM ] == '-' ){
			minus();
		}
		else if( aulW_Dform[ FIRST_ITEM ] == '*' ){
			multi();
		}
		else{
			slW_Dcalc = atoi( aulW_Dform );
			push( slW_Dcalc );
		}
	}
	printf( "%d\n", aslG_Dstack[ SECOND_ITEM ] );
	return EXIT_SUCCESS;
}

Measured memory_bytes: 548
def main():
    import sys
    input = sys.stdin.readline
    n = int(input())
    a = tuple(map(int,input().split()))
    b = tuple(map(int,input().split()))

    dg = 20

    pp = 20

    dp = [10**5]*(10**7)

    new = set([])
    for i in range(n):
        s = (1<<i)
        dp[s*pp+i] = i
        new.add(s*dg+i)

    for k in range(n-1):
        tank = set([])
        if len(new) == 0:
            break
        for popelt in new:
            s,idx = popelt//dg,popelt%dg
            if (k-idx)%2 == 0:
                fr = a[idx]
            else:
                fr = b[idx]
            cnt = 0
            for j in range(n):
                if (s>>j)&1 == 0:
                    if (j-k)%2 == 1:
                        val = a[j]
                    else:
                        val = b[j]
                    if val >= fr and dp[(s+(1<<j))*pp+j] > dp[s*pp+idx]+j-cnt:
                        dp[(s+(1<<j))*pp+j] = dp[s*pp+idx]+j-cnt
                        tank.add((s+(1<<j))*dg + j)
                else:
                    cnt += 1
        new = tank
    
    res = 10**5
    s = (2**n-1)*pp
    for i in range(n):
        if res > dp[s+i]:
            res = dp[s+i]
    if res == 10**5:
        print(-1)
    else:
        print(res)


if __name__ == '__main__':
    main()

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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;

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

int main(){

  string s;cin>>s;

  ll count=0;
  ll c=0;
  string y="YAKI";
  rep(i,0,min((ll)4,(ll)s.size())){
    if(s[i]==y[c])c++;
  }

  if(c==4)out("Yes");
  else out("No");

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>

using namespace std;

using ll = long long int;

int main(){
    
    ll N;
    array<ll, 128> S;
    
    cin >> N;
    for(ll i = 0; i < N; ++i){
        cin >> S[i];
    }
    
    sort(S.begin(), S.begin() + N);
    
    ll sum = 0;
    for(ll i = 0; i < N; ++i){
        sum += S[i];
    }
    
    if(sum % 10){
        cout << sum << endl;
    }else{
        for(ll i = 0; i < N; ++i){
            if(S[i] % 10){
                cout << (sum - S[i]) << endl;
                return 0;
            }
        }
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
char s[400][401];
int h,w;
long long cntb,cntw;
inline bool is_valid_coordinate(int i,int j){
    return (0<=i&&i<h&&0<=j&&j<w);
}
inline bool is_alternated(int i,int j,int di,int dj){
    return (is_valid_coordinate(i,j)
            &&is_valid_coordinate(i+di,j+dj)
            &&((s[i][j]=='b'&&s[i+di][j+dj]=='.')
            ||(s[i][j]=='w'&&s[i+di][j+dj]=='#')));
}
void check_recursively(int i,int j){
    if(is_valid_coordinate(i,j)&&(s[i][j]=='#'||s[i][j]=='.')){
        if(s[i][j]=='#'){
            s[i][j]='b';
            cntb++;
        }else if(s[i][j]=='.'){
            s[i][j]='w';
            cntw++;
        }
        int di[]={1,0,-1,0},dj[]={0,1,0,-1};
        for(int itr=0;itr<4;itr++){
            if(is_alternated(i,j,di[itr],dj[itr]))
                check_recursively(i+di[itr],j+dj[itr]);
        }
    }
}
void reset_recursively(int i,int j){
    if(is_valid_coordinate(i,j)&&(s[i][j]=='b'||s[i][j]=='w')){
        s[i][j]='x';
        int di[]={1,0,-1,0},dj[]={0,1,0,-1};
        for(int itr=0;itr<4;itr++){
            reset_recursively(i+di[itr],j+dj[itr]);
        }
    }
}
long long count_in_connected_component(int i,int j){
    cntb=0;
    cntw=0;
    check_recursively(i,j);
    reset_recursively(i,j);
    return cntb*cntw;
}
int main(){
    long long answer=0;
    scanf("%d%d",&h,&w);
    for(int i=0;i<h;i++)scanf("%s",s[i]);
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=='#')answer+=count_in_connected_component(i,j);
        }
    }
    printf("%lld",answer);
    return 0;
}

Measured memory_bytes: 15360
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
    vector<vector<int>> a(3, vector<int>(3));
    cin >> a[0][0] >> a[0][1] >> a[0][2];
    cin >> a[1][0] >> a[1][1] >> a[1][2];
    cin >> a[2][0] >> a[2][1] >> a[2][2];
    int n;
    cin >> n;
    vector<int> b(n);
    for (int i = 0; i < n; i++)
        cin >> b[i];
    
    vector<vector<bool>> check(3, vector<bool>(3, false));
    
    for (int k = 0; k < n; k++)
        for (int i = 0; i < 3; i++)
            for (int j = 0; j < 3; j++)
                if (b[k] == a[i][j])
                    check[i][j] = true;
    
    bool bingo = false;
    for (int i = 0; i < 3; i++)
        bingo |= check[i][0] & check[i][1] & check [i][2];
    for (int i = 0; i < 3; i++)
        bingo |= check[0][i] & check[1][i] & check [2][i];
    
    bingo |= check[0][0] & check[1][1] & check [2][2];
    bingo |= check[0][2] & check[1][1] & check [2][0];
    
    if (bingo)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    
    return 0;
}


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


#define  SZ(items) (int)items.size()
#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))
#define  nl "\n";

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



template <class T> inline T biton(T n, T pos)
{
    return n | ((T)1 << pos);
}
template <class T> inline T bitoff(T n, T pos)
{
    return n & ~((T)1 << pos);
}
template <class T> inline T ison(T n, T pos)
{
    return (bool)(n & ((T)1 << pos));
}
template <class T> inline T gcd(T a, T b)
{
    while (b)
    {
        a = a % b;
        swap(a, b);
    }
    return a;
}
template <class T> inline T bigmod(T p, T e, T m)
{
    T ret = 1;
    for (; e > 0; e >>= 1)
    {
        if (e & 1)
            ret = (ret * p) % m;
        p = (p * p) % m;
    }
    return (T)ret;
};



#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1)
{
    cerr << name << " is " << arg1 << std::endl;
}
template < typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " is " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define debug(...)
#endif


long long get(long long n){

    return (n*(n-1ll))/2ll;
}


void solve()
{
   long long n,m;
   cin>>n>>m;

   cout<<get(n)+get(m)<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    cout.tie(nullptr);
    cin.tie(nullptr);

    int t = 1;

    while (t--)
    {
        solve();
    }

    return 0;
}


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

int main() {
    int n, x;
    
    while(1) {
        cin >> n >> x;
        if(n == 0 && x == 0) {
            break;
        }
        
        int count = 0;
        for(int i = 1; i <= n - 2; i++) {
            for(int j = i + 1; j <= n - 1; j++) {
                for(int k = j + 1; k <= n; k++) {
                    if(i+j+k == x) {
                        count++;
                    }
                }
            }
        }
        cout << count << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
long long z,a,b,n;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a>>b;
		z+=b-a+1;
	}
	cout<<z<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;


int main() {
	//K(a1+a2+…aN)=M
	//M/K>=N&&M%K=0
	int N, K;
	cin >> N >> K;
	for (int i = K/N; i >= 1; i--)
	{
		if (K % i == 0 && K / i >= N) {
			cout << i; return 0;
		}
	}
}

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

const string YES = "Yes";
const string NO = "No";

void solve(std::vector<std::vector<long long>> A, long long N, std::vector<long long> b){
    vector<vector<bool>> flg(3, vector<bool>(3, false));
    for(ll bi : b){
        REP(i, 3){
            REP(j, 3){
                if(A.at(i).at(j) == bi){
                    flg.at(i).at(j) = true;
                }
            }
        }
    }

    REP(i, 3){
        ll sumv = 0, sumh = 0;
        REP(j, 3){
            sumv += flg.at(i).at(j);
            sumh += flg.at(j).at(i);
        }
        if(sumv >= 3 || sumh >= 3){
            cout << YES << endl;
            return;
        }
    }
    ll sumd1 = 0, sumd2 = 0;
    REP(i, 3){
        sumd1 += flg.at(i).at(i);
        sumd2 += flg.at(i).at(2 - i);
    }
    if(sumd1 >= 3 || sumd2 >= 3){
        cout << YES << endl;
        return;
    }
    cout << NO << endl;
    return;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    std::vector<std::vector<long long>> A(3, std::vector<long long>(3));
    for(int i = 0 ; i < 3 ; i++){
        for(int j = 0 ; j < 3 ; j++){
            scanf("%lld",&A[i][j]);
        }
    }
    long long N;
    scanf("%lld",&N);
    std::vector<long long> b(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&b[i]);
    }
    solve(std::move(A), N, std::move(b));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int d,n;
    cin>>d>>n;
    if(d==0){
        if(n==100){
            cout<<101<<endl;
        }
        else{
        cout<<n<<endl;
        }
    }
    else if(d==1){
       if(n==100){
            cout<<10100<<endl;
        }
        else{
        cout<<n*100<<endl;
        }
    }
    else{
        if(n==100){
            cout<<1010000<<endl;
        }
        else{
        cout<<n*10000<<endl;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long int ll;
typedef unsigned long long ull;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
typedef pair<ll,ll> P;


int main()
{
    int x,n;
    cin >> x>>n;
    map<int,bool>p;
    rep(i,n)
    {
        int a;
        cin>>a;
        p[a]=true;
    }
    int MIN=1000,ans;
   
    rep(i,102)
    {
        
        if(!p[i]&&abs(x-i)<MIN){
            MIN = min(abs(x-i),MIN);
            ans=i;
        }
    }
    cout<<ans<<endl;
    return 0;

}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<58;
const ll mod=1e9+7;

int main(){
  ll i,j;
  ll n,m;
  cin>>n>>m;
  VI x(n),y(m);
  for(i=0;i<n;i++) cin>>x[i];
  for(i=0;i<m;i++) cin>>y[i];
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  ll a=0,b=0;
  for(i=0;i<n;i++) a-=x[i]*(n-1-i-i);
  for(i=0;i<m;i++) b-=y[i]*(m-1-i-i);
  cout<<(a%mod)*(b%mod)%mod<<endl;
  return 0;
}

Measured memory_bytes: 1792
N = 26
D = int(input())

c_list = list(map(int, input().split()))

s_table = []
for _ in range(D):
	s_table.append(list(map(int, input().split())))

data = []
for _ in range(D):
	data.append(int(input()) - 1)

def calc(data):
	last = [-1] * N
	satisfaction = 0
	for i in range(D):
		j = data[i]
		satisfaction += s_table[i][j]
		last[j] = i
		for k in range(N):
			satisfaction -= c_list[k] * (i - last[k])
		print(satisfaction)
	return satisfaction

calc(data)


Measured memory_bytes: 9276
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
// #define fore(i,a) for(auto &i:a)
// #define all(x) (x).begin(),(x).end()
// #pragma GCC optimize ("-O3")
// using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
// typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
// 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 (b < a) { a = b; return 1; } return 0; }
 
using namespace std;
 
int main(void)
{
  int k;
  int a,b;
  
  cin>>k>>a>>b;
  
  int i=1;
  int n=k;
  while(1){
    if(a<=n*i&&n*i<=b){
      cout<<"OK"<<endl;
      break;
    }
    else{
      if(n*i>b){
        cout<<"NG"<<endl;
      	break;
      }
    }
    i++;
  }
    
  return 0;
}

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

int main() {
	int A, B;
	vector<int> va, vb;
	cin >> A >> B;
	for(int i = 0; i < A; i++) {
		int tmp;
		cin >> tmp;
		va.push_back(tmp);
	}
	for(int i = 0; i < B; i++) {
		int tmp;
		cin >> tmp;
		vb.push_back(tmp);
	}

	int mx = 0;
	for(int i = 0; i < vb.size(); i++) {
		int tmp = 0;
		int j = i;
		for(int k = 0; k < va.size() && j < vb.size(); k++) {
			if(vb[j] == va[k]) {
				tmp++;
				j++;
			}
		}
		mx = max(mx, tmp);
	}
	cout << mx << endl;
}

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

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        char c = br.readLine().charAt(0);
        System.out.println(problem151a(c));
    }

    private static char problem151a(char c) {
        return ++c;
    }
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, A;
    cin >> N >> A;
    N %= 500;
    if (N <= A)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

  static final char[] ALPHA = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
  static final long BASE = 26;
  public static void main(String[] args) {
      Scanner s = new Scanner(System.in);
      long n = s.nextLong();
      String name = "";
      if (n == 1) {
          System.out.println("a");
              return;
          }
          while (n != 0) {
              long rem = (n-1) % BASE;
              n = (n-1)/BASE;
              name = ALPHA[(int) (rem)] + name;
          }
          System.out.println(name);
  }
}


Measured memory_bytes: 26928
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class B
{
	public static void Main()	
	{
		int N = GetInt();
		int K = GetInt();
		int ans = K;
		for(int i = 1; i < N; i++)
			ans *= (K - 1);
		Console.WriteLine(ans);
	}
}


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(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


Measured memory_bytes: 11092
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <functional>
#include <stack>
#include <utility>
#include <map>
#include <queue>
#include <set>
#include <array>
#include <climits>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

const ll MOD = 1000000000 + 7;
const ll INF = 99999999;
const ll MAX_V = 105;
const double EPS = 10e-6;
const double PI = 3.14159265359;

ll dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 };
//int d[] = {0,1,0,-1};
//int nx = x + d[i];
//int ny = y + d[(i+1)%4]

bool dpx[4005][16005]{}, dpy[4005][16005]{};

int main() {
	vector<int> xs, ys;
	int gx, gy, xsum=0,ysum=0;
	bool dir = true;
	string s;
	cin >> s >> gx >> gy;
	for (int i = 0, l = 0; i < s.size(); i++) {
		if (s[i] == 'T') {
			if (dir) {
				xs.push_back(l);
				xsum += l;
			}
			else {
				ys.push_back(l);
				ysum += l;
			}
			l = 0;
			dir = !dir;
		}
		else {
			l++;
			if (i == s.size() - 1) {
				if (dir) {
					xs.push_back(l);
					xsum += l;
				}
				else {
					ys.push_back(l);
					ysum += l;
				}
			}
		}
	}
	ys.push_back(0);
	gx += 8000; gy += 8000;
	dpx[0][xs[0]+8000] = true; dpy[0][8000+ys[0]] = true;  dpy[0][8000 - ys[0]] = true;
	for (int i = 1; i < xs.size(); i++) {
		for (int j = 0; j <= xsum + 8000; j++) {
			if (j >= xs[i] && dpx[i - 1][j - xs[i]])
				dpx[i][j] = true;
			if (j + xs[i] <= 16001  && dpx[i - 1][j + xs[i]])
				dpx[i][j] = true;
		}
	}
	for (int i = 1; i < ys.size(); i++) {
		for (int j = 0; j <= ysum + 8000; j++) {
			if (j >= ys[i] && dpy[i - 1][j - ys[i]])
				dpy[i][j] = true;
			if (j + ys[i] <= 16001 && dpy[i - 1][j + ys[i]])
				dpy[i][j] = true;
		}
	}
	if (dpx[xs.size()-1][gx] && dpy[ys.size()-1][gy])cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 123648
<?php

list($n) = explode(' ', trim(fgets(STDIN)));
$a = explode(' ', trim(fgets(STDIN)));

$count = [];
foreach ($a as $number) {
    if (!isset($count[$number])) {
        $count[$number] = 1;
    } else {
        ++$count[$number];
    }
}

$pattern_list = [];
$sum = 0;
foreach ($count as $number => $count_per_num) {
    if ($count_per_num <= 1) {
        unset($count[$number]);
        continue;
    }

    $pattern = $count_per_num * ($count_per_num - 1) / 2;

    $pattern_list[$number] = $pattern;
    $sum += $pattern;
}

$answers = [];
foreach ($a as $number) {
    if (!array_key_exists($number, $pattern_list)) {
        $answers[] = $sum;
        continue;
    }

    $answers[] = $sum - $pattern_list[$number] + (($count[$number] - 1) * ($count[$number] - 2) / 2);
}

echo implode(PHP_EOL, $answers);


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

#define int long long int
#define rep(a,b,c) for(int a=b;a<c;a++)
#define repm(a,b,c) for(int a=(b-1);a>=c;a--)
#define pb push_back
#define str string
#define sf(a) scanfs("%d",&a)
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define clean(used) memset(used,false,sizeof(used))
using namespace std;

const int INF = 1e18 + 9;
const int Mod = 1e9 + 7;
inline int replac(str s){double ans=0;rep(i,0,s.length()){ans+=(s[i]-'0')*pow(10,s.length()-i-1);}return (int)ans;}
inline string numstr(int m){str s="";while(m>0){char c;int a=m/10;if(a>0)a=m%(a*10);else a=m;c=(char)('0'+a);s+=c;m/=10;}str st="";for(int i=s.size()-1;i>=0;i--){st+=s[i];}return st;}
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;

vi load[200002];

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,x,y;
    cin >> n >> m;
    rep(i,0,m){
        cin >> x >> y;
        x--;
        y--;
        load[x].push_back(y);
        load[y].push_back(x);
    }

    queue<int> q;
    for (int i : load[0]){
        q.push(i);
    }
    bool ans = false;
    while (!q.empty()){
        int d = q.front();
        q.pop();
        for(int j : load[d]){
            if(j == n-1){
                ans = true;
            }
        }
    }
    if(ans){
        cout << "POSSIBLE" <<  endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> p(N);
  int incorrect = 0;
  for(int i=0;i<N;i++){
    cin >> p[i];
    if(p[i]!=i+1){
      incorrect ++;
    }
  }
  if(incorrect == 0 || incorrect == 2){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, m;
	cin >> n >> m;
	vector<vector<int>> path(n+1);
	for(int i=0; i<m; ++i){
		int a, b;
		cin >> a >> b;
		path[a].push_back(b);
		path[b].push_back(a);
	}

	vector<int> sign(n+1,0);
	sign[1]=1;
	queue<int> q;
	q.push(1);
	while(!q.empty()){
		int z=q.front();
		q.pop();
		
		for(int i=0; i<path[z].size(); ++i){
			if(sign[path[z][i]]==0){
				sign[path[z][i]]=1;
				sign[path[z][i]]=z;
				q.push(path[z][i]);
			}
		}
	}

	cout << "Yes" << endl;
	for(int i=2; i<=n; ++i){
		cout << sign[i] << endl;
	}
}

Measured memory_bytes: 10232
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define tios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define tmod 1000000007

#define tvi vector<int>
#define tvii vector<int,int>
#define tvpii vector<pair<int,int>>
#define tmii map<int,int>
#define tmiv map<int,vector<int>>
#define tmsi map<string,int>
#define tmci map<char,int>
#define tumi unordered_map<int,int>
#define tumsi unordered_map<string,int>
#define tumci unordered_map<char,int>
#define tpii pair<int,int>
#define tsi set<int>
#define tusi unordered_set<int>
#define tqi queue<int>
#define tdqi deque<int>
#define tpqi priority_queue<int>

#define tr(i,n) for(int i=0;i<n;i++)
#define tl(i,n) for(int i=n;i>=0;i--)
#define tcr(a,x) for(auto a=x.begin();a!=x.end();a++)
#define tcbe(x) x.begin(),x.end()

tvi v;

int solve(int t) {
    if(t==0) return 1;
    if(t<2) return 0;
    if(t==3) return 1;
    if(v[t]!=-1) return v[t];
    v[t]=0;
    for(int i=3;i<=t;i++) {
        v[t] += solve(t-i);
        v[t]%=tmod;
    }
    return v[t];
}

int32_t main(void) {
    tios
    int n;
    cin>>n;
    v.resize(n+5,-1);
    if(n<3) cout<<0;
    else cout<<solve(n);
    return 0;
}


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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (long long)1e18 + 1;

class UnionFind {
public:
    struct Node {
        long long parent;
        long long rank;
        Node() = default;
        Node(const long long& _parent,
             const long long& _rank) :
            parent(_parent),
            rank(_rank) { }
    };

    std::vector<Node> node;

    UnionFind(const long long& num_node) :
        node(num_node) {
        for(long long i = 0; i < num_node; i++) {
            node[i].parent = i;
        }
    }

    long long getRoot(const long long& x) {
        return (node[x].parent == x) ?
            x : node[x].parent = getRoot(node[x].parent);
    }

    void unite(const long long& x,
               const long long& y) {
        auto rx = getRoot(x);
        auto ry = getRoot(y);
        if(rx != ry) {
            // if(ry < rx) std::swap(rx, ry);
            if(node[rx].rank < node[ry].rank) {
                node[rx].parent = ry;
            }
            else {
                node[ry].parent = rx;
                if(node[rx].rank == node[ry].rank) {
                    node[rx].rank++;
                }
            }
        }
    }

    bool checkSameRoot(const long long& x,
                       const long long& y) {
        return getRoot(x) == getRoot(y);
    }
};

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

    int N, K, L;
    std::cin >> N >> K >> L;

    UnionFind road(N), tr(N);
    REP(i, K) {
        int p, q;
        std::cin >> p >> q;
        if(i % 2 == 0) swap(p, q);
        road.unite(p - 1, q - 1);
    }
    REP(i, L) {
        int r, s;
        std::cin >> r >> s;
        tr.unite(r - 1, s - 1);
    }

    map<pair<int, int>, int> map;
    REP(i, N) {
        auto p = make_pair(road.getRoot(i), tr.getRoot(i));
        auto itr = map.find(p);
        if(itr != map.end()) {
            itr->second++;
        }
        else {
            map.insert(make_pair(p, 1));
        }
    }

    REP(i, N) {
        std::cout << map[make_pair(road.getRoot(i), tr.getRoot(i))] << " ";
    }
    std::cout << std::endl;

    return 0;
}


Measured memory_bytes: 18048
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long N, std::vector<long long> H)
{
    int ans = 0;
    int tmp = H[0];
    int cnt = 0;
    for (int i = 1; i < N; i++)
    {
        if(H[i]<=tmp){
            cnt++;
            tmp = H[i];
        }else{
            ans = max(ans,cnt);
            tmp = H[i];
            cnt = 0;
        }
    }

    cout << max(ans,cnt) << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> H(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &H[i]);
    }
    solve(N, std::move(H));
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){

	int sn;
	int i;
	int j,k;
	int flg;
	char in_a[82];
	char in_b[82];
	char str_a[82];
	char str_b[82];
	char str_sum[82];
	char c;
	char cs[3];
	char *p;
	int a,b,carry;

	scanf("%d",&sn);

	for(i=1;i<=sn;i++){

		scanf("%81s%*[^\n]",in_a);
		scanf("%81s%*[^\n]",in_b);

		flg=0;
		//chk a
		if(strlen(in_a)>80)flg=1;
		if(strlen(in_b)>80)flg=1;


		if(!flg){
			sprintf(str_a,"%81s",in_a);
			sprintf(str_b,"%81s",in_b);
//printf("in_a  %s\nstr_a  %s\nin_b  %s\nstr_b  %s\n",in_a,str_a,in_b,str_b);
//printf("in_a  %d\nstr_a  %d\nin_b  %d\nstr_b  %d\n",strlen(in_a),strlen(str_a),strlen(in_b),strlen(str_b));
			carry=0;
			for(j=80;j>0;j--){
				cs[0]=str_a[j];
				cs[1]='\0';
				a=atoi(cs);
				cs[0]=str_b[j];
				cs[1]='\0';
				b=atoi(cs);
				sprintf(cs,"%02d",a+b+carry);
				if(cs[0]=='0')carry=0;
				if(cs[0]=='1')carry=1;
				str_sum[j]=cs[1];
			}
			str_sum[0]='0';
			str_sum[81]='\0';
			if(carry){
				flg=1;
				str_sum[0]='1';
			}
			p=str_sum;
			while(*p=='0'&&p!=&str_sum[80])p++;
			//printf("%81s\n%81s\n%81s\n",str_a,str_b,str_sum);
		}
		flg?printf("overflow\n"):printf("%s\n",p);
	}

	return 0;
}

Measured memory_bytes: 1060
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

int main(){
	int n;
	cin >> n;
	int p[n];
	int inv[n];
	for(int i = 0; i < n; i++){
		cin >> p[i];
		p[i]--;
		inv[p[i]] = i;
	}
	int best = 0;
	int cur = 0;
	for(int j = 0; j < n; j++){
		if(j == 0 || inv[j] > inv[j-1]){
			cur++;
		} else {
			cur = 1;
		}
		best = max(best, cur);
	}
	cout << n - best << endl;
}


Measured memory_bytes: 1792