akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <algorithm>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

struct city{
  ll year;
  ll ind;
  ll perf;
};

struct pri{
  string name;
  ll ind;
};

bool comp(city a, city b){
  if(a.perf == b.perf)
    return a.year < b.year;
  return a.perf < b.perf;
}

bool compr(pri a, pri b){
  return a.ind < b.ind;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll n,m;
    cin >> n >> m;
    ll p,y;
    vector <city> v;
    vector <pri> vv;
    F0R(i,m) {
      cin >> p >> y;
      city temp;
      temp.ind = i+1;
      temp.perf = p;
      temp.year = y;
      v.pb(temp);
    }
    sort(v.begin(),v.end(),comp);
    ll curP = 0;
    ll curOrder = 0;
    for (auto it = v.begin(); it != v.end(); it++) {
      if(curP != (*it).perf){
        curOrder = 0;
      }
      curP = (*it).perf;
      curOrder++;
      string ss = "";
      string perfe = to_string(curP);
      string curOrdo = to_string(curOrder);
      F0R(i,6-perfe.length()) ss +="0";
      ss += perfe;
      F0R(i,6-curOrdo.length()) ss +="0";
      ss += curOrdo;
      pri tempPri;
      tempPri.ind = (*it).ind;
      tempPri.name = ss;
      vv.pb(tempPri);
    }

    sort(vv.begin(),vv.end(),compr);
    F0R(i,vv.size())
    cout << vv[i].name << endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 12016
#include<stdio.h>
#include<stdlib.h>

int main(){
    int y,m,d;
    scanf("%4d/%2d/%2d/",&y,&m,&d);
    if(y>2019)  printf("TBD\n");
    else if(m>=5)  printf("TBD\n");
    else printf("Heisei\n");
    
    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 3003

using namespace std;

const int mod = 1e9 + 7, inv = (mod + 1) / 2;

int n, m;
int a[N], f[N][N], x[N][2], y[N][2];

int main(){
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i)
		scanf("%d", a + i);
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= n; ++j)
			if(a[i] > a[j]) f[i][j] = 1;
	int sum = 1;
	while(m--){
		int X, Y; (sum *= 2) %= mod;
		scanf("%d%d", &X, &Y);
		for(int i = 1; i <= n; ++i){
			x[i][0] = f[X][i], x[i][1] = f[i][X];
			y[i][0] = f[Y][i], y[i][1] = f[i][Y];
		}
		for(int i = 1; i <= n; ++i){
			f[X][i] = 1ll * inv * (x[i][0] + y[i][0]) % mod;
			f[i][X] = 1ll * inv * (x[i][1] + y[i][1]) % mod;
			f[Y][i] = 1ll * inv * (y[i][0] + x[i][0]) % mod;
			f[i][Y] = 1ll * inv * (y[i][1] + x[i][1]) % mod;
		}
		f[X][Y] = f[Y][X] = 1ll * inv * (x[Y][0] + y[X][0]) % mod;
	}
	int ans = 0;
	for(int i = 1; i <= n; ++i)
		for(int j = i + 1; j <= n; ++j)
			(ans += f[i][j]) %= mod;
	ans = 1ll * ans * sum % mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 35456
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
struct e{
  ll a,b,c,d;
};
ll n,m,q;
vector<e>ho;
ll ans = 0;
vi sa;
void dfs(ll dep,ll sum){
  if(dep == n-1){
    vi A(n);
    A[0] = 1;
    for(int i=0;i<n-1;i++){
      A[i+1] += A[i]+sa[i];
    }
    if(A[n-1] > m)return;
    ll sum = 0;
    for(int i=0;i<q;i++){
      if(A[ho[i].b] - A[ho[i].a] == ho[i].c)sum += ho[i].d;
    }
    ans = max(sum,ans);
    return;
  }
  for(ll i = 0;i < m-sum;i++){
    sa.pb(i);
    dfs(dep+1,sum+i);
    sa.pop_back();
  }
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n>>m>>q;
  ho.resize(q);
  for(auto &a:ho){cin>>a.a>>a.b>>a.c>>a.d;a.a--;a.b--;}
  dfs(0,0);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3668
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    private const long INFINITY = 9223372036854775807;
    public static void Main()
    {
        int N = NextInt();
        int P = NextInt();
        int[] A = LineInt();
        long[,] dp = new long[N + 1, 2];
        dp[0, 0] = 1;
        dp[0, 1] = 0;
        for (int i = 0; i < N; i++)
        {
            //偶数ならtakeしなくてもかわらん
            if (A[i] % 2 == 0)
            {
                dp[i + 1, 0] = dp[i, 0] * 2;
                dp[i + 1, 1] = dp[i, 1] * 2;
            }
            else {
                dp[i + 1, 0] = dp[i, 1] + dp[i, 0];
                dp[i + 1, 1] = dp[i, 1] + dp[i, 0];
            }
        }
        Console.WriteLine(dp[N,P]);
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 13396
#include<iostream>
#include<string.h>
#include<cstdlib>
using namespace std;

#define N 100000

class Node {
public:
  int parent = -1;
  int depth = 0;
  int size = 0;
  int *child;
};

void depther(Node *, int, int);

int main() {

  int n;
  cin>>n;
  int v, k, c;
  Node list[N];
  for(int i = 0; i < n;  i++) {
      cin>>v>>k;
      list[v].size = k;
      list[v].child = (int *)malloc(sizeof(int) * k);
    for(int j = 0; j < k; j++) {
        cin>>c;
        list[v].child[j] = c;
        list[c].parent = v;
    }
  }
    
    for(int i = 0; i < N; i++) {
        if(list[i].parent == -1) depther(list, i, 0);
    }
  
  char status[14] = "";
  int j;
  for(int i = 0; i < n; i++) {
    if(list[i].parent == -1) strcpy(status, "root");
    else if(list[i].size == 0) strcpy(status, "leaf");
    else strcpy(status, "internal node");
    cout<<"node "<<i<<": parent = "<<list[i].parent<<", depth = "<<list[i].depth<<", "<<status<<", [";
    for(j = 0; j < list[i].size - 1; j++) cout<<list[i].child[j]<<", ";
    if(list[i].size != 0)cout<<list[i].child[j]<<']'<<endl;
    else cout<<']'<<endl;
  }
  
  return 0;
}

void depther(Node *list, int a, int dep) {
    list[a].depth = dep;
    dep++;
    for(int i = 0; i < list[a].size; i++) {
        depther(list, list[a].child[i], dep);
    }
}



Measured memory_bytes: 8956
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using ll = long long;
using namespace std;

int main() {
  int n;
  cin >> n;
  if (n % 10 == 9 || n / 10 == 9) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

#include<iostream>
using namespace std;

int main()
{
    for(int i = 1; i < 10; i++)
    for(int j = 1; j < 10; j++)
    {
        cout << i << "x" << j << "=" << i * j << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define MP make_pair
#define VI vector<int>
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.F<<","<<_p.S<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}

template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e4+5;
const ll MOD=1000000007;
const ll INF=(ll)1e18;

ll l[MAXn];
ll sum[MAXn];
int main(){
    IOS();
    ll n;
    cin >> n;
    REP1 (i,n) cin >> l[i];
    sort(l+1,l+n+1);
    REP1 (i,n) for (ll j=i+1;j<=n;j++) {
        ll cur = l[i] + l[j];
        ll it = lower_bound(l+j+1,l+n+1,cur) - l;
        sum[j+1]++;
        sum[it]--;
    }
    ll ans = 0;
    REP1 (i,n) {
        sum[i] += sum[i-1];
        ans += sum[i];
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 256
#selectionsort.rb
n=STDIN.gets.split[0].to_i
s=STDIN.gets.split
a=Array.new(n)
0.upto(n-1){|i|
  a[i]=s[i].to_i }
cnt=0
flag=0
0.upto(n-1){|i|
  minj=i
  i.upto(n-1){|j|
    if a[j] < a[minj] then
      minj=j
    end
  }
  if i != minj then
    w = a[minj]
    a[minj]=a[i]
    a[i]=w
    cnt += 1
  end
}

0.upto(n-2){|i|
    printf("%d ",a[i])}
printf("%d\n",a[n-1])
puts cnt 

Measured memory_bytes: 8640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1LL << 60;
const int MOD = 1'000'000'007;

template <typename T>
void print(const T &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}

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()
{
    ll d, t, s;
    cin >> d >> t >> s;
    if (s * t >= d)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3592
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
INF = 10**18

n = int(input())
a = [int(item) for item in input().split()]


# dp[i-th][wait num][used / not used]
dp = [[[-INF] * 2 for _ in range(3)] for _ in range(n+1)]
dp[0][0][0] = 0

for i in range(n):
    # use in i
    for j in range(3):
        dp[i+1][j][1] = max(dp[i+1][j][1] ,dp[i][j][0] + a[i])
    # rest in i
    for j in range(2):
        dp[i+1][j+1][0] = max(dp[i+1][j+1][0] ,dp[i][j][0])
    # not use in i
    for j in range(3):
        dp[i+1][j][0] = max(dp[i][j][1], dp[i+1][j][0])

ans = -INF
if n % 2 == 0:
    ans = max(dp[-1][1][1], ans)
    ans = max(dp[-1][0][0], ans)
else:
    ans = max(dp[-1][2][1], ans)
    ans = max(dp[-1][1][0], ans)
print(ans)

Measured memory_bytes: 162648
using System;

namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
    int next=int.Parse(Console.ReadLine());
      int ans=next;
  for(int i=next;i<=999;i++){
    if((i%111)==0){
      ans=i;
      break;
    }
  }
    Console.WriteLine(ans);
     }
    }    
}

Measured memory_bytes: 11092
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a < b ? a : b)
const int inf = 1000000000; // 10^9

int main(){
   int a,b;scanf("%d%d",&a,&b);
   char s[12];scanf("%s",s);
   int flag = 1;
   for(int i = 0;i < a;i++){
      if(s[i]=='-')flag = 0;
   }
   //printf("flag : %d\n",flag);
   if(s[a]!='-')flag = 0;
   //printf("flag : %d\n",flag);
   for(int i = a+1;i < b+a+1;i++){
      if(s[i]=='-')flag = 0;
   }
   //printf("flag : %d\n",flag);
   printf(flag==0?"No":"Yes");
}


Measured memory_bytes: 128
n = int(input())
h = list(map(int, input().split()))
ans = 'Yes'
for i in range(n - 1, 0, -1):
    d = h[i - 1] - h[i]
    if d >= 2:
        ans = 'No'
        break
    elif d == 1:
        h[i - 1] -= 1
print(ans)

Measured memory_bytes: 20612
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>
#include <climits>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

int main(int argc, char const* argv[])
{
  string s;
  cin >> s;
  bool cflag = false;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == 'C'){
      cflag = true;
    }
    if(s[i] == 'F'){
      if(cflag){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
// i want to become the best
class Main{
	public static void main(String[] args) throws Exception{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		//int n = Integer.parseInt(reader.readLine());
		int[] list = Arrays.stream(reader.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
	    System.out.println(list[1]*list[2]>=list[0]?"Yes":"No");
	}
}
class pair implements Comparable<pair>{
		long a = 0;
		int b = 0;
		public pair(long a,int b){
			this.a = a;
			this.b = b;
		}
		@Override
		public int compareTo(pair p){
			if(this.a == p.a) return -(Integer.compare(this.b,p.b));
			else return -(Long.compare(this.a,p.a));
		}
		@Override
		public String toString(){
			return a+" "+b;
		}
	}


Measured memory_bytes: 34440
#include <stdio.h>
#define SIZE 100

int
selectionSort(int [], int);

void
print(int [], int);

int
main(void)
{
    int i, n, arr[SIZE], sw;
    scanf("%d", &n);
    for (i = 0; i < n; i++)
        scanf("%d", arr + i);
    sw = selectionSort(arr, n);
    print(arr, n);
    printf("%d\n", sw);
    return 0;
}

int
selectionSort(int arr[], int n)
{
    int i, j, min, flag, v, sw;
    sw = 0;
    for (i = 0; i < n - 1; i++) {
        min = i;
        flag = 0;
        for (j = i + 1; j < n; j++)
            if (arr[j] < arr[min]) {
                min = j;
                flag = 1;
            }
        v = arr[i];
        arr[i] = arr[min];
        arr[min] = v;
        sw += flag;
    }
    return sw;
}

void
print(int arr[], int n)
{
    int i = 0;
    printf("%d", arr[i++]);
    for ( ; i < n; i++)
        printf(" %d", arr[i]);
    putchar('\n');
}


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

int main() {
    int k, a, b;
    cin >> k >> a >> b;

    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }

    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3636
ABC = list(map(int, input().split()))
ABC.sort()
cnt = 0
while ABC[0] != ABC[1] or ABC[1] != ABC[2]:
	if ABC[2] - ABC[0] >= 2:
		ABC[0] += 2
		cnt += 1
	elif ABC[2] - ABC[1] >= 2:
		ABC[1] += 2
		cnt += 1
	elif ABC[2] - ABC[0] == 1 or ABC[2] - ABC[1] == 1:
		ABC[0] += 1
		ABC[1] += 1
		cnt += 1
	ABC.sort()
print(cnt)

Measured memory_bytes: 38384
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
std::vector<long long int>vec(200002,0);
std::vector<long long int>sum(2022,0);
int main(){
  std::string str;
  std::cin>>str;
    long long int s=1;
  for(int i=1;i<=str.length();i++){
      
//      std::cout<<s<<std::endl;
//      std::cout<<(str[str.length()-i]-'0')*s+vec[i-1]<<" ";
      vec[i]=((str[str.length()-i]-'0')*s)%2019+vec[i-1]%2019;
      vec[i]=vec[i]%2019;
    sum[vec[i]]++;
      
      s=10*s;
      s=s%2019;
  }
//   for(int i=1;i<=str.length();i++)
//    std::cout<<vec[i]<<" mod:" <<vec[i]%2019<<std::endl;
   
  long long int count=0;
  for(int i=0;i<sum.size();i++){
      count+=sum[i]*(sum[i]-1)/2;
  }
    count+=sum[0];
  std::cout<<count<<std::endl;
  return 0;
}


Measured memory_bytes: 5228
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(m)]

ans = -1
for i in range(1000):
        can = 1
        t = str(i)
        if len(t)!=n: continue
        for s,c in sc:
                if int(t[s-1])!=c: can = 0
        if can:
                ans = i
                break

if ans<0: print(-1)
else: print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int ordena(const void *x, const void *y){
     const int *a = x;
     const int *b = y;

     if ((*a) > (*b))
          return -1;
     if ((*a) < (*b))
          return 1;
     return 0;
}

int main(){
     scanf("%*d");
     int k;
     int index = 0;
     scanf("%d", &k);
     int *a = malloc(1 * sizeof(int));

     while(scanf("%d", &a[index]) != EOF){
          ++index;
          a = realloc(a, (index+1) * sizeof(int));
     }

     qsort(a, index, sizeof(a[0]), ordena);

     int sum = 0;

     for(int i = 0; i < k; ++i){
          sum += a[i];
     }

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



     return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

ll H, W, N;
int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int dy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
ll ans[11];

int main()
{
    cin >> H >> W >> N;
    set<pair<int, int>> st, br;
    ans[0] = (H - 2) * (W - 2);
    for (int i = 0; i < N; i++)
    {
        int y, x;
        cin >> y >> x;
        y--, x--;
        pair<int, int> p = make_pair(y, x);
        br.insert(p);
        st.insert(p);
        for (int i = 0; i < 8; i++)
        {
            ll ny = y + dy[i], nx = x + dx[i];
            if (ny < 0 || ny >= H)
                continue;
            if (nx < 0 || nx >= W)
                continue;
            pair<ll, ll> q = make_pair(ny, nx);
            st.insert(q);
        }
    }
    for (auto &p : st)
    {
        ll y = p.first, x = p.second, cnt = 0;
        if (br.find(p) != br.end())
            cnt++;
        for (int i = 0; i < 8; i++)
        {
            int ny = y + dy[i], nx = x + dx[i];
            if (ny < 0 || ny >= H || nx < 0 || nx >= W)
            {
                cnt = -1;
                break;
            }
            pair<int, int> q = make_pair(ny, nx);
            if (br.find(q) != br.end())
                cnt++;
        }
        if (cnt != -1)
            ans[cnt]++, ans[0]--;
    }
    for (int i = 0; i < 10; i++)
        cout << ans[i] << endl;
}

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

void solve(long long N, std::vector<long long> A) {
    ll ans = 0;
    ll before = A[0];
    bool up = false;
    bool down = false;
    rep(i, N - 1) {
        if (A[i + 1] > before) {
            if (down) {
                ans++;
                down = false;
            } else {
                up = true;
            }
        }
        if (A[i + 1] < before) {
            if (up) {
                ans++;
                up = false;
            } else {
                down = true;
            }
        }
        before = A[i + 1];
    }
    cout << ans + 1 << endl;
}

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


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

typedef pair<int, int> P;
int N;
vector<P> red, blue;
int ans = 0;

int main() {
	cin >> N;
	for (int i = 0; i < 2*N; i++) {
		int x, y;
		cin >> x >> y;
		if (i < N) {
			red.push_back(P(x, y));
		}
		else {
			blue.push_back(P(x, y));
		}
	}

	sort(red.begin(), red.end());
	for (int i = N - 1; i >= 0; i--) {
		int rx = red[i].first, ry = red[i].second;
		int min_by = 200, buf = -1;
		for (int j = 0; j < (int) blue.size(); j++) {
			int bx = blue[j].first, by = blue[j].second;
			if (bx > rx && by > ry && min_by > by) {
				min_by = by;
				buf = j;
			}
		}

		if (buf != -1) {
			blue.erase(blue.begin() + buf);
			ans++;
		}
	}

	cout << ans << endl;
}

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

using namespace std;

int n, m;
int s[10], c[10];

bool check(int x) {
	vector<int> xs;
	
	if (x == 0) xs.push_back(0);
	else {
		while (x) {
			xs.push_back(x % 10);
			x /= 10;
		}
	}
	
	if (xs.size() != n) return false;
	
	for (int i = 0; i < m; i++) {
		if (xs[n - s[i]] != c[i]) return false;
	}
	
	return true;
}

int main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
	
	for (int i = 0; i < 1000; i++) {
		if (check(i)) {
			cout << i << endl;
			return 0;
		}
	}
	
	cout << -1 << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	string s; cin >> s;
	vector<int>vec(s.size() + 1);
	vec[s.size()] = 0;
	int a = 1;
	rREP(i, 0, s.size()) {
		vec[i] = (((s[i] - '0') * a) + vec[i + 1]) % 2019;
		a *= 10;
		a %= 2019;
	}
	map<int, ll>mp;
	ll ans = 0;
	rep(i, 0, vec.size()) {
		mp[vec[i]]++;
	}
	for (auto p : mp) {
		ans += (p.second * (p.second - 1)) / 2;
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 4292
import java.io.*;
import java.math.BigInteger;

public class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] line = br.readLine().split(" ");
		int[] monsters = new int[n+1];
		int i;
		for(i=0; i<=n; i++)
			monsters[i] = Integer.parseInt(line[i]);
		line = br.readLine().split(" ");
		int[] braves = new int[n];
		for(i=0; i<n; i++)
			braves[i] = Integer.parseInt(line[i]);
		
		BigInteger count = BigInteger.ZERO;
		int tmp, killed;
		for(i=0; i<n; i++){
			tmp = braves[i];
			killed = Math.min(tmp, monsters[i]);
			monsters[i] -= killed;
			tmp -= killed;
			count = count.add(new BigInteger(Integer.toString(killed)));
			killed = Math.min(tmp, monsters[i+1]);
			tmp -= killed;
			monsters[i+1] -= killed;
			count = count.add(new BigInteger(Integer.toString(killed)));
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 67992
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<utility>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int fac[1010 * 1010], fac_inv[1010 * 1010];
const int mod = 1000000007;

int pow(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1)res *= a;
        a *= a;
        res %= mod;
        a %= mod;
        b /= 2;
    }
    return res;
}

int inv(int x) {
    return pow(x, mod - 2);
}

void calc() {
    fac[0] = 1;
    fac_inv[0] = 1;
    for (int i = 1; i < 1010 * 1010; ++i) {
        fac[i] = fac[i - 1] * i % mod;
        fac_inv[i] = inv(fac[i]);
    }
}

int C(int n, int r) {
    return fac[n] * fac_inv[r] % mod * fac_inv[n - r] % mod;
}

int P(int n, int r) {
    return fac[n] * fac_inv[n - r] % mod;
}

int H(int n, int r) {
    return C(n + r - 1, r);
}
//calcを必ず実行
//mod書き換え
//fac,facinv配列長書き換え


int N, M;
int gyou, retsu;
int A[1010], B[1010];
pii X[1010 * 1010];//(行,列)1-indexed

signed main() {
    calc();
    cin >> N >> M;
    rep(i, N) {
        cin >> A[i];
        if (A[i] < M) {
            cout << 0 << endl;
            return 0;
        }
        if (X[A[i]].first != 0) {
            //複数の行に同じ値が出てくる
            cout << 0 << endl;
            return 0;
        }
        X[A[i]].first = i + 1;
    }
    rep(i, M) {
        cin >> B[i];
        if (B[i] < N) {
            cout << 0 << endl;
            return 0;
        }
        if (X[B[i]].second != 0) {
            //複数の列に同じ値が出てくる
            cout << 0 << endl;
            return 0;
        }
        X[B[i]].second = i + 1;
    }
    int horyuu = 0;
    int ans = 1;
    for (int i = 1; i <= N * M; ++i) {
        if (X[i].first && X[i].second) {
            if (horyuu >= N + M - gyou - retsu - 2) {
                ans *= P(horyuu, N + M - gyou - retsu - 2);
                horyuu -= N + M - gyou - retsu - 2;
            } else {
                cout << 0 << endl;
                return 0;
            }
            gyou++;
            retsu++;
        } else if (X[i].first) {
            if (horyuu >= M - retsu - 1) {
                ans *= M - retsu;
                ans %= mod;
                ans *= P(horyuu, M - retsu - 1);
                horyuu -= M - retsu - 1;
            } else {
                cout << 0 << endl;
                return 0;
            }
            gyou++;
        } else if (X[i].second) {
            if (horyuu >= N - gyou - 1) {
                ans *= N - gyou;
                ans %= mod;
                ans *= P(horyuu, N - gyou - 1);
                horyuu -= N - gyou - 1;
            } else {
                cout << 0 << endl;
                return 0;
            }
            retsu++;
        } else {
            horyuu++;
        }
        ans %= mod;
        ans += mod;
        ans %= mod;
        //cerr << i << " " << horyuu << " " << gyou << " " << retsu << " " << ans << endl;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 19840
#include <iostream>

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

#define pow(x) (x)*(x)

using namespace std;

void solve(){
    int a[3];
    rep(i,3){
        cin >> a[i];
    }

    rep(i,3){
        if(pow(a[i])==pow(a[(i+1)%3])+pow(a[(i+2)%3])){
            cout << "YES" << endl;
            return;
        }
    }

    cout << "NO" << endl;
}

int main(){
    int n;
    cin >> n;
    while(n--){
        solve();
    }

}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
long long n,v[3][2],res=0,f[5010*5010];
int main()
{
	cin>>n;
	for(int i=0;i<2;i++) for(int j=0;j<3;j++) cin>>v[j][i];
	for(int i=0;i<=n;i++) f[i]=-1e18;f[0]=0;
	for(int x=0;x<3;x++) if(v[x][0]<v[x][1])
		for(int i=v[x][0];i<=n;i++) f[i]=max(f[i],f[i-v[x][0]]+v[x][1]-v[x][0]);
	long long t=0;
	for(int i=0;i<=n;i++) t=max(t,f[i]+n);
	n=t;
	for(int i=0;i<=n;i++) f[i]=-1e18;f[0]=0;
	for(int x=0;x<3;x++) if(v[x][0]>v[x][1])
		for(int i=v[x][1];i<=n;i++) f[i]=max(f[i],f[i-v[x][1]]+v[x][0]-v[x][1]);
	t=0;
	for(int i=0;i<=n;i++) t=max(t,f[i]+n);
	cout<<t<<endl;
	return 0;
}

Measured memory_bytes: 198816
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

#define MAX_V 100100
#define INF 1000000000000000000LL

struct edge{ll to, cost;};
typedef pair<ll,ll> P;

vector<edge> G[MAX_V];
ll mn[MAX_V];

void ae(ll from, ll to, ll cost){
  edge e = {to,cost};
  G[from].push_back(e);
}

void dijk(ll start, ll V){
  priority_queue<P, vector<P>, greater<P> > que;
  for(ll i = 0; i < V; i++)mn[i] = INF;
  mn[start] = 0;
  que.push(P(0,start));
  while(!que.empty()){
    P p = que.top(); que.pop();
    ll v = p.second;
    if(mn[v]<p.first)continue;
    for(ll i = 0; i < G[v].size(); i++){
      edge e = G[v][i];
      if(mn[e.to] > mn[v]+e.cost){
        mn[e.to] = mn[v]+e.cost;
        que.push(P(mn[e.to],e.to));
      }
    }
  }
}

ll n,m,s,t;

vector<pair<pair<ll,ll>,pair<ll,ll> > > vv; 
ll mn1[100100];
ll mn2[100100];

int main(void) {
  cin>>n>>m>>s>>t;
  s--;
  t--;
  rep(i,0,m){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    a--;
    b--;
    vv.pb(mp(mp(a,b),mp(c,d)));
  }
  rep(i,0,vv.sz){
    ll a = vv[i].fi.fi;
    ll b = vv[i].fi.se;
    ll c = vv[i].se.fi;
    ae(a,b,c);
    ae(b,a,c);
  }
  dijk(s,n);
  rep(i,0,n){
    mn1[i] = mn[i];
  }
  rep(i,0,MAX_V){
    G[i].clear();
  }
  rep(i,0,vv.sz){
    ll a = vv[i].fi.fi;
    ll b = vv[i].fi.se;
    ll c = vv[i].se.se;
    ae(a,b,c);
    ae(b,a,c);
  }
  dijk(t,n);
  rep(i,0,n){
    mn2[i] = mn[i];
  }
  vector<ll> ans;
  ll mx = 0;
  per(i,0,n){
    ll p = mn1[i]+mn2[i];
    mx = max(mx,1000000000000000LL-p);
    ans.pb(mx);
  }
  reverse(all(ans));
  rep(i,0,ans.sz){
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 17644
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";}

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
typedef long long ll;
typedef double ld;
#define pll pair<ll,ll>
#define pii pair<int, int>
#define pb push_back
#define mp(x, y) make_pair((x), (y))
#define F first
#define S second
#define I insert
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pll>
#define vpii vector<pii>
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()

const int Mod = 1e9 + 7;
const int N  = 1<<12;

int dp[N];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n , m , a , b;
	cin >> n >> m;

	vpii keys(m);

	for(int i = 0;i < m; i++){
		cin >> a >> b;
		int c = 0 , c1;
		for(int j= 0;j < b ; j++){
			cin >> c1;
			c += (1<<(c1-1));
		}
		keys[i] = mp(a , c);
	}

	memset(dp , Mod , sizeof(dp));
	dp[0] = 0;

	int comm;

	for(int i = 1 ;i < (1<<n) ; i++){
		for(int j = 0;j < m ; j++){
			comm = i&keys[j].S;
			dp[i] = min(dp[i] , keys[j].F + dp[i^comm]);
		}
	}

	if(dp[ (1<<n)-1] < 10000000)
	cout << dp[ (1<<n)-1] << endl;
	else
	cout << -1 << endl; 
	return 0;

}


Measured memory_bytes: 256
// AtCoder Beginner Contest 130 - Problem A: Rounding (https://atcoder.jp/contests/abc130/tasks/abc130_a)
#include <bits/stdc++.h>

using namespace std;

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

    int X, A;
    cin >> X >> A;

    cout << (X < A ? 0 : 10) << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define MOD 1000000007
#define MAXN 10000
#define MAXA 1000000

LL fastExponentiation(LL base, int p) {
    if (p == 0)
        return 1;

    LL half = fastExponentiation(base, p/2);
    LL halfhalf = (half * half)%MOD;

    if (p%2 == 0)
        return halfhalf;
    else
        return (halfhalf * base)%MOD;
}

int n, a[MAXN + 3];
int cnt[MAXA + 3]; //to calculate lcm

int main() {
    cin >> n;

    memset(cnt, 0, sizeof(cnt));
    for (int i = 1; i <= n; i++) {
        cin >> a[i];

        int temp = a[i];
        for (int d = 2; d * d <= temp; d++) {
            if (temp % d == 0) {
                int count = 0;
                while (temp % d == 0) {
                    count += 1;
                    temp /= d;
                }

                cnt[d] = max(cnt[d], count);
            }
        }

        if (temp != 1)
            cnt[temp] = max(cnt[temp], 1);
    }

    LL lcm = 1;
    for (int i = 1; i <= MAXA; i++)
        lcm = (lcm * fastExponentiation(i, cnt[i]))%MOD;

    LL answer = 0;
    for (int i = 1; i <= n; i++) {
        LL b = (lcm * fastExponentiation(a[i], MOD - 2))%MOD;
        answer = (answer + b)%MOD;
    }

    cout << answer << endl;
}


Measured memory_bytes: 4224
#include<stdio.h>
//#include<windows.h>

int masu[22][22];
int ans=0;
int i,j;

void saiki(int x,int y){
	/*
	for(i=0;i<22;i++){
		for(j=0;j<22;j++){
			if(masu[i][j]==0)printf(" ");
			if(masu[i][j]==1)printf("¡");
		}
		puts("");
	}
	printf("%d",ans);
	Sleep(100);
	system("cls");
	*/
	masu[x][y]=1;
	ans++;
	if(masu[x][y-1]==0)saiki(x,y-1);
	if(masu[x+1][y]==0)saiki(x+1,y);
	if(masu[x][y+1]==0)saiki(x,y+1);
	if(masu[x-1][y]==0)saiki(x-1,y);
}

int main(){
	for(;;){
		ans = 0;
	int W,H;
	int x,y;
	char str[22];
	
	for(i=0;i<22;i++){
		for(j=0;j<22;j++){
			masu[i][j]=1;
		}
	}
	
	scanf("%d%d", &W, &H);
	if(W == 0){
		break;
	}
	for(i=0;i<H;i++){
		scanf("%s",str);
		for(j=0;j<W;j++){
			if(str[j]=='.')masu[i+1][j+1]=0;
			if(str[j]=='@'){
				x=i+1;
				y=j+1;
				masu[i+1][j+1]=0;
			}
		}
	}
	/*
	for(i=0;i<22;i++){
		for(j=0;j<22;j++){
			if(masu[i][j]==0)printf(" ");
			if(masu[i][j]==1)printf("¡");
		}
		puts("");
	}
	printf("%d\n",ans);
	system("cls");
	*/
	saiki(x,y);
	/*
	for(i=0;i<22;i++){
		for(j=0;j<22;j++){
			if(masu[i][j]==0)printf(" ");
			if(masu[i][j]==1)printf("¡");
		}
		puts("");
	}
	*/
	printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <iostream>
#include <vector>
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl "\n"
#define ALL(x) x.begin(),x.end()
using namespace std;

int H, W, k, ans;
vector<string> field(6);

int main() {
	cin >> H >> W >> k;
	rep(i, 0, H) cin >> field[i];

	rep(bit1, 0, 1 << H) rep(bit2, 0, 1 << W){
		int count = 0;
		rep(i, 0, H) rep(j, 0, W){
			if(bit1>>i & 1 || bit2>>j & 1) continue;
			if(field[i][j] == '#') count++;
		}
		if(count == k) ans++;
	}

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


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

void printData(int n){
  if(n==0) cout<<"-";
  else 
    for(int i=0;i<n;i++)
      cout<<"*";
  cout<<endl;
}

int main(){

  int n,work;
  while(1){
    cin>>n;
    if(n==0) break;
    int array[10];
    
    for(int i=0;i<10;i++)
      array[i]=0;
    
    for(int i=0;i<n;i++){
      cin>>work;
      array[work]++;
    }
    for(int i=0;i<10;i++){
      printData(array[i]);
    }
  }
  
  return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
using namespace std;
int T, N, a, b, c, d, e, f;
int money[12];
int arr[12][12];
int skill[12];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> a >> b >> c;
	int i;
	for (i = 0; i < a; i++)
	{
		cin >> money[i];
		int j;
		for (j = 0; j < b; j++)
		{
			cin >> arr[i][j];
		}
	}
	int ans = 987654321;
	for (i = 0; i < (1 << a); i++)
	{
		memset(skill, 0, sizeof(skill));
		int j;
		int p=0;
		for (j = 0; j < a; j++)
		{
			int k;
			if ((i & (1 << j) )== 0)
				continue;
			for (k = 0; k < b; k++)
			{
				skill[k] += arr[j][k];
			}
			p += money[j];
		}
		int succ = 0;
		for (j = 0; j < b; j++)
		{
			if (skill[j] < c)
				succ = 1;
		}
		if (!succ)
		{
			ans = min(ans, p);
		}
	}
	if (ans == 987654321)
		cout << -1;
	else
		cout << ans;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
//next_permutation(ALL(p));
//typedef priority_queue<int> pque;//これは大きい順
//typedef priority_queue<int, vector<int>, greater<int>> pque;//これは小さい順
//factorizeは、素因数分解用の関数

int main(){
	int n;
	cin >> n;
	int ans=0;
	rep(i,n+1){
		if(i>=1 && i<10)ans++;
		else if(i>=100 && i<1000){
			ans++;
		}else if(i>=10000 && i<100000){
			ans++;
		}
	}
	cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL){
    x=x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(x->right!=NIL){
    x=x->right;
  }
  return x;
}

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key){
    return u;
  }
  if(k< u->key){
    return treeSearch(u->left,k);
  }else{
    return treeSearch(u->right,k);
  }
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right!=NIL){
    return treeMinimum(x->right);
  }

  y=x->parent;
  while(y!=x->parent && y->right){
    x=y;
    y=y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y


  if(z->left==NIL || z->right==NIL){
    y=z;
  }else{
    y=treeSuccessor(z);
  }

  if(y->left!=NIL){
    x=y->left;
  }else{
    x=y->right;
  }

  if(x!=NIL){
    x->parent=y->parent;
  }

  if(y->parent==NIL){
    root=x;
  }else if(y==y->parent->left){
    y->parent->left=x;
  }else{
    y->parent->right=x;
  }

  if(y!=z){
    z->key=y->key;
  }
  free(y);
}


void insert(int k){
  Node y = NIL; //x' parent
  Node x = root; //T root
  Node z;

  
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }else{
      x=x->right;
    }
  }
  z->parent=y;

  if(y==NIL){
    root=z;
  }else if(z->key < y->key){
    y->left=z;
  }else{
    y->right=z;
  }
}

  


void inorder(Node u){
  if(u==NIL){
    return;
  }
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(Node u){
  if(u==NIL){
    return;
  }
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
  return 0;
}



Measured memory_bytes: 20448
#include <iostream>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <numeric>

using namespace std;

using Cake = struct
{
    int64_t x;
    int64_t y;
    int64_t z;
};

int64_t score(u_int8_t flags, int64_t x, int64_t y, int64_t z);

int main()
{
    int N, M;
    Cake c[1'000];

    cin >> N >> M;
    for (int i = 0; i < N; i++)
    {
        cin >> c[i].x >> c[i].y >> c[i].z;
    }

    int64_t m = 0;
    for (u_int8_t i = 0; i < 8; i++)
    {
        sort(c, c + N, [i](Cake l, Cake r) {
            return score(i, l.x, l.y, l.z) > score(i, r.x, r.y, r.z);
        });

        Cake zero = {0, 0, 0};
        Cake sum = accumulate(c, c + M, zero, [](Cake l, Cake r) {
            Cake res;
            res.x = l.x + r.x;
            res.y = l.y + r.y;
            res.z = l.z + r.z;
            return res;
        });
        m = max(m, score(i, sum.x, sum.y, sum.z));
    }

    cout << m << endl;

    return 0;
}

int64_t score(u_int8_t flags, int64_t x, int64_t y, int64_t z)
{
    return (flags & 0x01 ? x : -x) + (flags & 0x02 ? y : -y) + (flags & 0x04 ? z : -z);
}

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

using namespace std;
// Problem https://atcoder.jp/contests/abc087/tasks/arc090_a

int solver(int CANDYSUM,vector<int> UPLINE,vector<int> DOWNLINE){
    int result=0;
    // 累積和の作成
    vector<int> accuUPLINE;
    vector<int> accuDOWNLINE;
    accuUPLINE.clear();
    accuDOWNLINE.clear();
    accuUPLINE.push_back(0);
    accuDOWNLINE.push_back(0);
    for(int j=0;j<CANDYSUM;j++){
        accuUPLINE.push_back(accuUPLINE.at(j)+UPLINE.at(j));
        accuDOWNLINE.push_back(accuDOWNLINE.at(j)+DOWNLINE.at(j));
    }
/**    cout << "accuU P LINE: "; 
    for(int j=0;j<=CANDYSUM;j++){
        cout << accuUPLINE.at(j) << " ";
    }
    cout << endl;
    cout << "accuDOWNLINE: "; 
    for(int j=0;j<=CANDYSUM;j++){
        cout << accuDOWNLINE.at(j) << " ";
    }
    cout << endl;**/
    
    for(int j=0;j<CANDYSUM;j++){
        int nowsum=0;
//        cout << "Select " << j << ":";
        nowsum = accuUPLINE.at(j+1)+accuDOWNLINE.at(CANDYSUM)-accuDOWNLINE.at(j);
//        cout << nowsum << endl;
        if(result < nowsum){
            result = nowsum;
        }
    }
    return result;
}


int main(void){
    int answer;
    answer = 0;
    int N;
    cin >> N;
    vector<int> A1;
    vector<int> A2;
    for(int j=0;j<N;j++){
        int candy=0;
        cin >> candy;
        A1.push_back(candy);
    }
    for(int j=0;j<N;j++){
        int candy=0;
        cin >> candy;
        A2.push_back(candy);
    }
    answer = solver(N,A1,A2);
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    long n;
    cin >> n;
    long a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a,a+n);
    // for(int i=0;i<n;i++)cout<<a[i]<<endl;
    vector<bool>dp(1000001,true);
    for(int i=0;i<n;i++){
        if(!dp[a[i]])continue;
        if(i<n-1 && a[i] == a[i+1])dp[a[i]] = false;
        for(int j=2;a[i]*j<=1000000;j++){
            dp[a[i]*j] = false;
        }
    }
    int ans = 0;
    for(int i=0;i<n;i++){
        if(dp[a[i]])ans++;
    }
    cout<<ans<<endl;
    
    
}

Measured memory_bytes: 5284
#include<bits/stdc++.h>
//#define IORD
#define eps 1e-8
#define inf 0x3f3f3f3f
//#define mod (1000000007)

using namespace std;
typedef long long LL;
typedef pair<int,int> pp;

const int N=1e5+10;
int n,k,a[N];

int Che(int x)
{
    for(int i=0;i<n;i++)
        if(a[i]%x!=0) return 0;
    return 1;
}

int Sol()
{
    for(int i=0;i<n;i++) a[i]=abs(a[i]-k);
    int l=0,r=1e9+10,m=(l+r)>>1;
    while(l+1<r)
    {
        if(Che(m)) l=m;else r=m;
        m=(l+r)>>1;
        cout<<"m "<<m<<endl;
    }
    return l;
}

//int gcd(int a,int b) { return a==0?b:gcd(b,a%b); }
LL gcd(LL a, LL b){
    return b ? gcd(b, a%b) : a;
}

int main()
{
    #ifdef IORD
    freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif // IORD
    cin>>n>>k;
    if(n==1)
    {
        int p=0;
        cin>>p;
        cout<<abs(p-k)<<endl;
    }
    else
    {
    int ans=0,p=0,q=0;
    cin>>p>>q;
    p=abs(p-k),q=abs(q-k);
    ans=gcd(p,q);
    for(int i=2;i<n;i++)
    {
        cin>>p;
        p=abs(p-k);
        ans=gcd(ans,p);
    }
    cout<<ans<<endl;
    }
    return 0;
}















Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
int popcount(int val) { return __builtin_popcount(val); }
int popcountll(ll val) { return __builtin_popcountll(val); }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

template <typename T = char, typename U = string>
vector<pair<T, int> > rle(const U &s) {
  int n = s.size();
  vector<pair<T, int> > res;
  T now = s[0];
  int cnt = 1;
  FOR(i, 1, n) {
    if (s[i] != now) {
      res.emplace_back(now, cnt);
      cnt = 0;
    }
    now = s[i];
    ++cnt;
  }
  res.emplace_back(now, cnt);
  return res;
}

int main() {
  int n; cin >> n;
  string s; cin >> s;
  vector<pair<char, int> > ans = rle<>(s);
  cout << ans.size() << '\n';
  return 0;
}


Measured memory_bytes: 1480
wordlist = list(map(str, input().split()))

newwordlist = []
for i, word in enumerate(wordlist):
    newword = word
    if word[-1] == ",":
        newword = word.replace(',', '')
    elif word[-1] == ".":
        newword = word.replace('.', '')
    if 3 <= len(newword) <= 6:
        newwordlist.append(newword)

print(' '.join(newwordlist))



Measured memory_bytes: 5556