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

#define ll long long int

ll n, a[3005], dp_mx[3005][3005], dp_mn[3005][3005];

ll f(ll i, ll j){

    if(i > j) return 0;
    if(i == j+1) return dp_mx[i][j] = max(a[i], a[j + 1]) - min(a[i], a[j + 1]);

    if(dp_mx[i][j] != -1) return dp_mx[i][j];

    ll p = a[i] + min(f(i+2,j), f(i+1,j-1));
    ll q = a[j] + min(f(i+1, j-1), f(i, j-2));

    return dp_mx[i][j] = max(p,q);
}

ll g(ll i, ll j){

    if(i > j) return 0;
    if(i == j+1) return dp_mn[i][j] = max(a[i], a[j + 1]) - min(a[i], a[j + 1]);

    if(dp_mn[i][j] != -1) return dp_mn[i][j];

    ll p = a[i] + min(f(i+2,j), f(i+1,j-1));
    ll q = a[j] + min(f(i+1, j-1), f(i, j-2));

    return dp_mn[i][j] = max(p,q);
}

int main() {

    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

    cin>>n;
    for(ll z=0;z<n;z++) cin>>a[z];

    memset(dp_mx, -1, sizeof dp_mx);

    ll j = f(0,n-1);
    ll j1 = f(1,n-1), j2 = f(0, n-2);
    if(j1 < j2) cout<<j - j1;
    else cout<<j - j2;




    return 0;
}

Measured memory_bytes: 74368
import sys


n=int(input())
s=input()
t=input()
test=s+t
if(s==t):
    print(len(s))
    sys.exit()
for i in range(1,n+1)[::-1]:
    test=s[0:-i]+t
    if(test[:n]==s and test[-n:]==t):
        print(len(test))
        sys.exit()
        
print(len(s+t))

Measured memory_bytes: 3064
n, m = [int(a) for a in input().split(" ")]
alist = []
for i in input().split(" "):
    alist.append(int(i))
alist = sorted(alist, reverse=True)

chosen = alist[:m]
least = chosen[-1]
if least < sum(alist)/(4*m):
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3064
#include <stdio.h>

#define ARRAY_SIZE 200000

int main()
{
	int n = 0;
	scanf("%d", &n);

	int Array[ARRAY_SIZE] = { 0 };

	for (int i = 0; i < n; ++i) {
		scanf("%d", &Array[i]);
	}

	int maxv = Array[1] - Array[0]; // 最大の利益が負になる可能性があるので,0で初期化してはいけない.
	int minv = Array[0];

	for (int i = 1; i < n; ++i) {
		maxv = Array[i] - minv > maxv ? Array[i] - minv : maxv;
		minv = minv > Array[i] ? Array[i] : minv;
	}
	
	printf("%d\n", maxv);

	return 0;
}


Measured memory_bytes: 3544
N = int(input())
A = [0]*100000
AA = list(map(int, input().split()))
minA = 100000
maxA = 0
for a in AA:
  A[a] += 1
  minA = min(minA, a)
  maxA = max(maxA, a)
ans = 1
for i in range(max(minA-1,0), min(maxA+1, N-2)):
  ans = max(ans, A[i]+A[i+1]+A[i+2])
print(ans)

Measured memory_bytes: 14732
//#define _GLIBCXX_DEBUG
#include <atcoder/all>
#include <bits/stdc++.h>


using namespace std;
using namespace atcoder;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);
int dx[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
int dy[9] = {0, 1, 0, -1, 1, -1, -1, 1, 0};

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; }



int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  ll K; cin>>K;
  rep(i,K) cout<<"ACL";
  cout<<'\n';
  
  return 0;
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;




int main(void) {
  string str;
  cin >> str;
  ll i;
  string s="";
  
  for(i=0; i<str.size(); i++) {
    if(i<(ll)str.size()-1 && str[i]=='B' && str[i+1]=='C') {
      s.push_back('D');
      i++;
    }else {
      s.push_back(str[i]);
    }
  }
  
  ll ans=0;
  ll t=0;
  for(i=(ll)s.size()-1; i>=0; i--) {
    if(s[i]=='A') ans+=t;
    else if(s[i]=='D') t++;
    else t=0;
  }
  
  pt(ans);
}





Measured memory_bytes: 776
N,Q=list(map(int, input().split()))
S=input()

dp=[[0]*2 for _ in range(N)]
if S[0]=='A':
    dp[0][1]=1

for i in range(1,N):
    if S[i]=='C':
        dp[i][0]=dp[i-1][0]+dp[i-1][1]
    elif S[i]=='A':
        dp[i][0]=dp[i-1][0]
        dp[i][1]=1
    else:
        dp[i][0]=dp[i-1][0]
# print(dp)

for i in range(Q):
    l,r=list(map(int, input().split()))
    if l==1:
        print(dp[r-1][0]) 
    elif S[l-2]=='A' and S[l-1]=='C':
        print(dp[r-1][0]-dp[l-2][0]-1)
    else:
        print(dp[r-1][0]-dp[l-2][0])

Measured memory_bytes: 82808
N=int(input())
mod=10**9+7
dp=[{}for i in range(N)]
list=['AGC','ACG','GAC']
def dfs(x,y):
  if x in list:
    return 0
  if y==N:
    return 1
  if x in dp[y]:
    return dp[y][x]
  ans=0
  for i in 'ACGT':
    if x[0]=='A' and i=='C' and (x[1]=='G' or x[2]=='G'):
      continue
    ans+=dfs(x[1:]+i,y+1)
  dp[y][x]=ans%mod
  return ans%mod
print(dfs('TTT',0))

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

int main(){

  int N; cin >> N;
  vector<string> blue(N);
  for(int i=0;i<N;i++)
    cin >> blue.at(i);

  int M; cin >> M;
  vector<string> red(M);
  for(int i=0;i<M;i++)
    cin >> red.at(i);

  vector<int> scores(N+M);

  for(int i=0;i<N;i++){
    int score=0;
    for(int j=0;j<N;j++)
   	  if(blue.at(i)==blue.at(j))
        score++;
    for(int j=0;j<M;j++)
   	  if(blue.at(i)==red.at(j))
        score--;
    scores.at(i) = score;
  }
  for(int i=0;i<M;i++){
    int score=0;
    for(int j=0;j<N;j++)
   	  if(red.at(i)==blue.at(j))
        score++;
    for(int j=0;j<M;j++)
   	  if(red.at(i)==red.at(j))
        score--;
    scores.at(N+i) = score;
  }

  int max_score=0;
  for(int i=0;i<N+M;i++){
    if(max_score<scores.at(i))
      max_score=scores.at(i);
  }
  cout << max_score << endl;
}


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

int main(){
  int N;
  cin >> N;
  int T, A;
  cin >> T >> A ;
  int H[N];
  double dif;
  double min = 999999;
  int res ;
  for(int i = 0; i < N; i++){
    cin >> H[i];
    dif = abs(T - H[i] * 0.006 - A);
    if(dif < min){
      min = dif;
      res = i + 1;
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int i=0, j=0;
	double n[10000];
	while(scanf("%lf", &n[i])!=EOF){
		i++;
	}
	for(j=0;j<i;j++){
		printf("%lf\n", n[j]*7.81481481481481);
	}
	return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define lld long double
#define mod 1000000007
#define rep(i,n)    for(ll i=0;i<n;++i)
#define forup(i,a,b)    for(ll i=a;i<=b;++i)
#define all(v)    v.begin(),v.end()
#define inf 1000000010
#define pii pair<ll,ll>
#define vl vector<ll>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define MAXN 110
#define bsize 555
#define sz(v) v.size()
#define fast  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
ll power(ll x,ll y, ll md){ll res = 1;x%=md;while(y>0){if(y&1)res = (res*x)%md;x = (x*x)%md;y = y>>1;}return res%md;}

int main(){
    ll n,W;
    cin>>n>>W;
    ll w[110],v[110];
    rep(i,n){
        cin>>w[i]>>v[i];
    }
    ll dp[110][100010];
    rep(i,n+1){
        rep(j,W+1){
            if(i==0||j==0){
                dp[i][j]=0;
            }else if(w[i-1]<=j){
                dp[i][j]=max(v[i-1]+dp[i-1][j-w[i-1]],dp[i-1][j]);
            }else{
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    cout<<dp[n][W];
}

Measured memory_bytes: 81152
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int M = (int)1e5 + 1;

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

    int n;
    cin >> n;

    vector<int> p(M, 0);
    ll s = 0;

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

        p[a]++;
        s += a;
    }

    int q;
    cin >> q;

    while (q--) {
        int b, c;
        cin >> b >> c;

        s += (ll)(c - b) * p[b];
        p[c] += p[b];
        p[b] = 0;

        cout << s << '\n';
    }

    return 0;
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    ll n,d;
    cin>>n>>d;
    ll c=0;
    while(n--){
        ll x,y;
        cin>>x>>y;
        ll w = x*x + y*y;
        if(w <= d*d)
        c++;
    }
    cout<<c;
}

Measured memory_bytes: 3636
//spnauT
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int _=b,i=a;i<_;++i)
#define ROF(i,b,a) for(int _=a,i=b;i>_;--i)
#define REP(n) for(int _=(n);_--;)
#define _1 first
#define _2 second
#define PB push_back
#define SZ(x) int((x).size())
#define ALL(x) begin(x),end(x)
#define MSET(m,v) memset(m,v,sizeof(m))
#define MAX_PQ(T) priority_queue<T>
#define MIN_PQ(T) priority_queue<T,vector<T>,greater<T>>
#define IO {ios_base::sync_with_stdio(0);cin.tie(0);}
#define nl '\n'
#define cint1(a) int a;cin>>a
#define cint2(a,b) int a,b;cin>>a>>b
#define cint3(a,b,c) int a,b,c;cin>>a>>b>>c
using namespace std;using LL=int64_t;using PII=pair<int,int>;
using VI=vector<int>;using VL=vector<LL>;using VP=vector<PII>;
template<class A,class B>bool mina(A&x,B&&y){return y<x?(x=forward<B>(y),1):0;}
template<class A,class B>bool maxa(A&x,B&&y){return x<y?(x=forward<B>(y),1):0;}

class UnionFind
{
private:
	int N; VP par_sz;
public:
	UnionFind(int n = 0) noexcept {resize(n);}
	void resize(int n) noexcept {N = n; par_sz.resize(N); reset();}
	void reset() noexcept {FOR(i,0,N) par_sz[i] = {i,1};}
	int findSet(int a) noexcept
	{
		if(par_sz[a]._1 != a)
			par_sz[a]._1 = findSet(par_sz[a]._1);
		return par_sz[a]._1;
	}
	int unionSet(int a, int b) noexcept
	{
		a = findSet(a); b = findSet(b);
		if(a == b) return 0;
		if(par_sz[a]._2 < par_sz[b]._2) swap(a,b);
		par_sz[a]._2 += par_sz[b]._2;
		par_sz[b]._1 = par_sz[a]._1;
		return 1;
	}
};

const int MAX_N {100005};

int X[MAX_N];
int Y[MAX_N];

int main()
{
	IO;
	cint1(N);
	FOR(i,0,N) cin >> X[i] >> Y[i];

	auto dist = [&](int a, int b)
	{
		return min(abs(X[a] - X[b]), abs(Y[a] - Y[b]));
	};
	using T3 = tuple<int,int,int>;
	MIN_PQ(T3) Q;
	VI A(N);

	auto f = [&](auto func)
	{
		iota(ALL(A),0);
		sort(ALL(A), func);
		FOR(i,1,N) Q.emplace(dist(A[i-1], A[i]), A[i-1], A[i]);
	};
	f([&](int a, int b) {return X[a] < X[b];});
	f([&](int a, int b) {return Y[a] < Y[b];});

	UnionFind U(N);
	int sol {0};
	while(not Q.empty())
	{
		int d, a, b;
		tie(d,a,b) = Q.top();
		Q.pop();

		if(U.unionSet(a,b)) sol += d;
	}
	cout << sol << nl;

	return 0;
}

Measured memory_bytes: 6132
#include <bits/stdc++.h>
    #define REP(i, n) for(int i = 0;i < n;i++)
    #define REPR(i, n) for(int i = n;i >= 0;i--)
    #define FOR(i, m, n) for(int i = m;i < n;i++)
    #define FORR(i, m, n) for(int i = m;i >= n;i--)
    #define SORT(v, n) sort(v, v+n);
    #define VSORT(v) sort(v.begin(), v.end());
    #define llong long long
    #define pb(a) push_back(a)
    #define INF 999999999
    using namespace std;
    typedef pair<int, int> P;
    typedef pair<llong, llong> LP;
    typedef pair<int, P> PP;
    typedef pair<llong, LP> LPP;
    llong mod = 1000000007;

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

    llong cal(llong n,llong x)
    {
       if(n==-1) return 0;
       else return n/x+1;
    }

    int main()
    {
        llong a,b,x;
        cin>>a>>b>>x;
        cout<<cal(b,x)-cal(a-1,x)<<endl;
    }

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;
const int inf = 1001001000;
const long long int Inf = 1001001001001001000;

void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

//幅優先探索のテンプレ.デフォルトではstartからの距離を返す.
//graphは隣接リスト.startは探索開始地点
vector<int> bfs(vector<vector<int>> &graph, int start){
	queue<int> todo;
	vector<int> dist(graph.size(),-1);
	dist[start] = 0;
	todo.push(start);
	while(!todo.empty()){
		int now = todo.front();
		todo.pop();
		for (int i=0;i<graph[now].size();i++){
			int nxt = graph[now][i];
			if (dist[nxt] != -1) continue;
			dist[nxt] = dist[now] + 1;
			todo.push(nxt);
		}
	}
	return dist;
}

int main()
{
	int n;
	cin >> n;
	map <int,vector<pair<int, int>>> list;
	rep(i,n){
		int a;
		cin >> a;
		vector<pair<int, int>> temp(a);
		rep(j, a)
		{
			int x, y;
			cin >> x >> y;
			x--;
			temp[j] = pair<int, int>(x, y);
		}
		list[i] = temp;
	}
	int ans = 0;
	rep(i, 1 << n)
	{
		int t = 0;
		vector<int> syoujiki;
		rep(b, n)
		{
			if((i>>b)&1){
				syoujiki.push_back(b);
				t++;
			}
		}
		for (int s:syoujiki){
			vector<pair<int, int>> check = list[s];
			for (auto c:check){
				if (c.second == 1){
					if(count(all(syoujiki),c.first) == 0){
						t = 0;
					}
				}
				else {
					if(count(all(syoujiki),c.first) == 1){
						t = 0;
					}
				}
			}
		}
		ans = max(t, ans);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;

int main(void) {
	int N;
	while (cin >> N, N) {
		/*int head = 1, tale = 1;
		int sum = 0;
		int setNum = 0;
		while (true) {
			while ( tale < N && sum < N ) {
				sum += tale;
				tale++;
			}
			if ( tale >= N )
				break;
			if ( sum == N )
				setNum++;
			sum -= head;
			head++;
		}*/
		int setNum = 0;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				if (j * (j + 1) / 2 - i * (i + 1) / 2 == N) {
					setNum++;
				}
			}
		}
		cout << setNum << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <set>
#include <iomanip>
using namespace std;

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

int main()
{
    int N,M;
	cin >> N >> M;
	vector<P> unuse;
	for(int i=0; i<M; i++){
		int a, b;
		cin >> a >> b;
		a--;b--;
		unuse.push_back(P(a,b));
	}
	sort(unuse.begin(), unuse.end());
	int ans=1, left=unuse[M-1].first;
	for(int i=1; i<M; i++){
		if(unuse[M-i-1].second<=left){
			ans++;
			left=unuse[M-i-1].first;
		}
	}
	cout << ans << endl;
	
    

    return 0;
}


Measured memory_bytes: 1528
class edge:
    def __init__(self, from_node, to_node, cost):
        self.from_node = from_node
        self.to_node = to_node
        self.cost = cost

N, M = map(int, input().split())
ed = []
for i in range(M):
    a, b, c = map(int, input().split())
    a,  b = a-1, b-1
    ed.append(edge(b, a, -c))

def bellman_ford(s):
    INIT = 10 ** 30
    d = [INIT] * N
    d[s] = 0
    for _ in range(N):
        update = False
        for e in ed:
            if d[e.from_node] != INIT and d[e.to_node] > d[e.from_node] + e.cost:
                d[e.to_node] = d[e.from_node] + e.cost
                update = True
        if not update:
            return d, True
    return 0, False

d, j = bellman_ford(N-1)
if j:
    print(-d[0])
else:
    print("inf")


Measured memory_bytes: 46312
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;


int main() {
    int N, K;
    string S, S_copy;

    cin >> N >> K >> S;
    K = K - 1;

    if (S[K] == 'A') S[K] = 'a';
    if (S[K] == 'B') S[K] = 'b';
    if (S[K] == 'C') S[K] = 'c';

    cout << S;

    return 0;
}

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

int main(){
    int a,b,t;cin>>a>>b>>t;
    cout<<b*(t/a);
}



Measured memory_bytes: 256
import java.util.Arrays;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Scanner;

public class Main {
  Scanner sc;

  void run() {
    while (true) {
      int n = ni();
      int r = ni();
      if ((n | r) == 0)
        break;

      LinkedList<Integer> list = new LinkedList<Integer>();
      for (int i = 0; i < n; ++i) {
        list.add(n - i);
      }

      for (int i = 0; i < r; ++i) {
        int p = ni();
        int c = ni();

        ListIterator<Integer> ite = list.listIterator(p - 1);
        LinkedList<Integer> dup = new LinkedList<Integer>();
        for (int j = 0; j < c; ++j) {
          int e = ite.next();
          dup.add(e);
          ite.previous();
          ite.remove();
        }

        list.addAll(0, dup);
      }

      System.out.println(list.getFirst());
    }
  }

  int ni() {
    return sc.nextInt();
  }

  Main() {
    sc = new Scanner(System.in);
  }

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

  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }
}

Measured memory_bytes: 33676
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n;
	cin>>n;
	ll ar[n];
	for(i=0;i<n;i++){
		cin>>ar[i];
	}
	ll pre[n],suf[n];
	pre[0]=ar[0];
	for(i=1;i<n;i++){
		pre[i]=__gcd(pre[i-1],ar[i]);
	}
	suf[n-1]=ar[n-1];
	for(i=n-2;i>=0;i--){
		suf[i]=__gcd(suf[i+1],ar[i]);
	}

	ll mx=0;
	for(i=0;i<n;i++){
		if(i==0){
			k=suf[i+1];
		}
		else if(i==n-1){
			k=pre[i-1];
		}
		else {
			k=__gcd(pre[i-1],suf[i+1]);
		}
		mx=max(mx,k);
	}
	cout<<mx<<endl;
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = false;
}  // namespace mydef
using namespace mydef;
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define asn ans


void solve() {
}

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

    int X;
    cin >> X;
    Yes(X >= 30);

    solve();
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define db(x) cout << (x) << '\n';
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pii;
typedef pair<double,ll> pdi;
typedef pair<string,ll> psi;
typedef pair<ll,string> pls;
typedef pair<ll,pii> pip;
typedef pair<pii,pii> ppp;

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

    int s,w;
    cin >> s >> w;
    if(w>=s)
        db("unsafe")
    else
        db("safe")

    return 0;
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int sub = 0;

  int lower = max(a, c);
  int upper = min(b, d);

  cout << max(0, upper-lower) << endl;

  return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

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

    ll min_n=2,max_n=2;
    for(int i=k-1;i>=0;i--){
        ll min_num=((min_n+a[i]-1)/a[i])*a[i];
        ll max_num=(max_n/a[i])*a[i]+a[i]-1;
        if(min_num>max_n || max_num<min_n){
            cout<<-1<<endl;
            return 0;
        }
        min_n=min_num;
        max_n=max_num;
    }

    cout<<min_n<<" "<<max_n<<endl;
}

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

using P = pair<int, char>;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<P> p(M);
    for (int i = 0; i < M; ++i)
    {
        cin >> p[i].first >> p[i].second;
    }
    for (int i = 0; i < 1000; ++i)
    {
        string target = to_string(i);
        // reverse(target.begin(), target.end());
        int keta = to_string(i).size();

        // cout << i << ":" << keta << endl;
        if (keta != N)
            continue;
        bool ok = true;
        for (int j = 0; j < M; ++j)
        {
            if ((target[p[j].first - 1]) != p[j].second)
            {
                ok = false;
            }
        }
        if (ok)
        {
            //reverse(target.begin(), target.end());
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> map(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> map.at(i).at(j);
    }
  }
  vector<int> delW(W);
  vector<int> delH(H);
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (map.at(i).at(j) == '#') break;
      if (j == W - 1) delH.at(i)++;
    }
  }
  
  for (int i = 0; i < W; i++) {
    for (int j = 0; j < H; j++) {
      if (map.at(j).at(i) == '#') break;
      if (j == H - 1) delW.at(i)++;
    }
  }
  
  for (int i = 0; i < H; i++) {
    if (delH.at(i) == 1) continue; 
    for (int j = 0; j < W; j++) {
      if (delW.at(j) == 0) cout << map.at(i).at(j);
      if (j == W - 1) cout << endl;
    }
  }
}



Measured memory_bytes: 256
import math
def main():
    l, r = map(int,input().split())
    if r - l >= 637:
        print(0)
        return
    l_mod = l % 2019
    r_mod = r % 2019
    ans = []
    if l_mod > r_mod :
        ans = [i for i in range(l_mod,2019)]
        ans.extend([i for i in range(r_mod+1)])
    else:
        ans = [i for i in range(l_mod,r_mod+1)]
    ans.sort()
    a = 2019
    for i in range(len(ans)):
        for j in range(i + 1, len(ans)):
            a = min(a,(ans[i] * ans[j]) % 2019)
    print(a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,m;
    cin >> n >> m;
    vector<int> a(n+2);
    rep(i,m){
        int q,w;
        cin >> q >> w;
        a[q]++,a[w+1]--;
    }
    int cnt=0;
    rep(i,n){
        a[i+1]=a[i]+a[i+1];
    }
    rep(i,n+1){
        if(a[i]==m){
            cnt++;
        }
    }
    cout << cnt;

    return 0;
}

Measured memory_bytes: 640
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())
ans = 0
for a in range(1,k+1):
    for b in range(a, k+1):
        for c in range(b, k+1):
            if a == b and b == c:
                ans += gcd(a,b,c)
            elif (a == b and b != c) or (a != b and b == c):
                ans += gcd(a,b,c) * 3
            elif a != b and b != c:
                ans += gcd(a,b,c) * 6
            else:
                print('error')
print(ans)

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    vector<ll> A(N);
    vector<ll> B(N);

    map<ll, ll> M;

    REP(i, N){
        cin >> A[i];
        M[A[i]]++;
    }
    REP(i, N){
        cin >> B[i];
        M[B[i]]++;
    }
    sort(B.rbegin(), B.rend());

    ll maxn = 0;
    for(auto iter=M.begin(); iter!=M.end(); iter++){
        maxn = max(maxn, iter->second);
    }
    if(maxn >= N+1){
        cout << "No" << endl;
        return 0;
    }


    ll minx = LINF;
    ll maxx = -LINF;

    ll d;
    REP(i, N){
        if(A[i] == B[i]){
            minx = min(minx, i);
            maxx = max(maxx, i);
            d = A[i];
        }
    }

    // もしもかぶっているものがなければ
    if(minx == LINF){
        cout << "Yes" << endl;
        REP(i, N){
            if(i == N-1){
                cout << B[i] << endl;
            }
            else{
                cout << B[i] << " ";
            }
        }
        return 0;
    }
    // cout << "minx: " << minx << " maxx: " << maxx << endl;

    ll amin = LINF;
    ll amax = -LINF;
    // A[i]での範囲
    REP(i, N){
        if(A[i] == d){
            amin = min(amin, i);
            amax = max(amax, i);
        }
    }

    ll bmin = LINF;
    ll bmax = -LINF;
    // A[i]での範囲
    REP(i, N){
        if(B[i] == d){
            bmin = min(bmin, i);
            bmax = max(bmax, i);
        }
    }
    
    ll minc = min(amin-1, bmin-1);
    ll maxc = max(amax+1, bmax+1);

    // cout << "minc: " << minc << " maxc: " << maxc << endl;

    ll index1 = 0;
    ll index2 = 0;
    bool first = true;
    for(ll i=minx; i<=maxx; i++){
        if(index1 <= minc){
            // cout << B[i] << " " << B[index1] << endl;
            ll temp = B[i];
            B[i] = B[index1];
            B[index1] = temp;
            // B[i] = A[index1];
            // cout << B[i] << " " << B[index1] << endl;
            index1++;
            continue;
        }
        // B[i] = A[maxc + index2];
        ll temp = B[i];
        B[i] = B[maxc+index2];
        B[maxc+index2] = temp;
        index2++;
    }

    cout << "Yes" << endl;
    REP(i, N){
        if(i == N-1){
            cout << B[i] << endl;
        }
        else{
            cout << B[i] << " ";
        }
    }
    return 0;
}

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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n;
  std::cin >> n;
  std::vector<int64_t> v(n);
  std::cin >> v;

  std::sort(v.begin(), v.end());

  double ans = v[0] + v[1];
  ans /= 2;

  for (int64_t i = 2; i < n; i++) {
    ans += v[i];
    ans /= 2;
  }
  std::cout << std::fixed << std::setprecision(15) << ans << std::endl;

  return 0;
}


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

using namespace std;

int main() {
	int n, k; scanf("%d %d", &n, &k);
	vector<bool> biktima(n, true);
	for (int i = 0; i < k; ++i) {
		int d; scanf("%d", &d);
		for (int j = 0; j < d; ++j) {
			int x; scanf("%d", &x);
			biktima[--x] = false;
		}
	}
	int ans = 0;
	for (int i = 0; i < n; ++i) if (biktima[i]) ++ans;
	printf("%d\n", ans);
	return 0;
}


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 53;

long long x, total[N], patties[N];

long long count(long long n, long long pos = 1) {
  if (n == 0) return pos <= x;
  long long ret = 0; ++pos;
  if (total[n-1] + pos > x) return ret + count(n-1, pos);
  pos += total[n-1]; ret += patties[n-1];
  if (pos > x) return ret;
  ++ret; ++pos;
  if (total[n-1] + pos > x) return ret + count(n-1, pos);
  return ret + patties[n-1];
}

void solve() {
  total[0] = 1;
  patties[0] = 1;
  for (int i = 1; i < N; ++i) {
    total[i] = total[i-1]*2+3;
    patties[i] = patties[i-1]*2+1;
  }
  long long n; scanf("%lld%lld", &n, &x);
  printf("%lld", count(n));
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(a) cout<<#a<<":"<<a<<endl;
#define fr freopen("in.txt","r",stdin);
const int INF=0x3f3f3f3f;
const int N=1e6+7;
const int mod=1e9+7;
int maxn,minn;
int T,n,m;
string s1,s2;

int main(){
	cin>>s1>>s2;
	s2.erase(s2.end()-1,s2.end());
//	cout<<s2<<endl;
	if(s1==s2){
		puts("Yes");
	}
	else{
		puts("No");
	}


	return 0;
}





Measured memory_bytes: 3636
def resolve():
    N = int(input())
    S = list(input())

    def get_next(p_prev, prev, prev_mark):
        anms = ["S", "W"]
        p_prev_idx = anms.index(p_prev)
        if prev_mark == "o":
            return anms[p_prev_idx] if prev== "S" else anms[(p_prev_idx+1)%2]
        else:
            return anms[(p_prev_idx+1)%2] if prev == "S" else anms[p_prev_idx]

    out = ["S", "S"]
    for i in range(2, N):
        out.append(get_next(out[i-2], out[i-1], S[i-1]))
    if get_next(out[-2], out[-1], S[-1]) == out[0] and get_next(out[-1], out[0], S[0]) == out[1]:
        print("".join(out))
        return

    out = ["S", "W"]
    for i in range(2, N):
        out.append(get_next(out[i-2], out[i-1], S[i-1]))
    if get_next(out[-2], out[-1], S[-1]) == out[0] and get_next(out[-1], out[0], S[0]) == out[1]:
        print("".join(out))
        return
    
    out = ["W", "S"]
    for i in range(2, N):
        out.append(get_next(out[i-2], out[i-1], S[i-1]))
    if get_next(out[-2], out[-1], S[-1]) == out[0] and get_next(out[-1], out[0], S[0]) == out[1]:
        print("".join(out))
        return
    
    out = ["W", "W"]
    for i in range(2, N):
        out.append(get_next(out[i-2], out[i-1], S[i-1]))
    if get_next(out[-2], out[-1], S[-1]) == out[0] and get_next(out[-1], out[0], S[0]) == out[1]:
        print("".join(out))
        return
    
    print(-1)

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 88188
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<functional>
#include<queue>
#include<stack>
#include<math.h>
#define INF ((1<<30)-1+(1<<30))
#define EPS 1.0e-6

using namespace std;

typedef long long ll;

int n;
int a[105];

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

	int min = 99999999;
	for (int i = -100; i <= 100; i++) {
		int isum = 0;
		for (int j = 0; j < n; j++) {
			isum += (a[j] - i)*(a[j] - i);
		}
		if (isum < min)min = isum;
	}
	cout << min << endl;

	return 0;
}


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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;  cin >> a >> b >> c;
    cout << min(a + b, min(b + c, c + a)) << '\n';

    return 0;
}


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

using namespace std;

int main() {
	int r,n;
	while(cin >> r >> n,r) {
		vector<int> hi(2*r);
		while(n--) {
			int xl,xr,h; cin >> xl >> xr >> h;
			for(int i=max(-r,xl);i<min(r,xr);++i) hi[i+r]=max(hi[i+r],h);
		}
		double ans=1e9;
		for(int i=-r;i<=r;++i) {
			double tmp=sqrt(r*r-i*i);
			if(i!=-r) ans=min(ans,hi[i+r-1]-tmp+r);
			if(i!=r) ans=min(ans,hi[i+r]-tmp+r);
		}
		printf("%.10f\n",ans);
	}
	
	
	return 0;
}


Measured memory_bytes: 3216
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;

int gcd(int a, int b) { //最大公約数
  if (b==0) return a;
  else return gcd(b, a%b);
}

int lcm(int a, int b) { //最小公倍数
  return a * b / gcd(a, b);
}


int main()
{
  string s[2];
  cin>>s[0]>>s[1];
  if(s[0]==s[1]){
    cout<<"No"<<endl;
    return 0;
  }
  sort(s[0].begin(),s[0].end());
  sort(s[1].begin(),s[1].end());
  reverse(s[1].begin(),s[1].end());
  string tmp=s[1];


  sort(s,s+2);

  if(s[1]==tmp){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
    //freopen("in.txt","r",stdin);
    int n,m;
    scanf("%d%d",&n,&m);
    printf("%d\n",n*(n-1)/2+m*(m-1)/2);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
    
int main() {
    int n;
    cin >> n;
    double ans = n/2;
    if (n % 2 == 0) ans /= n;
    else ans = (ans+1) / n;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int main(void){
	          int i,j,k;

	      	  cin.tie(0);  ios_base::sync_with_stdio(false);

	      	  string s,t;
	      	  cin >> s  >> t;

	      	  int n=t.size(),m=s.size(),p=-1;

	      	  for(i=0;i<=m-n;i++){
	      		  bool f=true;
	      		  int c=0;
	      		  for(j=i;j<=i+n-1;j++){

	      			  if(s[j]!='?' && t[c]!=s[j]){
	      				  f=false; break;
	      			  }
	      			  else c++;
	      		  }

	      		if(f) p=i;
	      	  }


	      	  if(p==-1){
	      		  cout << "UNRESTORABLE" << endl;
	      		  return 0;
	      	  }

	      	  string ans;
	      	  for(i=0;i<p;i++){
	      		  if(s[i]=='?') ans+='a';
	      		  else ans+=s[i];
	      	  }
	      	  ans+=t;

	      	  for(i=p+n;i<m;i++){
	      		  if(s[i]=='?') ans+='a';
	      		  else ans+=s[i];
	      	  }

	      	  cout << ans << endl;

	          return 0;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
#[allow(unused_imports)]
use std::io::{self, Write};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
     };
     ($next:expr, $t:ty) => {
         $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
const MOD: u64 = 1000000007;
#[allow(dead_code)]
fn to_num(c: char) -> i64 {
    c as i64 - 48
}


fn main() {
    input!{
        N: usize,
        TA: [(usize, usize); N]
    }
    let mut L = 1;
    let mut R = 1;

    for (T, A) in TA {
        let n = max((L - 1) / T + 1 , (R - 1) / A + 1);
        L = n * T;
        R = n * A;
    }

    println!("{}", L+R);
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

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

    vector<int> p(a);
    vector<int> q(b);
    vector<int> r(c);
    for(int i=0;i<a;i++){
        cin>>p[i];
    }
    for(int i=0;i<b;i++){
        cin>>q[i];
    }
    for(int i=0;i<c;i++){
        cin>>r[i];
    }

    sort(p.rbegin(),p.rend());
    sort(q.rbegin(),q.rend());
    sort(r.rbegin(),r.rend());
    long long ans=0;
    for(int i=0;i<x;i++){
        ans+=p[i];
    }
    for(int i=0;i<y;i++){
        ans+=q[i];
    }
    int i=0;
    int j=x-1;
    int k=y-1;
    while(i<c){
        if(j<0 && k<0){
            break;
        }else if(j<0){
            if(q[k]<r[i]){
                ans-=q[k];
                ans+=r[i];
                k--;
                i++;
            }else{
                break;
            }
        }else if(k<0){
            if(p[j]<r[i]){
                ans-=p[j];
                ans+=r[i];
                j--;
                i++;
            }else{
                break;
            }
        }else{
            if(p[j]<q[k]){
                if(p[j]<r[i]){
                    ans-=p[j];
                    ans+=r[i];
                    j--;
                    i++;
                }else{
                    break;
                }
            }else{
                if(q[k]<r[i]){
                    ans-=q[k];
                    ans+=r[i];
                    k--;
                    i++;
                }else{
                    break;
                }
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}

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

namespace AtCoder.Contest.A
{
	static class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			var cin = new Scanner();

            Console.WriteLine((cin.NextInt() + cin.NextInt()) * cin.NextInt() / 2);

			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}

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

#define all(x) (x).begin(), (x).end()
#define sz(x) static_cast<int>((x).size())

using LL = long long;
template<class T, size_t D>
struct vec : vector<vec<T, D - 1>> {
  template<class... Args>
  vec(size_t n = 0, Args... args)
    : vector<vec<T, D - 1>>(n, vec<T, D - 1>(args...)) {}
};
template<class T>
struct vec<T, 1> : vector<T> {
  template<class... Args>
  vec(Args... args)
    : vector<T>(args...) {}
};

template<class T>
inline bool asMn(T& a, const T& b) { return a > b ? a = b, true : false; }
template<class T>
inline bool asMx(T& a, const T& b) { return a < b ? a = b, true : false; }
inline int nex(int i, int n) { return i == n - 1 ? 0 : i + 1; }
inline int pre(int i, int n) { return !i ? n - 1 : i - 1; }

mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

struct IT {
  #define mid ((lef + rig) >> 1)
  #define lC (i << 1)
  #define rC (i << 1 | 1)

  int n;
  vec<int, 1> mx, lz;
  IT(int n_)
    : n(n_) {
    mx = vec<int, 1>(n << 2);
    lz = vec<int, 1>(n << 2);
  }

  void trueVal(int i, int lef, int rig) {
    if (!lz[i]) {
      return ;
    }

    mx[i] += lz[i];
    if (lef != rig) {
      lz[lC] += lz[i];
      lz[rC] += lz[i];
    }
    lz[i] = 0;
  }

  void add(int l, int r, int val, int i, int lef, int rig) {
    trueVal(i, lef, rig);

    if (r < lef || rig < l) {
      return;
    }
    if (l <= lef && rig <= r) {
      lz[i] = val; trueVal(i, lef, rig);
      return;
    }

    add(l, r, val, lC, lef, mid);
    add(l, r, val, rC, mid + 1, rig);
    mx[i] = max(mx[lC], mx[rC]);
  }
  void add(int l, int r, int val) {
    add(l, r, val, 1, 0, n - 1);
  }

  int get(int l, int r, int i, int lef, int rig) {
    trueVal(i, lef, rig);
    if (l <= lef && rig <= r) {
      return mx[i];
    }

    if (r <= mid) {
      return get(l, r, lC, lef, mid);
    } else if (mid < l) {
      return get(l, r, rC, mid + 1, rig);
    } else {
      return max(get(l, r, lC, lef, mid), get(l, r, rC, mid + 1, rig));
    }
  }
  int get(int l, int r) {
    return get(l, r, 1, 0, n - 1);
  }
};

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

  int n, m; cin >> n >> m;
  vec<int, 2> a(m + 1);
  for (int i = 0; i < n; ++i) {
    int l, r; cin >> l >> r;
    a[l].emplace_back(r);
  }

  IT it(m + 2);
  for (int i = 0; i < it.n; ++i) {
    it.add(i, i, i);
  }

  int ans = n - m;
  for (int i = 0; i <= m; ++i) {
    for (auto& j : a[i]) {
      it.add(1, j, 1);
    }

    asMx(ans, it.get(i + 1, m + 1) - i - m - 1);
  }

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 14848
dic = dict()
for a in range(int(input())):
    i = input()
    if not i in dic:
        dic[i] = 1
    else:
        dic[i] = dic[i]+1
for b in range(int(input())):
    i = input()
    if not i in dic:
        dic[i] = -1
    else:
        dic[i] = dic[i]-1
print(max(max([a for a in dic.values()]), 0))

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

bool cards[52];

int Pos(char a)
{
    if(a == 'S')
        return 0;
    if(a == 'H')
        return 1;
    if(a == 'C')
        return 2;
    if(a == 'D')
        return 3;
}
char Suit(int i)
{
    if(i/13 == 0)
        return 'S';
    if(i/13 == 1)
        return 'H';
    if(i/13 == 2)
        return 'C';
    if(i/13 == 3)
        return 'D';
}

int main()
{
    int cant;
    cin >> cant;
    while(cant--)
    {
        char suit;
        int num;
        cin >> suit >> num;
        cards[Pos(suit)*13 + num - 1] = true;
    }
    for(int i = 0; i < 52; ++i)
    {
        if(!cards[i])
            cout << Suit(i) << " " << (i % 13) + 1 << endl;
    }
    return 0;
}



Measured memory_bytes: 3048
// abc134d: Preparing Boxes
#include <stdio.h>

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

  int m=0;
  for(int i=n;i>0;i--){
    int c=0;for(int j=i+i;j<=n;j+=i) c^=b[j];// 排他的論理和で剰余処理
    if(a[i]^c){
      b[i]=1;
      m++;
    }
  }

  printf("%d\n",m);
  for(int i=1;i<=n;i++)
    if(b[i]) printf("%d%c",i,--m?' ':'\n');

  return 0;
}

Measured memory_bytes: 2432