akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>
#include <cmath>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e6 * 2 + 10, INF = 1e9 * 1e9 + 10;



int main()
{
    fastInp;

    ll n;
    cin >> n;
    vector<ll> vec(n);
    map<ll, ll> cnt;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> vec[i];
        cnt[vec[i]]++;
        cnt[vec[i] - 1]++;
        cnt[vec[i] + 1]++;
        ans = max(ans, cnt[vec[i]]);
        ans = max(ans, cnt[vec[i] - 1]);
        ans = max(ans, cnt[vec[i] + 1]);
    }

    cout << ans;
    
    return 0;
}

Measured memory_bytes: 9864
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

### 素数の逆元とCombination

M = p
N = 10**4 # 必要なテーブルサイズ

g1 = [None] * (N+1) # 元テーブル
g2 = [None] * (N+1) #逆元テーブル
inverse = [None] * (N+1) #逆元テーブル計算用テーブル
g1[0] = g1[1] = g2[0] = g2[1] = 1
inverse[0], inverse[1] = [0, 1] 

for i in range( 2, N + 1 ):
    g1[i] = ( g1[i-1] * i ) % M 
    inverse[i] = ( -inverse[M % i] * (M//i) ) % M # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
    g2[i] = (g2[i-1] * inverse[i]) % M 

def cmb(n, r, M):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return (g1[n] * g2[r] * g2[n-r]) % M
ans = [0]*p
for i,num in enumerate(a):
    if num==0:
        continue
    val = 1
    for j in reversed(range(p)):
        ans[j] += -cmb(p-1,j,M) * val #pow(-i,p-1-j,M)
#         ans[j] += -cmb(p-1,j,M) * pow(-i,p-1-j,M)
        ans[j] %= M
        val *= -i
        val %= M
    ans[0] += 1
for i in range(p):
    ans[i] %= M
write(" ".join(map(str, ans)))

Measured memory_bytes: 75340
n, t = map(int, input().split())
dp = [0] * (t + 1)
ab = [tuple(map(int, input().split())) for _ in range(n)]
ab.sort()
max_b = [0] * n
max_b[-1] = ab[-1][1]
for i in range(n - 1, 0, -1):
    max_b[i - 1] = max(ab[i - 1][1], max_b[i])
for i in range(n - 1):
    a, b = ab[i]
    for j in range(t - 1, a-1, -1):
        dp[j] = max(dp[j - a] + b, dp[j])
    dp[t] = max(dp[t], dp[t-1] + max_b[i + 1])
print(max(dp))



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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

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

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

const ll INF=(ll)1e19;
//const int INF=(1<<30);

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

  int ans = (1<<30);
  REP(i,N){
    int c,t;
    cin >> c >> t;
    if(t > T)continue;
    chmin(ans,c);
  }
  if(ans == (1<<30)){
    cout << "TLE" << endl;
  }else{
    cout << ans << endl;
  }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 


// abc073d
vi to[305];
int dist[305][305];
int n,m,r;
bool used[10];
int village[10];
int ans = INF;
void dfs(int v=-1, int num=0, int sum=0)  {
  if (num == r) {
    chmin(ans, sum);
    return;
  }   
  rep(i, r) {
    if (i==v) continue;
    if (used[i])continue;
    used[i] = true;
    int ns;
    if (v!=-1) ns = sum + dist[village[i]][village[v]];
    else ns = 0;
    dfs(i, num+1, ns);
    used[i] =false;
  }
}

int main() {
   cin >> n >> m >> r;
  rep(i,n) rep(j, n) {
    dist[i][j] = INF;
    if (j==i) dist[i][j] = 0;
  }
  rep(i,r) {
    cin >> village[i];
    village[i]--;
  }
  rep(i,m) {
    int a,b,c; cin >> a >> b >> c;
    a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
    dist[a][b] = c;
    dist[b][a] = c; 
    } 
    rep(k, n)rep(i, n) rep(j, n) chmin(dist[i][j], dist[i][k]+dist[k][j]); 
  dfs();
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4032
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define be begin()
#define en end()
#define le length()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (__typeof(n) i = 0; i < n; i++)
#define repo(i, n) for (__typeof(n) i = 1; i <= n; i++)
#define eps 1e-6
#define pi 3.141592653589793
#define c(a) cout << a << "\n";
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAX = 2e5+6;
bool prime[10000009];
int main(){
   ll n;
   cin>>n;
   string s,a;
   cin>>s>>a;
   rep(i,n) cout<<s[i]<<a[i];
    
}

Measured memory_bytes: 256
import math
while 1:
    a1,m1,a2,m2,a3,m3=map(int,input().split())
    if a1==m1==a2==m2==a3==m3==0:break
    i=1
    x,y,z=0,0,0
    while 1:
        i=(a1*i)%m1
        x+=1
        if i==1:break
    while 1:
        i=(a2*i)%m2
        y+=1
        if i==1:break
    while 1:
        i=(a3*i)%m3
        z+=1
        if i==1:break
    xy=int(x*y/math.gcd(x,y))
    xyz=int(xy*z/math.gcd(xy,z))
    print(xyz)


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

using namespace std;

int n,a[100005],f[100005],i,ans;
 
int main()
{
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(i=1;i<n;i++)
	{
		if(a[i-1]>=a[i])
			f[i]=f[i-1]+1;
		ans=max(ans,f[i]);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1024
count_char = list(0 for i in range(26))
while True :
    try :
        str_org = str(input())
        str_org = str_org.lower()
        for i in range(len(str_org)) :
            num_org = ord(str_org[i])
            if num_org > 96 and num_org < 123 :
                count_char[num_org - 97] += 1
    except EOFError :
        break
    
for i in range(97, 123) :
    print(chr(i), ":", count_char[i-97])


Measured memory_bytes: 5564
import Data.List
main = do
 [a,b] <- map read . words <$> getLine :: IO [Double]
 print $ floor . (\x -> if (null x) then -1.0 else minimum x) $ filter (\x -> ((x >= a * 12.5) && (x < (a + 1) * 12.5))) [1..1250] `intersect` filter (\x -> ((x >= b * 10.0) && (x < (b+1) * 10.0))) [1..1250]

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

using namespace std;

struct node
{
    int x;
    int y;
}ma[90005];

int main()
{
    int n,m,d;
    int ans[90005];
    cin >> n >> m >> d;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
        {
            int a;
            scanf("%d",&a);
            ma[a].x=i;
            ma[a].y=j;
        }
    for(int i=1;i<=n*m;i++)
    {
        if(i<=d) ans[i]=0;
        else
        {
            ans[i]=ans[i-d]+abs(ma[i].x-ma[i-d].x)+abs(ma[i].y-ma[i-d].y);
        }
    }
    int q,l,r;
    cin >> q;
    while(q--)
    {
        scanf("%d %d",&l,&r);
        printf("%d\n",ans[r]-ans[l]);
    }
    return 0;
}


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

int n, a[21];

int src(int i, int m){
	
	if (m == 0) return 1;
	if (m <= 0) return 0;
	if (i >= n) return 0;

	int act = src(i + 1, m) || src(i + 1, m - a[i]);
	return act;
}

int main(void){

	int q, m;

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

		cin >> m;
		if (src(0, m)) cout << "yes" << endl;
		else cout << "no" << endl;
	}
}

Measured memory_bytes: 1156
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
const ll inf=1e9+7;
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }
ll lcm(ll a, ll b) { return a / (gcd(a, b)) * b; }

int n;
int main(){
    cin>>n;
    Q st(n);
    rep(i,0,n){
      int x,l;
      cin>>x>>l;
      st[i].first=x+l;
      st[i].second=x-l;
    }

    sort(st.begin(),st.end());

    int cnt=0,pos=st[0].second;
    rep(i,0,n){
      if(pos<=st[i].second){
        cnt++;
        pos=st[i].first;
      }
    }

    cout<<cnt<<endl;

    /*rep(i,0,n){
      cout<<st[i].first<<' '<<st[i].second<<endl;
    }*/

}

Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while( x->left != NIL ) x = x->left;

  return x;
}

Node treeMaximum(Node x){
  while( x->right != NIL ) x = x->right;

  return x;
}

Node treeSearch(Node u, int k){
  while( u != NIL && k != u->key ){
    if( k < u->key ) u = u->left;
    else u = u->right;
  }

  return u;
}

Node treeSuccessor(Node x){
  if( x->right != NIL ) return treeMinimum(x->right);

  Node y = x->parent;

  while( y != NIL && x == y->right ){
    x = y;
    y = y->parent;
  }

  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if( z->left == NIL || z->right == NIL ) y = z;
  else y = treeSuccessor(z);

  if( y->left != NIL ) x = y->left;
  else x = y->right;

  if( x != NIL ) x->parent = y->parent;

  if( y->parent == NIL ) root = x;
  else if( y == y->parent->left ) y ->parent->left = x;
  else y->parent->right = x;

  if( y != x ) z->key = y->key;

  free(y);
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while( x != NIL ){
    y = x;
    if( z->key < x->key ){
      x = x->left;
    }
    else x= x->right;
  }

  z->parent = y;

  if( y == NIL ) root = z;
  else if ( z->key < y->key ) y->left = z;
  else y->right = z;
}

void inorder(Node u){

  if( u == NIL ) return;

  inorder(u->left);

  printf(" %d", u->key);

  inorder(u->right);

}

void preorder(Node u){

  if( u == NIL ) return;

  printf(" %d", u->key);

  preorder(u->left);
  preorder(u->right);

}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 24040
#include <iostream>
using namespace std;
int main()
{
  int a,b;
  cin >> a >> b;
  if(a==1)
    a=99;
  if(b==1)
    b=99;
  
  if(a<b)
    cout << "Bob" << endl;
  else if(b<a)
    cout << "Alice" << endl;
  else
    cout << "Draw" << endl;
  
  return 0;
}

Measured memory_bytes: 256
using System;

namespace AtCoder.Abc
{
    class QuestionC
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var n = int.Parse(Console.ReadLine());

            int cnt = 0;
            for (int a = 1; a < n; a++)
            {
                for (int b = 1; b <= (n/a); b++)
                {
                    if (n-(a*b)>0)
                    {
                        cnt++;
                    }
                }
            }
            Console.WriteLine(cnt);

            Console.Out.Flush();
        }
    }
}


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

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
using ll  = long long;
using vi  = vector<int>;
using pii = pair<int,int>;
constexpr int mod = 1e9+7;

vector<pii> pf(int n){
  vector<pii> res;
  int i = -1;
  FOR(j,2,sqrt(n)+1){
    if(n == 1) break;
    if(n%j == 0){
      res.push_back(pii(j,0));
      i++;
    }
    while(n%j == 0){
      res[i].second++;
      n /= j;
    }
  }
  if(n != 1) res.push_back(pii(n,1));
  return res;
}

class ModuloCombination{
public:
  vector<ll> fact, fact_inv;

  static ll mod_pow(ll a, ll n){
    if(n == 0) return 1;
    if(n % 2 == 0) return mod_pow((a * a) % mod, n/2);
    return (a * mod_pow(a, n-1) % mod);
  }

  ModuloCombination(ll N):fact(N+1), fact_inv(N+1){ // N log modで初期化
    fact[0] = 1;
    FOR(i, 1, N+1) fact[i] = (i * fact[i-1]) % mod;
    // FOR(i, 0, N+1) fact_inv[i] = mod_pow(fact[i], mod-2);
    fact_inv[N] = mod_pow(fact[N],mod-2);
    ROF(i, N, 0) fact_inv[i] = fact_inv[i+1] * (i+1) % mod;
  }

  ll op(ll n, ll r){ // nCr
    if(r < 0 or n < r) return 0;
    return fact[n] * fact_inv[r] % mod * fact_inv[n-r] % mod;
  }
};

main(){
  int n,m; cin >> n >> m;
  auto fact = pf(m);

  ModuloCombination C(n+30);
  int res = 1;
  for(auto x : fact){
    int tmp = C.op(n+x.second-1,x.second);
    tmp %= mod;
    res *= tmp;
    res %= mod;
  }
  cout << res << endl;
}

Measured memory_bytes: 1792
import Control.Monad
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = do
  [n, m] <- readInts
  ass <- sortOn last <$> replicateM m readInts
  print $ solve 0 0 ass

readInts :: IO [Int]
readInts = map (maybe (error "parse error") fst . B.readInt) . B.words <$> B.getLine

solve :: Int -> Int -> [[Int]] -> Int
solve n _ [] = n
solve n p ([a, b]:ass)
  | a >= p
    = solve (n + 1) b ass
  | a < p
    = solve n p ass


Measured memory_bytes: 57724
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int inf = 100100100;

ll gcd(ll x, ll y){
  if(x < y) swap(x,y);
  if(y == 0) return x;
  return gcd(y,x%y);
}
ll lcm(ll a, ll b){
  ll g = gcd(a,b);
  return a/g*b;
}




int main(){
  int n;
  cin >> n;
  vector<ll> t(n);
  rep(i,n) cin >> t[i];

  ll ans = t[0];
  rep(i,n){
    ans = lcm(ans,t[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
//#include "testlib.h"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define int long long
#define ll long long
#define M 1000000007
#define MM 998244353
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define mii  map<ll ,ll >
#define msi  map<string,ll >
#define rep(a,b)    for(ll i=a;i<b;i++)
#define rep0(n)    for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define ppb pop_back
#define endl '\n'
#define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define r0 return 0;
#define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
#define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define Set(a, s) (a, s, sizeof (a))
#define FOR repi
#define vii vector<pii>
#define pii pair<int,int>
#define REVERSE(v) reverse(all(v))
#define trav(a, x) for(auto& a : x)
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
#define debug cerr<<"bhau"<<endl
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
template<typename T, typename U> static inline void amin(T &x, U y) 
{ 
    if (y < x) 
        x = y; 
}
template<typename T, typename U> static inline void amax(T &x, U y) 
{ 
    if (x < y) 
        x = y; 
}
 
ll max(ll a, ll b) { return (a > b)? a : b;}
int min(int a, int b) { return (a < b)? a : b;} 
const int N=1e5+10;
vi adj[N];
bool vis[N];
int dist[N];

int solve(){
    int n,m;cin>>n>>m;
    rep0(m){
        int x,y;cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }

    queue<pii> q;
    q.push({1,0});
    vis[1]=1;
    int ans=1e18;
    int par[n+1];
    while(!q.empty()){
        auto f=q.front();
        q.pop();
        dist[f.ff]=f.ss;
        for(auto i:adj[f.ff]){
            if(vis[i]){
              continue;
            }
            else{
                par[i]=f.ff;
                vis[i]=1;
                q.push({i,f.ss+1});
            }
        }
    }
    bool z=1;
    rep(1,n+1) if(!vis[i]) z=0;
    if(z){
        cout<<"Yes\n";
        for(int i=2;i<=n;i++) cout<<par[i]<<endl;
    }
else cout<<"No";



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


Measured memory_bytes: 14588
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
void times(alias fun)(int n) {
    foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(int n) {
    T[] res = new T[n];
    foreach(ref e; res) e = fun();
    return res;
}
// fold was added in D 2.071.0.
template fold(fun...) if (fun.length >= 1) {
    auto fold(R, S...)(R r, S seed) {
        static if (S.length < 2) {
            return reduce!fun(seed, r);
        } else {
            return reduce!fun(tuple(seed), r);
        }
    }
}

void main() {
    long N, K;
    readf("%d %d\n", &N, &K);
    writeln(K*(K-1)^^(N-1));
}


Measured memory_bytes: 256
import java.io.*;
import java.util.Arrays;
class Main{
	public static void main(String[] args) throws IOException {
		int i,j;
		int[] n = new int[10];
		String[] str = new String[10];
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		str = in.readLine().split(" ");
		for(i=0;i<5;i++)
			n[i] = Integer.parseInt(str[i]);
		System.out.println(n[2]<0 || n[3]<0 || n[2]+n[4]>n[0] || n[3]+n[4]>n[1]
			? "No" : "Yes");
	}
}

Measured memory_bytes: 24284
#include <stdio.h>

#define MAX 1000000

int cnt=0, count = 0, n;
int A[MAX], G[MAX];

void shellSort(int*, int);
void insertionSort(int*, int, int);

int main()
{
  int i, len;
  
  scanf("%d", &n);

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

  shellSort(A, n);

  printf("%d\n", count);

  for( i = count-1 ; i >= 0 ; i-- ){
    printf("%d", G[i]);
    if( i ) printf(" ");
  }
  printf("\n");
  printf("%d\n", cnt);
  for( i = 0 ; i < n ; i++ ) printf("%d\n", A[i]);

  return 0;
}

void shellSort(int A[], int n)
{
  int i, k;
  
  for( k = 1 ; ; ){
    if( k > n ) break;
    G[count] = k;
    k = 3 * k + 1;
    count++;
  }
  
  for( i = count ; i >= 0 ; i-- ) insertionSort(A, n, G[i]);
}

void insertionSort(int A[], int n, int g)
{
  int i, j, v;

  for( i = g ; i < n ; i++ ){
    v = A[i];
    j = i - g;
    while( j >= 0 && A[j] > v ){
      A[j + g] = A[j];
      j -= g;
      cnt++;
    }
    A[j + g] = v;
  }
}

Measured memory_bytes: 6372
//hi
#include<bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long int LL;
int main(void){
    char s[11],s2[30];
    scanf("%s",s);
    int n=strlen(s);
    int i,j;
	int k=n-1;
	LL ans=0;
    for(i=0;i<(1<<k);i++){
		int x=0;
		for(j=0;j<n;j++){
			s2[x++]=s[j];
			if(j!=n-1 && (i&(1<<j)))
				s2[x++]='+';
		}
		//printf("%d\n",x);
		LL cnt=0;
		//for(j=0;j<x;j++) printf("%c",s2[j]);
		//printf("\n");
		for(j=0;j<x;j++){
			if(s2[j]>='0' && s2[j]<='9') cnt=cnt*10+(int)(s2[j]-'0');
			else{
				ans+=cnt;
				cnt=0;
			}
		}
		ans+=cnt;
	}
	printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int top,S[1000];

void push(int x){
  S[++top] = x;
}
int pop(){
  top--;
  return S[top+1];
}
int main(){
  int a,b;
  top = 0;
  char s[100];
  while( scanf("%s",s) != EOF ){
    if( s[0] == '+'){
      a = pop();
      b = pop();
      push(a + b);
    }else if(s[0] == '-' ){
      b = pop();
      a = pop();
      push(a - b);
    }else if(s[0] == '*' ){
      a = pop();
      b = pop();
      push(a * b);
    }else{
      push(atoi(s));
    }
  }

  printf("%d\n",pop());
  return 0;
}



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

#define MAX 200000

template<typename T> T combination(int n, int r) {
	T ans = 1;
	for (int i = 0; i < r; i++) {
		ans *= n - i;
	}
	for (int i = 1; i <= r; i++) {
		ans /= i;
	}
	return ans;
}

int main() {
	int N, A[MAX];
	map<int, int> K;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		K[A[i]]++;
	}
	long long cmb = 0;
	for (map<int, int>::iterator it = K.begin(); it != K.end(); it++) {
		cmb += combination<long long>((*it).second, 2);
	}
	for (int i = 0; i < N; i++) {
		long long ans = cmb;
		ans -= (K[A[i]] - 1);
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 8320
#!/usr/bin/env python3

import enum


EPS = 1e-10


class PointsRelation(enum.Enum):
    counter_clockwise = 1
    clockwise = 2
    online_back = 3
    on_segment = 4
    online_front = 5


def inner_product(v1, v2):
    return v1.real * v2.real + v1.imag * v2.imag


def outer_product(v1, v2):
    return v1.real * v2.imag - v1.imag * v2.real


def judge_relation(p0, p1, p2):
    v1 = p1 - p0
    v2 = p2 - p0
    op = outer_product(v1, v2)
    if op > EPS:
        return PointsRelation.counter_clockwise
    elif op < -EPS:
        return PointsRelation.clockwise
    elif inner_product(v1, v2) < -EPS:
        return PointsRelation.online_back
    elif abs(v1) < abs(v2):
        return PointsRelation.online_front
    else:
        return PointsRelation.on_segment


def main():
    x_p0, y_p0, x_p1, y_p1 = map(float, input().split())
    p0 = complex(x_p0, y_p0)
    p1 = complex(x_p1, y_p1)
    q = int(input())
    for _ in range(q):
        p2 = complex(*map(float, input().split()))
        ans = judge_relation(p0, p1, p2)
        if ans == PointsRelation.counter_clockwise:
            print("COUNTER_CLOCKWISE")
        elif ans == PointsRelation.clockwise:
            print("CLOCKWISE")
        elif ans == PointsRelation.online_back:
            print("ONLINE_BACK")
        elif ans == PointsRelation.online_front:
            print("ONLINE_FRONT")
        else:
            print("ON_SEGMENT")


if __name__ == '__main__':
    main()

Measured memory_bytes: 8224
#include <bits/stdc++.h>
#define int long long
#define P(x) cout << x << endl
#define D(x) P(#x << ": " << x)
#define F(i,n) for (int i=0; i<(int)(n); i++)
#define DEC(i,n) for (int i=(int)(n); --i>=0;)
#define S(s) (int)((s).size())
#define ALL(v) v.begin(), v.end()
#define MI(a,v) a = min(a,(v))
#define MA(a,v) a = max(a,(v))
#define V vector
#define pb push_back
#define mt make_tuple
using namespace std;

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

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k; cin>>n>>k;
    int a[n];
    F(i,n) cin>>a[i];
    int g=0, ma=0;
    F(i,n) {
        g = gcd(g, a[i]);
        MA(ma, a[i]);
    }
    if (!(k % g == 0 && k <= ma))
        cout<<"IM";
    cout<<"POSSIBLE\n";
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(){
	int n;
	int a[200000],max,min;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(i==1)max=a[1]-a[0];
		if(i>0){
			int tem=a[i]-min;
			if(tem>max)max=tem;
			if(min>a[i])min=a[i]; 
		}
		else {
			min=a[0];
		}
	}
	printf("%d\n",max);
	return 0;
}


Measured memory_bytes: 2640
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();

		if (N % 500 <= A) {
			System.out.print("Yes");
		} else {
			System.out.println("No");
	    }
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define acc(v) accumulate(v.begin(), v.end(), 0)

using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;

int n,m,q;
vector<int> a, b, c, d;
int ans = 0;
void dfs(vector<int> A)
{
	if(A.size() == n+1){
		int tmp = 0;
		rep(i, q)
		{
			if(A[b[i]] - A[a[i]] == c[i])
				tmp += d[i];
		}
		ans = max(ans, tmp);
		return;
	}
	A.push_back(A.back());
	while (A.back() <= m)
	{
		dfs(A);
		A.back()++;
	}
}

int main()
{
	cin >> n >> m >> q;
	a = b = c = d = vector<int>(q);
	rep(i,q){
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	}
	dfs(vector<int>(1,1));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3608
while 1:
    H = int(raw_input())
    if H == 0: break
    A = [map(int,raw_input().split())+[0] for _ in range(H)]
    ans = 0
    while 1:
        vanish = False
        for h in range(H):
            l = r = 0
            while r < 6:
                if A[h][r] != A[h][l]:
                    if r-l >= 3:
                        if A[h][l] == 0:break
                        ans += A[h][l]*(r-l)
                        A[h][l:r] = [0]*(r-l)
                        vanish = True
                    l = r
                r += 1
        if not vanish: break
        for h in range(H)[::-1]:
            for w in range(5):
                if A[h][w] == 0:
                    for hh in range(h)[::-1]:
                        if A[hh][w] != 0:
                            A[h][w] = A[hh][w]
                            A[hh][w] = 0
                            break
    print ans

Measured memory_bytes: 4268
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll n,k;
    cin>>n>>k;
    long double a[n];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
    }
    long double ans=0,temp=0;
    for(int i=0;i<k;i++)
    {
        ans+=(a[i]/2)+0.5;
    }
    temp=ans;
    for(int i=k;i<n;i++)
    {
        temp-=(a[i-k]/2)+0.5;
        temp+=(a[i]/2)+0.5;
        ans=max(temp,ans);
    }
    cout<<fixed<<setprecision(12);
    cout<<ans;
	return 0;
}







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

int main()
{
  int x, y;

  cin >> x >> y;

  for (int i = 0; i <= x; i++)
  {
    if (((2 * i + 4 * (x - i)) == y) || ((4 * i + 2 * (x - i)) == y))
    {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,r1=0,r2=0,r3=0;
    string s,q,y;
    cin>>s;
    q=s;
    reverse(s.begin(),s.end());
    if(q==s)r1=1;
    string x="";
    for(i=0; i<(q.size()-1)/2; i++)
    {
        x=x+q[i];
    }
    y=x;
    reverse(x.begin(),x.end());
    if(y==x)r2=1;
    string b="";
    for(i=((q.size()+3)/2)-1; i<q.size(); i++)
    {
        b=b+q[i];
    }
    string c=b;
    reverse(b.begin(),b.end());
    if(c==b)r3=1;
    if(r1==1&&r2==1&&r3==1)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int sum = sc.nextInt();
    int g = sc.nextInt();
    int[] donutsG = new int[sum]; 
    
    int canMake = 0; 
    for(int i = 0; i< sum ; i++){
      donutsG[i] = sc.nextInt();
      if(donutsG[i]<=g){
      	g = g-donutsG[i];
        ++canMake;
        }
    }
    Arrays.sort(donutsG);
    
    while(g >= donutsG[0]){
      ++canMake;
      g= g-donutsG[0];
    }
    System.out.println(canMake);
  }
}

Measured memory_bytes: 23252
def main():
    n, k = map(int, input().split())
    h = [int(i) for i in input().split()]
    ans = solve(n, k, h)
    print(ans)


def solve(n, k, h):
    dp = [10 ** 9 for _ in range(n)]
    dp[0] = 0
    for i in range(1, n):
        for j in range(1, k + 1):
            if i - j < 0:
                break
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))
    return dp[n - 1]


if __name__ == '__main__':
    main()

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

using namespace std;


#ifdef zxc

#include <sys/resource.h>
#include "debug.h"

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ll = int64_t;
using ld = long double;
const ld EPS = 1e-9;
//const ll MOD = 924844033;
const ld PI = 3.141592653589793;
const int maxn = 300001;
const ll MOD = 1e9 + 7;

void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

ll pw(ll a, ll b) {
    ll res = 1;
    for (; b; b >>= 1) {
        if (b & 1) {
            res = res * a % MOD;
        }
        a = a * a % MOD;
    }
    return res;
}

template<typename Cont>
vector<vector<int>> accum2d(Cont a, int n, int m) {
    vector<vector<int>> res(n, vector<int>(m));

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            res[i][j] = a[i][j];
            if (i > 0) {
                res[i][j] += res[i - 1][j];
            }
            if (j > 0) {
                res[i][j] += res[i][j - 1];
            }
            if (i > 0 && j > 0) {
                res[i][j] -= res[i - 1][j - 1];
            }
        }
    }
    return res;
}

vector<vector<int>> resize2d(vector<vector<int>> a, int n, int m) {
    a.resize(n);
    for (auto &x:a) {
        x.resize(m);
    }
    return a;
}

int up[1030][1030];
int down[1030][1030];
int lft[1030][1030];
int rght[1030][1030];
int ans[1030][1030];
int pref[1030][1030];
int arifm[1030][1030];
int dp1[1030][1030];
int dp2[1030][1030];

signed main() {
#ifdef zxc
    struct rlimit rl;
    const rlim_t kStackSize = 512L * 1024L * 1024L;
    assert(!getrlimit(RLIMIT_STACK, &rl));
    rl.rlim_cur = kStackSize;
    assert(!setrlimit(RLIMIT_STACK, &rl));
    freopen("../kolya_input.txt", "r", stdin);
//    freopen("../kolya_output.txt", "w", stdout);
#else
    //    mt19937 mt(std::chrono::high_resolution_clock::now().time_since_epoch().count());
    //            freopen("", "r", stdin);
    //        freopen("hack.out", "w", stdout);
#endif
    auto solve = [](int _) {
        int n;
        cin >> n;
        ll k;
        cin >> k;
        vector<int> a(n);
        for (int &el:a) {
            cin >> el;
        }
        ll ans = 0;

        for (int i = 0; i < n; ++i) {
            int pref = 0;
            int val = 0;
            for (int j = 0; j < n; ++j) {
                if (a[i] < a[j]) {
                    ++val;
                    if (j < i) {
                        ++pref;
                    }
                }
            }
            ans += 1ll * k * (k - 1) / 2 % MOD * val % MOD + pref * k;
            ans %= MOD;
        }
        cout<<ans;
    };


    fast_io();
    cout.precision(9);
    cout << fixed;
    auto start = chrono::steady_clock::now();
    for (int i = 1; i <= 1; ++i)solve(i);
    auto end = chrono::steady_clock::now();

    debug("time", chrono::duration_cast<chrono::milliseconds>(end - start).count() / 1000.0);

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp> 
using namespace std;

vector<string> inputVS(void);

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

    long long N, A, B;
    cin >> N >> A >> B;

    long long n = N / (A + B); 
    long long remain = N % (A + B);
    long long co = n * A;
    if (remain < A){
        co += remain;
    }
    else {
        co += A;
    }

    cout << co << "\n";

    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;
const int INF = 1e9 + 1;

int main(){

	int N, T;
	cin >> N >> T;

	vector<int>t(N);
	rep(i, N)
		cin >> t[i];

	int ans = 0;
	rep(i, N-1) 
		ans += min(t[i + 1] - t[i], T);

	ans += T;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  int a = 0;
  
  if(s[0] == '1')
    a++;
  if(s[1] == '1')
    a++;
  if(s[2] == '1')
    a++;
  
  cout << a << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int long long
#define pb push_back 
#define ins insert
#define rs resize
#define br break;
#define cont continue;
#define vi vector<ll>
#define vll vector<long long>
#define si set<ll>
#define sll set<long long>
#define pii pair<ll,ll>
#define pll pair<long long, long long>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vec vector
#define cend cout<<endl;
#define sc second
#define fr first
#define retz return 0;
#define ll_MAX (ll)(1e9*1e9)
#define ll_MIN (ll)(-1e9*1e9)
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b)  for(int i=a; i<=b; i++)
#define repd(i,a,b) for(int i=a; i>=b; i--)
#define ps(arr, n) for(int i=1; i<n; i++)arr[i]+=arr[i-1];
#define inp(arr, n)for(int i=0; i<n; i++)cin>>arr[i];
#define out(arr, n)for(int i=0; i<n; i++)cout<<arr[i];
#define inp1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define out1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define loop(q) for(auto it:q)
#define loop1(q) for(auto&it:q)
#define db1 cout << "*" << endl
#define db2 cout << "YES" << endl
using namespace std;
using namespace __gnu_pbds; 
#define oset(X) tree<X,null_type,less<X>, rb_tree_tag, tree_order_statistics_node_update> 
#define roset(X) tree<X,null_type,greater<X>, rb_tree_tag, tree_order_statistics_node_update>  
#define okey order_of_key //lower_bound_set
#define ofind find_by_order
#define cyes cout << "Yes" << endl;
#define cno cout << "No" << endl;
#define mod 1000000007
#define mod2 998244353
#define INT_MAX1 900000000
//////////////////////////////////////////////////////////////////////////////////////////////

int n, w;
int dp[100001][101];
bool v[100001][101];
int w1[100001], v1[100001];

int s1(int r, int i)
{
    if(r<=0)
        return 0;
    if(i==n)
        return INT_MAX;
    if(v[r][i])
        return dp[r][i];
    v[r][i] = 1;
    return dp[r][i] = min(s1(r,i+1),w1[i]+s1(r-v1[i],i+1)); 
}

void solve()
{
    cin >> n>>w;
    rep(i,0,n-1)
        cin >> w1[i] >> v1[i];
    for(int i=100000; i>=0; i--)
    {
        if(s1(i,0) <= w)
        {
            cout << i << endl;
            return;
        }
    }
}
 
int32_t main()
{
    speed;
    int t = 1;
    //cin >> t;
    while(t--)
        solve();
}

Measured memory_bytes: 89088
#pragma comment(linker, "/stack:200000000")
                #pragma GCC optimize ("Ofast")
                #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
                #include <iostream>
                #include <iomanip>
                #include <sstream>
                #include <cstring>
                #include <vector>
                #include <deque>
                #include <queue>
                #include <set>
                #include <map>
                #include <valarray>
                #include <iterator>
                #include <functional>
                #include <limits>
                #include <algorithm>
                #include <numeric>
                #include <cmath>
                #include <cassert>
                #include <unordered_map>
                #include <unordered_set>
                #include <stack>
                using namespace std;
                #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
                 #define trace(x) cerr << #x << ": " << x << " " << endl;
             
                typedef int64_t ll;
             
                #define endl '\n'
                #define int ll
                ll mod=1e9+7;
                ll mod1=1e9+5;
                
                ll power(ll a,ll b)
                {
                    if(b==0) return 1;
                    else if(b%2==0)
                        return power((((a%mod)*(a%mod))%mod),b/2)%mod;
                    else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
                }
                bool check(string s,string s1)
                {
                    int j=0;
                    for(int i=0;i<s.length();++i)
                    {
                        if(j==3)
                            break;
                        if(s[i]==s1[j])
                        {
                            j++;
                        }
                    }
                    if(j==3)
                        return 1;
                    return 0;

                }
             int32_t main()
                {
                IOS
              
                int a;
                cin>>a;
                for(int i=1;i<=50000;++i)
                {
                    double x=(double)i*1.08;
                    int y=x;
                    if(y==a)
                    {
                        cout<<i;
                        return 0;
                    }
                }
                cout<<":(";

                
            }

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

int main(void){
	int N, money = 1000;
	cin >> N;
	for(int i = 1; i <= 10; i++){
		if(money >= N){
			cout << money - N << endl;
			break;
		}
		money += 1000;
	}
	return 0;
}


Measured memory_bytes: 3632
// #include <bits/stdc++.h>
#include <iostream>
// #include <cmath>
// #include <iomanip>
#include <string>
using namespace std;
 
int main() {
    int h, w;
    while (true) {
        cin >> h >> w;
        if ( h== 0 && w == 0) {
            break;
        }
        for (int i=0;i<h;i++) {
            for (int j=0;j<w;j++) {
                if ( (i+j) % 2 == 0) {
                    cout << '#';
                } else {
                    cout << '.';
                }
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}



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

using namespace std;

namespace {

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }
    
    typedef double real;
    typedef long long ll;

    const real EPS = 1e-12;

    struct Point {
        real x, y, z;
        Point() {}
        Point(real x, real y, real z) : x(x), y(y), z(z) {}
        Point operator-() const { return Point(-x, -y, -z); }
        Point operator+(const Point& p) const { return Point(x + p.x, y + p.y, z + p.z); }
        Point operator-(const Point& p) const { return (*this) + (-p); }
        Point operator*(real k) const { return Point(x * k, y * k, z * k); }
        Point operator/(real k) const { return (*this) * (1.0 / k); }
    };
    real dot(const Point& a, const Point& b) { return a.x * b.x + a.y * b.y + a.z * b.z; }
    real norm(const Point& a) { return sqrt(dot(a, a)); }
    istream& operator>>(istream& is, Point& p) { return is >> p.x >> p.y >> p.z; }

    struct Line {
        Point a, b;
        Line() {}
        Line(Point a, Point b) : a(a), b(b) {}
    };

    Point projection(const Line& l, const Point& p) {
        Point u = (p - l.a), v = (l.b - l.a);
        return l.a + (v / norm(v)) * (dot(u, v) / norm(v));
    }

    real distance(const Line& l, const Point& p) {
        Point q = projection(l, p);
        return norm(p - q);
    }

    bool intersect(real r, const Line& l, const Point& p) {
        r += EPS;
        if (distance(l, p) > r) return false;
        Point u = p - l.a, v = l.b - l.a;
        real theta = dot(u, v) / (norm(u) * norm(v));
        if (theta < 0) return false;
        u = p - l.b, v = l.a - l.b;
        theta = dot(u, v) / (norm(u) * norm(v));
        if (theta < 0) return false;
        return true;
    }

    int N, Q;
    vector<Point> P;
    vector<real> R;
    vector<ll> L;
    void solve() {
        cin >> N >> Q;
        P.clear(); P.resize(N);
        R.clear(); R.resize(N);
        L.clear(); L.resize(N);
        for (int i = 0; i < N; i++) {
            cin >> P[i] >> R[i] >> L[i];
        }
        for (int q = 0; q < Q; q++) {
            Point s, t;
            cin >> s >> t;
            Line l(s, t);
            ll ans = 0;
            for (int i = 0; i < N; i++) {
                if (intersect(R[i], l, P[i])) {
                    ans += L[i];
                }
            }
            cout << ans << endl;
        }
    }
}

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

Measured memory_bytes: 1236
import java.util.*;

class Main{

    Main(){
        Scanner SC = new Scanner(System.in);
        int N = Integer.parseInt(SC.next());
        int[] A = new int[N];
        for(int i=0;i<N;i++){
            A[i] = Integer.parseInt(SC.next());
        }

        int val = 1;
        for(int i=0;i<N;i++){
            if(A[i] == val) val++;
        }

        if(val == 1){
            System.out.println(-1);
        } else {
            System.out.println(N-val+1);
        }

    }

    public static void main(String[] args){
        Main main = new Main();
    }
}


Measured memory_bytes: 50724
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,z,w = LI()
a = LI()
if n == 1:
    ans = abs(a[0]-w)
else:
    ans = max(abs(a[-2] - a[-1]),abs(a[-1] - w))
print(ans)

Measured memory_bytes: 38768
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
char map[55][55];
int h, w;
int dir[8][2] =
{
    1, 0,
    0, 1,
    -1, 0,
    0, -1,
    1, 1,
    -1, -1,
    1, -1,
    -1, 1,
};
int main()
{
    while(~scanf("%d%d", &h, &w))
    {
        memset(map, 0, sizeof(map));
        getchar();
        for(int i = 0; i < h; ++i)
            scanf("%s", map[i]);
     
        for(int i = 0; i < h; ++i)
        {
            for(int j = 0; j < w; ++j)
            {
                if(map[i][j] == '#')
                    continue;
                int num = 0;
                for(int k = 0; k < 8; ++k)
                {
                    int x = i + dir[k][0];
                    int y = j + dir[k][1];
                    if(x < 0 || x >= h || y < 0 || y >= w)
                        continue;
                    if(map[x][y] == '#')
                        num++;
                }
                map[i][j] = (char)(num + '0');
            }
        }
        for(int i = 0; i < h; ++i)
        {
            for(int j = 0; j < w; ++j)
            {
                printf("%c", map[i][j]);
            }
            printf("\n");
        }
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int a, b, c;
    int i, check = 0;

    scanf("%d %d %d", &a, &b, &c);

    for(i=1; i<=100; i++){
        if(c == a * i % b)
            check++;
    }

    if(check != 0)
        printf("YES\n");
    else
        printf("NO\n");
    
    return 0;
}

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

using namespace std;

const int INF = 1e9 + 3;
const int N = 2e5 + 3;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;

const double PI = acos(-1);



void solve() {
    string s, t;
    cin >> s >> t;
    int ans = INF;
    for (int i = 0; i < s.size() - t.size() + 1; i++) {
        int sum = 0;
        for (int j = 0; j < t.size(); j++)
            sum += s[i + j] != t[j];
        ans = min(ans, sum);
    }
    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int t;
    t = 1;
    while (t--) {
        solve();
    }
}

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

int main(void){
    int a, b;
    cin>>a>>b;
    int ans=-1;
   
    if(0<a&&a<10&&0<b&&b<10){
        ans=a*b;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2**31-1)
input = sys.stdin.readline
write = sys.stdout.write
LMIIS = lambda : list(map(int,input().split()))
II = lambda : int(input())
dbg = lambda *something : print(*something) if DEBUG is True else 0
DEBUG = True



MOD = 10**9 + 7
def main():
    S = input()
    N = len(S)-1
    dp = [0] * 13
    

    if S[0] == '?':
        R = range(10)
    else:
        R = [int(S[0])]

    for i in R:
        dp[i] = 1

    for i in range(1,N):
        if S[i] == '?':
            R = range(10)
        else:
            R = [int(S[i])]


        dppre = dp
        dp = [0] * 13
        for j in range(13):
            for k in R:
                dp[(j * 10 + k) % 13 ] += dppre[j]
        for j in range(13):
            dp[j] %= MOD
    
    print(dp[5])


if __name__ == '__main__':
    main()

Measured memory_bytes: 43244
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1e18;
const ll mod = 1e9+7;
struct edge {
  int to, a;
  ll b;
};
struct state {
  int node, s;
  ll dist;
  bool operator<(const state& R) const {
    return dist > R.dist;
  }
};
int main() {
  int N, M, S;
  cin >> N >> M >> S;
  vector<vector<edge>> G(N);
  rep(i, M) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    --u, --v;
    G[u].push_back({v, a, b});
    G[v].push_back({u, a, b});
  }
  vector<int> C(N), D(N);
  rep(i, N) cin >> C[i] >> D[i];
  int mx = 5001;
  priority_queue<state> Q;
  vector<vector<ll>> dp(N+1, vector<ll>(mx+1, longinf));
  S = min(S, mx);
  dp[0][S] = 0;
  Q.push({0, S, 0});
  while(!Q.empty()) {
    int cur, s;
    ll d;
    cur = Q.top().node;
    s   = Q.top().s;
    d   = Q.top().dist;
    Q.pop();
    if(dp[cur][s] < d) continue;
    int ns = min(mx, s+C[cur]);
    ll nd = d+D[cur];
    if(dp[cur][ns]>nd) {
      dp[cur][ns] = nd;
      Q.push({cur, ns, nd});
    }
    for(auto& e: G[cur]) {
      if(s<e.a) continue;
      int ne = e.to;
      int ns = s-e.a;
      ll nd = d+e.b;
      if(dp[ne][ns]>nd) {
	dp[ne][ns] = nd;
	Q.push({ne, ns, nd});
      }
    }
  }
  rep(i, N) if(i) cout << *min_element(dp[i].begin(), dp[i].end()) << endl;
  return 0;
}


Measured memory_bytes: 9396
#include<bits/stdc++.h>
using namespace std;
int MX=100001;
int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    int n,wt;
    cin>>n>>wt;
    pair<long long,long long> a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i].first>>a[i].second;
    }
    long long dp[n+1][MX];
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<MX;j++)
        {
            if(j==0)
                dp[i][j]=0;
            else
                dp[i][j]=INT_MAX;
        }
    }
    long long max_val=0;
    long long w,v;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<MX;j++)
        {
            w=a[i-1].first;
            v=a[i-1].second;
            if(j>=v)
            {
                dp[i][j]=min(dp[i-1][j],dp[i-1][j-v]+w);
            }
            else
                dp[i][j]=dp[i-1][j];
            if(dp[i][j]<=wt && j>max_val)
                max_val=j;
        }
    }
    cout<<max_val;
    return 0;
}

/*
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
*/


Measured memory_bytes: 79232