akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
  
    ll a,b,c;
    cin>>a>>b>>c;
    ll k;
    cin>>k;
    if(k%2==0){
        cout<<a-b<<endl;
    }else{
        cout<<b-a<<endl;
    }
    
  
return 0;
}


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

int main(){
	int n,k;	cin>>n>>k;
	int ans1=0, ans2=0;
	for(int i=1;i<=n;i++){
		if(i%k==0)ans1++;
		else if(k%2==0 && i%k == k/2)ans2++;
	}
//	cout<<ans1<<endl;
//	cout<<ans2<<endl;

	long long ans=pow(ans1,3)+pow(ans2,3);
	cout<<ans<<endl;

	return 0;
}


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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll H, W, K; cin >> H >> W >> K;
  vector<vector<ll>> S(H, vector<ll>(W));
  for (ll i = 0; i < H; i++) {
    string s; cin >> s;
    for (ll j = 0; j < W; j++) {
      S.at(i).at(j) = s.at(j) - '0';
    }
  }
  ll ans = LLONG_MAX;
  for (ll x = 0; x < (1 << (H-1)); x++) {
    bool xFault = false;
    ll numBreak = 0;
    vector<ll> cnt(H);
    for (ll c = 0; c < W; c++) {
      ll rg = 0;
      vector<ll> thisCnt(H);
      for (ll r = 0; r < H; r++) {
	if (r > 0 && ((1 << (r-1)) & x)) rg++;
	if (S.at(r).at(c)) thisCnt.at(rg)++;
      }
      bool within = true;
      for (ll yy = 0; yy < H; yy++) {
	if (thisCnt.at(yy) > K) {
	  xFault = true;
	  break;
	}
	if (cnt.at(yy) + thisCnt.at(yy) > K) {
	  within = false;
	  break;
	}
      }
      if (xFault) break;
      if (within) {
	for (ll yy = 0; yy < H; yy++) cnt.at(yy) += thisCnt.at(yy);
      }else {
	numBreak++;
	for (ll yy = 0; yy < H; yy++) cnt.at(yy) = thisCnt.at(yy);
      }
    }
    if (xFault) continue;
    ll k = __builtin_popcountll(x);
    ans = min(ans, numBreak + k);
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(long long)>
using namespace std;
#define All(v) (v).begin(),(v).end()
const long long mod = 1000000007;
const long long inf = mod*mod;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
long long modpow(long long x, long long n, long long mod) {
    if (n == 0)return 1;
    long long res = modpow(x * x % mod, n / 2, mod);
    if (n & 1)res = res * x % mod;
    return res;
}
signed main(){
    long long n;
    cin>>n;
    vector<long long> A(n);
    for(long long i=0;i<n;i++)cin>>A[i];
    sort(All(A));
    if(n%2==0){
        for(long long i=0;i<n;i++){
            if(A[i]!=i/2*2+1){
                cout<<0<<endl;
                return 0;
            }
        }
    }
    else{
        for(long long i=0;i<n;i++){
            if(A[i]!=(i+1)/2*2){
                cout<<0<<endl;
                return 0;
            }
        }
    }
    cout<<modpow(2,n/2,mod)<<endl;
}


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

// 2*X - C  ->  X
long long dp[3000][3000][2]; // resulting value of X

// dp[L][R][p] = (L....R) inclusive, pth player turn
// p = 0 -> first, p = 1 -> second

// base cases
// dp[i][i][0] = a[i]
// dp[i][i][1] = 0

// Transitions
// pick L or pick R
// dp[L][R][0] = max(a[L] + dp[L+1][R][1],
// 					a[R] + dp[L][R-1][1])
// dp[L][R][1] = min(dp[L+1][R][0],
// 					dp[L][R-1][0])

// Order of Evaluation
// increasing of (R-L)

// ans = 2*(dp[0][n-1][0]) - sum

int main(){
	long long n, sum = 0;
	cin>>n;
	vector<long long> a(n);
	for(long long& x:a){
		cin>>x;
		sum += x;
	}
	
	for(long long i = 0; i < n; i++){
		dp[i][i][0] = a[i];
		dp[i][i][1] = 0;
	}
	
	for(long long RminusL = 1; RminusL < n; RminusL++){
		for(long long L = 0; L + RminusL < n; L++){
			long long R = L + RminusL;
			dp[L][R][0] = max(a[L] + dp[L+1][R][1],
							a[R] + dp[L][R-1][1]);
			
			dp[L][R][1] = min(dp[L+1][R][0],
							dp[L][R-1][0]);
		}
	}
	
	long long X = dp[0][n-1][0]; // (0...n-1) first player move
	long long ans = 2*X - sum;
	cout<<ans;
}

Measured memory_bytes: 85284
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    print(int(input())*2*3.1415926535)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61788
S = input()
T = input()
lst = []
num = len(S)
for i in range(num):
    R = S[0:i]
    Q = S[i:num]
    U = Q + R
    lst.append(U)
ans = lst.count(T)
if ans == 0:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3060
n,m,x = list(map(int, input().split()))
c = []
alg = []
for i in range(n):
    tmp = list(map(int, input().split()))
    c.append(tmp[0])
    tmp.pop(0)
    alg.append(tmp)

price_min = -1

for i in range(2**n):
    price = 0
    skill = [0]*m
    skillFlag = True
    buyBin = format(i, '0'+str(n)+'b')
    for j in range(n):
        if buyBin[j] == '1':
            price += c[j]
            for k in range(m):
                skill[k] += alg[j][k]

    for k in range(m):
        if skill[k] < x:
            skillFlag = False
    
    if skillFlag:
        if price_min > price or price_min == -1:
            price_min = price

print(price_min)

Measured memory_bytes: 9248
// 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;
//
//
                void solve(){
                    vector<int> vec(5);
                    for(int i = 0; i < 5; i++)
                        cin>>vec[i];
                    for(int i = 0; i < 5; i++)
                        if(vec[i] == 0){
                            cout<<i+1;
                            return ;
                        }
                }
                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: 3584
n=int(input())
xl_=[list(map(int,input().split())) for _ in range(n)]
xl=[[x[0]-x[1],x[0]+x[1]] for x in xl_]
xl.sort(key=lambda x:x[0])
r=xl[0][1]
ans=1
for i in range(1,n):#i-1番目のロボットまでは腕が重ならないことが保証されている。
    if r<=xl[i][0]:
        ans+=1
        r=xl[i][1]
    else:
        r=min(r,xl[i][1])
print(ans)

Measured memory_bytes: 75608
N = int(input())

dic = {'AC':0, 'WA':0, 'TLE':0, 'RE':0}
for i in range(N):
    s = input()
    dic[s] += 1

print("AC x ", dic['AC'])
print("WA x ", dic['WA'])
print("TLE x ", dic['TLE'])
print("RE x ", dic['RE'])

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

int main(){
	int n,m;
	int t[2];
	int a[2];
	int b[2];
	string ans;
	cin >> n;
	cin >> t[0] >> a[0] >> b[0] ;
	m=1;
	if(n==1){
		if(t[0]%2==(a[0]+b[0])%2){
				ans="Yes";
			}
			else{
				ans="No";
			}
			if(t[0]<a[0]+b[0]){
				ans="No";
			}
	}
	else{
		for(int i=1;i<n && m==1;i++){
			cin >> t[1] >> a[1] >> b[1] ;
			if(t[0]%2==(a[0]+b[0])%2){
				ans="Yes";
			}
			else{
				ans="No";
				m=0;
			}
			if((t[1]-t[0])<abs(a[1]-a[0])+abs(b[1]-b[0])){
				ans="No";
				m=0;
			}
			t[1]=t[0];
			a[1]=a[0];
			b[1]=b[0];
		}
	}
	printf("%s",ans.c_str());
	return 0;
}


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

int main() {
  int M, N, s = 0, p = 0;
  cin >> N;
  vector<string> plus(N);
  for (int i = 0; i < N; i++) {
    cin >> plus.at(i);
  }
  cin >> M;
  vector<string> minus(M);
  for (int j = 0; j < M; j++) {
    cin >> minus.at(j);
  }
  for (int k = 0; k < N; k++) {
    for (int l = 0; l < N; l++) {
      if (plus.at(k) == plus.at(l)){
        s += 1;
      }
    }
    for (int m = 0; m < M; m++) {
      if (plus.at(k) == minus.at(m)) {
        s -= 1;
      }
    }
    if (s > p) {
      p = s;
    }
    s = 0;
    
  }
  cout << p << endl;
}

Measured memory_bytes: 256
N = gets.to_i
F_CACHE = [1]
MOD = 10 ** 9 + 7

def extgcd(a, b)
  if b.zero?
    [1, 0, a]
  else
    x, y, d = extgcd(b, a % b)

    [y, x - (a / b) * y, d]
  end
end

def mod_inverse(a, m)
  x, y, _ = extgcd(a, m)
  (m + x % m) % m
end

(1..(N + 1)).inject(1) do |res, n|
  v = (res * n) % MOD

  F_CACHE << v

  v
end

class Integer
  def combination(k)
    return 1 if k.zero?
    return 0 if self < k

    # (self - k + 1..self).inject(:*) / k.factorial
    self.factorial * mod_inverse(k.factorial, MOD) * mod_inverse((self - k).factorial, MOD)
  end

  def permutation(k)
    return 1 if k.zero?

    (self - k + 1..self).inject(:*)
  end

  def factorial
    return F_CACHE[self] if F_CACHE[self]
    return 1 if self.zero?

    (1..self).inject(:*)
  end
end

A = gets.split.map(&:to_i)
counter = Hash.new
l = r = -1

A.each_with_index do |a, i|
  if counter[a]
    l = counter[a]
    r = i
    break
  else
    counter[a] = i
  end
end

1.upto(N + 1) do |k|
  puts ((N + 1).combination(k) - (l + N - r).combination(k - 1)) % MOD
end


Measured memory_bytes: 18956
#include<iostream>
#include <algorithm>
#include<string>
#include<vector>
#include<cmath>
using namespace std;

int main(){
int n;
cin>>n;
vector<int> d;
int cnt=0;
int a;
for(int i=0;i<n;i++){
  cin>>a;
  d.push_back(a);
}

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

if(n%2==1) cout<< cnt << endl;
else if(d[n/2]==d[n/2-1]) cout << cnt <<endl;

else cout<<d[n/2]-d[n/2-1]<<endl;

return 0;
}


Measured memory_bytes: 892
require "matrix"
a, b = gets.split.map(&:to_i)
ary1, ary2 = [], []
a.times{ary1<<gets.split.map(&:to_i)}
b.times{ary2<<gets.to_i}
m = Matrix[*ary1]
mb = Matrix.column_vector(ary2)
(m * mb).each{|z| puts z}

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

bool isExist(int a[],int i,int search){
  while(i>0){
    if(a[i-1]==search)
      return false;
    i--;
  }
    return true;
}

int main(){
  int A,B,K;
  cin>>A>>B>>K;
  int i=0,k=K;
  int a[200];
  while(k>0){
    if(A+i<=B){
      a[i]=A+i;
      cout<<a[i]<<endl;
      i++;
      k--;
    }else break;
  }
  k=K;
  while(k>0){
    if(B-k+1>=A){
      if(isExist(a,i,B-k+1)){
        a[i]=B-k+1;
        cout<<a[i]<<endl;
        i++;
      }
      k--;
    }else break;
  }
}


Measured memory_bytes: 256
n=int(input())
x=list(map(int,input().split()))

zahyo1=sum(x)//n
zahyo2=sum(x)//n+1

tairyoku1=0
tairyoku2=0
for i in range(n):
    tairyoku1+=(x[i]-zahyo1)**2
    tairyoku2+=(x[i]-zahyo2)**2

print(min(tairyoku1,tairyoku2))

Measured memory_bytes: 3064
t=[int(i) for i in input().split()]
if t[0]%2==t[3]%2==t[4]%2:
  print(t[0]+t[1]+t[3]+t[4])
else:
  if (t[0]+t[3]+t[4])%2==0 and t[0]*t[2]*t[4]==0:
    print(t[0]+t[1]+t[3]+t[4]-2)
  else:
    print(t[0]+t[1]+t[3]+t[4]-1)
  

Measured memory_bytes: 38384
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int s = scn.nextInt();
    	int count = 0;
    	int count2 = 0;
    	if(s==1){
        	count = count - 1;
        }
    	if(s==2){
        	count = count - 2;
        }
    	while(count2<2){
      		count = count + 1;
      		if(s==4){
            	count2 = count2 + 1;
            }
			if(s%2==0){
            	s = s/2;
            }else{
             	s = s*3 + 1;
            }
   		 }
    
    	System.out.println(count);
	}
}


Measured memory_bytes: 35808
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long ll;
typedef pair<ll,ll> P;


int n, m, x;

int main(){
	cin >> n >> x;
	int a = INF;
	for(int i = 0; i < n; i++){
		cin >> m;
		x-=m;
		a = min(a, m);
	}
	cout << n + x / a << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
 
#define check(c)       cout<<#c<<" : "<<c<<endl;
#define check2(a, b)    cout<<#a<<" : "<<a<<" | "<<#b<<" : "<<b<<endl;
#define check3(a, b, c)  cout<<#a<<" : "<<a<<" | "<<#b<<" : "<<b<<" | "<<#c<<" : "<<c<<endl;

void testCase(){
	  // int n; cin >> n;
	  // vector<int> a(n);

	   int n; cin >> n;
	   if(n == 1){
	   	cout << 0 << endl;
	   } else{
	   	cout << 1 << endl;
	   }

}
 
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

    int t = 1;
    // int t; cin >> t;
    while(t--)
        testCase();
    
    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
 
const int maxn = 1e5 + 20;

int n, a[maxn], cnt, res;
map<int, int> t;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int p;
		cin >> p;
		if (!t[p])
			a[cnt++] = p;
		t[p] ++;
	}
	for (int i = 0; i < cnt; i++)
		res += (t[a[i]] < a[i] ? t[a[i]] : t[a[i]] - a[i]);
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 5120
package main

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

const (
	N    = 3
	BASE = 10007
	MOD  = 1000000007
)

type Puzzle struct {
	board [N * N]int // (x, y). (0, 0) = 0,  (1, 0) = 1, (0, 1) = 3
}

type SolveContext struct {
	current  *Puzzle
	previous *Puzzle
	count    int
}

type Position struct {
	x int
	y int
}

func NewPuzzle(b [N * N]int) *Puzzle {
	return &Puzzle{board: b}
}

func (puzzle *Puzzle) toInt() int {
	arr := puzzle.board
	sum := arr[0]
	for i := 1; i < len(arr); i++ {
		sum = sum*BASE + arr[i]
		if sum > MOD {
			sum = sum % MOD
		}
	}
	return sum
}

func (puzzle *Puzzle) isSolved() bool {
	solvedBoard := [N * N]int{1, 2, 3, 4, 5, 6, 7, 8, 0}
	return puzzle.board == solvedBoard
}

func swap(puzzle *Puzzle, one, two Position) *Puzzle {
	swapped := NewPuzzle(puzzle.board)
	swapped.board[one.y*N+one.x], swapped.board[two.y*N+two.x] =
		swapped.board[two.y*N+two.x], swapped.board[one.y*N+one.x]
	return swapped
}

func (puzzle *Puzzle) getEmptyPosition() *Position {
	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			if puzzle.board[i*N+j] == 0 {
				return &Position{x: j, y: i}
			}
		}
	}
	return nil
}

func (puzzle *Puzzle) nextPuzzles() []*Puzzle {
	emptyPosition := puzzle.getEmptyPosition()
	if emptyPosition == nil {
		panic(fmt.Errorf("emptyPostion must not be empty"))
	}
	basePosition := *emptyPosition
	directions := [][2]int{[2]int{-1, 0}, [2]int{1, 0}, [2]int{0, -1}, [2]int{0, 1}} // []{x, y}
	nexts := []*Puzzle{}
	for _, dir := range directions {
		nextPosition := Position{basePosition.x + dir[0], basePosition.y + dir[1]}
		if nextPosition.x >= 0 && nextPosition.x <= N-1 &&
			nextPosition.y >= 0 && nextPosition.y <= N-1 {
			nexts = append(nexts, swap(puzzle, basePosition, nextPosition))
		}
	}
	return nexts
}

func solve(initialPuzzle *Puzzle) int {
	initial := SolveContext{initialPuzzle, nil, 0}
	visited := make(map[int]*struct{})
	stack := []SolveContext{initial}
	var solved SolveContext
	for len(stack) > 0 {
		solveContext := stack[0]
		current := solveContext.current
		count := solveContext.count
		visited[current.toInt()] = &struct{}{}
		stack = stack[1:]
		if current.isSolved() {
			solved = solveContext
			break
		}
		for _, v := range current.nextPuzzles() {
			if visited[v.toInt()] == nil {
				nextContext := SolveContext{v, current, count + 1}
				stack = append(stack, nextContext)
			}
		}
	}
	return solved.count
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	var arr [N * N]int
	for i := 0; i < len(arr); i++ {
		x, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		arr[i] = x
	}

	puzzle := NewPuzzle(arr)
	fmt.Println(solve(puzzle))
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}


Measured memory_bytes: 49416
import java.util.*;
public class Main {
	public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
      String line = sc.nextLine();
      String str[] = line.split(" ");
      int h = Integer.parseInt(str[0]);
      int w = Integer.parseInt(str[1]);
      for(int i =0;i<h;i++){
        String str2 = sc.nextLine();
        System.out.println(str2);
        System.out.println(str2);
      } 
	}
}

Measured memory_bytes: 24916
N, K = map(int, input().split())
ans = 0
if K == 0:
  ans = N * N
else:
  for b in range(K+1,N+1):
    k, m = N//b, N%b
    ans += k*(b-K)
    if m != 0:
      ans += max(m-K+1, 0)
print(ans)

Measured memory_bytes: 3060
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;




int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    for(int i=0;i<n;i++){cin>>a[i];}
    sort(a.begin(),a.end());
    ll ans=0;
    ll l=0,r=n-1;
    vector<ll> b;
    while(l<=r){
        b.push_back(a[l++]);
        if(l>r){break;}
        b.push_back(a[r--]);
    }
    ll mi=abs(b[0]-b[n-1]);
    ans+=abs(b[0]-b[n-1]);
    for(int i=1;i<n;i++){
        ans+=abs(b[i]-b[i-1]);
        mi=min(mi,abs(b[i]-b[i-1]));
    }
    ans-=mi;
    ll mx=ans;
    ans=0;
    b.clear();
    l=0; r=n-1;
    while(l<=r){
        b.push_back(a[r--]);
        if(l>r){break;}
        b.push_back(a[l++]);
    }
    mi=abs(b[0]-b[n-1]);
    ans+=abs(b[0]-b[n-1]);
    for(int i=1;i<n;i++){
        ans+=abs(b[i]-b[i-1]);
        mi=min(mi,abs(b[i]-b[i-1]));
    }
    ans-=mi;
    mx=max(mx,ans);
    cout<<mx<<endl;
    
    return 0;
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
#include <atcoder/string>
using namespace std;
using namespace atcoder;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define pb push_back
#define fi first
#define se second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void chOut(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using v_bool = vector<bool>;
using v_Pii = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;



signed main(){

    string S; cin >> S;
    int N = SZ(S);
    auto sa = suffix_array(S);
    auto la = lcp_array(S, sa);

    int ans = 0;
    REP(i, N - 1){
        ans += N - sa[i] - la[i];
    }
    ans += N - sa[N - 1];
    Out(ans);

    return 0;
}


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

int main() {
	string S, T, U;
	int A, B;
	cin >> S >> T;
	cin >> A >> B;
	cin >> U;
	if (U == S) A--;
	else if (U == T) B--;
	cout << A << " " << B << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int main(){
	string s;
	int ans=0;
	cin>>s;
	REP(i,s.size()){
		if(s[i]=='1'){
			cout<<9;
		}
		else{
			cout<<1;
		}
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cassert>

#include <vector>
#include <algorithm>
#include <string>
using namespace std;

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


void Main()
{
	int H, W;
	cin >> H >> W;
	vector<string> F(H+2);
	F[0] = string(W+2, '.');
	F[H+1] = string(W+2, '.');
	rep_init(i, 1, H+1)
	{
		string S;
		cin >> S;
		F[i] = "." + S + ".";
	}

	rep_init(i, 1, H+1)
	{
		rep_init(j, 1, W+1)
		{
			if (F[i][j] == '#') continue;

			int count = 0;
			rep_init(k, i-1, i+2)
			{
				rep_init(l, j-1, j+2)
				{
					if (F[k][l] == '#') ++count;
				}
			}

			F[i][j] = to_string(count)[0];
		}
	}

	rep_init(i, 1, H+1)
	{
		cout << F[i].substr(1, W) << endl;;
	}
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);

	Main();
	return 0;
}

Measured memory_bytes: 256
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int32_t, int32_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;
struct Vertex {
  vector<int32_t> neighbours;
};

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

  int32_t N;
  cin >> N;
  bool is_okay = true;
  char last_word = 0;
  unordered_map<string, bool> m;
  for (int32_t i = 0; i < N; ++i) {
    string w;
    cin >> w;
    if (i > 0 && w.c_str()[0] != last_word) {
      is_okay = false;
    }
    if (m.count(w) > 0) {
      is_okay = false;
    }
    m[w] = true;
    last_word = w.c_str()[w.length() - 1];
  }
  if (is_okay) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

const long double PI = acos(-1);
 
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

int main(){
    ll n;
    cin >> n;
    vector<int> a(n, 0);
    for (int i = 0; i < n; i++) cin >> a[i];

    int index = 1;
    int ans = 0;
    for (int i = 0; i < n; i++){
        if(a[i] != index) ans++;
        else index++;
    }
    if(index == 1) cout << -1 << endl;
    else cout << n - (index - 1) << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 505;
const ll LINF = 1e18 + 5;
int n, k, h[N];
ll dp[N][N];
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> n >> k;
 	for(int i=1;i<=n;i++) cin >> h[i];
 	for(int i=0;i<=n;i++)
 		for(int j=0;j<=n;j++)
 			dp[i][j] = LINF;
 	dp[0][0] = 0;
 	for(int i=1;i<=n;i++)
 		for(int j=1;j<=i;j++)
 			for(int t=0;t<i;t++)
 				dp[i][j] = min(dp[i][j],dp[t][j-1]+max(0,h[i]-h[t]));
 	ll ans = LINF;
 	for(int i=1;i<=n;i++)
 			ans = min(ans,dp[i][n-k]); 
 	if(ans==LINF) ans = 0;
  	cout << ans;
	return 0;
}


Measured memory_bytes: 1408
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.readline
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import combinations
def run():
    n,k = map(int, input().split())
    mod = 10 ** 9 + 7
    ret = 0
    inv = generate_inv(n, mod)

    if k >= n-1:
        k = n-1
    left = 1
    right = 1
    ret = 1
    for h in range(1, k+1):
        right *= (n - h) * inv[h]
        right %= mod
        left *= (n - h + 1) * inv[h]
        left %= mod
        ret += right * left
        ret %= mod
    print(ret)


def generate_inv(n,mod):
    """
    逆元行列
    n >= 2
    """
    ret = [0, 1]
    for i in range(2,n+1):
        next = -ret[mod%i] * (mod // i)
        next %= mod
        ret.append(next)
    return ret


def comb_mod(n, a, mod):
    """
    return: [n, a] % mod
    Note: mod must be a prime number
    """
    up = 1
    down = 1
    for i in range(a):
        up *= n - i
        up %= mod
        down *= i + 1
        down %= mod
    down = pow_mod(down, mod - 2, mod)
    return (up * down) % mod

def pow_mod(n, k, mod):
    res = 1
    while True:
        if k // 2 >= 1:
            if k % 2 == 1:
                res = (res * n) % mod
            n = (n ** 2) % mod
            k = k // 2
        else:
            break
    return (n * res) % mod


if __name__ == "__main__":
    run()

Measured memory_bytes: 11076
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <random>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;
using ll = long long;

using Pair = pair<int, int>;

int main() {
    int n;
    cin >> n;
    vector<Pair> ab, cd;
    for (auto i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        ab.push_back(Pair(a, b));
    }
    sort(ab.begin(), ab.end(), [](Pair l, Pair r) {
        return l.first < r.first;
    });
    for (auto i = 0; i < n; i++) {
        int c, d;
        cin >> c >> d;
        cd.push_back(Pair(c, d));
    }
    sort(cd.begin(), cd.end(), [](Pair l, Pair r) {
        return l.second < r.second;
    });
    for (auto i = 0; i < n; i++) {
        auto ccd = cd[i];
        for (auto j = ab.size(); j > 0; j--) {
            if (ccd.first > ab[j - 1].first && ccd.second > ab[j - 1].second) {
                ab.erase(ab.begin() + j - 1);
                break;
            }
        }
    }
    cout << n - ab.size();
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define vv(T) vector<vector<T>>
using namespace std;
using ll = long long;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using vll = vector<long long>;
using vvll = vector<vector<long long>>;
using vbool = vector<bool>;
using vvbool = vector<vector<bool>>;
using qint = queue<int>;
using sint = stack<int>;
using pii = pair<int, int>;

bool check(ll a, ll b, ll c){
    vector<long long> lines = {a, b, c};
    sort(lines.begin(), lines.end());
    bool ans = false;
    if(lines[2] < lines[1] + lines[0]) ans = true;
    return ans;
}

int main(){
    int n;
    cin >> n;
    vll l(n);
    rep(i, n) cin >> l[i];

    long long ans = 0;
    {
        for(int i = 0; i < n - 2; i++){
            for(int j = i + 1; j < n - 1; j++){
                for(int k = j + 1; k < n; k++){
                    auto a = l[i];
                    auto b = l[j];
                    auto c = l[k];
                    if(a == b || b == c || c == a) continue;
                    if(check(a, b, c)) ans++;
                }
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;
	int l = 0;
	for (int i = 0; i < b - a; ++i) {
		l += (i + 1);
	}
	cout << l - b;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

using P = pair<int, int>;

// dp[bit][k] := bitが立っている場所のカードをソートして並べた時、
// 最後の数がkである時の操作回数の最小値
vector<vector<int>> dp((1 << 18) + 10, vector<int>(60, INF));

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for(int i = 0; i < n; i++) {
        cin >> b[i];
    }
    dp[0][0] = 0;

    for(int bit = 0; bit < (1 << n); bit++) {
        // 今何枚並べているか
        int np = __builtin_popcount(bit);
        for(int k = 0; k <= 50; k++) {
            if(dp[bit][k] == INF) {
                continue;
            }
            int cost = 0;
            // 次に置くカードを決める
            // bitが立っている部分については既にソートして並べられていて、
            // bitが立っていない部分についてはソート済みの後に順番に置かれていると考える
            // すると、costは前から見ていった順に0,1,2...となる
            for(int i = 0; i < n; i++) {
                // もしi番目のカードを既に使っていたらだめ
                if(bit & (1 << i)) {
                    continue;
                }
                // 位置の相対的な偶奇で表か裏かが決まる
                int next = (abs(i - np) % 2 == 0 ? a[i] : b[i]);
                // 次に置くカードによって広義単調増加になるならば更新
                if(next >= k) {
                    chmin(dp[bit | (1 << i)][next], dp[bit][k] + cost);
                }
                cost++;
            }
        }
    }
    int ans = INF;
    for(int i = 0; i <= 50; i++) {
        chmin(ans, dp[(1 << n) - 1][i]);
    }
    cout << (ans == INF ? -1 : ans) << endl;
}

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

int main() {

  int X;
  cin >> X;
  
  int A, B, C, D, B0, C0;
  A = X / 1000;
  B0 = X - A*1000;
  B = B0 / 100;
  C0 =  B0 - B*100;
  C = C0 / 10;
  D = C0 - C*10;
  
  char op1 = '+';
  char op2 = '+';
  char op3 = '+';
  
  if ( A + B + C - D == 7) {
	op3 = '-';
  } else if ( A + B - C + D == 7) {
    op2 = '-';
  } else if ( A - B + C + D == 7) {
    op1 = '-';
  } else if ( A + B - C - D == 7) {
    op2 = '-';
    op3 = '-';
  } else if ( A - B + C - D == 7) {
    op1 = '-';
    op3 = '-';
  } else if ( A - B - C + D == 7) {
    op1 = '-';
    op2 = '-';
  } else if ( A - B - C - D == 7) {
    op1 = '-';
    op2 = '-';
    op3 = '-';
  }
  
  cout << A << op1 << B << op2 << C << op3 << D << "=7" << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
#define ll long long 
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define REP(i,n) for (int i=0; i<(n); i++)
#define RREP(i,n) for (int i=(n-1); i>=0; i--)
#define ALL(x) x.begin(),x.end()
#define SZ(x) x.size()
#define SQ(x) (x)*(x)
#define MNTO(a,b) a = min(a,(__typeof__(a))(b))
#define MXTO(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define debug(x) cerr<<#x<<" is "<<x<<endl
using namespace std;

// #define int ll

const int maxn = 1e5+5;
const int iinf = 1<<29;
const ll inf = 1ll<<60;
const ll mod = 1e9+7;


void GG(){cout<<"No\n"; exit(0);}

ll pow(ll a, ll n){ // a^n % mod
    ll re=1;
    while (n>0){
        if (n&1) re = re*a %mod;
        a = a*a %mod;
        n>>=1;
    }
    return re;
}

ll inv (ll b){
    if (b==1) return b;
    return (mod-mod/b) * inv(mod%b) % mod;
}

main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int a, b, c; cin>>a>>b>>c; cout<<min(a*b,c)<<endl;

    
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;

const ll mod=1e9+7;
const ll inf=1e16; 

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)

int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  long long a,b;
  cin >> a >> b;
  
   ll res=-1;
  rep(i,0,100000){
    if(floor(double(i)*0.08)==a&&floor(double(i)*0.1)==b) {
      res=i;
      break;
    }
  }
 cout << res << endl;
}

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

int main(void)
{
    list<char>sa;
    list<char>sb;
    list<char>sc;
    char ch;
    while((ch=getchar())!='\n')
    {
        sa.push_back(ch);
    }
    while((ch=getchar())!='\n')
    {
        sb.push_back(ch);
    }
    while((ch=getchar())!='\n')
    {
        sc.push_back(ch);
    }
    ch=sa.front();
    sa.pop_front();
    while(1)
    {
        if(ch=='a')
        {
            if(sa.empty())
            {
                printf("A\n");
                break;
            }
            ch=sa.front();
            sa.pop_front();
        }
        else if(ch=='b')
        {
            if(sb.empty())
            {
                printf("B\n");
                break;
            }
            ch=sb.front();
            sb.pop_front();
        }
        else if(ch=='c')
        {
            if(sc.empty())
            {
                printf("C\n");
                break;
            }
            ch=sc.front();
            sc.pop_front();
        }
    }

    return 0;
}


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

int main(void)
{
	double in, min, max;
	scanf("%lf", &in);
	min = max = in;
	while (scanf("%lf", &in) != EOF) {
		if (in < min)
			min = in;
		else if (max < in)
			max = in;
	}
	printf ("%.1f\n", max - min);
	exit(0);
}

Measured memory_bytes: 652
use proconio::input;

fn main() {
    input! {
        n: usize,
        a1: [i32; n],
        a2: [i32; n],
    }

    let mut map = vec![vec![std::i32::MAX; n]; 2];

    map[0][0] = a1[0];
    map[1][0] = a1[0] + a2[0];
    for j in 1..n {
        map[0][j] = map[0][j - 1] + a1[j];
        map[1][j] = if map[0][j] > map[1][j - 1] {
            map[0][j] + a2[j]
        } else {
            map[1][j - 1] + a2[j]
        };
    }
    println!("{}", map[1][n - 1]);
}

Measured memory_bytes: 2140
#include<bits/stdc++.h>
using namespace std;
 
int main(){

    int n;
    cin >> n;

    int p_min = 1000000000;
    int ans = 0;

    for(int i = 0; i < n; ++i){
        int p;
        cin >> p;
        p_min = min(p, p_min);
        if(p_min == p)++ans;
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    vint A(N);
    rep(i, N) cin >> A[i];
    ll ans = 0;
    int now = A[0];
    if (A[0] != 0) {
        cout << "-1" << endl;
        return 0;
    }
    REP(i, 1, N) {
        if (now + 1 < A[i]) {
            cout << "-1" << endl;
            return 0;
        }
        if (now + 1 == A[i]) {
            
        }
        else if (now >= A[i]) {
            ans += now;
        }

        now = A[i];
    }
    ans += now;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define deg_to_rad(deg) (((deg)/360)*2*M_PI)
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
const double PI = 3.1415926535897932;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

int main()
{
	int X;
	cin >> X;
	int range = (int)1e5;
	vector<ll> pw(range, 0);
	for (int i = 1; i < range; ++i) {
		ll t = i * i;
		pw[i] = t * t * i;
	}

	for (int i = 0; i < range; ++i) {
		for (int j = 0; j < range; ++j) {
			if (pw[i] + pw[j] == X) {
				cout << i << " " << j * -1 << endl;
				return 0;
			}
			if (pw[i] - pw[j] == X) {
				cout << i << " " << j << endl;
				return 0;
			}
		}
	}
	
	return 0;
}


Measured memory_bytes: 4036
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
//#define mp make_pair

int a, b;


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

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);


cin >> a >> b;

if(a<=b){
    cout << a << endl;
}
else {
    cout << a-1 << endl;
}

return 0;}


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

int arr[105];

int main() {
	// freopen("input.in", "r", stdin);
	// freopen("output.o", "w", stdout);
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
	sort(arr, arr + n);
	printf("%d", arr[n-1] - arr[0]);	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
            using namespace std;
             
            int main() {
              int N, A, B , x, K, i, sum;              
              cin >> N >> K;
              for (i = 0; i < N; i++){
                cin >> x;
                if(x * 2 < (K - x) * 2) {
                  sum += x * 2;
                } else {
                  sum += (K - x) * 2;
                }
              }
               cout << sum << endl;
            }

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

using namespace std;

int calc(const std::vector<int>& as) {
  int ret = 0;
  int prev = 0;
  int clump = 0;
  for (auto&& a : as) {
    if (a == prev) {
      clump++;
      continue;
    }

    if (clump > 1) {
      ret += clump / 2;
    }

    prev = a;
    clump = 1;
  }
  return ret;
}

int main() {
  int32_t n;
  std::cin >> n;
  std::vector<int> as(n + 1);
  for (int i = 0; i < n; ++i) {
    std::cin >> as[i];
  }
  as[n] = 10001;
  std::cout << calc(as) << std::endl;
  return 0;
}


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

int main()
{
  	int n, m;
  	cin>>n>>m;
  	int a[n][2], b[m][2];
  	for(int i = 0; i < n; i++)
      for(int j = 0; j < 2; j++)
        cin>>a[i][j];
 	for(int i = 0; i < m; i++)
      for(int j = 0; j < 2; j++)
        cin>>b[i][j];
  	for(int i = 0; i < n; i++)
    {	
      	int d = INT_MAX, ans = 0;
    	for(int j = 0; j < m; j++)
        {
        	int r = abs(a[i][0]-b[j][0])+abs(a[i][1]-b[j][1]);
          	if(r < d)
            {
            	d = r;
              	ans = j;
            }
        }
      	cout<<ans+1<<"\n";
    }
	return 0;
}

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

int main(){
    double D,T,S;

    cin >> D >> T >> S;

    if(D / S <= T)cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}


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

n,m,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

ans = 0
ans0 = 0
ans1 = 0
for i in range(n):
    if A[i] + ans0 <= k:
        ans0 += A[i]
        ans1 += 1
    else:
        break
ind = ans1-1

jnd = 0
for i in range(m):
    if B[i] + ans0 <= k:
        ans0 += B[i]
        ans1 += 1
        jnd += 1
    else:
        break


ans = ans1
# print(ans,ans0)
# print("jnd",jnd)

for i in range(ind, -1, -1):
    ans1 -= 1
    ans0 -= A[i]
    # print("m",ans0)
    # print("jnd",jnd)
    while jnd < m and ans0 + B[jnd] <= k:
        ans0 += B[jnd]
        
        jnd += 1
        ans1 += 1
    # print(ans1, ans0)
    ans = max(ans, ans1)
print(ans)
# print("jnd",jnd)

Measured memory_bytes: 108644
use std::ascii::AsciiExt;
use std::io::{stdin, BufReader, StdinLock, BufRead};

fn main() {
    let std_in = stdin();
    let mut br = BufReader::new(std_in.lock());

    let tmp: Vec<usize> = rvn(&mut br);
    let (n, k) = (tmp[0], tmp[1]);
    let mut s = rs(&mut br);
    s[k-1] = s[k-1].to_ascii_lowercase();
    for c in s {
        print!("{}", c);
    }
    println!();
}


//////////////////////////////////////////////////////////////////////////////////

fn rs(br: &mut BufReader<StdinLock>) -> Vec<char> {
    let mut buf = String::new();
    br.read_line(&mut buf).ok();
    buf.trim().chars().collect()
}

fn rn<T: std::str::FromStr>(br: &mut BufReader<StdinLock>) -> T {
    let mut buf = String::new();
    br.read_line(&mut buf).ok();
    buf.trim().parse().ok().unwrap()
}

fn rvs(br: &mut BufReader<StdinLock>) -> Vec<Vec<char>> {
    let mut buf = String::new();
    br.read_line(&mut buf).ok();
    buf.trim().split_whitespace().map(|e| e.chars().collect()).collect()
}

fn rvn<T: std::str::FromStr>(br: &mut BufReader<StdinLock>) -> Vec<T> {
    let mut buf = String::new();
    br.read_line(&mut buf).ok();
    buf.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}



Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long

signed main()
{

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    unordered_map<string,int> m;
    int t;
    cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        m[s]++;
    }
    cout<<"AC x "<<m["AC"]<<endl;
    cout<<"WA x "<<m["WA"]<<endl;
    cout<<"TLE x "<<m["TLE"]<<endl;
    cout<<"RE x "<<m["RE"]<<endl;
    return 0;
}


Measured memory_bytes: 3588
import sys
input=sys.stdin.readline
n,k,q=map(int,input().split())
C=[0]*n
for _ in range(q):
    i=int(input())
    C[i-1]+=1
Ans=[False]*n
for i,c in enumerate(C):
    score=k-q+c
    if score>0:
        Ans[i]=True
for ans in Ans:
    print('Yes' if ans else 'No')

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

using namespace std;
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
  
signed main() {
  vector<bool> A(100100,true);
  for(int i=2;i<=100010;i++){
    int up=sqrt(i)+1;
    for(int j=2;j<up;j++){
      if(i%j==0){
         A[i]=false;
        break;
      }
    }
  }

  vector<int> B(50050);
  for(int i=3;i<=100010;i+=2){
    B[i/2]=B[(i-2)/2];
    if(A[i]&&A[(i+1)/2]){
      B[i/2]++;
    }
  }
  int q;
    scanf("%d",&q);
  for(int i=0;i<q;i++){
    int l,r;
      scanf("%d%d",&l,&r);
    if(l==1){
      l+=2;
    }
    printf("%d\n",B[r/2]-B[(l-2)/2]);
  }
}

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

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    int alice = 0;
    int bob = 0;
    sort(a.begin(), a.end());
    int turn = 1;
    while (a.size() > 0)
    {
        int s = a.back();
        if (turn == 1)
        {
            alice += s;
        }
        else
        {
            bob += s;
        }
        a.pop_back();
        turn *= -1;
    }
    int ans = alice - bob;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>

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

using namespace std;


void C_141()
{
  int N, K, Q;
  cin >> N >> K >> Q;

  vector<int> point(N, 0);
  for (int i = 0; i < Q; ++i)
  {
    int A;
    cin >> A;
    ++point[A - 1];
  }

  for (int i = 0; i < N; ++i)
  {
    if (0 >= K - (Q - point[i])) cout << "No" << endl;
    else cout << "Yes" << endl;
  }

}

int main()
{
  //C_140();
  C_141();
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

#define MAX 100000
#define SENTINEL 2147483647 

typedef struct tagCard{
	char m;
	int n;
}CARD;

CARD A[MAX], B[MAX];
CARD L[MAX/2+2], R[MAX/2+2];
int cnt = 0;

void merge(CARD A[], int left, int mid, int right)
{
	int n1, n2;
	int i, j, k;
	n1 = mid - left;
	n2 = right - mid;
	for (i = 0; i < n1; i++) {
		L[i] = A[left + i];
	}
	L[i].n = SENTINEL;
	for (i = 0; i < n2; i++) {
		R[i] = A[mid + i];
	}
	R[i].n = SENTINEL;
	for (i = 0, j = 0, k = left; k < right; k++) {
		cnt++;
		if (L[i].n <= R[j].n) {
			A[k] = L[i];
			i++;
		}
		else {
			A[k] = R[j];
			j++;
		}
	}

}

void mergeSort(CARD A[], int left, int right)
{
	if (left + 1 < right) {
		int mid = (left + right) / 2;
		mergeSort(A, left, mid);
		mergeSort(A, mid, right);
		merge(A, left, mid, right);
	}
}

int partition(CARD C[], int p, int r)
{
	int i = p - 1;
	int j = 0;
	int x = C[r].n;
	CARD temp;

	for (j = p; j < r; j++)
	{
		if (C[j].n <= x)
		{
			i++;
			temp = C[i];
			C[i] = C[j];
			C[j] = temp;
		}
	}
	temp = C[i + 1];
	C[i + 1] = C[r];
	C[r] = temp;
	return i + 1;
}

void quicksort(CARD A[], int p, int r)
{
	int q;
	if (p < r)
	{
		q = partition(A, p, r);
		quicksort(A, p, q - 1);
		quicksort(A, q + 1, r);
	}
	return;
}

int main()
{
	int i, n;
	char mark[2];
	int value;
	int isStable = 1;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%s %d", mark, &value);
		A[i].m = B[i].m = mark[0];
		A[i].n = B[i].n = value;
	}
	mergeSort(A, 0, n);
	quicksort(B, 0, n - 1);
	for (i = 0; i < n; i++)
	{
		if (A[i].n == B[i].n)
		{
			if (A[i].m != B[i].m)
			{
				isStable = 0;
				break;
			}
		}
	}
	if (isStable)
	{
		printf("Stable\n");
	}
	else
	{
		printf("Not stable\n");
	}
	for (i = 0; i < n; i++)
	{
		printf("%c %d\n", B[i].m, B[i].n);
	}
	return 0;
}


Measured memory_bytes: 5076
L=lambda:list(map(int,input().split()));r=range;n,m=L();k=[L()for _ in r(n)];print(max(-sum(sorted([-sum([j[i]*(int(bin(s)[2:].zfill(3)[i])*2-1)for i in r(3)])for j in k])[:m])for s in r(8)))

Measured memory_bytes: 3316