akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int isprime(int n);
int isSmallTwinPrime(int n);
int GetMaxTwinPrimeNumber(int argRange);

int main()
{
	int const size = 10000;
	int data[size];	
	
	int i=0;
	while(1) //for(int i=0; data[i]!=0; i++)
	{
		cin >> data[i];
		if(data[i]<=0) break;
		i++;
	}
	
	int outputNum;
	
	for(int i=0; data[i]!=0; i++)
	{
		outputNum = GetMaxTwinPrimeNumber(data[i]);
		if(outputNum!=0)
		{
			cout << outputNum-2 << " " << outputNum << endl;
		}
	}
	
	return 0;
}

int isprime(int n) 
{
	for(int i = 2; i * i <= n; i++) 
	{
		if(n % i == 0) 
		{
			return 0;
		}
	}
	return 1;
}

int isSmallTwinPrime(int n)
{
	for(int i = 2; i * i <= n; i++) 
	{
		if((n-2) % i == 0) 
		{
			return 0;
		}
	}
	return 1;
}

int GetMaxTwinPrimeNumber(int argRange)
{
	int maxTwinPrimeNum = 0;
	
	for(int i=0; ; i++)
	{
		int Num = argRange - i;
		
		if(isprime(Num)==1 && isSmallTwinPrime(Num)==1)
		{
			maxTwinPrimeNum = Num;
			return maxTwinPrimeNum;
		}
		
		if(Num==0)
		{
			return 0;
		}
	}
}

Measured memory_bytes: 3032
import sys
from collections import deque

input = sys.stdin.readline


def bfs(K):
    count = 9
    queue = deque("123456789")
    while queue:
        num = queue.popleft()
        d1 = int(num[-1])
        # e.g.) 123 --> 1232
        if d1 - 1 >= 0:
            count += 1
            next_num = "".join([num, str(d1 - 1)])
            if count == K:
                return int(next_num)
            else:
                queue.append(next_num)
        # e.g.) 123 --> 1233
        count += 1
        next_num = "".join([num, str(d1)])
        if count == K:
            return int(next_num)
        else:
            queue.append(next_num)
        # e.g.) 123 --> 1234
        if d1 + 1 <= 9:
            count += 1
            next_num = "".join([num, str(d1 + 1)])
            if count == K:
                return int(next_num)
            else:
                queue.append(next_num)


def main():
    K = int(input())

    if K <= 9:
        ans = K
    else:
        ans = bfs(K)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 13640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    vector<ll> x(n);
    for(int i = 0; i < n; i++)
        cin >> x[i];
    ll sum = 0;
    for(ll i = 1; i < n; i++){
        if((x[i] - x[i - 1]) * a > b)
        sum += b;
        else
        sum += (x[i] - x[i - 1]) * a;
    }
    cout << sum << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

// 2???????????????????????????????±???????
double dot(P a, P b) {
    return (a.X * b.X + a.Y * b.Y);
}

// 2???????????????????????????????±???????
double cross(P a, P b) {
    return (a.X * b.Y - a.Y * b.X);
}

pair<int, int> convexDiameter(const vector<P> &ps) {
    int n = ps.size();
    int i = min_element(ps.begin(), ps.end()) - ps.begin();
    int j = max_element(ps.begin(), ps.end()) - ps.begin();
    int maxI, maxJ;
    double maxD = 0;
    rep(_, 0, 2*n) {
        if(maxD < norm(ps[i] - ps[j])) {
            maxD = norm(ps[i] - ps[j]);
            maxI = i;
            maxJ = j;
        }
        if(cross(ps[i] - ps[(i+1) % n], ps[(j+1) % n] - ps[j]) <= 0) j = (j+1) % n;
        else i = (i+1) % n;
    }
    return make_pair(maxI, maxJ);
}

int main() {
    int n; cin >> n;
    vector<P> ps;
    rep(i,0,n) {
        P temp; cin >> temp.X >> temp.Y;
        ps.pb(temp);
    }
    pii ans = convexDiameter(ps);
    printf("%.10f\n", sqrt(norm(ps[ans.first] - ps[ans.second])));
    return 0;
}

Measured memory_bytes: 3140
import scala.io._

// e.g
// 1 2 3
// val Array(a, b) = readLine.split(" ").map(_.toInt) => Array(1, 2, 3)
// 5
// 1 2 3
// 4 5 6
// 7 8 9
// val lines = Source.stdin.getLines()
// データ個数読み取り
// val n = lines.next().toInt
// データ行n個読み取り
// val data = lines.take(n).map{ line => line.split(" ").map(_.toInt).toList }.toList => List(List(1, 2, 3), List(4, 5, 6), List(7, b, 9))

object Main {
  def main(args: Array[String]): Unit = {
    val Array(a, b, c) = readLine.split(" ").map(_.toInt)
    if (a == b) {
      println(c)
    }
    else if (b == c) {
      println(a)
    }
    else {
      println(b)
    }
  }
}


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

using namespace std;

using i64 = long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


signed main(){
    int x, y;
    cin >> x >> y;
    int ans = 0;
    if(x == 3)
        ans += 100000;
    if(y == 3)
        ans += 100000;

    if(x == 2)
        ans += 200000;
    if(y == 2)
        ans += 200000;
    if(x == 1)
        ans += 300000;
    if(y == 1)
        ans += 300000;

    if(x == 1 && y == 1)
        ans += 400000;
    cout << ans << endl;
}


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

int main()
{
    int x,a,b;
    ios::sync_with_stdio(false);
    while(cin>>x>>a>>b)
    {
        if(fabs(x-a)>fabs(x-b))
            cout<<"B"<<endl;
        else cout<<"A"<<endl;
    }
    return 0;
}


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

x = max(a)
dp = [0] * (x+1)
for ai in a:
    i = 1
    while i * ai <= x:
        dp[i * ai] += 1
        i += 1

ans = 0
for ai in a:
    if dp[ai] <= 1:
        ans += 1

print(ans)

Measured memory_bytes: 132308
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<iomanip>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

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

	int a, b;
	cin >> a >> b;
	if (a % 2 == 0 || b % 2 == 0) {
		cout << "Even" << endl;
	}
	else {
		cout << "Odd" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string w, t;
    int a = 0;
    cin >> w;
    while (cin >> t) {
        if (t == "END_OF_TEXT") break;
        for (int i = 0; i < t.size(); i++) {
            if (isupper(t[i])) t[i] = tolower(t[i]);
        }
        if (t == w) a++;
    }
    cout << a << endl;
}


Measured memory_bytes: 3208
n = int(input())
a = list(map(int,input().split()))
count = 1
key = a[0]
ans = 0
if n==1:
    print(0)
else:
    for i in range(1,n):
        if key == a[i]:
            count += 1
        else:
            ans += count//2
            key = a[i]
            count = 1
ans += count//2
print(ans)


Measured memory_bytes: 3060
n,m,c=io.read("*n", "*n", "*n")
b={}
for i = 1, m do
    b[i] = io.read("*n")
end
cnt = 0
for j = 1, n do
    ans = c
    for i = 1, m do
        ans = ans + b[i] * io.read("*n")
    end
    if(0 < ans) then cnt = cnt + 1 end
end
print(cnt)

Measured memory_bytes: 256
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

n_ = 2*10**6 + 3
mod = 10**9+7
fun = [1]*(n_+1)
for i in range(1,n_+1):
    fun[i] = fun[i-1]*i%mod
rev = [1]*(n_+1)
rev[n_] = pow(fun[n_],mod-2,mod)
for i in range(n_-1,0,-1):
    rev[i] = rev[i+1]*(i+1)%mod

def nCr(n,r):
    if r > n:
        return 0
    return fun[n]*rev[r]%mod*rev[n-r]%mod


ans = 0
r1,c1,r2,c2 = nm()
for i in range(r1,r2+1):
    ans = (ans + nCr(c2+i+1,i+1) - nCr(c1+i,i+1))%mod
print(ans)

Measured memory_bytes: 72028
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    string s; cin>>s;
    if(s=="AAA" || s=="BBB") cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

#define REP(i,p,n) for(ll i=p;i<ll(n);++i)
#define rep(i,n) REP(i,0,n)

using ll = long long int;
using pll = pair<ll, ll>;

const ll mod = static_cast<ll>(1e9) + 7;

int main()
{
    ll A, B;
    cin >> A >> B;

    const ll ans = (A + B) / 2;

    if (abs(A - ans) - abs(B - ans) == 0)
    {
        cout << ans << endl;
    }
    else
    {
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <cstring>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

int main() {
  string str;
  cin >> str;
  int b = 0,r = 0;
  for( char c : str){
    if(c=='0')b++;
    else r++;
  }

  cout << min(b,r) * 2 << endl;
}


Measured memory_bytes: 512
//0-5
//1521112 ????????????@?????????????

#include <stdio.h>

int main(void){

	int a, b, a1, b1;
	int gcd, lcm,r;
	int tmp;

	while (scanf("%d %d", &a1, &b1) != EOF){

		a = a1;
		b = b1;
		if (a < b){
			tmp = a;
			a = b;
			b = tmp;
		}

		r = a%b;

		while (r != 0)
		{
			a = b;
			b = r;
			r = a%b;
		}
		gcd = b;
		lcm = a1 / gcd*b1;

		printf("%d %d\n", gcd,lcm);
	}

	return 0;

}

Measured memory_bytes: 592
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	ls := make([]int, n+1)
	ls[0], ls[1] = 2, 1
	for i := range ls {
		if i <= 1 {
			continue
		}
		ls[i] += ls[i-1] + ls[i-2]
	}
	fmt.Println(ls[n])
}


Measured memory_bytes: 512
n,l = map(int,input().split())
S = list()

for i in range(n):
  S.append(input())
else:
  S.sort()
  print("".join(S))

"""
文字列もlist.sort()で並べ替えができるよ！！！
あとは、joinメソッドを使うか、

for i in range(len(S)):
    str_print = str_print + S[i]
else:
    print(str_print)

の方法があるよ！！！
"""

Measured memory_bytes: 3060
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

LL test(vector<int> A){
	int N = A.size();
	LL ret = 0;
	for(int i=0;i<N;++i){
		int pos = i;
		for(int j=i;j<N;++j){
			if( A[j] < A[pos] ){
				pos = j;
			}
		}
		while( i+1 < pos ){
			swap( A[pos-2],A[pos] );
			pos -= 2;
		}
		if( i+1 == pos ){
			swap( A[pos-1],A[pos] );
			--pos;
			++ret;
		}
	}
	return ret;
}
void solve(){
	int N;
	cin >> N;
	vector<int> A(N);
	for(int i=0;i<N;++i){
		cin >> A[i];
	}
	//cerr << test(A) << endl;
	vector<int> B = A;
	sort(B.begin(), B.end());
	for(int i=0;i<N;++i){
		int index = lower_bound(B.begin(),B.end(),A[i])-B.begin();
		A[i] = index;
	}
	vector<int> odd(2,0);
	for(int i=0;i<N;++i){
		if( (A[i]&1) != (i&1) ){
			odd[i&1]++;
		}
	}
	cout << abs(odd[0]-odd[1]) + min(odd[0],odd[1]) << endl;
	return;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	
	
	solve();
}
#pragma endregion //main()


Measured memory_bytes: 1024
fn main() {
    let x: i32 =read();
    let y: i32 =read();
    println!("{}", x + y / 2);
}

fn read<T: std::str::FromStr>() -> T {
    use std::io::prelude::*;

    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

int main(){
  int n,m; cin >>n >>m;
  vector<li> cnt(n,0);
  rep(i,m){
    int a,b; cin >>a >>b; a--;b--;
    cnt[a]++; cnt[b]++;
  }
  int flag=1;
  rep(i,n) if(cnt[i]%2==1){
    flag=0;
    break;
  }
  yn(flag);
}


Measured memory_bytes: 4024
// C - Coloring Colorfully
#include <bits/stdc++.h>
using namespace std;

int main(){
	string S; cin>>S;
	int N = S.size();
	int a = 0, b = 0;
	for(int i=0; i<N; ++i){
		bool s = S[i]-'0';
		bool odd = i%2;
		if(odd^s) ++a;
		if((!odd)^s) ++b;
	}
	cout<< min(a, b) <<endl;
}

Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int bubble_sort(vector<int>& as) {
    int ret = 0;
    for (int i = 0; i < as.size() - 1; i++) {
        for (int j = 0; j < as.size() - 1 - i; j++) {
            if (as[j] > as[j + 1]) {
                swap(as[j], as[j + 1]);
                ret++;
            }
        }
    }
    return ret;
}

void print_all(vector<int>& as) {
    for (int i = 0; i < as.size(); i++) {
        if (i > 0) {
            cout << " ";
        }
        cout << as[i];
    }
    cout << endl;
}

int main() {
    int n;
    cin >> n;
    vector<int> as(n);
    for (auto& a : as) {
        cin >> a;
    }

    int swap_count = bubble_sort(as);
    print_all(as);
    cout << swap_count << endl;
}

Measured memory_bytes: 1196
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(void){
    // Your code here!
    long long n, t, j;
    vector<vector<long long>> csf(501, vector<long long>(3, 0));
    
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> csf[i][0] >> csf[i][1] >> csf[i][2];
    
    for(int i = 0; i < n - 1; i++){
        j = i;
        t = 0;
        while(j < n - 1){
            if(t >= csf[j][1])
                t = (long long)ceil((double)t / csf[j][2]) * csf[j][2];
            else
                t = csf[j][1];
            t += csf[j][0];
            j++;
        }
        cout << t << endl;
    }
    
    cout << 0 << endl;
    
    return 0;
}


Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    tmp0 = input[0].split(" ");
    N = Number(tmp0[0]);
    T = Number(tmp0[1]);
 // console.log(N,T);

    var ans=1001;
    for(i=1;i<=N;i++){
          tmp1 = input[i].split(" ");
          if(T>= Number(tmp1[1])){
                     c = Number(tmp1[0]);
                     ans= Math.min(ans,c);}
                        }
  
     if(ans==1001){console.log('TLE');} 
       else{console.log(ans);} 
     }        

    
  //*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
  Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//   

Measured memory_bytes: 7628
n = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
res = 0
for i in range((n + 1)//2):
  if B[i] > A[i]:
    res += min(A[i] + A[i+1], B[i])
    A[i+1] = max(0, A[i] + A[i+1] - B[i])
    A[i] = 0
    B[i] = 0
  else:
    res += B[i]
    A[i] -= B[i]
    B[i] = 0
  if B[n-i-1] > A[n-i]:
    res += min(A[n-i] + A[n-i-1], B[n-i-1])
    A[n-i-1] = max(0, A[n-i-1] + A[n-i] - B[n-i-1])
    A[n-i] = 0
    B[n-i-1] = 0
  else:
    res += B[n-i-1]
    A[n-i] -= B[n-i-1]
    B[n-i-1] = 0
print(res)

Measured memory_bytes: 18624
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    // n = 1 の場合のみ例外(n-1要素のvectorを定義できないので)
    if(n == 1) {
        cout << 0 << endl;
        return 0;
    }

    vector<int> c(n-1), s(n-1), f(n-1), ans(n);
    rep(i, n) {
        cin >> c[i] >> s[i] >> f[i];
    }

    // 駅i(iは0-index)をスタートにする
    rep(i, n-1) {
        int t = 0;  // 現在の時刻(最初は0)
        for(int j = i; j < n-1; j++) {  // 駅j(j = i ～ max(n-2, i))にいるとき駅j+1に移動するのにかかる時間を考える
            if(s[j] <= t) {  // 最初の列車が既に出発している場合
                if(t%f[j] == 0) {  // 現在の時刻がf[j]の倍数のとき
                    t += c[j];  // すぐ列車に乗れるのでc[j]かけて移動
                }
                else {  // 現在の時刻がf[j]の倍数でないとき
                    int wait = f[j] - t%f[j];  // 時刻がf[j]の倍数になるまで待ってから
                    t += wait + c[j];  // c[j]かけて移動
                }
            }
            else {  // 最初の列車がまだ出発していない場合
                t = s[j] + c[j];  // s[j]になるまで待ってからc[j]かけて移動
            }
        }
        ans[i] = t;
    }

    rep(i, n) {
        cout << ans[i] << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
a,v = map(int, input().split())
b,w = map(int, input().split())
t = int(input())

dist = abs(a - b)

if dist == 0:
    print("YES")
    exit()

speed = v - w

if speed <= 0:
    print("NO")
    exit()

able = t * speed

if dist <= able:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 9196
#include<stdio.h>
int main(){
  int a,b,c,d;
  scanf("%d%d%d%d",&a,&b,&c,&d);

  int e,f;
  for(e=1;c>0;e++)
    c-=b;
  for(f=1;a>0;f++)
    a-=d;
  
  if(e>f)puts("No");
  else puts("Yes");
return 0;}

Measured memory_bytes: 1664
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int K = scanner.nextInt();
        String S = scanner.next();

        char[] cha = S.toCharArray();

        if(N==1){
            System.out.println(0);
        }else{
            int score = 0;
            char left = 'n';
            char here = 'n';
            char right = 'n';
            for(int i=0; i<N; i++){
                if(i==0){
                    left = 'n';
                    here = cha[i];
                    right= cha[i+1];
                }else if(i==(N-1)){
                    left = cha[i-1];
                    here = cha[i];
                    right = 'n';
                }else{
                    left = cha[i-1];
                    here = cha[i];
                    right= cha[i+1];
                }
                
                if(here=='L' && left=='L'){
                    score +=1;
                }
                if(here=='R' && right=='R'){
                    score +=1;
                }
            }
    
            for(int i=0; i<K; i++){
                score = Math.min(score +2, N-1);
            }
            System.out.println(score);
        }
    }
}

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

int c[10][10];
int d[10][10];

void dijkstra(int s) {
  for (int i=0; i<10; i++) {
    d[s][i] = 1000;
  }
  d[s][s] = 0;
  bool used[10];
  for (int i=0; i<10; i++) used[i] = false;
  while (true) {
    int v = -1;
    for (int i=0; i<10; i++) {
      if (!used[i] && (v == -1 || d[s][i] < d[s][v])) v = i;
    }
    if (v == -1) {
      break;
    }
    used[v] = true;
    for (int i=0; i<10;i++) {
      d[s][i] = min(d[s][i], d[s][v] + c[v][i]);
    }
  }
}
int main() {
  int h, w;
  cin>>h>>w;
  for (int i=0; i<10; i++) {
    for (int j=0; j<10; j++) {
      cin>>c[i][j];
    }
  }

  for (int i=0; i<10; i++) {
    dijkstra(i);
  }

  int ans = 0;
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      int a;
      cin>>a;
      if (a == -1) {
        continue;
      }
      ans += d[a][1];
    }
  }
  cout<<ans<<endl;

}

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

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int main(){
	int l, r,d;
	cin >> l >> r >> d;
	int c = 0;
	for(int i = l; i <= r; i++){
		if(i%d == 0) c++;
	}
	cout << c << endl;
}


Measured memory_bytes: 3592
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define MAXN 100010

typedef long long ll;

int main() {
    ll N, M;
    cin >> N >> M;
    vector<pair<ll, ll>> shops(N);
    ll a, b;
    for (ll i = 0; i < N; i++) {
        cin >> a >> b;
        shops.push_back({a, b});
    }
    sort(shops.begin(), shops.end());
    ll ans = 0;
    for (auto shop : shops) {
        if (M - shop.second > 0) {
            ans += shop.second * shop.first;
            M -= shop.second;
        } else {
            ans += M * shop.first;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4480
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
 
int main() {
  ios::sync_with_stdio(0); 
  cin.tie(0); 
  
  int w, a, b;
  cin >> w >> a >> b;
  
  int distance = abs(a - b);

  if (distance <= w) cout << 0 << "\n";
  else cout << distance - w << "\n";
}


Measured memory_bytes: 3616
(() -> begin
  n = readline() |> x->parse.(Int,x)
  s = readline()
  dict = Dict([['R',0],['G',0],['B',0]])
  for i in 1:n
    dict[s[i]] += 1
  end
  ans = dict['R'] * dict['G'] * dict['B']
  for i in 1:n-2
    for j in i+1:n-1
      k = 2 * j - i
      if k <= n && s[i] != s[j] && s[j] != s[k] && s[k] != s[i]
        ans -= 1
      end
    end
  end
  println(ans)
end)()


Measured memory_bytes: 223120
#include <bits/stdc++.h>
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;

const double PI = acos(-1);

int main() {
	fastIO;
#ifdef LOCAL
	freopen("input.in", "rt", stdin);
#endif
	int a, b, h, m;
	cin >> a >> b >> h >> m;
	double f = 360.0 / (1.0*12*60);
	double ff = 360/60;
	double angA = (m + h*60) * f;
	double angB = 1.0*m * ff;
	double ang = 0;
	if(angA > angB)
		ang = angA - angB;
	else
		ang = angB - angA;
	cout << sqrt(a*a + b*b - 2*a*b*cos(ang * PI / 180.0));
	return 0;
}


Measured memory_bytes: 4176
s=input()
t=input()
S,T=[0]*(len(s)+1),[0]*(len(t)+1)
for i in range(len(s)):
  if s[i]=="A":
    S[i+1]=S[i]+1
  else:
    S[i+1]=S[i]-1
for i in range(len(t)):
  if t[i]=="A":
    T[i+1]=T[i]+1
  else:
    T[i+1]=T[i]-1
q=int(input())
for i in range(q):
  a,b,c,d=map(int,input().split())
  ss=S[b]-S[a-1]
  tt=T[d]-T[c-1]
  if (ss-tt)%3==0:
    print("YES")
  else:
    print("NO")

Measured memory_bytes: 54988
#include<stdio.h>

int main(){

   int n, temp, i, j, a[100];
   scanf("%d",&n);

   for(i=0;i<n;i++)
   scanf("%d",&a[i]);
   for(i=n-2;i>=0;i--){
      for(j=0;j<=i;j++){
        if(a[j]>a[j+1]){
           temp=a[j];
           a[j]=a[j+1];
           a[j+1]=temp;
        }
      }
   }
      printf("%d",a[n-1]-a[0]);

   return 0;
}


Measured memory_bytes: 128
def f(n):
    ans=1
    for i in range(2,n+1):
        ans=ans*i
    return ans

from math import sqrt
n=int(input())
x=[]
y=[]
for i in range(n):
    a,b=map(int,input().split())
    x.append(a)
    y.append(b)
ans=[]
for i in range(n-1):
    for j in range(i+1,n):
        ans.append(sqrt((x[i]-x[j])**2+(y[i]-y[j])**2))
res=0
for i in range(len(ans)):
    res+=ans[i]*2*f(n-1)
print(res/f(n))

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cstdio>
#define f first
#define s second

using namespace std;

pair <int, pair <int, int> > q[500005];
int n, m, a[500005], ans[500005];
int st[25*100001], used[5000005];
int cmp(pair <int, pair <int, int> > a, pair <int, pair <int, int> > b)
{
    if (a.s.f != b.s.f)
        return a.s.f < b.s.f;
    return a.f < b.f;
}
void update(int v, int l, int r, int x, int d)
{
    if (l == r)
    {
        st[v] = d;
        return;
    }
    int mid = (l + r) / 2;
    if (x <= mid)
        update(v * 2, l, mid, x, d);
    else
        update(v * 2 + 1, mid + 1, r, x, d);
    st[v] = st[v * 2] + st[v * 2 + 1];
}
int Find(int v, int A, int B, int l, int r)
{
    if (l > B || r < A)
        return 0;
    if (A == l && B == r)
        return st[v];
    int mid = (A + B) / 2;
    return Find(v * 2, A, mid, l, min(mid, r)) + Find(v * 2 + 1, mid + 1, B, max(mid + 1, l), r);
}

int main()
{
    scanf("%d", &n);
     scanf("%d", &m);
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);
   
    for (int i = 1; i <= m; i++)
        scanf("%d %d", &q[i].f, &q[i].s.f), q[i].s.s = i;
    sort(q + 1, q + m + 1, cmp);
    int j = 1;
    for (int i = 1; i <= m; i++)
    {
        while(j <= q[i].s.f)
        {
            if (!used[a[j]])
            {
                update(1, 1, n, j, 1);
                used[a[j]] = j;
            }
            else
            {
                update(1, 1, n, used[a[j]], 0);
                update(1, 1, n, j, 1);
                used[a[j]] = j;
            }
            j++;
        }
        ans[q[i].s.s] = Find(1, 1, n, q[i].f, q[i].s.f);
    }
    for (int i = 1; i <= m; i++)
        printf("%d\n", ans[i]);

    return 0;
}

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

int main(){

    int n;
    cin >> n;
    vector<int> a(n+1,0);
    vector<int> x1(n+1,0);
    vector<int> x2(n+1,0);


    for(int i = 1;i < n+1;i++){
        cin >> a[i] >> x1[i] >> x2[i];
    }

    for(int i = 0;i < n;i++){
        int t = a[i+1]-a[i];
        int d = abs(x1[i+1]-x1[i])+abs(x2[i+1]-x2[i]);
        if(t<d){
            cout << "No" << endl;
            return 0;
        }else{

            if(t%2 != d%2){
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;


    return 0;
}

Measured memory_bytes: 1408
#[allow(unused_imports)]
use std::collections::VecDeque;
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::HashMap;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_variables)]
        #[allow(unused_mut)]
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("parse error")
    };
}

fn main() {
    input!{
        a: i64,
        b: i64,
        _c: i64,
        k: i64,
    }
    let ans = cmp::min(a, k);
    let v = cmp::max(k - a - b, 0);
    println!("{}", ans - v);
}


Measured memory_bytes: 2128
#include <iostream>
#include <set>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a[111111],sum,mx,cnt;
multiset<ll>s;
int main()
{
	cin>>n;
	for(ll i=1;i<=n;i++)
		scanf("%lld",&a[i]),s.insert(a[i]);
	for(ll i=1;i<=n;i++)
	{
		sum=cnt=0;
		while(!s.empty()&&*s.begin()<=a[i])
			sum+=*s.begin(),cnt++,s.erase(s.begin());
		sum+=s.size()*a[i];
		cnt+=s.size();
		if(mx<a[i])
			printf("%lld\n",sum-mx*cnt);
		else
			printf("0\n");
		mx=max(a[i],mx);
	}
}


Measured memory_bytes: 6528
import sys
 
#ff = open("test.txt", "r")
ff = sys.stdin
 
while True :
    a, b = map(int, ff.readline().split())
    if (a == 0) & (b == 0) :
        break
 
    if a < b : print(a, b)
    else : print(b, a)
 
exit()

Measured memory_bytes: 7848
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <iostream>
#include <queue>

using namespace std;

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64; // 9e18
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

const double PI = 3.141592653589793238463;
const int MAXN = 1000500;
const int MAXVALUE = 1000000500;
const long double EPS = 1e-7;
const i64 INF = 1e18;
i64 mod = 1e9 + 7;


i64 T, n, m, k;
//vector <vector<i64>> a;
//vector <i64> a;
//vector <i64> b;
vector <i64> dp;


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(16);

    string s;
    cin >> s;

    for (i64 i = 0; i < 3; ++i) {
        cout << s[i];

    }

    cout << endl;


    return 0;
}

Measured memory_bytes: 3044
N, K = map(int, input().split())
S = input()

tp = [0, 0]
for i in range(1, N):
  if S[i] != S[i - 1]:
    tp.append(i)
tp.extend([N, N])
    
ranges = []
if S[0] == '1':
  l = 1
else:
  l = 0

r = l + 2 * K + 1
while r < len(tp):
  ranges.append(tp[r] - tp[l])
  l += 2
  r += 2
  
if len(ranges) == 0:
  ranges.append(N)
  
print(max(ranges))

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

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

using namespace std;

uint64_t ary[5000]__attribute__((aligned(32)));
int diff[5000]__attribute__((aligned(32)));
int inf[5000]__attribute__((aligned(32)));
int l1,l2,n;

int _mm_popcnt_u64(uint64_t x) {
  return __builtin_popcountll(x);
}

void update(int i) {
  if (i != l1) {
    diff[i] = 2 * _mm_popcnt_u64(ary[i]) - 64;
    int cnt = 0;
    inf[i] = 0;
    REP(j,64) {
      cnt += ((ary[i] >> j) & 1) ? 1 : -1;
      inf[i] = min(inf[i], cnt);
    }
  } else {
    diff[l1] = 2 * _mm_popcnt_u64(ary[l1]) - (n % 64);
    int cnt = 0;
    inf[l1] = 0;
    REP(j,n % 64) {
      cnt += ((ary[l1] >> j) & 1) ? 1 : -1;
      inf[l1] = min(inf[l1], cnt);
    }
  }
}

int main() {
  int q;
  cin>>n>>q;
  string s;
  cin>>s;
  REP(i,n){
    if(s[i]=='(')
      ary[i/64] |= UINT64_C(1) << (i % 64);
  }
  l1 = n/64;
  l2 = (n+63)/64;
  REP(i,l1){
    diff[i] = 2 * _mm_popcnt_u64(ary[i]) - 64;
  }
  if (l1 != l2) diff[l1] = 2 * _mm_popcnt_u64(ary[l1]) - (n % 64);
  REP(i,l1) {
    int cnt = 0;
    REP(j,64) {
      cnt += ((ary[i] >> j) & 1) ? 1 : -1;
      inf[i] = min(inf[i], cnt);
    }
  }
  if (l1 != l2) {
    int cnt = 0;
    REP(j,n % 64) {
      cnt += ((ary[l1] >> j) & 1) ? 1 : -1;
      inf[l1] = min(inf[l1], cnt);
    }
  }
  REP(cnt1,q){
    int p;
    cin>>p;
    --p;
    if ((ary[p/64] >> (p % 64)) & 1) {
      ary[p/64] ^= UINT64_C(1) << (p % 64);
      update(p/64);
      int pos = -1;
      REP(j,l1) {
        if (diff[j] != 64) {
          pos = j * 64;
          REP(k,64) {
            if (!((ary[j] >> k) & 1)) {
              pos += k;
              break;
            }
          }
          break;
        }
      }
      if (pos < 0) {
        pos = l1 * 64;
        REP(j,n%64) {
          if (!((ary[l1] >> j) & 1)) {
            pos += j;
            break;
          }
        }
      }
      cout << pos+1 << endl;
      ary[pos/64] ^= UINT64_C(1) << (pos % 64);
      update(pos/64);
    } else {
      ary[p/64] ^= UINT64_C(1) << (p % 64);
      update(p/64);
      int last1 = 0;
      int last1sum = 0;
      int sum = 0;
      REP(i,l1) {
        if (sum + inf[i] <= 1) {
          last1 = i;
          last1sum = sum;
        }
        sum += diff[i];
      }
      if (l1 != l2) {
        if (sum + inf[l1] <= 1) {
          last1 = l1;
          last1sum = sum;
        }
      }
      int pos = 0;
      if (last1 != l1) {
        int last1_s = 0;
        REP(i,64) {
          last1sum += ((ary[last1] >> i) & 1) ? 1 : -1;
          if (last1sum <= 1) last1_s = i;
        }
        pos = last1 * 64 + last1_s + 1;
      } else {
        int last1_s = 0;
        REP(i,n%64) {
          last1sum += ((ary[last1] >> i) & 1) ? 1 : -1;
          if (last1sum <= 1) last1_s = i;
        }
        pos = last1 * 64 + last1_s + 1;
      }
      cout << pos+1 << endl;
      ary[pos/64] ^= UINT64_C(1) << (pos % 64);
      update(pos/64);
    }
  }
  return 0;
}

Measured memory_bytes: 1680
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

int main(){
    string S;cin>>S;
    int N=S.size();
    for(int i=0;i<N;i++){
        cout<<'x';
    }
    return 0;
}

Measured memory_bytes: 256
from collections import Counter
n,k = map(int,input().split())
a = [int(i) for i in input().split()]
counts = dict(Counter(a))
counts = list(counts.values())
counts.sort()
count = 0

dev = len(counts)-k
for i in range(dev):
    count += counts[i]
        
print(count)


Measured memory_bytes: 111312
/*
      author : nishi5451
      created: 11.08.2020 20:51:26
*/

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


int main(){
    int n,k;
    cin >> n >> k;
    if(n%k==0) cout << 0 << endl;
    else cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 3636
import heapq
from itertools import permutations
n, m, r = map(int, input().split())
R = list(map(lambda x: int(x)-1, input().split()))
edges = [[]for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append((c, b))
    edges[b].append((c, a))


def dijkstra(init_v):
    next_v = [(0, init_v)]
    INF = 10**18
    dist = [INF]*n
    dist[init_v] = 0
    while next_v:
        d, v = heapq.heappop(next_v)
        if dist[v] < d:
            continue
        for d, v2 in edges[v]:
            if dist[v2] <= dist[v]+d:
                continue
            dist[v2] = dist[v]+d
            heapq.heappush(next_v, (dist[v2], v2))
    return dist


dists = []
for x in R:
    dist = dijkstra(x)
    dists.append(dist)

INF = 10**18
ans = INF
for subset in permutations(range(r)):
    d = 0
    for v, v2 in zip(subset, subset[1:]):
        d += dists[v][R[v2]]
    if d < ans:
        ans = d

print(ans)



Measured memory_bytes: 73644
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD=2019;
const long double PI=3.14159265358979;

long long modpow(long long x,long long y,long long z){
  long long ans=1;
  while(y>0){
    if(y&1){
      ans*=x%z;
    }
    x*=x%z;
    x%=z;
    ans%=z;
    y>>=1;
  }
  return ans;
}


int main() {
  string S;
  cin>>S;
  ll s=S.size(),ans=0;
  vector<ll> a(s+1);
  a[0]=0;
  for(int i=1;i<=s;i++){
    a[i]=a[i-1]+stoi(S.substr(i-1,1))*modpow(10,s-i,MOD);
    a[i]%=MOD;
  }
  sort(a.begin(),a.end());
  vector<ll> A(0);
  ll c=1;
  for(int i=0;i<=s;i++){
    //ll c=1;
    if(i==s||a[i]!=a[i+1]){
      A.push_back(c);
      c=1;
    }
    else{
      c++;
      //cout<<121;
    }
  }
  for(int i=0;i<A.size();i++){
    ans+=A[i]*(A[i]-1)/2;
  }
  //cout<<modC(2,2,12);
    
  cout<<ans;
}

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

ll fx[] = {0, 0, 0, 1, -1, 1, 1, -1, -1};
ll fy[] = {0, 1, -1, 0, 0, 1, -1, -1, +1};
map< ll, bool >mp;
vector<ll>a, b, v;
ll ar[ 2000005 ], br[ 2000005 ], ans[ 200005 ], per[ 2000005 ];

ll bs(ll key, ll n)
{
    ll l = 0, r = n - 1;

    while( l <= r )
    {
        ll m = ( l + r ) / 2;
        if( ar[ m ] >= key )
        {
            r = m-1;
        }
        else
        {
            l = m+1;
        }
    }
    return l;
}

string s = "";
int main()
{
    ll n, m, k;
    for(char ch = 'A';  ch <= 'Z'; ch++) s += ch;
    string ss ;
    cin>>k>>ss ;
    for(int i = 0; i < ss.size(); i++)
    {
        cout<<s[(ss[ i ] - 'A' + k) % 26] ;
    }
    puts("") ;
    return 0;
}
/*7 5
12 444 876 1309 1740 2174 2604
*/


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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }


int main() {
    int n,k; cin >> n >> k;
    if(500*n >= k) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
MOD = 10 ** 9 + 7

N, K = map(int, input().split())

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

totalMin = [0] * N
afterMin = [0] * N

def addAll(n):
  return (n * (n + 1) // 2) % MOD


for i in range(N):
  for j in range(N):
    if A[i] > A[j]:
      if i < j:
        afterMin[i] += 1
      totalMin[i] += 1

total = 0
for i in range(N):
  total = (total + afterMin[i] * K) % MOD
  total = (total + totalMin[i] * addAll(K - 1)) % MOD

print(total)


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

using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define vi vector<int>

#define ll long long int

int ctoi(char c) {return c-'0';}
int ord(char c) {return c-'a';}
int len(string s) {return s.length();}
int itoc(int i) {return i+'a';}


int main() {
int N;
cin>>N;
set<int> s;
for(int i=0;i<N;i++) {
    int x;
    cin>>x;
    s.insert(x);
}
cout<<(s.size()==N ? "YES" : "NO")<<endl;
return 0;
}


Measured memory_bytes: 9600
# 方針〜
# Dが10以下なのがポイント
# 全ての部分集合に対して「この集合を全問解いた場合、総合スコアをG点以上にするために何問解くか」をビット全探索すれば良い。
# Dividing Chocolate (ABC159-E)と似たようなもの

# なお、「この集合を全問解いた場合、総合スコアをG点以上にするために何問解くか」を解くときには
# 得点の高い方からGreedyだが、途中でコンプリートした時のボーナスを無視しても正しい答えは出せる。
# それ自体のスコアは間違いになるが、問題数が増える方向に間違うし、正しい部分集合のときには正しい問題数が得られるので。
# 今回は上記の方法でやってみる。

d, goal = list(map(int, input().split()))
problems = [list(map(int, input().split())) for _ in range(d)]

ans = 10 ** 6 * 10 * 2
for completed in range(2 ** d):
    
    point_all = 0
    num_problem = 0

    # 最下位のdigitが100点問題
    for point in range(d):
        if (completed & 2 ** point) > 0:
            point_all += 100 * (point+1) * problems[point][0]
            point_all += problems[point][1]
            num_problem += problems[point][0]
    
    if point_all < goal:
        for point in reversed(range(d)):
            if (completed & 2 ** point) == 0:
                p = (100 * (point+1))
                n = (goal - point_all + p - 1) // p
                n = min(problems[point][0], n)

                point_all += n * p  # ボーナス点は無視する
                num_problem += n

                if point_all >= goal:
                    break

    # 目標点数を達成しているとは限らないことに注意 条件に目標達成を入れる
    if point_all >= goal and num_problem < ans:
        ans = num_problem

print(ans)


Measured memory_bytes: 9216
import java.util.Scanner;

public class Main {

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

	public void run() {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long a = x/500;
		x = x % 500;
		long b = x/5;
		System.out.println(a*1000 + b*5);
		sc.close();
	}
}


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

using namespace std;
using pii = pair<int, int>;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<pii> A(N);
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    A[i] = make_pair(a, i);
  }
  sort(A.begin(), A.end());
  for (int i = 0; i < N; i++) {
    cout << A[i].second + 1 << (i == N - 1 ? '\n' : ' ');
  }
  return 0;
}


Measured memory_bytes: 1664
n, k = list(map(int, input().split()))
kl = [[] for _ in range(k)]
for i in range(k):
    a = int(input())
    d = list(map(int, input().split()))
    kl[i].append(d)
f1 = set(sum(sum(kl, []), []))
r = set(i for i in range(1, n + 1))
print(len(r - f1))


Measured memory_bytes: 9144
def check(x, y)
  2.times do |z|
    4.times do
      return true if x == y
      a, b, c, d, e, f  = x
      x = z.zero? ? [e, a, c, d, f, b] : [d, b, a, f, e, c]
      c = x
      4.times do
        i, j, k, l, m, n = c
        c = [i, k, m, j, l, n]
        return true if c == y
      end
    end
  end
  false
end

ar = $<.map{|e| e.chomp.split}.drop(1)
ar.size.times do |x|
  (x+1).upto(ar.size - 1) do |y|
    (puts 'No')^exit if check(ar[x], ar[y])
  end
end
puts 'Yes'

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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int Case(1), n;
	while (cin >> n, n) {
		if (n == 1) {
			cout << "Case " << Case++ << ":" << endl;
			printf("  1\n");
			continue;
		}
		vector<vector<int>>v(n, vector<int>(n));
		int nowi(0), nowj(1), pasti(0), pastj(0), cnt(1);
		v[pasti][pasti] = cnt++;
		v[nowi][nowj] = cnt++;
		while (nowi!=n-1||nowj!=n-1) {
			if (nowi == 0 && pasti == 0 && pastj+1 == nowj) {
				pasti = nowi;
				pastj = nowj;
				nowi++;
				nowj--;
				v[nowi][nowj] = cnt++;
			}
			else if (nowi == 0 && pasti == 1 && pastj + 1 == nowj) {
				if (nowj != n - 1) {
					pasti = nowi;
					pastj = nowj;
					nowj++;
					v[nowi][nowj] = cnt++;
				}
				else {
					pasti = nowi;
					pastj = nowj;
					nowi++;
					v[nowi][nowj] = cnt++;
				}
			}
			else if (nowj == 0 && pastj == 0 && pasti + 1 == nowi) {
				pasti = nowi;
				pastj = nowj;
				nowi--;
				nowj++;
				v[nowi][nowj] = cnt++;
			}
			else if (nowj == 0 && pastj == 1 && pasti + 1 == nowi) {
				if (nowi != n - 1) {
					pasti = nowi;
					pastj = nowj;
					nowi++;
					v[nowi][nowj] = cnt++;
				}
				else {
					pasti = nowi;
					pastj = nowj;
					nowj++;
					v[nowi][nowj] = cnt++;
				}
			}
			else if (nowi == n - 1 && pasti == n - 1 && pastj + 1 == nowj) {
				pasti = nowi;
				pastj = nowj;
				nowi--;
				nowj++;
				v[nowi][nowj] = cnt++;
			}
			else if (nowi == n - 1 && pasti == nowi - 1 && nowj + 1 == pastj) {
				pasti = nowi;
				pastj = nowj;
				nowj++;
				v[nowi][nowj] = cnt++;
			}
			else if (nowj == n - 1 && pastj == n - 1 && pasti + 1 == nowi) {
				pasti = nowi;
				pastj = nowj;
				nowi++;
				nowj--;
				v[nowi][nowj] = cnt++;
			}
			else if (nowj == n - 1 && pastj == nowj - 1 && pasti == nowi + 1) {
				pasti = nowi;
				pastj = nowj;
				nowi++;
				v[nowi][nowj] = cnt++;
			}

			else if (nowi == pasti - 1 && nowj == pastj + 1) {
				pasti = nowi;
				pastj = nowj;
				nowi--;
				nowj++;
				v[nowi][nowj] = cnt++;
			}
			else if (nowi == pasti + 1 && nowj == pastj - 1) {
				pasti = nowi;
				pastj = nowj;
				nowi++;
				nowj--;
				v[nowi][nowj] = cnt++;
			}

		}
		cout << "Case " << Case++ << ":" << endl;
		rep(i, 0, n) {
			rep(j, 0, n) {
				printf("%3d", v[i][j]);
			}
			cout << endl;
		}


	}
	return 0;
}

Measured memory_bytes: 3188
import scala.io.StdIn._

object Main extends App {


  val n = readInt()

  def solve() = {
    val lim = 100
    val s = for {
      x <- 1 to lim
      y <- 1 to lim
      z <- 1 to lim
    } yield {
      x*x + y*y + z*z + x*y + y*z + z*x
    }
    val default = Map.empty[Int, Int]
    val numAndCntMap = s.foldLeft(default) { (acc, num) =>
      acc.updated(num, acc.getOrElse(num, 0)+1)
    }
    (1 to n).map { i =>
      numAndCntMap.getOrElse(i, 0)
    }.mkString("\n")
  }

  println(solve())

}



Measured memory_bytes: 88572
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll t;
ll ret = 0;
vl A;
vl B;
vl C;

void input() {
  IN(N);
  REP(i, N) {
    IN(t);
    A.pb(t);
  }
  REP(i, N) {
    IN(t);
    B.pb(t);
  }
  REP(i, N-1) {
    IN(t);
    C.pb(t);
  }
}

void solve() {
  ll a, b, c;
  ll pre = -1;
  REP(i, N) {
    ll a = A[i];
    ll b = B[a-1];
    ll c = (a-1 == pre)?C[a-1-1]:0;
    // DEBUG(b);
    // DEBUG(c);
    // LN();
    ret += b + c;
    pre = a;
  }
  PRINT(ret);
}

int main(void){
  input();
  solve();
}


Measured memory_bytes: 256