akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define MOD = 1000000007;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class K, class V> void cout_v(map<K, V>& m)
{ for(auto it=m.begin();it!=m.end();it++)cout<<it->first<<":"<<it->second<<endl;}
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
inline int powi(int x,int y) {int p=1; while(y--) p*=x; return p;}
template<class T> inline bool is_overlap(const T& a, const T& b, const T& p, const T& q)
{ return p <=b && a <= q; }
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
#define ANS(a) cout<<a<<endl
void yes(bool f){cout<<(f?"yes":"no")<<endl;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    vector<string> s(3); cin >> s;

    int turn = 0;
    int i[3] = {0, 0, 0};
    while (1) {
        if (i[turn] == s[turn].size()) {
            cout << char('A' + turn) << endl;
            return 0;
        }
        int tmp = turn;
        turn = s[turn][i[turn]] - 'a';
        i[tmp]++;
    }
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]
            int n = int.Parse(Console.ReadLine());
            var numbers = ReadLine().ToList();

            long total = numbers.Sum();
            long snuke = 0;
            long minDiff = long.MaxValue;

            for (int i = 0; i < n - 1; i++)
            {
                snuke += numbers[i];
                long raccoon = total - snuke;
                long diff = Math.Abs(snuke - raccoon);

                if (diff < minDiff)
                {
                    minDiff = diff;
                }
            }

            Console.WriteLine(minDiff);            
        }

        static IEnumerable<long> ReadLine()
        {
            var line = Console.ReadLine().TrimEnd();
            var array = line.Split(' ');

            foreach (var s in array)
            {
                yield return long.Parse(s);
            }
        }
    }
}

Measured memory_bytes: 34884
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)
#if DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) /* ... */
#endif

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 100
#else
#define SIZE 123450
#endif

int N,A[SIZE],MA[SIZE];
int MAX=LONG_LONG_MAX/2;

void solve() {
    cin>>N;
    REP(i,N+1)cin>>A[i];
    MA[0]=max(0LL,1-A[0]);
    REP1(i,N) {
        MA[i]=min(MAX,max(0LL, MA[i-1]*2-A[i]));
    }
    int ans = 0;
    int before = 0;
    RREP(i,N+1) {
        int ma = MA[i]+A[i];
        if (i<60) ma = min(ma, 1LL<<i);
        int mi = (before+1)/2 + A[i];
        if (mi > ma) {
            cout << -1 << endl;
            return;
        }
        before = min(ma, before + A[i]);
        ans += before;
    }
    cout << ans << endl;
}



Measured memory_bytes: 5232
#include <stdio.h>

typedef struct List {
	struct List *next;
	int v;
} list;

int main()
{
	int i, N, M, u, w;
	list *adj[100001] = {}, e[200001];
	scanf("%d %d", &N, &M);
	for (i = 0; i < M; i++) {
		scanf("%d %d", &u, &w);
		e[i*2].v = w;
		e[i*2+1].v = u;
		e[i*2].next = adj[u];
		e[i*2+1].next = adj[w];
		adj[u] = &(e[i*2]);
		adj[w] = &(e[i*2+1]);
	}
	
	int count = 1, flag[100001] = {}, q[100001], head, tail;
	list *p;
	flag[1] = 1;
	q[0] = 1;
	for (head = 0, tail = 1; head < tail; head++) {
		u = q[head];
		for (p = adj[u]; p != NULL; p = p->next) {
			w = p->v;
			if (flag[w] == 0) {
				flag[w] = -flag[u];
				if (flag[w] == 1) count++;
				q[tail++] = w;
			} else if (flag[w] == flag[u]) break;
		}
		if (p != NULL) break;
	}
	if (head < tail) printf("%lld\n", (long long)N * (N - 1) / 2 - M);
	else printf("%lld\n", (long long)count * (N - count) - M);
	fflush(stdout);
	return 0;
}

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

int main() {
  while(1) {
    int n;
    cin>>n;
    if(n==0) break;
    int dp[301] = {1};
    for(int i=1;i*i<=n;i++) 
      for(int j=0;j<=n;j++)
	if(j-i*i >= 0) dp[j] += dp[j-i*i];
    cout << dp[n] <<endl;
  }
return 0;
}

Measured memory_bytes: 1160
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

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

void dfs(int t, int sx, int sy, vector< vector<int> >& a) {
	if (t == mini || t == 10) return;
	int h = a.size(), w = a[0].size();
	for (int k = 0; k < 4; k++) {
		int x = sx + dx[k], y = sy + dy[k];
		if (x < 0 || x >= w || y < 0 || y >= h || a[y][x] == 1)
			continue;
		bool flag;
		int _x, _y;
		for (;;) {
			if (a[y][x] == 3) {
				mini = min(mini, t + 1);
				return;
			}
			_x = x + dx[k]; _y = y + dy[k];
			if (_x < 0 || _x >= w || _y < 0 || _y >= h) {
				flag = false;
				break;
			}
			if (a[_y][_x] == 1) {
				flag = true;
				break;
			}
			x = _x; y = _y;
		}
		if (!flag) continue;
		a[_y][_x] = 0;
		dfs(t + 1, x, y, a);
		a[_y][_x] = 1;
	}
}

int main() {
	for (;;) {
		int w, h; cin >> w >> h;
		if (w == 0 && h == 0) break;
		vector< vector<int> > a(h, vector<int>(w));
		int sx, sy;
		for (int y = 0; y < h; y++)
			for (int x = 0; x < w; x++) {
				cin >> a[y][x];
				if (a[y][x] == 2) {
					a[y][x] = 0;
					sx = x; sy = y;
				}
			}
		mini = INT_MAX;
		dfs(0, sx, sy, a);
		cout << (mini < INT_MAX ? mini : -1) << endl;
	}
}

Measured memory_bytes: 1228
#include <stdio.h>

int main(void)
{
    int h, w;
    int i, j;
    
    scanf("%d%d", &h, &w);
    
    while(h||w){
        for(i=0; i<h; i++){
            for(j=0; j<w; j++){
                if((i+j)%2==0){
                    printf("#");
                }
                else{
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
        
        scanf("%d%d", &h, &w);
    }
    
    return 0;
}

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

class Progaram
{
    static void Main(string[] args)
    {
        var s = Console.ReadLine().ToCharArray();
        var n = s.Length;
        if (!s.SequenceEqual(s.Reverse()))
        {
            Console.WriteLine("No");
            return;
        }
        var s2 = s.Take(n / 2);
        if (!s2.SequenceEqual(s2.Reverse()))
        {
            Console.WriteLine("No");
            return;
        }
        Console.WriteLine("Yes");
    }
}



Measured memory_bytes: 13152
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define myPair pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define qmax priority_queue<int>
#define qmin priority_queue<int,vector<int>,greater<int>>
#define all(x) x.begin(),x.end()
#define FOR(i,a,b) for(int i = a; i <= b; i++)
#define FORR(i,a,b) for(int i = a; i >= b; i--)

const int mxn = 1e5 + 10, mod = 1e9 + 7;
int dp[101][mxn], aux[101][mxn];
int n,k;
int a[mxn];

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

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n >> k;
	FOR(i,1,n)
		cin >> a[i];
	FOR(j,1,k)
	{
		dp[0][j] = 0;
		aux[0][j] = 1;
	}
	aux[0][0] = dp[0][0] = 1;

	FOR(i,1,n)
	{
		aux[i][0] = dp[i][0] = 1;
		FOR(j,1,k)
		{
			int count = j - min(j, a[i]);
			if(count == 0)
				dp[i][j] = aux[i - 1][j];
			else
				dp[i][j] = (aux[i - 1][j] - aux[i - 1][count - 1] + mod) % mod;
		}
		FOR(j,1,k)
			aux[i][j] = (aux[i][j - 1] + dp[i][j]) % mod;
	}
	cout << dp[n][k];

	return 0;
}


Measured memory_bytes: 161436
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(void){

  int d,n,t,a,b,c,dp[202][202];
  vector<int>T,A,B,C;

  cin >> d >> n;
  
  //末尾にtを追加していく
  for(int i=0;i<d;i++){
    cin >> t;
    T.push_back(t);
  }
  
  for(int i=0;i<n;i++){
    cin >> a >> b >> c;
    A.push_back(a);
    B.push_back(b);
    C.push_back(c);
  }
  
  //メモ用配列の初期化
  for(int i=0;i<202;i++)
    for(int j=0;j<202;j++)
      dp[i][j]=-1;
  
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      if(A[i]<=T[0] && T[0]<=B[i] && A[j]<=T[1] && T[1]<=B[j])
	dp[0][j]=max(dp[0][j],abs(C[i]-C[j]));
  
  for(int i=1;i<=d;i++)
    for(int j=0;j<n;j++)
      for(int k=0;k<n;k++)
	if(A[k]<=T[i+1] && T[i+1]<=B[k] && dp[i-1][j]>=0)
	  //メモしていく
	  dp[i][k]=max(dp[i][k],dp[i-1][j]+abs(C[j]-C[k]));
  
  int ans=0;
  for(int i=0;i<n;i++)
    ans=max(ans,dp[d-2][i]);
  
  cout << ans <<endl;
  
  return 0;
}

Measured memory_bytes: 1384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD=1000000007;
const long double PI=3.1415926535;

int main() {
  ll K,A,B,C;
  cin>>A>>B>>C>>K;
  
  if(K%2==0){
    cout<<A-B;
  }
  else{
    cout<<B-A;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define F first
#define S second

using namespace std;
using namespace __gnu_pbds;
typedef long long  ll;

template <typename T>
using ordered_set = tree<T, null_type, less<T> , rb_tree_tag, tree_order_statistics_node_update>;

const double EPS = 1e-9;
const double pi = acos(-1.0);

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


int main() {
//#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//#endif
    int n , x;
    cin >> n >> x;
    int num , ans = 0;
    for(int i = 0 ; i < n ; ++i){
        cin >> num;
        ans = __gcd((int)abs(num - x) , ans);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
module Input
	def numread()
		s = gets().split()
		p = Array.new()
		for i in 0...s.size()
			p[i] = s[i].to_i()
		end
		return p
	end
	
	module_function:numread
end

include Input

loop{
	if(STDIN.eof())
		break
	end
	w = numread()
	x = (w[2] * w[4] - w[1] * w[5]).to_f / (w[0] * w[4] - w[1] * w[3]) + 0.00001
	y = (w[2] * w[3] - w[0] * w[5]).to_f / (w[1] * w[3] - w[0] * w[4]) + 0.00001
	print(sprintf("%.3f %.3f\n",x,y))
}

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

string solve(double a, double b){
    if(a < 35.5 && b <  71.0) return "AAA";
    if(a < 37.5 && b <  77.0) return "AA";
    if(a < 40.0 && b <  83.0) return "A";
    if(a < 43.0 && b <  89.0) return "B";
    if(a < 50.0 && b < 105.0) return "C";
    if(a < 55.0 && b < 116.0) return "D";
    if(a < 70.0 && b < 148.0) return "E";
    return "NA";
}

int main(){
    double a,b;
    while(cin >> a >> b){
        cout << solve(a,b) << endl;
    }
    return 0;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
#define vecmin(A) *min_element(A.begin(),A.end())
#define vecmax(A) *max_element(A.begin(),A.end())
typedef long long ll;

int main(){
  int n;
  cin >> n;
  vector<int> a(n),b(n),c(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  rep(i,n) cin >> c[i];
  sort(a);
  sort(b);
  sort(c);
  ll ans = 0;
  rep(i,n){
    int apart = upper_bound(a.begin(),a.end(),b[i]-1)-a.begin();
    int cpart = c.end() - lower_bound(c.begin(),c.end(),b[i]+1);
    ans += (ll)apart*cpart;
  }
 cout << ans << endl; 
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int numofbits(int bits)
{
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int h,w,k;
vector<string> s;

int calc(int bit)// bit=1 -> shita de waru
{
    int ans=numofbits(bit);
    vector<int> group(h);
    for (int i = 0; i < h; i++)
    {
        group[i]=i;
    }
    for (int i = 0; i < h-1; i++)
    {
        if(((bit>>i) &1) ==0)
        {
            group[i+1]=group[i];
        }
    }
    
    vector<int> count(h);
    for (int ww = 0; ww < w; ww++)//yoko
    {
        vector<int> tmp(h);
        bool over=false;
        bool impossible = false;
        for (int hh = 0; hh < h; hh++)//tate
        {
            tmp[group[hh]]+=count[hh]+(s[hh][ww]-'0');
            if(tmp[group[hh]]>k) 
            {
                over=true;
                break;
            }
        }
        if(over)
        {
            ans++;
            for (int hh = 0; hh < h; hh++)
            {
                count[hh]=0;
            }
            for (int hh = 0; hh < h; hh++)
            {
                count[group[hh]]+=(s[hh][ww]-'0');
                if(count[group[hh]]>k)
                {
                    impossible=true;
                    return h*w;                    
                }
            }
            
        }
        else
        {
            for (int hh = 0; hh < h; hh++)
            {
                count[hh]=tmp[hh];
            }
        }
    }
    //cout<<bit<<"\t"<<ans<<endl;

    return ans;
}

int main()
{
    int ans=100000;
    cin>>h>>w>>k;
    s.resize(h);
    for (int i = 0; i < h; i++)
    {
        cin>>s[i];
    }
    for (int bit = 0; bit < (1<<h-1); bit++)
    {
        ans=min(ans,calc(bit));
    }
    
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cmath>
#include<cstring>
#include<map>
#include<set>
using namespace std;
#define LL long long
int n,k,m,sb[2010][2010],sw[2010][2010],p,q;
void clear()
{
	memset(sb,0,sizeof(sb));
	memset(sw,0,sizeof(sw));
}
void cal()
{
	for(int i=1;i<=m;i++)
	for(int j=1;j<=m;j++)
	{
		sb[i][j]+=sb[i][j-1]+sb[i-1][j]-sb[i-1][j-1];
		sw[i][j]+=sw[i][j-1]+sw[i-1][j]-sw[i-1][j-1];
	}
}
int calb(int mx,int my,int nx,int ny)
{
	mx+=p;nx+=p;
	my+=q;ny+=q;
	if(mx>m||my>m||nx<1||ny<1)return 0;
	mx=max(1,mx);my=max(1,my);
	nx=min(m,nx);ny=min(m,ny);
	return sb[nx][ny]-sb[nx][my-1]-sb[mx-1][ny]+sb[mx-1][my-1];
}
int calw(int mx,int my,int nx,int ny)
{
	mx+=p;nx+=p;
	my+=q;ny+=q;
	if(mx>m||my>m||nx<1||ny<1)return 0;
	mx=max(1,mx);my=max(1,my);
	nx=min(m,nx);ny=min(m,ny);
	return sw[nx][ny]-sw[nx][my-1]-sw[mx-1][ny]+sw[mx-1][my-1];
}
int main()
{
	while(cin>>n>>k)
	{
		clear();
		int x,y;
		char s[3];
		m=k*2;
		for(int i=1;i<=n;i++)
		{
			scanf("%d%d%s",&x,&y,s);
			if(s[0]=='W')
			{
				sw[x%m+1][y%m+1]++;
			}
			else sb[x%m+1][y%m+1]++;
		}
		cal();
		int ans=-1,t;
		for(int i=0;i<=k;i++)
		for(int j=0;j<=k;j++)
		{
			p=i,q=j;
			t=calb(1,1,k,k)+calb(k+1,k+1,k+k,k+k)+calb(-k+1,-k+1,0,0)+calb(-k+1,k+1,0,k+k)+calb(k+1,-k+1,2*k,0)+calw(k+1,1,2*k,k)+calw(1,k+1,k,2*k)+calw(1,-k+1,k,0)+calw(-k+1,1,0,k);
			ans=max(t,ans);
			t=calw(1,1,k,k)+calw(k+1,k+1,k+k,k+k)+calw(-k+1,-k+1,0,0)+calw(-k+1,k+1,0,k+k)+calw(k+1,-k+1,2*k,0)+calb(k+1,1,2*k,k)+calb(1,k+1,k,2*k)+calb(1,-k+1,k,0)+calb(-k+1,1,0,k);
			ans=max(t,ans);
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 31872
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

int main() {
  string s, t;
  cin >> s >> t;

  REP(i, s.length()){
    rotate(s.begin(), s.begin()+1, s.end());

    if(s == t){
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

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

    int l[60];

    for (int i = 0; i < N; i++)
        cin >> l[i];

    sort(l, l + N, greater<int>());

    int sum = 0;

    for (int i = 0; i < K; i++)
    {
        sum += l[i];
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
function input()
  local inp = io.read()
  local r1,r2
  for i=1,string.len(inp),1 do
    if inp:sub(i,i)==' ' then
      r1 = tonumber(inp:sub(1,i-1))
      r2 = tonumber(inp:sub(i+1,string.len(inp)))
    end
  end
  return r1,r2
end


local n,T
n,T = input()
c={}
t={}
for i=1,n,1 do
  c[i],t[i] = input()
end

local res = 100000
for i=1,n,1 do
  if t[i]<=T then
    res = math.min(res,c[i])
  end
end
if res==100000 then
  print("TLE")
else
  print(res)
end

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string p,s;
    cin >> s;
    cin >> p;
    while(s.size() <= 100) s += s;
    if(s.find(p) != string::npos) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3200
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

bool in_cond(vint& A, vint& F,  int N, ll K, ll x) {
    rep(i, N) {
        if (ll(A[i]) * ll(F[i]) <= x) continue;
        if (K <= 0) return false;
        ll k = ll(A[i]) - x / ll(F[i]);
        K -= k;
        if (K < 0) return false;
    }
    return true;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    ll K;
    cin >> N >> K;
    vint A(N), F(N);
    multiset<int>  Aset;
    multiset<int, greater<int>> Fset;
    ll maxA = 0, maxF = 0;
    rep(i, N) {
        int a;
        cin >> a;
        A[i] = a;
        maxA = max(maxA, ll(a));
    }
    rep(i, N) {
        int f;
        cin >> f;
        F[i] = f;
        maxF = max(maxF, ll(f));
    }
    sort(A.begin(), A.end());
    sort(F.begin(), F.end(), greater<int>());
    ll L = -1, R = maxA * maxF;
    while (R - L > 1) {
        ll M = (L + R) / 2;
        if (in_cond(A, F, N, K, M) == true) {
            R = M;
        }
        else {
            L = M;
        }
    }

    cout << R << endl;
    return 0;
}

Measured memory_bytes: 1792
#define _GLIBCXX_DEBUG //エラーを出すためのおまじない
#include <bits/stdc++.h>
#include <algorithm>
//#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
#include <math.h>
using namespace std;
#define coYES cout << "YES" << endl
#define coNO cout << "NO" << endl
#define coYes cout << "Yes" << endl
#define coNo cout << "No" << endl
#define coyes cout << "yes" << endl
#define cono cout << "no" << endl
//#define cocount cout << count << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define Cinint(n) int n;\
cin >> n;
#define Cinvecint(a, n) vector<int> a(n);\
for (int i = 0; i < (int)(n); i++) {\
  int num;\
  cin >> num;\
  a.at(i) = num;\
}
#define Cinstring(s) string s;\
cin >>s;

  

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  rep(i, n) {
    int numc;
    cin >> numc;
    c.at(i) = numc;
    rep(j, m) {
      int numa;
      cin >> numa;
      a.at(i).at(j) = numa;
    }
  }
  bool flag = true;
  vector<int> skill(m);
  int min = 100000000;
  for (int tmp = 0; tmp < (1 << 12); tmp++) {
    bitset<12> s(tmp);
    //cout << s << endl;
    int money = 0;
    rep(i, m) {
      skill.at(i) = 0;
    }
    rep(i,n) {
      if (s.test(i)) {
        money += c.at(i);
        rep(j, m) {
          skill.at(j) += a.at(i).at(j);
        }
      }
    }
    bool flag2 = true;
    rep(i, m) {
      if (skill.at(i) < x) {
        flag2 = false;
      }
    }
    if (flag2) {
      flag = false;
      if (min > money) {
        min = money;
      }
    }
  }
  if (flag) {
    cout << -1 << endl;
  }
  else {
    cout << min << endl;
  }
}


Measured memory_bytes: 3592
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());

using ll = long long int;

ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a % b);
}

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

int main(){
    int r;
    cin >> r;
    cout << r * r * 3 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

const double pi=3.1415926535897932L;

int main() {
  double A, B, H, M;
  double xa, ya, xb, yb;
  
  cin >> A >> B >> H >> M;
  
  xa = A * sin(2.0L*pi*(H*60.0L+M)/720.0L);
  ya = A * cos(2.0L*pi*(H*60.0L+M)/720.0L);
  
  xb = B * sin(2.0L*pi*M/60.0L);
  yb = B * cos(2.0L*pi*M/60.0L);
  
  double dt = sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb));
    
  cout << setprecision(12) << dt << endl;
}

Measured memory_bytes: 4148
S=list(input())
N=len(S)
for i in range(N//2):
    if S[i]==S[N-1-i]:
        flag1=1
    else:
        flag1=0
        break
for i in range((N+1)//4):
    if S[i]==S[(N-3)//2-i]:
        flag2=1
    else:
        flag2=0
        break
for i in range((N+1)//2,N):
    if S[i]==S[(3*N-1)//2-i]:
        flag3=1
    else:
        flag3=0
        break
if flag1==1 and flag2==1 and flag3==1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
A = input()
B = input()
if A == B:
    print('EQUAL')
    exit()
if len(A) > len(B):
    print('GREATER')
elif len(A) < len(B):
    print('LESS')
else:
    for i in range(len(A)):
        if int(A[i]) > int(B[i]):
            print('GREATER')
            break
        elif int(A[i]) < int(B[i]):
            print('LESS')
            break

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}
int main(){
    ll n,k,c;cin >> n >>k >>c;
    string s;cin >>s;
    vl left(n),right(n);
    ll tmp=0,last=-inf;
    rep(i,n){
        if(s[i]=='o'&&i-last>c){
            tmp++;
            last=i;
        }
        left[i]=tmp;
    }
    rev(all(s));last=-inf;tmp=0;
    rep(i,n){
        if(s[i]=='o'&&i-last>c){
            tmp++;
            last=i;
        }
        right[i]=tmp;
    }
    rev(all(right));
    //rep(i,n)cout << right[i] <<endl;
    rep(i,n){
        if(i==0){
            if(right[i+1]<k)cout << i+1 <<endl;
        }
        else if(i==n-1){
            if(left[i-1]<k)cout << i+1 <<endl;
        }
        else {
            if(right[i+1]+left[i-1]<k)cout << i+1 <<endl;
        }
    }
}   

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

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

int main()
{
  int l[10];
  int v1,v2;
  char del;

  while(true){

    REP(i,10){
      cin >> l[i] >> del;
    }
    if(!(cin >> v1 >> del >> v2))
      break;

    int sum=0;
    REP(i,10) sum += l[i];

    double t = (double)sum / (v1+v2);
    double len = t * v1;

    int tmp=0;
    int res=0;
    REP(i,10){
      tmp += l[i];
      if(tmp >= len){
	res = i+1;
	break;
      }
    }

    cout << res << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {
    static class Solution {
        Integer[][]dp;
        public void find(int k) {
            dp = new Integer[k+1][k+1];
            long res = 0;
            for(int a=1; a<=k; a++) {
                for(int b=1; b<=k; b++) {
                    for(int c=1; c<=k; c++) {
                        int val = gcd(b,c);
                        if(dp[b][c] == null) {
                            dp[b][c] = val;
                        }
                        int val2 = gcd(a, val);
                        if(dp[a][val] == null) {
                            dp[a][val] = val2;
                        }
                        res += val2;
                    }
                }
            }
            System.out.println(res);

        }

        int gcd(int a, int b)
        {
            if(dp[a][b] != null) {
                return dp[a][b];
            }
            // Everything divides 0
            if (a == 0)
                return b;
            if (b == 0)
                return a;

            // base case
            if (a == b)
                return a;

            // a is greater
            if (a > b)
                return gcd(a-b, b);
            return gcd(a, b-a);
        }
    }

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

        int k = sc.nextInt();
        sol.find(k);
    }
}


Measured memory_bytes: 37340
using System;
using System.Linq;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var c = Console.ReadLine();
            var v = new string[]{ "a", "e", "i", "o", "u" };
            Console.WriteLine(v.Contains(c) ? "vowel" : "consonant");
        }
    }
}

Measured memory_bytes: 11220
open System
open System.Collections.Generic

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f
    let readChars() = read string |> Seq.toArray
    let readInts() = readChars() |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

[<AutoOpen>]
module Cout =
    let writer = new IO.StreamWriter(new IO.BufferedStream(Console.OpenStandardOutput()))
    let print (s: string) = writer.Write s
    let println (s: string) = writer.WriteLine s
    let inline puts (s: ^a) = string s |> println

// -----------------------------------------------------------------------------------------------------

// -----------------------------------------------------------------------------------------------------

let main() =
    let s = readChars()
    let len = s.Length
    let mutable ok = true
    for i in 0 .. 2 .. len - 2 do
        if not (s.[i] = 'h' && s.[i + 1] = 'i') then ok <- false
    if len % 2 = 1 then ok <- false
    if ok then "Yes" else "No"
    |> puts
    ()

// -----------------------------------------------------------------------------------------------------
main()
writer.Dispose()


Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
int main() {
    int a,b;
    cin>>a>>b;
    int ans1=a*b,ans2=a+b,ans3=a-b;
    if(ans1>ans2) {
    	if(ans1>ans3) cout<<ans1;
    	else cout<<ans3;
	}
	else if(ans2>ans3) cout<<ans2;
	else cout<<ans3; 
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>

long long gcd(long long a, long long b)
{
    return b?gcd(b,a%b):a;
}
long long m,n;
int main()
{
    while(~scanf("%lld%lld",&m,&n))
    {
        long long temp = gcd(m,n);
        printf("%lld %lld\n",temp,m/temp*n);
    }
    return 0;
}

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

typedef unsigned int ui;
#define rep(i,l,r) for(int i=l;i<=r;++i)
const int N=2000+5,A=4e6+5;
int cnt[A];
ui a[A/32+5];int mx;
bool Count(int x)
{
	return a[x/32]&(1<<(x&31));
}
void move(int x)
{
	int u=mx/32;mx+=x;
	int du=x/32,di=x&31;
	if(!di)
	{
		for(int i=u;i>=0;--i)a[i+du]|=a[i];
		return ;
	}
	for(int i=u;i>=0;--i)
	{
		a[i+du+1]|=a[i]>>32-di;
		a[i+du]|=a[i]<<di;
	}
}

int main()
{
	//freopen("will.in","r",stdin);freopen("will.out","w",stdout);
	int n;
	cin>>n;
	int sum=0;
	rep(i,1,n)
	{
		int x;
		scanf("%d",&x);
		sum+=x;
		++cnt[x];
	}
	mx=0;a[0]=1;
	rep(i,1,sum)
	{
		while(cnt[i]>2){++cnt[i*2];cnt[i]-=2;}
		while(cnt[i]--)move(i);
	}
	int tot=0;
	rep(i,1,sum)
	if(Count(i))++tot;
	tot=(tot+1)/2;
	rep(i,1,sum)
	if(Count(i))
	{
		if(!--tot)
		{
			cout<<i;
			exit(0);
		}
	}
}


Measured memory_bytes: 16384
n = gets.chomp.to_i
s = gets.chomp

r_sum = []
g_sum = []
b_sum = []
rgb = []

r = g = b = 0
s.each_char do |c|
  rgb << c
  r+=1 if c == "R"
  g+=1 if c == "G"
  b+=1 if c == "B"
  r_sum << r
  g_sum << g
  b_sum << b
end

i = 0
sum = 0
s.each_char do
  if s[i] == "R"
    sum += (g_sum[-1] - g_sum[i]) *  (b_sum[-1] - b_sum[i])
    n = 1
    while (i + 2*n < s.size )
      c1 = s[i+n]
      c2 = s[i+2*n]
      c1, c2 = [c2, c1] if c2 < c1
      sum -= 1 if c1 == "B" && c2 == "G"
      n+=1
    end
  end
  if s[i] == "G"
    sum += (r_sum[-1] - r_sum[i]) *  (b_sum[-1] - b_sum[i])
    n = 1
    while (i + 2*n < s.size )
      c1 = s[i+n]
      c2 = s[i+2*n]
      c1, c2 = [c2, c1] if c2 < c1
      sum -= 1 if c1 == "B" && c2 == "R"
      n+=1
    end
  end
  if s[i] == "B"
    sum += (r_sum[-1] - r_sum[i]) *  (g_sum[-1] - g_sum[i])
    n = 1
    while (i + 2*n < s.size )
      c1 = s[i+n]
      c2 = s[i+2*n]
      c1, c2 = [c2, c1] if c2 < c1
      sum -= 1 if c1 == "G" && c2 == "R"
      n+=1
    end
  end


  i+=1
end

puts sum


Measured memory_bytes: 14784
#include <stdio.h>

int
main(int argc, char *argv[])
{
  int n, T, t[200001];
  scanf("%d %d", &n, &T);
  for(int i = 0; i < n; i++) scanf("%d", &t[i]);

  int ans = 0;

  for(int i = 1; i < n; i++){
    if(T <= t[i] - t[i - 1]) ans += T;
    else ans += t[i] - t[i - 1];
  }
  ans += T;

  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 896
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1

def main():
    n,m=map(int, input().split())
    if (n,m)==(1,1):
        print(1)
    elif min(n,m)==1:
        print(max(n,m)-2)
    else:
        print((m-2)*(n-2))

main()

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main() {
  int K, X;
  cin >> K >> X;
  const char* sep = "";
  for (int i = X - K + 1; i < X + K; ++i) {
    cout << sep << i;
    sep = " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3608
import queue
import copy
 
def ngoin(bo,now):
    return 0 <= now[0] and now[0] < len(bo) and 0 <= now[1] and now[1] < len(bo[0])
 
def minido(bo,si,sj):
    tb = [[False for i in range(len(bo[0]))] for j in range(len(bo))]
    q = queue.Queue()
    q.put([si,sj,0])
    tb[si][sj] = True
    ret = 0
    while not q.empty():
        now = q.get()
        ret = now[2]
        if ngoin(bo,[now[0]-1,now[1]]):
            if bo[now[0]-1][now[1]] and not tb[now[0]-1][now[1]]:
                q.put([now[0]-1,now[1],now[2]+1])
                tb[now[0]-1][now[1]] = True
                
        if ngoin(bo,[now[0],now[1]+1]):
            if bo[now[0]][now[1]+1] and not tb[now[0]][now[1]+1]:
                q.put([now[0],now[1]+1,now[2]+1])
                tb[now[0]][now[1]+1] = True
                
        if ngoin(bo,[now[0]+1,now[1]]):
            if bo[now[0]+1][now[1]] and not tb[now[0]+1][now[1]]:
                q.put([now[0]+1,now[1],now[2]+1])
                tb[now[0]+1][now[1]] = True
                
        if ngoin(bo,[now[0],now[1]-1]):
            if bo[now[0]][now[1]-1] and not tb[now[0]][now[1]-1]:
                q.put([now[0],now[1]-1,now[2]+1])
                tb[now[0]][now[1]-1] = True
    return ret
            
 
h,w = map(int,input().split())
bo = [[True if x == '.' else False for x in input()] for i in range(h)]
grap = [[float('inf') for i in range(h*w)] for j in range(h*w)]
ans = 0
for i in range(h*w):
    grap[i][i] = 0
for si in range(h):
    for sj in range(w):
        if not bo[si][sj]:
            continue
        ans = max(ans,minido(bo,si,sj))
                
print(ans)


Measured memory_bytes: 11120
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

int main() {
int N,M;
cin >> N >> M;
vector<int> L(M);
vector<int> R(M);
int mini = -1,maxi = INF;
for(int i = 0;i < M;i++) {
    cin >> L.at(i) >> R.at(i);
    if (L.at(i) > mini) mini = L.at(i);
    if (R.at(i) < maxi) maxi = R.at(i);
}
if (maxi - mini < -1) cout << 0 << endl;
else cout << maxi - mini +1 << endl;
return 0;
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll x,a,b;
  cin >> x >> a >> b;

  if(a >= b)
    cout << "delicious" << endl;
  else if(b-a <= x)
    cout << "safe" << endl;
  else
    cout << "dangerous" << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>

using namespace std;

int gcd(int n, int m) {
    if (n == 0)
        return m;
    return gcd(m % n, n);
}

int bit_count(int i) {
    i = i - ((i >> 1) & 0x55555555);
    i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
    i = (i + (i >> 4)) & 0x0f0f0f0f;
    i = i + (i >> 8);
    i = i + (i >> 16);
    return i & 0x3f;
}

void print(vector<vector<vector<int>>> &dists, int dir, int h, int w) {
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            cout << dists[y][x][dir];
        }
        cout << endl;
    }
}

int main() {
    int h, w;
    cin >> h >> w;

    vector<vector<bool>> wall(h, vector<bool>(w, false));
    for (size_t i = 0; i < h; i++) {
        for (size_t j = 0; j < w; j++) {
            char t;
            cin >> t;
            wall[i][j] = t == '#';
        }
    }

    // U:0
    // R:1
    // D:2
    // L:3
    vector<vector<vector<int>>> dists(
        h, vector<vector<int>>(w, vector<int>(4, 0)));
    for (int y = 0; y < h; y++) {
        int dist = 0;
        for (int x = 0; x < w; x++) {
            if (wall[y][x]) {
                dist = 0;
                continue;
            }
            dist++;
            dists[y][x][1] = dist;
        }
        dist = 0;
        for (int x = w - 1; x >= 0; x--) {
            if (wall[y][x]) {
                dist = 0;
                continue;
            }
            dist++;
            dists[y][x][3] = dist;
        }
    }
    for (int x = 0; x < w; x++) {
        int dist = 0;
        for (int y = 0; y < h; y++) {
            if (wall[y][x]) {
                dist = 0;
                continue;
            }
            dist++;
            dists[y][x][2] = dist;
        }
        dist = 0;
        for (int y = h - 1; y >= 0; y--) {
            if (wall[y][x]) {
                dist = 0;
                continue;
            }
            dist++;
            dists[y][x][0] = dist;
        }
    }

    int m = 0;
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            m = max(m, dists[y][x][0] + dists[y][x][1] + dists[y][x][2] +
                           dists[y][x][3] - 3);
        }
    }

    cout << m << endl;
}


Measured memory_bytes: 219776
#include<bits/stdc++.h> 
using namespace std; 
int main(){
  long long l, r, d;
  long long cnt=0;
  cin>>l>>r>>d; 
  for(long long i=l;i<=r;i++){
    if(i%d==0)cnt++;
    
    }
  cout<<cnt;
  }

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

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    ll N;
    cin >> N;
    ll Ai;
    vector<ll> A{0};
    for(int i=0;i<N;i++){
        cin >> Ai;
        A.push_back(Ai + A.back());
    }
    ll res = numeric_limits<ll>::max();
    for(int i=2;i<N-1;i++){
        auto itr1 = lower_bound(A.begin(), A.end(), (A[0] + A[i])/2);
        auto itr2 = lower_bound(A.begin(), A.end(), (A[i] + A[N])/2);
        vector<ll> cand1{
            (A[i] - *prev(itr1,0)), (*prev(itr1,0) - A[0]),
            (A[N] - *prev(itr2,0)), (*prev(itr2,0) - A[i]),
        };
        vector<ll> cand2{
            (A[i] - *prev(itr1,0)), (*prev(itr1,0) - A[0]),
            (A[N] - *prev(itr2,1)), (*prev(itr2,1) - A[i]),
        };
        vector<ll> cand3{
            (A[i] - *prev(itr1,1)), (*prev(itr1,1) - A[0]),
            (A[N] - *prev(itr2,0)), (*prev(itr2,0) - A[i]),
        };
        vector<ll> cand4{
            (A[i] - *prev(itr1,1)), (*prev(itr1,1) - A[0]),
            (A[N] - *prev(itr2,1)), (*prev(itr2,1) - A[i]),
        };
        sort(cand1.begin(), cand1.end());
        sort(cand2.begin(), cand2.end());
        sort(cand3.begin(), cand3.end());
        sort(cand4.begin(), cand4.end());
        auto cand = min({
            cand1[3]-cand1[0],
            cand2[3]-cand2[0],
            cand3[3]-cand3[0],
            cand4[3]-cand4[0],
        });
        res = min(res, cand);
    }
    cout<<res<<endl;

    return 0;
}

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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef _DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif

signed main() {

    int a, b;
    string s;
    cin >> a >> b >> s;
    
    bool g=true;
    if(s[a]!='-') g=false;
    rep(i,s.size()){
        if(i==a) continue;
        if(!('0'<=s[i] && s[i]<='9')) g=false;
    }
    if(g)Yes; else No;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) {return (n==0)?1:10*TEN(n-1);}

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

    vector<vector<int>> g(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        scanf("%d%d", &a, &b); a--; b--;
        g[b].push_back(a);
    }

    for (int d: g[n-1]) {
        for (int e: g[d]) {
            if (e == 0) {
                cout << "POSSIBLE" << endl;
                return 0;
            }
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}


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

namespace abc_160b
{
    class Program
    {
        static void Main(string[] args)
        {
            int total = int.Parse(Console.ReadLine());

            int happy500 = (total / 500) * 1000;
            int happy5 = (((total % 500) / 5) * 5);

            Console.WriteLine(happy500 + happy5);
            Console.Read();
        }
    }
}


Measured memory_bytes: 13140
#include<stdio.h>
int main(void){
int f,a,c,i,t,A[100][100],b[100];
	f=0;
	c=0;
	scanf("%d %d",&a,&c);
	for(i=0;i<a;i++){
		for(t=0;t<c;t++){
			scanf("%d",&A[i][t]);
		}
	}
	for(t=0;t<c;t++){
		scanf("%d",&b[t]);
	}
	for(i=0;i<a;i++){
		f=0;
		for(t=0;t<c;t++){
			f+=A[i][t]*b[t];
		}
		printf("%d\n",f);
	}
	return 0;
}

Measured memory_bytes: 2692
#include <bits/stdc++.h>
#define fi first
#define se second
#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 srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin>>n;
  vi mp(100110,0);
  rep(i,n){
    int a;
    cin>>a;
    mp[a]++;
  }
  int ans = 0;
  srep(i,1,100100){
   ans = max(ans,mp[i]+mp[i-1]+mp[i+1]);
  }
  print(ans);
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll n,k;
ll a[20];
bool used[20];

ll ans;
map<ll,bool> mp;

void dfs(ll now, ll num){
	if(now == k){
		if(!mp[num]){
			mp[num] = true;
			ans++;
			//cout << num << "num" << endl;
		}
	}
	for (int i = 0;i < n;i++){
		if(!used[i]){
			ll nn;
			if(a[i] >= 10) nn = num * 100;
			else nn = num * 10;
			nn += a[i];
			used[i] = true;
			dfs(now+1,nn);
			used[i] = false;
		}
	}
	return;
}

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

	while(true){
		cin >> n;
		if(n == 0) break;
		cin >> k;

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

		memset(used,0,sizeof(used));
		mp = map<ll,bool>();
		ans = 0;
		
		dfs(0,0);

		cout << ans << endl;

	}

	return 0;

}



Measured memory_bytes: 3256