akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<limits.h>
#include<queue>
#include<set>


#define MOD 1000000007
#define DEBUG 0


using namespace std;

long long int modpow(long long int a, int n) {

	if (n == 0)return 1;
	if (n == 1) return a;

	long long int wk = modpow(a, n / 2);

	long long int ret = 0;
	if (n % 2 == 0) {
		ret = 1;
	}
	else {
		ret = a;
	}

	return (((ret * wk) % MOD) * wk) % MOD;

}

long long int gcd(long long int a, long long int b) {
	long long int tmp;
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	long long int r = a % b;

	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

long long int lcm(long long int a, long long int b) {

	long long int wk_int;

	wk_int = (a * b) % MOD;
	
	long long int ret;

	ret = (wk_int * modpow(gcd(a, b), MOD - 2)) % MOD;

	return ret;

}

bool isPrime(int n) {
	if (n == 1)return false;
	if (n == 2)return true;

	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}

	return true;
}



bool comp(const pair<long long int, vector<int>> a, const pair<long long int, vector<int>> b) {
	if (a.first != b.first) {
		return a.first < b.first;
	}
	else {
		return a.second < b.second;
	}

}










int main(){

	
	int n, m;
	cin >> n >> m;

	int ans = 0;

	if (n > 0)ans += n * (n - 1) / 2;

	if (m > 0)ans += m * (m - 1) / 2;

	cout << ans << endl;

	

	return 0;
}



Measured memory_bytes: 256
r,g,b,n=map(int,input().split())
res=0
for i in range(n//r+1):
    for j in range(n//g+1):
        if (n-r*i-g*j)<0:
            continue
        elif (n-r*i-g*j)%b==0:
            res+=1
            #print(i,j,(n-r*i-g*j)%b)
print(res)

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N, T;
    ll mini = numeric_limits<ll>::max();
    cin >> N >> T;
    rep(i, N) {
        ll c, t;
        cin >> c >> t;
        if(T >= t) mini = min(mini, c);
    }
    if(mini == numeric_limits<ll>::max()) cout << "TLE";
    else cout << mini;
    cout << endl;
    return 0;
}


Measured memory_bytes: 3608
n = int(input())
t, a = map(float, input().split())
height = [float(i) for i in input().split()]
temp = [t - 0.006*i for i in height]
loc, diff = 0, 100000000
m = 0
for i in temp:
    m += 1
    j = abs(a-i)
    if j < diff:
        loc = m
        diff = j
print(loc)

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

#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, n, 0)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1e9 + 7

using namespace std;

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

int main(void)
{
    int r;
    cin >> r;
    if (r < 1200)
    {
        cout << "ABC" << endl;
    }
    else if (r < 2800)
    {
        cout << "ARC" << endl;
    }
    else
    {
        cout << "AGC" << endl;
    }
    return 0;
}

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

#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define si set<int>
#define stk stack<int>
#define que queue<int>
#define pb push_back
#define ff first
#define ss second
#define pii pair<int,int>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std; 

int main(){
	string s;
	cin>>s;
	vector<string> da={"SUN","MON","TUE","WED","THU","FRI","SAT"};

	for(int i=0;i<7;i++){
		if(s==da[i]){
			cout<<7-i<<endl;
			break;
		}
	}
}

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

int main()
{
	stack<int> R;
	int n;
	int car[1000];
	int i = 0;
	
	while (cin >> n){
		if (n == 0){
			car[i] = R.top();
			R.pop();
			i++;
		}
		else {
			R.push(n);
		}
	}
	
	for (int j = 0; j < i; j++){
		cout << car[j] << endl;
	}
	
	return (0);
}

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

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

    int w = z + y,ans = 0;
    for(int i = 0; x > w; i++){
        if(w + z > x) break;
        w += z + y;
        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
s=input()
t=set()
for i in range(len(s)):
    t.add(s[i])
cnt=0
u=t.pop()
t.add(u)
for i in range(len(s)):
    if(u==s[i]):
        cnt+=1
#print(cnt)
if(cnt==2 and len(t)==2):
    print("Yes")
else:
    print("No")




Measured memory_bytes: 3060
using System;
using System.Linq;
using System.Collections.Generic;

public class Hello{
    public static void Main(){

        string str = Console.ReadLine();
        int[] count = new int[26];
        
        for(int i = 0; i < 26; i++) count[i] = 0;
        for(int i = 0; i < str.Length; i++) count[str[i] - 97]++;
        for(int i = 0; i < 26; i++){
            if(count[i] % 2 == 0){
                continue;
            }else{
                Console.WriteLine("No");
                return;
            }
        }
        Console.WriteLine("Yes");
    }
}


Measured memory_bytes: 11092
N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]
C_x = list(range(101))
C_y = list(range(101))
 
if sum([h for _, _, h in X]) == 1:
  for x, y, h in X:
    if h != 0:
      print(x, y, h)
else:
  for px in C_x:
    for py in C_y:
      h_list = [abs(x - px) + abs(y - py) + h for x, y, h in X if h > 0]
      if len(set(h_list)) == 1:
        print(px, py, h_list[0])
        break

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include <vector>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
int main(void) {
	int N;
	cin >> N;
	int sum = 0, temp;
	rep(i, N){
		cin >> temp;
		sum += temp;
	}
	cout << sum - N;
	return 0;
}

Measured memory_bytes: 256
package main

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

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

func scanInt() int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func scanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}

func scanString() string {
	if sc.Scan() {
		return sc.Text()
	}
	panic(sc.Err())
}

var sc = newScanner()

func main() {
	n, m, q := scanInt(), scanInt(), scanInt()
	a := make([][]int, 4)
	for i := 0; i < 4; i++ {
		a[i] = make([]int, q)
	}
	for i := 0; i < q; i++ {
		for j := 0; j < 4; j++ {
			a[j][i] = scanInt()
		}
	}

	f := func(arr []int) int {
		ret := 0
		for i := 0; i < q; i++ {
			if arr[a[1][i]]-arr[a[0][i]] == a[2][i] {
				ret += a[3][i]
			}
		}
		return ret
	}

	var dfs func(i, x int, arr []int) int
	dfs = func(k, x int, arr []int) int {
		if k > n {
			return f(arr)
		}
		var ret int
		for i := x; i <= m; i++ {
			arr = append(arr[0:k], i)
			r := dfs(k+1, i, arr)
			if ret < r {
				ret = r
			}
		}
		return ret
	}

	arr := make([]int, 0, n+1)
	ans := dfs(0, 1, arr)
	fmt.Println(ans)
}


Measured memory_bytes: 1776
#include<bits/stdc++.h>
using namespace std;
int main() {
  int A, B;
  cin >> A >> B;
  int sum1 = A + B;
  int sum2 = (2*A) - 1; 
  int sum3 = (2*B) - 1; 
  if (A < B) cout << max(sum1, sum3) << endl;
  else cout << max(sum1, sum2) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>

using namespace std;

int main(int argc, char *argv[]) {
  int n, num[100] = {0};
  long long *sum, *aft;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> num[i];

  sum = new long long[21];
  aft = new long long[21];
  memset(sum, 0, sizeof(long long) * 21);
  sum[num[0]] = 1;
  for (int i = 1; i < n-1; i++) {
    memset(aft, 0, sizeof(long long) * 21);
    for (int j = 0; j < 21; j++) {
      if (sum[j] > 0) {
        int a = j + num[i];
        if (0 <= a && a <= 20)
          aft[a] += sum[j];
        a = j - num[i];
        if (0 <= a && a <= 20)
          aft[a] += sum[j];
      }
    }
    long long *tmp = sum;
    sum = aft;
    aft = tmp;
  }

  cout << sum[num[n-1]] << endl;
  return 0;
}

Measured memory_bytes: 1184
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int main(){
  int N,X;
  cin>>N>>X;

  if(X==1||X==2*N-1){
    cout<<"No"<<endl;
    return 0;
  }

  vector<int> ans(2*N,0);
  vector<int> used(2*N,0);
  used[X-1]=1;used[X]=1;used[X+1]=1;
  ans[N]=X;
  ans[N-1]=X+1;
  ans[N+1]=X-1;

  int now=1;
  for(int i=1;i<=2*N-1;i++){
    if(ans[i]==0){
      while(now<=2*N-1&&used[now]==1) now++;
      ans[i]=now;
      used[now]=1;
    }
  }
  cout<<"Yes"<<endl;
  for(int i=1;i<=2*N-1;i++) cout<<ans[i]<<endl;

  return 0;
}


Measured memory_bytes: 3072
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

int A[200010];

int main()
{
    int N; cin>>N;
    map<int, vector<int>> mp;
    for(int i=0; i<N; ++i) {
        cin>>A[i];
        mp[A[i]+i].push_back(i);
    }
    long res=0;
    for(int i=N-1; i>0; --i) {
        int x=i-A[i];
        if (x<=0 or !mp.count(x)) continue;
        auto& v=mp[x];
        int t=lower_bound(begin(v), end(v), i-1)-begin(v);
        res+=t;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 26232
package main

import (
	"fmt"
)

func main() {
	var s, t string
	fmt.Scan(&s, &t)

	sm := make(map[byte]int)
	tm := make(map[byte]int)
	for i := 0; i < len(s); i++ {
		if sm[s[i]] != tm[t[i]] {
			fmt.Println("No")
			return
		}
		sm[s[i]] = i + 1
		tm[t[i]] = i + 1
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

int main() {
	const int INF = 100010;
	int N, M;
	cin >> N >> M;
	vector<int> x(N + 1, INF);
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		x[a] = min(x[a], b);
	}

	int res = 0;
	int minb = x[1];
	for (int i = 2; i <= N; i++) {
		if (minb <= i) {
			res++;
			minb = INF;
		}
		
		if (minb > x[i]) {
			minb = x[i];
		}
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,ll>;

int main() {
  int t;
  cin >> t;
  rep(_,t){
    int n;
    cin >> n;
    ll ans = 0;
    vector<P> vl,vr;
    rep(i,n){
      ll k,l,r;
      cin >> k >> l >> r;
      ans += min(l,r);
      if(l>r) vl.emplace_back(k,l-r);
      if(l<r) vr.emplace_back(n-k,r-l);
    }
    sort(vl.rbegin(),vl.rend());
    sort(vr.rbegin(),vr.rend());
    int i=0; priority_queue<ll> q;
    rep(_k,int(vl.size())){
      int k = vl.size()-_k;
      while(i<vl.size()&&vl[i].first>=k) q.emplace(vl[i++].second);
      if(!q.empty()) ans+=q.top(),q.pop();
    }
    i=0; q = priority_queue<ll>();
    rep(_k,int(vr.size())){
      int k = vr.size()-_k;
      while(i<vr.size()&&vr[i].first>=k) q.emplace(vr[i++].second);
      if(!q.empty()) ans+=q.top(),q.pop();
    }
    cout << ans << endl;
  }
}


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

int main() {
    double ans = 0;
    int N;
    cin >> N;
    vector<long long> A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for(int i = 0; i < N; i++) {
        ans += double(1) / A[i];
    }
    ans = double(1) / ans;
    cout << fixed << setprecision(6) << ans << endl;
}

Measured memory_bytes: 3756
import sys
import math

results = set()


s = sys.stdin.readline().strip()
K = int(sys.stdin.readline().strip())


chars = set(list(s))

for c in sorted(list(chars)):
    t = s

    ss = set()
    while True:
        i = t.find(c)
    
        if i == -1:
            break

        ss.add(t[i:])

        t = t[i+1:]

    for sa in sorted(list(ss)):
        for j in range(1, len(sa)+1):
            results.add(sa[:j])
            if len(results)==K:
                print(sa[:j])
                quit()

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

int main(){
   int n;
   string s;
   cin >> n;
   cin >> s;
   int ans = 1;
    for(int i = 1; i < n; i++){
        if(s[i-1] != s[i]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#define int long long
using namespace std;

int powmod(int a, int n, int mod) {
	if (n == 0) return 1;
	if (n % 2 == 0) return powmod((a * a) % mod, n / 2, mod);
	return (a * powmod(a, n - 1, mod)) % mod;
}

int mod = 1000000007;
int n, a, b, c;
int fact[200001];
int finv[200001];

int comb(int n, int k) {
	return fact[n] * finv[k] % mod * finv[n - k] % mod;
}

signed main() {
	int i;
	
	cin >> n >> a >> b >> c;
	
	fact[0] = 1;
	finv[0] = 1;
	for (i = 1; i < 2 * n; i++) {
		fact[i] = i * fact[i - 1] % mod;
		finv[i] = powmod(fact[i], mod - 2, mod);
	}
	
	int ans = 0;
	int inv = powmod(a + b, mod - 2, mod);
	
	for (i = 0; i < n; i++) {
		int p = powmod(a, n, mod) * powmod(b, i, mod) % mod * powmod(inv, n + i, mod) % mod * comb(n - 1 + i, i) % mod;
		ans += p * (n + i) % mod;
		ans %= mod;
	}
	
	for (i = 0; i < n; i++) {
		int p = powmod(b, n, mod) * powmod(a, i, mod) % mod * powmod(inv, n + i, mod) % mod * comb(n - 1 + i, i) % mod;
		ans += p * (n + i) % mod;
		ans %= mod;
	}
	
	ans = ans * 100 % mod * inv % mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3328
let ans, k, n = ref 0, ref 0, Scanf.scanf " %d" (+) 0
let ss, ls = Array.(make (n * (n - 1) / 2) 0, init n @@ fun _ -> Scanf.scanf " %d" (+) 0)
let g i k a = a.(i) > k
let f k a = let l, r = ref @@ -1, ref @@ Array.length a in while !r - !l > 1 do let m = !l + (!r - !l) / 2 in if g m k a then r := m else l := m done; !r
let _ = for i = 0 to n - 1 do for j = i + 1 to n - 1 do ss.(!k) <- ls.(i) + ls.(j); incr k done done;
  Array.(sort (-) ss; sort (fun x y -> y - x) ls; iteri (fun i l -> ans := !ans + max 0 ((n - i - 1) * (n - i - 2) / 2 - f l ss)) ls); Printf.printf "%d\n" !ans

Measured memory_bytes: 20476
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	string str;
	cin >> str;
	
	int s=0,t=0;
	int ans = 0;
	
	REP(i,str.size())
	{
		if(str[i] == 'S')
		{
			s++;
		}
		else
		{
			if(s > 0)
			{
				s--;
				ans++;
			}
		}
		
	}
	
	cout << str.size() - 2*ans << endl;
	
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//(a+b-1)/b

signed main(){
	string s,t; cin>>s>>t;
  int n=s.size(),m=t.size();
  vvl dp(n+10,vl(m+10));
  rep(i,0,n){
  	rep(j,0,m){
      if(s[i]==t[j])chmax(dp[i+1][j+1],dp[i][j]+1);
      chmax(dp[i+1][j+1],dp[i+1][j]);
      chmax(dp[i+1][j+1],dp[i][j+1]);
    }
  }
  string ans="";
  ll i=n,j=m;
  while(i>0 && j>0){
  	if(dp[i-1][j]==dp[i][j])--i;
    else if(dp[i][j-1]==dp[i][j])--j;
    else{
    	ans=s[i-1]+ans;
    	--i,--j;  
    }
  }
  cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 74536
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

const int maxn = 510;

bool flag;
int n,m,x,y;
int a[maxn][maxn];

int main()
{
	scanf("%d%d%d%d",&n,&m,&x,&y);
	if(n%x==0&&m%y==0) { puts("No"); return 0; }
	if(n%x==0) flag=true,swap(n,m),swap(x,y);
	
	int k1=1000000,k2=-1000000*(x-1)-1;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
			a[i][j]=i%x==0?k2:k1;
	}
	puts("Yes");
	if(flag)
	{
		for(int j=1;j<=m;j++) 
		{
			for(int i=1;i<=n;i++) printf("%d ",a[i][j]);
			puts("");
		}
	}
	else
	{
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=m;j++) printf("%d ",a[i][j]);
			puts("");
		}
	}
	
	return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())

const int MAX_N = 100010;
int par[MAX_N];  //親
int _rank[MAX_N]; //木の深さ

// n要素で初期化
void init(int n){
	REP(i, n){
		par[i] = i;
		_rank[i] = 0;
	}
}
//木の根を求める
int find(int x){
	if(par[x] == x) return x;
	else return par[x] = find(par[x]);
}
//xとyの属する集合を結合
void unite(int x, int y){
	x = find(x);
	y = find(y);
	if(x == y) return;
	if(_rank[x] < _rank[y]) par[x] = y;
	else{
		par[y] = x;
		if(_rank[x] == _rank[y]) _rank[x]++;
	}
}
//xとyが同じ集合に属するか
bool same(int x, int y){
	return find(x) == find(y);
}


int n, m;
int p[100010];
int pos[100010];


void input() {
	cin >> n >> m;
	REP(i, n) {
		cin >> p[i];
		p[i]--;
		pos[p[i]] = i;
	}
}

void solve() {
	init(n);
	REP(i, m) {
		int a, b;
		cin >> a >> b;
		unite(a-1, b-1);
	}
	int res = 0;
	REP(i, n) {
		if (same(i, pos[i])) res++;
	}
	cout << res << endl;
}

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


Measured memory_bytes: 1792
N = int(input())
S = list(input())
K = int(input())

x = S[K-1]
s = [i for i, t in enumerate(S) if t == x]

for i in range(N):
	if i not in s:
		S[i] = '*'
	else:
		pass

A = "".join(S)
print(A)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		double r=sc.nextDouble();
		double a,b;
		a=r*r*(Math.PI);
		b=(2*r)*(Math.PI);
		System.out.print(String.format("%2.6f",a));
		System.out.print(" ");
		System.out.println(String.format("%2.6f",b));
	}
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
const ll MOD = 1e9+7;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"[";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"]";return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&p)
{o<<"{"<<p.first<<", "<<p.second<<"}";return o;}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj)
{o<<"{";for(auto itr=obj.begin();itr!=obj.end();++itr)o<<(itr!=obj.begin()?", ":"")<<*itr;o<<"}";return o;}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  ll ans = 0;
  cin >> n;
  vector<int> a(n),b(n);
  priority_queue<P> que;

  for(int i=0; i<n; i++) cin >> a[i];
  for(int i=0; i<n; i++) {
    cin >> b[i];
    if(a[i] != b[i]) que.push(P(b[i],i));
  }

  while(!que.empty()){
    int v,m,l,r,s,k;
    tie(v,m) = que.top();
    que.pop();
    l = m == 0 ? n-1 : m-1;
    r = m == n-1 ? 0 : m+1;
    s = b[l]+b[r];
    k = a[m] >= s ? (b[m]-a[m])/s : b[m]/s;

    if(b[m] == a[m]) continue;
    if(b[m] <= s) continue;
    
    b[m] -= k*s;
    if(b[m] != a[m] && a[m] < s) que.push(P(b[m],m));
    ans += k;
  }

  for(int i=0; i<n; i++){
    if(a[i] != b[i]){
      cout << -1 << endl;
      return 0;
    }
  }

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


Measured memory_bytes: 3956
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int a, b, c, k;
	cin >> a >> b >> c >> k;
	if (k <= a) cout << k << '\n';
	else if (k <= a + b) cout << a << '\n';
	else cout << a - (k - a - b) << '\n';
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
typedef long long LL;
const int N = 200003;
int n, tmp;
LL ans;
char s[N];
int main(){
	scanf("%s", s + 1);
	n = strlen(s + 1);
	for(Rint i = 1;i <= n;i ++){
		if(s[i] == 'A') ++ tmp;
		else if(s[i] == 'B' && s[i + 1] == 'C'){
			ans += tmp;
			++ i;
		} else tmp = 0;
	}
	printf("%lld", ans);
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;
using ll=long long;
using P=pair<int,int>;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define el '\n'
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
#define INF 1e9
#define DEBUG(x) cout<<"debug: "<<x<<endl
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}

string s;
int main(){
    cin >> s;
    int ls = s.length();
    if(s[ls-1]== 's') s += 'e';
    s += 's';
    cout << s << el;
    return 0;
}


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

double ave_temp, temp_ave_temp_diff, temp, temp_diff;
int X, N, A, T;
int ans_0index;

constexpr double ave_temp_const = 0.006;

inline double calc_ave_temp(double x)
{
    return T - ave_temp_const * x;
}

inline double abs(double x)
{
    return x > 0 ? x : x * -1;
}

inline double calc_ave_temp_diff(double x)
{
    return min(abs(A - calc_ave_temp(x)), abs(calc_ave_temp(x) - A));
}

int main(int argc, char const *argv[])
{
    cin >> N;
    cin >> T >> A;

    cin >> X;
    temp_diff = calc_ave_temp_diff(X);
    ans_0index = 0;
    temp_ave_temp_diff = temp_diff;

    for (int i = 1; i < N; ++i)
    {
        cin >> X;

        temp_diff = calc_ave_temp_diff(X);

        if (temp_ave_temp_diff > temp_diff)
        {
            ans_0index = i;
            temp_ave_temp_diff = temp_diff;
        }
    }

    cout << ans_0index + 1 << endl;
}


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

vector<string> expr;

int formula(int &p,int dep){
    if(p>=expr.size()) return -1;
    if(expr[p].size()-1<dep){
        return -1;
    }
    if(isdigit(expr[p][dep])){
        int res=expr[p][dep]-'0';
        p++;
        return res;
    }
    char op=expr[p][dep];
    p++;
    int res=(op=='+' ? 0 : 1);
    while(p<expr.size()){
        int rhs=formula(p,dep+1);
        if(rhs==-1) break;
        if(op=='+') res+=rhs;
        else res*=rhs;
    }
    return res;
}

int main(){
    int n;
    while(cin>>n,n){
        expr.clear();
        expr.resize(n);
        for(int i=0;i<n;i++) cin>>expr[i];
        int p=0;
        int res=formula(p,0);
        cout<<res<<endl;
    }
    return 0;

}

Measured memory_bytes: 3192
#include <stdio.h>

int main()
{
  int i,a[100],ans = 0;

  for(i = 0;i < 5;i++){
    scanf("%d",&a[i]);
  }

  for(i = 0;i < 5;i++){
    if(a[i] < 40){
      a[i] = 40;
    }
    ans += a[i];
  }

  printf("%d\n",ans/5);

  return 0;
}

Measured memory_bytes: 1752
a = int(input())
b = list(input())
d = list(b[0])
if a < len(b):
    for c in range(a-1):
        d.append(b[c+1])
    d.append("...")
    d = "".join(d)
    print(d)
else:
    b = "".join(b)
    print(b)

Measured memory_bytes: 9188
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n = int(input())
b = [int(i) for i in readline().split()]+[1000000000]

a = [0]*(n+1)

a[0] = b[0]
for i in range(1,n):
    a[i] = min(b[i-1],b[i])

#print(a)
print(sum(a))



Measured memory_bytes: 3060
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
int main(){
  long long int ans=0,n,a[200010],i,sum[200010],sum1[200010];
  scanf("%lld\n",&n);
  for(i=0;i<=200000;i++){
    sum[i]=0;
  }
  for(i=0;i<n;i++){
    scanf("%lld\n",&a[i]);
    sum[a[i]]++;
  }
  for(i=0;i<=200000;i++){
    sum1[i]=sum[i];
    sum[i]=sum[i]*(sum[i]-1)/2;
    ans+=sum[i];
  }
  for(i=0;i<n;i++){
    printf("%lld\n",ans-sum1[a[i]]+1);
  }
  return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
int main(){
int counter=0;
string a;
cin>>a;
for(int i=0;i<3;i++){
if(a.at(i)=='a'){
counter++;
break;}}
for(int i=0;i<3;i++){
if(a.at(i)=='b'){
counter++;
break;}}
for(int i=0;i<3;i++){
if(a.at(i)=='c'){
counter++;
break;}}
if(counter==3)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;

int main(){

  int n;
  cin >> n;
  vector<string> s;

  string t;
  for (int i = 0; i < n; i++){
    cin >> t;
    s.push_back(t);
  }

  string pr;
  string no;
  pr = s[0];
  for (int i = 1; i < n; i++){
    no = s[i];
    //cout << pr << endl;
    //cout << no << endl;
    //cout << pr[pr.size() - 1] << endl;
    if (pr[pr.size() - 1] != no[0]){
      cout << "No" << endl;
      return 0;
    }
    pr = no;
  }

  sort(s.begin(), s.end());
  s.erase(unique(s.begin(), s.end()), s.end());

  if (n != s.size()){
    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
import collections
n = int(input())
Lista = [str(input()) for i in range(n)]
m = int(input())
Listb = [str(input()) for j in range(m)]
lst = []
for k in range(m):
  if Listb[k] in Lista:
    Lista.remove(Listb[k])
if len(Lista) > 0:
  lst = collections.Counter(Lista)
  print(lst.most_common()[0][1])
elif len(Lista) == 0:
  print(0)

Measured memory_bytes: 3316
def main():
    n = int(input())
    primes = get_primes(55555)
    out = []
    num = 0
    for prime in primes:
        if prime%5 == 1:
           out.append(prime)
           num += 1
        if n == num:
            print(*out)
            return

def get_primes(x):
    if x < 2: return []
    if x == 2: return [2]
    limit = x**0.5 + 1
    nums = list(range(3, x+1, 2))
    dividers = [2]
    divider = 3
    while limit > divider:
        dividers.append(divider)
        nums = [num for num in nums if num%divider]
        divider = nums[0]
    return dividers+nums
        
if __name__ == "__main__":
    main()

Measured memory_bytes: 4212
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] x=new int[n];
		for(int i=0;i<n;i++){
			x[i]=sc.nextInt();
		}
		int sum=0;
		for(int i=0;i<n-1;i++){
			if(i+1==x[i]){
				int tmp;
				tmp=x[i];
				x[i]=x[i+1];
				x[i+1]=tmp;
				sum++;
			}
		}
		if(x[n-1]==n){
			sum++;
		}
		System.out.print(sum);
		
	}
}


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

int main() {
  int n,m,i;
  string s,t;
  m = 0;
  cin >> s >> t;
  n = s.size();
  for(i=0;i<n;i++) {
    if(s[i] == t[i]) {
      m += 1;
    }else {
      m += 0;
    }
  }
  if(m == n) {
     cout << "Yes" << endl;
  } else {
  cout << "No" << endl;
  }
}

Measured memory_bytes: 3536
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8').trim()

const [x, a] = stdin
  .split('\n')[0]
  .split(' ')
  .map(Number)

const ans = () => {
  if (x < a) {
    return 0
  } else {
    return 10
  }
}

console.log(ans())


Measured memory_bytes: 11468
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int main()
{
    ll n, d;
    cin >> n >> d;
    int ans = 0;
    rep(i, n)
    {
        ll x, y;
        cin >> x >> y;
        if (d * d >= x * x + y * y)
        {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, z, n) for(int64_t i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
#define PI 3.14159265358979
//const int64_t INF = 1LL << 60;
const int INF = 1 << 29;
const int64_t MOD = 1000000007;
//const int64_t INF = 998244353;
using namespace std;
typedef pair<int64_t, int64_t> P;

int64_t powmod(int64_t x, int64_t n){
    //pow(x, n) % MOD
    int64_t ret = 1;
    while(n > 0){
        if(n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return ret;
}

int64_t nikou(int64_t A, int64_t B){
    int64_t x = 1, y = 1;
    rep(i, 0, A){
        x *= (B - i);
        y *= (i + 1);
        x %= MOD;
        y %= MOD;
    }
    y = powmod(y, MOD - 2);
    return x * y % MOD;
}

int main(){
    int64_t n, a, b;
    cin >> n >> a >> b;
    int64_t x = powmod(2, n) - 1;
    int64_t y = nikou(a, n);
    int64_t z = nikou(b, n);
    int64_t ans = x - y - z;
    cout << (ans % MOD + MOD) % MOD << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
// AtCoder DP Contest C. Vacation.

void solve()
{
	int n;
	cin >> n;
	vector<int> dp(3, 0);
	for(int day = 1; day <= n; day++) {
		vector<int> c(3), new_dp(3);
		for(int i = 0; i < 3; i++) cin >> c[i];
		
		for(int i = 0; i < 3; i++) {//previous day
			for(int j = 0; j < 3; j++) {//current day
				if(i != j) {
					new_dp[j] = max(new_dp[j], dp[i] + c[j]);
				}
			}
		}
		dp = new_dp;
	}
	cout << max({dp[0], dp[1], dp[2]});
}

int main()
{
	int t = 1;
	//cin >> t;
	while(t--) {
		solve();
		cout << '\n';
	}
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(ll i=0;i<n;i++)
const ll INF=1e15;
const ll MOD=1000000007;

int main(){
    ll N,M;cin>>N>>M;
    vector<pair<ll,ll>> info[N];
    rep(i,M){
        ll L,R,C;cin>>L>>R>>C;
        L--;R--;
        info[L].push_back(make_pair(R,C));
    }
    rep(i,N-1)info[i+1].push_back(make_pair(i,0));
    ll sum[N];
    rep(i,N){
        if(!i)sum[i]=0;
        else sum[i]=INF;
    }
    priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> que;
    que.push(make_pair(0,0));
    while(que.size()){
        ll d=que.top().first,v=que.top().second;
        que.pop();
        for(auto i:info[v]){
            ll nv=i.first;
            ll nc=i.second;
            if(d+nc<sum[nv]){
                sum[nv]=d+nc;
                que.push(make_pair(sum[nv],nv));
            }
        }
    }
    if(sum[N-1]==INF)cout<<-1<<endl;
    else cout<<sum[N-1]<<endl;
    return 0;
}

Measured memory_bytes: 9340
#include <stdio.h>

long long int gcd (long long int ,long long int );

int main(){
  long long int A,B,C,D;
  long long int lcmCD;
  
  scanf("%lld %lld %lld %lld",&A,&B,&C,&D);

  if( C > D )
    lcmCD = C/gcd(C,D)*D;
  else
    lcmCD = C/gcd(D,C)*D;  

  printf("%lld\n", (B-(A-1)) - (B/C-(A-1)/C) - (B/D-(A-1)/D) + (B/lcmCD-(A-1)/lcmCD) );
  
  return 0;
}

long long int gcd(long long int x,long long int y){
  if(y==0)
    return x;
  else 
    return gcd(y,x%y);
}


Measured memory_bytes: 128
//Radhe Radhe
#include<bits/stdc++.h>
#define godspeed  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define limit 1000000000000000000 //1e18
#define mod 1000000007 //1e9+7
#define llu long long unsigned
#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i,n)    for(ll i=0; i<n; i++)
#define rep1(i,a,b)    for(ll i=a; i<b; i++)
#define repV(i,n)    for(ll i=0; i<v.size(); i++)
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(7);
#define yes cout<<"Yes"<<'\n';
#define no cout<<"No"<<'\n';
using namespace std;

int main()
{
    godspeed
    ll  i,j,n,k,opt=0;
    string s,t;
    cin >>n>>s;
    ll lft=0,ryt=n-1;
    while(lft<ryt)
    {
        if(s[lft]=='W'&&s[ryt]=='R')
        {
            swap(s[lft],s[ryt]);opt++;
        }
        else if(s[lft]=='W'&&s[ryt]=='W')
        {
            ryt--;
        }
        else if(s[lft]=='R'&&s[ryt]=='R')
        {
            lft++;
        }
        else{
            lft++;ryt--;//R-W
        }
    }
    cout <<opt<< endl;
    return 0;
}


Measured memory_bytes: 3704
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

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

        int N = sc.nextInt();
        int W = sc.nextInt();
        int[] w = new int[N];
        int[] v = new int[N];
        for (int i = 0; i < N; ++i) {
            w[i] = sc.nextInt();
            v[i] = sc.nextInt();
        }

        System.out.println(solve(w, v, W));

        sc.close();
    }

    static int solve(int[] w, int[] v, int W) {
        int base = w[0];

        @SuppressWarnings("unchecked")
        List<Integer>[] values = new List[4];
        for (int i = 0; i < values.length; ++i) {
            values[i] = new ArrayList<>();
        }

        for (int i = 0; i < w.length; ++i) {
            values[w[i] - base].add(v[i]);
        }

        for (int i = 0; i < values.length; ++i) {
            Collections.sort(values[i], Collections.reverseOrder());
        }

        return search(values, W, base, 0, 0, 0);
    }

    static int search(List<Integer>[] values, int restWeight, int base, int rowIndex, int colIndex, int totalValue) {
        if (rowIndex == values.length) {
            return totalValue;
        }

        int result = 0;
        if (colIndex != values[rowIndex].size() && restWeight >= base + rowIndex) {
            result = Math.max(result, search(values, restWeight - (base + rowIndex), base, rowIndex, colIndex + 1,
                    totalValue + values[rowIndex].get(colIndex)));
        }

        result = Math.max(result, search(values, restWeight, base, rowIndex + 1, 0, totalValue));

        return result;
    }
}

Measured memory_bytes: 23892
#include<iostream>
#define F 7500000
using namespace std;int n,m,i;int main(){while(cin>>m>>n&&m){bool t[F]={};while(1){if(!t[m]){if(!n)break;for(i=m*2;i<F;i+=m)t[i]=1;n--;}m++;}cout<<m<<endl;}return 0;}

Measured memory_bytes: 10352
#include<bits/stdc++.h>
using namespace std;
int N,K;
main(){
  cin>>N>>K;
  vector<int>xs(K);
  while(N){
    for(int i=0;i<K;++i){
      ++xs[i];
      --N;
      if(N==0)break;
    }
  }
  sort(xs.begin(),xs.end());
  cout<<(xs.back()-xs.front())<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <functional>
#include <cmath>
#include <map>
using namespace std;

long long n, a[100009], L = 2, R = 2;

int main() {
	cin >> n; for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = n; i >= 1; i--) {
		long long P1 = (L + a[i] - 1) / a[i], P2 = R / a[i]; P1 *= a[i]; P2 *= a[i];
		if (P1 > P2) { cout << "-1" << endl; return 0; }
		L = P1; R = P2 + a[i] - 1;
	}
	cout << L << " " << R << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
#define mod 1000000007
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define setA0(a) for(ull i =0;i<n;i++){a[i] = 0;}
#define aout(a) for(auto x : a){cout<<x<<' ';} // array output macro 
#define ain(a) for(ull i =0;i<n;i++){cin>>a[i];} //array input macro
#define NofSetBits(x) __builtin_popcount(x);
#define InpGrph(g,e) while(e--){ll x;ll y;cin>>x>>y ;g[x].pub(y);g[y].pub(x);}
#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);



int main(){
  FastIO;
  ll n;
  cin>>n;
  string s;
  cin>>s;
  if(n&1){
    cout<<"No";
  }else{
    bool y =1;
    ll x = n/2-1;
    for(ll i=0;i<=x;i++){
      if(s[i]!=s[i+x+1]){
        y=0;
        break;
      }
    }
    if(y){
      cout<<"Yes";
    }else{
      cout<<"No";
    }
  }
  return 0;
}


Measured memory_bytes: 3576
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 10007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //------------------------------
    string s;cin>>s;
    while(s!="-"){
        int m;cin>>m;
        while(m--){
            int h;cin>>h;
            string s1=s.substr(0,h);
            string s2=s.substr(h,s.length()-h);
            //cout<<s1<<" "<<s2<<Endl;
            s=s2+s1;
        }
        cout<<s<<endl;
        cin>>s;
    }
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------


































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

int num[300000];

int main(void) {
    for (int i = 0; i < 300000; i++) {
        num[i] = 1;
    }
    num[0] = 0;
    num[1] = 0;

    for (int i = 2; i < 300000; i++) {
        for (int j = 2; i*j < 300000; j++) {
            num[i*j] = 0;
        }
    }

    int n;
    while (cin >> n, n) {
        int cnt = 0;
        for (int i = n+1; i <= 2*n; i++) {
            cnt += num[i];
        }

        cout << cnt << endl;
    }
    return 0;
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n;
  cin >> n;
  string s;
  cin >> s;
  if(n>=3200) cout << s << endl;
  else cout << "red" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cctype>
#include<cstring>
#include<cctype>
#include<cstdio>
#include<cstdlib>
#include<limits.h>

using namespace std;


int main()
{
  int low=1000000000;
  int high=0;
  int n,i,c;
  scanf("%d",&n);
  int p[n];
  for(i=0;i<n;i++)
  {
      scanf("%d",&p[i]);
      if(low>p[i])
        low=p[i];
      if(high<p[i])
        high=p[i];
  }
  c=high-low;
  printf("%d\n",c);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;
int a,b,c,d;
int keisan()
{
c=0;
d=0;
c=a*b;
d=(2*a)+(2*b);
return (0);
}
int main()
{
	cin>>a; 
	cin>>b;
	keisan();
	cout<<c<<" "<<d<<endl;
return (0);
	}

	



Measured memory_bytes: 3072
import scala.math.max

object Scanner {
  private val buf = new Array[Byte](1024); private var ptr = 0; private var len = 0
  @inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
  @inline private def hasNextByte(): Boolean =
    if (ptr >= len) { ptr = 0; len = System.in.read(buf); len > 0 } else { true }
  @inline private def hasNext(): Boolean = {
    while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
    hasNextByte()
  }
  @inline private def readByte(): Byte =
    if (hasNextByte()) { val res = buf(ptr); ptr += 1; res } else { -1 }
  def next(): String = {
    if(!hasNext()) ???
    val sb = new StringBuilder; var b = readByte()
    while (isPrintableChar(b)) { sb.append(b.toChar); b = readByte() }
    sb.toString
  }
  def nextInt(): Int = {
    val n = nextLong()
    if (n < Int.MinValue || Int.MaxValue < n) ???
    n.toInt
  }
  def nextLong(): Long = {
    if(!hasNext()) ???
    var minus = false; var b = readByte()
    if (b == '-') { minus = true; b = readByte() }
    def go (b: Byte, n: Long = 0): Long =
      if ('0' <= b && b <= '9') { go(readByte(), n * 10 + b - '0') }
      else if (minus) { -n } else { n }
    go(b)
  }
  def nextDouble(): Double = next.toDouble
}

object Main extends App{
  // val sc = Scanner
  val sc = new java.util.Scanner(System.in)
  val N, M, K = sc.nextInt
  val A = Array.fill(N)(sc.nextLong)
  val B = Array.fill(M)(sc.nextLong)
  var t: Long = A.sum
  var idx = N - 1
  var ans = 0
  var tmp = N
  for(i <- 0 to M){
    if(i != 0){
      t += B(i - 1)
      tmp += 1
    }
    while(t > K && idx >= 0){
      t -= A(idx)
      idx -= 1
      tmp -= 1
    }
    if(t <= K) ans = max(ans, tmp)
  }
  println(ans)
}

Measured memory_bytes: 62276
N = int(input())
for a in range(1,3501):
    for b in range(1,3501):
        m =  (4*a*b) - N*(a+b)
        if m> 0 and N*a*b % m == 0:
            c = (N*a*b)//m
            break
    else:
        continue
    break
print(a,b,c)


Measured memory_bytes: 2940
function Main(input) {
    var result;
    const N = parseInt(input[0])
    const K = parseInt(input[1])
    var S = input[2];    
    
    var c = S.charAt(K-1);
    switch(c) {
        case "A": c = "a"; break;
        case "B": c = "b"; break;
        case "C": c = "c"; break;

    }
    if(K < N) {
        console.log(S.substring(0, K-1) + c + S.substring(K));
    }else {
        console.log(S.substring(0, K-1) + c);
    }
}

// 1行入力の場合
// Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

// 改行で分割
// Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n/));

// 改行・空白で分割
Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));

Measured memory_bytes: 7372
package main
 
import (
	"fmt"
)

type count struct {
  AC int
  WA int
  TLE int
  RE int
}
 
func main() {
    var N int
    fmt.Scanf("%d", &N)
 
    answers := make([]string, N)
    cnt := count{AC: 0, WA:0, TLE:0, RE:0}
    for i := range answers{
      fmt.Scan(&answers[i])

      switch result := answers[i]; result {
        case "AC": 
          cnt.AC += 1
        case "WA":
          cnt.WA += 1
        case "TLE":
          cnt.TLE += 1
        case "RE":
          cnt.RE += 1
      }
    }

    fmt.Printf("AC x %d\n", cnt.AC)
    fmt.Printf("WA x %d\n", cnt.WA)
    fmt.Printf("TLE x %d\n", cnt.TLE)
    fmt.Printf("RE x %d\n", cnt.RE)
}

Measured memory_bytes: 6880