akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)

void imp(){
    cout<<"No"<<endl;
}

int main(){
    int n,a,b,c,d;
    string s;
    cin>>n>>a>>b>>c>>d>>s;
    a--,b--,c--,d--;
    if(c<d){
        REP(i,a,d-1){
            if(s[i]=='#'&&s[i+1]=='#'){
                cout<<"No"<<endl;
                return 0;
            }
        }
        cout<<"Yes"<<endl;
    }else{
        rep(i,n-1){
            if(s[i]=='#'&&s[i+1]=='#'){
                cout<<"No"<<endl;
                return 0;
            }
        }
        REP(i,b,d+1){
            if(s[i-1]=='.'&&s[i]=='.'&&s[i+1]=='.'){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
        cout<<"No"<<endl;
    }
    return 0;
}

//a=97,z=122

Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    vector<int> a(n);
    rep(i,n){
      cin >> s[i] >> a[i];
    }
    string x;
    cin >> x;
    bool t=false;
    int ans=0;
    rep(i,n){
      if (t) ans+=a[i];
      if (s[i]==x) t=true;
    }
    cout << ans << endl;
}


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

void constructXOR(int A[], int n) { 
	int XOR = 0; 
	for (int i = 0; i < n; i++) 
		XOR ^= A[i]; 
	for (int i = 0; i < n; i++) 
		A[i] = XOR ^ A[i]; 
} 

int main() 
{ 
	int n;
	cin >> n;
	int A[n + 10];
	for(int i = 0; i < n; i++){
		cin >> A[i];
	}
	constructXOR(A, n); 

	for (int i = 0; i < n; i++) 
		cout << A[i] << " "; 
	return 0; 
} 


Measured memory_bytes: 4300
#include<stdio.h>
int main()
{
	int n=0,x=0,y,m,l,t;
	scanf("%d%d%d",&m,&l,&t);
	while(l)
	{
		
		n++;
		x+=l+(n+1)*t;
		if(x>=m)
		break;
		x=x-(n+1)*t;
	}
	if(x>m)
	n--;
		printf("%d",n);
}

Measured memory_bytes: 128
// g++ -std=gnu++1y -O2 xxx.cpp

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

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

    bool isHtcStr=true;
    if (s.length()%2==0) {
        for (int i=0;i<s.length();i++) {
            if (i%2==0) {
                if (s[i]!='h') isHtcStr=false;
            } else {
                if (s[i]!='i') isHtcStr=false;
            }
        }
    } else {
        isHtcStr=false;
    }

    cout << (isHtcStr?"Yes":"No") << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main {
	
	static List<binarySet> ls=new ArrayList<>();
	static char[] U;
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		
		int n=in.nextInt(),k=in.nextInt();
		
		U=new char[n];
		Arrays.fill(U, '0');
		
		
		solveSet(new ArrayList<Integer>(),n,k);
		ls.sort(Comparator.comparingInt(binarySet::getDecimal));
		
		PrintWriter out=new PrintWriter(System.out);
		for(int i=0;i<ls.size();i++) {
			List<Integer> A=ls.get(i).ls;
			out.print(ls.get(i).dec+":");
			
			for(int j=0;j<A.size();j++)out.print(" "+A.get(j));
			out.println();
			out.flush();
		}
		
		out.flush();
	}
	
	static void solveSet(List<Integer> A,int n,int k) {
		if(A.size()==k) {
			ls.add(new binarySet(A,U));
			return;
		}
		
		for(int i=0;i<n;i++) {
			if(A.isEmpty() || i>A.get(A.size()-1)) {
				List<Integer> t=new ArrayList<>(A);
				t.add(i);
				solveSet(t,n,k);
			}
		}
	}

}
class binarySet{
	List<Integer> ls;
	int dec;
	binarySet(List<Integer> A,char[] c){
		ls=A;
		char[] t=c.clone();
		for(int i=0;i<ls.size();i++) {
			t[c.length-1-A.get(i)]='1';
		}
		dec=Integer.parseInt(String.valueOf(t),2);
	}
	
	int getDecimal() {
		return dec;
	}
}



Measured memory_bytes: 88176
using System;

class Program{
    class Node{
        public int parent;
        public int left;
        public int right;
    }

    static void WalkPreorder(Node[] nodes, int root){
        Console.Write(" "+root);
        if(nodes[root].left!=-1){
            WalkPreorder(nodes, nodes[root].left);
        }
        if(nodes[root].right!=-1){
            WalkPreorder(nodes, nodes[root].right);
        }
    }

    static void WalkInorder(Node[] nodes, int root){
        if(nodes[root].left!=-1){
            WalkInorder(nodes, nodes[root].left);
        }
        Console.Write(" "+root);
        if(nodes[root].right!=-1){
            WalkInorder(nodes, nodes[root].right);
        }
    }

    static void WalkPostorder(Node[] nodes, int root){
        if(nodes[root].left!=-1){
            WalkPostorder(nodes, nodes[root].left);
        }
        if(nodes[root].right!=-1){
            WalkPostorder(nodes, nodes[root].right);
        }
        Console.Write(" "+root);
    }

    public static void Main(){
        var n=int.Parse(Console.ReadLine());
        var nodes=new Node[n];
        for(var i=0; i<n; i++){
            nodes[i]=new Node();
            nodes[i].parent=-1;
        }
        for(var i=0; i<n; i++){
            var s=Console.ReadLine().Split(' ');
            var id=int.Parse(s[0]);
            var left=int.Parse(s[1]);
            var right=int.Parse(s[2]);
            nodes[id].left=left;
            nodes[id].right=right;
            if(left!=-1){
                nodes[nodes[id].left].parent=id;
            }
            if(right!=-1){
                nodes[nodes[id].right].parent=id;
            }
        }

        for(var i=0; i<n; i++){
            if(nodes[i].parent==-1){
                Console.WriteLine("Preorder");
                WalkPreorder(nodes, i);
                Console.WriteLine();
                Console.WriteLine("Inorder");
                WalkInorder(nodes, i);
                Console.WriteLine();
                Console.WriteLine("Postorder");
                WalkPostorder(nodes, i);
                Console.WriteLine();
            }
        }
    }
}

Measured memory_bytes: 9100
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
int main() {
	int n,m,x,y;
	int t[4][4] = {};
	t[0][1] = t[1][2] = t[2][3] = t[3][0] = 1;
	t[1][0] = t[2][1] = t[3][2] = t[0][3] = -1;
	while (cin >> n, n) {
		vector<int> v[51]; vector<int>u;
		rep(i, n+1) {
			vector<P> p;
			cin >> m;
			int memo;
			rep(j, m) {
				cin >> x >> y;
				p.push_back({ x,y });
			}
			rep(j, m - 1) {
				int dir;
				if (p[j + 1].first > p[j].first) {
					dir = 1;
				}
				else if (p[j + 1].first < p[j].first) {
					dir = 3;
				}
				else if (p[j + 1].second > p[j].second) {
					dir = 0;
				}
				else dir = 2;
				if (j) {
					v[i].push_back(t[memo][dir]);
				}
				v[i].push_back(abs(p[j + 1].first - p[j].first + p[j + 1].second - p[j].second));
				memo = dir;
			}
			if (i == 0) {
				for(int j=m-1;j>0;j--) {
					int dir;
					if (p[j - 1].first > p[j].first) {
						dir = 1;
					}
					else if (p[j - 1].first < p[j].first) {
						dir = 3;
					}
					else if (p[j - 1].second > p[j].second) {
						dir = 0;
					}
					else dir = 2;
					if (j<m-1) {
						u.push_back(t[memo][dir]);
					}
					u.push_back(abs(p[j - 1].first - p[j].first + p[j - 1].second - p[j].second));
					memo = dir;
				}
			}
		}
		rep1(i, n) {
			if (v[0] == v[i]) {
				cout << i << endl; continue;
			}
			if (u == v[i]) {
				cout << i << endl;
			}
		}
		cout << "+++++" << endl;
	}
	return 0;
}


Measured memory_bytes: 2988
#include<stdio.h>
#include<limits.h>

int main() {
	int n, min = INT_MAX;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		int x, cnt = 0;
		scanf("%d", &x);
		while (x % 2 == 0 && x>0) {
			x = x / 2;
			++cnt;
		}
		min = cnt < min ? cnt : min;
	}
	printf("%d", min);
}

Measured memory_bytes: 128
import Control.Monad
import Data.Functor
import Data.List

main :: IO ()
main = do
  n <- readLn
  am <- replicateM n $ map read . words <$> getLine :: IO([[Int]])
  let filled = map (map (\w -> if w == -1 then maxBound else w)) am
  print . solve $ filled

solve :: [[Int]] -> Int
solve am = sum . map snd $ mst am [(0, 0)]

type Node = Int
type Weight = Int
type AdjMatrix = [[Weight]]
type SpanningTree = [(Node, Weight)]

mst :: AdjMatrix -> SpanningTree -> SpanningTree
mst am st
  | length am <= length st = st
  | otherwise = mst am (nearest:st)
  where
    spanned = map fst st
    neighbors = [(i, (am !! j) !! i)
      | i <- [0..(length am - 1)], j <- spanned, i `notElem` spanned]
    nearest = minimumBy (\x y -> compare (snd x) (snd y)) neighbors



Measured memory_bytes: 7616
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
const LL MOD = 1e9 + 7;
const int LIMIT = 2020202;
LL INV[LIMIT];

// Fermat's little theorem から, 大きな冪乗の計算を行う.
// @param a: べき乗したい正整数.
// @param b: 指数.
// @return:  べき乗した計算結果(mod版).
LL mPow(LL a, LL b){
    LL t = 1;
    while(b){
        if(b & 1) t = (t * a) % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return t % MOD;
}

int main(){
    
    // 1. 入力情報.
    LL n, a, b;
    scanf("%lld %lld %lld", &n, &a, &b);
    rep(i, LIMIT) INV[i] = mPow(i, MOD - 2) % MOD;
    
    // 2. 花束の種類数(全パターン, 2 の n乗通り) を 計算.
    LL ans = mPow(2, n);
    
    // 3. n種類の花から, x本選ぶ選び方(nCx通り) を 計算.
    // ex.
    // 11C5 は, (11 * 10 * 9 * 8 * 7) / (5 * 4 * 3 * 2 * 1) 
    // = (7 / 1) * (8 / 2) * (9 / 3) * (10 / 4) * (11 / 5)
    // のように計算したい.
    
    // 3-1. 0本選ぶとき.
    LL c0 = 1;
    
    // 3-2. a本選ぶとき.
    LL ca = 1;
    rep(i, a){
        ca *= (MOD + n - i);
        ca %= MOD;
        ca *= INV[i + 1];
        ca %= MOD;
    }
    
    // 3-3. b本選ぶとき.
    LL cb = 1;
    rep(i, b){
        cb *= (MOD + n - i);
        cb %= MOD;
        cb *= INV[i + 1];
        cb %= MOD;
    }
    
    // 4. 0 または a または b に 一致しない花束の種類数を計算.
    ans = (ans + MOD - c0) % MOD;
    ans = (ans + MOD - ca) % MOD;
    ans = (ans + MOD - cb) % MOD;
    
    // 5. 出力.
    printf("%lld\n", ans);
    return 0;
    
}

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

int main() {
  int N,K;
  cin >> N>>K;
  int sum = 1;
  
  for (int i = 0; i < N;i++){
    if (sum*2 >= (sum + K)){
      sum += K;
    }
    else {
      sum *= 2;
    }
  }
  
  cout << sum << endl;

}



Measured memory_bytes: 3544
import Text.Printf
main :: IO()
main = do
  inputs <- getLine
  let [a,b] = map (\x -> read x :: Int) $ words inputs
  printf "%d %d %.6f\n"
             (a`div`b)
             (a`mod`b)
             ((fromRational (fromIntegral a)/(fromIntegral b))::Double)

Measured memory_bytes: 3964
a = list(map(int, input().split()))
n = int(input())
if n >= 2:
    if n % 2 == 0:
        print(int((n//2)*min(a[0]*8, a[1]*4, a[2]*2, a[3])))
    else:
        print(int((n//2)*min(a[0]*8, a[1]*4, a[2]*2, a[3])+min(a[0]*4, a[1]*2, a[2])))
else:
    print(min(a[0]*4, a[1]*2, a[2]))


Measured memory_bytes: 9116
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using E = System.Linq.Enumerable;

class Program
{
    static void Main(string[] args)
    {
        //入力を受け取る
        var Q = long.Parse(Console.ReadLine());
        var koho = SieveOfEratosthenes(100000);
          
     
        var B = new int[100001];
        foreach(int item in koho){
          if(koho.Contains((item+1)/2)){
            B[item] = 1;
          }
        }
      
        for(int i = 1; i < B.Length ;i++){
          B[i] += B[i-1];
        }
      
        //各クエリの答えを出力する
        for(int i = 0; i < Q ;i++){
          var LR = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
          var L = LR[0];
          var R = LR[1];
          Console.WriteLine(B[R]-B[L-1]);
        }
       
        
        
    }
  
  public static List<int> SieveOfEratosthenes(int n)
{
    // 素数を格納するリスト
    var primes = new List<int>();
    // 素数候補のリスト[2..n]
    var list = Enumerable.Range(2, n - 2).ToList();

    // 2以下の数の場合は空、2の場合は2を返す。
    if (n < 2) return primes;
    else if (n == 2) return new List<int>(2);

    // 素数候補をふるい落としながら素数を探す
    while (Math.Pow(list[0], 2) <= n)
    {
        var first = list[0];    // 先頭要素
        primes.Add(first);      // 先頭を素数リストへ
        list.RemoveAt(0);       // 先頭要素削除

        // 素数の倍数をふるい落とし
        list.RemoveAll(x => x % first == 0);
    }
    // 残りの探索リストをまとめて素数リストに追加
    primes.AddRange(list.ToArray());
    return primes;
}
}


Measured memory_bytes: 19260
#include <stdio.h>

int main(void){
    char s[200001],t[200001];
    int len,ans;

    scanf("%s",&s);
    scanf("%s",&t);

    ans=0;
    for (int i=0; s[i]!='\0'; i++){
        if (s[i]!=t[i]){
            ans++;
        }
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 2060
#include<iostream>
#include<algorithm>
#include<limits>
#include<iomanip>
#include<string>
#include <map>
#include <vector>
#include<string.h>
using namespace std;
 
int main(void) {
  vector<string> hoge;
  long long int n, cnt=0, max=0;
  cin >> n;
  string word;
  vector<string> vector;

  
  for(int i=0; i<n;i++) {
    cin >> word;
    vector.push_back(word);
  }
  
  sort(vector.begin(), vector.end());

  word = vector[0];
  for(int i=0;i<n;i++) {
    if(strcmp(word.c_str(),vector[i].c_str())==0) { cnt++; continue; }
    if(cnt==max) {hoge.push_back(vector[i-1]);}
    else if(cnt>max) { hoge.clear(); hoge.push_back(vector[i-1]); max=cnt;}
    cnt=1;
    word = vector[i];
  }
  if(cnt==max) {hoge.push_back(vector[n-1]);}
  else if(cnt>max) { hoge.clear(); hoge.push_back(vector[n-1]);}
  for(int i=0;i<hoge.size();i++) cout << hoge[i] << endl;
}


Measured memory_bytes: 15984
#[allow(dead_code)]
fn read_line(n: usize) -> String {
    let mut ss = String::new();
    for _i in 0..n {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        ss.push_str(&s);
    }
    ss
}

macro_rules! parse {
    ($s:expr => $($r:tt)*) => {
        let s = $s;
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        parse!{s => $($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)*}
    };
    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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()
{
    parse!{
        n: usize,
    }
    let ans = (n as f32 / 2.0 + 0.5) as u32;
    println!("{:?}", ans);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;

ll ncn(ll n){
    if(n == 1){return 2;}
    return ncn(n-1)*3*n;
}

int main(){
    ll N,P; cin >> N >> P;
    vll a(N);
    vll even(0), odd(0);
    for(int i=0; i<N; i++){
        cin >> a[i];
        if(a[i]%2==0){even.emplace_back(a[i]);}
        else{odd.emplace_back(a[i]);}
    }
    ll A = even.size(), B = odd.size();
    if(B==0&&P%2==1){
        cout << 0;
    }else if(B==0&&P%2==0){
        ll ans = 2;
        for(int i=1; i<N; i++){
            ans *= 2;
        }
        cout << ans;
    }
    else{
        ll ans = 2;
        for(int i=1; i<N-1; i++){
            ans *= 2;
        }
        cout << ans;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <algorithm>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define rep(i,n)	for(int i=0;i<n;i++)
#define srep(i,a,n)	for(int i=a;i<n;i++)
#define REP(i,n)	for(int i=0;i<=n;i++)
#define SREP(i,a,n)	for(int i=a;i<=n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define fst	first
#define scn second

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;
const ld eps = 1e-9;

int sum[2010][2010];
int vsum[2010][2010];
int hsum[2010][2010];

int main() {
	int n, m, q;	cin >> n >> m >> q;
	rep(i, n) {
		string s;	cin >> s;
		rep(j, m) {
			sum[i + 1][j + 1] = s[j] - '0';
			vsum[i + 1][j + 1] = sum[i + 1][j + 1] * sum[i][j + 1];
			hsum[i + 1][j + 1] = sum[i + 1][j + 1] * sum[i + 1][j];
		}
	}
	SREP(i, 1, n)	SREP(j, 1, m) {
		sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
		vsum[i][j] += vsum[i - 1][j] + vsum[i][j - 1] - vsum[i - 1][j - 1];
		hsum[i][j] += hsum[i - 1][j] + hsum[i][j - 1] - hsum[i - 1][j - 1];
	}
	rep(i, q) {
		int x1, y1, x2, y2;	cin >> x1 >> y1 >> x2 >> y2;
		x1--;	y1--;
		cout << (sum[x2][y2] - sum[x2][y1] - sum[x1][y2] + sum[x1][y1]) - (vsum[x2][y2] - vsum[x1 + 1][y2] - vsum[x2][y1] + vsum[x1 + 1][y1]) - (hsum[x2][y2] - hsum[x1][y2] - hsum[x2][y1 + 1] + hsum[x1][y1 + 1]) << endl;
	}
	return 0;
}

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

int main () {
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    double x_ = abs(x1 - x2);
    double y_ = abs(y1 - y2);

    printf("%.8f\n", sqrt(pow(x_, 2) + pow(y_, 2)));
    return 0;
}


Measured memory_bytes: 3288
N = gets.to_i
XY = $<.map{|s|
  x, y = s.split.map &:to_i
}
sum = 0
cnt = 0
XY.permutation(N){|perm|
  perm.each_cons(2){|(x1, y1), (x2, y2)|
    sum += ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5
  }
  cnt += 1
}
p sum / cnt


Measured memory_bytes: 1916
#include <iostream>
using ll = long long;
using namespace std;

int main() {
	ll A, B, C, K;
	cin >> A >> B >> C >> K;
	ll max = 0;


	if (K <= A) {
		max = K;
	}
	else if (K <= A + B) {
		max = A;
	}
	else {
		max = A - (K - A - B);
	}

	cout << max << endl;

	return 0;
}

Measured memory_bytes: 3164
#include<stdio.h>
#include<stdlib.h>
int main()
{
   long long int N, M;
   scanf("%lld %lld", &N, &M);
   
   if ((M - 2 * N) < 0)
	printf("%lld", M/2);
   else
	printf("%lld", N + (M - 2 * N) / 4);
   
   return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var line = consoleReader.SplitInt32();
            var A = line[0];
            var B = line[1];

            return B % A == 0 ? A + B : B - A;
        }

        const int mod = 1000000007;
        private readonly ConsoleReader consoleReader;
        public Program() : this(new ConsoleReader()) { }
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program().Calc());
        public static string MultiLine<T>(IEnumerable<T> source) => string.Join("\n", source);
    }

    public class ConsoleReader
    {
        public virtual string String() => Console.ReadLine();
        public int Int32() => int.Parse(String());
        public long Int64() => long.Parse(String());
        public ulong UInt64() => ulong.Parse(String());
        public double Double() => double.Parse(String());
        public string[] Split() => String().Split().ToArray();
        public int[] SplitInt32() => String().Split().Select(int.Parse).ToArray();
        public long[] SplitInt64() => String().Split().Select(long.Parse).ToArray();
        public ulong[] SplitUInt64() => String().Split().Select(ulong.Parse).ToArray();
        public double[] SplitDouble() => String().Split().Select(double.Parse).ToArray();

        public IEnumerable<string> Repeat(int count)
        {
            for (int i = 0; i < count; i++)
                yield return String();
        }
        public IEnumerable<int> RepeatInt32(int count)
        {
            for (int i = 0; i < count; i++)
                yield return Int32();
        }
        public IEnumerable<long> RepeatInt64(int count)
        {
            for (int i = 0; i < count; i++)
                yield return Int64();
        }
        public IEnumerable<string[]> RepeatSplit(int count)
        {
            for (int i = 0; i < count; i++)
                yield return Split();
        }
        public IEnumerable<int[]> RepeatSplitInt32(int count)
        {
            for (int i = 0; i < count; i++)
                yield return SplitInt32();
        }
    }
}


Measured memory_bytes: 13268
/********************************
*** ******** ********** *********
*** * ****** ********* * ********
*** ** ***** ******** *** *******
*** *** **** ******* ***** ******
*** **** *** ****** ******* *****
*** ***** ** ***** +++++++++ ****
*** ****** * **** *********** ***
*** *******  *** ************* **
*** ******** ** *************** *
**********_**********************
* |   /  / \  \     /    /\     *
* |  /  |   |  \   /    /  \    *
* | /   |   |   \ /    /    \   *
* |+\   |   |    |    /______\  *
* |  \  |   |    |   |        | *
* |   \  \_/     |   |        | *
********************************/
#include<bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
#define KING 1000000002
#define queen 1000002
#define fi first
#define se second
#define se second
#define lsb(i) (i & -i)
#define Pi 3.141592653589793238
#define nl cout<<'\n'
#define TEST cout<<"TEST",nl
#define all(a) a.begin(), a.end()
#define remax(a, b) (a = ((a<b) ? b : a))
#define remin(a, b) (a = ((a<b) ? a : b))
#define pr pair<lli,lli>
#define pb push_back
#define eb emplace_back
#define precise(a) cout<<fixed<<setprecision(a)
#define mp make_pair
#define vi vector<lli>
#define vpi vector<pr> 
#define P pair<lli,pr>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define NA(i,s,n) for(lli i=s;i<n;i++)
using namespace std;

lli power(lli x,lli y,lli p = (lli)(1e13)) { 
	lli res = 1;	 
	x = x % p; 
	while (y > 0) 
	{ 
		if (y & 1) 
			res = (res*x) % p; 
		y = y>>1; 
		x = (x*x) % p; 
	} 
	return res; 
}

long double dst(pair<lli,lli> p) {
    return sqrt(p.fi*p.fi + p.se*p.se);
}

void solve(){
    lli n, d, ans = 0; cin >> n >> d;
    NA(i,0,n) {
        pair<lli,lli> a;
        cin >> a.fi >> a.se;
        if(dst(a) <= d) ++ans;
    }
    cout << ans << '\n';
    return;
}


int main(){
    fastIO;
    lli t = 1;
    // cin >> t;
    NA(i,0,t){ 
		// cout << "Case #" << i+1 << ": \n";
		solve();
	}
	return 0;
}


Measured memory_bytes: 3696
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

vector<vector<P>> G;
vl height;
bool ok = true;

void dfs(ll v, ll h = 0) {
    // 行きの処理はこのへんに書く
    if(height[v] == INF) {
        height[v] = h;
    }
    else {
        if(height[v] != h) {
            ok = false;
        }
        return;
    }
    for(auto p : G[v]) { 
        ll u = p.first;
        ll cost = p.second;
        dfs(u, h + cost);
        // 帰りの処理はこのへんに書く
    }
}

int main() {
    ll n, m;
    cin >> n >> m;    
    
    G.resize(n);
    rep(i, m) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;  b--;
        G[a].pb(make_pair(b, c));
        G[b].pb(make_pair(a, -c));
    }
    
    height.assign(n, INF);
    rep(v, n) {
        if(height[v] == INF) {
            dfs(v);
        }
    }
    
    if(ok) {
        out("Yes");
    }
    else {
        out("No");
    }

    re0;
}

Measured memory_bytes: 15488
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define all(X) X.begin(),X.end()

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   str.substr (x) : returns a substring str[x],... end of string
   str.find(qtr) : returns the first occurenece of qtr in str */

const int M = 1000;
const int md = 1e9+7;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

queue<ll> q;
ll vis[M],deg[M];
ld pr[M],dp[M],dp2[M],out[M];
vector<ll> adj[M];

void dfs(ll u)
{
	vis[u] = 1;
	ld mn = 0;
	for(auto v:adj[u])
	{
		if(vis[v] == 0)
			dfs(v);
		deg[v]++;
		dp[u] += dp[v]+1;
		mn = max(mn,dp[v]+1.0);
	}
	if(adj[u].empty())
		return;
	ll sz = adj[u].size();
	dp[u] /= (ld)(sz);
	dp2[u] = dp[u];
	if (sz > 1) {
		for (int v: adj[u]) {
			dp2[u] = min(dp2[u], (dp[u]*sz - dp[v] - 1) / (sz - 1));
		}
	}
	return;
}

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

	ll n,m,i,u,v;
	ld ans = 1e15;

	cin >> n >> m;
	for(i=1;i<=m;++i)
	{
		cin >> u >> v;
		adj[u].pb(v);
		out[u] += 1.0;
	}
	dfs(1);

	q.push(1);
	pr[1] = 1.0;
	ans = dp[1];
	// cout << ans << endl;

	while(!q.empty())
	{
		u = q.front();
		q.pop();
		ans = min(ans,dp[1]-pr[u]*dp[u]+pr[u]*dp2[u]);
		for(auto v:adj[u])
		{
			deg[v]--;
			pr[v] = pr[v] + (pr[u]/out[u]);
			if(deg[v] == 0)
				q.push(v);
		}
	}

	cout << setprecision(10) << fixed << ans << "\n";
	return 0;
}

	

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

int main()
{
    int a,b,c,d,e;
    cin>>a>>b>>c;
    if(a==5)
        d++;
    else if(a==7)
        e++;
    if(b==5)
        d++;
    else if(b==7)
        e++;
    if(c==5)
        d++;
    else if(c==7)
        e++;
    
    if(d==2&&e==1)
        cout<<"YES";
    else
        cout<<"NO";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1<<30;
int num[]={3, 5, 7};
int calc(int count[3], int limit){
  // cout<<limit<<endl;
  // for(int i=0;i<3;i++)cout<<count[i]<<" ";
  // cout<<endl;
  if(limit<10){
    int zero=0;
    for(int i=0;i<3;i++){
      if(count[i]==0)zero++;
    }
   	if(zero==0){
      return int(limit>=3)+int(limit>=5)+int(limit>=7);
    }else if(zero>=2){
      return 0;
    }else{
      for(int i=0;i<3;i++){
      	if(count[i]==0){
          return int(limit>=num[i]);
        }
      }
    }
  }
  ostringstream oss;
  oss<<limit;
  int ret=0;
  for(int i=0;i<3;i++){
  	if(oss.str()[0]==char(num[i]+'0')){
      count[i]++;
      ret+=calc(count, limit%(int)round(pow(10.0, (int)oss.str().size()-1)));
      count[i]--;
    }else if(oss.str()[0]-char(num[i]+'0')>0){
      count[i]++;
      ret+=calc(count, (int)round(pow(10.0, (int)oss.str().size()-1))-1);
      count[i]--;
    }
  }
  return ret;
}
int main(){
  int n;cin>>n;
  int count[]={0, 0, 0};
  int ans=calc(count, n);
  ostringstream oss;
  oss<<n;
  for(int i=3;i<(int)oss.str().size();i++){
    ans+=calc(count, (int)round(pow(10.0, i))-1);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
n, m = gets.chomp.split.map(&:to_i)
a = Array.new(n)
m.times do
  a[gets.chomp.to_i] = 0
end
a[0] = 1
a[1] ||= 1

(2..n).each do |i|
  a[i] ||= (a[i-2] + a[i-1]) % (10**9 + 7)
end
puts a[n]


Measured memory_bytes: 2812
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;i++)
#define fs first
#define sc second
#define MAXN 100005
#define LIMIT 1500
#define LOGN 1048575
#define ll long long
#define pb push_back
#define ld long double
#define eps 1e-6
#define endl '\n'
#define lc 2*pos
#define rc 2*pos+1
using namespace std;
int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
	ll r,d,x;
	cin>>r>>d>>x;
	rep(i,10){
		x=r*x-d;
		cout<<x<<endl;
	}
	return 0;
}

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

int main() {
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  bool ex=false;
  while(a>=b&&k>0){
    b*=2;
    k--;
  }
  while(b>=c&&k>0){
    c*=2;
    k--;
  }
  if(a<b&&b<c){
    ex=true;
  }
  if(ex){ 
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
void readtxt()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
}
int main()
{
	//readtxt();
   	int n;
   	cin >> n;
   	string s;
   	map<string, int>mp;
   	while(n--)
   	{
   		cin >> s;
   		mp[s]++;
   	}
   	cout << mp.size()<<endl;
}

Measured memory_bytes: 19112
#include <stdio.h>
 
int main(){
  int H,W,i,j;
  while(1){
    scanf("%d %d",&H,&W);
    if(H==0 && W==0) break;
    for(j=0; j<H; j++){
      if(j%2==0){
    for(i=0; i<W; i++){
      if(i%2==0) printf("#");
      else  printf(".");
    }
      }
      else{
    for(i=0; i<W; i++){
      if(i%2==0) printf(".");
      else  printf("#");
    }
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}

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

using namespace std;

#define  SZ(items) (int)items.size()
#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))

template <class T> inline T bigmod(T p, T e, T m)
{
    T ret = 1;
    for (; e > 0; e >>= 1)
    {
        if (e & 1)
            ret = (ret * p) % m;
        p = (p * p) % m;
    }
    return (T)ret;
}

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1)
{
    cerr << name << " is " << arg1 << std::endl;
}
template < typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " is " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define debug(...)
#endif


void solve()
{
   int n;
   cin>>n;

   vector<string> items;
   for(int i=0;i<n;i++){
    string item;
    cin>>item;

    sort(item.begin(),item.end());
    items.push_back(item);
   }

   map<string,int> cnt;
   cnt[items[0]]++;

   long long res=0;

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

    res+=cnt[items[i]];

    cnt[items[i]]++;
   }

   cout<<res<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    cout.tie(nullptr);
    cin.tie(nullptr);

    int t = 1;

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

    return 0;
}


Measured memory_bytes: 12020
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define takeline cin.ignore();
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n;
	cin>>n;

	ll ar[n+1]; k=0;
	for(i=1;i<=n;i++){
		cin>>ar[i];
		k=k^ar[i];
	}

	if(k==0){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}

	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> TUP;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define mp(a,b) make_pair(a,b)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*y/gcd(x,y);
}

int main(){
	ll N; cin>>N;
    vector<ll> a(100000,0);
    rep(i,N){
        ll tmp; cin>>tmp;
        if(tmp==0){
            a[0]++;
            a[1]++;
        }
        else if(tmp==99999){
            a[99999]++;
            a[99998]++;
        }
        else{
            a[tmp]++;
            a[tmp-1]++;
            a[tmp+1]++;
        }
    }
    ll ans=0;
    rep(i,100000){
        ans=max(ans,a[i]);
    }
  
	printf("%lld",ans);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define f(i, l, r) for (int i = l; i <= r; i++)
#define rf(i, r, l) for (int i = r; i >= l; i--)
#define all(x) (x).begin(), (x).end()
#define sf(a) scanf("%d",&a)
#define llsf(a) scanf("%lld", &a)
#define l l
#define r r
#define lch (o << 1)
#define rch (o << 1 | 1)
#define mid ((l + r) >> 1)
#define mem(x, y) memset(x, y, sizeof(x))

const int inf = 2e9 + 7;
const ll INF = INT64_MAX;
double eps = 1e-6;
int mod = 1e9 + 7;
const int N = 1e6 + 10;
const double pi = acos(-1.0);

int main() {
#ifdef local
	freopen("in.txt", "r", stdin);
#endif
	int n, k; sf(n); sf(k);
	if (n == 1 && k > 1) {
		cout << 0; return 0;
	}
	int a = n / k; ll res = 0;
	if (k % 2 == 0) {
		int m = (n - k / 2)/k+1;
		res += 1ll * m * m * m;
		res += 1ll*a*a*a;
	}
	else {
		res += 1ll*a*a*a;
	}
	cout << res;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
X = list(map(int, input().split()))
if N >= M:
    print(0)
    exit()
X.sort()
Y = []
for i in range(1, M):
    Y.append(X[i] - X[i - 1])
Y.sort()
ans = sum(Y[:M-N])
print(ans)


Measured memory_bytes: 20316
x,y=map(int,input().split())
MOD = 10**9+7
if (x+y)%3!=0:print(0);exit()
def inv_mod(a, p=MOD):
    def inv_mod_sub(a, p):
        if a == 1:
            return 1, 0
        else:
            d, r = p//a, p%a
            x, y = inv_mod_sub(r, a)
            return y-d*x, x
    if p < 0: p = -p
    a %= p
    return inv_mod_sub(a,p)[0] % p

def comb_mod(n, k):
    if k < 0 or k > n:
        return 0
    else:
        return f_mod[n]*f_mod_inverse[k]*f_mod_inverse[n-k] % MOD
f_mod=[1]*(10**6)
f_mod_inverse=[1]*(10**6)
for i in range(1,10**6):
  f_mod[i]=f_mod[i-1]*i%MOD
  f_mod_inverse[i]=f_mod_inverse[i-1]*inv_mod(i)%MOD
cnt=(x+y)//3
dif=abs(x-y)
ele=(cnt-dif)//2
print(comb_mod(cnt,ele))

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif


void Main() {
    ll N; string S; cin >> N >> S;
    rep(i, S.size()){
        char c = S[i] + N;
        if (c - 'Z' > 0){c -= 26;}
        cout << c;
    }
}

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


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String s = in.readLine();
    for(int i=s.length()-1; i>0; i--) {
      if(s.length()%2!=0)
        continue;
      if(s.substring(0,i/2).equals(s.substring(i/2,i))) {
        System.out.println(i);
        break;
      }
    }
  }
}

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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100001,INF=1<<30;
vector<int> S[MAX];
vector<ll> dis(MAX);
ll ans,K;

ll BFS(){
    queue<int> Q;
    ll ans=1;
    Q.push(0);
    dis[0]=0;
    ans*=K;
    while(!Q.empty()){
        int a=Q.front();
        Q.pop();
        int cnt=0;
        for(int i=0;i<S[a].size();i++){
            int b=S[a][i];
            if(dis[b]==-1){
                if(dis[a]==0){
                    ans*=(K-1-cnt);
                    ans=ans%mod;
                    cnt++;
                    dis[b]=1;
                }else{
                    ans*=(K-2-cnt);
                    ans=ans%mod;
                    cnt++;
                    dis[b]=dis[a]+1;
                }
                Q.push(b);
            }
        }
    }
    
    return ans;
}

int main(){
    
    int N;cin>>N>>K;
    for(int i=0;i<N-1;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        S[a].push_back(b);
        S[b].push_back(a);
    }
    for(int i=0;i<N;i++){
        dis[i]=-1;
    }
    
    cout<<BFS()<<endl;
}



Measured memory_bytes: 7288
import sys
input = sys.stdin.readline


def main():
    H, W = map(int, input().split())
    A = [list(input()[:-1]) for _ in range(H)]

    B = [False]*H
    C = [False]*W
    for i in range(H):
        for j in range(W):
            if A[i][j]=="#":
                B[i] = True
                C[j] = True
    
    ans = ""
    for i in range(H):
        if B[i]==False:
            continue
        for j in range(W):
            if C[j]==False:
                continue
            ans += A[i][j]
        ans += "\n"

    print(ans[:-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#include <stdio.h>

#define MAX 100

int N, A[MAX];

int main() {
	int i, j;
	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}
	print();
	insertionSort();

	return 0;
}

void print() {
	int i;
	for (i = 0; i < N; i++) {
		if (i > 0) {
			printf(" ");
		}
		printf("%d", A[i]);
	}
	printf("\n");
}

void insertionSort() {
	int i, j, value;
	for (i = 1; i < N; i++) {
		value = A[i];
		j = i - 1;
		while(j >= 0 && A[j] > value) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = value;
		print();
	}
}


Measured memory_bytes: 2044
Row = int(input())
money = []
k=[]
num = 0
for _ in range(Row):
    a,b = map(str,input().split())
    money.append(float(a))
    k.append(b)
for i in range(Row):
    if k[i]=="JPY":
        num+=money[i]
    else:
        num=num+380000.0*money[i]
print(num)

Measured memory_bytes: 3064
import sys
def main():
    input = sys.stdin.readline
    q=int(input())
    Q=[tuple(map(int, input().split())) for _ in range(q)]
    asum=bsum=0
    from heapq import heappop, heappush
    s,l=[],[]
    mn=0
    for query in Q:
        if query[0]==1:
            a,b=query[1],query[2]
            bsum+=b
            E=[a,a]
            smx,lmn=a,a
            if s:
                smx=-heappop(s)
                E.append(smx)
            if l:
                lmn=heappop(l)
                E.append(lmn)
            if a<smx: mn+=smx-a
            elif lmn<a: mn+=a-lmn
            E.sort()
            for i in range(len(E)//2):
                heappush(s,-E[i])
                heappush(l,E[-1-i])
        else:
            print(-s[0], mn + bsum)

if __name__ == '__main__':
    main()

Measured memory_bytes: 110812
//https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/5/DPL_5_F

#include <bits/stdc++.h>

using namespace std;

long long MOD = 1e9 + 7;

long long f[1010][1010];

int main() {
    long long n;//ボール
    long long k;//箱
    cin >> n >> k;

    for (int i = 0; i <= 1000; ++i) {
        f[i][0] = 1;
        f[i][i] = 1;
    }

    for (int i = 1; i <= 1000; ++i) {
        for (int j = 1; j <= 1000; ++j) {
            f[i][j] = (f[i - 1][j - 1] + f[i - 1][j] + MOD) % MOD;
        }
    }

    cout << f[n - 1][k - 1] << endl;
    return 0;
}

/*
 * ボールは区別しないので，各箱に入るボールの個数のみ考える。
 * a1+a2+...+ak=n
 * をみたす1以上整数の組の個数が答え。
 * k人にn個のミカンを配るのと同じ。全員最低1個はもらう。
 * n個のミカンを一列に並べ，n-1箇所の隙間にk-1個の仕切りをはさむ。
 * B(n-1,k-1)
 *
 */


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

int main()
{
  ll n,a,b;
  cin>>n>>a>>b;
  ll x=n/(a+b);
  ll y=n%(a+b);
  ll c=x*a;
  if(y<=a)
    c+=y;
  else
    c+=a;
  cout<<c;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, s, n) for(int i = s; i < n; i++)

ll gcd(ll p, ll q) {
    if(p%q == 0) {
        return q;
    }
    return gcd(q, p%q);
}

ll lcm(ll p, ll q) {
    return p*q/gcd(p, q);
}

int main() {
    ll a, b;
    cin >> a >> b;
    ll val = lcm(a, b);
    cout << val << endl;
    return 0;
}   

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int N,K;
  cin>>N>>K;
  int h[N];
  for(int i=0;i<N;i++)cin>>h[i];
  
  int costs[N] = {0};
  for (int i=1; i < N; i++){
    int mincost = INT_MAX;
    for (int j=i-1; j >= 0 && j >= i-K; j--){
      int cost = abs(h[i]-h[j]) + costs[j];
      if (cost < mincost) mincost = cost;
    }
    costs[i] = mincost;  
  }
  cout << costs[N-1];
  return 0;
}

Measured memory_bytes: 1024
(N,M,X),*A=$<.map{_1.split.map &:to_i}
p (1..N).map{|n|A.combination(n).map{|a|a.transpose.map &:sum}.select{|c,*a|a.all?{_1>=X}}.map{_1[0]}.min}.compact.min||-1

Measured memory_bytes: 15256
#include <iostream>
#include <bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int ll;
const ll INF=1e18+5;
int main() {
    IO;
    int num , n ;
    cin>>num >>n;
    map<int , int >m ;
    for(int i = 0 ; i < n ; i++){
        int a ;
        cin>>a;
        m[a]++;
    }
    int append=0;
    while (true){
        if(m[num-append]==0){
            cout<<num-append;
            return 0;
        }
        if(m[num+append]==0){
            cout<<num+append;
            return 0;
        }
        append++;
    }
}


Measured memory_bytes: 3624
h = int(input())
w = int(input())
n = int(input())
a = 0
b = 0
c = 0
d = 0
for i in range(h):
  a += w
  b += 1
  if a >= n:
    break
for i in range(w):
  c += h
  d += 1
  if c >= n:
    break
if b > d:
  print(d)
else:
  print(b)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printInt(a) printf("%d\n", a)
#define printll(a) printf("%lld\n", a)
#define printYes() printf("Yes\n")
#define printNo() printf("No\n")
#define scanll(a) scanf("%lld", &a)
#define scanInt(a) scanf("%d", &a)
#define scan2Int(a, b) scanf("%d %d", &a, &b)
#define scan3Int(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define scan4Int(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)
typedef long long ll;
const int INF = 1001001001;
using namespace std;
 
int main() {
    int n,m,x;
    scan3Int(n,m,x);
    int books[n][m];
    int costs[n];
    rep(i, n) {
        cin >> costs[i];
        rep(j, m) {
            cin >> books[i][j];
        }
    }
    int counts[m], min = INF, total;
    bool flag;
    rep(bits, 1 << n) {
        flag = true;
        total = 0;
        rep(i, m) counts[i] = 0;
        rep(i, n) {
            if (bits >> i & 0b1) {
                total += costs[i];
                rep(j, m) {
                    counts[j] += books[i][j]; 
                }
            }
        }
        rep(i, m) if (counts[i] < x) flag = false;
        if (flag) 
            min = min < total ? min : total;
    }
    if (min == INF) printInt(-1);
    else printInt(min);
    return 0;
}

Measured memory_bytes: 3744
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
typedef long long ll;
const int INF=1000000000;
const int MOD=1000000007;

int main()
{
 string s, t;
 int c=0;
 cin >> s >> t;
 for(int i=0;i<s.length();i++){
   if(s[i]!=t[i]) c++;
 }
 cout<<c;
  return 0;
}

Measured memory_bytes: 3908