akhauriyash/Code-Regression huggingface dataset:
#include<vector>
#include<iostream>


int main(){
	//入力機構
	size_t n;
	std::cin>>n;//n<3000
	std::vector<int> A(n,0);//配列はn個。intは10^5以下を格納できる
	for(size_t i=0;i<n;i++){
		std::cin>>A[i];
	}

	//処理機構
	//f(m)について、mは非負整数の全ての値を取る。
	//よって、A[0],A[1],...,A[n-1]の最小公倍数より小さい整数はすべて引数に取れる。
	//その値から1を引いた数をpとすると、p mod A[i]=A[i]-1(i=0,1,...,n-1)である。これが最大値を算出する引数であることは明らか。
	//A[0]+A[1]+...+A[n-1]<=10^5*3000=3*10^8となり、intの範囲に収まる。
	int ans=0;
	for(size_t i=0;i<n;i++){
		ans+=(A[i]-1);
	}

	//出力機構
	std::cout<<ans<<std::endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
typedef long long LL;
LL f(LL a, LL b)
{
	if(!b) return -a;
	return a/b*b*2 + f(b, a%b);
}
int main()
{
	LL N, X, ans;
	scanf("%lld%lld", &N, &X);
	ans = N + f(N-X, X);
	printf("%lld\n", ans);
}


Measured memory_bytes: 128
let n = Scanf.scanf " %d" (+) 0
let sps = Array.init n @@ fun i -> Scanf.scanf " %s %d" @@ fun a b -> a, b, i + 1
let f (s, p, i) (s2, p2, i2) = if s = s2 then compare p2 p else compare s s2
let _ = Array.sort f sps; Array.iter (fun (_, _, i) -> Printf.printf "%d\n" i) sps

Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
string str;
char que[6]="KIHBR";
char que2[10]="AKIHABARA";
int main()
{
	while(cin>>str){
		int len = str.length();
		int k=0,t=0,i,flag=1;
		for( i=0;i<len;i++){
			//cout<<t<<" "<<str[i]<<" "<<que[k]<<" "<<que2[k+t]<<endl;
			if(str[i]==que[k]){
			//	cout<<str[i]<<1<<endl;
				k++;
				if(i+t<9&&str[i]!=que2[i+t]){
					t++;
				}

			}
			else if(i+t<9&&str[i]==que2[i+t]){
			//	cout<<str[i]<<2<<endl;
				continue;
			}
			else{
				flag=0;break;
			}
		}
		if(k==5&&flag==1)
			puts("YES");
		else 
			puts("NO");
	}
}

Measured memory_bytes: 256
a,b,c=(int(x) for x in input().split())
while a!=-1 or b!=-1 or c!=-1:
    if a==-1 or b==-1:
        print("F")
    else:
        if a+b>=80:
            print("A")
        elif a+b>=65 and a+b<80:
            print("B")
        elif a+b>=50 and a+b<65:
            print("C")
        elif a+b>=30 and a+b<50 and c>=50:
            print("C")
        elif a+b>=30 and c<50:
            print("D")
        else:
            print("F")
    a,b,c=(int(x) for x in input().split())


Measured memory_bytes: 5604
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define MOD 1e+7
#define inf 1e9
#define fi first
#define se second
using namespace std;

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

  string s;
  cin >> s;
  vector<string> str1 = {"dream", "erase"};
  vector<string> str2 = {"dreamer", "eraser"};
  reverse(s.begin(), s.end());
  rep(i,2) reverse(str1[i].begin(), str1[i].end());
  rep(i,2) reverse(str2[i].begin(), str2[i].end());

  while((int)s.size() >= 5) {
    if(s.substr(0,5) == str1[0]) {s = s.substr(5,s.size() - 5); continue;}
    if(s.substr(0,5) == str1[1]) {s = s.substr(5,s.size() - 5); continue;}
    if(s.substr(0,7) == str2[0]) {s = s.substr(7,s.size() - 7); continue;}
    if(s.substr(0,6) == str2[1]) {s = s.substr(6,s.size() - 6); continue;}
    cout << "NO" << endl;
    return 0;
  }
  cout << (s == "" ? "YES" : "NO") << endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i=0; i < N; i++){
    cin >> vec.at(i);
  }
  vector<int> vec2 = vec;
  sort(vec2.rbegin(), vec2.rend());
  for(int i=0; i < N; i++){
    if(vec.at(i) == vec2.at(0)){
      cout << vec2.at(1) << endl;
    }
    else {
      cout << vec2.at(0) << endl;
    }
  }
}

Measured memory_bytes: 3200
import bisect

n = int(input())
l = list(map(int, input().split()))
l.sort()

ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        idx = bisect.bisect_left(l, l[i]+l[j])
        ans += idx-j-1
print(ans)


Measured memory_bytes: 9340
N, M = map(int, input().split())
H = list(map(int, input().split()))
A = [0] * M
B = [0] * M
for i in range(M):
    A[i], B[i] = map(int, input().split())
    #0_index
    A[i] -= 1
    B[i] -= 1

ans = [1] * N

for i in range(M):
    a_height = H[A[i]]
    b_height = H[B[i]]
    if a_height < b_height:
        ans[A[i]] = 0
    elif a_height == b_height:
        ans[A[i]] = 0
        ans[B[i]] = 0
    else:
        ans[B[i]] = 0

#print("ans", ans)
print(ans.count(1))


Measured memory_bytes: 21580
d,g = map(int,input().split())
g //= 100
P,C = [],[]
for i in range(1, d+1):
    p,c = map(int,input().split())
    P.append(p)
    C.append(c//100)
ans = 10**9
# print(P)
# print(C)
for bin in range(1, 1<<d):
    cnt = tot = 0
    for j in range(d):
        if bin & 1<<j:
            cnt += P[j]
            tot += P[j]*(j+1) + C[j]
    if tot < g: continue
    ans = min(ans, cnt)
    # print('tot',tot, end=' ')
    # print('cnt',cnt, end='\n')
    for j in range(d):
        if bin & 1<<j:
            init_cnt = cnt - P[j]
            init_tot = tot - (P[j]*(j+1) + C[j])
            rest_g = g - init_tot
            k = max(0, (rest_g+j)//(j+1)) # round up, required quantity
            # print('Pj',P[j], end=' ')
            # print('Cj',C[j], end=' ')
            # print('init_cnt',init_cnt, end=' ')
            # print('init_tot',init_tot, end=' ')
            # print('rest_g',rest_g, end=' ')
            # print('k',k, end='\n')
            if k < P[j]:
                # ans = init_cnt + k
                ans = min(ans, init_cnt + k)
                # print('init_cnt+k',init_cnt+k, end='\n')
print(ans)


Measured memory_bytes: 3064
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    print(n*(n-1)//2-n//2)
    if n%2==1:
        for i in range(1,n):
            for j in  range(i+1,n+1):
                if j==n-i:continue
                print(i,j)
    else:
        for i in range(1,n):
            for j in  range(i+1,n+1):
                if j==n-i+1:continue
                print(i,j)        

if __name__=='__main__':
    main()

Measured memory_bytes: 42736
#include<bits/stdc++.h>
#define mx 100005
using namespace std;

long long l, a, dp[5];
int main(){
  scanf("%lld", &l);
  for(int i = 0; i < l; i++){
    scanf("%lld", &a);
    dp[0] += a;
    dp[1] = min(dp[1] + (a ? (a&1) : 2), dp[0]);
    dp[2] = min(dp[2] + ((a+1)&1), dp[1]);
    dp[3] = min(dp[3] + (a ? (a&1) : 2), dp[2]);
    dp[4] = min(dp[4] + a, dp[3]);
  }
  printf("%lld\n", dp[4]);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <sstream>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define rep(i,a,b) for(ll i = a; i <= b; ++i)
#define fo(i,a,b) for(int i = a; i<= b; ++i)
#define ull unsigned long long int
#define ll long long
#define all(a) a.begin(),a.end()
using namespace std;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
ll MD=1000000007;
ll md=998244353;
ll exp(ll a,ll b){ll r=1ll;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b/=2;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}//put b as bmod(md-1) if md is prime}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll pow_2(ll a, ll b)
{
    ll res = 1;
    while(b)
    {
        if(b & 1)
            res = (res * a);
        a = (a * a);
        b >>= 1;
    }

    return res;
}
bool isPrime(ll a)
{
    for(ll i=3; (i*i)<=a; i+=2)
    {
        if( (a%i)==0 )
            return false;
    }
    if( ( a!=2 ) && ( (a%2)==0 ) )
        return false;
    if( a==1 )
        return false;

    return true;
}
string decToBinary(int n)
{
    // Size of an integer is assumed to be 32 bits
    string s="";
    for (int i = 31; i >= 0; i--) {
        int k = n >> i;
        if (k & 1)
            //cout << "1";
            s=s+"1";
        else
            //cout << "0";
            s=s+"0";
    }
    return s;
}
int decimalToBinary(int N)
{

    // To store the binary number
    ull B_Number = 0;
    int cnt = 0;
    while (N != 0) {
        int rem = N % 2;
        ull c = pow(10, cnt);
        B_Number += rem * c;
        N /= 2;

        // Count used to store exponent value
        cnt++;
    }

    return B_Number;
}
string toString(ull num)
{
    std::string number;
    std::stringstream strstream;
    strstream << num;
    strstream >> number;
    return number;
}
const double PI = acos(-1);
int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
    int n,k;
    cin>>n>>k;
    int h[n];
    fo(i,0,n-1)cin>>h[i];
        int dp[n];
        dp[0]=0;
        dp[1]=abs(h[1]-h[0]);
        for(int i=2;i<n;i++)dp[i]=MD;
        for(int i=2;i<n;i++)
        {
            for(int j=0;j<=min(i,k);j++)
            {
                dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
            }

        }
        cout<<dp[n-1]<<endl;
return 0;}




Measured memory_bytes: 1024
#include<stdio.h>
int main(void){
  int i;
  char s[2][11];
  scanf("%s%s%s",s[0],s[1],s[2]);
  for(i=0;i<3;i++)s[i][0]=s[i][0]-32;
  printf("%c%c%c",s[0][0],s[1][0],s[2][0]);
  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
typedef long long ll;
ll min(ll x,ll y)
{
	if(x>y)
	{
		return y;
	}
	else
	{
		return x;
	}
}
ll dp(ll cost[], ll i,ll high[])
{
	if(i == 0)
	{
		return 0;
	}
	if(i == 1)
	{
		cost[i] = abs(high[i]- high[i-1]);
		return cost[i];
	}
	if(cost[i] != -1)
	{
		return cost[i];
	}
	cost[i] = min(dp(cost,i-1,high) + abs(high[i] - high[i-1]),dp(cost,i-2,high) + abs(high[i] - high[i-2]));
	return cost[i];
}
int main()
{
	ll n;
	scanf("%lld",&n);
	ll high[100000];
	ll cost[100000];
	for(ll i=0;i<n;i++)
	{
		scanf("%lld",&high[i]);
		cost[i] = -1;
	}
	ll ans = dp(cost,n-1,high);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 5632
import java.util.Scanner;

class C {
    public static void main(String... args) {
        final Scanner sc = new Scanner(System.in);
        final int n = sc.nextInt();
        final int m = sc.nextInt();
        final int d = sc.nextInt();
        final double single = (d == 0 ? 1. : 2.) * Math.max(n - d, 0) / n / n;
        System.out.printf("%.8f\n", single * (m - 1));
    }
}
public class Main {
    public static void main(String...args) {
        C.main();
    }
}


Measured memory_bytes: 22996
import scala.math.{abs,sqrt,pow}

object Main extends App {
  
  val sc = new java.util.Scanner(System.in)
  val n, d = sc.nextInt()
  val x = Array.fill(n)(Array.fill(d)(sc.nextInt()))
  val combinations = (0 until n).combinations(2).toList
  val ans = combinations.filter(c => isInt(calcD(x(c(0)), x(c(1))))).size
  println(ans)
    
  def calcD(x: Array[Int], y: Array[Int]): Double = {
    val sum = x.zip(y).foldLeft(0)((x, y) => x + pow((y._1 - y._2), 2).toInt)
    sqrt(sum)
  }
  
  def isInt(x: Double): Boolean = x % 1 == 0
}

Measured memory_bytes: 55532
import numpy as np

N = int(input().strip())
A = list(map(int, input().strip().split(' ')))

A = np.asarray(A)
i = np.asarray([x for x in range(1, N+1)])
A = A - i

b = np.round(np.median(A))
A = A - b
A = np.absolute(A)
print(A.sum().astype(np.uint64))

Measured memory_bytes: 34204
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int N;
int A[20], B[20];
int C[20];
vector<int> odd[55];
vector<int> even[55];
P p[20];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    for(int i = 0; i < N; i++){
        cin >> B[i];
    }
    int ans = 1000000;
    bool find = false;
    for(int i = 0; i < (1<<N); i++){
        int tmp = 0;
        for(int j = 0; j <= 50; j++) {
            odd[j].clear();
            even[j].clear();
        }
        for(int j = 0; j < N; j++){
            if(i&(1<<j)) C[j] = B[j];
            else C[j] = A[j];
            p[j] = P(C[j], j);
        }
        sort(p, p+N);
        for(int j = 0; j < N; j++){
            for(int k = j+1; k < N; k++){
                if(p[j].second > p[k].second) {
                    tmp++;
                }
            }
        }

        for(int j = 0; j < N; j++){
            if(i&(1<<j)){
                if((j+1)%2 == 0) odd[C[j]].push_back(j);
                else even[C[j]].push_back(j);
            }else{
                if((j+1)%2 == 1) odd[C[j]].push_back(j);
                else even[C[j]].push_back(j);
            }
        }
        
        bool ok = true;
        int cur = 0;
        int pos = 0;
        for(int j = 1; j <= 50; j++){
            vector<int> buf;
            if(pos%2 == 0){
                if(odd[j].size() == even[j].size() || odd[j].size() == even[j].size()+1){
                    int s = even[j].size();
                    for(int k = 0; k < s; k++){
                        buf.push_back(odd[j][k]);
                        buf.push_back(even[j][k]);
                    }
                    if(odd[j].size() == even[j].size()+1) buf.push_back(odd[j][s]);
                }else{
                    ok = false;
                }
            }else{
                if(odd[j].size() == even[j].size() || odd[j].size()+1 == even[j].size()){
                    int s = odd[j].size();
                    for(int k = 0; k < s; k++){
                        buf.push_back(even[j][k]);
                        buf.push_back(odd[j][k]);
                    }
                    if(odd[j].size()+1 == even[j].size()) buf.push_back(even[j][s]);
                }else{
                    ok = false;
                }
            }
            pos += (odd[j].size() + even[j].size());
            if(ok){
                for(int k = 0; k < buf.size(); k++){
                    for(int l = k+1; l < buf.size(); l++){
                        if(buf[k] > buf[l]) cur++;
                    }
                }
            }
        }
        tmp += cur;
        if(ok) {
            find = true;
            ans = min(ans, tmp);
        }
    }
    if(!find){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <utility>
#include <random>
#include <chrono>

using namespace std;

#define ll long long

int n;
int ans[200005];

int main()
{
    scanf("%d", &n);
    for (int i = 2; i <= n; i++) {
        int a; scanf("%d", &a); ans[a]++;
    }
    for (int i = 1; i <= n; i++) {
        printf("%d\n", ans[i]);
    }
    return 0;
}


Measured memory_bytes: 4592
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
    string s;

    cin >> s;

    if (s == "ABC")
    {
        cout << "ARC" << endl;
    }
    else
    {
        cout << "ABC" << endl;
    }

    return 0;
}

Measured memory_bytes: 3620
<?php
    while($input_line = trim(fgets(STDIN))){

        $num = explode(" ",$input_line);
        // echo $num[1];
        if($num[1]=="+"){
            echo $num[0]+$num[2];
            
        }elseif($num[1]=="-"){
            echo $num[0]-$num[2];
            
        }elseif($num[1]=="*"){
            echo $num[0]*$num[2];
            
        }elseif($num[1]=="/"){
            echo floor($num[0]/$num[2]);
            
        }elseif($num[1]=="?"){
            break;
        }
        echo "\n";
    }
?>


Measured memory_bytes: 9228
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<pair<ll, ll>>> vvpll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    string s;
    cin >> s;
    ll cnt = 0;
    rep(i, s.size()) {
        if(s[i] == 'x') {
            cnt++;
        }
    }
    if(cnt >= 8) {
        out("NO");
    }
    else {
        out("YES");
    }
    re0;
}

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

int main() {
    int h,w;
    cin>>h>>w;
    vector<string> a(h);
    
    rep(i,h) cin >> a[i];
    vector<bool> row(h, 0);
    vector<bool> col(w, 0);
    rep(i,h) {
       rep(j,w) {
           if (a[i][j] == '#') {
               row[i] = 1;
               col[j] = 1;
           }
       }
    }
    
    rep(i,h) {
        if(row[i]){
            rep(j,w){
                if(col[j]){
                    cout << a[i][j];
                }
            }
            cout << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
h = list(map(int,input().split()))
cnt = 0
 
while sum(h) > 0:
    min_h = max(h)
    i = h.index(min_h)
    #print(i)
    while i < len(h):
        if h[i] == min_h:
            h[i] -= 1
            i += 1
        else:
            break
    cnt += 1
 
print(cnt)

Measured memory_bytes: 3060
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
class union_find{
  int n;
  vector<int> par,rk,size;
  public:
  union_find(int max_n){
    n = max_n+1;
    for(int i=0;i<=n;i++){
      par.emplace_back(i);
      rk.emplace_back(0);
      size.emplace_back(1);
    }
  }
  int root(int x){
    vector<int> nodes;
    while(x!=par[x]){
      nodes.emplace_back(x);
      x = par[x];
    }
    for(auto v:nodes){
      par[v] = x;
    }
    return x;
  }
  void unite(int x,int y){
    x = root(x);
    y = root(y);
    if(x==y) return;
    if(rk[x]<rk[y]){
      par[x] = y;
      size[y] += size[x];
    }else{
      par[y] = x;
      if(rk[x]==rk[y]) rk[x]++;
      size[x] += size[y];
    }
  }
  bool same(int x,int y){
    return root(x)==root(y);
  }
  int treesize(int x){
    return size[root(x)];
  }
};
signed main(){
  init_io();
  ll n,m,ans=0;
  cin >> n >> m;
  vector<bool> memo(n,false);
  union_find uf(n);
  for(int i=0;i<m;i++){
    ll a,b;
    cin >> a >> b;
    a--;
    b--;
    uf.unite(a,b);
  }
  for(int i=0;i<n;i++){
    ll rt = uf.root(i);
    if(!memo[rt]){
      memo[rt] = true;
      ans++;
    }
  }
  cout << ans-1 << endl;
}


Measured memory_bytes: 4556
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

ll d_sum(ll n){
  str s = to_string(n);
  ll ans = 0;
  REP(i,s.length()){
    ans += s[i]-'0';
  }
  return ans;

}

int main(){
  ll n,a,b;
  cin >> n >> a >> b;
  ll sum = 0;
  REP(i,n+1){
    if(d_sum(i)>=a&&d_sum(i)<=b){
      sum+=i;
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
# collection.Counterを使わなくても同じようにできる
n=int(input()) 
s = []
for i in range(n):
    s.append(list(input()))
d = {}
ans = 0
for i in s:
    a = [c for c in i]
    a.sort()
    a = "".join(a)
    if a in d:
        ans += d[a]
        d[a] += 1
    else:
        d[a] = 1
     
print(ans)

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

using namespace std;

const int mod = 1e9 + 7;

int add(int a, int b) {
  int s = a + b;
  if (s >= mod) s -= mod;
  return s;
}

int mul(int a, int b) {
  return (long long)a * b % mod;
}

int pow(int b, int e) {
  int r = 1;
  while (e > 0) {
    if (e & 1) {
      r = mul(r, b);
    }
    b = mul(b, b);
    e /= 2;
  }
  return r;
}

int divm(int a, int b) {
  return mul(a, pow(b, mod - 2));
}

int fac[1000004];

int C(int n, int k) {
  return divm(fac[n], mul(fac[k], fac[n - k]));
}

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

  fac[0] = 1;
  for (int i = 1; i <= x; ++i) {
    fac[i] = mul(fac[i - 1], i);
  }

  int k = (x + y) / 3;
  printf("%d\n", (k * 3 == (x + y) && x >= k && y >= k) ? C(k, x-k) : 0);
  return 0;
}

Measured memory_bytes: 4096
#include<iostream>
using namespace std;
int main(){
	int a, b;
	char op;
	while (1){
		cin >> a >> op >> b;
		switch (op){
		case'+':cout << a + b << endl;
			break;
		case'-':cout << a - b << endl;
			break;
		case'*':cout << a * b << endl;
			break;
		case'/':cout << a / b << endl;
			break;
		case'?':return 0;
		}
	}
}

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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
typedef complex<ld> Point;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 1e5 + 5;
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

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;
}

// make vector of divisor O(sqrt(n))
vector<long long> divisor(long long n) {
    vector<long long> res;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i != n / i) res.push_back(n / i);
        }
    }
    return res;
}

int main() {
    ll n, m;
    cin >> n >> m;
    auto div = divisor(m);
    ll ans = 0;
    foreach (e, div) {
        if (m / e >= n) chmax(ans, e);
    }
    out(ans);
}


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

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

using namespace std;

int main(){
	int n,L; cin>>n>>L;
	int x=0,i;
	for(i=0;i<n;i++){
		int d; cin>>d;
		x+=d;
		if(x>L) break;
	}
	cout<<i+1<<endl;

	return 0;
}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1e17 - 10;
const double PI = acos(-1);
typedef pair<LL, LL> Pll;
int h, w, n, m, s, ans = 0, a[1000000],f[100000], num = 0, sum = 0;
int flag = 0;
string str,stt;
int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++) {
		if (a[a[i]] == i&&f[a[i]]==0) {
			f[i]++;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
  string s;
  cin >> s;
  int res = 0;
  
  while (true) {
    string a, b;
    s.erase(s.begin() + s.size() - 1);
    res++;

    if (s.size() % 2 != 0) continue;
    a = s.substr(0, s.size() / 2);
    b = s.substr(s.size() / 2, s.size());
    if (a == b) {
      break;
    }
  }
  printf("%d\n",s.size());

  return 0;
}


Measured memory_bytes: 3688
from collections import deque

S = input()
Q = int(input())

d = deque(S)
flg = True #Trueが前から,
for i in range(Q):
    t, *a = input().split()
    if t == "1":
        flg = not flg
    else:
        if flg:
            if a[0] == "1":
                d.appendleft(a[1])
            else:
                d.append(a[1])
        else:
            if a[0] == "2":
                d.appendleft(a[1])
            else:
                d.append(a[1])
d = list(d)
if flg:
    print(''.join(d))
else:
    print(''.join(d[::-1]))


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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF (int)1e9  //
#define LINF (ll)4e18  //
#define MOD (int)(1e9)+7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define PI 3.1415926535898

//------------------------------------------------------

int main() {
    string s;
    cin >> s;

    int diff = 0;

    rep(i, s.length() - 1) {
        if (s[i] != s[i + 1]) diff++;
    }

    cout << diff << endl;
    return 0;
}



Measured memory_bytes: 512
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		Set<Long> set = new HashSet<Long>();
		long n=sc.nextLong();
		for(int i=0; i<n; i++) {
			Long a = sc.nextLong();
			if(set.contains(a)) {
				System.out.println("NO");
				sc.close();
				return;
			}
			set.add(a);
		}
		System.out.println("YES");
		sc.close();
	}
}


Measured memory_bytes: 101684
import math,itertools

n = 10**5+1

prime = [1]*(n+1)
prime[0] = 0
prime[1] = 0
for i in range(2,int(math.sqrt(n))+1):
    if not prime[i]:
        continue
    for j in range(i*2,n+1,i):
        prime[j] = 0

A = [0]*(n+1)
for i in range(1,n,2):
	j = (i+1)//2
	if prime[i] and prime[j]:
		A[i] = 1

A = list(itertools.accumulate(A))

Q = int(input())
for i in range(Q):
    l,r = map(int,input().split())
    print(A[r]-A[l-1])



Measured memory_bytes: 7716
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstring>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map> //pair is also included in this library
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define fst first
#define snd second
#define MP make_pair //incase c++11 or later is not available

using namespace std;

typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//prefer define statement
//for reason that const int ver. of INF will raise a silly warning (unused variable)
#define INF (INT_MAX/3)
#define LIM_INF (INT_MAX)
//const int INF = INT_MAX/3;
#define PI = 3.14159265358979323846
/*------------------------------------------------------------------------------*/

char g[505][505];

int vert(int N){
  int ret = 0;
  REP(j, 0, N){
    REP(i, 0, N){
      if(g[i][j] == '.'){
        ret++;
        break;
      }
    }
  }
  return ret;
}

int make_line(int N){
  int ret = N;
  REP(i, 0, N){
    int curr = N;
    int w = 0;
    bool p = false;
    if(g[i][i] == '#'){
      curr = min(curr, N-1);
    }
    REP(j, 0, N){
      if(g[j][i] == '#'){
        p = true;
      }
      if(g[i][j] == '.'){
        w++;
      }
    }
    if(p){
      //cout << "curr: " << curr << endl;
      curr = min(curr, w);
    } else {
      curr = min(curr, w+1);
    }
    ret = min(curr, ret);
  }
  return ret;
}

int main(){
  int N;
  cin >> N;
  bool f = false;
  int black = 0;
  REP(i, 0, N){
    REP(j, 0, N){
      cin >> g[i][j];
      if(g[i][j] == '#'){
        f = true;
        black++;
      }
    }
  }

  if(!f){
    cout << -1 << endl;
  } else if(black == N * N){
    cout << 0 << endl;
  } else {
    int ex = make_line(N);
    cout << ex + vert(N) << endl;
  }

  return 0;
}


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

int main() {
  
  int a,b,c;
  cin >> a >> b >> c;
  
  if ( a == b && b == c ){
    cout << 1 << endl;
  }else if ( a == b || b == c || c == a ){
    cout << 2 << endl;
  }else{
    cout << 3 << endl;
  }
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int k;
const int maxb = 200;
const int maxd = 200;
vector<int> bit;
ll dp[maxb][maxd];
ll dfs(int pos, int num, bool flag)
{
	if(pos == -1) return num == k;
	if(!flag && dp[pos][num] != -1) return dp[pos][num];
	ll ret = 0;
	int end = flag ? bit[pos] : 9;
	for(int i = 0; i <= end; ++i)
		ret += dfs(pos - 1, num + (i != 0), flag && (i == end));
	if(!flag) dp[pos][num] = ret;
	return ret;
}	
ll calc(string s)
{
	reverse(s.begin(), s.end());
	bit.clear();
	for(int i = 0; i < s.length(); ++i)
		bit.push_back(s[i] - '0');
	return dfs(bit.size() - 1, 0, 1);
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	memset(dp, -1, sizeof(dp));
	string L;
	cin >> L >> k;
	cout << calc(L) << endl;
	return  0;
}
		

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for(int& x : a) cin >> x;
  int ans = 0;
  for(int i = 0; i < n; i++) {
    for(int j = i + 1; j < n; j++) {
      for(int k = j + 1; k < n; k++) {
        if(a[i]!=a[j] && a[j]!=a[k] && a[k]!=a[i]) {
          if(a[i]+a[j]>a[k] && a[i]+a[k]>a[j] && a[j]+a[k]>a[i]) {
            ans++;
          }
        }
      }
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3656
H, W = map(int,input().split())
C = ['.' * (W + 2)]

for i in range(H):
    C += ["." + input() + "."]

C += ['.' * (W + 2)]

result = "Yes"
for i in range(1, H + 2):
    for j in range(1, W + 2):
        if C[i][j] == "#":
            if "#" not in [C[i+1][j], C[i-1][j], C[i][j+1], C[i][j-1]]:
                result = "No"

print(result)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
using namespace std;
using P = pair<int, int>;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n), res(n);
  ll ans1 = 0;
  ll ans2 = 0;
  rep(i, n) cin >> a[i];
  sort(ALL(a));
  res[0] = -1;
  if(n % 2 == 0)res[n-1] = 1;
  else res[n-1] = -1;
  int plus = 1;
  for (int i = 1; i < n - 1; i++){
    if(plus)res[i] = 2;
    else res[i] = -2;
    plus = plus ^ 1;
  }
  sort(ALL(res));
  rep(i, n){
    ans1 += a[i] * res[i];
  }
  rep(i, n){
    ans2 += -1 * a[i] * res[n - 1 - i];
  }
  cout << max(ans1, ans2) << endl;
}

Measured memory_bytes: 4860
#include <math.h>
#include <bits/stdc++.h>
#include <deque>
#include <string>
#include <vector>
#include <algorithm>
#define ll long long int
#define l long double
#define pi 3.14159265358979323846
#define mod 1000000007
#define vali 1000000000000000000
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll a[n+1];
    for(int i=1;i<=n;i++)
    {
        ll x;
        cin>>x;
    a[x]=i;
    }
    for(int i=1;i<=n;i++)
    cout<<a[i]<<" ";
    cout<<endl;
}


Measured memory_bytes: 4336
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class Main {
    public static void main(String[] args) throws IOException {
        
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        
        int n = Integer.parseInt(br.readLine());
        int max = 0;
        Map<String, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            String s = br.readLine();
            if (map.containsKey(s)) {
                int cnt = map.get(s);
                map.put(s, ++cnt);
                max = Math.max(max, cnt);
            } else {
                map.put(s, 1);
                max = Math.max(max, 1);
            }
        }
        
        final int MAX = max;
        new ArrayList<>(map.entrySet())
                .stream()
                .filter(e -> e.getValue() == MAX)
                .map(e -> e.getKey())
                .sorted()
                .forEach(k -> {
                    try {
                        bw.write(k + "\n");
                    } catch (IOException e) {}
                });
        
        bw.flush();
    }
}

Measured memory_bytes: 76248
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ll N,P;
    cin >> N >> P;
    vector<ll> A(N);
    rep(i,N){
        cin >> A[i];
    }
    ll odd = 0;
    ll even = 0;
    rep(i,N){
        if (A[i] % 2 == 0) even++;
        else odd++;
    }
    vector<ll> num(52);
    num[0] = 1;
    for (ll i = 0; i < 51; i++){
        num[i + 1] = num[i] * 2;
    }
    vector<vector<ll> > pascal(52, vector<ll> (52));
    pascal[0][0] = 1;
    pascal[1][0] = 1;
    pascal[1][1] = 1;
    for (ll i = 1; i <= 51; i++){
        pascal[i][0] = 1;
        pascal[i][i] = 1;
    }
    for (ll i = 2; i <= 51; i++){
        for (ll j = 1; j < i; j++){
            pascal[i][j] = pascal[i - 1][j] + pascal[i - 1][j - 1];
        }
    }
    if (P == 0){
        ll ans = 0;
        ll pre = num[even];
        for (ll i = 0; i <= odd; i += 2){
            ans += (pre * pascal[odd][i]);
        }
        cout << ans << endl;
    }
    else{
        ll ans = 0;
        ll pre = num[even];
        for (ll i = 1; i <= odd; i += 2){
            ans += (pre * pascal[odd][i]);
        }
        cout << ans << endl;
    }
}

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

int main() {
  int N, sum, n;
  cin >> N;
  n = N,sum = 0;
  while (n != 0) {
    sum += n % 10;
    n = n / 10;
  }
  if (N % sum == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
int main(){
	int A, B, C; cin >> A >> B >> C;
	if(B / A >= C) cout << C << endl;
	else cout << B/A << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys

N,K=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())

S=[0]
for a in A:
    S.append(S[-1]+a)

B=[]    #美しさの全列挙
l=len(S)

for i in range(l):
    for j in range(i+1,l):
        B.append(S[j]-S[i])

B.sort(reverse=True)

kouho=[ 1 for _ in range(len(B))]    #部分和の合計値で、候補となる値を1のbitで表現する

for keta in range(60,-1,-1):
    new_kouho=[]
    goukei=0 #1の出現回数
    for idx,b in enumerate(B):
        b=b>>keta&1
        if kouho[idx]==1:   #元々の候補に入っていれば、値を次の候補に残す
            new_kouho.append(b)
            goukei+=b
        else:
            new_kouho.append(0)       
    if K<=goukei:
        kouho=new_kouho #goukeiがK以上だったら、絞った候補を元の候補列に代入

ans=None
for k,b in zip(kouho,B):
    if k==1:
        if ans is None:
            ans=b
        else:
            ans&=b

print ans

Measured memory_bytes: 156732
#include<iostream>
#include<algorithm>
#include<stack>
#include<functional>
#include<vector>
#include<map>
using namespace std;
#define mp make_pair
typedef pair<pair<int, int>, int> P;
vector<P>v0, v1, v2, v3;
int main() {
	int r, c, n;
	cin >> r >> c >> n;

	for (int i = 0; i < n; i++) {
		int w, x, y, z;
		cin >> w >> x >> y >> z;
		if ((w == 0 || w == r) || (x == 0 || x== c)) {
			if ((y == 0 || y == r) || (z == 0 || z == c)) {
			
				if (w == 0) {
						v3.push_back(P(mp(w, x), i));
				}
				else if (w == r) {
					v1.push_back(P(mp(w, x), i));
				}
				else if(x==0) {
					v0.push_back(P(mp(w, x), i));
				}
				else v2.push_back(P(mp(w, x), i));

				if (y == 0) {
					v3.push_back(P(mp(y,z), i));
				}
				else if (y == r)v1.push_back(P(mp(y, z), i));
				else if (z == 0)v0.push_back(P(mp(y, z), i));
				else v2.push_back(P(mp(y, z), i));
			}
		}
	}
	sort(v0.begin(), v0.end());
	sort(v1.begin(), v1.end());
	sort(v2.begin(), v2.end());
	sort(v3.begin(), v3.end());

	stack<int>S;
	for (int i = 0; i < v0.size(); i++) {
		int t = -1;
		if (S.size())t = S.top();
		if (v0[i].second == t)S.pop();
		else S.push(v0[i].second);
	}
	for (int i = 0; i < v1.size(); i++) {
		int t = -1;
		if (S.size())t = S.top();
		if (v1[i].second == t)S.pop();
		else S.push(v1[i].second);
	}
	int a = v2.size();
	for (int i = a - 1; i > -1;i--) {
		int t = -1;
		if (S.size())t = S.top();
		if (v2[i].second == t)S.pop();
		else S.push(v2[i].second);
	}
	a = v3.size();
	for (int i = a - 1; i > -1;i--) {
		int t = -1;
		if (S.size())t = S.top();
		if (v3[i].second == t)S.pop();
		else S.push(v3[i].second);
	}
	if (S.size())puts("NO");
	else puts("YES");
}

Measured memory_bytes: 3820
#include <iostream>

using namespace std;

int main(){
        string s;
        cin >> s;
        if(s[0]=='Y' && s[1]=='A' && s[2]=='K' && s[3] =='I'){
                cout << "Yes" << endl;
        }else{
                cout << "No" << endl;
        }
        return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr ll INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    int N,K;cin >> N >> K;
    int A[N+1];REPP(i,1,N+1) cin >> A[i];
    bool flag = 0;int cnt = 0;
    REPP(i,1,N){
        if(A[i] + A[i+1] >= K){
            flag = 1;
            cnt = i;
        }
    }
    if(flag){
        cout << "Possible" << endl;
        REPP(i,1,cnt){
            cout << i << endl;
        }
        repp(i,N,cnt){
            cout << i << endl;
        }
    }
    else cout << "Impossible" << endl;
}

Measured memory_bytes: 1280
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
int main(){
    long long n,a,c=9,s=0,b,d=1;
    cin >> n;
    a=log10(n);
    if(a==0){
        cout << n << endl;
    }
    else{
        for(int i=0; i<a; i+=2){
            s+=c;
            c*=100;
            d*=100;
            b=n-d+1; 
        }
        if(a%2==0){
            s+=b;
        }
        cout << s << endl;
    }
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,l,r) for (int i=l;i<=r;i++)
using namespace std;
typedef long long ll;
const int maxn=305;
ll f[maxn][maxn],g[maxn][maxn],c[maxn][maxn],fac[maxn],inv[maxn];
int n,k;
ll mm;
ll dfs(int i,int j);
ll getsum(int i,int j){
	if (~g[i][j]) return g[i][j];
	g[i][j]=0;
	rep(p,j,k) (g[i][j]+=dfs(i,p))%=mm;
	return g[i][j];
}
ll dfs(int i,int j){
	if (~f[i][j]) return f[i][j];
	if (i==1) return f[i][j]=1;
	f[i][j]=0;
	rep(len,1,i-1) {
		(f[i][j]+=getsum(len,j+1)*dfs(i-len,j)%mm*c[i-2][len-1]%mm)%=mm;
	}
	return f[i][j];
}
int main(){
	scanf("%d%d%lld",&n,&k,&mm);
	c[0][0]=1;
	rep(i,1,n) {
		c[i][0]=1; c[i][i]=1;
		rep(j,1,i-1) c[i][j]=(c[i-1][j]+c[i-1][j-1])%mm;
	}
	memset(f,-1,sizeof(f));
	memset(g,-1,sizeof(g));
	dfs(n+1,0);
	printf("%lld\n",f[n+1][0]);
	return 0;
}

Measured memory_bytes: 2432
#!/usr/bin/env python3
import sys
INF = float("inf")


def cmb(n, r):
    r = min(r, n-r)
    if r == 0:
        return 1
    if r == 1:
        return n

    numer = [n - r + k + 1 for k in range(r)]
    denom = [k + 1 for k in range(r)]

    for p in range(2, r+1):
        pivot = denom[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1, r, p):
                numer[k - offset] /= pivot
                denom[k] /= pivot

    result = 1
    for k in range(r):
        if numer[k] > 1:
            result *= int(numer[k])

    return result


def solve(N: int, K: int):

    # N以下のKの倍数の個数
    ans = (N//K)**3
    # print(ans)

    if K & 1 == 0:
        # 偶数ならK//2の倍数であってKの倍数でないものの組み合わせも必要
        ans += (N//(K//2) - N//K)**3

    print(ans)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>

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

using namespace std;

int main()
{
	int h,w;
	while(cin >> h >> w)
	{
		if(h == 0 && w == 0) break;

		rep(i,h)
		{
			rep(j,w)
			{
				cout << "#";
			}
			cout << endl;
		}
		cout  << endl;
	}
	return 0;
}

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
typedef long long ll;
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll 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 {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll 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;
  }
};

int main(){
  int n;
  mint ans=1;
  cin>>n;
  for(int i=1;i<=n;i++){
    ans*=i;
  }
  cout<<ans.x<<endl;
  return(0);
}


Measured memory_bytes: 256
N, K = map(int,input().split())
A = list(map(int,input().split()))
MIN_idx = A.index(min(A))
ans = 0
if (N-(MIN_idx+1)) % (K-1) == 0:
    ans += (N-(MIN_idx+1)) // (K-1)
else:
    ans += (N-(MIN_idx+1)) // (K-1) + 1
    MIN_idx -= (K-1) - (N-(MIN_idx+1)) % (K-1)
if MIN_idx % (K-1) == 0:
    ans += MIN_idx // (K-1)
else:
    ans += MIN_idx // (K-1) + 1
print(ans)


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

int main() {
  string c;
  cin >> c;
  if(c == "a" || c == "e" || c == "i" || c == "o" || c == "u"){
  cout << "vowel" << endl;
  }
  else{
  cout << "consonant" << endl;
  }
}


Measured memory_bytes: 3628
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
int n,b[110],bj2,bj5,bj15,bj25,ans;
int main() {
	scanf("%d",&n);
	for(int i=2;i<=n;i++)
		for(int j=2,temp=i;j<=n;j++)
			while(temp%j==0) {
				temp/=j;
				b[j]++;
			}
	for(int i=2;i<=n;i++)
		if(b[i]>=2) {
			bj2++;
			if(b[i]>=4) {
				bj5++;
				if(b[i]>=14) {
					bj15++;
					if(b[i]>=24) {
						bj25++;
						if(b[i]>=74) ans++;
					}
				}
			}
		}
	ans+=bj15*(bj5-1)+bj25*(bj2-1)+bj5*(bj5-1)/2*(bj2-2);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
program sample
	implicit none
    integer :: a,b,c
    
    read(*,*) a,b,c
    
	if (a+b==c .or. a+c==b .or. b+c==a) then
    	write(*,*) 'Yes'
    else
    	write(*,*) 'No'
    end if

    stop
end program sample


Measured memory_bytes: 2828
N,M = gets.strip.split.map(&:to_i)
vote = gets.strip.split.map(&:to_i)
S = vote.sum
sum = 0
(0..N-1).each do |i|
  if vote[i] >= (S.to_f)/(4*M) then
    sum += 1
  end
end
if sum >= M then
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 14264
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(i=a;i<n;i++)
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
void fill(int a[],int b,int c){
	int i;
	FOR(i,0,b) a[i]=c;
	return;
}
int main(void)
{
	int n,a,cnt=0,i;
	scanf("%d",&n);
	FOR(i,0,n){
		scanf("%d",&a);
		if(a%2) cnt++;
	}
	printf("%s\n",cnt%2?"NO":"YES");
	return 0;
}
    


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

int main() {
	int n;
	cin >> n;
	vector<int> t(n);
	for (int i = 0; i < n; i++)cin >> t.at(i);
	int m;
	cin >> m;
	vector<vector<int>> drink(m, vector<int>(2));
	for (int i = 0; i < m; i++) cin >> drink.at(i).at(0) >> drink.at(i).at(1);
	int non = 0;
	for (int i = 0; i < n; i++) non += t.at(i);
	for (int i = 0; i < m; i++) {
		int ans = non;
		ans -= t.at(drink.at(i).at(0)-1);
		ans += drink.at(i).at(1);
		cout << ans << endl;
	}
}

Measured memory_bytes: 256