akhauriyash/Code-Regression huggingface dataset:
def n_func(n,mod=10**9+7):
    ans=1
    for i in range(1,n+1):
        ans=(ans*i)%mod
    return ans
def inv_n(n,mod=10**9+7):
    return pow(n,mod-2,mod)
def nPr(n,r,mod=10**9+7):
    ans=n_func(n-r,mod)
    ans=inv_n(ans,mod)
    return ans*n_func(n,mod)%mod
def nCr(n,r,mod=10**9+7):
    ans=n_func(n-r,mod)*n_func(r,mod)%mod
    ans=inv_n(ans,mod)
    return ans*n_func(n,mod)%mod

N,K=map(int,input().split())

mod=10**9+7
for i in range(1,K+1):
    if N-K+1<i or K-1<i-1:
        print(0)
    else:
        print((nCr(N-K+1,i)*nCr(K-1,i-1))%mod)

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;

#define sz(a) int((a).size())
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ini(a, i) memset(a, i, sizeof(a))
#define inin(a, n, i) memset(a, i, sizeof(a[0])*(n))
#define contains(c, i) ((c).find(i) != (c).end())
#define present(i, c) (find(all(c), i) != (c).end())

#define trav(x, c) for(auto& x : c)
#define rep(i, n) for(int i = 0; i < n; i++)
#define repa(i, b, e) for(int i = (b)-((b)>(e)); i != (e)-((b)>(e)); i += 1-2*((b)>(e)))
	
template<class T> bool chkmax(T &x, T y) { return x < y ? x = y, true : false; }
template<class T> bool chkmin(T &x, T y) { return x > y ? x = y, true : false; }
template<class A, class B> A cvt(B x) { stringstream s; s << x; A r; s >> r; return r; }

void read() {}
void print() {}
template<class T, class... Args> void read(T& a, Args&... args) { cin >> a; read(args...); }
template<class T, class... Args> void print(T a, Args... args) { cout << a << ' '; print(args...); }
template<class... Args> void println(Args... args) { print(args...); cout << '\n'; }

#define debug(args...) { string s_(#args); replace(all(s_), ',', ' '); stringstream ss_(s_); istream_iterator<string> it_(ss_); cerr_(it_, args); }
void cerr_(istream_iterator<string> it) { (void) it; }
template<class T, class... Args> void cerr_(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; cerr_(++it, args...); }

template<class T, class S>  ostream& operator<<(ostream& os, const pair<T, S>& p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<class T> ostream& operator<<(ostream &os, const set<T> &s) { os << '{'; string sep; for (const auto &x : s) os << sep << x, sep = ", "; return os << '}'; }
template<class T, class S> ostream& operator<<(ostream &os, const map<T, S> &m) { os << '{'; string sep; for (const auto &x : m) os << sep << x, sep = ", "; return os << '}'; }
template<class T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }

const int INF = 0x3F3F3F3F;
const int MAXN = (int) 1e6;
const int MOD = (int) 1e9+7;

//=========================

void run_test() {
    vll a(2), b(2);
    rep(i, 2) read(a[i]);
    rep(i, 2) read(b[i]);
    ll ans = LLONG_MIN;
    rep(i, 2) rep(j, 2) chkmax(ans, a[i] * b[j]);
    println(ans);
}

//=========================

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//int t_ = 1, t__; cin >> t__; while(t_ <= t__) { cout << "Case #" << t_++ << ": "; run_test(); }
	// int t_; cin >> t_; while(t_--) run_test();
	run_test();
	return 0;	
}


Measured memory_bytes: 3652
M = 10 ** 6
e = 10 ** 3

# the sieve of Eratosthenes
primes = [True] * (M + 1)
primes[0] = False
primes[1] = False
for i in range(2, e):
    if primes[i]:
        for j in range(i * 2, M + 1, i):
            primes[j] = False

X = int(input())

print(X + primes[X:].index(1))

Measured memory_bytes: 18804
#include <iostream>
#include <string>
using namespace std;
string S,T;
int q,a,b,c,d,s[100010] = {0},t[100010] = {0};

int main(){
	cin  >> S >> T;
	for(int i=1;i<=S.size();i++){
		if(S[i-1]=='A') s[i] = s[i-1]+1;
		else s[i] += s[i-1]+2;
	}
	for(int i=1;i<=T.size();i++){
		if(T[i-1]=='A') t[i] = t[i-1]+1;
		else t[i] += t[i-1]+2;
	}
	cin >> q;
	for(int i=0;i<q;i++){
		cin >> a >> b >> c >> d;
		int u = s[b]-s[a-1],v = t[d]-t[c-1];
		if(u%3==v%3) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

#define debug(x) (cerr << #x << " = " << x << endl;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

vector<int>v[3];

int idx(char x)
{
  if(x == 'R')
    return 0;
  else if(x == 'G')
    return 1;
  else
    return 2;
}

map<pair<int,int>, bool> mapa;

int main()
{
  ios::sync_with_stdio(0);
  int n;
  string s;
  cin >> n >> s;
  for(int i = 0; i < n ; i++)
  {
    v[idx(s[i])].push_back(i);
    mapa[{idx(s[i]), i}] = true;
  }
  ll ans = 0;
  for(int i = 0; i < n; i++)
  {
    for(int j = i + 1; j < n; j++)
    {
      if(s[i] != s[j])
      {
        int id = -1;
        for(int k = 0; k < 3; k++)
        {
          if(k != idx(s[i]) && k != idx(s[j]))
            id = k;
        }

        auto it = upper_bound(v[id].begin(), v[id].end(), j);
        if(it == v[id].end())
          continue;
        ans += v[id].size() - (it - v[id].begin());
        int d = j - i;
        if(mapa.count({id, j + d}))
          ans--;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3812
#include <iostream>
#include <iomanip>
#include <cstdint>
#include <cmath>
#include <climits>
#include <cassert>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <memory>

#ifdef max
#undef max
#endif
#ifdef min
#undef min
#endif

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

using namespace std;

template<class T, class U>
istream& operator>>(istream& is, pair<T, U>& pair)
{
    is >> pair.first >> pair.second;
    return is;
}

template<class T>
istream& operator>>(istream& is, T& collection)
{
    for(auto& item : collection) is >> item;
    return is;
}

void solution()
{
    int n,k;
    cin >> n >> k;
    vector<int> ps(n);
    cin >> ps;
    int64_t sum = 0;
    for(int i = 0; i < k; ++i){
        sum += ps[i];
    }
    int64_t maxsum = sum;
    for(int i = k; i < n; ++i){
        sum = sum + ps[i] - ps[i-k];
        maxsum = max(maxsum, sum);
    }
    cout << fixed << setprecision(1) << ((k + maxsum) * 0.5) << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solution();
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<cctype>

using namespace std;

map<vector<int>,string> vton;
map<string,vector<int> > ntov;
char formula[101];
map<string,string> varton;
char *p;

vector<int> f();
vector<int> term();
vector<int> factor();

vector<int> f(){
  auto l=term();
  while(*p=='+'||*p=='-'){
    p++;
    auto r=term();
    if(l!=r)throw 0;
  }
  return l;
}

vector<int> term(){
  auto l=factor();
  while(*p=='*'||*p=='/'){
    int f=(*p=='*')?1:-1;
    p++;
    auto r=factor();
    for(int i=0;i<r.size();i++){
      l[i]+=f*r[i];
    }
  }
  return l;
}

vector<int> factor(){
  if(*p=='('){
    p++;
    auto l=f();
    p++;
    return l;
  }else{
    string s;
    while(isalpha(*p)){
      s+=*p++;
    }
    return ntov[varton[s]];
  }
}

int main(){
  for(int n,m,p;cin>>n>>m>>p,n;){
    vton.clear();
    while(m--){
      string d;
      cin>>d;
      vector<int> vd(n);
      for(int i=0;i<n;i++){
	cin>>vd[i];
      }
      vton[vd]=d;
      ntov[d]=vd;
    }
    cin>>formula;
    while(p--){
      string v,D;
      cin>>v>>D;
      varton[v]=D;
    }
    try{
      ::p=formula;
      auto r=f();
      cout<<(vton.count(r)?vton[r]:"undefined")<<endl;
    }catch(...){
      cout<<"error"<<endl;
    }
  }
}

Measured memory_bytes: 2484
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = b[a[0] - 1]
for i in range(1, n):
    ans += b[a[i] - 1]
    if a[i - 1] + 1 == a[i]:
        ans += c[a[i - 1] - 1]
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
typedef struct{
  int index;
  int value;
} Diff;
int main() {
  int N,i;
  scanf("%d", &N);
  int p[N],diffnum=0;
  Diff diff[N];
  for(i=0;i<N;i++){
    scanf("%d", &p[i]);
    if(p[i]!=i+1){
      diff[diffnum].index=i;
      diff[diffnum].value=p[i];
      diffnum++;
    }
  }
  if(diffnum==0){
    printf("YES\n");
  }
  else if(diffnum==2){
    if(diff[0].index+1==diff[1].value && diff[1].index+1==diff[0].value){
      printf("YES\n");
    }
    else{
      printf("NO\n");
    }
  }
  else{
    printf("NO\n");
  }
  
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<climits>
#include<map>
#define ll long long
using namespace std;
int main() {
	string s;
	cin >> s;
	sort(s.begin(), s.end());
	if (s[0] != 'a') {
		cout << 'a' << endl;
	}
	else {
		for (ll i = 0; i < s.size() - 1; i++) {
			if (s[i] + 1 < s[i + 1]) {
				cout << (char)(s[i] + 1) << endl;
				exit(0);
			}
		}
		set<ll>x;
		for (ll i = 0; i < s.size(); i++) {
			x.insert(s[i]);
		}
		if (x.size() == 26) {
			cout << "None" << endl;
		}
		else {
			cout << (char)(s[s.size()-1]+1) << endl;
		}

	}
}


Measured memory_bytes: 512
# writer解(c++)を写経した．answerのfor文のところ何やってるかさっぱりわかりませんが…
# https://atcoder.jp/contests/m-solutions2020/submissions/15122924
import sys
input = sys.stdin.readline
INF = 10**13


def main():
    N = int(input())
    T = [[int(i) for i in input().split()] for j in range(N)]
    X_dist = [[0]*N for _ in range(1 << N)]
    Y_dist = [[0]*N for _ in range(1 << N)]

    # bitという道路群を建設したときの，各集落の評価距離
    # bit 001001 とかの1が立っている集落に道を作る
    for bit in range(1 << N):
        cur_x = [0]
        cur_y = [0]
        for i in range(N):
            if bit & (1 << i):
                cur_x.append(T[i][0])
                cur_y.append(T[i][1])
        for i, (x, y, p) in enumerate(T):
            X_dist[bit][i] = p*min(abs(cx - x) for cx in cur_x)
            Y_dist[bit][i] = p*min(abs(cy - y) for cy in cur_y)

    # これはなに？
    answer = [INF] * (N+1)
    for i in range(1 << N):
        cnt = 0
        for j in range(N):
            if (i >> j) & 1:
                cnt += 1
        j = i
        while j >= 0:
            j &= i
            cost = 0
            for k in range(N):
                if not((i >> k) & 1):
                    cost += min(X_dist[j][k], Y_dist[i - j][k])
            answer[cnt] = min(answer[cnt], cost)
            j -= 1

    for ans in answer:
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 88536
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> c(m), t(n+1);
  rep(i, m) cin >> c[i];
  rep(i, n+1) t[i] = INF;
  t[0] = 0;
  rep(i, m) {
    rep(j, n-c[i]+1) {
      t[j+c[i]] = min(t[j+c[i]], t[j] + 1);
    }
  }
  cout << t[n] << endl;


  
  return 0;
}


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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    int X, A, B;
    cin >> X >> A >> B;
    cout << (X - A)%B << endl;
    return 0;
}


Measured memory_bytes: 256
"use strict";

function main(arg) {
    const N = arg.split("\n")[0];
    const S = N.split("").map(n=>parseInt(n)).reduce((m,n)=>m+n);
    console.log(N % S === 0 ? "Yes" : "No");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7496
s = input().split('T')
X, Y = map(int, input().split())

x = [len(i) for i in s[0::2]]
y = [len(i) for i in s[1::2]]

X = X - x[0]

x, y = sorted(x[1:]), sorted(y)

while x:
    mx = x.pop()
    if X < 0:
        X += mx
    else:
        X -= mx

while y:
    my = y.pop()
    if Y < 0:
        Y += my
    else:
        Y -= my

print('Yes' if X == 0 and Y == 0 else 'No')


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    int n,ans;
    cin >> n;
    if(!n*25%27)cout << n*25/27;
    else{
        if((n*25/27)*27/25==n)cout << n*25/27;
        else if((n*25/27+1)*27/25==n)cout << n*25/27+1;
        else cout << ":(" << endl;
    }
}
    


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

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//        StringTokenizer st = new StringTokenizer(br.readLine());

        String s = br.readLine();

        int a = s.indexOf("A");
        int z = s.lastIndexOf("Z");

        System.out.println(z-a+1);

    }


}


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

using namespace std;

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

#define INF 2<<29
#define F first
#define S second

int main(){
  ll n;
  ll a[100005];
  ll row=0;
  ll col=0;
  
  scanf("%lld",&n);
  for(ll i=0;i<n;i++){
    scanf("%lld",&a[i]);
  }

  sort(a,a+n,greater<ll>());
  
  for(ll i=0;i<n-1&&col==0;i++){
    if(a[i]==a[i+1]){
      if(row!=0){
	col=a[i];
      }else{
	row=a[i];
	i++;
      }
    }
  }
  
  printf("%lld\n",row*col);

  return (0);
}

Measured memory_bytes: 1024
import numpy as np

h, n = map(int, input().split())
a = []
b = []
for _ in range(n):
  ai, bi = map(int, input().split())
  a.append(ai)
  b.append(bi)
a = np.array(a)
b = np.array(b)
dp = np.zeros(h+1, dtype=np.int)
for c in range(1, h+1):
  dp[c] = np.min(dp[np.maximum(0, c-a)] + b)
print(dp[-1])

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


int main(){

    int A, B, K;
    cin >> A >> B >> K;


    if( 2*K >= B-A+1 ){
        for( int i = A; i <= B; i++ ) cout << i << endl;
    }else{
        for( int i = A; i < A+K; i++ ) cout << i << endl;
        for( int i = B-K+1; i <= B; i++ ) cout << i << endl;    
    }

    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>
#include <deque>

using namespace std;

int main()
{
  int a, b;

  cin >> a >> b;

  if (a == b) {
    cout << "a == b" << endl;
  }
  else if (a > b) {
    cout << "a > b" << endl;
  }
  else {
    cout << "a < b" << endl;
  }

  return 0;
}



Measured memory_bytes: 3092
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	nums := make([]int, n)
	for i:=0; i<n; i++{
		fmt.Scan(&nums[i])
	}

	for i:=len(nums)-1;i>=0; i--{
		fmt.Print(nums[i])

		if i == 0{
			fmt.Print("\n")
		}else{
			fmt.Print(" ")
		}
	}
}


Measured memory_bytes: 1156
def bigcmb(N, R, MOD):
    if (R < 0) or (N < R):
        return 0
    R = min(R, N - R)
    fact, inv = 1, 1
    for i in range(1, R + 1):
        fact = (fact * (N - i + 1)) % MOD
        inv = (inv * i) % MOD
    return fact * pow(inv, MOD - 2, MOD) % MOD

X, Y = map(int, input().split())
if (X + Y) % 3 != 0:
    print(0)
    exit()

mod = 10**9 + 7
count = (X + Y) // 3
ans = bigcmb(count, X - count, mod)
print(ans)

Measured memory_bytes: 63168
#include<bits/stdc++.h>
#define endl '\n'
#define debug(x) cerr<<#x<<"="<<x<<endl
using namespace std;
typedef long long ll;
#define int ll
int blalbalba=6985;
const int mn=3000+100;

vector<int> adj[mn];
int a[mn];
int n;
int mark[mn],state[mn];
int h[mn];

bool go(int v=0){
	mark[v]=1;
	bool ret=0;
	for(int u:adj[v]){
		if(a[u]<a[v]){
			a[v]--;
			ret=ret||(!go(u));
			a[v]++;
		}
	}
	mark[v]=0;
	return ret;
}

main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n;
	memset(state,-1,sizeof state);
	//debug(state[0]);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n-1;i++){
		int u,v;
		cin>>u>>v;
		u--,v--;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	//debug(2);
	for(int i=0;i<n;i++){
		bool f=go(i);
		if(f)
			cout<<i+1<<" ";
	}
	cout<<endl;
	return 0;
}


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

int main(){
    std::string stra,strb,strc;
    std::cin >> stra >> strb >> strc;
    
    //char a_s = stra[0];
    char a_e = stra[stra.size()-1];
    char b_s = strb[0];
    char b_e = strb[strb.size()-1];
    char c_s = strc[0];
    //char c_e = stra[stra.size()-1];

    if((a_e==b_s) && (b_e==c_s)){
        std::cout << "YES" << std::endl;
    }
    else{
        std::cout << "NO" << std::endl;
    }

    return 0;
}

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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b)
{
	return b ? gcd(b, a % b) : a;
}
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

void printVec(vector<int> &vec)
{
	for (auto &e : vec)
	{
		cout << e << " ";
	}
	cout << endl;
}

int func(std::string S)
{
	// cout << fixed << setprecision(8);

	return 0;
}

int main()
{
	string S;
	cin >> S;
	int len = (signed)S.size();

	int ans = 0;
	for (int i = 0; i < len / 2; i++)
	{
		if (S[i] != S[len - i - 1])
		{
			ans++;
		}
		// cout << S[i] << S[len - i] << endl;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
S = list(input())
q = int(input())
procedure = [list(input().split()) for i in range(q)]

cnt = 0
S2 = []

for i in range(q):
    if procedure[i][0] == '1':
        cnt += 1
    if procedure[i][0] == '2':
        if (procedure[i][1] == '1' and cnt%2 == 0) or (procedure[i][1] == '2' and cnt%2 == 1):
            S2.append(procedure[i][2])
        else:
            S.append(procedure[i][2])

S2.reverse()
S = S2 + S
if cnt%2 == 1:
    S.reverse()

print(''.join(S))

Measured memory_bytes: 34572
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long k = sc.nextLong();
        int[] a = new int[n];
        int[] f = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            f[i] = sc.nextInt();
        }
        Arrays.sort(a);
        Arrays.sort(f);
        long[][] b = new long[n][2];
        long tmp = 0;
        for (int i = 0; i < n; i++) {
            b[i][0] = (long)a[i];
            b[i][1] = (long)f[n-1 -i];
            long t = b[i][0] * b[i][1];
            if(tmp < t) tmp = t;
        }
        long l = -1L;
        long r = tmp;
        while(l < r){
            long m = (l+r)/2L;
            long c = 0L;
            for (int i = 0; i < n; i++) {
                long d = b[i][0] - (m / b[i][1]);
                c += 0 < d ? d : 0;
            }
            if(k < c){
                if(l == m) break;
                l = m;
            }else{
                if(r == m) break;
                r = m;
            }
        }
        System.out.println(r);
        sc.close();

    }

}


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

int main(){
	int a, b;
	while(cin >> a >> b){
		if(a+b == 0)
			cout << 1 << endl;
		else {
			int num = 0;
			for(int i = a+b; i > 0; i /= 10){
				num++;
			}
			cout << num << endl;
		}
	}
    return 0;
}


Measured memory_bytes: 3028
#include <bits/stdc++.h>
using namespace std;
#define speedio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif

#define ll         long long
#define int        long long
#define pb         push_back
#define ff         first
#define sec        second
#define eb         emplace_back
#define SORT(a)      sort(a.begin(),a.end())
#define SORTR(a)     sort(a.rbegin(),a.rend())
#define all(x)       x.begin(),x.end()
#define sz(v)        ((int)(v.size()))
#define mem(a,val)   memset(&a,val,sizeof(a))
#define mid(s,e)     ((s)+((e)-(s))/2)
#define endl       '\n'


typedef vector<int>     vi;
typedef vector<bool>    vb;
typedef vector<vi>      vvi;
typedef vector<string>  vs;

typedef pair<int, int>  pii;
typedef vector< pii >   vpii;

#define fo(i,a,b)     for(ll i = (int)(a); i <= (int)(b); ++i)
#define fr(i,b)       for(ll i = (int)0; i < (int)(b); ++i)
#define rf(i,a,b)     for(ll i = (ll)(a); i >= (ll)(b); --i)
#define read(a,n)     for(int i=0;i<n;++i)cin>>a[i];
#define show(a,n)     for(int i=0;i<n;++i)cout<<a[i]<<' ';cout<<endl;

const int MOD = 1e9 + 7 ;
const int INF = 1e18    ;


void add(ll &x, ll y) { x += y; if (x >= MOD) x -= MOD; if (x < 0) x += MOD; }

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;


void solve() {

	int x ; cin >> x ;

	if (x >= 30) cout << "Yes" << endl;
	else cout << "No" << endl;

}


int32_t main() {
	speedio; cout << fixed << setprecision(12);
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif*/

	int T = 1; //cin>>T;
	while (T--) {
		solve();
	}

	return 0;
}


Measured memory_bytes: 3652
from collections import deque

n, m = map(int, input().split())
rooms = [[] for i in range(n + 1)]

for i in range(m):
    a, b = map(int, input().split())
    rooms[a].append(b)
    rooms[b].append(a)

q = deque()
q.append(1)
signs = [-1]*(n + 1)
signs[1] = 0

while q:
    rnum = q.popleft()
    for i in rooms[rnum]:
        if signs[i] == -1:
            signs[i] = rnum
            q.append(i)

print("Yes")

for i in signs[2:]:
    print(i)

Measured memory_bytes: 35116
n, d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        kyori = 0
        for k in range(d):
            kyori += (x[i][k] - x[j][k]) ** 2
        kyori **= 0.5
        if kyori == int(kyori):
            ans += 1
print(ans)

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

int main(){
    int N, A, B;
    cin >> N >> A >> B;
    if(A>B) swap(A,B);

    if((B-A)%2==0){
        cout << "Alice" << endl;
    }else{
        cout << "Borys" << endl;
    }
}


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

using namespace std;

char s[100005];
int main() {
    scanf("%s", s);
    int n = strlen(s);
    for (int i = 1; i < n; ++i) {
        if (s[i] == s[i - 1]) {
            printf("%d %d\n", i - 1 + 1, i + 1);
            return 0;
        } else if (i - 2 >= 0 && s[i] == s[i - 2]) {
            printf("%d %d\n", i - 2 + 1, i + 1);
            return 0;
        }
    }

    printf("-1 -1 \n");
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
//#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
//cerr
using namespace std;
signed main() {
	int ans = 0, a, b; cin >> a >> b;
	while (a) {
		ans++; a /= b;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class ABC142
{
    static void Main(string[] args)
    {

        var s = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int n = s[0];
        int k = s[1];

        var h = Console.ReadLine().Split().Select(int.Parse).ToArray();

        Console.WriteLine(h.Count(x => x >= k));

    }
}

Measured memory_bytes: 19040
#include<bits/stdc++.h>
//macros
using namespace std;
typedef long long ll;
#define pb push_back
#define rep(i, a, b) for(ll i=(a); i<(b); i++)

int main(){
    ll N, res=0;
    cin >> N;
    rep(i,0,N) res+=i;
    cout << res << endl;
}

Measured memory_bytes: 256
x = []

for _ in range(10000):
    num = int(input())
    if num == 0:
        break
    else:
        x.append(list(str(num)))

for i in range(len(x)):
    y = 0
    for j in range(len(x[i])):
        y += int(x[i][j])
    print(y)


Measured memory_bytes: 5624
#include<stdio.h>
int main()
{
    int n,i;
    scanf("%d",&n);
    long long s=0;
    for(i=1;i<=n;i++)
    {
    	if(i%3==0 || i%5==0)
    	{
    		continue;
    	}
    	else
    	{
    		s=s+i;
    	}
    	// printf("%lld\n",s);
    }
    printf("%lld\n",s);
    return 0;   	
}


Measured memory_bytes: 1712
#include<stdio.h>
int main(void) 
{
    int a, b, c,i,yakusuu,sum;

    sum = 0;

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

    for (i = a;i <= b;i++)
    {
        yakusuu = c % i;

        if (yakusuu == 0)
        {
            sum++;
        }
        
    }

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


Measured memory_bytes: 2104
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <type_traits>
#include <map>


using namespace std;




int main(int argc, const char * argv[]) {
  // input from txt （提出時にこの箇所は削除すること）
  std::ifstream in("input.txt");
  std::cin.rdbuf(in.rdbuf());
  
  cin.tie(0);
  ios::sync_with_stdio(false);

  double water, sugar;
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  if(e == 0){
    cout << min(a*100,b*100) << " 0" << endl;
    return 0;
  }

  double mdense = 0;
  double mwater = 0, msugar = 0;
  for(int i = 0; i <= f/(a*100); i++){
    for(int j = 0; j <= f/(b*100); j++){
      for(int k = 0; k <= f/c; k++){
        for(int l = 0; l <= f/d; l++){
          water = i*a*100 + j*b*100;
          sugar = k*c + l*d;
          //cout << tmp_dense << "," << ldense <<endl;
          if(water > 0 && sugar > 0){
            double tmp_dense = sugar/water;
            if(water + sugar <= f && tmp_dense <= e/100.0){
            //cout << i << "," << j << "," << k << "," << l <<endl;
              if(tmp_dense > mdense){
                mdense = tmp_dense;
                mwater = water;
                msugar = sugar;
              }
            }
          }
        }
      }
    }
  }
  if(mdense == 0.0){
    cout << min(a*100,b*100) << " 0" << endl;
    return 0;
  }
  cout << (int)(mwater+msugar) << " " << (int)msugar << endl;
  return 0;
}


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

typedef pair<int,int>pii;
#define MOD 1000000007
#define MAXN 100005
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ll long long
#define pb push_back
#define f first
#define s second
#define debug(x) cout << "debug 1: " << x << "\n";
#define debug2(x, y) cout << "debug 2: " << x << " " << y << "\n";
#define debug3(x, y, z) cout << "debug 3: " << x << " " << y << " " << z << "\n";


int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    unsigned long long  n,k;
    cin>>n>>k;

    n=n%k;
    n=min(n,k-n);
    cout<<n;



}

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

int main()
{

	
		
	ll a, b, c ,k, k1 ;
	cin >> a >> b >> c >> k;
	k1 = k ;
	ll ans = 0 ;
	if(k <= a)
	{
		ans = k ; 
		cout << k ;
		return 0 ;
	}
	else
	{
		ans += a ;
		k1 -= a ;
		if(b -k1 >= 0)
		{
			cout << a ;
			return 0;
		}

		k1 -= b ;

		cout << a - k1 ;
	}
	return 0 ;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define all(_v) _v.begin(), _v.end()
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pvllvll pair <vector <ll>, vector <ll> >
#define ld long double
#define veci vector <int>
#define vecll vector <ll>

const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;

void solve() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    while(b <= a) b *= 2, k--;
    while(c <= b) c *= 2, k--;
    ///cout << a << ' ' << b << ' ' << c << ' ' << k << ' ';
    if(k >= 0 && a < b && b < c) cout << "Yes";
    else cout << "No";
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
    ///cin >> t;
    while(t--) solve(), cout << '\n';
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <iterator>

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

inline int ctoi(char c) {
    return (int)(c -'0');
}

// ----------------------------------------------------------

int main() {
    string s;
    cin >> s;
    if (s[0] != 'A') {
        cout << "WA" << endl;
        return 0;
    }
    const int n = s.length();
    bool c_flag = false;
    for(int i = 1; i < n; ++i) {
        const char temp = s[i];
        if (temp == 'C') {
            if (c_flag) {
                c_flag = false;
                break;
            }
            if (2 <= i && i <= n - 2) {
                c_flag = true;
                continue;
            }
        }
        if ('a' <= temp && temp <= 'z') {
            continue;
        }
        c_flag = false;
        break;
    }
    cout << (c_flag ? "AC" : "WA") << endl; 
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(
					System.in));
			StringBuilder sb = new StringBuilder();

			int[][] house = new int[12][10];

			for (int[] rooms : house) {
				for (int room : rooms) {
					room = 0;
				}
			}

			int n = Integer.parseInt(br.readLine());
			String[] strs;

			for (int i = 0; i < n; i++) {
				strs = br.readLine().split("\\s");
				house[(Integer.parseInt(strs[0]) - 1) * 3
						+ Integer.parseInt(strs[1]) - 1][Integer
						.parseInt(strs[2]) - 1] += Integer.parseInt(strs[3]);
			}

			for (int i = 0; i < house.length; i++) {
				for (int j = 0; j < house[i].length; j++) {
					if (j != 0 || j != house[i].length - 1)
						sb.append(" " + house[i][j]);
				}
				sb.append("\n");
				if (i != 0 && i != house.length - 1 && (i + 1) % 3 == 0)
					sb.append("####################\n");
			}
			System.out.print(sb);
			br.close();
		} catch (Exception e) {
			System.err.println(e);
		}
	}
}

Measured memory_bytes: 19240
a = int(input())
b = int(input())
if a == 1:
    if b == 2:
        print(3)
    else:
        print(2)
elif a == 2:
    if b == 1:
        print(3)
    else:
        print(1)
else:
    if b == 1:
        print(2)
    else:
        print(1)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
#include <memory>
using namespace std;
typedef long long LL;
//#define _USE_MATH_DEFINES

int main(void) {
	LL n, e1 = 0, w1 = 0, e2 = 0, w2 = 0, ans = 0, mi = 30000000;
	string s;
	cin >> n;
	cin >> s;

	for (LL i = 0; i < n; i++) {
		if (s[i] == 'E')e1++;
		if (s[i] == 'W')w1++;
	}

	for (LL i = 0; i < n; i++) {
		ans = 0;

		
		if (s[i] == 'E') {
			e2++;
			ans += w2;
			ans += e1 - e2;
		}
		else {
			ans += w2;
			ans += e1 - e2;
			w2++;
		}
		mi = min(mi, ans);
	}

	cout << mi << endl;


	return 0;
}

Measured memory_bytes: 900
main :: IO ()
main = do
  [a, b, c, k] <- map read . words <$> getLine
  print $ solve a b c k

solve :: Int -> Int -> Int -> Int -> Int
solve 0 0 _ k = -k
solve 0 b c k
  | b > k     = 0
  | otherwise = solve 0 0 c (k - b)
solve a b c k
  | a > k     = k
  | otherwise = a + solve 0 b c (k - a)


Measured memory_bytes: 3908
N, M = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
A.sort()
su = 0
mo = 0
cnt = 0
for i in range(N):
  if M <= su + A[i][1]:
    break
  else:
    su += A[i][1]
    mo += A[i][0]*A[i][1]
    cnt += 1
print(mo + (M-su)*A[cnt][0])

Measured memory_bytes: 27756
#include <iostream>
using namespace std;
int n, a[50];

bool check()
{
    for (int i = 1; i < n; ++i)
        if (a[i - 1] + 1 != a[i])
            return 0;
    return 1;
}

int main()
{
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    if (check())
        return (cout << "YES" << endl, 0);
    for (int i = 0; i < (n - 1); ++i)
        for (int j = i + 1; j < n; ++j)
        {
            int c = a[i];
            a[i] = a[j];
            a[j] = c;
            if (check())
                return (cout << "YES" << endl, 0);
            c = a[i];
            a[i] = a[j];
            a[j] = c;
        }
    cout << "NO" << endl;
    return 0;
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n,t[100000],a[100000],memo[100000],limit[100000],ans=1;

signed main() {
    cin >> n;
    rep(i,n) memo[i] = -1, limit[i] = INF;
    rep(i,n) cin >> t[i], limit[i] = min(limit[i], t[i]);
    rep(i,n) cin >> a[i], limit[i] = min(limit[i], a[i]);
    memo[0] = t[0];
    memo[n-1] = a[n-1];
    rep11(i,n) if (t[i] != t[i-1]) memo[i] = t[i];
    repm(i,n-1) if (a[i+1] != a[i]) memo[i] = a[i];
    rep(i,n) if (memo[i] == -1) ans = (ans*limit[i])%MOD;
    rep(i,n) if (memo[i] != -1 && memo[i] != min(a[i], t[i])) {
        cout << 0 << endl;
        return 0;
    }
    if (a[0] != t[n-1]) cout << 0 << endl;
    else cout << ans << endl;
}




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

int main() {
	int n;
	cin >> n;
	n = n % 100;
	n = n % 10;
	if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9) {
		cout << "hon";
	}
	else if (n == 0 || n == 1 || n == 6 || n == 8) {
		cout << "pon";
	}
	else {
		cout << "bon";
	}
	return 0;
}

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

int main(){
  int N;
  cin>>N;
  int num,a,b,c;
  a=b=c=0;
  for(int i=0;i<N;i++){
    cin>>num;
    num%=4;
    if(num==0) a++;
    else if(num==2) b++;
    else c++;
  }
  if(b>=2&&a>=(N-b+1)/2) cout<<"Yes"<<endl;
  else if(a>=N/2) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
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;
const int INF_N = 1e+9;
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++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    ll K, A, B; cin >> K >> A >> B;
    if(K <= A){
        cout << K+1 << endl;
        return;
    }
    if(B-A > 2){
        cout << (B-A)*((K-A+1)/2) + (K-A+1)%2 + A << endl;
    }else{
        cout << K+1 << endl;
    }
}

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


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

int main(){
  long long a, b, tmp, r;
  cin >> a >> b;
  
  long long A = a;
  long long B = b;
  
  if(A < B) {
    tmp = A;
    A = B;
    B = tmp;
  }
  
  r = A % B;
  while(true){
    if(r == 0) {
      break;
    }
    
    A = B;
    B = r;
    r = A % B;
  }

  cout << a * b / B << endl;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val ab = (1..n).map { Pair(sc.nextInt(), sc.nextInt()) }

  val sort = ab.sortedBy { it.second }

  var ok = true
  var sum = 0L
  for (abi in sort) {
    val a = abi.first
    val b = abi.second

    sum += a
    if (sum > b) {
      ok = false
      break
    }
  }

  if (ok) {
    println("Yes")
    return
  }

  println("No")

}

Measured memory_bytes: 77784
def main():
    n = int(input())
    s = input()

    rs = []
    gs = []
    bs = {}
    for i in range(n):
        if s[i] == "R":
            rs.append(i)
        elif s[i] == "G":
            gs.append(i)
        else:
            bs.setdefault(i, 1)

    cnt = 0

    for ri in rs:
        for gi in gs:
            df = abs(gi - ri)
            rr = max(gi, ri) + df
            ll = min(gi, ri) - df
            mm = -1
            if df % 2 == 0:
                mm = int((gi + ri) / 2)

            if rr in bs:
                cnt += 1
            if mm in bs:
                cnt += 1
            if ll in bs:
                cnt += 1

    all_cnt = len(rs) * len(gs) * len(bs)

    print(all_cnt - cnt)


main()


Measured memory_bytes: 9300
N = int(input())

h = [i for i in map(int, input().split())]

hmax = max(h)
hmin = min(h)


ans = hmin
for i in range(hmin+1, hmax+1):
    count = 0
    flag = False
    for j in h:
        if j < i and flag:
            flag = False
        elif j >= i and not flag:
            flag = True
            count += 1
    ans += count

print(ans)


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


int CheckHalfCount(int num) {

	int result = 0;
	while (num % 2 == 0)
	{
		result++;
		num /= 2;
	}
	return result;
}

int main() {
	int N;
	cin >> N;
	vector<int> D;
	for (int i = 0; i < N; i++) {
		int num;
		cin >> num;
		D.push_back(num);
	}

	int result = 0;
	for (size_t i = 0; i < D.size(); i++) {
		result += CheckHalfCount(D[i]);
	}

	cout << result << endl;

	return 0;
}

Measured memory_bytes: 384
s = list(input())

output_string = []

for i in range(len(s)):
  if s[i] == '0':
    output_string.append('0')
  elif s[i] == '1':
    output_string.append('1')
  else:
    if output_string:
      del output_string[-1]

print("".join(output_string))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
void ensure(bool exp) {
    if (!exp) {
        cout << -1 << endl;
        exit(0);
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<long long> d(n);
    map<long long, int> ver;
    for (int i = 0; i < n; ++i) {
        cin >> d[i];
        ver[d[i]] = i;
    }
    vector<int> p(n);
    iota(p.begin(), p.end(), 0);
    sort(p.begin(), p.end(), [&](int i, int j) {
        return d[i] < d[j];
    });
    vector<int> sz(n, 1), parent(n, -1);
    vector<long long> f(n);
    for (int i = n - 1; i >= 1; --i) {
        int u = p[i];
        long long dp = d[u] - n + 2 * sz[u];
        ensure(dp < d[u]);
        ensure(ver.count(dp) > 0);
        parent[u] = ver[dp];
        sz[parent[u]] += sz[u];
        f[parent[u]] += f[u] + sz[u];
    }
    ensure(f[p[0]] == d[p[0]]);
    for (int i = 1; i < n; ++i)
        cout << parent[p[i]] + 1 << " " << p[i] + 1 << "\n";
    return 0;
}

Measured memory_bytes: 10368
use std::io::*;//Not mine.
use std::str::FromStr;
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main(){
    let n:i32 = read();
    let y:i32 = read();
    let mut fin:bool = false;
    for i in 0..n + 1{
        for j in 0..n - i + 1 {
            let mut k = y - i * 10000 - j * 5000;
            if k >= 0 && k / 1000 == n - i - j {
                fin = true;
                k /= 1000;
                println!("{} {} {}", i,j,k);
            }
            if fin == true {
                break;
            }
        }
        if fin == true {
            break;
        }
    }
    if fin == false{
    println!("{}","-1 -1 -1");
    }
}

Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  while(1){
    int n,m,i,a;cin>>n>>m>>a;if(n==0)break;
    pair<int,int>w[1000];
    for(i=0;i<m;i++)cin>>w[i].first>>w[i].second>>n;
    sort(w,w+m);
    for(i=m-1;i>=0;i--){
      n=w[i].second;
      if(n==a)a++;
      else if(n+1==a)a--;
    }
    cout<<a<<endl;
  }
  return 0;
}

Measured memory_bytes: 1168
//Abhinav ---IIIT_A
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define f(i,x,n) for(int i=x;i<(int)n;++i)
#define vpii vector<pair<int,int>>
#define vi vector<int>
#define mpii map<pair<int,int>,int>
#define mpivpii map<int,vector<pair<int,int>>>
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define mpi map<int,int>
#define vvi vector<vector<int>>
#define vvvi vector<vvi>
ld pie=3.141592653589;
int mod=1e9+7;


void solve(){
	int n; cin>>n;
	int k=1; cin>>k;
	int a[n]; f(i,0,n) cin>>a[i];
	int cost[n];
	cost[0]=0;
	f(i,1,n){
		int mn=LLONG_MAX;
		for(int j=i-1;j>=0 && (i-j) <= k;--j){
			mn=min(mn,cost[j]+abs(a[i]-a[j]));
		}
		cost[i]=mn;
	}
	cout<<cost[n-1];
}

signed main(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
  int t=1; //cin>>t;
  while(t--) solve();
  return 0;
}
// check for overflows dummy !!!


Measured memory_bytes: 5128