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

const int MAX_N = (int)(1e5 + 5);

int n, c;
string s;

string ans;

bool decide(char c0, char c1) {
  string cand(n + 2, 'z');

  cand[0] = c0;
  cand[1] = c1;
  for (int i = 2; i < n + 2; ++i) {
    if (cand[i - 1] == 'S') {
      if (s[(i - 1) % n] == 'o') cand[i] = cand[i - 2];
      else cand[i] = cand[i - 2] == 'S' ? 'W' : 'S';
    }
    else {
      if (s[(i - 1) % n] == 'o') cand[i] = cand[i - 2] == 'S' ? 'W' : 'S';
      else cand[i] = cand[i - 2];
    }
  }

  ans = cand;

  return (cand[n] == cand[0] && cand[n + 1] == cand[1]);
}

int main(void) {
  // Here your code !
  scanf("%d", &n);
  cin >> s;

  if (decide('S', 'S')) {
    for (int i = 0; i < n; ++i) {
      printf("%c", ans[i]);
    }
  }
  else if (decide('S', 'W')) {
    for (int i = 0; i < n; ++i) {
      printf("%c", ans[i]);
    }
  }
  else if (decide('W', 'S')) {
    for (int i = 0; i < n; ++i) {
      printf("%c", ans[i]);
    }
  }
  else if (decide('W', 'W')) {
    for (int i = 0; i < n; ++i) {
      printf("%c", ans[i]);
    }
  }
  else {
    printf("-1");
  }

  printf("\n");

  return 0;
}


Measured memory_bytes: 768
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <cctype>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()

string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";

/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}


int main(void){
  ll N, A, B, W, H, C, D, Q, X, Y;
  ll ans;
  string S, T;
  cin >> A >> B >> C;
  if (A+B >= C) cout << "Yes" << endl;
  else cout <<"No" << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
using namespace std;
vector<int>v[100001];
int len[100001]={0};
int dfs(int x)
{
	if(len[x]!=0)
		return len[x];
	for(int i=0;i<v[x].size();i++)
	{
		int ll=1+dfs(v[x][i]);
		len[x]=max(len[x],ll);
	}
	return len[x];
}
int main()
{
	int n,m;
	cin>>n>>m;
	 int x,y;
	for(int i=0;i<m;i++)
	{
		cin>>x>>y;
		v[x].push_back(y);
	}
	int res=0;
	  for(int i=1;i<=n;i++)
	  {
	  		res=max(res,dfs(i));
	  }
	cout<<res<<"\n";
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define int long long int
#define ii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
#define MOD 998244353
#define output(x) for (auto a:x) cout<<a<<" ";cout<<endl;
#define output2(x) for (auto a:x) cout<<a.fi<<" "<<a.se<<endl;
 
int power(int x,int y,int mod) 
{ 
 	int ret = 1;
 	x = x % mod;
 	while (y){
 		if(y&1) ret = (ret*x)%mod;
 		y = y>>1;
 		x = (x*x)%mod;
    } 
    return ret%mod; 
}

int isprime(int x)
{
	for (int i=2;i*i<=x;i++)
		if (x%i==0) return 0;
	return 1;
}
 
 bool cmp(ii a,ii b){
	return a.se<b.se;
}
void solve()
{	
	int n;
	cin>>n;
	int ans = 0;
	for (int i=1;i<=n;i++){
		for (int j=1;j<=n;j++){
			for (int k=1;k<=n;k++){
				ans += __gcd(i,__gcd(j,k));
			}
		}
	}
	cout<<ans<<endl;
}
 
 
signed main(){
	// int t;
	// cin>>t;
	// while (t--)	
	solve();	
 
}

Measured memory_bytes: 3592
#include <stdio.h>

int main(void)
{
   int S,h,m,s;
   scanf("%d", &S);

   h=S/3600;
   m=(S-h*3600)/60;
   s=S-h*3600-m*60;

   printf("%d:%d:%d\n", h,m,s);
    
    return 0;
}

Measured memory_bytes: 592
#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)
#define var(Type, ...)  Type __VA_ARGS__; input(__VA_ARGS__)
#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); }
inline i64  sigma(i64 n)            { return (n * (n + 1) >> 1); }
inline i64  updiv(i64 a, i64 b)     { return (a + b - 1) / b; }
inline i64  sqr(i64 n)              { return n * n; }
inline string to_string(char c)     { return string(1, c); }
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 input() {}
template <class Head, class... Tail>
inline void input(Head &head, Tail&... tail) { cin >> head; input(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;
}

template <typename Func>
struct FixPoint : Func {
    inline constexpr FixPoint(Func &&f) noexcept : Func(forward<Func>(f)) {}

    template <typename... Args>
    inline decltype(auto) operator()(Args &&... args) const {
        return Func::operator()(*this, forward<Args>(args)...);
    }
};

template< typename Func >
inline decltype(auto) makeFixPoint(Func &&f) {
    return FixPoint< Func >{forward< Func >(f)};
}
// }}} End Header

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

    var(i64, S, c);

    i64 ans = 0;
    {
        i64 k = min(S, c / 2);
        ans += k;
        S -= k;
        c -= k * 2;
    }

    {
        ans += c / 4;
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 256
/*** I came, I saw, I conquered. ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;typedef unsigned long long ull;
#define sc(a) cin >> a
#define pf(a) cout << a << endl
#define forIn(arr, num) for(ll i = 0; i < num; i++) cin >> arr[i];
#define vpnt(ans) for(ll i = 0; i < ans.size(); i++) cout << ans[i] << (i + 1 < ans.size() ? ' ' : '\n');
#define mod 1000000007
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define GET_SET_BITS(a) (__builtin_popcount(a))
#define GET_SET_BITSLL(a) ( __builtin_popcountll(a))
#define GET_TRAIL_ZERO(a) (__builtin_ctz(a))
#define GET_LEAD_ZERO(a) (__builtin_clz(a))
#define GET_PARITY(a) (__builtin_parity(a))
#define no cout << "NO" << endl
#define yes cout << "YES" << endl
void go() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
/*----------------------------------------------------------------*/
ll binary_pow(ll n, ll p) {
    return p ? binary_pow(n * n % mod, p >> 1) * (p & 1 ? n : 1) % mod : 1;
}

void solve() {
    int n;
    sc(n);

    ll ans = (binary_pow(10, n) - 2 * binary_pow(9, n) + binary_pow(8, n)) % mod;
    while(ans < 0) {
        ans += mod;
    }    

    cout << (ans % mod) << endl;
}

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

Measured memory_bytes: 3652
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

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

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}

int main() {
  ll X, Y;
  get(X, Y);
  if (X % Y == 0) {
    print(-1);
  } else {
    ll Z = X;
    while (Z % Y == 0) {
      Z += X;
    }
    print(Z);
  }
  return 0;
}

Measured memory_bytes: 256
import time
start=time.time()
A,B,N=[int(s) for s in input().split()]
x=((N+1)//B)*B-1
ans=set()
ans.add((A*N)//B-A*(N//B))
while x>0:
  ans.add((A*x)//B-A*(x//B))
  x-=B
  if (time.time()-start)>1.7:
    break
print(max(ans))


Measured memory_bytes: 9128
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}



int main(){
   int n;cin>>n;
   vector<ll>v;
   v.push_back(2);
   v.push_back(1);
   REP(i,2,n){
       v.push_back(v[i-1]+v[i-2]);
   }
   cout<<v[n];
}



Measured memory_bytes: 256
import re
import numpy as np
import heapq

X, Y, Z, K = [int(item) for item in re.split(r"\s", input())]
A = [int(item) for item in re.split(r"\s", input())]
B = [int(item) for item in re.split(r"\s", input())]
C = [int(item) for item in re.split(r"\s", input())]


A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

total = A[0] + B[0] + C[0]

A = [A[0] - a for a in A]
B = [B[0] - b for b in B]
C = [C[0] - c for c in C]

q = [[0, 0, 0, 0]]
heapq.heapify(q)

for _ in range(K):
    val, a_i, b_i, c_i = heapq.heappop(q)
    print(total - val)

    if a_i + 1 <= len(A) - 1:
        c_1 = [A[a_i + 1] + B[b_i] + C[c_i], a_i + 1, b_i, c_i]
        if c_1 not in q:
            heapq.heappush(q, c_1)
    if b_i + 1 <= len(B) - 1:
        c_2 = [A[a_i] + B[b_i + 1] + C[c_i], a_i, b_i + 1, c_i]
        if c_2 not in q:
            heapq.heappush(q, c_2)
    if c_i + 1 <= len(C) - 1:
        c_3 = [A[a_i] + B[b_i] + C[c_i + 1], a_i, b_i, c_i + 1]
        if c_3 not in q:
            heapq.heappush(q, c_3)


Measured memory_bytes: 21316
/**
      Institution : Hajee Mohammad Danesh Science and Technology University,Dinajpur,Bangladesh (H S T U).
      Name        : Sourav Roy (Shuvo)
      Department  : Computer Science and Engineering (Batch - CSE'19)
      Email       : souravkumarroy813965@gmail.com
**/


#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define all(a) a.begin(),a.end()

void solve()
{
    int n,i,x,sum=0;
    cin >> n;
    map <int,int> mp;
    for(i=0; i<n; i++)
    {
        cin >> x;
        mp[x]++;
    }

    for(auto it : mp)
    {
        if(it.first > it.second)
        {
            sum += it.second;
        }
        else if(it.first < it.second)
        {
            sum += (it.second - it.first);
        }
    }

    cout << sum << endl;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    solve();

}
/**
Test Case :

**/


Measured memory_bytes: 9592
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

vector<string> split(const string& input, char delimiter)
{
	istringstream stream(input);
	string field;
	vector<string> ret;
	while (getline(stream, field, delimiter))
		ret.push_back(field);
	return ret;
}

signed main() {
	for (string s; getline(cin, s) && s != "END OF INPUT";) {
		vector<string> t(split(s, ' '));
		rep(i, 0, t.size())cout << t[i].size();
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3124
N,M = map(int,input().split())
X = list(map(int,input().split()))
X.sort()
B=[]

if N>=M:
    print(0)
else:
    for i in range(M-1):
        B.append(X[i+1]-X[i])

    B.sort()
    print(sum(B[:M-N]))



Measured memory_bytes: 20432
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;

vector<vector<pair<int,int>>>edges;

int memo[17][1 << 16];
struct aa {
	int now;
	bitset<17>eats;
	int time;
};
class Compare {
public:
	//aaが昇順に並ぶ
	bool operator()(const aa&l, const aa&r) {
		return l.time> r.time;
	}
};


int main() {
	while (1) {
		for (int i = 0; i < 17; ++i) {
			for (int j = 0; j < (1 << 16); ++j) {
				memo[i][j] =99999999;
			}
		}
		int N, M, L, S, T; cin >> N >> M >> L >> S >> T;
		if (!N)break;
		S--;
		edges.clear();
		edges.resize(L+1);
		int diss[300][300];
		for (int i = 0; i < N; ++i) {
			
			for (int j = 0; j< N; ++j) {

				diss[i][j] = i==j?0:99999999;

			}
			
		}
		for (int i = 0; i < M; ++i) {
			int a, b, c; cin >> a >> b >> c;
			a--; b--;
			diss[a][b] = c;
			diss[b][a] = c;
		}

		for (int i = 0; i < N; ++i) {
			for (size_t j = 0; j < N; j++)
			{
				for (size_t k = 0; k < N; k++)
				{
					diss[j][k] = min(diss[j][k],diss[j][i] + diss[i][k]);
				}
			}
		}
		vector<pair<int, int>>ramens;
		ramens.push_back(make_pair(S, 0));
		for (int i = 0; i < L; ++i) {
			int j, e; cin >> j >> e;
			j--;
			ramens.push_back(make_pair(j,e));
		}
		for (int i = 0; i < L+1; ++i) {
			for (int j = 0; j< L + 1; ++j) {
				if (i != j) {
					edges[i].push_back(make_pair(j, diss[ramens[i].first][ramens[j].first]));
				}
			}
		}

		priority_queue<aa, vector<aa>, Compare>que;
		que.push(aa{ 0,bitset<17>(1),0 });


		memo[0][0] = 0;
		int ans = 0;
		while (!que.empty()) {
			aa atop(que.top());
			que.pop();
			bitset<17>nbs(atop.eats);
			if (atop.now == 0) {
				ans = max(ans, int(nbs.count()));
				if (ans == L + 1)break;
			}

			for (auto j : edges[atop.now]) {
				const int nextplace = j.first;		
				const int nexttime = atop.time + j.second;
				if (nexttime < memo[nextplace][nbs.to_ulong()/2] && nexttime <= T) {
					memo[nextplace][nbs.to_ulong()/2] = nexttime;
					que.push(aa{ nextplace,nbs,nexttime });

					if (!nbs[nextplace]) {
						nbs[nextplace] = true;
						int alltime = nexttime + ramens[nextplace].second;
						if (alltime < memo[nextplace][nbs.to_ulong() / 2] && alltime <= T) {
							memo[nextplace][nbs.to_ulong() / 2] = alltime;
							que.push(aa{ nextplace,nbs, alltime });
						}
						nbs[nextplace] = false;
					}
				}
			}
		}
		cout << ans-1 << endl;
	}
	return 0;
}

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

int X[30], Y[30];
int check[50][50];

int main(){
	int N, M;
	while(cin >> N, N){
		for(int i = 0; i < N; i++){
			cin >> X[i] >> Y[i];
		}
		cin >> M;
		memset(check, 0, sizeof check);
		int x = 10, y = 10;
		for(int i = 0; i < M; i++){
			char c;
			int k;
			cin >> c >> k;
			while(k--){
				if(c =='N') y++;
				if(c =='S') y--;
				if(c =='E') x++;
				if(c =='W') x--;
				check[y][x] = 1;
			}
		}
		int ans = 0;
		for(int i = 0; i < N; i++){
			if(check[Y[i]][X[i]]) ans++;
		}
		if(ans == N) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

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

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

int main() {
    string S;
    int sum, operation;
    cin >> S;

    for (int i = 0; i < 8; i++) {
        sum = ctoi(S[0]);
        for (int j = 0; j < 3; j++) {
            if (((i >> j) & 1) == 0) sum -= ctoi(S[j + 1]);
            else sum += ctoi(S[j + 1]);
        }
        if (sum == 7) {
            operation = i;
            break;
        }
    }

    int idx = 0, shift = 0;
    for (int i = 0; i < 7; i++) {
        if (i % 2 == 0) cout << S[idx++];
        else {
            if (((operation >> shift) & 1) == 0) cout << "-";
            else cout << "+";
            shift++;
        }
    }
    cout << "=7\n";

    return 0;
}

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

map<int,int>prime_factor(int n){
  map<int,int>res;
  for(int i=2;i*i<=n;i++){
    while(n%i==0){
      res[i]++;
      n/=i;
    }
  }
  if(n!=1)res[n]=1;
  return res;
}
int main(){
  int n;
  cin>>n;
  cout<<n<<":";
  for(auto p:prime_factor(n)){
    auto k=p.first;
    auto v=p.second;
    for(int i=0;i<v;i++){
      cout<<" "<<k;
    }
  }
  cout<<endl;
}
  


Measured memory_bytes: 3116
n = int(input())
a = int(input())
ans = 0
ans += a-1
minim = 2
for ii in range(n-1):
    a = int(input())
    i = ii+1
    if(a==minim):
        minim+=1
    else:
        ans+=(a-1)//minim

print(ans)


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

#include <atcoder/all>

#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void()
#endif

using namespace std;
using namespace atcoder;

const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;

inline char getcha() {
  if (ci - cn == cm) {
    fread(cn, 1, cm, stdin);
    ci = cn;
  }
  return *ci++;
}

inline int getint() {
  int A = 0;
  if (ci - cn + 16 > cm) {
    while ((ct = getcha()) >= '0') {
      A = A * 10 + ct - '0';
    }
  } else {
    while ((ct = *ci++) >= '0') {
      A = A * 10 + ct - '0';
    }
  }
  return A;
}

int main() {
  // ios::sync_with_stdio(false);
  // cin.tie(0);
  int n = getint(), q = getint();
  fenwick_tree<long long> fw(n);
  for (int i = 0, a; i < n; i++) {
    a = getint();
    fw.add(i, a);
  }
  while (q--) {
    int t = getint(), x = getint(), y = getint();
    if (t) {
      printf("%lld\n", fw.sum(x, y));
    } else {
      fw.add(x, y);
    }
  }
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXB = 50;

int N;
ll np[MAXB*MAXB];

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

    cin >> N;
    for (int i = 0; i < N; i++)
    {
        ld t; cin >> t;
        ll x = (t * 1e9 + 0.5);

        int n2 = 0, n5 = 0;
        while (x % 2 == 0)
        {
            x /= 2;
            n2++;
        }
        while (x % 5 == 0)
        {
            x /= 5;
            n5++;
        }

        np[n5*50+n2]++;
        //cout << n5 << " " << n2 << "\n";
    }

    ll res = 0;
    for (int i = 0; i < MAXB * MAXB; i++)
        if (np[i])
        {
            for (int j = 0; j < i; j++)
            {
                if (np[j] && j/50 + i/50 >= 18 && (j%50 + i%50) >= 18)
                {
                    res += np[j] * np[i];
                }
            }
            if (i/50 >= 9 && i%50 >= 9)
                res += (np[i] * (np[i]-1)) / 2;
        }
    cout << res << "\n";
}

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

#ifdef DONLINE_JUDGE
//freopen("a.in", "r", stdin);
//freopen("a.out","w",stdout); // console output is better (in most cases)
#else
// add i/o method of specific testing system
#endif

using namespace std;

void call(int n)
{
    int i = 1;
    do
    {
        int x = i;
        if (x % 3 == 0)
        {
            cout << " " << i;
        }
        else
        {
            do
            {
                if (x % 10 == 3)
                {
                    cout << " " << i;
                    break;
                }
                x /= 10;
            } while (x);
        }
    } while (++i <= n);

    cout << endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    call(n);

    return 0;
}


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

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)1e5 + 9;
vector<int> T[N];
int u[N], v[N];

int pi[N];
int sz[N];

int fin(int u){
  if(u == pi[u])
    return u;
  return pi[u] = fin(pi[u]);
}

bool unite(int a, int b){ 
  a = fin(a);
  b = fin(b);
  if(a==b)
    return false;
  if(sz[a] > sz[b])
    swap(a,b);
  sz[b] += sz[a];
  pi[a] = b;
  return true;
}

int dir[N];
int pr[N];

void dfs(int u, int par){
  int mask = 0;
  pr[u] = par;
  for(auto x : T[u]){
    if(x != par){
      dfs(x, u);
      if(dir[x] == 0){
        mask ^= 1;
      }
    }
  }
  dir[u] = mask;
}

int f[N];

void dfs2(int u, int par){
  for(auto x : T[u]){
    if(x != par){
      dfs2(x, u);
      f[u] ^= f[x];
    }
  }
}

int main(){
  fastIO;
  int n, m;
  cin >> n >> m;
  if(m % 2 == 1){
    cout << "-1\n";
    return 0;
  }
  for(int i = 1; i <= n; i ++ )
    pi[i] = i, sz[i] = 1;
  vector<pii> shit;
  for(int i = 0 ; i < m ; i ++ ){
    cin >> u[i] >> v[i];
    if(unite(u[i], v[i])){
      T[u[i]].push_back(v[i]);
      T[v[i]].push_back(u[i]);
    }
    else{
      shit.push_back(mp(u[i], v[i]));
    }
  }
  dfs(1, -1);
  int l, r;
  for(auto x : shit){
    l = x.fi;
    r = x.se;
    f[l] ^= 1;
    cout << l << " " << r << "\n";
  }
  dfs2(1, -1);
  for(int i = 2; i <= n; i ++ ){
    if((f[i] ^ dir[i])){
      cout << i << " " << pr[i] << "\n";
    }
    else{
      cout << pr[i] << " " << i << "\n";
    }
  }
  return 0;
}

Measured memory_bytes: 16256
N, M = list(map(int, input().split(' ')))
AC_total = 0
WA_total = 0
ac_list = [False] * N
wa_list = [0] * N
for i in range(M):
    p, s = input().split(' ')
    p = int(p) - 1
    if not ac_list[p]:
        if s == 'WA':
            wa_list[p] += 1
        else:
            AC_total += 1
            WA_total += wa_list[p]
            ac_list[p] = True
print('{} {}'.format(AC_total, WA_total))

Measured memory_bytes: 4596
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <functional>

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

using namespace std;
using ll = long long;


int main() {
	int x, y, z;
	cin >> x >> y >> z;
	x -= z;
	cout << x / (y + z) << endl;
	return 0;
}

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

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

  vector<vector<int>> vec(m);
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;

    vec.at(i).resize(k);
    for (int j = 0; j < k; j++) {
      int s;
      cin >> s;
      s--; // 0-indexed
      vec.at(i).at(j) = s;
    }
  }

  vector<int> p(m);
  for (int i = 0; i < m; i++) {
    cin >> p.at(i);
  }

  int ans = 0;
  // 全てのスイッチのon/offパターンを探索する
  for (int i = 0; i < (1 << n); i++) {
    bool ok = true;

    // 電球 0〜m-1 について、全ての電球が点灯するか確認する
    for (int j = 0; j < m; j++) {
      int switch_on_cnt = 0;
      for (auto s : vec.at(j)) {
        // ### 例
        // i=2の場合、2 を2進数に変換すると 10 になる
        //
        // 一方で電球 j につながっているスイッチが 0, 1 (0-indexed) とする
        //
        // vec[j][0] = 0
        // vec[j][1] = 1
        //
        // 1つ目の要素は 0 となる
        //
        // (2 & (1 << 0))
        // --> (2 & 1)
        // --> (10 & 01)
        // --> (00)
        // --> 0 となる
        //
        // 2つ目の要素は 1 となる
        //
        // (2 & (1 << 1))
        // --> (2 & (10))
        // --> (10 & 10)
        // --> (10)
        // --> 2 となる
        //
        // そのため switch_on_cnt がインクリメントされる
        //
        if (i & (1 << s)) {
          switch_on_cnt++;
        }
      }
      // 条件を満たさな場合は false フラグを立てる
      if (switch_on_cnt % 2 != p.at(j)) {
        ok = false;
        // 今回のパターンが条件を満たさないことを確認したので、
        // 残りの探索はスキップする
        break;
      }
    }
    // 全部点灯していたらインクリメント
    if (ok) {
      ans++;
    }
  }

  cout << ans << endl;
  return 0;
}


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

unsigned GetDigit(unsigned num){
    return log10(num)+1;
}

int main(void){
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <n+1; ++i){
        if (GetDigit(i)%2 == 1){
            ans += 1;
        }
    }
    cout <<  ans <<endl;
    
};


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

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
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;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

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

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

    int x, y;
    cin >> x >> y;

    REP(t, 1000) REP(k, 1000) {
        if (t+k == x and t*2+k*4 == y) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}


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

int main() {
  int N, max = 0, ans = 0; cin >> N;
  for(int i = 0; i < N; i++) {
    int p; cin >> p;
    ans += p;
    if(max < p) max = p;
  }
  cout << ans - max / 2 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"
template<class T> void chmax(T &a, const T b){ a = max(a, b); }
template<class T> void chmin(T &a, const T b){ a = min(a, b); }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll t;
    cin >> t;
    rep(i, t) {
        ll n, m, a, b;
        cin >> n >> m >> a >> b;
        cout << floor_sum(n, m, a, b) << endl;
    }
    return 0;
}


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

using namespace std;
#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, k;
int a[N];
vector < int > g[N];
int w[N];
int c[N];
int u[N];
int d[N];
pair < int, int > e[N];
queue < int > q;

void dfs (int v) {
	for (auto to : g[v]) {
		if (c[to] == -1) {
			c[to] = (c[v] ^ 1);
			dfs(to);
		}
		
	}
}

int main () {
	SpeedForce;
	cin >> n >> m;
	for (int i = 1; i <= n; i ++) {
		cin >> a[i];
		c[i] = -1;
	}

	for (int i = 1; i <= m; i ++) {
		int l, r;
		cin >> l >> r;
		if (a[l] == a[r]) {
			w[i] = a[l];
			g[l].pb(r);
			g[r].pb(l);
			u[l] = u[r] = 1;

		} else {
			if (a[l] < a[r]) u[r] = 1;
			else u[l] = 1;
		}  

		e[i] = mp(l, r);
	}

	for (int i = 1; i <= n; i ++) if (!u[i]) {
		cout << "-1\n";
		exit(0);
	}

	for(int i = 1; i <= n; i++)
		c[i] = -1;
 
	for(int i = 1; i <= n; i++){
		if(c[i] == -1){
			c[i] = 0;
			dfs(i);
		}
	}
	for(int i = 1; i <= n; i++)
		if(c[i] == -1)
			c[i] = 0;
	for(int i = 1; i <= m; i++){
		int l, r;
		tie(l, r) = e[i];

		if(a[l] != a[r]){
			if(c[l] == c[r])
				w[i] = abs(a[l] - a[r]);
			else
				w[i] = max(a[l], a[r]);
		}
	}


	for (int i = 1; i <= n; i ++) {
		if (c[i] == 1) cout << 'B';
		else cout << 'W';
	}
	cout << '\n';

	for (int i = 1; i <= m; i ++) {
		cout << w[i] << '\n';
	}

   	return Accepted;
}

// B...a


Measured memory_bytes: 29184
#include<stdio.h>
#include<string.h>

int main(){
    char c[10];
    int i, len, point, flag1=0, flag2=0, flag3=0, buff=0;
    
    scanf("%s",c);
    
    for(i=0; c[i]!='\0'; i++);
    len = i;
    
    if(c[0]=='A'){
        flag3 = 1;
        for(i=2; i<len-1; i++){
            if(c[i]=='C'){
                flag1 = 1;
                point = i;
                break;
            }
        }

        if(flag1 == 1){
            for(i=1; i<len; i++){
                if(i != point){
                    if((c[i]>='a') && (c[i]<='z')){
                        buff++;
                    }
                }
            }

            if(buff == len-2){
                flag2 = 1;
            }
        }
    }

    
    if(flag1==1 && flag2==1 && flag3 ==1){
        printf("AC\n");
    }else{
        printf("WA\n");
    }


    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#define N 10000
#define NIL -1

typedef struct{
  int p;
  int L;
  int R;
}node;

node T[N];
int n, D[N],H[N];

int depth(int,int);
int height(int);
int sibling(int);

int main(){
  int i,j,v,l,r,root = 0;
  int deg = 0;
  scanf("%d",&n);

  for(i = 0; i < n; i++)
    T[i].p = NIL;

  for(i = 0; i < n; i++){
    scanf("%d%d%d",&v,&l,&r);
    T[v].L = l;
    T[v].R = r;
    if(l != NIL) T[l].p = v;
    if(r != NIL) T[r].p = v;
  }
  for(i = 0; i < n; i++){
    if(T[i].p == NIL) root = i;
  }
  
  depth(root,0);
  height(root);

  for(i = 0; i < n; i++){
    printf("node %d: parent = %d, sibling = %d, ",i,T[i].p,sibling(i));
    deg = 0;
    if(T[i].L != NIL) deg++;
    if(T[i].R != NIL) deg++;
    
    printf("degree = %d, depth = %d, height = %d, ",deg,D[i],H[i]);

    if(T[i].p == NIL){
      printf("root\n");
    }
    else if(T[i].L == NIL && T[i].R == NIL){
      printf("leaf\n");
    }
    else{
      printf("internal node\n");
    }
     }

 
  return 0;
}

int depth(int u,int d){
  if(u == NIL) return 0;
  D[u] = d;
  depth(T[u].L,d+1);
  depth(T[u].R,d+1);
}

int height(int u){
  int h1 = 0,h2 = 0;
  if(T[u].L != NIL) h1 = height(T[u].L) + 1;
  if(T[u].R != NIL) h2 = height(T[u].R) + 1;
  return H[u] = (h1 > h2 ? h1 : h2);
}

int sibling(int u){
  if(T[u].p == NIL) return NIL;
  if(T[T[u].p].L != NIL &&T[T[u].p].L != u) return T[T[u].p].L;
  if(T[T[u].p].R != NIL &&T[T[u].p].R != u) return T[T[u].p].R;
  return NIL;
}

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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()

#define uint8_t unsigned char
#define uint16_t unsigned short
#define uint32_t unsigned int
#define uint64_t unsigned long long

#define int8_t signed char
#define int16_t signed short
#define int32_t signed int
#define int64_t signed long long



using namespace std;
// #define PI 3.14159265358979323846
// cout << fixed << setprecision(20);

int main(int argc, char const* argv[])
{
    int N = 0;
    int K = 0;
    vector<int> h;
    int h_temp = 0;

    cin >> N >> K;
    while (cin >> h_temp) {
        h.push_back(h_temp);
    }
    int dp[N] = {};
    REP(i, N) dp[i] = INT_MAX;
    dp[0] = 0;
  
  	//REP(i,N)cout << dp[i] << endl;
    for (int i = 1; i < N; i++) {
        for (int j = 1; j <= K; j++) {
            if (i - j >= 0) {
                dp[i] = min(dp[i], dp[i-j]+ abs(h[i] - h[i-j]));
                //cout << i << " " << dp[i] << endl;
            }
        }
    }
    cout << dp[N-1] << endl;
    return 0;

}


Measured memory_bytes: 1144
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int count1 = 0;
        int count2 = 0;
        char one = '1';
        char zero = '0';
        for(int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if(i % 2 == 0) { // zeroから
                if(c != zero) count1++;
            } else {
                if(c != one) count1++;
            }
            if(i % 2 != 0) { // oneから
                if(c != zero) count2++;
            } else {
                if(c != one) count2++;
            }
        }
        System.out.println(Math.min(count1, count2));
    }
}


Measured memory_bytes: 25940
s = int(input())
l = [s]

for i in range(1, 1000):
    n = l[i - 1]
    if n % 2 == 0:
        l.append(int(n / 2))
    else:
        l.append(int(3 * n + 1))

# print(l[:100])
for i, v in enumerate(l):
    for j in range(i + 1, len(l) - i):
        if l[j] == v:
            print(j + 1)
            exit()

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

int main () {
	int n, x, m[110];
	cin >> n >> x;
	for (int i = 0; i < n; i++) cin >> m[i];

	int mn = m[0];
	
	for (int i = 0; i < n; i++) {
		x -= m[i];
		if (mn > m[i]) mn = min(mn, m[i]);
	}

	cout << n + x / mn << endl;

	return 0;
}

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

int main(void) {
  int x, y;
  cin >> x >> y;

  cout
    << abs(abs(y) - abs(x))
      - (y == 0 ? 1 : 0)
      + (signbit(x) == signbit(y)
        ? (x < y ? 0 : 2)
        : 1)
    << endl;
  return 0;
}

Measured memory_bytes: 3580
S,N,A,K,i,T,U;
main()
{
	scanf("%d",&N);
	for(i=0;i<N;i++)
	{
		scanf("%d%d",&A,&K);
		while(T=A/K+1,U=A%K%T)A=(T-1)*K-T+U;
		S^=T-1;
	}
	puts(S?"Takahashi":"Aoki");
}

Measured memory_bytes: 128
import numpy as np
N, C = (int(x) for x in input().split())
R = [[0]*100000 for _ in range(C)] #R[c][t]:時刻t+1にチャンネルc+1を録画するのに必要な録画機の個数
R = np.array(R)
for _ in range(N):
    s, t, c = map(int,input().split())
    R[c-1,s-1:t] = 1
ans = max(sum(R))
print(ans)

Measured memory_bytes: 73484
from heapq import heappush, heappop
import sys
input = sys.stdin.readline

def calc(camels, N):
    camels.sort(key=lambda x: x[0])
    heap = []
    for i, x in camels:
        heappush(heap, x)
        if len(heap) > i:
            heappop(heap)
    return sum(heap)

T = int(input())
for _ in range(T):
    N = int(input())
    s = 0
    ans = 0
    first = []
    second = []
    for i in range(N):
        K, L, R = map(int, input().split())
        if L >= R:
            first.append((K, L - R))
            ans += R
        else:
            second.append((N - K, R - L))
            ans += L
    ans += calc(first, N) + calc(second, N)
    print(ans)

Measured memory_bytes: 101180
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[])
{
	TLong x;
	TLong t = 1;
	scanf("%lld",&x);
	while(t * (t + 1) / 2 < x)	++t;
	printf("%lld\n", t);
	return 0;
}

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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)


typedef long long ll;
typedef unsigned long long int llt;

const int N = 5e5 + 10;

vector<int> g[N];
bool viss[N];
int vis[N];

void dfs(int curr, int par)
{
  for(auto x: g[curr])
    if(x != par)
      dfs(x, curr);
}

void dfs1(int curr, int par)
{
  viss[curr] = 1;
  for(auto x: g[curr])
    if(!viss[x])
      dfs1(x, curr);
}

void dfs2(int curr, int par, int num)
{
  vis[curr] = num;
  for(auto x: g[curr])
    if(vis[x] == 0)
      dfs2(x, curr, num);
}

ll fxor(ll n)
{
  if(n < 0) return 0;
  if(n % 4 == 3) return 0;
  else if(n % 4 == 0) return n;
  else if(n % 4 == 1) return n^(n-1);
  else if(n%4 == 2) return n^(n-1)^(n-2);
}

llt ppow(llt x, llt y)
{
  llt res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}

llt factdp[N];
llt fact(llt x)
{
  if(x == 0) return 1;
  if(x == 1) return 1;
  if(factdp[x] != -1) return factdp[x];
  return factdp[x] = (x*fact(x-1))%M;
}

string ans ="";
void convert10tob(llt N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     ans += to_string(x);
     return;
}

llt convertstrtob(string a, int b)
{
  llt aa = 0;
  llt mul = 1;
  for(int i=a.length()-1; i>=0; i--)
  {
    int curr = a[i] - '0';
    aa += (curr * mul);
    mul *= b;
  }
  return aa;
}



int main()
{
  llt n;
  cin>>n;
  llt a, b;
  a = b = 1;
  rep(i, 0, n)
  {
    llt x, y;
    cin>>x>>y;
    llt j = max(a /x, b / y);
    while(true)
    {
      llt xx = x*j;
      llt yy = y*j;
      if(xx >= a && yy >= b)
      {
        a = xx;
        b = yy;
        break;
      }
      j++;
    }
  }
  cout<<a+b<<endl;
  return 0;
}


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

int main() {
	long long n, a, b; cin >> n >> a >> b;
	if ((b - a) % 2 == 0) cout << (b - a) / 2 << endl;
	else cout << (b - a - 1) / 2 + min(a, n - b + 1) << endl;
}

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

int main(){
 string s;
 cin >> s;
 
  if( s[2] == s[3] && s[4] == s[5] ){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}




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

int main(int argc, const char *argv[])
{
    string s;
    cin >> s;

    int sum = 0;
    for (int i = 0; i < s.length(); i++)
    {
        sum += s[i] - '0';
    }

    if (sum % 9 == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3752
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Biscuits {
    class Program {
        static void Main(string[] args) {
            var input1 = Console.ReadLine().Split();
            var n = int.Parse(input1[0]);
            var p = int.Parse(input1[1]);
            var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            long ans;
            for (int i = 0; i < n; i++) {
                if (a[i] % 2 == 1) {
                    ans = (long)Math.Pow(2, n - 1);
                    Console.WriteLine(ans);
                    return;
                }
            }
            if (p == 0) {
                ans = (long)Math.Pow(2, n);
            } else {
                ans = 0;
            }
            Console.WriteLine(ans);
            return;
        }
    }
}


Measured memory_bytes: 13268
N,M= map(int,input().split(' '))
KSn =[]
for _ in range(M):
    KS = list(map(int,input().split(' ')))
    K = KS[0]
    Sn = KS[1:K+1]
    KSn.append(Sn)
Pn = list(map(int,input().split(' ')))

def bit_cal2(n):
    return_list = ['']* (2 ** n)
    for i in range(2 ** n):
        for j in range(n):
            if ((i >> j) & 1):
                return_list[i] = return_list[i] + '1'
            else:
                return_list[i] = return_list[i] + '0'
    return return_list

possible_list = bit_cal2(N)
comb_count = 0
for possible in possible_list:
    flag = True
    for i in range(M):
        count = 0
        for i2 in KSn[i]:
            count += int(possible[i2-1])
        if count%2 != Pn[i]:
            flag = False
            break
    if flag:
        comb_count += 1
print(comb_count)    


Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <deque>
using namespace std;
int main() {
    string s;
    int q;
    cin >> s >> q;
    bool dir = true;
    deque<char> dq(s.begin(), s.end());
    for (int i = 0; i < q; i++) {
        int t;
        cin >> t;
        if (t == 1) dir = !dir;
        else {
            int f;
            char c;
            cin >> f >> c;
            if ((dir && f == 1) || (!dir && f == 2)) dq.push_front(c);
            else dq.push_back(c);
        }
    }
    for (size_t i = 0; i < dq.size(); i++) {
        cout << (dir ? dq[i] : dq[dq.size() - 1 - i]);
    }
    cout << endl;
}

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b,c,d; cin>>a>>b>>c>>d;
	if(abs(c-a)<=d) cout<<"Yes\n";
	else if (abs(b-a)<=d&&(c-b)<=d) cout<<"Yes";
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll          long long int
#define pii         pair<int,int>
#define uu          first
#define vv          second
#define fastIO      ios::sync_with_stdio(0);cin.tie(0);
using namespace std;

const int MAX = 1e6 + 6;
const int INF = 1e9;

int main()
{
    fastIO;
    int n, k;
    cin>>n>>k;
    vector<int>h(n+1), dp(n+1);
    
    for(int i =1 ; i<=n ; i++ ) cin>>h[i];
    
    for(int i =2; i<=n ; i++) {
        dp[i] = INF;
        for(int j = 1; j <=k && (i-j) >=1 ; j++ ) 
            dp[i] = min( dp[i] , dp[i-j] + abs(h[i]- h[i-j]) );
    }
    cout<<dp[n]<<'\n';
    return 0;
    
}

Measured memory_bytes: 3932
package main

import "fmt"

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	var N int
	fmt.Scan(&N)
	p := make([]int, N)
	mx := 0
	sum := 0
	for i := range p {
		fmt.Scan(&p[i])
		sum += p[i]
		mx = max(mx, p[i])
	}
	fmt.Println((sum - mx) + mx/2)
}


Measured memory_bytes: 512
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


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;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b){
  ll r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return b;
}


ll LCM(ll a,ll b){
  ll c=a,d=b,r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return c/b*d;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

vector<pair<char,ll>> runlength(string s,vector<pair<char,ll>> p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
    return p;
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
  return p;
}


ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}







/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n;
  cin>>n;
  vector<ll> v(n);
  rep(i,n) cin>>v[i];
  ll dp[100010];
  rep(i,n) dp[i]=MOD;
  dp[0]=0;
  for(ll i=1;i<n;i++){
    chmin(dp[i],dp[i-1]+abs(v[i]-v[i-1]));
    if(i>1) chmin(dp[i],dp[i-2]+abs(v[i]-v[i-2]));
  }
  cout<<dp[n-1]<<endl;
  
  
  
}

Measured memory_bytes: 1792