akhauriyash/Code-Regression huggingface dataset:
N = int(input())
T, A = map(int, input().split())
m_diff = float('inf')
idx = 1
for i, diff in enumerate(map(lambda x, T=T, A=A: abs(A - (T - int(x) * 0.006)), input().split())):
    if diff < m_diff:
        m_diff = diff
        idx = i + 1
print(idx)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) { rep(_, n) cout << a[_] << " "; cout << endl; }
#define outp(a, n) { cout << endl; rep(_, n) cout << a[_].F << " " << a[_].S << endl; }
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)
#define LB(v, n) (int)(lower_bound(all(v), n) - v.begin())
#define UB(v, n) (int)(upper_bound(all(v), n) - v.begin())

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    // 1回解いたことある
    // とりあえずn = 3で
    // 0 1 2
    // から逆にやったらできそう
    // ただaiの制限に引っかかりそうで、n = 50に拡張したらいい
    
    ll k;
    cin >> k;
    
    ll loop = k / 50, rest = k % 50;
    
    int n = 50;
    vector<ll> a(n);
    rep(i, n) a[i] = loop + i - rest;
    
    rep(i, rest) a[i] += n + 1;
    
    out(n);
    outa(a, n);
}



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

typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define sor(v) sort(v.begin(),v.end())
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define mp1(a,b,c) P1(a,P(b,c))
#define mp make_pair

const int INF=1000000000;
const int dre_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dre_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
const int kaijou[10]={1,1,2,6,24,120,720,5040,40320,362880};

int main(){
	while(1){
		int r,c;
		static int a[12][10010];
		
		cin>>r>>c; if(r==0&&c==0)break;
		rep(i,r)rep(j,c)scanf("%d",&a[i][j]);
		
		int ret=0;
		rep(i,1<<r){
			int sum=0;
			rep(j,c){
				int cnt=0;
				rep(k,r){
					cnt+=(a[k][j]+(i>>k)&1)&1;
				}
				sum+=max(cnt,r-cnt);
			}
			ret=max(ret,sum);
			//cout<<i<<" "<<sum<<endl;
		}
		
		cout<<ret<<endl;
	}
}

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

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

    string s;
    int n;
    cin >> s >> n;

    int now = 0;
    rep(i, n){
        int t;
        cin >> t;
        if(t == 1){
            ++now;
        }
        else{
            int f; string c;
            cin >> f >> c;
            if(now & 1){
                if(f == 1){
                    s += c;
                }
                else{
                    s.insert(0, c);
                }
            }
            else{
                if(f == 1){
                    s.insert(0, c);
                }
                else{
                    s += c;
                }
            }
        }
    }

    if(now & 1){
        reverse(all(s));
    }
    cout << s;

    return 0;
}

Measured memory_bytes: 912
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) REP(i, 0, n)
#define mp make_pair
using namespace std;
int main()
{
	while (true) {
		int h, w; cin >> h >> w;
		if (!(h | w)) break;

		vector<string> 	grid(h);
		rep(i, h) cin >> grid[i];

		vector<vector<int> > hist(h, vector<int>(w+1, 0));
		rep(j, w) hist[0][j] = grid[0][j] == '.';
		REP(i, 1, h) rep(j, w) if (grid[i][j] == '.')
			hist[i][j] = hist[i-1][j] + 1;

		int res = 0;
		rep(i, h) {
			stack<pair<int, int> > S;
			rep(j, w+1) {
				if (S.empty() || S.top().first < hist[i][j])
					S.push(mp(hist[i][j], j));
				else if (S.top().first > hist[i][j]) {
					int pos = 0;
					while (!S.empty() && S.top().first >= hist[i][j]) {
						pair<int, int> p = S.top();
						S.pop();
						res = max(res, p.first * (j - p.second));
						pos = p.second;
					}
					S.push(mp(hist[i][j], pos));
				}
			}
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 2180
"use strict";

main(require("fs").readFileSync("/dev/stdin", "utf8"));

function main(input) {
  const [[n], cards] = input.split("\n").map(s => s.split(" ").map(Number));

  const targetValue = cards.reduce((p, c) => p + c) / 2;

  let currSum = 0;
  let diff = Infinity;
  for(let i = 0; i < n - 1; i++) {
    currSum += cards[i];
    diff = Math.min(diff, Math.abs(targetValue - currSum));
  }

  const ans = diff * 2;
  console.log(ans);
}

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

ll frog(vector<ll> h,vector<ll> dp,ll n,ll k){
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=k;j++){
            if(i+j<=n)
                dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
            else
                break;
        }
    }
    return dp[n];
}

int main() {
    ll n,k;cin>>n>>k;
    vector<ll> h(n+1),dp(n+4,INT_MAX);
    dp[0]=0;dp[1]=0;
    for(int i=0;i<n;i++)cin>>h[i+1];
    cout<<frog(h,dp,n,k)<<"\n";

	return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastt ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mx 1090989
ll Cnt[mx+10];

bool pf(ll x){
	if(x>1){
		Cnt[x]++;
		if(Cnt[x]>1) return true;
	}
	ll sz=sqrt(x);
	bool flag=false;
	for(ll i=2;i<=sz;i++){
		if(x%i==0){
			Cnt[i]++;
			if(Cnt[i]>1) flag=true; 
			if(x/i!=i){
				Cnt[x/i]++;
				if(Cnt[x/i]>1) flag=true;
			}
		}
	}
	return flag;
}
			
		

int main()
{
	fastt

	ll n;
	cin>>n;
	ll ar[n+10];
	for(ll i=1;i<=n;i++){
		cin>>ar[i];
	}
	ll gd=ar[1];
	for(ll i=2;i<=n;i++){
		gd=__gcd(gd,ar[i]);
	}
	if(gd>1){
		cout<<"not coprime"<<endl;
		return 0;
	}
	else{
		for(ll i=1;i<=n;i++){
			if(pf(ar[i])){
				cout<<"setwise coprime"<<endl;
				return 0;
			}
		}
		cout<<"pairwise coprime"<<endl;
	}

	return 0;
}



Measured memory_bytes: 12096
import sys

input = sys.stdin.readline


def main():
    X, Y, A, B, C = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))

    p.sort(reverse=True)
    q.sort(reverse=True)
    r.sort(reverse=True)

    s = p[:X] + q[:Y] + r
    s.sort(reverse=True)
    ans = sum(s[:X+Y])
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 23472
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DDiceInLine solver = new DDiceInLine();
        solver.solve(1, in, out);
        out.close();
    }

    static class DDiceInLine {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            double sum = 0;
            double ans = -1;
            double mat[] = new double[n];
            for (int i = 0; i < n; i++) {
                int temp = in.nextInt();
                mat[i] = (double) (temp * (temp + 1)) / (2 * temp);
            }
            for (int i = 0; i < k; i++) {
                sum += mat[i];
            }
            ans = sum;
            for (int i = k; i < n; i++) {
                sum -= mat[i - k];
                sum += mat[i];
                ans = Math.max(sum, ans);
            }
            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

    }
}



Measured memory_bytes: 40704
x,y,a,b,c = map(int,input().split())
r = sorted([i for i in map(int,input().split())],reverse = True)
r = r[0:x]
g = sorted([i for i in map(int,input().split())],reverse = True)
g = g[0:y]
n = sorted([i for i in map(int,input().split())],reverse = True)
#print(r,g,n)
com = sorted(r + g + n,reverse = True)
print(sum(com[0:x + y]))


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

int main() {
    int N, a, ans;
    ans = 9999999999;
    cin >> N;
    for(int i = 0;i<N ; i++) {
      cin >> a;
      int tmpAns = 0;
      while(a%2==0){
        tmpAns++;
        a = a/2;
      }
      ans = min(ans, tmpAns);
    }
  
  cout << ans << endl; 
  return 0;
}


Measured memory_bytes: 3552
n = int(input())

dp = [i for i in range(101010)]


t = 20

while True:
	for i in range(101010):
		if 6**t+(i+1) < 101010:
			dp[6**t+(i)] = min(dp[6**t+(i)], dp[i] + 1)

	t -= 1
	if t == 0:
		break

t = 20
while True:
	for i in range(101010):
		if 9**t+(i+1) < 101010:
			dp[9**t+(i)] = min(dp[9**t+(i)], dp[i] + 1)

	t -= 1
	if t == 0:
		break

i = 0
while i+1 < 101010:
	dp[i+1] = min(dp[i+1],dp[i]+1)
	i += 1

print dp[n]

Measured memory_bytes: 11024
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;


int main(void){
  int i,n,a;
  vector<int> p,ans;
  
  cin >> n;
  
  bool ok;
  a=2;
  while (ans.size()<n){
    ok=true;
    i=0;
    while (i<p.size() && a>=p[i]*p[i]){
      if (a%p[i]==0){
        ok=false;
        break;
      }
      i++;
    }
    
    if (ok){
      p.push_back(a);
      if (a%5==1) ans.push_back(a);
    }
    
    a++;
    
  }
  
  for (i=0;i<n;i++) cout << ans[i] << ' ';
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>
#include <bitset>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

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

  string s;
  cin >> s;
  s += "P";
  LL ans = 0;
  LL cnt = 0;
  REP(i, s.size())
  {
    if(s[i]=='A'||s[i]=='G'||s[i]=='C'||s[i]=='T'){
      cnt++;
    }else{
      if(cnt>=ans){
        ans = cnt;
      }
      cnt = 0;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef pair<int,int> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
long long int i,j,k;
long long int n,m,p,x=0;
long long int a[2002],b[2002],c[2002];
long long int dp[1002];
int kousin=0;
 
 
int main(){
	//nは頂点の数、mは辺の数
	cin>>n>>m;
	for(i=0;i<n;i++){
		dp[i]=INF;
	}
	dp[0]=0;
	for(i=0;i<m;i++){
		cin>>a[i]>>b[i];
		a[i]-=1;
		b[i]-=1;
		cin>>p;
		c[i]=-p;
	}
	while(true){
		bool update = false;
		for(i=0;i<m;i++){
			if(dp[a[i]]!=INF && dp[b[i]]>dp[a[i]]+c[i]){
				dp[b[i]] = dp[a[i]]+c[i];
				update = true;
				
			}
		}
		x+=1;
		if(!update)break;
		if(x==m)kousin = dp[n-1];
		if(x==2*m + 10 && kousin != dp[n-1]){
			x=-1;
			break;
		}else if(x==2*m+10){
			x=0;
			break;
		}
	}
	/*if(x[0][0]<0){
		cout<<"inf"<<endl;
	}else{
		cout<<-x[0][n-1]<<endl;
	}*/
	if(x==-1){
		cout<<"inf"<<endl;
	}else{
		cout<<-dp[n-1]<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <iomanip>
#include <stdio.h>
#include <math.h>
using namespace std;

int main()
{
    string str, q, tmp;
    long double x1,x2,y1,y2;
    cin>> x1 >> y1 >> x2 >> y2;
    // pow((x2-x1),2) + pow((y2-y1),2);
    // printf("%8f",sqrtl((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)));
    cout << setprecision(30) << sqrtl((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
    return 0;
}


Measured memory_bytes: 3272
//@author yash2040
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define int long long
#define pb push_back
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
main()
{
	fast();
	int t=1;
	//cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		int x=n/1000;
		if(n%1000==0)
		cout<<0<<endl;
		else
		{
			cout<<(x+1)*1000-n<<endl;
		}
	}
	
}




Measured memory_bytes: 3648
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long s = sc.nextLong();
        if (s == n) {
            System.out.println(n + 1);
            return;
        }
        for (long b = 2; b * b <= n; b++) {
            if (solve(n, s, b)) {
                System.out.println(b);
                return;
            }
        }
        boolean ok = false;
        long ans = 1000000000000L;
        for (long p = 1; p * p < n; p++) {
            long b = (n - s) / p + 1;
            // System.out.println("b = " + b);
            if (b < 2) {
                continue;
            }
            if (solve(n, s, b)) {
                ans = Math.min(ans, b);
                ok = true;
            }
        }
        if (!ok) {
            System.out.println(-1);
            return;
        }
        System.out.println(ans);
    }
    public static boolean solve(long n, long s, long num) {
        long ans = 0;
        while (n > 0) {
            ans += n % num;
            n /= num;
        }
        if (ans == s) {
            return true;
        }
        return false;
    }
}


Measured memory_bytes: 23124
'use strict';
function main(input) {
  const arr = input.trim().split('\n');
  const a = Number(arr[0]);
  const b = arr[1].split(' ')[0];
  const c = arr[1].split(' ')[1];
  let str = '';
  
  for (let i = 0; i < a; i ++) {
    str += (b[i] + c[i]);
  }

  console.log(str);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
a = int(input())
b = int(input())
c = int(input())
x = int(input())

count = 0

for i in range(a + 1):
  for g in range(b + 1):
    for h in range(c + 1):
      if i*500 + g*100 + h*50 == x:
        count += 1

print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long
#define MOD 1000000007
#define N (int) 3e6
using namespace std;
int r1, r2, c1, c2;

int ksm (int x, int y) {
	int ret = 1;
	while (y) {
		if (y & 1) (ret *= x) %= MOD;
		(x *= x) %= MOD;
		y >>= 1;
	}
	return ret;
}

int Inv (int x) {
	return ksm (x, MOD-2);
}

int fac[N], inv_f[N];
void Getinv () {
	fac[0] = 1;
	for (int i = 1; i <= (int) 2e6+5; i ++) fac[i] = fac[i-1] * i % MOD;
	inv_f[(int) 2e6+5] = Inv (fac[(int) 2e6+5]);
	for (int i = (int) 2e6 + 5 - 1; i >= 0; i --) inv_f[i] = inv_f[i+1] * (i + 1) % MOD;
}

int C (int m, int n) {
	return fac[m] * inv_f[n] % MOD * inv_f[m-n] % MOD;
}

int calc (int x, int y) {
	int ret = 0;
	for (int i = 0; i <= x; i ++) (ret += C (i+y+1, i+1)) %= MOD;
	return ret;
}

signed main () {
	cin >> r1 >> c1 >> r2 >> c2;
	
	Getinv ();
	
//	cout << calc (r1, c2) << " " << calc (r1, c2) << endl;
	
	cout << ((4ll * MOD + calc (r2, c2) - calc (r1-1, c2) - calc (r2, c1-1) + calc (r1-1, c1-1)) % MOD) << endl;
	
	return 0;
}

Measured memory_bytes: 35072
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;n>i;++i)
#define MOD 1000000007
using namespace std;
using ll=int64_t;
using pii=pair<int,int>;
using vi=vector<int>;
using VI=vector<ll>;
using vis=vector<string>;
using vvi=vector<vi>;
int gcd(int a,int b){
    if(a%b==0)
    return b;
    return gcd(b,a%b);
}
int lcm(int a,int b){
   return a*b/gcd(a,b);
}
bool prime(int num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2){
        if (num % i == 0)
        return false;
    }
    return true;
}
int main(){
    int n;
    cin>>n;
    vector<int> L(n);
    int ans=0;
    for(int i=0;i<n;i++){
        cin>>L.at(i);
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                if(L[i]!=L[j]&&L[j]!=L[k]&&L[i]!=L[k]){
                    if(abs(L[j]-L[k])<L[i]&&L[i]<L[j]+L[k]){
                        ans++;
                    }
                }
            }
        }
    }
    cout<<ans<<endl;
}

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

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

    long long n, a, b;
    cin >> n >> a >> b;

    long long min_val = (n - 1) * a + b;
    long long max_val = (n - 1) * b + a;
    long long res = max_val - min_val + 1;

    if ((n == 1 && a < b) || min_val > max_val) {
        cout << 0 << '\n';
    } else if (n == 2) {
        cout << 1 << '\n';
    } else {
        cout << res << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using VI = vector<int>;
using VB = vector<bool>;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  int p[n];
  rep(i, n) cin >> p[i];

  int cnt = 0;

  int mn = 2147483647;

  rep(i, n){
    mn = min(mn, p[i]);
    if (p[i] == mn){
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int N;
int ans = 0;
void dfs(ll x) {
	if (x < mod) {
		bool c3 = false, c5 = false, c7 = false;
		int tmp = x;
		while (tmp) {
			if (tmp % 10 == 3) c3 = true;
			if (tmp % 10 == 5) c5 = true;
			if (tmp % 10 == 7) c7 = true;
			tmp /= 10;
		}
		if (c3 && c5 && c7 && x <= N) ans++;
		for (int i = 3; i <= 7; i += 2) {
			dfs(x * 10 + i);
		}
	}
}
int main()
{
	cin >> N;
	dfs(3);
	dfs(5);
	dfs(7);
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
        #define N 200001
        int r[2 * N] = {0};
         
        int main() {
            int n, a[N], t;
            long long int u, s = 0;
            scanf("%d", &n);
            for (int i = 1; i <= n; i++) {
                scanf("%lld", &u);
                if (u < N) {
                    t = i - u;
                    if (0 <= t && t < 2 * N) r[t]++;
                    a[i] = (int) u;
                } else a[i] = 0;
            }
            for (int i = 1; i < n; i++) {
                u = a[i] + i;
                t = i - a[i];
                if (0 <= t && t < 2 * N) r[t]--;
                if (a[i] && u < 2 * N) s += r[u];
            }
            printf("%lld", s);
            return 0;
        }

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

int main() {
    int N;
    cin >> N;
    int xy[N][2];
    rep(i, N) cin >> xy[i][0] >> xy[i][1];

    double ans=0;
    rep(i, N) rep(j, N) {
        double deltax = xy[i][0] - xy[j][0], deltay = xy[i][1] - xy[j][1];
        ans += sqrt( deltax*deltax + deltay*deltay);
    }

    cout << setprecision(19) <<ans / N << endl;

    return 0;
}



Measured memory_bytes: 256
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.root = [-1]*(n+1)
		self.rank = [0]*(n+1)

	def find(self, x):
		if self.root[x] < 0:
			return x
		else:
			self.root[x] = self.find(self.root[x])
			return self.root[x]
			
	def unite(self, x, y):
		x = self.find(x)
		y = self.find(y)
		if x == y:
			return 0
		elif self.rank[x] > self.rank[y]:
			self.root[x] += self.root[y]
			self.root[y] = x
		else:
			self.root[y] += self.root[x]
			self.root[x] = y
			if self.rank[x] == self.rank[y]:
				self.rank[y] += 1

	def isSame(self, x, y):
		return self.find(x) == self.find(y) or x==y
		
def solve():
	n,_,*l=map(int,open(0).read().split())
	p=l[:n];xy=l[n:]
	ids=[0]*(n+1)
	for i,x in enumerate(p):ids[x]=i+1
	uf=UnionFind(n)
	for x,y in zip(*[iter(xy)]*2):uf.unite(x,y)
	print(sum(uf.isSame(i,ids[i])for i in range(1,n+1)))
	
if __name__=="__main__":solve()

Measured memory_bytes: 35316
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

// qsort(array, size, sizeof(int),comp);
int comp(const int *a,const int *b){
	return (*b - *a);
}

int main(int argc, char const *argv[])
{
	int n,*l;
	int cnt = 0;
	scanf("%d",&n);
	l = (int *)malloc(sizeof(int) * (2 * n));
	for (int i = 0; i < 2 * n; ++i)	scanf("%d",&l[i]);
	qsort(l,(2 * n),sizeof(int),comp);
	for (int i = 0; i < 2 * n; i += 2)
	{
		if(l[i] < l[i + 1])	cnt += l[i];
		else cnt += l[i + 1];
	}
	printf("%d\n", cnt);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
int main(void) {
	int n, s;
	cin >> n;
	vector<int> S(n);
	for (int i = 0; i < n; ++i) cin >> S[i];
	sort(S.begin(), S.end());
	int sum = accumulate(S.begin(), S.end(), 0);
	if (sum % 10 != 0) {
		cout << sum << endl;
		exit(0);
	}
	for (int i = 0; i < n; ++i) {
      	if (S[i] % 10 == 0) continue;
		sum -= S[i];
		cout << sum << endl;
		exit(0);
	}
	cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
typedef long long ll;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define forn(i,a,b) for(int i=a;i<(int)b;i++)
int main()
{
    int n,m;
    cin>>n>>m;
    if(n<m)
    {
        for(int i=0;i<m;i++)
        cout<<n;
    }
    else
    {
        for(int i=0;i<n;i++)
        cout<<m;
    }
    cout<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void fill(int y, int x, vector<vector<char> > &field){
    if(field[y][x] == '0') return;
    field[y][x] = '0';
    for(int i=0; i<4; i++){
        fill(y+dy[i], x+dx[i], field);
    }
}

int main(){
    vector<vector<char> > field(14, vector<char>(14, '0'));
    while(cin >> field[1][1]){
        for(int i=1; i<=12; i++){
            for(int j=1; j<=12; j++){
                if(!(i==1 && j==1)) cin >> field[i][j];
            }
        }
        int ans = 0;
        for(int i=1; i<=12; i++){
            for(int j=1; j<=12; j++){
                if(field[i][j] == '1'){
                    fill(i, j, field);
                    ans++;
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3092
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

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

		while (true) {
			final int n = sc.nextInt();
			
			if(n == 0){
				break;
			}
			
			ArrayList<Integer> taro = new ArrayList<Integer>(n);
			ArrayList<Integer> hanako = new ArrayList<Integer>(n);
			
			for(int i = 0; i < n; i++){
				taro.add(sc.nextInt());
			}
			
			Collections.sort(taro);
			
			for(int i = 1; i <= 2*n; i++){
				if(!taro.contains(i)){
					hanako.add(i);
				}
			}
			
			
			
			int cur = -1;
			int taro_p = 0, hanako_p = 0;
			while(!taro.isEmpty() && !hanako.isEmpty()){
				if(!taro.isEmpty() && !hanako.isEmpty()){
					if(cur == -1){
						int ret = taro.remove(0);
						cur = ret;
					}else{
						int ret = Collections.binarySearch(taro, cur);
						if(ret >= 0){
							if(ret != (taro.size() - 1)){
								int tmp = taro.remove(ret + 1);
								cur = tmp;
							}else{
								cur = -1;
							}
						}else{
							ret = -ret - 1;
							if(ret != taro.size()){
								int tmp = taro.remove(ret);
								cur = tmp;
							}else{
								cur = -1;
							}
						}
						
					}
				}else{
					break;
				}
				
				if(!taro.isEmpty() && !hanako.isEmpty()){
					if(cur == -1){
						int ret = hanako.remove(0);
						cur = ret;
					}else{
						int ret = Collections.binarySearch(hanako, cur);
						if(ret >= 0){
							if(ret != (hanako.size() - 1)){
								int tmp = hanako.remove(ret + 1);
								cur = tmp;
							}else{
								cur = -1;
							}
						}else{
							ret = -ret - 1;
							if(ret != hanako.size()){
								int tmp = hanako.remove(ret);
								cur = tmp;
							}else{
								cur = -1;
							}
						}
						
					}
				}else{
					break;
				}
				
			}
			
			
			System.out.println(hanako.size());
			System.out.println(taro.size());
			
		}
	}

}

Measured memory_bytes: 12000
#define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF= 1 << 30;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

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

double cross(const xy_t &a, const xy_t &b){
	return imag(conj(a) * b);
}

double dot(const xy_t &a, const xy_t &b){
	return real(conj(a) * b);
}

xy_t projection(const line &l, const xy_t &p){
	double t = dot(p - l.first, l.first - l.second) / norm(l.first - l.second);
	return l.first + t * (l.first - l.second);
}

bool intersectSP(const line &l, const xy_t &p){
	return abs(l.first- p) + abs(l.second - p) - abs(l.first - l.second) < EPS;
}

double distanceSP(line s, xy_t p){
	const xy_t r = projection(s, p);
	if(intersectSP(s, r)) return abs(r - p);
	return min(abs(s.first - p), abs(s.second - p));
}

int next1[] = {
	0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
};
int next2[] = {
	0, 1, 2, 3, 4, 5
};

int main(){
	int n;
	cin >> n;
	rep(t, n){
		int a, b;
		cin >> a >> b;
		if(a > 5 || (a <= 5 && a < b)){
			while(next1[a] != b){
				cout << next1[a] << " ";
				a++;
			}
			cout << b << endl;
		}else{
			while(next2[a] != b){
				cout << next2[a] << " ";
				a--;
			}
			cout << b << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
from collections import Counter

N = int(input())
S = input()
acsum = []

counter = Counter(S)
ans = 0
for i in range(1, N):
    left_counter = Counter(S[:i])
    right_counter = Counter(S[i:])
    left_set = set(left_counter.keys())
    right_set = set(right_counter.keys())
    common_set = left_set & right_set
    ans = max(ans, len(common_set))

print(ans)


Measured memory_bytes: 3316
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

struct Solver {
	int N;
	string s;
	int ans = 0;

	void solve() {
		cin >> N;
		dfs();

		cout << ans << endl;
	}

	void dfs() {
		if( s.size() ) {
			long a = stoll( s );
			if( a > N ) {
				return;
			}

			int b = 0;
			for( int i = 0; i < (int)s.size(); ++i ) {
				if( s[i] == '3' ) { b |= 1; }
				if( s[i] == '5' ) { b |= 2; }
				if( s[i] == '7' ) { b |= 4; }
			}

			if( b == 7 ) {
				ans += 1;
			}
		}

		string t = "357";
		for( int i = 0; i < (int)t.size(); ++i ) {
			s.push_back( t[i] );
			dfs();
			s.pop_back();
		}
	}
};

int main() {
	ios::sync_with_stdio( false );
	cout << fixed << setprecision( 10 );
	Solver().solve();

	return 0;
}


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

/* typedef */
/* long系 */
typedef long long ll;   // long long
typedef long double ld; // long double
/* vector系 */
typedef vector<int> vi;                    // intのvector
typedef vector<double> vd;                 // doubleのvector
typedef vector<ll> vll;                    // llのvector
typedef vector<ld> vld;                    // ldのvector
typedef vector<vector<int>> vvi;           // intの2次元vector
typedef vector<vector<double>> vvd;        // doubleの2次元vector
typedef vector<vector<ll>> vvll;           // llの2次元vector
typedef vector<vector<ld>> vvld;           // ldの2次元vector
typedef vector<pair<int, int>> vi_i;       // i_iのvector
typedef vector<pair<double, double>> vd_d; // d_dのvector
typedef vector<pair<ll, ll>> vl_l;         // l_lのvector
typedef vector<pair<ld, ld>> vld_ld;       // ld_ldのvector
typedef vector<string> vs;                 // stringのvector
/* pair系 */
typedef pair<int, int> i_i;       // int同士のpair
typedef pair<double, double> d_d; // double同士のpair
typedef pair<ll, ll> l_l;         // ll同士のpair
typedef pair<ld, ld> ld_ld;       // ld同士のpair

/* define */
#define all(v) v.begin(), v.end() // コンテナ全体
#define PI (acos(-1))             // 円周率pi

/* stringstream */
stringstream ss;
stringstream init_ss; // save default formatting

/* upper, lower */
struct ToUpper
{
    char operator()(char c)
    {
        return toupper(c);
    }
};
struct ToLower
{
    char operator()(char c)
    {
        return tolower(c);
    }
};

/* main */
void Main(void)
{
    string s;
    cin >> s;
    int n;
    cin >> n;
    cin.ignore();
    for (int i = 0; i < n; i++)
    {
        ss.str("");                      // バッファクリア
        ss.clear(stringstream::goodbit); // 状態クリア
        ss.copyfmt(init_ss);             // 書式クリア
        string tmp;
        getline(cin, tmp);
        ss << tmp;
        string order;
        ss >> order;
        int a, b;
        ss >> a >> b;
        if (order == "print")
        {
            cout << s.substr(a, b - a + 1) << endl;
        }
        else if (order == "reverse")
        {
            string ms;
            ms = s.substr(a, b - a + 1);
            reverse(all(ms));
            for (int i = a; i <= b; i++)
            {
                s[i] = ms[i - a];
            }
        }
        else if (order == "replace")
        {
            string reptmp;
            ss >> reptmp;
            for (int i = a; i <= b; i++)
            {
                s[i] = reptmp[i - a];
            }
        }
    }
}

int main(int argc, char const *argv[])
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();

    return 0;
}



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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

    cout << pow(N,3) << endl;
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define maxs(a,b) a=max(a,b)
#define mins(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){

    int n;cin>>n;
    vi a(n);
    vvi x(n),y(n);
    rep(i,n){
        cin>>a[i];
        rep(j,a[i]){
            int tx,ty;
            cin>>tx>>ty;
            x[i].push_back(tx);
            y[i].push_back(ty);
        }
    }

    int ans=0;

    vvi checked(n,vi(2,0));
    int cnt=n*2;

    vi honest(n),used(n);

    int patern=(1<<15);

    rep(i,patern){
        int ok=1;
        rep(j,n){
            if((i>>j)%2){
                rep(k,a[j]){
                    if(y[j][k] != (i>>(x[j][k]-1))%2){
                        ok=0;
                        break;
                    }
                }
            }
        }
        if(ok){
            int tmp=0;
            rep(j,n)tmp+=(i>>j)%2;
            maxs(ans,tmp);
        }
    }

    cout<<ans<<"\n";

}

Measured memory_bytes: 256
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cassert>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define SIZE 100005
#define INF 1e18
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define vec vector
using pint = pair<int,int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


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

    ll n;
    cin>>n;
    vll a(n);
    map<int,int> mp;

    rep(i,n){
        cin>>a[i];
        mp[a[i]]++;
    }

    ll ans=0;
    for(auto num: mp){
        if(num.se<num.fi)ans+=num.se;
        if(num.se>num.fi)ans+=num.se-num.fi;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 8324
//#include"cpp_kyopro.h"
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <stdlib.h>
#include <math.h>
#include <string.h>

using namespace std;

int main(void) {
	int a;
	string s;
	cin >> a;
	cin >> s;
	if (a >= 3200) cout << s << endl;
	else cout << "red" << endl;


	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main
{
	public static void main(String args[]) throws IOException{
		BufferedReader in = new BufferedReader();
		int n =in.nextInt();
		int[] arr = new int[n];
		for(int i=1; i<n; i++){
			arr[in.nextInt()-1]++;
		}
		for(int i:arr)
		out(i+"\n");
		
	}
	static void out(String s){
		System.out.print(s);
	}
}



class BufferedReader 
{ 
    java.io.BufferedReader br; 
    StringTokenizer st; 

    public BufferedReader() 
    { 
        br = new java.io.BufferedReader(new
                    InputStreamReader(System.in)); 
    } 

    public String next() 
    { 
        while (st == null || !st.hasMoreElements()) 
        { 
            try
            { 
                st = new StringTokenizer(br.readLine()); 
            } 
            catch (IOException  e) 
            { 
                e.printStackTrace(); 
            } 
        } 
        return st.nextToken(); 
    } 

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

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

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

    public String nextLine() 
    { 
        String str = ""; 
        try
        { 
            str = br.readLine(); 
        } 
        catch (IOException e) 
        { 
            e.printStackTrace(); 
        } 
        return str; 
    } 
}

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

#define ll long long int
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(i,x,n)  for(int i=x;i<n;i++)
#define FASTIO cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define eb(x) emplace_back(x)
#define mp(a,b) make_pair(a,b)
#define sz(a) int((a).size())
#define mod 1000000007
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define inf LLONG_MAX
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }


void seethis(vector<ll>vect)
{
    for(ll x:vect)
        cout<<x<<" ";
    cout<<"\n";
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
//LCM
int lcm(int a, int b) {  return a * (b / __gcd(a, b)); }

//For sort by second
bool cmp(const pair<int,int> &a)
{ return a.first<a.second; }

//Tree
/* const int MAXN = 1e5 + 5;
vector<ll> adj[MAXN];*/

//ModPower
ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}

int main()
{
	FASTIO;
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ll n;
	 cin>>n;

	 vector<ll>vect(n);

	 for(int i=0;i<n;i++)
	 	cin>>vect[i];

	sort(vect.rbegin(),vect.rend());

	 	//seethis(vect);

	 queue<int>q;
	 ll ans=vect[0];
	 q.push(vect[1]);
	 q.push(vect[1]);


	 for(int i=2;i<n;i++)
	 {
	 	ans+=q.front();
	 	q.push(vect[i]);
	 	q.push(vect[i]);
	 	q.pop();
	 }

	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 5568
import java.util.*;
import java.io.*;
import java.lang.*;

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

        String a = sc.next();

        if (a.equals("SUN"))
            System.out.println("7");
        else if (a.equals("MON"))
            System.out.println("6");
        else if (a.equals("TUE"))
            System.out.println("5");
        else if (a.equals("WED"))
            System.out.println("4");
        else if (a.equals("THU"))
            System.out.println("3");
        else if (a.equals("FRI"))
            System.out.println("2");
        else if (a.equals("SAT"))
            System.out.println("1");
    }
}


Measured memory_bytes: 35268
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;

const int IDENTITY = 0;
int myGcd(int x, int y) {
  if(x == IDENTITY) {
    return y;
  }
  if(y == IDENTITY) {
    return x;
  }
  return gcd(x, y);
}

template <typename T> struct RMQ {
  const T IDENTITY = (T)0;
  int n;                                     // 葉の数
  vector<T> dat;                             // 完全二分木の配列
  RMQ(int n_) : n(), dat(n_ * 4, IDENTITY) { // 葉の数は 2^x の形
    int x = 1;
    while(n_ > x) {
      x *= 2;
    }
    n = x;
  }

  void update(int i, T x) {
    i += n - 1;
    dat[i] = x;
    while(i > 0) {
      i = (i - 1) / 2; // parent
      dat[i] = gcd(dat[i * 2 + 1], dat[i * 2 + 2]);
    }
  }

  // the gcd element of [a,b)
  T query(int a, int b) { return query_sub(a, b, 0, 0, n); }
  T query_sub(int a, int b, int k, int l, int r) {
    if(r <= a || b <= l) {
      return IDENTITY;
    } else if(a <= l && r <= b) {
      return dat[k];
    } else {
      T vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
      T vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
      return gcd(vl, vr);
    }
  }
};

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  RMQ<int> tree(n);
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    tree.update(i, a[i]);
  }
  int ans = 1;
  ans = max(tree.query(1, n), tree.query(0, n - 1));
  for(int i = 1; i < n - 1; i++) {
    ans = max(ans, gcd(tree.query(0, i), tree.query(i + 1, n)));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5064
#include "bits/stdc++.h"

using namespace std;
using LL = long long;

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

	deque< LL> in;

	int pos_cnt = 0;

	for (int i = 0; i < n; ++i) {
		LL x;
		scanf("%lld", &x);
		in.push_back(x);
	}
	sort(in.begin(), in.end());

	vector< pair< LL, LL>> vec;
	for (int i = 0; i < n - 1; i ++) {
		LL a = in.front();
		LL b = in.back();
		in.pop_front();
		in.pop_back();

		if (i == n - 2) {
			in.push_front(b - a);
			vec.emplace_back(b, a);
		}
		else {
			if (in.back() <= 0) {
				in.push_back(b - a);
				vec.emplace_back(b, a);
			} else {
				in.push_front(a - b);
				vec.emplace_back(a, b);
			}
		}
	}

	cout << in[0] << endl;
	for (auto& x : vec) {
		printf("%lld %lld\n", x.first, x.second);
	}
}

Measured memory_bytes: 4468
#include <iostream>
#include <vector>
#include <stdio.h>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
using namespace std;
#define MAXN   55557
int spf[MAXN];

void sieve(){
    spf[1] = 1;
    for (int i=2; i<MAXN; i++)
        spf[i] = i;
    for (int i=4; i<MAXN; i+=2)
        spf[i] = 2;
 
    for (int i=3; i*i<MAXN; i++)
    {
        if (spf[i] == i)
        {
            for (int j=i*i; j<MAXN; j+=i)
 
                if (spf[j]==j)
                    spf[j] = i;
        }
    }
}
int main(){
	int n;
	cin>>n;
	sieve();
	for(int i=4;i<=55555;i++){
		if(i%30==1&&spf[i]==i&&n>0){
			cout<<i<<" ";
			n--;
		}
	}
	
	
	return 0;
	
}


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

int main() {
	string a,b;
	cin>>a>>b;
	if(a.size()>b.size()) cout<<"GREATER";
	else if(a.size()<b.size()) cout<<"LESS";
	else {
		for(int i=0; i<a.size(); i++){
			if(a[i]==b[i]) continue;
			else if(a[i]<b[i]) cout<<"LESS";
			else cout<<"GREATER";
			return 0;
		}
		cout<<"EQUAL";
		
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
# define  _deb(x) { cerr << "\033[94m"<< "[ " << #x << " = " << (x) << " ]\n\033[0m"; }
using namespace std;
#define int long long
const int xx = 2e5+10;
vector<int>g[xx];
int cost[xx];
int vis[xx];
void dfs(int s){
	vis[s] = 1;
	for(auto v : g[s]){
		if(vis[v]) continue;
		cost[v]+=cost[s];
		dfs(v);
	}
}
signed main(){
	int n,q;
	cin >> n >> q;
	for(int i=0;i<n-1;i++){
		int u,v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	for(int i=0;i<q;i++){
		int u,w;
		cin >> u >> w;
		cost[u] += w;
	}
	dfs(1);
	for(int i=1;i<=n;i++){
		if(i==n) cout<<cost[i]<<'\n';
		else{
			cout << cost[i]<<" ";
		}
	}
}
	

Measured memory_bytes: 22656
N, M = map(int, input().split())

if N == 1:
    print(M)
else:
    ans = 1
    for p in range(2, int(M**0.5) + 1):
        if M % p == 0 and p <= M // N:
            q = M // p # M = p*q
            ans = max(p, ans)
            if q <= M // N:
                ans = max(q, ans)
    print(ans)

Measured memory_bytes: 3188
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    else:
        odd = "".join(["#" if _%2 == 0 else "." for _ in range(W)])
        even = "".join(["." if _%2 == 0 else "#" for _ in range(W)])
        for _ in range(H):
            if _%2 == 0:
                print(odd)
            else:
                print(even)
        print()


Measured memory_bytes: 5620
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long long ll;

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  //for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

int main()
{
  ll K, X;
  std::cin >> K >> X;
  std::vector<ll> va;

  for (ll i = X - K + 1; i <= X + K - 1; i++) {
    va.push_back(i);
  }

  print(va);
  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input())
    A = list(map(int,input().split()))
    AI = [(a, i) for i, a in enumerate(A)]
    AI.sort(reverse = 1)
    dp = [[0] * (n + 1) for _ in range(n + 1)]
    for l in range(n):
        for r in range(n):
            if l + r >= n:
                break
            a, i = AI[l + r]
            dp[l + 1][r] = max(dp[l + 1][r], dp[l][r] + abs(i - l) * a)
            dp[l][r + 1] = max(dp[l][r + 1], dp[l][r] + abs((n - r - 1) - i) * a)
    print(max(dp[i][n - i] for i in range(n)))
resolve()

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

using namespace std;

int main(void) {
    int n, a, cnt[9] = {};
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a;
        if (a < 400) cnt[0]++;
        else if (a < 800) cnt[1]++;
        else if (a < 1200) cnt[2]++;
        else if (a < 1600) cnt[3]++;
        else if (a < 2000) cnt[4]++;
        else if (a < 2400) cnt[5]++;
        else if (a < 2800) cnt[6]++;
        else if (a < 3200) cnt[7]++;
        else cnt[8]++;
    }

    int cmb = 0;
    for (int i = 0; i < 8; i++)
        if (cnt[i]) cmb++;
    
    if (!cmb) cout << 1 << " " << cnt[8] << endl;
    else cout << cmb << " " << cmb + cnt[8] << endl;
    
    return 0;
}

Measured memory_bytes: 256
N=int(input())
p=list(map(int,input().split()))
t=0
for i in range(N):
  if i!=N-1:
    if p[i]==i+1:
      s=p[i+1]
      p[i]=s
      p[i+1]=i+1
      t+=1
  else:
    if p[i]==i+1:
      u=p[i-1]
      p[i]=u
      p[i-1]=i+1
      t+=1
print(t)

Measured memory_bytes: 14008