akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
import java.util.LinkedList;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			int r = sc.nextInt();
			if (n == 0 && r == 0) break;
			LinkedList<Integer> list = new LinkedList<>();
			for (int i = 0; i < n; ++i)
				list.add(i + 1);
			for (int k = 0; k < r; ++k) {
				int p = sc.nextInt();
				int c = sc.nextInt();
				for (int j = 0; j < c; ++j) {
					int idx = n - (p - 1 + c);
					int mv = list.get(idx);
					list.remove(idx);
					list.add(mv);
				}
			}
			System.out.println(list.get(list.size() - 1));
		}
	}
}


Measured memory_bytes: 39012
n = int(input())
A = list(map(int,input().split()))
a = A[0]
b = A[1]
x = 0
for i in A[2:]:
    x ^= i

d = {}
def F(a,b,xor):
    if (a,b,xor) in d:
        return d[(a,b,xor)]
    if a&1 ^ b&1 != xor&1:
        return float("INF")
    if xor == 0:
        if a<b:
            return float("INF")
        else:
            return (a-b)//2
    c1 = 2*F(a//2,b//2,xor//2)
    c2 = 2*F((a-1)//2,(b+1)//2,xor//2) + 1
    f = min(c1,c2)
    d[(a,b,xor)] = f
    return f

ans = F(a,b,x)
if ans >= a:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9156
inp = input()
values = inp.split(" ")
Ah = values[0]
As = values[1]
Bh = values[2]
Bs = values[3]
while int(Ah) > 0 and int(Bh) > 0:
    tempB = int(Bh)
    tempA = int(Ah)
    tempB = tempB - int(As)
    if tempB > 0:
        tempA = tempA - int(Bs)
    Ah = str(tempA)
    Bh = str(tempB)
if int(Ah) > int(Bh):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 61708
#include <stdio.h>
#include <string.h>

int main(void)
{
	int n;
	char s[128];
	char *p = s;

	scanf("%d", &n);
	scanf("%s", s);
	if (n & 1) {
		puts("No");
	} else {
		if (strncmp(s, p+n/2, n/2) == 0)
			puts("Yes");
		else
			puts("No");
	}
	
	return 0;
}


Measured memory_bytes: 128
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
import copy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)

# 1 2 3
# a, b, c = LI()


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

# a = I()


def I(): return int(sys.stdin.buffer.readline())

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


def IR(n): return [I() for i in range(n)]

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def LIR(n): return [LI() for i in range(n)]

# 2
# abc
# def
# [abc, def]


def SR(n): return [S() for i in range(n)]

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


def SRL(n): return [list(S()) for i in range(n)]


def main():
    n = I()
    print((pow(10, n) - (pow(9, n) + pow(9, n) - pow(8, n))) % mod)
    # print((pow(n, 10) - (pow(n, 9) + pow(n, 9) - pow(n, 8))) % mod)
    # ans = 0
    # now = 0
    # for i in range(n):

    #     for j in range(10):


# def pow(n, num):
#     s = num
#     for i in range(1, n):
#         s = s * num % mod
#     return s

def pow(a, n):
    x = 1
    while n > 0:
        if(n & 1):
            x *= a
        a = a*a
        n >>= 1
    return x


if __name__ == "__main__":
    main()


Measured memory_bytes: 123132
# include "iostream"
# include "cstdio"

using namespace std;

const int maxm=1000+10;
const int maxn=30+10; 
int n,c,d[maxn][maxn],t[4][maxn],x,y,z,ans;
bool f1,f2,f3;

int main(){
	scanf("%d%d",&n,&c);
	ans=0xfffffff;
	register int i,j,k,l; 
	for(i=1;i<=c;i++){
		for(j=1;j<=c;j++){
			scanf("%d",&d[i][j]);
		}
	}
	/*for(k=1;k<=c;k++){
		for(i=1;i<=c;i++){
			for(j=1;j<=c;j++){
				if(d[i][j]>d[i][k]+d[k][j]){
					d[i][j]=d[i][k]+d[k][j];
				}
			}
		}
	}*/ 
	/*for(i=1;i<=c;i++){
		for(j=1;j<=c;j++){
			printf("%d ",d[i][j]);
		}
		printf("\n");
	}*/ 
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			scanf("%d",&x);
			t[(i+j)%3][x]++;
		}
	}
	/*for(i=0;i<=2;i++){
		for(j=1;j<=c;j++){
			printf("%d ",t[i][j]);
		}
		printf("\n");
	}*/ 
	for(i=1;i<=c;i++){
		x=0;
		for(j=1;j<=c;j++){
			x+=t[0][j]*d[j][i];
		}
		//if(x==0) continue;
		for(j=1;j<=c;j++){
			if(j==i) continue;
			y=0;
			for(k=1;k<=c;k++){
				if(t[1][k]>=1 && y>=1){
					f2=true;
				}
				y+=t[1][k]*d[k][j];
			}
			//if(y==0) continue;
			for(k=1;k<=c;k++){
				if(k==j || k==i) continue;
				z=0;
				for(l=1;l<=c;l++){
					z+=t[2][l]*d[l][k];
				}
				//if(z==0) continue;
				if(ans>x+y+z){
					ans=x+y+z;
					//printf("i:%d j:%d k:%d %d %d %d\n",i,j,k,x,y,z);
				}
			}
		}
	} 
	printf("%d",ans);
	return 0; 
} 

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>

// #include <unordered_set>
// #include <unordered_map>

#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())

#define pb push_back
#define mp make_pair

int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}

typedef std::pair<int, int> P;
typedef long long ll;
typedef long double ld;

const int MOD = 1000000007;
const int INF = 1e9;
const ll LINF = INF * 1ll * INF;
const ld DINF = 1e200;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

using namespace std;

// #define int long long

signed main(){
  

    ios::sync_with_stdio(false);
    cin.tie(0);
	//cin高速化

    int n;
    cin>>n;

    cout<<n/3<<endl;
	return 0;

}


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

int main(){
    ll n,m,ans=0LL; cin >> n >> m;
    if(n>=m/2LL) ans = m/2LL;
    else{
        m -= n*2LL;
        ans = n + (m/4LL);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
#include<iostream>
using namespace std;
int main(){
	string a,b,c;
	cin>>a>>b>>c;
	if(a[a.size()-1]==b[0] && b[b.size()-1]==c[0]){
		cout<<"YES"<<endl;
		
	}
	
	else cout<<"NO"<<endl;
	
}

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


int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  if (a + b + c >= 22)
    puts("bust");
  else
    puts("win");
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef complex<double> P;
typedef pair<P,P> Edge;
typedef long long ll;

const double PI=4*atan(1.0);

void fast_stream(){
	std::ios_base::sync_with_stdio(0);
}
	

#ifdef RED_FILE
ifstream ifs("input.txt");
ofstream ofs("output.txt");
#define cin ifs
#define cout ofs
#endif


int main(){

    int n,w;
    int v[1001];
    while(cin>>n>>w&&!(n==0&&w==0)){
        memset(v,0,sizeof(v));
        int maxn=0;
        int my=0;
        for(int i = 0; i < n; i++){
            int t;
            cin>>t;
            v[t/w]++;
            my=max(my,t/w);
        }
        for(int i = 0; i <= my; i++)
            maxn=max(maxn,v[i]);
        double s=0.01;
        double per=1.0;
        for(int i = 0; i <= my; i++){
            s+=((double)v[i]/maxn)*per;
            per-=(1.0)/(my);
        }
        //printf("%.6f\n",s);
        cout<<s<<endl;
    }

    return 0;
}

Measured memory_bytes: 0
n,x=map(int,input().split())

a=list(map(int,input().split()))

c=0
if a[0] > x:
  c= a[0] - x
  a[0] = x

  
for i in range(0,n-1):
  if a[i]+a[i+1]>x:
    c+=(a[i]+a[i+1]-x)
    a[i+1]-=(a[i]+a[i+1]-x)
print(c)

Measured memory_bytes: 14060
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include<math.h>
#include<bitset>
#include<iomanip>
using namespace std;

int main() {
	int N; long long x,ans=0; cin >> N >> x;
	vector<long long> a(N);
	for (int i = 0; i < N; i++) cin>>a[i];
	for (int i = 0; i < N - 1; i++) {
		if (a[i + 1] + a[i] > x&&a[i]<=x) { 
			ans += a[i + 1] + a[i] - x; a[i + 1] -= a[i+1]+a[i]-x; 
		}
		else if (a[i + 1] + a[i] > x&&a[i] > x) {
			ans += a[i + 1] + a[i] - x;
			a[i + 1] =0;
			a[i] -= a[i] - x;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define lor(a,b,c) for(register int a=b;a<=c;++a)
#define ror(a,b,c) for(register int a=c;a>=b;--a)

const int N=2e5+5,K=8e3+5,MOD=1e9+7,S=1.6e4+5;
int n,a[N],b[N],mxx,mxy,dp[K][K],ans;
int fac[N],inv[N];

inline int qsm(int a,int b) {int ans=1; while(b) {if(b&1) ans=1ll*ans*a%MOD; a=1ll*a*a%MOD; b>>=1;} return ans;}
inline void inc(int &a,int b) {(a+=b)>=MOD?a-=MOD:a;}
inline int C(int a,int b) {return b<0||a<b?0:1ll*fac[a]*inv[b]%MOD*inv[a-b]%MOD;}

int main(){
	#ifndef ONLINE_JUDGE
	freopen("test.in","r",stdin);
	#endif

	scanf("%d",&n); lor(i,1,n) scanf("%d%d",&a[i],&b[i]),mxx=max(mxx,a[i]),mxy=max(mxy,b[i]);
	lor(i,1,n) dp[-a[i]+mxx][-b[i]+mxy]++;
	lor(i,0,mxx+mxx) lor(j,0,mxy+mxy){
		if(i) inc(dp[i][j],dp[i-1][j]); if(j) inc(dp[i][j],dp[i][j-1]);
	}
	lor(i,1,n) inc(ans,dp[a[i]+mxx][b[i]+mxy]);
	int tmp=max(mxx,mxy)*4;
	fac[0]=1; lor(i,1,tmp) fac[i]=1ll*fac[i-1]*i%MOD;
	inv[tmp]=qsm(fac[tmp],MOD-2); ror(i,0,tmp-1) inv[i]=1ll*inv[i+1]*(i+1)%MOD;
	lor(i,1,n) inc(ans,MOD-C(a[i]*2+b[i]*2,a[i]*2));
	ans=1ll*ans*((MOD+1)>>1)%MOD;
	printf("%d\n",ans);

	return 0;
}

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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

i64 gcd(i64 a, i64 b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

void solve(){
    i64 A,B,C,D;
    cin >> A >> B >> C >> D;

    A-=B;

    if(A<0 or B>D){
        cout << "No" << endl;
        return;
    }

    i64 g=gcd(B,D),r=((A%g)+g)%g,k=(C-r+g)/g,x=k*g+r;
    assert(x>=C+1);
    if(x-B<0) cout << "No" << endl;
    else cout << "Yes" << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    i64 T;
    cin >> T;
    rep(i,0,T) solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define NMAX 200005
#define ll long long int

using namespace std;

ll n, m, lg, sx, sy, maxim, outborder, antioutborder, i, sxx, syy;
char sir[NMAX], sir2[NMAX], aux;

int main(){
    cin >> n >> m >> lg;
    cin >> sx >> sy;
    cin.get(aux);
    cin.getline(sir, NMAX, '\n');
    cin.getline(sir2, NMAX, '\n');
    lg = strlen(sir);

    sxx = sy;

    for(i=0; i<lg; ++i){
        if(sir[i] == 'L')
            --sxx;
            if(sxx <= 0){
                cout << "NO\n";
                return 0;
            }
        if(sir2[i] == 'R' && sxx < m)
            ++sxx;

        }

    maxim = -1; sxx = sy;
    outborder = antioutborder = 0;

    for(i=0; i<lg; ++i){
        if(sir[i] == 'R')
            ++sxx;
             if(sxx > m){
                cout << "NO\n";
                return 0;
                }
        if(sir2[i] == 'L' && sxx > 1)
            --sxx;

        }

    maxim = -1; syy = sx;
    outborder = antioutborder = 0;


    for(i=0; i<lg; ++i){
        if(sir[i] == 'U')
            --syy;
             if(syy <= 0){
                cout << "NO\n";
                return 0;
                }
        if(sir2[i] == 'D' && syy < n)
            ++syy;

        }

    maxim = -1; sxx = sy; syy = sx;
        outborder = antioutborder = 0;


for(i=0; i<lg; ++i){
        if(sir[i] == 'D')
            ++syy;
            if(syy > n){
            cout << "NO\n";
        return 0;
            }
        if(sir2[i] == 'U' && syy > 1)
            --syy;

        }


    cout << "YES\n";
    return 0;
}


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

int main() {
  // ここにプログラムを追記
  char s[3];
  int c = 0;
  for (int i = 0;i < 3 ;i++){
    cin >> s[i];
    (s[i]=='1') ? ++c : 0;
  }
  cout << c << endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<string>v;
vector<int>ansl;
string s;
long long int ary[10001] = {0};
int mp[51][51];
int cnt = 0;
int d_x[] = {0,1,0,-1};
int d_y[] = {1,0,-1,0};
int W,H;

void dfs(int x,int y){
  mp[y][x] = 0;
  for(int dx = -1;dx<2;dx++){
    for(int dy = -1;dy<2;dy++){
    int nx = x+dx,ny = y+dy;
    if((nx>=0)&&(ny>=0)&&(ny<H)&&(nx<W)&&(mp[ny][nx] == 1)){
      dfs(nx,ny);
    }
  }
}
}
int main(){
  int N;
  int ans = 0;
  int ind = 0;
  cin >>N;

  for(int i = 0;i<N;i++){
    long long int x;
    int now = 0;

    cin >>x;
    if(x%2==0){
      while(x%2 == 0){
        x /= 2;
        now++;
      }
    }
    ans += now;
  }


  cout <<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,lg,tr,cr,f=0;

    cin>>n>>lg;
/*
    if(lg%2==1){
        cout<<"NO\n";
    }
    else{*/
       for(tr=0;tr<=n;tr++){
        cr=n-tr;
        if(4*tr+2*cr==lg){
            f=1;
            break;
        }
       }
       if(f==1){
        cout<<"Yes\n";
       }
       else{
        cout<<"No\n";
       }
}



Measured memory_bytes: 3604
S = input()

length = len(S)
is_strong_palindrome = True

for i in range(length//2):
    if S[i] != S[length-i-1]:
        is_strong_palindrome = False
        break

first_half_S = S[:length//2]
second_half_S = S[length//2+1:]
# print(first_half_S)
# print(second_half_S)

length_palindrome = len(first_half_S)
for i in range(length_palindrome//2):
    if first_half_S[i] != first_half_S[length_palindrome-i-1]:
        is_strong_palindrome = False
        break
    if second_half_S[i] != second_half_S[length_palindrome-i-1]:
        is_strong_palindrome = False
        break

if is_strong_palindrome:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
// Author -- Frame

#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<iostream>

#define lowbit(x) ((x)&(-x))
#define Finline __inline__ __attribute__ ((always_inline))
#define DEBUG printf("Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)

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

const int inf=0x3f3f3f3f,Inf=0x7fffffff;
const ll INF=0x7fffffffffffffff;
const double eps=1e-10;

uint seed=19260817;
const uint _RAND_MAX_=4294967295u;
Finline uint Rand(){return seed=seed*998244353u+1000000007u;}

template <typename _Tp>_Tp gcd(const _Tp &a,const _Tp &b){return (!b)?a:gcd(b,a%b);}
template <typename _Tp>Finline _Tp abs(const _Tp &a){return a>0?a:-a;}
template <typename _Tp>Finline _Tp max(const _Tp &a,const _Tp &b){return a<b?b:a;}
template <typename _Tp>Finline _Tp min(const _Tp &a,const _Tp &b){return a<b?a:b;}
template <typename _Tp>Finline void chmax(_Tp &a,const _Tp &b){(a<b)&&(a=b);}
template <typename _Tp>Finline void chmin(_Tp &a,const _Tp &b){(b<a)&&(a=b);}
template <typename _Tp>Finline bool _cmp(const _Tp &a,const _Tp &b){return abs(a-b)<=eps;}
template <typename _Tp>Finline void read(_Tp &x)
{
	register char ch(getchar());
	bool f(false);
	while(ch<48||ch>57) f|=ch==45,ch=getchar();
	x=ch&15,ch=getchar();
	while(ch>=48&&ch<=57) x=(((x<<2)+x)<<1)+(ch&15),ch=getchar();
	if(f) x=-x;
}
template <typename _Tp,typename... Args>Finline void read(_Tp &t,Args &...args)
{
	read(t);read(args...);
}
Finline int read_str(char *s)
{
	register char ch(getchar());
	while(ch==' '||ch=='\r'||ch=='\n') ch=getchar();
	register char *tar=s;
	*tar=ch,ch=getchar();
	while(ch!=' '&&ch!='\r'&&ch!='\n'&&ch!=EOF) *(++tar)=ch,ch=getchar();
	return tar-s+1;
}

const int N=100005;

int main()
{
	ll n,a,b;
	read(n,a,b);
	if((b-a)&1)
	{
		printf("%lld\n",min(n-b+((b-a+1)>>1),a-1+((b-a+1)>>1)));
	}
	else
	{
		printf("%lld\n",(b-a)>>1ll);
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
   int i;
   char st, a[53] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

   do{
   scanf("%c", &st);

   for(i=0;i<52;i++){
   if(a[i] == st){
      st = a[ (i+26)%52];
      break;
   }
   }
   printf("%c", st);
   }while(st !='\n');

   return 0;
}


Measured memory_bytes: 2056
#include <bits/stdc++.h>
#define int long long int 
using namespace std;
vector<int> neighbour[51];
vector<int> a[51];
vector<int> b[51];
int c[51];
int d[51];
int dist[51][2505];
const int inf=1e18;
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n,m,s;
  cin>>n>>m>>s;
  s=min(s,2500LL);
  for(int i=0;i<m;i++)
  {
  	int u,v,ai,bi;
  	cin>>u>>v>>ai>>bi;
  	neighbour[u].push_back(v);
  	a[u].push_back(ai);
  	b[u].push_back(bi);

  	neighbour[v].push_back(u);
  	a[v].push_back(ai);
  	b[v].push_back(bi);
  }

  for(int i=1;i<=n;i++) cin>>c[i]>>d[i];
  for(int i=1;i<=n;i++)
  {
  	for(int j=0;j<=2500;j++)
  	{
  		dist[i][j]=inf;
  	}
  }

  dist[1][s]=0;
  priority_queue <pair<int,pair<int,int>>> pq;
  pq.push({0,{1,s}});
  while(pq.size())
  {
  	auto curr=pq.top();
  	int dis=-curr.first;
  	int node=curr.second.first;
  	int paisa=curr.second.second;
  	pq.pop();
  	if(dist[node][paisa]<dis) continue;
  	int sz=neighbour[node].size();
  	for(int i=0;i<sz;i++)
  	{
  		if(paisa>=a[node][i])
  		{
  			if(dist[neighbour[node][i]][paisa-a[node][i]]>dist[node][paisa]+b[node][i])
  			{
  				dist[neighbour[node][i]][paisa-a[node][i]]=dist[node][paisa]+b[node][i];
  				pq.push({-dist[neighbour[node][i]][paisa-a[node][i]],{neighbour[node][i],paisa-a[node][i]}});	
  			}
  		}
  	}
  	int newpaisa=min(2500LL,paisa+c[node]);
  	if(dist[node][newpaisa]>dist[node][paisa]+d[node])
  	{
  		dist[node][newpaisa]=dist[node][paisa]+d[node];
  		pq.push({-dist[node][newpaisa],{node,newpaisa}});
  	}
  }
  vector<int> answer(n+1,inf);
  for(int i=2;i<=n;i++)
  	for(int j=0;j<=2500;j++)
  		answer[i]=min(answer[i],dist[i][j]);

  for(int i=2;i<=n;i++) cout<<answer[i]<<'\n';



  return 0;
}

Measured memory_bytes: 7292
def bubble_sort(seq):
    for i in range(len(seq)):
        flag = 0
        for j in range(len(seq)-1,i,-1):
            if seq[j-1][1] > seq[j][1]:
                seq[j-1],seq[j] = seq[j],seq[j-1]
                flag = 1
        if flag == 0: break
    return seq


def selection_sort(seq):
    for i in range(len(seq)):
        mini = i
        for j in range(i,len(seq)):
            if seq[mini][1] > seq[j][1]:mini = j
        seq[i],seq[mini] = seq[mini],seq[i]
    return seq



n = int(input())
*seq,= input().split()
seq2 = seq[:]

bl = bubble_sort(seq)
print(*bl)
print("Stable")
sl = selection_sort(seq2)
print(*sl)
if bl == sl:print("Stable")
else:print("Not stable")



Measured memory_bytes: 5616
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;

const int MAXN=200010;
vector<ll> v[MAXN],v2[MAXN];

int main(){FIN;
	int t; cin>>t;
	while(t--){
		ll n,ans=0; cin>>n;
		fore(i,0,n+1) v[i].clear(),v2[i].clear();
		fore(i,0,n){
			int k,l,r; cin>>k>>l>>r;
			if(l-r>0)	ans+=r,v[k-1].pb(l-r);
			else ans+=l,v2[k].pb(r-l);
		}
		multiset<ll> did;
		fore(i,0,n){
			for(auto x:v[i]){
				if(SZ(did)<i+1) did.insert(x);
				else if(*did.begin()<x) did.erase(did.begin()),did.insert(x);
			}
		}
		for(auto x:did) ans+=x;
		

		did.clear();
		for(int i=n-1;i>=0;i--){
			for(auto x:v2[i]){
				if(SZ(did)<(n-i)) did.insert(x);
				else if(*did.begin()<x) did.erase(did.begin()),did.insert(x);
			}
		}
		for(auto x:did) ans+=x;
		
		cout<<ans<<"\n";
	}
}

Measured memory_bytes: 22440
#include<bits/stdc++.h>
using namespace std;
struct activity {
    int A,B,C;
};
int solve(vector<activity>& v, int n) {
    int dp[n + 1][3];
    dp[1][0] = v[1].A;
    dp[1][1] = v[1].B;
    dp[1][2] = v[1].C;

    for(int i = 2; i <= n; i++) {
        dp[i][0] = v[i].A + max(dp[i- 1][1], dp[i - 1][2]);
        dp[i][1] = v[i].B + max(dp[i- 1][0], dp[i - 1][2]);
        dp[i][2] = v[i].C + max(dp[i- 1][1], dp[i - 1][0]);
    }
    return max(dp[n][0], max(dp[n][1], dp[n][2]));
}
int main() {
    int n;
    cin >> n;
    vector<activity> v(n+1);
    for(int i = 1; i <= n; i++) {
        cin >> v[i].A;
        cin >> v[i].B;
        cin >> v[i].C;
    }
    cout << solve(v, n);
}

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

using namespace std;

#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define F(i,x,n,y) for(i=x;i<n;i+=y)
#define fi(i,x,n) for(i=x;i<n;++i)
#define f(n) for(int i=0;i<n;++i)
#define fr(i,x,n) for(i=x;i>=n;--i)
#define endl '\n'

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

int ans[105][105];

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a,b;
    cin>>a>>b;
    int i,j;
    fi(i,1,101){
        fi(j,1,51){
            ans[i][j]=1;
        }
    }
    int cnt=0;
    F(i,1,101,2){
        int start=1;
        if(i%2==0){
            start=2;
        }
        F(j,start,51,2){
            if(cnt==a-1) break;
            ans[i][j]=0;
            ++cnt;
        }
        if(cnt==a-1) break;

    }
    cnt=0;
    F(i,1,101,2){
        int start=52;
        if(i%2==0){
            start=53;
        }
        F(j,start,101,2){
            if(cnt==b-1) break;
            ans[i][j]=1;
            ++cnt;
        }
        if(cnt==b-1) break;
    }
    cout<<"100 100"<<endl; 
    fi(i,1,101){
        fi(j,1,101){
            if(ans[i][j]==0) cout<<".";
            else cout<<"#";
        }
        cout<<endl;
    }


    return 0;
}


Measured memory_bytes: 256
//******* It's LEVI_17 ***************

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

#define ff first
#define ss second
#define MP make_pair
#define mset(x,a) memset(x,a,sizeof(x))
#define max3(x,y,z) max(x,max(y,z))
#define min3(x,y,z) min(x,min(y,z))
#define sqr(a) (a)*(a)
#define all(x) (x).begin(), (x).end()
#define f(i, n) for (int i = 0; i < n; i++)
#define f1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define vvll vector<vector<ll>>  
#define vll vector<ll> 
#define pll pair<ll,ll>
#define vpll vector<pll>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define cases ll t;cin >> t;while(t--)
#define rr return 0
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define deb(a)			std::cerr<<#a<<"="<<(a)<<"\n"
#define deb2(a,b)		std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define deb3(a,b,c)		std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
const int MOD = 1000 * 1000 * 1000 + 7;

//syntax for priority queue
// max queue -> priority_queue<ll>
// min queue -> priority_queue<ll,vector<ll>,greater<ll>>

//##############################################################################################

ll getRes(vll wt,vll val,ll n,ll w)
{
    ll sum_value = 0;
    for (auto x : val)
        sum_value += x;
    const ll INF = 1e18L + 5;
    vll dp(sum_value + 1, INF);
    dp[0] = 0;
    // dp[i] -> min total weight of items with value exactly equals i

    for (ll item = 0; item < n; ++item)
    {
        for (ll value_already = sum_value - val[item]; value_already >= 0; --value_already)
        {
            dp[value_already + val[item]] = min(dp[value_already + val[item]], dp[value_already] + wt[item]);
        }
    }
    ll ans = 0;
    for (ll i = 0; i <= sum_value; ++i)
    {
        if (dp[i] <= w)
            ans = max(ans, (ll)i);
    }

    return ans;

}

void solve()
{
    ll n,w;
    cin >> n >> w;
    vll wt(n),val(n);
    f(i, n)
        cin >> wt[i] >> val[i];
   
    ll res = getRes(wt,val, n,w);
    cout << res << "\n";
}

//###############################################################################################

int main()
{
    fast;
    ll t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    rr;
}


//Watashi wa tsuyoku modotte kimasu

Measured memory_bytes: 3972
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1000000000
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define f first
#define s second
#define pb push_back
//#define mp make_pair

int n, m, x, y, c, dist[1010], p[1010] ;
bool vis[1010];
map<pi, bool> mp;
vector<pi> adj[1010], v;


void djikstra(int s){
rep(i,1,n)dist[i]=inf;
rep(i, 1, n)vis[i]=false;
rep(i, 1, n)p[i]=i;
priority_queue<pi>  q;
q.push({0,s});
dist[s]=0;

while(!q.empty()){
    int a, u;
    tie(a,u)=q.top();
    q.pop();
    if(vis[u])continue;
    vis[u]=true;
    mp[{u,p[u]}]=true;
    mp[{p[u],u}]=true;

    for(auto t: adj[u]){
        int b, w;
        tie(b,w)=t;
        if(dist[b]>dist[u]+w){
            dist[b]=dist[u]+w;
            p[b]=u;
            q.push({-dist[b],b});
        }
    }
}


}

int main(){
int ans=0;
cin >> n >> m;
rep(i, 1, m){

cin >> x >> y >> c;
adj[x].pb({y,c});
adj[y].pb({x,c});
mp[{x,y}]=false;
mp[{y,x}]=false;
v.pb({x,y});
}

rep(i, 1, n){
djikstra(i);
}

for(auto t: v){
    int a, b;
    tie(a,b)=t;
    if(mp[{a,b}]||mp[{b,a}])ans++;
}

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


Measured memory_bytes: 512
N = input()
N = int(N)

count = 0

if N == 100000 :
  count = 90909
if N >= 10000 and N <= 99999 :
  count = N - 10000 + 1 + 900 + 9
if N >= 1000 and N <= 9999 :
  count = 909
if N >= 100 and N <= 999 :
  count = N - 100 + 1 + 9
if N >= 10 and N <= 99 :
  count = 9
if N >= 1 and N <= 9 :
  count = N

print(count)


Measured memory_bytes: 3060
N=int(input())
S=list(map(int,input().split()))

for i in range(N):
    v=S[i]
    j=i-1
    while j>=0 and S[j]>v:
        S[j+1] =S[j]
        j-=1
    S[j+1]=v
    Z=[str(a) for a in S]
    Z=" ".join(Z)
    print(Z)


Measured memory_bytes: 5604
// AOJ 2430 Longest Increasing Sequence
// 2018.5.13 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in()
{
	int n = 0, c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

#define INF 0x50505050
#define MAX_N  4002

typedef struct { long long s; int i; } TBL;
TBL tbl[MAX_N]; int sz;

long long s[MAX_N];
int dp[MAX_N][MAX_N];
int prev[MAX_N][MAX_N];
int ans[MAX_N];

int cmp(TBL *a, TBL *b)
{
	if (a->s == b->s) {
		if (a->i > b->i) return -1;
		return a->i < b->i;
	}
	if (a->s < b->s) return -1;
	return 1;
}

int main()
{
	int n, i, j;
	int cur, best, pos;

	n = in();
	for (i = 1; i <= n; i++) s[i] = s[i-1] + in();

	// dp[0,終点)での最長増加列長
	memset(dp, -INF, sizeof(dp));
	for (i = 0; i <= n; i++) dp[0][i] = 1;

    for (cur = 1; cur < n; cur++) {
		sz = 0;
        for (i = 0; i < cur; i++)    tbl[sz].s = s[cur]-s[i], tbl[sz++].i = i;
        for (i = cur+1; i <= n; i++) tbl[sz].s = s[i]-s[cur], tbl[sz++].i = i;
		qsort(tbl, sz, sizeof(TBL), cmp);

		best = -INF, pos = -1;
		for (i = 0; i < sz; i++) {
			j = tbl[i].i;
			if (j < cur) {
				if (best < dp[j][cur]) best = dp[j][cur], pos = j;
			} else if (j > cur) {
				if (dp[cur][j] < best+1) {
					dp[cur][j] = best+1;
					prev[cur][j] = pos;
				}
			}
		}
	}

	cur = -1, best = 0;
	for (i = 0; i < n; i++) {
		if (dp[i][n] > best) best = dp[i][n], cur = i;
	}

	sz = 0, i = n;
	while (cur > 0) {
		ans[sz++] = cur;
		j = prev[cur][i];
		i = cur, cur = j;
	}
	printf("%d\n", sz+1);
	if (sz) {
		printf("%d", ans[sz-1]);
		for (i = sz-2; i >= 0; i--) printf(" %d", ans[i]);
	}
	putchar('\n');
	return 0;
}



Measured memory_bytes: 109716
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+7;
typedef long long ll;
ll dp[maxn][57];
struct dian{
	int a,b;
};
vector<dian> ld;
vector<dian> ly;
dian store[maxn];
bool comp(const dian &a,const dian &b){
	return 1ll*b.a*(a.b+1)<1ll*a.a*(b.b+1);
}
bool cmp1(const dian &a,const dian &b){
	return a.b<b.b;
}
int ttime[maxn];
int main(){
	int n,t;
	cin>>n>>t;
	int a0=0,a1=0;
	for(int i=1;i<=n;i++) {
		scanf("%d%d",&store[i].a,&store[i].b);
		if(store[i].a==0){
			a0++;
			ld.push_back(store[i]);
		}
		else {
			a1++;
			ly.push_back(store[i]);
		} 
	}
	sort(ly.begin(),ly.end(),comp);
	for(int j=1;j<=50;++j)
		dp[0][j]=t+1;
	for(int i=1;i<=a1;i++){
		for(int j=1;j<=log(t)/log(2);j++){
			dp[i][j]=min(dp[i-1][j],dp[i-1][j-1]+1+1ll*ly[i-1].a*(dp[i-1][j-1]+1)+ly[i-1].b);
		}
	}
	int ans=0;
	sort(ld.begin(),ld.end(),cmp1);//按b升序排列 
//	int k=0;
/*	for(int i=0;i<ld.size();i++){
		ttime[k+1]=ld[i].b+1+ttime[k];
		k++;
	}*/
	for(int j=0;j<=log(t)/log(2);j++){
	/*	int sheng=t-dp[a1][j];
		int tmp=upper_bound(ttime+1,ttime+1+ld.size(),sheng)-ttime-1;
		if(j+tmp>ans)  ans=j+tmp; */ 
		int i;
		if(dp[a1][j]<=t){
			ll s=0;
			for( i=0;i<ld.size();i++){
				s+=ld[i].b+1;
				if(dp[a1][j]+s>t) break; 
			}
			ans=max(ans,j+i);
		}
	}
	cout<<ans;
	return 0;
}













Measured memory_bytes: 92528
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;
using ll = long long;
using ld = long double;

int main() {
    int N,M,C;
    vector<int> B;
    cin >> N >> M >> C;
    for (int i = 0; i < M; ++i) {
        int b;
        cin >> b;
        B.push_back(b);
    }
    int result = 0;

    for (int i = 0; i < N; ++i) {
        int r = 0;
        for (int j = 0; j < M; ++j) {
            int a;
            cin >> a;
            r += a * B[j];
        }
        r  += C;
        if(r > 0){
            result++;
        }
    }

    cout << result << endl;

    return 0;
}

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

using namespace std;

int main(){
int N, K ; cin >> N >> K;
  vector<int> A(N); for(int i = 0; i < N; i++){ cin >> A[i];}
  sort(A.begin(),A.end());
  
  vector<int> vec;
  int i = 0;
  while( i < N ){
    int j = i; int res = 0;
    while( A[j] == A[i] && j < N){
      res++; j++;}
    vec.push_back(res); i = j;}
  
  sort(vec.begin(),vec.end());
  int ans = 0;
  for(int i = 0; i < (int) vec.size() - K; i++){
    ans += vec[i];}
  cout << ans << endl; return 0;}
    

Measured memory_bytes: 2168
#include<bits/stdc++.h>
using namespace std;
long long n,i,a[87];
int main()
{
    cin>>n;
    a[0]=2;
    a[1]=1;
    for (i=2;i<=n;i++) a[i]=a[i-1]+a[i-2];
    cout<<a[n];
    return 0;
}

Measured memory_bytes: 256
#include	<iostream>
#include	<vector>
#include	<sstream>
#include	<iomanip>
#include	<algorithm>

using namespace std;

#define	MaxN 100000

long	A[ MaxN ];
long	B[ MaxN ];
long	C[ MaxN ];
int		P[ MaxN ];
long	F[ MaxN ];
long	S[ MaxN ];
vector< int >	wEdges[ MaxN ];

int
Get( int x ) {
    return ( x == P[ x ] ) ? x : P[ x ] = Get( P[ x ] );
}

void
Main() {
	int	N;	cin >> N;
	int	M;	cin >> M;

	int	wSortedIndex[ MaxN ];
	for ( auto i = 0; i < N; i++ ) {
        cin >> A[ i ] >> B[ i ];
        C[ i ] = max( A[ i ] - B[ i ], long( 0 ) );
        wSortedIndex[ i ] = i;
        P[ i ] = i;
        S[ i ] = B[ i ];
        F[ i ] = C[ i ];
    }
    auto	wRoot = distance( C, max_element( C, C+ N ) );

	for ( auto i = 0; i < M; i++ ) {
		int	wU;	cin >> wU;	wU--;
		int	wV;	cin >> wV;	wV--;
		wEdges[ wU ].emplace_back( wV );
		wEdges[ wV ].emplace_back( wU );
	}
	
    sort( wSortedIndex, wSortedIndex + N, []( int l, int r ) { return C[ l ] < C[ r ]; } );
	
	vector< bool >	wVisited( N, false );

    for ( auto i = 0; i < N; i++ ) {
        int u = wSortedIndex[ i ];
        wVisited[ u ] = true;
        for ( auto v : wEdges[ u ] ) {
        	if ( wVisited[ v ] ) {
				int x = Get( u );
				int	y = Get( v );
				if ( x == y ) continue;
				P[ y ] = x; S[ x ] += S[ y ];
				F[ x ] = min( F[ x ], max( C[ u ] - S[ y ], F[ y ] ) );
            }
        }
    }
    cout << F[ wRoot ] + S[ wRoot ] << endl;
}

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


Measured memory_bytes: 10620
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;



int main() {
	int n;
	string s;
	cin >> n >> s;
	
	map<char, int> m;
	for (int i = 0; i < n; i++) {
		m[s[i]]++;
	}

	ll cnt = 1;
	for (auto it = m.begin();it != m.end();it++) {
		cnt = (cnt * (it->second + 1)) % MOD_CONST;
	}
	cout << cnt - 1 << endl;
}



Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#define MAX 100005
using namespace std;
vector<int> maps[MAX];
int memo[MAX];
int indegree[MAX]={0};
//从i节点到结束所能达到的最长路径
int dfs(int x){
	if(memo[x]!=-1) return memo[x];
	
	int l=maps[x].size();
	int res=0;
	for(int i=0;i<l;i++){
		res= max(res,dfs(maps[x][i])+1);
	}
	memo[x]=res;
	return memo[x];
}
int main(){
	int n,m;
	scanf("%d %d",&n,&m);
	fill(memo,memo+MAX,-1);
	for(int i=0;i<m;i++){
		int from,to;
		scanf("%d %d",&from,&to);
		maps[from].push_back(to);
		indegree[to]+=1; 
	}
	
	int res=0;
	for(int i=1;i<=n;i++){
		if(indegree[i]==0){
			res = max(res,dfs(i));	
		} 
	}
	printf("%d",res);
	return 0;
} 

Measured memory_bytes: 11136
#include<bits/stdc++.h>
#define pf printf
#define sc(x) scanf("%d",&x);
#define scs(x) scanf("%s",x);
#define scl(x) scanf("%lld",&x);
#define rep(i,s,e) for(int i=s; i<=e; ++i)
#define dep(i,s,e) for(int i=s; i>=e; --i)
typedef long long ll;
using namespace std;
const double pi=acos(-1.0);
int main()
{
	ll a,c,d;
	double b;
	scl(a);scanf("%lf",&b);
	c=(long long)b;
	d=a*c;
	c=((long long)(b*100+0.5))%100;
	d+=a*c/100;
	pf("%lld\n",d);
}

Measured memory_bytes: 3804
#include<iostream>
#include<string>
#include<algorithm>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define repm(i, m, n) for (int i = (m); i < (n); i++)
#define rep_rev(i, n) for (int i = int (n); i >= 0; i--)
typedef long long ll;
using namespace std;

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

	int sum = 1;
	rep1(i, n)if (s[i - 1] != s[i])sum++;
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

using ll = long long;

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()

typedef pair<int, int> P;

const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;

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

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

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

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

#define MAX_N 100
#define MAX_M 1000

int n, m;
int a[MAX_M], b[MAX_M], c[MAX_M];

int d[MAX_N][MAX_N];

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> n >> m;
	
	REP(i, n) {
		REP(j, n) {
			if (i == j) d[i][j] = 0;
			else d[i][j] = INF;
		}
	}
	
	REP(i, m) {
		cin >> a[i] >> b[i] >> c[i];
		--a[i], --b[i];
		d[a[i]][b[i]] = c[i];
		d[b[i]][a[i]] = c[i];
	}
	
	REP(k, n) {
		REP(i, n) {
			REP(j, n) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	
	int ans = m;
	REP(i, m) {
		bool shortest = false;
		REP(j, n) {
			if (d[j][a[i]] + c[i] == d[j][b[i]]) shortest = true;
		}
		if (shortest) --ans;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int n,t,a[100005],r,ans;
int main(void){
    cin>>n>>t;
    for(int i=0;i<n;i++)cin>>a[i];
    int m=1000000000;
    for(int i=0;i<n;i++){
        m=min(m,a[i]);
        r=max(r,a[i]-m);
    }
    m=1000000000;
    for(int i=0;i<n;i++){
        m=min(m,a[i]);
        if(a[i]-m==r)ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<vector>
#include<string>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#pragma GCC target("avx")
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC diagnostic error "-std=c++14"

#define isNum(a) (a>='0'&&a<='9')
#define SP putchar(' ')
#define EL putchar('\n')
#define ri register int

template<class T>
inline void in(T&);
template<class T>
inline void out(const T&);

typedef long long ll;
using std::min;
using std::max;
using std::abs;
using std::sort;
using namespace std;

int a,b,c; 

int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    in(a);in(b);in(c);
    out(c);SP;out(a);SP;out(b);EL;
    return 0;
}

template<class T>
void in(T &Re)
{
    T k=0;
    char ch=getchar();
    int flag=1;
    while (!isNum(ch))
	{
        if (ch=='-')
		{
            flag=-1;
        }
        ch=getchar();
    }
    while (isNum(ch))
	{
        k=(k<<1)+(k<<3)+ch-'0';
        ch=getchar();
    }
    Re=flag*k;
}

template<class T>
void out(const T &Wr)
{
    if (Wr<0)
	{
        putchar('-');
        out(-Wr);
    }
	else
	{
        if (Wr<10)
		{
            putchar(Wr+'0');
        }
		else
		{
            out(Wr/10);
            putchar((Wr%10)+'0');
        }
    }
}




Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int n,m,k=0,tot=0,ans=0,head[10];
bool vis[10]={0};
struct edge{
	int u,v,next;
}e[200];
void add(int u,int v)
{
	e[++k].u=u;e[k].v=v;
	e[k].next=head[u];
	head[u]=k;
}
void dfs(int u)
{
	tot++;
	if(tot==n)
	{
		ans++;tot--;
		return;
	}
	vis[u]=1;
	for(int i=head[u];i;i=e[i].next)
	{
		int v=e[i].v;
		if(vis[v])continue;
		dfs(v);
	}
	tot--;vis[u]=0;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		add(u,v);add(v,u);
	}
	dfs(1);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define endl '\n'
const int mod=1e9+7,u=3e3+5;

int n,arr[u],dp[u][u];
int solve(int low,int high){
    if(dp[low][high]==-1){
        if(low==high){
            dp[low][high]=arr[low];
        }
        else{
        	dp[low][high]=max(arr[low]-solve(low+1,high),arr[high]-solve(low,high-1));
        }
    }
    return dp[low][high];
}

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

    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>arr[i];
    }

    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            dp[i][j]=-1;
        }
    }
    cout<<solve(1,n);

    return 0;
}

Measured memory_bytes: 70912
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios_base::sync_with_stdio(0);
    string s, t; cin >> s >> t;

    int ans = 0;
    for (int i=0;i<s.length();i++) {
        if (s[i]!=t[i]) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3832
import sys
sys.setrecursionlimit(10**6)

N = int(input())
A = list(map(int, input().split()))
B = [0] * 100003
for i in range(N):
    B[A[i]] += 1

max = 0
for i in range(100002):
    if max < B[i - 1] + B[i] + B[i + 1]:
        max = B[i - 1] + B[i] + B[i + 1]
print(max)

Measured memory_bytes: 13964
//Subhash Suman
//Date: 13/02/19 ; Day: Wednesday ; Time: 10::36::45 
//Description : 

#include<bits/stdc++.h>
#define ll long long int
#define MAX INT_MAX
#define MIN INT_MIN
#define vi vector<int>
#define pii pair<int,int>
#define mii map<int,int>

using namespace std;
const int N = 1e5+5;

class Graph{
public:
    int v;
    int e;
    unordered_map<int,vector<int>> mp;
    unordered_map<int,int> dist;
void addEdge(int x,int y){
    mp[x].push_back(y);
}
int dfs(int x){
    if(mp.count(x)==0){
        return 0;
    }
    if(dist.count(x)==0){    
        int y = 0;
        for(auto a : mp[x]){
            y = max(y,1+dfs(a));
        }
        dist[x] = y;
        return y;
    }
    else {
        return dist[x];
    }

}
int func(){
    int M=0;
    for(auto a : mp){
        if(dist.count(a.first)==0){
            M = max(dfs(a.first),M);
        }
    }
    return M;
}
};

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
    int v,e;
    cin>>v>>e;
    Graph g;
    g.v = v;
    g.e = e;
    for(int i = 0; i < e; i++){
        int a,b;
        cin>>a>>b;
        g.addEdge(a,b);
    }
    int x = g.func();
    cout<<x<<'\n';
    return 0;
}

Measured memory_bytes: 14884
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<stack>
#include<string>
#include<bitset>
#include<random>
#include<time.h>
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<(ll)m; i++)
#define FOR(i,n,m) for(long long i=n; i<(ll)m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	vector<ll> a(3);
	ll k;
	REP(i,3) cin>>a[i];
	cin>>k;
	sort(ALL(a));
	a[2]*=(1<<k);
	cout<<a[0]+a[1]+a[2]<<endl;
}


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

int main() {
        int i, j;
        int n, l, t;
        cin >> n >> l >> t;
        vector<int> x(n), w(n);
        for (i = 0; i < n; i ++) cin >> x[i] >> w[i];
        int cnt = 0;
        if (w[0] == 1) {
                for (i = 1; i < n; i ++) {
                        if (w[i] == 1) continue;
                        int dis = x[i] - x[0];
                        int k = t;
                        cnt = (cnt + (int)(k / l) * 2) % n;
                        k %= l;
                        if ((dis + 1) / 2 <= k) cnt = (cnt + 1) % n;
                        if (dis + (l - dis + 1) / 2 <= k) cnt = (cnt + 1) % n;
                }
        } else {
                for (i = 1; i < n; i ++) {
                        if (w[i] == 2) continue;
                        int dis = l - (x[i] - x[0]);
                        int k = t;
                        cnt -= (int)(k / l) * 2;
                        while (cnt < 0) {
                                cnt += n;
                        }
                        cnt %= n;
                        k %= l;
                        if ((dis + 1) / 2 <= k) cnt = ((cnt - 1) + n) % n;
                        if (dis + (l - dis + 1) / 2 <= k) cnt = ((cnt - 1) + n) % n;
                }
        }
        cnt %= n;
        //cerr << "cnt = " << cnt << endl;
        vector<pair<int, int>> y(n);
        for (i = 0; i < n; i ++) {
                if (w[i] == 1) {
                        y[i].first = (x[i] + t) % l;
                } else {
                        y[i].first = (x[i] - (t % l) + l) % l;
                }
                y[i].second = i;
        }

        if (w[0] == 1) {
                sort(y.begin(), y.end(), [](const pair<int, int>& a, const pair<int, int>& b) {
                        return (a.first == b.first ? (a.second > b.second) : a.first < b.first);
                });
        } else {
                sort(y.begin(), y.end());
        }
        //for (i = 0; i < n; i ++) cerr << y[i].first << ' ' << y[i].second << endl;
        int p;
        vector<int> ans(n);
        for (i = 0; i < n; i ++) {
                if (y[i].second == 0) {
                        ans[cnt] = y[i].first;
                        p = i;
                        break;
                }
        }
        for (i = 0; i < cnt; i ++) ans[i] = y[(p - cnt + i + n) % n].first;
        for (i = cnt + 1; i < n; i ++) ans[i] = y[(p + i - cnt) % n].first;
        for (i = 0; i < n; i ++) cout << ans[i] << endl;
        return 0;
}



Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
#define modul 1000000007

int main()
{
    int n;
    scanf("%d",&n);
    long long res=0;
    long long a[n];
    long long sum[n]={0};
    for(int i=0;i<n;i++)
    {
        scanf("%lld",&a[i]);
        if(i>0)
            sum[0]+=a[i];
        //sum[0]+=a[i];
        //sum[0]=modul;
    }
   // cout<< sum[0]<< " ";
    for(int i=1;i<n-1;i++)
    {

        sum[i]= sum[i-1]-a[i];
        //cout<< sum[i]<< " ";
    }
    cout<< endl;
    for(int i=0;i<n-1;i++)
    {
        res += ((sum[i]%modul)*a[i])% modul;
        res %= modul;
    }
    printf("%lld",res);
}



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

int main() {
    using namespace std;
    constexpr int maxN = 200010;
    int N;
    scanf("%d", &N);
    array<int, maxN> perm;
    {
        array<pair<int, int>, maxN> p;
        for(int i = 0; i < N; ++i)scanf("%d%d", &p[i].first, &p[i].second);
        sort(p.begin(), p.begin() + N);
        for(int i = 0; i < N; ++i)p[i] = {p[i].second, i + 1};
        sort(p.begin(), p.begin() + N);
        transform(p.cbegin(), p.cbegin() + N, perm.begin(), [](auto i){return i.second;});
    }

    constexpr unsigned long MOD = 998244353;
    array<unsigned long, maxN> binary;
    unsigned long n = binary[0] = 1;
    generate(binary.begin() + 1, binary.end(), [&n](){if(n >= MOD)n -= MOD;return n <<= 1;});

    array<int, maxN> fenwick_tree{};
    auto que = [&fenwick_tree, &N](int i){
        int s{0}, j{i};
        while(i){
            s += fenwick_tree[i];
            i -= i & -i;
        }
        while(j <= N){
            ++fenwick_tree[j];
            j += j & -j;
        }
        return s;
    };

    array<int, maxN> coef{};
    coef[N] = N + MOD - 4;
    for(int i = 0; i != N; ++i){
        auto p = perm[i], q = que(p);
        ++coef[q];
        ++coef[i - q];
        ++coef[p - q - 1];
        ++coef[N - i - p + q];
    }

    cout << inner_product(binary.begin(), binary.begin() + N + 1, coef.begin(), 4 + MOD - N) % MOD << endl;
    return 0;
}

Measured memory_bytes: 4096