akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] org = new int[n];
        List<Integer> a = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int tmp = sc.nextInt();
            org[i] = tmp;
            a.add(tmp);
        }
        Collections.sort(a, (e1, e2) -> e2 - e1);

        for (int i = 0; i < n; i++) {
            int candidate = a.get(0);
            if (org[i] == candidate) {
                candidate = a.get(1);
            }
            System.out.println(candidate);
        }

        sc.close();
    }

}


Measured memory_bytes: 98088
import sys
sys.setrecursionlimit(10000000)

N = int(sys.stdin.buffer.readline())

graph = [[]*N for _ in range(N)]

for _ in range(N-1):
    a, b, c = map(int, sys.stdin.buffer.readline().split())
    graph[a-1].append((b-1, c))
    graph[b-1].append((a-1, c))

Q, K = map(int, sys.stdin.buffer.readline().split())
dist_K = [-1]*N

def cal_dist_K(u = K-1, current_dist = 0):
    dist_K[u] = current_dist
    for v,c in graph[u]:
        if dist_K[v] == -1:
            cal_dist_K(v, current_dist + c)

cal_dist_K()

ans = []
for _ in range(Q):
    x, y = map(int, sys.stdin.buffer.readline().split())
    ans.append(int(dist_K[x-1] + dist_K[y-1]))

print("\n".join(map(str, ans)))

Measured memory_bytes: 154588
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>
#include <limits>
using namespace std;

set<int> s;
int main(){
    int a;
    for(size_t i = 0; i < 3; i++)
    {
        cin >> a;
        s.insert(a);
    }
    

    cout << s.size() << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
int nowX,nowY,nowT;
using namespace std;
int main(){
    int N;
    cin >> N;
    nowX=0,nowY=0,nowT=0;
int t,x,y;
int ans=0;
    for(int i=0;i<N;i++){
    cin >> t >> x >> y;
    if(abs(nowX-x)+abs(nowY-y)>t-nowT){
        ans=-1;
        break;
    }
    else if((t-nowT-abs(nowX-x)-abs(nowY-y))%2!=0){
        ans=-1;
        break;
    }
    else{
        nowX=x;
        nowY=y;
        nowT=t;
    }

    }
    if(ans==0){
        cout << "Yes"<<endl;
    }
    else{
        cout << "No"<<endl;
    }

 return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
long long int n,a,sum=0;
scanf("%lld",&n);
for(int i=0;i<n;i++){
scanf("%lld",&a);
sum+=a;
}
printf("%lld\n",sum/n);
return 0;
}

Measured memory_bytes: 1188
def main():
  N, *A = map(int, open(0).read().split())
  A.sort()

  if N % 2:
    array1 = [-2] * (N // 2) + [1] * 2 + [2] * (N // 2 - 1)
    array2 = [-2] * (N // 2 - 1) + [-1] * 2 + [2] * (N // 2)
  
    ret1 = 0
    ret2 = 0
    for i in range(N):
      ret1 += A[i]*array1[i] 
      ret2 += A[i]*array2[i]
    ret = max(ret1, ret2)

  else:
    array1 = [-2] * (N // 2 - 1) + [-1] + [1] + [2] * (N // 2 - 1)
  
    ret = 0
    for i in range(N):
      ret += A[i]*array1[i] 
  
  print(ret)

  
if __name__=="__main__":
  main()

Measured memory_bytes: 14452
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

ll fenwick[200100];

void add( int a, int x ){
	for( int i = a; i <= 200010; i += ( i & -i ) ) fenwick[i] += x;
}

ll sum( int a ){
	ll res = 0;
	for( int i = a; i > 0; i -= ( i & -i ) ) res += fenwick[i];
	return res;
}

int main(){
	ll n; cin >> n;
	vector<ll> v(n);
	ll maxi = 0;
	for( auto &i : v ){
		cin >> i;
		maxi = max(i, maxi);
	}
	ll thres = ((n*(n+1))/2 + 1)/2;
	ll l = 0, r = maxi+1;
	while( r-l > 1 ){
		ll m = (r+l)/2;
		vector<ll> s(n+1);
		s[0] = 100001;
		for( int i = 1; i <= n; ++i ){
			s[i] = s[i-1] + ( ( v[i-1] >= m ) ? 1 : -1 );
		}
        ll ans = 0;
		memset( fenwick, 0ll, sizeof(fenwick) );
        for( int i = 0; i <= n; ++i ){
            ans += sum(s[i]);
            add( s[i], 1 );
        }
		// cout << l << " " << m << " " << r << " " << ans << endl;
		if( ans >= thres ){
			l = m;
		} else {
			r = m;
		}
	}
	cout << l << endl;
	return 0;
}

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

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int k = s.nextInt();
        List<Integer> ht = new ArrayList<>();
        while(n > 0) {
            ht.add(s.nextInt());
            n--;
        }
        Collections.sort(ht);
        int ans = Integer.MAX_VALUE;
        for(int i = k - 1; i < ht.size() ; i++) {
            ans = min(ans,ht.get(i) - ht.get(i - k + 1));
        }
        System.out.println(ans);
    }
    static int min(int a, int b) {
        return a < b ? a : b;
    }
}


Measured memory_bytes: 58816
max_a_list = []
n = int(input())
b_list = list(map(int, input().split()))
max_a_list.append(b_list[0])
for i in range(1, n-1):
  max_a_list.append(min(b_list[i-1], b_list[i]))
max_a_list.append(b_list[n-2])
sum = 0
for i in range(len(max_a_list)):
  sum += max_a_list[i]
print(sum)

Measured memory_bytes: 3064
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;


void main() {
    string s;
    scan(s);

    int cnt_w;
    long ans;

    foreach_reverse (ch ; s) {
        if (ch == 'W') {
            cnt_w++;
        }
        else {
            ans += cnt_w;
        }
    }

    writeln(ans);
}



























void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 764
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main()
{
  int n,i,r=0,w=0,c=0,m=0;
    cin>>n;
  string s;
  cin>>s;
  for(i=0;i<n;i++)
  {
    if(s[i]=='W')
      ++w;
    else
      ++r;
  }
  for(i=n-w;i<n;i++)
  {
    if(s[i]=='W')
      ++m;
  }
  m=w-m;
  c=min(m,min(w,r));
  cout<<c;
}

Measured memory_bytes: 3740
open System

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f

    let readInts() =
        read string
        |> Seq.toArray
        |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

[<EntryPoint>]
let main _ =
    let N = read int
    let A = reada int64

    let sum = A |> Array.sum
    let mutable ans = Int64.MaxValue
    let mutable left = 0L
    for i in 0..N-1 do
        left <- left + A.[i]
        let right = sum - left
        ans <- Math.Min(ans, left - right |> abs)

    ans |> printfn "%d"
    0 // return an integer exit code


Measured memory_bytes: 34380
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))


def ZIP(n): return zip(*(MAP() for _ in range(n)))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    n = list(input())
    li = [int(x) for x in n if int(x) == 7]
    if len(li) > 0:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 10548
#include <bits/stdc++.h>
using namespace std;
#define repeat(i,a,b) for(int i=(a),_=(b);i<_;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,_=(a);i>=_;i--)
#define mst(a,x) memset(a,x,sizeof(a))
#define qwq (cerr<<"qwq"<<endl)
#define orz(x) (cerr<<#x": "<<x<<endl)
#define orzarr(a,n) {cerr<<#a": "; repeat(__,0,n)cerr<<(a)[__]<<" "; cerr<<endl;}
#define orzeach(a) {cerr<<#a": "; for(auto __:a)cerr<<__<<" "; cerr<<endl;}
#define fi first
#define se second
typedef long long ll; const int inf=~0u>>2; const ll INF=~0ull>>2; ll read(){ll x; if(scanf("%lld",&x)==-1)exit(0); return x;}
typedef double lf; typedef long double llf; const lf err=1e-11; const lf pi=acos(-1); lf readf(){lf x; if(scanf("%lf",&x)==-1)exit(0); return x;} template<typename T> T sqr(const T &x){return x*x;}
typedef pair<int,int> pii; template<typename A,typename B> ostream &operator<<(ostream &o,const pair<A,B> &x){return o<<'('<<x.fi<<','<<x.se<<')';}
//mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N=200010;
const int mod=(1?1000000007:998244353); ll mul(ll a,ll b,ll m=mod){return a*b%m;} ll qpow(ll a,ll b,ll m=mod){ll ans=1; for(;b;a=mul(a,a,m),b>>=1)if(b&1)ans=mul(ans,a,m); return ans;} ll getinv(ll v,ll m=mod){return qpow(v,m-2,m);}
//#define int ll
int n,m;
bool pal(string s){
	string t(s);
	reverse(t.begin(),t.end());
	return t==s;
}
signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	lf L; cin>>L;
	printf("%.10f",pow((L/3),3));
	return 0;
}

Measured memory_bytes: 384
# DAGの最長経路...トポロジカルソートもどきか？
# 普通にDAGに沿ったdpをすればいいのでは?
# 再帰だと実装楽そうだけどどうしよう
# 問題は終了と最初がわからんこと
# いや最初は全部長さ0をセットすればいいだろ
import sys
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline  # 文字列読み込む時はこっち
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def ints(): return list(map(int, readline().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, readline().split())))
    return tuple(map(list, zip(*ret)))


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce

N, M = ints()
dag = defaultdict(lambda: [])
indeg = [0] * N
for _ in ra(M):
    x, y = mina(*ints())
    indeg[y] += 1
    dag[x].append(y)

q = deque()
for u, inn in enu(indeg):  # 多点DFS初期化
    if inn == 0:
        q.append(u)

dp = [0] * N
while q:  # トポロジカル順序でdpテーブルを埋めていく
    u = q.popleft()
    # dp[u] = max(dp[u], l)
    for nx in dag[u]:
        dp[nx] = max(dp[nx], dp[u] + 1)
        indeg[nx] -= 1
        if indeg[nx] == 0:
            q.append(nx)
print(max(dp))


Measured memory_bytes: 96904
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N,A,B = LI()

num = N//(A+B)
print(num*A + min(N-(num*(A+B)),A))

Measured memory_bytes: 38384
n,k=map(int,input().split())
x=list(map(int,input().split()))
ans=10**9

for i in range(n-k+1):
    st=x[i]
    ed=x[i+k-1]
    
    if ed<=0:
        ans=min(ans,abs(st))
    elif st>=0 and ed>=0:
        ans=min(ans,ed)
    else:
        t=(min(abs(st),ed)*2)+max(abs(st),ed)
        ans=min(t,ans)

print(ans)


Measured memory_bytes: 14228
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n, a, b, c;
	cin>>n>>a>>b>>c;
	vector<char>ans;
	vector<string>query;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		query.push_back(s);
	}
	query.push_back("BC");
	for(int i=0;i<n;i++){
		string s=query[i];
		if(s=="AB"){
			if(a<b){
				ans.push_back('A');
				a++;
				b--;
			}
			else if(a>b){
				ans.push_back('B');
				a--;
				b++;
			}
			else if(query[i+1]=="BC"){
				ans.push_back('B');
				a--;
				b++;
			}
			else{
				ans.push_back('A');
				a++;
				b--;
			}
		}
		else if(s=="AC"){
			if(a<c){
				ans.push_back('A');
				a++;
				c--;
			}
			else if(c<a){
				ans.push_back('C');
				a--;
				c++;
			}
			else if(query[i+1]=="BC"){
				ans.push_back('C');
				a--;
				c++;
			}
			else{
				ans.push_back('A');
				a++;
				c--;
			}
		}
		else{
			if(b<c){
				ans.push_back('B');
				b++;
				c--;
			}
			else if(b>c){
				ans.push_back('C');
				b--;
				c++;
			}
			else if(query[i+1]=="AB"){
				ans.push_back('B');
				c--;
				b++;
			}
			else{
				ans.push_back('C');
				c++;
				b--;
			}
		}
		if(a<0 || b<0 || c<0){
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes\n";
	for(auto i:ans) cout<<i<<'\n';
}

Measured memory_bytes: 7416
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int h,w;
  const int mod=1000000007;
  cin>>h>>w;
  char ar[h][w];
  long long int dp[h][w];
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      cin>>ar[i][j];
  
  dp[0][0]=1;
  for(long long int i=1;i<h;i++)
  {
    if(ar[i][0]=='.')
    dp[i][0]=dp[i-1][0];
    else
      dp[i][0]=0;
  }
  for(long long int i=1;i<w;i++)
  {
    if(ar[0][i]=='#')
      dp[0][i]=0;
    else
      dp[0][i]=dp[0][i-1];
  }
  for(long long int i=1;i<h;i++)
  {
    for(long long int j=1;j<w;j++)
    {
      if(ar[i][j]=='#')
        dp[i][j]=0;
      else
        dp[i][j]=((dp[i-1][j]%mod)+(dp[i][j-1]%mod))%mod;
    }
  }
  
  cout<<dp[h-1][w-1]%mod;
}

Measured memory_bytes: 9088
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		// ???????????????????????°
		int num = sc.nextInt();

		for (int i = 0; i < num; i++) {
			int[] inputNumList = new int[3];

			inputNumList[0] = sc.nextInt();
			inputNumList[1] = sc.nextInt();
			inputNumList[2] = sc.nextInt();

			// ?????????????????????inputNumList[2]?????§?????????????????£?????????
			Arrays.sort(inputNumList);

			if (inputNumList[0] * inputNumList[0] + inputNumList[1]
					* inputNumList[1] == inputNumList[2] * inputNumList[2]) {
				System.out.println("YES");

			} else {
				System.out.println("NO");
			}
		}

	}

}

Measured memory_bytes: 33752
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

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


int main() {

	long long n, k, q; cin >> n >> k >> q;
	vector<long long> a(n + 2, 0);

	while (q--) {
		long long ai; cin >> ai;
		a[1]--, a[ai]++;
		if (ai < n) a[ai + 1]--, a[n + 1]++;
		debug(ai, a);
	}

	for (long long i = 1; i <= n; i++) a[i] += (a[i - 1]);
	for (long long i = 1; i <= n; i++) a[i] += k, cout << ((a[i] > 0) ? "Yes\n" : "No\n");



	return 0;
}

Measured memory_bytes: 3908
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const double PI = acos(-1);
const ll MOD = 1000000007;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr); //入出力高速化
  int N; cin >> N;
  vector<double> A(N);
  rep(i,N) cin >> A[i];

  sort(all(A));
	double ans = A[0];
	rep(i,N) ans = (ans + A[i]) / 2;

	cout << fixed << setprecision(10) << ans << endl;
}

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

#define ll              long long int
#define scan(any)       for(auto &i:any) cin>>i;
#define print(any)      for(auto i:any) cout<<i<<" "; 
#define endl            '\n'
#define pb push_back
#define vll vector<ll> 
#define f(i,x,y)  for(i=x;i<y;i++)
#define INF     LLONG_MAX
#define fast    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define p2(n,x)    cout << fixed << setprecision(x) <<n<<endl; 
#define pll    pair<ll,ll> 
#define ff first
#define ss second
#define blt(x)   __builtin_popcount(x)

void solve()
{
    ll mod=1e9+7;
    ll i,j,k,n;
    cin>>n;
    vll v(n);
    scan(v);
    ll sum=0;
    f(i,0,n)
    sum=(sum+v[i])%mod;

    ll ans=0;

    f(i,0,n)
    {
        sum=(sum-v[i]+mod)%mod;
        ans=(ans+((sum*v[i])%mod))%mod;
    }
    cout<<ans;

}

int main()
{
   
    fast
    ll t = 1;

    

    while(t--)
    solve();
    
    return 0;
}

Measured memory_bytes: 4780
#include<algorithm>
#include<iostream>
#include<stdio.h>
#include<queue>
using namespace std;

int main()
{
    int n;
    int  K;
    cin >> n>>K;
    int ans=0;
    while (n > 0)
    {
         ans++;n = n /K;
    }
    cout << ans;
  
    
}


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

int main(){
  int A,B,C;
  cin>>A>>B>>C;
  if((A==B && B!=C)||(B==C && C!=A)||(C==A && A!=B))
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

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

int main(){
    int x;
    cin >> x;
    int m = 0;
    for(int i = 1;i < x + 1;i++){
        for(int j = 2;;j++){
            int memo = pow(i, j);
            if(m < memo && memo <= x)m = memo;
            if(x <= memo || i == 1)break;
        }
    }
    cout << m << endl;
}

Measured memory_bytes: 3848
#include <string>
#include <iostream>
using namespace std;
int main() {
	string s;
	cin >> s;
	int n = s.size();
	bool ok = true;
	if (s[0] == '0' || s[n - 1] == '1') ok = false;
	for (int i = 0; i < n - 1; ++i) {
		if (s[i] != s[n - i - 2]) ok = false;
	}
	if (!ok) cout << -1 << endl;
	else {
		int pre = 1, cur = 2;
		for (int i = n - 2; i >= 0; --i) {
			cout << pre << ' ' << cur << endl;
			if (s[i] == '1') pre = cur;
			++cur;
		}
	}
	return 0;
}

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

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << '\n'; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) std::cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << '\n';
}

void solve() {
    Int a, b, c;
    cin >> a >> b >> c;
    if (a == b and b == c and a % 2 == 0) {
        print(-1);
        return;
    }
    Int res = 0;
    while (a % 2 == 0 and b % 2 == 0 and c % 2 == 0) {
        res++;
        Int aa = b / 2 + c / 2;
        Int bb = a / 2 + c / 2;
        Int cc = a / 2 + b / 2;
        a = aa;
        b = bb;
        c = cc;
    }
    print(res);
}

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


Measured memory_bytes: 3620
S = str(input())
if len(S) == 1:
    print(0)
    exit()
if len(S) % 2 == 0:
    ans1 = "10" * (len(S)//2)
    ans2 = "01" * (len(S)//2)
else:
    ans1 = "10" * (len(S)//2) + "1"
    ans2 = "01" * (len(S)//2) + "0"

result1 = 0
result2 = 0
for x,y in zip(S,ans1):
    if x != y:
        result1 += 1
for x,y in zip(S, ans2):
    if x != y:
        result2 += 1
print(min(result1,result2))
    


Measured memory_bytes: 9120
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
#include <cstdio>
#include <complex>
#include <cstring>

using namespace std;

const int N = 300 + 5;
int n, m;
int a[N][N];
int cnt[N];
int alive[N], ptr[N];

int checkOk(int ans)
{
    for(int i = 0; i < m; ++ i) {
        cnt[i] = 0;
        alive[i] = true;
    }
    for(int i = 0; i < n; ++ i) {
        cnt[a[i][0]] ++;
        ptr[i] = 0;
    }
    while(true) {
        int id = max_element(cnt, cnt + m) - cnt;
        if (cnt[id] <= ans) return true;
        alive[id] = false;
        for(int i = 0; i < n; ++ i) {
            cnt[a[i][ptr[i]]] --;
            while(ptr[i] < m && !alive[a[i][ptr[i]]]) ++ ptr[i];
            if (ptr[i] == m) return false;
            cnt[a[i][ptr[i]]] ++;
        }
    }

    return false;
}

void solve()
{
    cin >> n >> m;
    for(int i = 0; i < n; ++ i) {
        for(int j = 0; j < m; ++ j) {
            scanf("%d", &a[i][j]);
            a[i][j] --;
        }
    }
    for(int ans = 1; ans <= n; ++ ans ){
        if (checkOk(ans)) {
            cout << ans << endl;
            return;
        }
    }
}

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


Measured memory_bytes: 640
# 解説PDF読んで解説放送見てAC

# 逆から操作を考える（終点のNから考える）
# スカスカDP。なので配列を作らずに辞書で管理する必要がある

def calc_cost(n, ans_dict):

    min_cost = n * d

    inc_2 = (n + 2 - 1) // 2
    if inc_2 not in ans_dict:
        ans_dict[inc_2] = calc_cost(inc_2, ans_dict)
    min_cost = min(min_cost, d * (inc_2 * 2 - n) + a + ans_dict[inc_2])

    dec_2 = n // 2
    if dec_2 not in ans_dict:
        ans_dict[dec_2] = calc_cost(dec_2, ans_dict)
    min_cost = min(min_cost, d * (- dec_2 * 2 + n) + a + ans_dict[dec_2])

    inc_3 = (n + 3 - 1) // 3
    if inc_3 not in ans_dict:
        ans_dict[inc_3] = calc_cost(inc_3, ans_dict)
    min_cost = min(min_cost, d * (inc_3 * 3 - n) + b + ans_dict[inc_3])

    dec_3 = n // 3
    if dec_3 not in ans_dict:
        ans_dict[dec_3] = calc_cost(dec_3, ans_dict)
    min_cost = min(min_cost, d * (- dec_3 * 3 + n) + b + ans_dict[dec_3])

    inc_5 = (n + 5 - 1) // 5
    if inc_5 not in ans_dict:
        ans_dict[inc_5] = calc_cost(inc_5, ans_dict)
    min_cost = min(min_cost, d * (inc_5 * 5 - n) + c + ans_dict[inc_5])

    dec_5 = n // 5
    if dec_5 not in ans_dict:
        ans_dict[dec_5] = calc_cost(dec_5, ans_dict)
    min_cost = min(min_cost, d * (- dec_5 * 5 + n) + c + ans_dict[dec_5])

    ans_dict[n] = min_cost
    return min_cost

n_testcase = int(input())
for i in range(n_testcase):
    n, a, b, c, d = list(map(int, input().split()))

    # テストケースごとに辞書はリセットしないとダメですね
    ans_dict = {}

    ans_dict[0] = 0
    ans_dict[1] = d  # 1減らすのが常に最善

    ans = calc_cost(n, ans_dict)
    print(ans)
    # print(ans_dict)


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

vector<int> al[200050];
int visited[200050];
int dist[200050];
queue<int> q;

int main() {
	/* freopen("input.in", "r", stdin);
	freopen("output.o", "w", stdout); */
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= m; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		al[a].push_back(b);
		al[b].push_back(a);
	}
	visited[1] = 0;
	dist[1] = 0;
	for (q.push(1); !q.empty(); ) {
	    int v = q.front(); q.pop();
	    for (auto i: al[v]) {
	        if (visited[i]) continue;
	        q.push(i);
	        visited[i] = 1;
	        dist[i] = dist[v] + 1;
	    }
	}
	if (dist[n] == 2) puts("POSSIBLE");
	else puts("IMPOSSIBLE");
}

Measured memory_bytes: 13936
#include<stdio.h>

int main(){
  int N,i,j,k,v,A[1000];
  scanf("%d",&N);

  for(i=0;N>i;i++){
    scanf("%d",&A[i]);
  }

  for(i=1;N > i;i++){
    for(k=0;k<N-1;k++){
      printf("%d ",A[k]);
    }
    printf("%d\n",A[N-1]);
    v = A[i];
    j = i-1;
    while(j >= 0 && A[j] > v){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
  }
  for(k=0;k<N-1;k++){
      printf("%d ",A[k]);
    }
  printf("%d\n",A[N-1]);
 return 0;
}



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

int main() {
  ll n; cin >> n;
  vector<ll> v(n);
  rep(i,n)
    cin >> v[i];
  
  ll sum = 0;
  rep(i,n)
    sum += v[i];
  
  vector<ll> w(n); w[0] = v[0];
  for(ll i=1; i<n; i++)
    w[i] = w[i-1] + v[i];
  
  ll ans = sum;
  rep(i,n){
    if(ans >= abs(sum - w[i]*2))
      ans = abs(sum - w[i]*2);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3604
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
int main(){
  random_device rnd;
  mt19937 mt(rnd());
  int D;
  cin >> D;
  vector<int> c(26);
  for (int i = 0; i < 26; i++){
    cin >> c[i];
  }
  vector<vector<int>> s(D, vector<int>(26));
  for (int i = 0; i < D; i++){
    for (int j = 0; j < 26; j++){
      cin >> s[i][j];
    }
  }
  vector<int> last(26, -1);
  for (int i = 0; i < D; i++){
    int t = min(8, D - i);
    vector<vector<int>> L(26, vector<int>(t, 0));
    for (int j = 0; j < 26; j++){
      for (int k = 0; k < t; k++){
        L[j][k] = c[j] * (i + k - last[j]);
      }
    }
    int mx = 0;
    int a = 0;
    vector<int> best(t);
    vector<vector<int>> L2 = L;
    for (int j = 0; j < 33000; j++){
      vector<int> next(t, 0);
      if (j < 27000){
        for (int k = 0; k < t; k++){
          next[k] = mt() % 26;
        }
      } else if (j < 32000){
        next = best;
        for (int k = 0; k < 3; k++){
          int pos = mt() % t;
          int upd = mt() % 26;
          next[pos] = upd;
        }
      } else {
        next = best;
        for (int k = 0; k < 2; k++){
          int pos = mt() % t;
          int upd = mt() % 26;
          next[pos] = upd;
        }
      }
      int diff = 0;
      for (int k = 0; k < t; k++){
        diff += s[i + k][next[k]];
        for (int l = k; l < t; l++){
          diff += L2[next[k]][l] - (l - k) * c[next[k]];
          L2[next[k]][l] = (l - k) * c[next[k]];
        }
      }
      if (diff > mx){
        mx = diff;
        best = next;
      }
      for (int k = 0; k < t; k++){
        L2[next[k]] = L[next[k]];
      }
    }
    cout << best[0] + 1 << endl;
    last[best[0]] = i;
  }
}

Measured memory_bytes: 3712
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

#define N 2010
int h, w;
string s[N];
int g[N][N], v[N][N], l[N], r[N];
stack<int> st;

int solve(){
	mset(v, -1);
	rep(i, h-1) rep(j, w){
		v[i+1][j] = max(2, v[i][j]+1);
		if(!g[i][j]) v[i+1][j] = 0;
	}
	int res = 0;
	rep(i, h-1){
		mset(l, 0); mset(r, 0);
		while(!st.empty()) st.pop();
		rep(j, w){
			while(!st.empty() && v[i+1][st.top()] >= v[i+1][j]) st.pop();
			l[j] = st.empty()?0:st.top()+1;
			st.push(j);
		}
		while(!st.empty()) st.pop();
		for(int j = w-1; j >= 0; j--){
			while(!st.empty() && v[i+1][st.top()] >= v[i+1][j]) st.pop();
			r[j] = st.empty()?w:st.top();
			st.push(j);
		}
		rep(j, w){
			res = max(res, v[i+1][j]*(r[j]-l[j]+1));
		}
	}
	return res;
}

int main(){
	cin>>h>>w;
	int res = max(h, w);
	rep(i, h) cin>>s[i];
	rep(i, h) rep(j, w) g[i][j] = (s[i][j]=='#');
	rep(i, h-1) rep(j, w) g[i][j] ^= g[i+1][j];
	rep(i, h-1) rep(j, w-1) g[i][j] ^= g[i][j+1];
	w--;
	res = max(res, solve());
	/*rep(i, h-1){
		rep(j, w){
			cerr<<g[i][j]<<" ";
		}
		cerr<<endl;
	}*/
	rep(i, h-1) rep(j, w) g[i][j] = !g[i][j];
	res = max(res, solve());
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 35840
#include <iostream>
#include<stdio.h>
using namespace std;
template<class T>
struct bsNode
{
	T data;
	bsNode<T> *left;
	bsNode<T> *right;
	bsNode<T> *parent;
	bsNode():left(0),right(0),parent(0){}
	bsNode(T tmp,bsNode<T> *tmpl = 0,bsNode<T> *tmpr = 0,bsNode<T> *tmpp = 0):data(tmp),left(tmpl),right(tmpr),parent(tmpp){}
	};

template <class T>
class tree
{
	private:
	bsNode<T> *first;
	public:
	tree():first(0)
	{}
	bool insert( T data )
	{
		bsNode<T> *tmpp = first;
		bsNode<T> *&tmp = tmpp;
		if(!first)
		{
		first = new bsNode<T>(data);		 
		return true;
			}
	  else
		{
		while(true){
			if(tmp->data<data)
			{
				if(tmp->right)
				tmp = tmp->right;
				else
				{
				tmp->right = new bsNode<T>(data);	
				return true;
					}				
				}
			else if(tmp->data>data)
				{
				if(tmp->left)
				tmp = tmp->left;
				else
				{
				tmp->left = new bsNode<T>(data);	
				return true;
				}				
				}
			else return false;
			}}}
		void pre( bsNode<T> *tmp )
		{
			if(!tmp)return;
			cout<<' '<<tmp->data;
			if(tmp->left)pre(tmp->left);
			if(tmp->right)pre(tmp->right);
			}

		void mid( bsNode<T> *tmp )
		{
			if(!tmp)return;
			if(tmp->left)mid(tmp->left);
			cout<<' '<<tmp->data;
			if(tmp->right)mid(tmp->right);
			}
		void print()
		{
			
			mid(first);
			cout<<endl;
			pre(first);	
			cout<<endl;
			}
	};
	
int main()
{
	char com[10];
	int m,tmp;
	tree<int> mark;
	cin>>m;
	while(m--){
		
		scanf("%s",com);
		if(com[0]=='i')
		{
			cin>>tmp;
			mark.insert(tmp);
			}
		else mark.print();
		
		}
	return  0;
}



Measured memory_bytes: 26516
#include<stdio.h>
int main()
{

double max,n,R,min;
//int n;
//long R,min;
max=0;min=0;
scanf("%lf",&n);
for(int i=0;i<n;i++)
{
	scanf("%lf",&R);
	if(i==0){min=R;}
	if(i==1){max=R-min;}
if(max<R-min&&i>0)max=R-min;
if(min>R)min=R;
}
printf("%.0lf\n",max);
return 0;
}

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

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

  string str;
  cin >> str;

  int n = atoi(str.c_str());

  int len = str.size();
  vector<int> nums(len);
  transform(str.begin(), str.end(), nums.begin(),
            [](char ch) { return ch - '0'; });

  int sum = accumulate(nums.begin(), nums.end(), 0);

  if (n % sum) {
    cout << "No" << '\n';
  } else {
    cout << "Yes" << '\n';
  }

  return 0;
}

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

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

  long long diffMax = 1 - 1000000000;  // the worst case
  // the first turn
  long long n;
  cin >> n;
  long long leftMin = n;
  // the trailing turns
  for (int _ = 1; _ < N; _++) {
    cin >> n;
    diffMax = max(diffMax, n - leftMin);
    leftMin = min(leftMin, n);
  }
  cout << diffMax << endl;
}



Measured memory_bytes: 3108
from collections import deque

N = int(input())
li = deque(list(map(int, input().split())))

ans = N
num = 1
for i in range(N):
  ind = li.popleft()
  if ind == num:
    ans -= 1
    num += 1
    
if N == ans : ans = -1

print(ans)

Measured memory_bytes: 26780
#include<bits/stdc++.h>
#define rep(i, a, b)    for(int i = (a); i <= (b); ++i)
#define per(i, a, b)    for(int i = (a); i >= (b); --i)
#define debug(x)    cerr << #x << ' ' << x << endl
using namespace std;

typedef long long ll;
const int MAXN = 2e5 + 7;
const int MOD = 1e9 + 7;

int solution(string s) {
    int n = s.size();
    int *dp = new int[13];
    memset(dp, 0, sizeof(int) * 13);
    dp[0] = 1;
    for(int i = 1; i <= n; i++) {
        int *newdp = new int[13];
        memset(newdp, 0, sizeof(int) * 13);
        if(s[i-1] == '?') {
            for(int j = 0; j < 10; j++) {
                for(int k = 0; k < 13; k++) {
                    newdp[(j + k * 10)%13] += dp[k];
                    newdp[(j + k * 10)%13] %= MOD;
                }
            }
        } else {
            int ch = s[i-1] - '0';
            for(int k = 0; k < 13; k++){
                newdp[(ch + k * 10)%13] += dp[k];
                newdp[(ch + k * 10)%13] %= MOD;
            }
        }
        dp = newdp;
    }
    return dp[5];
}
int main() {
    string s;
    cin >> s;
    cout << solution(s) << endl;
    return 0;
}


Measured memory_bytes: 6656
#include <algorithm>
#include <complex>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <cctype>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;


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

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

    long sum;
    long cnt;

    sum = a[0] > 0 ? a[0] : 1;
    cnt = a[0] > 0 ? 0    : -a[0] + 1;
    for(int i = 1; i < n; i++){
        // cout << "i " << i << " sum " << sum << " cnt " << cnt << endl;
        if(sum > 0){
            sum += a[i];
            if(sum >= 0){
                cnt += sum + 1;
                sum = -1;
            }
        }else{
            sum += a[i];
            if(sum <= 0){
                cnt += -sum + 1;
                sum = 1;
            }
        }
    }

    long ans = cnt;

    sum = a[0] < 0 ? a[0] : -1;
    cnt = a[0] < 0 ? 0    : a[0] + 1;
    for(int i = 1; i < n; i++){
        // cout << "i " << i << " sum " << sum << " cnt " << cnt << endl;
        if(sum > 0){
            sum += a[i];
            if(sum >= 0){
                cnt += sum + 1;
                sum = -1;
            }
        }else{
            sum += a[i];
            if(sum <= 0){
                cnt += -sum + 1;
                sum = 1;
            }
        }
    }

    ans = min(ans, cnt);

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


Measured memory_bytes: 1024
def main():
    import sys
    import math
    s,t=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    if a[0]<b[0]:
        a,b=b,a
    p=a[0]-b[0]
    q=a[1]-b[1]
    x,y=p*s,q*t

    if q>0 or x+y>0:
        print(0)
        sys.exit()
    elif x+y==0:
        print('infinity')
        sys.exit()


    y=abs(y)
    if x%(y-x)==0: ans=int(x/(y-x))*2
    else: ans=math.floor(x/(y-x))*2+1
    print(ans)


 
if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import queue
import sys
sys.setrecursionlimit(1000000)

n=int(input())
L=[[] for i in range(n)]
V=[]
for i in range(n-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    L[a].append(b)
    L[b].append(a)
    V.append([a,b])
k=max(len(l) for l in L)

C=[-1]*n
D=[-1]*n
C[0]=0
D[0]=0
q=queue.Queue()
q.put(0)
while not q.empty():
    now=q.get()
    c=C[now]
    for i in L[now]: #子に対して
        if D[i]==-1:
            c=(c+1)%k
            C[i]=c
            D[i]=D[now]+1
            q.put(i)

print(k)
for v in V:
    if D[v[0]]>D[v[1]]:
        print(C[v[0]]+1)
    else:
        print(C[v[1]]+1)

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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(ll i=x;i<y;i++)
#define frr(i,x,y) for(ll i=x-1;i>=y;i--)
#define inf 10000000000000000
const ll mod=1000000007;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b)
{
    ll ans=1;
    while(b!=0)
    {
        if(b&1)
        {
            ans*=a;
            ans%=mod;
        }
        a=(a*a);
        a%=mod;
        b>>=1;
    }
    return ans%mod;
}
void solve()
{
    ll n;
    cin>>n;
    map<ll,ll> mp;
    fr(i,0,n)
    {
        ll x;
        cin>>x;
        mp[x]+=1;
    }
    //cout<<"ok\n";
    if(n%2==0)
    {
        for(ll i=1;i<n;i+=2)
        {
            if(mp[i]!=2)
            {
                cout<<"0\n";
                return;
            }
        }
    }
    else
    {
        if(mp[0]!=1)
        {
            cout<<"0\n";
            return;
        }
        for(ll i=2;i<n;i+=2)
        {
            if(mp[i]!=2)
            {
                cout<<"0\n";
                return;
            }
        }
    }
    //cout<<"ok\n";
    cout<<power(2,n/2)<<endl;
    // vector<PLL> arr;
    // for(auto i: mp)
    // {
    //     arr.pb(i);
    // }
    // fr(i,0,mp.size()-1)
    // {
    //     if(arr[i].F==0)
    //     {
    //         if(arr[i].S!=1)
    //     }
    // }
	return;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t=1;
    //cin>>t;
    while(t--)
    {
    	solve();
    }
	return 0;
}

Measured memory_bytes: 4224
import math

n = int(input())
a = list(map(int,input().split()))

lefGcd = [0]*100100
rigGcd = [0]*100100

lefGcd[0] = a[0]
rigGcd[n-1] = a[n-1]

for i in range(1,n):
	lefGcd[i] = math.gcd(lefGcd[i-1],a[i])

for i in reversed(range(0,n-1)):
	rigGcd[i] = math.gcd(rigGcd[i+1],a[i])

ans = max(rigGcd[1],lefGcd[n-2])

for i in range(1,n-1):
	ans = max(ans,math.gcd(lefGcd[i-1],rigGcd[i+1]))

print(ans)


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

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split();
        int K = int.Parse(input[0]);
        int X = int.Parse(input[1]);
        int []ans = new int[2 * K - 1];
        for(int i = 0; i < 2*K-1; i++)
        {
            ans[i] = X - K + 1 + i;
        }
        Console.WriteLine(String.Join(" ",ans));
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007
#define INF 1000000000000000000

int main(){
  string S;
  cin>>S;
  int N=S.size();
  ll ans=0;
  ll num=0;
  for(int i=0;i<N;i++){
    if(S.at(i)=='B'){
      num++;
    }else{
      ans+=num;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 640
#include<stdio.h>
int main(void)
{
    int a;
	scanf("%d",&a);
	
	if(a==0){
		printf("0\n");
	}
	else if(a==100){
		printf("1\n");
	}
	else if(a==10){
		printf("1\n");
	}
	else if(a==1){
		printf("1\n");
	}
	else if(a==110){
		printf("2\n");
	}
	else if(a==11){
		printf("2\n");
	}
	else if(a==101){
		printf("2\n");
	}
	else if(a==111){
		printf("3\n");
	}
	return 0;
	}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int tempmax(int &m,int &n)
{
	int temp;
	temp=m;
	m=n;
	n=temp;
	return 0;
}
int gcd(int m,int n)
{
	int r;
	if(n>m)
	tempmax(m,n);
	do
	{
		r=m%n;
		m=n;
		n=r;
	}while(r!=0);
	return m;
	
}
int main()
{
	int n,m,temp,i,max;
	long long min;
	while(cin>>m>>n)
	{
		max=gcd(m,n);
		min=m/max*n;
		cout<<max<<" "<<min<<endl;
		
		
	}
	return 0;
 } 

Measured memory_bytes: 3052
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <math.h>

int Array[100000];

void swap(int& a, int& b) {
	int temp = a;
	a = b;
	b = temp;
}

int partition(int A[], int p, int r) {
	int x = A[r];
	int i = p;
	for (int j = p; j < r; j++) {
		if (A[j] < x+1) {
			swap(A[i++], A[j]);
		}
	}
	swap(A[i], A[r]);
	return i;
}

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &Array[i]);
	}
	int c = partition(Array, 0, n - 1);
	for (int i = 0; i < n; i++) {
		if (i) printf(" ");
		if (i == c)printf("[%d]", Array[i]);
		else printf("%d", Array[i]);
	}
	printf("\n");
	return 0;
}



Measured memory_bytes: 3532
class UnionFind :
    def __init__(self, size) :
        self.parent = list(range(size))
        self.height = [0] * size
        self.size = [1] * size
        self.component = size

    def root(self, index) :
        if self.parent[index] == index :  # 根の場合
            return index
        rootIndex = self.root(self.parent[index])  # 葉の場合親の根を取得
        self.parent[index] = rootIndex  # 親の付け直し
        return rootIndex

    def union(self, index1, index2) :  # 結合
        root1 = self.root(index1)
        root2 = self.root(index2)

        if root1 == root2 :  # 連結されている場合
            return

        self.component -= 1  # 連結成分を減らす

        if self.height[root1] < self.height[root2] :
            self.parent[root1] = root2  # root2に結合
            self.size[root2] += self.size[root1]
        else :
            self.parent[root2] = root1  # root1に結合
            self.size[root1] += self.size[root2]
            if self.height[root1] == self.height[root2] :
                self.height[root1] += 1
        return

    def isSameRoot(self, index1, index2) :
        return self.root(index1) == self.root(index2)

    def sizeOfSameRoot(self, index) :
        return self.size[self.root(index)]

    def getComponent(self) :
        return self.component

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

for a, b in zip(sorted(A), sorted(B)):
    if a > b:
        print('No')
        exit()

# Bの昇順でAを並び替え
BA = list(zip(A, B))
BA.sort()

AI = [(a, i) for i, (_, a) in enumerate(BA)]
AI.sort()

tree = UnionFind(N)
for nessIndex, (_, originalIndex) in enumerate(AI):
    tree.union(nessIndex, originalIndex)

V = set()
for i in range(N):
    V.add(tree.root(i))

if len(V) > 1:  # サイクルが複数の場合
    print('Yes')
    exit()

if any(a <= b for a, b in zip(sorted(A)[1:], sorted(B)[:-1])):
    print('Yes')
    exit()

print('No')

Measured memory_bytes: 34396
# -*- coding: utf-8 -*-

def solve(H, W, C):
    for i in range(H):
        for j in list(C[i]):
            print(j)
            print(j)
        
if __name__ == '__main__':
    H, W = map(int, input().split())
    C = [[input()] for i in range(H)]
  
    solve(H, W, C)

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

const int MAX_N = 212345;
const ll INF = 1LL << 61;

int N;
int X[MAX_N], Y[MAX_N];
char D[MAX_N];

ll solve1() {
  ll res = INF;
  map<int, set<int> > M;
  REP(i, N) if (D[i] == 'D') M[ X[i] ].insert( Y[i] );
  REP(i, N) if (D[i] == 'U') {
    const auto& m = M[X[i]];
    auto it = m.lower_bound(Y[i]);
    if (it != m.end()) {
      ll d = (*it) - Y[i];
      chmin(res, d * 5);
    }
  }
  return res;
}
ll solve2() {
  ll res = INF;
  map<int, set<int> > M;
  REP(i, N) if (D[i] == 'L') M[ Y[i] ].insert( X[i] );
  REP(i, N) if (D[i] == 'R') {
    const auto& m = M[Y[i]];
    auto it = m.lower_bound(X[i]);
    if (it != m.end()) {
      ll d = (*it) - X[i];
      chmin(res, d * 5);
    }
  }
  return res;
}

ll solve3() {
  ll res = INF;
  map<int, set<int> > M;
  REP(i, N) if (D[i] == 'D') M[ X[i] - Y[i] ].insert( X[i] );
  REP(i, N) if (D[i] == 'R') {
    const auto& m = M[ X[i] - Y[i] ];
    auto it = m.lower_bound(X[i]);
    if (it != m.end()) {
      ll d = (*it) - X[i];
      chmin(res, d * 10);
    }
  }
  return res;
}
ll solve4() {
  ll res = INF;
  map<int, set<int> > M;
  REP(i, N) if (D[i] == 'L') M[ X[i] - Y[i] ].insert( X[i] );
  REP(i, N) if (D[i] == 'U') {
    const auto& m = M[ X[i] - Y[i] ];
    auto it = m.lower_bound(X[i]);
    if (it != m.end()) {
      ll d = (*it) - X[i];
      chmin(res, d * 10);
    }
  }
  return res;
}
ll solve5() {
  ll res = INF;
  map<int, set<int> > M;
  REP(i, N) if (D[i] == 'L') M[ X[i] + Y[i] ].insert( X[i] );
  REP(i, N) if (D[i] == 'D') {
    const auto& m = M[ X[i] + Y[i] ];
    auto it = m.lower_bound(X[i]);
    if (it != m.end()) {
      ll d = (*it) - X[i];
      chmin(res, d * 10);
    }
  }
  return res;
}
ll solve6() {
  ll res = INF;
  map<int, set<int> > M;
  REP(i, N) if (D[i] == 'U') M[ X[i] + Y[i] ].insert( X[i] );
  REP(i, N) if (D[i] == 'R') {
    const auto& m = M[ X[i] + Y[i] ];
    auto it = m.lower_bound(X[i]);
    if (it != m.end()) {
      ll d = (*it) - X[i];
      chmin(res, d * 10);
    }
  }
  return res;
}

int main2() {
  N = nextLong();
  REP(i, N) {
    cin >> X[i] >> Y[i] >> D[i];
  }

  ll ans = INF;
  chmin(ans, solve1());
  chmin(ans, solve2());
  chmin(ans, solve3());
  chmin(ans, solve4());
  chmin(ans, solve5());
  chmin(ans, solve6());

  if (ans >= INF / 2)
    cout << "SAFE" << endl;
  else
    cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 33200