akhauriyash/Code-Regression huggingface dataset:
n, l = map(int, input().split())
expected = sum([l+i-1 for i in range(1, n+1)])

diff = 10 ** 9
result = 10 ** 9

for i in range(1, n+1):
  reduced = expected - (l+i-1)
  if abs(expected - reduced) < diff:
    diff = abs(expected - reduced)
    result = reduced

print(result)

Measured memory_bytes: 9052
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#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=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int kurai(int a,int b){
  int m=pow(10,b),n=pow(10,b-1);
  return (a%m)/n;
}
int ketawa(int a){
  int k=0;
  rep(i,keta(a)){
  k+=kurai(a,i+1);
  }
  return k;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
int mid(int a,int b,int c){
  vector<int> k(3);
  k[0]=a;k[1]=b;k[2]=c;
  sort(all(k));
  return k[1];
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
 if(!b)return 1; if(b&1)return modpow(a,b-1,m)*a%m;
 int memo = modpow(a,b>>1,m);
 return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
 int a,b;
  cin>>a>>b;
  vector<int> c(a),d(a);
  int e=0;
  rep(i,a)
    cin>>c[i]>>d[i];
  rep(i,a){
  if(c[i]*c[i]+d[i]*d[i]<=b*b)
    e++;
  }
  out(e);
}

Measured memory_bytes: 6488
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
char a[8],b[8];
using namespace std;

int main()
{
	while(~scanf("%s %s",a,b)){
		if((a[0]==b[2])&&(a[1]==b[1])&&(a[2]==b[0]))
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}

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

int main(){
	int n, i;
	int h[200] = {0};
	int most = 0;
	while(cin >> n){
		h[n]++;
		if (most < h[n]) {
			most = h[n];
		}
	}
	for (i = 1; i <= 100; i++) {
		if (h[i] == most) {
			cout << i << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
package main

import (
        "fmt"
)

func main() {
    var (
        a, b int
    )
        fmt.Scanf("%d %d", &a, &b)

    if (multipleResultIsEven(a, b) == true) {
        fmt.Println("Even")
    } else {
        fmt.Println("Odd")
    }
}

func multipleResultIsEven(a int, b int) bool {
    if (a * b % 2 == 0){
        return true
    } else {
        return false
    }
}

Measured memory_bytes: 1832
#include<iostream>
#include<sstream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cfloat>
#include<functional>
#include<map>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<bitset>
#include<list>
#include<numeric>
#include<complex>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<long long, long long> ll_ll;
typedef pair<double, double> d_d;
typedef vector<int> Vint;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define rep2d(i, j, n) for(i = 0;i < n;++i)for(j = i + 1;j < n;++j)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)


signed main(void){
  int i, j, k;
  for(int testcase = 0;testcase >= 0;testcase++){
    ll2(a, b);
    if(a * b <= 0)puts("Zero");
    else if(a < 0 && b < 0){
      if((b - a) % 2 == 1)puts("Positive");
      else puts("Negative");
    }else puts("Positive");

/*/

//*/ break;
  }
  return 0;
}


Measured memory_bytes: 764
// Algorithm.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <algorithm>

using namespace std;


void Trace(int a[], int b) {
	for (int i = 0; i < b; i++) {
		if (i != 0) cout << ' ' << flush;
		cout << a[i] << flush;
	}
	cout << endl;
}


void Insertation_Sort(int a[], int b) {
	for (int i = 1; i < b; i++) {
		int v, j;
		v = a[i];
		j = i - 1;
		while (j >= 0 && a[j] > v) {
			a[j + 1] = a[j];
			j--;
		}
		a[j + 1] = v;
		Trace(a, b);
	}
}//挿入ソート
void Bubble_Sort(int a[], int b) {
	int count = 0;
	bool flag = true;
	int c;
	while (flag) {
		flag = false;
		for (int i = b - 1; i > 0; i--) {
			if (a[i] < a[i - 1]) {
				c = a[i];
				a[i] = a[i - 1];
				a[i - 1] = c;
				flag = true;
				count++;
			}
		}
	}
//	cout << count << endl;



}
int Selection_Sort(int a[], int b) {
	int c, count = 0;
	for (int i = 0; i < b; i++) {
		int minj = i;
		for (int j = i; j < b; j++) {
			if (a[j] < a[minj])
				minj = j;
		}
		c = a[i];
		a[i] = a[minj];
		a[minj] = c;
		if (minj != i) count++;
	}

	return count;

}



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



	int count = Selection_Sort(a, b);
	Trace(a, b);
	cout << count << endl;
}

/* 
bubbleSort(A, N) // N 個の要素を含む 0-オリジンの配列 A
2   flag = 1 // 逆の隣接要素が存在する
3   while flag
4     flag = 0
5     for j が N-1 から 1 まで
6       if A[j] < A[j-1]
7         A[j] と A[j-1] を交換
8         flag = 1
*/


Measured memory_bytes: 3128
//rohitaas_15
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> o_set;
#define ll  long long
#define int ll
#define um(a,b) unordered_map<a,b>
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(v) v.begin(),v.end()
#define f(a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define ff first
#define ss second
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define show(x) cout<<x<<"\n"
#define printvector(v,x,n) f(x,n-1){cout<<v[i]<<" ";}
#define input(v,n) f(0,n-1){cin>>v[i];}
#define vr vector<ll>
#define check() cout<<"hi"<<"\n"
#define MOD 1000000007
//#define endl "\n"
#define len() length()
#define con continue
#define maxv(v) *max_element(all(v));
#define minv(v) *min_element(all(v));
#define sumv(v) accumulate(all(v),0)
#define test() ll t;cin>>t;while(t--)
ll search(vr arr, ll l, ll r, ll x){if (r >= l) {ll mid = l + (r - l) / 2;if (arr[mid] == x)return mid;if (arr[mid] > x)return search(arr, l, mid - 1, x);return search(arr, mid + 1, r, x);} return -1;}
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll lcm(ll a , ll b){return (a*b)/ gcd(a,b);}
ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){ if (y & 1) res = (res*x) % p; y = y>>1;x = (x*x) % p; } return res; }
ll modInverse(ll n, ll p){return power(n, p-2, p);}
ll CmP(ll n, ll r, ll p=MOD){if (r==0)return 1;ll fac[n+1];fac[0] = 1;for (ll i=1 ; i<=n; i++)fac[i] = fac[i-1]*i%p; return (fac[n]* modInverse(fac[r], p) % p *modInverse(fac[n-r], p) % p) % p; }
/*ll constructSTUtil(vr v,ll start,ll end,int *st,ll index)
{
	if(start==end)
	{
		st[index]=v[start];
		return st[index];
	}
	ll mid=(start+end)/2;
	st[index]=constructSTUtil(v,start,mid,st,2*index)+constructSTUtil(v,mid+1,end,st,2*index+1);
	return st[index];
}
ll *constructST(vr v,ll n)
{
	ll po=(ll)(ceil(log2(n)));
	ll msize=2*power(2,po)+1;
	vr st[msize];
	constructSTUtil(v,0,n-1,st,1);
	return st;
}*/
ll ask1(ll y)
{
	cout<<1<<" "<<y<<endl;
	ll x;
	cin>>x;
	return x;
}


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

	 int t=1;
	 //cin>>t;
	 int cccc=t;
	while(t--)
	 {
	 	ll k;
	 	string s;
	 	cin>>k;
	 	cin>>s;
	 	string ans;
	 	if(k<s.length())
        {
            f(0,k-1)
	 	{
	 		ans+=s[i];
	 	}

        }

	 	if(s.length()<=k)
	 	{
	 		show(s);
	 	}
	 	else
	 	{
	 		show(ans<<"...");
	 	}






	 }


	 	/*cout<<"Case #"<<cccc-t<<": ";*/





}


Measured memory_bytes: 3644
m,s[]={0,31,60,91,121,152,182,213,244,274,305,335};main(d){char a[7][9]={"Thurs","Fri","Satur","Sun","Mon","Tues","Wednes"};while(1){scanf("%d%d",&m,&d);if(!m)exit(0);d+=s[m-1];printf("%sday\n",a[(d%7)?(d%7-1):6]);}}

Measured memory_bytes: 0
H,W=list(map(int, input().split()))
if H==1 or W==1:
     print(1)
else:
    a=W//2

    b=H//2

    N=a*b*2+W%2*b+H%2*a

    if H%2==1 and W%2==1:
        N+=1
    print(N)

Measured memory_bytes: 2940
#include<iostream>
#include<map>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    map<string, int>m;
    int q;
    cin>>q;
    while(q--){
        string command, str;
        cin>>command>>str;
        if(command=="insert"){
            m[str]=1;
        }
        else if(command=="find"){
            map<string, int>::iterator itr=m.find(str);
            if(itr==m.end())
                cout<<"no"<<endl;
            else
                cout<<"yes"<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 33308
n,m=map(int,input().split())
p=2

from itertools import product
iterator=product(range(p),repeat=n)

s=[0 for i in range(m)]    
for i in range(m):
    S=list(map(int,input().split()))
    k=S[0]
    s[i]=S[1:]

p=list(map(int,input().split()))

ans=0
for idxs in iterator:
    tmp1=0
    for i in range(m):
        tmp2=0
        for j in s[i]:
            tmp2+=idxs[j-1]
        if tmp2%2==p[i]:
            tmp1+=1
    if tmp1==m:
        ans+=1
print(ans)

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

using namespace std;

#define int long long
#define f(i,from,to) for(int i = from ; i < to ; i++)
#define tie() ios_base :: sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int INF = 1e9 + 7;
int32_t main()
{
        tie();

        int n,m;cin>>n>>m;
        string a[n+1];
        f(i,1,n+1) cin>>a[i];


        int dp[n+1][m+1];
        memset(dp , 0 , sizeof dp);


        dp[1][1] = (a[1][0] == '.');

        f(i,1,n+1)
            f(j,1,m+1)
                if(a[i][j-1] == '.')
                    dp[i][j] = (dp[i][j] + dp[i-1][j] + dp[i][j-1]) % INF;

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


Measured memory_bytes: 9216
n, k = map(int, input().split())
a = [int(x) for x in input().split()]

dp = []

for i in range(k+1):
    First_win = any(map(lambda x: not dp[i-x] if i-x >= 0 else False, a))
    dp.append(First_win)

print('First' if dp[k] else 'Second')


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

int main(){
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    ll tmp = x % d;
    if((x - tmp)/d > k){
        ll ans = x - k * d;
        cout << ans << endl;
        return 0;
    }
    ll cnt = (x-tmp)/d;
    ll ans1 = tmp;
    ll ans2 = d - tmp;
    //cout << cnt << ans1 << ans2 << k-cnt << endl;
    if((k-cnt)% 2 == 0) cout << ans1 << endl;
    else cout << ans2 << endl;
}

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

int fnc(int, int);

int gyo[101][101];
int *p;

int main(){
  int i, j, n, x;

  scanf("%d", &n);
  for(i = 1; i <= n; i++){
    gyo[i][i] = 0;
  }
  p = (int *)malloc(sizeof(int)*(n+1));

  scanf("%d %d", &p[0], &p[1]);

  for(i = 2; i <= n; i++){
    scanf("%d %d", &x, &p[i]);
  }

  for(i = 1; i < n; i++){
    gyo[i][i+1] = p[i-1]*p[i]*p[i+1];
  }

  for(i = 0; i <= n - 3; i++){
    for(j = i + 3; j <= n; j++){
      gyo[j-i-2][j] = fnc(j-i-2, j);
    }
  }

  printf("%d\n", gyo[1][n]);

  return 0;
}

int fnc(int r, int c){
  int m = 100000001, num = c - r;

  for(int i = 0; i < num; i++){
    if(m > gyo[r][r+i] + gyo[r+i+1][c] + p[r-1]*p[r+i]*p[c]){
      m = gyo[r][r+i] + gyo[r+i+1][c] + p[r-1]*p[r+i]*p[c];
    }
  }
  return m;
}



Measured memory_bytes: 2104
#include<iostream>
using namespace std;
int length(string str)
{
	int length = 0;
  	for(int length=0;length!=str.size();length++);
  	return length;
}
bool ispalindrome(string str, int left, int right)
{
	string temp = "";
	for(int i=left;i<=right;i++)
        temp+=str[i];
    string temp2= "";
    for(int i=temp.size()-1;i>=0;i--)
        temp2+=temp[i];

    return temp==temp2 ? true : false;

}
int main()
{
	string str; cin >> str;

  	ispalindrome(str,0,str.size()-1) && ispalindrome(str,0,((str.size()-1)/2)-1) && ispalindrome(str,((str.size()+3)/2)-1,str.size()-1) ? cout << "Yes\n" : cout << "No\n";
  	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long int N, K;
  cin >> N >> K;

  long int a,b;
  long int A[100000] = {};

  for (int i = 0; i < N; i++) {
    cin >> a >> b;
    A[a-1] += b;
  }

  for (a = 0, b=0; b < K; a++) {
    b += A[a];
  }

  cout << a << endl;

  return 0;

}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) < (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[8] = { //移動
	{ 0 ,1 },{ -1 ,0 },{ 1 ,0 },{ 0 ,-1 },
	{ 1 ,1 },{ 1 ,-1 },{ -1 ,1 },{ -1 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL

struct segtree {
	int N, dat[2 * 300000];
	segtree() {}
	segtree(int n) {
		N = 1;
		while (N < n) N *= 2;
		for (int i = 0; i < 2 * N - 1; i++)
			dat[i] = INF;
	}
	// update k th element
	void update(int k, int a) {
		k += N - 1; // leaf
		dat[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}
	// min [a, b)
	int query(int a, int b) { return query(a, b, 0, 0, N); }
	int query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l) return INF;
		if (a <= l && r <= b) return dat[k];
		int m = (l + r) / 2;
		return min(query(a, b, k * 2 + 1, l, m), query(a, b, k * 2 + 2, m, r));
	}
};


signed main(void) {
	int n, a, b;
	cin >>n >>  a >> b;

	cout << min(a, b) << " "<<  max(0, a+b -n) << endl; 

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long
int ip(int x)
{
    for(int i=2;i*i<=x;i++)
        if(x%i==0)return 0;
    return x>1;
}
const int Q=1<<16,P=1<<9;
int pn[Q];
ll als[P][P];
ll Lcm(ll a,ll b)
{return (a==0||b==0)?a|b:a/__gcd(a,b)*b;}
ll h[Q],z[Q];
int main()
{
    int tp=0,n;
    for(int i=2;tp<1000;i++)
        if(ip(i))pn[++tp]=i;
    scanf("%d",&n);
    if(n==2)
        return 0&printf("4 7\n23 10");
    tp=0;
    for(int i=1-n;i<=n-1;i++)
        if(i&1^1)h[i+n]=pn[++tp];
    for(int i=2;i<=(n<<1);i++)
        if(i&1^1)z[i]=pn[++tp];
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            if((i+j)&1^1)als[i][j]=h[j-i+n]*z[i+j];
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            if((i+j)&1)als[i][j]=Lcm(Lcm(als[i+1][j],als[i-1][j]),Lcm(als[i][j+1],als[i][j-1]))+1LL;
    ll mxx=0;
    for(int i=1;i<=n;i++,puts(""))
        for(int j=1;j<=n;j++)
            printf("%lld ",als[i][j]);
    return 0;
}
/*
412675878567959
1000000000000000
*/

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

template<class T>
T gcd(T a, T b)
{
    while (a > 0)
    {
        T t = a;
        a = b%a;
        b = t;
    }
    return b;
}

int main()
{
    int N = 0;
    cin>>N;
    vector<int> A(N);
    for (int &a: A)
        cin>>a;

    vector<int> F(1000001);
    int g = A[0];

    for (int a: A)
    {
        g = gcd(g, a);
        for (int f=2; f*f<=a; f++)
            if (a%f==0)
            {
                F[f]++;
                while (a%f==0)
                    a /= f;
            }
        if (a>=2)
            F[a]++;
    }

    bool p = true;
    for (int f: F)
        if (f>=2)
            p = false;
    if (p)
        cout<<"pairwise coprime"<<endl;
    else if (g==1)
        cout<<"setwise coprime"<<endl;
    else
        cout<<"not coprime"<<endl;
}


Measured memory_bytes: 10688
#[allow(unused_imports)]
use std::cmp::{min,max};
#[allow(unused_imports)]
use std::collections::{BTreeMap,BTreeSet};
#[allow(unused_imports)]
use std::ops::*;
#[allow(unused_imports)]
use std::collections::BinaryHeap;

#[allow(unused_macros)]
macro_rules! tf {
    ($c:expr, $t:expr, $f:expr) => {{
        if $c { $t } else { $f }
    }};
}

fn main() {
    let (n,m,x,y) = {
        let xs = read_vec_i64();
        (xs[0] as usize, xs[1] as usize, xs[2], xs[3])
    };
    let xs = read_vec_i64();
    let ys = read_vec_i64();
    let mut res = false;
    for z in x+1..y {
        let mut t = xs.iter().all(|&x| x < z) && ys.iter().all(|&y| y >= z);
        if t {
            res = true;
        }
    }
    println!("{}", tf!(res, "No War", "War"));
}

#[allow(dead_code)]
fn read_line() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    ret.pop();
    //ret.pop();
    return ret;
}

#[allow(dead_code)]
fn read_i64() -> i64 {
    let ss = read_line();
    return ss.parse::<i64>().unwrap();
}

#[allow(dead_code)]
fn read_vec_i64() -> Vec<i64> {
    let mut res = vec![];
    let ss = read_line();
    for ts in ss.split_whitespace() {
        let x = ts.parse::<i64>().unwrap();
        res.push(x);
    }
    return res;
}

use std::fmt::Display;
#[allow(dead_code)]
fn write_vec<T: Display>(xs: &Vec<T>) {
    if xs.len() == 0 {
        println!("");
        return;
    }
    print!("{}", xs[0]);
    for i in 1..xs.len() {
        print!(" {}", xs[i]);
    }
    println!("");
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
#define fio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define endl '\n'
// #define double long double
// #define mp make_pair
// #define pb push_back
// Upper case English alphabet to lower case ch |= ' ';
// Lower case English alphabet to upper case ch &= '_’ ;
//__builtin_popcount(x)

const int INF=(int)1e18+7,t=-1,till=0,N=1e5+7;
int gcd(int a, int b) { return b!=0 ? gcd(b, a % b) : a; }
// int digits(int n){return floor(log10(n))+1 ;}
// bool ispoweroftwo (int x) { return x && (!(x&(x-1))); }
//vector<int> vis,parent,ti,tout,dis;
vector<vector<int> > adj(N);
int vis[N],height[N];
//map<pair<int,int>,pair<int,int> > parent;
//double dp[N];
vector<int> row={-1,1,0,0};
vector<int> col={0,0,-1,1};
// vector<int> cats;
// int m;
int ans=0,ele=-1;
void dfs(int v){
    vis[v]=1;
    int f=1;
    for(auto u:adj[v]){
        if(height[u]>=height[v]) f=0;
        if(vis[u]==-1){
            dfs(u);
        }
    }
    if(f){
        //cout<<v+1<<endl;
        ans++;
    }
    
}

// bool comp(pair<int,int> p1,pair<int,int> p2){
//     return p1.first-p1.second > p2.first-p2.second; 
// }

int ss(int x,int y) {
    return (x-y)*(x-y);
}
void print(int f){
    if(f) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

signed main(){
    fio;
    int n,m;
    cin>>n>>m;
    memset(vis,-1,sizeof(vis));
    for(int i=0;i<n;i++){
        cin>>height[i];
    }
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        u--;v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(int i=0;i<n;i++){
        if(vis[i]==-1) dfs(i);
    }
    cout<<ans<<endl;




    




    

    
    
    
    

    
    

    

}

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

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int grid[5005][5005];

void compress(vi &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

void cumulativesum(int h,int w){
  int i,j;
  rep(i,h)rep(j,w) grid[i+1][j+1]+=grid[i+1][j]+grid[i][j+1]-grid[i][j];
}

int sum(int i,int j,int k,int l){//y,x??§??????????°???§                                 
  return grid[k][l]-grid[i][l]-grid[k][j]+grid[i][j];
}
int main(void) {
  int i,j;
  int n,m;
  cin>>n>>m;
  vi x(n),y(n);
  pii p[5000];
  rep(i,n){
    cin>>x[i]>>y[i];
    p[i].first=x[i];
    p[i].second=y[i];
  }

  compress(x);
  compress(y);

  rep(i,n){
    int fy=lower_bound(all(y),p[i].second)-y.begin();
    int fx=lower_bound(all(x),p[i].first)-x.begin();
    grid[fy+1][fx+1]++;
  }

  cumulativesum(n,n);//?´???????                                                      

  rep(i,m){
    int lx,ly,rx,ry;
    cin>>lx>>ly>>rx>>ry;
    lx=lower_bound(all(x),lx)-x.begin();
    ly=lower_bound(all(y),ly)-y.begin();
    rx=lower_bound(all(x),rx+1)-x.begin();
    ry=lower_bound(all(y),ry+1)-y.begin();
    cout<<sum(ly,lx,ry,rx)<<endl;
  }
}

Measured memory_bytes: 100988
/*
ID: skipian1
PROB: 
LANG: C++11
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF = 2000000000
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define X first
#define Y second

int main() {
  int n, cut;
  cin >> n;
  int arr[n];
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += abs(arr[i]);
  }
  sort(arr, arr+n);
  if (arr[0] <= 0 && arr[n-1] >= 0) {
    cout << sum << "\n";
    cut = n-1;
    for (int i = 1; i < n-1; i++) {
      if (arr[i] >= 0) {
	cut = i;
	break;
      }
    }
    int cur = arr[0];
    for (int i = cut; i < n-1; i++){ 
      cout << cur << " " << arr[i] << "\n";
      cur -= arr[i];
    }
    cout << arr[n-1] << " " << cur << "\n";
    cur = arr[n-1] - cur;
    for (int i = 1; i < cut; i++) {
      cout << cur << " " << arr[i] << "\n";
      cur -= arr[i];
    }
  } else if (arr[n-1] < 0) {
    cout << sum+2*arr[n-1] << "\n";
    int cur = arr[n-1];
    for (int i = n-2; i >= 0; i--) {
      cout << cur << " "  << arr[i] << "\n";
      cur -= arr[i];
    }
  } else {
    cout << sum-2*arr[0] << "\n";
    int cur = arr[0];
    for (int i = 1; i < n-1; i++) {
      cout << cur << " "  << arr[i] << "\n";
      cur -= arr[i];
    }
    cout << arr[n-1] << " " << cur << "\n";
  }
}


Measured memory_bytes: 2304
S = list(input())

n = len(S)

ans = 0

def calc(i=0, s=0, buf=''):
    global ans
    if i == len(S):
        if buf:
            s += int(buf)
        ans += s

    else:
        if buf:
            calc(i+1, s + int(buf), S[i])

        calc(i+1, s, buf + S[i])


calc()

print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
long A[22];
int main()
{
   long long a,i;
    A[1]=A[3]=A[5]=A[7]=A[8]=A[10]=A[12]=100;
    A[4]=A[6]=A[9]=A[11]=50;
    A[2]=75;
    cin>>a>>i;
    if(A[a]==A[i]) std::cout << "Yes" << '\n';
    else std::cout << "No" << '\n';
}


Measured memory_bytes: 3632
A, B, C = input().split()
A = int(A)
B = int(B)
C = int(C)

nlist = [A, B, C]
nlist2 = sorted(nlist)
if nlist2[2] == 7:
    if nlist2[0] == nlist2[1] == 5:
        print('YES')
    else:
        print('NO')
else:
    print('NO')

Measured memory_bytes: 3060
#include<stdio.h>
#define NMAX 8

int  a[NMAX+1][NMAX+1] = { 0 };
int  n, c = 0;

void dfs(int);

int main(void)
{
  int  m, i, j, k; 

  scanf("%d %d", &n, &m);
  for( i = 1; i <= m; i++){
    scanf("%d %d", &j, &k);
    a[j][k] = 1;
    a[k][j] = 1;
  }

  a[1][0] = 1;
  dfs(1);

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

  return 0;
}

void dfs(int v)
{
  int  i, t=0;

  for(i=1; i<=n; i++){
    t += a[i][0];
  }
  if(t == n){
    c++;
    return;
  }

  for( i = 1; i <= n; i++){
    if(a[i][0] == 0 && a[v][i] == 1){
      a[i][0] = 1;
      dfs( i );
      a[i][0] = 0;
    }
  }
  return;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

ll solve(int n, vector<ll> &v) {
    map<ll, ll> index;
    rep(i, n) index[v[i]] = i;

    ll ans = 0;

    set<int> used;

    for (int i = n; i > 0; i--) {
        int own_index = index[i];
        used.insert(own_index);
        bool has_left_lager = [&]() -> bool {
            auto it = used.lower_bound(own_index);
            if (it == used.begin()) return false;
            return true;
        }();
        int left_index = [&]() -> int {
            if (!has_left_lager) return -1;
            auto it = used.lower_bound(own_index);
            it--;
            return *it;
        }();
        bool has_right_lager = [&]() -> bool {
            auto it = used.lower_bound(own_index);
            it++;
            if (it == used.end()) return false;
            return true;
        }();
        if (!has_right_lager) continue;
        int right_lager_index = [&]() -> int {
            auto it = used.lower_bound(own_index);
            it++;
            return *it;
        }();
        bool has_right_right_lager = [&]() -> bool {
            auto it = used.lower_bound(right_lager_index);
            it++;
            if (it == used.end()) return false;
            return true;
        }();
        int right_right_index = [&]() -> int {
            if (!has_right_right_lager) return n;
            auto it = used.lower_bound(right_lager_index);
            it++;
            return *it;
        }();

        ll left_range = [&]() -> int {
            return own_index - left_index;
        }();
        ll right_range = [&]() -> int {
            return right_right_index - right_lager_index;
        }();

        ll now = left_range * right_range * i;

        ans += now;
    }

    return ans;
}

int main() {
    int n;
    cin >> n;
    vector<ll> v(n);
    rep(i, n) cin >> v[i];

    ll a = solve(n, v);
    reverse(v.begin(), v.end());
    ll b = solve(n, v);


    ll ans = a + b;
    cout << ans << endl;
}


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

int main()
{
  int n,k;
  cin>>k>>n;
  vector<long long>a(n);
  for(int i=0;i<n;i++)
    cin>>a[i];
  
  long long ans = 1e14;
  for(int i=0;i<n;i++)
  {
    long long now = a.back() - a[i];
    if( i )
    {
       now += k-a.back();
       now += a[i-1];
    }
    ans = min( ans, now );
  }
  cout<<ans;
  
  return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

class Main {

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

	while(stdin.hasNextInt()){
	    int d = stdin.nextInt();
	    int limit = 600 / d;
	    int sum = 0;
	    for(int i = 0; i < limit; i++){
		sum += (d * i) * (d * i) * d;
	    }
	    System.out.println(sum);
	}
    }
}

Measured memory_bytes: 12000
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <new>
#include <typeinfo>
#include <iterator>

typedef long long ll;
typedef unsigned long long ull;
constexpr ll mop = 1000000007;
constexpr ll mop2 = 998244353;

using namespace std;

signed main() {
	ll a, b, v, w, t;
	cin >> a >> v >> b >> w >> t;
	if (v > w) {
		if (abs(a - b) <= t * (v - w)) {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
//INF = 1 061 109 567 ; INF + INF = 2 122 219 134 ;
//LINF = 4 557 430 888 798 830 399 ; LINF + LINF = 9 114 861 777 597 660 798 ;
const int INF = 0x3f3f3f3f;     // -INF: 0xc0   abs(-INF) = INF + 1
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = (int)1e9+7;     // when MOD = 1e9+7, inv2 = 500000004
const int N = (int)-1;
ll L,R;
int dp[100][2][2][2][2];
int add(int a,int b) {
	a += b;
	if(a >= MOD) a -= MOD;
	return a;
}
int dfs(int len,int bl,int br,int cl,int have,int y,int x) {
	//dd(len),dd(bl),dd(br),dd(cl),de(have);
	if(len == -1) {
	//	dd(y),de(x);
		return 1;
	}
	if(dp[len][bl][br][cl][have] != -1) return dp[len][bl][br][cl][have];
	int kl = bl ? (L >> len & 1) : 0;
	int kr = br ? (R >> len & 1) : 1;
	int dl = cl ? (L >> len & 1) : 0;
	int re = 0;
	if(0 >= kl && 0 <= kr && !dl) {
		re = add(re,dfs(len-1,bl&&kl==0,br&&kr==0,cl&&dl==0,have,y,x));
	}
	if(1 >= kl && 1 <= kr) {
		re = add(re,dfs(len-1,bl&&kl==1,br&&kr==1,cl&&dl==1,1,y|1<<len,x|1<<len));
		if(dl == 0 && have) re = add(dfs(len-1,bl&&kl==1,br&&kr==1,cl,have,y|1<<len,x),re);
	}
//	dd(y),dd(x),dd(len),dd(bl),dd(br),dd(cl),dd(have),de(re);
	return dp[len][bl][br][cl][have] = re;
}
void o(int x) {
	per(i,0,5) cout<<(int)(x>>i&1);
	cout<<endl;
}
int main()
{
	memset(dp,-1,sizeof(dp));
	scanf("%lld%lld",&L,&R);
	int cnt = 0;
	printf("%d\n",dfs(63,1,1,1,0,0,0));
	return 0;
}



Measured memory_bytes: 256
import java.util.Deque;
import java.util.LinkedList;
import java.util.Scanner;

class Main {
	static final String YES = "YES";
	static final String NO = "NO";

	public static void main(String[] args) {
		Scanner sc = null;
		try {
			sc = new Scanner(System.in);
			int countDataset = sc.nextInt();
			int[] ballNums = new int[10];

			for (int i = 0; i < countDataset; i++) {
				for (int j = 0; j < 10; j++) {
					ballNums[j] = sc.nextInt();
				}

				System.out.println(push(ballNums) ? YES : NO);

			}
		} finally {
			sc.close();
		}
	}

	public static boolean push(int[] nums) {
		Deque<Integer> list1 = new LinkedList<Integer>();
		Deque<Integer> list2 = new LinkedList<Integer>();
		list1.push(0);
		list2.push(0);
		for (int number : nums) {
			if (list1.peek() < number) {
				list1.push(number);
			} else if (list2.peek() < number) {
				list2.push(number);
			} else {
				return false;
			}
		}
		return true;
	}
}

Measured memory_bytes: 26016
//CREATED BY TARANG KAPOOR



#include <bits/stdc++.h>

using namespace std;

int main()
{
  long long int n,k,t,ans; cin>>n>>k;
  if(n>=k)
  {
      if(n%k==0)
      cout<<0<<endl;
      else 
      cout<<(k-n%k)<<endl;
  }
 
  else{
   ans=min(n,abs(n-k));
   cout<<ans<<endl;
  }
}


Measured memory_bytes: 256
import java.util.*;
import java.util.Scanner;

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

        int N = sc.nextInt();
        int K = sc.nextInt();

        if (N % K == 0) {
            System.out.println("0");
        } else {
            System.out.println("1");
        }
    }
}

Measured memory_bytes: 23380
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
using namespace std;

#define mp make_pair
#define fi first
#define se second
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) (((a) * (b)) / (__gcd((a), (b))))
#define in_range(x, y, r, c) (x < r && y < c && x >= 0 && y >= 0)
#define setbits(x) __builtin_popcountll(x)
#define unsetend(x) __builtin_ctzll(x)
#define unsetfront(x) __builtin_clzll(x)
#define f first
#define s second
#define pb push_back
#define pf push_front
#define ll long long
#define endl "\n"
#define Endl "\n"

// long long expo(long long a, long long b, long long mod)
// {
//     ll ret = 1;
//     while (b > 0)
//     {
//         if (b % 2 == 1)
//             ret = (((ret)%mod) * ((a)%mod))%mod;
//
//         a = ((a)%mod) * ((a)%mod)%mod;
//         b = b / 2;
//     }
//     return (ret%mod);
// }

// vector<long long> seive()
// {
//    long long i,j;
//    vector<long long> hash(1000001,1);
//    vector<long long> primes;
//
//    for(i=2;i*i<=1000000;i++)
//    {
//        if(hash[i])
//        {
//            for(j=i*i;j<=1000000;j+=i)
//            hash[j]=0;
//        }
//    }
//    for(i=2;i<1000001;i++)
//    {
//        if(hash[i])
//        primes.pb(i);
//    }
//    return primes;
// }

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

    ll n, k, j, i;
    cin >> n >> k;
    ll h[n + 1];
    for (i = 1; i <= n; i++)
        cin >> h[i];

    ll dp[n + 1];

    for (i = 1; i <= n; i++)
        dp[i] = INT_MAX;
    dp[1] = 0;

    for (i = 2; i <= n; i++)
    {
        for (j = 1; j <= k; j++)
        {
            if (i - j >= 1)
            {
                dp[i] = min(dp[i - j] + abs(h[i] - h[i - j]), dp[i]);
            }
            else
                break;
        }
    }
    cout << dp[n];
}


Measured memory_bytes: 5156
<?php
$string = trim(fgets(STDIN));
$firstHalf = ltrim(substr($string, 0, 2), '0');
$secondHalf = ltrim(substr($string, 2), '0');
 
if (0 < $firstHalf && $firstHalf <= 12 && 0 < $secondHalf && $secondHalf <= 12) {
	echo 'AMBIGUOUS', PHP_EOL;
} elseif (0 < $firstHalf && $firstHalf <= 12) {
    echo 'MMYY', PHP_EOL;
} elseif (0 < $secondHalf && $secondHalf <= 12) {
	echo 'YYMM', PHP_EOL;
} else {
	echo 'NA', PHP_EOL;
}


Measured memory_bytes: 4728
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<functional>
using namespace std;
using ll = long long int;
#define rep(i, a, b) for (int(i) = a; (i) < (int)(b); (i)++)

int main(){
    ll N,A,B;
    cin >> N >> A >> B;
    ll d = N /(A+B);
    ll r = N %(A+B);
    if (r>A) cout << d*A+A << endl;
    else cout << d*A + r << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using namespace std;

int main(){
  ll n,m;
  string S,T;
  cin >> n >> m >> S >> T;

  ll lcm = n*m/__gcd(n,m);
  if (n>m){
    swap(n,m);
    swap(S,T);
  }
  rep(i,n){
    
    if((i*m)%n==0){
      if(S[i] != T[(i*lcm/n)/(lcm/m)]){
        cout << -1 << endl;
        return 0;
      }
    }

  }
  
  cout << lcm << endl;



  return 0;
}


Measured memory_bytes: 512
// in case of multiple test cases and N=1e5 don't intialize arrays as global except for graph vector-array
// always check whether or not you are doing mod of a negative number
// always use 1LL instead of 1
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
using namespace __gnu_pbds;
using namespace std;

// using long doubles saves you from corner cases but is very time consuming
#define double      	long double
#define int         	long long
#define pb          	push_back
#define pii         	pair<int,int>
#define vi          	vector<int>
#define vii         	vector<pii>
#define mi          	map<int,int>
#define mii         	map<pii,int>
#define all(a)      	(a).begin(),(a).end()
#define sz(x)       	(int)x.size()
// just comment the line below in case of interactive problems
#define endl        	"\n"
#define repp(i,a,b) 	for(int i=a;i<b;i++)
#define rep(i,a,b) 		for(int i=a;i<=b;i++)
#define brep(i,a,b)     for(int i=a;i>=b;i--)
#define deb1(x)      	cout << #x << "=" << x << endl
#define deb2(x, y)  	cout << #x << "=" << x << "," << #y << "=" << y << endl
#define deb3(x, y, z)  	cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define trace(v) 		for(auto it=v.begin();it!=v.end();it++)cout<<*it<<" ";cout<<endl;
#define tracearr(a,l,r) for(int iii=l;iii<=r;iii++)cout << a[iii] << " ";cout << endl;
#define PI          	3.1415926535897932384626
#define F 				first
#define S 				second
#define clr(x,y) 		memset(x, y, sizeof(x))
#define IOS         	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
// *s.find_by_order(1) - gives the 2nd samllest element in set
// s.order_of_key(x)   - gives the number of elements in the set which are strictly smaller than x


const int N=1e5 + 5;
const int MOD=1e9 + 7;

int32_t main()
{
	IOS;
	int T=1;
	//cin >> T;
	// int numOfSetBits = __builtin_popcountll(n);
	std::cout << std::fixed << std::setprecision(12);
	while(T--)
	{
		int a,b,c,d;
		cin >> a >> b >> c >> d;
		int ans1 = a*c;
		int ans2 = b*d;
		int ans3 = a*d;
		int ans4 = b*c;
		cout << max({ans1,ans2,ans3,ans4});
	}
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
 
using namespace std;
 
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl
ll n,q,k;
vector<pll>adj[100005];
ll h[100005];
void dfs(ll i,ll p,ll d)
{
	h[i]=d;
	for(auto j:adj[i])
	{
		if(j.FF!=p)
		{
			dfs(j.FF,i,d+j.SS);
		}
	}
}
int main() {
slld(n);
for(int i=1;i<n;i++)
{
	ll x,y,c;
	slld(x);slld(y);slld(c);
	adj[x].pb(mp(y,c));
	adj[y].pb(mp(x,c));
}
slld(q);slld(k);
dfs(k,k,0);
for(int i=1;i<=q;i++)
{
	ll x,y;
	slld(x);slld(y);
	plld(h[x]+h[y]);
}



	return 0;
           } 

Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
const int N = 3005;
long long dp[N][N];
int main() {
	int n;
	cin>>n;
	vector<long long> a(n);
	for(long long &i:a) {
		cin>>i;
	}
	for(int l = n-1;l>=0;l--) {
		for(int r=l;r<n;r++) {
			if(l==r) {
				dp[l][r] = a[l]; 
			} else {
				dp[l][r] = max(a[l] - dp[l+1][r], a[r] - dp[l][r-1]);
			}
		}
	}
	cout<<dp[0][n-1];
}



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

int main(int argc, const char * argv[]) {
    // insert code here...
    int X, A, B;
    cin >> X >> A >> B;
    
    if (X + A - B >= X) cout << "delicious" << endl;
    else if (X + A - B >= 0) cout << "safe" << endl;
    else cout << "dangerous" << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const int inf = INT_MAX;
const int MOD = 1000000007;
const long long INF = LLONG_MAX;
const long long MINF = LLONG_MIN;

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

const long long MAX_E = 10101;
const long long MAX_V = 10101;

struct edge {
  long long from, to, cost;
};

edge es[MAX_E];

long long dist[MAX_V];
long long V, E;

bool shortest_path(long long s) {
  for (int i = 1; i <= V; i++) dist[i] = MINF;

  dist[s] = 0;

  ll cnt = 0;

  ll dg = 0;

  while (true) {
    bool updated = false;
    for (int i = 1; i <= E; i++) {
      edge e = es[i];
      if (dist[e.from] != MINF && dist[e.to] < dist[e.from] + e.cost) {
        dist[e.to] = dist[e.from] + e.cost;
        updated = true;
      }
    }
    if (!updated) break;

    ++cnt;
    if (cnt == V) {
      dg = dist[V];
    } else if (cnt == 5 * V) {
      return dg != dist[V];
    }
  }

  return false;
}

ll N, M;

int main() {
  cin >> N >> M;
  V = N;
  E = M;
  repe(i, 1, M) {
    ll a, b, c;
    cin >> a >> b >> c;
    es[i] = edge{a, b, c};
  }

  if (shortest_path(1)) {
    cout << "inf";
  } else {
    cout << dist[N];
  }
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rall(x) (x).rbegin(),(x).rend()

int main(){
	int n,k; cin>>n>>k;
	vector<int> v(n);
	rep(i,n) cin>>v[i];
	sort(rall(v));
	int ans=0;
	rep(i,k) ans+=v[i];
	cout<<ans<<endl;	
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

VVI g;
VI ids;

void dfs(int v, int p, int id){
    ids[v] = id;
    for(int d: g[v]){
        if (d == p) continue;
        if (ids[d] != -1) continue;
        dfs(d, v, id);
    }
}

int main(){
    int n, m;
    cin >> n >> m;
    VI p(n);
    rep(i,n){
        cin >> p[i];
        p[i]--;
    }

    g.resize(n);
    rep(i,m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    ids.resize(n, -1);
    int id = 0;
    rep(i,n){
        if (ids[i] != -1) continue;
        dfs(i, -1, id++);
    }

    int ans = 0;
    rep(i,n){
        if (ids[i] == ids[p[i]] || p[i] == i) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12420
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	x := iScan()
	y := iScan()
	for i := 0; ; i++ {
		if x <= y {
			x *= 2
		} else {
			fmt.Println(i)
			break
		}
	}
}


Measured memory_bytes: 1776