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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


int main() {
    li x, y;
    cin >> x >> y;
    if (y % 2 > 0) {
        puts("No");
        return 0;
    }
    cout << (y >= x * 2 && y <= x * 4 ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>

#define ZERO 0
#define TWO 2
#define THREE 3
#define TRUE 1
#define FALSE 0
#define INIT 0
#define INIT_INPUT 0
#define INIT_CNT 1
#define EXIT_SUCCESS 0
#define EVEN_DISC( x ) x % 2

static unsigned char prime_disc( unsigned long ulW_Dtestcase );

int main( void )
{
	unsigned long ulW_Dtestcase;
	unsigned short usW_Darray_count;
	unsigned short usW_Cinput_cnt;
	unsigned char ubW_Fcnt_flug;
	unsigned short usW_Cprime_cnt = INIT;

	scanf("%d", &usW_Darray_count);
	for( usW_Cinput_cnt = INIT_INPUT; usW_Cinput_cnt < usW_Darray_count; usW_Cinput_cnt++){
		scanf("%ld", &ulW_Dtestcase );
		ubW_Fcnt_flug = prime_disc( ulW_Dtestcase );
		if( ubW_Fcnt_flug == TRUE ){
			usW_Cprime_cnt++;
		}
		else{
			/*else?????????????????????????????\*/
		}
	}
	printf("%d\n", usW_Cprime_cnt);
	return EXIT_SUCCESS;
}

static unsigned char prime_disc( unsigned long ulW_Dtestcase )
{
	unsigned long ulW_Fbool_flug;
	unsigned long ulW_Dcalc;
	unsigned long ulW_Dcalc_sub;
	
	ulW_Dcalc = EVEN_DISC( ulW_Dtestcase );
	if( ulW_Dtestcase == TWO){
		return TRUE;
	}
	else if( ( ulW_Dtestcase < TWO ) || ( ulW_Dcalc == ZERO ) ){
		return FALSE;
	}
	ulW_Dcalc = THREE;
	ulW_Dcalc_sub = ulW_Dcalc * ulW_Dcalc;
	while( ulW_Dcalc_sub <= ulW_Dtestcase ){
		ulW_Fbool_flug = ulW_Dtestcase % ulW_Dcalc;
		if( ulW_Fbool_flug == FALSE ){
			return FALSE;
		}
		else{
			/*else?????????????????????????????\*/
		}
		ulW_Dcalc += TWO;
		ulW_Dcalc_sub = ulW_Dcalc * ulW_Dcalc;
	}
	return TRUE;
}

Measured memory_bytes: 596
#include<iostream>
using namespace std;
int main(){
  int N;
  cin>>N;
  int V[N];
  int C[N];
  int sum=0;
  int i;
  for(i = 0;i<N;i++){
    cin>>V[i];
  }
  for(i=0;i<N;i++){
    cin>>C[i];
  }
  for(i=0;i<N;i++){
    if(V[i]-C[i]>=0){
      sum+=V[i]-C[i];
    }
  }
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 256
import sys
import math
from collections import deque
import heapq
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def tami(n):
  if len(edge[n]) == 0:
    top[n-1] = True
  else:
    num = h[n-1]
    for x in edge[n]:
      if num <= h[x-1]:
        break
    else:
      top[n-1] = True

N,M = IL()
h = IL()
ab = [IL() for i in range(M)]

edge = [[] for i in range(N+1)]
for a,b in ab:
  edge[a].append(b)
  edge[b].append(a)

top = [False]*N
for i in range(1,N+1):
  tami(i)

ans = 0
for i in top:
  if i == True:
    ans += 1
print(ans)

Measured memory_bytes: 107384
#include <iostream>
#include <iomanip>
#include<string>
#include<cmath>
using namespace std;

int main()
{
    long long l, n;
    string s;
    cin >> l >> n >> s;
    long long a = 0;
    //oo count
    for (int i = 0; i < (int)s.size() - 1; i++) {
        if (s[i] == 'o' && s[i + 1] == 'o') {
            a++;
        }
    }
    long long m = 1;
    for (int i = 0; i < n; i++) m *= 2;
    cout << (long long)(l + 3 * a * (m - 1)) << endl;
    return 0;
}



Measured memory_bytes: 3176
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,m;
  cin>>n>>m;
  int a=1, b=n, c=1 + (n+1) / 2, d = c-2;
  REP(i,m) {
    if (i%2 == 0) {
      cout<<a<<" "<<b<<"\n";
      ++a;--b;
    } else {
      cout<<c<<" "<<d<<"\n";
      ++c;--d;
    }
  }
  return 0;
}


Measured memory_bytes: 3652
n = int(input())
a = list(map(int, input().split()))

lsum = a[0]
rsum = sum(a[1:])
ans = abs(lsum - rsum)

for i in range(1, n-1):
    lsum += a[i]
    rsum -= a[i]
    res = abs(lsum - rsum)

    if res < ans:
        ans = res

print(ans)

Measured memory_bytes: 30624
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#define N 200005
#define LL long long
using namespace std;

struct node
{
	int k,len;
}p[N];
priority_queue<node>q;
bool operator<(node x,node y)
{
	return x.len>y.len;
}
bool cmp(node x,node y)
{
	return x.k<y.k;
}
int T,n;
int k[N],l[N],r[N];
int main()
{
	int i,j;
	scanf("%d",&T);
	while(T--)
	{
		j=0;
		LL ans=0;
		scanf("%d",&n);
		for(i=1;i<=n;i++)
		{
			scanf("%d%d%d",&k[i],&l[i],&r[i]);
			if(l[i]>=r[i])
			{
				ans+=r[i];
				p[++j].k=k[i];
				p[j].len=l[i]-r[i];
			}
		}
		sort(p+1,p+j+1,cmp);
		int size=0;
		for(i=1;i<=j;i++)
		{
			q.push(p[i]);
			size++;
			if(size>p[i].k)
			{
				size--;
				q.pop();
			}
		}
		while(!q.empty())
		{
			ans+=q.top().len;
			q.pop();
		}
		j=0;
		for(i=1;i<=n;i++)
		{
			if(l[i]<r[i])
			{
				ans+=l[i];
				p[++j].len=r[i]-l[i];
				p[j].k=n-k[i];
			}
		}
		sort(p+1,p+j+1,cmp);
		size=0;
		for(i=1;i<=j;i++)
		{
			q.push(p[i]);
			size++;
			if(size>p[i].k)
			{
				size--;
				q.pop();
			}
		}
		while(!q.empty())
		{
			ans+=q.top().len;
			q.pop();
		}
		printf("%lld\n",ans);
	}
	return 0;
}


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

using namespace std;

const long MOD = 1e9+7;

void solve()
{
	int N, M;
	cin >> N >> M;
	bitset<1000010> appearedA, appearedB;
	vector<int> as(N), bs(M);
	for (int i = 0; i < N; i++)
	{
		int a; cin >> a;
		as[i] = a;
		if (appearedA[a])
		{
			cout << 0 << endl;
			return;
		}
		appearedA[a] = 1;
	}
	for (int i = 0; i < M; i++)
	{
		int b; cin >> b;
		bs[i] = b;
		if (appearedB[b])
		{
			cout << 0 << endl;
			return;
		}
		appearedB[b] = 1;
	}

	sort(as.begin(), as.end());
	sort(bs.begin(), bs.end());

	long ans = 1;

	for (int x = N*M; x >= 1; x--)
	{
		if (appearedA[x] && appearedB[x])
		{
			continue;
		}
		if (appearedA[x])
		{
			long kb = bs.end() - lower_bound(bs.begin(), bs.end(), x);
			ans *= kb;
			ans %= MOD;
		}
		else if (appearedB[x])
		{
			long ka = as.end() - lower_bound(as.begin(), as.end(), x);
			ans *= ka;
			ans %= MOD;
		}
		else
		{
			long ka = as.end() - lower_bound(as.begin(), as.end(), x);
			long kb = bs.end() - lower_bound(bs.begin(), bs.end(), x);
			ans *= max(0L, (ka*kb-N*M+x));
			ans %= MOD;
			//cout << x << ' ' << ka << ' ' << kb << endl;
		}
		//cout << ans << endl;
	}
	cout << ans << endl;
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 512
def l_in(type_): return list(map(type_, input().split()))
def i_in(): return int(input())
def m_in(type_): return map(type_, input().split())
def r_in(n, type_): return [type_(input()) for _ in range(n)]
ans = None

n = i_in()
d = {}
for _ in range(n):
    k = input()
    d[k] = 1
ans = len(d)

print(ans)

Measured memory_bytes: 35220
# include<iostream>
#include <iomanip>

using namespace std;
int main() {
	int a = 0;
	int b = 0;
	double da = 0;
	double db = 0;
	cin >> a >> b;
	da = (double)a;
	db = (double)b;
	cout << fixed;
	cout << a / b << " " << a%b << " " <<  setprecision(1000) << da/db << endl;
	return 0;
}

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

#define ll long long
#define ar array

using namespace std;
int main(){
	string s1,s2;cin>>s1>>s2;
	int ctr=0;
	for(int i=0;i<s1.length();i++){
		if(s1[i]!=s2[i]){
			s1[i]=s2[i];
			ctr++;
		}
	}
	cout<<ctr<<" " <<endl;
}

void readArray(int Array[],int N){
	for(int i=0;i<N;i++){
		cin>>Array[i];
	}
}

void printArray(int Array[],int N){
	for(int i=0;i<N;i++){
		cout<<Array[i] << " ";
	}
	cout<<endl;
}
void readVector(vector<int>&v){
	for(int &e : v){
		cin>>e;
	}	
}
void swap(int* a, int* b) 
{ 
    int t = *a; 
    *a = *b; 
    *b = t; 
} 
int partition (int arr[], int low, int high) 
{ 
    int pivot = arr[high];    // pivot 
    int i = (low - 1);  // Index of smaller element 
  
    for (int j = low; j <= high- 1; j++) 
    { 
        // If current element is smaller TEMPthan or 
        // equal to pivot 
        if (arr[j] <= pivot) 
        { 
            i++;    // increment index of smaller element 
            swap(&arr[i], &arr[j]); 
        } 
    } 
    swap(&arr[i + 1], &arr[high]); 
    return (i + 1); 
} 
void Sort(int arr[], int low, int high) 
{
   //quicksort using divide and conquer	
    if (low < high) 
    { 
        /* pi is partitioning index, arr[p] is now 
           at right place */
        int pi = partition(arr, low, high); 
  
        // Separately sort elements before 
        // partition and after partition 
        Sort(arr, low, pi - 1); 
        Sort(arr, pi + 1, high); 
    } 
}

void printVector(vector<int>&v){
	for(int &e : v){
		cout<<e<<" ";
	}
}



Measured memory_bytes: 3924
use std::io;
fn main() {
    let mut string = String::new();
    io::stdin().read_line(&mut string).ok();
    let t: i32 = string.trim().parse().unwrap();
    let hour: i32 = t / 60i32.pow(2);
    let min: i32 = (t % 60i32.pow(2)) / 60;
    let second: i32 = t % 60i32.pow(2) % 60i32;
    println!("{}:{}:{}", hour, min, second);
}



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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a <= c && c <= b) cout << "Yes" << endl;
    else if(b <= c && c <= a) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cmath>
#include<iostream>
using namespace std;
string a,b;
int main()
{
	cin>>a>>b;
	for(int i=0;i<a.size();i++)
	{
		cout<<a[i];
		if(i<b.size())cout<<b[i];
	}
	cout<<endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
  public static final long MOD = 1000000007;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    String S = sc.next();
    char SSS[] = S.toCharArray();
    if(SSS[K-1] == 'A') SSS[K-1] = 'a';
    else if(SSS[K-1] == 'B') SSS[K-1] = 'b';
    else SSS[K-1] = 'c';
    for(int i=0; i<N; i++) System.out.print(SSS[i]);
    
  }

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

Measured memory_bytes: 23124
#include <iostream>

using namespace std;

int main()
{
    
     int H;
     cin >> H; 
     int W;
     cin >> W;
     int N_black;
     cin >> N_black;
     int operations = 0;
     int answers = 0;
     // if number of columns is greater than the number of rows, then go through columns, or else go throgh rows 
     if(H > W) {
         for(int columns = 1; columns <= W; columns++ ) {
             answers += 1;
         for(int rows = 1; rows <= H; rows++) {
             operations += 1;
         }
         if(operations >= N_black) {
             break;
         }
     } 
     } else { // go throuh the rows
     for(int rows = 1; rows <= H; rows++ ) {
         answers += 1;
         for(int columns = 1; columns <= W; columns++) {
           operations += 1;
         }
           if(operations >= N_black) {
                 break;
             }
     }
     }
     cout << answers;
     
    return 0;
}


Measured memory_bytes: 256
n = int(input())
list = []
for i in range(n):
    a,b=input().split()
    list.append([float(a), b])
ans=0
for i in range(n):
    if(list[i][1]=='JPY'):
        ans+=list[i][0]
    else:
        ans+= 380000*list[i][0];
    
print(ans)


Measured memory_bytes: 9084
#include<cstdio>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int n,u,v,m,tmp;
int c[1000001];
int usa[1000001][2],neko[1000001][2];
int row[2][500],col[2][500],dia[2][2];
int U,V;

int main(){
  scanf("%d%d%d%d",&n,&u,&v,&m);
  rep(i,1000001)rep(j,2)usa[i][j] = neko[i][j] = -1;

  rep(i,n)rep(j,n){
    scanf("%d",&tmp);
    usa[tmp][0] = i; usa[tmp][1] = j;
  }
  rep(i,n)rep(j,n){
    scanf("%d",&tmp);
    neko[tmp][0] = i; neko[tmp][1] = j;
  }
  rep(i,2){
    rep(j,n)row[i][j] = col[i][j] = 0;
    dia[i][0] = dia[i][1] = 0;
  }
  U = V = 0;

  if(n==1){ u*=4; v*=4; }

  rep(i,m)scanf("%d",&c[i]);
 
  bool f = false;
  rep(i,m){
    if(usa[c[i]][0]>=0){
      int y = usa[c[i]][0], x = usa[c[i]][1];
      row[0][y]++;
      if(row[0][y]==n)U++;

      col[0][x]++;
      if(col[0][x]==n)U++;

      if(x == y){
	dia[0][0]++;
	if(dia[0][0]==n)U++; 
      }
      if(x+y == n-1){
	dia[0][1]++;
	if(dia[0][1]==n)U++;
      }
    }
    
    if(neko[c[i]][0]>=0){
      int y = neko[c[i]][0], x = neko[c[i]][1];
      row[1][y]++;
      if(row[1][y]==n)V++;

      col[1][x]++;
      if(col[1][x]==n)V++;

      if(x == y){
	dia[1][0]++;
	if(dia[1][0]==n)V++;
      }
      if(x + y == n-1){
	dia[1][1]++;
	if(dia[1][1]==n)V++;
      }
    }

    if(U>=u && V>=v){
      break;
    }else if(U>=u){
      printf("USAGI\n");
      f = true; break;
    }else if(V>=v){
      printf("NEKO\n");
      f = true; break;
    }
  }
  if(!f)printf("DRAW\n");
}

Measured memory_bytes: 17392
#include <iostream>
#include <string>
#include <sstream>
#include <math.h>
#include<string>
using namespace std;
int main(){
    string S;
    cin >> S;
    if(S[2] == S[3] && S[4] == S[5])    cout << "Yes" << endl;
    else
    {
        cout << "No" << endl;
    }
    
}

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

#define INCANT cin.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define out(a) cout << a << endl
#define PRINT(V) for (auto v : (V)) cout << v << " "

const int MOD = 1000000007;
const double PI = acos(-1.0);

int solve() {
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    int sumA = accumulate(all(A), 0);
    sort(all(A));
    rep(i, M){
        int a = A.at(N-1-i);
        if((double)a < (double)sumA/(4*M)) return 0;
    }
    return 1;
}
int main() {
    INCANT;
    if(solve()) out("Yes");
    else out("No");
    return 0;
}




Measured memory_bytes: 3664
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    int n, t, e;
    int[] clock;
    boolean solved;

    void run(){
	while(sc.hasNext()){
	    n = sc.nextInt();
	    t = sc.nextInt();
	    e = sc.nextInt();
	    clock = new int[n+1];
	    for(int i=1; i<clock.length; i++)
		clock[i] = sc.nextInt();
	    solved = false;
	    solve();
	}
    }

    void solve(){
	int time;
	for(int i=1; i<clock.length; i++){
	    time = clock[i];
	    while(time < t-e) time += clock[i];
	    if((t-e)<=time && time<=(t+e)){
		System.out.println(i);
		solved = true;
		break;
	    }
	}
	if(!solved) System.out.println("-1");
    }
}
		
	    

Measured memory_bytes: 18316
listA=[]

for i in range(2):
    try:
        listA.append(list(map(int, input().split())))
        #listA<-[1,2,2,3,1]
        #print(listA)
        #ここに逐次処理を書けばいいと思う。
    except:
        break;
        #または、quit(),os.exit()をして止める。

if sum(listA[1]) >= (listA[0])[0]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 13964
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int, int >
#define F first
#define S second
#define int  long long int
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
using namespace std;
/// age ye mosh dp ro baze dashti dp tedad baz shodeye baste nashode yadet nare !!
const int N=1e5+100;
ll a[N];
ll n,m,v,p;
ll vis[N];
ll fen[N];
void add(ll idx,ll val){
    for (;idx<N;idx+=idx & (-idx)){
        fen[idx]+=val;
    }
}
ll get(ll idx){
    ll s=0;
    for (;idx;idx-= idx & (-idx)){
        s+=fen[idx];
    }
    return s;
}
ll bs(ll x){
    ll val=a[x];
    val+=m;
    memset(vis,0,sizeof vis);
    memset(fen,0,sizeof fen);
    vector <int> c;
    for (int i=x+1;i<=n;i++){
        if (a[i]>val){
            vis[i]=1;
            c.pb(m);
        }
    }
    ll p1=c.size();
    if (p1>p-1) return 0;
    for (int i=n;i>0;i--){
        if (vis[i] || i==x) continue;
        if (p1<p-1){
            c.pb(m);
           // if (x==3)
            //cout << c.back() << " " << i << endl;

            p1++;
            continue;
        }
        else{
            c.pb(min(m,val-a[i]));
            //if (x==3)
            //cout << c.back() << " " << i << endl;
        }
    }
    ll ans=0;
    for (int i=0;i<c.size();i++){
        ll u=c[i];
        ans+=u;
    }
    if (v==1){
        return 1;
    }
    ans/=(v-1);
    if (ans>=m) return 1;
    return 0;
}
int32_t main(){
    cin >> n >> m >> v >> p;
    for (int i=1;i<=n;i++){
        cin >> a[i];
    }
    sort(a+1,a+n+1);
    ll l=0,r=n+1;
    while(r-l>1){
        ll mid=(r+l)/2;
        ll z=bs(mid);
        if (z==1) r=mid;
        else l=mid;
    }
    cout << n+1-r;
}



Measured memory_bytes: 4452
N, K = gets.split.map{|i|i.to_i}
A = gets.split.map{|i|i.to_i - 1}
steps = Array.new(N){nil}
town = 0
steps[0] = 0
k = 1
loop{
    town = A[town]
    if steps[town]
        warn "step:%d:town%d:%d" % [k, town, steps[town]]
        rest = K - k
        size = k - steps[town]
        warn "rest:%d:mod%d" % [rest, rest % size]
        (rest % size).times{
            town = A[town]
        }
        break
    end
    steps[town] = k
    break if k >= K
    k += 1
}
puts town + 1


Measured memory_bytes: 28976
s = int(input())
S = [s]
#print(S)
N = 1000000
for i in range(N):
	if s%2 == 0:
		s = s//2

		#print(s)

		if s in S:
			ans = i+2
			break
		S.append(s)
	else:
		s = 3*s+1

		#print(s)

		if s in S:
			ans = i+2
			break
		S.append(s)
#print(S)
print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <utility>
using namespace std;
int main() {
	int n;
	int y;
	cin >> n;
	cin >> y;
	for (int i = 0; i < n+1; i++) {
		for (int j = 0; j < n+1; j++) {
			if (i + j > n)break;
			if (i* 10000 + j * 5000 + (n - i - j) * 1000 == y) {
				cout << i << " "<<j <<" "<< n - i - j;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1";
}

Measured memory_bytes: 256
n = int(input())
d = {}
max_ = 1
for i in range(n):
    s = input()
    if d.get(s) is None:
        d[s] = 1
    else:
        d[s] += 1
        if max_ < d[s]:
            max_ = d[s]
ans = sorted(d.items())
for k, v in ans:
    if v == max_:
        print(k)


Measured memory_bytes: 44248
from collections import deque
K = int(input())

cnt = 0
q = deque()
for i in range(1, 10):
    q.append(i)
while cnt < K:
    num = q.popleft()
    cnt += 1
    if num%10 > 0:
        q.append(10*num+(num%10)-1)
    q.append(10*num+(num%10))
    if num%10 < 9:
        q.append(10*num+(num%10)+1)

print(num)

Measured memory_bytes: 11872
N,M,X,Y = map(int,input().split())

x = list(map(int,input().split()))
y = list(map(int,input().split()))
ans = 'War'
for i in range(-100,101):
    if X < i <= Y and max(x)<i and min(y)>=i:
        ans = 'No War'
        break
print(ans)

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

Measured memory_bytes: 584
#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()
{
    string s;
    cin >> s;
    int N = s.size();
    vector<int> n(N);
    rep(i, N) n[i] = s[i] - '0';
    vector<string> op(3);
    rep(i, 1 << 3)
    {
        int sum = n[0];
        rep(j, 3)
        {
            if (i >> j & 1)
            {
                sum += n[j + 1];
                op[j] = '+';
            }
            else
            {
                sum -= n[j + 1];
                op[j] = '-';
            }
        }
        if (sum == 7)
        {
            cout << s[0] << op[0] << s[1] << op[1];
            cout << s[2] << op[2] << s[3] << "=7" << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
using namespace std;
int main()
{
    int a, b, k, t = 0;
    cin >> a >> b >> k;
    for(int i = min(a, b); i > 0; i--)
    {
        if(a % i == 0 && b % i == 0)
            t++;
        if(t == k)
        {
            cout << i;
            return 0;
        }

    }
    return 0;
}

Measured memory_bytes: 3636
x = int(input())
lo = 0
hi = x


def check(n, a):
    return (n * (n + 1)) // 2 >= a


while hi - lo > 1:
    m = lo + (hi - lo) // 2
    if check(m, x):
        hi = m
    else:
        lo = m
print(hi)

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

const int MOD = 1000000007;

int main() {
	long long a = 1;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		a *= i + 1;
		a %= MOD;
	}
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/local/bin python
# -*- coding: utf-8 -*-
#
# ~/PycharmProjects/atcoder/B-YYMMorMMYY.py
#

s = str(input())
s_former = int(s[:2])
s_latter = int(s[2:])

if 1 <= s_former <= 12:
    if 1 <= s_latter <= 12:
        print("AMBIGUOUS")
    else:
        print("MMYY")

else:
    if 1 <= s_latter <= 12:
        print("YYMM")
    else:
        print("NA")


# print(s_former)
# print(s_latter)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
typedef long long ll;
const ll inf = (1e+9)+1;
using namespace std;
int main(void){
    int n,m,q;ll l;cin>>n>>m>>l;
    ll cost[n][n],t[n][n];
    rep(i,n)rep(j,n){cost[i][j]=inf;t[i][j]=inf;}
    rep(i,m){
        int a,b;ll c;cin>>a>>b>>c;
        a--;b--;
        cost[a][b]=(c<=l)?c:inf;cost[b][a]=(c<=l)?c:inf;
    }
    rep(k,n)rep(i,n)rep(j,n){
        cost[i][j] = min(cost[i][j],cost[i][k]+cost[k][j]);
    }
    rep(i,n)rep(j,n) if(cost[i][j]<=l)t[i][j]=1;
    rep(k,n)rep(i,n)rep(j,n) t[i][j]=min(t[i][j],t[i][k]+t[k][j]);
    cin>>q;
    rep(i,q){
        int S,T;cin>>S>>T;S--;T--;
        if(t[S][T]==inf)cout<<-1<<endl;
        else cout<<t[S][T]-1<<endl;
    }
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
int main()
{ long long int a,b,c,d;
  cin>>a>>b>>c>>d;
 vector<long long int> v;
 v.push_back(a*c);
 v.push_back(a*d);
 v.push_back(b*c);
 v.push_back(b*d);
 long long int Y=*max_element(v.begin(),v.end());
 cout<<Y;

}


Measured memory_bytes: 3588
import java.util.*;

public class Main
{
    private final static Main main = new Main();

    public static void main(String[] args)
    {
        main.contest();
    }

    private void contest()
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        String regex = "[^";
        for(int i=0; i<k; ++i)
        {
            regex += sc.nextInt();
        }
        regex += "]+";
        System.out.println(solve(n, regex));
    }

    private int solve(int n, String regex)
    {
        while(!String.valueOf(n).matches(regex)) ++n;
        return n;
    }
}


Measured memory_bytes: 20628
import java.util.*;

public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] a = new int[5];
        int min = 10;
        int minIndex = 0;
        for (int i = 0; i<5; i++) {
            a[i] = sc.nextInt();
            if (a[i]%10 != 0 && a[i]%10 < min) {
                min = a[i]%10;
                minIndex = i;
            } 
        }

        int result =0;
        if (min == 10) {
            for (int i = 0; i<5; i++) {
                result += a[i];
            }
        }
        else {
            for (int i = 0; i<5; i++) {
                result += a[i];
                if (a[i]%10 != 0 && i != minIndex) {
                    result += (10 - a[i]%10);
                }
            }
        }

        System.out.println(result);
        sc.close();
    }
}

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

using namespace std;

using int64 = long long;

int main() {
  int N, M, Q;
  cin >> N >> M >> Q;
  vector< int > ev[501];
  for(int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    ev[x].emplace_back(y);
  }
  for(int i = 0; i <= N; i++) {
    sort(begin(ev[i]), end(ev[i]));
  }
  while(Q--) {
    int p, q;
    cin >> p >> q;
    int ret = 0;
    for(int i = p; i <= q; i++) {
      ret += upper_bound(begin(ev[i]), end(ev[i]), q) - begin(ev[i]);
    }
    cout << ret << endl;
  }

}


Measured memory_bytes: 2176
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

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

    char c = 'a';
    for(int i=0; i<26; i++) {
        if(count(S.begin(), S.end(), c) >= 2) {
            cout << "no" << endl;
            return 0;
        }
        c+=1;
    }
    cout << "yes" << endl;
    return 0;
}


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

int main(void) {
  int N, K;
  cin >> N >> K;
  int64_t X[MAX_N];
  rep(i, N) { cin >> X[i]; }

  int64_t Ans = INT64_MAX;
  for (int lp = 0; lp <= N - K; lp++) {
    int rp = lp + K - 1;
    // lp -> rp
    int64_t tmp0 = abs(X[lp]) + abs(X[rp] - X[lp]);
    Ans = min(Ans, tmp0);
    // rp -> lp
    int64_t tmp1 = abs(X[rp]) + abs(X[lp] - X[rp]);
    Ans = min(Ans, tmp1);
  }
  cout << Ans << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll MAX = 10000000;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    string S; cin >> S;
    string t = "";
    for(int i=0;i<S.size();i++){
        if(S[i] != 'A') t += S[i];
    }
    if("KIHBR" != t){
        cout << "NO" << endl;
        return 0;
    }
    for(int i=0;i<S.size();i++){
        if(S[i] == 'A'){
            if(i + 1 >= S.size()){
                cout << "YES" << endl;
                return 0;
            }else if(S[i+1] != 'K' && S[i+1] != 'B' && S[i+1] != 'R'){
                cout << "NO" << endl;
                return 0;
            }
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ld long double
#define ll long long int
#define mod 1000000007
#define ll_inf 1000000000000000000
#define int_inf 1000000000
#define pb push_back
#define endl '\n'
#define Endl '\n'
#define eps 1e-9
#define PI acos(-1.0)
#define ii pair<int,int>
#define se second
#define fi first
#define prout(x) cout.precision(x)
using namespace std;
ll a[200010];
int main(){
    int n;
    ll T, ans=0;
    cin>>n>>T;
    cin>>a[0];
    ans=T;
    for(int i=1;i<n;i++){
        cin>>a[i];
        if(a[i]-a[i-1]>T)ans+=T;
        else ans+=a[i]-a[i-1];
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,a,b,c;
  cin >> n;
  b=1;
  c=0;
  for(int i=0;i<n;i++){
    cin >> a;
    if(a==b) b++;
    else c++;
  };
  if(c==n) cout << -1;
  else cout << c;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

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

void bfs(const int sx, const int sy, const int w, const int h,
         vector<vector<bool>>& column, vector<vector<bool>> & row,
         vector<vector<int>>& cost) {
    queue<pair<int, int>> q; q.push({sx, sy});
    cost[sx][sy] = 1;
    while(not q.empty()) {
        auto p = q.front(); q.pop();
        // if(cost[p.first][p.second] > 0) continue;
//        cout << "p:" << p.first << " " << p.second << endl;

        for (auto i = 0; i < 4; i++) {
            int nx = p.first + dx[i], ny = p.second + dy[i];
            if(nx < 0 or nx >= h or ny < 0 or ny >= w) continue;
//            cout << "next:" << i << " " << nx << " " << ny << " "
//                 << column[p.first][p.second] << " " << row[p.first][p.second] << " "
//                 << column[nx][ny] << " " << row[nx][ny] << endl;
            if(i == 0 and column[p.first][p.second]) continue;
            if(i == 1 and row[p.first][p.second]) continue;
            if(i == 2 and column[nx][ny]) continue;
            if(i == 3 and row[nx][ny]) continue;
            if(cost[nx][ny] != -1) continue;
            cost[nx][ny] = cost[p.first][p.second] + 1;
            q.push({nx, ny});
//            cout << "cost:" << cost[nx][ny] << endl;
        }
    }
}

int main(){
    while(true){
        int w, h;
        cin >> w >> h;

        if(w == 0 and h == 0) break;

        vector<vector<bool>> column(h, vector<bool>(w - 1, false));
        vector<vector<bool>> row(h, vector<bool>(w, false));
        for (auto i = 0; i < h * 2 - 1; i++) {
            int tmp;
            if(i % 2 == 0) {
                for (auto j = 0; j < w - 1; j++) {
                    cin >> tmp;
                    column[i / 2][j] = tmp;
                }
            } else {
                for (auto j = 0; j < w; j++) {
                    cin >> tmp;
                    row[i / 2][j] = tmp;
                }
            }
        }

        vector<vector<int>> cost(h, vector<int>(w, -1));
        bfs(0, 0, w, h, column, row, cost);
        int ans = max(cost[h - 1][w - 1] , 0);
        cout << ans << endl;
    }

    return 0;
}


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


string s1,s2;
int size1,size2;

int pd[3002][3002];
int dp(int i1,int i2){
	if(i1>=size1 or i2>=size2)
		return 0;
	if(pd[i1][i2]!=-1) return pd[i1][i2];
	if(s1[i1]==s2[i2]) return pd[i1][i2] = dp(i1+1,i2+1)+1;
	return pd[i1][i2] = max(dp(i1+1,i2),dp(i1,i2+1));
}

int32_t main(){
	memset(pd,-1,sizeof pd);
	cin >> s1 >> s2;
	size1 = (int)s1.size();
	size2 = (int)s2.size();
	int size = dp(0,0),i=0,j=0;
	string out = "";
	while(size--){
		while((i+1)<size1 and pd[i][j]==pd[i+1][j])
			i++;
		while((j+1)<size2 and pd[i][j]==pd[i][j+1])
			j++;
		out+=s1[i];
		i++,j++;
	}
	cout << out << '\n';
}

Measured memory_bytes: 35712
"use strict";
// import bigInt from 'big-integer'

const Main = input => {
  input = input.trim();
  const length = input.length;

  const frontHalf = Math.floor(length / 2);
  const backHalf = length % 2 === 0 ? frontHalf : frontHalf + 1;
  const frontWords = input.slice(0, frontHalf).split("");
  const backWords = input
    .slice(backHalf)
    .split("")
    .reverse();

  let count = 0;
  for (let i = 0; i < frontHalf; i++) {
    if (frontWords[i] !== backWords[i]) count++;
  }
  console.log(count);
};

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

#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 main(int argc, const char * argv[]) {
    // source code
    string s;
    cin >> s;
    if (s == "Sunny") cout << "Cloudy" << endl;
    else if (s == "Cloudy") cout << "Rainy" << endl;
    else if (s == "Rainy") cout << "Sunny" << endl;
    
    return 0;
}


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

//v：始点、n：頂点の数、count：通った辺の数
vector<bool> seen;

int dfs(Graph &g, int v, int n, int count){
  if(count == n - 1) return 1;
  int ans = 0;
  seen[v] = true;
  for(auto nv : g[v]){
    if(seen[nv]) continue;
    ans += dfs(g, nv, n, count + 1);
    seen[nv] = false;
  }
  return ans;
}

int main(){
  int n, m;
  cin >> n >> m;
  Graph g(n);
  rep(i,m){
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  seen.assign(n,false);
  int count = 0;
  cout << dfs(g,0,n,count) << endl;

  return 0;
}


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

int main() {
  string s; cin >> s;
  int n; cin >> n;
  int t,f;
  char c;
  string top,end;
  bool ord = true;;
  rep(i,n){
    cin >> t;
    if(t == 1) ord = !(ord);
    else{
      cin >> f;
      if(ord){
        if(f == 1){
          cin >> c;
          top = c+top;
        }
        if(f == 2){
          cin >> c;
          end = end+c;
        }
      }
      else{
        if(f == 2){
          cin >> c;
          top = c+top;
        }
        if(f == 1){
          cin >> c;
          end = end+c;
        }
      }

    }
  }

  s = top + s + end;
  if(!ord) reverse(s.begin(),s.end());
  cout << s << endl;

  return 0;
}


Measured memory_bytes: 4420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;


int main(){
    string c1, c2, c3;
    cin >> c1 >> c2 >> c3;
    cout << c1.substr(0,1) + c2.substr(1,1) + c3.substr(2,1) + "\n";
}


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

int main() {
    int n;
    cin >> n;
    vector<ll> a(n + 1), b(n + 1, 0);
    for (int i = 0; i <= n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    ll ans = 0, nx = 0;
    for (int i = 0; i <= n; i++) {
        if (a[i] < b[i] + nx) {
            if (a[i] < nx) {
                ans += a[i];
                nx = b[i];
            } else {
                ans += a[i];
                nx = b[i] - (a[i] - nx);
            }
        } else {
            ans += b[i] + nx;
            nx = 0;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1920
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define LB(c, x) lower_bound(c.begin(), c.end(), x)
#define UB(c, x) upper_bound(c.begin(), c.end(), x)
#define LI(c, x) distance(c.begin(), LB(c, x))
#define UI(c, x) distance(c.begin(), UB(c, x))

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
ll modpow(ll a, ll b, ll m) {
    if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll h = modpow(a, b / 2, m);
        return h * h % m;
    } else {
        return a * modpow(a, b - 1, m) % m;
    }
}
ll comb(ll a, ll b, ll m) {
    if (b > a - b) {
        return comb(a, a - b, m);
    }
    ll c = 1, d = 1;
    REP(i, b) {
        c *= (a - i);
        d *= (b - i);
        c %= m;
        d %= m;
    }
    return c * modpow(d, m - 2, m) % m;
}

const int MOD = 1000000007;
int N, K;
vector<vector<int>> G;

ll dfs(int curr, int prev) {
    if (G[curr].size() > K) {
        return 0;
    }
    int k = prev == -1 ? K - 1 : K - 2;
    ll res = 1;
    for (auto x : G[curr]) {
        if (x == prev) {
            continue;
        }
        res *= k;
        res %= MOD;
        k--;
    }
    for (auto x : G[curr]) {
        if (x == prev) {
            continue;
        }
        res *= dfs(x, curr);
        res %= MOD;
    }
    return res;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> K;
    G = vector<vector<int>>(N);
    REP(i, N - 1) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    cout << dfs(0, -1) * K % MOD << endl;
    return 0;
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
const ll MOD = 998244353;

ll R[11], L[11], S[800010];

int main() {
	int N, K;
	cin >> N >> K;
	
	for (int i = 0;i < K;i++) {
		cin >> L[i] >> R[i];
	}
	for (int i = 0;i < 800010;i++)S[i] = 0;
	S[1] = 1, S[2] = -1;
	for (int i = 1;i <= N;i++) {
		S[i] += S[i - 1];
		for (int k = 0;k < K;k++) {
			S[i + L[k]] += S[i];
			S[i + R[k] + 1] += -S[i];

			S[i + L[k]] %= MOD;
			S[i + R[k] + 1] %= MOD;
		}
	}
	S[N] %= MOD;
	S[N] += MOD;
	cout << S[N] % MOD << endl;
}

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

#define REP(i,n) for(ll i=0;i<(n);i++)
#define REAP(i,a,n) for(ll i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll a,mi=1e9+7,ma=0;
    REP(i,n){
        cin >> a;
        mi=min(mi,a);
        ma=max(ma,a);
    }
    cout << ma-mi << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define LL long long
#define pii pair<int,int>
#define pll pair<LL,LL>
#define ALL(V) V.begin(),V.end()
#define f1(a,b) for(int a=1;a<=b;a++)
#define f0(a,b) for(int a=0;a<b;a++)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl "\n"
using namespace std;
const LL N=1e6+69, base=1024*1024, mod=1e9+7,ma=1e15;
priority_queue <pll> q;
LL n,m,po,ko,a,b,c,odl[N][2],odw[N][2],o,wynik;
LL dp[N][2];
vector <int> vek;
vector <pll> G[N];
pair<LL,pll> kra[N];
void dij(int,int);
int32_t main(void) {
    boost;
    cin>>n>>m;
    cin>>po>>ko;
    f1(i,m) {
        cin>>a>>b>>c;
        G[a].PB(MP(b,i));
        G[b].PB(MP(a,i));
        kra[i]=MP(c,MP(a,b));
    }
    dij(po,0);
    o=odl[ko][0];
    dij(ko,1);
    //cout<<o<<endl;
    //f1(i,n) cout<<dp[i][1]<<" ";
    //return 0;
    wynik=dp[ko][0];
    wynik*=wynik;
    wynik%=mod;
    f1(i,n) {
        if(o%2==1) continue;
        if(odl[i][0]==odl[i][1]&&odl[i][0]==o/2) {
            LL nwm=dp[i][0]*dp[i][1];
            nwm%=mod;
            nwm*=nwm;
            nwm%=mod;
            //cout<<dp[i][0]*dp[i][1]<<endl;
            wynik-=nwm;
            if(wynik<0) wynik+=mod;
            wynik%=mod;
        }
    }
    sort(ALL(vek));
    vek.resize(distance(vek.begin(),unique(ALL(vek))));
    f0(i,vek.size()) {
        int nr=vek[i];
        a=kra[nr].s.f;
        b=kra[nr].s.s;
        //cout<<"nisjdibnkjfd "<<a<<" "<<b<<endl;
        LL nwm=0;
        if(odl[a][0]<o/2&&odl[b][0]>o/2) nwm=dp[a][0]*dp[b][1];//, cout<<a<<" fddf "<<b<<endl;
        if(odl[b][0]<o/2&&odl[a][0]>o/2) nwm=dp[b][0]*dp[a][1];//, cout<<a<<" wfre "<<b<<endl;
        nwm%=mod;
        nwm*=nwm;
        nwm%=mod;
        wynik-=nwm;
        if(wynik<0) wynik+=mod;
        wynik%=mod;
    }
    cout<<wynik<<endl;
}
void dij(int v,int nr) {
    f1(i,n) odl[i][nr]=ma;
    odl[v][nr]=0;
    dp[v][nr]=1;
    q.push(MP(0,v));
    while(!q.empty()) {
        v=q.top().s;
        q.pop();
        if(odw[v][nr]==1) continue;
        odw[v][nr]=1;
        f0(i,G[v].size()) {
            int w=G[v][i].f;
            LL dod=kra[G[v][i].s].f;
            if(odl[w][nr]>odl[v][nr]+dod) {
                dp[w][nr]=dp[v][nr];
                odl[w][nr]=odl[v][nr]+dod;
                if(nr==1&&odl[w][1]+odl[w][0]==o) vek.PB(G[v][i].s);
                //if(nr==1&&G[v][i].s==8) cout<<"jan pawel "<<odl[w][1]<<" "<<odl[w][0]<<endl;
                q.push(MP(-odl[w][nr],w));
            }
            else if(odl[w][nr]==odl[v][nr]+dod) {
                if(nr==1&&odl[w][1]+odl[w][0]==o) vek.PB(G[v][i].s);
                //if(nr==1&&G[v][i].s==8) cout<<"jan pawel "<<odl[w][1]<<" "<<odl[w][0]<<endl;
                dp[w][nr]+=dp[v][nr];
                dp[w][nr]%=mod;
            }
        }
    }
}

Measured memory_bytes: 51704
//#pragma GCC optimize(2)
// Happy TLE and WA every day!
// by: zxb the vegetable chicken
#include<bits/stdc++.h>
#define mp              make_pair
#define rep(i,n)        for(int i = 0; i < n; i++)
#define foreach(i,c)    for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define BINF            0x7fffffff
#define INF             0x3f3f3f3f
#define LINF            4557430888798830399
#define END(s)          {cout<<s; return 0;}
#define CON(s)          {cout<<s; continue;}
#define BRE(s)          {cout<<s; break;}
#define pb              push_back
#define All(a)          a.begin(), a.end()  //with A in CAPITAL!!!
#define sz(a)           (int)a.size()
#define F               first
#define S               second
#define Time            clock()/CLOCKS_PER_SEC
//#define usingFiles
using namespace std;

typedef unsigned int ui;
typedef pair<int, int> pii;
typedef long long ll;

inline bool Read(int& x){
	x = 0;
	int c;
	int sign = 1;
	while( (c = getchar()) < '0' || c > '9' ) if(c == '-') sign = -1;
	x = c ^ '0';
	while( (c = getchar()) >= '0' && c <= '9' ) x = (x<<3) + (x<<1) + (c ^ '0');
	x *= sign;
	return 1;
}

inline bool Write(int x){
	if(x >= 10) Write(x / 10);
	putchar(x % 10 + '0');
	return 1;
}

const int rp = 666666;
const bool debug = 1;
const bool I_good_vegetable_a = 1;

int n, W;
ll w[110];
int v[110];
ll dp[2][100100];
int res = 0;

signed main(){
	ios::sync_with_stdio(false);
	#ifdef usingFiles
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	cin >> n >> W;
	rep(i, n) cin >> w[i] >> v[i];
	memset(dp, 0x3f, sizeof(dp));
//	cout << dp[0][0] << endl;
	res = v[0];
	rep(i, v[0] + 1) dp[0][i] = w[0];
	dp[0][0] = 0;
	int sum = v[0];
	for(int i = 1; i < n; i++){
		int now = i & 1;
		int last = (i - 1) & 1;
		for(int j = 0; j <= sum; j++){
			if(dp[last][j] == LINF) continue;
			if(dp[last][j] + w[i] <= W) dp[now][j + v[i]] = min(dp[now][j + v[i]], dp[last][j] + w[i]);
			dp[now][j] = min(dp[now][j], dp[last][j]);
		}
		sum += v[i];
		rep(j, sum + 1) dp[last][j] = LINF;
	}
	rep(i, sum + 1){
		if(dp[(n - 1) & 1][i] != LINF){
			res = max(res, i);
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin >> s;
  int m = -1, M = -1;
  bool f=false , f_2 = false;
  
  
  
  for(char c='a'; c <= 'z'; c++){
    for(int i=0; i<s.size()-1;i++){
      if(s.at(i) == c && s.at(i+1) == c){
        m = i+1;
        M = i+2;
        f=true;
        break;
      }
    }
    if(f){
      break;
    }
  }
  
  if(!f){
    for(char c='a'; c <= 'z'; c++){
      for(int i=0; i<s.size()-2;i++){
        if(s.at(i) == c && s.at(i+2) == c){
          m = i+1;
          M = i+3;
          f_2=true;
          break;
        }
      }
      if(f_2){
        break;
      }
    }
  }
  
  cout << m << " " << M << endl;
  
  
}

Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX;
const ll MOD = 1e9+7;

ll A[112345],B[112345],C[112345];
ll l[112345],r[112345];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll X,Y,Z;cin>>X>>Y>>Z;
  ll N=X+Y+Z;
  vector<pair<ll,ll> > dif(N);
  repeat(i,N){
    cin >>A[i]>>B[i]>>C[i];
    dif[i]={A[i]-B[i],i};
  }
  sort(dif.begin(),dif.end());
  priority_queue<ll> Q;
  repeat(K,N){
    if(Y+Z<=K){
      break;
    }
    int i=dif[K].second;
    Q.push(C[i]-B[i]);
    l[K]=B[i];
    if(K>0)l[K]+=l[K-1];
    if(K<Y)continue;
    l[K]+=Q.top();
    Q.pop();
  }
  while(!Q.empty())Q.pop();
  for(int K=N-1;K>=Y;K--){
    int i=dif[K].second;
    Q.push(C[i]-A[i]);
    r[K]=r[K+1]+A[i];
    if(Y+Z<=K)continue;
    r[K]+=Q.top();
    Q.pop();
  }
  ll ans = 0;
  for(int K=Y-1;K<Y+Z;K++){
    ans = max(ans,l[K]+r[K+1]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6264