akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath> 
#include <cstdlib> // abs(int), labs(long int), llabs(llint)

#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define ll long long

using namespace std;

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

    int temp_count = 0;
    int ans = 0;
    for(int i = 0;i < s.size();i++){
        switch(s[i]){
            case 'A':
            case 'C':
            case 'G':
            case 'T':
                temp_count++;
            break;

            default:
                ans = max(ans,temp_count);
                temp_count = 0;
            break;
        }
    }

    ans = max(ans,temp_count);

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

Measured memory_bytes: 256
#include <stdio.h>
using lli = long long int;
#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define REP(i, n) FOR(i, 0, n)
int main(void){
    lli r, d, x; scanf("%lld%lld%lld", &r, &d, &x);
    REP(i, 10){
        (x *= r) -= d; printf("%lld\n", x);
    }
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
class Case04

  def initialize
  end

  def show
    p self.instance_variables
        .map{ |sym| [sym, self.instance_variable_get(sym)] }
        .to_h
  end

  def gcd(x,y)
    if x < y then
      x, y = y, x
    end
    r = x % y
    while r != 0 do
      x = y
      y = r
      r = x % y
    end
    y 
  end

  def prime_dev(x)
    @d = []
    2.upto(Math.sqrt(x).to_i + 1) do |p|
        q = 0
      while x % p == 0 do
        q += 1
        x = x / p
      end
      @d << q if q > 0
    end
    @d << 1 if x > 1
    @d.length + 1
  end
  
  # 実行する
  def execute
    read
    solve
    output
  end

  # 読込
  def read
    @a, @b  = gets.chomp.split.map(&:to_i)
  end

  # 回答
  def solve
    @g = gcd(@a, @b)
    @result = prime_dev(@g)
  end
  
  # 出力
  def output
    puts @result
  end

end

Case04.new.execute if $0 == __FILE__



Measured memory_bytes: 3836
//2019.12.22
//s1270188 xxxmk2
//alds1_06a

#include<stdio.h>
#include<stdlib.h>

#define N 10001

int main(){
  int *A, *B, C[N], num;
  int i;
  
  //clear CNT
  for(i=0;i<N;i++) C[i]=0;

  //input
  scanf("%d",&num);
  A=(int *)malloc(sizeof(int)*num);
  B=(int *)malloc(sizeof(int)*num);
  for(i=0;i<num;i++) {
    scanf("%d",&A[i]);
    C[A[i]]++;
  }

  //C
  for(i=1;i<N;i++) C[i]+=C[i-1];

  //B
  for(i=num-1;i>=0;i--){
    B[C[A[i]]-1]=A[i];
    C[A[i]]--;
  }


  //output
  for(i=0;i<num-1;i++) printf("%d ",B[i]);
  printf("%d\n",B[i]);
  
  free(A);
  free(B);
  return 0;
}




Measured memory_bytes: 17068
import sys
import fractions
import math
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

H, A = IL()
print(math.ceil(H/A))

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

int main(){
	char ip;
	cin >>ip;
	if( ip == 'A' )
		cout <<"T\n";
	else if( ip == 'T' )
		cout <<"A\n";
	else if( ip == 'C' )
		cout <<"G\n";
	else 
		cout <<"C\n";
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <iostream>
using namespace std;

int main(){
        int N;
        int a[100000]={0};
        int result2=0;
        int result=0;


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

        for(int i=0;i<N;i++){
                if(a[a[i]]==i){
                        result2++;
                }
        }
        result=result2/2;


        cout << result << endl;
        return 0;
}


Measured memory_bytes: 1272
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;

int main()
{
  int A;
  int B;
  cin>>A>>B;
  if(A<=9)
  {
    if(B<=9)
    {
      cout<<A*B<<endl;
    }
    else
    {
      cout<<"-1"<<endl;
    }
  }
  else
  {
    cout<<"-1"<<endl;
  }

return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace Problem0002
{
    class Program
    {
        static void Main(string[] args)
        {
            var sums =
                GetInputLines()
                .Select(line => line.Split().Select(word => int.Parse(word)).Sum());
            var lengths = sums.Select(sum => sum.ToString().Length);
            foreach (int length in lengths)
            {
                Console.WriteLine(length);
            }
        }

        static IEnumerable<string> GetInputLines()
        {
            string line;
            while (!string.IsNullOrEmpty(line = System.Console.ReadLine()))
            {
                yield return line;
            }
        }
    }
}

Measured memory_bytes: 9592
#include <bits/stdc++.h>
//#define DEBUG
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
template <class T>
void print_vect(std::vector<T> v){
    for(int i = 0 ; i < v .size(); i++) cout << v[i] << " ";
    cout << endl;
}

void solve(){
    int n; 
    cin >> n;
    vi d(n);
    for(int i = 0 ; i < n ; i++){
        cin >> d[i];
    }
    sort(d.begin(), d.end());
    int lb = d[(n-1)/2] + 1;
    int rb = d[n/2];
    int ans = rb - lb + 1;
    cout << ans << endl;
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    #ifdef DEBUG
    int TEST_CASES = 2;
    while(TEST_CASES--){
    #endif // DEBBUG

    solve();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}

//My mistake:
// I did not read the problem properly
// I can start from anywhere
// Hence, optimal path should have only one direction!!!!
//Again, this is C. So I should expect it to have a simple solution

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

int main()
{
  int a,b,c,d,e,f;
  int i=0;
  
  cin>>a>>b>>c;
  
  if(a%2==0&&b%2==0&&c%2==0)
  {
  if(!(a==b)&&!(b==c)&&!(c==a))
  {
  	while(1)
  	{
    	d=(b/2)+(c/2);
    	e=(c/2)+(a/2);
    	f=(a/2)+(b/2);
    
    	a=d;
   	    b=e;
    	c=f;
        i++;
    
    	if(!(a%2==0))
        {
          break;
        }
          	if(!(b%2==0))
        {
          break;
        }
          	if(!(c%2==0))
        {
          break;
        }
  	}
  }
  else
  {
    i=-1;
  }
  }
  else
  {
    i=0;
  }
  
  cout<<i<<endl;
  
  return 0;
}

Measured memory_bytes: 256
import pdb

def eat(n, x):
    ret = 0

    if x == 0:
        return 0, x

    if n == 0:
        x -= 1
        return 1, x

    if allnum[n] <= x:
        x -= allnum[n]
        return pnum[n], x
        
    # eat bread
    x -= 1 
    if x == 0:
        return 0, x

    # eat n-1 beager
    tmp, x = eat(n - 1, x)
    ret += tmp
    if x == 0:
        return ret, x

    # eat patty
    x -= 1
    ret += 1
    if x == 0:
        return ret, x

    # eat n-1 beager
    tmp, x = eat(n - 1, x)
    ret += tmp
    if x == 0:
        return ret, x

    # eat bread
    x -= 1 
        
    return ret, x


def main():
    tmp = input().split()
    n = int(tmp[0])
    x = int(tmp[1])
    global pnum
    global allnum
    pnum = [1]
    allnum = [1]
    for i  in range(1, 51):
        pnum.append(pnum[i-1] * 2 + 1)
        allnum.append(allnum[i-1] * 2 + 3)

    ans, tmp = eat(n, x)

    print(ans)

        
if __name__ == '__main__':
    main()


Measured memory_bytes: 5768
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;
char a[1000] , b[1000];
int main()
{
	while(~scanf("%s%s" , a + 1 , b + 1)){
		int len_a = strlen(a + 1);
		int len_b = strlen(b + 1);
		if(len_a > len_b) printf("GREATER\n");
		else if(len_a < len_b) printf("LESS\n");
		else if(len_a == len_b){
			bool ok = 0;
			for(int i = 1;i <= len_a;i++){
				if(a[i] > b[i]){
					ok = 1;
					printf("GREATER\n");
				}
				else if(a[i] < b[i]){
					ok = 1;
					printf("LESS\n");
				}
				if(ok) break;
			}
			if(!ok) printf("EQUAL\n");
		}
	}
}

Measured memory_bytes: 256
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

def main():
    A, B = MI()
    x = 10 * B
    for i in range(x, x + 10):
        y = int(i * 8 / 100)
        if y == A:
            print(i)
            exit()
    print(-1)
if __name__ == "__main__":
    main()


Measured memory_bytes: 74480
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

// combination(a,b)が奇数か判定
bool comb(int a, int b) {
	int dis = a - b;
	ll cnt0 = 0;
	while (a) {
		cnt0 += a / 2; a >>= 1;
	}
	ll cnt1 = 0;
	while (b) {
		cnt1 += b / 2; b >>= 1;
	}
	while (dis) {
		cnt1 += dis / 2; dis >>= 1;
	}
	return cnt0 <= cnt1;
}

int solve(string a) {
	int N = a.length();
	if (N == 2) {
		return abs((a[0] - '0') - (a[1] - '0'));
	}
	// 答えが1かどうか判定する
	int f = 0;
	for (int i = 0; i < N; ++i)
		if (comb(N - 1, i))
			f ^= (a[i] == '1' ? 1 : 0);
	if (f) return 1;
	// 答えが2かどうか判定する
	for (int i = 0; i < N; ++i)
		if (a[i] == '1')
			return 0;
	for (int i = 0; i < N; ++i) {
		a[i] = (a[i] == '2' ? '1' : '0');
	}
	f = 0;
	for (int i = 0; i < N; ++i)
		if (comb(N - 1, i))
			f ^= (a[i] == '1' ? 1 : 0);
	if (f) return 2;
	return 0;
}

int main() {
	int N; cin >> N;
	string a; cin >> a;
	for (int i = 0; i < N; ++i)
		a[i] = (char)(a[i] - 1);
	cout << solve(a) << endl;
	return 0;
}

Measured memory_bytes: 2308
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
 int a, b, c;
 cin >> a;
 
int s = a % 60;
int m = a / 60 % 60;
int h = a / 3600 % 60;
cout << h << ":" << m << ":" << s << endl;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

template <ll Mod>
struct ModInt {
  ll n;
  ModInt(const ll x = 0) : n(x) { while (n < 0) n += Mod; n %= Mod; }
  ModInt operator+(const ModInt r) const { return ModInt(*this) += r; }
  ModInt operator-(const ModInt r) const { return ModInt(*this) -= r; }
  ModInt operator*(const ModInt r) const { return ModInt(*this) *= r; }
  ModInt operator/(const ModInt r) const { return ModInt(*this) /= r; }
  ModInt &operator+=(const ModInt r) { n += r.n; if (n >= Mod) n -= Mod; return *this; }
  ModInt &operator-=(const ModInt r) { if (n < r.n) n += Mod; n -= r.n; return *this; }
  ModInt &operator*=(const ModInt r) { n = n * r.n % Mod; return *this; }
  ModInt &operator/=(const ModInt r) { return *this *= r.inv(); }
  ModInt pow(ll x) const { ModInt<Mod> ret(1), tmp(*this); while (x) { if (x&1) ret *= tmp; tmp *= tmp; x >>= 1; } return ret; }
  ModInt inv() const { return pow(Mod-2); }
  friend ostream& operator<<(ostream& os, const ModInt& obj) { return os << obj.n; }
  friend istream& operator>>(istream& is, ModInt& obj) { ll t; is >> t; obj = ModInt(t); return is; }
};
constexpr ll mod = 1000000007;
using mint = ModInt<mod>;
mint operator"" _mi(unsigned long long n) { return mint(n); }

ll dfs(ll now, ll p, const vector<vl>& g, vl &size) {
  ll cnt = 1;
  for (auto&& i : g[now]) {
    if (i != p) {
      cnt += dfs(i, now, g, size);
    }
  }
  return size[now] = cnt;
}

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

  ll n;
  cin >> n;
  vector<vl> g(n);
  rep(i, n-1) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  // size[i] := 頂点iを根とする部分木の頂点数
  vl size(n);
  dfs(0, 0, g, size);

  mint ans(0);
  rep(i, n) {
    mint cnt(0);

    for (auto&& j : g[i]) {
      ll t;
      if (size[j] < size[i]) t = size[j];
      else t = size[0]-size[i];
      cnt += (2_mi).pow(t)-1;
    }

    ans += (2_mi).pow(n-1)-(cnt+1_mi);
  }

  ans /= (2_mi).pow(n);
  cout << ans << endl;
}


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

int main() {
    
  while(true){
    int H,W;
    cin >> H >>W;
    
    if(H==0 && W==0) break;
    
    for(int i= 0; i < H; i++){
      for(int j=0; j < W; j++){
        if(i%2==0){
          if(j%2==0) cout << "#";
          else cout << ".";
        }else{
          if(j%2==0) cout << ".";
          else cout << "#";
        }
      }
      cout << endl;
    }
    cout << endl;
  }
  
}


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

public class Main {
	private Scanner sc;
	
	public static void main(String[] args) {
		new Main();
	}
	
	public Main() {
		sc = new Scanner(System.in);

		while (sc.hasNextLine() == true) {
			int nico = Integer.parseInt(sc.nextLine());
			long ans = 1;
			
			for (int i = 0; i < nico; i++) {
				ans = ans * (i + 1);
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 25948
using System;
using System.Collections.Generic;

namespace B___Buffet
{
    class Program
    {
        static void Main (string[] args)
        {
            var n = int.Parse (Console.ReadLine ());
            var input = Console.ReadLine ().Split (' ');
            var input1 = Console.ReadLine ().Split (' ');
            var a = new List<int> ();
            var b = new List<int> ();
            var ans = 0;
            for (var i = 0; i < n; i++)
            {
                a.Add (int.Parse (input[i]));
                b.Add (int.Parse (input1[i]));
                ans += b[i];
            }
            input = Console.ReadLine ().Split (' ');
            var c = new List<int> ();
            for (var i = 0; i < n - 1; i++)
            {
                c.Add (int.Parse (input[i]));
            }
            for (var i = 1; i < n; i++)
            {
                if (a[i] == a[i - 1] + 1)
                {
                    ans += c[a[i - 1] - 1];
                }
            }
            Console.WriteLine (ans);
        }
    }
}

Measured memory_bytes: 13140
# import sys
# import math
# import decimal
# import queue
# import bisect
# import heapq # priolity-queue
# import time
# import itertools
# import collections # queue
# from operator import itemgetter
# from fractions import Fraction

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def main():
    n,m = map(int,input().split())
    ans = n*(n-1)//2
    ans += m*(m-1)//2
    print(ans)
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 3316
import itertools
n, m, x = map(int, input().split())
b = [list(map(int, input().split())) for _ in range(n)]
ans = float("inf")
for s in itertools.product([True, False], repeat=n):
    c = 0
    t = [0]*m
    for i in range(n):
        if s[i]:
            c += b[i][0]
            for j in range(m):
                t[j] += b[i][j+1]
    for j in range(m):
        if t[j] < x:
            break
    else:
        ans = min(c, ans)
if ans == float("inf"):
    ans = -1
print(ans)

Measured memory_bytes: 9256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long res = 1;
        for (long i = 1; i <= n; i++) {
            res *= i;
            res %= 1000000007;
        }
        System.out.println(res);
    }
}

Measured memory_bytes: 23124
int main() {
    int S;
    scanf("%d", &S);
    int h, M, m, s;
    h = S / (60 * 60);
    M = S % (60 * 60);
    m = M / 60;
    s = M % 60;
    printf("%d:%d:%d\n", h, m, s);
    return 0;
}


Measured memory_bytes: 2108
#include <iostream>
#include <string.h>
using namespace std;

int main(){
  int n;
  int cnt=1;
  int yakusu;
  cin >> n;
  if(n<105){
    cout << 0 << endl;
  }else{
    for(int i=107;i<=n;i+=2){
      yakusu=0;
      for(int j=1;j<=i;j++){
        if(i%j==0){
          yakusu++;
        }
      }
      if(yakusu==8){
        cnt++;
      }
    }
    cout << cnt << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef pair<int,int> P;
typedef long long ll;

int main(void){
    int a,b;
    cin>>a>>b;
    if(a>=13)cout<<b<<endl;
    else{
        if(a<=5)cout<<0<<endl;
        else cout<<b/2<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム（標準入力変更用）
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define in(x1) cin >> x1
#define in2(x1, x2) cin >> x1 >> x2
#define in3(x1, x2, x3) cin >> x1 >> x2 >> x3
#define inN(x, N) rep(i, N) in(x[i])
#define outl(x) cout << x << endl
#define out2l(x, y) cout << x << " " << y << endl 

//よく使う関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());

    int N, M;
    in2(N, M);

    vvll A(N);

    map<int, int> counts;
    rep(i, N)
    {
        int k;
        in(k);

        rep(j, k)
        {
            int a;
            in(a);

            counts[a]++;
        }
    }

    int ans = 0;

    for (auto c : counts)
    {
        if (c.second == N) ans++;
    }
    
    outl(ans);

    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int a, b;
    cin >> a >> b;

    vvi grid(100, vi(100, 0));
    for (int i = 50; i < 100; ++i) {
        rep(j, 100) grid[i][j] = 1;
    }
    a--; b--;
    for (int i = 0; i < 50; i += 2) {
        bool flag = false;
        rep(j, 100) {
            if (!a) {
                flag = true;
                break;
            }
            if (j % 2 == 0) {
                a--;
                grid[i][j] = 1;
            }
        }
        if (flag) break;
    }
    for (int i = 99; i >= 50; i -= 2) {
        bool flag = false;
        rep(j, 100) {
            if (!b) {
                flag = true;
                break;
            }
            if (j % 2 == 0) {
                b--;
                grid[i][j] = 0;
            }
        }
        if (flag) break;
    }
    cout << "100 100" << endl;
    rep(i, 100) rep(j, 100) {
        cout << (grid[i][j] ? '.' : '#');
        if (j == 99) cout << '\n';
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define max(a, b) (a > b? a : b);

long long row[300000], col[300000], point[300000];

int binary_search(long long target, long long array[], long long n)
{
    long long fn = 0, bn = n - 1, tmp;
    while (fn <= bn)
    {
        tmp = (fn + bn) / 2;
        if (array[tmp] < target) {fn = tmp + 1;} else if (array[tmp] > target) {bn = tmp - 1;} else {return tmp;}
    }
    return fn;
}

int compare(const void *a, const void *b) {return *(long long*)a > *(long long*)b ? 1 : (*(long long*)a == *(long long*)b ? 0 : -1);}

int main(void)
{
    long long H, W, M;
    scanf("%lld %lld %lld", &H, &W, &M);
    long long maxRow = 0, maxCol = 0;

    for (long long i = 0; i < M; i++)
    {
        long long a, b;
        scanf("%lld %lld", &a, &b);
        row[a - 1]++;
        col[b - 1]++;

        if (row[a - 1] > maxRow)
            maxRow = row[a - 1];
        if (col[b - 1] > maxCol)
            maxCol = col[b - 1];

        point[i] = a * W + b;
    }

    long long r = maxRow + maxCol - 1;

    long long numRow = 0, numCol = 0;
    long long indexRow[M], indexCol[M];
    for (long long i = 0; i < H; i++)
    {
        if (row[i] == maxRow)
        {
            indexRow[numRow++] = i;
        }
    }

    for (long long i = 0; i < W; i++)
    {
        if (col[i] == maxCol)
        {
            indexCol[numCol++] = i;
        }
    }

    if (numRow*numCol>M) {printf("%lld", r+1); return 0;}
    qsort(point, M, sizeof(long long), compare);

    for (long long i = 0; i < numRow; i++)
    {
        for (long long j = 0; j < numCol; j++)
        {
            long long key = (indexRow[i]+1)*W+indexCol[j]+1;
            if (point[binary_search(key, point, M)] != key)
            {
                printf("%lld", r + 1);
                return 0;
            }
        }
    }

    printf("%lld", r);
    return 0;
}


Measured memory_bytes: 13388
#include<iostream>
#define NMAX 500000
#define SENTINEL 2000000000
using namespace std;

int c=0;

void merge(int a[],int n,int first,int mid,int last){
    int F[NMAX+1],L[NMAX+1];
    int nf=mid-first;
    int nl=last-mid;
    for(int i=0;i<nf;i++) F[i]=a[first+i];
    for(int i=0;i<nl;i++) L[i]=a[mid+i];
    F[nf]=L[nl]=SENTINEL;
    int i=0,j=0;
    for(int k=first;k<last;k++){
        if(F[i]<=L[j]) a[k]=F[i++];
        else a[k]=L[j++];
        c++;
    }
}

void mergeSort(int a[],int n,int first,int last){
    if(last-first>1){
        int mid=(first+last)/2;
        mergeSort(a,n,first,mid);
        mergeSort(a,n,mid,last);
        merge(a,n,first,mid,last);
    }
}

int main(){
    int n,a[NMAX];
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    mergeSort(a,n,0,n);
    for(int i=0;i<n;i++){
        cout<<a[i]<<((i==n-1)?'\n':' ');
    }
    cout<<c<<endl;
}


Measured memory_bytes: 6912
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();

        int[] a = new int[m];
        int[] b = new int[m];

        for (int i = 0; i < m; i++) {
            a[i] = sc.nextInt() - 1;
            b[i] = sc.nextInt() - 1;
        }

        sc.close();

        long[] ans = new long[m];
        ans[m - 1] = (long) n * (n - 1) / 2;

        UnionFind uni = new UnionFind(n);

        for (int i = m - 1; i > 0; i--) {
            ans[i - 1] = ans[i];

            if (uni.root(a[i]) != uni.root(b[i])) {
                ans[i - 1] -= uni.size(a[i]) * uni.size(b[i]);
                uni.unite(a[i], b[i]);
            }
        }
        for (int i = 0; i < m; i++) {
            System.out.println(ans[i]);
        }
    }

    static class UnionFind {
        List<Integer> par;

        // 初期化
        UnionFind(int n) {
            par = new ArrayList<Integer>();
            Integer[] values = new Integer[n];
            Arrays.fill(values, -1);
            par.addAll(Arrays.asList(values));
        }

        // 根を求める
        int root(int x) {
            if (par.get(x) < 0) {
                return x;
            }
            int root = root(par.get(x));
            par.set(x, root);
            return root;
        }

        int size(int x) {
            return -par.get(root(x));
        }

        // 同じ根をもつか判定
        boolean same(int x, int y) {
            return root(x) == root(y);
        }

        // 併合
        boolean unite(int x, int y) {
            x = root(x);
            y = root(y);
            if (x == y) {
                return false;
            }

            if (size(x) < size(y)) {
                int temp = x;
                x = y;
                y = temp;
            }

            par.set(x, par.get(x) + par.get(y));
            par.set(y, x);

            return true;
        }
    }
}

Measured memory_bytes: 108056
#include <iostream>
#include <string>
#include <vector>
# define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;


int main() {
    int nx, ny;
    vector<int> dxs = {0, 1, 1, 1, 0, -1, -1, -1};
    vector<int> dys = {1, 1, 0, -1, -1, -1, 0, 1};

    int h, w; cin >> h >> w;
    vector<string> grid(h);
    rep (i, h) cin >> grid[i];

    vector<vector<int>> ans(h);
    rep (i, h) {
        ans[i].resize(w);
        fill(ans[i].begin(), ans[i].end(), 0);
    }

    rep (i, h) {
        rep (j, w) {
            rep (k, 8) {
                nx = i + dxs[k];
                ny = j + dys[k];
                if (nx < 0 or ny < 0) continue;
                if (h <= nx or w <= ny) continue;
                if (grid[nx][ny] == '#') {
                    ans[i][j]++;
                }
            }
        }
    }

    rep (i, h) {
        rep (j, w) {
            if (grid[i][j] == '#') {
                cout << '#';
            }
            else {
                cout << ans[i][j];
            }
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define mod 1000000007


int main() {
    int N; cin >> N;
    map<int, int> M;
    int f = 0;
    for(int i=0; i<N; i++){
        int r; cin >> r;
        if(r<400) M[0]++;
        else if(r<800) M[1]++;
        else if(r<1200) M[2]++;
        else if(r<1600) M[3]++;
        else if(r<2000) M[4]++;
        else if(r<2400) M[5]++;
        else if(r<2800) M[6]++;
        else if(r<3200) M[7]++;
        else f++;
    }
    
    int c = 0;
    for(auto m:M)
        c++;
    if(c==0){
        c++;
        f--;
    }
    cout << c << " " << c+f << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(){
    int A[3],R[3],i,smallest;

    scanf("%d%d%d",&A[0],&A[1],&A[2]);

    R[0]=abs(A[0]-A[1])+abs(A[0]-A[2]);
    R[1]=abs(A[1]-A[0])+abs(A[1]-A[2]);
    R[2]=abs(A[2]-A[0])+abs(A[2]-A[1]);

    for(i=0;i<3;i++){
        if(i==0)
            smallest=R[i];
        else{
            if(smallest>R[i])
                smallest=R[i];
        }
    }
    printf("%d\n",smallest);

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
const double eps = 1e-8;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T> ostream& operator << (ostream& os, const set<T>& s) { for (auto si : s) os << si << " "; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { (a += (b % mod + mod)) %= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12); // debuged
    int T;
    T = 1;
    while (T--) solve();
}

void solve() {
    int k, x;
    cin >> k >> x;
    if (500 * k >= x) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int cnt_digits(long long N) {
  int digits = 0;

  while (N > 0) {
    digits++;
    N /= 10;
  }

  return digits;
}

int F(long long A, long long B) { return max(cnt_digits(A), cnt_digits(B)); }

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

  int ans = cnt_digits(N);

  for (long long A = 1; A * A <= N; A++) {
    if (N % A != 0) continue;

    long long B = N / A;
    ans = min(ans, max(cnt_digits(A), cnt_digits(B)));
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
from _collections import deque
n,m,k=map(int,input().split())
import sys
sys.setrecursionlimit(10**9) #再帰の上限をあげる

fre=[[] for _ in range(n+1)]
bro=[[] for _ in range(n+1)]

for i in range(m):
    a,b=map(int,input().split())
    fre[a].append(b)
    fre[b].append(a)

for i in range(k):
    a, b = map(int, input().split())
    bro[a].append(b)
    bro[b].append(a)

ans=[]

x=[-1]*(n+1)

def s(z,y):
    if x[y]>0:
        return
    x[y]=z
    for i in fre[y]:
        if x[i]==-1:
            s(z,i)

for i in range(1,n+1):
    s(i,i)

g=[0]*(n+1)
for i in range(1,n+1):
    g[x[i]]+=1
for i in range(1,n+1):
    g[i]=g[x[i]]

for i in range(1,n+1):
    aa=g[i]-1
    aa-=len(fre[i])
    for j in bro[i]:
        if x[i]==x[j]:
            aa-=1
    ans.append(str(aa))
print(" ".join(ans))



Measured memory_bytes: 380220
import java.util.*;
public class Main{

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int z = sc.nextInt();
        int people = 1;
        int now = y+2*z;

        while(now+y+z<=x){
            people++;
            now+=(y+z);
            //System.out.println(now);
        }

        System.out.println(people);

    }
}



Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<algorithm> // sort
#include<map> // pair
#include<cmath>
#include<cstring>
#include<set>
using namespace std;
using ll = long long;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
const ll mod = 1e9+7;
const int INF = 1e9;
const ll INFLONG = 1e18;
int main(){
  ll n;
  cin >> n;
  ll a[n];
  rep(i,n){
    cin >> a[i];
  }
  ll sum = 0;
  rep(i,n){
    if(a[i] != i+1){
      sum ++;
    }
  }
  if(sum == 2 || sum == 0){
    cout << "YES";
  }else{
    cout << "NO";
  }
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if((x-r)>=0 && (x+r)<=W){
		if((y-r)>=0 && (y+r)<=H){
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 584
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll A, B, C;

    cin >> A >> B >> C;

    map<ll, ll> mp;
    mp[A]++;
    mp[B]++;
    mp[C]++;

    cout << mp.size() << endl;

    // if(ans){
    //     cout << "Yes" << endl;
    // }else{
    //     cout << "No" << endl;
    // }

}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<cstdlib>
#include<stack>
#include<queue>
#include<algorithm>
#include<set>
#include<vector>
#include<cmath>
#include<string>
#include<bitset>
#define lmid l,mid,rt<<1
#define rmid mid+1,r,rt<<1|1
#define ll long long
using namespace std;
int main()
{
     int n,a,b;
     scanf("%d%d%d",&n,&a,&b);
     if(n*a<=b){printf("%d\n",n*a);}
     else printf("%d\n",b);
     return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	string a;
	cin>>a;
	string b;
	for(int i=0;i<a.length();i++){
		if(a[i]=='C') b[0]=a[i];
		else if((b[0]=='C')&&(a[i]=='F')) b[1]=a[i];
		else continue;
	}
	if((b[0]=='C')&&(b[1]=='F')) cout<<"Yes";
	else cout<<"No";
	return 0;
}

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

int main(void){
    int cnt[10001] = {};
    int N, sum;
    cin >> N;

    for(int i= 1; i < 100; i++){
        for(int j = 1; j < 100; j++){
            for(int k = 1; k < 100; k++){
                sum = (i + j + k) * (i + j + k) - i * (j + k) - j * k;
                if(sum <= 10000) cnt[sum]++;
            }
        }
    }
    for(int i = 1; i <= N; i++){
        cout << cnt[i] << endl;
    }    
    
    return 0;
}


Measured memory_bytes: 3608
#include <stdio.h>
#include <iostream>

using namespace std;

const int INDEFINITE = -1;

template<class T> inline T pow(T base, T exponent) {
    if (exponent == 0) return 1;

    if (exponent % 2 == 1) {
        return base * pow(base, exponent - 1);
    } else {
        T tmp = pow(base, exponent / 2);
        return tmp * tmp;
    }
}

int dp(int N, int m[]) {
    if (m[N] != INDEFINITE) {
        return m[N];
    }

    if (6 > N) {
        m[N] = N;
    } else {
        for (int i = 6; i <= N; i *= 6) {
            if (m[N] != INDEFINITE) {
                m[N] = min(m[N], dp(N - i, m) + 1);
            } else {
                m[N] = min(N, dp(N - i, m) + 1);
            }
        }
        for (int i = 9; i <= N; i *= 9) {
            if (m[N] != INDEFINITE) {
                m[N] = min(m[N], dp(N - i, m) + 1);
            } else {
                m[N] = min(N, dp(N - i, m) + 1);
            }
        }
    }

    return m[N];
}

int main() {
    int N; cin >> N;
    int m[N + 1];
    for (int i = 0; i <= N; ++i) {
        m[i] = INDEFINITE;
    }

    cout << dp(N, m) << endl;

    return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>

int main(){
 int data[10], i, sum = 0, ave;
 for(i = 1; i <= 5; i++){
  scanf("%d", &data[i]);
 if(data[i] < 40) data[i] = 40;
 sum += data[i];
 }
 ave = sum / 5;
 printf("%d\n", ave);
 return 0;
}
 

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb emplace_back
#define mp make_pair
#define nt _ll128
#define ld long double
long double PI =3.14159265358979323846;
using ll = long long;



const ll modo=998244353;
const ll inf=1e17;
const ll ms=(2e5)+5;

vector<int> vv[ms];
ll ar[ms]={0};


void go(int i,int p,ll x)
{
    ar[i]+=x;

    for(int ii:vv[i])
    {
        if(ii!=p)
        {
            go(ii,i,ar[i]);
        }
    }
}

int main()
{
    idfc;

    int n,q;
    cin>>n>>q;
    int i;

    int u,v;

    for(i=1;i<n;i++)
    {
        cin>>u>>v;
        vv[u].pb(v);
        vv[v].pb(u);
    }
    while(q--)
    {
        cin>>u>>v;
        ar[u]+=v;
    }
    go(1,1,0);

    for(i=1;i<=n;i++)cout<<ar[i]<<" ";

    return 0;
}

Measured memory_bytes: 28580
#include <stdio.h>
int main(void){
  int X,Y,money=0;
  if(scanf("%d%d",&X,&Y)<2) return 1;
  if(X==3) money+=100000;
  else if(X==2) money+=200000;
  else if(X==1){
    if(Y==1) money+=700000;
    else money+=300000;
  }
  if(Y==3) money+=100000;
  else if(Y==2) money+=200000;
  else if(Y==1) money+=300000;
  printf("%d\n",money);
  
  return 0;
}

Measured memory_bytes: 128
N,K = map(int,input().split())
R,S,P = map(int,input().split())
dp = []
order = input()
def jcount(x):
  if x=='r':
    ans = P
  elif x=='s':
    ans = R
  else:
    ans = S
  return ans
counter = 0
for i in range(N):
  if i < K:
    counter += jcount(order[i])
    dp.append(order[i])
  elif order[i] != dp[i-K]:
    counter += jcount(order[i])
    dp.append(order[i])
  else:
    dp.append('x')
print(counter)

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

int main() {
	long long n, m = 10000000000, h = 0;
	cin >> n;
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		if(a < m){
			m = a;
		}
		if(h < a){
			h = a;
		}
	}
	cout << h - m << endl;
	return 0;
}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
 
int main(){
  //input
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  int n ; 
  cin >> n;
  ll a[n]={};
  rep(i,n) cin>>a[i];
  
  vector<int>vec;
  if(n==1) cout<<0<<endl;
  
  else{
    int sum=1;
    rep(i,n-1){
      if(a[i]>=a[i+1]) sum++;
      else{
        vec.push_back(sum);
        sum=1;
      }
      if(i==n-2) vec.push_back(sum);
    }
    sort(vec.begin(),vec.end(),greater<int>());
    cout<<vec[0]-1<<endl;
  }
  
}
  



Measured memory_bytes: 1660
#include <iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main(){
    int R[MAX],n;

    cin >> n;
    for(int i = 0; i<n;i++) cin >> R[i];

    int maxv = -2000000000; //十分小さい値を初期値に設定
    int minv = R[0];

    for(int i=1; i<n;i++){
        maxv = max(maxv,R[i] - minv);
        minv = min(minv,R[i]);
    }

    cout << maxv << endl;

    return 0;
}



Measured memory_bytes: 3892
main :: IO ()
main = do
    [_, w] <- map read . words <$> getLine :: IO [Int]
    n <- read <$> getLine :: IO Int
    as <- zip [1..] . map read . words <$> getLine :: IO [(Int, Int)]
    let ns = concatMap (\(c, n) -> replicate n c) as :: [Int]
    let ms = map (\(i, x) -> if even i then reverse x else x) 
           . zip [1..] $ f w ns
    mapM_ (putStrLn . unwords . map show) ms

f _ [] = []
f w ns = take w ns : f w (drop w ns)

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

using namespace std;

typedef long long ll;

int main(){
  ll N; cin >> N;
  vector<ll> A(N); for(ll i = 0; i < N; i++){ cin >> A[i];}
  vector<ll> X(N,0);
  for(ll i = 0; i < N; i++){
    if( i % 2 == 0){ X[0] += A[i];}
    else{ X[0] -= A[i];}}
  X[0] /= 2; 
  //X[0]決定
  for(ll i = 0; i < N - 1; i++){
    X[i+1] = A[i] - X[i];}
  
 for(ll i = 0; i < N; i++){ cout << 2 * X[i] << " " ;}
  return 0;}
      
  


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

#define pb push_back
#define ll long long
#define maxn 300005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
const ll mod = 1e9+7;

int main(){
	int n,m;
	while(cin >> n >> m){
		ll pre[n+5] = {};
		ll now = 1;
		pre[0] = 1;
		for(int i=1;i<=n;i++){
			now *= max(m-1-i,0);
			now %= mod;
			pre[i] = now;
		}
		int deg[n+5] = {};
		f1(n){
			deg[i] = -1;
		}
		deg[1] = 0;
		f(n-1){
			int add1,add2;
			cin >> add1 >> add2;
			deg[add1]++;
			deg[add2]++;
		}
		ll ans = m;
		for(int i=1;i<=deg[1];i++){
			ans *= m-i;
			ans %= mod;
		}
		fr(i,2,n+1){
			ans *= pre[deg[i]];
			ans %= mod;
		}
		cout << ans << endl;
	}

}

Measured memory_bytes: 1408
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
class Solver{
public:
    static const int MAXN=1e5+10;
    ll N,K;
    ll A[MAXN];
    inline int getBit(ll v, int i){
        return (v>>i)&1;
    }
    void solve(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        cin>>N>>K;
        for(int u=1;u<=N;u++){
            cin>>A[u];
        }
        ll t=0;
        for(int b=62;b>=0;b--){
            int cnt1=0;
            for(int u=1;u<=N;u++){
                cnt1+=getBit(A[u],b);
            }
            if(cnt1<N-cnt1){
                if((t|((1ll)<<b))<=K)
                    t=t|((1ll)<<b);
            }
        }
        ll ans=0;
        for(int u=1;u<=N;u++){
            ans+=A[u]^t;
        }
        cout<<ans;
    }
};
int main()
{
    // freopen("in.txt","r",stdin);
    (new Solver())->solve();
}


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, A, B, C, D, E;
    cin >> N >> A >> B >> C >> D >> E;
    ll mn = std::min({A, B, C, D, E});
    ll ans = 5LL + (N - 1) / mn;
    cout << ans << endl;
    return 0;
}

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

int main()
{
  string s;
  cin >> s;
  int K;
  cin >> K;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == 'a') continue;
    if('z'-s[i]+1 <= K){
      K -= 'z'-s[i]+1;
        s[i] = 'a';
    }
  }
  if(K >= 26) K %= 26;
  s[s.size()-1] += K;
  cout << s << endl;
}

Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
using namespace std;
int n,sum,num[15],maxx;
template<typename I>inline void read(I&ot){
	I ch=getchar(), x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();}
	while(ch>='0' && ch<='9'){x=10*x+ch-'0'; ch=getchar();}
	ot=x*f;}
template<typename I,typename... U>inline void read(I&x,U&... y){read(x); read(y...);}
template<typename I>inline I mx(const I&a,const I&b){return a>b ? a : b;}
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n);
	for(int i=1;i<=n;i++)
	{
		read(num[i]);
		maxx=mx(maxx,num[i]);
		sum+=num[i];
	}
	printf("%d\n",sum-maxx/2);
//	fclose(stdin); fclose(stdout);
	return 0;
}


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

int main() {
    int N, cnt = 0;
    cin >> N;
    vector<int> d(N);

    for (int i = 0; i < N; i++) {
        cin >> d.at(i);
    }

    sort(d.begin(), d.end());
    reverse(d.begin(), d.end());

    for (int i = 0; i < N; i++) {
        if (i != 0 && d.at(i) == d.at(i-1)) {
            continue;
        }
        
        else {
            cnt++;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int n;
  string s;
  cin>>n>>s;
  int dp[n];
  for(int x=0;x<2;x++){
    dp[0]=x;
    for(int y=0;y<2;y++){
      dp[1]=y;
      for(int i=1;i<n-1;i++){
	if(s[i]=='o'){
	  if(dp[i]) dp[i+1]=dp[i-1];
	  else dp[i+1]=!dp[i-1];
	}else{
	  if(dp[i]) dp[i+1]=!dp[i-1];
	  else dp[i+1]=dp[i-1];
	}
      }
      bool f=1;
      for(int i=1;i<n+1;i++){
	if(s[i%n]=='o'){
	  if(dp[i%n]) f&=dp[(i+1)%n]==dp[(i-1)%n];
	  else f&=dp[(i+1)%n]!=dp[(i-1)%n];
	}else{
	  if(dp[i%n]) f&=dp[(i+1)%n]!=dp[(i-1)%n];
	  else f&=dp[(i+1)%n]==dp[(i-1)%n];
	}
      }
      if(f){
	for(int i=0;i<n;i++) cout<<(dp[i]?'S':'W');
	cout<<endl;
	return 0;
      }
    }
  }
  cout<<-1<<endl;
  return 0;
}


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

using namespace std;

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

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

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

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int red[252521], white[252521];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int n;
  string c;
  cin>>n>>c;
  REP(i, n){
    red[i+1]=red[i];
    white[i+1]=white[i];
    if(c[i]=='R'){
      ++red[i+1];
    }
    else{
      ++white[i+1];
    }
  }
  int ans=1e8;
  REP(i, n+1){
    CHMIN(ans, max(white[i], red[n]-red[i]));
    // DEBUG(max(white[i], red[n]-red[i]));
  }
  cout<<ans<<'\n';
  return 0;
}


Measured memory_bytes: 5360
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

int main()
{
	ll n;
	cin >> n;
	ll ar[n];
	for(ll i = 0; i < n; i++)
		cin >> ar[i];
	bool ok = true;
	for(ll i = 0; i < n - 1; i++)
	{
		if(ar[i + 1] < ar[i])
		{
			ok = false;
			break;
		}
	}
	if(ok)
	{
		puts("YES");
		exit(0);
	}
	for(ll i = 0; i < n; i++)
	{
		for(ll j = i + 1; j < n; j++)
		{
			ll br[n];
			for(ll k = 0; k < n; k++)
				br[k] = ar[k];
			swap(br[i], br[j]);
			bool ok = true;
			for(ll k = 0; k < n - 1; k++)
			{
				if(br[k + 1] < br[k])
				{
					ok = false;
					break;
				}
			}
			if(ok)
			{
				puts("YES");
				exit(0);
			}
		}
	}
	puts("NO");
	return 0;
}

Measured memory_bytes: 256