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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
char N[200];
ll K;
ll dp[200][10][4];
ll i,j,k;
ll calc(ll ii,ll kk,bool c){
    if(kk==K)
        return 1;
    if(!N[ii])
        return 0;
    if(dp[ii][kk][c]!=-1){
        return dp[ii][kk][c];
    }
    ll i = 0;
    ll ret = 0;
    fornum(i,0,10){
        if(!c&&i>N[ii]-'0')
            break;
        ret += calc(ii + 1, kk + (i != 0), c || i != N[ii] - '0');
    }
    return dp[ii][kk][c] = ret;
}
int main(){
    scanf("%s%lld", N,&K);
    fornum(i,0,111){
        fornum(j,0,5){
            dp[i][j][0] = dp[i][j][1] = -1;
        }
    }
    printf("%lld", calc(0, 0, 0));

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,x,i;
	scanf("%d", &n);
	for(i=1; i<=n; i++)
	{
		x=i*1.08;
		if(x==n)
		{
			printf("%d\n", i);
			break;
		}
		if(i==n)
		printf(":(\n");
	}
	
	return 0;
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <cstring>
using namespace std;
#define sci(n) scanf("%lld", &(n))
#define scd(n) scanf("%Ld", &(n))
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> pll;
int main(void)
{
	LL n; sci(n);
	for (int i = 0; i < n; i++) {
		LL a; sci(a); if (a % 2) {
			printf("first"); return 0;
		}
	}
	printf("second");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<stack>
#include<iostream>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define vec(a) vector<int>a
using namespace std;


int main()
{
#ifndef ONLINE_JUDGE
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
#endif
	fastio
	string str;
	ll n,i,j,k,l;
	cin>>n;
	set<string> se;
	while(n--)
	{
		cin>>str;
		se.insert(str);
	}
	cout<<se.size()<<"\n";
	return 0;
}
	

Measured memory_bytes: 19184
import Data.List

main = do
  li <- getLine
  let [a,b,x] = map read $ words li
  let ans = compute a b x
  print ans

{-

       ...|
  .....   | <= a
 . t'     |
-----b----+
かなり傾くような場合
a * b * a / 2 >= x
のとき、a * b * b tan t' / 2 = x, t' = atan2 2x abb, t = pi/2-t' のとき tan t' = 1/tan t

角を超える場合
    ------+
   .      |
  .       | a
 . t'     |
-----b----+
aab - a* a* a*tan t/2 = x, tan t = 2(aab-x)/aaa
-}

compute :: Double -> Double -> Double -> Double
compute a b x
  | x == aab = 0
  | 2*x <= aab = atan2 (a*b*b) (2*x) * 180 / pi
  | True = atan2 ((aab-x)*2) (a*a*a) * 180 / pi
  where
    aab = a * a * b

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

using namespace std;
typedef long ll;


int main(){
   ll a, b, c;
   cin>>a>>b>>c;
   ll k;
   cin>>k;
    ll ans = a;
   if(k<=a){
       ans = k;
       cout<<ans<<endl;
       return 0;
   } 
   k = k-a;
   if(k<=b){
       cout<<ans<<endl;
       return 0;
   }
   k = k-b;

   ans = ans - k;
   cout<<ans<<endl;




    return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long n, d;
	cin>>n>>d;
	long long x, y;
	long long ans=0;
	for (int i=1; i<=n; i++) {
		cin>>x>>y;
		if (sqrt(x*x+y*y)<=d) {
			ans++;
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 3616
//
/*==========================================================*/
/*    Template ver 2017-0720    |    Created by JollyBee    */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
const double EPS=(double)1e-9;
const double PI=(double)acos(-1.0);
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define FOR(i,n) for(int i=0;i<n;i++)
#define REPP(i,l,r,c) for(int i=l;i<=r;i+=c)
#define REP(i,l,r) REPP(i,l,r,1)
#define FORD(i,n) for(int i=n-1;i>=0;i--)
#define REVV(i,l,r,c) for(int i=l;i>=r;i-=c)
#define REV(i,l,r) REVV(i,l,r,1)
//random
int irand(int lo, int hi){
    return (((double)rand())/(RAND_MAX+1.0)) * (hi-lo+1) + lo;
}
//ll to string
string toString(ll x) {
    stringstream ss;
    ss << x;
    return ss.str();
}
//string to ll
ll toNumber(string S) {
    ll ret;
    sscanf(S.c_str(),"%lld",&ret);
    return ret;
}
// std::fill(start, end, value);
// for(auto it: DS){}

const int INF=(int)2e9;
const ll MOD=(ll)1e9+7;
/*==========================================================*/
/*                     END OF TEMPLATE                      */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/

ll dp[2][55][2505];

int main(){
    // reset
    FOR(j,53) FOR(k,2503) dp[0][j][k] = 0; dp[0][0][0] = 1;
    // input
    int n,a; scanf("%d %d", &n, &a);
    REP(i,1,n){
        int num; scanf("%d", &num);
        //
        int idx = i % 2;
        int prev = (i-1) % 2;
        //
        REP(j,0,50) REV(k,2500,0){
            dp[idx][j][k] = dp[prev][j][k];
            if(j > 0 && k >= num) dp[idx][j][k] += dp[prev][j-1][k-num];
        }
    }
    // count
    ll res = 0; REP(i,1,n) res += dp[n%2][i][i*a];
    // print
    printf("%lld\n", res);
    return 0;
}


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

int main(){
    char b;
    cin>>b;
    if(b=='A'){
        cout<<"T"<<endl;
    }else if(b=='C'){
        cout<<"G"<<endl;
    }else if(b=='G'){
        cout<<"C"<<endl;
    }else if(b=='T'){
        cout<<"A"<<endl;
    }
    return 0;
}

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

#define ll long long
#define inf (ll)1e15
ll dp[405][405];

ll sum(const vector<ll>& v,int s,int e){
    ll ans = 0 ;
    for(int i=s;i<=e;i++){
        ans += v[i];
    }
    return ans ;
}

ll slimes(const vector<ll>& v,int s,int e) {
	if(s>=e)
		return 0;
	if(dp[s][e] != -1)
		return dp[s][e];

	ll ans = inf;

	for(int k=s;k<e;k++) {
		ll currentSum = sum(v,s,k) + sum(v,k+1,e);
		ans = min(ans, currentSum + slimes(v,s,k) + slimes(v,k+1,e));
	}

	return dp[s][e] = ans;
}

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

    memset(dp,-1,sizeof dp);

    cout << slimes(v,0,n-1) << endl;

    return 0;
}

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

#include <iostream>
#include <vector>
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using p = pair<int,int>;//<key,value>


int main() {
int n;
cin>>n;
vector<int> a(n);
rep(i,n)cin>>a[i];
vector<int> b(n);
rep(i,n)cin>>b[i];
vector<int> c(n-1);
rep(i,n)cin>>c[i];
rep(i,n) a[i]--;
int sum=0;
rep(i,n){
sum+=b[a[i]];}
rep(i,n-1){
if(a[i+1]==a[i]+1){
	sum+=c[a[i]];
}}
cout<<sum<<endl;
return 0;
}







Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int i,a;
  i = 0;
  a = 1;
  while(1)
    {
      i++;
      scanf("%d",&a);
      if (a == 0){break;};
      printf("Case ");
      printf("%d",i);
      printf(": ");
      printf("%d",a);
      printf("\n");
    };
  return 0;
}

Measured memory_bytes: 1032
/*
<equation> ::= <formula> "=" <formula>
<formula>  ::= "T" | "F" |
"a" | "b" | "c" | "d" | "e" | "f" |
"g" | "h" | "i" | "j" | "k" |
"-" <formula> |
"(" <formula> "*" <formula> ")" |
"(" <formula> "+" <formula> ")" |
"(" <formula> "->" <formula> ")"
*/

#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define F 0
#define T !F

vector <int> a(11);

int equation(string& s, int& i);
int formula(string& s, int& i);

int main(){
	while(1){
		string str;
		cin >> str;
		if(str == "#")
			break;
		
		int ans = T;
		for(int bit = 0; bit < 2048; bit++){
			for(int i = 0; i < 11; i++){
				if(bit >> i & 1)
					a[i] = T;
				else
					a[i] = F;
			}
			int j = 0;
			int result = equation(str, j);
			if(result == F)
				ans = F;
		}
		
		if(ans == T)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	
	
	return 0;
}

int equation(string& s, int& i){
	int val = formula(s, i);
	i++;
	int val2 = formula(s, i);
	
	if(val == T && val2 == T || val == F && val2 == F)
		return T;
	else
		return F;
}

int formula(string& s, int& i){
	if(s[i] == 'a'){
		i++;
		return a[0];
	}
	else if(s[i] == 'b'){
		i++;
		return a[1];
	}
	else if(s[i] == 'c'){
		i++;
		return a[2];
	}
	else if(s[i] == 'd'){
		i++;
		return a[3];
	}
	else if(s[i] == 'e'){
		i++;
		return a[4];
	}
	else if(s[i] == 'f'){
		i++;
		return a[5];
	}
	else if(s[i] == 'g'){
		i++;
		return a[6];
	}
	else if(s[i] == 'h'){
		i++;
		return a[7];
	}
	else if(s[i] == 'i'){
		i++;
		return a[8];
	}
	else if(s[i] == 'j'){
		i++;
		return a[9];
	}
	else if(s[i] == 'k'){
		i++;
		return a[10];
	}
	else if(s[i] == 'T'){
		i++;
		return T;
	}
	else if(s[i] == 'F'){
		i++;
		return F;
	}
	else if(s[i] == '-'){
		i++;
		int val = formula(s, i);
		return !val;
	}
	else{
		i++;
		int val = formula(s, i);
		char op = s[i];
		if(op == '-')
			i += 2;
		else
			i++;
		int val2 = formula(s, i);
		
		i++;
		if(op == '*')
			return val && val2;
		else if(op == '+')
			return val || val2;
		else{
			if(val == T && val2 == F)
				return F;
			else
				return T;
		}
	}
}

Measured memory_bytes: 1232
#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: 85276
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int INF = 2e9;

void dfs(int x, int bef, int dp[], const int n, const vector<int> &A, const vector<vector<int>> &T, int ans[]) {
  int *p = lower_bound(dp ,dp+n+1, A[x]);
  int tmp = *p;
  *p = min(tmp, A[x]);
  ans[x] = lower_bound(dp ,dp+n+1, INF) - dp;

  for (auto t: T[x]) {
    if (t == bef) continue;

    dfs(t, x, dp, n, A, T, ans);
  }
  *p = tmp;

  return;
}

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

  vector<int> A(n);
  for (int i = 0; i < n; i++) cin >> A[i];
  
  vector<vector<int>> T(n);
  
  for (int i = 0; i < n - 1; i ++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    T[u].push_back(v);
    T[v].push_back(u);
  }

  int dp[n+1];
  fill(dp, dp+n+1, INF);
  dp[0] = A[0];

  int ans[n];

  dfs(0, -1, dp, n ,A, T, ans);

  for (int i = 0; i < n; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 39232
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


n = int(input())
ab = [[int(x) for x in input().split()] for _ in range(n-1)] 
graph = [[] for _ in range(n+1)]

for a, b in ab:
    graph[a].append(b)
    graph[b].append(a)


root = 1
parent = [0] * (n+1) 
order = [] 
stack = [root]
while stack:
    x = stack.pop()
    order.append(x)
    for y in graph[x]:
        if y == parent[x]:
            continue
        parent[y] = x
        stack.append(y)

color = [-1] * (n+1)
for x in order:
    ng = color[x]
    c = 1
    for y in graph[x]:
        if y == parent[x]:
            continue
        if c == ng:
            c += 1
        color[y] = c
        c += 1


ans = [] 
for a, b in ab:
    if parent[a] == b:
        ans.append(color[a])
    else:
        ans.append(color[b])

k = max(ans)
print(k)
for x in ans:
    print(x)

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

total = ((m)+(m+n-1))*n/2

min_abs = 101
min = 0
for i in range(n):
  now = abs(m + i)
  if now < min_abs:
    min_abs = now
    min = m + i

if total > 0:
    if min > 0:
        min_total = int(total - min)
    else:
        min_total = int(total + min)
else:
    if min > 0:
        min_total = int(total + min)
    else:
        min_total = int(total - min)
    

print(min_total)
    

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

int main(void) {
    string S;
    int64_t K;
    int pos = 0;
    int ans;
    cin >> S >> K;

    // 2が5000 * 10^12 => 5 * 10^15日後には
   
    ans = 1;
    for(int i=0;i<K;i++) {
        if(S[i] != '1') {
            ans = S[i]-'0';
            break;
        }     
    }

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


Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <stack>
#include <queue> // priority_queue も入ってる
#include <set>   // 要素数は size() で取得 multisetもある
#include <map>
#include <array> // sizeはコンパイル時定数で固定
#include <vector>
#include <numeric>   // accumulate, gcd
#include <algorithm> // count_ifに必要
#include <iomanip>   // cout << setprecision(15) << x で小数の出力精度を指定
#include <tuple>
#include <utility> //pair
#include <cmath>

using namespace std;
// 問題が起こるまでintは使用禁止2020-04-13
using ll = long long;

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

template <class InputIterator, class T>
bool contains_itr(InputIterator iterator, const T &value)
{
    if (find(iterator.begin(), iterator.end(), value) == iterator.end())
        return false;
    else
        return true;
}

template <class T>
bool contains_set(set<T> st, const T &value)
{
    if (st.find(value) == st.end())
    {
        return false;
    }
    else
    {
        return true;
    }
}

template <class InputIterator>
auto sum(InputIterator iterator)
{
    return accumulate(iterator.begin(), iterator.end(), 0);
}

// endは排他的(exclusive)なので注意
vector<ll> range(ll begin, ll end)
{
    vector<ll> result;
    for (ll i = begin; i < end; ++i)
    {
        result.push_back(i);
    }
    return result;
}

// =========ここまでテンプレ============

int main()
{
    ll a;
    string b;
    cin >> a;
    cin >> b;
    b.replace(b.size() - 3, 1, "");
    ll c = stoll(b);
    ll result100 = a * c;
    cout << result100 / 100 << endl;
}

Measured memory_bytes: 3168
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

a, b = readmi()

cnt = a
count = 1
if b == 1:
    print(0)
    exit()
while(1):
    if cnt >= b:
        break
    cnt -= 1
    cnt += a
    count += 1
print(count)

Measured memory_bytes: 6480
#include<stdio.h>
#include<iostream>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
    int a,b,c,d;
    while(cin>>a>>b>>c>>d){
        cout<<min(a,b)+min(c,d)<<endl;
    }
    return 0;

}


Measured memory_bytes: 256
import bisect
a = input()
b = input()
dp = [[] for _ in range(26)]
# print(dp)

for e,i in enumerate(a):
    t=ord(i)-ord('a')
    dp[t].append(e)
# print(dp)
f = 0
ans = 0
c = 0 
for e,i in enumerate(b):
    t = ord(i)-ord('a')
    if not dp[t]:
        print(-1)
        exit()
    i_i = bisect.bisect_left(dp[t],f)
    if len(dp[t])<=i_i:
        F = dp[t][0] 
        ans+=F+1
        c +=1
    else:
        F = dp[t][i_i]
        ans += F-f+1
    f = F+1
    # print(dp[t],f,F,ans)
    if e == len(b)-1: ans = c*len(a)+ F+1
print(ans)

Measured memory_bytes: 7764
import java.util.*;
import java.util.stream.Collectors;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        sc.nextLine();
        String inArr = sc.nextLine();
        List<Integer> list = Arrays.asList(inArr.split(" ")).stream().map(x -> Integer.parseInt(x)).collect(Collectors.toList());

        int sum = list.stream().mapToInt(x->x).sum();

        if(list.stream().filter(x -> {
            int hoge = 4 * m;
            double fuga = (double)sum / (double)hoge;
            if(x < fuga){
                return false;
            }else{
                return true;
            }

        }).count() >= m){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }


    }
}


Measured memory_bytes: 28624
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	string S;
	cin >> S;

	vector<int> R, G, B;
	for (int i = 0; i < N; i++) {
		if (S[i] == 'R') R.emplace_back(i);
		if (S[i] == 'G') G.emplace_back(i);
		if (S[i] == 'B') B.emplace_back(i);
	}

	lint ans = 1LL * R.size() * G.size() * B.size();
	for (int i = 0; i < R.size(); i++) {

		vector<int> exist(8001);

		for (int j = 0; j < G.size(); j++) {
			exist[G[j] - R[i] + 4000] = 1;
		}

		for (int j = 0; j < B.size(); j++) {
			if (exist[R[i] - B[j] + 4000]) ans--;
			if ((B[j] - R[i]) % 2 == 0 && exist[(B[j] - R[i]) / 2 + 4000]) ans--;
			if (0 <= (B[j] - R[i]) * 2 + 4000 && (B[j] - R[i]) * 2 + 4000 <= 8000 && exist[(B[j] - R[i]) * 2 + 4000]) ans--;
		}

	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  if (count(S.begin(),S.end(),'W') == S.length() || count(S.begin(),S.end(),'B') == S.length()) {
    cout << 0;
  } else {
    int answer;
    string reversi;
    if (S[0] == 'W') {
      reversi.push_back('B');
      for (int i = S.find('B')+1; i < S.length(); i++) {
        if (S[i] != reversi.back()) {
          reversi.push_back(S[i]);
        }
      }
    } else {
      reversi.push_back('W');
      for (int i = S.find('W')+1; i < S.length(); i++) {
        if (S[i] != reversi.back()) {
          reversi.push_back(S[i]);
        }
      }
    }
    answer = reversi.length();
    reversi.clear();
    if (S.back() == 'B') {
      reversi.push_back('W');
      for (int i = S.rfind('W')-1; i+1; i--) {
        if (S[i] != reversi.back()) {
          reversi.push_back(S[i]);
        }
      }
    } else {
      reversi.push_back('B');
      for (int i = S.rfind('B')-1; i+1; i--) {
        if (S[i] != reversi.back()) {
          reversi.push_back(S[i]);
        }
      }
    }
    answer = min(answer,(int)reversi.length());
    cout << answer;
  }
}

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

string s, tmp;
int size_, ans, msize;

bool check(string t) {
    int si = t.size();

    for (int i = 0; i < si - 1; ++i) {
        if (t[i] != t[i + 1]) {
            return false;
        }
    }

    return true;
}

int main() {
    cin >> s;

    size_ = s.size();

    int temp = 0;
    ans = 999;
    string sub = s;

    for (int k = 0; k < 26; ++k) {
        temp = 0;
        s = sub;
        while (!check(s)) {
            temp++;
            tmp = "";
            size_ = s.size();
            for (int i = 0; i < size_ - 1; ++i) {
                if (s[i] == char('a' + k)) {
                    tmp += s.substr(i,1);
                }
                else {
                    tmp += s.substr(i + 1, 1);
                }
            }
            s = tmp;
        }
        ans = min(temp, ans);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
# ITP1_6_C
# Array - Official House
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_6_C&lang=jp
from sys import stdin

n = int(stdin.readline().rstrip())

NUMBER_OF_BUILDING = 4
FLOORS_PER_BUILDING = 3
ROOMS_PER_FLOOR = 10

official_house = [
    [
        [
            0 for _ in range(ROOMS_PER_FLOOR)
            ] for _ in range(FLOORS_PER_BUILDING)
        ] for _ in range(NUMBER_OF_BUILDING)
    ]

for cnt in range(n):
    b, f, r, v = (int(n) for n in stdin.readline().rstrip().split())
    official_house[b - 1][f - 1][r - 1] += v

for no, building in enumerate(official_house):
    if no != 0:
        print("#" * 20)

    for floor in building:
        print(" " + " ".join(map(str, floor)))



Measured memory_bytes: 5608
use std::cmp::min;
use std::io::stdin;

fn main() {
    let mut is = String::new();
    stdin().read_line(&mut is).ok();
    let n: usize = is.trim().parse().unwrap();
    is.clear();
    stdin().read_line(&mut is).ok();
    let a: Vec<usize> = is.split_whitespace().map(|e| e.parse().unwrap()).collect();
    is.clear();
    let mut min_nodes = vec![0; n + 2];
    let mut max_nodes = vec![0; n + 2];
    let mut flg;
    for i in (0..=n).rev() {
        min_nodes[i] = (min_nodes[i + 1] + 1) / 2 + a[i];
        max_nodes[i] = max_nodes[i + 1] + a[i];
    }
    let mut ans = 1;
    let mut now = 1;
    flg = max_nodes[n] > 0 && min_nodes[0] <= 1 && max_nodes[0] >= 1;
    if flg {
        for i in 0..n {
            let next_min = min_nodes[i + 1];
            let next_max = max_nodes[i + 1];
            now = min((now - a[i]) * 2, next_max);
            ans += now;
            if now < next_min {
                flg = false;
                break;
            }
        }
    }

    if flg {
        println!("{}", ans);
    } else {
        println!("-1");
    }
}


Measured memory_bytes: 5316
N=int(input())
S=input()
i=0
j=N-1
ans=0
while True:
    while S[j]=='W':
        j-=1
        if j<0:
            break
    while S[i]=='R':
        i+=1
        if i>=N:
            break
    if j<i:
        break
    ans+=1
    i+=1
    j-=1
    if j<i:
        break
print(ans)


Measured memory_bytes: 9388
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

int main() {
  int N, P;
  int64_t M, V;
  std::cin >> N >> M >> V >> P;
  std::vector<int> A(N);
  for (int &x: A) {
    std::cin >> x;
  }
  std::sort(A.begin(), A.end());
  std::vector<int64_t> sum(N + 1);
  for (int i: range(0, N)) {
    sum[i + 1] = sum[i] + A[i];
  }
  int ok = N, ng = -1;
  while (ok - ng > 1) {
    int md = (ok + ng) >> 1;
    ([&] {
      if (N - md <= P) return true;
      if (A.cend() - std::upper_bound(A.cbegin(), A.cend(), A[md] + M) >= P) return false; 
      return M * (V - P - md) <= (A[md] + M) * (N - P - md) - (sum[N - (P - 1)] - sum[md + 1]);
    }() ? ok : ng) = md;
  }
  std::cout << N - ok << '\n';
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

ll dp[1<<21];
void Main() {
  ll n;
  R n;
  ll a[n][n];
  rep(i,n)rep(j,n) R a[i][j];
  mem(dp);
  dp[0]=1;
  rep(t,1<<n) {
    ll k=__builtin_popcount(t);
    rep(i,n) {
      if(t&(1<<i)) continue;
      if(!a[k][i]) continue;
      dp[t|(1<<i)]+=dp[t];
      dp[t|(1<<i)]%=MAX;
    }
  }
  pr(dp[(1<<n)-1]);
}

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


Measured memory_bytes: 16768
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int co = 0;
        int yakusu = 0;
      
      for(int i=1;i<=N;i++){
        co = 0;
        if(i%2!=0){
          for(int j=1;j<=i;j++){
            if(i%j==0){co++;}
          }
          if(co==8){yakusu++;}
        }
      }
      System.out.print(yakusu);
    }
}

Measured memory_bytes: 21716
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

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

int A, B;

int main()
{
    cin >> A >> B;
    if (A % 2 == 1 && B % 2 == 1)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
}


Measured memory_bytes: 256
n=int(input())
h=list(map(int,input().split()))
ans=0
for i in range(n-1):
  if h[n-1-i]-h[n-2-i]==-1:
    h[n-2-i]=h[n-2-i]-1
  elif h[n-1-i]-h[n-2-i]<-1:
    ans-=100
if ans==0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 14252
/* ***********************************************
Author        :ACagain
Created Time  :2018/4/21 11:50:24
File Name     :dong.cpp
************************************************ */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define lson o<<1,l,m
#define rson o<<1|1,m+1,r
#define pii pair<int,int>
#define mp make_pair
#define ll long long
#define INF 0x3f3f3f3f
const int maxn=55;

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
	ll n,a,b,c,d;
	cin>>n>>a>>b>>c>>d;
	if(a>b)
	  swap(a,b);
	ll dis=b-a,num=n-1;
	ll r=num*d,l=num*c;
	int flag=0;
	int tt=c+d;
	if(dis>=l&&dis<=r)
	  flag=1;
	else
	for(int i=1;i<=num;i++)
	{
		l-=tt;
		r-=tt;
		if(dis>=l&&dis<=r)
		{
			flag=1;
			break;
		}
	}
	if(flag)
	  cout<<"YES"<<endl;
	else
	  cout<<"NO"<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {
    static Input in = new Input(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int A = in.nextInt();
        int B = in.nextInt();

        out.println(A * B);

        out.flush();
    }

    static class Input {
        private BufferedReader br;
        private String[] buff;
        private int index = 0;

        Input(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }
        String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
        String next() {
            while (buff == null || index >= buff.length) {
                buff = nextLine().split(" ");
                index = 0;
            }
            return buff[index++];
        }
        byte nextByte() {
            return Byte.parseByte(next());
        }
        short nextShort() {
            return Short.parseShort(next());
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        float nextFloat() {
            return Float.parseFloat(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
        BigDecimal nextBigDecimal() {
            return new BigDecimal(next());
        }
    }
}



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

inline int getint()
{
	static char c;
	while ((c = getchar()) < '0' || c > '9');

	int res = c - '0';
	while ((c = getchar()) >= '0' && c <= '9')
		res = res * 10 + c - '0';
	return res;
}

const int MaxN = 200000;

int n;
int a[MaxN + 1], b[MaxN + 1];

int main()
{
	cin >> n;
	for (int i = 1; i <= n; ++i)
		b[a[i] = getint()] = i;

	int t = 0, f = -1;
	for (int i = n - 1; i; --i)
	{
		if (!t && b[i] > b[i + 1])
			++t, f = i + 1;
		else if (t && (b[i] > b[f]) + (b[i + 1] > b[i]) + (b[f] > b[i + 1]) != 2)
			++t, f = i + 1;
	}

	cout << t << endl;

	return 0;
}

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

int main(){
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for(auto& x:a){
		cin >> x;
	}
	sort(a.begin(), a.end());
	vector<int> b;
	int c = 1;
	for(int i =1; i< n; i++){
		if(a.at(i) == a.at(i-1)) c++;
		if(a.at(i) != a.at(i-1)){
			b.push_back(c);
			c=1;
		}
		if(i == n-1) b.push_back(c);
	}
	int u = b.size()-k;
	sort(b.begin(), b.end());
	if(u<0) u = 0;
	int sum = 0;
	for(int i = 0; i < u; i++){
		sum += b.at(i);
	}
	cout << sum <<endl;

}


Measured memory_bytes: 2168
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n, x, l[120];
string str;

int main(){
	cin >> n >> x;
	ll c = 1;
	ll at = 0;
	for(ll i = 1; i <= n; i++){
		cin >> l[i];
		at += l[i];
		if(at <= x){c++;}
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
N,M = [int(v) for v in input().split()]
wa_total = [0 for _ in range(N)]
ac_flag = [False for _ in range(N)]

for _ in range(M):
    p,ans = [v for v in input().split()]
    p = int(p) - 1

    if not ac_flag[p]:
        if ans == "AC":
            ac_flag[p] = True
        else:
            wa_total[p] += 1

ac_ans = 0
wa_ans = 0

for a,b in zip(wa_total,ac_flag):
    if b:
        ac_ans += 1
        wa_ans += a
print(ac_ans,wa_ans)


Measured memory_bytes: 4760
#include <bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
void Add(int &x,int y) {
    x+=y; if (x>=mod) x-=mod;
}
int fpow(int x,int y) {
    int res=1;
    while (y) {
    	if (y&1) res=1ll*res*x%mod;
    	x=1ll*x*x%mod; y>>=1;
	}
    return res;
}
int dp[150][405],f[150][405][405],cnt[405][405];
int a[405],b[405],fac[405],invfac[405],g[405];
int visa[405],visb[405],vis[405][405],w,ans,N;
int A(int n,int m) {
    if (n<m) return 0;
    return 1ll*fac[n]*invfac[n-m]%mod;
}
int main() {
    scanf("%d",&N);
    for (int i=1; i<=N; i++) scanf("%d",&a[i]);
    for (int i=1; i<=N; i++) scanf("%d",&b[i]);
    fac[0]=1;
    for (int i=1; i<=N; i++) fac[i]=1ll*fac[i-1]*i%mod;
    invfac[N]=fpow(fac[N],mod-2);
    for (int i=N-1; i>=0; i--) invfac[i]=1ll*invfac[i+1]*(i+1)%mod;
    dp[1][2]=1;
    for (int i=1; i<N/3; i++) 
        for (int j=0; j<=i*2; j++) 
            for (int h=0; h<=j; ++h) 
                Add(dp[i+1][j+2-h],1ll*A(j,h)*dp[i][j]%mod);
                
    for (int j=0; j<=(N/3)*2; j++) Add(w,1ll*dp[N/3][j]*fac[j]%mod);
    for (int i=1; i<=N; i++) {
        visa[a[i]]=1; cnt[i][0]=i;
        memset(visb,0,sizeof(visb));
        for (int j=1; j<=N; j++) {
            visb[b[j]]=1; cnt[i][j]=cnt[i][j-1];
            if (!visa[b[j]]) cnt[i][j]++;
            if (!visa[b[j]] && !visb[a[i]]) vis[i][j]=1;
        }
    }
    
    for (int t=N/3; t>=1; t--) {
        memset(g,0,sizeof(g));
        for (int i=N; i>=1; i--) {
            int s=(t==N/3);
            for (int j=N; j>=1; j--) {
                if (vis[i][j]) f[t][i][j]=1ll*s*(N-3*(N/3-t)-cnt[i][j])%mod;
                Add(s,g[j]);
                Add(g[j],f[t+1][i][j]);
            }
        }
    }
    for (int i=1; i<=N; i++) 
        for (int j=1; j<=N; j++) 
            Add(ans,f[1][i][j]);
    printf("%d\n",1ll*ans*w%mod);
    return 0;
}


Measured memory_bytes: 87808
package main

import "fmt"

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)
	for i := 1; i <= 1000000; i++ {
		if a*i%b == c {
			fmt.Println("YES")
			return
		}
	}
	fmt.Println("NO")
}


Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] report = new int[N];
        for(int i=0;i<N;i++)report[i]=sc.nextInt();
        Arrays.sort(report);
        int[] correct = new int[N];
        for(int i=0;i<N;i++)correct[i]=Math.abs(i-(N-i-1));
        Arrays.sort(correct);
        
        if(Arrays.equals(report,correct)){
        	//answer is 2^(N/2)
        	final int mod = 1000000007;
        	int answer = 1;
        	for(int i=0;i<N/2;i++){
        		answer = answer *2;
        		answer = answer%mod;
        	}
        	System.out.println(answer);
        }else{
        	System.out.println(0);
        }
    }
}

Measured memory_bytes: 32664
#include <iostream>
using namespace std;
char mas[25][25];
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
int w,h,sx,sy,cnt;
void dfs(int,int);

int main(){
    while(1){
        cin >> w >> h;
        if(w == 0 && h == 0) break;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                cin >> mas[i][j];
                if(mas[i][j] == '@'){
                    sx = j;
                    sy = i;
                }
            }
        }
        cnt = 0;
        dfs(sx,sy);
        cout << cnt << endl;
    }
}

void dfs(int x,int y){
    mas[y][x] = '#';
    cnt++;
    for(int i=0;i<4;i++){
        int nx = x+dx[i];
        int ny = y+dy[i];
        if(nx >= 0 && nx < w && ny >= 0 && ny < h && mas[ny][nx] == '.') {
            dfs(nx,ny);
        }
    }
}

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

typedef long long ll; 
ll m=1e9+7;
ll dp[2002][1002];


ll dfs(ll a,ll b){
  dp[0][0]=1;
  if(a<b)return 0;
  if(dp[a][b])return dp[a][b];
  ll res=0;
  if(a)res+=dfs(a-1,b);
  if(a&&b)res+=dfs(a-1,b-1);
  res%=m;
  return dp[a][b]=res;
}

int main(){
  ll n,k;
  cin>>n>>k;
  cout<<dfs(k,n)<<endl;
  return 0;
}



Measured memory_bytes: 7108
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<ll,ll>
#define vi(x) vector<x>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace std;
using namespace __gnu_pbds;

signed main()
{
    fast;
    
    ll n,k,i,ans=0;
    cin>>n>>k;
    ll a[n+2];
    for(i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    for(i=0;i<k;i++) ans += a[i];
    cout<<ans;
}

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

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> l(m), r(m);
    rep(i, m) cin>>l[i]>>r[i];
    int card_l=l[0], card_r=r[0];
    rep(i, m){
        if (card_l<l[i]) card_l=l[i];
        if (r[i]<card_r) card_r=r[i];
    }
    int ans=0;
    if(card_l<=card_r) ans = card_r - card_l + 1;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1152
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<stack>
#include<queue>

using namespace std;

int selection_sort(int *a, int n)
{
	int cou = 0;
	for (int i = 0; i < n; i++) {
		int minj = i;
		for (int j = i; j < n; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		if (i != minj) {
			int k = a[i];
			a[i] = a[minj];
			a[minj] = k;
			cou++;
		}
	}
	return cou;
}

int main()
{
	int n;
	cin >> n;
	int a[105];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	int k=selection_sort(a, n);

	for (int i = 0; i < n - 1; i++) {
		cout << a[i] << " ";
	}
	cout << a[n - 1] << endl;

	cout << k << endl;

	return 0;
}

Measured memory_bytes: 3076
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef unsigned long long LL;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

constexpr LL kMax = 1000000000000000000;

int main() {
  int N; cin >> N;
  vector<LL> A(N); cin >> A;
  for (LL a : A) {
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  sort(A.rbegin(), A.rend());

  LL v = A[N-1];
  for (int i = 0; i < N-1; ++i) {
    long double w = 1e18 / v;
    if (w < A[i]) {
      cout << -1 << endl;
      return 0;
    }
    v *= A[i];
  }
  if (v > kMax) {
      cout << -1 << endl;
      return 0;
  }
  cout << v << endl;
}


Measured memory_bytes: 3964
#include <bits/stdc++.h> 
using namespace std;
long long n,m,i,j,ans,x,y,l,r,mid;
int main(){
	cin>>n;
	while (n--){
		cin>>x>>y;
		if (x==1&&y==1){
			cout<<"0\n";
			continue;
		}
		if (x==y||abs(x-y)==1){
			cout<<(min(x,y)-1)*2<<endl;
			continue;
		}
		ans=0;l=0;r=0x3fffffff;
		while (l<r){
			mid=(l+r)/2;
			if (mid*mid<x*y){
				ans=mid;
				l=mid+1;
			}
			else r=mid;
		}
		//cerr<<ans<<endl;
		if (ans*(ans+1)>=x*y){
			cout<<ans*2-2<<endl;
			continue;
		}
		cout<<ans*2-1<<endl;
	}
	return 0;
}

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

using namespace std;

bool check(int n) {
	vector<int> d;
	for(; n / 10; n /= 10) d.push_back(n % 10);
	d.push_back(n);

	if (d.size() != 4) return false;
	return (d[0] == d[1] && d[1] == d[2]) || (d[1] == d[2] && d[2] == d[3]);
}

int main() {
	ios::sync_with_stdio(false); cin.tie(NULL);
	int n; cin >> n;

	cout << (check(n) ? "Yes" : "No");
}


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


def solve2(N, A):
    A.sort()
    amax = A[-1]
    dp = [True] * (amax + 1)
    cnt = [0] * (amax + 1)

    for a in A:
        cnt[a] += 1

    for i in range(amax):
        x = i + 1
        if cnt[x] > 1:
            dp[x] = False

        if cnt[x] > 0:
            y = x * 2
            while y <= amax:
                dp[y] = False
                y += x

    ansval = [x for x in A if dp[x]]

    # print(ansval)
    ans = len(ansval)

    return ans


def solve1(N, A):
    ans = 0
    for i in range(N):
        is_ans = True
        for j in range(N):
            if i != j:
                if A[i] % A[j] == 0:
                    is_ans = False
                    break

        if is_ans:
            ans += 1

    return ans


print(solve2(N, A))


Measured memory_bytes: 34744
div = 10**9+7
N,M =map(int,input().split())
A = [int(input()) for _ in range(M)]
# print(A)

ans = [0] * (N+1)
ans[0] = 1
ans[1] = 1
for a in A: ans[a] = -1
for i in range(2,N+1):
    if ans[i] == -1: continue
    else:
        a1 = ans[i-1]
        a2 = ans[i-2]
        if a1 == a2 == -1: break
        else:
            if a1 == -1: a1 = 0
            if a2 == -1: a2 = 0
            ans[i] = (a1+a2) % div
# print(ans)
print(ans[N])

Measured memory_bytes: 7848
#include <stdio.h>

int main(void)
{
	int day;
	scanf("%d", &day);
	if (day == 25)printf("Christmas");
	else if (day == 24)printf("Christmas Eve");
	else if (day == 23)printf("Christmas Eve Eve");
	else if (day == 22)printf("Christmas Eve Eve Eve");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath> 
#include <queue>
#include <functional>

using namespace std;
//typedef long long ll;
//typedef pair<int, int> P;
//static const int dx[4] = {1, -1, 0, 0};
//static const int dy[4] = {0, 0, 1, -1};
int main() {

    int n; cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; i++) {
        cin >> d[i];
    }
    
    sort(d.begin(), d.end());
    
    int ans = d[n/2] - d[n/2-1];

    cout << ans << '\n';

}


Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<Integer> list = new ArrayList<Integer>();
        for(int i = 1; i <= 5; i++){
            int x = sc.nextInt();
            if(x == 0){
                System.out.println(i);
            }
        }
        sc.close();
    }
}


Measured memory_bytes: 35692
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<stack> 
#include<queue>
#include<cmath>
#include<map>
#define LL long long
#define N 400100
#define M 1010
#define MOD 1000000007
#define FOR(i,l,r) for (int i = (l); i <= (r); i ++)
#define CLR(a,x) memset(a,x,sizeof(a))
#define INF 0x3f3f3f3f
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define X first
#define Y second
using namespace std;
int a[M], b[M], c[M], d[M], vis[M], link[M];
vector<int> g[M];
int match(int u){
	for (int i = 0; i < g[u].size(); i ++){
		int v = g[u][i];
		if (vis[v]) continue;
		vis[v] = 1;
		if (!link[v] || match(link[v])){
			link[v] = u;
			return 1;
		}
	}
	return 0;
}
int main(){
	int n;
	cin >> n;
	for (int i = 1; i <= n; i ++) scanf("%d%d", &a[i], &b[i]);
	for (int i = 1; i <= n; i ++) scanf("%d%d", &c[i], &d[i]);
	for (int i = 1; i <= n; i ++) for (int j = 1; j <= n; j ++)
		if (a[i] < c[j] && b[i] < d[j]) g[i].pb(j);
	int ans = 0;
	memset(link, 0, sizeof(link));
	for (int i = 1; i <= n; i ++){
		memset(vis, 0, sizeof(vis));
		if (match(i)) ans ++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
/***********************************************************************************
*           Falling down is an accident, Staying down is a choice.                 *
***********************************************************************************/
#include <bits/stdc++.h>
using namespace std;
#define ios std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) //Fast IO
#define _USE_MATH_DEFINES
#define PI acos(-1.0) //3.14159265358
#define EPS 1e-9 //epsilon, 10^-9, checking for equality 
#define pb push_back
#define fi first
#define se second
#define isort(x) sort(x.begin(),x.end())
#define dsort(x) sort(x.rbegin(),x.rend())
const int inf=1e9+7; //10^9 +7
const int modc=998244353;
typedef long long int ll;
void solve();int main(){ios;solve();return 0;}
/***********************************************************************************/
void solve()
{
	int n,k;cin>>n>>k;
	vector<int> adj[100005];
	vector<ll> ans(n,0);
	for(int i=0;i<n-1;i++)
	{
		int a,b;cin>>a>>b;
		a--;b--;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	queue<int> q;
	vector<bool> visited(n,false);
	q.push(0);
	visited[0]=true;
	ans[0]=k;
	while(1)
	{
		int i=1;
		int cur=q.front();
		q.pop();
		for(auto x:adj[cur])
		{
			if(visited[x]) continue;
			ans[x]=k-i;
			i++;
			q.push(x);
			visited[x]=true;
		}
		break;
	}
	while(!q.empty())
	{
		int i=2;
		int cur=q.front();
		q.pop();
		for(auto x:adj[cur])
		{
			if(visited[x]) continue;
			ans[x]=k-i;
			i++;
			q.push(x);
			visited[x]=true;
		}
	}
	ll finalans=1;
	for(int i=0;i<n;i++)
	{
		finalans=(finalans*ans[i])%inf;
	}
	cout<<finalans<<endl;

}

Measured memory_bytes: 7288
import java.util.HashMap;
import java.util.Scanner;


public class Main {
	
       public static void main(String[] args) {
    	  Scanner input=new Scanner( System.in);
    	  
    	  long ans=0;
    	  String string=input.next();
    	  int len=string.length();
    	  
    	 if(string.charAt(0)==string.charAt(len-1))
    	 {
    		 if((len-2)%2==1)
    		 {
    			 System.out.println("Second");
    		 }
    		 else
    			 System.out.println("First");
    	 }
    	 else
    	 {
    		 if((len-2)%2==1)
    		 {
    			 System.out.println("First");
    			
    		 }
    		 else
    			 System.out.println("Second");
    	 }
    	 // System.out.println(ans);
          
	}
}


Measured memory_bytes: 26752