akhauriyash/Code-Regression huggingface dataset:
import collections

n=int(input())
m=n//2
a=list(map(int,input().split()))
g=[]
k=[]
for x in range(n):
  if (x+1)%2==1:
    k.append(a[x])
  else:
    g.append(a[x])
    
gg=collections.Counter(g)
kk=collections.Counter(k)
aa=collections.Counter(a)

if len(aa)==1:
  print(n//2)
  
else:
  if gg.most_common()[0]==kk.most_common()[0]:
    
      print(min(m-gg.most_common()[0][1]+m-kk.most_common()[1][1],m-kk.most_common()[0][1]+m-gg.most_common()[1][1]))
   
     
  else:
    print(n-gg.most_common()[0][1]-kk.most_common()[0][1])
 

Measured memory_bytes: 31116
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

signed main(){
	int A,B;
	cin>>A>>B;
	cout<<6-A-B<<endl;
	return 0;
}


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

#define ll long long

using namespace std;

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

   double a1,ans;

    a1=double(l)/3;

   ans=a1*a1*a1 ;

    cout<<setprecision(10)<<ans;


    return 0;
}


Measured memory_bytes: 256
import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline
mii=lambda:map(int,input().split())

# get primes
lim=10000
sieve=[1]*lim
prime=[]
for i in range(2,lim):
    if not sieve[i]: continue
    prime.append(i)
    for j in range(i*i,lim,i):
        sieve[j]=0

prime.sort()
prime=[i for i in prime if i>500]
prime=prime[:500]
li=[]
while prime:
    li.append(prime.pop(0))
    li.append(prime.pop(-1))
powers=li

# print matrix
n=int(input())
out=[[0 for j in range(n)] for i in range(n)]

s=set()
for i in range(n):
    for j in range(n):
        if (i+j)%2==0:
            # put small number
            out[i][j]=powers[(i+j)//2]*(i+1)
            if out[i][j] in s:
                print("why",i,j)
            s.add(out[i][j])

for i in range(n):
    for j in range(n):
        if (i+j)%2==1:
            # put big number
            big=i+1
            if i>0: big*=i
            if i<n-1: big*=i+2
            big*=powers[(i+j)//2]
            big*=powers[(i+j+1)//2]
            k=1
            while big*k+1 in s: k+=1
            out[i][j]=big*k+1
            s.add(out[i][j])


# checking
if 0:
    for i in range(n-1):
        for j in range(n):
            x=out[i][j]
            y=out[i+1][j]
            if x<y: x,y=y,x
            while x%y!=1: 1
            x=out[j][i]
            y=out[j][i+1]
            if x<y: x,y=y,x
            while x%y!=1: 1
    s=set()
    for i in out:
        for j in i:
            s.add(j)
    while len(s)!=n**2: 1
    while max(s)>10**15: 1
    while min(s)<1: 1

for li in out: print(" ".join(map(str,li)))


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

ll modPow(ll n, ll p, ll mod) {
    n %= mod;
    // return (n^p) % mod
    if (p == 0)
        return 1;
    ll res = modPow(n * n % mod, p / 2, mod);
    if (p % 2 == 1)
        res = res * n % mod;
    return res;
}

int main() {
    string L;
    cin >> L;
    int N = L.length();

    ll ans = 0;
    ll mod = 1e9 + 7;
    ll cnt = 0;
    for (int i = 0; i < N; i++) {
        if (L[i] == '1') {
            ll temp = modPow(2, cnt, mod);
            temp = (temp * modPow(3, N - i - 1, mod)) % mod;
            ans = (ans + temp) % mod;
        }
        cnt += L[i] - '0';
    }

    ans = (ans + modPow(2, cnt, mod)) % mod;
    cout << ans << endl;
}


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

const ll MAXN = 200000;

ll N, ans=1, tmp=0;
char c;
map<char, ll> M;
vector<ll> A(MAXN, 0);

signed main(){
    cin >> N;
    for(int i=0;i<N;i++) {
        cin >> c;
        M[c]++;
    }
    for(map<char, ll>::iterator itr=M.begin();itr!=M.end();itr++) {
        pair<char, ll> p = *itr;
        ans *= p.second+1;
        ans %= 1000000007;
    }
    ans--;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code ---*/
	N := nextInt()
	B := nextInts(N - 1)
	ans := B[0]
	for i := 1; i < N-1; i++ {
		ans += int(math.Min(float64(B[i-1]), float64(B[i])))
	}
	ans += B[N-2]
	fmt.Fprintln(out, ans)
}

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

// Genericsがないので筋肉で...
// interfaceでの取扱がようわからんし
func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}

// mapからkeysとvaluesを返す感じのやつ
// なんかしらんけどmap[interface{}]interface{}しか受け付けない。なんのためのinterface{}やねん
// なので呼ぶときのmapはmap[int]stringとかじゃダメ
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
	return
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
vvi f;
int ans=0;
void search(int x,int y){
    vi v={1,0,-1,0,1,1,-1,-1,1};
    rep(i,8){
        if(f[y+v[i]][x+v[i+1]]==1){
            f[y+v[i]][x+v[i+1]]=0;
            search(x+v[i+1],y+v[i]);
        }
    }
}

int main(void){
    int w,h;
    while(cin>>w>>h,w){
        ans=0;
        f=vvi(h+2,vi(w+2,0));
        rep(i,h)rep(j,w){
            cin>>f[i+1][j+1];
        }
        rep(i,h)rep(j,w){
            if(f[i+1][j+1]==1){
                search(j+1,i+1);
                ans++;
            }
        }
        cout<<ans<<endl;
    }
}

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

int main()
{
    int N,D;
    cin>>N>>D;
    int count=0;
    for(int i=0;i<N;i++)
    {
        long long int x,y;
        cin>>x>>y;
        long long int sq_sum = x*x + y*y;
        if(pow(sq_sum,0.5) <= D)
        {
            count++;
        }
    }
    cout<<count;
}

Measured memory_bytes: 4292
#include<iostream>
#include<math.h>

using namespace std; 

typedef long long ll;

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

    for(int a=-1000; a<1000; a++){
        for(int b=-1000; b<1000; b++){
            if(pow(a,5)-pow(b,5)==x){
                cout<<a<<" "<<b<<endl;
                return 0;
            }            
        }
    }

    return 0;
}


Measured memory_bytes: 3940
#include<stdio.h>


main(){
  int n, i, j, e, sum;
  int M[500][500];
  int V, E;
  int minv;
  int d[500];
  int p[500];
  int vis[500];

  scanf("%d", &n);

  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      scanf("%d", &e);
      M[i][j] = (e==-1)?(1<<21):e;
    }
  }

  for ( i = 0; i < n; i++ ) {
    d[i] = (1<<21);
    p[i] = -1;
    vis[i] = 0;
  }

  d[0] = 0;

  while(1){
    minv = (1<<21);
    V = -1;
    for ( i = 0; i < n; i++ ){
      if ( minv > d[i] && !vis[i] ){
        V = i;
        minv = d[i];
      }
    }
    if ( V == -1 ) break;
    vis[V] = 1;
    for ( E = 0; E < n; E++ ){
      if ( !vis[E] && M[V][E] != (1<<21)){
        if ( d[E] > M[V][E] ){
          d[E] =  M[V][E];
          p[E] = V;
            }
      }
    }
  }

  sum = 0;

  for ( i = 0; i < n; i++ ){
    if ( p[i] != -1 ) sum += M[i][p[i]];
  }

  printf("%d\n", sum);

  return 0;
}





Measured memory_bytes: 2072
#include<stdio.h>
#include<iostream>
using namespace std;

int main()
{
    int n;
    
    cin >> n;
    
    int a[n];
    int l;
    int m = 0;
    while(cin >> l) {
        a[m] = l;
        m++;
    }
    
    for (int i = n - 1; i >= 0; i--) {
        cout << a[i];
        if (i != 0) {
            cout << " ";
        } 
    }
    cout << endl;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std ;
#define fast ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL)
#define ff first 
#define ss second
int main(){fast ;
	int h , w ;
	cin >> h >> w ;
	vector<string> a(h) ;
	for(int i = 0 ; i < h ; i++)
		cin >> a[i] ;
	
	vector<vector<int>> dist(h,vector<int>(w,-1)) ;
	vector<pair<int,int> > black ;
	
	for(int i = 0 ; i < h ; i++){
		for(int j = 0 ; j < w ; j++){
			if(a[i][j] == '#'){
				black.push_back({i,j}) ;
				dist[i][j] = 0 ;
			}
		}
	}
	
	for(int i = 0 ; i < black.size() ; i++){
		for(int dx = -1 ; dx <= 1 ; dx ++){
			for(int dy = -1 ; dy <= 1 ; dy++){
				if(dx*dx + dy*dy == 1){
					int xk = black[i].ff + dx ;
					int yk = black[i].ss + dy ;
					if(xk >= 0 && yk >= 0 && xk < h && yk < w && dist[xk][yk] == -1){
						black.push_back({xk,yk}) ;
						dist[xk][yk] = dist[black[i].ff][black[i].ss] + 1 ;
					}
				}
			}
		}
	}
	
	cout << dist[black.back().ff][black.back().ss] << '\n' ;
	
}




Measured memory_bytes: 15468
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define all(x) (x).begin(), (x).end()

using namespace std;
typedef long long int ll;

int main(){

    int N;

    cin >> N;

    cout << "ABC" << N << endl;


}


Measured memory_bytes: 256
object Main extends App {

  //最大公約数
  def gcd(x: Long, y: Long): Long = {
    if(y == 0) x
    else gcd(y, (x % y))
  }

  //最小公倍数
  def lcm(x: Long, y: Long): Long = {
    if(x == 0 || y == 0) 0
    else (x * y) / gcd(x, y)
  }

  val n = scala.io.StdIn.readInt()
  val readA =  scala.io.StdIn.readLine()
  val aArray = readA.split(" ").map(_.toLong).toVector
  var kobaisuu = 1L

  aArray.foreach(a =>
    kobaisuu = lcm(a, kobaisuu)
  )
  val bunshiArray = aArray.map(a => kobaisuu / a)
  println(kobaisuu.toDouble / bunshiArray.sum.toDouble)
}

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

// 番号の和がSになるような頂点集合の分割を考えて、異なるブロックに属する頂点同士に辺を張ると、単純性と隣接頂点の和に関する条件はクリア。
// S=N(N:odd) or N+1(N:even) とすると,SはStot= N(N+1)/2の約数であり、
// 任意のN(>=3)についてブロックが2以上になるので、連結性についてもクリア。
int main(){
  int N;
  cin >> N;
  const int sum= (N%2!=0) ? N
                          : N+1;

  queue<pair<int, int>> ans;
  for(int v1=1; v1<=N; v1++){
    for(int v2=v1+1; v2<=N; v2++){
      if(v1+v2==sum){ continue; }
      else{
        ans.push(make_pair(v1, v2));
      }
    }
  }

  cout << ans.size() << endl;
  while(!ans.empty()){
    auto [v1, v2]= ans.front();
    ans.pop();
    
    cout << v1 <<" "<< v2 << endl;
  }
}

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

using std::cout;
using std::cin;
using std::endl;

long nC2(int n) {
	if (n == 0)
	{
		return 0;
	}
	return (n * (n - 1)) / 2;
}

int main() {
	int n, m;
	cin >> n >> m;
	cout << (nC2(n) + nC2(m)) << endl;

}


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

using namespace std;

#define LOCAL
#define all(a) begin(a), end(a)
#define MOD 1000000007
#define PII pair<int, int>
#define REP(x, l, u) for(ll x = l;x<u;x++)
#define RED(x, l, u) for(ll x = l;x>=u;x--)
#define complete_unique(a) a.erase(unique(begin(a),end(a)),end(a))
#define mst(x, a) memset(x,a,sizeof(x))
typedef vector<int> VI;
typedef long long ll;

ll quick_pow(ll a, ll b) {
    long long res = 1;
    while (b) {
        if (b & 1) { res = a * res; }
        a = a * a;
        b >>= 1;
    }
    return res;
}

ll gcd(ll a, ll b) {
    a = abs(a), b = abs(b);
    while (b != 0) {
        a %= b;
        swap(a, b);
    }
    return a;
}

bool is_prime(int n) {
    if (n == 1) return false;
    if (n == 2) return true;
    if (n % 2 == 0) return false;
    int j = sqrt(n);
    for (int i = 2; i <= j; ++i) {
        if (n % i == 0) return false;
    }
    return true;
}

ll reverse_num(ll n) {
    ll x = 0, t = n;
    while (t != 0) {
        x = x * 10 + t % 10;
        t /= 10;
    }
    return x;
}

// TO-DO
// contest required
#ifdef LOCAL

void solve() {
    int l, r, d;
    cin >> l >> r >> d;
    int res = 0;
    for (int i = l; i <= r; ++i) {
        if (i % d == 0) res++;
    }
    cout << res;
}

int main() {
    // 加速输入和输出
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();
    return 0;
}

#endif

Measured memory_bytes: 3648
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define fi first 
#define se second
const long long MOD = 1000000007;
const long long inf = 1ll << 61;
const double eps = 0.000000000001;
typedef long long ll;
struct edge { int to; int cost; int color; };
vector<int>G[10005];
int ans[10005];
int c[10005];
int cnt;
void dfs(int now) {
	rep(i, G[now].size()) {
		int e = G[now][i];
		if (ans[e])continue;
		cnt++;
		ans[e] = c[cnt];
		dfs(e);
		
	}
	return;
}
signed main() {
	int n; cin >> n;
	rep(i, n-1) {
		int a, b; cin >> a >> b; a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	rep(i, n)cin >> c[i];
	sort(c, c + n); reverse(c, c + n);
	ans[0] = c[0];
	dfs(0);
	int sum = 0;
	rep(i, n - 1)sum += ans[i + 1];
	cout << sum << endl;
	rep(i, n) {
		if (i)cout << ' '; cout << ans[i];
	}cout << endl;
}


Measured memory_bytes: 1280
# -*- coding: utf-8 -*-

import math

a,b=map(int,input().split())
na=[i for i in range(math.ceil(a*12.5),math.ceil((a+1)*12.5-1)+1)]
nb=[i for i in range(b*10,(b+1)*10)]

ans=set(na)&set(nb)

if len(ans)==0:
    print(-1)
else:
    print(min(ans))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

vector<int> init(int size){
  vector<int> par(size,-1);
  return par;
}

int root(int x, vector<int>& par){
  if(par[x] < 0){
    return x;
  }else{
    return par[x] = root(par[x],par);
  }
}

bool same(int x, int y, vector<int>& par){
  return root(x, par) == root(y, par);
}

void unite(int x, int y, vector<int>& par){
  x = root(x, par), y = root(y, par);
  if(same(x,y, par))return;
  par[x] += par[y];
  par[y] = x;
}

int size(int x, vector<int>& par){
  return -par[root(x, par)];
}

int pow(int x, int n){
  if(n == 0)return 1;
  if(n % 2 == 0)return pow(x * x % MOD, n/2);
  else return x * pow(x, n-1) % MOD;
}

vector< int > divisor(int n) {
  vector< int > ret;
  for(int i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret),greater<int>());
  return (ret);
}

signed main(){
  int n;cin>>n;int h[110000];rep(i,n)cin>>h[i];
  int ans = 0, now = 0;
  rep(i,n-1){
    if(h[i] >= h[i+1]){
      now++;
    }else{
      ans = max(now, ans);now = 0;
    }
  }
  ans = max(now, ans);
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
template<typename T> T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; }
template<typename T> T mod_inv(T x, const T &p) { return mod_pow(x, p-2, p); }
const ll DVSR = 1e9+7;


int main(int argc, char const *argv[])
{
  string S; cin >> S;
  int K; cin >> K;
  int L;
  L = S.length();
  set<string> st;
  RNG(k, 1, K+1) {
    REP(i, S.length()) {
      if (i+k <= L) st.insert(S.substr(i, k));
    }
  }
  auto ptr = st.begin();
  REP(i, K-1) ptr++;
  cout << *ptr << endl;
  return 0;
}


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

const int maxn=(1<<16)-1;

int n;
bool bl[maxn+5];
long long dp[maxn+5];
long long gp[maxn+5];
long long a[32][32];

int main(){
	cin>>n;
	int N=(1<<n)-1;
	//cout<<N<<'\n';
	for(int i=0;i<n;++i){
		for(int j=0;j<n;++j){
			cin>>a[i][j];
		}
	}
	for(int i=0;i<=N;++i){
		for(int j=0;j<n;++j){
			int tt=((1<<j)|i);
			if(tt==i||bl[tt]) continue;
			else{
				bl[tt]=1;
				gp[tt]=gp[i];
				for(int k=0;k<n;++k){
					if((i|(1<<k))==i) gp[tt]+=a[j][k];
				}
			} 
		}
	}
	for(int i=0;i<=N;++i){
		int tmp[32],tot=0;
		for(int j=0;j<n;++j){
			if((i|(1<<j))==i) continue;
			else tmp[tot]=j,tot++;
		}
		for(int j=1;j<=(1<<tot)-1;++j){
			//if((i&j)!=0) continue;
			int zz=0;
			for(int k=0;k<tot;++k)
				if((j|(1<<k))==j) zz|=(1<<tmp[k]);
			dp[i|zz]=max(dp[i|zz],dp[i]+gp[zz]);
		}
	}
	cout<<dp[N]<<"\n";
	return 0;
}

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

//template
#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 ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
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; }
//template end



int main(){
   int n; scanf("%d",&n);
   vector<int> a(n); rep(i,0,n)scanf("%d",&a[i]);
   bool f=1; if(a[0]>0)f=0;
   rep(i,0,n-1)if(a[i+1]-a[i]>1)f=0;
   if(!f){printf("-1\n"); return 0;}
   ll ans=a.back();
   rrep(i,n-2,-1)if(a[i]+1!=a[i+1])ans+=a[i];
   printf("%lld\n",ans);
   return 0;
}

Measured memory_bytes: 1024
use proconio::input;

fn main() {
    input! {
        ND: (i64,i64),
        XYL: [(i64,i64);ND.0],
    }
    let mut count = 0;
    for XY in XYL.iter() {
        if XY.0.pow(2)+XY.1.pow(2) <= ND.1.pow(2) {
            count += 1;
        }
    }
    println!("{}", count.to_string())
}


Measured memory_bytes: 7756
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define FI(i, a, b) for (int i = (a); i <= (b); ++i)
#define FD(i, b, a) for (int i = (b); i >= (a); --i)
#define DEBUG(x) cerr << #x << ": " << (x) << endl;

int main() {
  int n, m;
  cin >> n >> m;
  int ans = n * (n - 1) / 2 + m * (m - 1) / 2;
  cout << ans << endl;
}

Measured memory_bytes: 256
fn main() {
    let mut v: Vec<i64> = read_vec();
    v.sort();
    let cost = (v[0]-v[1]).abs() + (v[1]-v[2]).abs();
    println!("{}", cost);
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim().split_whitespace().map(|e|
        e.parse().ok().unwrap()
    ).collect()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
int main()
{
    int H, N, sum(0);
    std::cin >> H >> N;
    int A[N];
    for (int i = 0; i < N; i++)
    {
        std::cin >> A[i];
        sum += A[i];
    }
    if (H - sum > 0)
    {
        std::cout << "No" << std::endl;
    }
    else
    {
        std::cout << "Yes" << std::endl;
    }
}

Measured memory_bytes: 640
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;

long long Work() {
    long long ans = 0;
    int n;
    scanf("%d", &n);
    vector< vector<long long> > a(n, vector<long long>(n, 0));
    vector< vector<long long> > b(n, vector<long long>(n, 0));
    vector< pair<long long, pair<int, int> > > c;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            scanf("%d", &a[i][j]);
            if (i < j) {
                c.push_back(make_pair(a[i][j], make_pair(i, j)));
            }
            if (i > j && a[i][j] != a[j][i]) { return -1; }
        }
    sort(c.begin(), c.end(), [](const pair<long long, pair<int, int> >& a,
                                const pair<long long, pair<int, int> >& b) {
            return (a.first < b.first);
         });
    for (const auto& iter : c) {
        int x = iter.second.first, y = iter.second.second;
        if (b[x][y] == iter.first) {
            continue;
        }
        if (b[x][y] < iter.first && b[x][y] != 0) {
            return -1;
        }
        ans += iter.first;
        b[x][y] = b[y][x] = iter.first;
        for (int i = 0; i < n; i++)
            for (int j = i + 1; j < n; j++) {
                if ((i == x || b[x][i] > 0) && (y == j || b[y][j] > 0) &&
                    (b[i][j] == 0 || b[i][j] > b[x][i] + b[y][j] + b[x][y])) {
                    b[i][j] = b[j][i] = b[x][i] + b[x][y] + b[y][j];
                }
                if ((i == y || b[y][i] > 0) && (x == j || b[x][j] > 0) &&
                    (b[i][j] == 0 || b[i][j] > b[x][j] + b[y][i] + b[x][y])) {
                    b[i][j] = b[j][i] = b[x][j] + b[x][y] + b[y][i];
                }

            }
    }
    return ans;
}

int main() {
    cout << Work() << endl;
    return 0;
}


Measured memory_bytes: 2808
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main() {
  string s, t;
  cin >> s >> t;

  int a, b;
  cin >> a >> b;

  string u;
  cin >> u;

  if (u == s) {
    a--;
  } else {
    b--;
  }

  cout << a << " " << b << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
#define MAX 200000

int main(){
  ll N,temp,count=0;
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>temp;
    if(temp%2!=0) count++;
  }
  if(count%2==0) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <unordered_map>

using namespace std;

int main()
{
  string s,t;
  int sm[26] = {0};
  int tm[26] = {0};

  cin >> s >> t;

  for (int i = 0; i < t.length(); i++) {
    tm[t[i] - 'a']++;
  }
  for (int i = 0; i < s.length(); i++) {
    sm[s[i] - 'a']++;
  }

  sort(tm, tm + 26);
  sort(sm, sm + 26);

  for (int i = 0; i < 26; i++) {
    if (tm[i] != sm[i]) {
      cout << "No";
      return 0;
    }
  }

  cout << "Yes";
  return 0;
}

Measured memory_bytes: 776
/*  ex9_2
    Rikuta  */
#include <stdio.h>
#include <stdlib.h>
// リストのノード（スタック内の各データ）の定義
typedef struct node
{
    char elem;
    struct node *next;
} node;

//プロトタイプ宣言
void push(node **cube, char elem);
char pop(node **cube);
char last(node **cube);

int main(void)
{   
    //最初のノードがさす先．
    node *cube = NULL;
    //countの初期化
    int count = 0;
    while (1)
    {   
        //一時的な文字の宣言
        char temp_char;
        //入力
        scanf("%c", &temp_char);
        //改行で終了
        if (temp_char=='\n')
        {
            break;
        }
        if (temp_char=='0')
        {   
            if (last(&cube)=='1')
            {
                //0が入力され，cubeの最後の文字が1なら，cubeをpopして，カウントを+2
                pop(&cube);
                count+=2;
            }
            else
            {   
                //0が入力され，cubeの最後の文字が0なら，0をpush
                push(&cube, temp_char);
            }
            
            
        }
        if (temp_char=='1')
        {
            if (last(&cube) == '0')
            {
                //1が入力され，cubeの最後の文字が0なら，cubeをpopして，カウントを+2
                pop(&cube);
                count+=2;
            }
            else
            {
                //1が入力され，cubeの最後の文字が1なら，1をpush
                push(&cube, temp_char);
            }
        }
    }
    //countを出力
    printf("%d\n", count);
    return 0;
}

//スタックにデータを追加
void push(node **cube, char elem)
{
    //追加する分の領域を確保
    node *new = calloc(1, sizeof(node));
    //確保できないならエラー
    if (new == NULL)
        exit(1);
    //新しいデータの要素はelemでそれに続くものはcubeとなる
    new->elem = elem;
    new->next = *cube;
    //新しいノードが1番目に更新される．
    *cube = new;
}

//スタックからデータを取り出す
char pop(node **cube)
{
    char elem;
    node *tmp = *cube;
    if (tmp == NULL)
        exit(1);
    elem = tmp->elem;
    *cube = tmp->next;
    //取り出したノードのメモリを解放
    free(tmp);
    return elem;
}
//スタックの最初を参照する．
char last(node **cube)
{
    //最初の文字が入る変数の宣言
    char elem;
    node *tmp = *cube;
    //データがなければ'-'を返す．
    if (tmp == NULL)
        return '-';
    //データの最初をelemとして返す
    elem = tmp->elem;
    return elem;
}


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

int main() {
  int N,A,B;
  cin >> N;
  vector<int> a(N);
  vector<int> allzero(N,0);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  
  while(a != allzero){
	sort(a.begin(), a.end());
  	reverse(a.begin(), a.end());

  	A += a.at(0);
  	a.at(0) = 0;

  	B += a.at(1);
  	a.at(1) = 0;
  }

  cout << A-B << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr ll ZERO = 0;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

int main() {
    int N;
    cin >> N;
    vector<int> prime = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101};
    int A = prime.size();
    vector<int> vec;
    for(int i = 0;i < A;i++) {
        int n = N;
        int p = prime.at(i);
        int cnt = 0;
        for(int j = p;j <= N;j *= p) {
            cnt += n / j;
        }
        vec.push_back(cnt);
    }
    int two = 0;
    int four = 0;
    int fourteen = 0;
    int twentyfour = 0;
    int seventeenfour = 0;
    for(int i = 0;i < vec.size();i++) {
        if(vec.at(i) >= 2) {
            two++;
        }
        if(vec.at(i) >= 4) {
            four++;
        }
        if(vec.at(i) >= 14) {
            fourteen++;
        }
        if(vec.at(i) >= 24) {
            twentyfour++;
        }
        if(vec.at(i) >= 74) {
            seventeenfour++;
        }
    }
    int ret = 0;
    ret += seventeenfour;
    ret += twentyfour * (two - 1);
    ret += fourteen * (four - 1);
    ret += four * (four - 1) / 2 * (two - 2);
    cout << ret << endl;
}

Measured memory_bytes: 256
n = int(input())
d1 = []
d2 = []
while n:
    a, b = map(int, input().split())
    d1.append(a)
    d2.append(b)
    n-=1
cnt = 0
flag = 0
for i in range(len(d1)):
    if d1[i]==d2[i]:
        cnt+=1
    else:
        cnt=0
    if cnt==3:
        flag = True
        print('Yes')
        break
if not flag:
    print('No')


Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long l,r;
    cin>>l>>r;
    if(r/2019 != l/2019 || l%2019 == 0) {
        cout<<0<<endl;
        return 0;
    }
    l = l%2019;
    r = r%2019;
    int ans = 2019;
    for (int i = 0; l+i < r; i++)
    {
        for (int j = i+1; l+j <= r; j++)
        {
            int chk = ((l+i)*(l+j))%2019;
            ans = min(ans,chk);
        }
    }
    
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
 
#define ll long long
#define MOD 1000000007
#define pll             pair<ll,ll>
#define pii             pair<int,int> 
#define mp(a,b)         make_pair(a,b)
#define pb 				push_back
#define vi				vector<int>
#define vl 				vector<long long>
#define vb 				vector<bool>
#define printv(v)		for(auto x : v) cout<<x<<' ';br;
#define FOR(i,a,b) 		for(ll i = a; i <= b ; i++)
#define forn(i,n) 		for(ll i = 0 ; i < n; i++)
#define br 				cout<<endl;
#define testc()			ll t;cin>>t;while(t--)
 
#define fast 			ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define INF				INT_MAX
#define INFL			LLONG_MAX
#define max1(x,y) (x)>(y)?(x):(y)
#define ss second
#define ff first
#define MAXN 100001

int main(){
    fast
    ll n,k;
    cin>>n>>k;
    ll arr[n+1]={0};
    FOR(i,1,n)
    cin>>arr[i];
    sort(arr+1,arr+n+1);
    ll dp[k+1];
    fill_n(dp,k+1,1);
    // FOR(i,0,k){
    //     cout<<dp[i]<<" ";
    // }
    // cout<<endl;
    FOR(i,1,k){
        FOR(j,1,n){
            if(arr[j]>i)
            break;
            dp[i]=min(dp[i],-1*dp[i-arr[j]]);
        }
    }
    // FOR(i,1,k){
    //     cout<<dp[i]<<" ";
    // }
    // cout<<endl;
    if(dp[k]==1){
        cout<<"Second\n";
    }
    else
    cout<<"First\n";
    return 0;
}

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

int main() {

    int n;
    double dist[10][10];
    cin >> n;

    vector<pair<int, int>> pos(n);
    vector<int> permutation(n);

    for(int i = 0; i < n; ++i) {
        cin >> pos[i].first >> pos[i].second;
    }

    for(int i = 0; i < n; ++i)
        permutation[i] = i;

    for(int i = 0; i < n - 1; ++i) {
        for(int j = i + 1; j < n; ++j) {
            dist[i][j] = pow(pos[i].first - pos[j].first, 2) + pow(pos[i].second - pos[j].second, 2);
            dist[i][j] = sqrt(dist[i][j]);
            dist[j][i] = dist[i][j];
        }

    }

    double ave = 0;
    while(1) {

        for(int i = 0; i < n - 1; ++i) {
            int pos_i = permutation[i];
            int nextPos_i = permutation[i + 1];
            ave += dist[pos_i][nextPos_i];
        }

        if(!next_permutation(permutation.begin(), permutation.end()))
            break;

    }

    int N = 1;
    for(int i = 2; i <= n; ++i)
        N *= i;

    printf("%.10f\n", ave / N);

    return 0;
}

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

int main() {
    int N;
    cin >> N;
    int mn = 2*pow(10, 5) + 1;
    int cnt = 0;
    rep(i, N) {
        int tmp;
        cin >> tmp;
        if (tmp < mn) {
            mn = tmp;
            cnt += 1;
        }
    }
   cout << cnt << endl;
    return 0;
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int x ; 
  cin >> x ; 
  if(x <30 ) cout << "No" ;
  else       cout << "Yes" ;
  
}


Measured memory_bytes: 3636
n, d=map(int, input().split())
x=[]
for i in range(n):
    x.append(list(map(int, input().split())))
ans=0

for i in range(n):
    for j in range(n):
        distance=0
        for k in range(d):
            distance=distance+(x[i][k]-x[j][k])**2
        root_distance=int(distance**(1/2))
        if abs(distance-root_distance*root_distance)<10**(-6):
            ans=ans+1
print((ans-n)//2)


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

int main()
{
	string s, t;
	cin >> s >> t;
	int n = s.size();
	for (int i = 0; i < n; i++)
	{
		string u = s.substr(n - i, i) + s.substr(0, n - i);
		if (t == u)
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
/**
* Think twice, code once.
* 1.integer overflow(maybe even long long overflow : (a+b >= c) -> (a >= c-b)
* 2.runtime error
* 3.boundary condition
* ---------------------------------------------------------------------------------------
* Author : zzy
* Date : 2020-03-21-03.57.40 Friday
*/
#include <bits/stdc++.h>

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
#define SZ(x) ((int)(x).size())

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn = (int)1e5+1000;
int n, m, x, y, indeg[maxn], dp[maxn];
vvi g(maxn);

void toposort() {
    queue<int> q;
    for1(i, n) {
        if (!indeg[i]) q.push(i);
        dp[i] = 1;
    }
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (int to : g[u]) {
            --indeg[to];
            if (!indeg[to]) q.push(to);
            dp[to] = max(dp[to], dp[u]+1);
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif

    cin >> n >> m;
    forn(i, m) {
        cin >> x >> y;
        g[x].eb(y);
        ++indeg[y];
    }
    toposort();
    int ans = 1;
    for1(i, n) {
        ans = max(ans, dp[i]);
    }
    cout << ans-1 << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


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

int main(void){
    int a, b, c;
    cin>>a>>b>>c;
    if((a==b and a!=c) or (b==c and a!=b) or(c==a and a!=b)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding:utf-8 -*-

def solve():
    import copy

    N, M, Q = list(map(int, input().split()))
    query = []
    for i in range(Q):
        a, b, c, d = list(map(int, input().split()))
        query.append((a,b,c,d))

    cands = []
    def rec(start, lst):
        if len(lst) == N:
            return lst

        for i in range(start, M+1):
            tmp_lst = copy.deepcopy(lst)
            tmp_lst.append(i)
            ret = rec(i, tmp_lst)
            if ret is not None:
                cands.append(ret)

    rec(1, [])

    ans = 0
    for cand in cands:
        total = 0
        for abcd in query:
            a,b,c,d = abcd
            if cand[b-1]-cand[a-1] == c:
                total += d
        ans = max(ans, total)

    print(ans)




if __name__ == "__main__":
    solve()


Measured memory_bytes: 27732
import java.util.*;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        long hs[] = new long[N];
        for(int i = 0;i < N;i++)
            hs[i] = sc.nextLong();

        long dp[] = new long[N];
        //for(int i = 0;i < N;i++)
        //    dp[i] = Long.MAX_VALUE;
        dp[0] = 0;
        for(int i = 1;i < N;i++) {
            long min = Long.MAX_VALUE ;
            for(int h = 1;h <= K && i - h >= 0;h++){
                long tmp = dp[i - h] + Math.abs(hs[i] - hs[i - h]);
                if(min > tmp)
                    min = tmp;
            }
            dp[i] = min;
        }

        System.out.println(dp[N - 1]);

    }










    public static Integer min(List<Integer> ar){
        int min = 10000;
        int index = 0;
        for(int i = 0; i< ar.size();i++){
            if(min > ar.get(i)){
                min = ar.get(i);
                index = i;
            }
        }
        return min;
    }
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    int N,T; cin >> N >> T;
    vector<ll> a(N+1); 
    a[0] = LINF;
    REP(i,N) cin >> a[i+1];

    ll low = LINF;
    map<ll,int> b;
    REP(i,N){
        low = min(low, a[i]);
        b[low - a[i+1]] ++;
    }

    
    for(auto bb: b){
        cout << bb.second << endl;
        break;
    }

    return 0;
}

Measured memory_bytes: 10328
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    ll mod = 1e9 + 7;
    COMinit();
    int N, K;
    cin >> N >> K;

    vector<ll> A(N);
    REP(i, N) cin >> A[i];
    sort(ALL(A));

    ll ans = 0;
    FOR(i, 1, N-K+1) {
        ans -= A[i-1] * COM(N-i, K-1);
        ans %= mod;
        if(ans < 0) ans += mod;
    }
    FOR(i, K, N) {
        ans += A[i-1] * COM(i-1, K-1);
        ans %= mod;
    }
    cout << ans << endl;

    return 0;
}

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

int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int j=0;j<n;j++){
        cout<<a[n-j];
        if(j<n-1){
            cout<<" ";
        }
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3088
N=int(input())
A=[0 for i in range(N)]
B=[0 for i in range(N)]
for i in range(N):
    A[i],B[i]=map(int,input().split())
A.sort()
B.sort()
medmin=0
medmax=0
if N%2==0:
    medmin=(A[-1+N//2]+A[N//2])
    medmax=(B[-1+N//2]+B[N//2])
else:
    medmin=A[(N-1)//2]
    medmax=B[(N-1)//2]
print(medmax-medmin+1)
#print(medmax,medmin)

Measured memory_bytes: 25392
#include<stdio.h>
int main(){
  char s[20];
  scanf("%s",s);
  for(int i = 0; i<19; i++){
    if(s[i] == ','){
      printf(" ");
    }else{
      printf("%c",s[i]);
    }
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <deque>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
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;}
void print(vec v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(vecll v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(vector<vec> v){for(auto e:v){for(auto ee:e)cout<<ee<<" ";cout<<endl;}}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}
const int INF=1e6;
const ll int MOD=998244353;

main(){
    int n=in();
    cout<<(n+1)*n/2;
}

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

int main(){
	string S;
	cin >> S;
	if(S[0] == '7' || S[1] == '7' || S[2] == '7') {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;

}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define rep(i, a, b) for(int i=(a);i<=(int)(b);++i)
#define per(i, a, b) for(int i=(a);i>=(int)(b);--i)
#define debug(x)   cout << #x << ' ' << x << endl;
#define one(x) __builtin_popcount(x)
using namespace std;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << max(0, c - (a-b)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int a = 1, b = 1, i = 1;
    while ((a != 0)||(b != 0)){
    	if (i != 1)
            cout << endl;
        i++;
        cin >> a >> b;
        if ((a != 0)||(b != 0))
            for (int i = 1; i <= a; i++){
                for (int j = 1; j <= b; j++)
                    if ((i == 1) || (i == a) || (j == 1) || (j == b))
                    	cout << '#';
                    	else cout << '.';
                cout << endl;
            }
    }
}


Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  ll a, b, x = 0;
  std::cin >> a >> b;
  for(int i=2;i<n;i++){
    ll t;std::cin >> t;
    x ^= t;
  }
  // 2^kのbitが1-1の時のみ総和が2*2^k減る
  ll s = a + b - x;
  set<ll> st;
  if(s<0||s%2){
    std::cout << -1 << '\n';
    return 0;
  }

  for(int i=0;i<50;i++){
    if(s%2) st.insert(i-1);
    s /= 2;
  }
  ll num = 0;
  vll tw(60, 1);
  for(int i=1;i<60;i++) tw[i] = tw[i-1]*2;
  for(auto v:st) num += tw[v];//確定

  if(num>a){
    std::cout << -1 << '\n';
    return 0;
  }

  for(int i=50;i>=0;i--){
    if(((x>>i)&1)==0){
      if(st.find(i)!=st.end()) continue;
    }else{
      //両方1の場合は無理
      if(st.find(i)!=st.end()){
        std::cout << -1 << '\n';
        return 0;
      }
      if(num+tw[i]<=a) num+=tw[i];
    }
  }

  std::cout << (num==0?-1:a - num) << '\n';
  return 0;
}


Measured memory_bytes: 3168
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] arges) {

		Scanner sc = new Scanner(System.in);
		List<String> k = new ArrayList<String>();
		while (true) {
			String line = sc.nextLine();
			k.add(line);
			if (line.equals("0")) {
				break;
			}
		}

		for (String string : k) {
			if (string.equals("0")) {
				break;
			}
			String[] lig = new String[string.length()];
			for (int i = 0; i < string.length(); i++) {
				lig[i] = string.substring(i, i + 1);
			}
			int sum = 0;
			int[] v = new int[lig.length];
			for (int i = 0; i < lig.length; i++) {
				v[i] = Integer.parseInt(lig[i]);
				sum += v[i];
			}
			System.out.println(sum);
		}

	}

}

Measured memory_bytes: 26800
n = int(input())
h = list(map(int,input().split()))

dp = [-1 for _ in range(n)]

dp[0] = 0
dp[1] = abs(h[0] - h[1])


for i in range(2,n):
  v1 = abs(h[i-1] - h[i])
  v2 = abs(h[i-2] - h[i])
  dp[i] = min(dp[i-1] + v1,dp[i-2] + v2)
  
print(dp[n-1])

Measured memory_bytes: 13928
#define DIN freopen("input.txt","r",stdin);
#define DOUT freopen("output.txt","w",stdout);
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,a,b) for(int i=(a);i<=(int)(b);i++)
#define REP_(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> P;
int read()
{
    int x=0,flag=1;
    char c=getchar();
    while((c>'9' || c<'0') && c!='-') c=getchar();
    if(c=='-') flag=0,c=getchar();
    while(c<='9' && c>='0') {x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return flag?x:-x;
}

int main()
{
    int ans=0,n=read();
    REP(i,1,n)
    {
        int x=read();
        if(i&1 && x&1) ans++;
    }
    cout<<ans;

    return 0;
}


Measured memory_bytes: 3628