akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
using namespace std;

const int MOD = 1e9+7;
int a[200005], b[200005];
int c[8005][4005];
int d[8005][4005];

inline void add(int &x, int v) {
  if ((x += v) >= MOD) x -= MOD;
}

int main() {
  int n, MAXB = 0, MAXA = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &a[i], &b[i]);
    MAXA = max(MAXA, a[i]);
    MAXB = max(MAXB, b[i]);
    c[b[i]][a[i]]++;
  }
  for (int i = MAXB; i > 0; i--) 
    for (int j = MAXA; j > 0; j--) {
      add(c[i-1][j], c[i][j]);
      add(c[i][j-1], c[i][j]);
    }
  for (int i = 0; i <= MAXA; i++) {
    for (int j = 0; j <= MAXA; j++) add(d[0][i + j], c[0][i] * 1LL * c[0][j] % MOD);
    for (int j = 1; j <= MAXB; j++) add(d[j][i], (c[0][i] * 1LL * c[j][0]) % MOD);
  }
  for (int i = 1; i <= MAXB; i++) {
    for (int j = 0; j <= MAXA; j++) add(d[i][j], c[i][0] * 1LL * c[0][j] % MOD);
    for (int j = 1; j <= MAXB; j++) add(d[i + j][0], (c[i][0] * 1LL * c[j][0]) % MOD);
  }
  for (int i = 0; i < n; i++) add(d[2*b[i]][2*a[i]], (MOD-1));
  for (int i = 2*MAXB; i >= 0; i--)
    for (int j = 2*MAXA; j >= 0; j--) {
      if (i) add(d[i-1][j], d[i][j]);
      if (j) add(d[i][j-1], d[i][j]);
    }
  
  printf("%d\n", (int)((d[0][0] * 1LL * (MOD/2+1)) % MOD));
  return 0;
}


Measured memory_bytes: 87936
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)
const int INF = (1<<30);
const ll INFLL = 1LL<<62;
const long double EPS = 1e-12;

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

class HOGE{
  public:
    ll index;
    ll value;
    HOGE(ll index, ll value){
      this->index = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "index : " << index << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N, M;
  cin >> N;
  vector<string> strs(N);
  vector<int> count(N, 0);
  int end=0;
  rep(i, 0, N){
    string tmp;
    cin >> tmp;
    bool flag=false;
    rep(j, 0, end){
      if(strs[j] == tmp){
        count[j]++;
        flag = true;
        break;
      }
    }
    if(!flag){
      strs[end] = tmp;
      count[end]++;
      end++;
    }
  }

  cin >> M;
  rep(i, 0, M){
    string tmp;
    cin >> tmp;
    rep(j, 0, end){
      if(strs[j] == tmp){
        count[j]--;
      }
    }
  }

  int ans=0;
  rep(j, 0, end){
    if(ans < count[j]){
      ans = count[j];
    }
  }

  cout << ans << "\n";

  return 0;
}


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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

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

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

int main() {
    int A, B;
    cin >> A >> B;
    int cur = 1;
    int ans = 0;
    while (cur < B) {
        cur += A - 1;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &x){
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}
inline void write(int x){if (x > 9) write(x/10); putchar(x%10+'0'); }
const int L = 1000050;
string N;
int l,a[L],ans,f[L],g[L];
int main(){
	int i;
	cin>>N; l = N.size();
	for (i = 1; i <= l; ++i) a[i] = N[i-1]-'0';//,pre[i] = pre[i-1] + a[i];
	f[0] = 1,g[0] = 0;
	for (i = 1; i <= l; ++i){
		g[i] = g[i-1] + a[i];
		f[i] = f[i-1] + 9 - a[i];
		g[i] = min(g[i],f[i-1] + 10 - a[i]);
		f[i] = min(f[i],g[i]+1);
	}
//	for (i = l; i >= 1; --i) suf[i] = suf[i+1] + min(9-a[i],a[i]);
//	int ans = pre[l];
//	for (i = 0; i < l; ++i) ans = min(ans,2+pre[i]+suf[i+1]);
	cout<<g[l]<<endl;
    return 0;
}


Measured memory_bytes: 13188
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] v = new int[n];
		int[] c = new int[n];

		for (int i = 0; i < n; i++) {
			v[i] = sc.nextInt();

		}
		for (int i = 0; i < n; i++) {
			c[i] = sc.nextInt();

		}

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

			if (v[i] > c[i]) {
				sum += (v[i] - c[i]);

			}
			//System.out.println(sum);

		}

		System.out.println(sum);
		sc.close();
	}
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N;
  cin >> N;
  vector<double> x(N), y(N);
  for(int i = 0; i < N; i++){
    cin >> x[i] >> y[i];
  }

  vector<int> p(N);
  for(int i = 0; i < N; i++){
    p[i] = i;
  }

  double sum = 0.0;
  do{
    for(int i = 0; i < N-1; i++){
      sum += sqrt(pow(x[p[i]]-x[p[i+1]], 2) + pow(y[p[i]]-y[p[i+1]], 2));
    }
  }while(next_permutation(p.begin(), p.end()));

  double Npath = 1.0;
  for(int i = 1; i <= N; i++){
    Npath *= i;
  }

  cout << setprecision(16) << sum / Npath << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define INF (1e18)

int main(){   
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A,B,Q;
    ll s[100010], t[100010], x[100010];
    cin >> A >> B >> Q;
    rep(i,1,A+1) cin >> s[i];
    rep(i,1,B+1) cin >> t[i];
    rep(i,0,Q) cin >> x[i];
    s[0] = -INF; s[A+1] = INF;
    t[0] = -INF; t[B+1] = INF;
    rep(i,0,Q){
        ll ans = INF;
        ll p1 = lower_bound(s, s+A+2, x[i]) - s;
        ll p2 = lower_bound(t, t+B+2, x[i]) - t;
        ans = min(ans, max(s[p1] - x[i], t[p2] - x[i]));
        ans = min(ans, max(x[i] - s[p1-1], x[i] - t[p2-1]));
        ans = min(ans, s[p1] - t[p2-1] + min(s[p1]-x[i], x[i]-t[p2-1]));
        ans = min(ans, t[p2] - s[p1-1] + min(t[p2]-x[i], x[i]-s[p1-1]));
        print(ans);
    }
}


Measured memory_bytes: 3712
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N = I()
A = [0] + LI()
mod = 10**9+7

count = [0]*(N+1)
for i in range(1,N+2):
    if count[A[i]] != 0:
        a,b = count[A[i]],i  # 重複する文字のあるindex
    else:
        count[A[i]] = i


kaijou = [1]
for i in range(1,N+2):
    kaijou.append((kaijou[-1]*i) % mod)


def nCr(n,r):
    if n < r:
        return 0
    return (kaijou[n]*pow(kaijou[r],mod-2,mod)*pow(kaijou[n-r],mod-2,mod)) % mod


for k in range(1,N+2):
    print((nCr(N+1,k)-nCr(N+a-b,k-1)) % mod)


Measured memory_bytes: 92008
package main

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

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)
	a := make([]int, n)
	for i := range a {
		a[i] = nextInt(sc)
	}
	b := make([]int, n+5) // 溢れることを考えなくてすむように、大きめの配列を確保する
	for i := range b {
		b[i] = -1
	}
	left, right := n/2, n/2+1
	for i := 0; i < n; i++ {
		if n%2 == (i+1)%2 {
			b[left] = a[i]
			left--
		} else {
			b[right] = a[i]
			right++
		}
	}
	wtr := bufio.NewWriter(os.Stdout)
	for i := 0; i < len(b); i++ {
		if b[i] >= 0 {
			fmt.Fprintf(wtr, "%d ", b[i])
		}
	}
	fmt.Fprintln(wtr)
	wtr.Flush()
}


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

const int N=1e5+5;
long long n,ans,tot;
int x,m,y,sz,lft;
int used[N];
vector<int> v;

int main(){
	scanf("%lld%d%d",&n,&x,&m);
	for(y=x;!used[y];y=1ll*y*y%m){
		used[y]=1;
		v.push_back(y);
	}
	sz=int(v.size());
	if(n<=1ll*sz){
		sz=int(n);
		for(int i=0;i<sz;i++) ans+=v[i];
	}else{
		int i;
		for(i=0;i<v.size();i++){
			if(v[i]==y) break;
			ans+=v[i];
		}
		n-=1ll*i;
		sz=int(v.size())-i;
		for(int j=i;j<v.size();j++) tot+=v[j];
		ans+=n/sz*tot;
		lft=int(n%(1ll*sz));
		for(int j=i;j<i+lft;j++) ans+=v[j];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4340
$n=<>;@A=glob<>;$M=-1e7;$m=1e7;
for(0..$n-1){
    if($A[$_]>$M){
        $M=$A[$_];$Mi=$_;
    }
    if($A[$_]<$m){
        $m=$A[$_];$mi=$_;
    }
}
if($M*$m<0){
print $n*2-1,$/;
$i=($M+$m>=0)?$Mi+1:$mi+1;
print"$i $_\n"for 1..$n;
}else{print $n-1,$/}
if($M+$m<0){
    print $n-$_,$",$n-$_-1,$/ for 0..$n-2
}
else{
    print $_,$",$_+1,$/ for 1..$n-1
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long b=0;
  char a[3];
  cin>>a;
  
  b=b+a[0]+a[1]+a[2];
  b=b-'a'-'b'-'c';
  if(b==0)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;

  return(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define all(v) v.begin(), v.end()

const ll mod=1000000007;

int countBits(int in){
  int res=0;
  for(int i=0;i<10;i++){
    int msk=1<<i;
    if((in&msk)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string outputYesNo(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int n,m;cin>>n>>m;
  vector<int> h(n+1);
  for(int i=1;i<n+1;i++){
    cin>>h[i];
  }
  vector<vector<int>> g(n+1);
  for(int i=0;i<m;i++){
    int a,b;cin>>a>>b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int ans=0;
  for(int i=1;i<n+1;i++){
    vector<int> &elem=g[i];
    bool cond=true;
    for(int j=0;j<elem.size();j++){
      if(h[i]<=h[elem[j]]){
        cond=false;
        break;
      }  
    }
    if(cond){
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 8748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define INT(str) stoi((str), 0)
#define INTB(str) stoi((str), 0, 2) // 2進数の文字列を int に
//cout << fixed << setprecision(15);

int main() {
  int N, K;
  cin >> N >> K;
  vi H(N);
  REP(i, N) cin >> H[i];
  
  sort(H.begin(), H.end(), greater<int>());
  ll r = 0;
  for(int i = K; i < N; i++)
    r += H[i];
  
  cout << r << endl;
}

Measured memory_bytes: 4052
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# import numpy as np
sys.setrecursionlimit(int(pow(10,6)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("out.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

# @lru_cache(None)

t=1
# t=int(input())
for _ in range(t):
    H,W,K=L()
    r=[[]]
    for i in range(H):
        x=[]
        for ele in r:
            x.append(ele+[i])
        r+=x
    c=[[]]
    for i in range(0,W):
        x=[]
        for ele in c:
            x.append(ele+[i])
        c+=x

    A=[input() for i in range(H)]
    count=0
    for rows in r:
        for columns in c:
            indiv=0
            for i in range(H):
                for j in range(W):
                    if i not in rows and j not in columns and A[i][j]=="#":
                        indiv+=1
            if indiv==K:
                # print("-"*10)
                # print(*rows)
                # print(*columns)
                count+=1
    print(count)






Measured memory_bytes: 10608
#include <iostream>
#include <vector>

using namespace std;

#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define FOR1(i,a,b) for(int i = a ; i <= b ; i++)
#define FOR2(i,a,b) for(int i = a ; i >= b ; i--)

int main(){
    int n;
     
    cin >> n;
    while(n--){
        int s,g;
        vector<int> v;
         
        cin >> s >> g;
        if(s < g){
	  FOR1(i,s,g) v.push_back(i);
        }
        else if(s > g){
            if(s > 5){
	      FOR1(i,s,9) v.push_back(i);
                if(g > 5){
		  FOR2(i,5,0) v.push_back(i);
		  FOR1(i,1,g) v.push_back(i);
                }
                else{
		  FOR2(i,5,g) v.push_back(i);
                }
            }
            else if(s <= 5){
	      FOR2(i,s,g) v.push_back(i);
            }
        }        
    
	rep(i,(int)v.size()){
            if(!i) cout << v[i];
            else cout << ' ' << v[i];
        }
        cout << endl;
    }
     
    return 0;
}

Measured memory_bytes: 1220
# @oj: atcoder
# @id: hitwanyang
# @email: 296866643@qq.com
# @date: 2020-04-29 14:14
# @url:https://atcoder.jp/contests/abc163/tasks/abc163_a
import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string
# region fastio

BUFSIZE = 8192

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
def main():
    r=int(input())
    print (round(2*math.pi*r,2))
if __name__ == "__main__":
    main()

Measured memory_bytes: 68164
import scala.io.StdIn

object Main extends App {

  val Array(h, w) = StdIn.readLine().split(" ").map(_.toInt)

  val a = for (i <- 0 until h) yield StdIn.readLine()

  val exH = a.zipWithIndex.map(e => if (e._1.forall(c => c == '.')) -1 else e._2).filter(_ != -1)
  
  def allWhite(col: Int) = a.forall(p => p(col) == '.')

  val exW = (for (j <- 0 until w) yield if (allWhite(j)) -1 else j).filter(_ != -1)

  for (r <- 0 until h if exH.exists(_ == r)) {
    for (c <- 0 until w if exW.exists(_ == c)) {
      print(a(r)(c))
    }
    println("")
  }

}


Measured memory_bytes: 29036
#include <bits/stdc++.h>
// atoi : atoi(変数名.c_str())
// to_string(数値)
// %0桁数d とすると表示桁数が「桁数」に満たない場合に0埋めされる
// find(): int i = 変数名.find(“文字列”) 何番目にあるかを得る
// cout << (条件 ? "Yes" : "No") << endl;
// printf("%02d:%02d:%02d",hour,minute,second);
// 降順 sort(a.begin(),a.end(),greater<int>());
// bitset<ビット数> 変数名;  // すべてのビットが0の状態で初期化される
// bitset<ビット数> 変数名("ビット列");  // 指定したビット列で初期化される
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  int n;
  cin >> n;
  long T,A;
  cin >> T >> A;
  rep(i,n-1){
    long t,a;
    cin >> t >> a;
    long nt = (T+t-1)/t;
    long na = (A+a-1)/a;
    long mult = max(nt,na);
    T = t*mult;
    A = a*mult;
  }
  cout << T+A << endl;
}


Measured memory_bytes: 256
#ifndef bhartiya
    // #pragma GCC optimize("Ofast")
    // #pragma GCC optimize("unroll-loops")
    // #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
// not that imp
typedef pair<pll, ll> plll;
typedef vector<ll> vl;
typedef vector<pll> vll;

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


#define pb push_back
#define bitc  __builtin_popcountl
#define mp make_pair
#define ff first
#define ss second

#define swap(a,b) {a=a^b;b=a^b;a=a^b;}
#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define inf 200000000000000ll
// #define inf 10000000000ll
#define mod 1000000007ll
// #define mod 998244353ll
#define eps 1e-7

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

const ll maxn = 3004;
pair<ll,pll> dp[maxn][maxn];
string s,st,str="";
bool vis[maxn][maxn];

ll recur(ll i, ll j){
    if(i<0 || j<0) return 0;
    if(vis[i][j]) {
        trace(i,i,j,dp[i][j].ff);
        return dp[i][j].ff;
    }
    vis[i][j] = true;
    if(s[i] == st[j]){
        trace(i,j);
        ll x = recur(i-1, j-1);
        trace(i,j,x);
        dp[i][j] = mp(x+1, mp(i-1,j-1));
    }
    else {
        ll a = recur(i-1,j);
        ll b = recur(i,j-1);
        if(a>=b){
            dp[i][j] = mp(a,mp(i-1,j));
        }
        else if(b>a){
            dp[i][j] = mp(b,mp(i,j-1));
        }
    }
    return dp[i][j].ff;
    trace(i,j,dp[i][j].ff);
}

void getStr(ll i, ll j){
    if(i<0 || j<0) return;
    if(s[i] == st[j]) str = s[i] + str;
    getStr(dp[i][j].ss.ff,dp[i][j].ss.ss);
}

int main() 
{ 
	ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.precision(10);
    // cin.exceptions(cin.failbit);
    #ifdef bhartiya
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int t = 1;
    // cin>>t;
    while(t--){
        // string s, st;
        cin>>s>>st;
        recur(s.length()-1,st.length()-1);
        getStr(s.length()-1,st.length()-1);
        cout<<str;
    }
}

Measured memory_bytes: 220544
{
  const main = (input: string) => {
    const r = reader(input);
    const n = r.n();
    const ds = r.ns();

    let sum = 0

    ds.forEach((d1, i1) => {
      ds.forEach((d2, i2) => {
        if (!(i1 < i2)) {
          return
        }
        sum += d1 * d2
      })
    })
    console.log(sum)
  };

  const reader = (str: string) => {
    const lines = str.trim().split("\n");
    const s = () => lines.shift() || "";
    const n = () => Number(s());

    const ss = () => s().split(" ");
    const ns = () => ss().map(Number);
    const nls = () => lines.map(Number);

    return { lines, s, n, ss, ns, nls };
  };

  const getInput = () => require("fs").readFileSync("/dev/stdin", "utf8");

  main(getInput());
}


Measured memory_bytes: 7500
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def perm(n,mod=None):
    ans = 1
    for i in range(1,n+1):
        ans *= i
        if mod!=None:
            ans %= mod
    return ans
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]

N,P = mint()
ans = 1
p = 2
while P>1:
    if P%p==0:
        n = 0
        while P%p==0:
            n += 1
            P //= p
            if n==N:
                ans *= p
                n = 0
    p = p+1 if p*p<P else P
print(ans)

Measured memory_bytes: 67860
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"

int dp[1001][1001]; 
int main() {
	int N, M; cin >> N >> M;
	vector<int>ds(N), cs(M);
	for (int i = 0; i < N; ++i) {
		cin >> ds[i];
	}
	for (int i = 0; i < M; ++i) {
		cin >> cs[i];
	}
	for (int i = 0; i < 1001; ++i) {
		for (int j = 0; j < 1001; ++j) {
			dp[i][j] = 1e9+1e8;
		}
	}
	dp[0][0] = 0;
	for (int i = 0; i <= N; ++i) {
		for (int j = 0; j < M; ++j) {
			dp[i][j + 1] = min(dp[i][j], dp[i][j + 1]);
			if (i != N) {
				dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + ds[i] * cs[j]);

			}
		}
	}
	int ans = dp[N][M];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7020
// -*- mode:c++; coding:utf-8; indent-tabs-mode:nil; -*-
// ALDS1_1-A

#include <iostream>

static void print_ints(const int as[], const unsigned int n) {
  const char* sep = "";
  for (unsigned int i = 0; i < n; ++i) {
    std::cout << sep << as[i];
    sep = " ";
  }
  std::cout << std::endl;
}

inline
static void insert(int as[], const unsigned int i) {
  // as[0..i-1] is sorted
  const int asi = as[i];
  unsigned int j = i;
  while (j >= 1 && asi < as[j-1]) {
    as[j] = as[j-1];
    --j;
  }
  as[j] = asi;
}

void insertion_sort(int as[], const unsigned int n) {
  for (unsigned int i = 1; i < n; ++i) {
    print_ints(as, n);
    insert(as, i);
  }
}

int main(void) {
  unsigned int n;
  std::cin >> n;
  int as[n];
  for (unsigned int i = 0; i < n; ++i) {
    std::cin >> as[i];
  }

  insertion_sort(as, n);
  print_ints(as, n);

  return 0;
}
// end

Measured memory_bytes: 1168
#include<cstdio>
#include<algorithm>
int main()
{
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	printf("%d\n",std::max(0,std::min(b,d)-std::max(a,c)));
	return 0;
}

Measured memory_bytes: 128
import Data.List
import Control.Monad
g k (x:[])=head x 
g k (x:y:xs)=if last x+last y < k then g (k-last x) (y:xs) else head y
main=do
 [n,k]<-map read.words<$>getLine
 ab<-replicateM n (map read.words<$>getLine)
 let abl=sortBy (\x y->if head x<=head y then LT else GT) ab
 print$g k abl

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 62;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n;
  ll m;
  cin >> n >> m;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  rep(i, n) a[i] /= 2;
  ll g = a[0];
  rep(i, n-1) g = __gcd(g, a[i+1]);
  rep(i, n) {
    if((a[i] / g) % 2 == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  ll l = 1ll;
  rep(i, n) l = l * a[i] / __gcd(l, a[i]);
  cout << (m/l+1)/2 << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
//#define ll long long
const int M=111000;
bool t[111111];
int rui[111111];
int q,l,r;

int main(){
	t[0]=t[1]=1;

	for(int i=2;i<=M;i++){
		if(!t[i]){
		for(int j=i*2;j<=M;j+=i)t[j]=1;
		}
	}
	for(int i=1;i<=M;i++){
		if(!t[i]&&!t[(i+1)/2])rui[i]=1;
	}
	for(int i=2;i<=M;i++)rui[i]+=rui[i-1];

	cin>>q;
	rep(i,q){
		cin>>l>>r;
		cout<<rui[r]-rui[l-1]<<endl;
	}	
	
	return 0;
}


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

// {{{ put
void newline() {cout << endl;}
template <typename T> void display(T input){cout << input;}
template <typename T> void put(T input){display(input); newline();}
// }}}

int digit_num(int n){
  return n >= 10 ? 1 + digit_num(n / 10)
                 : 1;
}

int main() {
  int a, b;
  while(cin >> a){
    cin >> b;
    put(digit_num(a + b));
  }
}

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

int main () {
  string S, T;
  cin >> S >> T;
  
  int a = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) != T.at(i)) {
      a++;
    }
    else {
      continue;
    }
  }
  
  cout << a << endl;
}


Measured memory_bytes: 3912
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222





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



  cin >> n >> m;
  vll a(n), v;
  rep(i, n) cin >> a[i];
  sort(all(a));
  vpll vp;
  rep(i, m) {
    ll b, c;
    cin >> b >> c;
    vp.pb(pll(c, b));
  }
  sort(rall(vp));
  rep(i, m) {
    rep(j, vp[i].second) {
      v.pb(vp[i].first);
      if (v.size() >= n) break;
    }
  }
  ll cur = 0;
  rep(i, n) {
    if (a[i] < v[cur]) {
      a[i] = v[cur];
      cur++;
    }
    if (cur == v.size()) break;
  }
  ans = accumulate(all(a), 0LL);
  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 5744
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  string t, b, ans="YES";
    cin >> t >> b;
    for(int i=0; i<3; i++){
      if(t[i]!=b[2-i]) ans="NO";
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
import math

X = int(input())
a = math.ceil(X / 108 * 100)
b = math.floor(X / 108 * 100)

if int(a / 100 * 108) == X:
    print(a)
elif int(b / 100 * 108) == X:
    print(b)
else:
    print(':(')


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 2100000010;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;
typedef pair<int,P> PP;

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 mod(ll &val, ll M) {
    val = val % M;
    if(val < 0) {
        val += M;
    }
}

template<typename T>
T RS(T N, T P, T M){
    if(P == 0) {
        return 1;
    }
    if(P < 0) {
        return 0;
    }
    if(P % 2 == 0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) {
        return N * RS(N,P - 1,M);
    }
    return N * RS(N, P-1, M) % M;
}

int main() {
    int N;
    cin >> N;
    int ret = 0;
    for(int i = 1;i <= N;i++) {
        if(N % i == 0) {
            ret += N / i - 1;
        }
        else {
            ret += N / i;
        }
    }
    cout << ret << endl;
}

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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i,N) for(int i=0; i<N; i++)
#define cinv(v,N) vector<int> v(N); for(int i=0; i<N; i++){ cin >> v[i]; }
#define mt make_tuple
const ll MOD2 = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
  //input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n, k; cin >> n >> k; ll m;
  vector<ll> x(n); FOR(i,n){ cin >> x[i]; }
  m = lower_bound(x.begin(), x.end(), 0)-x.begin();//x[m]>=0,x[m-1]<0
  //左側にm本,0と右側にn-m本蝋燭がある。
  
  //main
  ll ans = 1e18;
  for(int i=1; i<=n-m; i++){//右側で終了。右側を何本消すか。m→1,m+i-1→i。
    if(i>k||(k-i)>m){
      continue;
    }else{
      ll tmp;
      if((k-i)!=0){//0<(k-i)<=mの時。
        tmp = abs(x[m-1+i])+2*abs(x[m-(k-i)]); 
      }else{
        tmp = abs(x[m-1+i]); 
      }
      ans = min(ans,tmp);
    } 
  }
  for(int i=1; i<=m; i++){//左側で終了。左側を何本消すか。m-1→1,0→m
    if(i>k||(k-i)>n-m){
      continue;
    }else{
      ll tmp;
      if((k-i)!=0){
        tmp = abs(x[m-i])+2*abs(x[m-1+(k-i)]);
      }else{
        tmp = abs(x[m-i]);
      }
      ans = min(ans,tmp);
    } 
  }
  
  // output
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <map>
#include <queue>
#include <math.h>
using namespace std;

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

	if (n % 500 <= a)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
from itertools import product
from operator import mul

SGN = (-1, 1)

N, M = map(int, input().split())

e = [list(map(int, input().split())) for _ in range(N)]

ans = -1
for sgns in product(SGN, repeat=3):
    t = [sum(map(mul, ee, sgns)) for ee in e]
    ans = max(ans, sum(sorted(t, reverse=True)[:M]))
print(ans)


Measured memory_bytes: 3444
import math
import fractions
import copy
#以下てんぷら
def j(q):
    if q==1: print("YES")
    elif q == 0:print("NO")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in a:
        print(i)
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


#n = ip()                                     #入力整数1つ
n,m= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
a=[ip() for i in range(m)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#a.pop(0)は10^5あるときTLEしやすい!注意!抜くなら逆ソート!
#これを消すとなぜかWAになる呪い
for i in range(m-1):
    if a[i]+1 == a[i+1]:
        print(0)
        exit(0)
if n == 1:
    print(1)
else:
    p = 0
    dp = [0 for i in range(n+1)]
    dp[1]  = 1
    dp[2] = 2
    for i in range(3,n+1):
        dp[i] = dp[i-1]+dp[i-2]
    left = [i+1 for i in a]
    right = [i-1 for i in a]
    left.insert(0,0)
    right.append(n)
    s = 1
    for i in range(len(right)):
        if right[i] != left[i] :s*=dp[right[i]-left[i]]
    print(s%rem)


Measured memory_bytes: 468180
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mxn= 2e5+5;
// check for forloop
// intialize variable
// overflow
// go for easy solution
#define mod 1000000007
ll INF = 1000000000000000005LL;
#define endl '\n'
void rishabh(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int main(){
    int n;
    cin>>n;
    int arr[mxn];
    for(int i=1;i<=n;i++){
        cin>>arr[i];
    }
    int ans=0;
    for(int i=0;i<=n;i++){
        if(arr[arr[i]]==i)ans++;
    }
    cout<<ans/2;
}

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


int main() {
ll n,k;
  cin>>n>>k;
 string s;
  cin>>s;
  vector<int> vec;
    
  ll re=0;
  bool fir1=true;
  if(s[0]=='0'){
    fir1=false;}
  rep(i, s.size()){
    if(i>=1){
      if(s[i]!=s[i-1]){
        vec.push_back(re);
        re=0;}
    }
    re++;
    if(i==s.size()-1){
      vec.push_back(re);}
  }
  
  ll lon=vec.size();
  
  ll lsum[lon+1];
  lsum[0]=0;
  lsum[1]=vec.at(0);
  for(int i=2;i<=lon;i++){
    lsum[i]=lsum[i-1]+vec.at(i-1);}
  
  
  ll res=0;
  if(fir1){
    for(int i=0;i<=lon;i+=2){
      res=max(res,lsum[min(i+2*k+1,lon)]-lsum[i]);
    }
  }
  
  
  if(!fir1){
    res=lsum[min(2*k,lon)]-lsum[0];
    for(int i=1;i<=lon;i+=2){
      res=max(res,lsum[min(i+2*k+1,lon)]-lsum[i]);
    }
  }
  
  cout<<res<<endl;

}


Measured memory_bytes: 1656
n=int(input())
s=[input() for _ in range(n)]

import collections as cl
c=cl.Counter(s)
saidai=max(c.values())

ans=[]
for i in c.keys():
  if c[i]==saidai:
    ans.append(i)

ans=sorted(ans)
for i in range(len(ans)):
  print(ans[i])

Measured memory_bytes: 101968
A,B=map(int,input().split())

def f(a):
    e=a%4
    if e==0:
        return a
    elif e==1:
        return (a-1)^a
    elif e==2:
        return (a-2)^(a-1)^a
    return 0

print(f(B)^f(A-1))

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

using namespace std;

const int N = 105;
const int K = 100005;

int n, k, a[N], f[K];

int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 0; i <= k; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (i >= a[j]) f[i] |= (f[i - a[j]] ^ 1);
    }
  }
  cout << (f[k] ? "First" : "Second") << endl;
  return 0;
}



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

int main() {
    int n;
    cin >> n;
    map<int, int> mp;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        mp[a - 1] += 1;
        mp[a    ] += 1;
        mp[a + 1] += 1;
    }
    int ans = 0;
    /*
    mp[1] = 2;
    mp[3] = 5;
    mp[4] = 1;
    mp[7] = 1;
    */
    for(auto &x : mp){
        ans = max(ans, x.second);
    }
    cout << ans << endl;
}

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

int main() {
  int n,i;
  cin>>n;
  long double x,ans=0;
  string u;
  for(i=0;i<n;i++){
    cin>>x>>u;
    if(u=="JPY")
      ans+=x;
    else ans+=x*380000.0;
  }
  cout<<ans;

  
  
}

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++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
const int MOD = 1000000007;

int main() {
  string Ans = "NG";  // 回答：1

  int K; cin >> K; // 目標の元因数
  int A,B; cin >> A >> B; // 範囲

  for(int i = A ; i <= B; i++){
    if (i%K==0){
      Ans ="OK";
      break;
    }

  }

  cout << Ans << endl;
}


Measured memory_bytes: 3628
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace B
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var ABC = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var (A, B, C) = (ABC[0], ABC[1], ABC[2]);
            var n = A;
            var answer = false;
            while (n <= A * B)
            {
                if (n % B == C) answer = true;
                n += A;
            }

            Console.WriteLine(answer ? "YES" : "NO");
        }
    }
}


Measured memory_bytes: 28276
#include <iostream>
#include <cmath>
#include <numeric>

using namespace std;

#define ll long long

int N;
ll  T[105], ans = 1;

ll GCD(ll a, ll b){
    if(b==0) return a;

    return GCD(b, a % b);
}

ll LCM(ll a, ll b){
    ll ans_buff;

    if(a > b) ans_buff = (a / GCD(a, b)) * b;
    else ans_buff = (b / GCD(a, b)) * a;

    return ans_buff;
}

int main(){
    cin >> N;

    for(int i = 0; i < N; i++) cin >> T[i];

    for(int i = 0; i < N; i++) ans = LCM(ans, T[i]);

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include<iostream>
#include<string>

using namespace std;
 
int main(void){

	int g;
	char g2;
	string blood;
	string numbl[4]={"A","B","AB","O"};
	int nubl[4]={0};

	while(cin>>g>>g2>>blood){
		for(int i=0;i<4;i++){
			if(blood==numbl[i]) nubl[i]++;
		}
	}

	for(int i=0;i<4;i++){
		cout<<nubl[i]<<endl;
	}

    return 0;
}

Measured memory_bytes: 1216
import sys
n = int(input())
a = list(map(int,input().split()))
p = 0
for i in range(n):
    if a[i] % 2 == 0:
        if a[i] % 3 == 0 or a[i] % 5 == 0:
            p = 1
        else:
            print("DENIED")
            sys.exit()
print("APPROVED")
            
        

Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <string>
#include <functional>
#include <math.h>
#include <utility>
using namespace std;
int card[201],n;
void Cut(int k){
	int t[201];
	for(int i=0;i<2*n;i++)t[i]=card[i];
	for(int i=0;i<2*n;i++){
		card[i]=t[(i+k)%(2*n)];
	}
}
void Refull(){
	int t[201];
	for(int i=0;i<2*n;i++)t[i]=card[i];
	for(int i=0;i<n;i++){
		card[i*2]=t[i];
		card[i*2+1]=t[i+n];
	}
	return;
}
int main()
{
	int m;cin>>n>>m;
	for(int i=0;i<2*n;i++){
		card[i]=i+1;
	}
	for(int i=0;i<m;i++){
		int t;cin>>t;
		if(t==0)Refull();
		else Cut(t);
	}
	for(int i=0;i<2*n;i++)cout<<card[i]<<endl;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int f(int a, int b) {
  int la = to_string(a).size();
  int lb = to_string(b).size();
  return max(la, lb);
}

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

  int ans = to_string(n).size();
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      long long j = n / i;
      int tmp = f(i, j);
      if (tmp < ans) {
        ans = tmp;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#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()

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  int A[N],B[N-1];
  REP(i,N-1){
    cin>>B[i];
  }
  A[0]=B[0];
  A[N-1]=B[N-2];
  FOR(i,1,N-1){
    A[i]=min(B[i-1],B[i]);
  }
  lint ans=0;
  REP(i,N)ans+=A[i];
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main( void )
{
	int a, b, z, i;

	while(scanf("%d %d", &a, &b)!=EOF){
		z = a + b;
		for( i=0; z!=0; i++ ){
			z/=10;
		}
		printf("%d", i);
		putchar('\n');
	}

	return 0;
}

Measured memory_bytes: 604
#ANS-3
input_N,A,B = input().split()
A = int(A)
B = int(B)

count = 0
for i in range(int(input_N)+1):
    sum_all = 0
    i_str = str(i)
    for j in range(len(i_str)):
        sum_all += int(i_str[j])
    if A<=sum_all:
        if sum_all<=B:
            count += i
            
print(count)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main() {
	string s, s1, s2;
	cin >> s;

	s1 =  s.substr( 0, (s.size() - 1)/2 );
	s2 =  s.substr((s.size() + 2 )/2 );
	if (s1 == s2)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define llint long long

using namespace std;

llint n, k;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	
	llint ans = 0;
	for(;n;n/=k) ans++;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
n = int(input())
t0 = 0
x0 = 0
y0 = 0
flag = True

for _ in range(n):
    t, x, y = map(int, input().split())
    t -= t0
    x -= x0
    y -= y0
    diff = abs(x) + abs(y)
    t0 = t
    x0 = x
    y0 = y
    if diff > t:
        flag = False
        break
    if t % 2:
        if diff % 2:
            pass
        else:
            flag = False
            break
    else:
        if diff % 2:
            flag = False
            break
        else:
            pass
print('Yes') if flag else print('No')

Measured memory_bytes: 3064