akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
  int rank[10000];
  
  char ch;
  int a, b;
  int cnt = 0;
  while(cin>>a>>ch>>b, a+b) {
    rank[a] = b;
    cnt ++;
  }
  
  int q;
  while(cin>>q) {
    int c = 1;
    bool dbl[32]; fill(dbl, dbl+31, false);
    for(int i=1; i<=cnt; i++) {
      if(rank[q]<rank[i] && !dbl[rank[i]]) {
	c ++;
	dbl[rank[i]] = true;
      }
    }
    
    cout << c << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1164
# include<iostream>
using namespace std;
char s[51][51];
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
int main(void)
{
    int n, m;
    int i, j;
    cin >> n >> m;
    for(i = 0; i < n; ++i)
        cin >> s[i];
    for(i = 0; i < n; ++i)
        for(j = 0; j < m; ++j)
        {
            int k;
            int v = 0;
            if(s[i][j] == '.')
                continue;
            for(k = 0; k < 4; ++k)
            {
                if(i+dx[k] < n && i+dx[k] >= 0 && j+dy[k] < m && j+dy[k] >= 0)
                {
                    if(s[i+dx[k]][j+dy[k]] == '#')
                    {
                        v = 1;
                        break;
                    }
                }
            }
            if(v == 0)
            {
               // cout << "i=" << i << ", j=" << j << endl;
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
def b_search (min, max)
  mid = (min + max) / 2
  if mid == min
    if possible?(min)
      return min
    else
      return max
    end
  end
  unless possible?(mid)
    min = mid
  else
    max = mid
  end
  b_search(min, max)
end

def possible?(limit)
  neccesary_training = 0
  N.times do |i|
    tmp_cost = $eat_costs[i] - limit / $food_costs[i]
    neccesary_training += tmp_cost if tmp_cost > 0
    return false if neccesary_training > K
  end
  neccesary_training <= K
end

INF = 10 ** 18
N, K = gets.split.map(&:to_i)
$eat_costs = gets.split.map(&:to_i).sort
$food_costs = gets.split.map(&:to_i).sort { |a, b| b <=> a }

puts b_search(0, INF)


Measured memory_bytes: 32860
#include <cstdio>
#include <algorithm>
#include <utility>
#include <cstdlib>
#include <iostream>
using namespace std;
 
typedef pair<int, int> ii;
int n, m;
const int maxn = 2e5+100;
ii a[maxn];
 
int tree[maxn<<2], lazy[maxn<<2];
inline void pushup(int cur)
{
    tree[cur] = max(tree[cur<<1], tree[cur<<1|1]);
}
inline void push(int cur, int v)
{
    tree[cur] += v;
    lazy[cur] += v;
}
inline void pushdown(int cur)
{
    if (lazy[cur])
    {
        push(cur<<1, lazy[cur]);
        push(cur<<1|1, lazy[cur]);
        lazy[cur] = 0;
    }
}
void build(int cur, int tl, int tr)
{
    lazy[cur] = 0;
    if (tl == tr)
    {
        tree[cur] = -(m-tl+1);
    }
    else
    {
        int tm = (tl+tr)>>1;
        build(cur<<1, tl, tm);
        build(cur<<1|1, tm+1, tr);
        pushup(cur);
    }
}
void update(int cur, int tl, int tr, int ql, int qr, int v)
{
    if (ql > qr)
        return;
    else if (ql <= tl && tr <= qr)
        push(cur, v);
    else
    {
        pushdown(cur);
        int tm = (tl+tr)>>1;
        update(cur<<1, tl, tm, ql, min(tm, qr), v);
        update(cur<<1|1, tm+1, tr, max(tm+1, ql), qr, v);
        pushup(cur);
    }
}
int query(int cur, int tl, int tr, int ql, int qr)
{
    if (ql > qr)
        return -1e9;
    else if (ql <= tl && tr <= qr)
        return tree[cur];
    else
    {
        pushdown(cur);
        int tm = (tl+tr)>>1;
        int ret = query(cur<<1, tl, tm, ql, min(tm, qr));
        ret = max(ret, query(cur<<1|1, tm+1, tr, max(tm+1, ql), qr));
        pushup(cur);
        return ret;
    }
}
int main()
{
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; ++i)
    {
        scanf("%d %d", &a[i].first, &a[i].second);
    }
    sort(a, a+n);
    int ans = max(0, n-m);
    build(1, 0, m+1);
    for (int i = 0; i < n; ++i)
    {
        update(1, 0, m+1, 0, a[i].second, 1);
        int ret;
        ans = max(ans, ret=query(1, 0, m+1, a[i].first+1, m+1)-a[i].first);
 
    }
    printf("%d\n", ans);    
}

Measured memory_bytes: 7936
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void fun(char *,char *);
void fun(char *a,char *b)
{
    int i=0,j=0;
    if(strlen(a)==strlen(b))
    {
        for(i=0,j=0;a[i]!='\0',b[j]!='\0';i++,j++)
        {
            printf("%c",a[i]);
            printf("%c",b[j]);
        }
        printf("\n");
    }
    if(strlen(a)==strlen(b)+1)
    {
        for(i=0,j=0;a[i]!='\0',b[j]!='\0';i++,j++)
        {
            printf("%c",a[i]);
            printf("%c",b[j]);
        }
        printf("%c\n",a[strlen(a)-1]);
    }
}
int main()
{
    char a[101];
    char b[101];
    gets(a);
    gets(b);
    fun(a,b);
    return 0;
}

Measured memory_bytes: 128
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		solve();
	}

	public static void solve() {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
		String s = sc.nextLine();
        String t = sc.nextLine();
        int n = s.length();
        sc.close();
        List<String> anses = new ArrayList<>();
        for(int i = 0; i + t.length() <= n; i++){
            String temp = "";
            for(int j = 0; j < n; j++){
                if(i <= j && j < i + t.length()){
                    if(s.charAt(j) == '?' || s.charAt(j) == t.charAt(j-i)) temp += t.charAt(j-i);
                    else break; 
                }else{
                    if(s.charAt(j) == '?') temp += 'a';
                    else temp += s.charAt(j);
                }
            }
            if(temp.length() == n) anses.add(temp);
        }

        Collections.sort(anses);
        
        if(anses.isEmpty()) out.println("UNRESTORABLE");
        else out.println(anses.get(0));
        out.flush();
	}
}

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

using namespace std;

int main() {
	int x, y;
	cin >> x >> y;
	string ans = "Yes";
	if (x == 2 || y == 2) ans = "No";
	else if (x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12) {
		if (y == 4 || y == 6 || y == 9 || y == 11) ans = "No";
	}
	else if (x == 4 || x == 6 || x == 9 || x == 11) {
		if (y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12) ans = "No";
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3524
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

int p[200001],r[200001],c[200001];
void init(){rep(i,200001)p[i]=i,r[i]=0,c[i]=1;}
int find(int x){return (p[x]==x)?x:(p[x]=find(p[x]));}
void unite(int x,int y) {
  x=find(x),y=find(y);
  if(x==y)return;
  int cx=c[x],cy=c[y];
  if(r[x]<r[y])p[x]=y;
  else{p[y]=x;if(r[x]==r[y])r[x]++;}
  c[find(x)]=cx+cy;
}
bool same(int x,int y){return find(x)==find(y);}

void Main() {
  init();
  ll n,m;
  cin >> n >> m;
  string s[n];
  rep(i,n) R s[i];
  rep(i,n) {
    rep(j,m) {
      rep(k,4) {
        int x=i+dx[k],y=j+dy[k];
        if(check(n,m,x,y)&&s[i][j]!=s[x][y]) unite(i*m+j,x*m+y);
      }
    }
  }
  ll ans=0;
  map<ll,P> ma;
  rep(i,n) {
    rep(j,m) {
      ll k=i*m+j;
      if(s[i][j]=='#') ma[find(k)].F++;
      else ma[find(k)].S++;
    }
  }
  tr(it,ma) {
    ans+=it->S.F*it->S.S;
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

int main(){
  int N;
  cin >> N;
  vector <int> t(N),x(N),y(N);
  for(int i=0;i<N;i++){
    cin >> t.at(i) >> x.at(i) >> y.at(i);
  }
  bool flag=true;
  for(int i=0;i<N;i++){
    if((abs(x.at(i))+abs(y.at(i))>t.at(i))||((x.at(i)+y.at(i))%2!=t.at(i)%2)){
      flag=false;
      break;
    }
  }
  if(flag){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 1408
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
ll INF = 100000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n,h ;
	cin >> h >> n ;
	vll a(n),b(n) ;
	for(int i=0;i<n;i++) cin >> a.at(i) >> b.at(i) ;
	vvll dp(n+1,vll(h+10000,INF)) ;
	dp.at(0).at(0) = 0 ;
	for(int i=1;i<=n;i++){
		for(int j=0;j<dp.at(0).size();j++){
			dp.at(i).at(j) = dp.at(i-1).at(j) ;
			if(j>=a.at(i-1)) dp.at(i).at(j) = min(dp.at(i).at(j),dp.at(i).at(j-a.at(i-1))+b.at(i-1)) ;
		}
	}
	ll ans = INF ;
	for(int j=h;j<dp.at(0).size();j++) ans = min(ans,dp.at(n).at(j)) ;
	cout << ans << endl ;
}


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

const int N = 3e5 + 10;
typedef long long ll;
ll n, x, a[N], K, cnt[N], sum[N], ans[N];

bool chk(ll k, ll x) { return sum[x] >= k * x; }

int main() {
    cin >> n;
    rep(i, 1, n) cin >> x, ++sum[++cnt[x]];
    rep(i, 1, n) sum[i] += sum[i - 1];
    ll now = 0;
    for (int k = n; k >= 1; k--) {
        while (now < n && chk(k, now + 1)) ++now;
        ans[k] = now;
    }
    rep(i, 1, n) printf("%lld\n", ans[i]);
    return 0;
}


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

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> ans(N, 0), a(K), b(K);

    for(int i=0; i<K; i++){
	cin >> a[i] >> b[i];
    }
    
    for(int i=0; i<K; i++){
	ans[a[i]-1]++;
	ans[b[i]-1]++;
    }
    
    for(int i=0; i<N; i++){
	cout << ans[i] << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,k,d,ans;
int arr[1009];
int main(){
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>arr[i];
    for(int i=1;i<=n+1;i++){
        int x = arr[i-1] + d;
        if(x <= k) ans++;
        d = x;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define dscan(a,b) scanf("%d %d",&a,&b);
#define scan(a) scanf("%d",&a);
#define pin(a) printf("%d\n",a)
#define pll(a) printf("%I64d\n",a);
#define inf 1000000009
#define infmx 1e18
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define IOS ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define all(x) x.begin(),x.end()
typedef pair<int,int>pi;
typedef pair<long long,long long>pll;
typedef vector<int>vi;
const int N=2100000;
ll mod=1e9+7;
int power(int a,int p){int r=1,y=a;while(p){if(p&1)r=(1LL*r*y)%mod;p>>=1;y=(1LL*y*y)%mod;}return r;}
int ara[N];
int main()
{
    IOS;
    int n;cin>>n;
    for(int i=0;i<n;i++){
        int a;cin>>a;
        ara[a]++;
    }
    int res=0;
    for(int i=1;i<=100000;i++){
        int temp=ara[i]+ara[i-1]+ara[i+1];
        res=max(res,temp);
    }
    cout<<res<<endl;
}


Measured memory_bytes: 3904
#include <cmath>
#include <deque>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int N, M, a, b; bool vis[100009]; vector<int> g[100009];
int main() {
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		cin >> a >> b; a--, b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	deque<int> que; que.push_back(0); vis[0] = true;
	int l = 0, r = 0;
	while (true) {
		bool flag = false;
		for (int i : g[l]) {
			if (!vis[i]) {
				flag = true;
				que.push_front(i);
				vis[i] = true;
				l = i;
				break;
			}
		}
		if (!flag) break;
	}
	while (true) {
		bool flag = false;
		for (int i : g[r]) {
			if (!vis[i]) {
				flag = true;
				que.push_back(i);
				vis[i] = true;
				r = i;
				break;
			}
		}
		if (!flag) break;
	}
	cout << que.size() << endl;
	for (int i : que) cout << i + 1 << ' ';
	return 0;
}

Measured memory_bytes: 6784
const MOD: usize = 998244353;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n = sc.read();
    let m = sc.read();
    let a: Vec<Vec<i64>> = (0..n).map(|_| sc.vec(m)).collect();
    let rank = f2_gauss_jordan(a);

    let mut pow = vec![0; n + m + 1];
    pow[0] = 1;
    for i in 1..(n + m + 1) {
        pow[i] = (pow[i - 1] * 2) % MOD;
    }

    let ans = pow[n + m - 1] + MOD - pow[n + m - rank - 1];
    println!("{}", ans % MOD);
}

fn f2_gauss_jordan(mut a: Vec<Vec<i64>>) -> usize {
    let n = a.len();
    let m = a[0].len();
    let mut rank = 0;
    let mut row = 0;
    for col in 0..m {
        match (row..n).filter(|&i| a[i][col] == 1).next() {
            Some(pivot) => {
                a.swap(row, pivot);
                rank += 1;
                for k in (row + 1)..n {
                    if a[k][col] == 1 {
                        for i in 0..m {
                            a[k][i] ^= a[row][i];
                        }
                    }
                }

                row += 1;
            }
            None => {}
        }

        if row >= n {
            break;
        }
    }
    rank
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String t = sc.next();
    if (t.substring(0, s.length()).equals(s)) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}


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

int main() {
  string o,e;
  cin >> o >> e;
  
  int a = o.size();
  
  for(int i=0; i<a; i++){
     cout << o[i];
    if(i==a-1 && e.size()<o.size()) break;
     cout << e[i];
  }
  
}


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

using namespace std;

int main(void)
{
    int len;
    long long pwrs[12] = {1}, n;
    for (int i = 1; i < 12; i++)
    {
        pwrs[i] += pwrs[i - 1] + round(pow(26, i));
        
    }
    cin >> n;
    for (int i = 1; i < 12; i++)
    {
        if (n < pwrs[i])
        {
            len = i;
            n -= pwrs[i - 1];
            break;
        }
    }
    char c[len + 1] = {0};
    for (int i = len - 1; i >= 0; i--)
    {
        c[i] = 'a' + n % 26;
        n /= 26;
    }
    cout << c;
    
    cout << endl;
}

Measured memory_bytes: 3916
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	int N;
	string S;

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



Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  ll max_d, min_d;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int k = 0; k < K; k++) {
    bool saturated = true;
    for (int i = 0; i < N; i++)
      if (A[i] != N) saturated = false;
    if (saturated) break;
    vector<ll> B(N, 0);
    for (int i = 0; i < N; i++) {
      min_d = max(0LL, i - A[i]);
      max_d = min(N - 1, i + A[i]);
      B[min_d]++;
      if (max_d + 1 < N) B[max_d + 1]--;
    }
    for (int i = 1; i < N; i++) B[i] += B[i - 1];
    for (int i = 0; i < N; i++) A[i] = B[i];
  }
  for (int i = 0; i < N - 1; i++) cout << A[i] << " ";
  cout << A[N - 1] << endl;
  return 0;
}

Measured memory_bytes: 6300
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int d = sc.nextInt();
        int x = sc.nextInt();
        long out = r * x - d;
        for (int i = 0; i < 10; i++) {
            System.out.println(out);
            out = r * out - d;
        }
        sc.close();
    }
}

Measured memory_bytes: 22228
from heapq import heappush, heappop


def dijkstra(edge, start, end):
    """
    Create distance(cost) table for all nodes.
    :param edge: List of tuple(to, cost)
    :param start: start node
    :param end: end node
    :return: minimum cost from start to end
    """
    h = [(0, start)]
    used = [False] * len(edge)

    while h:
        cost, node = heappop(h)
        if used[node]:
            continue
        used[node] = True

        if node == end:
            return cost

        for i, c in edge[node]:
            heappush(h, (cost + c, i))

    return -1


K = int(input())

edge = [[] for _ in range(K)]
for i in range(1, K):
    if i % 10 != 9:
        edge[i].append(((i+1) % K, 1))
    edge[i].append(((i*10) % K, 0))

print(dijkstra(edge, 1, 0) + 1)

Measured memory_bytes: 93044
#include "bits/stdc++.h"
#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define All(obj) (obj).begin(),(obj).end()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;


int main() {
	speed;
	int n, k;
	vector<int> l;
	cin >> n >> k;
	rep(i, n) {
		int b;
		cin >> b;
		l.push_back(b);
	}
	sort(All(l));
	int ans = 0;
	rep(i, k) {
		ans += l.back();
		l.pop_back();
	}
	cout << ans;
	ed;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,m,i,j,k,l,mod=1e9+7,dp[505][505][505],pw[505][505],fac[505],inv[505],fi[505],cnt[505],ans;
int c(int x,int y){return 1ll*fac[x]*fi[y]%mod*fi[x-i]%mod;}
int main(){
//	cerr<<sizeof(dp)/1024.0/1024.0<<endl;
	fac[0]=fac[1]=inv[0]=inv[1]=fi[0]=fi[1]=1;
	for(pw[0][0]=i=1;i<=500;i++)for(pw[i][0]=j=1;j<=500;j++) pw[i][j]=1ll*pw[i][j-1]*i%mod;
	for(i=2;i<=500;i++){
		fac[i]=1ll*fac[i-1]*i%mod;
		inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
		fi[i]=1ll*fi[i-1]*inv[i]%mod;
	}
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		cnt[x]++;
	}
	dp[m+1][0][0]=1;
	for(i=m;i>=1;i--){
		for(j=0;j<=m;j++){
			for(k=0;k<=m;k++)if(dp[i+1][j][k]){
				for(l=0;j+l<=m&&k+l*i<=m;l++){
					dp[i][j+l][k+l*i]=(dp[i][j+l][k+l*i]+1ll*dp[i+1][j][k]*fi[l])%mod;
				}
			}
		}
		for(j=0;j<=m;j++){
			for(k=0;k<=m;k++)if(dp[i][j][k]){
				dp[i][j][k]=1ll*dp[i][j][k]*pw[k-(i-1)*j][cnt[i]]%mod;
			}
		}
	}
	for(i=1;i<=m;i++){
		for(j=0;j<=m;j++)if(dp[1][i][j]){
			int c0=m+1-j-i;
			if(c0<0) continue;
			int res=1ll*dp[1][i][j]*fi[c0]%mod*fac[i+c0]%mod;
			if((i+c0)&1) ans=(ans+res)%mod; else ans=(ans-res+mod)%mod;
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 500992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

void yes(){cout<<"Yes"<<endl;}
void no(){cout<<"No"<<endl;}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  int ma=*max_element(begin(a),end(a)),mi=*min_element(begin(a),end(a));
  if(ma-mi>1) no();
  else if(ma-mi==1){
    int x=0;
    rep(i,n) if(a[i]==mi) x++;
    if(2*ma<=n+x && x<ma) yes();
    else no();
  }else{
    if(ma==n-1 || 2*ma<=n) yes();
    else no();
  }
}

Measured memory_bytes: 640
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		boolean[] hate = new boolean[10];
		for(int i=0; i<K; i++)
			hate[sc.nextInt()]=true;
		
		for(int i=N; i<=1000000; i++) {
			boolean ok = true;
			int pay = i;
			while(pay>0) {
				if(hate[pay%10]) {
					ok = false;
					break;
				}
				pay/=10;
			}
			if(ok) {
				System.out.println(i);
				break;
			}
		}
		
		sc.close();
	}
}


Measured memory_bytes: 9940
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef long long ll;
const ll MOD = (ll)1e9 + 7;
ll add(ll x, ll y)
{
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll mult(ll x, ll y)
{
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p)
{
	if (p == 0) return 1;
	if (p == 2 || (p & 1)) return mult(x, bin_pow(x, p - 1));
	return bin_pow(bin_pow(x, 2), p / 2);
}
ll rev(ll x)
{
	return bin_pow(x, MOD - 2);
}

const int N = 200200;
ll f[N], rf[N];

ll getC(int n, int k)
{
	if (k < 0 || k > n) return 0;
	return mult(f[n], mult(rf[k], rf[n - k]));
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	f[0] = 1;
	for (int i = 1; i < N; i++)
		f[i] = mult(f[i - 1], i);
	rf[N - 1] = rev(f[N - 1]);
	for (int i = N - 1; i > 0; i--)
		rf[i - 1] = mult(rf[i], i);

	int n, m, a, b;
	scanf("%d%d%d%d", &n, &m, &a, &b);
	ll ans = 0;
	for (int i = 0; i < n - a; i++)
		ans = add(ans, mult(getC(b - 1 + i, i), getC(m - b - 1 + n - 1 - i, n - 1 - i)));
	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 3328
S = input()
if int(S[0])+int(S[1])+int(S[2])+int(S[3])==7:
  print(S[0]+"+"+S[1]+"+"+S[2]+"+"+S[3]+"=7")
elif int(S[0])+int(S[1])+int(S[2])-int(S[3])==7:
  print(S[0]+"+"+S[1]+"+"+S[2]+"-"+S[3]+"=7")
elif int(S[0])+int(S[1])-int(S[2])-int(S[3])==7:
  print(S[0]+"+"+S[1]+"-"+S[2]+"-"+S[3]+"=7")
elif int(S[0])-int(S[1])-int(S[2])-int(S[3])==7:
  print(S[0]+"-"+S[1]+"-"+S[2]+"-"+S[3]+"=7")
elif int(S[0])-int(S[1])+int(S[2])-int(S[3])==7:
  print(S[0]+"-"+S[1]+"+"+S[2]+"-"+S[3]+"=7")
elif int(S[0])+int(S[1])-int(S[2])+int(S[3])==7:
  print(S[0]+"+"+S[1]+"-"+S[2]+"+"+S[3]+"=7")
elif int(S[0])-int(S[1])-int(S[2])+int(S[3])==7:
  print(S[0]+"-"+S[1]+"-"+S[2]+"+"+S[3]+"=7")
else:
  print(S[0]+"-"+S[1]+"+"+S[2]+"+"+S[3]+"=7")

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

int main() {
    string a, b;
    cin >> a >> b;
    string ans;
    if(a.size() > b.size()) ans = "GREATER";
    else  if(a.size() < b.size()) ans = "LESS";
    else {
        if(a < b) ans = "LESS";
        else if(a > b) ans = "GREATER";
        else ans = "EQUAL";
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <math.h>
#include <algorithm> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll INF = 1000000000000000000LL;
using namespace std;

const int MOD = 1000000007;

//h,n,w
int main(){
    ll N;
    cin >> N;
    
    vector <ll> a(N);
    vector <ll> b(N);
    ll acnt = 0;
    ll bcnt = 0;

    REP(i,N)
    {
        cin >> a[i];
    }
    REP(i,N)
    {
        cin >> b[i];
    }
    REP(i,N)
    {
        ll sa = abs(a[i] - b[i]);
        //a<bのときは、aを2ずつあげる
        if(a[i] < b[i])
        {
            acnt += sa / 2;
            if(sa % 2 == 1)
            {
                ++acnt;
                ++bcnt;
            }
        }
        else if(a[i] > b[i])
        {
            bcnt += sa;
        }
    }
    string res;

    if(acnt >= bcnt)res = "Yes";
    else res = "No";
    cout << res << endl;

    return 0;    
}


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

int main() {
    double N;
    cin>>N;
    vector<pair<double, double>> D(N);
    REP(i,0,N){
        int p, q;
        cin >> p >> q;
        D[i] = make_pair(p, q);
    }
    double sum_edge = 0;
    REP(i, 0, N-1){
        REP(j, i+1, N){
            double x_2 = (D[i].first - D[j].first)*(D[i].first - D[j].first);
            double y_2 = (D[i].second - D[j].second)*(D[i].second - D[j].second);
            sum_edge += pow( x_2+y_2 , 0.5);
        }
    }
    sum_edge *= 2/N;
    cout << setprecision(12) << sum_edge << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int INF = 987654321;
const ll MOD = 1000000007;
//const long double PI = (acos(-1));
//const long double EPS = 0.0000000001;
int dy[4] = {-1, 0, 1, 0};
int dx[4] = {0, 1, 0, -1};

ll len[51];
ll cnt[51];

void precal() {
	len[0] = 1;
	cnt[0] = 1;
	rep(i,1,51) {
		len[i] = len[i-1] * 2 + 3;
		cnt[i] = cnt[i-1] * 2 + 1;
	}
}

ll n, x;

ll f(ll n, ll x) {
	//cout << n << ", " << x << endl;
	if(x == 0) {
		return 0;
	} else if(n == 0) {
		return 1;
	} else if(len[n] == x || len[n] == x+1) {
		return cnt[n];
	}

	ll y = len[n-1];
	ll ret = 0;
	if(x >= y+1) {
		ret += cnt[n-1];
		x -= (y+1);
	} else {
		return f(n-1, x-1);
	}

	if(x >= 1) {
		ret++;
		x -= 1;
	} else {
		return ret;
	}

	if(x > 0) 
		ret += f(n-1, x);
	return ret;
}

int main(void) {
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("in.txt", "r", stdin);
	precal();
	cin >> n >> x;
	cout << f(n, x) << endl;
	return 0;
}

Measured memory_bytes: 256
s = input()
L = len(s)

l, r, p = 0, 0, s[L // 2]
if L % 2 == 0:
    l, r = L // 2 - 1, L // 2
else:
    l, r = L // 2, L // 2

cnt = 0
while l >= 0 and r < L and s[l] == s[r] == p:
    p = s[l]
    cnt += 1
    l -= 1
    r += 1

print(cnt + L // 2)


Measured memory_bytes: 3188
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main(){
  int X, Y;
  cin >> X >> Y;
  int m = 0;
  if(X==1){
    m+=300000;
  }
  else if(X==2){
    m+=200000;
  }
  else if(X==3){
    m+=100000;
  }
  if(Y==1){
    m+=300000;
  }
  else if(Y==2){
    m+=200000;
  }
  else if(Y==3){
    m+=100000;
  }
  if(X==1 && Y==1){
    m+=400000;
  }
  cout << m << endl;
}

Measured memory_bytes: 256
S = input()
if(S=='SUN'):
    print(7)
elif(S=='MON'):
    print(6)
elif(S=='TUE'):
    print(5)
elif (S=='WED'):
    print(4)
elif (S=='THU'):
    print(3)
elif (S=='FRI'):
    print(2)
else:
    print(1)

Measured memory_bytes: 9064
#include <cstdio>
#include <cstring>

int in[5];

int main()
{
    int a,b,cnt=0;
    while(~scanf("%d%d",&a,&b)){
        ++cnt;
        ++in[a];++in[b];
    }
    if(cnt<3){printf("NO\n");return 0;}
    cnt=0;
    for(int i=1;i<=4;++i){
        if(in[i]&1) ++cnt;
        if(cnt>2){
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");

    return 0;
}


Measured memory_bytes: 128
s = input()
isAdd = False
l = -1
r = -1
for i in range(len(s)):
    if s[i] == 'A' and l == -1: l = i
    if s[len(s)-1-i] == 'Z' and r == -1: r = len(s)-1-i

print(r-l+1)


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

int main() {
  int a,b;
  cin >> a >> b;
  if(a > 8 || b > 8){
    cout << ":(" << endl;
  }
  else{
    cout << "Yay!" << endl;
  }
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
using namespace std;
 
int main(){
    int p, q;
    while(cin >> p >> q){
        map<int,int> used;
        vector<int> dig;
         
        int n = p * 10;
        bool fin = true;
        int start, size;
        
        size = 0;
        used[p] = size++;
        for(;;){
            dig.push_back(n / q);
 
            int m = n % q;
            if(m == 0)break;
            if(used.count(m)){
                fin = false;
                start = used[m];
                break;
            }
 
            used[m] = size++;
             
            n %= q;
            n *= 10;
        }
 
        for(int i=0;i<dig.size();i++)cout << dig[i];
        cout << endl;
 
        if(fin)continue;
 
        for(int i=0;i<dig.size();i++){
            if(i < start)cout << " ";
            else cout << "^";
        }
 
        cout << endl;
    }
    return 0;
}

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

using namespace std;

string str;
int n;

int main()
{
    //freopen("in.txt", "r", stdin);
    cin >> str;
    n = (int) str.length();
    string ans = "";
    for(int i=0; i<str.length(); i++){
        if(str[i] == '?') ans += 'D';
        else ans += str[i];
    }
    cout << ans << endl;
}



Measured memory_bytes: 3920
#include <iostream>
#include <cmath>

using namespace std;

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

    bool flag = false;
    for (int h = 1; h <= 3500; ++h) {
        for (int n = 1; n <= 3500; ++n) {
            double w = (double) N * h * n / (4 * h * n - N * n - N * h);
            if (w > 0 && w - floor(w) < 1e-9) {
                cout << h << " " << n << " " << (int) w << endl;
                flag = true;
            }
            if (flag)
                break;
        }
        if (flag)
            break;
    }
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
ll s;

ll calc3(ll x) {
    return x / 3;
}

ll calc5(ll x) {
    return x / 5;
}

ll calc15(ll x) {
    return x / 15;
}

ll calc3(ll a,ll b) {//[a,b)の3の倍数
    return calc3(b-1) - calc3(a-1);
}

ll calc5(ll a,ll b) {//[a,b)の5の倍数
    return calc5(b-1) - calc5(a-1);
}

ll calc15(ll a,ll b) {//[a,b)の15の倍数
    return calc15(b-1) - calc15(a-1);
}

ll calc(const ll x) {
    ll beki = 10;
    ll ret = 0;
    ll i = 1;
    for(i = 1;beki < x;i++,beki*=10) {
        ll I = beki - beki / 10;
        ll a = calc3(beki/10,beki);
        ll b = calc5(beki/10,beki);
        ll c = calc15(beki/10,beki);

        ret += 4 * a + 4 * b + (I - a - b + c) * i;
    }

    ll I = x + 1 - (beki / 10);
    ll a = calc3(beki/10,x+1);
    ll b = calc5(beki/10,x+1);
    ll c = calc15(beki/10,x+1);

    ret += 4 * a + 4 * b + (I - a - b + c) * i;

    return ret;
}

ll C(ll x) {
    return (calc(x) >= s);
}

ll lower_bound(ll s,ll t) {
    ll lb = s - 1,ub = t;

    while(ub - lb > 1) {
        ll mid = (ub + lb) / 2;
        (C(mid) ? ub : lb) = mid;
    }
    return ub;
}


int main() {
    cin >> s;

    ll start = lower_bound(1,1e18 + 1);

    string ans = "";
    for(ll i = start;i < start + 21;i++) {
        if(i % 3 == 0 || i % 5 == 0) {
            if(i % 3 == 0) {
                ans += "Fizz";
            }
            if(i % 5 == 0) {
                ans += "Buzz";
            }
        }else {
            ans += to_string(i);
        }
    }

    ll b;
    if(start % 15 == 0)b = 8;
    else if(start % 3 == 0 || start % 5 == 0){
        b = 4;
    }
    else b = to_string(start).size();
    ll d = b - (calc(start) - s) - 1;
    cout << ans.substr(d,20) << endl;
    return 0;
}


Measured memory_bytes: 3280
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define N 100005
ll inf = 1e14;
int mod = 998244353;
char en = '\n';

ll abs1(ll x) {
  if (x < 0)
    return -x;
  return x;
}
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

ll dp[N];
ll arr[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  memset(dp, 0, sizeof(dp));
  dp[1] = 0;

  ll n;
  cin >> n;
  for (ll i = 1; i <= n; i++)
    cin >> arr[i];

  dp[2] = dp[1] + abs1(arr[2] - arr[1]);
  for (ll i = 3; i <= n; i++) {
    dp[i] = min(dp[i - 1] + abs1(arr[i] - arr[i - 1]),
                dp[i - 2] + abs1(arr[i] - arr[i - 2]));
  }

  cout << dp[n] << en;
  return 0;
}


Measured memory_bytes: 1792
N, M = map(int, input().split())
H = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(M)]

ANS = [True] * N

for ab in AB:
    a = ab[0] - 1
    b = ab[1] - 1

    if H[a] > H[b]:
        ANS[b] = False
    elif H[a] == H[b]:
        ANS[a] = ANS[b] = False
    else:
        ANS[a] = False

print(ANS.count(True))


Measured memory_bytes: 32052
#include<stdio.h>
#define MAX 8
#define FREE 1
#define NFREE -1

int ltr[MAX],ttb[MAX];
int ttl[2*MAX-1],ttr[2*MAX-1];

int A[MAX][MAX];

void intia()
{
  int i;
  for(i=0;i<MAX;i++)
    {
      ltr[i]=FREE;
      ttb[i]=FREE;
    }
  for(i=0;i<2*MAX-1;i++)
    {
      ttl[i]=FREE;
      ttr[i]=FREE;
    }
}

void printBro()
{
  int i,j;
  for(i=0;i<MAX;i++)
    {
      for(j=0;j<MAX;j++)
	{
	  if(A[i][j]==1)
	    {
	      if(ltr[i]!=j)return;
	    }
	}
    }
  
  for(i=0;i<MAX;i++)
    {
      for(j=0;j<MAX;j++)
	{
	  if(ltr[i]==j)printf("Q");
	  if(ltr[i]!=j)printf(".");
	}
      printf("\n");
    }
}

void recur(int k)
{
  int i;
  if(k==MAX)
    {
      printBro();
      return;
    }
  for(i=0;i<MAX;i++)
    {
      if(NFREE==ttb[i] || NFREE==ttl[k+i] || NFREE==ttr[k-i+MAX-1])continue;
      ltr[k]=i;
      ttb[i]=ttl[k+i]=ttr[k-i+MAX-1]=NFREE;
      
      recur(k+1);
      ltr[k]=ttb[i]=ttl[k+i]=ttr[k-i+MAX-1]=FREE;
    }
}

int main()
{
  int i,j,key;
  intia();
  for(i=0;i<MAX;i++)
    {
      for(j=0;j<MAX;j++) A[i][j]=-1;
    }
  scanf("%d",&key);
  for(i=0;i<key;i++)
    {
      int row,column;
      scanf("%d %d",&row,&column);
      A[row][column]=1;
    }
  recur(0);
  return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int N;
    int a, b;
    std::cin >> N;
    if(N == 2) {
        std::cin >> a >> b;
        std::cout << a + b << std::endl;
    }
  	else std::cout << "Hello World" << std::endl;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
long long sum = 0;
string s;
int main()
{
    cin >> s;
    for(int i = 0;i < s.size();i++)
    {
        sum += ('0' - s[i]);
    }
    if(sum % 9 == 0) cout << "Yes";
    else cout << "No";
    return 0;
}


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

const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
using P = pair<int, int>;



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

    ll x;
    cin >> x;
    ll ans = 0;
    ans += x / 500 * 1000;
    x %= 500;
    ans += x / 5 * 5;
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=2e5+9;
int main()
{
    FASTINOUT;
    string s;
    cin>>s;
    for (int i=0;i<s.length();i++){
        if (s[i]==',')
            cout<<" ";
        else
            cout<<s[i];
    }
    return 0;
}


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

int comparator(const long long int *a, const long long int *b);
long long int TREES[100001];

int main(void) {
  long K,N;
  scanf("%ld %ld", &N, &K);
  for(long i=0;i<N;i++) {
    scanf("%lld", &TREES[i]);
  }

  qsort(TREES, N, sizeof(long long int), comparator);


  long long int minDist = TREES[K - 1] - TREES[0];
  long long int beg, end;
  for(long i=1;i<=N - K;i++) {
    long long int dist = TREES[i + K - 1] - TREES[i];
    if(dist < minDist) {
      minDist = dist;
    }
  }
  printf("%lld\n", minDist);
  return 0;
}

int comparator(const long long int *a, const long long int *b) {
  if(*a > *b) return 1;
  else if(*a == *b) return 0;
  else return -1;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N;
  cin>>N;
  vector<int>a(N);
  for(int i=0;i<N;i++)cin>>a[i];
  bool ok=false;
  for(auto it:a)if(it==1)ok=true;
  if(!ok){
    cout<<-1<<endl;
    return 0;
  }
  int c=1;
  for(int i=0;i<N;i++){
    if(c==a[i])c++;
  }
  cout<<N-(c-1)<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    string s;
    cin >> s;
    int w;
    cin >> w;
    string ans = "";
    for (int i = 0; i < s.size(); i += w) ans += s[i];
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <cmath>
#include <unistd.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#define PI 3.14159265358979323846
 
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	int N, pe=0, be=0, pd=0, bd=0, min=100010;
	string S;
 
	cin >> N >> S;
	for(int i=0;i<N;i++)
	{
		if(S[i]=='#')
			pd++;
		else
			bd++;
	}

	if(pe+bd<min)
		min = pe+bd;

	for(int i=0;i<N;i++)
	{
		if(S[i]=='#')
		{
			pd--;
			pe++;
		}
		else
		{
			bd--;
			be++;
		}

		if(pe+bd<min)
			min = pe+bd;
	}

	cout << min << endl;
 
	return 0;
}

Measured memory_bytes: 720
#pragma warning disable

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Numerics;
using System.Collections;

static class MainClass
{
    public static void Main(string[] args)
    {

        var n = Console.ReadLine().ToInt32();
        Console.WriteLine((n * (n + 1)) / 2);
    }




    #region ライブラリ
    public static long ToInt64(this string str) => long.Parse(str);
    public static int ToInt32(this string str) => int.Parse(str);
    public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
    public static List<string> SplittedStringToList(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
    public static List<int> SplittedStringToInt32List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();
    public static List<long> SplittedStringToInt64List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => long.Parse(x)).ToList();
    public static List<BigInteger> SplittedStringToBigInteger(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => BigInteger.Parse(x)).ToList();
    public const int INF = int.MaxValue / 2;
    public const long LONGINF = long.MaxValue / 2;
    public const int Mod1e9 = 1000000007;
    

    public static void PrintArray(int[,] array)
    {
        for (int i = 0; i < array.GetLength(0); i++)
        {
            var sb = new StringBuilder();
            for (int j = 0; j < array.GetLength(1); j++)
            {
                sb.Append(array[i, j]).Append(" ");
            }
            Console.WriteLine(sb.ToString());
        }
    }

    #endregion
}



Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>

using namespace std;

#define int long long

const int INF = 1e18 + 239;

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

	int n, k;
	cin >> n >> k;
	k--;
	vector<int> a(n);
	for (auto &t : a) {
		cin >> t;
	} 
	sort(a.begin(), a.end());
	auto kek = [&](int x) {
		int ans = 0;
		for (int j = n - 1; j > 0; j--) {
			int t = a[j];
			if (t == 0) {
				if (x <= 0) {
					ans += (j);
				}
				continue;
			}
			int need = (x) / t;
			if (t > 0) {
				int f = 0;
				for (int i = need - 10; i <= need + 10; i++) {
					if (t * i >= x && t * (i - 1) < x) {
						need = i;
						f = 1;
						break;
					}
				}
				assert(f);
				int cnt_ok = (a.begin() + j) - lower_bound(a.begin(), a.begin() + j, need);
				ans += cnt_ok;
			} else {
				need = (x) / t;			
				int f = 0;
				for (int i = need - 10; i <= need + 10; i++) {
					if (t * i >= x && t * (i + 1) < x) {
						need = i;
						f = 1;
						break;
					}
				}
				assert(f);
				int cnt_ok = upper_bound(a.begin(), a.begin() + j, need) - (a.begin());
				ans += cnt_ok;
			}
		}
		ans = n * (n - 1) / 2 - ans;
		return ans;
	};
	int l = -INF;
	for (int i = 62; i >= 0; i--) {
		if (kek(l + (1ll << i)) <= k) {
			l += (1ll << i);
		}
	}
	cout << l << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll x,y;
	cin>>x>>y;
	if(x==y)
	{
		cout<<0<<'\n';
		return 0;
	}
	/*
	if(x<y)
	{
		if(x>=0)
		{
			cout<<y-x<<'\n';
		}
		else if(-x<=y)
		{
			cout<<y-(-x)+1<<'\n';
		}
		else
		{
			int ans = 0;
			if(y<=0)
			{
				cout<<y-x<<'\n';
				return 0;
			}
			ans=abs(x)-abs(y);
			ans++;
			cout<<ans<<'\n';
		}
		return 0;
	}
	else
	{
		int ans = 1;
		if(abs(x)<abs(y))
		{
			if(x>=0)
			{
				ans=-y-x;
				ans++;
			}
			else
			{
				x=-x;
				ans+=abs(y)-x;
				ans++;
			}
			cout<<ans<<'\n';
			return 0;
		}
		x=-x;
		if(x<=0&&y>=0)
		{
			
			ans+=abs(x)-abs(y);
			ans++;
			cout<<ans<<'\n';
			return 0;
		}
		if(x<=y)
		{
			if(x>=0)
			{
				cout<<y-x+1<<'\n';
			}
			else if(-x<=y)
			{
				cout<<y-(-x)+2<<'\n';
			}
			else
			{
				if(y<=0)
				{
					cout<<y-x+1<<'\n';
					return 0;
				}
				ans+=abs(x)-abs(y);
				ans++;
				cout<<ans<<'\n';
			}
			return 0;
		}
		else
		{
			y=-y;
			ans+=abs(y-x);
			ans++;
			cout<<ans<<'\n';
			return 0;
		}
	}
	*/
	if(x>=0&&y>=0)
	{
		if(x<=y)
		{
			cout<<y-x<<'\n';
		}
		else
		{
			if(y!=0) cout<<2+x-y<<'\n';
			else cout<<x-y+1<<'\n';
		}
		return 0;
	}
	if(x<=0&&y>0)
	{
		if(abs(x)<=abs(y))
		{
			cout<<1+abs(y)-abs(x)<<'\n';
		}
		else
		{
			cout<<1+abs(x)-abs(y)<<'\n';
		}
		return 0;
	}
	if(x<=0&&y<=0)
	{
		if(x<=y)
		{
			cout<<y-x<<'\n';
			return 0;
		}
		else
		{
			if(x!=0) cout<<x-y+2<<'\n';
			else cout<<x-y+1<<'\n';
			return 0;
		}
	}
	//x>=0&&y<=0
	if(abs(x)<=abs(y))
	{
		cout<<abs(y)-abs(x)+1<<'\n';
	}
	else
	{
		cout<<abs(x)-abs(y)+1<<'\n';
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string s;
int l;
int main(){
	cin>>s;
	l=s.length();
	if(s[0]==s[l-1]){
		if((l-2)%2==0)cout<<"First\n";
		else cout<<"Second\n";
	}
	else{
		if((l-2)%2==1)cout<<"First\n";
		else cout<<"Second\n";
	}
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) for (int i = 0; i <= (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define KOZYUN(a) sort(all(a),greater<int>())
#define int ll
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORe(i, m, n) for(int i = m;i <= n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
#define IN(a) cin >> a
#define INT(a) int a; cin >> a
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    INT(n);
    VI a(n); VIin(a);
    int ans = 0;
    int res = 1;
    bool flag = false;
    rep(i,n){
        if(res != a[i]) ans++;
        else res++;
        if(a[i] == 1) flag = true;
    }
    if(flag) ANS;
    else OUT(-1);

    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<int>A(N);
  for (int i = 0; i < N; i ++) cin >> A[i];
  vector<long long>L(N + 1, 0);
  vector<long long>R(N + 1, 0);
  for (int i = 0; i < N; i ++) {
    int k = i - A[i];
    if (k >= 0 && k <= N) L[k] ++;
    int j = i + A[i];
    if (j >= 0 && j <= N) R[j] ++;
  }
  long long ans = 0;
  for (int i = 0; i < N; i ++) {
    long long k = L[i] * R[i];
    ans += k;
  }
  cout << ans << endl;
}



Measured memory_bytes: 7112