akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(void)
{
	char s[100000];
	scanf("%s",s);
	int counta=0,countb=0;
	for (int i=0;i<100000;i++)
	{
		if(s[i]!='\0')
		{
			if(i%2==0&&s[i]=='1')counta++;
			if(i%2==1&&s[i]=='0')counta++;
			if(i%2==0&&s[i]=='0')countb++;
			if(i%2==1&&s[i]=='1')countb++;
		}
		else break;
	}
	if(counta<countb)printf("%d",counta);
	else printf("%d",countb);
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
#include <set> 
using namespace std;

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

const ll INF = 1e15;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

const int MAX = 510000;
const int MOD = 1000000007;


int a[200010], box[200010];

int main(void) {
	int N; cin >> N;
	for (int i = 0; i < N; i++) cin >> a[i];
	
	for (int i = N; i >= 1; i--) {
		int sum = 0;
		for (int j = i; j <= N; j += i) {	
			sum += box[j-1];
		}
		if (a[i-1] != sum % 2) box[i-1] = 1;
	}

	vector<int> ans;
	for (int i = 0; i < N; i++) {
		if (box[i] == 1) {
			ans.push_back(i + 1);
		}
	}

	cout << ans.size() << endl;
	for (int i = 0; i < ans.size(); i++) cout << ans[i] << ' ';


}


Measured memory_bytes: 2936
#include<stdio.h>

int main(void){
   int x,y,i,j;
   for(;;){
      scanf("%d %d",&y,&x);
      if(x+y==0) break;
      for(i=0;i<y;i++){
         for(j=0;j<x;j++)
            if((i+j)%2==0)
               printf("#");
            else
               printf(".");
         printf("\n");
      }
   printf("\n");
   }
   return 0;
}



Measured memory_bytes: 2044
#include <iostream>
#include <vector>
#include <algorithm> 
#include <queue>
using namespace std;


vector<int> v[100001];
vector<int> dist[200000];
long d[100001];

void bfs(int k){
    queue<int> q;
    q.push(k);
    d[k] = 0;
    while (!q.empty()){
        int now = q.front(); q.pop();
        for (int i = 0; i < v[now].size(); i++){
            int next = v[now][i];
            if (d[next] == -1){
                d[next] = d[now] + dist[now][i];
                q.push(next);
            }
        }
    }
}
int main(void){
    int n;
    cin >> n;
    for (int i = 0; i < n - 1; i++){
        int s, t, c;
        cin >> s >> t >> c;
        s--;   t--;
        v[s].push_back(t);    v[t].push_back(s);
        dist[s].push_back(c);   dist[t].push_back(c);

    }

    int q, k;
    cin >> q >> k;
    k--;

    for (int i = 0; i < n; i++){
        d[i] = -1;
    }

    bfs(k);


    for (int i = 0; i < q; i++){
        int x, y;
        cin >> x >> y;
        x--;   y--;
        cout << d[x] + d[y] << endl;
    }
}




Measured memory_bytes: 18388
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

struct before_main{before_main(){cin.tie(0); ios::sync_with_stdio(false);}} before_main;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

string initial, target;
vector<pair<string, string>> subs;

int dodo() {

  set<string> used;
  queue<pair<string, int>> q;
  q.emplace(initial, 0);
  while(!q.empty()) {
    string p; int cost; tie(p, cost) = q.front(); q.pop();
    int n = p.size();
    if(p == target) { return cost; }
    rep(k, subs.size()) {
      string np; int pos = 0;
      int m1 = subs[k].first.size();
      if(n < m1) { continue; }
      while(pos < n) {
        int nxtpos = p.find(subs[k].first, pos);
        if(nxtpos == string::npos) {
          np += p.substr(pos);
          break;
        }
        np += string(p.begin() + pos, p.begin() + nxtpos) + subs[k].second;
        pos = nxtpos + m1;
      }
      if(np.size() > target.size()) { continue; }
      if(used.count(np)) { continue; }
      used.insert(np);
      q.emplace(np, cost+1);
    }
  }

  return -1;
}

int main() {

  for(int N; cin >> N && N;) {
    subs.clear();
    rep(i, N) {
      string a, b; cin >> a >> b; subs.emplace_back(a, b);
    }
    cin >> initial >> target;
    cout << dodo() << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3232
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    s = S()
    d = defaultdict(int)
    for i in s:
        d[i] += 1
    for i in d.keys():
        if d[i] != 2:
            print("No")
            quit()
    print("Yes")
    return

#B
def B():
    n = I()
    p = LI()
    ans = 0
    for i in range(1,n-1):
        k = p[i-1:i+2]
        k.sort()
        if k[1] == p[i]:
            ans += 1
    print(ans)
    return

#C
def C():
    n = I()
    d = LI()
    d.sort()
    print(d[n//2]-d[n//2-1])
    return

#D
def D():
    n,k = LI()
    fact = [1]*100001
    for i in range(1,100001):
        fact[i] = fact[i-1]*i%mod
    inv = [1]*100001
    inv[-1] = pow(fact[-1],mod-2,mod)
    for i in range(1,100001)[::-1]:
        inv[i-1] = inv[i]*i%mod

    for i in range(1,k+1):
        if n-k+1 < i:
            print(0)
        else:
            ans = fact[n-k+1]*inv[i]*inv[n-k+1-i]%mod
            ans *= fact[k-1]*inv[k-i]*inv[i-1]%mod
            ans %= mod
            print(ans)
    return

#E
def E():
    ma = 100000000
    def dijkstra(s):
        d = defaultdict(lambda : ma)
        q = [(0,s,0)]
        d[(s,0)] = 0
        while q:
            dx,x,t = heappop(q)
            t = (t+1)%3
            k = t == 1
            for y in v[x]:
                if dx+k < d[(y,t)]:
                    d[(y,t)] = dx+k
                    heappush(q,(d[(y,t)],y,t))
        res = d[(g,0)]
        if res == ma:
            res = -1
        return res

    n,m = LI()
    v = [[] for i in range(n)]
    for i in range(m):
        a,b = LI()
        a -= 1
        b -= 1
        v[a].append(b)
    s,g = LI()
    s -= 1
    g -= 1
    print(dijkstra(s))
    return

#F
def F():
    n = I()

    return


#Solve
if __name__ == "__main__":
    E()


Measured memory_bytes: 102960
n=int(input())
s=input()
t=""
k=""
l=[]
for i in range(1,n):
    ans1=0
    t=sorted(set(s[:i]))
    k=sorted(set(s[i:]))
    for i in t:
        for j in k:
            if i==j:
                ans1+=1
    l.append(ans1)
print(max(l))

Measured memory_bytes: 3064
import java.util.Scanner


object Main {

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n,k = sc.nextInt()
    val s = sc.next()
    val ms = s.toArray
    ms(k-1) = ms(k-1).toLower
    println(ms.mkString)
  }
}

Measured memory_bytes: 25556
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1<<30;
int gcd(int a, int b){
  if(a>b)swap(a, b);
  if(a==0)return b;
  return gcd(a, b%a);
}
int main(){
  int n;cin>>n;
  int ans=-1;
  for(int i=0;i<n;i++){
    int x;cin>>x;
  	if(ans==-1)ans=x;
    else ans=gcd(ans, x);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())

s = set()
g = set()

for _ in range(M):
    A, B = map(int, input().split())
    if A == 1:
        s.add(B)
    if B == N:
        g.add(A)

if s & g:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")



Measured memory_bytes: 24224
K,T=map(int,input().split())
A=list(map(int,input().split()))
from heapq import heappush,heappop
from collections import deque

A.sort(reverse=True)
d=deque(A)
d2=deque(A)
ans=A[0]
mod=1
while d:
  if len(d)==1:
    print(d[0]-1)
    exit()
  a=d.pop()
  b=d.popleft()
  if not a==1:
    d.append(a-1)
  if not b==1:
    d.appendleft(b-1)
print(0)

    
  


Measured memory_bytes: 3316
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#define mod 1000000007
using namespace std;
int main(){
    int a[100000],b[100000];
    vector<pair<int,int> > p;
    long long ans=1LL,l=0LL,n,x=0,y=0;
    scanf("%lld",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        p.push_back(make_pair(a[i],1));
    }
    for(int i=0;i<n;i++){
        scanf("%d",&b[i]);
        p.push_back(make_pair(b[i],-1));
    }
    sort(p.begin(),p.end());
    for(long long i=0;i<p.size();i++){
        if(p[i].second==1){
            if(y){
                ans*=y;
                ans%=mod;
                y--;
            }
            else{
                x++;
            }
        }
        else{
            if(x){
                ans*=x;
                ans%=mod;
                x--;
            }
            else{
                y++;
            }
        }
    }
    printf("%ld\n",ans);
}

Measured memory_bytes: 2932
from collections import deque

H,W = map(int,input().split())
A = [list(input()) for i in range(H)]

dist = [[float("inf")]*W for i in range(H)]
q = deque([])
for y in range(H) :
    for x in range(W) :
        if A[y][x] == "#" :
            dist[y][x] = 0
            q.append((y,x))

dxy = [(-1,0),(1,0),(0,-1),(0,1)]

while q :
    y,x = q.popleft()
    for dy,dx in dxy :
        ny,nx = y+dy,x+dx
        if ny<0 or ny>=H or nx<0 or nx>=W :
            continue
        if dist[ny][nx] > dist[y][x] + 1 :
            dist[ny][nx] = dist[y][x] + 1
            q.append((ny,nx))

ans = 0
for y in range(H) :
    ans = max(ans, max(dist[y]))
print(ans)


Measured memory_bytes: 129628
import java.util.*;
import java.io.*;

public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();   
        int k = sc.nextInt();   
        int d;
        int A;
        int[] people = new int[n];
        for (int i = 0; i < n; i++) {
            people[i] = 0;
        }
        for (int i = 0; i < k; i++) {
            d = sc.nextInt();
            for (int j = 0; j < d; j++) {
                A = sc.nextInt();
                A--;
                people[A]++;
            }
        }
        
        int res = 0;
        for (int i = 0; i < n;i++) {
            if (people[i] == 0) res++;
        }
        System.out.println(res);   
    }
}

Measured memory_bytes: 37268
/* code of Ayush Tiwari
    codeforces- servermonk
    codechef- ayush572000
*/

#include <bits/stdc++.h>
#define ll long long

//STL
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define all(v) v.begin(), v.end()

//loops
#define forn(i,a,b) for(int i=a;  i<b; i++)
#define rforn(i,a,b) for(int i=a; i>=b; i--)

// defined values
#define maxn 200004
#define Mod 1000000007

// fast io
#define FIO() ios_base::sync_with_stdio(0);cin.tie(0);


using namespace std;


void solution(){

    // This is the main code
    ll n,k;
    cin>>n>>k;
    ll val[n+1],w[n+1],v=0;
    forn(i,0,n){
        cin>>w[i]>>val[i];
        v+=val[i];
    }
    ll dp[n+1][v+1];
    forn(i,0,n+1){
        forn(j,0,v+1){
            if(i==0 || j==0){
                dp[i][j] = (j==0)?0:INT_MAX;
            }
            else{
                if(val[i-1]<=j) dp[i][j]=min(dp[i-1][j],w[i-1]+dp[i-1][j-val[i-1]]); 
                else dp[i][j]=dp[i-1][j];
            }
        }
    }
    ll ans=0;
    forn(i,0,n+1){
        for(ll j=0;j<=v;j++){
            if(dp[i][j]<=k) ans=max(ans,j);
        }
    }
    cout<<ans;
}


int main(){
    
    #ifndef ONLINE_JUDGE
    freopen("E:/CP/input.txt","r",stdin);
    freopen("E:/CP/output.txt","w",stdout);
    #endif  
    
    FIO()   
    
    ll t=1;
    //cin>>t;
    while (t--)
    {
        solution();
    }
    return 0;
}

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

int main(){
	int n;
	cin >> n;
	long long int ans = 0;
	int smin = 1e9 +1;
	bool eq = true;
	for(int i=0; i<n; i++){
		int a,b;
		cin >> a >> b;
		ans += b;
		if(a > b) smin = min(smin, b);
		if(a != b) eq = false;
	}
	if(eq){
		cout << 0 << endl;
	}else{
		if(smin != (int)(1e9+1)) ans -= smin;
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 256
PROGRAM ATCODER

implicit none
character(len=10**5) :: s
integer :: count=0, i

read(*,*) s

do i = 1, len_trim(s)
  if(s(i:i) == 'g')then
    count = count + 1
  end if
end do

if (count > len_trim(s)/2) then
  count = len_trim(s) - count
end if

write(*,'(i0)') len_trim(s)/2-count

contains
!!!!!! サブルーチンは↓

!!!!!!

END PROGRAM ATCODER

Measured memory_bytes: 700
virgin = true

readlines.each do |input|
  puts "" unless virgin

  na = input.chomp.chars.map(&:to_i)
  digit_n = na.size
  zero = "* = ****"
  result = Array.new(5)
  result.map!{zero.dup}
  ri = 5 - digit_n

  0.upto(digit_n-1) do |i|
    result[ri][3] = '*' unless (na[i] % 5).zero?
    if 5 <= na[i]
      result[ri][0] = ' '
      result[ri][1] = '*'
    end
    result[ri][na[i]%5+3] = ' '
    ri += 1
    break if 4 < ri
  end

  0.upto(7) do |i|
    0.upto(4) do |j|
      print result[j][i]
      puts "" if j == 4
    end
  end

  virgin = false if virgin
end

Measured memory_bytes: 6124
#include <iostream>

int main()
{
	int n, m, l;
	std::cin >> n >> m >> l;
	int *matrixA = new int[n * m];
	int *matrixB = new int[m * l];
	long long *matrixC = new long long[n * l];

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			std::cin >> matrixA[i*m + j];
		}
	}
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < l; j++)
		{
			std::cin >> matrixB[i*l + j];
		}
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < l; j++)
		{
			matrixC[i*l + j] = 0;
			for (int k = 0; k < m; k++)
			{
				matrixC[i*l + j] += matrixA[i*m + k] * matrixB[k*l + j];
			}
			if (j > 0)
			{
				std::cout << " ";
			}
			std::cout << matrixC[i*l + j];
		}
		std::cout << '\n';
	}
	delete[] matrixA;
	matrixA = 0;
	delete[] matrixB;
	matrixB = 0;
	delete[] matrixC;
	matrixC = 0;
	return 0;
}

Measured memory_bytes: 3200
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	long long a, b, c;
	cin >> a >> b >> c;

	long double right = a + (long double) 2 * sqrtl((long double) a * b) + b;
	long double left = c;
	if (right < left) {
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}

	return 0;

}

Measured memory_bytes: 256
N, K = map(int, input().split())

DP = [-1] * (max(N, K) + 10)
ans = 0
for i in range(1, N+1)[::-1]:
    cnt = 0
    n = i
    while n < K and DP[n] < 0:
        n *= 2
        cnt += 1
    if n < K:
        if DP[n] >= 0:
            DP[i] = (1/2) ** cnt * DP[n]
        else:
            DP[i] = (1 / 2) ** cnt
    else:
        DP[i] = (1/2) ** cnt
    ans += DP[i]
print(ans/N)


Measured memory_bytes: 41968
#include <bits/stdc++.h>
#define forna(i,a,n) for(int i=a;i<n;i++)
typedef long long int lli;
using namespace std;

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
lli a,b,c,d,k,sum=0;
// cin>>t;
// while(t--){
cin>>a>>b>>c>>k;
if(k>0){
   d=min(a,k);
  sum+=d;
  k-=d;}
  if(k>0){
 d=min(b,k);
sum+=0;
k-=d;}
if(k>0){
 d=min(c,k);
sum+=-d;
k-=d;}
cout<<sum;
}


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

long long mod=1000000007;

void solve(){
	int n;cin>>n;
	long long ans=0LL;
	vector<long long>a(n);
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<60;i++){
		long long p=1LL<<i,cnt=0;
		for(int j=0;j<n;j++)cnt+=(p&a[j])!=0;
		ans+=p%mod*cnt%mod*(n-cnt)%mod;
		ans%=mod;
	}
	cout<<ans<<endl;
}

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

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

using namespace std;
using ll = long long;

//container util
#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)

const int INF = 1e9;

int main(void){

	int N, K; cin >> N >> K;

	ll ans = 1;
	REP(i,N){
		if(i == 0) ans *= K;
		else ans *= (K-1);
	}

	cout << ans << endl;


	return 0;

}


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

using namespace std;

int N, K, mod;

int mul (int x, int y) {return 1LL * x * y % mod;}
void adto (int &x, int y) {x += y; if (x >= mod) x -= mod;}

void solve ()
{
    int dp[2][5009];
    for (int j=0; j<N; j++)
        dp[1][j] = 0;
    for (int j=0; j * K<N; j++)
        dp[1][j * K] = (N & 1 ? 1 : j + 1);
    for (int i=1; i<K; i++)
    {
        int nl = (i & 1) ^ 1;
        for (int j=0; j<=N; j++)
            dp[nl][j] = 0;
        for (int j=0; j<N; j++)
            if (dp[i & 1][j] > 0)
                for (int r=0; j + r * i < N; r++)
                    adto (dp[nl][j + r * i], mul (dp[i & 1][j], r + 1));
    }
    int ans = 0;
    for (int j=0; j<N; j++)
        adto (ans, dp[K & 1][j]);
    printf ("%d\n", ans);
}

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

scanf ("%d %d", &N, &mod);
K = (N + 1) / 2;
solve ();
return 0;
}


Measured memory_bytes: 384
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let x = read_as_vec::<u64>()[0];
    let mut cur: u64 = 100;

    let mut i: u64 = 0;
    while cur < x{
        cur += cur/100;
        i += 1;
    }

    println!("{}", i);


}


Measured memory_bytes: 2084
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        boolean end = judge(x);
        while(!end){
            x++;
            end = judge(x);
        }
        System.out.println(x);
    }
    public static boolean judge(int x){
        if(x==2){
            return true;
        }
        if(x%2==0){
            return false;
        }
        for(int i = 3;i*i<=x;i+=2){
            if(x%i==0){
                return false;
            }
        }
        return true;
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>

using namespace std;

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

	vector<int> vec(n);

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

	for (int j = n - 1; j >= 0; j--)
	{
		cout << vec[j];
		if (j != 0)
		{
			cout << " ";
		}
	}
	cout << endl;
}


Measured memory_bytes: 3084
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <unordered_map>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;

using namespace std;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i, n) {
        cin >> a[i];
    }
    ll current = 1;
    ll count = 0;
    rep(i,n) {
        if(a[i] != current) {
            count++;
        } else {
            current++;
        }
    }
    if(count == n)
        cout << -1 << endl;
    else
        cout << count << endl;
}


Measured memory_bytes: 1792
import java.util.Scanner;
public class Main{
    public static void main(String args[]){
	Scanner in =new Scanner(System.in);

	int r,c;

	r = in.nextInt();
	c = in.nextInt();

	int[][] table = new int[r+1][c+1];

	for(int i=0;i<r;i++){
	    for(int j=0;j<c;j++){
		table[i][j] = in.nextInt();
	    }
	}

	//0で初期化
	for(int i=0;i<r;i++){
	    table[i][c]=0;
	}
	for(int j=0;j<c;j++){
	    table[r][j]=0;
	}
	table[r][c]=0;
	
	//行の合計
	for(int i=0;i<r;i++){
	    for(int j=0;j<c;j++){
	        table[i][c]+=table[i][j];
	    }
	}
	//列の合計
	for(int j=0;j<c;j++){
	    for(int i=0;i<r;i++){
	        table[r][j]+=table[i][j];
	    }
	}
	//全要素の合計
	for(int i=0;i<r;i++){
	    table[r][c]+=table[i][c];
	}


	for(int i=0;i<=r;i++){
	    for(int j=0;j<=c;j++){
		System.out.print(table[i][j]);
		if(j!=c)System.out.print(" ");
	    }
	    System.out.println();
	}
    }
}
	


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

int main(){
long long n,k;
long long ans;
cin>>n>>k;
if(k ==1){
  cout<<0<<endl;
}
else{
ans = n%k;
if(ans>k-n%k)
  ans = k-n%k;
cout<<ans<<endl;
}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m) for (int i = 0; i < (int)(m); i++)
 
int main() {
 int K;
 cin>>K;
 for (size_t i = 0; i < K; i++)
 {
   cout<<"ACL";
 }
 
}

Measured memory_bytes: 3536
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
int main() {
	int n[4] = {}, A[1010101];
	string S;
	cin >> S;
	for (int i = 0; i < 3; i++)
		if (S[i] == 'a')
			n[0]++;
		else if (S[i] == 'b')
			n[1]++;
		else if (S[i] == 'c')
			n[2]++;
	if (n[0] == 1 && n[1] == 1 && n[2] == 1)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<double> point;
#define F first
#define S second

map<char, int> mp =
{
		{'L', 0},
		{'R', 1},
		{'U', 2},
		{'D', 3}
};

int main()
{
	#ifdef DGC
		//freopen("a.txt", "r", stdin);
		//freopen("b.txt", "w", stdout);
	#endif

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

	int n, m, k, x, y;
	cin >> n >> m >> k >> x >> y;
	string s1, s2;
	cin >> s1 >> s2;

	bool ok = false;
	vector<int> f1(4), f2(4);
	for (int i = 0; i < k; ++i)
	{
		f1[mp[s1[i]]]++;

		if (y - f1[0] + f2[1] < 1)
			ok = true;
		if (y + f1[1] - f2[0] > m)
			ok = true;
		if (x - f1[2] + f2[3] < 1)
			ok = true;
		if (x + f1[3] - f2[2] > n)
			ok = true;

		if (s2[i] == 'L' && y - f2[0] + f1[1] > 1)
			++f2[0];
		if (s2[i] == 'R' && y + f2[1] - f1[0] < m)
			++f2[1];
		if (s2[i] == 'U' && x - f2[2] + f1[3] > 1)
			++f2[2];
		if (s2[i] == 'D' && x + f2[3] - f1[2] < n)
			++f2[3];
	}

	if (!ok)
		cout << "YES\n";
	else
		cout << "NO\n";

	return 0;
}


Measured memory_bytes: 920
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  ll a, b;
  cin >> a >> b;
  cout << lcm(a, b) << endl;
  return 0;
}

Measured memory_bytes: 3616
s = gets.chomp.split('').to_a
ans = 0
0.upto(2 ** (s.size - 1) - 1) do |i|
  b = i.to_s(2).rjust(s.size - 1, "0")
  sum = s[0].dup
  1.upto(s.size - 1) do |j|
    t = s[j].dup
    if b[j - 1] == "0"
      sum.to_s.concat(t)
    else
      sum.to_s.concat("+").concat(t)
    end
  end
  ans += eval(sum)
end
puts ans

Measured memory_bytes: 1916
#include<stdio.h>
int n,m,a;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;++i){
		scanf("%d",&a);
		n-=a;
	}
	if(n<0)n=-1;
	printf("%d\n",n);
	return 0;
}

Measured memory_bytes: 1736
#include<vector>

struct TopologicalSort {
    int n;
    std::vector<std::vector<int>> G;
    std::vector<int> indeg;
    TopologicalSort(int n) : n(n), G(n, std::vector<int>()), indeg(n) {}
    void addEdge(int from, int to) {
        G[from].push_back(to);
        indeg[to]++;
    }
    std::vector<int> getSorted() {
        std::vector<int> stk, ret;
        for (int i = 0; i < n; i++) { if (indeg[i] == 0) { stk.push_back(i); }}
        while (!stk.empty()) {
            int i = stk.back();
            stk.pop_back();
            ret.push_back(i);
            for (int j = 0; j < G[i].size(); j++) {
                if (--indeg[G[i][j]] == 0) { stk.push_back(G[i][j]); }
            }
        }
        return ret;
    }
};

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

int main() {
    int V, E;
    cin >> V >> E;
    TopologicalSort ts(V);
    for (int i = 0; i < E; i++) {
        int s, t;
        cin >> s >> t;
        ts.addEdge(s, t);
    }
    vector<int> ans = ts.getSorted();
    for (int i = 0; i < V; i++) { cout << ans[i] << endl; }
}


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

int main(){
  int a,b,c,tyou=0,hishi=0;
	while(scanf("%d,%d,%d",&a,&b,&c)!=EOF){
		if(a*a+b*b==c*c)tyou++;
		else if(a==b)hishi++;
	}
	cout << tyou << '\n' << hishi << endl;
  return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll r,g,b;
    cin >> r >> g >> b;

    if((r * 100 + g * 10 + b) % 4 == 0){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

}

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

using namespace std;

int main() {
	int n;
	cin >> n;
	int* a = new int[n];
	long long** maxsum = new long long* [n];

	for (int i = 0;i < n;i++) {
		cin >> a[i];
		maxsum[i] = new long long[3];
	}
	maxsum[0][0] = maxsum[0][1] = 0;
	maxsum[0][2] = a[0];
	maxsum[1][0] = 0;
	maxsum[1][1] = maxsum[1][2] = (long long)max(a[0], a[1]);
	for (int i = 2;i < n;i++) {
		if (i % 2 == 0) {
			maxsum[i][0] = maxsum[i][1] = max(maxsum[i - 1][1], maxsum[i - 2][0] + a[i]);
			maxsum[i][2] = maxsum[i - 2][2] + a[i];
		}
		else {
			maxsum[i][0] = max(maxsum[i - 1][0], maxsum[i - 2][0] + a[i]);
			maxsum[i][1] = maxsum[i][2] = max(maxsum[i - 1][2], maxsum[i - 2][2] + a[i]);
		}
	}
	cout << maxsum[n - 1][1] << "\n";
}




Measured memory_bytes: 12224
#define ONLINE_JUDGE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

ll N;
vector<string> S;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> N;
    S = vector<string>(N);
    for(int i = 0; i < N; ++i){
        cin >> S[i];
    }
    solve();
}

// 1 <= N <= 2× 10^5
// S_i は英小文字のみからなり、長さは 1 以上 10 以下

// ll N, vector<string> S
// 何種類の景品を手に入れたか出力せよ。
void solve(){
    set<string> st;
    rep(i,N)st.insert(S[i]);
    cout<<st.size()<<endl;
}


Measured memory_bytes: 25104
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<ll> A(N), B(N);
  rep(i, N) cin >> A[i];
  rep(i, N) cin >> B[i];
  priority_queue<pair<ll, int>> Q;
  rep(i, N) Q.emplace(B[i], i);
  ll ans = 0;
  while(!Q.empty()) {
    auto top = Q.top();
    ll b = top.first;
    int i = top.second;
    ll diff = b-A[i];
    Q.pop();
    if(diff >= B[(i-1+N)%N] + B[(i+1)%N]) {
      ans += diff / (B[(i-1+N)%N] + B[(i+1)%N]);
      diff %= B[(i-1+N)%N] + B[(i+1)%N];
      B[i] = A[i]+diff;
      if(diff != 0) Q.emplace(B[i], i);
    } else {
      continue;
    }
  }
  bool ok = true;
  rep(i, N) if(A[i] != B[i]) ok = false;
  cout << (ok ? ans : -1) << endl;
  return 0;
}


Measured memory_bytes: 9328
#include <bits/stdc++.h>
#include <math.h>
#include <float.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
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; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
const int MOD = 1000000007;

int main(){
    const double PI = acos(-1.0);
    double a, b, x;
    cin >> a >> b >> x;
    x /= a;
    cout << fixed << setprecision(15);
    if (x > a*b/2) cout << atan2((a*b-x)*2/a, a)*180/PI << endl;
    else cout << atan2(b, 2*x/b)*180/PI << endl;

}

Measured memory_bytes: 4108
#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"
#include "cassert"
#include "functional"

using namespace std;

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

//const double EPS = 1e-8;

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


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

	cin >> N >> K;
	vector<pair<long long int, long long int>>v(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i].first >> v[i].second;
	}
	vector<pair<long long int, long long int>>a(pow(3, N / 2));
	vector<pair<long long int, long long int>>b(pow(3, N - N / 2));
	for (int i = 0; i < N / 2; i++) {
		int add = pow(3, i);
		for (int j = 0; j < add; j++) {
			a[j + add] = { a[j].first - v[i].first,a[j].second + v[i].second };
			a[j + 2 * add] = { a[j].first + v[i].first,a[j].second - v[i].second };
		}
	}
	for (int i = 0; i < N - N / 2; i++) {
		int add = pow(3, i);
		for (int j = 0; j < add; j++) {
			b[j + add] = { b[j].first - v[i + N / 2].first,b[j].second + v[i + N / 2].second };
			b[j + 2 * add] = { b[j].first + v[i + N / 2].first,b[j].second - v[i + N / 2].second };
		}
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	L = R = b.size() - 1;
	deque<long long int>Q;
	multiset<long long int>ms;
	long long int ans = 0;
	for (auto &i : a) {
		while (L >= 0 && i.first + b[L].first >= -K) {
			//ms.insert(-b[L--].second);
			if (Q.empty())Q.push_back(L);
			else {
				while (!Q.empty() && b[Q.back()].second < b[L].second)Q.pop_back();
				Q.push_back(L);
			}
			L--;
		}
		while (R > L&& i.first + b[R].first > K) {
			//ms.erase(ms.find(-b[R--].second));
			if (!Q.empty() && Q.front() == R) {
				Q.pop_front();
			}
			R--;
		}
		//if (!ms.empty())ans = max(ans, i.second - *ms.begin());
		if (!Q.empty())ans = max(ans, i.second + b[Q.front()].second);
	}
	cout << ans << endl;
}


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

#define int long long
signed main(){
    int n,a,b;
    cin>>n>>a>>b;
    int quo = n/(a+b);
    int rem = n-(quo*(a+b));
    int ans = quo*a;
    if(rem>a){
        ans+=a;
    }else{
        ans+=(rem);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

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

int A,B;

int main(){
    cin>>A>>B;
    if(abs(A-B)%2)out("IMPOSSIBLE");
    else out((A+B)/2);
    
}


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

int main() {
  vector<int>  sunuke(5) ; 
  
  
  for (int i = 0 ; i < 5 ; i++){
   cin >> sunuke.at(i) ;  
  }
    
  for (int i = 0 ; i < 5 ; i++){
   if(i+1 != sunuke.at(i)){
     cout << i+1 << endl ; 
   }
  }
  
  
  
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    const ll mod=998244353;
    int n;
    cin>>n;
    vector<int>d(n),p(n);
    rep(i,n)p[i]=0;
    rep(i,n){
        cin>>d[i];
        p[d[i]]++;
    }
    if(d[0]!=0||p[0]!=1){cout<<0<<endl; return 0;}
    ll ans=1;
    for(int i=1; i<n; ++i){
        ans*=p[d[i]-1];
        ans%=mod;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define MOD (long long)1000000007
#define INF (long long)998244353
using namespace std;

int main(void){
    long long n;
    cin >> n;
    long long ans=n-1;
    for(long long i=2; i*i<=n; i++){
        if(n%i==0){
            ans=min(ans,i-1+n/i-1);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define IO(x) freopen(x".in", "r", stdin); freopen(x".out", "w", stdout);
const int INF = 0x3f3f3f3f;
//void upd(ll &x,ll y) { x=(x+y)%mod; }
int n;
int main()
{ 
    cin>>n;
    int lim=0,rank;
    for(int i=1;i<=n;i++)
    {
    	int a,b;
    	scanf("%d%d",&a,&b);
    	if(a>lim) 
		{
			lim=a;
			rank=b;
		}
	}
	cout<<lim+rank;
	return 0;
}

Measured memory_bytes: 256
n, m = [int(i) for i in input().split()]
a = [0 for i in range(n)]
for i in range(m):
    u, v = [int(j) for j in input().split()]
    a[u - 1] += 1
    a[v - 1] += 1

for i in range(n):
    print(a[i])

Measured memory_bytes: 3060
//package BeginnerContest145;

import java.util.*;
import java.io.*;

public class Main {
    static TreeSet<String> perm;

    public static void perms(String s, int i){
        perm.add(s);
        for(int x = i; x<s.length(); x++){
            char[] swap = s.toCharArray();
            char a = swap[i];
            char b = swap[x];
            swap[x] = a;
            swap[i] = b;
            perms(new String(swap), i+1);
        }
    }
    public static void main(String[] args) throws IOException {
        FastReader sc = new FastReader();
        PrintWriter pw = new PrintWriter(System.out);
        perm = new TreeSet<>();
        int n = sc.nextInt();
        StringBuilder s = new StringBuilder();
        for(int i = 1; i<=n; i++){
            s.append(String.valueOf(i));
        }
        String k = s.toString();
        perms(k, 0);
        int[] x = new int[n];
        int[] y = new int[n];
        for(int i = 0; i<n; i++){
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
        }
        double total = 0;
        for(String p : perm){
            double t = 0;
            //pw.println(p);
            for(int i = 0; i<n-1; i++){
                int t1 = Integer.parseInt(p.substring(i,i+1));
                int t2 = Integer.parseInt(p.substring(i+1, i+2));
                t1--;
                t2--;
                t += Math.sqrt((x[t1] - x[t2])*(x[t1] - x[t2]) + (y[t1] - y[t2])*(y[t1] - y[t2]));
            }
            //pw.println(t);
            total+=t;
        }
        pw.println(total / perm.size());
        pw.close();



    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 47104
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdint>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;

int N;
vector<int> A;
vector<int> B;
vector<int> C;

int main(){
    cin >> N;
    A=vector<int>(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    B=vector<int>(N);
    for(int i=0;i<N;i++){
        cin >> B[i];
    }
    C=vector<int>(N);
    for(int i=0;i<N;i++){
        cin >> C[i];
    }

    std::sort(A.begin(),A.end());
    std::sort(B.begin(),B.end());
    std::sort(C.begin(),C.end());

    long ans=0;

    vector<long> ans_b(N);
    ans_b[0]=std::lower_bound(A.begin(),A.end(),B[0])-A.begin();
    for(int i=1;i<N;i++){
        ans_b[i]=std::lower_bound(A.begin(),A.end(),B[i])-A.begin() + ans_b[i-1];
    }

    for(int c : C){
        auto low_b=std::lower_bound(B.begin(),B.end(),c);
        if(low_b!=B.begin()){
            ans+=ans_b[low_b-B.begin()-1];
        }
    }

    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
//#define ull unsigned  long  long
#define int long long int
#define lld long double
#define endl "\n"
#define S second
#define F first
#define pir      pair<int,int>
#define vtr      vector<int>
#define mpp      map<int,int>
#define pb       push_back
#define popb     pop_back()
#define mk       make_pair
#define stc      set<char>
#define st       set<int>
#define stk      stack<int>
#define ctn      continue
#define MOD      1000000007
#define fr(i,a,b)   for(int i=a;i<b;i++)
#define rfr(i,a,b)  for(int i=a-1;i>=b;i--)
#define must        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

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

int myfun(int x,int y)
{
    return x*y;
}
void primeFactors(int n)
{
    while (n%2 == 0)
    {
        cout<<2<<endl;
        n = n/2;
    }
    for (int i = 3; i <= sqrt(n); i = i+2)
    {
        while (n%i == 0)
        {
            cout<<i<<endl;
            n = n/i;
        }
    }
    if (n > 2)
        cout<<n<<endl;
}

void fillPrefixSum(int a[], int N, int prefixSum[])
{
    prefixSum[0] = a[0];

    for (int i = 1; i < N; i++)
        prefixSum[i] = prefixSum[i-1] + a[i];
}
int is_sorted(int a[],int n)
{
    for(int i=0;i<n-1;i++)
    {
        if(a[i]>a[i+1])
            return false;
    }
    return true;
}

int factorial(int n)
{
    return (n==1 || n==0) ? 1: n * factorial(n - 1);
}

int findlcm(vtr a, int n) 
{ 
    // Initialize CNTult 
    int cnt = a[0]; 
  
    // cnt contains LCM of a[0], ..a[i] 
    // after i'th iteration, 
    for (int i = 1; i < n; i++) 
        cnt = (((a[i] * cnt)) / 
                (gcd(a[i], cnt))); 
  
    return cnt; 
} 



int power(int x,  int y, int p)
{
    int CNT = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            CNT = (CNT*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return CNT;
}

bool peli(string s)
{
    int right=s.length();
    int j;
    for(int i=0,j=right-1;i<=j;i++,j--)
    {
        if(s[i]!=s[j])
        {
            return false;
        }
    }
    return true;
}


void Solve1()
{
    int n;
    cin>>n;
    vtr v(n+1);
    for(int i=1;i<n;i++)
    {
        v[i]++;
        for(int j=2;j*i<n;j++)
        {
            v[i*j]++;
        }
    }
    int cnt=0;
    for(int i=1;i<n;i++)
    {
        cnt+=v[i];
    }
    cout<<cnt<<endl;
}


signed main()
{

    must;
    int tt=1;
    //cin >> tt;
    while(tt--)Solve1();
    //double ttt;
    //ttt=double(e-s)/double(CLOCKS_PER_SEC);
    //cout<<fixed<<ttt<<setprecision(5)<<endl;
    return 0;
}


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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

template <class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

struct Edge {
    ll to, rev;
    long double cap;
    Edge(ll _to, long double _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph &G, ll from, ll to, long double cap, bool revFlag,
              long double revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {
    ll n;
    cin >> n;
    vec<ll> p(n), q(n);
    REP(i, n) {
        cin >> p[i];
    }
    REP(i, n) {
        cin >> q[i];
    }

    vec<ll> o(n);
    REP(i, n) {
        o[i] = i + 1;
    }

    ll con = 0;
    int a = 0;
    int b = 0;
    do {
        if(o == p)
            a = con;
        if(o == q)
            b = con;
        con++;
    } while(next_permutation(all(o)));

    cout << abs(a - b) << en;
}

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

    solve();

    /*
    ll t;
    cin >> t;
    REP(i, t) { solve();}
    */

    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  bool b = true;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    if (A.at(i) % 2 == 0 && A.at(i) % 3 != 0 && A.at(i) % 5 != 0) {
      b = false;
      break;
    }
  }
  if (b) {cout << "APPROVED" << endl;}
  else {cout << "DENIED" << endl;}
}

Measured memory_bytes: 3584
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
#define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;


struct UnionFind {
    vector<int> par;
        
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int find(int x) {
        if (par[x] < 0) return x;
        else return par[x] = find(par[x]);
    }
    
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[find(x)];
    }
};



signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll ans=0;
    vii x,y;
    const int MAX=110000;
    cin>>n;
    x.resize(n);
    y.resize(n);
    UnionFind uf(MAX*2);
    rep(i,n){
        cin>>x[i]>>y[i];
        uf.unite(x[i],y[i]+MAX);
    }
    map<int ,ll> mx,my;
    rep(i,MAX){
        mx[uf.find(i)]++;
    }
    rep2(i,MAX,MAX*2){
        my[uf.find(i)]++;
    }
    rep(i,MAX*2){
        ans+=mx[i]*my[i];
    }
    cout<<ans-n<<endl;
    return 0;
}

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<pair<int,string>> sub(m);
    rep(i,m) cin >> sub[i].first >> sub[i].second;

    int ac = 0, pena = 0;
    map<int,int> mp;
    rep(i,m) {
        int p = sub[i].first;
        string s = sub[i].second;
        if(mp[p] == -1) continue;
        if(s == "WA"){
            mp[p]++;
        } else {
            ac++;
            pena += mp[p];
            mp[p] = -1;
        }
    }
    cout << ac << " " << pena << endl;
}


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


int main(){
    int64_t n, ans = 0;
    cin >> n;
    vector<int64_t> vec(n);

    cin >> vec.at(0);
    int64_t t = vec.at(0);
    
    for(int i = 1; i < n; i++){
        cin >> vec.at(i);
        if(vec.at(i) < t ){
            ans += t - vec.at(i);
        }else{
            t = vec.at(i);
        }
         
    }

    cout << ans << endl;

}

Measured memory_bytes: 4824