akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <unistd.h>
#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
#define vecin(a) rep(i,a.size())cin >> a[i]
#define vecout(a) rep(i,a.size())cout << a[i] << " ";cout << "\n"
#define vecvec(a) vector<vector<(a)>>
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const ld pi = 3.14159265358;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
template<class T> inline bool change(T a,T b){if(a > b){swap(a,b);return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const ll cmax = 1000000;
ll fac[cmax], finv[cmax], inv[cmax];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < cmax; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll nCk(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll A,B,N;
    cin >> A >> B >> N;
    ll n = min(N,B - 1);
    cout << A * n / B - n / B * A << "\n";
}

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

int A, B, C;

ll dfs(int A, int B, int C)
{
  ll res = 0ll;
  if ((A & 1) || (B & 1) || (C & 1)) return 0;
  int nextA = (B >> 1) + (C >> 1);
  int nextB = (A >> 1) + (C >> 1);
  int nextC = (A >> 1) + (B >> 1);

  res += dfs(nextA, nextB, nextC);

  return res + 1;
}

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

  cin >> A >> B >> C;

  if (A == B && B == C && A != 1) {
    cout << -1 << endl;
    return 0;
  }

  ll ans = dfs(A, B, C);
  cout << ans << endl; 

  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  
  for(int i=0;i<m;i++){
    int data;
    cin>>data;
    n-=data;
  }
  
  cout<<max(n,-1)<<endl;
  return(0);
}


Measured memory_bytes: 3624
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int X, K;
    cin >> K >> X;
    FOR(i, X - K + 1, X + K)
        cout << i << " ";
    cout << endl;
    return 0;
};


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

#define reps(i,j,k) for(int i=(j);i<(k);i++)
#define rep(i,j) reps(i,0,j)
#define fs first
#define sc second
#define pb push_back
#define mk make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

template<class S,class T>
ostream &operator<<(ostream &out, const pair<S,T> p){
	return out << "(" << p.fs << ", " << p.sc << ")";
}

template<class T>
ostream &operator<<(ostream &out, const vector<T> &v){
	out << "{";
	rep(i,v.size()) out << v[i] << ", ";
	return out << "}" << endl;
}

int main(){
	int m,n;
	cin >> n >> m;
	vi c(n);
	vi q(m+1,0);
	vi eqs(m,0);
	rep(i,n){
		cin >> c[i];
		q[c[i] % m]++;
	}

	int cnt = 0;
	sort(c.begin(),c.end());
	rep(i,n-1){
		if(c[i]==c[i+1])
			eqs[c[i++]%m]+=2;;
	}
	cnt = q[0] / 2;
	reps(i, 1, (m+1)/2){
		int t = min(q[i], q[m-i]);
		cnt += t;
		cnt += min(q[i] - t, eqs[i]) / 2;
		cnt += min(q[m-i] - t, eqs[m-i]) / 2;
	}
	if(m%2==0) cnt += q[m/2] / 2;

	cout << cnt << endl;
	return 0;
}



Measured memory_bytes: 1408
use std::io::{stdin,BufRead,BufReader};

fn main() {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let n = buf.trim().parse::<usize>().unwrap();
    let mut a: Vec<usize> = BufReader::new(stdin()).lines()
        .map(|l| l.unwrap().trim().parse::<usize>().unwrap())
        .collect();
    for (i, &n) in a.iter().enumerate() {
        if n > i {
            println!("-1");
            return;
        }
    }
    a.reverse();
    let mut tmp = n + 1;
    let mut total = 0;
    for i in a {
        if tmp < n + 1 && i + 1 < tmp {
            println!("-1");
            return;
        }
        if i + 1 != tmp {
            total += i;
        }
        tmp = i;
    }
    println!("{}", total);
}


Measured memory_bytes: 6396
#include <stdio.h>

int main(void)
{
    int n, k;
    int ans;

    scanf("%d %d", &n, &k);
                                                                                                                         if(k==1){                                                                                                                printf("%d", 0);                                                                                                 }else{                                                                                                                   printf("%d", n-k);                                                                                               }                                                                                                                
    return 0;
}


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

int main(){
    int N,K,P=0;
    cin >> N >> K;
    set<int> n;
    vector<int> d(10001);
    vector<int> A(10001);
    for(int i=0; i < N ; i++){
        n.insert(i + 1);
    }
    for(int i=0; i < K; i++){
        cin >> d[i];
        for(int j=0; j < d[i]; j++){
            cin >> A[j];
            n.erase(A[j]);
        }
        

    }
    cout << n.size() <<endl;
    return 0;
}

Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
void calc(int &b, int &sum) {
  int a;
  cin >> a;
  if (a % 10) {
    b = min(b, a % 10);
    sum += a / 10 * 10 + 10;
  } else {
    sum += a;
  }
}
int main() {
  int b = 10, sum = 0;
  rep(i,5)
    calc(b, sum);
  if (b == 10) {
    cout << sum;
  } else {
    cout << sum - 10 + b;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		int w=stdIn.nextInt();
		int h=stdIn.nextInt();
		int x=stdIn.nextInt();
		int y=stdIn.nextInt();
		int r=stdIn.nextInt();
		System.out.println(x+r<=w&&x-r>=0&&y+r<=h&&y-r>=0?"Yes":"No");
	}
}


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

int main()
{
  int X, Y, A, B, C, tmp, r_count = 0, flag;
  int64_t ans = 0;
  priority_queue<int> p;
  priority_queue<int> q;
  priority_queue<int> r;

  cin >> X >> Y >> A >> B >> C;
  for (int i = 0; i < A; i++)
  {
    cin >> tmp;
    p.push(tmp);
  }
  for (int i = 0; i < B; i++)
  {
    cin >> tmp;
    q.push(tmp);
  }
  for (int i = 0; i < C; i++)
  {
    cin >> tmp;
    r.push(tmp);
  }
  while (r_count < X + Y)
  {
    if (X == 0)
    {
      if (r.empty())
        flag = 2;
      else
      {
        if (r.top() > q.top())
          flag = 3;
        else
          flag = 2;
      }
    }
    else if (Y == 0)
    {
      if (r.empty())
        flag = 1;
      else
      {
        if (r.top() > p.top())
          flag = 3;
        else
          flag = 1;
      }
    }
    else
    {
      if (r.empty())
      {
        if (p.top() > q.top())
          flag = 1;
        else
          flag = 2;
      }
      else
      {
        if (p.top() >= q.top() && p.top() >= r.top())
          flag = 1;
        else if (q.top() >= p.top() && q.top() >= r.top())
          flag = 2;
        else
          flag = 3;
      }
    }
    if (flag == 1)
    {
      ans += p.top();
      p.pop();
      X--;
    }
    else if (flag == 2)
    {
      ans += q.top();
      q.pop();
      Y--;
    }
    else
    {
      ans += r.top();
      r.pop();
      r_count++;
    }
    flag = 0;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1784
def resolve():
    N, A = list(map(int, input().split()))
    X = [int(i) - A for i in input().split()]
    d = {0: 1}
    for x in X:
        for _sum, count in list(d.items()):
            d[_sum+x] = d.get(_sum+x, 0) + count

    print(d[0]-1)
    


if '__main__' == __name__:
    resolve()



Measured memory_bytes: 3188
import sys
X = int(input())

for i in range(-1000, 1001):
    # print(i)
    for j in range(-1000, 1001):
        # print(i**5 - j**5)
        if (i**5 - j**5) == X:
            print(str(i) + ' ' + str(j))
            sys.exit()


Measured memory_bytes: 9040
import java.util.Scanner

object Main extends App {

  val sc = new Scanner(System.in)

  val (n, m, d) = (sc.nextLong, sc.nextLong, sc.nextLong)

  if (d != 0) {
    printf("%.10f\n", 2.0 * (n - d) * (m - 1) / (n * n))
  } else {
    printf("%.10f\n", 1.0 * (n - d) * (m - 1) / (n * n))
    
  }
}


Measured memory_bytes: 25676
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']
require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

n = sum(gets.chomp.split("").map(&:to_i))
if(n%9 == 0)
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 26220
n = int(input())
As = [int(i) for i in input().split()]
absl = [abs(a) for a in As]

neg = sum(1 for a in As if a < 0)

# print(neg)

if neg % 2 == 0:
    print(sum(absl))
else:
    print(sum(absl) - min(absl) * 2)

Measured memory_bytes: 65184
#include<bits/stdc++.h>
using namespace std;
 
ostream& operator<<(ostream &out, string str) {
	for(char c : str) out << c;
	return out;
}
 
template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) {
	return out << "(" << p.first << ", " << p.second << ")";
}
 
template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
	out << "{";
	for(auto it = a.begin(); it != a.end(); it = next(it))
		out << (it != a.begin() ? ", " : "") << *it;
	return out << "}";
}
 
void dump() { cerr << "\n"; }
template<class T, class... Ts> void dump(T a, Ts... x) {
	cerr << a << ", ";
	dump(x...);
}
 
#ifdef DEBUG
#  define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__)
#else
#  define debug(...) false
#endif
 
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ST first
#define ND second
 
template<class T> int size(T && a) { return a.size(); }
 
using LL = long long;
using PII = pair<int, int>;
 
mt19937 _gen(chrono::system_clock::now().time_since_epoch().count());
int rd(int a, int b) {
	return uniform_int_distribution<int>(a, b)(_gen);
}
 

vector<int> pref(string str) {
	int len = size(str);	
	vector<int> ret(len);
	ret[0] = len;
	int i = 1, m = 0;
	while(i < len) {
		while(m + i < len && str[m + i] == str[m]) m++;
		ret[i++] = m;
		m = (m != 0 ? m - 1 : 0);
		for(int j = 1; ret[j] < m; m--) ret[i++] = ret[j++];
	}
	return ret;
}

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

	int n;
	cin >> n;

	string str;
	cin >> str;

	int ans = 0;
	REP(i, n) {
		vector<int> p = pref(str);
		debug(p);
		FOR(j, 1, n - i - 1) {
			debug(j, p[j]);
			ans = max(ans, min(j, p[j]));
		}
		str.erase(str.begin());
	}

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


Measured memory_bytes: 384
<?php

fscanf(STDIN, '%d %d', $n,$k);

$d = explode(' ', rtrim(fgets(STDIN),PHP_EOL));

//var_dump($d);exit;
//$flg = false;
for ($i=$n;$i<=100000;$i++) {

    $str = str_split($i);
    $cnt = 0;

    foreach ($str as $word) {
        if (in_array($word, $d)){
            continue 2;
        }

        $cnt += 1;

        if($cnt == count($str)){
            print($i);
            exit;
        }
    }

//    echo $i.PHP_EOL;
//    exit;

}

Measured memory_bytes: 5496
#include<bits/stdc++.h>
#define MAXN 2005
#define INF 1e18
using namespace std;
long long W[MAXN],dp[MAXN],N,K,ans=INF;
int main(){
	cin>>N>>K;
	for(long long i=0;i<N;i++){
		cin>>W[i];
		dp[i]=INF;
	}
	for(long long m=0,sum;m<N;m++){
		sum=0;
		for(long long i=0;i<N;i++) dp[i]=min(dp[i],W[(i-m+N)%N]);
		for(long long i=0;i<N;i++) sum+=dp[i];
		ans=min(sum+m*K,ans);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};

int N,A,B,C;
int l[8];
int rec(int d,int a,int b,int c){
	if(d==N){
		cerr << a << " "  << b << " " << c << endl;
		if(min(a,min(b,c))>0){
			return abs(a-A)+abs(b-B)+abs(c-C)-30;
		}else{
			return 1e9;
		}
	}
	int ret0 = rec(d+1,a,b,c);
	int ret1 = rec(d+1,a+l[d],b,c)+10;
	int ret2 = rec(d+1,a,b+l[d],c)+10;
	int ret3 = rec(d+1,a,b,c+l[d])+10;
	return min(ret0,min(ret1,min(ret2,ret3)));
}

int main(){
	cin >> N >> A >> B >> C;
	for(int i=0;i<N;i++) cin >> l[i];
	cout <<rec(0,0,0,0) << endl;
    return 0;
}


Measured memory_bytes: 256
/* include c++ libraries */
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <map>
#include <queue>
#include <set>

/* include c-lang libraries */
#include <climits>
#include <cmath>

/* include my libraries */
//#include <show_vec.hh>

using namespace std;

#define LINE DEBUG{ printf("LINE : %d\n", __LINE__); }
#define DEBUG if(false)

using ll = long long;
template<class T> using vec = vector<T>;

const int MOD = 1000000007;

int main(){
  string S;
  cin >> S;

  int Rs = 0;
  for(int i = 0; i < 3; i++){
    if(S[i] == 'R'){
      Rs++;
    }
  }
  if(Rs == 2){
    if(S[1] == 'S'){
      Rs = 1;
    }
  }
  cout << Rs << endl;
  return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <queue>
#include<map>
#include<algorithm>
#include<set>
#include<iomanip>
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1; i<=n;i++)
#define ALL(a) a.begin(),a.end()
#define PI  acos(-1)
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
typedef long long int ll;
typedef long double ld;
int main() {
    int h, w, d,l,r,q; cin >> h >> w >> d;
    vector<vector<int>> a(h, vector<int>(w));
    vector<pair<int, int>> v(h*w+1);
    rep(i, h) rep(j, w) {
        cin >> a[i][j];
        v[a[i][j] - 1] = make_pair(i,j);
    }vector<int> s(h* w + 1, 0);
    rep(i, h* w -d) {
        s[i + d] += s[i] + abs(v[i].first - v[i + d].first) + abs(v[i].second - v[i + d].second);
    }cin >> q;
    rep(i, q) {
        cin >> l >> r; l--; r--;
        cout << s[r] - s[l] << endl;
    }
}

Measured memory_bytes: 4552
package main
import (
  "fmt"
  "os"
)
func main() {
  var h,w int
  var s string
  var m [][]int
  fmt.Scan(&h,&w)
  m = make([][]int,h+2)
  m[0] = make([]int,w+2)
  m[h+1] = make([]int,w+2)
  for i:=1;i<h+1;i++ {
    m[i] = make([]int,w+2)
    fmt.Scan(&s)
    for j:=1;j<w+1;j++ {
      if s[j-1:j] == "#" {
        m[i][j] = 1
      }
    }
  }
  var sum int
  for i:=1;i<h+1;i++ {
    for j:=1;j<w+1;j++ {
      if m[i][j] == 1 {
        sum = m[i-1][j]+m[i+1][j]+m[i][j-1]+m[i][j+1]
        if sum == 0 {
          fmt.Println("No")
          os.Exit(0)
        }
      }
    }
  }
  fmt.Println("Yes")
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
#include <iomanip>

using namespace std;

int main(int argc, char* argv[])
{

	int x;

	cin >> x;
  
    cout << ((x<1200) ? "ABC" : "ARC") << endl;

	return 0;

}

Measured memory_bytes: 256
#include <stdio.h>
 
using namespace std;
 
int main(){
    int a,b;
    char op;
    while(true){
        scanf("%d %c %d",&a,&op,&b);
        if(op == '?') break;
        switch(op){
        case '+':
            printf("%d\n",a+b);
            break;
        case '-':
            printf("%d\n",a-b);
            break;
        case '/':
            printf("%d\n",a/b);
            break;
        case '*':
            printf("%d\n",a*b);
            break;
        }
    }
}


Measured memory_bytes: 2708
#include <iostream>
using namespace std;
int main() {
  int a,n,sum,min,max,i;
  while(1){
  cin >>n;
  if (n==0){
    break;
  }
  cin >>min;
  sum=min;
  max=min;
  for (i=0;i<n-1;i++){
    cin>>a;
    sum=sum+a;
    if(min>a){
      min=a;
    }
    if(max<a){
      max=a;
    }
  }
  cout <<(sum-max-min)/(n-2)<<endl;
  }
  return 0;
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int x = 4;
    map<char, int> s;
    for(int i = 0; i< x; i++)
    {
        char c;
        cin>>c;
        s[c]++;
    }

    if(s.size()==2)
    {
        for(auto t:s)
        {
            if(t.second!=2)
            {
                cout<<"No";
                return 0;
            }
        }
        cout<<"Yes";
        return 0;
    }
    else
        cout<<"No";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pci pair<char, int>
#define pic pair<int, char>
#define plvl pair<long long, vector<long long> >
#define pcvc pair<char, vector<char> >


using namespace std;

const int mod = 1e9 + 7;

ll gcd(ll a, ll b) {
	if(b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

template <typename T>
void show1(vector<T> dp) {
	for(auto d : dp) {
		cout << d << " ";
	}
	cout << endl;
}

template <typename T>
void show2(vector<vector<T> > dp) {
	for(auto d : dp) {
		for(auto dd : d) {
			cout << dd << " ";
		}
		cout << endl;
	}
}

void executeCode() {
	int n, k;
	cin >> n >> k;
	vector<int> vec(n);
	for(int i = 0 ; i < n ; i++) {
		cin >> vec[i];
	}
	sort(vec.begin(), vec.end());
	ll ans = 0;
	int i = 0;
	while(i < vec.size() && k--) {
		ans += vec[i];
		i++;
	}
	cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
	int tt = 1;
	// cin >> tt;
	while(tt--) {
		executeCode();	
	}
	return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
int main(void)
{
	int a[28],i,j,b[30];
	for(i=1;i<31;i++){
		b[i-1]=i;
	}
	for(i=0;i<28;i++){
		scanf("%d",&a[i]);
		for(j=0;j<30;j++){
			if(a[i]==b[j]){
				b[j]=0;
			}
		}
	}
	for(i=0;i<30;i++){
		if(b[i]!=0){
			printf("%d\n",b[i]);
		}
	}
	return 0;
}


Measured memory_bytes: 2104
#include <iostream>
using namespace std;
string s;
int c;
int main() {
	cin>>s;
	for(int i=0; s[i]; i++) {
		if(i%2==0 && s[i]=='0') c++;
		if(i%2==1 && s[i]=='1') c++;
	}
	cout<<min(c, (int)s.size()-c);
	return 0;
}

Measured memory_bytes: 512
package main

import (
	"fmt"
)

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

	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&arr[i])
	}

	count := 1
	current := 0
	for i := 1; i <= n; i++ {
		current = current + arr[i-1]
		if current <= x {
			count++
		} else {
			break
		}
	}

	fmt.Println(count)
}


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

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


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

int main() {
    int x, n;
    cin >> n;
    vector<int> boss(n, 0);
    for(int i = 1; i < n; ++i) {
        cin >> x;
        boss[x-1]++;
    }
    for(int i = 0; i < n; ++i) {
        cout << boss[i] << endl;
    }
    return 0;
}

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

string a, b, c;
int x, y, z;

int main () {
	cin >> a >> b >> c;
	char s1 = a[0];
	char s2 = b[0];
	char s3 = c[0];
	x = (int)s1 - 32;
	y = (int)s2 - 32;
	z = (int)s3 - 32;
	cout << (char)x << (char)y << (char)z;
}

Measured memory_bytes: 3596
import sys

sys.setrecursionlimit(10000000)
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue
from decimal import Decimal
# import fractions

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
dl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B = sl()
    A = Decimal(A)
    B = Decimal(B)
    print(int(A*B))


if __name__ == '__main__':
    main()


Measured memory_bytes: 10828
<?php

	$data = explode(" ", trim(fgets(STDIN)));
	$n = $data[0];
	$m = $data[1];
	$s = trim(fgets(STDIN));
	$t = trim(fgets(STDIN));
	
	$a = max($n, $m);
	$b = min($n, $m);
	while($b>0){
	    $tmp = $a;
	    $a = $b;
	    $b = $tmp % $b;
	}
	$ans = $n / $a * $m;
	$c = 0;
	$x = $n / $a;
	$y = $m / $a;
	while($c<$a){
	    if($s[$x*$c] !== $t[$y*$c]) $ans = -1;
	    $c++;
	}
	echo $ans;
?>

Measured memory_bytes: 4728
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int h, w;
char m[21][21];

int bfs(int x, int y) {
  queue<P> que;
  que.push(make_pair(x, y));

  int memo[21][21];
  REP(i, h) REP(j, w) memo[i][j] = INF;
  memo[x][y] = 0;

  int ma = 0;
  while(!que.empty()) {
    P p = que.front(); que.pop();
    int sx = p.first; int sy = p.second;

    REP(i, 4) {
      int nx = sx + dx4[i], ny = sy + dy4[i];
      if(nx >= 0 && nx < h && ny >= 0 && ny < w) {
        if(memo[nx][ny] == INF && m[nx][ny] == '.') {
          if(memo[nx][ny] > memo[sx][sy] + 1) {
            memo[nx][ny] = memo[sx][sy] + 1;
            ma = max(ma, memo[nx][ny]);
          }
          que.push(make_pair(nx, ny));
        }
      }
    }
  }
  return ma;
}

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

  cin >> h >> w;
  REP(i, h) {
    REP(j, w) {
      cin >> m[i][j];
    }
  }

  int ans = 0;
  REP(i, h) {
    REP(j, w) {
      if(m[i][j] == '.') ans = max(ans, bfs(i, j));
    }
  }

  cout << ans << endl;
}


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

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

int f(int x){
    int res = 0;
    while(x%2 == 0) {
        x /= 2;
        res++;
    }
    return res;
}

int main(void){
    int n,m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    rep(i,n){
        if(a[i]%2 == 1){
            cout << 0 << endl;
            return 0;
        }
        a[i] /= 2;
    }

    int t = f(a[0]);
    rep(i,n) {
        if (f(a[i]) != t) {
            cout << 0 << endl;
            return 0;
        }
        a[i] >>= t;
    }
    m >>= t;

    ll l = 1;
    rep(i,n) {
        l = lcm(l, a[i]);
        if (l > m) {
            cout << 0 << endl;
            return 0;
        }
    }

    m /= l;
    int ans = (m+1)/2;
    cout << ans << endl;
    return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;

  int N2 = a * b % 2;
  if (N2 == 0) {
    cout << "Even" << endl;
  } else {
    cout << "Odd" << endl;
  }
}


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

typedef pair<ll, ll> pll;

const int MAX_PRIME = 2000000;
vector<int> primes;
vector<bool> is_prime;
// 小さい素数(MAX_PRIMEまで)は先に用意しとく
void init_primes() {
  is_prime = vector<bool>(MAX_PRIME + 1, true);
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= MAX_PRIME; i++) {
    if (is_prime[i]) {
      primes.push_back(i);
      for (int j = i*2; j <= MAX_PRIME; j+=i) {
        is_prime[j] = false;
      }
    }
  }
}

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

  init_primes();

  ll a,b;cin>>a>>b;
  // std::vector<pll> v1,v2;
  set<ll> st;
  for(int i=0;i<primes.size();i++){
    // int cnt=0;
    int v = primes[i];
    while(a && a%v==0){
      st.insert(v);
      // cout<<v<<endl;
      a/=v;
      // cnt++;
    }
    // if(cnt){
    //   v1.push_back({v, cnt});
    // }
  }
  if(a!=1)st.insert(a);
  int res=1;
  for(int i=0;i<primes.size();i++){
    // int cnt=0;
    int v = primes[i];
    bool used=false;
    while(b && b%v==0){
      if(st.count(v) && !used){
        // cout<<v<<endl;
        used=true;
        res++;
      }
      b/=v;
      // cnt++;
    }
    // if(cnt){
    //   v2.push_back({v, cnt});
    // }
  }
  if(b!=1 && st.count(b))res++;

  cout<<max(1, res)<<endl;

  return 0;
}


Measured memory_bytes: 1656
#include <iostream>
using namespace std;
   
int F[102][102];
int xg,yg,w,h;
   
   
void DFS(int Y,int X,int c){
  //if(Y < 1 || X < 1)
    //return;
  if(F[Y][X] != c){
    return;
  }
   
  F[Y][X] = -1;
  DFS(Y+1,X  ,c);
  DFS(Y-1  ,X,c);
  DFS(Y,X+1  ,c);
  DFS(Y  ,X-1,c);
}
   
   
int main(){
  int xs,ys,n;
  while(1){
    cin >> w >> h;
    if(w == 0 && h == 0)
      break;
for(int i=0; i<103; i++){
      for(int j=0; j<103; j++){
        F[i][j] = 10;
      }
    }
       F[0][104] = 0;
    cin >> xs >> ys >> xg >> yg >> n;
   
   
    for(int i=0;i<n;i++){
      int c,d,x,y;
      cin >> c >> d >> x >> y;
      if(c == 0)
         c = 1919810;
      if(d == 0){
        for(int j=0;j<4;j++){
          F[x+j][y] = c;
          F[x+j][y+1] = c;
        }
      } else {
        for(int j=0;j<4;j++){
          F[x][y+j] = c;
          F[x+1][y+j] = c;
        }
      }
    }
  DFS(xs,ys,F[xs][ys]);
   
  if(F[xg][yg] == -1){
    cout << "OK" << endl;
  } else {
    cout << "NG" <<endl;
  }
  }
}


Measured memory_bytes: 3736
#include<bits/stdc++.h>
using namespace std;
string m[110];
bool mycmp(string a,string  b)
{
	return (a<b);
}
int main()
{
	int n,l;
	cin>>n>>l;
	for(int i=1;i<=n;i++)
	{
		cin>>m[i];
	}
	sort(m+1,m+n+1,mycmp);
	for(int i=1;i<=n;i++)
	{
		cout<<m[i];
	}
	return 0; 
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;
using Debug = System.Diagnostics.Debug;


static class P
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var v = a.GroupBy(x => x).Where(x => x.Count() >= 2).OrderByDescending(x => x.Key).ToArray();
        if (v.Length < 2)
        {
            Console.WriteLine(0);
            return;
        }
        if (v[0].Count() < 4)
        {
            Console.WriteLine(v[0].Key * v[1].Key);
            return;
        }
        {
            Console.WriteLine(v[0].Key * v[0].Key);
            return;
        }
    }
}

Measured memory_bytes: 35164
import static java.lang.System.out;
import java.util.Scanner;

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

        int h = S / 3600;
        int m = (S - h * 3600) / 60; 
        int s = S - (h * 3600 + m * 60);                                        

        out.printf("%d:%d:%d%n", h, m ,s);
    }   
}

Measured memory_bytes: 26236
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

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

# 解説
H, W, A, B = list(map(int, sys.stdin.readline().split()))
if H % A == 0 and W % B == 0:
    # 前提より、A*Bの範囲ずつ見ていくと絶対マイナスになっちゃう
    print('No')
    exit()


# 条件を満たす数列の累積和を構成
def cumsum(S, s):
    ret = np.zeros(S + 1, dtype=int)
    n = 0
    for i in range(0, len(ret), s):
        ret[i] = n
        n -= 1
    for a in range(1, s):
        n = 1e7
        for i in range(a, len(ret), s):
            ret[i] = n
            n -= 1
    return ret


print('Yes')
if H % A != 0:
    col = np.diff(cumsum(H, A))
    ans = np.tile(col, W).reshape(W, H).T
else:
    col = np.diff(cumsum(W, B))
    ans = np.tile(col, H).reshape(H, W)
print('\n'.join(map(lambda r: ' '.join(r), ans.astype(str))))


Measured memory_bytes: 40120
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>       // for next_permutation
#include <vector>
#include <cstdlib>
#define INF 998244353

using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pi;

const ll MOD = 1e9+7;

static long gcd(long a, long b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}
/*
long long int facctorialMethod(int k){//階乗
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}*/

long long int tousasum(long long int n){//等差数列
    return n*(n+1)/2;
}

unsigned GetDigit(unsigned num){//桁数
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

bool IsPrime(int num)//素数判定
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

map< ll, ll > prime_factor(ll n) {//素因数分解
    map< ll, ll > ret;
    for(ll i = 2; i * i <= n; i++) {
        while(n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if(n != 1) ret[n] = 1;
    return ret;
}

ll calcNumOfCombination(ll n, ll r){
    ll num = 1;
    for(ll i = 1; i <= r; i++){
        num = num * (n - i + 1) / i;
    }
    return num;
}

int bubblesort(vector<int> array,int size){//バブルソート　転倒数
    int kaisu = 0;
    for(int i = 0; i < size; i++){
        for(int j = i + 1; j < size; j++){
            if(array[i] > array[j]){
                int number = array[i];
                array[i] = array[j];
                array[j] = number;
                kaisu++;
            }
        }
    }
    return kaisu;
}

ll facctorialMethod(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum = (sum * i)%MOD;
    }
    return sum;
}

// nPnの順列に対して処理を実行する
void foreach_permutation(int n, std::function<void(int *)> f) {
    int indexes[n];
    for (int i = 0; i < n; i++) indexes[i] = i;
    do {
        f(indexes);
    } while (std::next_permutation(indexes, indexes + n));
}

int main(){
    int N;
    cin >> N;
    int x[N];
    int y[N];
    for(int i=0;i<N;i++){
        cin >> x[i];
        cin >> y[i];
    }
    vector<double> results;
    vector<int> v(N);
    long double answer = 0.0;
    iota(v.begin(), v.end(), 1);
    double exp = 0.0;// v に 1, 2, ... N を設定
    do {
        double result = 0.0;
/*
        for(auto x:v){
            cout << x ;
        }*/
        for(int i=0;i<N-1;i++){
            result+=sqrt((x[v[i]-1]-x[v[i+1]-1])*(x[v[i]-1]-x[v[i+1]-1])+ (y[v[i]-1]-y[v[i+1]-1])*(y[v[i]-1]-y[v[i+1]-1]));
        }

        exp++;

        answer += result;
        //cout << answer << endl;
        results.push_back(result);
    } while( next_permutation(v.begin(), v.end()) );




    answer = answer / exp;

    printf("%.10Lf",answer);


}





Measured memory_bytes: 892
def main():
    n = int(input())

    dices = []
    for i in range(n):
        dices.append(Dice(list(map(int, input().split(' ')))))

    if not equals_any(dices):
        print('Yes')
    else:
        print('No')

def equals_any(dices):
    for i, d1 in enumerate(dices):
        for d2 in [d for d in dices[i+1:]]:
            if equals(d1, d2):
                return True

    return False

def equals(d1, d2):
    for i in range(4):
        for j in range(4):
            if d1.equals(d2):
                return True
            d2.toE()
        d2.toN()

    d2.toE().toN()

    for i in range(2):
        for j in range(4):
            if d1.equals(d2):
                return True
            d2.toE()
        d2.toN().toN()

    return False

class Dice:
    def __init__(self, labels):
        self.labels = labels

        self._tb = (0, 5)
        self._fb = (1, 4)
        self._lr = (3, 2)

    def toN(self):
        tb = self._tb
        self._tb = self._fb
        self._fb = tuple(reversed(tb))

        return self

    def toS(self):
        tb = self._tb
        self._tb = tuple(reversed(self._fb))
        self._fb = tb

        return self

    def toW(self):
        tb = self._tb
        self._tb = tuple(reversed(self._lr))
        self._lr = tb

        return self

    def toE(self):
        tb = self._tb
        self._tb = self._lr
        self._lr = tuple(reversed(tb))

        return self

    def get_top(self):
        return self.labels[self._tb[0]]

    def get_bottom(self):
        return self.labels[self._tb[1]]

    def get_front(self):
        return self.labels[self._fb[0]]

    def get_back(self):
        return self.labels[self._fb[1]]

    def get_left(self):
        return self.labels[self._lr[0]]

    def get_right(self):
        return self.labels[self._lr[1]]

    top    = property(get_top)
    bottom = property(get_bottom)
    front  = property(get_front)
    back   = property(get_back)
    left   = property(get_left)
    right  = property(get_right)

    def equals(self, other):
        if not (self.top == other.top and self.bottom == other.bottom):
            return False

        if not (self.front == other.front and self.back == other.back):
            return False

        if not (self.left == other.left and self.right == other.right):
            return False

        return True

    def __str__(self):
        return str([self.top, self.front, self.right, self.left, self.back, self.bottom])

if __name__ == '__main__':
    main()

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

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

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

int main() {
    int n;
    cin >> n;
    set<int> st;
    for (int i = 0;i < n;++i) {
        int a;
        cin >> a;
        st.insert(a);
    }
    cout << st.size() << endl;
}


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


int main() {
  string s, t;
  cin >> s >> t;
  int A, B;
  cin >> A >> B;
  string u;
  cin >> u;
  
  if(u == s){
    cout << A - 1 << " " << B;
  }
  else{
    cout << A << " " << B - 1;
  }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int r = 0;

    r += x / 500 * 1000;
    x %= 500;

    r += x / 5 * 5;
    x %= 5;

    cout << r << endl;

    return 0;
}

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

int main(){
  int age,b;
  cin >> age >> b;
  if(age >= 13){
    cout << b << endl;
  }else if(age >= 6){
    cout << b / 2 << endl;
  }else{
    cout << 0 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    ll n, k; cin >> n >> k;

    ll tmp = 0;
    ll arr[100001]; INITA(arr, 0, 100000, 0);
    REP(i, n) {
        ll a, b; cin >> a >> b;
        arr[a] += b;
    }
    FOR(i, 1, 100000) {
        if (k <= arr[i]) {
            cout << i << endl;
            return 0;
        }
        k -= arr[i];
    }
    return 0;
}

Measured memory_bytes: 4324
a = input()
b = []
count = 0
a = a.replace('BC','D')
for i in range(1,len(a)+1):
    if a[-i] == 'D':
        count += 1
    elif a[-i] == 'A':
        b.append(count)
    else:
        count = 0
print(sum(b))

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


long long int  func(long long int n, long long int r) 
{ 

 
  long long int p = 1, k = 1; 

  
  if (n - r < r) 
    r = n - r; 

  if (r != 0) { 
    while (r) { 
      p = 1LL*p*n; 
      k = 1LL*k*r; 

      // gcd of p, k 
      long long int m = __gcd(p, k); 

      // dividing by gcd, to simplify product 
      // division by their gcd saves from the overflow 
      p /= m; 
      k /= m; 

      n--; 
      r--; 
    } 
  } 

  else
    p = 1; 

   return p;
} 


int main()
{


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

    int total;
    cin>>total;
    vector<long long int >nish;
    for(int i=0;i<total;i++)
    {
      long long int first;
      cin>>first;
      nish.push_back(first);
    }

    for(int i=0;i<total;i++)
    {
      if(nish[i]==0)
      {
        cout<<"0"<<endl;
        return 0;
       }
    }


    long double d=0;
    for(int i=0;i<total;i++)
    {
      d+=log10(nish[i]);
    }
    if(d>18.1)
    {
      cout<<"-1"<<endl;
      return 0;
    }

    long long int ans=1;
    for(int i=0;i<total;i++)
      {
        ans=1LL*ans*nish[i];
      }

      if(ans>1000000000000000000)
      {
        cout<<"-1"<<endl;
        return 0;
      }
      cout<<ans<<endl;


return 0;
}


Measured memory_bytes: 4280
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();
        int [] X = new int[N];
        int [] Y = new int[N];
        
        for(int i=0; i<N; i++){
            X[i] = sc.nextInt();
            Y[i] = sc.nextInt();
        }
        
        int count =0;
        
        for(int i=0; i<N; i++){
            if(Math.pow(X[i],2)+Math.pow(Y[i],2)<=Math.pow(D,2)){
                count++;
            }
        }
        
        System.out.println(count);
    }
}


Measured memory_bytes: 61076
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

typedef long long int ll;
const long long LINF = 1LL<<55;

int main(){
    int a, b, q;
    cin >> a >> b >> q;
    vector<ll> s(a + 2), t(b + 2);
    for(int i = 1; i <= a; i++){
        cin >> s[i];
    }
    for(int i = 1; i <= b; i++){
        cin >> t[i];
    }
    s[0] = t[0] = -LINF;
    s.back() = t.back() = LINF;
    for(int i = 0; i < q; i++){
        ll x, ans = LINF;
        cin >> x;
        auto itr1 = lower_bound(begin(s), end(s), x);
        auto itr2 = lower_bound(begin(t), end(t), x);
        for(auto i = itr1 - 1; i <= itr1; i++){
            for(auto j = itr2 - 1; j <= itr2; j++){
                ll s = abs(*i - x) + abs(*i - *j);
                ll t = abs(*j - x) + abs(*j - *i);
                ans = min({ans, s, t});
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

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

int main() {
	int n, k; scanf("%d%d", &n, &k); std::vector<int> p(n);
	for(auto& v: p) scanf("%d", &v);
	sort(begin(p), end(p));

	int ans = 0;
	for(int i = 0; i < k; i++) ans += p[i];
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3792
n,m,c = map(int,input().split())
b,*a = [list(map(int,input().split())) for _ in range(n+1)]
res=0
for i in range(n):
  sum=0
  for j in range(m):
    sum+=a[i][j]*b[j]
  if sum+c>0:
    res+=1
print(res)

Measured memory_bytes: 62340
#include<cstdio>
#define MAX 10000
#define NIL -1

struct Node { int parent, left, right; };

Node T[MAX];
int n, H[MAX], D[MAX];


int setHeight(int u) {
  int h1 = 0, h2 = 0;
  if ( T[u].left != NIL ) h1 = setHeight(T[u].left) + 1;
  if ( T[u].right != NIL ) h2 = setHeight(T[u].right) + 1;
  return H[u] = ( h1 > h2 ? h1 : h2 );
}

void setDepth(int u, int d) {
  if ( u == NIL ) return;
  D[u] = d;
  setDepth(T[u].left, d + 1);
  setDepth(T[u].right, d + 1);
}

int getSibling(int u) {
  if ( T[u].parent == NIL ) return NIL;
  if ( T[T[u].parent].left != u && T[T[u].parent].left != NIL )
    return T[T[u].parent].left;
  if ( T[T[u].parent].right != u && T[T[u].parent].right != NIL )
    return T[T[u].parent].right;
  return NIL;
}

void print(int u) {
  printf("node %d: ", u);
  printf("parent = %d, ", T[u].parent);
  printf("sibling = %d, ", getSibling(u));
  int deg = 0;
  if ( T[u].left != NIL ) deg++;
  if ( T[u].right != NIL ) deg++;
  printf("degree = %d, ", deg);
  printf("depth = %d, ", D[u]);
  printf("height = %d, ", H[u]);
  if ( T[u].parent == NIL ) printf("root\n");
  else if ( deg > 0 ) printf("internal node\n");
  else printf("leaf\n");
}

int main() {
int i, v, l, r, root = 0;
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) T[i].parent = NIL;

  for ( i = 0; i < n; i++ ) {
    scanf("%d %d %d", &v, &l, &r);
    T[v].left = l;
    T[v].right = r;
    if ( l != NIL ) T[l].parent = v;
    if ( r != NIL ) T[r].parent = v;
  }

  for ( i = 0; i < n; i++ ) if ( T[i].parent == NIL ) root = i;

  setHeight(root);
  setDepth(root, 0);

  for ( i = 0; i < n; i++ ) print(i);

  return 0;
}

Measured memory_bytes: 2760
n = int(input())
ant = 0
if n == 0:
    ant = 1
ans = ''
for i in range(10000):
    if n == 0:
        break
    if n % 2 ** (i + 1) == 0: 
        ans = '0' + ans
    else:
        n -= (-2)**i
        ans = '1' + ans
if ant == 0:
    print(ans)
else:
    print('0')

Measured memory_bytes: 3060
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    const A = arg[1].split(" ").map(n=>parseInt(n));
    
    // 逆から考える
    A.reverse();
    
    let answer = [];
    let list = [];
    
    for(let i in A) {
        let alreadyIn = 0;
        
        for(let j=i-(N - i); j>=0; j -= (N - i)) {
            if(list[j] === 1) {
                alreadyIn++;
            }
        }

        if(alreadyIn % 2 === 0) {
            if(A[i] !== 0) {
                answer.push(N - i);
                list.push(1);
            } else {
                list.push(0);
            }
        } else {
            if(A[i] === 0) {
                answer.push(N - i);
                list.push(1);
            } else {
                list.push(0);
            }
        }
    }

    const cnt = answer.length;
    answer.sort((a,b)=>a-b);

    console.log(cnt);
    console.log(answer.join("\n"));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 37680
import sys
from pprint import pprint

from collections import Counter
from math import factorial

def nCr(n, r):
    return factorial(n) // factorial(r) // factorial(n - r)

N = int(sys.stdin.readline())
S = sys.stdin.readline().strip()
# print(len(S))

counter = Counter(S)
if len(counter) != 3:
    print("0")
    sys.exit()
rgb_count = 0

max_width = len(S) // 2
for width in range(1, max_width+1):
    max_left = len(S) - 2 * width
    # print(width, max_left)
    for i in range(max_left):
        if len(set([S[i], S[i+width], S[i+2*width]])) == 3:
            rgb_count += 1


all_count = nCr(counter["R"], 1) * nCr(counter["G"], 1) * nCr(counter["B"], 1) 
# print(all_count, rgb_count)
print(all_count - rgb_count)

Measured memory_bytes: 69948
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <algorithm>
#include <stdio.h>
#include <functional>
using namespace std;
 
int main()
{
	int n;
	cin >> n;

	string taro, hanako;
	int tarop = 0, hanakop = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> taro >> hanako;

		if (taro > hanako)
		{
			tarop += 3;
		}
		else if (taro < hanako)
		{
			hanakop += 3;
		}
		else
		{
			tarop++;
			hanakop++;
		}
	}

	cout << tarop << " " << hanakop << endl;
	return 0;
}

Measured memory_bytes: 1208