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

public class Main {
	private final static int WHITE=0;
	private final static int BLACK=1;
	private static int[][] mat;
	private static int n;

	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int i,j;
		n=sc.nextInt();
		mat = new int[n][n];
		for(i=0;i<n;i++){
			for (j=0;j<n;j++){
				mat[i][j]=sc.nextInt();
				if(mat[i][j]==-1) mat[i][j]=Integer.MAX_VALUE;
			}
		}
		System.out.println(Prim());
	}

	public static int Prim(){
		int sum=0;
		int u,min,i,j;
		int[] d=new int[100];
		int[] p=new int[100];
		int[] color=new int[100];
		for(i=0;i<n;i++){
			d[i]=Integer.MAX_VALUE;
			p[i]=-1;
			color[i]=WHITE;
		}
		d[0]=0;
		while(true){
			min=Integer.MAX_VALUE;
			u=-1;
			for(i=0;i<n;i++){
				if(min>d[i] && color[i]!=BLACK){
					u=i;
					min=d[i];
				}
			}
			if(u==-1) break;
			color[u]=BLACK;
			for(j=0;j<n;j++){
				if(color[j]!=BLACK && mat[u][j]!=Integer.MAX_VALUE){
					if(d[j]>mat[u][j]){
						d[j]=mat[u][j];
						p[j]=u;
					}
				}
			}
		}
		for(i=0;i<n;i++) if(p[i]!=-1) sum+=mat[i][p[i]];
		return sum;
	}
}

Measured memory_bytes: 31644
//                             ¯\_(ツ)_/¯   
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mma,ava,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(),(a).end()
#define ll long long
 
 
void file(){
	#ifndef ONLINE_JUDGE
    	freopen("in.txt", "r", stdin);
	#endif
}
int tc;
 
const int N=2e5+5,M=2e6+5,MOD=1e9+7,OO=1e9;
std::vector<int> c(26);
int D;
std::vector<int>last(26);
std::vector<vector<int>>s;
int go(int indx,int S,int depth){
	if(indx == D || depth == 3)return S;
	
	for(int j=0;j<26;j++){
		S-=c[j]*(indx-last[j]);
	}
	int mx = 0;
	for(int j=0;j<26;j++){
		int takeback = s[indx][j] + c[j]*(indx-last[j]);
		int l = last[j];
		last[j] = indx;
		mx = max(mx,go(indx+1,S+takeback,depth+1));
		last[j] = l;
	}
	return mx;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//file();
	scanf("%d",&D);
	
	for(int i=0;i<26;i++)scanf("%d",&c[i]);
	s = vector<vector<int>>(D,vector<int>(26));
	for(int i = 0;i<D;i++){
		for(int j=0;j<26;j++){
			scanf("%d",&s[i][j]);
		}
	}
	int S = 0;
	
	for(int i=0;i<D;i++){
		for(int j=0;j<26;j++){
			S-=c[j]*(i-last[j]);
		}
		int who = 1;
		int mx = -1e9;
		int take = 0;
		for(int j=0;j<26;j++){
			int takeback = s[i][j] + c[j]*(i-last[j]);
			int l = last[j];
			last[j] = i;
			int wa = go(i+1,S+takeback,0);
			last[j] = l;
			if(mx < wa){
				mx = wa;
				take = takeback;
				who = j+1;
			}
		}
		last[who-1] = i;
		S+= take;
		printf("%d\n",who );
	}
}

Measured memory_bytes: 3864
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
typedef long long ll;
const ll mod = (1e9 + 7);
int n;
ll c[N],p2[N],err[N];
int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n; for (int i = 1; i <= n; ++i) cin >> c[i];
	sort(c + 1, c + n + 1);
	p2[0] = 1LL; for (int i = 1; i <= n; ++i) p2[i] = (p2[i - 1] * 2) % mod;
	err[0] = 0; err[1] = 2LL;
	for (int i = 2; i <= n; ++i)
		err[i] = ((err[i - 1] * 4) % mod + ((p2[i - 1] * p2[i - 1]) % mod) * 2) % mod;
	ll ans = 0LL;
	for (int i = 1; i <= n; ++i) {
		ll tmpp = (p2[i - 1] * p2[i - 1]) % mod;
		ll tmp = err[n - i]*2 + p2[n - i] * p2[n - i] * 2; tmp %= mod;
		tmp *= c[i]; tmp %= mod;
		ans += tmpp*tmp; ans %= mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 4992
#include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

// author:Swastik Banerjee

using namespace std;

typedef long long ll;
#define MOD 1000000007

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


  ll x, y;
  cin >> x >> y;
  if (x == 1 || y == 1)
    cout << 1;
  else {
    x *= y;

    ll ans = ceil((long double)(x) / (long double)(2));

    cout << ans;
  }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int a,b,c,result = 0;
	int d[3] ={0};
	scanf("%d %d %d",&a,&b,&c);
	if(a < b){
		int tmp = a;
		a = b;
		b = tmp;
	}else if(a < c){
		int tmp = a;
		a = c;
		c = tmp;
	}
	d[0] = a%2;
	d[1] = b%2;
	d[2] = c%2;
	if(d[0]==d[1]&&d[0]==d[2]){
		result = (2*a-b-c)/2;
	}else{
		result += 1;
		if(d[0]==d[1]){
			c--;
		}else if(d[0]==d[2]){
			b--;
		}else{
			a--;
		}
		result += (2*a-b-c)/2;
	}
	printf("%d\n",result);
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main()
{
  long N;
  cin >> N;
  string ans = "";
  int count = 0;
  long d = 2;
  while (N != 0)
  {
    if (N % d != 0)
    {
      ans = "1" + ans;
      if ((N < 0 && count % 2 == 0) || (0 < N && count % 2 == 1))
        N += N % d;
      else if ((N < 0 && count % 2 == 1) || (0 < N && count % 2 == 0))
        N -= N % d;
    }
    else
    {
      ans = "0" + ans;
    }
    count++;
    d *= 2;
  }
  if (ans == "")
    ans = "0";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define N 1000005
using namespace std;

int n, var[N], coc[N];
vector < int > g[N];
queue < int > q;

void dfs(int node, int par){
	int say = 0;
	for(int i = 0; i < g[node].size(); i++)
		if(g[node][i] != par){
			dfs(g[node][i], node);
			say += var[g[node][i]];
		}
	if(say > 1){
		puts("First");
		exit(0);
	}
	var[node] = !say;
}

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%d",&n);
	for(int i = 1; i < n; i++){
		int u, v;
		scanf("%d %d",&u ,&v);
		g[u].pb(v);
		g[v].pb(u);
		coc[u]++;
		coc[v]++;
	}
	if(n == 2)
		return puts("Second"), 0;
	for(int i = 1; i <= n; i++)
		if(coc[i] > 1){
			dfs(i, 0);
			if(var[i])
				return puts("First"), 0;
			break;
		}
	puts("Second");
	return 0;
}

Measured memory_bytes: 30080
#include <algorithm>
#include <bitset>
#include <boost/rational.hpp>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

  string buf;
  cout << 0 << endl;
  cin >> buf;
  if (buf[0] == 'V') {
    return 0;
  }

  char ls = buf[0], us = buf[0];
  int lb = 0, ub = N;
  rep(i, 19) {
    const int mid = (lb + ub) / 2;
    cout << mid << endl;
    string buf;
    cin >> buf;
    if (buf[0] == 'V') {
      break;
    }

    const int len = mid - lb + 1;
    if ((len % 2 == 0) == (buf[0] == ls)) {
      ub = mid;
      us = buf[0];
    } else {
      lb = mid;
      ls = buf[0];
    }
  }

  return 0;
}


Measured memory_bytes: 3784
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
#define pb emplace_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos(-1))
#define MAXN (300006)
#define MAXK 26
#define MAXX 15000006
#define ll long long int 
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < ee; ++ii)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph emplace
#define btinpct(x) __builtin_popcountll(x)
#define p2(x) (1LL<<(x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
ll n,k;
ld ans;
ll tryy(ll x, ll k){
	ll times=0;
	while(x<k){
		times++;
		x*=2;
	}
	return times;
}
ld qexp(ld x, ll e) {
	if(e==0)return 1;
	ld half=qexp(x,e/2);
	half*=half;
	if(e&1)half*=x;
	return half;
}
int main()
{
	FAST
	cin>>n>>k; cout<<setprecision(18)<<fixed;
	FOR(i,1,n+1){
		if(i>=k){
			ans+=(1/(ld)n);
			continue;
		}
		ll times=tryy(i,k);
		ans+=(1/(ld)n)*qexp((ld)0.5,times);
	}
	cout<<ans;
}



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;

int main() {
  int k, x;
  cin >> k >> x;
  for(int i = x - k + 1; i <= x + k - 1; i++){
    cout << i << " ";
  }
  cout << endl;
  return 0;
}




Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]

class Util():
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)

def main():
    S = cin.string()
    print(min(S.count("0"),S.count("1")) * 2)
    return

if __name__ == "__main__":
    main()


Measured memory_bytes: 39280
if __name__ == '__main__':
    l, r = map(int, input().split())
    if l + 2019 <= r:
        print(0)
        exit()
    m = 2019
    for i in range(l, r):
        res_i = i % 2019
        for j in range(l + 1, r + 1):
            res_j = j % 2019
            res = (res_i * res_j) % 2019
            if m > res:
                m = res
    print(m)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<long long int> x(n);
	vector<long long int> y(n);
	vector<long long int> z(n);

	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> z[i];
	}

	long long int ans = 0;

	for (int i = 0; i < 8; i++) {
		long long int a[3];
		for (int j = 0; j < 3; j++) {
			if (((1 << j)&i) != 0) {
				a[j] = 1;
			}
			else {
				a[j] = -1;
			}
		}
		vector<long long int> aa(n);
		for (int j = 0; j < n; j++) {
			aa[j] = x[j] * a[0] + y[j] * a[1] + z[j] * a[2];
		}
		sort(aa.begin(), aa.end(), greater<long long int>());
		long long int ka = 0;
		for (int j = 0; j < m; j++) {
			ka += aa[j];
		}

		ans = max(ans, ka);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,k,i,s;
  cin >> n >> k;
  i=0,s=0;
    while(i<n){
      int x_i;
      cin >> x_i;
      if(2*x_i<2*(k-x_i)) s +=2*x_i;
      else s +=2*(k-x_i);
     i++;
    } 
  cout << s << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using uint = unsigned int;
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
// #define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif

template <class T>
struct SegTreeT {
    SegTreeT *l, *r;
    int left, right;
    T value = 0;
    SegTreeT(vector<T>& data):SegTreeT(0, data.size() - 1, data){ }
    SegTreeT(int st, int lt, vector<T>& data): left(st), right(lt){
        if(left == right){
            l = r = nullptr;
            value = data[left];
        }else{
            l = new SegTreeT(left, (right - left) / 2 + left, data);
            r = new SegTreeT((right - left) / 2 + left + 1, right, data);
        }
    }
    void add(int st, int lt, T val){
        if(right < st || lt < left){ return; }
        if(st <= left && right <= lt){
            value += val;
        }else{
            l -> add(st, lt, val);
            r -> add(st, lt, val);
        }
    }
	T getVal(int idx){
        if(right < idx || idx < left){ return 0; }
        return value + (l ? l->getVal(idx) + r->getVal(idx) : 0);
	}
};
using SegTree = SegTreeT<int>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    vector<vector<int>> cs(255);
    for(size_t i = 0; i < s.size(); i++){
        cs[s[i]].push_back(i);
    }
    int r = s.size() - 1;
    int n = s.size();
    vector<int> v(n);
    iota(v.begin(), v.end(), 0);
    SegTree st(v);
    vector<int> is(255);
    int odds = 0;
    ll ans = 0;
    for(int i = 0; i < n; i++){
        char c = s[i];
        int i1 = cs[c][is[c]], i2 = cs[c][cs[c].size() - 1 - is[c]];
        int p1 = st.getVal(i1), p2 = st.getVal(i2);
        if(i1 < i2){
            ans += abs(p1 - odds - (r - p2));
            st.add(i2 + 1, r, -1);
            // printd(c, i, p1, p2, abs(p1 - (r - p2)));
        }else if(i1 == i2){
            odds++;
            if(odds > 1){
                cout << -1 << '\n';
                return 0;
            }
            // if(p1 < n / 2){
                ans += abs(p1 - n / 2);
                // printd(c, i, p1, (int)s.size() / 2);
            // }
        }
        is[c]++;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 20860
import java.util.Scanner;

public class Main {
	static double dx[]=new double[19];
	static double dy[]=new double[19];
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		double x[]=new double[20];
		double y[]=new double[20];
		
		int i,k=0;
		double sum=0;
		while(sc.hasNext()){
			String str[]=sc.next().split(",");
			x[k]=Double.parseDouble(str[0]);
			y[k]=Double.parseDouble(str[1]);
			k++;
		}
		for(i=1;i<k;i++){
			dx[i-1]=x[i]-x[0];
			dy[i-1]=y[i]-y[0];
		}
		for(i=0;i+1<k-1;i++){
			sum+=area(dx[i],dy[i],dx[i+1],dy[i+1]);
		}
		System.out.printf("%.6f\n",sum);
	}
	public static double area(double a,double b,double c,double d){
		double s=a*d-b*c;
		if(s<0) s=s*(-1);
		return s/2;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <cmath>

using lli=long long int;

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

  std::vector<lli> s_arr(N);
  for(int i = 0; i < N; i++){
    std::cin >> s_arr[i];
  }

  lli score_max = -1;
  for(int nforward = 1; nforward < N; nforward++){
    lli score = s_arr[N-1];
    lli score_n = score;
    int nstep = 0;
    while(true){
      nstep++;
      int a = N-1-nforward*nstep;
      if(a%nforward==0 && 2*a<=N-1) break;
      if(a<nforward) break;
      score += s_arr[nstep*nforward]+s_arr[a];
      score_n = std::max(score_n, score);
    }
    score_max = std::max(score_max, score_n);
  }

  std::cout << score_max << std::endl;

  return 0;
}



Measured memory_bytes: 1152
#include <stdio.h>
#include <stdlib.h>

#ifdef TEST
struct test {
    int ans;
} td[] = {
    {},
};
#endif

void
solver(int k, int n, int *a)
{
    int i;
    int min_l = k;
    int l;

    min_l = a[n - 1] - a[0];
    for(i = 1; i < n; i++) {
        l = a[i - 1] + k - a[i];
        //        printf("%d; %d %d %d\n", i, l, a[i - 1], a[i]);
        if(min_l > l)
            min_l = l;
    }
    printf("%d\n", min_l);
}

int
main(int argc, char *argv[])
{
#ifdef TEST
    int tt;
    for(tt = 0; tt < sizeof(td) / sizeof(struct test); tt++) {
        solver();
        printf("%d\n", td[tt].ans);
    }
#endif
    int K, N;
    int A[1000000];
    int i;

    scanf("%d%d", &K, &N);
    for(i = 0; i < N; i++)
        scanf("%d", A + i);
    solver(K, N, A);
    return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define N 1401
using namespace std;
int mp[N][N];
int h,w;

struct dat{int h,i;};

int calc(int A[]){
  stack <dat> S;
  int res = 0;
  for(int i=0;i<=w;i++){
    int h = A[i];
    if(S.empty() || S.top().h < h) S.push((dat){h,i});
    else if(S.top().h > h){
      int ni = i;
      while(!S.empty() && S.top().h > h){
        dat t = S.top(); S.pop();
        ni = t.i;
        int area = (i - t.i) * t.h;
        res = max(res,area);
      }
      res = max(res,(i-ni)*h);
      S.push((dat){h,ni});
    }
  }
  return res;
}

int main(){

  cin>>h>>w;
  
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)cin>>mp[i][j],mp[i][j]=!mp[i][j];
  
  for(int j=0;j<w;j++)
    for(int i=1;i<h;i++)if(mp[i][j]) mp[i][j] = mp[i-1][j]+1;


  //cout<<endl;for(int i=0;i<h;i++){for(int j=0;j<w;j++)cout<<mp[i][j]<<" ";cout<<endl;}
  int ans = 0;
  for(int i=0;i<h;i++)ans = max(ans,calc(mp[i]));
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 10716
a,b,k=map(int,input().split())

for i in range(1,k+1):
    if i%2:
        if a%2:
            a-=1
        a//=2
        b+=a
    else:
        if b%2:
            b-=1
        b//=2
        a+=b

print(a,b)

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

const int MAXN = 60000;

bool prime[MAXN] = {true, true};

int main()
{
  for (int i = 2; i * i < MAXN; i++){
    for (int j = i * i; j < MAXN; j += i){
      prime[j] = true;
    }
  }

  int n;
  
  while (~scanf("%d", &n)){
    for (int i = n - 1; i >= 2; i--){
      if (!prime[i]){
        printf("%d ", i);
        break;
      }
    }
    for (int i = n + 1; i < MAXN; i++){
      if (!prime[i]){
        printf("%d\n", i);
        break;
      }
    }
  }

  return (0);
}

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

int main(){
  string a;
  cin >> a;
  if(a=="ABC"){
  cout << "ARC" << endl;
  }else{cout << "ABC" << endl;}
  return 0;
}

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

typedef struct{
	int J,Y;
	string mem;
}KG;

int main(){
	
	KG kg;
	kg.J=kg.Y=0;
	kg.mem="";
	
	stack<KG>S;
	vector<KG>V;
	S.push(kg);
	while(!S.empty()){
		kg=S.top();
		S.pop();
		if(kg.J==5 && kg.Y==5){
			V.push_back(kg);
			continue;
		}
		if(kg.J==5 && kg.Y<=3){
			V.push_back(kg);
			continue;
		}
		if(kg.J<=3 && kg.Y==5){
			V.push_back(kg);
			continue;
		}
		if(kg.J==6 && kg.Y==4){
			V.push_back(kg);
			continue;
		}
		if(kg.J==4 && kg.Y==6){
			V.push_back(kg);
			continue;
		}
		V.push_back(kg);
		KG tmp=kg;
		tmp.J++;
		tmp.mem+="A";
		S.push(tmp);
		kg.Y++;
		kg.mem+="B";
		S.push(kg);
		
	}
	int j,y;
	cin>>j>>y;
	vector<string>A;
	for(int i=0;i<V.size();i++){
		if(V[i].J==j && V[i].Y==y)A.push_back(V[i].mem);
	}
	sort(A.begin(),A.end());
	for(int i=0;i<A.size();i++)cout<<A[i]<<endl;
	
	return 0;
}


Measured memory_bytes: 1276
import java.io.*;
import java.nio.CharBuffer;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        int n = scanner.nextInt();
        int[] x = new int[n];
        int[] gcdL = new int[n];
        int[] gcdR = new int[n];
        for (int i = 0; i < n; ++i)
            x[i] = scanner.nextInt();
        gcdL[0] = x[0];
        for (int i = 1; i < n; ++i)
            gcdL[i] = gcd(x[i], gcdL[i - 1]);
        gcdR[n - 1] = x[n - 1];
        for (int i = n - 2; i >= 0; --i)
            gcdR[i] = gcd(x[i], gcdR[i + 1]);
        int ans = gcdR[1];
        ans = Integer.max(ans, gcdL[n - 2]);
        for (int i = 1; i < n - 1; ++i)
            ans = Integer.max(ans, gcd(gcdL[i - 1], gcdR[i + 1]));
        writer.println(ans);
        writer.close();
    }

    private static int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }


        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

        int nextInt() {
            return Integer.valueOf(next());
        }

        long nextLong() {
            return Long.valueOf(next());
        }

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

Measured memory_bytes: 42300
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vint a(3);
    REP(i,3) cin >> a[i];
    sort(ALL(a));
    if(a[0]!=a[1]){
        cout << a[0] << endl;
    }else{
        cout << a[2] << endl;
    }

    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

const int INF=1e18;
const int MOD=998244353;

void add(int &x,int y){
    x+=y;
    x%=MOD;
}

int n,s;
int a[3001],dp[3001][3001][3];
signed main(){
    cin>>n>>s;
    REP(i,n)cin>>a[i];
    dp[0][0][0]=1;
    REP(i,n){
        REP(j,s+1){
            add(dp[i+1][j][0],dp[i][j][0]);
            add(dp[i+1][j][1],dp[i][j][0]+dp[i][j][1]);
            add(dp[i+1][j][2],dp[i][j][0]+dp[i][j][1]+dp[i][j][2]);
            if(j-a[i]>-1){
                add(dp[i+1][j][1],dp[i][j-a[i]][0]+dp[i][j-a[i]][1]);
                add(dp[i+1][j][2],dp[i][j-a[i]][0]+dp[i][j-a[i]][1]);
            }
        }
    }
    cout<<dp[n][s][2]<<endl;
}

Measured memory_bytes: 211328
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int T = sc.nextInt();
		int cc = 1001;
		
		for(int i = 0; i < N; i++){
			int c = sc.nextInt();
			int t = sc.nextInt();
			if(t > T) continue;
			if(c < cc) cc = c;
		}
		
      	if(cc == 1001) System.out.println("TLE");
		else System.out.println(cc);
	}
}

Measured memory_bytes: 23124
#include <cstdio>
#include <vector>
using namespace std;
int main() {
	int n,num;
	while (scanf("%d",&n)&&n!=0) {
		vector<int> ice(10,0);
		for (int i=0; i<n; i++) {
			scanf("%d",&num);
			ice[num]++;
		}
		for (int i=0; i<10; i++) {
			if (ice[i]==0) {
				printf("-");
			} else {
				for (int j=0; j<ice[i]; j++) printf("*");
			}
			printf("\n");
		}
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <cctype>
#include <map>
#include <set>
#include <bitset>
#include <utility> 
using namespace std;

int main() {
    int N; cin >> N;
    string S; cin >> S;
    int right_w = count(S.begin(),S.end(),'.');
    int left_b = 0;
    int ans = min(N-right_w,right_w);
    for (int i=0;i<N;i++){
        ans = min(ans,right_w+left_b);
        if (S[i]=='#') left_b++;
        else right_w--;
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n;cin>>n;
  vector<int> a;
  vector<int> b;
  for(int i = 0; n > i; i++){
    int tmp;cin>>tmp;
    b.push_back(tmp);
    a.push_back(tmp);
  }
  sort(a.begin(),a.end(),greater<int>());
  for(int i = 0; n > i; i++){
    if(b[i]!=a[0]){
      cout << a[0] << endl;
    }else{
      cout << a[1] << endl;
    }
  }
}
  

Measured memory_bytes: 3436
// Problem : E - All-you-can-eat
// Contest : AtCoder Beginner Contest 145
// URL : https://atcoder.jp/contests/abc145/tasks/abc145_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;	

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;

int n, T;
int dp[maxN];
pii t[maxN];

int main() {
	ios_base::sync_with_stdio(0);
	cin >> n >> T;
	REP(i, n) cin >> t[i].st >> t[i].nd;
	sort(t, t + n);
	dp[0] = 0;
	FOR(i, 1, 6000) dp[i] = -1;
	REP(j, n) {
		FORD(i, 6000, t[j].st) {
			if (dp[i - t[j].st] >= 0 && i - t[j].st <= T - 1) {
				//cout << "hir" << endl;
				dp[i] = max(dp[i - t[j].st] + t[j].nd, dp[i]);
			}
		}
	}
	int ans = 0;
	RI(i, 6000) {
		//cout << i << " " << dp[i] << endl;
		ans = max(ans, dp[i]);
	}
	cout << ans << endl;
	return 0;
}



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

int main() {
  string S;
  getline(cin,S);
  string s=S;
    while(getline(cin,S)) {
    s+=S;
    }
  for (int i=(int)'a'; i<=(int)'z'; i++) {
      int count=0;
      for (int j=0; j<s.size(); j++) {
          if (i==(int)s.at(j) || i+(int)'A'-(int)'a'==(int)s.at(j)) count++;
      }
      cout << (char)i << " : " << count << endl;
  }
}


Measured memory_bytes: 3176
#include<bits/stdc++.h>
#define int long long
#define MOD 1000000007
#define M 51
using namespace std;
typedef pair<int,string> P;

int A, B, C, D, m;
vector<string> alph[M], ATGC[M];
string str[M];
map<string,int> rstr;
int memo[M];
bool flag;

int dp[M][M][M][M];
bool used[M][M][M][M];

int dfs(int x){

  if(flag) return 0;
  
  if(memo[x]!=-1) return memo[x];
  
  memo[x]=0;
  
  int res = ATGC[x].size();
  
  for(int i=0;i<alph[x].size();i++){
    
    res+=dfs(rstr[alph[x][i]]);
    
    if(res>A+B+C+D){
      flag=true;
      return 0;
    }
    
  }
  
  return memo[x]=res;
}

main(){
  
  cin>>A>>B>>C>>D;
  
  cin>>m;
  
  int cnt=0;
  string tmp, s;
  
  while(cin>>s){

    if(s[s.size()-1]==':'){
      tmp=s.substr(0,s.size()-1);
      str[cnt]=tmp;
      rstr[tmp]=cnt;
      cnt++;
    }else{
      
      if(s[0]=='['){
	ATGC[cnt-1].push_back(s.substr(1,s.size()-2));		
      }
      else{
	alph[cnt-1].push_back(s);
      }
      
    }
    
  }
  
  memset(memo,-1,sizeof(memo));
  
  dfs(0);
  
  if(flag){
    cout<<0<<endl;
    return 0;
  }

  for(int i=m-1;i>=0;i--){
    
    if(memo[i]==-1) continue;

    for(int j=i-1;j>=0;j--){

      int cnt=0;
      
      for(int k=0;k<alph[j].size();k++)
	if(alph[j][k]==str[i]) cnt++;

      for(int k=0;k<cnt;k++)

	for(int l=0;l<alph[i].size();l++)
	  
	  alph[j].push_back(alph[i][l]);
      
      
    }
    
  }

  for(int i=0;i<alph[0].size();i++){
    for(int j=0;j<ATGC[rstr[alph[0][i]]].size();j++){
      ATGC[0].push_back(ATGC[rstr[alph[0][i]]][j]);
    }
  }
  
  dp[0][0][0][0]=1;
  used[0][0][0][0]=true;
  
  for(int i=0;i<ATGC[0].size();i++){
    
    for(int j=0;j<ATGC[0][i].size();j++){
      
      char ch = ATGC[0][i][j];
      
      for(int a=A;a>=0;a--){
	
	if(a>i) continue;
	
	for(int b=B;b>=0;b--){

	  if(a+b>i) continue;
	  
	  for(int c=C;c>=0;c--){

	    if(a+b+c>i) continue;
	    
	    for(int d=D;d>=0;d--){

	      if(a+b+c+d!=i) continue;
	      
	      if(!used[a][b][c][d]) continue;
	      
	      if(ch=='A'){
		if(a!=A){
		  dp[a+1][b][c][d]+=dp[a][b][c][d];
		  dp[a+1][b][c][d]%=MOD;
		  used[a+1][b][c][d]=true;
		}
	      }
	      if(ch=='T'){
		if(b!=B){
		  dp[a][b+1][c][d]+=dp[a][b][c][d];
		  dp[a][b+1][c][d]%=MOD;
		  used[a][b+1][c][d]=true;
		}
	      }
	      if(ch=='G'){
		if(c!=C){
		  dp[a][b][c+1][d]+=dp[a][b][c][d];
		  dp[a][b][c+1][d]%=MOD;
		  used[a][b][c+1][d]=true;
		}
	      }
	      if(ch=='C'){
		if(d!=D){
		  dp[a][b][c][d+1]+=dp[a][b][c][d];
		  dp[a][b][c][d+1]%=MOD;
		  used[a][b][c][d+1]=true;
		}
	      }

	    }

	  }
	  
	}
	
      }
	    
    }
    
  }
  
  cout<<dp[A][B][C][D]<<endl;
  
}

Measured memory_bytes: 61688
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
#define No cout<<"No"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    int n;
    cin>>n;
    ll a[n+1],b[n];
    ll sum=0;
    rep(i,n+1){
        cin>>a[i];
        sum+=a[i];
    }
    rep(i,n){
        cin>>b[i];
    }
    /*
    iがaiかai+1の勇者をbi体まで倒す
     */
    ll ans=0;
    rep(i,n){
        if(b[i]>=a[i]){
            b[i]-=a[i];
            a[i]=0;
            a[i+1]=max(a[i+1]-b[i],0LL);
        }
        else{
            a[i]-=b[i];
        }
    }
    rep(i,n+1){
        ans+=a[i];
    }
    cout<<sum-ans<<endl;
    return 0;
}


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

int main(){
  long int n,a,b ;
  cin >> n >> a >> b ;
  if(a>b){
    cout << 0 << endl ;
    return 0 ;
  }
  if(a==b){
    cout << 1 << endl ;
    return 0 ;
  }
  if(n==1){
    cout << 0 << endl ;
    return 0 ;
  }
  cout << (b-a)*(n-2)+1 << endl ;
}

Measured memory_bytes: 256
S = input()[::-1]
ss = ['maerd', 'remaerd', 'esare', 'resare']

while True:
    for s in ss:
        if S.startswith(s):
            S = S[len(s):]
            break
    else:
        if S != '':
            print('NO')
            break

    if S == '':
        print('YES')
        break


Measured memory_bytes: 9132
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

const int MAX = 1010;
const int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
typedef pair<int, int>P;

int dx[4] = { 1,0,-1,0 };//D,R,U,L
int dy[4] = { 0,1,0,-1 };

int dp[2020][2010];
map<int, int>mpB, mpW;
int a[4020];
char c[4020];
int N;
int cntB[2010][2010], cntW[2010][2010];

int rec(int i, int j) {
	int res;
	if (dp[i][j] != -1) {
		return dp[i][j];
	}
	else if(i>0&&j>0 ){
		res = min(rec(i - 1,j) + cntB[i][j], rec(i,j - 1) + cntW[j][i]);
	}
	else if (i == 0) {
		res = rec(i, j - 1) + cntW[j][i];
	}
	else {
		res=rec(i - 1, j) + cntB[i][j];
	}
	dp[i][j] = res;
	return res;
}
signed main() {
	cin >> N;
	REP(i, 2*N) {
		cin >> c[i] >> a[i];
		if (c[i] == 'B') {
			mpB[a[i]] = i;
		}
		else {
			mpW[a[i]] = i;
		}
	}
	REP(i, 2010)REP(j, 2010) {
		cntB[i][j] = 0;
		cntW[i][j] = 0;
		dp[i][j] = -1;
	}
	dp[0][0] = 0;
	REP(i, 2*N) {
		FOR(j, i + 1, 2 * N) {
			if (c[i] == 'B') {
				if (a[j] < a[i] && c[j] == 'B') {
					cntB[a[i]][0]++;
				}
				if (c[j] == 'W') {
					cntB[a[i]][a[j]]++;
				}
			}
			else {
				if (a[j] < a[i] && c[j] == 'W') {
					cntW[a[i]][0]++;
				}
				if (c[j] == 'B') {
					cntW[a[i]][a[j]]++;
				}
			}
		}
	}
	/*REP(i, N + 1) {
		REP(j, N + 1) {
			pe(i); pe(j); print(cntB[i][j]);
		}
	}*/
	REP(i, N+1) {
		FOR(j,1,N+1) {
			cntB[i][j] += cntB[i][j - 1];
			cntW[i][j] += cntW[i][j - 1];
		}
	}
	/*REP(i, N + 1) {
		REP(j, N + 1) {
			pe(i); pe(j); print(cntW[i][j]);
		}
	}*/
	//REP(i, N+1) {
	//	REP(j, N+1) {
	//		//(dp[i+1][j]==0)? dp[i][j] + cntB[i + 1][j]:
	//		dp[i + 1][j] =min(dp[i+1][j], dp[i][j] + cntB[i + 1][j]);
	//		dp[i][j + 1] =min(dp[i][j + 1], dp[i][j] + cntW[j + 1][i]);
	//	}
	//}
	/*FOR(i,1, N + 1) {
		FOR(j,1, N + 1) {
			dp[i][j] = (dp[i][j] == 0) ? dp[i-1][j] + cntB[i][j] : min(dp[i][j], dp[i-1][j] + cntB[i][j]);
			dp[i][j] = (dp[i][j] == 0) ? dp[i][j-1] + cntW[j][i] : min(dp[i][j], dp[i][j-1] + cntW[j][i]);
		}
	}*/
	print(rec(N,N));
	/*REP(i, N + 1) {
		REP(j, N + 1) {
			pe(i); pe(j); print(dp[i][j]);
		}
	}*/
}

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

const int mod=998244353;

long C[2001][4001];

long comb(int n){
	for(int i=0;i<=n;i++){
		C[i][0]=1;
		for(int j=1;j<i;j++){
			C[i][j]=C[i-1][j-1]+C[i-1][j];
			C[i][j]%=mod;
		}
		C[i][i]=1;
	}
}

int main(){
	string s;
	cin >> s;
	int n=s.length();
	int red[n]={};
	red[0]=(s[0]=='0'?2:s[0]=='1'?1:0);
	for(int i=1;i<n;i++) red[i]+=red[i-1]+(s[i]=='0'?2:s[i]=='1'?1:0);
	
	long dp[n+1][2*n+1]={};
	dp[1][0]=(s[0]!='0'?1:0);
	dp[1][1]=(s[0]!='2'?1:0);
	for(int i=2;i<=n;i++){
		for(int j=max(0,red[i-1]-i);j<=min(i,red[i-1]);j++){
			dp[i][j]=(dp[i-1][j]+(j!=0?dp[i-1][j-1]:0))%mod;
		}
	}
	comb(n);
	long ans=0;
	for(int i=0;i<=n;i++){
		if(i<=red[n-1]) ans+=dp[n][i]*C[n][red[n-1]-i]%mod;
		ans%=mod;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 123136
/*                                 ___ _____ 
  ___  _ __ ___   ___  __ _  __ _ / _ \___  |
 / _ \| '_ ` _ \ / _ \/ _` |/ _` | | | | / / 
| (_) | | | | | |  __/ (_| | (_| | |_| |/ /  
 \___/|_| |_| |_|\___|\__, |\__,_|\___//_/   
                      |___/            
*/
// Getting better at it ! ! !
#include <bits/stdc++.h>
#include <string.h>
#define int long long
#define MAX (int)(1e7 + 5)
#define MAX2D (int)(1e3 + 5)
#define itn int
#define inf 5e18
#define MOD (int)(1e9 + 7)
#define pb push_back
#define mk make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sitr set<int>::iterator
#define mitr map<int, int>::iterator
#define pii pair<int, int>
#define vii vector<pii>
#define vi vector<int>
#define vll vector<unsigned int>
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define fast                       \
    ios_base ::sync_with_stdio(0); \
    cin.tie(NULL);                 \
    cout.tie(NULL)
using namespace std;


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

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...);
}
#ifndef ONLINE_JUDGE
#define see(x...)                 \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define see(x...)
#endif
int n,k;
const int M = 2e5+1;
vi a(M);
int mx = 0;
bool good(int m) {
    int cuts = 0;
    for(int i=0;i<n;i++) {
        int pieces = a[i]/m + (a[i]%m > 0);
        pieces--;
        cuts += pieces;
    }
    if(cuts <= k) return true;
    return false;
}

int f() {
    int l = 1, r = mx;
    int ans = l;
    while(l <= r) {
        int mid = (l+r)/2;
        if(good(mid)) ans = mid, r = mid-1;
        else l = mid+1;
    }
    return ans;
}

signed main()
{
    fast;
    cin>>n>>k;
    for(int i=0;i<n;i++) cin>>a[i], mx = max(mx, a[i]);
    cout<<f();
    return 0; 
}
 
/*
max factors number = 720720 --> 240 factors
max factors number = 1441440 -->288 factors
 
Beautiful program
Please run for me.
I've tried you in BASIC,
FORTRAN and C.
Beautiful program,
You've errors galore.
And each time I run you,
You're swapped out of core.
*/

Measured memory_bytes: 4632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep_1(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define rep_2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main()
{
  string s; cin >> s;
  if (s[2] == s[3] && s[4] == s[5]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pi;

#define fi first
#define se second

int read() {
  int res = 0, w = 1; char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-') c = getchar(), w = -1;
  while (isdigit(c)) res = (res << 1) + (res << 3) + c - '0', c = getchar();
  return res * w;
}

int main() {
#ifdef dream_maker
//  freopen("tst.in", "r", stdin);
#else
  //freopen(".in", "r", stdin);
  //freopen(".out", "w", stdout);
#endif
  ll s;
  cin >> s;
  int a = 0, b = 0, c = 0, d = 0;
  int p = sqrt(s);
  if (1ll * p * p < s) p++;
  a = d = p;
  ll t = 1ll * a * d - s;
//  cout << a << " "<< b << " " << t << endl;
  for (int i = 1; i < 1e9; i++) {
    if (t % i == 0 && t / i < 1e9) {
      c = i, b = t / i;
      break;
    }
  }
  cout << "0 0 " << a << " "<< b << " " << c << " "<< d << endl;
  return 0;
}


Measured memory_bytes: 256
S = input()
T = input()

dp = [[0] * (len(T)+1) for _ in range(len(S)+1)]
for i in range(len(S)):
    for j in range(len(T)):
        if S[i] == T[j]:
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1)
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j])
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1])

res = ""
i = len(S)
j = len(T)

while i > 0 and j > 0:
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        res = S[i-1] + res
        i -= 1
        j -= 1

print(res)
            

Measured memory_bytes: 113628
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <functional>
using namespace std;

int main() {
	int N,K;
	cin>>N>>K;
	vector<int>a(N);
	for(int i=0;i<N;i++)cin>>a[i];
	
	vector<long long>ruiseki(N+1);
	for (int i = 1; i <= N; i++)
	{
		ruiseki[i] = ruiseki[i-1] + a[i-1];
	}

	vector<long long>sorted;
	for (int i = 0; i < N; i++)
	{
		for (int j = i; j < N; j++)
		{
			long long b = ruiseki[j+1] - ruiseki[i];
			sorted.push_back(b);
		}
	}

	sort(sorted.begin(), sorted.end(), greater<long long>());

	long long ans = 0;
	for (long long i = 63; i >= 0; i--)
	{
		int cnt = 0;
		for (int j = 0; j < sorted.size(); j++)
		{
			if (sorted[j] & (1ll << i))
			{
				cnt++;
			}
		}

		if (cnt >= K)
		{
			for (int j = 0; j < sorted.size(); j++)
			{
				if (sorted[j] & (1ll << i))
				{
				}
				else
				{
					swap(sorted[j], sorted.back());
					sorted.pop_back();
					j--;
				}
			}

			ans += (1ll<<i);
		}
	}

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 6516
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);};};
const ll MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<62;

bool ch=true;

int count(vi &a,int n){
    int count=0;
    if(a[0]==n)count++;
    if(a[2]==n)count++;
    if(a[1]==n)count++;
    if(a[0]==n)a[0]++;
    else if(a[1]==n)a[1]++;
    else if(a[2]==n)a[2]++;
    else ch=false;
    return count;
}

int main(void){

    int n;
    cin>>n;
    vi v(n);rep(i,n)cin>>v[i];
    vi a{0,0,0};
    ll ans=1;
    rep(i,n){
        ans*=count(a,v[i]);
        ans%=MOD;
    }
    if(ch)fin(ans);
    else fin(0);
}

Measured memory_bytes: 640
N = int(input())
xl = [list(map(int, input().split())) for _ in range(N)]

XL = [[x-l, x+l] for x,l in xl]
XL.sort(key=lambda x: x[1])

now = -float("inf")
ans = 0
for left, right in XL:
    if now <= left:
        now = right
        ans += 1
print(ans)


Measured memory_bytes: 43588
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long i,j,k,a,n,c=0;
	cin>>n;
	long long A[n],B[n];
	for(i=0;i<n;i++)
	cin>>A[i]>>B[i];
  	for(i=n-1;i>=0;i--)
		{
       if((A[i]+c)%B[i]==0) continue;
			 c+=B[i]-(A[i]+c)%B[i];
		}
		cout<<c<<endl;
}


Measured memory_bytes: 5188
import sys
input = sys.stdin.readline
from collections import *

H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
x, y = defaultdict(int), defaultdict(int)

for i in range(H):
    for j in range(W):
        x[A[i][j]] = i
        y[A[i][j]] = j

x[0] = x[D]
y[0] = y[D]
acc = [[0] for _ in range(D)]

for i in range(D):
    now = i
    
    while now+D<=H*W:
        acc[i].append(acc[i][-1]+abs(x[now+D]-x[now])+abs(y[now+D]-y[now]))
        now += D

Q = int(input())

for _ in range(Q):
    L, R = map(int, input().split())
    print(acc[L%D][R//D]-acc[L%D][L//D])
    

Measured memory_bytes: 81236
def main():
  N,K= map(int,input().split())
  h = list(map(int,input().split()))
  dp = [-1]*N
  dp[0] = 0
  for i in range(1,N):
    tmp = i - K
    if tmp < 0: tmp = 0
    dp[i] = min(dp[j] + abs(h[i] - h[j]) for j in range(tmp,i))
  print(dp[N-1])

if __name__ == '__main__':
  main()


Measured memory_bytes: 13928
import numpy as np
import itertools
H, W, K = [int(_) for _ in input().split()]
S = np.zeros((H + 1, W + 1), dtype=int)
S[1:, 1:] = [[int(_) for _ in input()] for _ in range(H)]
cum = S.cumsum(axis=0).cumsum(axis=1)
#sum(a,b -> x,y) (1-indexed)
#cum[x][y]+cum[a-1][b-1]-cum[a-1][y]-cum[x][b-1]
ans = 10**10
for bs in itertools.product([True, False], repeat=H - 1):
    bs = [True] + list(bs) + [True]
    idxs = []
    for i, b in enumerate(bs):
        if b:
            idxs += [i]
    cum2 = np.array([cum[i2] - cum[i1] for i1, i2 in zip(idxs, idxs[1:])])
    i = 0
    cnt = sum(bs) - 3
    while i < W:
        di = min(
            np.searchsorted(c[i + 1:] - c[i], K, side='right') for c in cum2)
        if di == 0:
            cnt = 10**10
            break
        i += di
        cnt += 1
    ans = min(ans, cnt)
print(ans)


Measured memory_bytes: 27504
#include <string>
#include <iostream>

using namespace std;

int main() {
  string A,B,C;
	std::cin >> A >> B >> C;
  
  if(A[A.size()-1]==B[0]){
    if(B[B.size()-1]==C[0]){
      cout << "YES" <<endl;
      return 0;
    }
  }
  cout << "NO" <<endl;
  return(0);
}


Measured memory_bytes: 256