akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define FOR(i,n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<ii> vii;

const int MX = 100005;

struct DSU {
    int p[MX], rk[MX];

    DSU () {
        for (int i = 0; i < MX; i++) {
            p[i] = i;
            rk[i] = 0;
        }
    }

    int parent (int a) {
        return a == p[a] ? a : p[a] = parent(p[a]);
    }

    void joint (int a, int b) {
        a = parent(a), b = parent(b);
        if (a == b)
            return;

        if (rk[a] > rk[b]) {
            p[b] = a;
        } else {
            p[a] = b;
            if (rk[a] == rk[b])
                rk[b]++;
        }
    }

    bool same (int a, int b) {
        return parent(a) == parent(b);
    }
};

int n, m, x, y, p[MX], res = 0;
DSU ds;

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

    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        cin >> p[i];

    while (m--) {
        cin >> x >> y;
        ds.joint(x, y);
    }

    for (int i = 1; i <= n; i++)
        res += ds.same(i, p[i]);

    cout << res << endl; 

    return 0;
}


Measured memory_bytes: 1408
#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>;
int main(void){
  string s;
  cin >> s;

  if (s == "Sunny") cout << "Cloudy" << endl;
  if (s == "Cloudy") cout << "Rainy" << endl;
  if (s == "Rainy") cout << "Sunny" << endl;
}


Measured memory_bytes: 3528
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#define _overload_rep(_1, _2, _3, name, ...) name
#define _rep(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define _rep_simple(i, n) _rep(i, 0, n)
#define rep(...) _overload_rep(__VA_ARGS__, _rep, _rep_simple)(__VA_ARGS__)

int GuessNumber(int n, int m, const std::vector<int> &s, const std::vector<int> &c) {
  int res = -1;
  for (int num = 999; num >= 0; --num) {
    std::string num_str = std::to_string(num);
    bool is_ok = true;
    if (num_str.size() != n) continue;
    rep(i, m) {
      if (num_str[s[i] - 1] != (char) ('0' + c[i])) {
        is_ok = false;
        break;
      }
    }
    if (is_ok) res = num;
  }
  return res;
}

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

  int n, m;
  std::vector<int> s(5, 0), c(5, 0);
  std::cin >> n >> m;
  rep(i, m) {
    std::cin >> s[i] >> c[i];
  }
  std::cout << GuessNumber(n, m, s, c) << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

int main() {
    int r,g;
    cin >> r >> g;
    cout << 2 * g - r << endl;
}



Measured memory_bytes: 256
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<atcoder/all>
using namespace std;
using namespace atcoder;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int n, q; cin >> n >> q;
    fenwick_tree<ll> fw(n);
    rep(i, n) {
        int a; cin >> a;
        fw.add(i, a * 1LL);
    }
    rep(_, q) {
        int t; cin >> t;
        if(t == 0) {
            int p, x; cin >> p >> x;
            fw.add(p, x * 1LL);
        } else {
            int l, r; cin >> l >> r;
            cout << fw.sum(l, r) << endl;
        }
    }
}

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

Measured memory_bytes: 8240
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <iomanip>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1LL << 60;

int main() {
  cin.tie(0); ios_base::sync_with_stdio(false);
  ll N; cin >> N;
  vector<ll> A(N);
  ll sum = 0;
  for(int i = 0; i < N; ++i) {
    cin >> A[i];
    sum += A[i];
  }
  for(int i = 0; i < N; ++i) A[i+1] += A[i];
  
  ll ans = INF;
  for(int i = 0; i < N; ++i) {
    ll left = A[i];
    ll right = sum - A[i];
    ans = min(ans, abs(right - left));
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <queue>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstring>
#include <cstdio>

using namespace std;

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

int main(void){
  int a, b, c, x;
  cin >> a >> b >> c >> x;

  int cnt = 0;
  for (int i = 0; i <= a; i++) {
    if (500 * i > x) break;
    for (int j = 0; j <= b; j++) {
      if (x < 500 * i + 100 * j) break;
      int remain = x - 500 * i - 100 * j;
      if (remain / 50 <= c && remain % 50 == 0) {
        cnt ++;
      }
    }
  }

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 256
n = int(input())
b = [int(i) for i in input().split()]

total = 0
for i in range(n):
    if i == 0:
        total += b[0]
    elif i == n - 1:
        total += b[-1]
    else:
        total += min(b[i - 1], b[i])

print(total)


Measured memory_bytes: 3060
N=int(input())
x=0
A=[0]*N
from collections import defaultdict
cnt=defaultdict(int)
for i in range(N):
    a=int(input())
    x^=a
    cnt[a^(a-1)]+=1
two=[1]*31
for i in range(1,31):
    two[i]=two[i-1]*2
ans=0
for i in range(30,0,-1):
    if ans<0:
        break
    if x%two[i]//two[i-1]==1:
        if cnt[two[i]-1]>0:
            ans+=1
            x^=two[i]-1
        else:
            ans=-1
            break
print(ans)

Measured memory_bytes: 4084
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <queue>
#include <algorithm>
#define R register
#define IN inline
#define W while
#define gc getchar()
#define MX 200500
template <class T>
IN void in(T &x)
{
	x = 0; R char c = gc;
	for (; !isdigit(c); c = gc);
	for (;  isdigit(c); c = gc)
	x = (x << 1) + (x << 3) + c - 48;
}
int n, m, low, hig, rcnt, ans;
int buf[MX];
struct INFO {int l, r;} dat[MX];
IN bool operator < (const INFO &x, const INFO &y) {return x.l == y.l ? x.r > y.r : x.l < y.l;}
std::priority_queue <int, std::vector <int>, std::greater <int> > pq;
int main(void)
{
	in(n), in(m);
	low = 1, hig = m;
	for (R int i = 1; i <= n; ++i) in(dat[i].l), in(dat[i].r);
	std::sort(dat + 1, dat + 1 + n);
	for (R int i = 1; i <= n; ++i)
	{
		pq.push(dat[i].r);
		if (low <= dat[i].l) ++low;
		else
		{
			buf[++rcnt] = pq.top();
			pq.pop();
		}
	}
	std::sort(buf + 1, buf + 1 + rcnt);
	for (R int i = rcnt; i; --i)
	{
		if (hig >= buf[i] && hig >= low) --hig;
		else ++ans;
	}
	printf("%d", ans);
}
//resubmitted by luogu.org

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

int main() {
    ll x,count500=0,count5=0,ans;
    cin >> x;

    while (x >= 500) {
        x -= 500;
        count500++;
    }

    while (x>=5) {
        x-=5;
        count5++;
    }

    ans=1000*count500+5*count5;
    cout<<ans<<endl;
}


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

#define SIZE 300005
#define MOD 1000000007LL
#define INF INT_MAX / 3
#define LLINF 1LL << 60
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define FORALL(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FOREACH(i,c) for(auto (i) : (c))
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef valarray<int> Array;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cout<<a[i];if(i==a.size()-1)cout<<endl;else cout<<" ";}}
int gcd(int a,int b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
int lcm(int a,int b){return a==0||b==0?0:a*b/gcd(a,b);}


vector<string> split(const string &str, char delim)
{
  istringstream iss(str); string tmp; vector<string> res;
  while(getline(iss, tmp, delim)) res.push_back(tmp);
  return res;
}

void solve(string s)
{
  int a = 0, b = 0;
  vector<string> words = split(s,0x20);
  for(auto t : words)
  {
    if(t.size() != 4) continue;
    else
    {
      bool f = false;
      FOR(v,1,25)
      {
        if(gcd(v,26)!=1) continue;
        FOR(w,0,25)
        {
          string tmp = t;
          REP(j,4) tmp[j] = 'a'+((v*(t[j]-'a')+w)%26);
          if(tmp == "this" || tmp == "that")
          {
            a = v; b = w; f = true;
            break;
          }
        }
        if(f) break;
      }
      if(f) break;
    }
  }
  REP(i,s.size()) if(s[i] != 0x20)s[i] = 'a'+((a*(s[i]-'a')+b)%26);
  printf("%s\n",s.c_str());
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n; cin.ignore();
  REP(i,n)
  {
    string s;
    getline(cin,s);
    solve(s);
  }
  return 0;
}

Measured memory_bytes: 3200
s=input()
n=len(s)
from itertools import product
bit=list(product([0,1],repeat=n))
#print(bit)
ans=0
for b in bit:
  #print(b)
  cnt=0
  kouho=""
  for i in range(n):
    if i==n-1:
      kouho+=s[i]
      #print(kouho)
      cnt+=int(kouho)
      kouho=""
    else:
      if b[i]==0:
        kouho+=s[i]
      elif b[i]==1:
        kouho+=s[i]
        cnt+=int(kouho)
        #print(kouho)
        kouho=""
    
  ans+=cnt

print(ans//2)

      
      

Measured memory_bytes: 9300
# -*- coding:utf-8 -*-

N = int(input())
li_raw = input().split()
li = [int(j) for j in li_raw]

turn = 1
A = 0
B = 0

while li != []:
    max = 0
    for x in li:
        if x > max:
            max = x
    if turn == 1:
        A += max
    else:
        B += max
    li.remove(max)
    turn = -turn
print(A-B)


Measured memory_bytes: 3060
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

char str[200005];

int main(int argc, char* argv[])
{
    int n,a,b,c,d;
    scanf("%d%d%d%d%d", &n,&a,&b,&c,&d);
    a--; b--; c--; d--;
    scanf("%s", str);

    int i;
    for(i=a+1; i<c; i++) {
        if(str[i-1]=='#' && str[i]=='#') {
            printf("No\n"); return 0;
        }
    }
    for(i=b+1; i<d; i++) {
        if(str[i-1]=='#' && str[i]=='#') {
            printf("No\n"); return 0;
        }
    }

    if(c>d) {
        bool bOk=false;
        for(i=b+1; i<=d+1; i++) {
            if(str[i-2]!='#' && str[i-1]!='#' && str[i]!='#') {
                bOk = true;
                break;
            }
        }
        if(!bOk) {
            printf("No\n"); return 0;
        }
    }
    printf("Yes\n");


    return 0;
}


Measured memory_bytes: 384
import math
S=input()
S=S.split()
A=float(S[0])
B=float(S[1])
H=float(S[2])
M=float(S[3])
C=abs(30*H-5.5*M)
if C-180>0:
  C=360-C
C=C*(math.pi/180)
ans=math.sqrt(A*A+B*B-2*A*B*math.cos(C))
print(ans)

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

using namespace std;

#define db(x) cout << (x) << '\n';
#define all(x) x.begin(),x.end()
#define UNIQUE(x) sort(all(x)),x.resize(unique(all(x))-x.begin())
#define LB(v,x) lower_bound(all(v),x)
#define UB(v,x) upper_bound(all(v),x)
#define endl "\n"
#define F first
#define S second
#define PB push_back
#define PF push_front
#define int long long
#define trick int m = (l+r)>>1,lc=n<<1,rc=lc|1

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;

int dy[]={0,1,1,1,0,-1,-1,-1};
int dx[]={-1,-1,0,1,1,1,0,-1};
const int maxn = 1e6;
const int OO = 1e18;
const int mod = 1e9 + 7;
const double PI = acos(-1);

void maxself(int &a,int b)
{a=max(a,b);}
void minself(int &a,int b)
{a=min(a,b);}

int n,m,x,y,mx;
vi v;
vector<vi> g(maxn);
int a[maxn],b[maxn];
string s;

bool mk[maxn*2];

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

//	freopen("name.in","r",stdin);
//	freopen("name.out","w",stdout);

	v.PB(2);
	for(int i=3;i<=maxn;i+=2)
		if(mk[i]==0)
			for(int j=i*i;j<=maxn;j+=2*i)
				mk[j]=1;
	
	for(int i=3;i<=maxn;i+=2)
	if(mk[i]==0)
	v.PB(i);
	cin >> n;
	vector<pii> fact;
	for(auto d:v)
	{
		if(n%d==0)
		{
			fact.PB({d,1});
			n/=d;
			while(n%d==0)
			{
				fact[fact.size()-1].S++;
				n/=d;
			}
		}
	}
	
	if(n>1)
	{
		fact.PB({n,1});
	}
	int ans =0;
	for(auto d:fact)
	{
		for(int i=1;i<=d.S;i++)
		ans++,d.S-=i;
	}
	cout << ans;

	return 0;
}



Measured memory_bytes: 28644
#include <fstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;

#define REP(i,n) for(ll i = 0; i < (n); ++i)
#define FOR(i,s,n) for(ll i = s; i < (n); ++i)
#define ALL(t) t.begin(), t.end()

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vb = vector<bool>;
using vvb = vector<vb>;

template <typename F> ll bsearch(ll ok, ll ng, F f){
	while (abs(ok - ng) > 1){
		ll middle = (ok + ng) / 2;
		(f(middle) ? ok : ng) = middle;
	}
	return ok;
}
int main() {
#ifdef CIN_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(5);
	ll n; cin >> n;
	vl t(n);
	REP(i, n) cin >> t[i];
	sort(ALL(t)); reverse(ALL(t));
	ll ssum = 0;
	REP(i, n) ssum += t[i];
	
	vvvl dp(n+1, vvl(ssum+1));
	FOR(i, 1, n+1){
		REP(j, ssum + 1){
			dp[i][j] = dp[i - 1][j];
			if (dp[i][j].empty() && j - t[i - 1] >= 0 && (!dp[i - 1][j - t[i - 1]].empty() || j - t[i - 1] == 0)){
				dp[i][j] = dp[i - 1][j - t[i - 1]];
				dp[i][j].push_back(i - 1);
			}
		}
	}

	ll ans = bsearch(ssum + 1, ssum / 3 - 1, [&](ll x){
		vl li;
		for (ll i = x; i >= 0; --i){
			if (!dp[n][i].empty()){
				li = dp[n][i];
				break;
			}
		}

		vl t2;
		auto it = li.begin();
		REP(i, n){
			if (it!=li.end() && *it==i){
				++it;
			}
			else{
				t2.push_back(t[i]);
			}
		}

		ll sum = 0;
		REP(i, t2.size()) sum += t2[i];
		if (sum / 2 > x) return false;
		if (sum <= x) return true;

		vvb dp2(t2.size()+1, vb(sum+1));
		dp2[0][0] = true;
		FOR(i, 1, t2.size() + 1){
			REP(j, sum + 1){
				dp2[i][j] = dp2[i - 1][j];
				if (j - t2[i - 1] >= 0 && dp2[i - 1][j - t2[i - 1]]){
					dp2[i][j] = true;
				}
			}
		}

		for (ll i = x; i >= 0; --i){
			if (dp2[t2.size()][i]){
				return sum - i <= x;
			}
		}

		return false;
	});

	cout << ans << endl;
}

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

using namespace std;
int main()
{
    string s;
    cin>>s;
    for(int i=0 ;i<s.length(); i++)
        if((i%2==1&&s[i]=='R')||(i%2==0&&s[i]=='L'))
           {
               cout<<"No";
               return 0;
           }

    cout<<"Yes";


    return 0;
}


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

int main()
{
	int i, N, a[100001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(a[i]));
	
	int count[3] = {};
	for (i = 1; i <= N; i++) {
		if (a[i] % 2 == 1) count[0]++;
		else if (a[i] % 4 == 2) count[1]++;
		else count[2]++;
	}
	
	if (count[2] >= count[0]) printf("Yes\n");
	else if (count[2] == count[0] - 1 && count[1] == 0) printf("Yes\n");
	else printf("No\n");
	fflush(stdout);
	return 0;
}

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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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 coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
const ll INF = 1LL << 60;
const int mod = 1e9+7;
//Write From this Line

int main()
{
	int h = 3 , w = 3 ;
	vector<vector<int>> a(h,vector<int>(w));
	rep(i,h) rep(j,w) cin >> a[i][j];
	rep(i,2){
		rep(j,2){
			if(a[i][j] - a[i+1][j] != a[i][j+1] - a[i+1][j+1]){
				coN();
				return 0 ;
			}
		}
	}
	coY();
}


Measured memory_bytes: 256
s=input()
sl=len(s)

if sl==1:
  print(int(s))
  exit()

ans=0
for i in range(2**(sl-1)):
  l=['' for j in range(sl-1)]
  for k in range(sl-1):
    if (i>>k)&1:
      l[k]='+'

  t_ans=0
  t_s=s[0]

  for k in range(1,sl):
    if l[k-1]=='+':
      t_ans+=int(t_s)
      t_s=s[k]
    else:
      t_s+=s[k]

  t_ans+=int(t_s)
  ans+=t_ans

print(ans)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

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

    int x = 0;
    int xmax = 0;
    for(int i = 0; i < N; ++i)
    {
        char si;
        cin >> si;
        x += (si == 'I' ? 1 : -1);
        xmax = max(xmax, x);
    }
    cout << xmax << endl;
    return 0;
}

Measured memory_bytes: 888
#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long ll;
ll q, h, s, d, n;

int main(void) {
  scanf("%lld%lld%lld%lld%lld", &q, &h, &s, &d, &n);
  ll res = 0;
  res += n/2 * min({q*8, h*4, s*2, d});
  res += n%2 * min({q*4, h*2, s});
  printf("%lld\n", res);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x = 0;
  int mx = 0;
  int cnt = 0;
  int n;
  string s;
  cin >> n;
  cin >> s;
  REP(i,n){
    if (s[i]=='I')cnt++;
    else cnt--;
    if (mx<cnt)mx=cnt;
  }
  cout << mx << endl;
}


Measured memory_bytes: 256
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI():return list(map(int,sys.stdin.readline().rstrip().split()))
def LS():return list(sys.stdin.readline().rstrip().split())

def main():
  X = LI()
  
  for i,x in enumerate(X):
    if x==0:
      print(i+1)
      exit()


if __name__ == '__main__':
	main()


Measured memory_bytes: 9184
#pragma GCC optimize (3)
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<algorithm>
#include<unordered_map>
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>*/
//#include<ext/rope>
#define ll long long
#define ull unsigned long long
#define INFI 2147483647
#define INFL 9223372036854775807
#define INFU 18446744073709551615
using namespace std;
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;
const double PI=acos(-1.0);
const double eps=1e-6;
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0' || ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
template<typename T> void debug(T x)
{
    cout<<"value="<<x<<endl;
    return;
}
signed main()
{
	//ios_base::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
	int x=read();
	if(x>=30) puts("Yes");
	else puts("No");
	return 0;
}


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

const int N = 205, M = 10000005;
int tot = 0, s[N];

bool prime(int n) {
	if (n <= 2) return 0;
	for (int i = 2; i * i <= n; ++i)
		if (n % i == 0) return 0;
	return 1;
}
bool e[N][N];

std::vector<int> L, R;
int l, r, bel[N], match; bool vis[N];

bool dfs(int x) {
	for (int i = 0; i < r; ++i) if (e[x][i] && !vis[i]) {
		vis[i] = 1;
		if (!~bel[i] || dfs(bel[i])) {
			bel[i] = x; return 1;
		}
	}
	return 0;
}

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	int n; std::cin >> n;
	for (int i = 0; i < n; ++i) {
		int x; std::cin >> x;
		if (s[tot] == x) --tot;
		else s[++tot] = x;
		s[++tot] = x + 1;
	}
	for (int i = 1; i <= tot; ++i)
		(s[i] & 1 ? L : R).emplace_back(s[i]);
	l = L.size(), r = R.size(), std::memset(bel, -1, sizeof bel);
	for (int i = 0; i < l; ++i)
		for (int j = 0; j < r; ++j)
			e[i][j] = prime(std::abs(L[i] - R[j]));
	for (int i = 0; i < l; ++i) std::memset(vis, 0, r), match += dfs(i);
	std::cout << l + r - match + (l - match & 1) << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

int n, m;
int chair[105];

int dist(int k){
	int ret = 1000;
	for(int i = k; i <= n; ++i){
		if(chair[i]){
			ret = i - k;
			break;
		}
	}
	for(int i = k; i >= 1; --i){
		if(chair[i]){
			ret = std::min(ret, k - i);
			break;
		}
	}
	return ret;
}

int main(){
	while(true){
		for(int i = 0; i < 105; ++i)chair[i] = 0;
		
		std::cin >> n >> m;
		if(n == 0 && m == 0)break;

		for(int i = 0; i < m; ++i){
			char ch;
			std::cin >> ch;

			if(ch == 'A'){
				for(int j = 1; j <= n; ++j){
					if(chair[j] == 0){
						chair[j] = 1;
						break;
					}
				}
			}
			else if(ch == 'B'){
				bool f = false;

				for(int j = n; j >= 1; --j){
					if(chair[j] == 0 && chair[j - 1] != 1 && chair[j + 1] != 1){
						chair[j] = 2;
						f = true;
						break;
					}
				}

				if(!f){
					for(int j = 1; j <= n; ++j){
						if(chair[j] == 0){
							chair[j] = 2;
							break;
						}
					}
				}
			}
			else if(ch == 'C'){
				if(i == 0)chair[n % 2 ? ((n + 1) / 2) : (n / 2 + 1)] = 3;
				else{
					for(int j = 1; j <= n; ++j){
						if(chair[j]){
							if(j + 1 <= n && chair[j + 1] == 0){
								chair[j + 1] = 3;
								break;
							}
							if(j - 1 >= 1 && chair[j - 1] == 0){
								chair[j - 1] = 3;
								break;
							}
						}
					}
				}
			}
			else if(ch == 'D'){
				if(i == 0)chair[1] = 4;
				else{
					int maxV = -1000, maxI;
					for(int j = 1; j <= n; ++j){
						if(chair[j] == 0){
							if(dist(j) > maxV)maxV = dist(j), maxI = j;
						}
					}
					chair[maxI] = 4;
				}
			}
		}

		for(int i = 1; i <= n; ++i){
			if(chair[i] == 0)std::cout << "#";
			else std::cout << (char)('A' + chair[i] - 1);
		}
		std::cout << std::endl;
	}
	
	return 0;
}

Measured memory_bytes: 1152
#include <string>
#include <vector>
#include <deque>
#include <map>
#include <set>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <iostream>
#include <utility>
#include <sstream>
#include <cstring>
#include <bitset>
#include <climits>
 
using namespace std;
#define  AS(arr)  (sizeof(arr)/sizeof(arr[0]))
#define ALL(c) (c).begin(),(c).end() 
#define SIZE(a) int((a).size())
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define REP(i,n) for(int i=0;i<(int)n;++i)
typedef vector<int> VI;
typedef vector<string> VS;
typedef long long LL;

int c[100001][27];
int main(void){
    string s;
    int i = 0;
    cin >> s;
    int size = s.size();
    s += 'X';
   REP(i, size)
   {
     if(i==0)
     {
         if(s[i] == s[i+1])
         {
             cout << (i+1) << ' ' << (i+2) << endl;
             return 0;
         }
     }
     else if(i != size-1)
     {
         if(s[i] == s[i+1])
         {
             cout << (i+1) << ' ' << (i+2) << endl;
             return 0;
         }
         if(s[i-1] == s[i+1])
         {
             cout << (i) << ' ' << (i+2) << endl;
             return 0;
         }
         
     }
     
   }
   cout << "-1 -1" << endl;
    
}


Measured memory_bytes: 512
""" a = list(map(int,input().split()))
b = list(map(int,input().split()))
 """

a = int(input())
c =0

for i in range(1,10):
    if a/i  == a//i and a//i<=9:
        c+=1
        break

if c>=1:
    print("Yes")
else:    
    print("No")

Measured memory_bytes: 8956
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const A = parseInt(arg[0].split(" ")[0]);
    const B = parseInt(arg[0].split(" ")[1]);
    const N = parseInt(arg[0].split(" ")[2]);
    
    let answer = 0;
    
    if(B - 1 < N) {
        answer = Math.floor((A * (B-1)) / B) - (A * Math.floor((B-1) / B));
    } else {
        answer = Math.floor((A * N) / B) - (A * Math.floor(N / B));
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 29608
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"---------------"#x"---------------"<<endl
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
						For(_x,L,R)cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector <int> vi;
typedef long double LD;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f|=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int N=2e5+5;
int n;
struct Point{
	int x,y;
	void get(){
		x=read(),y=read();
	}
}p[N],p1,p2;
bool cmp(Point a,Point b){
	if (a.y!=b.y)
		return a.y<b.y;
	return a.x<b.x;
}
int lim=1e8;
int Ha[N],hs;
void LSH(){
	int c=0;
	For(i,1,n)
		if (p1.x<=p[i].x&&p[i].x<=p2.x&&p1.y<=p[i].y&&p[i].y<=p2.y)
			p[++c]=p[i];
	n=c,hs=0;
	For(i,1,n)	
		Ha[++hs]=p[i].x;
	Ha[++hs]=p1.x,Ha[++hs]=p2.x;
	sort(Ha+1,Ha+hs+1);
	hs=unique(Ha+1,Ha+hs+1)-Ha-1;
	For(i,1,n)
		p[i].x=lower_bound(Ha+1,Ha+hs+1,p[i].x)-Ha;
	p1.x=lower_bound(Ha+1,Ha+hs+1,p1.x)-Ha;
	p2.x=lower_bound(Ha+1,Ha+hs+1,p2.x)-Ha;
}
namespace bit{
	int c[N];
	void init(){
		clr(c);
	}
	void Add(int x,int d){
		for (;x<=hs;x+=x&-x)
			c[x]=max(c[x],d);
	}
	int Ask(int x){
		int ans=0;
		for (;x;x-=x&-x)
			ans=max(ans,c[x]);
		return ans;
	}
}
LD PI=acos(-1.0L);
int main(){
	p1.get(),p2.get();
	n=read();
	For(i,1,n)
		p[i].get();
	if (p1.x>p2.x)
		swap(p1,p2);
	if (p1.y>p2.y){
		p1.y=lim-p1.y-1;
		p2.y=lim-p2.y-1;
		For(i,1,n)
			p[i].y=lim-p[i].y-1;
	}
	LSH();
	bit::init();
	sort(p+1,p+n+1,cmp);
	For(i,1,n){
		int v=bit::Ask(p[i].x)+1;
		bit::Add(p[i].x,v);
	}
	int len=bit::Ask(p2.x);
	LD ans=100.0L*(Ha[p2.x]+p2.y-Ha[p1.x]-p1.y);
	ans+=(PI/2-2)*10*len;
	if (len==min(Ha[p2.x]-Ha[p1.x],p2.y-p1.y)+1)
		ans+=PI/2*10;
	printf("%.13Lf\n",ans);
	return 0;
}

Measured memory_bytes: 3328
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<list>
#include<stack>
#include<map>
#include<set>
#include<string>
#include <sstream>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;


int main(){
  long ii,jj,kk;

  int n,m,v;
  set<int> a,b;
  cin >> n;

  for(ii=0;ii<n;ii++){
    cin >> v;
    a.insert(v);
  }

  cin >> m;

  for(ii=0;ii<m;ii++){
    cin >> v;
    a.insert(v);
  }

  set<int>::iterator it;
  it = a.begin();
  while(it != a.end()){
    cout << *it << endl;
    it++;
  }
    
  return 0;
}



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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

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

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

int main(){
  vector<p> v(3);
  vector<int> count(4, 0);
  for (int i = 0; i < 3; i++) {
    cin >> v[i].first >> v[i].second;
    count[v[i].first-1]++;
    count[v[i].second-1]++;
  }

  for (int i = 0; i < 4; i++) {
    if(count[i] == 3){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;

}


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

using namespace std;

int main(int argc, char const *argv[])
{
	int A, B;
	int ans = 0;
	cin >> A >> B;
	if(A <= B) {
		cout << A;
	} else {
		cout << A - 1;
	}
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        var res = 0;
        var n = Console.ReadLine();
        var k = int.Parse(Console.ReadLine());
        var count = new int[k + 1];
        //count[0] = 1;
        for (int i = 0; i < n.Length; i++)
        {
            var newCount = count.ToArray();
            //今ギリギリでなくなったものを足す
            var nonZeroCount = n.Take(i).Count(x => x != '0');
            if (n[i] != '0' && nonZeroCount <= k) newCount[nonZeroCount]++;
            if (n[i] != '0' && nonZeroCount + 1 <= k) newCount[nonZeroCount + 1] += n[i] - '0' - 1;
            for (int j = 0; j < k; j++)
                newCount[j + 1] += count[j] * 9;
            count = newCount;
        }
        if (n.Count(x => x != '0') == k) count[k]++;
        Console.WriteLine(count[k]);
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	string S;
	cin >> S;
	S[3] = '8';
	cout << S << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  
int main() {
  int n;
  cin >> n;

  int r_min;
  int r_max = -1 * 1e9 - 1;
  cin >> r_min;
  for (int i = 1; i < n; i++)
  {
    int temp;
    cin >> temp;
    r_max = max(temp - r_min, r_max);
    r_min = min(r_min, temp);
  }

  cout << r_max << endl;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
long long dp[100100][3];
int main()
{
	string S;
	cin>>S;
	long long cnt=1;
	const long long M=1000000007;
	for(int i=0;i<S.length();i++)
	{
		if(S[i]=='A')
		{
			dp[i+1][0]=(dp[i][0]+cnt)%M;
			dp[i+1][1]=dp[i][1];
			dp[i+1][2]=dp[i][2];
		}
		if(S[i]=='B')
		{
			dp[i+1][0]=dp[i][0];
			dp[i+1][1]=(dp[i][1]+dp[i][0])%M;
			dp[i+1][2]=dp[i][2];
		}
		if(S[i]=='C')
		{
			dp[i+1][0]=dp[i][0];
			dp[i+1][1]=dp[i][1];
			dp[i+1][2]=(dp[i][2]+dp[i][1])%M;
		}
		if(S[i]=='?')
		{
			dp[i+1][0]=(dp[i][0]*3+cnt)%M;
			dp[i+1][1]=(dp[i][1]*3+dp[i][0])%M;
			dp[i+1][2]=(dp[i][2]*3+dp[i][1])%M;
			cnt=(cnt*3)%M;
		}
	}
	cout<<dp[S.length()][2]<<endl;
	return 0;
}

Measured memory_bytes: 2816
import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict

# from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
# from functools import reduce
# from math import ceil, floor, log10, log2, factorial
# from pprint import pprint

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))


N, D = [int(x) for x in input().split()]

ans = math.ceil(N / (2 * D + 1))
print(ans)

pass


Measured memory_bytes: 38256
x ,k ,d = map(int,input().split())

x = abs(x)
c = x // d
# 必要な移動回数
k_r = k - c
# 移動した後の残りの移動回数
ans_2 = x - d * c
#残り移動回数が偶数のときのｘからの距離

if c >= k:
    print(x - k * d )
    exit()

x_l = x - d * c
#ｘまでの残りの距離

if k_r % 2 == 0:
    print(ans_2)
    exit()
else :
    x_l -= d
    x_l =abs(x_l)
    print(x_l)

Measured memory_bytes: 9184
def solve():
    n = int(input())
    b = list(map(int, input().split()))
    b.insert(0, 100000000)
    b.append(100000000)

    sum = 0
    for i in range(n):
        p = b[i]
        next = b[i+1]
        sum += min(p, next)

    print(sum)

solve()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int n;
pair<int,int> a[100001];
int l;
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>n;
    int i;
    for(i=1 ; i<=n ; i++){
        int x,l;
        cin>>x>>l;
        a[i]={x+l,x-l};
    }
    sort(a+1,a+n+1);
    int k=-2e9;
    int ans=0;
    for(i=1 ; i<=n ; i++){
        if(a[i].second>=k){
            ans++;
            k=a[i].first;
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1024
X,Y,A,B,C = map(int, input().split())
ps = sorted(map(int,input().split()),reverse=True)[:X]
qs = sorted(map(int,input().split()),reverse=True)[:Y]
rs = list(map(int,input().split()))
print(sum(sorted(ps+qs+rs, reverse=True)[:X+Y]))

Measured memory_bytes: 22528
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define For1(i, n) for(int i = 1; i <= (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n);
    
    vc<vc<int>> a;
    For(i, n/2) a.push_back({i+1, n/2*2-i});
    if(n % 2 != 0) a.push_back({n});
    
    // for(auto &v : a) Couts(v);
    int s = (int)a.size();
    vc<pair<int, int>> e;
    For(i, s) for(int j = i+1; j < s; j ++){
        for(auto &x : a[i]) for(auto &y : a[j]) e.emplace_back(x, y);
    }
    Cout(e.size());
    for(auto &p : e) Cout(p.first, " ", p.second);
}




Measured memory_bytes: 384
X=int(input())
if X==0:
	print(0)
else:
	A = []
	while(X!=0):
		X,R = divmod(X,-2)
		if (R<0):
			R-=(-2)
			X+=1
		A.append(R)
	print("".join(map(str,A[::-1])))

Measured memory_bytes: 3060
from heapq import heapify, heappop, heappush

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [-a for a in A]
heapify(A)
for _ in range(M):
    a = heappop(A)
    heappush(A, -(-a//2))
print(-sum(A))

Measured memory_bytes: 14180
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

ll devide_and_ceil(ll a, ll b){
    if(a%b==0){
        return a/b;
    }else{
        return a/b + 1;
    }
}

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

    // input
    ll N;
    cin >> N;

    ll A = 1;
    ll B = 1;

    FOR(i, 0, N){
        ll a, b;
        cin >> a >> b;

        ll n = max(devide_and_ceil(A, a), devide_and_ceil(B, b));
        A = n * a;
        B = n * b;
    }

    p(A+B);
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner inp = new Scanner(System.in);
        int n = inp.nextInt();

        int max = 0;
        int min = 10000;
        long sum = 0;

        for (int i = 0; i < n; i++) {
            int a = inp.nextInt();

            if (i == 0) {
                min = a;
                max = a;
                sum += a;
            } else {
                if (a < min) {
                    min = a;
                }

                if (a > max) {
                    max = a;
                }

                sum += a;
            }
        }

        System.out.println(min + " " + max + " " + sum);
    }
}



Measured memory_bytes: 41548
S=input()
for i in range(1,len(S)//2+1):
    check=0
    T=S[:len(S)-2*i]
    for j in range(0,len(T)//2):
        if T[j]!=T[j+len(T)//2]:
            check=1
    if check==0:
        print(len(T))
        break
if check==1:
    print(0)


Measured memory_bytes: 2940
#include <algorithm>
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;

struct binarytree{
	int parent, left, right;
};

int order(vector <binarytree> &node, int i, int mode){
	int e1, e2;

	if (mode==0) cout << " " << i;

	e1 = node[i].left;
	if (e1 != -1) order(node, e1, mode);
	if (mode==1) cout << " " << i;

	e2 = node[i].right;
	if (e2 != -1) order(node, e2, mode);
	if (mode==2) cout << " " << i;
	return 0;
}

int main(void){
	int n, e, tmp;
	stringstream ss;

	cin >> n;
	vector <binarytree> node(n);
	for (int i=0; i<n; i++){
		node[i].parent = -1;
		node[i].left = -1;
		node[i].right = -1;
	}

	for (int i=0; i<n; i++){
		cin >> e;

		cin >> tmp;
		node[e].left = tmp;
		if (tmp != -1) node[tmp].parent = e;

		cin >> tmp;
		node[e].right = tmp;
		if (tmp != -1) node[tmp].parent = e;
	}

	e = 0;
	tmp = node[e].parent;
	while (tmp!=-1){
		e = tmp;
		tmp = node[e].parent;
	}

	cout << "Preorder" << endl;
	order(node, e, 0);
	cout << endl;

	cout << "Inorder" << endl;
	order(node, e, 1);
	cout << endl;

	cout << "Postorder" << endl;
	order(node, e, 2);
	cout << endl;

	return 0;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
int A[6000];

int memo[4010][6010];

int dfs(int l,int r){
    if(r-l==N)return 0;

    int &ret=memo[l][r];
    if(ret!=-1)return ret;
    if((r-l)&1){
        if(A[l-1]>A[r])ret=dfs(l-1,r);
        else ret=dfs(l,r+1);
    }
    else{
        ret=max(dfs(l-1,r)+A[l-1],dfs(l,r+1)+A[r]);
    }
    return ret;
}
signed main(){
    cin>>N;
    rep(i,N){
        cin>>A[i];
        A[i+N+N]=A[i+N]=A[i];
    }
    memset(memo,-1,sizeof(memo));
    int ans=0;
    for(int i=N;i<N+N;i++){
        chmax(ans,dfs(i,i+1)+A[i]);
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

#define MOD 1000000007
#define PI 3.1415926535897932384626433832795
#define INF (int)1e9
typedef long long int int64;

void print() {
    cout << endl;
}

void print(string s, bool endline = true) {
    cout << s;
    if (endline) print();
}

void print(int s, bool endline = true) {
    cout << s;
    if (endline) print();
}

template <typename T, typename T2>
void print(pair<T, T2>& p, bool endline = true) {
    print("(", false);
    print(p.first, false);
    print(", ", false);
    print(p.second, false);
    print(")", false);

    if (endline) print();
}

template <typename T, typename T2>
void print(map<T, T2>& m, bool endline = true) {
    print("{");
    for (auto& p : m) {
        print("  ", false);
        print(p);
    }
    print("}");

    if (endline) {}
}

template<typename T>
void print(vector<T>& v, bool endline = true) {
    print("[", false);
    for (size_t i = 0; i < v.size(); ++i) {
        print(v[i], false);
        if(i != v.size() - 1) print(",", false);
    }
    print("]", false);

    if(endline) print();
}

template <typename T>
vector<T> operator+(const vector<T> &a, const vector<T> &b)
{
    vector<T> ret;
    ret.reserve( a.size() + b.size() );                // preallocate memory
    ret.insert( ret.end(), a.begin(), a.end() );        // add A;
    ret.insert( ret.end(), b.begin(), b.end() );        // add B;

    return ret;
}

template <typename T>
vector<T> &operator+=(vector<T> &a, const vector<T> &b)
{
    a.reserve( a.size() + b.size() );                // preallocate memory without erase original data
    a.insert( a.end(), b.begin(), b.end() );         // add B;
    return a;
}

int main() {
    // g++ -Wall -Wextra -O2 -std=c++17 helloworld.cpp
    int n;
    string s;

    cin >> n;
    cin >> s;

    for (size_t i = 0; i < s.size(); ++i) {
        char tmp = s[i] - 'A';

        tmp += n;
        tmp %= 26;
        tmp += 'A';

        s[i] = tmp;
    }

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void) {
	char S[100001];
	scanf("%s", S);
  
	int a = 0;
	int X[200] = { 0 };
	for (int i = 0; i < strlen(S); i++) {
		a = S[i];
		X[a] = 1;
	}

	a = 0;
	for (int i = 97; i <= 122; i++) {
		if (X[i] != 1) {
			a = i;
			break;
		}
	}

	if (a == 0) {
		printf("None");
	}
	else {
	printf("%c", a);
	}
		return 0;
}


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

bool is_prime[300000];

int main(){
    for (int i = 2; i <= 300000; i++) is_prime[i] = true;
    for (int i = 2; i * i <= 300000; i++){
        if (!is_prime[i]) continue;
        for (int j = 2; i * j <= 300000; j++) is_prime[i * j] = false;
    }
    int x;
    cin >> x;
    for (int i = x; i <= 3000000; i++) {
        if (is_prime[i]){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;

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

	cout << "Christmas";

	for(int i=0; i<25-d; i++) cout << " Eve";

	cout << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <bitset>
#include <cmath>

using namespace std;
using ll = long long;

ll go(ll h) {
    if (h == 1) {
        return 1;
    }
    if (h == 0) {
        return 0;
    }
    return 2 * go(h / 2) + 1;
}

int main() {
    ll h;
    cin >> h;
    cout << go(h) << "\n";
    return 0;
}


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

typedef long long ll;

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

// chmax, chmin
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; }

int main() {
    int N,M;
    cin >> N >> M;
    
    ll ans = 1900 * M + 100 * ( N - M );
    
    ll pow = 1;
    for ( int i = 0; i < M; ++i){
        pow *= 2;
    }
    
    ans *= pow;
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3524
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int a,b,c,sum=0;
  string s;
  cin>>a>>b;
  cout<<max(a+b,max(a-b,a*b))<<'\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define M 1000000007
vector<ll>vec[1000006];
ll ans=0;
ll vis[1000006];
int main(void)
{
  ll n,i,m,x,y,j;
  char a[1006][1006];
  ll dp[1006][1006];
  cin>>n>>m;
  for(i=0;i<n;i++)
  {
	for(j=0;j<m;j++)
	{
    	cin>>a[i][j];
	}
  }
  //if(a[0][0]=='#')
  memset(dp,0,sizeof(dp));
 dp[0][0]=1;
 for(i=1;i<n;i++)
 {
 	if(a[i][0]!='#')
 dp[i][0]=(dp[i-1][0]%M)%M;
 }
 for(i=1;i<m;i++)
 {
 	if(a[0][i]!='#')
 	dp[0][i]=(dp[0][i-1]%M)%M;
 }
  for(i=1;i<n;i++)
  {
  	for(j=1;j<m;j++)
  	{
  		if(a[i][j]=='#')
  		continue;
    	dp[i][j]=(dp[i-1][j]%M+dp[i][j-1]%M)%M;
  	}
  }
 
  cout<<dp[n-1][m-1]<<endl;
}

Measured memory_bytes: 34304
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string.h>
using namespace std;
int digit[4];
int main(){
	int n,m;
	cin>>n>>m;
	int fac=0;
	memset(digit,-1,sizeof(digit));
	if(n==1&&m==0){
		cout<<0<<endl;
		return 0;
	}
	while(m--){
		int a,b;  cin>>a>>b;
		if(a==1&&b==0&&n!=1) {
		fac=1;
		}
		else if(digit[a]!=-1&&digit[a]!=b) { fac=1; }
		else digit[a]=b;
	}
	if(fac) cout<<-1<<endl;
	else{
		int ans=0;
		if(digit[1]==-1) ans+=pow(10,n-1);
		else ans+=digit[1]*pow(10,n-1);
		if(digit[2]!=-1) ans+=digit[2]*pow(10,n-2);
		if(digit[3]!=-1) ans+=digit[3]*pow(10,n-3);
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
sub f{my($u,$t,$p)=@_;push@$t,$u;$_-$p&&f($_,$t^R,$u)for@$u}@a=$,=$";$#a=<>;map{push@$_,$u-$_+$;for($u,$;)=split}<>;f 1,b;@b>$./3&@0>$./3?map{$s=--$x;$a[$_]=$s+=3for@$_}0,b:map$a[$_]=$#x+=$#x%3,@b>@0?@b:@0;print map$_<=$.&&$_||3*++$z,@a

Measured memory_bytes: 271104