akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>
using namespace std;

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

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

class State{
public:
  int id,cost,gas;

  State(){}
  State(int _id,int _cost,int _gas){
    id = _id;
    cost = _cost;
    gas = _gas;
  }

  bool operator<(const State &st)const{
    return cost > st.cost;
  }
};

int n,m,cap;
int src,dest;
vector<P> t[6002];
bool flg[6002];

bool closed[6002][2002];

map<string,int> name;

int trans(string s){
  if(name.find(s) == name.end()){
    int size = name.size();
    name[s] = size;
    return size;
  }
  else{
    return name[s];
  }
  return -1;
}

void solve(){
  priority_queue<State> open;
  memset(closed,0,sizeof(closed));
  open.push(State(src,0,cap));

  while(!open.empty()){
    State st = open.top();
    open.pop();
    if(closed[st.id][st.gas]) continue;
    closed[st.id][st.gas] = true;

    if(st.id == dest){
      cout<<st.cost<<endl;
      return ;
    }

    if(flg[st.id]){
      st.gas = cap;
    }

    rep(i,t[st.id].size()){
      P p = t[st.id][i];
      if(st.gas >= p.second){
        open.push(State(p.first,st.cost+p.second,st.gas-p.second));
      }
    }
  }

  cout<<-1<<endl;
}

int main(){
  while(cin>>m>>n>>cap,m||n||cap){
    cap *= 10;
    name.clear();

    string src_s,dest_s;
    cin>>src_s>>dest_s;
    src = trans(src_s);
    dest = trans(dest_s);

    rep(i,6002) t[i].clear();

    rep(i,m){
      string a_s,b_s;
      int a,b,d;

      cin>>a_s>>b_s>>d;
      a = trans(a_s);
      b = trans(b_s);

      t[a].push_back(P(b,d));
      t[b].push_back(P(a,d));
    }

    memset(flg,0,sizeof(flg));
    rep(i,n){
      string id_s;
      int id;
      cin>>id_s;
      flg[trans(id_s)] = true;
    }

    /*
    rep(i,name.size()){
      cout<<i<<":";
      rep(j,t[i].size()){
        cout<<t[i][j].first<<","<<t[i][j].second<<"   ";
      }
      cout<<endl;
    }
    cout<<endl;
    */

    solve();
  }
}

Measured memory_bytes: 49000
#include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    ll INF =1e9+7;
    typedef pair<ll,ll> ii;
    #define f(i,a,b) for(long long i = a;i < b;i++)
    #define rf(i,a,b) for(long long i=a;i>=b;i--)
    #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #define w(t) while(t--)
    #define c(n); cin>>n;
    #define p(n) cout<<n;
    #define pl(n) cout<<n<<endl;
    #define ps(n); cout<<n<<" ";
    int main(void){
        fastio;
        ll a,b,c,d;
        c(a);
        c(b);
        c(c);
        c(d);
        int monthd[12]={31,28,31,30,31,30,31,31,30,31,30,31};
        if(monthd[a-1] == b){
            pl(1);
        }
        else{
            pl(0);
        }
    }


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define break break
#define continue continue
#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define LLPair pair<ll, ll>
#define vint vector<int>
#define vll vector<ll>
typedef long long ll;

using namespace std;


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

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int a, b;
	scanf("%d %d", &a, &b);
	if(a < b){
		printf("a < b\n");
	}
	if(a > b){
		printf("a > b\n");
	}
	if(a == b){
		printf("a == b\n");
	}
	return 0;
}

Measured memory_bytes: 580
//AtCoder 
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
constexpr ll MOD=1e9+7;
//[桁][未満フラグ,未満で1]
//条件は桁が違う場合1
ll dp[100001+10][2];

int main() {
    string L;
    cin>>L;
    dp[0][0]=1;
    for(ll k=0;k<L.size();++k){
		ll digit = L[k] - '0';
		for(ll d = 0; d < 2; ++d) { //未満フラグ1
            if(d==0){
				(dp[k + 1][1] += dp[k][1]) %= MOD;
			} else {
				(dp[k + 1][1] += dp[k][1]) %= MOD; //0と1がいける
                (dp[k + 1][1] += dp[k][1]) %= MOD;
            }
		}
		for(ll d = 0; d <= digit; ++d) { //未満フラグ0
            if(d==0){
			    (dp[k + 1][d < digit] += dp[k][0]) %= MOD;
            }else {
			    (dp[k + 1][d < digit] += dp[k][0]) %= MOD; //0と1がいける
			    (dp[k + 1][d < digit] += dp[k][0]) %= MOD;
            }
		}
	}
    cout<<(dp[L.size()][0]+dp[L.size()][1])%MOD<<endl;
    return 0;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(n);++i)
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

main(){

  ll h,w;
  cin>>h>>w;

  constexpr long long INF = (1LL<<60);
  ll ans=INF;
  for(ll i=1;i<=h-2;++i){
    ll a,b,c;
    a=i*w;
    b=(h-i)/2*w;
    c=(h-i)*w-b;
    chmin(ans,max({a,b,c})-min({a,b,c}));
  }
  for(ll i=1;i<=w-1;++i){
    ll a,b,c;
    a=i*h;
    b=(h/2)*(w-i);
    c=(w-i)*h-b;
    chmin(ans,max({a,b,c})-min({a,b,c}));
  }
  swap(h,w);
  for(ll i=1;i<=h-2;++i){
    ll a,b,c;
    a=i*w;
    b=(h-i)/2*w;
    c=(h-i)*w-b;
    chmin(ans,max({a,b,c})-min({a,b,c}));
  }
  for(ll i=1;i<=w-1;++i){
    ll a,b,c;
    a=i*h;
    b=(h/2)*(w-i);
    c=(w-i)*h-b;
    chmin(ans,max({a,b,c})-min({a,b,c}));
  }
  cout<<(ans)<<endl;

}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int hamming[1000001] = {0};
    int n, m;
    int i, j;

    hamming[1] = 1;
    for (i = 1; i <= 500000; i++){
        if (hamming[i] == 1){
            hamming[i * 2] = 1;
        }
    }
    for (i = 1; i <= 333333; i++){
        if (hamming[i] == 1){
            hamming[i * 3] = 1;
        }
    }
    for (i = 1; i <= 200000; i++){
        if (hamming[i] == 1){
            hamming[i * 5] = 1;
        }
    }

    for (i = 1; i <= 1000000; i++){
        hamming[i] += hamming[i - 1];
    }

    while (1){
        scanf("%d", &m);
        if (m == 0){
            break;
        }
        scanf("%d", &n);

        printf("%d\n", hamming[n] - hamming[m - 1]);
    }

    return (0);
}

Measured memory_bytes: 4512
n, m = map(int, input().split())
lista = []
for i in range(m):
    # s:判定に使用するスイッチ
    k, *s, = map(int, input().split())
    lista.append(list(s))
# p:2で割った時の余りが等しいと点灯
# 全てのpについて成り立たせよう
p = list(map(int, input().split()))

#p[0]について成り立たせよう
sumans = 0
# 全ての状態
for bit in range(1 << n):
    # 任意の状態aの中
    # 全ての電球について判定
    flag = True
    for i in range(m):
        sum = 0
        # 電球1について
        for j in lista[i]:
            if bit & (1 << (j - 1)):
                sum += 1
        if sum % 2 != p[i]:
            flag = False
    if flag:
        sumans += 1
print(sumans)

Measured memory_bytes: 40688
N = int(input())
S = [int(input()) for i in range(N)]
dp = [[0 for i in range(10101)] for j in range(101) ]
max_S = sum(S)
ans =0

dp[0][0] = 1
for i in range(N):
    for j in range(max_S+1):
        if dp[i][j] == 1:
            dp[i+1][j] =1
            dp[i+1][j+S[i]] =1

for j in range(max_S+1):
    if (j%10 !=0) & (dp[N][j]) == 1:
        ans = max(ans,j)

print(ans)

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

int main() {
	
	int a, b;
	cin >> a >> b;
	if(a <= 8 && b <= 8) puts("Yay!");
	else puts(":(");
	
	return 0;
}

Measured memory_bytes: 256
/** Which of the favors of your Lord will you deny ? **/

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

#define LL long long
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define F first
#define S second

#define ALL(x)      (x).begin(), (x).end()
#define READ        freopen("alu.txt", "r", stdin)
#define WRITE       freopen("vorta.txt", "w", stdout)

#ifndef ONLINE_JUDGE
#define DBG(x)      cout << __LINE__ << " says: " << #x << " = " << (x) << endl
#else
#define DBG(x)
#endif

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p);
template <class T>
ostream &operator <<(ostream &os, vector<T>&v);
template <class T>
ostream &operator <<(ostream &os, set<T>&v);

inline void optimizeIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int nmax = 2e5+7;

int main()
{
    optimizeIO();

    string s;
    cin>>s;

    int n = s.size();

    s = s + "#";
    int c = 1;

    int ans = 0;

    for(int i=0;i<=n;i++)
    {
        if(s[i]==s[i-1]) c++;
        else
        {
            if(s[i-1]=='R')
            {
                ans = max(ans,c);
            }

            c = 1;
        }
    }

    cout<<ans<<endl;

    return 0;
}

/**

**/

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p)
{
    os<<"{"<<p.first<<", "<<p.second<<"} ";
    return os;
}
template <class T>
ostream &operator <<(ostream &os, vector<T>&v)
{
    os<<"[ ";
    for(int i=0; i<v.size(); i++)
    {
        os<<v[i]<<" " ;
    }
    os<<" ]";
    return os;
}

template <class T>
ostream &operator <<(ostream &os, set<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" ";
    }
    os<<" ]";
    return os;
}




Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){
	string s;
	cin>>s;
	cout<<('4'<s.at(6)||s.at(5)=='1'?"TBD":"Heisei")<<endl;
}


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

#define endl '\n'
#define ll long long
#define rint register int

#define re register
#define pb(x) push_back(x);
#define ce(x) cout << x << '\n';

using db = long double;
using pll = pair < ll, ll >;
#define scan(a, n) 		for(int i = 0; i < n; i++)cin >> a[i];

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define hell 1000000007
#define infl LLONG_MAX

#define Foxen(i,s) for (i=s.begin(); i!=s.end(); i++)
#define Fill(s,v) memset(s,v,sizeof(s))
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl     //print with precision

#define tc(tt) \
    ll tt;    \
    cin >> tt; \
    for (ll _tt = 0; _tt < tt; _tt++) // testcase 

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

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll t, i, x, j, y, 	z, k, n;
	cin >> n >> k;
	ll a[n], b[n + 1];
	scan(a, n);

	rep(j, 0, k, 1) {
		memset(b, 0, sizeof(b));
		rep(i, 0, n, 1) {
			ll mi = max(0LL, i - a[i]), mx = min(n - 1, i + a[i]);
			b[mi]++;
			b[mx + 1]--;
		}
		bool br = a[0] == b[0];
		rep(i, 1, n, 1) {
			b[i] += b[i - 1];
			br = br && (a[i] == b[i]);
		}

		if (br)	break;

		rep(i, 0, n, 1)
		a[i] = b[i];

	}

	rep(i, 0, n, 1)	cout << a[i] << " ";
}


Measured memory_bytes: 6768
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

int n, m, s;
bool v[10];
vector<int> a[10];
void f(int p, int q) {
	int i;
	if (v[p]) return;
	if (q == n) {
		s++;
		return;
	}
	v[p] = 1;
	for (i =0; i < a[p].size(); i++) {
		f(a[p][i], q + 1);
	}
	v[p] = 0;
}
int main()
{
	int i, t1, t2;
	cin >> n >> m;
	while (m--) {
		scanf ("%d %d", &t1, &t2);
		a[t1].push_back(t2);
		a[t2].push_back(t1);
	}
	f(1, 1);
	cout << s;
    return 0;
}


Measured memory_bytes: 256
s = input()

n = len(s)
a = "10" * (n // 2) + "1" * (n % 2)
b = "01" * (n // 2) + "0" * (n % 2)

print(min(bin(int(s, 2) ^ int(a, 2)).count("1"), bin(int(s, 2) ^ int(b, 2)).count("1")))


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

using namespace std;
using lint = long long;

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

    // N=2のときK=1
    if (N == 2) {
        cout << 1 << endl;
        return 0;
    }

    // N>2のとき
    lint ans = 2;
    for (lint i = 2; i * i <= N; ++i) {
        if (N % i == 1) {
            if (i * i != N - 1) {
                ans += 2;
            } else {
                ans += 1;
            }
            continue;
        }

        if (N % i == 0) {
            lint NN = N;
            while (NN % i == 0) NN /= i;
            if (NN % i == 1) ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF (1e9)
using namespace std;

int main(){
  double ans;
  int d,e;
  while(1){
    cin>>d>>e;
    if(!d&&!e)break;
    ans=INF;
    for(int i=0;i<=d;i++)
      for(int j=i;j<=d;j++)
	if(i+j==d)ans=min(ans,abs(sqrt(i*i+j*j)-e));
    printf("%.8f\n",ans);
  }
  return 0;
}

Measured memory_bytes: 1196
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Console;

namespace AtCoder_1
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = CinT();
            string[] S = new string[N];
            int[] p = new int[N];
            Dictionary<string, Dictionary<int, int>> s = new Dictionary<string, Dictionary<int, int>>();
            for(int i = 0;i < N; i++)
            {
                var a = CinAr();
                if (!s.ContainsKey(a[0]))
                {
                    s.Add(a[0], new Dictionary<int, int>());
                }
                s[a[0]].Add(S2i(a[1]), i + 1);
            }
            var ggg = s.OrderBy((x) => x.Key, StringComparer.CurrentCulture);
            foreach(var f in ggg)
            {
                var ttt = f.Value.OrderByDescending((X) => X.Key);
                foreach(var l in ttt)
                {
                    Cout(l.Value);
                }
            }
            
            Cin();
        }



        static readonly int MOD1E9 = (int)1e9 + 7;
        static string Cin() { return ReadLine(); }
        static string[] CinAr() { return ReadLine().Split(' '); }
        static int CinT() { return S2i(Cin()); }
        static int[] CinTAr() { return CinAr().Select((x, i) => { return S2i(x); }).ToArray(); }
        static long CinL() { return S2L(Cin()); }
        static long[] CinLAr() { return CinAr().Select((x, i) => { return S2L(x); }).ToArray(); }
        static double CinD() { return S2D(Cin()); }
        static double[] CinDAr() { return CinAr().Select((x, i) => { return S2D(x); }).ToArray(); }
        static int S2i(string s) { return int.Parse(s); }
        static long S2L(string s) { return long.Parse(s); }
        static double S2D(string s) { return double.Parse(s); }
        static void OYes() { Cout("Yes"); }
        static void ONo() { Cout("No"); }
        static void Cout(object s) { WriteLine(s); }
        static int[] yakusuu(int n)
        {
            if (n == 1) { return new int[] { 1 }; }
            HashSet<int> res = new HashSet<int>();
            for (int i = 1; i < Math.Ceiling(n / 2.0); i++)
            {
                if (n % i == 0)
                {
                    res.Add(i);
                    res.Add(n / i);
                }
            }
            return res.ToArray();
        }
        /// <summary>
        /// Debug時のみの使用を推奨
        /// </summary>
        /// <typeparam name="Type"></typeparam>
        /// <param name="types"></param>
        static void CoutAr<Type>(IEnumerable<Type> types)
        {
            string text = "";
            foreach (var i in types)
            {
                text += " " + i;
            }
            WriteLine(text.Substring(1));
        }
    }
}


Measured memory_bytes: 11616
#include<bits/stdc++.h>
using namespace std;
using Graph = vector< vector<int64_t> >;

vector<bool> seen;
vector<int64_t> dist;

void bfs(const Graph &g, int64_t s) {
    queue<int> q;
    q.push(s);
    seen[s] = true;
    while(!q.empty()) {
        int v = q.front();
        q.pop();
        for(int64_t next_v : g[v]) {
            if(seen[next_v]) continue;
            seen[next_v] = true;
            dist[next_v] = dist[v] + 1;
            q.push(next_v);
        }
    }
}

int main() {
    int64_t n, m;
    cin >> n >> m;

    Graph g(n * 3);
    for(int64_t i = 0; i < m; i++) {
        int64_t u, v;
        cin >> u >> v;
        u--;
        v--;
        g[u].push_back(v + n);
        g[u + n].push_back(v + n * 2);
        g[u + n * 2].push_back(v);
    }

    seen.assign(n * 3, false);
    dist.assign(n * 3, 0);

    int64_t s, t;
    cin >> s >> t;

    bfs(g, --s);

    int64_t ans = dist[--t] / 3;
    if(ans == 0) cout << "-1" << endl;
    else         cout << ans << endl;

    return 0;
}

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

int main() {
  string abcd;
  cin >> abcd;
  int a = abcd[0] - '0';
  int b = abcd[1] - '0';
  int c = abcd[2] - '0';
  int d = abcd[3] - '0';

  for (int i = 0; i < (1 << 3); i++) {
    vector<char> op = {'-', '-', '-'};
    for (int j = 0; j < 3; j++) {
      if ((1 << j) & i) { op[j] = '+'; }
    }
    int sum = 0;
    sum     = (op[0] == '+' ? a + b : a - b);
    sum     = (op[1] == '+' ? sum + c : sum - c);
    sum     = (op[2] == '+' ? sum + d : sum - d);
    if (sum == 7) {
      printf("%d%c%d%c%d%c%d=7\n", a, op[0], b, op[1], c, op[2], d);
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	char str[100000];
	cin>>str;
	int n;
    n=strlen(str);
    for(int i=0;i<n;i++){
    	if(str[i]==',') cout<<" ";
    	else cout<<str[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
C - 二人のアルピニスト / Two Alpinists
https://atcoder.jp/contests/code-festival-2016-qualc/tasks/codefestival_2016_qualC_c

"""
import sys


def solve(N, T, A):
    mountains_t = dict()
    peak_t = T[0]
    mountains_t[1] = (peak_t, peak_t)
    for i, t in enumerate(T[1:], start=2):
        if t > peak_t:
            peak_t = t
            mountains_t[i] = (peak_t, peak_t)
        else:
            if t < peak_t:
                return 0
            mountains_t[i] = (1, peak_t)

    mountains_a = dict()
    peak_a = A[-1]
    mountains_a[N] = (peak_a, peak_a)
    for j, a in zip(range(N-1, 0, -1), reversed(A[:-1])):
        if a > peak_a:
            peak_a = a
            mountains_a[j] = (peak_a, peak_a)
        else:
            if a < peak_a:
                return 0
            mountains_a[j] = (1, peak_a)

    MOD = 10**9 + 7
    ans = 1
    for i in range(1, N+1):
        lt, ht = mountains_t[i]
        la, ha = mountains_a[i]
        if lt == ht or la == ha:
            if lt == ht and la == ha:
                if lt != la:
                    return 0
            elif lt == ht:
                if not la <= lt <= ha:
                    return 0
            else:
                if not lt <= la <= ht:
                    return 0
        else:
            high = min(ht, ha)
            ans = ans * high% MOD
    return ans


def main(args):
    N = int(input())
    T = [int(t) for t in input().split()]
    A = [int(a) for a in input().split()]
    ans = solve(N, T, A)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 49208
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a); a = (a * a);  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 100009,M = 42;
ll i,j,x,n,k;
string a;
ll pw[M],w[M][2],dp[M][2];
void binary(ll n)
{
    a = "";
    while(n > 0){
        a = char('0' + n % 2) + a;
        n /= 2;
    }
    while(a.length() < M) a = "0" + a;
}
ll solve(ll i,bool small)
{
    if(i == M) return 0;
    
    ll &res = dp[i][small];
    if(res != -1) return res;
    
    res = -MAX;
    ll limit = (small ? 1 : a[i] - '0');
    for(ll use = 0;use <= limit;use += 1)
        res = max(res, pw[M - 1 - i] * w[M - 1 - i][1 - use] + solve(i + 1,(use < a[i] - '0' ? 1 : small)));
    
    return res;
}
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    memset(dp,-1,sizeof(dp));
    pw[0] = 1;
    rep(i,1,M) pw[i] = pw[i - 1] * 2;
    cin>>n>>k;
    rep(i,0,n){
        cin>>x;
        rep(j,0,M) w[j][(x >> j) & 1] += 1;
    }
    binary(k);
    cout<<solve(0,0);
    return 0;
}

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

int main() {
  int N, K, x;
  cin >> N >> K;
  int ans = 0;
  for (int i=0; i < N; i++) {
    cin >> x;
    if (x <= K /2) {
      ans += 2 * x;
    }
    else {
      ans += 2 * (K - x);
    }
  }
  cout << ans << endl;
}

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

int main(){
    int n;
    long m;
    long a[1002];

    while(true){
        cin >> n >> m;
        if(n == 0 && m == 0) break;
        long ans = -1;

        for(int i=0;i<n;i++) cin >> a[i];
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(i != j){
                    if(a[i] + a[j] <= m){
                        ans = max(ans, a[i] + a[j]);
                    }
                }
            }
        }
        if(ans == -1){
            cout << "NONE" << "\n";
        }
        else{
            cout << ans << "\n";
        }

    }

    return 0;
}


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

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

int main() {

  int q;
  cin >> q;

  vector<int> a(100005);
  const int64_t inf = 1e9;
  for (int m = 2; m < (int)a.size(); m++) {
    int64_t p = 1;
    for (int x = 2; x * x <= m; x++) {
      if (m % x == 0) {
        p *= x;
        p = min(p, inf);
        if (m % x != x) {
          p *= (m / x);
          p = min(p, inf);
        }
      }
    }
    if (p >= m * 2) { a[m] += 1; }
  }
  rep(i, a.size() - 1) a[i + 1] += a[i];

  while (q--) {
    int n;
    cin >> n;
    cout << a[n] << endl;
  }

  return 0;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

int main() {
  ll x, y, z, k;
  cin >> x >> y >> z >> k;
  vll a(x);
  rep(i,x) cin >> a[i];
  vll b(y);
  rep(i,y) cin >> b[i];
  vll c(z);
  rep(i,z) cin >> c[i];
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  sort(b.begin(),b.end());
  reverse(b.begin(),b.end());
  sort(c.begin(),c.end());
  reverse(c.begin(),c.end());
  vll ab;
  rep(i,x)rep(j,y) ab.push_back(a[i]+b[j]);
  ll m = ab.size();
  sort(ab.begin(),ab.end());
  reverse(ab.begin(),ab.end());
  vll ans;
  rep(i,min(k,m))rep(j,z) ans.push_back(ab[i]+c[j]);
  sort(ans.begin(),ans.end());
  reverse(ans.begin(),ans.end());
  rep(i,k) cout << ans[i] << endl;
  return 0;
}

Measured memory_bytes: 43368
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
using P = pair<int, int>;
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}
int digit_sum(int i){
    if(i==0)return 0;
    return i%10+digit_sum(i/10);
}
signed main(signed argc, char* argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    const int MOD = 1e9 + 7;
    int n;
    cin>>n;
    if(n%10==0)cout<<10<<endl;
    else cout<<digit_sum(n)<<endl;
}


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

const int nums[] = {5, 4, 3, 2, 1};

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

  int xx = X % 100; // 下２桁
  int count = 0;
  while(xx > 0) {
    for(int i = 0; i < 5; ++i) {
      if(xx >= nums[i]) {
        xx -= nums[i];
        count++;
        break;
      }
    }
  }
  // cout << count << endl;
  cout << ((X / 100 >= count) ? 1 : 0) << endl;

  return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
x = 0
m = 0
for i in range(10**5):
    if i**2 < M <= (i+1)**2:
        m = i+1
        break
if m >N:
    for i in range(N, m):
        if M % i == 0:
            x = M // i
            break
if x == 0:
    for i in reversed(range(1, M //N +1)):
        if M % i == 0:
            x = i
            break
print(x)

Measured memory_bytes: 3060
N,W=map(int,input().split())
DP= [[0 for j in range(W+1)] for i in range(N+1)] 
v=[0]*(N+1) 
w=[0]*(N+1)

for i in range(1,N+1):
    v[i],w[i]=map(int,input().split())

for i in range(1,N+1):
    for j in range(1,W+1):
        if j-w[i]<0:
            DP[i][j]=DP[i-1][j]
        else:
            DP[i][j]=max(DP[i-1][j],DP[i-1][j-w[i]]+v[i])

                    
print(DP[N][W])
    


Measured memory_bytes: 25936
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define endl '\n';
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main() {
    
    vvll v(10,vll(10,0));
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        int r=i%10;
        int t=i;
        while(t>=10)t/=10;
        int l=t;
        v[l][r]++;
    }
    ll ans=0;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            ans+=v[i][j]*v[j][i];
        }
    }
    fin(ans);
    // for(int i=1;i<=9;i++){
    //     for(int j=1;j<=9;j++){
    //         cout<<v[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
}


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

int main(){
    int N,i,j,tmp,*out;
    vector<int> V;
    cin >> N;
    out = new int[N];
    for(i=0;i<N;i++){
        cin >> tmp;
        V.push_back(tmp);
    }
    for(i=0;i<N;i++){
        for(j=N-1-i;j>=0;j--){
            if(V[j]==j+1){
                out[i] = V[j];
                V.erase(V.begin()+j);
                break;
            }
        }
        if(j<0){
            cout << -1 << endl;
            return 0;
        }
    }
    for(i=N-1;i>=0;i--){
        cout << out[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;

void calcZ(char in[], int z[]){
	int l=-1,r=-1;
	for(int i=1;in[i];i++){
		int j=i;
		if(i<=r){
			if(z[i-l]<r-i+1){
				z[i]=z[i-l];
				continue;
			}
			j=r+1;
		}
		while(in[j]==in[j-i]){
			j++;
		}
		z[i]=j-i;
		if(z[i]){
			r=j-1;
			l=i;
		}
	}
}

const int L=5e5+1;
const int L2=2*L;
char s[L];
char t[L];
char st[L2];
char ts[L2];
int zst[L2];
int zts[L2];
int ls;
int lt;
const LL inf=1LL<<60;
LL mst[L2];
LL sst[L2];
LL mts[L2];
LL sts[L2];
LL fts(int i,int f);
LL fst(int i,int f){
	if(sst[i]){
		if(sst[i]==f){
			return inf;
		}
		else{
			return mst[i];
		}
	}
	sst[i]=f;
	int l=zst[i+ls+1];
	if(l==ls){
		mst[i]=min(l+fst((i+l)%lt,f),inf);
	}
	else if(l+i==lt){
		mst[i]=min(l+fts(l,f),inf);
	}
	else{
		mst[i]=l;
	}
	return mst[i];
}
LL fts(int i,int f){
	if(sts[i]){
		if(sts[i]==f){
			return inf;
		}
		else{
			return mts[i];
		}
	}
	sts[i]=f;
	int l=zts[i+lt+1];
	if(l==lt){
		mts[i]=min(l+fts((i+l)%ls,f),inf);
	}
	else if(l+i==ls){
		mts[i]=min(l+fst(l,f),inf);
	}
	else{
		mts[i]=l;
	}
	return mts[i];
}

int main(){
	scanf("%s",s);
	scanf("%s",t);
	ls=strlen(s);
	lt=strlen(t);
	strcpy(st,s);
	st[ls]='.';
	strcpy(st+ls+1,t);
	strcpy(ts,t);
	ts[lt]='.';
	strcpy(ts+lt+1,s);
	calcZ(ts,zts);
	calcZ(st,zst);
	LL m=0;
	for(int i=0;i<ls;i++){
		LL v=fts(i,i+1);
		//cerr << i << ": " << v << endl;
		m=max(m,v);
	}
	if(m>=inf){
		puts("-1");
	}
	else{
		printf("%lld\n",m/lt);
	}


    return 0;
}


Measured memory_bytes: 65280
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  int min;
  string str;
  cin >> str;
  int n;
  n = str.size(); 
  a = 0;
  b = 0;
   
   for(int i = 0; i < n; i++){
    if(str.at(i) == '1'){
      a = a + 1;
    }else{
      b = b + 1;
    }
  }
  
  if(a > b){
      min = b;
  }else{
      min = a;
  }

  cout << min * 2 << endl;
}

Measured memory_bytes: 512
import collections

N = int(input())
S = [input() for i in range(N)]
C = collections.Counter(S)
L = C.most_common()

ans = []
flag = 0

for n in range(len(C)):
    if L[n][1] < flag:
        break
    else:
        ans.append(L[n][0])
        flag = (L[n][1])

ans.sort()

for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 50088
MOD = 10**9+7

X,N = map(int, input().split())
if N == 0:
    print(X)
    quit()

P = sorted(list(map(int, input().split())))

p = []
for i in range(102):
    p.append(i)

for i in range(N):
    p[P[i]] = MOD

tmp = 0
m = MOD
ans = 0
for i in reversed(range(0,102)):
    tmp = abs(X-p[i])
    m = min(tmp,m)
    if m == tmp:
        ans = p[i]

print(ans)


Measured memory_bytes: 9240
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


class fenwick_tree {
	vector<long> t;
	long size;
public:
	fenwick_tree(long n) {
		t.assign(n + 1, 0);
		size = n + 1;
	}

	long LSOne(long k) {	// least significant 1-bit
		return k & (-k);
	}

	void update(long index, long val) {	// can go up or go down
		for (; index < size; index += LSOne(index)) t[index] += val;
	}

	long query_full(long a, long b) {		// range query
		return query(b) - ((a <= 1) ? 0 : query(a - 1));
	}

	long query(long b) {	// range query 1..b
		if (b < 1) return 0;

		long sum = 0;
		for (; b; b -= LSOne(b)) sum += t[b];
		return sum;
	}
};



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

	long long n, i, j, k, ans = 0, x, v;
	cin >> n;

	fenwick_tree ft(n + 1);
	for (i = 0; i < n; i++) {
		cin >> x;
		v = ft.query_full(1, x);
		if (v == 0) ans++;
		ft.update(x, 1);
	}

	cout << ans << "\n";


	return 0;
}


Measured memory_bytes: 1792
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
#define pb push_back
#define fi first
#define se second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int mod = 1e9 + 7;
void solve(){
    int n;
    cin >> n;
    vi a(n + 1);
    for (int i = 1; i <= n; ++i) cin >> a[i];
    int cnt = 0;
    for (int i = 1; i < n; ++i) {
        if (a[i] == i) {
            swap(a[i], a[i + 1]);
            ++cnt;
        }
    }
    if (a[n] == n) cnt++;
    cout << cnt;
}
int main(){
    speed;
    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; ++i) {
        solve();
    }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
 
#define rep(i, n)      for (int i = 0; i < (n); i++)
#define repr(i, n)     for (int i = (n) - 1; i >= 0; i--)
#define repe(i, l, r)  for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r) - 1; i >= (l); i--)
#define repi(i, l, r)  for (int i = (l); i <= (r); i++)
#define repir(i, l, r) for (int i = (r); i >= (l); i--)
#define range(a) a.begin(), a.end()
void init_io() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(15); }
 
using namespace std;
using ll = long long;

int main() { init_io();
  int N; cin >> N;
  vector<int> X(N), Y(N);
  rep(i, N) cin >> X[i] >> Y[i];
  vector<int> perm(N); rep(i, N) perm[i] = i;
  double ans = 0;
  int cnt = 0;
  do {
    double s = 0;
    rep(i, N - 1) {
      double dx = X[perm[i + 1]] - X[perm[i]];
      double dy = Y[perm[i + 1]] - Y[perm[i]];
      s += hypot(dx, dy);
    }
    ans += s;
    cnt++;
  } while (next_permutation(range(perm)));
  cout << ans / cnt << endl;
}


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

#ifdef LOCAL
#include "contest.h"
#else
#define dump(x) 
#endif

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

int main(){
    iostream_init();
    string s;
    cin >> s;
    int n = s.size() / 2;
    for(char c : s) if(c == 'p') n--;
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int N,M;
vector<int> A,B;

vector<int> g[1010];

int dist[1010][1010];
const int INF=1e9;

void dijkstra(int s){
    for(int i=0;i<=N;i++) dist[s][i]=INF;
    dist[s][s]=0;
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> PQ;
    PQ.push(mkp(0,s));
    while(!PQ.empty()){
        auto f=PQ.top();
        PQ.pop();

        int now=f.second;
        int cost=f.first;
        if(dist[s][now]<cost) continue;
        for(auto nex:g[now]){
            if(dist[s][nex]>dist[s][now]+1){
                dist[s][nex]=dist[s][now]+1;
                PQ.push(mkp(dist[s][nex],nex));
            }
        }
    }
}

int main(){
  cin>>N>>M;
  A.resize(M);
  B.resize(M);
  rep(i,M){
      cin>>A[i]>>B[i];
      g[A[i]].push_back(B[i]);
  }

  for(int i=1;i<=N;i++) dijkstra(i);

  int d=INF;
  int a=INF,b=INF;
  for(int i=1;i<=N;i++){
      for(int j=1;j<=N;j++){
          if(i==j) continue;
          if(dist[i][j]<INF&&dist[j][i]<INF){
              if(dist[i][j]+dist[j][i]<d){
                  d=dist[i][j]+dist[j][i];
                  a=i;
                  b=j;
              }
          }
      }
  }

  if(d==INF){
      cout<<"-1"<<endl;
      return 0;
  }

  vector<int> ans;
  int now=a;
  while(now!=b){
      for(auto nex:g[now]){
          if(dist[nex][b]==dist[now][b]-1){
              now=nex;
              break;
          }
      }
      ans.push_back(now);
  }

  while(now!=a){
      for(auto nex:g[now]){
          if(dist[nex][a]==dist[now][a]-1){
              now=nex;
              break;
          }
      }
      ans.push_back(now);
  }

  cout<<ans.size()<<endl;
  for(auto p:ans) cout<<p<<endl;

  return 0;
}


Measured memory_bytes: 4224
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc;

	static final int INF=1<<28;
	static final double EPS=1e-9;

	void run(){
		sc=new Scanner(System.in);
		int n=sc.nextInt();
		sc.nextLine();
		for(int i=0; i<n; i++){
			String s=sc.nextLine();
			println(dec(s));
		}
		sc.close();
	}

	String dec(String s){
		for(int a=0; a<26; a++){
			if(a%2==0||a%13==0)
				continue;
			for(int b=0; b<26; b++){
				String t="";
				for(char c : s.toCharArray()){
					if(Character.isLowerCase(c))
						c=(char)((a*(c-'a')+b)%26+'a');
					t+=c;
				}
				if(t.contains("that")||t.contains("this"))
					return t;
			}
		}

		return null;
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

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

Measured memory_bytes: 12000
"""
NTC here
"""
 

#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase

def iin(): return int(input())
 
 
def lin(): return list(map(int, input().split()))

def main():
    T = 1
    while T:
        T-=1
        n, m = lin()
        a = lin()
        sm = sum(a)
        print(max(-1, n-sm))

        
        








# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

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

using namespace std;
using ll = long long;

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

    int a, b, h; cin >> a >> b >> h;
    cout << ((a+b)*h)/2;

    return 0;
}


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

int main(){
    string s;
    int i,a,b,f=1;
    cin>>a>>b;
    cin>>s;
    
    for(i=0;i<a;i++){
        if(s[i]>'9'||s[i]<'0'){
            f=0;
            break;
        }
    } 
    if(s[a]!='-') f=0;
    for(i=a+1;i<s.size();i++){
        if(s[i]>'9'||s[i]<'0'){
            f=0;
            break;
        }
    }
    if(f==1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 32);
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/


int main() {
    cin >> n >> m >> k;
    vi v(n);
    REP(i,n) {
        cin >> v[i];
    }
    if(n==1){
        cout << abs(k - v[0]) << endl;
    }else{
        cout << max(abs(v.back() - k), abs(v.back() - v[v.size() - 2])) << endl;
    }
}

Measured memory_bytes: 256
N = int(input())
a = [int(input()) for i in range(N)]
count = 0
hantei = 0
s = a[0]

while count < N :
    if s == 2 :
        print(count + 1)
        hantei = 1
        break
    else :
        s = a[s - 1]
        count += 1

if hantei == 0 :
    print(-1)

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

using namespace std;

int n, ans, f[1000000], w[1000000], e[1000000];
string s;

int main(){
    cin >> n >> s;
    e[1] = 0;
    for (int i = 1; i < n; i++) e[i] = e[i-1] + ((s[i-1] == 'W') ? 1 : 0);
    w[n-1] = 0;
    for (int i = n - 2; i >= 0; i--) w[i] = w[i+1] + ((s[i+1] == 'E') ? 1 : 0);
    ans = 1e9;
    for (int i = 0; i < n; i++) {
        //cout << e[i]<<" "<< w[i] << " " << e[i] + w[i] <<endl; 
        ans = min(ans, e[i] + w[i]);
    }
    cout << ans;
}

Measured memory_bytes: 5892
#include<bits/stdc++.h>
#define ll long long
#define foi(a,n) for(int i = a; i < (int)n; i++)
#define foj(a,n) for(int j = a; j < (int)n; j++)
#define pb(a) push_back(a)
#define ln '\n'
#define fastio 	ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define cases int tests; cin >> tests; while(tests--)
using namespace std;

int main(){
	fastio;
	ll n, m, p;
	//~ cases
	{	
		cin >> n;
		if(n >= 30) cout << "Yes";
		else cout << "No";
		
		
	}
}


Measured memory_bytes: 3608
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <cassert>
using namespace std;

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

int main(){
    long long A, B, C, D;
    cin >> A >> B >> C >> D;
    long long X = B/C - (A-1)/C;
    long long Y = B/D - (A-1)/D;
    long long E = C*D/gcd(C, D);
    long long Z = B/E - (A-1)/E;
    cout << B-A+1-(X+Y-Z) << endl;

    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict

MOD = 1000000007


def main():
    n, m = list(map(int, input().split()))
    stairs = defaultdict(lambda: True)
    for i in range(m):
        a = int(input())
        stairs[a] = False

    dp = defaultdict(lambda: 0)
    dp[0] = 1

    for i in range(1, n + 1):
        if stairs[i]:
            dp[i] = dp[i - 1] + dp[i - 2]
            dp[i] %= MOD

    print(dp[n])


main()

Measured memory_bytes: 24520
/**
 *      ABC 112 D
 *      author  : kyomukyomupurin
 *      created : 2018-10-06 21:18:38
**/

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N, M; cin >> N >> M;
    int pos = M / N;

    while (1){
        if (M % pos == 0){
            cout << pos << '\n'; return 0;
        }
        else {
            --pos;
        }
    }
    
    return 0;
}

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

int main()
{
    string s,cmd;
    int n;
    cin>>n;
    set<string> str;
    for(int i=0;i<n;i++)
    {
        cin>>cmd>>s;
        if(cmd=="insert")
        {
            str.insert(s);
        }
        else if(cmd=="find")
        {
            if(str.find(s)!=str.end())
            {
                cout<<"yes"<<endl;
            }
            else cout<<"no"<<endl;
        }
    }

    return 0;
}


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

using namespace std;

#define endl "\n"


int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  if ((a == b && a != c && b != c)|| (b == c && a != b && a != c) || (a == c && b != c && b!= a))
    cout << "Yes" << endl;
  else 
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

int main() {
  string t;
  cin >> t;
  i64 N = t.size();
  rep(i,0,N) {
    if(t[i] == '?') {
      t[i] = 'D';
    }
  }
  cout << t << endl;
}


Measured memory_bytes: 3724