akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
#include<array>
#include<functional>
#include<iomanip>
#include<ios>
using namespace std;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)

typedef int value_type; /* ソートするキーの型 */

value_type med3(value_type x, value_type y, value_type z)
/* x, y, z の中間値を返す */
{
    if (x < y)
        if (y < z) return y; else if (z < x) return x; else return z; else
        if (z < y) return y; else if (x < z) return x; else return z;
}

void quicksort(value_type a[], int left, int right,value_type index[])
/* クイックソート
 * a     : ソートする配列 
 * left  : ソートするデータの開始位置
 * right : ソートするデータの終了位置
 * index: index配列
 */
{
    if (left < right) {
        int i = left, j = right;
        value_type tmp, pivot = med3(a[i], a[i + (j - i) / 2], a[j]); /* (i+j)/2ではオーバーフローしてしまう */
        while (1) { /* a[] を pivot 以上と以下の集まりに分割する */
            while (a[i] < pivot) i++; /* a[i] >= pivot となる位置を検索 */
            while (pivot < a[j]) j--; /* a[j] <= pivot となる位置を検索 */
            if (i >= j) break;
            tmp = a[i]; a[i] = a[j]; a[j] = tmp; /* a[i],a[j] を交換 */
            tmp = index[i]; index[i] = index[j]; index[j] = tmp;
            i++; j--;
        }
        quicksort(a, left, i - 1,index);  /* 分割した左を再帰的にソート */
        quicksort(a, j + 1, right,index); /* 分割した右を再帰的にソート */
    }
}

bool is753(int n){
    bool x[3]={false,false,false};

    while(n>0){
        switch (n%10){
            case 3:
                x[0]=true;
                break;
            case 5:
                x[1]=true;
                break;
            case 7:
                x[2]=true;
                break;
            default:
            return false;
        }
        n/=10;
    }
    if(x[0]&& x[1]&&x[2]){
        return true;
    }else{
        return false;
    }

}

int dfs(int n,int N){
    if (n>N){
        return 0;
    }
    

    int ret;
    if(is753(n)){
        ret=1;
    }else{
        ret=0;
    }
    FOR(i,3){
        ret+=dfs(10*n + (2*i+3),N);
    }
    return ret;
}


int main(){
    int N,D,X;

    cin >> N >> D >>X;
    int consumed=0;
    int A[N];
    FOR(i,N){
        cin >>A[i];
        bool k=true;
        int dt=0;
        while(k){
            if(dt*A[i]+1 <=D){
                dt++;

            }else{
                k=false;
            }
        }
        consumed+=dt;
    }
    int ans=consumed+X;

    cout << ans;

    


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
	int n;
	cin >> n;
	vi a(n);
	rep(i, n) cin >> a[i];
	sort(all(a));
	if(a.back() - a[0] > 1) {
		cout << "No" << endl;
		return 0;
	}
	if(a.back() == a[0]) {
		if(a[0] == n - 1) cout << "Yes" << endl;
		else if(a[0]*2 > n) cout << "No" << endl;
		else cout << "Yes" << endl;
		return 0;
	}
	int minNum = upper_bound(all(a), a[0]) - a.begin();
	int maxNum = n - minNum;
	if(minNum + maxNum / 2 < a.back() || maxNum == 1 || minNum > a[0]) cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

#define DIV 1000000007

using namespace std;

long long N, M;
long long A[101];
vector<long long> odd;
vector<long long> a;
vector<long long> b;
int main(){
	cin >> N >> M;
	long long tmp = 0;
	for(int i = 0; i < M; i++){
		cin >> A[i];
		if(A[i]%2 == 1){
			tmp++;
			odd.push_back(A[i]);
		}
	}
	if(M==1){
		if(A[0]==1){
			cout << A[0] << endl;
			cout << 1 << endl;
			cout << 1 << endl;
			return 0;
		}
		cout << A[0] << endl;
		cout << 2 << endl;
		cout << A[0]-1<< " " << 1 << endl;
		return 0;
	}
	
	if(tmp > 2){
		cout << "Impossible" << endl;
		return 0;
	}

	if(tmp == 0){
		for(int i = 0; i < M; i++){
			a.push_back(A[i]);
		}
	}else if(tmp == 1){
		a.push_back(odd[0]);
		for(int i = 0; i < M; i++){
			if(A[i]%2==0){
				a.push_back(A[i]);
			}
		}
	}else{
		a.push_back(odd[0]);
		for(int i = 0; i < M; i++){
			if(A[i]%2==0){
				a.push_back(A[i]);
			}
		}
		a.push_back(odd[1]);
	}
	for(int i = 0; i < a.size(); i++){
		if(i == 0){
			if(a[0] == 1){
				continue;
			}
			b.push_back(a[0]-1);
		}else if(i == (a.size() - 1)){
			b.push_back(a[i] + 1);
		}else{
			b.push_back(a[i]);
		}
	}

	for(int i = 0; i < a.size(); i++){
		if(i != a.size() - 1){
			cout << a[i] << " ";
		}else{
			cout << a[i] << endl;
		}
	}
	cout << b.size() << endl;
	for(int i = 0; i < b.size(); i++){
		if(i != b.size() - 1){
			cout << b[i] << " ";
		}else{
			cout << b[i] << endl;
		}
	}
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdlib.h>
#include<stdio.h>
#include<vector>
#include<utility>
#include<stdbool.h>
using namespace std;
typedef long long ll;
#define N (1000000000+7)
ll num[110] = { 0 };

ll h = 0;
ll n = 0;
void check(ll x) {
	if (x <= n) {
		num[3] = 0, num[5] = 0, num[7] = 0;
		while (x >= 10) {
			num[x % 10]++;
			x /= 10;
		}
		num[x]++;
		if (num[3] >= 1 && num[5] >= 1 && num[7] >= 1) {
			h++;
		}
	}
	return;
}

void dfs(ll x){
	check(x);
	if (x < 1000000000) {
		dfs(10 * x + 3);
		dfs(10 * x + 5);
		dfs(10 * x + 7);
	}
}
int main(void) {
	cin >> n;
	dfs(0);
	cout << h << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var (
		S string
		K int
	)
	fmt.Scan(&S, &K)

	for i, s := range S {
		if rune(s) != '1' {
			fmt.Println(string(s))
			return
		}
		if i == K-1 {
			fmt.Println(string(s))
			return
		}
	}
}


Measured memory_bytes: 1772
import java.util.Scanner;
import java.util.ArrayList;

public class Main {

  static int gcd(int a, int b) {
    if (a == 0)
      return b;
    else
      return gcd(b % a, a);
  }

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String[] s = new String[n];
    int[] a = new int[n];
    int ans = 0, o = 0;
    for (int i = 0; i < n; i++) {
      s[i] = sc.next();
      a[i] = sc.nextInt();
    }
    String x = sc.next();
    for (int i = 0; i < n; i++) {
      if (o == 1)
        ans += a[i];
      if (s[i].equals(x))
        o = 1;
    }
    System.out.println(ans);
  }
}


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

int main() {
long long n;
cin>>n;
vector<pair<long long , int>> fs;
for(long long i=2;i*i<=n;i++){
int x=0;
while(n%i==0){
n/=i;
x++;
}
fs.emplace_back(i,x);
}

if(n!=1)fs.emplace_back(n,1);
  
  int ans=0;
  for(auto p:fs){
    int x=p.second;
    int b=1;
    while(b<=x){
      x-=b;
      b++;
      ans++;
    }
  }
    
    cout<<ans<<endl;


}



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

///////////////////////////////////////////
const long long int INF = 1000000000000000000LL;
using ll = long long int;
using vi = vector<int>;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
//template <class  T>T max(T x,T y){if(x>y){return x;}else{return y;}}
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return 1; } return 0; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return 1; } return 0; }
template<class T>T sqar(T x){ return x*x; }
///////////////////////////////////////////

int main(){
    ll a,b,c,k;
    ll max,ans=0;
    cin>>a;
    max=a;
    cin>>b;
    chmax(max,b);
    cin>>c;
    chmax(max,c);
    ans = a+b+c-max;
    cin>>k;
    rep(i,k){
        max *=2;
    }
    cout<<ans+max<<endl;
    return 0;
}


Measured memory_bytes: 256
while True:
    a, b = map(int, input().split())
    if a == b == 0:
        break
    n = int(input())
    block = [list(map(int, input().split())) for i in range(n)]
    dp = [[0]*(b+1) for i in range(a+1)]
    dp[1][0] = 1
    for i in range(1, a+1):
        for j in range(1, b+1):
            if not [i, j] in block:
                dp[i][j] = dp[i - 1][j] + dp[i][j - 1]
    print(dp[a][b])


Measured memory_bytes: 5604
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
    int n;
    cin>>n;
    int r;
    cin>>r;
    int minr=r;
    int maxv=-1000000005;
    
    rep(i,n-1){
        cin>>r;
        maxv=max(r-minr,maxv);
        minr=min(r,minr);
    }
    
    cout<<maxv<<endl;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define task "MAXFRAME"

#define nguyen_dz the_best
#define ll long long
#define ld long double
#define pb push_back
#define endl "\n"
#define ff first
#define ss second
#define pll pair<ll,ll>
#define YES cout <<"YES"<<endl;
#define NO cout <<"NO"<<endl;
#define Yes cout <<"Yes"<<endl;
#define No cout<<"No" <<endl;


using namespace std;
const ll  maxn= 4e6+100;

ll a[maxn];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("test.txt","r",stdin);
    if (fopen(task".INP","r"))
    {
        freopen(task".INP", "r", stdin);
        freopen(task".OUT", "w", stdout);
    }
ld a, b;
 cin>>a>>b;
 a*=b;
 cout <<(ll)(a);

}



Measured memory_bytes: 3744
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <iterator>
#include <utility>


using namespace std;

template <class T>
T convertStringToNumber(const string& str) {
	stringstream ss;
	T ret;

	ss << str;
	ss >> ret;

	return ret;
}


vector<vector<string>> inputData() {
	vector<vector<string>> data_set;

	string buffer;

	while(true){
		getline(cin, buffer);
		int n = convertStringToNumber<int>(buffer);

		if(!n)
			break;

		vector<string> temp;
		for(int i = 0; i < n; ++i) {
			getline(cin, buffer);
			temp.push_back(buffer);
		}

		data_set.push_back(temp);
	}

	return data_set;
}


vector<string> splitString(const string& str, const string& separator = " ") {
	vector<string> ret;

	std::size_t bp, ep;
	bp = ep = 0;
	while((ep = str.find_first_of(separator, bp)) != string::npos){
		if(bp != ep){
			ret.push_back(string(str.begin() + bp, str.begin() + ep));
		}
		bp = ep + 1;
	}

	if(bp <= str.size() - 1){
		ret.push_back(string(str.begin() + bp, str.end()));
	}

	return ret;
}



pair<int,int> judgeScore(int a, int b) {
	if(a > b)
		return make_pair(a+b, 0);
	else if(a < b)
		return make_pair(0, a+b);
	else
		return make_pair(a, b);
}


void doAllProcess() {
	auto data_set = inputData();

	for(int i = 0; i < data_set.size(); ++i) {
		int player1, player2;
		player1 = player2 = 0;

		for(int j = 0; j < data_set[i].size(); ++j) {
			auto score = splitString(data_set[i][j]);
			auto ret = judgeScore(convertStringToNumber<int>(score[0]),
									convertStringToNumber<int>(score[1]));
			player1 += ret.first;
			player2 += ret.second;
		}

		cout << player1 << " " << player2 << endl;
	}
}


int main() {
	doAllProcess();

	return 0;
}


Measured memory_bytes: 3932
let solve h w c =
  let s = Array.make w 0 in
  let t = Array.make w 0 in
  let r = ref 0 in
  for i = 0 to h - 1 do
    if c.(i).(0) = 0 then r := 1
  done;
  for j = 0 to w - 1 do
    if c.(0).(j) = 0 then begin
      s.(j) <- 1;
      r := 1
    end
  done;
  for i = 1 to h - 1 do
    if c.(i).(0) = 0 then t.(0) <- 1;
    for j = 1 to w - 1 do
      if c.(i).(j) = 1 then t.(j) <- 0
      else begin
        let d = if s.(j) < t.(j-1) then s.(j) else t.(j-1) in
        t.(j) <- 1 + if s.(j-1) < d then s.(j-1) else d;
        if t.(j) > !r then r := t.(j)
      end
    done;
    Array.iteri (fun i e -> s.(i) <- e) t
  done;
  !r * !r

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let read () = List.map int_of_string (split_on_char ' ' (read_line ()))

let () =
  match read () with
  | [h; w] ->
    let c = Array.make_matrix h w 0 in
    for i = 0 to h - 1 do
      let rec doit j = function
        | [] -> ()
        | x::xs ->
          c.(i).(j) <- x;
          doit (j + 1) xs in
      read () |> doit 0
    done;
    solve h w c |> Printf.printf "%d\n"
  | _ -> assert false

Measured memory_bytes: 25268
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, M: int, x: "List[int]", y: "List[int]"):
    c = [1] * (N+1)
    p = [False] * (N+1)
    p[1] = True

    for i in range(M):
        c[y[i]] += 1
        c[x[i]] -= 1

        if p[x[i]] is True:
            p[y[i]] = True
        
        if c[x[i]] == 0:
            p[x[i]] = False

    print([i for i in p if i is True].count(True))

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    x = [int()] * (M)  # type: "List[int]"
    y = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, M, x, y)

if __name__ == '__main__':
    main()


Measured memory_bytes: 13336
#include <bits/stdc++.h> //library
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //for-loop (from 0)
#define reps(i,n) for(int i = 1; i <= (int)(n); i++) //for-loop (from 1)
#define all(x) (x).begin(),(x).end() //start-to-end iteration, mainly in upper_bound, lower_bound
#define SZ(x) ((int)(x).size()) //unsigned to signed

using namespace std;
using ll = long long; //long long
ll M = 1000000000 + 7;
const ll INF = 1LL << 60;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; } //compare a,b and replace by greater
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; } //compare a,b and replace by smaller
ll qp(int a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; } //power
ll qp(int a, ll b, ll Mod = M) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%Mod; a = 1ll * a*a%Mod; } while (b >>= 1); return ans; } //power(mod)
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; } //gcd
int dx[4] = { 1,0,-1,0 }; //path
int dy[4] = { 0,1,0,-1 }; //path
ll RS(ll N, ll P, ll Mod = M) { if (P == 0)return 1; else if (P % 2 == 0) { ll sq = RS(N, P / 2, Mod); return sq*sq%Mod; } else { return N*RS(N, P - 1, Mod) % Mod; } } //power(mod)(repeat-square,fast)
ll nPr(ll n, ll r, ll Mod = M) { ll ans = 1; rep(i, r) { ans = ans * (n - i) % Mod; } return ans; } //permutation
ll nCr(ll n, ll r, ll Mod = M) { ll bunbo = 1; ll bunshi = 1; rep(i, r) { bunbo = bunbo * (i + 1) % Mod; bunshi = bunshi * (n - i) % Mod; } return bunshi * RS(bunbo, Mod - 2, Mod) % Mod; } //combination

int main(void) {
  double L; cin >> L;
  double a = L/3.0;
  cout << setprecision(20) << a*a*a << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdlib.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

int main()
{
  int x;
  int count1;
  int count2;
  
  cin>>x;
  
  count1=x/500;
  x=x%500;
  count2=x/5;
  
  cout<<count1*1000+count2*5<<endl;
  
  return 0;
}

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

#ifdef ONLINE_JUDGE
    #undef DBG
#endif

#define sz(x) ((int) (x).size())
#define forn(i, n) for (int i = 0; i < n; ++i)
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fr first
#define sc second

using ll = long long;


const int N = 15;
char s[N];

int main() {
    scanf("%s", s);
    if (strcmp(s, "Sunny") == 0) 
        printf("Cloudy\n");
    if (strcmp(s, "Cloudy") == 0) 
        printf("Rainy\n");
    if (strcmp(s, "Rainy") == 0) 
        printf("Sunny\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    string s; cin>>s;
    string pre="";
    ll q; cin>>q;
    ll hanten=0;
    rep(i,q){
        ll x; cin>>x;
        if(x==1) hanten++;
        else{
            ll f; char c; cin>>f>>c;
            if(f==1){
                if(hanten%2==0) pre=pre+c;
                else s=s+c;
            }else{
                if(hanten%2==0) s=s+c;
                else pre=pre+c;
            }
        }
    }
    reverse(pre.begin(),pre.end());
    s=pre+s;
    ll n=s.size();
    if(hanten%2==0) cout<<s<<endl;
    else{
        reverse(s.begin(),s.end());
        cout<<s<<endl;
    }
    return 0;
}

Measured memory_bytes: 1708
N,K = gets.split.map &:to_i
P = gets.split.map{_1.to_i - 1}
C = gets.split.map &:to_i


groups = []
groups_c = []
used = []
N.times do |i|
    next if used[i]
    group = []
    c = []
    until used[i]
        group << i
        c << C[i]
        used[i] = true
        i = P[i]
    end

    groups << group
    groups_c << c
end

ans = -10**10
groups.count.times.map do |gi|
    group = groups[gi]
    c = groups_c[gi]
    m = group.count
    l = K / m - 1
    sum = group.map{C[_1]}.sum
    sum = sum > 0 ? sum * l : 0

    max = -10**10 
    k1 = K % m + m
    m.times do |i|
        s = 0
        idx = i
        k1.times do 
            s += c[idx]
            idx += 1
            idx %= m if idx>=m
            max = s if s > max
        end
    end

    score = sum + max
    ans = score if score > ans
end

p ans

Measured memory_bytes: 14768
#include<stdio.h>
#include<math.h>

void print_info(int array[][10]);

int main (void)
{
	int testA,testB,testC;
	do
	{
		scanf("%d %d %d",&testA,&testB,&testC);
		if(testA == -1 && testB == -1 && testC == -1)
		{
			break;
		}
		if(testA == -1 || testB == -1)
		{
			printf("F\n");
		}
		else if(testA + testB >= 80)
		{
			printf("A\n");
		}
		else if(testA + testB >= 65)
		{
			printf("B\n");
		}
		else if(testA + testB >= 50)
		{
			printf("C\n");
		}
		else if(testA + testB >= 30)
		{
			if(testC >= 50)
			{
				printf("C\n");
			}
			else
			{
				printf("D\n");
			}
		}
		else
		{
			printf("F\n");
		}

	}while(1);
	
	return 0;
}


Measured memory_bytes: 2032
/*
 * Author : Sadi
 * Sun 05/07/2020
 * 16:41:07.47
 */
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <cassert>

using namespace std;

#define    watch(x); cout << "\n" <<  #x << " is: " << x << "\n";
#define    all(a) (a).begin(), (a).end()
#define    fi first
#define    se second

template<class A, class B>
ostream& operator << (ostream& output, const pair<A, B>& p) {
    output << "(" << p.first << ", " << p.second << ")";
    return output;
}

template<class A>
ostream& operator << (ostream& output, const vector<A>& a) {
    output << "[";
    for(auto it = a.begin(); it != a.end(); ++it) {
        if(it != a.begin()) {
            output << ", ";
        }
        output << *it;
    }
    output << "]";
    return output;
}

using lld = long long;
using pii = pair<int, int>;
using pll = pair<lld, lld>;

const int inf = 1e9;
//const int mod = 1e9 + 7;
//const double PI = acos(-1.0);
//const int mx = 1e5 + 5;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

    int n, l;
    cin >> n >> l;
    vector<int> v;
    int flavour = 0;
    for(int i = 1; i <= n; ++i) {
        flavour += l + i - 1;
        v.push_back(l + i - 1);
    }
//    cout << flavour << endl;
//    cout << v << endl;
    if(lower_bound(all(v), 0) == v.end()) {
        cout << flavour - v[v.size() - 1] << endl;
    }
    else {
        cout << flavour - *lower_bound(all(v), 0);
    }

//    int ans = -inf;
//    for(int i = 0; i < (int) v.size(); ++i) {
//        int val = flavour - v[i];
//        ans = max(ans, val);
//    }
//    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,cx,cy,ans;
  cin >> n;
  vector<int> x(n),y(n),h(n);
  int c;
  for(int i=0;i<n;i++){
    cin >> x[i] >> y[i] >> h[i];
    if(h[i]!=0){
      c=i;
    }
  }
  bool f=false;
  for(int i=0;i<=100;i++){
    for(int j=0;j<=100;j++){
      bool b=true;
      ans=h[c]+abs(i-x[c])+abs(j-y[c]);
      for(int k=0;k<n;k++){
        if(h[k]!=max(0,ans-abs(i-x[k])-abs(j-y[k]))){
          b=false;
        }
      }
      if(b){
        cout << i << " " << j << " " << ans << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N,M; cin >> N >> M;
    vi D[M];
    rep(i,M){
        int a; cin >> a;
        rep(j,a){
            int b; cin >> b;
            b--;
            D[i].eb(b);
        }
    }
    int P[M]; rep(i,M) cin >> P[i];
    int ans=0;
    rep(i,1<<N){
        bool frag=true;
        rep(j,M){
            int cnt=0;
            for(auto a:D[j]){
                if((i>>a) & 1) cnt++;
            }
            if(cnt%2!=P[j]) frag=false;
        }
        if(frag) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#define ll long long int
#define lim 100010
#define INF 1e9
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define ABS(x) ((x)>0?(x):-(x))


int main(void){
	int h,w;
	scanf("%d%d",&h,&w);
	char S[h][w+1];
	int L[h][w],R[h][w],U[h][w],D[h][w];
	for(int i=0;i<h;i++){
		scanf("%s",S[i]);
		for(int j=0;j<w;j++){
			if(S[i][j]=='#'){
				L[i][j] = 0;
			}else if(j==0){
				L[i][j] = 1;
			}else{
				L[i][j]=L[i][j-1]+1;
			}
		}
		for(int j=0;j<w;j++){
			if(S[i][j]=='#'){
				U[i][j] = 0;
			}else if(i==0){
				U[i][j]=1;
			}else{
				U[i][j]=U[i-1][j]+1;
			}
		}
		for(int j=w-1;j>=0;j--){
			if(S[i][j]=='#'){
				R[i][j] = 0;
			}else if(j==w-1){
				R[i][j] = 1;
			}else{
				R[i][j]=R[i][j+1]+1;
			}
		}
	}
	for(int i=h-1;i>=0;i--){
		for(int j=0;j<w;j++){
			if(S[i][j]=='#'){
				D[i][j] = 0;
			}else if(i==h-1){
				D[i][j] = 1;
			}else{
				D[i][j]=D[i+1][j]+1;
			}
		}
	}
	int ans=L[0][0]+R[0][0]+D[0][0]+U[0][0]-3;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			ans = MAX(ans,L[i][j]+R[i][j]+D[i][j]+U[i][j]-3);	
		}
	}
	
	printf("%d",ans);
	
	
	return 0;
}

Measured memory_bytes: 66560
import java.util.*;
public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		char c = 'c';
		int a[][] = new int[h][w];
		for(int i = 0;i < h;i++){
			int cnt = -1;
			char s[] = sc.next().toCharArray();
			for(int k = 0;k < w;k++){
				if(c == s[k]) cnt = 0;
				else if(cnt >= 0) cnt++;
				a[i][k] = cnt;
			}
		}
		for(int i = 0;i < h;i++){
			for(int k = 0;k < w;k++){
				if(k != w - 1) System.out.print(a[i][k] + " ");
				else System.out.println(a[i][k]);
			}
		}
	}
}

Measured memory_bytes: 33172
n = gets.to_i
ps = gets.split.map(&:to_i)
count = 0
(0..n-3).each_with_index do |p,i|
    tmp = []
    tmp << ps[i]
    tmp << ps[i+1]
    tmp << ps[i+2]
    tmp.sort!
    count += 1 if tmp[1] == ps[i+1]
end
puts count


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

ll dp[110][10][10][10];

int main(){
    int n;
    cin >> n;
    
    ll ans = 0,mod = 1e9+7;
    
    dp[0][0][0][0] = 1;
    
    for(int i = 0;i < n;i++){
        for(int j = 0;j < 4;j++){
            for(int l = 0;l < 4;l++){
                for(int f = 0;f < 4;f++){
                    for(int k = 0;k < 4;k++){
                        if(j == 3 && l == 2 && f == 1)continue;
                        if(j == 2 && l == 3 && f == 1)continue;
                        if(j == 2 && l == 1 && f == 3)continue;
                        if(j == 2 && f == 3 && k == 1)continue;
                        if(j == 2 && l == 3 && k == 1)continue;
                        
                        dp[i+1][j][l][f] += dp[i][l][f][k];
                        dp[i+1][j][l][f] %= mod;
                    }
                }
            }
        }
    }
    
    for(int i = 0;i < 4;i++){
        for(int j = 0;j < 4;j++){
            for(int l = 0;l < 4;l++){
                ans += dp[n][i][j][l];
            }
        }
    }
    cout << ans % mod << endl;
}

Measured memory_bytes: 4216
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextLong()
    val k = sc.nextLong()
    val r = n % k
    println(Math.min(r, k - r))
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 29476
#include<iostream>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long int
#define hell 1000000007LL
using namespace std;
ll power(ll x, ll y, ll z){ 
    if(y==0)
     return 1;
    else
    {
        ll p=power(x,y/2,z);
        if(y%2==0)
         return (p*p)%z;
        else
        return (x*((p*p)%z))%z;
    }}
ll gcd(ll x,ll y)
{
    if(y==0)
     return x;
    else
    return gcd(y,x%y);
}
ll po(ll x)
{
    ll c=0;
    while(x>0)
    {
        x=x&(x-1);
        c++;
    }
    return c;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    ll n,d,c=0;
    cin>>n>>d;
   for(int i=0;i<n;i++)
   {
       ll x,y;
       cin>>x>>y;
       if(x*x+y*y<=d*d)
       c++;
   }
   cout<<c;}

Measured memory_bytes: 3652
from bisect import bisect
def main():
  n,k,*a=map(int,open(0).read().split())
  a.sort()
  i=bisect(a,0)
  a,b=a[i:],a[i-1::-1]
  n,m=len(a),len(b)
  ok=10**18
  ng=-ok
  while ok-ng>1:
    x=(ok+ng)//2
    s=0
    if x>=0:
      s+=n*m
      t=0
      i=n
      for y in a:
        while i and a[i-1]*y>x:
          i-=1
        t+=i
        if y*y<=x:
          t-=1
      s+=t//2
      t=0
      i=m
      for y in b:
        while i and b[i-1]*y>x:
          i-=1
        t+=i
        if y*y<=x:
          t-=1
      s+=t//2
    else:
      i=m
      for y in a:
        while i and b[i-1]*y<=x:
          i-=1
        s+=m-i
    if s>=k:
      ok=x
    else:
      ng=x
  print(ok)

main()
    

Measured memory_bytes: 98056
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

int main() {
	int n, k; 
	while (cin >> n >> k, n + k) {
		vector<int> card(n);
		for (int i = 0; i < n; ++i) cin >> card[i];
		sort(card.begin(), card.end());
		set<int> cnt;
		do {
			int tmp = 0;
			for (int i = 0; i < k; ++i)
				tmp = tmp * (card[i] >= 10 ? 100 : 10) + card[i];
			cnt.insert(tmp);
		} while (next_permutation(card.begin(), card.end()));
		cout << cnt.size() << endl;
	}

	return 0;
}


Measured memory_bytes: 3196
// WA ...

#include <iostream>
#define endl '\n'
using namespace std;
const int MAX = 12000000;
int n, m, x, cost = MAX + 1;
int lvl[13];
int t[12][13];

int check()
{
    for (int i = 1; i < m + 1; ++i)
    {
        if (lvl[i] < x)
            return 0;
    }
    return 1;
}

void learn(int idx)
{
    if (check())
    {
        if (lvl[0] < cost)
            cost = lvl[0];
        return;
    }
    if (idx == n)
        return;
    for (int i = 0; i < 2; ++i)
    {
        if (i)
        {
            for (int j = 0; j < m + 1; j++)
                lvl[j] += t[idx][j];
            learn(idx + 1);
            for (int j = 0; j < m + 1; j++)
                lvl[j] -= t[idx][j];
        }
        else
            learn(idx + 1);
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m >> x;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m + 1; j++)
            cin >> t[i][j];
    learn(0);
    if (cost > MAX)
        cout << -1 << endl;
    else
        cout << cost << endl;
    return 0;
}


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    string S,T;
    cin >> S >> T;
    ll cnt = 0;
    for (ll i = 0; i < (ll)S.size(); i++) {
        if (S[i] != T[i]) {
            ++cnt;
        }
    }
    cout << cnt << "\n";
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

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

MOD = 10**9
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

L = int(input())

ans = float(L)/3

print(ans*ans*ans)


Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
using namespace std;
char ch[6];
int main(){
scanf("%s", ch);
int N = strlen(ch);
for(int i = 0; i + 1 < N; ++i){
if(ch[i] == 'A' && ch[i + 1] == 'C'){
printf("Yes\n");
return 0;
}
}
printf("No\n");
return 0;
}

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

using namespace std;

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

  int N; cin>>N;
  for (int i = 1; i <= 9; i++) {
    if (N % i == 0 and N / i <= 9) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1000000000000



struct edge{ll from,to,cost; };
edge es[5050];
ll d[2525];
ll V,E;

ll ttt=0;

void bellmanford(ll s){
    for(ll i=0;i<V;i++) d[i]=INF;
    d[s]=0;
    ll cnt=0;
    while(true){
        bool update=false;
        cnt++;
        for(int i=0;i<E;i++){
            edge e=es[i];
            if(d[e.from]!=INF && d[e.to]>d[e.from]+e.cost){
                d[e.to]=d[e.from]+e.cost;
                
                update=true;
                if(cnt>V*3&&e.to==V-1) {
                    ttt=-1;
                    return;
                }
                if(cnt>V*6){
                    return;
                } 
            }
        }
        if(!update) break;
    }
}

int main(){
    ll i,j;
    ll n,m,p;
    cin>>n>>m>>p;
    V=n;
    E=m;

    for(i=0;i<m;i++){
        ll a,b,c;
        cin>>a>>b>>c;
        a--;
        b--;
        es[i]={a,b,p-c};
    }
    bellmanford(0);
    if(ttt==-1) cout<<-1<<endl;
    else cout<<max(0ll,-d[n-1])<<endl;

    return 0;
}

Measured memory_bytes: 384
import sys

sys.setrecursionlimit(500005)
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

k = ni()
s = ns()
if len(s) <= k:
    print(s)
else:
    print(s[:k] + "...")


Measured memory_bytes: 61680
#三井住友2019 D
def main():
    import sys
    N = int(sys.stdin.readline())
    S = sys.stdin.readline().rstrip()
    cnt = 0
    for i in range(0, 10):
        for j in range(0, 10):
            for k in range(0, 10):
                st1 = S.find(str(i))
                if st1 ==-1:
                    continue
                
                st2 = S[st1+1:].find(str(j))
                if st2 ==-1:
                    continue
              
                st3 = S[st1+st2+2:].find(str(k))
                if st3 ==-1:
                    continue
                #print(st1,st2,st3, i,j,k)
                cnt +=1
    print(cnt)


                    
    
   
    
if __name__=='__main__':
    main()

Measured memory_bytes: 3064
use std::cmp;
use std::collections::{BTreeSet, BinaryHeap, VecDeque};

const INF: i64 = 1e9 as i64;
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let a = sc.chars();
    let n = a.len();
    let mut heads = vec![];
    let mut set = BTreeSet::new();
    for (i, &c) in a.iter().enumerate().rev() {
        set.insert(c);
        if set.len() == 26 {
            set.clear();
            heads.push(i);
        }
    }

    let mut group = vec![0; n];
    for (i, head) in heads.into_iter().rev().enumerate() {
        group[head] = i + 1;
    }
    for i in 1..n {
        group[i] = cmp::max(group[i], group[i - 1]);
    }

    let mut index = vec![VecDeque::new(); 26];
    for i in 0..n {
        let c = a[i] as usize - 'a' as usize;
        index[c].push_back(i);
    }

    let mut cur_group = 0;
    let mut cur_pos = 0;
    let mut ans = String::new();
    loop {
        for i in 0..26 {
            while let Some(x) = index[i].pop_front() {
                if x >= cur_pos {
                    index[i].push_front(x);
                    break;
                }
            }
            let c = (i as u8 + 'a' as u8) as char;
            match index[i].iter().next().cloned() {
                Some(head) => {
                    if group[head] == cur_group + 1 {
                        ans.push(c);
                        cur_pos = head + 1;
                        cur_group += 1;
                        break;
                    }
                }
                None => {
                    println!("{}{}", ans, c);
                    return;
                }
            }
        }
    }
}
/// frqn
/// vhydscshfcgdemurlfrutcpzhopfotpifgepnqjxupnsk(a)pziurswqazdwnwbgdhyktfyhqqxpoidf
/// hjdakoxraiedxskywuepzfniuyskxiyjpjlxuqnfgmnj(c)vtlpnclfkpervxmdbvrbrdn

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .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: 10492
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>

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

using namespace std;
using ll = long long;
using P = pair<int, int>;
using TP = tuple<ll, ll, ll>;
ll MOD = 1e9+7;
ll INF = 1LL<<40;

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

    int K, S;
    cin >> K >> S;
    ll ans = 0;
    REP(i, K+1){
        REP(j, K+1){
            if(S >= i+j && i+j+K >= S){
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lld long long int
#define vec vector<lld>
#define pll pair<lld,lld>
#define pb push_back
#define ss second
#define ff first
#define mp make_pair
#define mod 1000000007
#define answer(x) cout<<endl<<"answer : "<<x<<endl<<endl;
#define op(x) cout<<x<<endl;
#define maxn 100005
#define messi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main() {messi lld t=1;//cin>>t;
    while(t--)
    {
        lld n=0,m=0,k=0,i=0,j=0,p=0,q=0,x=0,y=0,z=0,ans=0,cnt=0,l=0,r=0,mid=0,lo=0,hi=0;string s;bool flag=false;
        cin>>s;
        if(s=="RRR")
            ans=3;
        else if(s=="RRS" || s=="SRR")
            ans = 2;
        else if(s=="SSS")
            ans=0;
        else ans =1;
        cout<<ans<<endl;
    }
	return 0;
}
/*  CODED BY:-
 ________________________________________
|            __        __                |
|  /\   /\  |__)  /\  |  \ |__| \ /  /\  |
| /~~\ /~~\ |  \ /~~\ |__/ |  |  |  /~~\ |
|________________________________________|

*/


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define rg register
#define rep(i,a,b) for (rg int i=(a);i<=(b);i++)
#define per(i,a,b) for (rg int i=(b);i>=(a);i--)
#define pb push_back
#define lowbit(x) (x&(-x))
#define replow(i,a,b) for(rg int i = (a);i<=(b);i+=lowbit(i))
#define perlow(i,a,b) for(rg int i = (b);i>=(a);i-=lowbit(i))
#define mk make_pair
#define VI vector<int>
#define pii pair<int,int>
#define pLL pair<long long,long long>
#define fi first
#define se second
#define il inline
#define ll long long
#define ull unsigned long long
#define db double
#define ld long double
#define inf 0x3f3f3f3f
#define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<15,stdin),p1==p2)?EOF:*p1++)
char buf[1<<15],*p1 = buf,*p2 = buf;
inline ll read(){
    #define num ch-'0'
    char ch;bool flag=0;ll res;
    while(!isdigit(ch=getc()))
    (ch=='-')&&(flag=true);
    for(res=num;isdigit(ch=getc());res=res*10ll+num);
    (flag)&&(res=-res);
    #undef num
    return res;
}
inline void write(ll x){
	if (x < 0) x = ~x + 1ll, putchar('-');
	if (x > 9) write(x / 10ll);
	putchar(x % 10ll + '0');
}
#define mid ((l + r)>>1)
#define ls (x<<1)
#define rs ((x<<1)|1)
#undef mid
#undef ls
#undef rs
#define maxn 1010000
const ll mod = 1e9 + 7;
ll fac[maxn],inv[maxn];
ll fpow(ll a,ll v)
{
	ll ans = 1;
	while(v)
	{
		if(v & 1) ans = a * ans % mod;
		v>>=1;
		a = a * a % mod;
	}
	return ans;
}
void init()
{
    fac[0]=1;
    for(int i=1;i<maxn;i++) fac[i]=fac[i-1]*i%mod;
    inv[maxn-1]=fpow(fac[maxn-1],mod-2);
    for(int i=maxn-2;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
}
 
ll C(ll a,ll b)
{
    if(b>a) return 0;
    return fac[a]*inv[a-b]%mod;
}
struct node{
	int to,nxt;
};
node edge[maxn<<1];
int cnt = 0;
int head[maxn];
void add(int x,int y)
{
	edge[++cnt].to = y;
	edge[cnt].nxt = head[x];
	head[x] = cnt;
}
void addedge(int x,int y)
{
	add(y,x);
	add(x,y);
}
ll dep[maxn];
ll deg[maxn];
void dfs(int x,int fa)
{
	dep[x] = dep[fa] + 1;
	for(int i = head[x];i;i = edge[i].nxt)
	{
		int v = edge[i].to;
		if(v == fa) continue;
		deg[x]++;
		dfs(v,x);
	}
}
void solve()
{
	int n = read(),m = read();
	rep(i,1,n-1)
	{
		int x = read(),y = read();
		addedge(x,y);
	}
	dfs(1,-1);
	ll ans = m;
	rep(i,1,n)
	{
		if(dep[i] == 1) ans = ans * C(m-1,deg[i]);
		else ans = ans * C(m-2,deg[i]);
		ans %= mod;
	}
	printf("%lld\n",ans);
}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("data.txt","r",stdin);
	#endif
	init();
//	int T = read();
//	while(T--)
	solve();
}

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

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

    int L=s.size();
    int i,count=0;

    rep(i,L){
        if(s[i]!=t[i]){
            count++;
        }
    }
    cout<<count<<endl;

}

Measured memory_bytes: 3916
#include<iostream>
using namespace std;
const int INF = 10000;

int solve(int N){
  for(int i = 1; i < INF; i++){
    int cnt = 0;
    for(int j = 1; j <= i; j++) if(i % j == 0) ++cnt;
    if(cnt == N) return i;
  }
  return -1;
}

int main(){
  int N; cin >>N;
  cout <<solve(N) <<endl;
  return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double DB;

#define F(i,a,b) for(int i=(a);i<=(b);++i)
#define R(i,n) for(int i=(0);i<(n);++i)
#define fill(a,b) memset(a,b,sizeof a);

const int maxn = 2010;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;
int a[2*maxn];
int  n;
LL x;

deque<int> q;

int main()
{
	//freopen("test.txt","r",stdin);
	scanf("%d %lld",&n,&x);
	F(i,1,n) scanf("%d",a+i),a[n+i] = a[i];
	LL ans = INF;
	R(k,n)
	{
		while(q.size()) q.pop_back();
		LL res = x*k;
		int r = k+1;
		F(i,1,r) 
		{
			while(!q.empty() && a[q.back()] > a[i]) q.pop_back();
			q.push_back(i);
		}
		while(r <= n+k)
		{
			res += a[q.front()];
			if(a[q.front()] == a[r - k]) q.pop_front();
			++r;
			while(!q.empty() && a[q.back()] > a[r]) q.pop_back();
			q.push_back(r);
		}
//		puts("");
		ans = min(ans,res);
//		printf("%d %d\n",ans,res);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
//#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cctype>
#include <cstdlib>      // srand,rand


using namespace std;
#define modd 1000000007



typedef pair<long long, long long> pl;


typedef string::const_iterator State;
class ParseError {};




#define ll long long




class UnionFind {
public:
	vector <ll> par;
	vector <ll> siz;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL){
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}



	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}


};


class SegmentTree {
private:
	int n;
	vector <ll> node;

public:
	// 元の配列　v をセグメントツリーで表現する。
	SegmentTree(vector<ll> v) {
		//最下段のノード数は元配列のサイズ以上になる最小の2冪->これをnとおく。
		//セグ木全体で必要なノード数は2n-1個である。
		int sz = v.size();
		n = 1; 
		while (n < sz)n *= 2;

	}

};




long long N, M, K, a, b, c, d, e, H, W, L,T;
ll A[300005] = {};
ll B[300005] = {};
ll C[100][3005] = {};
bool f, ff;
string S,SS;
set <long long>sll;
pl bufpl;
vector <long long>vl[100005];
vector <long long>vll;
vector <pl>vpl;
vector <string> vs;
set<ll> llset[50];
multiset<ll> llmset;
queue<ll> ql;


struct ST
{
	ll first;
	ll second;
	ll kaisuu;
	

	bool operator<(const ST& another) const
	{
		return first < another.first;//比較
	};

};



/*vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/


long long modinv(long long aa, long long mm) {
	long long bb = mm, uu = 1, vv = 0;
	while (bb) {
		long long tt = aa / bb;
		aa -= tt * bb; swap(aa, bb);
		uu -= tt * vv; swap(uu, vv);
	}
	uu %= mm;
	if (uu < 0) uu += mm;
	return uu;
}


ll minn, maxx;
double ansa;

ll zettai(ll aa) {

	if (aa < 0) {
		aa *= -1;
	}
	return aa;

}


bool itta[300000];

int main() {
	
	cin >> S>>K;


	a = 0;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == '1') {
			a++;
		}
		else {
			b = S[i] - '0';
			break;
		}
	}


	if (a >= K) {
		d = 1;
	}
	else {
		d = b;
	}
	
	cout << d << endl;

	//cout << fixed << setprecision(10) << ansa << endl;
	return 0;



}


Measured memory_bytes: 4096
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [input() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    from collections import Counter
    N = I()
    a = LI()
    c = Counter(a)
    ans=0
    for i, j in c.items():
        if j - i < 0:
            ans += j
        else:
            ans += j - i
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 64424
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(a,b) memset(a,b,sizeof(a))
#define msn(a,n,b) for(int i=0;i<=n;i++)a[i]=b
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define fi first
#define se second
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef double db;
const int mod=1e9+7;
const int seed=233;
const double PI=acos(-1.0);
const double eps=1e-7;
const int inf=0x3f3f3f3f;
const int max_n=200005;
ll ceil(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?(x+y-1)/y:-x/y;}
ll floor(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?x/y:-(x+y-1)/y;}
namespace {
    inline int Add(int x,int y){return (x+=y)>=mod?x-mod:x;}
    inline int Sub(int x,int y){return (x-=y)<0?x+mod:x;}
    inline int Mul(int x,int y) {return 1ll*x*y%mod;}
    inline int Pow(int x,int y=mod-2){if(y==0)return 1;int res=1;while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}return res;}
}
/**********************head************************/
int n, a[max_n];
int main() {
    scanf("%d", &n);
    for(int i = 2; i <= n; i++) {
        int x; scanf("%d", &x);
        a[x]++;
    }
    for(int i = 1; i <= n; i++) printf("%d\n", a[i]);
    return 0;
}

Measured memory_bytes: 4512
def resolve():
    N = int(input())
    h = [int(i) for i in input().split()]
    dp = [0, abs(h[1] - h[0])]
    for i in range(2, N):
        dp.append(
            min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))
        )
    print(dp[N - 1])


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 54896