akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int m,n;
    int a;
    int sum = 0;
    cin >> n >> m;
    while(m--)
    {
        cin >> a;
        sum = sum + a;
        if(sum > n)
        {
            cout << -1 <<endl;
            break;
        }
    }
    if(sum <= n)
        cout << n - sum <<endl;
    return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;


public class Main {

	static Scanner sc = new Scanner(System.in);
	static int N,A,B,C,X;
	static int[] Y;
	public static void main(String[] args) {
		while(read())	solve();
	}
	private static void solve() {
		int frame = 0;
		int ptr = 0;
		while(true){
			if(Y[ptr] == X)	ptr++;
			X = (A*X + B) % C;
			//System.out.println(X);
			//System.out.println("X=" + X + "\tptr=" + ptr);
			
			if(ptr==N) {
				System.out.println(frame);
				break;
			} else if (frame>=10000) {
				System.out.println("-1");
				break;
			}
			frame++;
		}
	}
	private static boolean read() {
		N = sc.nextInt();
		A = sc.nextInt();
		B = sc.nextInt();
		C = sc.nextInt();
		X = sc.nextInt();
		if (N==0 && A==0 && B==0 && C==0 && X==0) {
			return false;
		}

		Y = new int[N];
		for(int i=0; i<N; i++) {
			Y[i] = sc.nextInt();
		}
		return true;
	}

}

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

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

  vector<int> a(N, 0);
  for (int i = 0; i < N; i++) {
    scanf("%d", &a.at(i));
  }

  sort(a.begin(), a.end());

  int ans = 0;
  for (int i = 0; i < N - 1; i++) {
    ans += a.at(i + 1) - a.at(i);
  }

  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>   
using namespace std;
using namespace __gnu_pbds;
typedef long long ll; 
#define int long long
typedef unsigned long long lu;
typedef vector<ll> v;
typedef vector<vector<ll> > vv;
typedef vector<string>  vs;
typedef vector<pair<ll,ll>> vpr;
typedef vector<bool>vb;
typedef vector<double>vd;
typedef long double ld;
#define f(i,n) for(ll i = 0; i < n; i++)
#define ff(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define amax(x,y) if(y>x) x=y;
#define amin(x,y) if(y<x)x=y;
#define bg(x) x.begin()
#define sz(x) (ll)x.size()
#define in(x,n) for(ll i=0;i<n;i++)cin>>x[i]
#define out(x,n) for(ll i=0;i<n;i++)cout<<x[i]<<" " 
#define mxt(a) *(max_element(a.begin(),a.end()))
#define mnt(a) *(min_element(a.begin(),a.end())
#define tc ll t;cin>>t;while(t--)
typedef pair<ll,ll> pi;
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define yesno(f) if(f) yes else no
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
const ld PI = 2 * acos(0.0);
ll cel(ll x1,ll y1){if((x1%y1)==0)return x1/y1;else return x1/y1+1;}
ll power(ll a,ll b,ll m)
{
    if(b==0)
        return 1;
    ll d=power(a,b/2,m);
    d=(d*d)%m;
    if(b&1)
        d=(d*a)%m;
    return d;
}
const ll mod=1e9+7;
int MOD(int a)
{
    if(a<0)
        a+=mod;
    if(a>=mod)
        a%=mod;
    return a;
}
// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
/*string operations :
str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
str.substr (x) : returns a substring str[x],... end of string
str.find(qtr) : returns the first occurenece of qtr in str */
int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int n;cin>>n;
    cout<<(power(10,n,mod)-2*power(9,n,mod)+power(8,n,mod)+2*mod)%mod;
    return 0;
}

Measured memory_bytes: 3632
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "x", long, "y", long, "cost");
alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less);

void main()
{
    auto n = lread();
    auto s = sread();
    long lcount, rcount;
    foreach (e; s)
    {
        if (e == '(')
            lcount++;
        else
            lcount = max(lcount - 1, 0);
    }
    foreach_reverse (e; s)
    {
        if (e == '(')
            rcount = max(rcount - 1, 0);
        else
            rcount++;
    }
    // lcount.writeln();
    // rcount.writeln();
    writeln('('.repeat(rcount), s, ')'.repeat(lcount));
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 2852
# coding: utf-8
# Your code here!
t1,n1=map(int,input().split())
t2,n2=map(int,input().split()) 
t3,n3=map(int,input().split())
t4,n4=map(int,input().split())
if t1==1:
    print(6000*n1)
if t1==2:
    print(4000*n1)
if t1==3:
    print(3000*n1)
if t1==4:
    print(2000*n2)

if t2==1:
    print(6000*n2)
if t2==2:
    print(4000*n2)
if t2==3:
    print(3000*n2)
if t2==4:
    print(2000*n2)
    
if t3==1:
    print(6000*n3)
if t3==2:
    print(4000*n3)
if t3==3:
    print(3000*n3)
if t3==4:
    print(2000*n3)
    
if t4==1:
    print(6000*n4)
if t4==2:
    print(4000*n4)
if t4==3:
    print(3000*n4)
if t4==4:
    print(2000*n4)


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

int main() {
  int a,b,c;
  cin>>a>>b;
  c=max(a,b);
  b=min(a,b);
  if((c+b)%2==1){
    cout<<"IMPOSSIBLE"<<endl;
  }
  else {
    cout<<(c+b)/2<<endl;
  }
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, w;
    cin >> n >> w;

    vector<pair<int, int>> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i].first >> a[i].second;

    vector<vector<long long>> dp(n + 1, vector<long long>(w + 1, 0));
    for (int i = 1; i <= n; i++){
        for (int j = 0; j <= w; j++){
            if (j - a[i - 1].first >= 0)
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - a[i - 1].first] + a[i - 1].second);
            else
                dp[i][j] = dp[i - 1][j];
        }
    }

    cout << dp[n][w] << '\n';

    return 0;
}


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

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
    
        int k = sc.nextInt();
        int s = sc.nextInt(); // 最大値
        sc.close();
       
        int index = 0;
        int x,y,z;

        for (x = 0;x <= k;x++) {
            for(y = 0;y <= k;y++) {
                z = s - x - y; // 最大値から x と y を引いて z　の数を求める。
                    if(0 <= z && z <= k) {
                        index++;
                    } 
                
            }
        }
        
        System.out.print(index);
        
    }

}

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

int main() {
  int n;
  cin >>n;
  int cnt = 0;
  rep(i,n){
    ll a;
    cin >>a;
    bool can = true;
    while(can){
      if(a%2==0){
        a/=2;
        cnt++;
      }
      else can = false;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <functional>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int n, a[110];
int ans;

signed main() {
	std::random_device rnd;
	std::mt19937_64 mt(rnd());
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	for (int i = 0; i < n; i++)for (int j = i + 1; j < n; j++)for (int k = j + 1; k < n; k++)if (a[i] != a[j] && a[j] != a[k] && a[i] != a[k] && (ll)max({ a[i],a[j],a[k] }) * 2 < (ll)a[i] + a[j] + a[k])ans++;
	cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

int p[15],c[15];

const int MOD = 1e9+7;
int main(){
  int D,G; cin >> D >> G;
  rep(i,D) cin >> p[i] >> c[i];
  
  int ans = 1 << 30;
  for(int bit = 0; bit < (1<<D);bit++){
    int q = 0, score = 0, highest = -1;
    for(int i = 0;i<D;i++){
      if(bit & (1<<i)){
        score += p[i] * (i+1) *100 + c[i];
        q += p[i];
      }else chmax(highest,i);
    }

    if(highest != -1 && G > score){
      int cnt = 1;
      while(cnt < p[highest]){
        score += (highest + 1) * 100;
        q++;
        cnt++;
        if(G <= score) break;
      }
    }
    
    if(score >= G) chmin(ans,q);
  }
  
  cout << ans << endl;
  
  return 0;
}

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

int cnt[100001];

int main() {
    int N;
    cin >> N;
    vector<int> r(N);
    for (auto& i : r) cin >> i;
    sort(r.begin(), r.end());

    for (auto i : r) cnt[i]++;

    int c = 0;
    for (int i = 0; i < 100001; i++) {
        if (cnt[i] > 1) c += cnt[i] - 1;
    }

    cout << N - (c + 1) / 2 * 2 << endl;

    return 0;
}


Measured memory_bytes: 1024
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("o3")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2LL) //等差数列の和、初項,末項,項数
#define pb push_back
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int n;
	scanf("%d", &n);
	map<string, int> m;
	string s;
	rep(i, n) {
		scans(s);
		++m[s];
	}
	printf("%d\n", (int)m.size());

	Please AC;
}


Measured memory_bytes: 18744
#include <iostream>
#include <stack>
#include <deque>
#include <queue>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstdio>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define mp make_pair
#define fname ""
#define fi first
#define se second
#define sz(a) (int)a.size()
#define pb push_back
#define fo(i,k,n) for(int i=k; (int)i<n; ++i)
#define rep(i,n,k) for(int i=n; (int)i>=k; --i)
#define all(v) v.begin(), v.end()
#define it ::iterator
#define forit(it,v) for(__typeof(v.begin()) it = v.begin(); it != v.end(); ++it)


const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int N = 100100;

int a,b,c;

int main(){
    
//freopen(fname"in", "r", stdin);
//freopen(fname"out", "w", stdout);

	cin>>a>>b>>c;

	int k = a*100 + b*10 + c;

	if(k%4 == 0)
		printf("YES");
	else
		printf("NO");
    
    return 0;
}









Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int main() {
	string s, t;
	cin >> s >> t;
	int n = s.size();
	int ans = (int) 1e9;
	for (int i = 0, j = t.size() - 1; j < n; ++i, ++j) {
		int tmp = 0;
		int ind = 0;
		for (int k = i; k <= j; ++k) {
			if (s[k] != t[ind++]) {
				++tmp;
			}
		}
		ans = min(ans, tmp);
	}
	cout << ans;
}

Measured memory_bytes: 3200
NN = input().split()
N = int(NN[0])
M = int(NN[1])
AA = input().split()
total1 = 0
total2 = 0
for i in AA:
  total1 += int(i)
for i in AA:
  if float(i) >= total1/(4*M):
    total2 +=1
if total2 >= M:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9088
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  vector<ll> n(5);
  for(int i = 0;i < 5;i++)cin >> n[i];
  ll res = 0;
  for(int i = 0;i < 5;i++){
    if(n[i] == 0)res = i + 1;
  }
  cout << res << endl;
}

Measured memory_bytes: 3588
#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;
typedef long long ll;
typedef unsigned long long ull;

typedef long double R;
typedef complex<R> P;

struct C {
    P p;
    R r;
    C() {}
    C(P p, R r) : p(p), r(r) {}
};
const int MN = 24;

int n;
bool g[MN][MN];
int col[MN];


short dp[1<<MN];

int calc(int m) {
    if (dp[m] != -1) return dp[m];
    int ma = 0;
    bool can[MN];
    for (int i = 0; i < n; i++) {
        can[i] = true;
        for (int j = 0; j < i; j++) {
            if (m & (1<<j)) continue;
            if (g[i][j]) {
                can[i] = false;
                break;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            if (col[i] != col[j]) continue;
            if (m & (1<<i)) continue;
            if (m & (1<<j)) continue;
            if (!can[i]) continue;
            if (!can[j]) continue;
            ma = max(ma, 2+calc(m | (1<<i) | (1<<j)));
        }
    }
    return dp[m] = ma;
}

bool solve() {
    cin >> n;
    if (!n) return false;
    C c[MN];

    for (int i = 0; i < n; i++) {
        R x, y, r;
        cin >> x >> y >> r >> col[i];
        c[i] = C(P(x, y), r);
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < i; j++) {
            g[i][j] = (abs(c[i].p - c[j].p) < c[i].r+c[j].r);
        }
    }
    memset(dp, -1, sizeof(dp));
    cout << calc(0) << endl;
    return true;
}

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

Measured memory_bytes: 34024
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <string.h>
#include <stdlib.h>

using namespace std;
// vector push_back push front top empty pop make_pair long long insert begin end  
typedef long long ll;
typedef vector<int> vi;
typedef vector<pair <int,int> > vpi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define B begin()
#define RB rbegin()
#define E end()
#define RE rend()
#define Z size()
#define REP(i,a,b) for (int i = a; i < b; i++)
#define L length()
#define show(a) cerr << " *** " << a << endl;
#define show1(a) cerr << " /// " << a << endl;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin >> n;
	if (n&1)
		cout << (n-1)/2;
	else
		cout << n /2 - 1;
}


Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine();
        string[] strinputArray = input.Split(' ');
        int[] intinputArray = Array.ConvertAll<string, int>(strinputArray, delegate (string value) { return int.Parse(value); });
        if (intinputArray[0] <= intinputArray[1] && intinputArray[0] <= intinputArray[2])
        {
            if (intinputArray[1] <= intinputArray[2])
            {
                Console.WriteLine(intinputArray[0] + " " + intinputArray[1] + " " + intinputArray[2]);
            }
            else
            {
                Console.WriteLine(intinputArray[0] + " " + intinputArray[2] + " " + intinputArray[1]);
            }
        }
        else if (intinputArray[0] >= intinputArray[1] && intinputArray[0] >= intinputArray[2])
        {
            if (intinputArray[1] <= intinputArray[2])
            {
                Console.WriteLine(intinputArray[1] + " " + intinputArray[2] + " " + intinputArray[0]);
            }
            else
            {
                Console.WriteLine(intinputArray[2] + " " + intinputArray[1] + " " + intinputArray[0]);
            }
        }
    }
}


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

typedef long long ll;

string s;

int main() {
    cin >> s;
    char b1 = s[0];
    int b2 = (s.size() - 2);
    char b3 = s[s.size() - 1];

    // cout << b2 << endl;
    // cout << b1 << b2 << b3;
    cout << b1 << b2 << b3 << endl;
}

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

int main() {
  vector<int> a(4);
  for (auto &e : a) {
    cin >> e;
  }
  sort(begin(a), end(a));
  cout << (a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9 ? "YES" : "NO") << endl;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int main()
{  long long int n,i,s=0;
  cin>>n;
 for(i=1;i<=n;i++)
 {
     if(i%5!=0&&i%3!=0)
     s+=i;
     
 }
 cout<<s;
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
	int H, R;
	cin >> H >> R;

	if (H + R == 0) cout << 0 << endl;
	else if (H + R > 0) cout << 1 << endl;
	else cout << -1 << endl;

	return 0;
}


Measured memory_bytes: 3108
lst = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(lst[int(input())-1])

Measured memory_bytes: 3060
# https://atcoder.jp/contests/abc074/tasks/abc074_b

N = int(input())
K = int(input())
x_list = list(map(int, input().split()))

ans = 0
for x in x_list:
    K_x = K - x

    if K_x >= x:
        ans += x*2

    elif K_x < x:
        ans += K_x*2

print(ans)

Measured memory_bytes: 2940
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cassert>
#include <cmath>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>

using namespace std;

#define INF 1e+9
#define mp make_pair
#define pb push_back
#define fi first
#define fs first
#define se second
#define i64 long long
#define li long long
#define lint long long
#define pii pair<int, int>
#define vi vector<int>

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define fore(i, b, e) for (int i = (int)b; i <= (int)e; i++)

const int maxn = 105;

int a[maxn][maxn];
int n, m;

bool move(pii& cur, pii change) {
    pii tmp = mp(cur.fi + change.fi, cur.se + change.se);
    if (tmp.fi < 0 || tmp.fi >= n || tmp.se < 0 || tmp.se >= m || a[tmp.fi][tmp.se] != 0)
        return false;
    cur = tmp;
    return true;
}

int main() {
#ifdef LOCAL
    freopen("inp", "r", stdin);
    //freopen("outp", "w", stdout);
#else
    // freopen(TASKNAME ".in", "r", stdin);
    // freopen(TASKNAME ".out", "w", stdout);
#endif
    int c;
    scanf("%d%d%d", &n, &m, &c);
    pii cur = mp(0, 0);
    pii LEFT = mp(0, -1);
    pii RIGHT = mp(0, 1);
    pii DOWN = mp(1, 0);
    fore(j, 1, c) {
        int cnt;
        scanf("%d", &cnt);
        forn(iter, cnt) {
            a[cur.fi][cur.se] = j;
            //printf("iter = %d cur = %d %d\n", iter, cur.fi, cur.se);
            if (move(cur, RIGHT))
                continue;
            if (move(cur, LEFT))
                continue;
            move(cur, DOWN);
        }
    }
    forn(i, n) {
        forn(j, m)
            printf("%d ", a[i][j]);
        printf("\n");
    }
}



Measured memory_bytes: 384
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};//RDLU
/*
int main(){
	ll n,x;
	cin>>n>>x;
	vi in(n);
	rep(i,n)cin>>in[i];
	if(n>2001)return 0;
	ll out=inf;
	loop(i,1,n+1){
		ll sum=(n+i)*x;
		rep(j,i)sum+=in[n-1-j];
		for(int j=n-1;j>=0;j--){
			ll dis;
			if(j-i>=0)dis=in[j]-in[j-i];
			else dis=in[j];
			sum+=dis*((n-j-1)/i+2)*((n-j-1)/i+2);
		}
		out=min(out,sum);
	}
	
	cout<<out<<endl;
}
*/
int n,m;
string s;
vvi G,co;
vi used;
void dfs(int a){
	used[a]=0;
	rep(i,G[a].size()){
		int to=G[a][i];
		if(used[to]==0)continue;
		co[a]['A'!=s[to]]--;
		co[to]['A'!=s[a]]--;
	}
//	cout<<a<<endl;
//	show2d(co);
	rep(i,G[a].size()){
		int to=G[a][i];
		if(used[to]&&(co[to][0]==0||co[to][1]==0))
			dfs(to);
	}
}
int main(){
	cin>>n>>m>>s;
	G=vvi(n);
	used=vi(n,1);
	co=vvi(n,vi(2));
	rep(i,m){
		int a,b;
		cin>>a>>b;
		a--;b--;
		G[a].pb(b);
		G[b].pb(a);
		co[a]['A'!=s[b]]++;
		co[b]['A'!=s[a]]++;
	}
	rep(i,n)if(used[i]&&(co[i][0]==0||co[i][1]==0)){
		dfs(i);
	}
	
//	show2d(co);
//	show1d(used);
	
	bool h=false;
	rep(i,n)if(used[i])h=true;
	if(h)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}










Measured memory_bytes: 23428
from sys import exit, stderr, stdin
input = stdin.readline
# setrecursionlimit(10**7)

def debug(var, name="hoge"):
    print(str(type(var)) + name +":" + " = " + repr(var), file=stderr)
    return


def main():
    A, B, C = sorted(list(map(int,input().split())))
    print(A+B)
    # N = int(input())
    # a = [int(input()) for _ in range(N)]
    # S = str(input())[:-1]
    # print(S)
    # L = len(S)
    # INF = 10000000002
    # EPS = 1e-9
    # exit()


if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		if(c <= a) {
			int w = a;
			a = c;
			c = w;
			int y = b;
			b = d;
			d = y;
		}
		//これでa<cである
		if(b <= c) {
			System.out.println(0);
			return;
		}
		if(b <= d) {
			System.out.println(b - c);
		} else {
			System.out.println(d - c);
		}
	}
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    lint n, k;
    cin >> n >> k;
    vector<pair<lint, lint>> p(n);
    repeat(i, n) cin >> p[i].fst >> p[i].snd;
    
    auto inside_points = [&p](lint xmin, lint xmax, lint ymin, lint ymax) {
        vector<pair<lint, lint>> v;
        for (auto e: p) {
            if (xmin <= e.fst and e.fst <= xmax and ymin <= e.snd and e.snd <= ymax) {
                v.emplace_back(e);
            }
        }
        return v;
    };
    
    lint ans = numeric_limits<lint>::max();
    for (auto p1: p) for (auto p2: p) for (auto p3: p) for (auto p4: p) {
        lint xmin = p1.fst;
        lint xmax = p2.fst;
        lint ymin = p3.snd;
        lint ymax = p4.snd;
        if (xmin > xmax) continue;
        if (ymin > ymax) continue;
        
        auto v = inside_points(xmin, xmax, ymin, ymax);
        if ((int)v.size() >= k) {
            ans = min(ans, (xmax - xmin) * (ymax - ymin));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	final static long MOD = 1000000007;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.next().length();

		long[][] dp = new long[2][N+1];
		dp[0][0] = 1;
		long[] zero = new long[N+1];
		zero[0] = 1;
		for(int i=0; i<N; i++) {
			Arrays.fill(dp[(i+1)%2], 0);
			for(int j=0; j<=i; j++) {
				dp[(i+1)%2][j+1] = (dp[(i+1)%2][j+1] + dp[i%2][j]*2)%MOD;
				dp[(i+1)%2][Math.max(0, j-1)] = (dp[(i+1)%2][Math.max(0, j-1)] + dp[i%2][j])%MOD;
			}
			zero[i+1] = dp[(i+1)%2][0];
		}
		for(int i=0; i<=N; i++)
			for(int j=0; j<(N-i-M)/2; j++)
				zero[i] = (zero[i]*2)%MOD;
		
		for(int i=0; i<N; i++) {
			Arrays.fill(dp[(i+1)%2], 0);
			dp[i%2][0] = zero[i];
			for(int j=0; j<=i; j++) {
				dp[(i+1)%2][j+1] = (dp[(i+1)%2][j+1] + dp[i%2][j])%MOD;
				if(j-1>0)
					dp[(i+1)%2][j-1] = (dp[(i+1)%2][j-1] + dp[i%2][j])%MOD;
			}
		}
		
		System.out.println(dp[N%2][M]);
		
		sc.close();
	}
	
}


Measured memory_bytes: 11040
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        String[] lines = getStdin();
        String[] str = lines[0].split(" ");
        int n = Integer.parseInt(str[0]);
        int m = Integer.parseInt(str[1]);
        
        //獲得票数をint型配列へ
        String[] str2 = lines[1].split(" ");
        int[] z = new int[n];
        ArrayList<Integer> h = new ArrayList<>();
            for(int i = 0; i < n; i++){
                z[i] = Integer.parseInt(str2[i]);
                h.add(z[i]);
            }
        Collections.sort(h);
        Collections.reverse(h);
            //総獲得票数
        int total = 0;
            for (int i = 0; i < h.size(); i++){
                total = total + h.get(i);
            }
            //M番目の人気商品が全体の1/4M以下ならno
            if(h.get(m - 1) < total*1.0/(4.0*m)){
                System.out.println("No");
            } else {
            System.out.println("Yes");
            }
   }
  private static String[] getStdin() {
    Scanner scanner = new Scanner(System.in);
    ArrayList<String> lines = new ArrayList<>();
    while (scanner.hasNext()) {
      lines.add(scanner.nextLine());
    }
    return lines.toArray(new String[lines.size()]);
  }
}

Measured memory_bytes: 27036
N = int(input())
alist = list(map(int, input().split()))
m1, m2 = 0, 0
for i, a in enumerate(alist):
  if i == 0:
    m1+=a
    m2+=a
  elif i%2 == 0:
    m1+=a
    m2+=-1*a
  else:
    m1+=-1*a
    m2+=a    

ans = [m1, m2]
for i in range(2, N-1, 2):
  # index=i
  ans.append(ans[i-2] -2*alist[i-2] + 2*alist[i-1])
  # index=i+1
  ans.append(ans[i-1] - 2*alist[i-1] + 2*alist[i])

ans.append(ans[N-3] - 2*alist[N-3] + 2*alist[N-2])

print(*ans)

Measured memory_bytes: 14400
#include<iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int paper[14][14];
int white=0,mdro=0;
int main(){int a,c,e;char b,d;
while(cin>>a>>b>>c>>d>>e){
	if(e==3){
    paper[a][c+2]++;
	paper[a+1][c+1]++;
	paper[a+1][c+2]++;
	paper[a+1][c+3]++;
	paper[a+2][c]++;
	paper[a+2][c+1]++;
	paper[a+2][c+2]++;
	paper[a+2][c+3]++;
	paper[a+2][c+4]++;
	paper[a+3][c+1]++;
	paper[a+3][c+2]++;
	paper[a+3][c+3]++;
	paper[a+4][c+2]++;}else
	if(e==2){
	paper[a+1][c+1]++;
	paper[a+1][c+2]++;
	paper[a+1][c+3]++;
	paper[a+2][c+1]++;
	paper[a+2][c+2]++;
	paper[a+2][c+3]++;
	paper[a+3][c+1]++;
	paper[a+3][c+2]++;
	paper[a+3][c+3]++;}else{
	paper[a+1][c+2]++;
	paper[a+2][c+1]++;
	paper[a+2][c+2]++;
	paper[a+2][c+3]++;
	paper[a+3][c+2]++;}}
for(int i=0;i<10;i++){
for(int ii=0;ii<10;ii++){
	if(paper[i+2][ii+2]==0){
	white++;}else
		if(paper[i+2][ii+2]>mdro){mdro=paper[i+2][ii+2];}}}
cout<<white<<endl<<mdro<<endl;
	return 0;}


Measured memory_bytes: 1160
# import sys
# readline = sys.stdin.readline
# generator = (readline().strip() for _ in range(N))

# import numpy as np
# from itertools import permutations
# from itertools import combinations
# from itertools import combinations_with_replacement
# import queue
# import heapq

# N, M = map(int, input().split())
# As = list(map(int, input().split()))
# queries = (input() for _ in range(N))


def solve():
    K = int(input())
    S = input()

    if len(S) <= K:
        return S
    else:
        return S[:K] + '...'


def main():
    print(solve())


if __name__ == "__main__":
    main()


Measured memory_bytes: 9108
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(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 = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

bool visit[101];
vvl G(101);

bool dfs(ll u, ll i){
	bool res = false;
	visit[u] = true;
	for(auto v : G[u]){
		if(v == i) return true;
		if(visit[v]) continue;
		res = res || dfs(v,i);
	}
	return res;
}

int main(){
	ll n,m; cin >> n >> m;
	rep(i,m){
		ll u,v; cin >> u >> v;
		G[u].push_back(v);
	}
	rep(i,n){
		rep(j,n) visit[j] = false;
		if(dfs(i,i)){
			puts("1");
			return 0;
		}
	}
	puts("0");
}


Measured memory_bytes: 3160
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Main {
	public static void main(String[] args) throws Exception {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		String buf = br.readLine();
		int n = Integer.valueOf(buf);

		buf = br.readLine();
		String[] a = buf.split(" ", 0);

		List<Integer> aList = Stream.of(a)
		    .map(Integer::valueOf)
		    .sorted(Comparator.reverseOrder())
		    .collect(Collectors.toList());

		int alice = 0;
		int bob = 0;
		for (int i = 0; i < aList.size(); i++) {
			if (i % 2 == 0) {
				alice += aList.get(i);
			} else {
				bob += aList.get(i);
			}
		}

		System.out.println(alice - bob);
	}

}


Measured memory_bytes: 28116
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const int maxm = 1e6 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
int n,r;
int main(){
//	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); 
	cin >> n >> r;
	if(n >= 10) cout << r << endl;
	else cout << r + 100 * (10-n) << endl;
    return 0;
}


Measured memory_bytes: 256
n=int(input())
s=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))
ans=0
for i in range(m):
    mini=0
    maxi=n-1
    flag=0
    while flag==0:
        if mini>=maxi:
          flag=1
        mid=(mini+maxi+1)//2
        if t[i]<s[mid]:
            maxi=mid-1
        elif t[i]>s[mid]:
            mini=mid+1
        else:
            ans+=1
            break
print(ans)


Measured memory_bytes: 16708
package main

import "fmt"

func scanNums(nums_len int) (nums []int) {
	var num int
	for i := 0; i < nums_len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}

func main() {
	var n int
	fmt.Scan(&n)
	nums := scanNums(n)
	nums = append(nums, 101)

	sum := 0
	max := 0
	for i := 0; i < n; i++ {
		if i == 0 {
			sum++
		} else if max <= nums[i] {
			sum++
		}

		if nums[i] > max {
			max = nums[i]
		}
	}

	fmt.Println(sum)
}


Measured memory_bytes: 512
import sys


def estimate(A, B, C, K):
    N_A = A
    if(N_A >=K):
        N_A = K
        N_B = 0
        N_C = 0
        return N_A
    N_B = B
    if(N_A+N_B >= K):
        return N_A
    N_C = K- (N_A+N_B)
    return N_A-N_C



if(__name__ == "__main__"):
    ABCK = input().split()

    A= int(ABCK[0].strip())
    B= int(ABCK[1].strip())
    C= int(ABCK[2].strip())
    K= int(ABCK[3].strip())

    # print(A, B, C, K)
    value = estimate(A, B, C, K)
    print(value)


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

int m,n,ans,dp[2][N][N][N];
char mm[N][N];
bool now,cur;

inline void Max(int &u,int v){if(v>u) u=v;}
int main()
{
	int i,j,p,q,l,r,mid;
	cin>>m>>n;
	for(i=1;i<=m;i++) scanf("%s",mm[i]+1);
	now=1;
	for(q=1;q<=m;q++)
	{
		for(p=q;p>=1;p--)
		{
			for(i=n;i>=1;i--)
			{
				if(p==q)
				{
					if(i==n) dp[now][p][q][i]=n+1;
					if(mm[p][i]==mm[p][i+1]) dp[now][p][q][i]=dp[now][p][q][i+1];
					else dp[now][p][q][i]=i+1;
				}
				else
				{
					if(mm[q-1][i]==mm[q][i]) dp[now][p][q][i]=min(dp[now][p][q-1][i],dp[now][q][q][i]);
					else dp[now][p][q][i]=i;
				}
			}
		}
	}
	for(ans = 0; ;ans ++)
	{
		if(dp[now][1][m][1]==n+1)
		{
			cout << ans << endl;
			return 0;
		}
		swap(now,cur);
		for(p = 1; p<=m; p++)
		{
			for(q = p; q <= m; q++)
			{
				for(i = 1;i <= n;i++)
				{
					if(dp[cur][p][q][i]==n+1) dp[now][p][q][i]=n+1;
					else dp[now][p][q][i]=dp[cur][p][q][dp[cur][p][q][i]];
					for(l = p,r = q; l < r;)
					{
						mid=((l+r)>>1);
						Max(dp[now][p][q][i],min(dp[cur][p][mid][i],dp[cur][mid+1][q][i]));
						if(dp[cur][p][mid][i]>dp[cur][mid+1][q][i]) l=mid+1;
						else r=mid;
					}
				}
			}
		}
	}
}

Measured memory_bytes: 61440
#include <iostream>
#include <iomanip>
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <vector>
#include <cassert>
#include <fstream>
#include <algorithm>
#include <list>
#include <random>
#include <ctime>
#include <cmath>
#include <random>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
//#define int ll
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ld, ld> pld;
typedef complex<double> base;

#define mmin(a, b) a = min(a, (b))
#define mmax(a, b) a = max(a, (b))
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define ALL(a) a.begin(),a.end()
#define sqr(x) (x) * (x)
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define cint const int &
#define SZ(a) ((int)(a.size()))
#define watch(x) cout << (#x) << " = " << x << endl;

const double PI = 2 * acos(0.0);


template<class T>
void show(const vector<T> &a) {
    for (T x : a)
        cout << x << " ";
    cout << endl;
}

const int N = 2e5 + 9;
const ll oo = 1e18;

ll a[N];
ll pref[N];

ll get_sum(int l, int r) {
    if (!l--) return pref[r];
    return pref[r] - pref[l];
}

pll mlow(int L, int R) {
    int l = L + 1;
    int r = R;
    while (l < r) {
        int m = (l + r) >> 1;
        if (get_sum(L, m - 1) <= get_sum(m, R))
            l = m;
        else
            r = max(L, m - 1);
        if (l == r - 1) {
            if (get_sum(L, r - 1) <= get_sum(r, R))
                l = r;
            else
                r = l;
        }
    }
    pll ret = mp(get_sum(L, r - 1), get_sum(r, R));
    return mp(min(ret.first, ret.second), max(ret.first, ret.second));
}

pll mhig(int L, int R) {
    int l = L + 1;
    int r = R;
    while (l < r) {
        int m = (l + r) >> 1;
        if (get_sum(L, m - 1) >= get_sum(m, R))
            r = m;
        else
            l = min(R, m + 1);
        if (l == r - 1) {
            if (get_sum(L, l - 1) >= get_sum(l, R))
                r = l;
            else
                l = r;
        }
    }
    pll ret = mp(get_sum(L, r - 1), get_sum(r, R));
    return mp(min(ret.first, ret.second), max(ret.first, ret.second));
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;
    fori (i, n) {
        cin >> a[i];
        if (i) pref[i] = pref[i - 1];
        pref[i] += a[i];
    }
    ll ans = oo;
    for (int i = 2; i <= n - 2; ++i) {
        vector<pll> a = {mlow(0, i - 1), mhig(0, i - 1)};
        vector<pll> b = {mlow(i, n - 1), mhig(i, n - 1)};
        for (auto p1 : a) for (auto p2 : b)
            mmin(ans, max(p1.second, p2.second) - min(p1.first, p2.first));

    }
    cout << ans;
}



Measured memory_bytes: 3328
#define MOD_TYPE 1

#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;
/*
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
*/
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
constexpr int INF = (int)1e9;
constexpr ll LINF = (ll)4e18;
constexpr ld PI = acos(-1.0);
constexpr ld EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

inline void init_main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
}
template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
#pragma endregion

int main()
{
  init_main();

  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  vector<pll> p;
  ll before = -1;
  bool zero[100010] = {};
  rep(i, n)
  {
    if (a[i] > before)
    {
      p.emplace_back(MP(a[i], i));
      before = a[i];
    }
    else
    {
      zero[i] = true;
    }
  }

  ll d[100010];
  d[0] = a[0];
  REP(i, 1, p.size())
  {
    d[p[i].second] = p[i].first - p[i - 1].first;
  }

  ll Max_add[100010] = {};
  ll cnt[100010] = {};
  /*
  for (auto pi : p)
  {
    cerr << pi.first << " " << pi.second << endl;
  }*/

  rep(i, n)
  {
    auto itr = lower_bound(all(p), MP(a[i], -1LL));
    int j = itr->second;

    if (j == 0)
    {
      cnt[0] += a[i];
    }
    else
    {
      int j_prev = (itr - 1)->second;
      Max_add[j_prev]++;
      ll a_prev = (itr - 1)->first;
      cnt[j] += a[i] - a_prev;
    }
  }

  for (int i = 100005; i >= 0; i--)
    Max_add[i] += Max_add[i + 1];

  rep(i, n)
  {
    if (zero[i])
    {
      cout << 0 << "\n";
    }
    else
    {
      cout << Max_add[i] * d[i] + cnt[i] << "\n";
    }
  }

  return 0;
}


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

#define L 100005

typedef struct kozo{
  char name[100];
  int t;
}P;

P Q[L+1];
int head, tail,n;

void enqueue(P x){
  Q[tail]=x;
  tail=(tail+1)%L;
}

P dequeue(){
  P x=Q[head];
  head =(head +1)%L;
  return x;
}
int min(int a,int b){return a<b ? a:b;}


int main(){
  int elaps = 0,c;
  int i,q;
  P u;
  scanf("%d %d", &n,&q);

  for(i=1;i <= n;i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
  }
  head = 1;
  tail = n+1;

  while(head != tail){
    u = dequeue();
    c = min(q,u.t);
    u.t-=c;
    elaps+=c;
    if(u.t>0) enqueue(u);
    else{
      printf("%s %d\n",u.name,elaps);
    }
  }

  return 0;
}

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

int main() {
    string s;
    cin >> s;
    int c_count = 0;
    if(s[0] != 'A') {
        cout << "WA" << endl;
        return 0;
    }
    if(isupper(s[1]) || isupper(s[s.size()-1])) {
        cout << "WA" << endl;
        return 0;
    }
    for(int i=2; i<s.size()-1; i++) {
        if(s[i] == 'C') {
            c_count++;
            if(c_count > 1) {
                cout << "WA" << endl;
                return 0;
            }
        }
        else if(isupper(s[i])) {
            cout << "WA" << endl;
            return 0;
        }
    }
    if(c_count == 0) {
        cout << "WA" << endl;
        return 0;
    }
    cout << "AC" << endl;
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

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

  int n,k,num;
  while(cin >> n >> k) {
    if(n+k == 0) break;
    vector<int> seq(n+1,-1);
    for(int i=1;i<=k;i++) {
      cin >> num;
      seq[num] = num;
    }
    int max_cnt,cnt;
    max_cnt = cnt = 0;
    if(seq[0] == -1) {
      for(int i=1;i<=n;i++) {
        if(seq[i] == -1) {
          max_cnt = max(max_cnt,cnt);
          cnt = 0;
        }
        else {
          cnt++;
        }
      }
    }
    else {
      bool use_empty = false;
      int bf_i;
      for(int i=1;i<=n;i++) {
        if(seq[i] == -1) {
          max_cnt = max(max_cnt,cnt);
          if(!use_empty) {
            use_empty = true;
            bf_i = i;
            cnt++;
          }
          else {
            use_empty = false;
            i = bf_i;
            cnt = 0;
          }
        }
        else {
          cnt++;
        }
      }
    }
    max_cnt = max(max_cnt,cnt);
    cout << max_cnt << endl;
  }
}

Measured memory_bytes: 1532
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <math.h> //円周率はM_PI
using namespace std;


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

	if (w >= s) {
		cout << "unsafe" << endl;
	}
	else {
		cout << "safe" << endl;
	}

}


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

#ifdef LOCAL
	#define de(x) cout<<#x<<"="<<x<<endl
	#define rff freopen("input.txt","r",stdin)
	#include "Debug.h"
#else
	#define de(x)
	#define rff
#endif

#define itr(x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();it++)
#define no_sync ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define For(i,n) for (int i=1;i<=(int)(n);i++)
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define all(x) (x).begin(),(x).end()
#define PQ priority_queue
#define pii pair<int,int>
#define vi vector <int>
#define lb lower_bound
#define ub upper_bound
#define ll long long
#define pb push_back
#define mp make_pair
#define re return
#define se second
#define fi first
const int INF=0x7fffffff;
const int MAXN=100+3;

double ava,mx=INF;
int a[MAXN],n,ans;

int main(){
	cin>>n;
	rep(i,n){
		cin>>a[i];
		ava+=a[i];
	}
	ava/=n;
	rep(i,n){
		if (fabs((double)a[i]-ava)<mx){
			ans=i;
			mx=fabs((double)a[i]-ava);
		}
	}
	cout<<ans;
	re 0;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
A = list(map(int, input().split()))
M = max(A)
if K > M:
    print("IMPOSSIBLE")
    exit()

def gcd(n,m):
    if n < m:
        tmp = n
        n = m
        m = tmp
    while n % m != 0:
        tmp = m
        m = n % m
        n = tmp
    return m
g = M
for a in A:
    g = gcd(g,a)
    if g == 1:
        break
if K % g == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 14104