akhauriyash/Code-Regression huggingface dataset:
import sys

sys.setrecursionlimit(int(1e6))

n, m = map(int, input().split())

edges = {}

for i in range(m):
    s, t = map(int, input().split())
    if s not in edges:
        edges[s] = set()
    if t not in edges:
        edges[t] = set()
    edges[s].add(t)
    edges[t].add(s)

order = [0] * n
lowlink = [0] * n
visited = set()
bridges = set()


def dfs(v, p, i):
    visited.add(v)

    i += 1
    lowlink[v] = order[v] = i

    if v not in edges:
        return

    for t in edges[v]:
        if t not in visited:
            dfs(t, v, i)
            lowlink[v] = min(lowlink[v], lowlink[t])
            if lowlink[t] == order[t]:
                bridges.add((min(v, t), max(v, t)))
        elif t != p:
            lowlink[v] = min(lowlink[v], lowlink[t])


k = 0
for i in range(n):
    if i not in visited:
        dfs(i, -1, k)

for s, t in sorted(bridges):
    print(s, t)



Measured memory_bytes: 26104
N,Q = map(int,input().rstrip().split())
S = input().rstrip()
a = [0]*N
for i in range(N):
    if i > 1:
        a[i] = a[i-1]
    if i != 0 and S[i-1]=='A' and S[i] == 'C':
        a[i] += 1
for _ in range(Q):
    l, r = map(int,input().rstrip().split())
    print(a[r-1]-a[l-1])

Measured memory_bytes: 11584
N, M = map(int, input().split())
A = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(M)]

li=[]

for i in range(N):
    li.append([A[i],1])

for i in range(M):
    li.append([S[i][1],S[i][0]])

#二次元配列のソート(リストの最初の要素で)
from operator import itemgetter
li.sort(key=itemgetter(0), reverse=True)

tmp=0
index=0
ans=0
while tmp <N:
    if li[index][1] >0:
        ans+=li[index][0]
        li[index][1] -=1
        tmp+=1
    else:
        index +=1

print(ans)

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

#define MIN 10
#define ll long long

int digits(ll int num){    /*桁数を返す*/
    ll int dig = 1;
    int i = 0;
    if(num == 1)return 1;

    while(dig <= num){
        dig *= 10;
        i++;
    }
    return i;
}

int main(){
    ll int N,A,B;
    ll int i;
    cin >> N;

   for(i=sqrt(N);N % i != 0 ;i--);

    cout << digits(N / i) << endl;

    return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    vector<bool> in(N, false);
    int sum = 0;
    for(int now = N; now > 0; now--){
        int cnt = 0;
        for(int i = now; i <= N; i += now) if(in[i-1]) cnt++;
        if(cnt%2 != A[now-1]){
            in[now-1] = true;
            sum++;
        }
    }
    cout << sum << endl;
    rep(i, N) if(in[i]) cout << i+1 << endl;
    return 0;
}

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

int main() {

	int N;
	cin >> N;
	int ans=0;
	int tans = 0;

	for (int i = 1; i <= N; ++i) {
		int value = 0;
		int _a = i;
		while (_a % 2 == 0 || _a != 1) {
			_a /= 2;
			value++;
		}
		if (value >= ans) ans = value;
	}
	ans = pow(2, ans);

	cout << ans << endl;

	return 0;
}

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

int main() {
    char c[4];
    for(int i = 0; i < 4; ++i) cin >> c[i];

    sort(c,c+4);

    if(c[0] == c[1] && c[1] != c[2] && c[2] == c[3]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#0:上面　1:S 2:E 3:W 4:N 5:下
class Dice:
    def __init__(self):#クラス内で用いる変数の定義（クラス作成時に代入しなくてよい）
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]
        self.order = 'NNNNWNNNWNNNENNNENNNWNNN'
    #サイコロの目の数を設定
    def setNumber(self, n0, n1, n2, n3, n4, n5):
        self.number[0] = n0
        self.number[1] = n1
        self.number[2] = n2
        self.number[3] = n3
        self.number[4] = n4
        self.number[5] = n5
        
    #サイコロを転がせ，それぞれのいちを追跡
    def roll(self, loc):#loc:
    #初期位置
        for i in range(6):
            self.work[i] = self.number[i]
        if loc == 'E':
            self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif loc == 'N':
            self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif loc == 'S':
            self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        else:
            self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])
    
    def equals(self, another):
        ret = False;
        
        for i in range(len(self.order)):
            self.roll(self.order[i])
            flag = True
            for k in range(6):
                if self.number[k] != another.number[k]:
                    flag = False
                    break
            if flag == True:
                return True
        
        return ret
          

n = int(input())
DICE = []#インスタンスのリスト

for i in range(n):
    table = list(map(int, input().split()))
    tmp = Dice()
    tmp.setNumber(table[0],table[1],table[2],table[3],table[4],table[5])#init
    DICE.append(tmp)

flag = True

for i in range(n-1):
    for k in range(i+1, n):
        if DICE[i].equals(DICE[k]) ==True:
            flag = False
            break

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


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

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    while (true) {
        C -= B;
        if (C <= 0) {
            cout << "Yes" << endl;
            break;
        }
        A -= D;
        if (A <= 0) {
            cout << "No" << endl;
            break;
        }
    }
}

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

inline void gi(int &x)
{
    x=0;int t=1,k=getchar();
    for(;k<'0'||k>'9';k=getchar())if(k=='-')t=-1;
    for(;k>='0'&&k<='9';k=getchar())x=(x<<1)+(x<<3)+(k^48);x*=t;
}

const int N=10003;
int n;
int a[N], b;
long long tot1, tot2;

int main(void)
{
  gi(n);
  for(int i=0; i<n; ++i) gi(a[i]);
  for(int i=0; i<n; ++i)
  {
    gi(b);
    if(b > a[i]) tot1+=(b-a[i])/2;
    else if(a[i] > b) tot2+=a[i]-b;
  }
  puts((tot1 >= tot2) ? "Yes" : "No");
  return 0;
}


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

int gcd(int x, int y)
{
    int r;

    if(x == 0 || y == 0)  // 引数チェック
    {
        fprintf(stderr, "引数エラーです。\n");
        return 0;
    }

    // ユーグリッドの互除法
    while((r = x % y) != 0)  // yで割り切れるまでループ
    {
        x = y;
        y = r;
    }
    return y;
}

int main(void){
	long n,X;
	long x[100001];
	long d[100001];
	long m;
	scanf("%d %d", &n,&X);
	for(int i=0;i<n;i++){
		scanf("%d", &x[i]);
		d[i] = abs(X - x[i]);
	}
	
	m=d[0];
	for(int i=1;i<n;i++){
		m = gcd( m, d[i]);
		if(m==1)	break;
	}
	
	printf("%d", m);
	return 0;
}

Measured memory_bytes: 1664
h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))
p=list()
for i in range(n):
    p.extend([i+1 for j in range(a[i])])
#print(p)
for i in range(h):
    if i%2==0:
        print(*p[i*w:i*w+w])
    else:
        print(*p[i*w:i*w+w][::-1])

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll a,b,c;
    cin >> a >> b >> c;
    ll ans;
    ans = a-b-c;
    if (b > a)ans = c;
    if (0 > ans)ans *= -1;
    else if (ans > 0)ans = 0;

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



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout<<#x<<" : "<<x<<endl
#define all(x) x.begin(), x.end()
#define rep(n) for(int i = 0; i < n; i++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
using namespace std;

int main(){
  	fastio;
    int n, k;
    cin>>n>>k;

    vector<int> h(n), dp(n, INT_MAX);

    for(int & x : h)
        cin>>x;

    dp[0] = 0;

    for(int i = 1; i < n; i++)
        for(int j = i-1; (j >= i-k && j >= 0); j--)
            dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));

    cout<<dp[n-1]<<"\n";

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
 
#define int long long 
#define ll long long 
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define ff first
#define ss second
#define vi vector<ll>
#define mod 1000000007
#define MOD 1000000007
#define full(a) a.begin(),a.end()
#define inf INT_MAX
#define minf INT_MIN
#define dd double
#define fori(x,n) for(ll i=x;i<n;i++)
#define modd 998244353
#define umap unordered_map<ll,ll>
double dp[3000][3000];
double p[3000];
ll n;

double count(ll i,ll j){
  if(i==n){
    if(j>n-j)return 1;
    return 0;
  }
  if(dp[i][j]!=-1)return dp[i][j];
  return dp[i][j]=p[i]*count(i+1,j+1)+(1-p[i])*count(i+1,j);
}


int32_t main() 
{ 
  
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    
    cin>>n;
    fori(0,3000)
    for(int j=0;j<3000;j++)dp[i][j]=-1;

    fori(0,n)cin>>p[i];

    cout<<setprecision(12)<<count(0,0);
   

    
   


return 0;
}    



Measured memory_bytes: 74292
import sys
from operator import itemgetter

input = sys.stdin.readline
n = int(input())
tasks = sorted([list(map(int, input().split())) for _ in range(n)], key=itemgetter(1))

time = 0
cando = True
for task in tasks:
  time += task[0]
  if time > task[1]:
    cando = False
    
print('Yes' if cando else 'No')

Measured memory_bytes: 55288
<?php
//error_reporting(0);
//$N = trim(fgets(STDIN));
//list($N,$W) = explode(" ",trim(fgets(STDIN)));
$h = explode(" ",trim(fgets(STDIN)));
sort($h);
if (implode("",$h)=="1479") {
  printf("YES\n");
}
else {
  printf("NO\n");
}


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

int N;
vector<int> a;

int main() {
    cin>>N;
    a.resize(N);
    for (int i=1; i<N; i++) cin>>a[i];
    vector<int> staff(N,0);
    for (int i=1; i<N; i++) {
        staff[a[i]-1]++;
    }
    for (int i=0; i<N; i++) cout<<staff[i]<<endl;
    return 0;
}


Measured memory_bytes: 4844
using System;
// using System.Collections.Generic;
// using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        string card = Console.ReadLine();
        double cardNum = double.Parse(card);
        string[] values = Console.ReadLine().Split(' ');
        double[] valuesdouble = new double[values.Length];
        double sumA = 0;
        double sumB = 0;
        double min = 0;

        for(int i=0; i<values.Length; i++){
            valuesdouble[i] = double.Parse(values[i]);
            sumB += valuesdouble[i];
        }
        min = 2147483647;

        for(int i=0; i<valuesdouble.Length - 1; i++){
            sumA += valuesdouble[i];
            sumB -= valuesdouble[i];
            double diff = Math.Abs(sumA - sumB);
            // Console.WriteLine("A: " + sumA.ToString());
            // Console.WriteLine("B: " + sumB.ToString());
            // Console.WriteLine("Diff: " + diff.ToString());
            if(diff < min)
                min = diff;
        }

        Console.WriteLine(min.ToString());
    }
}

Measured memory_bytes: 34012
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long ans = N-1;
		for(int i = (int)Math.sqrt(N); i >= 1; i--) {
			if(N % i == 0) {
				ans = i + N/i - 2;
				break;
			}
		}
		System.out.println(ans);

	}

}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
#define N 500007
#define pb push_back;
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define mod 998244353

int main()
{
    FAST;
    ll n;
    cin>>n;
    ll x,i,sm=0;
    vector<ll> v;
    ll xr=0;
    for(i=0;i<n;i++)
    {
        cin>>x;
        xr^=x;
        v.push_back(x);
    }
    for(i=0;i<n;i++)
    {
        ll x=xr^v[i];
        cout<<x<<" ";
    }
}

Measured memory_bytes: 5252
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) (int)((x).size())
#define debug(x) cout << #x << ":" << x << ' ';
#define debugg(x) cout << #x << ":" << x << ' ' << "\n";
#define endl "\n"
#define L(X) ((X)<<1)
#define R(X) (((X)<<1)|1)
#define M(X,Y) (((X)+(Y))>>1)

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

const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long int LLINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1);

template<typename T>   T max_self(T& a, T b) { if (a < b) a = b; return a; }
template<typename T>   T min_self(T& a, T b) { if (a > b) a = b; return a; }
template<typename T>   T add(T x, T y) { return ((x % MOD)  + (y % MOD)) % MOD;}
template<typename T>   T mul(T x, T y) { return ((x % MOD) * (long long)(y % MOD)) % MOD;}
template<typename T>   T sub(T x, T y) { return add(x, -y + MOD);}
template<typename T>   T gcd(T a, T b) { return b ? gcd(b, a % b) : a;}
template<typename T>   T lcm(T a, T b) { return a / gcd(a, b) * b;}
template<typename T>   vector<T> read(vector<T>& v, int n) {v.resize(n); for (auto &x : v)cin >> x;}
template<typename T>   void trav(vector<T> &v) {for (int i = 0 ; i < (int)v.size() ; ++i) {cout << v[i]; if (i != (int)v.size() - 1) cout << ' ';}}
int lg2(long long x)   {   return 64 - __builtin_clzll(x) - 1;	}
int lg2(int x)   {   return 32 - __builtin_clz(x) - 1;	}

//Variables Declaration


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

 	int n , k , cnt =0 ;
 	cin >> n >> k ;

 	for (int i = 0 ; i < n ; ++i){
 		int x ; 
 		cin >> x ;

 		if( x >= k ) cnt ++;
 	}
 	cout << cnt << endl;




	return 0;
}


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

using namespace std;

int a[N];

int main(){
	int n;
	scanf("%d", &n);
	for(int i=0;i<n;i++) scanf("%d", a+i);
	sort(a, a+n);
	double val=a[0];
	for(int i=1;i<n;i++){
		val+=a[i];
		val/=2;
	}
	printf("%.12lf\n", val);
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define ppb pop_back
#define INF 1e18
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using namespace std;

int main(int argc,char* argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(0);
cout.precision(10);

    int n;cin>>n;
    int pv=0;
    for(int i = 0;i<n;i++)
    {
        int x;cin>>x;
        pv*=10;pv+=x;
    }

    int qv=0;
    for(int i = 0;i<n;i++)
    {
        int x;cin>>x;
        qv*=10;qv+=x;
    }

    int a = 1,b = 1;
    int* c = new int[n];
    for(int i = 0;i<n;i++)c[i]=i+1;
    vector<int>alpha;
    int x=0;
    for(int i;i<n;i++){x*=10;x+=c[i];}
    alpha.push_back(x);
    while(next_permutation(c,c+n))
    {
        x=0;
        for (int i=0; i < n; i++)
        {
            x *= 10;
            x += c[i];
        }
        alpha.push_back(x);
    }

    for(size_t i = 0;i<alpha.size();i++)
    {
        if(pv==alpha[i])a=i+1;
        if(qv==alpha[i])b=i+1;
    }

    cout<<abs(a-b)<<endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <unordered_map>
#include <unordered_set>
#include <fstream>

using namespace std;

typedef unsigned long long ll;


int main() {

    vector<int> numbers (3);
    
    for(int i = 0; i < 3; i++)
        cin >> numbers[i];
    
    sort(numbers.begin(), numbers.end());
    
    cout << numbers[0]+numbers[1];

    return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<string>
#include<utility>
#include<algorithm>
#include<stack>
#include<queue>

#define numof(array) (sizeof (array) / sizeof *(array))
using namespace std;

#define INF (1 << 29)
//static const int dx[] = {1, 0, -1, 0};
//static const int dy[] = {0, 1, 0, -1};
typedef pair<int, int> P;
typedef pair<string, int> PP;
static const int di[] = {1, -1, 4, -4};

//int puzzle[2][4];
//int d[2][4];

map<string, int> m;


string move(string str, const int zero, const int direction)
{
    str[zero] = str[zero + di[direction]];
    str[zero + di[direction]] = '0';

    //cout << str << endl;    
    return str;
}

int find_zero(string str)
{
    for (int i = 0; i < 8; i++) {
        if (str[i] == '0') return i;
    }
    
    return 0;   
}


void create_map(void)//"01234567"から何手で作れるかを調べる
{
    queue<PP> que;
    que.push(PP("01234567", 0));

    static int cnt = 0;

    while(que.size()) {
        pair<string, int> p = que.front();
        que.pop();

        if (cnt == 8*7*6*5*4*3*2) return;  

        if (m.find(p.first) != m.end()) continue;
        m.insert(map<string, int>::value_type(p.first, p.second));
        cnt++;

        int zero = find_zero(p.first);
        
        if (zero != 3 && zero != 7){//右
            que.push(PP(move(p.first, zero, 0), p.second+1));
        }
        if (zero != 0 && zero != 4){//左
            que.push(PP(move(p.first, zero, 1), p.second+1));
        }
        if (zero < 4){//下
            que.push(PP(move(p.first, zero, 2), p.second+1));
        }
        if (zero >= 4){//上
            que.push(PP(move(p.first, zero, 3), p.second+1));
        }
    }
    

}
              
    

int main(void)
{
    create_map();

    while (true) {
        string str;
        for (int i = 0; i < 8; i++) {
            string input;
            if(!(cin >> input)) return 0;
            str += input;
        }

        cout << m[str] << endl;
    }

	return 0;
}

Measured memory_bytes: 3532
#include <stdio.h>
int main()
{
  int n;
  scanf("%d", &n);
  while(n--){
	  int a,b,c;
	  scanf("%d%d%d",&a,&b,&c);
	  a = a*a;
	  b = b*b;
	  c = c*c;
	  if(a==b+c)
		  printf("YES\n");
	  else if(b==a+c)
		  printf("YES\n");
	  else if(c==a+b)
		  printf("YES\n");
	  else
		  printf("NO\n");
	}
  return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
 
#define INF 1234567890
#define ll long long

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	string s;
	cin >> s;
	int sum = 0;
	for(int i=0; i<s.size(); i++)
	{
		sum += s[i]-'0';
	}
	if (sum%3==0) cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define CIN>>x scanf("%lld",&x);
#define all(v) v.begin(), v.end()
bool chmin(ll & a, ll  b) { if (b < a) { a = b; return 1; } return 0; }
bool chmax(ll & a, ll b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N=500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin >> n>>a>>b;
    x=n/(a+b);
    y=n%(a+b);

    if(y<a){
        ans=x*a+y;
    }
    else ans=x*a+a;

    cout<<ans<<endl;
}

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

int main() {
int N;
cin >> N;
if (N<10) {
    cout << N <<endl;
}else if (N<100) {
    cout << 9 <<endl;
}else if(N < 1000) {
    cout << 9 + (N-99) << endl;
}else if(N < 10000) {
    cout << 9+900 << endl;
}else if(N < 100000) {
    cout << 9+900+(N-9999) << endl;
}else if(N<1000000) {
    cout << 9+900+90000 << endl;
}
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });

            var N = Sarray()[0];
            var Vi = Sarray();
            Array.Sort(Vi);
            double ans = Vi[0];
            for (var i = 1; i < N; ++i)
            {
                ans = (ans + Vi[i]) / 2;
            }
            Write(ans);

            //Out.Flush();
        }
    }
}

Measured memory_bytes: 13396
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <list>
#include <iomanip>
#include <queue>
#include <cmath>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;
typedef pair<ll, ll> p;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
const long long mod = 1e9 + 7;
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);

vector<int> to[200005];
vector<int> ans;
ll gcd(ll a, ll b);

int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	bool ans = false;

	rep(i, n) {
		cin >> a[i];
		if (a[i] == k) ans = true;
	}

	sort(a.begin(), a.end());
	ll x;

	if (a[n - 1] > k) {
		x = a[0];
		rep(i, n - 1) {
			x = gcd(x, a[i + 1]);
			if (x == 1) {
				ans = true;
				break;
			}
		}
		if (k % x == 0) ans = true;
	}

	if (ans) cout << "POSSIBLE";
	else cout << "IMPOSSIBLE";

	return 0;
}


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

Measured memory_bytes: 8596
#include <bits/stdc++.h>
using namespace std;
using cpx = complex<double>;
using namespace std::literals;
using Int = long long;
using Double = long double;
#ifdef __GNUG__
#define _GLIBCXX_DEBUG
#endif
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define F first
#define S second
#define perm(c)   \
    sort(ALL(c)); \
    for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))
vector<Int> IntsIn(int n) {
    auto v = vector<Int>(0);
    for (int i = 0; i < n; i++) {
        Int a;
        cin >> a;
        v.push_back(a);
    }
    return v;
}
template <typename T>
void Puts(T x) {
    cout << x << endl;
}
void setPrecision(int num = 20) {
    std::cout << std::fixed << std::setprecision(num);
}
template <typename T>
T Max(T a) {
    return a;
}
template <typename T, typename... Args>
T Max(T a, Args... args) {
    return std::max(Max(args...), a);
}
template <typename T>
T Min(T a) {
    return a;
}
template <typename T, typename... Args>
T Min(T a, Args... args) {
    return std::min(Min(args...), a);
}
template <typename T>
bool vector_contains(std::vector<T> vec, T value) {
    return (std::distance(vec.begin(), std::find(vec.begin(), vec.end(), value)) != vec.size());
}
template <typename T>
long indexOf(std::vector<T> &vec, const T &value) {
    auto result = std::distance(vec.begin(), std::find(vec.begin(), vec.end(), value));
    return ((long)result == (long)vec.size()) ? -1 : result;
}
template <typename T>
void removeAt(std::vector<T> &vec, unsigned int index) {
    vec.erase(vec.begin() + index);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &value) {
    std::fill((T *)array, (T *)(array + N), value);
}
template <typename T>
struct countMap {
    map<T, Int> dict;
    countMap() {
        dict = map<T, Int>();
    }
    Int operator[](T key) {
        if (dict.find(key) != dict.end()) {
            return dict[key];
        } else {
            return 0;
        }
    }
    // key に対応する値があれば1増加させる，なければキーを新設して1をセット
    void incremntFor(T key) {
        if (dict.find(key) != dict.end()) {
            dict[key]++;
        } else {
            dict.emplace(key, 1);
        }
    }
    // for (auto &p: dict) でループできるように
    auto begin() const {
        return dict.begin();
    }
    auto end() const {
        return dict.end();
    }
};
int main() {
    Int n;
    cin >> n;
    auto v = IntsIn(n);
    auto next = 1LL;
    rep(i, n) {
        if(v[i]==next){
            next++;
        }
    }
    next--;
    if(next==0){
        puts("-1");
    }else{
        Puts(n - next);
    }
}


Measured memory_bytes: 2420
K = gets.chomp.to_i

if K < 10
  puts K
  exit
end

def search(x, i, n, res = [])
  if x <= 1
    cs = [res[-1]-1, res[-1], res[-1]+1].select{|v| 0 <= v && v <= 9}
    res << cs[n-1]
    puts res.join
    exit
  end
  res << i
  nn = n
  cs = [i-1, i, i+1].select{|v| 0 <= v && v <= 9}
  cs.each do |j|
    if nn - PAT[x-1][j] <= 0
      return search(x-1, j, nn, res)
    end
    nn -= PAT[x-1][j]
  end
end

PAT = {}
PAT[1] = Hash.new(0)
0.upto(9) do |i|
  PAT[1][i] = [i-1, i, i+1].select{|v| 0 <= v && v <= 9}.size
end
k = 9


PAT[2] = Hash.new(0)
0.upto(9) do |i|
  PAT[2][i] = [i-1, i, i+1].select{|v| 0 <= v && v <= 9}.size
  if i > 0
    search(2, i, K-k) if k + PAT[2][i] >= K
    k += PAT[2][i]
  end
end

# x桁
3.upto(10) do |x|
  PAT[x] = Hash.new(0)
  0.upto(9) do |i|
    PAT[x][i] = PAT[x-1][i-1] + PAT[x-1][i] + PAT[x-1][i+1]
    if i > 0
      search(x, i, K-k) if k + PAT[x][i] >= K
      k += PAT[x][i]
    end
  end
end


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define forp(i,a,b) for (int i = (a); i <(b); i++)
#define forn(i,a,b) for (int i = (a); i >(b); i--)
#define mod 1000000007
#define multiple_testcases_t int t;cin>>t;while(t--){solve();}
#define single_testcase_t solve();
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;



// <----- Actual solve() function to print output -----> //
int tc=1;
void solve()
{
   int n,k=0,z=-1,ans=INT_MAX;
   string a,b;
   cin>>a>>b;
   forp(i,0,(a.size()-b.size()+1))
   {
     z=0;
     int j=i;
     k=0;
      while(k<b.size())
      {
        if(b[k]!=a[j])
          z++;
		k++,j++;
      }
     ans=min(ans,z);
   }
  cout<<ans;
 //  cout<<"\n";      //if t>1 uncomment this
}

// MAIN function --------------------------------------------------------------------------//
int main()
{
    fast_io
//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);

  single_testcase_t
 // multiple_testcases_t
return 0;
}





Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  if (s.size()%2) {
    cout << "No" << endl;
    return 0;
  }
  for (int i = 0; i < s.size(); i += 2) {
    if (s[i] != 'h' || s[i+1] != 'i') {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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

int main() {
    int a, b;
    cin >> a >> b;
    if(abs(a - b) % 2 == 1) cout << "IMPOSSIBLE" << endl;
    else cout << ((max(a, b) - min(a, b)) / 2) + min(a, b) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
using P = pair<int, int>;
const ll inf =1e9;

struct edge{
    int to;
    int cost;
};
using graph = vector<vector<edge>>;

int main(){
    str s; cin >> s;
    bool easy = true;
    for(int i=0; i<s.size(); i++){
        if(i%2 == 0){
            if(s[i] != 'R' && s[i] != 'U' && s[i] != 'D'){
                easy = false;
            }
        }else{
            if(s[i] != 'L' && s[i] != 'U' && s[i] != 'D'){
                easy = false;
            }
        }
    }
    if(easy){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

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

#define ll long long
#define endl '\n'
#define REP(i, a, n) for(int i=a; i<n; ++i)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double PI = 3.141592653589793238460;
const ll mod = 1e9 + 7;

void FAST(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

int main(){
  FAST();

  double n, d;
  cin >> n >> d;
  cout << ceil(n / (2 * d + 1)) << endl;

  return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;
use num::*;
use num::integer::Roots;

fn main() {
    input! {
    a:usize,
    b:usize,
    c:[String;a],
    }
    let mut c =c.iter().map(|a|a.chars().collect_vec()).collect_vec();
    let mut t = vec![0;a];
    let mut y = vec![0;b];
    for i in 0..a {
        for j in 0..b {
            if c[i][j]=='#' {t[i]=1;y[j]=1;}
        }
    }
    let tt=t.iter().sum();
    let yy=y.iter().sum();
    let mut ttt=0;
    let mut yyy=0;
    let mut v:Vec<Vec<char>>=vec![vec!['.';yy];tt];
    for i in 0..a {
        if t[i]==1 {
            ttt+=1;
        }
        for j in 0..b {
            if y[j]==1 {
                yyy+=1;
            }
            if t[i]==1&&y[j]==1 {
                if c[i][j]=='#' {
                    v[ttt-1][yyy-1]='#'
                }
            }
        }
        yyy=0
    }
    let v:Vec<String>=v.iter().map(|a|a.iter().collect()).collect_vec();
    for i in 0..tt {
        println!("{}",v[i])
    }
}

Measured memory_bytes: 2284
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

int main()
{
    ll k, q;
    cin >> k >> q;
    vector<ll> d(k);
    for(auto& x: d) cin >> x;
    vector<ll> n(q), x(q), m(q);
    for(int i=0; i<q; i++) cin >> n[i] >> x[i] >> m[i];

    for(int i=0; i<q; i++){
        ll s = x[i];
        ll u = 0, v = 0;
        ll r = (n[i]-1) % k;

        for(auto& x: d){
            u += x % m[i];
            if(x % m[i] == 0) u += m[i];
        }
        for(int j=0; j<r; j++){
            v += d[j] % m[i];
            if(d[j] % m[i] == 0) v += m[i];
        }
        s += (n[i]-1)/k * u + v;

        ll ans = (n[i]-1) - s/m[i] + x[i]/m[i]; 
        cout << ans << endl;
    }
}

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

int main()
{
        int number[100][100], memo[100][200], i, j, tmp, tmp1;
        int line[100], max = 0;
        char str[201], *p;

        i = 0;
        while ( scanf( "%s", str ) != EOF ) {
                j = 0;
                // strtokを用いてカンマを取り除く
                p = strtok( str, "," );
                while ( p != NULL ) {
                        number[i][j] = atoi( p );
                        j++;
                        p = strtok( NULL, "," );
                }
                line[i] = j;
                i++;
        }

        int m = 0, l2 = 0;
        // 前の段との和をmemoに記録する
        while (  m < i ) {
                if ( m <= i / 2 ) {
                        // 半分より前の場合

                        if ( m == 0 ) {
                                // 1段目の場合, その値を代入
                                memo[m][0] = number[m][0];
                        } else {
                                // 2～i/2段目の場合, 前の段の値+自身の値を代入
                                // 一番左の値
                                memo[m][0] = number[m][0] + memo[m-1][0];
                                // 一番右の値
                                memo[m][line[m]-1] = number[m][line[m]-1] + memo[m-1][line[m-1]-1];
                        }

                        // 最左と最右以外は, 比較によってmemoに入れる値を決定する
                        for ( l2 = 1 ; l2 < line[m]-1 ; l2++ ) {
                                // 自身の値とmemoの前段の値を求める
                                tmp  = number[m][l2] + memo[m-1][l2-1];
                                tmp1 = number[m][l2] + memo[m-1][l2];
                                if ( tmp > tmp1 ) {
                                        memo[m][l2] = tmp;
                                } else {
                                        memo[m][l2] = tmp1;
                                }
                        }
                } else {
                        // 半分より後の場合
                        for ( l2 = 0 ; l2 < line[m] ; l2++ ) {
                                // 自身の値とmemoの前段の値を求める
                                tmp = number[m][l2] + memo[m-1][l2];
                                tmp1 = number[m][l2] + memo[m-1][l2+1];
                                if ( tmp > tmp1 ) {
                                        memo[m][l2] = tmp;
                                } else {
                                        memo[m][l2] = tmp1;
                                }
                        }
                }
                m++;
        }
        printf( "%d\n", memo[m-1][line[m-1]-1] );

        return 0;
}



Measured memory_bytes: 2044
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<math.h>
#include <string>
#define cinf(n,x,y) for(int i=0;i<(n);i++) cin >> x[i] >>y[i];
typedef long long int ll;
using namespace std;
ll mod=1e9+7;

int main(){
	int n; cin >>n;
	vector<ll> a(n),b(n);
	cinf(n,a,b);
	ll ans=0;
	ll cnt=0;
	for(int i=n-1;i>=0;i--){
		a[i]+=cnt;
		ans+=(a[i]%b[i]!=0?b[i]-a[i]%b[i]:0);
		cnt+=(a[i]%b[i]!=0?b[i]-a[i]%b[i]:0);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
import sys
input = sys.stdin.readline

import math

def main(): 

    N,K=map(int,input().split())
    ans=0
    for i in range(1,N+1):
        if K<=i<=N:
            ans+=1/N
        else:
            if math.log(K/i)//math.log(2)==math.log(K/i)/math.log(2):
                x=math.log(K/i)//math.log(2)
            else:
                x=math.log(K/i)//math.log(2)+1
            ans+= 1/N*(0.5**x)
            
    print(ans)

if __name__ == "__main__":
    main()
    

Measured memory_bytes: 3060
#include<iostream>
#include<string>
using namespace std;
long long int a[100005];
long long int b[100005]={};
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);

    string N;
    string result="No";
    cin >> N;
    for(int i=0;i<2;i++){
        if(N[i]=='9') result="Yes";
    }
        
	cout << result << "\n";
	return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.string;
import std.conv;

int main() {
  int[string] hash;
  int n = to!int(readln.chomp);
  string[] s = readln.chomp.split;

  foreach (ref c; s) {
    hash[c]++;
  }

  writeln(hash.length == 3 ? "Three" : "Four");

  return (0);
}


Measured memory_bytes: 256
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    S = input()
    K = int(input())

    ls = len(S)

    if ls == 1:
        print(K//2)
        return

    if ls == 2:
        print(0 if S[0] != S[1] else K)
        return

    if S[0] == S[-1]:
        c0 = S[0]
        for i in range(1, ls):
            if c0 != S[i]:
                break
        else:
            print(ls*K//2)
            return
        i0 = i
    else:
        i = i0 = 0

    ans = 0
    c0 , cn = "", 0
    for i in range(i, ls):
        c1 = S[i]
        if c1 == c0:
            cn += 1
        else:
            if cn > 1:
                ans += cn // 2
            cn = 1
            c0 = c1

    if i0 == 0:
        if cn > 1:
            ans += cn // 2
        ans *= K
    else:
        ans = ans * K + ((i0+cn)//2) * (K-1) + i0//2 + cn//2


    print(ans)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 3064
import math
N = int(input())

def order_check(x):
  y = 1
  while x >= 10:
    x = x//10
    y +=1
  return y

Answer = N

for i in range(round(math.sqrt(N))):
  if N%(i+1) ==0:
    temp = max(order_check(i+1),order_check(N/(i+1)))
    if temp < Answer:
      Answer = temp

print(Answer)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int N, D1, D2, M;
int A1[610][610], A2[610][610]; 
vector<pair<int, int>> v1, v2;
vector<pair<int, int>> V[4]; 
void dfs1(int x, int y, int c){
	A1[x][y] = c; 
	for(auto p : v1){
		int nx = x + p.first; int ny = y + p.second; 
		if(nx < 0 || nx > M || ny < 0 || ny > M) continue; 
		if(A1[nx][ny]) continue; 
		dfs1(nx, ny, 3 - c); 	
	}
}
void dfs2(int x, int y, int c){
	A2[x][y] = c; 
	for(auto p : v2){
		int nx = x + p.first; int ny = y + p.second; 
		if(nx < 0 || nx > M || ny < 0 || ny > M) continue; 
		if(A2[nx][ny]) continue; 
		dfs2(nx, ny, 4 - c); 	
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0); 
	cin >> N >> D1 >> D2; 
	M = 2 * N - 1; 
	for(int i = -M; i <= M; i++){
		for(int j = -M; j <= M; j++){
			int d = i * i + j * j;
			if(d == D1) v1.emplace_back(i, j); 
			if(d == D2) v2.emplace_back(i, j); 
		}
	}
	for(int i = 0; i <= M; i++){
		for(int j = 0; j <= M; j++){
			if(!A1[i][j]) dfs1(i, j, 1); 
			if(!A2[i][j]) dfs2(i, j, 1);  
		}
	}
	for(int i = 0; i <= M; i++){
		for(int j = 0; j <= M; j++){
			int t = A1[i][j] + A2[i][j] - 2; 
			V[t].emplace_back(i, j); 
		}
	}
	int idx = -1; 
	for(int t = 0; t < 4; t++){
		if(V[t].size() >= N * N) idx = t; 
	}
	for(int i = 0; i < N * N; i++){
		cout << V[idx].at(i).first << " " << V[idx].at(i).second << "\n"; 
	}
}

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

#define rep(i,l,n) for(int (i)=(l);(i)<(n);(i)++)
#define min(a,b) (a)<(b)?(a):(b)
#define max(a,b) (a)>(b)?(a):(b)
#define abs(a) (a)>0?(a):-(a)
#define ll long long

int main(){
	int N,M; scanf("%d %d",&N,&M);
	int sum=0;
	int A[N];
	rep(i,0,N){
		scanf("%d",&A[i]);
		sum += A[i];
	}
	int cnt=0;
	rep(i,0,N){
		if( 4*M*A[i] >= sum ) cnt++;
	}
	if( cnt < M ) printf("No");
	else printf("Yes");
	return 0;
}


Measured memory_bytes: 128
fun main(args: Array<String>) {
    val sc = java.util.Scanner(System.`in`)
    val s = sc.next()

    println(if (s.toCharArray().asSequence().withIndex().all {
        iv ->
        when (iv.value) {
            'U', 'D' -> true
            'L' -> iv.index % 2 == 1
            'R' -> iv.index % 2 == 0
            else -> true
        }
    }) "Yes" else "No")
}


Measured memory_bytes: 35912
using System;

namespace noteCsharp
{
    class Program
    {
        static void Main(string[] args)
        {
            while(true){
                string[] inputstr = Console.ReadLine().Split(char.Parse(" "));
                int height = int.Parse(inputstr[0]);
                int width = int.Parse(inputstr[1]);
                if(height==0 && width == 0)
                {
                    return;
                }
                for (int cycle0 = 0; cycle0 < height; cycle0++)
                {
                    for (int cycle1 = 0; cycle1 < (width - 1); cycle1++)
                    {
                        Console.Write("#");
                    }
                    Console.WriteLine("#");
                }
                Console.WriteLine();
            }
        }
    }
}



Measured memory_bytes: 17924
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main()
{
    vector<int> xs(5);
    rep(i, 5) cin >> xs[i];

    rep(i, 5)
    {
        if (xs[i] == 0)
        {
            cout << (i + 1) << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int D;
vector<int> C;
vector<vector<int>> S;

long long getTime() {
	timespec ts;
	clock_gettime(CLOCK_REALTIME_COARSE, &ts);
	long long r = ts.tv_sec;
	r *= 1000000000;
	r += ts.tv_nsec;
	return r;
}

ll calcScore(const vector<int>& T) {
	vector<int> last(26, -1);
	ll score = 0;
	for (int i = 0; i < D; ++ i) {
		int d = i - last[T[i]];
		score -= C[T[i]] * d * (d-1) / 2;
		last[T[i]] = i;
		score += S[i][T[i]];
	}
	for (int j = 0; j < 26; ++ j) {
		int d = D - last[j];
		score -= C[j] * d * (d-1) / 2;
	}
	return score;
}

int hoge(const vector<int>& T) {
	vector<int> last(26, -1);
	vector<ll> pena(26);
	for (int i = 0; i < D; ++ i) {
		last[T[i]] = i;
		for (int j = 0; j < 26; ++ j) {
			pena[j] += C[j] * (i - last[j]);
		}
	}
	int r = 0, cnt = 1;
	for (int j = 1; j < 26; ++ j) {
		if (pena[j] > pena[r]) {
			r = j; cnt = 1;
		} else if (pena[j] == pena[r]) {
			if (rand() % ++cnt == 0) { r = j; }
		}
	}
	return r;
}

int main() {
	auto startTime = getTime();

	cin >> D;
	C.resize(26);
	for (auto& x : C) cin >> x;
	S = vector<vector<int>>(D, vector<int>(26));
	for (auto& x : S) for (auto& y : x) cin >> y;

	vector<int> res(D);
	for (int i = 0; i < D; ++ i) {
		res[i] = 0;
		for (int j = 1; j < 26; ++ j) {
			if (S[i][j] > S[i][res[i]]) res[i] = j;
		}
	}

	for (int tt = 1; ; ++ tt) {
		int x = hoge(res);
		int ii = 0;
		ll m = -(1LL<<62);
		for (int i = 0; i < D; ++ i) {
			int tmp = res[i];
			res[i] = x;
			auto s1 = calcScore(res);
			if (s1 > m) {
				ii = i;
				m = s1;
			}
			res[i] = tmp;
		}
		if (res[ii] == x) break;
		res[ii] = x;
	}

	ll maxScore = calcScore(res);
	auto ans = res;

	auto s0 = maxScore;
	for (int tt = 1; ; ++ tt) {
		if (tt % 1024 == 0 && getTime() - startTime >= 1900000000) break;
		int i = rand() % D;
		int tmp = res[i];
		if (tt % 2 == 0) {
			res[i] = hoge(res);
		} else {
			res[i] = rand() % 26;
		}
		if (tmp == res[i]) continue;
		auto s1 = calcScore(res);
		if (s1 > maxScore) { maxScore = s1; ans = res; cerr << s1 << endl; }
		if (s1 <= s0) {
			auto d = s0 - s1;
			if (rand() / (1.0 + RAND_MAX) < 1 - exp(-0.0009 * d)) {
				res[i] = tmp;
			} else {
				s0 = s1;
			}
		} else {
			s0 = s1;
		}
	}

	for (auto x : ans) cout << x + 1 << endl;
}


Measured memory_bytes: 4184
#include <cstdio>
#include <cmath>
int n;
double x[1005], y[1005], X, Y, d, e;
double dist(double a, double b) {
	return a*a + b*b;
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lf%lf", &x[i], &y[i]);
		X += x[i]; Y += y[i];
	}
	X /= n; Y /= n;
	double P = 0.1;
	for (int i = 0; i < 30000; i++) {
		int f = 0;
		d = dist(X - x[0], Y - y[0]);
		for (int j = 1; j < n; j++) {
			e = dist(X - x[j], Y - y[j]);
			if (d < e) { d = e; f = j; }
		}
		X += (x[f] - X)*P;
		Y += (y[f] - Y)*P;
		P *= 0.999;
	}
	printf("%.16lf ", sqrt(d));
}

Measured memory_bytes: 256
#include "stdio.h"

bool linearSearch(int A[], int n, int key){

  int i=0;
  A[n] = key;

  while( A[i] != key ){
    i++;
  }
  return (i != n);
}


int main(void){

  int N_sample;
  scanf("%d", &N_sample);

  int* sample = new int [N_sample+1];

  for(int i=0;i<N_sample;i++){
    scanf("%d", &sample[i]);
  } 


  int N_target;
  scanf("%d", &N_target);

  int* target = new int [N_target+1];

  for(int i=0;i<N_target;i++){
    scanf("%d", &target[i]);
  }

  
  int cnt = 0;
  for(int i=0;i<N_target;i++){
    if(linearSearch(sample, N_sample, target[i])){
       cnt++;
    }  
  }

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

  delete [] sample;
  delete [] target;

  return 0;
}


Measured memory_bytes: 2744
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
const int INF = 2145141919;

int main() {
    int n;
    cin >> n;
    vector<vector<int>> v(n);
    for (int i = 0; i < n; i++) {
        int x, l;
        cin >> x >> l;
        v[i] = {x, l};
    }
    sort(v.begin(), v.end());

    vector<int> ret(n, INF);
    for (int i = 0; i < n; i++) {
        auto p = upper_bound(ret.begin(), ret.end(), v[i][0] - v[i][1]);
        ret[p - ret.begin()] = min(ret[p - ret.begin()], v[i][0] + v[i][1]);
    }

    cout << lower_bound(ret.begin(), ret.end(), INF) - ret.begin() << endl;
    return 0;
}

Measured memory_bytes: 6144
n = int(input())
p = list(map(int, input().split()))
a = 0
for i in range(n-2):
  if (p[i]<p[i+1] and p[i+1] < p[i+2]) or (p[i]>p[i+1] and p[i+1] > p[i+2]):
    a += 1
print(a)

Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
const int INF = 1e10;
const long double PI = (acos(-1));

struct mint {
	int x;
	mint(int x = 0) :x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= MOD)x -= MOD;
		return *this;
	}
	mint & operator-=(const mint a) {
		if ((x += MOD - a.x) >= MOD)x -= MOD;
		return *this;
	}
	mint & operator*=(const mint a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint a)const {
		return mint(*this) += a;
	}
	mint operator-(const mint a)const {
		return mint(*this) -= a;
	}
	mint operator*(const mint a)const {
		return mint(*this) *= a;
	}
	mint pow(int t)const {
		if (!t)return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1)a *= *this;
		return a;
	}

	//for prime mod
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a)const {
		mint res(*this);
		return res /= a;
	}
};
ostream& operator<<(ostream & os, const mint & m) {
	os << m.x;
	return os;
}


signed main() {
	int N;
	cin >> N;
	vector<int>A(N);
	int zero = 0;
	rep(i, N) {
		cin >> A[i];
		if (A[i] == 0)zero++;
	}
	mint ans = 1;
	map<int, int>m;
	m[-1] = 3;
	rep(i, N) {
		int a = m[A[i] - 1];
		int b = m[A[i]];
		ans *= a - b;
		m[A[i]]++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 7296
import sys
n, m = map(int, input().split())
num = [-1]*n

if n == 1 and m == 0:
  print(0)
  sys.exit()

for _ in range(m):
  s, c = map(int, input().split())

  # 一桁目が0
  if s == 1 and c == 0 and n > 1:
    print(-1)
    sys.exit()
  # 同じ桁が指定される
  if num[s-1] != -1 and num[s-1] != c:
    print(-1)
    sys.exit()
  num[s-1] = c

if num[0] == -1:
  num[0] = 1
for i in range(1, n):
  if num[i] == -1:
    num[i] = 0

for i in num:
  print(i, end='')

Measured memory_bytes: 3064