akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int INF=1000000000;
typedef long long ll;

//count the number of mutually prime numbers
ll Euler_phi(ll n){
    ll count=n;
    for (ll i = 2; i <= sqrt(n);i++){
        if(n%i==0){
            count -= count / i;
            while(n%i==0)
                n /= i;
        }
    }
    if(n>1)
        count -= count / n;
    return count;
}

//verify AOJ NTL 1 D http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_1_D&lang=jp

int main(){
    ll n;
    cin >> n;
    cout<<Euler_phi(n)<<endl;
    return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main(){
    IOS;
    string s;
    cin>>s;
    int ans=0;
    for(int i=0;i<s.size();i++){
        int curr=0;
        while(s[i]=='R'){
            i++;curr++;
        }
        ans=max(curr,ans);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3612
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    int a[3][3];
    bool f[3][3] {};

    rep(i, 3) rep(j, 3) read(a[i][j]);

    int N; read(N);
    rep(i, N) {
        int b; read(b);
        rep(y, 3) rep(x, 3) if (a[y][x] == b) f[y][x] = true;
    }

    bool bingo = false;
    rep(y, 3) {
        bingo |= (f[y][0] & f[y][1] & f[y][2]);
    }
    rep(x, 3) {
        bingo |= (f[0][x] & f[1][x] & f[2][x]);
    }
    bingo |= (f[0][0] & f[1][1] & f[2][2]);
    bingo |= (f[0][2] & f[1][1] & f[2][0]);

    print((bingo) ? "Yes" : "No");

    return 0;
}


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

int dislike[10];

bool check(int n) {
    while(n) {
        int curr = n % 10;
        if(dislike[curr] == 1) return false;
        n /= 10;
    }
    return true;
}

int main()
{
  int n, k;
  cin >> n >> k;
  for(int i = 0; i < k; i++) {
    int x;
    cin >> x;
    dislike[x] = 1;
  }
  
  for(int i = n; ; i++) {
      if(check(i)) {
          return cout << i , 0;
      }
  }
  
}


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


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

  
  ll k;
  cin >> k;
  ll amari = 7%k;
  ll ans = 1;
  while(amari){
    amari *= 10;
    amari += 7;
    amari %= k;
    ans++;
    if(ans>k){
      cout << -1 << endl;
      return 0;      
    }
  }
  cout << ans << endl;
  return 0;
    

}


Measured memory_bytes: 3552
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val a = sc.nextInt()
    val b = sc.nextInt()
    val ans = if(a==b) {
      "Draw"
    } else if(a==1 || a>b && b!=1) {
      "Alice"
    } else {
      "Bob"
    }
    System.out.println(ans)
  }
}


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

using lnt = long long;
using Real = long double;

#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(lnt i=0;i<(n);++i)
#define RANGE(i, a, b) for(lnt i=(a);i<(b);++i)
#define RREP(i, n) for(lnt i=(n)-1;i>= 0;--i)

#define ln '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define dcout cout<<fixed<<setprecision(20)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)

constexpr int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
constexpr Real eps = 1e-9; const Real pi = acosl(-1);
constexpr lnt BIG = INT_MAX/10, BBIG = LLONG_MAX/10;

template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<class T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<class T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
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 pint = pair<int, int>; using plnt = pair<lnt, lnt>;
using vint = vector<int>; using vlnt = vector<lnt>;
constexpr lnt MOD = 1e9+7;

int main(){
	summon_tourist;

	int A, B, C, K; cin >> A >> B >> C >> K;
	if(K < A){
		cout << K << ln;
		return 0;
	}
	K = max(K-A-B, 0);
	cout << A-K << ln;
}

Measured memory_bytes: 3640
#include <stdio.h>
#include <stdlib.h>


int dfs(int,int,int , int);

int tag();
void change(int *, int *);

int xarr[4]={-1,0,1,0},yarr[4]={0,-1,0,1};
int array[4][4],sum;
int main(){
  int i,j,zerox,zeroy;
  for(i=0;i<4;i++){
    for(j=0;j<4;j++){
      scanf("%d",&array[i][j]);
      if(array[i][j]==0){
	
	zerox=j;
	zeroy=i;	
      }
    }
  }
  
  for(sum=0;;sum++){
    if(dfs(0,10,zerox,zeroy)==1) break;
  }
  printf("%d\n",sum);  /*output*/
  return 0;
}
int  dfs(int dep, int prev, int zerox, int zeroy){
  int i,xx,yy,ta;
  ta=tag();
  if(ta==0) return 1;
  if(dep+ta>sum) return -1;
  
    for(i=0;i<4;i++){
      if(i-prev==-2 || i-prev==2) continue;
      xx=zerox+xarr[i];
      yy=zeroy+yarr[i];
      if(xx<0 || yy<0 || xx>=4 || yy>=4) continue;
      change(&array[zeroy][zerox],&array[yy][xx]);
      
      if(dfs(dep+1,i,xx,yy)==1) return 1;
      change(&array[zeroy][zerox],&array[yy][xx]);
      
    }
    return -1;
    
}



int tag(){
  int i,j,num=0;
  for(i=0;i<4;i++){
    for(j=0;j<4;j++){
      if(array[i][j]==0) continue;
      num+=abs((array[i][j]-1)/4-i)+abs((array[i][j]-1)%4-j);
      
 
    }
  }
  return num;
}

/*exchange array[zeroy][zerox] and array[yy][xx]*/
void change(int * num1, int *num2){  
  int ch;
  ch=*num1;
  *num1=*num2;
  *num2=ch;
}



Measured memory_bytes: 2084
package main

import "fmt"

func main() {
	var H, W int
	fmt.Scan(&H, &W)
	c := make([][]rune, H)
	for i := 0; i < H; i++ {
		c[i] = make([]rune, W)
	}
	s := ""
	for i := 0; i < H; i++ {
		fmt.Scan(&s)
		for j, v := range s {
			c[i][j] = v
		}
	}
	for i := 0; i < H; i++ {
		for j := 0; j < 2; j++ {
			for k := 0; k < len(c[i]); k++ {
				fmt.Printf("%c", c[i][k])
			}
			fmt.Printf("\n")
		}
	}
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N, R;
  cin >> N >> R;

  if (N >= 10) {
    cout << R << endl;
  } else {
    cout << R + 100 * (10 - N) << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;

const int INF = 1000000000;

struct MaxFlow {
  int N;
  VVI cap, flow;
  VI dad, Q;

  MaxFlow(int N) :
    N(N), cap(N, VI(N)), flow(N, VI(N)), dad(N), Q(N) {}

  void AddEdge(int from, int to, int cap) {
    this->cap[from][to] += cap;
  }

  int BlockingFlow(int s, int t) {
    fill(dad.begin(), dad.end(), -1);
    dad[s] = -2;

    int head = 0, tail = 0;
    Q[tail++] = s;
    while (head < tail) {
      int x = Q[head++];
      for (int i = 0; i < N; i++) {
        if (dad[i] == -1 && cap[x][i] - flow[x][i] > 0) {
          dad[i] = x;
          Q[tail++] = i;
        }
      }
    }

    if (dad[t] == -1) return 0;

    int totflow = 0;
    for (int i = 0; i < N; i++) {
      if (dad[i] == -1) continue;
      int amt = cap[i][t] - flow[i][t];
      for (int j = i; amt && j != s; j = dad[j])
        amt = min(amt, cap[dad[j]][j] - flow[dad[j]][j]);
      if (amt == 0) continue;
      flow[i][t] += amt;
      flow[t][i] -= amt;
      for (int j = i; j != s; j = dad[j]) {
        flow[dad[j]][j] += amt;
        flow[j][dad[j]] -= amt;
      }
      totflow += amt;
    }

    return totflow;
  }

  int GetMaxFlow(int source, int sink) {
    int totflow = 0;
    while (int flow = BlockingFlow(source, sink))
      totflow += flow;
    return totflow;
  }
};

int main(){
    int H, W;
    cin >> H >> W;

    MaxFlow mf(H+W+2);

    
    for(int y=0;y<H;y++){
        string row;
        cin >> row;
        for(int x=0;x<W;x++){
            if(row[x]=='o'){
                mf.AddEdge(2+y, 2+H+x, 1);
                mf.AddEdge(2+H+x, 2+y, 1);
            }else if(row[x]=='S'){
                mf.AddEdge(0, 2+y, INF);
                mf.AddEdge(2+y, 0, INF);
                mf.AddEdge(0, 2+H+x, INF);
                mf.AddEdge(2+H+x, 0, INF);
            }else if(row[x]=='T'){
                mf.AddEdge(1, 2+y, INF);
                mf.AddEdge(2+y, 1, INF);
                mf.AddEdge(1, 2+H+x, INF);
                mf.AddEdge(2+H+x, 1, INF);
            }
        }
    }

    ll ans = mf.GetMaxFlow(0, 1);
    if (ans >= INF){
        ans = -1;
    }
    cout << ans << endl;

    return 0;
}


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

double INF = 1'000'000'000.0;
typedef pair<double, int> P;

int main(){
    while (1){
        int n;
        cin >> n;
        if (!n) break;
        vector<vector<double>> sphere(n, vector<double>(4));
        for (int i = 0; i < n; i++) cin >> sphere[i][0] >> sphere[i][1] >> sphere[i][2] >> sphere[i][3];
        vector<vector<double>> distance(n, vector<double>(n, 0.0));
        for (int i = 0; i < n; i++){
            for (int j = i + 1; j < n; j++){
                double x = (sphere[i][0] - sphere[j][0]);
                double y = (sphere[i][1] - sphere[j][1]);
                double z = (sphere[i][2] - sphere[j][2]);
                double r = sqrt(x * x + y * y + z * z) - sphere[i][3] - sphere[j][3];
                if (r < 0) r = 0;
                distance[i][j] = r;
                distance[j][i] = r;
            }
        }

        double ans = 0;
        priority_queue<P, vector<P>, greater<P>> que;
        vector<bool> check(n, false);
        que.push({0, 0});
        while (que.size()){
            double d = que.top().first;
            int s = que.top().second;
            que.pop();
            if (check[s]) continue;
            check[s] = true;
            ans += d;
            for (int i = 0; i < n; i++){
                if (!check[i]) que.push({distance[s][i], i});
            }
        }
        cout << fixed;
        cout << setprecision(3) << ans << endl;
    }
}


Measured memory_bytes: 3476
// https://atcoder.jp/contests/abc145/tasks/abc145_e

#include "algorithm"
#include "functional"
#include "iostream"
#include "numeric"
#include "queue"
#include "set"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N, T;
  cin >> N >> T;
  VPL fs(N);

  rep(i, N) {
    ll a, b;
    cin >> a >> b;
    fs[i] = {a, b};
  }

  sort(all(fs));

  ll MAX = 6000;
  // dp[i][j] i (>=1) 番目の料理までだけを考えた時の、注文後 j
  // 分以下となる美味しさの最大値.
  VVL dp(N + 1, VL(MAX + 1));

  repf(i, 1, N + 1) {
    PL f = fs[i - 1];
    ll time = f.first;
    ll del = f.second;

    rep(j, MAX + 1) {
      chmax(dp[i][j], dp[i - 1][j]);

      if (time <= j && j - time < T) {
        chmax(dp[i][j], dp[i - 1][j - time] + del);
      }
    }
  }

  ll res = 0;
  rep(i, MAX + 1) { chmax(res, dp[N][i]); }

  cout << res << endl;
}

void solve2() {
  ll N, T;
  cin >> N >> T;
  VPL fs(N);

  rep(i, N) {
    ll a, b;
    cin >> a >> b;
    fs[i] = {a, b};
  }

  sort(all(fs));

  // dp[i][j] i (>=1) 番目の料理までだけを考えた時の、注文・食事後 j
  // 分以下となる美味しさの最大値
  VVL dp(N + 1, VL(T + 1));

  repf(i, 1, N + 1) {
    PL f = fs[i - 1];
    ll time = f.first;
    ll del = f.second;

    rep(j, T + 1) {
      chmax(dp[i][j], dp[i - 1][j]);

      if (time <= j) chmax(dp[i][j], dp[i - 1][j - time] + del);
    }
  }

  ll res = 0;

  // i 番目まで食べるケースの最大値。かかる時間でソートしているため i
  // 番目は最後に食べるとして良い
  rep(i, N - 1) { chmax(res, dp[i + 1][T - 1] + fs[i + 1].second); }

  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 141184
#include <bits/stdc++.h>
using namespace std;
int dp[100001];
int mincost(int arr[], int n)
{
	if (n == 1)
		return 0;
	if (n < 1)
		return 10000000;

	if (dp[n] != -1)
		return dp[n];

	int a = abs(arr[n] - arr[n - 1]) + mincost(arr, n - 1);
	int b = abs(arr[n] - arr[n - 2]) + mincost(arr, n - 2);
	return dp[n] = min(a , b );
}

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

	int arr[n + 1];

	for (int i = 1; i < n + 1; i++)
		cin >> arr[i];
	memset(dp, -1, sizeof(dp));
	cout << mincost(arr, n);
}

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

int main(){
  string s;
  cin >> s;
  sort(s.begin(),s.end());//これによって数字1-9▶英大文字A-Z▶英小文字a-zの順に優先的に前に来て並ぶ
  map<char,bool> check;
  
  for(char i:s){//for(変数宣言:範囲)
    if (check.count(i)) continue;
    else {
      int t = count(s.begin(),s.end(),i);//第3引数は探したい対象
      if (t % 2 != 0){
        cout << "No" << "\n";
        return 0;
      }
    }
  }
  cout << "Yes" << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

signed main()
{
    int a;
    cin>>a;
    cout << a + a * a + a * a * a << endl;
    return 0;
}

Measured memory_bytes: 3628
N, K = map(int, input().split())
h = list(map(int, input().split())) + [0]*(N+K)

dp = [10**100] * (N + K + 100)
dp[0] = 0
for i in range(N-1):
    for j in range(1, K+1):
        dp[i + j] = min(dp[i + j], dp[i] + abs(h[i+j] - h[i]))
print(dp[N-1])

Measured memory_bytes: 55392
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;

template<class T> T umax(T a,T b) {return (a>b?a:b);}
template<class T> T umin(T a,T b) {return (a<b?a:b);}
template<class T,class P> T umax(T a,P b) {return (a>b?a:b);}
template<class T,class P> T umin(T a,P b) {return (a<b?a:b);}

typedef long long int ll;
const int maxn = 1e5+7;
const ll mod = 1e9+7;

bool compare(const pair<ll,ll>& x, const pair<ll,ll>& y) {
    if(x.second == y.second) return x.first < y.first;
    return x.second < y.second;
}

ll power(ll a,ll b) {
    ll res = 1;
    while(b) {
        if(b&1) {
            res = (res*a)%mod;
        }
        a = (a*a)%mod;
        b >>= 1;
    }
    return res;
}

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

double dp[305][305][305];
int n;

int main() {
    int x;
    cin >> n;
    int a,b,c;
    a = b = c = 0;
    for(int i=0;i<n;i++) {
        cin >> x;
        if(x == 1) a++;
        else if(x == 2) b++;
        else c++;
    }
    for(int k=0;k<=n;k++) {
        for(int j=0;j+k<=n;j++) {
            for(int i=0;i+j+k<=n;i++) {
                if(i==0 && j==0 && k==0) {
                    continue;
                }
                if(i+j+k > n) {
                    continue;
                }
                if(i > 0) {
                    dp[i][j][k] += 1.0*i/(i+j+k) * dp[i-1][j][k];
                }
                if(j > 0) {
                    dp[i][j][k] += 1.0*j/(i+j+k) * dp[i+1][j-1][k];
                }
                if(k > 0) {
                    dp[i][j][k] += 1.0*k/(i+j+k) * dp[i][j+1][k-1];
                }
                dp[i][j][k] += 1.0*n/(i+j+k);
            }
        }
    }
    printf("%.16lf\n",dp[a][b][c]);
    return 0;
}


Measured memory_bytes: 219392
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int digit(ll n) {
    int ret = 0;
    while(n != 0) {
        ret++;
        n /= 10;
    }
    return ret;
}

ll p(int m) {
    ll ret = 1;
    rep(i,0,m) ret *= 10;
    return ret;
}

int main() {
    ll n; cin >> n;
    ll ans = 0;
    int d = digit(n);

    rep(i,0,1 << (d - 1)) {
        ll n_t = n;
        ll temp = 0;
        int s = 0;
        // cout << i << ":" << endl;
        rep(j,0,d) {
            if(i >> j & 1) {
                // cout << p(j - s + 1) << endl;
                temp += n_t % p(j - s + 1);
                n_t /= p(j - s + 1);
                s = j + 1;
            }
        }
        temp += n_t;
        // cout << temp << endl;
        ans += temp;
    }
    cout << ans << endl;
    return 0;
}

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

bool check(char c)
{
	if (c == 'A' || c == 'C' || c == 'G' || c == 'T')
		return true;
	else
		return false;
}

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

	int ans = -1;
	int pos = 0;

	while (pos < (int)S.size()) {
		int cnt = 0;
		--pos;
		while (check(S[++pos]) && pos < (int)S.size()) ++cnt;
		while (!check(S[++pos]) && pos < (int)S.size());
		ans = max(ans, cnt);
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back()
#define ALL(a) (a).begin(),(a).end()

using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;


signed main(){
    int n; cin >> n;
    int a[n+1],b[n];
    rep(i,n+1) cin >> a[i];
    rep(i,n) cin >> b[i];
    int res=0;
    ll ans=0;
    rep(i,n){
        if(res>a[i]){
            ans+=a[i];
            res=b[i];
            continue;
        }else{
            ans+=res;
            a[i]-=res;
        }
        if(a[i]>b[i]){
            ans+=b[i];
            res=0;
        }else{
            ans+=a[i];
            res=b[i]-a[i];
        }
    }
    ans+=min(res,a[n]);
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  int N, M;
  cin >> N >> M;
  //vector <int> A(N);
  //vector <int> B(N);
  vector <P> p(N);
  rep(i,N) cin >> p[i].first >> p[i].second;
  sort(all(p));
  ll ans = 0;  //必要なお金
  for (int i = 0; i < N; i++){
    //この店で購入する本数
    ll buy = min(M, p[i].second);
    ans += buy * p[i].first;
    M -= buy;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3940
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define sd(t)       scanf("%d",&(t))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define hii         cout << "hii" << endl
#define okay        cout << "okay" << endl
#define hey         cout << "hey" << endl
const int INF = 1e12;
const int MOD = 1e9+7;
 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.x << ' ' << v.y; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.x << "=>" << i.y << ')' << ' '; return os; } 
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE
 
clock_t time_p=clock();
void starboy1299()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
 
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("jjj.txt", "w", stdout);
    #endif
} 

void solve(){
    int n;
    cin >> n;
    vi arr(n);
    rep(i, 0, n){
        cin >> arr[i];
    }

    int curr = 1000;

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

        if(arr[i] > arr[i-1]){
            int temp = curr % arr[i-1];
            int val = curr/arr[i-1];
            curr = val*arr[i] + temp;
        }

    }

    cout << curr << endl;

}          

int32_t main(){
    fast();
    int t = 1;
    // cin>> t;
    for(int i=1; i<=t; i++){
        // cout << "Case #" << i << ": ";
        solve();
    }
    starboy1299();
}

Measured memory_bytes: 3840
#include <iostream>
#include <map>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

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

    int n; cin >> n;
    map<string, int> count;
    REP(i, n) {
        string s; cin >> s;
        count.insert(make_pair(s, 0));
        count[s]++;
    }

    int maxi = 0;
    for (auto itr = count.begin(); itr != count.end(); itr++)
        maxi = max(maxi, itr->second);

    for (auto itr = count.begin(); itr != count.end(); itr++)
        if (itr->second == maxi)
            cout << itr->first << '\n';
    return 0;
}


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

int main(){
    int a,b, c,d;
    double e;
    cin >> a >> b;
    c = a/b;
    d = a%b;
    e = (double(a))/(double(b));
    
    cout << fixed;
    cout << c << " "<< d  << " "<< setprecision(5) << e << endl;
}


Measured memory_bytes: 3292
#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;

const long long INF = 1LL << 60;
const ll MOD = ll(1e9)+7;


int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}


int main() {
  ll X;
  cin >> X;

  vector<vector<ll>> vec;

  for (ll i = -3000; i <= 3000; i++) {
    vector<ll> tmp;
    tmp.push_back(i);
    tmp.push_back(pow(i, 5));
    vec.push_back(tmp);
  }

  ll A, B;

  for (ll i = 0; i < vec.size(); i++) {
    for (ll j = 0; j < vec.size(); j++) {
      if((vec.at(i).at(1) - vec.at(j).at(1)) == X) {
        A = vec.at(i).at(0);
        B = vec.at(j).at(0);
      }
    }
  }
  
  


  cout << A << " " << B << endl;
  return 0;
}

Measured memory_bytes: 4420
import Data.List                                                                                                                                      
main :: IO ()                                                                                                                                         
main = do                                                                                                                                             
  _ <- getLine                                                                                                                                        
  bs <- map read . words <$> getLine                                                                                                                  
  putStrLn $ case solve bs [] of                                                                                                                      
    Nothing -> "-1"                                                                                                                                   
    Just x -> init $ unlines $ map show x                                                                                                             
                                                                                                                                                      
solve :: [Int] -> [Int] -> Maybe [Int]                                                                                                                
solve [] ps = Just ps                                                                                                                                 
solve xs ps =                                                                                                                                         
  let check = filter (\(x,y) -> x==y) $ zip xs [1..]                                                                                                  
  in if null check                                                                                                                                    
     then Nothing                                                                                                                                     
     else solve (map fst . delete (last check) $ zip xs [1..]) $ (:ps) . fst . last $ check

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

#define ll long long
// #define MULTI_TEST

int a, b, h, m;
// c2 = a2 + b2 - 2abcos(x)

void solve() {
	cin >> a >> b >> h >> m;
	long double o1 = 30 * (h + m/60.0);
	long double o2 = 6 * (m);
	
	long double o = abs(o2-o1);

	long double ans = sqrt( a*a + b*b - 2*a*b*cos(o*M_PI/180.0) );
	cout << fixed << setprecision(10) << ans;
}



int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
#ifdef MULTI_TEST
	int t;
	cin >> t;
	while(t--) {
		solve();
		cout << "\n";
	}
#else
	solve();
	cout << "\n";
#endif

	return 0;
}


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

ll N, K, sum=0;
vector<ll> H;

signed main(){
    cin >> N >> K;
    H.resize(N);
    for(int i=0;i<N;i++) {
        cin >> H[i];
    }
    sort(H.begin(), H.end());
    if(K>=N) cout << 0;
    else {        
        for(int i=0;i<N-K;i++) {
            sum += H[i];
        }
        cout << sum;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1792
n = int(input())
a = [int(x) for x in input().split()]
four = 0
two = 0
el = 0
for i in range(n):
    if a[i] % 4 == 0:
        four += 1
    elif a[i] % 2 == 0 :
        two += 1
    else:
        el += 1

if two == 0:
    if four + 1 >= el:
        print("Yes")
    else:
        print("No")
else:
    if four >= el:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
int A,B,C,X,ans=0;
int main(){
  cin >> A >> B >> C >> X;
  for(int i=0;i<=A;i++){
    for(int j=0;j<=B;j++){
      for(int k=0;k<=C;k++){
        if(500*i+100*j+50*k==X) ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	h := readi()
	w := readi()
	if h == 1 || w == 1 {
		fmt.Println(1)
		return
	}
	fmt.Println((h*w + 1) / 2)
}

// IO---------------------------------------------------

func readi() (n int) {
	fmt.Scan(&n)
	return
}

func readf() (n float64) {
	fmt.Scan(&n)
	return
}

func reads() (n string) {
	fmt.Scan(&n)
	return
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func readSlice() []string {
	return strings.Split(readLine(), " ")
}

func atoi(a []string) (b []int) {
	b = make([]int, len(a))
	for i := range a {
		b[i], _ = strconv.Atoi(a[i])
	}
	return
}

func atof(a []string) (b []float64) {
	b = make([]float64, len(a))
	for i := range a {
		b[i], _ = strconv.ParseFloat(a[i], 64)
	}
	return
}

func readSlice2(n int) (a []int, b []int) {
	a = make([]int, n)
	b = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

func readFloatSlice2(n int) (a []float64, b []float64) {
	a = make([]float64, n)
	b = make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

func yesOrNo(b bool) {
	if b {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}

func yesorNO(b bool) {
	if b {
		fmt.Println("YES")
		return
	}
	fmt.Println("NO")
}

func yesorno(b bool) {
	if b {
		fmt.Println("yes")
		return
	}
	fmt.Println("no")
}

// calc---------------------------------------------------

func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}

func ave(a []int) (ave int) {
	for i := 0; i < len(a); i++ {
		ave += a[i]
	}
	ave /= len(a)
	return
}

func eq(a []string, b []string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] != b[i] {
			return false
		}
	}
	return true
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func max(a ...int) int {
	max := a[0]
	for i := 1; i < len(a); i++ {
		if max < a[i] {
			max = a[i]
		}
	}
	return max
}

func min(a ...int) int {
	min := a[0]
	for i := 1; i < len(a); i++ {
		if min > a[i] {
			min = a[i]
		}
	}
	return min
}

func mid(a []int) int {
	sort.Ints(a)
	return a[len(a)/2]
}

func sum(a []int) (ans int) {
	for i := range a {
		ans += a[i]
	}
	return
}


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

int main(void) {

	int num, temp, valid_amount = 0;
	cin >> num;
	map<int,int> mp;

	for (int i = 0; i < num; i++) {
		cin >> temp;
		if (mp.count(temp)) mp.at(temp)++;
		else mp[temp] = 1;
	}

	for (auto it : mp) {
		if (it.first <= it.second) valid_amount += it.first;
	}

	cout << num - valid_amount << endl;
	return 0;
}


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int s, w; std::cin >> s >> w;
  std::cout << (s <= w ? "unsafe" : "safe") << "\n";
}


Measured memory_bytes: 3636
#include <stdio.h>
#pragma warning(disable : 4996)
char c[10]; const char d[3] = "bw";
int main() {
	while (~scanf("%c", &c[0])) {
		if (c[0] == '0') break;
		for (int i = 1; i < 9; i++) {
			if (i % 3 == 0) getchar();
			scanf("%c", &c[i]);
		}
		bool ok = false;
		for (int i = 0; i < 2; i++) {
			bool flag = false;
			if (c[0] == d[i] && c[1] == d[i] && c[2] == d[i]) flag = true;
			if (c[3] == d[i] && c[4] == d[i] && c[5] == d[i]) flag = true;
			if (c[6] == d[i] && c[7] == d[i] && c[8] == d[i]) flag = true;
			if (c[0] == d[i] && c[3] == d[i] && c[6] == d[i]) flag = true;
			if (c[1] == d[i] && c[4] == d[i] && c[7] == d[i]) flag = true;
			if (c[2] == d[i] && c[5] == d[i] && c[8] == d[i]) flag = true;
			if (c[0] == d[i] && c[4] == d[i] && c[8] == d[i]) flag = true;
			if (c[2] == d[i] && c[4] == d[i] && c[6] == d[i]) flag = true;
			if (flag) {
				ok = true; printf("%c\n", d[i]); break;
			}
		}
		if (!ok) printf("NA\n"); getchar();
	}
	return 0;
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

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

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  int n;
  std::cin >> n;
  vi c(n + 1), s(n + 1), f(n + 1);
  REP(i, n - 1) {
    c[i] = read();
    s[i] = read();
    f[i] = read();
  }
  REP(i, n) {
    int time = 0;
    time += s[i] + c[i];
    FOR(j, i + 1, n - 1) {
      if (time > s[j]) {
        time += f[j] - (time % f[j] == 0 ? f[j] : time % f[j]);
      } else {
        time += s[j] - time;
      }
      time += c[j];
    }
    print(time);
  }
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n:usize,
        m:usize,
        a: [usize; n]
    }

    let total: usize = a.iter().sum();

    let mut sorted = a.clone();
    sorted.sort();
    sorted.reverse();

    if sorted[m - 1] * 4 * m < total {
        println!("No");
    } else {
        println!("Yes");
    }
}


Measured memory_bytes: 4352
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
# include <array>
# include <climits>
#define ll long long int
#define rep(i,rept) for (ll i = 0; i < rept; i++)
#define yes(b) std::cout<< (b ? "Yes" : "No")
#define YES(b) std::cout<< (b ? "YES" : "NO")
using namespace std;
/*int ketawa(ll num) {
	int dig, sum = 0;
	while (num) {
		dig = num % 10;
		sum = sum + dig;
		num = num / 10;
	}
	return sum;
}
*/
bool keta(ll num, vector<int> v) {
	int dig;
	while (num) {
		dig = num % 10;
		for (auto& i : v) {
			if (dig == i) {
				return false;
			}
		}
		num = num / 10;
	}
	return true;
}

ll func(ll a, ll b, ll c, ll d,int n) {
	return ((c / (d - b) + n)*(d - b)) + (a % (d - b));
}
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	ll a[1001];
	ll aa[1001];
	ll b[1001];
	ll bb[1001];
	cin >> n;
	a[0] = 1;
	b[0] = 1;
	aa[0] = 1;
	bb[0] = 1;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i] >> b[i];
		aa[i] = a[i];
		bb[i] = b[i];
		aa[i] *= std::max((aa[i - 1] + a[i] - 1) / a[i], (bb[i - 1] + b[i] - 1) / b[i]);
		bb[i] *= std::max((aa[i - 1] + a[i] - 1) / a[i], (bb[i - 1] + b[i] - 1) / b[i]);
	}
	cout << aa[n] + bb[n];
	return 0;
}


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

void main_()
{
    ll N;
    cin >> N;

    ll x4num = 0;
    ll x2num = 0;
    for (ll i = 0; i < N; ++i) {
        int a;
        cin >> a;
        if (a % 4 == 0) {
            x4num++;
        } else if (a % 2 == 0) {
            x2num++;
        }
    }
    if (x4num * 2 + 1 + 2 * (x2num / 2) < N) {
        cout << "No\n";
    } else {
        cout << "Yes\n";
    }
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define forn(x, n)              for (int x = 0; x < n; x++)
#define forr(x, n)              for (int x = n; x >= 0; x--)
#define fore(x, a, b, c)        for (int x = a; x <= b; x += c)
#define forre(x, a, b, c)       for (int x = a; x >= b; x -= c)
#define clr                     cin.ignore(numeric_limits<streamsize>::max(), '\n')
#define all(container)          (container).begin(), (container).end()
#define rall(container)         (container).rbegin(), (container).rend()
#define tracev(v)               for (auto& x: v) cerr << x << " "; cerr << '\n';
#define trace2v(v)              for (auto& x: v) cerr << x.fi << " - " << x.se << '\n'; cerr << '\n';
#define FILL(x, val)            memset(x, val, sizeof(x))
#define pb                      push_back
#define eb                      emplace_back
#define fi                      first
#define se                      second
#define mod                     (int)1000000007
#define INF                     (int)0x3f3f3f3f

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }  

typedef long long ll; 
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifndef ONLINE_JUDGE
    freopen("errlog", "w", stderr);
#endif
    ll n, k; cin >> n >> k;
    vector<ll> h(n);
    forn(i, n) cin >> h[i];
    sort(rall(h));
    ll ans = 0;
    fore(i, k, n-1, 1) {
        ans += h[i];
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 1792
#pragma comment(linker, "/STACK:1000000000")
#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <memory>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <ctime> 
#include <stack>
#include <iostream>
#include <fstream>

#define mp make_pair
#define pb push_back

using ll = long long;
using ld = long double;

using namespace std;

const int MAXN = 100001;
const int LG = 17;


struct prefsum {
	int p[LG];
	int start;

	int id(int x) {
		return start + x;
	}

	int& operator[] (int index) {
		return p[index];
	}

};

const int MAXM = MAXN * LG + MAXN;
vector <int> e[MAXN];
vector <int> partof[MAXM];
vector <int> sumof[MAXM];
int a[MAXM];
prefsum ps[MAXN];
int h[MAXN];

int n;
int possible[MAXN], pose = 0;

int merge(int v1, int v2) {
	if ((v1 == 0) || (v2 == 0)) return 0;
	if ((v1 == -1) && (v2 == -1)) return -1;
	if ((v1 != -1) && (v2 != -1)) return 0;
	return v1 + v2 + 1;
}

void upd(int x) {
	a[x] = -1;
	for (int u : sumof[x]) {
		a[x] = merge(a[x], a[u]);
	}
}

void go(int x) {
	if (x < n) {
		if (a[x] != -1) possible[pose++] = x;
	}
	for (int u : partof[x]) {
		upd(u);
		if (a[u] != 0) go(u);
	}
}

int curt;

void adedge(int fr, int t) {
	sumof[fr].push_back(t);
	partof[t].push_back(fr);
}

void dfs(int v, int p) {
	h[v] = h[p] + 1;
	ps[v].start = curt;
	assert(curt + LG < MAXM);
	ps[v][0] = p;
	a[curt] = curt;
	for (int i = 1; i < LG; i++) {
		ps[v][i] = ps[ps[v][i - 1]][i - 1];	
		adedge(ps[v].id(i), ps[v].id(i - 1));
		adedge(ps[v].id(i), ps[ps[v][i - 1]].id(i - 1));
	}
	curt += LG;
	for (int u : e[v]) {
		if (u != p)
			dfs(u, v);
	}
}

void advance(int ci, int& x, int j) {
	adedge(ci, ps[x].id(j));
	x = ps[x][j];
}

int main() {
	//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0); cout.setf(ios::fixed); cout.precision(20);
	cin >> n;
	memset(a, 0, sizeof(a));
	for (int i = 1; i < n; i++) {
		int a, b;
		cin >> a >> b;
		e[a].push_back(b);
		e[b].push_back(a);
	}
	curt = n;
	dfs(1, 1);
	for (int i = 1; i < n; i++) {
		int c, d;
		cin >> c >> d;
		if (ps[c][0] == d) {
			a[i] = ps[c].id(0);
			possible[pose++] = i;
		} else if (ps[d][0] == c) {
			a[i] = ps[d].id(0);
			possible[pose++] = i;
		} else {
			for (int j = LG - 1; j >= 0; j--) {
				if (h[c] >= h[d] + (1 << j)) {
					advance(i, c, j);
				}
				if (h[d] >= h[c] + (1 << j)) {
					advance(i, d, j);
				}
			}
			if (c != d) {
				for (int j = LG - 1; j >= 0; j--) {
					if (ps[d][j] != ps[c][j]) {
						advance(i, d, j);
						advance(i, c, j);
					}
				}
				advance(i, c, 0);
				advance(i, d, 0);
			}
		}
	}
	for (int posb = 0; posb < pose; posb++) {
		int v = possible[posb];
		a[a[v]] = -1;
		go(a[v]);
	}
	assert(pose <= n - 1);
	if (pose == n - 1) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

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

int compare_char(const void* left, const void* right) {
    char *left_char = (char *)left;
    char *right_char = (char *)right;

    return strcmp( left_char, right_char );
}

int main(){
    int N;
    scanf("%d",&N);
    char S[N][11];
    int count = 1;
    for(int i = 0;i<N;i++) scanf("%s",S[i]);
    qsort(S,N,sizeof(S[0]),compare_char);
    for(int i = 1;i<N;i++) if(strcmp(S[i-1],S[i])!=0) count++;
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 5736