akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

			//出力の都度更新をやめる
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);


			Ans();

			//更新する
			Console.Out.Flush();
			
		}
public static void Ans() {

			var inputArray = retreiveLongArray();
			var inputCount = 2;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			var N = (int)inputArray[0];
			var M = (int)inputArray[1];

			var hens = createLongTuppleList(M);

			var ans = 0;

			for (int i = 0; i < M; i++) {
				var map = new Dictionary<int, List<int>>();
				for (int k = 0; k < N; k++) {
					map.Add(k, new List<int>());
				}

				for (int j = 0; j < M; j++) {
					if (i==j) {
						continue;
					}
					var hen = hens[j];
					var a = (int)hen.Item1 - 1;
					var b = (int)hen.Item2 - 1;

					map[a].Add(b);
					map[b].Add(a);
				}

				_isReach = Enumerable.Repeat(false, N).ToArray();
				_map = map;

				DFS(0, -1);

				if (!_isReach.All(x =>x)) {
					ans++;
				}

			}

			//答えの出力
			Console.WriteLine(ans);

		}

		private static bool[] _isReach;
		private static Dictionary<int, List<int>> _map;

		private static void DFS(int current,int from) {
			_isReach[current] = true;
			var nexts = _map[current];

			foreach (var next in nexts) {
				if (next==from) {
					continue;
				}
				if (_isReach[next]) {
					continue;
				}

				DFS(next, current);

			}

		}


		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}


		/// <summary>
		/// 2組みずつの入力データ(数値)からTuppleListを作成する
		/// </summary>
		/// <param name="N"></param>
		/// <returns></returns>
		private static List<Tuple<long, long>> createLongTuppleList(long N) {
			var inpList = new List<Tuple<long, long>>();

			for (int i = 0; i < N; i++) {
				var inp = retreiveLongArray();
				var item1 = inp[0];
				var item2 = inp[1];
				inpList.Add(new Tuple<long, long>(item1, item2));
			}
			return inpList;
		}
	}
}


Measured memory_bytes: 28680
fun main(args: Array<String>) {
    val n = readInt()
    val d = readIntList().toMutableList()
    val m = readInt()
    val t = readIntList()


    if (n < m) {
        println("NO")
        return
    }

    val numD = mutableMapOf<Int, Int>()
    d.forEach {
        numD[it] = numD.getOrDefault(it, 0) + 1
    }

    val numT = mutableMapOf<Int, Int>()
    t.forEach {
        numT[it] = numT.getOrDefault(it, 0) + 1
    }

    numT.forEach {(k, v) ->
        if (numD.getOrDefault(k, 0) < v) {
            println("NO")
            return
        }
    }
    
    println("YES")
    return
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)

Measured memory_bytes: 110700
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N = int(input())
G = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)


dp = [1] * N

def dfs(v, p):
    cnt = 0
    for c in G[v]:
        if c == p:
            continue
        dfs(c, v)
        if dp[c] == 1:
            cnt += 1
        dp[v] += dp[c] - 1
    if cnt > 1:
        dp[v] += cnt - 1

dfs(0, -1)

ans = [1] * N

def dfs2(v, p, par_val):
    cnt = 0
    for c in G[v]:
        if c == p:
            continue
        if dp[c] == 1:
            cnt += 1
        ans[v] += dp[c] - 1
    if p != -1:
        if par_val == 1:
            cnt += 1
        ans[v] += par_val - 1
    if cnt > 1:
        ans[v] += cnt - 1
    for c in G[v]:
        if c == p:
            continue
        dfs2(c, v, ans[v] - (dp[c] - 1) - (1 if dp[c] == 1 and cnt > 1 else 0))

dfs2(0, -1, 0)
print(min(ans))

Measured memory_bytes: 115152
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const int MAX = 100010;

ll mod_pow(ll x, ll e) {
  ll v = 1 % MOD;
  for (; e > 0; e >>= 1) {
    if (e & 1) {
      v = (v * x) % MOD;
    }
    x = (x * x) % MOD;
  }
  return v;
}

ll f[MAX], finv[MAX];
void init() {
  f[0] = 1;
  for (int i = 1; i < MAX; i++) {
    f[i] = i * f[i-1] % MOD;
  }
  finv[MAX-1] = mod_pow(f[MAX-1], MOD - 2);
  for (int i = MAX - 1; i >= 1; i--) {
    finv[i-1] = finv[i] * i % MOD;
  }
}

ll C(int n, int k) {
  if (k > n) {
    return 0;
  }
  return (f[n] * finv[k] % MOD) * finv[n-k] % MOD;
}

int main() {
  init();
  int n;
  cin >> n;
  ++n;
  vector<ll> a(n);
  map<ll, int> cnt;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ++cnt[a[i]];
  }
  int L = 0, R = 0;
  for (auto ps: cnt) {
    if (ps.second == 2) {
      ll v = ps.first;
      for (int i = 0; i < n && a[i] != v; i++, L++);
      for (int i = n - 1; i >= 0 && a[i] != v; i--, R++);
    }
  }
  for (int k = 1; k <= n; k++) {
    ll res = (C(n, k) - C(L + R, k - 1) + MOD) % MOD;
    cout << res << endl;
  }
  return 0;
}


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

int main() {
  int A,V,B,W,T;
  cin>>A>>V>>B>>W>>T;
  
  if(V-W>0){
    V=V-W;
      if(A-B>0){A=A-B;}else{A=B-A;}
      if(V*T-A<0){cout<<"NO"<<endl;}else{cout<<"YES"<<endl;}
  }else{cout<<"NO"<<endl;  }
}

Measured memory_bytes: 3528
# -*- coding: utf-8 -*-


if __name__ == '__main__':
    n, m = list(map(int, input().split()))
    ab = sorted([tuple(map(int, input().split())) for _ in range(m)],
                key=lambda x: x[1])
    count = 1

    # See:
    # https://www.youtube.com/watch?v=nVSWen0oM38
    b = ab[0][1]

    for i in range(1, m):
        if ab[i][0] >= b:
            b = ab[i][1]
            count += 1

    print(count)


Measured memory_bytes: 19024
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <unistd.h>
#include <math.h>
long long int ans=0;
#define  ll long long
//最大公約数
long long int getgcd(long long n, long long m){
  int r;
  if (n > m) {
    long long t = m;
    m = n;
    n = t;
  }
  while ((r = m % n) != 0) {
    m = n;
    n = r;
  }
return n;
}

//階乗
long long factorial(long long n){
    long long int answer = 1;
while(n > 1){
  answer *= n;
  n--;
}
    return answer;
}

//組み合わせ
long long calcNumOfCombination(long long  n, long long r){
    return factorial(n) / (factorial(r) * factorial(n-r));
}
 void yes(){
   printf("Yes\n");
 }

 void no(){
   printf("No\n");
 }

 long long int swap(ll *x,ll *y){
   long long int tmp;
   tmp = *x;
   *x = *y;
   *y = tmp;
 }

int main(int argc, char const *argv[]) {
  ll a=0,b=0;
  scanf("%lld %lld",&a,&b);
  printf("%lld\n",a*b);
  return 0;
}


Measured memory_bytes: 1728
import math

N=int(input())
A = list(map(int,input().split()))
cnt=[0]*(N+1)
for i in range(0,N):
	cnt[A[i]-1]+=1
ans=0
for i in range(0,N+1):
	if cnt[i]==0:
		ans+=0
	else:
		ans+=cnt[i]*(cnt[i]-1)//2

for i in range(0,N):
	point=A[i]
	deff=(cnt[point-1]*(cnt[point-1]-1))//2-((cnt[point-1]-1)*(cnt[point-1]-2))//2
	print(ans-deff)

Measured memory_bytes: 26140
#include<iostream>
#include<stdio.h>

using namespace std;

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

  int r, g, b, n;
  cin >> r;
  cin >> g;
  cin >> b;
  cin >> n;

  int i,j,temp1,temp2;
  int res=0;
  
  for(i=0; i<=n/r; ++i){
    temp1 = n - i * r;
    for(j=0; j<=temp1/g; ++j){
      temp2 = temp1 - j * g;
      if(temp2%b==0){
	++res;
      }
    }
  }
  cout << res << "\n";
  return 0;
}


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

void Main()
{
    string s;
    cin >> s;
    if (s.back() == 's') cout << s + "es" << endl;
    else cout << s + "s" << endl;
}

int main(int argc, char **argv)
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    Main();
    return 0;
}


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

s = []
for i in range(M):
    s.append(list(map(int,input().split())))

p = list(map(int,input().split()))

ans = 0

for i in range(2**N):
    flag = True
    for j in range(M):
        tmp = 0
        for h in range(1,s[j][0]+1):
            if (i>>(s[j][h]-1))&1:##点灯する
                tmp += 1
        if tmp%2 != p[j]:
            flag = False
            break
    if flag:
        ans += 1

print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

class Main{
  public static void main(String[] arg){
    Scanner scan=new Scanner(System.in);
    int a=scan.nextInt();
    int b=scan.nextInt();
    int c=scan.nextInt();
    if(a-b<=c){
      System.out.println(c-a+b);
    }else{
      System.out.println(0);
    }
  }
}

Measured memory_bytes: 21588
L, R = [int(i) for i in input().split()]

if (R-L) > 2019:
  R = 2019 + L

lst = []
for i in range(L, R):
  for j in range(i+1, R+1):
    a = (i*j) % 2019
    lst.append(a)
    
print(min(lst))

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

#define rep(i,n) for (int i = 0; i < (n); i++)
#define ru(a,b) (((a)+((b)-1)) / (b))   //切り上げ(a/b)
#define dump(x)  cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using P = pair<int, int>;

bool compare_by_b(pair<int, string> a, pair<int, string> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

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

	map<string, int> s;
	rep(i, n) {
		string ss;
		cin >> ss;
		//s.insert_or_assign(ss, s[ss]+1);

		if (s.count(ss))
			s[ss]++;
		else
			s.insert(pair<string, int>(ss, s[ss] + 1));
	}

	//std::cout << "---------------" << endl;

	vector<pair<int, string>> pair_s;
	for (auto x : s) {
		//std::cout << x.first << " " << x.second << endl;
		pair_s.push_back(pair<int, string>(x.second, x.first));
	}

	sort(pair_s.begin(), pair_s.end(), greater<pair<int, string>>());

	//std::cout << "---------------" << endl;
	
	int max = 0;
	rep(i, pair_s.size()) {
		if (max <= pair_s[i].first)
		{
			//std::cout << pair_s[i].first << " " << pair_s[i].second << endl;
			max = pair_s[i].first;
		}
	}

	sort(pair_s.begin(), pair_s.end(), compare_by_b);

	//std::cout << "---------------" << endl;
	rep(i, pair_s.size()) {
		if (max <= pair_s[i].first)
		{
			//std::cout << pair_s[i].first << " " << pair_s[i].second << endl;
			std::cout << pair_s[i].second << endl;
			max = pair_s[i].first;
		}
	}

	return 0;
}

Measured memory_bytes: 29428
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

def main():
    A,B=mis()
    for i in range(1000000):
        if math.floor(i*.08)==A and math.floor(i*.1)==B:
            print(i)
            return
    print(-1)

main()







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

class Main{
    public static void main(String[] args){
        FastScanner fsc=new FastScanner();
        int n=fsc.nextInt();
        long[] a=new long[n];
        for(int i=0;i<n;i++){
            a[i]=fsc.nextLong();
        }
        fsc.close();
        Arrays.sort(a);
        int l=a.length;
        for(int i=0;i<l/2;i++){
            long tmp=a[i];
            a[i]=a[l-i-1];
            a[l-i-1]=tmp;
        }
        long h=-1, w=-1;
        for(int i=0;i<n-1;i++){
            if(a[i]==a[i+1]){
                if(h<0){
                    h=a[i++];
                } else if(w<0){
                    w=a[i];
                    break;
                }
            }
        }
        if(w<0) System.out.println(0);
        else System.out.println(h*w);
    }
    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte(){
            if(ptr<buflen) return true;
            else{
                ptr = 0;
                try{
                    buflen = in.read(buffer);
                }
                catch(IOException e){
                    e.printStackTrace();
                }
                if(buflen<=0) return false;
            }
        return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }
                else if(b == -1 || !isPrintableChar(b)) return minus ? -n : n;
                else throw new NumberFormatException();
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
        public void close(){
            try{in.close();}
            catch(IOException e){e.printStackTrace();}
        }
    }
}


Measured memory_bytes: 22176
// 解説読んだ
// PythonだとTLEなりやがるので

package main

import "fmt"

type Grid struct {
	X, Y int
}

func main() {
	var H, W int
	fmt.Scan(&H, &W)
	T := make([][]bool, H)
	queue := []Grid{}
	for i := 0; i < H; i++ {
		var line string
		fmt.Scan(&line)
		T[i] = make([]bool, W)
		for j, c := range []rune(line) {
			if string(c) == "#" {
				T[i][j] = true
				queue = append(queue, Grid{X: j, Y: i})
			}
		}
	}
	steps := []int{0, 1, 0, -1, 0}
	ans := 0
	for len(queue) > 0 {
		nex_queue := []Grid{}
		for _, q := range queue {
			for i := 0; i < 4; i++ {
				nx, ny := q.X+steps[i], q.Y+steps[i+1]
				if 0 <= nx && nx < W && 0 <= ny && ny < H && !T[ny][nx] {
					T[ny][nx] = true
					nex_queue = append(nex_queue, Grid{X: nx, Y: ny})
				}
			}
		}
		queue = nex_queue
		ans++
	}
	fmt.Println(ans - 1)
}


Measured memory_bytes: 42240
#include<stdio.h>

int main()
{
    int a,b,c,k;
    scanf("%d %d %d %d",&a,&b,&c,&k);
    if(k<=a)
    printf("%d",k*1);
    else if(k>a&&k<=a+b)
    {
        printf("%d",a*1);
    }
    else if(k>a+b&&k<=a+b+c)
    {
        printf("%d",(a*1)+((k-(a+b))*(-1)));
    }
}


Measured memory_bytes: 1728
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
using namespace std;
int main(void) {
	int n;
	stack<int> st;
	while (cin >> n) {
		if (n == 0) {
			cout << st.top() << endl;
			st.pop();
		}
		else {
			st.push(n);
		}
	}
	return 0;
}

Measured memory_bytes: 2956
#include <iostream>

using namespace std;

bool is_prime(int x) {
  if (x == 2) return true;
  if (x < 2 || x % 2 == 0) return false;

  for (int i = 3; i*i <= x; i += 2)
    if (x % i == 0) return false;

  return true;
}

int main() {
  int ans = 0, n; cin >> n;

  while(n--) {
    int x; cin >> x;
    if (is_prime(x)) ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 1160
N = int(input())
ketasu = len(str(N))

ans = 9
if (ketasu % 2 == 0) and (ketasu != 2):
    for i in range(2, ketasu, 2):
        ans += 9*(10**(i))
elif (ketasu % 2 != 0) and (ketasu != 1):
    for i in range(2, ketasu-1, 2):
        ans += 9*(10**(i))
    ans = ans + (N - 10**(ketasu-1) + 1)

if ketasu == 1:
    ans = N

print(ans)


Measured memory_bytes: 3064
main = do
    ss <- getLine
    let (n,x) = (ns!!0, ns!!1)
                  where ns = map (\x -> read x :: Int) $ words ss
    if n==0 && x==0
        then return ()
        else do
            putStrLn $ show $ solve n x
            main

solve n x = length $ filter (\l -> sum l == x) [[x,y,z] | x<-[1..n], y<-[1..n], z<-[1..n], x<y, y<z]


Measured memory_bytes: 5508
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

int dx[] = { -1, 0, 1, 0, -1, -1, 1, 1};
int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};


int main() {

	long long  n; cin >> n;
	vector<long long > a;
	for (long long  i = 0; i <= n - 1; i++) {
		long long  x; cin >> x;
		a.push_back(x);
		a.push_back(x);
	}
	sort(a.begin(), a.end());

	long long  j = (long long )a.size() - 2;
	long long  ans = 0;

	while (--n and j > 0) {
		ans += a[j--];
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 7056
from sys import stdin
def solve():
  n = int(input())
  s = stdin.readline().rstrip()
  
  leftblack = 0
  leftwhite = 0
  rightblack = s.count('#')
  rightwhite = s.count(".")
  
  ans = leftblack+rightwhite
  
  for i in range(n):
    if s[i] == "#":
      leftblack += 1
      rightblack -= 1
    else:
      leftwhite += 1
      rightwhite -= 1
    ans = min(ans,leftblack+rightwhite)
  
  print(ans)
solve()

Measured memory_bytes: 3500
//============================================================================
// Name        : AOL.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
	int a,b,c,d,l,n;
	cin>>l>>a>>b>>c>>d;
	int kokugo,sansuu,ooihou;
    kokugo=a/c;
    if( a%c>0)kokugo+=1;
    sansuu=b/d;
    if( b%d>0)sansuu+=1;
    n=kokugo;
    if( kokugo<sansuu)n=sansuu;
    cout<<l-n<<endl;

}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
typedef long long ll;
const ll inf = 1e9;
int main(){
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,n)cin >> a[i];
    int q; cin >> q;
    rep(i,q){
        int com, b, e;
        cin >> com >> b >> e;
        if(com == 0)cout << *min_element(a.begin()+b, a.begin()+e) << endl;
        else cout << *max_element(a.begin()+b, a.begin()+e) << endl;
    }
    return 0;
} 


Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define ll long long int
#define vl vector<ll>
#define pb push_back
using namespace std;
int main()
{
    ll t,tp,mx=0,c=0,n,i,j,k;
        cin >> n;
        vl v(n+1,0);
        for(i=1;i<=n;i++)
        cin >> v[i];
        set<ll> s;
        s.insert(1);c=0;
        i=1;
        while(true)
        {
        	c++;
        	if(v[i]==2)
        	break;
        	i=v[i];
        	if(s.count(i))
        	{
        		c=-1;
        		break;
        	}
        	else
        	{
        		s.insert(i);
        	}
        }
        cout << c ;
        
    
    return 0;
}

Measured memory_bytes: 8744
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <climits>
#include <cmath>

using namespace std;




int main(int argc, char *argv[])
{
	int n, k;
	int ans = INT_MAX;
	vector<int> h;

	cin >> n >> k;


	//input
	for (int i = 0; i < n; i++){
		int hi;

		cin >> hi;

		h.push_back(hi);
	}


	//sort
	sort(h.begin(), h.end());


	//calc
	for (int i = 0; i + k - 1 < n; i++){
		int hmin = h[i];
		int hmax = h[i + k - 1];

		if (hmax - hmin < ans){
			ans = hmax - hmin;
		}
	}

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


Measured memory_bytes: 1020
#include <cstdio>
#include <iostream>
#include <stdlib.h>// malloc
using namespace std;

bool *s = (bool*)malloc(200010*sizeof(bool));
bool *t = (bool*)malloc(200010*sizeof(bool));


int main(){

	int M,N;
	cin >> M >> N;
	for(int i = 0; i <= M; i++){
		s[i] = false;
		t[i] = false;
	}
	for(int i = 0; i < N; i++){
		int a,b;
		cin >> a >> b;
		if(a == 1) s[b] = true;
		else if(b == M) t[a] = true;

	}

	for(int i = 2; i < M; i++){
		//cout << s[i] << " " << t[i]<<endl;
		if(s[i] == true && t[i] == true)
			{
				cout << "POSSIBLE" << endl;

				return 0;
			}

	}
		cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 640
#include <stdio.h> 
 
 
 int main(){ 
     char number[1001]; 
     int i, sum; 
     while(1){ 
         scanf("%s", number); 
         if(number[0]=='0')break; 
         sum=0; 
         for(i=0;number[i]!='\0';i++){ 
             sum+=number[i]-'0'; 
         } 
         printf("%d\n", sum); 
     } 
 
 
     return 0; 
 } 



Measured memory_bytes: 2124
//https: //atcoder.jp/contests/dp/tasks/dp_c
#include <iostream>
#include <vector>
#include <tuple>

int main()
{
    int n;
    std::cin >> n;
    std::vector<std::tuple<int, int, int>> days(n + 1);
    for (int i = 1; i <= n; ++i)
    {
        int a, b, c;
        std::cin >> a >> b >> c;
        days[i] = std::make_tuple(a, b, c);
    }
    std::vector<std::vector<int>> dp(n + 1, std::vector<int>(4, 0));
    dp[1][1] = std::get<0>(days[1]);
    dp[1][2] = std::get<1>(days[1]);
    dp[1][3] = std::get<2>(days[1]);
    for (int i = 2; i <= n; ++i)
    {
        dp[i][1] = std::get<0>(days[i]) + std::max(dp[i - 1][2], dp[i - 1][3]);
        dp[i][2] = std::get<1>(days[i]) + std::max(dp[i - 1][1], dp[i - 1][3]);
        dp[i][3] = std::get<2>(days[i]) + std::max(dp[i - 1][1], dp[i - 1][2]);
        //std::cout << dp[i][1] << " " << dp[i][2] << " " << dp[i][3] << '\n';
    }
    std::cout << std::max(dp[n][1], std::max(dp[n][2], dp[n][3])) << '\n';
    return 0;
}

Measured memory_bytes: 9840
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
  int n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n+1), b(m+1);
  a[0] = 0; b[0] = 0;
  for(int i = 1; i < n+1; i++){
    int x;
    cin >> x;
    a[i] = a[i-1] + x;
  }
  for(int i = 1; i < m+1; i++){
    int x;
    cin >> x;
    b[i] = b[i-1] + x;
  }
  
  int ans = 0;
  for(int i = 0; i < n+1; i++){
    if(a[i] > k) continue;
    int left = 0, right = b.size();
    while (right - left > 1) {
      int mid = left + (right - left) / 2;
      if (b[mid] > k-a[i]) right = mid;
      else left = mid;
    }
    if(right == (int)b.size()) ans = max(ans, (int)b.size()-1+i);
    else ans = max(ans, left+i);
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6400
#include<stdio.h>
int main(){
  int i,n,a,b,count=0,num;
  scanf("%d %d %d",&n,&a,&b);
  for(i=1;i<=n;i++){
    num=i/10000+(i/1000)%10+(i/100)%10+(i/10)%10+i%10;
    if(num>=a && num<=b)
      count+=i;
  }
  printf("%d\n",count);
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

void _26adic(li s,vector<int>& v){
  int i=0;
  while(s){
    v[i]=s%26;
    s/=26;
    i++;
  }
}


int main(){
  li n; cin >>n;
  int k=1;
  li s=26;
  while(1){
    if(n<=s)break;
    else{
      n-=s;
      k++;
      s*=26;
    }
  }
  if(df)print(n,k);
  vector<int> v(k,0);
  _26adic(n-1,v);
  reverse(v.begin(),v.end());
  if(df) rep(i,v.size())print(v[i]);
  rep(i,v.size()){
    char c=v[i]+'a';
    cout << c;
  }
  print("\n");
}


Measured memory_bytes: 3624
/*
_________________________
|   LIVE FREE OR DIE     |
|       327 2153         |
|          New           |
|_______HAMPSHIRE________|
 
*/
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define MAX 200005
#define int long long
#define MOD 1000000007

int32_t main()
{
	IOS;
	string s,k;cin>>s>>k;
	if(s.length()+1 == k.length() && s.substr(0,s.length())==k.substr(0,s.length()))
		cout<<"Yes\n";
	else
		cout<<"No\n";
	return 0;
}

Measured memory_bytes: 3656
import sys

input = sys.stdin.readline

n = int(input())
SET = set()
dict = {}
ans = 0
for i in range(n):
    s = list(input())
    s.sort()
    s = str(s)
    if s in SET:
        if s in dict:
            dict[s] += 1
        else:
            dict[s] = 1
    SET.add(s)

for i in dict.values():
    ans += i * (i + 1) // 2
print(ans)


Measured memory_bytes: 19052
#include<stdio.h>

int main(int argc, char *argv[]){

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

  if(((n%10)==2) || ((n%10)==4) || ((n%10)==5) || ((n%10)==7) || ((n%10)==9)){
    printf("hon\n");
  }else if(((n%10)==0) || ((n%10)==1) || ((n%10)==6) || ((n%10)==8)){
    printf("pon\n");
  }else if((n%10)==3){
    printf("bon\n");
  }

  return 0;
}



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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

using Graph = vector<vint>;

struct BICC {
  vint ord, low, cmp;
  set<Pi> bs;
  BICC(){}
  void init(const Graph& graph) {
    int n = graph.size();
    resz(ord, n, -1);
    resz(low, n);
    resz(cmp, n, -1);
  }
  void dfs(const Graph& graph, int u, int p, int& k) {
    ord[u] = low[u] = k++;
    for(int v : graph[u]) {
      if(v == p) continue;
      if(~ord[v]) chmin(low[u], ord[v]);
      else {
	dfs(graph, v, u, k);
	chmin(low[u], low[v]);
	if(ord[u] < low[v]) bs.emplace(minmax(u, v));
      }
    }
  }
  void fillcmp(const Graph& graph, int u, int k) {
    cmp[u] = k;
    for(int v : graph[u]) {
      if(cmp[v] == -1 && !bs.count(minmax(u, v))) fillcmp(graph, v, k);
    }
  }
  Graph build(const Graph& graph) {
    init(graph);
    int n = graph.size(), k = 0;
    rep(u, n) {
      if(ord[u] == -1) dfs(graph, u, -1, k);
    }
    int sz = 0;
    rep(u, n) {
      if(cmp[u] == -1) fillcmp(graph, u, sz++);
    }
    Graph tree(sz);
    set<Pi> exist;
    for(Pi b : bs) {
      if(exist.count(b)) continue;
      exist.emplace(b);
      int u, v; tie(u, v) = b;
      tree[cmp[u]].push_back(cmp[v]);
      tree[cmp[v]].push_back(cmp[u]);
    }
    return tree;
  }
};

const int MAX_N = 200010;

int N, M;
Graph graph, tree;

int cmp_sz[MAX_N];
int dp[2][MAX_N];
void dfs(int u, int p) {
  dp[0][u] = 0;
  dp[1][u] = cmp_sz[u];
  for(int v : tree[u]) {
    if(v == p) continue;
    dfs(v, u);
    dp[0][u] += max(dp[1][v], dp[0][v]);
    dp[1][u] += dp[0][v];
  }
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> N >> M;
  resz(graph, N);
  rep(i, M) {
    int s, t;
    cin >> s >> t;
    graph[s].push_back(t);
    graph[t].push_back(s);
  }
  BICC bicc;
  tree = bicc.build(graph);
  rep(u, N) ++cmp_sz[bicc.cmp[u]];
  memset(dp, -1, sizeof(dp));
  int ans = 0;
  rep(i, tree.size()) {
    if(~dp[0][i]) continue;
    dfs(i, -1);
    ans += max(dp[0][i], dp[1][i]);
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 33784
def SelectionSort(l):
  countSwap = 0
  for i in range(len(l)):
    minj = i
    for j in range(i, len(l)):
      if l[j] < l[minj]:
        minj = j
    if minj == i:
      continue
    else:
      temp = l[i]
      l[i] = l[minj]
      l[minj] = temp
      countSwap += 1
  print(" ".join(map(str, l)))
  print(countSwap)

N = input()
l = list(map(int, input().split()))
SelectionSort(l)


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

using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rInt(a) scanf("%d",&a);
#define MAXN 200010
#define INF 1 << 30
main(){
    int n, diff;
    scanf("%d %d",&n,&diff);
    bool taken[MAXN];
    vi arr (MAXN,INF);
    rep(i,MAXN) taken[i] = false;
    int val;
    int total = 0;
    rep(i,n){
        scanf("%d",&val);
        if(!taken[val]){
            arr[val] = 1;
            total++;
            taken[val] = true;
        }else{
            arr[val]++;
        }
    }
    sort(arr.begin(),arr.end());
    int counter = 0;
    int pos = 0;
    while(total>diff){
        counter += arr[pos];
        total--;
        pos++;
    }
    cout << counter << endl;
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)


#define INF (1e9)
typedef long long unsigned int ll;


int main()
{

    int a,b,c;
    cin >> a>>b>>c;

    if(a*c<b){
        cout << c;
    }else{
        int d = b / a;
        cout << d;
    }

    return 0;
}


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

using namespace std;

#define ll long long

const int N = 2e5+15;

int ar[N],temp[N];

int find(int x,int n){
    int l=1,r= n,mid;

    while(l<r){
        mid = (l+r+1)/2;
        if(x<temp[mid])
            r = mid-1;
        else
            l = mid;
    }
    return l;
}
int pen[N];
void update(int ind,int x){
    while(ind<N)
        pen[ind] += x, ind+= ind&(-ind);
}
int query(int ind){
    int ret=0;
    while(ind)
        ret += pen[ind],ind = ind&(ind-1);
    return ret;
}
int solve(int n){
    int m = (n+1)/2;
    int l= 1,r = N-1,mid;

    while(l<r){
        mid = (l+r)/2;

        if(m<=query(mid))
            r= mid;
        else
            l = mid+1;
    }

    return temp[l];
}
int main(){

    //freopen("input.txt","r",stdin);
    int n;
    cin>>n;
    for(int i=1;i<=n;++i){
        scanf("%d",&ar[i]);temp[i]= ar[i];
    }
    sort(temp+1,temp+n+1);
    for(int i=1;i<=n;++i){
        ar[i]= find(ar[i],n);
    }
    for(int i=1;i<=n;++i){
        update(ar[i],1);
    }
    for(int i=1;i<=n;++i){
        update(ar[i],-1);

        printf("%d\n",solve(n-1));

        update(ar[i],1);
    }
    return 0;
}

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

int main() {
  string x;
  int N,K,R,S,P;
  long long A,ans;
  ans=0;
  cin >>N>>K>>R>>S>>P>>x;
  vector<int> f(N);
  for(int i=0;i<N;i++){
    f[i]=0;
  }

  for(int i=0;i<K;i++){
    f[i]=1;
    if(x[i]=='r'){
      ans+=P;
    }
    else if(x[i]=='s'){
      ans+=R;
    }
    else{
      ans+=S;
    }
  }
    
 for(int i=K;i<N;i++){
   if(x[i]==x[i-K]&&f[i-K]==1){
continue;
   }
   else{
         f[i]=1;
    if(x[i]=='r'){
      ans+=P;
    }
    else if(x[i]=='s'){
      ans+=R;
    }
    else{
      ans+=S;
    }
  }
 }
  cout<<ans<<endl;
}


Measured memory_bytes: 896
p = [1]*51
t = [1]*51
def f(n,x):
    if n==0:
        return 1
    if x==1:
        return 0
    if x==t[n]:
        return p[n]
    if x==p[n]:
        return p[n-1]+1
    if x<p[n]:
        return f(n-1,x-1)
    return p[n-1]+f(n-1,x-p[n])+1

for i in range(1,51):
    p[i] = p[i-1]*2+1
    t[i] = t[i-1]*2+3
n,x = map(int,input().split())    
print(f(n,x))


Measured memory_bytes: 3064
use std::io::{BufRead, Write};
use std::io;

fn solve<R: BufRead, W: Write>(mut input: R, mut output: W) {
    let mut buf = String::new();
    input.read_line(&mut buf).unwrap();
    let s = buf.trim_right().as_bytes().to_owned();
    assert_eq!(s.len(), 4);
    writeln!(output, "{}", if (s[0] == s[1] || s[2] == s[3]) && s[1] == s[2] { "Yes" } else { "No" }).unwrap();
}

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    solve(stdin.lock(), stdout.lock());
}

#[cfg(test)]
mod tests {
    fn test(input: &str, output: &str) {
        let mut v: Vec<u8> = Vec::new();
        ::solve(input.as_bytes(), &mut v);
        assert_eq!(String::from_utf8(v).unwrap(), output);
    }

    #[test]
    fn case1() {
        test(
            "1118
",
            "Yes\n",
        );
    }

    #[test]
    fn case2() {
        test(
            "7777
",
            "Yes\n",
        );
    }

    #[test]
    fn case3() {
        test(
            "1234
",
            "No\n",
        );
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cstring>

using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    double ans = 0;
    for(int i = 1; i <= n ; ++i){
        double temp  = 1.0 / n;
        int a = i;
        while(a < k ){
            a    *= 2;
            temp /= 2;
        }
        ans +=  temp;
    }        
    printf("%.10f\n",ans);
}

Measured memory_bytes: 256
li = list(map(str, input()))
x=0
y=0

if 'N' in li and 'S' in li and not 'E' in li and not 'W' in li:
  print('Yes')
  exit()
  
if 'E' in li and 'W' in li and not 'S' in li and not 'N' in li:
  print('Yes')
  exit()

for i in range(len(li)):
  if li[i]=='N':
    x=x+1
  elif li[i]=='S':
    x=x-1
  elif li[i]=='E':
    y=y+1
  elif li[i]=='W':
    y=y-1

if x==0 and y==0:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9092
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(),x.end()
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
const int mod = 1e9+7;
const int INF = 2e9;
// const ll INF = 1e12;
const int MAX = 1e6;
// const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

// struct edge {int to, cost;}; // 辺
// vector<edge> graph[MAX]; // 隣接リスト
// bool visited[MAX]; // 訪問状況

int main() {
    // input
    int n;
    cin >> n;
    vi a(n), b(n), c(n);
    rep(i, n) {
        cin >> a[i];
    }
    rep(i, n) {
        cin >> b[i];
    }
    rep(i, n) {
        cin >> c[i];
    }
    // solve
    sort(ALL(a));
    sort(ALL(b));
    sort(ALL(c));
    ll ans = 0;
    rep(j, n) {
        ll i = lower_bound(ALL(a), b[j]) - a.begin();
        ll k = c.end() - upper_bound(ALL(c), b[j]);
        ans += i * k;
    }
    // output
    cout << ans << endl;
}

Measured memory_bytes: 4572
import java.util.*;

public class Main {
	public static void main(String[] args) {
			Scanner scan =  new Scanner(System.in);
			int N = scan.nextInt();
			int K = scan.nextInt();
			ArrayList<Integer> al = new ArrayList<>();
			for(int i=0;i<N;i++){
				al.add(scan.nextInt());
			}
			Collections.sort(al);
			int ans = 0;
			for(int i=0;i<K;i++){
				ans+=al.get(i);
			}
			System.out.println(ans);
	}
}


Measured memory_bytes: 30608
#include<bits/stdc++.h>
using namespace std;
#define itn int
#define int long long
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  itn n,k;
  int sum=1,mx,mn;
  map<int,int> date={};
  cin>>n>>k;
  mx=n;
  mn=0;
  for(int i=1;i<k;i++){
    mn+=i;
    mx+=n-i;
    if(mx>n*(n+1)/2) mx=n*(n+1)/2;
    //cout<<mn<<" "<<mx<<"\n";
  }
  for(int i=k;i<n+1;i++){
    //cout<<mn<<" "<<mx<<"\n";
    sum+=mx-mn+1;
    mn+=i;
    mx+=n-i;
    if(mx>n*(n+1)/2) mx=n*(n+1)/2;
    sum%=1000000007;
  }
  cout<<sum%(1000000007)<<"\n";
}

Measured memory_bytes: 3652
n=int(input())
M,R=10**9+7,range(4)
dp=[[[[0]*4for k in R]for j in R]for i in range(n+1)]
dp[0][3][3][3]=1
for i in range(1,n+1):
  for j in R:
    for k in R:
      for l in R:
        for m in R:
          if(2,0,1)!=(k,l,m)!=(0,1,2)!=(k,l,m)!=(0,2,1)!=(j,l,m)!=(0,2,1)!=(j,k,m):dp[i][k][l][m]=(dp[i][k][l][m]+dp[i-1][j][k][l])%M
print(sum(c for a in dp[n]for b in a for c in b)%M)

Measured memory_bytes: 3316
#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() {
    ll n, M, V, P;
    cin >> n >> M >> V >> P;

    vl a(n+1);
    a[0] = INF;
    exrep(i, 1, n) {
        cin >> a[i];
    }
    sort(rall(a));

    // aを降順にソートすると、a[i]が採用されるならばa[1],a[2],…,a[i-1]も採用される
    // なので「x番目に初期スコアが高い問題は採用されるか？」という判定問題で二分探索すればよい
    // x <= P の場合問題xは採用される
    // a[x] + M < a[P] の場合問題xは採用されない
    // それ以外の場合は「1,2,…,P-1 & x」番目の問題が採用されるようにするのが最適
    // なぜなら問題xはP-1問を除いて他のすべての問題よりスコアが高くなる必要があるので、除くP-1問としてはスコアの大きい方から順に選ぶべきだから
    // 全ジャッジが問題1,2,…,P-1 & xに投票するとしてよい
    // 問題x+1,x+2,…,nも問題xよりスコアが高くなることはないので全ジャッジが投票してよい
    // そして投票後の問題xのスコアは a[x] + M なので、P <= i < x なるiについては a[x] + M - a[i] 人まで投票してよい
    // 以上より入れられてもかまわない票の総数yは、 y = M * (P + n - x) + (sum_{P <= i < x} (a[x] + M - a[i])) となる
    // y < M*V のとき問題xに採用される可能性はない
    // M*V <= y のとき問題xに採用される可能性があることを示す
    // 問題iに入れられてもかまわない票の数をb[i](<=M)とし、(sum_{1 <= i <= n} b[i]) >= M*V と仮定する
    // 問題iがiの昇順でb[i]回連続で現れる数列を考えこの数列の最初のM*V問にジャッジ1,2,…,M,1,2,…,M,…,1,2,…,Mと票を割り当てる
    // このときどの問題に入る票数もb[i]以下で、どのジャッジもV票を投じ、どのジャッジも同じ問題に二度投票していない
    // よって M*V <= y のとき問題xに採用される可能性があるといえる

    ll left = 0;
    ll right = n+1;
    while(right - left > 1) {
        ll mid = (left + right)/2;
        ll x = mid;
        if(x <= P) {
            left = mid;
        }
        else if(a[x] + M < a[P]) {
            right = mid;
        }
        else {
            ll y = M * (P + n - x);
            exrep(i, P, x-1) {
                y += a[x] + M - a[i];
            }
            if(M*V <= y) {
                left = mid;
            }
            else {
                right = mid;
            }
        }
    }
    
    out(left);
    re0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For(i, 0, n)
#define rrep(i, n) rFor(i, n, 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int main(){
    int n;
    scanf("%d", &n);
    int a[n];
    rep(i, n) scanf("%d", &a[i]);
    int ans = 0;
    rep(i, n)For(j, i + 1, n)For(k, j + 1, n){
        if(a[i] != a[j] && a[j] != a[k] && a[k] != a[i]){
            ans += (a[i] < a[j] + a[k] && a[j] < a[i] + a[k] && a[k] < a[i] + a[j]);
        }
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 3824
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vi = vector<int>;
using vs = vector<string>;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repp(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define repd(i, n) for(ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()

ll k, l, m, n;
const ll M = 1e9 + 7;



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

	int x;
	cin >> x;

	cout << 1 - x << endl;
}

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

using namespace std;

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main() {
  int N;
  cin >> N;
  cout << N << ":";
  for(auto p : prime_factor(N)) {
    while(p.second--) cout << " " << p.first;
  }
  cout << endl;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()
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; }

int main(){
  int n;
  cin >> n;
  vl a(n);
  rep(i,n) cin >> a.at(i);
  sort(all(a));
  reverse(all(a));
  int cnt = 0;
  long ans = 0;
  rep(i,n-1){
    ans += a.at((i+1)/2);
  }
  cout << ans << endl;
}

Measured memory_bytes: 4840
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
const int mod=1e9+7;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;cin>>N;
  int num[N];
  FOR(i,0,N)num[i]=i+1;
  map<int,int> MAP;
  FOR(i,0,N){
    int x=num[i];
    FOR(j,2,sqrt(num[i])+1){
      while(x%j==0){
        MAP[j]++;
        x/=j;
      }
    }
    if(x>1)MAP[x]++;
  }
  ll ans=1;
  for(auto m : MAP){
    ans*=m.second+1;
    ans%=mod;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <assert.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <string.h>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;

const int N = 1002;

long long a, b, c;

int main() {
    cin >> a >> b >> c;
    long long ans = b + min(b, c);
    c -= min(b, c);
    ans += min(a, c);
    c -= min(a, c);
    ans += c > 0;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h=0, w=0;
		while (true) {
			int H = sc.nextInt();
			int W = sc.nextInt();
			if (H == 0 && W == 0){
				break;
			}
			for (h = 0; h < H; h++) {
				for (w = 0; w < W; w++) {
					if (h % 2 == 0){
						if (w % 2 == 0){
							System.out.print("#");
						} else {
							System.out.print(".");
						}
					} else {
						if (w % 2 == 0){
							System.out.print(".");
						} else {
							System.out.print("#");
						}
					}
				}
				System.out.println("");
			}
			System.out.println("");
		}

	}

}

Measured memory_bytes: 33232