akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int inf = 1001001001;

int main(){
  int n,p;
  cin >> n >> p;
  string s;
  cin >> s;

  if(p == 2 || p == 5) {
    ll ans = 0;
    for(int r = 0; r < n; r++){
      if((s[r] -'0')%p == 0) ans += r+1;
    }
    cout << ans << endl;
    return 0;
  }


  int c = 0;
  int fac = 1;
  vector<ll> val(p,0);
  val[0]++;
  rep(i,n){
    c += (s[n-1-i]-'0')*fac;
    c %= p;
    val[c]++;
    fac *= 10;
    fac %= p;
  }
  ll ans = 0;
  rep(i,p) ans += val[i]*(val[i]-1)/2;
  cout << ans << endl;
}


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


int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i=0;i<n;i++) {
        cin >> a[i];
    }
    int m=0;
    vector<int> box(n);
    for (int i=n/2;i<n;i++) {
        box[i]=a[i];
        m+=box[i];
    }
    for (int i=n/2-1;i>=0;i--) {
        int t=0;
        for (int j=2*(i+1); j<=n; j+=i+1) {
            t+=box[j-1];
        }
        box[i]=(t+a[i])%2;
        m+=box[i];
    }

    cout << m << endl;
    for (int i=0;i<n;i++) {
        if (box[i]==1) cout << i+1 << ' ';
    }
    cout << endl;
}

Measured memory_bytes: 2432
#include <iostream>
#include <vector>
#include <utility>
using namespace std;
typedef long long ll;

int N, K;
int dp[5010][5010];
int dp2[5010][5010];
vector<int> a(5010);
void calc() {
  for(int i=0;i<K;i++) {
    dp[0][i] = 0;
  }
  dp[0][0] = 1;

  for(int i=0;i<K;i++) {
    dp2[0][i] = 0;
  }
  dp2[0][0] = 1;

  for(int i=1;i<=N;i++) {
    for(int j=0;j<=K;j++) {
      if(j-a[i] >= 0)
        dp[i][j] |= dp[i-1][j-a[i]];
      dp[i][j] |= dp[i-1][j];
    }
  }

  for(int i=1;i<=N;i++) {
    for(int j=0;j<=K;j++) {
      if(j-a[N-i+1] >= 0)
        dp2[i][j] |= dp2[i-1][j-a[N-i+1]];
      dp2[i][j] |= dp2[i-1][j];
    }
  }
}
int main() {
  int ans=0;
  cin >> N >> K;
  a.push_back(-1);
  for(int i=1;i<=N;i++) {
    cin >> a[i];
  }
  calc();


  for(int i=0;i<=N;i++) {
    for(int j=1;j<=K;j++) {
      dp2[i][j] += dp2[i][j-1];
    }
  }
  for(int i=1;i<=N;i++) {
    for(int j=0;j<K;j++) {
      if(dp[i-1][j] == 0) continue;
      int y = K-1-j;
      int x = K-a[i]-j;
      int low;
      if(y<0) break;
      if(x-1 < 0)
        low = 0;
      else
        low = dp2[N-i][x-1];
      if(dp2[N-i][y] - low == 0) continue;
      ans++;
      break;
    }
  }

  cout << N-ans << endl;
}


Measured memory_bytes: 196224
N = int(input()) 
s = input() 
b = int(N/2)


if N % 2 == 0:
  s1 = s[0:b]
  s2 = s[b:N]

  if s1 == s2:
    print('Yes')
  else:
    print('No')
else:
  print('No')

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

int main(){
  string result;
  string s1,s2;
  long long n;
  cin >> n;
  cin>>s1>>s2;
  
  for(int i=0;i<n;i++){
  	result += s1[i];
  	result += s2[i];
  }
  
  cout << result;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
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() {
    ll n;
    cin >> n;
    string c;
    cin >> c;
    vector<ll> a(n+10, 0);
    rep2(i, 1, n+1){
        if (c[i-1]=='R') a[i] += a[i-1] + 1;
        else a[i] += a[i-1];
    }
    ll num = a[n];
    ll ans;
    if (num == 0) ans = 0;
    else ans = num - a[num];
    cout << ans << endl;
}

Measured memory_bytes: 5236
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>

using namespace std;
using ll = long long int; 

void prime(vector<int> &num, int n){
    for(int i=0;i<=n;i++){
        num[i] = 1;
    }
    num[0] = 0;
    num[1] = 0;
    num[2] = 1;

    for(int i=2;i<=sqrt(n);i++){
        if(num[i] == 1){
            for(int j=2;j<=n/i;j++){
                num[i*j] = 0;
            }
        }
    }
}


ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

ll keta(ll a){
  ll ans = 1;
  while(1){
    if(a/10 > 0){
      ans++;
      a = a/10;
    }
    if(a<10) break;
  }
  return ans;
}

const int MAX = 50;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

#define REP(i,n) for(ll i=0;i<(ll)(n);i++) //REP(i, 5) cout<<i;
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)

int main(void){
  
  ll n, m, x;
  cin>>n>>m>>x;
  ll mini = 1000000000;

  vector<ll> c(n);
  ll a[n][m];

  REP(i, n){
    ll x;
    cin>>x;
    c[i] = x;
    REP(j, m){
      ll y;
      cin>>y;
      a[i][j] = y;
    }
  }


  for(int bit=0; bit<(1<<n);++bit){
    vector<ll> v(m, 0);
    ll piv = 0;
    ll sum = 0;

    for(int i=0;i<n;++i){
      if(bit & (1<<i)){
        REP(j, m){
          v[j]+= a[i][j];
        }
        sum += c[i];
      }
    }
    REP(i, m){
      if(v[i]<x){
        piv = 1;
        break;
      }
    }
    if(piv==0) mini = min(mini, sum);
  }
  if(mini == 1000000000)cout<<"-1"<<endl;
  else cout<<mini<<endl;
 return 0;
}

Measured memory_bytes: 3724
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;

class Puzzle
{
public:
	string s;
	int count;
};

int main()
{
	int d[4] = { 1, -1, 4, -4 };
	map<string, int> memo;
	queue<Puzzle> que;
	Puzzle target;
	target.s = "01234567";
	target.count = 0;
	que.push(target);
	memo[target.s] = target.count;

	while (!que.empty())
	{
		Puzzle p = que.front();
		que.pop();
		int zeroPos = p.s.find('0');
		for (int i = 0; i < 4; i++)
		{
			if (zeroPos % 4 == 0 && i == 1) continue;
			if (zeroPos % 4 == 3 && i == 0) continue;
			if (!(0 <= zeroPos + d[i] && zeroPos + d[i] < 8)) continue;
			Puzzle next = p;
			next.count++;
			swap(next.s[zeroPos], next.s[zeroPos + d[i]]);
			if (memo.count(next.s)) continue;
			memo[next.s] = next.count;
			que.push(next);
		}
	}

	while (true)
	{
		string str;
		char c;
		for (int i = 0; i < 8; i++)
		{
			if (!(cin >> c)) return 0;
			str.push_back(c);
		}
		cout << memo[str] << endl;
	}

	return 0;
}

Measured memory_bytes: 5324
import sys

while True:
    a,b = map(int,raw_input().split())
    if [a,b] == [0,0]:
        break
    data = []
    plot = []
    for i in range(a):
        ta,tb = raw_input().split()
        data.append([ta,int(tb)])
    for i in range(b):
        ta = raw_input()
        plot.append(ta)
###                                                                             
    total = 0
    for i in data:
        for j in plot:
            c = i[0].count("*")
            if i[0][c:] == j[c:]:
                total += int(i[1])
    print total

Measured memory_bytes: 4296
//2018.09.23

#include <iostream>
#include <math.h>

using namespace std;

int main() {

    double x;
    cin >> x;

    double xroot = sqrt(x);

    double i, j, maxv=0.0;
    for(i=2.0;i<=xroot;i+=1.0){
        j=2.0;
        while(pow(i,j+1.0)<=x){ j+=1.0;}
        maxv = max(maxv, pow(i,j));
    }

    maxv = max(maxv,1.0);
    cout << maxv << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<((int)(n)); i++)
#define rep1(i, n) for(int i=1; i<=((int)(n)); i++)
#define rrep(i, n) for(int i=((int)(n)-1); i>=0; i--)
#define ALL(a) (a).begin(), (a).end()
#define pb push_back
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T> bool chmin(T&x,T y){if(x>y){x=y;return true;}return false;}
template<class T> bool chmax(T&x,T y){if(x<y){x=y;return true;}return false;}
ll gcd(ll x, ll y){ if(x>y) swap(x, y);while(x!=0){ y%=x; swap(x, y); }return y; }
ll mpow(ll x, ll r){if(r==0) return 1;if(r%2==1){ return x*mpow(x, r-1)%mod; }else{ ll aa = mpow(x, r/2); return aa*aa%mod; }}

int main(){
	int a, b, c, d; cin >> a >> b >> c >> d;
	int t = 0;
	while(1){
		if(t==0){
			c -= b;
			if(c <= 0){
				cout << "Yes" << endl;
				return 0;
			}
		}else{
			a -= d;
			if(a <= 0){
				cout << "No" << endl;
				return 0;
			}
		}
		t = 1-t;
	}
	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>

using namespace std;

int main() {

    int n, q, S[10000], T[500];

    cin >> n;
    for (int i = 0; i < n; i++) cin >> S[i];

    cin >> q;
    for (int i = 0; i < q; i++) cin >> T[i];

    int ans = 0;

    for (int i = 0; i < q; i++) {
        if (count(S, S + n, T[i])) ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3112
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace D
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var n = int.Parse(Console.ReadLine());
            var ai = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var number = 1;
            var count = 0;
            for (var i = 0; i < ai.Length; i++)
            {
                if (ai[i] != number)
                {
                    ai[i] = -1;
                    count++;
                    continue;
                }
                number++;
            }
            Console.WriteLine(ai.Where(x => x > 0).Count() != 0 ? count : -1);
        }
    }
}


Measured memory_bytes: 34012
n = int(input())
a = list(map(int, input().split()))

if n%2 == 0:
  ans = [str(a[n-1-i*2]) for i in range(n//2)] + [str(a[j*2]) for j in range(n//2)]
else:
  ans = [str(a[n-1-i*2]) for i in range(n//2+1)] + [str(a[1+j*2]) for j in range(n//2)]

print(' '.join(ans))


Measured memory_bytes: 33476
n,m = map(int,input().split())
h = list(map(int,input().split()))
judge = [True] * n

for i in range(m):
    a,b = map(int,input().split())
    if h[a-1] == h[b-1]:
        judge[a-1],judge[b-1] =False, False
    elif h[a-1] > h[b-1]:
        judge[b-1] = False
    else:
        judge[a-1] = False

print(judge.count(True))


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

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    int ans = 0;
    int cnt = 0;
    for(int i = 0; i < n; i++){
        if((s[i] == 'A') || (s[i] == 'T') || (s[i] == 'G') || (s[i] == 'C')){
            cnt++;
        }else{
            cnt = 0;
        }
        ans = max(ans,cnt);
    }
    cout << ans;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){

int x1=0;
int x2=0;
int x3=0;
int x4=0;
int x5=0;

scanf("%d %d %d %d %d", &x1, &x2, &x3, &x4, &x5);

/*printf("%d\n",x1);
printf("%d\n",x2);
printf("%d\n",x3);
printf("%d\n",x4);
printf("%d\n",x5);*/

if(x1 == 0){
	printf("1\n");
}else if(x2 == 0){
	printf("2\n");
}else if(x3 == 0){
	printf("3\n");
}else if(x4 == 0){
	printf("4\n");
}else if(x5 == 0){
	printf("5\n");
}

return(0);
}

Measured memory_bytes: 1644
from sys import stdin
readline = stdin.readline

h, w = map(int, readline().split())

dp = [list(map(int, readline().split())) for _ in range(h)]

for i in range(h):
    for j in range(w):
        dp[i][j] ^= 1

for i in range(1, h):        
    for j in range(1, w):
        if dp[i][j]:
            dp[i][j] = 1 + min(dp[i - 1][j - 1], dp[i - 1][j],dp[i][j - 1])

print(max(y for x in dp for y in x) ** 2)

Measured memory_bytes: 45248
import java.util.*;
public class Main {
	public static void main (String [] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		HashMap<Integer, Integer> Even = new HashMap<Integer,Integer>();
		HashMap<Integer, Integer> Odd = new HashMap<Integer,Integer>();
		
		for (int i = 0; i < N; i++) {
			HashMap <Integer, Integer> map;
			if (i % 2 == 0) map = Even;
			else map = Odd;
			
			int c = sc.nextInt();
			if (map.containsKey(c)) 
				map.put(c, map.get(c) + 1);
			else
				map.put(c, 1);
		}
		
		ArrayList<int[]> ev = new ArrayList<int[]>(); ev.add(new int[] {-1, 0});
		ArrayList<int[]> od = new ArrayList<int[]>(); od.add(new int[] {-1, 0});
		for (int key: Even.keySet()) 
			ev.add(new int [] {key, Even.get(key)});
		for (int key: Odd.keySet()) 
			od.add(new int [] {key, Odd.get(key)});
		
		ev.sort(new Comparator<int[]>() {
			public int compare (int [] o1, int [] o2) 
				{return o2[1] - o1[1];}
		});
		od.sort(new Comparator<int[]>() {
			public int compare (int [] o1, int [] o2) 
				{return o2[1] - o1[1];}
		});
		
		int m1 = 0, m2 = 0;
		while (ev.get(m1)[0] == od.get(m2)[0]) {
			if (ev.get(m1)[1] - ev.get(m1 + 1)[1] >= od.get(m2)[1] - od.get(m2 + 1)[1]) 
				m2++;
			else
				m1++;
		}
		System.out.println(N - (ev.get(m1)[1] + od.get(m2)[1]));
	}
}


Measured memory_bytes: 63292
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a,b;
	int k;
	cin>>a>>b;
	for(int i=0;i<b.size();i++)cout<<a[i]<<b[i];
	if(a.size()>b.size())cout<<a[b.size()];
	cout<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	@SuppressWarnings("unchecked")
	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int k = scanner.nextInt();
		List<Integer>[] lists = new ArrayList[10];
		for (int i = 0; i < 10; i++)
			lists[i] = new ArrayList<Integer>();
		for (int i = 0; i < n; i++) {
			int c = scanner.nextInt();
			int g = scanner.nextInt() - 1;
			lists[g].add(c);
		}
		int[] dp = new int[k + 1];
		Arrays.fill(dp, -1);
		dp[0] = 0;
		for (int i = 0; i < 10; i++) {
			Collections.sort(lists[i], Collections.reverseOrder());;
			for (int j = k - 1; j >= 0; j--) {
				if (dp[j] == -1)
					continue;
				int sum = 0;
				for (int l = 0; l < lists[i].size() && j + l < k; l++) {
					sum += lists[i].get(l);
					dp[j + l + 1] = Math.max(dp[j + l + 1], dp[j] + sum
							+ (l + 1) * l);
				}
			}
		}
		System.out.println(dp[k]);

	}
}

Measured memory_bytes: 33524
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if(b-a==c-b)puts("YES");
	else puts("NO");
	return 0;
	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
using namespace std;
int _P=1000000007;
int main(){
	long long N;
	cin >> N;
	int oprtime=0;
	for(long long div=2;div*div<=N;++div)
	{
		int s=0, p=0;
		while(N%div==0) {++s;N/=div;}
		if(s) {
			p = 1;
			while(p<=s) s-=p++;
			oprtime += p-1;
		}
	}
	cout << oprtime + (N>1) << endl;
	return 0;
}

Measured memory_bytes: 3676
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 20000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
struct edge
{
	int to,cap,rev;
};
vector<edge>G[20105];
bool used[20105];

void add_edge(int from,int to,int cap)
{
	G[from].push_back((edge){to,cap,G[to].size()});
	G[to].push_back((edge){from,0,G[from].size()-1});
}
int dfs(int v,int t,int f)
{ 
	if(v==t) return f;
	used[v]=true;
	for(int i=0;i<G[v].size();i++)
	{
		edge &e=G[v][i];
		if(!used[e.to] && e.cap>0)
		{ 
			int d=dfs(e.to,t,min(f,e.cap));
			if(d>0) 
			{ 
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}
int max_flow(int s,int t)
{ 
	int flow=0;
	while(1)
	{ 
		memset(used,0,sizeof(used));
		int f=dfs(s,t,INF);
		if(!f) return flow;
		flow+=f;
	}
}
int n,m; char f[105][105];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++) scanf("%s",&f[i]);
	int S = 20100,T = 20101;
	
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(f[i][j] == 'X'){
				add_edge(S,(i*m+j)*2,INF);
				add_edge((i*m+j)*2,(i*m+j)*2+1,INF);
			}
			else{
				add_edge((i*m+j)*2,(i*m+j)*2+1,1);
			}
			
			if(i==0 || i==n-1 || j==0 || j==m-1){
				add_edge((i*m+j)*2+1,T,INF);
			}
			
			int dx[4]={0,1,0,-1};
			int dy[4]={1,0,-1,0};
			for(int k=0;k<4;k++){
				int nx = i+dx[k],ny = j+dy[k];
				if(!(0<=nx&&nx<n&&0<=ny&&ny<m)) continue;
				add_edge((i*m+j)*2+1,(nx*m+ny)*2,INF);
			}
		}
	}int ans = max_flow(S,T); if(ans > n*m) ans = -1;
	cout << ans << endl;
}

Measured memory_bytes: 3712
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

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

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}

int main(){
    LL N,M;
    cin >> N >> M;
    LL num=0;
    if(M-2*N>=0){
        num=N;
        M=M-2*N;
        while(M>=4){
            M=M-4;
            ++num;
        }
    }
    else{
        while(M>=2){
            M=M-2;
            ++num;
        }
    }
    cout << num;
    }

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

//no1
int main(int argc, const char * argv[]) {
    string n;
    cin >> n;
    bool hit = false;

    for(int i = 0; i < 3; i++){
        hit |= n[i] == n[i+1];
    }

    if(hit){
        cout << "Bad" << endl;
    }else{
        cout << "Good" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
n,m,q=map(int,input().split())
abcd=[]
for _ in range(q):
	a,b,c,d=map(int,input().split())
	abcd.append((a,b,c,d))
ans=0
import itertools
p=itertools.combinations_with_replacement(range(1,m+1),n)
for x in p:
	r=0
	for i in range(q):
		if x[abcd[i][1]-1]-x[abcd[i][0]-1]==abcd[i][2]:
			r+=abcd[i][3]
	ans=max(ans,r)
print(ans)

Measured memory_bytes: 9136
#include <iostream>
#include <stack>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

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


int main()
{
	int n, maxN = 0;
	cin >> n;
	vector<int> h(n);
	rep(i, n) cin >> h[i];
	for(int i = 0; i < n; i++)
	{
		int count = 0;
		for(int j = 0; i+j+1 < n; j++)
		{
			if (h[i+j+1] > h[i+j]) break;
 			count++;
		}
		maxN = max(maxN, count);
	}
	cout << maxN;
	return 0;
}

Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        int c = stdIn.nextInt();
        
        if(c - (a - b) > 0){
            System.out.println(c - (a - b));
        }else{
            System.out.println(0);
        }
        
    }
}


Measured memory_bytes: 21716
import collections


def search(data, w, h, start):
    maps = [[-1] * w for i in range(h)]
    move = [(1, 0), (-1, 0), (0, 1), (0, -1)]
    que = collections.deque([(start[1], start[0])])
    maps[start[1]][start[0]] = 0
    result = 0
    while que:
        y, x = que.popleft()
        num = maps[y][x]
        for m in move:
            if 0 <= y+m[0] < h and 0 <= x+m[1] < w:
                if maps[y+m[0]][x+m[1]] != -1:
                    continue
                if data[y+m[0]][x+m[1]] == '#':
                    continue
                elif data[y+m[0]][x+m[1]] == '.':
                    maps[y+m[0]][x+m[1]] = num+1
                    result = max(result, maps[y+m[0]][x+m[1]])
                    que.append((y+m[0], x+m[1]))
    return result


def main():
    h, w = map(int, input().split())
    data = []
    for i in range(h):
        tmp = input()
        data.append([j for j in tmp])

    ans = 0
    for i in range(h*w-1):
        if data[i//w][i % w] == '.':
            ans = max(search(data, w, h, (i % w, i//w)), ans)
    print(ans)


main()


Measured memory_bytes: 3316
import java.util.*;

public class Main {
	public static void main(String[] args) {
      Scanner sc =new Scanner(System.in);
      int A = sc.nextInt();
      int B = sc.nextInt();
      int C = sc.nextInt();
      int max = Math.max(Math.max(A,B),Math.max(B,C));
      System.out.print(A + B + C + max * 9);
    }
}

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

#define ll long long int

using namespace std;

int main() {
    ll n, d, x;
    cin >> n >> d >> x;
    vector<ll> A(n);
    for (auto & a : A) cin >> a;

    ll res = x;
    for (auto a : A) {
        res += 1 + ((d-1)/a);
    }

    cout << res << endl;
}


Measured memory_bytes: 3596
#![allow(unused_imports)]
use std::io::{self, prelude::*};

fn main() {
    let mut buf = String::new();
    let stdin = io::stdin();
    stdin.lock().read_to_string(&mut buf).unwrap();

    let bytes = buf.as_bytes();
    let mut iter = bytes.iter().enumerate();
    let space_index;

    loop {
        match iter.next() {
            Some((i, b' ')) => {
                space_index = i;
                break;
            }
            _ => (),
        }
    }
    let lf_index;
    loop {
        match iter.next() {
            Some((i, b'\n')) => {
                lf_index = i;
                break;
            }
            _ => (),
        }
    }
    let h: usize = (&buf)[0..(space_index)].parse().unwrap();
    let line_width: usize = (&buf)[(space_index + 1)..(lf_index)]
        .parse::<usize>()
        .unwrap()
        + 1;
    let mut writer = io::BufWriter::new(io::stdout());
    let mut left_index = lf_index + 1;
    for _ in 0..h {
        let slice = &bytes[left_index..(left_index + line_width)];
        writer.write_all(slice).unwrap();
        writer.write_all(slice).unwrap();
        left_index += line_width;
    }
}


Measured memory_bytes: 2128
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();

        System.out.println(solve(N));

        sc.close();
    }

    static int solve(int N) {
        List<Integer> amounts = new ArrayList<>();
        amounts.add(1);
        for (int i = 6; i <= N; i *= 6) {
            amounts.add(i);
        }
        for (int i = 9; i <= N; i *= 9) {
            amounts.add(i);
        }

        int[] minOperationNums = new int[N + 1];
        Arrays.fill(minOperationNums, Integer.MAX_VALUE);
        minOperationNums[0] = 0;

        for (int i = 1; i < minOperationNums.length; ++i) {
            for (int amount : amounts) {
                if (i >= amount) {
                    minOperationNums[i] = Math.min(minOperationNums[i], minOperationNums[i - amount] + 1);
                }
            }
        }

        return minOperationNums[N];
    }
}

Measured memory_bytes: 24532
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#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 = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n) 
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

lint gcd(lint a, lint b) {
    lint r;
    while (b != 0) {
        r = a % b;
        a = b; 
        b = r;
    }
    return a;
}

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

lint power(lint x, lint n, lint mod = MOD) {
    lint ret = 1;
    while(n > 0) {
        if(n & 1){
            (ret *= x) %= mod;
        }
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}

vector<lint> make_power(int n, lint base){
    lint num = 1;
    vector<lint> ret;
    for (int i=0; i<=n; ++i){
        ret.push_back(num);
        num *= base;
    }
    return ret;
}

void BubbleSort(vector<int> &a, int n){
    int swap_num = 0;
    int i = 1;
    while (i <= n){
        int j = n;
        while (j > i){
            if(a[j-1] > a[j]){
                swap(a[j-1], a[j]);
                swap_num++;
            }
            j--;
        }
        i++;
    }
    REP(i, n){
        if(i == 0){
            cout << a[1];
        }
        else {
            cout << " " << a[i+1];
        }
    }
    cout << endl;
    cout << swap_num << endl;
    return;
}

int main(){
    int n, tmp;
    cin >> n;
    vector<int> a(n+1);
    REP(i, n){
        cin >> a[i+1];
    }
    BubbleSort(a, n);
    return 0;
}


Measured memory_bytes: 3108
s = gets.chomp
K = gets.to_i

substrings = []

(0).upto(s.size - 1) do |i|
  (0).upto(K-1) do |j|
    # p "i: #{i} i+j:#{i+j} #{s[i..(i+j)]}"
    substrings << s[i..(i+j)]
  end
end

puts substrings.uniq.sort[K-1]


Measured memory_bytes: 4856
inp = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n')
l = inp.shift().split(' ')
N = l[0] * 1
M = l[1] * 1 
s = []
c = []
for (i=0; i<N; i++) {
  s[i] = inp[i].split(' ')
}
for (i=N; i<N+M; i++) {
  c[i-N] = inp[i].split(' ')
}
for (i=0; i<N; i++) {
  min = 1000000000
  for (j=0; j<M; j++) {
    x = s[i][0] * 1
    y = s[i][1] * 1
    m = Math.abs(c[j][0] - x) + Math.abs(c[j][1] - y)
    if (min > m) {
      min = m
      n = j + 1
    }
  }
  console.log(n)
}


Measured memory_bytes: 7500
import math

N = int(input())

def primeFactors(n):
        while n % 2 == 0:
                yield 2
                n /= 2
        
        for i in range(3, int(math.sqrt(n)) + 1, 2):
                while n % i == 0:
                        yield i
                        n /= i

        if n > 2:
                yield n


def cn(n):
        i = 1
        count = 0
        while n >= i:
                n -= i
                count += 1
                i += 1
        return count


res = 0

check = list(primeFactors(N))

while check:
        g = check[0]
        num = check.count(g)
        res += cn(num)
        del check[:num]

print(res)

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

#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;

typedef long long ll;

int main(){

    int n;
    cin >> n;

    vector<double> x(n);
    vector<double> y(n);

    rep(i,n){
        cin >> x[i] >> y[i];
    }

    vector<int> v(n);

    rep(i, n){
        v[i] = i;
    }

    double sum = 0.0;
    int count = 0;

    do{

        rep(i, n - 1){
            sum += sqrt(pow(x[v[i + 1]] - x[v[i]], 2.0) + pow(y[v[i + 1]] - y[v[i]], 2.0));
        }
        count++;

    }while(next_permutation(ALL(v)));

    cout << setprecision(12) << sum / count << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
     
int main() {
      int a;
      cin >> a;
      int b1,b2,b3;
  b1 = (a + 10) % 10;
  b2 = ((a + 100 - b1) % 100)/10;
  b3 = a/100;
  cout << b1 + b2 + b3 << endl;
}

Measured memory_bytes: 256
from collections import Counter
N=int(input())
a=Counter(list(map(lambda x:int(x)//400,input().split())))
#print(a)
d=a.keys()
if {8,9,10,11,12}&set(a.keys()):
    b=len(set(d)-{8,9,10,11,12})
    #print(b)
    c=sum([a[i] for i in range(8,13)])
    print(max(b,1),(b+c))
else:
    print(len(d),len(d))

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



int main()
{
    long long n,a,b;
    cin>>n>>a>>b;
    if(a+b>=n){
    	if(a>=n){
    		cout<<n<<endl;
		}else{
			cout<<a<<endl;
		}
	}else{
		long long j=n%(a+b);
		long long k=n/(a+b);
    	if(a>=j){
    		cout<<j+k*a<<endl;
		}else{
			cout<<(k+1)*a<<endl;	
	}
}
}

Measured memory_bytes: 256
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
import sys,bisect,string,math,time,functools,random
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[];g=[[] for i in range(n)]
    for i in range(E):
        inp=LI();org_inp.append(inp)
        if index==0:inp[0]-=1;inp[1]-=1
        if len(inp)==2:
            a,b=inp;g[a].append(b)
            if not Directed:g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
            if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,boundary=1,search=[],replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,boundary=1,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):return [[tb//(n**bt)%n for bt in range(k)] for tb in range(n**k)]
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)
def show2d(g,h,w):
    for i in range(h):show(g[i*w:i*w+w])

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=0



k=I()
c=0

m=list(range(1,10))
ans=[]
n=10
for i in range(n):
    nx=[]
    for j in m:
        d=j%10
        tmp=[j*10+d+x for x in range(-1,2)]
        if d==0:
            tmp=tmp[1:]
        elif d==9:
            tmp=tmp[:2]
        nx+=tmp
    ans+=m
    m=nx[:]
    
print(ans[k-1])
    
    

Measured memory_bytes: 68908
import itertools

N,C=map( int, raw_input().split() ) 

D=[0]
for i in range(C) :
	x=[0]+map( int, raw_input().split() )
	D.append(x)

c=[0]
for i in range(N) :
	x=[0]+map( int, raw_input().split() ) 
	c.append(x)

#S[mod 3][Color]
S= [ [ 0 for j in range(C+1) ] for i in range(3) ]

for color in range(1,C+1):
	for x in range(1,N+1):
		for y in range(1,N+1):
			mod=(x+y)%3
			S[mod][color]+=D[ c[x][y] ][color]		

ans=float("inf")
L=list(itertools.permutations(range(1,C+1),3))

for c1,c2,c3 in L:
	ans= min(ans, S[0][c1]+S[1][c2]+S[2][c3])

print ans


Measured memory_bytes: 37020
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    string key[] = {"dream" , "dreamer" , "erase" , "eraser"};
    for(int i = 0; i < 4; i++){
        reverse(key[i].begin() , key[i].end());
    }
    bool can = true;
    for(int i = 0; i < s.size();){
        bool can2 = false;
        for(int j = 0; j < 4; j++){
            if(s.substr(i, key[j].size()) == key[j]){
                can2 = true;
                i += key[j].size();
            }
        }
        if(!can2){
            can = false;
            break;
        }
    }
    (can) ? cout << "YES" << endl : cout << "NO" << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;

int main(){
    char s[20];
    cin>>s;
    for(int i =0; i<19; i++){
        if(s[i]==','){
            s[i]=' ';
        }
        cout<<s[i];
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

typedef struct point_xy_tag{
	double x ;
	double y ;
}Vector2D, Vertex2D;

Vector2D new_vector2D(Vertex2D a, Vertex2D b){
	Vector2D c;
	c.x = a.x - b.x;
	c.y = a.y - b.y;
	return c;
}

double outer_product(Vector2D a, Vector2D b){
	return a.x*b.y - a.y*b.x;
}

isExternal(double c1, double c2, double c3){
	if( (c1>0.0 && c2>0.0 && c3>0.0) || (c1<0.0 && c2<0.0 && c3<0.0) ){
		return 1;
	}
	return 0;
}

int main(void) {
	Vertex2D a, b, c, p;
	while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &a.x, &a.y, &b.x, &b.y, &c.x, &c.y, &p.x, &p.y) != EOF){
		printf("%s\n", isExternal(outer_product(new_vector2D(p, a), new_vector2D(b, a)), outer_product(new_vector2D(p, b), new_vector2D(c, b)), outer_product(new_vector2D(p, c), new_vector2D(a, c)) ) ? "YES" : "NO") ;
	}
	return 0;
}

Measured memory_bytes: 612
N,M,C = map(int,input().split())
B =list(map(int,input().split()))
ans = 0
sum = 0
for i in range(N):
    A = list(map(int,input().split()))
    for k in range(M):
        sum += A[k]*B[k]
    if sum + C > 0:
        ans += 1
    sum = 0
print(ans)
        

Measured memory_bytes: 3060
#include <stdio.h>

int main()
{

    int s;
    scanf("%d", &s);
    int c, d;
    scanf("%d %d", &c, &d);

    if (d/s!=(c-1)/s)
    {
        printf("OK");
    }
    else
        printf("NG");

    printf("\n");
}

Measured memory_bytes: 2140
using System;

namespace ITP1_6_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string str1 = Console.ReadLine();
            int n = int.Parse(str1);

            string[] str2 = Console.ReadLine().Split(' ');

            int i;

            for(i = 0; i < n; i++)
            {
                Console.Write("{0}", str2[n - i - 1]);
                if (i == n - 1)
                    Console.Write("\n");
                else
                    Console.Write(" ");
            }
        }
    }
}

Measured memory_bytes: 15556
import collections
import math
import operator as op
from functools import reduce
import numpy as np
import math
import bisect
import heapq


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


def get_inputs(cast_func=None):
    if cast_func is None:
        return input().split()
    else:
        return list(map(cast_func, input().split()))


def get_input(cast_func=None):
    if cast_func is None:
        return input()
    else:
        return cast_func(input())


def main():
    N = get_input(int)
    print(N * (N - 1) // 2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 12428
#include "bits/stdc++.h"

#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define eb emplace_back
#define rep(i, a, b) for (long i = (a); i <= (b); ++i)
#define per(i, a, b) for (long i = (a); i >= (b); --i)
#define mmst(v) memset(v, 0, sizeof(v))

template<typename T1,typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 & a, T2 b) { if (a < b) a = b; }

const long kMax2 = 109;
const long kMax3 = 1009;
const long kMax4 = 10009;
const long kMax5 = 100009;
const long kMax6 = 1000009;
const long kMax9 = 1000000010;
const long kInfI = 0x3F3F3F3F;
const float kInfF = 1e15;
const long long kMod = 1000000007;

const long long kMAX = 1000000000;

using namespace std;
using ll = long long;

inline int readInt() {
  char c = getchar();
  while(!isdigit(c) && c != '-') c = getchar();
  int sigma = 1;
  if (c == '-') {
    sigma = -1;
    c = getchar();
  }
  int x = 0;
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * sigma;
}

template <class T>
void PrintVector(const vector<T> & v) {
  for (const auto & e: v) {
    cout << e << endl;
  }
}

template <class T>
void PrintVector(const vector<T> & v, int n) {
  rep(i, 0, n - 1) {
    cout << v[i] << endl;
  }
}

double dist(double lhs, double rhs) {
  return sqrt(lhs * lhs + rhs * rhs);
}

ll gcd(ll x, ll y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}

int main() {
  ll ans = 0;
  long n, m, a, b, x, y;
  string s, t;
  vector<string> ss;
  vector<ll> aa;
  vector<ll> ba;
  vector<ll> xx;
  vector<ll> yy;

  cin >> n;

  rep(i, 0, n - 1) {
    ll a0;
    cin >> a0;
    aa.pb(a0);
  }
  ll ct = 1;
  long i = 0;
  while (i < n) {
    if (aa[i] == ct) ++ct;
    ++i;
  }

  if (ct == 1) ct = n + 2;
  cout << n - ct + 1 << endl;

  return 0;
}


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

const int N = 1e5 + 5;
typedef long long LL;

int n, m, num[N], ans;
bool vis[N];

int main() {
	cin>>n>>m;
	for(int i = 1; i <= n; i++)
		num[i] = 1;
	vis[1] = 1;
	for(int i = 1, x, y; i <= m; i++) {
		cin>>x>>y;
		num[x]--, num[y]++;
		vis[y] |= vis[x];
		if(!num[x]) vis[x] = 0;
	}
	for(int i = 1; i <= n; i++)
		ans += vis[i];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4040
#include <bits/stdc++.h>
#define re return
#define ll long long
#define ld long double
#define f first
#define s second
#define pi acos(-1)
#define oo (int)1e9
#define OO (ll)1e18
#define EPS 1e-7
#define FX(n) fixed<<setprecision(n)
#define mm(o,k) memset(o,k,sizeof o)
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn=105;
pair<int,int> a[maxn];
/*
0 based node indices
left nodes are numbered from 0
right nodes are numbered from 0 as well
*/
struct MaximumMatching {
	vector<int> m1, m2, seen;
	vector<vector<int> > g;
	int seen_id;
	MaximumMatching(int numNodesLeft, int numNodesRight) {
		g = vector<vector<int> >(numNodesLeft, vector<int>());
		m1 = vector<int>(numNodesLeft, -1);
		m2 = vector<int>(numNodesRight, -1);
		seen_id = 0;
		seen = vector<int>(numNodesRight, 0);
	}
	void addEdge(int leftNode, int rightNode) {
		assert(leftNode < int(m1.size()));
		assert(rightNode < int(m2.size()));
		g[leftNode].push_back(rightNode);
	}
	int getMaxMatching() {
		int ans = 0;
		for (int node = 0; node < int(m1.size()); node++) {
			seen_id++;
			if (dfs(node)) ans++;
		}
		return ans;
	}
	bool dfs(int node) {
		for (int i = 0; i < int(g[node].size()); i++) {
			int child = g[node][i];
			// if the child is not matched yet, match it with me
			if (m2[child] == -1) {
				m2[child] = node;
				m1[node] = child;
				return true;
			}

			// if the child was seen before (some other node tried to take it), leave it
			if (seen[child] == seen_id) continue;
			seen[child] = seen_id;

			// if the child is already matched with some other node, try to match that other node is some other way
			int enemy = m2[child];
			// take the child for me
			m1[enemy] = -1; m1[node] = child; m2[child] = node;
			// try to match the enemy
			if (dfs(enemy)) return true;
			// match the child with the enemy if not successful
			m1[enemy] = child; m1[node] = -1; m2[child] = enemy;
		}
		return  false;
	}
};
int main()
{
    IO;
    int n;
    cin >> n;
    MaximumMatching flow(n,n);
    for(int i=0;i<n;++i)
        cin >> a[i].f >> a[i].s;
    for(int i=0;i<n;++i){
        int x,y;
        cin >> x >> y;
        for(int j=0;j<n;++j)
            if(a[j].f<x&&a[j].s<y)flow.addEdge(i,j);
    }
    cout<<flow.getMaxMatching()<<endl;
    re 0;
}

Measured memory_bytes: 256
<?php

$inputs = [];
while (($item = fgets(STDIN)) !== false) {
    $inputs[] = $item;
}

$map = [
    'A' => 'T',
    'T' => 'A',
    'C' => 'G',
    'G' => 'C',
];
$x = trim(array_shift($inputs));
echo $map[$x];


Measured memory_bytes: 4604
using System;
using System.Linq;

class B{
  static void Main(){
    int[] NM = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
    int L = NM[0];
    string[] Ar = new string[L];
    for (int j = 0; j < L; j++){
      Ar[j] = Console.ReadLine();
    }
    Array.Sort(Ar);
    Console.WriteLine(String.Join("", Ar));
  }
}

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

#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define MOD 1000000007

const int MAX_M = 100000;


int main(){
  ll k;
  //string s;
  cin >> k;

  //vector<ll> a(n);
  queue<ll> q;
  //map<string,ll> d{};

  rep(i,1,10){
    q.push(i);
  }

  rep(i,0,k-1){
    ll x = q.front();
    if(x%10 != 0){
      q.push(10*x+x%10-1);
    }
    q.push(10*x+x%10);
    if(x%10 != 9){
      q.push(10*x+x%10+1);
    }
    q.pop();
  }

  cout << q.front() << endl;


  //cout << ((ok)? "Yes" : "No") << endl;
}


Measured memory_bytes: 1792
n, c, k = map(int, input().split())
T = []
for i in range(n):
    t = int(input())
    T.append(t)
T.sort()
x = 0
ans = 1
w = T[0] + k
for i in range(n):
    if T[i] <= w and x < c:
        x += 1
    else:
        ans += 1
        x = 1
        w = T[i]+k
print(ans)

Measured memory_bytes: 7384
#import sys
#input = sys.stdin.readline

n = int(input())
a = [0]*n
b = [0]*n
a =[int(xi) for xi in input().split()]
b =[int(yi) for yi in input().split()]

cnt, prev_cnt = 0, -1
while cnt != prev_cnt:
    prev_cnt = cnt
    for i in range(n):
        
        adj_sum = b[i - 1] + b[(i + 1) % n]
        k = (b[i] - a[i]) // adj_sum
        if k > 0:
            b[i] -= k * adj_sum
            cnt += k

print(cnt if a == b else -1)

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

using namespace std;

int main()
{
   int n,a[100006];
   cin>>n;
   for(int i=1;i<=n;i++){ 
       cin>>a[i];
   } 
   int lst=a[1];
   for(int i=2;i<=n;i++){ 
       if(a[i]<lst){ 
           if(abs(a[i]-lst)>1){ 
               cout<<"No"<<endl; 
               return 0;
           } }
           if(a[i]>lst){ 
           lst=a[i];
           }  
   }   
   cout<<"Yes"<<endl; 
       

    return 0;
}


Measured memory_bytes: 640
if __FILE__ == $0
  i = 0
  while line = STDIN.gets
    tokens = line.chomp!.split.map!(&:to_i)
    a,b,c = *tokens
    cnt = 0
    for i in a..b
      cnt += 1 if c%i==0
    end
    puts cnt
  end
end

Measured memory_bytes: 8648
use std::collections::BinaryHeap;
use std::cmp;

fn getline() -> String{
	let mut __ret=String::new();
	std::io::stdin().read_line(&mut __ret).ok();
	return __ret;
}


fn main(){
    let s=getline();
    let v:Vec<_>=s.trim().split(' ').collect();
    let n:i32=v[0].parse().unwrap();
    let h:i32=v[1].parse().unwrap();
    let mut amax = -1;
    let mut heap = BinaryHeap::new();
    for i in 0..n{
        let s=getline();
        let v:Vec<_>=s.trim().split(' ').collect();
        let a:i32=v[0].parse().unwrap();
        let b:i32=v[1].parse().unwrap();
        amax = cmp::max(amax, a);
        heap.push(b);
    }
    let mut ans = 0;
    let mut d = 0;
    while d < h && !heap.is_empty()  && amax < *(heap.peek().unwrap()) {
        d += heap.pop().unwrap();
        ans += 1;
    }
    if h>d { ans += (h-d + amax - 1)  / amax; }
    println!("{}",ans);
}

Measured memory_bytes: 4352
#include<iostream>
using namespace std;
int n,A,B,cr,Poz[5005],x,i,j;
long long Dp[5005][5005],cost;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    cin>>n>>A>>B;
    for(i=1; i<=n; i++)
    {
        cin>>x;
        Poz[x]=i;
    }
    for(i=1; i<=n; i++)
    {
        cr=1-cr;
        for(j=0; j<=n; j++)
        {
            if(j<Poz[i])
                cost=B;
            if(j==Poz[i])
                cost=0;
            if(j>Poz[i])
                cost=A;
            if(j==0)
                Dp[cr][j]=cost+Dp[1-cr][j];
            else
                Dp[cr][j]=min(Dp[cr][j-1],cost+Dp[1-cr][j]);
        }
    }
	cout<<Dp[cr][n]<<"\n";
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(){
    int m, d, i, tmp, ans=0;
    cin >> m >> d;
    for(i=22;i<=d;i++){
        tmp=i;
        if(1<=(tmp/10)*(tmp%10) && (tmp/10)*(tmp%10)<=m && tmp/10>=2 && tmp%10>=2) ans++;
    }
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 256