akhauriyash/Code-Regression huggingface dataset:
from itertools import permutations
n, m = map(int, input().split())
list_AB = [ list(map(int,input().split(" "))) for i in range(m)]
list_MAP = [[0]*n for _ in range(n)]
list_N = [i for i in range(2, n+1)]

for a, b in list_AB:
    list_MAP[a-1][b-1] = 1
    list_MAP[b-1][a-1] = 1

ans = 0

for l in permutations(list_N, n-1):
    cnt = 0
    p = 1
    q = 0
    for num in l:
        q = num
        cnt += list_MAP[p-1][q-1]
        p = num

    if cnt == n-1:
        ans += 1

print(ans)

Measured memory_bytes: 3188
# -*- coding:utf-8 -*-
import sys

DBG_FLAG = 0

def p_dbg(str):
    if(DBG_FLAG == 1):
        sys.stdout.flush()
        print str

S=raw_input()
# 回文でない文字列を作るには
# -> 文字列を一旦ソートする。
# -> 特定の文字を一つ選択し、先頭に置く
# -> 選択した文字とは別の文字を選択し、次に配置する。
#    このとき、i-2番目の文字と一致しないこと。

# 回文ではない
# -> 1.同じ文字が2文字以上連続しない
#    2.異なる2文字の部分文字列があるとき、直後に
#      逆順の文字列が存在しない

array = list(S)
p_dbg(array)

a_ary = [char for char in array if char == "a"]
b_ary = [char for char in array if char == "b"]
c_ary = [char for char in array if char == "c"]

a_len = len(a_ary)
b_len = len(b_ary)
c_len = len(c_ary)

if ((a_len + b_len + c_len) > 2) and ((a_len == 0) or (b_len == 0) or (c_len == 0)):
    print "NO"
else:
    result = "YES"
    tmp_array = []
    while (a_len + b_len + c_len) > 2:
        p_dbg("len:"+str(a_len)+":"+str(b_len)+":"+str(c_len)+":"+str(a_len + b_len + c_len))
        if (a_len == 0) or (b_len == 0) or (c_len == 0):
            result = "NO"
            break
        else:
            a_len = a_len -1
            b_len = b_len -1
            c_len = c_len -1

    p_dbg("len:"+str(a_len)+":"+str(b_len)+":"+str(c_len)+":"+str(a_len + b_len + c_len))
    if ((a_len == 2) or (b_len == 2) or (c_len == 2)):
        result = "NO"
    if (a_len + b_len + c_len) == 1:
        result = "YES"

    if result == "NO":
        print "NO"
    else:
        print "YES"


Measured memory_bytes: 4544
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
using ld=long double;
using VI=vector<ll>;
using VD=vector<ld>;
using VVI=vector<VI>;
using VC=vector<char>;
using VVC=vector<VC>;
using VS=vector<string>;
using PLL =pair<ll,ll>;
using PLD=pair<ld,ld>;
using VPLL=vector<PLL>;
#define print(x) std::cout<<x<<"\n"
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repd(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SZ(x) ((ll)(x).size())
#define MAX(x) *max_element((x).begin(),(x).end())
#define MIN(x) *min_element((x).begin(),(x).end())
#define SORTR(x) sort((x).rbegin(),(x).rend())
#define SORT(x) sort((x).begin(),(x).end())
#define SUM(x) accumulate((x).begin(),(x).end(), 0)
#define FILL(x,a) fill(x.begin(),x.end(),a)
#define EACH(i,x) for(typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

const ll INF = 1e18;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;
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; }
template <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first, BidirectionalIterator middle,BidirectionalIterator last){reverse(middle, last); return next_permutation(first , last);}
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll GCD(VI v){ll a = v[0]; for (ll i = 1; i<SZ(v); i++) {a = gcd(a, v[i]);} return a;}
ll LCM(VI v){ll a = v[0]; for (ll i = 1; i<SZ(v); i++) {a = lcm(a, v[i]);} return a;}
VI Bit2Vector(const ll bit, ll n) {	VI s;	rep(i,n) if (bit & (1 << i)) s.push_back(i); return s;}


void Main()
{
	ll n,m,l; ll res=0;
	ll w=1;
	cin>>n;
	VI dp(n+2,INF);
	VI h(n);
	rep(i, n) cin >> h[i];
	//初期条件はじめはコスト0
	dp[0]=0;
	rep(i,n){
		//１個先のすでに計算したコストと新しく計算する1個先のコスト比較
		ll cost1=abs(h[i+1]-h[i]);
		dp[i+1]=min(dp[i+1],dp[i]+cost1);
		//2個先のすでに計算したコストと新しく計算する2個先のコスト比較
		ll cost2=abs(h[i+2]-h[i]);
		dp[i+2]=min(dp[i+2],dp[i]+cost2);
	}
	res=dp[n-1];
	cout << res << "\n";
	return;
}

int main()
{
	std::cin.tie(0);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

using ll = long long;

int main(){
	vector<int> vals(11);
	int r;
	int a;
	int D;

	cin >> r;
	cin >> D;
	cin >> a;

	vals.at(0) = a;
	// read inputs
	for (size_t i = 1; i < 11; ++i) {
		vals.at(i) = r * vals.at(i-1) - D;
	}
	
	for (size_t i = 1; i < vals.size(); ++i) {
		cout << vals.at(i) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
i=0
j=0
p=0
while(i<len(a)):
  j=i+1
  s=0
  while(j<len(a)):
      s=s+a[j]
      j=j+1
  
  p=p+s*a[i]
  i=i+1
print(p)


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

int main() {
  int N;
  double x;
  double ans = 0;
  string u;
  cin >> N;
  for (int i=0; i<N; i++) {
    cin >> x >> u;
    if (u == "JPY") {
      ans += x;
    } else {
      ans += x * 380000;
    }
  }
  cout << ans << "\n";
}


Measured memory_bytes: 256
X, Y, A, B, C = gets.split.map &:to_i
P = gets.split.map(&:to_i).sort.reverse
Q = gets.split.map(&:to_i).sort.reverse
R = gets.split.map(&:to_i).sort.reverse

ans = 0
x = X
y = Y
r = 0
while x + y - r > 0
    candidate = Hash.new
    candidate[:P] = P[0] if x > 0 && !P.empty?
    candidate[:Q] = Q[0] if y > 0 && !Q.empty?
    candidate[:R] = R[0] if !R.empty?
    selected, _ = candidate.max{|a, b| a[1] <=> b[1]} # max_by_value
    case selected
    when :P
        ans += P.shift
        x -= 1
    when :Q
        ans += Q.shift
        y -= 1
    when :R
        ans += R.shift
        r += 1
    end
end

p ans

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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> x(m + 1);
    for (int i = 0; i < n; i++)
    {
        int k;
        cin >> k;
        vector<int> a(k);
        for (int j = 0; j < k; j++)
        {
            cin >> a.at(j);
            x.at(a.at(j))++;
        }
    }
    int count = 0;
    for (int i = 0; i < m + 1; i++)
    {
        if (x.at(i) == n)
        {
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

void chmax(int &a, int b) { a = max(a, b); }

int INF = 1e+15;
int n;
int a[100000][3];
int dp[100001][3];

signed main() {
	int i, j, k;
	
	cin >> n;
	rep(i, n) {
		cin >> a[i][0] >> a[i][1] >> a[i][2];
	}
	
	rep(i, n + 1) rep(j, 3) dp[i][j] = -INF;
	dp[0][0] = 0;
	
	rep(i, n) {
		rep(j, 3) {
			rep(k, 3) {
				if (i > 0 && j == k) continue;
				chmax(dp[i + 1][k], dp[i][j] + a[i][k]);
			}
		}
	}
	
	int ans = 0;
	rep(i, 3) chmax(ans, dp[n][i]);
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 4992
# coding: utf-8
import re
import math
from copy import deepcopy
import fractions
import random
from heapq import heappop,heappush
import time
import sys
readline = sys.stdin.readline
#import numpy as np
mod=int(10**9+7)
inf=int(10**20)
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def fac_list(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="number"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
#main
def keta(n):
    n=str(n)
    for a in range(6-len(n)):
        n="0"+n
    return n
n,m=map(int,input().split())
P=[[] for a in range(n)]
for a in range(m):
    p,y=map(int,input().split())
    p-=1
    city=a
    P[p].append({"y":y,"city":city})
C=[]
for a in range(n):
    P[a].sort(key=lambda x:x["y"])
    for b in range(len(P[a])):
        C.append([keta(a+1)+keta(b+1),P[a][b]["city"]])
C.sort(key=lambda x:x[1])
for a in C:
    print(a[0])







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

using namespace std;

const int N = 100005;

int n;
int x[N], X;

int main() {
    
    scanf("%d %d", &n, &X);
    
    for (int i = 1; i <= n; i++) {
        scanf("%d", &x[i]);
    }
    
    sort(x + 1, x + 1 + n);
    int gcd = -1;
    for (int i = 2; i <= n; i++) {
        int diff = x[i] - x[i - 1];
        if (gcd == -1) {
            gcd = diff;
        } else {
            gcd = __gcd(gcd, diff);
        }
    }
    
    for (int i = 1; i <= n; i++) {
        if (x[i] != X) {
            if (gcd == -1) {
                gcd = abs(X - x[i]);
            } else {
                gcd = __gcd(gcd, abs(X - x[i]));
            }
        }
    }
    
    printf("%d\n", gcd);
    
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
using std::cin;
using std::cout;
using std::endl;

int main(){
  int N;
  cin >> N;
  for(int i = 0;i < N;i++){
    char S;
    cin >> S;
    
    if(S == 'Y'){
      cout << "Four" << endl;
      break;
    }
    if(i == N -1){
      cout << "Three" << endl;
    }
  }
}

Measured memory_bytes: 256
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;
ll sign(ll A){
    return (A>0)-(A<0);
}
int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    if (N == 1) {
        print(1);
        return 0;
    }
    ll cnt = 0;
    ll inc = sign(A[1] - A[0]);
    rep(i, N-1) {
        if(inc == 0) {
            inc = sign(A[i+1] - A[i]);
            continue;
        }
        if (A[i+1] > A[i] && inc == -1) {
            cnt++;
            inc = 0;
        } else if (A[i+1] < A[i] && inc == 1) {
            cnt++;
            inc = 0;
        }
    }
    print(cnt+1);
    return 0;
}

Measured memory_bytes: 1024
# coding: utf-8
# Your code here!

import sys

def input():
    return sys.stdin.readline().rstrip()

N, M = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(N)]
a.sort()
price = [a[i][0] for i in range(N)]
stock = [a[i][1] for i in range(N)]
bought = 0
total_price = 0

for i in range(N):
    if bought + stock[i] <= M:
        total_price += price[i] * stock[i]
        bought += stock[i]
    else:
        total_price += price[i] * (M - bought)
        break
print(total_price)

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


int main(){
    
    while(true){
        int n;
        cin>>n;
        if(n==0) return 0;
        int now=0;
        int cnt=0;
        int r=0,l=0;
        while(n--){
            string s;
            cin>>s;
            if(s=="ru") r=1;
            if(s=="rd") r=0;
            if(s=="lu") l=1;
            if(s=="ld") l=0;

            if(now==0 && r==1 && l==1){
                cnt++;
                now=1;
            }else if(now==1 && r==0 && l==0){
                cnt++;
                now=0;
            }
        }
        cout<<cnt<<endl;
    }
}


Measured memory_bytes: 3108
#include<stdio.h>
main()
{
    int a,b,x,i;
    scanf("%d %d",&a,&b);
    if(a>b)
    {
        x=a;a=b;b=x;

    }
    for(i=0;i<b;i++)
    {
        printf("%d",a);
    }
}


Measured memory_bytes: 1700
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<algorithm>
#include<functional>
#include<deque>
#include<string.h>
#include<ctype.h>
using namespace std;


int diff(int x, int y){
  int ans;
  if (x > y){
    ans = x - y;
  } else {
    ans = y - x;
  }
  return ans;
}

int a, b, c, d;

int main(){
  bool f = false;
  cin >> a >> b >> c >> d;
  if (diff(a, c) <= d){
    f = true;
  }
  if (diff(a, b) <= d && diff(b, c) <= d){
    f = true;
  }

  if (f == true) cout << "Yes" << endl;
  if (f == false) cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

//最大公約数と最小公倍数
ll gcd(ll a, ll b) {return(b?gcd(b,a%b):a);}
ll lcm(ll a, ll b) {return(a/gcd(a,b)*b);}

int main() {
    int n, m; cin >> n >> m;
    string s, t; cin >> s >> t;
    ll g = lcm(n,m);
    ll h = lcm(g/n,g/m);
    for (ll i = 0; i <= (n-1)*(g/n); i += h) {
        if (i <= (m-1)*(g/m)) {
            if (s[i/(g/n)] != t[i/(g/m)]) {
                cout << -1 << endl; 
                return 0;
            }
        } else break;
    }
    cout << g << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<bitset>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
ll fact(ll x, ll k, ll p) {//最大値、個数、あまり
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
short ctos(char a) {
	return (int)(a - '0');
}
#define int long long
const long long Inf = 4523372036854775807;
const int inf = 15000000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
int a[100000];
signed main() {
	int n, k;
	cin >> n >> k;
	int t = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] == 1) t = i;
	}
	cout << ceil((n - k)*1.0 / (k - 1)) + 1 << endl;
}

Measured memory_bytes: 1024
{-# LANGUAGE BangPatterns #-}

module Main where

import Data.Char
import Data.List
import Control.Monad
import Control.Applicative
import Text.Printf


readInt :: IO Int
readInt = read <$> (input `seq` input)
    where input = do
            !c <- getChar
            if isDigit c || c == '-'
                then (c :) <$> input
                else return []

prints :: Show a => [a] -> IO ()
prints as = putStrLn $ concat $ intersperse " " $ map show as

main = do
    [h, w] <- replicateM 2 readInt
    if h == 0 && w == 0
        then return ()
        else replicateM h (putStrLn $ replicate w '#') >> putStrLn "" >> main


Measured memory_bytes: 4108
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;

int main() {
    int x, y, z, K; cin >> x >> y >> z >> K;
    vector<ll> a(x), b(y), c(z), vec;
    rep(i, x) cin >> a[i];
    rep(i, y) cin >> b[i];
    rep(i, z) cin >> c[i];
    sort(RALL(a)); sort(RALL(b)); sort(RALL(c));
    rep(i, x) {
        rep(j, y) {
            rep(k, z) {
                if ((i+1) * (j+1) * (k+1) <= K) {
                    vec.push_back(a[i]+b[j]+c[k]);
                }
                else break;
            }
        }
    }
    sort(RALL(vec));
    rep(i, K) {
        cout << vec[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 1404
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>

using namespace std;

int main() {
	int N;
	cin >> N;
	int candy = 0;
	for (int i = 1; i <= N; i++) candy += i;
	cout << candy << endl;
	return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,i,e,f,g,n,m,k,l;
string s,s1,s2,s3;
int main() {
           cin>>s>>s1>>a>>b>>s3;
           if(s3==s) a--;
           if(s3==s1) b--;
           cout<<a<<" "<<b;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  int n;
  cin >> n;
  bool ans = true;
  rep(i, n) {
    int a;
    cin >> a;
    if (a % 2 == 0) {
      if(!(a % 3 == 0 || a % 5 == 0)) ans = false;
    }
  }
  if(ans) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
int x,p=0,s=0;
    cin>>x;
    if(x%500==0)
        cout<<2*x;
    else{
    while(x>500)
    {
     x-=500;
     p++;
    }
        while(x>5)
        {
         x-=5;
         s++;
        }
        cout<<p*1000+s*5<<endl;
    }
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P pair<int,int>
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; }

signed main(){
  int n,k;
  cin >> n >> k;
  vint A(n);
  rep(i,0,n) cin >> A[i];
  vint keta(60);
  rep(i,0,60){
    rep(j,0,n){
      if(A[j]>>i&1) keta[i]++;
    }
  }
  int ans = 0;
  rrep(i,60,-1){
    if(i != -1 && !((k>>i)&1)) continue;
    int tmp = 0;
    rrep(j,60,0){
      int mask = 1LL<<j;
      if(j > i){
        if(k&mask) tmp += mask*(n-keta[j]);
        else tmp += mask*keta[j];
      }
      else if(j == i){
        tmp += mask*keta[j];
      }
      else{
        tmp += mask*max(keta[j],n-keta[j]);
      }
    }
    ans = max(ans,tmp);
  }
  /* rep(i,0,n){
    int tmp = 0;
    tmp += A[i]^k;
    ans = max(ans,tmp);
  } */
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll n;
	cin>>n;
	vector<int>v(n);
	for(int i=1;i<n;i++){
		int a;
		cin>>a;
		v[a-1]++;
	}
	for(auto& p:v){
		cout<<p<<endl;
	}
	return 0;
}

Measured memory_bytes: 4028
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, H, W;
  cin >> N >> H >> W;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    if (a >= H && b >= W) {
      ans++;
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <utility>
#define maxn 100005

using namespace std;
typedef long long ll;
const int LEN = 100000;

struct fastio{
  char s[LEN + 5]; int len,it;
  fastio(){
    it = len = 0;
  }
  char get(){
    if(it < len) return s[it++];
    it = 0, len = fread(s,1,LEN,stdin);
    return len ? s[it++] : EOF;
  }
  bool notend(){
    char c;
    for(c = get();c == ' ' || c == '\n';c = get());
    if(it) it--;
    return c != EOF;
  }
  void put(char c){
    if(len == LEN) fwrite(s,1,LEN,stdout), len = 0;
    s[len++] = c;
  }
  void flush(){
    fwrite(s,1,len,stdout);
    len = 0;
  }
}buff,bufo;
inline int getint(){
  char c; int res = 0, sig = 1;
  for(c = buff.get();c < '0' || c > '9';c = buff.get()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = buff.get())
    res = (res << 3) + (res << 1) + (c - '0');
  return sig * res;
}
int n;
ll a[maxn],m[maxn];

int main(){
  n = getint();
  for(int i = 1;i <= n;i++) a[i] = getint() * 2;
  for(int i = 1;i <= n;i += 2) m[1] += a[i];
  for(int i = 2;i <= n;i += 2) m[1] -= a[i];
  m[1] /= 2;
  for(int i = 2;i <= n;i++) m[i] = a[i - 1] - m[i - 1];
  for(int i = 1;i <= n;i++) printf("%lld%c",m[i],i == n ? '\n' : ' ');
  return 0;
}


Measured memory_bytes: 2944
fun main(args: Array<String>) {

    val (n, k) = readLine()!!.split(" ").map(String::toInt)

    val hList = readLine()!!.split(" ").map (String::toInt)

    println(abc142b(k,hList))
}

fun abc142b(k: Int, hList: List<Int>): Any? {
    return hList.filter { it >= k }.count()
}


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


long long dp[100+1][100000+1] = {};

int main() {
  long long N, W;
  cin >> N >> W;
  vector<long long> w(N), v(N);
  for (long long i = 0; i < N; i++) {
    cin >> w[i] >> v[i];
  }
  
  for (long long i = 0; i < N; i++) {
    for (long long j = 1; j <= W; j++) {
      if (w[i] <= j) {
        if (i == 0) {
          dp[i][j] = v[i];
        } else {
          dp[i][j] = max(dp[i-1][j-w[i]]+v[i], dp[i-1][j]);
        }
      } else {
        if (i == 0) {
          dp[i][j] = 0;
        } else {
          dp[i][j] = dp[i-1][j];
        }
      }
    }
  }
  cout << dp[N-1][W] << endl;
  return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n
#define endl '\n'

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const ll mod=1000000007;
const ll mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll nCrmod(ll n,ll r){ll x=1,y=1; rep(i,r){x=x*(n-i)%mod; y=y*(i+1)%mod;} return x*powmod(y,mod-2)%mod;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	string s;
	ll k;
	cin >> s >> k;
	ll n=s.size();
	rep(i,n){
		if(s[i]!='a' && 'z'-s[i]+1<=k){
			k-='z'-s[i]+1;
			s[i]='a';
		}
		if(i==n-1){
			rep(j,k){
				if(s[i]=='z') s[i]='a';
				else s[i]++;
			}
		}
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
using namespace std;

int dan;
long long int memo[40];

int main(){
  memo[1]=1;
  memo[2]=2;
  memo[3]=4;
  for(int i=4;i<31;i++){
    memo[i]=memo[i-1]+memo[i-2]+memo[i-3];
  }
  for(int i=1;i<31;i++){
    if(memo[i]%10==0){
      memo[i]=memo[i]/10;
    }
    else{
      memo[i]=memo[i]/10+1;
    }
  }

  for(int i=1;i<31;i++){
    if(memo[i]%365==0){
      memo[i]=memo[i]/365;
    }
    else{
      memo[i]=memo[i]/365+1;
    }
  }
  
  while(1){
    cin>>dan;
    if(dan==0){break;}
    cout<<memo[dan]<<endl;
  }
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));

int li[30];
int dp[200010];
pair<char, int> pos[200010];

int main(){
	string s; cin >> s;
	
	REP(i,0,200010) dp[i] = INF;
	REP(i,0,26) li[i] = s.size() + 1;
	dp[s.size() + 1] = 0;
	dp[s.size()] = 1;
	pos[s.size()] = {'a', s.size() + 1};
	
	RREP(i, s.size() - 1, 0){
		li[s[i] - 'a'] = i + 1;
		
		REP(j,0,26){
			if(dp[li[j]] + 1 < dp[i]){
				dp[i] = dp[li[j]] + 1;
				pos[i] = {(char)('a' + j), li[j]};
			}
		}
	}
	
	int c = 0;
	while(c < s.size() + 1) cout << pos[c].first,c = pos[c].second;
	cout << endl;
	return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

string a, b, c;
int main() {
    cin >> a >> b >> c;
    bool ok = true;
    if (a.back() != b.front())
        ok = false;
    if (b.back() != c.front())
        ok = false;
    if (ok)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}


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

const int NMAX = 1e5 + 5;
long long a[NMAX], sol, b[NMAX];
int n;

int main()
{
    cin >> n;
    for(int i = 1; i <= n + 1; i++) {
        cin >> b[i];
    }
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for(int i = 1; i <= n; i++) {
        long long minim = min(a[i], b[i]);
        sol += minim;
        a[i] -= minim;
        b[i] -= minim;
        minim = min(a[i], b[i + 1]);
        sol += minim;
        a[i] -= minim;
        b[i + 1] -= minim;
    }
    cout << sol;
    return 0;
}


Measured memory_bytes: 5168
#include <stdio.h>
 
int main(void){
	
	int a,b;
	
	scanf("%d %d",&a,&b);
	if(a == 1||a == 3||a == 5||a == 7||a == 8||a == 10||a == 12) 
	{
		if(b == 1||b == 3||b == 5||b == 7||b == 8||b == 10||b == 12){
		printf("Yes\n");
		} else {
		printf("No\n");
		}
		
	} else if(a == 4||a == 6||a == 9||a == 11){
		if(b == 4||b == 6||b == 9||b == 11){
		printf("Yes\n");
		} else {
		printf("No\n");
		}
	} else if(a == 2) {
		if(b == 2){
		printf("Yes\n");
		} else {
		printf("No\n");
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")

using namespace std;

#define fi first
#define se second
using ll = long long;

const int INF = (int) 1e9 + 9;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int d[n];
    for (int i = 0; i < n; ++i) {
        cin >> d[i];
    }
    int sum = 0;
    for (int i = 0; i <= n-2; ++i) {
        for (int j = i+1; j < n; ++j) {
            sum += d[i]*d[j];
        }
    }
    cout << sum << '\n';
    return 0;
}


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

struct List {
  int num;
  struct List *before;
  struct List *next;
};

struct List l;

void insert(int key) {
  struct List *a = (struct List *)malloc(sizeof(struct List));
  a->num = key;
  a->before = &l;
  a->next = l.next;
  l.next = a;
  a->next->before = a;
}

void delete(int b) {
  struct List *c;
  c = l.next;
  while(c->num != -1) {
    if (c->num == b) {
      c->next->before = c->before;
      c->before->next = c->next;
      break;
    }  
    c = c->next;
  } 
  }

void delete_First() {
  l.next = l.next->next;
  l.next->before = &l;
}

void delete_Last() {
  l.before = l.before->before;
  l.before->next = &l;
}

int main(void) {
  int n;
  char command[12];
  int key;
  int adress = 1;
  struct List *box;
  l.num = -1;
  l.before = &l;
  l.next = &l;

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", command);
    if (strcmp(command, "deleteFirst") == 0)
      delete_First();
    else if (strcmp(command, "deleteLast") == 0)
      delete_Last();
    else {
      scanf("%d", &key);
      if (strcmp(command, "insert") == 0) 
	insert(key);
      else if (strcmp(command, "delete") == 0)
	delete(key);
      }
    }
 
  
  box = l.next;
  while(box->num != -1) {
    printf("%d", box->num);
    box = box->next;
    if (box->num != -1)
      printf(" ");
  }
  printf("\n");
  
  return 0;
}



Measured memory_bytes: 36100
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    a = tuple(map(int, input().split()))

    b = []
    box = [0] * (N + 1)
    for i, r in zip(reversed(range(1, N + 1)), a[::-1]):
        total_r = sum(box[j] for j in range(i, N + 1, i)) % 2
        if r == 0 and total_r == 1:
            box[i] = 1
            b.append(i)
        elif r == 1 and total_r == 0:
            box[i] = 1
            b.append(i)

    M = len(b)
    if M == 0:
        print(0)
    else:
        print(M)
        print(" ".join(map(str, b)))


if __name__ == "__main__":
    main()


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

const ll mod = 1000000007;
const int INF = 1001001001;

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int h, w; cin >> h >> w;
	int m; cin >> m;
    //store the number of targets in each row and column
	vector<int> x(h+1), y(w+1);
  
    //store the position of targets
	set<pair<int, int>> st;
  
	for(int i = 0; i < m; i++){
		int a, b; cin >> a >> b;
		x[a]++;
		y[b]++;
		st.insert({a, b});
	}
	int xmx = *max_element(x.begin(), x.end());
    int ymx = *max_element(y.begin(), y.end());
    
    //keep track of indices which have the maximum number of targets
	vector<int> tmpx, tmpy;
	for(int i = 1; i <= h; i++){
		if(x[i] == xmx) tmpx.push_back(i);
	}
	for(int i = 1; i <= w; i++){
		if(y[i] == ymx) tmpy.push_back(i);
	}
  		
    //this iteration stops after at most m + 1 times.
	bool no_bomb = false; 
	for(int i = 0; i < tmpx.size(); i++){
		for(int j = 0; j < tmpy.size(); j++){
          
            //there is not a target at (tmpx[i], tmpy[i])
			if(!st.count({tmpx[i], tmpy[j]})){
				no_bomb = true;
				break;
			}
		}
	}
	int ans = xmx + ymx;
	if(!no_bomb) ans--;
	cout << ans << endl;
} 



Measured memory_bytes: 23764
import java.util.NoSuchElementException;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        try {
            int h = Integer.parseInt(sc.nextLine());
            int[] a = new int[h + 1];
            for (int i = 1; i <= h; i++) {
                int k = sc.nextInt();
                a[i] = k;
            }
            a = buildMaxHeap(a, h);
            for (int i = 1; i <= h; i++) {
                System.out.printf(" %d", a[i]);
            }
            System.out.println();
        } catch (NoSuchElementException
                | NumberFormatException e) {
            System.out.println(e);
        }
    }

    private static int left(int i) {
        return i * 2;
    }

    private static int right(int i) {
        return i * 2 + 1;
    }

    private static int[] buildMaxHeap(int[] a, int h) {
        for (int i = h / 2; i >= 1; i--) {
            a = maxHeapify(a, i, h);
        }
        return a;
    }

    private static int[] maxHeapify(int[] a, int i, int h) {
        int l = left(i);
        int r = right(i);
        int largest = i;
        if (l <= h && a[l] > a[i]) {
            largest = l;
        }
        if (r <= h && a[r] > a[largest]) {
            largest = r;
        }

        if (largest != i) {
            int tmp = a[i];
            a[i] = a[largest];
            a[largest] = tmp;
            a = maxHeapify(a, largest, h);
        }
        return a;
    }
}



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

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0;i < n;i++){
    cin >> a[i];
  }
  int ret = 0;
  int cur = 0;
  for(int i = 0;i < n-1;i++){
    if(a[i] >= a[i+1]){
      cur++;
    }else{
      cur = 0;
    }
    ret = max(ret,cur);
  }
  cout << ret << endl;
}


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

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


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

int main()
{
    char ch[100000];
    char ch2[100000];

    // 入力
    scanf("%s", &ch);
    int num = strlen(ch);

    if(num < 2) {
        printf("0");
        return 0;
    }

    if (ch[0] == '0') {
        for(int i = 0; i < num; i ++) {
            if( i%2 == 0 ) {
                ch2[i] = '0';
            } else {
                ch2[i] = '1';
            }
        }
    } else {
        for(int i = 0; i < num; i ++) {
            if( i%2 == 0 ) {
                ch2[i] = '1';
            } else {
                ch2[i] = '0';
            }
        }
    }

    int j = 0;
    for(int i = 0; i < num; i ++) {
        if(ch[i] != ch2[i]) {
            j++;
        }
    }
 
    // 出力
    printf("%d", j);
    return 0;
}


Measured memory_bytes: 384
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N, A, B = sc.nextInt()
    val H = Array.fill(N)(sc.nextInt())

    // 貪欲法？
    // 常に一番体力が大きそうなモンスターを中心に攻撃していけば良さそう
    // 一番体力の大きなモンスターを効率よく選択する為には最大ヒープを使えば良さそう
    // まず, 体力を大きい順に優先度付したモンスターを全てぶち込む
    // すると、先頭のモンスターが一番体力が大きいので、最大ヒープから取り出し
    // そのモンスターを中心に攻撃する。それ以外のモンスターには均一にBだけダメージを与えるので
    // 全体としてのヒープ性は保たれる。全てのモンスターの体力が0になると終了する
    // 攻撃が終わった後, 再度モンスターをヒープに入れる. この時、ヒープが再計算される

    // 第一案.
    // これだと, 最悪計算量, 攻撃が10^9回しなければならないので, 時間が間に合わない
    // もうちょい効率のいい方法を考える必要がある
//    def solve(N: Int, A: Int, B: Int, H: Array[Int]): Int = {
//      import scala.collection.mutable
//      val priorityQueue =
//        mutable.PriorityQueue[Int](0 until N: _*)(
//          Ordering.by[Int, Int](H))
//      @scala.annotation.tailrec
//      def loop(count: Int): Int =
//        if (H.exists(_ > 0)) {
//          val i = priorityQueue.dequeue()
//
//          H(i) -= A
//          for {
//            j <- 0 until N
//            if i != j
//          } H(j) -= B
//
//          priorityQueue += i
//          loop(count + 1)
//        } else count
//      loop(0)
//    }

    // 第二案,
    // x回攻撃した時に, 全ての魔物を倒せるか倒せないかを C(x)とする
    // そうした時, x * B のダメージを全ての敵に対して与えることができる
    // また, A > B から (A - B)を1体に与え, Bを全体に与えるとみなすことができ
    // (A - B)をどの順番で攻撃しても変わりないので、
    // 一回の判定で O(N) で, 二分探索分で O(N log M)で計算できるので間に合う
    def solve(N: Int, A: Long, B: Long, H: Array[Int]): Int = {
      val C = A - B
      val M = Math.pow(10, 9).toInt

      def check(x: Int): Boolean =
        H.foldLeft(0L)((b, h) =>
          b + (((h - x * B) max 0L) / C.toDouble).ceil.toLong) <= x

      def upperBounds(): Int = {
        @scala.annotation.tailrec
        def loop(left: Int, right: Int): Int =
          if (right - left > 1) {
            val mid = left + (right - left) / 2
            if (check(mid)) loop(left, mid)
            else loop(mid, right)
          } else right
        loop(-1, M+1)
      }

      upperBounds()
    }

    println(solve(N, A, B, H))
  }

}


Measured memory_bytes: 67512
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int x = Integer.parseInt(sc.next());
        int y = Integer.parseInt(sc.next());
        String postal = sc.next();
        String[] decomp = new String[3];
        decomp[0] = postal.substring(0, x);
        decomp[1] = postal.substring(x, x + 1);
        decomp[2] = postal.substring(x + 1, postal.length() - 1);
        for (int i = 0; i < 3; i++) {
            char[] array = decomp[i].toCharArray();
            if (i == 0 || i == 2) {
                for (char c : array) {
                    if (!Character.isDigit(c)) {
                        System.out.println("No");
                        return;
                    } 
                }
            } else {
                if (array[0] != '-') {
                    System.out.println("No");
                    return;
                }
            }
        }
        System.out.println("Yes");
    }
}


Measured memory_bytes: 21716
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if(a<b && b<c)
			System.out.println("Yes");
	        else
			System.out.println("No");
	}
}




Measured memory_bytes: 26268
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
signed main(){
    int n,k;cin >> n >> k;
    int a[n];
    rep(i,n){
        cin >> a[i];
        a[i]--;
    }
    vector<int> p = {0};
    rep(i,n){
        p.push_back(a[p.back()]);
    }
    int i;
    for(i = 0;i < p.size() && p[i]!= p.back();i++);
    int T = p.size() - i-1;
    if(k <= i){
        cout << p[k]+1 << endl;
        return 0;
    }
    k -= i;
    k%= T;
    //rep(j,p.size())trace(j,p[j]);
    //trace(i,k,T);
    cout << p[i+k]+1 << endl;

    return 0;
}

Measured memory_bytes: 6932
import java.util.*;

public class Main {
    public static final int MAX_N = 50;

    public static void main(String[] args) {
        // read inputs
        final long K;
        try (Scanner in = new Scanner(System.in)) {
            K = in.nextLong();
        }

        // solve
        long[] xs = new long[MAX_N];
        final int N = 50;
        for (int i = 0; i < N; i++) {
            if (i < K % N) {
                xs[i] = i + (K / N + 1) * (N + 1) - K;
            } else {
                xs[i] = i + K / N * (N + 1) - K;
            }
        }
        System.out.printf("%d\n", N);
        System.out.printf("%d", xs[0]);
        for (int i = 1; i < N; i++) {
            System.out.printf(" %d", xs[i]);
        }
        System.out.printf("\n");
    }
}


Measured memory_bytes: 23252
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){
int d,s,t;

cin>>d>>t>>s;
if(t*s>=d){
    cout<<"Yes"<<endl;
}else{
    cout<<"No"<<endl;
}



    
return 0;
}


Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.IO;

class Program{
    static void Main(string[] args){
        var A1 = Console.ReadLine().Split();
        var A2 = Console.ReadLine().Split();
        var A3 = Console.ReadLine().Split();
        var sheet = new[] {A1, A2, A3};
        var N = int.Parse(Console.ReadLine());
        var isHoles = new bool[3, 3];
        var selected = new HashSet<string>();
        for (int i = 1; i <= N; i++){
            var b = Console.ReadLine();
            if (selected.Contains(b)) continue;
            for (int r = 0; r < 3; r++){
                for (int c = 0; c < 3; c++){
                    if (b == sheet[r][c]) isHoles[r,c] = true;
                    selected.Add(b);}}}
        var isBingo = false;
        for (int r = 0; r < 3; r++) if (!isBingo) isBingo = isHoles[r, 0] && isHoles[r, 1] && isHoles[r, 2];
        for (int c = 0; c < 3; c++) if (!isBingo) isBingo = isHoles[0, c] && isHoles[1, c] && isHoles[2, c];
        if (!isBingo) isBingo = isHoles[0, 0] && isHoles[1, 1] && isHoles[2, 2];
        if (!isBingo) isBingo = isHoles[0, 2] && isHoles[1, 1] && isHoles[2, 0];
        var answer = isBingo ? "Yes" : "No";
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();}}

Measured memory_bytes: 27920
from collections import defaultdict

n, m = map(int, input().split())
p = defaultdict(set)
for _ in range(m):
  ai, bi = map(int, input().split())
  p[ai].add(bi)
  p[bi].add(ai)

cnt = 0
cand_list = [(1, set(range(2, n + 1)))]

while(len(cand_list) != 0):
  c = cand_list.pop(0)

  if len(c[1]) == 0:
    cnt += 1
  for x in c[1] & p[c[0]]:
    remain = c[1].copy()
    remain.remove(x)
    cand_list.append((x, remain))

print(cnt)


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

int main() {
  int n, sum = 0;
  cin >> n;
  for (int x = n; x >= 1; x /= 10) {
    sum += x - (x / 10) * 10;
  }
  cout << (n % sum == 0 ? "Yes" : "No") << endl;
  
  return 0;
}

Measured memory_bytes: 256