akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

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

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

 int a,b;cin>>a>>b;
 cout<<max(0,a-2*b)<<endl;

  return 0;
}

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

int N, K;
set<int> result;
int card[16];
bool used[16];

void solve(int k, int ans) {
	if(k == K) {
		result.insert(ans);
		return;
	}
	for(int i = 0; i < N; i++) {
		if(used[i] == true) continue;
		used[i] = true;
		int t = card[i];
		int next;
		if(t < 10) {
			next = ans * 10;
		} else {
			next = ans * 100;
		}
		next += t;
		solve(k + 1, next);
		used[i] = false;
	}
}

int main() {
	for(;;) {
		result.clear();
		memset(used, 0, sizeof used);

		cin >> N >> K;
		if(N == 0 && K == 0)
			break;

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

		solve(0, 0);
		cout << result.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
ll strtoint(string str);
int main(){
	fast;
	ll n,s=0; cin>>n;
	for(auto i=1;i<=n;++i){
		if(!(i%3==0&&i%5==0 || i%3==0 || i%5==0))s+=i;
	}
	cout<<s<<'\n';
	return 0;
}
ll strtoint(string str){
	ll x=0;
	stringstream ss;
	ss<<str;
	ss>>x;
	return x;
}

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

using namespace std;

int main() {
#ifndef ONLINE_JUDGE
	freopen("../input.txt", "r", stdin);
	freopen("../output.txt", "w", stdout);
#endif
	long long N;
	cin >> N;
	long long arr[N];
	for (long long i = 0; i < N; i++) {
		cin >> arr[i];
	}
	sort(arr, arr + N);
	long long ans = 0;
	for (long long i = 0; i < N; i++) {
		for (long long j = i + 1; j < N; j++) {
			if (arr[i] != arr[j]) {
				for (long long k = j + 1; k < N; k++) {
					if (arr[i] != arr[j] && arr[i] != arr[k] && arr[j] != arr[k]) {
						if (arr[i] + arr[j] > arr[k]) {
							ans++;
						}
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int dx[] = { 1,-1, 0, 0};
int dy[] = { 0, 0,-1, 1};

struct NODE{
	int x;
	int y;
	int bx;
	int by;
	int depth;
};

int main(){
	NODE q,t;
	int gx,gy,w,h;
	while(cin >> w >> h && (w||h) ){
		int data[9][9];
		for(int i=0;i<9;i++)for(int j=0;j<9;j++)
			data[i][j] = 1;
		
		for(int i=0;i<h;i++)for(int j=0;j<w;j++){
			cin >> data[1+i][1+j];
			if(data[1+i][1+j] == 2){
				t.bx = 1+j;
				t.by = 1+i;
				data[i+1][1+j] = 0;
			}else if(data[1+i][1+j] == 4){
				t.x = 1+j;
				t.y = 1+i;
				data[i+1][1+j] = 0;
			}else if(data[1+i][1+j] == 3){
				gx = 1+j;
				gy = 1+i;
				data[i+1][1+j] = 0;
			}
		}
		/*for(int i=0;i<9;i++){
			for(int j=0;j<9;j++)cout << data[i][j];
			cout << endl;
		}*/
		queue<NODE> Q;
		t.depth = 0;
		Q.push(t);
		int done[9][9][9][9];
		rep(i,9)rep(j,9)rep(k,9)rep(l,9)
			done[i][j][k][l] = (1<<21);
		
		int ret = (1<<21);
		while(Q.size()){
			//cout << q.x << "," << q.y << " - " << q.bx << "," << q.by << endl;
			q = Q.front();
			Q.pop();
			if( q.depth >= done[q.x][q.y][q.bx][q.by])continue;
			done[q.x][q.y][q.bx][q.by] = q.depth;
			if(q.bx == gx && q.by == gy){
				ret = min(ret,q.depth);
			}
			for(int i=0;i<4;i++){
				t.x = q.x+dx[i];
				t.y = q.y+dy[i];
				t.bx = q.bx;
				t.by = q.by;
				t.depth = q.depth;
				if(data[t.y][t.x] == 1)continue;
				
				if(t.x == q.bx && t.y == q.by){
					int tx = q.bx + dx[i];
					int ty = q.by + dy[i];
					if(data[ty][tx] == 1)continue;
					t.bx = tx;
					t.by = ty;
					t.depth = q.depth + 1;
				}
				Q.push(t);				
			}
		}
		if(ret != (1<<21))cout << ret << endl;
		else cout << -1 << endl;
	}
}

Measured memory_bytes: 0
N = int(input())
nums = list(map(int, input().split()))
nodes = []
currentLeaf = 1
fail = False
#check from top
for i in range(N + 1):
	nodes.append(currentLeaf)
	currentLeaf = (currentLeaf-nums[i])*2
	if (currentLeaf < 0):
		fail = True
		break 
if (fail):
	print(-1)
else:
  #check from bottom
  currentLeaf = 0
  totalNode = 0
  for i in reversed(range(N+1)):
      currentLeaf += nums[i]
      currentLeaf = min(currentLeaf, nodes[i])
      totalNode += currentLeaf

  if (fail):
      print(-1) 
  else:
      print(totalNode)

Measured memory_bytes: 674388
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include<functional>
#include<queue>
#include<regex>
#include<time.h>
#include<type_traits>

using namespace std;
using ll = long long;

constexpr ll MOD = 1000000007;
constexpr ll INF = 1050000000;
constexpr ll LONGINF = 1050000000000000000;

template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }//aに最大値が入る
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }//aに最小値が入る
template<class T>void swap(T &a, const T &b) { T tmp = a; a = b; b = a; return; }//aとbを入れ替える

int main() {
	ll h, w; cin >> h >> w;

	ll ans = INF;

	if (h % 3 == 0 || w % 3 == 0) { cout << 0 << endl; return 0; }//均等に出来る


	for (int k = 0; k < 2; k++) {
		for (int i = 1; i < w; i++) {
			ll check_x = (ll)i * h;
			ll check_y = h / 2 * (w - i);
			ll check_z = h * w - (check_x + check_y);
			ans = min(ans, max({ check_x,check_y,check_z }) - min({ check_x,check_y,check_z }));

			ll check_a = (ll)i*h;
			ll check_b = (w - i) / 2 * h;
			ll check_c = h * w - (check_a + check_b);

			ans = min(ans, max({ check_a,check_b,check_c }) - min({ check_a,check_b,check_c }));

			//cout << check_x << " " << check_y << " " << check_z << endl;
			//cout << check_a << " " << check_b << " " << check_c << endl;
		}
		swap(h, w);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
SC = [[] for _ in range(N)]

error = False
for _ in range(M):
    s, c = map(int, input().split())
    s -= 1
    if SC[s] and SC[s] != c:
        error = True
        break
    else:
        SC[s] = c

if error:
    print(-1)
elif SC[0] == 0 and len(SC) > 1:
    print(-1)
else:
    if not SC[0] and len(SC) == 1:
        SC[0] = 0
    if not SC[0] and len(SC) > 1:
        SC[0] = 1
    if len(SC) > 1 and not SC[1]:
        SC[1] = 0
    if len(SC) > 2 and not SC[2]:
        SC[2] = 0
    print(''.join(map(str,SC)))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define int long long int
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
const int N=5e6+10;
const int mod=1e9+7;
int arr[N],iarr[N];
int logi(int n){int p=0;while(n/2){n=n/2;p++;}return p;}
int poww(int x,int y){int pro=1;while(y){if(y&1)pro=((pro%mod)*(x%mod)%mod);y=y>>1;x=((x%mod)*(x%mod)%mod);}return pro;}
map<int,int> mp;
int arr1[1000001],arr2[1000001];

void solve()
{
	string s;
	cin>>s;
	int i=0,j=s.size()-1,cnt=0;;
	while(i<=j)
	{
		if(s[i]!=s[j])
		{
			cnt++;
		}
		i++,j--;
	}
	cout<<cnt;
}

int32_t main()																																	
{
	fast;
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


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

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
#define exit(a, b) return cout << a, b;

#define PB push_back
#define MP make_pair

#define sd(n) scanf("%lld", &n)
#define pdn(n) printf("%lld\n", n);
#define pds(n) printf("%lld ", n);
#define endl '\n'

#define forn(a, b, i) for (int i = a; i < b; i += 1)
#define all(v) v.begin(), v.end() 

using vi = vector<int>;
using vb = vector<bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

#define print(stuff) cout << stuff << endl
#define len(stuff) stuff.size()

#define int long long

const int inf = (int) 5e15;
const int upper = 1e5 + 10;
const int M = 1000000007;

int answer = 0;

char arr[1005][1005];
// int fac[upper], invfac[upper];
// int modexp (int a, int b, int m) {
// 	if (b == 0) return 1;
// 	int ans = modexp (a, b/2, m); 
// 	ans = (ans * ans) % m;

// 	if (b % 2 == 1) ans = (ans * a) % m;

// 	return ans;
// }
// void prec() {
// 	fac[0] = 1;
// 	for (int i = 1; i < upper; i += 1) fac[i] = (fac[i - 1] * i) % M;
// 	invfac[upper - 1] = modexp(fac[upper - 1], M - 2, M);
// 	for (int i = upper - 2; i >= 0; i -= 1) invfac[i] = (invfac[i + 1] * (i + 1)) % M;
// }


signed main () {
	start_routine();
	speed();
	#ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// freopen("errlog.txt", "w", stderr);
	#endif	

	string s; cin >> s;
	if (len(s) == 2) {
		cout << s;
	}
	else {
		reverse(all(s));
		cout << s;
	}
 	end_routine();
}	

Measured memory_bytes: 256
#include<bits/stdc++.h>
#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(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using vint = vector<int>;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, i;
	cin >> n >> i;
	cout << n - i + 1 << "\n";
	return 0;
}

Measured memory_bytes: 896
# C - Many Requirements
from collections import deque
from typing import Tuple

N: int
M: int
conditions: Tuple[Tuple[int, int, int, int]]


def dfs():
    queue = deque([[1]])
    highest = 0
    while queue:
        seq = queue.popleft()
        if len(seq) == N + 1:
            highest = max(
                highest, sum(d for a, b, c, d in conditions if seq[b] - seq[a] == c)
            )
        else:
            for i in range(seq[-1], M + 1):
                queue.append(seq + [i])
    return highest


def main():
    global N, M, conditions
    N, M, Q, *ABCD = map(int, open(0).read().split())
    conditions = tuple(zip(*[iter(ABCD)] * 4))
    print(dfs())


if __name__ == "__main__":
    main()


Measured memory_bytes: 25604
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);

		int a = scan.nextInt();
		int b = scan.nextInt();

		int tmp = a * b;

		if (tmp % 2 == 0) {
			System.out.println("Even");
		} else {
			System.out.println("Odd");
		}
	}

	//***********************以下共通関数************************************************
	/**
	 * 文字列を反転して返す
	 * @param pStr 文字列
	 * @return 反転した文字列
	 */
	public static String myReverse(String pStr) {
		if (pStr.length() < 1) {
			return "";
		}

		StringBuffer sb = new StringBuffer(pStr);
		return sb.reverse().toString();
	}

	/**
	 * 余りを求める。
	 * @param a
	 * @param b
	 * @return 余り。余りがマイナスの時はプラスで返す。
	 */
	public static long myMod(long a, long b) {
		long ret = 0;

		ret = a % b;

		if (ret < 0) {
			ret += b;
		}

		return ret;
	}

	/**
	 * 乗数を求める ※mod対応
	 * @param kisu 基数
	 * @param josu 乗数
	 * @param primeNumMod_0 法 mod値 使わない場合は「0」
	 * @return
	 */
	public static long myPowWithMod(long kisu, long josu, long primeNumMod_0) {

		long ans = 1;

		//乗数が0の場合→1
		if (josu == 0)
			return 1;

		if (primeNumMod_0 == 0) {
			//modを使わないとき

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= kisu;
					josu = josu / 2;
				} else {
					//累乗が奇数の時
					ans *= kisu;
					josu--;
				}
			}

			return ans;

		} else {
			//modを使うとき

			//初めに桁を落とす
			kisu = myMod(kisu, primeNumMod_0);

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= myMod(kisu, primeNumMod_0);
					josu = josu / 2;

				} else {
					//累乗が奇数の時
					ans *= myMod(kisu, primeNumMod_0);
					josu--;

				}
			}

			return myMod(ans, primeNumMod_0);

		}

	}

}


Measured memory_bytes: 27104
#include<stdio.h>

int main(void){
  long int W,H,x,y;
  scanf("%ld %ld %ld %ld",&W,&H,&x,&y);
  long int min[2];
  if(2*x ==W && 2*y==H) printf("%.1lf 1",(double)0.5*W*H);
  else printf("%.1lf 0",(double)0.5*W*H);
  
  return 0;
}
  

Measured memory_bytes: 128
N, K = map(int, input().split())
H = []
for i in range(N):
    H.append(int(input()))
# print(N, K, H)

H.sort()
# print(H)

ans = H[-1] - H[0]
# print(ans)
for i in range(N - K + 1):
    val = H[i + K - 1] - H[i]
    # print(i, val)
    ans = min(ans, val)

print(ans)


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

using ll = long long;
template <class T> using p = pair<T, T>;
template <class T> using vt = vector<T>;

#define rep(i, n)   for (int i = 0; i < (n); i++)
#define sz(x)       (int)(x).size()
#define eb          emplace_back
#define pb          push_back
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

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

  int n;
  cin >> n;
  ll mx;
  cin >> mx;
  ll ans = 0;
  rep (i, n - 1) {
    ll num;
    cin >> num;
    if (mx >= num) ans += (mx - num);
    else mx = num;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include<time.h>
#include<string>
#include<cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include <limits>
#include <climits>
#include <numeric>
#include<cassert>
#include<cctype>
#include<iterator>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=c_max(x,a)
#define chmin(x,a) x=c_min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
#define MOD 1000000007
#define INF 1<<30
#define INFTY 1000000000000000001LL
#define MAX_INT INT_MAX
#define Endl '\n'
#define greater greater<int>()
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
// g++ -o a a.cpp -Wall -lm -std=c++14

int main(){
    int n,m;cin>>n>>m;
    VI P(m),Y(m);
    rep(i,m)cin>>P[i]>>Y[i],--P[i];
    vector<VI> vals(n);
    rep(i,m)vals[P[i]].push_back(Y[i]);
    rep(v,n){
        sort(ALL(vals[v]));
        vals[v].erase(unique(ALL(vals[v])),vals[v].end());
    }
    rep(i,m){
        int v=P[i];
        printf("%06d",v+1);
        int id=lower_bound(ALL(vals[v]),Y[i])-vals[v].begin();
        printf("%06d\n",id+1);
    }
}

Measured memory_bytes: 8576
#include <iostream>
#include <cmath>
#include <climits>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string.h>
#include <iomanip>
#include <ctype.h>

#define ll          long long int
#define ull         unsigned long long int
#define pb          push_back
#define pii         pair<int,int>
#define F           first
#define S           second
#define vi          vector<int>
#define vli          vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define M_PI        3.14159265358979323846
#define mp          make_pair
#define sz(x)       (int)x.size()
//#define hell        1000000007
#define matrix      vector<vector<ll>>
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define eps 0.000000001
#define all(a)      (a).begin(),(a).end()
const long long INF = (long long) 1e7+1;
const long long mod = (long long) 998244353;
const long long hell = (long long) 1000000007;

using namespace std;
#include <stdio.h>
ll m;
ll power(ll x,ll y)
{
  ll res=1;
  while(y>0)
  {
    if(y%2) res=(x%hell*res%hell)%hell;
    x=(x%hell*x%hell)%hell;
    y=y/2;
  }
  return res;
}

ll modinv(ll x){
  return power(x,hell-2);
}

void solve();


void fastIO() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int main(){
   fastIO();
    solve();
}
//void sieve();
ll pw(ll k,ll x);
ll gcd(ll x,ll y);

/*
  For freq or prime factors

for(auto pri:prime){
  while(k%pri==0){
    pcnt[pri]++;
    k/=pri;
  }
}*/

bool issafe(int x,int y,int n,int m){
  return (x>=0 && y>=0 && x<n && y<m);
}


void solve(){
  int test;
  //cin>>test;
  test=1;
  ll fact[100001];
  fact[0]=1;
  
  for(int i=1;i<=100000;i++)
  fact[i]=(fact[i-1]%hell*i%hell)%hell;
  
  while(test--){
       int n,k;
       cin>>n>>k;
       
       ll a[n];
       forn(i,0,n)
       cin>>a[i];
       
       sort(a,a+n);
       
       ll ans=0;
       for(int i=n-1;i>=0;i--){
           if(i+1>=k){
               ans=((ans%hell+(fact[i]%hell*modinv(fact[k-1])%hell*modinv(fact[i-k+1])%hell)*a[i]%hell)%hell)%hell;
           }
           else
           break;
       }
       
       for(int i=0;i<n;i++){
           if(n-i>=k){
               ans=((ans%hell-(fact[n-i-1]%hell*modinv(fact[k-1])%hell*modinv(fact[n-i-k])%hell)*a[i]%hell)+hell)%hell;
           }
           else
           break;
       }
       cout<<ans;
  }    
}    

    




///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1

ll gcd(ll x,ll y){
  if(x==0)
  return y;
  else
  return gcd(y%x,x);
}


ll pw(ll k,ll x){
  if(x==0)
  return 1;
  if(x&1)
  return ((pw(k,x-1))*k);
  else
  return ((pw(k,x/2))*(pw(k,x/2)));
}


Measured memory_bytes: 1792
# 入力
X=int(input())

# 最大値（1のべき乗数で初期化）
mx=1

# 2〜1000
for a in range(2,1000):

  i=2
  while True:
    # べき乗
    b=pow(a,i)

    # X以下の場合、最大値保存
    if b<=X:
      mx=max(mx,b)
    else:
      # Xをオーバーした場合はループを抜ける
      break

    i+=1

# 最大値を出力
print(mx)

Measured memory_bytes: 2940
N = int(input())
A = list(map(int, input().split()))
broke = False
for i in range(N):
    if A[i] % 2 == 0:
        if A[i] % 6 != 0 and A[i] % 10 != 0:
            print('DENIED')
            broke = True
            break
if broke == False:
    print('APPROVED')

Measured memory_bytes: 3064
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from collections import Counter
def resolve():
    N,D=pin()
    X=[lispin()for i in range(N)]
    cnt=0
    for i in range(N-1):
        for j in range(i+1,N):
            temp=0
            #print(i,j)
            for d in range(D):
                temp+=(X[i][d]-X[j][d])**2
            #print(temp)
            for k in range(100000):
                if k**2==temp:cnt+=1
                if k**2>temp:break
    print(cnt)
#%%submit!
resolve()

Measured memory_bytes: 38512
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdio.h>
using namespace std;
#define ll long long
int main(int argc, char const *argv[])
{
    int a, b, c;
    scanf("%d/%d/%d", &a, &b, &c);
    printf("2018/%02d/%02d\n", b, c);
    return 0;
}

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

int main() {
	long long int a,b,c,d,z[4]={0};
	cin>>a>>b>>c>>d;
	z[0]=a*c;
	z[1]=a*d;
	z[2]=b*c;
	z[3]=b*d;
	long long int sum=-1000000000000000000;
	for(int i=0;i<4;i++){
		if(z[i]>sum){
			sum=z[i];
		}
	}
	cout<<sum;
	return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack> 
#include <sstream>
#include <set>

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}

using namespace std;
// now

struct UnionFind {
    vector<int> d;
    UnionFind(int n=0) : d(n,-1){}
    int Find (int x){//根の番号を探す
        if(d[x] < 0) return x;
        return d[x] = Find(d[x]);
    }
    bool unite (int x, int y){
        x = Find(x); y = Find(y);
        if(x == y ) return false;
        if(d[x] < d[y]){
            swap(x,y);
        }
        d[x] += d[y];
        d[y] = x;
        return true;
    } 

    bool same(int x, int y){
        return Find(x) == Find(y);
    }
    int size(int x) {
        return (-d[Find(x)]);
    }
};


ll nCr (ll n, ll r){
    ll ans = 1;
    for(ll i = n ; i > n-r ; i --){
        ans *= i;
    }
    for(ll i = 1 ; i<= r; i ++){
        ans /= i;
    }
    return ans ;
}

int nPr (int n,int r){
    int ans = 1;
    for(int i = n ; i > n-r ; i --){
        ans *= i;
    }
    return ans ;
}
 ll modd = 1e9+ 7;
ll wa (ll n,ll mi, ll ma){
    ll ans  = n * (mi+ma) /2;
    return ans;
}
ll kw(ll k,ll n){
    
    ll ans  =0;
    ll mi,ma;
    mi= wa(k,0,k-1);
    
    ma = wa(k,n-k+1,n);
    
    return (ma-mi +1)%modd;
}
char grid[7][7];
int h,w,k;

int main(){

    cin >> h >> w >> k;

    

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

    int ans = 0;
    REP(i,1<<h){
        REP(j,1<<w){
            int cnt = 0;
            REP(i1,h){
                REP(j1,w){
                    if(i>>i1 &1)continue;
                    if(j >> j1&1)continue;
                    if(grid[i1][j1] == '#')cnt++;
                }
            }
            if(cnt == k) ans ++;
        }

    }

    cout << ans <<endl;


}





Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<ll,ll>
#define poly vector<ll>
#define mem(a) memset((a),0,sizeof(a))
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x.size()))
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
ll rnd(){
	ull ans=0;
	For(i,0,4)ans=ans<<15^rand();
	return ans%((ull)1<<63);
}
const int N=100005;
vector<int> v[N];
int ans=1,qf[N],a[N],rt;
void dfs(int p,int fa){
	qf[p]=0;
	int sum=0;
	for(auto i:v[p])if(i!=fa){
		dfs(i,p);
		if(qf[i])qf[p]=1;
		else sum++;
	}
	//cout<<p<<" "<<sum<<" "<<qf[p]<<endl;
	if(sum>1){
		ans+=sum-1; qf[p]=1;
	}
}
void init(int p,int fa){
	a[p]=p;
	for(auto i:v[p])if(i!=fa){
		init(i,p); a[p]=a[i];
	}
	if(v[p].size()>=3&&rt==-1){
		for(auto i:v[p])if(i!=fa)rt=a[i];
	}
}
int main(){
	#ifdef Brollan
		freopen("1.in","r",stdin);
	#endif
	int n=read();
	For(i,1,n-1){
		int s=read()+1,t=read()+1;
		v[s].pb(t); v[t].pb(s);
	}
	rt=-1; init(1,0); rt=max(rt,0);
		dfs(rt,0); 
		cout<<ans<<endl;
		return 0;
}

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

typedef long long ll;

ll gcd( ll x, ll y );
ll lcm( ll x, ll y );

int main()
{
    int x, y = 0;

    for ( int i = 0; i < 10; ++i ) {
        cin >> x;
        y += x;
    }
    cout << y << endl;
    return 0;
}

ll gcd( ll x, ll y )
{
    if ( y == 0 ) return x;
    return gcd( y, x % y );
}

ll lcm( ll x, ll y )
{
    return x / gcd( x, y ) * y;
}




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

 int main() {
   ll S;
   cin >> S;
   ll n = 0;

   ll tmp = S;
   while (tmp > 0) {
     tmp /= 10;
     n++;
   }
   ll ans = 0;

   if (n == 1) ans = S;
   else {
     for (ll i = 0; i < (1 << n - 1); i++) {
       ll s = S;
       for (ll j = n - 2; j >= 0; j--) {
         if (i & (1 << j)) {
           ans += s / (ll)pow(10, j + 1);
           s %= (ll)pow(10, j + 1);
         }
       }
       ans += s;
     }
   }
   cout << ans << endl;
 }


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

#define REP(i,n) for(long long i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(long long i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9


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

  string ans;
  int left = 0, right = 0;
  REP(i, N){
    if(S[i] == '('){
      left++;
      ans+='(';
    }
    else{
      ans+=')';
      if(left == 0){
        ans.insert(ans.begin(), '(');
      }
      else{
        left--;
      }
    }
  }
  REP(i, left){
    ans+=')';
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int a, b, c, tmp;
    cin >> a >> b >> c;
    if (a > b){
        tmp = a;
        a = b;
        b = tmp;
    }
    if (a > c){
        tmp = a;
        a = c;
        c = tmp;
    }
    if (b > c){
        tmp = b;
        b = c;
        c = tmp;
    }
    cout << a << " " << b << " " << c << endl;
    
}


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

typedef long long ll;

const int N = 3e3 + 10;
int n, K, q, a[N], bak[N];
vector<int> c;

int main() {
    cin >> n >> K >> q;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    int ans = 1e9 + 7;
    for (int i = 1; i <= n; ++i) {
        copy(a + 1, a + n + 1, bak + 1);
        c.clear();
        int lbound = a[i];
        int l = 1, r = 1;
        while (l <= n) {
            r = l;
            while (r <= n && a[r] >= lbound) ++r;
            if (r > l) {
                sort(bak + l, bak + r);
                for (int j = 0; j < r - l - K + 1; ++j)
                    c.push_back(bak[l + j]);
            }
            l = max(r, l + 1);
        }
        sort(c.begin(), c.end());
        if ((int) c.size() >= q)
            ans = min(ans, c[q - 1] - lbound);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    tmp0 = input[0].split(" ");
    A = Number(tmp0[0])
    B = Number(tmp0[1])
    tmp = A+B
    if(tmp%2 === 0)
    {
        console.log(tmp/2)
    }else{        
        console.log("IMPOSSIBLE")
    }
}
  //*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// Main("0 3\n");

Measured memory_bytes: 7372
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cctype>

#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <map>
#include <algorithm>

using namespace std;

//#define deb_table(arr, w, h) rep(w_n, w){  rep(h_n, h) {cout << arr[w][h] << " "  } cout << endl; }
#define rep(i, n) for(int i = 0; i < n; i++)

// P(価値, 重さ)
typedef pair<int ,int> P;

class data
{
    public:
        int v;
        int w;
    public:
        data(int a, int b){ v=a; w=b;}
};

int case_num=1;
/*
風呂敷の耐えられる重さW(1000 以下)
お宝の数 N
お宝 1 の価値(整数), お宝 1 の重さ( ＜ W:整数)
お宝 2 の価値(整数), お宝 2 の重さ( ＜ W:整数)
.
.
.
お宝 N の価値(整数), お宝 N の重さ( ＜ W:整数)
*/

int max( int a, int b)
{
    if(a > b) { return a;}
    else { return b; }
}

//
int solve()
{
    int w,n;
    vector<data> v;
    cin >> w;
    //終わりのときは-1を返す
    if(w == 0) { return -1; }

    cin >> n;
    int value, weight;

    //int dp[n+1][w+1];
    //dp[考えたインデックス][重さ]
    //インデックスは０から数えてnまで　=> [n+1]
    //重さは０から数えてwまで        　=> [w+1]
    int dp[n+1][w+1];
    //dp init
    rep(i,n+1)rep(j,w+1) dp[i][j] = 0;  

    rep(i, n)
    {
        scanf("%d,%d" ,&value, &weight);
        v.push_back( data(value, weight) );
    }

    //dp[何番目まで考えたか][重さ] = 最大値

    rep(i,n)
    {
        rep(j,w+1)
        {
            //dp[i][j]から二つ分岐、分岐先ではmaxをとる
            if(0 <= i && i < n && 0 <= j && j  <= w )
            {
                //真下に落とす
                //printf("dp[%d][%d] = %d\n", i,j, dp[i][j]);
                //puts("or");
                //printf("dp[%d][%d] = %d\n", i+1,j, dp[i+1][j]);
                dp[i+1][j] = max(dp[i+1][j] , dp[i][j]);
               // if(i==2){ printf("dp[2][0] = %d", dp[2][0]); }
                if ( j+v[i].w <= w )
                {
                    //if(i == 1) { printf("dp[%d][%d]", i+1, j+v[i].w );  cout << dp[i+1][j+ v[i].w] << endl; }
                    //dp[i+1][j + v[i+1].w] = max(dp[i+1][j + v[i+1].w] , dp[i][j] + v[i+1].v);
                    dp[i+1][j + v[i].w] = max(dp[i+1][j + v[i].w] , dp[i][j] + v[i].v);
                }
            }
        }
    }
    /*
    rep(i,n+1){
        cout << "[";
        rep(j,w+1){
            cout << dp[i][j] << " ";
        }
        cout << "]" << endl;
    }
    */
    //maxを取る値の最小の重さを探す
    int least_weight;
    rep(j,w){
         if(dp[n][j] < dp[n][j+1])
         {
             least_weight= j+1;
         }
    }
   
    cout << "Case " << case_num << ":" << endl;
    cout << dp[n][w] << endl;
    cout << least_weight<< endl;
    return 0;
}

int main()
{
    while (1)
    {
        if(solve() == -1){ break;};
        case_num++;
    }
}

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

map<int, int> sftNums;

void addSftNums(vector<int> work) {
  int scale=0;
  int sftNum=0;
  map<int, int> sftMap;
  for (auto w: work) {
    if (w==0) continue;
    sftNum+=w*pow(10,scale++);
    sftMap[w]++;
  }

  if (sftMap[7]>0&&sftMap[5]>0&&sftMap[3]>0){
    if (sftNum!=0){
      sftNums[sftNum]++;
    }
  }
  return;
}

void dfs(vector<int> work, int num, int idx){
  work.push_back(num);
  if(idx==9) {
    addSftNums(work);
    return;
  }
  int nums[4] = {0,3,5,7};
  for (int i = 0; i < 4; i++) {
    dfs(work, nums[i], idx+1);
  }
  return;
}

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

  vector<int> blank;
  dfs(blank, 0, 0);

  int ans = 0;
  for (auto sftNum: sftNums){
    if (sftNum.second ==0 ) continue;

    if (sftNum.first > N) break;

    ans++;
  }

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

Measured memory_bytes: 1536
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()

int main() {
		int N;
		cin >> N;
		vector<ll> f(N, 0);
		for (int i = 0; i < N; i++) {
				for (int j = 0; j < 10; j++) {
						int t;
						cin >> t;
						if (t) f[i] |= (1LL<<j);
				}
		}

		int p[N][11];
		for (int i = 0; i < N; i++) {
				for (int j = 0; j <= 10; j++) {
						cin >> p[i][j];
				}
		}

		int ans = -1e9;
		for (ll joisino = 1; joisino < (1<<10); joisino++) {
				vector<int> cnt(N, 0);
				for (int i = 0; i < N; i++) {
						for (int j = 0; j < 10; j++) {
								if (joisino & (1LL<<j)) {
										if (f[i] & (1LL<<j)) {
												cnt[i]++;
										}
								}
						}
				}

				int x = 0;
				for (int i = 0; i < N; i++) {
						x += p[i][cnt[i]];	
				}
				ans = max(ans, x);
		}

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


Measured memory_bytes: 384
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define get0(x)     (get<0>(x))
#define get1(x)     (get<1>(x))
#define get2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       9223372036854775807LL
#define LLMIN       -9223372036854775808LL
#define IMAX        2147483647
#define IMIN        -2147483648
typedef long long LL;
using namespace std;

int N;
LL A[20000],B[20000],R[20000];

int main(void){
    cin>>N;
    REP(i,N){LL x;cin>>x;x--;R[x]=i+1;}
    REP(i,N){A[i]=(i+1)*30000;B[i]=(N-i)*30000;}
    REP(i,N){B[i]+=R[i];}
    REP(i,N){cout<<A[i]<<" ";}
    cout<<endl;
    REP(i,N){cout<<B[i]<<" ";}
    cout<<endl;
     return 0;
}

Measured memory_bytes: 1152
def main():
    n = int(input())
    n_lis = []
    n_lis= list(map(int, input().split()))
    q = int(input())
    q_lis = []
    sum_lis = []
    q_lis = list(map(int, input().split()))
    
    for i in range(2**n):
        test_lis = []
        for j in range(n):
            if ((i>>j) & 1):
                test_lis.append(n_lis[j])
        sumtest = sum(test_lis)
        sum_lis.append(sumtest)
    for qs in q_lis:
        if qs in sum_lis:
            print("yes")
        else:
            print("no")

if __name__ == "__main__":
    main()



Measured memory_bytes: 43080
n,k=map(int,input().split())
s=input()
d=[]
f=True

if "0" not in s:
  print(n)
  exit()
if s[0]=="0":
    d.append(0)
    f=False

seq=1
for i in range(1,n):
    if s[i]=="0" and not f:
        seq+=1
    elif s[i]=="0" and f:
        f=False
        d.append(seq)
        seq=1
    elif s[i]=="1" and f:
        seq+=1
    else:
        f=True
        d.append(seq)
        seq=1
    if i==n-1:
      d.append(seq)
if s[-1]=="0":
    d.append(0)
l=len(d)
res=[0]*(l+1)
res[0]=0
for i in range(1,l+1):
    res[i]=res[i-1]+d[i-1]
ans=1
for i in range(1,l+1):
    if i%2==1:
        continue
    if 2*k+i-1>l:
      a=res[l]-res[i-2]
    else:
      a=res[2*k+i-1]-res[i-2]
    if a>ans:
        ans=a
print(ans)


Measured memory_bytes: 46448
#pragma comment(linker, "/stack:200000000")

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define ret(a) return cout<<a,0;

using namespace std;

mt19937 mrand(random_device{}()); 
const ll mod = 1e9 + 7;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

typedef pair < int , int > pii ;
#define y1 sfasfd
const int N = 3e5 + 123;
ll f[N] ,inv[N];
ll get(int x1 , int y1 , int x2 , int y2){
	if(x1 == x2 && y2 == y1)
		return 1;
	int l1 = x2 - x1, l2 = y2 - y1 ;
	return f[l1 + l2] * inv[l1] % mod * inv[l2] % mod;
}
int main(){ 
	int h , w , a, b;
	f[0] = 1;
	for(int i = 1 ; i <= 300000 ; i++){
		f[i] = f[i - 1] * i % mod;
	}inv[0] = 1;
	inv[300000] = powmod(f[300000] , mod - 2 , mod);
	for(int i = 299999 ; i >= 1 ; i--){
		inv[i] = inv[i + 1] * (i + 1) % mod;
	}
	cin >> h >> w >> a >> b;
	ll ans = 0;
	for(int i = 1 ; i <= h - a ; i++){
		ans += get( i , b + 1, h , w) * get(1 , 1 , i , b)  % mod;
		ans %= mod;
	}
	cout << ans;
}

Measured memory_bytes: 4992
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define ld long double
#define mp make_pair

void print(vector<auto> &a)
{
    for (int i = 0; i<a.size(); i++) cout<<a[i]<<' ';
    cout<<endl;
}

void get(vector<auto> &a)
{
    for (int i = 0; i<a.size(); i++) cin>>a[i];
}

const ll p = 998244353;

int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    s = s%p;
    if (s<0) s+=p; 
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}


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

    int n;
    cin>>n;
    vector<ll> a(n);
    get(a);
    vector<ll> dp(n);
    dp[0] = 0;
    dp[1] = abs(a[1]-a[0]);
    for (int i = 2; i<n; i++)
    dp[i] = min(dp[i-2] + abs(a[i]-a[i-2]), dp[i-1] + abs(a[i]-a[i-1]));
    cout<<dp[n-1];
    
}

Measured memory_bytes: 1792
S = input()
F = "ATGC"
cnt = 0
n = len(S)
for i in range(n):
  for j in range(i+1, n+1):
    flg = True
    for k in range(i, j):
      flg *= (S[k] in F)
    if flg:
      cnt = max(cnt, j - i)
print(cnt)


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

double calc_dist(int x1, int y1, int x2, int y2){
  double ret = 0.0;
  ret = sqrt(double((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)));
  return ret;
}

int main(){
  int n; cin >> n;
  double ans = 0.0;
  double div = 1.0;
  vector<int> perm(n);
  vector<pair<int, int> > coo(n, pair<int, int>());
  for(int i = 0; i < n; i++){
  	int tmpx, tmpy; cin >> tmpx >> tmpy;
    coo[i] = make_pair(tmpx, tmpy);
    
    perm[i] = i;
    div *= double(i + 1);
  }
  
  do{
    double tmp = 0.0;
    for(int i = 0; i < n-1; i++){
      tmp += calc_dist(coo[perm[i]].first, coo[perm[i]].second,
                       coo[perm[i+1]].first, coo[perm[i+1]].second);
    }
    ans += tmp;
  }while(next_permutation(perm.begin(), perm.end()));
  cout << fixed << setprecision(10) << ans / div << endl;
}

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

int main()
{
	int i,n,p[12],ans;
  
	cin >> n;

	for(i=0;i<n;i++){
		cin >> p[i];
	}

	sort(p, p+n);

	for(i=0;i<n-1;i++){
		ans += p[i];
	}
	ans += p[n-1]/2;

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

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

ll ap2(ll x, ll n) {
  if (x == 1) return n;
  else ap2(x/2, n+1);
}

ll pow(ll a, ll b) {
  ll res = 1;
  for (ll i = 1; i <= b; i++){
    res *= a;
  }
  return res;
}

int main() {
  ll H;
  ll sum = 0, res = 0;
  cin >> H;

  res = ap2(H, 0);

  for (ll i = 0; i <= res; i++) {
    sum += pow(2, i);
  }
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
  int n;
  cin >> n;
  vector<vi> a(n,vi(n-1));
  rep(i,n)rep(j,n-1){
    cin >> a[i][j];
    a[i][j]--;
  }
  rep(i,n)reverse(rng(a[i]));
  queue<P> q;
  auto check = [&](int i){
    if(a[i].size() == 0)return;
    int j = a[i].back();
    if(a[j].size() == 0)return;
    if(a[j].back() == i){
      if(i>j)swap(i,j);
      P p(i,j);
      q.push(p);
    }
  };
  rep(i,n){
    check(i);
  }
  int day = 0;
  while(!q.empty()){
    day++;
    queue<P> prevQ;
    swap(q,prevQ);
    int flag[1001][1001];
    while(!prevQ.empty()){
      int i = prevQ.front().fi,j = prevQ.front().se;
      prevQ.pop();
      if(flag[i][j] == 535)continue;
      flag[i][j] = 535;
      a[i].pop_back();
      a[j].pop_back();
      check(i);check(j);
    }
  }
  rep(i,n){
    if(a[i].size() != 0){
      cout<<-1<<endl;
      return 0;
    }
  }
  cout<<day<<endl;
  return 0;
}

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

typedef long long ll;
using namespace std;
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int num=0;
    while(n){
        num++;
        n/=k;
    }
    printf("%d\n",num);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

const int N = 21;
struct node{
    int a,c,d;
};
vector<node> G[N];
int ans = 0;

int n, m, q;
void dfs(int lev,int p,vector<int>& ve){
    if(lev == n+1){
        int cs = 0;
        for(int i=0;i<n;++i){
            for(auto nd:G[i+1]){
                if(ve[nd.a] == ve[i+1] - nd.c)
                {
                    cs += nd.d;
                }
            }
        }
        ans = max(cs,ans);
        return ;
    }
    for(int i=p;i<=m;++i){
        ve.push_back(i);
        dfs(lev+1,i,ve);
        ve.pop_back();
    }
}
int main(){
    int a,b,c,d;
    cin >> n >> m >> q;
    for(int i=1;i<=q;++i){
        cin >> a >> b >> c >> d;
        G[b].push_back({a,c,d});
    }
    vector<int> ve;
    dfs(0,1,ve);
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
int K, N;
int main(){
	int answer;
	scanf("%d %d",&N,&K);
	answer = K;
	if (N == 1){
		printf("%d\n", K);
		return 0;
	}
	for (int i = 0; i < N - 1; i++){
		answer *= K - 1;
	}
	printf("%d\n", answer);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long i64;
using std::cout;
using std::endl;
using std::cin;

int main(){
	std::string s; cin >> s;
	
	const i64 MOD = 1e9 + 7;
	const std::string w = "ABC";
	i64 dp[s.size() + 1][4][5] = {}; //dp[i][j][k]; j := ?の場合のみ仕様 1->A, 2->B, 3->C
	dp[0][0][0] = 1;
	for(int i = 0; i < s.size(); i++) {
		if(s[i] == '?') {
			//for(int j = 1; j < 4; j++) dp[i + 1][j][0] = 1;
			for(int j = 1; j < 4; j++) {
				for(int k = 0; k < 4; k++) {
					for(int l = 0; l < 4; l++) {
						dp[i + 1][j][k] += dp[i][l][k];
						dp[i + 1][j][k] %= MOD;
					}
				}
			}
			
			for(int j = 0; j < 3; j++) {
				int to = w[j] - 'A';
				
				for(int k = 0; k < 4; k++) {
					dp[i + 1][to + 1][to + 1] += dp[i][k][to];
					dp[i + 1][to + 1][to + 1] %= MOD;
				}
			}
		} else {
			// dp[i + 1][0][0] = 1;
			for(int j = 0; j < 4; j++) {
				for(int k = 0; k < 4; k++) {
					dp[i + 1][0][j] += dp[i][k][j];
					dp[i + 1][0][j] %= MOD;
				}
			}
			
			int to = s[i] - 'A';
			for(int k = 0; k < 4; k++) {
				dp[i + 1][0][to + 1] += dp[i][k][to];
				dp[i + 1][0][to + 1] %= MOD;
			}
		}
	}
	
	i64 ans = 0;
	for(int i = 0; i < 4; i++) (ans += dp[s.size()][i][3]) %= MOD;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 16128
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mod 1e9+7
using namespace std;
int main()
{
   ll n,m;
   
   cin>>n>>m;
   
   ll a[m];
   int sum=0;
   
   for(ll i=0;i<m;i++)
   {
       cin>>a[i];
       sum+=a[i];
   }
   
   if(sum>n)
   {
       cout<<-1<<endl;
   }
   else
   {
       cout<<n-sum<<endl;
   }
   
   
    return 0;
}


Measured memory_bytes: 3660
N,M = map(int,input().split())
P=[0]*M
Y=[0]*M
T=[0]*M
for i in range(M):  
  P[i],Y[i] = map(int,input().split())
  T[i] = [i,P[i],Y[i]]

T.sort(key=lambda x:(x[1],x[2]))
for i,item in enumerate(T):
  if i==0:
    item.append(1)
  else:
    if T[i][1]==T[i-1][1]:
      item.append(T[i-1][3]+1)
    else:
      item.append(1)
      
T.sort(key=lambda x:(x[0],x[3]))

for item in T:
  city = str(item[1])
  city = (6-len(city))*"0"+city
  order =  str(item[3])
  order = (6-len(order))*"0"+order
  print(city+order)

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

LL dp[2][100010], w[110], v[110], n, m;

LL solve(int pos, int val) {
	if(pos == n) return 0;
	LL &ret = dp[pos][val];
	if(ret != -1) return ret;
	ret = 1000000000000000;
	ret = min(ret, solve(pos + 1, val));
	ret = min(ret, solve(pos + 1, val + v[pos]) + w[pos]);
	cout<<pos<<" "<<val<<" "<<ret<<endl;
	return ret;
}

int main() {
	memset(dp, -1, sizeof(dp));
	cin>>n>>m;
	for(int i = 0; i < n; i++) {
		cin>>w[i]>>v[i];
	}
//	solve(0, 0);
	LL ans = 0;
//	for(int i = 0; i <= 100000; i++) {
//		if(dp[n-1][i] <= m) ans = max(ans, (LL)i);
//	}
	int mx = 100000;
	for(int i = 0; i < 2; i++) {
		for(int j = 1; j <= mx; j++) dp[i][j] = 1000000000000000;
		dp[i][0] = 0;
	}
	for(int i = 0; i < n; i++) {
		bool prev = i % 2;
		bool curr = !prev;
		for(int j = 1; j <= mx; j++) {
			dp[curr][j] = min(dp[curr][j], dp[prev][j]);
			if(j >= v[i]) dp[curr][j] = min(dp[curr][j], dp[prev][j-v[i]] + w[i]);
		}
	}
	for(int i = 0; i < 2; i++) {
		for(int j = 1; j <= mx; j++) if(dp[i][j] <= m) ans = max(ans, (LL)j);
	}
	cout<<ans<<endl;
	return 0;
}
/*
3 8
3 3
4 5
5 6
*/

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(){
  while(1){
    int e,a;cin>>e;if(e==0)break;a=e;
    for(int i=0,z=0;z<=e;i++,z=i*i*i)
      for(int j=0,y=0;y+z<=e;j++,y=j*j)
	if(i+j+e-y-z<a)a=i+j+e-y-z;
    cout<<a<<endl;
  }
  return 0;
}

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

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

    int n, k;
    cin >> n >> k;
	vector<int> v(n);
	for (int& x : v) {
		cin >> x;
	}
	int ans = 0;
	for (int i = 1; i <= min(n, k); i++) {
		for (int j = 1; j <= i; j++) {
			vector<int> t(i);
			auto p = [](int x) {return x < 0;};
			auto it = copy_if(begin(v), begin(v) + j, begin(t), p);
			it = copy_if(end(v) - i + j, end(v), it, p);
			sort(begin(t), it);
			int s = accumulate(begin(v), begin(v) + j, 0);
			s += accumulate(end(v) - i + j, end(v), 0);
			s -= accumulate(begin(t), begin(t) + min<int>(t.size(), k - i), 0);
			ans = max(ans, s);
		}
	}

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

//Vampirish Night
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			int k = sc.nextInt();
			if((n|k)==0)break;
			int[] s = new int[k];
			for(int i=0;i<k;i++)s[i]=sc.nextInt();
			boolean f = true;
			for(int i=0;i<n;i++){
				for(int j=0;j<k;j++){
					int x = sc.nextInt();
					if(s[j]<x)f = false;
					s[j]-=x;
				}
			}
			System.out.println(f?"Yes":"No");
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000