akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
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; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;


// 素因数分解(first要素がfactで、second要素がその個数)
vector<pair<ll, ll>> prime_factorize(ll n) {
    vector<pair<ll, ll>> res;
    for (ll p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}


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

    auto v = prime_factorize(n);
    int ans = 0;
    for(auto p: v){
        int c = 1;
        while(p.second-c >= 0){
            p.second -= c;
            c++;
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;
using ll = long long;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

int main()
{
	int n, m, i, j;
	string s, t;

	cin >> s >> t;
	n = s.length();
	m = t.length();

	for (i = n - m; i >= 0; i--) {
		if (s[i] == t[0] || s[i] == '?') {
			for (j = i + 1; j < i + m; j++) {
				if (s[j] != '?' && s[j] != t[j - i])break;
			}
			if (j == i + m) {
				for (j = 0; j < i; j++) {
					if (s[j] == '?') {
						cout << "a";
					}
					else {
						cout << s[j];
					}
				}
				cout << t;
				for (j = j + m; j < n; j++) {
					if (s[j] == '?') {
						cout << "a";
					}
					else {
						cout << s[j];
					}
				}
				cout << endl;
				return 0;
			}
		}
	}

	cout << "UNRESTORABLE" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	ll n; cin>>n;
	ll ans=1;
	ll k=3;
	while(true){
		if(ans+k>n)break;
		ans+=k;
		k+=2;
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 3616
#include<stdio.h>
#include<math.h>

struct Point{
  double x;
  double y;
};
void koch(int,struct Point,struct Point);
int main(){
  struct Point a,b;
  int n;
  scanf("%d",&n);
  a.x=0;
  a.y=0;
  b.x=100;
  b.y=0;
  printf("%.8f %.8f\n",a.x,a.y);
  koch(n,a,b);
  printf("%.8f %.8f\n",b.x,b.y);
  return 0;
}
void koch(int n,struct Point a,struct Point b){
  if(n==0)return;
  struct Point s,t,u;
  double th;
  th=M_PI*60/180;
  s.x=(2.0*a.x+1.0*b.x)/3;
  s.y=(2.0*a.y+1.0*b.y)/3;
  t.x=(1.0*a.x+2.0*b.x)/3;
  t.y=(1.0*a.y+2.0*b.y)/3;
  u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
  u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;
    koch(n-1,a,s);
  printf("%.8f %.8f\n",s.x,s.y);
  koch(n-1,s,u);
  printf("%.8f %.8f\n",u.x,u.y);
  koch(n-1,u,t);
  printf("%.8f %.8f\n",t.x,t.y);
   koch(n-1,t,b);
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std ;
void input(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("/home/yash/Desktop/CPP/input.txt","r",stdin);
    freopen("/home/yash/Desktop/CPP/output.txt","w",stdout);
    #endif
}
class activity{
  public : 
  int A,B,C;
};
int maxHappiness( vector<activity> arr , int n ) {
     int dp[n+1][3];
     dp[1][0] = arr[1].A;
     dp[1][1] = arr[1].B;
     dp[1][2] = arr[1].C;
     for(int i=2;i<=n;i++){
       dp[i][0] = arr[i].A + max( dp[i-1][1] , dp[i-1][2] ) ;
       dp[i][1] = arr[i].B + max( dp[i-1][0] , dp[i-1][2] ) ;
       dp[i][2] = arr[i].C + max( dp[i-1][0] , dp[i-1][1] ) ;
     }
     int ans = max( dp[n][0] , max( dp[n][1] , dp[n][2] ) ) ;
     return ans ;
}
int main(){
 // input();
  int n;
  cin>>n;
  vector<activity> arr(n+1);
  for(int i=1;i<=n;i++){
    cin>>arr[i].A;
    cin>>arr[i].B;
    cin>>arr[i].C;
  }
  int ans = maxHappiness( arr , n ) ;
  cout<<ans<<endl;
    
  return 0;
}

Measured memory_bytes: 3840
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
const int MAXN=1e5+10;
const ll MOD=10;
ll _gcd(ll a,ll b){if(b==0)return a;return _gcd(b,a%b);}
ll gcd(ll a,ll b){a=abs(a),b=abs(b);if(a<b)swap(a,b);return _gcd(a,b);}
ll qpow(ll a,ll n){ll rt=1;while(n){if(n&1)rt=(rt*a)%MOD;a=a*a%MOD;n>>=1;}return rt;}
ll factor[MAXN];
void cal_factor(){factor[0]=1;for(int u=1;u<MAXN;u++){factor[u]=(factor[u-1]*u)%MOD;}}
ll C(ll n,ll k){return factor[n]*qpow(factor[n-k],MOD-2)%MOD*qpow(factor[k],MOD-2)%MOD;}
int N;
int pos[MAXN];
void solve()
{
    scanf("%d",&N);
    ll sum=0;
    for(int u=1;u<=N;u++){
        ll t;
        scanf("%lld",&t);
        pos[t]++;
        sum+=t;
    }
    int Q;
    scanf("%d",&Q);
    while(Q--){
        int b,c;
        scanf("%d %d",&b,&c);
        int sz=pos[b];
        sum+=-(ll)b*sz+(ll)c*sz;
        printf("%lld\n",sum);
        pos[c]+=pos[b];
        pos[b]=0;
    }
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}

Measured memory_bytes: 4204
import itertools
n,m=map(int,input().split())
p=[[False]*n for i in range(n)]

for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    p[a][b]=True
    p[b][a]=True
ans=0
for i in itertools.permutations(range(1,n),n-1):
    list=[0]+[k for k in i]
    if all(p[list[j]][list[j+1]]==True for j in range(n-1)):
        ans+=1
print(ans)   


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
const ll INF = 10000000000000000;
const ll mod = 1000000007;
//printf("%.10f\n", n);
ll n, W; ll w[345678], v[345678], dp1[5000][23456], dp2[5000][23456];
void solve1() {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= W; j++) {
			if (i == 0) {
				if (j >= w[i]) { dp1[i][j] = v[i]; }
				continue;
			}
			if (j < w[i]) {
				dp1[i][j] = dp1[i - 1][j];
			}
			else {
				dp1[i][j] = max(dp1[i - 1][j], dp1[i - 1][j - w[i]] + v[i]);
			}
		}
	}
	return;
}
void solve2() {
	for (int i = n - 1; i >= 0; i--) {
		for (int j = 0; j <= W; j++) {
			if (j < w[i]) {
				dp2[i][j] = dp2[i + 1][j];
			}
			else {
				dp2[i][j] = max(dp2[i + 1][j], dp2[i + 1][j - w[i]] + v[i]);
			}
		}
	}
	return;
}
signed main() {
	ll m, a = 0, b = 0, cnt = 0, ans = 0; cin >> n >> W;
	for (int i = 0; i < n; i++) {
		cin >> w[i] >> v[i];
	}
	W--; solve1(); solve2();
	for (int h = 0; h < n; h++) {
		if (h == 0) { ans = max(dp2[1][W] + v[0], ans); continue; }
		if (h == n - 1) { ans = max(ans, dp1[n - 2][W] + v[n - 1]); continue; }
		for (int i = 0; i <= W; i++) {
			ans = max(ans, dp1[h - 1][i] + dp2[h + 1][W - i] + v[h]);
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
	int64_t N, M;
	cin >> N >> M;
	cout << abs((N - 2) * (M - 2));
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

あるマスi, jについて何回操作対象になるか考える
まず、左右について、自分が端でなければ3回、端なら2回操作対象になる
次に上下についても同様
よって、四隅の操作回数は4回、四端の操作回数は6回、その他の操作回数は9回
ただし幅が1ならば全部奇数、よって1を掛けることになる
ということで答えは|(N-2)(M-2)|
*/

Measured memory_bytes: 256
#include <stdio.h>
#include <queue>
using namespace std;

typedef long long int ll;
constexpr int kN = int(2E5 + 10), LOGN = 20, kInf = int(2E9 + 10);

int x[kN], nxtl[kN][LOGN], nxtr[kN][LOGN];
ll pl[kN][LOGN], pr[kN][LOGN];

int main() {
	int n, k, q, l, r, nl, nr;
	ll ans;
	queue<int> qu;
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++) scanf("%d", &x[i]);
	x[0] = -kInf, x[++n] = kInf;
	for (int i = 0; i <= n; i++) {
		while (!qu.empty()) {
			if (x[i] - x[qu.front()] >= k) {
				nxtl[qu.front()][0] = i;
				qu.pop();
			}
			else break;
		}
		qu.push(i);
	}
	while (!qu.empty()) {
		nxtl[qu.front()][0] = n;
		qu.pop();
	}

	for (int i = n; i >= 0; i--) {
		while (!qu.empty()) {
			if (x[qu.front()] - x[i] >= k) {
				nxtr[qu.front()][0] = i;
				qu.pop();
			}
			else break;
		}
		qu.push(i);
	}
	while (!qu.empty()) {
		nxtr[qu.front()][0] = 0;
		qu.pop();
	}

	for (int i = 1; i < LOGN; i++) for (int j = 0; j <= n; j++) nxtl[j][i] = nxtl[nxtl[j][i - 1]][i - 1];
	for (int i = 1; i < LOGN; i++) for (int j = 0; j <= n; j++) nxtr[j][i] = nxtr[nxtr[j][i - 1]][i - 1];
	for (int i = 0; i <= n; i++) pl[i][0] = nxtl[i][0];
	for (int i = 0; i <= n; i++) pr[i][0] = nxtr[i][0];
	for (int i = 0; i <= n; i++) if (pl[i][0] == n) pl[i][0] = 0;


	for (int i = 1; i < LOGN; i++) for (int j = 0; j <= n; j++) pl[j][i] = pl[j][i - 1] + pl[nxtl[j][i - 1]][i - 1];
	for (int i = 1; i < LOGN; i++) for (int j = 0; j <= n; j++) pr[j][i] = pr[j][i - 1] + pr[nxtr[j][i - 1]][i - 1];
	scanf("%d", &q);
	for (int i = 1; i <= q; i++) {
		scanf("%d%d", &l, &r);
		nl = l, nr = r;
		ans = r - l + 1;
		for (int j = LOGN - 1; j >= 0; j--) {
			if (nxtl[l][j] <= r) {
				ans -= pl[l][j];
				l = nxtl[l][j];
				ans += 1 << j;
			}
		}
		l = nl, r = nr;
		for (int j = LOGN - 1; j >= 0; j--) {
			if (nxtr[r][j] >= l) {
				ans += pr[r][j];
				r = nxtr[r][j];
			}
		}
		printf("%lld\n", ans);
	}
}


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

using namespace std;
using ll =long long;
using db = double;
using vll = vector<long long>;

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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(a) {SORT(a);(a).erase(unique((a).begin(),(a).end()),(a).end());}
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
#define debug(x)  cout << #x << " = " << (x) << endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
//グラフ用
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};	
//ここから書き始める

ll combination(ll n, ll i){
	ll count = 0;
	ll multi = 1;
	ll div =1;
	int limit = i;
	while(count < limit){
		multi *= n;
		n--;
		multi/= count+1;
		count ++ ;
	}
	return multi / div;
}

int main()
{
	cout <<setprecision(10);
	ll n ; 
	string s , t;
	cin >> n >> s >> t;
	int additional = n;

	int j = 0 ;
	for(int i = 0 ; i < n ; i ++){
		if(s[i] == t[j]){
			additional --;
			j++;
		}else{
			additional = n;
			j = 0;
			if(s[i] == t[j]){
				additional--;
				j++;
			}
		}
	}
	cout << n + additional << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define FORN(i, x, y) for (int i = x; i <= y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define scan1(X) scanf("%d", &X)
#define scan2(X, Y) scanf("%d%d", &X, &Y)
#define scan3(X, Y, Z) scanf("%d%d%d", &X, &Y, &Z)
#define scan4(X, Y, Z, W) scanf("%d%d%d%d", &X, &Y, &Z, &W)
#define scanl1(X) scanf("%lld", &X);
#define scanl2(X, Y) scanf("%lld%lld", &X, &Y)
#define scanl3(X, Y, Z) scanf("%lld%lld%lld", &X, &Y, &Z)
#define scanl4(X, Y, Z, W) scanf("%lld%lld%lld%lld", &X, &Y, &Z, &W)
#define print1(X) printf("%d\n", X);
#define print2(X, Y) printf("%d %d\n", X, Y);
#define print3(X, Y, Z) printf("%d %d %d\n", X, Y, Z);
#define print4(X, Y, Z, W) printf("%d %d %d %d\n", X, Y, Z, W);
#define printl1(X) printf("%lld\n", X);
#define printl2(X, Y) printf("%lld %lld\n", X, Y);
#define printl3(X, Y, Z) printf("%lld %lld %lld\n", X, Y, Z);
#define printl4(X, Y, Z, W) printf("%lld %lld %lld %lld\n", X, Y, Z, W);
#define max3(X, Y, Z) max(X, max(Y, Z))
#define max4(X, Y, Z, W) max(max(X, Y), max(Z, W))
#define min3(X, Y, Z) min(X, min(Y, Z))
#define min4(X, Y, Z, W) min(min(X, Y), min(Z, W))
#define popcount(X) __builtin_popcount(X)
#define all(x) x.begin(), x.end()
#define size(X) (int)X.size()
#define mp make_pair
#define pb push_back
#define fr first
#define sc second
#define lc(x) 2 * x
#define rc(x) 2 * x + 1
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<ld, ld> pldld;
const long long l_inf = numeric_limits<long long>::max();
const long long l_ninf = numeric_limits<long long>::min();
const int inf = numeric_limits<int>::max();
const int ninf = numeric_limits<int>::min();
const double pi = 1.00 * acos(-1.00);
const double eps = 1e-8;
void cio(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
ll gcd(ll a, ll b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return (a * (b / gcd(a, b))); }
int sq( int x ) {return x * x;}
////////////////////////////////////////////////////////////////////Header
const int maxn = 1e5 + 5;
int n;
int h[maxn];
int dp[maxn];

int main () {
    scan1(n);
    FORN(i, 1, n) scan1(h[i]);
    dp[1] = 0;
    dp[2] = abs(h[2] - h[1]);
    FORN(i, 3, n) {
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
    }
    print1(dp[n]);
}

Measured memory_bytes: 4560
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
const LL MOD = 1e9+7;
const int SIZE = 1e6+5;
const LL INF = 1LL<<60;
const double eps = 1e-4;
const double PI=3.1415926535897932;

int f[100009];

int main(){
	DRI(n);
	REP(i,n){
		DRI(x);f[x]++;
	}
	int evens=0,ans=0;
	REP(i,100009){
		ans+=(f[i]>0);
		if(f[i]&&f[i]%2==0){
			evens++;
		}
	}
	if(evens%2)printf("%d",ans-1);
	else printf("%d",ans);
}


Measured memory_bytes: 640
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

a = X()
b = X()
for i in range(len(a)):
    if a[i]==b[i]:
        cnt+=1

print(cnt)


Measured memory_bytes: 10348
fun main(args: Array<String>) {
    println(readLine()!!.foldIndexed(Pair(0, 0)) { index, acc, c ->
        if (index % 2 == 0) {
            if (c != '0') {
                Pair(acc.first + 1, acc.second)
            } else {
                Pair(acc.first, acc.second + 1)
            }
        } else {
            if (c != '1') {
                Pair(acc.first + 1, acc.second)

            } else {
                Pair(acc.first, acc.second + 1)
            }
        }
    }.toList().min())
}


Measured memory_bytes: 41668
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-ffloat-store")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define endl "\n"
#define f(i,a,b) for(int i=a;i<b;i++)
#define debug(val) printf("check%d\n",val)
#define all(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define mod 1000000007
#define inf  1e18
#define ps(x,y)   fixed<<setprecision(y)<<x
#define clr(val) memset(val,0,sizeof(val))
#define what_is(x) cerr << #x << " is " << x << endl;
#define inp(a,n) for(int i=0;i<n;i++) cin>>a[i];
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int maxn=2e5+10;
const int N = 2e3 + 10;
int main() 
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
    int n;
	cin>>n;
    int a[maxn],b[maxn];
	for (int i=1;i<=n;i++)
	{
		int x,y;
		cin>>x>>y;
		a[i]=x+y,b[i]=x-y;
	}
	sort(a+1,a+n+1);sort(b+1,b+n+1);
	cout<<max(a[n]-a[1],b[n]-b[1])<<endl;
return 0;   
}

Measured memory_bytes: 5172
n = int(input())
f = n // 4
s = n // 7

flag = False
for i in range(f + 1):
    for j in range(s + 1):
        total = i * 4 + j * 7
        if total == n:
            flag = True
            break

if flag:
    print('Yes')
else:
    print('No')

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

int main()
{
    long A,B,K;
    cin>>A>>B>>K;
    if(A-K>=0){
        cout << A-K <<" "<<B<<endl;
    }else{
        if(B-(K-A)>=0){
            cout <<0<<" "<<B-(K-A) <<endl;
        }else{
            cout <<0<<" "<<0<<endl;
        }
    }
}

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

int main() {
    int n, m;
    cin >> n >> m;
    pair<ll, int> p[n];
    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        p[i] = {a, b};
    }
    sort(p, p + n);

    ll ans = 0;
    rep(i, n) {
        if (m <= p[i].second)
            ans += m * p[i].first, m = 0;
        else
            ans += p[i].first * p[i].second, m -= p[i].second;

        if (m == 0) break;
    }

    cout << ans << endl;
    return 0;
}


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


#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'

int main()

{
    optimize();

    int n,l;
    vector<string> v;
    string s;
    cin>>n>>l;
    for(int i=0;i<n;i++)
    {
       cin>>s;
        v.push_back(s);
    }
    sort( v.begin(),v.end());
    for(string u:v )
        cout<<u;










    return 0;
}



Measured memory_bytes: 3652
from sys import stdin


def main() -> int:
    s = next_str()
    cnt = 0

    for i in range(len(s) // 2 - 1, 0, -1):
        if s[0:i] == s[i:i * 2]:
            cnt = i * 2
            break

    print(cnt)
    return 0


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

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

void fnInput(llong& rnNum)
{
  cin >> rnNum;
}

int fnDigitsCheck(int nDividend)
{
  int nDgtCnt = 1;

  while (nDividend /= 10)
    nDgtCnt++;

  return nDgtCnt;
}

int fnMultiplCheck(llong nNum)
{
  int nDivisor = sqrt(nNum);

  while (nNum % nDivisor)
    nDivisor--;

  int nDividend = nNum / nDivisor;
  return fnDigitsCheck(nDividend);  
}

int main()
{
  llong nNum;
  
  fnInput(nNum);
  cout << fnMultiplCheck(nNum) << endl;

  return 0;
}

Measured memory_bytes: 256
import collections
N=int(input())
A=list(map(int,input().split()))
l=[]
c=collections.Counter(A)
values=list(c.values())	#aのCollectionのvalue値のリスト(n_1こ、n_2こ…)
key=list(c.keys())	#先のvalue値に相当する要素のリスト(要素1,要素2,…)
for i in range(len(key)):
    l.append([key[i],values[i]])#lは[要素i,n_i]の情報を詰めたmatrix
#print(l)
n=len(l)
ans=0
cnt=0
d=dict(l)
#print(d)
ans=0
for i in range(31,0,-1):
    piv=pow(2,i)
    cnt=0
    for j in range(n):
        val1=d.get(l[j][0])
        val2=d.get(piv-l[j][0])
        if (val1!=None)and(val2!=None):
            add=min(val1,val2)
            if l[j][0]==piv-l[j][0]:
                add=(add//2)
                ans=ans+add
                add=add*2
            else:
                ans=ans+add
            d[l[j][0]]=val1-add
            d[piv-l[j][0]]=val2-add
        #print(d)
        #input()
    #ans=ans+(cnt-c[piv//2])//2
    #print(i,ans)
print(ans)

Measured memory_bytes: 126156
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}
int maze[50][50];
int ans;
void init(){
  rep(i,50)rep(j,50) maze[i][j] = 0;
  ans = 0;
}
int dx[8] = {1,1,0,-1,-1,-1,0,1};
int dy[8] = {0,1,1,1,0,-1,-1,-1};
void ume(int i,int j) {
  maze[i][j] = 0;
  rep(k,8) {
    int nx = i+dx[k];int ny = j+dy[k];
    if(isin(nx,0,50) and isin(ny,0,50) and maze[nx][ny]) ume(nx,ny);
  }
  return;
}
vi ansvec;
int main() {
  while(true){

  int w,h;
  cin >> w >> h;
  if(w==0 and h == 0) {
    for(auto v : ansvec) cout << v << endl;
    return 0;
  }
  init();
  rep(i,h) rep(j,w) cin >> maze[i][j];
  rep(i,h) rep(j,w) {
    if(maze[i][j] == 1) {
      ume(i,j);
      ans++;
    }
  }
  ansvec.eb(ans);
}
  return 0;
}



Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i;
    char s[5];

    for(i=0; i<3; i++)
    {
        cin>>s[i];
    }
    if(s[0]=='R'&&s[1]=='R'&&s[2]=='R')
    {
        cout<<"3"<<endl;
    }
    else if(s[0]=='R'&&s[1]=='R')
    {
        cout<<"2"<<endl;
    }
    else if(s[1]=='R'&&s[2]=='R')
    {
        cout<<"2"<<endl;
    }
    else if(s[0]=='R'||s[1]=='R'||s[2]=='R')
    {
        cout<<"1"<<endl;
    }
    else
    {
        cout<<"0"<<endl;
    }

    return 0;
}


Measured memory_bytes: 3620
#Combinationクラス
class Combination:
    '''
    計算量：階乗・逆元テーブルの作成O(N)
            nCkを求めるO(1)
    '''

    def __init__(self, n, MOD):
        self.fact = [1]
        for i in range(1, n + 1):
            self.fact.append(self.fact[-1] * i % MOD)
        self.inv_fact = [pow(self.fact[i] ,MOD - 2 ,MOD) for i in range(n + 1)]
        self.MOD = MOD

    def factorial(self, k):
        '''k!を求める'''
        return self.fact[k]

    def inverse_factorial(self, k):
        '''k!の逆元を求める'''
        return self.inv_fact[k]

    def combination(self, k, r):
        '''kCrを求める'''
        return (self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r]) % self.MOD

    def combination_2(self, k, r):
        '''kCrを求める'''
        res = 1
        for l in range(r):
            res *= (k - l)
            res %= self.MOD
        return (res * self.inv_fact[r]) % self.MOD


n, k = map(int, input().split())
MOD = 10**9 + 7
red_num = n - k
bule_num = k
comb = Combination(2001, MOD)
for i in range(1, k+1):
    if n-k+1 < i:
        print(0)
        continue
    ans = comb.combination(n-k+1, i)
    ans *= comb.combination(k-1, k-i)
    ans %= MOD
    print(ans)
    

Measured memory_bytes: 42736
my $N = glob <>;
my @a = map {$_ + 0} split(/\s+/o, <>);
my $t = 0;
$t += $_ for (@a);
$t /= $N;
$t = &myround($t);
my $c = 0;
$c += ($_ - $t)**2 for (@a);
print $c;
sub myround($){
  my $val = shift;
  my $tmp = int(abs($val) + 0.5);
  return $val >= 0 ? 0 + $tmp : 0 - $tmp;
}

Measured memory_bytes: 768
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

typedef long long ll;
const int mod=1e9+7;

int main(){
	int n, m, x;
	cin >> n >> m >> x;
	vector<int> a(n+1);
	for(int i=0; i<m; i++){
		int tmp;
		cin >> tmp;
		a[tmp]++;
	}
	vector<int> l(n+1), r(n+1);
	for(int i=n-1; i>=0; i--)
		l[i] = l[i+1]+a[i];
	for(int i=1; i<=n; i++)
		r[i] = r[i-1]+a[i];
	int ans;
	ans=min(l[0]-l[x], r[n]-r[x]);
	cout << ans << endl;
	return 0;
}

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

int main(){
  int  ad[26];
  string s;
  cin>>s;
  for(int i=0;i<26;i++){
    ad[i]=0;
  }
  for(int i=0;i<s.size();i++){
    ad[s[i]-'a']++;
  }
  bool at=false;
  for(int i=0;i<26;i++){
    if(ad[i]%2!=0){
      at=true;
      break;
    }
  }
  if(at) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}
      
      
  
      


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

int main(){
   int a,b;
   int d,r;
   double f;
   cin >> a  >>b;
   d = a/b;
   r = a % b;
   f = (double)a / b;
   
   cout << d << " " << r << "  ";
   cout << fixed << setprecision(5) << f << endl;
    
}

Measured memory_bytes: 1244
import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
    auto n = lread();
    auto a = aryread();
    auto a_so = a.sort();
    // writeln(a_so);
    long[long] ary;
    foreach (i; 0 .. n)
    {
        ary[a_so[i] - 1] = ary.get(a_so[i] - 1, 0) + 1;
        ary[a_so[i]] = ary.get(a_so[i], 0) + 1;
        ary[a_so[i] + 1] = ary.get(a_so[i] + 1, 0) + 1;

    }
    long ans = -1;
    foreach (key, value; ary)
    {
        // writeln(key, ':', value);
        ans = max(ans, value);
    }
    writeln(ans);
}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}

void arywrite(T)(T a)
{
    a.map!text.join(' ').writeln;
}


Measured memory_bytes: 8824
N,C = map(int, input().split())

xv = [tuple(map(int, input().split())) for _ in range(N)]


# 時計回りと反時計回りで得られるカロリーの累積和を取っておく
accum_clockwise = [None] * N
accum_clockwise[0] = xv[0]
tmp = xv[0][1]
for i in range(1,N):
    tmp += xv[i][1]
    accum_clockwise[i] = (xv[i][0], tmp)

accum_anticlockwise = [None] * N
accum_anticlockwise[0] = (C - xv[-1][0], xv[-1][1])
tmp = xv[-1][1]
for i in range(1, N):
    tmp += xv[N-1-i][1]
    accum_anticlockwise[i] = (C - xv[N-1-i][0], tmp)


# 時計回りと反時計回りについて、i個目まで食べに行って初期値に戻ってくるときに得られる、最高カロリーを記録しておく
# 反時計回りにx個まで食べに行ったとき（引き返さない方）、時計回りにはN-x個まで食べられるので、N-x番目のいずれかまで食べに行って戻った時の最高カロリーを事前に求めておいて、
# 反時計回りにそれぞれの寿司まで食べに行った時の点と合わせる（O(N^2)から前処理でO(N)に分解）
max_clockwise = [0] * (N+1)
for i in range(N):
    max_clockwise[i+1] = max(max_clockwise[i], accum_clockwise[i][1] - accum_clockwise[i][0] * 2)


max_anticlockwise = [0] * (N+1)
for i in range(N):
    max_anticlockwise[i+1] = max(max_anticlockwise[i], accum_anticlockwise[i][1] - accum_anticlockwise[i][0] * 2)



ans_clockwise = 0
for i in range(N):
    ans_clockwise = max(ans_clockwise, accum_clockwise[i][1] - accum_clockwise[i][0] + max_anticlockwise[N-1-i])

ans_anticlockwise = 0
for i in range(N):
    ans_anticlockwise = max(ans_anticlockwise, accum_anticlockwise[i][1] - accum_anticlockwise[i][0] + max_clockwise[N-1-i])

print(max(ans_clockwise, ans_anticlockwise))


Measured memory_bytes: 47136
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int tr[200010];
int lb(int pos){return pos & (-pos);}
void mdf(int pos,int wh){
	while(pos<=200000){
		tr[pos]+=wh;
		pos+=lb(pos);
	}
}
long long fnd(int pos){
	long long ret=0;
	while(pos){
		ret+=tr[pos];
		pos-=lb(pos);
	}
	return ret;
}
int N,A[100010];
int L,R,M;
int qzh[100010];
bool check(int md){
	for(int i=1;i<=N;i++)
		qzh[i]=qzh[i-1]+((A[i]<=md)?-1:1);
	long long tj=0;
	for(int i=0;i<=N;i++){
		tj+=fnd(qzh[i]);
		mdf(qzh[i],1);
	}
	for(int i=N;i+1;i--)	mdf(qzh[i],-1);
	if(tj*2>=(1ll*(N+1)*N)/2)	return true;
	return false;
}
int main(){
	scanf("%d",&N);
	qzh[0]=N+1;
	for(int i=1;i<=N;i++)	scanf("%d",&A[i]);
	L=0;R=1e9+10;
	while(L+1<R){
		M=(L+R)>>1;
		if(check(M))	L=M;
		else	R=M;
	}
	printf("%d\n",(!check(L))?L:R);
	return 0;
}

Measured memory_bytes: 1664
def find(target, list):
  for i in xrange(len(list)):
    if target == list[i]:
      return 1
  return 0


n = int(raw_input())
S = raw_input().split()
q = int(raw_input())
T = raw_input().split()
count = 0
for i in xrange(q):
  count += find(T[i], S)
print count

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

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

int R, C;
vector<string> G;
vector<string> H;

void traverse(int r, int c) {
	H[r][c] = '#';

	int cnt = 0;
	if (r+1 < R && G[r+1][c] == '#') {
		cnt++;
	}
	if (c+1 < C && G[r][c+1] == '#') {
		cnt++;
	}

	if (cnt != 1) {
		return;
	}
	if (r+1 < R && G[r+1][c] == '#') {
		traverse(r+1, c);
	}
	if (c+1 < C && G[r][c+1] == '#') {
		traverse(r, c+1);
	}
}

int main() {
	cin >> R >> C;
	REP(i, R) {
		string c;
		cin >> c;
		G.push_back(c);
		string c2;
		REP(j, C) {
			c2 += ".";
		}
		H.push_back(c2);
	}

	traverse(0, 0);
	cout << (G == H ? "Possible" : "Impossible") << endl;
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int32 n,m;
vector<int32> g[(int32)1e5];

int32 color[(int32)1e5];

bool bipartite(int32 v, int32 c){
    color[v] = c;
    REP(i,g[v].size()){
        if(color[g[v][i]] == c)return false;
        if(color[g[v][i]] == 0 && !bipartite(g[v][i], -c))return false;
    }
    return true;
}

int main()
{
    cin >> n >> m;
    REP(i,m){
        int32 a,b;
        cin >> a >> b;
        a--;b--;
        g[a].pb(b);
        g[b].pb(a);
    }
    if(bipartite(0, 1)){
        int32 cnt = 0;
        REP(i,n)
            if(color[i] == 1)cnt++;
        ANS(cnt * (n - cnt) - m);
    }else{
        ANS(n * (n-1) / 2 - m);
    }
    return 0;
}

Measured memory_bytes: 7424
k, n = map(int, input().split())
a = list(map(int, input().split()))
x = 0
ans = 0
for i in range(n - 1):
    ans += a[i + 1] - a[i]
    x = max(x, a[i + 1] - a[i])
ans += k - a[-1] + a[0]
x = max(x, k - a[-1] + a[0])
print(ans - x)


Measured memory_bytes: 25840
#include <stdio.h>

int main()
{
    int cat, dog, x;
    scanf("%d%d%d", &cat, &dog, &x);
    if(cat + dog >= x){
        if(cat <= x){
            printf("YES\n");
        }
        else printf("NO\n");
    }
    else printf("NO\n");
    return 0;
}

Measured memory_bytes: 128
def S(i):
    ans = 0
    while i // 10 > 0:
        ans += i % 10
        i //= 10
    ans += i
    return ans

K = int(input())
count, N = 0, 1
while count < K:
    N2, Nd = N, 1
    while N2//10 > 0:
        Nd += 1
        N2 //= 10
    minX, X = N/S(N), N
    for i in range(Nd+2):
        x = (N//10**(i+1) + 1) * 10**(i+1) -1
        if minX > x/S(x):
            minX, X = x/S(x), x
    print(X)
    count += 1
    N = X+1

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a,a+n);
  int sum=0;
  for(int i=0;i<k;i++){
    sum+=a[i];
  }
  cout<<sum;
  return 0;
}
  

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

using namespace std;
typedef long long ll;
ll a[200010],b[200010];
vector<ll> v;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll i,j,n,ans = 0,k = 1;
    cin >> n;
    for(i=0;i<n;i++) cin >> a[i];
    for(i=0;i<n;i++) cin >> b[i];
    for(i=0;i<29;i++){
        k *= 2;
        ll sum = 0;
        v.clear();
        for(j=0;j<n;j++) v.push_back(b[j]%k);
        sort(v.begin(),v.end());
        for(j=0;j<n;j++){
            ll x = a[j]%k;
            if(x<k/2) sum += (upper_bound(v.begin(),v.end(),k-1-x) - lower_bound(v.begin(),v.end(),k/2 - x));
            if(x>=k/2) sum += n - (lower_bound(v.begin(),v.end(),k/2*3-x) - v.begin()) + (upper_bound(v.begin(),v.end(),k-1-x) - v.begin());
        }
        if(sum&1) ans += k/2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5876
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

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

  int h = 0,t = S.size()-1,ans = 0;
  while(1) {
    if(S.at(h) != 'x' && S.at(t) != 'x' && S.at(h) != S.at(t)) {
      cout << -1 << endl;
      return 0;
    }else if(S.at(h) == S.at(t)) {
      h++; t--;
    }else if(S.at(h) == 'x' && S.at(t) != 'x') {
      ans++; h++;
    }else if(S.at(h) != 'x' && S.at(t) == 'x') {
      ans++; t--;
    }

    if(t-h <= 0) break;
  }

  cout << ans << endl;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
#define sz 100002
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define P push
#define VEC(n) ll int x; vector<ll int>v;for(int i=0;i<n;i++){cin>>x;v.pb(x);}
#define TEST() int test;cin>>test; while(test--)
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
//https://codeforces.com/contest/1215/problem/A
//ll int LCM(ll int a,ll int b) { ll int gcd=__gcd(a,b);ll int lcm=a*b/gcd;return lcm;}
//ll int bigmod(ll int b, ll int p, ll int m){if(p==0)return 1;if(p%2!=0) return b%m*fun(b,p-1,m)%m;if(p%2==0){ ll int res=fun(b,p/2,m);return (res%m*res%m)%m;}}
//void seive() { prime[np++]=2;for(i=3; i<=sz; i+=2){if(mark[i]==0){ prime[np++]=i;for(j=i*i; j<=sz; j+=i) mark[j]=1; } }}
//string add(string s1,string s2) {string s;int j=s1.size()-1,c=0,m; for(int i=s2.size()-1; i>=0; i--) {if(j>=0)m=s2[i]-'0'+s1[j]-'0'+c;else m=s2[i]-'0'+c; if(m>9) { s+=m%10+'0';c=m/10; } else {  c=0;s+=m+'0'; }j--; } if(c!=0) {s+=c+'0'; }reverse(s.begin(),s.end());return s;}
//int pos;string mul(int n) {string s;for(int i=0; i<pos; i++) { s+="0"; }pos++;int c=0,m; for(int i=s1.size()-1; i>=0; i--) { m=(s1[i]-'0')*n+c;if(m>9) { s+=m%10+'0';c=m/10;} else { c=0; s+=m+'0';} }while(c!=0) { s+=c%10+'0';c=c/10;}    reverse(s.begin(),s.end());return s;}


int main()
{
    int n,x,i,cnt=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        if(i%2&&x%2)cnt++;
    }
    cout<<cnt<<endl;
}




Measured memory_bytes: 3588
def BFS(Bs,del_idx,result):
    if Bs==[1]:
        return result
    
    if del_idx!=None:
        del Bs[del_idx]


    for i,b in enumerate(Bs):
        if b>i+1:
            return None
        
    for i,b in enumerate(Bs):
        if i+1==b:
            DBs=Bs.copy()
            result.append(i+1)
            out=BFS(DBs,i,result)
            if out:
                return out
            else:
                del result[-1]

    return None


def Solve():
    output=[]
    N=int(input())
    Bs=[int(x) for x in input().split()]
    return BFS(Bs,None,[])
        

        
result=Solve()
if result:
    result.reverse()
    for r in result:
        print(r)
else:
    print(-1)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) REP(i,0,n)
#define REP(i,l,r) for(int i=l;i<r;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int gcd(int a,int b){
    if(a%b==0)return b;
    else return gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
struct edge{
    int to,cost;
};
class dijkstra{
    int V;
    int d[100002];
    priority_queue<P,vector<P>,greater<P>>que;
    void update(int s,vector<edge> G[]){
        fill(d,d+V+1,100000000000ll);
        d[s]=0;
        que.push(make_pair(0,s));
        while(!que.empty()){
            P p=que.top();
            que.pop();
            int v=p.second;
            if(d[v]<p.first)continue;
            rep(i,G[v].size()){
                edge e=G[v][i];
                if(d[e.to]>d[v]+e.cost){
                    d[e.to]=d[v]+e.cost;
                    que.push(make_pair(d[e.to],e.to));
                }
            }
        }
    }
public:
    dijkstra(int v,int s,vector<edge> G[]){
        V=v;
        update(s,G);
    }
    int find(int e){
        return d[e];
;    }
};
ll dp[123][123456];
signed main(){
    int N,W;
    cin>>N>>W;
    REP(i,1,N+1){
        int w,v;
        cin>>w>>v;
        rep(j,W+1){
            if(j<w) dp[i][j]=dp[i-1][j];
            else dp[i][j]=max(dp[i-1][j],dp[i-1][j-w]+v);
        }
    }
    cout<<dp[N][W]<<endl;
}



Measured memory_bytes: 97408
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main
{
    public static void process()throws IOException
    {
        int n = ni();
        HashMap<String, Integer> map = new HashMap<>();

        map.put("AC", 0);
        map.put("TLE", 0);
        map.put("WA", 0);
        map.put("RE", 0);

        for(int i = 1; i <= n; i++){
            String s = nln();
            map.put(s, map.get(s) +1);
        }

        pn("AC x "+map.get("AC"));
        pn("WA x "+map.get("WA"));
        pn("TLE x "+map.get("TLE"));
        pn("RE x "+map.get("RE"));
    }
 
    static final long mod=(long)1e9+7l;

    static FastReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        out = new PrintWriter(System.out);
        sc=new FastReader();
 
        long s = System.currentTimeMillis();
        int t=1;
        //t=ni();
        while(t-->0)
            process();
 
        out.flush();
        System.err.println(System.currentTimeMillis()-s+"ms");
    }
    
    static void pn(Object o){out.println(o);}
    static void p(Object o){out.print(o);}
    static int ni()throws IOException{return Integer.parseInt(sc.next());}
    static long nl()throws IOException{return Long.parseLong(sc.next());}
    static double nd()throws IOException{return Double.parseDouble(sc.next());}
    static String nln()throws IOException{return sc.nextLine();}
    static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
    
    static class FastReader{ 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader(){ 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next(){ 
            while (st == null || !st.hasMoreElements()){ 
                try{ st = new StringTokenizer(br.readLine()); } catch (IOException  e){ e.printStackTrace(); } 
            } 
            return st.nextToken(); 
        } 
  
        String nextLine(){ 
            String str = ""; 
            try{ str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } 
            return str; 
        } 
    } 
}

Measured memory_bytes: 45148
import java.util.*;
//import java.util.stream.Collectors;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		int x = Integer.parseInt(sc.next());
		Integer[] a = new Integer[m];
		Arrays.setAll(a, i -> Integer.parseInt(sc.next()));
		List<Integer> list = new ArrayList<>(Arrays.asList(a));
		int countMinus = 0, countPlus = 0;
		for(int i=x; i!=0; i--){
			if(list.contains(i)){
				countMinus++;
			}
		}
		for(int i=x; i!=n; i++){
			if(list.contains(i)){
				countPlus++;
			}
		}
		System.out.println(countPlus < countMinus ? countPlus : countMinus);
	}
}


Measured memory_bytes: 35688
#include <bits/stdc++.h>
#define pb push_back
#define sz(a) (int)(a).size()

using namespace std;

typedef struct Node {
	Node(): white(1), black(1) {}
	int white;
	int black;
	vector <int> adj;
}node;

int N, M = 1e9 + 7;
vector <node> T;

void dfs (int x, int p) {
	for (int i=0; i<sz(T[x].adj); ++i) {
		if (T[x].adj[i] != p) {
			dfs(T[x].adj[i], x);
			T[x].white = (1LL * T[x].white * (T[T[x].adj[i]].white + T[T[x].adj[i]].black)) % M;
			T[x].black = (1LL * T[x].black * T[T[x].adj[i]].white) % M;
		}
	}
}

int main ()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> N;
	node temp;
	T.assign(N + 1, temp);
	for (int i=0, x, y; i<N-1; ++i) {
		cin >> x >> y;
		T[x].adj.pb(y);
		T[y].adj.pb(x);
	}
	dfs(1, 0);
	int ans = (T[1].white + T[1].black) % M;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 10752
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
ll ans;
int main()
{
	int n,l,r;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d%d",&l,&r);
		ans+=(r-l)+1;
	}
	printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    vector<int> A(5);
    for(int i = 0; i < 5; i++) cin >> A[i];
    int C,Cmin;
    C = Cmin = 99999;
    int I = 0;
    for(int i = 0; i < 5; i++){
        C = A[i] % 10;
        if(C != 0) Cmin = min(C,Cmin);
        if(Cmin == C) I = i;
    }
    int S = 0;
    for(int i = 0; i < 5; i++){
        if(i == I) S += A[i];
        else if(A[i]%10 == 0)  S += A[i];
        else S += A[i]/10*10 + 10;
    }
    cout << S << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String [] sArray = s.split("");
		int len = sArray.length;
		boolean judge = true;
		int Ccount = 0;
		if(sArray[0].equals("A"));//1文字目の”A”判定
		else judge = false;
		if(sArray[1].equals(sArray[1].toUpperCase())) judge = false;//２文字目の(大小)判定
		for(int i = 2; i <= len - 2; i++) {//3文字目と末尾から2文字目の間
			if(sArray[i].equals("C")) Ccount++;//”C”カウント
			else if(sArray[i] == sArray[i].toUpperCase()) judge = false;//(大小)判定
		}
		if(Ccount != 1) judge = false;//”C”の数判定
		if(sArray[len - 1].equals(sArray[len - 1].toUpperCase())) judge = false;//末尾文字の(大小)判定
		
		if(judge) System.out.println("AC");//結果出力
		else System.out.println("WA");
		
		sc.close();
	}
}


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

int main()
{
    string s;
    bool a=false,b=false;

    cin>>s;

    for(int i=0;i<3;i++){
        if(s[i]=='A')a=true;
        else if(s[i]=='B')b=true;
    }

    if(a && b)cout<<"Yes";
    else cout<<"No";
    return 0;
}


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

typedef long long ll;
 
int main(){
  int n;
  ll h;
  cin >> n >> h;
  ll a[n], b[n];
  ll ma = 0;
  for(int i=0; i<n; i++){
    cin >> a[i] >> b[i];
    ma = max(a[i], ma);
  }
  sort(b, b+n, greater<int>());
  ll ans = 0;
  for(int i=0; i<n; i++){
    if(b[i]>ma){
      ans++;
      h -= b[i];
    }
    if(h<=0){
      cout << ans << endl;
      return 0;
    }
  }
  ans += h/ma;
  if(h%ma!=0) ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  //input
  int N, M;
  cin >> N >> M;
  vector <int> cnt(M);
  /*
  vector< vector<int> > A (30, vector<int>(30) );
  rep(i,N){
    cin >> K[i];
    rep(j,K[i]){
      cin >> A[i][j];
    }
  }
  */
  rep(i,N){
    int K;
    cin >> K;
    rep(j,K){
      int  A;
      cin >> A;
      A--;
      cnt[A] ++;
    }
  }

  //solve
  int ans = 0;
  rep(i,M){
    if (cnt[i] ==  N) ans ++;
  }

  //output
  cout << ans << endl;
}


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

int main(){
  int n,t0=0,x0=0,y0=0,t1,x1,y1,dif=0,dif_t=0;cin>>n;

  for(int i=0;i<n;++i){
    cin>>t1>>x1>>y1;
    dif=abs(x0-x1)+abs(y0-y1);
    dif_t=t1-t0;
    if((dif%2!=dif_t%2)||dif>dif_t){
      cout<<"No"<<endl;
      return 0;
    }
    t1=t0;
    x1=x0;
    y1=y0;
  }cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n;
  cin >> n;

  rep1(i,9){
    if(n%i==0){
      if(n/i<=9){
	cout << "Yes" << "\n";
	return 0;
      }
    }
  }

  cout << "No" << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
#include <cassert>
#include <vector>
#include <array>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <numeric>
#define ALL(c) (c).begin(), (c).end()

using namespace std;
using ll = long long;
using pli = pair<ll, int>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdi = pair<double, int>;
using pdd = pair<double, double>;

int main() {
	int N;
	cin >> N;
	if (N % 2 == 0) {
		cout << N * (N - 1) / 2 - N / 2 << endl;
		for (int i = 1; i <= N; i++)
		{
			for (int j = i + 1; j <= N; j++)
			{
				if (i + j != N + 1)
					cout << i << " " << j << endl;
			}
		}
	}
	else {
		cout << N * (N - 1) / 2 - (N - 1) / 2 << endl;
		for (int i = 1; i <= N; i++)
		{
			for (int j = i + 1; j <= N; j++)
			{
				if (i + j != N)
					cout << i << " " << j << endl;
			}
		}
	}
	return 0;
}

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

n = int(input())
amari = []
alpha = 'abcdefghijklmnopqrstuvwxyz'

while True:
    if (n-1) < 26:
        amari.insert(0, alpha[n-1])
        break
    else:
        ama = (n-1) % 26
        amari.insert(0, alpha[ama])
        n = (n -1)//26

print("".join(amari))

Measured memory_bytes: 9164
#include <stdio.h>

int main(void)
{
    int n, i,  min, max;
    long long sum = 0;
    scanf("%d", &n);
    int a[n];
    for(i = 0; i < n; i++){
        scanf("%d", &a[i]);
        sum += a[i];
    }
    
    min = max = a[0];
    for(i = 0; i < n; i++){
        if(min > a[i] ){
            min = a[i];
        }
        if(max < a[i]){
            max = a[i];
        }
    }

    printf("%d %d %lld\n", min, max, sum);

    return 0;
}


Measured memory_bytes: 2108