akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

// 標準入力から改行かスペースまで読み取り、数字として返す
int get_num() {
    // 10文字+区切り文字までしか受け付けられない
    char s[11];
    int i, n;
    for (i = 0; i < sizeof(s); i++) {
        s[i] = getchar();
        if (s[i] == ' ' || s[i] == '\n') {
            s[i] = '\0';
            break;
        }
    }
    sscanf(s, "%d", &n);
    return n;
}

void sort(int a[], int num) {
    int i, j, b;
    for (i = 0; i < num-1; i++) {
        for (j = 0; j < num-i-1; j++) {
            if (a[j] > a[j+1]) {
                b = a[j];
                a[j] = a[j+1];
                a[j+1] = b;
            }
        }
    }
}

int main(void) {
    int N;
    int a[100];
    int i;
    int alice = 0, bob = 0;

//    int b[] = {2,7,4};
//    sort(b, 3);
//    for(i = 0; i < 3; i++) {
//        printf("%d,", b[i]);
//    }
//    printf("\n");

    N = get_num();
    for (int i = 0; i < N; i++) {
        a[i] = get_num();
    }
    sort(a, N);
    
//    for (int i = 0; i < N; i++) {
//        printf("%d,", a[i]);
//    }
//    printf("\n");
    
    i = N-1;
    while(i >= 0) {
        alice += a[i];
        i--;
        if (i < N) {
            bob += a[i];
            i--;
        }
    }
    
    printf("%d\n", alice - bob);
    
    return 0;
}



Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,a[100005],ma[100005]={0},j=0,ans=0;
	cin>>n;for(int i=0;i<n;i++)cin>>a[i];sort(a,a+n);for(int i=0;i<n;i++){if(a[i]==a[i+1])ma[j]++;else{ma[j]++;j++;}}for(int l=0;l<n;l++)if(ma[l]%2==1)ans++;cout<<ans<<endl;return 0;
}

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

int main(){
  int n;
  string s;
  cin >>n >>s;
  int ans=0;
  for(int i=0;i<n;i++){
    if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
      ans += 1;
    }
  }
  
  cout << ans << endl;
  
}

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

typedef long long ll;
const ll INF = 1e18;

// Greatest Common Divisor
ll gcd(ll a, ll b)
{
  while (b != 0) {
    a = a % b;
    std::swap(a, b);
  }
  return a;
}

int main(int argc, char* argv[])
{
  std::vector< int > va(3, 0);

  std::cin >> va[0] >> va[1] >> va[2];

  std::sort(va.begin(), va.end());
  va.erase(std::unique(va.begin(), va.end()), va.end());

  std::cout << (int)va.size() << std::endl;

  return 0;
}


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

int main() {
	ll N, Q;
	string str;

	cin >> N >> Q >> str;
	
	vector<int> S(N + 1, 0);
	for (int i = 0; i < N; i++) {
		if (i + 1 < N && str[i] == 'A' && str[i + 1] == 'C') {
			S[i + 1] = S[i] + 1;
		}
		else {
			S[i + 1] = S[i];
		}
	}

	for (int i = 0; i < Q; i++) {
		int l, r;
		cin >> l >> r;
		l--, r--;
		cout << S[r] - S[l] << endl;
	}
}


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

void call2(int n);
int main() {
    int n;
    cin >> n;
    call2(n);
}

void call2(int n) {
    for (int i=1;i<=n;++i) {
        int x = i;
        if ( x % 3 == 0 ){
            cout << " " << i;
            continue;
        }
        while ( x ) {
            if (x % 10 == 3) {
                cout << " " << i;
                break;
            }
            x /= 10;
        }
    }
    cout << endl;
}

Measured memory_bytes: 1160
aLst = [list(map(int, input().split(" "))) for i in range(3)]
lst = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

n = int(input())

for i in range(n):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if aLst[j][k] == b:
                lst[j][k] = 1

# 縦
for i in range(3):
    sum = 0
    for j in range(3):
        sum += lst[i][j]
    if sum == 3:
        print("Yes")
        exit(0)  

# 横
for i in range(3):
    sum = 0
    for j in range(3):
        sum += lst[j][i]
    if sum == 3:
        print("Yes")
        exit(0)  

# 斜め(左上から右下)
sum = 0
for i in range(3):
    sum += lst[i][i]
if sum == 3:
    print("Yes")
    exit(0)  

# 斜め(右上から左下)
sum = 0
for i in range(3):
    sum += lst[i][2-i]
if sum == 3:
    print("Yes")
    exit(0)

print("No")  


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <algorithm>
#include <iomanip> //cout << fixed << setprecision(12) << ans << endl;
using namespace std;
 
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define loop(i, l, r) for(int i = l; i < r; i++)
#define rloop(i, l, r) for(int i = l; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vec_i;
typedef pair<int,int> pair_ii;
typedef pair<ull,ull> pair_ull;
 
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
const int INF = 1e9;
const int MOD = 1e9+7;
 
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, k;
	cin >> n >> k;
	int cnt=0;
	rep(i, n){
		int a;
		cin >> a;
		if(a >= k){
			cnt++;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define NL <<"\n"

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#include "benri.h"
#else
#define out(args...)
#endif
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
const ll MOD=1e9+7; //998244353

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout<<fixed<<setprecision(0);
	ll k;
  cin>>k; k;
	--k;
	vector<int> a{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	cout<<a[k] NL;
	return 0;
}


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

int main(){
int a, b;
char op;
while(1){
  cin >> a >> op >> b;
  if(op == '?') break;
  if(op == '+'){
     cout << a + b << endl;
    }else if(op == '-'){
     cout << a - b << endl;
    }else if(op == '*'){
     cout << a * b << endl;
    }else if(op == '/'){
     cout << a / b << endl;
    }
 }
return 0;
}
  


Measured memory_bytes: 3012
import sys
sys.setrecursionlimit(100000)
N,M = map(int,input().split())
graph = [[] for i in range(10**5 + 10)]
dp = [-1 for i in range(10**5 + 10)]

for i in range(M):
    x,y = map(int,input().split())
    graph[x-1].append(y-1)
    
def rec(v):
    if dp[v] != -1:
        return dp[v]
    tmp = 0
    for x in graph[v]:
        r = rec(x)+1
        if tmp < r:
            tmp = r
    dp[v] = tmp
    return dp[v]

result = 0
for i in range(N):
    r = rec(i)
    result = r if r>result else result
print(result)

Measured memory_bytes: 164188
#include<iostream>
using namespace std;
#define MAX 2000000

int H,A[MAX+1];

void maxHeap(int i){
  int l,r,largest;
  l=2*i;
  r=2*i+1;

  if(l<=H && A[l]>A[i])largest=l;
  else largest=i;
  if(r<=H && A[r]>A[largest])largest=r;

  if(largest!=i){
    int t=A[i];
    A[i]=A[largest];
    A[largest]=t;
    maxHeap(largest);
  }
}

int main(){
  cin>>H;
  for(int i=1;i<H+1;i++){
    cin>>A[i];
  }
  for(int i=H/2;i>=1;i--)maxHeap(i);
  for(int i=1;i<=H;i++){
    cout<<" "<<A[i];
  }
  cout<<endl;

  return 0;
}



Measured memory_bytes: 4972
/**
*    created: 14.05.2020 11:28:23
**/
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

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

    string s; cin>> s;
    int n = s.size();
    int cnt1 = 0, cnt2 = 0;
    rep(i,n) {
        if (i % 2 == 0 && s[i] != '0') cnt1++;
        if (i % 2 == 1 && s[i] != '1') cnt1++;
    }
    rep(i,n) {
        if (i % 2 == 0 && s[i] != '1') cnt2++;
        if (i % 2 == 1 && s[i] != '0') cnt2++;
    }
    cout << min(cnt1, cnt2) << endl;
    return 0;
}

Measured memory_bytes: 3764
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#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) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

struct Sum {
  using T = int;
  T operator()(const T& left, const T& right) {
    return left + right;
  }
  static constexpr T identity() { return T(0); }
};

template<class Monoid>
class SegTree {
private:
  using T = typename Monoid::T;
  Monoid op;
  const int n;
  vector<T> t;

  void propagate_to(int i) { t[i] = op(t[2*i], t[2*i+1]); }

public:
  SegTree(int n_) : n(n_), t(2*n, op.identity()) {}
  SegTree(const vector<T>& v) : n(v.size()), t(2*n) {
    copy(begin(v), end(v), begin(t) + n);
    for (int i = n-1; i > 0; --i) {
      propagate_to(i);
    }
  }

  void set(int i, const T& x) {
    t[i += n] = x;
    while (i >>= 1) {
      propagate_to(i);
    }
  }

  T get(int i) { return t[i + n]; }

  T accumulate(int l, int r) {
    T accl = op.identity(), accr = op.identity();
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) accl = op(accl, t[l++]);
      if (r & 1) accr = op(t[r-1], accr);
    }
    return op(accl, accr);
  }
};

int main() {
  string s, t;
  cin >> s;
  cin >> t;
  int sn = s.length();
  int tn = t.length();
  vi vs(sn);
  rep (i, sn) {
    if (s[i] == 'A') {
      vs[i] = 1;
    } else {
      vs[i] = -1;
    }
  }
  vi vt(tn);
  rep (i, tn) {
    if (t[i] == 'A') {
      vt[i] = 1;
    } else {
      vt[i] = -1;
    }
  }
  SegTree<Sum> segs(vs);
  SegTree<Sum> segt(vt);
  int q;
  cin >> q;
  //vi a(q), b(q), c(q), d(q);
  rep (i, q) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    a -= 1; c -= 1;
    int sums = segs.accumulate(a, b);
    int sumt = segt.accumulate(c, d);
    int diff = sums - sumt;
    if (diff < 0) diff *= (-1);
    if (diff % 3 == 0) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
  }

  return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cstdlib>
#define rep for(int i = 0; i<n; i++)

using namespace std;

int main()
{	
	double t, x;

	cin >> t >> x;
	
	
	cout << t / x << endl;




    return 0;
}

Measured memory_bytes: 256
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
import heapq
INF = float("inf")
MOD = 10**9 + 7
sys.setrecursionlimit(10**7)
# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def mi(): return map(int, input().split())
def ii(): return int(input())
###template###

N, D = mi()
D = D * 2 + 1

print(ceil(N/D))




Measured memory_bytes: 38748
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a > b) {
		swap(a, b);
	}
	if (a > c) {
		swap(a, c);
	}
	if (b > c) {
		swap(b, c);
	}
	cout << a << " " << b << " " << c << endl;;
	return 0;
}

Measured memory_bytes: 3104
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<utility>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i <= n; i++)
#define FORR(i, m, n) for(ll i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n)
#define MAX 100000
#define inf 1000000007
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

int main() {
    //cin高速化
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m = 0;
    cin >> n;
    //1オリジン
    vll a(n+1, 0);//初期化忘れない
    vll b(n+1, 0);
    FOR(i, 1, n) cin >> a[i];
    FORR(i, n, 1){
        ll tmp = 0;
        for(ll j = i; j <= n; j += i){//倍数だけチェック
            tmp += b[j];
        }
        if(tmp%2 != a[i]){
            b[i] = 1;
            m ++;
        }
    }

    cout << m << endl;
    FOR(i, 1, n){
        if(b[i] == 1) cout << i << " " << endl;
    }
	return 0;
}

Measured memory_bytes: 4096
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
 
class Program
{
    static void Main()
    {
        string inputs;
        while((inputs = Console.ReadLine()) != null)
        {
            var tmp = inputs.Split(' ');
            Console.WriteLine(int.Parse(tmp[0]) + int.Parse(tmp[1]));
        }
    }
}

Measured memory_bytes: 9004
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int H,W;
    char s[52][52];
    cin>>H>>W;
    for(int j=1;j<H+1;j++){
      for(int i=1;i<W+1;i++){
        cin>>s[j][i];
      }
    }
    
    for(int j=1;j<H+1;j++){
      for(int i=1;i<W+1;i++){
        if(s[j][i]=='.'){s[j][i]='0';}
      }
    }
  				

    for(int j=1;j<H+1;j++){
      for(int i=1;i<W+1;i++){
        if(s[j][i]=='#'){
          if(s[j-1][i-1]!='#')s[j-1][i-1]+=1;
          if(s[j-1][i]!='#')s[j-1][i]+=1;
          if(s[j-1][i+1]!='#')s[j-1][i+1]+=1;
          if(s[j][i-1]!='#')s[j][i-1]+=1;
          if(s[j][i+1]!='#')s[j][i+1]+=1;
          if(s[j+1][i-1]!='#')s[j+1][i-1]+=1;
          if(s[j+1][i]!='#')s[j+1][i]+=1;
          if(s[j+1][i+1]!='#')s[j+1][i+1]+=1;
          }
        }
      }

      for(int j=1;j<H+1;j++){
        for(int i=1;i<W+1;i++){
          cout<<s[j][i];
        }
        cout<<endl;
      }
      return 0;
          

      
    
}

Measured memory_bytes: 256
let limit = 202020
let modulo = 998244353

let (+@) a b = (a + b) mod modulo
let ( *@) a b = (a * b) mod modulo
let rec modpow a n =
  if n = 0 then 1
  else if n mod 2 = 1 then a *@ modpow a (n-1)
  else let h = modpow a (n/2) in h *@ h
let modinv a = modpow a (modulo - 2)

let fact =
  let arr = Array.init limit Fun.id in
  arr.(0) <- 1;
  for i = 1 to limit-1 do arr.(i) <- i *@ arr.(i-1); done;
  arr

let inv_fact = Array.map modinv fact

let comb n k = fact.(n) *@ inv_fact.(k) *@ inv_fact.(n-k)

let () =
  Scanf.scanf "%d %d %d" @@ fun n m k ->
  Array.init (k+1) (fun i -> m *@ modpow (m-1) (n-1-i) *@ comb (n-1) (n-1-i))
  |> Array.fold_left (+@) 0
  |> Printf.printf "%d\n"

Measured memory_bytes: 8584
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		sc.close();

		int X = (int) Math.ceil((double) C / B);
		int Y = (int) Math.ceil((double) A / D);
		if (X <= Y) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 35836
S = input()
N = len(S)
mod = 10**9 + 7

p = 1

dp = [[0]*13 for _ in range(N+1)]
dp[0][0] = 1

for i in range(1,N+1):
  if S[-i] == '?':
    for k in range(10):
      a = (k * p) % 13
      for j in range(13):
        dp[i][j] += dp[i-1][j-a] % mod
        dp[i][j] %= mod
  else:
    a = (int(S[-i]) * p) % 13
    for j in range(13):
      dp[i][j] += dp[i-1][j-a] % mod
  p = (p * 10) % 13

print(dp[N][5])

Measured memory_bytes: 96084
def LI():
  return list(map(int,input().split()))
  
n=int(input())
a=LI()

money=1000
kabu=0
for i in range(n-1):
    if a[i]<a[i+1]:
        # kau
        if money<a[i]:
            continue
        kabu=money//a[i]
        money=money-kabu*a[i]
    elif a[i]==a[i+1]:
        pass
    else:
        money=money+kabu*a[i]
        kabu=0
    # print(i,money,kabu)

money=money+kabu*a[-1]
print(money)
    

Measured memory_bytes: 62004
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >> S;
    if(S == "Sunny"){
        cout << "Cloudy" << endl;
    }
    if (S == "Cloudy")
    {
        cout << "Rainy" << endl;
    }
    if(S == "Rainy"){
        cout << "Sunny" << endl;
    }
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	var s string
	fmt.Scan(&n, &s)

	n = n % 26
	if n == 0 {
		fmt.Println(s)
		return
	}

	srune := []rune(s)
	for i := 0; i < len(srune); i++ {
		char := srune[i] + rune(n)
		if char > []rune("Z")[0] {
			plus := char - []rune("Z")[0]
			srune[i] = []rune("A")[0] + plus - 1
		} else {
			srune[i] = char
		}
	}
	fmt.Println(string(srune))
}


Measured memory_bytes: 768
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val (a, b, n) = in.readLine().split("\\s+") match {
      case Array(a, b, n) => (a.toLong, b.toLong, n.toLong)
    }

    if (n + 1 >= b) {
      val k = (n + 1) / b
      out.println(a * k - Math.ceil(1.0 * a / b).toLong - a * (k - 1))
    } else {
      out.println(a * n / b)
    }
    out.flush()
  }
}


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

int main() {
  string t = "keyence";
  string s;
  cin >> s;
  int a = 0, b = 0;
  while (a < s.size() && a < t.size() && s[a] == t[a]) a++;
  while (b < s.size() && b < t.size() && s[s.size() - 1 - b] == t[t.size() - 1 - b]) b++;
  cout << (a + b >= t.size() ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    if (A > 8 || B > 8) {
      System.out.println(":(");
    } else {
      System.out.println("Yay!");
    }


    sc.close();
  }
}

Measured memory_bytes: 35920
card=gets.to_i
a=Array.new(card)
card.times{|i|
	a[i]=gets.to_i
}

count=0
(a.length-1).times{|i|
	b=a[i]/2
	count+=b
	a[i]-=(b*2)
	if a[i]==1&&a[i+1]>0 then
		a[i+1]-=1
		
		count+=1
	end
}
count+=a[a.length-1]/2
puts count




Measured memory_bytes: 2940
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("input.txt", "r", stdin);
    ll S;
    cin >> S;
    ll x1 = 0, y1 = 0, x2 = 1000 * 1000 * 1000;
    ll y3 = (S + x2 - 1) / x2;
    ll le = x2 * y3 - S;
    assert(le >= 0 && le <= x2);
    ll x3 = 1;
    ll y2 = le;
    cout << x1 << " " << y1 << " " << x2 << " " << y2 << " " << x3 << " " << y3;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<malloc.h>
int main(void){
  int x,i;
  int n=0;
  int c=1;
  int a;
  int *b;
  scanf("%d %d",&a,&x);
  b=(int*)malloc(sizeof(int)*a);
  for(i=0;i<a;i++){
      scanf("%d",&b[i]);
  }
  for(i=0;i<a;i++){
      n=n+b[i];
      if(x>=n){
          c++;
      }
  }
  printf("%d\n",c);
  return 0;
}

Measured memory_bytes: 128
s = list(input())
findA = 0
findZ = 0
ans = 0
ansz = 0
for i in range(len(s)):
    if(s[i] == 'A' and findA==0):
        ans = i
        findA+=1
    if(s[len(s) - i-1] == 'Z' and findZ==0):
        ansz = len(s)-i
        findZ+=1
print(ansz - ans)

Measured memory_bytes: 4840
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
int main(void)
{
  for(;;){
    int n;
    cin >> n;
    if(!n) return 0;
    vector<string> vs(n);
    REP(i,n) cin >> vs[i];
    set<char> mask;
    for(string s:vs) for(char c:s) mask.insert(c);
    vector<char> ma(mask.begin(),mask.end());
    while(ma.size()<10) ma.push_back('a');
    int csum[256][10];
    REP(i,256) REP(j,10) csum[i][j]=0;
    int tmp=1;
    REP(i,vs.size()-1){
      tmp=1;
      for(int j=vs[i].size();j>=0;--j){
	csum[vs[i][j]][1]+=tmp;
	tmp*=10;
      }
    }
    tmp=1;
    for(int j=vs[n-1].size();j>=0;--j){
      csum[vs[n-1][j]][1]-=tmp;
      tmp*=10;
    }
    REP(i,256) REP(j,10) csum[i][j]=csum[i][1]*j;
    int answer=0;
    map<char,bool> l0;
    for(string s:vs) for(char c:s) l0[c]=false;
    REP(i,vs.size()) if(vs[i].size()>1) l0[vs[i][0]]=true;
    do{
      if(l0[ma[0]]) continue;
      int sum=0;
      REP(i,ma.size()) sum+=csum[ma[i]][i];
      if(sum==0) ++answer;
    }while(next_permutation(ma.begin(),ma.end()));
    cout << answer << endl;

  }
}

Measured memory_bytes: 3064
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

point = {"r": P, "s": R, "p": S}
total = 0

#K回前に出した手を管理しておく
#iとi - Kは mod K が等しいため、K個前の手は mod K で表現できる
#出した手を全て記録する必要はなく、直近K個だけあれば十分
before = ["*" for _ in range(K)]

for i,now in enumerate(T):
  #K回前に出した手と、今勝てる手が違うのであれば
  #得点を足し、手を書き換える
  if before[i % K] != now:
    total += point[now]
    before[i % K] = now
  else:
    before[i % K] = "*"

print(total)

Measured memory_bytes: 3956
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int sec[] = new int[n];
        for (int i = 0; i < n; i++) {
            sec[i] = scanner.nextInt();
        }
        for (int i = sec.length-1; i >= 0; i--) {
            if(i < sec.length-1) System.out.print(" ");
            System.out.print(sec[i]);
        }
        System.out.println();
    }
}


Measured memory_bytes: 26372
#include <iostream>
#include <string>

using namespace std;
using ll = long long;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

string CF = "CODEFESTIVAL2016";

void solve(string S) {
  int cnt{};
  for(auto i = 0; i != 16; ++i) {
    if(S[i] != CF[i]) ++cnt;
  }
  cout << cnt << endl;
}

int main() {
  string S;
  cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import itertools
import operator
import collections

def solve(N: int, x: "List[int]", y: "List[int]"):
    if N == 1:
        print(1)
        return

    PL = list(zip(x,y))
    PL.sort(key = operator.itemgetter(0,1))

    pqdic = collections.defaultdict(list)
    for i in range(N-1):
        for j in range(i+1,N):
            p = PL[j][0] - PL[i][0]
            q = PL[j][1] - PL[i][1]
            pqdic[p,q].append((i,j))

    max_pqlen = 0
    for k,v in pqdic.items():
        max_pqlen = max(max_pqlen,len(v))

    print(N - max_pqlen)




# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]" 
    y = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, x, y)

if __name__ == '__main__':
    main()


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

using namespace std;

#define int long long

const int N = 305;
int n, mod, K, dp[N][N], C[N][N], psum[N][N];

void sieve(){
    for(int i = 0; i < N; ++i) C[0][i] = C[i][i] = 1;
    for(int i = 1; i < N; ++i){
        for(int j = 1; j < i; ++j){
            C[j][i] = (C[j][i - 1] + C[j - 1][i - 1]) % mod;
        }
    }
}

signed main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> K >> mod;
    sieve();

    for(int i = 0; i <= K; ++i) dp[1][i] = 1, psum[1][i] = (i + 1) % mod;

    for(int i = 2; i <= n + 1; ++i){
        for(int j = 0; j <= K; ++j){
            for(int k = 1; k < i; ++k){
                dp[i][j] += ((dp[i - k][j] * (psum[k][K] - psum[k][j])) % mod * C[k - 1][i - 2]) % mod; dp[i][j] %= mod;
            }
            if(j) psum[i][j] = (dp[i][j] + psum[i][j - 1]) % mod;
        }
    }

     cout << (dp[n + 1][0] + mod) % mod;

    return 0;
}


Measured memory_bytes: 2432
#C
N = int(input())
A =list(map(int,input().split()))
buka_num = [0]*N

for x in range(N-2,-1,-1):
    zyousi = A[x]
    buka_num[zyousi-1] +=1
for x in range(N):
    print(buka_num[x])

Measured memory_bytes: 32364
import java.util.Scanner;
class Main{
  public static void main(String[] args){
  Scanner scanner = new Scanner(System.in);
  
  for(int i = 1; ; i++){
      int x = scanner.nextInt();
      int y = scanner.nextInt();
      int numbers[] = {x, y};
      int temp;
      if(x == 0 && y == 0){
          break;
          }
      for(int j = 0; j < numbers.length - 1; j++){
          
          if(numbers[j] > numbers[j + 1]){
              temp = numbers[j];
              numbers[j] = numbers[j + 1];
              numbers[j + 1] = temp;
          }
          System.out.println(numbers[0] + " " + numbers[1]);
      }
      
    }
  }
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    vector<pii> a(n);
    REP(i,n){
        int32 ai;
        cin >> ai;
        a[i] = pii(ai, i);
    }
    sort(ALL(a), greater<pii>());
    REP(i,n){
        REP(j,n){
            if(a[j].second != i){
                cout << a[j].first << endl;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 4736
from heapq import heapify,heappop,heappush

N,M = map(int,input().split())
AB=[]

for i in range(0,N,1):
    a,b= map(int,input().split())
    AB.append([a,b])

AB.sort()
q = []
heapify(q)
cersol = 0
ans = 0
for i in range(0,M+1,1):#残り日数
    while 1:
        if cersol < N and AB[cersol][0] <= i:
            heappush(q,-AB[cersol][1])
            cersol+=1
        else:
            break
    if len(q)>0:
        ans += -heappop(q)
print(ans)



Measured memory_bytes: 70488
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int>
using namespace std;

bool  check (char c){
    if (c=='A' or c=='C' or c=='G' or c=='T') return true;
    return false;
}

inline void solve(){
    string  s; cin>>s;
    int len=sz(s),res=0,l=-1;
    for (int i=0;i<len;i++){
        if (check(s[i]) and l==-1){
            l = i ; res=max(res,1LL);
        }
        else if (check(s[i])){
            res = max(res,i-l+1);
        }
        else  l = -1 ; 
    }
    cout << res << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  int i=1;
  while(++i<=n){
    int x=i;
    if(x%3==0){
      cout << " " << i;
      continue;
    }
    while(x){
      if(x%10==3){
	cout << " " << i;
	break;
      }
      x/=10;
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3080
//#pragma GCC optimize("-O3")
/*
				C++
				encoding: UTF-8
				Last Modified: 03/May/20 05:38:33 PM
*/

#include <bits/stdc++.h>
#ifdef H4wk3ye
#	include <prettypr.hpp>
#endif

using namespace std;

// clang-format off

#define		int                    long long
#define		ve                     vector
#define		pb                     push_back
#define		endl                   "\n"
#define		ff                     first
#define		ss                     second
#define		pii                    pair<int, int>
#define		len(v)                 (int)v.size()
#define		all(v)                 v.begin(), v.end()
#define		reset(a, b)            memset(a, b, sizeof(a));
#define		fr(i, s, n)            for (int i = s ; i < n ; ++i)
#define		dfr(i, s, n)           for (int i = s ; i > n ; --i)

template < typename T > void pr (const T& t) {
    cout << t << "\n";
}

template < typename T, typename U, typename... ARGS >
void pr (const T& t, const U& u, const ARGS&... args) {
    cout << t << " ";
    pr (u, args...);
}

// clang-format on


signed main () {
	ios_base::sync_with_stdio (false), cin.tie (nullptr);
	int n, m;
	cin >> n >> m;
	int arr[n + 1];
	fr (i, 1, n + 1) cin >> arr[i];
	set< int > s;
	fr (i, 0, m) {
		int u, v;
		cin >> u >> v;
		if (arr[u] < arr[v])
			s.insert (u);
		else if (arr[u] > arr[v])
			s.insert (v);
		else {
			s.insert (u);
			s.insert (v);
		}
	}
	pr (n - len (s));
	return 0;
}

Measured memory_bytes: 7104
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <climits>

int main(int argc, char **argv) {
        long long int n=0;
        std::cin >> n;
        long long int *ret = new long long int[n];


        std::vector<std::pair<long long int, long int> > v;
        for(long long int i=0; i < n; i++) {
                long long int a;
                std::cin >> a;
                v.push_back({a,i});
                ret[i] = 0;
        }

        std::sort(v.begin(),v.end());
        std::reverse(v.begin(),v.end());

        long long int cur = 0;
        long long int min = INT_MAX;
        long long int count = 0;
        while (cur < n) {
                long long int next = cur;
                while (next<n and v[cur].first == v[next].first) {
                        if (min > v[next].second) {
                                min = v[next].second;
                        }
                        next++;
                        count++;
                }
                if (next == n) {
                        ret[min] += (v[cur].first) * count;
                } else {
                        ret[min] += (v[cur].first - v[next].first) * count;
                }
                cur = next;
        }

        for (long long int i=0; i < n; i++) {
                std::cout << ret[i] << std::endl;
        }
        return 0;
}


Measured memory_bytes: 3568
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<limits>
#include<algorithm>
#include<numeric>
#include<utility>

using ull = unsigned long long int;
using ll = long long int; 

int main(){
    ll A,B,C;
    std::cin >> A >> B >> C;
    int login = 7;
    int cnt=0;

    while(C>0){
        C-=A;
        login--;
        if(login==0){
            C-=B;
            login=7;
        }
        cnt++;
    }

    std::cout << cnt << std::endl;

    return 0;
}


Measured memory_bytes: 3100
import java.util.Scanner;

public class Main {

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

		int n = sc.nextInt();

		int sum = 0;

		for (int i = 0; i < n; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();

			sum += r - l + 1;
		}

		System.out.println(sum);

		sc.close();
	}

}

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

int main()
{
	int n;
	cin>>n;
	int f=0;
	while(n>0)
	{
		int z=n%10;
		if(z==7)
		{
			f=1;
			cout<<"Yes"<<endl;
			break;
		}
		n=n/10; 
	}
	if(f==0)
	{
		cout<<"No"<<endl;
	}

}

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

#define rep(i, s, n) for(int i = s; i < n; ++i)
#define rrep(i, n) for(int i = n - 1; i > -1; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const long long INF = 1000000000;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

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

Measured memory_bytes: 256
#include<cstdio>
#include<set>
#include<iostream>
#include <iterator>
#include <utility>
#include<map>
#define max 100005
using namespace std;
struct tree
{
	int parent;
	int left;
	int  right;
};
struct tree T[30];
int dep(int i)
{
	int d=0;
	while(T[i].parent!=-1)
	{
		i=T[i].parent;
		d++;
	}
	return d;
}
int sib(int i)
{
	if(T[i].parent==-1)
	return -1;
	int x;
	x=T[i].parent;
	if(i==T[x].left)
	return T[x].right;
	else
	return T[x].left;
}
int deg(int i)
{
	if(T[i].right==-1&&T[i].left==-1)
	return 0;
	else if(T[i].right>=0&&T[i].left>=0)
	return 2;
	else
	return 1;
}
int h(int i)
{
	int a=0,b=0;
	if(T[i].left!=-1)
	a=h(T[i].left)+1;
	if(T[i].right!=-1)
	b=h(T[i].right)+1;
	return (a>b)? a:b;
}
void print(int i)
{
	printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,T[i].parent,sib(i),deg(i),dep(i),h(i));
	if(T[i].parent==-1)
	cout<<"root";
	else if(T[i].left==-1&&T[i].right==-1)
	cout<<"leaf";
	else
	cout<<"internal node";
	printf("\n");
}
int main()
{
	int n;
	int id,left,right;
	cin>>n;
	for(int i=0;i<n;i++)
	T[i].parent=-1;
	for(int i=0;i<n;i++)
	{
		int id,r,l;
		cin>>id>>l>>r;
		T[id].left=l;
		T[id].right=r;
		if(l!=-1)
		T[l].parent=id;
		if(r!=-1)
		T[r].parent=id;
	}
	for(int i=0;i<n;i++)
	print(i);
	return 0;
}


Measured memory_bytes: 3224
const config = {
    input: '/dev/stdin',
    newline: '\n'
};

const line = require('fs').readFileSync(config.input, 'utf-8').split(config.newline);

const solve = arr => {
    const helper = (xs, stack) => {
        if (xs.length === 0) return stack[0];
        const hd = xs[0];
        const tl = xs.slice(1);
        if (hd === '+') {
            const snd = stack.pop();
            const fst = stack.pop();
            stack.push(fst + snd);
        } else if (hd === '-') {
            const snd = stack.pop();
            const fst = stack.pop();
            stack.push(fst - snd);
        } else if (hd === '*') {
            const snd = stack.pop();
            const fst = stack.pop();
            stack.push(fst * snd);
        } else {
            stack.push(parseFloat(hd));
        }
        return helper(tl, stack); 
    };

    return helper(arr, []);
};

console.log(solve(line[0].split(' ')));



Measured memory_bytes: 16024
N = int(input())
X = list(map(int,input().split()))

ave = 0
for i in range(N):
    ave += X[i]
ave //= N

ans1,ans2 = 0,0
for i in range(N):
    ans1 += (X[i] - ave)**2
    ans2 += (X[i] - ave-1) ** 2

print(min(ans1,ans2))

Measured memory_bytes: 40536
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip>
using namespace std;
#define int long long

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

    int n,k,r,s,p; cin >> n >> k >> r >> s >> p;
    string t; cin >> t;

    vector<int> score(n);
    int ans = 0;

    for(int i = 0;i < k;i ++){
        if(t.at(i) == 'r') score.at(i) = p;
        if(t.at(i) == 's') score.at(i) = r;
        if(t.at(i) == 'p') score.at(i) = s;
    }
    for(int i = k;i < n;i ++){
        if(t.at(i) == 'r' && !(t.at(i-k) == 'r' && score.at(i-k) > 0)) score.at(i) = p;
        if(t.at(i) == 's' && !(t.at(i-k) == 's' && score.at(i-k) > 0)) score.at(i) = r;
        if(t.at(i) == 'p' && !(t.at(i-k) == 'p' && score.at(i-k) > 0)) score.at(i) = s;
    }

    for(int i = 0;i < n;i ++) ans += score.at(i);

    cout << ans << endl;
}

Measured memory_bytes: 1232
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

int h,w;
vector<string> g;
int dy[]={0,0,1,-1};
int dx[]={1,-1,0,0};
ll bcnt,wcnt;
bool seen[410][410];
void dfs(int y,int x){
  seen[y][x]=1;
  if(g[y][x]=='.') wcnt++;
  if(g[y][x]=='#') bcnt++;
  rep(dir,4){
    int ny=y+dy[dir];
    int nx=x+dx[dir];
    if(ny<0||ny>=h||nx<0||nx>=w) continue;
    if(seen[ny][nx]) continue;
    if(g[y][x]==g[ny][nx]) continue;
    dfs(ny,nx);
  }
}
int main(){
  cin >> h >> w;
  g.resize(h);
  rep(i,h) cin >> g[i];
  ll ans=0;
  rep(i,h)rep(j,w){
    bcnt=0; wcnt=0;
    dfs(i,j);
    ans+=bcnt*wcnt;
  }
  cout << ans << endl;
}

Measured memory_bytes: 15616
#include <bits/stdc++.h>
#define endl '\n'
#define FIO ios_base::sync_with_stdio(0); cin.tie(NULL)
#define pb push_back
#define pii pair<int,int>
#define ll long long int 
#define ui unsigned int
#define pll pair<ll,ll> 
#define mp make_pair
#define f first
#define s second
#define all(x) (x).begin(),(x).end() 
#define SORT(v) sort(all(v))
#define SORTD(v) sort(all(v),greater<int>())
#define SET(a,b) for(ui i=0;i<size(a);++i){a[i]=b;} 
#define test() int t; cin>>t ; while(t--)
#define FOR(i,a,b) for(int i=a;i<b;++i)  
#define cerr if(0)cerr
#define watch(x) cerr<<#x<<" is "<<x<<endl;
#define print(x) cout<<x<<endl
#define printv(v) for(auto i : v){cout<<i<<" ";}cout<<endl;
const ll MOD=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}


//_________________________________________________________________________________

using namespace std;


int main()
{
	FIO;
	
	int n;
	cin>>n;
	
	vector<int> v(n);
	FOR(i,0,n)
	{
		cin>>v[i];
	}
	SORT(v);
	
	cout<<v[n/2]-v[n/2-1];
	


	return 0;

}
	
	





Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int a[100100], max1[100100], m[100100], max2 = -1;
int main(){
    int i, N, T;
    cin>>N>>T;
    for(i=0; i<N; i++) cin>>a[i];
    for(i=N-1; i>=0; i--){
        max1[i] = max(max1[i+1], a[i]);
    }
    for(i=0; i<N; i++){
        m[i] = max1[i] - a[i];
        max2 = max(max2, m[i]);
    }
    int cnt=0;
    for(i=0; i<N; i++){
        if(m[i] == max2){
            cnt++;
        }
    }
    cout<<cnt;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
using ll = long long;

const long long MOD = 998244353;

int main(){
    int N, S;
    std::cin >> N >> S;

    std::vector<int> A;
    for(int i=0; i<N; i++){
        int b; std::cin >> b; A.push_back(b);
    }

    std::vector<std::vector<ll>> dp(N+1, std::vector<ll>(S+1, 0));
    dp[0][0] = 1;
    for (int i=0; i<N; ++i) {
        for (int j=0; j<S+1; ++j) {
            dp[i+1][j] += dp[i][j]*2%MOD;
            if (j+A[i] <= S) {
                dp[i+1][j+A[i]] += dp[i][j]%MOD;
            }
        }
    }

    std::cout << (dp[N][S]+MOD)%MOD;
    return 0;
}


Measured memory_bytes: 73668
#include<bits/stdc++.h>
using namespace std;
long long maxn = 1e6;
vector<int> eratosthenes(){
    std::vector<bool> flag(maxn+1, true);
	flag[0]=flag[1]=false;
    vector<int> res;
	for(long long i=2; i<=maxn; ++i){
	    if(flag[i]){
           res.push_back(i);
           for(long long j=i*i; j<=maxn; j+=i){
             flag[j] = false;
           }    
        }
    }
    

	return res;
}

int main(){
  long long a,b;
  cin>>a>>b;
  long long tmp = __gcd(a,b);
  int res = 1 ;
  int upper = 100;

  vector<int> primes = eratosthenes();

  for(auto j:primes){
    if(tmp%j==0){
      res++;
      while(tmp%j==0){
        tmp/=j;
      }
    }
  }
  if(tmp>1)res++;
  cout<<res<<endl;
  return 0;
}

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

/*
struct Edge
{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
*/
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string S;
    cin >> S;
    if (S.back() == 's') {
        cout << S + "es" << endl;
    } else {
        cout << S + "s" << endl;
    }
    return 0;
}


Measured memory_bytes: 3652
N=int(input())
d={}
for i in range(1,10):
  for j in range(1,10):
    d[i*10+j]=0
for i in range(1,min(10,N+1)):
  d[i*10+i]=1
for i in range(11,N+1):
  i=str(i)
  h,t=int(i[0])*10,int(i[-1])
  if t!=0:
    d[h+t]+=1
ans=0
for i in range(1,9):
  for j in range(i+1,10):
    ans+=(d[i*10+j]*d[j*10+i])*2
for i in range(1,10):
  ans+=d[i*10+i]**2
print(ans)

Measured memory_bytes: 9224
#include<stdio.h>
int main(void)
{
    int a,b;
    scanf("%d %d",&a,&b);
     if(a < b){
    printf("a < b\n");
     }
     else  if(a > b){
    printf("a > b\n");
     }
        else{
            printf("a == b\n");
        }
            
        return 0;
        
}


Measured memory_bytes: 2140
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};



int n;

void solve(){
  int n;cin >> n;
  vector<vector<ll>> L_list(n),R_list(n+1);
  ll ans=0;
  rep(i,n){
    int k,l,r;
    cin >> k >> l >> r;
    if(l>=r){
      ans+=r;
      L_list[k-1].push_back(l-r);
    } 
    else{
      ans+=l;
      R_list[k-1].push_back(r-l);
    } 
  }
  int num_L=L_list.size(),num_R=R_list.size();
  priority_queue<ll> que_L,que_R;
  Rep(i,num_L,n) for(ll s:L_list[i]) que_L.push(s);
  per(i,num_L){
    for(ll s:L_list[i]) que_L.push(s);
    if(que_L.empty()) continue;
    ans+=que_L.top();que_L.pop();
  }
  rep(i,n-num_R) for(ll s:R_list[i]) que_R.push(s);
  Rep(i,n-num_R,n){
    if(i>=1) for(ll s:R_list[i-1]) que_R.push(s);
    if(que_R.empty()) continue;
    ans+=que_R.top();que_R.pop();
  }
  cout << ans << endl;
}

int main(){
  int T;cin >> T;
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(50);
  rep(i,T) solve();
}

Measured memory_bytes: 17468
#include <iostream>
#include <string>

using namespace std;

int main() {
	string s; cin >> s;
	int ans = 0, now = 0;
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] == 'R') now++;
		else now--;
		if (now == 4) ans++, now = 0;
		else if (now == -4) now = 0;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3192
#include<iostream>
#include<math.h>
#include<queue>
#include<map>
using namespace std;
typedef pair<int,int> i_i;
#define mp(a,b) make_pair(a,b)
int main(){
  int n,m;
  cin >> n >> m;
  int step[1<<15];
  int inf = 1<<10;
  fill(step,step+(1<<15),inf);
  int i,j,k,c=0,b=0;
  int in=0;
  int o1=0,o2=0;
  for(i=0;i<n;i++) {
    cin >> k;
    b+=k;
    in=in<<1;
    in+=k;
  }
  /*
  for(i=n-1;i>=0;i--) cout << ((in>>i&1) ? 1:0);
  cout << endl;
  */
  //step[in]=0;
  for(i=0;i<m;i++) {
    cin >> k;
    o1=o1<<k;
    o2=o2<<k;
    if(i%2==0) {
      b+=k;
      o1+=pow(2,k)-1;
    }else{
      o2+=pow(2,k)-1;
    }
  }
  /*
  for(i=0;i<n;i++) cout << ((o1>>i&1) ? 1:0);
  cout << endl;
  for(i=0;i<n;i++) cout << ((o2>>i&1) ? 1:0);
  cout << endl;
  */

  queue<i_i> q;
  i_i x;
  x.first=in;x.second=0;
  q.push(x);
  while(step[o1]==inf&&step[o2]==inf&&!q.empty()){
    x=q.front();
    q.pop();
    /*
    for(i=n-1;i>=0;i--) cout << ((x.first>>i&1) ? 1:0);
    cout << endl;
    */
    if(step[x.first]>x.second){
      step[x.first]=x.second;
      for(i=n-1;i>0;i--){
	if((x.first>>i&1)==(x.first>>(i-1)&1)) continue;
	if((x.first>>i&1))
	  q.push(mp(x.first-pow(2,i)+pow(2,i-1),x.second+1));
	else
	  q.push(mp(x.first+pow(2,i)-pow(2,i-1),x.second+1));
      }
    }
  }
  
  
  cout << min(step[o1],step[o2]) << endl;
  return 0;
}

Measured memory_bytes: 1440
// RUQはある区間のすべての値を更新するクエリ
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int n;
struct RUQ{
  static const int MAX_N = 1 << 18;
  P dat[2*MAX_N-1];
  RUQ(){}
  RUQ(int n_){init(n_);}
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    for(int i=0;i<2*n-1;i++) dat[i].first=-1,dat[i].second=INT_MAX;
  }
  int query(int k){
    k+=n-1;
    P p=dat[k];
    //cout<<k<<"/"<<dat[k].second<<endl;
    while(k>0){
      k=(k-1)/2;
      //cout<<k<<"/"<<dat[k].second<<endl;
      p=max(p,dat[k]);
    }
    return p.second;
  }

  void update(int a,int b,int k,P p,int l,int r){
    if(r<=a||b<=l) return;
    if(a<=l&&r<=b) {
      //cout<<a<<":"<<b<<":"<<k<<":"<<l<<":"<<r<<endl;
       dat[k]=p;
    }else{
      update(a,b,k*2+1,p,l,(l+r)/2);
      update(a,b,k*2+2,p,(l+r)/2,r);
    }
  }
};
signed main(){
  int _n,q;
  cin>>_n>>q;
  RUQ ruq(_n+1);
  for(int i=0;i<q;i++){
    int f;
    cin>>f;
    if(!f){
      int s,t,x;
      cin>>s>>t>>x;
      //cout<<i<<":"<<x<<endl;
      ruq.update(s,t+1,0,P(i,x),0,n);
    }else{
      int u;
      cin>>u;
      cout<<ruq.query(u)<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 11292