akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

int main(){
   int N, M;
   std::cin >> N >> M;
   std::vector<int> L(M);
   std::vector<int> R(M);
   for (int i=0; i<M; i++){
      std::cin >> L.at(i) >> R.at(i);
   }
   int L_max = 0;
   int R_min = 100000;
   for (int i=0; i<M; i++){
      if (L.at(i) > L_max){
         L_max = L.at(i);
      }
      if (R.at(i) < R_min){
         R_min = R.at(i);
      }
   }
   if (R_min - L_max < 0)
      std::cout << 0 << std::endl;
   else
      std::cout << R_min-L_max+1 << std::endl;

}



Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
bool solve(ll n) 
{ 
    if (n == 0 || n == 9) 
        return true; 
    if (n < 9) 
        return false; 
  
    // (n/9) - n%8]
    return solve((ll)(n >> 3) - (ll)(n & 7)); 
} 
int main(){
    long long n;
    cin >> n;
  	//for element
    vector<long long> v(n);
    for(int i = 0; i < n; ++i){
	        cin >> v[i];
	    }
	   
	    long long currmaxforarry = v[0];
   long long ff = 0;
	    for(int i = 1; i < n; ++i){
	        if(currmaxforarry > v[i]){
	            ff += (currmaxforarry - v[i]);
	        }
          //update curr max
	        currmaxforarry = max({currmaxforarry,v[i],v[i-1]});
	    }
	    cout << ff << endl;
    return 0;
}


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

int i,c;

int area(int d) {
    int sum=0;
   for (i=d; i<=600-d ;i+=d){
        c=d*i*i;
        sum=sum+c;
    }
    return sum;
}

int main(void){
    int d;
    while(cin >> d){
    cout << area(d) <<endl;
    }
    return 0;
}



Measured memory_bytes: 2992
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define print(v) for(auto &z:v) cout<<z<<' ';cout<<'\n'
#define hi cout<<'h'<<'i'<<'\n' 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define all(v) v.B,v.E
#define sz(v) (int)((v).size())
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define clk1 clock_t start_time=clock()
#define clk2 cout<<(clock()-start_time)/(double)CLOCKS_PER_SEC
#define clean(arr) memset(arr,0,sizeof(arr))
#define mod 1000000007
#define mod2 998244353
#define space 100005
//<<fixed << setprecision(9)

int main()
{
    int n,i,j,t;
    boost;
    int k,a,b;
    cin>>k;
    cin>>a>>b;
    bool ok=0;
    rep(i,a,b+1)
    {
        if(i%k==0)ok=1;
    }
    if(ok)cout<<"OK";
    else cout<<"NG";
    return 0;
}



Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
int a[105][105];
int main()
{
	int m,n;
	char s;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			cin>>s;
			if(s=='#')
			{
				a[i][j]=-100000000;
				a[i][j-1]++;
				a[i][j+1]++;
				
				a[i-1][j+1]++;
				a[i-1][j-1]++;
				a[i-1][j]++;
				
				a[i+1][j-1]++;
				a[i+1][j]++;
				a[i+1][j+1]++;
				
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		if(a[i][j]>=0) cout<<a[i][j];
		else cout<<"#";
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <math.h>
#include <time.h>
#include <bitset>
#include <stdio.h>
#include <stdlib.h>
#include <iomanip>
#include <iostream>
#include <string.h>
#include <algorithm>
using  namespace  std;

#define ff first
#define ss second
#define pb push_back
#define ll long long
#define ull unsigned long long
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define mst(ss,b) memset(ss,b,sizeof(ss));
#define dbg(x) cout << #x << "= " << x << endl;
typedef pair <int, int> pii;
const int inf = 0x3f3f3f3f;
const ll INF = (1LL<<62)-1;
const ll mod = 1e9+7;
const int N = 4000+5;

char s1[N], s2[N];
int n, m;
ull p[30], h1[N][N], h2[N][N];

void calc(int n, ull hx[][N], char *s){
    for(int i=1; i<=n; i++){
        ull h = 0;
        for(int j=i; j<=n; j++)h += p[s[j]-'a'], hx[j-i+1][i] = h;
    }
}

void go(){
    int ans = 0;
    calc(n, h1, s1);
    calc(m, h2, s2);
    int len = min(n, m);
    for(int i=1; i<=n; i++)sort(h1[i]+1, h1[i]+2+n-i);
    for(int i=1; i<=m; i++)sort(h2[i]+1, h2[i]+2+m-i);
    for(int i=1; i<=len; i++){
        for(int j=1; j+i-1<=n; j++){
            int pos = lower_bound(h2[i]+1, h2[i]+2+m-i, h1[i][j])-h2[i];
            if(h2[i][pos] == h1[i][j])ans = max(ans, i);
        }
    }
    printf("%d\n", ans);
}

int  main(){
    scanf("%s%s", s1+1, s2+1);
    n = strlen(s1+1), m = strlen(s2+1);
    p[0] = 1;
    for(int i=1; i<30; i++)p[i] = p[i-1]*233;
    go();
    return 0;
}


// lower_bound()
// __builtin_popcount()
// ios::sync_with_stdio(false);
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
// const double eps=1e-12;
// #pragma comment(linker,"/STACK:102400000,102400000")

Measured memory_bytes: 158228
//#pragma comment(linker,"/STACK:102400000,102400000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<cstdlib>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<map>
#include<vector>
#include<algorithm>
#define sf scanf
#define pf printf
#define cls(a) memset(a,0,sizeof a)
#define _cls(a) memset(a,-1,sizeof a)

using namespace std;
typedef long long LL;

string str;
int org[100100];

int ok(int now){
	int i,cnt=0;
	now^=1;
	for(i=0;i<str.size()-1;++i){
		now^=1;
		if(str[i]==str[i+1]) {now^=1;cnt++;continue;}
		if(str[i]=='1'){
			if(!now)
				continue;
			if(str[i+1]!='4' && str[i+1]!='7') cnt++,now^=1;
		}else if(str[i]=='2'){
			if(now){//right
				if(str[i+1]=='3' || str[i+1]=='6' || str[i+1]=='9') cnt++,now^=1;
			}else{
				if(str[i+1]=='1' || str[i+1]=='4' || str[i+1]=='7') cnt++,now^=1;
			}
		}else if(str[i]=='3'){
			if(now) continue;
			if(str[i+1]!='6' && str[i+1]!='9') cnt++,now^=1;
		}else if(str[i]=='4'){
			if(!now) continue;
			if(str[i+1]!='1' && str[i+1]!='7') cnt++,now^=1;
		}else if(str[i]=='6'){
			if(now) continue;
			if(str[i+1]!='3' && str[i+1]!='9') cnt++,now^=1;
		}else if(str[i]=='7'){
			if(!now) continue;
			if(str[i+1]!='1' && str[i+1]!='4') cnt++,now^=1;
		}else if(str[i]=='8'){
			if(now){//right
				if(str[i+1]=='3' || str[i+1]=='6' || str[i+1]=='9') cnt++,now^=1;
			}else{
				if(str[i+1]=='1' || str[i+1]=='4' || str[i+1]=='7') cnt++,now^=1;
			}
		}else if(str[i]=='9'){
			if(now) continue;
			if(str[i+1]!='3' && str[i+1]!='6') cnt++,now^=1;
		}
	}
	return cnt;
}

int main(){
	int i,cnt,j;
	while(cin>>str,str!="#"){
		int ret=ok(1);
		int res=ok(0);
		pf("%d\n",min(ret,res));
	}
	return 0;
}

Measured memory_bytes: 1328
/*|In The Name Of Allah|*/
//This Month Will Be Expert ISA
#include <bits/stdc++.h>

using namespace std;

const int N = 1e6+7;

const int mod = 1e9+7;

int n;
int ar[N];

vector < int > primeFactors(long long num){
    vector < int > prm;
    while (num % 2 == 0){
        prm.push_back(2);
        num = num/2;
    }
    for (long long i = 3; i*i <= num; i = i + 2){
        while (num % i == 0){
            prm.push_back(i);
            num = num/i;
        }
    }
    if (num > 2)
        prm.push_back(num);
    return prm;
}

int mxF[N];

int fastP(int b, int e){
    if(!e)
        return 1;
    if(e & 1)
        return b * 1ll * fastP(b * 1ll * b % mod, e >> 1) % mod;
    return fastP(b * 1ll * b % mod, e >> 1) % mod;
}

int main(){
    scanf("%d" , &n);
    for(int i = 1; i <= n; i++){
        scanf("%d" , &ar[i]);
        map < int , int > cntF;
        vector < int > prmF = primeFactors(ar[i]);
        for(auto v : prmF){
            cntF[v]++;
        }
        for(auto v : cntF){
            mxF[v.first] = max(mxF[v.first] , v.second);
        }
    }
    int sum = 0;
    long long LCM = 1;
    for(int i = 1; i <= 1e6; i++){
        while(mxF[i]--){
            LCM = LCM * i % mod;
        }
    }
    for(int i = 1; i <= n; i++){
        sum = (sum + LCM * fastP(ar[i] , mod - 2)) % mod;
    }
    printf("%d\n" , sum);
}

Measured memory_bytes: 4352
import sys
a, b, c, d = map(int, input().split())

def ans(a):
    if a < 0:
        print(0) 
    else:
        print(a)

if a < c:
    if c < b:
        if b < d:
            ans(b-c)
        else:
            ans(d-c)
    else:
        ans(0)
else:
    if a < d:
        if d < b:
            ans(d-a)
        else:
            ans(b-a)
    else:
        ans(0)

sys.exit(0)


Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
import sys

def io_generator():
	while True:
		yield raw_input()

#+++++++++++++++++++

def main(io):
	a,b= map(int, io.next().split())
	if b%a==0:
		return a+b
	else:
		return b-a

#++++++++++++++++++++

if __name__ == "__main__":
	io=io_generator()
	print main(io)


Measured memory_bytes: 2568
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define INF 2000000000  //int型は2 * 10^9ぐらいまで
#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

   int n, a[100], ans = 0;
   cin >> n;
   REP(i, n) cin >> a[i];

   int p = 0, k = a[0];
   REP(i, n){
      if(a[i] == k) p++;
      else{
         k = a[i];
         ans += p / 2;
         p = 1;
      }
   }
   ans += p / 2;
   cout << ans << endl;
   rtn 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import numpy as np

n,m = map(int, input().split())
graph = [[0 for i in range(n)] for j in range(n)]
graph = np.array(graph)

for i in range(m):
    a,b = map(int, input().split())
    graph[a-1,b-1] = 1
    graph[b-1,a-1] = 1

used = [False]*n
used[0] = True

def DFS(v,used):
    global ans
    if all(used):
        ans += 1
        return 
    for i in range(n):
        if used[i]:
            continue
        if graph[i,v] == 0:
            continue
        used[i] = True
        DFS(i,used)
        used[i] = False
    return

ans = 0
DFS(0,used)

print(ans)

Measured memory_bytes: 12444
sx,sy,tx,ty=map(int,input().split())
ans=''
for i in range(ty-sy):
  ans+='U'
for i in range(tx-sx):
  ans+='R'
for i in range(ty-sy):
  ans+='D'
for i in range(tx-sx):
  ans+='L'
ans+='L'
for i in range(ty-sy+1):
  ans+='U'
for i in range(tx-sx+1):
  ans+='R'
ans+='D'
ans+='R'
for i in range(ty-sy+1):
  ans+='D'
for i in range(tx-sx+1):
  ans+='L'
ans+='U'
print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
signed main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int a,b;
  for(int i=0;i<7;i++){
    cin>>a>>b;
    cout<<a-b<<'\n';
  }
  return(0);
}



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

using namespace std;

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

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

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int n, k;
	cin >> n >> k;
	vector<int> cnt(n);
	rep (i, k) {
	  int d;
	  cin >> d;
	  rep (j, d) {
		int a;
		cin >> a;
		cnt[a - 1]++;
	  }
	}
	int res = 0;
	rep (i, n) res += !cnt[i];
	cout << res << endl;
    
    return 0;
}


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

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

Measured memory_bytes: 3592
#include<iostream>
using namespace std;
char a[4];
int main()
{
	for(int i=0;i<4;i++)
	{
		cin>>a[i];
	}
	if(a[0]==a[1])
	{
		if(a[1]==a[2]||(a[2]==a[1]&&a[2]==a[3]))
		{
			cout<<"Yes"<<endl;
			return 0;
		}
		else
		{
			cout<<"No"<<endl;
			return 0;
		}
	} 
	if(a[3]==a[2])
	{
		if(a[2]==a[1]||(a[1]==a[0]&&a[1]==a[2]))
		{
			cout<<"Yes"<<endl;
			return 0;
		}
		else
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl; 
	return 0;
}
 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>

using namespace std;


int main(){
   string s;
   cin>>s;
   int n=0;
   int m=0;
   for(int i=0;i<s.size();i++){
      if(s[i]=='1')n++;
      else m++;
   }
   cout<<min(n,m)*2<<endl;
}

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

int main(){
	int n;
	cin >> n;
	int d[n], max = -1;
	for(int i = 0; i < n; i++){
		cin >> d[i];
		max = max < d[i] ? d[i] : max;
	}
	
	vector<int> pr;
	pr.push_back(2);
	for(int i = 3; i <= sqrt(max); i++){
		for(int j = 0; j < pr.size() && pr[j] <= sqrt(i); j++){
			if(i % pr[j] == 0) goto BREAK;
		}
		pr.push_back(i);
		BREAK:;
	}
	int cnt = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < pr.size() && pr[j] <= sqrt(d[i]); j++){
			if(d[i] % pr[j] == 0) goto BREAK2;
		}
		cnt++;
		BREAK2:;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1268
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>

#define int long long
using namespace std;
const int Mod = 998244353;

//R G B RG RB GR GB BR BG
int32_t main(){

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

    int n;
    cin>>n;

    string s;
    cin>>s;

    unordered_map<string,int> mp;
    int ans = 1;
    mp["-"] = n;
    for(auto ch : s){
        int c = 0;
        if(ch=='R'){
            if(mp["GB"]) c+=mp["GB"]--;
            if(mp["BG"]) {
                if(!c)c+=mp["BG"]--;
                else c+=mp["BG"];
            }
            if(c){
                ans = ans*c%Mod;
                continue;
            }
            if(mp["G"]) c+=mp["G"]--,mp["GR"]++;
            if(mp["B"]) {
                if(!c) c+=mp["B"]--,mp["BR"]++;
                else c+=mp["B"];
            }
            if(c){
                ans = ans*c%Mod;
                continue;
            }
            if(mp["-"]) c+=mp["-"]--,mp["R"]++;   
            if(c){
                ans = ans*c%Mod;
                continue;
            }         
        }
        if(ch=='G'){
            if(mp["RB"]) c+=mp["RB"]--;
            if(mp["BR"]) {
                if(!c)c+=mp["BR"]--;
                else c+=mp["BR"];
            }
            if(c){
                ans = ans*c%Mod;
                continue;
            }
            if(mp["R"]) c+=mp["R"]--,mp["RG"]++;
            if(mp["B"]) {
                if(!c)mp["BG"]++,c+=mp["B"]--;
                else c+=mp["B"];
            }
            if(c){
                ans = ans*c%Mod;
                continue;
            }
            if(mp["-"]) c+=mp["-"]--,mp["G"]++;   
            if(c){
                ans = ans*c%Mod;
                continue;
            }         
        }
        if(ch=='B'){
            if(mp["GR"]) c+=mp["GR"]--;
            if(mp["RG"]) {
                if(!c)c+=mp["RG"]--;
                else c+=mp["RG"];
            }
            if(c){
                ans = ans*c%Mod;
                continue;
            }
            if(mp["R"]) c+=mp["R"]--,mp["RB"]++;
            if(mp["G"]) {
                if(!c) mp["GB"]++,c+=mp["G"]--;
                else c+=mp["G"];
            }
            if(c){
                ans = ans*c%Mod;
                continue;
            }
            if(mp["-"]) c+=mp["-"]--,mp["B"]++;   
            if(c){
                ans = ans*c%Mod;
                continue;
            }         
        }
    }

    cout<<ans<<endl;

    return 0;
}

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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

// clang-format off
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
// clang-format on

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vec>;

template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) {
    return stream << p.first << " " << p.second;
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}
template <typename T>
T sum_(vector<T> vec, T init = 0) {
    return std::accumulate(all(vec), T(init));
}

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

template <typename T>
void init(vector<T>& v) {
    rep (i, v.size())
        cin >> v[i];
}

template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) {
    assert(v.size() == w.size());
    rep (i, v.size())
        cin >> v[i] >> w[i];
}

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

// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vec a(n + 1);
    init(a);
    vec b(n);
    init(b);
    b.pb(0);

    int ans = 0;
    int carry = 0;
    rep (i, n + 1) {
        ans += min(a[i], b[i] + carry);
        carry = min(max(0LL, b[i] + carry - a[i]), b[i]);
    }
    print(ans);

    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define INF 2147483647
#define SYOU(x) setprecision(x)
using namespace std;
long long i[300000];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e=1,f=0;
  cin >>a>>b>>c>>d;
  if(a>b){
    a=a-b,b=b*c,a=a*d;
    cout <<b+a<<'\n';
  }
  else cout <<a*c<<'\n';
  return (0);
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl
#define MAX_N 100006
#define all(x) x.begin(),x.end()
typedef pair<int,int> P;
typedef pair<int,P> PP;

int n,m;
int k[100000];
int par[MAX_N];
int rrank[MAX_N];
void init(int nn)
{
	rep(i,nn)
	{
		par[i]=i;
		rrank[i]=0;
	}
}
int find(int x)
{
	if(par[x]==x)return x;
	else return par[x]=find(par[x]);
}
void unite(int x,int y)
{
	x=find(x);
	y=find(y);
	if(x==y) return;
	if(rrank[x]<rrank[y])par[x]=y;
	else{
		par[y]=x;
		if(rrank[x]==rrank[y])rrank[x]++;
	}
}
bool same(int x,int y)
{
	return find(x)==find(y);
}
vector<int> h[100000];
int hai[100000];
int main()
{
	
	cin>>n>>m;
	init(n);
	rep(i,n)
	{
		cin>>k[i];
		rep(j,k[i])
		{
			cin>>hai[j];
			hai[j]--;
			h[hai[j]].push_back(i);
		}
	}
	rep(i,m)
	{
		int kk=h[i].size();
		rep(j,kk-1)
		{
			unite(h[i][j],h[i][j+1]);
		}
	}
	//rep(i,n)cout<<
	rep(i,n-1)
	{
		
		if(!same(i,i+1))
		{
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    const int A = 26;
    int D; cin >> D;
    vector<int> c(A);
    REP(i,A) cin >> c[i];
    vector<vector<int>> s(D,vector<int>(A));
    REP(i,D) REP(j,A) cin >> s[i][j];

    vector<int> last(A,-1);
    int score = 0;
    REP(i,D) {
        int a; cin >> a;
        a--;
        score += s[i][a];
        last[a] = i;
        REP(j,A) {
            score -= c[j]* (i-last[j]);
        }
        OUT(score);
    }
    
    return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> h(n-1);
    int b, ans = 0, cnt = 0;
    cin >> b;
    rep(i,n-1){
        cin >> h[i];
        if(b >= h[i]){
            ++cnt;
            b = h[i];
        }
        else{
            cnt = 0;
            b = h[i];
        }
        chmax(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3688
#include <stdio.h>
int main()
{
  long long n ;
  scanf("%lld",&n);

  long long max = -1000001 ;
  long long min  = 1000001 ;
  long long ai ;
  long long sum = 0 ;

  for(int i=1 ; i<=n ; i++){
    scanf("%lld",&ai);
    sum += ai ;
    if (max < ai) {
      max = ai;
    } else {
      max += 0 ;
    }
    if (min > ai) {
      min = ai;
    } else {
      min += 0 ;
    }
  }

  printf("%lld %lld %lld\n", min, max, sum);

  return 0;
}


Measured memory_bytes: 2092
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
signed main(){
  int a,b;cin>>a>>b;
  string s;cin>>s;
  bool flag=true;
  rep(i,a+b+1){
    if(i>=0&&i<a){
      if(s[i]=='-')flag=false;
    }
    if(i==a)if(s[i]!='-')flag=false;
    if(i>a)if(s[i]=='-')flag=false;
  }
  if(flag){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}


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

using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;

void solve() {
	int n;
	cin >> n;
	vector<ll> a(n);
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
		sum %= mod;
	}
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		sum -= a[i];
		sum += mod;
		sum %= mod;
		ans += (a[i] * sum) % mod;
		ans %= mod;
	}
	cout << ans;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		cout << endl;
	}
}

Measured memory_bytes: 4780
#include <stdio.h>

int main() {
  int a,b,c;
  scanf("%d %d %d\n",&a,&b,&c);

 if (a<b) {
   if (b<c) {
     printf("Yes\n");
   }
   else{
     printf("No\n" );
   }
 }
  else{
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 2060
#include <bits/stdc++.h>
#define rep(i, l, r) for(register int i = l; i < r; i++)
#define hrp(i, l, r) for(register int i = l; i <= r; i++)
#define rev(i, r, l) for(register int i = r; i >= l; i--)
#define pb push_back
#define int ll
#ifndef JOEON
#define D(...)
#define R(x, l)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn> inline tn next(void);
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v);
signed main(void)
{
	#ifdef JOEON
//		freopen("C:\Users\Joeon\Desktop\IN.txt", "r", stdin);
//		freopen("C:\Users\Joeon\Desktop\OUT.txt", "w", stdout);
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	string str = next<string>();
	if (str == "ABC") cout<<"ARC"<<endl;
	else cout<<"ABC"<<endl;
	return 0;
}
template<typename tn> inline tn next(void)
{
	tn k;
	cin>>k;
	return k;
}
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v)
{
	rep(i, 0, v.size()) os<<v[i]<<' ';
	return os;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
//#include "graph.cpp"
#define ll long long
#define loop(i,n) for(int i=0 ; i<n ; ++i)
#define rep(i,x,n) for(int i=x ; i<=n ; ++i)
#define iteloop(type,data,name,it) for(type<data>::iterator it=name.begin() ;it!=name.end() ; ++it)
#define getOpp(x) (x^2)
#define NOT(x) (x^1)
using namespace std;
using namespace __gnu_pbds;

typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_set;
const int N=25;
int n;
int val[N] , cost[N];
int main(){
    cin.sync_with_stdio(false), cin.tie(0) , cout.tie(0);
    cin>>n;
    int res=0;
    loop(i,n){
        cin>>val[i];
    }
    loop(i,n){
        cin>>cost[i];
        if(val[i]>cost[i]){
            res+=val[i]-cost[i];
        }
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
using namespace std;

typedef long long ll;
const int MAXN=1e6+5;

int n,m;
bool vis[MAXN];
vector<int>edge[MAXN];
queue<int>q;
map<int,int>f[MAXN];
int d[MAXN];
int fa[MAXN];

int find(int x){
    if(x==fa[x]) return x;
    return fa[x]=find(fa[x]);
}

void bfs(){
    memset(d,-1,sizeof d);
    q.push(1); vis[1]=1; d[1]=0;
    while(!q.empty()){
        int u=q.front();
        q.pop();
        for(int i=0,sz=edge[u].size();i<sz;i++){
            int v=edge[u][i];
            v=find(v);
            if(!vis[v]){
                d[v]=d[u]+1;
                q.push(v);
                vis[v]=1;
            }
        }
    }
}

int main(){
    int cnt=0;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        f[i][0]=++cnt;
    for(int i=1;i<MAXN;i++)
        fa[i]=i;
    for(int i=1;i<=m;i++){
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        if(f[u][w]==0){
            f[u][w]=++cnt;
            edge[u].push_back(cnt);
            edge[cnt].push_back(u);
        }
        u=f[u][w];
        u=find(u);
        if(f[v][w]==0){
            f[v][w]=++cnt;
            edge[v].push_back(cnt);
            edge[cnt].push_back(v);
        }
        v=f[v][w];
        v=find(v);
        fa[find(u)]=find(v);
    }
    map<int,int>::iterator it;
    for(int i=1;i<=n;i++)
        for(it=f[i].begin();it!=f[i].end();it++){
            int j=it->second;
            j=find(j);
            edge[i].push_back(j);
            edge[j].push_back(i);
        }
    bfs();
    if(d[n]==-1)  puts("-1");
    else printf("%d\n",d[n]/2);
}


Measured memory_bytes: 123904
#include "bits/stdc++.h"
using namespace std;

#define ll long long int
#define str string
#define ALL(a)  (a).begin(),(a).end()
#define P pair<ll,ll>

using Graph = vector<vector<int>>;

const int dy[] = { 0, 0, 1, -1 }, dx[] = { 1, -1, 0, 0 };
ll INFL = 1ll << 60, INF = 1 << 30, mod = 1e9 + 7, Min = INFL, Max = -1;
ll a, b, c, n, sum, A[500010], B[500000], rui[500000], dp[5000];
str S,T; bool check = true;	vector<ll> v;



int main() {
	//Code Line
cin >> n;
cin >> S >> T;

for(int i = 0;i < n;i++){
cout << S[i] << T[i];
}


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }


void solve(long long N, long long X, std::vector<long long> L){
	ll res = 1;
	ll sum = 0;
	REP(i, N) {
		sum += L[i];
		if (sum <= X) res++;
	}
	cout << res << "\n";
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long X;
    scanf("%lld",&X);
    std::vector<long long> L(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&L[i]);
    }
    solve(N, X, std::move(L));
    return 0;
}


Measured memory_bytes: 256
/**
 * Princess's Gamble
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			StringTokenizer st = new StringTokenizer(line);
			int n, m, p;
			n = parseInt(st.nextToken());
			m = parseInt(st.nextToken());
			p = parseInt(st.nextToken());
			if ((n | m | p) == 0) break;

			int[] bets = new int[n];
			int total = 0;
			for (int i = 0; i < n; i++) {
				bets[i] += parseInt(br.readLine());
				total += bets[i];
			}

			if (bets[m - 1] == 0) {
				System.out.println("0");
			} else {
				int dividend = total * (100 - p) / bets[m - 1];
				System.out.println(dividend);
			}
		} //end while
	} //end main
}

Measured memory_bytes: 22216
#include <cstdio>
using namespace std;


int main(){
    int n,tmp;
    int L[3];

    scanf("%d %d %d",&L[0],&L[1],&L[2]);

    if(L[0]>=L[1]){
        tmp=L[0];
        L[0]=L[1];
        L[1]=tmp;
    }
    if(L[0]>=L[2]){
        tmp=L[0];
        L[0]=L[2];
        L[2]=tmp;
    }
    if(L[1]>=L[2]){
        tmp=L[1];
        L[1]=L[2];
        L[2]=tmp;
    }

    if((L[1]-L[0])%2==0){
        n=(L[1]-L[0])/2 + (L[2]-L[1]);
    }else{
        n=1+(L[1]+1-L[0])/2 + (L[2]-L[1]);
    }

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

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

namespace Volume27_2745
{
    class Program
    {
        static void Main(string[] args)
        {
            Cooking cooking = new Cooking();
            string input;
            while (!(input = Console.ReadLine()).StartsWith("0 0"))
            {
                int currRue = int.Parse(input.Split(' ').ToArray()[0]);
                int currWater = int.Parse(input.Split(' ').ToArray()[1]);
                int idealConce = int.Parse(input.Split(' ').ToArray()[2]);
                int weightRue = int.Parse(input.Split(' ').ToArray()[3]);
                Console.WriteLine(cooking.NeedCurryRue(currRue, currWater, idealConce, weightRue));
            }
        }
    }
    class Cooking
    {
        internal int NeedCurryRue(int currRue, int currWater, int idealConce, int weightRue)
        {
            int numOfRue = 0;
            while (currWater * idealConce > currRue)
            {
                numOfRue += 1;
                currRue += weightRue;
            }
            return numOfRue;
        }
    }
}



Measured memory_bytes: 16988
N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

flag = False
cnt = 0
Z = [i for i in range(X + 1, Y + 1)]
for z in Z:
    if max(x) < z and z <= min(y):
        flag = True
        break

if flag:
    print("No War")
else:
    print("War")


Measured memory_bytes: 3060
import sys
h,w = map(int,raw_input().split())

arr = []

for i in range(h):
	arr.append(list(raw_input()))

field = [['.' for i in range(w)] for j in range(h)]

direct = [[0,-1],[1,0],[0,1],[-1,0]]

for i in range(h):
	for j in range(w):
		for k in range(4):
			dx = j + direct[k][1] 
			dy = i + direct[k][0]
			if -1 < dx and dx < w and -1 < dy and dy < h :
				if arr[i][j] == '#' and arr[dy][dx] == '#':
					field[i][j] = '#'
					field[dy][dx] = '#'

for i in range(h):
	for j in range(w):
		if arr[i][j] != field[i][j]:
			print 'No'
			sys.exit()

print 'Yes'


Measured memory_bytes: 2696
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int a[10],b[10];

int main(){
	for(int i=0;i<10;i++)cin>>a[i];
	for(int i=0;i<10;i++)cin>>b[i];
	sort(a,a+10);
	sort(b,b+10);
	cout<<a[7]+a[8]+a[9]<<" "<<b[7]+b[8]+b[9]<<endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int &e : A) cin >> e;
  vector<int> B = A;
  sort(B.rbegin(), B.rend());
  
  for (int i = 0; i < N; i++) {
    if (A[i] == B[0]) cout << B[1] << endl;
    else cout << B[0] << endl;
  }
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
/*
    By: Umang Srivastava
*/
#define lli long long int
#define ld long double
#define mod 1000000007
#define lp(var,start,end,inc) for (var = start; var <end ; var=var+inc)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<lli>
#define pll pair<lli,lli> 
#define vpll vector<plli>
#define max(a,b) a>b?a:b
#define min(a,b) a<b?a:b

lli c=0;
lli n;
vector<lli>graph[200000];
int vis[200000]={0};
void dfs(lli v)
{
    if(vis[v]==1)
        return;
    vis[v]=1;
    c++;
    for(lli u=0;u<graph[v].size();u++)
    {
        dfs(graph[v][u]);
    }
}


int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    lli m,s=0,i,a,b,ans=0;
    cin>>n>>m;
    for(i=0;i<m;i++)
    {
        cin>>a>>b;
        graph[(a-1)].pb((b-1));
        graph[(b-1)].pb((a-1));
    }
    vector<lli>::iterator ip;
    for(i=0;i<n;i++)
    {
        ip = unique(graph[i].begin(),graph[i].end());
        graph[i].resize(distance(graph[i].begin(),ip));
    }

    for(i=0;i<n;i++)
    {
        c=0;
        dfs(i);
        ans=max(ans,c);
    }
    cout<<ans;
}

Measured memory_bytes: 21624
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

int main()
{
  string day;
  cin >> day;
  const char mon[2] = {day[5], day[6]};
  if(atoi(mon) < 5)
  {
    cout << "Heisei" << endl;
  }
  else
  {
    cout << "TBD" << endl;
  }
  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef pair<double,double> PD;
typedef pair<int,P> ed;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N,K;
  cin >> N >> K;
  vp pos(N);
  rep(i,N) {
    cin >> pos[i].first >> pos[i].second;
  }
  ll ans = LONG_LONG_MAX;
  rep(wl,N) {
    srep(wr,wl+1,N) {
      rep(hl,N) {
        srep(hr,hl+1,N) {
          ll wlp = pos[wl].first;
          ll wrp = pos[wr].first;
          ll hlp = pos[hl].second;
          ll hrp = pos[hr].second;
          if(wlp>wrp) swap(wlp,wrp);
          if(hlp>hrp) swap(hlp,hrp);
          int cnt = 0;
          rep(i,N) {
            if(wlp<=pos[i].first  && pos[i].first <=wrp &&
               hlp<=pos[i].second && pos[i].second<=hrp) {
                 cnt++;
            }
          }
          if(cnt>=K) {
            chmin(ans,(wrp-wlp)*(hrp-hlp));
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int N;
vector<Int> s;

int main(void) {
    cin>>N;

    for(int i = 0;i < N;i++) {
        Int x;
        cin>>x;
        s.push_back(x);
    }

    Int ans = 0;
    for(int d = 1;d <= N-1;d++) {
        Int score = 0;
        int left = 0;
        int right = N-1;
        
        while(1) {
            left += d;
            right -= d;
            if(left == right || right <= d || left-d == right)
                break;
            score += s[left]+s[right];
            ans = max(ans, score);
        }
    }

    cout<<ans<<endl;


    return 0;
}


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


#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
const int mod = 1e9+7;
void solve(){
      ll a, b;
      char c;
      cin >> a >>c >> b;
      if(c == '-')cout<<a-b<<"\n";
      else cout<<a+b<<"\n";
}


int main(){
   solve();
}

Measured memory_bytes: 256
/**
 *    author        : Sudipta Banik Trisha 
 *    created       : August 30, 2020 1:22 AM
 *    Problem Name  : D - Brick Break
 *    Problem Limit : 2000 ms , 1024 MB
 *    Problem Url   : https://atcoder.jp/contests/abc148/tasks/abc148_d
 *    @genarated by : ai-virtual-assistant
**/

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

int main(){
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;

    vector<int>v(n+1),vec;

    for(int i=1; i<=n; i++){
        cin >> v[i];
    }

    int cnt=0, pos = 1;

    for(int i=1; i<=n; i++){
        if(v[i] == pos){
            pos++;
        }
        else cnt++;
    }

    if(cnt == n) cout << "-1" << endl;
    else cout << cnt << endl;

    return 0 ;
}


Measured memory_bytes: 4052
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;
bool debug = true;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  vector<ll> temp_P(N);
  for (ll i = 0; i < N; ++i) {
    cin >> temp_P.at(i);
  }
  vector<ll> P(N);
  for (ll i = 0; i < N; ++i) {
    P.at(temp_P.at(i) - 1) = i + 1;
  }
  vector<ll> a(N, 0), b(N, 0);
  for (ll i = 0; i < N; ++i) {
    a.at(i) = i + 1;
    b.at(N - i - 1) = i + 1;
  }
  for (ll i = 0; i < N; ++i) {
    ll p = P.at(i);
    for (ll j = i; j < N; ++j) {
      a.at(j) += p;
    }
    for (ll j = 0; j <= i; ++j) {
      b.at(j) += p;
    }
  }
  for (ll i = 0; i < N; ++i) {
    cout << a.at(i) << " ";
  }
  cout << "\n";
  for (ll i = 0; i < N; ++i) {
    cout << b.at(i) << " ";
  }
  cout << "\n";
}


Measured memory_bytes: 3984
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll H, W;
  cin >> H >> W;
  REP(i, 0, H) {
    string s;
    cin >> s;
    cout << s << endl;
    cout << s << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import sys
import math
import heapq
mod=10**9+7
inf=float("inf")
from math import sqrt
from collections import deque
from collections import Counter
from math import ceil
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import Decimal #floatの高精度ver, 渡すのはstr型で
from functools import lru_cache
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########

from itertools import permutations as per
n,m=map(int,input().split())
A=[[] for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    a-=1 ;b-=1
    A[a].append(b)
    A[b].append(a)

ans=0
for bit in per([i for i in range(1,n)]):
    # print(bit)
    peanut=0
    bit=[0]+list(bit)
    for i in range(n-1):
        if not bit[i] in A[bit[i+1]]:
            peanut=1
            break
    else:
        ans+=1
    

print(ans)

Measured memory_bytes: 9908
n, m = map(int, input().split())
h_array = list(map(int, input().split()))
ab = []
sum = 0
answer = [True for i in range(n)]

for i in range(m):
  ab.append(list(map(int, input().split())))

for i in range(len(ab)):
  if h_array[ab[i][0]- 1] >= h_array[ab[i][1]- 1]:
    answer[ab[i][1] - 1] = False
  if h_array[ab[i][1]- 1] >= h_array[ab[i][0]- 1]:
      answer[ab[i][0] - 1] = False

print(answer.count(True))

Measured memory_bytes: 31992
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n;
	while(cin >> n, n){
		vi v;
		rep(i, n){ int x; cin >> x; v.pb(x); }
		rep(it, 10001){
			bool ok = 1;
			rep(i, v.size()) if(v[i] != i + 1){
				ok = 0;
				break;
			}
			if(ok){
				cout << it << endl;
				goto END;
			}
			rep(i, v.size()) v[i]--;
			v.pb(v.size());
			rep(i, v.size()) if(v[i] == 0) v.erase(v.begin() + i--);
		}
		cout << -1 << endl;
		END:;
	}
	return 0;
}


Measured memory_bytes: 3144
#include <iostream>
#define mod 998244353
using namespace std;
inline long long ksm(long long x,long long y)
{
	long long rtn=1;
	while(y)
	{
		if(y&1) rtn*=x,rtn%=mod;
		x*=x,x%=mod,y>>=1;
	}
	return rtn;
}
int main(int argc, char** argv) {
	long long n,m,k;
	cin >> n >> m >> k;
	long long ans=0;
	long long qwq=0,now=1;
	for(long long i=0;i<=k;i++)
	{
		ans+=m*ksm(m-1,n-i-1)%mod*now,ans%=mod;
		now*=n-i-1,now%=mod,now*=ksm(i+1,mod-2);
		now%=mod;
	}
	cout << ans%mod;
	return 0;
}

Measured memory_bytes: 3156
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R

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

	cin >> N >> K;
	vector<long long int>v(N);
	vector<long long int>w;
	for (int i = 0; i < N; i++) {
		cin >> L >> R;
		if (v[L - 1] < R) {
			w.push_back(v[L - 1]);
			v[L - 1] = R;
		}
		else {
			w.push_back(R);
		}
	}
	sort(w.begin(), w.end(), greater<long long int>());
	long long int ans = 0;
	sort(v.begin(), v.end(), greater<long long int>());
	for (int i = 1; i < w.size(); i++) {
		w[i] += w[i - 1];
	}
	for (int i = 1; i < v.size(); i++) {
		v[i] += v[i - 1];
	}
	for (long long int i = 0; i < K; i++) {
		if (i&&v[i]==v[i-1])break;
		if (i == K - 1)ans = max(ans, v[i]+(i+1)*(i+1));
		else if(K-i-2>=0&&K-i-2<w.size())ans = max(ans, v[i] + w[K - i - 2] + (i + 1)*(i + 1));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2168
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;


void main() {
    string N = readln.chomp;

    int ans;

    foreach (ch ; N) {
        ans += ch - '0';
    }

    ans = max(ans, (N[0] - '0' - 1) + 9 * (N.length.to!int - 1));

    writeln(ans);
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> dp(k + 1);
  for (int i = 1; i <= k; i++) {
    bool win = false;
    for (int j = 0; j < n; j++) {
      if (i - a[j] < 0) continue;
      win |= !dp[i - a[j]];
    }
    dp[i] = win;
  }
  puts(dp[k] ? "First" : "Second");
  return 0;
}

Measured memory_bytes: 640