akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int h,w;
    cin>>h>>w;
    vector<vector<int>> a(h,vector<int>(w));
    rep(i,h)rep(j,w) cin>>a[i][j];
    rep(i,h)rep(j,w){
        int x;
        cin>>x;
        a[i][j]=abs(a[i][j]-x);
    }
    const int off=20000,sz=2*off;
    vector<vector<bitset<sz>>> dp(h,vector<bitset<sz>>(w));
    dp[0][0][off+a[0][0]]=dp[0][0][off-a[0][0]]=1;
    rep(i,h)rep(j,w){
        if(i){
            dp[i][j]|=(dp[i-1][j]<<a[i][j]);
            dp[i][j]|=(dp[i-1][j]>>a[i][j]);
        }
        if(j){
            dp[i][j]|=(dp[i][j-1]<<a[i][j]);
            dp[i][j]|=(dp[i][j-1]>>a[i][j]);
        }
    }
    int ans=INF;
    rep(i,2*sz){
        if(dp[h-1][w-1][i]){
            chmin(ans,int(abs(i-off)));
        }
    }
    cout<<ans<<endl;
}

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

int n, k, g, mx;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> k;
	for(int i = 0, x; i < n; i++) {
		cin >> x;
		if(!g) g = x;
		else g = __gcd(x, g);
		mx = max(x, mx);
	}
	if(k > mx || k % g) cout << "IMPOSSIBLE";
	else cout << "POSSIBLE";
}

Measured memory_bytes: 256
list = [0,'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
num_list =[0]
for i in range(1,15):
    num_list.append(26**i+num_list[i-1])

n = int(input())
i = 0
while True:
    if num_list[i] >= n:
        break
    else:
        i +=1


word = []
for j in range(i,0,-1):
    x = n//26**(j-1)
    if x==27:
        word.append(26)
        n = n -26**(j-1)*(n//26**(j-1))+26**(j-1)
    else:
        word.append(x)
        n = n -26**(j-1)*(n//26**(j-1))
while True:
    if 0 in word:
        p = word.index(0)
        word[p-1] = word[p-1]-1
        word[p] = 26
    else:
        break
h =''
for k in range(len(word)):
    h+=str(list[word[k]])
print(h)

Measured memory_bytes: 9204
N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]

ans = -float("INF")
for bit in range(1 << 10):
    day = []
    for i in range(10):
        if (bit >> i) & 1:
            day.append(i)
    if day == [] or bit == 0:
        continue
    tmp = 0
    for i in range(N):
        c = 0
        for k in day:
            if F[i][k] == 1:
                c += 1
        tmp += P[i][c]
    ans = max(ans, tmp)

print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		
		//入力するためのオブジェクトを生成
		Scanner sc = new Scanner(System.in);
	
		//ScannerクラスのnextInt()クラスを使う
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		//小さい値２つの領域の確保
		int ans1 = 0;
		int ans2 = 0;

		//値を二つずつ比較する
		if(Math.min(a,b)==a){
			ans1 = a;
			if(Math.min(b,c)==b){
				ans2 = b;
			}else{
				ans2 = c;
			}				
		}else{
			ans1 = b;
			if(Math.min(a,c)==a){
				ans2 = a;
			}else{
				ans2 = c;
			}	
		}

		//出力する
		System.out.print(ans1 + ans2);

		//scオブジェクトを閉じる
		sc.close();
	}
}
		
		


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

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

	int c;
	if (a == 1 && b == 2) {
		c = 3;
	}
	else if (a == 1 && b == 3) {
		c = 2;
	}
	else if (a == 2 && b == 1) {
		c = 3;
	}
	else if (a == 2 && b == 3) {
		c = 1;
	}
	else if (a == 3 && b == 1) {
		c = 2;
	}
	else if (a == 3 && b == 2) {
		c = 1;
	}

	cout << c << endl;

	return 0;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

li table[10][30030];
li next[10];

li n;
string s;

inline bool check(li x, li y, li z) {
    li now = 0;
    if (table[x][now] == INF) {
        return false;
    }
    now = table[x][now];
    if (table[y][now] == INF) {
        return false;
    }
    now = table[y][now];
    return (table[z][now] != INF);
}

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

    rep(i, 10) {
        table[i][n] = INF;
    }
    for (li i = n - 1; i >= 0; i--) {
        rep(j, 10) {
            table[j][i] = (s[i] - '0' == j ? i + 1 : table[j][i + 1]);
        }
    }

    //dump2d(table, n + 1, 10);

    li res = 0;
    rep(i, 10)rep(j, 10)rep(k, 10) {
        if (check(i, j, k)) {
            ++res;
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 2688
#include <iostream>
#include <vector>
#include <set>
#include <deque>
#include <map>
#include <iomanip>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <utility>
using namespace std;
int ky[8] = {-1,1,-2,2,-2,2,-1,1}; 
int kx[8] = {-2,-2,-1,-1,1,1,2,2};
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int ddy[8] = {-1,0,1,-1,1,-1,0,1};
int ddx[8] = {-1,-1,-1,0,0,1,1,1};
typedef long long ll;
#define pi pair
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define rep1(i,a,b) for(int i = a; i < b; i++)
#define rep2(i,a,b) for(int i = a; i <= b; i++) 
#define INF 999999999999
const double PI = acos(-1.0); 
ll n;
ll a[200000];
ll cnt[1000001];
ll ans;
bool ok[1000001];
ll mx;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin >> n;
    mx = -INF;
    rep1(i,0,n){
        cin >> a[i];
        cnt[a[i]]++;
        mx = max(mx, a[i]);
    }

    rep2(i,1,mx){
        if(cnt[i]){
            for(int j = i + i; j <= mx; j += i)
                ok[j] = true;
        }
    }

    rep1(i,0,n)
        if(cnt[a[i]] == 1 && !ok[a[i]]) ans++;
    
    cout << ans;
	return 0;
}


Measured memory_bytes: 13884
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

ll f(ll x){
    if(x%2){
        return x*3+1;
    }else{
        return x/2;
    }
}

int main(){
    ll s;cin>>s;
    vi exist(1000010,0);
    ll index=1;
    while(exist[s]==0){
        exist[s]=index;
        index++;
        s=f(s);
    }
    cout<<index<<endl;
}

Measured memory_bytes: 7128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <stack>
typedef long long ll;

using namespace std;

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


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


using namespace std;

int main(){
   int n;
   cin>>n;
   
  string S;
  cin>>S;
  if(n%2==0 &&(S.substr(0,n/2)==S.substr(n/2,n))){
      cout<<"Yes";
  }else{
      cout<<"No";
  }
   


}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class B
{
	public static void Main()
	{
		string[] args;
		
		args = Console.ReadLine().Split(' ');
		int H = Int32.Parse(args[0]);
		int W = Int32.Parse(args[1]);
		int N = Int32.Parse(args[2]);

		args = Console.ReadLine().Split(' ');
		int sr = Int32.Parse(args[0]);
		int sc = Int32.Parse(args[1]);
		
		string S = Console.ReadLine();
		string T = Console.ReadLine();

		bool ans = true;
		int r = 0;
		int c = 0;
		// U vs D
		r = sr;
		for(int i = 0; i < N; i++)
		{
			if(S[i] == 'U')
			{
				if(r == 1)
				{
					ans = false;
					break;
				}
				else
				{
					r--;
				}
			}

			if(T[i] == 'D')
				r = Math.Min(r+1, H);
		}

		// D vs U
		r = sr;
		for(int i = 0; i < N; i++)
		{
			if(S[i] == 'D')
			{
				if(r == H)
				{
					ans = false;
					break;
				}
				else
				{
					r++;
				}
			}

			if(T[i] == 'U')
				r = Math.Max(r-1, 1);
		}

		// R vs L
		c = sc;
		for(int i = 0; i < N; i++)
		{
			if(S[i] == 'R')
			{
				if(c == W)
				{
					ans = false;
					break;
				}
				else
				{
					c++;
				}
			}

			if(T[i] == 'L')
				c = Math.Max(c-1, 1);
		}

		// L vs R
		c = sc;
		for(int i = 0; i < N; i++)
		{
			if(S[i] == 'L')
			{
				if(c == 1)
				{
					ans = false;
					break;
				}
				else
				{
					c--;
				}
			}

			if(T[i] == 'R')
				c = Math.Min(c+1,W);
		}

		Console.WriteLine(ans ? "YES" : "NO");
	}
}





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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

// pairsをfirstを優先キーとして昇順ソート
bool compare_by_a(pair<ll, ll> a, pair<ll, ll> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, K;
    cin >> N >> K;

    vector<P> p(N);

    REP(i, N){
        cin >> p[i].first >> p[i].second;
    }

    sort(p.begin(), p.end(), compare_by_a);

    ll now = 0;
    REP(i, N){
        now += p[i].second;
        if(K <= now){
            cout << p[i].first << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 4788
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<functional>
using namespace std;
int a, b, c, n, e;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> e;
		if (e % 4 == 0)a++;
		else if (e % 2 == 0)b++;
		else c++;
	}
	if ((b == 0 && a >= c - 1) || (b >= 1 && a >= c)) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

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();
		if (a == b && b == c && a % 2 == 0) {
			System.out.println(-1);
		} else {
			int count = 0;
			while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
				int ta = a;
				int tb = b;
				int tc = c;
				a = (tb + tc) / 2;
				b = (ta + tc) / 2;
				c = (ta + tb) / 2;
				count++;
			}
			System.out.println(count);
		}
 	}
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll mod=1000000007;
#define sz(v) (ll)v.size()
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n,k,q,a;
	cin>>n>>k>>q;
	ll pres[n+1],val[n+1];
	for(ll i=0;i<=n;i++)pres[i]=0;
	for(ll i=0;i<q;i++)
	{
		cin>>a;
		pres[a]++;
	}
	for(ll i=1;i<=n;i++)
		val[i]=k+pres[i]-q;
	for(ll i=1;i<=n;i++)
		val[i]>0?cout<<"Yes\n":cout<<"No\n";
	return 0;
}

Measured memory_bytes: 2176
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let n = v[0];
	let m = v[1];
	if n != 0 && m != 0 {
		println!("{}", n*(n-1)/2 + m*(m-1)/2);
	}else if n == 0 {
		println!("{}", m*(m-1)/2);
	}else if m == 0 {
		println!("{}", n*(n-1)/2);
	}
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll ans[200010];
bool checked[200010];
ll p[200010];
vector<vector<int>> v;
void dfs(ll sum,int pos){
    checked[pos]=true;
    ll ssum=sum+p[pos];
    ans[pos]=ssum;
    for(int i=0;i<v[pos].size();i++){
        if(!checked[v[pos][i]]){
            dfs(ssum,v[pos][i]);
        }
    }
}
int main(){
    int n,q;
    cin>>n>>q;
    v.resize(n);
    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        a--;b--;
        v[a].push_back(b);v[b].push_back(a);
    }
    rep(i,q){
        int t;ll x;
        cin>>t>>x;t--;
        p[t]+=x;
    }
    dfs(0,0);
    rep(i,n-1){
        cout<<ans[i]<<' ';
    }
    cout<<ans[n-1]<<endl;
    return 0;
}


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

using namespace std;
typedef long long ll;

int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> h(n);
    for(int i = 0; i < n; ++i){
        cin >> h.at(i);
    }
    sort(h.begin(), h.end());
    ll ans = h.back();
    for(int i = 0; i + k - 1 < n; ++i){
        ans = min(
            ans,
            h.at(i + k - 1) - h.at(i)
        );
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
N = int(input())
dish = list(map(int,input().split()))
sat =  list(map(int,input().split()))
cons = list(map(int,input().split()))
add = 0
past = -2
for i in range(len(dish)):
	curr = dish[i]
	if curr==past+1 and curr-2>=0:
		add+= (sat[curr-1]+cons[curr-2])
	else:
		add += sat[curr-1]
	past = curr
print(add)


Measured memory_bytes: 38256
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

fn main() {
    let (_n, _t) = get!(usize, usize);
    let aa = get!(String).split_whitespace().map(|n| n.parse::<usize>().unwrap()).collect::<Vec<_>>();

    let mut max_a = 0;
    let mut max_d = 0;
    let mut cnt = 0;
    for a in aa.into_iter().rev() {
        if max_a > a {
            let d = max_a - a;
            if d > max_d {
                max_d = d;
                cnt = 1;
            } else if d == max_d {
                cnt += 1;
            }
        } else {
            max_a = a;
        }
    }
    println!("{}", cnt);
}

Measured memory_bytes: 8444
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace B
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int n = RInt();
            if(n == 4 || n == 2 || n == 1)
            {
                Console.WriteLine(4);
                return;
            }

            int cnt = 1;
            while (true)
            {
                if(n == 4)
                {
                    Console.WriteLine(cnt + 3);
                    return;
                }
                if (n % 2 == 0) n = n / 2;
                else n = n * 3 + 1;
                cnt++;
            }
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define VI vector<int> 
#define SI set<int>
#define QI queue<int> 
#define PII pair<int, int>
#define MP make_pair
#define PB push_back
#define REP(i,a,b) for(int i = a; i < b; ++i)
#define F for(int i = 0; i < n; ++i)
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define M 1000000007
using namespace std;

int main()
 {  
    FIO
    ll n; cin>>n;
    string temp ="";
    while(n > 0) {
        n--;
        ll r = n%26;
        temp += (char)('a' + r );  
        n /= 26;
    }
    reverse(temp.begin(), temp.end());
    cout<<temp;
 
    return 0;
}

Measured memory_bytes: 3600
using System;
using System.Linq;

namespace CodeForces
{
    class Program
    {
        static void Main(string[] args)
        {
            solve();
        }
        private static void solve()
        {
            var k = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();
            string r;
            if (s.Length <= k)
                r = s;
            else
                r = s.Substring(0, k) + "...";
            Console.WriteLine(r);
        }
    }
}

Measured memory_bytes: 27480
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;

int main(){
    int a , b, c;
    cin >> a >> b >> c;
    string hoge = "NO";
    if(a-b == b-c){
        hoge = "YES";
    }
    cout << hoge << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<string.h>
#include<math.h>
#include<numeric>

using namespace std;

int main() {
	int n, p[20],counter=0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	for (int i = 1; i < n - 1; i++) {
		if (p[i - 1] < p[i] && p[i] < p[i + 1])
			counter++;
		if (p[i - 1] > p[i] && p[i] > p[i + 1])
			counter++;
	}
	cout << counter << endl;
		return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int x,y,ans,p,mid;
	scanf("%lld %lld",&y,&x);
	if(x!=1&&y!=1)
	{
		if(x%2==0)
	{
		mid = x/2;
		ans = mid*y;
	}
	else
	{
		mid = x/2 + 1;
		p=y/2;
		if(y%2!=0)
		{
			ans = p*x+mid;
		}
		else
		{
			ans = p*x;
		}
	}
	}
	else
	{
		ans=1;
	}
	
	printf("%lld",ans);
}


Measured memory_bytes: 256
#include <cstdio>

int main() {
	int s;
	scanf("%d", &s);
	int h = s / 3600;
	int m = (s - h * 3600) / 60;
	s = (s - h * 3600 - m * 60);
	printf("%d:%d:%d\n", h, m, s);
}

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

int main(){
  int N,K,num,ans=0;
  cin >> N >> K;
  int d;
  int A[N+1];
  for(int i=0; i<N+1; i++) A[i] = 0;
  for(int i=0; i<K; i++){
    cin >> d;
    for(int j=0; j<d; j++){
      cin >> num;
      A[num]++;
    }
  }
  for(int i=1; i<N+1; i++) if(A[i]==0) ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3680
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
int main(){
  int INF=(1<<29);
  stack<int> s;
  int i,j,n,x,y,ans[2010],a[2010];
  vector<vector<int> > g(2010);
  scanf("%d %d %d\n",&n,&x,&y);
  x--,y--;
  for(i=0;i<n;i++){
    if(i==0){
      g[i].push_back(1);
    }
    else if(i==(n-1)){
      g[i].push_back(n-2);
    }
    else{
      g[i].push_back(i-1);
      g[i].push_back(i+1);
    }
  }
  g[x].push_back(y);
  g[y].push_back(x);
  for(i=0;i<n;i++){
    ans[i]=0;
  }
  for(i=0;i<n;i++){
    s.push(i);
    for(j=0;j<n;j++){
      a[j]=INF;
    }
    a[i]=0;
    while(!s.empty()){
      x=s.top();
      s.pop();
      for(j=0;j<g[x].size();j++){
        if(a[g[x][j]]>a[x]+1){
          a[g[x][j]]=a[x]+1;
          s.push(g[x][j]);
        }
      }
    }
    for(j=0;j<n;j++){
      ans[a[j]]++;
    }
  }
  for(i=1;i<n;i++){
    printf("%d\n",ans[i]/2);
  }
  return 0;
}

Measured memory_bytes: 384
n = int(input())
num_list = [input() for i in range(n)]

bucket = {}
for i in range(1, 101):
    bucket[i] = 0
for i in range(n):
    bucket[int(num_list[i])] += 1
res = 0
for i in range(1, 101):
    if bucket[i] > 0:
        res += 1

print(res)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>    //pow(x,y)=x^y 99999とかの場合+1するif文
#include <algorithm> //sort(a.begin(), a.end());reverse(a.begin(), a.end());
#include <ctime>     //実行時間を測る
#define ll long long
#define vecvec(h,w,name) vector<vector<ll>> name(h, vector<ll>(w));
#define rep(init, i, n) for (ll i = init; i < (n); i++)
#define rev(s) reverse(s.begin(), s.end())
#define sor(v) sort(v.begin(), v.end()) //昇順
#define PI 3.14159265358979323846264338327950L
//コード自動整形 Shift + Option + F @vscode
//変数名一括置換　command+fn+f2 @vscode
using namespace std;
using vec = vector<ll>;
//function
ll facctorialMethod(ll k);     //階乗を出力する
ll modpow(ll a, ll n, ll mod); // a^n mod を計算する
ll gcd(ll a, ll b);//最大公約数
ll lcm(ll a, ll b);//最小公倍数
//

//struct
// UnionFind
// coding: https://youtu.be/TdR816rqc3s?t=726
// comment: https://youtu.be/TdR816rqc3s?t=6822
struct UnionFind
{
  vector<ll> d;
  UnionFind(ll n = 0) : d(n, -1) {}
  ll find(ll x)
  { //根っこを返す
    if (d[x] < 0)
      return x;
    return d[x] = find(d[x]); //根っこの場所を貼り付ける
  }
  bool unite(ll x, ll y)
  { //くっつける操作、連結成分の情報整理 ABC177,157D参照
    x = find(x);
    y = find(y);
    if (x == y)
      return false;
    if (d[x] > d[y])
      swap(x, y); //dはマイナスをかけたサイズだからxの方がサイズ小さいようにする
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  //ll root()
  bool same(ll x, ll y) { return find(x) == find(y); } //同じ集合に属しているかを判定
  ll size(ll x) { return -d[find(x)]; }                //あるID、xが所属するグループに所属するIDの数を得る ABC177,157D参照
};
//

/////main/////
int main()
{
  int clock_on = 0; //提出時は0!!!!!!!!!!!!!!!!!
  int time_clock = clock();
  //
  ll n,m,a,b;
  cin>>n>>m;
  set<ll> S;
  UnionFind uf(n);
rep(0,i,m){
    cin>>a>>b;
    --a;--b;
    uf.unite(a,b);
}
ll temp;
rep(0,i,n){
    temp = uf.find(i);
    //cout<<uf.find(i)<<endl;
    S.insert(temp);
}
cout<<S.size()-1<<endl;


  //
  if (clock_on == 1)
    printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - time_clock) / CLOCKS_PER_SEC);
  return 0;
}
/////main/////

/////function/////
//階乗を出力する
ll facctorialMethod(ll k)
{
  ll sum = 1;
  for (ll i = 1; i <= k; ++i)
  {
    sum *= i;
  }
  return sum;
}

// a^n mod を計算する
ll modpow(ll a, ll n, ll mod)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

//最大公約数
ll gcd(ll a, ll b){
  if(a%b == 0){
    return b;
  }else{
    return gcd(b, a%b);
  }
}

//最小公倍数
ll lcm(ll a, ll b){
  return a*b / gcd(a, b);
}

Measured memory_bytes: 7844
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC116A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b;
            string[] ss = Console.ReadLine().Split(' ');
            a = int.Parse(ss[0]);
            b = int.Parse(ss[1]);
            Console.WriteLine((a * b) / 2);
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13140
import sys
input=sys.stdin.readline
from collections import defaultdict
class UnionFind:
    def __init__(self,n):
        self.par=[i for i in range(n)]
        self.rank=[0]*n
    def find(self,x):
        if self.par[x]==x:
            return x
        else:
            self.par[x]=self.find(self.par[x])
            return self.par[x]
    def union(self,x,y):
        x=self.find(x)
        y=self.find(y)
        if x==y:
            return
        if self.rank[x]<self.rank[y]:
            self.par[x]=y
        else:
            self.par[y]=x
            if self.rank[x]==self.rank[y]:
                self.rank[x]+=1
    def same_check(self,x,y):
        return self.find(x)==self.find(y)

n=int(input())
uf=UnionFind(n)
XY=[tuple(map(int,input().split())) for _ in range(n)]
Xd=defaultdict(list)
Yd=defaultdict(list)
for i,(x,y) in enumerate(XY):
    Xd[x].append(i)
    Yd[y].append(i)
for x in Xd:
    i=Xd[x][0]
    for j in Xd[x]:
        uf.union(i,j)
for y in Yd:
    i=Yd[y][0]
    for j in Yd[y]:
        uf.union(i,j)
d=defaultdict(list)
for i in range(n):
    d[uf.find(i)].append(i)
ans=0
for k in d:
    Xs,Ys=set(),set()
    for i in d[k]:
        x,y=XY[i]
        Xs.add(x); Ys.add(y)
    ans+=len(Xs)*len(Ys)
ans-=n
print(ans)

Measured memory_bytes: 109040
#include<iostream>
#include<vector>
#include<cstring>
#include<queue>
using namespace std;

#define maxv 100

struct edge{
    int to, cap, rev;
};

vector<edge> G[maxv];
int dist[maxv];
int iter[maxv]; // どこまで調べ終わったか

void add_edge(int from, int to, int cap){
    G[from].push_back(edge({to, cap, (int)G[to].size()}));
    G[to].push_back(edge({from, 0, (int)G[from].size()-1}));
}

void bfs(int s){
    memset(dist, -1, sizeof(dist));
    queue<int> q;
    dist[s] = 0;
    q.push(s);
    while(!q.empty()){
        int x = q.front();  q.pop();
        for(edge e : G[x]){
            int next = e.to;
            if(e.cap > 0 && dist[next] < 0){
                dist[next] = dist[x]+1;
                q.push(next);
            }
        }
    }
}

int dfs(int v, int t, int f){
    if(v == t)  return f;
    for(int &i = iter[v]; i < G[v].size(); i++){
        edge &e = G[v][i];
        if(e.cap > 0 && dist[e.to] > dist[v]){
            int d = dfs(e.to, t, min(f, e.cap));
            if(d > 0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

const int INF = 1<<30;

int max_flow(int s, int t){
    int flow = 0;
    while(true){
        bfs(s);
        if(dist[t] < 0) return flow;
        memset(iter, 0, sizeof(iter));
        int f;
        while((f = dfs(s, t, INF)) > 0) flow += f;
    }
}

int main(){
    int v, e;
    cin >> v >> e;
    while(e--){
        int a, b, c;
        cin >> a >> b >> c;
        add_edge(a, b, c);
    }
    cout << max_flow(0, v-1) << endl;
    return 0;
}


Measured memory_bytes: 3220
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
#define SZ(x) (int)((x).size())
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  int64 x, k, d;
  cin >> x >> k >> d;
  int64 y = x % d;
  if (y < 0) y += d;
  int64 z = y - d;
  int64 step = min(abs(x - y) / d, k);
  if ((k - step) % 2) step -= 1;
  int64 ret = 1LL << 60;
  ret = min(ret, abs(x + step * d));
  ret = min(ret, abs(x - step * d));
  step = min(abs(x - z) / d, k);
  if ((k - step) % 2) step -= 1;
  ret = min(ret, abs(x + step * d));
  ret = min(ret, abs(x - step * d));
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
long long INF = 2e9;
int main(){
  int N;
  cin >> N;
  long long sum = 0;
  long long m = INF;
  for (int i = 0; i < N; i++){
    long long a;
    cin >> a;
    sum += a;
    m = min(m, a);
  }
  if (N % 2 == 1){
    if (sum % 2 == 1){
      cout << "First" << endl;
    } else {
      cout << "Second" << endl;
    }
  } else {
    if (sum % 2 == 1 || m % 2 == 1){
      cout << "First" << endl;
    } else {
      cout << "Second" << endl;
    }
  }
}


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

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

  int ans = 0;
  for (int i = 1; i <= N; i += 2) {
    int count = 0;
    for (int j = 1; j <= N; j++)
      if (i % j == 0) count++;
    if (count == 8) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define M1 1000000007
#define M2 998244353

#define fl(i,a,b)  for(ll i=a;i<b;i++)
#define bfl(i,a,b) for(ll i=b-1;i>=a;i--)
#define f(i,n)     for(int i=0;i<n;i++)
#define bf(i,n)    for(int i=n-1;i>=0;i--)
#define f1(i,n)    for(int i=1;i<=n;i++)
#define bf1(i,n)   for(int i=n;i>=1;i--)

#define all(v) v.begin(),v.end()
#define pll pair<long,long>
#define pii pair<int,int>



#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define bn "\n"

//------------------------------------------------------------------------ 
// #define V(a) vector<a>
// #define vt() vector< tuple < int ,int ,int > > ;
// #define vector< int ,int > pv;
// vector< pair <int,int> > vect;


//------------------------------------------------------------------------

ll modI(ll a,ll m);
ll gcd(ll a,ll b);
ll powM(ll x,ll y,ll m);
ll swap(ll a,ll b);

void swap(ll& a,ll& b)
{
    ll tp=a;
    a=b;
    b=tp;
}

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

ll powM(ll x,ll y,ll m)
{
    ll fin=1,r=1;
    x%=m;
    while(r>0&&r<=y)
    {
        if(r&y)
        {
            fin*=x;
            fin%=m;
        }
        r<<=1;
        x*=x;
        x%=m;
    }
    return fin;
}
 
ll modI(ll a, ll m)
{
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m;
        a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0) x+=m0;
    return x;
}

//---------------------------------------------------------------------------

// variable = Expression1 ? Expression2 : Expression3
// max = (n1 > n2) ? n1 : n2; 
// (n>m) ? cout<<"True"<<endl:cout<<"false"<<endl ;

// ---------------------------------------------------------------------------	

// int n;cin>>n;int a[n];for(int i=0;i<n;i++)cin>>a[i];    
// for(int i=0;i<n;i++)cout<<a[i];
// int a,b;cin>>a>>b;   

//----------------------------------------------------------------------------

// vector< tuple < int ,int ,int > > tv;
// vector< int ,int > pv;


//----------------------------------------------------------------------------


int main() {
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
	int tt=1;
   // cin>>tt;
	while(tt--)
	{
	      int n; cin>>n;
    vector<ll> a(n);
    f(i,n) cin>>a[i];
    int index = 0;
    long long start = 1000;
    long long fin = 0;
    while(index<n)
    {
        int j = index; index++;
        while(index<n && a[index] >= a[index-1] ) index++;
        ll zz = start/a[j];
        fin += ( zz*(a[index-1]-a[j]) );
        start += zz*(a[index-1]-a[j]);
    }
    p1(start);
    
	   
	   
	    
	}
	
	return 0;
}


Measured memory_bytes: 3640
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){
  int n; cin >> n;
  int a[n+1],cnt=0;
  for(int i=1;i<=n;i++) cin >> a[i];
  for(int i=1;i<=n;i++){
    if(i<a[i] && a[a[i]]==i){
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 640
data = []
for i in range(10):
    data.append(int(raw_input()))

m1 = m2 = m3 = 0 
for i in data:
    if 0 <= i <= 10000:
        if m1 <= i:
            m3 = m2
            m2 = m1
            m1 = i 
        elif m2 <= i < m1:
            m3 = m2
            m2 = i 
        elif m3 <= i < m2:
            m3 = i 

print "{}\n{}\n{}".format(m1, m2, m3) 

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

ansl = [0, 0]
s = [0, 0]

for i in range(2):
	for j in range(n):
		s[i] += a[j]
		if (i+j) % 2 == 0:
			if s[i] >=0:
				ansl[i] += abs(s[i]) + 1
				s[i] = -1
		else:
			if s[i] <=0:
				ansl[i] += abs(s[i]) + 1
				s[i] = 1

print(min(ansl))



Measured memory_bytes: 14332
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<limits>
#include<queue>
#include<stack>
#include<math.h>
#include<array>
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;
int main(){
    int N, a[100];
    cin >> N;
    pair<double, int> P[100];
    double sum  = 0;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        sum = sum + a[i];
    }
    sum = sum / N;
    for(int i  = 0; i < N; i++){
        P[i].first = fabs(a[i] - sum), P[i].second = i;
    }
    sort(P, P + N);
    cout << P[0].second << endl;
    return 0;
}

Measured memory_bytes: 256
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    d = [str(i) for i in range(10)]
    a, b = list(map(int, readline().split()))
    s = str(readline().rstrip().decode('utf-8'))
    for i in range(a + b + 1):
        if i < a or a < i:
            if s[i] not in d:
                print("No")
                exit()
        else:
            if s[i] != "-":
                print("No")
                exit()
    print("Yes")


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38384
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=1e9,dx[]={-1,0,1,0},dy[]={0,-1,0,1};
string s,word[]={"dream","erase","dreamer","eraser"};
pair<int,int> p[4]={{5,0},{5,1},{7,2},{6,3}};
void dfs(int x)
{
	if(x==s.size())
	{
		cout<<"YES";
		exit(0);
	}
	for(int d=0;d<4;d++)
	{
		int len=p[d].first,wd=p[d].second;
		if(s.substr(x,len)==word[wd])
			dfs(x+len);
	}
}
int main(){
	cin>>s;
	dfs(0);
	cout<<"NO";
	return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(args...) do { cout << "\033[34;1m" << #args << " -> "; err(args); } while (0)
#else
#define dbg(...)
#endif
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... Args>
void err(T<t> a, Args... args) { for (auto x: a) cout << x << ' '; err(args...); }
template<typename T, typename... Args>
void err(T a, Args... args) { cout << a << ' '; err(args...); }
// ----------------------------------------------------------------------------
const int N = 100 + 10;
LL a[N];
int main() {
    LL n, s; cin >> n >> s;
    FOR (i, 0, n) cin >> a[i];
    sort(a, a + n);
    int ans = 0;
    FOR (i, 0, n) {
        if (s >= a[i]) { s -= a[i]; ++ans; }
    }
    if (ans == n && s) --ans;
    cout << ans << endl;
}

Measured memory_bytes: 256
n=int(input())
a=[]
b=[]

for i in range(n):
    x,y=list(map(int,input().split()))
    a.append(x+y)
    b.append(x-y)

mnp=min(a)
mxp=max(a)
mnm=min(b)
mxm=max(b)

res=[mxp-mnp,mxm-mnm,mnm,mxm,mnp-mxp]
print(max(res))

Measured memory_bytes: 24960
#include <iostream>
using namespace std;
int main(void){
    int a, b, c, x, min, max;
    cin >> a >> b >> c; 
    if(b < a){
        x = a;
        a = b;
        b = x;
    }
    if(c < b){
        x = b;
        b = c;
        c = x;
    }
    if(b < a){
        x = a;
        a = b; 
        b = x;
    }
    cout << a << " " << b << " " << c;
    cout << endl;
}


Measured memory_bytes: 3084
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  vector<pair<ll, ll> > arr(N);
  ll X, L;
  for(int i=0;i<N;++i) {
    cin>>X>>L;
    arr[i] = mp(X+L, X);
  }
  sort(arr.begin(), arr.end());
  ll tmp = arr[0].fi;
  int ans = 1;
  for(int i=1;i<N;++i) {
    X = arr[i].se;
    L = arr[i].fi-X;
    if(X-L<tmp) continue;
    ans++;
    tmp = X+L;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 4812
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF (1LL<<61 + 1<<29)
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
void _INPUT_IMPL_() {};
template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
void _OUTPUT_IMPL_() {};
template <class T, class... Args> void _OUTPUT_IMPL_(T dest, Args... args) { cout<< dest << (sizeof...(Args)?" ":""); _OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define out(...) _OUTPUT_IMPL_(__VA_ARGS__)

int main() {
	in_v(int, p, 3);
	sort_v(p);
	out(p[0] + p[1]);
}

Measured memory_bytes: 256
#include <iostream>
#include <unordered_map>
#include <iterator>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>

using namespace std;

int main(void)
{
  int n;
  cin >> n;
  vector<size_t> v(20000);
  int sum = 0;

  unordered_map<size_t, int> um;
  for (int i = 0; i < n; i++) {
    string str;
    cin >> str;
    size_t hs = hash<string>()(str);
    auto itr = lower_bound(v.begin(), v.end(), hs);

    if (itr == v.end()) {
      v.push_back(hs);
      sum++;
    } else if (*itr != hs) {
     v.insert(itr, hs);
      sum++;
    } else {
    }
  }
  cout << sum << endl;

  return 0;
}

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

ll M = 1000000007;

ll mypow(ll x,ll n){
    ll ans=1;
    rep(i,n){
        ans = (x*ans)%M;
    }
    return ans;
}

int main(){
    ll n; cin >> n;
    ll ans = mypow(10,n) - 2*mypow(9,n) + mypow(8,n);
    ans %= M;
    ans = (ans+M)%M;
    cout << ans << endl;
}

Measured memory_bytes: 3496
#include<stdio.h>

int main() {
	char str[21];
	char *st, *en;
	char tmp;
	
	scanf("%s", str);
	
	st = str;
	en = str;
	while(*en != '\0') { ++en; }
	--en;

	while(st < en) {
		tmp = *st;
		*st = *en;
		*en = tmp;

		++st;
		--en;
	}

	printf("%s\n", str);
	
	return 0;
}

Measured memory_bytes: 524
def main():
    n = int(input())
    s = input()
    tmp = 0
    if n%2 != 0:
        print("No")
        exit()
    for i in range(n//2):
        if s[i] != s[int(n/2)+i]:
            tmp += 1
    if tmp > 0:
        print('No')
    else:
        print('Yes')


    
    
if __name__ == "__main__":
    main()


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9

using namespace std;
typedef long long int lli;
typedef long long ll;

int h,w;
vector<vector<char>> s(50,vector<char>(50));
vector<vector<int>> fill_num(50, vector<int>(50,-1));
int wall = 0;
bool success = true;
int ans = 0;

vector<int> num_y = {1,-1,0,0};
vector<int> num_x = {0,0,1,-1};

int main() {
    cin >> h >> w;
    rep(i,h) rep(j,w){
        char c;
        cin >> c;
        s[i][j] = c;
        if(c == '#') wall++;
    }

    queue<vector<int>> q;
    q.push({0,0});
    fill_num[0][0] = 1;

    while(true){
        vector<int> now = q.front();
        q.pop();

        if(now[0] == h-1 && now[1] == w-1) break;

        rep(i,4){
            int next_y = now[0] + num_y[i];
            int next_x = now[1] + num_x[i];
            
            if(next_y >= 0 && next_y < h && next_x >= 0 && next_x < w){
                if(s[next_y][next_x] == '.' && fill_num[next_y][next_x] == -1){
                    q.push({next_y, next_x});
                    fill_num[next_y][next_x] = fill_num[now[0]][now[1]] + 1;
                }
            }
        }

        if(q.size() == 0){
            success = false;
            break;
        }
    }

    if(success){
        ans = h*w - wall - fill_num[h-1][w-1];
    }
    else{
        ans = -1;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256