akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    x--;
    p[x] = i;
  }
  int t = 1, ans = 1;
  for (int i = 1; i < n; i++) {
    if (p[i] > p[i - 1]) {
      t++;
    } else {
      t = 1;
    }
    ans = max(ans, t);
  }
  cout << n - ans << '\n';
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
inline long long read()
{
	char s;
	long long k=0,base=1;
	while((s=getchar())!='-'&&s!=EOF&&!(s>='0'&&s<='9'));
	if(s==EOF)exit(0);
	if(s=='-')base=-1,s=getchar();
	while(s>='0'&&s<='9')
	{
		k=k*10+(s-'0');
		s=getchar();
	}
	return k*base;
}
void write(int x)
{
	if(x<0)
	{
		putchar('-');
		write(-x);
	}
	else
	{
		if(x/10)write(x/10);
		putchar(x%10+'0');
	}
}
long long a,b,c,d,e;//1 2 4 8
long long minx;
long long ans;
int main()
{
	a=read();b=read();c=read();d=read();e=read();
	a*=4;b*=2;
	minx=min(a,min(b,c));
	ans=min(minx*e,(long long)floor(e*1.0/2.0)*d+(e%2)*minx);
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2], R[MAX/2+2];
int cnt=0;

void merge(int A[], int l, int m, int r)
{
    int n1, n2, i, j, k;
    n1 = m-l+1;
    n2 = r-m;
    for(i=0;i<n1;i++) L[i]=A[l+i];
    for(i=0;i<n2;i++) R[i]=A[m+i+1];
   
    i=0, j=0, k=l;
    while(i<n1 && j<n2)
    {
        cnt++;
        if(L[i]<=R[j])
            A[k] = L[i++];
        else
            A[k] = R[j++];
        k++;
    }
    while(i<n1)
    {
        A[k++] = L[i++];
        cnt++;       
    } 
    while(j<n2)
    {
    A[k++] = R[j++];
    cnt++;
    }
}
        

void meregeSort(int A[], int l, int r)
{
    if(l<r)
    {
        int m = (l+r)/2;
        meregeSort(A, l, m);
        meregeSort(A, m+1, r);

        merge(A, l, m, r);
    }
}

int main()
{
    int A[MAX], n, i;
    cin>>n;
    for(i=0; i<n; i++) cin>>A[i];
    meregeSort(A, 0, n-1);
   
    for(i=0; i<n; i++)
    {
        if(i)cout<<" ";
        cout<<A[i];
    }
    cout<<endl;
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 6968
#include<iostream>
#include<functional>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
#pragma warning(disable:4996)
int n, m, q, a[1 << 18], b[1 << 18], c[1 << 18], d[1 << 18], e[1 << 18], dist[1 << 17];
vector<pair<int, int>>x[1 << 17], y[1 << 17], z[1 << 17];
vector<int>D[1 << 17];
void reader(int *x) {
	int k = getchar_unlocked(); *x = k - '0';
	while (true) {
		k = getchar_unlocked();
		if (k < '0' || k > '9') break;
		*x = ((*x) << 1) + ((*x) << 3) + k - '0';
	}
}
int main() {
	reader(&n); reader(&m); reader(&q);
	fill(d, d + m + 1, 1 << 30);
	for (int i = 1; i <= m; i++) reader(&a[i]), reader(&b[i]);
	for (int i = 1; i <= q; i++) reader(&c[i]), d[c[i]] = i;
	for (int i = 1; i <= m; i++) {
		x[a[i]].push_back(make_pair(b[i], d[i]));
		x[b[i]].push_back(make_pair(a[i], d[i]));
	}
	fill(dist, dist + n + 1, -1); dist[1] = 0;
	queue<int> Q1; Q1.push(1);
	while (!Q1.empty()) {
		int a1 = Q1.front(); Q1.pop();
		for (pair<int, int> i : x[a1]) {
			if (dist[i.first] == -1) {
				dist[i.first] = dist[a1] + 1;
				Q1.push(i.first);
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		D[dist[i]].push_back(i);
		for (pair<int, int> j : x[i]) {
			if (dist[i] < dist[j.first]) y[i].push_back(j);
			if (dist[i] > dist[j.first]) z[i].push_back(j);
		}
	}
	e[1] = (1 << 30);
	for (int i = 1; i < n; i++) {
		for (int j : D[i]) {
			for (pair<int, int>k : z[j]) {
				e[j] = max(e[j], min(e[k.first], k.second));
			}
		}
	}
	sort(e + 1, e + n + 1);
	int T = 1;
	for (int i = 1; i <= q; i++) {
		while (e[T] <= i) T++;
		printf("%d\n", T - 1);
	}
	return 0;
}

Measured memory_bytes: 32972
n,p=map(int,input().split())
s=list(map(int,list(input()[::-1])))
if p in [2,5]:
  ans=0
  for i in range(n):
    if s[-i-1]%p==0:ans+=i+1
  print(ans)
  exit()
from collections import defaultdict
d=defaultdict(int)
t=0
d[t]+=1
m=1
for i in range(n):
  t+=m*s[i]
  t%=p
  d[t]+=1
  m*=10
  m%=p
print(sum(d[i]*(d[i]-1)//2 for i in range(p)))

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

int main(){
    int a,b; cin>>a>>b;
    
    if(a == b){
        cout<<"a == b"<<endl;
    }else if(a < b){
        cout<<"a < b"<<endl;
    }else{
        cout<<"a > b"<<endl;
    }
    
    return 0;
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(x) x.begin(),x.end()
typedef long long ll;
ll mod = 1000000007;
ll inf = 1e18;
int main(){

    int s;
    cin >> s;
    
    vector<ll> a(2001,1);
    a[0]=0; a[1]=0; a[2]=0; a[3]=1; a[4]=1; a[5]=1;
    
    for(int i=6; i<=2000; i++){
        int num=i;
        for(int j=0; num-3-j>=3; j++){
            a[num]+=a[num-3-j];
        }
        a[num]%=mod;
    }

    cout << a[s] << endl;
    
    return 0;
}

Measured memory_bytes: 3636
#include<math.h>
#include<iostream>

using namespace std;

/*-----素数判定関数   エラー：-1 , 素数でない：0 , 素数：1-----*/
int isPrime(int x) {
	
	if (x < 2) {
		return -1;
	}

	int root_x = sqrt(x);

	for (int i = root_x; i > 1; --i) 
	{
		if (x % i == 0) return 0;
	}

	return 1;
}
/**/

int main() {

	int X;
	cin >> X;

	int count = 0;
	bool prime = false;

	while (isPrime(X + count) == 0)
	{
		count++;
	}

	cout << X + count;

	return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  int hazi = max( A, C );
  int owa = min( B, D );
  
  if( owa - hazi > 0 ){
    cout << owa - hazi << endl;
  }else{
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}

	Scanner sc = new Scanner(System.in);

	boolean checkAndPadding(int id,int position, boolean[] visited, int[] line, Map<Integer, List<E>> map){
		if(visited[id]){
			return line[id] == position;
		}
		
		line[id] = position;
		visited[id] = true;

		if(!map.containsKey(id)){
			return true;
		}
		List<E> list = map.get(id);

		for (E e : list) {
			int targetId;
			int targetPos;
			if (e.l == id) {
				targetId = e.r;
				targetPos = line[id] + e.d;
			} else {
				targetId = e.l;
				targetPos = line[id] - e.d;
			}
			
			if (visited[targetId]) {
				if(line[targetId] != targetPos){
					return false;
				}
			}else{
				if(!checkAndPadding(targetId,targetPos,visited,line,map)){
					return false;
				}
			}
		}
		
		return true;
		
	}
	
	void run() {

		int n = sc.nextInt();

		int m = sc.nextInt();
		int l[] = new int[m];
		int r[] = new int[m];
		int d[] = new int[m];

		Map<Integer, List<E>> map = new HashMap<Integer, List<E>>();

		for (int i = 0; i < m; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
			d[i] = sc.nextInt();

			E e = new E(l[i], r[i], d[i]);
			List<E> leftList = map.containsKey(l[i]) ? map.get(l[i]) : new LinkedList<E>();
			// List<E> leftList = leftMap.getOrDefault(l[i], new
			// LinkedList<E>());
			leftList.add(e);
			map.put(l[i], leftList);

			List<E> rightList = map.containsKey(r[i]) ? map.get(r[i]) : new LinkedList<E>();
			rightList.add(e);
			map.put(r[i], rightList);
		}

		int[] line = new int[n + 1];
		boolean[] visited = new boolean[n + 1];

		{
			List<E> init = new LinkedList<E>();
			E e = new E(0, 1, 0);
			init.add(e);
			map.put(0, init);
			visited[0] = true;
		}

		for (int i = 1; i < n + 1; i++) {
			if(!visited[i]){
				if(!checkAndPadding(i, line[i], visited, line, map)){
					System.out.println("No");
					return;
				};
			}
		}

		System.out.println("Yes");

	}

	class E {
		int l;
		int r;
		int d;

		E(int l, int r, int d) {
			this.l = l;
			this.r = r;
			this.d = d;
		}
	}

}


Measured memory_bytes: 189496
A = int(input())
B = int(input())
C = int(input())
X = int(input())

cnt = 0
for a in range(A+1):
    for b in range(B+1):
        c = (X - 500 * a - 100 * b) // 50
        if 0 <= c <= C:
            cnt += 1
print(cnt)


Measured memory_bytes: 3060
//Radhe Radhe
#include<bits/stdc++.h>
#define godspeed  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define rep(i,n)    for(ll i=1; i<=n; i++)
#define rep1(i,a,b)    for(ll i=a; i<=b; i++)
#define repVect(i,n)    for(ll i=0; i<sum.size(); i++)
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(7);
#define yes cout<<"Yes"<<'\n'
#define no cout<<"No"<<'\n'
using namespace std;

int main()
{
    godspeed

    ll i,j,a[3],diff;
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    diff=a[2]-a[0]+a[2]-a[1];
    if(diff%2==0){
        cout<<diff/2<<endl;
    }
    else{
        diff++;
        cout<<diff/2+1<<endl;
    }
    return 0;
}





Measured memory_bytes: 3640
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


H,W = map(int,input().split())

def rangeCheck(row,col):
    return row >= 0 and row <= H-1 and col >= 0 and col <= W-1

diff_row = [-1,-1,-1,0,0,1,1,1]
diff_col = [-1,0,1,-1,1,-1,0,1]

table = [list(str(input())) for _ in range(H)]

for row in range(H):
    for col in range(W):
        if table[row][col] != '.':continue
        count = 0
        for i in range(8):
            adj_row = row+diff_row[i]
            adj_col = col+diff_col[i]
            if rangeCheck(adj_row,adj_col) == False:continue
            if table[adj_row][adj_col] == '#':count += 1

        table[row][col] = str(count)

for row in range(H):
    for col in range(W):
        print("%c"%(table[row][col]),end="")
    print("")





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

int main() {
  int N;
  double M;
  cin >> N >> M;
  int A[N];
  int sum=0;
  for(int i=0; i<N; i++) {
    cin >> A[i];
    sum+=A[i];
  }
  int cnt=0;
  for(int i=0; i<N; i++) {
    if(A[i]>=sum/(4*M)) {
      cnt++;
    }
  }
  if(M<=cnt) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <list>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <fstream>
#include <sstream>
#include <unordered_map>
#include <ctime>
#include <assert.h>
using namespace std;

const unsigned long long BASE = (unsigned long long)(1e9 + 7);

#define FROM_0(i, n) for(int i = 0; i < (n); i++)
#define FROM_S(i, s, e) for(int i = (s); i < (e); i++)
#define ITER_BEGIN_END(iter, vec) for(auto iter = vec.begin(); iter != vec.end(); iter++)

int main()
{
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    long long x1 = a * c, x2 = a * d, x3 = b * c, x4 = b * d;
    cout << max(max(x1, x2), max(x3, x4)) << endl;
    return 0;
}


Measured memory_bytes: 3640
#include <stdio.h>

int main(void)
{
	int i,j,n;
	int max=0;
	int a[10];


	for(i=0;i<10;i++){
		scanf("%d",&a[i]);
	}


	for(i=0;i<3;i++){
		for(j=0;j<10;j++){
			if(max<=a[j]){
				max=a[j];
				n=j;
			}
		}
		a[n]=-1;
		printf("%d\n",max);
		max=0;
	}

	return 0;
}

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

int main() {
    int X;
    cin >> X;
    
    priority_queue<int> que;
    que.push(1);
    int cur=2;
    while(cur*cur<=X) {
        int tmp=cur;
        while(tmp<=X) {
            que.push(tmp);
            tmp *= cur;
        }
        cur++;
    }
    cout << que.top() << endl;


    return 0;
    
}

Measured memory_bytes: 256
NK = input().split()  #N 人のすぬけ君 K 種類のお菓子
N = int(NK[0])
K = int(NK[1])

L = [] #お菓子を持っている人番号のリスト

for i in range(K):
  d = int(input())
  A = input().split()
  for k in range(d):
    if not int(A[k]) in L:
      L.append(int(A[k]))


solution = N - len(L)
print(solution)


Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
signed main(){
	long long ans=0,h,n,a;
  cin>>h>>n;
  for(int i=0;i<n;i++){
    cin>>a;
    ans+=a;
  }
  if(ans >= h)
    cout<<"Yes\n";
  else
    cout<<"No\n";
  return(0);
  }
  
 

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod = 998244353;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1)res = res * a%mod; a = a * a%mod; }return res; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
// head

long long a, b, c;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	//	freopen("a.in","r",stdin);
	//	freopen("a.out","w",stdout);
	cin >> a >> b >> c;
	if (c>(a+b) && (4*a*b) < (c-a-b)*(c-a-b)) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


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

int main() {
	//??£?¨?
	int most_views = 0,views=0,most_long=0,len=0;
	char tmp_sentence[1000];
	string sentence,mo_ma_word,longest_word,word="";
	vector<string> words;

	cin.getline(tmp_sentence, sizeof(tmp_sentence));
	sentence = tmp_sentence;
	for (int i = 0; i < sentence.size(); i++) {
		if (sentence[i] == ' ') { words.push_back(word); word = ""; }
		else word = word + sentence[i];
	}
	words.push_back(word);
	for (int i = 0; i < words.size(); i++) {
		for (int j = 0; j < words.size(); j++) {
			if (words[i] == words[j])views++;
		}
		if (most_views < views) {
			most_views = views;
			mo_ma_word = words[i];
		}
		views = 0;
	}
	for (int i = 0; i < words.size(); i++) {
		if (most_long < words[i].size()) {
			most_long = words[i].size();
			longest_word = words[i];
		}
	}
	cout << mo_ma_word <<' '<<longest_word<<endl;
}

Measured memory_bytes: 3192
loop do
    n = gets.to_i
    break if n == 0
    a = (1..n).map { gets.split.map(&:to_i) }
    a.sort_by! {|_, *b|
        b.each_slice(2).map {|m, s| 60 * m + s}.inject(:+)
    }
    p a[0][0]
    p a[1][0]
    p a[-2][0]
end


Measured memory_bytes: 7700
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define REP rep
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD=1e9+7;

#define rall(X) (X).rbegin(),(X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}

int N;

signed main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  cin >> N;

  cout << (N-2)*180 << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

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

int main(void){
	ll a,b;
	cin >> a >> b;
	cout << (a*b/gcd(a,b)) << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	int N; cin >> N;

	vector<int>sches;
	{

		string st; cin >> st;
		for (int i = 0; i < N; ++i) {
			if (st[i] == 'O')sches.push_back(1);
			else if (st[i] == 'J')sches.push_back(0);
			else sches.push_back(2);
		}
	}
	int dp[1001][8];
	memset(dp, 0, sizeof(dp));
	dp[0][1] = 1;
	for (int i = 0; i < N; ++i) {
		for (int key = 0; key < 8; ++key) {
			bitset<3>prebs(key);
			for (int j = 0; j < 8; ++j) {
				bitset<3>bs(j);
				bool aok = false;
				for (int l = 0; l < 3; ++l) {
					if (prebs[l] && bs[l])aok = true;
				}
				if (!aok)continue;
				if (!bs[sches[i]])continue;
				
				dp[i + 1][j] += dp[i][key];
				dp[i + 1][j] %= 10007;
				
			}
		}
		
	}
	int sum = 0;
	for (int l = 0; l < 8; ++l) {
		sum += dp[N][l];
	}
	cout << sum % 10007 << endl;

	return 0;
}

Measured memory_bytes: 3252
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        char[] c = S.toCharArray();
        int Q = sc.nextInt();
        int cnt = 0;
        ArrayDeque<Character> q = new ArrayDeque<Character>();
        for (int i=0;i<c.length;i++) {
            q.add(c[i]);
        }
        for (int i=0;i<Q;i++) {
            int T = sc.nextInt();
            if (T==1) {
                cnt++;
            } else { // T==2
                int F = sc.nextInt();
                char C = sc.next().charAt(0);
                if ((F+cnt)%2==1) {
                    q.addFirst(C);
                } else { // (F+cnt)%2==0
                    q.add(C);
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        while (!q.isEmpty()) {
            sb.append(q.poll());
        }
        if (cnt%2==1) sb.reverse();
        System.out.println(sb);
    }
}

Measured memory_bytes: 146612
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>

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

using namespace std;
typedef long long int ll;
const int INF = 1000000000;
const double PI = acos(-1);
const ll mod = 1000000007;

int main()
{
    int d;
    int c[26];
    int s[365][26];
    cin >> d;
    rep(i, 26) cin >> c[i];
    rep(i, d) rep(j, 26) cin >> s[i][j];

    int last[26] = {};  // 各コンテストを最後に開催した日
    int t[365] = { 1 };  // 各日に開催するコンテスト
    rep(i, d) {
        int max_v = -INF;
        rep(j, 26) {  // どのコンテストを開催するか決める
            int v = 0;
            v += s[i][j];  // 満足度上昇
            int m = min(d - i - 1, 13);
            rep(l, m) {
                rep(k, 26) {
                    if (k == j) v -= c[k] * (l);
                    v -= c[k] * (i + 1 + l - last[k]);  // 満足度低下
                }
            }
            if (v > max_v) {
                max_v = v;
                t[i] = j + 1;  // 開催するコンテストを格納
            }
        }
        last[t[i] - 1] = i + 1;  // 最後に開催した日を格納
    }

    rep(i, d) {
        cout << t[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3688
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 3000010, CL = 18;
char C[CM + CL], * ci = C + CL, * owa = C + CM, c;

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


	fread(ci, 1, CM, stdin);
	int N = 0;
	while ((c = *ci++) >= '0') N = N * 10 + c - '0';

	ll p[20][20] = {};
	rep(i, N) {
		//if (ci - owa > 0) {
		//	memcpy(C, owa, CL);
		//	ci -= CM;
		//	fread(C + CL, 1, CM, stdin);
		//}

		ll kari = 0;
		while ((c = *ci++) >= '0') kari = kari * 10 + c - '0';
		int d = 9;
		if (*(ci - 1) == '.') {
			while ((c = *ci++) >= '0') {
				kari = kari * 10 + c - '0';
				d--;
			}
		}

		int a = __builtin_ctzll(kari) + d;
		if (a > 18) a = 18;
		int b = d;
		while (kari % 5 == 0) {
			b++;
			kari /= 5;
		}
		p[a][b]++;
	}
	ll kotae = 0;
	rep(a, 19) rep(b, 19) if (p[a][b]) {
		ll P = p[a][b];
		for (int x = 18 - a; x <= 18; x++) {
			for (int y = 18 - b; y <= 18; y++) {
				kotae += P * p[x][y];
			}
		}
	}
	for (int a = 9; a <= 18; a++) {
		for (int b = 9; b <= 18; b++) {
			kotae -= p[a][b];
		}
	}

	printf("%lld\n", kotae / 2);

	Would you please return 0;
}

Measured memory_bytes: 4144
#include<cstdio>
#include<algorithm>
#include<cstdlib>
using namespace std;

int main(){
    int R ,G ,B , n;
    long long ans = 0;
    scanf("%d%d%d%d",&R,&G,&B,&n);
    for(int i = 0; R * i  <= n; i++){
        for(int j = 0; R * i + j * G <= n; j++){
            if((n - (R * i + j * G) ) % B == 0) ans++;
        }
    }
    printf("%lld\n", ans);
    return 0;
}

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

int main(){
	int n,m;
	cin>>n>>m;
	vector<vector<int>> edge(n,vector<int>(n,0));
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		a--,b--;
		edge[a][b]=1;
		edge[b][a]=1;
	}
	vector<int> v(n-1);
	iota(v.begin(),v.end(),1);
	int res=0;
	do{
		
		bool isok=true;
		for(int i=0;i<n-1;i++){
			if(i==0){
				if(!edge[0][v[0]]) isok=false;
			}
			else if(!edge[v[i-1]][v[i]]) isok=false;
		}
		if(isok) res++;
	}while(next_permutation(v.begin(),v.end()));
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
A, B, C = [input().split() for i in range(3)]
A = [int(num) for num in A]
B = [int(num) for num in B]
C = [int(num) for num in C]
A.insert(0,0)
B.insert(0,0)
C.insert(0,0)
p = 0
for i in range(1,N+1):
  p += B[A[i]]
  if A[i-1] == A[i] - 1:
    p += C[A[i-1]]
print(p)

Measured memory_bytes: 3064
//Author rahuliitkgp
/*A thing of beauty is a joy forever,
Its loveliness increases,
it will never pass into nothingness.*/
//Men at Work :)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;

#define ff              first
#define ss              second
#define SZ(x)           ((int)(x).size())
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void cpp() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//#endif
}

int main(){
    cpp();
    ll x;
    cin>>x;
    int flag = 0;
    for(ll i=0; i<=5000; i++){
        for(ll j=-5000; j<=5000; j++){
            if(pow(i, 5) - pow(j, 5)==x){
                cout<<i<<" "<<j<<endl;
                flag  = 1;
                break;
            }
        }
        if(flag) break;
    }
    return 0;
}




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

int main(void){
    int N;
    cin >> N;
    int rate[N];
    for(int i = 0; i < N ; i++){
        cin >> rate[i];
    }
    
    int b,c,d,e,f,g,h;
    int a=b=c=d=e=f=g=h=0;
    int k = 0;
    int n;
    
    for(int i = 0; i < N ; i++){
        n = rate[i];
        if(n < 400 && n >= 1) {a=1;}
        else if(n < 800 && n >= 400)  {b=1;}
        else if(n < 1200 && n >= 800) {c=1;}
        else if(n < 1600 && n >= 1200) {d=1;}
        else if(n < 2000 && n >= 1600) {e=1;}
        else if(n < 2400 && n >= 2000) {f=1;}
        else if(n < 2800 && n >= 2400) {g=1;}
        else if(n < 3200 && n >= 2800) {h=1;}
        else {k++;}
    }
    
    int color_min;
    int color_max;
    if (k == 0){
        color_min = a+b+c+d+e+f+g+h;
        color_max = color_min;
    }else if(a+b+c+d+e+f+g+h == 0){
        color_min = 1;
        color_max = a+b+c+d+e+f+g+h+k;
    }else{
        color_min = a+b+c+d+e+f+g+h;
        color_max = a+b+c+d+e+f+g+h+k;
    }
    
    cout << color_min << " " << color_max << endl;
}

Measured memory_bytes: 3136
N = int(input())
G = [None for i in range(N)]
for i in range(N):
    u, k, *vs = map(int, input().split())
    G[u-1] = [e-1 for e in vs]


from collections import deque
dist = [-1]*N
que = deque([0])
dist[0] = 0
while que:
    v = que.popleft()
    d = dist[v]
    for w in G[v]:
        if dist[w] > -1:
            continue
        dist[w] = d + 1
        que.append(w)

for i in range(N):
    print(i+1, dist[i])



Measured memory_bytes: 6032
// In the name of God

#include <bits/stdc++.h>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i=0;i<n;i++) cin >> a[i];
	vector<long long> pref(n, 0);
	pref[0] = a[0];
	for(int i=1;i<n;i++) {
		pref[i] = pref[i-1] + a[i];
	}
	long long ans = 1e18;
	for(int i=0;i<n;i++) {
		long long first = pref[i];
		long long second = pref[n-1] - pref[i];
		ans = min(ans, abs(first-second) );
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
    int n,ans;
    cin >> n;
    int B[n-1];
    REP(i,n-1)cin >> B[i];
    ans = B[0];
    REP(i,n-2){
        if(B[i] > B[i+1]){
            ans += B[i+1];
        }
        else{
            ans += B[i];
        }
    }
    ans += B[n-2];
    if(n == 2) ans = B[0]*2;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
#define pint pair<int, int>
#define vint vector<int>
using namespace std;

const int INF=1e9+7;
const ll LINF=1e18;
const int MOD=1e9+7;
//const int MOD=998244353;

int main(){
	string A; cin>>A;
	int n=A.size();

	vector<int> v[26],w;
	int num[26]={};
	FOR(i,0,n){
		v[A[i]-'a'].PB(i);
	}
	FOR(i,0,26) v[i].PB(INF);

	int k=1;
	int p[200001]={};
	ROF(i,0,n){
		p[i]=k;
		num[A[i]-'a']++;
		bool f=true;
		FOR(j,0,26){
			if(num[j]==0) f=false;
		}
		if(f){
			fill(num,num+26,0);
			k++;
			w.PB(i);
		}
	}
	/**
	FOR(i,0,n) cout<<p[i];
	cout<<endl;
	cout<<"k: "<<k<<endl;
	**/
	int nowpos=0;
	int length=k;
	string ans="";
	FOR(i,0,k){
		FOR(j,0,26){
			int a=*lower_bound(all(v[j]),nowpos);
			if(a==INF||p[a]==length-1){
				ans+=('a'+j);
				nowpos=a+1;
				length--;
				break;
			}
		}
	}
	co(ans);
}


Measured memory_bytes: 2180
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

struct pos {
    int x, y;
};

const vector<pos> moves{{1,  0},
                        {-1, 0},
                        {0,  1},
                        {0,  -1}};
int n;

bool inRange(pos &p) { return 0 <= p.x && p.x < n && 0 <= p.y && p.y < n; }

int main() {
    cin >> n;
    vector<vector<int>> dis(n, vector<int>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            dis[i][j] = min({i, j, n - 1 - i, n - 1 - j});
        }
    }

    vector<vector<bool>> used(n, vector<bool>(n));
    int ret = 0;
    for (int i = 0; i < n * n; i++) {
        int p;
        cin >> p, p--;
        ret += dis[p / n][p % n];
        used[p / n][p % n] = true;

        queue<pos> que;
        que.push({p / n, p % n});
        while (!que.empty()) {
            pos here = que.front();
            que.pop();
            for (auto move:moves) {
                pos next = {here.x + move.x, here.y + move.y};
                if (inRange(next)) {
                    int cost = dis[here.x][here.y] + (used[here.x][here.y] ? 0 : 1);
                    if (dis[next.x][next.y] > cost) {
                        dis[next.x][next.y] = cost;
                        que.push(next);
                    }
                }
            }
        }
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 4648
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
    int a, b;
    scanf("%d %d", &a, &b);
    int major;

    major = a+b;
    major = max(major, a-b);
    major = max(major, a*b);
    printf("%d\n", major);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

//prime_factor=素因数分解を返す
map< long long, int > prime_factor(long long n) {
         map< long long, int > ret;
        for(long long i = 2; i * i <= n; i++) {
            while(n % i == 0) {
                ret[i]++;
                n /= i;
            }
        }
        if(n != 1) ret[n] = 1;
        return ret;
}
int main(){
  ll n;
  cin>>n;
  int ans=0;
  for(auto v:prime_factor(n)){
     for(int j=1;j<100;j++){
       if(v.second>=j){
          ans++;
         v.second-=j;
       }
     }
  }if(n!=1)
   cout<<ans<<endl;
  else cout<<0<<endl;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int maxn=4e5+7;
int main()
{
    char a[105];
    scanf("%s",a);
    int s=strlen(a);
    int sum=0;
    for(int i=0;i<s/2;i++){
        if(a[i]!=a[s-i-1])
            sum++;
    }
    printf("%d\n",sum);
	return 0;
}


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

const int N=1e7+1e2;

template<typename T>inline void read(T &x)
{
	x=0;T c=getchar(),p=1;
	while(!isdigit(c)){if(c=='-')p=-1;c=getchar();}
	while(isdigit(c)){x=(x<<1)+(x<<3)+(c^'0');c=getchar();}
	x*=p;
}

int n;
int P[105];

int cnt,ispri[N],pri[N];

inline void Getprime(int Up)
{
	for(int i=2;i<=Up;i++)ispri[i]=1;
	for(int i=2;i<=Up;i++){
		if(ispri[i])pri[++cnt]=i;
		for(int j=1;j<=cnt && 1ll*i*pri[j]<=Up;j++){
			ispri[i*pri[j]]=0;
			if(i%pri[j]==0)break;
		}
	}
}

inline void File()
{
	freopen("magic.in","r",stdin);
	freopen("magic.out","w",stdout);
}

const int M=2e6+1e2;

bool G[1505][1505];
int tot,tot1,tot2,point,A[1005],B[1005],match[1005],vis[1005];

inline bool Dfs(int x)
{
	for(int i=1;i<=tot2;i++){
		if(!vis[i] && G[x][i]){
			vis[i]=1;
			if(match[i]==-1 || Dfs(match[i])){
				match[i]=x;
				return 1;
			}
		}
	}
	return 0;
}

int main()
{
	//File();
	Getprime(N-10);
	read(n);
	for(int i=1;i<=n;i++)read(P[i]);
	if(P[1]&1)A[++tot1]=P[1];
	else B[++tot2]=P[1];
	for(int i=2;i<=n;i++){
		if(P[i]!=P[i-1]+1){
			if((P[i-1]+1)&1)A[++tot1]=P[i-1]+1;
			else B[++tot2]=P[i-1]+1;
			if(P[i]&1)A[++tot1]=P[i];
			else B[++tot2]=P[i];
		}
	}
	if((P[n]+1)&1)A[++tot1]=P[n]+1;
	else B[++tot2]=P[n]+1;
	for(int i=1;i<=tot1;i++)
		for(int j=1;j<=tot2;j++)
			if(ispri[abs(A[i]-B[j])])G[i][j]=1;
	int Ans=0;
	memset(match,-1,sizeof match);
	for(int i=1;i<=tot1;i++){
		memset(vis,0,sizeof vis);
		if(Dfs(i))Ans++;
	}
	
	Ans=Ans+(tot1-Ans)/2*2+(tot2-Ans)/2*2;
	if((tot1-Ans)&1)Ans+=3;
	printf("%d\n",Ans);
	return 0;
}	


Measured memory_bytes: 43904
#include<bits/stdc++.h>
using namespace std;
vector<int> e[100001];
int n,m,q,mp[100001],han[100001];

typedef pair<int,int> P;
void bfs(int p,int c,int d){
  queue<P> q;
  q.push(P(p,0));
  while(!q.empty()){
    P tp=q.front();q.pop();
    if(tp.second==d+1)break;
    if(han[tp.first]>=d-tp.second)continue;
    if(!mp[tp.first])mp[tp.first]=c;
    han[tp.first]=d-tp.second;
    for(int i=0;i<e[tp.first].size();i++)
      q.push(P(e[tp.first][i],tp.second+1));
  }
}
int main(){
  cin>>n>>m;
  for(int i=0,a,b;i<m;i++){
    cin>>a>>b;
    e[a].push_back(b);
    e[b].push_back(a);
  }
  cin>>q;
  int v[100001],d[100001],c[100001];
  for(int i=0;i<q;i++)
    cin>>v[i]>>d[i]>>c[i];
  memset(han,-1,sizeof(han));
  for(int i=q-1;i>=0;i--)
    bfs(v[i],c[i],d[i]);
  
  for(int i=1;i<=n;i++)cout<<mp[i]<<endl;
  return 0;
}


Measured memory_bytes: 8952
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define MOD = 998244353;
#define int long long int
#define double long double
#define inf (int)(1e15)
#define all(x) (x).begin(), (x).end()
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define isYes(x) printf("%s\n", (x) ? "Yes" : "No")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define isIn(x, y, h, w) (x >= 0 && x < h && y >= 0 && y < w)
#define pair pair<int, int>
typedef vector<int> vi;   // Vector of long long
typedef vector<vi> vvi;   // Vector of vi
typedef vector<pair> vii; // Vector of pairs
typedef vector<vii> vvii; // Vector of Vector of pairs
typedef vector<bool> vb;  // Vector of bool
#define pq priority_queue // Max heap (To convert to min heap, use negative sign before every value)
#define ff first          // For pairs
#define ss second
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, -1, 0, 1};
const int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}, dy8[] = {1, -1, 1, 0, -1, 1, -0, -1};
#define testcases(t) \
    int(t);          \
    cin >> (t);      \
    while ((t)--)
#define range(c, r) (c).begin(), (c).begin() + (r)    // Mainly used in sorting
#define present(c, x) ((c).find(x) != (c).end())      // for sets, maps, multi-maps
#define cpresent(c, x) (find(all(c), x) != (c).end()) // for vectors
#define run(x, c) for ((x) = (c).begin(); (x) != (c).end(); (x)++)
#define fo0 (i, n) for (i = 0; i < n; i++)
#define fo1 (i, n) for (i = 1; i <= n; i++)
#define rfo(i, n) for (i = n - 1; i >= 0; i--)
#define rfor(i, n) for (i = n; i > 0; i--)
signed main()
{
    int n, a, b;
    cin >> n >> a >> b;
    for (int i = a; i <= b; i++)
    {
        if (i % n == 0)
        {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}

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

int main() {
	vector<vector<pair<double,int> > > v;
	vector<pair<double,int> > v1;
	for(int i = 0; i < 3; i++) {
		v.push_back(vector<pair<double,int> >());
		for(int j = 0; j < 8; j++) {
			pair<double,int> tmp;
			cin >> tmp.second >> tmp.first;
			v[i].push_back(tmp);
		}
		sort(v[i].begin(), v[i].end());
		for(int j = 0; j < 2; j++) {
			printf("%d %.2f\n", v[i][j].second, v[i][j].first);
		}
		v1.insert(v1.end(), v[i].begin() + 2, v[i].end());
	}

	sort(v1.begin(), v1.end());
	for(int j = 0; j < 2; j++) {
		printf("%d %.2f\n", v1[j].second, v1[j].first);
	}

}

Measured memory_bytes: 1256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int x(char c){
	if(isdigit(c))return c-'0';
	else return c-'a'+10;
}

string color[]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};

int main() {
	string str;
	while(cin>>str,str!="0"){
		int r,g,b;
		r=x(str[1])*16+x(str[2]);
		g=x(str[3])*16+x(str[4]);
		b=x(str[5])*16+x(str[6]);
//cout<<r<<" "<<g<<" "<<b<<endl;
		int i;
		string res="";
		int re=1000000000;
		for(i=0;i<8;i++){
			if(re>(r-(i&4?255:0))*(r-(i&4?255:0))+(g-(i&2?255:0))*(g-(i&2?255:0))+(b-(i&1?255:0))*(b-(i&1?255:0))){
				res=color[i];
				re=(r-(i&4?255:0))*(r-(i&4?255:0))+(g-(i&2?255:0))*(g-(i&2?255:0))+(b-(i&1?255:0))*(b-(i&1?255:0));
			}
		}
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
n, k = map(int, input().split())
h = []
for _ in range(n):
    h.append(int(input()))
h.sort()
# answer = min(h[k - 1] - h[0], h[-1] - h[-k])
# print(answer)
answer = float('inf')
for i in range(n - k + 1):
    cost = h[k - 1 + i] - h[i]
    # print(h[i:k+i])
    if answer > cost:
        answer = cost

print(answer)

Measured memory_bytes: 7384
import numpy as np
N = int(input())
h = np.array(list(map(int, input().split())))

## 愚直にfor文組めばとりあえずすぐに解決できるけど...
count = 0
for i in range(1,N+1):
  mounts = h[:i]
  mounts_ = np.where(mounts<=h[i-1],0,1)
  if np.sum(mounts_) == 0:
    count += 1
print(count)

Measured memory_bytes: 12500
def solution(a):
    foo = []
    r = len(a)
    c = len(a[0])
    for i in xrange(r):
        for j in xrange(c):
            if a[i][j] & 1 == 1:
                if j != c - 1:
                    foo.append((i + 1, j + 1, i + 1, j + 2))
                    a[i][j] -= 1
                    a[i][j + 1] += 1
                elif i != r - 1:
                    foo.append((i + 1, j + 1, i + 2, j + 1))
                    a[i][j] -= 1
                    a[i + 1][j] += 1
    return foo

def main():
    r, c = [int(i) for i in raw_input().strip().split()]
    a = [[int(j) for j in raw_input().strip().split()] for i in xrange(r)]
    foo = solution(a)
    print(len(foo))
    for row in foo:
        print('%d %d %d %d' % row)

if __name__ == '__main__':
    main()


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

using namespace std;

int main(int argc, char const *argv[])
{
    int a;
    string s;
    cin >> a;
    cin >> s;

    if (a<3200) {
        cout << "red" << endl;
    }
    else cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] num = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };

            int K = int.Parse(Console.ReadLine());

            Console.WriteLine(num[K - 1].ToString());
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
int main(){
  int N,K;
  cin >> N >> K;
  vector<vector<int>> a(K,vector<int>(N));
  rep(i,K){
    int x;
    cin >> x;
    rep(j,x){
      int y;
      cin >> y;
      a.at(i).at(y-1)=1;
    }
  }
  int count=0;
  rep(i,N){
    bool h=0;
    rep(j,K){
      if(a.at(j).at(i)==1)h=1;
    }
    if(!h)count ++;
  }
  cout << count << endl;
    
}
  

Measured memory_bytes: 3636
import sys
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    N, X = mi()
    a, p = [1], [1]
    for i in range(N):
        a.append(a[i]*2+3)
        p.append(p[i]*2+1)

    def f(N, X):
        if N == 0:
            return 0 if X <= 0 else 1

        if X <= 1 + a[N-1]:
            return f(N-1, X-1)
        else:
            return p[N-1]+1+f(N-1, X-2-a[N-1])

    print(f(N, X))

if __name__ == '__main__':
    main()


Measured memory_bytes: 62024
/*
このコード、と～おれ!
Be accepted!
  ∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printfin(a) printf(a ? "possible\n" : "inposible\n")
#define all(x) (x).begin(), (x).end()
using ll = long long;

//マクロとかここまで

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>

using namespace std;

int main() {
	
	int n, k, ans = 0, x;
	scanf("%d%d", &n, &k);
	rep(i, n) {
		scanf("%d", &x);
		ans += min(x * 2, int(fabs(x - k) * 2));
	}
	printf("%d\n", ans);
	
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
using ll = long long;
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;


using mint = modint998244353;
using Vm = vector<mint>;

istream &operator>>(istream &is, mint &a) { int v; cin >> v; a = v; return is; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.val(); }


int main() {
  int n, m; cin >> n >> m;
  Vm a(n), b(m);


  // clang ではコンパイルエラーになる
  cin >> a >> b; 

  // clang でも gcc でも動く
  // for (auto &e : a) cin >> e;
  // for (auto &e : b) cin >> e;


  auto c = convolution(a, b);


  // clang ではコンパイルエラーになる
  cout << c << '\n';

  // clang でも gcc でも動く
  // for (auto e : c) cout << e << ' ';
  // cout << '\n';
}

Measured memory_bytes: 19024
n = int(input())
n_a = n % 10

if n_a == 2 or n_a == 4 or n_a == 5 or n_a == 7 or n_a == 9:
  print('hon')
elif n_a == 0 or n_a == 1 or n_a == 6 or n_a == 8:
  print('pon')
else:
  print('bon')

Measured memory_bytes: 9172
//https://atcoder.jp/contests/hitachi2020/tasks/hitachi2020_b
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}
int main() {
	ll A,B,M; cin>>A>>B>>M;
	vector<ll> aA(A);
	ll min_a=INT64_MAX;
	ll min_b=INT64_MAX;
	for(auto&& a:aA) {
		cin>>a;
		chmin(min_a,a);
	}
	vector<ll> bB(B);
	for(auto&& b:bB) {
		cin>>b;
		chmin(min_b,b);
	}

	ll ans=min_a+min_b;
	FOR(i,0,M){
		ll x,y,c; cin>>x>>y>>c;
		--x;--y;
		ll v=aA.at(x)+bB.at(y)-c;
		chmin(ans,v);
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	string s, t;
	cin >> s >> t;
	
	auto tapu = [&](string a, vector<vector<int>>& d) -> void {
		for (int i = 0; i < a.size(); ++i) {
			(a[i] == 'A' ? d[i+1][0] : d[i+1][1]) += 1;
			d[i+1][0] += d[i][0];
			d[i+1][1] += d[i][1];
		}
	};
	vector<vector<int>> ds(s.size() + 1, vector<int>(2, 0));
	vector<vector<int>> dt(s.size() + 1, vector<int>(2, 0));
	tapu(s, ds);
	tapu(t, dt);

	int Q;
	cin >> Q;
	vector<bool> ans(Q);
	for (int q = 0; q < Q; ++q) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;

		int sumS = (ds[b][0] - ds[a-1][0]) * 2 + (ds[b][1] - ds[a-1][1]);
		int sumT = (dt[d][0] - dt[c-1][0]) * 2 + (dt[d][1] - dt[c-1][1]);
		ans[q] = sumS % 3 == sumT % 3;
	}
	for (auto v : ans) { cout << (v ? "YES" : "NO") << endl; }

	return 0;
}


Measured memory_bytes: 14600
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug" << x << endl;
using namespace std;

int main(){
    int x,y,z;
    while(cin >> x >> y >> z){
        int ans = 0;
        range(i,x,y+1){
            if(z % i == 0) ans++;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define ll long long
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define INF = 1001001001
#define pi = acos(-1)
using namespace std;
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

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

    cout << a+(a*a)+(a*a*a) << endl;

    return 0;
}

Measured memory_bytes: 3616
using System;

namespace Aizu
{
    class OnlineJudge
    {
        public static void Main()
        {
            string[] str;
            while (true)
            {
                str = Console.ReadLine().Split(' ');
                int x = int.Parse(str[0]);
                int y = int.Parse(str[1]);
                if (x == 0 && y == 0) { break; }
                for (int i = 1; i <= x; i++)
                {
                    for (int j = 1; j <= y; j++)
                    {
                        if (i % 2 == 0 && j % 2 != 0 || i % 2 != 0 && j %  2 == 0)
                        {
                            Console.Write(".");
                        }
                        else
                        {
                            Console.Write("#");
                        }

                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }
        }
    }
}



Measured memory_bytes: 15940
#include <bits/stdc++.h>
#include <cstdio>
#include <cstdlib>

#ifdef _MSC_VER
#include <Windows.h>
#else
#include <unistd.h>
#endif

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD=(double)1e9+7;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

#define DEBUG


int main(){
    LL H,W;
    cin>>H>>W;
    LL res=H*W;
    LL S1,S2,S3;
    if(H%3==0||W%3==0){
        cout<<0<<endl;
        return 0;
    }
    for(LL i=1LL;i<H;i++){
        S1=i*W;
        if(W%2==0){
            S2=(LL)(W/2LL)*(H-i);
            S3=S2;
        }else{
            S2=(LL)((W-1LL)/2LL)*(H-i);
            S3=(LL)((W+1LL)/2LL)*(H-i);
        }
        res=min(max(max(abs(S1-S2),abs(S1-S3)),abs(S2-S3)),res);
        if((H-i)%2==0){
            S2=(H-i)*W/2LL;
            S3=S2;
        }
        res=min(max(max(abs(S1-S2),abs(S1-S3)),abs(S2-S3)),res);
    }
    LL tmp=W;
    W=H;
    H=tmp;
    for(LL i=1LL;i<H;i++){
        S1=i*W;
        if(W%2==0){
            S2=(LL)(W/2LL)*(H-i);
            S3=S2;
        }else{
            S2=(LL)((W-1LL)/2LL)*(H-i);
            S3=(LL)((W+1LL)/2LL)*(H-i);
        }
        res=min(max(max(abs(S1-S2),abs(S1-S3)),abs(S2-S3)),res);
        if((H-i)%2==0){
            S2=(H-i)*W/2LL;
            S3=S2;
        }
        res=min(max(max(abs(S1-S2),abs(S1-S3)),abs(S2-S3)),res);
    }

    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256