akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

int calc(int a)
{
    int ret = 0;
    while (a)
    {
        ret += a % 10;
        a /= 10;
    }
    return ret;
}

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

    int n;
    cin >> n;

    int ans = 1e9;
    for (int a = 1; a * 2 <= n; ++a)
    {
        ans = min(ans, calc(a) + calc(n - a));
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 256
# Connect Cities
# Union Findデータ構造（素集合データ構造）

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

class UnionFind():
	"""docstring for UnionFind"""
	def __init__(self, n):
		self.parents = [-1]*n

	def find(self,x):
		if self.parents[x] < 0: #自分が親である時
			return x
		else: #自分が子供である時
			self.parents[x]=self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		# 各要素の親要素を返す
		x=self.find(x)
		y=self.find(y)

		if x==y:
			return
		if self.parents[x] > self.parents[y]:
			x,y=y,x

#		self.parents[x]+=self.parents[y]
		self.parents[y]=x
		# print(self.parents)
n,m=input2()
AB=[input_array() for _ in range(m)]


uf = UnionFind(n)
for ab in AB:
	a=ab[0]
	b=ab[1]
	uf.union(a-1,b-1)

ans=0
for i in uf.parents:
	if i < 0:
		ans+=1
print(ans-1)

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

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

    if(a + b >= c) {
        cout << b + c << endl;
    } else {
        cout << a + 2 * b + 1  << endl;
    }
    return 0;
}

Measured memory_bytes: 384
<?php
  fscanf(STDIN, "%d%d", $n, $m);
  $x = explode(" ", trim(fgets(STDIN)));
  sort($x);
  $sa = [];
  for($i=1; $i<$m; $i++){
      $sa[] = $x[$i]-$x[$i-1];
  }
  rsort($sa);
//   print_r($sa);
  $ans = 0;
  for($i=$n-1; $i<$m-1; $i++){
      $ans += $sa[$i];
  }
  echo $ans;

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

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

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

        int N;
        std::cin >> N;

        int A, B;
        std::cin >> A >> B;

        std::cout << min((N * A), B) << std::endl;

    }
    catch(const exception& e) {
        std::cout << e.what() << std::endl;
        exit(1);
    }
    return 0;
}


Measured memory_bytes: 892
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int, int>
#define pb(a) push_back(a)
#define all(v) v.begin(), v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

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

	int X[3];

	for (int i = 0; i < 3; i++) {
		cin >> X[i];
	}

	int C = X[2];

	sort(X, X + 3);

	yn(X[1] == C);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

int main(){
    int N;
    cin >> N;
    map<ll, ll> mp;
    rep(i, N){
        ll a, b;
        cin >> a >> b;
        mp[b] += a;
    }
    ll time = 0;
    bool is = true;
    for(auto p : mp){
        if(time + p.second > p.first){
            is = false;
            break;
        }
        time += p.second;
    }
    if(is) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 12800
#include<iostream>
#include<algorithm>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }
char buf[1000010]; 
int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  std::cin >> buf;
  int a0 = 0, a1 = 1, b0 = 0, b1 = -1;
  int c0 = a0-b0, c1 = a0-b1, c2 = a1-b0, c3 = a1-b1;
  for(char *p = buf; *p; p++) {
    if(*p=='0')      { --a0; --a1; --b0; --b1; }
    else if(*p=='1') { ++a0; ++a1; ++b0; ++b1; }
    else             { --a0; --a1; ++b0; ++b1; }
    if(a0 < 0) a0 += 2;
    if(a1 < 0) a1 += 2;
    if(b0 > 0) b0 -= 2;
    if(b1 > 0) b1 -= 2;
    c0 = std::max(c0, a0-b0);
    c1 = std::max(c1, a0-b1);
    c2 = std::max(c2, a1-b0);
    c3 = std::max(c3, a1-b1);
  }
  fin(std::min(std::min(c0, c1), std::min(c2, c3)));
  return 0;
}


Measured memory_bytes: 4640
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
using namespace std;
using ll = unsigned long long;
using p = pair<int, int>;

int main()
{
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    int ans = INT_MAX;

    rep(i, 0, max(X, Y) + 1)
    {
        // Cの購入数を2iとしたときの、A, Bの購入数を求める
        // Cを使ってA, Bをいくつ作ったかと考えると、理解が進んだ
        int amount = (C * 2 * i) + (A * max(0, X - i)) + (B * max(0, Y - i));

        ans = min(ans, amount);
    }

    std::cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
int happy[100000][3],dp[100000][3];
void read()
{
    cin>>n;

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++ )
        {
        cin>>happy[i][j];
        }
    }

}
int max(int a,int b)
{
    if(a>b)
    return a;
    else
    return b;
}
int solve()
{
dp[0][0]=happy[0][0];
dp[0][1]=happy[0][1];
dp[0][2]=happy[0][2];
  
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<3;j++ )
        {
            if(j==0)
            dp[i][j]=happy[i][j]+max(dp[i-1][1],dp[i-1][2]);
            else if(j==1)
            dp[i][j]=happy[i][j]+max(dp[i-1][0],dp[i-1][2]);
            else
            dp[i][j]=happy[i][j]+max(dp[i-1][1],dp[i-1][0]);
        }
        //cout<<dp[i][0]<<dp[i][1]<<dp[i][2]<<"\n";
    }
    return max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}
int main() {
	read();
	cout<<solve();
	
	return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <string>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;



int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main(int argc, const char * argv[]) {
    int N,K;
    cin >> N >> K;

    if(N>=K && N%K==0){
        cout << "0" << endl;
    }
    else if(N>=K){
        cout << "1" << endl;
    }
    else if(N<K){
        cout << "1" << endl;
    }
}


Measured memory_bytes: 256
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let cycle = ["Sunny", "Cloudy", "Rainy", "Sunny", "Cloudy", "Rainy"];

    let S = rl();
    let mut t = None;
    for i in 0..cycle.len() {
        if S == cycle[i] {
            t = Some(cycle[i + 1]);
            break;
        }
    }

    println!("{}", t.unwrap())
}


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

#define ll long long
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define bac(i,a,b) for(ll i=b-1;i<=a;i--)

#define pb push_back
#define vi vector<int>
#define vll vector<ll>

#define mod 1000000007
vi v(100000,-1);
int result(vi &ve,int indx,int size,int inc)
{
    int mi=INT_MAX;
    if(v[indx]!=-1)
    return v[indx];
    if(indx==size-1)
    return 0;
    if(indx>size-1)
    return INT_MAX;
    for(int i=1;i<=inc;i++){
        if(indx+i<size){
    mi=min(mi,result(ve,indx+i,size,inc)+abs(ve[indx]-ve[indx+i]));
    v[indx]=mi;
        }
    }
    return v[indx];
}
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int a,k;
	cin>>a>>k;
	vi vec(a);
	for(int i=0;i<a;i++)
	cin>>vec[i];
	int res=result(vec,0,a,k);
	cout<<res<<"\n";
	v.clear();
	return 0;
}


Measured memory_bytes: 10368
def m():
    N, M = [int(i) for i in input().split()]
    cards = sorted([int(i) for i in input().split()])
    manups = []
    for _ in range(M):
        b, c = [int(i) for i in input().split()]
        # c is number, b is max
        manups.append((c, b))
    manups.sort(reverse=True)

    cursor = 0
    for manup in manups:
        sub = manup[0]
        count = manup[1]
        for c in range(1, count+1):
            if cursor == N:
                break
                return(sum(cards))

            if cards[cursor] <= sub:
                cards[cursor] = sub
            else:
                break
                return(sum(cards))

            cursor += 1
    return(sum(cards))


if __name__ == '__main__':
    print(m())


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

int main() {
  int N, K,C;
  cin >> N >> K;
  C=0;
  
  for(int i=N;i<K+1;i++){
    bool a,b,c;
    b=(i%10==i/10000%10);
    c=(i/10%10==i/1000%10);
    a=(b&&c);
    if(a){
      C++;
    }
  }
  
  cout << C << endl;
}


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

int main() {
int n,m;
cin >> n >> m;
int s[m];
char c[m];
if(m==0){
    if(n==1){cout << "0";
    return 0;}
    else{cout << pow(10,n-1);
    return 0;}
}
for(int i=0;i<m;i++){
    cin >> s[i] >> c[i];
}
for(int i=0;i<m;i++){
    if((s[i]==1)&&(c[i]=='0')){
        if(n==1){
            cout << "0";
            return 0;
        }
        else{cout << "-1";
        return 0;}
    }
}
int ans =-1;
for(int i=pow(10,n-1);i<pow(10,n);i++){
        string st=to_string(i);    
    for(int j=0;j<m;j++){

        if(!(st[s[j]-1]==c[j])){
            break;}
        if(j==m-1)ans=i;
        }
if(!(ans==-1))break;
    }
cout << ans;    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,i,j,k,m,w;cin >> n;
    int f[n][3];vector<int> ans;
    for(i=0;i<n;i++) cin >> f[i][0] >> f[i][1] >> f[i][2];
    cin >> m;
    int dp[394] = {};
    for(i=1;i<=393;i++) dp[i] = -1;
    for(i=0;i<n;i++){
        for(j=f[i][0];j<=f[i][1];j++){
            for(k=j;k<=393;k++){
                if(dp[k-j] != -1) dp[k] = max(dp[k],dp[k-j]+f[i][2]);
            }
        }
    }
    while(cin >> w){
        if(dp[w]==-1){
            cout << -1 << endl;return 0;
        }
        ans.push_back(dp[w]);
    }
    for(auto x:ans) cout << x << endl;
}


Measured memory_bytes: 3172
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;
typedef pair<ll,ll> P;

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

template<class T>
bool umax(T &a, const T &b){
    if (a<b) {
        a=b; return 1;
    }
    return 0;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b<a) {
        a=b; return 1;
    }
    return 0;
}

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
// v.front() = -BOUND;
// v.back() = BOUND;

struct edge{
    int cost, to;

    edge(int in_cost, int in_to){
        cost=in_cost;
        to=in_to;
    }
    bool operator<(const edge &a) const
    {
        return cost > a.cost;
    }
};

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

    ll ans=0;
    if(A%2==0 && B%2==0){
        if( ((B-A)/2)%2 == 0){
            ans=B;
        }else{
            ans=B^1;
        }
    }else if(A%2==1 && B%2==1){
        if( ((B-A+1)/2)%2 == 0){
            ans=A;
        }else{
            ans=A^1;
        }
    }else if(A%2==0 && B%2==1){
        if( ((B-A+1)/2)%2 == 1){
            ans=1;
        }else{
            ans=0;
        }
    }else if(A%2==1 && B%2==0){
        if( ((B-A-1)/2)%2 == 0){
            ans=A^B;
        }else{
            ans=A^B^1;
        }
    }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
typedef long long ll;
#define i(x) cin>>x
#define fr(n,x) for(ll n=0;n<x;n++)
#define pf(x) cout<<x
const ll mod=1e9+7 ;


int main()
{
    ll x;
    cin>>x;
    map<string,ll>ms;
    ios_base::sync_with_stdio(false),cin.tie(NULL);
    fr(n,x)
    {
        string j;
        cin>>j;
        sort(j.begin(),j.end());
        ms[j]++;
    }
    ll res=0;
    for(auto j:ms)
    {
        ll v=j.second;
        res+=(v*(v-1))/2;
    }
    cout<<res;
}

Measured memory_bytes: 11364
import java.util.*;
import java.io.*;
class Main {

    private static int[][] getLISMatrix(String s, String t) {
        int N = s.length();
        int M = t.length();

        int [][]dp = new int[N+1][M+1];

        for(int i=0; i <= N; ++i)
            dp[i][0] = 0;
        for(int i=0; i <= M; ++i)
            dp[0][i] = 0;

        for(int i=1; i <= N; ++i)
            for(int j=1; j <= M; ++j) {
                if (s.charAt(i-1) == t.charAt(j-1))
                    dp[i][j] = Math.max(dp[i][j], 1 + dp[i-1][j-1]);
                else dp[i][j] = Math.max(dp[i][j-1], dp[i-1][j]);
            }

        // for(int i=0; i <= N; ++i) {
        //     for(int j=0; j <= M; ++j)
        //         System.out.print(dp[i][j] + " ");
        //     System.out.println();
        // }

        return dp;
    }

    private static String getLISString(int [][]dp, String s, String t) {
        int N = s.length();
        int M = t.length();

        int x = N, y = M;



        StringBuilder resultBuilder = new StringBuilder();

        while (x > 0 && y > 0) {

            if (dp[x][y] == dp[x-1][y])
                --x;

            else if (dp[x][y] == dp[x][y-1])
                --y;
            else {
                resultBuilder.append(s.charAt(x-1));
                --x;
                --y;
            }
        }

        return resultBuilder.reverse().toString();
    }

    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String s = br.readLine();
        String t = br.readLine();
        

        System.out.println(getLISString(getLISMatrix(s, t), s, t));
    }
}

Measured memory_bytes: 85716
package main
 
import (
  "fmt"
)
 
func main() {
  var a, b int
  fmt.Scanf("%d %d", &a, &b)
  
  ans := 0
  if a == b {
    ans = a + b
  }
  if a > b {
    ans = a + (a - 1)
  }
  if a < b {
    ans = b + (b - 1)
  }
  
  fmt.Printf("%d\n", ans)
}

Measured memory_bytes: 1828
n = int(input())
a, b = map(int, input().split())
p = list(map(int, input().split()))
dp = [0]*3

for i in p:
    if i <= a:
        dp[0] += 1
    elif a < i <= b:
        dp[1] += 1
    else:
        dp[2] += 1

print(min(dp))

Measured memory_bytes: 8992
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long INF = 1LL << 60;
template <class T> bool chmin(T& a, T b){if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b){if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, int B) {return (A + (B - 1)) / B;}
long long divCeil(int A, long long B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

int main()
{
  string w;
  cin >> w;
  int N = w.size();
  
  string abc = "abcdefghijklmnopqrstuvwxyz";
  vector<int> appear(26, 0);
  
  for (int i = 0; i < N; i++)
  {
    appear.at(abc.find(w.at(i)))++;
  }
  
  string ans = "Yes";
  for (int i = 0; i < 26; i++)
  {
    if (appear.at(i) % 2 == 1) ans = "No";
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <set>

using namespace std;

int f[200000];
int g[200000];
vector <int> v[200000];
vector <int> w[200000];
vector <int> z[200000];
set <int> s[200000];

int dfs(int x) {
    int i;
    
    if (f[x] == 1) return -1;
    
    f[x] = 1;
    
    for (i = 0; i < v[x].size(); i++) {
        int y = dfs(v[x][i]);
        
        if (y == -1) {
            g[x] = -1;
        } else {
            s[x].insert(y);
        }
    }
    
    if (g[x] == -1) {
        for (i = 0; z[x].size() < 2; i++) {
            if (!s[x].count(i)) z[x].push_back(i);
        }
        
        return -1;
    } else {
        for (i = 0; ; i++) {
            if (!s[x].count(i)) return g[x] = i;
        }
    }
}

int main() {
    int n, p = 0, q, x1, x2, f1 = 1, f2 = 2, i;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) {
        int x;
        
        scanf("%d", &x);
        
        x--;
        
        v[x].push_back(i);
        w[i].push_back(x);
    }
    
    while (1) {
        if (f[p] == 1) break;
        
        f[p] = 1;
        p = w[p][0];
    }
    
    for (i = 0; i < n; i++) f[i] = -1;
    
    dfs(p);
    
    q = p;
    x1 = z[p][0];
    x2 = z[p][1];
    
    while (1) {
        int nf1 = 0, nf2 = 0;
        
        p = w[p][0];
        
        if (f1 > 0) {
            if (z[p][0] != x1) nf1 |= f1;
            if (z[p][0] == x1) nf2 |= f1;
        }
        
        if (f2 > 0) {
            if (z[p][0] != x2) nf1 |= f2;
            if (z[p][0] == x2) nf2 |= f2;
        }
        
        x1 = z[p][0];
        x2 = z[p][1];
        f1 = nf1;
        f2 = nf2;
        
        if (p == q) break;
    }
    
    if ((f1 & 1) || (f2 & 2)) {
        puts("POSSIBLE");
    } else {
        puts("IMPOSSIBLE");
    }
    
    return 0;
}


Measured memory_bytes: 58752
# include <bits/stdc++.h>
# define A first
# define B second
# define PII pair<int,int>
using namespace std;
const int maxn = 1<<18;
int a[maxn+3];
PII imax[maxn];
void fun(int x, PII &y)
{
    if(x == y.A || x == y.B) return;
    if(a[x] > a[y.A]) y.B = y.A,y.A = x;
    else if(a[x] > a[y.B]) y.B=x;
}
int main()
{
    int N, n, ans=0;
    scanf("%d",&n);
    N = 1<<n;
    a[N] = 0;
    for(int i=0; i<N; ++i) scanf("%d",&a[i]), imax[i].A=i, imax[i].B=N;
    for(int i=1; i<N; ++i)
    {
        for(int j=0; j<n; ++j)
        {
            if(i&(1<<j))
            {
                int k=i^(1<<j);
                fun(imax[k].A, imax[i]);
                fun(imax[k].B, imax[i]);
            }
        }
    }
    for(int i=1; i<N; ++i)
    {
        ans = max(ans, a[imax[i].A]+a[imax[i].B]);
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 6144
package main

import (
	"fmt"
)

func getSum(m map[string]float64) (sum float64) {
	sum = 0
	for k, v := range m {
		if k == "JPY" {
			sum += v
		}
		if k == "BTC" {
			sum += v * 380000.0
		}
	}
	return
}

func main() {
	var N int
	fmt.Scan(&N)
	m := make(map[string]float64)
	for i := 0; i < N; i++ {
		var k string
		var v float64
		fmt.Scan(&v)
		fmt.Scan(&k)
		m[k] += v
	}
	fmt.Println(getSum(m))
}


Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>

int main() {
	int i;
	char S[4];
	scanf("%s", &S);
	if(strcmp (S,"RRR") == 0) {
		printf("3");
	}
	else if(strcmp (S,"RRS") == 0 || strcmp(S,"SRR") == 0) {
		printf("2");
	}
	else if(strcmp(S,"RSR") == 0 || strcmp(S,"RSS") == 0 || strcmp(S,"SRS") == 0 || strcmp(S,"SSR") == 0) {
		printf("1");
	}else {
		printf("0");
	}
	return 0;
}

Measured memory_bytes: 1644
s = input()
N = len(s)
K = int(input())
word = []
for i in range(N):
    for j in range(i, min(N, i+K)):
        word.append(s[i:j+1])

word.sort()
word_set = list(set(word))
word_set.sort()
print(word_set[K-1])


Measured memory_bytes: 4964
void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  int a, b, c;
  rd(a, b, c);

  writeln(max(a * 10 + b + c, b * 10 + c + a, c * 10 + a + b));
}

void rd(T...)(ref T x) {
  import std.stdio, std.string, std.conv;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}


Measured memory_bytes: 256
$n = gets.to_i

$str = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']

def go(strr, store)
	if strr.size != $n then
		store.each{ |s|
			go(strr + s, store)
		}
		go(strr + $str[store.size], store + [$str[store.size]])
	else
		puts strr
	end
end

go('a', ['a'])


Measured memory_bytes: 3836
//おまじない
//#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#include<iomanip>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define space ' '
#define pll pair<ll,ll>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn = 3000;
pair<int,int> ab[maxn+1];
int n,t;
int dp1[maxn+2][maxn+2]={0};
int dp2[maxn+2][maxn+2]={0};
int ans = 0;

int main(){
    
    cin >> n>>t;
    rep(i,n){
        int a,b;
        cin >> a>>b;
        ab[i+1] = make_pair(a,b);
    }
    
    for(int i=1;i<=n;i++){
        for(int k=1;k<t;k++){
            dp1[i][k]=dp1[i-1][k];
            if(k-ab[i].first>=0)dp1[i][k]=max(dp1[i][k],dp1[i-1][k-ab[i].first]+ab[i].second);
            else dp1[i][k]=dp1[i-1][k];
        }
    }
    
    for(int i=n;i>=1;i--){
        for(int k=1;k<t;k++){
            dp2[i][k]=dp2[i+1][k];
            if(k-ab[i].first>=0)dp2[i][k]=max(dp2[i][k],dp2[i+1][k-ab[i].first]+ab[i].second);
            else dp2[i][k]=dp2[i+1][k];
        }
    }
    
    
    for(int i=1;i<=n;i++){
        for(int j=1;j<t;j++){
            //cout << i<<space<<j<<space<<dp1[i-1][j]<<space<<dp2[i-1][j]<<endl;
            ans = max(ans,dp1[i-1][j]+dp2[i+1][t-1-j]+ab[i].second);
        }
    }
    
    cout << ans<<endl;
    
    return 0;
}


Measured memory_bytes: 70656
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
 
public class Main{

  public static void main(String[] args) throws IOException {
    try ( BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) ) {

      int[][][] rooms = new int[4][3][10];
      for( int i = 0; i < 4; i++ ) {
        for( int j = 0; j < 3; j++ ) {
          Arrays.fill(rooms[i][j], 0);
        }
      }
      String[] lines = br.readLine().split(" ");
      int n = Integer.parseInt(lines[0]);
      int b,f,r;

      for(int i = 0; i < n; i++) {
        lines = br.readLine().split(" ");
        b = Integer.parseInt(lines[0]);
        f = Integer.parseInt(lines[1]);
        r = Integer.parseInt(lines[2]);
        rooms[--b][--f][--r] += Integer.parseInt(lines[3]);
      }

      StringBuilder result = new StringBuilder(300);
      String sep = "####################\n";
      for(int i = 0; i < 4; i++ ) {
        for( int j = 0; j < 3; j++ ) {
          for( int k = 0; k < 10; k++ ){
            result.append(" " +rooms[i][j][k]);
          }
          result.append("\n");
        }
        if( i != 3) result.append(sep);
      }
      System.out.print(result);
    }
  }
}


Measured memory_bytes: 24460
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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);
    int N,X,Y; cin >> N >> X >> Y;
    --X; --Y;
    vector<int> dist(N);
    rep(i,N) {
        for (int j = i+1; j < N; ++j) {
            int k = j-i;
            chmin(k,abs(X-i)+1+abs(Y-j));
            dist[k]++;
        }
    }

    for (int i = 1; i < N; ++i) {
        cout << dist[i] << ln;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 1200
using namespace std;
char s[maxn][maxn];
int f[maxn][maxn];
const int mod = 1000000007;
int main(){
	ios::sync_with_stdio(false);
	int H, W;
	cin >> H >> W;
	for(int i = 1; i <= H; i += 1) cin >> s[i] + 1;
	f[1][1] = 1;
	for(int i = 1; i <= H; i += 1)
		for(int j = 1; j <= W; j += 1)
			if(s[i][j] == '.'){
				f[i + 1][j] = (f[i + 1][j] + f[i][j]) % mod;
				f[i][j + 1] = (f[i][j + 1] + f[i][j]) % mod;
			}
	cout << f[H][W];			
} 

Measured memory_bytes: 7040
def getLnInput():
    return input().split()


def getNewVote(currentVote, newRatio):
    multFacCeil = []
    for i in range(2):
        multFacCeil.append((currentVote[i] - 1) // newRatio[i] + 1)
    newVote = []
    maxMF = max(multFacCeil)
    for i in range(2):
        newVote.append(newRatio[i] * maxMF)
    return newVote


def main():
    N = int(getLnInput()[0])
    voteNum = list(map(int, getLnInput()))
    for i in range(N - 1):
        newRatio = list(map(int, getLnInput()))
        voteNum = getNewVote(voteNum, newRatio)
    print(sum(voteNum))
    return


main()


Measured memory_bytes: 3192
#include <iostream>

using namespace std;

int main(){
  string S;
  string T;
  cin >> S;
  cin >> T;
  int cnt = 0;
  
  for(int i=0;i<3;i++){
    if(S[i] == T[i]){
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9+7
int main()
{
	int n;
	cin>>n;
	vector<int> v;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		v.push_back(x);
	}
	vector<int> dp(n+1,INF);
	dp[0]=0;
	for(int i=0;i<n;i++)
	{
		for(int j:{i+1,i+2})
		{
			if(j<n)
			{
				dp[j]=min(dp[j],dp[i]+abs(v[i]-v[j]));
			}
		}
	}
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T & a, U & ... b) { cin >> a; IN_(b ...); };
template<typename T> void OUT(T && a) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

int main() {
	IN(LL, n);
	LL ans = 0;
	inc1(i, n) {
		if(i % 3 != 0 && i % 5 != 0) { ans += i; }
	}
	OUT(ans);
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(I,0,n){cout<<(I ? " ":"")<<A[I]x;}cout<<endl;
#define pprint(A,y,m,n) rep(J,0,m){print(A[J],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
long N,M;
vector<int> g[size];
int visit[size] = {}; long n;
bool dfs(int v){
    bool flag = true;
    for(int u:g[v]){
        if(visit[u] == -1){
            n++;
            visit[u] = visit[v] ^ 1;
            if(!dfs(u)) flag = false;
        }else{
            if(visit[v] == visit[u]) flag = false;
        }
    }return flag;
}
int main(){
	cin>>N>>M;
	int a,b;
	rep(i,0,M){
		cin>>a>>b; a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	long ans = N * N;
    long cnt = 0; long sum = 0; long bip = 0;
    rep(i,0,N) visit[i] = -1;
	rep(i,0,N)if(visit[i] == -1 && g[i].size()){
		n = 1;
        visit[i] = 1;
		if(dfs(i)) bip++;
        cnt++;
        sum += n;
	}cout<<ans - sum * sum + cnt * cnt + bip * bip<<endl;
}

Measured memory_bytes: 9984
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll a[100009];
int main()
{
    ll i,j,n,t,m,k,q;
    cin>>n>>k>>q;
 // a[q+2];
     for(i=0;i<q;i++)
     {
         cin>>t;
         --t;
         a[t]++;
         }
         for(i=0;i<n;i++)
         {
             if(a[i]+k-q<=0) cout<<"No"<<endl;
             else cout<<"Yes"<<endl;
         }

}



Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
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 (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll a,b;
    cin>>a>>b;
    ll s = a-1;
    ll t = b-1;
    ll ans = (t+s-1)/s;
    
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int i,n,point=0;
	bool run[3];
	string s;
	cin >> n;
	int out=3;
	while(n--){
		for(i=0;i<3;i++) run[i]=0;
		point=0;
		out=3;
		while(out){
			cin >> s;
			if(s == "HIT"){
				if(run[2])point++;
				for(i=2;i>0;i--) run[i]=run[i-1];
				run[0]=1;
				}
				else if(s == "HOMERUN"){
					for(i=0;i<3;i++) if(run[i]){ point++; run[i]=0;}
					point++;
				}
				else out--;
		}
	cout << point << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
using ll = long long;
#define int ll
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
signed main(){
    vector<int>a(3);
    rep(i,3) cin >> a[i];
    int n; cin >>n;
    rep(i,n){
        sort(all(a));
        int temp = a.back();
        a.pop_back();
        temp*=2;
        a.push_back(temp);
    }
    int ans = 0;
    rep(i,3)ans +=a[i];
    cout << ans << endl;
}


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

ans=S.count('R')*S.count('G')*S.count('B')


i=0
while i<N-1:
    j=i+1
    while 2*j-i<N:
        ans-=1*(S[i]!=S[j])*(S[j]!=S[2*j-i])*(S[2*j-i]!=S[i])
        j+=1
    i+=1

print(ans)
        



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

int main(){
  string a, b;
  cin >> a >> b;
  string c = a + b;
  long int ci = stoi(c);
  long int rt = (long int)sqrt((double)ci);
  if(ci - rt * rt == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    int a,b,c,d,e,k;
    int n[5];
    int i,j;
    for(i=0;i<5;i++){
        cin>>n[i];
    }
    cin>>k;
    for(i=0;i<5;i++){
        for(j=0;j<5;j++){
            if(abs(n[i]-n[j])>k){
                cout << ":(" << endl;
                return 0;
            }
        }
    }
    std::cout << "Yay!" << std::endl;
    return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn.{readInt,readLine}
import scala.collection.mutable.HashMap

object Main extends App {
  val n = readInt
  val map = new HashMap[String,Int]
  for(i<-1 to n) {
    val s = readLine.split(" ")
    if(s(0)=="insert")
      map(s(1)) = 1
    else
      if(map.contains(s(1))) println("yes") else println("no")
  }

}

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

char buf[50010];

int main(){
	string s;
	getline(cin, s);
	const char *ptr = s.c_str();
	
	vector<string> key;
	int d = 0;
	while(sscanf(ptr, ".%[^.]%n", buf, &d) > 0){
		ptr += d;
		key.push_back(buf);
	}
	
	int m = 0;
	int prev = -1;
	int k = 0;
	while(getline(cin, s)){
		ptr = s.c_str();
		int indent = -1;
		sscanf(ptr, " %n%[^:]:%n", &indent, buf, &d);

		if(indent <= prev){ break; }

		if(m == -1) m = indent;

		if(m == indent && key[k] == buf){
			m = -1;
			prev = indent;

			if(++k == key.size()){
				if(d < s.size()){
					cout << "string \"" << s.substr(d + 1) << "\"\n";
				}
				else{
					cout << "object\n";
				}
				
				return 0;
			}
		}
	}
	
	cout << "no such property\n";
}

Measured memory_bytes: 1300
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include <ctype.h>
int main(){
	char a[11], b[11], c[11];
	scanf("%s%s%s", a, b, c);

	printf("%c%c%c\n", toupper(a[0]), toupper(b[0]), toupper(c[0]));


	return 0;	
}

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


int main()
{
	int n;  cin>>n;
	
	 string  ans;
	 if(n==22)  ans="Christmas Eve Eve Eve";
	
	else if(n==23) ans="Christmas Eve Eve";
	
	else if(n==24) ans="Christmas Eve";
	
	else if(n==25)  ans="Christmas";
	
	cout<<ans<<endl;
	
	return 0;
	
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int main(void) {
    string s;
    while (cin>>s) {
        for (int i=0;i<s.size();i++) {
            char c=s.at(i);
            if (c=='@') {
                int count = s.at(i+1)-48;
                for (int j=0;j<count;j++) {
                    cout<<s.at(i+2);
                }
                i=i+2;
            } else {
                cout<<c;
            }
            if (i==s.size()-1) {
                cout<<endl;
            }
        }
    }
}


Measured memory_bytes: 3008
N = int(input())
A = [int(input()) for i in range(N)]

ans = 0
part_sum = 0
for i in range(N):
    if A[i] == 0 or i == N-1:
        part_sum += A[i]
        ans += (part_sum // 2)
        part_sum = 0
    else:
        part_sum += A[i]

print(ans)






Measured memory_bytes: 12952
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(ll i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array);
//bool can;
const ll N=1000005;
std::vector<ll> visited;
ll ans;
ll k;
const ll MOD=1000000007;
ll fact[N], invfact[N];

ll Power(ll base , ll e)
{
    if(e == 0) return 1;
    ll ans = base; e--;
    while(e)
	{
        if(e & 1) ans = (((ans%MOD) * (base%MOD)) %MOD+MOD)%MOD;
        base = (((base%MOD) * (base%MOD)) %MOD+MOD)%MOD;
        e >>= 1;
	}
	return (ans+MOD) %MOD;
}


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

    ll modinv(ll k)
    {
        return Power(k, MOD-2);
    }

    void precompute()
    {
        fact[0]=fact[1]=1;
        for(ll i=2;i<N;i++)
        {
            fact[i]=fact[i-1]*i;
            fact[i]%=MOD;
        }
        invfact[N-1]=modinv(fact[N-1]);
        for(ll i=N-2;i>=0;i--)
        {
            invfact[i]=invfact[i+1]*(i+1);
            invfact[i]%=MOD;
        }
    }

    ll nCr(ll x, ll y)
    {
        if(y>x)
            return 0;
        ll num=fact[x];
        num*=invfact[y];
        num%=MOD;
        num*=invfact[x-y];
        num%=MOD;
        return num;
    }


std::vector<ll> adj[100005];
void fu(ll node,ll res){
	ll cnt=0;
	if(res==0) cnt=1;
	else cnt=2;
	ans=((ans%MOD)*(nCr(k-res,1)%MOD))%MOD;
	visited[node]=1;
	for(auto kk:adj[node]){
		if(!visited[kk]) fu(kk,cnt++);
	}

}

int main(){
	ll n;
	IOS
	
	cin>>n>>k;
	ans=1;
	//can=true;
	precompute();
	visited.resize(n+1,0);
	
	ll aa,bb;
	
	
	fo(i,n-1){
		cin>>aa>>bb;
		adj[aa].pb(bb);
		adj[bb].pb(aa);


	}
	fu(1,0);
	cout<<ans<<endl;


}

Measured memory_bytes: 24448
abcd = input()
n = len(abcd) - 1
form_list = []
for i in range(2 ** n):
    form = abcd[0]
    for j in range(n):
        if ((i >> j) & 1):
            form += "+" + abcd[j + 1]
        else:
            form += "-" + abcd[j + 1]
    form_list.append(form)
#form_list
flag = False
for formula in form_list:
    if eval(formula) == 7:
        #print(formula)
        flag = True
        break
if flag:
    print(formula + "=7")

Measured memory_bytes: 3064
var a,b,i,i_done,i_done2:integer;
    cake:array[1..16] of integer;
begin
    read(a);//a:=11;
    read(b);//b:=4;
    
    i_done:=0;
    for i:=1 to 16 do begin
        if (i mod 2 = 0)and(cake[i]=0)and(i_done<a) then begin cake[i]:=1; inc(i_done);end;
        end;
    
    i_done2:=0;
    for i:=1 to 16 do begin
        if (i mod 2 = 1)and(cake[i]=0)and(i_done2<b) then begin cake[i]:=2; inc(i_done2);end;
        end;
    
    if (i_done=a)and(i_done2=b)and(a+b<=16)and(a>=1)and(b>=1) then begin
        writeln('Yay!');
        end else begin
        writeln(':(');
        end;
    
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    lli n,m;
    cin>>n>>m;
    lli div=m/2;
    
    if(n<2*2*m && n%2==0)
    {
        for(int i=1;i<=m;i++)
        {
            if(div)
            {
            cout<<i<<" "<<2*m-i+2<<endl;
            div--;
            }
            else
            cout<<i<<" "<<2*m-i+1<<endl;
        }
    }
    else
    {
        for(int i=1;i<=m;i++)
        {
            cout<<i<<" "<<2*m-i+1<<endl;
        }
    }
    return 0;
}

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

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);++i)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);--i)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
//constexpr long long MOD = (ll) 1e9 + 7;
constexpr long long MOD = 998244353LL;
using ld=long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

struct Edge {
	ll to, rev;
    long double cap;
	Edge(ll _to, long double _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, long double cap, bool revFlag, long double revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve(){
    ll n;
    cin>>n;
    Array a(n);
    REP(i,n) cin>>a[i];
    sort(all(a));

    ll aa=1;
    REP(i,n){
        if(__builtin_mul_overflow(aa,a[i],&aa) || aa>(ll)1e18){
            cout<<-1<<en;
            return;
        }
    }
    cout<<aa<<en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	
	solve();
	//ll t;cin>>t;REP(i,t) solve();

    return 0;
}


Measured memory_bytes: 3992
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld double 
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define BOOST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(v) v.begin(),v.end()
#define sl(a) a.size()
#define mod 1000000007 
#define lcm(a,b) (a*b)/__gcd(a,b)
#define MAX1 100006
#define f first
#define s second
#define pi 2*acos(0.0)
void solve()
{
    ll n,a,b;  cin>>n>>a>>b;
    cout<<min(n*a,b);
}
int main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt","r",stdin);
    //for getting error from error.txt
    freopen("error.txt", "w", stderr);
    // for writing output to output.txt
    freopen("output.txt","w",stdout);
    #endif
    BOOST
    int T=1;  //cin>>T;
    while(T--) solve();
    cerr<<"Time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<"\n";
    cerr<<"My CLOCKS_PER_SEC= "<<CLOCKS_PER_SEC<<"\n";
    return 0;
}

Measured memory_bytes: 3752