akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    void Run()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        int k = sc.NextInt();

        double sum = 0;
        for (int i = 1; i <= n; i++)
        {
            int s = i;
            int den = 1;
            while (s <= k - 1)
            {
                s *= 2;
                den *= 2;
            }
            sum += 1 / (double)den;
        }
        Console.WriteLine((sum / n).ToString("0.##########"));
    }

    static void Main(string[] args)
    {
        new Program().Run();
    }

    static long Gcd(long a, long b)
    {
        if (a < b) return Gcd(b, a);
        if (b == 0) return a;
        return Gcd(b, a % b);
    }
}

class Scanner
{
    int index = -1;
    string[] buf;

    public Scanner()
    {
    }

    public int NextInt()
    {
        CheckNext();
        return int.Parse(buf[index++]);
    }

    public long NextLong()
    {
        CheckNext();
        return long.Parse(buf[index++]);
    }

    public double NextDouble()
    {
        CheckNext();
        return double.Parse(buf[index++]);
    }

    public string NextString()
    {
        CheckNext();
        return buf[index++];
    }

    private void CheckNext()
    {
        if (index >= 0 && index < buf.Length) return;

        buf = Console.ReadLine().Split(' ');
        index = 0;
    }
}


Measured memory_bytes: 13140
#include "bits/stdc++.h"
using namespace std;
#define maxn 1501
#define rep(i,n) for(int i=0; i<int(n); ++i)
#define pb push_back
#define mp make_pair

long long div2(int H, int W){
    if (H%2 ==0 || W%2==0) return 1ll * H * W / 2;
    return max(1ll * H / 2 * W, 1ll * W / 2 * H);
}

long long div3(int H, int W){
    long long diff = 1ll * H * W;
    for(int i=0; i<H; ++i){
        long long area_1 = 1ll * i * W;
        long long area_2 = div2(H-i,W);
        long long area_3 = 1ll * (H-i) * W - area_2;
        // cout << area_1 << ' ' << area_2 << ' ' << area_3 << endl;
        // cout << max(area_3, area_1) - min(area_2, area_1) << endl;
        diff = min(diff, max(area_3, area_1) - min(area_2, area_1));
    }
    return diff;
}
void solve(){
    int H, W;
    cin >> H >> W;
    cout << min(div3(H,W),div3(W,H));
}

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(0);
    solve();
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void){
	int k,c,sum;

	while(cin>>k,k){
		sum=0;
		for(int i=0;i<k*(k-1)/2;i++){
			cin>>c;
			sum=sum+c;
		}
		cout<<sum/(k-1)<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	X, t := sc.nextInt(), sc.nextInt()

	fmt.Fprintln(wtr, max(X-t, 0))
	wtr.Flush()
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<int(n);i++)
#define FOR(i,n,m) for(int i=n;i<int(m);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

int vx[]={0,0,-1,1};
int vy[]={1,-1,0,0};
int dx[]={1,0,-1,1,-1,1,0,-1};
int dy[]={1,1,1,0,0,-1,-1,-1};

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}	

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int N_MAX=100010;

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

	string ans;
	char target=s[k-1]+32;
	ans=s.substr(0,k-1)+target+s.substr(k,s.size()-k);
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    string S;
    int ans = 0;
    cin >> S;
    for (size_t i = 0; i < S.size()/2; i++)
    {
        if (S[i]!=S[S.size()-1-i])
        {
            ans++;
        }
        
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <climits>
using namespace std;
int N, M, X, C[15], A[15][15], S[15];
int rec(int n) {
  if(n == N) {
    int cost = 0, x[15];
    for(int i = 0; i < M; i++) {
      x[i] = 0;
    }
    for(int i = 0; i < N; i++) {
      if (S[i] == 1) {
		cost += C[i];
        for(int j = 0; j < M; j++) {
          x[j] += A[i][j];
        }
      }
    }
    for(int i = 0; i < M; i++) {
      if (x[i] < X) return INT_MAX;
    }
    return cost;
  }
  int minCost = INT_MAX;
  S[n] = 0;
  minCost = min(rec(n + 1), minCost);
  S[n] = 1;
  minCost = min(rec(n + 1), minCost);
  return minCost;
}

int main() {
  cin >> N >> M >> X;
  for(int i = 0; i < N; i++) {
    cin >> C[i];
    for(int j = 0; j < M; j++) {
      cin >> A[i][j];
    }
    S[i] = 0;
  }
  int cost = rec(0);
  if (cost == INT_MAX) {
    cout << -1 << endl;
    return 0;
  }
  cout << cost << endl;
  return 0;
}

Measured memory_bytes: 3656
N=int(input())
ans=0
A=0
B=0
ab=0
for _ in range(N):
    S=input()
    ans+=S.count('AB')
    A+=S[-1]=='A'
    B+=S[0]=='B'
    ab+=(S[-1]=='A' and S[0]=='B')

if ab>0 and ab==A==B:
    ans-=1
print(ans+min(A,B))

Measured memory_bytes: 9152
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main(void)
{
	int n;
	scanf("%d",&n);
	if(n<1200)printf("ABC\n");
	else if(n<2800)printf("ARC\n");
	else printf("AGC\n");
	return 0;
}

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

int main() {
  long long x;
  scanf("%lld", &x);
  double a=100.0;


  for(int i=1; ;i++){
    a*=1.01;
    a=(long long int)a;
    if(a>=x) {
      printf("%d", i);
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
const int MAX = 3005;
int n;
double p[MAX], dp[MAX][MAX];
double solve() {
    int i, j;
    double res = 0;
    memset(dp, 0, sizeof(dp)); dp[0][0] = 1;
    for(i = 1; i <= n; i++) {
        dp[i][0] = dp[i - 1][0] * (1 - p[i - 1]);
        for(j = 1; j <= i; j++)
            dp[i][j] = dp[i - 1][j - 1] * p[i - 1] + dp[i - 1][j] * (1 - p[i - 1]);
    }
    for(j = 0; j <= n; j++) {
        if(j > n - j)
            res += dp[n][j];
    }
    return res;
}
int main() {
    int i;
    scanf("%d", &n);
    for(i = 0; i < n; i++)
        scanf("%lf", &p[i]);
    printf("%.10lf\n", solve());
    return 0;
}

Measured memory_bytes: 70784
n, *a = map(int, open(0).read().split())
a.append('*')
cnt = 0
tmp_cnt = 0
tmp = '*'
for i in range(n+1):
    if a[i] == tmp:
        tmp_cnt += 1
    else:
        cnt += tmp_cnt//2
        tmp = a[i]
        tmp_cnt = 1
print(cnt)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int N,M;
vector<vector<ll>> dist;

void warshallFloyd(){
	rep(k,N)rep(i,N){
		if(dist[i][k] == LINF) continue;
		rep(j,N){
			if(dist[k][j] == LINF) continue;
			dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j]);
		}
	}
}

int main(){
	cin >> N >> M;
	dist.resize(N,vector<ll>(N,LINF));
	rep(i,N)rep(j,N) if(i == j) dist[i][j] = 0;
	int R; cin >> R;
	vector<int> r(R);
	rep(i,R){
		cin >> r[i];
		r[i]--;
	}
	sort(r.begin(),r.end());
	rep(i,M){
		int A,B; cin >> A >> B;
		A--; B--;
		ll C; cin >> C;
		dist[A][B] = C;
		dist[B][A] = C;
	}

	warshallFloyd();

	ll ans = LINF;
	do{
		ll now = 0;
		rep(i,R-1){
			if(dist[r[i]][r[i+1]] == LINF){
				now = LINF;
				break;
			}
			now += dist[r[i]][r[i+1]];
		}
		ans = min(ans,now);
	}while(next_permutation(r.begin(),r.end()));

	cout << ans << endl;
	
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main() {
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI a(n);
	rep(i, n) cin >> a[i];
	sort(all(a));
	//for(auto x :a) printf("%d, ",x); puts("");
	ll ans =0;
	rep(i, n-2) rep2(j, i+1, n-1){
		auto p1= lower_bound(all(a), a[j]-a[i]+1) - a.begin();
		auto p2= upper_bound(all(a), a[i]+a[j]-1) - a.begin();
		//dbg(i,j,p1,p2,a[i],a[j]);
		
		if(p2>j)
		ans += p2 - j -1;

	}
	cout << ans <<"\n";
	return 0;
	
}


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

using namespace std;

class Edge {
public:
    int from, to, weight;
    Edge(int f, int t, int w) : from(f), to(t), weight(w) {}
};

int memo[100001] = {0};

int height(vector<vector<Edge>> &Graph, int parent) {
    if (memo[parent]) return memo[parent];
    int ret = 0;
    for (int i=0; i<(int)Graph[parent].size(); ++i) {
        ret = max(ret, Graph[parent][i].weight + height(Graph, Graph[parent][i].to));
    }
    return memo[parent] = ret;
}

int diameter(vector<vector<Edge>> &Graph, int parent) {
    int ret = 0;
    int h1 = 0, h2 = 0;
    for (int i=0; i<(int)Graph[parent].size(); ++i) {
        int h = Graph[parent][i].weight + height(Graph, Graph[parent][i].to);
        if (h1 < h) {
            h2 = h1;
            h1 = h;
        } else if (h2 < h) {
            h2 = h;
        }
        ret = max(ret, diameter(Graph, Graph[parent][i].to));
    }
    ret = max(ret, h1 + h2);
    return ret;
}

int main() {
    int n, s, t, w;
    cin >> n;
    vector<vector<Edge>> Graph(n + 1);
    for (int i=1; i<=n-1; ++i) {
        cin >> s >> t >> w;
        Graph[s].push_back(Edge(s, t, w));
    }
    cout << diameter(Graph, 0) << endl;
    return 0;
}

Measured memory_bytes: 14596
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;


int main(){
    ll X, Y;

    cin >> X >> Y;

    ll c, t;

    if(Y % 2 == 0){
        c = 2 * X - Y / 2;
        t = Y / 2 - X;
        if(c >= 0 && t >= 0){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3596
#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,L;
	cin >> N >> L;
	int a=1e9;
	int ans = 0;
	for(int i=1; i<=N; i++){
		ans += L+i-1;
		if(abs(a)>abs(L+i-1)) a = L+i-1;
	}

	cout << ans - a << endl;


	return 0;
}




Measured memory_bytes: 256
import bisect
N=int(input())
A=list(map(int,input().split()))
A1=[]
A2=[]
for i in range(N):
  A1.append(i+1+A[i])
  A2.append(i+1-A[i])
A1.sort()
#A2.sort()
ans=0
for i in range(N):
  ai=A[i]
  i+=1
  ans+=bisect.bisect_right(A1,i-ai)-bisect.bisect_left(A1,i-ai)
  #ans+=bisect.bisect_right(A2,i+ai)-bisect.bisect_left(A2,i+ai)
print(ans)

Measured memory_bytes: 110332
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int num=in.nextInt();
        int size=in.nextInt();
        int ar[]=new int[size];
        long sum=0;
        for (int i = 0; i < size; i++) {
            ar[i]=in.nextInt();
            sum=sum+ar[i];
        }
        if(sum>=num){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 50360
#include <bits/stdc++.h>//復習必須
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
#define P pair<int, int>
const int mod=1e9+7;
int main (){
  int n; cin >> n;
  for(int i = 1; i <= 50000; i++){
    int now = i * 1.08;
    if(now == n){
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
  return 0;
}

 


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define loop(i,n) for(int i = 0;i < (n);i++)
#define all(A) A.begin(),A.end()
#define pb push_back
#define mp make_pair
#define sz(A) ((int)A.size())
typedef std::vector<int> vi;
typedef std::pair<int,int> pi;
typedef std::vector<pi> vp;
typedef long long ll;
#define popcnt(x) __builtin_popcount(x)
#define LSOne(x) ((x) & (-(x)))
#define print(A,t) cerr << #A << ": "; copy(all(A),ostream_iterator<t>(cerr," " )); cerr << endl
#define prArr(A,n,t)  cerr << #A << ": "; copy(A,A + n,ostream_iterator<t>(cerr," " )); cerr << endl
#define PRESTDIO() cin.tie(0),cerr.tie(0),ios_base::sync_with_stdio(0)
#define what_is(x) cerr << #x << " is " << x << endl
#define bit_lg(x) (assert(x > 0),__builtin_ffsll(x) - 1)
const double PI = acos(-1);
template<class A,class B>
std::ostream& operator << (std::ostream& st,const std::pair<A,B> p) {
	st << "(" << p.first << ", " << p.second << ")";
	return st;
}
using namespace std;

int dp[100][100];

int f(int e, int low){
	if(e == 0) return e;
	int & ret = dp[e][low];
	if(ret != -1) return ret;
	ret = 0;
	for(int x = low; x <= e; x++)
		ret = max(ret, 1 + f(e - x, low + 1));
	return ret;	
}


int main(){
#ifdef HOME
	freopen("in.in", "r", stdin);
#endif
	int ans = 0;
	memset(dp, -1, sizeof dp);
	ll n; cin >> n;
	for(ll x = 2; x*x <= n; x++){
		int e = 0;
		while(n%x == 0) {
			e++;
			n /= x;
		}
		ans += f(e, 1);
	}
	if(n > 1) ans += f(1, 1);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3668
#include <algorithm>
#include <cassert>
#include <cstdlib>
#include <iostream>
#include <sstream>
using namespace std;

#define NDEBUG

int mod;
const char *p;

int mod_pow(int x, int n) {
	int res = 1;
	while(n > 0) {
		if(n & 1) res = (res * x) % mod;
		x = (x * x) % mod;
		n >>= 1;
	}
	return res;
}

int mod_inverse(int x) {
	return mod_pow(x, mod - 2);
}

int expr();
int term();
int factor();
int number();

int expr() {
	int res = term();
	while(*p == '+' || *p == '-') {
		switch(*(p++)) {
		case '+': res = (res + term()) % mod; break;
		case '-': res = (res - term() + mod) % mod; break;
		}
	}
	return res;
}

int term() {
	int res = factor();
	while(*p == '*' || *p == '/') {
		switch(*(p++)) {
		case '*': res = (res * factor()) % mod; break;
		case '/':
			const int divisor = factor();
			if(divisor == 0) throw "NG";
			res = (res * mod_inverse(divisor)) % mod;
			break;
		}
	}
	return res;
}

int factor() {
	if(*p == '(') {
		++p;
		const int res = expr();
		++p;
		return res;
	}

	assert(isdigit(*p));
	return number();
}

int number() {
	int res = 0;
	while(isdigit(*p)) {
		res = res * 10 + *(p++) - '0';
	}
	return res;
}

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

	for(string input; getline(cin, input);) {
		const unsigned separator = input.find(':');

		mod = stoi(input.substr(0, separator));
		if(mod == 0) break;

		string s = input.substr(separator + 1);
		s.erase(remove(s.begin(), s.end(), ' '), s.end());
		p = s.c_str();

		try {
			ostringstream os;
			os << s << " = " << expr() << " (mod " << mod << ")\n";
			cout << os.str();
		} catch(const char *) {
			cout << "NG\n";
		}
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1624
import java.util.Scanner;
public class Main {
	static int N;
	static int count;
@SuppressWarnings("resource")
public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	N=sc.nextInt();
	count("","3");
	count("","5");
	count("","7");
	System.out.println(count);
}

public static void count(String s,String s2) {
	s+=s2;
	if(Long.parseLong(s)>N) {
		return;
	}
	if(s.contains("3")&&s.contains("5")&&s.contains("7")) {
	count++;
	}
	count(s,"3");
	count(s,"5");
	count(s,"7");
}
}


Measured memory_bytes: 35796
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int N;
    cin >> N;
    int ans = 0;
    int l, r;
    rep(i, 0, N)
    {
        cin >> l >> r;
        ans += (r - l + 1);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string.h>

using namespace std;

const int MAXN = 200000 + 100;
int n, m;
struct Node
{
    int u, v, w;
}edge[MAXN];
int pre[MAXN];

int finds(int x)
{
    return x == pre[x] ? x : (pre[x] = finds(pre[x]));
}

bool cmp(Node a, Node b)
{
    return a.w < b.w;
}

void solve()
{
    int ans = 0;

    sort(edge, edge + m, cmp);

    for (int i = 0; i <= n; i++)
    {
        pre[i] = i;
    }

    int num = 0;

    for (int i = 0; i < m; i++)
    {
        int fa = finds(edge[i].u), fb = finds(edge[i].v);

        if (fa != fb)
        {
            pre[fa] = fb;
            num++;
            if (num == n / 2) ans = edge[i].w;
            if (num == n - 1) break;
        }
    }

    printf("%d\n", ans);
}

void input()
{
    int u, v, w;

    while (scanf("%d %d", &n, &m) != EOF)
    {
        if (n == 0 && m == 0)
        {
            break;
        }
        for (int i = 0; i < m; i++)
        {
            scanf("%d %d %d", &edge[i].u, &edge[i].v, &edge[i].w);
        }

        solve();
    }
}

int main()
{
    input();
    return 0;
}

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

long long a, b, c;

bool solve();

int main() {
  cin >> a >> b >> c;
  if(solve())
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

bool solve() {
  long long ab = a * b, x = (c - a - b);
  if(x < 0) return 0;
  return ab < (long double)(x * x) / 4.0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  vl T(N), A(N);
  REP(i, N) cin >> T[i] >> A[i];
  ll t = T[0];
  ll a = A[0];
  FOR(i, 1, N) {
    if (t % T[i] != 0)
      t += T[i] - (t % T[i]);
    if (a % A[i] != 0)
      a += A[i] - (a % A[i]);
    if ((t / T[i]) * A[i] > a) {
      a = (t / T[i]) * A[i];
    } else {
      t = (a / A[i]) * T[i];
    }
  }
  cout << a + t << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iterator>
#include <regex>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT* delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<VI> as(2, VI(n));
  FOR(a,as) {
    FOR(x,a) {
      cin >> x;
    }
  }
  REP(i,1,n) {
    as[0][i] += as[0][i-1];
  }
  for(int i=n-2; i>=0; i--) {
    as[1][i] += as[1][i+1];
  }

  int ans = -1;
  REP(i,0,n) {
    ans = max(ans, as[0][i] + as[1][i]);
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
ans = 1
sw = 0
import collections
c = collections.Counter(a)
if c[0] != 0:
    ans = 0
for i in range(n):
    ans *= a[i]
    if ans > 10**18:
        ans = -1
        break
print(ans)

Measured memory_bytes: 23748
N, K=map(int, input().split())
R, S, P=map(int, input().split())
T=list(input())

row=[]
for i in range(K):
  row.append(T[i::K])
  
score=0
for r in row:
  pre="n"
  for i, hand in enumerate(r):
    if hand==pre:
      pre=0
    else:
      if hand=="r":
        score+=P
        pre="r"
      elif hand=="s":
        score+=R
        pre="s"
      else:
        score+=S
        pre="p"
        
print(score)

Measured memory_bytes: 12712
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
    for (T& x: vec) { is >> x; }
    return is;
}

int main() {
	ll ans = 0;
	ll tmp;
	//int n; cin >> n;
	vector<string> s(3);
	cin >> s[0] >> s[1] >> s[2];
	int who = 0;
	while(1){
		if(s[who].size()==0){
			cout << (char)('A' + who) << endl;
			break;
		}
		else{
			int next = s[who][0] - 'a';
			s[who] = s[who].substr(1);
			who = next;
		}
	}
	//cout << ans << endl;
}

Measured memory_bytes: 3608
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  long long a, b;
  cin >> a >> b;
  cout << a / __gcd(a, b) * b << '\n';
  return 0;
}

Measured memory_bytes: 256
// Vicfred
// https://atcoder.jp/contests/abc127/tasks/abc127_c
// implementation, greedy
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

void main() {
    int n, m;
    readf("%s %s\n", &n, &m);

    int maxleft = -1;
    int minright = int.max;
    foreach(i; 0..m) {
        int left, right;
        readf("%s %s\n", &left, &right);
        maxleft = max(maxleft, left);
        minright = min(minright, right);
    }

    int ans = minright - maxleft + 1;
    if(minright < maxleft) ans = 0;
    ans.writeln;
}



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


bitset<4000005> dp;

int N;
int s;

int main() {

  cin >> N;
  int num;

  dp[0] = 1;
  for (int i = 0; i < N; i++) {
    cin >> num;
    dp = dp | (dp << num);
    s += num;
  }
  
  if (s % 2) {
    s += 1;
  }
  
  int half_s = s / 2;

  for (int i = half_s; i <= s; i++) {
    if (dp[i]) {
      cout << i << endl;
      break;
    }
  }
  
  return 0;

}
  


Measured memory_bytes: 2176
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;

struct edge {
    i64 from, to, cost;
    edge(i64 from, i64 to) : from(from), to(to), cost(1) {}
    edge(i64 from, i64 to, i64 cost) : from(from), to(to), cost(cost) {}
};
using Graph = vector<vector<edge>>;

constexpr i64 INF = std::numeric_limits<i64>::max();
constexpr i64 SINF = std::numeric_limits<i64>::max() / 10;
const i64 MOD = 1000000007;
const i64 dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };
//const i64 dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//const i64 dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//const i64 dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
    for (auto& e : t) fill_v(e, v);
}

struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main() {
    i64 n;
    cin >> n;
    vector<string> s(n);
    vector<i64> p(n);
    vector<bool> used(n, false);
    for (int i = 0; i < n; ++i) {
        cin >> s[i] >> p[i];
    }
    for (int i = 0; i < n; ++i) {
        i64 idx, mp;
        idx = -1; mp = -1;
        string ms = "zzzzzzzzzzzz";
        for (int j = 0; j < n; ++j) {
            if(used[j]) continue;
            if (ms > s[j]) {
                idx = j;
                ms = s[j];
                mp = p[j];
            }
            else if (ms == s[j] && mp < p[j]) {
                idx = j;
                ms = s[j];
                mp = p[j];
            }
        }
        used[idx] = true;
        cout << idx + 1 << endl;
    }
}

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

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

  int H, W;
  cin >> H >> W;
  int A[10][10];
  rep(i,10){
    rep(j,10){
      cin >> A[i][j];
    }
  }
  rep(k,10){
    rep(i,10){
      rep(j,10){
        A[i][j] = min(A[i][j], A[i][k] + A[k][j]);
      }
    }
  }

  int c ,ans = 0;
  rep(i,H){
    rep(j,W){
      cin >> c;
      if(c != -1) ans += A[c][1];
    }
  }
  cout << ans << endl;
}

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

def main():
    N,M=map(int,input().split())
    edge=[[] for _ in range(N)]
    redge=[[] for _ in range(N)]
    for _ in range(M):
        l,r,d=map(int1,input().split())
        d+=1
        edge[l].append((r,d))
        edge[r].append((l,-d))
    s=0
    D=[-INF]*N
    used=[False]*N
    while True:
        for s in range(s,N):
            if not used[s]:
                break
        else:
            break
        D[s]=0
        stack=[s]
        while stack:
            v=stack.pop()
            used[v]=True
            for nv,d in edge[v]:
                if D[nv]==-INF:
                    D[nv]=D[v]+d
                else:
                    if D[nv]!=D[v]+d:
                        print('No')
                        exit()
                if not used[nv]:
                    stack.append(nv)
    print('Yes')


if __name__ == '__main__':
    main()


Measured memory_bytes: 81712
#include <bits/stdc++.h>
#define fo(i, a, b) for (int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
using namespace std;
typedef long long ll;
int main()
{
  int n, a, b;
  cin >> n >> a >> b;

  vector<int> x(n);
  re(i, n) x[i] = i + 1;
  vector<int> y(n);
  re(i, n) y[i] = x[i] / 10000 + x[i] / 1000 % 10
                + x[i] / 100 % 10 + x[i] / 10 % 10 + x[i] % 10;

  int ans = 0;
  re(i, n) if (a <= y[i] && y[i] <= b) {
    ans += x[i];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <math.h>
using namespace std;

int calc(long long X,long long n){
  if(((n+1) * n / 2 ) >= X){
      return n;
  }else{
    calc(X,n+1);
  }
}

void solve(){
  long long X;
  long long ans;
  cin >> X;
  ans = calc(X,1);
  std::cout << ans;
}


int main() {
  solve();
}



Measured memory_bytes: 256
N = int(input())
dp = [i for i in range(N+1)]
num = []
[num.append(6 ** i) for i in range(1, 7)]
[num.append(9 ** i) for i in range(1, 6)]
for i in range(N + 2):
    for add in num:
        if i + add > N: continue
        dp[i + add] = min(dp[i + add], dp[i] + 1)

print(dp[N])

Measured memory_bytes: 7064
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define K 1000000007

ll pown(ll x, ll y){
  ll res=1;
  rep(i,y){
    res= res * x % K;
  }
  return res;
}



int main() {
  ll N;
  cin >> N;
  //vector<ll> a(N);
  //vector<vector<int>> data(3, vector<int>(4));

  ll ans;
  ans = pown(10, N) - pown(9, N) - pown(9, N) + pown(8, N);
  ans = ans % K;
  ans = (ans + K)% K;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <array>
#include <cmath>
#include <random>
#include <functional>
#include <climits>
#include <iomanip>
using namespace std;
using lint=long long;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  if(n==1) cout<<"Hello World"<<endl;
  else {
    int a,b;
    cin>>a>>b;
    cout<<a+b<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
s = list(input())
ans = [1] * len(s)

for i in range(len(s)):
    if s[i] == 'R' and s[i + 1] == 'L':
        for j in reversed(range(i)):
            if s[j] != 'R':
                break
            if (i - j) % 2 == 1:
                ans[i] += ans[j]
                ans[j] = 0
            else:
                ans[i + 1] += ans[j]
                ans[j] = 0

        for k in range(i + 2, len(s)):
            if s[k] != 'L':
                break
            if (k - i) % 2 == 1:
                ans[i] += ans[k]
                ans[k] = 0
            else:
                ans[i + 1] += ans[k]
                ans[k] = 0

for i in range(len(s)):
    if s[i] == 'R' and s[i + 1] == 'L':
        temp = ans[i]
        ans[i] = ans[i + 1]
        ans[i + 1] = temp

print(*ans)


Measured memory_bytes: 54520
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
import numpy as np
n=ii()
arr=np.cumsum(np.array([0]+limii()))

#print(arr)
res={}
for i in arr:
    if i not in res:
        res[i]=1
    else:
        res[i]+=1
ans=0
for i in res.values():
    ans+=i*(i-1)//2
print(ans)



Measured memory_bytes: 38856
#include <stdio.h>
#define min(p,q)((p)<(q)?(p):(q))

int pro[100][100];
int A[100],B[100];

int f(int l,int r){
  if(pro[l][r])return pro[l][r];
  if(l+1==r)return 0;
  int answer = 1e9;
  for(int m = l+1;m<r;m++)answer=min(answer,f(l,m)+f(m,r)+A[l]*A[m]*B[r-1]);

  pro[l][r]=answer;
  
  return pro[l][r];
}

int main(){
  int n;
  scanf("%d",&n);
  for(int i=0;i<n;i++)scanf("%d%d",A+i,B+i);
  printf("%d\n",f(0,n));
}



Measured memory_bytes: 2112
N = int(input())
src = [tuple(map(int,input().split())) for i in range(N)]

nt,na = src[0]
for t,a in src[1:]:
    t1 = -(-nt//t) * t
    a1 = t1 * a // t
    a2 = -(-na//a) * a
    t2 = a2 * t // a
    if t2 < nt or a2 < na:
        nt,na = t1,a1
    else:
        nt,na = t2,a2
print(nt+na)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <functional>
#include <queue>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

int main(){
    int N;
    cin >> N;
    int d[N];
    REP(i, N){
        cin >> d[i];
    }
    sort(d, d + N);

    int count = 1;
    REP(i, N -1){
        if(d[i] < d[i + 1]){
            count++;
        }
    }

    cout << count << endl;
    return 0;
}

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

int main() {
  int y, m , d;
  char s, t;
  cin >> y >> s>> m >> t>> d;

  if(m >= 5) {
    cout << "TBD" << endl;
  } else {
    cout << "Heisei" << endl;
  }

}



















Measured memory_bytes: 3648
a = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)
c = gets.chomp.split.map(&:to_i)
n = gets.chomp.to_i
d = []
n.times { d << gets.to_i }

if d.include?(a[0]) && d.include?(a[1]) && d.include?(a[2])
  puts "Yes"
elsif d.include?(b[0]) && d.include?(b[1]) && d.include?(b[2])
  puts "Yes"
elsif d.include?(c[0]) && d.include?(c[1]) && d.include?(c[2])
  puts "Yes"
elsif d.include?(a[0]) && d.include?(b[0]) && d.include?(c[0])
  puts "Yes"
elsif d.include?(a[1]) && d.include?(b[1]) && d.include?(c[1])
  puts "Yes"
elsif d.include?(a[2]) && d.include?(b[2]) && d.include?(c[2])
  puts "Yes"
elsif d.include?(a[0]) && d.include?(b[1]) && d.include?(c[2])
  puts "Yes"
elsif  d.include?(a[2]) && d.include?(b[1]) && d.include?(c[0])
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 1788
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B___Card_Game_for_Two
{

    /// <summary>
    /// https://atcoder.jp/contests/abc088/tasks/abc088_b
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            int[] a = Console.ReadLine().Split(' ').Select(int.Parse).OrderByDescending(f=>f).ToArray();

            var alicePoint = 0;
            var bobPoint = 0;
            for (int i = 0; i < a.Length; i++)
            {
                if (i % 2 == 0)
                {
                    alicePoint += a[i];
                }
                else
                {
                    bobPoint += a[i];
                }
            }

            // Alice は Bob より何点多く取るか
            var result = alicePoint - bobPoint;

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 13396
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC132
{
    class B
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] p = Console.ReadLine().Split(' ').Select(o => int.Parse(o)).ToArray();
            int counter = 0;
            for(int i = 1; i < n - 1; i++)
            {
                int x = p[i - 1], y = p[i], z = p[i + 1];
                if((x<y && y<z) || (z<y && y < x))
                {
                    counter++;
                }
            }
            Console.WriteLine(counter);
        }
    }
}


Measured memory_bytes: 13396
/* Author: Jason L.(int3xccATgmailDOTcom), Mon Nov 13 14:31:14 CST 2017 */
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using pll = pair<ll, ll>; using dd = long double;
//=========================================================================
namespace {
static bool constexpr dbg =
#ifdef INT3XCC_DEBUG
        1;
#else
        0;
#endif
#define Dprintf(fmt, ...) do{if(dbg) printf(fmt, ##__VA_ARGS__);}while(0)
#define REP0(i, n) for (ll i = 0, ii_ = (n); i <  ii_; ++i)
#define REP1(i, n) for (ll i = 1, ii_ = (n); i <= ii_; ++i)
//=========================================================================
ll constexpr N = 1.1e5;
ll n;
bool vis[N+9];
//=========================================================================
void init() {
    cin>>n;
}
ll bfs() {
    deque<pll> de; de.emplace_back(1, 1);
    while (!de.empty()) {
        ll i = de.front().first, dis = de.front().second; de.pop_front();
        if (!i) return dis;
        vis[i] = true;
        ll nx = (10*i)%n;
        if (!vis[nx]) de.emplace_front(nx, dis);
        nx = (i+1)%n;
        if (!vis[nx]) de.emplace_back(nx, dis+1);
    }
}
void solve() {
    cout<<bfs();
}}
//=========================================================================
int main() {
    if (!dbg) { std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
    cout<<fixed<<setprecision(20); init(); solve(); return 0;
}

Measured memory_bytes: 1408
/*Whose woods these are I think I know.
His house is in the village though;
He will not see me stopping here
To watch his woods fill up with snow.

My little horse must think it queer
To stop without a farmhouse near
Between the woods and frozen lake
The darkest evening of the year.

He gives his harness bells a shake
To ask if there is some mistake.
The only other sound’s the sweep
Of easy wind and downy flake.

The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli a=0ll,b=0ll,c=0ll,k=0ll;
    cin>>a>>b>>c>>k;
    if(k<=(a+b))
        cout<<min(k,a);
    else{
        k-=(a+b);
        cout<<(a-k);
    }
    cout<<endl;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define INIT  ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount

#define int ll

int t, n, m, k, a[300010], q, l, r;



int32_t main(){
INIT
cin>>n>>k;

for(int i=0; i<n; i++){
    cin>>a[i];
}   int sum=0;
sort(a, a+n); for(int i=0; i<k; i++){sum+=a[i];}
cout<<sum;
return 0;
}



Measured memory_bytes: 3656
// 標準入力
var fs = require('fs'),
length = fs.fstatSync(process.stdin.fd).size,
buffer = new Buffer(length),
bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
input = buffer.toString('utf8', 0, bytesRead).trim().split('\n');
main();
    
// ここから
function main(){
  var primeNumbers = calcPrimeNumbers();
  for(var i = 0, len = input.length; i < len; i++){
    console.log(primeNumbers[parseInt(input[i], 10)]);
  }
}
   
function calcPrimeNumbers(){
  var max = 999999;
  var primeNumbers = new Int32Array(max + 1);
   
  // 除外
  primeNumbers[0] = primeNumbers[1] = 0;// ここをこうすると
  // for(var i = 2, maxI = ~~Math.sqrt(max); i <= maxI; i++){
  for(var i = 2; i <= 1000; i++){
  if(primeNumbers[i]){
      continue;
    }
       
    for(var j = (i<<1); j <= max; j+=i){
      primeNumbers[j] = 1;
    }
  }
   
   for(var i = 2; i <= max; i++){
    // これがこうなる
    primeNumbers[i] = primeNumbers[i-1] + 1 - primeNumbers[i];
  }
     
  return primeNumbers;
}

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

int main() {

	int n = 1299709 + 1;
	bool prime[n+1];
  memset(prime, true, sizeof(prime));
 
  for (int p=2; p*p<=n; p++)
  {
      if (prime[p] == true)
      {
          for (int i=p*2; i<=n; i += p)
              prime[i] = false;
      }
  }

  int N;
	while (cin >> N && N != 0) {
		int ans = 0;
		if (N < 2 && N > 1299709) {
			ans = 0;
			cout << ans << '\n';
			continue;
		}

		int l = N, r = N;
		while(!prime[l] || !prime[r]) {
			if (!prime[l])
				l--;
			if (!prime[r])
				r++;
		}
		ans = r-l;
		cout << ans << '\n';
	}

	return 0;
}

Measured memory_bytes: 4232
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

LL solve(LL x) {
    if(x == 0) return 0;
    if(x < 7) return 1;
    if(x < 12) return 2;
    LL y = x/11;
    return y*2+solve(x-11*y);
}

int main() {
    LL x;
    cin >> x;
    cout << solve(x) << endl;
    return 0; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()


int main() {
#ifdef local
	freopen("in.txt", "r", stdin);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int n, i; cin >> n >> i;
	cout << n - (i - 1) << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG


signed main() {
  int N, K, R, S, P; cin >> N >> K >> R >> S >> P;
  string T; cin >> T;
  
  int ans = 0;
  rep(k, K) {
    int t = 1;
    for(int i=k; i<N; i+=K) {
      if(i+K >= N) {
        if(T[i] == 'r') ans += (t+1)/2*P;
        if(T[i] == 's') ans += (t+1)/2*R;
        if(T[i] == 'p') ans += (t+1)/2*S;
        break;
      }
      if(T[i] == T[i+K]) t++;
      else {
        if(T[i] == 'r') ans += (t+1)/2*P;
        if(T[i] == 's') ans += (t+1)/2*R;
        if(T[i] == 'p') ans += (t+1)/2*S;
        t = 1;
      }
      
    }
  }
  
  cout << ans << endl;
        

}


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

using namespace std;

vector<int> graf[1005], cykl;

int poprzednik[1005], odwiedzony[1005];

void dfs(int x){
    odwiedzony[x] = 1;
    for (int i : graf[x]){
        if (odwiedzony[i] == 1){
            vector<int> nowy = {i};
            int pom = x;
            while (pom != i){
                nowy.push_back(pom);
                pom = poprzednik[pom];
            }
            if (!cykl.size() || nowy.size() < cykl.size())
                cykl = nowy;
        }
        if (!odwiedzony[i]){
            poprzednik[i] = x;
            dfs(i);
        }
    }
    odwiedzony[x] = 2;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m, a, b;
    cin >> n >> m;
    for (int i = 0; i < m; i++){
        cin >> a >> b;
        graf[a].push_back(b);
    }
    for (int i = 1; i <= n; i++)
        random_shuffle(graf[i].begin(), graf[i].end());
    for (int i = 1; i <= n; i++)
        if (!odwiedzony[i])
            dfs(i);
    if (!cykl.size()){
        cout << "-1\n";
        return 0;
    }
    cout << cykl.size() << "\n";
    for (int i : cykl)
        cout << i << "\n";
    return 0;
}


Measured memory_bytes: 3808