akhauriyash/Code-Regression huggingface dataset:
import sys

n = int(raw_input())
a_list = [int(i) for i in raw_input().split()]

# n = 9                                                                                                                                                                                                                                       
# a_list = [1,2,3,4,5,6,7,8,9]                                                                                                                                                                                                                

b_list = [0] * n

for i in range(n):
    if n % 2 == 0:
        if i % 2 == 0:
            idx = int(n / 2) + i/2
        else:
            idx = int(n / 2) - i/2 - 1
    else:
        if i % 2 != 0:
            idx = int(n / 2) + i/2 + 1
        else:
            idx = int(n / 2) - i/2
    b_list[idx] = a_list[i]



# 1                                                                                                                                                                                                                                           
# 2,1                                                                                                                                                                                                                                         
# 3,1,2                                                                                                                                                                                                                                       
# 4,2,1,3                                                                                                                                                                                                                                     
# 5,3,1,2,4                                                                                                                                                                                                                                   
# 6,4,2,1,3,5                                                                                                                                                                                                                                 
# 7,5,3,1,2,4,6                                                                                                                                                                                                                               
# 8,6,4,2,1,3,5,7                                                                                                                                                                                                                             
# 9,7,5,3,1,2,4,6,8                                                                                                                                                                                                                           

ans = ''
for b in b_list:
    ans += '{} '.format(b)
ans = ans.rstrip()

print ans



Measured memory_bytes: 22736
n,m = map(int,input().split())
h = list(map(int,input().split()))
e = [[] for i in range(n)]

for i in range(m):
    a,b = map(int,input().split())
    e[a-1].append(b-1)
    e[b-1].append(a-1)

count = 0
for i in range(n):
    if e[i] == []:
        count += 1
    else:
        check = True
        for j in e[i]:
            if h[j] >= h[i]:
                check = False
        if check:
            count += 1
print(count)

Measured memory_bytes: 92792
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


S = int(input())
MOD = 10**9 + 7

memo = [0] * 2001

# memo[0] = 0
# memo[1] = 0
# memo[2] = 0
memo[3] = 1
memo[4] = 1
memo[5] = 1

for i in range(6,2001):
    for j in range(0,i-2):
        memo[i] += memo[j]%MOD
    memo[i]+=1
    memo[i] %= MOD

print(memo[S])


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

int main(){
  string s,t,u;
  int a,b;
  cin >> s >> t >> a >> b >> u;
  if(s==u) a--;
  else b--;
  cout << a << " " << b << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int MAX=0;
struct edge{int to;int id;};
vector<vector<edge>>G;
vector<bool>seen;
vector<int>color;
void dfs(int v,int p=-1,int cr=-1){
  seen[v]=true;
  int k=1;
  for(auto nx:G[v]){
    if(nx.to==p)continue;
    if(seen[nx.to])continue;
    if(cr==k)k++;
    color[nx.id]=k;
    MAX=max(MAX,k);
    k++;
    dfs(nx.to,v,color[nx.id]);
  }
}
int main(){
  int N;
  cin>>N;
  G.resize(N);
  seen.assign(N,false);
  color.resize(N-1,0);
  for(int i=0;i<N-1;i++){
    int a,b;
    cin>>a>>b;
    a--,b--;
    G[a].push_back(edge{b,i});
    G[b].push_back(edge{a,i});
  }
  dfs(0);
  cout<<MAX<<endl;
  for(int i=0;i<N-1;i++){
    cout<<color[i]<<endl;
  }

}

Measured memory_bytes: 11016
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    int N,K;
    cin >> N >> K;
    map<int,int> mp;
    rep(i, N) {
        int a;
        cin >> a;
        ++mp[a];
    }
    vec<int> cnts;
    int nowK = 0;
    for(auto e:mp){
        cnts.push_back(e.second);
        ++nowK;
    }
    sort(all(cnts));
    int ans = 0;
    rep(i,nowK-K){
        ans+=cnts[i];
    }
    cout << ans << endl;
}

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

int main()
{
  ll l, r;
  cin >> l >> r;
  int first = l % 2019;
  int last = r % 2019;
  if (r - l + 1 >= 2019 || first > last) {
    cout << 0 << endl;
  } else {
    int ans = 2020;
    for (int i = first; i < last; i++) {
      for (int j = i + 1; j <= last; j++) {
        if (ans > (i * j) % 2019) {
          ans = (i * j) % 2019;
        }
      }
    }
    cout << ans << endl;
  }

  return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using namespace std;
constexpr int inf = 1<<30;
constexpr int mo = 1e9+7;
constexpr ll infl = 1ll<<60;

ll combi(ll N_, ll C_) {
	const int NUM_=400001;
	static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
	if (fact[0]==0) {
		inv[1]=fact[0]=factr[0]=1;
		for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
	}
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;
}

int main(){
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    int s;
    cin>>s;
    if(s < 3){
        cout << 0 << endl;
        return 0;
    }
    int num = s/3;
    ll tmp = 0ll;
    for(int i=1;i<=num;++i){
        ll res = s - 3*i;
        tmp += combi(res+i-1,res);
        tmp %= mo;
    }
    cout << tmp << endl;
    return 0;
    
}


Measured memory_bytes: 13016
import math
N = int(input())
n = 1000

x = [None] * N
y = [None] * N
for i in range(N):
    x[i], y[i] = map(int, input().split())

ans = 0
for i in range(n):
    theta = (2 * math.pi / n) * i
    tmp_x = 0
    tmp_y = 0
    for j in range(N):
        if x[j] * math.cos(theta) + y[j] * math.sin(theta) > 0:
            tmp_x += x[j]
            tmp_y += y[j]
    if tmp_x**2 + tmp_y**2 > ans**2:
        ans = math.sqrt(tmp_x**2 + tmp_y**2)

print(ans)


Measured memory_bytes: 3316
# https://atcoder.jp/contests/abc104/tasks/abc104_b
s = input()
if s[0] != "A":
    print("WA")
    exit()
if (s[2:len(s) - 1].count("C") != 1):
    print("WA")
    exit()
if (len(s) - len([b for b in s if b.islower()]) != 2):
    print("WA")
    exit()
print("AC")


Measured memory_bytes: 2940
#include<stdio.h>
#include<string.h>

int main()
{
    int k;
    char s[101];
    scanf("%d", &k);
    scanf("%s", &s);
    int len = strlen(s);
    if(len <= k)
    {
        printf("%s", s);
        
    }
    else
    {
       for(int i = 0; i < k; i++)
        {
            printf("%c", s[i]);
        }
        printf("...");
    }

    
}

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

typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef vector< vector< vector<ll> > > vvvint;
typedef vector<string> vstring;
typedef vector< vector<string> > vvstring;
typedef vector<char> vchar;
typedef vector< vector<char> > vvchar;
typedef vector<long double> vdouble;
typedef vector< vector<long double> > vvdouble;
typedef vector< vector< vector<long double> > > vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ALL(obj) (obj).begin(), (obj).end()
// #define LLONG_MAX 9223372036854775806
#define MOD 1000000007
const double PI=3.14159265358979323846;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> T Ceil(T a, T b){return (a+b-1)/b;}

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

void printv(vint &v){
    for(auto e:v) cout<<e<<" ";
        cout<<endl;
    }

int main() {
    cout<<fixed<<setprecision(10);

    ll k; cin>>k;
    ll a,b; cin>>a>>b;
    repf(i,a,b+1){
        if(i%k==0){
            puts("OK");
            return 0;
        }
    }

    puts("NG");
    return 0;

}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<math.h>
#define rep(i,n) for(ll i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
int main(){
    string s;
    cin >> s;
    if(s=="SUN") cout << '7' << endl;
    if(s=="MON") cout << '6' << endl;
    if(s=="TUE") cout << '5' << endl;
    if(s=="WED") cout << '4' << endl;
    if(s=="THU") cout << '3' << endl;
    if(s=="FRI") cout << '2' << endl;
    if(s=="SAT") cout << '1' << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string cal(int a)
{
	string n;
	if(a==0)
	return "0";
	for(;;)
	{
		if(a==0)
		{
			reverse(n.begin(),n.end());
			return n;
		}
		if(a%2)
		{
			n+='1';
			a--;
		}
		else
		n+='0';
		a/=-2;
	}
}
int main()
{
	int a;
	cin >>a;
	cout <<cal(a)<<endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException{
		BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String strARY[] = str.split(" ");
		int w = Integer.parseInt(strARY[0]);
		int h = Integer.parseInt(strARY[1]);
		int x = Integer.parseInt(strARY[2]);
		int y = Integer.parseInt(strARY[3]);
		int r = Integer.parseInt(strARY[4]);
		if (x+r <= w && y+r <= h && x-r >= 0 && y-r >= 0 ){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 17088
n = int(input())
a = list(map(int, input().split()))

cnt = dict()
for i in range(n):
    try:
        cnt[a[i]] += 1
    except:
        cnt[a[i]] = 1

ansnow=0
for v,c in cnt.items():
    ansnow += c*(c-1)//2

for i in range(n):
    ans=ansnow-(cnt[a[i]]-1)
    print(ans)

Measured memory_bytes: 86476
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-6;
const string YES = "Possible";
const string NO = "Impossible";
#define pb push_back
#define mp make_pair

const int MAX_N = 600;
int g[MAX_N][MAX_N];
int N,M;


void solve()
{
	vector<vector<int>> ans;
	for(int i=0;i<N;++i){
		for(int j=0;j<M-1;++j){
			if(g[i][j]%2){
				g[i][j+1]++;
				ans.emplace_back(vector<int>{i,j,i,j+1});
			}
		}
	}
	for(int i=0;i<N-1;++i){
		if(g[i][M-1]%2){
			g[i+1][M-1]++;
			ans.emplace_back(vector<int>{i,M-1,i+1,M-1});
		}
	}
	cout << ans.size() << endl;
	for(int i=0;i<ans.size();++i){
		printf("%d %d %d %d\n", ans[i][0]+1,ans[i][1]+1,ans[i][2]+1, ans[i][3]+1);
	}
}

int main()
{
	cin >> N >> M;
	for(int i=0;i<N;++i){
		for(int j=0;j<M;++j){
			cin >> g[i][j];
		}
	}
	solve();
}

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

int main(){
    int n;
    int A[21], B[51], C[51];

    cin>>n;

    for(int i=1;i<=n;i++){
        cin>>A[i];
    }

    for(int i=1;i<=n;i++){
        cin>>B[i];
    }

    for(int i=1;i<n;i++){
        cin>>C[i];
    }

    int u = -1, sum=0;
    for(int i=1;i<=n;i++){
        sum += B[A[i]];
        if(u+1==A[i])sum+=C[u];
        u = A[i];
    }

    cout<<sum;
}


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

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

    const int v = 1000000000;

    int x = (v-s%v)%v;
    int y = (s+x)/v;

    cout << "0 0 1000000000 1 " << x << " " << y << endl;
    return 0;
}

Measured memory_bytes: 256
var t: String? = readLine()
var t2: String = t!
var n = Int(t2)!

var maxi = Int.min
var ans = 0
for _ in 0..<n{
    var u: String? = readLine()
    var u2: String = u!
    var p = Int(u2)!
    maxi = max(maxi, p)
    ans += p
}

ans -= maxi / 2
print(ans)

Measured memory_bytes: 3696
#include <stdio.h>

int main () {
    int ns,nt;
    scanf("%d ",&ns);
    int s[ns];
    int pre;
    for (pre=0;pre<ns;pre++) {
        scanf (" %d",&s[pre]);
    }
    scanf("%d ",&nt);
    int t[nt];
    for (pre=0;pre<nt;pre++) {
        scanf (" %d",&t[pre]);
    }

    int result=0;
    for (pre=0;pre<nt;pre++) {
        int pre2;
        for (pre2=0;pre2<ns;pre2++) {
            if (t[pre] == s[pre2]) {
                result ++;
                break;
            }
        }
    }
    printf("%d\n",result);

    return 0;
}


Measured memory_bytes: 2144
n, k = list(map(int, input().split()))

trees = []
for _ in range(0, n):
  trees.append(int(input()))
trees.sort()
trees.reverse()
ans = 100000000000
for i in range(0, n-k+1):
  ans = min(ans, trees[i] - trees[i+k-1])
print(ans)

Measured memory_bytes: 7384
#include <bits/stdc++.h>
#define INF (int)1e9
#define endl "\n"
#define ll long long
#define ull unsigned long long

using namespace std;

int main()
{
    int maxn = 1000;

    int a, b;
    cin >> a >> b;

    for (int i = 1; i <= maxn; i++)
    {
        if (a == floor(0.08 * (double)i) and b == floor(0.1 * (double)i))
        {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
X = I()
g = gcd(360,X)
lcm = 360 * X // g
#print(lcm)
print(lcm // X)


Measured memory_bytes: 10648
# Dynamic Programming - Longest Common Subsequence
def lcs_len(X,Y):
    m,n = len(X),len(Y)
    LCS_r = [0 for _ in range(m+1)]
    for y in Y:
        previous = LCS_r[:]
        for i,x in enumerate(X):
            if x == y:
                LCS_r[i+1] = previous[i] + 1
            elif LCS_r[i] > previous[i+1]:
                LCS_r[i+1] = LCS_r[i]
    return LCS_r[-1]

q = int(input())
for _ in range(q):
    X = input()
    Y = input()
    print(lcs_len(X,Y))


Measured memory_bytes: 7724
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        w: i64,
        h: i64,
        x: i64,
        y: i64,
    }
    let ans = (h * w) as f64 * 0.5;
    let v = if 2 * x == w && 2 * y == h {1} else {0};
    println!("{:.9} {}", ans, v);
}

fn main() {
    run();
}


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

using CP = complex<long double>;
#define X real()
#define Y imag()
const long double PI = acos(-1.0L);
const long double EPS = 1e-10;
// conj(x) : complex conjugate,(0,1)->(0,-1)
// abs(x) : dist between(0,0) and x
// norm(x) : abs(x) * abs(x)
// arg(x) : argment

// dot(a,b) = |a||b|cos x
long double dot(CP a, CP b) { return (a * conj(b)).X; }
// cross(a,b) : area of parallelogram
long double cross(CP a, CP b) { return (a * conj(b)).Y; }
long double corner(CP a, CP b) {
  //[0,pi]
  return acos(dot(a, b) / (abs(a) * abs(b)));
}
CP projection(CP p, CP s, CP t) {
  CP base = t - s;
  long double r = dot(p - s, base) / norm(base);
  return s + base * r;
}
CP reflection(CP p, CP s, CP t) {
  CP tmp = (projection(p, s, t) - p);
  tmp *= 2;
  return p + tmp;
}

CP intersection(CP a, CP b, CP c, CP d) {
  return a + (b - a) * (cross(d - c, c - a) /
                        cross(d - c, b - a));
}

bool on_seg(CP a, CP b, CP p) {
  // if not use end point, dot(a - p, b - p) < 0
  return abs(cross(a - p, b - p)) <= 1e-10 &&
         dot(a - p, b - p) <= 0;
}

// crossing lines? (a,b) and (c,d)
bool iscross(CP a, CP b, CP c, CP d) {
  // parallel
  if(abs(cross(a - b, c - d)) <= 1e-10) {
    return on_seg(a, b, c) || on_seg(a, b, d) ||
           on_seg(c, d, a) || on_seg(c, d, b);
  }
  CP isp = intersection(a, b, c, d);
  return on_seg(a, b, isp) && on_seg(c, d, isp);
}

long double distLP(CP a, CP b, CP p) {
  return abs(cross(b - a, p - a) / abs(b - a));
}

// segmentver.
long double distSP(CP a, CP b, CP p) {
  if(dot(b - a, p - a) < 0) return abs(p - a);
  if(dot(a - b, p - b) < 0) return abs(p - b);
  return distLP(a, b, p);
}

// segment and segment
long double distSS(CP a, CP b, CP c, CP d) {
  long double res = 1e18;
  if(iscross(a, b, c, d)) return 0.0L;
  res = min(res, distSP(a, b, c));
  res = min(res, distSP(a, b, d));
  res = min(res, distSP(c, d, a));
  res = min(res, distSP(c, d, b));
  return res;
}

struct convex_hull {
  vector<CP> ch;
  int psize;
  convex_hull() {}
  convex_hull(vector<CP> &ps) { calculation(ps); }
  void calculation(vector<CP> &ps) {
    auto lmd = [&](const CP &l, const CP &r) {
      if(l.X != r.X) return l.X < r.X;
      return l.Y < r.Y;
    };
    psize = ps.size();
    sort(ps.begin(), ps.end(), lmd);
    int k = 0;
    ch.resize(psize * 2);
    for(int i = 0; i < psize; ++i) {
      while(k > 1 && cross(ch[k - 1] - ch[k - 2],
                           ps[i] - ch[k - 1]) <= 0)
        --k;
      ch[k++] = ps[i];
    }
    for(int i = psize - 2, t = k; i >= 0; --i) {
      while(k > t && cross(ch[k - 1] - ch[k - 2],
                           ps[i] - ch[k - 1]) <= 0)
        --k;
      ch[k++] = ps[i];
    }
    ch.resize(k - 1);
    psize = ch.size();
  }
};

long long q, a, b, c, d;
CP xs, xt, ys, yt;

int main() {
  cout << fixed << setprecision(10);
  cin >> q;
  for(int t = 0; t < q; ++t) {
    cin >> a >> b >> c >> d;
    xs = CP(a, b);
    xt = CP(c, d);
    cin >> a >> b >> c >> d;
    ys = CP(a, b);
    yt = CP(c, d);
    cout << distSS(xs, xt, ys, yt) << endl;
  }
  return 0;
}


Measured memory_bytes: 3364
import numpy as np
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ans=0
a=np.cumsum(A)
b=np.cumsum(B)
a=np.insert(a,0,0)
b=np.insert(b,0,0)
j=m
for i in range(n+1):
    if a[i] > k:
        break
    while b[j] > k-a[i]:
        j-=1
    ans=max(ans,i+j)
print(ans)

Measured memory_bytes: 58524
N, A, B = map(int, input().split())
S = input()

nA = 0
nB = 0

for ch in S:
    if ch == 'a':
        if nA + nB < A + B:
            print("Yes")
            nA += 1
        else:
            print("No")
    elif ch == 'b':
        if nA + nB < A + B and nB < B:
            nB += 1
            print("Yes")
        else:
            print("No")
    else:
        print("No")

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

int main(){
  long N;
  cin>>N;
  for(int h=1;h<=3500;h++){
    for(int n=1;n<=3500;n++){
      if((4*h*n-N*h-N*n)==0) break;
      if(((N*h*n)%(4*h*n-N*h-N*n))==0 && ((N*h*n)/(4*h*n-N*h-N*n))>0){
        cout<<h<<" "<<n<<" "<<((N*h*n)/(4*h*n-N*h-N*n))<<endl;
        return 0;
      }
    }
  }
  return 0;
}


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

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

        public static void Solve()
        {
            var K = int.Parse(Console.ReadLine());
            if (K % 2 == 0 || K% 5 == 0)
            {
                Console.WriteLine(-1);
                return;
            }
            //var n = 7L;
            //var answer = 1L;
            //while (n % K != 0)
            //{
            //    n *= 10;
            //    n += 7;
            //    n %= K;
            //    answer++;
            //}

            //好きな数字である７を初期化
            int num = 7;
            //何項目を初期化
            int count = 1;

            while (num % K != 0)
            {
                //ｋの倍数かどうかを判断
                
                count ++;
                //乗余はｋの倍数かどうかを判断
                num *= 10;
                num += 7;
                num %= K;
            }
            //何項目を出力
            Console.WriteLine(count);

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

Measured memory_bytes: 27416
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
  int j=0;
  string s,a="abcdefghijklmnopqrstuvwxyz";
  cin>>s;
  sort(s.begin(),s.end());
  for(int i=0;i<s.size();i++){
    if(s[s.size()-1]=='a'){
      cout<<"b"<<endl;
      break;
    }
    if(s[i]==s[i+1]) continue;
    if(s[i]==a[j]) j++; 
    else if(s[i]!=a[j]){
      cout<<a[j]<<endl;
      break;
    }
    if(i==s.size()-1&&s[s.size()-1]=='z'){
        cout<<"None"<<endl;
        break;
    }else if(i==s.size()-1)cout<<"z"<<endl;
  }
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,x;
  cin >> n;
  x=n;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  sort(s.begin(), s.end());
  for (int i = 0; i < n-1; i++) {
    if(s[i]==s[i+1]){
      x--;
    }
  }
  
  cout << x << endl;
}


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

int main(){
	set<string> gacha;
	int n;
	cin>>n;
	string s;
	
	while(n--){
		cin>>s;
		gacha.insert(s);
	}
	
	cout<<gacha.size()<<endl;
	return 0;
}

Measured memory_bytes: 19136
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let (a, b, c) = (v[0], v[1], v[2]);
    if b - a == c - b {
        println!("YES");
    } else {
        println!("NO");
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

using namespace std;
using ll = long long;

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

  const int inf = 1e9;

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

  vector<int> cnt(1e5 + 1);
  for (auto x : a)
    cnt[x]++;

  vector<int> v;
  for (auto x : cnt)
    if (x >= 2)
      v.push_back(x);

  int ans = n;
  for (int i = 0; i < v.size(); i++) {
    ans -= v[i];
    if (v[i] % 2 == 1) {
      ans++;
      continue;
    }
    if (i == v.size() - 1) {
      break;
    }
    v[i + 1]--;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4236
#include<stdio.h>
int main()
{
    int n,b=0,c=0,d=0,i;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(a[i]%2) b++;
        else if(a[i]%4) c++;
        else d++;
    }
    if(d>=b) printf("Yes");
    else if(d==b-1&&c==0) printf("Yes");
    else printf("No");
    return 0;
}

Measured memory_bytes: 512
from collections import deque

nk = input().split(' ')
n = int(nk[0])
k = int(nk[1])
w = []
for i in range(0, n):
  w.append(int(input()))

# 1台あたりの積載量がvのとき、荷物の配列aを積めるか返す
def allocatable(a, v):
  b = deque(a)
  currentCar = 0
  wSum = 0
  while currentCar < k:
    weight = b.popleft()
    if wSum + weight <= v:
      wSum += weight
    else:
      # 積み切れなければbに戻して次の車へ
      b.appendleft(weight)
      currentCar += 1
      wSum = 0
    # bに要素が残っていなければ積み切った => True
    if not b:
      return True
  # 最後の車まで来て残っていればFalse
  return not b

# 最小の積載量Pを求める
def search(a):
  l = 0
  r = 1000000000
  while l + 1 < r:
    i = int((l + r) / 2)
    if allocatable(a, i):
      r = i
    else:
      l = i
  return r

print(search(w))


Measured memory_bytes: 10672
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1LL<<60;
const ll mod = 1e9 + 7;

int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}

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

ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}

double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}


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


///////////////////////////////////////////////////////////////////////////////////

int main(){
    int n;
    cin >> n;
    long long ans = 0;
    for (int i = 1;i <= n;i++){
        ll a = n / i;
        ans += a*(a+1)/2*i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdlib>

using namespace std;

int main()	{
  int a, b, c;
  cin >> a >> b >> c;
  int maximum = max(a, max(b, c));
  cout << a + b + c - maximum << endl;
  return 0;
}

Measured memory_bytes: 3592
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <deque> 

using namespace std;


//定义比较结构
struct cmp1{
    bool operator ()(int &a,int &b){
        return a>b;//最小值优先
    }
};

std::priority_queue<int,vector<int>,cmp1> q;//最小值优先

int n, m;
int a[100010];

struct Card
{
	int value;
	int count;
};
Card cards[100010];

int r[100010];


bool compareCard(const Card &a, const Card &b)
{
	return a.value > b.value;
}

bool compare(const int &a, const int &b)
{
	return a < b;
}

int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 0 ; i < n ; i++)
		scanf("%d", &(a[i]));
		
	for (int i = 0 ; i < m ; i++)
		scanf("%d%d", &(cards[i].count), &(cards[i].value));
		
	sort(cards, cards + m, compareCard);
	
	int szR = 0;
	for (int i = 0 ; i < m ; i++)
	{
		for (int j = 0 ; j < cards[i].count ; j++)
		{
			if (szR > n)
				break;
			
			r[szR] = cards[i].value;
			szR++;
			if (szR > n)
				break;
//			q.push(cards[i].value);
//			
//			if (q.size() >= n)
//				break;
		}
	}
	
	
//	int limit = q.size();
//	
//	for (int i = limit - 1 ; i >= 0 ; i--)
//	{
//		r[i] = q.top();
//		q.pop();
//	}
		

	sort(a, a + n, compare);	
	
//	for (int i = 0 ; i < limit ; i++)
	for (int i = 0 ; i < szR ; i++)
	{
		if (r[i] > a[i])	
			a[i] = r[i];
	}
	
	long long sum = 0;
	for (int i = 0 ; i < n ; i++)
		sum = sum + a[i];
	
	printf("%lld\n", sum);
	
	return 0;
}


Measured memory_bytes: 1792
# include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
typedef long long ll;
int n,arr[105];
vector<int>ans;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>arr[i];
    }
    int cnt=n;
    bool ada;
    for(int k=1;k<=n;k++){
         ada=false;
        for(int i=cnt;i>=1;i--){
            if(arr[i]==i){
                ada=true;
                ans.pb(i);
                for(int j=i+1;j<=cnt;j++){
                    arr[j-1]=arr[j];
                }
                break;
            }
        }
        if(!ada){
            break;
        }
        cnt--;
    }
    if(!ada){
        cout<<-1<<endl;
        return 0;
    }
    reverse(ans.begin(),ans.end());
    for(auto isi:ans){
        cout<<isi<<endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int n,i;
    int a[100];
    
    scanf("%d",&n);
    for(i = 0 ; i < n ;i++){
        scanf("%d",&a[i]);
    }
    
    for(i = 0 ; i < n ; i++){
        if(a[i]%2 == 0){
            if(a[i]%3 != 0 && a[i]%5 != 0){
                printf("DENIED");
                return 0;
            }
        }
    }
    printf("APPROVED");
    return 0;
}


Measured memory_bytes: 128
import java.util.*;

class Main{

    public static void main(String[] args){

	Scanner sc = new Scanner(System.in);

	String S = sc.next();

	String T = sc.next();

	int ans = 0;

	for(int i=0; i<3; i++){

	if(S.charAt(i)==T.charAt(i)){

	ans++;

   }
  }	

	System.out.println(ans);

 }
}

Measured memory_bytes: 22996
from collections import deque

que=deque(input())
q=int(input())
rev=False
for i in range(q):
      s=input()
      if s=='1':
            rev=not rev
      else:
            t,f,c=s.split()
            if (f=='1' and rev==False) or (f=='2' and rev):
                  que.appendleft(c)
            else:
                  que.append(c)
if rev:
      que.reverse()
print(''.join(que))

Measured memory_bytes: 74200
s = gets.chomp
i = s.length
i.times do
  s.chop!
  l = (s.length / 2).ceil
  s1 = s.chars.drop(l).join
  s2 = s.chars.take(l).join
  if s1 == s2
    puts(s.length)
    exit
  end
end

Measured memory_bytes: 3836
#include<bits/stdc++.h>
#define int long long int
const int mod=1e9+7;
#define fastinout     ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;
int fac[3001];
int power(int x, int y, int p)
{
    int res = 1;
    x = (x+p) % p;
    while (y > 0)
    {
        if (y & 1)
            res = ((res * x)+p) % p;
        y = y >> 1;
        x = ((x * x)+p) % p;
    }
    return res;
}
int imod(int a, int m)
{
    return power(a, m - 2, m);
}
int ncr(int n,int r,int p)
{  
    if (r == 0) 
        return 1;  
  
    return ((fac[n] * (imod(fac[r], p)+p) % p * (imod(fac[n - r], p)+p) % p)+p) % p; 
} 
void myfun()
{
	int n,i,k,ans=0;
	fac[0] = 1; 
    for (i = 1; i <= 3000; i++) 
        fac[i] = ((fac[i - 1] * i)+mod) % mod;
    cin>>n;
    for(i=1;i<1000;i++)
    {
      k=n-i*3;
      if(k>=0)
	  {
	  ans=ans+ncr(k+i-1,i-1,mod);
	  ans=(ans+mod)%mod;
	  }
	  else
	  break;	
	}
	cout<<ans;
}

signed main()
{
	 fastinout;
	int t=1;
	//cin>>t;
	while(t--)
	myfun();
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,tp,ans1,ans2,ans;
  vector<int> x,y;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>tp;
    x.push_back(tp);
    y.push_back(tp);
  }
  sort(x.begin(),x.end());
  ans1=x[n/2-1];
  ans2=x[n/2];
  for(int i=0;i<n;i++){
    if(y[i]<=ans1) ans=ans2;
    if(y[i]>=ans2) ans=ans1;
    cout<<ans<<endl;
  }
  return 0;
}

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

int main() {
    int K, S;
    cin >> K >> S;
    int pattern = 0;
    for(int x = 0; x <= K; x++) {
        for(int y = 0;  y <= K; y++) {
            int z = S - x - y;
            bool down = 0 <= z;
            bool up = z <= K;
            if(up && down) {
                pattern++;            
            }
        }
    }
    cout << pattern << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define fill(a,val) memset(a, (val), sizeof a)
#define pb push_back
#define lli long long int
#define scantype int
#define endl "\n"
#define unique(x) x.erase(unique(x.begin(),x.end()), x.end())
#define debug(x) cerr << #x " = " << (x) << '\n'
#define what_is(x) cerr << #x << " is " << x << endl;
 
lli MOD  = 1000000007;
lli inf = 1e15;
 
void scan(scantype &x);

lli powermod(lli _a,lli _b,lli _m){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
lli string_to_number(string s){lli x=0; stringstream convert(s); convert>>x; return x;}
lli add(lli a,lli b){lli x = (a+b)%MOD; return x; }
lli mul(lli a,lli b){lli x = (a*b)%MOD; return x; }
lli sub(lli a,lli b){lli x = (a-b+MOD)%MOD; return x; }
lli div(lli a,lli b){lli x = a;lli y = powermod(b,MOD-2,MOD);lli res = (x*y)%MOD;return res;}

bool isprime(long long int n)
{
    if(n ==1 )
        return false;
    if(n == 2)
        return true;
    for(long long int i =2;i<=n/i;i++)
    {
        if(n%i == 0)
            return false;
    }
    return true;
}
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);   
    int t;
    t = 1;
    while(t--)
    {
        int n;
        cin>>n;
        int a[n];
        for(int i = 0;i<n;i++ )
            cin>>a[i];
        sort(a,a+n);
        int ans = 0;

        for(int i = 1;i<n;i++)
            ans += a[i]-a[i-1];
        cout<<ans;
    }    


    
    return 0;    
}
 

void scan(scantype &x)
{
    register int c = getchar(); //for negative/positive
    x = 0;
    int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = getchar());
    if(c=='-') {neg=1;c=getchar();}
    for(;c>47 && c<58;c = getchar()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
const int INF = 2e9;
using P = pair<int,int>;

int main(){
    int n, q;
    cin >> n >> q;
    int s[n], t[n], x[n];
    vector<P> eve;
    set<int> se;
    rep(i,n) {
      cin >> s[i] >> t[i] >> x[i];
      eve.push_back(P(s[i]-x[i],x[i]));
      eve.push_back(P(t[i]-x[i],-x[i]));
    }
    int d[q];
    rep(i,q) cin >> d[i];
    sort(eve.begin(),eve.end());
    int p = 0;
    int ans[q];
    rep(i,q){
      while(p < eve.size() && eve[p].first <= d[i]) {
        if(eve[p].second > 0) {
          se.insert(eve[p].second);
        } else {
          se.erase(-eve[p].second);
        }
        p++;
      }
      if(se.empty()) {
        ans[i] = -1;
      } else {
        ans[i] = *se.begin();
      }
    }
    for(auto k : ans) {
      cout << k << endl;
    }
    return 0;
}

Measured memory_bytes: 18028
n = input()
n = int(n)
d, x = input().split(" ")
d = int(d)
x = int(x)

a_list = list()
for _ in range(n):
	a = input()
	a_list.append(int(a))

cookie = 0
for a in a_list:
	for i in range(1000):
		day = (a * i) + 1
		if day > d:
			break
		else:
			cookie += 1

print(cookie + x)

Measured memory_bytes: 3064
let rec solve a b c acc ss =
  if a < 0 || b < 0 || c < 0 then raise Not_found;
  match ss with
  | [] -> acc
  | "AB" :: rest ->
      begin try solve (a + 1) (b - 1) c ('A' :: acc) rest with
      | Not_found -> solve (a - 1) (b + 1) c ('B' :: acc) rest
      end
  | "AC" :: rest ->
      begin try solve (a + 1) b (c - 1) ('A' :: acc) rest with
      | Not_found -> solve (a - 1) b (c + 1) ('C' :: acc) rest
      end
  | "BC" :: rest ->
      begin try solve a (b + 1) (c - 1) ('B' :: acc) rest with
      | Not_found -> solve a (b - 1) (c + 1) ('C' :: acc) rest
      end

let () = Scanf.scanf "%d %d %d %d\n" @@ fun n a b c ->
  let ss = List.init n @@ fun _ -> Scanf.scanf "%s\n" Fun.id in
  try
    let ans = solve a b c [] ss in
    print_endline "Yes";
    List.iter (Printf.printf "%c\n") (List.rev ans)
  with Not_found -> print_endline "No"



Measured memory_bytes: 22564
//By: Luogu@rui_er(122461)
#include <bits/stdc++.h>
using namespace std;

int main()
{
	int x, a, b;
	cin>>x>>a>>b;
	if(b - a <= 0) cout<<"delicious"<<endl;
	else if(b - a <= x) cout<<"safe"<<endl;
	else cout<<"dangerous"<<endl;
	return 0;
}

Measured memory_bytes: 256
S = input()
if S[0] == 'R' and S[1] == 'R' and S[2] == 'R':
    print(3)
elif (S[0] == 'R' and S[1] == 'R') or (S[1] == 'R' and S[2] == 'R'):
    print(2)
elif S[0] == 'R' or S[1] == 'R' or S[2] == 'R' or (S[0] == 'R'
                                                   and S[2] == 'R'):
    print(1)
else:
    print(0)


Measured memory_bytes: 9032
import java.util.Scanner;

public 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 X = Integer.parseInt(sc.next());

        int res = 0;
        for (int a=0; a<=A; a++) {
            for (int b=0; b<=B; b++) {
                int c = (X - a * 500 - b * 100) / 50;
                if (c >= 0 && c <= C) {
                    res++;
                }
            }
        }
        System.out.println(res);

    }
}


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

bool **edge;
bool *visited;
bool *impossible;
int V;

bool solve(int current);

int main(){

  int E,v1,v2;

  cin >> V >> E;

  //malloc
  edge = (bool**)malloc(sizeof(bool*) * V);
  for(int i=0; i<V; i++){
    edge[i] = (bool*)malloc(sizeof(bool) * V);
    for(int j=0; j<V; j++){
      edge[i][j] = false;
    }
  }
  visited = (bool*)malloc(sizeof(bool) * V);
  impossible = (bool*)malloc(sizeof(bool) * V);
  for(int i=0; i<V; i++){ visited[i] = impossible[i] = false; }

  //read edges
  for(int i=0; i<E; i++){
    cin >> v1 >> v2;
    edge[v1][v2] = true;
  }

  //solve
  bool result = false;
  for(int i=0; i<V; i++){
    result = solve(i);
    if(result)break;
    impossible[i] = true;
  }
  
  cout << result << endl;
  
  return 0;
}



bool solve(int current){
  if(visited[current])return true;
  if(impossible[current])return false;
  
  visited[current] = true;

  for(int i=0; i<V; i++){
    if(edge[current][i]){
      if(solve(i))return true;
    }
  }

  visited[current]=false;
  impossible[current] = true;
  return false;
}



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

using namespace std;

#define li long long int

const int N = 1e5 + 5;

int n, k;
int a[N];
int dp[N];

int go(int idx) {
	if (idx >= n) return 0;
	if (dp[idx] != -1) return dp[idx];
	int ans = 1e9 + 7;
	for (int i = 1; i <= k; i++) {
		if (idx + i <= n) {
			ans = min(ans, go(idx + i) + abs(a[idx + i] - a[idx]));
		}
	}
	return dp[idx] = ans;
}

void solve() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	memset(dp, -1, sizeof(dp));
	int ans = go(1);
	cout << ans;
}

int main() {
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

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

int main(){
	
	int x;
	cin >> x;
	if (x==2) {cout<<2; return 0;}
	if (x%2 == 0) x+=1;
	while (x){
		bool prime = true;
		for (int i=3; i < sqrt(x); i+=2) {
			if (x%i==0){
				prime =false;
				break;
				}	
			}
		if (prime) {cout << x; return 0;}
		x+=2;
		}
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (decltype(n) i = 0; i < n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define readvec(vec)    \
  for (auto& e : vec) { \
    cin >> e;           \
  }
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
typedef long long int ll;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef vector<double> vecd;
typedef vector<string> vecstr;
typedef vector<char> vecchar;
typedef vector<bool> vecbool;
typedef vector<vector<bool>> vec2bool;
typedef vector<vector<int>> vec2int;
typedef vector<vector<double>> vec2d;
////////////////////////////////////////////////
void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
////////////////////////////////////////////////
template <typename T>
T gcd(T a, T b) {
  if (b == 0) {
    return a;
  }
  if (a < b) return gcd(b, a);
  return gcd(b, a % b);
}
////////////////////////////////////////////////
int main() {
  init();
  int n;
  cin >> n;
  vecint a(n, 0);
  REP(i, n) cin >> a[i];
  vecint l(n + 1, 0), r(n + 1, 0);
  l[0] = r[n] = 0;
  for (int i = 1; i <= n; i++) {
    l[i] = gcd(l[i - 1], a[i - 1]);
  }
  for (int i = n - 1; i >= 0; i--) {
    r[i] = gcd(r[i + 1], a[i]);
  }
  // REP(i, n + 1) { cout << l[i] << " " << r[i] << endl; }

  int ans = 1;
  REP(i, n) { ans = max(ans, gcd(l[i], r[i + 1])); }
  cout << ans << endl;
}


Measured memory_bytes: 1408
#include <iostream>
    #include <queue>
    #include <map>
    #include <cmath>
    #include <algorithm>
    #include <queue>
    #include <cstdarg>
    #include <set>
     
    using namespace std;
    #define INF 2e9 + 9
    #define MOD 1000000007
    #define ALL(v) v.begin() , v.end()
    #define Int int64_t
    #define pll pair<Int,Int>
    template<class T> using pql = priority_queue<T, vector<T>>;
    template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
    #define ll(n) Int n; cin >> n;
    #define LL(...) Int __VA_ARGS___; cin >> __VA_ARGS___;
    #define OUT(...) cout << __VA_ARGS___;
    #define RP(n, i, s) for(Int i = s ;i < n ;i++)
    #define REP(n, i) for (Int i = 0; i < n; i++)
    #define REPe(n, i) for (Int i = 1; i <= n; i++)
    #define RPe(n, i, s) for (Int i = s; i <= n; i++)
    #define upd_max(maxer, updater) if (maxer < updater) maxer = updater;
     
    struct node {
        Int to;
        Int length;
    };
     
     
    vector<Int> divisor(Int n) {
        vector<Int> ret;
        for (Int i = 1; i * i <= n; i++) {
            if (n % i == 0) {
                ret.push_back(i);
                if (i * i != n) ret.push_back(n / i);
            }
        }
        return (ret);
    }
     
    /*
    vector<vector<int>> to;
    vector<int> flag;
    vector<int> c;
     
     
    Int dfs(int from, int mae) {
        flag[from] = 1;
        Int mini = 0;
        for (auto next : to[from]) {
            if (next == mae) continue;
            if (flag[next] == 1) {
                return -1;
            } else {
                mini = min(mini, dfs(next, from));
            }
        }
        return mini;
    }*/
     
    int dx8[8] = {0, -1, -1, -1, 0, 1, 1, 1};
    int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
     
    struct datas{
        Int max;
        Int size;
    };
     
    int main(void) {
        Int a, b ;
        cin >> a >> b;
        if ( a < 1 || 9 < a) {
            cout << -1 << endl;
            return 0;
        }
        if (b < 1 || 9 < b) {
            cout << -1 << endl;
          return 0;
        }
        cout << a * b << endl;
    }
     
     

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <numeric>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

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

    int A[5];
    rep(i,5) {
        int a; cin >> a;
        if(a==0) cout << i+1 << endl;
    }
}

Measured memory_bytes: 3544
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String s=sc.nextLine();
		int i=0;
		while(s.charAt(i)!='A')
		{
			i++;
		}
		int j=s.length()-1;
		while(s.charAt(j)!='Z')
		{
			j--;
		}
		System.out.println(s.substring(i,j+1).length());
	}

}


Measured memory_bytes: 41156
from collections import defaultdict as ddydd
from collections import deque as dq
N, K = map(int, input().split())
mod = 10 ** 9 + 7
Tree = ddydd(list)
for _ in range(N - 1):
  a, b = map(int, input().split())
  Tree[a].append(b)
  Tree[b].append(a)
Q = dq(list())
visited = [0] * (N + 1)
visited[1] = 1
res = K
temp = K - 1
for n in Tree[1]:
  visited[n] = 1
  Q.append(n)
  res *= temp
  res = res % mod
  temp -= 1

while Q:
  n = Q.popleft()
  temp = K - 2
  for m in Tree[n]:
    if visited[m] == 0:
      visited[m] = 1
      Q.append(m)
      res *= temp
      res = res % mod
      temp -= 1
print(res)

Measured memory_bytes: 29264
str = gets.chomp
gets.to_i.times do
    l = gets.chomp.split
    a = l[1].to_i
    b = l[2].to_i
    case l[0]
    when 'replace'
        str[a..b] = l[3]
    when 'reverse'
        str[a..b] = str[a..b].reverse
    when 'print'
        puts str[a..b]
    end
end

Measured memory_bytes: 8704
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 100000000000000009
#define MOD 1000000007
#define int long long
using P = pair<int,int>;

signed main(){
  int h,w;
  cin >> h >> w;
  vstring mass(h);
  rep(i,h) cin >> mass[i];
  vint dx = {-1,-1,-1,0,0,1,1,1};
  vint dy = {-1,0,1,-1,1,-1,0,1};
  rep(i,h){
    rep(j,w){
      if(mass[i][j] == '.'){
        int count = 0;
        rep(s,8){
          int nx = i + dx[s];
          int ny = j + dy[s];
          if(0 <= nx && 0 <= ny && nx < h && ny < w){
            if(mass[nx][ny] == '#') count++;
          }
        }
        cout << count;
      }
      else cout << '#';
    }
    cout << endl;
  }
}

Measured memory_bytes: 256