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

int main()
{
    int i = 0;
    int n,l;
    cin >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    int num = INF;
    int ans = 0;
    for (const auto &e : p)
    {
        if(e<=num){
            num = e;
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
n = int(input())
t, a = map(int, input().split())
h = input().split()
for i in range(n):
    h[i] = int(h[i])

min = 100000
min_t = 0
for i in range(n):
    if abs(a - (t - h[i] * 0.006)) < min:
        min_t = i
        min = abs(a - (t - h[i] * 0.006))
print(min_t+1)


Measured memory_bytes: 9240
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
 
int main() {
	int N; cin >> N;
    vector<int> b(N); 
    rep(i, N) cin >> b[i];
    vector<int> a;

    while(!b.empty()) {
        int found = 0;
        per (i, (int) b.size()) {
            if (b[i] == i + 1) {
                a.push_back(i + 1);
                b.erase(b.begin() + i);
                found = 1;
                break;
            }
        }
        if(!found) {
            cout << -1 << '\n';
            return 0;
        }
    }

    reverse(a.begin(), a.end());
    rep(i, N) cout << a[i] << '\n';

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long

int n;
lin a[100001];

int main(void)
{
    cin >> n;
    rep(i, n)
    {
        cin >> a[i];
    }

    sort(a, a + n);

    int i = n - 1;
    int k = 0;
    lin tk = min(a[k], a[i] - a[k]);
    loop(j, 1, i)
    {
        lin tj = min(a[j], a[i] - a[j]);
        if(tk < tj)
        {
            k = j;
            tk = tj;
        }
    }

    cout << a[i] << " " << a[k] << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

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

const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

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

	int n;
	cin >> n;
	vector<int> v(n);
	rep(i, n) cin >> v[i];
	int mean = accumulate(all(v), 0) / n;
	ll min_v = INF;
	for (int m = -1; m < 2; m++) {
		ll ans = 0;
		rep(i, n) {
			int a = v[i] - mean + m;
			ans += a * a;
		}
		chmin(min_v, ans);
	}
	cout << min_v << endl;
}


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

using namespace std;

int main()
{
  int64_t n;

  cin >> n;

  deque<int64_t> dq;

  int64_t ans = 0;

  for(int64_t i = 0;
      i < n;
      ++i)
    {
      int64_t p;
      cin >> p;
      dq.push_back(p);
      if(i >= 2)
        {
          if(dq[0] > dq[1] && dq[1] > dq[2])
            {
              ++ans;
            }
          if(dq[0] < dq[1] && dq[1] < dq[2])
            {
              ++ans;
            }
          dq.pop_front();
        }
    }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
n,m = map(int,input().split())
pi = [int(i) for i in input().split()]

xy = [[] for j in range(n+1)]

for i in range(m):
    x,y = map(int,input().split())
    xy[x].append(y)
    xy[y].append(x)
    
path = [[] for i in range(n+1)]
#check = [0] * (n+1)

check = [-1]*(n+1)

def dfs(x,check):
    #if check[x] != -1:
    #    return
    for i in range(len(xy[x])):
        cho = xy[x][i]
        #print(cho,x)
        if check[cho] != -1:
            continue
        check[cho] = num
        dfs(cho,check)
    
    return

num = 0
for i in range(1,n+1):
    #print(i,check[i])
    if check[i] != -1:
        continue
    if len(xy[i]) == 0:
        continue
    dfs(i,check)
    num += 1
#print(check)
ans = 0

for i in range(1,n+1):
    if pi[i-1] == i:
        ans += 1
    elif check[pi[i-1]] == -1:
        continue
    elif check[i] == check[pi[i-1]]:
        ans += 1
print(ans)


Measured memory_bytes: 89700
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n; ll k;
	cin>>n>>k;
	vector<int>per(n+1);
	vector<ll>arr(n+1);
	for(int i=1; i<=n; i++)
	 cin>>per[i];
	for(int i=1; i<=n; i++)
	 cin>>arr[i];
	vector<ll>adj[n+1];
	vector<ll>moves(n+1);
	for(int i=1; i<=n; i++){
		ll sum=0;
		adj[i].push_back(sum);
		int start=i;
		int pos=per[start];
		sum+=arr[pos];
		adj[i].push_back(sum);
		int cnt=1;
		while(pos!=start){
			pos=per[pos];
			sum+=arr[pos];
			adj[i].push_back(sum);
			cnt++;
		}
		moves[i]=cnt;
		adj[i][0]=adj[i].back();
	}
	ll ans=(-2e18);
	for(int i=1; i<=n; i++)
	{
		if(adj[i][0]<=0)
		{
			for(int j=1; j<=min(k,moves[i]); j++)
			 ans=max(ans,adj[i][j]);
		}
		else{
			for(int j=1; j<=min(k,moves[i]); j++){
				ll temp1=adj[i][j];
				temp1=temp1+adj[i][0]*((k-j)/moves[i]);
				ans=max(ans,temp1);
			}
		}
	}
	cout<<ans;
	return 0;
	
}

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

using namespace std;

int main() {
  int x;
  cin >> x;
  int coin = 0;
  while (x >= 500) {
    if (x >= 500) {
      x -= 500;
      coin += 1000;
    }
  }
  while (x > 5) {
    if (x > 5) {
      x -= 5;
      coin += 5;
    }
  }
  
  cout << coin << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	string s;
  	cin>>s;
  	int ans=1000;
  	for (int i=0;i<s.size()-3+1;i++){
    	int a=stoi(s.substr(i,3));
      	ans=min(abs(753-a),ans);
    }
  	cout<<ans<<endl;  	
  	
}


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

#define ld long double
#define ll long long
#define ull unsigned long long

#define f first
#define s second

#define endl '\n'
#define pii pair <ll, ll>

#define ios ios_base::sync_with_stdio(0), cin.tie()
#define pb push_back
#define mp make_pair

#define pi 3.14159265358979323846264
#define y1 abacaba
 
#define fn "abc"

using namespace std;

const int MXN = 1e6 + 30;
const int MAXN = 1e3 + 2;
const ll INF = 1e9 + 7;
const ll BINF = 1e16;
const int mod = 1e9 + 7;
const ld EPS = 1e-15;   
const ll dx[] = {0, 0, 1, -1};
const ll dy[] = {1, -1, 0, 0};

int n, w, h;

int main(){

    #ifdef DIAS
        freopen("input.txt", "r", stdin);
    #elif NAME 
    	freopen(fn".in", "r", stdin);
    	freopen(fn".out", "w", stdout);
    #endif       
    cin >> n;
    cin >> w >> h;
    cout << (n - w + 1) * (n - h + 1);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
const ll INF = 1LL<<60;
typedef pair<ll, ll> P;

int main() {
    cin>>N>>S;
    mat lsum(N+2, vec(3, 0)), rsum(N+2, vec(3, 0));
    vector<char> c = {'R', 'G', 'B'};
    rep(i,N){
        rep(j,3) lsum[i+1][j] = lsum[i][j] + (S[i] == c[j]);
    }
    Rrep(i,N){
        rep(j,3) rsum[i+1][j] = rsum[i+2][j] + (S[i] == c[j]);
    }
    ll ans = 0;
    rep(i,N){
        rep(j,3){
            rep(k,j){
                if(c[j] != S[i] && c[k] != S[i]){
                    ans += lsum[i][j] * rsum[i+2][k];
                    ans += lsum[i][k] * rsum[i+2][j];
                }
            }
        }
    }
    for(int r = 1; r * 2 < N; ++r){
        for(int i = 0; i + r * 2 < N; ++i){
            if(S[i] != S[i+r] && S[i+r] != S[i+r*2] && S[i+r*2] != S[i]) --ans;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3996
#include <stdio.h>

int
main(void)
{
    int n;
    scanf("%d", &n);
    int a[n][n];
    int i, j;
    for (i = 0; i < n; ++i)
        for (j = 0; j < n; ++j)
            scanf("%d", &a[i][j]);

    int k;
    long sum = 0;
    for (i = 0; i < n; ++i) {
        for (j = i+1; j < n; ++j) {
            int found = 1;
            for (k = 0; k < n; ++k) {
                if (k == i || k == j)
                    continue;
                int compound = a[i][k] + a[j][k];
                if (a[i][j] == compound) {
                    found = 0;
                    continue;
                }
                if (a[i][j] > compound) {
                    printf("-1\n");
                    return 0;
                }
            }
            if (found)
                sum += a[i][j];
        }
    }
    printf("%ld\n", sum);
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include<string.h>
int main(void) {
	// your code goes here
	char ch[1000];
	scanf("%s",ch);
	int i;
	int p=strlen(ch);
	int max=0,c=0;
	for(int i=0;i<p;i++)
	{
        if(ch[i]=='R')
        {
            c=c+1;
        }
        else if(ch[i]=='S')
        {
            c=0;
        }
        if(max<c)
        {
            max=c;
        }
	}
	printf("%d\n",max);
	return 0;
}



Measured memory_bytes: 1736
n = int(input())
point = []
for i in range(n):
    x_, y_ = map(int, input().split())
    point.append([x_, y_])

point.sort(key=lambda x: x[1])
point.sort(key=lambda x: x[0])
ans = 0
x = []
y = []
for i in range(n):
    x.append(point[i][0])
    y.append(point[i][1])

for i in range(n):
    for j in range(i+1, n):
        count = 0
        p = x[j] - x[i]
        q = y[j] - y[i]
        for k in range(n):
            for l in range(k+1, n):
                if (x[l] - x[k] == p) and (y[l] - y[k] == q):
                    count += 1
        ans = max(ans, count)

print(n - ans)


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

int main() {
    int x,n;
    cin>>x>>n;
    
    if(n == 0) {
        cout<<x<<endl;
        return 0;
    }
    
    bool flag = true;
    map<int,int> m;
    
    for(int i=0;i<n;i++) {
        int num;
        cin>>num;
        if(num == x) {
            flag = false;
        }
        m[num] = m[num]+1;
    }
    
    if(flag) {
        cout<<x<<endl;
        return 0;
    }
    int low = x-1;
    
    while(1) {
        if(m[low] == 0) {
            break;
        } else {
            low--;
        }
    }
    
    int high = x+1;
    
    while(1) {
        if(m[high] == 0) {
            break;
        } else {
            high++;
        }
    }
    
    if(abs(low-x) <= abs(high-x)) {
        cout<<low<<endl;
    } else {
        cout<<high<<endl;
    }
    return 0;
}

Measured memory_bytes: 3632
class Union_find(object):
    def __init__(self, N):
        #親の番号を格納する。親だった場合は-(その集合のサイズ)
        self.parent = [-1]*(N)
    #Aがどのグループに属するか
    def root(self, A):
        if self.parent[A] < 0:
            return A
        else:
            #親を繋ぎ変えて高速化
            self.parent[A] = self.root(self.parent[A])
            return self.parent[A]
    def size(self, A):
        return -self.parent[self.root(A)]
    # A,Bをくっつける
    def connect(self, A, B):
        # A,Bを直接つなぐのでなく、root(A),root(B)をつなぐ
        A = self.root(A)
        B = self.root(B)
        if A == B:
            return False
        # 大きい方に小さい方をくっつける
        if self.size(A) < self.size(B):
            A, B = B, A
        self.parent[A] += self.parent[B]
        self.parent[B] = A
        return True

N, M = list(map(int, input().split()))
A = []
B = []
for _ in range(M):
    a, b = list(map(int, input().split()))
    A.append(a-1)
    B.append(b-1)
uni = Union_find(N)
result = []
unconv = int(N*(N-1)/2)
for a, b in zip(reversed(A), reversed(B)):
    result.append(unconv)
    size_a = uni.size(a)
    size_b = uni.size(b)
    if uni.connect(a, b):
        unconv -= size_a*size_b
for r in reversed(result):
    print(r)


Measured memory_bytes: 16912
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
const int mod = 1000000007;
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")


P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}



int main(){
  
  int r;cin>>r;
  cout << 3*r*r << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#include <string>
int main(){
string b, c, d, e, f;
cin >> b;
c=b[0];
d=b[1];
e=b[2];
f=b[3];
if (c=="Y" & d=="A" & e=="K" & f=="I"){
	cout<<"Yes";

}
else{
	cout<<"No";
}
}

















Measured memory_bytes: 256
#include <cstdio>
	#include <string>
	#include <iostream>
	#include <algorithm>
	#include <cmath>

	using namespace std;
	using ll=long long int;
	int n,a[100];

	int main(){
		scanf("%d",&n);
		for(int i=0;i<n;i++) scanf("%d",&a[i]);
		int r=100000000;
		for(int k=-100;k<=100;k++){
			int c=0;
			for(int i=0;i<n;i++) c+= pow(a[i]-k,2);
			r=min(r,c);
		}
		printf("%d",r);
		return 0;
	}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int n,m,q,a[11],b[21],x[53],y[53],z[53],w[53],aw;
int main(){
	cin>>n>>m>>q;
	for(int i=1;i<=q;i++)
		cin>>w[i]>>x[i]>>y[i]>>z[i];
	for(int i=1;i<m;i++)
		b[i]=0;
	for(int i=m;i<m+n;i++)
		b[i]=1;
	do{
		int s=1,d=1,p=0;
		for(int i=1;i<m+n;i++)
			if(!b[i])
				s++;
			else
				a[d++]=s;
		for(int i=1;i<=q;i++)
			if(a[x[i]]-a[w[i]]==y[i])
				p+=z[i];
		aw=max(aw,p);
	}while(next_permutation(b+1,b+m+n));
	cout<<aw;
	return 0;
}

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

int N;
vector<long long> A;
vector<long long> Left, Right, M;

template<class T> long long makegcd(T a, T b) {
    T large = (a > b) ? a : b;
    T small = (a < b) ? a : b;
    if(small == 0) return large;
    if (large % small == 0) return small;
    else return makegcd(small, large%small);
}

int main() {
    scanf("%d", &N);
    A.resize(N); M.resize(N);
    Left.resize(N+1); Right.resize(N+1);
    for (int i = 0; i < N; i++) scanf("%Ld", & A[i]);

    Left[0] = 0; Right[N] = 0;
    for (int i = 1; i < N+1; i++) {
        int j = N - i;
        Left[i] = makegcd(Left[i-1], A[i-1]);
        Right[j] = makegcd(Right[j+1], A[j]);
    }
    for (int i = 0; i < N; i++) M[i] = makegcd(Left[i], Right[i+1]);

    long long maxgcd = *max_element(M.begin(), M.end());

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


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

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int n = sc.nextInt();
        int m = sc.nextInt();
        int x = sc.nextInt();
        int[] c = new int[n];
        int[][] a = new int[n][m];

        for (int i = 0; i < n; i++) {
            c[i] = sc.nextInt();
            for (int j = 0; j < m; j++) {
                a[i][j] = sc.nextInt();
            }
        }

        int ans = Integer.MAX_VALUE;
        for (long i = (1 << n)-1; i > 0; i--) {
            long tmp = i;
            int cash = 0;
            int[] exp = new int[m];
            for (int j = n-1; j >= 0; j--) {
                long t = tmp >> j;
                if (t > 0) {
                    for (int k = 0; k < m; k++) {
                        exp[k] += a[j][k];
                    }
                    cash += c[j];
                }
                tmp -= t << j;
            }

            boolean isExp = true;
            for (int j = 0; j < m; j++) {
                if (exp[j] < x) {
                    isExp = false;
                    break;
                }
            }
            if (isExp)
                ans = Math.min(cash, ans);
        }

        if (ans == Integer.MAX_VALUE)
            System.out.println(-1);
        else
            System.out.println(ans);
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

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

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

Measured memory_bytes: 27004
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys

INF = float('inf')


def solve(N: int, K: int, H: "List[int]"):
    return sum(sorted(H)[:-K]) if K != 0 else sum(H)


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    H = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(f'{solve(N, K, H)}')


if __name__ == '__main__':
    main()


Measured memory_bytes: 94688
#include<iostream>
#include<string>

using namespace std;

int main() {
	string o, e;
	cin >> o >> e;
	for (int i = 0; i < o.size(); i++) {
		cout << o[i];
		if (i < e.size())cout << e[i];
	}
	cout << endl;
	return 0;
} 

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

int main(){
	int n; cin >> n;
	vector<int> v;
	for(int i = 0; i < n; ++i){
		int a; cin >> a;
		v.push_back(a);
	}
	sort(v.begin(), v.end());
	int ans = 0;
	for(int i = 0; i < v.size() - 1; ++i){
		if(v[i] == v[i + 1]) ++ans;
	}
	cout << v.size() - ans - ans % 2 << endl;
	return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int n,m; cin >> n >> m;
  int ans = n*(n-1) + m*(m-1);
  COUT(ans/2);
  return 0;
}


Measured memory_bytes: 256
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#define MAX_N 100
#define MAX_M (MAX_N * MAX_N)
 
typedef struct EDGE {
    int to;
    struct EDGE *next;
} edge;
 
int size;
edge buff[MAX_M];
edge *adj[MAX_N];
 
void add_edge(int u, int v) {
    edge *e = buff + size++;
    e->to = v;
    e->next = adj[u];
    adj[u] = e;
}
 
typedef int data_t;
data_t queue[MAX_N];
int head, tail;
 
void enqueue(data_t data) {
    queue[tail++] = data;
}
 
data_t dequeue() {
    return queue[head++];
}
 
bool empty() {
    return head == tail;
}
 
int dist[MAX_N];
 
void bfs(int s) {
    edge *e;
 
    memset(dist, -1, sizeof(dist));
    dist[s] = 0;
    enqueue(s);
 
    while(!empty()) {
        const int u = dequeue();
        for(e = adj[u]; e != NULL; e = e->next) {
            if(dist[e->to] == -1) {
                dist[e->to] = dist[u] + 1;
                enqueue(e->to);
            }
        }
    }
}
 
int main() {
    int n;
    int u, k;
    int i, j;
    int v;
 
    scanf("%d", &n);
    for(i = 0; i < n; ++i) {
        scanf("%d %d", &u, &k);
        for(j = 0; j < k; ++j) {
            scanf("%d", &v);
            add_edge(u - 1, v - 1);
        }
    }
 
    bfs(0);
    for(u = 0; u < n; ++u) {
        printf("%d %d\n", u + 1, dist[u]);
    }
 
    return EXIT_SUCCESS;
}



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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;
int ans,n,hi;
int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);

  cin>>n;
  for (int i=0; i<n; i++) {
    int x; cin>>x;
    ans += x>=hi;
    hi=max(x,hi);
  }
  cout<<ans;
  

  return 0;
}


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

int N;
std::vector<int> color(9, 0);
int main() {
    std::cin >> N;

    int a;
    for(int i=0; i<N; ++i) {
        std::cin >> a;
        if(a >= 3200) {
            a = 3200;
        }
        ++color[a/400];
    }

    int cnt = 0;
    for(int i=0; i<8; ++i) {
        if(color[i] > 0) {
            ++cnt;
        }
    }

    int min = std::max(cnt, 1), 
        max = cnt + color[8];
    std::cout << min << " " << max << std::endl;
}

Measured memory_bytes: 256
import collections
N = int(input())
L = collections.Counter([int(T) for T in input().split()]).most_common()
Count = 0
for A in range(0,len(L)):
    for B in range(A+1,len(L)):
        for C in range(B+1,len(L)):
            if (L[A][0]+L[B][0]>L[C][0]) and (L[B][0]+L[C][0]>L[A][0]) and (L[C][0]+L[A][0]>L[B][0]):
                Count += L[A][1]*L[B][1]*L[C][1]
print(Count)

Measured memory_bytes: 9456
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

class Doubling{
public:
	vector<vector<int> > table, G;
	vector<int> dep;
	int n, logn = 1;
	void init(int N){
		n = N;
		while((1<<logn) <= N)logn++;
		G.resize(N);dep.resize(N);
		table.resize(logn);
		rep(i,logn)table[i].resize(N);
	}
	void add_edge(int u, int v){	//木
		G[u].pb(v);G[v].pb(u);
	}
	void dfs(int v, int par){
		table[0][v] = par;
		if(par != -1)dep[v] = dep[par]+1;
		rep(i,G[v].size())if(G[v][i] != par)dfs(G[v][i], v);
	}
	void build(int root=0){
		dfs(root, -1);
		rrep(i,logn-1)rep(j,n){
			if(table[i-1][j] == -1)table[i][j] = -1;
			else table[i][j] = table[i-1][table[i-1][j]];
		}
	}
	int lca(int u, int v){
		if(dep[u] > dep[v])swap(u, v);
		rep(i,logn)if((dep[v]-dep[u]) & (1<<i))v = table[i][v];
		if(v == u)return v;
		drep(i,logn-1,0){
			if(table[i][u] == -1)continue;
			if(table[i][u] != table[i][v]){u = table[i][u];v = table[i][v];}
		}
		return table[0][v];
	}
	int distance(int u, int v){
		return dep[u]+dep[v]-2*dep[lca(u, v)];
	}
};

vector<P> edge;
int dis[2000][2000];
int n, k;
signed main(){
	scanf("%lld%lld", &n, &k);
	Doubling D;D.init(n);
	rep(i,n-1){
		int x, y;
		scanf("%lld%lld", &x, &y);x--;y--;
		D.add_edge(x, y);
		edge.pb(P(x, y));
	}
	D.build();
	rep(i,n)rep(j,n)dis[i][j] = D.distance(i, j);
	
	int ans = INF;
	if(k%2 == 1){
		rep(i,edge.size()){
			int u = edge[i].fi, v = edge[i].se, res = 0;
			rep(j,n)res += min(dis[u][j], dis[v][j]) > k/2;
			chmin(ans, res);
		}
	}else{
		rep(i,n){
			int res = 0;
			rep(j,n)if(dis[i][j] > k/2)res++;
			chmin(ans, res);
		}
	}
	
	printf("%lld\n", ans);
	return 0;
}







Measured memory_bytes: 31872
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
while(true){
        int m = sc.nextInt();
        int f = sc.nextInt();
        int r = sc.nextInt();
        int c;
        c = m + f;
            if (m == -1 && f == -1 && r == -1) {
                break;
            }
            if (m == -1 || f == -1) {
                System.out.println("F");
            }
                else if (c >= 80) {
                System.out.println("A");
            }   else if (c >= 65) {
                System.out.println("B");
            }   else if (c >= 50 || (c < 50 && r >= 50)) {
                System.out.println("C");
            }   else if (c >= 30 && r < 50) {
                System.out.println("D");
            }
                else if (c < 30) {
                System.out.println("F");
                }
        }
    }
}


Measured memory_bytes: 26472
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#include<assert.h>
#include<chrono>
#include<random>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
template<typename T>inline void chkmin(T &x,T y){x=x<y?x:y;}
template<typename T>inline void chkmax(T &x,T y){x=x>y?x:y;}
const int MAXN=500005;
struct node
{
	double t,v;node(){}
	node(double _t,double _v){t=_t;v=_v;}
	friend node operator +(node n1,node n2){return node((n1.t*n1.v+n2.t*n2.v)/(n1.v+n2.v),n1.v+n2.v);}
}li[MAXN];int hd,tl;
int n,L,T[MAXN],V[MAXN];
int main()
{
	n=read();L=read();
	for(int i=1;i<=n;i++)T[i]=read(),V[i]=read();
	double sum=0,SIZ=0;hd=1;
	for(int i=1;i<=n;i++)
	{
		node temp=node(0,0);
		while(hd<=tl&&SIZ-temp.v+V[i]>L)temp=temp+li[hd++];
		sum-=temp.t*(SIZ+V[i]-L);temp.v-=(SIZ+V[i]-L);SIZ=L-V[i];
		if(temp.v)li[--hd]=temp;
		temp=node(T[i],V[i]);sum+=1.0*T[i]*V[i];SIZ=L;
		while(hd<=tl&&li[tl].t>=temp.t)temp=temp+li[tl--];
		li[++tl]=temp;
		printf("%.6lf\n",sum/L);
	}
	return 0;
}



Measured memory_bytes: 20224
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from pprint import pprint
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def BellmanFord(g, s):
    V = list(g.keys())
    for v in g.values():
        V.extend(list(v.keys()))
    V = set(V)

    dist = defaultdict(lambda: sys.maxsize)
    pred = defaultdict(lambda: -1)

    dist[s] = 0

    N = len(V)
    for i in range(N+1):
        for u in g:
            for v in g[u]:
                if dist[v] > dist[u] + g[u][v]:
                    if i == N:
                        return 'inf'
                    dist[v] = dist[u] + g[u][v]
                    pred[v] = u
    return dist


@mt
def slv(N, M, ABC):
    g = defaultdict(dict)
    g_ = defaultdict(dict)
    for a, b, c in ABC:
        g_[b][a] = c

    reachable = [N]
    q = [N]
    while q:
        v = q.pop()
        for u in g_[v]:
            if u not in reachable:
                reachable.append(u)
                q.append(u)
    reachable = set(reachable)
    for a, b, c in ABC:
        if a in reachable and b in reachable:
            g[a][b] = -c

    dist = BellmanFord(g, 1)
    if dist == 'inf':
        return 'inf'
    return -1*dist[N]


def main():
    N, M = read_int_n()
    ABC = [read_int_n() for _ in range(M)]

    print(slv(N, M, ABC))


if __name__ == '__main__':
    main()


Measured memory_bytes: 8136
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int n, m;
    string s;
    cin >> n >> m >> s;
    reverse(s.begin(), s.end());
    vector<int> trace(n+1, -1);
    vector<int> st = {0};
    trace[0] = 0;
    while(!st.empty()) {
        int f = st.back(); st.pop_back();
        // cout << "visit " << f << endl;
        for(int i = 1; i <= m; i++) {
            if (f+i > n || s[f+i] == '1' || trace[f+i] != -1)
                continue;
            trace[f+i] = f;
            // cout << f+i << endl;
            if (f+i == n) {
                int ptr = f+i;
                vector<int> ans;
                while (ptr != 0) {
                    ans.push_back(ptr - trace[ptr]);
                    ptr = trace[ptr];
                    // cout << "trace " << ptr << endl;
                }
                // reverse(ans.begin(), ans.end());
                for(int val: ans)
                    cout << val << " ";
                return 0;
            }
            st.push_back(f+i);
        }
    }
    cout << -1 << endl;
    return 0;
}



Measured memory_bytes: 1480
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;

typedef pair<int, int> P;

struct EDGE {
	int to, cost;
};

int n, m, k;
vector<EDGE> g[3000];
vector<int> st;
int d[3000];
int d_mid[3000][3000];

void add_edge(int a, int b, int l)
{
	g[a].push_back((EDGE){b, l * 2});
	g[b].push_back((EDGE){a, l * 2});
}

void search()
{
	priority_queue<P, vector<P>, greater<P> > que;
	
	for (int i = 0; i < n; i++) d[i] = INF;
	for (int i = 0; i < st.size(); i++){
		que.push(P(0, st[i]));
	}
	
	for (; que.size(); que.pop()){
		P p = que.top();
		if (d[p.second] != INF) continue;
		d[p.second] = p.first;
		for (int i = 0; i < g[p.second].size(); i++){
			EDGE &e = g[p.second][i];
			if (d[e.to] != INF) continue;
			que.push(P(p.first + e.cost, e.to));
		}
	}
}

int main()
{
	scanf("%d %d %d", &n, &m, &k);
	for (int i = 0; i < m; i++){
		int a, b, l;
		scanf("%d %d %d", &a, &b, &l);
		add_edge(--a, --b, l);
	}
	
	for (int i = 0; i < k; i++){
		int s;
		scanf("%d", &s);
		st.push_back(--s);
	}
	
	search();
	for (int v = 0; v < n; v++){
		for (int i = 0; i < g[v].size(); i++){
			EDGE &e = g[v][i];
			d_mid[v][e.to] = (d[v] + d[e.to] + e.cost) / 2;
		}
	}
	
	int res = 0;
	for (int i = 0; i < n; i++){
		res = max(res, d[i]);
	}
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			res = max(res, d_mid[i][j]);
		}
	}
	printf("%d\n", (res + 1) / 2);
	
	return 0;
}

Measured memory_bytes: 39260
#include <iostream>
using namespace std;
int main() {
    string S,T,U;
    int A,B;
    cin >>S>>T;
    cin>>A>>B;
    cin>>U;
    if (S==U){
        A-=1;
    } else if (T==U){
        B-=1;
    }
    cout<<A<<" "<<B;
    return 0;
}


Measured memory_bytes: 888
#include <algorithm>
#include <iostream>
#include <vector>
#include <utility>
#include <map>

int main()
{
  long long ncards, noperations;
  std::cin >> ncards >> noperations;
  std::map<long long, long long> card;
  for (long long i = 0; i < ncards; i++) {
    long long v;
    std::cin >> v;
    card[v]++;
  }
  for (long long i = 0; i < noperations; i++) {
    long long cnt, num;
    std::cin >> cnt >> num;
    card[num] += cnt;
  }
  long long result = 0;
  long long cnt = ncards;
  for (auto it = card.rbegin(); it != card.rend(); it++) {
    if (it->second <= cnt) {
      cnt -= it->second;
      result += it->first * it->second;
    } else {
      result += it->first * cnt;
      cnt = 0;
    }
    if (cnt == 0) {
      break;
    }
  }
  std::cout << result << '\n';
  return 0;
}


Measured memory_bytes: 12800
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){
    
    ll n;
    cin >> n;
    n--;
    
    P(n*(n+1)/2);
   
    return  0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int  a[1001000];
int main()
{
	int n,k,t;
	cin>>n;
	for(int i=1;i<=n;i++)
	cin>>a[i];
	k=a[1];
	for(int i=2;i<=n;i++)
	{
		if(i%2==0)
		k-=a[i];
		else
		k-=-a[i];
	}
	cout<<k<<" ";
	for(int i=1;i<=n-1;i++)
	{
		cout<<2*a[i]-k<<" ";
		k=2*a[i]-k;
	}
}

Measured memory_bytes: 1664
import heapq
N, M = map(int, input().split())
A = list(map(lambda x: int(x) * (-1), input().split()))
heapq.heapify(A)
for i in range(M):
  m = heapq.heappop(A)
  heapq.heappush(A, (-m // 2) * (-1))

print(-sum(A))

Measured memory_bytes: 14180
import java.util.Scanner;
 
class Main {
    public static void main(String[] args) {
        Scanner kb = new Scanner( System.in);   
         
        while( true ) {
            int H = kb.nextInt();
            int W = kb.nextInt();
             
            if( 0==W && 0==H ) { break; }
             
            for( int i=0; i<H; i++ ) {
                for( int j=0; j<W; j++ ) {
                    if( 0==i || H-1==i || 0==j || W-1==j ) {
                        System.out.print( "#" );
                    } else {
                        System.out.print( "." );
                    }
                }
                System.out.print( "\n" );
            }
            System.out.print( "\n" );
        }
    }
}

Measured memory_bytes: 29600
#include <bits/stdc++.h>
#define Int int64_t
#define pb push_back
using namespace std;

int main()
{
   Int N;cin>>N;
   string S,T;
   
   cin>>S>>T;
   string ans="";
   for(int i=0;i<S.length();++i){
       ans.pb(S[i]);
       ans.pb(T[i]);
   }
   cout<<ans<<"\n";
   
   
}

Measured memory_bytes: 3556
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <array>
#include <cmath>
#include <queue>
#include <stack>
#include <numeric>
using namespace std;

int main() {

	int n, m;
	cin >> n >> m;
	vector<int> a(m);
	for (int i = 0; i < m; i++) cin >> a.at(i);
	int sum = 0;
	for (int i = 0; i < m; i++) 
		sum += a.at(i);

	if (sum > n) {
			cout << "-1" << endl;
		}else {
			cout << n - sum << endl;
		}
	}


Measured memory_bytes: 3676
def f():    
    dp = [1]*(10**5+1) #エラトステネスの篩
    dp[0],dp[1] = 0, 0
    for i in range(2, 10**5+1):
        if dp[i] == 0:
            continue
        j = i
        while j + i <= 10**5:
            j += i
            if dp[j] == 1:
                dp[j] = 0
    
    ni = [0]*(10**5+1) #2012_like check
    for i in range(2, 10**5+1):
        if dp[i] == 1 and dp[(i+1)//2] == 1:
            ni[i] = 1
    
    ru = [0]*(10**5+1)
    for i in range(1, 10**5+1):
        ru[i] = ru[i-1] + ni[i]
    
    q = int(input())
    for i in range(q):
        l, r = map(int,input().split())
        print(ru[r] - ru[l-1])

if __name__ == '__main__':
    f()

Measured memory_bytes: 13564
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
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; }
int main()
{
    string S;
    cin >> S;
    int max_ = 0;
    int count = 0;
    for (int i=0; i<S.size(); i++) {
        if (S[i] == 'R') {
            count += 1;
            if (count > max_) {
                max_ = count;
            }
        } else {
            count = 0;
        }
    }

    cout << max_ << endl;
    return 0;
}

Measured memory_bytes: 3624
import System.IO

main = do
    end <- isEOF
    if end then return ()
    else
        do
            line <- getLine
            let [x, y] = map read . words $ line
                gcdXY = gcd x y
                lcmXY = x * y `div` gcdXY
                in putStrLn $ show gcdXY ++ " " ++ show lcmXY
            main

Measured memory_bytes: 4140
#include <stdio.h>

int n, x, l;
int i, d = 0, ans = 1;

int main() {
    scanf("%d %d", &n, &x);

    for (i = 0; i < n; i++) {
        scanf("%d", &l);
        d += l;
        if (d > x) {break;}
        ans++;
    }

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>
#include <utility>
#include <climits>
#include <numeric>
#define ll long long
#define INF INT_MAX 
using namespace std;
int main(){
    string s;
    cin >> s;
    ll ans = 0;
    ans = (s[0]-'1')+((s.size()-1)*9);
    ll ans2 = 0;
    for(int i=0;i<s.size();i++){
        ans2 = ans2+s[i]-'0' ;
    }
    cout << max(ans2,ans) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
int dp[1 << 15][101]; int n, m;
void init() {
	rep(i, 1<<15) {
		rep(j, 101) {
			dp[i][j] = (int)MOD;
		}
	}
	dp[0][0] = 0;
	return;
}
int main() {
	while (cin >> n >> m, n) {
		init();
		int s[15], d[100];
		rep(i, n) {
			cin >> s[i];
		}
		rep(i, m) {
			cin >> d[i];
		}
		sort(d, d + m);
		rep(i, 1 << n) {
			rep(j, m) {
				int sum = 0;
				rep(k, n) {
					if ((i >> k) & 1) {
						sum += s[k];
					}
				}
				dp[i][j + 1] = min(dp[i][j + 1], dp[i][j]+abs(sum-d[j]));
				rep(k, n) {
					if (!((i >> k) & 1)) {
						dp[i | 1 << k][j + 1] = min(dp[i | 1 << k][j+1], dp[i][j] + abs(sum + s[k] - d[j]));
						dp[i | 1 << k][j] = min(dp[i | 1 << k][j], dp[i][j]);
					}
				}
			}
		}
		int mi = (int)MOD;
		rep(i, 1<<n) {
			mi = min(mi, dp[i][m]);
		}
		cout << mi << endl;
	}
	return 0;
}


Measured memory_bytes: 16060
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<locale.h>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long int ll;
 
int main()
{
 int N,K;
 int a[200002]={};
 scanf("%d %d",&N,&K);
 for(int i=0;i<N;i++)
 {
	int b; scanf("%d",&b);
	a[b]++;
 }
 sort(a,a+200001,greater<>());
 int ans=0;
 for(int i=K;i<=200001;i++)
 {
	ans+=a[i];
 }
 printf("%d",ans);
} 

Measured memory_bytes: 4612
#include<stdio.h>
int a[200005],b[200005];
int main ()
{  int k,n;  scanf("%d %d",&k,&n);
   for(int i=1;i<=n;i++)
      scanf("%d",&a[i]);
    int max=a[2]-a[1];
    for(int i=2;i<=n;i++)
       {  if(max<a[i]-a[i-1])  max=a[i]-a[i-1];
	   }
	   if(max<k-a[n]+a[1])  max=k-a[n]+a[1];
	printf("%d",k-max);
}

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

int main() {
  vector<int> a(3);
  rep(i,3,0) cin >> a[i];
  sort(a.begin(),a.end());
  
  if(a[0] == 5 && a[1] == 5 && a[2] == 7) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
h=list(map(int,input().split()))
lis=[]

for i in range(m):
    a,b=map(int,input().split())
    ha=h[a-1]
    hb=h[b-1]
    if ha==hb:
        lis.append(a)
        lis.append(b)
    if ha>hb:
        lis.append(b)
    else:
        lis.append(a)

print(n-len(list(set(lis))))


Measured memory_bytes: 19932
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

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

class DFaceProducesUnhappiness {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int N, K;
        in>>N>>K;
        string S;
        in>>S;
        int cnt = 0;
        REP(i, N-1){
            cnt += (S[i]!=S[i+1]);
        }
        cnt -= min(cnt, 2*K);
        out<<N-cnt-1<<'\n';
    }
};


int main() {
	DFaceProducesUnhappiness solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3764
i = 0
k_n = []
k_n_all = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

p_price, k_number = map(int, input().split())
k_n = map(int, input().split())
result_number = list(set(k_n_all) - set(k_n))
result_price = p_price

while True:
    x = 0
    y = 0
    z = list(map(int, str(result_price)))
    while x < len(z):
        if z[x] in result_number:
            y += 0
        else:
            y += 1
        x += 1

    if y == 0:
        print(result_price)
        break
    else:
        result_price += 1

Measured memory_bytes: 9148
#include <iostream>
#include <string.h>
#include <stdlib.h>
using namespace std;

typedef struct _D
{
    int type;
    int r;
    int c;
    int total;
    _D()
    {
      type = -1;
      r = 0;
      c = 0;
      total = 0;
    }
}D;

int main(void){
  int H, W;
  cin >> H >> W;
  string m;
  D data[H][W] = {};
  for(int i = 0; i < H; i++) {
    cin >> m;
    for(int j = 0; j < W; j++)
    {
        if (strncmp(&m[j], "#", 1) == 0){data[i][j].type = -1;}
        else{data[i][j].type = 1;}
        data[i][j].r = 0;
        data[i][j].c = 0;
        data[i][j].total = 0;
    }
  }
  
  long _max = 0;
  for(int h = 0; h < H; h++){
    for(int w = 0; w < W; w++){
      if(data[h][w].type == -1){continue;}
      if(w-1 < 0 || data[h][w-1].type == -1)
      {
        int w2 = w;
        for(; w2 < W; w2++){if(data[h][w2].type == -1){break;}}
        if(w2 == W){data[h][w].c = w2 - w;}
        else{data[h][w].c = w2 - w;}       
      }
      else{data[h][w].c = data[h][w-1].c;}
  
      if(h-1 < 0 || data[h-1][w].type == -1)              
      {
        int h2 = h;
        for(; h2 < H; h2++){if(data[h2][w].type == -1){break;}}
        if(h2 == H){data[h][w].r = h2 - h;}
        else{data[h][w].r = h2 - h;}  
      }
      else{data[h][w].r = data[h-1][w].r;}
        
      
      //printf("%d, %d, %d, %d\n", h ,w, data[h][w].r, data[h][w].c);
      data[h][w].total = data[h][w].r + data[h][w].c - 1;
      if(_max < data[h][w].total)
      {
         _max = data[h][w].total;  
      }
    }
  }
  
  /*
  for (int h = 0; h < H; h++){
    string m = "";
    for(int w = 0; w < W; w++){
      if(data[h][w].type == -1)
      {
        cout << " # ";
      }
      else
      {
        cout << " " << data[h][w].total << " ";
      } 
    }
    cout << "\n";
  }
  */
  
  cout << _max;
}

Measured memory_bytes: 62720