akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }

long long T1, T2, A1, A2, B1, B2;
void solve() {
    long long a = T1 * A1 + T2 * A2;
    long long b = T1 * B1 + T2 * B2;
    if (a == b) {
        cout << "infinity" << endl;
        return;
    }

    if (a < b) swap(A1, B1), swap(A2, B2), swap(a, b);
    long long ha = T1 * A1, hb = T1 * B1;
    if (ha > hb) {
        cout << 0 << endl;
        return;
    }

    long long q = (hb - ha + a-b-1) / (a - b);
    long long res = q * 2 - 1;
    if ((ha - hb) % (a - b) == 0) ++res;


    //COUT(a); COUT(b); COUT(ha); COUT(hb); COUT(q);
    
    cout << res << endl;
}

int main() {
    cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;
    solve();
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main{
	final static int MOD = 1000000007;
	final static int INF = 1000000000;

	public static void main(String[] args) throws IOException{
		NScanner sc = new NScanner(System.in);
		StringBuilder str = new StringBuilder(sc.next());
		int q = sc.nextInt();
		for(int i = 0; i < q; ++i){
			String com = sc.next();
			int a = sc.nextInt();
			int b = sc.nextInt();
			if(com.equals("replace")){
				String rst = sc.next();
				str = str.replace(a, b+1, rst);
			}else if(com.equals("print")){
				System.out.println(str.substring(a, b+1));
			}else{
				str = str.replace(a, b+1, new StringBuilder(str.substring(a, b+1)).reverse().toString());
			}
		}
	}

}

class NScanner{

	private BufferedReader br;
	private StringTokenizer tok;

	public NScanner(InputStream is) throws IOException{
		br = new BufferedReader(new InputStreamReader(is));
		getLine();
	}

	private void getLine() throws IOException{
		while(tok == null || !hasNext()){
			tok = new StringTokenizer(br.readLine());
		}
	}

	public boolean hasNext(){
		return tok.hasMoreTokens();
	}

	public String next() throws IOException{
		if(hasNext()){
			return tok.nextToken();
		}else{
			getLine();
			return tok.nextToken();
		}
	}

	public int nextInt() throws IOException{
		if(hasNext()){
			return Integer.parseInt(tok.nextToken());
		}else{
			getLine();
			return Integer.parseInt(tok.nextToken());
		}
	}

	public long nextLong() throws IOException{
		if(hasNext()){
			return Long.parseLong(tok.nextToken());
		}else{
			getLine();
			return Long.parseLong(tok.nextToken());
		}
	}

	public double nextDouble() throws IOException{
		if(hasNext()){
			return Double.parseDouble(tok.nextToken());
		}else{
			getLine();
			return Double.parseDouble(tok.nextToken());
		}
	}
}


Measured memory_bytes: 24776
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string a;
    cin>>a;
    if (a=="SUN"){
        cout<<"7"<<endl;
    }
    else if (a=="MON"){
        cout<<"6"<<endl;
    }
    else if (a=="TUE"){
        cout<<"5"<<endl;
    }
    else if (a=="WED"){
        cout<<"4"<<endl;
    }
    else if (a=="THU"){
        cout<<"3"<<endl;
    }
    else if (a=="FRI"){
        cout<<"2"<<endl;
    }
    else {
        cout<<"1"<<endl;
    }
}


Measured memory_bytes: 256
n = int(input())
s = input()
dp = [[0]*(n+1) for _ in range(n+1)]
res = 0
for i in range(n-1,-1,-1):
    for j in range(n-1,-1,-1):
        if s[i] == s[j]:
            dp[i][j] = dp[i+1][j+1] +1
        res = max(res,min(dp[i][j],j-i))
print(res)

        
            

Measured memory_bytes: 232200
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
int main(int argc, const char * argv[])
{
    int A;
    int B;
    
    cin >> A >> B;
    
    int count = 0;
    for(int i = A; i < B+1; i++)
    {
        int num1 = i/10000;
        int num2 = (i/1000)%10;
        
        int num4 = (i/10)%10;
        int num5 = i%10;
        if(num1 == num5 && num2 == num4)
        {
            count++;
        }
    }
    
    
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        int ans = Math.min(a+b, a+c);
        ans = Math.min(ans, b+c);
        System.out.println(ans);
        sc.close();
    }
}

Measured memory_bytes: 35608
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int inf=1e9;
const double PI=acos(-1);
const double eps=1e-6;
const int mod=1e9+7;
const int maxn=1e5+10;
int x,y,z,m;
ll a[1010],b[1010],c[1010];
bool cmp(ll a,ll b){
	return a>b;
}
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>x>>y>>z>>m;
	for(int i=1;i<=x;i++){
		cin>>a[i];
	}
	for(int j=1;j<=y;j++){
		cin>>b[j];
	}
	for(int i=1;i<=z;i++){
		cin>>c[i];
	}
	sort(a+1,a+x+1,cmp);
	sort(b+1,b+y+1,cmp);
	sort(c+1,c+z+1,cmp);
	vector<ll>q;
	for(int i=1;i<=x;i++){
		for(int j=1;j<=y;j++){
			for(int k=1;k<=z;k++){
				if(i*j*k<=m) q.push_back(a[i]+b[j]+c[k]);
				else break;
			}
		}
	}
	sort(q.begin(),q.end(),cmp);
	for(int i=0;i<m;i++){
		cout<<q[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1400
#include <iostream>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a+b>c+d)
	cout<<"Left";
	else if(a+b==c+d)
	cout<<"Balanced";
	else
	cout<<"Right";
	return 0;
}

Measured memory_bytes: 256
import Control.Monad
import Data.Bool

solve a b = tail . map thd . scanl f (0, 0, True) where
  f (n,m,_) c
    | c == 'a' && n < a+b = (n+1, m, True)
    | c == 'b' && n < a+b && m < b = (n+1, m+1, True)
    | otherwise = (n, m, False)

main = do
  [_,a,b] <- map read.words <$> getLine
  s <- getLine
  mapM_ (putStrLn.bool "No" "Yes") $ solve a b s

thd (_,_,a) = a

Measured memory_bytes: 5372
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n,T=map(int,input().split())
    AB=[tuple(map(int,input().split())) for _ in range(n)]
    AB.sort()

    dp=[0]*T
    ans=0
    for a,b in AB:
        ndp=dp[:]
        for t in range(T):
            if(t+a<T):
                ndp[t+a]=max(ndp[t+a],dp[t]+b)
            else:
                ans=max(ans,dp[t]+b)
        dp=ndp
    print(ans)
resolve()

Measured memory_bytes: 43228
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end
n = gets_i

l0 = 2
l1 = 1
l2 = l0 + l1

if n == 1
  puts l1
  return
end

2.upto(n) do
  l2 = l1 + l0
  l0 = l1
  l1 = l2
end

puts l2


Measured memory_bytes: 14504
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
const int Max = 1e9 + 7;

int main()
{
	int n;
	cin >> n;
	ll res = 1;
	for (int i = 1; i <= n; i++)
	{
		res *= i;
		res %= Max;
	}
	cout << res;
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
#define FOR(i,s,e) for(int i=(s);i<(e);i++)
#define REP(i,n) FOR(i,0,n)
#define all(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long LL;
typedef pair<int, int> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<LL> A(n);
    REP(i, n) cin >> A[i];

     sort(all(A));
    vector<LL> s(n), l(n);
    REP(i, n/2){
        s[i] = A[i];
        l[i] = A[n-1-i];
    }
    LL ss = l[0]-s[0], sl = l[0]-s[0];
    REP(i, (n+1)/2-2){
        ss += l[i+1]+l[i]-2*s[i+1];
        sl += 2*l[i+1]-s[i]-s[i+1];
    }
    if(n%2){
        LL ct = A[n/2];
        ss += max(l[n/2-1]-ct, ct-s[0]);
        sl += max(l[0]-ct, ct-s[n/2-1]);
	}else{
        ss += l[n/2-2]-s[n/2-1];
        ss += l[n/2-1]-s[0];
        sl += l[n/2-1]-s[n/2-2];
        sl += l[0]-s[n/2-1];
    }
    if(n==2){
        cout << A[1]-A[0] << endl;
        return 0;
    }
    cout << max(sl, ss) << endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <set>

using namespace std;

int main()
{
	string s;
	int k;

	cin >> s;
	cin >> k;

	set<string> substrs;
	int size = (int)s.size();

	for (int i = 0; i < size; ++i)
	{
		for (int j = 1; j <= k; ++j)
		{
			if (i + j <= size)substrs.insert(s.substr(i, j));
		}
	}

	auto itr = substrs.begin();

	for (int l = 0; l < k - 1; ++l)
	{
		++itr;
	}

	cout << *itr;

	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  ll n, k; cin >> n >> k;
  ll x = 0;
  for(int i=0;i<n-1;++i) {
    x = k * (x/(k-1)) + x % (k-1) + 1;
  }
  cout << x << endl;
}



Measured memory_bytes: 3088
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N, K;
    cin >> N >> K;
    int Nplus = 1;
    int IT;
    for (int i = 0; i < N; i++){
        if (Nplus * 2 <= Nplus + K){
            Nplus = Nplus * 2;
        }else {
            Nplus = Nplus + K;
        }
    }
    cout << Nplus << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <deque>
#include <algorithm>

typedef long long ll;
typedef unsigned long long ull;
#define mod 1000000007
#define rep(i, n) for(int i = 0; i < n; ++i)

using namespace std;

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

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

	vector<int> t;
	t.push_back(a[n - 1]);
	for (int i = n - 2; i >= 0; i--) {
		if (a[i] >= t[t.size() - 1]) {
			t.push_back(a[i]);
			continue;
		}
		
		int left = 0;
		int right = t.size();
		int mid;
		while (left < right) {
			mid = (left + right) / 2;

			if (a[i] < t[mid]) {
				right = mid;
				if (mid == 0) {
					t[mid] = a[i];
					break;
				}
			}
			else {
				left = mid;
				if (mid == right - 1) {
					t[right] = a[i];
					break;
				}
			}
		}
	}

	cout << t.size() << "\n";
 }


Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
std::vector<ll> v1;
std::vector<ll> v2;
ll n, k;
int main () {
	ios::sync_with_stdio(false);
	cin >> n >> k;
	ll sum = 0;
	ll maxx = -1;
	for(ll i = 0; i < n; ++i) {
		ll temp;
		cin >> temp;
		v1.push_back(temp);
		sum+=v1[i];
	}
	for(ll i = 0; i < n; ++i) {
		ll temp;
		cin >> temp;
		v2.push_back(temp);
		maxx = max(maxx, v1[i] * v2[i]);
	}
	sort(v1.begin(), v1.end());
	sort(v2.begin(), v2.end(), greater<ll>());
	ll s = 0, e = maxx;
	if(sum <= k) {
		cout << 0 << endl;
		return 0;
	}
	ll t;
	ll ans;
	while(s <= e) {
		ll mid = (e + s) / 2; 
		t = 0;
		for(ll i = 0; i < n; ++i) {
			if(v1[i] * v2[i] <= mid)
				continue;
			else 
				t += v1[i] - mid / v2[i];
		}
		if(t <= k) {
			e = mid - 1;
			ans = mid;
		}
		else {
			s = mid + 1;
		}
	}
	cout << ans << endl;
}





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

using namespace std;

typedef unsigned int uint;

int main (void){
  uint n, m;
  cin >> n >> m;
  cin.ignore();
  uint a[m], b[m];
  uint i;
  for(i=0;i<m;i++){
    cin >> a[i] >> b[i];
    cin.ignore();
  }

  // 全数カウント
  uint cnt[n] = {0};
  for (i=0;i<m;i++){
    cnt[a[i]-1]++;
    cnt[b[i]-1]++;
  }

  for(i=0;i<n;i++){
    cout << cnt[i] << endl;
  }
  return 0;
}
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

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

    if (500*K >= X){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3632
ans = list()
while 1 :
	n = int(input())
	if n == 0: break
	s = list(map(int, input().split()))
	avg = sum(s)/n
	tmp = 0
	for i in s: tmp += (i-avg)**2
	ans += [(tmp/n)**(1/2)]

for i in ans: print(i)



Measured memory_bytes: 5660
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>

#if __cplusplus >= 201103 //C++11~
#include <tuple>

#endif

using namespace std;

typedef pair<int,int> Paint;

bool Pairsecond(const Paint& pf,Paint&ps){//sortCompare
  return pf.second < ps.second;
}

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)
#define pb push_back
#define MAX 1000000000
#define MOD 1000000007

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")

int main(){
  int n;cin>>n;
  vector<Paint> a;
  for(int i = 0; n > i; i++){
    int tmp;cin>>tmp;
    a.push_back(make_pair(tmp,i+1));
  }
  sort(a.begin(),a.end());
  for(int i = 0; n > i; i++){
    cout << a[i].second;
    if(i+1!=n)cout << " ";
  }
  cout << endl;
}

Measured memory_bytes: 1780
#import sys
#input = sys.stdin.readline
from itertools import accumulate, product
def main():
    H, W, K = map( int, input().split())
    S = [ list( map( int, list( input()))) for _ in range(H)]
    ans = 10**5
    cnt = 0
    AS = [ [0] + list( accumulate(S[i])) for i in range(H)]
    #print(AS)
    #TAS = list( zip(*AS))
    SAS = []
    for a in AS:
        SAS.extend(a)
    for P in product( range(2), repeat=H-1):
    # for i in range(2**(H-1)):
    #     P =[]
    #     for _ in range(H-1):
    #         P.append(i%2)
    #         i //= 2
        now = sum(P)
        if ans < now:
            continue
        start = 0
        goal = 0
        #print(P, now)
        while start < W:
            for i in range(start, W):
                cnt = 0
                check =True
                for j in range(H):
                    #cnt += AS[j][i+1] - AS[j][start]
                    #cnt += TAS[i+1][j] - TAS[start][j]
                    #                    print(P, start, i, j,cnt)
                    cnt += SAS[j*(W+1)+i+1] - SAS[j*(W+1)+start]
                    if j == H-1:
                        if cnt > K:
                            check = False
                            break
                    else:
                        if P[j] == 1:
                            if cnt > K:
                                check = False
                                
                                break
                            cnt = 0
                if check:
                    goal += 1
            if start == goal:
                start = W+1
                now = 10**5
                break
            #print("sg",P,start, goal, W)
            start = goal
            if goal < W:
                #print("now")
                now += 1
            #print(now)
        
        if now < ans:
            ans = now
    print(ans)
                
if __name__ == '__main__':
    main()


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)

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

typedef long long ll;

const string YES = "Yes";
const string NO = "No";

void solve(long long A, long long B, long long C, long long D){
    int cnt = 0;
    while(A > 0 && C > 0){
        if(cnt %2 == 0){
            C -= B;
        }
        else{
            A-= D;
        }
        cnt++;
    }
    if(A <= 0){
        cout<<NO<<endl;
    }
    else{
        cout<<YES<<endl;
    }
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long D;
    scanf("%lld",&D);
    solve(A, B, C, D);
    return 0;
}


Measured memory_bytes: 3764
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<cmath>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

double const toRad = std::acos(-1)/1.8e2;
double a, b, S;

bool isOK(double deg) {
  double rad = deg*toRad;
  double s = std::sin(rad);
  if(s <= 1e-12) return true; // should be full
  double c = std::cos(rad);
  if(c <= 1e-12) return false; // should be zero
  double h = b*c/s;
  double cS;
  if(h <= a) cS = b*h*0.5;
  else {
    h = a*s/c;
    cS = a*(b - h*0.5);
  }
  return S < cS*(1.0+0.8e-10);
}

int main() {
  std::cout << std::setprecision(10) << std::fixed;
  double x; std::cin >> a >> b >> x;
  S = x/a;
  double ok = 0.0, ng = 90.0;
  while(ng-ok > 1e-6) {
    double mid = (ok+ng)*0.5;
    if(isOK(mid)) ok = mid; else ng = mid;
  }
  fin((ok+ng)*0.5);
  return 0;
}


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

int main() {
    long int a,k;
    cin>>a;
    k=a;
    int t=0;
    while(k)
    {
        k=k/10;
        t++;
    }
    
    if(t==6)
    cout<<90909;
    if(t==5)
    cout<<a-9090;
    if(t==4)
    cout<<909;
    if(t==3)
    cout<<a-90;
    if(t==2)
    cout<<9;
    if(t==1)
    cout<<a;
    
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
int main(){
    int a,b;
    cin >> a >> b;
    if(b>a){
        swap(a,b);
    }

    if(a>b){
        cout << 2*a-1 << endl;
    }else{
        cout << a+b << endl;
    }
}


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

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

    queue<int> white;
    stack<int> red;
    for(int i = 0;i < N;i++){
        char tmp;
        cin >> tmp;
        if(tmp == 'R'){
            red.push(i);
        }else{
            white.push(i);
        }
    }

    int swaps=0;
    while(true){
        if(white.empty() || red.empty()){
            break;
        }
        if(white.front() < red.top()){
            swaps++;
            white.pop();
            red.pop();
        }else{
            break;
        }
    }
    cout << swaps << endl;
    return 0;
}

Measured memory_bytes: 4464
#include<bits/stdc++.h>
using namespace std;
#define    For(i,n) for(int i=0;i<n;i++)
#define    fors(i,s) for(int i=0;i<s.size();i++)
#define    forn(i,n) for(int i=1;i<=n;i++)
#define    nl     "\n"
#define    test   int t;cin>>t;for(int l=0;l<t;l++)
#define    End    return 0
#define    gt     greater<int>()
#define    ll     long long int

int main()
{
    //test
    {
        int n;
        cin>>n;
        if(n>=30)cout<<"Yes";
        else cout<<"No";
    }
}


Measured memory_bytes: 3588
mod=10**9+7
n=int(input())
a=list(map(int,input().split()))
def gcd(a,b):
  while b:a,b=b,a%b
  return a
def lcm(a,b):return a*b//gcd(a,b)
l=a[0]
for i in range(1,n):
  l=lcm(l,a[i])
ans=0
l%=mod
for i in range(n):
  ans+=l*pow(a[i],mod-2,mod)
  ans%=mod
print(ans)

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

int main(){
  int a,b ;
  cin >> a >> b;
  if (a==b) cout << "Yes" << endl;
  else cout << "No" << endl;
}
  


Measured memory_bytes: 256
from scipy.sparse.csgraph import dijkstra as di
from itertools import permutations
N,M,R = map(int, input().split())
r = list(map(int, input().split()))

route = [[0 for i in range(N)] for j in range(N)]
for i in range(M):
    a,b,c = map(int, input().split())
    route[a-1][b-1] = route[b-1][a-1] = c
# for i in range(N):
#     print(route[i])


p_route = di(route)
# print(p_route)

mn = float('INF')
for tmp in permutations(r):
    t_sum = 0
    for i in range(len(tmp)-1):
        t_sum += p_route[tmp[i]-1][tmp[i+1]-1]
    if t_sum < mn:
        mn = t_sum

print(int(mn))

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

int main() {

    int n;
    cin >> n;
    vector<int> p(n);
    rep(i, n){
        cin >> p[i];
    }

    bool one = false;
    int tmp = 0;
    int idx = 0;
    REP(i, 1, n){
        if(p[i-1] > p[i] && !one){
            one = true;
            tmp = p[i-1];
            idx = i-1;
        }
        else if(p[i-1] > p[i] && one){
            p[idx] = p[i];
            p[i] = tmp;
            break;
        }
    }

    bool ok = true;    
    REP(i, 1, n){
        if(p[i-1] > p[i]){
            ok = false;
            break;
        }
    }
    if(ok){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }

    return 0;
}

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

namespace BeginnerContest053
{
    class Program
    {
        static void Main(string[] args)
        {
            // var input = Console.ReadLine();                                                   

            //Console.WriteLine(int.Parse(input) < 1200 ? "ABC" : "ARC");
                                                               

            //var first  = input.IndexOf("A");
            //var last = input.LastIndexOf("Z");
            //Console.WriteLine(last - first +1);


            //var max = long.Parse(input);

            //if (max <= 6)
            //{
            //    Console.WriteLine(1);
            //}
            //else if (max < 11)
            //{
            //    Console.WriteLine(2);
            //}
            //else
            //{            
            //    var result = max / 11;
            //    result *= 2;
            //    if (max%11 != 0)
            //    {
            //        result += 1;
            //        var mod =  max % 11 ;
            //        if (mod > 6)
            //            result += 1;
            //    }
                    

            //    Console.WriteLine(result);
            //}                            


            var length = int.Parse(Console.ReadLine());

            var data = new List<string>(Console.ReadLine().Split(' '));

            var dict = new Dictionary<int,int>();
            foreach (var value in data)
            {
                if (!dict.ContainsKey(int.Parse(value)))
                {
                    dict.Add(int.Parse(value),0);
                }
                dict[int.Parse(value)] += 1;
            }
            var count = 0;

            foreach (var i in dict)
            {
                count += 1;
            }

            if (count%2 == 0)
                count -= 1;

            Console.WriteLine(count);







        }
    }
}


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

using namespace std;

int a[100005];

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

    int mx = 0;
    int mn = 1<<30;
    bool ok = 1;
    for(int i=0;i<n;i++){
        scanf("%d", &a[i]);
        mx = max(mx, a[i]);
        mn = min(mn, a[i]);
    }

    if(mx == mn){
        if(mx == n-1 || 2*mx <= n) ok = 1;
        else ok = 0;
    }
    else if(mx == mn+1){
        int cnt1 = 0, cnt2 = 0;
        for(int i=0;i<n;i++){
            if(a[i] == mx) cnt1++;
            else cnt2++;
        }
        if(cnt2+1 <= mx && mx <= (n+cnt2)/2) ok = 1;
        else ok = ok = 0;
    }
    else ok = 0;

    if(ok) printf("Yes\n");
    else printf("No\n");
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;
typedef unsigned long long ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
typedef pair<ll, pair<ll, ll > > iip;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;

int main(){

    ll H, W, N; 
    cin >> H >> W >> N;
    
    ll s = 0;
    ll e = 0;
    vector<ll > ans(H * W, 0);
    for(ll i = 0; i < N; i++){
        ll t = 0;
        cin >> t;
        e += t;
        for(ll j = s; j < e; j++){
            ans[j] = i+1;
        }
        s = e;
    }

    //conf
    for(ll i = 0; i < H; i++){
        if(i % 2 == 0){
            for(ll j = 0; j < W; j++){
                cout << ( j ? " " : "" ) << ans[i * W + j];
            }
        }else{
            for(ll j = W; j > 0; j--){
                //cout << i * W + j - 1 << endl;
                cout << ans[i * W + j - 1] <<  ( j ? " " : "" );
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;


int main()
{
	ll n,k;
	cin>>n>>k;
	vector<cpp_int>a(n);
	rep(i,n)cin>>a[i];
	cpp_int cnt1=0,cnt2=0;
	rep(i,n){
		FOR(j,i+1,n){
			if(a[i]>a[j]){
				cnt1++;
			}
		}
		rep(j,n){
			if(a[i]>a[j]){
				cnt2++;
			}
		}
	}
	//cout<<cnt1<<" "<<cnt2<<endl;
	cpp_int ans=(cpp_int)cnt1*k%M+(cpp_int)cnt2*k*(k-1)/2%M;
	ans%=M;
	cout<<ans<<endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	string r;
	{
		for(int i = 0; i < ty - sy; i++) r.push_back('U');
		for(int i = 0; i < tx - sx; i++) r.push_back('R');
		for(int i = 0; i < ty - sy; i++) r.push_back('D');
		for(int i = 0; i < tx - sx; i++) r.push_back('L');
	}
	{
		r.push_back('L');
		for(int i = 0; i < ty - sy + 1; i++) r.push_back('U');
		for(int i = 0; i < tx - sx + 1; i++) r.push_back('R');
		r.push_back('D');
		r.push_back('R');
		for(int i = 0; i < ty - sy + 1; i++) r.push_back('D');
		for(int i = 0; i < tx - sx + 1; i++) r.push_back('L');
		r.push_back('U');
	}
	cout << r << endl;
	return 0;
}


Measured memory_bytes: 256
def solve():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    p = -1
    ans = 0
    for i, d in enumerate(a):
        if d == p+1:
            ans += b[d-1] + c[p-1]
        else:
            ans += b[d-1]
        p = d
    print(ans)




if __name__ == '__main__':
    solve()


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl "\n"

#define PB push_back
#define MP make_pair
#define F first
#define S second

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

#define MAX(a,b,c) (max(max(a,b),c))
#define MIN(a,b,c) (min(min(a,b),c))

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<int>::iterator vit;

const int N=1e9+7;

int32_t main(){
    IOS;
    int a,b;
    cin>>a>>b;
    if(a==a%10&&b==b%10) cout<<a*b;
    else cout<<-1;
    return 0;
}


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

int main() {
  ll N, cnt = 0;
  bool high = 0;
  cin >> N;
  vector<ll> h(N);
  ll hmax = 0;
  for(ll i = 0; i < N; i++) {
    cin >> h.at(i);
    if(hmax <= h.at(i)) hmax = h.at(i);
  }
  for(ll i = 0; i < hmax; i++) {
    for(ll j = 0; j < N; j++) {
      if(h.at(j) > 0) high = 1;
      else if((high == 1) && (h.at(j) <= 0)) {
        cnt++;
        high = 0;
      }
      h.at(j)--;
    }
    if(high == 1) {
      cnt++;
      high = 0;
    }
  }
  cout << cnt << endl;
}


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

bool comp(pair<ll,ll> A,pair<ll,ll> B)
{
    if(A.second==B.second)
    {
        return A.first<B.first;
    }
    return A.second>B.second;
}
bool comp1(pair<ll,ll> A,pair<ll,ll> B)
{
    if(A.second==B.second)
    {
        return A.first>B.first;
    }
    return A.second>B.second;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    ll n,m,k;
    cin>>n>>m>>k;
    ll x=n-m;
    ll sum=x-k;
    if(sum>=0)
    {
        cout<<0;
    }
    else
    {
        cout<<k-x<<endl;
    }
    return 0;
}

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

int main(){
    string str;
    cin>>str;
    string c,r;
    int a,b,p;
    cin>>p;
    
    for(int i=0; i<p; i++){
        cin>>c>>a>>b;
        if(c=="print"){
            cout<<str.substr(a,b-a+1)<<endl;
        }else if(c=="reverse"){
            string s3=str.substr(a,b-a+1);
            reverse(s3.begin(),s3.end());
            str=str.substr(0,a)+s3+str.substr(b+1,str.size()-b-1);
        }else{
            cin >> r;
            str=str.substr(0,a)+r+str.substr(b+1,str.size()-b-1);
        }
    }
}


Measured memory_bytes: 3216
S = input()
N = [int(S[i]) for i in range(len(S))]
X = [N[i]*100 + N[i+1]*10 + N[i+2] for i in range(len(N)-2)]

for i in range(len(X)):
  X[i] = abs(X[i]-753)

print(min(X))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> to[100005];
const int inf = 100000000;

int main() {
  int N,M;
  cin >> N >> M;
  int a,b;
  for(int i=0;i<M;i++){
    cin >> a >> b;
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  queue<int> q;
  vector<int> dist(N,inf);
  vector<int> pre(N,-1);
  dist.at(0) = 0;
  q.push(0);
  while(!q.empty()){
    int v = q.front();
    q.pop();
    for(int u : to[v]){
      if(dist[u] != inf) continue;
      dist[u] = dist[v] + 1;
      pre[u] = v;
      q.push(u);
    }
  }
  
  cout << "Yes" << endl;
  
  for(int i=0;i<N;i++){
    if(i == 0) continue;
    int ans = pre[i];
    ans++;
    cout << ans << endl;
  }
  
  return(0);
}


Measured memory_bytes: 10728
package main

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

func main() {

	for {
		n := ScanedLinetoIntSlice()
		//H, W
		H := n[0]
		W := n[1]

		//var H, W int

		//fmt.Scanln(&H, &W)

		if H == 0 && W == 0 {
			break
		}
		for i := 0; i < H; i++ {
			for j := 0; j < W; j++ {
				fmt.Printf("#")
			}
			fmt.Printf("\n")
		}
		fmt.Printf("\n")

	}

}

func ScanedLinetoIntSlice() []int {

	//var sc = bufio.NewScanner(os.Stdin)
	//sc.Scan()
	line := readLine()

	words := strings.Fields(line)

	var numbers []int

	for _, v := range words {
		number, _ := strconv.Atoi(v)
		numbers = append(numbers, number)
	}

	return numbers
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}



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

int main()
{
        string s, oval="";

        while(1) {
                int sum = 0;
                getline(cin, s);
                if(s[0] == '0') break;
                for(int i = 0; i < s.length(); i++) {
                        sum += (s[i] - 0x30);
                }
                cout << sum << endl;
        }

        return 0;
}


Measured memory_bytes: 3144
#include <iostream>
#include <algorithm>

using namespace std;

int main(void) {
	int i = 0, l, r, L = 0, R = 100000, c, g;
	cin >> c >> g;
	for (; i < g; i++) {
		scanf("%d%d", &l, &r);
		L = max(L, l);
		R = min(R, r);
	}
	R = R - L + 1;
	if (R <= 0)
		printf("0\n");
	else
		printf("%d\n", R);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
template<typename T> T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; }
template<typename T> T mod_inv(T x, const T &p) { return mod_pow(x, p-2, p); }
const ll DVSR = 1e9+7;


int main(int argc, char const *argv[])
{
  ll X, res = 0; cin >> X;
  res += (X / 500)*1000;
  X %= 500;
  res += (X / 5)*5;
  X %= 5;
  cout << res << endl;
  return 0;
}


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

char a[101][101]={0};

int main(){
    int h, w;
    scanf("%d %d", &h, &w);
    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j){
            scanf(" %c",&a[i][j]);
        }
    }
    for(int i=0;i<w+2;++i){
        printf("#");
    }
    printf("\n");
    for(int i=0;i<h;++i){
        printf("#");
        for(int j=0;j<w;++j){
            printf("%c",a[i][j]);
        }
        printf("#\n");
    }
    for(int i=0;i<w+2;++i){
        printf("#");
    }
    printf("\n");

    return 0;
}


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

using namespace std;

#define fin cin
#define fout cout
//ifstream fin("x.in"); ofstream fout("x.out");

int main() {
    ios::sync_with_stdio(0); cin.tie(nullptr);
    int n, k;
    cin >> n >> k;

    long long ans = 0;
    for (int i = 1; i <= n; ++ i) {
        int r = k - (i % k);

        r %= k;
        if ((r + r) % k != 0)
            continue;

        int cnt = max(0, (n - r) / k + 1);
        if (r == 0 && cnt > 0)
            -- cnt;

        ans += 1LL * cnt * cnt;
    }

    cout << ans << "\n";

    return 0;
}


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

int main(){
  int X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;

  priority_queue<ull> p, q, r;
  ull tmp;
  for (int i = 0; i < A; i++) {
      cin >> tmp;
      p.push(tmp);
  }
  for (int i = 0; i < B; i++) {
      cin >> tmp;
      q.push(tmp);
  }
  for (int i = 0; i < C; i++) {
      cin >> tmp;
      r.push(tmp);
  }

  ull p_ans = 0, q_ans = 0;
  priority_queue<ull, vector<ull>, greater<ull> > x, y;
  for (int i = 0; i < X; i++) {
      ull p_max = p.top();
      x.push(p_max);
      p_ans += p_max;
      p.pop();
  }
  for (int i = 0; i < Y; i++) {
      ull q_max = q.top();
      y.push(q_max);
      q_ans += q_max;
      q.pop();
  }
  while(true) {
      ull p_least, q_least, r_max;
      if(x.size()) p_least = x.top();
      else p_least = INF;
      if(y.size()) q_least = y.top();
      else q_least = INF;
      if(r.size()) r_max = r.top();
      else break;
      if (p_least >= r_max && q_least >= r_max) break;
      if (p_least < q_least) {
        p_ans -= p_least;
        p_ans += r_max;
        x.pop();
        r.pop();
        x.push(r_max);
      } else {
        q_ans -= q_least;
        q_ans += r_max;
        y.pop();
        r.pop();
        x.push(r_max);
      }
      
  }
  cout << p_ans + q_ans << endl;
  return 0;
}

Measured memory_bytes: 4852
#include"bits/stdc++.h"
using namespace std;

void Main() {
  string s, t;
  cin >> s >> t;
  cout << t << s << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


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

using namespace std;

using ll = long long;

struct Edge {
    int to;
    ll cost;
    Edge(int to, ll cost) : to(to), cost(cost) {}
};

using Graph = vector<vector<Edge> >; //隣接リスト

const ll INF = 1e15;
// const int NONE = -1;

// sは始点、mincは最短経路のコスト、Prevは最短経路をたどる際の前の頂点
// trueなら負の閉路を検出
bool bellman_ford(int s, const Graph& graph, vector<ll>& minc/*, vector<int> Prev*/) { 
    int n = graph.size();
    minc.resize(n, INF);
    //Prev.resize(n, NONE);
    minc[s] = 0; //始点までの距離は0
    for (int i = 1; i < n; i++) {
        for (int from = 0; from < n; from++) {
            for (const Edge& e : graph[from]) {
                if (minc[from] != INF && minc[e.to] > minc[from] + e.cost) {
                    minc[e.to] = minc[from] + e.cost;
                    //Prev[e.to] = from;
                }
            }
        }
    }
 
    //負の閉路を検出
    for (int from = 0; from < n; from++) {
        for (const Edge& e : graph[from]) {
            if (minc[from] != INF && minc[e.to] > minc[from] + e.cost) {
                return true;
            }
        }
    }
    return false;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    ll p;
    cin >> n >> m >> p;
 
    Graph graph(n), graph_rev(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        a--; b--;
        graph[a].emplace_back(b, p - c);
        graph_rev[b].emplace_back(a, p - c);
    }
 
    vector<ll> minc_1;
    bellman_ford(0, graph, minc_1);
 
    vector<ll> minc_n;
    bellman_ford(n - 1, graph_rev, minc_n);    
 
    for (int i = 0; i < n; i++) {
        for (Edge& e : graph[i]) {
            if (minc_1[i] >= INF || minc_n[e.to] >= INF) continue;
            if (minc_1[e.to] > minc_1[i] + e.cost) {
                cout << -1 << endl;
                return 0;
            }
        }
    }
 
    cout << max(-minc_1[n - 1], 0LL) << endl;
    return 0;
}


Measured memory_bytes: 768
n=int(input())
sp=[[i for i in input().split()] for j in range(n)]
for k in range(n):
  sp[k][1]=int(sp[k][1])
sp2=sorted(sorted(sp, key=lambda x: x[1])[::-1], key=lambda x:x[0])
for l in sp2:
  print(sp.index(l)+1)

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
  static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  private static int gcd(int a, int b) {
    int large = Math.max(a, b);
    int small = Math.min(a, b);
    while (large % small > 0) {
      int temp = small;
      small = large % small;
      large = temp;
    }
    return small;
  }


  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    int[] a = sc.nextIntArray(n);
    if (n == 2) {
      System.out.println(Math.max(a[0], a[1]));
      return;
    }
    int[] gcdLeft = new int[n];
    gcdLeft[0] = a[0];
    int[] gcdRight = new int[n];
    gcdRight[n - 1] = a[n - 1];
    for (int i = 1; i < n; i++) {
      gcdLeft[i] = gcd(gcdLeft[i - 1], a[i]);
    }
    for (int i = n - 2; i >= 0; i--) {
      gcdRight[i] = gcd(gcdRight[i + 1], a[i]);
    }
    int max = 0;
    for (int i = 0; i < n; i++) {
      if (i == 0) {
        max = Math.max(max, gcdRight[i + 1]);
      } else if (i == n - 1) {
        max = Math.max(max, gcdLeft[i - 1]);
      } else {
        max = Math.max(gcd(gcdLeft[i - 1], gcdRight[i + 1]), max);
      }
    }
    System.out.println(max);
  }
}

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

const int mod=1000000007;
typedef long long ll;
int ksm(ll a,int b,int c=1){
	for(;b;b/=2,a=a*a%mod)
		if(b&1)c=c*a%mod;
	return c;
}

inline void reduce(int&x){x+=x>>31&mod;}
int n,K,ans;
vector<pair<int,int> >factor(int n){
	vector<pair<int,int> >ret;
	for(int i=1;i*i<=n;++i)if(n%i==0)ret.emplace_back(i,0),ret.emplace_back(n/i,0);
	sort(ret.begin(),ret.end());
	return ret;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>K;
	auto vec=factor(n);
	for(auto&i:vec){
		int res=ksm(K,(i.first+1)/2);
		for(auto j:vec)if(i.first%j.first==0)reduce(res-=j.second);
		i.second=res;res=(ll)res*i.first/(2-(i.first&1))%mod;
		reduce(ans+=res-mod);
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int n, k;
    string s;
    cin >> n >> s >> k;
    char c = s[k-1];
    for (int i = 0; i < n; i++)
    {
        if (s[i] == c)
        {
            cout << c;
        } 
        else 
        {
            cout << '*';
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    double time[2];
    while(cin>>time[0]>>time[1]){
        if(time[0]<35.5&&time[1]<71)cout<<"AAA\n";
        else if(time[0]<37.5&&time[1]<77)cout<<"AA\n";
        else if(time[0]<40.0&&time[1]<83)cout<<"A\n";
        else if(time[0]<43.0&&time[1]<89)cout<<"B\n";
        else if(time[0]<50.0&&time[1]<105)cout<<"C\n";
        else if(time[0]<55.0&&time[1]<116)cout<<"D\n";
        else if(time[0]<70&&time[1]<148)cout<<"E\n";
        else cout<<"NA\n";
    }
}

Measured memory_bytes: 3036
#include "bits/stdc++.h"
#define double long double
#define int long long
#define mii map<int,int>
#define low lower_bound
#define upp upper_bound
#define inf 1000000007 //10^9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define sort(vec) sort(all(vec));
#define rever(vec) reverse(all(vec));
#define unsort(vec) sort(vec); rever(vec);
#define bisea binary_search
#define cend cout<<endl;
#define F first
#define S second
using namespace std;
signed main() {
  int h,w,cnt=0;
  cin>>h>>w;
  char tab[h][w];
  rep(i,h) {
    rep(j,w) {
      cin>>tab[i][j];
      if(tab[i][j]=='#') cnt++;
    }
  }
  if(cnt<=h+w-1) cout<<"Possible"<<endl;
  else cout<<"Impossible"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
template< typename T >
T mod_pow(T x, T n, const T &p) {
  if(x < 0) return 0;
  T ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const ld eps = 1e-9;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  ll n, k; cin >> n >> k;
  vector<ll> ans(k+1);
  for(ll i=1;i<=k;++i) {
    ans[i] = mod_pow<ll>(k/i, n, MOD);
  }
  for(ll i=k-1;i>=1;--i) {
    for(ll j=2*i;j<=k;j+=i) {
      ans[i] = (ans[i] + MOD - ans[j]) % MOD;
    }
  }
  ll su = 0;
  for(ll i=1;i<=k;++i) {
    su += ans[i] * i % MOD;
    su %= MOD;
  }
  cout << su << endl;
}


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

int main() {

  int N ; cin >> N ;
  int P ; 
  int a,b,c,d,e,f,g,h ;

  a = N % 10 ;
  b = (N / 10) % 10 ;
  c = (N / 100) % 10 ;
  d = (N / 1000) % 10 ;
  e = (N / 10000) % 10 ;
  f = (N / 100000) % 10 ;
  g = (N / 1000000) % 10 ;
  h = (N / 10000000) % 10 ;

 if ( N % (a+b+c+d+e+f+g+h) == 0 ){
   cout << "Yes" << endl;
  }
 else {
   cout << "No" << endl;
 }
}


Measured memory_bytes: 3644
# include <iostream>
# include <cmath>
# include <vector>
# include <algorithm>
# include <string>
# include <set>
# include <map>
# include <bitset>
# include <queue>
# include <iomanip>

# define FILE
using namespace std;

const int N = 1e5 + 100;

int main()
{
    # ifdef FILEs
        freopen( "input.txt", "r", stdin );
        freopen( "output.txt", "w", stdout );
    # endif // FILE
    ios_base::sync_with_stdio( false );

    int n; cin >> n;
    double a[1111] = {};
    for( int i = 1; i <= n; i ++ ){
        cin >> a[i];
    }
    sort( a+1, a + n + 1 );
    for( int i = 2; i <= n; i ++ ){
        a[i] = ( a[i-1] + a[i] ) / 2.0;
    }
    cout << fixed << ' '<< setprecision( 7 ) << a[n];
    return 0;
}


Measured memory_bytes: 256