akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define F first
#define S second
#define db double
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
using namespace std;

 ll mod=1e9 +7;

ll expo(ll base,ll exponent,ll mod){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
 
vector<bool>  prime(90000002,true);
void Sieve() 
{ 
   
    for (int p=2; p*p<=90000001; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=90000001; i += p) 
                prime[i] = false; 
        } 
    } 
}

ll get_val(vector<ll>&ft,ll index)
{
  ll res=0;
  for(;index>=0;index=(index & (index+1))-1)
    res+=ft[index];
  return res;
}

void update(vector<ll>&ft,ll index,ll val)
{
  for(;index<(ll)ft.size();index|=index+1)
    ft[index]+=val;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //   #ifndef ONLINE_JUDGE
    // // for getting input from input.txt
    // freopen("input.txt", "r", stdin);
    // // for writing output to output.txt
    // freopen("output.txt", "w", stdout);
    // #endif
    
    // Sieve();
   ll tests=1;
 // cin>>tests;
  // ll t=1;
    while(tests--)
    {
      ll i,j,n;
      cin>>n;
      vector<ll>a(n);
      ll sum=0;
      rep(i,0,n-1)
      {
        cin>>a[i];
        sum+=a[i];
      }
      sort(all(a));
      if(sum%10!=0) {cout<<sum;}
      else
      {
        i=0;
        while(i<n && a[i]%10==0) i++;
        if(i>=n) sum=0;
        else sum-=a[i];
        cout<<sum;
      }

    }

    return 0;
   }

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

int main(){
  int a, b, c;
  cin>>a>>b>>c;
  int d = (b/a);
  if(b>=a){
    if(d>c){
      cout<<c;
    }
    else{
      cout<<d;
    }
  }
  else{
    cout<<0;
  }
  return 0;
}


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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
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; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

using Graph = vector<vector<int>>;

typedef pair<int, int> P;
const int MOD = 1000000007;

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

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

    ll ans = 0;
    rep(i,N){
        if (i == 0) ans = A[i];
        else ans = gcd(ans, A[i]);
    }    

    cout << ans << endl;
}



Measured memory_bytes: 3788
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
#include <cstdint>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000000000
#define MAX 200001

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
const ll MOD = 1000000007;

template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    ll N;
    cin >> N;
    vector<ll> xy1;
    vector<ll> xy2;
    rep(i,N){
        ll x,y;
        cin >> x >> y;
        xy1.push_back(x-y);
        xy2.push_back(x+y);
    }
    sort(xy1.begin(), xy1.end());
    sort(xy2.begin(), xy2.end());
    ll ans = max(xy1[xy1.size()-1] - xy1[0],xy2[xy2.size()-1] - xy2[0]);
    cout << ans << endl;
}

Measured memory_bytes: 6616
#include<bits/stdc++.h>
using namespace std;
#define ALL(A) A.begin(),A.end()
const long long mod=1000000007;
int main(){
    int n;
    cin>>n;
    long long a[n+2],pre[n+2],suf[n+2];
    a[0]=0;a[n+1]=0;
    for(int i=1;i<=n;i++)
    cin>>a[i];
    
    pre[0]=0;suf[n+1]=0;
    for(int i=1;i<=n+1;i++)
    pre[i]=pre[i-1]+abs(a[i]-a[i-1]);

    for(int i=n;i>=0;i--)
    suf[i]=suf[i+1]+abs(a[i+1]-a[i]);

    for(int i=1;i<=n;i++)
    {
        cout<<pre[i-1]+suf[i+1]+abs(a[i-1]-a[i+1])<<endl;
    }
    return 0;
}

Measured memory_bytes: 3584
import collections
import heapq

n = int(input())
l = [input() for _ in range(n)]
c = collections.Counter(l)
max_count = 0
ans = []
for word, count in c.most_common():
  if(max_count <= count):
    heapq.heappush(ans, word)
    max_count = count
  else:
    break
for _ in range(len(ans)):
  print(heapq.heappop(ans))

Measured memory_bytes: 45040
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b,n;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>a>>b>>n;
	n=min(n,b-1);
	cout<<floor(a*n/b)-a*floor(n/b);
	return 0;
}

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

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    int ans = A + B + C;
    if(ans >= 22){
        cout << "bust" << '\n';
    }else{
        cout << "win" << '\n';
    }
    return 0;
}

Measured memory_bytes: 3600
a1_list = list(map(int, input().split()))
a2_list = list(map(int, input().split()))
a3_list = list(map(int, input().split()))
n = int(input())
for i in range(n):
    b = int(input())
    for j in range(3):
        if a1_list[j] == b:
            a1_list[j] = 0
        if a2_list[j] == b:
            a2_list[j] = 0
        if a3_list[j] == b:
            a3_list[j] = 0
bingo = False
yoko = [0] * 3
tate = [0] * 3
for j in range(3):
    if(a1_list[j] == 0):
        tate[j] += 1
        yoko[0] += 1
        if tate[j] == 3 or yoko[0] == 3:
            bingo = True
            break
    if(a2_list[j] == 0):
        tate[j] += 1
        yoko[1] += 1
        if tate[j] == 3 or yoko[1] == 3:
            bingo = True
            break
    if(a3_list[j] == 0):
        tate[j] += 1
        yoko[2] += 1
        if tate[j] == 3 or yoko[2] == 3:
            bingo = True
            break
if bingo:
    print("Yes")
else:
    if(a1_list[0] == 0 and a2_list[1] == 0 and a3_list[2] == 0):
        print("Yes")
    elif(a1_list[2] == 0 and a2_list[1] == 0 and a3_list[0] == 0):
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 3064
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

#include <bits/stdc++.h>
using namespace std;

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(long long i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(long long i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#define fi first
#define se second
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using Int = long long;
using ll = long long;
using P = pair<Int,Int>;
using vi = vector<Int>;
using vvi = vector<vi>;
using vp = vector<P>;
using vvp = vector<vp>;

const Int INF = (1LL<<50);


void solve(long long N, long long K){
  Int x = N %K;
  cout << min(x, K-x) << endl;
}

int main(){
  std::cout << std::fixed << std::setprecision(15);
  long long N;
  scanf("%lld",&N);
  long long K;
  scanf("%lld",&K);
  solve(N, K);
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int i,su,n,j;
	char seg[10][7]={"0111111","0000110","1011011","1001111","1100110","1101101","1111101","0100111","1111111","1101111"};
	char current[7];	

	while(1){
		for(i=0;i<7;i++) current[i]='0';
		scanf("%d",&su);
		if(su==-1) break;
		for(i=0;i<su;i++){
			scanf("%d",&n);
			for(j=0;j<7;j++){
				if(current[j]==seg[n][j]) printf("0");
				else printf("1");
				current[j]=seg[n][j];
			}
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 572
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
const ld pi = 3.14159265358979323846;
const ll mod = 1000000007;
const ll inf = 1LL << 60;
 
int main() {
    ll n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n){
        cin>>a[i];
    }
    vector<ll> s(n+1, 0); //累積和
    rep(i,n){
        s[i+1]=s[i]+a[i];
    }
    ll ans=0;
    rep(i,n-1){
        ll sum=(s[n]-s[i+1])%mod;
        ans+=a[i]*sum;
        ans%=mod;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6376
#include <iostream>
#include <cstring>

const int MAXN = 3002;
const int P = 998244353;

int a[MAXN];
int64_t f[MAXN][MAXN];

int64_t solve(int n, int sum) {
  memset(f, 0, sizeof(f));
  int64_t ans = 0;
  for (int i = n; i > 0; --i) {
    if (sum > a[i]) ans += i * f[i + 1][sum - a[i]];
    else if (sum == a[i]) ans += i * (n + 1 - i);
    if (ans >= P) ans %= P;

    for (int j = 1; j <= sum; ++j) {
      f[i][j] = f[i + 1][j];
      if (j >= a[i]) f[i][j] += f[i + 1][j - a[i]];
      if (f[i][j] >= P) f[i][j] %= P;
    }
    f[i][a[i]] += n + 1 - i;
  }
  return ans;
}

int main() {
  int n, sum;
  std::cin >> n >> sum;
  for (int i = 1; i <= n; ++i) std::cin >> a[i];
  std::cout << solve(n, sum) << std::endl;
  return 0;
}


Measured memory_bytes: 70784
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	a := nextInts(n + 1)
	b := nextInts(n)

	ans := 0
	for i := 0; i < n; i++ {
		if a[i] >= b[i] {
			ans += b[i]
			a[i] -= b[i]
		} else {
			ans += a[i]
			b[i] -= a[i]
			if a[i+1] >= b[i] {
				ans += b[i]
				a[i+1] -= b[i]
			} else {
				ans += a[i+1]
				a[i+1] = 0
			}
		}
	}
	puts(ans)
	wt.Flush()
}

var (
	sc  = bufio.NewScanner(os.Stdin)
	rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	wt  = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func nextMega() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, _ := rdr.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


Measured memory_bytes: 4480
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	int n; double a, b = 0; cin >> n;
	for (int h = 0; h < n; h++) {
		cin >> a;
		b += 1 / a;
	}
	cout << 1 / b << endl;
	cin >> n;
}


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

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

  if(n % 2 == 0) cout << ((double)(n) / (double)(2)) / (double)(n);
  else cout << (double)((n + 1) / 2) / (double)(n);
}

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

bool f(int x){
    return x % 2 == 1;
}

int main(){
    ll cnt = 0;
    int x, y, z; x = y = z = 0;
    int a, b, c; cin >> a >> b >> c;

    for(;;){
        if(f(a) || f(b) || f(c)){ break; }

        y = a / 2; z = a / 2;
        x = b / 2; z += b / 2;
        x += c / 2; y += c / 2;

        if(x == a && y == b && z ==c){
            cout << -1 << endl;
            exit(0);
        }

        a = x; b = y; c = z;
        cnt++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  ll sum=0;
  ll ans=0;
  REP(i,n){
    ll a;
    cin >> a;
    if(a==0){
      ans += sum/2;
      sum = 0;
    }else{
      sum += a;
    }
  }
  if(sum>0) ans += sum/2;
  cout << ans << '\n'; 
  return 0;
}


Measured memory_bytes: 256
use std::str::FromStr;

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

fn get_vec<T : FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
}

fn get_vec_by_lines<T : FromStr>(n : usize) -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for _i in 0..n {
        let x : T = get_one();
        v.push(x);
    }
    return v;
}

fn dfs(v : &Vec<(i64,i64)>, cur : usize, till : i64) -> (i64, usize) {
    //println!("{} {} {:?}", cur, till, v[cur]);
    if cur >= v.len() || v[cur].0 > till {
        return (1,cur);
    }
    let mut x = cur+1;
    let mut clsans = 1;
    while x < v.len() && v[x].0 < v[cur].0+v[cur].1 {
        //println!("   {} {:?}", x, v[x]);
        let (lans, next) = dfs(v,x,v[x].0 + v[x].1);
        x = next;
        clsans *= lans;
        clsans %= 998244353;
    }
    return (1+clsans, x);
}

fn main() {
    let n : usize = get_one();

    let mut v : Vec<(i64, i64)> = Vec::new();
    for i in 0..n {
        let xd : Vec<i64> = get_vec();
        v.push((xd[0],xd[1]));
    }

    v.sort();
    let mut next = 0;
    let mut ans = 1;
    while next < v.len() {
        let (lans, lnext) = dfs(&v, next, v[next].0+1);
        next = lnext;
        ans *= lans;
        ans %= 998244353;
    }

    println!("{}", ans);
}


Measured memory_bytes: 24900
#include <bits/stdc++.h>
#define ull uint64_t
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mx5 100005
#define mx52 200005
#define mx6 1000005
#define mod 1000000007
#define nfs ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

struct Line {
    ll m, c;
    double intersect(const Line& b) {
        return ((double)(c - b.c)) / (b.m - m);
    }

    ll eval(int x) {
        return m*x + c;
    }
};

Line getLine(ll dpi, ll hi) {
    return {-2*hi, hi*hi + dpi};
}

int main() {
    nfs
    int i, j, n;
    ll c, h[mx52];
    
    cin >> n >> c;
    for (i = 0; i < n; i++) {
        cin >> h[i];
    }
    
    ll dp[n] = {};
    deque <Line> options(1, getLine(dp[0], h[0]));
    for (int i = 1; i < n; i++) {
        while (options.size() > 1 && options[0].intersect(options[1]) < h[i])
            options.pop_front();
        dp[i] = options[0].eval(h[i]) + h[i]*h[i] + c;
        Line newLine = getLine(dp[i], h[i]);
        int li = options.size() - 1;
        while (li and options[li].intersect(options[li - 1]) >= options[li].intersect(newLine)) {
            options.pop_back();
            li--;
        }
        options.push_back(newLine);
    }
    cout << dp[n - 1];
}

Measured memory_bytes: 8280
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
using namespace std;
using ll = long long;
int main(){
    int a,b,w;
    cin >> w >> a >> b;
    int A,B;
    A = min(a,b);
    B = max(a,b);
    cout << max((B-(A+w)),0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#pragma warning (disable:4996)

int main() {
	int N, A;
	(void)scanf("%d%d", &N, &A);

	int count, n;
	if (A % 2 == 0)count = 0;
	else count = 1;
	if (N % 2 == 0)n = N / 2 - 1;
	else n = (N - 1) / 2;

	for (int i = 0; i < n; i++) {
		(void)scanf("%*d%d", &A);
		if (A % 2 == 1)count++;
	}

	printf("%d", count);
}

Measured memory_bytes: 1732
#include <iostream>
#include <vector>
#include <algorithm>

int main(int argc, char* argv[])
{
  int N, K;
  std::cin >> N >> K;

  std::vector<int> s;

  for (int i = 0; i < N; i++) {
    int a;
    std::cin >> a;
    s.push_back(a);
  }

  std::sort(s.begin(), s.end(), std::greater<int>());
  uint32_t count = 0;

  for (int i = 0; i < s.size(); i++) {
    if (s[i] >= K) {
      count++;
    } else {
      break;
    }
  }
  std::cout << count << std::endl;
}

Measured memory_bytes: 892
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iterator>
#include <fstream>
#include <math.h>

#include <random>
#include <vector>
#include <string>
#include <stack>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <list>
#include <bitset>
#include <unordered_set>
#include <unordered_map>

#include <random>
#include <ctime>

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define FOR(i, from, to) for (int i = from; i < to; i++)
#define ROF(i, from, to) for (int i = from; i > to; i--)

const long double PI = 3.141592653589793238463;
const int INF = 0x3f3f3f3f;
const int INFS = 1000000000;
const ll M = 1000000007;
const ll LLINF = 1000000000000000000;
const double EPS = 1e-8;

#define int long long

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, t;
    cin >> n >> t;
    vector<int> a(n);
    FOR(i, 0, n) {
        cin >> a[i];
    }
    int mn = a[0], mx = 0;
    vector<int> res(n);
    res[0] = 0;
    FOR(i, 1, n) {
        res[i] = a[i] - mn;
        if (a[i] < mn)
            mn = a[i];
        mx = max(mx, res[i]);
    }
    int ans = 0;
    FOR(i, 0, n) {
        if (res[i] == mx)
            ++ans;
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 4772
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s,t;
  	cin>>s>>t;
  int count=0;
  for(int i=0;i<s.size();i++)
    if(s[i]!=t[i])
      count++;
  cout<<count;
  return 0;
}

Measured memory_bytes: 3848
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;
#define RET(ans) {cout<<ans<<endl;return 0;} 

    // 二次元ベクターの基本
    /*
    vector<vector<int>> dp; // 宣言
    dp.resize(n); // 1次元めの要素数決定
    dp[i].push_back(int); // プッシュバック
    rep(i,n){
        sort(dp[i].begin(),dp[i].end()); // 二次元めを昇順ソート
    }
    */

    // 整数スキャン（複数）
    /*
    int x,y,z;
    scanf("%d%d%d",&x,&y,&z);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s; cin >> s;
    */

    // n個の文字列スキャン
    /*
    vector<string> slist;
    rep(i,n){
        string s; cin >> s;
        slist.push_back(s);
    }
    */

int main() {
    int n,m,c;
    cin >> n >> m >> c;
    int b[m];
    rep(i,m){
        cin >> b[i];
    }


    ll ans = 0;
    rep(i,n){
        int a[m];
        rep(i,m){
            cin >> a[i];
        }
        int calc = 0;
        rep(i,m){
            calc += a[i]*b[i];
        }
        calc += c;
        if(calc>0)ans++;
    }
    
    cout << ans << endl;
    return 0;
}
 
 


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

int main()
{
  vector<string> C(3);
  for (int i = 0; i < 3; i++)
    cin >> C.at(i);

  cout << C.at(0).at(0) << C.at(1).at(1) << C.at(2).at(2) << endl;
}


Measured memory_bytes: 3596
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;
int main() {
	string s;
	getline(cin, s);
	bool flag = false;
	int n = s.length();
	for (int i = 0; i < n; i++) {
		if (s[i] == 'C') {
			for (int j = i; j < n; j++) {
				if (s[j] == 'F') {
					cout << "Yes";
					return 0;
				}
			}
		}
	}
	cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int N; cin >> N;
  int a[N]; rep(i, N) cin >> a[i];
  sort(a, a+N);
  int result = a[N-1] - a[0];
  cout << result << endl;
  return 0;
}

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

#define pb push_back
#define mp make_pair
#define all(n) (n).begin(),(n).end()
#define fi first
#define se second

typedef pair<int, int> PII;
typedef long long ll;

const int MOD = 1e9+7;
const int MAXN = 200000;
int n,m,v[MAXN];
vector<int> ed[MAXN];

int dfs(int k) {
	if (v[k]) return 0;
	int ret = 1;
	v[k]=1;
	for (int i : ed[k]) ret+=dfs(i);
	return ret;
}
int main() {

	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> m;
	for (int i=0;i<m;i++) {
		int a,b;
		cin >> a >> b;
		ed[--a].pb(--b);
		ed[b].pb(a);
	}
	int ans = 0;
	for (int i=0;i<n;i++) {
		ans = max(ans,dfs(i));
	}
	cout << ans << "\n";
}

Measured memory_bytes: 21476
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;

int main() {
	int N ;
	cin >> N;
	vector<LL> A,B;
	LL sum = 0;
	for(int i=0; i<N; i++) {
		LL p,q;
		cin >> p >> q;
		A.push_back(p);
		B.push_back(q);
	}
	
	for(int i=0; i<N; i++) {
//		LL p,q;
//		cin >> p >> q;
		LL p = A[N-1-i];
		LL q = B[N-1-i];
		LL k = ((p+sum)%q);
		if(k == 0);
		else sum += q-k;
	}
	cout << sum << endl;
	return 0;
}



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

int main(){
  int n;
  cin>>n;
  vector<int> a;
  for(int i=0;i<n;i++){
    int x;
    cin>>x;
	a.push_back(x);
  }
  long long sum=0;
  int memory = a[0];
  for(int i=1;i<n;i++){
    if(a[i]>memory){
      memory = a[i];
    }
    else{
      sum+=memory-a[i];
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 4328
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;

int main()
{
    char x,y;

    while(scanf("%c %c",&x,&y) != EOF)
    {
        getchar();
        if(x < y) printf("<\n");
        else if(x > y) printf(">\n");
        else printf("=\n");
    }

    return 0;
}




Measured memory_bytes: 256
N,M,Q = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(Q)]

ans = 0
for i in range(2**(N+M-1)):
    cnt = 0
    mm = bin(i)
    for j in list(str(mm)):
        if j=="1":
            cnt += 1
    if cnt != M-1:
        continue
    
    li = [0]
    mm2 = 1
    for j in range(N+M-1):
        if (i>>j)&1:
            mm2 += 1
        else:
            li.append(mm2)
    
    ttl = 0
    for j in range(Q):
        a,b,c,d = ab[j]
        if li[b]-li[a]==c:
            ttl += d
    ans = max(ans,ttl)
    # if ans == ttl:
    # print(mm,li)

print(ans)

    
        
    



Measured memory_bytes: 79740
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0168

"""
import sys
from sys import stdin
from math import ceil
input = stdin.readline


def solve(n):
    dp = [[0] * (n+1) for _ in range(n+1)]
    for i in range(min(n+1, 4)):
        dp[0][i] = 1

    for i in range(1, n+1):
        for j in range(n+1):
            if j <= i:
                dp[i][j] = 0
            else:
                t = 0
                for k in range(1, min(j, 4)):
                    t += dp[i-1][j-k]
                dp[i][j] = t

    total = 0
    for d in dp:
        total += d[-1]
    return total


def main(args):
    while True:
        n = int(input())
        if n == 0:
            break

        result = solve(n)
        print(ceil(result / 365 / 10))


if __name__ == '__main__':
    main(sys.argv[1:])
    

Measured memory_bytes: 7800
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    int m,d;
    scanf("%d%d", &m, &d);

    int cnt=0;
    int i;
    for(i=22; i<=d; i++) {
        int d0=i/10;
        int d1=i%10;
        if(d0>1 && d1>1 && d0*d1<=m) {
            //printf("%d %d %d\n", d0,d1,m);
            cnt++;
        }
    }
    printf("%d\n", cnt);



    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int N, S;
    vector<int> L(100);
    S = 0;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> L[i];
    }

    for (int i = 0; i < N - 2; i++)
    {
        for (int j = i + 1; j < N - 1; j++)
        {
            for (int k = j + 1; k < N; k++)
            {
                if (L[i] != L[j] && L[j] != L[k] && L[k] != L[i])
                {
                    if (L[i] + L[j] > L[k] && L[j] + L[k] > L[i] && L[k] + L[i] > L[j])
                    {
                        S++;
                        //cout << L[i] << L[j] << L[k] << endl;
                    }
                }
            }
        }
    }

    cout << S << endl;
    return 0;
}

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

using namespace std;

int main(){

    long long N;
    cin>>N;
    string S;
    cin>>S;
    long long R=0,B=0;


    for(auto &x:S){
        if(x=='R')R++;
        else{
            B++;
        }

    }


    if(R>B)cout<<"Yes"<<endl;
    else{
        cout<<"No"<<endl;
    }
    
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        StringBuilder pattern1 = new StringBuilder();
        StringBuilder pattern2 = new StringBuilder();
        for(int i = 0 ; i < s.length(); i++){
            if(i % 2 == 0){
                pattern1.append("1");
                pattern2.append("0");
            }else{
                pattern1.append("0");
                pattern2.append("1");
            }
        }
        String pattern1_str = pattern1.toString();
        String pattern2_str = pattern2.toString();
        int pat1 =0;
        int pat2 =0;
        for(int i = 0 ; i < s.length(); i++){
            if(s.charAt(i) == pattern1_str.charAt(i)){
                pat1 += 1;
            }else{
                pat2 += 1;
            }
        }
        if(pat1 >= pat2){
            System.out.println(pat2);
        }else{
            System.out.println(pat1);
        }
    }
}

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

int main(){
	int a, b,c,d;
cin >> a >> b >> c >> d;
if(a + b < c + d)cout << "Right" << endl;
else if(a + b == c + d)cout << "Balanced" << endl;
else cout << "Left" << endl;
return 0;
}


Measured memory_bytes: 256
#include<ctype.h>
char*w,W[101],*p;
t;
main(c){
	for(;scanf("%s%s",W,&t),t!='X';){
		w=W;
		for(;*w;){
			for(p=w+1;*p&&*p!='_'&&!isupper(*p);p++);
			switch(t){
			case 'U':
				putchar(toupper(*w));
				w++;
				break;
			case 'L':
				if(w==W)
					putchar(tolower(*w));
				else
					putchar(toupper(*w));
				w++;
				break;
			case 'D':
				if(w!=W)
					putchar('_');
				break;
			}
			for(;w<p;w++)
				putchar(tolower(*w));
			if(*w=='_')
				w++;
		}
		puts("");
	}
	exit(0);
}

Measured memory_bytes: 0
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <numeric>
 
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
string S;
ll N;
ll ans;
ll M = 1000000000;


int main() {
    cin >> S;
    if(S[0]=='R'){
        if(S[1]=='R'){
            if(S[2]=='R'){
                cout << 3 << endl;
            }else{
                cout << 2 << endl;
            }
        }else{
            cout << 1 << endl;
        }
    }else{
        if(S[1]=='R'){
            if(S[2]=='R'){
                cout << 2 << endl;
            }else{
                cout << 1 << endl;
            }
        }else{
            if(S[2]=='R'){
                cout << 1 << endl;
            }else{
                cout << 0 << endl;
            }
        }
    }
}


Measured memory_bytes: 3672
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int n;
pair<int,int>a[200001];
int ans[200001];
int main(){
	ios::sync_with_stdio(false);
	cin >> n;
	for(int i=1; i<=n ;i++){
		cin >> a[i].first;
		a[i].second=i;
	}
	sort(a+1,a+n+1);
	for(int i=1; i<=n/2 ;i++) ans[a[i].second]=a[n/2+1].first;
	for(int i=n/2+1; i<=n ;i++) ans[a[i].second]=a[n/2].first;
	for(int i=1; i<=n ;i++) cout << ans[i] << endl;
}

Measured memory_bytes: 4608
from bisect import bisect_left


LARGE = 998244353


class SegmentTree(object):

    def __init__(self, init_array, seg_func=min, seg_func_null=10 ** 9 + 7):

        self.seg_func = seg_func
        self.seg_func_null = seg_func_null
        self.n = 1
        while self.n < len(init_array):
            self.n *= 2
        self.dat = [0] * (2 * self.n - 1)
        for i in range(len(init_array)):
            self.dat[self.n - 1 + i] = init_array[i]
        for i in range(self.n - 2, -1, -1):
            self.dat[i] = self.seg_func(self.dat[2 * i + 1], self.dat[2 * i + 2])

    def update(self, k, a):
        k += self.n - 1
        self.dat[k] = a
        while k > 0:
            k = (k - 1) // 2
            self.dat[k] = self.seg_func(self.dat[k * 2 + 1], self.dat[k * 2 + 2])

    def query(self, p, q):
        # [p, q)
        if q <= p:
            return self.seg_func_null

        p += self.n - 1
        q += self.n - 2
        res = self.seg_func_null

        while q - p > 1:
            if p & 1 == 0:
                res = self.seg_func(res, self.dat[p])
            if q & 1 == 1:
                res = self.seg_func(res, self.dat[q])
                q -= 1
            p = p // 2
            q = (q-1) // 2
        if p == q:
            res = self.seg_func(res, self.dat[p])
        else:
            res = self.seg_func(self.seg_func(res, self.dat[p]), self.dat[q])

        return res


def solve(n, x_list, d_list):
    reach_right = [0] * n
    reach_right[-1] = n - 1
    # from right
    seg = SegmentTree(list(range(n)), max, -1)
    for i in range(n - 2, -1, -1):
        j = bisect_left(x_list, x_list[i] + d_list[i])
        k = seg.query(i, j)
        seg.update(i, k)
        reach_right[i] = k
    # dp
    dp = [[0] * 2 for _ in range(n)]
    dp[n - 1][0] = 1
    dp[n - 1][1] = 1
    for i in range(n - 2, -1, -1):
        dp[i][0] = (dp[i + 1][0] + dp[i + 1][1]) % LARGE
        j = reach_right[i] + 1
        if j <= n - 1:
            dp[i][1] = (dp[j][0] + dp[j][1]) % LARGE
        else:
            dp[i][1] = 1

    return (dp[0][0] + dp[0][1]) % LARGE


def main():
    n = int(input())
    xd_list = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: x[0])
    x_list = [xd[0] for xd in xd_list]
    d_list = [xd[1] for xd in xd_list]
    res = solve(n, x_list, d_list)
    print(res)


def test():
    assert solve(2, [1, 3], [5, 3]) == 3
    assert solve(3, [-1, 3, 6], [10, 3, 5]) == 5
    assert solve(4, [-10, -4, 4, 7], [3, 3, 3, 10]) == 16


if __name__ == "__main__":
    test()
    main()


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

int main() {
  int N; cin >> N;
  int A[N]; for (int i = 0; i < N; i++) cin >> A[i];
  bool flag = false;
  for (int i = 0; i < N; i++){
    if (A[i] % 2 == 0 && (A[i] % 3 != 0 && A[i] % 5 != 0)) flag = true;
  }
  if (flag == false) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = (a), i##_end_ = (b); i <= i##_end_; ++i)
#define drep(i, a, b) for(int i = (a), i##_end_ = (b); i >= i##_end_; --i)
#define clar(a, b) memset((a), (b), sizeof(a))
#define debug(...) fprintf(stderr, __VA_ARGS__)
typedef long long LL;
typedef long double LD;
const int BUF_SIZE = (int)1e6 + 10;
struct fastIO {
	char buf[BUF_SIZE], buf1[BUF_SIZE];
	int cur, cur1; FILE *in, *out;
	fastIO() { cur = BUF_SIZE, in = stdin, out = stdout; cur1 = 0; }
	inline char getchar() { if(cur == BUF_SIZE) fread(buf, BUF_SIZE, 1, in), cur = 0; return *(buf + (cur++)); }
	inline void putchar(char ch) { *(buf1 + (cur1++)) = ch; if (cur1 == BUF_SIZE) fwrite(buf1, BUF_SIZE, 1, out), cur1 = 0; } inline int flush() { if (cur1 > 0) fwrite(buf1, cur1, 1, out); return cur1 = 0; }
}IO;
#define getchar IO.getchar
#define putchar IO.putchar
LL read() {
	char ch = getchar();
	LL x = 0, flag = 1;
	for (;!isdigit(ch); ch = getchar()) if (ch == '-') flag *= -1;
	for (;isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
	return x * flag;
}
void write(LL x) {
	if (x < 0) putchar('-'), x = -x;
	if (x >= 10) write(x / 10);
	putchar(x % 10 + 48);
}

const int Maxn = 4009, Mod = 1e9 + 7;
int n, k, fac[Maxn * Maxn / 4], invFac[Maxn * Maxn / 4];

LL fpm(LL base, LL tims) {
	LL r = 1;
	while (tims) {
		if (tims & 1) r = r * 1ll * base % Mod;
		base = base * 1ll * base % Mod;
		tims >>= 1;
	}
	return r;
}

void init() {
	n = read(), k = read();
	fac[0] = 1;
	rep (i, 1, n * k) fac[i] = fac[i - 1] * 1ll * i % Mod;
	invFac[n * k] = fpm(fac[n * k], Mod - 2);
	drep (i, n * k - 1, 0) invFac[i] = invFac[i + 1] * (i + 1ll) % Mod;
}

LL C(int n, int m) {
	if (n < m) return 0;
	return 1ll * fac[n] * invFac[m] % Mod * invFac[n - m] % Mod;
}

LL dp[Maxn][Maxn];
void solve() {
	if (k == 1) {
		puts("1");
		return ;
	}
	dp[0][0] = 1;
	rep (i, 0, n)
		rep (j, 0, i) {
			(dp[i + 1][j] += dp[i][j]) %= Mod;
			(dp[i][j + 1] += dp[i][j] * 1ll * C(n * k - i - j * (k - 1) - 1, k - 2) % Mod) %= Mod;
		}
	cout << 1ll * dp[n][n] * fac[n] % Mod << endl;
}

int main() {
//	freopen("bosky.in", "r", stdin);
//	freopen("bosky.out", "w", stdout);

	init();
	solve();

#ifdef Qrsikno
	debug("\nRunning time: %.3lf(s)\n", clock() * 1.0 / CLOCKS_PER_SEC);
#endif
	return IO.flush();
}



Measured memory_bytes: 94720
n,W = map(int,input().split())
w = [0]*n ; v = [0]*n
for i in range(n) :
    w[i],v[i] = map(int,input().split())
max_v = max(v)


# dp[i][j] = i番目までの荷物をいくつか選んで価値をjぴったりにしたときの重さの最小値
dp = [[10**18]*(n*max_v+1) for i in range(n)]
# 価値を0ぴったりにする重さの最小値は0
for i in range(n) :
    dp[i][0] = 0

for i in range(n) :
    for j in range(n*max_v+1) :
        if j-v[i] >= 0 : # i番目の荷物を選んで価値をjぴったりにできる場合
            dp[i][j] = min(dp[i][j], dp[i-1][j-v[i]]+w[i])
        dp[i][j] = min(dp[i][j], dp[i-1][j])

for j in range(n*max_v,-1,-1) :
    if dp[n-1][j] <= W :
        print(j)
        break

Measured memory_bytes: 120940
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

ll mpow(ll x,ll n);
int main(void);

ll mpow(ll x, ll n){
    ll ans = 1;
    while(n>=1){
        if(n%2 == 0){
            x = x * x %MOD;
            n = n/2;
        }else{
            ans = ans * x %MOD;
            n = n-1;
        }
    }
    
    return ans;
}
 

int main(void){
    ll N, K;
    cin >> N >> K;
    vector<ll> A, Asort;
    rep(i,N){
        ll a;
        cin >> a;
        A.push_back(a);
        Asort.push_back(a);
    }

    sort(all(Asort));

    // ll B[N], C[N];
    ll sum1 = 0;
    ll sum2 = 0;
    ll ans = 0;

    reps(i,N){
        ll sum1 = 0;
        rep(j,i){
            if(A[N-i] > A[N-i+j]){
                sum1++;
            }
        }
        ans += sum1 % MOD * K % MOD;
        ans = ans % MOD;
        //B[N-i] = sum;
    }

    rep(i,N){
        ll sum2 = 0;
        ll j = 0;
        while(A[i] > Asort[j]){
            sum2++;
            j++;
        }
        ans += sum2 % MOD * (K-1) % MOD * K % MOD * mpow(2,MOD-2) % MOD;
        ans = ans % MOD;
        //C[i] = sum;
    }

    // ll ans = sum1*K % MOD + sum2 * (K-1) % MOD * K * mpow(2,MOD-2) % MOD;

    /* rep(i,N){
        cout << Asort[i] << endl;
    } */

    cout << ans << endl;

    
	
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define PI 3.14159265358979323846264
#define pii pair <int, int>
#define pipii pair <int, pair <int, int> > 
#define piipi pair <pair <int, int>, int>
#define pb push_back
#define mp make_pair
#define vi vector <int>
#define vl vector <long long>
#define vpii vector <pair <int, int> >
#define ll long long
#define fi first
#define se second
#define FOR(i, x, y) for (int i=x; i<=y; i++)
#define FORD(i, y, x) for (int i=y; i>=x; i--)
#define debug printf("OK\n")
int n;
string s;
int cl[100005], cr[100005];
int ans[100005];
int main() {
    cin >> s;
    n = s.length();
    for (int i=0; i<n; i++) {
        if (s[i] == 'R') cr[i] = i;
        else cr[i] = cr[i-1];
    }
    for (int i=n-1; i>=0; i--) {
        if (s[i] == 'L') cl[i] = i;
        else cl[i] = cl[i+1];
    }
    for (int i=0; i<n; i++) {
        if (s[i] == 'L') {
            int d = i - cr[i];
            if (d % 2 == 0) {
                ans[cr[i]]++;
            } else {
                ans[cr[i] + 1]++;
            }
        } else {
            int d = cl[i] - i;
            if (d % 2 == 0) {
                ans[cl[i]]++;
            } else {
                ans[cl[i] - 1]++;
            }
        }
    }
    for (int i=0; i<n; i++) {
        printf("%d%c", ans[i], i==n-1?'\n':' ');
    }
    return 0;
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    
    int a, b; cin >> a >> b;
    if (b % a == 0) {
        cout << a + b << '\n';
    } else {
        cout << b - a << '\n';
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
const int SIZE = 4000005;
const int INF = 1e9;
set<pair<int, char>> x[SIZE], y[SIZE], xy[SIZE], yx[SIZE];
int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int n; cin >> n;
   rep(i,n){
      int xi, yi;
      char ui; 
      cin >> xi >> yi >> ui;
      xi*=10; yi*=10;
      x[xi].insert({yi, ui});
      y[yi].insert({xi, ui});
      xy[xi+yi].insert({xi, ui});
      yx[xi-yi+2000000].insert({xi, ui});
   }
   int ans = INF;
   rep(i,SIZE){
      for(set<pair<int, char>>::iterator itr=x[i].begin(); itr != x[i].end(); itr++){
         set<pair<int, char>>::iterator itr_new = itr;
         itr_new++;
         if (itr_new == x[i].end())break;
         if (itr->second == 'U' && itr_new->second == 'D')ans = min(ans, (itr_new->first - itr->first)/2);
      }
      for(set<pair<int, char>>::iterator itr=y[i].begin(); itr != y[i].end(); itr++){
         set<pair<int, char>>::iterator itr_new = itr;
         itr_new++;
         if (itr_new == y[i].end())break;
         if (itr->second == 'R' && itr_new->second == 'L')ans = min(ans, (itr_new->first - itr->first)/2);
      }
      for(set<pair<int, char>>::iterator itr=xy[i].begin(); itr != xy[i].end(); itr++){
         set<pair<int, char>>::iterator itr_new = itr;
         itr_new++;
         if (itr_new == xy[i].end())break;
         if (itr->second == 'R' && itr_new->second == 'U')ans = min(ans, itr_new->first - itr->first);
         if (itr->second == 'D' && itr_new->second == 'L')ans = min(ans, itr_new->first - itr->first);
      }
      for(set<pair<int, char>>::iterator itr=yx[i].begin(); itr != yx[i].end(); itr++){
         set<pair<int, char>>::iterator itr_new = itr;
         itr_new++;
         if (itr_new == yx[i].end())break;
         if (itr->second == 'R' && itr_new->second == 'D')ans = min(ans, itr_new->first - itr->first);
         if (itr->second == 'U' && itr_new->second == 'L')ans = min(ans, itr_new->first - itr->first);
      }
   }
   if (ans==INF)cout << "SAFE" << endl;
   else cout << ans << endl;
}

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

n = int(input())

# for i in range(1, 10**9):
#     if i % 2 == 0 and i % n == 0:
#         print(i)
#         break

if n % 2 == 0:
    print(n) 
else:
    print(2*n)


Measured memory_bytes: 2940
N,T = gets.chomp.split(" ").map(&:to_i)
c,t = N.times.map{gets.split.map(&:to_i)}.transpose
min = 10000
N.times do |i|
  if T >= t[i]
    min = [min,c[i]].min
  end
end
if min == 10000
  puts "TLE"
else
  puts min
end


Measured memory_bytes: 14372
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = (a); i < (b); ++i) 

int main()
{
    int R, G, B, N;
    cin >> R >> G >> B >> N;
    ll cnt = 0;
    for(int r = 0; N - r*R >= 0; ++r) 
        for(int g = 0; N - r*R - g*G >= 0; ++g) {
            if((N - r*R - g*G)%B == 0) ++cnt;
        }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
using namespace std;


int main(){
  int m;
  cin>>m;
  while(m--){
    int g[5][5];
    for(int y=0;y<5;y++){
      for(int x=0;x<5;x++){
	cin>>g[y][x];
      }
    }
    int ans=0;
    for(int l=0;l<5;l++){
      for(int r=l;r<5;r++){
	for(int t=0;t<5;t++){
	  for(int b=t;b<5;b++){
	    int f=1;
	    int c=0;
	    for(int y=l;y<=r;y++){
	      for(int x=t;x<=b;x++){
		f&=g[y][x];
		c++;
	      }
	    }
	    if(f&&ans<c){
	      ans=c;
	    }
	  }
	}
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}
 

Measured memory_bytes: 1160
#include<iostream>

using namespace std;

int main(){
    int n;
    long long int T, t[200009], ans=0;
    cin >> n >> T;
    for(int i=0;i<n;i++)cin >> t[i];
    for(int i=0;i<n-1;i++){
        ans+=min(T, t[i+1]-t[i]);
    }
    cout << ans+T << endl;
}

Measured memory_bytes: 1792
#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(){
  std::string s;
  std::cin >> s;
  int K;
  scanf("%d", &K);
  int n = s.length();
  std::vector<std::string > vec;
  for (int i=0; i<n; i++){
    std::string moji;
    //std::cout << "S[" << i << "]=" << s[i] << std::endl;
    //std::cout << "moji=" << moji << std::endl;
    for (int j=i; j<std::min(i+6,n); j++){
      moji += s[j];
      //std::cout << "Sj[" << j << "]=" << s[j] << std::endl;
      vec.push_back(moji);
      //std::cout << "moji=" << moji << std::endl;
    }
  }
  std::sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  //printf("size=%lu\n", vec.size());
  std::cout << vec[K-1] << std::endl;
  return 0;
}


Measured memory_bytes: 1160