akhauriyash/Code-Regression huggingface dataset:
N = int(input())
d_list = list(map(int, input().split()))

mod = 998244353

if d_list[0] != 0:
    print(0)
    exit()

from collections import Counter

counter = Counter(d_list)

if counter[0] != 1:
    print(0)
    exit()

prev = 0
max_d = max(d_list)
ans = 1
for i in range(1, max_d + 1):
    if i == 1:
        if counter[i] != 0:
            ans = 1
        else:
            print(0)
            exit()
    else:
        if counter[i] != 0:
            ans *= prev ** counter[i]
            ans %= mod
        else:
            print(0)
            exit()
    prev = counter[i]

print(ans)


Measured memory_bytes: 19808
import java.util.*;
public class Main {
	static int mai,n;
	static int ue[]=new int[201];
	static int sita[]=new int[201];
	static int hade[]=new int[201];
	static int kion[]=new int[201];
	static int m[][]=new int[201][201];
	static int bfs(int day,int kei,int a){//aは前の派手さ
		if(n+1==day)return kei;
		if(m[day][a]>=0)return kei+m[day][a];
		int max=-1;
		boolean sw=false;
		for(int i=0;i<mai;i++){
			if(kion[day]<sita[i]||kion[day]>ue[i])continue;
			if(sw=false){
				sw=true;
				max=bfs(day+1,kei+Math.abs(a-hade[i]),hade[i]);
			}
			max=Math.max(bfs(day+1,kei+Math.abs(a-hade[i]),hade[i]),max);
		}
		m[day][a]=max-kei;
		return max;
	}
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		n = in.nextInt();
		mai = in.nextInt();
		for(int i=1;i<=n;i++)kion[i]=in.nextInt();
		for(int i=0;i<mai;i++){
			sita[i]=in.nextInt();
			ue[i]=in.nextInt();
			hade[i]=in.nextInt();
		}
		for(int i=0;i<201;i++){
			for(int k=0;k<201;k++)m[i][k]=-1;
		}
		int max=0;
		for(int i=0;i<mai;i++){
			if(kion[1]<sita[i]||kion[1]>ue[i])continue;
			max=Math.max(bfs(2,0,hade[i]),max);
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 22824
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <map>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())
#define AsceSort(a) sort(a.begin(),a.end())

using namespace std;
typedef long long ll;

int main(void) {
	int n;
	cin >> n;
	if (n == 1) {
		cout << "Hello World" << endl;
	}
	else if (n == 2) {
		int a, b;
		cin >> a >> b;
		cout << a + b << endl;
	}
	return 0;
}



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

typedef long long ll;
typedef long double ld;
typedef string str;

#define f(i, begin, end) for (auto i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define trav(v) for (auto &x : v)
#define dis(v) trav(v) cout << x << " ";
#define deb(x) cerr << #x << ":" << x << "\n"
#define debv(v) trav(v) cerr << x << " ";
#define all(v) v.begin(), v.end()
#define nl cout << "\n"

int main()
{

    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t = 1;
    // cin >> t;
    while (t--)
    {
        ll a, b, n, m, i, j, k;
        str s1, s2;
        char ch;
        cin >> n;
        cin >> s1 >> s2;
        f(i, 0, n) cout << s1[i] << s2[i];
        nl;
        // cin >> n;
        // vector<ll> v(n);
        // f(i, 0, n) cin >> v[i];
    }
    return 0;
}

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

const int RLEN=1<<18|1;
inline char nc() {
	static char ibuf[RLEN],*ib,*ob;
	(ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
	return (ib==ob) ? -1 : *ib++;
}
inline int rd() {
	char ch=nc(); int i=0,f=1;
	while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();}
	while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();}
	return i*f;
}

const int N=1e5+50;

int n,ans[N];
vector <int> g[N];
struct Tree {
	int rt,col[N];
	vector <int> edge[N];
	inline int dfs(int x,int f) {
		vector <int> vec;
		int sum=1;
		for(auto v:edge[x]) {
			int t=dfs(v,x);
			sum^=1;
			if(t) vec.push_back(t);
		}
		if(sum) vec.push_back(x);
		while(vec.size()>2) {
			int u=vec.back(); vec.pop_back();
			int v=vec.back(); vec.pop_back();
			g[u].push_back(v); g[v].push_back(u);
		} return col[x]=sum,vec.size()?vec[0]:0;
	}
	inline void init() {
		for(int i=1;i<=n;i++) {
			int f=rd();
			if(~f) edge[f].push_back(i);
			else rt=i; 
		} dfs(rt,0);
	}
} T[2];
inline void dfs(int x,int c) {
	ans[x]=c;
	for(auto v:g[x])
		if(!~ans[v]) dfs(v,c^1);
}
int main() {
	n=rd(); 
	T[0].init(); 
	T[1].init();
	for(int i=1;i<=n;i++) 
		if(T[0].col[i]^T[1].col[i]) return puts("IMPOSSIBLE"),0;
	for(int i=1;i<=n;i++) ans[i]=-1;
	for(int i=1;i<=n;i++) if(!~ans[i]) dfs(i,0);
	puts("POSSIBLE");
	for(int i=1;i<=n;i++)
		printf("%d ",T[0].col[i] ? (ans[i]?1:-1) :0);
}

Measured memory_bytes: 20992
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    H, W = map(int, readline().split())
    A = [list(map(int, readline().split())) for _ in range(H)]
    B = [list(map(int, readline().split())) for _ in range(H)]

    M = 0
    G = [[0] * W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            G[i][j] = abs(A[i][j] - B[i][j])
            if M < G[i][j]:
                M = G[i][j]

    M *= max(H, W)
    dp = [[0] * W for _ in range(H)]
    dp[0][0] = 1 << (M + G[0][0]) | 1 << (M - G[0][0])

    for i in range(H):
        for j in range(W):
            if i + 1 < H:
                dp[i + 1][j] |= (dp[i][j] >> G[i + 1][j]) | (dp[i][j] << G[i + 1][j])
            if j + 1 < W:
                dp[i][j + 1] |= (dp[i][j] >> G[i][j + 1]) | (dp[i][j] << G[i][j + 1])

    ans = INF
    for i in range(2 * M + 2):
        if dp[H - 1][W - 1] & (1 << i) and ans > abs(i - M):
            ans = abs(i - M)

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 85692
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;
using Data = pair<long long, vector<int> >;

int main() {
    vector<long long> N(3);
    int K;
    for (int i = 0; i < 3; ++i) cin >> N[i]; cin >> K;
    vector<vector<long long> > v(3);
    for (int iter = 0; iter < 3; ++iter) {
        v[iter].resize(N[iter]);
        for (int i = 0; i < N[iter]; ++i) cin >> v[iter][i];
        sort(v[iter].begin(), v[iter].end(), greater<long long>());
    }
    priority_queue<Data> que;
    set<Data> se;
    que.push(Data(v[0][0] + v[1][0] + v[2][0], vector<int>({0, 0, 0})));
    for (int k = 0; k < K; ++k) {
        auto c = que.top();que.pop();
        cout << c.first << endl;
        
        // 次の三候補
        for (int iter = 0; iter < 3; ++iter) {
            if (c.second[iter] + 1 < N[iter]) {
                long long sum = c.first - v[iter][c.second[iter]] + v[iter][c.second[iter] + 1];
                auto num = c.second; num[iter]++;
                auto d = Data(sum, num);
                
                // すでに push されたもの以外
                if (!se.count(d)) se.insert(d), que.push(d);
            }
        }
    }
}

Measured memory_bytes: 1408
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <limits.h>
#include <assert.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <bitset>
#include <vector>
using namespace std;

#define LL long long

#define fi first
#define se second
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(a,b) (((a)+(b))>>1)
#define maxx(a,b) ((a)<(b)?(b):(a))
#define minx(a,b) ((a)<(b)?(a):(b))
#define absx(a) ((a)<0?-(a):(a))
#define mk(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define itr iterator
#define lowbit(x) ((x)&-(x))

typedef unsigned LL ULL;
typedef unsigned uint;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;

template< typename T > inline void read(T &x) {
    static bool fr_f; static char fr_ch;
    fr_f=0; x=0; fr_ch=getchar();
    while(fr_ch<'0' || '9'<fr_ch) {if(fr_ch=='-') fr_f=1; fr_ch=getchar();}
    while('0'<=fr_ch && fr_ch<='9') {x=(x<<1)+(x<<3)+fr_ch-'0'; fr_ch=getchar();}
    if(fr_f) x=-x;
}

template< typename T > inline void Max (T &a, T b) {if(a<b) a=b;}
template< typename T > inline void Min (T &a, T b) {if(b<a) a=b;}
template< typename T > inline void Swap(T &a, T &b) {T c=a;a=b;b=c;}
template< typename T > inline T Abs(T a) {if(a<0) return -a; else return a;}

const double   pi = acos(-1.0) ;
const int     MOD = (int)1e9+7 ;
const int     INF = (int)0x3f3f3f3f ;
const LL     LINF = (LL)INF<<32|INF ;
const int    SINF = (uint)(-1)>>1 ;
const LL    SLINF = (ULL)(-1)>>1 ;
const double DINF = 1e50 ;
const double  eps = 1e-5 ;
const int    maxn = (int) 1e5+20 ;
const int    maxm = (int) 1e6+20 ;
const int    maxk = (int) 1000+20 ;

inline int sig(double x) {return x<-eps?-1:x>eps;}
inline LL fp(LL a,LL n,LL p) {LL res=1; for(;n;n>>=1,a=a*a%p) if(n&1) res=res*a%p; return res;}
template<typename T>inline T gcd(T a,T b) {for(T c;b;c=a%b,a=b,b=c); return a;}

//--------------------start--------------------



void work()
{
    int D, N;
    cin >>D >>N;
    int i = 1;
    int idx = 0;
    while(1)
    {
        int cnt = 0;
        int j = i;
        while(j % 100 == 0)
        {
            cnt++;
            j /= 100;
        }

        if(cnt == D)
        {
            idx++;
        }

        if(idx == N)
        {
            cout <<i <<endl;
            break;
        }
//        cout <<idx <<" " <<cnt <<" " <<i <<endl;
        i++;
    }
}

//---------------------end---------------------

int main()
{
#ifdef yukihana0416
freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif // yukihana0416
    work();
    return 0;
}


Measured memory_bytes: 764
n=int(input())
a=list(input())

# あかのインデックス
RR=[-1]
# しろのインデックス
WW=[]

for i in range(n):
    if a[i]=='R':
        RR.append(i)
    else:
        WW.append(i)
WW.append(float('inf'))

if a.count('R')==0 or a.count('R')==n:
    print(0)
    exit()
if a.count('W')==1 or a.count('R')==1:
    print(1)
    exit()

for i in range(len(RR)-1):
    if RR[-2-i]<WW[i+1]:
        ans=i+1
        break

# 白くするコスト
wc = [0]
# 赤くするコスト
rc = [0]

import itertools

a = ['R'] + a

if a[-1] == 'R':
    a.append('W')
else:
    a.append('R')

cntr = 0
cntw = 0
flag1 = True
for i in range(n + 2):
    if a[i] == 'W':
        cntr += 1
        if flag1:
            flag1 = False
        else:
            if cntw != 0:
                wc.append(cntw)
                cntw = 0
    else:
        if flag1:

            continue
        else:
            cntw += 1
            if cntr != 0:
                rc.append(cntr)
                cntr = 0

wc = list(itertools.accumulate(wc))
rc = list(itertools.accumulate(rc))


for i in range(len(wc)):
    ans = min(ans, rc[i] + wc[-1] - wc[i])
print(ans)


Measured memory_bytes: 93476
import Data.List (sort)
import qualified Data.Map as Map

main :: IO ()
main = print . solve . map read . tail . lines =<< getContents

solve :: [Int] -> Int
solve xs = let m = Map.fromList $ zip (sort xs) (cycle [0, 1])
               in length [ x | (i, x) <- zip (cycle [0, 1]) xs, maybe False (/=i) $ Map.lookup x m ] `div` 2


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

int main(){
  string S;
  cin >> S;
  int size = S.size()/2;
  int allSize = S.size();
  bool flag = true; // 強い回文
  string front, back;
  front  = S.substr(0, size);
  back = S.substr(size+1, allSize);
  string back1 = back;
  string front1 = front;
  reverse(back.begin(), back.end());
  flag = front == back;
  reverse(front.begin(), front.end());
  flag = front1 == front && flag;
  // reverse(back.begin(), back.end());
  flag = back1 == back && flag;
  if(flag){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}



Measured memory_bytes: 256
from functools import reduce
def gcd(x, y):
    if not y:
        return x
    return gcd(y, x % y)
N, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
x.sort()
d = []
for i in range(N):
    d.append(x[i + 1] - x[i])
ans = reduce(gcd, d)
print(ans)


Measured memory_bytes: 14596
var lines = [];
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

rl.on('line', function(input) {
    lines.push(input);
});

rl.on('close', function() {
    var inputsAsArr = lines[0].split(' ');
    var sideA = Number(inputsAsArr[0]);
    var sideB = Number(inputsAsArr[1]);
    var sideC = Number(inputsAsArr[2]);

    var outputStr = (sideA === sideB && sideA === sideC && sideB === sideC) ? 'Yes' : 'No';
    console.log(outputStr);

    // var A = Number(lines[0].split(" ")[0]);
    // var B = Number(lines[0].split(" ")[1]);
    // var C = Number(lines[0].split(" ")[2]);
 
    // if (A === B && A === C && B === C) { console.log("Yes") }
    // else { console.log("No") }
});


Measured memory_bytes: 22084
A,B,C,D = map(int, input().split())

simultaneous_sec = 0
if A <= C:
    if B <= C:
        simultaneous_sec = 0
    else:
        simultaneous_sec = min(B, D) - C
else:
    if D <= A:
        simultaneous_sec = 0
    else:
        simultaneous_sec = min(B, D) - A
print(simultaneous_sec)

Measured memory_bytes: 9076
K = int(input())

if K ==2 or K%5==0 or K%2==0:
    print(-1)
    exit()

preamari = 7%K
ans = 1
while preamari != 0:
    preamari = (preamari*10 + 7%K)%K
    ans+=1

print(ans)
    

Measured memory_bytes: 62872
#include <bits/stdc++.h>
using namespace std;
int main(){
	int sum = 0;
	int b[100000];
	int a;
	cin >> a;
	for(int i = 0;i<a;i++){
		cin >> b[i];
	}
	for(int i = 1;i<a-1;i++){
		if((b[i]>=b[i+1] && b[i]<b[i-1]) or (b[i]<b[i+1] && b[i]>=b[i-1])){
			sum += 1;
		}
	}
	cout << sum;
	return 0;
} 

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  char c;
  
  scanf("%c", &c);
  if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
    printf("vowel\n");
  else 
    printf("consonant\n");
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include<string>
#include<cctype>

using namespace std;

string toUpper(string s) {
    string t = s;
    for (int i = 0; i < s.size(); i++) {
        t[i] = toupper(s[i]);
    }
    return t;
    
}

int main()
{
    string target, source;

    cin >> target;
    target = toUpper(target);

    int cnt = 0;

    while(1) {
        cin >> source;
        if (source == "END_OF_TEXT") break;
        source = toUpper(source);
        if (target == source) cnt++;

    }

    cout << cnt << endl;

    return 0;
}



Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
long long int dp[2][2019];
int main(){
	long long int n;
	string s;
	cin >> s;
	n = s.size();
	for(long long int i = 0;i < 2;i++){
		for(long long int j = 0;j < 2019;j++){
			dp[i][j] = 0;
		}
	}
	dp[0][s[0] - '0'] = 1;
	long long int ans = 0;
	ans += dp[0][0];
	for(long long int i = 1;i < n;i++){
		for(long long int j = 0;j < 2019;j++){
			dp[i % 2][j] = 0;
		}
		for(long long int j = 0;j < 2019;j++){
			dp[i % 2][(j * 10 + (s[i] - '0')) % 2019] += dp[(i - 1) % 2][j];
		}
		if(s[i] != '0') dp[i % 2][(s[i] - '0')] ++;
		ans += dp[i % 2][0];
	}
	cout << ans << endl;
}

Measured memory_bytes: 3732
#include <stdio.h>

int main(void) {
	// your code goes here
		int n,i,a=0;
	scanf("%d",&n);
	if(7==n/100)a=1;
	i=n%100;
	if(7==i/10)a=1;
	i%=10;
	if(7==i)a=1;
	if(a)printf("Yes");else{
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 1728
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


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

struct Node *root , *NIL;

void insert(int k)
{
	struct Node *y = NIL;
	struct Node *x = root;
	struct Node *z;
	
	z = (struct Node *)malloc(sizeof(struct 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(struct Node *u)
{
	if( u == NIL) return;
	inorder(u->left);
	printf(" %d",u->key);
	inorder(u->right);
}

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

int main()
{
	int n , i , x;
	char  com[100];
	char str1[] = "insert";
	char str2[] = "print";
	scanf("%d",&n);
	
	for( i = 0; i < n; i++)
	{
		while(scanf("%s",com) != EOF)
		if(strcmp(com,str1)==0)
		{
			scanf("%d",&x);
			insert(x);
		}
		else if( strcmp(com,str2)==0)
		{
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}
	return 0;
}



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


int main() {
int a,b,c,x;
  cin >>a >> b>> c>>x;
  int cnt=0;
for(int i=0;i<=a;i++){
  for(int j=0;j<=b;j++){
    for(int k=0;k<=c;k++){
      if(500*i+100*j+50*k == x)cnt++;
    }
  }
}
  cout << cnt <<endl;
}


Measured memory_bytes: 3592
n, m = map(int, input().split())
xyz = [list(map(int, input().split())) for _ in range(n)]

ans = 0
for loop in range(8):
    sign = [1, 1, 1]
    t = loop
    i = 0
    while t > 0:
        if t%2 == 1:
            sign[i] = -1
        t >>= 1
        i += 1
    txyz = [[] for _ in range(n)]
    for i in range(n):
        for j in range(3):
            txyz[i].append(sign[j]*xyz[i][j])
        txyz[i].append(sum(txyz[i][0:3]))
    txyz.sort(key=lambda x: x[3])
    s = 0
    for i in range(m):
        s += txyz[i][3]
    ans = max(ans, abs(s))
print(ans)

Measured memory_bytes: 44764
n,m=map(int, input().split()) 
h = list(map(int, input().split()))
ab=[list(map(int,list(input().split()))) for i in range(m)] 


ans = [1]*n
for i in ab:
    if h[i[0]-1] <= h[i[1]-1]:
        ans[i[0]-1] = 0
    if h[i[0]-1] >= h[i[1]-1]:
        ans[i[1]-1] = 0

print(ans.count(1))

Measured memory_bytes: 32072
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};

int main(){
  ll A,B,M,aa=INF,bb=INF;
  cin>>A>>B>>M;
  ll a[A],b[B];
  for(ll i=0;i<A;i++){
    cin>>a[i];
    aa=min(aa,a[i]);
  }
  for(ll i=0;i<B;i++){
    cin>>b[i];
    bb=min(bb,b[i]);
  }
  ll ans=aa+bb;
  for(ll i=0;i<M;i++){
    ll x,y,c,k;
    cin>>x>>y>>c;
    k=(a[x-1]+b[y-1]-c);
    ans=min(ans,k);
  }
  cout<<ans<<endl;
}


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


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = [0]*60
    for a in A:
        for i in range(len(B)):
            if (a >> i) & 1:
                B[i] += 1
    ans = 0
    for i, b in enumerate(B):
        ans += 2**i * b * (N-b)
    ans %= 10**9+7
    print(ans)


if __name__ == '__main__':
    main()


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

//Made with <3 by MinumCoklatPanas
typedef long long ll;
const int INF = 1e9;
const ll INFF = 1e18;
const int MAXN = 510;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double INFD = 1E9;
const double EPS = 1e-9;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int x;
    cin >> x;
    if (x < 600)
        cout << "8\n";
    else
    if (x < 800)
        cout << "7\n";
    else
    if (x < 1000)
        cout << "6\n";
    else
    if (x < 1200)
        cout << "5\n";
    else
    if (x < 1400)
        cout << "4\n";
    else
    if (x < 1600)
        cout << "3\n";
    else
    if (x < 1800)
        cout << "2\n";
    else
        cout << "1\n";
    return 0;
}

Measured memory_bytes: 3656
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""


n,k = m()

ans = 1

for i in range(n):
    if i == 0:
        ans *= k
    else:
        ans *= k-1
print(ans)

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

struct point {
  ll x, y;
  point(){};
  point(ll a, ll b) {
    x = a;
    y = b;
  }
};

bool comp_x(point p, point q) {
  if (p.x != q.x) {
    return p.x < q.x;
  } else {
    return p.y < q.y;
  }
}

bool comp_y(point p, point q) {
  if (p.y != q.y) {
    return p.y < q.y;
  } else {
    return p.x < q.x;
  }
}

ll N, M;
vector<point> P;

void solve() {
  ll l, r;
  sort(P.rbegin(), P.rend(), comp_x);
  l = P[0].x;
  sort(P.begin(), P.end(), comp_y);
  r = P[0].y;
  cout << max((ll)0, r - l + 1) << '\n';
  return;
}

int main() {
  cin >> N >> M;
  P.resize(M);
  for (int i = 0; i < M; i++) {
    cin >> P[i].x >> P[i].y;
  }
  solve();
  return 0;
}


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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

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

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

    int n, q;
    while (cin >> n >> q, n) {
        map<int, int> mp;
        rep(i, n) {
            int m;
            cin >> m;
            rep(j, m) {
                int x;
                cin >> x;
                mp[x]++;
            }
        }

        int ans = 9999;
        int ma = -1;
        for (auto p : mp) {
            if (p.second >= q && p.second > ma) {
                ans = p.first;
                ma = p.second;
            }
        }
        cout << (ans < 9999 ? ans : 0) << endl;
    }
}

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



int main(){
    long n;
    vector<long> in(5,0);
    cin>>n;
    int i,j;
    for(i=0;i<5;i++){
        cin >> in[i];
    }
    cout << (n-1)/(*min_element(in.begin(),in.end())) + 1+4<< endl;
    return 0;
}

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

constexpr int si = 101 * 1002, si_log = 8 + 10 + 1, mod = static_cast<int>(1e9) + 7;
constexpr int shi = 101 * 1000;
int n, m;
uint64_t ans, ar[1234];

vector<pair<uint64_t, int>> di[1234];
map<uint64_t, int> ma;

uint64_t gcd(uint64_t a, uint64_t b) {
   while (b) {
      auto r = a % b;
      a = b;
      b = r;
   }
   return a;
}
void de(uint64_t a,
   vector<pair<uint64_t, int>>& div) {
   const auto hi = static_cast<uint64_t>(sqrtl(static_cast<long double>(a)));
   for (uint64_t lo = 2; lo <= hi; ++lo) {
      if (0 == a % lo) {
         int p = 0;
         do {
            ++p; a /= lo;
         } while (0 == a % lo);
         div.push_back(make_pair(lo, p));
         if (1 == a) return;
      }
   }
   if (1 < a) div.push_back(make_pair(a, 1));
}

int main() {
   ios_base::sync_with_stdio(0); cin.tie(0);
   
   cin >> n; for (int i = 0; i < n; i++) cin >> ar[i];

   sort(ar, ar+n);
   auto it = unique(ar, ar + n);
   m = (int)(it - ar);
   if (1 == m) { cout << ar[0]; return 0; }

   //for (const auto &v : se) {
   //   de(v, di[j]);
   //   for(const auto &p : di[j]) {
   //      auto &z = ma[p.first];
   //      z = max(z, p.second);
   //   }
   //   ++j;
   //}
   ans = 1;
   for (int i = 0; i < m; i++)
   {
      auto g = gcd(ans, ar[i]);
      auto d = ar[i] / g;
      ans *= d;
   }

   for (const auto &p : ma) {
      auto po = p.second;
      while(0 < po--)
      {
         ans *= p.first;
      }
   }
   cout << ans << '\n';
   return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n, ans int64
	fmt.Scan(&n)
	name_list := make([]string, n)
	for i := range name_list {
		fmt.Scan(&name_list[i])
	}
	// fmt.Println(name_list)

	initials := map[string]int64{"M":0, "A":0, "R":0, "C":0, "H":0}

	for _, v := range name_list {
		for k, _ := range initials {
			if v[:1] == k {
				initials[k]++
			}
		}
	}
	// fmt.Println(initials)

	ans += initials["M"]*initials["A"]*initials["R"]+
			initials["M"]*initials["A"]*initials["C"]+
			initials["M"]*initials["A"]*initials["H"]+
		initials["M"]*initials["R"]*initials["C"]+
		initials["M"]*initials["R"]*initials["H"]+
			initials["M"]*initials["C"]*initials["H"]+
		initials["A"]*initials["R"]*initials["C"]+
		initials["A"]*initials["R"]*initials["H"]+
		initials["R"]*initials["C"]*initials["H"]+
		initials["A"]*initials["C"]*initials["H"]

	fmt.Println(ans)

}


Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	int l;
	cin>>n;
	cin>>l;
	string a[n+1];
	for (int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	string res="";
	for (int i=1;i<=n;i++){
		cout<<a[i];
	}
}

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

int main(){
  int N;
  cin >> N;
  int s=0,t=N;
  
  while(t>0){
    s+=t%10;
    t/=10;
  }
  
  if(N%s==0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())
    K = int(readline())
    x = list(map(int, readline().split()))

    ans = 0

    for i in range(N):
        ans += 2 * min(abs(x[i]), K - x[i])

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61600
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
typedef long long LL;
int n,m;
int A[maxn],B[maxn];
int main()
{
    cin>>n;
    for(int i=1;i<=n+1;i++)
        cin>>A[i];
    for(int i=1;i<=n;i++)
        cin>>B[i];
    LL sum=0,res=0;
    for(int i=1;i<=n;i++)
    {
        if(B[i]>=A[i])
        {
            sum+=A[i];
            res=B[i]-A[i];
            if(res>=A[i+1])
            {
                sum+=A[i+1];
                A[i+1]=0;
            }
            else
            {
                sum+=res;
                A[i+1]-=res;
            }
        }
        else
            sum+=B[i];
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include<math.h>
#define gc()getchar_unlocked()
int in(){
   int n=0,c=gc();
   do n=10*n+(c&0xf),c=gc();
   while(c>='0');
   return n;
}
int x[102],y[102];
int main(){
    int n,i,t,t2;
    int d,d1,d2;
    long long d3;
    n=in();
    for(i=0;i<n;i++)x[i]=in();
    for(i=0;i<n;i++)y[i]=in();
    d=0,d1=0,d2=0,d3=0;
    for(i=0;i<n;i++){
        t=x[i]-y[i];
        if(t<0)t=-t;
        if(t>d)d=t;
        d1+=t;
        t2=t*t,d2+=t2;
        d3+=t2*t;
        }
    printf("%d\n",d1);
    printf("%.8lf\n",sqrt((double)d2));
    printf("%.8lf\n",pow((double)d3,1.0/3));
    printf("%d\n",d);
    
    return 0;
}



Measured memory_bytes: 2144
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};
long double eps = 1e-6;
long double pi = acos(-1);

ll mod = 998244353;
template<typename T> void add(T &a,T b){a=(a+b)%mod;}
template<typename T> void sub(T &a,T b){a=(a+mod-b)%mod;}

ll dp[333][333][333];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    string s;
    int k;
    cin>>s>>k;
    int n = s.size();
    int sum[n+1]={};
    int z = 0;
    int o = 0;
    for(int i=0;i<n;i++){
        if(s[i] == '0'){
            z++;
            sum[z+1] = sum[z];
        }
        else o++;
        sum[z+1] = o;
    }
    
    dp[0][0][0] = 1;
    for(int i=0;i<z;i++){
        for(int y=0;y<=min(k,o);y++){
            for(int j=sum[i];j<=min(o,sum[i]+k);j++){
                for(int p=max(j,sum[i+1]);p<=min(sum[i+1]+k,o);p++){
                    ll ret = dp[i][j][y];
                    int cnt = y;
                    int dif = p - j;
                    dif -= sum[i+1] - sum[i];
                    dif = max(0,dif);
                    cnt += dif;
                    if(cnt <= k){
                        add(dp[i+1][p][cnt],ret);
                    }
                    else break;
                }
            }
        }
    }
    ll ans = 0;
    for(int i=sum[z];i<=o;i++){
        for(int y=0;y<=min(o,k);y++){
            add(ans,dp[z][i][y]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 33752
#include <bits/stdc++.h>
using namespace std;
const int N=1005;
int a[N],b[N],c;
bool ok=1;
void Solve(int l, int r, int pr=0)
{
	if(l>r) return;
	int p=-1,f=N;
	for(int i=l;i<=r;i++)
	{
		if(a[i]<=f) p=i,f=a[i];
	}
	b[++c]=a[p];
	Solve(p+1,r,pr+1);
	Solve(l,p-1,pr);
}
bool done[N];
int cnt[N];
int main()
{
	int n,i,j;
	scanf("%i",&n);
	for(i=1;i<=n;i++) scanf("%i",&a[i]);
	bool ok=1;
	for(j=1;j<=n;j++)
	{
		bool tmp=0;
		for(int i=n;i>=1;i--) if(!done[i] && a[i]<=cnt[i]+1)
		{
			done[i]=1;
            b[++c]=a[i];
            tmp=1;
            //printf("%i ",a[i]);
            for(int k=i+1;k<=n;k++) if(a[k]>a[i]) cnt[k]++;
            break;
		}
		if(!tmp) ok=0;
	}
	vector<int> Try;
	if(ok)
	{
		for(i=1;i<=n;i++)
		{
			if(b[i]-1<=Try.size()) Try.insert(Try.begin()+b[i]-1,b[i]);
			else{ ok=0;break;}
		}
	}
	if(ok) for(i=1;i<=n;i++) if(Try[i-1]!=a[i]) ok=0;
	if(!ok) return 0*printf("-1\n");
	for(i=1;i<=n;i++) printf("%i\n",b[i]);
	return 0;
}

Measured memory_bytes: 256
use proconio::{input, fastout};

#[fastout]
fn main() {
    input!{
        n: i32,
        mut v: [i32; n],
    }
    v.sort();
    let mut r = v[0] as f64;
    for &i in v[1..].iter() {
        r = (r + i as f64) / 2f64;
    }
    println!("{}", r);
}


Measured memory_bytes: 2188
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class ARotation {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    string c1, c2;
	    in >> c1 >> c2;
	    reverse(c2.begin(), c2.end());
	    ans2(c1 == c2, out);
	}
};


int main() {
	ARotation solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

long minValue(long H,long W){
    long minVal,i;
    if (W%3 == 0){
        minVal= 0;
    }else{
        minVal = H;
        long long min = H*W;
        for (i=1;i< W;i++){
            long min = max({abs(H*i- (W-i)*(H/2)),abs(H*i- (W-i)*(H/2 + H%2)),(W-i)*(H%2)});
            if (min == 32704){}
            if (min< minVal){
                minVal = min;
            }
        }
    }
    return minVal;
}

int main()
{
    // 整数の入力
    long H,W,i,a,b,candidate1,candidate2,candidate3;
    cin >> H >> W;
    cout << min(minValue(H,W),minValue(W,H)) <<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll ary[100];
    ary[0] = 2;
    ary[1] = 1;
    REP(i, 2, 88)
    {
	    ary[i] = ary[i-1] + ary[i-2];
    }
    int n;
    cin >> n;
    cout << ary[n] << endl;
}


Measured memory_bytes: 256
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

int survive[SIZE];

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

    int n, m, q;
    cin >> n >> m >> q;
    list< int > lst;
    for( int i = 0; i < n; ++i ) {
        lst.pb( i );
        survive[i] = 1;

    }

    auto it = lst.begin();
    for( int i = 0; i < m; ++i ) {
        int a;
        cin >> a;
        
        if( a % 2 == 0 ) {
            while( a > 0 ) {
                ++it;
                if( it == lst.end() ) ++it;
                --a;

            }
        
        } else {
            while( a > 0 ) {
                --it;
                if( it == lst.end() ) --it;
                --a;

            }
        }
        survive[*it] = 0;
        it = lst.erase( it );
        if( it == lst.end() ) ++it;        
    }

    for( int i = 0; i < q; ++i ) {
        int b;
        cin >> b;
        cout << survive[b] << endl;

    }

    return 0;
}




Measured memory_bytes: 10228
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <complex>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define RREP(i,x) for(int i=(x)-1;i>=0;i--)
#define RFOR(i,c) for(auto i=(c).rbegin();i!=(c).rend();++i)
#define ALL(container) container.begin(), container.end()
#define SZ(container) ((int)container.size())

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;
#define X real()
#define Y imag()

typedef complex<int> P;
 // 線分・半直線・直線
struct L { P pos, dir; };
inline int signum(int x) { return (!x ? 0 : x > 0 ? 1 : -1); }
inline int outp(const P& a, const P& b) {
	return (conj(a)*b).imag();
}
inline double norm(P p){
	return p.X*p.X+p.Y*p.Y;
}
inline int ccw(const P& p, const P& r, const P& s) {
    P a(r-p), b(s-p);
    int sgn = signum(outp(a, b));
    if (sgn != 0)
        return sgn;
    if (a.real()*b.real() < -EPS || a.imag()*b.imag() < -EPS)
        return -1;
    if (norm(a) < norm(b) - EPS)
        return 1;
    return 0;
}

int n;
main(){
	while(cin >> n, n){
		vector<int> tar, rtar;
		REP(i, n+1){
			vector<int> l;
			int m;
			P p1, p2;
			cin >> m >> p1.X >> p1.Y >> p2.X >> p2.Y;
			l.push_back(abs(p2-p1));
			REP(j, m-2){
				P p;
				cin >> p.X >> p.Y;
				l.push_back(ccw(p1, p2, p));
				p1 = p2;p2 = p;
				l.push_back(abs(p2-p1));
			}
			if(i == 0){
				tar = l;
				reverse(l.begin(), l.end());
				for(int i=1;i<l.size();i+=2) l[i] = -l[i];
				rtar = l;
			}else{
				if(l == tar || l == rtar) cout << i << endl;
			}
		}
		cout << "+++++" << endl;
	}
	return 0;
}

Measured memory_bytes: 1228
/*
    Author - Param Kothari
    Ah shit, here we go again
*/

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

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair

typedef long long ll;
typedef long double ld;

void solve(){
    int n, m, c;
    cin >> n >> m >> c;
    vector<int> b(m);
    for(int i = 0; i < m; i++){
        cin >> b[i];
    }
    vector<vector<int>> a(n, vector<int> (m));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> a[i][j];
        }
    }
    int res = 0;
    for(int i = 0; i < n; i++){
        int curr = 0;
        for(int j = 0; j < m; j++){
            curr += a[i][j] * b[j];
        }
        curr += c;
        res += (curr > 0);
    }
    cout << res << "\n";
    return;
}

int main(){
    IOS;
    int t = 1;
    // cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3632
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>//priority_queue(優先度付きキュー)：最大値の探索が早い
#include<set>
#include<stack>
#include<string>
#include<vector>

#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<tuple>
#include<utility>
#define rep0(i,n)  for(ll i=0; i<n; i++)
#define rrep0(i,n) for(ll i=n-1; 0<=i; i--)
#define rep1(i,n)  for(ll i=1; i<=n; i++)
#define rrep1(i,n) for(ll i=n; 1<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
using ll = long long;
using namespace std;
/*ビットxにi番目のフラグが立っているかどうか
if(x & (1 << i))
↑ a << b == a*pow(b,2)
/*{0, 1, ..., n-1} の部分集合の全探索
for (int bit = 0; bit < (1 << n); ++bit)
*/

int main(){
  ll n;  cin >> n;
  vi x(n+1);
  rep1(i,n){
    ll a;  cin >> a;
    x[a] = i;
  }
  rep1(i,n){
    cout << x[i] << " ";
  }
}


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

using ll = long long;
using pp = pair<ll,ll>;
const ll amari = 1e9+7;
const char BC = 'A' - 'a';
#define ben(a) a.begin(),a.end() //昇順
#define enb(a) a.rbegin(),a.rend() //降順
#define pb(a,b) a.push_back(b)
//fixed << setprecision(20)
int main(){
	int a,b,c,d,e,f,g,h,i;
	cin >> a >> b >> c;
	cin >> d >> e >> f;
	cin >> g >> h >> i;
	int ok = 0;
	int j = a - b;
	int k = d - e;
	int l = g - h;
	if(j != k || k != l || j != l)ok = 1;
	int m = b - c;
	int n = e - f;
	int o = h - i;
	if(m != n || n != o || m != o)ok  = 1;
	int p = a - d;
	int q = b - e;
	int r = c - f;
	if(p != q || q != r || p != r)ok = 1;
	int s = d - g;
	int t = e - h;
	int u = f - i;
	if(s != t || t != u || u != s)ok = 1;

	if(ok)cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}



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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
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; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2;
//template end



int main(){
    int n; scanf("%d",&n);
    ll ans=1LL*n*(n-1)/2;
    printf("%lld\n",ans);
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<char> C(N);
  int countW = N;
  int countR = 0;
  for(int i = 0; i < N; i++){
    cin >> C.at(i);
    if(C.at(i) == 'R'){
      countR++;
      countW--;
    }
  }
  
  int numW = 0;
  for(int i = 0; i < countR; i++){
  	if(C.at(i) == 'W') numW++;
  }
  
  int numR = 0;
  for(int i = countR; i < N; i++){
  	if(C.at(i) == 'R') numR++; 
  }
  
  cout << min(numW, numR) << endl;
  
  return 0;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int Magic(int a){
    return a>1 ? (a-1)*10 : 0;
}
int main(){
    int N,A,B,C;
    cin>>N>>A>>B>>C;
    int l[N];
    for(int i=0; i<N; i++) cin >> l[i];
    int res = 1e9,MP=1e9;
    for(int msk=0; msk<pow(4,N); ++msk){
        int a[3]={};
        int cnt[3]={};
        int tmp=msk;
        for(int i=0; i<N; i++){
            if(tmp%4==1){
                a[0]+=l[i];
                cnt[0]++;
            }else if(tmp%4==2){
                a[1]+=l[i],cnt[1]++;
            }else if(tmp%4==3){
                a[2]+=l[i],cnt[2]++;
            }
            tmp/=4;
        }
        if(a[0] && a[1] && a[2]){
            int mp=abs(A-a[0]) + abs(B-a[1]) + abs(C-a[2]);
            for(int i=0; i<3; i++) mp += Magic(cnt[i]);
            MP = min(MP, mp);
        }

    }
    cout << MP << endl;
}


Measured memory_bytes: 256
import math


def get_primes(n):
    primes = []
    checks = [True for _ in range(int(math.sqrt(n)) + 1)]
    checks[0] = checks[1] = False
    for i in range(2, len(checks)):
        if checks[i]:
            primes.append(i)
            tmp = 0
            while i + tmp * i < len(checks):
                checks[i + tmp * i] = False
                tmp += 1
    return primes


def combination(a, b):
    i = 1
    for _i in range(a - b + 1, a + 1):
        i *= _i
    return i // math.factorial(b)


def solve(string):
    n, m = map(int, string.split())
    primes = get_primes(m)
    m_copy = m
    divides = dict()
    for _p in primes:
        while m_copy % _p == 0:
            m_copy = m_copy // _p
            if str(_p) in divides.keys():
                divides[str(_p)] += 1
            else:
                divides[str(_p)] = 1
    if m_copy > 1:
        divides[str(m_copy)] = 1

    ans = 1
    for i in divides.values():
        ans *= combination(i + n - 1, i)
    return str(ans % (1000000007))


if __name__ == '__main__':
    print(solve(input()))


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

using namespace std;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    string s;
    cin >> s;
    if(s == "keyence"){
        cout << "YES";
        return 0;
    }
    int n = s.length();
    for(int l = 0; l < n; l++){
        for(int r = l; r < n; r++){
            int len = r - l + 1;
            string t = s.substr(0, l);
            if(r + 1 < n) t += s.substr(r + 1, n - len);
            if(t == "keyence"){
                cout << "YES";
                return 0;
            }
        }
    }
    cout << "NO";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 2000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

bool debug=false;
/*---------------------------------------------------*/

int main(){
  string s;
  cin>>s;
  if(s[0]==s[2])cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


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

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}

unsigned long  gcd(unsigned long x, unsigned long y)
{
        if (y == 0) {
                return x;
        } else {
                return gcd(y, x % y);
        }
}


int card[200005];



int main(void){
    int n;
    int i;
    long long snuke = 0;
    long long raccoon = 0;
    long long total = 0;
    long long min = 200000000000010;
    scanf("%d", &n);
    for (i = 0; i < n; i++){
        scanf("%d", &card[i]);
        total += card[i];
    }

    for (i = 0; i < n-1; i++){
        snuke += card[i];
        raccoon = total - snuke;
        min = min>llabs(raccoon - snuke)?llabs(raccoon - snuke):min;
    }

    printf("%lld\n", min);

    return 0;

}


Measured memory_bytes: 896