akhauriyash/Code-Regression huggingface dataset:
X = int(input())

if X<=599:
  print(8)
elif X<=799:
  print(7)
elif X<=999:
  print(6)
elif X<=1199:
  print(5)
elif X<=1399:
  print(4)
elif X<=1599:
  print(3)
elif X<=1799:
  print(2)
else:
  print(1)

Measured memory_bytes: 61612
#include <stdio.h>
int main(){
	int n, max=0, t, i, a;

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

	for(i=0;i<t;i++){
		scanf("%d", &a);
		if(max<a)
			max=a;
	}

	max-=n-max;
	printf("%d\n", 0<max-1?max-1:0);

	return 0;
}

Measured memory_bytes: 128
n, m = list(map(int, input().split()))

c = [0] * (n+1)

py = []

for i in range(m):
    py.append(list(map(int, input().split())) + [i])

py.sort(key=lambda x:x[1])

a = [""] * m

for p, y, i in py:
    c[p] += 1
    x = c[p]
    z = str(p * 1000000 + x)
    #print(a)
    if len(z) < 12:
        a[i] = "0" * (12-len(z)) + z
    else:
        a[i] = z

for x in a:
    print(x)

Measured memory_bytes: 36524
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod;

int main(){
  string s; cin>>s;
  bool ok=1;
  for(int i=0;i<3;i++)if(s[i]==s[i+1])ok=0;
  cout<<(ok?"Good":"Bad")<<endl;
  return 0;
}


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

using namespace std;

int main() {
    int soma = 0;
    char digito;
    while(cin >> digito){
        soma+=int(digito)-48;
        if(soma%9==0) soma = 0;
    }
    if(soma==0) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 3068
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

vector<int> MakePrimeNumber(int);
vector<int> MakePlus(int, int, vector<int>);

int main(){
  int n, m, count;
  vector<int> prime, data;

  prime = MakePrimeNumber(200000);

  while(1){
    cin >> n >> m;
    if(n == -1 && m == -1) break;

    data = MakePlus(n, m, prime);

    cout << data[m-1] << endl;
    data.clear();
  }

  return 0;
}

vector<int> MakePrimeNumber(int n){
  int i, j, k;
  vector<int> data;

  data.push_back(2);
  data.push_back(3);
  for(i=5; i<=n; i+=2){
    for(j=1, k=0; data[j]<=sqrt(i); ++j){
      if(i%data[j] == 0){
        k = 1;
        break;
      }
    }
    if(k == 0) data.push_back(i);
  }
  return data;
}

vector<int> MakePlus(int n, int m, vector<int> prime){
  int x;
  vector<int>::iterator i, j, k, l;
  vector<int> data;

  i = upper_bound(prime.begin(), prime.end(), n);
  for(j=i; data.size()<m; ++j){
    for(k=i; k<=j; ++k) data.push_back(*j + *k);
  }

  sort(data.begin(), data.end());

  while(1){
    for(k=i; k<=j; ++k){
      x = *j + *k;
      if(x < data[m-1]){
	l = upper_bound(data.begin(), data.end(), x);
	data.insert(l, x);
      }else if(k == i){
	return data;
      }
    }
    ++j;
  }
}

Measured memory_bytes: 1352
#include <bits/stdc++.h>
using namespace std;
//define
#define itn int //for int typo error
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto&a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define pb  push_back
#define mb  make_pair
#define fi  first
#define se  second
//typedef
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<vector<ll>> matrix;
typedef pair<int, int> pii;
inline int rint(){int x; scanf("%d", &x); return x;}
//can modify here
const ll mod = 1000000007;
//don't ever modify here, a^b % mod function, extended euclid algo, gcd
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll eea(ll a, ll b, ll &x, ll &y){if(!b){x=1,y=0;return a;} ll x1,y1; ll d = eea(b,a%b,x1,y1);x=y1;y=x1-(ll)(a/b)*y1;return d;}
ll gcd(ll a, ll b){ll x; ll y; return eea(a,b,x,y);}


//code here
void solve()
{
    int n, k, t;
    cin >> n >> k;
    double arr[n];
    rep(i,0,n)
    {
        cin >> t;
        arr[i] = (t+1)/2.0;
        if(i != 0)
            arr[i] += arr[i-1];
    }
    double ans = arr[k-1];
    rep(i, k, n)
    {
        if(arr[i] - arr[i-k] - ans > (double)1e-9)
            ans = arr[i] - arr[i-k];
    }
    printf("%.12lf", ans);
}


int main() {
    //For faster IO, comment out for interative problems
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

	solve();
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
//g++ -std=c++11 

using namespace std;
long long N, u, v;

vector<long long> tree[100005];
long long memo_a[100005];

int main(){
	cin >> N >> u >> v;
	u--;v--;
	rep(i, N-1) {
		long long a, b;
		cin >> a >> b;
		a--;b--;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}


	// point, (pa, dis)
	queue<pair<long long, pair<long long,long long> > >Q;
	Q.push(make_pair(v, make_pair(-1, 0)));
	while(!Q.empty()) {
		long long cur = Q.front().first;
		long long pa = Q.front().second.first;
		long long dis = Q.front().second.second;
		memo_a[cur] = dis;
		Q.pop();
		//cout << cur << endl;
		for(auto next: tree[cur]) {
			if(next != pa) {
				Q.push(make_pair(next, make_pair(cur, dis + 1)));
			}
		}
	}

	long long ans = 0;
	Q.push(make_pair(u, make_pair(-1, 0)));
	while(!Q.empty()) {
		long long cur = Q.front().first;
		long long pa = Q.front().second.first;
		long long dis = Q.front().second.second;
		Q.pop();

		if(memo_a[cur] <= dis) {
			continue;
		}
		for(auto next: tree[cur]) {
			if(next != pa) {
				Q.push(make_pair(next, make_pair(cur, dis + 1)));
			}
		}

		//端っこに来た
		if(tree[cur].size() == 1) {
			ans = max(ans, memo_a[tree[cur][0]]);
		}

	}

	cout << ans << endl;
}



Measured memory_bytes: 11160
import sys
import math
import fractions

N, M = map(int, input().split())
a = list(map(lambda x: int(x) >> 1, input().split()))
set(a)

fdigit = 0
while True:
	c = 1 << fdigit
	if a[0] & c != 0:
		break
	fdigit += 1

alcm = 1
for i in range(N):
	digit = 0
	while True:
		c = 1 << digit
		if a[i] & c != 0:
			break
		digit += 1
	if digit != fdigit:
		print(0)
		sys.exit(0)

	alcm = (alcm * a[i]) // fractions.gcd(alcm, a[i])

print(math.ceil((M // alcm) / 2))

Measured memory_bytes: 16320
N=int(input())
A=list(map(int,input().split()))

ans=[0]*len(A)
without0=0
for i in range(1,len(A),2):
  without0+=A[i]
ans[0]=sum(A)-without0*2
for i in range(1,len(A)):
  ans[i]=A[i-1]*2-ans[i-1]
print(*ans)

Measured memory_bytes: 14028
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int A[101],B[101],C[101];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>A[i];
	int ret=0;
	FOR(i,N) {
		cin>>B[i];
		ret+=B[i];
	}
	FOR(i,N-1) cin>>C[i];
	FOR(i,N-1) if(A[i]+1==A[i+1]) ret+=C[A[i]-1];
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	scanner := makeWordScanner()
	a := eGetInt(scanner)
	b := eGetInt(scanner)
	fmt.Println(max(0, a-(2*b)))
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}


Measured memory_bytes: 640
from collections import deque

S = deque(input())
rev = False

Q = int(input())

for _ in range(Q):
    i_q = list(input().split())
    if i_q[0] == "1":
        rev = not rev
    else:
        appendtop = False
        if not rev and i_q[1] == "1":
            appendtop = True
        elif rev and i_q[1] == "2":
            appendtop = True

        if appendtop:
            S.appendleft(i_q[2])
        else:
            S.append(i_q[2])

if rev:
    while len(S) > 0:
        print(S.pop(), end="")
else:
    while len(S) > 0:
        print(S.popleft(), end="")

print()


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

#define fi first
#define se second
#define forn(i,n) for(int i=0; i< (int)n; ++i)
#define for1(i,n) for(int i=1; i<= (int)n; ++i)
#define fore(i,l,r) for(int i=(int)l; i<= (int)r; ++i)
#define ford(i,n) for(int i=(int)(n) - 1; i>= 0; --i)
#define fored(i,l,r) for(int i=(int)r; i>= (int)l; --i)
#define pb push_back
#define el '\n'
#define d(x) cout<< #x<< " " << x<<el
#define ri(n) scanf("%d",&n)

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<char,int> pci;
typedef tuple<int, int, int> tiii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

const ll INF = LONG_LONG_MAX;
const int MAXN = 21;
const int mod = 1e9+ 7;

int can[MAXN][MAXN];
ll dp[int(1<<MAXN)];
int allmask;

int n;

ll go(int mask){
    int idx = __builtin_popcount(mask);
    if(idx == n) return (mask == allmask);
    ll &r = dp[mask];
    if(r!=-1) return r;
    r= 0;
    for(int i=0; i<n; ++i){ // i es mujeres, idx es hombres
        if(!((1<<i)&mask) && can[idx][i]){
            r+= go(mask|(1<<i));
            r%=mod;
        }
    }
    return r;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin>>n;
    memset(dp, -1, sizeof dp);
    forn(i,n)
        forn(j,n)
            cin>>can[i][j];
    allmask = (1<<n)-1;
    cout<<go(0)<<el;

}


Measured memory_bytes: 16640
n=int(input())
A=list(map(int,input().split()))
ans=int(1000000000)
for i in range(1,1000):
    now=int(0)
    for j in range(n):
        now+=(i-A[j])*(i-A[j])
    if now<ans:
        ans=now
        
print(ans)

Measured memory_bytes: 3316
import java.io.*;
public class Main {
	public static void main(String[] args)throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		while(true){
		String str = br.readLine();
		String[] i=str.split(" ");
		int n=Integer.parseInt(i[0]),x=Integer.parseInt(i[1]),count=0;
		if(n==0&&x==0){break;}
		for (int a=1;a<=n;a++){
			for (int b=2;b<=n;b++){
				for(int c=3;c<=n;c++){
					if(a+b+c==x&&(a<b&&b<c)){count+=1;}
				}
			}
		}
		System.out.println(count);
		}
	}
}

Measured memory_bytes: 18772
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
	string str;
	char input[101];

	scanf("%s", input);
	str = input;

	for (int i = 0; i < str.size(); i++)
	{
		printf("x");
	}

	printf("\n");

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <map>
#include <queue>
#include <list>


#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
//#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define vint vector<int>
#define INF 1e9

using namespace std;
typedef long long  ll;

typedef pair<string, int> P;

vector<ll> divisor(ll n) {
    vector<ll> ret;
    for(ll i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            ret.push_back(i);
            if(i * i != n) ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    return (ret);
}

int main(){
    ll x;
    cin >> x;
    vector<ll> divi;
    divi = divisor(x);

    double limit = pow(x, 0.25);

//    ll a, b;
    REP(i, 0, divi.size()){
        for(ll a = 0; a <= ll(limit+1); a++){
            ll b = a - divi[i];
            if(pow(a, 5) - pow(b, 5) == x){
                p2(a, b);
                return 0;
            }
        }
    };

    return 0;
}


Measured memory_bytes: 4108
if __name__ == '__main__':
    import time
    START = time.time()
    LIMIT = START + 1.9

    from sys import stdin
    # from collections import defaultdict
    # from collections import deque
    # from collections import Counter
    from copy import deepcopy
    # import numpy as np
    from numpy import random as np_random
    # import math
    import random
    input = stdin.readline

    CONTEST_NUM = 26
    INFTY = 10**9

    D = int(input())
    cc = [0]+list(map(int, input().split()))
    ss = [[0]*(CONTEST_NUM+1) for _ in range(D)]
    for i in range(D):
        ss[i] = [0]+list(map(int, input().split()))
 
    last_day = [-1]*(CONTEST_NUM+1)
    content = 0

    def count_discontent(content, date):
        for contest in range(1, CONTEST_NUM+1):
            content -= cc[contest]*(date-last_day[contest])
        return content

    def greedy_decide_contest(date):
        point = -INFTY
        for contest in range(1, CONTEST_NUM+1):
            get_point = ss[date][contest]+cc[contest]*(date-last_day[contest])
            if get_point > point:
                point = get_point
                t = contest
        return t

    tt = [0]*D
    for date in range(D):
        # t = int(input())
        t = greedy_decide_contest(date)
        tt[date] = t
        content += ss[date][t]
        last_day[t] = date
        content = count_discontent(content, date)
        # print(t)

    best_content = content
    best_tt = deepcopy(tt)

    P = 0.1

    while time.time() <= LIMIT:
        content = 0
        tt = [0]*D
        last_day = [-1]*(CONTEST_NUM+1)
        for date in range(D):
            if np_random.binomial(1, P):
                t = random.randint(1, CONTEST_NUM)
            else:
                t = greedy_decide_contest(date)
            tt[date] = t
            content += ss[date][t]
            last_day[t] = date
            content = count_discontent(content, date)
        if content > best_content:
            best_content = content
            best_tt = deepcopy(tt)
    
    # print(best_content)
    # print(best_tt)

    for t in best_tt:
        print(int(t))




Measured memory_bytes: 27648
#include<iostream>

using namespace std;

int main(){
  int a=0, b=0;

  cin >> a >> b;

  if( a <= 5){
    b = 0;
  }
  if( a <= 12 && a>= 6){
    b=b/2;
  }

  cout << b << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int a,b;
	cin >> a >> b;
	if (a != 0 && b%a == 0)
		cout << a+b << endl;
	else
		cout << b-a << endl;

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"strconv"
	"strings"
)

const debug = false

func (p *problem) solve() {
	N := p.NextInt()
	line2 := p.NextInts()
	D, X := line2[0], line2[1]
	var eat int
	for i := 0; i < N; i++ {
		m := p.NextInt()
		for j := 0; j < 101; j++ {
			if (m*j + 1) > D {
				break
			}
			eat++
		}
	}
	p.PrintInt(eat + X)
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func main() {
	if debug {
		log.SetOutput(os.Stdout)
	} else {
		log.SetOutput(ioutil.Discard)
	}

	p := problem{
		in:  bufio.NewReader(os.Stdin),
		out: bufio.NewWriter(os.Stdout),
	}
	p.solve()

	if err := p.out.Flush(); err != nil {
		panic(err)
	}
}

type problem struct {
	in  *bufio.Reader
	out *bufio.Writer
}

func (p *problem) PrintInt(d int) {
	p.Printf("%d", d)
}

func (p *problem) Printf(format string, a ...interface{}) {
	if _, err := fmt.Fprintf(p.out, format, a...); err != nil {
		panic(err)
	}
}

func (p *problem) NextInt() int {
	return stoi(p.Next())
}

func (p *problem) NextInts() []int {
	line := p.NextSSLine()
	ds := make([]int, len(line))
	for i, s := range line {
		ds[i] = stoi(s)
	}
	return ds
}

func (p *problem) NextSSLine() []string {
	return strings.Split(p.Next(), " ")
}

// Next reads line and return string.
func (p *problem) Next() string {
	var b []byte
	for {
		l, pre, err := p.in.ReadLine()
		if err != nil {
			panic(err)
		}
		b = append(b, l...)
		if !pre {
			break
		}
	}
	return string(b)
}

func stoi(s string) int {
	i, err := strconv.Atoi(s)
	if err != nil {
		fmt.Println(i)
		fmt.Println(err)
	}
	return i
}


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

#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) \
  for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define rep(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) \
  for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define rep_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int;  // 多倍長整数（任意精度）
typedef pair<int, int> P;

// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll MOD = ll(1e9) + 7;
const ll INF = ll(1e10);
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";
const double PI = acos(-1);

// define methods
// 最大公約数
ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector<pair<ll, ll>> prime_factorize(ll n) {
  vector<pair<ll, ll>> p;
  for (ll i = 2; i * i <= n; i++) {
    if ((n % i) != 0) continue;
    pair<ll, ll> a = make_pair(i, 0);
    while ((n % i) == 0) {
      n /= i;
      a.second += 1;
    }
    p.push_back(a);
  }

  if (n != 1) p.push_back(make_pair(n, 1));
  return p;
}
// 組み合わせの整合性を保つ（後ほど解析する）
ll modinv(ll a) {
  ll b = MOD, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= MOD;
  if (u < 0) {
    u += MOD;
  }
  return u;
}
// 順列
ll permutation(const ll n, const ll m) {
  ll result = 1;
  for (ll i = n; i > n - m; i--) {
    result = (result * i) % MOD;
  }
  return result;
}

// 繰り返し n 乗法
ll repeat_square(const ll n, const ll x) {
  if (x == 0) return 1;
  ll res = repeat_square(n, x / 2);
  res = res * res % MOD;
  if ((x % 2) == 1) res = res * n % MOD;
  return res;
}
// 組み合わせ nCm
ll combination(ll n, ll m) {
  ll p = permutation(n, m);
  ll div = 1;
  for (ll i = 2; i <= m; i++) {
    div = (div * i) % MOD;
  }
  return (p * modinv(div)) % MOD;
}

// アルファベットの取得
string get_alphabet(ll n) {
  n--;
  return string(1, 'a' + (n % 26));
}

int main() {
  int N, Q;
  string S;
  cin >> N >> Q >> S;
  vector<int> L(Q+1), R(Q+1);
  rep(i, Q) {
    cin >> L[i] >> R[i];
  }

  vector<int> p(N, 0);
  int count = 0;
  string prev = S.substr(0, 1);
  rep(i, 1, N) {
    string s = S.substr(i, 1);
    if ((prev + s) == "AC") count++;
    p[i] = count;
    prev = s;
  }

  rep(i, Q) {
    int l = L[i], r = R[i];
    int ans = p[r-1] - p[l-1];
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 4536
use std::io;
use std::io::prelude::*;

fn main (){
    let stdin = io::stdin();

    for l in stdin.lock().lines() {
        let mut stack: Vec<f64> = vec![];
        for token in l.unwrap().split_whitespace() {
            match token.parse::<f64>() {
                Ok(x) => stack.push(x),
                _ => {
                    let y = stack.pop().unwrap();
                    let x = stack.pop().unwrap();
                    stack.push(match token {
                        "+" => x + y,
                        "-" => x - y,
                        "*" => x * y,
                        _ => x / y,
                    })
                }
            }
        }
        println!("{}", stack[0]);
    }
}



Measured memory_bytes: 5064
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  ll n;
  cin >> n;
  ll ans = 1e18;
  for (ll i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      ans = min(ans, i + (n / i) - 2);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3584
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#define int long long
using namespace std;

signed main() {
	int N;
	cin >> N;
	vector<int> vec(N);
	for(int i = 0;i < N;i++) {
		cin >> vec.at(i);
	}
	sort(vec.begin(),vec.end());
	cout << vec.at((N - 1) / 2 + 1) - vec.at((N - 1) / 2) << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
  
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    ll N, K; cin >> N >> K;
    vector<pair<ll,ll>> ab(N);
    for(int i=0; i<N; i++) cin >> ab[i].first >> ab[i].second;

    sort(ab.begin(), ab.end());
    ll cnt = 0;

    for(int i=0; i<N; i++){
        cnt += ab[i].second;
        if(cnt >= K){
            cout << ab[i].first << endl;
            break;
        }
    }
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;cin>>n;
  int a[n],l[n],x=200001,k=0;
  for(int i=0;i<n;++i)
  {
    cin>>a[i];
    l[i]=min(x,a[i]);
    x=min(x,a[i]);
  }
  for(int i=0;i<n;++i)
  {
    if(l[i]==a[i])
      k++;
  }
  cout<<k;
}
  

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define forn(b) for(int i = 0; i < b; i++)
#define rforn(b) for(int i = b - 1 ;i >= 0; i--)
#define It(m) for(auto it = m.begin(); it != m.end(); it++)
#define N 500500
#define PI 3.14159265358979323846264338327950L
#define speed ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
const ll mod = (ll)1e9 + 7;
    
int main(){
    speed;
    int a, b; cin >> a >> b;
    vector<int> v { a * b, a - b, a + b};
    sort(all(v));
    cout << v[2];   
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <malloc.h>
#include <vector>
#include<queue>
#include <algorithm>

using namespace std;


int main(){
  double a,b;
  cin >>a >> b;
  //int A_i = 12*a;
  double A = a*12.5;
  double B = b*10;

  double A_ = A;
  
  if(A-double(int(A)) >0.1){
     A_ += 12.5;
  }
  else{ A_+=12;
  }
  
  double B_ = B+10;
  //double _A = (a-1)/0.08;
  //double _B = (b-1)/0.1;
  if ( B_<=A|| A_<=B) {
    cout << -1 << endl;
    return 0;
  }
  if(A>=B){
    if(A-double(int(A)) >0.1) cout << int(A+1)<< endl;
    else cout << int(A)<< endl;
    
  }
  else cout << int(B) << endl;
  return 0;
}

Measured memory_bytes: 256
def ints():
  return [int(x) for x in input().split()]
def readi():
  return int(input())

N = readi()
A = ints()

w = 1000000007

s = 0
for k in range(60):
  n = [0, 0]
  for i in range(N):
    n[A[i]%2] += 1
    A[i] >>= 1

  s += (n[0]*n[1] << k) % w

print(s%w)


Measured memory_bytes: 122808
class Dice
  def dice_s(n)
    n[0],n[1],n[4],n[5] = n[4],n[0],n[5],n[1]
    return n
  end

  def dice_e(n)
    n[0],n[2],n[3],n[5] = n[3],n[0],n[5],n[2]
    return n
  end

  def dice_w(n)
    n[0],n[2],n[3],n[5] = n[2],n[5],n[0],n[3]
    return n
  end

  def dice_n(n)
    n[0],n[1],n[4],n[5] = n[1],n[5],n[0],n[4]
    return n
  end

  def dice_b(n)
    n[0],n[1],n[4],n[5] = n[5],n[4],n[1],n[0]
    return n
  end

  def dice_sp(n)
    n[1],n[2],n[4],n[3] = n[2],n[4],n[3],n[1]
    return n
  end
end

n = gets.chomp.split.map(&:to_i)
q = gets.to_i
dice = Dice.new()

q.times {
  t, f = gets.split.map(&:to_i)

  if t == n[4]
    dice.dice_s(n)
  elsif t == n[3]
    dice.dice_e(n)
  elsif t == n[2]
    dice.dice_w(n)
  elsif t == n[1]
    dice.dice_n(n)
  elsif t == n[5]
    dice.dice_b(n)
  end

  while n[1] != f
    dice.dice_sp(n)
  end

  puts n[2]
}

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

bool check(int p[], int n){
  bool ret = true;
  rep(i,n-1){
    if(p[i+1]-p[i]!=1){
      ret = false;
    }
  }
  return ret;
}

int main(){
  int n;
  cin >> n;
  int p[n];
  rep(i,n) cin >> p[i];
  bool flag=false;
  
  if(check(p,n)){
  	cout << "YES" << endl;
    return 0;
  }
  
  rep(i,n){
    rep(j,i){
      swap(p[i], p[j]);
      if(check(p,n)){
        flag = true;
        break;
      }
      swap(p[i], p[j]);
    }
  }
  
  if(flag) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


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

const int nax = 1e5 + 7;
vector<int> adj[nax];
int indegree[nax];
int dist[nax];

void bfs(int n)
{
    queue<int> q;
    for (int i = 1; i <= n; i++)
        if (indegree[i] == 0)
            q.push(i);

    while (!q.empty())
    {
        int k = q.front();
        q.pop();
        for (auto x : adj[k])
        {
            dist[x] = max(dist[x], dist[k] + 1);
            if (--indegree[x] == 0)
                q.push(x);
        }
    }
}
#undef int
int main()
{
#define int long long
    int n, m;
    cin >> n >> m;
    int u, v, ans = 0;
    memset(indegree, 0, sizeof(indegree));
    for (int i = 0; i < m; i++)
    {
        cin >> u >> v;
        adj[u].push_back(v);
        indegree[v]++;
    }
    bfs(n);
    for (int i = 1; i <= n; i++)
        ans = max(ans, dist[i]);

    cout << ans << endl;
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-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;
}
int main(){
    ll n,a;cin >> n >>a;
    vl v(n);
    rep(i,n)cin >> v[i];
    ll dp[n+1][2501];
    rep(i,n+1)rep(k,2501)dp[i][k]=0;
    dp[0][0]=1;
    rep(i,n){
        per(j,n+1){
            if(j>i)continue;
            per(k,2501){
                if(k+v[i]<=2500)dp[j+1][k+v[i]]+=dp[j][k];
            }
        }
    }
    ll ans=0;
    rep(i,n+1){
        if(i==0)continue;
        rep(k,2501){
            if(i*a==k){
                ans+=dp[i][k];
            }
        }
    }
    cout <<ans <<endl;
}

Measured memory_bytes: 1280
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("Ofast")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2LL) //等差数列の和、初項,末項,項数
#define pb push_back
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int n;
	scanf("%d", &n);
	vector<int> a(n);
	rep(i, n)scanf("%d", &a[i]);
	sort(all(a), greater<int>());
	ll ans = a[0];
	n -= 2;
	for(int i = 1; n > 0; ++i) {
		ans += a[i] * min(n, 2);
		n -= 2;
	}
	printf("%lld\n", ans);

	Please AC;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  string S[H + 1];
  vector<vector<int> > vert(H + 1, vector<int>(W + 1));
  vector<vector<int> > hori(H + 1, vector<int>(W + 1));

  for (int i = 0; i < H; i++) cin >> S[i];

  for (int i = 0; i < H; i++) {
    int cnt = 0, start = 0;
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '.') cnt++;
      if (S[i][j] == '#') {
        for (int k = start; k < j; k++) hori[i][k] = cnt;
        cnt = 0;
        start = j;
      }
      if (j == W - 1)
        for (int k = start; k < j + 1; k++) hori[i][k] = cnt;
    }
  }

  for (int j = 0; j < W; j++) {
    int cnt = 0, start = 0;
    for (int i = 0; i < H; i++) {
      if (S[i][j] == '.') cnt++;
      if (S[i][j] == '#') {
        for (int k = start; k < i; k++) vert[k][j] = cnt;
        cnt = 0;
        start = i;
      }
      if (i == H - 1)
        for (int k = start; k < i + 1; k++) vert[k][j] = cnt;
    }
  }

  vector<vector<int> > ans(H, vector<int>(W));
  int answer = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] != '#') {
        ans[i][j] = vert[i][j] + hori[i][j];
        answer = max(answer, ans[i][j]);
      }
    }
  }

  cout << answer - 1 << endl;
  return 0;
}


Measured memory_bytes: 51456
#include <bits/stdc++.h>
using namespace std;
struct lazy_segment_tree{
  int N;
  vector<int> ST_zero;
  vector<int> ST_one;
  vector<long long> ST_inv;
  vector<bool> lazy;
  lazy_segment_tree(vector<int> &A){
    int n = A.size();
    N = 1;
    while (N < n){
      N *= 2;
    }
    ST_zero = vector<int>(N * 2 - 1, 0);
    ST_one = vector<int>(N * 2 - 1, 1);
    ST_inv = vector<long long>(N * 2 - 1, 0);
    lazy = vector<bool>(N * 2 - 1, false);
    for (int i = 0; i < n; i++){
      if (A[i] == 0){
        ST_zero[N - 1 + i] = 1;
        ST_one[N - 1 + i] = 0;
      }
    }
    for (int i = N - 2; i >= 0; i--){
      ST_zero[i] = ST_zero[i * 2 + 1] + ST_zero[i * 2 + 2];
      ST_one[i] = ST_one[i * 2 + 1] + ST_one[i * 2 + 2];
      ST_inv[i] = ST_inv[i * 2 + 1] + ST_inv[i * 2 + 2] + (long long) ST_one[i * 2 + 1] * ST_zero[i * 2 + 2];
    }
  }
  void eval(int i){
    if (lazy[i]){
      if (i < N - 1){
        lazy[i * 2 + 1] = !lazy[i * 2 + 1];
        lazy[i * 2 + 2] = !lazy[i * 2 + 2];
      }
      lazy[i] = false;
      swap(ST_zero[i], ST_one[i]);
      ST_inv[i] = (long long) ST_zero[i] * ST_one[i] - ST_inv[i];
    }
  }
  void flip(int L, int R, int i, int l, int r){
    eval(i);
    if (r <= L || R <= l){
      return;
    } else if (L <= l && r <= R){
      lazy[i] = true;
      eval(i);
    } else {
      int m = (l + r) / 2;
      flip(L, R, i * 2 + 1, l, m);
      flip(L, R, i * 2 + 2, m, r);
      ST_zero[i] = ST_zero[i * 2 + 1] + ST_zero[i * 2 + 2];
      ST_one[i] = ST_one[i * 2 + 1] + ST_one[i * 2 + 2];
      ST_inv[i] = ST_inv[i * 2 + 1] + ST_inv[i * 2 + 2] + (long long) ST_one[i * 2 + 1] * ST_zero[i * 2 + 2];
    }
  }
  void flip(int L, int R){
    flip(L, R, 0, 0, N);
  }
  tuple<int, int, long long> inversion(int L, int R, int i, int l, int r){
    eval(i);
    if (r <= L || R <= l){
      return make_tuple(0, 0, 0);
    } else if (L <= l && r <= R){
      return make_tuple(ST_zero[i], ST_one[i], ST_inv[i]);
    } else {
      int m = (l + r) / 2;
      tuple<int, int, long long> A = inversion(L, R, i * 2 + 1, l, m);
      tuple<int, int, long long> B = inversion(L, R, i * 2 + 2, m, r);
      return make_tuple(get<0>(A) + get<0>(B), get<1>(A) + get<1>(B), get<2>(A) + get<2>(B) + (long long) get<1>(A) * get<0>(B));
    }
  }
  long long inversion(int L, int R){
    return get<2>(inversion(L, R, 0, 0, N));
  }
};
int main(){
  int N, Q;
  cin >> N >> Q;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  lazy_segment_tree ST(A);
  for (int i = 0; i < Q; i++){
    int T;
    cin >> T;
    if (T == 1){
      int L, R;
      cin >> L >> R;
      L--;
      ST.flip(L, R);
    }
    if (T == 2){
      int L, R;
      cin >> L >> R;
      L--;
      cout << ST.inversion(L, R) << endl;
    }
  }
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

// Mod int
const int mod = 1000000007;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
typedef vector<mint> vm;
typedef vector<vm> vvm;
//

int main(){
  int n,m;
  cin >> n >> m;
  vvm board(n+1,vm(m+1,0));
  VI s(n), t(m);
  rep(i,n) cin >> s[i];
  rep(i,m) cin >> t[i];

  rep(i,n) rep(j,m){
    if(s[i] == t[j]) board[i+1][j+1] = 1;
  }

  //dpと累積和を同時に作成
  FOR(i,1,n+1) FOR(j,1,m+1){
    // dpの遷移が起こる場合
    if(board[i][j] == 1){
      board[i][j] += board[i-1][j-1];
    }
    // 通常の累積和の値を取得
    board[i][j] += board[i][j-1] + board[i-1][j] - board[i-1][j-1];
  }
  // // 空文字の部分列分を追加
  board[n][m] += 1;
  cout << board[n][m] << endl;
  return 0;
}


Measured memory_bytes: 31616
S = str(input())
T = str(input())

N = 10000
for i in range(len(S) - len(T)+ 1):
  s =S[i:(i+len(T))]
  n =0
  for k in range(len(T)):
    if s[k] !=  T[k]:
      n+= 1
  N  = min(N, n)
  
print(N)

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

int get_pivot(vector<int>& A, int from, int to) {
    for (int i=from+1; i<to; i++) {
        if (A[i] != A[from]) {
            return max(A[i], A[from]);
        }
    }
    return -1;
}

void quick_sort(vector<int>& A, int from, int to) {
    int pivot = get_pivot(A, from, to);
    if (pivot == -1) return;

    int i = from, j = to-1;
    while (true) {
        while (i != j && A[i] < pivot) i++;
        while (i != j && A[j] >= pivot) j--;
        if (i == j) {
            quick_sort(A, from, i);
            quick_sort(A, i, to);
            break;
        } else {
            swap(A[i], A[j]);
        }
    }
}

void quick_sort(vector<int>& A) {
    quick_sort(A, 0, A.size());
}

int main()
{
    int N;
    cin >> N;
    vector<int> X(N);
    vector<int> Y(N);
    REP(i, N) {
        cin >> X[i];
        Y[i] = X[i];
    }

    quick_sort(Y);
    REP(i, N) {
        if (X[i] < Y[N/2]) {
            cout << Y[N/2] << endl;
        } else {
            cout << Y[N/2-1] << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3712
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
priority_queue<int> s;
ll sa[610001],sb[610001],ans;
int i,j,k,n,a[610001];
int main(){
	scanf("%d",&n);
	for (i=1;i<=3*n;i++) scanf("%d",&a[i]);
	while (!s.empty()) s.pop();
	for (i=1,sa[0]=0;i<=n;i++) sa[0]+=a[i],s.push(-a[i]);
	for (i=1;i<=n;i++){
		s.push(-a[n+i]);
		sa[i]=sa[i-1]+a[n+i]+s.top();
		s.pop();
	}
	while (!s.empty()) s.pop();
	for (i=3*n,sb[0]=0;i>2*n;i--) sb[0]+=a[i],s.push(a[i]);
	for (i=1;i<=n;i++){
		s.push(a[2*n-i+1]);
		sb[i]=sb[i-1]+a[2*n-i+1]-s.top();
		s.pop();
	}
	for (ans=-(1LL<<60),i=0;i<=n;i++) ans=max(ans,sa[i]-sb[n-i]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 6140
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
#include <queue>
#include <iomanip>
#include <float.h>
#include <set>
#include<functional>
#include <stack>
#include <time.h>
#include <climits>
#include <bitset>
#include <fstream>
using namespace std;
typedef pair<int, int>p;
vector<long long> divisor(long long n) {
	vector< long long> ret;
	for (long long  i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(begin(ret), end(ret));
	return (ret);
}
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	long long n;
	cin >> n;
	long long ans = 0;
	vector<long long>vec = divisor(n);
	for (int i = 0; i < vec.size(); i++) {
		long long m = n / vec[i] - 1;
		if (m!=0&&n / m == n%m)ans += m;
	}
	cout << ans;

}

Measured memory_bytes: 384
// 最大公約数
// a,bの最小公倍数(LCM)はa*b/GCD
/*
 * C言語のサンプルプログラム - Webkaru
 * - 入力した2つの自然数の最大公約数を求める -
 */
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000 //10^9:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(){
    int N;
    cin>>N;
    int a;
    int c=1;
    rep(i,N){ 
        cin>>a;
        if(a==c){
            c++;
        }
    }
    int ans;
    if(c==1) ans=-1;
    else ans=N - (c-1); 
    cout<<ans<<endl;
    return 0;
}

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

int N;
string S;

int main() {
  cin >> N >> S;

  if (N % 2) {
    cout << "No" << endl;
    return 0;
  }

  rep(i, N / 2) {
    if (S[i] != S[i + N / 2]) {
      cout << "No" << endl;
      return 0;
    }
  }

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


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

int main()
{
	char a,b,c,d,e,f;
	scanf("%c%c%c%c%c%c", &a, &b, &c, &d, &e, &f);
	
	if(c==d && e==f)
	{
		printf("Yes");
	}
	else
	{
		printf("No");
	}
	return 0;
}

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

int main(void){
	int sx,sy,tx,ty;
	cin >> sx >> sy >> tx >> ty;
	//まずはsx syを (0,0)に移動する
	tx -= sx;
	ty -= sy;
	//4つの象限に分ける
	//(tx,ty)まで最短距離を出力する
	if( tx > 0 && ty > 0){
		for(int i=0;i<ty;i++)cout << "U";
		for(int i=0;i<tx;i++)cout << "R";
		for(int i=0;i<ty;i++)cout << "D";
		for(int i=0;i<tx;i++)cout << "L";
		cout <<"L";
		for(int i=0;i<ty+1;i++)cout << "U";
		for(int i=0;i<tx+1;i++)cout << "R";
		cout <<"D";
		cout <<"R";
		for(int i=0;i<ty+1;i++)cout << "D";
		for(int i=0;i<tx+1;i++)cout << "L";
		cout <<"U";
	}else if( tx>0 && ty<0){
		for(int i=0;i<abs(ty);i++)cout << "D";
		for(int i=0;i<tx;i++)cout << "R";
		for(int i=0;i<abs(ty);i++)cout << "U";
		for(int i=0;i<tx;i++)cout << "L";
		cout <<"L";
		for(int i=0;i<abs(ty)+1;i++)cout << "D";
		for(int i=0;i<tx+1;i++)cout << "R";
		cout <<"U";
		cout <<"R";
		for(int i=0;i<abs(ty)+1;i++)cout << "U";
		for(int i=0;i<tx+1;i++)cout << "L";
		cout <<"D";
	}else if(tx<0 && ty<0){
		for(int i=0;i<abs(ty);i++)cout << "D";
		for(int i=0;i<abs(tx);i++)cout << "L";
		for(int i=0;i<abs(ty);i++)cout << "U";
		for(int i=0;i<abs(tx);i++)cout << "R";
		cout <<"R";
		for(int i=0;i<abs(ty)+1;i++)cout << "D";
		for(int i=0;i<abs(tx)+1;i++)cout << "L";
		cout <<"U";
		cout <<"L";
		for(int i=0;i<abs(ty)+1;i++)cout << "U";
		for(int i=0;i<abs(tx)+1;i++)cout << "R";
		cout <<"D";
	}else{
		for(int i=0;i<abs(ty);i++)cout << "U";
		for(int i=0;i<abs(tx);i++)cout << "L";
		for(int i=0;i<abs(ty);i++)cout << "D";
		for(int i=0;i<abs(tx);i++)cout << "R";
		cout <<"R";
		for(int i=0;i<abs(ty)+1;i++)cout << "U";
		for(int i=0;i<abs(tx)+1;i++)cout << "L";
		cout <<"D";
		cout <<"L";
		for(int i=0;i<abs(ty)+1;i++)cout << "D";
		for(int i=0;i<abs(tx)+1;i++)cout << "R";
		cout <<"U";
	}
	return 0;
}

Measured memory_bytes: 256
import collections
import heapq
import math
import random
import sys
input = sys.stdin.readline
sys.setrecursionlimit(500005)
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
rs = lambda: input().rstrip()

Nmax = 10**6 + 1

n = ri()
A = rl()

f = [0] * Nmax
for v in A:
    f[v] += 1
for i in range(2, Nmax//2+1):
    for j in range(i*2, Nmax, i):
        f[i] += f[j]

def gcd(a, b):
    while b > 0:
        a, b = b, a % b
    return a

if max(f[2:]) <= 1:
    print("pairwise coprime")
else:
    x = 0
    for v in A:
        x = gcd(x, v)
    if x == 1:
        print("setwise coprime")
    else:
        print("not coprime")


Measured memory_bytes: 225368
#include <iostream>

using namespace std;

using ll = long long;

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

    ll A[N + 1];
    for (int i = 1; i <= N; ++i) {
        cin >> A[i];
    }

    ll sum[N + 1], xorsum[N + 1];
    sum[0] = xorsum[0] = 0;
    // 累積和と累積xor どちらも1-indexed

    for (int i = 1; i <= N; ++i) {
        sum[i] = sum[i - 1] + A[i];
        xorsum[i] = (xorsum[i - 1] ^ A[i]);
    }

    ll ans = 0;
    for (int l = 1; l <= N; ++l) {
        int ok = l, ng = N + 1;
        // (l, ok)は条件を満たし、(l, ng)は条件を満たさない
        // このokとngの距離を縮めていくことで境界値r0を求める

        while (ng - ok > 1) {
            int mid = (ok + ng) / 2;
            if (sum[mid] - sum[l - 1] == (xorsum[mid] ^ xorsum[l - 1])) {
                ok = mid;
            } else {
                ng = mid;
            }
        }

        // 最終的なokが境界値r0となる
        ans += ok - l + 1;
    }

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


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define ll long long
#define W(x) cerr << "\033[31m"<<  #x << " = " << x << "\033[0m" << endl;

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef set<int> si;
typedef vector<vi> vii;
typedef vector<ii> vpi;
typedef vector<ll> vll;
int oo = (1e9) + 7;
ll oo2 = 1ll*oo*oo;

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

    if(n % 2 == 0) {
        n/2 >= k ? puts("YES") : puts("NO");
    } else {
        n/2 + 1 >= k ? puts("YES") : puts("NO");
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    cout << (1000 - n % 1000) % 1000 << endl;
}


Measured memory_bytes: 3648