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

typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define int ll
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define ALL(s) (s).begin(),(s).end()
#define ALLn(s,n) s,s+n
#define F first
#define S second
#define pb push_back
#define tc(t) int t; cin >> t; while(t--)
#define _ ios_base::sync_with_stdio(false); cin.tie(NULL);
#define D1(x) { cerr << " [" << #x << ": " << x << "]\n"; }
#define D2(x) { cerr << " [" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n"; }

const ll MOD = 1e9 + 7;
const ll MAXN = 1e6 + 7;
const ll INF = LONG_LONG_MAX;

void solve() {
	int x,n;
	cin >> x >> n;
	int a[n];
	map<int,int> mp;

	F0R(i,n) cin >> a[i], mp[a[i]]++;
	int ans = INT_MAX;
	int val = -1;
	FOR(i,-300,300) {
		if(mp.count(i)==0) {
			if(ans>abs(x-i)) {
				ans = abs(x-i);
				val = i;
			}
		}
	}
	cout << val << "\n";
}

int32_t main() {_
	
#ifndef ONLINE_JUDGE
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
#endif

	// tc(t)
		solve();
	cerr << "[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
}



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

int main(){
    int N, ans = 0; long long H, W, h, w;
    cin >> N >> H >> W;
    for (int i = 0; i < N; i++) {
        cin >> h >> w;
        if (H <= h && W <= w) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> pll;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(make_pair(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
const int mod = 1000000007;

int main() {
    int a, b;
    cin >> a >> b;
    if(a <= 9 && b <= 9) {
        cout << a * b << endl;
    } else {
        cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3604
fn main() {
    // 複数行 1行複数要素
    loop {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let mut iter = buf.trim().split_whitespace();
        // 2要素変換
        let element1: i32 = iter.next().unwrap().parse().unwrap();
        let element2: i32 = iter.next().unwrap().parse().unwrap();
        // break
        if element1 == 0 && element2 == 0 {
            break;
        };
        // ソート、出力
        let mut elements = [element1, element2];
        elements.sort();
        println!("{} {}", elements[0], elements[1]);
    }
}



Measured memory_bytes: 5024
#include <stdio.h>

#define MAX 10000
#define NIL -1

typedef struct {
	int parent, left, right;
} Node;

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u,int d) {
  if(u == NIL) return;
  D[u] = d;
  setDepth(T[u].left, d+1);
  setDepth(T[u].right,d+1);
}

int setHeight(int u) {
  int h1 = 0, h2 = 0;
  if(T[u].left != NIL)
    h1 = setHeight(T[u].left)  + 1;
  if(T[u].right != NIL)
    h2 = setHeight(T[u].right) + 1;
  return H[u] = (h1 > h2 ? h1 : h2);
}

// 接点 u の兄弟を返す
int getSibling(int u) {
  if(T[u].parent == NIL) return NIL;
  if(T[T[u].parent].left != u && T[T[u].parent].left != NIL )
    return T[T[u].parent].left;
  if(T[T[u].parent].right != u && T[T[u].parent].right != NIL )
    return T[T[u].parent].right;
  return NIL;
}

void print(int u) {
  int deg = 0;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].parent);
  printf("sibling = %d, ",getSibling(u));
  if(T[u].left  != NIL) deg++;
  if(T[u].right != NIL) deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);
  
  if(T[u].parent == NIL) {
    printf("root\n");
  } else if(T[u].left == NIL && T[u].right == NIL) {
    printf("leaf\n");
  } else {
    printf("internal node\n");
  }
}

int main(void) {
  int i, v, l, r, root = 0;
  scanf("%d",&n);
  for(i=0;i<n;i++) T[i].parent = NIL;
  for(i=0;i<n;i++) {
    scanf("%d %d %d",&v,&l,&r);
    T[v].left  = l;
    T[v].right = r;
    if(l != NIL) T[l].parent = v;
    if(r != NIL) T[r].parent = v;
  }
  
  for(i=0; i<n; i++)
  if(T[i].parent == NIL) root = i;
  
  setDepth(root,0);
  setHeight(root);
  
  for(i=0;i<n;i++) print(i);
  
  return 0;
}


Measured memory_bytes: 2108
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;
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; }

typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
typedef long double ldouble;

typedef vector<llong> vecllong;
typedef vector<vecllong> vvecllong;

const llong MOD = 1e9 + 7;
const llong INF = 1e17;

#define FOR(i, n) for (llong i = 0; i < n; i++)
#define FORS(i, a, b) for (llong i = a; i < b; i++)
#define FORR(i, n) for (llong i = n; i > 0; i++)

vector<vector<bool>> stage;
vvecllong dp;

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

    llong H, W;
    cin >> H >> W;

    stage = vector<vector<bool>>(H + 2, vector<bool>(W + 2, false));

    FORS(h, 1, H + 1) {
        FORS(w, 1, W + 1) {
            char c;
            cin >> c;
            if(c == '.') {
                stage[h][w] = true;
            }
        }
    }

    dp = vvecllong(H + 1, vecllong(W + 1, 0));  // memo[h][w] = 場合の数
    dp[1][1] = 1;

    FORS(h, 1, H + 1) {
        FORS(w, 1, W + 1) {
            if(stage[h + 1][w]) dp[h + 1][w] = (dp[h + 1][w] + dp[h][w]) % MOD;
            if(stage[h][w + 1]) dp[h][w + 1] = (dp[h][w + 1] + dp[h][w]) % MOD;
        }
    }

    cout << (dp[H][W] % MOD) << endl;

    return 0;
}

Measured memory_bytes: 8320
N = int(input())
h = list(map(int,input().split()))

def culc(h_tmp):
  if len(set(h_tmp))==1:
    return h_tmp[0]
  elif len(h_tmp)==0:
    return 0
  else:
    min_h = min(h_tmp)
    i = h_tmp.index(min_h)
    h_tmp = list(map(lambda x:x-min_h,h_tmp))
    return culc(h_tmp[:i]) + culc(h_tmp[i+1:]) + min_h

print(culc(h))


Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

	public static void main(String[] args) throws IOException {

		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

			List<Integer> inSpades = new ArrayList<>();
			List<Integer> inHearts = new ArrayList<>();
			List<Integer> inClub = new ArrayList<>();
			List<Integer> inDia = new ArrayList<>();

			final Integer maxLine = Integer.valueOf(br.readLine());

			for (int i = 0; i < maxLine; i++) {

				final String inputLine = br.readLine();

				final String[] set = inputLine.split(" ");

				final String suit = set[0];
				final Integer number = Integer.valueOf(set[1]);

				switch(suit) {
				case "S":
					inSpades.add(number);
					break;
				case "H":
					inHearts.add(number);
					break;
				case "C":
					inClub.add(number);
					break;
				case "D":
					inDia.add(number);
				}
			}

			List<Integer> outSpades = new ArrayList<>();
			List<Integer> outHearts = new ArrayList<>();
			List<Integer> outClubs = new ArrayList<>();
			List<Integer> outDias = new ArrayList<>();
			for(int i = 1; i <= 13; i++) {
				outSpades.add(i);
				outHearts.add(i);
				outClubs.add(i);
				outDias.add(i);
			}

			 outSpades.removeAll(inSpades);
			 outHearts.removeAll(inHearts);
			 outClubs.removeAll(inClub);
			 outDias.removeAll(inDia);

			 StringBuilder result = new StringBuilder();

			 int count = 0;
			 for(int i = 0; i < outSpades.size(); i++) {
				 if(0 < count++) {
					 result.append("\n");
				 }
				 result.append("S " + outSpades.get(i));
			 }
			 for(int i = 0; i < outHearts.size(); i++) {
				 if(0 < count++) {
					 result.append("\n");
				 }
				 result.append("H " + outHearts.get(i));
			 }
			 for(int i = 0; i < outClubs.size(); i++) {
				 if(0 < count++) {
					 result.append("\n");
				 }
				 result.append("C " + outClubs.get(i));
			 }
			 for(int i = 0; i < outDias.size(); i++) {
				 if(0 < count++) {
					 result.append("\n");
				 }
				 result.append("D " + outDias.get(i));
			 }

			 if(!result.toString().equals("")) {
				 System.out.println(result);
			 }
		}
	}
}


Measured memory_bytes: 24368
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
constexpr int MOD = 1000000007;
constexpr int INF = 2000000000;

int main() {
	int n, q;
	std::queue<std::pair<std::string,int>> que;
	std::cin >> n >> q;
	int a;
	std::string c;
	for (int i = 0; i < n; i++) {
		std::cin >> c >> a;
		que.push(std::make_pair(c, a));
	}
	int time = 0;
	while (!que.empty()) {
		c = que.front().first;
		a = que.front().second;
		que.pop();
		if (a > q) {
			time += q;
			a -= q;
			que.push(std::make_pair(c, a));
		}
		else {
			time += a;
			std::cout << c << " " << time << std::endl;
		}
	}
}

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

b = []
ord = [-1 for x in range(n+1)]
c = 1
l = 1

v = 1
#while(ord[v] == -1):
for x in range(n):
    if (ord[v] != -1):
        break
    ord[v] = x
    b.append(v)
    v = a[v-1]
c = len(b) - ord[v]
l = ord[v]

if (k < l):
    print(b[k])
else:
    k -= l
    k %= c
    print(b[l+k])


Measured memory_bytes: 32380
#include <iostream>
#include <unordered_map>

using namespace std;

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

    unordered_map<long long, int> mp;
    long long a, ans = 0, sum = 0;
    ++mp[0];
    for (int i = 0; i < n; ++i) {
        cin >> a;
        sum += a;
        ans += mp[sum];
        ++mp[sum];
    }
    cout << ans << endl;
}
/*
累積和が等しい2点間の、連続する部分列の和は０になる。
ある累積和がn個存在するとき、n個の中から2点を選ぶ組み合わせはnC2通り。

累積和１が３回現れる場合。
1回目：
    sum += a;  // sum = 1
    ans += mp[sum];  // mp[1] = 0 <- 初回の累積和はカウントされない
    ++mp[sum];  // mp[1] = 1

2回目：
    sum += a;  // sum = 1
    ans += mp[sum];  // mp[1] = 1 <- 累積和１が２回出たのでansがカウントされる。2C2=1通り
    ++mp[sum];  // mp[1] = 2 <- 累積和１が２点に存在する

3回目：
    sum += a;  // sum = 1
    ans += mp[sum];  // mp[1] = 2 <- 累積和１が３回出たのでansがカウントされる。3C2=3通り
    ++mp[sum];  // mp[1] = 3 <- 累積和１が３点に存在する
*/


Measured memory_bytes: 8520
// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
void solve();
int main() { solve(); return 0; }

vector<string> Z { "NO", "YES" };

#include <set>
void solve() {
  string s;
  cin >> s;
  string u = s;
  reverse(u.begin(), u.end());  
  int n = s.size();
  int cnt = 0;
  loop(i,0,n) cnt += s[i]!=u[i];
  cout << cnt/2 << endl;
}


Measured memory_bytes: 3608
from collections import Counter
import math

N = int(input())
Al = list(map(int, input().split()))
d_di = {}
#d_in = {}
counter = Counter(Al)
As_l = list(set(Al))
for n in As_l:
    cnt = int(counter[n])
    if cnt > 1:
        d_di[n] = (math.factorial(cnt) // (2 * math.factorial(cnt - 2)))
    else:
        pass
#    if cnt > 2:
#        d_in[n] = (math.factorial(cnt-1) // (2 * math.factorial(cnt - 3)))
#    else:
#        d_in[n] = 1
# print(d_di)
# print(d_in)
total = sum(v for v in d_di.values())
for k in Al:
    ans = total - (counter[k]-1)
    if ans < 0:
        ans = 0
    else:
        pass
    print(ans)


Measured memory_bytes: 114380
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7,N=1e6+5;
ll n,h,d,f[N],sum[N],s;
int main()
{
    scanf("%lld%lld%lld",&n,&h,&d);
    f[0]=1;
    for(int i=1;i<=n;i++)
        f[i]=f[i-1]*i%mod,s=(s+f[i])%mod;
    sum[1]=1;
    for(int i=2;i<=h;i++)
        sum[i]=(sum[i-1]+(sum[i-1]-sum[max(0ll,i-d-1)])*s)%mod;
    printf("%lld\n",((sum[h]-sum[h-d])*f[n]%mod+mod)%mod);
}


Measured memory_bytes: 15872
#include<iostream>
#define O return cout<<"NO"<<endl,0
using namespace std;
string s;
main()
{
  cin>>s;
  int id=0;
  if(s[id]=='A')id++;
  if(s[id]=='K')id++;
  else O;
  if(s[id]=='I')id++;
  else O;
  if(s[id]=='H')id++;
  else O;
  if(s[id]=='A')id++;
  if(s[id]=='B')id++;
  else O;
  if(s[id]=='A')id++;
  if(s[id]=='R')id++;
  else O;
  if(s[id]=='A')id++;
  if(id<s.size())O;
  cout<<"YES"<<endl;
}

Measured memory_bytes: 256
"""
author : halo2halo
date : 24, Jan, 2020
"""

import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, A = map(int, read().split())

print('Even' if N * A % 2 == 0 else 'Odd')


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

int main(){
    int N;
    cin >> N;
    vector<long long> A(N);
    vector<long long> B(N);
    for(int i = 0; i < N; i++)cin >> A[i] >> B[i];
    
    long long sum = 0;
    for(int i = N - 1; i >= 0; i--)sum += ((B[i] - ((A[i] + sum) % B[i])) % B[i]);
    
    cout << sum << endl;
}

Measured memory_bytes: 1792
a1=list(map(int,input().split(" ")))
a2=list(map(int,input().split(" ")))
a3=list(map(int,input().split(" ")))
N=int(input())
b=[]

for i in range(N):
    b.append(int(input()))

allnum=[]
allnum.append(a1)
allnum.append(a2)
allnum.append(a3)


bingo=[[0,0,0],[0,0,0],[0,0,0]]

for k in b:
    for i in range(3):
        for j in range(3):
            if(k==allnum[i][j]):
                bingo[i][j]=1

for i in range(3):
    if(bingo[i][0] and bingo[i][1] and bingo[i][2]):
        print("Yes")
        exit()
for i in range(3):
    if(bingo[0][i] and bingo[1][i] and bingo[2][i]):
        print("Yes")
        exit()
if(bingo[0][0] and bingo[1][1] and bingo[2][2]):
    print("Yes")
    exit()

if(bingo[2][0] and bingo[1][1] and bingo[0][2]):
    print("Yes")
    exit()
print("No")

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

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    if ((b - a) % 2 == 0) {
        cout << "Alice" << endl;
    }
    else {
        cout << "Borys" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,k;cin>>n>>k;
  priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<>>que;
  while(n--){
    ll a,b;cin>>a>>b;
    que.push(mp(a,b));
  }
  while(true){
    ll num = que.top().F;
    ll cnt = que.top().S;
    que.pop();
    if(cnt < k){
      k-=cnt;
    }else{
      cout<<num<<endl;return 0;
    }
  }
  return 0;
}



Measured memory_bytes: 2420
# Your code here!

#データの読み込み

fline=readlines
input=fline[0].split(" ")

n=input[0].to_i
u=Array.new(n)
x=Array.new(n)
i=0
for i in 0..n-1 do
    input=fline[i+1].split(" ")
    u[i]=input[1]
    x[i]=input[0].to_f
end

#実際の処理

ans=0
for i in 0..n-1 do
	if u[i]=='JPY' then
		ans=ans+x[i]
	else
		ans=ans+x[i]*380000
	end
end


#出力

printf('%f', ans)





Measured memory_bytes: 1788
n = int(input())
s = input()

def caluculate_x(n, s):
    x = 0
    x_list = [0]
    
    i = 0
    while (i < n):
        if (s[i] == 'I'):
            x += 1
        elif (s[i] == 'D'):
            x -= 1
        
        x_list.append(x)
        
        i += 1
        
    return x_list

answer = max(caluculate_x(n, s))
print(answer)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define mems(a,x) memset(a,x,sizeof(a))
#define first fi
#define second se
using namespace std;
typedef long long ll;
const int mod=1e9+7,MS=105,N=66;
const double eps=1e-8;
ll inv(ll x){return x==1?x:(mod-mod/x)*inv(mod%x)%mod;}
ll inv(ll x,ll mod){return x==1?x:(mod-mod/x)*inv(mod%x,mod)%mod;}
ll qpow(ll a,ll n){ll ans=1;while(n){if(n&1) ans=ans*a%mod;a=a*a%mod;n>>=1;}return ans;}
ll mul(ll a,ll b){ll ans=0;while(b){if(b&1) ans=(ans+a)%mod;a=(a+a)%mod;b>>=1;};return ans;}
ll qpow(ll a,ll n,ll mod){ll ans=1;while(n){if(n&1) ans=ans*a%mod;a=a*a%mod;n>>=1;}return ans;}
ll mul(ll a,ll b,ll mod){ll ans=0;while(b){if(b&1) ans=(ans+a)%mod;a=(a+a)%mod;b>>=1;};return ans;}
struct vec
{
    double x,y;
    vec(double x=0,double y=0):x(x),y(y){}
    vec operator+(const vec&o)const{ return vec(x+o.x,y+o.y);}
    vec operator-(const vec&o)const{ return vec(x-o.x,y-o.y);}
    double operator*(const vec&o)const{ return x*o.x+y*o.y;}
    double operator^(const vec&o)const{ return x*o.y-y*o.x;}
    vec operator/(const double&o)const{ return vec(x/o,y/o);}
    vec operator*(const double&o)const{ return vec(x*o,y*o);}
    void sc(){scanf("%lf%lf",&x,&y);}
    double len(){return sqrt(x*x+y*y);}
};
struct Mat
{
    ll a[MS][MS];
    int n,m;
    Mat(int n=0,int m=0):n(n),m(m) { mems(a,0);}
    Mat operator*(const Mat&B)const
    {
        Mat C(n,B.m);
        for(int i=1;i<=n;i++)
            for(int j=1;j<=B.m;j++)
                for(int k=1;k<=m;k++)
                C.a[i][j]=(C.a[i][j]+a[i][k]*B.a[k][j])%mod;
        return C;
    }
};
int n,k;
vec a[N];
double c[N];
vec s1,s2;
vec polar(double a,double r){return vec(cos(r)*a,sin(r)*a);}
bool intersect(vec c1,vec c2,double r1,double r2)
{
    double d=(c1-c2).len();
    if(d-eps>r1+r2||d<=r1||d<=r2) return false;
    //相离或内含
    double a=acos((r1*r1+d*d-r2*r2)/(2*r1*d));
    double t=atan2(c2.y-c1.y,c2.x-c1.x);
    s1=c1+polar(r1,t-a);
    s2=c1+polar(r1,t+a);
    return true;
}
bool judge(double T)
{
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            if(!intersect(a[i],a[j],T/c[i],T/c[j])) continue;
            int x=0,y=0;
            for(int k=1;k<=n;k++)
            {
                if(c[k]*(s1-a[k]).len()<=T+eps) x++;
                if(c[k]*(s2-a[k]).len()<=T+eps) y++;
            }
            if(x>=k||y>=k) return true;
        }
        int x=0;
        for(int j=1;j<=n;j++)
            if(c[j]*(a[i]-a[j]).len()<=T+eps) x++;
        if(x>=k) return true;
    }
    return false;
}
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
        a[i].sc(),scanf("%lf",&c[i]);
    double l=0,r=200000;
    for(int i=1;i<=40;i++)
    {
        double m=(l+r)/2;
        if(judge(m)) r=m;
        else l=m;
    }
    printf("%.10f\n",(l+r)/2);
}
/*
|? ?| * |f(x)  | == |f(x+1)|
|? ?|   |f(x-1)|    |f(x)  |
*/


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

int cmpnum(const void * n1, const void * n2) {
	if (*(long *)n1 > *(long *)n2) {
		return 1;
	}
	else if (*(long *)n1 < *(long *)n2) {
		return -1;
	}
	else {
		return 0;
	}
}

int main(void) {

  long n,m;
  scanf("%ld %ld", &n, &m);
  long a[n+1];
  a[0] = 0;
  for (long i = 1; i <= n; i++) {
    scanf("%ld", &a[i]);
    a[i] += a[i-1];
    a[i] %= m;
  }
  qsort(a, n+1, sizeof(long), cmpnum);
  long count = 0, ans = 0;
  for (long i = 0; i <= n; i++) {
    count++;
    if (i == n || a[i] != a[i+1]) {
      ans += count*(count-1)/2;
      count = 0;
    }
  }
  printf("%ld\n", ans);

  return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

ll dp[330][330];

int main() {
    ll n;
    while(cin >> n) {
        if (n == 0) continue;

        vll w(n);
        rep(i, n) cin >> w[i];

        rep(i, n) rep(j, n) dp[i][j] = 0;

        for(ll len = 1; len < n; len++) {
            rep(i, n) {
                ll j = i + len;
                if(j >= n) continue;

                if(dp[i+1][j-1] == len-1 && abs(w[i] - w[j]) <= 1) dp[i][j] = len + 1;
                for(ll k = i; k < j; k++) chmax(dp[i][j], dp[i][k] + dp[k+1][j]);
            }
        }
        cout << dp[0][n-1] << endl;
    }
}



Measured memory_bytes: 3844
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define all(x) x.begin(), x.end()

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef long long ll;

template <typename T> void max_self(T& a, T b){
  a = max(a,b);
}

template <typename T> void min_self(T& a, T b){
  a = min(a,b);
}

void solve(){	
  int w,s;cin>>s>>w;
  if(w>=s)
    cout<<"unsafe\n";
  else
    cout<<"safe\n";
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //int t; cin >> t;
  //while(t--) solve();
  //
  solve();
  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout.setf(ios::fixed);
    cout.precision(10);
    int n;
    cin >> n;
    set<int> as, bs, isec;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        as.insert(a);
    }
    cin >> n;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        bs.insert(a);
    }

    set_symmetric_difference(as.begin(), as.end(), bs.begin(), bs.end(), inserter(isec, isec.end()));
    vi vs;
    for (int i: isec) {
        vs.push_back(i);
    }
    sort(vs.begin(), vs.end());
    for (int v: vs) {
        cout << v << endl;
    }
}


Measured memory_bytes: 44348
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [a, b] = [int(input_raw[0]), int(input_raw[1])]
    if (a > 0):
        print "Positive"
        return

    if (a <= 0 and b >= 0):
        print "Zero"
        return

    if ((b - a + 1) % 2 == 0):
        print "Positive"
    else:
        print "Negative"


if __name__ == '__main__':
    main()

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

int N,M,a,b,startingPoint,visite,ans;
vector<int> adj[100100];
bool visited[100100];

void dfs(int x){
	if(visited[x]) return;
	visited[x] = true;
    visite++;
	for(int i = 0;i < adj[x].size();i++){
		int y = adj[x][i];
		dfs(y);
	}
    if (visite == N) ans++;
	visited[x] = false;
    visite--;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>N>>M;
	for(int i = 1;i <= M;i++){
		cin>>a>>b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	dfs(1);
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6004
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

#define rep(i, n) for(int i=0; i<(n); ++i)
#define max  200001

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int x, a, b;
    
    scanf("%d%d%d", &x, &a, &b);
    
    x-=a;
    
    printf("%d\n", x-(x/b)*b);
    
    return 0;
}



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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

int gcd(int x, int y)
{
	return y ? gcd(y, x % y) : x;
}

void output(int n, int m) {
	cout << setfill('0') << setw(6) << n << setfill('0') << setw(6) << m << "\n";
}

void hawawa()
{
	int n, m;
	cin >> n >> m;
	Vec<Vec<P<int, int>>> v(n);
	Vec<P<int, int>> input;
	for (int i = 0; i < m; i++) {
		int p, y;
		cin >> p >> y;
		p--;
		v[p].push_back(make_pair(y, i + 1));
		input.push_back(make_pair(p, y));
	}
	for (auto&& i : v) {
		sort(begin(i), end(i));
	}
	for (int i = 0; i < m; i++) {
		int p = input[i].first;
		output(p + 1, 1 + lower_bound(v[p].begin(), v[p].end(), make_pair(input[i].second, i + 1)) - v[p].begin());
	}
}

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


Measured memory_bytes: 7796
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    string s;
    cin >> s;
    string t = "AKIHABARA";
    
    rep(i, t.size()){
        if(t[i] == 'A'){
            if(s[i] != 'A'){
                s = s.substr(0, i) + 'A' + s.substr(i);
            }
        }
        else if(s[i] != t[i]){
            cout << "NO" << endl;
            return;
        }
        // cout << i << ": " << s << endl;
    }
    
    if(s == t) cout << "YES" << endl;
    else cout << "NO" << endl;
    return;
}

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 3640
import copy
n, m = map(int, input().split(' '))
db = [[] for _ in range(n)]
a = []
b = []
for i in range(m):
    a_ ,b_ = map(int, input().split(' '))
    db[a_-1].append(b_-1)
    db[b_-1].append(a_-1)
    a.append(a_-1)
    b.append(b_-1)

def dfs(num):
    if checker[num] == 1:
        return 0
    checker[num] = 1
    for k in db_1[num]:
        dfs(k)
    return 0

counter = 0
for i in range(m):
    checker = [0 for _ in range(n)]
    db_1 = copy.deepcopy(db)
    db_1[a[i]].remove(b[i])
    db_1[b[i]].remove(a[i])
    dfs(a[i])
    if all(checker[s] == 1 for s in range(len(checker))):
        continue
    else:
        counter += 1
print(counter)

Measured memory_bytes: 3572
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
	    Scanner s=new Scanner(System.in);
	    long n=s.nextLong();
	    long k=s.nextLong();
	    long a=n/k;
	    if(a*k==n)
	    {}
	    else
	    a++;
	    System.out.println(a);}}
	    

Measured memory_bytes: 22612
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define ALL(a) (a).begin(), (a).end()
string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";

/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}


int main(void){
  ll N, A, B, W, H, D;
  string s, t;
  cin >> s >> t;
  int s_count[26]={0}, t_count[26]={0};
  rep(i, s.length()){
    rep(j, 26){
      if (s[i] == alphabet_lower[j]) s_count[j]++;
    }
  }
  rep(i, t.length()){
    rep(j, 26){
      if (t[i] == alphabet_lower[j]) t_count[j]++;
    }
  }
  string s_ans, t_ans;
  rep(i, 26){
    rep(j, s_count[i]) s_ans+= alphabet_lower[i];
    rep(j, t_count[25-i]) t_ans+=alphabet_lower[25-i];
  }
  if (s_ans< t_ans) cout<<"Yes" << endl;
  else cout <<"No" << endl;

}


Measured memory_bytes: 256
//Moh_K_Imar .......
//29/08/2020  ... 5,08.
//Ya Rab....
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
int main(){
    ld a,b,c;
    cin>>a>>b>>c;
    ld x=a/c;
    if(x<=b)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}



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

int main (){
    int N;
    cin>>N;
    vector<int> A(N);
    for(int i=0; i<N; i++){
        cin>>A.at(i);
    }
    int C=0;
    int Size=N;
    int Num=1;
    while(C<Size){
        if(Num==A.at(C)){
            Num ++;
            C ++;
        }
        else{
            C ++;
        }
    }
  	if(Num>1){
      	cout<<N-(Num-1);
    }
  	else{
      	cout<<-1;
    }
  	
}



Measured memory_bytes: 1024
import sys
input = sys.stdin.readline

x = int(input())
k = int(input())
R = [(_r, i%2) for i, _r in enumerate(map(int, input().split()))]
n = int(input())
TA = [list(map(int, input().split())) for _ in range(n)]
T, A = zip(*TA)
L = [None]*n
b = 0
for i, t in enumerate(T, 1):
  R.append((t, -i))
R.sort()
dx = 1
l, r, p, q = 0, x, 0, x
for _r, i in R:
  d = _r-b
  b = _r
  if dx == 1:
    if d <= p:
      p -= d
      q -= d
    elif d < q:
      q -= d
      l = r-q
      p = 0
    else:
      l = 0
      r = 0
      p = 0
      q = 0
  else:
    if d <= x-q:
      p += d
      q += d
    elif d < x-p:
      p += d
      r = l+(x-p)
      q = x
    else:
      l = x
      r = x
      p = x
      q = x
  if i >= 0:
    dx = i
  else:
    a = A[-i-1]
    if a < l:
      res = p
    elif a <= r:
      res = (a-l)+p
    else:
      res = q
    L[-i-1] = res
print(*L, sep="\n")

Measured memory_bytes: 57212
#include<stdio.h>

int main(void){
  int t[4][13];
  int n,i,j,f;
  char c;
 

  for(i=0;i<4;i++){
    for(j=0;j<13;j++){
      t[i][j]=0;
    }
  }
 scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %c %d",&c,&f);
    if(c=='S'){
      t[0][f-1]=1;
    } else if(c=='H'){
      t[1][f-1]=1;
    } else if(c=='C'){
      t[2][f-1]=1;
      } else if(c=='D'){
      t[3][f-1]=1;
      }
  }
  

  for(i=0;i<4;i++){
    for(j=0;j<13;j++){
      if(t[i][j]==0){
	if(i==0){
	  printf("S %d\n",j+1);
	}
	else if(i==1){
	  printf("H %d\n",j+1);
	}
	else if(i==2){
	  printf("C %d\n",j+1);
	}
	else{
	  printf("D %d\n",j+1);
	}
      }
    }
  }

  return 0;
}

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

#define	MOD 1000000007;
#define PI 3.14159265358979323846;
#define rep(i,n) for(int i = 0;i<(int)n;i++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;
static const long long INFTY = (1LL << 32);
int main()
{
	ll X, Y;
	cin >> X >> Y;

	int count = 0;
	ll i = X;
	while (true) {
		if (i <= Y) {
			count++;
		}
		else {
			break;
		}
		i *= 2;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#define ll long long
#define out(a) printf("%d ",a)
#define writeln printf("\n")
const int N=1e5+50;
const int mod=1e9+7;
using namespace std;
int a,b,c,x,y,z;
int read()
{
	int s=0,t=1; char c;
	while (c<'0'||c>'9'){if (c=='-') t=-1; c=getchar();}
	while (c>='0'&&c<='9'){s=s*10+c-'0'; c=getchar();}
	return s*t;
}
ll readl()
{
	ll s=0,t=1; char c;
	while (c<'0'||c>'9'){if (c=='-') t=-1; c=getchar();}
	while (c>='0'&&c<='9'){s=s*10+c-'0'; c=getchar();}
	return s*t;
}
int main()
{
	a=read(),b=read(),c=read();
    x=abs(a-b); y=abs(b-c); z=abs(a-c);
    if (x>=y&&x>=z) out(y+z);
    else if (y>=x&&y>=z) out(x+z);
    else if (z>=x&&z>=y) out(x+y);
  return 0;
}
	

Measured memory_bytes: 256
A = list(map(int, input().split()))
ans = 0

while sum([A[i] % 2 for i in range(3)]) == 0:
    if A.count(A[0]) == 3:
        ans = -1
        break
    A = [(sum(A)-A[i])/2 for i in range(3)]
    ans += 1

print(ans)

Measured memory_bytes: 9216
import math

def Eratos(n):
	primes = [2]
	num = [2*i+1 for i in range(1,n//2)]
	tmp = []

	top = 1
	while top < math.sqrt(n):
		top = num[0]
		for i in range(1,len(num)):
			if num[i] % top != 0:
				tmp.append(num[i])
		num = tmp
		tmp = []
		primes.append(top)
	for i in range(len(num)):
		primes.append(num[i])
	return primes

n = int(input())
cont = 0
primes = Eratos(20000)
for i in range(n):
	a = int(input())
	if a<10000:
		if primes.count(a)!=0:
			cont += 1
	else:
		for j in range(len(primes)):
			if a%primes[j]==0:
				break
			else:
				if math.sqrt(a)<primes[j]:
					cont += 1
					break
print(cont)


Measured memory_bytes: 6120
A, B, M = map(int, input().split())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
mi = min(A) + min(B)
for _ in range(M):
    x, y, c = map(int, input().split())
    mi = min(mi, A[x-1] + B[y-1] - c)
print(mi)

Measured memory_bytes: 70636
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
signed main(){
  int h,w,y,x;
  cin >> h >> w >> x >> y;
  int ans = h*w;
  ans -= x*w+(h-x)*y;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int N,i,j,x=4,y=7,a=0,flag=0;
	scanf("%d",&N);
	for(i = 1; i < 101; i++){
		for(j = 1; j < 101; j++){
			a= (x * i) + (y * j);
			
			if(N % 4 == 0){
				flag = 1;
			}
			else if(N % 7 == 0){
				flag = 1;
			}
			else if(N % a == 0){
				flag = 1;
			}
			else{
			}
		}
	}
	flag ? printf("Yes\n") : printf("No\n");
	return 0;
}

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

int main() {
    long big = 1e9+7;
    int N;
    long W;
    int V = 0;
    cin>>N>>W;
    long w[N];
    int v[N];
    for(int i=0;i<N;++i){
        cin>>w[i]>>v[i];
        V+=v[i];
    }
    long DP[N][V+1];
    for(int i=0;i<N;++i){
        DP[i][0] = 0;
    }
    for(int i=1;i<=V;++i){
        if(i <= v[0]){
            DP[0][i] = w[0];
        }
        else DP[0][i] = big;
    }

    for(int i=1;i<=V;++i){
        for(int j=1;j<N;++j){
            if(i>=v[j]){
                DP[j][i] = min(DP[j-1][i], DP[j-1][i-v[j]] + w[j]);
            }
            else DP[j][i] = DP[j-1][i];
        }
    }
    /**
    for(int i=0;i<N;++i){
        for(int j=0;j<=V;++j){
            cout<<DP[i][j]<<" ";
        }
        cout<<endl;
    }
    cout<<endl;
    **/
    int ans;
    bool aru;
    for(int i=0;i<=V;++i){
        aru = false;
        for(int j=0;j<N;++j){
            if(DP[j][i] <= W)aru = true;
        }
        if(aru){
            ans = i;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 78336
import math

def main():
    a, b, h, m = map(int, input().split())
    mr = 6*m
    hr = 30*h+mr/12
    angle = math.radians(abs(mr-hr))
    ans = (a**2+b**2-2*a*b*math.cos(angle))**0.5
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 62608
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Yagnik
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CTaxIncrease solver = new CTaxIncrease();
        solver.solve(1, in, out);
        out.close();
    }

    static class CTaxIncrease {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            int a = s.nextInt(), b = s.nextInt(), MX = (int) 1e6 + 10;
            for (int i = 0; i <= MX; i++) {
                if (Math.floor(i * 0.08) == a && Math.floor(i * 0.1) == b) {
                    w.println(i);
                    return;
                }
            }
            w.println(-1);
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



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

using namespace std;

#define ll long long
#define rep(i,n) for(int i=1;i<=(n);i++)
#define rep0(i,n) for(int i=0;i<(n);i++)

const ll INF=1e9+7;
int n,t,k=1;
int a[100001],b[100000];
int main()
{
	/*freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);*/
	cin>>n>>t;
	rep(i,n){
		cin>>a[i];
	}
	for(int i=n-1;i>=1;i--){
		if(a[i+1]>a[n]){
			swap(a[i+1],a[n]);
		}
		b[i]=a[n]-a[i];
	}
	sort(b+1,b+n);
	while(b[n-k]==b[n-k-1]&&n-k-1>=1){
		k++;
	} 
	cout<<k;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int llint
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define PI 3.1415926535897
#define EPS (1e-10)
#define INF INT_MAX
#define INFLL LLONG_MAX
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using MCI = std::map<char, int>;
using VPII = std::vector<PII>;
using namespace std;


int N;
int A[100010];
int B[100010];


int solve(){
	if(accumulate(RNG(A, 0, N), 0LL) < accumulate(RNG(B, 0, N), 0LL)) return -1;
	int ans = 0;
	int sum = 0;
	VI v;
	rep(i, 0, N)
		if(A[i] < B[i]) ans++, sum += (B[i]-A[i]);
		else if(A[i] > B[i]) v.pb(A[i]-B[i]);
	if(ans == 0) return 0;
	sort(ALL(v), greater<int>());
	int sum2 = 0;
	for(int x : v){
		sum2 += x, ans++;
		if(sum <= sum2) break;
	}
	return ans;
}


signed main(){
	cin >> N;
	rep(i, 0, N) cin >> A[i];
	rep(i, 0, N) cin >> B[i];

	cout << solve() << endl;

	return 0;
}

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

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

    if(a-1>n-b)
    {
        if((b-a)%2==0) cout<<"Alice\n";
        else cout<<"Borys\n";
    }

    if(a-1<n-b)
    {
        if((b-a)%2==0) cout<<"Alice\n";
        else cout<<"Borys\n";
    }
    //cout<<"Alice\n";
    if(a-1==n-b)
    {
        if((b-a)%2==0) cout<<"Alice\n";
        else cout<<"Borys\n";
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if (a+b == c+d) {
    cout << "Balanced" << endl;
  }
  else if (a+b < c+d){
    cout << "Right" << endl;
  }
  else {
    cout << "Left" << endl;
  }
}

Measured memory_bytes: 256
import math
n = int(input())

root = math.sqrt(n)
x = str(int(root // 1))
answer = 0

for i in reversed(range(1, int(x) + 1)):
    if n % i == 0:
        answer = i
        break
answer_2 = int(n / answer)

if len(str(answer)) >= len(str(answer_2)):
    print(len(str(answer)))
else:
    print(len(str(answer_2)))

Measured memory_bytes: 9252
#pragma comment(linker, "/STACK:102400000,102400000")
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <cassert>

//#include <unordered_map>
//#include <unordered_set>
using namespace std;

typedef long long ll;
#define eps 1e-8
#define LL_INF 0x3fffffffffffffff
#define INF 1LL<<30
#define mem(a, b) memset(a, b, sizeof(a))
#define pper(i,n,m) for(int i = n;i >= m; i--)
#define repp(i, n, m) for (int i = n; i <= m; i++)
#define rep(i, n, m) for (int i = n; i < m; i++)
#define sa(n) scanf("%d", &(n))
#define slla(n) scanf("%lld", &(n))
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define DE(val) cout<<#val<<": "<<val<<endl;

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

const int dx8[9] = { 0,-1,0,1,0,1,1,-1,-1 };
const int dy8[9] = { 0,0,1,0,-1,1,-1,1,-1 };
const int maxn = 2e5 + 50;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
ll po(ll a, ll b, ll mod) { ll res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
ll gcd(ll a, ll b) { if (a == 0) { return b; } else { return gcd(b%a, a); } }
void YES() { puts("YES"); exit(0); }
void Yes() { puts("Yes"); exit(0); }
void NO() { puts("NO"); exit(0); }
void No() { puts("No"); exit(0); }
void one() { puts("-1"); exit(0); }

int n;
char val[maxn];
int num[maxn];


bool check(int x)
{
	int cnt = 0;
	memset(num, 0, sizeof(num));
	int end = -1;
	int st = -1;
	repp(i, 1, n)
	{
		if (val[i] == '1')
		{
			st = i;
			end = i + x - 1;
			break;
		}
	}
	if (end == -1)
	{
		return true;
	}
	repp(i, st, end)
	{
		int now = val[i] - '0';
		int op = now ^ (cnt & 1);
		if (op)
		{
			if (i + x - 1>n)
				return false;
			cnt++;
		}
	}
	return true;
}

bool check2(int x)
{
	int cnt = 0;
	memset(num, 0, sizeof(num));
	int end = -1;
	int st = -1;
	repp(i, 1, n)
	{
		if (val[i] == '0')
		{
			st = i;
			end = i + x - 1;
			break;
		}
	}
	if (end == -1)
	{
		return true;
	}
	repp(i, st, end)
	{
		int now = '1' - val[i];
		int op = now ^ (cnt & 1);
		if (op)
		{
			if (i + x - 1>n)
				return false;
			cnt++;
		}
	}
	return true;
}
void solve()
{
	scanf("%s", val + 1);
	n = strlen(val + 1);
	int le = 1;
	int ri = n;
	while (le<ri)
	{
		int mid = (le + ri + 1) / 2;
		if (check(mid) || check2(mid))
		{
			le = mid;
		}
		else
		{
			ri = mid - 1;
		}
	}
	cout << le;
}


int main()
{

	solve();
	// system("pause");
	return 0;
}


Measured memory_bytes: 1152
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000

using vi = vector<int>;


int main() {

	int A, B, C;

	cin >> A >> B >> C;

	if (B / A > C) {
		cout << C << endl;
	}
	else {
		cout << B/A << endl;
	}

	return 0;
}

Measured memory_bytes: 256
from operator import mul
from functools import reduce
 
def cmb(n,r):
    r = min(n-r,r)
    if r==0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
  

from collections import defaultdict
dic = defaultdict(int)
N = int(input())
for n in range(N):
  s = list(input())
  s.sort()
  k = tuple(s)
  dic[k] += 1
ans = 0
for k in dic.keys():
  if dic[k]<2:
    continue
  ans += cmb(dic[k],2)
print(ans)


Measured memory_bytes: 24152
#include<iostream>
#include<algorithm>
#include <stdio.h>
#include <time.h>
#include <queue>
using namespace std;
int GG(int n){
    int c=1;
    while(c<=n)
        c*=2;
    return c/2;
}
int main(){
    int n;
    cin>>n;
   cout<< GG(n);

    return 0;
}



Measured memory_bytes: 256
pub struct Scanner{
    line : Vec<String> ,
    idx : usize
}

impl  Scanner{
   #[allow(dead_code)]
   fn new() -> Scanner{
       return Scanner{ line: vec![], idx : 0}
   }
   #[allow(dead_code)]
   fn next<T: std::str::FromStr> (&mut self) -> T{
       if self.idx == self.line.len() {
           let mut buffer = String::new();
           std::io::stdin().read_line(&mut buffer).ok();

           let a : Vec<&str>  = buffer.trim().split(' ').collect();
           self.line = a.iter().map(|&s| String::from(s)).collect();
           self.idx = 0;
       }
       let ret : T = self.line[self.idx].parse::<T>().ok().expect("Parse error.");
       self.idx += 1;
       ret
   }
   #[allow(dead_code)]
   fn read_vec<T: std::str::FromStr>  (&mut self, n: usize) -> Vec<T>{
       let mut v : Vec<T>= Vec::with_capacity(n);
       for _i in 0..n {
           v.push(self.next());
       }
       v
   }
}


fn main() {
    let mut scan = Scanner::new();
    let x:i32  = scan.next();
    
    println!("{}", x/500*1000 + x%500/5*5);
}

Measured memory_bytes: 4352