akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

vector<ll> a(mx);
int n;
ll k;

bool finish(ll x){
  ll cnt=0;
  for(int i=0; i<n; i++){
    ll v = x-a[i];
    cnt += a.end() - lower_bound(a.begin(),a.end(), v);
  }
  return cnt<k;
}
 
int main(){
  cin >> n >> k;
  a.resize(n);
  rep(i,n){cin>>a[i];}
  sort(a.begin(),a.end());
  
  ll l=0,r=mx,mid=(r+l)/2;
  while(r-l>1){
    mid=(r+l)/2;
    if(finish(mid)){ r=mid; }else{ l=mid; }
  }

  ll ans = 0;
  vector<ll> sum(n+1,0);
  rep(i,n) sum[i+1] = sum[i] + a[i];
  rep(i,n){
    int it = upper_bound(a.begin(),a.end(),l-a[i]) - a.begin();
    ans += sum[n]-sum[it];
    ans += (ll)(n-it)*a[i];
    k -= (n-it);
  }
  ans += k*l;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
// AOJ 2919 Training
// 2019.2.17 bal4u

#include <stdio.h>
#include <stdlib.h>

int main()
{
	int N, A, B, C;

	scanf("%d%d%d%d", &N, &A, &B, &C);
	printf("%d\n", N-A-B+C);
	return 0;
}



Measured memory_bytes: 2056
import math

N = int(input())
cities = []

for _ in range(N):
  x, y = map(int, input().split())
  cities.append([x, y])

total = 0
for i in range(N):
    for j in range(i + 1, N):
        xi, yi = cities[i]
        xj, yj = cities[j]
        total += math.sqrt(pow(xi - xj, 2) + pow(yi - yj, 2))   
print(total * 2 / N)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

ll f(ll a, ll x){
    if(a < 0) return 0LL;
    else return a/x + 1;
}

int main(void){
    ll a, b, x; cin >> a >> b >> x;

    cout << f(b, x) - f(a-1, x) << endl;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()


def main():
    N, Y = map(int, input().split())
    Y //= 1000
    for a in range(Y, -1, -1):
        for b in range(Y // 5 - 2 * a, -1, -1):
            c = Y - 10 * a - 5 * b
            if 0 <= c and a + b + c == N:
                print("{} {} {}".format(a, b, c))
                return
    print("-1 -1 -1")


if __name__ == "__main__":
    main()


Measured memory_bytes: 66316
#include <iostream>
#include <vector>
int main() {
	int N;
	std::cin >> N;
	std::vector<int> h(N);
	for (auto&i : h)std::cin >> i;
	h.push_back(0);
	int ans = 0;
	int count = 0;
	int prev = 0;
	do {
		count = 0;
		prev = 0;
		for (auto&i : h) {
			if (!(i > 0 || prev <= 0))++count;
			prev = i;
		}
		for (auto&i : h)--i;
		ans += count;
	} while (count);
	printf("%d", ans);
}

Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main (String[] args) throws java.lang.Exception {
        Scanner sc = new Scanner(System.in);
        while(true) {
            int a = sc.nextInt();
            String d = sc.next();
            int b = sc.nextInt();
            if(d.equals("?")) break;
            if(d.equals("+")) System.out.println(a + b);
            if(d.equals("-")) System.out.println(a - b);
            if(d.equals("*")) System.out.println(a * b);
            if(d.equals("/")) System.out.println(a / b);
        }
    }
}


Measured memory_bytes: 26464
#include<bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  int t=1;
  while(t--)
  {
      set<int> s;
      int n;
      cin>>n;
      int a[n];
      REP(i,n)
      {
          cin>>a[i];
          s.insert(a[i]);
      }
      if(s.size()==n)cout<<"YES";
      else cout<<"NO";
  }
  return 0;
}

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

void dfs(int x, const vector<vector<bool>>& bridges, vector<bool>& visits) {
  if (visits.at(x)) {
    return;
  }
  visits.at(x) = true;
  for (int i = 0; i < bridges.at(x).size(); i++) {
    if (bridges.at(x).at(i)) {
      dfs(i, bridges, visits);
    }
  }
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<bool>> bridges(N, vector<bool>(N, false));
  vector<pair<int, int>> sides(M);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    sides.at(i).first = a;
    sides.at(i).second = b;
    bridges.at(a).at(b) = true;
    bridges.at(b).at(a) = true;
  }
  int count = 0;
  for (int i = 0; i < M; i++) {
    bridges.at(sides.at(i).first).at(sides.at(i).second) = false;
    bridges.at(sides.at(i).second).at(sides.at(i).first) = false;

    vector<bool> visits(N, false);
    dfs(0, bridges, visits);
    for (int iv = 0; iv < N; iv++) {
      if (visits.at(iv) == false) {
        count++;
        break;
      }
    }
    bridges.at(sides.at(i).first).at(sides.at(i).second) = true;
    bridges.at(sides.at(i).second).at(sides.at(i).first) = true;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
    int a, b, c;
    int n = 0;
    cin >> a >> b >> c;
    for (int i = a; i <= b; i++) {
        if (c % i == 0) n++;
    }
    cout << n << endl;
    
    return 0;
}


Measured memory_bytes: 3112
#include <stdio.h>

int main() {
  int sum = 0;
  int a[2];
  for(int i=0; i<2; ++i){
  	scanf("%d",&a[i]);
  }
  
  for(int i=0; i<2; i=i+1){
    if(a[0]>a[1]){
      sum = a[0] + sum;
      a[0] = a[0] - 1;
    }else{
      sum = a[1] + sum;
      a[1] = a[1] - 1;
    }
  }
  
  printf("%d\n", sum);
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
using namespace std;
int main(void)
{ 
  long long int i,j,k,n,a[100001],b[100000],ans;
  cin>>n;
  ans=0;
  for(i=0;i<=n;i++){cin>>a[i];}
  for(i=0;i<n;i++){cin>>b[i];}
  
  for(i=0;i<n;i++)
  {
    if(a[i]>=b[i]){ans+=b[i];}
    else if(a[i]+a[i+1]>=b[i])
    {
      a[i+1]=a[i+1]+a[i]-b[i];
      ans+=b[i];
    }
    else
    {
      ans=ans+a[i]+a[i+1];
      a[i+1]=0;
    }
            
  }
  cout<<ans;
}

Measured memory_bytes: 5160
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder
{
    class Program
    {
        public static void Main(string[] args)
        {
            string S = Console.ReadLine();
            int N = S.Length;
            int num0 = S.Count(s => s == '0');
            int num1 = N - num0;
            Console.WriteLine((num0 > num1)? num1 * 2: num0 * 2);
        }
    }
}

Measured memory_bytes: 13244
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <climits>
#include <cstring>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

using namespace std;

const int N_MAX = 1000000;

int rows[N_MAX];
int cols[N_MAX];
int dp[101][101];

int main(){
  int n;
  cin >> n;
  
  rep(i, 0, n) cin >> rows[i] >> cols[i];
  rep(i, 0, n){
    rep(j, 0, n){
      dp[i][j] = INT_MAX;
    }
  }
  // init
  rep(i, 0, n-1) dp[i][i+1] = rows[i] * rows[i+1] * cols[i+1];
  
  // strtegy
  /*
    dp[i][j] ... minimum multiplication times i to j
    dp[i][j] = dp[i][k] + dp[k+1][j] + row[i] * col[k] * col[j] for all i < k < j-1

    (i, j) -> (0, 1), (1, 2), ..., (0, 2), (1, 3), ..., (0, n-1), ...
   */
  
  // iteration
  rep(k, 2, n){
    rep(i, 0, n){
      int j = i + k;
      //cout << i << ", " << j << endl;
      if(j >= n) break;
      int tmp = INT_MAX;
      for(int l=i; l < j; l++){
	// cout << i << ", " << l << ", " << j << endl;
	int residue = rows[i] * cols[l] * cols[j];
	int cand_min = dp[i][l] + dp[l+1][j] + residue;
	if(i == l) cand_min = dp[l+1][j] + residue;
	if(j == l+1) cand_min = dp[i][l] +  residue;
	if(tmp > cand_min) tmp = cand_min;
      }
      if(dp[i][j] > tmp) dp[i][j] = tmp;
    }
  }
  
  /*
  for(int k=2; k<n; k++){
    for(int row=0; row+k < n; row++){
      int col = row+k;
      if(dp[row][col-1] < dp[row+1][col]){
	dp[row][col] = dp[row][col-1] + rows[row] * rows[col] * cols[col];
      }
      else{
	dp[row][col] = dp[row+1][col] + rows[row] * cols[row] * cols[col];
      }
      cout << "row: " << row << ", col: " << col << ", dp[row][col]: " << dp[row][col] << endl;
      cout << rows[row] << ", " << cols[row] << ", " << cols[col] << endl;
    }
    }*/
  /*
    rep(i, 0, n){
    rep(j, 0, n){
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }
  */
  if(n==1) cout << 0 << endl;
  else{
    cout << dp[0][n-1] << endl;
  }
  // multiple the result
  
  return 0;
}



Measured memory_bytes: 3132
while True:
    m,f,r=map(int, input().split())
    
    if m==f==r==-1:
        break
    
    if m==-1 or f==-1:
        print("F")
    elif m+f>=80:
        print("A")
    elif m+f>=65:
        print("B")
    elif m+f>=50:
        print("C")
    elif m+f>=30 and r>=50:
        print("C")
    elif m+f>=30:
        print("D")
    else:
        print("F")


Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// --------------------------------------------------------
#define FOR(i,l,r) for (int i = (l); i < (r); ++i)
#define REP(i,n) FOR(i,0,n)
#define SORT(c) sort((c).begin(), (c).end())
#define RSORT(c) sort((c).rbegin(), (c).rend())
#define SZ(c) ((int)(c).size())
#define debug(x) cerr << #x << " = " << (x) << '\n';
using P = pair<int,int>;
using VS = vector<string>;
using VI = vector<int>;
using VVI = vector<VI>;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const ll MOD = 1e+9 + 7;
// --------------------------------------------------------


const int MAX_N = 1e+5;
VI dp(MAX_N, 0);

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);

    int N; cin >> N;
    VI h(N); REP(i,N) cin >> h[i];

    dp[1] = dp[0] + abs(h[1] - h[0]);
    FOR(i,2,N) {
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
    }

    cout << dp[N-1] << '\n';

    return 0;
}

// https://atcoder.jp/contests/dp/tasks/dp_a


Measured memory_bytes: 3972
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    int n,ans=0;
    cin>>n;
    rep(i,n){
        int a=i+1,b=0;
        while(a>0) a=a/10,b++;
        if(b%2) ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 256
#!perl
use strict;
use warnings;
use utf8;
use feature qw/say/;

my $S = <STDIN>;
chomp $S;
my @S = split(//, $S);

sub sum_all {
    my ($head, $tail) = @_;
    my @back = split(//, $tail);
    my $count = 0;

    $count += $_ for @$head;
    $count += $tail;
    my $front = '';
    while ( defined (my $n = shift @back) ) {
        $front .= $n;
        $count += sum_all([@$head, $front], join('', @back)) if (@back > 0);
    }
    return $count;
}

say sum_all([], $S);

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch PopularVote | diff PopularVote.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address PopularVote.cpp && ./a.out

/*
 
 4/4/2020
 
 5:02-5:13 WA
 
 */

const int MAX_N=1e6+1;
int A[MAX_N];
int N,M;

void solve() {
  sort(A,A+N),reverse(A,A+N);
  int sum=accumulate(A,A+N,0);
  long double t=1.0*sum/(4*M);
  int cnt=0;
  REP(i,N) if(A[i]>=t) ++cnt;
  cout<<(cnt>=M?"Yes":"No")<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>M;
  REP(i,N) cin>>A[i];
  solve();
  
  return 0;
}


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

int main()
{
	int n,m;
	while(cin>>n>>m&&n)
	{
		vector<int> a;
		int ans=0;
		for(int i=0;i<n;i++)
		{
			int x;
			cin>>x;
			a.push_back(x);
		}
		sort(a.begin(),a.end());
		for(int i=0;i<n%m;i++)
		{
			ans+=a[0];;
			a.erase(a.begin());
		}
		n-=n%m;
		for(int i=0;i<a.size();i++)ans+=a[i];
		for(int i=0;i<n/m;i++)
		{
			ans-=a[i*m];
		}
		cout<<ans<<endl;
	}
	
}

Measured memory_bytes: 1232
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		//System.out.println(n);
		String ans = "";
		while(n>0){
			n--;
			ans += (char)('a' + (n%26));
			//if(n<26) break;
			n = n/26;
		}
		for(int i=ans.length()-1 ; i>=0; i--){
			System.out.print(ans.charAt(i));
		}
		
	}

}

Measured memory_bytes: 27080
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int t[100010],n,c,k;
bool jd(int x)
{
	int cnt=1; bool flag=true;
	for(int i=2;i<=n;i++)
	{
		if(t[i]-t[i-cnt]>k) {x--;cnt=0;}
		if(t[i]-t[i-cnt]<=k)
		{
			cnt++;
		}
		if(cnt==c) {x--;cnt=0;}
		if(x<0) {flag=false;break;}
	}
	if(flag==false) return false;
	else return true;
}
int main()
{
	scanf("%d%d%d",&n,&c,&k);
	for(int i=1;i<=n;i++) cin>>t[i];
	sort(t+1,t+1+n);
	int head=1,tail=n,mid;
	while(head<tail)
	{
		mid=(head+tail)/2;
		if(jd(mid-1)==false) head=mid+1;
		else tail=mid;
	}
	printf("%d",tail);
	return 0;
}

Measured memory_bytes: 640
N,M = map(int, input().split())
A = [int(i) for i in input().split()]

from heapq import heapify, heappop, heappush

heapify(A)

BC = [[int(i) for i in input().split()] for _ in range(M)]
BC.sort(key=lambda x:-x[1])

flag = False # 更新終わりフラグ
for b,c in BC:
    while b > 0:
        MINA = heappop(A)
        if c > MINA:
            heappush(A, c)
        else:
            heappush(A, MINA)
            flag = True
            break
        b -= 1
    if flag: break


print(sum(A))

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

int main(){
    int n; cin>>n;
    int a[110];
    for (int i = 0; i < n; i++)
    {
        cin>>a[i];
    }
    
    sort(a,a+n,greater<int>());
    int alice = 0;
    int bob = 0;
    for (int i = 0; i < n; i++)
    {
        if (i%2==0)
        {
            alice += a[i];
        }
        else
        {
            bob+=a[i];
        }
        
    }
    cout << alice - bob << endl;
    
}

Measured memory_bytes: 256
N=int(input())
A = list(map(int, input().split()))
gray=any([1<=i<=399 for i in A])
brown=any([400<=i<=799 for i in A])
green=any([800<=i<=1199 for i in A])
sky=any([1200<=i<=1599 for i in A])
blue=any([1600<=i<=1999 for i in A])
yellow=any([2000<=i<=2399 for i in A])
orange=any([2400<=i<=2799 for i in A])
red=any([2800<=i<=3199 for i in A])
color_list=[gray,brown,green,sky,blue,yellow,orange,red]
count= color_list.count(True)
change=len([i for i in A if 3200<=i])
if count==0:
    print(1,change)
else:
    print(count,count+change)

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

#include <stdio.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define vec vector
#define ref(a) &(a)

typedef long long ll;

using namespace std;

ll l, r;

int solve() {
  ll res = pow(10, 9)+1;
  if (r - l >= 2019) return 0;
  for (ll i = l; i < r; i++) {
    for (ll j = i+1; j <= r; j++) {
      res = min(res, i * j % 2019);
    }
  }
  return res;
}

int main() {
  cin >> l >> r;
  cout << solve() << endl;
  return 0;
}

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

template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

const int max_n = 10;
int n;
struct point{
    int x, y;
};
point pts[max_n];
double ans=0, cnt=0;
vector<int> v;

int main(){
    cin >> n;
    rep(i, n) {
        cin >> pts[i].x >> pts[i].y;
        v.push_back(i);
    }

    do{
        int X = pts[v[0]].x, Y = pts[v[0]].y;
        for(int i=1; i<n; i++){
            int nx = pts[v[i]].x, ny = pts[v[i]].y;
            ans += sqrt((X-nx)*(X-nx) + (Y-ny)*(Y-ny));
            X = nx, Y = ny;
        }
        cnt++;
    }while(next_permutation(v.begin(), v.end())); 
    ans /= cnt;
    printf("%.7f\n", ans);
    return 0;
}

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

class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
        int[] x = new int[N],y = new int[N];
		double total = 0,result;

		for(int i = 0;i < N;i++)
		{
			var p = Console.ReadLine().Split(' '); //positionストラクトにxPos,yPosを入れ込む
			x[i] = int.Parse(p[0]);
			y[i] = int.Parse(p[1]);
		}
		for(int i = 0;i < N - 1;i++)
		{
			for(int j = i + 1;j < N;j++)
			{
				total += Math.Sqrt(Math.Pow(x[i] - x[j], 2) + Math.Pow(y[i] - y[j], 2));
			}
		}
		//totalは各地点間の距離の和
		result = total * 2 / N;
		Console.Write(result);
	}
}



Measured memory_bytes: 11092
#include<stdio.h>

int main()
{
  int n;
  int d[100];
  int temp;
  int count = 0;
  int i = 0;
  
  scanf("%d", &n);
  for(int i = 0 ; i < n; i++)
    {
      scanf("%d", &d[i]);
    }
  while(1)
    {
      if(i == n-1)
	{
	  break;
	}
      if(d[i] > d[i+1])
	{
	  temp = d[i];
	  d[i] = d[i+1];
	  d[i+1] = temp;
	  i = 0;
	  count++;
	  continue;
	}
      i++;
    }
  for(int i = 0 ; i < n; i++)
    {
      if(i == n-1)
	{
	  printf("%d\n", d[i]);
	  break;
	}
      printf("%d ", d[i]);
    }
  printf("%d\n", count);
}



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

int main() {
	int N,M,ans=0;
  cin>>N>>M;
  for(int i=0;i<M;i++){
    int a;
    cin>>a;
    ans+=a;
  }
  if(ans>N)cout<<-1<<endl;
  else cout<<N-ans<<endl;
}


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

int main(){
	int n;cin>>n;
	multiset<P>a,b,c;
	multiset<int>al,ar,bl,br;
	rep(i,n){
		int l,r;cin>>l>>r;
		b.insert(P(l,r));
		bl.insert(l);
		br.insert(r);
	}
	auto calc=[&](){
		int La=*al.rbegin(),Ra=*ar.begin()+1;
		int Lb=*bl.rbegin(),Rb=*br.begin()+1;
		return max(0,Ra-La)+max(0,Rb-Lb);
	};
	int Max=0;
	int Ma=0;
	while(!b.empty()){
		P p=*b.begin();
		bl.erase(bl.find(p.first));
		br.erase(br.find(p.second));
		b.erase(b.begin());
		
		al.insert(p.first);
		ar.insert(p.second);
		a.insert(P(p.second,p.first));
		Ma=max(Ma,p.second-p.first+1);
		
		if(!al.empty()&&!bl.empty())Max=max(Max,calc());
		if(a.size()>1&&!b.empty()){
			int Lb=*bl.rbegin(),Rb=*br.begin()+1;
			Rb=min(Rb,a.begin()->first+1);
			Max=max(Max,Ma+max(0,Rb-Lb));
		}
	}
	cout<<Max<<endl;
}

Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll vis[200003]={0};
ll vis2[200003]={0};
vector<ll>adj[200003];
vector<ll>x;
ll ans[200003];
ll n;
void dfs(ll k,ll count)
{
    vis[k]=1;
    vis2[k]=1;
    for(ll i=0;i<adj[k].size();i++)
    {
           if(vis[adj[k][i]]==0)
           {
               count++;
               dfs(adj[k][i],count);
           }
    }
    for(ll i=1;i<=n;i++)
    {
        if(vis2[i]==1)
            {ans[i]=count;
              vis2[i]=0;
            }
    }

}

int main()
{
   ll a,b,c,d,i;
   cin>>a>>b>>c>>d;
   for(i=1;;i++)
   {
       if(a>0&&c>0)
       {
           if(i%2==1)
           {
               c=c-b;
           }
           else
            a=a-d;
       }
     if(a<=0)
     {cout<<"No"<<endl;
       return 0;
     }
     if(c<=0)
     {
         cout<<"Yes"<<endl;
         return 0;
     }
   }

}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

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

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

const ll INF=(ll)1e19;
//const int INF=(1<<30);
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}


int main(){
  int n;
  cin >> n;
  VI a(n);
  REP(i,n)cin >> a[i];

  VI l(n),r(n);

  l[0] = a[0];
  FOR(i,1,n){
    l[i] = gcd(a[i],l[i-1]);
  }
  r[0] = a[n-1];
  FOR(i,1,n){
    r[i] = gcd(a[n-1-i],r[i-1]);
  }

  int ans=1;
  REP(i,n-2){
    chmax(ans, gcd(l[i],r[n-3-i]));
  }
  chmax(ans, l[n-2]);
  chmax(ans, r[n-2]);

  cout << ans << endl;
}



Measured memory_bytes: 1408
import sys

if __name__ == "__main__":
    n,m = map(int,input().split())
    c = list(map(int,input().split()))
    INF = 10**18
    dp = [INF]*(n+1)
    dp[0] = 0
    for i in c:
        for j in range(i,n+1):
            dp[j] = min(dp[j],dp[j-i]+1)
    print(dp[-1])


Measured memory_bytes: 7520
#include<bits/stdc++.h>
#define maxn 300010
using namespace std;
char s[maxn], t[maxn];
int main()
{
	int n, m, len, x, y, xl, xr, yl, yr;
	scanf("%d%d%d", &n, &m, &len);
	scanf("%d%d", &x, &y);
	scanf("%s", s + 1);
	scanf("%s", t + 1);
	xl = 1; xr = n; yl = 1; yr = m;
	for (int i = len; i >= 1; i--)
	{
		if (t[i] == 'L') yr = min(yr + 1, m);
		else if (t[i] == 'R') yl = max(yl - 1, 1);
		else if (t[i] == 'U') xr = min(xr + 1, n);
		else xl = max(xl - 1, 1);
		if (s[i] == 'R') yr--;
		else if (s[i] == 'L') yl++;
		else if (s[i] == 'D') xr--;
		else xl++;
		if (yr < yl || xr < xl) {puts("NO"); return 0;}
	}
	if (x >= xl && x <= xr && y >= yl && y <= yr) puts("YES");
	else puts("NO");
	return 0;
}

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

int n,x,ar[200000];

int main() {

    while(cin>>n>>x) {

        for(int i=0; i<n; i++)
            scanf("%d",ar+i);

        long long ans=0;

        for(int i=0; i<=n-2; i++)
            if(ar[i]+ar[i+1]>x) {
                int extra=(ar[i]+ar[i+1])-x;
                ans+=extra;

                if(extra<=ar[i+1])
                    ar[i+1]-=extra, extra=0;
                else {
                    extra-=ar[i+1];
                    ar[i+1]=0;
                    ar[i]-=extra;
                }

            }

//      for(int i=0;i<n;i++)
//        printf("%d ",ar[i]);
//
//      puts("");

        cout<<ans<<endl;
    }


    return 0;
}

/*

4 4
0 4 4 2

*/


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	for (auto &u : v) os << u << el;
	return (os);
}

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

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int N; cin >> N;
	multiset<int> st1, st2;
	vint dat(1<<N); cin >> dat;
	sort(rbegin(dat), rend(dat));
	st1.insert(dat[0]);
	for (int i = 1; i < (1<<N); i++) st2.insert(dat[i]);

	for (int i = 0; i < N; i++) {
		queue<int> que;
		for (auto itr = --end(st1);; itr--) {
			int val = *itr;
			auto pos = st2.lower_bound(val);
			if (pos == begin(st2)) {
				cout << "No" << endl;
				return;
			}
			--pos;
			que.push(*pos);
			st2.erase(pos);
			if (itr == begin(st1)) break;
		}
		while (!que.empty()) {
			int val = que.front(); que.pop();
			st1.insert(val);
		}
	}
	cout << "Yes" << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 13696
#include <stdio.h>

int main(){

  int x,y,c,d;

  scanf("%d%d",&x,&y);

  if(x < y){
    c=x;
    x=y;
    y=c;
  }

  while(y != 0){
  
    d=x%y;
    x=y;
    y=d;
  }

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

 return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c;
  cin >> c;
  if (c == 'a' ||c == 'e'||c == 'i'||c == 'o'||c == 'u'){
    cout << "vowel" << endl;
  }
  else{
    cout << "consonant" << endl;
  }

}

Measured memory_bytes: 256
fn main(){
    let mut cost:i32 = read();
    cost = 1000 - cost % 1000;
    if cost < 1000{
        println!("{}", cost);
    }else{
        println!("{}", 0);
    }
}

fn read<T: std::str::FromStr>() -> T{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}




Measured memory_bytes: 2136
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<set>
#include<vector>
#include<bitset>
#include<map>
#define N 200005
#define ll long long
#define oo 1000000000000000
#define For(i,x,y) for(int i=x;i<=y;i++)
#define Rep(i,x,y) for(int i=x;i>=y;i--)
#define Forn(i,x,y) for(int i=x;i<y;i++)
using namespace std;
inline int read(){int x=0,f=0;char ch=getchar();for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=1;for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-48;return f?-x:x;}
inline void write(ll x){if(x<10) putchar(x+48);else write(x/10),putchar(x%10+48);}
inline void writeln(ll x){if(x<0) putchar('-'),x=-x;write(x);putchar('\n');}
int n,a[N];
ll sum[N],py;
ll ans=oo;
int main(){
	n=read();For(i,1,n) a[i]=read(),sum[i]=sum[i-1]+a[i],py+=a[i];
	Forn(i,1,n) ans=min(ans,abs(py-sum[i]-sum[i]));
	writeln(ans);
	return 0;
}

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

string keys[2] = {
    "qwertasdfgzxcvb",
    "yuiophjklnm"
};

int main(){
    string s;
    while(cin >> s, s[0] != '#'){
        int id = (keys[0].find(s[0]) != -1? 0 : 1), cnt = 0;
        for(char c : s){
            if(keys[id].find(c) == -1){
                cnt++;
                id ^= 1;
            }
        }
        cout << cnt << endl;
    }
    return 0;
}


Measured memory_bytes: 3108
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n;
    cin >> n;
    vector<int> v(n), c(n);
    rep(i, n) cin >> v[i];
    rep(i, n) cin >> c[i];

    int ans = 0;
    rep(i, n){
        if(v[i] - c[i] > 0){
            ans += v[i] - c[i];
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
using namespace std;

int main(){

	int p,m,c;
	scanf("%d %d %d",&p,&m,&c);

	printf("%d\n",p+m+c);

	return 0;
}

Measured memory_bytes: 2668
'use strict'
function Main(input) {
    input = input.split("\n");
    const n = parseInt(input[0].split(' ')[1], 10)
    const arr = input[1].split(' ').map(v => parseInt(v, 10)).sort((a,b) => b - a)
    let sum = 0;
    for (let i = 0; i < n; i ++) {
        sum += arr[i]
    }
    console.log(sum)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <stdio.h>

int main(){
  int dice[7];
  char com[1000];
  int i,j,k;
  int n,e,w,s,top;

  for(i=1;i<=6;i++) scanf("%d",&dice[i]);
  scanf("%s",com);
  top=1;
  n=5;
  s=2;
  w=4;
  e=3;



  for(i=0;com[i]!='\0';i++){
    if(com[i]=='N'){
      n=top;
      top=s;
      s=7-n;
    }else if(com[i]=='S'){
      s=top;
      top=n;
      n=7-s;
    } else if(com[i]=='W'){
      w=top;
      top=e;
      e=7-w;
    }else if(com[i]=='E'){
      e=top;
      top=w;
      w=7-e;
    }
  }
  printf("%d\n",dice[top]);

  return 0;
}

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

struct edge{
	int to, cap, rev;

	edge(int to, int cap, int rev){
		this->to = to;
		this->cap = cap;
		this->rev = rev;
	}
};

struct dinic{
	int inf = 1e9;
	vector<vector<edge>> e;
	vector<int> level, iter;

	dinic(int n){
		e.resize(n);
		level.resize(n);
		iter.resize(n);
	}

	void addedge(int from, int to, int cap){
		e[from].emplace_back(edge(to, cap, e[to].size()));
		e[to].emplace_back(edge(from, 0, e[from].size() - 1));
	}

	void bfs(int s){
		fill(level.begin(), level.end(), -1);
		queue<int> q;
		level[s] = 0;
		q.push(s);
		while(!q.empty()){
			int v = q.front();
			q.pop();
			for(auto &&ee:e[v]) if(0 < ee.cap && level[ee.to] < 0){
				level[ee.to] = level[v] + 1;
				q.push(ee.to);
			}
		}
	}

	int dfs(int v, int t, int f){
		if(v == t) return f;
		for(int &i = iter[v]; i < e[v].size(); i++){
			edge &ee = e[v][i];
			if(0 < ee.cap && level[v] < level[ee.to]){
				int d = dfs(ee.to, t, min(f, ee.cap));
				if(0 < d){
					ee.cap -= d;
					e[ee.to][ee.rev].cap += d;
					return d;
				}
			}
		}
		return 0;
	}

	int max_flow(int s, int t){
		int flow = 0;
		while(true){
			bfs(s);
			if(level[t] < 0) return flow;
			fill(iter.begin(), iter.end(), 0);
			int f;
			while(0 < (f = dfs(s, t, inf))) flow += f;
		}
	}
};

int main(){
	int h, w;
	cin >> h >> w;
	string s[h];
	for(int i = 0; i < h; i++) cin >> s[i];
	pair<int, int> source, sink;
	for(int i = 0; i < h; i++) for(int j = 0; j < w; j++){
		if(s[i][j] == 'S') source = {i, j};
		if(s[i][j] == 'T') sink = {i, j};
		if(s[i][j] == 'S' || s[i][j] == 'T') s[i][j] = 'o';
	}
	if(source.first == sink.first || source.second == sink.second){
		cout << -1 << endl;
		return 0;
	}
	dinic d(h + w + 2);
	for(int i = 0; i < h; i++) for(int j = 0; j < w; j++) if(s[i][j] == 'o'){
		d.addedge(i, h + j, 1);
		d.addedge(h + j, i, 1);
	}
	d.addedge(h + w, source.first, 1e9);
	d.addedge(h + w, h + source.second, 1e9);
	d.addedge(sink.first, h + w + 1, 1e9);
	d.addedge(h + sink.second, h + w + 1, 1e9);
	cout << d.max_flow(h + w, h + w + 1) << endl;
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <functional>


using namespace std;

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

    if(n==0)n=1;
    if(m==0)m=1;

    cout<<(n*(n-1)+m*(m-1))/2;

}






Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n=0,c_AC=0,c_WA=0,c_TLE=0,c_RE=0;
cin>>n;
while (n>0)
{
    string s;
    cin>>s;
    if ( s[0]=='A'){c_AC++;}
    if ( s[0]=='W'){c_WA++;}
    if ( s[0]=='T'){c_TLE++;}
    if ( s[0]=='R'){c_RE++;}
    n--;
}
cout<<"AC x "<<c_AC<<endl;
cout<<"WA x "<<c_WA<<endl;
cout<<"TLE x "<<c_TLE<<endl;
cout<<"RE x "<<c_RE<<endl;
}

Measured memory_bytes: 3608
/**
    A	Darker and Darker    	C++14 (GCC 5.4.1)
    Accept
**/
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <algorithm>    // std::copy
#include <iterator>     // std::back_inserter
#include <set>
using namespace std;
 
int main(){
    int H,W;
    cin >> H >> W;
    vector<vector<char>> A(H, vector<char>(W,0));
    vector< pair<int, int> > black;
    int count = 0;
    for(int i = 0 ; i < H  ; i++){
        for (int j = 0; j < W ; j++){
            cin >> A[i][j];
            if(A[i][j] == '#') {
                black.push_back(make_pair(i,j));
                count++;
            }
        }
    }
    // for(int i = 0 ; i < H  ; i++){
    //     for (int j = 0; j < W ; j++){
    //         cout << A[i][j];
    //     }
    //     cout << endl;
    // }
    
    int ans = 0;
    int start = 0;
    while(1){
        // cout << endl;
        // int count = 0;
        // for(int i = 0 ; i < H  ; i++){
        //     for (int j = 0; j < W  ; j++){
        //         // cout << A[i][j] << " ";
        //         if(A[i][j] == '#')  count++;
        //     }
        //     // cout << endl;
        // }
        if(count == H * W){break;}
 
        int m = black.size();
        for(int i = start ; i < m; i++){
            // black.erase(black.begin());
 
            // if(A[black[i].first][black[i].second] == '#'){
                if(black[i].first != 0 && A[black[i].first-1][black[i].second] != '#'){
                    A[black[i].first-1][black[i].second] = '#';
                    count++;
                    black.push_back(make_pair(black[i].first-1,black[i].second));
                }
                if(black[i].second != 0 && A[black[i].first][black[i].second-1] != '#'){ 
                    A[black[i].first][black[i].second-1] = '#';
                    count++;
                    black.push_back(make_pair(black[i].first,black[i].second-1));
                }
                if(black[i].first != H - 1 && A[black[i].first+1][black[i].second] != '#'){ 
                    A[black[i].first+1][black[i].second] = '#';
                    count++;
                    black.push_back(make_pair(black[i].first+1,black[i].second));
                }
                if(black[i].second !=  W - 1 && A[black[i].first][black[i].second+1] != '#'){
                    A[black[i].first][black[i].second+1] = '#';
                    count++;
                    black.push_back(make_pair(black[i].first,black[i].second+1));
                }
 
            // }
        }
        start = m;
        ans++;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 10992
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define mod 1000000007
#define INF2 9999999999
#define INF (1 << 30)
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)

using namespace std;
using ll = __int64_t;

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

void solve(){
    ll n;
    ll sum = 0;
    cin >> n;

    for(ll i = 1; i <= n; i++){
        sum += i;
        if(sum == n){
            for(ll j = 1; j <= i; j++){
                cout << j << endl;
            }
            return;
        }else if(sum > n){
            for(ll j = 1; j <= i; j++){
                if(j != sum-n) cout << j << endl;
            }
            return;
        }
    }
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
const int P = 1e9+7;
typedef long long i64;

int fpm(int x,int d) {
  int ret = 1;
  for(; d; x = (i64) x*x % P, d >>= 1)
    if(d & 1) ret = (i64) ret*x % P;
  return ret;
}

int fac[4000005];
int inv[4000005];
int f[2005][2005];

int C(int n,int m) {
  return (i64) fac[n] * inv[m] % P * inv[n-m] % P;
}

int N, K;
int main() {
  if(fopen("input.txt","r")) {
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  }

  scanf("%d%d", &N, &K);

  if(K == 1) {
    puts("1");
    return 0;
  }
  
  int n = N * K;
  
  fac[0] = 1;
  for(int i = 1;i <= n; ++i) 
    fac[i] = (i64) fac[i-1] * i % P;
  inv[n] = fpm(fac[n], P-2);
  for(int i = n-1; ~i; --i)
    inv[i] = (i64) inv[i+1] * (i+1) % P;

  f[N][N] = 1;
  for(int i = N; ~i; --i) {
    for(int j = N; ~j; --j) {
      if(i) (f[i-1][j] += f[i][j]) %= P;
      if(i < j) (f[i][j-1] += (i64) f[i][j] * C(i+j*(K-1)-1,K-2) % P) %= P;
    }
  }
  
  // for(int i = 0;i <= N; ++i)
  //   for(int j = 0;j <= N; ++j)
  //     printf("%d%c", f[i][j], " \n"[j == N]);
  
  printf("%lld", (i64) f[0][0] * fac[N] % P);
  
  return 0;
}


Measured memory_bytes: 47232
#include<stdio.h>

int main(){
  int N;
  scanf("%d", &N);

  int H[N], i;

  for(i = 0; i < N; i++){
    scanf("%d", &H[i]);
  }

  int ans = 0;

  int max = 0;

  for(i = 0; i < N; i++){
    if(max <= H[i]){
      ans++;
      max = H[i];
    }
  }

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

  return 0;
}


Measured memory_bytes: 128
import numpy as np

N, M, Q = map(int, input().split())
data = [[0] * (N+1) for _ in range(N+1)]

for i in range(M):
    l, r = map(int, input().split())
    data[l][r] += 1

data = np.array(data)
np.cumsum(data, axis=0, out=data)
np.cumsum(data, axis=1, out=data)
data = data.tolist()
#print(data)
for i in range(Q):
    p, q = map(int, input().split())
    p -= 1
    x = data[q][q]
    x -= data[p][q] + data[q][p]
    x += data[p][p]
    print(x)

Measured memory_bytes: 23548
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for(int i = 1, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;
using namespace std;
#define repi(itr, ds) for(auto itr = ds.begin(); itr != ds.end(); itr++)

// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for(T &x : vec) is >> x;
  return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for(int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}\n   ";
  return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  repi(itr, map_var) {
    os << *itr;
    itr++;
    if(itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  repi(itr, set_var) {
    os << *itr;
    itr++;
    if(itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}

#define DUMPOUT cerr

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
  DUMPOUT << head;
  if(sizeof...(Tail) > 0) {
    DUMPOUT << ", ";
  }
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...)                                                             \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                             \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
          << "    ",                                                          \
      dump_func(__VA_ARGS__)
#else
#define DEB if(false)
#define dump(...)
#endif

typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

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

  auto ps = vector<int>(N + 1);
  for(int i = 2; i <= N; i++) {
    int cur = i;
    for(int j = 2; j <= i; j++) {
      while(cur % j == 0) {
        ps[j]++;
        cur /= j;
      }
    }
  }
  auto size = [&](int m) {
    auto num = vector<int>();
    copy_if(ALL(ps), back_inserter(num), [&](int x) { return x >= m - 1; });
    return num.size();
  };
  auto ans = size(75) + size(25) * (size(3) - 1) + size(15) * (size(5) - 1) + size(5) * (size(5) - 1) * (size(3) - 2) / 2;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define PPF pop_front
#define PPB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int,int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int mod=1e9+7;
//
//
struct poi{
  int X;int Y;int Z;
  bool operator<(const poi&R)const{
    return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
  }
};
//
//
int main(){
	int D,C;
	cin>>D>>C;
	cout<<D*C<<endl;
	return 0;
}



Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int N;
  cin >> N;
  
  string S;
  cin >> S;
  bool bl = true;
  if (N%2) bl = false;
  else {
    if (S.substr(N/2) != S.substr(0, N/2)) bl = false;
  }
  if (bl) puts("Yes");
  else puts("No");
  return 0;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
int main(){
	unsigned long long int N;
	cin >> N;
	cout << (N*(N+1))/2 - ((N/3)*(N/3 + 1)/2)*3 - ((N/5)*(N/5 + 1)/2)*5 + ((N/15)*(N/15 + 1)/2)*15 << "\n";
}

Measured memory_bytes: 3632
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>

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

using namespace std;
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

int main()
{
    ll n;
    cin >> n;
    ll result = ((n - 1) * n) / 2;
    cout << result << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s[] = new String [n];
    for(int i = 0;i < n;i++){
      s[i] = sc.next();
    }

    long m = 0;
    long a = 0;
    long r = 0;
    long c = 0;
    long h = 0;
    for(int i = 0;i < n;i++){
      if(s[i].indexOf('M') == 0){
        m++;
      }
      if(s[i].indexOf('A') == 0){
        a++;
      }
      if(s[i].indexOf('R') == 0){
        r++;
      }
      if(s[i].indexOf('C') == 0){
        c++;
      }
      if(s[i].indexOf('H') == 0){
        h++;
      }
    }

    long sum = m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h;

    System.out.println(sum);
  }
}


Measured memory_bytes: 52884
A=[list(map(int,input().split())) for _ in range(3)]
N=int(input())
C=[[0]*3 for _ in range(3)]

for _ in range(N):
  b=int(input())
  for i in range(3):
    for j in range(3):
      if b==A[i][j]:
        C[i][j]=1

for i in range(3):
  if C[i][0]==1 and C[i][1]==1 and C[i][2]==1:
    print("Yes")
    exit()
for i in range(3):
  if C[0][i]==1 and C[1][i]==1 and C[2][i]==1:
    print("Yes")
    exit()
if C[0][0]==1 and C[1][1]==1 and C[2][2]==1:
  print("Yes")
  exit()
if C[0][2]==1 and C[1][1]==1 and C[2][0]==1:
  print("Yes")
  exit()
print("No")


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

using namespace std;

const int N = 22;
const int MOD = 1e9 + 7;
const int MASK = (1 << 21) + 5;

bitset <MASK> vis[N];
int n, a[N][N], f[N][MASK];

int call (int at, int mask) {
  if (at == n) return 1;
  if (vis[at][mask]) return f[at][mask];
  vis[at][mask] = 1;
  for (int i = 0; i < n; ++i) {
    if (mask & 1 << i) continue;
    if (!a[at][i]) continue;
    f[at][mask] += call(at + 1, mask | 1 << i);
    if (f[at][mask] >= MOD) f[at][mask] -= MOD;
  }
  return f[at][mask];
}

int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> a[i][j];
    }
  }
  cout << call(0, 0) << '\n';
  return 0;
}



Measured memory_bytes: 166912