akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll ch[3][3];
	for(ll i=0;i<3;i++){
		for(ll j=0;j<3;j++){
			cin>>ch[i][j];
		}
	}
	ll n;
	cin>>n;
	map<ll,ll>q;
	for(ll j=0;j<n;j++){
		ll now;
		cin>>now;
		q[now]++;
	}
	for(ll i=0;i<3;i++){
		bool ans=true;
		for(ll j=0;j<3;j++){
			if(q[ch[i][j]]==0){
				ans=false;
			}
		}
		if(ans){
			cout << "Yes";
			return 0;
		}
	}
	for(ll i=0;i<3;i++){
		bool ans=true;
		for(ll j=0;j<3;j++){
			if(q[ch[j][i]]==0){
				ans=false;
			}
		}
		if(ans){
			cout << "Yes";
			return 0;
		}
	}
	if(q[ch[0][0]]&&q[ch[1][1]]&&q[ch[2][2]]){
		cout << "Yes";
		return 0;
	}
	if(q[ch[2][0]]&&q[ch[1][1]]&&q[ch[0][2]]){
		cout << "Yes";
		return 0;
	}	
	cout << "No";
	// your code goes here
	return 0;
}

Measured memory_bytes: 3560
package main

import (
  "fmt"
)

func main() {
  var s string
  fmt.Scanf("%s", &s)
  
  ans := "No"
  for i := 0; i < len(s)-1; i++ {
    if s[i:i+2] == "AC" {
      ans = "Yes"
    }
  }
  fmt.Printf("%s\n", ans)
}

Measured memory_bytes: 1836
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define Rep(var,init,cnt) for(int (var)=(init); (var)<(int)(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(rall(v))
#define SUM(v) accumulate(all(v),0)
#define tget(tp,idx) get<idx>(tp)
#define TF(flag) ((flag)?1:0)
#define YN(flag) cout<<(flag?"YES":"NO")<<endl;
#define Yn(flag) cout<<(flag?"Yes":"No")<<endl;
#define yn(flag) cout<<(flag?"yes":"no")<<endl;
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using ti = tuple<int,int,int>;
using tl = tuple<ll,ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const valarray<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, valarray<T> &v){
  for(T &in:v) is>>in;
  return is;
}

// Usual Template End ===================

// Template End =========================

int main(void){
  int A,B; cin>>A>>B;
  Yn(A%2==1&&B%2==1);
}












Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
// const lint MOD = 998244353;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
	int n;cin>> n;
	ll ans = 0;
	ll m = LINF;
	int count = 0;
	rep(i,n){
		ll a;cin>>a;
		ans += abs(a);
		m = min(m,abs(a));
		if(a < 0)count++;
	}
	cout << (count%2?ans-m*2 : ans) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long x;
  cin >> x;
  for(long long i=-120;i<120;i++){
    for(long long j=-120;j<120;j++){
      if(i*i*i*i*i-j*j*j*j*j==x){
        cout << i << " " << j;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3632
def main():
    import sys
    input=sys.stdin.readline
    n,k=map(int,input().split())
    ab=[list(map(int,input().split())) for _ in [0]*n]
    g=[[] for _ in [0]*10]
    [g[b-1].append(a) for a,b in ab]
    [g[c].sort(reverse=True) for c in range(10)]
    for c in range(10):g[c]=[0]+g[c]
    for c in range(10):
        for i in range(2,len(g[c])):
            g[c][i]+=g[c][i-1]+2*(i-1)
    dp=[0]*(k+1)
    for c in range(10):
        dp2=[0]*(k+1)
        for i in range(len(g[c])):
            for j in range(k+1-i):
                dp2[i+j]=max(dp2[i+j],dp[j]+g[c][i])
        dp=dp2
    print(max(dp))
if __name__=='__main__':
    main()


Measured memory_bytes: 5928
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)
#define REPIT(i,x) for(auto i{(x).begin()}; i != (x).end(); i++) 

#define PB push_back
#define MP make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef double dbl;
typedef vector<bool> Vb;
typedef vector<char> Vc;
typedef vector<double> Vd;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<string> Vs;
typedef vector<vector<int>> VVi;
typedef vector<vector<ll>> VVl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }
inline void YES() { cout << "YES" << endl; } inline void Yes() { cout << "Yes" << endl; }
inline void NO() { cout << "NO" << endl; } inline void No() { cout << "No" << endl; }

const int inf = 1 << 30;
const ll linf = 1LL << 60;
const int MOD = 1000000007;


int main()
{
	int a, p;
	cin >> a >> p;
	cout << (a * 3 + p) / 2 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

int *p;
int **m;

void init(int n){
  int i;
  p = (int*)malloc(sizeof(int) * (n + 1));
  m = malloc(sizeof(int*) * (n + 1));
  for(i=0; i<=n; i++){
    m[i] = malloc(sizeof(int) * (n + 1));
  }
}

int min(int a, int q){
  if (a>q){
    return q;
  }
}

void matrixChainOrder(int n){
  int i,l,j,k,q;

  //printf("point1\n");
  for(i = 1; i <= n; i++){
    m[i][i] = 0;
  }
  //printf("m[i][i] inited\n");
  for(l = 2; l<=n; l++){
    for(i = 1; i<=n-l+1; i++){
      j = i+l-1;
      m[i][j] = INT_MAX;
      for(k = i; k<=j-1; k++){
        q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
        m[i][j] = min(m[i][j],q);
      }
    }
  }
}

int main() {
  int n, garbage;
  int i;

  scanf("%d",&n);
  init(n);
  //printf("Finish init\n");
  //garbage = (int*)malloc(sizeof(int) * n);
  scanf("%d %d",&p[0], &p[1]);
  //printf("%d,%d\n",p[0],p[1] );
  //matrixChainOrder(p[0]);
  //printf("0 fin\n");
  //matrixChainOrder(p[1]);
  for(i=2; i<=n; i++){
    scanf("%d %d",&garbage, &p[i]);
    //matrixChainOrder(p[i]);
  }
  matrixChainOrder(n);
  printf("%d\n",m[1][n]);
  return 0;
}



Measured memory_bytes: 2052
S=input()
N=len(S)
if S[-1]=="1":
    print(-1)
    exit()
if S[0]=="0":
    print(-1)
    exit()
if S[-2]=="0":
    print(-1)
    exit()
for i in range(N-1):
    if S[i]!=S[N-2-i]:
        print(-1)
        exit()
ans=[]
nowzero=0
for i in range(N):
    if S[i]=="0":
        break
    nowzero+=1
if nowzero==N-1:
    for i in range(1,N):
        print(i,i+1)
    exit()
ans.append((1,2))
for i in range(N-2):
    if S[i]=="1":
        if i!=N-2 and S[i+1]=="0":
            nowzero=i+2
        ans.append((i+2,i+3))
    else:
        ans.append((nowzero,i+3))
for line in ans:
    print(line[0],line[1])

Measured memory_bytes: 15968
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()

vector<int> primes;

bool is_prime(int n) {
    if(n < 2) return false;
    else if(n == 2) return true;

    if(n % 2 == 0) return 0;
    for(int i=3; i*i<=n; i+=2) if(n % i == 0) return false;
    return true;
}

void solve(int a,int d,int n) {
    int cnt = 0;
    for(int k=0; ; k++) {
        int t = a + k*d;
        if(binary_search(ALL(primes), t)) ++cnt;
        if(cnt == n) {
            printf("%d\n", t);
            return ;
        }
    }
    return ;
}

int main() {
    FOR(i,1,1e6+1) if(is_prime(i)) primes.push_back(i);
    for(int a,d,n; scanf("%d%d%d",&a,&d,&n) && a; ) solve(a,d,n);
    return 0;
}

Measured memory_bytes: 2784
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    N, Y = NMI()
    for i in range(N+1):
        for j in range(N+1-i):
            k = N - i - j
            if 10000*i + 5000*j + 1000*k == Y:
                print(i, j, k)
                exit()
    print(-1,-1,-1)


if __name__ == "__main__":
    main()

Measured memory_bytes: 9420
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    int n = s.size();
    if (n & 1) {
        cout << "No\n";
    } else {
        for (int i = 0; i < n; i += 2) {
            if (s.substr(i, 2) != "hi") {
                cout << "No\n";
                return 0;
            }
        }
        cout << "Yes\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <climits>
#include <vector>
#include <algorithm>
using namespace std;

bool ne(int* a, int* b){
	for(int i=0; i<4; i++){
		if(a[i]!=b[i]) return true;
	}
	return false;
}
double dot(int* a, int* b){
	return (a[1] - a[0]) * (b[1] - b[0]) + (a[3] - a[2]) * (b[3] - b[2]);
}
double cross(int* a, int* b){
	return (a[1] - a[0]) * (b[3] - b[2]) - (a[3] - a[2]) * (b[1] - b[0]);
}
double chk(vector<int*> vs){
    double mn=LONG_MAX;
    for(int i=0; i<vs.size(); i++) for(int j=0; j<vs.size(); j++) if(ne(vs[i], vs[j])) for(int k=0; k<2; k++){
        int p1q1[4] = { vs[i][0],vs[j][0+k],vs[i][2],vs[j][2+k] };
        int p2q1[4] = { vs[i][1],vs[j][0+k],vs[i][3],vs[j][2+k] };
        int p1q2[4] = { vs[i][0],vs[j][1],vs[i][2],vs[j][3] };
        int q1p1[4] = { vs[j][0],vs[i][0],vs[j][2],vs[i][2] };
        int q1p2[4] = { vs[j][0],vs[i][1],vs[j][2],vs[i][3] };
        if(cross(vs[i], p1q1)*cross(vs[i], p1q2)<0 && cross(vs[j], q1p1)*cross(vs[j], q1p2)<0){
            return 0;
        }
		double p1p2_p1p2 = dot(vs[i],vs[i]);
        double p1q1_p1p2 = dot(p1q1, vs[i]);
        if(p1q1_p1p2 <= 0){
            mn=min(mn,dot(p1q1,p1q1));
        }else if(p1q1_p1p2 >= p1p2_p1p2){
            mn=min(mn,dot(p2q1,p2q1));
        }else{
			double p1q1_x_p1p2 = cross(vs[i], p1q1);
            mn=min(mn,p1q1_x_p1p2*p1q1_x_p1p2/p1p2_p1p2);
        }
    }
    return mn;
}
int main(){
	int N;
	scanf("%d", &N);
	vector<int*> vs(N);
	for(int i=0; i<N; i++){
		vs[i] = new int[4];
		scanf("%d %d %d %d", &vs[i][0], &vs[i][2], &vs[i][1], &vs[i][3]);
	}
	double mn=LONG_MAX;
	for(int split=5; mn==LONG_MAX && split>0; split/=2){
		vector<vector<int*>> area(split*split, vector<int*>());
		if(area.size() == 1){
			area[0] = vs;
		}else{
			for(int i=0;i<N;i++){
				int sx = min(4,split*min(vs[i][0],vs[i][1])/100);
				int ex = split*max(vs[i][0],vs[i][1])/100;
				int sy = min(4,split*min(vs[i][2],vs[i][3])/100);
				int ey = split*max(vs[i][2],vs[i][3])/100;
				for(int x=sx; x<split && x<=ex; x++){
					for(int y=sy; y<split && y<=ey; y++){
						area[x+split*y].push_back(vs[i]);
					}
				}
			}
		}
		for(int x=0; x<split; x++){
			for(int y=0; y<split; y++){
				if(area[x+split*y].size()){
					sort(area[x+split*y].begin(), area[x+split*y].end(), [](int* a,int* b){ return min(a[0]+a[2],a[1]+a[3]) > min(b[0]+b[2],b[1]+b[3]); });
					if(x>0) area[(x-1)+split*y].push_back(area[x+split*y][0]);
					if(y>0) area[x+split*(y-1)].push_back(area[x+split*y][0]);
					if(x*y>0) area[(x-1)+split*(y-1)].push_back(area[x+split*y][0]);
				}
			}
		}
		for(int i=0;i<area.size();i++){
			mn=min(mn,chk(area[i]));
		}
	}
	printf("%f\n", sqrt(mn));
}

Measured memory_bytes: 12564
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, K):
    for i in range(10000000000):
        if K ** i > N:
            return i


def main():
    N, K = read_int_n()
    print(slv(N, K))


if __name__ == '__main__':
    main()


Measured memory_bytes: 6852
import java.util.Scanner;

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

		long min = Long.MAX_VALUE;
		for (int i = 1; i <= (int)Math.sqrt(n); i++) {
			if (n % i == 0) {
				min = Math.min(min, (i - 1) + (n / i - 1));
			}
		}
		System.out.println(min);
	}
}


Measured memory_bytes: 21844
#include <stdio.h>
#include <iostream>
#include <string>

using namespace std;

int main(){
	int A, B, C;
	cin >> A >> B >> C;
	int sum = 0;
	int days = 0;
	while(true){
		if(sum + A*7 + B >= C){
			for(int i = 0; i < 7; i++){
				sum += A;
				days++;
				if(i == 6){
					sum += B;
				}
				if(sum >= C){
					break;
				}
			}
		}
		else{
			sum += A*7 + B;
			days += 7;
		}
		if(sum >= C){
			break;
		}
	}
	cout << days << "\n";
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using P = pair<int,int>;
using ll = long long;
P lp[200005], rp[200005];
int q, n, k, l, r, le, re;
int main(){
	scanf("%d", &q);
	rep(i,q){
		scanf("%d", &n);
		ll ans = le = re = 0;
		priority_queue<int> lqu, rqu;
		rep(i,n){
			scanf("%d%d%d", &k, &l, &r);
			(l < r ? rp[re++] : lp[le++]) = P{k,abs(l-r)};
			ans += min(l,r);
		}
		sort(lp, lp+le, greater<P>());
		sort(rp, rp+re);
		for(int i=le, le2=0; i>0; i--){
			while(le2 < le && lp[le2].first >= i) lqu.push(lp[le2++].second);
			if(!lqu.empty()){
				ans += lqu.top();
				lqu.pop();
			}
		}
		for(int i=le, re2=0; i<n; i++){
			while(re2 < re && rp[re2].first <= i) rqu.push(rp[re2++].second);
			if(!rqu.empty()){
				ans += rqu.top();
				rqu.pop();
			}
		}
		printf("%lld\n", ans);
	}
}

Measured memory_bytes: 5592
N,K = map(int, input().split())
A_list = list(map(int, input().split()))

max_a = max(max(A_list), K)
max_len = 0
tmp = max_a
while tmp > 0:
    max_len += 1
    tmp//=2

K_bits = [1 if (K >> j &1) else 0 for j in range(max_len)][::-1]

sum_1_bits = [0] * max_len
for a in A_list:
    a_bits = [j for j in range(max_len) if (a >> j &1)]
    for bit in a_bits:
        sum_1_bits[bit] += 1
sum_1_bits = sum_1_bits[::-1]

# dp start
# dp[is未満][桁]
dp = [[0] * max_len for i in range(2)]
border = N/2
twice = 2 ** (max_len-1)
highest_digit = 0
i = 0

if K == 0:
    res = 0
    for b in sum_1_bits:
        res += twice * b
        twice //= 2

    print(res)
    exit()
    
while True:
    if K_bits[i] == 1:
        highest_digit = i
        break
    dp[0][i] = dp[0][i-1] + twice * sum_1_bits[i]
    dp[1][i] = dp[1][i-1] + twice * sum_1_bits[i]
    twice //= 2
    i += 1

dp[0][highest_digit] = dp[0][highest_digit-1] + twice * (N-sum_1_bits[highest_digit])
dp[1][highest_digit] = dp[1][highest_digit-1] + twice * sum_1_bits[highest_digit]
twice //= 2

for i in range(highest_digit+1, max_len):

    ibits = sum_1_bits[i]
    dp[1][i] = dp[1][i-1] + twice * max(ibits, N-ibits)
    if K_bits[i] == 1:
        dp[1][i] = max(dp[1][i], dp[0][i-1] + twice * ibits)
    k_side = ibits if K_bits[i] == 0 else N-ibits
    dp[0][i] = dp[0][i-1] + twice * k_side
    twice //= 2

print(max(dp[0][-1],dp[1][-1]))


Measured memory_bytes: 20620
#include <stdio.h>
#include <set>

using namespace std;

set<unsigned int> hashList;

int make_face(char input)
{
	int ret;
	
	switch (input){
	  case 'R': ret = 0; break;
	  case 'G': ret = 1; break;
	  case 'B': ret = 2; break;
	  case 'C': ret = 3; break;
	  case 'M': ret = 4; break;
	  case 'Y': ret = 5; break;
	}
	
	return (ret);
}

unsigned int make_hash(int cube[])
{
	int ret;
	
	ret = 0;
	for (int i = 0; i < 6; i++){
		ret = ret * 6 + cube[i];
	}
	
	return (ret);
}

int rote_x(int cube[])
{
	int temp;
	
	temp = cube[1];
	cube[1] = cube[3];
	cube[3] = cube[4];
	cube[4] = cube[2];
	cube[2] = temp;
	
	return (0);
}

int rote_y(int cube[])
{
	int temp;
	
	temp = cube[0];
	cube[0] = cube[3];
	cube[3] = cube[5];
	cube[5] = cube[2];
	cube[2] = temp;
	
	return (0);
}

int rote_z(int cube[])
{
	int temp;
	
	temp = cube[0];
	cube[0] = cube[4];
	cube[4] = cube[5];
	cube[5] = cube[1];
	cube[1] = temp;
	
	return (0);
}

int main(void)
{
	int cube[6];
	int ans;
	int n;
	
	while (1){
		hashList.clear();
		
		scanf("%d", &n);
		
		if (n == 0){
			 break;
		}
		
		ans = 0;
		for (int i = 0; i < n; i++){
			for (int j = 0; j < 6; j++){
				char str[20];
				
				scanf("%s", str);
				cube[j] = make_face(str[0]);
			}
			if (hashList.find(make_hash(cube)) != hashList.end()){
				ans++;
				continue;
			}
			for (int i = 0; i < 4; i++){
				for (int j = 0; j < 4; j++){
					for (int k = 0; k < 4; k++){
						hashList.insert(make_hash(cube));
						rote_x(cube);
					}
					rote_y(cube);
				}
				rote_z(cube);
			}
		}
		
		printf("%d\n", ans);
	}
	
	return (0);
}

Measured memory_bytes: 0
#include<stdio.h>
int b[1000],c[1000],d[1000],e[1000],a;
int main(){
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++)scanf("%d%d%d%d",b+i,c+i,d+i,e+i);
		int p,q,r,s;
		scanf("%d%d%d%d",&p,&q,&r,&s);
		bool ok=false;
		for(int i=0;i<a;i++){
			if(c[i]<=p&&d[i]<=q&&e[i]<=r&&4*c[i]+9*d[i]+4*e[i]<=s){
				ok=true;
				printf("%d\n",b[i]);
			}
		}
		if(!ok)printf("NA\n");
	}
}


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

const int INF = INT_MAX / 2;

template <class T> inline bool chmin(T& a, T b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int N, M, R;
  cin >> N >> M >> R;
  vector<int> rs(R);
  for(int i = 0; i < R; ++i) {
    cin >> rs[i];
  }
  vector<vector<int>> d(N, vector<int>(N, INF));
  int a, b, c;
  for(int i = 0; i < M; ++i) {
    cin >> a >> b >> c;
    d[a - 1][b - 1] = c;
    d[b - 1][a - 1] = c;
  }
  for(int i = 0; i < N; ++i) {
    d[i][i] = 0;
  }

  for(int k = 0; k < N; ++k) {
    for(int i = 0; i < N; ++i) {
      for(int j = 0; j < N; ++j) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  // 最短距離はここで計算できた
  sort(rs.begin(), rs.end());
  int md = INF;
  do {
    int dd = 0;
    int p = rs[0];

    for(auto n : rs) {
      dd += d[p - 1][n - 1];
      p = n;
    }
    chmin(md, dd);
  } while(next_permutation(rs.begin(), rs.end()));

  cout << md << endl;
  return 0;
}

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

constexpr int inf = 0x3FFFFFFF;
int dist[15][15];
int dp[1<<15][15];

void read_dist(int V, int E){
    for (int i = 0; i != V; ++i){
        for (int j = 0; j != V; ++j){
            dist[i][j] = inf;
        }
    }
    while (E--){
        int s, t, d;
        cin >> s >> t >> d;
        dist[s][t] = d;
    }
}

int TSP(int V);
void init_dp(int V);
vector<int> find_visited_vertex(int mask);

int main()
{
    int V = 0;
    int E = 0;
    cin >> V >> E;
    read_dist(V, E);
    cout << TSP(V) << endl;
    return 0;
}

int TSP(int V){
    init_dp(V);
    int all = 1 << V;
    for (int mask = 1; mask != all; ++mask){
        auto vs = find_visited_vertex(mask);
        for (auto v : vs){
            int prev_mask = mask ^ (1 << v);
            for (auto u : vs){
                if (v == u) continue;
                dp[mask][v] = min(dp[mask][v], dp[prev_mask][u] + dist[u][v]);
            }
        }
    }
    int min_cost = dp[all - 1][V - 1];
    return (min_cost < inf) ? min_cost : -1;
}

void init_dp(int V){
    for (int mask = 0; mask != 1 << V; ++mask){
        for (int i = 0; i != V; ++i){
            dp[mask][i] = inf;
        }
    }
    dp[0][V - 1] = 0;
    for (int i = 0; i != V - 1; ++i) dp[1 << i][i] = dist[V - 1][i];
}

vector<int> find_visited_vertex(int mask){
    vector<int> vs;
    int idx = 0;
    while (mask){
        if (mask & 1) vs.push_back(idx);
        ++idx;
        mask >>= 1;
    }
    return vs;
}

Measured memory_bytes: 5068
import bisect
A, B, Q = map(int, input().split())
INF = 10**18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]

for q in range(Q):
    x = int(input())
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = INF
    for S in [s[b-1], s[b]]:
        for T in [t[d-1], t[d]]:
            d1, d2 = abs(S-x) + abs(T-S), abs(T-x) + abs(S-T)
            res = min(res, d1, d2)
    print(res)


Measured memory_bytes: 14464
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
//const long long INF = 1LL << 60;
 int INF = 500000;
 int MAX = 1e5+10;
 ll mod = 1e9+7;

int main(){
  int n,k;
  string s;
  cin >> n >> k >> s;
  s[k-1] = 'a' + (s[k-1] - 'A');
  cout << s << endl; 
}

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

using namespace std;

int main() {
    string s;
    cin >> s;
    string res;
    res += s[0];
    int n = s.length();
    for (int i = 1; i < n; i++) {
        if (s[i] != res.back()) {
            res += s[i];
        }
    }
    cout << res.length() - 1;
    return 0;
}


Measured memory_bytes: 512
# -*- coding:utf-8 -*-

def solve():
    S = input()

    num0 = 0
    num1 = 0
    for moji in S:
        if moji == "0":
            num0 += 1
        else:
            num1 += 1
    erase_num = min(num0, num1)
    print(erase_num*2)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 3244
import sys
n = int(input())
time = [list(map(int,input().split())) for i in range(n)]
time.sort(key=lambda x: x[1])
sum = 0
for i in range(n):
    sum += time[i][0]
    if sum > time[i][1]:
        print('No')
        sys.exit()
print('Yes')


Measured memory_bytes: 53600
#include<iostream>

#define rep(i, s, n) for (int i = s; i <= n; i++)

using namespace std;
 
int main()
{
    int k,n;
    cin >> k >> n;

    int a[n];
    rep(i,0,n-1) cin >> a[i];

    int max = 0;
    rep(i,1,n-1)
    {
        int tmp = a[i] - a[i-1];
        if(tmp>max) max = tmp;
    }
    int tmp = k - a[n-1] + a[0];
    if(tmp>max) max = tmp;
    int ans= k-max;

    cout << ans << endl;

    return 0;
}

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

long long n, x, ans, p, cur;

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	cin >> n >> x;

	x = min(x, n - x);

	ans += x;
	ans += n - x;

	p = n - x;
	cur = x;

	while(cur > 0) {
		ans += 2 * (p / cur) * cur;
		p %= cur;
		swap(p, cur);
	}

	cout << ans - p << '\n';
	
	return 0;

}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

inline void fastio () {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
}

#define whats(x) cerr << #x << " = " << (x) << "\n"; 

using LL = long long;
using LD = long double;

const LL INF = LLONG_MAX;
const LL MOD = 998244353;
const LL N = 2e5+1;

int main() {
	fastio();

	LL a, b = 0;
	cin >> a;
	string s;
	cin >> s;
	for (auto e : s) {
		if (e != '.') {
			b += (e-'0');
			b *= 10;
		}
	}
	b /= 10;

	cout << a*b/100 << "\n";

}

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

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;

#define endl '\n'
#define ff first
#define ss second
#define sz(v) (int)v.size()
#define int long long
#define pb push_back
#define f(i,l,r) for(ll i=l;i<=r;i++)
#define rf(i,r,l) for(ll i=r;i>=l;i--)
#define Max 5000001
#define inf 2147483647
#define llinf 9223372036854775807
#define all(v) v.begin(),v.end()
#define bp(n) __builtin_popcountll(n)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

#define d0(a) cout<<a<<' ';
#define d1(a) cout<<a<<endl;
#define d2(a,b) cout<<a<<' '<<b<<endl;
#define d3(a,b,c) cout<<a<<' '<<b<<' '<<c<<endl;
#define d4(a,b,c,d) cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
#define d5(a,b,c,d,e) cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<endl;
#define d6(a,b,c,d,e,f) cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<' '<<f<<endl;

const ll N=1e5+5,mod=1e9+7,bit=61;



signed main()
{
    fast;

    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll a,b,c,k;
        cin>>a>>b>>c>>k;
        ll tk=min(k,a);
        ll ans=tk;
        k-=tk;
        tk=min(k,b);
        k-=tk;
        ans-=k;
        cout<<ans<<endl;
    }
    return 0;
}


















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

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

struct Node {
    int   key;
    Node *right, *left, *parent;
};

Node *root, *NIL;

Node *find(Node *u, int k) {
    while (u != NIL && k != u->key) {
        if (k < u->key)
            u = u->left;
        else
            u = u->right;
    }
    return u;
}

void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z        = (Node *)malloc(sizeof(Node));
    z->key   = k;
    z->left  = NIL;
    z->right = NIL;

    while (x != NIL) {
        y = x;
        if (z->key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }

    z->parent = y;
    if (y == NIL) {
        root = z;
    } else {
        if (z->key < y->key) {
            y->left = z;
        } else {
            y->right = z;
        }
    }
}

void inorder(Node *u) {
    if (u == NIL) return;
    if (u == NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u) {
    if (u == NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

int main() {
    int    n, i, x;
    string com;
    cin >> n;

    rep(i, n) {
        cin >> com;
        if (com == "find") {
            cin >> x;
            Node *t = find(root, x);
            if (t != NIL) {
                cout << "yes" << endl;
            } else {
                cout << "no" << endl;
            }
        } else if (com == "insert") {
            cin >> x;
            insert(x);
        } else if (com == "print") {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }

    return 0;
}



Measured memory_bytes: 21932
import std.stdio;
void main() {
	int h, w;
	for (;;) {
		"%d %d\n".readf(&h, &w);
		if (h == 0 && w == 0) break;
		foreach (j; 0..h) {
			foreach (i; 0..w) {
				if (j == 0 || j == h - 1)
					"#".write;
				else {
					if (i == 0 || i == w - 1) "#".write;
					else ".".write;
				}
				if (i == w - 1) "".writeln;
			}
		}
		"".writeln;
	}
}

Measured memory_bytes: 2464
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  long ans = 1;
  long sum[n+1];
  int i;
  int a[n]={};
  a[0]=1;
  for(i=0;i<m;i++){
    cin >> a[i];
  }
  sum[0]=1;
  sum[1]=1;
  for(i=2;i<=n;i++){
    sum[i] = (sum[i-1]+sum[i-2])%1000000007;
  }
  ans *= sum[a[0]-1];
  for(i=1;i<m;i++){
    if(a[i-1]+1==a[i]){
      ans = 0;
      break;
    }else ans *= sum[a[i]-a[i-1]-2];
    ans %= 1000000007;
  }
  if(m!=0)ans *= sum[n-a[m-1]-1];
  if(m==0)ans = sum[n];
  ans %= 1000000007;
  cout << ans;
}


Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<string>
#include<cstring>
#include<functional>

#define rep(i,a,b) for(int (i) = (a) ; (i) < (b) ; (i) ++)

using namespace std;

int main(){
	int A,B;
	cin >> A >> B;
	if(A < 10 && B < 10) cout << A * B << endl; else cout << "-1" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    if(0 < a && a < 10 && 0 < b && b < 10)cout << a*b;
    else cout << -1;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
template<class S>void tf(bool b,S t,S f){cout<<(b?t:f)<<endl;}
void OUT(bool b){tf(b,"YES","NO");}
void Out(bool b){tf(b,"Yes","No");}
void out(bool b){tf(b,"yes","no");}
template<class T>void puta(T&&t){cout<<t<<endl;}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}

int popcnt(int x){return __builtin_popcount(x);}
int popcnt(ll x){return __builtin_popcountll(x);}
int bsr(int x){return 31 - __builtin_clz(x);}
int bsr(ll x){return 63 - __builtin_clzll(x);}
int bsf(int x){return __builtin_ctz(x);}
int bsf(ll x){return __builtin_ctzll(x);}
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}

/*他のライブラリを入れる場所*/

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vi a(1000001,-1);
	int c=1;
	while(1){
		if(a[n]!=-1){
			cout<<c<<endl;
			return 0;
		}
		a[n]=c;
		if(n%2==0)n/=2;
		else n=n*3+1;
		c++;
	}
	return 0;
}

Measured memory_bytes: 4224
class segmentTreeOR():
    initValue = 0
    dat = []
    lenTreeList = -1
    depthTreeList = 0
    lenOriginalList = -1

    def __init__(self):
        pass

    def load(self, l):
        # len(l)個よりも大きい2の二乗を得る
        self.lenOriginalList = len(l)
        self.lenTreeList = 2 ** (len(l) - 1).bit_length()  # len 5 なら 2^3 = 8
        self.depthTreeList = (len(l) - 1).bit_length()  # 木の段数(0 origin)
        self.dat = [self.initValue] * (self.lenTreeList * 2)
        # 値のロード
        for i in range(len(l)):
            self.dat[self.lenTreeList - 1 + i] = l[i]
        self.build()

    def build(self):
        for i in range(self.lenTreeList - 2, -1, -1):
            self.dat[i] = self.dat[2 * i + 1] | self.dat[2 * i + 2]

    def setValue(self, i, a):
        """
        set a to list[i]
        """
        # print("setValue: {0}, {1}".format(i, a))
        nodeId = (self.lenTreeList - 1) + i
        # print(" first nodeId: {0}".format(nodeId))
        self.dat[nodeId] = a
        while nodeId != 0:
            nodeId = (nodeId - 1) // 2
            # print(" next nodeId: {0}".format(nodeId))
            self.dat[nodeId] = self.dat[nodeId * 2 + 1] | self.dat[nodeId * 2 + 2]

    def querySub(self, a, b, nodeId, l, r):
        """
        [a,b) 区間の親クエリに対するノードnodeへ[l, r)の探索をデリゲート
        区間については、dataの添え字は0,1,2,3,4としたときに、
        [0,3)なら0,1,2の結果を返す
        """
        # print("querySub: a={0}, b={1}, nodeId={2}, l={3}, r={4}".format(a, b, nodeId, l, r))
        if (r <= a or b <= l):
            return self.initValue
        if a <= l and r <= b:
            return self.dat[nodeId]
        resLeft = self.querySub(a, b, 2 * nodeId + 1, l, (l + r) // 2)
        resRight = self.querySub(a, b, 2 * nodeId + 2, (l + r) // 2, r)
        return resLeft | resRight

    def query(self, a, b):
        return self.querySub(a, b, 0, 0, self.lenTreeList)

### ここまでライブラリ ###

n = int(input())
s = input()
sl = list(s)
sl = list(map(lambda x: ord(x) - ord("a"), sl))
l = list(map(lambda x: 1 << x, sl))
st = segmentTreeOR()
st.load(l)

q = int(input())
for _ in range(q):
    ty, x, y = input().split()
    x = int(x)
    if ty == "1":
        nind = ord(y[0]) - ord("a") # 置き換える文字のaからの距離
        st.setValue(x-1, 1 << nind)
    elif ty == "2":
        x = int(x) - 1 # 1 origin -> 0 origin
        y = int(y)  # こっちは開区間なのでこのまま
        res = 0
        cnt = st.query(x, y)
        print(bin(cnt).count("1")) # popcount()
    else:
        print("error")

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

int main(){
    string s;
    cin >> s;
    int c = 0; 
    if(s[0] == '1'){
       c++;
    } 
    if(s[1] == '1'){
       c++;
    }
    if(s[2]=='1'){
       c++;
    }
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define REP(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)((x).size()))

const double PI  = acos(-1.0);
const double EPS = 1e-9;
const ll INF = 1e9+10;
const ll mod = 1e9+7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define print(x) cerr << #x << " is " << x << endl;

ll pcnt[3], plim[3];
int main() {
    ll X, Y, A, B, C, p, ans = 0;
    cin >> X >> Y >> A >> B >> C;
    vector<P> D(A + B + C);
    plim[0] = X;
    plim[1] = Y;
    plim[2] = C;
    rep(i, A){
        cin >> p;
        D.push_back(make_pair(p, 0));
    }
    rep(i, B){
        cin >> p;
        D.push_back(make_pair(p, 1));
    }
    rep(i, C){
        cin >> p;
        D.push_back(make_pair(p, 2));
    }
    sort(ALL(D), greater<P>());
    
    int cnt = 0;
    for (int i = 0; i < A + B + C; i++){
        ll val = D[i].first;
        ll kind = D[i].second;
        if (pcnt[kind] < plim[kind]){
            ans += val;
            pcnt[kind]++;
            cnt++;
        }
        if (cnt == X + Y){
            break;
        }
        //cout << D[i].first << " " << D[i].second << endl;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 11520
//# define FLAG
///delet.........
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# include <iostream>
# include <fstream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <math.h>
# include <algorithm>
using namespace std;
# define pi acos(-1.0)
# define IOS ios::sync_with_stdio(false)
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define For(i,n,a) for(int i=n; i>=a; --i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define Fo(i,n,a) for(int i=n; i>a ;--i)
typedef long long LL;
typedef unsigned long long ULL;
inline int Scan() {
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
///coding...

map<int,int>M;
int a[200005],b[200005];

int main()
{
#ifdef FLAG
    freopen("in.txt","r",stdin);
#endif /// FLAG
    int n,m;
    bool flag=0;
    cin>>n>>m;
    FOR(i,1,m) {
        cin>>a[i]>>b[i];
        if(a[i]==1)M[b[i]]++;
    }
    FOR(i,1,m) {
        if(M[a[i]]&&b[i]==n)flag=1;
    }
    if(flag)puts("POSSIBLE");
    else puts("IMPOSSIBLE");
    return 0;
}
///delete # define FLAG...


















Measured memory_bytes: 11136
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int h = sc.nextInt();
    int w = sc.nextInt();
    String blank = sc.nextLine();
    String[] s = new String[h];

    for(int i = 0; i < h; i++){
      s[i] = sc.nextLine();
    }

    for(int i = 0; i < w+2; i++){System.out.print('#');}
    System.out.println("");
    for(int i = 0; i < h; i++){
      System.out.print('#');
      System.out.print(s[i]);
      System.out.println('#');
    }
    for(int i = 0; i < w+2; i++){System.out.print('#');}
    System.out.println("");
    

  }
}

/*
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String blank = sc.nextLine();
String s = sc.nextLine();
System.out.println();
System.exit(0)
*/


Measured memory_bytes: 22228
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;

int n;
vector<vector<pair<int, int>>> v;

bool judge(int bit){
     for(int i = 0; i < n; i++){
           if(!(bit & (1 << i)))continue;
           
           for(auto it : v[i]){
               int x = it.first;
               int y = it.second;
               if(y == 1 && !(bit & (1 << x)))return false;
               if(y == 0 && (bit & (1 << x))) return false;
            }
     }
     return true;
}

int main() {
   cin >> n;
   v.resize(n);
   rep(i,n){
       int a; cin >> a;
       v[i].resize(a);
       rep(j,a){
           cin >> v[i][j].first >> v[i][j].second;
           v[i][j].first--;
        }
   }

   int ans = 0;
   for(int bit = 0; bit < (1 << n); bit++){
      
        if(judge(bit)){
            int count = 0;
            for(int i = 0; i < n; i++){
                if(bit & (1 << i)) count++;
            }
            ans = max(ans,count);
        }
    } 
    print(ans);
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.TreeMap;

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

    void solve(Scanner sc) {
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] ps = new int[m];
        int[] ys = new int[m];
        HashMap<Integer, Map<Integer, Integer>> pyMap = new HashMap<>(n);
        for (int i = 0; i < m; i++) {
            ps[i] = sc.nextInt();
            ys[i] = sc.nextInt();
            pyMap.computeIfAbsent(ps[i], (e) -> new TreeMap<Integer, Integer>()).put(ys[i], i);
        }

        String[] ans = new String[m];
        for (Entry<Integer, Map<Integer, Integer>> e : pyMap.entrySet()) {
            int index = 1;
            for (Entry<Integer, Integer> y : e.getValue().entrySet()) {
                ans[y.getValue()] = String.format("%06d%06d", e.getKey(), index++);
            }
        }

        Arrays.stream(ans).forEach(System.out::println);
    }
}


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

// dp[i][j][k] :=     i: 上位 i 桁目まで決定
//                    j: small(数字を自由に選べる)か
//                    k: {3,5,7} を選んだかのflag
//                    の条件を満たす数値の数
int dp[11][2][8];

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

  string n;
  cin >> n;

  int len = n.size();
  dp[0][0][0] = 1;

  for (int i = 0; i < len; ++i)
  {
    for (int j = 0; j < 2; ++j)
    {
      for (int k = 0; k < 8; ++k)
      {
        if (!dp[i][j][k]) continue;

        if (j == 1)                  // small ([0, 9] から数字を選べる)か
        {
          if (!k) dp[i + 1][1][0] += dp[i][1][0];

          dp[i + 1][1][k | 1] += dp[i][1][k];              // +3
          dp[i + 1][1][k | 2] += dp[i][1][k];              // +5
          dp[i + 1][1][k | 4] += dp[i][1][k];              // +7
        }
        else                         // not small ([0, d] から数字を選べる)か
        {
          int d = n[i] - '0';

          if (!k)     dp[i + 1][1][0]     += dp[i][0][0];

          if (d == 3) dp[i + 1][0][k | 1] += dp[i][0][k];  // +3
          if (3 < d)  dp[i + 1][1][k | 1] += dp[i][0][k];  // +3
          if (d == 5) dp[i + 1][0][k | 2] += dp[i][0][k];  // +5
          if (5 < d)  dp[i + 1][1][k | 2] += dp[i][0][k];  // +5
          if (d == 7) dp[i + 1][0][k | 4] += dp[i][0][k];  // +7
          if (7 < d)  dp[i + 1][1][k | 4] += dp[i][0][k];  // +7
        }
      }
    }
  }

  int ans = dp[len][0][7] + dp[len][1][7];
  cout << ans << endl;
//  Debug Coding 
/*for (int i = 0; i <= len; ++i)
    for (int j = 0; j < 2; ++j)
      for (int k = 0; k < 8; ++k)
        if (dp[i][j][k])
        {
          cout << "dp[" << i << "][" << j << "][" << k << "] = (";
          cout << dp[i][j][k] << ")" << endl;
        }
*/
  return 0;
}

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

signed main(){
    int A,B,C,X,Y;
    cin >> A >> B >> C >> X >> Y;
    int ans = A*X+B*Y;
    for (int i = 0; i <= max(X,Y); i++) {
        if (C*2*i+(X-i)*A+(Y-i)*B < ans) {
            if((X-i)*A < 0 || (Y-i)*B < 0) {
                if(C*2*i+(X-i)*A+(Y-i)*B-min((X-i)*A,(Y-i)*B) < ans) {
                    ans = C*2*i+(X-i)*A+(Y-i)*B-min((X-i)*A,(Y-i)*B);
                }
            }
            else {
            ans = C*2*i+(X-i)*A+(Y-i)*B;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#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() {
    int h, w, n;
    cin >> h >> w >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int c = 0;
    rep(i,h) {
        vector<int> ans(w);
        rep(j,w){
            ans[j]=c+1;
            a[c]--;
            if(a[c]==0) c++;
        }
        if(i%2) reverse(all(ans));
        rep(k,w) cout << ans[k] << " ";
        cout << endl;
    }
  
    return 0;
}

Measured memory_bytes: 3612
import numpy as np
#from numba import njit

#(N, K) = map(int, input().split())
#A = np.array(list(map(int, input().split())))
N = int(input())
h = np.array(list(map(int, input().split())))

#@njit

def solve(N,h):
    s = 0
    while (np.any(h > 0)):
        w = np.where(h > 0)[0]
        l = w[0]
        r = w[0]
        i = 1
        while (i < len(w)):
            if (w[i] == r + 1):
                r = w[i]
            i += 1
        
        h = np.concatenate([h[:l], h[l:r+1]-1, h[r+1:]])
        s += 1
    return s

print(solve(N,h))


Measured memory_bytes: 27324
#include<iostream>
#include<algorithm>
#include <string>
#include<cstdio>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
using namespace std;
typedef long long ll;

int main()
{
	int n,f=0; cin >> n;
	int a[10000] = { 0 };
	REP(i, n) {
		int gomi;
		cin >> gomi;
		if (gomi >= 3200) {
			f++;
		}
		a[gomi / 400] += 1;

	}
	int g = 0;
	REP(i, 8) {
		if (a[i]) { g++; }
	}
	if (g ) {
		cout << g << " ";
	}
	else { cout << 1 << " "; }
	//if (f + g >= 8) { cout << 8 << endl; }
	 cout << f + g << endl; 
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define mem(a,b) memset((a),(b),sizeof(a))
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) x.size()
#define all(x) x.begin(),x.end()
using namespace std;
#define _GLIBCXX_PERMIT_BACKWARD_HASH
#include <ext/hash_map>
using namespace __gnu_cxx;
struct str_hash{size_t operator()(const string& str)const{return __stl_hash_string(str.c_str());}};
typedef long long ll;
typedef unsigned long long ull;
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDD pair<double,double>
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-8;
const int MAX=1e5+10;
const ll mod=1e9+7;
int main()
{
	ll x,y;
	while(~scanf("%lld%lld",&x,&y))
	{
		if(__gcd(x,y)==y) puts("-1");
		else printf("%lld\n",x*(y-1));
	}
	return 0;
}

Measured memory_bytes: 256
def main():
    N, K = map(int, input().split())
    H = list(map(int, input().split()))
    H2 = sorted(H)
    a = N-K
    if N-K >= 0:
        print(sum(H2[0:N-K]))
    elif N-K < 0:
        print(0)


if __name__ == "__main__":
    main()

Measured memory_bytes: 26360
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
	int a,b,c,t,h,x,i,j,k,n;
	cin>>n;
	cin>>t;
	cin>>a;
	a=a*1000;
	t=t*1000;
	b=100000000;
	for(i=1;i<=n;i++){
		cin>>h;
		x=t-h*6;
		if(a>x) x=a-x;
		else x=x-a;
		if(x<b){
			b=x;
			c=i;
		}
	}
	cout<<c<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if (n >= 1000) {
            System.out.println("ABD");
        }else{
            System.out.println("ABC");
        }
    }
}

Measured memory_bytes: 21716