akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define M (int)1e9
#define pi 3.1415926536
 
vector <int> SieveOfEratosthenes(int n) 
{ 
    vector<int> ans;
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    if (prime[p] == true) 
    for (int i=p*p; i<=n; i += p) 
    prime[i] = false; 
        
  	for (int p=2; p<=n; p++) 
    if (prime[p]) 
    ans.push_back(p);
	return ans;
}
 
vector <int> fib(int n)
{
	vector<int> ans;
	int x=0,y=1,l=1;
	ans.push_back(x);
	ans.push_back(y);
	while(l<n)
	{
		l=x+y;
		x=y;y=l;
		ans.push_back(l);
	}
	return ans;
}
 
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; 
} 
 
 
long long power(int n,int k)
{
	if(k==0)	return 1;
	else return n*power(n,k-1);
}
 
int sdigit(int x)
{
	int ans=0;
	while(x)
	{
		ans+=x%10;
		x/=10;
	}
	return ans;
}
 
long long lcm(int a,int b)
{
	return ((long long)a*(long long)b)/__gcd(a,b);
}
 
 bool aisekaro(string a,string b)
 {
    //cout<<a<<endl<<b<<endl;
 	int i=0;
 	char x=a[0];
	for(i;i<max(a.size(),b.size());i++)
	{
	    //cout<<a[i]<<" "<<b[i]<<endl;
		if(i<min(a.size(),b.size())){	
			if(a[i]>b[i])	return true;
			if(a[i]<b[i])	return false;
			if(a[i]==b[i])  continue;
			
			//x=a[i];
		}
		if(i>=a.size()){
			if(b[i]==x)	continue;
			else return b[i]<x;
		}
		if(i>=b.size()){
			if(a[i]==x)	continue;
			else  return a[i]>x;
		}

	}
	return true;
 }
 long long subArraySum(int arr[], int n, int sum) 
{ 
    int curr_sum = arr[0], start = 0, i; 
  
    for (i = 1; i <= n; i++) 
    { 
        while (curr_sum > sum && start < i - 1) 
        { 
            curr_sum = curr_sum - arr[start]; 
            start++; 
        } 
  
        
        if (curr_sum == sum) 
        {  
            cout << "Sum found between indexes " 
                 << start << " and " << i - 1; 
            return 1; 
        } 
  
        if (i < n) 
        curr_sum = curr_sum + arr[i]; 
    } 
  
    return -1; 
} 
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	int k;
	string s;
	cin>>k>>s;
	if(s.size()<=k)	cout<<s;
	else cout<<s.substr(0,k)+"...";


	return 0;
			
}

Measured memory_bytes: 3632
package main

import "fmt"

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

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

	x := make([]int, n)
	for i := range x {
		fmt.Scan(&x[i])
	}

	k--
	ans := 1000000000
	for i := 0; i+k < n; i++ {
		d := x[i+k] - x[i]
		if v := abs(x[i]) + d; v < ans {
			ans = v
		}
		if v := abs(x[i+k]) + d; v < ans {
			ans = v
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 5504
#include <iostream>
#include <limits>
#include <vector>

using namespace std;

int main() {
    size_t n;
    cin >> n;
    vector<int> x(n);
    for (size_t i = 0; i < n; ++i) cin >> x[i];
    size_t min_num = numeric_limits<size_t>::max();
    for (int p = 1; p <= 100; ++p) {
        size_t sum = 0;
        for (const auto& v : x) sum += (v - p) * (v - p);
        if (sum < min_num) min_num = sum;
    }
    cout << min_num << endl;
    return EXIT_SUCCESS;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ll long long
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using P = pair<int, int>;

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)]; }
};

int deg[100005];
vector<int> to[100005];

int main(){
    int n,m,k;
    cin >> n >> m >> k;
    UnionFind uf(n);
    rep(i,m){
      int a,b;
      cin >> a >> b;
      --a; --b;
      deg[a]++;
      deg[b]++;
      uf.unite(a,b);
    }
    rep(i,k){
      int a,b;
      cin >> a >> b;
      --a; --b;
      to[a].push_back(b);
      to[b].push_back(a);
    }
    rep(i,n){
      int ans = uf.size(i)-1-deg[i];
      for (int u : to[i]){
        if (uf.same(i,u)) --ans;
      }
      printf("%d%c",ans,i==n-1?'\n':' ');
    }
} 

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

int main()
{
  string a,b;
  bool flag=false;
  cin >> a >> b;

  deque<char> v1,v2;

  for(auto z:a)
    v1.push_back(z);
  for(auto z:b)
    v2.push_back(z);

  for(int i=0;i<v1.size();i++){
    if(v1==v2){
      flag=true;
      break;
    }
    v1.push_back(v1.front());
    v1.pop_front();
  }

  if(flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define nl ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define pi acos(-1)

using namespace std;

int main() {
    nl // Bazzi - Paradise

    int k, x;
    cin >> k >> x;
    
    int yen = 500*k;
    cout << (yen>=x ? "Yes" : "No");

    return 0;
}

Measured memory_bytes: 3620
/* kadai3_4
   nabe9393 */

#include<stdio.h>

int main(void){
  int number, i, answer=0;
  scanf("%d", &number );
  for(i=1; i < 10; i++){
    if(number % i == 0 && number / i < 10){
      answer++;
    }
  }
  if(answer != 0){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }
return 0;
} 

Measured memory_bytes: 128
#include <iostream>    // cin, cout
#include <string>    // string, stoi, to_string
#include <algorithm>    // sort, lower_bound, heap, min, next_permutation 
#include <functional>    // greater, less
#include <vector>    // vector
#include <stack>    // stack
#include <queue>    // queue
#include <list>    // list
#include <map>    // map
#include <set>    // set
#include <tuple>    // tuple
#include <bitset>    // bitset
#include <cstdio>  // fopen, printf, scanf, puts
#include <cmath>    // sin, exp, log, pow, sqrt
#include <iomanip>    // setfill, setbase
#include <ctime>    // clock

using namespace std;
using pii = pair<int, int>;
using ti = tuple<int, int, int>;

const double eps=1e-14;
const int mod = 1e9 + 7;
const int inf = ((1<<30));
const long long linf = (1LL<<60);

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    cout << h2*60 + m2 - h1*60 - m1 - k << endl;
    return 0;
}


Measured memory_bytes: 3652
#include<stdio.h>
int main()
{
    int n[4];
    int i;
    for (i = 0; i < 4; i++)
        scanf("%d", &n[i]);
    int a, b, c, d;
    a = b = c = d = 0;
    for (i = 0; i < 4; i++)
    {
        if (n[i] == 1)a++;
        if (n[i] == 9)b++;
        if (n[i] == 7)c++;
        if (n[i] == 4)d++;
    }
    if (a*b*c*d == 0)
        printf("NO\n");
    else
        printf("YES\n");
    return 0;
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    vector<vector<T>>(h,vector<T>(w))
#define VVI(T,h,w,i) vector<vector<T>>(h,vector<T>(w,i))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
    ll n = in();
    vector<array<array<ll, 2>, 5>>f(n);
    REP(i, n)REP(j, 5)REP(k, 2)f[i][j][k] = in();
    vector<array<ll, 11>>p(n);
    REP(i, n)REP(j, 11)p[i][j] = in();

    ll ans = -INFLL;
    REP1(i, 1023) {
        ll rieki = 0;
        REP(j, n) {
            ll c = 0;
            REP(k, 10) {
                c +=
                    (i >> k) % 2 == 1 &&
                    f[j][k / 2][k % 2] == 1;
            }
            rieki += p[j][c];
        }
        ans = max(ans, rieki);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
#import sympy as syp(素因数分解とか)
Mod = 1000000007
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main(): #startline-------------------------------------------
    print("Yes" if "7" in input() else "No")
if __name__ == "__main__":
    main() #endline===============================================

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

int main() {
  int N,M;
  cin>>N>>M;
  vector<int>s(M);
  vector<int>c(M);
  vector<int>A(N);
  int C=0;
  int ans=0;
  int CC=0;
  for(int i=0;i<M;i++){
    cin>>s[i]>>c[i];
    if(i>0){
      if(s[i]==s[i-1]){
        if(c[i]!=c[i-1]){
         C++; 
        }
      }
    }
    if(s[i]==1&&c[i]==0){
      CC++;
    }
  }
  for(int i=0;i<M;i++){
    A[s[i]-1]=c[i];
  }
  if(N>1){
    if(A[0]==0&&CC==0){
      A[0]=1;
    }
  }
  if(C>0){
    cout<<-1;
  }
  else if(A[0]==0){
    for(int i=0;i<N;i++){
      ans+=A[i];
    }
    if(N==1){
      cout<<0;
    }
    else if(ans==0){
      cout<<-1;
    }
    else{
    for(int i=1;i<N;i++){
      if(A[i]!=0){
        cout<<A[i];
      }
      else{
        cout<<A[i+1];
        break;
      }
    }
    }
  }
  else{
    for(int i=0;i<N;i++){
      cout<<A[i];
    }
  }
  cout<<endl;
}

Measured memory_bytes: 256
const main = (input: string) => {
  let [r, D, x] = input.trim().split(" ").map(str => parseInt(str))
  const OUTPUT_LINE = 10;
  let answer: string = "";
  let answer2: string = "";

  for (let i = 0; i < OUTPUT_LINE; i++) {
    answer = `${answer}${r * x - D}\n`;
    x = r * x - D
  }

  console.log(answer.trim());
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7628
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    int n,t;cin>>n>>t;
    vector<pair<ll,ll>> p(n);
    rep(i,n){
        cin>>p[i].first>>p[i].second;
    }
    sort(p.begin(),p.end());
    vector<ll> dp(4000,-1);
    dp[0]=0;
    ll res=0;
    
    rep(i,n){
        int a=p[i].first,b=p[i].second;
        ll buf=0;
        rep(j,t)if(dp[j]!=-1)chmax(buf,dp[j]);
        chmax(res,buf+b);
        for(int j=3999;j>=0;j--){
            if(dp[j]!=-1&&j+a<4000){
                chmax(dp[j+a],dp[j]+b);
            }
        }
    }
    rep(i,t+1){
        chmax(res,dp[i]);
    }
    cout<<res<<endl;
}


Measured memory_bytes: 3696
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <tuple>
#include <random>
#include <unordered_map>
#include <unordered_set>
using namespace std ;

int main() {
    int s, w ;
    cin >> s >> w ;
    if  (w>=s) {
        cout << "unsafe" ;
    } else {
        cout << "safe" ;
    }
}


Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
#include<vector>

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

    std::vector<int> h(n);
    for (int i = 0; i < n; i++) {
        std::cin >> h[i];
    }

    int ans = 1;

    for (int i = 1; i < n; i++) {
        bool flag = true;
        for (int j = 0; j < i; j++)
        {
            if(h[j] > h[i]) {
                flag = false;
            }
        }

        if(flag) {
            ans++;
        }

    }

    std::cout << ans << std::endl;
}

Measured memory_bytes: 256
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n) 
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

lint gcd(lint a, lint b) {
    lint r;
    while (b != 0) {
        r = a % b;
        a = b; 
        b = r;
    }
    return a;
}

lint lcm(lint a, lint b) {
    return (a / gcd(a, b)) * b;
}

lint power(lint x, lint n, lint mod = MOD) {
    lint ret = 1;
    while(n > 0) {
        if(n & 1){
            (ret *= x) %= mod;
        }
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}

vector<lint> make_power(int n, lint base){
    lint num = 1;
    vector<lint> ret;
    for (int i=0; i<=n; ++i){
        ret.push_back(num);
        num *= base;
    }
    return ret;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    lint n;
    cin >> n;
    lint a[n];
    vector<lint> b(n);
    REP(i, n){
        cin >> a[i];
        b[i] = LINF / 2;
    }
    REP(i, n){
        auto itr = lower_bound(ALL(b), a[i]) - b.begin();
        b[itr] = a[i];
        // cout << itr << endl;
    }
    lint ans = 0;
    REP(i, n){
        if(b[i] != LINF / 2){
            ans = i+1;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    int ct=0,ch=0;
    string t,h;
    for(int i=0;i<n;i++){
        cin >> t >> h;
        if(t>h) ct+=3;
        else if(t==h){
            ct++;
            ch++;
        }
        else ch+=3;
    }
    cout<< ct << " " << ch <<endl;
    return 0;
}


Measured memory_bytes: 3112
import java.util.Scanner;

class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int A;
        int B;
        int C;
        int min;

        A = sc.nextInt();
        B = sc.nextInt();

        if (A > B) {
            C = A - B;
            min = B;
        } else {
            C = B - A;
            min = A;
        }

        if (C % 2 == 0) {
            System.out.println(C/2+min);
        } else {
            System.out.println("IMPOSSIBLE");
        }
    }
}


Measured memory_bytes: 24020
#include<bits/stdc++.h>
using namespace std;
struct a
{
    char s[11];
    int p,id;
} r[105];
int ans[105];
int main()
{
    int n;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>r[i].s>>r[i].p;
        r[i].id=i;
    }
    for(int i=1; i<n; i++)
    {
        for(int j=1; j<=n-i; j++)
            if(!strcmp(r[j].s,r[j+1].s))
            {
                if(r[j].p<r[j+1].p)
                {
                    a tmp=r[j];
                    r[j]=r[j+1];
                    r[j+1]=tmp;
                }
            }
            else if(strcmp(r[j].s,r[j+1].s)>0)
            {
                a tmp=r[j];
                r[j]=r[j+1];
                r[j+1]=tmp;
            }
    }
    for(int i=1; i<=n; i++)
    {
        cout<<r[i].id<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n;
  cin>>n;
  vector<char> moji={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
  string s;
  while(n){
    n--;
    s+=moji[n%26];
    n/=26;
  }
  reverse(s.begin(),s.end());
  cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 3636
n,k = map(int,input().split())
ans = 0
mod = 10**9+7
for i in range(k,n+2):
    M = n*(n+1)//2-(n-i)*(n-i+1)//2
    m = (i-1)*(i)//2
    ans += M-m+1
    ans %= mod
print(ans)

Measured memory_bytes: 9056
import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
    auto n = lread();
    auto a = aryread();
    long sum_a = a.sum();
    // writeln(sum_a);
    auto s = new long[](n + 1);
    foreach (i; 0 .. n)
    {
        s[i + 1] = s[i] + a[i];
    }
    // writeln(s);
    long ans = long.max;
    long tmp;
    foreach (i; 1 .. (s.length) - 1)
    {
        // writeln(s[i], ":", sum_a - s[i]);
        tmp = abs(s[i] - (sum_a - s[i]));
        ans = min(ans, tmp);
    }
    writeln(ans);
}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}

void arywrite(T)(T a)
{
    a.map!text.join(' ').writeln;
}


Measured memory_bytes: 12608
#include <iostream>
#include <vector>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

ll dp[1000010];
ll dp2[1000010];
int main(void){
    ll n,i,j,k,h;
    std::vector<ll> v(200),v2(200);
    h=0;k=0;
    for(i=1;(i*(i+1)*(i+2)/6)<=1000000;i++){
        v[k++]=(i*(i+1)*(i+2)/6);
        if((i*(i+1)*(i+2)/6)%2)v2[h++]=(i*(i+1)*(i+2)/6);
    }
    ll vs = k;

    fill(dp,dp+(1000000+1),1000000);
        //cout << dp[0][0] << endl;
    dp[0]=0;

    for(i=1;i<=vs;i++){
        for(j=v[i-1];j<=1000000;j++){
            dp[j]=min(dp[j-v[i-1]]+1,dp[j]);
        }
    }

    vs = h;
    fill(dp2,dp2+(1000000+1),1000000);
    dp2[0]=0;
    for(i=1;i<=vs;i++){
        for(j=v2[i-1];j<=1000000;j++){
            dp2[j]=min(dp2[j-v2[i-1]]+1,dp2[j]);
        }
    }
    while(cin >> n && n){
        cout << dp[n] << " " << dp2[n] << endl;
    }
    return 0;
}



Measured memory_bytes: 18704
# python3
# -*- coding: utf-8 -*-
import sys
import math
#from math import gcd
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint

INF = float('inf')

ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
sys.setrecursionlimit(1000000000)


def lcm(a, b):
    return (a * b) // gcd(a, b)


# main
S = input()
print('x' * len(S))


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

typedef long long int ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
const ll mod = 1000000007;
const ll INF = 10010010010010010;

int main() {
    int n; cin >> n;
    int b[n-1]; rep(i,n-1) cin >> b[i];
    int s = b[0];
    rep(i,n-2) {
        s += min(b[i],b[i+1]);
    }
    cout << s+b[n-2] << endl;
    return 0;
}


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

int main(){
	int arr[100001] = {};
	int n; cin >> n;
	for (int i = 0; i < n; i++){
		int sayi; cin >> sayi;
		arr[sayi-1] = i+1;
	}
	forloop{
		cout << arr[i] << " ";
	}
	getchar(); getchar();
	return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int len ;
char s[100005] ;

int main(){
	scanf("%s",s+1) ;
	len=strlen(s+1) ;
	int last=s[1] , ans=0 ;
	for(int i=2;i<=len;++i){
		if(last!=s[i]) last=s[i] , ans++ ;
	}
	cout << ans << '\n' ;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;
const ll mod = 1e9 + 7;


int main() {
  string s, t, u;
  int a, b;
  cin >> s >> t >> a >> b >> u;
  if (s == u) {
	  a--;
	} else {
	  b--;
	}
  cout << a << " " << b << endl;
  return 0;
}


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

#define fastIO ios::sync_with_stdio(false);cout.tie(0);cin.tie(0);
#define endl '\n'
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define inf INT_MAX
#define minf INT_MIN

typedef long long int lli;

using namespace std;

ofstream outfile;
ifstream infile;

int countt[27];
void checker(int fours, int twos, int ones){
	int i;
	while(fours){
		bool flag = true;
		for(i = 0; i < 26 && flag; ++i){
			if(countt[i] > 3){
				countt[i]-=4;
				fours--;
				flag = false;
			}
		}
		if(flag){
			cout << "No\n";
			return;
		}
	}

	while(twos){
		bool flag = true;
		for(i = 0; i < 26 && flag; ++i){
			if(countt[i] > 1){
				countt[i]-=2;
				twos--;
				flag = false;
			}
		}
		if(flag){
			cout << "No\n";
			return;
		}
	}
	cout << "Yes\n";
}
int main()
{
	infile.open("input.txt");
	outfile.open("output.txt");

	int h, w, f = 0, t = 0, o = 0;
	string s;

	int i, j;
	for(i = 0; i < 26; ++i)
		countt[i] = 0;

	cin >> h >> w;
	
	for(i = 1; i <= h; ++i){
		cin >> s;
		for(j = 1; j <= w; ++j){
			countt[s[j-1]-'a']++;
		}
	}
	if(h == 1 && w == 1){
		cout << "Yes\n";
		return 0;
	}
	if(h%2){
		if(w%2){
			f = ((h-1)*(w-1))/4;
			t = ((h-1)+(w-1))/2;
			o = 1;
		}else{
			f = ((h-1)*w)/4;
			t = w/2;
		}
	}
	else{
		if(w%2){
			f = (h*(w-1))/4;
			t = h/2;
		}else{
			f = (h*w)/4;
		}
	}
	//cout << f << " "<< t << " "<< o << "\n";
	checker(f, t, o);
}

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

void solve(){
	
	string s ;
	string t ; 

	cin>>s>>t ;

	int m=s.length() ;
	int n=t.length() ;

	int max_same=0 ;

	for(int i=0;i+n-1<m;i++){

		string temp=s.substr(i,n) ;

		int same=0 ;

		for(int j=0;j<n;j++){
			

			if(temp[j]==t[j])
			{
				same++ ;
				max_same=max(same,max_same) ;
			
			}

		}	

		//cout<<temp<<"\n" ;

	}

	cout<<n-max_same ;

}	

int main(){
	
	int y ;

	y=1 ;
	//cin>>y ;

	while(y--)
	{	
		solve() ;
	}

}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
using namespace std;

bool isVisited[100001];
vector<int> edges[100001];

void bfs(int node)
{
	queue<int> que;

	que.push(node);
	isVisited[node] = true;

	while (!que.empty())
	{
		node = que.front();
		que.pop();

		for (int i = 0; i < edges[node].size(); i++)
		{
			int next = edges[node][i];
			if (isVisited[next])
			{
				continue;
			}

			isVisited[next] = true;
			que.push(next);
		}
	}
}

int main()
{
	int n, m;
	int chunks = 0;
	cin >> n >> m;

	while (m--)
	{
		int a, b;
		cin >> a >> b;

		edges[a].push_back(b);
		edges[b].push_back(a);
	}

	for (int i = 1; i <= n; i++)
	{
		if (isVisited[i] == false)
		{
			++chunks;

			bfs(i);
		}
	}

	cout << chunks - 1 << endl;
}

Measured memory_bytes: 8920
import java.io.IOException;
import java.math.BigInteger;
import java.util.Scanner;

/**
 */
class Main {
	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);

		while(in.hasNext()) {
			String s = in.nextLine();
			solve(s);
		}
	}

	public static void solve(String s) {
		int n = 'Z' - 'A' + 1;
		boolean solved = false;
		for(int i=0;i<=n;i++) {
			String ans = "";
			for(int j=0;j<s.length();j++) {
				int offset = i;
				int ch = s.charAt(j);
				if((int)'a' <= (int)s.charAt(j) && (int)s.charAt(j) <= (int)'z') {
					ans += (Character.toString((char) ((int)'a' + (ch -(int)'a' + offset) % n)));
				} else {
					ans += Character.toString((char)ch);
				}
			}
			if(isEnd(ans)) {
				System.out.println(ans);
				solved = true;
				break;
			}
		}

		if (!solved) throw new AssertionError();
	}

	public static boolean isEnd(String ans) {
		return ans.contains("the") ||
				ans.contains("this") ||
				ans.contains("that")
//		return ans.contains("the ") ||
//					ans.contains("this ") ||
//					ans.contains("that ") ||
//					ans.contains("the.") ||
//					ans.contains("this") ||
//					ans.contains("that.")||
//				(ans.contains("the") && ans.length() == 3) ||
//				(ans.contains("this") && ans.length() == 4) ||
//				(ans.contains("that") && ans.length() == 4)
				;
	}
}

Measured memory_bytes: 26352
n = int(input())
lst = [int(x) for x in input().split()]

total = [0, 0]
ret = [0, 0]
for i in range(2):
    for j in range(n):
        total[i] += lst[j]
        if (i + j) % 2 == 0:
            if total[i] >= 0:
                ret[i] += total[i] + 1
                total[i] = -1
        else:
            if total[i] <= 0:
                ret[i] += abs(total[i] - 1)
                total[i] = 1

print(min(ret))

Measured memory_bytes: 14336
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "vector"
#include "string"
#include "map"
#include "algorithm"
#include "functional"
#include "set"

using namespace std;

const long long int MOD = 1000000007;

int N, M, K, H, W, L, R;

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

	cin >> N;
	cout << 1110 - N << endl;
	return 0;
}


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

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

    int H, W;

    cin >> H >> W;

    vector<string> S(H);

    vector<vector<pair<int, int>>> W_light(H); // 横方向に伸びる光の束
    vector<vector<pair<int, int>>> H_light(W); // 縦方向に伸びる光の束

    int Ans[H][W];

    for (int h = 0; h < H; h++) {
        for (int w = 0; w < W; w++) {
            Ans[h][w] = 0;
        }
    }

    for (int h = 0; h < H; h++) {
        cin >> S[h];
        string str = S[h] + '#';
        int start = 0;
        for (int w = 1; w < W + 1; w++) {
            if (str[w] != str[w - 1]) {
                if (str[w] == '#') {
                    W_light[h].emplace_back(make_pair(start, w - 1));
                    for (int i = 0; i < w - start; i++) {
                        Ans[h][w - 1 - i] += w - start;
                        //cout << h << w - 1 - i << ":" << w - start << '\n';
                    }
                } else {
                    start = w;
                }
            }
        }
    }

    string S_Hplus1 = "";
    S.emplace_back(S_Hplus1.assign(W, '#'));

    for (int w = 0; w < W; w++) {
        int start = 0;
        for (int h = 1; h < H + 1; h++) {
            if (S[h][w] != S[h - 1][w]) {
                if (S[h][w] == '#') {
                    H_light[w].emplace_back(make_pair(start, h - 1));
                    for (int i = 0; i < h - start; i++) {
                        Ans[h - 1 - i][w] += h - start;
                        //cout << h - 1 - i << w << ":" << h - start << '\n';
                    }
                    //cout << start << h - 1 << '\n';
                } else {
                    start = h;
                }
            }
        }
    }

    int max_ans = 0;
    for (int h = 0; h < H; h++) {
        for (int w = 0; w < W; w++) {
            //cout << h << w << ":" << Ans[h][w] << '\n';
            if (max_ans < Ans[h][w]) {
                max_ans = Ans[h][w];
            }
        }
    }

    cout << max_ans - 1 << '\n';

    return 0;
}


Measured memory_bytes: 36608
#include <iostream>
#include <vector>

using namespace std;

int main() {
	long long int n;
	vector<long long int> furui(300010, 0);
	furui[0] = furui[1] = 1;
	for (long long int i = 2; i < 300010; i++) {
		if (furui[i] == 0) {
			if (i % 7 == 1 || i % 7 == 6) {
				for (int j = 8; i*j <= 300010; j+=7) {
					furui[i*j] = 1;
				}
				for (int j = 6; i*j <= 300010; j += 7) {
					furui[i*j] = 1;
				}
			}
			else {
				furui[i] = 1;
			}
		}
	}
	//cout << 'a' << endl;
	while (cin >> n) {
		if (n == 1) {
			break;
		}
		cout << n << ':';
		for (int i = 2; i <= n; i++) {
			if (furui[i] == 0 && n%i == 0 && ((n / i) % 7 == 1 || (n / i) % 7 == 6)) {
				cout << ' ' << i;
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 5008
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int block_num = 1;
    rep(i, n-1) {
        if (s[i] != s[i+1]) {
            ++block_num;
        }
    }
    cout << block_num - 1 << endl;
    return 0;
}

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

#define YES		0
#define NO		1

class circle {
	int W, H, x, y, r;
public:
	void input();
	int judge();
	void output(int i);

};

void circle::input()
{
	cin >> W >> H >> x >> y >> r;
}

int circle::judge()
{
	if((x < r) || (y < r)){
		return NO;
	}else if(((W-x) < r) || ((H - y) < r)){
		return NO;
	}else{
		return YES;
	}
}

void circle::output(int i)
{
	if(YES == i){
		cout << "Yes" << endl;
	}else if(NO == i){
		cout << "No" << endl;
	}
}

int main()
{
	circle ob1;

	ob1.input();
	ob1.output(ob1.judge());

	return 0;

}



Measured memory_bytes: 3116
N = int(input())
S = input()

white = len([char for char in S if char == '.'])

result = 0
if white == 0:
    result = 0
else:
    result = white
    left_black = 0
    right_white = white
    for char in S:
        if char == '.':
            right_white -= 1
        else:
            left_black += 1
        result = min(result, right_white + left_black)
print(result)


Measured memory_bytes: 5096
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll w[105],v[105],dp[105][100005];

int main()
{
    ll W,n,i,j;
    cin>>n>>W;
    for(i=0;i<=n;i++)
    {
        for(j=0;j<100005;j++)
        {
            dp[i][j]=1e18;
        }
    }
    dp[0][0]=0;
//    memset(dp,-1,sizeof(dp));
    for(i=0;i<n;i++)
    {
        cin>>w[i]>>v[i];
    }
    for(i=1;i<=n;i++)
    {
        for(j=0;j<100005;j++)
        {
            if((j-v[i-1])>=0)
            {
                dp[i][j]=min(dp[i-1][j],w[i-1]+dp[i-1][j-v[i-1]]);
            }
            else
                dp[i][j]=dp[i-1][j];
        }
    }
    ll c=100004;
    while(dp[n][c]>W && c>=0)
        c--;
    cout<<c<<endl;
}

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

const int MAX_V=100;
const int INF=100100100;
struct edge {int to, cap, rev; };

vector<edge> G[MAX_V];
bool used[MAX_V];

void add_edge(int from, int to, int cap){
    edge e; e.to=to; e.cap=cap; e.rev=G[to].size();
    G[from].push_back(e);
    e.to=from; e.cap=0; e.rev=G[from].size()-1;
    G[to].push_back(e);

}

//増加パスの長さを返す
int dfs(int v, int t, int f){
    if(v==t) return f;
    used[v]=true;
    for(int i=0; i<G[v].size(); i++){
        edge &e = G[v][i];
        if(!used[e.to] && e.cap>0){
            int d= dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap -=d;
                G[e.to][e.rev].cap +=d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int s, int t){
    int flow=0;
    while(1){
        memset(used,0,sizeof(used));
        int f =dfs(s,t,INF);
        if(f==0) return flow;
        flow +=f;
    }
}

int main(){
    int V, E; cin >> V >>E;
    for(int i=0; i<E; i++){
        int u, v, c; cin >> u >> v >> c;
        add_edge(u,v,c);
    }
    cout << max_flow(0,V-1) << endl;
}


Measured memory_bytes: 3168
#include <stdio.h>
#define N 45

int fibonacci(int);

int main(){
  int n;
  scanf("%d", &n);
  printf("%d\n", fibonacci(n));
  return 0;
}

int fibonacci(int n){
  int i, F[N];
  for(i=0; i<=n; i++)F[i]=-1;
  for(i=0; i<=n; i++){
    if(i==0 || i==1)F[i]=1;
    else F[i]=F[i-1]+F[i-2];
  }
  return F[n];
}



Measured memory_bytes: 2112
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

typedef long long llt;

const int MaxN = 1000 + 5, MaxM = 1000 + 5;
const llt Mod = 1e9 + 7;

int N, M;
char Mp[MaxN][MaxM];
llt dp[MaxN][MaxM];

void init() {
  scanf("%d %d", &N, &M);
  for (int i = 1; i <= N; ++i) for (int j = 1; j <= M; ++j) {
    do Mp[i][j] = getchar(); while (Mp[i][j] != '#' && Mp[i][j] != '.');
  }
}

void solve() {
  dp[0][1] = 1;
  for (int i = 1; i <= N; ++i) for (int j = 1; j <= M; ++j)
    if (Mp[i][j] == '.') dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % Mod;
  cout << dp[N][M] << endl;
}

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

Measured memory_bytes: 9088
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<numeric>
using namespace std;
int main() {

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

	sort(a, a + 3);

	if (a[0] + a[1] == a[2])
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    int x[N];
    for(int i = 0; i < N; i++) cin >> x[i];
    sort(x, x + N);

    int cnt[M]; //x mod M がiのカードの数
    int p[M]; //x mod M がiのカードでできるペアの数
    fill(cnt, cnt + M, 0);
    fill(p, p + M, 0);

    int tmp = 1;
    for(int i = 0; i < N; i++){
        if(i == N - 1){
            cnt[x[i] % M] += tmp;
            p[x[i] % M] += tmp / 2;
        }

        else {
            if(x[i] == x[i + 1]) tmp++;
            else {
                cnt[x[i] % M] += tmp;
                p[x[i] % M] += tmp / 2;
                tmp = 1;
            }
        }
    }

    // debug
    /*
    for(int i = 0; i < M; i++){
        cout << setw(2) << i;
    }
    cout << endl;
    for(int i = 0; i < M; i++){
        cout << setw(2) << cnt[i];
    }
    cout << endl;
    for(int i = 0; i < M; i++){
        cout << setw(2) << p[i];
    }
    cout << endl;
    */

    ll ans = 0;
    ans += cnt[0] / 2;
    for(int i = 1; i < (M + 1) / 2; i++){
        int j = M - i;

        while(cnt[i] > 0 && cnt[j] > 0){
            //cout << i << " " << j << endl;
            //cout << ans << endl;
            ans++;
            if(cnt[i] == p[i] * 2){
                cnt[i]--;
                p[i]--;
            } else {
                cnt[i]--;
            }

            if(cnt[j] == p[j] * 2){
                cnt[j]--;
                p[j]--;
            } else {
                cnt[j]--;
            }
        }

        //cout << i << endl;
        //cout << ans << endl;
        if(p[i] > 0 || p[j] > 0){
            //cout << "hoge" << endl;
            //cout << i << " " << j << endl;
            ans += p[i] + p[j];
        }
        //cout << ans << endl;
    }

    if(M % 2 == 0){
        ans += cnt[M / 2] / 2;
    }

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

Measured memory_bytes: 1408
/** 
 * THIS IS MOOONI'S CODE !
 * HACK IT IF YOU CAN !
**/
#include <bits/stdc++.h>
 
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, k;
  cin >> n >> k;
  if (n > k) {
    n %= k;
  }
  cout << min(n, k - n) << '\n';
  return 0;
}

Measured memory_bytes: 256
<?php
//error_reporting(0);
//list($N,$Q) =  explode(" ",trim(fgets(STDIN)));
$N = trim(fgets(STDIN));
$x[] = trim(fgets(STDIN));
$x[] = trim(fgets(STDIN));
$x[] = trim(fgets(STDIN));
$x[] = trim(fgets(STDIN));
$x[] = trim(fgets(STDIN));

$mm = min($x);
$r = ceil($N / $mm);
//一番輸送量が少ないところで何回とまるか？
printf("%d\n",5+$r-1);


Measured memory_bytes: 4604
A=int(input())
three=int(A/3)
five=int(A/5)
fif=int(A/15)
count=0
for i in range(A+1):
    count+=i

if A>=15:
    final=int(count-(1/2*three*(3+three*3))-(1/2*five*(5+five*5))+(1/2*fif*(15+fif*15)))
    print(final)

elif 5<=A<15:
    final=int(count-(1/2*three*(3+three*3))-(1/2*five*(5+five*5)))
    print(final)

elif 3<=A<5:
    final=int(count-(1/2*three*(3+three*3)))
    print(final)

else:
    print(count)

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

int main(void){

    char a[20] = "AKIHABARA";
    char b[60];
    cin >> b;
    int j = 0;
    int flag = 1;
    for(int i = 0; b[i] != '\0' || a[j] != '\0'; i++){
        if(a[j] == b[i]){
            j++;
            continue;
        }else if(a[j] == 'A'){
            j++;
            i--;
            continue;
        }else{
            flag = 0;
            break;
        }
    }

    if(flag) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

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

	if (a < b && b < c && a!=b && b!=c && c!=a) {
		std::cout << "Yes" << std::endl;
	}
	else {
		std::cout << "No" << std::endl;
	}
}


Measured memory_bytes: 3100
#include<stdio.h>
#include<string.h>
#include<math.h>

int main(){
    int H1,M1,H2,M2,K,time=0;;
    scanf("%d %d %d %d %d",&H1,&M1,&H2,&M2,&K);
    time = (H2-H1)*60 + M2- M1 - K;
    printf("%d\n",time); 


    return 0;
}

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

#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main()
{
	IOS;
        int a,b,c;
        cin >> a >> b >>c;
        if((a < c && c < b) || (a > c && c > b))
        {
                cout <<"Yes";
                return 0;
        }
        cout <<"No";
	return 0;
}


Measured memory_bytes: 256
/* 
 * Project: AtCoder Beginners Contest 145 C - Average Length
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/08/11
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

int n;
vector<pair<int,int>> p;
vector<int> x;
vector<int> y;

double get_distance(pair<int,int> p1, pair<int,int> p2) {
    int dx = p1.first - p2.first;
    int dy = p1.second - p2.second;
    return sqrt(dx*dx + dy*dy);
}

void solve() {

    vector<int> idx(n);
    for (int i=0;i<n;i++) {
        idx[i] = i;
    }

    vector<double> sums(n);
    int cnt = 0;
    do {
        double sum = 0;
        for (int i=0;i<n-1;i++) {
            sum += get_distance(p[idx[i]],p[idx[i+1]]);
        }
        sums.push_back(sum);
        cnt++;
    } while (next_permutation(idx.begin(), idx.end()));
    double average = accumulate(sums.begin(), sums.end(), 0.0) / cnt;
    printf("%lf\n", average);
}

int main() {

    scanf("%d", &n);
    for (int i=0;i<n;i++) {
        int tmp_x;
        int tmp_y;
        scanf("%d", &tmp_x);
        scanf("%d", &tmp_y);
        pair<int,int> tmp_p;
        tmp_p.first = tmp_x;
        tmp_p.second = tmp_y;
        p.push_back(tmp_p);
    }

    solve();
}

Measured memory_bytes: 3512
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <functional>
#include <algorithm>

int main() {
  int A, B, C, D, E, F;
  std::cin >> A >> B >> C >> D >> E >> F;
  std::vector<bool> water(F / 100 + 1, false);
  std::vector<bool> salt(F + 1, false);
  water[0] = true;
  salt[0] = true;
  for (int i = 1; i <= F / 100; ++i) {
    water[i] = (i >= A && water[i - A]) || (i >= B && water[i - B]);
  }
  for (int i = 1; i <= F; ++i) {
    salt[i] = (i >= C && salt[i - C]) || (i >= D && salt[i - D]);
  }
  double max = 0.0;
  int ansA = 0, ansB = 0;
  for (int i = 0; i <= F / 100; ++i) {
    for (int j = 0; j <= F; ++j) {
      if (water[i] && salt[j]) {
        if (i * 100 + j <= F && j <= i * E) {
          double rate = (100.0 * j) / (100.0 * i + j);
          if (max <= rate) {
            max = rate;
            ansA = i * 100 + j;
            ansB = j;
          }
        }
      }
    }
  }
  std::cout << ansA << " " << ansB << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
using namespace std;
 
int main() {
    int n;
    while(cin >> n, n) {
        vector<int> S(n+1);
        string str;
        cin >> str;
        S[0] = 0;
        S[1] = str.size();
        for(int i=2; i<=n; ++i) {
            cin >> str;
            S[i] = S[i-1] + str.size();
        }
        int tmp[5] = {5, 7, 5, 7, 7};
        int ret = 0;
        bool finished = false;
        for(int i=0; i<=n; ++i) {
            if(finished) break;
            int current=i;
            int current_haiku = 0;
            int offset=1;
            ret = i;
            while(current+offset <= S.size()) {
                if(S[current+offset] - S[current] == tmp[current_haiku]) {
                    current += offset;
                    offset = 1;
                    current_haiku++;
                    if(current_haiku == 5) {
                        finished = true;
                        break;
                    }
                } else if(S[current+offset] - S[current] > tmp[current_haiku]) {
                    break;
                } else {
                    offset++;
                }
            }
        }
        cout << ret+1 << endl;
    }
}

Measured memory_bytes: 3184
def main():
    n=int(input())
    Num=[0]*(n**2+1)
    Exited=[0]*(n**2+1)
    X=tuple(map(int,input().split()))
    for i in range(n**2):
        q,r=divmod(i,n)
        Num[i+1]=min(q,n-q-1,r,n-r-1)
    ans=0
    for x in X:
        ans+=Num[x]
        Exited[x]=1
        Stack=[x]
        while Stack:
            v=Stack.pop()
            if v>n and (Num[v]<Num[v-n] and (Exited[v] or Num[v-n]-Num[v]>1)):
                Num[v-n]-=1
                Stack.append(v-n)
            if v<=n**2-n and (Num[v]<Num[v+n] and (Exited[v] or Num[v+n]-Num[v]>1)):
                Num[v+n]-=1
                Stack.append(v+n)
            if v%n!=0 and (Num[v]<Num[v+1] and (Exited[v] or Num[v+1]-Num[v]>1)):
                Num[v+1]-=1
                Stack.append(v+1)
            if v%n!=1 and (Num[v]<Num[v-1] and (Exited[v] or Num[v-1]-Num[v]>1)):
                Num[v-1]-=1
                Stack.append(v-1)
    print(ans)

if __name__=='__main__':
    main()

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

int N,K,x[100];

int main()
{
    cin>> N>> K;
    for (int i=0; i<N; i++){
        cin>>x[i];
    }
    int ans=0;
    for (int i=0; i<N; i++){
        if (K-x[i]<=x[i]-0) ans+=K-x[i];
        else ans+=x[i];
    }
    cout<<2*ans;
    return 0;
}


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

int64_t MOD = 1000000007;
double PI = 3.141592653589793;

int main()
{
    int N, M, ans = 0;
    cin >> N >> M;
    vector<vector<int>> list(N);
    for (int i = 0; i < M; i++)
    {
        int p, q;
        cin >> p >> q;
        p--, q--;
        list[p].push_back(q), list[q].push_back(p);
    }

    unordered_map<int, int> nkr;
    for (int i = 0; i < N; i++)
        nkr[i] = 0;

    vector<bool> arrived(N, false); //訪問済みかどうか
    queue<int> que;                 //訪問予定
    int search, now;

    que.push(0);
    arrived[0] = true;
    nkr.erase(0);
    while (!nkr.empty())
    {
        int tmp = 1;
        while (!que.empty())
        {
            int now = que.front();
            que.pop();
            nkr.erase(now);

            for (int i = 0; i < list[now].size(); i++)
            {
                int search = list[now][i];
                if (!arrived[search]) //未訪問
                {
                    arrived[search] = true;
                    que.push(search);
                    tmp++;
                    nkr.erase(search);
                }
            }
        }
        ans = max(ans, tmp);
        if (!nkr.empty())
        {
            auto tmp = nkr.begin();
            int tmp2 = tmp->first;
            que.push(tmp2);
            arrived[tmp2] = true;
            nkr.erase(tmp2);
        }
    }
    cout << ans;
}

Measured memory_bytes: 22852
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;


int main() {
	int N;
	vector<LL>A, B;
	LL total = 0;
	cin >> N;
	for (int i = 0; i <= N; ++i) {
		int tmp; cin >> tmp;
		A.push_back(tmp);
	}
	for (int i = 0; i < N; ++i) {
		int tmp; cin >> tmp;
		B.push_back(tmp);
		total += tmp;
	}
	for (int i = 0; i < N; ++i) {
		if (B[i]) {
			int x = min(A[i], B[i]);
			A[i] -= x;
			B[i] -= x;
		}
		if (B[i] && A[i + 1]) {
			int x = min(A[i + 1], B[i]);
			A[i + 1] -= x;
			B[i] -= x;
		}
	}
	for (int i = 0; i < N; ++i) {
		total -= B[i];
	}
	cout << total << endl;
	return 0;
}

Measured memory_bytes: 2676
import java.lang.ArithmeticException

fun str() = readLine()!!
fun int() = str().toInt()
fun long() = str().toLong()

fun read(d:String = " ") = str().split(d)
fun <T> list(d:String = " ",f:String.()->T) = read(d).map {f(it)}
fun list() = list {toInt()}.toIntArray()

fun <T> T.print() = this.also(::println)

fun main() {
	abc000X()
}

fun abc000X() {
	val n = int()
	val a = LongArray(n) {0}
	val b = LongArray(n) {0}
	for(i in a.indices) {
		val (t,u) = list {toLong()}
		a[i] = t
		b[i] = u
	}
	a.sort()
	b.sort()
//	System.err.println(a.joinToString())
//	System.err.println(b.joinToString())

	if(n%2==1) {
		println(b[n/2]-a[n/2]+1)
	} else {
		val l = a[n/2-1]+a[n/2]
		val h = b[n/2-1]+b[n/2]
		println(h-l+1)
	}
}


Measured memory_bytes: 71068