akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10
class SegmentTree:
    def __init__(self, arr, function):
        self.tree = [None for _ in range(len(arr))] + arr
        self.size = len(arr)
        self.fn = function
        self.build_tree()

    def build_tree(self):
        for i in range(self.size - 1, 0, -1):
            self.tree[i] = self.fn(self.tree[i * 2], self.tree[i * 2 + 1])

    def update(self, p, v):
        p += self.size
        self.tree[p] = v
        while p > 1:
            p = p // 2
            self.tree[p] = self.fn(self.tree[p * 2], self.tree[p * 2 + 1])

    def query(self, l, r):
        l, r = l + self.size, r + self.size
        res = None
        while l <= r:
            if l % 2 == 1:
                res = self.tree[l] if res is None else self.fn(res, self.tree[l])
            if r % 2 == 0:
                res = self.tree[r] if res is None else self.fn(res, self.tree[r])
            l, r = (l + 1) // 2, (r - 1) // 2
        return res

n=int(input())
h=list(map(int,input().split()))
b=list(map(int,input().split()))
new_arr=[]
for i in range(n):
    new_arr.append([h[i],b[i],i])
new_arr.sort(key=lambda x: x[0])
new_arr=new_arr[::-1]

ans=[0 for i in range(n)]
seg=SegmentTree(ans,max)

for seq in new_arr:
    idx=seq[2]
    new_value=seg.query(idx,n-1)
    new_value+=seq[1]
    #ans[idx]=new_value
    seg.update(idx,new_value)
mx=seg.query(0,n-1)
print(mx)



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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif


void Main() {
    ll A, B; cin >> A >> B;
    if (A - 2 * B <= 0){
        cout << 0 << endl;
    } else {
        cout << A - 2 * B << endl;
    }
}

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


Measured memory_bytes: 256
import itertools

def marchcount(a):
	if a == "M":
		march_list[0] += 1
	elif a == "A":
		march_list[1] += 1
	elif a == "R":
		march_list[2] += 1
	elif a == "C":
		march_list[3] += 1
	elif a == "H":
		march_list[4] += 1
	return


n = int(input())
march_list = [0 for i in range(5)] 
for i in range(n):
	marchcount(input()[0])

ans = 0
for i in itertools.combinations(march_list,3):
	ans += i[0]*i[1]*i[2]
print(ans)


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

int main() {
  int N, P;
  string S;
  cin >> N >> P >> S;
  reverse(S.begin(), S.end());
  
  if (P == 2 || P == 5) {
    long ans = 0;
    for (int i = 0; i < N; i++) {
      if ((S.at(i) - '0') % P == 0) ans += N - i;
    }
    return cout << ans << "\n", 0;
  }
  
  int dig = 1, sum = 0;
  map<int, int> MA;
  MA[0]++;
  for (int i = 0; i < N; i++) {
    (sum += (S.at(i) - '0') * dig) %= P;
    (dig *= 10) %= P;
    MA[sum]++;
  }
  long ans = 0;
  for (auto ma : MA) ans += (long) ma.second * (ma.second - 1) / 2;
  cout << ans << "\n";
}

Measured memory_bytes: 900
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << (min(b,d)-max(a,c)>=0?min(b,d)-max(a,c):0) << endl;
}


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

const int MOD = 1e9 + 7;

int main(){
    
    int n,m;
    cin >> n >> m;
	vector<int> s(n),t(m);
	rep(i,n) cin >> s[i];
	rep(i,m) cin >> t[i];
	
	vector<vector<ll>> dp(n+1, vector<ll>(m+1));
	rep(i,m+1) dp[0][i] = 1;
	rep(i,n+1) dp[i][0] = 1;
	
	rep(i,n){
		rep(j,m){
			dp[i+1][j+1] = (dp[i+1][j] + dp[i][j+1]) % MOD;
			if(s[i] != t[j]){
				dp[i+1][j+1] = (dp[i+1][j+1] - dp[i][j] + MOD) % MOD;
			}
		}
	}

	cout << dp[n][m] << endl;
    return 0;
    
}


Measured memory_bytes: 31616
a = {"1":[1,3,5,7,8,10,12],"2":[4,6,9,11],"3":[2]}

x,y = map(int, input().split())

for k in a.keys():  
    if x in a[k]:
        xi = k
    if y in a[k]:
        yi = k
if xi == yi:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
struct point{int x;int y;};
int i,j,k,count1=0,count2=0;

int main(){
    int n,t1,t2;
    cin>>n;
    point p1,p2;
    t2=0;
    p2.x=0;
    p2.y=0;
    int d;
    for(i=0;i<n;i++){
        cin>>t1>>p1.x>>p1.y;
        d=abs(p1.x-p2.x)+abs(p1.y-p2.y);
        if((t1-t2-d)%2==1||d>(t1-t2)){
            cout<<"No"<<endl;
            return 0;
        }else{
            t2=t1;
            p2.x=p1.x;
            p2.y=p1.y;
        }
    }
    cout<<"Yes"<<endl;
}

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

const long long int MOD = 1000000007;

vector<long long int> inverse;
vector<long long int> f, f_inverse;

void factorial_Initialize(int max){
    vector<long long int> a(max+1,1);
    inverse = a;
    f = a;
    f_inverse = a;

    for (int i=2; i<=max; i++){
        inverse[i]   = MOD - inverse[MOD % i] * (MOD / i) % MOD;
        f[i]         = f[i-1]         * i          % MOD;
        f_inverse[i] = f_inverse[i-1] * inverse[i] % MOD;
    }
}

long long int nCr(int n, int r){
    if(n < r || r < 0) return 0;
    if (n >= f.size()){
        factorial_Initialize(n);
    }
    return f[n] * f_inverse[r] % MOD * f_inverse[n-r] % MOD;
}

int main(){
    int n, k;
    cin >> n >> k;

    for(int i=1; i<=k; i++){
        cout << nCr(n-k+1, i) * nCr(k-1, i-1) % MOD << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.IntStream;
import java.util.stream.LongStream;

/**
 * 解説どおりに作成したソースコード
 */
public class Main {

	private static final int N = 50;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			long k = scanner.nextLong();
			long[] a = new long[N];
			IntStream.range(0, N).forEach(i -> a[i] = k / N + i);
			LongStream.range(0, k % N).forEach(l -> calcReverse(a, (int) (l % N)));
			System.out.println(N);
			IntStream.range(0, N - 1).forEach(i -> System.out.print(a[i] + " "));
			System.out.println(a[N - 1]);
		}
	}

	/**
	 * 指定された操作の逆操作を実施
	 * 
	 * @param a     操作対象の配列
	 * @param index 足し算をするindex
	 */
	private static void calcReverse(final long[] a, final int index) {
		a[index] += N + 1;
		IntStream.range(0, N).forEach(i -> a[i]--);
	}
}


Measured memory_bytes: 27220
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class DFaceProducesUnhappiness {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int N, K;
	    in >> N >> K;
	    string S;
	    in >> S;

	    REP(i,1,S.size()) {
            if (i == S.size()-1 || S[i] != S.front() && S[i+1] == S.front()) K--;
	        if (S.front() != S[i]) S[i] = S.front();
	        if (K == 0) break;
	    }
	    int answer = 0;
        REP(i,0,S.size()) {
            if (S[i] == 'L') {
                if (i > 0 && S[i-1] == 'L') answer++;
            } else {
                if (i < S.size()-1 && S[i+1] == 'R') answer++;
            }
        }
        out << answer << "\n";
	}
};


int main() {
	DFaceProducesUnhappiness solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

int main(){
  int n,i = 0;
  string s;
  cin >> n >> s;
  if(n % 2 == 1){
    cout << "No";
  }
  else{
    int hanbun = 0;
    hanbun = n / 2;
    while(i < hanbun){
      if(s[i] == s[hanbun + i]){
        i = i + 1;
      }
      else{
        cout << "No";
        return 0;
      }
    }
    cout << "Yes";
    return 0;
  }
}

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

#define all(x) x.begin(), x.end()

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MN = 1e5 + 5, LN = 17, INF = 0x3f3f3f3f, MOD = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    ll n, s;
    cin >> n >> s;
    if (n == s) {
        cout << n + 1 << '\n';
        return 0;
    }
    for (ll i = 2; i <= sqrt(n); i++) {
        ll sum = 0;
        ll temp = n;
        while (temp > 0) {
            sum += temp % i;
            temp /= i;
        }
        if (sum == s) {
            cout << i << '\n';
            return 0;
        }
    }
    ll ret = LLONG_MAX;
    for (ll i = 1; i <= sqrt(n - s); i++) {
        if ((n - s) % i == 0) {
            ll b1 = i + 1, b2 = (n - s) / i + 1;
            if (b1 >= sqrt(n) && (n / b1) % b1 + n % b1 == s) ret = min(ret, b1);
            if (b2 >= sqrt(n) && (n / b2) % b2 + n % b2 == s) ret = min(ret, b2);
        }
    }
    if (ret == LLONG_MAX) cout << -1 << '\n';
    else cout << ret << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

struct SegmentTree {
    struct Node {
        Node operator*(const Node& o) const {
            return { min(v, o.v) };
        }
        int v;
    };

    SegmentTree(int n) : e({ (1U << 31) - 1 }), n(n) {
        for (m = 2; m < n; m *= 2);
        t = vector<Node>(m + n + n % 2, e);
    }
    Node& operator[](int i) {
        return t[m + i];
    }
    const Node& root() const {
        return t[1];
    }
    void build() {
        for (int i = (n - 1 + m) / 2; i > 0; i--) {
            t[i] = t[i * 2] * t[i * 2 + 1];
        }
    }
    void update(int i, const Node& o) {
        for (t[i += m] = o; i /= 2, i > 0;) t[i] = t[i * 2] * t[i * 2 + 1];
    }
    Node query(int l, int r) {
        Node o = e;
        for (l += m, r += m; l < r; l /= 2, r /= 2) {
            if (r & 1) o = o * t[--r];
            if (l & 1) o = o * t[l++];
        }
        return o;
    }
    vector<Node> t;
    const Node e;
    int n, m;
};

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

    int n, q;
    cin >> n >> q;

    SegmentTree st(n);
    for (int i = 0; i < q; i++) {
        int c, x, y;
        cin >> c >> x >> y;

        if (c == 0) {
            st.update(x, { y });
        } else {
            y++;
            cout << st.query(x, y).v << '\n';
        }
    }

    return 0;
}

Measured memory_bytes: 3936
#include <iostream>
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
 
using namespace std;
 
int main()
{
   
   int n;
   cin>>n;
   if(n>=30){
       cout<<"Yes"<<endl;
   }
   else{
       cout<<"No"<<endl;
   }
   
   
   return 0;
}

Measured memory_bytes: 3600
/*
Dont BLUNDER
*/
#include<bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;


 */
#define d long double
#define int long long
#define pii pair<int,int>
#define pb push_back
#define endl '\n'
#define pi acos(-1)

#define init(x,a) memset(x,a,sizeof(x))
#define all(c) c.begin(),c.end()
int const mod1 = 998244353;
int const mod = 1000000007;
#define l first
#define r second
int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ) {stringstream ss; ss << number; return ss.str();}
#define out(x) cout<<#x<<" = "<<" "<<x<<"\n";
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define haha ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// * Using PBDS *
/*typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
               os; */



int modexp(int x, int n) {
	if (n == 0) {
		return 1;
	}
	else if (n & 1) {
		return (modexp((x * x) % mod, n / 2) % mod * x % mod) % mod;
	}
	else {
		return (modexp((x * x) % mod, n / 2) % mod);
	}
}

int modinv(int n)
{
	return modexp(n, mod - 2);
}

int gcd(int a, int b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}
bool comp(pii a, pii b) {
	return a.second < b.second;

}



signed main()
{
	haha
// #ifndef ONLINE_JUDGE

// 	freopen("inp.txt", "r", stdin);

// 	freopen("out1.txt", "w", stdout);
// #endif
	int s = 0;
	int n;
	cin >> n;
	int arr[n];
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	int mx = arr[0];
	for (int i = 1; i < n; i++) {
		mx = max(arr[i], mx);
		s += max(0ll, mx - arr[i]);
	}
	cout << s;



















}

Measured memory_bytes: 5180
#include <iostream>
#include <vector>
#include <map>
#include <unordered_set>

int main(void){

  int n;
  std::cin >> n;
  std::vector<int> a(n+1);
  for(int i=1; i<=n; i++){
    std::cin >> a[i];
  }

  std::unordered_set<int> result;
  for(int i=n; i>=1; i--){
    int count = 0;
    for(int j=i; j<=n; j+=i){
      if(result.find(j) != result.end()) count++;
    }
    if(a[i] != (count%2)) result.insert(i);
  }

  std::cout << result.size() << std::endl;
  if(result.size() != 0){
    for(auto elem: result){
      std::cout << elem << " ";
    }
    std::cout << std::endl;
  }
  return 0;
}


Measured memory_bytes: 7844
#include <bits/stdc++.h>
#define rep(i,j) for (int (i)=0;(i)<(int)(j);++(i))
#define put(i) cout << (i) << endl
using namespace std;
typedef long long ll;
const int mod = 1e9+7;

int main() {
    string s;
    int k;
    cin >> s >> k;

    for (int i=0; i<s.size(); ++i) {
        if (s[i] == 'a') continue;
        else {
            int d='z'-s[i]+1;
            if (d <= k) {
                k -= d;
                s[i] = 'a';
            }
        }
    }

    if (k > 0) {
        k -= 26*(k/26);
        int d=s[s.size()-1]-'a';
        d=(d+k)%26;
        s[s.size()-1]='a'+d;
    }

    cout << s << endl;
}


Measured memory_bytes: 512
#include<stdio.h>

main(){

int a=0;

int W,H,x,y,r=0;

scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

if(x-r>=0&&x+r<=W){

if(y-r>=0&&y+r<=H){

a=1;

}

}

else{

a=0;

}

if(a==1){

printf("Yes\n");

}

else if(a==0){

printf("No\n");

}

return 0;

}

Measured memory_bytes: 584
#include<bits/stdc++.h>
 using namespace std;
int main(){
  int N;
  cin >> N;
  int V[30], C[30], R[30];
  for (int i = 0; i < N; i++) {
    cin >> V[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> C[i];
    R[i] = V[i] - C[i];
  }
  int res = 0;
  for (int i = 0; i < N; i++) {
    if (R[i] > 0) {
      res += R[i];
    }
  }
  cout << res << "\n";
}


Measured memory_bytes: 256
n=int(raw_input())
a=map(int,raw_input().split())

count=0
p=0

def cal():
	global p
	global count
	global a,n
	

	
	while True:
		while p + 1 < len(a) and a[p + 1] == a[p]:
			p += 1
		if p + 1 >= len(a):
			return count + 1
		
		if a[p+1]>a[p]:
			while p+1<len(a) and a[p+1]>=a[p]:
				p+=1
			if p+1>=len(a):
				return count+1
		else:
			while p+1<len(a) and a[p+1]<=a[p]:
				p+=1
			if p+1>=len(a):
				return count+1
		count+=1
		p+=1

print cal()

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

ll solve(int n, ll x){
    if(n==0)return 1;
    ll len=(1LL<<(n+1))-3;
    ll num=(1LL<<n)-1;
    if(x==1)return 0;
    else if(x<=len+1)return solve(n-1,x-1);
    else if(x==len+2)return num+1;
    else if(x<=(len+1)*2)return num+1+solve(n-1,x-len-2);
    else return num*2+1;
}

int main(){
    int n; ll x;
    cin>>n>>x;
    cout<<solve(n,x)<<endl;
    return 0;
}

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

int main() {

    int n, ans = 0, p = 0;
    cin >> n;
    rep(i, n){
        int h;
        cin >> h;
        if(p < h){
            ans += h - p;
        }
            p = h;
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
//(・ω・)
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
using namespace std;
int main(){
    int n,q;
    long long k;
    cin >>  n >> k >> q;
    vector<int> a(q);
    for(int i=0; i<q; i++){
        cin >> a[i];
    }
    vector<long long> ans(n,k-q);
    for(int i=0; i<q; i++){
        ans[a[i]-1]++;
    }
    for(int i=0; i<n; i++){
        if(ans[i]<=0) cout << "No" << endl;
        else cout << "Yes" << endl;
    }
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 200009
#define mod 1000000007
int  n,m,i,j,k,l,t,a,b,arr[10];
vector<int>v,v1,v2;
int main()
{
    scanf("%d %d",&n,&m);
    for(i=0;i<m;i++)
    {
        scanf("%d",&l);
        arr[l]++;
    }
    j=n;
    while(j)
    {
        v1.push_back(j%10);
        j/=10;
    }
    reverse(v1.begin(),v1.end());
    for(i=0;i<10;i++)
    {
        if(!arr[i])
            v.push_back(i);
    }
    sort(v.begin(),v.end());
    n=0;
    for(i=0;i<v1.size();i++)
    {
        if(n)
            v2.push_back(v[0]);
        else
        {
            m=0;
            for(j=0;j<v.size() && m==0;j++)
            {
                if(v[j]>=v1[i]){
                    v2.push_back(v[j]);
                    m=1;
                    if(v[j]>v1[i])
                        n=1;
                }
            }
            if(m==0)
            {
                for(j=i-1;j>=0 && m==0;j--)
                {
                    for(k=0;k<v.size() && m==0;k++)
                    {
                        if(v[k]>v2[j])
                        {
                            n=1;
                            m=1;
                            v2[j]=v[k];
                        }
                    }
                    if(m==0)
                        v2.pop_back();
                }
                if(m==0)
                {
                    for(i=0;i<v.size();i++)
                    {
                        if(v[i]>0)
                        {
                            v2.push_back(v[i]);
                            break;
                        }
                    }
                    for(i=0;i<v1.size();i++)
                        v2.push_back(v[0]);
                    for(i=0;i<v2.size();i++)
                        printf("%d",v2[i]);
                    return 0;
                }
                else
                    i=v2.size()-1;
            }
        }
    }
    for(i=0;i<v2.size();i++)
        printf("%d",v2[i]);
}


Measured memory_bytes: 256
#include <iostream>

long long x;

using namespace std;
long long n, ans, a[500000], cnt[500000], N = 500000;

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (0 <= i - a[i] && i - a[i] < N)
		    ans += cnt[i - a[i]];
		if (0 <= i + a[i] && i + a[i] < N)
		    cnt[i + a[i]]++;
	}
	cout << ans;
}

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

int main() {
    int a,b,c;
    cin>>a>>b>>c;

    if(b-a==c-b){
        cout<<"YES"<<endl;
    }

    else {
        cout<<"NO"<<endl;
    }
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define sz(x) (int)(x).size();
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
int32_t main()
{
	int h=in();int w=in();
	int n=in();
	vector<int> a(n);
	trav(i,a)i=in();
	vector<int> col;
	for(int i=0;i<n;i++)
	{
		while(a[i]--)col.push_back(i+1);
	}
	int cur=0;
	for(int i=0;i<h;i++)
	{
		vector<int> pr;
		for(int i=cur;i<cur+w;i++)pr.push_back(col[i]);
		if(i&1)reverse(all(pr));
		trav(i,pr)cout<<i<<" ";
		cout<<"\n";
		cur+=w;
		
	}
	
}

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

int main() {
	int n, d;
	cin >> n >> d;

	int range = 2*d+1;
	int ans;
	if (n % range == 0) {
		ans = n / range;
	} else {
		ans = n / range + 1;
	}

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

Measured memory_bytes: 256
import java.io.*;

public class Main{
	public static void main(String[] args) throws IOException{
		//
		int[] data = new int[10001];
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
		//StringBuilder output = new StringBuilder();
		for(int i=0; i < 10001; i++){
			data[i] = Integer.parseInt(input.readLine());
			if( data[i] == 0){
				break;
			}
			//output.append("Case ").append(Integer.toString(i+1)).append(": ").append(Integer.toString(data[i])).append("\n");
		}
		for(int i=0; i < 10001; i++){
			if( data[i] == 0){
				break;
			}
			System.out.println("Case "+ (i+1) + ": " + data[i]);
		}
		//System.out.print(output);
		//
	}
}

Measured memory_bytes: 31552
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<ctime>
#include<cstring>
#include<cstdio>
#define IOS ios::sync_with_stdio(false); cin.tie(0); 
using namespace std;
typedef pair<int,int> PII;
const int N=110;
const int INF=0x3f3f3f3f;
int main(){
	IOS;
	//clock_t starttime,endtime;	
	//starttime=clock();
	int L;
	cin>>L;
	double tt=L/3.0;
	printf("%.6f\n",tt*tt*tt);
	//endtime=clock();
	//cout<<(double)(endtime - starttime) / CLOCKS_PER_SEC<<"s"<<endl;
	return 0;
}

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

using namespace std;

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

int main() {
    string s;
    cin >> s;
    rep(i, s.size()){
        if((i+1) % 2 == 0){
            if(s[i] == 'R'){
                cout << "No" << endl;
                return 0;
            }
        }else{
            if(s[i] == 'L'){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
l,r=map(int,input().split())
c=0
M=[]
for i in range(l,r+1):
    M.append(i%2019)
    c+=1
    if c>2019:
        break
n=len(M)
a=2020
for i in range(n-1):
    for j in range(i+1,n):
        a=min(a,M[i]*M[j]%2019)
print(a)

Measured memory_bytes: 40812
import itertools

seq = [int(input()) for i in range(5)]
ans = 10 ** 9

for ss in itertools.permutations(seq):
    t = 0
    for s in ss:
        t = (t - 1) // 10 + 1
        t *= 10
        t += s
    ans = min(ans, t)
    
print(ans)

Measured memory_bytes: 3060
N = int(input())
Ac,Wa,Re,Tle = 0,0,0,0
for i in range(N):
    result = input()
    if result == "AC":
        Ac += 1
    elif result == "WA":
        Wa += 1
    elif result == "RE":
        Re += 1
    else:
        Tle += 1

print("AC x " + str(Ac))
print("WA x " + str(Wa))
print("TLE x " + str(Tle))
print("RE x " + str(Re))

Measured memory_bytes: 9212
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
# 同一の集合の判定
def same(x, y):
    if find(x) == find(y):
        return True
    else:
        return False
# 集合の併合
def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    if par[x] > par[y]:
        x, y = y, x
    par[x] += par[y]
    par[y] = x

# 集合の数
def uCnt(x):
    return -par[find(x)]

N, M = map(int, input().split())
par = [-1 for i in range(N)]

for i in range(M):
    a, b = map(int, input().split())
    unite(a - 1, b - 1)

ans = min(par)
print(-ans)

Measured memory_bytes: 14428
import sys,math,collections,itertools
input = sys.stdin.readline

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

##ノードの数を増やせるだけ増やす##
non_leaf_node = []
tmp = 1
for i in range(0,N+1):
    tmp = tmp -A[i]
    if tmp < 0:#頂点数が0以下になってはいけない
        print(-1)
        exit()
    non_leaf_node.append(tmp)
    tmp *= 2
non_leaf_node[-1]=0
##後ろ側から頂点の最大数を足し上げる##
##頂点数=node[i] = (non_leaf_node[i+1]+A[i+1] または non_leaf_node[i]+leaf[i])+leaf


ans = A[-1]
for i in range(N-1,-1,-1):
    non_leaf_node[i] = min(non_leaf_node[i],non_leaf_node[i+1]+A[i+1])
    ans += non_leaf_node[i]+A[i]
print(ans)


Measured memory_bytes: 673520
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();

		int max = Math.max(A, Math.max(B, C));
		int min = Math.min(A, Math.min(B, C));
		int med = (A+B+C) - max - min;

		int max_min_2 = max - min;
		int max_med_2 = max - med;

		int ans = 0;

		if((max_min_2 % 2 == 0) && (max_med_2 % 2 == 0)) {
			int temp = max_min_2 / 2;
			ans += temp;
			temp = max_med_2 / 2;
			ans += temp;
		}else if((max_min_2 % 2 == 1) && (max_med_2 % 2 == 1)) {
			int temp = max_min_2 / 2;
			ans += temp;
			temp = max_med_2 / 2;
			ans += temp;
			ans += 1;
		}else{
			int temp = max_min_2 / 2;
			ans += temp;
			temp = max_med_2 / 2;
			ans += temp;
			ans += 2;
		}
		System.out.println(ans);
	}

}


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

#define rep(i, n) REP(i, 0, n)
#define REP(i,k,n) for(int i = k; i < n; i++)
#define mmax(start, end) *max_element(start, end)
#define mmin(start, end) *min_element(start, end)
#define argmax max_element
#define argmin min_element
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef pair<int, int> prii;

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

template<class T = ll> T in() {
    T _in;
    cin >> _in;
    return _in;
}

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

    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i+=2) {
        cout << s[i];
    }
    cout << endl;

    return 0;
}


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

int main()
{  
  #ifndef ONLINE_JUDGE
	 freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);

  #endif

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

     long long ans[n];
     ans[0]=0;
     ans[1]=abs(a[0]-a[1]);

     for(int i=2; i<n; i++)
     { long long min =LONG_LONG_MAX;
       
       for(int j=1; j<=k; j++)
       { //cout<<"hi"<<endl; 
       	if( i-j >=0)
       	  { if(ans[i-j]+abs(a[i-j]-a[i]) < min )
       	  	 min=ans[i-j]+abs(a[i-j]-a[i]);
       	  }

       	  else
       	  	 break;
       	}

       //	cout<<min<<endl;
       
        ans[i]=min;
       }
    
    cout<<ans[n-1]<<endl;

 }

Measured memory_bytes: 4672
import java.util.Scanner;
class Main
{
    public static void main(String args[])
    {
	Scanner scan=new Scanner(System.in);
	int n=scan.nextInt();
	for(int i=0;i<n;i++)
	    {
		int a,b,c,tmp;
		a=scan.nextInt();
		b=scan.nextInt();
		c=scan.nextInt();
		if(Math.pow(a,2)+Math.pow(b,2)==Math.pow(c,2) || Math.pow(a,2)+Math.pow(c,2)==Math.pow(b,2) || Math.pow(c,2)+Math.pow(b,2)==Math.pow(a,2))System.out.println("YES");
		else System.out.println("NO");
	    }
    }
}

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

using namespace std;

const int MAXH=11;
const int MAXW=1e3+1;

int h,w,k,sum[MAXH][MAXW]= {0},ans=INT_MAX;
bool s[MAXH][MAXW];
vector<int> border;

inline int getAns() {
	static int tot[MAXH];
	int times=0,j,i,pre,flag;
	memset(tot,0,sizeof tot);
	for(j=1,i; j<=w; ++j) {
		flag=pre=0;
		for(auto &i:border) {
			if(tot[i]+sum[i][j]-sum[pre][j]<=k) {
				tot[i]+=sum[i][j]-sum[pre][j];
				pre=i;
			} else {
				++times;
				flag=1;
				break;
			}
		}
		if(flag) {
			pre=0;
			for(auto &i:border) {
				if(sum[i][j]-sum[pre][j]>k) return INT_MAX;
				tot[i]=sum[i][j]-sum[pre][j];
				pre=i;
			}
		}
	}
	return border.size()-1+times;
}

inline void dfs(const int &dep,const int &h) {
	if(dep>h) {
		ans=min(getAns(),ans);
		return ;
	}
	border.push_back(dep);
	dfs(dep+1,h);
	border.erase(border.end()-1,border.end());
	if(dep!=h) dfs(dep+1,h);
	return ;
}

int main() {
	cin>>h>>w>>k;
	cin.ignore();
	for(int i=1,j; i<=h; ++i) {
		char c;
		for(j=1; j<=w; ++j) {
			cin>>c;
			s[i][j]=c-48;
			sum[i][j]=sum[i-1][j]+s[i][j];
		}
	}
	dfs(1,h);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i = x; i < n; i++)
#define MAX 100
#define INF 1000000001

int n,m;
bool visited[50];
// char X[100][100];
// int dp[1000000001];
vector<int> adj[50];
pair<int,int> e[50];

void dfs(int s, int a, int b) {
    visited[s] = true;
    for (auto u: adj[s]) {
        if ((s == a && u == b) || (s == b && u == a)) continue;
        if (visited[u]) continue;
        dfs(u,a,b);
    }
    // return;
}

int main(void){
    cin >> n >> m;
    REP(i,0,m) {
        int a,b;
        cin >> a >> b;
        a--;b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
        e[i].first = a;
        e[i].second = b;
    }
    
    // REP(i,0,m)
    int ans = 0;
    REP(i,0,m) {
        REP(j,0,n) visited[j] = false;
        
        dfs(0, e[i].first, e[i].second);
        
        // REP(j,0,n) {
        //     if (!visited[j]) {
        //         ans++;
        //         break;
        //     }
        // }
        bool bridge = false;
        for (int j = 0; j < n; ++j) if (visited[j] == false) bridge = true;
        if (bridge) ans += 1;
        // cout << i << endl;
        
    }

    cout << ans << endl;
    

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,w) for (int i = 0;i < (w); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int INF = 1e9;

int main(){
  string s;cin >> s;
  int ans = 0;
  rep(i,s.size()){
    if(i%2 == 0){
      if(s[i] == 'p') ans--;
    }else{
      if(s[i] == 'g') ans++;
    }
  }
  cout << ans << endl;

}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
#define N 1000000007
using namespace std;

long long ans = 1, n;

int main() {
  cin >> n;
  for(long long i = 1; i <= n; ++i) {
    ans *= i;
    ans %= N;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int mod = 1e9 + 7;

//-------------------------<MATH>-------------------------------------------------------//
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll expo(ll base,ll pow){ll ans = 1;
   while(pow!=0){if(pow&1==1){ans = ans*base;ans = ans%mod;}
   base *= base;base%=mod;pow/=2;}return ans;}
ll inv(ll x){return expo(x,mod-2);}
ll mult_mod(ll a , ll b){a = a%mod; b = b%mod;ll c = (a * b)%mod;return c;}
ll add_mod(ll a , ll b){a = (a + 100*1LL*mod)%mod;b = (b + 100*1LL*mod)%mod;ll c = (a + b)%mod;return c;}
ll fac[(int)(1e3 + 5)] , inv_fac[(int)(1e3 + 5)];
void precomp_factorial(int M){fac[0] = 1;for(int i = 1 ; i <= M ; i++) fac[i] = mult_mod(i , fac[i - 1]);
    inv_fac[M] = inv(fac[M]);for(int i = M - 1 ; i >= 0 ; i--) inv_fac[i] = mult_mod(i + 1 , inv_fac[i + 1]);}
ll nCk(ll n , ll k){ll ans = fac[n];ans = mult_mod(ans , inv_fac[n - k]);ans = mult_mod(ans , inv_fac[k]);return ans;}
int lo[(int)(1e3 + 6)];
void sieve(int M){for(int i = 2 ; i < M ; i++){ if(lo[i]) continue; for(int j = i ; j < M ; j += i)lo[j] = i;}}
int max_expo_prime_n_fac(ll N , int prime){int ress = 0;while(N){ress += (N/prime);N /= prime;}return ress;}
//-------------------------</MATH>-------------------------------------------------------//

//-------------------------<STRING>-------------------------------------------------------//
string get_prefix(string x , int MAX){return x.substr(0 , min((int)x.size() , MAX));}
string get_suffix(string x,int MAX){int dn=1;for(int i=x.size()-1;i>=0;i--){if(dn==MAX)return x.substr(i);dn++;}return x;}
string convert_to_binary(int x,int len) {string ans=""; while(x){if(x&1){ans='1'+ans;}
    else{ans ='0'+ans;}x/=2;}int k = ans.size();while(k < len){ans = '0' + ans;k++;}return ans;}
//-------------------------</STRING>-------------------------------------------------------//

ull llrand() {ull r = 0;for(int i = 0; i < 5; ++i){r = (r << 15)|(rand() & 0x7FFF);}return r & 0xFFFFFFFFFFFFFFFFULL;}
int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1};    // last 4 diagonal
int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};
/*---------------------------------------------------------------------------------------------------------------------*/

int arr[123456][10], dp[123456][10];

int main(){

   int n;
   cin >> n;
   for(int i = 0; i < 2; i++){
       for(int j = 0; j < n; j++) cin >> arr[j][i];
   }

   for(int i = 0; i < n; i++){
       for(int j = 0; j < 2; j++){
           int n1 = 0;
           if(i){
              n1 = dp[i-1][j];
           }
           if(j) n1 = max(dp[i][j-1], n1);
           dp[i][j] = n1+arr[i][j];
       }
   }
   cout << dp[n-1][1];
}


Measured memory_bytes: 2304
#include<iostream>
using namespace std;
 
int gcd(int a, int b)
{
    if (b == 0) return a;
 
    return gcd(b, a % b); 
}
int main(int, char**)
{
    int n;
 
    cin >> n;
 
    long long result = 0;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            for (int k = 1; k <= n; k++)
                result += gcd(gcd(i, j), k);
 
    cout << result << endl;
 
    return 0;
}

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

long gcd(long x, long y) { return y ? gcd(y, x % y) : x; }
long lcm(long x, long y) { return x / gcd(x, y) * y; }

int main() {
  int N;
  cin >> N;
  long ans = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      for (int k = 1; k <= N; k++) {
        ans += gcd(gcd(i, j), k);
      }
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 3636
//解説見た
//DPでいけるのか......................................................
#include <bits/stdc++.h>
typedef long long lint;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

int main() {
    lint R,C,K; cin >> R >> C >> K;
    vector<lint> r(K),c(K),v(K);
    map<pair<int,int>, int> field;
    rep(i,K) {
        cin >> r[i] >> c[i] >> v[i];
        field[make_pair(--r[i],--c[i])] = v[i];
    }
    vector<vector<vector<lint>>> dp(4, vector<vector<lint>>(R+1,vector<lint>(C+1,0)));
    for (int y=0; y<R; y++) {
        for (int x=0; x<C; x++) {
            lint value = 0;
            auto pos = make_pair(y,x);
            if (field.find(pos) != field.end()) value = field[pos];
            //rep(i,3) {
            //    dp[i][y][x+1] = max(dp[i][y][x+1],dp[i][y][x]);
            //    dp[i+1][y][x+1] = max(dp[i+1][y][x+1], dp[i][y][x] + value);
            //}
            for (int i=3; i>=1; i--) {
                dp[i][y][x] = max(dp[i][y][x], dp[i-1][y][x] + value);
                dp[i][y][x+1] = max(dp[i][y][x+1], dp[i][y][x]);
            }
            lint hi = 0;
            rep(i,4) {
                hi = max(hi, dp[i][y][x]);
            }
            dp[0][y+1][x] = hi;
        }
    }
    //rep(i,4) {
    //    rep(y,R+1) {
    //        rep(x,C+1) {
    //            cout << dp[i][y][x] << ' ';
    //        }
    //        cout << endl;
    //    }
    //    cout << endl << endl; 
    //}
    cout << dp[0][R][C-1] << endl;
}

Measured memory_bytes: 372644
h,w,d = map(int,input().split())

al_l = []
for _ in range(h):
    al = list(map(int,input().split()))
    al_l.append(al)

from collections import defaultdict
dic = {}
for i in range(h):
    for j in range(w):
        dic[al_l[i][j]] = (i,j)

path = {}
for i in range(1,d+1):
    tmp = 0
    while True:
        path[i] = tmp
        i += d
        if i > h*w:
            break
        x1, y1 = dic[i]
        x2, y2 = dic[i-d]
        tmp += abs(x1-x2) + abs(y2-y1)

q = int(input())
for _ in range(q):
    l, r = map(int,input().split())
    print(path[r] - path[l])
    
    

Measured memory_bytes: 37220
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int MAXN=2e5+5;
int read()
{
    int s=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
    return s*f;
}
ll arr[MAXN];
int main()
{
    int n;
    while(cin>>n)
    {
        for(int i=1;i<=n;i++)cin>>arr[i];
        int p=1;
        int num=0;
        for(int i=1;i<=n;i++)
        {
            if(arr[i]==p)
            {
                p++;
                num++;
            }
        }
        if(num==0)cout<<-1<<endl;
        else cout<<n-num<<endl;
    }
    return 0;
}


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

int main(int argc, char *argv[]) {
	int n,temp,res;
	cin >> n;
	int v[n],c[n];
	for(int i = 0; i<n; i++) cin >> v[i];
	for(int i = 0; i<n; i++) cin >> c[i];

	
	for(int i = 0; i<n; i++){
		if(c[i] < v[i]){
			res += v[i] - c[i];
		}
	}

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

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

int main() {

  ll n;
  cin>>n;
  cout<<n+(n*n)+(n*n*n)<<endl;
	return 0;
}

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

int n, ans;

int main() {
  cin >> n;
  vector<int> a(n);
  rep (i, n) {
    cin >> a[i];
  }
  ans = 0;
  rep (i, n) {
    if (a[a[i]-1] == i+1) ans++;
  }
  cout << ans/2 << endl;
  return 0;
}


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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
typedef vector<vector<int>> VV;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define PRALL(a) a.begin(),a.end(),greater<pair<int,int>>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/
ll gcd(ll a,ll b){
    while(b!=0) {
        int t=b;
        b=a%b;
        a=t;
    }
    return a;
}
int main(){
    int n;cin>>n;
    V a(n);
    rep(i,n)cin>>a[i];
    V left(n+1,0),right(n+1,0);
    rep(i,n)left[i+1]=gcd(left[i],a[i]);
    rrep(i,n)right[i]=gcd(right[i+1],a[i]);
    ll ans=0;
    rep(i,n){
        int l=left[i];
        int r=right[i+1];
        ans=max(ans,gcd(l,r));
    }
    cout<<ans<<endl;
}


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

using namespace std;

int main() {
  long long n;
  scanf("%lld", &n);
  vector<long long> a(n+2);
  a[0] = 0; a[n+1] = 0;
  for (int i=1; i<n+1; i++) scanf("%lld", &a[i]);

  long long sum = 0;
  for (int i=1; i<n+2; i++) sum += abs(a[i] - a[i-1]);

  for (int i=1; i<n+1; i++) {
    printf("%lld\n", sum + abs(a[i-1]-a[i+1]) - (abs(a[i-1]-a[i]) + abs(a[i]-a[i+1])));
  }
}


Measured memory_bytes: 2048
F =->{_1.split.map &:to_i}
D = gets.to_i
C,*S = (0..D).map{F[gets]}
d,*L = [D]*27
A = []
until 0 > d-=1
  s = S[d]
  i,m = -1, -(1<<60)
  26.times {|j|
    n = s[j] - C[j]*(L[j]-d)
    (i=j;m=n) if m<n
  }
  L[i] = d
  A << i
end
A.reverse_each {p _1+1}

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

int main() {
  int a, b;
  cin >> a >> b;

  string as;
  for (int i = 0; i < b; i++) {
    as += to_string(a);
  }
  string bs;
  for (int i = 0; i < a; i++) {
    bs += to_string(b);
  }
  if (as < bs) {
    cout << as << endl;
  } else {
    cout << bs << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<functional>
#include<vector>
#include<map>

using namespace std;
#define endl '\n'
#define pb push_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define REP(i,n) for(int i = 0;i < (n);i++)
#define FOR(i,a,b) for(int i = (a);i <= (b);i++)
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> vii;

template <class T = int> T in() { T x; cin >> x; return (x); }
template <class T = int> void out(T x) { cout << (x) << endl; }

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

ll bpow(int n) {
	ll x = 1;
	for (int i = 1; i <= n; i++) {
		x *= 2;
	}
	return x;
}

void solve() {

	int N, M;

	cin >> N >> M;

	int ans;

	for (int i = M / N; i >=1; i--) {
		if (M % i == 0) {
			if (M / i >= N) {
				ans = i;
				break;
			}
		}
	}

	out(ans);

	return;

}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;

}

Measured memory_bytes: 256
using System;

class ABC_129_A
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int P = int.Parse(input[0]);
        int Q = int.Parse(input[1]);
        int R = int.Parse(input[2]);

        int ans = (Math.Min(Math.Min(P + Q, Q + R),P + R));

        Console.WriteLine(ans);
    }
}

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

string s;
int A[300005], B[300005];

signed main(){
  
  int c;
  cin>>c;
  
  cin>>s;
  
  for(int i=0;i<(int)s.size();i++){
    if( s[i] == 'W' ) A[i] = 1;
    if( s[i] == 'E' ) B[i] = 1;
  }
  
  for(int i=1;i<(int)s.size();i++) A[i] += A[i-1];
  
  for(int i=(int)s.size()-2;i>=0;i--) B[i] += B[i+1];
  
  int ans = 300005;
  
  for(int i=0;i<(int)s.size();i++){
    
    int cnt = 0;
    
    if( i != 0 ) cnt += A[i-1];
    
    if( i != (int)s.size() - 1 ) cnt += B[i+1];

    ans = min( ans, cnt );
    
  }
  
  cout<<ans<<endl;
  
  return 0;
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int, int> pii;
const int mod = (int)1e9 + 7;

int h,w;
vector<string> vs;
int dr[]={0,1,0,-1,0};


void rec2(int y,int x, int py, int px){
	if(y==h-1 && x==w-1){ return;}
	rep(i,2){
		int ny=y+dr[i],  nx=x+dr[i+1];
		if(py==ny && nx == px) continue;
		if(ny<0 || ny>=h || nx<0 || nx>=w) continue;
		if(vs[ny][nx] == '#' && i<2){
			vs[ny][nx] = '@';
			rec2(ny, nx, y, x);
			break;
		}
	}
	
}


int main()
{

	//cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> h >>w;
	vs.resize(h);
	rep(i,h) cin >> vs[i];
	vs[0][0]='@';
	rec2(0,0,-1,-1);
	//for(auto x :vs) cout<<x <<endl;
	rep(i,h)rep(j,w) if(vs[i][j]=='#'){puts("Impossible");return 0;}
	puts("Possible");
	return 0;
}


Measured memory_bytes: 256
# coding: utf-8
N=int(input())
#A,B=map(int, input().split())
#List=list(map(int, input().split()))
SList=[(input()) for i in range(N)]
print("AC x",SList.count("AC"))
print("WA x",SList.count("WA"))
print("TLE x",SList.count("TLE"))
print("RE x",SList.count("RE"))

Measured memory_bytes: 16152