akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, m;
  cin>>n>>m;
  vector<int> x[m];
  for (int i=0; i<n; i++) {
    int a, b;
    cin>>a>>b;
    if (a > m) {
      continue;
    }
    --a;
    x[a].push_back(b);
  }
  priority_queue<int> pq;
  long long ans = 0;
  for (int i=0; i<m; i++) {
    for (int j=0; j<x[i].size(); j++) {
      pq.push(x[i][j]);
    }
    if (pq.size() == 0) {
      continue;
    }
    long long t = pq.top();
    pq.pop();
    ans += t;
  }
  cout<<ans<<endl;
}

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

int main()
{
    int N, temp;
    int A[200005];
    cin >> N;
    REP(i, N)
        cin >> A[i];
    sort(A, A + N);
    temp = 0;
    REP(i, N){
        if(lower_bound(A, A+N, A[i]) != (upper_bound(A, A+N, A[i])-1)){
            cout << "NO" << endl;
            break;
        }else
            temp++;
    }
    if(temp == N)
        cout << "YES" << endl;
    return 0;
}



Measured memory_bytes: 1024
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    List<Long> list = new ArrayList<>();
    String[] S = sc.nextLine().split(" ");
    for(int i = 0; i < N; i++){
      long n = Long.parseLong(S[i]);
      list.add(n);
    }
    
    Collections.sort(list, Collections.reverseOrder());
    
    long len1 = 0;
    long len2 = 0;
    long tem = list.get(0);
    for(int i = 1; i < N; i++){
      if(len1 > 0 && len2 > 0){
        break;
      }
      
      if(tem == list.get(i)){
        if(len1 == 0){
          len1 = tem;
          i++;
          tem = list.get(i);
        }else{
          len2 = tem;
        }
      }else{
        tem = list.get(i);
      }
    }
    
    long ans = len1 * len2;
    System.out.println(ans);
  }
}

Measured memory_bytes: 46672
#include<bits/stdc++.h>
using namespace std;
long long n;
map<long long,long long>q;
map<long long,long long>::iterator it;
long long  modl(long long a, long long b, long long c)       
{
    long long res, t;
    res = 1 % c;
    t = a % c;
    while (b)
    {
        if (b & 1)
        {
            res = res * t % c;
        }
        t = t * t % c;
        b >>= 1;
    }
    return res;
}
long long mod=1e9+7;
int main()
{
    q.clear();
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        long long num;
        cin>>num;
        q[num]++;
    }
    if(q[0]>1)
    {
        cout<<"0"<<endl;
    }
    else if(q[0]==1||q[0]==0)
    {
        int num=0;
        for(it=q.begin();it!=q.end();it++)
        {
            if(it->second==2)
            {
                num++;
            }
            else if(it->second>2)
            {
                cout<<"0"<<endl;
                return 0;
            }
        }
        num%=mod;
        cout<<modl(2,num,mod)%mod<<endl;
    }
    return 0;
}

Measured memory_bytes: 4224
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
int main() {
	char c1, c2, c3, c4, c5, c6;
	cin >> c1 >> c2 >> c3 >> c4 >> c5 >> c6;
	if (c1 == c6 && c2 == c5 && c3 == c4)
		cout << "YES" << "\n";
	else
		cout << "NO" << "\n";
}

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

int main() {
  int k;
  cin>>k;
  vector<int> s(32);
  
  s = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  
  cout << s[k-1] << endl;
}

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

int main(){
  long long n, m, d;
  cin >> n >> m >> d;
  cout << fixed << setprecision(10);
  if (n<=d) {cout << 0 << endl; return 0;}
  if (d == 0) cout << (m-1)/(double)n << endl;
  else cout << (m-1)*2*(n-d)/(double)(n*n) << endl;;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
//#define endl "\n";
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
const long long int m=pow(10,9)+7;

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    vector<ll> vec(n);
    for (int i = 0; i < n; i++)
        cin >> vec[i];
    ll s = 0, ans = 0;
    for (int i = 0; i < n; i++) 
    {
        ans += s * vec[i];
        ans %= m;
        s += vec[i];
        s %= m;
    }
 
    cout << ans;
    return 0;
}


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

int main() {
	char S[100002];
	scanf("%s", S);
	long long len = strlen(S);
	for (long long i = len - 1; i > 0;)
	{
		if (i >= 4 && !strcmp(S + i - 4, "dream")) 
		{
			i -= 5; 
			S[i + 1] = 0;
		}
		else if (i >= 6 && !strcmp(S + i - 6, "dreamer")) 
		{ 
			i -= 7; 
			S[i + 1] = 0;
		}
		else if (i >= 4 && !strcmp(S + i - 4, "erase")) 
		{ 
			i -= 5; 
			S[i + 1] = 0;
		}
		else if (i >= 5 && !strcmp(S + i - 5, "eraser")) 
		{
			i -= 6; 
			S[i + 1] = 0;
		}
		//printf("%d\n", i);
		else {
			puts("NO");
			return 0;
		}
	}
	puts("YES");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mod 1000000007

int main() {

    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    ll t = 1;
    //cin>>t;

    while(t--) {
       ll n,m;
       cin>>n>>m;

       ll s=0,a;

       for(int i=0;i<m;i++) {
        cin>>a;
        s+=a;
       }

       if(s>n) {
        cout<<"-1\n";
       }
       else cout<<n-s<<"\n";
    }

}



Measured memory_bytes: 3656
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE TypeApplications #-}
import Data.Int (Int64)
import qualified Data.ByteString.Char8 as BS

main = do
  n <- readLn @Int
  s <- BS.getLine
  let n_r, n_g, n_b :: Int64
      n_r = fromIntegral (BS.count 'R' s)
      n_g = fromIntegral (BS.count 'G' s)
      n_b = fromIntegral (BS.count 'B' s)
  print $
    n_r * n_g * n_b
    - sum [ 1 :: Int64
          | d <- [1..n `div` 2]
          , i <- [0..n - 1 - 2 * d]
          , let j = i + d
                k = j + d -- k <= n - 1
          , s `BS.index` i /= s `BS.index` j
          , s `BS.index` i /= s `BS.index` k
          , s `BS.index` j /= s `BS.index` k
          ]


Measured memory_bytes: 3928
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>
#include <time.h>
#include <random>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 3e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pd(x) cerr<<"//"<<(x)<<endl;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl


ll mod = 1000000007;
ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}

ll n,m,num,sum,ans,a,b,c,d,e,g,h,w,i,j,k,l,q;
ll x[500005],y[500005],z[500005];
bool dp[205][205];
char s[500005];
bool flag,dame;

ll  fact[400005];
ll rfact[400005];

void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<400000; i++){
        fact[i] = (fact[i-1]*i) % mod;
        rfact[i] = rui(fact[i],mod - 2);
    }
}
ll ncr(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod) * rfact[n-r]) % mod;
}

int main(){
	cin >> n;
	a = INF;
	for(i=0;i<5;i++){
		cin >> b;
		a = min(a,b);
	}
	p((n+a-1)/a + 4);
	return 0;
}

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

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll c[100100];

ll rwpw(ll a, ll p){
	ll ret = 1ll;
	while(p){
		if(p%2){
			mul_mod(ret,a);
		}
		mul_mod(a,a);
		p /= 2;
	}
	return ret;
}

int main(void){
	ll n,k,i,j,ans=0ll;
	std::cin >> n >> k;
	for(i=1ll; i<=k; ++i){
		add_mod(c[i],i);
		add_mod(ans,c[i]*rwpw(k/i,n)%MOD);
		for(j=i*2; j<=k; j+=i){
			add_mod(c[j],MOD-c[i]);
		}
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 4372
N = int(input())
A = list(map(int, input().split()))
allL = sum(A)
L, mL = 0, float('inf')
for i in range(N):
    L += A[i]
    if abs(2*L-allL) < mL:
        mL = abs(2*L-allL)
    else:
        break
print(mL)

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

using namespace std;

const int N = 100000 + 77 , L = 30;
int a , b , c;
int main(){
   ios::sync_with_stdio(0);cin.tie(0);
   cin >> a >> b >> c;
   cout << (a - b + 1) * (a - c + 1);
   return 0;
}



Measured memory_bytes: 892
#include <iostream>
#include <iomanip>

void Output(int n, int grade[][3]) {
	for (int i = 0; i < n; ++i) {
		if (grade[i][0] == -1 || grade[i][1] == -1) {
			std::cout << "F" << std::endl;
		}
		else if (grade[i][0] + grade[i][1] >= 80) {
			std::cout << "A" << std::endl;
		}
		else if (grade[i][0] + grade[i][1] >= 65) {
			std::cout << "B" << std::endl;
		}
		else if (grade[i][0] + grade[i][1] >= 50) {
			std::cout << "C" << std::endl;
		}
		else if (grade[i][0] + grade[i][1] >= 30) {
			if (grade[i][2] >= 50) {
				std::cout << "C" << std::endl;
			}
			else {
				std::cout << "D" << std::endl;
			}
		}
		else {
			std::cout << "F" << std::endl;
		}
	}
}

int main()
{
	int grade[50][3];
	for (int i = 0; true; ++i) {
		std::cin >> grade[i][0] >> grade[i][1] >> grade[i][2];
		if (grade[i][0] == -1 && grade[i][1] == -1 && grade[i][2] == -1) {
			Output(i, grade);
			break;
		}
	}
	return 0;
}




Measured memory_bytes: 3104
// AtCoder Regular Contest 080 C - 4-adjacent
// 2018.1.11 bal4u

#include <stdio.h>

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int main()
{
	int N, a;
	int i, n4, odd, ans;			// n4: 4の倍数

	odd = n4 = 0;
	N = in();
	for (i = 0; i < N; i++) {
		a = in();
		if (a & 1) odd++;
		else if (!(a & 3)) n4++;
	}
	ans = 0;
	if (n4 >= odd) ans = 1;
	else if (n4 == odd-1 && odd + n4 == N) ans = 1;
	puts(ans? "Yes": "No");
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int N;
  cin >> N;
  int L[2*N];
  for(int i=0;i<2*N;i++) cin >> L[i];

  sort(L, L+2*N);

  ll ans = 0LL;
  for(int i=0;i<2*N;i+=2){
    ans += L[i];
  }

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

Measured memory_bytes: 256
package main

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

var MOD = 998244353
var (
	N, S int
	A    [10000]int
	dp   []int
)

func main() {
	readVariables()
	dp = make([]int, S+1)
	dp[0] = 1
	answer := 0
	for i := 0; i < N; i++ {
		if i > 0 {
			dp[0]++
			dp[0] %= MOD
		}
		for j := S; j >= 0; j-- {
			if j+A[i] <= S {
				dp[j+A[i]] += dp[j]
				dp[j+A[i]] %= MOD
			}
		}
		// fmt.Println(dp)
		answer += dp[S]
		answer %= MOD
	}
	fmt.Println(answer)
}

func readVariables() {
	N, S = nextInt(), nextInt()
	for i := 0; i < N; i++ {
		A[i] = nextInt()
	}
}

/* Template */

var scanner *bufio.Scanner

func init() {
	Max := 1001001
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 0, Max), Max)
	scanner.Split(bufio.ScanWords)
}

//nextInt converts next token from stdin and returns integer value.
//nextInt panics when conversion into an integer fails.
func nextInt() int {
	if !scanner.Scan() {
		panic("No more token.")
	}
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic("nextInt(): cannot convert to int: " + scanner.Text())
	}
	return num
}

func nextStr() string {
	if !scanner.Scan() {
		panic("No more token.")
	}
	return scanner.Text()
}

// MinInt returns minimum argument
func MinInt(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

//MaxInt returns maximum argument
func MaxInt(x, y int) int {
	if x < y {
		return y
	} else {
		return x
	}
}

//AbsInt returns |x| for x
func AbsInt(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//ModPow calculates integer power with modulo operation
//if modulo <= 1, it powers w/o module operation
//if base < 0, return value might be negative too.
func ModPow(base, exponent, modulo int) (result int) {
	result = 1
	for exponent > 0 {
		if exponent%2 == 1 {
			result *= base
			if modulo > 1 {
				result %= modulo
			}
		}
		base *= base
		if modulo > 1 {
			base %= modulo
		}
		exponent /= 2
	}
	return
}

//Gcd
func Gcd(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = gcd(result, vals[i])
	}
	return
}

func gcd(x, y int) int {
	x, y = AbsInt(x), AbsInt(y)
	for y > 0 {
		x, y = y, x%y
	}
	return x
}

//Lcm
func Lcm(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = lcm(result, vals[i])
	}
	return
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}


Measured memory_bytes: 768
import * as fs from "fs";

const [_, line2] = fs.readFileSync("/dev/stdin", "utf8").split("\n");
const X = line2.split(" ").map(Number);


function totalStamina(P: number): number {
	return X.reduce((S, x) => {
		return S+(x-P)*(x-P);
	}, 0);
}

let minimumStamina: number = Infinity;

for (let P=0; P<101; P++) {
	minimumStamina = Math.min(minimumStamina, totalStamina(P));
}

console.log(minimumStamina);


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

int main() {
	int a, b;
	cin >> a >> b;
	if (a > b) {
		cout << "a > b\n";
	}
	else if(a < b) {
		cout << "a < b\n";
	}
	else {
		cout << "a == b\n";
	}
	return 0;
}


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

#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 hash dhsjakhd
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;

ll n,m,T,k,q;
const ll big = 1000000007;

string s;
vl A;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    ll a,b,c,d,e;
    cin >> n;
    cin >> s;
    cin >> q;
    for(ll c1 = 0; c1 < q; c1++){
        cin >> a;
        A.push_back(a);
    }
    for(ll c1 = 0; c1 < q; c1++){
        a = A[c1];
        m = 0;
        d = 0;
        ll tot = 0;
        ll ans = 0;
        ll l = 0;
        for(ll r = 0; r < n; r++){
            if(s[r] == 'M'){
                m++;
                ans += d;
            }
            if(s[r] == 'D'){
                d++;
            }
            if(r-l >= a){
                if(s[l] == 'M')m--;
                if(s[l] == 'D'){
                    d--;
                    ans -= m;
                }
                l++;
            }
            if(s[r] == 'C'){
                tot += ans;
            }
        }
        cout << tot << "\n";
    }
    return 0;
}


Measured memory_bytes: 1948
#include<stdio.h>
#include<algorithm>
using namespace std;
typedef unsigned long long wolf;
char str[1000000];
char tmp[16];
wolf key=1000000007;
wolf v[1000000];
wolf hash[1000000];
wolf pow[1000000];
int main(){
	int a,b;
	scanf("%d%d%s",&a,&b,str);
	wolf now=0;
	wolf val=1;
	for(int i=0;i<500000;i++){
		now+=str[i]*val;
		hash[i+1]=now;
		pow[i]=val;
		val*=key;
	}
	int L=0;
	int R=1;
	//for(int i=1;i<=a;i++)printf("%llu\n",hash[i]);
	for(int i=0;i<b;i++){
		scanf("%s",tmp);
		if(tmp[0]=='L'&&tmp[1]=='+')L++;
		if(tmp[0]=='L'&&tmp[1]=='-')L--;
		if(tmp[0]=='R'&&tmp[1]=='+')R++;
		if(tmp[0]=='R'&&tmp[1]=='-')R--;
		
		v[i]=(hash[R]-hash[L])*pow[a-L];
	//	printf("%d %d %llu %llu\n",L,R,hash[R]-hash[L],v[i]);
	}
	std::sort(v,v+b);
	int ret=1;
	for(int i=1;i<b;i++)if(v[i]!=v[i-1])ret++;
	printf("%d\n",ret);
}

Measured memory_bytes: 15668
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#include<cstdio>

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

using namespace std;
using ll =long long;
using P = pair<int,int>;

#define MAX_N 8

int perm[MAX_N];
vector<P> pos;


void permutation(int n){
    for(int i=0; i<n; i++){
        perm[i]=i;
    }
    
    double ans=0;
    double count=0;
    do{
        /* ここにpermの処理を書く */
        for(int i=0; i+1<n; i++){
            int x1 = pos[perm[i]].first;
            int y1 = pos[perm[i]].second;
            int x2 = pos[perm[i+1]].first;
            int y2 = pos[perm[i+1]].second;
            
            ans += (double)sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
        }
        count++;
        
    }while(next_permutation(perm, perm+n));
    
    cout << setprecision(15) << ans/count << endl;
}

int main(int argc, const char * argv[]) {
    int N;
    cin >> N;
    
    rep(i, N){
        P p;
        cin >> p.first >> p.second;
        pos.push_back(p);
    }
    
    permutation(N);
    
    return 0;
}


Measured memory_bytes: 256
N,A,B = map(int, input().split())
X = list(map(int, input().split()))

total_cost = 0
for i in range(N - 1):
  walk_cost = A * (X[i+1] - X[i])
  if walk_cost < B:
    total_cost += walk_cost
  else:
    total_cost += B

print(total_cost)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

auto z_algorithm(const string &s) {
	int n = s.size(), i = 1, j = 0, k;
	vector<int> z(n, n);
	while (i < n) {
		while (i + j < n && s[i + j] == s[j]) j++;
		z[i] = j, k = !!j;
		while (i + k < n && k + z[k] < j) z[i + k] = z[k], k++;
		i += k + !j, j -= k;
	}
	return z;
}

const int limit = 3000010;
int memo[limit];


int main(void){
	string s, t;
	cin >> s >> t;

	const int n = s.size();
	const int m = t.size();	

	string g = t + "#";

	while(g.size() <= m + 1 + 2 * max(n, m)) g += s;
	auto z = z_algorithm(g);
	const int all = g.size();
	const int p = __gcd(n, m);

	rep(i, p){
		const int start = m + 1 + i;
		int cur = start;
		while(cur < all and z[cur] == m) cur += p;
		if(cur - start >= n){
			puts("-1");
			return 0;
		}		
	}

	int ans = 0;
	rrep(i, all, m + 1){
		if(z[i] == m and i + m < all) {
			memo[i] = memo[i + m] + 1;
		} else {
			memo[i] = 0;
		}
		chmax(ans, memo[i]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 17352
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        String ans = "NO";
        int[] res = new int[]{A,B,C};
        Arrays.sort(res);
        if(res[0]==5&&res[1]==5&&res[2]==7) ans = "YES";
        System.out.println(ans);
    }
}


Measured memory_bytes: 21712
#include <iostream>

using namespace std;

int main()
{
    string s;
    cin>>s;
    if(s[0]=='S')
        cout<<"Cloudy"<<endl;
    else if(s[0]=='C')
        cout<<"Rainy"<<endl;
    else
        cout<<"Sunny"<<endl;
    return 0;
}

Measured memory_bytes: 256
a=int(input())
list=map(int,input().split())
list2=[]
list3=[]
for x in list:
    if x%2==0:
        list2.append(x)
for y in list2:
    if y%3!=0 and y%5!=0:
        list3.append(y)
s=len(list3)
if s==0:
    print("APPROVED")
else:
    print("DENIED")

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


int f(ll a,ll b)
{
	return (int)max(log10(a),log10(b));
}

int main()
{
	ll N;
	cin>>N;
	int ans=10;
	for(int i=1;i<sqrt(N)+1;i++)
	{
		if(N%i!=0) continue;
		ll k=N/i;
		int v=f(i,k);
		ans=min(ans,v);
	}
	cout<<ans+1<<endl;
	return 0;
}


Measured memory_bytes: 3876
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S = read().rstrip().decode('utf-8')

weekday = 'SUN,MON,TUE,WED,THU,FRI,SAT'.split(',')
dic = {x:7 - i%7 for i,x in enumerate(weekday)}

answer = dic[S]
print(answer)


Measured memory_bytes: 2940
def unique(li):
    """Returns a list of unique elements in ordered list li

    >>> unique([1, 1])
    [1]
    >>> unique([1, 2])
    [1, 2]
    """
    return [li[i] for i in range(len(li)) if i == 0 or li[i] > li[i-1]]


def run():
    n = int(input())
    li = [int(x) for x in input().split()]
    assert(n == len(li))

    print(" ".join([str(x) for x in unique(li)]))


if __name__ == '__main__':
    run()



Measured memory_bytes: 18436
#include<bits/stdc++.h>
#define lln long long int
#define llu unsigned lln
#define sc(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define scd(n) scanf("%lf",&n);
#define pf(res) printf("%d\n",res);
#define pfl(res) printf("%lld\n",res);
#define pfd(res) printf("%lf\n",res);
#define maxii 100005
using namespace std;
typedef pair<int,int> pii;
typedef pair<lln,lln> pll;
typedef vector<int> vi;
typedef vector<lln> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

int arr[105];
int arr2[105];

int main()
{
    int x,n;
    sc(x)
    sc(n)
    if(n==0)
    {
        cout<<x;
        return 0;
    }
    for(int i=0;i<n;i++)
    {
        sc(arr[i])
        arr2[arr[i]]++;
    }

   sort(arr,arr+n);
   int res1,r,l,res2;
   if(arr2[x]==0)
   {
       cout<<x;
       return 0;
   }
   for(int i=x+1;i<=101;i++)
   {
       if(arr2[i]==0)
       {
           r=i;
           res1=i-x;
           break;
       }
   }
   for(int i=x-1;i>=0;i--)
   {
       if(arr2[i]==0)
       {
           l=i;
           res2=x-i;
           break;
       }
   }
   //cout<<res1<<" "<< res2<<endl;;
   if(res1>=res2)
   {
       cout<<min(l,r);
   }
   else if(res1<res2)
   {
       cout<<r;
   }
   //else cout<<l;
}







Measured memory_bytes: 3656
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
using namespace std;

int main()
{
    int N, X, Y;
    cin >> N >> X >> Y;
    --X, --Y;
    map<int, int> dic;
    for (int toid = 1; toid < N; ++toid)
    {
        for(int fromid = 0; fromid < toid; ++fromid)
        {
            int d1 = toid - fromid;
            int d2 = abs(Y - toid) + 1 + abs(X - fromid);
            int distance = std::min(d1, d2);
            ++dic[distance];
            //if (d1 == d2) ++dic[distance];
        }

    }
    for (int i = 1; i <= N - 1; ++i)
    {
        cout << dic[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

constexpr int kMaxNodeNum = 8;
bool has_path[kMaxNodeNum + 1][kMaxNodeNum + 1];
bool node_is_passed[kMaxNodeNum + 1];
int passed_node_count;
int N;

int MarkAndCountPaths(int next);

int CountPaths(int next) {
  if(passed_node_count == N)
    return 1;
  int count = 0;
  for(int i = 1; i <= N; i++) {
    if(!has_path[next][i]) continue;
    if(node_is_passed[i]) continue;
    count += MarkAndCountPaths(i);
  }
  return count;
}

int MarkAndCountPaths(int next) {
  node_is_passed[next] = true;
  passed_node_count++;
  int count = CountPaths(next);
  passed_node_count--;
  node_is_passed[next] = false;
  return count;
}

int main(int argc, char *argv[]) {
  int M;
  cin >> N >> M;
  for(int i = 0; i < M; i++){
    int from, to;
    cin >> from >> to;
    has_path[from][to] = true;
    has_path[to][from] = true;
  }
  cout << MarkAndCountPaths(1) << endl;

  return 0;
}


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

typedef long long int ll ;

ll gcd(ll aaa,ll bbb) {
    if(bbb==0) {
        return aaa;
    }
    return gcd(bbb,aaa%bbb);
}

ll lcm(ll m,ll n)
{
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;

    return ((m / gcd(m, n)) * n);
}

int main() { 

	long N;
	cin >> N;
	long a[N];
	long Ma=0,color=0;
	map<long,long>m;
	for(int i = 0; i < N; i++) {
		cin >> a[i];
		if(a[i] >= 1 && a[i] <= 399) {
			m[0]++;
		}else if(a[i] >= 400 && a[i] <= 799) {
			m[1]++;
		}else if(a[i] >= 800 && a[i] <= 1199) {
			m[2]++;
		}else if(a[i] >= 1200 && a[i] <= 1599) {
			m[3]++;
		}else if(a[i] >= 1600 && a[i] <= 1999) {
			m[4]++;
		}else if(a[i] >= 2000 && a[i] <= 2399) {
			m[5]++;
		}else if(a[i] >= 2400 && a[i] <= 2799) {
			m[6]++;
		}else if(a[i] >= 2800 && a[i] <= 3199) {
			m[7]++;
		}else {
			m[8]++;
		}
	}

	for(int i = 0; i < 8; i++) {
		if(m[i] != 0) {
			color++;
		}
	}

	if(color == 0) {
		cout << 1 << ' ' << m[8]<< endl;
	}else {
		cout << color << ' ' << color + m[8]<< endl;
	}

	return 0;
}


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

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

const int MAXN = 1e5;

int n, arr[MAXN+10], ans;
int lgcd[MAXN+10], rgcd[MAXN+10];

int main()
{
    int i, j;

    scanf("%d", &n);
    for(i=1; i<=n; i++) scanf("%d", &arr[i]);

    lgcd[1]=arr[1], rgcd[n]=arr[n];
    for(i=2; i<=n; i++) lgcd[i]=__gcd(lgcd[i-1], arr[i]);
    for(i=n-1; i>=1; i--) rgcd[i]=__gcd(rgcd[i+1], arr[i]);

    for(i=2; i<=n-1; i++) ans=max(ans, __gcd(lgcd[i-1], rgcd[i+1]));
    ans=max(ans, max(rgcd[2], lgcd[n-1]));
    printf("%d", ans);
}


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


int main() {
  int N;
  int d[110];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> d[i];
  }
  int num[110] = {0};
  for (int i = 0; i < N; i++) {
    num[d[i]]++;
  }
  int ans = 0;
  for (int i = 1; i <= 100; i++) {
    if (num[i]) ans++;
  }
  cout << ans << endl;
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
using namespace std;
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 26;
const int mod = 1e9+7;
int dp[1<<upperlimit];
int main() {
	string s;
	cin >> s;
	int mask=0;
	for(int i = 0; i < s.size(); i++){
		mask^=1<<(s[i]-'a');
		for(int j = 0; j < 26; j++){
			int mask2=mask^(1<<j);
			if((dp[mask2]==0)&&(mask2!=0)) continue;
			if((dp[mask]==0)&&(mask!=0)) dp[mask]=dp[mask2]+1;
			else dp[mask]=min(dp[mask],dp[mask2]+1);
		}
	}
	int ans=dp[mask];
	ans=max(ans,1);
	pd(ans);
	return 0;
}

Measured memory_bytes: 262404
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,s,len;
inline bool check(ll x,ll tmp){
	if(tmp==1)return true;
	ll cnt=0;
	while(x)cnt+=x%tmp,x/=tmp;
	return cnt==s;
}
int main(){
	cin>>n>>s,len=(ll)sqrt(n)+1;
	for(ll i=2;i<=len;++i)if(check(n,i)){cout<<i;return 0;}
	if(n<=s){cout<<(n<s?-1:n+1);return 0;}
	ll tmp=n-s,ttmp=tmp/len+1;
	for(int i=ttmp;i;--i)if(tmp%i==0&&s>=i&&s-i<=tmp/i&&i<=tmp/i){cout<<tmp/i+1;return 0;}
	cout<<-1;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main(){
  int D,N;
  cin>>D>>N;
  if(N==100){
    if(D==0){cout<<N+1<<"\n";
    return 0;
  }
  else if(D==1){cout<<(int)pow(100,D)*N+100<<"\n";
    return 0;
  }
  else{cout<<(int)pow(100,D)*N+10000<<"\n";
    return 0;
  }
}
  if(D==0)cout<<N<<"\n";
  else cout<<(int)pow(100,D)*N<<"\n";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib> 
using namespace std;


int X;
char s[1050];

string b[9] = {".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};


int main(){

  cin >> X;
  while(X){

    cin >> s;

    int i = 0;
    char pre;
    int n;

    for(i = 0; i < strlen(s); i++){
      n = 1;
     
      pre = s[i];
      if(pre == '0') continue;
      while(pre == s[i+1] && i < strlen(s)){
	n++;
	i++;
      }
      int x = atoi(&pre);
   
      cout <<  b[x-1][(n-1) % b[x-1].length()];
    }
    cout << endl;
    X--;
  }
  return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define _ << ' ' <<
using namespace std;
using ll = long long;

ll dst[305][305];
int sol[305][305];

int main()
{
    int n, m, l;
    cin >> n >> m >> l;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            if (i != j)
                dst[i][j] = 1e15;

    for (int i = 0; i < m; ++i)
    {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        dst[a][b] = dst[b][a] = c;
    }
    for (int k = 0; k < n; ++k)
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < n; ++j)
                dst[i][j] = min(dst[i][j], dst[i][k] + dst[k][j]);

    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
                sol[i][j] = dst[i][j] <= l ? 1 : 1e5;

    for (int k = 0; k < n; ++k)
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < n; ++j)
                sol[i][j] = min(sol[i][j], sol[i][k] + sol[k][j]);
    int q;
    cin >> q;
    while (q--)
    {
        int s, t;
        cin >> s >> t;
        s--; t--;
        cout << (sol[s][t] >= 1e5 ? -1 : sol[s][t] - 1) << '\n';
    }
}


Measured memory_bytes: 1664
#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <ctime>
#include <cstring>
#include <cassert>
#include <bitset>
#include <sstream>
#include <queue>

#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define sz(a) ((int) (a).size())
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

typedef long long int64;
typedef long double ldb;

const long double eps = 1e-9;
const int inf = (1 << 30) - 1;
const long long inf64 = ((long long)1 << 62) - 1;
const long double pi = acos(-1);

template <class T> T sqr (T x) {return x * x;}
template <class T> T abs (T x) {return x < 0 ? -x : x;}

int main () {
    ios_base::sync_with_stdio(0);
//	freopen("input.txt", "rt", stdin);
//	freopen("output.txt", "wt", stdout);

	string s;
	cin >> s;

	if (sz(s) >= 4 && s.substr(0, 4) == "YAKI") {
		cout << "Yes" << endl;
		return 0;
	}

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


Measured memory_bytes: 256
import heapq
from collections import defaultdict, deque
# from math import ceil, factorial, gcd
from itertools import accumulate, permutations
import sys
import bisect


sys.setrecursionlimit(10 ** 7)
INF = float("inf")
MOD = 10 ** 9 + 7

si = lambda: input().strip()
ii = lambda: int(input())
mii = lambda: map(int, input().split())
msi = lambda: map(str, input().split())
lmii = lambda: list(map(int, input().split()))
lmsi = lambda: list(map(str, input().split()))
smii = lambda: sorted(map(int, input().split()))
# ----------

H, W, K = mii()
S = []
for i in range(H):
    S.append(si())

ans = INF
for div in range(1<<(H-1)):
    id = [0] * H
    g = 0
    for i in range(H):
        id[i] = g
        if div >> i & 1:
            g += 1

    c = [[0] * W for _ in range(g+1)]

    for i in range(H):
        for j in range(W):
            if S[i][j] == '1':
                c[id[i]][j] += 1

    now = defaultdict(int)

    def add(j):
        for i in range(g+1):
            now[i] += c[i][j]
        for i in range(g+1):
            if now[i] > K:
                return False
        return True

    num = g
    for j in range(W):
        if not add(j):
            num += 1
            now = defaultdict(int)
            if not add(j):
                num = INF
                break

    ans = min(ans, num)

print(ans)



Measured memory_bytes: 50908
#include<bits/stdc++.h>
using namespace std;
int main(){
  long n,max(1),cnt(0);
  
  cin >> n;
  
  vector<int> a(n),b(n);
  
  for(int i = 0;i<n;i++){
    cin >> a.at(i);
    b.at(i) = 0;
  }
  
  for(int i = 0;i<n;i++){
    if(a.at(i) == max){
      b.at(i) = a.at(i);
      max++;
    }else cnt++;
  }
  if(max == 1)cnt = -1;
  cout << cnt << endl;
  
}

Measured memory_bytes: 1792
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

x = 10**12
res = 0

for i in range(N):
    y = abs(A - (T - H[i] * 0.006))
    if y < x:
        x = y
        res = i+1

print(res)

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

int main() {
  int N;
  cin >> N;
  
  int sum = 0;
  
  for(int i = 0; i < N; i++){
    int l, r;
    cin >> l >> r;
    
    sum += r - l + 1;
  }
  cout << sum << endl;
}

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

int main(){
  int x, a, b;
  cin >> x >> a >> b;
  
  int s = a-x;
  int t = b-x;
  if(s<0)s *= -1;
  if(t<0)t *= -1;
  if(s>t)cout << "B" << endl;
  else cout << "A" << endl;
}

Measured memory_bytes: 256
<?php
$S = trim(fgets(STDIN));
$K = trim(fgets(STDIN));

const NUM = 5000000000000000;

$point = 0;
for($i=0; $i<strlen($S); $i++) {
    if($S[$i] == 1) {
        $point++;
    } else {
        $point = pow($S[$i], NUM) + $point;
    }

    if($K <= $point){
        echo $S[$i];
        exit;
    }
}

Measured memory_bytes: 4728
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm> // swap
#include <map>
#include <utility> // pair

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

using namespace std;

int main() 
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x, a, b;
	cin >> x;
	cin >> a;
	cin >> b;

	int numB = (x - a) / b;
	cout << (x - a - b * numB);

	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  double n, k, s, a, b, c;
  in2(n, k);
  a = 0.00000000000;
  rep2(i, 1, n + 1){
    s = 1.00000000000 / n;
    b = 1;
    c = i;
    while(c < k){
      c = c * 2;
      s = s / 2.00000000000;
    }
    a = a + s;
  }
  kono(10);
  out(a);
  memi;
}


Measured memory_bytes: 256
def solve
  while true
    total = 0

    n, m = gets.split.map(&:to_i)
    break if n <= 0

    pn = gets.split.map(&:to_i).sort {|a, b| b <=> a }

    while pn.count > 0
      t = []
      m.times do
        t.push pn.shift
        break if pn.count <= 0
      end
      t.pop if t.count == m
      t.each { |price| total += price }
    end
    p total
  end
end

solve

Measured memory_bytes: 9544
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
template<class Type> void join(const Type &a){for(auto elem:a)cout<<elem<<' ';cout<<endl;}

int main(){
	string s;
	cin>>s;
	
	REP(i,s.size()){
		if(i%2){
			if(s[i]=='R'){
				cout<<"No"<<endl;
				//cout<<i;//
				return 0;
			}
		}else{
			if(s[i]=='L'){
				cout<<"No"<<endl;
				//cout<<i;//
				return 0;
			}
		}
	}
	
	cout<<"Yes"<<endl;
}

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

typedef long long ll;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int a,b,q;
    cin >> a >> b >> q;
    vector<ll> s(a),t(b),ans(q);
    for (int i = 0;i < a;++i) cin >> s[i];
    for (int i = 0;i < b;++i) cin >> t[i];
    for (int i = 0;i < q;++i) {
        ll x,n = INT64_MAX,m = INT64_MAX;
        cin >> x;
        int c = lower_bound(s.begin(),s.end(),x)-s.begin();
        if (c != a) {
            int d = lower_bound(t.begin(),t.end(),s[c])-t.begin();
            if (d != 0) {
                d--;
                if (t[d] > x) n = s[c]-x;
                else n = -t[d]+s[c]+min(x-t[d],s[c]-x);
                d++;
            }
            if (d != b) n = min(n,t[d]-x);
        }
        if (c != 0) {
            c--;
            int d = lower_bound(t.begin(),t.end(),s[c])-t.begin();
            if (d != b) {
                if (t[d] < x) m = x-s[c];
                else m = t[d]-s[c]+min(t[d]-x,x-s[c]);
            }
            if (d != 0) {
                d--;
                m = min(m,x-t[d]); 
            }
        }
        ans[i] = min(n,m);
    }
    for (int i = 0;i < q;++i) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 3712
import sys
N = int(input())
a = list(map(int, input().split()))
m = max(a)
cnt0 = a.count(m)
cnt1 = a.count(m-1)
if cnt0+cnt1 != N:
    print('No')
    sys.exit()
if cnt1+1<=m<=cnt1+cnt0//2:
    print('Yes')
elif cnt1 == 0 and m+1 == cnt0:
    print('Yes')
else:
    print('No')

    



Measured memory_bytes: 52652
// =========
use std::cmp::{max, min};
use std::collections::HashSet;
use std::process::exit;
const MOD: usize = 1000000007;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    // var... 変数の識別子, $t...型を一つよむ
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        //ここで繰り返し
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    //
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    // 配列の最後のNestではここで型が指定されてparseされる
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
// =========

fn gcd(a: usize, b: usize) -> usize {
    if b == 0 {
        return a;
    } else if a < b {
        return gcd(a, b % a);
    } else {
        return gcd(b, a % b);
    }
}

fn main() {
    input! {
        n: usize,
        a: [isize;n],
        b: [isize;n],
    }
    let mut aa = 0;
    let mut bb = 0;
    for i in 0..n {
        aa += max(0, a[i] - b[i]);
        bb += max(0, (b[i] - a[i]) / 2)
    }
    if bb >= aa {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

struct PriorityQueue(alias _fun, T) {
    import std.functional : binaryFun;
    import std.algorithm : swap;
    alias fun = binaryFun!_fun;

    ///
    this(T[] ts) {
        foreach (t; ts) enqueue(t);
    }

    ///
    PriorityQueue!(_fun, T) enqueue(T e) {
        if (this.tree.length == 0) this.tree.length = 1;
        if (this.tree.length == this.n) this.tree.length *= 2;
        this.tree[this.n] = e;
        auto i = this.n;
        this.n += 1;
        while (i) {
            auto j = (i-1)/2;
            if (fun(this.tree[i], this.tree[j])) {
                swap(this.tree[i], this.tree[j]);
                i = j;
            } else break;
        }
        return this;
    }

    alias insertFront = enqueue;
    alias insert = enqueue;

    ///
    T dequeue() {
        auto ret = this.tree[0];
        this.n -= 1;
        this.tree[0] = this.tree[this.n];
        this.tree = this.tree[0..$-1];
        size_t i;
        for (;;) {
            auto l = i*2+1;
            auto r = i*2+2;
            if (l >= this.n) break;
            size_t j;
            if (r >= this.n) {
                j = l;
            } else {
                j = fun(this.tree[r], this.tree[l]) ? r : l;
            }
            if (fun(this.tree[j], this.tree[i])) {
                swap(this.tree[i], this.tree[j]);
                i = j;
            } else break;
        }
        return ret;
    }

    ///
    @property
    T front() {
        return this.tree[0];
    }

    ///
    @property
    bool empty() {
        return this.n == 0;
    }

    ///
    void popFront() {
        this.dequeue();
    }

    alias removeFront = popFront;

    ///
    @property
    size_t length() {
        return this.n;
    }

private:
    size_t n;
    T[] tree;
}

///
PriorityQueue!(fun, T) priority_queue(alias fun, T)(T[] ts = []) {
    return PriorityQueue!(fun, T)(ts);
}

alias AL = Tuple!(int, "a", long, "b");

AL[10^^5] AS;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];
    foreach (i; 0..N) {
        auto ab = readln.split.to!(int[]);
        AS[i] = AL(ab[0], ab[1]);
    }
    sort!"a.a < b.a"(AS[0..N]);
    auto pq = priority_queue!("a.b > b.b", AL)();
    
    auto as = AS[0..N];
    long r;
    foreach (i; 1..M+1) {
        while (!as.empty && as[0].a <= i) {
            pq.enqueue(as[0]);
            as = as[1..$];
        }
        if (!pq.empty) {
            r += pq.front.b;
            pq.dequeue();
        }
    }
    writeln(r);
}

Measured memory_bytes: 6908
#include <bits/stdc++.h>
#define watch(x) std::cout << (#x) << " is " << (x) << std::endl
#define print(x) std::cout << (x) << std::endl
using LL = long long;

int main() {
	//freopen("in","r",stdin);
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::string a;
	int r = 0;
	std::cin >> a;
	for (auto &c : a) r += (c - '0');
	std::cout << (r % 9 == 0 ? "Yes" : "No") << std::endl;
	return 0;
}

Measured memory_bytes: 3776
N = int(input())
A = [int(a) for a in input().split()]

S = [0]*N
S[0] = A[0]
for i in range(1, N):
    S[i] = A[i]+S[i-1]
    
ans = 2*10**14
l = 0
temp = 2*10**14
r = 2
#for i in range(2, N):
#    if abs(S[-1]-2*S[i]+S[1]) < temp:
#        temp = abs(S[-1]-2*S[r]+S[1])
#        r = i
        
for i in range(2, N-1):
    r = max(r, i)
    while l+1 < i-1 and abs(S[i-1]-2*S[l]) > abs(S[i-1]-2*S[l+1]):
        l += 1
    while r+1 < N-1 and abs(S[N-1]-2*S[r]+S[i-1])  > abs(S[N-1]-2*S[r+1]+S[i-1]):
        r += 1
    t = max(S[N-1]-S[r], S[r]-S[i-1], S[i-1]-S[l], S[l]) - min(S[N-1]-S[r], S[r]-S[i-1], S[i-1]-S[l], S[l])
    ans = min(ans, t)
    
print(ans)

Measured memory_bytes: 25676
// Hail god Yato
 
#include <bits/stdc++.h> 
using namespace std;
 
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const ll mod = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//
struct node{
    int cnt[26] = {0};
    node* next[26] = {nullptr};
    // node(){
    //     for(int i = 0; i < 26; i++){
    //         cnt[i] = 0;
    //         next[i] = NULL;
    //     }
    // }
}*root;
        
        void insert(string str){
            int count[26] = {0};
            for(int i = 0; i < str.length(); i++)
                count[str[i]-'a']++;

            node* cur = root;
            for(int i = 0; i < str.length(); i++){
                for(int j = 0; j < 26; j++){
                    cur->cnt[j] += bool(count[j]);
                }

                int c = str[i]-'a';
                count[c]--;
                // cur->cnt[c]--;
                if(cur->next[c] == nullptr)
                    cur->next[c] = new node();
                cur = cur->next[c];
            }
        }
        int go(string str){
            node* cur = root;
            for(int i=  0; i < str.length()-1; i++){
                cur = cur->next[str[i]-'a'];
            }
            return cur->cnt[str.back() - 'a']-1;
        }

        void solve(){
            root = new node();
            ll n;
            cin>>n;
            vector<string> vec(n);
            for(int i = 0; i < n; i++){
                cin>>vec[i];
                reverse(vec[i].begin(), vec[i].end());
                insert(vec[i]);
            }
            int ans = 0;
            for(int i = 0;i < n; i++)
                ans += go(vec[i]);

            cout<<ans;
            // insert("abcxyx");
        }
        int main(){ 
                hs;
                ll t;
                t=1;
                // cin>>t;
                for (int i=1; i<=t; i++){
                        //cout<<"Case #"<<i<<": ";
                        solve();
                 }
return 0; 
}         



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

int main(){
	long a,b,m,n,gcd;
	cin>>a;
	cin>>b;
	
	m=a;
	n=b;

	while(true){
		if(m%n==0){
			gcd = n;
			break;
		}else{			
			long temp = n;
			n = m%n;
			m = temp;
		}
	}
	
	long lcm;
	lcm = a*b/gcd;
	cout << lcm;

}

Measured memory_bytes: 256