akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <numeric>
#include <cstdlib>
#include <random>
#include <bits/stdc++.h>


using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll mod=1000000007ll;
const ll inf=1000000000000000ll;

const ll MAX_N=2*100000+10;

ll dp[MAX_N];

ll N;
vector<ll> knum(21),a(MAX_N);

bool x(){
  for(ll i=0;i<21;i++){
    if(knum[i]>=2)return false;
  }
  return true;
}

void kplus(ll r){
  for(ll i=0;i<21;i++){
    if((1<<i)&a[r]){
      knum[i]++;
    }
  }
}

void kminus(ll l){
  for(ll i=0;i<21;i++){
    if((1<<i)&a[l]){
      knum[i]--;
    }
  }
}

int main(){
  cin>>N;
  for(ll i=0;i<N;i++){
    cin>>a[i];
  }
  ll l=0,r=0;
  ll ans=0;

  while(true){
    while(r<=N && x()){
      kplus(r);
      r++;
    }
    ans+=r-l-1;
    kminus(l);

    l++;
    if(l==N)break;
  }

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


Measured memory_bytes: 1792
n = int(input())
w = {}
for i in range(n):
  a, b = map(int,input().split())
  if b in w:
    w[b] += a
  else:
    w[b] = a
sum = 0
w = sorted(w.items(), key=lambda x:x[0])
#print(w)
for i in range(len(w)):
  k = w[i][0]
  v = w[i][1]
  sum += v
  if sum > k:
    print("No")
    break
else:
  print("Yes")

Measured memory_bytes: 87512
#include<stdio.h>
int main(){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(a+b==c||a+c==b||b+c==a){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}

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

int main() {
  ll n, k;
  cin >> n >> k;

  vector<ll> arr(n);
  ll x = 0, y = 0;
  bool iseven = k % 2 == 0 ? true : false;
  for (ll i = 1; i <= n; i++) {
    ll tmp = i % k;
    if (tmp == 0) x++;
    if (iseven) {
      if (tmp == k / 2) y++;
    }
  }
  ll sum = pow(x, 3);
  if (iseven) { sum += pow(y, 3); }
  cout << sum << endl;
}

Measured memory_bytes: 1792
#include<stdio.h>

int main(void){
  long long n,k,a[524288],p,c,i;
  long long f[524288];
  scanf("%lld%lld",&n,&k);
  for(i=1;i<=n;i++){
    f[i]=-1;
    scanf("%lld",&a[i]);
  }
  f[1]=0;p=a[1];c=1;k--;
  while(k>0){
    if(f[p]!=-1){k%=(c-f[p]);}
    if(k==0){break;}
    f[p]=c;
    p=a[p];
    c++;k--;
  }
  printf("%lld\n",p);
  return 0;
}


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

int main(){
  	int n;
  	std::cin >> n;
  	std::vector<int> a(n);
  	int count = 1;
  	int wreck = 0;
  	for(auto&e : a){
      	std::cin >> e;
      	if(e!=count){
          	wreck++;
        }else{
          	count++;
        }
    }
  	if(count==1){
      	std::cout << -1 << "\n";
    }else{
      	std::cout << wreck << "\n";
    }
  	return 0;
}

Measured memory_bytes: 3660
use std::i64;
use std::cmp;

// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}


fn main(){
    input! {
        n: usize, w_lim: usize,
        wv: [(usize, usize); n],
    }

    let (w, v): (Vec<_>, Vec<_>)= wv.into_iter().unzip();
    let v_lim = v.iter().sum::<usize>() + 1;
    let mut dp = vec![vec![std::usize::MAX/10; v_lim]; n];
    dp[0][0] = 0;
    dp[0][v[0]] = w[0];
    for i in 1 .. n {
        for j in 0 .. v_lim {
            if j >= v[i] {
                dp[i][j] = cmp::min(dp[i-1][j], dp[i-1][j-v[i]]+w[i]);
            } else {
                dp[i][j] = dp[i-1][j];
            }
        }
    }

    let mut ans = 0;
    for i in 0 .. v_lim {
        if dp[n-1][i] <= w_lim {
            ans = i;
        }
    }
    println!("{}", ans);
}




Measured memory_bytes: 106748
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int a_count = 0, b_count = 0, c_count = 0;
        String a = in.next();
        String b = in.next();
        String c = in.next();
        char next = a.charAt(a_count);
        a_count++;
        boolean notEmpty = true;
        while (notEmpty){
            if (next == 'a'){
                if (a_count == a.length()){
                    System.out.println('A');
                    return;
                }
                else{
                    next = a.charAt(a_count);
                    a_count++;
                }
            }
            else if (next == 'b'){
                if (b_count == b.length()){
                    System.out.println('B');
                    return;
                }
                else{
                    next = b.charAt(b_count);
                    b_count++;
                }
            }
            else {
                if (c_count == c.length()){
                    System.out.println('C');
                    return;
                }
                else{
                    next = c.charAt(c_count);
                    c_count++;
                }
            }
        }
    }
}

Measured memory_bytes: 21844
#pragma region Macros

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

using ll = long long;
#define int ll
using vi = vector<int>;
using vvi = vector<vi>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
ostream &operator<<(ostream &out, vector<T> const &v) {
    for (auto &&a : v) out << a << " ";
    out << endl;
    return out;
}

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

#pragma endregion

void Main() {
    int N, K;
    cin >> N >> K;

    vi a(N, 0);
    int k;
    int buff;
    REP(i, K) {
        cin >> k;
        REP(j, k) {
            cin >> buff;
            a[buff - 1]++;
        }
    }
    int count = 0;
    REP(i, N) {
        if (a[i] == 0) {
            count++;
        }
    }
    cout << count;
}

#pragma region main
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    Main();
    cout << flush;
}
#pragma endregion


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define data_type long long
#define endl "\n"
#define pi acos(-1.0)


int  main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    vector<data_type> store;
    data_type n,x=0,m,i=0;
    cin>>n;
    map<data_type,data_type> mm;
    while(i<n-1)
        cin>>x,mm[x]+=1,i++;

    for(int i=1; i<=n; i++)
        cout<<mm[i]<<endl;



    return 0;
}




Measured memory_bytes: 16164
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n, m = LI()

    B = [1] * n
    R = [0] * n
    R[0] = 1

    for _ in range(m):
        x, y = LI_()

        B[x] -= 1
        B[y] += 1

        # 赤いボールが移動したかも？
        if R[x]:
            R[y] = 1

        # 箱が空なので赤いボールは絶対入ってない！
        if not B[x]:
            R[x] = 0

    return sum(R)


print(main())


Measured memory_bytes: 4596
main = do
  [a,b] <- words <$> getLine 
  putStrLn $ solve (a,b)

solve :: (String,String) -> String
solve (a,b) =
  if ok(read (a++b)) then "Yes" else "No"

ok :: Int -> Bool
ok n = sq == fromIntegral (ceiling sq)
  where m = fromIntegral n
        sq = sqrt m

Measured memory_bytes: 508
n = int(input())
bis = input().split()
ais = 0
for i in range(n):
  if i == 0:
    ais += int(bis[0])
  elif i == n-1:
    ais += int(bis[i-1])
  else:
    ais += min(int(bis[i-1]),int(bis[i]))
print(ais)

Measured memory_bytes: 3060
n=int(input())
e=[0]*(n+1)
for i in range(2,n+1):
    cur=i
    for j in range(2,i+1):
        while cur%j==0:
            e[j]+=1
            cur//=j
def num(m):
    return len(list(filter(lambda  x: x>=m-1,e)))

print(num(75)+num(25)*(num(3)-1)+num(15)*(num(5)-1)+num(5)*(num(5)-1)*(num(3)-2)//2)


Measured memory_bytes: 3060
#include<iostream>

using namespace std;

void CheckEyeTest(const double, int&, int&, int&, int&);

int main(){
  int leftA=0, leftB=0, leftC=0, leftD=0, rightA=0, rightB=0, rightC=0, rightD=0;
  double left, right;

  while(cin >> left >> right){
    CheckEyeTest(left, leftA, leftB, leftC, leftD);
    CheckEyeTest(right, rightA, rightB, rightC, rightD);
  }

  cout << leftA << " " << rightA << endl;
  cout << leftB << " " << rightB << endl;
  cout << leftC << " " << rightC << endl;
  cout << leftD << " " << rightD << endl;

  return 0;
}

void CheckEyeTest(const double x, int& a, int& b, int& c, int& d){
  if(x >= 1.1)
    ++a;
  else if(x >= 0.6)
    ++b;
  else if(x >= 0.2)
    ++c;
  else
    ++d;
}

Measured memory_bytes: 0
import java.util.Scanner;
class Main {
	public void ab() {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		double f = 0;
		int d = a / b;
		int r = a % b;
		f = a * 1.0 / b;
		System.out.printf("%d %d %7f",d,r,f);
	}
	public static void main(String[] args) {
		new Main().ab();
	}
}

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

int main() {
   int n;
   cin >> n;
   vector<int> v(n);
   for (int &i : v) {
       cin >> i;
   }

   string text = "APPROVED";
   for (int i : v) {
       if (i % 2 == 0) {
           if (i % 3 != 0 && i % 5 != 0) {
               text = "DENIED";
           }
       }
   }

   cout << text << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include<algorithm> 
#include <iomanip>
#include <math.h>
#include <cctype>
//小文字を大文字 c-0x20;


#define db double
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define maxn 5005
#define mod 998244353
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define vv(z,a,b) vector<vector<int>>z(a,vector<int>(b))
#define vvll(z,a,b) vector<vector<ll>>z(a,vector<ll>(b))
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(c) begin(c),end(c)
#define fix(k) fixed<<setprecision(k)
#define PI 3.141592653589793
using namespace std;


int main(){
    int n;cin>>n;
  vi x(n);
  vi y(n);
  rep(i,n)cin>>x.at(i);
  rep(i,n)cin>>y.at(i);
  vi sum(n);
  db p1=0,p2=0,p3=0,p4=0;
  rep(i,n){
    int k=x.at(i)-y.at(i);
    p1+=abs(k);
  }
  rep(i,n){
    int k=x.at(i)-y.at(i);
    p2+=abs(k)*abs(k);
  }
  p2=sqrt(p2);


   rep(i,n){
    int k=x.at(i)-y.at(i);
    p3+=abs(k)*abs(k)*abs(k);
  }
  p3=cbrt(p3);


  rep(i,n){
    int k=x.at(i)-y.at(i);
    sum.at(i)=abs(k);
  }
  sort(sum.begin(),sum.end());
p4=sum.at(n-1);

  
  cout<<fix(8);
  cout<<p1<<endl;
  cout<<p2<<endl;
  cout<<p3<<endl;
  cout<<p4<<endl;

}


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

int main() {

    ll K, A, B;

    cin >> K >> A >> B;

    string ans = "NG";
    
    for (ll i = 0; i < 1000; i++) {
        if(i * K >= A && i*K <= B) ans = "OK";
    }

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

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int N;
vector<vector<pair<int,int>>> data;
bool judge(int bit){
  for(int i=0;i<N;i++){
    if(!(bit&(1<<i)))continue;
    for(auto v:data[i]){
      int x=v.first;
      int y=v.second;
      if(y==1&&!(bit&(1<<x)))return false;
      if(y==0&&(bit&(1<<x)))return false;
    }
  }
  return true;
}
int main(){
  cin>>N;
  data.resize(N);
  for(int i=0;i<N;i++){
    int num;
    cin>>num;
    for(int j=0;j<num;j++){
       int x,y;
       cin>>x>>y;
       x--;
       data[i].push_back(make_pair(x,y));
     // cin>>data[i][j].first>>data[i][j].second;
    }
  }
  int ans=0;
  for(int bit=0;bit<(1<<N);bit++){
    int cnt=0;
    if(judge(bit)){
      for(int i=0;i<N;i++){
        if(bit&(1<<i))cnt++;
      }
      ans=max(ans,cnt);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
/**
 * @Author:      G_BG
 * @DateTime:    2018-10-06 21:47:46
 * @Description: 
 */
#include<bits/stdc++.h>
using namespace std;
#define MST(a, b) memset(a, b, sizeof(a));
#define CLR(a) MST(a, 0);
#define pb push_back
#define rep(x, y, z) for (int x = y; x < z; ++x)
#define dwn(x, y, z) for (int x = y; x >= z;--x)
#define lowbit(x) (x & (-x))
typedef long long LL;
typedef unsigned long long ULL;
const double PI = 3.1415926535898;
const double E = 2.718281828459;
const int INF = 0x7fffffff;
const int mod = 1e9+7;
const int maxn=1e5+10;
int main(int argc, char const *argv[]) {
	ios::sync_with_stdio(0);cin.tie(0);
	int n ,t;cin >> n >> t;
	int ans = 2e5;
	for(int i = 0;i < n;i++){
		int ci,ti; cin >> ci >> ti;
		if(ti <= t) ans = min(ans,ci);
	}
	if(ans == 2e5) cout << "TLE" << endl;
	else cout << ans << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
var nodes = [];
var restrictions = [];
function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    var tmp = input[0].split(" ");
    var a = parseInt(tmp[0]);
    var b = parseInt(tmp[1]);
    var count = 0;
    while (true) {

        a -= b;
        count++;
        if (a <= 0) break;

    }
    console.log(count);

}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
int cnt[111111];

signed main(){
    cin>>N;
    rep(i,N){
        int a;cin>>a;cnt[a]++;
    }

    int ans=N;
    int latte=0;
    rep(i,111111){
        if(cnt[i]<=1)continue;
        int t=cnt[i]-1;
        ans-=t/2*2;
        latte+=t%2;
    }
    if(latte%2)latte++;
    ans-=latte;
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 1024
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def EulerTour(graph, root=1):
    N = len(graph) - 1
    parent = [0] * (N + 1)
    stack = [-root, root]
    tour = []
    ind_L = [0] * (N + 1)
    ind_R = [0] * (N + 1)
    i = -1
    while stack:
        v = stack.pop()
        tour.append(v)
        i += 1
        if v > 0:
            ind_L[v] = i
            p = parent[v]
            for w in graph[v]:
                if w == p:
                    continue
                parent[w] = v
                stack.append(-w)
                stack.append(w)
        else:
            ind_R[-v] = i
    return tour, ind_L, ind_R, parent


N = int(readline())
graph = [[] for _ in range(N + 1)]
C = (0,) + tuple(map(int, readline().split()))
m = map(int, read().split())
for a, b in zip(m, m):
    graph[a].append(b)
    graph[b].append(a)

tour, ind_L, ind_R, parent = EulerTour(graph)
removed = [0] * (N + 1)
answer = [N * (N + 1) // 2] * (N + 1)
memo = [0] * (N + 1)

for v in tour:
    if v > 0:
        memo[v] = removed[C[parent[v]]]
    else:
        v = -v
        removed[C[v]] += 1
        c = C[parent[v]]
        x = (ind_R[v] - ind_L[v]) // 2 + 1  # subtree size
        x -= removed[c] - memo[v]
        answer[c] -= x * (x + 1) // 2
        removed[c] += x

for i, x in enumerate(removed):
    x = N - x
    answer[i] -= x * (x + 1) // 2
print('\n'.join(map(str, answer[1:])))


Measured memory_bytes: 107844
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

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

func main() {
	sc.Split(bufio.ScanWords)

	N := getInt()
	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt()
	}
	sort.Ints(a)

	a = append(a, a[N-1]+1)

	cnt := 1
	x := 0
	x2 := 0
	for i := 1; i <= N; i++ {
		if a[i] == a[i-1] {
			cnt++
		} else {
			//			out(a[i-1], cnt)
			if cnt > 2 {
				if cnt%2 == 1 {
					x += cnt - 1
					cnt = 1
				} else {
					x += cnt - 2
					cnt = 2
				}
			}
			if cnt == 2 {
				x2++
			}
			cnt = 1
		}
	}

	//	out(a, "x", x, "x2", x2, N)
	if x2%2 == 1 {
		x2++
	}
	out(N - (x + x2))
}


Measured memory_bytes: 3072
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	double a,b;
	while(cin>>a>>b){
		if(a<35.5&&b<71)puts("AAA");
		else if(a<37.5&&b<77)puts("AA");
		else if(a<40&&b<83)puts("A");
		else if(a<43&&b<89)puts("B");
		else if(a<50&&b<105)puts("C");
		else if(a<55&&b<116)puts("D");
		else if(a<70&&b<148)puts("E");
		else puts("NA");
	}
	return 0;
}

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

template <typename T>
struct UnionFind{
    std::vector<T> par, rank, sz;
    UnionFind(T n) : par(n), rank(n, 0), sz(n, 1){
        for(T i=0; i<n; i++) par[i] = i;
    }
    void init(T n){
        par.resize(n);
        rank.resize(n);
        sz.resize(n);
        for(T i=0; i<n; i++){
            par[i] = i;
            rank[i] = 0;
            sz[i] = 1;
        }
    }
    
    int root(T x){
        if(par[x] == x) return x;
        else  return par[x] = root(par[x]);
    }
    
    bool is_same(T x, T y){
        return root(x)==root(y);
    }
    
    int size(T x) {
        return sz[root(x)];
    }
    
    bool unite(T x, T y){
        x = root(x);
        y = root(y);
        if(x==y) return false;
        
        if(rank[x] < rank[y]) std::swap(x, y);
        if(rank[x]==rank[y]) rank[x]++;
        par[y] = x;
        sz[x] += sz[y];
        return true;
    }
};

int main(){
    using namespace std;
    int N, K, L; cin >> N >> K >> L;
    UnionFind<int> load(N), train(N);
    for (int i = 0; i < K; i++)
    {
        int p, q; cin >> p >> q;
        p--; q--;
        load.unite(p, q);
    }
    for (int i = 0; i < L; i++)
    {
        int r, s; cin >> r >> s;
        r--; s--;
        train.unite(r, s);
    }

    map<pair<int, int>, int> mp;
    vector<pair<int, int>> p;
    for (int i = 0; i < N; i++)
    {
        p.push_back(make_pair(load.root(i), train.root(i)));
        mp[p[i]]++;
    }
    
    for (int i = 0; i < N; i++)
    {
        cout << mp[p[i]];
        if(i!=N-1) cout << " ";
        else cout << endl;
    }
}


Measured memory_bytes: 18160
module Main where
    import Data.List
    import Control.Monad
    
    main = do
        getLine
        inputs<-getInputs
        let needle =  reverse $ sort inputs
        print $ foldr (+) 0 (get2nds needle)

    get2nds::[a]->[a]
    get2nds [] =[]
    get2nds [x] =[x]
    get2nds (x:[y]) = [y]
    get2nds (x:y:xs)= y:(get2nds xs)
    
        
    read' s = read s ::Integer

    getInputs = do
        line <- getLine
        let inputs = map read' (words line)
        return inputs

    getLines n = do
        lines <- (replicateM n getLine)
        return lines

    getGCD::Integer->Integer->Integer
    getGCD m n 
        | m < n = (getGCD n m)
        | n == 0 = m
        | otherwise = getGCD (mod m n) n

    getLCM::Integer->Integer->Integer
    getLCM m n = div (m * n) (getGCD m n)
   

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

n, y = [int(x) for x in input().split()]
flag = 0
for i in range(2001):
    for j in range(2001):
        tmp = 10000*i + 5000*j + 1000*(n-i-j)
        if tmp == y:
            if n-i-j >= 0:
                print('{} {} {}'.format(i,j,n-i-j))
                flag = 1
                break
    if flag == 1:
        break
if flag == 0:
    print('{} {} {}'.format(-1,-1,-1))

Measured memory_bytes: 3064
import sys

sys.setrecursionlimit(500000)
def input():
    return sys.stdin.readline()[:-1]

def main():
    N,M,L = list(map(int,input().split()))
    e_list = [[] for i in range(N)]
    for i in range(M):
        A,B,C = list(map(int,input().split()))
        A,B = A-1,B-1
        e_list[A].append((B,C))
        e_list[B].append((A,C))

    INF = float('inf')
    D = [[INF]*N for i in range(N)]
    for i in range(N):
        for j,d in e_list[i]:
            D[i][j]=d

    for k in range(N):
        for i in range(N):
            for j in range(N):
                if D[i][j]>D[i][k]+D[k][j]:
                    D[i][j] = D[i][k]+D[k][j]

    E = [[INF]*N for i in range(N)]

    for i in range(N):
        for j in range(N):
            if D[i][j]<=L:
                E[i][j]=1

    for k in range(N):
        for i in range(N):
            for j in range(N):
                if E[i][j]>E[i][k]+E[k][j]:
                    E[i][j] = E[i][k]+E[k][j]

    Q = int(input())
    for i in range(Q):
        s,t = list(map(int,input().split()))
        s,t = s-1,t-1
        if E[s][t]>10**28:
            print(-1)
        else:
            print(E[s][t]-1)
            
if __name__ == '__main__':
    main()



Measured memory_bytes: 72284
#include <iostream>
#include <vector>
#include <map>
#include <utility>
using namespace std;

map<int, vector<pair<int, int>>> mp;
long mn[100010];
void se(int key){
    for(int i=0; i<mp[key].size(); ++i){
        if(mn[mp[key][i].first]<1){
            mn[mp[key][i].first]=mn[key]+mp[key][i].second;
            se(mp[key][i].first);
        }
    }
}
int main() {
	int N, a, b, c; cin >> N;
	for(int i=0; i<N-1; ++i){
	    cin >> a >> b >> c;
	    mp[a].push_back(make_pair(b, c));
	    mp[b].push_back(make_pair(a, c));
	}
	int Q, K, x, y; cin >> Q >> K;
	mn[K]=1;
	se(K);
	for(int i=0; i<Q; ++i){
	    cin >> x >> y;
	    cout << mn[x]+mn[y]-2 << endl;
	}
	return 0;
}


Measured memory_bytes: 22912
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; 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 VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n, x, y;
    cin >> n >> x >> y;
    x--, y--;
    vvll d(n, vll(n));
    REP(i, n) {
        REP(j, n) {
            if (j <= i) continue;
            d[i][j] = j - i;
            d[j][i] = j - i;
        }
    }
    REP(i, n) {
        REP(j, n) {
            d[i][j] = min(d[i][j], d[i][x] + 1 + d[y][j]);
        }
    }
    vll res(n);
    REP(i, n) {
        REP(j, n) {
            if (j <= i) continue;
            res[d[i][j] - 1]++;
        }
    }
    REP(i, n - 1) {
        cout << res[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 31616
r = [[(j - k) * 9 % 13 for j in range(10)] for k in range(13)]
d = [1] + [0] * 12
M = 10 ** 9 + 7
for c in input():
    if c == '?':
        d = [sum(d[j] for j in k) % M for k in r]
    else:
        d = [d[(int(c) - k) * 9 % 13] for k in range(13)]
    #print(d)
print(d[5])

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> va;
typedef vector<int> vb;
typedef vector<int> vc;

typedef int _loop_int;
#define REP(i, n) for (_loop_int i = 0; i < (_loop_int)(n); ++i)
#define FOR(i, a, b) for (_loop_int i = (_loop_int)(a); i < (_loop_int)(b); ++i)
#define FORR(i, a, b)                                                          \
  for (_loop_int i = (_loop_int)(b)-1; i >= (_loop_int)(a); --i)

#define DEBUG(x) cout << #x << ": " << x << endl
#define DEBUG_ARRY(v, n) REP(i, n) cout << " " << v[i]
#define DEBUG_VEC(v)                                                           \
  cout << #v << ":";                                                           \
  REP(i, v.size()) cout << " " << v[i];                                        \
  cout << endl
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a = min((a), (b))
#define CHMAX(a, b) a = max((a), (b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a) % MOD + MOD) % MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(a, b) (abs(a - b) < EPS)
typedef complex<Real> P;

int main() {
  int n;
  int vec[20];
  cin >> n;
  REP(i, n) cin >> vec[i];
  int max = vec[0], cnt = 0;
  FOR(i, 1, n) {
    if (vec[i] >= max) {
      cnt++;
      max = vec[i];
    }
  }
  cout << cnt + 1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const int mod=1000000 ;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
//17:00~
vector<vector<int>>ko;
llint ans=1;
static llint dp[1001][1001];
int solve(int ter){
	int w=0;
	for(auto it:ko[ter]){
		int x=solve(it);
		ans*=dp[w][x];
		ans%=mod;w+=x;
	}
	return w+1;
}
int main(void){
	cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);
	int n,i,j,win=0;cin>>n;
	for(i=0;i<=n;i++){dp[i][0]=1;dp[0][i]=1;}
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
		}
	}
	ko.res(n);
	for(i=1;i<n;i++){
		int a,b;cin>>a>>b;a--;b--;
		ko[a].pub(b);win^=b;win^=i;
	}
	solve(win);
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 11060
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String sn = sc.next();
    long n = Long.valueOf(sn);
    int l = sn.length();
    int fi = Integer.valueOf(sn.substring(l-1, l));
    long ans = 0;
    
    if(fi%2 != 0){
      System.out.println(0);
      return;
    }
    
    long nd = n; // - (long)fi;
    long div = 1;
    int c = 0;
    for(int i=1; i<30; i++){
      div *= 5;
      if(nd < div){
        c = i-1;
        break;
      }
    }
    
    div = 1;
    long cans = 1;
    for(int i=1; i<=c; i++){
      div *= 5;
      cans = nd / div / 2;
      ans += cans;
    }
    
    System.out.println(ans);
    
  }
}


Measured memory_bytes: 23508
import fractions

N = int(input())
A = [0] + list(map(int, input().split()))


l = [0, A[1]] + [0] * (N - 1)
r = [0] * N + [A[N]]

for i in range(2, N + 1):
	l[i] = fractions.gcd(l[i - 1], A[i])
for i in reversed(range(1, N)):
	r[i] = fractions.gcd(r[i + 1], A[i])

gcds = [r[2]]
for i in range(2, N):
	gcds.append(fractions.gcd(l[i - 1], r[i + 1]))
gcds.append(l[N - 1])

print(max(gcds))

Measured memory_bytes: 16124
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
int main(){
    int count = 0;
    string s;
    cin >> s;

    if(s.size() == 1){
        cout << 0 << endl;
        return 0;
    }

    for(int i=1; i<s.size(); i++){
        if(s[i] != s[i-1]) count++;
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
typedef long long lint;

#define MAXN 100010
//d,edge,g,P,q
lint d[MAXN];
struct edge{
        int to;
        lint cost;
};
vector<edge> g[MAXN];
typedef pair<lint,int> P;
priority_queue<P,vector<P>,greater<P> > q;

void pfs(int s){
        d[s]=0;q.push({0,s});
        lint cd,v;
        while(q.size()){
                cd=q.top().first;v=q.top().second;q.pop();
                if(cd>d[v])continue;
                for(edge &e:g[v])if(d[e.to]>cd+e.cost){
                        d[e.to]=cd+e.cost;
                        q.push({d[e.to],e.to});
                }
        }
}

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

int main(){
        lint v,e,r;cin>>v>>e>>r;
        rep(i,v)d[i]=INT_MAX;
        int a,b;lint c;
        rep(i,e){
                cin>>a>>b>>c;
                g[a].push_back({b,c});
        }pfs(r);
        rep(i,v){
                if(d[i]==INT_MAX)cout<<"INF"<<endl;
                else cout<<d[i]<<endl;
        }
}


Measured memory_bytes: 19484
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 2e5+5;
int a[maxn];
int main(){
	int N;
	scanf("%d",&N);
	for(int i = 1;i <= N;i++)
		scanf("%d",&a[i]);
	int ans = 0;
	for(int i = 1,j = 1;i <= N;i++){
		if(a[i] == j){
			ans++;
			j++;
		}
	}
	if(ans)
		printf("%d\n",N-ans);
	else
		printf("-1\n");
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(){
    int k,a,b,d,i=1,o=0;
    scanf("%d%d%d",&k,&a,&b);
    while(1){
        d=k*i;
        i++;
        if(a<=d&&d<=b){
            o=1;
            break;
            
        }
        else if(b<=d){
            o=2;
            break;
        }
    }
    if(o==1)printf("OK\n");
    else if(o==2)printf("NG\n");
    return 0;
}

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

using namespace std;

using ll = long long;

mt19937 mt(736);


int bubble(vector<int> &arr)
{
	int cnt = 0;

	for (int j = 0; j < arr.size(); j++)
		for (int i = 1; i < arr.size(); i++)
			if (arr[i - 1] > arr[i])
			{
				swap(arr[i - 1], arr[i]);
				cnt++;
			}

	return cnt;
}


void solve(istream &cin = std::cin, ostream &cout = std::cout)
{
	int n;

	cin >> n;

	vector<pair<int, int>> arr(n);

	for (auto &it : arr)
		cin >> it.first;
	for (auto &it : arr)
		cin >> it.second;

	for (int i = 1; i < arr.size(); i += 2)
		swap(arr[i].first, arr[i].second);

	const unsigned to = (1u << (unsigned) n);
	int ans = numeric_limits<int>::max();

	auto red = [&arr](int a, int b) {
		return tuple<int, int>{arr[a].first, a} < tuple<int, int>{arr[b].first, b};
	};
	auto blue = [&arr](int a, int b) {
		return tuple<int, int>{arr[a].second, a} < tuple<int, int>{arr[b].second, b};
	};

	for (unsigned mask = 0; mask < to; mask++)
		if (__builtin_popcount(mask) == arr.size() / 2)
		{
			vector<int> b, r;

			for (unsigned i = 0; i < n; i++)
				if (mask & (1u << i))
					b.push_back(i);
				else
					r.push_back(i);

			sort(b.begin(), b.end(), blue);
			sort(r.begin(), r.end(), red);

			bool good = true;

			for (int i = 0; good && i < b.size(); i++)
				good &= arr[r[i]].first <= arr[b[i]].second;
			for (int i = 1; good && i < r.size(); i++)
				good &= arr[b[i - 1]].second <= arr[r[i]].first;

			if (good)
			{
				vector<int> tmp;

				reverse(r.begin(), r.end());
				reverse(b.begin(), b.end());

				while (tmp.size() < arr.size())
				{
					tmp.push_back(r.back());
					r.pop_back();
					r.swap(b);
				}

				int cnt = bubble(tmp);

				ans = min(ans, cnt);
			}
		}

	if (ans == numeric_limits<int>::max())
		ans = -1;

	cout << ans << endl;
}


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

	cout << fixed;

#ifdef LOCAL
	auto st = clock();

	ifstream fin("../input.txt");

	solve(fin);

	cout << "clock: " << (clock() - st) / (double) CLOCKS_PER_SEC << endl;
#else
	solve();
#endif

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main(){
    char s[5];
    int yn=0;
    scanf("%s",s);
    if(s[0]==s[1]){
        if(s[2]==s[3]&&s[0]!=s[2])yn=1;
    }else if(s[0]==s[2]){
        if(s[1]==s[3]&&s[0]!=s[1])yn=1;
    }else if(s[0]==s[3]){
        if(s[2]==s[1]&&s[0]!=s[2])yn=1;
    }
    if(yn==1){
        printf("Yes");
    }else{
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void) {
  int i, n, k, ans, height;
  
  ans = 0;
  
  scanf("%d", &n);
  scanf("%d", &k);
  
  for(i=0;i<n;i++) {
    scanf("%d", &height);
    if(height >= k) ans++;
  }
  
  printf("%d", ans);

  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>

//#define int long long
#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second

using namespace std;
using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
template<class T>void print(T a){cout << a << endl;}
//lambda: [](int x, int y){return x<y;}

signed main(void) {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    if(abs(b - a) > 1e18) {
        print("Unfair");
    }
    if(k % 2) {
        print(b - a);
    } else {
        print(a - b);
    }

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define lli long long int
#define llu long long unsigned int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FOR(i,s,e) for(i=s; i<e; i++)
#define mod 1000000007
#define F first
#define S second
#define plli pair<lli,lli>
#define pqlli priority_queue<lli>
#define test(t) cin>>t; while(t--)
using namespace std;

lli power(lli a, lli b, lli M = mod)
{
	lli result = 1;
    for (;;)
    {
        if (b & 1)
            result = (result*a)%M;
        b >>= 1;
        if (!b)
            break;
        a = (a*a)%M;
    }
    return result;
}

#define RED 1LL
#define GREEN 2LL
#define WHITE 3LL
#define INV 4LL
#define WASRED 5LL;
#define WASWHI 6LL;

int main()
{
	IOS;
	lli x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	lli pa[a], pb[b], pc[c];
	
	for(lli i = 0; i<a; i++)
	cin>>pa[i];
	for(lli i = 0; i<b; i++)
	cin>>pb[i];
	for(lli i = 0; i<c; i++)
	cin>>pc[i];

	vector<plli> v;

	for(lli i = 0; i<a; i++)
	v.pb(mp(pa[i], RED));

	for(lli i = 0; i<b; i++)
	v.pb(mp(pb[i], GREEN));

	for(lli i = 0; i<c; i++)
	v.pb(mp(pc[i], WHITE));

	sort(v.begin(), v.end());
	lli cnt = 0, i = (lli)v.size()-1, ans = 0;
	
	while(x > 0)
	{
		if(v[i].second == RED)
		{v[i].second = WASRED; ans += v[i].first; x--;}
		else if(v[i].second == WHITE)
		{v[i].second = WASWHI; ans += v[i].first, x--; cnt++;}
		i--;
	}
	i = (lli)v.size()-1;
	while(y > 0)
	{
		if(v[i].second == GREEN)
		v[i].second = INV, ans += v[i].first, y--;
		else if(v[i].second == WHITE)
		v[i].second = INV, ans += v[i].first, y--;
		else if(v[i].second == RED and cnt > 0)
		ans += v[i].first, y--, cnt--;
		i--;
	}
	cout<<ans<<endl;
}


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

int main() {
  int A,B,K;
  cin >> A >> B >>K;

  for(int i = A;i<=B;i++){
    if(i<=A+K-1 || B-i<=K-1){
      cout << i << endl;;
    }
  }

}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

MOD = 10**9+7
cum = [0 for _ in range(n)]
cum[0] = a[0]
for i in range(1, n):
    cum[i] = cum[i-1]+a[i]

ans = 0
for i in range(n):
    ans += a[i]*(cum[n-1]-cum[i])
    ans %= MOD
print(ans)

Measured memory_bytes: 109888
#!/usr/bin/env python3

import itertools
import math

N = int(input())
towns = []
for i in range(N):
    l = list(map(int, input().split()))
    towns.append(l)
# print(N, towns)

paths = list(map(list, itertools.permutations(range(N), N)))
# print(paths)

dists = []
for path in paths:
    dist = 0
    for i, v in enumerate(path):
        town = towns[v]
        if i != N - 1:
            town_next = towns[path[i+1]]
            # print(i)
            # print(town)
            # print(town_next)
            x1, y1 = town[0], town[1]
            x2, y2 = town_next[0], town_next[1]
            dist += math.sqrt((x1 - x2)**2 + (y1 - y2)**2)
    dists.append(dist)

# print(dists)
print(sum(dists)/len(dists))


Measured memory_bytes: 49088
n = int(input())
p = list(map(int,input().split()))
p.sort()
min = -1
sum = -1

for i in range(p[0], p[-1] + 1):
    tmp_sum = 0
    for j in range(len(p)):
        tmp_sum += (p[j] - i)** 2
    if sum == -1 or sum > tmp_sum:
        sum = tmp_sum

print(sum)


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

int main(void) {
    double a, b, c, s, l, h;
    cin >> a >> b >> c;
    h = b * sin(c / 180.0 * M_PI);
    s = a * h / 2.0;
    l = sqrt(a * a + b * b - 2 * a * b * cos(c / 180.0 * M_PI));
    l += a + b;
    cout << fixed << s << endl << l << endl << h << endl;
    return 0;
}

Measured memory_bytes: 1288
from collections import deque
N = int(input())

Q = deque([1,2,3,4,5,6,7,8,9])
a = 0
for i in range(N):
  a = Q.popleft()
  if a%10 > 0:
    Q.append(a*10 + (a%10 -1))
  Q.append(a*10 + a%10)
  if a%10 < 9:
    Q.append(a*10 + (a%10 +1))

print(a)

Measured memory_bytes: 19556
#include <stdio.h>

int main(){

	int i,j,h, w;

	while(1){

	scanf("%d %d", &h, &w);

	if(w == 0 && h == 0)
		break;
	
	for(i = 0; i < h; i++){
		for(j = 0; j < w; j++){
			printf("#");
		}
    printf("\n");
	}
	printf("\n");
	}

	return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {

    ios::sync_with_stdio(0);
    cin.tie(0);

    string s;
    cin >> s;
    int num = 0;
    rep(i, 0, s.size()) {
        if (s[i] == '+')
            num++;
        else
            num--;
    }
    cout << num << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		int isu = in.nextInt();
      	int hito = in.nextInt();
        int w = in.nextInt();
      

      System.out.print((isu-w)/(hito+w));
	}
}

Measured memory_bytes: 23764
import java.util.Scanner;

public class Main {
	static int intN =0;
	static int sosuCnt =0;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//String n = sc.nextLine();
		String[] h1 = sc.nextLine().split(" ");

		int intK = Integer.parseInt(h1[1]);

		int intN = Integer.parseInt(h1[0]);

		String[] h = sc.nextLine().split(" ");

		int sum=0;

		for (int i = 0;i < intN;i++) {
			if (Integer.parseInt(h[i]) >= intK) {
                sum=sum+1;
			}

		}

		System.out.println(sum);


		//int a = Integer.parseInt("");
		//for (int i = 0;i < intN;i++) {
		//sum=sum+i;
	//}

	}
}


Measured memory_bytes: 38144
a,b=map(int,input().split())
positive=0
zero=int(a<=0<=b)
negative=0
if b<0:
    negative=b-a+1
elif 0<a:
    positive=b-a+1
print('Zero' if zero==1 else 'Negative' if negative%2!=0 else 'Positive')

Measured memory_bytes: 3060
import java.util.Arrays;
import java.util.Scanner;

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

        Arrays.sort(ab, (l, r) -> Integer.compare(l[1], r[1]));

        int count = 0;
        int tmpR = ab[0][1];
        for(int i = 1;i < m;i++) {
            int tmpL = ab[i][0];
            if(tmpR > tmpL) count++;
            else tmpR = ab[i][1];
        }

        int ans = m - count;
        System.out.println(ans);
    }
}


Measured memory_bytes: 90956
n, k = map(int, input().split())

m = 10**9+7

def f(n, k):
  res = 0
  lst = [0]*(k+1)
  for i in range(k, 0, -1):
    lst[i] = pow((k//i), n, m) - sum(lst[i*j] for j in range(2, k//i+1))%m
    res += i*lst[i]
    res %= m
  return res

print(f(n, k))

Measured memory_bytes: 11288
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

#define UP 'U'
#define DOWN 'D'
#define LEFT 'L'
#define RIGHT 'R'

int main(int argc, char **argv) {
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	tx -= sx; ty -= sy;
	REP(i, ty) cout << UP;
	REP(i, tx) cout << RIGHT;
	REP(i, ty) cout << DOWN;
	REP(i, tx) cout << LEFT;
	cout << LEFT;
	REP(i, ty + 1) cout << UP;
	REP(i, tx + 1) cout << RIGHT;
	cout << DOWN << RIGHT;
	REP(i, ty + 1) cout << DOWN;
	REP(i, tx + 1) cout << LEFT;
	cout << UP << endl;
	return 0;
}


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



int main()
{	
	int n,sum=0;
	string s;
	vector<string>v;
	cin>>n>>s;
	for(int i=0;i<=9;i++)
	{
		for(int j=0;j<=9;j++)
		{
			for(int k=0;k<=9;k++)
			{
				string t="";
				t+=('0'+i);
				t+=('0'+j);
				t+=('0'+k);
				v.push_back(t);
			}
		}
	}
	for(int i=0;i<v.size();i++)
	{
		int cnt=0;
		for(int j=0;j<n;j++)
		{
			if(cnt==0&&v[i][0]==s[j])cnt++;
			else if(cnt==1&&v[i][1]==s[j])cnt++;
			else if(cnt==2&&v[i][2]==s[j])cnt++;
		}
		if(cnt==3)sum++;
	}
	cout<<sum<<endl;
	return 0;	
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef vector<int> vi;
typedef pair<int, int> pi;
#define SQ(a) (a) * (a)
#define deb(x) cout << #x << " = " << x << '\n'
#define deb2(x, y) cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"
 
 
int main(int argc, char const *argv[])
{
 
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    double a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    double dp[n+1][n+1];
    memset(dp,0,sizeof dp);
    dp[0][0]=1;
    for(int i=1;i<=n;i++){
        dp[i][0]=dp[i-1][0]*(1-a[i-1]);
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            dp[i][j] = dp[i-1][j]*(1-a[i-1]) + dp[i-1][j-1]*a[i-1];
        }
    }
    // for(int i=0;i<=n;i++){
    //     for(int j=0;j<=n;j++){
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<"\n";
    // }
    double ans=0;
    int st= n/2 +1;
    for(int i=st;i<=n;i++){
        ans+= dp[n][i];
    }
    cout<<setprecision(10)<<ans;

    return 0;
}

Measured memory_bytes: 74144