akhauriyash/Code-Regression huggingface dataset:
N, M = map(int, input().split())
to = [[] for _ in range(N)]
ans = 'IMPOSSIBLE'

for _ in range(M):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    to[a].append(b)
    to[b].append(a)
    
for nxt in to[0]:
    if N - 1 in to[nxt]:
        ans = 'POSSIBLE'
        break
        
print(ans)

Measured memory_bytes: 108776
/*
START BY THE NAME OF ALMIGHTY ALLAH
THIS WONT BE ACCEPTED
STOP_GIVING_UP

██╗███████╗████████╗██╗ █████╗ ██╗  ██╗
██║██╔════╝╚══██╔══╝██║██╔══██╗██║ ██╔╝
██║███████╗   ██║   ██║███████║█████╔╝
██║╚════██║   ██║   ██║██╔══██║██╔═██╗
██║███████║   ██║   ██║██║  ██║██║  ██╗
╚═╝╚══════╝   ╚═╝   ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝




*/
#include<bits/stdc++.h>
#define l(i,a,n)for(int i=a;i<n;i++)
#define pb push_back
#define in insert
#define mp make_pair
#define lw(v) sort(v.begin(),v.end());
#define hi(v) sort(v.begin(),v.end(),greater<long long>());
#define all(v) v.begin(),v.end()
#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long t,r=1,r1=0,r2=0,k=0,a,b,c=1,m,d=0,n,e,f,x=0,g,p=0,q=0,y=0,z=0;
    vector<long long>v;
    vector<long long>u;
    set<long long>s;
    std::vector<int>::iterator it;
    string  s1,s2,s3,s4;
    cin>>n>>m;
    if(n<=5)
    {
        cout<<0<<endl;
    }
    else if(n>5&&n<13)
    {
        cout<<m/2<<endl;
    }
    else
    {
    cout<<m;
    }

}











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

int main() {
    int N;
    cin >> N;
    int flg = false;
    for(int i = 1; i <= 9; i++) {
        if(N / i < 10 && N % i == 0) {
            flg = true;
        }
    }
    if(flg) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 判定条件を解説通りに実装
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			long d = scanner.nextLong();
			System.out.println(IntStream.range(0, n).filter(i -> {
				long x = scanner.nextLong(), y = scanner.nextLong();
				return (x * x + y * y) <= d * d;
			}).count());
		}
	}
}


Measured memory_bytes: 59664
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#include<queue>
#define int long long
using namespace std;

const int INF = 1e10;
const int ZERO = 0;
typedef pair<int,int> P;
int H,W;
char maze[100][100];
int cnt[100][100];
int dy[4] = {0,1,0,-1} ,dx[4] = {1,0,-1,0};
int bfs() {
	queue<P> que;
	for(int i = 0;i <= H;i++) {
		for(int j = 0;j <= W;j++) {
			cnt[i][j] = INF;
		}
	}
	que.push(P(1,1));
  	cnt[1][1] = 0;
	while(que.size() != 0) {
		P p = que.front();
		que.pop();
		for(int i = 0;i < 4;i++) {
			int ny = p.first + dy[i];
			int nx = p.second + dx[i];
			if(1 <= nx && nx <= W && 1 <= ny && ny <= H && maze[ny - 1][nx - 1] != '#' && cnt[ny][nx] == INF) {
				que.push(P(ny,nx));
				cnt[ny][nx] = cnt[p.first][p.second] + 1;
			}
		}
	} 
	return cnt[H][W];
}
signed main() {
	cin >> H >> W;
	for(int i = 0;i < H;i++) {
		for(int j = 0;j < W;j++) {
			cin >> maze[i][j];
		}
	}
	int count = 0;
	for(int i = 0;i < H;i++) {
		for(int j = 0;j < W;j++) {
			if(maze[i][j] == '#') {
				count++;
			}	
		}
	}
  	if(bfs() == INF) {
      	cout << -1 << endl;
    }
  	else {
		cout << H * W - bfs() - 1 - count << endl;
    }
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var nml = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var n = nml[0];
        var m = nml[1];
        var l = nml[2];
        var adjMatrix = new long[n + 1][];
        for (int i = 0; i < adjMatrix.Length; ++i)
        {
            adjMatrix[i] = new long[i + 1];
            for (int j = 0; j < adjMatrix[i].Length; ++j)
            {
                adjMatrix[i][j] = long.MaxValue;
            }
            adjMatrix[i][i] = 0;
        }
        for (int i = 0; i < m; ++i)
        {
            var abc = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            var u = abc[0];
            var v = abc[1];
            if (u < v)
            {
                u += v;
                v = u - v;
                u -= v;
            }
            adjMatrix[u][v] = Math.Min(adjMatrix[u][v], abc[2]);
        }
        var q = int.Parse(Console.ReadLine());
        var queries = new Tuple<int, int>[q];
        for (int i = 0; i < queries.Length; ++i)
        {
            var st = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            queries[i] = Tuple.Create(st[0], st[1]);
        }

        CompleteWithShortestDistances(adjMatrix);
        for (int i = 0; i < adjMatrix.Length; ++i)
        for (int j = 0; j < adjMatrix[i].Length; ++j)
        {
            adjMatrix[i][j] = adjMatrix[i][j] > l ? long.MaxValue : i == j ? 0 : 1;
        }
        CompleteWithShortestDistances(adjMatrix);

        var answer = new StringBuilder();
        foreach (var query in queries)
        {
            var s = query.Item1;
            var t = query.Item2;
            if (s < t)
            {
                s += t;
                t = s - t;
                s -= t;
            }
            answer.AppendLine((adjMatrix[s][t] < int.MaxValue ? adjMatrix[s][t] - 1 : -1).ToString());
        }
        Console.Write(answer);
    }

    static void CompleteWithShortestDistances(long[][] g)
    {
        for (int k = 1; k < g.Length; ++k)
        {
            for (int j = 1; j < g.Length; ++j)
            for (int i = 1; i < g[j].Length; ++i)
            {
                var dkj = k < j ? g[j][k] : g[k][j];
                var dki = k < i ? g[i][k] : g[k][i];
                if (dkj == long.MaxValue)
                {
                    break;
                }
                if (dki == long.MaxValue)
                {
                    continue;
                }

                g[j][i] = Math.Min(g[j][i], dki + dkj);
            }
        }
    }
}


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

int main()
{ 
  int N,K;
  cin >> N>>K;
 
  string S;
  cin>>S;
 
  int ct=0;
  for(int i=0; i<N-1; i++){
    ct+= S[i]==S[i+1];
  }
 
  cout<< min(ct+2*K,N-1)<<"\n";
  return 0;
}


Measured memory_bytes: 512
//Green Bin

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,name,type) vector<type>name(n);rep(i,0,n)cin>>name[i]
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
#define cout15(a) printf("%.15f\n",a)
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<ll,string> p;
using g = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

int main (){
    ll n;cin>>n;
    vector<string>s(n);
    rep(i,0,n){
        string t;cin>>t;
        sort(range(t));
        s[i]=t;
    }
    sort(range(s));
    map<ll,ll>m{};
    m[0]++;
    ll c = 0;
    ll ans = 0;
    rep(i,1,n){
        if(s[i]!=s[i-1]){
            c++;
        }
        m[c]++;
    }
    irep(i,m){
        if(i->second>1)ans+=(i->second)*(i->second-1)/2;
    }
    cout<<ans<<nnn;
    return 0;
}

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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1005,INF=1000;

int main(){
    
    string A;cin>>A;
    ll N=A.size();
    ll ans=N*(N-1)/2+1;
    vector<ll> S(26);
    for(int i=0;i<N;i++){
        S[A[i]-'a']++;
    }
    
    for(int i=0;i<26;i++){
        if(S[i]>=2) ans-=S[i]*(S[i]-1)/2;
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 640
program V1504;
 var
  x,y:array[0..2501] of longint;
  t:array[0..51] of longint;
  i,j,m,n,o,p,s,sum:longint;
 function haha(k:longint):longint;
  begin
   if t[k]<>k then t[k]:=haha(t[k]);
   exit(t[k]);
  end;
 begin
  readln(n,m);
  for i:=1 to m do
   readln(x[i],y[i]);
  for i:=1 to m do
   begin
    for j:=1 to n do
     t[j]:=j;
    s:=n;
    for j:=1 to m do
     if i<>j then
      begin
       o:=haha(x[j]);
       p:=haha(y[j]);
       if o<>p then
        begin
         dec(s);
         t[o]:=p;
        end;
      end;
    if s<>1 then inc(sum);
   end;
  writeln(sum);
 end.


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Collections;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

//namespace _1_A
//{
class Program
{
    static void Main(string[] args)
    {
        int i;
        int work;
        ArrayList array = new ArrayList();
        int[] iarray = new int[2];
        string x = Console.ReadLine();
        string[] sarray = x.Split(' ') ;
        iarray[0] = int.Parse(sarray[0]);
        iarray[1] = int.Parse(sarray[1]);
        for (i = 0; i < 3000; i++)
        {
            if ((iarray[0] == iarray[1]) && iarray[0] ==  0)
                break;
            else if(iarray[0] > iarray[1])
            {
                    work = iarray[0];
                    iarray[0] = iarray[1];
                    iarray[1] = work;
            }

            array.Add(iarray[0]);
            array.Add(iarray[1]);
            x = Console.ReadLine();
            sarray = x.Split(' ');
            iarray[0] = int.Parse(sarray[0]);
            iarray[1] = int.Parse(sarray[1]);
        }
        int k = 0;

        foreach (object obj in array)
        {
            if (k == 1)
            {
                Console.WriteLine(" " + obj.ToString());
                k = 0;
            }
            else
            {
                Console.Write(obj.ToString());
                k++;
            }
        }

        //Console.Read();
    }
}
//}

Measured memory_bytes: 9360
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N; long long L[100010], R[100010]; 
	L[0] = 0; R[0] = 0; 
	cin >> N; 
	for(int i = 1; i <= N; i++) cin >> L[i] >> R[i]; 
	sort(L, L+N+1, greater<long long>()); 
	sort(R, R+N+1); 
	long long ans = 0; 
	for(int i = 0; i <= N; i++){
		if(L[i] < R[i]) break; 
		ans += L[i] - R[i]; 
	}
	cout << ans * 2 << endl; 
}

Measured memory_bytes: 1792
#!/usr/bin/env python3
import sys


def solve(N: int, K: int):
    print(len(Base_10_to_n(N, K)))
    return


def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef long long ll;

int main(){
    // read in integer 
    int len;
    cin >> len;

    // read in list of strings 
    string first;
    string second; 
    cin >> first >> second; 

    // output by index
    REP(i, len) cout << first.at(i) << second.at(i);
    cout << endl;
}

Measured memory_bytes: 256
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    Int n;
    cin >> n;
    map<Int, Int> m;
    for (Int i = 0; i < n; i++) {
        Int a;
        cin >> a;

        m[a]++;
    }

    for (auto itr = m.begin(); itr != m.end();) {
        if ((*itr).second <= 1) {
            itr = m.erase(itr);
        } else {
            ++itr;
        }
    }

    Int ans;
    if (m.size() < 2) {
        ans = 0;
    } else if (4 <= (*m.rbegin()).second) {
        ans = (*m.rbegin()).first * (*m.rbegin()).first;
    } else {
        ans = (*m.rbegin()).first * (*next(m.rbegin())).first;
    }

    cout << ans << endl;

    return 0;
}


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

int		main(void)
{
	string s, t;

	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());
	if (s < t)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}



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

using ll = long long;

int main()
{
    ios::sync_with_stdio(false);

    int N; cin >> N;

    auto initial = vector<int>(N);
    for (auto& x : initial) cin >> x;

    auto delta = vector<int>(N-1);
    for (auto i = 0; i < N-1; i++)
        delta[i] = initial[i+1]-initial[i];

    int M; ll K; cin >> M >> K;

    auto pi = vector<int>(N-1);
    iota(begin(pi), end(pi), 0);

    for (auto i = 0; i < M; i++)
    {
        int a; cin >> a;
        a--;
        swap(pi[a], pi[a-1]);
    }

    auto piK = vector<int>(N-1);
    auto used = vector<bool>(N-1);
    for (auto i = 0; i < N-1; i++) if (!used[i])
    {
        auto cycle = vector<int>({i});
        for (auto j = pi[i]; j != i; j = pi[j])
        {
            cycle.push_back(j);
            used[j] = true;
        }

        for (auto j = 0; j < int(cycle.size()); j++)
            piK[cycle[j]] = cycle[(j + K) % cycle.size()];
    }

    auto x = ll(initial[0]);
    for (auto i = 0; i < N; i++)
    {
        cout << x << endl;
        if (i != N-1) x += delta[piK[i]];
    }
}


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

int main() {
  int N;
  cin >> N;
  if (N == 1) {
    cout << "Hello World" << endl;
  }
  else {
    int A, B;
    cin >> A >> B;
    cout << A + B << endl;
  }
}
 



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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)

int A[5];
int main(){
	fast;
	
	FOR(i,0,4) cin>>A[i];
	
	cout<<min_element(A,A+5) - A + 1;
}


Measured memory_bytes: 3636
from collections import defaultdict, deque
import sys


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]


n = I()
print(n ** 3)


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

using namespace std;

int main(){
    string s;
    cin >> s;
    int y[3];
    // cout << s << endl;
  
    int j = 0;
    string t = "";
    for(int i=0;i < s.size();i++){
        if(!('0' <= s[i] && s[i] <= '9')){
            // cout << t << endl;
            y[j] = atoi(t.c_str());
            j++;
            t = "";
            continue;
        }
        t += s[i];
        if(i == s.size()-1){
            y[j] = atoi(t.c_str());
        }
    }

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

    if(y[0] <= 2019 && y[1] <= 4 && y[2] <= 30){
        cout << "Heisei" << endl;
    }else{
        cout << "TBD" << endl;
    }
 
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cmath>

#define REP(i,n) for(int (i) = 0;(i) < (n);(i)++)
using namespace std;
vector<int> w;
int k,n;

int solve(int f,int e){
	if(e-f==1) return e;
	int m = (f+e)/2,j=0;
	REP(i,k){
		int sum=0;
		if(m < w[j])break;
		if(j == n)break;
		while(j < n && sum+w[j] <= m)sum += w[j++];
	}
	if(j==n) return solve(f,m);
	return solve(m,e);
}

int main(){
	int sum=0,x;
	cin >> n >> k;
	REP(i,n) {
		cin >> x;w.push_back(x);
		sum += x;
	}
	cout << solve(ceil((double)sum/k)-1,sum) << endl;
	return 0;
}

Measured memory_bytes: 3540
N, x = map(int, input().split())

n = [1]
p = [1]

for i in range(1, N+1):
    n.append(n[-1] * 2 + 3)
    p.append(p[-1] * 2 + 1)
    
lev = N
n1 = [0, 1, 2, 3, 3]
ans = 0

while lev >= 0:
    if lev ==0:
        ans += 1
        break
    if n[lev]//2 + 2 <= x:
        ans += p[lev-1] + 1
        x -= n[lev-1] + 2
    elif n[lev]//2 + 1 == x:
        ans += p[lev-1] + 1
        break
    elif x==1:break
    else: x -= 1

    lev -= 1
 
print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/
const int MOD = 1000000007;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  string k; cin >> k;
  int sz = k.size();
  int d; cin >> d;
  // true...tight
  vector<vector<vector<long long>>> dp(sz+1, vector<vector<long long>>(d, vector<long long>(2, 0)));
  dp[0][0][true] = 1;
  REP(i, sz) REP(j, d) {
    REP(l, k[i]-'0') (dp[i+1][(j+l)%d][false] += (dp[i][j][true] + dp[i][j][false]) % MOD) %= MOD;
    (dp[i+1][(j+(k[i]-'0'))%d][true] += dp[i][j][true]) %= MOD;
    FOR(l, k[i]-'0', 10) (dp[i+1][(j+l)%d][false] += dp[i][j][false]) %= MOD;
  }
  cout << (dp[sz][0][true] + dp[sz][0][false] - 1 + MOD) % MOD << '\n';
  return 0;
}


Measured memory_bytes: 55424
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {
			int A = Integer.parseInt(sc.next());
			int B = Integer.parseInt(sc.next());
			int C = Integer.parseInt(sc.next());
			
			if((A < C && C < B) || (A > C && C > B)) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		} // Scanner Close
	}
}

Measured memory_bytes: 22100
#include <stdio.h>
#include <string.h>

// http://www.prefield.com/algorithm/misc/dice.html
enum FACE { TOP, BOTTOM, FRONT, BACK, LEFT, RIGHT };
class dice {
public:
	void assign(int top,int front,int right,int left,int back,int bottom){
		id[TOP] = top; id[FRONT] = front; id[RIGHT] = right;
		id[LEFT] = left; id[BACK] = back; id[BOTTOM] = bottom;
	}
	dice(int top,int front,int right,int left,int back,int bottom){
		assign(top,front,right,left,back,bottom);
	}
	dice(int top,int front,int right){
		assign(top,front,right,7-right,7-front,7-top);
	}
	dice(int top,int front,bool righthand){
		int right=0;
		if(top==1){
			if(front==2)right=3;
			if(front==3)right=5;
			if(front==5)right=4;
			if(front==4)right=2;
		}else if(top==2){
			if(front==1)right=4;
			if(front==4)right=6;
			if(front==6)right=3;
			if(front==3)right=1;
		}else if(top==3){
			if(front==1)right=2;
			if(front==2)right=6;
			if(front==6)right=5;
			if(front==5)right=1;
		}else if(top==4){
			if(front==1)right=5;
			if(front==5)right=6;
			if(front==6)right=2;
			if(front==2)right=1;
		}else if(top==5){
			if(front==1)right=3;
			if(front==3)right=6;
			if(front==6)right=4;
			if(front==4)right=1;
		}else if(top==6){
			if(front==2)right=4;
			if(front==4)right=5;
			if(front==5)right=3;
			if(front==3)right=2;
		}

		if(!righthand)right=7-right;
		assign(top,front,right,7-right,7-front,7-top);
	}

	const int& operator[](FACE f) const{return id[f];}
	bool operator==(const dice &b) const{
		const dice &a = *this;
		return a[TOP] == b[TOP] && a[BOTTOM] == b[BOTTOM] &&
			a[FRONT] == b[FRONT] && a[BACK] == b[BACK] &&
			 a[LEFT] == b[LEFT] && a[RIGHT] == b[RIGHT];
	}
	void roll_north() {roll(TOP, FRONT, BOTTOM, BACK);}
	void roll_south() {roll(TOP, BACK, BOTTOM, FRONT);}
	void roll_east()  {roll(TOP, LEFT, BOTTOM, RIGHT);}
	void roll_west()  {roll(TOP, RIGHT, BOTTOM, LEFT);}
	void roll_right() {roll(FRONT, LEFT, BACK, RIGHT);}
	void roll_left()  {roll(FRONT, RIGHT, BACK, LEFT);}
private:
	void roll(FACE a, FACE b, FACE c, FACE d){
		int tmp = id[a];
		id[a] = id[b]; id[b] = id[c];
		id[c] = id[d]; id[d] = tmp;
	}
	int id[6];
};

int M[200][200];
int P[200][200];
int R[7];
int main(){
	int N;
	for(;scanf("%d",&N),N;){
		memset(M,0,sizeof(M));
		memset(P,0,sizeof(P));
		memset(R,0,sizeof(R));
		for(;N--;){
			int top,front;
			scanf("%d%d",&top,&front);
			dice di(top,front,true);
			int x=100,y=100;
			for(;;){
				int ma=3,idx;
				if(di[FRONT]>ma && P[y+1][x]<P[y][x])ma=di[FRONT],idx=0;
				if(di[BACK]>ma && P[y-1][x]<P[y][x])ma=di[BACK],idx=1;
				if(di[LEFT]>ma && P[y][x-1]<P[y][x])ma=di[LEFT],idx=2;
				if(di[RIGHT]>ma && P[y][x+1]<P[y][x])ma=di[RIGHT],idx=3;
				if(ma==3)break;
				if(idx==0)y++,di.roll_south();
				if(idx==1)y--,di.roll_north();
				if(idx==2)x--,di.roll_west();
				if(idx==3)x++,di.roll_east();
			}
			P[y][x]++;
			R[M[y][x]]--,M[y][x]=di[TOP],R[M[y][x]]++;
		}
		for(int i=1;i<=6;i++)printf(i<6?"%d ":"%d\n",R[i]);
	}
}

Measured memory_bytes: 1348
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ll long long
#define ull unsigned long long
#define ld long double
#define zeros(x) x^(x-1)&x
#define pii pair<ll,ll>
#define cd complex<double>
#define dbg(x) cerr<<x<<endl;
#define Nmax 500005
using namespace std;

ll n, ans[Nmax], viz[Nmax], q, m, x, y;
vector<int> v[Nmax];
struct lol{
    int nod, d, c;
}a[Nmax];

void solve(int nod, int d, int c){
    if (viz[nod] >= d) return;
    if (!viz[nod]) ans[nod] = c;
    viz[nod] = d;
    for (auto it : v[nod]){
        solve(it, d-1, c);
    }
}

int main()
{
    cin >> n >> m;
    for (int i=1;i<=m;i++){
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    cin >> q;
    for (int i=1;i<=q;i++){
        cin >> a[i].nod >> a[i].d >> a[i].c;
    }
    for (int i=q;i>=1;i--){
        solve(a[i].nod, a[i].d+1, a[i].c);
    }

    for (int i=1;i<=n;i++) cout << ans[i] << '\n';


    return 0;
}


Measured memory_bytes: 21752
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <time.h>
#include <iomanip>
#include <thread>
#include <atomic>
#include <mutex>
#include <future>
#define double long double
#define int long long
#define low lower_bound
#define upp upper_bound
#define mod (int)1e9+7
#define inf (int)1e16
#define rep(i,n) for (int i = 0; i < n; i++)
#define Rep(i,n) for (int i = n; i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout<<endl;
#define P pair<int, int>
#define prique priority_queue<P, vector<P>, greater<P>>
struct edge { int to, cost; };
using namespace std;
template<typename T> void unsort(vector<T>& vec) {
	sort(all(vec), greater<T>());
	return;
}

signed main() {
	int r, d, x;
	cin >> r >> d >> x;
	int ans[11];
	ans[0] = x;
	rep(i, 10) {
		cout << ans[i] * r - d << endl;
		ans[i + 1] = ans[i] * r - d;
	}
}


Measured memory_bytes: 256
n = int(input())
a_list = [int(x) for x in input().split()]

if 0 in a_list:
  print(0)
  
else:
  flg = True
  num = 1
  for a in a_list:
    num *= a
    if num > 1E18:
      print(-1)
      flg = False
      break

  if flg:
    print(num)

Measured memory_bytes: 21648
#include <iostream>
//#include <vector>
//#include <algorithm>

using namespace std;

//vector < vector < int > > rebra;

int getbit(int mask, int num)
{
    return (mask >> num) &1;
}

int main()
{
    int n, m, a, b, c, l = 1;
    cin >> n >> m;
    for (int i = 0; i < n; i++)
        l *= 2;
    l--;
    int rebra[n][n];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            rebra[i][j] = -1;
    for (int i = 0; i < m; i++){
            cin >> a >> b >> c;
            rebra[a][b] = c;
        }
    long long dp[l+1][n];
    for (int i = 0; i <= l; i++)
        for (int j = 0; j < n; j++)
            dp[i][j] = -1;
    dp[1][0] = 0;
    long long f = 1;
    for (long long mask = 1; mask <= l; mask++)
        for (int j = 0; j < n; j++)
            if ((getbit(mask, j) == 1) && (dp[mask][j] != -1))
                for (int q = 0; q < n; q++)
                    if ((rebra[j][q] != -1) && (getbit(mask, q) == 0)){
                        f = 1;
                        for (int y = 0; y < q; y++)
                            f *= 2;
                        f += mask;
                        if ((dp[f][q] == -1) || (dp[mask][j] + rebra[j][q] < dp[f][q])){
                            dp[f][q] = dp[mask][j] + rebra[j][q];
                            f = 0;
                            }

                    }
    int mm = -1;
    for (int i = 1; i < n; i++)
        if ((dp[l][i] != -1) && (rebra[i][0] != -1))
            if (mm == -1){
                mm = dp[l][i] + rebra[i][0];
            } else {
                if ((mm == -1) || (dp[l][i] + rebra[i][0] < mm))
                    mm = dp[l][i] + rebra[i][0];
            }
    /*for (int i = 0; i < n; i++){
        for (int j = 1; j <= l; j++)
            cout << dp[j][i] << ' ';
        cout << endl;
    }*/
    cout << mm << endl;

}

Measured memory_bytes: 5000
#include<bits/stdc++.h>
using namespace std;
long long read()
{
	char ch=getchar();long long x=0,ff=1;
	while(ch<'0'||ch>'9') {if(ch=='-') ff=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}
	return ff*x;
}
void write(long long z)
{
	if(z<0){putchar('-');z=-z;}
	if(z>=10){write(z/10);}
	putchar(z%10+'0');
}
long long n,top;
long long a[100005],zhan[100005];
long long ans[100005],val[100005];
int main()
{
	n=read();
	for(long long i=1;i<=n;++i) 
	{
		a[i]=read();
		val[i]=a[i];
	}
	for(long long i=1;i<=n;++i)
	{
		if(a[i]>a[zhan[top]]) zhan[++top]=i;
		else 
		{
			long long l=0,r=top;
			while(l+1<r)
			{
				long long mid=(l+r)>>1;
				if(a[zhan[mid]]>a[i]) r=mid;
				else l=mid;
			}
			if(a[i]!=a[zhan[r]]) ans[zhan[r]]+=a[i]-a[zhan[r-1]];
		}
	}
	sort(val+1,val+n+1);
	long long now=1;
	for(long long i=1;i<=top;++i) 
	{
		while(now<=n&&val[now]<a[zhan[i]]) now++;
		ans[zhan[i]]+=(a[zhan[i]]-a[zhan[i-1]])*(n-now+1);
	}
	for(long long i=1;i<=n;++i) write(ans[i]),puts("");
	return 0;
}

Measured memory_bytes: 4352
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

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

	int C0 = 0;
	int C1 = 0;
	int C2 = 0;
	int C3 = 0;
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;

		if (s == "AC") {
			C0++;
		}
		else if (s == "WA") {
			C1++;
		}
		else if (s == "TLE") {
			C2++;
		}
		else if (s == "RE") {
			C3++;
		}
	}

	cout << "AC x " << C0 << endl;
	cout << "WA x " << C1 << endl;
	cout << "TLE x " << C2 << endl;
	cout << "RE x " << C3 << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1LL << 60;
vector<int> s[11];
int main(){
    int n, m;
    cin >> n>> m;
    rep(i,m){
        int k;
        cin >> k;
        rep(j,k){
            int a;
            cin >> a;
            a--;
            s[i].push_back(a);
        }
    }
    vector<int> p(m);
    rep(i,m) cin >>p[i];
    int ans=0;
    for(int i=0; i<1<<n; i++){
        vector<int> d(n);
        bool ok = true;
        rep(j,n) d[j] = i>>j&1;
        rep(j,m){
            int sm = 0;
            for(int k : s[j]){
                if(d[k])sm++;
            }
            if(p[j]!=sm%2){
                ok = false;
                break;
            }
        }
        if(ok) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    string g; int y,m,d;
    while(true){
        cin >> g;
        if(g == "#") break;
        cin >> y >> m >> d;
        if(y <= 30 || (y == 31 && m <= 4)){
            cout << "HEISEI " << y << " " << m << " " << d << endl;
        }else{
            cout << "? " << y-30 << " " << m << " " << d << endl;
        }
    }
    
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve(0);
    //cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}



Measured memory_bytes: 3208
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
INF = 10 ** 9 + 1  # sys.maxsize # float("inf")
MOD = 10 ** 9 + 7


def debug(*x):
    print(*x, file=sys.stderr)


def loop():
    xs = [3, 1, 2, 1]
    ret = []
    N = 6
    visited = [0] * 100
    for i, a in enumerate(xs):
        if visited[a]:
            debug("ret", ret)
            debug("visited", visited)
            s = sum(ret)
            loop_start = visited[a] - 1
            debug("a, visited[a], i", a, visited[a], i)
            loop_end = i
            loop_sum = sum(ret[loop_start:loop_end])
            debug("loop_sum", loop_sum)
            loop_length = loop_end - loop_start
            loop_count = (N - i) // loop_length
            debug("loop_count", loop_count)
            debug("(N - i) % loop_length", (N - i) % loop_length)
            loop_left = (N - i) % loop_length
            loop_tail = sum(ret[loop_start:loop_start + loop_left])
            debug("loop_tail", loop_tail)
            return s + (N - i) // loop_length * loop_sum + loop_tail
        ret.append(a)
        visited[a] = (i + 1)


def solve(N, X, M):
    visited = [0] * M
    a = X
    ret = []
    for i in range(N):
        if visited[a]:
            # debug("ret", ret)
            s = sum(ret)
            loop_start = visited[a] - 1
            # debug("a, visited[a], i", a, visited[a], i)
            loop_end = i
            loop_sum = sum(ret[loop_start:loop_end])
            # debug("loop_sum", loop_sum)
            loop_length = loop_end - loop_start
            loop_count = (N - i) // loop_length
            # debug("loop_count", loop_count)
            # debug("(N - i) % loop_length", (N - i) % loop_length)
            loop_left = (N - i) % loop_length
            loop_tail = sum(ret[loop_start:loop_start + loop_left])
            # debug("loop_tail", loop_tail)
            return s + loop_count * loop_sum + loop_tail
        ret.append(a)
        visited[a] = (i + 1)
        a = (a * a) % M

    return sum(ret)


def main():
    # parse input
    N, X, M = map(int, input().split())
    print(solve(N, X, M))


# tests
T1 = """
6 2 1001
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
1369
"""

T2 = """
1000 2 16
"""
TEST_T2 = """
>>> as_input(T2)
>>> main()
6
"""

T3 = """
10000000000 10 99959
"""
TEST_T3 = """
>>> as_input(T3)
>>> main()
492443256176507
"""


def _test():
    import doctest
    doctest.testmod()
    g = globals()
    for k in sorted(g):
        if k.startswith("TEST_"):
            doctest.run_docstring_examples(g[k], g, name=k)


def as_input(s):
    "use in test, use given string as input file"
    import io
    f = io.StringIO(s.strip())
    g = globals()
    g["input"] = lambda: bytes(f.readline(), "ascii")
    g["read"] = lambda: bytes(f.read(), "ascii")


input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

if sys.argv[-1] == "-t":
    print("testing")
    _test()
    sys.exit()

main()


Measured memory_bytes: 69472
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = int(1e9);
typedef long long int ll;

/* -- template -- */

ll gcd(ll x, ll y){
    if(y == 0)return x;
    return gcd(y, x % y);
}

int main(){
    ll A, B, C, D;cin >> A >> B >> C >> D;
    if(D > C)swap(C, D);
    ll CD = (C * D)/(gcd(C, D));
    ll ac = (A - 1) / C, bc = (B) / C, c = bc - ac;
    ll ad = (A - 1) / D, bd = (B) / D, d = bd - ad;
    ll acd = (A - 1) / CD, bcd = (B) / CD, cd = bcd - acd;
    cout << B - A + 1 - (c + d - cd) << endl;
}


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


void solve(long long N, long long L, std::vector<std::string> S){
  sort(S.begin(), S.end());

  for(auto& i : S) {
    cout << i;
  }

  cout << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
  long long L;
  scanf("%lld",&L);
  std::vector<std::string> S(N);
  for(int i = 0 ; i < N ; i++){
    std::cin >> S[i];
  }
    solve(N, L, std::move(S));
    return 0;
}


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

int main(){
  int N,K;
  cin >> N >> K;
  int64_t ans=0;
  for(int i=0;i<N;i++){
    int x;
    cin >> x;
    ans+=min(x,abs(x-K))*2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int d = scan.nextInt();
		int e = scan.nextInt();
		int k = scan.nextInt();

		 if (e-a<=k) System.out.println("Yay!");
	        else System.out.println(":(");
	}
}

Measured memory_bytes: 21844
#include <iostream>

using namespace std;

int main() {
	const bool debug = false;
	int N;
	cin >> N;

	int* balls = new int[N * 10];
	for (int i = 0; i < N * 10; i++) {
		cin >> balls[i];
	}

	for (int j = 0; j < N; j++) {
		bool isYes = true;
		int hole[2] = { 0,0 };
		for (int i = 0; i < 10; i++) {
			if (hole[0] < balls[i+j*10]) {
				hole[0] = balls[i + j * 10];
				if (debug)
					cout << "" << balls[i + j * 10] << "\n";
			} else if (hole[1] < balls[i + j * 10]) {
				hole[1] = balls[i + j * 10];
				if (debug)
					cout << "  " << balls[i + j * 10] << "\n";

			} else {
				if (debug)
					cout << "falure\n";
				isYes = false;
				break;
				
			}
		}
		cout << (isYes ? "YES" : "NO") << "\n";
	}
}


Measured memory_bytes: 3104
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    M, D = MAP()
    count = 0
    for mm in range(1, M+1):
        for dd in range(1, D+1):
            d1 = dd % 10
            d10 = dd // 10
            if d1 > 1 and d10 > 1:
                if d1 * d10 == mm:
                    count += 1
    print(count)

if __name__ == '__main__':
    main()


Measured memory_bytes: 39536
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)




int N;
int C[1000], W[1000];
//-----------------------------------------------------------------
bool dp1[1010][1010];
int dp2[1010];
int sm[1010];
int main() {
	cin >> N;
	rep(i, 0, N) scanf("%d%d", &C[i], &W[i]);

	sm[0] = W[0];
	rep(i, 1, N) sm[i] = sm[i - 1] + W[i];

	rep(i, 0, N) dp1[i][i] = true;
	rep(len, 2, N + 1) rep(L, 0, N) {
		int R = L + len - 1;
		if (N <= R) break;

		// L?????????
		if (dp1[L + 1][R]) {
			int wei = sm[R] - sm[L];
			if (wei <= C[L]) dp1[L][R] = true;
		}

		// R?????????
		if (dp1[L][R - 1]) {
			int wei = sm[R - 1];
			if (L != 0) wei -= sm[L - 1];
			if (wei <= C[R]) dp1[L][R] = true;
		}
	}

	dp2[0] = 1;
	rep(R, 1, N) {
		dp2[R] = dp2[R - 1] + 1;
		rep(L, 0, R) {
			if (dp1[L][R]) {
				if(L == 0)
					dp2[R] = min(dp2[R], 1);
				else
					dp2[R] = min(dp2[R], dp2[L - 1] + 1);
			}
		}
	}

	cout << dp2[N - 1] << endl;
}

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

int main()
{
  string s; cin >> s;
  int n = s.length();
  rep(i, n) cout << "x";
  cout << endl;

  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i,n) cin >> v[i];
    sort(v.begin(),v.end());
    rep(i,n-1){
        if(v[i] == v[i+1]){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 1024
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
int dp[1011][5011],ndp[5011];
int n,p[1011],w[1011],sz[1011];
vector<int> son[1011];
void check(int x)
{
	for(int i=0;i<=sz[x];i++)
	{
		if(dp[x][i]<=233333333)return;
	}
	puts("IMPOSSIBLE");
	exit(0);
}
int main()
{
	geti(n);
	for(int i=2;i<=n;i++)geti(p[i]),son[p[i]].PB(i);
	for(int i=1;i<=n;i++)geti(w[i]);
	memset(dp,31,sizeof(dp));
	for(int x=n;x>=1;x--)
	{
		dp[x][0]=0;
		for(int i=0;i<son[x].size();i++)
		{
			int u=son[x][i];
			for(int t=0;t<=min(5000,sz[x]+sz[u]);t++)ndp[t]=mod;
			for(int tx=0;tx<=sz[x];tx++)
			{
				for(int ty=0;ty<=sz[u]&&tx+ty<=5000;ty++)
				{
					ndp[tx+ty]=min(ndp[tx+ty],dp[x][tx]+dp[u][ty]);
				}
			}
			for(int t=0;t<=min(5000,sz[x]+sz[u]);t++)dp[x][t]=ndp[t];
			sz[x]+=sz[u];
			sz[x]=min(sz[x],5000);
			check(x);
		}
		memset(ndp,31,sizeof(ndp));
		for(int t=0;t<=w[x];t++)ndp[w[x]]=min(ndp[w[x]],dp[x][t]);
		for(int t=0;t<=sz[x];t++)if(dp[x][t]<=w[x])ndp[t]=min(ndp[t],w[x]);
		sz[x]=max(sz[x],w[x]);
		for(int t=0;t<=sz[x];t++)dp[x][t]=ndp[t];
		check(x);
	}
	puts("POSSIBLE");
	return 0;
}

Measured memory_bytes: 20096
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N,M,C;cin>>N>>M>>C;
    int ans=0;
    vector<int>B(M);
    for(int i=0;i<M;i++){
        cin >> B[i];
    }
    int A;
    for(int i=0;i<N;i++){
        int sum = C;
        for(int i=0;i<M;i++){
            cin >> A;
            sum += A*B[i];
        }
        if (sum > 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    const string t = "keyence";
    
    bool ans = false;
    for (int i=0; i<=7; i++) {
        for (int j=i; j<n; j++) {
            string ss;
            ss = s.substr(0,i);
            ss += s.substr(j,n-i);
            if (ss == t) ans = true;
        }
    }
    cout << (ans? "YES" : "NO") << endl;
}


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

using namespace std;

const double EPS = 1e-7;
const int N = 1e5+5, M = 1e5+5, OO = 0x3f3f3f3f;
typedef long long ll;

int gcd(int a, int b){
    if(b)   return gcd(b, a%b);
    else return a;
}

ll fixMod(ll a, ll b){
    return (a%b + b)%b;
}

void pushBack(ll& h, ll base, ll mod, char c){
    h = ((h*base)%mod + c)%mod;
}

void pushFront(ll& h, ll p, ll mod, char c){
    h = (h + (c*p)%mod)%mod;
}

void popFront(ll& h, ll p, ll mod, char c){
    h = fixMod((h - (p*c)%mod), mod);
}

void popBack(ll& h, ll inv, ll mod, char c){
    h = (fixMod(h-c, mod)*inv)%mod;
}

ll power(ll a, ll b, ll m){
    if(!b)  return 1;
    ll t = power(a, b>>1, m);
    return ((t*t)%m * (b&1 ? a : 1))%m;
}


int n,x;
vector<pair<int,int>> v;
int main(){
//    freopen("araf_bara.txt", "wt", stdout);
cin>>n;
for(int i=1; i<=n; i++){
    cin>>x;
    v.push_back({x,i});
}
sort(v.begin(), v.end());
for(int i=0; i<n; i++){
    cout<<v[i].second<<" ";
}
cout<<endl;

}


Measured memory_bytes: 1780
s=int(input())
if s+1<=10**9:
  b=str(s+1)
  a=['0','0',b,'1','1','1']
else:
  x2=int(s**(1/2))
  y3=int(s**(1/2))
  while x2*y3<s:
    y3+=1
  if y3>10**9:
    x2+=1
    y3=int(s**(1/2))+1
  x2=str(x2)
  y3=str(y3)
  
  y2=str(1)
  x3=str(int(x2)*int(y3)-s)
  x1=str(0)
  y1=str(0)
  a=[x1,y1,x2,y2,x3,y3]
print((' ').join(a))

Measured memory_bytes: 62316
#include <bits/stdc++.h>
using namespace std; 
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define LINY "YES\n"
#define Liny "Yes\n"
#define LINN "NO\n"
#define Linn "No\n"
#define unordered_map umap
typedef long long ll;
typedef long double ld;
ll min(ll x,ll y){return (x<y ? x:y);}
ll max(ll x,ll y){return (x>y ? x:y);}
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){if(a<b){swap(a,b);} return a*b /gcd(a,b);}
bool isPrime(int n){if(n<2){return false;}for(int i=2;i<sqrt(n)+1;i++){if(n%i==0) return false;}return true;}

int main(){
  int D,N; cin>>D>>N;
  int count=0;
  ll i=0;
  while(count<N){
    i++;
    ll temp=i;
    bool f = true;
    REP(j,D){
      if(temp%100==0){temp/=100;}
      else{f=false; break;}
    }
    if(f){ if(temp%100!=0) count++;}
  }
  printf("%Ld",i);
}


Measured memory_bytes: 256
/*
Author: CNYALI_LK
LANG: C++
PROG: a.cpp
*/
#include<bits/stdc++.h>
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define all(x) x.begin(),x.end()
using namespace std;
const double eps=1e-8;
const double PI=acos(-1.0);
typedef long long ll;
template<class T>void chkmin(T &a,T b){a=a<b?a:b;}
template<class T>void chkmax(T &a,T b){a=a>b?a:b;}
template<class T>T sqr(T a){return a*a;}
template<class T>T mmin(T a,T b){return a<b?a:b;}
template<class T>T mmax(T a,T b){return a>b?a:b;}
template<class T>T aabs(T a){return a<0?-a:a;}
#define min mmin
#define max mmax
#define abs aabs
char s[101010];
int main(){
#ifdef cnyali_lk
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
	scanf("%s",s);
	if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I')printf("Yes\n");
	else printf("No\n");
	return 0;
}



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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int hand[26]={0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,1,0,0,0,1,0,};
  while(1){
    string s;
    cin >> s;
    if(s=="#") return 0;
    int count=0;
    for(int i=1;i<s.length();i++){
      if(hand[s[i-1]-'a']!=hand[s[i]-'a']) count++;
    }
    cout << count << endl;
  }
  return 0;
}



Measured memory_bytes: 3224
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
	int X, t; cin >> X >> t;
	cout << (X > t?X - t:0) << endl;
	return 0;
}

Measured memory_bytes: 256