akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int N;
    cin >> N;
    int ans = 0;
    int count = 1;
    vector<int> a(N);
    rep(i, N)
    {
        cin >> a.at(i);
        if (a.at(i) != count)
        {
            ans++;
        }
        else
        {
            count++;
        }
    }
    if (count == 1)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << ans << endl;
    }
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < n; ++i)
#define FORR(i, m, n) for (ll i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
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; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;cin >> s;
    int n=s.size();
    if(s[0]=='0'||s[n-1]=='1'){
        cout << -1 << endl;
        return 0;
    }
    REP(i,n-1){
        if(s[i]!=s[n-2-i]){
            cout << -1 << endl;
            return 0;
        }
    }
    int t=1;
    REP(i,n-1){
        cout << t << " " << i+2 << endl;
        if(s[i]=='1'){
            t=i+2;
        }
    }
}

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


int main(){
  
  
  long long x;
  cin>>x;
  int flag = 0;
  int A,B;
  for(int i=-1000 ;i<=1000;i++){
   for(int j=-1000;j<=1000;j++){
    long long a=i,b=j;
	A = a;
	B = b;
     for(int k=1;k<=4;k++){
      a = a*i;
       b = b*j;
     }
	 //A =a;
	 //B = b;
     if(a - b == x)
      	flag = 1;
      
     if(flag == 1)
       break;
       
   }
    if(flag == 1)
      break;
  }
  cout<<A<<" "<<B<<endl;
  
  
  
  
 return 0; 
  
  
}

Measured memory_bytes: 3432
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e15;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k, t;
    cin >> k >> t;
    int MAX = 0;
    vector<int> a(t);
    rep(i, 0, t){
        cin >> a[i];
        chmax(MAX, a[i]);
    }
    if(t == 1){
        cout << k - 1 << endl;
        return 0;
    }
    int rest = k - MAX;
    int ans = k - rest * 2;
    cout << max(0LL, ans - 1) << endl;
}

Measured memory_bytes: 256
s=input()
t=input()
n=len(s)
m=len(t)
dp=[[0 for _ in range(m+1)] for _ in range(n+1)]
for i in range(n):
  for j in range(m):
    if s[i]==t[j]:dp[i+1][j+1]=dp[i][j]+1
    else:dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j],dp[i+1][j+1])
ans=''
while n*m:
  if s[n-1]==t[m-1]:
    ans+=s[n-1]
    n-=1
    m-=1
  else:
    if dp[n-1][m]>dp[n][m-1]:n-=1
    else:m-=1
print(ans[::-1])

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

#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

ll mod=1;

const ll INF = 1LL << 60;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

// a^n mod を計算 再帰
ll modpow(ll a,ll n,ll &mod){
  if(!n) return 1;
  ll x = modpow(a,n/2,mod)%mod;
  x *=x;
  if(n%2==1)x*=a;
  return x%mod;
}



int main(){
  int x;cin>>x;
  int ans=1;
  for(int i=2;i*i<=x;i++){
    for(int j=i*i;j<=x;j*=i)chmax(ans,j);
  }
  cout<<ans;
}


Measured memory_bytes: 384
#include<stdio.h>
#define N 1000
int main(void){
  int i,j,n,A[N];
  int v;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  
  for(j=0;j<n-1;j++) printf("%d ",A[j]);
  printf("%d\n",A[n-1]);

  for(i=1;i<n;i++){
    v = A[i];
    j = i - 1;
    while(j>=0 && A[j]>v){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    for(j=0;j<n-1;j++) printf("%d ",A[j]);
    printf("%d\n",A[n-1]);
  }
}


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

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

  long long ans=0;
  int pst=0, st;
  rep(i, N-1) {
    st = A[i] + pst - A[i+1];
    if (st > 0) {
      ans += st;
      pst = st;
    }
    else {
      pst = 0;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 4024
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll h, a;
  cin >> h >> a;
  cout << (h+a-1)/a << newl;
}

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

#define ll long long
#define rep(i,n) for(ll i=(ll)(0); i<(ll)(n); ++i)
#define irep(i,m,n) for(ll i=(ll)(m); i<(ll)(n); ++i)
#define vi vector<int>

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

const long long MOD = 1e9 + 7;

signed main()
{
  int n;
  cin>>n;
  vector<vi> a(2, vi(n+1));
  
  rep(i,2) rep(j,n) cin>>a[i][j+1];
  
  vector<vi> s(2, vi(n+1));
  a[0][0]=0;
  s[0][0]=0;
  rep(i,2) rep(j,n){
    s[i][j+1]=s[i][j]+a[i][j+1];
  }
  
  int ans=0;
  rep(i,n){
    chmax(ans,s[0][i+1]+s[1][n]-s[1][i]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
// i_m_arin

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef priority_queue<ll> pqll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef map<ll,ll> mpll;
typedef set<ll> stll;

#define f(i, a, n) 	for(ll i=a; i<(ll)n; i++)
#define f2(i, a, b) for(ll i=a; i<=(ll)b; i++)
#define pb 			push_back
#define ff 			first
#define ss 			second
#define pf			push_front
#define mp			make_pair
#define all(a)		(a).begin(),(a).end()
#define decimal(x)	fixed<<setprecision(x)
#define fsort(a)	sort(all(a))
#define rsort(a)	sort(all(a),greater<>())
#define fast_io		ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mem0(a)		memset(a,0,sizeof(a))
#define mem1(a)		memset(a,-1,sizeof(a))
#define lcm(a,b)	(a*b)/__gcd(a,b)
#define ub(v,x)		upper_bound(all(v),x)-v.begin()
#define lb(v,x)		lower_bound(all(v),x)-v.begin()

const ld PI  = acos(-1);
const ll MOD = 1e9+7;
const ll INF = LLONG_MAX;
const ll SIZE= 100000;


void solve(){
string s;
cin>>s;
ll sum=0;
f(i,0,s.size()){
	sum+=s[i]-'0';
}
if(sum%9==0){
	cout<<"Yes"<<endl;
}
else{
	cout<<"No"<<endl;
}
}

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

Measured memory_bytes: 3788
def main():
    from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #r = input()
    #n = int(input())
    #a, b = map(int, input().split())
    #s, y = input().split()
    #a = input().split()
    #a = [int(input()) for i in range(n)]
    #a = list(map(int, input().split()))
    #a = [list(map(int, input().split())) for i in range(n)]
    #a = [int(s) - 1 for s in input().split()]
    #l=[int(input()) for _ in range(int(input()))]
    #res = 0

    n= int(input())
    x = list(map(int, input().split()))
    avr = sum(x) // len(x)
    avr2 = avr + 1
    x2 = [(i-avr)**2 for i in x]
    x3 = [(i-avr2)**2 for i in x]
    print(min(sum(x2),sum(x3)))

if __name__ == '__main__':
    main()


Measured memory_bytes: 38352
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    int n;
    cin >> n;
    int a[n] = {};
    int b[n - 1];
    rep(i, n - 1) { cin >> b[i]; }

    a[0] = b[0];
    repd(i, 1, n - 1) { a[i] = min(b[i - 1], b[i]); }
    a[n - 1] = b[n - 2];

    ll ans = 0;
    rep(i, n) {
        // cout << a[i] << ",";
        ans += a[i];
    }

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

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

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

void prime_map(map<ll, ll> &m, ll num) {
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }

    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }
        return;
    } else {
        prime_map(m, num);
    }
}


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

int main()
{
  int A,B;
  int res=0;
  cin >> A >> B;

  int sum=1;
  if (B==1) {
    cout << 0 << endl;
    return 0;
  }
  for(;;){
    sum = sum - 1 + A;
    res++;
    if(B <= sum) break; 
  }
  
  cout << res << endl;
  return 0;
}



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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

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


int main(void){

	int N; cin >> N;
	vector<int> B(N-1);

	REP(i,N-1) cin >> B[i];


	ll ans = B[0] + B[N-2];

	REP(i,N-2){
		ans += min(B[i], B[i+1]);
	}

	cout << ans << endl;

	return 0;

	}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

signed main(){
	int N;
	vint v(5);
	cin>>N;
	rep(i,5)cin>>v[i];

	int mi=*min_element(all(v));
	cout<<5+(N-1)/mi<<endl;
	return 0;
}

Measured memory_bytes: 256
-- import Data.List (nub, sort)

main :: IO ()
main = do
    [n,m] <- map read . words <$> getLine
    print $ solve n m

-- |
-- >>> solve 2 2
-- 8
-- >>> solve 3 2
-- 12
-- >>> solve 1 8
-- 0
-- >>> solve 100000 100000
-- 530123477
solve :: Integer -> Integer -> Integer
solve n m
  | abs (n - m) >= 2 = 0
  | n == m = n' * m' * 2 `mod` base
  | otherwise = n' * m' `mod` base
  where
    n' = fact n `mod` base
    m' = fact m `mod` base

base :: (Eq a, Num a) => a
base = 10 ^ (9 :: Int) + 7

fact :: (Eq a, Num a, Integral a) => a -> a
fact 0 = 1
fact n = (n * fact (n - 1)) `mod` base



Measured memory_bytes: 7804
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


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

pa = factorization(a)
pb = factorization(b)

print(len(({1} | {x for x, y in pa}) & ({1} | {x for x, y in pb})))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;



int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//ios_base& scientific (ios_base& str);
string s;
cin >> s;
string ans;
for(int i=0; i<s.length(); i++){
	if(s[i]=='0')
		ans+='0';
	else if(s[i]=='1')
		ans+='1';
	else if(s[i]=='B' && i!=0){
		ans= ans.substr(0, ans.length()-1);
	}
}
cout << ans << endl;
return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python3
#ABC62 B

h,w = map(int,input().split())

x = ['#']*(w+2)
a = [list(input()) for _ in range(h)]
for i in range(h):
    a[i].insert(0,'#')
    a[i].append('#')
a.insert(0,x)
a.append(x)
for i in range(h+2):
    print(''.join(a[i]))


Measured memory_bytes: 38384
s = int(input())
l = [False for _ in range(10**6)]
for i in range(1, 10**5 + 1):
  if l[s]:
    print(i)
    exit()
  l[s] = True
  if s % 2 == 0:
    s = s // 2
  else:
    s = 3 * s + 1

Measured memory_bytes: 10904
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

int main(){
  int N, M;
  cin >> N >> M;
  vector<pair<long, long> > X(N);
  long price, number;
  for(int i=0;i<N;i++){
    cin >> price >> number;
    X[i] = make_pair(price, number);
  }
  sort(X.begin(), X.end());
  long res = 0;
  for(int i=0;i<N;i++){
    if(M>X[i].second){
      M -= X[i].second;
      res += X[i].first * X[i].second;
    }else{
      res += X[i].first * M;
      break;
    }
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 1792
import sys
input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

#import numpy as np

def main():
	n,k=MI()
	A=LI()
	p=[]
	m=[]
	mod=10**9+7

	for i in A:
		if i>=0:
			p.append(i)
		else:
			m.append(i)
	p.sort(reverse=True)
	m.sort()
	#print(p,m)

	ans=1
	if (p==[] and k%2==1):
		for i in range(k):
			ans*=m[-i-1]
			ans%=mod
			#print(k,ans)

	elif n==k:
		for i in range(n):
			ans*=A[i]
			ans%=mod

	else:
		i=0
		j=0
		pl=len(p)
		ml=len(m)
		while k>=2:
			if i+2<=pl and j+2<=ml:
				pp=p[i]*p[i+1]
				mm=m[j]*m[j+1]
				if pp>mm:
					ans*=pp
					ans%=mod
					i+=2
				else:
					ans*=mm
					ans%=mod
					j+=2
			elif i+2<=pl:
				pp=p[i]*p[i+1]
				ans*=pp
				ans%=mod
				i+=2
			else:
				#print(i,j)
				mm=m[j]*m[j+1]
				ans*=mm
				ans%=mod
				j+=2
			k-=2

		if k==1:
			ans*=p[i]
			ans%=mod
	print(ans)



if __name__ == "__main__":
	main()


Measured memory_bytes: 99460
import math
MOD = 1000000007
N = int(input())
d_p = dict()
d_m = dict()
zz = 0
for n in range(N):
    a,b = map(int,input().split())

    if a==0 and b==0:
        zz += 1
        continue
    if a==0:
        n_sign = 1
        a=0
        b=0
    elif b==0:
        n_sign = 0
        a=0
        b=0  


    else:    
        n_sign = ((a<0) + (b<0))%2
        a = abs(a)
        b = abs(b)
        gcd = math.gcd(a,b)
        a//=gcd
        b//=gcd
        #print(n_sign,a,b)

    

    if n_sign==1:
        s =str(b)+'/'+str(a)
        d_m[s] = d_m.get(s,0) + 1
    elif n_sign==0:
        s =str(a)+'/'+str(b)
        d_p[s] = d_p.get(s,0) + 1      
    
#print (d_m,d_p)

ans = 1
for k,v in d_m.items():
    if k in d_p:
        ans *= (2**v + 2**d_p[k] - 1)
        
        d_p.pop(k)
    else:
        ans *= 2**v
    ans %= MOD

for k,v in d_p.items():
    ans *= 2**v
    ans %= MOD
ans -= 1
ans += zz
ans %= MOD
print (ans)


Measured memory_bytes: 38192
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stack>

using namespace std;

int common_time=1,n;

int table[101][101],time_table[101][2];

void func(int node){
	if(time_table[node][0] == 0){
		time_table[node][0] = common_time++;
	}else{
		return;
	}
	for(int i=1;i<=n;i++){
		if(table[node][i] == 1){
			func(i);
		}
	}
	time_table[node][1] = common_time++;
}

int main(){
	int row,num,col;
	scanf("%d",&n);

	for(int i=1;i<=n;i++){
		for(int k=1;k<=n;k++){
			table[i][k]=0;
		}
		time_table[i][0]=0;
		time_table[i][1]=0;
	}

	for(int i=1;i<=n;i++){
		scanf("%d %d",&row,&num);
		for(int k=1;k<=num;k++){
			scanf("%d",&col);
			table[row][col]=1;
		}
	}

	for(int i=1;i<=n;i++){
		func(i);
	}

	for(int i=1;i<=n;i++){
		printf("%d %d %d\n",i,time_table[i][0],time_table[i][1]);
	}

    return 0;
}



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

Measured memory_bytes: 580
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int n;
    char s[100010][10];
    cin >> n;
    map<string, int> mp;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        sort(s[i], s[i]+10);
        if (mp.find(s[i]) == mp.end()) {
            mp[s[i]] = 1;
        }
        else {
            ans += mp[s[i]];
            mp[s[i]]++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 12160
#include <bits/stdc++.h>
 
#define int long long
#define a(a, b) ((a) = ((a) + (b) + M) % M)
#define f(a) for (int i = 1; i <= a; i++)
 
const int N = 200000 + 10;
const int M = 998244353;
 
int n, c, q;
char s[N];
 
int w (int b, int p) {
    int r = 1;
    while (p) { if (p & 1) r = r * b % M; b = b * b % M; p >>= 1; }
    return r;
}
 
signed main() {
    scanf("%s", s + 1); n = strlen(s + 1);
    f(n - 1) c += s[i] != s[i + 1];
    f(n) (q += s[i] - 'a') %= 3;
    if (!c) return puts("1"), 0;
    int t = w(2, n - 1), r = w(3, n - 1);
    a(r, (c == n - 1) - t);
    if (n % 3) return printf("%lld", r), 0;
    t = w(2, n / 3 - 1);
    if (!q) t = ((M - t) * 2ll + (n == 3) * (M - 1)) % M;
    printf ("%lld", a(r, t));
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
 
using namespace std;
 
int main(){
    
    int n;
    
    cin >> n;

    auto ans = n / 111;

    if(n % 111 != 0) ans++;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int n;
    cin >> n;
    vint l(n);
    rep(i, n) cin >> l[i];
    vint rl = l;
    sort(rall(rl));

    int ans = 0;
    rep(i, n-2) {
        srep(j, n-1, i+1) {
            int stick = 0;
            srep(k, n, j+1) {
                if (rl[k] > rl[i] - rl[j]) stick++;
            }
            ans += stick;
        }
    }

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

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	
	public static void main(String[] args) throws IOException {
		new Main().input().solve().output();
	}
	
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//	InputUtil in = new InputUtil();
	PrintWriter out = new PrintWriter(System.out);
	int H = 0;
	int W = 0;
	String[] matrix = null;
	int[] charCount = new int[26]; 
	boolean ans = true;
	public Main input() throws IOException {
		String[] tmp = br.readLine().split(" ");
		H = Integer.parseInt(tmp[0]);
		W = Integer.parseInt(tmp[1]);
		matrix = new String[H];
		for(int i=0; i<H; i++) {
			matrix[i] = br.readLine();
		}
		return this;
	}

	public Main solve() throws IOException {
		for(int i=0; i<H; i++) {
			lineCheck(matrix[i],charCount);
		}
		int maxOdd = (H%2) * (W%2);
		int maxMultiple2 = (H/2)*(W%2) + (W/2)*(H%2);
		int countOdd=0;
		int countMultiple2=0;
		for(int i=0; i<26; i++) {
			if(charCount[i]%4 != 0){
				if(charCount[i]%2 != 0){
					countOdd++;
					if(countOdd>maxOdd){
						ans=false;
						return this;
					}
				}else{
					countMultiple2++;
					if(countMultiple2>maxMultiple2){
						ans=false;
						return this;
					}
				}
			}
		}
		return this;
	}
	
	public Main output() {
		out.println(ans ? "Yes" : "No");
		out.flush();
		return this;
	}
	
	private void lineCheck(String s, int[] check) {
		int len = s.length();
		for(int i=0; i<len; i++) {
			check[s.charAt(i)-'a']++;
		}
	}
}

Measured memory_bytes: 23124
n = int(input())
exps = [0] * 1003

for i in range(2, n+1):
    t = i
    div = 2
    while div*div <= n:
        if t % div == 0:
            exps[div] += 1
            t //= div
        else:
            div += 1
    if t != 1:
        exps[t] += 1

ans = 1
mod = int(1e9) + 7

for i in range(2, n+1):
    ans *= (exps[i] + 1)
    ans %= mod

print(ans)

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

using namespace std;

int main(){
	int N, t[50];
	string s[50];
	cin >> N;
	for(int i = 0; i < N; i++)cin >> s[i] >> t[i];
	string X;
	cin >> X;
	
	bool f = false;
	int ans = 0;
	for(int i = 0; i < N; i++){
		if(!f && X == s[i])f = true;
		else if(f){
			ans += t[i];
		}
	}
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(NULL);
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...)       \
	F_ORC(__VA_ARGS__) \
	(__VA_ARGS__)

#define E_ACH2(x, a) for (auto &x : a)
#define E_ACH3(x, y, a) for (auto &[x, y] : a)
#define E_ACH4(x, y, z, a) for (auto &[x, y, z] : a)
#define E_ACHC(...) GET5(__VA_ARGS__, E_ACH4, E_ACH3, E_ACH2)
#define EACH(...)       \
	E_ACHC(__VA_ARGS__) \
	(__VA_ARGS__)

template <typename A, typename B>
inline void chmin(A &a, B b)
{
	if (a > b)
		a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b)
{
	if (a < b)
		a = b;
}

int main()
{
	fast;
	ll n, k;
	cin >> n >> k;
	vll a(n);
	FOR(n)
	{
		cin >> a[i];
	}
	sort(all(a));
	ll ans = 0;
	FOR(n - k)
	{
		ans += a[i];
	}
	cout << ans;
}

Measured memory_bytes: 4704
import java.util.Scanner;

public class Main {
    public static void main (String args[]){
    	Scanner str = new Scanner(System.in);
    	int a = str.nextInt();
    	int b = str.nextInt();
    	int c = str.nextInt();
    	if ( a < b & b <c){
    		System.out.println("Yes");
    	}else{
    		System.out.println("No");
    	}
    }
}

Measured memory_bytes: 26180
from copy import copy
import numpy as np

H,W,K=map(int,input().split())
c=np.array([list(input()) for _ in range(H)])
red_h=np.array(["R"]*W)
red_w=np.array(["R"]*H).reshape((H,1))

ans=0
for i in range(2**H):
    tmp1=copy(c)
    for j in range(H):
        if i%2==1:
            tmp1[j,:]=red_h
        i//=2
    for k in range(2**W):
        tmp2=copy(tmp1)
        cnt=0
        for l in range(W):
            if k%2==1:
                tmp2[:,l]=red_w[:,0]
            k//=2
    
        for h in range(H):
            for w in range(W):
                if tmp2[h,w]=="#":
                    cnt+=1
        if cnt==K:
            ans+=1
print(ans)

Measured memory_bytes: 27200
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ans = (int) (Math.ceil(((double) a + (double) b) / 2));
        System.out.println(ans);
    }
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

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

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> A(N-1);
    vector<int> B(N);
    REP(i, N-1) cin >> A[i];
    REP(i, N) B[i] = 0;
    REP(i, N-1) B[A[i]-1]++;
    REP(i, N) cout << B[i] << endl;
    return 0;
}


Measured memory_bytes: 4840
#include<bits/stdc++.h>
#include<ctype.h>
# define pb push_back
#define fst first
#define sec second
#define For(i,a,b) for(int i=a;i<b;i++)
#define ll long long int
#define ull unsigned long long int
#define mod 1000000007
#define fo(i,n) for(ll i=0;i<n;i++)
#define endl "\n"
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define boolsize 1000001
#define pi pair<ll,ll>
#define vi vector<ll>
#define vii vector<pi>
using namespace std;
template<typename T>
void showvector(vector <T> v)
{
    for(T x:v)
        cout<<x<<" ";
    cout<<endl;

}
template<typename T>
void showvector1(vector <T> v)
{
    ll n=v.size();
    fo1(i,n-1)
        cout<<v[i]<<endl;

}
template<typename T>
void showset(set <T> s)
{
    for(T x: s)
        cout<<x<<" ";
    cout<<endl;
}
template<class T>
void showvectorpair(vector<T> v)
{
    for(auto it=v.begin();it!=v.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T,typename P>
void showmap(map <T,P> m)
{
    for(auto it=m.begin();it!=m.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T>
bool comp(T a,T b)
{
    return (a>b);
}
template<class T>
bool comppair(T a,T b)
{
    if(a.first==b.first)
        return(a.second>b.second);
    return (a.first>b.first);
}
bool sameparity(ll a,ll b)
{
    return (a%2==b%2);
}
bool difparity(ll a,ll b)
{
    return !(a%2==b%2);
}
bool isprime(ll x)
{   if(x<=1)
     return false;
    for(ll i=2;i<=sqrt(x);i++)
    {
        if(x%i==0)
            return false;
    }
    return true;
}
bool iseven(ll x)
{
    return !(x%2);
}
bool isodd(ll x)
{
    return (x%2);
}
/// check for test case before submitting
void vfun()
{
    ll n,k;
    cin>>n;
    vector <ll> v(n);
    fo(i,n)
    cin>>v[i];

}

int main()
{
//    #ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//    #endif
    ios_base::sync_with_stdio(0); ///cant use scanf, printf
    cin.tie(0);cout.tie(0); /// no longer auto flush cout before each cin, remove for interactive
    //cout << fixed << setprecision(11); /// no scientific output
    ll test=1;
    //cin>>test;
    while(test--)
    {
            ll n;
            cin>>n;
            ll pos,t=0;
            t=sqrt(2*n);
            pos=((t+1)*(t))/2;
            if(n>pos)
            t+=(n-pos);
            cout<<t;
//         if(vfun())
//            cout<<"YES\n";
//         else
//            cout<<"NO\n";
    }
}
///before sub
/// check for value of zero and single input in array
///loop vars,1LL in mult, equal, one, bounds, int v ll, endl, finish taking inputs
/// check whether test cases are given or not





Measured memory_bytes: 3624
#!/usr/bin/env python
import sys

N = int(input())
H = list(map(int, input().split()))

max_ = 0
if N == 1:
    print('Yes')
else:
    for i in range(N):
        if H[i] < max_:
            print('No')
            sys.exit(0)
        else:
            if H[i] == max_:
                pass
            else:
                max_ = max(1, H[i]-1)
            # print('max:{}'.format(max_))
    print('Yes')

Measured memory_bytes: 14252
#include <iostream>
#include <iomanip>
#include <string>
#include <unordered_map>
#include <cmath>
#include <algorithm>

typedef long long ll;
typedef long double ld;

using namespace std;
int main()
{
  int m, n;
  cin >> n >> m;
  cout << (m == n ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

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

int main()
{
        int n, a[100010];
        scanf("%d", &n);
        for (int i = 0; i < n; i++)
        {
                scanf("%d", &a[i]);
        }
        int left[100010], right[100010];
        left[0] = a[0];
        for (int i = 1; i < n; i++)
        {
                left[i] = gcd(left[i - 1], a[i]);
        }
        right[n - 1] = a[n - 1];
        for (int i = n - 2; i >= 0; i--)
        {
                right[i] = gcd(right[i + 1], a[i]);
        }
        int ans = right[1];
        if (ans < left[n - 2])
        {
                ans = left[n - 2];
        }
        for (int i = 1; i < n - 1; i++)
        {
                if (ans < gcd(left[i - 1], right[i + 1]))
                {
                        ans = gcd(left[i - 1], right[i + 1]);
                }
        }
        printf("%d", ans);
}

Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <climits>
#include <string.h>
#include <algorithm>

using namespace std;
#define fast ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define pb push_back
#define sz(s) (int)s.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = (int) 1e5 + 77;

int main(){
    fast;
    ll n,m,x;
    ll d[2222];
    cin>>n>>m;
    vector<ll> v[2222];
    forn(i,m){
        forn(j,3){
            cin>>x;
            v[i].push_back(x);
        }
    }
    
    forn(i,n+1){
        d[i] = -1e16;
    }
    
    d[1]=0;
    
    forn(i,n-1){
        forn(j,m){
            if(d[v[j][1]]<d[v[j][0]]+v[j][2]){
                d[v[j][1]] = d[v[j][0]] + v[j][2];
            }
        }
    }
    
    ll ans = d[n];
    
    forn(i,n-1){
        forn(j,m){
            if(d[v[j][1]]<d[v[j][0]]+v[j][2]){
                d[v[j][1]] = d[v[j][0]] + v[j][2];
            }
        }
    }
    
    if(d[n]>ans)
        cout<<"inf\n";
    else
        cout<<d[n]<<endl;
    
    return 0;
}


Measured memory_bytes: 384
import sys
import collections
import itertools
#def input(): return sys.stdin.readline().strip()
#def INT(): return int(input())
#def MAP(): return map(int, input().split())
#def LIST(): return list(map(int, input().split()))

n,k = map(int, input().split())

A = []
for i in range(k):
    d = input()
    A.append(tuple(map(int, input().split())))

c = list(itertools.chain.from_iterable(A))
ans1 = collections.Counter(c)

print(n-len(ans1))

Measured memory_bytes: 9468
#include<iostream>
#include<vector>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <map>
#include<cmath>
#include <queue>
#include <stack>
#include <numeric>
#include <cassert>
#include<map>
#include<bitset>

using lli = long long int;
lli inf = 1000000007;
using namespace std;


void solve() {
	string S;
	cin >> S;
	int Q;
	cin >> Q;
	bool inversion = false;
	vector<string> q;
	vector<string> s;
	for (int i = 0; i < Q; i++) {
		int Ti;
		cin >> Ti;
		if (Ti == 1) {
			// 反転する
			inversion = !inversion;
		}
		else if (Ti == 2) {
			int Fi;
			string Ci;
			cin >> Fi >> Ci;
			if (Fi == 1) {
				// 戦闘
				if (inversion) {
					// 反転してるので後ろ
					q.push_back(Ci);
				}
				else {
					//反転してなきゃ先頭
					s.push_back(Ci);
				}
			}
			else if (Fi == 2) {
				// 末尾
				if (inversion) {
					// 反転してるので先頭
					s.push_back(Ci);
				}
				else {
					//反転してなきゃ末尾
					q.push_back(Ci);
				}
			}
		}
	}
	// 反転してるなら逆	
	if (inversion) {
		//末尾から出力
		for (int i = 0; i < q.size(); i++) cout << q[q.size() - i - 1];
		reverse(S.begin(),S.end());
		cout << S;
		for (int i = 0; i < s.size(); i++) cout << s[i];
	}
	else {
		for (int i = 0; i < s.size(); i++) cout << s[s.size() - i - 1];
		cout << S;
		for (int i = 0; i < q.size(); i++) cout << q[i];
	}
	cout << endl;

}

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

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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)

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

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 5e3 + 9, M = 5e3 + 9, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;

int n, k, a[N], dp[N][N], temp;

//int solve(int i, int sum){
//    if(i == n)  return (sum >= k - temp && sum < k);
//
//    int &ret = dp[i][sum];
//    if(~ret)    return ret;
//
//    return ret = solve(i + 1, sum) | solve(i + 1, min(k, sum + a[i]));
//}

//int solve(){
//    for(int i = 0;i < N;i++)
//        for(int sum = 0;sum < N;sum++)
//            dp[i][sum] = (sum >= k - temp && sum < k);
//
//    for(int i = N - 2;i >= 0;i--){
//        for(int sum = N - 2;sum >= 0;sum--){
//            dp[i][sum] = dp[i + 1][sum] | dp[i + 1][min(k, sum + a[i])];
//        }
//    }
//
//    return dp[0][0];
//}




int solve(){
    bitset<N> sum;

    sum[0] = 1;
    for(int i = 0;i < n;i++)
        sum |= sum << a[i];

    for(int i = k - temp;i <= k - 1;i++)
        if(sum[i])  return 1;

    return 0;
}


int main(){
    init();

    cin >> n >> k;
    for(int i = 0;i < n;i++)    cin >> a[i];

    sort(a, a + n);
    while(n - 1 >= 0 && a[n - 1] >= k)  n--;

    int l = 0, r = n - 1;
    while(l <= r){
        int i = (l + r) >> 1;

        temp = a[i];    a[i] = 0;
//        memset(dp, -1, sizeof dp);
        int ok = !(solve());
        a[i] = temp;

        if(ok == 1)
            l = i + 1;
        else
            r = i - 1;
    }

    cout << l;
}

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

#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define vi vector<int>

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cerr << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define debug(...) CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) (__VA_ARGS__)

using namespace std;
using ll = long long;
using P = pair<int, int>;

void Main() {
  string s;
  cin >> s;
  int ans = 1000;
  rep(i, s.size()-2) {
    int score = (s[i] - '0')*100 + (s[i+1] - '0')*10 + (s[i+2] - '0');
    ans = min(ans, abs(score - 753));
  }
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

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

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        for(int i=1;i<6;i++){
            if(sc.nextInt() == 0){
                System.out.println(i);
            }
        }


    }

}


Measured memory_bytes: 35716
#include <bits/stdc++.h>
using namespace std;
// #define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
#define ITR(v,c) for(auto v=begin(c);v!=end(c);v++)
#define FORE(x,c) for(auto &x:c)
#define FOR(v,a,n) for(int v=a;v<(int)(n);v++)
#define REP(v,n) FOR(v,0,n)
#define RREP(v,n) for(int v=((int)(n)-1);v>=0;v--)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define SZ(c) ((int)c.size())
const int DX[9]={0,1,0,-1,1,1,-1,-1,0}, DY[9]={-1,0,1,0,-1,1,1,-1,0};
const int INF=1e9; const long long INFLL=1e18;
template<class T> ostream& operator << (ostream &os, const vector<T> &v) {
    ITR(i,v) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is, vector<T> &v) {
    ITR(i,v) is>>*i; return is; }
//------------------------------------------------------------------------------

signed main() {
    int N,T;
    cin>>N>>T;
    vi a(N);
    cin>>a;

    int M=0,m=INF,max_dif=0;
    REP(i,N) {
        if(m>a[i]) {
            m=a[i];
            M=0;
        }
        else if(M<a[i]) {
            M=a[i];
            max_dif=max(max_dif,M-m);
        }
    }
    
    int ans=0;
    set<int> s;
    REP(i,N) {
        if(s.find(a[i]-max_dif)!=end(s)) {
            ans++;
        }
        s.insert(a[i]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double ld;

#define for0(i, n) for (ll i = 0; i < (ll)(n); ++i) // 0 based indexing
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (ll i = (ll)(l); i <= (ll)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (ll i = (ll)(n); i >= 1; --i) // reverse 1 based

#define ff first
#define ss second
#define pb push_back

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin >> s;
	if(s == "ABC"){
		cout <<"ARC"<<endl;
	}
	else{
		cout << "ABC"<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 3608
x , n = map(int, input().split())
p = list(map(int, input().split()))
p = sorted(p)
q = 10000
r = 10000
for i in range(0, 102):
    if i not in p:
        if q > abs(i-x):
            q = abs(i-x)
            r = i
print(r)


Measured memory_bytes: 9184
import sys
input = sys.stdin.readline
import marshal


class Graph:
    def __init__(self, n, directed=False, decrement=True, destroy=False, edges=[]):
        self.n = n
        self.directed = directed
        self.decrement = decrement
        self.destroy = destroy
        self.edges = [set() for _ in range(self.n)]
        self.parent = [-1]*self.n
        self.info = [-1]*self.n
        for x, y in edges:
            self.add_edge(x,y)

    def add_edge(self, x, y):
        if self.decrement:
            x -= 1
            y -= 1
        self.edges[x].add(y)
        if self.directed == False:
            self.edges[y].add(x)

    def dfs2(self, info, start=1, goal=-1, time=0, save=False):
        """
        :param info: 各頂点の付加情報 = [v1,v2,v3,...,vN]
        :param start: スタート地点
        :param goal: ゴール地点
        :param save: True = 前回の探索結果を保持する
        :return: 伝搬後のinfo
        """

        if self.decrement:
            start -= 1
            goal -= 1
        if not save:
            self.parent = [-1] * self.n
        if self.destroy:
            edge2 = self.edges
        else:
            edge2 = marshal.loads(marshal.dumps(self.edges))

        p, t = start, time
        self.parent[p] = -2
        while True:
            if edge2[p]:
                q = edge2[p].pop()
                if q == self.parent[p] and not self.directed:
                    """ 逆流した時の処理 """
                    """"""""""""""""""""
                    continue
                if self.parent[q] != -1:
                    """ サイクルで同一点を訪れた時の処理 """
                    """"""""""""""""""""
                    continue
                if q == goal:
                    """ ゴール時の処理"""
                    # return t + 1
                    """"""""""""""""""""
                    continue
                """ p から q への引継ぎ"""
                info[q] += info[p]
                """"""""""""""""""""
                self.parent[q] = p
                p, t = q, t + 1
            else:
                """ p から進める点がもう無い時の点 p における処理 """
                """"""""""""""""""""
                if p == start and t == time:
                    break
                p, t = self.parent[p], t-1
                """ 点 p から親ノードに戻ってきた時の親ノードにおける処理 """

                """"""""""""""""""""
        return info

##################################################################################################

N, Q = map(int, input().split())
M = N-1
graph = Graph(N, directed=False, decrement=True, destroy=False)
for _ in range(M):
    x, y = map(int, input().split())
    graph.add_edge(x, y)
info = [0]*N
for _ in range(Q):
    p, x = map(int, input().split())
    info[p-1] += x
res = graph.dfs2(info, start=1)
print(*res)

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

using ll = long long;

int main(){
	int n;
	cin >> n;
	ll a[3 * n];
	for(int i = 0; i < 3 * n; i++) cin >> a[i];
	sort(a, a + 3 * n);
	reverse(a, a + 3 * n);
	ll ans = 0;
	for(int i = 0; i < n; i++) ans += a[2 * i + 1];
	cout << ans << endl;
}

Measured memory_bytes: 2560
#include <gmpxx.h>
#include <math.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
// int => mpz_class
// scanf("%d", &x); => cin >> x;
// printf("%d\n", x); => std::cout << x << "\n";

// コンパイル時に -lgmpxx -lgmp

int main() {
    int n, k;
    // scanf("%d%d", &n, &k);
    std::cin >> n >> k;
    int a[200000];
    for (int i = 0; i < n; i++) {
        // scanf("%d", &a[i]);
        std::cin >> a[i];
    }

    /* ここまで値の読み込み */

    // mpz_class score = 1;
    // for (int i = 0; i < k; i++) {
    //     score *= a[i]; /* kでの評点を求めて，scoreとした */
    // }
    // mpz_class score1 = score;
    for (int i = 0; i < (n - k); i++) {
        // score /= a[i];
        // score *= a[i + k];
        // if (score > score1) {
        if (a[i] < a[i + k]) {
            puts("Yes");
        } else {
            puts("No");
        }
        // printf("score:%d\n",score);
        // score1 = score;
    }

    return 0;
}


Measured memory_bytes: 3804
/*
T(i, d) 表示范围为 [1, i] 的结尾为 d 的排列数
0 <= i <= n, 1 <= d <= i
则 Sum{ T(n, d) } 为最终解

T(i, d) = 
if s[i-1] = '<'，则 d 要大于 T(i-1) 的结尾数字，Sum{ T(i-1, d') } 1 <= d' < d
if s[i-1] = '>'，则 d 要小于 T(i-1) 的结尾数字，Sum{ T(i-1, d') } d <= d' <= i 

*/
package main

import "fmt"

const MOD = 1e9+7

func main() {
  var n int
  fmt.Scanf("%d", &n)
  var seq string
  fmt.Scanf("%s", &seq)
  current := make([]int64, 1+1)
  current[1] = 1
  for i := 2; i <= n; i++ {
    sum := make([]int64, i+1)
    // [1, i-1]
    for j := 1; j < i; j++ {
      sum[j+1] = sum[j] + current[j]
    }
    rangeSum := func(i, j int) int64 {
      return (sum[j] - sum[i]) % MOD
    }
    next := make([]int64, i+1)
    for j := 1; j <= i; j++ {
      if seq[i-2] == '<' {
        next[j] = rangeSum(1, j)
      } else {
        next[j] = rangeSum(j, i)
      }
    }
    current = next
  }
  var result int64
  for i := 1; i <= n; i++ {
    result += current[i]
  }
  fmt.Println(result % MOD)
}

Measured memory_bytes: 7644
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

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

int main(int argc, char **argv)
{
    int N;
    cin >> N;
    int p[N];
    REP(i, N) cin >> p[i];
    int c = 0;
    REP(i, N) {
        if (i + 1 != p[i]) c++;
    }
    if (c <= 2) cout <<"YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < (int)(x); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = LLONG_MAX/4;
const int n_max = 1e5+10;

class drug{
    public:
    drug(){};
    drug(int a, int b, int c):a(a), b(b), c(c){};
    int a;
    int b;
    int c;
};

int main(){
    ll n,ma,mb; cin >> n >> ma >> mb;
    vector<drug> d(n);
    rep(i,n){
        ll a,b,c; cin >> a >> b >> c;
        d[i] = drug(a,b,c);
    }
    vvvl dp(2, vvl(400, vl(400,INF)));
    dp[0][0][0] = 0;
    rep(i,n)rep(j,400)rep(k,400){
        if(dp[i%2][j][k] != INF){
            dp[(i+1)%2][j+d[i].a][k+d[i].b] = min(dp[i%2][j][k] + d[i].c, dp[(i+1)%2][j+d[i].a][k+d[i].b]);
            dp[(i+1)%2][j][k] = min(dp[i%2][j][k], dp[(i+1)%2][j][k]);
        }
    }
    ll res = INF;
    rep(i,400)rep(j,400){
        if(!i || !j)continue;
        if(i * mb == j * ma)res = min(res, dp[n%2][i][j]);
    }
    cout << (res == INF ? -1 : res) << endl;
}

Measured memory_bytes: 4096