akhauriyash/Code-Regression huggingface dataset:
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
        n: usize,
    }
    let mut ans = 0;
    for i in 1..=n {
        let m = n / i;
        ans += m * (i + (i * m)) / 2;
    }
    println!("{}", ans);
}


Measured memory_bytes: 2200
N,M=map(int,input().split(' '))
A=[input() for x in range(N)]
B=[input() for x in range(M)]
ans = 'No'
for h in range(0,(N-M)+1):
  for w in range(0,(N-M)+1):
    if sum([B[i]!=A[i+h][w:(w+M)] for i in range(M)])==0:
      ans = 'Yes'
      break
  if ans == 'Yes':
    break
print(ans)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif
            var line1 = Console.ReadLine();
            var solver = new Solver(line1);
            var answer = solver.Solve();
            Console.WriteLine(answer);
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public Solver(string line1)
        {
            a = int.Parse(line1);
        }

        public int a { get; set; }

        public string Solve()
        {
            return (a + a * a + a * a * a).ToString();
        }
    }
}


Measured memory_bytes: 27536
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

int main() {
		int n, p_cnt=1, q_cnt=1, cnt=0;
		cin >> n;
		vector<int> _p(n, 0);
		vector<int> _q(n, 0);
		vector<int> sorted_v(n, 0);
		for (int i=0; i<n; i++) {
			cin >> _p[i];
		}
		for (int i=0; i<n; i++) {
			cin >> _q[i];
	 	}
		for (int i=0; i<n; i++) {
			sorted_v[i] = _q[i];
		}
		sort(sorted_v.begin(), sorted_v.end());

		do {
			cnt++;
			if (_p.size() == sorted_v.size() && equal(_p.cbegin(), _p.cend(), sorted_v.cbegin())) {
				p_cnt = cnt;
			}
			if (_q.size() == sorted_v.size() && equal(_q.cbegin(), _q.cend(), sorted_v.cbegin())) {
				q_cnt = cnt;
			}
		} while (next_permutation(sorted_v.begin(), sorted_v.end()));

		cout << abs(p_cnt - q_cnt) << endl;
	return 0;
}

Measured memory_bytes: 384
n,a,b = map(int,input().split())

def modComb(n,r,mod):
    tmp = 1
    # r = min(r,n-r)
    for i in range(1,r+1):
        tmp = tmp * (n-i+1) % mod
        tmp = tmp * pow(i,mod-2,mod)
    
    return tmp % mod


mod = 10**9+7
ans = pow(2,n,mod) - 1

print((ans-modComb(n,a,mod)-modComb(n,b,mod)) % mod)



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

int main(void) {
  int i;
  char s[110];
  scanf("%s", s);
  bool f[26];
  for(i = 0; i < 26; ++i) f[i] = false;
  for(i = 0; i < strlen(s); ++i) f[s[i] - 'a'] = !f[s[i] -'a'];
  for(i = 0; i < 26; ++i) if(f[i]) {
    printf("No");
    return 0;
  }
  printf("Yes");
  return 0;
}

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

string to_string(string s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define db(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define db(...) 42
#endif

using ll = long long;

int main() {
  int w, a, b;
  cin >> w >> a >> b;
  if (a + w < b) {
    cout << b - (a+w) << endl;
  } else if (b + w < a) {
    cout << a - (b+w) << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int A,B,C;
	cin >> A >> B >> C;
	int  t=A-B;
	if(t>C){
		cout << 0 << endl;
	}
	else{
		cout << C-t << endl;
	}	
	return 0;
}

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

#define MAX_N 8
#define MAX_M 28
using namespace std;
#define INF 9999999

int N,M;

bool g[MAX_N][MAX_N] = {false};
int dp[1 << MAX_N][MAX_N];//dpテーブル

//すでに訪れた頂点をＳ、現在位置がvとする
bool bitdp[MAX_N][MAX_N] = {false};
int rec(int S ,int v){
    if(S ==(1 << N) - 1){
        return 1;//全ての頂点を訪問した。
    }
    int res = 0;
    for(int u = 0; u < N; u++){
        if(!(S >> u & 1) && g[v][u] == true){//まだuには訪問していない　かつ、その辺は存在するか
            //次にuに移動する
            res += rec(S | 1 << u, u);
        }
    }
    return res;
}

int main(){
    cin >> N >> M;
    int f,t;
    for(int i = 0; i < M; i++){ 
        cin >> f >> t;
        g[f-1][t-1] = true;
        g[t-1][f-1] = true;
    }
    //bitDPで計算する
    cout << rec(1,0) << endl;//頂点1からスタートする。
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define rrdebug(i, j, x) rep(i, alength(x))rep(j, alength(x[i]))cout << #x << "[" << i << "][" << j << "]:" << x[i][j] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = 3.141592653589;
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
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; }
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){ if(!b)return a; return gcd(b, a % b); }
intl lcm(intl a,intl b){ return a / gcd(a, b) * b; }
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
//-------------------------------------------------------------------------------

intl k;
vector<intl> v;
void input_var(){
    cin >> k;
}
//-------------------------------------------------------------------------------


void dfs(intl a) {
    if(digit10(a) == 11)return;
    v.pb(a);
    if(a % 10)dfs(a * 10 + ((a % 10) - 1));
    dfs(a * 10 + (a % 10));
    if((a % 10) != 9)dfs(a * 10 + ((a % 10) + 1));
}

signed main(){
    cout << fixed << setprecision(10);
    input_var();
    repi(i,1,10)dfs(i);
    sort(all(v));
    cout << v[k - 1] << endl;
    return 0;
}

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

int main(void){
    int t_hp;
    int t_atk;

    int a_hp;
    int a_atk;

    cin>>t_hp>>t_atk>>a_hp>>a_atk;

    while (true)
    {
        a_hp-=t_atk;
        if(a_hp<=0){
            cout<<"Yes";
            break;
        }
        t_hp-=a_atk;
        if(t_hp<=0){
            cout<<"No";
            break;
        }
    }
    

    return 0;
}

Measured memory_bytes: 3592
n,k=map(int,input().split())
a=list(map(int,input().split()))
f=list(map(int,input().split()))

a.sort()
f.sort(reverse=True)

pi=[a[i]*f[i] for i in range(n)]

l=-1
r=max(pi)

while l+1<r:
  x=(l+r)//2
  s=sum([max(a[i]-x//f[i],0) for i in range(n)])
  if s<=k:
    r=x
  else:
    l=x
print(r)



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

int main(void) {
  int N, K;
  cin >> N >> K;
  vector<int> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  sort(p.begin(), p.end());
  long long ans = 0;
  for (int i = 0; i < K; i++) {
    ans += p[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3544
// 2012/02/18 Tazoe

#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

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

	vector<int> B[10];
	for(int i=0; i<N; i++){
		int C, G;
		cin >> C >> G;

		B[G-1].push_back(C);
	}

	for(int i=0; i<10; i++){
		sort(B[i].begin(), B[i].end(), greater<int>());

		for(int j=1; j<B[i].size(); j++){
			B[i][j] += (j+j)+B[i][j-1];
		}
	}
/*
	for(int i=0; i<10; i++){
		for(int j=0; j<B[i].size(); j++){
			cout << B[i][j] << ' ';
		}
		cout << endl;
	}
*/
	int DP[11][2000];
	for(int i=0; i<=10; i++)
		for(int j=0; j<=K; j++)
			DP[i][j] = -1;

	DP[0][0] = 0;

	for(int i=1; i<=10; i++){
		for(int j=0; j<=K; j++){
			DP[i][j] = DP[i-1][j];
		}

		for(int j=0; j<K; j++){
			if(DP[i-1][j]==-1)
				break;

			for(int k=0; k<B[i-1].size(); k++){
				if(j+k+1>K)
					break;

				if(DP[i-1][j]+B[i-1][k]>DP[i][j+k+1]){
					DP[i][j+k+1] = DP[i-1][j]+B[i-1][k];
				}
			}
		}
/*
		for(int j=0; j<=K; j++){
			cout << DP[i][j] << ' ';
		}
		cout << endl;
*/
	}

	cout << DP[10][K] << endl;

	return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int N;
string S;

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

  for (int i = 0; i < S.size(); i++) {
    char c = S[i] + N;
    if (c > 'Z') {
      c = c - 26;
      cout << c;
    } else {
      cout << c;
    }
  }
  cout << endl;

  return 0;
}

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

signed main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  int ans=min(A,B)+min(C,D);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N, M;
  cin >> N >> M;

  ll onetime = 1900*M + 100*(N - M);

  ll ans = onetime * (ll)pow(2, M);

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


Measured memory_bytes: 512
#include<iostream>
#include<queue>
#include<math.h>

using namespace std;

int main(){
    int n;
    double a,t;
    cin >> n >> t >> a;
    double h[n-1];
    double mi;
    int m_i;
    double ti;
    
    for(int i=0;i<n;i++){
        cin >> h[i];
    }
    mi = fabs(a-(t-h[0]*0.006));
    m_i = 0;
    for(int i=1;i<n;i++){
        ti = fabs(a-(t-h[i]*0.006));
        if(mi>ti){
            m_i=i;
            mi = ti;
        }
    }
    cout << m_i+1;
}

Measured memory_bytes: 256
s = input()
d = []
d.append("AKIHABARA")

d.append("AKIHABAR")
d.append("AKIHABRA")
d.append("AKIHBARA")
d.append("KIHABARA")

d.append("AKIHABR")
d.append("AKIHBRA")
d.append("AKIHBAR")
d.append("KIHBARA")
d.append("KIHABRA")
d.append("KIHBAR")

d.append("AKIHBR")
d.append("KIHABR")
d.append("KIHBAR")
d.append("KIHBRA")

d.append("KIHBR")
if s in d:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 38256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
int a[200010],n;
ll sum;
ll Abs(ll x){
    return x>0?x:-x;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]),sum+=a[i];
    ll s=0,minn=1000000000000000000ll;
    for(int i=1;i<n;i++){
        s+=a[i];
        minn=min(minn,Abs(sum-s-s));
    }
    printf("%lld\n",minn);
    return 0;
}

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

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

    auto cards = std::vector<int>(n);

    for(auto &card: cards)
    {
        std::cin >> card;
    }
    std::sort(cards.begin(), cards.end(), std::greater<int>());

    int alice_score = 0;
    int bob_score = 0;

    bool is_turn_alice = true;
    for(auto c: cards)
    {
        if(is_turn_alice)
        {
            alice_score += c;
        }
        else
        {
            bob_score += c;
        }
        is_turn_alice = !is_turn_alice;
    }

    std::cout << alice_score - bob_score << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
long long int n,m,i;
scanf("%lld %lld",&n,&m);
  long long int ans[n+1],a[m],sw;
  sw=0;
  ans[0]=1;
  
  if(m>0){
  for(i=0;i<m;++i)
  {scanf("%lld",&a[i]);}
  
  if(a[sw]==1) {ans[1]=0;
               sw++;}
  else ans[1]=1;
  
  for(i=2;i<=n;++i)
  {
  if(i==a[sw]) {ans[i]=0;
                sw++;}
   else
   {
   ans[i]=(ans[i-1]+ans[i-2])%1000000007;
   }
  }
  printf("%lld",ans[n]);
  }
  
  else if(n==1) printf("1");
  
  else{
  ans[0]=1;
  ans[1]=1;
  
    for(i=2;i<=n;++i)
  {ans[i]=(ans[i-1]+ans[i-2])%1000000007;
  }
    
  printf("%lld",ans[n]);
  }
return 0;}

Measured memory_bytes: 3188
//According to all known laws of aviation, there is no way that a bee should be able to fly.
//Its wings are too small to get its fat little body off the ground. The bee, of course, flies anyway.
//Because bees don't care what humans think is impossible.
#include <bits/stdc++.h>
#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define mod 1000000007
using namespace std ;
using bigint = long long int ;
using vi = vector<int> ;
using vll = vector<long long int> ;

int main(){
    FAST_IO ;
    int A , T ; cin >> A >> T ;
    if( ( T - 2 * A ) % 2 == 0 && ( 4 * A - T ) % 2 == 0 && ( T - 2 * A) >= 0 && ( 4 * A - T ) >= 0 ){
        cout << "Yes" << endl ;
    }
    else
        cout << "No" << endl ;
    return 0 ;
}


Measured memory_bytes: 3616
/**
* Copyright(c)
* All rights reserved.
* Author : Mingzhe
* Description : sample
*/
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cstdlib>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <string>
#include <cstring>
#include <sstream>
#include <memory.h>
#define MAXN 10005
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;

int x[MAXN];

int main(){
    int n;
    cin>>n;
    int amount = 0;
    for(int i=0;i<n;i++){
        cin>>x[i];
        amount += x[i];
    }
    int ans = INF;
    int sum = 0;
    for(int i=0;i<n-1;i++){
        sum += x[i];
        ans = min( ans , abs(sum -(amount-sum)) );
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int main(void){
    for(int x, y, s, res; cin >> x >> y >> s, x; cout << res << endl){
        res = 0;

        range(i, 1, s){
            range(j, 1, s){
               if(i * (100 + x) / 100 + j * (100 + x) / 100 == s){
                    res = max(res, i * (100 + y) / 100 + j * (100 + y) / 100);
               }
            }
        }
    }

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int r;
    cin >> r;
    cout << r * r << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
int main(){
	ll a,b,n;
	scanf("%lld%lld%lld",&a,&b,&n);
	ll d;
	if(n>=b)d=b-1;
	else d=n;
	printf("%lld\n",a*d/b);
	return 0;
}

Measured memory_bytes: 3824
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define rep(i, n) FOR(i,0,n)
#define irep(i, n) IFOR(i,0,n)
template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;

using namespace std;

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

    int cnt = 0;
    FOR(i, 1, n) {
        FOR(j, 1, n) {
            if ((i * j) < n) cnt++;
            else break;
        }
    }
    cout << cnt << endl;

    return 0;
}


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

int main ()
{
int towns[4] = { 0 };
	for (int i = 0; i < 3 * 2; ++i)
	{
		int town;
		cin >> town;
		++towns[town - 1];
	}

	int check = 1;
	for (int i = 0; i < 4; ++i)check *= towns[i];
	
	if (check != 3)cout << "YES" << endl;
	else cout << "NO" << endl;
return 0;
}

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

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

    int n;
    cin >> n;

    vector<int> a(n);
    REP(i, n) cin >> a[i];

    ll ans = 0;
    REP(i, n) ans += a[i];
    ans -= n;

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<int(n);i++)
#define FOR(i,n,m) for(int i=n;i<int(m);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

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

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

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int N_MAX=100010;

int n;
vector< vector<pii> > tree = vector< vector<pii> >(N_MAX, vector<pii>());
vector<int> color=vector<int>(N_MAX,-1);

void dfs(int now){
	for(int i=0;i<tree[now].size();i++){
		int next=tree[now][i].first;
		int weight=tree[now][i].second;
		if(color[next]==-1){
			if(weight%2==0){
				color[next]=color[now];
			}else{
				if(color[now]==0)color[next]=1;
				else color[next]=0;
			}
			dfs(next);
		}else{
			continue;
		}
	}
}

int main(){
	cin>>n;
	for(int i=0;i<n-1;i++){
		int u,v,w;
		cin>>u>>v>>w;
		u--; v--;
		tree[u].pb(pii(v,w));
		tree[v].pb(pii(u,w));
	}
	color[0]=0;
	dfs(0);
	for(int i=0;i<n;i++){
		cout<<color[i]<<endl;
	}
	return 0;
}



Measured memory_bytes: 7552
n = int(input())
*A, = map(int, input().split())
p = 10**9+7
A = [format(a, '060b') for a in A]
s = 0
for i in range(60):
    Ai = [a[i] for a in A]
    c0 = Ai.count('0')
    c1 = n-c0
    c = c0*c1
    s = (s+c*(2**(59-i))) % p
print(s)


Measured memory_bytes: 54436
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <queue>
#include <stack>
#include <bitset>
#include <set>
#include <chrono>
#include <string>
#include <assert.h>

using namespace std;

#define endl '\n'

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

    long long n, x;
    cin >> n >> x;

    vector<long long> B(n), L(n), U(n), O(n);

    long long T = 0;

    for (int i = 0; i < n; ++i)
    {
        cin >> B[i] >> L[i] >> U[i];
        O[i] = i;
        T += B[i] * L[i];
    }

    auto f = [&](int i) {
        return L[i] * B[i] + U[i] * (x - B[i]);
    };

    sort(O.begin(), O.end(), [&](int u, int v) {
        return f(u) > f(v);
    });

    vector<long long> acc(n + 1);
    for (int i = 1; i <= n; ++i)
        acc[i] = acc[i - 1] + f(O[i - 1]);

    auto ok = [&](long long s) {
        int tot = s / x;
        int rem = s % x;

        for (int i = 0; i < n; ++i)
        {
            long long prefix = 0, cur = 0;
            if (tot <= i)
            {
                prefix = acc[tot];
            }
            else
            {
                prefix = acc[tot + 1];
                prefix -= f(O[i]);
            }

            if (rem <= B[O[i]])
                cur = rem * L[O[i]];
            else
                cur = B[O[i]] * L[O[i]] + (rem - B[O[i]]) * U[O[i]];

            if (prefix + cur >= T)
                return true;
        }

        return false;
    };

    auto res = ok(2439);

    long long lo = -1, hi = x * n;

    while (lo + 1 < hi)
    {
        long long m = (hi + lo) / 2;
        if (ok(m))
        {
            hi = m;
        }
        else
        {
            lo = m;
        }
    }

    cout << hi << endl;

    return 0;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
 
#define mp make_pair
#define fi first
#define se second
 
const int N = 1e5 + 10;

int l[N], r[N];
multiset<long long> sa, sb; 
long long a, b;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	
	int n;
	cin>>n;
	int l1 = 0;
	for(int i=1; i<=n; i++) {
		cin>>l[i]>>r[i];
		int l2 = r[i] - l[i]; 
		if (i > 1) a -= l2, b += l1;
		l1 = l2;
		long long x, y;
		if (i > 1) {
			set<long long>::iterator it = sa.end(); it--;
			x = *it + a;
			it = sb.begin();
			y = *it + b;
		} else x = 0, y = 0;
		if (x <= l[i] && l[i] <= y) {
			sa.insert(l[i] - a), sb.insert(l[i] - b);
		} else if (l[i] < x) {
			sa.insert(l[i] - a), sa.insert(l[i] - a);
			set<long long>::iterator it = sa.end(); it--;
			sb.insert(*it + a - b); sa.erase(it);
		} else if (l[i] > y) {
			sb.insert(l[i] - b), sb.insert(l[i] - b);
			set<long long>::iterator it = sb.begin(); 
			sa.insert(*it + b - a); sb.erase(it);
		}
	}
	long long jaw = 0, t = -1e13;
	for(int i=n; i>=1; i--) jaw += l[i] - t, t += r[i] - l[i];
	long long d = -n; 
	long long tmp = -1e13;
	for(set<long long>::iterator it = sa.begin(); it != sa.end(); it++)
		jaw += 1LL * d * (*it + a - tmp), tmp = *it + a, d++;
	cout <<jaw<<endl;
	return 0;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const long long mod = 1000000007;
const long long inf = 1e18;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    string a,b;
    cin>>a>>b;
    if(a[0]==b[2] && b[0]==a[2] && a[1]==b[1])
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;
}


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

string s, t;

void solve(){
    int count = 0;
    for (int i = 0, sz = s.size(); i < sz; i++){
        if (s[i] != t[i]) count += 1;
    }
    cout << count;
}


int main(){
   	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> s >> t;
    solve();
	return 0;
}

Measured memory_bytes: 3796
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

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

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

	int lena = (int)a.size();
	int lenb = (int)b.size();

	if (lena > lenb){
		cout << "GREATER" << endl;
		return 0;
	}
	else if (lena < lenb){
		cout << "LESS" << endl;
		return 0;
	}
	else {
		REP(i, lena){
			if (a[i] > b[i]){
				cout << "GREATER" << endl;
				return 0;
			}
			else if (a[i] < b[i]){
				cout << "LESS" << endl;
				return 0;
			}

		}
	}

	cout << "EQUAL" << endl;

}


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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    ll n = in(), t = in();
    vll a = in(n);
    vll cur_min(n, LINF);
    vll score(n, 0);
    ll max_score = 0;
    cur_min[0] = a[0];
    setint st;
    st.insert(0);
    rep(i, n - 1)
    {
        cur_min[i + 1] = min(cur_min[i], a[i + 1]);
        score[i + 1] = max(a[i + 1] - cur_min[i + 1], (ll)0);
        if (max_score == score[i + 1])
        {
            st.insert(i + 1);
        }
        else if (max_score < score[i + 1])
        {
            st.clear();
            st.insert(i + 1);
            max_score = score[i + 1];
        }
    }
    cout << st.size() << 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: 4992
import sys
def input():
    return sys.stdin.readline()[:-1]
N=int(input())
s=[[]for i in range(N)]
for i in range(N-1):
    a,b=map(lambda x: int(x)-1,input().split())
    s[a].append(b)
    s[b].append(a)
sys.setrecursionlimit(20000)
l=[None]*N
def hu(n):
    for i in s[n]:
        if l[i]==None:
            l[i]=c.pop()
            hu(i)
c=list(map(int,input().split()))
c.sort()
print(sum(c[:-1]))
l[0]=c.pop()
hu(0)
print(*l)

Measured memory_bytes: 14068
n = int(input())
a = list(map(int,input().split()))
num  = []
for i in range(n):
    num.append([a[i],i])
num.sort(reverse = True)
dp = [[0]*(n+1)for i in range(n+1)]
ans = 0
for l in range(n):
    for r in range(n):
        if l+r == n:
            ans = max(ans,dp[l][r])
            break
        dp[l+1][r] = max(dp[l+1][r], dp[l][r] + num[l+r][0]*abs(num[l+r][1]-l))
        dp[l][r+1] = max(dp[l][r+1],dp[l][r]+num[l+r][0]*abs(num[l+r][1]-n+1+r))
print(ans)

Measured memory_bytes: 100860
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
    string s, t;
    cin >> s >> t;
    int ans = 0;
    if(s[0] == t[0]){
        ans++;
    }
    if(s[1] == t[1]){
        ans++;
    }
    if(s[2] == t[2]){
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int norPri = sc.nextInt();
      	int freePri = sc.nextInt();
      	int busNorPri = sc.nextInt();
      	int busFreePri = sc.nextInt();
      
      	System.out.println(Math.min(norPri, freePri)
        	+ Math.min(busNorPri, busFreePri));
	}
}

Measured memory_bytes: 21844
N = int(input())
A = tuple(map(int,input().split()))

box = [0] * N

for i in range(N-1, -1, -1):
    cnt = 0
    tmp = i + 1
    while tmp <= N:
        cnt += box[tmp - 1]
        tmp += (i + 1)
    
    if cnt  % 2 != A[i]:
        box[i] = 1

ans = [idx+1 for idx in range(N) if box[idx] == 1]

print(len(ans))

if ans:
    print(*ans)

Measured memory_bytes: 74588
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 1000000000
#define MOD 1000000007

typedef  long long ll;

using namespace std;

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;
}

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

ll gcd(ll  a,ll b){
    ll r;
    if(a < b){
        ll tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r = a % b){
        a = b;
        b = r;
    }
    return b;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    cout<<  ans << endl;
    }
}

ll wa(ll a,ll c,ll d,ll cd){
    ll t1 = (a-1)/c;
    ll t2 = (a-1)/d;
    ll t3 = (a-1)/cd;
    return  a-1-t1-t2+t3;
}

void solve() {
   int n;
   cin >> n;
   int p[n];
   for(int i = 0;i < n;i++) cin >> p[i];
   int ans = 0;
   for(int i = 0;i < n-2;i++){
       if((p[i] > p[i+1] && p[i+1] > p[i+2]) || (p[i] < p[i+1] && p[i+1]<p[i+2]) )
       ans++;
   }

   cout << ans << endl;
}
int main() {

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

	solve();

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <math.h>
#include <map>
#include <numeric>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
    while(1){
        int a,b,l; cin >> a >> l;
        if(a==0&&l==0)break;
        map<int,int> mp;
        mp[a]=1;
        int num=2;
        string s,t;
        s=to_string(a);
        while(1){
            while(s.size()<l)s+='0';
            t=s;
            sort(t.begin(),t.end());
            b=stoi(t);
            reverse(t.begin(),t.end());
            a=stoi(t);
            if(mp[a-b]!=0){
                cout << mp[a-b]-1 << " " << a-b << " " << num-mp[a-b] << endl;
                break;
            }
            mp[a-b]=num;
            num++;
            s=to_string(a-b);
        }
    }
}


Measured memory_bytes: 3252
import Control.Monad
import Data.List
import Data.Ord
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Storable as V

main=do
    n<-readLn::IO Int
    as<-V.fromList.sort.map (\(i,a)->a-i).zip [1..].unfoldr (B.readInt.B.dropWhile(==' ')) <$> B.getLine::IO(V.Vector Int)
    print $ tsearch as (0,n-1)

tsearch as (l,r)
    | l == r = calc $ as V.! l
    | l+1 == r = min (calc $ as V.! l) (calc $ as V.! r)
    | l+2 == r = minimum [calc $ as V.! l, calc $ as V.! (l+1), calc $ as V.! r]
    | c1 < c2  = tsearch as (l,b2)
    | c1 == c2 = tsearch as (b1,b2)
    | c1 > c2  = tsearch as (b1,r)
    where
        c1 = calc $ as V.! b1
        c2 = calc $ as V.! b2
        b1 = l+(r-l)`div`3
        b2 = l+((r-l)`div`3)*2
        calc b = V.sum $ V.map (\a->abs $ a-b) as

Measured memory_bytes: 31100
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((ll)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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;
}

template <class T>
T find_min(T l, T r, bool f(T)) {
  T c;
  while (r - l > 1) {
    c = (r + l) / 2;
    if (f(c)) {
      r = c;
    } else {
      l = c;
    }
  }

  return r;
}

/*

*/
ll N, K;
vector<ll> A;
vector<ll> F;

bool f(ll x) {
  ll shugyo = 0;
  rep(i, N) {
    ll multi = A[i] * F[i];
    if (multi <= x)
      continue;
    multi -= x;
    multi = (multi + F[i] - 1) / F[i];
    shugyo += multi;
  }
  return (shugyo <= K);
}

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

  sort(all(A));
  sort(all(F), greater<ll>());

  cout << find_min(-1LL, LINF, f) << endl;
}


Measured memory_bytes: 3328
from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom
n,p=map(int,input().split())
a=list(map(int,input().split()))
cnt=0
odd=0
even=0
ans=0
for i in range(n):
    if a[i]%2==0:
        even+=1
    else:
        odd+=1
if p==0:
    cnt=odd
    if cnt%2!=0:
        cnt-=1
    while cnt>=0:
        ans+=combinations_count(odd, cnt)
        cnt-=2
    ans*=2**even
else:
    cnt=odd
    if cnt%2==0:
        cnt-=1
    while cnt>=0:
        ans+=combinations_count(odd, cnt)
        cnt-=2
    ans*=2**even
print(ans)
    

Measured memory_bytes: 3572
#include <iostream>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

#ifdef DEBUG
    #define IFD if(true)
#else
    #define IFD if(false)
#endif

int main()
{
    int N, D;

    cin >> N >> D;
    int ans = N / (D * 2 + 1);
    if(N % (D * 2 + 1) != 0) ans++;
    cout << ans << endl;

    return 0;
}


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

int main(){
    bool is_prime[1000000];

    is_prime[0] = is_prime[1] = false; 
    for(int i=2; i<1000000; i++){
        is_prime[i] = true;
    }
    for(int i=2; i*i<1000000; i++){
        if(is_prime[i]){
            for(int j=i*i; j<1000000; j+=i){ 
                is_prime[j] = false; 
            }
        }
    }
    int n_prime[1000000];
    int cnt = 0; 
    for(int i=0; i<1000000; i++){
        if(is_prime[i])
        cnt++;
        n_prime[i] = cnt;
    }
    while(true){
        int n;
        cin >> n;
        if(cin.eof())
        break;
        cout << n_prime[n] << endl;
    }
    return 0;
}


Measured memory_bytes: 7884
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

ll fact[3010] = {0};
ll finv[3010] = {0};
ll inv[3010] = {0};

ll mult(ll n, ll m, ll p){
    if(m==0) return 1;
    if(n==0) return 0;
	if(m==1) return n%p;
	else if(m%2==0){
		ll t = mult(n,m/2,p);
		return t*t%p;
	}else{
		ll t = mult(n,m-1,p);
		return t*n%p;
	}
}

void factorial(ll N, ll p){
	fact[0] = fact[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(ll i=2;i<=N;i++){
		fact[i] = i*fact[i-1]%p;
		inv[i] = p-inv[p%i]*(p/i)%p;
		finv[i] = finv[i-1]*inv[i]%p;
	}
}

ll comb(ll n,ll k, ll p){
	if(n<k) return 0;
	if(n<0 || k<0) return 0;
	else return (((fact[n]*finv[k])%p)*finv[n-k])%p;
}

int main(){
    int p;
    cin >> p;
    factorial(p,p);
    vector<ll> A(p,0),B(p,0);
    vector<vector<ll>> beki(p,vector<ll>(p,1));
    for(int i=1;i<p;i++) beki[0][i] = 0;
    for(int i=1;i<p;i++) for(int j=1;j<p;j++) beki[i][j] = i*beki[i][j-1]%p;
    for(int i=0;i<p;i++) cin >> A[i];
    for(int i=0;i<p;i++){
        if(A[i]==0) continue;
        (B[0] += 1)%=p;
        for(int j=0;j<p;j++){
            ll add = comb(p-1,j,p)*beki[i][j]%p;
            if(j%2==0) (B[p-1-j] += -add+p)%=p;
            else (B[p-1-j] += add)%=p;
        }
    }
    for(int i=0;i<p;i++) cout << B[i] << (i!=p-1? " ":"\n");
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll cur = 1, mv = 0;
    rep(i, n) {
        if (a[i] == cur) {
            mv = max(mv, cur);
            cur++;
        }
    } 
    if (mv == 0) {
        cout << -1 << endl;
    }
    else {
        cout << (n - mv) << endl;
    }
    return 0;
}


Measured memory_bytes: 1792
using System;

namespace Atcoder
{
    class ABC120_A
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            int c = int.Parse(str[2]);
            if(b / a <= c)
            {
                Console.Write(b / a);
            }
            else
            {
                Console.Write(c);
            }

        }
    }
}

Measured memory_bytes: 11092
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    long A = scanner.nextInt();
    long B = scanner.nextInt();
    long C = scanner.nextInt();
    long K = scanner.nextInt();
    long minus = A + B >= K ? 0 : K - A - B;
    long plus = A >= K ? K : A;
    System.out.println(plus - minus);
  }
}


Measured memory_bytes: 35560
////*24-AUG-19*///
//Why do we fall?//
// So we can learn to pick ourself up!//
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define int long long
#define endl "\n"
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fr(a,b,c) for(int a=b; a<c; a++)
#define frr(a,b,c) for(int a=b;a>=c;a--)
#define pb push_back
#define pii pair<int,int>
#define R(a) ll a; cin >> a;

typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;

#define RA(a, n) ll a[(n) + 1] = {}; fr(i, 1, (n)+1) {cin >> a[i];}
#define RM(a, n, m) int a[n + 1][m + 1] = {}; fr(i, 1, n+1) {fr(j, 1, m+1) cin >> a[i][j];}
#define reset(X) memset(X, 0, sizeof(X))
using vi=vector<int>;
const int inf = 1e18;
const int mod=1e9+7;
unsigned int power(int x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
bool isPrime(int n)
{   if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}
int modInverse(int n, int p)
{
    return power(n, p-2, p);
}
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    if(b.fi==a.fi)return (a.se>b.se);
    return (b.fi>a.fi);
}
signed main()
{
    fastio;
    R(h);R(n);
    RA(a,n);
    int sum=0;
    fr(i,1,n+1)
    {
        sum+=a[i];
    }
    if(sum>=h)
    {
        cout<<"Yes"<<endl;
    }
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;
using ull = unsigned long long;

ull gcd(ull a, ull b)
{
    if (a > b) {
        swap(a, b);
    }

    ull r = b % a;
    while (r != 0) {
        b = a;
        a = r;
        r = b % a;
    }

    return a;
}

int main()
{
    ull N, M;
    cin >> N >> M;

    string S, T;
    cin >> S;
    cin >> T;

    ull g = gcd(N, M);
    ull L = N * M / g;

    for (ull i = 0; i < N; ++i) {
        if (i*M % N == 0) {
            ull j = i*M / N;

            if (S[i] != T[j]) {
                std::cout << -1 << std::endl;
                return 0;
            }
        }
    }

    std::cout << L << std::endl;

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>
 
using namespace std;
using namespace __gnu_pbds;
 
#define endl '\n'
 
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template<typename T>
static T randint(T lo, T hi){
	return uniform_int_distribution<T>(lo, hi)(rng);
}


int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int n, m, k;
	cin >> n >> m >> k;

	int xo, yo, xi, yi;
	cin >> xo >> yo >> xi >> yi;
	

	vector<vector<char>> a(n + 1, vector<char>(m + 1));
	vector<set<int>> row(n + 1), col(m + 1);
	vector<set<int>> r_block(n + 1), c_block(m + 1);
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++){
			cin >> a[i][j];
			if(a[i][j] == '@'){
				r_block[i].insert(j);
				c_block[j].insert(i);
				continue;
			}

			row[i].insert(j);
			col[j].insert(i);
		}

	

	priority_queue<pair<int, pii>, vector<pair<int, pii>>, greater<pair<int, pii>>> pq;
	pq.push({0, {xo, yo}});

	row[xo].erase(yo);
	col[yo].erase(xo);

	while(!pq.empty()){
		auto u = pq.top();pq.pop();
		int x = u.second.first, y = u.second.second, cost = u.first;

		if(x == xi && y == yi){
			cout << cost << endl;
			return 0;
		}

		auto lo = r_block[x].lower_bound(y);
		auto hi = r_block[x].upper_bound(y);

		int b, e;

		if(lo == r_block[x].begin())
			b = 0;
		else{
			lo--;
			b = *lo;
		}

		if(hi == r_block[x].end())
			e = m + 1;
		else
			e = *hi;

		lo = row[x].lower_bound(max(b + 1, y - k));
		hi = row[x].upper_bound(min(e - 1, y + k));

		while(lo != hi){
			pq.push({cost + 1, {x, *lo}});
			lo++;
		}

		row[x].erase(row[x].lower_bound(max(b + 1, y - k)), hi);

		lo = c_block[y].lower_bound(x);
		hi = c_block[y].upper_bound(x);

		if(lo == c_block[y].begin())
			b = 0;
		else{
			lo--;
			b = *lo;
		}

		if(hi == c_block[y].end())
			e = n + 1;
		else
			e = *hi;

		lo = col[y].lower_bound(max(b + 1, x - k));
		hi = col[y].upper_bound(min(e - 1, x + k));

		while(lo != hi){
			pq.push({cost + 1, {*lo, y}});
			lo++;
		}

		col[y].erase(col[y].lower_bound(max(b + 1, x - k)), hi);

	}

	cout << -1 << endl;


	return 0;
}

Measured memory_bytes: 192744
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>

using namespace std;

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

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

int main()
{
    int n;
    int v1, v2, v4;
    cin >> n;

    int ans = 0;
    REP(i, n)
    {
        int a;
        cin >> a;

        if (a % 2 == 1)
            v1++;
        else if (a % 4 == 0)
            v4++;
    }

    if (v4 + v1 == n)
        cout << (v4 < v1 - 1 ? "No" : "Yes") << endl;
    else
        cout << (v4 < v1 ? "No" : "Yes") << endl;

    return 0;
}

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

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

int dp[3][2030];
int dpdp[2030];

int main(){
    string s;
    ll n;
    cin >> s;
    n=s.size();
    
    
    for(ll i=0;i<n;i++){
        for(ll j=0;j<2019;j++){
            dp[(i+1)%2][(j*10+(s[i]-'0'))%2019]+=dp[i%2][j];
            dpdp[j]+=dp[i%2][j];
            dp[i%2][j]=0;
            //dp2[j*10+(s[i]-'0')]+=dp[i][j];
        }
        dp[(i+1)%2][(s[i]-'0')]++;
    }
    
    for(ll j=0;j<2019;j++){
            dpdp[j]+=dp[n%2][j];
    }
    
    //cout << dp[1][8] << endl;
    
    cout << dpdp[0] << endl;
    
    return 0;
    
}











Measured memory_bytes: 3648