akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"math/big"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*10)

func main() {
	N := getStdinInt()
	A := getStdinIntArr64()
	Abig := make([]*big.Int, N)
	for i := 0; i < N; i++ {
		Abig[i] = big.NewInt(A[i])
	}

	for i := 0; i < len(A); i++ {
		if A[i] == 0 {
			fmt.Printf("0\n")
			return
		}
		if A[i] > 1000000000000000000 {
			fmt.Printf("-1\n")
			return
		}
	}

	ans := big.NewInt(1)
	cmp := big.NewInt(1000000000000000000)
	for i := 0; i < len(Abig); i++ {
		ans = ans.Mul(ans, Abig[i])
		if ans.Cmp(cmp) == 1 {
			fmt.Printf("-1\n")
			return
		}
	}
	fmt.Printf("%s\n", fmt.Sprint(ans))
	fmt.Printf("\n")
}

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}

func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}

func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, e := sc.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 14976
#include<iostream>
    using namespace std;
    int main(){
      long N,A[100],s[10000],t=0,u;
      cin>>N;
      for(int i=0;i<N;i++)cin>>A[i];
      for(int j=0;j<N;j++){
        for(int k=0;k<N;k++){
        s[t]=A[j]-A[k];
        t++;
        }
      }
      for(int l;l<t;l++){
        if(s[l]>u)u=s[l];
      }
      cout<<u<<endl;
    }

Measured memory_bytes: 384
#include <algorithm>
#include <map>
#include <iostream>
#include <string>
#include <set>
#include <queue>
#include <cmath>
#include <iterator>
#include <array>
typedef long long int ll;
using namespace std;
#define maxN 200005
#define mod 1000000007

ll n;
ll a = 0, b = 0;
void solve()
{
    cin >> n;
    for (ll i = -126; i <= 126; i++)
    {
        for (ll j = -126; j <= 126; j++)
        {
            if (ll(i * i * i * i * i) - ll(j * j * j * j * j) == n)
            {
                a = i, b = j;
                return;
            }
        }
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    solve();
    cout << a << " " << b << endl;
}

Measured memory_bytes: 3604
def cc
    n,k,q = gets.chomp.split(/\s/).map{|x| x.to_i}

    po = Array.new(n, k)
    an = Array.new(100000+1,0)
    for i in 1..q
        an[gets.chomp.to_i-1] += 1
    end

    for i in 1..n
        puts po[i-1] - (q - an[i-1]) > 0 ? 'Yes' : 'No'
    end
end

cc


Measured memory_bytes: 3708
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };

    let n: usize = sc.read();
    let a: u64 = sc.read();
    let b: u64 = sc.read();
    match solve(a, b, n) {
        Some(ans) => {
            println!("YES");
            for (i, ans) in ans.into_iter().enumerate() {
                if i > 0 {
                    print!(" ");
                }
                print!("{}", ans);
            }
            println!();
        }
        None => {
            println!("NO");
        }
    }
}

fn solve(a: u64, b: u64, n: usize) -> Option<Vec<u64>> {
    if (a ^ b).count_ones() & 1 == 0 {
        return None;
    }
    if n == 1 {
        return Some(vec![a, b]);
    }
    let k = (0..).find(|&i| (a & (1 << i)) != (b & (1 << i))).unwrap();
    let a_bit = (a >> k) & 1;
    let b_bit = (b >> k) & 1;
    assert_ne!(a_bit, b_bit);

    let next_a = remove_bit(a, k);
    let next_b = remove_bit(b, k);
    let next_c = next_a ^ 1;

    let prefix = solve(next_a, next_c, n - 1);
    let suffix = solve(next_c, next_b, n - 1);
    match (prefix, suffix) {
        (Some(prefix), Some(suffix)) => {
            let mut result = vec![];
            for p in prefix.into_iter() {
                result.push(insert(p, k, a_bit));
            }
            for s in suffix.into_iter() {
                result.push(insert(s, k, b_bit));
            }
            Some(result)
        }
        _ => None,
    }
}

fn remove_bit(x: u64, i: u64) -> u64 {
    let prefix = (x >> (i + 1)) << i;
    let suffix = x & ((1 << i) - 1);
    assert_eq!(prefix & suffix, 0);
    prefix | suffix
}

fn insert(x: u64, i: u64, b: u64) -> u64 {
    let suffix = x & ((1 << i) - 1);
    let prefix = (x >> i) << (i + 1);
    assert_eq!(prefix & (1 << i), 0);
    assert_eq!(suffix & (1 << i), 0);
    assert_eq!(prefix & suffix, 0);
    prefix | (b << i) | suffix
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 7164
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

int main(){
    ll N;
    cin >> N;
    ll cnt[66][2] = {};
    rep(i, N){
        ll a;
        cin >> a;
        rep(j, 62)cnt[j][0 != (a & (1LL << j))]++;
    }
    ll ans = 0;
    rep(i, 62){
        ll tmp = 1LL << i;
        tmp %= MOD;
        tmp = (tmp * cnt[i][0]) % MOD;
        tmp = (tmp * cnt[i][1]) % MOD;
        ans = (ans + tmp) % MOD;
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  string S;
  string march = "MARCH";
  int count = 0;
  vector<long> data(5, 0);
  for (int i = 0; i < N; i++){
    count = 0;
    cin >> S;
    for (char a: march) {
      if(S.at(0) == a) data.at(0 + count)++;
      count++;
    }
  }
  cout << data.at(2) * data.at(3) * data.at(4) + data.at(1) * data.at(3) * data.at(4) + data.at(1) * data.at(2) * data.at(4) + data.at(1) * data.at(2) * data.at(3) + data.at(0) * data.at(3) * data.at(4) + data.at(0) * data.at(2) * data.at(4) + data.at(0) * data.at(2) * data.at(3) + data.at(0) * data.at(1) * data.at(4) + data.at(0) * data.at(1) * data.at(3) + data.at(0) * data.at(1) * data.at(2) << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Convert;
using static System.Console;
using static System.Math;
class MainClass
{
	static void Main(string[] args)
	{
		{
			string n = ReadLine();
			int[] arr = ReadLine().Split(' ').Select(int.Parse).ToArray();
			WriteLine(Min(GetCnt(arr, true), GetCnt(arr, false)));
		}
    }
    private static long GetCnt(int[] arr,bool isPlus)
          {
              var result = 0L;
              var sum = 0L;
              for(int i = 0; i < arr.Length; i++)
              {
                  sum += arr[i];
                  if (isPlus)
                  {
                      if (sum <= 0) { result += 1 - sum;sum = 1; }
                  }
                  else
                      if (sum >= 0) { result += 1 + sum;sum = -1; }
                  isPlus = isPlus ? false : true;
              }
              return result;
		}
}

Measured memory_bytes: 27996
import sys
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
import itertools


def main():
    input = sys.stdin.buffer.readline
    h, w = map(int, input().split())
    c = [list(map(int, input().split())) for _ in range(10)]
    a = [list(map(int, input().split())) for _ in range(h)]
    d = floyd_warshall(csgraph=csr_matrix(c, dtype="i8"), directed=True)
    ans = 0
    for n in itertools.chain.from_iterable(a):
        if n != -1:
            ans += int(d[n][1])
    print(ans)


if __name__ == "__main__":
    main()


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

#define For(i, l, r) for(register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for(register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, T b) { return b > a ? a = b, 1 : 0; }

inline int read() {
	int x(0), sgn(1); char ch(getchar());
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') sgn = -1;
	for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
	return x * sgn;
}

void File() {
#ifdef zjp_shadow
	freopen ("A.in", "r", stdin);
	freopen ("A.out", "w", stdout);
#endif
}

const int N = 55;

int n, A;

long long dp[N][N * N * 2];

int main () {

	File();

	n = read();
	A = read();

	dp[0][0] = 1;

	int minv = 0, maxv = 0;
	For (i, 0, n - 1) {
		int x = read() - A;
		For (j, minv, maxv) {
			dp[i + 1][j + x] += dp[i][j];
			dp[i + 1][j] += dp[i][j];
		}
		chkmin(minv, minv + x);
		chkmax(maxv, maxv + x);
	}
	printf ("%lld\n", dp[n][0] - 1);

	return 0;

}


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

S = readline().decode().rstrip()

ans = 'WA'
if S[0] == 'A':
    if S[2:-1:].count('C') == 1:
        ans = 'AC' if S[1::].replace('C', "").islower() else 'WA'
print(ans)


Measured memory_bytes: 8928
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

//class topological_sort{
//public:
//    int V;
//    vector<int> vis, indeg, sorted;
//    vector<vector<int>> edge;
//    topological_sort(int v){
//        V = v;
//        vis.resize(v, 0);
//        indeg.resize(v, 0);
//        edge.resize(v);
//    }
//
//    void add(int from, int to){
//        edge[from].push_back(to);
//        indeg[to]++;
//    }
//
//    void bfs(int s){
//        queue<int> q;
//        q.push(s);
//        vis[s] = 1;
//        while (!q.empty()) {
//            int f = q.front();
//            q.pop();
//            sorted.push_back(f);
//            rep(i, edge[f].size()){
//                int e = edge[f][i];
//                indeg[e]--;
//                if (indeg[e] == 0 && !vis[e]) {
//                    vis[e] = 1;
//                    q.push(e);
//                }
//            }
//        }
//    }
//
//    void sort(){
//        rep(i, V){
//            if (indeg[i] == 0 && !vis[i]) {
//                bfs(i);
//            }
//        }
//    }
//};

struct edge {int to; int cost;};

struct dist {int l, r, d;};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N, M;
    cin >> N >> M;
    
    vector<vector<edge>> G(N);
    vector<int> D(N);
    vector<int> used(N);
    vector<dist> DST(M);
    rep(i, M){
        int l, r, d;
        cin >> l >> r >> d;
        l--, r--;
        DST[i] = {l, r, d};
        G[l].pb({r, d});
        G[r].pb({l, -d});
    }
    
    rep(i, N){
        if(!used[i]){
            queue<int> q;
            q.push(i);
            used[i] = 1;
            while(!q.empty()){
                int t = q.front();
                q.pop();
                for(edge e: G[t]){
                    D[e.to] = D[t] + e.cost;
                    if(!used[e.to]) {
//                        cout << e.to <<  endl;
                        q.push(e.to);
                        used[e.to] = 1;
                    }
                }
            }
        }
    }
    
    rep(i, M){
        if(D[DST[i].r] - D[DST[i].l] != DST[i].d){
            output("No");
            return 0;
        }
    }
    output("Yes");
    
    
    
    
    return 0;
}


Measured memory_bytes: 12160
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = n;
		int r = 0;
		int sum = 0;
		while(q!=0){
			r = q%10;
			q = q/10;
			sum += r;
		}
		if(n%sum==0){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 23252
def judge(As):
    print('?', *[A + 1 for A in As])
    res = input()
    if res == '-1':
        exit()
    return res[0]
N = int(input())
N2 = N + N
L, R = 0, N
fL = judge(range(L, L + N))
fR = 'B' if fL == 'R' else 'R'
while R - L > 1:
    mid = (L + R) // 2
    fM = judge(range(mid, mid + N))
    if fM == fL:
        L = mid
    else:
        R = mid
res = [''] * N2
res[L] = fL
res[L + N] = fR
T1s = set(range(L + 1, L + N))
T2s = set(range(L)) | set(range(L + N + 1, N2))
for i in range(N2):
    if i == L or i == L + N:
        continue
    if i in T1s:
        res[i] = judge(T2s | {i})
    else:
        res[i] = judge(T1s | {i})
print('! ', ''.join(res))

Measured memory_bytes: 3532
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
  int ans,i,l,num;
  char N[200001];
  ans=0;
  scanf("%s",N);
  l=strlen(N);
  for(i=0;i<l;i++){
    if(strncmp("1",&N[i],1)==0) num=1;
    else if(strncmp("2",&N[i],1)==0) num=2;
    else if(strncmp("3",&N[i],1)==0) num=3;
    else if(strncmp("4",&N[i],1)==0) num=4;
    else if(strncmp("5",&N[i],1)==0) num=5;
    else if(strncmp("6",&N[i],1)==0) num=6;
    else if(strncmp("7",&N[i],1)==0) num=7;
    else if(strncmp("8",&N[i],1)==0) num=8;
    else num=0;
    ans=ans+num;
  }
  if(ans%9==0) printf("Yes");
  else printf("No");
  return 0;
}



Measured memory_bytes: 1864
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int W = sc.nextInt();
        int H = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int r = sc.nextInt();

        if ((x-r) >= 0 && (x+r) <= W && (y+r)<= H && (y-r)>=0 ){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }
}



Measured memory_bytes: 26296
require 'prime'

class Fractional
    attr_reader :mod

    def initialize(max, mod)
        @max = max
        @mod = mod
        @frac     = { 0 => 1, 1 => 1 }
        @frac_inv = { 0 => 1, 1 => 1 }
        @inv      = {         1 => 1 }

        pre_calc(max)
    end

    def pre_calc(max)
        2.upto(max) do |i|
            @frac[i] = @frac[i - 1] * i % @mod;
            @inv[i] = @mod - @inv[@mod % i] * (@mod / i) % @mod
            @frac_inv[i] = @frac_inv[i - 1] * @inv[i] % @mod
        end
    end

    def at(i)
        @frac[i]
    end

    def inv_at(i)
        @frac_inv[i]
    end
end

class Combination
    def initialize(fraction)
        @fraction = fraction
    end

    def calc(n, r)
        return 0 if n < r
        return 0 if (n < 0 || r < 0)

        denom_inv = (@fraction.inv_at(r) * @fraction.inv_at(n - r) % @fraction.mod)
        return @fraction.at(n) * denom_inv % @fraction.mod
    end
end

MOD = 10 ** 9 + 7 
n, m = gets.chomp!.split(' ').map(&:to_i)

# maxは n - 1 + (mの素因数分解時の1種類の素因数の数の最大)
# m < 10^9で2^50 > 10^9なので(mの素因数分解時の1種類の素因数の数の最大)は50個あれば十分
f = Fractional.new(10 ** 5 + 50, MOD)
c = Combination.new(f)

total = 1
primes = Prime.prime_division(m)
primes.each do |prime, num|
    # 同一素数の数
    x = num
    # 仕切りの数
    y = (n-1)

    total = total * c.calc(x + y, x) % f.mod
end

puts total


Measured memory_bytes: 21500
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(20);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const long long dy9[] = {0,1,1,1,0,-1,-1,-1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */



/* main */

signed main(){
    ll N;
    cin >> N;
    vl A(N);
    FOR(i,0,N)cin >> A[i];
    ll ans = 0;
    FOR(i,0,N-1){
        ans += A[i]/2;
        A[i] %= 2;
        if(A[i]){
            if(A[i+1]){
                ans++;
                A[i+1]--;
            }
        }
    }
    ans += A[N-1]/2;
    cout << ans << endl;
}

Measured memory_bytes: 1024
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
for i in range(n):
    z=0
    for j in range(i+1):
        z+=a[j]
    for j in range(i,n):
        z+=b[j]
    ans=max(ans,z)
print(ans)


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

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

    for (int i=0; i<s.size() ;i++){
        rotate(s.begin(),s.begin()+1,s.end());
        if (s==t){
            cout << "Yes" <<endl;
            exit(0);
        }
    }
    cout << "No" <<endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)


@mt
def slv(N, K, AB):
    M = Mod(10**9+7)
    def P(n, k):
        ret = 1
        for i in range(n, n-k, -1):
            ret = M.mul(ret, i)
        return ret
    
    g = defaultdict(list)
    for a, b in AB:
        g[a].append(b)
        g[b].append(a)
    
    q = [1]
    done = set()
    ans = K
    while q:
        u = q.pop()
        
        for v in g[u]:
            if v not in done:
                done.add(v)
                q.append(v)
        c = len(g[u])-1
        if u == 1:
            c += 1
        
        done.add(u)
        if u == 1:
            ans = M.mul(ans, P(K-1, c))
        else:
            ans = M.mul(ans, P(K-2, c))
    return ans


def main():
    N, K = read_int_n()
    AB = [read_int_n() for _ in range(N-1)]
    print(slv(N, K, AB))


if __name__ == '__main__':
    main()


Measured memory_bytes: 111988
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll a,b,c;
    ll c7=0,b5=0;
    cin>>a>>b>>c;
    if(b==7)c7++;
    if(b==5)b5++;
    if(a==5)b5++;
    if(a==7)c7++;
    if(c==5)b5++;
    if(c==7)c7++;
        if(b5==2 && c7==1)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int sum, N;
  cin >> N;
  sum = 0;
  
  for ( int i = 0; i < N; i++){
    int a, b;
    cin >> a >> b;
    sum += ( b - a + 1 );
  }
  
  cout << sum << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <map>
#include <cmath>
#include <queue>
#include <cstring>

using namespace std;
const int maxn = 1e7+5;
typedef long long ll;


int main()
{
    int a,b;
    cin>>a>>b;

    if(a%b)
    {
        printf("1\n");
    }
    else printf("0\n");


    return 0;
}


Measured memory_bytes: 256
def solve():
    n = int(input())
    prev = input()
    already = {prev}
    for _ in range(n - 1):
        word = input()
        if word in already:
            return False
        if prev[-1] != word[0]:
            return False
        already.add(word)
        prev = word
    return True


print('Yes' if solve() else 'No')


Measured memory_bytes: 2940
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-01-26 20:28:09
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(_) cerr << #_ << ": " << (_) << '\n'
#else
#define debug(_) 1728
#endif

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

  int h, a; cin >> h >> a;
  cout << (h + a - 1) / a << endl;

  return 0;
}

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

A = []

for i in range(1,N+1):
    ans = 0
    X = S[:i]
    Y = S[i:len(S)+1]
    L = []
    M = []
    for j in range(len(X)):
        L.append(X[j])
    for k in range(len(Y)):
        M.append(Y[k])
    LS = set(L)
    for l in LS:
         if l in M:
            ans += 1

    A.append(ans)

print(max(A))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int n,a[200001],f=1;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+1+n);
	for(int i=1;i<n and f;i++)
		if(a[i]==a[i+1])f=0;
	if(f)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}

Measured memory_bytes: 1024
N,X=[int(x) for x in input().split(' ')]
arr=[int(x) for x in input().split(' ')]
temp=0
flag=0
for x in range(N):
  if arr[x]+temp>X:
    temp=x
    flag=1
    break
  else:
    temp+=arr[x]
if flag:
  print(temp+1)
else:
  print(N+1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define null NULL

using namespace std;

const ll MOD = 1e9 + 7;

const int mx = 200;
int n, used[mx], l[mx];
vector<pair<int, int> > a, b;
vector<int> g[mx];

bool dfs(int v) {
	if (used[v] == 1)
		return 0;
	used[v] = 1;
	for (auto v1 : g[v]) {
		if (l[v1] == -1) {
			l[v1] = v;
			return 1;
		}
	}
	for (auto v1 : g[v]) {
		if (dfs(l[v1])) {
			l[v1] = v;
			return 1;
		}
	}
	return 0;
}

int main() {
	cin >> n;
	a.resize(n);
	b.resize(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i].first >> a[i].second;
	}
	for (int i = 0; i < n; ++i) {
		cin >> b[i].first >> b[i].second;
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if (a[i].first < b[j].first && a[i].second < b[j].second)
				g[i].push_back(j);
		}
	}
	for (int i = 0; i < n; ++i) {
		l[i] = -1;
	}
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			used[j] = 0;
		}
		if (dfs(i))
			ans++;
	}
	cout << ans << endl;
}

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

typedef long long ll;

ll find_div(int n) {
	vector<int> divs;
	for (int i = 1; i * i <= n; ++i) {
		if (n % i == 0) {
			divs.push_back(i);
			divs.push_back(n/i);
		}
	}
	divs.resize(unique(divs.begin(), divs.end()) - divs.begin());
	return (ll) divs.size();
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	ll res = 0;
	for (int i = 1; i < n; ++i) {
		res += find_div(n-i);
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3576
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    long long N;

    scanf("%lld", &N);

    long long A = sqrtl(N);

    while(N % A != 0){
        A--;
    }
    long long B = N / A;

    int ans = 0;

    while(B > 0){
        B /= 10;
        ans++;
    }

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

    return 0;
}

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

int main() {
	bool bl_Y = false;
  	int N;
  	cin >> N;
  	for (int i = 0; i < N; i++) {
    	string one_word;
      	cin >> one_word;
      	if (one_word == "Y") {
        	bl_Y = true;
        }
    }
  	if (bl_Y == true) {
    	cout << "Four" << endl;
    }else if (bl_Y == false) {
    	cout << "Three" << endl;
    }
}

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

#pragma region  // {{{

#define all(x) std::begin(x), std::end(x)
#define rall(x) std::rbegin(x), std::rend(x)
#define rep(i, begin, end) for (int64_t i{begin}, i##_end{end}; i < i##_end; ++i)
#define repc(i, begin, last) for (int64_t i{begin}, i##_last{last}; i <= i##_last; ++i)
#define repr(i, begin, last) for (int64_t i{begin}, i##_last{last}; i >= i##_last; --i)
#define let const auto
using i64 = std::int64_t;
using u64 = std::uint64_t;

constexpr int32_t INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;

void ioSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(11);
    std::cerr << std::fixed << std::setprecision(11);
    std::clog << std::fixed << std::setprecision(11);
}

template <class T>
std::istream& operator,(std::istream& is, T& rhs) {
    return is >> rhs;
}

#define var(type, ...) \
    type __VA_ARGS__;  \
    std::cin >> __VA_ARGS__

inline void println() {
    std::cout << '\n';
}
template <class Head, class... Tail>
inline void println(Head&& head, Tail&&... tail) {
    std::cout << head << " " + (!sizeof...(tail));
    println(std::forward<Tail>(tail)...);
}

template <class T, class U>
inline bool chmin(T& a, const U& b) {
    return b < a && (a = b, true);
}

template <class T, class U>
inline bool chmax(T& a, const U& b) {
    return b > a && (a = b, true);
}

#pragma endregion  // }}}

// constexpr int MOD = int(1e9) + 7;
// constexpr int MOD = 998244353;

signed main() {
    ioSetup();
    var(int, a);
    println(!a);

    return 0;
}


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

#define mod 1000000007

using namespace std;
typedef long long ll; 
 
int main(void){
	
	int N;
	ll ans = 0;
	
	cin >> N;
	
	map<string, int> mp;
	
	for(int i=0; i<N; i++){
		string s;
		cin >> s;
		sort(s.begin(), s.end());
		mp[s]++;
	}
	
	for(auto p:mp)
		ans += p.second * (ll)(p.second - 1) / 2;
	
	cout << ans;
	
	return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  string s;
  cin >> s;
  sort(s.begin(), s.end());
  if (s == "abc")
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
ll MOD = 1000000000 + 7;

int main() {
    int n;
    cin >> n;
    int none = 0, two = 0, four = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (!(a % 4))
            four++;
        else if (!(a % 2))
            two++;
        else
            none++;
    }

    string ans = "Yes";
    if (four < none) ans = "No";
    if (two == 0 and four + 1 == none) ans = "Yes";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll n;
vector<ll> a;

int main() {
	cin >> n;
	a.resize(n);
	rep(i, n)cin >> a[i];
	sort(ALL(a));
	ll g = INF;
	ll ans = -1;
	rep(i, n - 1) {
		if (g >= abs(a.back() / 2 - a[i])) {
			g = abs(a.back() / 2 - a[i]);
			ans = a[i];
		}
	}
	cout << a.back() << " " << ans << endl;
}

Measured memory_bytes: 1024
#include <cmath>
#include <chrono>
#include <random>
#include <ctime>
#include <algorithm>
#include <iosfwd>
#include <iostream>
#include <list>
#include <ostream>
#include <streambuf>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define fori(i, n) for(ll i = 0; i < (n); ++i)
#define forI(i, n) for(ll i = 1; i <= (n); ++i)
#define pll pair<ll, ll>
#define ff first
#define ss second

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

#define pt pair<ll, ll>
#define x first
#define y second

pll operator+(pll a, pll b) { return {a.x + b.x, a.y + b.y}; }

ll rand0m() {
    return (ull(rand()) << 15ull | ull(rand()));
}                   //[0 ... n)
ll rand0m(ll x) {
    return rand0m() % x;
}               //[0 ... n)
ll rand0m(ll minn, ll maxx) {
    return rand0m(maxx - minn + 1) + minn;
}   //[minn ... maxx]

const ll MAXN = 1e5 + 1;
const ll mod = 1e9 + 7;
const ll INF = 1e18;

ll n, m;

ld dp[311][311][311];

ld solve(vector<ll> &ve) {
    ll ar[] = {0, 0, 0};
    fori(i, n){
        ++ar[ve[i] - 1];
    }
    //dp[ar[0]][ar[1]][ar[2]] = 0;
    fori(k, ar[2] + 1){
        fori(j, ar[1] + ar[2] + 1){
            fori(i, ar[0] + ar[1] + ar[2] + 1){
                if(k == 0 && j == 0 && i == 0) continue;
                //1 / (1 - (n - a - b - c) / n) = n / (a + b + c)
                ld p0 = ld(n) / (i + j + k);
                ld p1 = ld(i) / (i + j + k);
                ld p2 = ld(j) / (i + j + k);
                ld p3 = ld(k) / (i + j + k);
                dp[i][j][k] = p0;
                if(i) dp[i][j][k] += p1 * dp[i - 1][j][k];
                if(j) dp[i][j][k] += p2 * dp[i + 1][j - 1][k];
                if(k) dp[i][j][k] += p3 * dp[i][j + 1][k - 1];
            }
        }
    }
    return dp[ar[0]][ar[1]][ar[2]];
}

ll dfs(ll step, vector<ll> ve, ll a){
    if(a == 0)
        return step;
    ll i = rand0m(n);
    if(ve[i] > 0){
        --ve[i];
        --a;
    }
    return dfs(step + 1, ve, a);
}
void stress(){
    srand(1);

    //vector<ll> ve = {1, 3, 2, 3, 3, 2, 3, 2, 1, 3};
    cin >> n;
    vector<ll> ve(n);
    fori(i, n) cin >> ve[i];

    ll m = 0;
    n = ve.size();
    for(ll w: ve) m += w;
    ll c = 0;
    ll t = 1000000;
    fori(i, t){
        c += dfs(0, ve, m);
    }
    cout.precision(10);
    cout << fixed << ld(c) / t << " " << solve(ve);
}

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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n;
    vector<ll> ve(n);
    fori(i, n) cin >> ve[i];
    //stress();
    cout.precision(12);
    cout << fixed << solve(ve);
}

Measured memory_bytes: 456960
from collections import deque


def dfs(start):
    link = {start}
    S = deque()
    # child = deque()
    visited[start] = 1
    S.append(start)
    while len(S) > 0:
        node = S.pop()
        # child.clear()
        for f in friend[node]:
            if visited[f] == 0:
                S.append(f)
                visited[f] = 1
                link.add(f)
    for i in link:
        res[i] = len(link) - len(link & friend[i]) - len(link & block[i]) - 1


N, M, K = map(int, input().split())
Friend = [list(map(int, input().split())) for _ in range(M)]
Block = [list(map(int, input().split())) for _ in range(K)]
visited = [0 for _ in range(N + 1)]
res = [0 for _ in range(N + 1)]

friend = [set() for _ in range(N + 1)]
block = [set() for _ in range(N + 1)]

for a, b in Friend:
    friend[a].add(b)
    friend[b].add(a)

for a, b in Block:
    block[a].add(b)
    block[b].add(a)

for i in range(1, N + 1):
    if visited[i] == 1:
        continue
    dfs(i)

print(*res[1:])


Measured memory_bytes: 116824
#include<iostream>
using namespace std;
int main() {
	char a;
	cin >> a;
	if (a == 'A') {
		cout << 'T' << endl;
	}
	else if (a == 'T') {
		cout << 'A' << endl;
	}
	else if (a == 'C') {
		cout << 'G' << endl;
	}
	else {
		cout << 'C' << endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int a,b;
	char op;
	
	while(1){
		scanf("%d %c %d",&a,&op,&b);
		
		if(op==('+')){
		printf("%d\n",a+b);
		}
		else if(op==('-')){
			printf("%d\n",a-b);
		}
		else if(op==('*')){
			printf("%d\n",a*b);
		}
		else if(op==('/')){
			printf("%d\n",a/b);
		}
		else if(op==('?')) break;
	}
	return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>

using namespace std;

typedef long long ll;

#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())

int main() {

	int n, m;
	cin >> n >> m;
	cout << (1900 * m + 100 * (n - m))*pow(2, m) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <numeric>

#define FOR(i,a,b) for(i=(a);i<(b);++i) 
#define FORR(i,a,b) for(i=(a);i>(b);--i)
#define REP(i,n) for(i=0;i<(n);++i)
#define REPR(i,n) for(i=(n);i>0;--i)
#define ll long long
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807

using namespace std;

long long GCD(long long a, long long b) {
	if (a < b)
		swap(a, b);
	if (b == 0) return a;
	else return GCD(b, a % b);
}

bool sosuu_check(int num) {
	int i;
	for (i = 2; i <= sqrt(num); ++i) {
		if (num%i==0)
			return false;
	}
	return (num < 2) ? false : true;
}

int main() {
	int N, H, i, MA, ans=0;
	cin >> N >> H;
	vector<int> a(100000),b(100000);
	REP(i, N) 
		cin >> a[i] >> b[i];
	MA = *max_element(a.begin(), a.begin() + N);
	sort(b.begin(), b.begin() + N);
	FORR(i, N - 1, -1) {
		if (H <= 0) {
			cout << ans << endl;
			return 0;
		}
		if (b[i] > MA) {
			++ans;
			H -= b[i];
		}
		else
			break;
	}
	if (H <= 0) {
		cout << ans << endl;
		return 0;
	}
	ans += (H + MA - 1) / MA;
	cout << ans << endl;
}

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

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353 
#define MEM_SIZE 100010
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()


template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solve(void)
{
  int n;cin>>n;
  vector<int> a (n,0);
  for (int i = 0; i < n; i++)
  {
     cin>>a[i];
  }
  vector<int> b (n,0);
  for (int i = 0; i < n; i++)
  {
     cin>>b[i];
  }
  vector<vector<int> > dp (500000,vector<int>(55,INF));
  dp[0][0] = 0;
  for (int bit = 0; bit < (1<<n); bit++)
  {
    int s_size = 0;
    for (int i = 0; i < n; i++)
    {
      int mask = 1<<i;
      if(bit&mask)s_size++;
    }
    vector<pair<int,int> > inv_s;
    int now = s_size;
    for (int i = 0; i < n; i++)
    {
      int mask = 1<<i;
      if((bit&mask) == 0){
        inv_s.emplace_back(i,now);
        now++;
      }
    }
    for (int last = 0; last < 51; last++)
    {
      for (auto &&v : inv_s)
      {
        int i = v.first;
        int now = v.second;
        int i_val;
        if(abs(i - s_size)%2 == 0){
          i_val = a[i];
        }
        else
        {
          i_val = b[i];
        }
        if(i_val >= last)
        {
          chmin(dp[bit|(1<<i)][i_val],dp[bit][last] + abs(now - s_size));
        }
        
      }
      
    }
    
    
  }
  
  int res  = INF;
  for (int i = 0; i < 55; i++)
  {
    chmin(res,dp[(1<<n)-1][i]);
  }
  if(res == INF)
  {
    cout<<-1<<endl;
  }  
  else
  {
    cout<<res<<endl;
  }
  return;
  
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


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

string to_string(string s)
{
	return '"' + s + '"';
}

string to_string(const char *s)
{
	return to_string((string)s);
}

string to_string(bool b)
{
	return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p)
{
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v)
{
	bool first = true;
	string res = "{";
	for (const auto &x : v)
	{
		if (!first)
		{
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}";
	return res;
}


void debug_out() { cerr << '\n'; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
	cerr << " " << to_string(H);
	debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(x...) ;
#endif

#define ll long long
#define len(a) a.size()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(a)  (a).begin() , (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define iter(x , a) for(auto &x : a)

class dsu {
public :
	vector<int> par , sz ;
	int comp ;
	dsu(int n) {
		comp = n ;
		par.resize(n + 1) ;
		sz.resize(n + 1) ;
		fill(all(sz) , 1) ;
		iota(all(par), 0);
	}
	int parent(int x) {
		if (x == par[x]) return x ;
		return par[x] = parent(par[x]) ;
	}
	void unite(int a , int b) {
		int x = parent(a) ;
		int y = parent(b);

		if (x != y) {
			sz[y] += sz[x] ;
			sz[x] = 0 ;
			par[x] = y  ;
		}

	}

};
void solve() {
	int n , x ;
	cin >> n >> x;
	dsu d(n) ;
	for (int i = 0 ; i < x ; ++i) {
		int a , b ;
		cin >> a >> b ;
		d.unite(a , b) ;
	}
	int ans = 0 ;
	for (auto &x : d.sz)
		ans = max(ans , x) ;
	cout << ans ;

}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt" , "r" , stdin) ;
#endif
	int T = 1 ;
	while (T--) {
		solve() ;
	}
}

Measured memory_bytes: 4768
#include<stdio.h>
 
int main()
{
    long long int a,b;
    long double c;
 
    scanf("%lld %lld",&a,&b);
 
    c=(a+b)/2.0;
    a=(a+b)/2;
 
    if(c-a == 0.00) 
    	printf("%.0Lf\n",c);
    else 
    	printf("IMPOSSIBLE\n");
}

Measured memory_bytes: 128
#[allow(unused_imports)]
use proconio::input;
use proconio::marker::*;
use std::collections::HashSet;

fn main() {
  input! {
    s: Chars,
    k: usize,
  }
  let base = [
    'a', 'b', 'c', 'd', 'e',
    'f', 'g', 'h', 'i', 'j',
    'k', 'l', 'm', 'n', 'o',
    'p', 'q', 'r', 's', 't',
    'u', 'v', 'w', 'x', 'y', 'z'
  ];
  
  let n = s.len();
  let mut set: HashSet<String> = HashSet::new();
  for c in base.iter() {
    for (i, cc) in s.iter().enumerate() {
      if c == cc {
        let mut ii = i+1;
        let mut temp = c.to_string();
        set.insert(temp.clone());
        while ii < n && ii < i + 5 {
          temp = temp + &s[ii].to_string();
          set.insert(temp.clone());
          ii += 1;
        }
      }
    }
    if 5 < set.len() { break }
  }
  
  let mut result = set.into_iter().collect::<Vec<String>>();
  result.sort();
  println!("{}", result[k-1]);
}

Measured memory_bytes: 2280
"use strict";
function main(input) {
  let n=0;
  let m=0;
  [n, m] = input[0].trim().split(" ").map(i => parseInt(i));
  const a = input[1].trim().split(" ").map(i => parseInt(i));

  let total = 0;
  for(let i=0;i<m;i++){
    total += a[i];
  }
  
  console.log(((n-total)<0)?-1:(n-total));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));

Measured memory_bytes: 30688
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N];

int main()
{
	int n,k,q;
	while(cin >> n >> k >> q){
		memset(a,0,sizeof(a));
		for(int i = 1; i <= q; i++){
			int t;
			cin >> t;
			a[t]++;
		}
		for(int i = 1; i <= n; i++){
			if(a[i] - q + k > 0)
				cout << "Yes" << endl;
			else
				cout << "No" << endl;
		}
	}
	return 0;
 } 

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


int main() {
  char c;
  string smallalphabet;
  smallalphabet="abcdefghijklmnopqrstuvwxyz";
  cin >> c;
  int k;
  for (int i=0;i<smallalphabet.size();i++){
      if (smallalphabet.at(i) == c){
          k = i;break;
      }
      else{
          continue;
      }
  }
  cout <<smallalphabet.at(k+1)<<endl;
}


Measured memory_bytes: 256
package main

import (
        "fmt"
)

func main() {
        var n int
        fmt.Scan(&n)
        nums := make([]int, n)
        for i := 0; i < n; i++ {
                fmt.Scan(&nums[i])
        }
        count := 0
        for {
                hasOdd := false
                for i := 0; i < n; i++ {
                        if nums[i]%2 == 0 {
                                nums[i] = nums[i] / 2
                        } else {
                                hasOdd = true
                                break
                        }
                }
                if hasOdd {
                        break
                } else {
                        count += 1
                }
        }
        fmt.Println(count)
}

Measured memory_bytes: 512
def SumReturn(num):
    total=0
    while num!=0:
        total += num%10
        num //= 10
        
    return total

if __name__ == '__main__':
    
    n, a, b = map(int, input().split())
    
    sum = 0
    
    for i in range(1, n+1):
        
        if SumReturn(i)>=a and SumReturn(i)<=b:
            sum += i
            
    print(sum)

Measured memory_bytes: 9008
from numpy import*;B=searchsorted;a,b=loadtxt(open(0),'i',skiprows=1);c=0;l=1<<29
while l:h,l=l,l>>1;y=sort(hstack((b%h-h,b%h)));c+=sum(B(y,h-a%h)-B(y,l-a%h))%2*l
print(c)


Measured memory_bytes: 64160
import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
//class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
        BufferedReader stdReader =
            new BufferedReader(new InputStreamReader(System.in));
        String[] nums = stdReader.readLine().split(" ");
         
        int[] a = {Integer.parseInt(nums[0]), Integer.parseInt(nums[1]), Integer.parseInt(nums[2])};
        
        Arrays.sort(a);
        System.out.println(a[0] + " " + a[1] + " " + a[2]);
	}
}

Measured memory_bytes: 16964
#include <bits/stdc++.h>
#define ll long long
#define all(x) x.begin(),x.end()
#define TESTCASES 0

using namespace std;

string s;

int Go(){

  cin >> s;

  bool is = 0;
  for(auto c : s) is |= (c == '7');

  puts(is ? "Yes" : "No");

  return 0;
}


int main(){

  int t;
  if(TESTCASES) scanf("%d",&t); 
  else          t = 1;
  
  while(t--) Go();
} 

Measured memory_bytes: 3580