akhauriyash/Code-Regression huggingface dataset:
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N := nextInt()
	an := make([]int, 0)
	for N > 0 {
		N--
		an = append(an, N%26+'a')
		N /= 26
	}
	ans := make([]rune, len(an))
	for i := 0; i < len(an); i++ {
		ans[len(ans)-1-i] = rune(an[i])
	}
	fmt.Println(string(ans))
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

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

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}

func Reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}


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

n = int(input().rstrip())
P = [int(x) for x in input().rstrip().split()]
Q = [int(x) for x in input().rstrip().split()]
cnt = [1 if i > 0 else 0 for i in range(0, n + 1)]
fact = [1]
for i in range(1, n+1):
    fact.append(fact[i-1] * i)

ord_P = 0
for i in range(0, n):
    cnt[P[i]] -= 1
    ord_P += sum(cnt[:P[i]+1]) * fact[n - i - 1]

ord_Q = 0
cnt = [1 if i > 0 else 0 for i in range(0, n + 1)]
for i in range(0, n):
    cnt[Q[i]] -= 1
    ord_Q += sum(cnt[:Q[i]+1]) * fact[n - i - 1]

print(abs(ord_P - ord_Q))


Measured memory_bytes: 38256
#include <iostream>

using namespace std;

int main(){
        bool a=false,b=false,c=false,d=false;
    for(int i=0;i<4;i++){
        int x;
        cin >> x;
        switch (x)
        {
        case 1:
            a = true;
            break;
        case 9:
            b = true;
            break;
        case 7:
            c = true;
            break;
        case 4:
            d = true;
            break;
        }
    }
    if(a&&b&&c&&d){
        cout <<"YES" <<endl;
    }
    else{
        cout <<"NO"<<endl;
    }
}

Measured memory_bytes: 256
N, A, B = map(int, input().split())
score = 0
count = 0
for i in range(1, N+1):
    score = 0
    number = i
    while i > 0:
        score += i%10
        i = int(i/10)
    if score >= A and score <=B:
        count += number
print(count)

Measured memory_bytes: 2940
#include<algorithm>
#include<functional>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

typedef unsigned long long ull;
typedef long long ll;

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

using namespace std;

typedef pair<int ,int > P;

stack<int> sta;

int main()
{
	int n;
	while(cin>>n)
	{
		if(n==0)
		{
			cout<<sta.top()<<endl;
			sta.pop();
		}
		else
			sta.push(n);
	}


	return 0;
}

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

int main() {
  string S;
  cin >> S;
  string answer = "TBD";
  if (S.at(5) == '0') {
    if (S.at(6)=='1' || S.at(6)=='2' || S.at(6)=='3' || S.at(6)=='4') {
      answer = "Heisei";
    }
  }
  cout << answer << endl;
}

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

double a, b;
double A[7] = {35.5, 37.5, 40.0, 43.0, 50.0, 55.0, 70.0};
double B[7] = {71.0, 77.0, 83.0, 89.0, 105.0, 116.0, 148.0};
string S[8] = {"AAA", "AA", "A", "B", "C", "D", "E", "NA"};

int main() {
  while(cin >> a >> b) {
    int ra, rb;
    for(ra = 0; ra < 7 && !(a < A[ra]); ++ra);
    for(rb = 0; rb < 7 && !(b < B[rb]); ++rb);
        cout << S[max(ra,rb)] << endl;
  }
  return 0;
}

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

using namespace std;

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


Measured memory_bytes: 4772
#include<stdio.h>
int main(){
    int H, W;
    while(1){
    scanf("%d %d",&H,&W);
	if(H==0 && W==0) break;
	for(int i=1;i<=W;i++){
		printf("#");
	}
	printf("\n");
	for(int k=1;k<=H-2;k++){
	printf("#");
	for(int i=1;i<=W-2;i++){
		printf(".");
	}
	printf("#\n");
	}
	for(int i=1;i<=W;i++){
		printf("#");
	}
	printf("\n\n");
	}
}



Measured memory_bytes: 2036
#include<iostream>

using namespace std;

int main() {
    int N;

    cin >> N;

    int d[N];

    for(int i = 0; i < N; i++) {
        cin >> d[i];
    }

    int ans = 0;

    for(int i = 0; i < N - 1; i++) {
        for(int j = i + 1; j < N; j++) {
            ans += d[i] * d[j];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long n;
   cin>>n;
   int ar[n];
   for(int i=0;i<n;i++)
   {
       cin>>ar[i];
   }
   long long a,val=0;
   a=ar[0];
   for(int j=1;j<n;j++)
   {
       if(ar[j]<a)
       {val=val+a-ar[j];}
       else
       {
           a=ar[j];
       }
       
   }
   cout<<val;
}

Measured memory_bytes: 4356
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(all(a));

    ll ans = 0;
    if (n % 2 == 0){
        rep(i, 2){
            vector<ll> b, c;
            b.push_back(a[n/2 - i]);
            c.push_back(a[n/2 - i]);
            int left = 0, right = n-1;
            while(left < n /2 - 1){
                b.push_back(a[right]);
                b.push_back(a[left]);
                c.push_back(a[left++]);
                c.push_back(a[right--]);
            }
            b.push_back(a[n/2 - 1 + i]);
            c.push_back(a[n/2 - 1 + i]);
            ll sum1 = 0, sum2 = 0;
            rep(i,n-1) {
                sum1 += abs(b[i] - b[i+1]);
                sum2 += abs(c[i] - c[i+1]);
            }
            ans = max(ans, sum1);
            ans = max(ans, sum2);
        }        
    }else{
        vector<ll> b, c;
        b.push_back(a[n/2]);
        c.push_back(a[n/2]);
        int left = 0, right = n-1;
        while(left < n /2){
            b.push_back(a[right]);
            b.push_back(a[left]);
            c.push_back(a[left++]);
            c.push_back(a[right--]);
        }
        ll sum1 = 0, sum2 = 0;
        rep(i,n-1) {
            sum1 += abs(b[i] - b[i+1]);
            sum2 += abs(c[i] - c[i+1]);
        }
        ans = max(ans, sum1);
        ans = max(ans, sum2);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6936
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int n,m;
vector<vector<int>> G;
long  double dp[601],ans=700;
void f(int block)
{
    dp[n-1]=0;
    for(int i=n-2;i>=0;i--)
    {
        int deg=G[i].size();
        long double mn=0,sum=0;
        for(auto v:G[i])
        {
            mn=max(mn,dp[v]);
           sum+=dp[v];
        }
        if(i==block&&deg>=2)
        {
            sum-=mn;
            deg--;
        }
        dp[i]=1+sum/deg;

    }
    ans=min(ans,dp[0]);
}
int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    cin>>n>>m;
    G.resize(n);
    for(int i=0;i<m;i++)
    {
        int s,t;
        cin>>s>>t;
        --s,--t;
        G[s].push_back(t);
    }
    for(int i=0;i<n;i++)
        f(i);
    cout<<fixed<<setprecision(10)<<ans;
    return 0;
}


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

using namespace std;
using ll = long long;
int main()
{
    ios::sync_with_stdio(0);
    
    ll x , a;
    cin >> x >> a;
    if(x<a)
        cout << "0\n";
    else
    {
            cout << "10\n";
    }
    
        return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  CoderWork
//
//  Created by Minoru Hayashi on 2020/02/29.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//

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

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

template<class T> inline bool chmin(T& a, T b){ if(a>b){a=b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b){ if(a<b){a=b; return 1;} return 0;}


const int INF = 1LL<<29;

//#define __DBG__


void solve(void){

  int N, W;
  cin >> N >> W;
  
  vector<vector<ll>> DP(N+1,vector<ll>(W+1)); 
  vector<int> v(N+1), w(N+1);
  
  REP(i,N) {
    cin >> w[i] >> v[i];
  }
  
 
  REP(i,N){
	REP(j,W+1){
      if(j>=w[i]){
        DP.at(i+1).at(j) = max(DP.at(i).at(j-w[i])+v[i], DP.at(i).at(j));
      }
      else
      {
        DP.at(i+1).at(j) = DP.at(i).at(j);
      }
    }
  }

  cout << DP.at(N).at(W) << endl;

  return;
}


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


    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
  
    solve();
 
    return 0;
}




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


#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 2019
ll power(ll x, ll y){
    ll res = 1;
    while(y>0){
        if(y&1)res=(res*x)%mod;
        y=y>>1;
        x = (x*x)%mod;
    }
    return res;
}


int main(){
    IOS;
    string s;
    cin >> s;
    map <int, int> mp;
    int n = s.length();
    ll curr_sum=0;
    mp[0]++;
    for(int i = n-1 ;i  >= 0 ; i--){
        curr_sum = (curr_sum + ((s[i]-'0')*power(10,n-1-i))%mod)%mod;
        mp[curr_sum]++;
    }
    long long int ans = 0;
    for(int i = 0 ;i < 2019 ; i++){
        int k = mp[i];
        ans += (ll)k*(k-1)/2;
    }
    cout<<ans<<"\n";
return 0;
}


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

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

    vector<long long> a(3*n);
    REP(i,3*n){
        cin>>a[i];
    }

    sort(ALL(a));
    reverse(ALL(a));
    long long sum=0;

    REP(i,n){
        sum+=a[2*i+1];       
    }

    cout<<sum<<endl;
}

Measured memory_bytes: 2560
#include<stdio.h>
#include<ctype.h>
int main(){
	int count[27]={0};
	char c;
	while(scanf("%c",&c)!=EOF){
 		c=tolower(c);
		if(islower(c))count[c-'a']++;
	}
	for(char i=0;i<26;i++)printf("%c : %d\n",i+'a',count[(int)i]);
}



Measured memory_bytes: 2080
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <map>
#include <set>
#include <list>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <iomanip>
#include <functional>

#define SIZE 300005
#define INF 1000000000
#define FD(d) fixed << setprecision(d)
#define MOD 1000000007
#define ll long long

using namespace std;


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

	if (a == b) {
		cout << c << endl;
	}

	if (a == c) {
		cout << b << endl;
	}

	if (c == b) {
		cout << a << endl;
	}

	return (0);
}


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

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

    long long A;
    long long sum = 0;
    long long ans = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A;
        if (A == 0)
        {
            ans += sum / 2;
            sum = 0;
        }
        else
        {
            sum += A;
        }
    }
    ans += sum / 2;
    cout << ans << endl;
}


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

//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = (LL)INF * INF;

int main()
{
	//ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	string S;
	cin >> S;
	FOR(i, 0, SZ(S))
		FOR(j, i - 1, SZ(S))	
		{
			string T;
			FOR(k, 0, SZ(S))
				if(k < i || k > j)
					T += S[k];
			if(T == "keyence")
			{
				cout << "YES";
				return 0;
			}
		}
	cout << "NO";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 200005;
int a[MAXN],n,top,stk[MAXN],l[MAXN],r[MAXN];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%d",a+i);
	stk[0]=0;
	for(int i=1;i<=n;++i){
		while(top && a[i]<a[stk[top]])--top;
		l[i]=stk[top]+1;
		stk[++top]=i;
	}
	top=0;
	stk[0]=n+1;
	for(int i=n;i>0;--i){
		while(top && a[i]<a[stk[top]])--top;
		r[i]=stk[top]-1;
		stk[++top]=i;
	}
	long long ans=0;
	for(int i=1;i<=n;++i)
		ans+=(long long)(i-l[i]+1)*(r[i]-i+1)*a[i];
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3328
#!/usr/bin/env python
"""AtCoder Beginner Contest 169: B - Multiplication 2
https://atcoder.jp/contests/abc169/tasks/abc169_b
"""


def calc(As):
    MAX = 10 ** 18
    ans = 1
    for n in As:
        ans *= n
        if MAX < ans:
            return -1
    return ans


def main():
    N = int(input())
    As = list(map(int, input().split()))

    if As.count(0) != 0:
        print(0)
    else:
        print(calc(As))


if __name__ == '__main__':
    main()


Measured memory_bytes: 21532
import java.io._
import scala.io.StdIn.{readInt, readLine}

object Main {
  val out:BufferedWriter =
    new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512)
  var count = 0
  class Node(var key:Int, var left:Node = null, var right:Node = null) { }

  def insert(tree:Node, key:Node) = {
    val keyNode = key
    def loop(node:Node):Node =
      if(node.key > keyNode.key) {
        if(node.left == null) node
        else loop(node.left)
      } else {
        if(node.right == null) node
        else loop(node.right)
      }

    val target = loop(tree)

    if(keyNode.key < target.key) target.left = keyNode
    else target.right = keyNode
  }

  def inOrder(root:Node):Unit = {
    var stack:List[Node] = Nil
    var curr = root
    var flg = true

    while(flg) {
      while(curr != null) {
        stack = curr::stack
        curr = curr.left
      }
      if(curr == null && stack != Nil) {
        val item = stack.head
        stack = stack.tail
        out.write(" ")
        out.write(item.key.toString)
        if(count<100) count += 1
        else {
          out.flush
          count = 0
        }
        curr = item.right
      } else {
        flg = false
      }
    }
  }

  def scan(list:List[Node]):Unit = {
    list match {
      case Nil => ()
      case hd::tl => {
        out.write(" ")
        out.write(hd.key.toString)
        if(count<100) count += 1
        else {
          out.flush
          count = 0
        }
        val hd2 = if(hd.right!=null) hd.right::tl else tl
        val hd3 =if(hd.left!=null) hd.left::hd2 else hd2
        scan(hd3)
      }
    }
  }

  def preOrder(tree:Node):Unit =
    if(tree == null) return
    else  scan(tree::Nil)

  def main(args:Array[String]) = {
    val n = readInt
    val tree = new Node(-1)

    for(i<-0 until n) {
      val s = readLine.split(" ")
      s(0) match {
        case "insert" =>
          if(tree.key == -1) tree.key = s(1).toInt
          else insert(tree, new Node(s(1).toInt))
        case _ => {
          inOrder(tree)
          out.write("\n")
          out.flush()
          preOrder(tree)
          out.write("\n")
          out.flush()
        }
      }
    }
  }
}

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

static const int N = 100;

int selectionSort(int a[], int n) {
    int sw = 0;

    for (int i = 0; i < n; i++) {
        int min = i, j;
        for (j = i + 1; j < n; j++) {
            if (a[j] < a[min]) {
                min = j;
            }
        }
        if (min != i) {
            swap(a[min], a[i]);
            sw++;
        }
    }

    return sw;
}

int main() {
    int a[N], n;

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

    int sw = selectionSort(a, n);

    for (int i = 0; i < n; i++) {
        if (i > 0) cout << ' ';
        cout << a[i];
    }
    cout << endl << sw << endl;

    return 0;
}



Measured memory_bytes: 3068
// #pragma GCC optimize("unroll-loops", "omit-frame-pointer", "inline")
// #pragma GCC option("arch=native", "tune=native", "no-zero-upper")
// #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("tree-vectorize","openmp","predictive-commoning")
// #pragma GCC option("D_GLIBCXX_PARALLEL","openmp")

// #pragma GCC optimize("O3")
// #pragma GCC target("avx2")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  int N, K;
  cin >> N >> K;
  vector<int> p(N);
  cin >> p;
  sort(all(p));
  int ans = 0;
  for (int i = 0; i < K; i++) ans += p[i];
  cout << ans << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();

  // int t; cin >> t;
  // for(int i=1;i<=t;i++){
  //   cout << "Case #" << i << ": ";
  //   solve();
  // }
  return 0;
}


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

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

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

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

  string ans = "Christmas";
  for (int i = 24; i >= n; i--) {
    ans += " Eve";
  }

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


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		String s = sc.next();
		String result = "";

		int count = 0;

		for(int i = 0; i < n; i++) {
			char c = s.charAt(i);
			if(c == '(') {
				count++;
				result = result + "(";
			} else {
				if(count == 0) {
					result = "(" + result + ")";
				} else {
					count--;
					result = result + ")";
				}
			}

		}

		for(int i = 0; i < count; i++) {
			result = result + ")";
		}

		System.out.println(result);

	}
}


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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define in2(x, y) int x,y;cin>>x>>y
#define bit(n) (1<<(n))

#define out(x) cout<<(x)<<endl;
#define err(x) cerr<<(x)<<endl;
#define errr(x,y) cerr<<(x)<<" "<<(y)<<endl;

#define rep(i,n) for (int i=0;i<(n);i++)
#define repp(i,n) for (int i=1;i<=(n);i++)
#define reppp(j, i, n) for (int j=i+1; j<n; j++)

#define lim5 100002
#define lim9 1000000002

#define deg(rad) (((rad)/2/M_PI)*360)
#define pow(x) (x)*(x)
#define mid(min, max) ((min + max) / 2)


int main() {
	in(n);

	int min = n / 1.08;
	errr((min + 1) * 1.08, n);

	if ((int)(min * 1.08) == n) {
		out(min);
		return 0;
	}
	if ((int)((min + 1) * 1.08) == n) {
		out(min + 1);
		return 0;
	}

	out(":(");
	return 0;
}


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

int main(){
  int x,n;
  cin >> x >> n;
  const int max_n = 100;
  int p[max_n + 1];
  for(int i = 0; i < n; i++) cin >> p[i];

  int current_min = 10000;
  int ans = 0;

  sort(p, p+n);
  int j = 0;
  for(int i = -100; i < 200; i++){
    if(p[j] == i){
      j++;
      continue;
    }
    if(current_min > abs(x-i)){
      current_min = abs(x-i);
      ans = i;
    }
  }
  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int a;
  cin>>N;
 a=(N%10);N/=10;
  
  if(a==0){
    cout<<"pon"<<endl;
  }
  else if(a==1){
    cout<<"pon"<<endl;
  }
  else if(a==6){
    cout<<"pon"<<endl;
  }
  else if(a==8){
    cout<<"pon"<<endl;
  }
  else if(a==2){
    cout<<"hon"<<endl;
  }
  else if(a==4){
    cout<<"hon"<<endl;
  }
  else if(a==5){
    cout<<"hon"<<endl;
  }
  else if(a==7){
    cout<<"hon"<<endl;
  }
  else if(a==9){
    cout<<"hon"<<endl;
  }
  else if(a==3){
    cout<<"bon"<<endl;
  }
}
  

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int,int>P;
int dp[100];
int fibo(int x){
	if(x==0||x==1){return dp[x]=1;}
	if(dp[x]!=0){return dp[x];}  
  	return dp[x]=fibo(x-1)+fibo(x-2);
  
}
 


int main() {
 rep(i,100){dp[i]=0;}
  int n; cin>>n;
	cout<<fibo(n)<<endl;
  
  
}


Measured memory_bytes: 3096
N=int(input())
S1=[]
S2=[]
S3=[]
S4=[]
YP=[]
YM=[]

for i in range(N):
    x,y=map(int,input().split())
    if x==0:
        if y>=0:
            YP.append([0,x,y])
        else:
            YM.append([0,x,y])
    else:
        if x>0 and y>=0:
            S1.append([y/x,x,y])
        elif x>0 and y<0:
            S2.append([y/x,x,y])
        elif x<0 and y<0:
            S3.append([y/x,x,y])
        else:
            S4.append([y/x,x,y])
S1.sort(reverse=True)

S2.sort(reverse=True)
S3.sort(reverse=True)
S4.sort(reverse=True)
L=YP+S1+S2+YM+S3+S4
List=L+L
#print(List)

ans=0
for i in range(len(L)):
    X=List[i][1]
    Y=List[i][2]
    cnt=(X*X+Y*Y)
    if ans<cnt:
        ans=cnt
    for j in range(1,len(L)):
            X+=List[i+j][1]
            Y+=List[i+j][2]
            cnt=(X*X+Y*Y)
            if ans<cnt:
                ans=cnt
print(ans**0.5)

Measured memory_bytes: 39280
N, K, Q = map(int, input().split())
vet = [0]*112345
for i in range(Q):
    x = int(input())
    vet[x]+=1

for i in range(1,N+1):

    if K + (vet[i]-Q) <= 0:
        print("No")
    else:
        print("Yes")

Measured memory_bytes: 4772
#include <stdio.h>
#include<stdlib.h>
int getdigit(int n);
int digitsum(char n[],int a);
int main(void){
    char n[10];
    gets(n);
    int a = getdigit(atoi(n));
    int fx = digitsum(n,a);
    
    if(!(atoi(n)%fx))
    {
        puts("Yes");
    }
    else
    {
        puts("No");
    }
    
    return 0;
}

int getdigit(int n){
    int digit = 0;
    while(n!=0)
    {
        n/=10;
        digit++;
    }
    return digit;
}

int digitsum(char n[],int a){
    int sum = 0;
    for(int i=0;i<a;i++)
    {
        sum += (n[i]-'0');
    }
    return sum;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) (vec).begin(),(vec).end()
#define int long long

signed main(){
    int a,b,p,q,r;cin>>a>>b>>p>>q>>r;
    double ans=((double)b*(p+r)+a*q)/(q+r);
    printf("%.5lf\n",ans);
}


Measured memory_bytes: 3216
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (int i = 0; i < (int)vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

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

int main() {

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

	int N, K;
	cin >> N >> K;

	vector<int> x(N);
	for (int i = 0; i < N; i++) cin >> x[i];

	int ans = 0;
	for (int i = 0; i < N; i++) {
		ans += min(x[i], abs(x[i] - K)) * 2;
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    ll n;
    cin >> n;
    vector<ll> a(n, 0);
    map<ll, ll> odd;
    map<ll, ll> even;
    map<ll, ll> all;
    rep1(i, n){
        cin >> a[i];
        if (i & 1) odd[a[i]]++;
        else even[a[i]]++;
        all[a[i]]++;
    }
    if (all.size() == 1){
        cout << n/2 << endl;
        return 0;
    }
    vector<P> o, e;
    for (auto x: odd) o.push_back(make_pair(x.second, x.first));
    for (auto x: even) e.push_back(make_pair(x.second, x.first));
    sort(o.begin(), o.end(), greater<P>());
    sort(e.begin(), e.end(), greater<P>());
    ll ans;
    if (o[0].second!=e[0].second) ans = n - (o[0].first + e[0].first);
    else ans = n - max((o[0].first + e[1].first), (o[1].first + e[0].first));
    cout << ans << endl;
    //printf("%.12f", ans);
}

Measured memory_bytes: 18780
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=100000000000005;
const int maxn=1e6+5;
const int mod=1e9+7;
ll n,m,p;
ll num[maxn];
ll gcd(ll a,ll b)
{
    if(!b) return a;
    return gcd(b,a%b);
}
int main()
{
    /***
        X=(p+0.5)*a_i
        X=a_i/2*(2*p+1)
        2*p+1必须为奇数
        lcm=(a_1,a_2,...a_i)
        lcm/(a[i]/2)必须为奇数
    ***/
    scanf("%lld%lld",&n,&m);
    int f=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&num[i]);
        if(num[i]%2) f=1;
    }
    if(f) printf("0\n");
    else
    {
        f=0;
        for(int i=1;i<=n;i++) num[i]/=2;
        ll _lcm=num[1];
        for(int i=2;i<=n;i++)
            _lcm=_lcm/gcd(_lcm,num[i])*num[i];
        //printf("%lld\n",_lcm);
        for(int i=1;i<=n;i++)
        {
            if((_lcm/num[i])%2==0){
                f=1;
                break;
            }
        }
        if(f) printf("0\n");
        else
        {
            ll temp=m/_lcm;
            if(temp%2) printf("%lld\n",temp/2+1);
            else printf("%lld\n",temp/2);
        }
    }
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)

int main(){
    int A,B;
    cin >> A >> B;
    int cnt = 0;
    int x,y;
    y = B - 1;
    x = ceil(double(y / double(A-1.0)));
    
    cout << x <<endl;
}

Measured memory_bytes: 256
from sys import stdin
from itertools import combinations

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

li.sort(reverse=True)

ali = 0
bob = 0

for i in range(len(li)):
    if i%2 == 0:
        ali += li[i]
    else:
        bob += li[i]

print(ali-bob)

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

bool right();

int main()
{
    if (right()) printf("Yes\n");
    else printf("No\n");

    return 0;
}

bool right()
{
    int c[3][3];
    for (int i = 0; i < 3; i++)
        for (int j = 0; j < 3; j++)
        {
            scanf("%d", c[i] + j);
        }

    for (int i = 0; i < 2; i++)
    {
        int tmp1 = c[i + 1][0] - c[i][0], tmp2 = c[0][i + 1] - c[0][i];
        for (int j = 1; j < 3; j++)
        {
            if (tmp1 != c[i + 1][j] - c[i][j]) return false;
            if (tmp2 != c[j][i + 1] - c[j][i]) return false;
        }
    }

    return true;
}

Measured memory_bytes: 256
P = 10**9 + 7
N = 1000000
inv_t = [0]+[1]
for i in range(2,N):
    inv_t += [inv_t[P % i] * (P - int(P / i)) % P]



n, k = map(int, input().split())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7

A.sort()

mini_count = 0
maxim_count = 0
pattern = 1
for i in range(n-k, -1, -1):
    mini = A[i]
    mini_count += mini * pattern % mod
    mini_count %= mod
    pattern = pattern * (n-i) * inv_t[n-i-k+1] % mod


pattern = 1
for i in range(n-k+1, 0, -1):
    maxim = A[-i]
    maxim_count += maxim * pattern % mod
    maxim_count %= mod
    pattern = pattern * (n-i+1) * inv_t[n-i-k+2] % mod

ans = maxim_count - mini_count
ans %= mod

print(ans)

Measured memory_bytes: 89356
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;
//struct edge{lint to,num;};
//vector<int> bucket[MAX_N/1000];

typedef vector<vector<lint>> mat;

mat mtx{
    {1,0,1},//F(N-1),F(N-2),...,F(N-K)の係数
    {1,0,0},//1は単位元(ex.積なら1,ANDなら2^N-1)
    {0,1,0},//0は零元(ex.積やANDなら0,ORなら2^N-1?)
}; // K次正方行列

vector<lint> F{0,0,1}; //F(1)~F(K)の値

mat mul(mat &A,mat &B){
    mat C(A.size(),vector<lint>(B[0].size()));
    rep(i,A.size()) rep(j,B.size()) rep(k,B[0].size()){
        C[i][k]=(C[i][k]+A[i][j]*B[j][k])%MOD; //演算 適宜演算子を変える
    }
    return C;
}

mat powmat(mat A,lint n){
    mat B(A.size(),vector<lint>(A.size()));
    rep(i,A.size()) B[i][i]=1; //単位元 零元が0じゃない時はそこも自分で埋める
    while(n){
        if(n&1) B=mul(B,A);
        A=mul(A,A);
        n>>=1;
    }
    return B;
}

lint calc(lint n){ //F(N)の計算
    mat A=mtx;
    A=powmat(A,n-1);
    lint res=0; //零元
    rep(i,A.size()) res=(res+A[A.size()-1][i]*F[A.size()-1-i])%MOD;//演算 適宜演算子を変える
    return res;
}

int main(void){
    int S;
    cin >> S;
    cout << calc(S) << endl;
}

Measured memory_bytes: 3640
n, m = map(int, input().split())
h_list = list(map(int, input().split()))
ab_list = [list(map(int, input().split())) for _ in range(m)]
ok_list = [True]*n

for ab in ab_list:
    a = ab[0] - 1
    b = ab[1] - 1
    if h_list[a] <= h_list[b]:
        ok_list[a] = False
    if h_list[b] <= h_list[a]:
        ok_list[b] = False

print(ok_list.count(True))

Measured memory_bytes: 31992
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func permutation(n int, k int) int {
	v := 1
	if 0 < k && k <= n {
		for i := 0; i < k; i++ {
			v *= (n - i)
		}
	} else if k > n {
		v = 0
	}
	return v
}

func factorial(n int) int {
	return permutation(n, n-1)
}

func main() {
	var c []int
	var a [][]int
	var as []int
	var value, mvalue int

	sc.Split(bufio.ScanWords)
	n := nextInt()
	m := nextInt()
	x := nextInt()

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if j == 0 {
				c = append(c, nextInt())
				as = []int{}
			}
			as = append(as, nextInt())
		}
		a = append(a, as)
	}

	mvalue = math.MaxInt64
	for k := 1; k < int(math.Pow(float64(2), float64(n))); k++ {
		value = 0
		skill := make([]int, m)
		i := 0
		// fmt.Printf("%v  ", k)
		for b := 1; b <= k; b *= 2 {
			if k&b > 0 {
				// fmt.Printf("%v, %v, %v ", k, b, k&b)
				if len(skill) == 0 {
					copy(skill, a[i])
				} else {
					for j := 0; j < m; j++ {
						skill[j] += a[i][j]
					}
				}
				value += c[i]
			}
			// fmt.Printf("%v ", skill)
			i++
		}
		// fmt.Printf("%v ", skill)
		ok := true
		for j := 0; j < m; j++ {
			if skill[j] < x {
				ok = false
			}
		}
		// fmt.Printf("%v %v\n", ok, value)
		if ok && mvalue > value {
			mvalue = value
		}
	}
	if mvalue == math.MaxInt64 {
		mvalue = -1
	}

	fmt.Printf("%v\n", mvalue)
}


Measured memory_bytes: 2132
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    string s;
    cin >> s;
    char pprev = s.at(0), prev = s.at(1);
    if (pprev == prev) {
        cout << 1 << " " << 2 << "\n";
        return 0;
    }
    range(i, 2, s.size()) {
        char cur = s.at(i);
        if (cur == pprev) {
            cout << i - 2 + 1 << " " << i + 1 << "\n";
            return 0;
        } else if (cur == prev) {
            cout << i - 1 + 1<< " " << i + 1 << "\n";
            return 0;
        }
        pprev = prev, prev = cur;
    }
    cout << -1 << " " << -1 << "\n";
    return 0;
}

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

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

template<typename T> bool chmin(T& a, T b) {return a > b ? a = b, true : false;}
template<typename T> bool chmax(T& a, T b) {return a < b ? a = b, true : false;}

int main(){
    int a[3], b[3];
    REP(i,3) cin >> a[i] >> b[i];
    int one = 0;
    int two = 0;
    int three = 0;
    int four = 0;
    REP(i,3){
        if(a[i]==1) one++;
        if(a[i]==2) two++;
        if(a[i]==3) three++;
        if(a[i]==4) four++;
        if(b[i]==1) one++;
        if(b[i]==2) two++;
        if(b[i]==3) three++;
        if(b[i]==4) four++;
    }
    if(one>=3 || two>=3 || three>=3 || four>=3) cout << "NO" << endl;
    else cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 256
#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)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/



int N, D[50];
//---------------------------------------------------------------------------------------------------
int cnt[13], vis[24];
int count() {
    int mi = 101010;
    rep(i, 0, 24) rep(j, 0, 24) if (vis[i] and vis[j] and i != j) {
        int d1 = abs(i - j);
        int d2 = 24 - d1;
        int d = min(d1, d2);
        mi = min(mi, d);
    }
    return mi;
}
//---------------------------------------------------------------------------------------------------
int solve() {
    rep(i, 0, N) cnt[D[i]]++;

    if (cnt[0]) return 0;
    vis[0] = 1;

    vector<int> v;
    rep(i, 1, 12) {
        if (cnt[i] == 1) v.push_back(i);
        else if (cnt[i] == 2) vis[i] = vis[24 - i] = 1;
        else if(2 < cnt[i]) return 0;
    }
    if (cnt[12] == 1) vis[12] = 1;
    else if (2 <= cnt[12]) return 0;

    int M = v.size();
    if (M == 0) {
        return count();
    }

    int ans = 0;
    rep(msk, 0, 1<<M) {
        rep(i, 0, M) {
            if (msk & (1 << i)) vis[v[i]] = 1, vis[24 - v[i]] = 0;
            else vis[v[i]] = 0, vis[24 - v[i]] = 1;
        }
        ans = max(ans, count());
        
    }
    return ans;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> D[i];
    cout << solve() << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,mod=1000000007,pas,i,j,fct[200009];
long long xar(long long q, long long w){
    if(w==0) return 1;
    long long qw=xar(q,w/2);
    if(w%2==0) return (qw*qw)%mod; else return (((qw*qw)%mod)*q)%mod;
}
long long di(long long q, long long w){
    long long qw=q*xar(w,mod-2);
    return qw%mod;
}
long long C(long long q){
    long long qw=1,we=1;
    for(i=a; i>=a-q+1; i--){
        qw*=i;qw%=mod;
    }
    for(i=1; i<=q; i++){
        we*=i;we%=mod;
    }
    return di(qw,we);
}
int main(){
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>a>>b>>c;
    pas=xar(2,a)+mod-1;
    pas%=mod;
//    cout<<pas<<endl;
    pas=pas-C(b)-C(c)+mod*3;
    pas%=mod;
    cout<<pas;
    return 0;
}

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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  if(n == 1) {
    cout << 0 << endl;
    return 0;
  }
  vector<char>  a(n, '0');
  vector<char>  b(n, '0');
  rep(i,n) {
    if(i%2==0) {
      a[i] = '1';
    } else {
      b[i] = '1';
    }
  }
  int candi1 = 0;
  int candi2 =0;
  rep(i,n) {
    if(s[i] != a[i]) {
      candi1 ++;
    }
    if(s[i] != b[i]) {
      candi2 ++;
    }
  }
  cout << min(candi1, candi2) << endl;
  return 0;
}
  


Measured memory_bytes: 512
import java.util.Scanner;

//Triangle and Circle
public class Main{

	public static class Point {
		public double x;
		public double y;
		public Point(double x_, double y_) {
			x = x_; y=y_;
		}
	}
	public static class Line {
		public Point s,t;
		public Line(Point s_, Point t_) {
			s = s_; t = t_;
		}
	}
	public static double distanceSP(Line s, Point p) {
		Point r = proj(s, p);
		if (intersectSP(s, r)) return norm(sub(r, p));
		return Math.min(norm(sub(s.s, p)), norm(sub(s.t, p)));
	}
	public static boolean intersectSP(Line s, Point p) {
		return ccw(s.s, s.t, p) == 0;
	}
	public static int ccw(Point a, Point b, Point c) {
		Point p = sub(b, a);
		Point q = sub(c, a);
		if(extp(p, q) > EPS) return 1;		// counter clockwise
		if(extp(p, q) < -EPS)return -1;		// clockwise
		if(inp(p, q) < -EPS) return 2;		// c--a--b on line
		if(Math.abs(norm(p) - norm(q)) < EPS) return -2;	// a--b--c on line
		return 0;				// a--c--b(or a--c=b) on line 
	}
	public static Point sub(Point p1, Point p2) {
		return new Point(p1.x-p2.x, p1.y-p2.y);
	}
	public static Point proj(Line l, Point p) {
		double t = inp(sub(p, l.s), sub(l.s, l.t)) / Math.pow(norm(sub(l.s, l.t)),2);
		Point tp = sub(l.s, l.t);
		return new Point(l.s.x + t*tp.x, l.s.y + t*tp.y);
	}
	public static double inp(Point p1, Point p2) {
		return p1.x*p2.x + p1.y*p2.y;
	}
	public static double extp(Point p1, Point p2) {
		return p1.x*p2.y - p2.x*p1.y;
	}
	public static final double EPS = 1.0e-8;
	public static double norm(Point p) {
		return Math.hypot(p.x, p.y);
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			Point pp = new Point(sc.nextDouble(), sc.nextDouble());
			if(pp.x==0&&pp.y==0)break;
			Point[] p = new Point[3];
			p[0]=pp;
			for(int i=1;i<3;i++)p[i]=new Point(sc.nextDouble(),sc.nextDouble());
			Point c = new Point(sc.nextDouble(),sc.nextDouble());
			double r = sc.nextDouble();
			boolean isB = true;
			for(int i=0;i<3;i++){
				if(!(Math.pow(c.x-p[i].x, 2)+Math.pow(c.y-p[i].y, 2)<=r*r))isB = false;
			}
			if(isB){
				System.out.println("b");continue;
			}
			boolean left = true;
			boolean right = true;
			double min = Integer.MAX_VALUE;
			double max = 0;
			for(int i=0;i<3;i++){
				double ex = extp(sub(p[(i+1)%3], p[i]), sub(c, p[i]));
				if(ex < 0)left = false;
				else if(ex > 0)right = false;
				Line l = new Line(p[i], p[(i+1)%3]);
				Line m = new Line(p[(i+1)%3], p[i]);
				double d = Math.max(distanceSP(l, c), distanceSP(m, c));
				min = Math.min(min, d);
				max = Math.max(max, d);
			}
			boolean in = left|right;
			if(in && min >= r)System.out.println("a");
			else if(!in && min > r)System.out.println("d");
			else System.out.println("c");
		}
	}
}

Measured memory_bytes: 0
#include<iostream>

using namespace std;

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

	int x;
	x = (100.0 / 108) * n;
	int check = 1.08 * x;

	if (check == n)
	{
		cout << x;
		return 0;
	}
	else
	{
		x++;
	}
	check = x * 1.08;
	if (check == n)
	{
		cout << x;
		return 0;
	}
	else cout << ":(";

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define endl "\n"
const int inf=1e9+7;
//#define for(i, a, b) for(int i=a; i<b; i++)
void solve(){
	int n, k;
	cin>>n>>k;
	int arr[n];
	for(int i=0;i<n;i++) cin>>arr[i];
  	int dp[n];
  	memset(dp, inf, sizeof(dp));
	dp[0]=0;
	dp[1]=abs(arr[1]-arr[0]);
	for(int i=1;i<n;i++){
		for(int jump=1;i-jump>=0 && jump<=k;jump++){
			dp[i] = min(dp[i-jump]+abs(arr[i]-arr[i-jump]), dp[i]);
		}
	}
	//for(int i=0;i<n;i++) cout<<dp[i]<<endl;
	cout<<dp[n-1];
}
signed main(){
	#ifdef _DEBUG
		freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
	#endif
	
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
 
}

Measured memory_bytes: 1792
import math

def is_int(n):
  return True if int(n) == n else False

def dist(x, y):
  buf = 0
  for i in range(len(x)):
    buf += (x[i] - y[i]) ** 2
  return math.sqrt(buf)
    

N, D = list(map(lambda a: int(a), input().split(" ")))
X = []
for i in range(N):
  X.append(list(map(lambda x: int(x), input().split(" "))))

cnt = 0

for j in range(N):
  for k in range(j):
    if is_int(dist(X[j], X[k])):
      cnt += 1

print(cnt)


Measured memory_bytes: 9200
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;

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

    vector<int> taste(201);

    REP(i, n) {
        taste[i] = l+i;
    }

    if (l < 0 && l+n-1 >= 0) {
        int sum = 0;
        REP(i, n) {
            sum += taste[i];
        }
        cout << sum << endl;
    }

    else if (l < 0) {
        int sum = 0;
        REP(i, n-1) {
            sum += taste[i];
        }
        cout << sum << endl;
    }

    else {
        int sum = 0;
        REP(i, n-1) {
            sum += taste[i+1];
        }
        cout << sum << endl;
    }
        
}


Measured memory_bytes: 256