akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
 
using namespace std;
 
#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)
 
const int N = 1111;
 
 
int n;
vector<int> r;
vector<int> w;
 
int nupsuck(int t, vector<int>& w){
 
    int dp[N][N]={0};
 
    int ret = 0;
    rep(i,w.size()){
        rep(j,t){
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
            dp[i+1][j+w[i]] = max(dp[i+1][j+w[i]], dp[i][j]+w[i]);
        }
    }   
    rep(i,w.size()+1){
        rep(j,t+1)ret = max(ret, dp[i][j]);
    }
 
    rep(i,w.size()+1){
        rep(j,t+1){}
    }
 
    return ret;
}
 
 
bool input(){
    cin>>n;
    if(n==0)return false;
 
    r.clear();w.clear();
 
 
    rep(i,n){
        int a,b;
        cin>>a>>b;
        r.push_back(a);
        w.push_back(b);
    }
 
    return true;
}
 
 
int solve(){
    int wsum = 0, rsum =0;
    int len = 0;
    int lenx = 0;
    rep(i,n){
        wsum += w[i];
        rsum += r[i];
        len = max(len, r[i]);
        if(len==r[i])lenx = i;
    }
 
 
    if(len*2 > rsum){
        vector<int> w2 = w;
        w2.erase(w2.begin() + lenx);
        int np = nupsuck(len-(rsum-len), w2);
        //cout<<len<<" "<<wsum<<" "<<rsum<<" "<<np<<endl;
        return 2*len + wsum - np;
    }
    return rsum+wsum;
}
 
 
int main(){
 
    while(input()){
        cout<<solve()<<endl;
    }
}

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

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int tak=ceil(double(c)/b);
    int aok=ceil(double(a)/d);
    if(tak<=aok) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define bug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i) 
const int inf = 5e18;  
const int mod1 = 998244353;
const int mod = 1e9 + 7;
const int nax = 200005;
int n,x,y,dist[4][nax];
void solve()
 {
  cin>>n;
  loop(i,0,n)
   {
    cin>>x>>y;
    dist[0][i] = x + y;
    dist[1][i] = x - y;
    dist[2][i] = - x - y;
    dist[3][i] = - x + y;
   }
  loop(i,0,4)
   sort(dist[i],dist[i]+n);
  int ans = 0;
  loop(i,0,4)
   ans = max(ans,dist[i][n-1] - dist[i][0]);
  cout<<ans;
 }
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0); 
 /* int t;
  cin>>t;
  while(t--)*/
  solve();
  // cerr<<END<<1.0*clock()/CLOCKS_PER_SEC;
  return 0;
} 

Measured memory_bytes: 9860
#include <bits/stdc++.h>    
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds; 
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
typedef long long ll; 
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long 
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 + 10;
const ll N2      = 70;
//const ld PI  = 3.141592653589793;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}
void solve(){
  #ifndef ONLINE_JUDGE    
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
}
signed main()
{
    fastio();
    solve();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    //*comment for all except cc/cf   
    ll x; 
    cin>>x; 
    ll n=-118,res,res2;
    while(n<120){
      bool ok=1;
      ll m=-119;
      while(m<119){
      ll ans=(ll)pow(n,5)-(ll)pow(m,5);
      if(ans==x){
        ok=0;
        res=n;
        res2=m;
        break; 
      }
      m++;
      }
      if(ok==0){
        break; 
      }
      n++;
    }
    cout<<res<<" "<<res2<<endl; 
    return 0;
}
    

Measured memory_bytes: 4076
fun main(arg: Array<String>) {
    val (n, x) = listOfLong()
//val ans = 3 * (n - gcd(n, x))
    val ans = f(x, n - x) + n
    println(ans)
}
fun listOfLong() = readLine()!!.split(" ").map { it.toLong() }
tailrec fun gcd(a: Long, b: Long): Long = if (a % b == 0L) b else gcd(b, a % b)
tailrec fun f(a : Long, b : Long) : Long {
    if (b == 0L) return -a
    if (a < b) return f(b, a)
    else {
        val m = a / b
        return m * 2 * b + f(b, a % b)
    }
}


Measured memory_bytes: 37760
#include <iostream>

using namespace std;

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

    int count = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == '+')
        {
            count++;
        }
        else
        {
            count--;
        }
    }

    cout << count << endl;
    return 0;
}

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

namespace ConsoleApplication20 {
    class Program {//b55
        static void Main(string[] args) {

            int n = int.Parse(Console.ReadLine());
            var result = Method(n);
            Console.WriteLine(result);

        }

        private static long Method(int n) {
       
            long p = 1;
            long result = 1;

          
            for (int i = 0; i < 9; i++) {
                p = p * 10;  // 10の9乗にする
            }
                p = p + 7; //7を足す
            

            for (int i = 1; i <= n; i++) {
                result = result * i % p;
            }

            return result;
        }
    }
}



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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }
template <class T1, class T2, class Pred = std::less<T2> >
struct sort_pair_second {
    bool operator()(const std::pair<T1,T2>&left, const std::pair<T1,T2>&right) {
        Pred p;
        return p(left.second, right.second);
    }
};

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

    int A, B; cin >> A >> B;
    reps(i, 1000) if ((int)(i * 0.08) == A && (int)(i * 0.1) == B) {cout << i << endl; return 0;}
    cout << -1 << endl; return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin)-1;i>=(end);i--)
#define IREP(i, n) IFOR(i,n,0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=("; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;


template<typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) { REP(i, a.size()) {cin >> a[i]; a[i]--;} }

ll mod = 1000000007;

int main()
{
    ll N, X;
    cin >> N >> X;
    ll ans = 0;
    vec T(N), P(N);
    T[0] = 1;
    P[0] = 1;
    FOR(i, 1, N) {
        T[i] = T[i - 1] * 2 + 3;
        P[i] = P[i - 1] * 2 + 1;
    }

    while (X > 0) {
        if (N == 1) {
            ans += max((ll)0, min(X - 1, (ll)3));
            break;
        }
        else if (X >= 2 + T[N - 1]) {
            ans += P[N - 1] + 1;
            X -= 2 + T[N - 1];
            N--;
        }
        else if (X >= 1 + T[N - 1]) {
            ans += P[N - 1];
            X -= 1 + T[N - 1];
            N--;
        } else {
            X--;
            N--;
        }
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

int main() {
    string a,b,c;
    cin >> a >> b >> c;
    if (a[a.size()-1] == b[0] && b[b.size()-1] == c[0]) {
        cout << "YES" << endl;
        return 0;
    }
    cout << "NO" << endl;
}

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

struct Student {
    int no;
    int arrive;
};

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

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

    std::sort(students.begin(), students.end(), [](const Student& lhs, const Student& rhs) {
        return lhs.arrive < rhs.arrive;
    });

    for (int i = 0; i < N; ++i) {
        std::cout << students[i].no << " ";
    }

    std::cout << std::endl;

    return 0;
}
 


Measured memory_bytes: 1780
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <cctype>
using namespace std;

int main() {
    int n, p[10] = {},m=0,ans=0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        m = max(m, p[i]);
        ans += p[i];
    }
    cout << ans - m / 2 << endl;
}

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

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

Measured memory_bytes: 256
//-----------------------
// author : xyqkoala
// time : 2020-07-06
//-----------------------

#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;

typedef long long LL;
const int MOD = 1e9+7;

void solve();


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


void solve(){
	int n;
	cin>>n;
	vector<int> nums(n);
	for(int i=0;i<n;i++) cin>>nums[i];
	LL res = 0;
	sort(nums.begin(),nums.end(),greater<int>());
	int cnt = n-1;
	if(cnt){
		cnt--;
		res+=nums[0];
	}
	int idx = 1;
	while(cnt){
		if(cnt){
			res+=nums[idx];
			cnt--;
		}
		if(cnt){
			res+=nums[idx++];
			cnt--;
		}
	}
	cout<<res<<endl;
}


Measured memory_bytes: 3976
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <unordered_map>
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) find(Range(c), x) != c.end()
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]
void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ std::cin >> head; _cin(std::forward<Tail>(tail)...); }
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; For(i, n){ Cin(T, x); map[x] ++; }
#define Cout(x) cout << (x) << "\n"
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Couty(cond) Cout((cond) ? "Yes" : "No")
#define CoutY(cond) Cout((cond) ? "YES" : "NO")

using namespace std;
using ll = long long;

int main(void){
  Cin(string, s);
  for(int i = 0; i < s.size(); i += 2) cout << s[i];
  cout << "\n";
}


Measured memory_bytes: 512
import heapq

n, h = [int(i) for i in input().split()]
attack = 0
throw = []

for _ in range(n):
    a, b = [int(i) for i in input().split()]
    attack = max(a, attack)
    heapq.heappush(throw, -b)

cnt = 0
t = -heapq.heappop(throw)
while h > 0:
    if t > attack:
        h -= t
        cnt += 1
        if throw:
            t = -heapq.heappop(throw)
        else:
            t = -1
    else:
        cnt += h // attack
        if h % attack > 0:
            cnt += 1
        break

print(cnt)


Measured memory_bytes: 82352
x=int(input())
a = 0
b = 0

for i in range(1000):
    for j in range(1,1000):
        tmp = (i*i*i*i*i) + (j*j*j*j*j)
        if x == tmp:
            a = i
            b = -j
            break

for i in range(1000):
    for j in range(1,1000):
        tmp = (i*i*i*i*i) - (j*j*j*j*j)
        if x == tmp:
            a = i
            b = j
            break

print(a,b)

Measured memory_bytes: 9208
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<random>

#define rep(i,n) for(int i=0; i<n; i++)

using namespace std;

typedef long long ll;



int N, M;
ll K, a[20000];
ll dp[20005];

int main() {
	cin >> N >> M >> K;
	rep(i, N) {
		cin >> a[i];

		dp[i + 1] = 1ll << 60;
	}

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

		ll amx = 0, amn = 1ll << 60;
		for (int j = 0; j < M; j++) {
			if (i + j >= N) break;

			amx = max(amx, a[i + j]);
			amn = min(amn, a[i + j]);

			dp[i + j + 1] = min(dp[i + j + 1], dp[i] + (K + (amx - amn)*(j + 1)));
		}
	}

	cout << dp[N] << endl;


	return 0;
}


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

int main(){
    vector<int> a;
    int n;
    cin >> n;
    a.resize(n+1);
    for(int i = 1; i <= n; i++)cin >> a[i];
    int ans = 0;
    for(int i = 1; i <= n; i += 2){
        if (a[i]%2 == 1)ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3144
/**************************************************
 * Atcoder problems
 * Contest No :081
 * Problem No :A
 * File Name  :program_copy.cs
 * Create date:2020/06/07
 *
 * Copyright 2020 Shunichi Sato,All Rights Reserved.
**************************************************/
//memo terinal command
//compile:mcs program.cs
//excute :mono program.exe
using System;
class Program
{
	static void Main(string[] args)
	{
        // 整数の入力
        string input = Console.ReadLine();
		// 個数の判定
		int output = 0;
        if (input[0] == '1')
        {
            output++;
        }
        if (input[1] == '1')
        {
            output++;
        }
        if (input[2] == '1')
        {
            output++;
        }
		//出力
		Console.WriteLine(output);
	}
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;

int a[N], sum[N];
int fac[N], inv[N];

void init() {
  fac[0] = fac[1] = inv[0] = inv[1] = 1;
  for (int i = 2; i < N; ++i) {
    fac[i] = 1ll * fac[i - 1] * i % MOD;
    inv[i] = 1ll * (MOD - MOD/i) * inv[MOD%i] % MOD;
  }
  for (int i = 2; i < N; ++i) inv[i] = 1ll * inv[i] * inv[i - 1] % MOD;
}

void solve() {
  int n;
  scanf("%d", &n);
  sum[0] = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    sum[i] = (sum[i - 1] + a[i]) % MOD;
  }
  int ans = 0;
  n --;
  for (int i = 1; i < n; ++i) {
    int tp = 1ll * fac[i - 1] * fac[n] % MOD * inv[i + 1] % MOD;
    int xd = (sum[n] - sum[i] - sum[n - i]) % MOD + MOD;
    xd %= MOD;
    tp = 1ll * tp * xd % MOD;
    ans = (ans + tp) % MOD;
  }
  //cout << ans << endl;
  n ++;
  for (int i = 1; i < n; ++i) {
    int tp = 1ll * fac[i - 1] * fac[n - 1] % MOD * inv[i] % MOD * ((a[n] - a[n - i] + MOD) % MOD) % MOD;
    ans = (ans + tp) % MOD;
  }
  printf("%d\n", ans);
}

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


Measured memory_bytes: 1792
from itertools import permutations
from math import sqrt, factorial
n = int(input())

towns = []
for i in range(n):
    towns.append(list(map(int, input().split())))

perms = permutations(towns)

sum_dists = 0
for path in list(perms):
    for i in range(n-1):
        dist = sqrt((path[i+1][0] - path[i][0])**2 +
                    (path[i+1][1] - path[i][1])**2)
        sum_dists += dist

print(sum_dists / factorial(n))


Measured memory_bytes: 7972
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
#include<queue>
#include<cmath>

#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(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(a, n) sort(a, a+n)
#define VSORT(v) sort(v.begin(), v.end())

using namespace std;

int main()
{
    int n;

    cin >> n;

    int h[n];

    REP(i, n) {
        cin >> h[i];
    }

    int cost[n];
    cost[0] = 0;
    cost[1] = abs(h[0]-h[1]);


    FOR(i, 2, n) {
        cost[i] = min(cost[i-1] + abs(h[i] - h[i-1]), cost[i-2] + abs(h[i] - h[i-2]));
    }

    cout << cost[n-1] << endl;

    return 0;
}

Measured memory_bytes: 1024
object Main {

  trait Monoid[A]{
  	def op(a1: A, a2: A): A
  	def zero: A
  }

  class PersistentSegmentTree[A](val numOfNode: Int, val M: Monoid[A]){

  	sealed trait Tree{ val value: A }
  	case object Empty extends Tree{ val value: A = M.zero }
  	case class Node(value: A, left: Tree, right: Tree) extends Tree
  	object Node {
  		def apply(value: A) = new Node(value, Empty, Empty)
  		def apply(l: Tree, r: Tree) = new Node(M.op(l.value,r.value),l,r)
  	}

  	private val nil: Node = Node(M.zero,Empty,Empty)
  	private[this] var root: Tree = nil

  	private def updateRec(id: Int, x:A, l: Int = 0, r: Int = numOfNode, t: Tree = root): Tree = {
  		val m = (l + r)/2
  		def branch(now: Node): Node = {
  			if(r-l<=1)Node(x)//Node(M.op(now.value,x))
  			else if(id < m)Node(updateRec(id,x,l,m, now.left), now.right)
  			else Node(now.left,updateRec(id,x,m,r,now.right))
  		}
  		t match {
  			case now:Node => branch(now)
  			case now:Tree => branch(nil)
  			case _ => nil
  		}
  	}

  	def update(id: Int, x: A):Unit = {
  		root = updateRec(id, x)
  	}

  	def query(a: Int, b: Int, l: Int = 0, r: Int = numOfNode, t: Tree = root): A = {
  		val m = (l + r)/2
  		t match {
  			case now: Node => {
  				if(b<=l || r<=a)M.zero
  				else if(a<=l && r<=b)now.value
  				else M.op(query(a,b,l,m,now.left),query(a,b,m,r,now.right))
  			}
  			case _ => M.zero
  		}
  	}
  }

  def main(args: Array[String]): Unit = {
  	val line = scala.io.StdIn.readLine.split(" ").map(_.toInt)
  	val n = line(0)
  	val q = line(1)
  	val m = new Monoid[Int]{
  		def op(a1: Int, a2: Int): Int = a1 min a2
  		def zero: Int = Int.MaxValue
  	}

  	val segtree = new PersistentSegmentTree[Int](n,m)

  	for(i <- 1 to q){
  		val input = scala.io.StdIn.readLine.split(" ").map(_.toInt)
  		val x = input(1)
  		val y = input(2)
  		if(input(0)==0)segtree.update(x,y)
  		else println(segtree.query(x,y+1))
  	}
  }
}

Measured memory_bytes: 192756
#include<cstdio>
#include<vector>
#include<iostream>
using namespace std;
int n, a[200005], b[200005];
vector < int > ans;
inline void dd() {
    for (int i = 1; i <= n; ++i)
        printf("%d ", b[i]);
}
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    for (int i = n; i >= 1; --i) {
        int t = 0;
        for (int j = i; j <= n; j += i) {
            t += b[j];
        }
        if ((t % 2) != a[i]) {
            b[i] = 1;
            ans.push_back(i);
        }
    }
    printf("%d\n", ans.size());
    for (int i = 0; i < ans.size(); ++i)
        printf("%d ", ans[i]);
    return 0;
}

Measured memory_bytes: 2936
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
    int n;
    scanf("%d",&n);
    bool f=false;
    while(n) {
        if(n%10==7) f=true;
        n/=10;
    }
    printf("%s\n",f?"Yes":"No");
    return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ul unsigned long int
#define ld long double
#define f(t) for(ll i =0;i<t;i++)
#define vi vector<int>
#define vl vector<ll>
#define pri pair<int,int>
#define mpi map<int,int>
#define prl pair<ll,ll>
#define mp make_pair
#define mpl map<ll,ll>
#define umpl unordered_map<ll,ll>
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define inf 2e18
#define EPS 1e-3
#define PI 3.1415926535897932385
const double h = 1e-6;
const int MAX_  = 100005;
#define display(v) f(v.size())cout << v[i] << " "
#define all(v) v.begin(),v.end()

inline ll mul(ll a, ll b){ return (a * 1ll * b) % MOD; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += MOD; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > MOD) c -= MOD; return c; }
 //////////////////////*********CODE***********/////////////////////
 //////////////////////////////////////////////////////////////////

int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   int n,x,y;  cin>>n>>x>>y;
   map<int,int> m;
   for(int i = 1;i<=n;i++)
   {
      for(int j =i+1;j<=n;j++)
      {
         int val = min(abs(i-j),min(abs(x-i)+1+abs(y-j) , abs(x-j) + abs(y-i) +1 ));
         m[val]++;
      }
   }
   for(int i=1;i<n;i++)cout << m[i] << "\n";
   return 0;
}     

Measured memory_bytes: 384
a, b, c, k = map(int, input().split())
val = 0
val += 1 * min(a, k)
k -= min(a, k)
val += 0 * min(b, k)
k -= min(b, k)
val += -1 * min(c, k)
k -= min(c, k)
print(val)


Measured memory_bytes: 9128
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << (c - b == b - a ? "YES" : "NO");
}


Measured memory_bytes: 256
import kotlin.math.max
import kotlin.math.min

fun main() {
    abc145d()
}

fun abc145d() {
    val (x, y) = readLine()!!.split(" ").map { it.toInt() }
    if (x == y && x % 3 != 0) {
        // xとyが同じ値の場合、3の倍数でないと到達不可能
        // 2,2とか8,8とか
        println(0)
        return
    }
    // パスカルの三角形で考えれば答えは出るが、すべての組み合わせを求めていくと時間内におさまらないと思われる
    val small = min(x, y)
    val big = max(x, y)
    if (small * 2 == big) {
        // x,yの座標の小さい方の2倍＝大きい方ならその移動パターンは1しかない（1,2移動を選び続けるor2,1を選び続けるしかないので）
        println(1)
        return
    }
    if (small * 2 <= big) {
        // xとyの関係はお互いの2倍までの範囲内が限度なので、それを超えた盤面ではXYに到達不可能
        println(0)
        return
    }
    // 3の倍数のマスを基準に探していけば早い気がする
    var one = (x + y) / 3
    var two = 0
    var found = false
    while (!found && one > 0) {
        if ((one + two * 2 == small && one * 2 + two == big) ||
            (one + two * 2 == big && one * 2 + two == small)) {
            found = true
            break
        }
        two++
        one--
    }
    if (found) {
        val depth = one + two
        val memo = mutableMapOf<Pair<Int, Int>, Int>()
        val pattern = triangle(depth, two, memo)
        println(pattern % 1_000_000_007)
    } else {
        // 到達できない
        println(0)
    }
}

private fun triangle(i: Int, j: Int, memo: MutableMap<Pair<Int, Int>, Int>): Int {
    //    if (i == j) return 1
    //    if (i == 0 || j == 0) return 1
    //    if (j == 1 || j + 1 == i) return i
    //    if (i to j in memo) {
    //        return memo.getOrDefault(i to j, 1)
    //    }
    //    val one = triangle(i -1, j -1, memo)
    //    val two = triangle(i - 1, j, memo)
    //    memo[i to j] = one + two
    //    return one + two
    val base_num = 1_000_000_007
    val max_num = i + 1
    val fac = LongArray(max_num) { 1L }
    val inv = LongArray(max_num) { 0L }
    val finv = LongArray(max_num) { 1L }
    inv[1] = 1L
    for (k in 2 until max_num) {
        fac[k] = fac[k - 1] * k % base_num
        inv[k] = base_num - inv[base_num % k] * (base_num / k) % base_num
        finv[k] = finv[k - 1] * inv[k] % base_num
    }
    val ans = fac[i] * (finv[j] * finv[i - j] % base_num) % base_num
    return ans.toInt()
}


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

using namespace std;

int main() {
	int ans = 0;
	string s;
	cin >> s;

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


	return 0;

}

Measured memory_bytes: 512
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

struct Sieve{
	int n;
	vector<int> f, primes;
	Sieve(int n):n(n), f(n+1){
		f[0] = f[1] = -1;
		for(long long i = 2; i <= n; i++){
			if(f[i]) continue;
			primes.push_back(i);
			f[i] = i;
			for(long long j = i*i; j <= n; j += i){
				if(!f[j]) f[j] = i;
			}
		}
	}
	bool isPrime(int x){return f[x] == x;}
	vector<int> factorList(int x){
		vector<int> res;
		while(x != 1){
			res.push_back(f[x]);
			x /= f[x];
		}
		return res;
	}
	vector<pair<int, int>> factor(int x){
		vector<int> fl = factorList(x);
		if(fl.size() == 0) return {};
		vector<pair<int, int>> res(1, pair<int, int>(fl[0], 0));
		for(int p : fl){
			if(res.back().first == p){
				res.back().second++;
			}
			else{
				res.emplace_back(p, 1);
			}
		}
		return res;
	}
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    Sieve sie(55556);
    vector<int> pf_list = sie.primes;
    vector<int> ans;
    for(auto p : pf_list){
        if(p%5 == 1) ans.push_back(p);
        if(ans.size() == n) break;
    }
    for(auto q : ans){
        cout << q << " ";
    }
    cout << endl;
    return 0;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

// 0, M / G, 2 * M / G, ..., (N - 1) * M / G
//  ^
//  | 同じ位置で同じ文字か調べる。
//  v
// 0, N / G, 2 * N / G, ..., (M - 1) * N / G
// N = M; S = T or NG
// N != M; L = LCM(N, M) 最小。Lを伸ばしても、上の条件判定は変わらない。

int main() {
  ll N, M; cin >> N >> M;
  string S, T; cin >> S >> T;
  if (N == M) {
    return !printf("%lld\n", S == T ? 2 * N : -1LL);
  }
  if (S[0] != T[0]) {
    return !printf("-1\n");
  }
  auto G = __gcd(N, M);
  auto L = N / G * M;
  rep(k, L) {
    if (k % (M / G) == 0 && k % (N / G) == 0) {
      auto i = k / (M / G);
      auto j = k / (N / G);
      assert(i < N && j < M);
      if (S[i] != T[j]) {
        return !printf("-1\n");
      }
    }
  }
  printf("%lld\n", L);
}


Measured memory_bytes: 512
/* Everything happens for a reason.
Be patient, things will be at their rightful place.
It was meant to happen this way, accept it.
And now decide what you can make out of this life.
*/
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define ip pair<ll,ll>
#define vii vector<ll>
#define vpp vector<ip>
#define vdd vector<ld>
#define vb vector<bool>
#define pi  pair<ll,ip>
#define sc(x) scanf("%lli",&x)
#define c(x) cin >> x
#define fo(i,k,n) for( int i=k;i<n;i++)
#define hu 200010
#define pq priotity_queue<ll>
#define pqs priority_queue<ll,vii,greater<ll>>
#define ppq priority_queue<ip,vpp,greater<ip>>
#define INF INT_MAX
#define ff first
#define ss second
using namespace std;
const ll M = 1000000000+7;
//Grid Movement
ll dx[] = {-1, 0, 1, 0};
ll dy[] = {0, -1, 0, 1};

ld Pi= acos(-1);

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

ll mex(ll x, ll y) 
{ 
	ll res = 1;	  
	x = x % M; 
	if (x == 0) return 0; 
	while (y > 0) 
	{ 
		if (y & 1) 
		res = (res*x) % M; 
		y = y>>1; 
		x = (x*x) % M; 
	} 
	return res; 
} 

bool comp(ll comp1,ll comp2)
{
    return comp1>comp2;
}

void yes()
{
    printf("YES\n");
}

void no()
{
    printf("NO\n");
}

ll inv(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
 
    if (m == 1)
      return 0;
 
    while (a > 1)
    {
        int q = a / m;
        int t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
 
    if (x < 0)
       x += m0;
 
    return x;
}

void sieve(ll n)
{
    vii primes(n+1);
    vb is_prime(n+1);
	is_prime.resize(n+1);
	primes.resize(n+1);
 
	is_prime[0] = is_prime[1] = false;
	for(int i = 2; i<=n; i++)
	{
	    if(is_prime[i])
	    {
	    	primes.pb(i);
	        for (int j = i*i; j<=n; j+=i)
	            is_prime[j] = false;
	    }
	}
}


int main()
{
    ll n;
    sc(n);
    ll a[n],sum = 0;
    
    fo(i,0,n) {
        sc(a[i]);
        sum+=a[i];
        sum = sum%M;
    }
    
    ll b[n-1];
    b[0] = (M+sum-a[0])%M;
    fo(i,1,n-1) b[i] = (b[i-1]-a[i]+M)%M;
    sum = 0;
 /*   for(auto it:a)cout << it << " ";
    cout << endl;
    for(auto it:b) cout << it << " ";
    cout << endl;
    */
    fo(i,0,n-1)
    {
        sum = (sum+(a[i]*b[i])%M)%M;
    }
    
    printf("%lli\n",sum);
    
}





Measured memory_bytes: 6912
Module Module1
    Sub Main()
        Dim x, a, b, c, a0, b0, c0, cnt
    
        a0 = Int(Console.ReadLine)
        b0 = Int(Console.ReadLine)
        c0 = Int(Console.ReadLine)
        x = Int(Console.ReadLine)
        
        cnt = 0
        For a = 0 To a0             '500円玉
            For b = 0 To b0         '100円玉
                For c = 0 To c0     ' 50円玉
                    If 500 * a + 100 * b + 50 * c = x Then
                        cnt = cnt + 1
                    End If
                Next c
            Next b
        Next a

        Console.WriteLine (cnt)

    End Sub
End Module

Measured memory_bytes: 22600
#include <stdio.h>
int S[100000],n;
int binarySearch(int);

int main(){
  int q,key,i,count=0;

  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&S[i]);

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&key);
    if(binarySearch(key))
      count++;
  }  
  
  printf("%d\n",count);
  
  return 0;
}

int binarySearch(int key){
  int left=0,right=n,mid;
  
  while(left<right){
    mid=(left+right)/2;
    if(S[mid]==key)
      return 1;
    if(key<S[mid])
      right=mid;
    else
      left=mid+1;
  }
  return 0;
}

Measured memory_bytes: 988
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define rnd(x, y) uniform_int_distribution<ll>(x, y)(rng)

//struct custom_hash {
//    static uint64_t splitmix64(uint64_t x) {
//        // http://xorshift.di.unimi.it/splitmix64.c
//        x += 0x9e3779b97f4a7c15;
//        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
//        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
//        return x ^ (x >> 31);
//    }
//    size_t operator()(uint64_t x) const {
//        static const uint64_t FIXED_RANDOM = 
//            chrono::steady_clock::now().time_since_epoch().count();
//        return splitmix64(x + FIXED_RANDOM);
//    }
//};

#define fi first
#define se second

ll dist[200005];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,x,y;
	cin>>n>>x>>y;
	for(ll i=1;i<=n;i++)
	{
	    for(ll j=i+1;j<=n;j++)
	    {
	        ll dodo=0;
	        ll dodo1=abs(i-x)+abs(j-y)+1;
	        ll dodo2=abs(j-i);
	        dodo=min(dodo1,dodo2);
	        dist[dodo]++;
	    }
	}
	for(ll i=1;i<=(n-1);i++)
	{
	    cout<<dist[i]<<endl;
	}
    return 0;
}


//252908XL

/*
comments:-

*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main(){
	string r,a;
	while(1){
		int h=0,b=0;
		cin>>r>>a;
		if(r=="0" && a=="0") break;
		rep(i,0,4){
			if(r.find(a[i])!=string::npos) b++;
		}
		rep(i,0,4){
			if(r[i]==a[i]){
				b--; h++;
			}
		}
		o(h<<" "<<b);
	}
}

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

/* -------------------------------- Template -------------------------------- */

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

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

template<typename T> T inf() { assert(false); }
template<> constexpr int inf<int>() { return 1e9; }
template<> constexpr ll inf<ll>() { return 1e18; }
template<> constexpr ld inf<ld>() { return 1e30; }

/* -------------------------------- Library -------------------------------- */

/* ---------------------------------- Main ---------------------------------- */

int main() {
  ll n, x;
  cin >> n >> x;
  vector<ll> a(n);
  for (ll &i: a) cin >> i;
  ll res = inf<ll>();
  REP(i,n+1) {
    chmin(res, accumulate(ALL(a), 0LL) + x * i);
    vector<ll> b = a;
    REP(j,n) chmin(b[(j+1)%n], a[j]);
    a = b;
  }
  cout << res << endl;
  return 0;
}


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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)

const LL mod=(1e9)+7;
int main()
{
    LL n;
    cin>>n;
    LL a[n];
    LL mx=INF;
    set<string>st;
    int f=0;
    REP(i,n)
    {
       string s;
       cin>>s;
       st.insert(s);
    }
    cout<<st.size();


}



Measured memory_bytes: 19204
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;cin>>s;
  string t=s;
  for(int i=0;i<s.size();i++)t[i]=s[s.size()-1-i];
  string u=t;
  string a="maerd",b="remaerd",c="esare",d="resare";
  string ans="";
  for(;;){
    if(t.substr(0,5)==a){
      ans+=a;
      t.erase(t.begin(),t.begin()+5);
    }
    else if(t.substr(0,7)==b){
      ans+=b;
      t.erase(t.begin(),t.begin()+7);
    }
    else if(t.substr(0,5)==c){
      ans+=c;
      t.erase(t.begin(),t.begin()+5);
    }
    else if(t.substr(0,6)==d){
      ans+=d;
      t.erase(t.begin(),t.begin()+6);
    }
    else{
      cout<<"NO"<<endl;
      return 0;
    }
    if(ans==u){
      cout<<"YES"<<endl;
      return 0;
    }
  }
}
    
  

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

typedef long long ll;
typedef pair<ll, ll> P;

int a, b;

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

    if(b < 10)          a *= 10;
    else if(b < 100)    a *= 100;
    else                a *= 1000;

    int num = a + b;

    string ans = "No";
    for(int i=1;i*i<=num;i++){
        if(num % i != 0)    continue;
        int j = num / i;
        if(j == i){
            ans = "Yes";
            break;
        }
    }

    cout << ans << endl;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>0;(i)--)
#define rrep(i,n,m) for(int (i)=(n);(i)<(m);(i)++)
#define rrepr(i,n,m) for(int (i)=(n);(i)>(m);(i)--)
#define esort(s) sort((s).begin(),(s).end())

typedef long long ll;
typedef pair<int,int> ipair;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;

const int INF = 1000000000;
const ll LINF = 1000000000000000000;
const double PI = acos(-1.0);
const double EPS = 1e-10;

const ll MOD = 1000000007ll;
const int MAX=510000;

int N;
vi A;

void solve(){
    cin>>N;
    rep(i,N) {int x;cin>>x;A.push_back(x);}

    int ans=-1;
    int num=1;
    rep(i,N){
        // cout<<A[i]<<" "<<num<<"\n";
        if(A[i]==num) {ans=num;++num;}
    }
    cout<<((ans>0)?(N-ans):ans)<<endl;
    return;
}

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

    solve();
    return 0;
}

Measured memory_bytes: 1400
k, x = map(int, input().split())


def solve():
    _min_tmp = (x - k + 1)
    _max_tmp = (x + k - 1)
    _min = max(-1000000, _min_tmp)
    _max = min(1000000, _max_tmp)

    ans = list(map(str, range(_min, _max + 1)))

    return ' '.join(ans)


print(solve())


Measured memory_bytes: 3060
n=int(input())
l=list(map(int,input().split()))
c=0
l.sort()
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if(l[i]!=l[j]!=l[k] and (l[i]+l[j]>l[k])):
                c=c+1
print(c)


Measured memory_bytes: 67472
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, k;
  cin >> n >> k;
  vector<int> vec(1);
  for(int i=1;i<k+1;i++){
    int d;
    cin >> d;
    for(int a=0;a<d;a++){
     int A;
     cin >> A;
     if(a==0 && i==1){
        vec.at(0)=A;
      }
     for(int j=0;j<vec.size();j++){
      if(j==vec.size()-1 && A!=vec.at(j)){
        vec.push_back(A);
      }
      if(A==vec.at(j)){
        break;
      }
     }
     
    }
  }
  cout << n-vec.size() << endl;
}
  
    
  

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int>;

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

int N;
ll A, B, C[2], S[100100];
bool D[2][18][100100];
const ll MOD = 1e9 + 7;
ll dp[100100][2];

inline bool ok(int l, int r, bool which){
    int length = r - l, k = 0;
    bool res = true, flag = false;
    while(length > 0){
        if(length & 1){
            res = res && D[which][k][l] &&
                (!flag || (S[l] - S[l-1] >= C[which]));
            l += (1 << k);
            flag = true;
        }

        length >>= 1;
        ++k;
    }
    
    return res;
}

ll rec(int idx, bool which){
    if(idx == -1){return 0ll;}
    if(dp[idx][which] != -1ll){return dp[idx][which];}

    int x = idx, y = idx + 1, w = which;
    while( true ){
        y = lower_bound(S, S+N, S[x] + C[w]) - S;

        if(!ok(x + 1, y, !w)){
            x = -1;
            break;
        }
        if(y - x == 1 || y == N || S[y] - S[y-1] >= C[!w]){
            x = y;
            break;
        }else{
            x = y - 1;
            w = !w;
        }
    }

    ll res = x < N ? (rec(x, 0) + rec(x, 1)) : 1ll;
    res %= MOD;

    // printf("%d, %d: %lld\n", idx, which, res);
    return dp[idx][which] = res;
}

void prepare(){
    for(int i=0;i<2;i++){
        for(int k=0;k<N;k++){
            D[i][0][k] = true;
        }        
        
        for(int j=0;j<17;j++){
            int size = 1 << j;
            for(int k=0;k<N;k++){
                if(k + size >= N){
                    D[i][j+1][k] = D[i][j][k];
                }else{
                    D[i][j+1][k] =
                        D[i][j][k] &&
                        D[i][j][k+size] &&
                        (S[k+size] - S[k+size-1] >= C[i]);
                }
            }
        }
    }
}

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

    std::cin >> N >> A >> B;
    C[0] = A; C[1] = B;

    for(int i=0;i<N;++i){
        std::cin >> S[i];
    }

    prepare();
    
    memset(dp, -1ll, sizeof(dp));

    // rec(0, 1);
    // return 0;
    
    ll res = rec(0, 0) + rec(0, 1);
    res %= MOD;
    std::cout << res << std::endl;
}


Measured memory_bytes: 15488
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int ans=0,ans1=0;
  for(int i=0;i<s.size();i++)
      ans=ans*10+s[i]-'0',
      ans1=ans1+s[i]-'0';
    if(ans%ans1==0)cout<<"Yes";
    else cout<<"No";
return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    // Your code here!
    
    val S: String = readLine()!!
    var l = mutableMapOf<Char, Int>()
    for (item in S) {
        if (l.containsKey(item)) {
            l[item] = l[item]!! + 1
        } else {
            l.put(item, 1)
        }
    }

    if (l.size == 2 && l.values.all({it == 2})) {
        println("Yes")
    } else {
        println("No")
    }
}


Measured memory_bytes: 33532
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#include <bitset>
#define M 1000000007
#define M1 998244353

#define tr(container, it) \
    for (typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

ll power(ll x, ll n)
{
    ll result = 1;
    while (n)
    {
        if (n % 2 == 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}

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

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

inline ll mul(ll x, ll y, ll m)
{
    ll z = 1LL * x * y;
    if (z >= m)
    {
        z %= m;
    }
    return z;
}

ll powmod(ll x, ll y, ll m)
{
    ll r = 1;
    while (y)
    {
        if (y & 1)
        {
            r = mul(r, x, m);
        }
        y >>= 1;
        x = mul(x, x, m);
    }
    return r;
}

void start()
{
    fast;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
/***********************************************************************************************************/

int solve(int *a, int n, int *dp)
{
    if (n == 1)
    {
        return dp[n] = 0;
    }
    if (n == 2)
    {
        return dp[n] = abs(a[n - 1] - a[n - 2]);
    }
    if (dp[n] != -1)
    {
        return dp[n];
    }
    return dp[n] = min(abs(a[n - 1] - a[n - 2]) + solve(a, n - 1, dp), abs(a[n - 1] - a[n - 3]) + solve(a, n - 2, dp));
}

int main()
{
    start();
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int dp[n + 1];
    memset(dp, -1, sizeof(dp));
    cout << solve(a, n, dp);
    return 0;
}

Measured memory_bytes: 8256
def main():
    t = list(input())

    q_list = []

    for i in range(len(t)):
        if t[i] == '?':
            q_list.append(i)

    for q in q_list:
        if q != 0 and t[q-1] == 'P':
            t[q] = 'D'
        elif q != len(t)-1 and t[q+1] == 'D':
            t[q] = 'P'
        else:
            t[q] = 'D'

    print(''.join(t))
    #score = t.count('P') + t.count('D') + t.count('PD')

if __name__ == '__main__':
    main()

Measured memory_bytes: 18464
#include <iostream>
#define LL long long
using namespace std;

int main(void) {
  int a, b;
  char op;
  cin >> a >> op >> b;

  if (op == '+') {
    cout << a+b << endl;
  } else if (op == '-') {
    cout << a-b << endl;
  }
  return 0;
}


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



int main()
{
    int N,M,C;
    std::cin >> N >> M >> C;
    std::vector<int> B;
    std::vector<std::vector<int>> A;

    for(int i = 0; i < M; ++i){
        int b;
        std::cin >> b;
        B.push_back(b);
    }
    A.resize(N);
    for(int i = 0; i< N; ++i){
        for(int j = 0; j<M; ++j){
            int a;
            std::cin >> a;
            A[i].push_back(a);
        }
    }

    int count = 0;
    for(int i =0; i < N; ++i){
        int sum = 0;
        for(int j = 0; j < M; ++j){
            sum += A[i][j] * B[j];
        }
        if(sum > -C) count++;
    }
    std::cout <<  count << std::endl; 

    return 0;
}




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

int main() {
    int a, b;
    cin >> a >> b;
    cout << (a - 1) * (b - 1) << endl;
}

Measured memory_bytes: 256