akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static Scanner sc;
	
	public static void main(String[] args) {
		//System.out.println("Please input H and W below");
		//宣言
		sc = new Scanner(System.in);
		int H[]= new int[300];
		int W[]= new int[300];
		int i=1;
		//入力
		for(;;) {
			H[i]=sc.nextInt();
			W[i]=sc.nextInt();
			if(H[i]==0 && W[i]==0) {
				break;
			}
			i++;
		}
		i=1;
		/*System.out.printf("H[%d]=%d,W[%d]=%d\n", i,H[i],i,W[i]);*/
		//出力
		for(;;){
			if(H[i]==0 && W[i]==0) {
				break;
			}
			//長方形
			int j,k;
			for(j=1;j<=H[i];j++) {
				for(k=1;k<=W[i];k++) {
					System.out.print("#");
				}	
				System.out.print("\n");
			}
			System.out.print("\n");
			i++;
		}
	}
}



Measured memory_bytes: 38272
import bisect
N = int(input())
A = list(map(int,input().split()))
A.sort()
B = list(map(int,input().split()))
C = list(map(int,input().split()))
C.sort()

res = 0
for b in B:
  pairA = bisect.bisect_left(A, b)
  pairC = bisect.bisect_right(C, b)
  res += pairA * (N-pairC)

print(res)

Measured memory_bytes: 105444
import sys
pin=sys.stdin.readline
sys.setrecursionlimit(10000000)

def f(n):
  if n==0:
    return 1
  if n==1:
    if dp[n]==0:
      return 0
    return 1
  if dp[n]==0:
    return 0
  if dp[n-1]==-1:
    dp[n-1]=f(n-1)
  if dp[n-2]==-1:
    dp[n-2]=f(n-2)
  return dp[n-1]+dp[n-2]


N,M=map(int,pin().split())
mod=1000000007
dp=[-1]*(N+1)
dp[0]=1
for i in range(M):
  dp[int(pin())]=0
print(f(N)%mod)

Measured memory_bytes: 501708
n,a,b,c=map(int,input().split())
banboo = [int(input()) for i in range(n)]

def dfs(num,A,B,C):
    if num == n:
        return abs(A-a)+abs(B-b)+abs(C-c)-30 if min(A,B,C)>0 else float("inf")
    v1 = dfs(num+1,A,B,C)
    v2 = dfs(num+1,A+banboo[num],B,C) + 10
    v3 = dfs(num+1,A,B+banboo[num],C) + 10
    v4 = dfs(num+1,A,B,C+banboo[num]) + 10
    return min(v1,v2,v3,v4)
print(dfs(0,0,0,0))

Measured memory_bytes: 45404
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define pb push_back 
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
typedef long long ll;
const int INF = 100000000, mod = 1000000007;
const ll LLINF = 1LL << 50;
using namespace std;


int main() {
    int n;
    vector<int> a, b, c;
    ll ans = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int t;
        cin >> t;
        a.pb(-t);
    }
    for (int i = 0; i < n; i++) {
        int t;
        cin >> t;
        b.pb(t);
    }
    for (int i = 0; i < n; i++) {
        int t;
        cin >> t;
        c.pb(t);
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    for (int i = 0; i < n; i++) {
        int ta, tc;
        tc = c.end() - upper_bound(c.begin(), c.end(), b[i]);
        ta = a.end() - upper_bound(a.begin(), a.end(), -b[i]);
        ans += (ll)ta*tc;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1784
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

  if(n%10 == 3) cout << "bon" << endl;
  else if (n%10 == 0 || n%10 == 1 || n%10 == 6 ||n%10 == 8) cout << "pon" << endl;
  else cout << "hon" << endl;

  return 0;
}


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

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

int r,d,x,ans;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    

    cin>>r>>d>>x;
    ans=x;
    rep(i,1,10)
    {
        ans = r*ans-d;
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}


int main(void) {
  ll N, X;
  cin >> N >> X;
  ll l[111];
  ll i;
  
  for(i=0; i<N; i++) {
    cin >> l[i];
  }
  
  ll now=0;
  ll cnt=1;
  for(i=0; i<N; i++) {
    now+=l[i];
    if(now<=X) {
      cnt++;
    }
  }
  pt(cnt);
  
}







Measured memory_bytes: 256
N = gets.to_i
B = gets.split.map(&:to_i)

R = Array.new(N)

B.each_with_index do |b, idx|
  if idx == 0
    R[0] = b
    R[1] = b
  else
    if R[idx] > b
      R[idx] = b
    end

    R[idx + 1] = b
  end
end

p R.inject(:+)


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
bool debug = false;

int main() {
  double Ans = 0;  // 回答：
  // int Ans = 0;  // 回答：
  // string Ans = "Yes";  // 回答：

  int N; cin >> N;  // 町の数
  vector<int> X(N); // 各町のＸ座標
  vector<int> Y(N); // 各町のＹ座標
  rep(i,N){
    cin >> X.at(i) >> Y.at(i);
  }

  double Dsum = 0;     // 各町間の距離のサマリ
  int Rcnt = 0;     // 全ルート数
  vector<int> T(N); // 各町の訪問順全順列
  rep(i,N){T.at(i)=i;}
  do {
    Rcnt++;
    // 配列 T は、町の訪問順に並んだ、町の番号
    rep(j,N-1){
      Dsum += sqrt( (X.at(T.at(j)) - X.at(T.at(j+1)) ) * (X.at(T.at(j)) - X.at(T.at(j+1)) ) + (Y.at(T.at(j)) - Y.at(T.at(j+1)) ) * (Y.at(T.at(j)) - Y.at(T.at(j+1)) ) );
    }
	// 順列に対する処理
	} while (next_permutation(T.begin(),T.end()));

  cout << fixed << setprecision(7);
  Ans = Dsum / Rcnt;
//  cout << "Dsum:" << Dsum << " Rcnt:" << Rcnt << endl;
  cout << Ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define forr(i, n) for(int i = 0;i < (int)n; i++)
#define deb(x) cout<<#x<<" " <<x<<"\n";
#define all(x) x.begin(), x.end()
#define eb emplace_back
#define mp make_pair
#define test int tests;cin >> tests;while(tests--)
#define endl "\n"
const int INF = 2e9;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int x,y;
	cin>>x>>y;
	if(((y-2*x)/2)+((4*x-y)/2)==x && (((4*x-y)/2) >= 0) && ((y-2*x)/2)>=0) cout<<"Yes";
	else cout<<"No\n";
	return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <stdlib.h>
#define MIN 1
#define MAX 1000

int main()
{
    int x, a, b;

    scanf("%d %d %d", &x, &a, &b);

    if ((x >= MIN && x <= MAX) && (a >= MIN && a<= MAX) && (b >= MIN && b <= MAX)) {
        if (abs(x - a) < abs(x - b)) {
            printf("A\n");
        }
        if (abs(x - a) > abs(x - b)) {
            printf("B\n");
        }
    } else {
        return 1;
    }
    return 0;
}

Measured memory_bytes: 128
/*
** 逆序数
*/

# include <iostream>
using namespace std;

# define MAX 200010
# define SENTINEL 2000000000
typedef long long llong;

int s[MAX], n;
llong cnt;

int L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(int a[], int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    for (int i = 0; i < n1; i++)
        L[i] = a[left + i];
    for (int i = 0; i < n2; i++)
        R[i] = a[mid + i];
    L[n1] = R[n2] = SENTINEL;
    int i = 0, j = 0;
    for (int k = left; k < right; k++) {
        if (L[i] <= R[j]) {
            a[k] = L[i++];
        }
        else {
            a[k] = R[j++];
            cnt += n1 - i;
        }
    }
}

void mergeSort(int a[], int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        mergeSort(a, left, mid);
        mergeSort(a, mid, right);
        merge(a, left, mid, right);
    }
}

int main() {
    // freopen("infile", "r", stdin);
    // freopen("outfile", "w", stdout);
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> s[i];
    cnt = 0;
    mergeSort(s, 0, n);
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 4656
k = int(input())
ans = [-1] * 11
ans[-1] = 1
idx = 1
def add(keta):
    if ans[keta] == -1:
        ans[keta] = 1
    else:
        ans[keta] += 1
        if ans[keta] == 10:
            add(keta - 1)
            ans[keta]=max(0,ans[keta-1]-1)
        elif abs(ans[keta - 1] - ans[keta]) > 1 and ans[keta - 1] != -1:
            add(keta - 1)
            ans[keta] = max(0, ans[keta - 1] - 1)
        
while idx != k:
    idx+=1
    if ans[-2] == -1:
        if ans[-1] == 9:
            ans[-2] = 1
            ans[-1] = 0
        else:
            ans[-1] += 1
        continue
    add(-1)
# print(ans)
ans=[ans[i] for i in range(len(ans)) if ans[i]!=-1]
ans=map(str,ans)
print("".join(ans))

Measured memory_bytes: 56432
const MOD: i64=1000000007;
fn main() {
    let (n,m) = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s: Vec<usize> = s.split_whitespace().map(|x|x.parse().unwrap()).collect();
        (s[0], s[1])
    };
    let x: Vec<i64> = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.split_whitespace().map(|x|x.parse().unwrap()).collect()
    };
    let y: Vec<i64> = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.split_whitespace().map(|x|x.parse().unwrap()).collect()
    };
    let mut s=0;
    for i in 1..n {
        s += (i*(n-i))as i64%MOD*(x[i]-x[i-1])%MOD;
        s %= MOD;
    }
    let mut t=0;
    for i in 1..m {
        t += (i*(m-i))as i64%MOD*(y[i]-y[i-1])%MOD;
        t %= MOD;
    }
    println!("{}",s*t%MOD);
}

Measured memory_bytes: 10492
#include<stdio.h>
int main (void){
  int a,b,c;
  int i;
  int num=0;
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);

  for(i=a;i<=b;i++)
    if(c%i==0)
      num++;

  printf("%d\n",num);
  return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define inf 1000000007
#define double long double
using namespace std;
typedef pair<double, double>P;
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
ll mod_pow(ll x, ll n, ll mod) {
	ll bit = 1;
	while (n) {
		if (n & 1)bit = bit * x % mod;
		x = x * x % mod;
		n /= 2;
	}
	return bit;
}
ll C(ll a, ll b) {
	ll x = 1, y = 1;
	rep(i, b) {
		x = x * (a - i) % inf;
		y = y * (b - i) % inf;
	}
	rep(i, inf) {
		if (x == y * i % inf) {
			return i;
		}
	}
}
signed main() {
	ll a, b;
	cin >> a >> b;
	if ((a + b) % 2 == 1)puts("IMPOSSIBLE");
	else cout << (a + b) / 2 << endl;
	ggr
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N;
  cin>>N;
     vector<int> P(N);
   for (int i = 0; i < N; i++) {
    cin >> P.at(i);
  }
int curMIN =1000000;
int ans =0;
for (int i = 0; i < N; i++) {
 curMIN = min(curMIN,P[i]);
  if(curMIN==P[i]){
    ans++;
  }
}
  cout <<ans<<endl;
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;

int MOD = 1e9+7;

//ll po(ll b, ll p){ return !p?1:po(b*b%MOD,p/2)*(p&1?b:1)%MOD;}
// ll pomd(ll a, ll k, ll md) { ll p; if (k == 0){ return 1; } p = pomd(a, k / 2, md); p = p * p % md; if (k % 2){ p = p * a % md; } return p; }
// counting divsrs: vi arr(N); for(int i{1}; i<N; ++i) for(int j=i; j<N; j+=i) d[j]++;

#define mp make_pair
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)

void setIO(string name = ""){
    freopen((name+".in").c_str(), "r", stdin); 
    freopen((name+".out").c_str(), "w", stdout);
}	

int main(){
 	ios_base::sync_with_stdio(0); cin.tie(0); 
	// setIO();
	ll h,a; cin >> h >> a;
	cout << (h%a==0?h/a:h/a+1) << "\n";

}





Measured memory_bytes: 3596
#include <stdio.h>
int main(){
  int i,N,j,A[100],tmp,count=0;
  scanf("%d",&N);
  for(i = 0; i < N; i++){
    scanf("%d",&A[i]);
  }
  for(j = 0; j < N-1; j++){
    for(i = N-1; i >= 1+j; i--){
      if(A[i] < A[i-1]){
	tmp = A[i];
	A[i] = A[i-1];
	A[i-1] = tmp;
	count++;
      }
    }
  }
  for(i = 0; i < N-1; i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[i]);
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
 int main(){
   char S[20];
   scanf("%s",&S[0]);
  if(S[0]=='S')
    printf("Cloudy\n");
  else if(S[0]=='C')
    printf("Rainy\n");
  else
    printf("Sunny\n");

  return 0;
 }

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

const int NMAX = 1e5 + 5;
const int INF = NMAX * 3;

int n, nodT, nodA;
int distT[NMAX], distA[NMAX];
vector <int> G[NMAX];

void bfsT() {
    for (int i = 1; i <= n; i++)
        distT[i] = INF;

    queue <int> Q;
    distT[nodT] = 0;
    Q.push(nodT);
    while (!Q.empty()) {
        int nod = Q.front();
        Q.pop();
        for (auto v: G[nod])
            if (distT[nod] + 1 < distT[v]) {
                distT[v] = distT[nod] + 1;
                Q.push(v);
            }
    }
}

void bfsA() {
    for (int i = 1; i <= n; i++)
        distA[i] = INF;

    queue <int> Q;
    distA[nodA] = 0;
    Q.push(nodA);
    while (!Q.empty()) {
        int nod = Q.front();
        Q.pop();
        for (auto v: G[nod])
            if (distA[nod] + 1 < distA[v]) {
                distA[v] = distA[nod] + 1;
                Q.push(v);
            }
    }
}



int main()
{
    cin >> n >> nodT >> nodA;
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }

    bfsT();
    bfsA();

    /*for (int i = 1; i <= n; i++)
        cout << distA[i] << " ";*/
    
    int ans = 0;
    for (int i = 1; i <= n; i++)
        if (distT[i] < distA[i]) {
            int ansHere = distA[i] - (1 || abs(distA[i] - distT[i]) % 2 == 0);
            ans = max(ans, ansHere);
        }
    cout << ans;

    return 0;
}

Measured memory_bytes: 6656
while True:
    m, f, r = map(lambda x: int(x), input().split(" "))
    if (m, f, r) == (-1, -1, -1):
        break
    if m == -1 or f == -1:
        print("F")
    elif m + f >= 80:
        print("A")
    elif m + f >= 65:
        print("B")
    elif m + f >= 50 or r >= 50:
        print("C")
    elif m + f >= 30:
        print("D")
    else:
        print("F")



Measured memory_bytes: 5600
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;
const long long mod = 1e9 + 7;

int main() {
/**
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif
*/
  int n, x;
  cin >> n >> x;
  pair<long long, long long> v;
  v.second = x;
  v.first = 0;
  for (int i = 1; i < n; i++) {
    cin >> x;
    v.first = (v.first + (v.second * x) % mod) % mod;
    // v.second += x;
    v.second = (v.second + x) % mod;
    // v.second %= mod; // avoid overflow
    // cout << "v.first: " << v.first << endl;
  }
  cout << v.first << endl;
}


Measured memory_bytes: 3580
using System;

namespace ABC132_B
{
    class Program
    {
        static void Main(string[] args) {
            int n = int.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split();
            long[] numbers = new long[n];

            for(int i = 0; i < n; i++) {
                numbers[i] = long.Parse(input[i]);
            }

            long sum = 0;
            for(int i = 1; i < n - 1; i++) {
                if(numbers[i - 1] < numbers[i]) {
                    if(numbers[i + 1] > numbers[i]) {
                        sum++;
                    }
                }
                if (numbers[i - 1] > numbers[i]) {
                    if (numbers[i + 1] < numbers[i]) {
                        sum++;
                    }
                }
            }

            Console.WriteLine(sum);
        }
    }
}

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

#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=1;i<=n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>

const int N = 105;
const int V = 1e5+10;
const int inf = 1e13;

int dp[N][V],w[N],v[N],we,n;

void solve()
{
  cin >> n >> we;
     
  f(i,n) cin >> w[i] >> v[i];
  
  for(int j=0;j<=1e5;j++) dp[0][j] = inf;  
   
  dp[0][0] = 0;  
    
  f(i,n)
  {  
   for(int j=0;j<=1e5;j++) dp[i][j] = dp[i-1][j];   
      
   for(int j=0;j<=1e5;j++)
      if(j-v[i] >=0) dp[i][j] = min(dp[i][j] , w[i] + dp[i-1][j-v[i]]);
  }
    
  int ans = 0;  
    
  for(int j=0;j<=1e5;j++) 
      if(dp[n][j] <= we) ans=max(ans,j);
    
  cout << ans;
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

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

#define pb push_back
#define mp make_pair
#define ld long double
#define ll long long int
#define f(i,g,n) for(int i=g;i<=n;i++)
#define rf(i,g,n) for(int i=n;i>=g;i--)

const int N=1e3+1;

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

	ll n,m,k;
	cin>>n;
	m = sqrt(n);
	for(int i=m;i>=1;i--)
	{
		if(n%i == 0)
		{
			m = i;
			k = n/i;
			break;
		}
	}
	cout<<m+k-2;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxs 320022
#define LL long long
#define mme(i,j) memset(i,j,sizeof(i))
using namespace std;
LL a[maxs],pre[maxs],suf[maxs];
priority_queue<LL, vector<LL>, greater<LL> >q;
priority_queue<LL> qq;

int main(){

    int n;
    while(~scanf("%d",&n))
    {
        LL sum1 =0,sum2=0;
        while(!q.empty())
            q.pop();
        while(!qq.empty())
            qq.pop();

        for(int i=1;i<=3*n;i++)
        {
            scanf("%d",&a[i]);
            if(i<=n) sum1+=a[i], q.push(a[i]);
            else if(i>2*n) sum2+=a[i], qq.push(a[i]);
        }
        pre[n]=sum1;
        suf[2*n+1]=sum2;

        for(int i=n+1;i<=2*n;i++){
            if(q.top()<a[i]){
                sum1+= a[i]-q.top();
                q.pop();
                q.push(a[i]);
            }
            pre[i]=sum1;
        }
        suf[2*n]=sum2;
        for(int i=2*n-1;i>=n;i--){
            if(qq.top()>a[i+1]){
                sum2=sum2 - qq.top()+a[i+1];
                qq.pop();
                qq.push(a[i+1]);
            }
            suf[i]=sum2;
        }
        LL ans = pre[n]-suf[n];
        for(int i=n+1;i<=2*n;i++){
            ans = max(ans,pre[i]-suf[i]);
        }

        printf("%lld\n",ans);
    }
    return 0;
}

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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

void dfs(int i,int par,vector<vector<int>>& edges,vector<bool>& p)  {
    for (int& j : edges[i]) if (j != par) {
        p[j] = !p[i];
        dfs(j,i,edges,p);
    }
}

int main() {
    int n;
    cin >> n;
    vector<int> ans(n,-1);
    vector<bool> p(n),used(n+1,false);
    vector<vector<int>> edges(n);
    for (int i = 0;i < n-1;++i) {
        int u,v;
        cin >> u >> v;
        u--;v--;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }
    p[0] = false;
    dfs(0,-1,edges,p);
    int cnt = 0;
    for (int i = 0;i < n;++i) if (p[i]) cnt++;
    if (cnt <= n/3) {
        int j = 0;
        for (int i = 0;i < n;++i) if (p[i]) {
            j += 3;
            ans[i] = j;
            used[j] = true;
        }
    } else if (n-cnt <= n/3) {
        int j = 0;
        for (int i = 0;i < n;++i) if (!p[i]) {
            j += 3;
            ans[i] = j;
            used[j] = true;
        }
    } else {
        int j = -1;
        for (int i = 0;i < n;++i) if (p[i]) {
            j += 3;
            if (j > n) break;
            ans[i] = j;
            used[j] = true;
        }
        j = -2;
        for (int i = 0;i < n;++i) if (!p[i]) {
            j += 3;
            if (j > n) break;
            ans[i] = j;
            used[j] = true;
        }
    }
    stack<int> st;
    for (int i = 1;i < n+1;++i) if (!used[i]) st.push(i);
    for (int i = 0;i < n;++i) if (ans[i] < 0) {
        ans[i] = st.top();
        st.pop();
    }
    for (int i = 0;i < n;++i) cout << ans[i] << " \n"[i == n-1];
}

Measured memory_bytes: 22400
#pragma GCC optimize("O3")

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <string_view>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout(a) cout << fixed << setprecision((int)(a))

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ll MOD2   = 998244353;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define reps(i, n)      for(int i = 1; (i) <= (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define repbit(bit, n)  for(int bit = 0; (bit) < (1 << (n)); ++(bit))
#define ifbit(bit, i)   if((bit) & (1 << (i)))
#define CtoI(c)         int((c)) - int('0')
#define ItoC(c)         char((c) + '0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/



/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    int n; cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i, n) cin >> a[i], --a[i];
    rep(i, n) cin >> b[i];
    rep(i, n-1) cin >> c[i];

    int ans = 0;
    ans += b[a[0]];
    for(int i = 1; i < n; ++i){
        if(a[i - 1] == a[i] - 1)
            ans += b[a[i]] + c[a[i - 1]];
        else ans += b[a[i]];
    }

    cout << ans << endl;

return 0;
}

Measured memory_bytes: 3640
import java.io.*;
import java.util.*;

import static java.lang.Math.*;

public class Main {
  public static void main(String[] args) {
    new Main().solve();
  }

  private void solve() {
    try(InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out)) {

      final int n = in.nextInt();
      List<Pear> task = new ArrayList<>(n);
      for (int i = 0; i < n; i++) {
        task.add(new Pear(in.nextInt(), in.nextInt()));
      }

      task.sort(new Comparator<Pear>() {
        @Override
        public int compare(Pear a, Pear b) {
          return a.compareTo(b);
        } });

      boolean isComp = true;
      int time = 0;
      for (Pear p : task) {
        time += p.c;
        if(time > p.l) {
          isComp = false;
          break;
        }
      }

      String ans = isComp ? "Yes" : "No";
      out.println(ans);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
  

  private class Pear implements Comparable{
    public int c,l;
    Pear(int c, int l) {
      this.c = c;
      this.l = l;
    }

    @Override
    public int compareTo(Object o) {
      if(o == null) throw new NullPointerException();
      Pear obj = (Pear)o;
      return l == obj.l ? 0 : l - obj.l;
    }
  }

  int atoi(String s) { return Integer.parseInt(s); }
  long atol(String s) { return Long.parseLong(s); }

  static class InputReader implements AutoCloseable {
    public BufferedReader br;
    public StringTokenizer st;

    public InputReader(InputStream stream) {
      br = new BufferedReader(new InputStreamReader(stream), 32768);
      st = null;
    }
    public String next() {
      if (st == null || !st.hasMoreTokens()) {
        try { st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          throw new UncheckedIOException(e);
        }
      }
      return st.nextToken();
    }
    public int nextInt() { return Integer.parseInt(next()); }
    public long nextLong() { return Long.parseLong(next()); }
    int[] mapInt(int len) {
      int[] ret = new int[len];
      for (int i = 0; i < len; i++) ret[i] = Integer.parseInt(next());
      return ret;
    }
    long[] mapLong(int len) {
      long[] ret = new long[len];
      for (int i = 0; i < len; i++) ret[i] = Long.parseLong(next());
      return ret;
    }
    @Override public void close() throws IOException { br.close(); }
  }
}

Measured memory_bytes: 50688
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

int mod = -1;
int inv[50000];
string erase_space(string str){
	int n = str.size();
	string ans = "";
	rep(i,n){
		if(str[i] == ' ')continue;
		ans += str[i];
	}
	return ans;
}

class Arithmetic{
public:
	string str;
	int n, flag = 1;
	void init(string s){str = s;n = str.size();}
	int add(int a, int b){return (mod+a+b%mod)%mod;}
	int mul(int a, int b){return (a*b)%mod;}
	int div(int a, int b){
		if(b == 0){flag = 0;return 0;}
		return mul(a, inv[b]);
	}
	
	P get_num(int p){
		int ans = 0, q = -1, f = 0;
		if(str[p] == '(')return calc(p+1, 0);
		if(str[p] == '-'){f = 1;p++;}
		if(str[p] == '('){P pi = calc(p+1, 0);return P(-pi.fi, pi.se);}
		repi(i,p,n){
			if(!isdigit(str[i]))break;
			ans = ans*10+(str[i]-'0');q = i;
		}
		if(f)return P(-ans, q);
		return P(ans, q);
	}
	
	P calc(int pp = 0, int f = 0){
		P pi = get_num(pp);
		int ans = pi.fi, p = pi.se+1;
		repi(i,p,n){
			if(f and str[i] == ')')return P(ans, i-1);
			if(str[i] == ')')return P(ans, i);
			if(str[i] == '*' or str[i] == '/'){
				pi = get_num(i+1);
				if(str[i] == '*')ans = mul(ans, pi.fi);
				if(str[i] == '/')ans = div(ans, pi.fi);
			}
			if(str[i] == '+' or str[i] == '-'){
				if(f)return P(ans, i-1);
				if(str[i] == '+')pi = calc(i+1, 1);
				if(str[i] == '-')pi = calc(i, 1);
				ans = add(ans, pi.fi);
			}
			i = pi.se;
		}
		return P(ans, n-1);
	}
	int solve(int ret = -INF){
		flag = 1;
		P ans = calc();
		if(!flag)return ret;
		return ans.fi;
	}
};

signed main(){
	Arithmetic A;
	while(1){
		string str;
		getline(cin, str);
		if(str == "0:")break;
		int idx = 0;
		rep(i,str.size()){if(str[i] == ':'){idx = i;break;}}
		mod = atoll(str.substr(0, idx).c_str());
		str = erase_space(str.substr(idx+1, str.size()-idx-1));
		inv[1]=1;
		for(int i=2;i<mod;i++)inv[i]=mod-mod/i*inv[mod%i]%mod;
		A.init(str);
		int ans = A.solve();
		if(ans == -INF)cout << "NG" << endl;
		else{
			cout << str << " = " << ans;
			printf(" (mod %lld)\n", mod);
		}
	}
	return 0;
}





Measured memory_bytes: 3764
#include <stdio.h>
#define MOUNTAINS 10

void swap(int *a, int *b) {
    int tmp = *a;
    *a = *b;
    *b = tmp;
}

int main(void) {
    int height[MOUNTAINS],i,j;
    
    for (i = 0; i < MOUNTAINS; i++) {
	scanf("%d", &height[i]);
    }
    for (i = 0; i < MOUNTAINS-1; i++) {
	for (j = 0; j < MOUNTAINS-(i+1); j++) {
	    if (height[j] < height[j+1]) {
		swap(&height[j], &height[j+1]);
	    }
	}
    }
    for (i = 0; i < 3; i++) {
	printf("%d\n", height[i]);
    }
    return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<ll> vec;

void debug(vec &v) {
	int n = v.size();
	rep(i, n) {
		if (i > 0)cout << " ";
		cout << v[i];
	}
	cout << endl;
}

void solve() {
	ll a, b, k; cin >> a >> b >> k;
	ll m = min(a, k);
	a -= m; k -= m;
	m = min(b, k);
	b -= m;
	cout << a << " " << b << endl;
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(7);
	//init();
	//int t; cin >> t; rep(i, t)solve();
	solve();
	stop
		return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;cin>>n;
	string str;cin>>str;
	if(n%2==1){
		cout<<"No"<<endl;
		return 0;
	}else{
		int suc=1;
		for(int i=0;i<n/2;i++){
			if(str[i]!=str[n/2+i]){
				suc=0;break;
			}
		}
		if(suc){
			cout<<"Yes"<<endl;
			
		}else cout<<"No"<<endl;
		return 0;
	}
	return 0;
}

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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

#define vi vector <lli>
#define loop(num) for (lli i = 0 ; i < num ; i ++ )
#define loopcin(num , ar ) for (lli i = 0 ; i < num ; i ++ ) {cin >> ar [i] ;}
#define loopcout(num , ar) for (lli i = 0 ; i < num ; i ++ ) {cout << ar [i] << ' '; }

#define forr(num1 , num2) for (lli i = num1 ; i < num2 ; i ++ )
#define forrcin(num1 , num2 , ar ) for (lli i = num1 ; i < num2 ; i ++ ) {cin >> ar [i] ;}
#define forrcout(num1 , num2 , ar) for (lli i = num1 ; i < num2 ; i ++ ) {cout << ar [i] << ' '; }

#define D2forrcin(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cin >> A[i][j] ;}}
#define D2forrcout(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cout << A[i][j] << ' ' ;}cout << endl ;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define F first
#define S second

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main ()
{
    fastio
    lli n , k , x  , y ;
    cin >> n >> k >> x >> y ;
    cout << (n >= k ? k * x + (n - k) * y : n * x) ;

    return 0 ;
}

/*___________________________________________________________________functions___________________________________________________________________________*/



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

ll sousa(ll a){
  ll c=0;
  ll b=a;
  while(b%2==0){
    c++;
    b/=2;
  }
  return c;
}

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

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

int main(){

  ll n,m;
  cin >> n >> m;
  ll a[n];
  for(ll i=0;i<n;i++)cin >> a[i];

  ll b=sousa(a[0]);
  bool ok=true;

  for(ll i=1;i<n;i++){
    if(b!=sousa(a[i])){
      ok=false;
      break;
    }
  }

  if(!ok)cout << 0 << endl;
  else{
    for(ll i=0;i<n;i++)a[i]/=2;
    ll l=1;
    for(ll i=0;i<n;i++){
      l=lcm(l,a[i]);
      if(m<l){
        cout << 0 << endl;
        return 0;
      }
    }

    if(m<l)cout << 0 << endl;
    else cout << 1+(m-l)/(2*l) << endl;

  }


}

Measured memory_bytes: 4456
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 100001;
static const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline T int_ceil(T a, T b) { T res = a / b; if(a % b != 0) res++; return res; }
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define print(...)
#endif

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);
	ll n; cin >> n;
	vector<ll> v(n);
	rep(i, n) cin >> v[i];
	ll ans = 0;

	rep(i, n-1){
		if(v[i+1] < v[i]) {
			ans += v[i] - v[i+1];
			v[i+1] = v[i];
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4788
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int posx = 0;
        int posy = 0;
        int totalTime = 0;

        boolean flag = false;

        for(int i=0; i<num; i++){
            int time = sc.nextInt();
            int x = sc.nextInt();
            int y = sc.nextInt();

            int timeDiff = time - totalTime;

            int xdiff = Math.abs(x - posx);
            int ydiff = Math.abs(y - posy);
            int totalDiff = xdiff + ydiff;

            boolean DiffIsOdd = numIsOdd(timeDiff - totalDiff);

            if (totalDiff > timeDiff || DiffIsOdd){
                flag = false;
                break;
            } else {
                flag = true;
            }
            totalTime = time;
            posx = x;
            posy = y;
        }

        if(flag){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

    public static boolean numIsOdd(int num){
        if (num % 2 == 0){
            return false;
        }else{
            return true;
        }
    }
}


Measured memory_bytes: 88368
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
unsigned long long inf = (1LL << 62);
ll mod = 1000000007;

//bool operator< (pint a, pint b) {
	//return a.second < b.second;

//}



ll gcd(ll a, ll b) {

	if (b == 0)
		return a;

	return gcd(b, a % b);


}

ll max(ll a, ll b) {
	if (a < b) {
		return b;
	}
	else
		return a;

}

ll min(ll a, ll b) {
	if (a < b)
		return a;

	return b;
}




pint dx[4] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };

vector<pint> list;










void floyd(int N, ll** d) {

	rep(k, N+1){
		rep(i, N+1) {
			if (d[i+1][k+1] == inf) continue;
			rep(j, N+1) {
				if (d[j+1][k+1] == inf) continue;

				d[i+1][j+1] = min(d[i+1][j+1], d[i+1][k+1] + d[j+1][k+1]);

			}

		}
	}




}


ll d[100005];
vector<ll> M[100005];
vector<ll> anslist;


stack<int> to_1;






string S;


ll C[2 * 100005];
ll index[2 * 100005];
ll dp[2 * 100005];
int main() {
	ll N;


	cin >> N;

	rep(i, N)
		cin >> C[i+1];


	dp[0] = 1;
	rep(i, N) {
		
		if (index[C[i+1]] != 0 && (i+1) - index[C[i+1]] > 1) {
			dp[i + 1] = (dp[i] + dp[index[C[i + 1]]]) % mod;
		}

		else {
			dp[i + 1] = dp[i];
		}

		index[C[i + 1]] = i + 1;

	}


	cout << dp[N] << endl;

	return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const int MOD=1e9+7;

vector<vector<int>> enuCmb(int n, int k) {
    vector<vector<int>> res;
    if (n==0 || k==0 || n<k) {
      	return res;
    } else { 
		res=enuCmb(n-1,k);
		vector<vector<int>> res1=enuCmb(n-1,k-1);
		rep(i,res1.size()) {
			res1[i].push_back(n-1);
			res.push_back(res1[i]);
		}
		if (k==1) {
			vector<int> ins={n-1};
			res.push_back(ins);
		}
		return res;
    }
}

int main() {
    ios_base::sync_with_stdio(false); 

    int n;
    cin >> n;
    vector<vector<int>> a(2,vector<int>(n+1));
    rep(i,2) {
        rep(j,n) {
            cin >> a[i][j+1];
            a[i][j+1]+=a[i][j];
        }
    }
    int ans=0;
    repr(i,1,n+1) {
        ans=max(ans,a[0][i]-a[0][0]+a[1][n]-a[1][i-1]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#define endl '\n'
#define ll long long

using namespace std;

int N, A, B;
vector<int> monsters;
int ret;

bool check(ll times)
{
	ll require = 0;
	for (int i = 0; i < N; i++)
	{
		ll hp = monsters[i] - B * times;
		if (hp <= 0) { continue; }
		require += hp / (A-B);
		if (hp % (A-B) != 0) require += 1;
	}
	if (require <= times)
		return true;
	else
		return false;
}

void parametric_search(ll left, ll right)
{
	if (left > right) return;
	auto mid = (left + right) / 2;
	auto flag = check(mid);
	if (flag)
	{
		ret = mid;
		parametric_search(left, mid - 1);
	}
	else
	{
		parametric_search(mid + 1, right);
	}
}

int main(void)
{
	cin.tie(NULL); ios_base::sync_with_stdio(false);
	cin >> N >> A >> B;
	ll me = 0;
	for (int i = 0; i < N; i++) { ll temp; cin >> temp; monsters.push_back(temp);  me = max(me, temp); }
	parametric_search(0, me / B + 1);
	cout << ret;
	return 0;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//    cout << fixed << setprecision(15);

    i32 n; cin >> n;
    set<string> ss;
    string s;
    rep(i,n) {
        cin >> s;
        ss.insert(s);
    }

    cout << ss.size() << '\n';


    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


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

int main() {
  int N;
  cin>>N;
  vector<int> p(N);
for (int i = 0; i < N; i++) {
  cin >> p.at(i);
}
  int Z=0,a=0;
  for(int i=1;i<N;i++){
    if(p.at(i-1)>=p.at(i)){
      a++;
    }
    else{
      Z=max(Z,a);
      a=0;
    }
  }
  cout<<max(Z,a)<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>

using namespace std;

int n, q;
string s;
int g[200005] = { 0 };
char t[200005], d[200005];
vector<int> idx[26];

int after(int x) {
    for (int i = 0; i < q; ++i) {
        if (s[x] == t[i]) {
            if (d[i] == 'R') ++x;
            if (d[i] == 'L') --x;
        }
        if (x < 0 || x >= n) {
            return x;
        }
    }
    return x;
}

int main() {
    cin >> n >> q >> s;
    for (int i = 0; i < q; ++i) {
        cin >> t[i] >> d[i];
    }
    int ll, rr;
    if (after(0) >= 0) {
        ll = 0;
    } else if (after(n - 1) < 0) {
        ll = n;
    } else {
        int l = 0, r = n - 1, m;
        while (abs(l - r) > 1) {
            m = (l + r) / 2;
            if (after(m) < 0) {
                l = m;
            } else {
                r = m;
            }
        }
        ll = r;
    }
    if (after(0) > n - 1) {
        rr = 0;
    } else if (after(n - 1) < n) {
        rr = n;
    } else {
        int l = 0, r = n - 1, m;
        while (abs(l - r) > 1) {
            m = (l + r) / 2;
            if (after(m) <= n - 1) {
                l = m;
            } else {
                r = m;
            }
        }
        rr = r;
    }
    cout << rr - ll << endl;
}


Measured memory_bytes: 1020
import java.util.*;

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

        String c1 = sc.next();
        String c2 = sc.next();
        String c3 = sc.next();

        System.out.println(c1.substring(0,1) + c2.substring(1,2) + c3.substring(2,3));
    } 
}

Measured memory_bytes: 22732
#include    <stdio.h>

int main(void)
{
  int a, b, c, i = 0;

  scanf("%d %d %d", &a, &b, &c);
  
  while (a <= b) {
    if (c % a == 0) i++;
    a++;
  }
  printf("%d\n", i);
  
  return 0;
}

Measured memory_bytes: 596
//IOI 2021

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

#define pb push_back
#define ff first
#define ss second

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

const int MAXN = 3  * 100 * 1000 + 17;

int n, x, a[MAXN], t = 1;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> x;
	if (x == 2 * n - 1 || x == 1) {
		cout << "No";
		return 0;
	}
	a[n] = x;
	for (int i = n + 1; i <= 2 * n - 1; i++) {
		if (t == x)
			t++;
		a[i] = t;
		t++;
	}
	for (int i = 1; i < n; i++) {
		if (t == x)
			t++;
		a[i] = t, t++;
	}
	cout << "Yes" << endl;
	for (int i = 1; i <= 2 * n - 1; i++)
		cout << a[i] << endl;
	return 0;
}


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

int main(){
  int n,m,p;
  while(cin>>n>>m>>p && n+m+p){
    int sum=0;
    int correct=0;
    for(int i=0;i<n;i++){
      int input;
      cin>>input;
      sum+=input;
      if(i+1==m) correct=input;
    }
    sum=sum*(100-p);
    if(correct==0)
      cout<<0<<endl;
    else
      cout<<sum/correct<<endl;

  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <map>

using namespace std;

int main(void) {
    int n, m;
    map<string, int> mymap;
    cin>>n;
    for (int i=0; i<n; ++i) {
        string s;
        cin>>s;
        mymap[s] += 1;
    }
    cin>>m;
    for (int i=0; i<m; ++i) {
        string s;
        cin>>s;
        if (mymap.find(s) != mymap.end()) {
            mymap[s] = max(mymap[s]-1, 0);
        }
    }

    int val = 0;
    for (auto it = mymap.begin(); it != mymap.end(); ++it) {
        val = max(val, it->second);
    }
    cout<<val<<endl;

    return 0;
}


Measured memory_bytes: 888
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        if (a == 7 || a == 5 || a == 3) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 24276