akhauriyash/Code-Regression huggingface dataset:
a,b,c,x = [int(input()) for i in [0]*4]
p_A = [p*500 for p in range(1,a+1)]
p_B = [q*100 for q in range(1,b+1)]
p_C = [r*50 for r in range(1,c+1)]

list_AB = sum([sum([1 for j in p_B if i+j == x]) for i in p_A])
list_BC = sum([sum([1 for j in p_C if i+j == x]) for i in p_B])
list_CA = sum([sum([1 for j in p_A if i+j == x]) for i in p_C])
list_ABC = sum([sum([sum([1 for k in p_C if i+j+k == x]) for j in p_B]) for i in p_A])
a_1 = sum([[0,1][x in i] for i in (p_A,p_B,p_C)])

print(a_1 + list_AB + list_BC + list_CA + list_ABC)

Measured memory_bytes: 3064
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

public static class P
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var a = Enumerable.Repeat(0, n).Select(_ => Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray()).ToArray();
        int[] nextOpponent = new int[n + 1];
        for (int i = 0; i < n; i++)
            nextOpponent[i] = a[i][0];
        nextOpponent[n] = n;
        int[] index = new int[n];
        List<int> nextDayMatch = nextOpponent.Take(n).Where((x, y) => /*next[y] == x &&*/nextOpponent[x] == y).ToList();
        int remainCount = n;
        int turn = 0;
        while (remainCount > 0)
        {
            if (nextDayMatch.Count == 0)
            {
                Console.WriteLine(-1);
                return;
            }
            foreach (var next in nextDayMatch)
            {
                index[next]++;
                if (index[next] >= a[next].Length)
                {
                    nextOpponent[next] = n;
                    remainCount--;
                    continue;
                }
                nextOpponent[next] = a[next][index[next]];
            }
            List<int> newNextDay = new List<int>();
            foreach (var next in nextDayMatch)
            {
                //可能性がある人
                var op = nextOpponent[next];
                //両思いだったら
                if (next == nextOpponent[op])
                {
                    newNextDay.Add(next);
                    newNextDay.Add(op);
                }
            }
            nextDayMatch = newNextDay.Distinct().ToList();
            turn++;
        }
        Console.WriteLine(turn);
    }

    static readonly TextReader In = Console.In;
    static int NextInt
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        get
        {
            int res = 0;
            int next = In.Read();
            int rev = 1;
            while (45 > next || next > 57) next = In.Read();
            if (next == 45) { next = In.Read(); rev = -1; }
            while (48 <= next && next <= 57)
            {
                res = res * 10 + next - 48;
                next = In.Read();
            }
            return res * rev;
        }
    }
}


Measured memory_bytes: 45724
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
 
int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  rep(i, h) cin >> s.at(i);
  int ans = 0;
  rep(is, 1<<h)rep(js, 1<<w){
  
    int cnt = 0;
    rep(i, h)rep(j, w){
      if(is>>i&1) continue;
      if(js>>j&1) continue;
      if(s.at(i).at(j) == '#') cnt++; 
    }
    if(cnt == k) ans++;
  }
  cout << ans << endl;
  
  
  
  return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>

using namespace std;

int calc(vector<string> &grid, int rows, int cols) {
	int h = grid.size();
	int w = grid[0].size();

	int ret = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (rows >> i & 1) {
				continue;
			}
			if (cols >> j & 1) {
				continue;
			}
			if (grid[i][j] == '#') {
				ret++;
			}
		}
	}
	return ret;
}

int main() {
	int h, w, k;
	cin >> h >> w >> k;

	vector<string> grid(h);
	for (int i = 0; i < h; i++) {
		cin >> grid[i];
	}

	int ans = 0;
	for (int i = 0; i < (1 << h); i++) {
		for (int j = 0; j < (1 << w); j++) {
			int cnt = calc(grid, i, j);
			if (cnt == k) {
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3196
/*
* @Author Silviase(@silviasetitech)
* For ProCon
*/

import java.util.*;
import java.lang.*;
import java.math.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        String s = sc.next();
        String t = sc.next();
        boolean b = false;
        for (int i = 0; i < s.length(); i++) {
            if ((s.substring(i) + s.substring(0,i)).equals(t)){
                b = true;
            }
        }
        if (b) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

        sc.close();
    }

}

Measured memory_bytes: 23892
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;

// const long long INF = 10000000;
const long long INF = 1LL << 60;

long N;
long long h[100010];
long long dp[100010];

int main() {

  cin >> N;
  for (int i = 0; i < N; ++i) cin >> h[i];
  for (int i=0; i < N; ++i) dp[i] = INF;

  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);

  for (int i=2; i<N; ++i) {
    long a = dp[i-1] + abs(h[i] - h[i-1]);
    long b = dp[i-2] + abs(h[i] - h[i-2]);

    if (a < dp[i]) {
      dp[i] = a;
    }

    if (b < dp[i]) {
      dp[i] = b;
    }
  }

  cout << dp[N-1] << endl;
  return 0;
}


Measured memory_bytes: 1792
from sys import stdin
s=stdin.readline().rstrip()
K=int(stdin.readline().rstrip())
subs=[]
for i in range(K):
  for j in range(0, len(s)-i):
    subs.append(s[j:j+i+1])
subs=list(set(subs))
subs.sort()
print(subs[K-1])

Measured memory_bytes: 5068
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define vll vector<ll>
#define vpll vector<pair<ll,ll> >
ll mx=INT_MAX;
ll mi=INT_MIN;

int main()
{
    ll n,i,j,s=0,p,q;
    ll a,b,c,d;cin>>a>>b>>c>>d;
    while(1)
    {
        if(s==0)
        {
            c=c-b;s=1;
        }
        else
        {
            a=a-d;s=0;
        }
        if(c<=0 || a<=0) break;
    }
    if(s==1)
    {
        cout<<"Yes";
    }
    else cout<<"No";
    
}

Measured memory_bytes: 3592
#include <stdio.h>
#include <math.h>

int main()
{
    
	int N;
	int m = scanf("%d",&N);
	if (m == EOF) {
		printf("scan error!\n");
		return 0;
	}

	int ten = 1;
	int ten_num = 1;
	int ten_max = 6;
	for (int i = 0; i < ten_max; i++) {
		if (N < ten) {
			ten_num--;
			break;
		}
		else if (i == (ten_max-1)) {
			break;
		}
		//printf("%d\n", ten);
		ten *= 10;
		ten_num++;
	}

	//printf("%d\n", ten_num);
	int sum = 0;

	if (ten_num % 2 == 1) {
		sum += N - pow(10, ten_num-1) + 1;
		ten_num--;
	}

	for (int t = ten_num; t > 0; t--) {
		if (t % 2 == 1) {
			sum += pow(10, t) - pow(10, t - 1);
		}
		//printf("%d\t%d\n", t, sum);
	}

	printf("%d\n", sum);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef  long long ll;

ll ans[100001]={0};

int func(int n){
  if(ans[n] != 0)
    return ans[n];
  else if(n >= 6){
    int mini = func(n-1);
    for(int i = 6; i <= n; i*=6){
      mini=min(mini,func(n-i));
    }
    for(int i = 9; i <= n; i*=9){
      mini=min(mini,func(n-i));
    }
    ans[n] = mini+1;
    return mini+1;
  }
  else{
    ans[n] =  n;
    return n;
  }
}

int main(){
  int N;

  cin >> N;

  func(N);
  // for(int i = 1; i <= N; i++){
  //     ll mini = ans[i-1];
  //     for(ll j = 6; j <= i; j*=6){
  //       if(mini > ans[i-j])
  //         mini = ans[i-j];
  //     }
  //     for(ll j = 9; j<=i; j*=9){
  //       if(mini > ans[i-j])
  //         mini = ans[i-j];
  //     }
  //     ans[i] = mini + 1;
    
  // }
  cout << ans[N] << endl;
  
  return 0;
}




Measured memory_bytes: 4096
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


class SegTree:
    """
    init(init_val, ide_ele): 配列init_valで初期化 O(N)
    update(k, x): k番目の値をxに更新 O(N)
    query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
    """

    def __init__(self, init_val, segfunc, ide_ele):
        """
        init_val: 配列の初期値
        segfunc: 区間にしたい操作
        ide_ele: 単位元
        n: 要素数
        num: n以上の最小の2のべき乗
        tree: セグメント木(1-index)
        """
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        """
        k番目の値をxに更新
        k: index(0-index)
        x: update value
        """
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, left, right):
        """
        [left, right)のsegfuncしたものを得る
        left: index(0-index)
        right: index(0-index)
        """
        res = self.ide_ele
        left += self.num
        right += self.num
        while left < right:
            if left & 1:
                res = self.segfunc(res, self.tree[left])
                left += 1
            if right & 1:
                res = self.segfunc(res, self.tree[right - 1])
            left >>= 1
            right >>= 1
        return res


def resolve():
    n, m = map(int, input().split())
    LRC = sorted([list(map(int, input().split())) for _ in range(m)], key=lambda x: [x[0], x[1]])
    dist = [f_inf] * n
    dist[0] = 0
    seg = SegTree(dist, lambda x, y: min(x, y), f_inf)
    for l, r, c in LRC:
        l -= 1
        r -= 1
        mi = seg.query(l, r)
        if dist[r] > mi + c:
            seg.update(r, mi + c)
            dist[r] = mi + c
    res = dist[-1]
    print(res if res != f_inf else -1)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 41096
#include <iostream>
#include <numeric>

long long gcd(long long a, long long b)
{
    if(b==0) return a;
    else return gcd(b,a%b);
}

long long lcm(long long a, long long b)
{
  if(b == 0) return a;
  long long temp = gcd(a, b);

  return a / temp * b;
}


int main(int argc, char* argv[]){
  int N;  
  std::cin >> N;
  
  long long temp, answer=1LL;
  for(int i=0; i<N; i++){
    std::cin >> temp;
    answer = lcm(answer, temp);
    //std::cout << answer << std::endl;
  }

  std::cout << answer << std::endl;
  
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env ruby
# require 'pry'

# N
# a_1 b_1
# ...
# a_N b_N
# ↑を[[a_1,..a_N],[b_1,..b_N]]にする
# N = gets.to_i
# a, b = N.times.map{gets.split.map(&:to_i)}.transpose

n = gets.to_i
ary = [*(1..n)]
count = 0
ary.map do |e|
  count+=1 if e.to_s.length.odd?
end

puts count


Measured memory_bytes: 16888
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
long long dp[N][N];
int mod = 1000000007;
int n,m;
string s[N];

int32_t main(){
	ios::sync_with_stdio(false);
	cin.tie(0) , cout.tie(0);
	cin>>n>>m;
	for(int i = 0 ; i < n; i ++) cin>>s[i];
	dp[n-1][m-1] = 1;
	for(int i = n- 1 ; i >=0 ; i--){
		for(int j = m - 1; j >= 0 ; j--){
			if(s[i][j] == '.'){
				if((i+1) < n) dp[i][j] += dp[i+1][j] , dp[i][j] %= mod;
				if((j+1) < m) dp[i][j] += dp[i][j+1] , dp[i][j] %= mod;
			}
		}
	}
	printf("%lld\n" , dp[0][0]);
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define ll long long
#define pp push_back
#define fr first
#define sc second
#define mp make_pair
using namespace std;

int a[2222222];
int vis[2222222];
int v[2222222];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n; cin >> n;
    for(int i = 0;i < n;i++){
        cin >> v[i];
        vis[v[i]]++;
    }
    sort(v,v + n);
    int ans = 0;
    for(int i = 0;i < n;i++){
        if(a[v[i]]){
            continue;
        }
        if(vis[v[i]] < 2)ans++;
        for(int j = v[i];j <= 1e6;j+=v[i])
            a[j] = 1;
    }
    cout << ans << '\n';


    return 0;
}


Measured memory_bytes: 12084
#include <stdio.h>
#define N 500000
#define SENTINEL 2000000000

void merge(int *,int,int,int,int);
void mergeSort(int *,int,int,int);

int cnt;
int L[N/2+2],R[N/2+2];

int main()
{
  int n,A[N],i;
  cnt = 0;
  scanf("%d",&n);
  for(i=0;i<n;i++)
{
  scanf("%d",&A[i]);
}
mergeSort(A,n,0,n);
for(i=0;i<n;i++)
{
  printf("%d",A[i]);
  if(i!=n-1)
    printf(" ");
}
printf("\n");
printf("%d\n",cnt);
return 0;
}
void merge(int *A,int n,int left,int mid,int right)
{
  int i,j,k,n1, n2;
  n1 = mid - left ;
  n2 = right - mid;
  for(i=0;i<n1;i++)
    L[i] = A[left + i];
  for(i=0;i<n2;i++)
    R[i] = A[mid + i];
  L[n1] = SENTINEL;
  R[n2] = SENTINEL;
  i = 0;
  j = 0;
  for(k=left;k<right;k++)
    {
      cnt++;
      if(L[i] <= R[j])
        {
          A[k] = L[i++];
        }
      else
        {
          A[k] = R[j++];
        }
    }
}
void mergeSort(int *B,int n,int left,int right)
{
  int mid;
  if(left+1 < right)
  {
    mid = (left + right)/2;
     mergeSort(B,n,left,mid);
     mergeSort(B,n,mid,right);
    merge(B,n,left,mid,right);
  }
}



Measured memory_bytes: 5620
#include<bits/stdc++.h>
using namespace std;
int n;
long long m,a[105],b[105],dp[100005][105],ans=0;
bool ok=1;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>a[i]>>b[i];
	for(int i=1;i<=1e5;i++)for(int j=0;j<=n;j++)dp[i][j]=1e18;
	for(int i=1;i<=1e5;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(i-b[j]>=0)dp[i][j]=min(dp[i-b[j]][j-1]+a[j],dp[i][j-1]);
			else dp[i][j]=dp[i][j-1];
			if(dp[i][j]<=m)
			{
//				cout<<i<<' '<<j<<' '<<dp[i][j]<<endl;
				ans=i;
			}
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 85656
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;

#define INF (1ll<<60)


long long M = 1000000007;


int main(int argc, char const *argv[]) {
    long long n,a,b;cin>>n>>a>>b;
    if(a>b){
        cout<<0<<endl;
        return 0;
    }
    cout<< max(0ll,(b-a)*(n-2)+1)<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt(); //N種類のドーナツがある
    int X = sc.nextInt(); //Xgの粉を持っている
    int[] m = new int[N];
    int amount = 0;
    
    for(int i=0;i<N;i++){
      m[i] = sc.nextInt();
      amount += m[i];
    }
    
    int min = m[0];
    for(int j=1;j<N;j++){
      if(m[j]<min){
        min = m[j];
      }
    }
    
    int last = (X-amount)/min;
    System.out.println(N+last);
  }
}

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


const ll MOD = 1000000007;

//計算結果メモ用
//周期性を利用して、10のi乗*s[j]%13を予め求めておく
//右から文字を見ていくので、右からn桁までの数を13で割った余りを計算したい時は、
//n-1桁までの余りに10**n*(右からn桁目の数)%13を足せばよいことになる
//10**6 % 13 == 1なので、周期6で上手く行く
//後は各10のべき乗に0~9を書けて13で割った余りを計算していくとよい
int memo[6][10];

ll dp[100001][13]; //右からi桁目まで見て、13で割った余りがjになるような数の個数は何通りか
int main(){

    //memoの計算
    rep(i,10) memo[0][i] = i;
    rep(i,6) memo[i][0] = 0;
    rep(i,5){
        for(int j = 1; j < 10; j++){
            memo[i+1][j] = 10*memo[i][j]%13;
        }
    }
    
    //sの入力
    string s; cin >> s;
    int n = s.size(); //s.size()を何回も呼び出すのはダメ、先に記録しておく

    //dpの計算
    if(s[n-1] == '?') rep(j,10) dp[n-1][j] = 1;
    else dp[n-1][(s[n-1]-'0')] = 1;
    for(int i = n-2; i >= 0; i--){ //10の(n-1-i)乗*s[i]%13をmemoから求める
        if(s[i] == '?'){
            rep(j,10){ //?に何を入れるかで全探索する
                rep(k,13){ //各剰余について計算
                //推移は右からなのでiの部分は1減らして、剰余の状態については各kにmemoを足せばよい
                    dp[i][(memo[(n-1-i)%6][j]+k)%13] += dp[i+1][k]; 
                }
            }
        }else{
            rep(j,13){ //各剰余から次への推移を考える
                dp[i][(memo[(n-1-i)%6][(s[i]-'0')] + j) % 13] += dp[i+1][j];
            }
        }
        rep(j,13) dp[i][j] %= MOD; //MODを取っておく
    }
    
    //答えの出力
    cout << dp[0][5] % MOD << endl;
}

Measured memory_bytes: 10624
#include <bits/stdc++.h>
using namespace std;
int n,a[50],b[50],c[50],ans,x,A[30],t;
void dfs(int x){
	if (x==n+1){
		t=n;
		for (int i=1;i<=n;++i) c[i]=a[i];
		for (int i=0;i<13;++i) if (A[i]==2) c[++t]=-i,c[++t]=i;
		sort(c+1,c+t+1); x=24+c[1]-c[t];
		for (int i=1;i<t;++i) x=min(x,c[i+1]-c[i]);
		ans=max(x,ans); return;
	}
	a[x]=-b[x];
	dfs(x+1);
	a[x]=b[x];
	dfs(x+1);
}
int main(){
	scanf("%d",&n); A[0]=1;
	for (int i=1;i<=n;++i) scanf("%d",&x),++A[x];
	for (int i=0;i<13;++i)
	if (A[i]>2){puts("0"); return 0;}
	n=0;
	for (int i=0;i<13;++i) if (A[i]==1) b[++n]=i;
	dfs(1);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
Imports System

Module Program
    Sub Main(args As String())
        Dim tmpA As String() = Split(Console.ReadLine(), " ")

        Dim N As Long = CLng(tmpA(0))
        Dim K As Long = CLng(tmpA(1))

        Dim count As Long = 0
        Do While N > 0
            N = N \ K
            count = count + 1
        Loop

        Console.WriteLine(count)
    End Sub
End Module


Measured memory_bytes: 13536
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007

void solve()
{
	ll n;
	cin>>n;
	vector<ll> a(n),cnt(1e6,0);
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
		cnt[a[i]]++;
	}
	ll ans=0;
	for(int i=1;i<1e6;i++)
	{
		ans=max(ans,cnt[i-1]+cnt[i]+cnt[i+1]);
	}
	cout<<ans;
	return;
}
int main()
{
	fast;
	int q;
	q=1;
	// cin>>q;
	while(q--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 11928
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;
using TextReader = System.IO.TextReader;
using System.Text;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var n = consoleReader.Int;
            return n < 3200 ? "red" : consoleReader.String;
        }

        #region いつもの
        private readonly ConsoleReader consoleReader;
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program(new ConsoleReader(Console.In)).Calc()); static string AllLines<T>(IEnumerable<T> source) => string.Join("\n", source);
        #endregion
    }

#pragma warning disable
    public class ConsoleReader
    {
        private string[] line = Array.Empty<string>();
        private int linePosition;
        private TextReader textReader;
        public ConsoleReader(TextReader tr) { textReader = tr; }
        public int Int => int.Parse(String);
        public long Long => long.Parse(String);
        public double Double => double.Parse(String);
        public string String
        {
            get
            {
                if (linePosition >= line.Length)
                {
                    linePosition = 0;
                    line = textReader.ReadLine().Split();
                }
                return line[linePosition++];
            }
        }
        public class SplitLine
        {
            private string[] splited;
            public SplitLine(ConsoleReader cr) { splited = cr.textReader.ReadLine().Split(); }
            public int[] Int => String.Select(x => int.Parse(x)).ToArray();
            public long[] Long => String.Select(x => long.Parse(x)).ToArray();
            public double[] Double => String.Select(x => double.Parse(x)).ToArray();
            public string[] String => splited;
        }
        public SplitLine Split => new SplitLine(this);
        public class RepeatReader
        {
            ConsoleReader cr; int count;
            public RepeatReader(ConsoleReader cr, int count) { this.cr = cr; this.count = count; }
            public IEnumerable<T> Select<T>(Func<ConsoleReader, T> func) { for (int i = 0; i < count; i++) yield return func(cr); }
            public IEnumerable<string> String { get { for (int i = 0; i < count; i++) yield return cr.String; } }
            public IEnumerable<int> Int { get { for (int i = 0; i < count; i++) yield return cr.Int; } }
            public IEnumerable<double> Double { get { for (int i = 0; i < count; i++) yield return cr.Double; } }
        }
        public RepeatReader Repeat(int count) => new RepeatReader(this, count);
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;

int main() {
    string a,b,c;
    char flag='a';
    cin >> a >> b >> c;
    ll count=a.size()+b.size()+c.size();
    for (ll i=0;i<count;++i){
        if (flag=='a'){
            if (a.size()==0){
                cout << "A" << endl;
                return 0;
            }
            flag=a[0];
            a.erase(a.begin());
        }else if(flag=='b'){
            if (b.size()==0){
                cout << "B" << endl;
                return 0;
            }
            flag=b[0];
            b.erase(b.begin());
        }else{
            if (c.size()==0){
                cout << "C" << endl;
                return 0;
            }
            flag=c[0];
            c.erase(c.begin());
        }
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
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; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    ll w, h, x, y;
    cin >> w >> h >> x >> y;
    cout << w*h/2.0 << " " << ((w/2.0 == x && h/2.0 == y) ? 1 : 0) << endl;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7

N, K = MAP()
h = LIST()

dp = [INF]*(N)

dp[0] = 0

for i in range(1, min(K, len(h))):
	dp[i] = min([dp[j]+abs(h[i]-h[j]) for j in range(i)]) 

for i in range(K, N):
	dp[i] = min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1, K+1)])
	
#print(dp)
print(dp[N-1])

Measured memory_bytes: 76456
use std::io::Read;
use std::str::SplitWhitespace;
use std::str::FromStr;

pub fn read_stdin() -> String {
    let mut s = String::new();
    ::std::io::stdin().read_to_string(&mut s).unwrap();
    s
}

pub trait Parse<T> {
    fn parse(&mut self) -> T;
}

impl<'a, T> Parse<T> for SplitWhitespace<'a>
where
    T: FromStr,
{
    fn parse(&mut self) -> T {
        let word = self.next().unwrap();
        word.parse().ok().unwrap()
    }
}

fn main() {
    let source = read_stdin();
    let mut iter = source.split_whitespace();
    let h: usize = iter.parse();
    let w: usize = iter.parse();
    let m: Vec<Vec<char>> = (0..h)
        .map(|_| {
            let s: String = iter.parse();
            s.chars().collect()
        })
        .collect();

    let mut mm = vec![vec![0; w]; h];

    for (i, v) in m.iter().enumerate() {
        let mut start = None;
        let mut end = 0;
        for (j, &c) in v.iter().enumerate() {
            if c == '#' {
                if let Some(s) = start {
                    let len = end - s;
                    for k in s..end {
                        mm[i][k] = len;
                    }
                    start = None;
                }
            } else if start == None {
                start = Some(j);
                end = j + 1;
            } else {
                end += 1;
            }
        }
        if let Some(s) = start {
            let len = end - s;
            for k in s..end {
                mm[i][k] = len;
            }
        }
    }

    for i in 0..w {
        let mut start = None;
        let mut end = 0;
        for j in 0..h {
            if m[j][i] == '#' {
                if let Some(s) = start {
                    let len = end - s;
                    for k in s..end {
                        if mm[k][i] > 0 {
                            mm[k][i] -= 1;
                        }
                        mm[k][i] += len;
                    }
                    start = None;
                }
            } else if start == None {
                start = Some(j);
                end = j + 1;
            } else {
                end += 1;
            }
        }
        if let Some(s) = start {
            let len = end - s;
            for k in s..end {
                if mm[k][i] > 0 {
                    mm[k][i] -= 1;
                }
                mm[k][i] += len;
            }
        }
    }

    let max = mm.into_iter()
        .map(|v| v.into_iter().max().unwrap())
        .max()
        .unwrap();

    println!("{}", max);
}

Measured memory_bytes: 65784
//Author: kaiyu
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <numeric>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
#define sz(x) ((long long)(x).size())
#define all(x)  x.begin(),x.end()
#define endl "\n"
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define pii pair<int,int>
#define tt ll t;cin >> t;while(t--)
#define int3(x,y,z) ll x,y,z;cin >> x >> y >> z;
#define int2(x,y) ll x,y;cin >> x >>y;
#define int1(x) ll x;cin>>x;
#define  fio ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
ll power(ll a,ll b,ll m=mod){ ll ans=1; a=a%m;  while(b>0) {  if(b&1)  ans=(1ll*a*ans)%m; b>>=1;a=(1ll*a*a)%m;}return ans;}

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


bool cmp(pair<string,int>p1,pair<string,int>p2) {
    return p1.ss > p2.ss;
}

const int MAXN = 5 * 100000 + 10;

#define int long long

int32_t main() {
    fio
    int n,k;
    cin >> n >> k;
    map<int,int>pk;

    for (int i = 0; i < k; ++i) {
        int d;
        cin >> d;
        for (int j = 0; j < d; ++j) {
            int x;
            cin >> x;
            pk[x]++;
        }

    }
    cout << n-pk.size() <<endl;


}






Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
  public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

void solve(long long N, long long K, std::string S){
    for (int i = 0; i < N; i++)
    {
        if(i+1==K){
            cout << (char)tolower(S[i]);
        }else{
            cout << S[i];
        }
    }

    cout << endl;
    
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::string S;
    std::cin >> S;
    solve(N, K, S);
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<long long, long long>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

bool fn_is_prime(ll n) {
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return n != 1;
}

bool isOK(int index, int key, vector<ll>& a) {
    if (a[index] >= key) return true;
    else return false;
}

int binary_search(int key, vector<ll>& a) {
    int ng = -1;
    int ok = a.size();

    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key, a)) ok = mid;
        else ng = mid;
    }
    return ok;
}

struct UnionFind {
    vector<int> r;

    UnionFind(int N) {
        r = vector<int>(N, -1);
    }

    int root(int x) {
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }

    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }

    int size(int x) {
        return -r[root(x)];
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }
};

int main()
{
    int x; cin >> x;
    if (x< 1200)
        cout << "ABC" << endl;
    else
        cout << "ARC" << endl;
}


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

long long int a[150];
int n, m;

bool i_can(int wid, int m){
	int k = 1, sum = 0;
	for(int i = 0;i<=n;i++){
		sum += a[i];
		if (a[i] > wid) return false;
		if(sum > wid){
			sum = a[i];
			k++;
		}
		if (m < k) return false;
	}
	return true;
}

int nibun(int s, int e, int m){
	if(!(i_can((s+e)/2,m))){
		return nibun((s + e) / 2 + 1, e, m);
	}
	else if (s >= e) return s;
	else return nibun(s, (s + e) / 2, m);
}

int main(){
	while(cin >> m >> n){
		if (!n && !m) break;
		a[0] = 0;
		for(int i = 1;i<=n;i++){
			cin >> a[i];
		}
		cout << nibun(0, 1500001, m) << endl;
	}
	return 0;
}

Measured memory_bytes: 3024
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct edge{
    ll to, cost;
};


ll gcd(ll a,ll b){
    if(b == 0){
        return a;
    }else{
        return gcd(b, a%b);
    }
}

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll n, m;
    cin>>n>>m;
    vector<ll> a(n);
    for(ll i=0;i<n;++i){
        cin>>a[i];
    }
    sort(a.begin(), a.end());

    vector<pair<ll, ll>> p(m);
    for(ll i=0;i<m;++i){
        ll b, c;
        cin>>b>>c;
        p[i] = make_pair(c, b);
    }
    sort(p.begin(), p.end());
    reverse(p.begin(), p.end());

    ll count = 0;
    bool flag = false;
    vector<ll> q(n, 0);
    for(ll i=0;i<m;++i){
        if(flag){
            break;
        }
        for(ll j=0;j<p[i].second;++j){
            q[count] = p[i].first;
            count++;
            if(count == n){
                flag = true;
                break;
            }
        }
    }
    ll ans = 0;
    for(ll i=0;i<n;++i){
        ans += max(a[i], q[i]);
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 6372
#include<bits/stdc++.h>
using namespace std;
bool comp(const pair<string,int> &a, const pair<string,int> &b)
{
	if(a.second > b.second)
		return true;
	else if(a.second == b.second)
	{
		return a.first < b.first;
	}
	return false;
}
int main()
{
	int n;
	cin >> n;
	map<string,int> m;
	for(int i = 0; i < n; i++)
	{
		string s;
		cin >> s;
		m[s]++;
	}
	int dist = m.size();
	pair<string, int> p[dist]; 
	int i = 0;
	map<string,int> :: iterator it;
    for (it = m.begin(); it != m.end(); ++it) 
        p[i++] = make_pair(it->first, it->second); 
    sort(p, p + dist, comp); 
	int max = p[0].second;
	cout << p[0].first << "\n";
	int j = 1;
	while (p[j].second == max)
	{
		cout << p[j].first << "\n";
		j++;
	}
	
	return 0;
}

Measured memory_bytes: 28288
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <numeric>
#include <complex>

using namespace std;

typedef long long ll;

#define mp make_pair
#define pb push_back
#define PI 3.1415926535897932384626433832795

#define fill(x, v)  fillchar(x, v, sizeof(x))
typedef pair<int, int>  pii;
typedef vector<int>     vi;
typedef vector< pii >   vpii;

#define MAXN 110
#define MAXK 100500
#define MOD (int)(1e9 + 7)

int f[MAXN][MAXK];
int s[MAXK];
int a[MAXN];
int n, k;

int main() {
    scanf("%i%i", &n, &k);

    f[0][0] = 1;
    for(int i = 0; i <= k; ++i) s[i] = 1;

    for(int i = 1; i <= n; ++i) {
        scanf("%i", &a[i]);

        for(int j = 0; j <= k; ++j) {
            int z =  j - a[i] - 1;
            //printf("z=%i\n", z);

            if (z < 0) z = 0; else z = s[z];

            f[i][j] = (s[j] - z + MOD) % MOD;
            //printf("f(%i, %i) = %i\n", i, j, f[i][j]);
        }
        s[0] = f[i][0];
        for(int j = 1; j <= k; ++j) s[j] = (s[j - 1] + f[i][j]) % MOD;
    }

    printf("%i\n", f[n][k]);

    return 0;
}

Measured memory_bytes: 40832
#include<stdio.h>
int main(void)
{
  int a,b;
  int max=0,min=0;
  int c = 0;
  
  scanf("%d",&a);
  scanf("%d",&b);
  
  if(a<b){
    max = b;
    min = a;
  }
  else{
    max = a;
    min = b;
  }
  
  c = max - 1;
  
 if(c<min)
   printf("%d",min+max);
  else
   printf("%d",c+max);
      
  return 0;


}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class T> inline int sod_L(T n){
  int res=0;
  while(n){
    res += n%10;
    n /= 10;
  }
  return res;
}
int main(){
  int A, B, N, i, j, res=0;
  rd(N);
  rd(A);
  rd(B);
  for(i=1;i<N+1;i++){
    j =sod_L(i);
    if(A <= j  &&  j <= B){
      res += i;
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190608-2

// --- original code ---
// {
//   int N, A, B;
//   int i, j, res = 0;
// 
//   rd(N,A,B);
//   rep(i,1,N+1){
//     j = sod(i);
//     if(A <= j <= B) res += i;
//   }
//   wt(res);
// }


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

int main(void)
{
    int N;
    cin >> N;
    int a[N];
    for( int i = 0; i < N; i++){
        cin >> a[i];
    }
    deque<int> A;
    for( int i = 0; i < N; i++){
        if( (i+N-1) % 2 == 0){
            A.push_front(a[i]);
        }else {
            A.push_back(a[i]);
        }
    }
    for( int i = 0; i < N; i++){
        cout << A[i] << " ";
    }
    return 0;
}

Measured memory_bytes: 3840
#include<iostream>

using namespace std;

int main()
{
	int N,a,b,t=0;
	cin>>N>>a>>b;
	for(int i=1;i<=N;i++)
	{
		int z=i;
		int s=0; 
		while(z)
		{
			s=s+z%10;
			z/=10;
		}
//		cout<<s<<endl;
		if(s>=a&&s<=b){
			 t=t+i;
			 //cout<<i<<endl;
		}
	}
	cout<<t<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define iterator IT
#define SIZ(V) V.size()
#define FS(a) fixed<<setprecision(a)
using namespace std;
namespace STARTER {
	int MAX(int a,int b) {
		return a>b?a:b;
	}
	int MIN(int a,int b) {
		return a<b?a:b;
	}
	int ABS(int a) {
		return a<0?-a:a;
	}
	int GCD(int a,int b) {
		return !b?a:GCD(b,a%b);
	}
	int LCM(int a,int b) {
		return a/GCD(a,b)*b;
	}
	int QSM(int a,int b,int p) {
		int ret=1;
		while (b) {
			if (b&1)
				ret=ret*a%p;
			a=a*a%p;
			b>>=1;
		}
		return ret;
	}
	int ROUND(double a) {
		return a+0.5;
	}
}
using STARTER::MAX;
using STARTER::MIN;
using STARTER::ABS;
using STARTER::GCD;
using STARTER::LCM;
using STARTER::QSM;
using STARTER::ROUND;
int main() {
	int n;
	cin>>n;
	if (n&1)
		cout<<n/2+1<<'\n';
	else
		cout<<n/2<<'\n';
	return 0;
}

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

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
const int maxn = 1e5 + 10;
int n , T , E;
int a[maxn];
ll dp[maxn];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP" , "r"))
        freopen(taskname".INP","r",stdin),
        freopen(taskname".OUT","w",stdout);
    cin >> n >> E >> T;
    for(int i = 1 ; i <= n ; ++i)cin >> a[i];
    int j = 0;ll pref = 1e18;
    for(int i = 1 ; i <= n ; ++i){
        dp[i] = 1e18;
        while(j < i && 2 * (a[i] - a[j + 1]) > T){
            pref = min(pref,dp[j]-2*a[j + 1]);
            ++j;
        }
        dp[i] = min(pref+2*a[i],dp[j]+T);
//        cout << dp[i] << " ";
    }
    cout << dp[n] + E;
}


Measured memory_bytes: 1408
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <cstring>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

int main(void)
{
    int n;
    cin >> n;
    vi a(n+1);
    vi b(n+1);
    
    
    for (int i= 2; i <= n; i++) {
        cin >> a[i];
        b[a[i]] ++;
    }
    
    
    
    
    for (int i= 1; i <= n; i++) cout << b[i] << endl;
    
}

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

int main()
{
	string s;
	cin >>s;
	if(s.size() == 1){
		cout <<(s[0] - '0') <<"\n";
	}
	else{
		int cnt = 0, sum = 0;
		for(int i = 1; i < s.size(); ++i){
			if(s[i] == '9')
				++cnt;
		}
		if(cnt == s.size() - 1){
			sum = s[0] - '0' + cnt * 9;
		}
		else{
			sum = s[0] - '0' - 1 + (s.size() - 1) * 9;
		}
		cout <<sum <<"\n";
	}
	return 0;
}


Measured memory_bytes: 3600
from sys import exit
from math import gcd

def segfunc(x, y):
    '''
    問題に応じて返り値を設定
    '''
    return gcd(x, y)


def init(a):
    '''
    配列aで初期化
    '''
    for i in range(n):
        seg[i+num-1] = a[i]    
    for i in range(num-2, -1, -1) :
        seg[i] = segfunc(seg[2*i+1], seg[2*i+2])


def query(p, q):
    '''
    [p, q)についてsegfuncを適用したものを返す
    '''
    if q <= p:
        return ide_ele
    
    p += num - 1
    q += num - 2
    res = ide_ele

    while q - p > 1:
        if p & 1 == 0:
            res = segfunc(res, seg[p])
        if q & 1 == 1:
            res = segfunc(res, seg[q])
            q -= 1
        p = p // 2
        q = (q - 1) // 2
    
    if p == q:
        res = segfunc(res, seg[p])
    else:
        res = segfunc(res, segfunc(seg[p], seg[q]))
    
    return res


n, k = map(int, input().split())
a = list(map(int, input().split()))

if k > max(a):
    print('IMPOSSIBLE')
    exit()

num = (2 ** len(bin(n - 1)) - 2)
ide_ele = 0
seg = [ide_ele] * 2 * num

init(a)

if k % query(0, n) == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 24712
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define watch(x) cout<<"->"<<#x<<" : "<<x<<endl;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c)) 
typedef long long ll;
typedef unsigned long long llu;
const double PI = 2*acos(0.0);
bool comp(const pair<int,int> &a, const pair<int,int> &b)
{
	if(a.first==b.first)
		return a.second>b.second;
	return a.first<b.first;
}
signed main()
{
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n,m;
	cin>>n>>m;
	vector<pair<int,int>>a(m);
	for(int i=0;i<m;i++)cin>>a[i].first>>a[i].second;
	sort(a.begin(),a.end(),comp);
	int l = a[0].first;
	int r = a[0].second;
	for(int i=1;i<m;i++)
	{
		if(a[i].first>l)l=a[i].first;
		if(a[i].second<r)r=a[i].second;
	}	
	if(r<l)cout<<"0"<<endl;
	else cout<<r-l+1<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<float> money(n);
	vector<string> value(n);	
	float ans = 0;

	for (int i = 0;i < n;i++)
	{
		cin >> money[i] >> value[i];
	}

	for (int i = 0;i < n;i++)
	{
		if (value[i] == "JPY")
		{
			ans += money[i];
		}
		else
		{
			ans += (380000.0 * money[i]);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import os

def main():
    count = int(input())
    NumList = list(map(int, input().split()))
    ansList = []
    ansCount = 0

    for num in NumList:
        if num % 2 == 0:
            ansList.append(num)
            if ((num % 3 == 0) or (num % 5 == 0)):
                ansCount += 1
            else:
                pass
        else:
            pass

    if len(ansList) != ansCount:
        print("DENIED")
    else:
        print("APPROVED")

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
# include <cstdio>
# include <iostream>
using namespace std;
int num[4];

int fun( int x )
{
	int cnt = 0;
	while (x) {
		num[cnt] = x%10;
		cnt++;
		x/=10;
	}
	//for ( int i = 0;i < 4;i++ ) cout<<num[i]<<endl;
	int res = 1;
	for ( int i = 0;i < 4-1;i++ ) {
		if (num[i]==num[i+1]) {
			res++;
			if ( res >= 3) 
				return 1;
		}
		else {
			res = 1;
		}
	}
	return 0;

}

int main(void)
{
	int n; scanf("%d",&n);
	int flag = fun(n);
	if ( flag ){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}


	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	vector<bool> a(300000, true);
	a[0] = a[1] = false;
	for (int i = 2; i < 300000; i++)
		if (a[i])
			for (int j = i * 2; j < 300000; j += i)
				a[j] = false;
	vector<int> sum(300001);
	for (int i = 1; i < 300000; i++)
		sum[i] = sum[i - 1] + a[i];
	for (;;) {
		int n; cin >> n;
		if (n == 0) break;
		cout << sum[n * 2] - sum[n] << endl;
	}
}

Measured memory_bytes: 2328