akhauriyash/Code-Regression huggingface dataset:
/*author  ADITYA BANSAL
                 //~ MNNIT ALLAHABAD     */
        #include<bits/stdc++.h>
        using namespace std;
        #define ll long long
        #define ull unsigned long long
        ll power(ll,ll);
        ll ncr(ll,ll);
        ll add(ll a,ll b);
        void fact();
        ll mul(ll a,ll b);
        #define watch(x) cerr<<(#x)<<"is"<<x<<nl;
        #define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
        #define fi(a,b) for(ll i=a; i<b; i++)
        #define fk(a,b) for(ll k=a; k<b; k++)
        #define fri(a,b) for(ll i=a; i>=b; i--)
        #define fj(a,b) for(ll j=a; j<b; j++)
        #define ffi(a,b) for(ll i=a;i*i<=b;i++)
        #define mp make_pair
        #define ff first 
        #define  tc ll t; cin>>t; while(t--)
        #define all(v) (v).begin(),(v).end()
        #define ss second
        #define pb push_back
        #define mem(v,a) memset((v),a,sizeof(v));
        #define pll pair<ll,ll>
        #define mll map<ll,ll>
        #define sll set<ll>
        #define vll vector<ll>
        #define max3(a,b,c) max(a,max(b,c))
        #define min3(a,b,c) min(a,min(b,c))
        #define nl endl
         int mod=1e9+7;
        const ll  N=1000032LL;
        ll fac[N+2];
        ll inv[N+2];
        
       
        
        signed main(){  
    	fast
    	fact();
    	 //~ tc
        {
		  ll x,y;
		  cin>>x>>y;
		  
		  if((x+y)%3!=0) return cout<<0,0;  
		  
		 ll p=(x+y)/3;
		  ll q=min(x,y);
		if(q-p<0) return cout<<0,0; 
		  ll ans=ncr(p,q-p);
		  cout<<ans<<nl;
		  
	     }
            return 0;
        }
         
         
        /******************************************************************************/
         
        ll add(ll a,ll b){
			a+=b;
		   if(a>=mod) a-=mod;
		   if(a<0) a+=mod;
		   return a;
		} 
         
        ll mul(ll a,ll b){
            return ((a%mod)*(b%mod))%mod;
        }
         
        ll power(ll a,ll n){
          ll res=1;
          while(n){
              if(n&1) res= mul(res,a);
             n>>=1; 
             a= mul(a,a);
          }
            return res;
        }
        void fact(){
        	inv[0]=fac[0]=1;
        	fi(1,N){
        	 fac[i]=mul(fac[i-1],i);
        	inv[i]=power(fac[i],mod-2);
        }
        }
         
        ll ncr(ll n,ll r){
        	
        	if(r>n) return 0;
        	ll e=fac[n];
        	e=mul(e,inv[r]);
        	e=mul(e,inv[n-r]);
        	return e;
        }


Measured memory_bytes: 16000
from sys import stdin
input = stdin.readline

a = input()
nums = list(map(int, input().split()))

res = 0
for i in range(len(nums)-2):
  for j in range(i+1,len(nums)-1):
    if(nums[i]==nums[j]):
      continue
    for k in range(j+1,len(nums)):
      if(nums[i]==nums[k] or nums[j]==nums[k]):
        continue
      
      m = max(nums[i],nums[j],nums[k])
      if m==nums[i] and m<nums[j]+nums[k]:
        res+=1
      elif m==nums[j] and m<nums[i]+nums[k]:
        res+=1
      elif m==nums[k] and m<nums[i]+nums[j]:
        res+=1

print(res)

Measured memory_bytes: 9224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

int main(){
    ll n;
    cin >> n;
    ll d;
    for(ll i = 1; i * i <= n; i++){
        if (n % i == 0) d = i;
    }
    cout << d + n/d - 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <stack>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, nuint_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; 
#define int long long
#define MOD 1000000007
#define what_is(x) cerr << #x << " is " << x << endl;
#define loop(i,a,n) for(int i=a;i<n;i++)

#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, szof(x))
#define sortall(x) sort(aint(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int, int> pt;


int dp[100010][2];
signed main() {
	
	fastio();
	//#define LOCAL_DEFINE
	#ifdef LOCAL_DEFINE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	//https://codeforces.com/contest/1084/problem/D
	// https://codeforces.com/contest/1155/problem/E
	//https://www.spoj.com/problems/MON2012/
	//https://codeforces.com/blog/entry/52726	
	int n;
	cin>>n;
	int ans=0;
	string s;
	cin>>s;
	int arr[27];
	memset(arr,0,sizeof(arr));
	for(int i=0;i<n;i++)
	{
		arr[s[i]-'a']++;
		int ans1=1;
		for(int j=0;j<26;j++)
		{
			if((s[i]-'a')==j)
			{
				ans1*=1;
			}else{
				ans1*=(arr[j]+1);
				ans1%=MOD;
			}
		}
		ans+=ans1;
		ans%=MOD;
	}
	cout<<ans;
	return  0;


}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
#define lli long long int
#include<bits/stdc++.h>
int main(){
  lli i,ans=753,sum;
  string s,b;
  cin>>s;
  for(i=0;i<s.size()-2;i++){
    sum=0;
    b=s.substr(i,3);
    //cout<<b<<" ";
    sum+=(b[0]-'0')*100+(b[1]-'0')*10+b[2]-'0';
    ans=min(ans,abs(sum-753));
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
N,T = map(int,input().split())
mn = 10**10
for i in range(N):
    c,t = map(int,input().split())
    #print(c,t)
    if t <= T and c <= mn:
        mn = c
if mn == 10**10:
    print("TLE")
else:
    print(mn)



Measured memory_bytes: 9164
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int solve(vector<int> v){
  int ret = 1;
  int cur;
  bool flag = true;
  rep(i, v.size() - 1)
  {
    if(flag){
      if(v[i+1] == v[i]){
        continue;
      }
      cur = v[i+1] > v[i];
      flag = false;
    }
    if(cur){
      if(v[i+1] < v[i]){
        ret++;
        flag = true;
      }
    }else{
      if(v[i+1] > v[i]){
        ret++;
        flag = true;
      }
    }
  }
  return ret;
}
int main()
{
  int n;
  cin >> n;
  if(n==1){
    cout << 1 << endl;
    return 0;
  }
  vector<int> a(n);
  rep(i,n){
    cin >> a[i];
  }
  cout << solve(a) << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

int cnt[1 << 24], N;

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		for (int j = i; j <= N; j += i) cnt[j]++;
	}

	long long ans = 0;
	for (int i = 1; i <= N; i++) ans += 1LL * i * cnt[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 42684
/* Accepted. */
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<cmath>
using namespace std;
#define MAXN 200006
int n;
multiset<int> S;
int main() {
	cin >> n;
	for( int i = 0 , t ; i < n ; ++ i ) scanf("%d",&t) , S.insert(t);
	int ans = 0;
	while( !S.empty() ) {
		auto it = S.end(); --it;
		int x =  * ( it );
		S.erase( it );
		int k = log2( x ) + 1;
		if( S.count( (1<<k) - x ) ) S.erase(S.find((1<<k) - x) ) , ++ans;
	}
	cout << ans;
}


Measured memory_bytes: 9728
/*
    WRITER:kakitamasziru
*/
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
//#include <unordered_map> // unordered_map
//#include <unordered_set> // unordered_set
#include <bitset> // bitset
//#include <cctype> // isupper, islower, isdigit, toupper, tolower
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1001001000;
const int MOD = 1000000007;
typedef pair<int,int> P;
//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}
long long nCr(long long n, long long r) {
    long long A = 1, B = 1;
    //Aが分子Bが1/r!
    for (long long i = n - r + 1; i <= n; i++) {
        A = A * i % MOD;
    }
    for (long long i = 1; i <= r; i++) {
        B = B * i % MOD;
    }
    B = mod_pow(B, MOD - 2);
    B %= MOD;
    //Bは割るのではなく掛ける
    return (A * B) % MOD;
}

int main() {
    long long X,Y;cin >> X >> Y;
    if(X == Y || Y == 1 || X%Y == 0){
        cout << "-1" << endl;
        return 0;
    } 
    if(X < Y){
        cout << X << endl;
        return 0;
    }
    else {
        cout << X*Y-X << endl;
        return 0;
    }

    /*
    g++ abc.cpp
    ./a.out
    */
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
using namespace std;

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

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

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int N;
int L[100];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> N;
  int a = 0;
  int b = 0;
  int sum = 0;
  REP(i, N) {
    cin >> b;
    if(b > a) {
      sum += a;
      a = b;
    } else {
      sum += b;
    }
  }

  cout << (sum > a ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
q=int(input())
cnt=[0]*100001
def check(x):
    ret=1
    for k in range(2,int(x**(1/2))+1):
        if x%k==0:
            ret=0
            break
    return ret
for n in range(3,100000,2):
    if check(n)*check((n+1)//2)==1:
        cnt[n]=cnt[n-2]+1
    else:
        cnt[n]=cnt[n-2]
for m in range(4,100001,2):
    cnt[m]=cnt[m-1]
ans=[0]*q
for i in range(q):
    l,r=map(int,input().split())
    ans[i]=cnt[r]-cnt[l-1]
for i in range(q):
    print(ans[i])


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

int main(){
    int n, q;
    string s;
    vector<int> l(1e+5), r(1e+5);

    cin >> n >> q;
    cin >> s;

    for (int i=0;i<q;i++){
        cin >> l[i] >> r[i];
    }

    // make DP
    vector<int> m(1e+5);

    char prev_c = 'Z';
    int count = 0;
    for (int i=0;i<s.length();i++){
        if (s[i] == 'C' and prev_c == 'A'){
            count += 1;
        }
        prev_c = s[i];
        m[i] = count;
    }

    for (int i=0;i<q;i++){
        int num;
        num = m[r[i]-1] - m[l[i]-1];
        cout << num << endl;
    }
    return 0;
}


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

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

    rep(_, T) {
		int N, M, A, B;
        cin >> N >> M >> A >> B;
        cout << floor_sum(N, M, A, B) << '\n';
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3620
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long l = sc.nextInt();
        long r = sc.nextInt();
        long min = 10000;
        for(long L = l; L < l + 2019; L++){
            for(long R = L + 1;  R <= r && R < L + 2020; R++){
              min = Math.min(((L % 2019) * (R % 2019)) % 2019, min);
            }
        }
        System.out.println(min);
    }
}


Measured memory_bytes: 21844
n,d = map(int, input().split())
arr = []
for _ in range(n):
  x,y = map(int, input().split())
  arr.append([x,y])
cnt = 0
for i in range(n):
  if arr[i][1]**2 + arr[i][0]**2 <= d**2:
    cnt += 1
print(cnt)

Measured memory_bytes: 103724
from scipy.sparse import*
e=enumerate
h,*s=open(0)
h=int(h[:2])
*g,=eval('[0]*500,'*500)
for i,t in e(s):
  for j,u in e(t):
    k=i*20+j
    g[k][k+1]=u>'#'<t[j+1]
    g[k][k+20]=(i<h-1)*u>'#'<s[i+1][j]  
a=csgraph.johnson(csr_matrix(g),0)
print(int(a[a<999].max()))

Measured memory_bytes: 19308
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
	int N;
	cin >> N;
	vector<ll> A(N + 1);
	for (auto& v : A)
	{
		cin >> v;
	}
	vector<ll> B(N);
	for (auto& v : B)
	{
		cin >> v;
	}

	ll ans = 0;
	ll sub = 0;
	for (int i = 0; i < N; ++i)
	{
		ans += min(sub + B[i], A[i]);
		sub = A[i] <= sub ? B[i] : B[i] - (A[i] - sub);
		if (sub < 0)
			sub = 0;
	}

	if (sub > 0)
	{
		ans += min(sub, A[N]);
	}

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


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <set>
using namespace std;
int c[26],s[400][30],last[400][30],d,now = -1000000000;
vector<int> ans,w;
int score(int l, int r, vector<int> &v){//[l,r)
    int i,j,res = 0;
    for(i=l;i<r;i++){
        for(j=0;j<26;j++){
            last[i][j] = 0;
        }
    }
    for(i=l;i<r;i++){
        int x = v[i]; x--;
        if(x<0 || x>25){
            //cout << x << endl;
            exit(1);
        }
        res += s[i][x];
        last[i][x] = i + 1;
        for(j=0;j<26;j++){
            res -= c[j]*(i + 1 - last[i][j]);
        }
    }
    return res;
}

void score2(int x){
    vector<int> vv; vv.resize(d);
    int i,j;
    vector<int> st;
    for(i=0;i<d;i++){
        int k = -1,mx = -1;
        for(j=0;j<26;j++){
            if(mx<s[i][j]){
                mx = s[i][j]; k = j + 1;
            }
        }
        if(mx>x) vv[i] = k;
        else st.push_back(i);
    }
    for(j=1;j<=26;j++){
        int y = j;
        for(int x:st){
            vv[x] = y;
            y++;
            if(y==27) y = 1;
        }
        int sc = score(0,d,vv);
        if(now<sc){
            swap(ans,vv); now = sc; 
        }
    }
}

/*vector<int> score3(){
    vector<int> vv; vv.resize(d);
    int i,j,l = 0;
    for(i=0;i<d;i++){
        if(i%26!=25 && i!=d - 1) continue;
        for(j=l;j<=i;j++){
            
        }
        l = i + 1;
    }
}*/

int main(){
    int i,j; cin >> d;
    for(i=0;i<26;i++){
        cin >> c[i];
    }
    for(i=0;i<d;i++){
        for(j=0;j<26;j++){
            cin >> s[i][j];
        }
    }
    for(i=0;i<d;i++){
        ans.push_back(i%26 + 1);
    }
    now = score(0,d,ans);
    for(j=1;j<26;j++){
        w.clear();
        for(i=0;i<d;i++){
            w.push_back((i + j)%26 + 1);
        }
        int sc = score(0,d,w);
        if(sc>now){
            swap(ans,w); now = sc;
        }
    }
    for(i=0;i<=20000;i+=10){
        score2(i);
    }
    for(i=0;i<d;i++){
        cout << ans[i] << "\n";
    }
}

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

int main(){
	string s, t;
	cin >> s;
	cin >> t;
	for(int i = 0; i < t.size(); i++){
		printf("%c%c", s[i], t[i]);
	}
	if(s.size() > t.size()){
		printf("%c", s[s.size() - 1]);
	}
	printf("\n");
	return 0;
}

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

using namespace std;
#define int long long
struct str{
	int x,y;
}st[150000];
bool cmp(str a,str b){
	return a.x<b.x;
}
signed main(){
	int n,m;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>st[i].x;
		st[i].y=i;
	}
	sort(st+1,st+1+n,cmp);
	for(int i=1;i<=n;i++){
		printf("%d ",st[i].y);
	}
	return 0;
} 

Measured memory_bytes: 2432
#!usr/bin/env python3
import math

a,b = list(map(int,input().split()))

t = 0
if b // 100 == 0 and b // 10 != 0:
    t = 1
elif b // 10 == 0:
    t = 2
if t == 0:
    x = 1000*a+b
elif t == 1:
    x = 100*a+b
else:
    x = 10*a+b

if(math.sqrt(x) % 1 == 0):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(void) {
  int N;
  cin >> N;
  vector<int64_t> A(N);
  rep(i, N) { cin >> A[i]; }

  vector<int64_t> SUM(N + 1);
  SUM[0] = 0;
  rep(i, N) {
    SUM[i + 1] = SUM[i] + A[i];
    // cout << SUM[i+1] << " ";
  }
  // cout << endl;

  unordered_map<int64_t, int64_t> hist;
  int64_t answer = 0;
  rep(i, N) {
    answer += (int64_t)hist[SUM[i + 1]];
    hist[SUM[i + 1]]++;
  }
  answer += hist[0];
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 11592
n=int(input())
a=list(map(int,input().split()))

#初期値が0の辞書
from collections import defaultdict
ab_dic = defaultdict(lambda: 0) 

#a+b
ab=[]

#b-aの個数
ba=[]

for i in range(n):
    banme=i+1
    ab.append(a[i]+banme)
    ba.append(banme-a[i])
    ab_dic[banme+a[i]]+=1


result=0
for i in range(n):
    ii=n-1-i
    if ab_dic[ba[ii]]>=1:
        result+=ab_dic[ba[ii]]
    ab_dic[ab[ii]]-=1


print(result)





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

int main()
{
    /*collecting balls
    int n,k;
    cin>>n>>k;
    vector <int> x(n);
    for(int i=0;i<n;i++)
    {
        cin>>x[i];
    }
    int dist = 0;
    for(int i=0;i<n;i++)
    {
        int dist_part= min(x[i],abs(k-x[i]));
        dist+=dist_part*2;
    }
    cout<<dist<<endl;
    */
    /*
    int n;
    cin>>n;
    vector <int> a(n);
    rep(i,n)
    {
        cin>>a[i];
    }
    sort(a.rbegin(),a.rend());
    int alice=0;
    int bob = 0;
    for(int i=0;i<n;i++)
    {
        if(i%2==0)
        {
            alice += a[i];
        }
        else
        {
            bob += a[i];
        }
    }
    cout<<alice-bob<<endl;
    */
    
    int a,b,c;
    cin>>a>>b>>c;
    int count = 0;
    bool flag = true;
    if(a%2!=0 || b%2!=0||c%2!=0)
    {
        cout<<0<<endl;
        return 0;
    }
    
    if(a==b&&a==c)
    {
        cout<<-1<<endl;
        return 0;
    }
    
    while(flag)
    {
        int tempA,tempB,tempC=0;
        tempA=(b+c)/2;
        tempB=(a+c)/2;
        tempC=(a+b)/2;
        if(tempA%2!=0 || tempB%2!=0||tempC%2!=0)
        {
            count++;
            break;
        }
        else
        {
            a=tempA;
            b=tempB;
            c=tempC;
            count++;
        }
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys
import os

for s in sys.stdin:
    s = s.strip()
    lst = list(s)

    while len(lst) > 1:
        lst2 = []
        for i in range(len(lst) - 1):
            a = int(lst[i])
            b = int(lst[i+1])
            c = (a + b) % 10
            lst2.append(str(c))
        lst = lst2
    print(lst[0])

Measured memory_bytes: 7580
#define $;for(i=j=0;j<n?:(j=0,++i<n);j++)
#define _(a,b)$ for(b=l=0;l<n;)b+=a[i][l]*p[l++][j]%m $ a[i][j]=b%m;}
long m=1e9+7,p[50][50],a[50][50],b[50][50],k;i,j,l;main(n){scanf("%d%ld",&n,&k)$ a[i][i]=scanf("%d",p[i]+j);for(;k;k/=2){if(k&1){_(a,b[i][j])_(p,b[i][j])$ k+=a[i][j];printf("%d",k%m);}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

antennas = []
antennas.append(int(input()))
antennas.append(int(input()))
antennas.append(int(input()))
antennas.append(int(input()))
antennas.append(int(input()))
k = int(input())

antennas = sorted(antennas)
if antennas[4] - antennas[0] > k:
    print(':(')
else:
    print('Yay!')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
long Gcd(long m, long n){
	long temp;
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}
int main(){
    long n,m;
    cin>>n>>m;
    string s,t;
    cin>>s>>t;
    if(s[0]!=t[0]){
        cout<<"-1";
        return 0;
    }
    long g = Gcd(n,m);
    g = (m*n)/g;
    if(m>n){
        swap(n,m);
        swap(s,t);
    }
    for(int i=1; i<m; i++){
        if((i*g/m)%(g/n)==0){
            if(t[i]!=s[i*g/m/(g/n)]){
                cout<<"-1";
                return 0;
            }
        }
    }
    cout<<g;
}

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

int main(){
    int n; cin >> n;
    vector<int> c(n);
    rep(i,n) cin >> c[i];
    int ans=1000000000;
    rep(i,100){
        int sum=0;
        rep(j,n) sum+=(c[j]-(i+1))*(c[j]-(i+1));
        ans=min(ans,sum);
    }
    cout << ans << endl;
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
	int x1,x2,x3,x4,x5;
	cin >> x1 >> x2 >> x3 >> x4 >> x5;
	if(x1 == 0)
		cout << "1\n";
	else if(x2 == 0)
		cout << "2\n";
	else if(x3 == 0)
		cout << "3\n";
	else if(x4 == 0)
		cout << "4\n";
	else
		cout << "5\n";
}

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

signed main () {
	int n;
	cin >> n;
	vector < int > l(n);
	for (int &x: l)
		cin >> x;
	sort(l.begin(), l.end());
	int64_t ans = 0;
	for (int a = 0; a < n; ++a) {
		for (int b = a + 1; b < n; ++b) {
			int c = lower_bound(l.begin(), l.end(), l[a] + l[b]) - l.begin();
			ans += c - b - 1;
		}
	}
	cout << ans << '\n';
}


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


int main(){
  int n;
  string s;
  cin >> n >> s;
  if(n & 1){
    cout << "No";
    return 0;
  }
  for(int i = 0; i < n / 2; i++){
    if(s[i] != s[i + n / 2]){
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <vector>
#define ll long long

std::vector<std::vector<int> > factors(120, std::vector<int>(120));

void INIT_factors(){
  for(int i=1; i<factors.size(); i++){
    int temp = i;
    for(int j=2; j<=temp; j++){
      int count = 0;
      while(temp%j == 0){
	temp/=j;
	count++;
      }
      factors[i][j] = count;
    }
  }
}


int comb( int n, int k )
{
  if (k > n) return 0;
  if (k * 2 > n) k = n-k;
  if (k == 0) return 1;

  int result = n;
  for( int i = 2; i <= k; ++i ) {
    result *= (n-i+1);
    result /= i;
  }
  return result;
}

int main(void){
  INIT_factors();

  int n;
  std::cin >> n;

  int ge14 = 0;
  int ge24 = 0;
  int ge74 = 0;
  int ge4 = 0;
  int ge2 = 0;
  std::vector<int> v(120);
  for(int i=1; i<120; i++){
    for(int j=2; j<=n; j++){
      v[i] += factors[j][i];
    }
    ge4 += v[i]>=4 ? 1 : 0;
    ge2 += v[i]>=2 ? 1 : 0;
    ge14 += v[i]>=14 ? 1 : 0;
    ge24 += v[i]>=24 ? 1 : 0;
    ge74 += v[i]>=74 ? 1 : 0;
  }

  /*for(int i=0; i<v.size(); i++){
    std::cout << v[i] << " ";
  }
  std::cout << std::endl;*/

  int count = comb(ge4, 2) * comb(ge2-2, 1);
  count += comb(ge14, 1) * comb(ge4-1, 1);
  count += comb(ge24, 1) * comb(ge2-1, 1);
  count += comb(ge74, 1);
  std::cout << count << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}

unsigned long  gcd(unsigned long x, unsigned long y)
{
        if (y == 0) {
                return x;
        } else {
                return gcd(y, x % y);
        }
}

int a[100005];
int mod = 1000000007;

long long calc(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i)%mod;
    }
    return rtn;
}

int main(void){
    int n, m;
    long long ans;

    scanf("%d %d", &n, &m);
    if (abs(n - m) == 0){
        ans = (2 * calc(n) * calc(m)) % mod;
    }else if (abs(n - m) == 1){
        ans = (calc(n) * calc(m)) % mod;
    }else{
        printf("0\n");
        return 0;
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 128
//AtCoder ABC114 B - 754
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
int main() {
    string S; cin>>S;
    ll ans=INT64_MAX;
    for(ll i=0;i<=(ll)S.size()-3;++i){
        ll v=std::stol(string(&S[i],3));
        ans=std::min<ll>(ans,abs((ll)753-v));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a, b = [0] * n, [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
a.sort()
b.sort()
if n % 2:
    min_m, max_m = a[n // 2], b[n // 2]
    ans = max_m - (min_m - 1)
else:
    min_m2 = a[n // 2] + a[n // 2 - 1]
    max_m2 = b[n // 2] + b[n // 2 - 1]
    ans = max_m2 - min_m2 + 1
print(ans)

Measured memory_bytes: 25496
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using namespace std;
unsigned GetDigit(unsigned long num);

int main()
{
	int n, m;
	string s;

	cin >> n;
	cin >> s;
	string tmp = "Yes";

	if (n % 2 == 0) {
		for (int i = 0; i < n/2; i++) {
			if (s[i] == s[i + (n / 2)]) {
				tmp = "Yes";
			}
			else {
				tmp = "No";
				break;
			}
		}
		cout << tmp << endl;
	}
	else {
		cout << "No" << endl;
	}
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int a;
    int b;
    int c;
    cin >> a;
    cin >> b;
    cin >> c;
    if (a<=b and b<=c){
        cout << a << " " << b << " " << c << "\n";
    }else if (b<=a and a<=c){
        cout << b << " " << a << " " << c << "\n";
    }else if (c<=a and a<=b){
        cout << c << " " << a << " " << b << "\n";
    }else if (a<=c and c<=b){
        cout << a << " " << c << " " << b << "\n";
    }else if (b<=c and c<=a){
        cout << b << " " << c << " " << a << "\n";
    }else if (c<=b and b<=a){
        cout << c << " " << b << " " << a << "\n";
    }
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    mint ans1 = 1;
    mint ans2 = 1;
    mint ans3 = 1;
    rep(i,n) ans1*=10;
    rep(i,n) ans2*=9;
    rep(i,n) ans3*=8;
    mint ans = ans1 - ans2*2 + ans3;
    cout << ans << endl;

}


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

using namespace std;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)


int main(void){

	int N, M; cin >> N >> M;
	
	long long ans;
	if(N == 1 and M == 1) ans = 1;
	else if(N == 1 and M > 1) ans = M-2;
	else if(M == 1 and N > 1) ans = N-2;
	else ans = (long long)(N-2)*(M-2);

	cout << ans << endl;

	return 0;

}


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

using namespace std;
using ll = long long;

int main(){
    string s;
    cin >> s;
    int a = 0;
    int b = 0;
    for(int i=0; i<3; i++){
        if(s[i]=='A'){
            a += 1;
        }else{
            b += 1;
        }
    }
    if(a*b==0){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#define FL "a"
using namespace std;
typedef long long ll;
typedef double dd;
const int N=2e5+10;
const ll INF=1e18;
inline ll read(){
  ll data=0,w=1;char ch=getchar();
  while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
  if(ch=='-')w=-1,ch=getchar();
  while(ch<='9'&&ch>='0')data=data*10+ch-48,ch=getchar();
  return data*w;
}
inline void file(){
  freopen(FL".in","r",stdin);
  freopen(FL".out","w",stdout);
}

int n,m;ll x[N];ll ans;
int head[N],nxt[N<<1],to[N<<1],val[N<<1],cnt;
inline void add(int u,int v,int w){
  to[++cnt]=v;val[cnt]=w;nxt[cnt]=head[u];head[u]=cnt;
}

struct edge{int u,v;ll w;}E[20*N];
inline bool cmp(edge a,edge b){return a.w<b.w;}
int fa[N];int find(int x){return fa[x]?fa[x]=find(fa[x]):x;}

ll dep[N];int Dep[N],ffa[N],siz[N],son[N],top[N];
void dfs1(int u,int ff){
  ffa[u]=ff;siz[u]=1;son[u]=0;Dep[u]=Dep[ff]+1;
  for(int i=head[u],v;i;i=nxt[i]){
    v=to[i];if(v==ff)continue;
    dep[v]=dep[u]+val[i];dfs1(v,u);
    siz[u]+=siz[v];if(siz[son[u]]<siz[v])son[u]=v;
  }
}
void dfs2(int u,int tp){
  top[u]=tp;if(son[u])dfs2(son[u],tp);
  for(int i=head[u],v;i;i=nxt[i]){
    v=to[i];if(v==ffa[u]||v==son[u])continue;
    dfs2(v,v);
  }
}
inline int lca(int u,int v){
  while(top[u]!=top[v])
    Dep[top[u]]>Dep[top[v]]?u=ffa[top[u]]:v=ffa[top[v]];
  return Dep[u]<Dep[v]?u:v;
}
inline ll dist(int u,int v){return dep[u]+dep[v]-2ll*dep[lca(u,v)];}

int rt,blk,sz[N],w[N],vis[N];
void getsz(int u,int ff){
  sz[u]=1;
  for(int i=head[u],v;i;i=nxt[i]){
    v=to[i];if(v==ff||vis[v])continue;
    getsz(v,u);sz[u]+=sz[v];
  }
}
void getrt(int u,int ff){
  w[u]=blk-sz[u];
  for(int i=head[u],v;i;i=nxt[i]){
    v=to[i];if(v==ff||vis[v])continue;
    getrt(v,u);w[u]=max(w[u],sz[v]);
  }
  if(w[u]<w[rt])rt=u;
}
int c;ll len[N];
void getmin(int u,int ff){
  if(len[c]+x[c]>len[u]+x[u])c=u;
  for(int i=head[u],v;i;i=nxt[i]){
    v=to[i];if(v==ff||vis[v])continue;
    len[v]=len[u]+val[i];getmin(v,u);
  }
}
void getedge(int u,int ff){
  if(u!=c)E[++m]=(edge){u,c,x[u]+x[c]+dist(u,c)};
  for(int i=head[u],v;i;i=nxt[i]){
    v=to[i];if(v==ff||vis[v])continue;
    getedge(v,u);
  }
}
inline void solve(int u){
  //printf("solve:%d\n",u);
  len[u]=0;c=u;getmin(u,0);
  //printf("c=%d\n",c);
  getedge(u,0);vis[u]=1;
  for(int i=head[u],v;i;i=nxt[i]){
    v=to[i];if(vis[v])continue;
    getsz(v,u);rt=0;blk=sz[v];getrt(v,u);solve(rt);
  }
}

int main()
{
  n=read();
  for(int i=1;i<=n;i++)x[i]=read();
  for(int i=2,u,v,_w;i<=n;i++){
    u=read();v=read();_w=read();
    add(u,v,_w);add(v,u,_w);
    E[++m]=(edge){u,v,x[u]+x[v]+_w};
  }
  dfs1(1,0);dfs2(1,1);

  rt=0;w[0]=blk=n;len[0]=INF;
  getsz(1,0);getrt(1,0);solve(rt);

  /*for(int i=1;i<=m;i++)
    printf("(%d,%d,%lld)\n",E[i].u,E[i].v,E[i].w);*/
  
  sort(E+1,E+m+1,cmp);
  for(int i=1,u,v;i<=m;i++){
    u=E[i].u;v=E[i].v;
    if(find(u)!=find(v)){
      fa[find(u)]=find(v);
      ans+=E[i].w;
    }
  }
  printf("%lld\n",ans);
  return 0;
}


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

int main()
{
    int K;
    cin >> K;
    string S;
    cin >> S;
    if (S.size() <= K)
        cout << S << endl;
    else
    {
        for (int i = 0; i < K; i++)
            cout << S[i];
        cout << "..." << endl;
    }
    return 0;
}

Measured memory_bytes: 3596
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	string s; cin >> s;
	sort(ALL(s));
	string ext(s.begin(), unique(ALL(s)));
	REP(i, 26) {
		if (ext[i] != 'a' + i) {
			cout << (char)('a' + i);
			return 0;
		}
	}
	cout << "None" << endl;
}

Measured memory_bytes: 512
module Main where

count :: Eq a => a -> [a] -> Int
count _ [] = 0
count a (x:xs)
	| a == x = 1 + count a xs
	| otherwise = count a xs

summary :: [String] -> String
summary results = "AC x " ++ ac ++ "\nWA x " ++ wa ++ "\nTLE x " ++ tle ++ "\nRE x " ++ re
	where { ac = show $ count "AC" results ;
		wa = show $ count "WA" results ;
		tle = show $ count "TLE" results ;
		re = show $ count "RE" results }

main :: IO ()
main = interact $ summary . tail . lines


Measured memory_bytes: 22396
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll ;
typedef double db;
const double pi = 3.141592654;
#define pb         push_back
#define forab(i,a,b)       for(int i=(a);i<=(b);i++)
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)
#define pcase(z,x)     printf("Case %ld: %lld\n",z,x)
#define nw				"\n"


int main(void)
{
	CIN;
	ll tc,l,k,sum=0,x=0,y,z=0,m=1,n=0,ans=0;
	cin>>n>>m>>k;
	vector<int>v(m);
	for(ll i=0;i<m;i++)
	{
		cin>>v[i];
		if(v[i]<k)x++;
		else z++;
	}
	cout<<min(x,z)<<nw;
}


Measured memory_bytes: 3592
require 'set'

def main
  loop do
    n,h = gets.chomp.split(' ').map(&:to_i)
    break if (n|h) == 0
    puts get_non_hole_cubes_num(n, h)
  end
end
 
def get_non_hole_cubes_num n, h
  hole_cubes = Set.new
 
  h.times do
    c,a,b = gets.chomp.split(' ')
    case c
    when 'xy'
      x = a.to_i
      y = b.to_i
      1.upto(n) do |idx|
        hole_cubes << "#{x} #{y} #{idx}"
      end
    when 'xz'
      x = a.to_i
      z = b.to_i
      1.upto(n) do |idx|
        hole_cubes << "#{x} #{idx} #{z}"
      end
    when 'yz'
      y = a.to_i
      z = b.to_i
      1.upto(n) do |idx|
        hole_cubes << "#{idx} #{y} #{z}"
      end
    end
  end
  n ** 3 - hole_cubes.size
end

main

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

#define ll long long
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);

void solve()
{
    ll n,final=0;
    cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++) cin>>a[i];
    
    for(ll i=1;i<n;i++)
    {
        if(a[i]>=a[i-1]);
        else
        {
            final+=a[i-1]-a[i];
            a[i]=a[i-1];
        }
    }
    cout<<final;
}

int main()
{
	FAST
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++) solve();
	return 0;
}

Measured memory_bytes: 5216
#include<iostream>
using namespace std;
long long n,k;
int a[200005],last[200005];
bool vis[200005];
int main(){
cin >> n >> k;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
	int take = min(k, 200000LL);
	k -= take;
	int cur = 1;
	while(take > 0)
	{
		cur = a[cur];
		take--;
	}
	if(k == 0)
	{
		cout << cur;
		return 0;
	}
	int len = 0;
	while(!vis[cur])
	{
		vis[cur] = 1;
		len++;
		cur = a[cur];
	}
	k %= len;
	while(k > 0)
	{
		cur = a[cur];
		k--;
	}
	cout << cur;
		return 0;
}

Measured memory_bytes: 4612
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll Mypow(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}

ll INFL = 1LL << 60;//10^18 = 2^60
int INF = 1 << 30;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1};
//vector<int> dx = {1,-1,0,0};

int main(){
  ll N, T; cin >> N >> T;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  ll max_cost = -1;
  ll mi = INFL;
  rep(i, N){
    mi = min(mi, A[i]);
    if(mi < A[i]){
      max_cost = max(max_cost, A[i] - mi);
    }
  }
  multiset<ll> Mset;
  set<ll> M;
  rep(i, N){
    Mset.insert(A[i]);
    if(Mset.count(A[i]-max_cost)){
      M.insert(i);
    }
  }

  multiset<ll> mset;
  set<ll> m;
  revrep(i, N){
    mset.insert(A[i]);
    if(mset.count(A[i]+max_cost)){
      m.insert(i);
    }
  }
  cout << max(m.size(), M.size()) << endl;


}


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

using namespace std;

int main(int argc, const char *argv[]) {
  int x, n;
  cin >> x >> n;
  set<int> vp;
  for (int i = 0; i < n; ++i) {
    int p;
    cin >> p;
    vp.insert(p);
  }

  int min_abs = -1, min_n = -1;
  for (int i = -100; i < 200; ++i) {
    if (vp.count(i) > 0) {
      continue;
    }

    int abs_n = abs(x - i);
    if (min_abs < 0 || min_abs > abs_n) {
      min_abs = abs_n;
      min_n = i;
    } else if (min_abs == abs_n && min_n > i) {
      min_n = i;
    }
  }

  cout << min_n << '\n';

  return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;
import java.util.Arrays;
import java.util.StringJoiner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] processInfo = scanner.nextLine().split(" ");
        
        int processCount = Integer.parseInt(processInfo[0]);
        int quantum = Integer.parseInt(processInfo[1]);
        
        Queue queue = new Queue(processCount);
        
        for (int i = 0; i < processCount; i++) {
            String[] p = scanner.nextLine().split(" ");
            queue.push(new Process(p[0], p[1]));
        }
        int totalTime = 0;
        
        while (!queue.isEmpty()) {
            Process p = queue.poll();
            int spend = p.doTask(quantum);
            
            totalTime += spend;
            if (p.hasDone()) {
                System.out.printf("%s %d%n", p.getName(), totalTime);
            } else {
                queue.push(p);
            }

        }
        
    }
    
    private static class Queue {
        
        private Process[] data;
        private int top = 0;
        private int last = 0;
        
        public Queue(int size) {
            data = new Process[size + 1];
        }
        
        public void push(Process p) {
            data[last] = p;
            last++;
            
            if (last >= data.length) {
                last = 0;
            }
        }
        
        public Process poll() {
            Process p = data[top];
            data[top] = null;
            top++;
            if (top >= data.length) {
                top = 0;
            }
            
            return p;
        }
        
        public boolean isEmpty() {
            return top == last;
        }
        
    }
    
    private static class Process {
        private String name = null;
        private int time = 0;
        public Process(String name, String time) {
            this.name = name;
            this.time = Integer.parseInt(time);
        }
        
        public int doTask(int quantum) {
            int spend = quantum - Math.max(quantum - time, 0);
            time = Math.max(time - quantum, 0);
            return spend;
        }
        
        public String getName() {
            return name;
        }
        
        public boolean hasDone() {
            return time <= 0;
        }
    }
}


Measured memory_bytes: 127884
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;
#define REP(i,a,b) for(register int i=a;i<=b;++i)
#define DREP(i,a,b) for(register int i=a;i>=b;--i)
#define mem(a) memset(a,0,sizeof(a))
inline char get_char(){
	static char buf[1000000],*p1,*p2;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int read(){
    int numm=0;
    char _;_=get_char();
    while(_<'0'||_>'9'){_=get_char();} 
    while(_>='0'&&_<='9'){numm=(numm<<3)+(numm<<1)+(_^48);_=get_char();   }
    return numm;
}
const int maxn=1000+10;
const int maxm=200000+10;
vector<int>E[maxn];
int n,m,beg[maxn],len,num[maxn][maxn];
bool can[maxn][maxn],vis[maxn],can1[maxn][maxn];
int vis1[maxn],vis2[maxn],from[maxm],to[maxm];
void dfs(int u,int rt){
	vis[u]=1;
	can[rt][u]=1;
	int size=E[u].size()-1;
	REP(i,0,size){
		int v=E[u][i];
		if(vis[v])continue;
		dfs(v,rt);
	}
}
void dfs1(int u){
	vis[u]=1;
	int size=E[u].size()-1;
	REP(i,0,size){
		int v=E[u][i];
		if(vis[v])continue;
		vis1[v]=num[u][v];
		dfs1(v);
	}
}
void dfs2(int u){
	vis[u]=1;
	int size=E[u].size()-1;
	DREP(i,size,0){
		int v=E[u][i];
		if(vis[v])continue;
		vis2[v]=num[u][v];
		dfs2(v);
	}
}
int main(){
//	freopen("test.txt","r",stdin);
	n=read();m=read();
	REP(i,1,m){
		int u,v;
		u=read();v=read();
		E[u].push_back(v);
		num[u][v]=++len;
		from[len]=u;
		to[len]=v;
	}
	REP(i,1,n){
		dfs(i,i);
		mem(vis);
	}
	REP(i,1,n){
		dfs1(i);
		mem(vis);
		dfs2(i);
		mem(vis);
		int size=E[i].size()-1;
		REP(j,0,size){
			int v=E[i][j];
			if(vis1[v]!=num[i][v] || vis2[v]!=num[i][v])
				can1[i][v]=1;
		}
		mem(vis1);
		mem(vis2);
	}
	REP(i,1,m){
		int u=from[i],v=to[i];
		if((can[v][u]^can1[u][v])==0)
			puts("same");
		else puts("diff");
	}
	return 0;
}

Measured memory_bytes: 13600
/*
	Name: Active Infants
	Description: abc163_e
	History:
    Number     	Time                  Author                  details
    1     	    2020.4.20 15:00       JerryDream              NULL
*/
#include "bits/stdc++.h"
using namespace std;
struct child
{
	int id;
	long long val;
	bool operator < (child it)
	{
		if(val != it.val)
		{
			return val > it.val;
		}
		return id < it.id;
	}
};
const int maxn = 2010;
int n;
child a[maxn];
long long dp[maxn][maxn]; 
int main()
{
	cin>>n;
	for(int i = 0; i < n; i++)
	{
		cin>>a[i].val;
		a[i].id = i;
	}
	sort(a, a + n);
	for(int k = 0; k < n; k++)
	{
		for(int i = 0; i <= k; i++)
		{
			int j = k - i;
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + a[k].val * (a[k].id - i));
			dp[i][j + 1] = max(dp[i][j + 1], dp[i][j] + a[k].val * (n - j - 1 - a[k].id));
		}
	}
	long long ans = 0LL;
	for(int i = 0; i <= n; i++)
	{
		ans = max(ans, dp[i][n - i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 26316
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
typedef long long ll;
const long long inf=1e+9;
int main(void){
    // Your code here!
    int h,n;cin>>h>>n;
    vector<ll> A(n),B(n),c(n);
    rep(i,n){
        cin>>A[i]>>B[i];
        c[i]=A[i];
    }
    sort(c.begin(),c.end());
    ll maxa=c[n-1];
    vector<ll> dp(h+maxa);
    dp[0]=0;
    rep(i,h+maxa){
        if(i==0)continue;
        rep(j,n){
            ll a=A[j],b=B[j];
            if(i-a>=0){
                if(dp[i]==0)dp[i]=dp[i-a]+b;
                dp[i]=min(dp[i],dp[i-a]+b);
            }else{
                if(dp[i]==0)dp[i]=b;
                else{
                    dp[i]=min(dp[i],b);
                }
            }
        }
    }
    ll res=inf;
    for(int i=h;i<h+maxa;i++){
        res=min(dp[i],res);
    }
    cout<<res<<endl;
}

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

int main() {
    int vec[101][101], b[101], n, m, i, j, sum;

    cin >> n >> m;
    for(i=1;i<n+1;i++){
        for(j=1;j<m+1;j++){
            cin >> vec[i][j];
        }
    }
    for(j=1;j<m+1;j++){
        cin >> b[j];
    }

    for(i=1;i<n+1;i++){
        sum=0;
        for(j=1;j<m+1;j++){
            sum= vec[i][j]*b[j]+sum;
        }
        cout << sum << endl;
    }

    return 0;
}


Measured memory_bytes: 3120
#include<stdio.h>
#include<string.h>
int main(){
  char s[100];
  scanf("%s",s);
  if(strcmp(s,"Sunny")==0){
    printf("Cloudy");
  }
  if(strcmp(s,"Cloudy")==0){
    printf("Rainy");
  }
  if(strcmp(s,"Rainy")==0){
    printf("Sunny");
  }
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>

#define rep(i, j) FOR(i, 0, j)
#define FOR(i, j, k) for(int i = j; i < k; ++i)

using namespace std;
bool a[1000001];

bool isprime(int x){
  for(int i = 2; i * i <= x; i++)
    if(x % i == 0) return true;
  return x == 1; 
}

int solve(int i){
  while(true){
    if(a[i] && !isprime(i)) return i;
    i--;
  }
}

int main(){
  int n, x, v, res;
  while(scanf("%d%d", &n, &x) && n && x){
    rep(i, x + 1) a[i] = false;
    a[0] = true;
    rep(i, n){
      scanf("%d", &v);
      for(int i = v; i <= x; i++) if(a[i - v]) a[i] = true;
    }

    if(res = solve(x)) printf("%d\n", res);
    else puts("NA");
  }
  return 0;
}

Measured memory_bytes: 2016