akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
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;
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

using P = pair<ll, ll>;
using Data = pair<ll, P>;

struct edge {
    ll to, cost, time;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m, s;
    cin >> n >> m >> s;
    chmin(s, 2500LL);
    vector<vector<edge>> g(n);
    for(ll i = 0; i < m; i++) {
        ll u, v, a, b;
        cin >> u >> v >> a >> b;
        g[--u].emplace_back(edge{--v, a, b});
        g[v].emplace_back(edge{u, a, b});
    }
    for(ll i = 0; i < n; i++) {
        ll c, d;
        cin >> c >> d;
        g[i].emplace_back(edge{i, -c, d});
    }
    vector<vector<ll>> dp(n, vector<ll>(2525, LLINF));
    dp[0][s] = 0;
    priority_queue<Data, vector<Data>, greater<Data>> que;
    que.push(Data(0LL, P(s, 0LL)));
    while(que.size()) {
        auto now = que.top();
        que.pop();
        ll nd = now.first;
        ll nm = now.second.first;
        ll nv = now.second.second;
        if(nd > dp[nv][nm]) {
            continue;
        }
        for(const auto &e : g[nv]) {
            if(nm - e.cost >= 0) {
                ll t = min(2500LL, nm - e.cost);
                if(dp[e.to][t] > nd + e.time) {
                    dp[e.to][t] = nd + e.time;
                    que.push(Data(dp[e.to][t], P(t, e.to)));
                }
            }
        }
    }
    for(ll i = 1; i < n; i++) {
        ll ans = LLINF;
        for(int j = 0; j <= 2500; j++) {
            chmin(ans, dp[i][j]);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 7304
#include<stdio.h>
#include<iostream>
#include<vector>

using namespace std;

int N;
vector<long long int> a,b;

int main() {
    cin >> N;
    for(int i=0;i<N+1;i++){
        int x;
        cin >> x;
        a.push_back(x);
    }
    for(int i=0;i<N;i++){
        int x;
        cin >> x;
        b.push_back(x);
    }
    long long int stock = 0;
    long long int ans = 0;
    long long int zero = 0;
    for(int i=0;i<N;i++){
        long long int kill = max(a[i] - stock,zero);
        ans += min(a[i],stock) + min(b[i] ,kill);
        stock = max(b[i] - kill,zero);
    }
    cout << ans + min(stock,a[N])<< endl;
    return 0;
}

Measured memory_bytes: 5516
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    if(n>=128)
        cout<<128;
    else if(n>=64)
        cout<<64;
    else if(n>=32)
        cout<<32;
    else if(n>=16)
        cout<<16;
    else if(n>=8)
        cout<<8;
    else if(n>=4)
        cout<<4;
    else if(n>=2)
        cout<<2;
    else if(n==1)
        cout<<1;
    else
        cout<<0;
    return 0;
}


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

int main() {
    int x,n;
    cin>>x>>n;
    vector<int> p(n);
    rep(i,n){
        cin>>p[i];  
    }
    int ans = -150;
    int distance = 100;
    for(int i=-150;i<=150;i++){
        int judge = 0;
        rep(j,n){
            if(i==p[j]){
                judge = 1;
                break;
            }
        }
        int tmp = abs(x-i);
        if(tmp<distance&&judge==0){
            ans = i;
            distance = tmp;
        }
        judge = 0;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3620
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<string.h>

typedef int32_t i32;

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  i32 *x = (i32 *) calloc (n + 1, sizeof (i32));
  for (i32 i = 1; i <= n; ++i) {
    scanf ("%" SCNi32, x + i);
  }
  x[0] = n * n + 1;
  i32 *ans = (i32 *) calloc (n * n + 1, sizeof (i32));
  for (i32 i = 1; i <= n; ++i) {
    ans[x[i]] = i;
  }
  uint8_t *used = (uint8_t *) calloc (n + 1, sizeof (uint8_t));
  for (i32 i = 0; i < n; ++i) {
    i32 min = 0;
    for (i32 j = 1; j <= n; ++j) {
      if (!used[j] && x[min] > x[j]) min = j;
    }
    used[min] = 1;
    i32 k = min - 1;
    for (i32 j = 1; j < x[min] && k > 0; ++j) {
      if (ans[j] > 0) continue;
      ans[j] = min;
      k--;
    }
    if (k > 0) {
      puts ("No");
      return;
    }
  }
  memset (used, 0, sizeof (uint8_t) * (n + 1));
  x[0] = 0;
  for (i32 i = 0; i < n; ++i) {
    i32 max = 0;
    for (i32 j = 1; j <= n; ++j) {
      if (!used[j] && x[max] < x[j]) max = j;
    }
    used[max] = 1;
    i32 k = n - max;
    for (i32 j = n * n; j > x[max] && k > 0; --j) {
      if (ans[j] > 0) continue;
      ans[j] = max;
      k--;
    }
    if (k > 0) {
      puts ("No");
      return;
    }
  }
  puts ("Yes");
  for (i32 i = 1; i <= n * n; ++i) {
    printf ("%" PRIi32, ans[i]);
    putchar (" \n"[i < n * n ? 0 : 1]);
  }
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 2048
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
#from collections import deque,defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
# n = I()
# A = readInts()
# div = sum(A)//2
# nya = 0
# pivot = 0
# for i in range(n):
#     nya += A[i]
#     if nya >= div:
#         pivot = i
#         break
# #print(i)
# print(abs(sum(A[i+1:]) - nya))
n = int(input())
A = readInts()
# 全体の合計
total = sum(A)
mi_ = float('inf')
left = 0
for i in range(n):
    left += A[i]
    total -= A[i]
    mi_ = min(mi_, abs(left - total))
print(mi_)


Measured memory_bytes: 26056
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int n; rd(n);
  auto a=new long[](100);

  a[0]=2; a[1]=1;
  for(int i=2; i<=n; i++){
    a[i]=a[i-1]+a[i-2];
  }

  writeln(a[n]);
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<cstring>
#include<iostream>
#include<cstdio>
#define ull unsigned long long
#define ll long long
const int maxn=100000;
using namespace std;
ll s[1000];
int main()
{ int n,m;
cin>>n>>m;
  int l,r;
  cin>>l>>r;
  m--;
  while(m--)
  {
      int a,b;
      cin>>a>>b;
      l=max(l,a);
      r=min(r,b);
  }//cout<<l<<" "<<r<<endl;
 if(l>r)cout<<0<<endl;
 else cout<<r-l+1<<endl;

}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub 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: usize = read();
    let k: usize = read();
    let mut a: Vec<i64> = vec![];

    for i in 0..n {
        a.push(read());
    }

    a.sort();

    let mut b = vec![];
    for i in 1..a.len() {
        b.push(a[i] - a[i - 1]);
    }
    let mut tmp: i64 = b[..k - 1].iter().sum();
    let mut ans = tmp;
    // println!("tmp:{:?}", tmp);

    for i in k - 1..b.len() {
        let prev = b[i + 1 - k];
        let next = b[i];

        tmp += next;
        tmp -= prev;
        if ans > tmp {
            ans = tmp;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 6396
def solve
  n, m = gets.split.map!(&:to_i)
  h = gets.split.map!(&:to_i)
  ab = []
  ma = []
  ans = 0

  (0..(m - 1)).each do |i|
    ab[i] = gets.split.map!(&:to_i)
  end

  (0..(n - 1)).each do |i|
    ma[i] = 0
  end

  (0..(m - 1)).each do |i|
    ma[ab[i][0] - 1] = h[ab[i][1] - 1] if ma[ab[i][0] - 1] <= h[ab[i][1] - 1]
    ma[ab[i][1] - 1] = h[ab[i][0] - 1] if ma[ab[i][1] - 1] <= h[ab[i][0] - 1]
  end

  (0..(n - 1)).each do |i|
    ans += 1 if h[i] > ma[i]
  end

  print ans
end
solve

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

ll a[400],sum[400][400],dp[400][400];

ll solve(int i, int j){
    // base case
    if(i==j){
        return 0;
    }
    if(dp[i][j]!=-1)
        return dp[i][j];
    ll ans=(1LL<<60),temp;
    for(int k=i;k<j;k++){
        temp=solve(i,k)+solve(k+1,j)+sum[i][j];
        ans=min(ans,temp);
    }
    //cout<<"fnas "<<fans<<'\n';
    //fans+=ans;
    return dp[i][j]=ans;
}

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        //sum+=a[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            sum[i][j]=a[j]+((j==i)?0:sum[i][j-1]);
        }
    }
    memset(dp,-1,sizeof(dp));
    ll sd=solve(0,n-1);
    cout<<sd<<'\n';
}

Measured memory_bytes: 6156
n,k,s = map(int,input().split())
ans = []
if (s < 1000000000):
    for i in range(n):
        if (i < k):
            ans.append(s)
        else:
            ans.append(s + 1)
elif (s == 1000000000):
    for j in range(n):
        if (j < k):
            ans.append(s)
        else:
            ans.append(1)
ans = map(str,ans)
print(' '.join(ans))

Measured memory_bytes: 14104
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

#define MOD 1000000007

int main() {
  int n;
  scanf("%d", &n);
  long long a[n], ans = 0, cnt0[60] = {0}, cnt1[60] = {0};
  for (int i=0; i<n; i++) {
    scanf("%lld", a+i);
    for (int j=0; j<60; j++)
      if ((a[i]&(1ull<<j)) == 0) cnt0[j]++;
      else cnt1[j]++;
  }
  for (int i=0; i<60; i++) {
    ans += (((cnt1[i] * (cnt0[i])) % MOD) * ((1ull << i) % MOD)) % MOD;
    ans %= MOD;
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) a = b;
  return a > b;
}
template<class T> inline bool chmax(T&a, T b) {
  if (a < b) a = b;
  return a < b;
}

signed main() {
  int N; cin >> N;
  vector< vector<int> > p;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    vector<int> a(3);
    for (int j = 0; j < 3; j++) cin >> a[j];
    sort(a.begin(), a.end());
    for (int j = 0; j < p.size(); j++) {
      if (p[j][0]==a[0] && p[j][1]==a[1] && p[j][2]==a[2]) {
        ans++;
        break;
      }
    }
    p.push_back(a); 
  }
  cout << ans << endl; 
}



Measured memory_bytes: 3220
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    if(n % 2) {
        cout << b[n / 2] - a[n / 2] + 1 << endl;
    } else {
        cout << (b[(n - 1) / 2] + b[n / 2]) - (a[(n - 1) / 2] + a[n / 2]) + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 4784
#include <iostream>
#include <set>
#include <algorithm>
#include <climits>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define MP(a,b) make_pair(a,b)
int main(){
	int n,m,a,b,c,mi,ret;
	int info[100][100];
	pair<int,int> now;
	while(cin >> n && n){
		cin >> m;
		ret = 0;
		rep(i,100)rep(j,100)info[i][j] = INT_MAX;

		rep(i,m){
			scanf("%d,%d,%d\n",&a,&b,&c);
			info[a][b] = info[b][a] = (c/100)-1;
		}

		set<int> remain;
		for(int i=1;i<n;i++)remain.insert(i);

		while(!remain.empty()){
			now = MP(1<<21,-1);
			rep(i,n)
				if(remain.find(i) == remain.end() )
					rep(j,n)
						if(remain.find(j) != remain.end())now = min(now,MP(info[i][j],j));
			ret+=now.first;
			remain.erase(now.second);
		}
		cout << ret << endl;
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n;
    cin>>n;
    --n;
    vector<int> a(n+2,inf);
    rep(i,n)cin>>a[i+1];
    ll ans = 0;
    rep(i,n+1)ans += min(a[i],a[i+1]);
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
S = gets.chomp

first = S[0..1].to_i
second = S[2..3].to_i

ft = false
ft = true if (1 <= first  && first <= 12)

st = false
st = true if (1 <= second  && second <= 12)

if (ft && st)
  print('AMBIGUOUS')
elsif (!ft && !st)
  print('NA')
elsif ft
  print('MMYY')
else
  print('YYMM')
end


Measured memory_bytes: 3836
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

typedef long long llt;

const int MaxN = 21;
const llt Mod = 1e9 + 7;

int N;
int G[MaxN][MaxN];
llt dp[2][1 << MaxN];

void init() {
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j)
    scanf("%d", &G[i][j]);
}

void solve() {
  dp[1][0] = 1ll;

  for (int i = 0; i < N; ++i) {
    int now = i & 1, pre = (i + 1) & 1;
    memset(dp[now], 0, sizeof dp[now]);
    for (int S = 0; S < (1 << N); ++S) {
      if (dp[pre][S] == 0) continue;
      // printf("i = %d, S = %d\n", i, S);
      for (int j = 0; j < N; ++j) {
        if (G[i][j] == 0) continue;
        if (S & (1 << j)) continue;
        int Q = S | (1 << j);
        dp[now][Q] = (dp[now][Q] + dp[pre][S]) % Mod;
      }
    }
  }

  printf("%lld\n", dp[(N - 1) & 1][(1 << N) - 1]);
}

int main() {
  init();
  solve();
  return 0;
}

Measured memory_bytes: 33024
#include <bits/stdc++.h>
using namespace std;;
typedef long long ll;
ll dp[1000500][3],a[1000500];
int main()
{
 	string s;
 	cin >> s;
 	ll n=s.length();
 	for(int i=0;i<=n;i++)
    {
        a[i]=ll(s[i]-'0');
        dp[i][0]=1123456789;
        dp[i][1]=1123456789;
    }
    a[n]=0;
    n++;
    dp[n][0]=1123456789;
    dp[n][1]=1123456789;
    dp[0][0]=0;
   // cout<<n<<endl;
    for(int i=0;i<n;i++)
    {
        ll x=a[i];
        for(int j=0;j<2;j++)
        {
            //x+=j;
            dp[i+1][0]=min(dp[i+1][0],dp[i][j]+x+j);
            dp[i+1][1]=min(dp[i+1][1],dp[i][j]+10-x-j);
            //cout<<i+1<<" "<<dp[i+1][0]<<" "<<dp[i+1][1]<<endl;
        }
    }
    //cout<<dp[1][1]<<" "<<dp[2][1]<<endl;
 	cout<<dp[n][0]<<endl;
	return 0;
}


Measured memory_bytes: 32644
n=int(input())
s=input()
a=['SS','SW','WS','WW']
for j in range(4):
    for i in range(1,n):
        if s[i]=='o':
            if a[j][i]=='S':
                if a[j][i-1]=='S':
                    a[j]+='S'
                else:
                    a[j]+='W'
            else:
                if a[j][i-1]=='S':
                    a[j]+='W'
                else:
                    a[j]+='S'
        else:
            if a[j][i]=='S':
                if a[j][i-1]=='S':
                    a[j]+='W'
                else:
                    a[j]+='S'
            else:
                if a[j][i-1]=='S':
                    a[j]+='S'
                else:
                    a[j]+='W'
ans='-1'
for j in range(4):
    if a[j][0]==a[j][-1]:
        if s[0]=='o':
            if a[j][0]=='S' and a[j][-2]==a[j][1]:
                ans=a[j][:-1]
                break
            if a[j][0]=='W' and a[j][-2]!=a[j][1]:
                ans=a[j][:-1]
                break
        if s[0]=='x':
            if  a[j][0]=='S' and a[j][-2]!=a[j][1]:
                ans=a[j][:-1]
                break
            if  a[j][0]=='W' and a[j][-2]==a[j][1]:
                ans=a[j][:-1]
                break
print(ans)

Measured memory_bytes: 4024
n=int(input())
p=list(map(int,input().split()))
ans=0
for i in range(1,n-1):
    if p[i-1]<p[i] and p[i]<p[i+1]:
        ans+=1
    if p[i-1]>p[i] and p[i]>p[i+1]:
        ans+=1  
        
print(ans)

Measured memory_bytes: 9148
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            ll n,i,j;
            cin>>n;
            ll ar[n+1];
            ll ans=1,flag=0;
            for(i=1;i<=n;++i)
            {
                cin>>ar[i];
                if(ar[i]==0)
                    flag=1;
            }
            if(flag)
            {
                cout<<0<<endl;
                return 0;
            }
            for(i=1;i<=n;++i)
            {
                if(log10(ans) + log10(ar[i])>18)
                {
                    cout<<-1<<endl;
                    return 0;
                }
                ans=ans*ar[i];
            }

            if(ans>1000000000000000000)
            {
                cout<<-1<<endl;
                return 0;
            }
            cout<<ans<<endl;
        }
        return 0;
    }


Measured memory_bytes: 4768
open System
open System.Collections.Generic

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f

    let readInts() =
        read string
        |> Seq.toArray
        |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

module Util =
    let strRev (s: string): string =
        s
        |> Seq.rev
        |> Seq.map string
        |> String.concat ""

    let inline roundup (x: ^a) (y: ^a): ^a =
        let one = LanguagePrimitives.GenericOne
        (x + y - one) / y

type ModInt = MVal of int64

[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
[<RequireQualifiedAccess>]
module ModInt =
    let modulo = (int64 1e9) + 7L

    let inline init (x: ^a) : ModInt =
        let x = (int64 x) % modulo
        match x with
        | _ when x < 0L -> MVal (x + modulo)
        | _ when x >= modulo -> MVal (x - modulo)
        | _ -> MVal x

    let value (MVal x) = x

    let value2 (x: ModInt) (y: ModInt) = (value x, value y)

    let toString (MVal v) : string = sprintf "%d" v

    /// 拡張ユークリッドの互除法
    /// a (mod m) における逆元 a^-1
    let inline inverse (MVal a) : ModInt =
        let mutable (a, b, u, v) = (a, modulo, 1L, 0L)
        while b > 0L do
            let t = a / b
            a <- a - (t * b)
            let tmp = a
            a <- b
            b <- tmp
            u <- u - (t * v)
            let tmp = u
            u <- v
            v <- tmp
        init u

type ModInt with
    static member inline (+) (lhs: ModInt, rhs: ModInt) : ModInt =
        let l, r = ModInt.value2 lhs rhs
        ModInt.init (l + r)

    static member inline (-) (lhs: ModInt, rhs: ModInt) : ModInt =
        let l, r = ModInt.value2 lhs rhs
        ModInt.init (l - r)

    static member inline (*) (lhs: ModInt, rhs: ModInt) : ModInt =
        let l, r = ModInt.value2 lhs rhs
        ModInt.init (l * r)

    /// a / b = a * b^-1 (mod m)
    static member inline (/) (lhs: ModInt, rhs: ModInt) : ModInt =
        let r = ModInt.inverse rhs
        lhs * r

    /// a^n (mod m) 繰り返しニ乗法
    /// O(log n)
    static member inline Pow (a: ModInt, n: int64) : ModInt =
        let mutable (res, a, n) = (ModInt.init 1, a, n)
        while n > 0L do
            if (n &&& 1L) = 1L then res <- res * a
            a <- a * a
            n <- n >>> 1
        res

[<EntryPoint>]
let main _ =
    let n = read int

    let mutable ans = ModInt.init 1
    for i in 1..n do ans <- ans * ModInt.init i

    printfn "%s" (ModInt.toString ans)
    0 // return an integer exit code


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

string s;

int main() {
	char a;
	cin >> a;
	if ('A' <= a && a <= 'Z') cout << 'A' << endl;
	else if ('a' <= a && a <= 'z') cout << 'a' << endl;
	return 0;
}

Measured memory_bytes: 3592
function main(input = "") {
    let lines = input.split("\n");
    let N = 0 | lines[0];
    let arr = lines[1].split(" ").map((v) => (Number(v)));

    let res = 0;
    for (let i = 1; i < N; i++) {
        let diff = arr[i - 1] - arr[i];
        if (diff > 0) {
            res += diff
            arr[i] += diff;
        }
    }
    return res;
}

//******************************
exports.main = main;

function Main(input) {
    console.log(main(input.trim()));
}

if (process.argv[2] !== "test") {
    Main(require("fs").readFileSync("/dev/stdin", "utf8"));
}

Measured memory_bytes: 50224
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll N,ans=1;
  cin>>N;
  vector<ll> vec(N);
  for(ll i=0;i<N;i++){cin>>vec.at(i);}
  sort(vec.begin(),vec.end());
  if(vec.at(0)==0){cout<<0<<endl;return 0;}
  else{
    for(ll i=0;i<N;i++){
      if(1000000000000000000/ans<vec.at(i)){cout<<-1<<endl;return 0;}
      ans*=vec.at(i);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

char s[212345];
vl v;

int main(){
	scanf("%s", s);
	int n = strlen(s);
	ll ans = 0;
	int i = 0;
	v.EB(0);
	while(i <= n){
		if(s[i]=='A'){
			v[v.size()-1]++;
			i++;
		}else if(i+1<n && s[i]=='B' && s[i+1]=='C'){
			v.EB(0);
			i+=2;
		}else{
			REP(i, (int)v.size()){
				ans += (v.size()-i-1)*v[i];
			}
			v.clear();
			v.EB(0);
			i++;
		}
	}
	printf("%lld\n", ans);
}


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

int main(){
  int A[100], n;
  cin >> n;
  for(int i = 0; i < n; i++) cin >> A[i];
  for(int j = 1; j < n; j++){
    for(int i = 0; i < n; i++) cout << A[i] << (i == n-1 ? '\n' : ' ');
    int key = A[j];
    int i = j - 1;
    while(i >= 0 && A[i] > key){
      A[i + 1] = A[i];
      i--;
    }
    A[i + 1] = key;
  }
  for(int i = 0; i < n; i++) cout << A[i] << (i == n-1 ? '\n' : ' ');
  return 0;
}


Measured memory_bytes: 3120
#include <iostream>
using namespace std;
int main(void){
  for(;;){
    int N, M;
    cin >> N >> M;
    if(N == 0 && M == 0){ return 0; }
    int d[N], v[N];
    for(int i = 0 ; i < N ; i++){
      cin >> d[i] >> v[i];
    }
    int max[M];
    for(int i = 0 ; i < M ; i++){
      max[i] = -1;
    }
    for(int i = 0 ; i < N ; i++){
      if(max[d[i]-1] < v[i]){
    	max[d[i]-1] = v[i];
      }
    }
    int ans = 0;
    for(int i = 0 ; i < M ; i++){
      ans += max[i];
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 3012
S = input()
sl = []
ans = 'AC'

for i in S:
    sl.append(i)
if S[0] != 'A':
    ans = 'WA'
if S[2:-1].count('C') != 1:
    ans = 'WA'

if S[1:].replace("C","c",1).islower() == False:
    ans = 'WA'
#print(sl)
print(ans)

Measured memory_bytes: 9056
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define li long
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pli pair<li,li>
#define pll pair<ll,ll>
#define pb push_back
#define fori(i,k,n) for(int i = k;i<n; i++)
#define rfori(i,k,n) for(int i = k; i>=n; i--)
#define tc int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define inf INT_MAX
#define ninf INT_MIN
#define W(x) cout<<x<<endl
#define WW(x,y) cout<<x<<' '<<y<<endl;
#define in(x) cin>>x
const ll mod1 = 998244353;
const ll mod2 = 1e9+7;
template <class T>
using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

ll power(ll x,ll y){
    ll res = 1;
    
    while(y>0){
        if(y&1)res = (res*x);
        y>>=1;
        x = (x*x);
    }
    return res;
}

ll power(ll x,ll y,ll p){
    ll res = 1;
    x%=p;
    while(y>0){
        if(y&1)res = (res*x)%p;
        y>>=1;
        x = (x*x)%p;
    }
    return res;
}

int main(){
	fastio();
	string s,t;
	cin>>s>>t;
	if(t.size()!=s.size()+1)cout<<"Yes\n";
	else{
		for(int i = 0; i<s.size(); i++){
			if(s[i]!=t[i]){
				cout<<"No\n";
				return 0;
			}
		}
		cout<<"Yes\n";
	}
}

Measured memory_bytes: 3656
#include<stdio.h>
int main(){
  int x, y;

  while( scanf("%d %d",&x ,&y) != EOF ){

    if( x==0 && y==0 ){
      break;
    }

    else if( x > y ){
      printf("%d %d\n",y,x);
    }

    else{
      printf("%d %d\n",x ,y);
    }

  }

  return 0;
}

Measured memory_bytes: 600
import java.util.*;
import java.awt.geom.Point2D;

public class Main {
	static int n;
	static Point2D d;
	static HashMap<Point2D,Boolean> c;

	static boolean dfs(Point2D p,double sum,int time){
		//if(sum >= d.distance(p)) return false;
		if(time == n) return true;
		
		for(Point2D pp : c.keySet()){
			if(c.get(pp)) continue;
			if(sum+p.distance(pp) >= d.distance(pp)) return false;
		}
		c.put(p, true);
		for(Point2D pp : c.keySet()){
			if(c.get(pp)) continue;
			if(dfs(pp,sum+p.distance(pp),time+1)) return true;
		}
		c.put(p, false);
		
		return false;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			n = sc.nextInt();
			Point2D h = new Point2D.Double(sc.nextDouble(), sc.nextDouble());
			d = new Point2D.Double(sc.nextDouble(), sc.nextDouble());
			if(n == 0) break;

			c = new HashMap<Point2D,Boolean>();
			c.put(h, false);
			for(int i=0;i<n;i++){
				c.put(new Point2D.Double(sc.nextDouble(),sc.nextDouble()), false);
			}
		
			System.out.println(dfs(h,0,0) ? "YES" : "NO");
		}
	}
}

Measured memory_bytes: 13000
// D - RGB Triplets
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
long long ng,r,g,b;

int main(){
	int N; string S; cin>>N>>S;
	rep(i, N){
		S[i]=='R'? r++: S[i]=='G'? g++: b++;
		rep(d, N/2+1){
			int j = i + d, k = j + d;
			if(k >= N) break;
			if(S[i] != S[j] && S[j] != S[k] && S[k] != S[i]) ng++;
		}
	}
	cout<< r*g*b - ng <<endl;
}

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

typedef struct{
	double y;
	double x;
} coordinate;



int main(void){
	const double PI= atan(1.0)*4;
	int a,b,h,m;
	double ans;
	coordinate lng,sht;
	scanf("%d%d%d%d",&a,&b,&h,&m);
	lng.y=b*cos((double)m/30*PI);
	lng.x=b*sin((double)m/30*PI);
	//printf("lng: %f, %f\n",lng.y, lng.x);
	sht.y=a*cos((30*(double)h+0.5*(double)m)/180*PI);
	sht.x=a*sin((30*(double)h+0.5*(double)m)/180*PI);
	//printf("sht: %f, %f\n",sht.y, sht.x);
	ans=sqrt((lng.x-sht.x)*(lng.x-sht.x)+(lng.y-sht.y)*(lng.y-sht.y));
	printf("%.12f\n",ans);
	return 0;
}


Measured memory_bytes: 2532
//AB Substrings

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, string>;
using garph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int n;cin>>n;
    vecrep(n,s,string);
    int b=0,a=0,ans=0,ab=0;
    rep(i,0,n){
        if(s[i][0]=='B')b++;
        if(s[i][s[i].size()-1]=='A')a++;
        if(s[i][0]=='B'&&s[i][s[i].size()-1]=='A')ab++;
        rep(j,0,s[i].size()-1){
            if(s[i][j]=='A'&&s[i][j+1]=='B')ans++;
        }
    }
    ans+=min(min(a,b),n-1);
    if(a==ab&&b==ab&&ab!=n&&ab!=0)ans-=1;
    cout<<ans<<nnn;
    return 0;
}

Measured memory_bytes: 3700
#include<iostream>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    int ans=0;
    if(a>=b+2)cout<<a+(a-1)<<endl;
    else if(b>=a+2)cout<<b+(b-1)<<endl;
    else cout<<a+b<<endl;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
    string s1,s2;
    cin >> s1 >> s2;
    for(int i=0;i<s1.size();i++){
        if(s1[i]!=s2[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    if(s2[s2.size()-1]!=' '){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3624
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
char str[100];
inline int read(){
	int x=0,flag=1;
	char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')flag=-1,ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return x*flag;
}
int main(){
	int i,j,k,m,n;
	scanf("%s",str);
	int len=strlen(str);
	for(i=0;i<len-8;i++)printf("%c",str[i]);
	puts("");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<string.h>
using namespace std;

int main(){
		string n[10];
		int a = 0;
		int sta[10] = { 0 };
		int fin[10] = { 0 };
		for (a; a < 10; a++){
			cin >> n[a];
			if (n[a][0] == '-'){ break; }
			fin[a] = n[a].size();
			int m = 0;
			int h[201] = { 0 };
			cin >> m;
			for (int i = 0; i < m; i++){
				cin >> h[i];
			}
			for (int j = 0; j < m; j++){
				for (int k = 0; k + sta < h[j] + sta; k++){
					n[a].insert(fin[a], n[a].substr(sta[a], h[j]));
				}
				fin[a] += h[j];
				sta[a] += h[j];
			}
		}
		for (int b = 0; b < a; b++){
			cout << n[b].substr(sta[b], fin[b] - sta[b]) << endl;
		}
	return 0;
}


Measured memory_bytes: 3308
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <string>
#include <functional>

using namespace std;


int main() {
	int A, B;
	cin >> A >> B;
	if (A > 8 | B > 8) {
		cout << ":(" << endl;
	} else {
		cout << "Yay!" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long 
int ctoi(char c) {return c-'0';}/*char to int*/
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}/*MAX*/
int lcm(ll a,ll b){return a*b/gcd(a,b);}/*MIN*/
bool primecheck(ll n){/*sosuu*/if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
int  main(){
int n,m;
cin >> n >> m;
if(n==m){
    cout <<"Yes"<<endl;
    return 0;
}
cout << "No"<<endl;
}





Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
  
  int N, K, x, a;
  int A = 0;
  cin >> N >> K;
  
  for (int i = 0; i < N; i++) {
    
    cin >> x;
    
    if (x < K) {
      if (2 * x >= K) {
        a = K - x;
        //cout << a << endl;
      }
      else {
        a = x;
        //cout << a << endl;
      }
    }
    
    else {
      a = x - K;
      //cout << a << endl;
    }
    
    A = A + 2 * a;
    //cout << A << endl;
    
  }
  
  cout << A << endl;
          
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
int main(){
	char s[105];
	int r=0,b=0;
	int n;
	scanf("%d",&n);
	scanf("%s",s);
	for(int i=0;i<n;i++){
		if(s[i]=='R')r++;
		if(s[i]=='B')b++;
	}
	if(r>b)printf("Yes\n");
	else
	printf("No\n");
	return 0;
} 

Measured memory_bytes: 128
from copy import copy
import random
random.seed(1)
import math
import sys
input = sys.stdin.readline
D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for _ in range(D)]
last = [0]*26
ans = [0]*D
score = 0
for i in range(D):
    ps = [0]*26
    for j in range(26):
        pl = copy(last)
        pl[j] = i+1
        ps[j] += s[i][j]
        for k in range(26):
            ps[j] -= c[k]*(i+1-pl[k])
    idx = ps.index(max(ps))
    last[idx] = i+1
    ans[i] = idx+1
    score += max(ps)
for k in range(1,40001):
    na = copy(ans)
    x = random.randint(1,365)
    y = random.randint(1,365)
    na[x-1] = na[y-1]
    last = [0]*26
    ns = 0
    for i in range(D):
        last[na[i]-1] = i+1
        ns += s[i][na[i]-1]
        for j in range(26):
            ns -= c[j]*(i+1-last[j])
    if k%100 == 1:
        T = 30-(28*k/40000)
    p = pow(math.e,-abs(ns-score)/T)
    if ns > score or random.random() < p:
        ans = na
        score = ns
for a in ans:
    print(a)

Measured memory_bytes: 89160
N, T = map(int, input().split())
ct = []
for i in range(N):
  tmp = list(map(int, input().split()))
  ct.append(tmp)
ct.sort()

ans = 0
for i in range(len(ct)):
  if ct[i][1] <= T:
    ans = ct[i][0]
    break
if ans == 0:
  print('TLE')
else:
  print(ans)


Measured memory_bytes: 9168
N,M=map(int,input().split())
H=list(map(int,input().split()))
flag=[1]*N

for i in range(M):
    a,b=map(int,input().split())
    a-=1
    b-=1
    if (H[a]==H[b]):
        flag[a]=0
        flag[b]=0
    elif (H[a]>H[b]):
        flag[b]=0
    else:
        flag[a]=0
print(sum(flag))

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    string S;
    cin >> S;

    ll N = SZ(S)+1;
    vec A(N, -1);
    A[0] = 0; A[N-1] = 0;
    for(ll j=N-2; j>=0 && S[j] == '>'; --j) A[j] = MAX(A[j],N-1-j);
    for(ll j=1; j<N && S[j-1] == '<'; ++j) A[j] = MAX(A[j],j);
    REP(i,1,N-1) {
        if(S[i-1] == '>' && S[i] == '<') {
            A[i] = 0;
            for(ll j=i-1; j>=0 && S[j] == '>'; --j) A[j] = MAX(A[j],i-j);
            for(ll j=i+1; j<N && S[j-1] == '<'; ++j) A[j] = MAX(A[j],j-i);
        }
    }

    ll sum = 0;
    REP(i,0,N) sum += A[i];
    PR(sum);
    

    return 0;
}

/*
0   1   2   3   4   5   6   7   8   9
0 < 3 > 2 > 1 > 0 < 1 < 2 > 0 < 1 < 2 < 3 < 4 < 5 > 2 > 1 > 0 < 1
  0   1   2   3   4   5   6   7   8
*/

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

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
    ifstream t("/proc/self/status");
    cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getchar());
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) - '0' + ch;
	return sum * fg;
}

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

const int MAXN = (int) 1e2;

int n, x;

int a[MAXN + 5];

inline void input()
{
	n = read<int>(), x = read<int>();
	for(int i = 1; i <= n; ++i) a[i] = read<int>();
}

inline void solve()
{
	sort(a + 1, a + n + 1);

	int ans = 0;
	for(int i = 1; i <= n; ++i) if(x >= a[i]) x -= a[i], ++ans;
	if(x && ans == n) --ans;
	printf("%d\n", ans);
}

int main()
{
//	freopen("A.in", "r", stdin);
//	freopen("A.out", "w", stdout);

	input();
	solve();

	return 0;
}



Measured memory_bytes: 256
//Leonidas
#pragma GCC optimize("Ofast")
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container'.',hpp>
//#include <ext/pb_ds/tree_policy'.',hpp>
//typedef tree < int , null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> TREE;
#define ll long long
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define pss pair<short,short>
#define pld pair<long double,long double >
#define ld long double
#define piii  pair<pii,int>
#define vii vector<pair<int,int> >
#define st first
#define nd second
#define pll pair<ll,ll>
#define speed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define M_PI 3.14159265358979323846
//#define int long long
const int mod=1000000007;
//const int mod=1009;
//const int mod=998244353;
const int inf=1000000009;
const long long INF=1000000000000000009;
const long long big=1000000000000000;
const long double eps=0.000000000000000000001;
using namespace std;
int32_t main()
{
    speed
    ll n;
    cin>>n;
    string s="";
    while(n)
    {
        n--;
        int x=n%26;
        s+=(char)(x+97);
        n-=x;
        n/=26;
    }
    reverse(s.begin(),s.end());
    cout<<s;
    return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  int ans = max( a + b, a - b );
  int ans1 = max(ans, a * b);
  cout << ans1 << endl;
  return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<map>
#define fs first
#define sc second
using namespace std;
typedef long long ll;

int n;
pair<ll,int> p[300010],b[300010];
ll a[300010];
bool use[300010];

int main(){
  cin.tie(0);
  std::ios::sync_with_stdio(0);

  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a[i] >> b[i].fs;
    p[i] = make_pair(a[i],i);
    b[i].sc = i;
    use[i] = false;
  }
  sort(p,p+n); sort(b,b+n);

  int ans = 0;
  ll sum = 0;
  
  int id = 0, num = 0;
  for(int i=0;i<n;i++){
    if(!use[b[i].sc]){
      sum += a[b[i].sc];
      use[b[i].sc] = true;
      num++;
    }

    while(id<n){
      if(!use[p[id].sc]){
	if(p[id].fs > b[i].fs && sum+p[id].fs > (num+1)*b[i].fs)break;
	sum += p[id].fs;
	use[p[id].sc] = true;
	num++;
      }
      id++;
    }
    if(sum <= num*b[i].fs)ans = max(ans,num);

    sum -= a[b[i].sc]; num--;
  }
  cout << ans << endl;
}
      

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

using namespace std;

int dp[1000003];
vector<int> a({100, 101, 102, 103, 104, 105});

int main() {
    int X;
    cin >> X;
    for(int i : a) dp[i] = true;
    for(int i = 101; i <= X; ++i) {
        for(int j : a) {
            dp[i] |= dp[i - j];
        }
    }
    if(dp[X]) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}


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

         
                    
using namespace std;
                     
#define rep(i,a,b); for(long int i=a;i<b;i++)
#define mk make_pair        
#define LIMIT 100007
#define MOD 1000000007
#define ll long long int
#define endl '\n'
#define min(a,b) (a>b?b:a)
#define max(a,b) (a<b?b:a)
#define pb push_back
#define FAST std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

ll power(ll t,ll x)
{

	ll ans=1;
	while(t>0)
	{
		if(t%2==1)
			ans=(ans*x)%MOD;

		t=t/2;
		x=(x*x)%MOD;
	}

	return ans;
}


int main() 
{ 
    FAST
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
	int n,k;
	cin>>n>>k;
	int h[n];
	rep(i,0,n) cin>>h[i];

	ll dp[n];
	dp[0]=0;
	rep(i,1,n)
	{
		ll m=dp[i-1]+abs(h[i]-h[i-1]);
		for(int j=1;i-j>=0 && j<=k;j++)
		{
			if(m>dp[i-j]+abs(h[i]-h[i-j]))
				m=dp[i-j]+abs(h[i]-h[i-j]);
		}
		dp[i]=m;
	}

	cout<<dp[n-1];


    return 0; 
}  


Measured memory_bytes: 4832
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+5;
int readint(){
	int x=0,f=1;char s=getchar();
	#define sc (s=getchar())
	while(s<'0'||s>'9'){
		if(s=='-')
			f=-1;
		sc;
	}
	while(s>='0'&&s<='9'){
		x=(x<<3)+(x<<1)+(s^48);
		sc;
	}
	#undef sc
	return x*f;
}
signed main(){
	int k=readint();
	int x=readint(),y=readint();
	for(int i=x;i<=y;i++){
		if(i%k==0){
			puts("OK");
			return 0;
		}
	}
	puts("NG");
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];
#define int long long

signed main(){
    int N, A, B; cin >> N >> A >> B;
    cout << N/(A+B)*A + (int)min(N%(A+B),A) << endl;
}

Measured memory_bytes: 256
d, g = map(int, input().split())
pc = [list(map(int, input().split())) for _ in range(d)]

min_count = 1001
for i in range(2 ** d):
    s = 0
    count = 0
    max_flag = 0
    for j in range(d):
        if (i >> j) & 1:
            s += 100 * (d - j) * pc[d - j - 1][0] + pc[d - j - 1][1]
            count += pc[d - j - 1][0]
        elif max_flag == 0:
            max_flag = d - j

        if s >= g:
            min_count = min(min_count, count)
            s = 0
            count = 0
            break

    for _ in range(pc[max_flag - 1][0]):
        s += 100 * max_flag
        count += 1
        if s >= g:
            min_count = min(min_count, count)
            s = 0
            count = 0
            break

print(min_count)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		long sum = 0;
		for(int i = 0; i < s.length(); i++) {
			long coefficient = 0;
			for(int j = 0; j < s.length(); j++) {
				if(j == i)
					coefficient += (long)(Math.pow(10, j)*Math.pow(2, s.length() - 1 - j));
				else if(j < i)
					coefficient += (long)(Math.pow(10, j)*Math.pow(2, s.length() - 2 - j));
			}
			sum += coefficient*(Integer.parseInt(s.substring(s.length() - 1 - i, s.length() - i)));
		}
		System.out.println(sum);
	}
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll A, B, C;
    cin >> A >> B >> C;
    if(A + B + C >= 22) cout << "bust";
    else cout << "win";
    cout << endl;
    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>

using namespace std;

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

    int n, m;
    cin >> n >> m;

    int dp[1<<n];
    fill(dp, dp + (1 << n), 2e6);
    dp[0] = 0;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        int t = 0;
        for (int j = 0; j < b; j++) {
            int c;
            cin >> c;
            t += 1 << (c - 1);
        }
        dp[t] = min(dp[t], a);
    }

    for (int i = 0; i < 1 << n; i++) {
        for (int j = 0; j < 1 << n; j++) {
            dp[i|j] = min(dp[i|j], dp[i] + dp[j]);
        }
    }

    cout << (dp[(1<<n)-1] >= 2e6 ? -1 : dp[(1<<n)-1]) << endl;

    return 0;
}


Measured memory_bytes: 256