akhauriyash/Code-Regression huggingface dataset:
import itertools
num = int(input())
p = [int(i) for i in input().split()]
q = [int(i) for i in input().split()]

lista=[]

for i in range(1,num+1): lista.append(i)

tudo=list(itertools.permutations(lista))

a,b,cont=0,0,0

for i in tudo:
    if list(i) == p: a=cont
    if list(i) == q: b=cont
    cont+=1
print(abs(a-b))


Measured memory_bytes: 8052
import sys
sys.setrecursionlimit(1000000)
from math import factorial, ceil, floor
from bisect import bisect_right as bsr
from operator import itemgetter as ig
from collections import defaultdict as dd
from collections import deque, Counter as cnt

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)
def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]
def nlist(n, v):
    if not n: return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]

# エントリーポイント
def main():
    N, M = input(int, int)
    ABC = input([[int, 3], M])

    # Nから到達できる辺のみ抽出する
    g = nlist([N + 1], [])
    for a, b, c in ABC:
        g[b] += [(a, c)]

    que, arl, rch = [N], [False] * (N + 1), {N}
    while que:
        cur = que.pop()
        if arl[cur]: continue
        arl[cur] = True
        for nxt, _ in g[cur]:
            if arl[nxt]: continue
            rch |= {nxt}
            que.append(nxt)
    edges = [(a, b, c) for a, b, c in ABC if a in rch and b in rch]

    # ベルマンフォード法で負の最短経路(スコアの最大値)を導出する
    g = nlist([N + 1], INF)
    g[1] = 0
    for _ in range(N):
        f = True
        for a, b, c in edges:
            c = -c
            if g[a] + c < g[b]:
                g[b] = g[a] + c
                f = False
        if f:
            break
    else:
        # 負の閉路を除外する
        print("inf")
        return
    print(-g[N])
    return

if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()


Measured memory_bytes: 4596
import sys
import fractions
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

K=int(input())
ksum=0
gcbmap=[[0]*200 for i in range(200)]
for i in range(1,201):
    for j in range(1,201):
        gcbmap[i-1][j-1]=fractions.gcd(i,j)

tmp=0
for i in range(1,K+1):
    for j in range(1,K+1):
        tmp=gcbmap[i-1][j-1]
        for k in range(1,K+1):
            ksum+=gcbmap[tmp-1][k-1]

print(ksum)


Measured memory_bytes: 10996
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    int n; cin>>n;
    cout<<"ABC"<<n<<endl;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n; cin >> n;
	map<int,int> f;
	for(int i = 2; i <= n; i++){
		int x = i;
		for(int j = 2; j <= x; j++) if(x % j == 0){
			int c = 0;
			for(; x % j == 0; x /= j) c++;
			f[j] += c;
		}
	}
	//dbg(f);
	vector<vector<ll>> dp(f.size() + 1, vector<ll>(80));
	dp[0][1] = 1;
	int cur = 0;
	for(auto i : f){
		rep(j, 80) if(dp[cur][j]) rep(k, i.second + 1){
			if(j * (k + 1) < 80)
			dp[cur + 1][j * (k + 1)] += dp[cur][j];
		}
		cur++;
	}
	cout << dp[cur][75] << endl;
	return 0;
}

Measured memory_bytes: 256
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	#a = int(input())
	h, w = tin()
	#s = input()
	al = [lin() for _ in range(h)]
	dl = [[abs(a-b) for a,b in zip(all, lin())] for all in al]
	pp = [[set() for _ in range(w)] for _ in range(h)]
	pp[0][0].add(dl[0][0])
	for wi in range(1, w):
		ss = pp[0][wi]
		d = dl[0][wi]
		for v in pp[0][wi-1]:
			ss.add(v+d)
			ss.add(abs(v-d))
	
			
	for hi in range(1, h):
		ss = pp[hi][0]
		gap = dl[hi][0]
		for v in pp[hi-1][0]:
			ss.add(v+gap)
			ss.add(abs(v-gap))
		
		for wi in range(1, w):
			ss = pp[hi][wi]
			gap = dl[hi][wi]
			for v in pp[hi][wi-1]:
				ss.add(v+gap)
				ss.add(abs(v-gap))
			
			for v in pp[hi-1][wi]:
				ss.add(v+gap)
				ss.add(abs(v-gap))
			
	#for hi in range(h):
	#	for wi in range(w):
	#		print(hi,wi,pp[hi][wi])
			
	ret = min(pp[-1][-1])
	print(ret)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 545400
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a + b >= c){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }


    return 0;
}

Measured memory_bytes: 3604
import math
X = Y = a = 0
while True:
	x,y = map(int,input().split(','))
	if x == y == 0:
		break
	r = a * math.pi / 180
	X += x*math.sin(r)
	Y += x*math.cos(r)
	a+=y
print(*map(int,(X,Y)),sep='\n')


Measured memory_bytes: 5716
N, K = map(int, input().split())
A = list(map(int, input().split()))

pos = []
neg = []
zero = 0
for a in A:
    if a > 0:
        pos.append(a)
    elif a == 0:
        zero += 1
    else:
        neg.append(a)
        
len_pos = len(pos)
len_neg = len(neg)

cnt_pos = len_pos * (len_pos - 1) // 2 + len_neg * (len_neg - 1) // 2
cnt_neg = len_pos * len_neg
cnt_zero = zero * (zero - 1) // 2 + zero * (len_pos + len_neg)
#print(cnt_pos, cnt_neg, cnt_zero, cnt_pos + cnt_neg + cnt_zero, N * (N - 1) // 2)

if K <= cnt_neg:
    pos.sort()
    neg.sort()
    ok = 10 ** 19
    ng = -10 ** 19
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        pos_i, neg_i = len_pos - 1, len_neg - 1
        cnt = 0
        while pos_i >= 0 and neg_i >= 0:
            if pos[pos_i] * neg[neg_i] <= mid:
                cnt += neg_i + 1
                pos_i -= 1
            else:
                if neg_i:
                    neg_i -= 1
                else:
                    pos_i -= 1
        if cnt >= K:
            ok = mid
        else:
            ng = mid
    print(ok)

elif K <= cnt_neg + cnt_zero:
    print(0)
    
else:
    K -= cnt_neg + cnt_zero
    pos.sort()
    neg = [abs(n) for n in neg]
    neg.sort()

    ok = 10 ** 19
    ng = -10 ** 19
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        left, right = 0, len_pos - 1
        cnt = 0
        while left <= len_pos - 1 and right >= 0:
            if pos[left] * pos[right] <= mid:
                cnt += right + 1
                if left <= right:
                    cnt -= 1
                left += 1
            else:
                if right:
                    right -= 1
                else:
                    left += 1

        left, right = 0, len_neg - 1
        while left <= len_neg - 1 and right >= 0:
            if neg[left] * neg[right] <= mid:
                cnt += right + 1
                if left <= right:
                    cnt -= 1
                left += 1
            else:
                if right:
                    right -= 1
                else:
                    left += 1
        cnt //= 2
        
        if cnt >= K:
            ok = mid
        else:
            ng = mid
    print(ok)

Measured memory_bytes: 99028
def cin; gets.split.map(&:to_i) end
def cout(*x); puts x.join(" ") end

# exit if $0 != __FILE__

require 'set'

n, m = cin

k1, *a1 = cin
s = Set.new(a1)
(n-1).times do
  k, *a = cin
  s &= Set.new(a)
end

puts s.length


Measured memory_bytes: 2044
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

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

  string ans="";
  for(int i=0;i<N;i++){
    ans+=S[i];
    ans+=T[i];
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
using namespace std;

typedef long long ll;
vector<vector< int >> G;

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

    G.assign(N, vector<int>());

    int x, y;
    for(int i = 0; i < N-1; i++) {
        cin >> x >> y;
        x--, y--;
        G[x].push_back(y);
        G[y].push_back(x);
    }

    queue<int> q1, q2, tmp;

    q1.push(0);
    q2.push(N-1);

    vector<bool> used(N, false);

    int fen = 0, snu = 0;

    bool turn = true;
    while(true) {
        if(fen + snu == N) {
            break;
        }
        if(turn) {
            while(!q1.empty()) {
                fen++;
                int v = q1.front();
                used[v] = true;
                q1.pop();

                for(int u : G[v]) {
                    if(used[u]) continue;
                    used[u] = true;
                    tmp.push(u);
                } 
            }
            while(!tmp.empty()) {
                q1.push(tmp.front());
                tmp.pop();
            }
        } else {
            while(!q2.empty()) {
                snu++;
                int v = q2.front();
                used[v] = true;
                q2.pop();

                for(int u : G[v]) {
                    if(used[u]) continue;
                    used[u] = true;
                    tmp.push(u);
                } 
            }
            while(!tmp.empty()) {
                q2.push(tmp.front());
                tmp.pop();
            }

        }

        turn = !turn;
    }

    fen--, snu--;

    if(fen > snu) {
        cout << "Fennec" << endl;
    } else {
        cout << "Snuke" << endl; 
    }
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
ll t,A,B,C,D,bisa;
ll fpb(ll aa,ll bb)
{
	if(bb==0)
		return aa;
	else
		return fpb(bb,aa%bb);
}
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>t;
	while(t--)
	{
		cin>>A>>B>>C>>D;
		bisa=1;
		if(A-B<0)
			bisa=0;
		else
		if(D<B)
			bisa=0;
		else
		if(C<=B)
		{
			ll halo=(A%B+(B-C))%B;
			ll hai=fpb(B,D);
			ll lagi=halo%hai;
			if(lagi==0)	lagi+=hai;
			//cout<<halo<<" "<<hai<<" "<<lagi<<"\n";
			if(lagi+C>=B)
				bisa=1;
			else
				bisa=0;
		}
		if(bisa)
			cout<<"Yes\n";
		else
			cout<<"No\n";
		//cout<<bisa<<"\n";
	}
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(void) {
 
  int a,b,c;
  
  scanf("%d %d", &a, &b);
  c = a*b;
  
  if(c % 2 == 0){
   printf("Even");    
  }else{
   printf("Odd");
  }
  
  return 0;
}

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

int main(void){
  string a,b,c;
  cin>>a>>b>>c;
  if((a.at(a.size()-1)==b.at(0))&&(b.at(b.size()-1)==c.at(0)))
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;
int main(){
  vector<int> vec;
  int ii;
  int max,min,middle;
  int num1,num2;
  vec.resize(3);

  for(ii=0;ii<3;ii++){
	cin >> vec[ii];
  }

  sort(vec.begin(),vec.end());

  min = vec[0];
  middle = vec[1];
  max = vec[2];
  num1 = (max-min)/2;
  num2 = (max-middle)/2;
  


  vec[0] = min + num1 * 2;
  vec[1] = middle + num2 * 2;

  sort(vec.begin(),vec.end());

  //1.全部同じ
  if(vec[0] == vec[1] && vec[1] == vec[2]){
	cout << (num1+num2) << endl;
  }
  //2.1つだけ、1違い
  else if(vec[2] == vec[1]){
	cout << (num1+num2+2) << endl;
  }
  
  //3.2つ、1違い
  else{
	cout << (num1+num2+1) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
function Main(input) {
    input = input.trim().split(" ");
    const d = input[0];
    const t = input[1];
    const s = input[2];

    const arriveTime = d / s;
    if(arriveTime <= t) {
        console.log("Yes");
    } else {
        console.log("No");
    }
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main()
{
    int N;
    cin >> N;
    string S;
    map<string ,int> mp;
    for (int i = 0; i < N; i++) {
        cin >> S;
        mp[S];
    }

    cout << mp.size() << endl;
    return 0;
}

Measured memory_bytes: 19208
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int n,h,max_h=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>h;
        if(i && max_h-h>1){
            cout<<"No"<<endl;
            return 0;
        }
        max_h=max(max_h,h);
    }
    cout<<"Yes"<<endl;
    return 0;
}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
ll x[125252];
int m;
ll k;
int a[125252];

vi mul(vi &a,vi &b){
  vi ret(n-1);
  REP(i,n-1)ret[i] = a[b[i]];
  return ret;
}

int main(){
  scanf("%d",&n);
  REP(i,n)scanf("%lld",x+i);
  scanf("%d%lld",&m,&k);
  REP(i,m)scanf("%d",a+i);

  vi I(n-1);
  REP(i,n-1)I[i]=i;
  vi U = I;
  REP(i,m){
    swap(U[a[i]-2],U[a[i]-1]);
  }
  vi A = I;
  while(k){
    if(k&1)A=mul(A,U);
    U=mul(U,U);
    k>>=1;
  }
  ll y = x[0];
  REP(i,n){
    printf("%lld\n",y);
    if(i==n-1)break;
    int k = A[i];
    y += x[k+1]-x[k];
  }

  return 0;
}


Measured memory_bytes: 3944
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] cnt = new int[100001];
		for(int i=0;i<n;i++){
			int a = sc.nextInt();
			cnt[a]++;
		}
		
		long c = 0;
		for(int i=0;i<cnt.length;i++){
			if(cnt[i]>1)
				c+=cnt[i]-1;
		}
		
		if(c%2!=0)
			c++;
		
		System.out.println(n-c);
	}
}


Measured memory_bytes: 50764
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

/* キューに要素xを追加 */
void enqueue(P x){
	Q[tail] = x;
	tail = (tail + 1)% LEN;
}

/* キューの先から要素を取り出す */
P dequeue(){
	P x = Q[head];
	head = (head + 1)% LEN;
	return x;
}


int main(){
	int elaps = 0, c;
	int i, q;
	P u;
	
	scanf("%d %d", &n, &q);
	
	for ( i = 1; i <= n; i++){
    	scanf("%s", Q[i].name);
    	scanf("%d", &Q[i].t);
	}
	head = 1;
	tail = n+1;

	while(tail != head)
	{
		u = dequeue();
		
		if(u.t > q)
		{
			u.t = u.t - q;
			enqueue(u);
			elaps = elaps + q;
//			enqueue(u);
		}
		else
		{
			elaps = elaps + u.t;
			printf("%s %d\n", u.name, elaps);
		}
	}
	return 0;
}


Measured memory_bytes: 11884
using DataStructures
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n::Int,m::Int=parseMap(split(readline()))
    road::Vector{Vector{Int}}=[[] for i in 1:n]
    dis::Vector{Int}=[8589934592 for i in 1:n]
    dis[1]=0
    for i in 1:m
        a,b=parseMap(split(readline()))
        push!(road[a],b)
        push!(road[b],a)
    end
    arr=Deque{Int}()
    push!(arr,1)
    while !isempty(arr)
        a=popfirst!(arr)
        for b in road[a]
            if dis[b]>dis[a]+1
                dis[b]=dis[a]+1
                push!(arr,b)
            end
        end
    end
    println("Yes")
    ans=[0 for i in 1:n]
    for i in n:-1:1
        ans[dis[i]+1]=i
    end
    for i in 2:n
        println(ans[dis[i]])
    end
end
main()

Measured memory_bytes: 251164
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
  int D;
  cin >> D;
  if (D==25) {
cout << "Christmas" << endl;
  }
else {
string S;
  repl(i,D,25) {

    S +=" Eve";
  }
  cout << "Christmas" +S << endl;
}
}
  
  

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * @author kawakami
 *
 */
class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner as = new Scanner(System.in);
		StringBuffer sb = new StringBuffer();
		
		int x = 0;
		int n = 0;
		int i = 0;
		int j = 0;
		int p = 0;
		int r = 0;
		int tre = 0;
		
		int A[];
		
		n = Integer.parseInt(as.next());
		
		A = new int[n];
		
		for(i=0;i<n;i++){
			
			A[i] = Integer.parseInt(as.next());
			
		}
		
		p = 0;
		r = n-1;
		
		x = A[r];
		i = p-1;
		
		for(j=p;j<r;j++){
			
			if(A[j] <= x){
				
				i = i + 1;
				tre = A[i];
				A[i] = A[j];
				A[j] = tre;
				
			}
			
		}
		
		tre = A[i + 1];
		A[i + 1] = A[r];
		A[r] = tre;
		
		//System.out.println(i+1);
		for(int k=0;k<n;k++){
			
			
			//System.out.println(k+":"+(i+1));
			if(k == (i+1)){
				
				//System.out.println("!!");
				sb.append("[").append(String.valueOf(A[k])).append("]").append(" ");
				
			}
			else if(k != n-1){
				
				sb.append(String.valueOf(A[k])).append(" ");
				
			}
			else{
				
				sb.append(String.valueOf(A[k]));
				
			}
			
		}
		
		System.out.println(sb);

	}

}

Measured memory_bytes: 73412
// Problem : D - Friends
// Contest : AtCoder - AtCoder Beginner Contest 177
// URL : https://atcoder.jp/contests/abc177/tasks/abc177_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
using namespace std;

/* DEBUGGING */
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif

/* MACROS */ 
typedef long long int ll;
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

typedef map<int,int> mii;

#define  ff          first
#define  ss          second
#define  pb          push_back
#define  IOS         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  lb          lower_bound
#define  ub          upper_bound
#define  all(x)      (x).begin(), (x).end()
#define  lcm(x, y)   ((x) * (y) / __gcd(x, y))
#define  ps(x,y)     fixed<<setprecision(y)<<x
#define  setbit(x)   __builtin_popcountll(x)
#define  rep(i,a,b)  for(int i=a ; i<b ; ++i)
#define  repr(i,a,b) for(int i=a ; i>=b ; --i)

/* CONSTANTS */ 
#define PI 3.141592653589793
const ll MOD = 1e9 + 7;
const ll INF = 1000000000;
const ll MAX_N = 2e5 + 2;

// #define cerr if(false)cerr
/* CODE STARTS HERE */

vi adj[MAX_N],vis(MAX_N);
int cnt;

void dfs(int node){
    vis[node] = 1;
    
    cnt++;
    for(auto x:adj[node]){
        if(!vis[x]) dfs(x);
    }
}

void solve(){
    int n,m; cin >> n >> m;
    int a,b; 
    rep(i,0,m){
        cin >> a >> b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    
    int ans = 0;
    rep(i,1,n+1){
        if(!vis[i]){
            cnt=0;
            dfs(i);
            ans = max(ans, cnt);
        }
    }
    
    cout << ans;
}

int main(){
    IOS;
    solve();
}

Measured memory_bytes: 21036
#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
      
    cin>>n;
    rep(i,n){
        cin>>a;
        if(a%2==1)continue;
        while(1){
            a/=2;
            cnt++;
            if(a==0||a==1||a%2==1)break;
        }
        ans=max(ans,cnt);
    }
    Cout(cnt);
    return 0;
}


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

#define For(i, j, k) for(int i = j; i <= k; i++)
#define Forr(i, j, k) for(int i = j; i >= k; i--)
#define Set(i, v) memset(i, v, sizeof i)
#define pb push_back

using namespace std;

const int N = 100010;

int n;
int dis[N];
bool vis[N];

struct Node{
	int o, d;

	Node(int _o = 0, int _d = 0):o(_o), d(_d) {}

	bool operator < (const Node& A) const{
		return d > A.d;
	}
};

priority_queue<Node> q;

int main(){
	scanf("%d", &n);

	memset(dis, 0x3f, sizeof dis);
	dis[1] = 1;
	q.emplace(1, 1);
	while(!q.empty()){
		Node s = q.top(); q.pop();
		if(vis[s.o]) continue;
		vis[s.o] = true;

		int u = (s.o + 1) % n;
		if(dis[u] > s.d + 1) dis[u] = s.d + 1, q.emplace(u, dis[u]);

		u = (s.o * 10) % n;
		if(dis[u] > s.d) dis[u] = s.d, q.emplace(u, dis[u]);
	}

	printf("%d\n", dis[0]);
	return 0;
}

Measured memory_bytes: 1404
package main

import (
	"fmt"
)

func main() {
	var s string
	var k int64
	fmt.Scan(&s, &k)
	var c1 int64
	var first rune
	for _, c := range s {
		if c != '1' {
			first = c
			break
		}
		c1++
	}
	if c1 >= k {
		fmt.Println("1")
		return
	}
	fmt.Println(string(first))
}


Measured memory_bytes: 512
H, W = map(int, input().split(' '))
cells = [[False if tgt == '.' else True for tgt in list(input())] for i in range(H)]

paintable = True

for line in cells:
    line.append(False)
    line.insert(0, False)
cells.insert(0, [False for i in range(W + 2)])
cells.append([False for i in range(W + 2)])

for i in range(1, H + 1):
    for j in range(1, W + 1):
        if (cells[i][j] == True):
            if cells[i - 1][j] == False and cells[i][j - 1] == False and cells[i + 1][j] == False and cells[i][j + 1] == False:
                paintable = False
                break
    if not paintable:
        break

print ('Yes' if paintable else 'No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define db double
#define iosks std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int N=1e6+10,M=3e4+10;
const ll inf=1e18,mod=998244353;
const db pi=atan(1)*4;
ll pow2(ll a,ll b) {ll s=1; while(b) {if(b&1) s=(s*a)%mod; a=(a*a)%mod; b/=2; } return s;}
ll lcm(ll a,ll b) {return a/__gcd(a,b)*b; }
int read()
{
    int s=0,f=1; char ch=getchar();
    while(ch<'0'&&ch>'9') {if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9') {s=s*10+ch-'0'; ch=getchar();} return s*f;
}

ll n,m,k,r,c,v;
ll a[3050][3050],dp[3050][3050][5];

int main()
{
    iosks;
    cin>>n>>m>>k;
    for(int i=0;i<k;i++) cin>>r>>c>>v,a[r][c]=v;
    ll ans=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            for(int q=1;q<=3;q++){
                dp[i][j][q]=max(dp[i][j-1][q],max(dp[i-1][j][3]+a[i][j],dp[i][j-1][q-1]+a[i][j]));
                ans=max(ans,dp[i][j][q]);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	int n,m;cin>>n>>m;
	vl a(m);
	ll sum=0;
	rep(i,m){
		cin>>a[i];
		sum+=a[i];
	}
	if(sum>n)cout<<-1<<endl;
	else cout<<n-sum<<endl;
}

Measured memory_bytes: 3676
import java.util.*;

class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		int x=sc.nextInt();
		int ans=0;
		for(int i=0;i<=a;i++)
		for(int j=0;j<=b;j++)
		for(int k=0;k<=c;k++)
			if(i*500+j*100+k*50==x)
				ans++;
		System.out.println(ans);
	}
}

Measured memory_bytes: 22996
D = int(input())
A = [[0]*26]*D
S = 0
C = list(map(int,input().split()))
P = 0
ld =[0]*26#最後に行った日の格納
l = [0]*26#損失の計算
sp = 0#一時格納
t = [0]*D
for i in range(D):
  A[i] = list(map(int,input().split()))
for j in range(D):
  maxvalue = max(A[j])
  index = A[j].index(maxvalue)
  for n in range(26):
    ld[n] = ld[n]+1
  sp = ld[index]
  ld[index] = 0 
  for k in range(26):
    l[k] = C[k]*ld[k]
  lmax =max(l)
  if 13*lmax > maxvalue:
    lindex = l.index(lmax)
    ld[index] = sp
    ld[lindex] = 0
    for m in range(26):
      l[m] = C[m]*ld[m]
  S = S+maxvalue-sum(l)
  t[j] = index+1
for num in range(D):
  print(t[num])

Measured memory_bytes: 9212
import java.util.*;

import static java.lang.System.*;

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

        int max = Math.min(A,B);
        int min = Math.max(A + B - N, 0);

        out.println(max+" "+min);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
using namespace std;
typedef pair<ll,ll> pll;



bool srt = false;
ll n, k;
ll a[200005];
ll p[200005];
ll gf(set<ll> &S)
{
        return *S.begin();
}
ll gl(set<ll> &S)
{
        return *S.rbegin();
}
int main()
{
        cin >> n >> k;
        for(ll i=1;i<=n;i++) {
                cin >> a[i];
        }
        for(ll i=2;i<=n;i++) {
                p[i] = p[i-1];
                p[i] += (a[i] > a[i-1]);
        }
        set<ll > S;
        for(ll i=1;i<=k;i++) S.insert(a[i]);
        ll ans =1;
        if(p[k]-p[1] == k-1) {
                srt=true;
        }
        for(ll i=k+1;i<=n;i++) {
                if(a[i-k] == gf(S) && a[i] > gl(S)) {
                        S.erase(a[i-k]);
                        S.insert(a[i]);
                        continue;
                }
                bool ss = false;
                if(p[i] - p[i-k+1] == k-1) {
                        ss=true;
                }
                if(ss && srt) {

                }else if(ss && !srt) {
                        ans++;
                        srt=true;
                }else {
                        ans++;
                }
                S.erase(a[i-k]);
                        S.insert(a[i]);
        }
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;long long an=1;bool x=true;
  vector<long long>a(n);
  for(int i=0;i<n;i++){cin>>a[i];if(a[i]==0)x=false;}
  for(int i=0;i<n;i++){
    if(a[i]>1000000000000000000/an){
      an=-1;break;
    }
    an*=a[i];
  }
  if(x)cout<<an<<endl;
  else cout<<0<<endl;
}



Measured memory_bytes: 4048
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N), B(N), C(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A[i]--;
  }
  for (int i = 0; i < N; i++) cin >> B[i];
  for (int i = 0; i < N - 1; i++) cin >> C[i];
  ll food_ind, prev_ind = -100, score = 0;
  for (int i = 0; i < N; i++) {
    food_ind = A[i];
    score += B[food_ind];
    if (prev_ind + 1 == food_ind) score += C[prev_ind];
    prev_ind = food_ind;
  }
  cout << score << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>

#include <algorithm>

using namespace std;

int d,n,m;
int main(void){
  scanf("%d",&d);
  while(d!=0){
    scanf("%d%d",&n,&m);
    int  dates[100005];
    int i,co=0;
    int me;
    for(i=0;i<n-1;i++){
      scanf("%d",&(dates[co]));
      co++;
    }
    dates[co]=0;co++;
    dates[co]=d;co++;
    sort(dates,dates+co);
    int ans=0;
    int mi,hi,tyu;
    for(i=0;i<m;i++){
      scanf("%d",&me);
      mi=0;hi=co-1;
      while(hi-mi>1){
	tyu=(mi+hi)/2;
	if(dates[tyu]<=me){
	  mi=tyu;
	}
	else{
	  hi=tyu;
	}
      }
      mi=me-dates[mi];
      hi=dates[hi]-me;
      ans+=(mi<hi)?mi:hi;
    }
    printf("%d\n",ans);
    scanf("%d",&d);
  }
  return 0;
}

Measured memory_bytes: 1432
C = [list(map(int, input().split())) for _ in range(3)]

a = [C[0][0] - C[0][0]]
b = [C[0][0] - a[0]]

for i in range(1, 3):
    a.append(C[i][0] - b[0])
    b.append(C[0][i] - a[0])

for i in range(3):
    for j in range(3):
        num = a[i] + b[j]
        if num != C[i][j]:
            print('No')
            exit()

print('Yes')

Measured memory_bytes: 3064
N = int(input())
A = []
for i in range(2):
    A.append([int(a) for a in input().split()])
    
ans_list = []
for i in range(N):
    temp = 0
    for j in range(N):
        if j < i:
            temp += A[0][j]
        elif j == i:
            temp += A[0][j] + A[1][j]
        else:
            temp += A[1][j]
    ans_list.append(temp)
    
print(max(ans_list))

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

int main() {
    ll k;
    cin >> k;
    vector<int> num(k+1);
    num[0] = 7%k;
    if(num[0]==0) {cout << 1 << endl; return 0;}
    rep(i,k) {
        num[i+1] = num[i]*10 + 7;
        num[i+1]%=k;
        if(num[i+1]==0){
            cout << i+2 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 7088
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n,w;
    cin>>n>>w;
    ll a,b,m;
    vector<ll> dp(w+1,0);
    for(int i=0;i<n;i++){
    	cin>>a>>b>>m;
    	vector<ll> v;
    	for(ll j=1;m;j*=2){
    		if(j>m) v.pb(m),m=0;
    		else m-=j,v.pb(j);
    	}
    	for(auto& j:v){
    		ll c=a*j,d=b*j;
    		for(int k=w-d;k>=0;k--){
    			dp[k+d]=max(dp[k+d],dp[k]+c);
    		}
    	}
    }
    cout << dp[w] << endl;
    return 0;
}



Measured memory_bytes: 3316
import sys

lines = sys.stdin.readlines()
N = int(lines[0])
XU = [n.split() for n in lines[1:]]

JPN = []
BTC = []
for xu in XU:
  if 'JPY' == xu[1]:
    JPN.append(float(xu[0]))
  else:
    BTC.append(float(xu[0]))

print(sum(JPN) + sum(BTC) * 380000.0)

Measured memory_bytes: 3060
n = int(input())
# 100000以下の引き出せるお金の候補を作る
# 9**5 = 59049
# 6**6 = 46656

li = []
for i in range(1, 6):
  li.append(9**i)
  li.append(6**i)
li.append(6**6)
li.append(1)
li.sort()

# print(li)
DP = list(range(n + 1))

for l in li:
    for j in range(l, n + 1):
        DP[j] = min(DP[j - l] + 1, DP[j])
print(DP[-1])

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

int main(void) {
    vector<int> num(1000);
    num[0] = 0;
    for (int i = 1; i < 1000; i++) {
        if (i%3 == 0) {
            num[i] = 20*10 + num[i-1];
        } else {
            num[i] = 19*5 + 20*5 + num[i-1];
        }
    }

    int n; cin >> n;
    int y, m, d;
    while (n--) {
        cin >> y >> m >> d;
        d += num[y-1] - 1;
        if (y%3 == 0) {
            d += 20*(m-1);
        } else {
            for (int i = 1; i < m; i++) {
                if (i%2 == 0) {
                    d += 19;
                } else {
                    d += 20;
                }
            }
        }

        cout << num[999] - d << endl;

    }
    return 0;
}

Measured memory_bytes: 3056
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;
int main(void) {
	string s, t;
	cin >> s >> t;
	for(int i=0;i<s.size();++i) {
		rotate(s.rbegin(), s.rbegin() + 1, s.rend());
		if (s == t) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
card = [list(map(int,input().split())) for c in range(3)]
N = int(input())
nums = [int(input()) for n in range(N)]
ans =0
ind = [[False,False,False],[False,False,False],[False,False,False]]

for index,c in enumerate(card):
	for index2,c2 in enumerate(c):
		for n in nums:
			if n == c2:
				ind[index][index2] = True

if (ind[0][0] == True and ind[1][1] == True and ind[2][2] == True) or \
	(ind[0][2] == True and ind[1][1] == True and ind[2][0] == True)  or \
	(ind[0][0] == True and ind[1][0] == True and ind[2][0] == True)  or \
	(ind[0][1] == True and ind[1][1] == True and ind[2][2] == True)  or \
	(ind[0][2] == True and ind[1][2] == True and ind[2][2] == True)  or \
	(ind[0][0] == True and ind[0][1] == True and ind[0][2] == True)  or \
	(ind[1][0] == True and ind[1][1] == True and ind[1][2] == True)  or \
	(ind[2][0] == True and ind[2][1] == True and ind[2][2] == True):
  	print("Yes")
else:
	print("No")


Measured memory_bytes: 3064
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val in = new Scanner(System.in)
    val N = in.nextInt()
    val X = in.nextInt()
    val Y = in.nextInt()
    val foods = (for (_ <- 0 until N) yield {
      val K = in.nextInt()
      (for (_ <- 0 until K) yield {
        val a = in.nextInt()
        val b = in.nextInt()
        val c = in.nextInt()
        (a, b, c)
      }).toArray
    }).toArray

    val dist = (for (_ <- 0 until N) yield (for (_ <- 0 until N) yield in.nextInt()).toArray).toArray
    for {
      k <- 0 until N
      i <- 0 until N
      j <- 0 until N
    } dist(i)(j) = math.min(dist(i)(j), dist(i)(k) + dist(k)(j))

    val cost = Array.fill(1 << (N + 1), N + 1)(Int.MaxValue / 2)
    cost(1)(0) = 0
    for {
      mask <- 0 until (1 << N)
      current <- 0 until N
      next <- 1 until (N + 1)
      if (mask & (1 << current)) != 0
      if (mask & (1 << next)) == 0
    } {
      val nextMask = mask | (1 << next)
      cost(nextMask)(next) = math.min(cost(nextMask)(next), cost(mask)(current) + dist(current)(next % N))
    }

    val bottom = N / 2
    val top = N - bottom

    val deq = new Array[Int](1000000)
    val deqv = new Array[Int](1000000)

    def knapsack(mask: Int, dp: Array[Int]): Unit = {
      dp(0) = 0
      for {
        i <- 0 until N
        if (mask & (1 << i)) != 0
        (price, value, remain) <- foods(i)
        a <- 0 until price
      } {
        var s = 0
        var t = 0

        var num = 0
        while (num * price <= (Y - a)) {
          val v = dp(num * price + a) - num * value
          while (s < t && deqv(t - 1) <= v) {
            t -= 1
          }
          deq(t) = num
          deqv(t) = v
          t += 1

          dp(num * price + a) = deqv(s) + num * value
          if (deq(s) == num - remain) {
            s += 1
          }

          num += 1
        }
      }

      for {
        i <- 1 to Y
      } {
        dp(i) = math.max(dp(i), dp(i - 1))
      }
    }

    val bottomDp = Array.fill[Int](1 << bottom, Y + 1)(-1)
    val topDp = Array.fill[Int](1 << top, Y + 1)(-1)
    for (mask <- 0 until (1 << bottom)) {
      knapsack(mask, bottomDp(mask))
    }
    for (mask <- 0 until (1 << top)) {
      knapsack(mask << bottom, topDp(mask))
    }

    var max = 0
    for {
      mask <- 0 until (1 << N)
    } {
      val moveCost = cost(mask | (1 << N))(N)
      val budget = math.min(Y, X - moveCost)
      val bottomMask = mask & ((1 << bottom) - 1)
      val topMask = mask >> bottom

      if (budget > 0) {

        for {
          bottomBudget <- 0 to budget
        } {
          max = math.max(max, bottomDp(bottomMask)(bottomBudget) + topDp(topMask)(budget - bottomBudget))
        }
      }
    }
    println(max)
  }
}

Measured memory_bytes: 120512
n, k = map(int, input().split())
a = list(map(int, input().split()))
count = 0

for i in range(n):
    for j in range(n):
        if ((a[i] > a[j]) and (i > j)):
            count += (k-1)*k//2
        if ((a[i] > a[j]) and (i < j)):
            count += k*(k+1)//2

print(count%(10**9+7))

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  
  sort(A.begin(), A.end());
  for(int i = 0; i < N-1; i++){
    if(A.at(i) == A.at(i + 1)){
      cout << "NO" << endl;
      return 0;
    }
  }
  
  cout << "YES" << endl;
  return 0;
}



Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main(){

	string a, b, c;
	cin >> a >> b >> c;
	if( a.back()==b.front()){
		if( b.back()==c.front()){
			cout << "YES" <<endl;
		}
		else{
		cout << "NO" << endl;
		}
	}
	else{
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
S = input()
def isMM(s):
  i = int(s)
  return True if 1 <= i <=12 else False
isYYMM = isMM(S[2:4])
isMMYY = isMM(S[0:2])
if isYYMM:
  if isMMYY:
    print("AMBIGUOUS")
  else:
    print("YYMM")
else:
  if isMMYY:
    print("MMYY")
  else:
    print("NA")


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

int main() {
    int x, a;
    cin >> x >> a;
    int ans;
    if (x < a) ans = 0;
    else ans = 10;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>


using namespace std;


int main(){
	int ans, n;
	string S;
	cin >> S;

	for (int i = 0; i < S.size(); i++) {
		S.erase(S.size() - 1);
		n = S.size();

		if (n == 2) {
			ans = 2;
		}
		
		else if (n % 2 == 0) {

			if (S.substr(0, n / 2) == S.substr(n / 2, n)) {
				ans = n;
				break;
			}
		}
	}

	cout << ans;

	return 0;
}


Measured memory_bytes: 256
# Problem A - Range Flip Find Route

# input
h, w = map(int, input().split())
s_board = [['']*w for i in range(h)]
for i in range(h):
    s = list(input())
    for j in range(w):
        s_board[i][j] = s[j]

# initialization
INF = 10**5
dp = [[INF]*w for i in range(h)]
if s_board[0][0]=='#':
    dp[0][0] = 1
else:
    dp[0][0] = 0

# count
for i in range(h):
    for j in range(w):
        # skip
        if i==0 and j==0:
            continue

        # left
        if j-1>=0:
            if s_board[i][j]=='#' and s_board[i][j-1]=='.':
                dp[i][j] = min(dp[i][j], dp[i][j-1] + 1)
            else:
                dp[i][j] = min(dp[i][j], dp[i][j-1])

        # up
        if i-1>=0:
            if s_board[i][j]=='#' and s_board[i-1][j]=='.':
                dp[i][j] = min(dp[i][j], dp[i-1][j] + 1)
            else:
                dp[i][j] = min(dp[i][j], dp[i-1][j])

# output
print(dp[-1][-1])


Measured memory_bytes: 3188
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

constexpr auto INF = numeric_limits<ll>::max();

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

  const ll M = N / 1.08;
  ll answer = INF;
  for (ll i = -1; i <= 1; i++) {
    ll X = M + i;
    const ll R = X * 1.08;
    if (R == N) {
      answer = X;
    }
  }
  if (answer == INF) {
    cout << ":(" << endl;
  } else {
    cout << answer << endl;
  }
  return 0;
}


Measured memory_bytes: 256
for i in range(10000):
    x = int(input())
    if x == 0:
        break
    print("Case {}: {}".format(i + 1, x))

"""
EOL = 0
MAX = 10000

for i in range(MAX):
  x = int(input())
  if x == EOL:
    break

  print('Case {}: {}'.format(i + 1, x))
"""


Measured memory_bytes: 5608
#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 L, R, d;
  cin >> L >> R >> d;
  int ans = 0;
  for (int i = L; i <= R; i++)
  {
    if (i % d == 0)
    {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

const int N = 107, M = 1e3 + 7, INF = 0x3f3f3f3f3f3f3f3f;

int dp[N][M * N], w[N], v[N];

int32_t main() {

        int n, k; cin >> n >> k;
        for(int i = 1; i <= n; i++) {
                cin >> w[i] >> v[i];
        }

        memset(dp, 0x3f, sizeof dp);
        dp[0][0] = 0;
        for(int i = 1; i <= n; i++) {
                for(int j = 0; j < N * M; j++) {
                        dp[i][j] = dp[i - 1][j];
                        if(j - v[i] >= 0) dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
                }
        }

        int mx = 0;

        for(int i = 1; i < N * M; i++) {
                if(dp[n][i] <= k) {
                        mx = i;
                }
        }

        cout << mx << endl;
}


Measured memory_bytes: 90368
#include <iostream>
#include <string>
int main(){
  char s[10];
  for (int i = 0; i < 10; i++){
    std::cin >> s[i];
    if (i == 3){
      s[i] = '8';
    }
  }

  for (int i = 0; i < 10; i++){
    std::cout << s[i];
  }
  std::cout << std::endl;
  return 0;
}

Measured memory_bytes: 3620