akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>

using namespace std;


int main() {
    
    long n;
    long q;
    cin >> n;
    vector <long> s;
    vector <long> t;
    for (int i=0;i<n;i++){
        long p;
        cin >> p;
        s.push_back(p);
    }
    cin >> q;
    for(int i=0;i<q;i++){
        long p;
        cin >> p;
        t.push_back(p);
    }
    vector <long>::iterator idx;
    long ans = 0;
    for (int i=0;i<q;i++) {
        idx = lower_bound(s.begin(), s.end(),t[i]);
        if(*idx == t[i]){
            ans += 1;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4380
import sys

input = sys.stdin.readline

N = int(input())
A = list(map(int,input().split()))
A = A[:N]
B = list(map(int,input().split()))
B = B[:N]
C = list(map(int,input().split()))
C = C[:N]

A.sort()
B.sort()
C.sort()

ans = 0

#B_iを選んだ時にAの選び方は何通り？
BB = [0] * N
a = 0
for b in range(N):
    while A[a] < B[b] and a <= N-2:
        a += 1
    if a == N-1 and A[a] < B[b]:
        BB[b] = N
    else:
        BB[b] = a
#print(BB)

Bsum = [0] * N
Bsum[0] = BB[0]
for bb in range(1,N):
    Bsum[bb] = Bsum[bb-1] + BB[bb]
#print(Bsum)

ans = 0
b_ = 0
for c in range(N):
    while B[b_] < C[c] and b_ <= N-2:
        b_ += 1
    if b_ == N-1 and B[b_] < C[c]:
        b_ += 1
    b_ -= 1
    if b_ == -1:
        b_ = 0
        continue
    #print(b_)
    ans += Bsum[b_]

print(ans)

Measured memory_bytes: 23188
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll bg=1234567890123;
#define ff(i,n) for(i=0;i<n;i++)
#define gg1(n1) cin>>n1;
#define gg(n1,n2) cin>>n1>>n2;
#define gg3(n1,n2,n3) cin>>n1>>n2>>n3;
#define hh(n) cout<<n<<endl;
#define t top
#define p push
#define pb push_back
#define mp make_pair
ll dp[100][100000];
int main()
{
  ll n,w1,i,j;
  cin>>n>>w1;
  ll v[n],w[n];
  for(i=0;i<n;i++)
    cin>>w[i]>>v[i];
  for(i=0;i<n;i++)
     for(j=0;j<=w1;j++)
        dp[i][j]=-1;
  dp[0][0]=0;
  dp[0][w[0]]=v[0];
  for(i=0;i<n-1;i++)
  {
       for(j=0;j<=w1;j++)
       {
            if(dp[i][j]!=-1)
            {
                 dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
                 if(j+w[i+1]<=w1)
                 {
                      dp[i+1][j+w[i+1]]=max(dp[i+1][j],dp[i][j]+v[i+1]);
                 }
            }
       }
  }
  ll maxi=0;
  for(i=0;i<=w1;i++)
    maxi=max(maxi,dp[n-1][i]);
  cout<<maxi<<endl;  
  return 0;
}

Measured memory_bytes: 78336
#from collections import deque

def bfs(maze, sy, sx):
    gy, gx = H - 1, W - 1
    q = [[sy, sx]]
    visited[sy][sx] = 1
    #print(sy, sx, gy, gx)
    now = 0
    while q:
      y, x = q.pop(0)
      if (y, x) == (gy, gx):
        return visited[y][x]
      for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
        new_y, new_x = y + j, x + k #改行して条件文を続けるときにバックスラッシュ
        if (0 <= new_y <= H - 1) and (0 <= new_x <= W - 1):
          if maze[new_y][new_x] == "." and visited[new_y][new_x] > 10 ** 5:#まだ来たことない点だったという条件
            visited[new_y][new_x] = visited[y][x] + 1
            q.append([new_y, new_x])
    return 0

          
if __name__ == "__main__":
    H, W = map(int, input().split())
    maze = [[0] * W for i in range(H)]
    count = 0
    for i in range(H):
      s = str(input())
      for j in range(W):
        maze[i][j] = s[j]
        if s[j] == ".":
          count += 1
    visited = [[float("inf")] * W for j in range(H)]
    ans = bfs(maze, 0, 0)
    if ans == 0:
      print(-1)
    else:
      print(count - ans)


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main()
{
    const unsigned long long CONSTANT = 2019;
    unsigned long long l,r;
    unsigned long long min = CONSTANT - 1;

    cin >> l >> r;
    
    for(long long i=l; i<=r-1; i++){
        for(long long j=i+1; j<=r; j++){
            if(min > ((i*j)%CONSTANT)) {
                min =(i*j)%CONSTANT;
                if(min == 0){
                    cout << 0 << endl;
                    return 0;
                }
            }
        }
    }

    cout << min << endl;
}

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

using namespace std;

int main() {
	int b;
	string str;
	stringstream ss;

	str = "";
	for (int i = 0; i < 3; ++i) {
		cin >> b;
		ss << b;
	}
	ss >> str;
	//cout << str << endl;
	if (str == "110" || str == "001") {
		cout << "Open" << endl;
	}
	else {
		cout << "Close" << endl;
	}

	return 0;
}



Measured memory_bytes: 3216
N = int(input())
S = list()
for i in range(N):
    S.append(input())

judge = ['AC', 'WA', 'TLE', 'RE']
count = [0] * 4

for i in range(N):
    letter = S[i]
    ind = judge.index(letter)
    count[ind] += 1

for i in range(len(judge)):
    print(judge[i], "x", str(count[i]))


Measured memory_bytes: 16248
n=int(input())

class UnionFind():
    def __init__(self,num):
        self.n = num         #class内変数nに、外部から入力した値numを代入
        self.parents = [-1 for i in range(self.n)]
          #parentsは要素の親(1こ上のやつ)番号0~n-1を格納、自分が最親なら-(要素数)を格納(初期値は-1)

    #xの最親は誰？
    def find(self,x):
        if self.parents[x]<0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x]) #再帰して1番上までいってる
                #調べながらparentsの値を更新してる！（経路圧縮）
            return self.parents[x]

    #結合せよ
    #xの親とyの親をくっつける
    def union(self,x,y):
        xx=self.find(x)  #xxはxの最親
        yy=self.find(y)  #yyはyの最親
        if xx==yy:
            return     #同じ屋根の下にあった場合は何もしない
        else:
            size_xx=abs(self.parents[xx]) #xが含まれる木のサイズ
            size_yy=abs(self.parents[yy]) #yが含まれる木のサイズ
            if size_xx>size_yy:
                xx,yy=yy,xx  #yyの方が大きい木、ってことにする

            self.parents[yy]+=self.parents[xx] #大きい木のサイズ更新
            self.parents[xx]=yy   #サイズが小さい木を大きい木に接ぐ

    #xの属する木の大きさ（まあunionでも使ったけど）
    def size(self,x):
        xx=self.find(x)
        return abs(self.parents[xx])

    #xとyはこの空の続く場所にいますか　いつものように笑顔でいてくれますか　今はただそれを願い続ける
    def same(self,x,y):
        return 1 if self.find(x)==self.find(y) else 0

    #xと　同じ木にいる　メンバーは？
    def members(self,x):
        xx=self.find(x)
        return [i for i in range(self.n) if self.find(i)==xx]
             #ifの条件式に漏れたら無視

    #最親だけを並べあげる
    def roots(self):
        return [i for i,x in enumerate(self.parents) if x < -1]
        #いやこれは天才すぎる、basisのenumerate.py参照

    #すべての最親について、メンバーを辞書で
    def all_group_members(self):
        return {r:self.members(r) for r in self.roots()}

    #グループ分けどうなりましたか、２重リストで
    def state_grouping(self):
        return list(self.all_group_members().values())

    #出力用
    def __str__(self):
        return "\n".join("{}: {}".format(r,self.members(r)) for r in self.roots())
        #"\n"はただの改行コード
        #str(辞書)を改行しながら表示する
        #print(インスタンス)で__str__に飛ぶ
        #出力過程で、membersで全要素にfindをしてる→逐一経路圧縮されてる！

uf=UnionFind(2*10**5)
ans=0
#uf.union(0,1)
#print(uf.parents)
for i in range(n):
    x,y=map(int,input().split())
    x-=1;y-=1;y+=10**5
    uf.union(x,y)
for p in uf.roots():
    l=uf.members(p) #メンバーズ
    tem= len([i for i in l if i>=10**5])
    ans+= (len(l)-tem)*tem
    #print(l , tem)
print(ans-n)
# 

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

int main(){
  int A, B;
  cin >> A >> B;
  int count = 0;
  for(; A <= B; A++){
    int up, down, down1, down2;
    up = A / 1000;
    down = A % 100;
    down1 = down / 10;
    down2 = down % 10;
    down = 10 * down2 + down1;
    if(up == down){
      count += 1;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3616
s = input()
slen = len(s)

kotae = 0
for i in range(2**(slen-1)):
    si = s
    for j in range(slen-1):
        if i & 1<<j:
            si = si[:slen-j-1]+"+"+si[slen-j-1:]
        else:
            pass
    kotae += eval(si)

print(kotae)

Measured memory_bytes: 3060
def examA():
    def calc_L(x1,y1,x2,y2):
        return ((x2-x1)**2 + (y2-y1)**2)**0.5
    N = I()
    X = [LI()for _ in range(N)]
    ans = 0
    for x in itertools.permutations(X):
        cur = 0
        for i in range(1,N):
            cur += calc_L(x[i-1][0],x[i-1][1],x[i][0],x[i][1])
        #print(x,cur)
        ans += cur
    for i in range(1,N+1):
        ans /= i
    print(ans)
    return

def examB():
    def judge(n):
        sn = 0
        for i in n:
            sn += int(i)
        if int(n)%sn==0:
            return "Yes"
        return "No"
    N = SI()
    ans = judge(N)
    print(ans)
    return

def examC():
    N, K = LI()
    P = LI()
    ans = 0
    S = [0]*(N+1)
    for i in range(N):
        S[i+1] = S[i]+(P[i]+1)/2
    for i in range(N-K+1):
        cur = S[i+K] - S[i]
        if cur>ans:
            ans = cur
    print(ans)
    return

def examD():
    def bfs(n,V,s,W):
        visited = [False]*n
        que = deque()
        que.append(s)
        while(que):
            now = que.pop()
            visited[now] = True
            for ne in V[now]:
                if visited[ne]:
                    continue
                W[ne] += W[now]
                que.append(ne)
        return W
    N, Q = LI()
    V = [[]for _ in range(N)]
    for _ in range(N-1):
        a, b = LI()
        a -= 1; b -= 1
        V[a].append(b)
        V[b].append(a)
    W = [0] * N
    for _ in range(Q):
        p, x = LI()
        W[p-1] += x
    ans = bfs(N,V,0,W)
    print(" ".join(map(str,ans)))
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examD()

"""

"""

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

using namespace std;

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

    int N, K, Q;
    cin >> N >> K >> Q;
    vector<int> A(N, K - Q);
    for (int i = 0; i < Q; ++i) {
        int a_i;
        cin >> a_i;
        ++A[a_i - 1];
    }
    for (int a_i : A) {
        if (a_i <= 0) cout << "No" << '\n';
        else cout << "Yes" << '\n';
    }
}

Measured memory_bytes: 1024
//M-SOLUTIONS 2020_B
#include <stdio.h>
int main(){
	int a,b,c;
	int k;
	scanf("%d %d %d",&a,&b,&c);
	scanf("%d",&k);
	
	for(int i=0;i<k;i++){
		//bが小さければまずbの数値を大きくする
		if(a>=b){
			b = b * 2;
//			printf("b =%d \n",b);
		}
		//cが小さければcの数値を大きくする
		else if(b>=c){
			c = c * 2;
//			printf("c =%d \n",c);
		}
	}
	
	if(a<b && b<c)	printf("Yes");
	else printf("No");
	
	return 0;
}


Measured memory_bytes: 1736
require 'matrix'

SIN60 = Math.sin(-60.0 / 180.0 * Math::PI)
COS60 = Math.cos(-60.0 / 180.0 * Math::PI)
ROTATE = Matrix[[COS60, SIN60], [-SIN60, COS60]]

def koch(n, st, ed)
  return [ed] if n == 0
  e = (ed - st) / 3
  s = st + e
  u = s + ROTATE * e
  t = s + e
  return [
    koch(n - 1, st, s),
    koch(n - 1, s, u),
    koch(n - 1, u, t),
    koch(n - 1, t, ed)
  ].flatten
end

puts "%.6f %.6f" % Vector[0.0, 0.0].to_a
koch(gets.to_i, Vector[0.0, 0.0], Vector[100.0, 0.0]).each do |p|
  puts "%.6f %.6f" %  p.to_a
end


Measured memory_bytes: 7272
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <cstdio>
#define rep(i, j) for(int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
using namespace std;
int main()
{
	int e; while (cin >> e , e)
	{
		int m = 214214, x = 0;
		rep(z, 101) rep(y, 1001)
		{
			x = e - (y * y + z * z * z);
			if (e == x + (y * y) + (z * z * z) && x >= 0 ) 
			{ m = min(x + y + z, m); }
		}
		printf("%d\n", m);
	}
	return 0;
}

Measured memory_bytes: 3116
import collections,sys
input=sys.stdin.readline
n=int(input())
l=list(map(int,input().split()))

c = collections.Counter(l)
q=int(input())
ans=0
for x in c:
  ans+=x*c[x]
for _ in range(q):
  a,b=map(int,input().split())
  if not a in c:
    print(ans)
  elif c[a]==0:
    print(ans)
  else:
    if b in c:
      c[b]+=c[a]
    else:
      c[b]=c[a]
    ans+=(b*c[a]-a*c[a])
    print(ans)
    c[a]=0



Measured memory_bytes: 86292
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vll2 = vector<vector<ll>>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w, n;
    cin >> h >> w >> n;
    cout << n / max(h, w) + (n % (max(h, w)) > 0) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define MOD 2019
#define M(x) ((x+MOD)%MOD)
#define MAX 100010

ll a[MAX], x[MAX], n;

int main()
{
	cin >> n;
	x[n] = 0;
	for (int i = 1;i <= n;++i)
	{
		cin >> a[i];
		if(i!=n) x[n] += a[i] * (i % 2 ? -1 : 1);
	}
	x[n] += a[n];
	x[1] = 2 * a[n] - x[n];
	for (int i = 2;i < n;++i)
		x[i] = 2 * a[i - 1] - x[i - 1];
	for (int i = 1;i <= n;++i)
		cout << x[i] << " ";
	//system("pause");
	return 0;
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(ll i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(ll i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n,m,x;
    cin>>n>>m>>x;
    set<int> se;
    REP(i,m){
        int t;
        cin>>t;
        se.insert(t);
    }
    int a=0;
    REP(i,x){
        if(se.count(i)){
            a++;
        }
    }
    int b=0;
    FOR(i,x,n+1){
        if(se.count(i)){
            b++;
        }
    }
    cout<<min(a,b)<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long sum = 0;
		long a[] = new long[N];
		long b[] = new long[N];
		for (int i = 0; i < N; i++) {
			a[i] = sc.nextLong();
			b[i] = sc.nextLong();
		}
		for (int i = N-1; i >=0; i--) {
			if ((a[i]+sum)%b[i]!=0) {
				long temp = (a[i]+sum)/b[i]+1;
				temp = temp *b[i]-(a[i]+sum);
				sum +=temp;
			}
		}
		System.out.println(sum);
	}
}

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

using namespace std;

#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define INF 1000000000
#define INFL 10000000000000000LL
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main(){
  string s;
  cin >> s;
  if(s.size()!=26){
    bool c[26] = { };
    REP(i, s.size()){
      c[s[i]-'a'] = true;
    }
    int ms = 29;
    REP(i, 26){
      if(!c[i]) ms = min(ms, (int)i);
    }
    s += ('a' + ms);
    cout << s << endl;
  }
  else{
    int k = 25;
    while(s[k] < s[k-1]) k--;
    k--;
    if(k == -1){
      cout << -1 << endl;
      return 0;
    }
    string t = s.substr(0, k);
    bool c[26] = { };
    REP(i, k){
      c[t[i]-'a'] = true;
    }
    int ms = 29;
    REP(i, 26){
      if(!c[i] && i > (s[k] - 'a')) ms = min(ms, (int)i);
    }
    t += ('a' + ms);
    cout << t << endl;
  }
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define all(ppp) ppp.begin(),ppp.end() 

#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 pb push_back

typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<string> vs;

int main(){
    int N;
    cin>>N;
    vs S(N);
    F0R(i,N){
        cin>>S[i];
    }
    map<string,int> mp;
    F0R(i,N){
        mp[S[i]]++;
    }
    int maxi=0;
    for(auto it=mp.begin();it!=mp.end();it++){
        int tmp=(*it).second;
        if(tmp>maxi){
            maxi=tmp;
        }
    }
    for(auto it=mp.begin();it!=mp.end();it++){
        int tmp=(*it).second;
        if(tmp==maxi){
            cout<<(*it).first<<endl;
        }
    }

    return 0;
}


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

int n, x[104];

int cal(int pos){
	int ret = 0;
	for(int i = 0; i < n; i++)	ret += (x[i]-pos)*(x[i] - pos);
	return ret;
}
int main() {
	cin>>n;
	int ans = 987654321;
	for(int i = 0; i < n; i++)	cin>>x[i];
	for(int i = 1; i<= 100; i++)	ans = min(ans, cal(i));
	cout<<ans;
	return 0;
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

ll fact(ll n) {
    if (n == 1) {
        return 1;
    } else {
        return (n * fact(n - 1)) % MOD;
    }
}

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N, M;
    cin >> N >> M;

    ll ans = 0;
    if (abs(N-M) == 0) {
        ans = fact(N)*fact(M)*2;
        ans %= MOD;
    } else if (abs(N-M) == 1) {
        ans = fact(N)*fact(M);
        ans %= MOD;
    }

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

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

using namespace std;

const int N = 2 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

long long r, d, x;

bool read() {
    if (!(cin >> r >> d >> x))
        return false;

    return true;
}

void solve() {
    for (int i = 0; i < 10; ++i) {
        x = r * x - d;
        cout << x << endl;
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();

    return 0;
}



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

using namespace std;

int main() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;

    int ans = 0;

    if (A >= K) {
        ans = K;
    }else if(A < K && K <= A + B){
        ans = A;
    }else{
        ans = A - (K - A - B);
    }

    cout << ans << endl;
}



Measured memory_bytes: 3620
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

int mod = 1000000007;
void solve() {
  int n, k;
  scan(n, k);
  vi a(n+1);
  iota(begin(a), end(a), 0);
  vll acc(n+2, 0);
  rep (i, n+1) {
    acc[i+1] = acc[i] + a[i];
  }
  ll ans = 0;
  FOR (i, k, n+2) {
    ll mi = acc[i] - acc[0];
    ll ma = acc[n+1] - acc[n+1-i];
    ans = (ans + ma - mi + 1) % mod;
  }
  print(ans);
}

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


Measured memory_bytes: 5244
package main

import (
	"fmt"
	"strings"
)

func main() {
	// Code for A - CF
	var s string
	fmt.Scan(&s)

	C := strings.Index(s, "C")
	F := strings.LastIndex(s, "F")

	if C != -1 && F != -1 && C < F {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

int main(void){
    int n;
    cin>>n;
    vector<int> v(n);
    rep(i, n){
        cin>>v[i];
    }
    
    int ans=0;

    rep(i, n){
        for (int j=i+1;j<n;j++){
            ans+=v[i]*v[j];
        }
    }

    cout<<ans<<endl;
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int n, a[101];
bool b;
i64 mod_pow(i64 x, i64 y, i64 mod){
	i64 res = 1;
	while(y > 0){
		if(y & 1) res = res * x % mod;
		x = x*x %mod;
		y >>= 1;
	}
	return res;
}
void solve(){
	cin >> n >> b;
	int cnt = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		cnt += a[i]%2;
	}
	
	if(cnt){
		cout << mod_pow(2,n-1,LINF) << endl;
	}
	else{
		if(b) cout << 0 << endl;
		else cout << mod_pow(2,n,LINF) << endl;
	}
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


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

#define ll long long int
#define LD long double

const int N = 100010;

int inf = 1e9;
int mod = 1e9 + 7;

signed main()
{
    //freopen("IN.txt", "r", stdin);
    //freopen("OUT.txt", "w", stdout);

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

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

    multiset <int> s;
    deque<int> d;

    for(int i = 0; i < k; i++) {
        while((int)d.size() && d.back() > A[i]) {
            d.pop_back();
        }
        s.insert(A[i]);
        d.push_back(A[i]);
    }

    int ans = 0;
    int cnt = 0;

    for(int i = 0; i <= n - k; i++) {
        int mini = *(s.begin());
        int maxi = *(s.rbegin());
        if((int)d.size() == k) {
            cnt++;
        }
        if(A[i] == mini) {
            if(i + k < n && A[i + k] > maxi) {
                s.erase(s.find(mini));
                s.insert(A[i + k]);
                if(A[i] == d.front()) {
                    d.pop_front();
                }
                while((int)d.size() && d.back() > A[i + k]) {
                    d.pop_back();
                }
                d.push_back(A[i + k]);
                continue;
            }
        }
        if((int)d.size() < k) {
            ans++;
        }
        s.erase(s.find(A[i]));
        if(i + k < n) {
            s.insert(A[i + k]);
        }
        if(A[i] == d.front()) {
            d.pop_front();
        }
        while((int)d.size() && d.back() > A[i + k]) {
            d.pop_back();
        }
        d.push_back(A[i + k]);
    }

    if(cnt) {
        ans++;
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 11264
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <deque>

int main(){
  int N;
  scanf("%d", &N);
  std::vector<int > A(N);
  for (int i=0; i<N; i++){
    scanf("%d", &A[i]);
    A[i]-=(i+1);
  }
  std::sort(A.begin(), A.end());
  int center = N/2;
  long long sum = 0;
  for (int i=0; i<N; i++){
    sum += abs(A[i]-A[center]);
  }
  printf("%lld\n", sum);
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int maxn = 3e5;
int vis[maxn],a[maxn],num[maxn];

int main()
{
	memset(vis,-1,sizeof(vis));
	long long n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a[i];
	num[0]=1;
	vis[1]=0;
	int cnt=0;
	int start,ends;
	while(true)
	{
		cnt++;
		if(vis[a[num[cnt-1]]]==-1) 
		{
			num[cnt]=a[num[cnt-1]];
			vis[num[cnt]]=cnt;
		}
		else
		{
			start=vis[a[num[cnt-1]]];
			ends=cnt-1;
			break;
		}
	}
	if(k<start)
	{
		cout<<num[k]<<endl;
	}
	else
	{
		k-=start;
		int t=ends-start+1;
		cout<<num[start+k%t]<<endl;
	}
	return 0;
} 

Measured memory_bytes: 6212
#include <iostream>
using namespace std;
int taka=0,ao=0,sun=0,counter=0;
int takab=0,aob=0,sunb=0;
int takac=0,aoc=0,sunc=0;
int takacopy=0,aocopy=0,suncopy=0;

int takaq(){
    takac=taka/2;
    aocopy+=takac;
    suncopy+=takac;
    return 0;
}


int aoq(){
    aoc=ao/2;
    takacopy+=aoc;
    suncopy+=aoc;
    return 0;
}

int sunq(){
    sunc=sun/2;
    takacopy+=sunc;
    aocopy+=sunc;
    return 0;
}

int main(){
    
    cin>>taka;
    cin>>ao;
    cin>>sun;
    takab =taka %2;
    aob   =aob  %2;
    sunb  =sun  %2;
    
    while(counter<=10000000&&takab==0&&aob==0&&sunb==0){
        
        takaq();
        aoq();
        sunq();
        
        taka=takacopy;
        ao=aocopy;
        sun=suncopy;
        
        takacopy=0;
        aocopy=0;
        suncopy=0;
        
        takab =taka %2;
        aob   =aob  %2;
        sunb  =sun  %2;
        counter+=1;
    }
    if(counter>10000000){
        cout<<"-1"<<endl;
    }else{
        cout<<counter<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define NIL -1
#define MAX 25

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

vector<Node> t(MAX, {NIL, NIL, NIL});

void preparse(int u) {
    if (u == NIL) return;
    printf(" %d", u);
    preparse(t[u].left);
    preparse(t[u].right);
}

void inparse(int u) {
    if (u == NIL) return;
    inparse(t[u].left);
    printf(" %d", u);
    inparse(t[u].right);
}

void postparse(int u) {
    if (u == NIL) return;
    postparse(t[u].left);
    postparse(t[u].right);
    printf(" %d", u);
}

int main() {
    int n;
    scanf("%d", &n);
    rep(i, n) {
        int id, l, r;
        scanf("%d %d %d", &id, &l, &r);
        if (l != NIL) t[l].parent = id;
        if (r != NIL) t[r].parent = id;
        t[id].left = l;
        t[id].right = r;
    }

    int r;
    rep(i, n) {
        if (t[i].parent == NIL) {
            r = i;
            break;
        }
    }

    printf("Preorder\n");
    preparse(r);
    printf("\n");
    printf("Inorder\n");
    inparse(r);
    printf("\n");
    printf("Postorder\n");
    postparse(r);
    printf("\n");
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int L,R;
    cin >> L >> R;
    long long ans = 2020;
    for(long long i=L;i<R;i++){
        for(long long j=L+1;j<=R;j++){
            ans=min(ans,(i*j)%2019);
            if(ans==0){
                cout << 0 << endl;
                return 0;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
# alpha = [chr(ord("a")+i) for i in range(10)]
ans = [[] for _ in range(11)]
ans[0].append("a")
for i in range(10):
    for e in ans[i]:
        idx = 0
        for c in e:
            idx = max(idx, ord(c)-ord('a'))
        for j in range(idx+2):
            ans[i+1].append(e+chr(ord("a")+j))
for i in range(len(ans[N-1])):
    print(ans[N-1][i])

Measured memory_bytes: 128712
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
 
#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define For(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
 
int main() {
    string s;
    vector<int> alpha(26,0);
    while (getline(cin, s)) {
        REP(i, s.size()) {
            if (isalpha(s[i])) {
                alpha[tolower(s[i]) - 'a'] += 1;
            }
        }
    }
     
    char n = 'a';
    REP(i,26) {
        cout << (char)(n + i) << " : " << alpha[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3144
#include <iostream>

int main(int argc, const char * argv[]) {
    
    int n, m, l ;
    
    std::cin >> n >> m >> l ;
    
    
    int A[n][m] ;
    for (int y=0; y<n; y++) {
        for (int x=0; x<m; x++) {
            std::cin >> A[y][x] ;
            if (A[y][x] > 10000) return 0 ;
        }
    }
    
    int B[m][l] ;
    for (int y=0; y<m; y++) {
        for (int x=0; x<l; x++) {
            std::cin >> B[y][x] ;
            if (B[y][x] > 10000) return 0 ;
        }
    }
    
    for (int i=0; i<n; i++) {
        for (int j=0; j<l; j++) {
            long long int Cij = 0 ;
            
            for (int k=0; k<m; k++) {
                Cij += A[i][k]*B[k][j] ;
            }
            
            if (j==0) printf("%lld", Cij) ;
            else printf(" %lld", Cij) ;
            
        }
        printf("\n");
    }
    
    
    return 0 ;
}




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

int main() {
    ll a;
    cin >> a;

    ll ans = (a + 10) / 11 * 2;

    if (ans / 2 * 11 - 5 >= a)
        --ans;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <climits>
#include <cmath>
#include <cfloat>

#define FOR(i,b,n) for(int i=b;i<n;i++)
#define REP(i,b,n) for(i=b;i<n;i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))

using namespace std;

int n, m;
char encr[1000] = {0}, decr[1000] = {0};

int main()
{
	while(cin >> n, n)
	{
		FOR(i, 0, n)
		{
			cin >> encr[i] >> decr[i];
		}
		
		cin >> m;
		
		FOR(i, 0, m)
		{
			char c;
			cin >> c;
			
			FOR(i, 0, n)
			{
				if( encr[i] == c )
				{
					c = decr[i];
					goto las;
				}
			}
			
			las:
			cout << c;
		}
		
		cout << endl;
	}
	
	return 0;
}

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

int main() {
  int A,B,C;
  cin >> A >> B >> C;
  vector<int> num = {A,B,C};
  sort(num.begin(), num.end());
  int diff1 = num[2] - num[1];
  int diff2 = num[2] - num[0];
  int res;
  if((diff1 ^ diff2) & 1){
    res = (diff1 + diff2 + 1)/2 + 1;
  }else{
    res = (diff1 + diff2)/2;
  }
  cout << res << endl;
  return 0;
}

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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amin(T& a,T2 b){ if(a > b) a = b;}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m;
	cin >>n >>m;
	
	vector<vector<pii>> r(n);
	rep(i, m){
		int a, b, c; cin >>a >>b >>c;
		r[a-1].emplace_back(b-1, c);
	}
	const ll inf = 1LL<<60;

	auto bellman = [&](int s){
		vector<ll> ds(n, -inf);
		ds[s] =0;
		for(int i =0, nxt =1; i<n+3 && nxt>0 ; i++){
			nxt = 0;
			rep(j, n) for(auto z: r[j]){
				if(ds[j] != -inf && ds[z.first] < ds[j] + z.second){
					ds[z.first] = ds[j] + z.second;
					nxt = 1;
					if(i>n && z.first==n-1) {ds[s] = inf; return ds;}
				}
			}
			//if(i>n ) {ds[s] = inf; return ds;}
		}
		return ds;
	};
	auto ans = bellman(0);
	if(ans[0] ==inf) puts("inf");
	else cout << ans[n-1] <<"\n";
	return 0;
}


Measured memory_bytes: 384
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

n = s()
memo = 0
for i in range(len(n)):
	memo += int(n[i])
if memo%9 == 0:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 9308
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
long long a[10010],b[10010],cnt;
int N;
int read()
{
	static int x;
	static char ch;
	x = 0;
	for(ch=getchar();ch>'9'||ch<'0';ch=getchar());
	for(;ch>='0'&&ch<='9';ch=getchar()) x = x * 10 + ch - '0';
	return x;
}
int main()
{
	N = read();
	for (int i = 1;i<=N;++i) a[i] = read();
	for (int i = 1;i<=N;++i) b[i] = read();
	for (int i = 1;i<=N;++i) 
		if  (a[i]>=b[i]) cnt-=a[i]-b[i];
		else cnt += (b[i] - a[i])>>1;
	if (cnt<0) puts("No");else puts("Yes");
	return 0;
}

Measured memory_bytes: 384
N=int(input())
l =list(map(int,input().split()))
cnt =0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
         if l[i] !=l[j] and l[j] != l[k] and l[k] !=l[i] and max(max(l[i],l[j]) ,l[k]) < l[i]+l[j]+l[k] - max(max(l[i],l[j]) ,l[k]):
             cnt +=1

print(cnt)

Measured memory_bytes: 9240
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100000;

vi g[N + 1];
int d[N + 1][3];

void bfs(int s, int n) {
	rep1(i, n) rep(j, 3) d[i][j] = INF;
	d[s][0] = 0;
	queue<pii> que;
	que.push(pii(s, 0));
	while(!que.empty()) {
		pii p = que.front();
		que.pop();
		for(auto i : g[p.first]) {
			if(p.second == 2 && d[i][0] > d[p.first][p.second] + 1) {
				d[i][0] = d[p.first][p.second] + 1;
				que.push(pii(i, 0));
			}
			else if (p.second <= 1 && d[i][p.second + 1] > d[p.first][p.second]) {
				d[i][p.second + 1] = d[p.first][p.second];
				que.push(pii(i, p.second + 1));
			}
		}
	}
}

int main() {
	int n, m;
	cin >> n >> m;
	rep(i, m) {
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
	}
	int s, t;
	cin >> s >> t;

	bfs(s, n);
	if(d[t][0] == INF) {
		cout << -1 << endl;
	}
	else {
		cout << d[t][0] << endl;
	}
}


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


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

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

int main()
{
	int a, b;
	while (cin >> a >> b) {
		cout << gcd(a, b) << " " << lcm(a, b) << endl;
	}
	return 0;
}

Measured memory_bytes: 3040
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(c) (c).begin(), (c).end()
#define pb push_back
#define eb emplace_back
const long long INF = 1LL<<60; // 仮想的な無限大の値;
using namespace std;
using ll = long long;
using P  = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

Measured memory_bytes: 3616
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int K = scanner.nextInt();

        int[] poss = new int[N];

        for(int i=0; i<N; i++)
            poss[i] = scanner.nextInt();

        getWinnerDP(K, N, poss);
    }

    public static void getWinnerDP(int K, int N, int[] poss) {

        boolean[] dp = new boolean[K + 1];

        for(int x = 1; x<=K; x++) {
            for(int stones = 0; stones < N; stones++) {
                if(poss[stones] <= x && !dp[x - poss[stones]]) {
                    dp[x] = true;
                }
            }
        }

        System.out.println(dp[K] ? "First" :  "Second");
    }
    private static boolean findWinner(int K, int N, int[] poss, int[] memo) {

        if(K == 0) {
            return false;
        }

        if(memo[K] != -1) {
            return memo[K] == 1 ? true: false;
        }

        boolean canWin = false;

        for(int i=0 ; i<N; i++) {
            if(poss[i] <= K) {
                boolean opponentResult = findWinner(K - poss[i], N, poss, memo);
                if(!opponentResult) {
                    canWin = true;
                }
            }
        }
        memo[K] = canWin ? 1: 0;
        return canWin;
    }

}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	for(int i=1;i<=b;i++)
	   if((a*i)%b==c)
	   {
	   	 cout<<"YES";
	   	 return 0;
	   }
	cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
N,T = map(int,input().split())
A_s = list(map(int,input().split()))
MIN = A_s[0]
DIVS = []
for A in A_s:
    if MIN > A:
        MIN = A
    DIVS.append(A-MIN)
MAX = max(DIVS)
answer = DIVS.count(MAX)
print(answer)

Measured memory_bytes: 90852
#include<bits/stdc++.h>
#define FastIO      ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define pb          push_back
#define siz         100009
#define inf         1e9+8
#define mp          make_pair
#define rep(i,n)    for(int i=0;i<n;i++)
#define repo(i,m,n) for(int i=m;i<=n;i++)
#define ll          long long
#define pii         pair<int,int >
#define sc(n)       scanf("%d",&n)
#define sc2(m,n)    scanf("%d%d",&m,&n);
#define MOD         4294967296
#define fileout     freopen("output.txt","w",stdout)
#define filein      freopen("input.txt","r",stdin)
#define mem(x,i)    memset(x,i,sizeof x)
#define PI          acos(-1.0)
#define ff          first
#define ss          second
using namespace std;

vector<pii>adj[siz];
int vis[siz];
void DFS(int src)
{
    rep(i,adj[src].size())
    {
        if(vis[adj[src][i].ff]==-1)
        {
            if(adj[src][i].ss%2) vis[adj[src][i].ff]=1-vis[src];
            else vis[adj[src][i].ff]=vis[src];
            DFS(adj[src][i].ff);
        }
    }
}
int main()
{
    int n;
    cin>>n;
    rep(i,n-1)
    {
        int u,v,w;
        cin>>u>>v>>w;
        adj[u].pb({v,w});
        adj[v].pb({u,w});
    }
    mem(vis,-1);
    vis[1]=1;
    DFS(1);
    repo(i,1,n) cout<<vis[i]<<endl;

}


Measured memory_bytes: 8448
#[allow(unused_imports)]
use std::collections::HashSet;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

//use lazy_static::lazy_static;

//lazy_static! {
//    static ref MOD :usize = 10usize.pow(9) + 7;
//}

use std::collections::HashMap;

static MOD: usize = 1000_000_007;

fn main() {
    let l: Vec<char> = read::<String>().chars().collect::<Vec<char>>();
    let n = l.len();

    let mut pow3 : Vec<usize> = vec![0; n];
    prepare(&l, &mut pow3);
    let answer = solve(&l, &pow3);
    println!("{}", answer);
}


fn prepare(l: &[char], m3: &mut[usize]) {
    let n = l.len();
    let mut pos_of_one = n - 1;
    let mut x3 = 1;

    m3[0] = 1;

    for i in (0..n).rev() {
        if l[i] == '0' {
            continue;
        }

        let r = pos_of_one - i;
        for _ in 0..r {
            x3 = x3 * 3 % MOD;
        }
        m3[n-i-1] = x3;
        pos_of_one = i;
        //println!("m3 {}, {}", r, x3);
    }
}


fn solve(l: &[char], m3: &[usize]) -> usize {
    let n = l.len();

    let mut count = 0;
    let mut c1 = 0;
    for i in 0..n {
        if l[i] == '0' {
            continue;
        }
        let remaining = n - i - 1;
        if c1 == 0 {
            c1 = 1;
        } else {
            c1 = c1 * 2 % MOD;
        }
        
        let c2 = m3[remaining];
        let c3 = c1 * c2 % MOD;

        count = (count + c3) % MOD;
    }
    c1 = c1 * 2 % MOD;
    count = (count + c1) % MOD;
    return count;
}


Measured memory_bytes: 4352
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx")

#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

using int64 = long long;

constexpr int MAX = 80 * 80 * 2;

bool dp[80][80][MAX + 100];
// dp[i][j][k] : (i, j) にいったときの偏りを k にできるか

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

  int h, w; cin >> h >> w;
  int a[h][w], b[h][w];

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

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) cin >> b[i][j];
  }

  dp[0][0][abs(a[0][0] - b[0][0])] = 1;

  for (int i = 1; i < w; ++i) {
    int d = abs(a[0][i] - b[0][i]);
    for (int j = 0; j <= MAX; ++j) {
      dp[0][i][j] |= (dp[0][i - 1][j + d] || dp[0][i - 1][abs(j - d)]);
    }
  }

  for (int i = 1; i < h; ++i) {
    int d = abs(a[i][0] - b[i][0]);
    for (int j = 0; j <= MAX; ++j) {
      dp[i][0][j] |= (dp[i - 1][0][j + d] || dp[i - 1][0][abs(j - d)]);
    }
  }

  for (int i = 1; i < h; ++i) {
    for (int j = 1; j < w; ++j) {
      int d = abs(a[i][j] - b[i][j]);
      for (int k = 0; k <= MAX; ++k) {
        dp[i][j][k] |= (dp[i][j - 1][k + d] || dp[i][j - 1][abs(k - d)]);
        dp[i][j][k] |= (dp[i - 1][j][k + d] || dp[i - 1][j][abs(k - d)]);
      }
    }
  }

  int ans = 0;

  for (int i = 0; i <= MAX; ++i) {
    if (dp[h - 1][w - 1][i]) {
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}


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

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair <int, int>
#define pll pair <ll, ll>
#define gcd __gcd
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

const ll L = 2e2+5;

ll fla[L];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    ll N, L;
    cin >> N >> L;

    ll res = 1e9;
    ll sum = 0;

    bool f = false;

    for(ll i=1; i<=N; i++)
    {
        fla[i] = L+i-1;

        // cout << fla[ i]<< endl;

        sum+=fla[i];
        
        // if(fla[i]>=0)
        // {
            // f = true;
            if(fla[i]<0)
            {
                f = true;
                res = min(res, abs(0LL-fla[i]));
            }

            else
            {
                res = min(res, abs(0LL-fla[i]));
            }
        // }
    }

    if(f)
    {
        res = -res;
    }

    // cout << sum << " " << res << endl;

    cout << sum-res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
int main(){
    int n;cin >> n;
    if(n%2==0) cout << n/2 << endl;
    else cout << n/2 + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextString() string {
	if !sc.Scan() {
		panic("failed scan string")
	}
	return sc.Text()
}

func nextInt() int {
	if !sc.Scan() {
		panic("failed scan int")
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	max := 4 * 100000
	buf := make([]byte, max)
	sc.Buffer(buf, max)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	s := nextString()

	var count int
	for i := 0; i < n; i++ {
		if s[i] == 'E' {
			count++
		}
	}

	min := count
	for i := 0; i < n; i++ {
		if s[i] == 'E' {
			count--
		}
		if i > 0 && s[i-1] == 'W' {
			count++
		}
		if count < min {
			min = count
		}
	}

	fmt.Println(min)
}


Measured memory_bytes: 1280
using System;
using System.Linq;
using System.Collections.Generic;
class ProgramC
    {
        static void Main(string[] args)
        {
            
            //入力
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int k = int.Parse(input[1]);
            long[] a = new long[n];

            long sum = 0;


            string[] input2 = Console.ReadLine().Split(' ');
            for(int i = 0;i < n;i++)
                a[i] = long.Parse(input2[i]);

            Array.Sort(a);

            for(int i = 0;i < n - k;i++)
                sum += a[i];

            Console.WriteLine(sum);
        } 
    }

Measured memory_bytes: 31580
#include<iostream>
#include<vector>
#include<cmath>


int main(){

	int N;
	unsigned long long int ans = 0;
	std::cin >> N;

	std::vector<unsigned long long int> list(N,0);

	unsigned long long int sum=0;

	for (int i = 0; i < N;i++){
		std::cin >> list[i];
		sum += list[i];
	}


	for (int i = 0; i < N-1; i++){
		ans += ((list[i]%1000000007) * ((sum-=list[i])%1000000007));
		ans %= 1000000007;
	}

	std::cout << ans << std::endl;
}

Measured memory_bytes: 4772
import java.util.*;

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

    int n = sc.nextInt();
    int[] a = new int[n];
    int ans = 0;

    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
      if(i % 2 == 0 && a[i] % 2 == 1){
        ans += 1;
      }
    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 35740