akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
const int inf = 1001001000;

void print(vector<vector<int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}
//mod nCrを返す関数.何回も計算するときはこっち.未検証
// long long int modcomb(int n, int r, long long int mod = 2147483647){
// 	if (n < r) return 0;
//     if (n < 0 || r < 0) return 0;
// 	static int flag = 1;
// 	static vector<long long int> fac(n+1,1);
// 	static vector<long long int> finv(n+1,1);
// 	static vector<long long int> inv(n+1,1);
// 	if (flag){
// 		for (int i = 2; i < n+1; i++){
// 			fac[i] = fac[i - 1] * i % mod;
// 			inv[i] = mod - inv[mod%i] * (mod / i) % mod;
// 			finv[i] = finv[i - 1] * inv[i] % mod;
//   		}
// 		flag = 0;
// 	}
//     return fac[n] * (finv[r] * finv[n - r] % mod) % mod;
// }
long long int modcomb(long long int n, long long int r){
	long long int x = 1, y = 1;
	for (long long int i = 0; i < r; i++){
		x = x * (n - i);
		y = y * (i + 1);
	}
	return x / y;
}

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	map<int, int> m;
	rep(i,n){
		m[a[i]]++;
	}
	int mx = 0;
	for (auto x : m)
	{
		mx = max(mx, x.second);
	}
	modcomb(mx+1, 2);
	long long int s = 0;
	for (auto x : m)
	{
		s += modcomb(x.second, 2);
	}
	rep(i,n){
		long long int ans = s;
		ans = ans - modcomb(m[a[i]], 2) + modcomb(m[a[i]] - 1, 2);
		cout << ans << endl;
	}


	return 0;
}

Measured memory_bytes: 10112
#include <bits/stdc++.h>
using LL = long long;
using namespace std;
int main() {
	LL n, k; cin >> n >> k;
	int a[n + 1] = {}; 
	for (int i = 1; i <= n; i++) cin >> a[i];
	vector<int> cycle;
	map<int, bool> mp;
	int st = -1;
	for (int i = 1; 1; i = a[i]) {
		if (!mp[a[i]]) {
			cycle.push_back(a[i]);
			mp[a[i]] = true;
		}
		else {
			st = a[i];
			break;
		}
	}
	for (int i = 0; i < cycle.size(); i++) {
		if (cycle[i] == st) {
			st = i;
			break;
		}
	}
	int sz = cycle.size();
	int len = sz - st;
	if (k <= sz) cout << cycle[k - 1];
	else {
		
		k -= sz;
		k %= len;
		cout << cycle[st + (k - 1 + len) % len];
	}
}

Measured memory_bytes: 13912
#!/usr/bin/env python
# coding: UTF-8

import sys
if sys.version_info[0]<3: input=raw_input

class StandardInput:

    def stdin_string(self):
        self.s=str(input().rstrip())
        return self.s

    def stdin_integer(self):
        self.n=int(input().rstrip())
        return self.n

    def stdin_array(self):
        self.arr=input().rstrip().split()
        return self.arr

    def stdin_integer_array(self):
        self.arr=list(map(int,input().rstrip().split()))
        return self.arr

def test(n):
    if n==3:
        return 'bon'
    elif n==0 or n==1 or n==6 or n==8:
        return 'pon'
    else:
        return 'hon'

def main():
    obj=StandardInput()
    n=int(obj.stdin_string()[-1])
    print(test(n))
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 9200
import java.util.*;

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

        String str = "";
        int[] cnt = new int[26];

        while(sc.hasNext()) {
            str = sc.nextLine();
            str = str.toLowerCase();
            char[] c = str.toCharArray();
            for(int i = 0; i < c.length; i++) {
                if('a' <= c[i] && c[i] <= 'z') {
                    cnt[c[i] - 'a']++;
                }
            }
        }
        for(int i = 0; i < 26; i++) {
            System.out.println(((char)(i + 'a')) + " : " + cnt[i]);
        }
    }
}

Measured memory_bytes: 26060
N = int(input())
numList = []

def isPrime(num):
    retVal = True
    if num % 2 == 0:
        retVal = False
    else:
        for n in range(3, num//2, 2):
            if num % n == 0:
                retVal = False
                break
    return retVal

num = 6
for i in range(N):
    for prime in range(num+5, 55555, 5):
        if isPrime(prime):
            num = prime
            numList.append(prime)
            break

ans = " ".join(map(str, numList))
print(ans)

Measured memory_bytes: 3064
def judge(s):
    n = len(s)
    
    for i in range(n//2):
        if s[i]!=s[n-1-i]:
            return False
    
    return True

S = input()
N = len(S)

if judge(S) and judge(S[:(N-1)//2]) and judge(S[(N-1)//2+1:]):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38256
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <deque>
#include <queue>

using namespace std;
typedef long long ll;
using namespace std;
        
int main(){
    int X;
    cin >> X;
    if(X == 2){
        cout << X << endl;
    } else {
        if(X%2 == 0) X++;
        while(true){
            int a = X;
            for(int i = 2; i <= sqrt(X); i++){
                if(a%i == 0){
                    a/=i;
                    break;
                }
            }
            if(a == X){
                cout << X << endl;
                break;
            }
            X+=2;
        }
    }
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;
class Main {
	// 絵柄の種類
	enum MARK {
		S, H, C, D;
	}

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

		// カード番号の開始・終了
		final int startNum = 1, endNum = 13;

		// 所持カードリストを作成
		ArrayList<Card> exsistsCards = new ArrayList<Card>();

		// 所持カード枚数(入力レコード数)を入力
		int cardCount = Integer.parseInt(sc.nextLine());

		for (int i = 0; i < cardCount; i++) {
			// 所持カード(絵柄 + " " + 数字)の入力
			exsistsCards.add(new Card(sc.nextLine()));
		}

		// カードの全パターンを列挙してリストにないものを出力
		for (MARK m : MARK.values()) {
			num: for (int i = startNum; i <= endNum; i++) {
				String str = m + " " + i;
				for (Card c : exsistsCards) {
					if (str.equals(c.getString())) {
						continue num;
					}
				}
				System.out.println(str);
			}
		}
	}

	// カードクラス
	static class Card {
		private MARK mark; // 絵柄
		private int num; // 数字

		// 絵柄と数字から生成
		Card(String input) {
			String[] str = input.split("[\\s]+");
			this.mark = MARK.valueOf(str[0]);
			this.num = Integer.parseInt(str[1]);
		}

		public String getString() {
			return this.mark + " " + this.num;
		}
	}
}



Measured memory_bytes: 26484
#include "bits/stdc++.h"
#include<vector>
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<iomanip>
#include<assert.h>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<stack>
#include<complex>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;
	
#define WHATS(var)cout<<__LINE__<<' '<<#var<<"="<<var<<endl;
	
template<class S, class T> ostream& operator <<(ostream &os, const pair<S, T> v){
os << "( " << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<T> &v){
for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<vector<T>> &v){
for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<set<T>> &v){
for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream &os, const set<T> &v){
int i=0;
for(auto it:v){
	if(i > 0){os << ' ';}
	os << it;
	i++;
} 
return os;
}
template<class T,class TT> ostream& operator <<(ostream &os, const map<T,TT> &v){
	int i=0;
	for(auto it:v){
		if(i > 0){os << ' ';}
		os << it;
		i++;
	} 
return os;
}
using ll = long long ;

bool ask(vector<int>v){
	cout<<'?';
	for(auto x:v){
		cout<<' '<<x+1;
	}
	cout<<endl;
	string st;cin>>st;
	return st=="Red";
}

bool askl(int N,int l){
	vector<int>v(N);
	iota(v.begin(),v.end(),l);
	return ask(v);
}
int main(){
	ios::sync_with_stdio(false);
	
	int N;cin>>N;

	bool zero_red;
	{
		zero_red=askl(N,0);
	}

	int same_l=-1,same_r=-1;

	{
		int ng=0;
		int ok=N;

		while(ng+1!=ok){
			int amid=(ng+ok)/2;
			if(askl(N,amid)==zero_red){
				ng=amid;
			}else{
				ok=amid;
			}
		}
		same_l=ok;
		same_r=ok+N-1;
	}

	vector<int>is_reds(2*N,-1);

	vector<int>red_places,blue_places;
	for(int i=0;i<2*N;++i){
		if(same_l<=i&&i<same_r)continue;
		else{
			vector<int>v(N-1);
			iota(v.begin(),v.end(),same_l);
			v.push_back(i);
			is_reds[i]=ask(v);
			if(is_reds[i]){
				if(red_places.size()<N/2)red_places.push_back(i);
			}else{
				if(blue_places.size()<N/2)blue_places.push_back(i);
			}
		}
	}
	for(int i=0;i<2*N;++i){
		if(same_l<=i&&i<same_r){
			vector<int>v(red_places);
			v.insert(v.end(),blue_places.begin(),blue_places.end());
			v.push_back(i);
			is_reds[i]=ask(v);
		}
	}
	cout<<"! ";
	for(int i=0;i<2*N;++i){
		if(is_reds[i])cout<<"R";
		else cout<<"B";
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 724
n = int(input())
l = list(map(int, input().split()))

ls = [0]*n
sum = 0
for i in range(n):
  ls[i] = l[i] - (i+1)

ls.sort()
med = ls[n//2]

for i in ls:
  sum += abs(i - med)
print(sum)

Measured memory_bytes: 25196
#include <bits/stdc++.h>
using namespace std;
const int MAX_N=100005;
const int INF=0x3f3f3f3f;
int h[MAX_N];
int dp[MAX_N]; 
int n,k;
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>h[i];
	dp[1]=0;
	for(int i=2;i<=n;i++)
	{
		dp[i]=INF;
		for(int j=max(i-k,1);j<i;j++)
		{
			dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
		}
	}
	cout<<dp[n]<<endl;
	return 0;
}


Measured memory_bytes: 1024
P = [input().split() for i in range(3)]
N = int(input())
b = [input() for i in range(N)]

P_ = [[0,0,0] for _ in range(3)]
for j in range(3):
    for i in range(3):
        if P[i][j] in b:
            P_[i][j] = 1
        else:
            P_[i][j] = 0
            
ans = 'No'

# 横
for i in range(3):
    if [P_[i][j] for j in range(3)] == [1,1,1]:
        ans = 'Yes'
        
# 縦
for i in range(3):
    if [P_[j][i] for j in range(3)] == [1,1,1]:
        ans = 'Yes'
        
if [P_[i][2 - i] for i in range(3)] == [1,1,1]:
    ans = 'Yes'
        
if [P_[i][i] for i in range(3)] == [1,1,1]:
    ans = 'Yes'
    
print(ans)


Measured memory_bytes: 3064
#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;


#define Seg_Max_N (1<<18) 

using Value = pair<long long int, long long int>;
const Value ini = (make_pair(1e18, 0));
struct segtree {
	int N;
	vector<int>nums;
	vector<Value>dat;

	segtree() {}
	segtree(int n) :dat(2 * Seg_Max_N), nums(2 * Seg_Max_N) {
		N = 1;
		while (N < n) N *= 2;
		for (int i = 0; i < 2 * N - 1; i++) {
			dat[i] = ini;
		}
	}
	// update k th element
	void update(int k, Value a) {
		k += N - 1; // leaf
		if (a == ini) {
			nums[k]--;
			if (!nums[k])dat[k] = a;
		}
		else {
			nums[k]++;
			dat[k] = a;
		}
		while (k > 0) {
			k = (k - 1) / 2;
			const Value al(dat[k * 2 + 1]);
			const Value ar(dat[k * 2 + 2]);
			dat[k] = min(al, ar);
		}
	}
	// min [a, b)
	Value  query(int a, int b) { return query(a, b, 0, 0, N); }
	Value  query(int a, int b, int k, int l, int r) {
		if (r <= a or b <= l) return ini;
		if (a <= l and r <= b) return dat[k];
		const int m = (l + r) / 2;
		const Value al(query(a, b, k * 2 + 1, l, m));
		const Value ar(query(a, b, k * 2 + 2, m, r));
		return min(al,ar);
	}
};
int main() {
	int N, R, L; cin >> N >> R >> L;
	int pre = 0;
	int ntop = 0;
	vector<int>times(N);
	vector<int>scores(N);
	segtree seg(N);
	for (int i = 0; i < N; ++i) {
		seg.update(i, make_pair(0, i));
	}
	for (int i = 0; i < R; ++i) {
		int d, t, x; cin >> d >> t >> x; d--;
		const int top = seg.query(0, N).second;
		times[top] += t - pre;
		pre = t;
		scores[d] -= x;
		seg.update(d,make_pair( scores[d],d));
	}
	const int top = seg.query(0, N).second;
	times[top] += L - pre;
	int amax = -1;
	int time = -1;
	for (int i = 0; i < N; ++i) {
		if (time < times[i]) {
			time = times[i];
			amax = i;
		}
	}
	cout << amax+ 1 << endl;
	return 0;
}

Measured memory_bytes: 13900
#include <stdio.h>

#define MAX 10000
#define NIL -1

typedef struct { int parent, left, right;} Node;

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u,int d) {
  if(u == NIL) return;
  D[u] = d;
  setDepth(T[u].left, d+1);
  setDepth(T[u].right,d+1);
}

int setHeight(int u) {
  int h1 = 0, h2 = 0;
  if(T[u].left != NIL)
    h1 = setHeight(T[u].left)  + 1;
  if(T[u].right != NIL)
    h2 = setHeight(T[u].right) + 1;
  return H[u] = (h1 > h2 ? h1 : h2);
}

int getSibling(int u) {
  if(T[u].parent == NIL) return NIL;
  if(T[T[u].parent].left != u && T[T[u].parent].left != NIL )
    return T[T[u].parent].left;
  if(T[T[u].parent].right != u && T[T[u].parent].right != NIL )
    return T[T[u].parent].right;
  return NIL;
}

void print(int u) {
  int deg = 0;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].parent);
  printf("sibling = %d, ",getSibling(u));
  if(T[u].left  != NIL) deg++;
  if(T[u].right != NIL) deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);
  
  if(T[u].parent == NIL) {
    printf("root\n");
  } else if(T[u].left == NIL && T[u].right == NIL) {
    printf("leaf\n");
  } else {
    printf("internal node\n");
  }
}

int main(void) {
  int i, v, l, r, root = 0;
  scanf("%d",&n);
  for(i=0;i<n;i++) T[i].parent = NIL;
  for(i=0;i<n;i++) {
    scanf("%d %d %d",&v,&l,&r);
    T[v].left  = l;
    T[v].right = r;
    if(l != NIL) T[l].parent = v;
    if(r != NIL) T[r].parent = v;
  }
  
  for(i=0; i<n; i++)
  if(T[i].parent == NIL) root = i;
  
  setDepth(root,0);
  setHeight(root);
  
  for(i=0;i<n;i++) print(i);
  
  return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include<string>
#include<stack>
#include<queue>
#include<stdio.h>
#include <algorithm>
#include<set>
#include<vector>

#define _CRT_SECURE_NO_WARNINGS

using namespace std;


int main()
{
	
	int a, b, c, d;
	int sum = 0;
	int count=0;
	int kari = 0;
	int w, h;
	int x, y, r;
	vector<string> lang;
	vector<int> data;
	string s; // s.size() to_string char string %s

	cin >> a >> b;

	printf("%d %d %.5lf\n", a / b, a % b, (double)a / b);
	return 0;
}



Measured memory_bytes: 3232
using System;
using System.Collections.Generic;

class ABC_129_C
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int N = int.Parse(input[0]);
        int M = int.Parse(input[1]);

        int[] A = new int[M];
        for (int i = 0; i < M; i++)
        {
            A[i] = int.Parse(Console.ReadLine());
            if(i>0 && A[i-1]+1==A[i])
            {
                Console.WriteLine(0);
                return;
            }
        }

        int bi = M==0 ? -1: 0;
        ulong[] pattern = new ulong[N+1];
        pattern[0] = 1L;
        for (int i = 0; i < N; i++)
        {
            if (bi >= 0 && bi < M && A[bi] == i)
            {
                pattern[i] = 0L;
                bi++;
            }
            pattern[i+1] += pattern[i] % 1000000007UL;
            if(i+1<N) pattern[i+2] += pattern[i] % 1000000007UL;
        }

        Console.WriteLine(pattern[N] % 1000000007UL);
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 
//using namespace boost::multiprecision; 
using namespace std;
#define ll long long int
#define ld long long double
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll, ll>
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define nl '\n'
#define mp make_pair
#define debug1(x) cout <<#x<<" "<<x<<'\n';
#define debug2(x,y) cout <<#x<<" "<<x <<" "<<#y<<" "<<y <<'\n';
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<'\n';
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define inf 1e18
const int mod = (int)1e9+7;
pair<ll,ll>s4[4]={{-1,0},{1,0},{0,-1},{0,1}};
pair<ll,ll>s8[8]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,1},{1,0},{1,-1}};

void solve() {
    ll a,b,c;
    cin >> a >>b>>c;
    swap(a,b);
    swap(a,c);
cout << a << " "<< b <<" "<<c <<endl;

}

signed main() {
    boost;
    solve();
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#define rep(i, s, t) for(i = s; i <= t; ++i)
#define dep(i, s, t) for(i = s; i >= t; --i)

using namespace std;

const int N = 55;
int n;
int a[N][N], b[N];
int tmp[N];
long long ans;

void cp(int *a, int *b) {
	int i;
	rep(i, 0, 50) b[i] = a[i];
}

bool check(int *a, int S, int p) {
	int i, j;
	dep(i, S, 1)
		rep(j, 1, 50) a[j%i] |= a[j];
	return a[p];
}

int main() {
	int i, j, k, x; bool f;
	scanf("%d", &n);
	rep(i, 1, n) {scanf("%d", &x); a[i][x] = 1;}
	rep(i, 1, n) scanf("%d", &b[i]);
	
	rep(i, 1, n) {
//		rep(j, 1, n) tmp[j] = a[i][j];
		cp(a[i], tmp);
		if(!check(tmp, 50, b[i])) {puts("-1"); return 0;}
	}
	dep(i, 50, 1) {
		f = 0;
		rep(j, 1, n) {
			cp(a[j], tmp);
			if(!check(tmp, i-1, b[j])) {f = 1; break;}
		}
		if(f) {
			rep(j, 1, n)
				rep(k, 1, 50)
					a[j][k%i] |= a[j][k];
			ans += 1ll << i;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];
    rep(i, n - 1) {
        if (h[i] < h[i + 1]) continue;
        if ((i != 0) && (h[i] == h[i - 1])) continue;
        h[i]--;
    }
    bool ans = true;
    rep(i, n - 1) {
        if (h[i] > h[i + 1]) {
            ans = false;
            break;
        }
    }
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 1024
N = int(input())
As = list(map(lambda x: int(x), input().split(" ")))

hat_list = [0] * 100000

result = 1

for a in As:
    pre_hat = hat_list[a-1]
    if a == 0:
        pre_hat = 3
    hat = hat_list[a]

    result *= (pre_hat - hat)
    result %= 1000000007
    hat_list[a] += 1

print(result)


Measured memory_bytes: 14396
n=int(input())
a=[int(i) for i in input().split()]

ans='APPROVED'

for i in range(n):
    if a[i] % 2 == 0:
        if a[i] % 3 != 0:
            if a[i] % 5 != 0:
                ans='DENIED'

print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define ios() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
constexpr ll MOD = 10e9+7;
constexpr ll INF = 1LL << 60;
constexpr int Inf = 1e9;
inline int in() {int x; cin >> x; return x;}
template <typename T> inline void out(const T& x) {cout << x << endl;}
template <class T> inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}
template <class T> inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
//UP = 0;RIGHT = 1; DOWN = 2; LEFT =3;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b)
{
  if (a < b)
    gcd(b, a);
  int r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}
void eratos(bool * isPrime,int max){
  fill(isPrime,isPrime + max,true);
  isPrime[0] = false; 
  isPrime[1] = false; 
  for(int i=2; i<=max/i; ++i) 
      if(isPrime[i]) 
          for(int j=2; j<=max/i; ++j) 
              isPrime[i*j] = false;    
}
//

int ans[100010],table[100010];
signed main()
{
  ios();
  int N;
  string S;
  int Q;
  cin >> N >> Q >> S;
  int L = S.length();
  fill(table,table + L,0);
  rep(i,L-1)
  {
    if(S[i]== 'A' && S[i+1] == 'C') table[i] = 1;
  }
  rep(i,L-1) table[i+1] += table[i];
  rep(i,Q)
  {
    int l,r;
    cin >> l >> r;
    ans[i] = table[r-2] -table[l-2];
  }
  rep(i,Q) cout << ans[i] << endl;

  
}


Measured memory_bytes: 2640
# B
S = input()
res = (len(S) * (len(S) - 1)) // 2 + 1

cnt_dict = dict()
for s in "abcdefghijklmnopqrstuvwxyz":
    cnt_dict[s] = 0

for i in range(len(S)):
    cnt_dict[S[i]] += 1
    
for s in "abcdefghijklmnopqrstuvwxyz":
    if cnt_dict[s] >= 2:
        d = (cnt_dict[s] * (cnt_dict[s] - 1)) // 2
        res -= d
        
print(res)

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


int N;
int T[100000], X[100000], Y[100000];


void solve(){
    int t = 0, x = 0, y = 0;
    for(int n = 0; n < N; n++){
        int dt = T[n] - t;
        int dx = abs(X[n] - x);
        int dy = abs(Y[n] - y);
        if(dt < dx + dy || ((dx + dy + dt) % 2 != 0)){
            cout << "No" << endl;
            return;
        }
        t = T[n], x = X[n], y = Y[n];
    }
    cout << "Yes" << endl;
}


int main(){
    cin >> N;
    for(int n = 0; n < N; n++){
        cin >> T[n] >> X[n] >> Y[n];
    }
    solve();
    return 0;
}

Measured memory_bytes: 1408
import java.util.*;
class Main {
  public static void main(String[] args) {
    
    Scanner scan = new Scanner(System.in);
    int n= scan.nextInt();
    ArrayList<Integer> a = new ArrayList<>();
    for(int i =0 ; i < n ; i++){
      a.add(scan.nextInt());
    }
    int max = a.remove(a.indexOf(Collections.max(a, null)));
    int sum = 0;
    for(int x : a){
      sum+=x;
    }
    if(sum>max){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 20948
inpt = input()
inpts = inpt.split()
a = int(inpts[0])
b = int(inpts[1])
c = int(inpts[2])
k = int(inpts[3])

if a >= k:
    s = k
elif a+b >= k:
    s = a
else:
    s = a - (k - (a+b))
print(s)

Measured memory_bytes: 9156
// CppPractice.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int n, tmp;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> tmp;
		a.at(tmp - 1) = i + 1;
	}

	for (int i = 0; i < n; i++) {
		cout << a.at(i) << " ";
	}
	cout << endl;
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


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

#define MAX_N 200000

using namespace std;



string s;

int n;

bool pal(int st, int dr)
{
    for(int i = st, j = dr; i < j; i ++, j --)
    {
        if(s[i] != s[j])
            return 0;
    }

    return 1;
}

int a[MAX_N + 1];
int ap[MAX_N + 1];

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i ++)
    {
        cin >> a[i];
        ap[a[i]] ++;
    }

    long long rez = 0;
    for(int i = 1; i <= n; i ++)
        rez = rez + 1LL * ap[i] * (ap[i] - 1) / 2;

    for(int i = 1; i <= n; i ++)
    {
        long long ant = rez;
        int x = a[i];
        rez = rez - 1LL * ap[x] * (ap[x] - 1) / 2;
        rez = rez + 1LL * (ap[x] - 1) * (ap[x] - 2) / 2;


        cout << rez << "\n";
        rez = ant;
    }

    return 0;
}


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

int main() {
	int n;
	double t, a;
	cin >> n >> t >> a;
	double min_value = 1LL << 60;
	int min_index = -1;
	for (int i = 0; i < n; ++i) {
		double h;
		cin >> h;
		double diff = abs((t - h * 0.006) - a);
		if (diff < min_value) {
			min_value = diff;
			min_index = i;
		}
	}
	cout << min_index + 1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// Hey! 僕の提出を見てくれてありがとう.
// ロボ子さん可愛いぞ！！！！！君もV沼にはまろう↓
// https://www.youtube.com/channel/UCDqI2jOz0weumE8s7paEk6g
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
//sortを降順にする時は greater<型>()

void solve(long long N){
  string a = to_string(N);
  char x = a[a.length()-1];
  if(x == '0' ||x == '1' ||x == '6' ||x == '8'){
    cout << "pon" << endl;
  }else if(x == '3'){
    cout << "bon" << endl;
  }else{
    cout << "hon" << endl;
  }
}

int main(){
    long long N;
				scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3716
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    # n: 0-ind, m: 1-ind
    n,m = map(int, input().split())
    ml = [ [] for _ in range(m+1)]
    
    # 0~n-1: people (-1), n~n+m-1: lang (+n-1)
    uf = UnionFind(n+m)

    for i in range(n):
        ll = list(map(int, input().split()))[1:]
        for l in ll:
            uf.union(i,l+n-1)
    
    for i in range(n):
        if not uf.same(0,i):
            print('NO')
            break
    else:
        print('YES')
        


if __name__ == "__main__":
    main()

Measured memory_bytes: 86320
# ABC144E - Gluttony
def binary_search(upper_bound: int = 1 << 60, lower_bound: int = -1) -> int:
    ok, ng = upper_bound, lower_bound
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if check(mid):
            ok = mid
        else:
            ng = mid
    return ok


def check(x: int) -> bool:
    cost = sum(a - x // f for a, f in zip(A, F) if a * f > x)
    return cost <= K


def main():
    global K, A, F
    N, K, *AF = map(int, open(0).read().split())
    A, F = AF[:N], AF[N:]
    A.sort(), F.sort(reverse=1)
    ans = binary_search()
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 127928
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
int a[100000+9], n, f[100000+9], f1[100000+9];
int main() {
    //freopen("inp.txt","r",stdin);
	cin >> n;
	for (int i=1; i<=n; i++) cin >> a[i];
	f[1] = a[1];
	for (int i=2; i<=n; i++)
		f[i] = __gcd(f[i-1], a[i]);
	f1[n] = a[n];
	for (int i=n-1; i>=1; i--)
		f1[i] = __gcd(f1[i+1], a[i]);
	int res = max(f[n-1], f1[2]);
	for (int i=2; i<=n-1; i++)
		res = max(res, __gcd(f[i-1], f1[i+1]));
	cout << res;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
int main()
{
   int a,b,c,result;

   cin>>a>>b>>c;
   if((a==b && b==c && c==a)||(a!=b && b!=c && c!=a)){
        cout<<"No"<<endl;
   }
   else{
         cout<<"Yes"<<endl;
   }


    return 0;
}


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

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

int main()
{
  int n, d;
  cin >> n >> d;

  vector<long long> x(n), y(n);
  rep(i, 0, n) cin >> x[i] >> y[i];

  int ans = 0;
  rep(i, 0, n)
  {
    if (x[i] * x[i] + y[i] * y[i] <= (long long)d * d)
      ans++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 6384
package main

import (
	"fmt"
)

func max(a int, b int) int{
	if a < b {
		return b
	}
	return a
}


func main() {
	var a,b int
	fmt.Scan(&a,&b)
	plus := a+b
	minus := a-b
	multi := a*b
	max := max(max(plus, minus),multi)
	
	fmt.Println(max)
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

int main(){
    long long h, n;
    cin >> h >> n;

    vector<long long> a(n);
    vector<long long> b(n);

    for(long long i = 0; i < n; i++) cin >> a[i] >> b[i];

    vector<long long> dp(h+1, 1e12);
    dp[0] = 0;

    for(long long i = 1; i <= h; i++){
        for(long long j = 0; j < n; j++){
            if(i <= a[j]){
                dp[i] = min(dp[i], b[j]);
            }
            else{
                dp[i] = min(dp[i], dp[i-a[j]] + b[j]);
            }
        }
    }

    cout << dp[h] << endl;
    return 0;
}

Measured memory_bytes: 3728
n,k=map(int,input().split())
s=list(input())
point=s[0]
count=0
while k!=0 and count!=n:
    if s[count]!=point:
        while True:
            if count==n:break
            elif s[count]!=point:
                s[count]=point
                count +=1
            else:break
        k -=1
    else:count +=1

#print("".join(s))
ans=0
for i in range(n-1):
    if s[i]==s[i+1]:
        ans +=1
print(ans)

Measured memory_bytes: 49648
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
#define chmax(x,y) (x = max(x, y))
void solve(); int main() { solve(); return 0; }

void solve() {
  vector<int> S;
  loop(i,0,3) {
    int a;
    cin >> a;
    S.push_back(a);
  }
  sort(S.begin(), S.end());
  if (S[0]+S[1]==S[2]) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin>>N;
    double ans=0;
    for(int i=0;i<N;i++){
        double x;
        string u;
        cin>>x>>u;
        if(u=="JPY")ans+=x;
        else ans+=x*380000;
    }
    cout<<ans;
}

Measured memory_bytes: 256
// Complete Binary Tree
#include <stdio.h>

#define MAX 250
//#define NIL -1 // 番兵

int parent(int i){
  return i / 2; // 親の接点番号
}

int left(int i){
  return 2 * i; // 左の子の接点番号
}

int right(int i){
  return 2 * i + 1; // 右の子の接点番号
}

int main(){
  int i, n, A[MAX];

  scanf("%d", &n);

  //for(i=0; i <= n; i++){
  //  A[parent(i)] = A[left(i)] = A[right(i)] = NIL;
  //}

  // 1オリジンでキーの列を入力
  for(i=1; i <= n; i++){
    scanf("%d", &A[i]);
  }

  /*
  for(i=1; i <= n; i++){
    printf("node %d: key = %d, ", i, A[i]);
    if(A[parent(i)] != NIL)printf("parent key = %d, ", A[parent(i)]);
    if(A[left(i)] != NIL)printf("left key = %d, ", A[left(i)]);
    if(A[right(i)] != NIL)printf("right key = %d, ", A[right(i)]);
    printf("\n");
  }
  */

  for(i=1; i <= n; i++){
    printf("node %d: key = %d, ", i, A[i]);
    if(parent(i) > 0)printf("parent key = %d, ", A[parent(i)]);
    if(left(i) <= n)printf("left key = %d, ", A[left(i)]);
    if(right(i) <= n)printf("right key = %d, ", A[right(i)]);
    printf("\n");
  }
  
  return 0;
}



Measured memory_bytes: 2040
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
static const int MAX_N = 300;
static const int MAX_M = 300;

int N, M;
int A[MAX_M][MAX_N];

int sport[MAX_M + 1];

void solve(){
	int min = 300;
	for(int i = 0; i < M; i++){
		fill(sport, sport + M + 1, 0);
		for(int j = 0; j < N; j++){
			for(int k = 0; k < M; k++){
				if(A[j][k] != 0){
					//cout << A[j][k];
					//if(j == N - 1) cout << endl;
					//else cout << " ";
					sport[A[j][k]]++;
					break;
				}
			}
		}
		int max = 0;
		int max_i;
		for(int j = 1; j <= M; j++){
			//cout << sport[j] << endl;
			if(sport[j] > max){
				max = sport[j];
				max_i = j;
			}
		}
		//cout << max << endl;
		for(int j = 0; j < N; j++){
			for(int k = 0; k < M; k++){
				if(A[j][k] == max_i) A[j][k] = 0;
			}
		}
		if(min > max) min = max;
	}
	cout << min << endl;
}

int main(){
	cin >> N >> M;
	for(int i = 0; i < N; i++){
		for(int j = 0; j < M; j++){
			cin >> A[i][j];
		}
	}
	solve();
	return 0;
}


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

// #include <boost/algorithm/string/join.hpp>
// using boost::algorithm::join;
//
// #include "boost/multi_array.hpp"
// boost::multi_array<int, 3> dp;
// dp.resize(boost::extents[10][9][8]);
//
// #include <boost/multiprecision/cpp_dec_float.hpp>  // quite slowly
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision; // mp::log10
// using bigint = boost::multiprecision::cpp_int;
// using rational = mp::cpp_rational;  // double d = static_cast<double>(r);

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

//constexpr ll MOD = 1e9+7;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/4;
constexpr int INF=inf<int>;
constexpr ll LINF=inf<ll>;

#define Sort(x) sort(begin(x),end(x))
#define Reverse(x) reverse(begin(x),end(x))
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ull<<(n))
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,(v).size())

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
#define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

int main(int argc, char** argv) {
  int N;
  cin >> N;

  set<ll> S;
  REP(i, N) {
    ll x;
    cin >> x;
    auto ret = S.insert(x);
    if (!ret.second) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;

  return 0;
}

/* vim: set expandtab shiftwidth=2 softtabstop=2 : */


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
int board[10][10];
int grid[205][205];
int minCost[10];
vector<pair<int,int> > edgeList[10];
int minDist[10];
bool special;
int main()
{
    int H,W;
    cin >> H >> W;
    for(int i = 0;i <= 9;i++)
    {
        for(int j = 0;j <= 9;j++)
        {
            cin >> board[i][j];
            edgeList[i].push_back(make_pair(j,board[i][j]));
        }
    }
    for(int i = 0;i <= 9;i++)
    {
        for(int z = 0;z <= 9;z++)
            minDist[z] = 1e9;
        minDist[i] = 0;
        priority_queue<pair<int,int> > myQ;
        myQ.push(make_pair(0,i));
        while(!myQ.empty())
        {
            pair<int,int> curTop = myQ.top();
            myQ.pop();
            for(int j = 0;j < edgeList[curTop.second].size();j++)
            {
                int child = edgeList[curTop.second][j].first;
                int weight = edgeList[curTop.second][j].second;
                if(minDist[child] > minDist[curTop.second] + weight)
                {
                    minDist[child] = minDist[curTop.second] + weight;
                    myQ.push(make_pair(minDist[child]*-1,child));
                }
            }
        }
        minCost[i] = minDist[1];
    }
    long long totalPaid = 0;
    for(int i = 1;i <= H;i++)
    {
        for(int j = 1;j <= W;j++)
        {
            cin >> grid[i][j];
            if(grid[i][j] != -1)
                totalPaid += minCost[grid[i][j]];
        }
    }
    cout << totalPaid;

    return 0;
}


Measured memory_bytes: 384
from collections import defaultdict

N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))

dic = defaultdict(int)
for d in D:
    dic[d] += 1

for t in T:
    if t in dic and dic[t] >= 1:
        dic[t] -= 1
    else:
        print("NO")
        exit()
print("YES")


Measured memory_bytes: 41700
import java.util.*;
import java.util.function.*;
import java.math.*;
public class Main {
    public static void main(String[] args){
		Scanner s = new Scanner(System.in);
		int N = s.nextInt();
		long[] A = new long[N];
		Map<Long, Long> map1 = new HashMap<>();
		Map<Long, Long> map2 = new HashMap<>();
		for(int i = 0; i < N; i++) {
			A[i] = s.nextLong();
			if(i + 1 > A[i])
				map1.put(i + 1 - A[i], map1.getOrDefault(i + 1 - A[i], 0l) + 1);
			map2.put(i + 1 + A[i], map2.getOrDefault(i + 1 + A[i], 0l) + 1);

		}

		long result = 0;
		for(Map.Entry<Long, Long> entry : map1.entrySet()) {
			result += entry.getValue() * map2.getOrDefault(entry.getKey(), 0l);
		}

		System.out.println(result);
    }
}


Measured memory_bytes: 80584
#include <cstdio>
#pragma warning(disable : 4996)
int c[29]; long long ret; char s[200009];
int main() {
	scanf("%s", s);
	for (int i = 0; s[i]; i++) ret -= c[s[i] - 97], c[s[i] - 97]++, ret += i;
	printf("%lld\n", ret + 1);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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; }

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll k;
  cin >> k;
  ll n = 50;
  ll mod = k % n;
  ll num = k / n;
  cout << n << endl;
  rep(i, n){
    ll val = num + 49;
    if(i < mod) val += n - (mod-1);
    else val -= mod;
    cout << val << ' ';
  }
  cout << endl;

}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int count[4][3][10] = {0};
	int N, i, j, k;

	fscanf(stdin, "%d", &N);
	for (i = 0; i < N; i++) {
		int b, f, r, v;
		fscanf(stdin, "%d %d %d %d", &b, &f, &r, &v);
		count[b - 1][f - 1][r - 1] += v;
	}
	for (i = 0; i < 4; i++) {
		if (i > 0) printf("####################\n");
		for (j = 0; j < 3; j++) {
			for (k = 0; k < 10; k++) {
				printf(" %d", count[i][j][k]);
			}
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 616
FAST_IO = 1
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())
N,M, k= rrm()
a = rrm()
b = rrm()
prefix_a = [0]
for n in a:
    prefix_a.append(prefix_a[-1]+n)
prefix_b = [0]
for n in b:
    prefix_b.append(prefix_b[-1]+n)
ans = 0
b = M
for i in range(0, N+1):
    # take i from a
    while b>0 and (prefix_a[i] + prefix_b[b])>k :
        b -= 1
    if prefix_a[i]+prefix_b[b]<=k:
        ans = max(ans, i+b)
print(ans)
    
    

Measured memory_bytes: 128536
import java.util.*;

public class Main {
    static HashMap<String,Long> dic = new HashMap<>();
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long x = sc.nextLong();
        long layer = (long) (4*Math.pow(2,n)-3);
        dic.put(Long.toString(1),1L);
        long ans = helper(layer,x);
        System.out.println(ans);
    }
    // treat every sub-problem as a complete burger. Make-up for the lower buns when necessary
    static public long helper(long layer, long x){
        String k = Long.toString(layer)+"*"+Long.toString(x);
        long ans = 0;
        if(dic.containsKey(k)) return dic.get(k);
        if(x<=0||layer==0) return 0;
        if(layer==1) return 1;
        // in former step, the bun on the top may be annoying so that x>layer.
        // in case this happens, let x <= layer for all the time.
        if(x>layer) x=layer;
        if(2*x+1<=layer){
            ans += helper((layer-3)/2,x-1);
        } else{
            ans += helper((layer-3)/2,(layer-3)/2);
            ans += 1; // the patty in the middle
            if(x==layer) x--;// eating the top bun means nothing
            ans += helper((layer-3)/2,x-(layer+1)/2);
        }
        dic.put(k,ans);
        return ans;
    }
}

Measured memory_bytes: 21844
#include <iostream>

int main() {
    int A, B, C, D, E, F;
    std::cin >> A >> B >> C >> D >> E >> F;

    double max_density = -1;
    int total_mass_at_max = 0;
    int sugar_mass_at_max = 0;

    for (int a = 0; 100 * A * a <= F; a ++) {
        for (int b = 0; 100 * A * a + 100 * B * b <= F; b ++) {
            int water = 100 * A * a + 100 * B * b;

            for (int c = 0; C * c <= F - water; c ++) {
                for (int d = 0; D * d <= F - water - C * c; d ++) {
                    int sugar = C * c + D * d;
                    if ((water + sugar) * E < sugar * (100 + E)) continue;

                    double density = (double)sugar / (double)(water + sugar);
                    if (density > max_density) {
                        max_density = density;
                        total_mass_at_max = water + sugar;
                        sugar_mass_at_max = sugar;
                    }
                }
            }
        }
    }
    std::cout << total_mass_at_max << " " << sugar_mass_at_max << std::endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<random>
#include<set>
#include<queue>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define dump(a) cout << a << endl; 

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

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = -10000000;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}

/**
* @fn
* 最小値を取ります.Vector<int>を渡すこと.
*/
long long int imin(vector<int> a) {
	int MIN = 1000000000;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
	}
	return MIN;
}

/**
* @fn
* 自然数について、桁数を求める
*/
Int getDigit(Int num) {
	return (Int)(log10(num)) + 1;
}


int get2Digit(Int num) {
	int cnt = 0;
	while (num > 0) {
		if (num % 2 != 0) {
			return cnt;
		}
		cnt++;
		num /= 2;
	}
}

long long int absmin(vector<int> a, long long int b) {
	int mini = 100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b)) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}


long long int absmax(vector<int> a, long long int b) {
	int max = -100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (max < abs(a.at(i) - b)) {
			max = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}

int gcd(int a, int b)
{
	if (a < b) swap(a, b);
	if (b < 1) return -1;
	if (a % b == 0) return b;
	return gcd(b, a % b);
}

void haerobatya(int start, int end, char level) {
	if (start > end) swap(start, end);
	for (int i = start; i <= end; i++) {
		if (i < 100) {
			cout << "https://atcoder.jp/contests/abc0" << i << "/tasks/abc0" << i << "_" << level << endl;
		}
		else {
			cout << "https://atcoder.jp/contests/abc" << i << "/tasks/abc" << i << "_" << level << endl;
		}
	}
}

long long int cntmod(long long int warareru, long long int mod) {
	long long int i = 0;
	for (i = 0; true; i++) {
		if (warareru % mod == 0 && warareru >= mod) {
			warareru /= mod;
		}
		else {
			return i;
		}
	}
}

void ansYes(bool a) {
	if (a == true) cout << "Yes" << endl;
	else cout << "No" << endl;
}

void ansYES(bool a) {
	if (a == true) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Int euclidean_gcd(Int a, Int b) {
	while (true) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

typedef pair<int, int> pai;


//ここまでライブラリ
//ここから本文
int main() {
	int x, t;
	cin >> x >> t;
	dump(max(0,x-t))
}

Measured memory_bytes: 256