akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif


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

  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  auto get_dp = [&]() {
    vector<vector<bool>> dp(n + 1, vector<bool>(k));
    dp[0][0] = true;
    for (int i = 0; i < n; i++) {
      if (a[i] < k) {
        dp[i + 1][a[i]] = true;
      }
      dp[i + 1] = dp[i];
      for (int j = a[i]; j < k; j++) {
        dp[i + 1][j] = dp[i + 1][j] || dp[i][j - a[i]];
      }
    }
    return dp;
  };

  auto pref = get_dp();
  reverse(a.begin(), a.end());
  auto suff = get_dp();
  reverse(a.begin(), a.end());
  vector<vector<int>> suff_sum(n + 1, vector<int>(k + 1));
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      suff_sum[i][j + 1] = suff_sum[i][j] + suff[i][j];
    }
  }

  debug(suff_sum);
  int num = 0, l, r;
  for (int i = 0; i < n; i++) {
    if (a[i] >= k) {
      num++;
      continue;
    }
    // [L, R] = [k - a[i], k - 1]
    for (int j = 0; j < k; j++) {
      if (pref[i][j] == false) continue;
      l = k - a[i] - j;
      r = k - 1 - j;
      l = max(l, 0);
      if (r < 0) break;
      if (suff_sum[n - 1 - i][r + 1] - suff_sum[n - 1 - i][l] > 0) {
        num++;
        break;
      }
    }
  }

  cout << n - num << '\n';

  return 0;
}


Measured memory_bytes: 107644
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

int N;

long long first_f(string X, int pop_count)
{
  if (pop_count == 0)
    return -1;
  long long result = 0;
  REVERSE(X);
  long long pow2 = 1;
  rep(i, X.size())
  {
    if (X[i] == '1')
    {
      result += pow2;
      result %= pop_count;
    }

    pow2 *= 2;
    pow2 %= pop_count;
  }

  return result;
}

long long f(long long X, long long count)
{
  if (X == 0)
    return count;

  long long pop_count = 0;
  long long tempX = X;
  while (tempX != 0)
  {
    if (tempX % 2 == 1)
      pop_count++;
    tempX /= 2;
  }
  long long nX = X % pop_count;
  return f(nX, count + 1);
}

int main()
{
  string X;
  long long Xplus;
  cin >> N >> X;

  long long PCX = 0;
  rep(i, N)
  {
    if (X[i] == '1')
      PCX++;
  }

  long long XmodPCXplus1 = first_f(X, PCX + 1);
  long long XmodPCXminus1 = first_f(X, PCX - 1);
  long long pow2_plus = 1, pow2_minus = 1;
  REVERSE(X);

  vector<long long> ans(N);
  rep(i, N)
  {
    long long nX;
    if (X[i] == '0')
    {
      X[i] = '1';
      nX = XmodPCXplus1 + pow2_plus;
      nX %= PCX + 1;
      ans[i] = f(nX, 1);
      X[i] = '0';
    }

    if (X[i] == '1')
    {
      if ((PCX - 1) != 0)
      {
        X[i] = '0';
        nX = XmodPCXminus1 - pow2_minus;
        nX += (PCX - 1);
        nX %= PCX - 1;
        ans[i] = f(nX, 1);
        X[i] = '1';
      }
      else
        ans[i] = 0;
    }

    pow2_plus *= 2;
    pow2_plus %= PCX + 1;

    if ((PCX - 1) != 0)
    {
      pow2_minus *= 2;
      pow2_minus %= PCX - 1;
    }
  }

  REVERSE(ans);
  REVERSE(X);
  rep(i, N)
  {
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 5316
fun main(args: Array<String>) {
    val(N,M) = readIntList()

    println(N*(N-1)/2+M*(M-1)/2)
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

Measured memory_bytes: 37992
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)()
#define all(x) x.begin(),x.end()
typedef long long ll;
typedef pair<int,int> p;
//const ll big=998244353;
const ll big=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/

    string s,t;cin >> s >> t;
    //dp[i+1][j+1]:=s[i],t[j]まで見たときのLcsの長さ
    vector<vector<int>> dp((int)s.size()+2,vector<int>((int)t.size()+2));
    rep(i,s.size()+1)rep(j,t.size()+1){
        if(i<(int)s.size()&&j<(int)t.size()&&s[i]==t[j])dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+1);
        else dp[i+1][j+1]=max(dp[i][j],dp[i+1][j+1]);
        dp[i+1][j]=max(dp[i][j],dp[i+1][j]);
        dp[i][j+1]=max(dp[i][j],dp[i][j+1]);
    }
    string ans="";
    int i=(int)s.size(),j=(int)t.size();
    while(i>0&&j>0){
        if(dp[i-1][j]==dp[i][j])i--;
        else if(dp[i][j-1]==dp[i][j])j--;
        else{
            ans.push_back(s[i-1]);
            i--;
            j--;
        }
    }
    reverse(all(ans));
    cout << ans << endl;
}

Measured memory_bytes: 38544
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
typedef long long lint;
const int N=3e5+5;
int n,qa,qb;

namespace utils{
	template <class T> inline void apn(T &x,const T y){x=x<y?x:y;}
	template <class T> inline void apx(T &x,const T y){x=x>y?x:y;}
	inline int nxi(){
		int x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=c=='-'&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

int main(){
	n=nxi(),qa=nxi(),qb=nxi();
	if((lint)qa*qb<n||qa+qb>n+1){
		puts("-1");
		return 0;
	}
	for(int i=1,j=n; i<=qb; ++i){
		int num=std::min(qa,j-(qb-i));
		for(int k=j-num+1; k<=j; ++k){
			printf("%d ",k);
		}
		j-=num;
	}
	puts("");
	return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define double long double
using namespace std;
int n,k;
struct PT {
  double x, y;
  PT() {}
  PT(double x, double y) : x(x), y(y) {}
  PT(const PT &p) : x(p.x), y(p.y)    {}
  PT operator + (const PT &p)  const { return PT(x+p.x, y+p.y); }
  PT operator - (const PT &p)  const { return PT(x-p.x, y-p.y); }
  PT operator * (double c)     const { return PT(x*c,   y*c  ); }
  PT operator / (double c)     const { return PT(x/c,   y/c  ); }
} p[65];

double dot(PT p, PT q)     { return p.x*q.x+p.y*q.y; }
double dist2(PT p, PT q)   { return dot(p-q,p-q); }
double cross(PT p, PT q)   { return p.x*q.y-p.y*q.x; }
ostream &operator<<(ostream &os, const PT &p) {
  return os << "(" << p.x << "," << p.y << ")";
}

// rotate a point CCW or CW around the origin
PT RotateCCW90(PT p)   { return PT(-p.y,p.x); }
PT RotateCW90(PT p)    { return PT(p.y,-p.x); }
PT RotateCCW(PT p, double t) {
  return PT(p.x*cos(t)-p.y*sin(t), p.x*sin(t)+p.y*cos(t));
}

int c[65];
double INF = 1e100;
double EPS = 1e-12;

vector<PT> CircleCircleIntersection(PT a, PT b, double r, double R) {
  vector<PT> ret;
  double d = sqrt(dist2(a, b));
  if (d > r+R || d+min(r, R) < max(r, R)) return ret;
  double x = (d*d-R*R+r*r)/(2*d);
  double y = sqrt(r*r-x*x);
  PT v = (b-a)/d;
  ret.push_back(a+v*x + RotateCCW90(v)*y);
  if (y > 0)
    ret.push_back(a+v*x - RotateCCW90(v)*y);
  return ret;
}
bool check(double X){
    //cout << "test " << X << endl;
    double r[65];
    for (int i = 0; i < n; i++){
        r[i] = X/c[i];
    }
    for (int i = 0; i < n; i++){
        for (int j = i; j < n; j++){
            if (i == j){
                int ans = 0;
                for (int k = 0; k < n; k++){
                    double D = sqrt(dist2(p[i],p[k]));
                    if (D*c[k] < X){
                        ans++;
                    }
                }
                if (ans >= k) return true;
                continue;
            }
            vector<PT> check = CircleCircleIntersection(p[i],p[j],r[i],r[j]);
            for (auto x : check){
                int ans = 0;
                for (int k = 0; k < n; k++){
                    double D = sqrt(dist2(x,p[k]));
                    //cout << x << " " << p[k] <<  " " << D << endl;
                    if (D*c[k]-X <= EPS){
                        ans++;
                    }
                }
                //cout << x << " " << ans << endl;
                if (ans >= k) return true;
            }

        }
    }
    return false;
}
int main(){
    scanf("%d%d",&n,&k);
    for (int i = 0,x,y; i < n; i++){
        scanf("%d%d%d",&x,&y,&c[i]);
        p[i].x = (double)x;
        p[i].y = (double)y;
    }
    double lo = 0, hi = 300000;
    while (hi-lo > 1e-6){
        double mid = (lo+hi)/2;
        if (check(mid)){
            hi = mid;
        }
        else lo = mid;
    }
    printf("%.6Lf",lo);

}


Measured memory_bytes: 256
#include <stdio.h>

int main(){

  int i,N,j,minj,count=0,A[100],tmp,flag=0;
  scanf("%d",&N);

  for(i=0;i<N;i++){

    scanf("%d",&A[i]);

  }

  for(i=0;i<N-1;i++){
    minj=i;
    for(j=i+1;j<N;j++){
      if(A[j]<A[minj]){
	minj=j;
	flag=1;
      }
    }
    if(flag==1){
    tmp=A[i];
    A[i]=A[minj];
    A[minj]=tmp;
    count++;
    flag=0;
    }
  }
  for(i=0;i<N-1;i++){
    printf("%d ",A[i]);
}
  printf("%d\n",A[N-1]);
  printf("%d\n",count);
  return 0;
}



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

ll dis(ll x1, ll y1, ll x2, ll y2){
    return abs(x1 - x2) + abs(y1 - y2);
}

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

    vector<string> a(h);
    set<ll> ban_h;
    set<ll> ban_w;

    rep(i, h){
        cin >> a[i];
    }

    rep(i, h){
        bool flg = true;
        rep(j, w){
            if (a[i][j] == '#'){
                flg = false;
            }
        }
        if (flg){
            ban_h.insert(i);
        }
    }

    rep(i, w){
        bool flg = true;
        rep(j, h){
            if (a[j][i] == '#'){
                flg = false;
            }
        }
        if (flg){
            ban_w.insert(i);
        }
    }


    rep(i, h){
        bool flg = false;
        rep(j, w){
            if (ban_h.find(i) != ban_h.end() || ban_w.find(j) != ban_w.end()){
                continue;
            }else{
                cout << a[i][j];
                flg = true;
            }
        }
        if (flg){
            cout << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3652
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, S, E) for (int(X) = (S); (X) < (E); ++(X))
#define rrep(X, S, E) for (int(X) = (E)-1; (X) >= (S); --(X))
#define itrep(X, Y) for (auto(X) = (Y).begin(); (X) != (Y).end(); (X)++)
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll INF = 9 * 1e18;
const ll MOD = 1e9 + 7;

int main() {
  ll N, M;
  cin >> N;
  cin >> M;
  vector<vl> switches(M);
  rep(i, 0, M) {
    ll k;
    cin >> k;
    rep(j, 0, k) {
      ll tmp;
      cin >> tmp;
      switches[i].push_back(tmp);
    }
  }
  vl p(M);
  rep(i, 0, M) { cin >> p[i]; }

  ll ans = 0;
  for (ll i = 0; i < (1 << N); i++) {
    bool flag = true;
    rep(m, 0, M) {
      vl v = switches[m];
      ll cnt = 0;
      itrep(it, v) {
        if ((i >> (*it - 1)) & 1 == 1) {
          cnt++;
        }
      }
      if (cnt % 2 != p[m]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      ans++;
    }
  }
  print(ans);

  return 0;
}


Measured memory_bytes: 256
def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)

N,K=map(int,input().split())
A=[int(x) for x in input().split()]

ans=max(A)
cnt=ans
for i in range(N):
  cnt=gcd(cnt,A[i])

if K%cnt==0 and K<=ans:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

Measured memory_bytes: 14224
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
	
	int N;
	scanf("%d", &N);

	int sta;
	if (N % 2 == 0) 
		sta = N;
	else
		sta = N+1;

	for (int i = sta;; i += 2) {
		if ((i%N) == 0) {
			printf("%d\n", i);
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;

const long long MOD = 1000000007;
// powmod p^n%mod
LL powmod(LL p,LL n,LL mod){
	LL q=p%mod;
	LL pow=1;
	while(n){
		if(n&1){
			pow*=q;
			pow%=mod;
		}
		q=q*q;
		q%=mod;
		n/=2;
	}
	return pow;
}


void solve(long long N, long long K){
	LL ret=0;
	for(LL i=K;i<=N+1;i++){
		ret+=(1+(N+1-i)*i)%MOD;
		ret%=MOD;
	}
	cout << ret << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    solve(N, K);
    return 0;
}


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

#define FOR(a,n) for(int i = a; i <= n; i++)

const int maxn = 1000 + 10;
int a[maxn];

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

        int MAX = 1;
        for(int i = 1; i <= n; i++)
            if(abs(a[i]) > abs(a[MAX])) MAX = i;

        if(a[MAX] == 0)
        {
            printf("0\n");
            continue;
        }

        printf("%d\n",2 * n);

        if(a[MAX] > 0)
        {

            FOR(1,2)
                printf("%d %d\n",MAX,n);

            FOR(1,n-1)
            {
                printf("%d %d\n",n,i);
                printf("%d %d\n",n,n);
            }
        }
        else
        {
            FOR(1,2)
                printf("%d %d\n",MAX,1);

            for(int i = n; i > 1; i--)
            {
                printf("%d %d\n",1,i);
                printf("%d %d\n",1,1);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<string>
#include<string.h>
using namespace std;
const int maxn=5e5+10;
int q,n;
char s[maxn];
set<int>S[30];
int main()
{
	std::ios::sync_with_stdio(false);
	cin>>n>>s+1>>q; 
	int a;
	int l,r,i;
	char c;
	for(int i=0;i<26;i++)S[i].insert(n+1);
	for(int i=1;i<=n;i++)S[s[i]-'a'].insert(i);
	while(q--)
	{
		cin>>a;
		if(a==1)
		{
			cin>>i>>c;
			if(s[i]!=c)S[s[i]-'a'].erase(i);
			s[i]=c;
			S[c-'a'].insert(i);
		}
		else
		{
			cin>>l>>r;
			int ans=0;
			for(int i=0;i<26;i++)
			{
				if(*S[i].lower_bound(l)<=r)ans++;
			}
			cout<<ans<<endl;
		}
	}
	return 0;
 } 


Measured memory_bytes: 24192
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int a[101001];
int main()
{
	int n,i,tmp,sum;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a+1,a+n+1);
	sum=1;
	tmp=0;
	for(i=n-1;i>=1;i--)
	{
		//printf("%d ",a[i]);
		if(a[i]!=a[i+1])
		{
			if(sum>=2)
				tmp=a[i+1];
			sum=0;
		}
		sum++;
		if(sum>=2&&tmp!=0)
		{
			printf("%lld",(long long)a[i]*tmp);
			return 0;
		}
		if(sum>=4)
		{
			printf("%lld",(long long)a[i]*a[i]);
			return 0;
		}
	}
	printf("0");
	return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

template<typename T, class F, const T I>
struct SegmentTree {
    const F op = F();
    int n; vector<T> dat;
    void init(int n_) { n = 1; while (n < n_) n *= 2; dat.assign(n * 2, I); }
    void build(const vector<T>& v) {
        int n_ = v.size(); init(n_); for (int i = 0; i < n_; ++i) dat[n + i] = v[i];
        for (int i = n - 1; i; --i) dat[i] = op(dat[i * 2], dat[i * 2 + 1]);
    }
    void update(int k, T v) { dat[k += n] = v; while (k /= 2) dat[k] = op(dat[k * 2], dat[k * 2 + 1]); }
    T query(int a, int b) {
        T vl = I, vr = I;
        for (int l = a + n, r = b + n; l < r; l /= 2, r /= 2) { if (l & 1) vl = op(vl, dat[l++]); if (r & 1) vr = op(dat[--r], vr); }
        return op(vl, vr);
    }
    template<class C> int find(int a, int b, C& check) { return find(a, b, check, 1, 0, n); }
private:
    template<class C> int find(int a, int b, C& check, int k, int l, int r) {
        if (!check(dat[k]) || r <= a || b <= l) return -1; else if (k >= n) return k - n;
        int m = (l + r) / 2; int vl = find(a, b, check, (k * 2) | 0, l, m);
        if (~vl) return vl; else return find(a, b, check, (k * 2) | 1, m, r);
    }
};

template<typename T = int> struct min_of { constexpr T operator ()(T& lhs, T& rhs) const { return min<T>(lhs, rhs); } };

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N) cin >> a[i];

    SegmentTree<int, min_of<int>, INT32_MAX> st;
    st.build(a);

    ll ans = 0;
    rep(i, N) {
        int r = 0;
        {
            int low = i + 1, high = N + 1;
            while (high - low > 1) {
                int mid = (low + high) / 2;
                if (st.query(i + 1, mid) < a[i]) high = mid;
                else low = mid;
            }
            r = low;
        }
        int l = 0;
        {
            int high = i, low = -1;
            while (high - low > 1) {
                int mid = (high + low) / 2;
                if (st.query(mid, i) < a[i]) low = mid;
                else high = mid;
            }
            l = high;
        }
        ans += (ll)a[i] * (i - l + 1) * (r - i);
    }

    write(ans);
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define eps 1e-9
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
const int N = 1e6 + 10;
const int INF = 1e9 + 7;
int main()
{
	string s;
	cin >> s;
	int n = s.size() - 1;
	bool flag = false;
	ll l = INF, r;
	rep(i, 1, n)
		if(s[i] == s[i - 1])
		{
			flag = true;
			r = i + 1;
			l = i;
			break;
		}

	rep(i, 2, n)
		if(s[i] == s[i - 2])
		{
			flag = true;
			r = i + 1;
			l = i - 1;
			break;
		}

	if(l == INF) cout << -1 << " " << -1;
	else cout << l << " " << r;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <string.h>
#include <stdio.h>
#include <cmath>
using namespace std;

int main(){
	int N,A,B;
	cin >> N >> A >> B;
	int P[N];
	for(int i = 0;i < N;i++){
		cin >> P[i];
	}
	int count = 0;
	int check1 = 0;
	int check2 = 0;
	int check3 = 0;
	int loop = 1;
	while(loop){
		for(int i = 0;i<N;i++){
			if(check1 == 0 && P[i] <= A){
				check1 = 1;
				P[i] = 100;
			}
			if(check2 == 0 && P[i] > A && P[i] <= B){
				check2 = 1;
				P[i] = 100;
			}
			if(check3 == 0 && P[i] > B && P[i] < 100){
				check3 = 1;
				P[i] = 100;
			}
		}
		if(check1 == 1 && check2 == 1 && check3 == 1){
			count++;
			check1 = 0;
			check2 = 0;
			check3 = 0;
		}
		else {
			loop = 0;
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#include <cstdio>
int main() {
 int k, a, b;
 scanf("%d%d%d", &k, &a, &b);
 if (a / k < b / k || a % k == 0 || b % k == 0) {
  printf("OK\n");
 } else {
  printf("NG\n");
 }
 return 0;
}

Measured memory_bytes: 3152
#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() {
    ll a, b, c, d; cin >> a >> b >> c >> d;
    cout << max(a*c, max(a*d, max(b*c, b*d))) << endl;
}


Measured memory_bytes: 3632
/*
    Ujjawal Pabreja [cuber_coder]
*/
#include <bits/stdc++.h> 
#include <functional> 
using namespace std;
using ll = long long;
using ld = long double;
#define speed_cubing    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(i,a)        for(ll i = 0 ; i < a ; i++)
#define repe(i,a,b)     for(ll i = a ; i < b ; i++)
#define bac(i,a)        for(ll i = a ; i >= 0 ; i--)
#define bace(i,a,b)     for(ll i = a ; i >= b ; i--)
#define pb              push_back
#define mp              make_pair
#define in              insert
#define ff              first
#define ss              second
#define vv              vector
#define vll             vector <ll>
#define pll             pair <ll,ll>
#define vpll            vector <pll>
#define umap            unordered_map
#define uset            unordered_set
#define mset            multiset
#define pqueue          priority_queue
#define setbit(x)       __builtin_popcountll(x)
#define init(c,a)       memset(c,a,sizeof(c))
#define all(c)          c.begin(),c.end()
#define sz(c)           (ll)c.size()
#define lb              lower_bound
#define ub              upper_bound
#define maxe            *max_element
#define mine            *min_element
#define rev             reverse
#define Y               "YES"
#define N               "NO"
#define nl              "\n"
#define debug(x)        cout << #x << " : " << x << nl;
const ll inf = 1e18;  
const ll mod = 1e9 + 7;
const ll MOD = 998244353;
const ll MAX = 2e5 + 1;
 
// ====== BigInt begins ======
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// ====== BigInt ends ======
 
// ====== PBDS begins ======
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, 
//         tree_order_statistics_node_update> 
//         pbds; 
// ====== PBDS ends ======
 
// ====== Useful functions begin ======
inline ll add(ll a,ll b) {return ((a%mod)+(b%mod))%mod;}
inline ll sub(ll a,ll b) {return ((a%mod)-(b%mod)+mod)%mod;}
inline ll mul(ll a,ll b) {return ((a%mod)*(b%mod))%mod;}
ll pwr(ll x,ll n){
    if(n == 0){
        return 1;
    }
    if(n&1){
        return mul(x, pwr(mul(x, x), (n - 1) / 2));
    } else {
        return pwr(mul(x, x), n / 2);
    }
}
ll modinv(ll n){ 
    return pwr(n, mod - 2); 
}
ll gcd(ll a,ll b) {
    if(b == 0) {
        return a;
    }
    return gcd(b, a % b);
}
// ====== Useful functions end ======
 
// ====== Variables begin ======
void speed_solve(){
    ll n;
    cin >> n;
    cout << n + n * n + n * n * n << nl;
}
 
int main(){
    speed_cubing;
    ll test_cases = 1;
    // cin >> test_cases;
    rep(i,test_cases){
        // cout << "Case #" << i + 1 << ": ";
        speed_solve();
    }
    return 0;
}

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

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

ll dp[200005][2];

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  dp[0][1] = A[0];
  dp[1][1] = max(A[0], A[1]);
  for (int i = 2; i < N; i++) {
    if (i%2 == 0) {
      dp[i][0] = max(dp[i-1][1], dp[i-2][0] + A[i]);
      dp[i][1] = dp[i-2][1] + A[i];
    } else {
      dp[i][0] = max(dp[i-1][0], dp[i-2][0] + A[i]);
      dp[i][1] = max(dp[i-1][1], dp[i-2][1] + A[i]);
    }
  }
  if (N%2 == 0) {
    cout << dp[N-1][1] << '\n';
  } else {
    cout << dp[N-1][0] << '\n';
  }
  return 0;
}

Measured memory_bytes: 7200
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std ;
int main()
{
	int n,t,i;
	cin>>n>>t;
	int c[n],q[n];
	for (i=0;i<n;i++)
		cin>>c[i]>>q[i];
	vector<int> p;
	for (i=0;i<n;i++)
	{
		if(q[i]<=t)
		p.push_back(c[i]);
	}
	if (p.size()==0)
		cout<<"TLE"<<endl;
	else
		cout<<*min_element(p.begin(),p.end())<<endl;
}

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

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

  for (int i = 1; i <= 50000; i++) {
    int money = i * 1.08;
    if (money == N) {
      cout << i << endl;
      return 0;
    }
  }

  cout << ":(" << endl;
  return 0;
}

Measured memory_bytes: 256
/*
  Vivek Rathi
  CSE 2nd Year
  MNNIT
*/
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define ll long long int
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define present(c,x) ((c).find(x) != (c).end())
#define null NULL
#define mp make_pair
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define inf 1e17
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
double dp[301][301][301];
int main()
{
	boost
	ll n,has[4]={0};
	cin>>n;
	ll a[n];
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
		has[a[i]]++;
	}
	ll c0=has[1],c1=has[2],c2=has[3];
	dp[0][0][0]=0.0;
	for(ll k=0;k<=n;k++)
	{
		for(ll j=0;j+k<=n;j++)
		{
			for(ll i=0;i+j+k<=n;i++)
			{
				if(i==0&&j==0&&k==0) continue;
				if(k-1>=0)dp[i][j][k]+=dp[i][j+1][k-1]*((double)k/(i+j+k));
				if(j-1>=0)dp[i][j][k]+=dp[i+1][j-1][k]*((double)j/(i+j+k));
				if(i-1>=0)dp[i][j][k]+=dp[i-1][j][k]*((double)i/(i+j+k));
				dp[i][j][k]+=((double)n/(i+j+k));
			}
		}
	}
	printf("%.10lf",dp[c0][c1][c2]);
	return 0;
}

Measured memory_bytes: 213248
b,w = map(int,input().split())
flg = 0
if b>w:
  flg = 1
  b,w = w,b
elif b == w:
  for _ in range(b+w):
    print(500000004)
  exit()
mod = 10**9+7
rng = 200100
fctr = [1]
finv = [1]
for i in range(1,rng):
  fctr.append(fctr[-1]*i%mod)
def inv(a):
  return pow(a,mod-2,mod)
def cmb(n,k):
  if n<0 or k<0:
    return 0
  else:
    return fctr[n]*inv(fctr[n-k])*inv(fctr[k])%mod

ans = [500000004]*b
nume = pow(2,b-1,mod)
domi = pow(2,b,mod)
for i in range(b+1,b+w+1):
  domi = domi*2%mod
  nume = nume*2-cmb(i-2,i-b-1)
  if i >= w:
    nume += cmb(i-2,i-w-1)
  nume %= mod
  x = nume*inv(domi)%mod
  if flg:
    ans.append(mod+1-x)
  else:
    ans.append(x)
print(*ans,sep="\n")

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

int main(){
  string s,base="keyence"; cin>>s;
  for(int i=0;i<base.size();i++){
    if(base[i]!=s[i]){
      int j=s.size()-1;
      for(int k=base.size()-1;k>=i;k--){
        if(base[k]!=s[j]){
          cout<<"NO"<<endl;
          return 0;
        }j--;
      }
      cout<<"YES"<<endl;
      return 0;
    }
  }
  cout<<"YES"<<endl;
}

Measured memory_bytes: 256
import sys, re
from math import ceil, floor, sqrt, pi, factorial#, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    n, a, b, c = i_map()
    num_list = i_row(n)

    min_mp = INF
    for bin in list(product([0, 1, 2, 3], repeat=n)):
        ac = bin.count(1)
        bc = bin.count(2)
        cc = bin.count(3)
        if ac < 1 or bc < 1 or cc < 1:
            continue
        mp = 0
        if ac >= 2:
            mp += 10 * (ac-1)
        if bc >= 2:
            mp += 10 * (bc-1)
        if cc >= 2:
            mp += 10 * (cc-1)
        sum_a, sum_b, sum_c = 0, 0, 0
        for i in range(n):
            if bin[i] == 1:
                sum_a += num_list[i]
            elif bin[i] == 2:
                sum_b += num_list[i]
            elif bin[i] == 3:
                sum_c += num_list[i]
        mp += abs(a-sum_a)
        mp += abs(b-sum_b)
        mp += abs(c-sum_c)
        min_mp = min(min_mp, mp)
            
    print(min_mp)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61112
import java.util.Scanner;

class Main {

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

        int x=stdIn.nextInt();
        int a=x/500; //500円の枚数
        int b=x%500; //500円に換算した後の余り
        int c=b/5;
        
        System.out.println(a*1000+c*5);
        
    }

}

Measured memory_bytes: 23764
from collections import Counter
N = int(input())
S = input()
mx = 0
for i in range(1,N):
    pre = Counter(S[:i])
    back = Counter(S[i:])
    tmp = 0
    for k in pre.keys():
        if k in back:
            tmp += 1
    mx = max(mx, tmp)
print(mx)


Measured memory_bytes: 43628
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define inf (1ll<<60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
signed gcd(int a, int b){return b?gcd(b,a%b):a;}
signed lcm(int a,int b){return a*b/gcd(a,b);}

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int a,b;
    cin >> a >> b;
    cout << a*b/2 << endl;
}

Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
ll n, lim;
vector<ll> w, v;
ll memo[110][1000 * 110];
ll dp(ll i, ll j){
    if(j == 0) return 0;
    if(i == -1) return INF;
    if(memo[i][j] != -1) return memo[i][j];

    ll res = INF;
    res = min(res, dp(i - 1, j));
    if(j >= v[i]) res = min(res, dp(i - 1, j - v[i]) + w[i]);

    return memo[i][j] = res;
}


int main(void){
    cin >> n >> lim;
    w.resize(n);
    v.resize(n);

    for(int i = 0; i <= n; i++){
        for(int j = 0; j < 1000 * 110; j++){
            memo[i][j] = -1;
        }
    }
    ll total = 0;
    for(int i = 0; i < n; i++){
        cin >> w[i] >> v[i];
        total += v[i];
    }

    ll ans = 0;
    for(ll i = 0; i <= total; i++){
        if(dp(n - 1, i) <= lim) ans = max(ans, i);
    }

    cout << ans << endl;
}

Measured memory_bytes: 88320
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int k = scanner.nextInt();
			// result[i]はiを割って余りがk以上の数字の数
			long[] result = new long[n + 1];
			Arrays.fill(result, 0);
			IntStream.rangeClosed(k + 1, n)
					.forEach(i -> result[i] = (n / i) * (i - k) + Math.max((n % i) - Math.max(k - 1, 0), 0));
			System.out.println(Arrays.stream(result).sum());
		}
	}
}


Measured memory_bytes: 28880
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	string s;

	int n, i, j, k, ans = 0, a, b, ct;
	cin >> n;
	cin >> s;
	vector<int> s1(n + 1), s2(n  + 1); 
	s1[0] = 0;
	for (i = 0; i < n; i++) {
		s1[i + 1] = s1[i];
		if (s[i] == 'W') s1[i + 1]++;
	}
	s2[n] = 0;
	for (i = n; i > 0; i--) {
		s2[i - 1] = s2[i];
		if (s[i - 1] == 'E') s2[i - 1]++;
	}
	
	ans = n * 10;
	for (i = 0; i < n; i++) {
		ans = min(ans, s1[i] + s2[i + 1]);
	}

	cout << ans << "\n";


	return 0;
}


Measured memory_bytes: 2964
x = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(x[int(input())-1])

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vii = vector<pair<int, int>>;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

// 素因数分解; 返り値は(素数, 乗数)のvector配列
vector<pair<ll, int>> factorize(ll n) {
	vector<pair<ll, int>> res;
	for (ll i = 2; i * i <= n; ++i) {
		if (n % i) continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1) res.emplace_back(n, 1);
	return res;
}

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };
constexpr auto MAX = 100010;

// ──────────────────────────────────────────────────────────────────────────────

int main() {
	int n, k;
	cin >> n >> k;
	vl a(n);
	rep(i, n) cin >> a[i];
	sort(ASC(a));

	ll ans = 0;
	for (int i = 0; i < n - k; ++i) {
		ans += a[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<string>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

bool check_restorable ( string s, string t, int i_init ) {
    rep(i, t.length()) {
        if ( s[i+i_init] != t[i] && s[i+i_init] != '?' ) {
            return false;
        }
    }
    return true;
}

void restore ( string& s, string t, int idx ) {
    rep(i, t.length()) {
        s[i+idx] = t[i];
    }
    rep(i, s.length()) {
        if ( s[i] == '?' ) {
            s[i] = 'a';
        }
    }
    return;
}

int main(){
    string s, t;
    cin >> s >> t;
    int idx = -1;

    rep(i, s.length()-t.length()+1) {
        if ( check_restorable(s, t, i) ) {
            idx = i;
        }
    }
    if ( idx == -1 ) {
        cout << "UNRESTORABLE" << endl;
    }
    else {
        restore(s, t, idx);
        cout << s << endl;
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
t, a = map(int, input().split(' '))

for _ in range(N - 1):
    nt, na = map(int, input().split(' '))
    if nt >= t and na >= a:
        t = nt
        a = na
    else:
        tr = (t + nt - 1) // nt
        ar = (a + na - 1) // na
        r = max(tr, ar)
        t = r * nt
        a = r * na

print(t + a)


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

ll digit(ll a){
ll c=0;
while(a){a/=10;c++;}
return c;
}

int main(){
  ll i,j,N,M,bf=-1,cnt=1;
  cin>>N>>M;
  vector<ll> anslist(M);
  vector<data> v(M);
  rep(i,M){
    cin>>v[i].first.first>>v[i].first.second;
    v[i].second=i;
  }
  sort(v.begin(),v.end());
  rep(i,M){
    if(bf==v[i].first.first){
      cnt++;
    }else{
      cnt=1;
    }
    anslist[v[i].second]=v[i].first.first*1000000+cnt;
    bf=v[i].first.first;
  }
  rep(i,M){
    N=12-digit(anslist[i]);
    rep(j,N){cout<<0;}
    cout<<anslist[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 4608
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)
// cout << setprecision(10)

using namespace std;
typedef long long int ll;

int N;
int main(void){
    cin >> N;
    ll total = 0;
    for(int i=1;i<=N;i++){
        if(i%3!=0 and i%5!=0) total += i;
    }
    cout << total << endl;
    return 0;
}



Measured memory_bytes: 3636
n = int(input())

arr = [map(int,raw_input().split()) for i in range(n-1)]

def ceil(n,d):
	if n%d==0:
		return n/d

	else:
		return n/d+1

for i in range(n):
	t = 0

	for j in range(i,n-1):
		c,s,f = arr[j]
		t = max(ceil(t,f)*f, s) + c


	print t


Measured memory_bytes: 2692
let n, p = Scanf.scanf " %d %d" @@ fun a b -> a, b
let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" @@ (+) 0
let e, o = Array.fold_left (fun (e, o) a -> if a mod 2 = 0 then e + 1, o else e, o + 1) (0, 0) a_s
let memo = Array.make_matrix 51 51 @@ -1
let rec comb n k =
  if memo.(n).(k) > -1 then memo.(n).(k)
  else
    (memo.(n).(k) <- if n < k then 0 else if n = k then 1 else if k = 0 then 1
      else comb (n - 1) (k - 1) + comb (n - 1) k;
    memo.(n).(k))
let f n =
  let i = ref n in
  let sum = ref 0 in
  while !i <= o do sum := !sum + comb o !i; i := !i + 2 done;
  !sum
let _ =
  Printf.printf "%d\n" @@ if p = 1 && o = 0 then 0
    else
      let even = int_of_float @@ 2. ** float e in
      even * if p = 1 then f 1 else f 0

Measured memory_bytes: 384
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iostream>
#include <algorithm>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)

#define INF 1e9;
#define MOD 1e9+7;
#define INF64 1e18;


using namespace std;

int main() {

	SINT32 N = 0;
	SINT32 ma = 0;
	SINT32 co = INF;
	SINT32 ANS = 0;

	cin >> N;

	vector<SINT32> DATA(N);
	
	rep(i,0,N) {
		cin >> DATA[i];
		ma = MAX(ma,DATA[i]);
	}

	rep(i,0,N) {
		if (DATA[i] != ma) {
			if (DATA[i] > ma/2) {
				if (co > (DATA[i]- ma/2 -1)) {
					co = (DATA[i]- ma/2 -1);
					ANS = DATA[i];
				}
			} else {
				if ((ma/2-DATA[i]) <= co) {
					co = (ma/2)-DATA[i];
					ANS = DATA[i];
				}
			}
		}
	}

	cout << ma <<" " << ANS <<endl;
	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

//	// DATA.emplace_back(BUF);	//後ろに追加

//  DATA.erase(std::unique(DATA.begin(), DATA.end()), DATA.end());	//ソート後に使用

//	DATA.insert(DATA.begin() + X, 0);	//X番目の要素に0を挿入


//	vector<vector<SINT32>> DP(N,vector<SINT32>(3));　//2次元配列

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

// 	vector<pair<int,pair<int,int>>> DATA(M);
//	cin >> DATA[i].first;
//	cin >> DATA[i].second.first;
//	cin >> DATA[i].second.second;


//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();


/* 文字列回転
	string N;
	cin >> N;
	N = N[N.length()-1] + N.substr(0,N.length()-1);
*/

/* SET コンテナ
	set<SINT32> DATA;
	for (SINT32 i = 0; i < N; i++) {
		SINT32 buf;
		cin >> buf;
		DATA.insert(buf);
	}

	//全表示
    set<string>::iterator it; //  イテレータを用意
    for(it = DATA.begin(); it != DATA.end(); it++) {
        cout << *it << endl;
    }

	//N番目を一部表示
	set<string>::iterator it; //  イテレータを用意
	it = DATA.begin();
	rep (i,0,N) {
		it++;
	}
	cout << *it << endl;
*/

/* map
	map<string,SINT32> mp;
	SINT32 N = 0;
	SINT32 mx = 0;

	cin >> N;
	for (SINT32 i = 0; i < N; i++) {
		string s;
		cin >> s;
		mp[s]++;
	}
	for(auto it=mp.begin();it!=mp.end();it++) {
		mx=max(mx,it->second);
	}

*/

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i) sort((i).begin(),(i).end(), greater<int>());
#define F first
#define S second
constexpr auto INF = 1000000000;
constexpr auto LLINF = 9223372036854775807;
constexpr auto mod = 1000000007;
int main() {

	int n, m;
	cin >> n >> m;
	bool ab[8][8] = {};
	FOR(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		ab[a][b] = 1;
		ab[b][a] = 1;
	}
	VI g(n);
	FOR(i, n)g[i] = i;

	int ans = 0;
	do {
		if (g[0] == 0) {
			bool ok = 1;
			FOR(i, g.size() - 1) {
				if (!ab[g[i]][g[i + 1]])ok = 0;
			}
			if (ok)ans++;
		}
	} while (next_permutation(g.begin(), g.end()));
	
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*

fun main() {
    val sc = Scanner(System.`in`)

    val n = sc.nextInt()
    val m = sc.nextInt()

    val isBads = BitSet(n)
    val h = Array(n) { sc.nextInt() }
    
    repeat(m) {
        val a = sc.nextInt()
        val b = sc.nextInt()
        val ah = h[a-1]
        val bh = h[b-1]

        if (ah <= bh) {
            isBads[a-1] = true
        }
        if (bh <= ah) {
            isBads[b-1] = true
        }
    }

    println((1..n).count { !isBads[it - 1] })
}


Measured memory_bytes: 62608
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;
    static final int ALF = 26;

    Main() {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int Y = sc.nextInt();
        int Z = sc.nextInt();
        X-=Z*2;
        System.out.println(X/(Y+Z)+(X%(Y+Z))/Y);
    }

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


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;
bool isNum(ll x){
    bool nana=false, go=false, san=false;
    while(x>0){
        int num=x%10;
        x/=10;
        if(num==3) san=true;
        if(num==5) go=true;
        if(num==7) nana=true;
    }
    return san&&go&&nana;
}

int main(){
    fast_io

    ll a, b;
    cin>>a>>b;

    if(a>0){
        if(b>0) cout<<"Positive"<<endl;
        else if(b==0) cout<<"Zero"<<endl;
    }
    else if(a==0) cout<<"Zero"<<endl;
    else{//a<0
        if(b>=0) cout<<"Zero"<<endl;
        else {
            int n=b-a+1;
            if(n%2==0) cout<<"Positive"<<endl;
            else cout<<"Negative"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256