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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;

const int N = 200012;
const int LOGN = 18;

int n , a , b,p[N],cost[N];

int color[N],res,f1,f2;
bool vis[N];
vector<int> g[N];

void dfs(int u , int c){
	if(vis[u])
		return;
	vis[u] = 1;
	res++;
	for (int i = 0; i < g[u].size(); ++i){
		int v = g[u][i];
		if(color[v] == -1 || color[v] == c){
			if(!vis[v]){
				dfs(v,c);
			}
		}
	}
}
int main() {
//	freopen("input.txt", "r", stdin);
	memset(cost,-1,sizeof cost);
	memset(color,-1,sizeof color);
	scanf("%d",&n);
	for (int i = 0; i < n-1; ++i){
		scanf("%d%d",&a,&b);
		g[a].push_back(b);
		g[b].push_back(a);
	}
	color[1] = 1;
	color[n] = 0;
	queue<int> q;
	q.push(1);
	cost[1] = 0;
	p[1] = -1;
	while(q.size()){
		int src = q.front();
		q.pop();
		for (int i = 0; i < g[src].size(); ++i){
			int v = g[src][i];
			if(cost[v] == -1){
				cost[v] = cost[src] + 1;
				p[v] = src;
				q.push(v);
			}
		}
	}
	int cur = n;
	vector<int> path;
	while(cur != 1){
		if(cur != n)
			path.push_back(cur);
		cur = p[cur];
	}
	for (int i = 0; i < path.size(); ++i){
		if(i < path.size()/2){
			color[path[i]] = 0;
		}else{
			color[path[i]] = 1;
		}
	}
	dfs(1,1);
	f1 = res;
	memset(vis,0,sizeof vis);
	res = 0;
	dfs(n,0);
	f2 = res;
	if(f2 >= f1){
		cout << "Snuke" << endl;
	}else{
		cout << "Fennec" << endl;
	}
	return 0;
}

Measured memory_bytes: 13048
#include<bits/stdc++.h>
#define int long long
const int inf=1145141919810893;
const int mod=1000000007;
using namespace std;
template<class T>bool chmin(T &a,const T &b){
	if(a>b){
		a=b;
		return true;
	}
	return false;
}
template<class T>bool chmax(T &a,const T &b){
	if(a<b){
		a=b;
		return true;
	}
	return false;
}
template<class T>void debug(T *a,int l,int r,const char *name){
	for(int i=l;i<r;i++)
		cout<<name<<"["<<i<<"]="<<a[i]<<endl;
}
int p[114514];
int K;
signed main(){
	int i,j;
	cin>>K;
	for(i=0;i<K;i++)
		cin>>p[i];
	int ma=2,mi=2;
	for(i=K-1;i>=0;i--){
		if(p[i]>ma||((mi+p[i]-1)/p[i])*p[i]>ma){
			cout<<"-1"<<endl;
			return 0;
		}
		mi=((mi+p[i]-1)/p[i])*p[i];
		ma=(ma/p[i])*p[i]+p[i]-1;
	}
	cout<<mi<<" "<<ma<<endl;
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    map<string, ll> mp;
    rep(i,n) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        mp[s]++;
    } 
    ll ans = 0;
    for (auto x : mp) {
        ll t = x.second;
        if (t != 1) {
            ans += (t*(t-1))/2;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11368
N, K = map(int,input().split())
A = [int(x) for x in input().split()]

l = 0
r = max(A) + 1

while(l+1<r):
    m = (l+r)//2
    count = 0
    for a in A:
        count += (a-1) // m
    
    if count > K:
        l = m
    else:
        r = m
print(r)



Measured memory_bytes: 30796
#include<stdio.h>
int main(void)
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a<=b&&b<=c){
		printf("%d %d %d\n",a,b,c);
	}
	else if(a<=c&&c<=b){
		printf("%d %d %d\n",a,c,b);
	}
	else if(b<=a&&a<=c){
		printf("%d %d %d\n",b,a,c);
	}
	else if(b<=c&&c<=a){
		printf("%d %d %d\n",b,c,a);
	}
	else if(c<=a&&a<=b){
		printf("%d %d %d\n",c,a,b);
	}
	else if(c<=b&&b<=a){
		printf("%d %d %d\n",c,b,a);
	}
	return 0;
}


Measured memory_bytes: 2760
import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M = map(int, readline().split())
    G = [[] for _ in range(N)]
    for _ in range(M):
        u, v = map(int, readline().split())
        G[u - 1].append(v - 1)
    S, T = map(int, readline().split())
    S -= 1
    T -= 1

    dist = [[-1] * 3 for _ in range(N)]
    dist[S][0] = 0
    queue = deque([(S, 0)])
    while queue:
        v, step = queue.popleft()
        if step == 0 and v == T:
            break

        for nv in G[v]:
            if dist[nv][(step - 1) % 3] != -1:
                continue
            dist[nv][(step - 1) % 3] = dist[v][step] + 1
            queue.append((nv, (step - 1) % 3))

    if dist[T][0] == -1:
        print(-1)
    else:
        print(dist[T][0] // 3)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 100316
#include <stdio.h>
#include <stdlib.h>

int getNumberOfLine();
int* CreatArrayThroughNumbersOfElements(int numbersOfElements);
int MaximumProfitFromArray(int* array, int number);

int main(void)
{
	int numbersOfLine = getNumberOfLine();
	int* moneyArray = CreatArrayThroughNumbersOfElements(numbersOfLine);
	int max = MaximumProfitFromArray(moneyArray, numbersOfLine);
	printf("%d\n", max);
}

int getNumberOfLine()
{
	int input;
	scanf("%d", &input);
	return input;
}

int* CreatArrayThroughNumbersOfElements(int numbersOfElements)
{
	int *p = (int*) malloc(numbersOfElements * sizeof(int));
	int i;
	for (i = 0; i < numbersOfElements; i++)
		scanf("%d", p + i);
	return p;
}

int MaximumProfitFromArray(int* array, int number)
{
	int i;
	int front, late;
	int minInSearchedElemets = *(array + 0);
	int subOfMaxInNotSearchedElements = 1, maxInNotSearchedElements = *(array + 1);
	int maxProfit = *(array + 1) - *(array);
	for (i = 1; i < number; i++)
	{
		if (*(array + i) > *(array + subOfMaxInNotSearchedElements))
		{
			subOfMaxInNotSearchedElements = i;
		}
	}
	maxInNotSearchedElements = *(array + subOfMaxInNotSearchedElements);
	// printf("In 47 lines, maxProfit = %d ", maxProfit);
	// printf("subOfMaxInNotSearchedElements = %d ", subOfMaxInNotSearchedElements);
	// printf("maxInNotSearchedElements = %d\n", maxInNotSearchedElements);
	// printf("minInSearchedElemets = %d\n", minInSearchedElemets);
	// printf("maxProfit = %d\n", maxProfit);


	for (front = 0; front < number - 1; front++)
	{
		if (*(array + front) > minInSearchedElemets)
		{
			// printf("front = %d, first if continue; now minInSearchedElemets = %d\n", front, minInSearchedElemets);
			continue;
		}
		minInSearchedElemets = *(array + front);
		// printf("change min to: %d\n", minInSearchedElemets);
		if (subOfMaxInNotSearchedElements > front)
		{
			if (maxProfit < maxInNotSearchedElements - *(array + front))
				maxProfit = maxInNotSearchedElements - *(array + front);
			continue;
		}
		subOfMaxInNotSearchedElements = front + 1;
		for (i = front + 1; i < number; i++)
		{
			// printf("now minInSearchedElemets = %d, and i = %d\n", minInSearchedElemets, i);
			if (*(array + i) > *(array + subOfMaxInNotSearchedElements))
			{
				subOfMaxInNotSearchedElements = i;
			}
		}
		maxInNotSearchedElements = *(array + subOfMaxInNotSearchedElements);
		// printf("now min = %d, maxInNotSearchedElements = %d\n", minInSearchedElemets, maxInNotSearchedElements);
		if (maxProfit < maxInNotSearchedElements - *(array + front))
		{
			// printf("front = %d, when min = %d\n", front, minInSearchedElemets);
			maxProfit = maxInNotSearchedElements - *(array + front);
		}

	}

	return maxProfit;
}


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

int main() {
  int N;
  cin >> N;
  int x = 0;
  
  for (int i = 0; i < N; i++){
    string S;
    cin >> S;
    
    if (S == "Y"){
      x = 1;
      break;
    }
  }
  
  if (x == 0){
    cout << "Three" << endl;
  }
  else if (x == 1){
    cout << "Four" << endl;
  }
  
}

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

void play_card_game(int &taro_win, int &hanako_win)
{
  string taro, hanako;
  cin >> taro >> hanako;
  if (taro > hanako)
  {
    taro_win += 3;
  }
  else if (taro < hanako)
  {
    hanako_win += 3;
  }
  else
  {
    taro_win++;
    hanako_win++;
  }
}

int main()
{
  int taro_win = 0;
  int hanako_win = 0;

  int game_count;
  cin >> game_count;
  for (int i = 0; i < game_count; i++)
  {
    play_card_game(taro_win, hanako_win);
  }
  cout << taro_win << ' ' << hanako_win << endl;
}



Measured memory_bytes: 3144
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int N,D;
    cin >> N >> D;
    
    vector<vector<int>> X(N,vector<int>(D));
    
    for(int i = 0;i < N;i++){
        for(int j = 0;j < D;j++){
            cin >> X[i][j];
        }
    }
    int ans = 0;
    for(int i = 0;i < N - 1;i++){
        for(int j = i + 1;j < N;j++){
            int sum = 0;
            for(int k = 0;k < D;k++){
                sum += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
            }
            
            for(int l = 1;l * l <= sum;l++){
                if(l * l == sum){
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<cstring>
#include<algorithm> 
using namespace std;
const double pai=3.1415926535;

int main()
{
	int h1,s1,h2,s2;
	cin>>h1>>s1>>h2>>s2;
	while(h1>0&&h2>0)
	{
		h2-=s1;
		if(h2<=0)
			break;
		h1-=s2;
	}
	if(h1<=0)
		cout<<"No";
	else
		cout<<"Yes";
}
 

Measured memory_bytes: 3636
from sys import stdin
N = int(stdin.readline().rstrip())
l = stdin.readline().rstrip().split()

n = 0
for i in range (len(l)):
  if int(l[i]) == i+1:
    n += 1
  else:
    n += 0
if n == N or n == N-2:
  print('YES')
else:
  print('NO')

Measured memory_bytes: 3060
// テ・ツ淞コテヲツ慊ャテ」ツδ?」ツδウテ」ツδ療」ツδャテ」ツδシテ」ツδ?(テァツクツョテ・ツーツ湘ァツ可?

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
typedef pair<int, int> pii;
typedef long long ll;
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int M, N;
bool used[8000000];

signed main() {
    while(cin >> M >> N, M || N) {
        memset(used, false, sizeof(used));
        int p = M;
        rep(i,0,N) {
            while(used[p]) p++;
            int k = p;
            for(int j=k; j<8000000; j+=k) {
                used[j] = true;
            }
        }
        while(used[p]) p++;
        cout << p << endl;
    }
    return 0;
}

Measured memory_bytes: 10932
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;

void mainmain(){
	int n;
	while(cin>>n,n){
		vint v(n);
		rep(i,n) cin>>v[i];
		int a=31;
		int c=0;
		cout<<a<<endl;
		while(a!=1){
			a-=v[c%n];
			cout<<a<<endl;
			a-=5-v[c%n];
			c++;
			cout<<a<<endl;
		}
		cout<<0<<endl;
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

Measured memory_bytes: 1192
#include <cstdio>
#include <algorithm>
#define MOD 100000
using namespace std;
int main() {
    int n, m;
    scanf("%d%d",&n,&m);
    int yado[n];
    yado[0]=0;
    scanf("%d",&yado[1]);
    for (int i=2; i<n; i++) {
        scanf("%d",&yado[i]);
        yado[i]+=yado[i-1];
    }
    int npos=0, in, res=0;
    for (int i=0; i<m; i++) {
        scanf("%d",&in);
        int s=npos, e=npos+in;
        npos=e;
        if (s>e) swap(s, e);
        // printf("%d %d\n",s,e);
        res += yado[e]-yado[s];
        res %= MOD;
    }
    printf("%d\n",res);
}

Measured memory_bytes: 1104
//rustc 1.39.0

fn main() {

    let mut s = String::new(); // バッファを確保
    std::io::stdin().read_line(&mut s).unwrap(); // 一行読む。失敗を無視
    let X : i32 = s.trim().parse().ok().unwrap();
    
    if X >= 30 {
        println!("Yes");
    } else {
        println!("No");
    }
}

Measured memory_bytes: 2128
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include <math.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_sz_desc(const void* a, const void* b) {
    return *((size_t*)a) > * ((size_t*)b) ? -1 : 1;
}

int compare_i64_asc(const void* a, const void* b) {
    return *((int64_t*)a) < *((int64_t*)b) ? -1 : 1;
}

int compare_c_asc(const void* a, const void* b) {
    return *((char*)a) < *((char*)b) ? -1 : 1;
}

int compare_c_desc(const void* a, const void* b) {
    return *((char*)a) > * ((char*)b) ? -1 : 1;
}

int compare_f(const void* a, const void* b) {
    return *((int64_t*)a) < *((int64_t*)b) ? -1 : 1;
}

int compare_f2(const void* a, const void* b) {
    return *((uint64_t*)a) > * ((uint64_t*)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
    size_t result = 1;

    for (size_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
    uint64_t result = 1;

    for (uint64_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t gcdU64(uint64_t m, uint64_t n)
{
    uint64_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

static size_t gcdZu(size_t m, size_t n) {
    size_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

int main(void) {
    uint64_t N,A,B;

    scanf("%"PRIu64" %"PRIu64" %"PRIu64, &N, &A, &B);

    if (B < A) {
        puts("0");

        return 0;
    }

    if (N == 1) {
        puts(A == B ? "1" : "0");
    }
    else {
        printf("%"PRIu64, (B - A) * (N - 2) + 1);
    }

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
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);
    int n;
    cin >> n;
    vector<int> x(n),y(n);
    rep(i,n) cin >> x[i] >> y[i];
    auto dist = [&](int i, int j)->double{
        int dx = x[i]-x[j];
        int dy = y[i]-y[j];
        return sqrt(dx*dx+dy*dy);
    };
    vector<int> perm(n);
    rep(i,n) perm[i] = i; //1-n-1
    double ave = 0;
    int perm_num = 0;
    do {
        perm_num++;
        double dist_sum = 0;
        rep(i, n-1) dist_sum+=dist(perm[i], perm[i+1]);
        ave+=1.0*dist_sum;
    } while(next_permutation(perm.begin(), perm.end()));
    ave /= perm_num;
    printf("%8.10lf\n",ave);
}

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

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
char capitalize(char c) { return static_cast<char>(std::toupper(static_cast<unsigned char>(c))); }
// template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
// template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

#define int long long
#define YES "Yes"
#define NO  "No"

#define forit(v) for(auto it = v.begin(); it != v.end(); ++it)

using namespace std;

int f(int n, int x) {
  if (n == -1) return 0;
  else return n / x + 1;
}

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

  int num = 0;
  // num = numeric_limits<int>::max();
  // num = numeric_limits<int>::min();
  bool flag = false;
  // flag = true;

  int a, b, x; cin >> a >> b >> x;

  num = f(b, x) - f(a - 1, x);
  
  cout << num << endl;
  // cout << (flag ? YES : NO) << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    scanf("%d",&t);
    while(t>0)
    {
        int x=t%10;
        t/=10;
        if(x==7)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 3772
#include <iostream>
#include <cstdio>

int main()
{
    int a, b;
    double d;
    
    std::cin >> a >> b;
    
    std::cout << a / b << std::endl;
    std::cout << a % b << std::endl;

    d = 1.0 * a / b;
    std::printf("%.5lf", d);
}


Measured memory_bytes: 3224
#include <stdio.h>
static char cs[256];    // chars
void init(void) {
    int i;
    for (i = 0; i < 256; ++i) {
        cs[i] = i;
        if (i >= 'A' && i <= 'Z' || i >= 'a' && i <= 'z') cs[i] ^= 0x20;
    }
}
int main(void) {
    int c;
    init();
    while ((c = getchar()) != EOF) putchar(cs[c]);
    return 0;
}

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

using ll = long long;
using pii = pair<int, int>;

const int MOD = 1000000007; // or 998244353
struct mint
{
    unsigned int n;

    mint() : n(0) {}
    mint(int n) : n((n%MOD+MOD)%MOD) {}
    mint(long long n) : n((n%MOD+MOD)%MOD) {}
    mint(unsigned int n) : n(n%MOD) {}
    mint& operator=(const mint &m) { n = m.n; return *this; }

    mint operator+(mint m) { return (n+m.n)%MOD; }
    mint operator-(mint m) { return (n+MOD-m.n)%MOD; }
    mint operator*(mint m) { return (1LL*n*m.n)%MOD; }
    mint pow(long long int p) { mint r = 1, a = *this; while(p) { if(p&1) r=r*a; a=a*a; p>>=1; } return r; }
    mint inv() { return pow(MOD-2); }
    mint operator/(mint m) { return m.inv()*n; }

    mint operator+=(mint m) { n=(n+m.n)%MOD; return *this; }
    mint operator-=(mint m) { n=(n+MOD-m.n)%MOD; return *this; }
    mint operator*=(mint m) { n=(1LL*n*m.n)%MOD; return *this; }
    mint operator/=(mint m) { n=(m.inv()*n).n; return *this; }
    bool operator==(mint m) { return n == m.n; }

    friend std::ostream& operator<<(std::ostream& os, const mint& n) { return os<<n.n; }
};

int n, k;
vector<int> adj[101010];
mint dfs(int v, int p, bool isRoot=false)
{
  mint r = 1;
  if(!isRoot && adj[v].size() == 1) {
    return r;
  }

  int c = k;
  if(isRoot) c -= 1; else c -= 2;
  int d = adj[v].size();
  if(isRoot) d -= 0; else d -= 1;

  for(int i=c; i>c-d; i--) r *= i;

  for(int u : adj[v]) {
    if(u == p) continue;
    r *= dfs(u, v);
  }

  return r;
}

int main(int argc, char **argv)
{
#ifdef LOCAL
  freopen("in.txt", "r", stdin);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);

  cin >> n >> k;
  for(int i=0; i<n-1; i++) {
    int x, y; cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }

  for(int i=1; i<=n; i++) {
    if(adj[i].size()+1 > k) {
      cout << 0 << endl;
      return 0;
    }
  }

  cout << dfs(1, -1, true)*k;

  return 0;
}

Measured memory_bytes: 10496
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

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; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<60;
constexpr double eps = (1e-9);

constexpr ll mod = 998244353;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return x ? mod - x : 0;}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}

  friend ostream& operator << (ostream& os, const mint& m) noexcept {
    return os << m.x;
  }

  friend istream& operator<< (istream& is, mint& m) noexcept {
    return is >> m.x;
  }
};

struct combination {
  vector<mint> fact, ifact;  // 階乗と階乗の逆元
  combination(int n):fact(n+1),ifact(n+1) {  // 階乗と階乗の逆元を n まで求める
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

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

  int n, m, k;
  cin >> n >> m >> k;

  combination comb(n);

  mint ans = 0;
  for (int i = 0; i <= k; i++) {
    mint x = (m-1);
    ans += comb(n-1, i) * x.pow(n-i-1) * m;
  }

  cout << ans << endl;

  return 0;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

using Row = vector<int64>;
using Mat = vector<Row>;

vector<string> a;

int main(void){
	int64 H, W;
	cin >> H >> W;
	a.resize(H);
	REP(i, H) cin >> a[i];
	Mat dp(H, Row(W, 0));
	dp[0][0] = 1;
	auto in = [&](int32 y, int32 x){
		return y < H && x < W && a[y][x] != '#';
	};
	REP(i, H){
		REP(j, W){
			if(in(i+1, j))
				(dp[i+1][j] += dp[i][j]) %= mod;
			if(in(i, j+1))
				(dp[i][j+1] += dp[i][j]) %= mod;
		}
	}
	cout << dp[H-1][W-1] << endl;
}


Measured memory_bytes: 9216
#include<iostream>
#include<string>
using namespace std;
int ans;
int w,h;
string map[40];
int vec[4][2]={{0,1},{0,-1},{-1,0},{1,0}};
void move(int x,int y){
	ans++;
	map[x][y]='#';
	for(int i=0;i<4;i++){
		if((x+vec[i][0]>=0)&&(y+vec[i][1]>=0)&&(x+vec[i][0]<h)&&(y+vec[i][1]<w)){
			if(map[x+vec[i][0]][y+vec[i][1]]=='.'){
				move(x+vec[i][0],y+vec[i][1]);
			}
		}
	}
	return;
}

int main(){
	while(cin>>w>>h,w){
		ans=0;
		int fx,fy;
		for(int i=0;i<h;i++){
			cin>>map[i];
		}
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(map[i][j]=='@'){
					fx=i;
					fy=j;
					break;
				}
			}
		}
		move(fx,fy);
		cout<<ans<<endl;
		
	}
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
//      freopen("q.in","r",stdin);
//      freopen("q.out","w",stdout);
      int n;
      cin>>n;
      vector<string>arr(n);
      vector<int>T(n);
      int ans=0;
      for(int i=0;i<n;i++)cin>>arr[i]>>T[i];
      string X;
      cin>>X;
      int ind=find(all(arr),X)-arr.begin();
      for(int i=ind+1;i<n;i++)ans+=T[i];
      cout<<ans;
}


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

long long mod = 1000000007;
vector<long long> p;
int n, k;

void init()
{
	p[1] = 1;
	for (long long i = 2; i <= n; ++i) {
		p[i] = p[i - 1] * i % mod;
	}
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

long long comb(long long a, long long b)
{
	if (a == b || b == 0) {
		return 1;
	}

	return ((p[a] * modinv(p[a - b], mod) % mod) * modinv(p[b], mod)) % mod;
}

int main()
{
	cin >> n >> k;

	p.resize(n + 1);
	init();

	vector<int> a(n);
	for (auto& i : a) {
		cin >> i;
	}

	sort(a.begin(), a.end());

	long long mx = 0;
	long long mn = 0;
	for (int i = 0; i <= n - k; ++i) {
		mn = (mn + (a[i] * comb(n - i - 1, k - 1)) % mod) % mod;
		mx = (mx + (a[n - i - 1] * comb(n - i - 1, k - 1)) % mod) % mod;
	}

	long long ret = (mx - mn) % mod;
	if (ret < 0) {
		ret += mod;
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <vector>

#define PI 3.1415927

using namespace std;

struct student{
    int x;
    int y;
}ans[55],res[55];

int main(){
    int n,m;
    cin>>n>>m;
    for (int i=0;i<n;i++){
        cin>>ans[i].x>>ans[i].y;
    }
    for (int i=1;i<=m;i++){
        cin>>res[i].x>>res[i].y;
    }
    for (int i=0;i<n;i++){
        int b=1;
        int x=ans[i].x;
        int y=ans[i].y;
        int mi=900000001;
        for (int j=1;j<=m;j++){
            int k=abs(x-res[j].x)+abs(y-res[j].y);
            if (k<mi){
                mi=k;
                b=j;
            }
        }
        cout<<b<<endl;
    }

}


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

int main(){
  int l,r,d;
  cin >> l >> r >> d;
  int c = 0;
  for(int i = l; i <= r; i++){
    if(i%d==0) c++;
  }
  cout << c << endl;
}

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

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

    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '0') ans += "0";
        else if (s[i] == '1') ans += "1";
        else if (s[i] == 'B') {
            if (!ans.empty()) ans.pop_back();
        } 
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

int main(){
    int n;
    cin >> n;
    vector<int> l(4);
    rep(i, n) {
        char a;
        cin >> a;
        if(a == 'P') l[0]++;
        else if(a == 'W') l[1]++;
        else if(a == 'G') l[2]++;
        else l[3]++;
    }

    int ans = 0;
    rep(i, 4) {
        if(l[i] > 0) ans++;
    }
    if(ans == 3) cout << "Three" << endl;
    else cout << "Four" << endl;

    return 0;
}

Measured memory_bytes: 3600
n = int(input())
li = list(map(int,input().split())) + [0]
counter = 0
while (max(li) > 0):
  for r in range(len(li)):
    if li[r] > 0:
      break
  
  for l in range(r, len(li)):
    if li[l] == 0:
      break

  li = [li[i]-1 if i >= r and i < l else li[i] for i in range(len(li))]

  counter += 1

print(counter)


Measured memory_bytes: 3060
/*  AC祈願アンコウ
   　／￣＼
   ○    ／￣￣￣＼ヘ
    　 /・　 ・　 ＼>   
    ／￣￣￣＼　　  Ｖ| 
   ｜  ―――  ｜      ｜|
    ＼＿＿＿／　　  ∧|
    　　＼　　　　／
    　　　￣￣￣￣
*/

#include <bits/stdc++.h>
using namespace std;
 
//#define int ll

typedef int64_t ll;
static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define SZ(a) signed((a).size())
#define LEN(a) signed((a).length())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
#define ALL(x) (x).begin(),(x).end()
#define YESNO(x) puts((x)?"YES":"NO")
#define YesNo(x) puts((x)?"Yes":"No")

signed main(){
    int n,d,x;
    cin >> n >> d >> x;

    REP(i,n){
        int tmp;
        cin >> tmp;
        x += (d-1)/tmp + 1;    
    }

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

    return 0;
}

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


int a[100010];
int main (int argc, char const *argv[])
{
    int s;
    cin>>s;
    a[0]=s;
    
    for(int i = 0; i < 100009; i++)
    {
        
        if (a[i]%2==0) {
            a[i+1]=a[i]/2;
        }
        else
        {
            a[i+1]=a[i]*3+1;
        }
            
    }
    
    int b[10000];
    for(int i = 0; i < 10000; i++)
    {
        b[i]=0;
    }
    int ans=0;
    
    for(int i = 0; i < 100010; i++)
    {
        b[a[i]]++;
        
        if (b[a[i]]==2) {
            ans=i+1;
            break;
        }
        
    }
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 640
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9+7;

int main(){

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

    int cnt = 1;
    for (int i = 0; i < N; ++i) {
        if(a[i]==cnt){
            cnt++;
        }
    }
    int ans=0;
    if(cnt==1) {
        cout<<-1<<endl;
        return 0;
    }
    ans = N+1-cnt;

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

Measured memory_bytes: 1024
#include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<functional>
#define scanf_s scanf
#define fir first
#define sec second
#define mp make_pair
#define mt make_tuple
#define pub push_back
using namespace std;
typedef long long int llint;
const llint one = 1;
const llint big = (one<<30);


int main(void){
	
	__int128 N,K,ans;
	llint a,b;
	scanf("%lld %lld",&a,&b);
	N=a;K=b;
	N--;
	if(N==0){printf("0\n");return 0;}
	ans=1;
	N--;
	for(;N>0;N--){
		ans=(K*ans+(K-1))/(K-1);
	}
	a=ans;
	printf("%lld\n",a);
	return 0;
}

Measured memory_bytes: 2712
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

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

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;

void dfs(int n, string s)
{
    if(n == 0){
        cout << s << endl;
    }else{
        int mx = 'a';
        for(int i = 0; i < s.size(); i++){
            mx = max(mx,(int)s[i]);
        }
        for(int i = 'a'; i <= mx+1; i++){
            
            string t = s+(char)i;
            dfs(n-1,t);
            
        }
    }
}

int main()
{
    int n; cin >> n;
    dfs(n-1,"a");
}

Measured memory_bytes: 1536
#include <iostream>
using namespace std;
int main(void){
int n,m,t[100],p,x,sum=0,i;
cin>>n;
for(i=0;i<n;i++){
cin>>t[i];
sum+=t[i];
}
cin>>m;
while(m--){
cin>>p>>x;
cout<<sum-t[p-1]+x<<endl;
}
return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef vector<vl> mt;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<string> vs;
typedef vector<vs> table;
typedef vector<vl> v2;
typedef vector<v2> v3;
typedef vector<v3> v4;


const ll e5 = 1 << 20;
const ll mods[] = {998244353, 1000000007, 1000000009};
const ll bases[] = {997, 1009, 1013};
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 50;

ll n,m;
vl a;
vl dp;
vl idx;

int main(){
  cin >> n >> m;
  a = vl(m);
  dp = vl(1<<n,INF);
  idx = vl(1<<n);
  iota(idx.begin(),idx.end(),0ll);
  sort(idx.begin(),idx.end(),[](ll a,ll b){
    return __builtin_popcount(a) < __builtin_popcount(b);
  });
  for(ll i = 0;i < m;i++){
    cin >> a[i];
    ll b;
    cin >> b;
    ll x = 0;
    for(ll j = 0;j < b;j++){
      ll c;
      cin >> c;
      x |= (1<<(c-1));
    }
    dp[x] = min(dp[x],a[i]);
  }
  for(ll i : idx){
    for(ll j = 0;j < (1<<n);j++){
      dp[i|j] = min(dp[i|j],dp[i]+dp[j]);
    }
  }
  // for(ll i = 0;i < (1<<n);i++){
  //   cerr << dp[i] << endl;
  // }
  if(dp[(1<<n)-1] == INF){
    cout << -1 << endl;
  }else{
    cout << dp[(1<<n)-1] << endl;
  }
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG

#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

#include <cmath>

#define int long long

using namespace std;

signed main() {
  string s;
  cin >> s;
  int n = s.size();

  static int dp[(int)1e5 + 1][13] = { };
  const int MOD = 1e9 + 7;

  for (int i = 0; i < n; i++) {
    if (s[i] == '?') {
      for (int num = 0; num < 10; num++) {
        if (i == 0) {
          dp[i][num] = 1;
        } else {
          for (int j = 0; j < 13; j++) {
            dp[i][(10 * j + num) % 13] += dp[i - 1][j];
            dp[i][(10 * j + num) % 13] %= MOD;
          }
        }
      }
    } else {
      int num = s[i] - '0';

      if (i == 0) {
        dp[i][num] = 1;
      } else {
        for (int j = 0; j < 13; j++) {
          dp[i][(10 * j + num) % 13] += dp[i - 1][j];
          dp[i][(10 * j + num) % 13] %= MOD;
        }
      }
    }
  }

  int ans = dp[n - 1][5];

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 10624
#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define REPI(i,a,b) for(int (i)=int(a);i<int(b);++i)
#define INF 10000000

int main(void){
  using namespace std;
  int N,X;
  cin >> N >> X;
  vector<int> L;
  vector<int> bound;
  bound.push_back(0);
  REP(i,N){
    int ipt;cin >> ipt;
    L.push_back(ipt);
    bound.push_back(accumulate(L.begin(),L.end(),0));
  } 
  cout << count_if(bound.begin(),bound.end(),[X](int x){return x<=X;});
}

Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
using namespace std;
typedef long long ll;

int main(){
  int A,B,K;
  vector<int> vect;
  cin >> A >> B >> K;
  
  for (int i = 1; i <= 100; i++){
    if (A%i == 0 && B%i == 0){
      vect.push_back(i);
    }
  }
  
  sort(vect.begin(), vect.end(),greater<int>());
  
  cout << vect[K-1];
  return 0;
}

Measured memory_bytes: 256
use proconio::*;

#[fastout]
fn run() {
    input! {
        n: usize,
        m: usize,
        mut e: [(usize, usize); m],
    }
    let mut cnt = vec![0; n];
    for e in e.iter_mut() {
        e.0 -= 1;
        e.1 -= 1;
        cnt[e.0] += 1;
        cnt[e.1] += 1;
    }
    let mut buf = vec![0usize; 2 * m];
    let mut buf = buf.as_mut_slice();
    let mut g = Vec::with_capacity(n);
    for c in cnt.iter() {
        let (x, y) = buf.split_at_mut(*c);
        g.push(x);
        buf = y;
    }
    for (a, b) in e {
        cnt[a] -= 1;
        g[a][cnt[a]] = b;
        cnt[b] -= 1;
        g[b][cnt[b]] = a;
    }
    let mut prev = vec![n; n];
    prev[0] = 0;
    let mut q = std::collections::VecDeque::new();
    q.push_back(0);
    while let Some(v) = q.pop_front() {
        for &u in g[v].iter() {
            if prev[u] == n {
                prev[u] = v;
                q.push_back(u);
            }
        }
    }
    println!("Yes");
    for p in prev.iter().skip(1) {
        println!("{}", *p + 1);
    }
}

fn main() {
    run();
}


Measured memory_bytes: 12960
n=int(input())
f=[list(map(int,input().split())) for _ in range(n)]
p=[list(map(int,input().split())) for _ in range(n)]
inf=float("inf")
ans=-inf
for i in range(1,2**10):
    cc=0
    for k in range(n):
        c=0
        for j in range(10):
            if ((i>>j)&1) and f[k][j]:
                c+=1
        cc+=p[k][c]
    ans=max(ans,cc)
print(ans)


Measured memory_bytes: 3064
package main
import "fmt"
func main() {
  var c11,c12,c13,c21,c22,c23,c31,c32,c33 int
  fmt.Scan(&c11,&c12,&c13)
  fmt.Scan(&c21,&c22,&c23)
  fmt.Scan(&c31,&c32,&c33)
  if c12-c11 != c22-c21 || c12-c11 != c32-c31 ||
  c13-c11 != c23-c21 || c13-c11 != c33-c31 ||
  c21-c11 != c22-c12 || c21-c11 != c23-c13 ||
  c31-c11 != c32-c12 || c31-c11 != c33-c13 {
    fmt.Println("No")
  } else {
    fmt.Println("Yes")
  }
}

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

int main() {
	string abcd;
  cin >> abcd;
  vector<int> nums(4);
  for(int i = 0; i < 4; i++){
    nums.at(i) = abcd[i] - '0';
  }
  vector<char> ops = {'+', '-'};
  for(int i = 0; i < 2; i++){
    for(int j = 0; j < 2; j++){
      for(int k = 0; k < 2; k++){
        int sum = nums.at(0);
        switch (i)
        {
        case 0:
          sum += nums.at(1);
          break;
        case 1:
          sum -= nums.at(1);  
          break;
        }
        switch (j)
        {
        case 0:
          sum += nums.at(2);
          break;
        case 1:
          sum -= nums.at(2);  
          break;
        }
        switch (k)
        {
        case 0:
          sum += nums.at(3);
          break;
        case 1:
          sum -= nums.at(3);  
          break;
        }
        if(sum == 7){
          cout << nums.at(0) << ops.at(i) << nums.at(1) << ops.at(j) << nums.at(2) << ops.at(k) << nums.at(3) << "=7" << endl;
          return 0;
        }
      }
    }
  }
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<map>
#include<iostream>
using namespace std;
int main(){
    int x;
    scanf("%d",&x);
    map<int,int> value;
    for(int i=-120;i<=120;i++){
        value[i*i*i*i*i]=i;
    }
    map<int,int>::iterator iter;
    iter=value.begin();
    while(iter!=value.end()){
     if(value.find(x+(*iter).first)!=value.end()){
         cout<<value[x+(*iter).first]<<" "<<value[(*iter).first] <<endl;
         break;
     }
     iter++;
    }
    return 0;

}

Measured memory_bytes: 3716
n, m = map(int, input().split())
store = []
cnt = 0
ans = 0
for _ in range(n) :
        a, b = map(int, input().split())
        comb = [a,b]
        store.append(comb)
store.sort()
for i in store:
        if cnt + i[1] <= m :
                ans += i[0]*i[1]
                cnt += i[1]
        else:
                ans += i[0] * (m - cnt)
                break
print(ans)

Measured memory_bytes: 20072
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: [i64; 5]
    }

    let mut ans = 0;
    let mut d = 0;
    for x in a {
        let y = if x % 10 == 0 { x } else { (x / 10 + 1) * 10 };
        ans += y;
        d = std::cmp::max(d, y - x);
    }

    println!("{}", ans - d);
}


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0; i<N; i++) cin >> a.at(i);
  
  int cnt=0;
  
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  for(int i=0; i<N; i++){
    if(i!=N-1){
      if(a.at(i)==a.at(i+1)) continue;
      else cnt++;
    }
    else cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,y; cin>>n>>y;
    for(int i=0; i<=2000; ++i) {
        for(int j=0; j<=2000; ++j) {
            int k = n - (i + j);
            if(k >= 0) {
                if(1LL*10000*i + 5000*j*1LL + 1000*k*1LL == y) {
                    cout<<i<<" "<<j<<" "<<k<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<"-1 -1 -1"<<endl;

    return 0;
}



Measured memory_bytes: 256
s = input()
if len(s) % 2 == 1:
    s = s[:-1]
else:
    s = s[:-2]
while True:
    if s[:len(s)//2] == s[len(s)//2:]:
        print(len(s))
        exit()
    else:
        s = s[:-2]

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

const int MAXDATA = 100100;
vector<vector<int>> to(MAXDATA);
vector<bool> seen(MAXDATA, false);
vector<int> group(MAXDATA, -1);
int groupNum = 0;

void dfs(const vector<vector<int>> &graph, int v)
{
    seen[v] = true;
    group[v] = groupNum;
    for (auto nv : graph[v])
    {
        if (seen[nv])
            continue;
        group[nv] = groupNum;
        dfs(graph, nv);
    }
}

int main()
{
    int n, m, k;
    cin >> n >> m >> k;

    vector<vector<int>> friends(n);
    rep (i, m)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        friends[a].push_back(b);
        friends[b].push_back(a);
    }

    vector<int> c(k), d(k);
    rep (i, k)
    {
        cin >> c[i] >> d[i];
        c[i]--;
        d[i]--;
    }

    rep (i, n)
    {
        if (group[i] != -1)
            continue;
        dfs(friends, i);
        groupNum++;
    }

    vector<int> cnt(n, 0);
    rep (i, n)
        cnt[group[i]]++;

    vector<int> ans(n);
    rep (i, n)
        ans[i] = cnt[group[i]] - 1 - friends[i].size();

    rep (i, k)
        if (group[c[i]] == group[d[i]])
        {
            ans[c[i]]--;
            ans[d[i]]--;
        }

    rep (i, n)
        cout << ans[i] << " ";
    cout << endl;
    return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
#define FS              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll              long long int
#define ld              long double
#define pb              push_back
#define bp              __builtin_popcount
#define sz              size()
#define ff              first
#define ss              second
#define vll             vector<ll>
#define vbool           vector<bool>
#define vpll            vector<pair<ll,ll>>
#define pll             pair<ll,ll>
#define vllv            vector<vector<ll>>
#define setpri(x)       cout<<setprecision(x)<<fixed;
#define all(v)          v.begin(),v.end()
#define allr(v)         v.rbegin(),v.rend()
#define yesr {cout<<"YES"<<endl;return;}
#define nor {cout<<"NO"<<endl;return;}
// getline (std::cin,name);
ll MOD=1e9+7;
ll ceil1(ll n,ll x){return (n-1)/x+(n>0);}

ll gcd(ll a,ll b){return __gcd(a,b);}
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}

ll pow1(ll n,ll m ,ll mod=MOD );
ll pow2(ll n,ll k);

ll modinv(ll n,ll mod=MOD){  return pow1(n,mod-2,mod);}

bool func(pair<ll,ll> &a,pair<ll,ll> &b ){
        if(a.ff != b.ff)return a.ff < b.ff;
        return a.ss > b.ss;
}
ll const N=(ll)3e2+11;
ll const LG=(ll)log2(N)+1;


void solve(){
        ll i,j,k,l,n,m,x,y,z,r;
        
        cin>>n>>m;
        if(n<m){
                cout<<0<<endl;
        }else cout<<10<<endl;
        
        
}       
int main(){
        FS;
        
        ll i,j,k,n,m,x,y,z,q;
        q=1;
        // cin>>q;
        while(q--){
                solve();
        }
        return 0;
}


ll pow1(ll n,ll m,ll mod){
        if(m==0)return 1;
        
        if(m%2==0)return pow1((n*n)%mod,m/2,mod);
    	
    	return (pow1((n*n)%mod,m/2,mod)*n)%mod;
}

ll pow2(ll n,ll k){
        ll ans=1;
            while(k>0){
                if(k%2==1)ans=ans*n;
                n=n*n;
                k/=2;
            }
            return ans;
}

Measured memory_bytes: 3612
#include <iostream>

using namespace std;

// 素数判定
bool isPrime(int x)
{
	// 1 は例外的に素数じゃない判定しておく
	if(x == 1)
	{
		return false;
	}
	
	// 偶数をはじく
	if(x != 2 && x % 2 == 0)
	{
		return false;
	}
	
	//√x までの間で割り切れる数値があれば素数じゃない
	for(int i = 3; i*i <= x; i+=2)
	{
		if(x % i == 0)
		{
			return false;
		}
	}
	return true;
}

int main()
{
	int n, x;
	int prime_num = 0;
	
	cin >> n;
	for(int i = 0; i < n; i++)
	{
		cin >> x;
		if( isPrime(x) )
		{
			prime_num++;
		}
	}
	cout << prime_num << endl;
	
	return 0;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int S, W;
    cin >> S >> W;
    if (S > W)
    {
        cout << "safe" << endl;
    }
    else
    {
        cout << "unsafe" << endl;
    }
}

Measured memory_bytes: 3624