akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
// 素数かどうか判定
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))




signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	vector<int>a(n); 
	int sum = 0;
	rep(i, n) {
		cin >> a[i];
		sum += a[i];
	}
	sort(a.begin(), a.end());
	if (sum % 10 != 0) {
		cout << sum << endl; return 0;
	}
	rep(i, n) {
		if (a[i] % 10 != 0) {
			cout << sum - a[i] << endl; return 0;
		}
	}
	cout << 0 << endl;
	return 0;
}

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

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define uniqueV(x)                                                             \
  sort(x.begin(), x.end());                                                    \
  x.erase(unique(x.begin(), x.end()), x.end());
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y)                                                           \
  cerr << "(" << #x << ", " << #y << ") = "                                    \
       << "(" << x << ", " << y << ")" << '\n'

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

// ----------------------------------------------

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

  ll a, b, c, k;
  cin >> a >> b >> c >> k;

  if (k <= a) {
    cout << k << endl;
    return 0;
  }
  k = k - a;

  if (k <= b) {
    cout << a << endl;
    return 0;
  }
  k = k - b;

  cout << a - k << endl;
  return 0;
}

Measured memory_bytes: 3652
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include<bits/stdc++.h>

long long int m = 1000000007;
using namespace std;

long long int pow2(long long int a, long long int b){
    long long int resp = 1;
    
    while(b!=0){
        if(b%2==1){
            resp = resp*a%m;
        }
        a = a*a%m;
        b /= 2;
    }
    
    return resp%m;
}

long long int fat(long long int maior, long long int menor){
    long long int resp=1;
    
    for(int i=menor;i<=maior;i++){
        resp*=i;
        resp=resp%m;
    }
    return resp;
}

long long int vs[200010];

int main(){
    vs[0]=1;
    
    for(int i=1;i<200005;i++){
        vs[i] = (vs[i-1]*i)%m;
    }

    long long int a,n,b,r,aux,auxb;
    
    cin >> n >> a >> b;
    
    r = pow2(2, n) - 1;
    
    aux = vs[a];
    aux = pow2(aux, m-2) * fat(n,n-a+1) % m;
    r-= aux;
    
    if(r<0) r = m+r;
    
    aux = vs[b];
    aux = pow2(aux, m-2) * fat(n,n-b+1) % m;
    r-= aux;
    
    if(r<0) r = m + r;
    
    
  
    cout << r << endl;
    
    return 0;
}


Measured memory_bytes: 5184
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)
#define lli long long int
#define llu unsigned long long int
#define fr(va, beg, end) for (lli va = beg; va < end; va++)
#define pb push_back
#define rt return 0
#define endln "\n"
#define all(x) x.begin(), x.end()
// cout << fixed << setprecision(0) << pi <<" "<<npi<<endl;
// gcd function
// __gcd(a, b)
// for max of n elements
// cout<<max({a,b,c,d})<<endl;

lli n, mod = 1e9 + 7;
vector<lli> vis;
vector<vector<lli>> adj, dp;

lli dfs(lli a) {
    int flag = 0;
    for (lli i = 0; i < adj[a].size(); i++) {
        if (vis[adj[a][i]] == 0) {
            flag = 1;
            vis[adj[a][i]] = 1;
            dfs(adj[a][i]);
            dp[a][0] *= (dp[adj[a][i]][0] + dp[adj[a][i]][1]);
            dp[a][1] *= dp[adj[a][i]][0];
            dp[a][0] %= mod;
            dp[a][1] %= mod;
        }
    }
    if (flag == 0) {
        dp[a][0] = 1;
        dp[a][1] = 1;
    }

    return 0;
}

int main(void) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    lli a, b;
    cin >> n;
    adj.resize(n + 2);
    vis.resize(n + 2, 0);
    dp.resize(n + 2, vector<lli>(2, 1));

    fr(i, 0, n - 1) {
        cin >> a >> b;
        adj[a].pb(b);
        adj[b].pb(a);
    }

    vis[1] = 1;
    dfs(1);
    cout << (dp[1][0] + dp[1][1]) % mod << endl;
    rt;
}

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


def solve(s: str):
    from collections import Counter
    c = Counter(s)

    N = len(s)
    ans = INF


    for k in c.keys():
        # print(k)
        c = 0
        sc = s
        for j in range(N):
            ls = []
        # print(sc, '---')
            for i in range(len(sc)-1):
                if sc[i] == k or sc[i+1] == k:
                    ls.append(k)
                else:
                    ls.append(sc[i])
                # print(ls)
            c += 1
            
            if all([j == k for j in sc]):
                break

            sc = ''.join(ls)
        ans = min(ans, c-1)

    print(ans)


    # for k in c.keys():
    #     sc = list(s)
    #     N = len(sc)
        
    #     while(not all([r == k for r in sc])):
    #         ls = []
    #         for i in range(N-1):
    #             if sc[i] == k:
    #                 ls.append(m)
    #             else:
    #                 ls.append(sc[i])
    #         print(ls)
    #         sc = ls.copy()
    #         print(sc)


    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    solve(s)

if __name__ == '__main__':
    main()


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



int main()
{
 

  string a;
  string b;
  cin>>a;
   cin>>b;

  int n=a.length(), m=b.length();
   int dp[n+1][m+1];
  
   for(int i=0; i<=n; i++)
   { for(int j=0; j<=m; j++)
   	{ if(i==0|| j==0)
   		 dp[i][j]=0;

   	  else if(a[i-1]==b[j-1])
   	  	dp[i][j]=1+dp[i-1][j-1];

   	  else
   	     dp[i][j]=max(dp[i-1][j], dp[i][j-1]);
     
   	}
    
   }
   
   string s="";
   int j=m, i=n;
   while(i>0 && j>0)
   {  //cout<<dp[i][j]<<endl;
     
      if( dp[i-1][j] == dp[i][j])
   	    i--;

   	  else if(dp[i][j-1] == dp[i][j])
   	   	 j--;

   	  else 
   	   	{  s+= a[i-1];

   	   		i--; j--;}
    
    }
  
   reverse(s.begin(),s.end());
   cout<<s<<endl;

}
 

Measured memory_bytes: 38808
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	buf.Split(bufio.ScanWords)

	a := scanInt()
	b := scanInt()

	lower := max(a*100/8, b*10)
	upper := min((a+1)*100/8, (b+1)*10)
	for candidate := lower; candidate <= upper; candidate++ {
		if candidate*8/100 == a && candidate/10 == b {
			fmt.Printf("%d", candidate)
			return
		}
	}
	fmt.Printf("%d", -1)
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

var buf = bufio.NewScanner(os.Stdin)

func scanInt() int {
	buf.Scan()
	i, _ := strconv.Atoi(buf.Text())
	return i
}

func scanInts(n int) []int {
	a := make([]int, n)
	for k, _ := range a {
		a[k] = scanInt()
	}
	return a
}

func scanString() string {
	buf.Scan()
	return buf.Text()
}

func scanStrings(n int) []string {
	a := make([]string, n)
	for k, _ := range a {
		a[k] = scanString()
	}
	return a
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
const static int mx[] = {1,-1,1,-1};
const static int my[] = {1,-1,-1,1};

int main(){
  int N;
  
  while(~scanf("%d",&N)){
    if(N==0) break;
    int inheritance_schedule[50];
    ll inheritance_belongings[50];
    memset(inheritance_schedule,0,sizeof(inheritance_schedule));
    memset(inheritance_belongings,0,sizeof(inheritance_belongings));
    
    for(int i=0;i<N;i++) inheritance_belongings[i] = (1LL<<i);
    for(int i=0;i<N;i++){
      int total_days;
      scanf("%d",&total_days);
      
      int mask = 0;
      for(int j=0;j<total_days;j++){
	int day;
	scanf("%d",&day);
	mask |= (1<<day);
      }
      inheritance_schedule[i] = mask;
    }

    int res = -1;
    for(int day=1;day<=30;day++){
      for(int from=0;from<N;from++){
	for(int to=0;to<N;to++){
	  int both_suit_schedule
	    = inheritance_schedule[from] & inheritance_schedule[to];
	
	  if(both_suit_schedule & (1<<day)){
	    inheritance_belongings[to] |= inheritance_belongings[from];
	  }
	}
      }

      for(int i=0;i<N;i++){
	if(inheritance_belongings[i] == ((1LL<<N) - 1LL) ){
	  res = day;
	  goto found;
	}
      }
    }
  found:;
    printf("%d\n",res);
  }
}

Measured memory_bytes: 1188
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  for(int i=0; i<n; i++) cin >> p[i];
  //vector<int> r(p.begin(), p.end());
  //sort(r.begin(), r.end());
  int flag = -1;
  for(int i=0; i<n; i++){
   //cout << "i=" << i << endl;
   for(int j=0; j<n; j++){
     //cout << "j=" << j << endl;
     vector<int> q(p.begin(), p.end());
     int tmp;
     tmp = q[i];
     q[i] = q[j];
     q[j] = tmp;
     //for(int m=0; m<n; m++) cout << q[m] << " ";
     //cout << endl;
     //判定
       for(int l=0; l<n-1; l++){
         if(q[l] > q[l+1]){
           flag = 0;
           break;
         }
         else flag = 1;
     }
     if(flag == 1) break;
   }
   if(flag == 1) break;
  }
  if(flag == 1) cout << "YES";
  else cout << "NO";
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using namespace boost::multiprecision;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPI(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define ALL(x) (x).begin(),(x).end()

int f(int n) { return ((n % 2) == 0) ? (n/2) : ((3*n) + 1); }

int main () {
  map<int,int> dic;
  int s;
  cin >> s;

  for(int i = 1; ; i++) {
    int result = f(s);

    if(dic.count(s) > 0) {
      cout << i << endl;
      break;
    }
    else {
      dic[s] = result;
      s = result;
    }
  }


  return 0;
}


Measured memory_bytes: 256
/**
        Bismilla- hir rahma-nir rahi-m
    @uthor Md Hasibur Rahman (Evan)
                JKKNIU
*/


#include<bits/stdc++.h>
#define         ll              long long
#define         FI              freopen("input.txt","r",stdin)
#define         FO              freopen("output.txt","w",stdout)
#define         PrintCase(i)    printf("Case %d: ",i)
#define         sc(a)           scanf("%d",&a)
#define         scl(a)          scanf("%lld",&a)
#define         rep(i,n)        for(int i=0;i<n;i++)
#define         pb              push_back
#define         MAX             1000000
#define         fast            ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define			endl			"\n"


using namespace std;

bool isPrime(ll a)
{
    for(ll i=2;i*i<=a;i++)
        if(a%i==0)
            return false;
    return true;
}






bool isPowerOfTwo(ll a)
{
    if(a==1)
        return true;
    if(a&1)
        return false;
    while(a)
    {
        a/=2;
        if(a!=1 && a&1)
            return false;
        if(a==1)
            return true;
    }
    return true;
}




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



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



ll power(ll base, ll exponent)
{
    ll ans = 1;
    for(ll i=1;i<=exponent;i++)
        ans*=base;
    return ans;
}




bool isPowerOfX(ll x, ll value)
{
    if(value==1)
        return true;
    while(value)
    {
        value/=x;
        if(value%x && value!=1)
            return false;
    }
    return true;
}


ll X_or(ll for1, ll for2, ll value)
{
	ll arr[7];
	arr[3] = for1^for2;
	//cout<<(for1^for2)<<endl;
	arr[4] = arr[3]^for2;
	arr[5] = arr[4]^arr[3];
	cout<<arr[3]<<" "<<arr[4]<<" "<<arr[5]<<" ..... \n";
	if(value%3==0)
	{
		//cout<<arr[]
		return arr[3];
	}
	else
	{
		ll ret = ((value%3)==1)?arr[4] : arr[5];
		return ret;
	}
}


ll X_nor(ll for1, ll for2, ll value)
{
	ll arr[7];
	arr[3] = ~(for1^for2);
	//cout<<~(for1^for2)<<endl;
	if(arr[3]<0)
		arr[3]*=(-1);
	arr[4] = ~(arr[3]^for2);
	if(arr[4]<0)
		arr[4]*=(-1);
	arr[5] = ~(arr[3]^arr[4]);
	if(arr[5]<0)
		arr[5]*=(-1);
	cout<<arr[3]<<" "<<arr[4]<<" "<<arr[5]<<" ..... \n";
	if(value%3==0)
	{
		return arr[3];
	}
	else
	{
		ll ret = (value%3==1)? arr[4] : arr[5];
		return ret;
	}
}


int main()
{
	ll x,y;
	cin>>x>>y;
	(y>=(2*x) && y<=(4*x) && !(y&1))?cout<<"Yes\n":cout<<"No\n";
    return 0;
}


Measured memory_bytes: 3564
#include <stdio.h>

int main (){

  int S;
  int h, m, s;

  scanf("%d",&S);

  h = S / 3600;
  m = S / 60 - h * 60;
  s = S - (h * 3600 + m * 60);

  printf("%d:%d:%d\n", h, m, s);

  return 0;

}

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

const int INF = 1e8;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    long long n, k;
    cin >> n >> k;
    cout << min(n % k, k - (n%k)) << endl;
}

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

using namespace std;

using ll=long long;

int main(){
    const ll INF=1e9;
    ll n,k;
    cin >> n >>k;
    vector<ll> h(n);
    for(int i=0;i<n;i++){
        cin >> h[i];
    }
    vector<ll> dp(n,INF);
    dp[0]=0;
    for(ll i=1;i<n;i++){
        for(ll j=1;j<=min(i,k);j++){
            dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
        }
    }
    cout << dp[n-1] << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define pb push_back
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}

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

  ll q, h, s, d, n;
  cin >> q >> h >> s >> d >> n;

  ll ans = 0;
  ll cnt = min({q*8, h*4, s*2, d});
  if(n % 2 == 0){
    ans += n/2 * cnt;
  }else{
    ans += n/2 * cnt;
    ll cnt2 = min({q*4, h*2, s});
    ans += cnt2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int X;
    cin >> X;

    int uresisa = 0;

    uresisa += X / 500 * 1000;
    X = X % 500;

    uresisa += X / 5 * 5;

    cout << uresisa << endl;

}

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

int main(void){

    int y1, m1, d1, y2, m2, d2, diff;
    scanf("%d %d %d", &y1, &m1, &d1);
    scanf("%d %d %d", &y2, &m2, &d2);
    if (y2 < y1) {
        swap(y1, y2); swap(m1, m2); swap(d1, d2);
    }
    diff = y2 - y1;
    if (diff == 0) {
        if (m1 == m2 && d1 == d2) printf("%d\n", diff);
        else {
            printf("%d\n", diff+1);
        }
    } else {
        if (m1 == m2 && d1 == d2) printf("%d\n", diff);
        else if (m1 == m2 && d1 != d2) {
            if (d2 < d1) printf("%d\n", diff);
            else printf("%d\n", diff+1);
        }
        else if (m1 != m2) {
            if (m2 < m1) printf("%d\n", diff);
            else printf("%d\n", diff+1);
        }

    }
    return 0;
}



Measured memory_bytes: 2760
# coding: utf-8

# 標準入力 <int><int>
K, N = map(int, input().split())

# 標準入力 <int> list[]
A = list(map(int, input().split()))

lmax = 0

for a in range(N):
  if a != N - 1:
    if A[a + 1] - A[a] > lmax:
      lmax = A[a + 1] - A[a]
  else:
    if A[0] + K - A[a] > lmax:
      lmax = A[0] + K - A[a]

print(K - lmax)


Measured memory_bytes: 25800
s=input()
length=len(s)

s=s[::-1]

s=s+"WWWWWWW"

index=0
flag=True
while index<length:
    if s[index]=="m" and s[index+1]=="a" and s[index+2]=="e" and s[index+3]=="r" and s[index+4]=="d":
        index+=5
    elif s[index]=="e" and s[index+1]=="s" and s[index+2]=="a" and s[index+3]=="r" and s[index+4]=="e":
        index+=5   
    elif s[index]=="r" and s[index+1]=="e" and s[index+2]=="m" and s[index+3]=="a" and s[index+4]=="e" and s[index+5]=="r" and s[index+6]=="d":
        index+=7   
    elif s[index]=="r" and s[index+1]=="e" and s[index+2]=="s" and s[index+3]=="a" and s[index+4]=="r" and s[index+5]=="e":
        index+=6
    else:
        flag=False
        break
if flag:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include<string>
#include<cstdio>
#include <algorithm>
#include<complex>
using namespace std;

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

int main() {
	string inp;

	while (cin>>inp)
	{
		rep(i, 12) {
			cout << inp[i];
			if (i == 3) cout << " ";
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define faster_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
#define bug(a)       cerr << #a << " : " << a << endl;
template<class T>void ExEuclid(T n, T m, T &a, T &b, T &gcd){if(m==0){gcd=n;a=1;b=0;return;}ExEuclid(m,n%m,a,b,gcd);T x=a;a=b;b=x-(n/m)*a;}
template<class T>T gcd(T n, T m){if(m==0){return n;}gcd(m,n%m);}
template<class T>T lcm(T n, T m){return (n*m)/gcd(n,m);}
template<class T>string to_string(T n){string s="";while(n)s+=((n%10)+'0'),n/=10;reverse(s.begin(),s.end());return s;}
template<class T>ll to_int(T s){ll num=0,power=0;for(int i=s.size()-1; i>=0; i--)num+=(pow(10.0,power++)*(s[i]-'0'));return num;}
template<class T>bool is_mod(T n, T m){if(n%m==0)return true;return false;}
template<class T>bool is_upper(T s){for(int i=0; i<s.size(); i++)if(s[i]>90 || s[i]<65)return false;return true;}
template<class T>bool is_lower(T s){for(int i=0; i<s.size(); i++)if(s[i]>122 || s[i]<97)return false;return true;}
template<class T>T mod(T n, T m){return ((n%m)+m)%m;}
template<class T>T Big_mod(T base, T power, T MOD){
    if(power==1)return base;
    if(power & 1)return ((base%MOD)*(Big_mod(base,power-1,MOD))%MOD)%MOD;
    else {T temp=(Big_mod(base,power>>1,MOD));return ((temp%MOD)*(temp%MOD))%MOD;}
}



int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    faster_io;
    int n,m,sum=0;
    cin>>n;
    int a[n+5];
    for(int i=0; i<n; i++)cin>>a[i],sum+=a[i];
    sort(a,a+n);
    sum-=a[n-1];
    if(a[n-1]<sum)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <fstream>
#include <numeric>
#include <unordered_set>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>

#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x.size())
#define pb push_back
#define ll long long
#define int long long
#define pii pair <int, int>
#define print(x) for(auto it : x) cout << it << ' ';

using namespace std;

const int N = (int)(1e6) + 322;
const int MAXN = (int)(1e7) + 100;
const int inf = (int)(1e18) + 322;
const int mod = 998244353;
const double eps = 1e-6;
#define endl "\n" // remove

int n, k, c;
string s;
int dp[N], dps[N];

signed main () {
    ios_base :: sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k >> c >> s;
    s = '@' + s;
    for(int i = 1; i <= n; ++i) {
        if (s[i] == 'x') dp[i] = dp[i - 1];
        else dp[i] = ((i - c - 1 >= 0) ? dp[i - c -  1] : 0ll) + 1;
    }
    for(int i = n; i >= 1; --i) {
        if (s[i] == 'o') dps[i] = dps[i + c + 1] + 1;
        else dps[i] = dps[i + 1];
    }
    vector <int> ans;
    map <pair <int, int>, int> cnt;
    map <pair <int, int>, int> id;
    for(int i = 1; i <= n; ++i) {
//        cout << dp[i] << ' ' << dps[i] << endl;
        if (dp[i] + dps[i] - 2 == k - 1 && s[i] == 'o') {
            cnt[{dp[i], dps[i]}]++;
            id[{dp[i], dps[i]}] = i;
            ans.pb(i);
        }
    }
    for(auto it : cnt) {
        if (it.second == 1) {
            cout << id[it.first] << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 33992
#include <bits/stdc++.h>
#define F first
#define S second
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,a,b;
	cin>>n>>a>>b;
	string s;
	cin>>s;
	for (int i=0;i<n;i++){
		if (s[i]=='a'){
			if (a+b>0){
				cout<<"Yes\n";
				a--;
			}
			else{
				cout<<"No\n";
			}
		}
		else if (s[i]=='b'){
			if (a+b>0&&b>0){
				cout<<"Yes\n";
				b--;
			}
			else{
				cout<<"No\n";
			}
		}
		else{
			cout<<"No\n";
		}
	}
}

Measured memory_bytes: 976
n = int(input())
h = list(map(int, input().split()))

dp = [0]*n
dp[1] = abs(h[1]-h[0])

for i in range(2, n):
    # +1
    temp1 = abs(h[i]-h[i-1])+dp[i-1]
    # +2
    temp2 = abs(h[i]-h[i-2])+dp[i-2]

    dp[i] = min(temp1, temp2)

print(dp[n-1])

Measured memory_bytes: 13928
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
void solve(long long L, long long R){
  ll n,ans = 10000000;
  for (ll i = L; i < R;i++) {
    for (ll j = i+1; j <= R; j++) {
      n = (i*j)%2019;
      ans = min(ans,n);
      if(ans == 0)break;
    }
    if(ans == 0)break;
  }
  cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long L;
    scanf("%lld",&L);
    long long R;
    scanf("%lld",&R);
    solve(L, R);
}


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

int main(){
  
  int n;
  
  cin >> n;
  vector<int> A(n);
  for(int i = 0;i < n;i++) cin >> A[i];
  
  if(prev_permutation(A.begin(), A.end())){
    for(int i = 0;i < n;i++){
      cout << (i?" ":"");
      cout << A[i];
    }
    cout << endl;
  }
  next_permutation(A.begin(), A.end());
  
  for(int i = 0;i < n;i++){
    cout << (i?" ":"");
    cout << A[i];
  }
  cout << endl;
  
  if(next_permutation(A.begin(), A.end())){
    for(int i = 0;i < n;i++){
      cout << (i?" ":"");
      cout << A[i];
    }
    cout << endl;
  }
  
  return 0;
}


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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int i,j;
    ll w,h,x,y;
    cin>>w>>h>>x>>y;
    ll area=w*h/2;
    cout<<area<<(w*h%2?".5 ":" ")<<(x*2==w && y*2==h)<<endl;
    return 0;
}


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

int n;
long long t1, t2, a1, a2;

int main(void){
	cin >> n >> t1 >> a1;
	for(int i=1; i<n; i++){
		cin >> t2 >> a2;
		long long x = t1/t2, y = a1/a2;
		x = max(x, y);
		while(x*t2<t1 || x*a2<a1) x++;
		t1 = x*t2;
		a1 = x*a2;
	}
	cout << t1+a1 << endl;
}

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

using namespace std;

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

    int q;
    cin>>q;

    set<int> Set;
    while(q--)
    {
        int op,x;
        cin>>op>>x;

        if(op)
        {
            cout<<(Set.find(x)!=Set.end())<<endl;
        }else
        {
            Set.insert(x);
            cout<<Set.size()<<endl;
        }
    }

    return 0;
}



Measured memory_bytes: 12508
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


w, h, n = LI()
ws = list(range(w + 1))
hs = list(range(h + 1))
for _ in range(n):
    x, y, a = LI()
    if a == 1:
        ws = [i for i in ws if x <= i]
    elif a == 2:
        ws = [i for i in ws if i <= x]
    elif a == 3:
        hs = [i for i in hs if y <= i]
    else:
        hs = [i for i in hs if i <= y]
if len(ws) == 0 or len(hs) == 0:
    ans = 0
else:
    ans = (ws[-1] - ws[0]) * (hs[-1] - hs[0])
print(ans)


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

int main(void) {
    string str;
    
    getline(cin, str);
    
    for(int i = 0, size = str.size(); i < size; ++i) {
        if('a' <= str[i] && str[i] <= 'z') {
            str[i] = str[i] - 'a' + 'A';
        }
    }
    
    cout << str << endl;
}


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

def seachPrimeNum(N):
    max = int(numpy.sqrt(N))
    seachList = [i for i in range(2,N+1)]
    primeNum = []
    while seachList[0] <= max:
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum
prime = seachPrimeNum(10**5 + 3)
X = I()

print(min([i for i in prime if i >= X]))


Measured memory_bytes: 16684
from fractions import gcd
def init(init_val,n):
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2])

def segfunc(x,y):
    return gcd(x,y)

def update(k,x):
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2])

def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
    return res
N = int(input())
a = list(map(int,input().split()))
#####単位元######
ide_ele = 0

#num:n以上の最小の2のべき乗
num =2**(N-1).bit_length()
seg=[ide_ele]*2*num

init(a,N)
res = 0
for i in range(N):
    tmp = gcd(query(0,i),query(i+1,N))
    if tmp >= res:
        res = tmp
print(res)


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

int main()
{
	int n;
	string s,t1 = "",t2 = "";
	cin >> n >> s;
	if(n%2)cout << "No\n";
	else{
		for(int i=0;i<n/2;i++){
			t1 += s[i];
		}
		for(int i=n/2;i<n;i++){
			t2 += s[i];
		}
		if(t1==t2)cout <<"Yes\n";
		else cout << "No\n";
	}
}


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

int main(){
	int x,y;
	cin>>x>>y;
	if(x==1){
		x=14;
	}
	if(y==1){
		y=14;
	}
	if(x>y){
		cout<<"Alice";
	}else if(x<y){
		cout<<"Bob";
	}else{
		cout<<"Draw";
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
const int mod = 1000000007;
const int p = 13;

// 場合の数を格納
// i桁目までで剰余がj(0-12)であるときの場合の数
// 各桁において'?'の場合は0-9で走査して調べる
int dp[100005][15];

// i桁目の数をm(i)とする
// S = 10^(n-1)*m(1) + 10^(m-2)*m(2) + ... + 10^1*m(n-2) + 10^0*m(n-1)
// S%p = {(10^(n-1) % p)*(n(1) % p) + ... + (10^0 % p) * (m(n-1) % p)} % p
// 各桁の剰余が求まれば、その和を取れば全体の剰余は求まるので、桁ごとに分けてdp
int main(){
    string S;
    cin >> S;
    int n = S.length();
    
    int mul = 1;
    vector<int> m(n);       // (10のべき乗) % 13
    for(int i = n-1; i >= 0; --i){
        m[i] = mul;
        mul = (mul * 10) % p;
    }
    
    // dpテーブルの初期化
    dp[0][0] = 1;
    
    for(int i = 0; i < n; ++i){
        if(S[i] != '?'){        // 数が確定しているとき
            int temp = S[i] - '0';  // 今見ている桁の数字
            for(int j = 0; j < p; ++j){
                dp[i + 1][(j + m[i] * temp) % p] += dp[i][j];          // 剰余が(j + m[i]*temp) % 13になる
            }
        }
        else{               // 数が確定していないとき
            for(int N = 0; N <= 9; ++N){        // '?'に(0-9)を代入して剰余を計算
                for(int j = 0; j < p; ++j){
                    int id = (j + m[i] * N) % p;       // 更新するindex
                    dp[i + 1][id] = (dp[i + 1][id] + dp[i][j]) % mod;
                }
            }
        }
    }

    cout << dp[n][5] << endl;
}

Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
#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 all(a) (a).begin(),(a).end()		 //sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;
int main() {
    int N;
    cin>>N;
    vector<ll> A(N);
    rep(i,N)cin>>A[i];
    sort(all(A));
    ll ans = 0;
    print(A);
    if(N%2 == 0){//偶数
        //大小大小
        ans = 0;
        for (int i = N-1; i >= N/2; --i){
            if(i == N/2){
                ans += A[i];
            }
            else{
                ans += 2*A[i];
            }
            //cerr<<ans<<endl;
        }
        for(int i = 0; i < N/2; ++i){
            if(i == N/2-1){
                ans -= A[i];
            }
            else{
                ans -= 2*A[i];
            }
            //cerr<<ans<<endl;
        }
    }
    else{//奇数
        //大小大小大
        ll ans1 = 0;
        for (int i = N-1; i >=N/2; --i){
            if(i == N/2||i == N/2 + 1){
                ans1 += A[i];
            }
            else{
                ans1 += 2*A[i];
            }
        }
        for(int i = 0; i < N/2; ++i){
                ans1 -= 2*A[i];
        }
        //小大小大小
        ll ans2 = 0;
        for (int i = N-1; i >N/2; --i){
            ans2 += 2*A[i];
        }
        for(int i = 0; i <= N/2; ++i){
            if(i == N/2||i == N/2-1){
                ans2 -= A[i];
            }
            else{
                ans2 -= 2*A[i];
            }
        }
        ans = max(ans1,ans2);
        //cerr<<ans1<<" "<<ans2<<endl;
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>

using namespace std;
int main() {
  int n, t;
  cin >> n >> t;
  int total = 0;
  int start = 0;
  int end = 0;
  for (int i= 0;i<n;i++){
    int tt;
    cin >> tt;
    if(tt > end){
      total += end - start;
      start = tt;
    }
    end = tt+t;
  }
  total += end - start;
  cout << total << endl;
}


Measured memory_bytes: 256
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE Strict #-}
{-# LANGUAGE StrictData #-}
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.Vector.Algorithms.Insertion as VA
import Data.Array.Unboxed
import Data.Array.ST
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Control.Monad.ST
import Data.List
import Data.Char

dp :: Int -> VU.Vector (Int,Int) -> UArray (Int,Int) Int
dp n bs = runSTUArray $ do
    arr <- newArray ((0,0),(n,n)) 0
    forM_ [0..n-1] $ \i -> do
        forM_ [0..n-i-1] $ \j -> do
            ij <- readArray arr (i,j)
            let (index,value) = bs VU.! (i+j)
                left          = ij + value*(abs (index-i))
                right         = ij + value*(abs ((n-j-1)-index))
            l <- readArray arr (i+1,j)
            writeArray arr (i+1,j) $ max l left
            r <- readArray arr (i,j+1)
            writeArray arr (i,j+1) $ max r right
    return arr
            
            
            

main :: IO ()
main = do
    n <- readLn
    as <- VU.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    let bs :: VU.Vector (Int,Int)
        bs = runST $ do
        bs <- VU.thaw (VU.indexed as)
        VA.sortBy (\j k -> compare (snd k) (snd j)) bs
        VU.freeze bs
    print $ maximum [ dp n bs ! (i,n-i) | i <- [0..n]]  

Measured memory_bytes: 36048
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   long N = sc.nextLong();
   long forans = N/11;
   
   long ans = forans*2;
   if(N-forans*11>6) ans+=2;
   else if(N%11!=0) ans++;
   System.out.println(ans);
 }
}

Measured memory_bytes: 23124
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int s = sc.nextInt();
		if(s<1000000000) {
			for(int i=0; i<k; i++) {
				System.out.print(s +" ");
			}
			
			for(int i=0; i<n-k; i++) {
				System.out.print((s+1) + " ");
			}
		}else {
			for(int i=0; i<k; i++) {
				System.out.print(s +" ");
			}
			
			for(int i=0; i<n-k; i++) {
				System.out.print(1 + " ");
			}
		}
	}

}


Measured memory_bytes: 44484
#include <iostream>
#include <vector>
#include <string>
#include <functional>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
  int N, X;
  cin >> N >> X;
  vector<int> L(N);
  for(int i=0; i<N; i++){
    cin >> L[i];
  }
  int counter=1;
  int D=0;
  for(int i=0; i<N; i++){
    D += L[i];
    if(D<=X) counter++;
    else break;
  }
  cout << counter << endl;
  return 0;
}


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

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next().replaceAll("eraser", "").replaceAll("erase", "").replaceAll("dreamer", "").replaceAll("dream", "");
		System.out.println((s.equals(""))? "YES" : "NO");
	}
}

Measured memory_bytes: 28216
#include<stdio.h> 
int main() 
{
	 int a[10],i,j,t;
	 for(i=0;i<10;i++) scanf("%d",&a[i]); 
	for(i=0;i<10;i++){
		for(j=i+1;j<10;j++)
			if(a[i]<a[j]) 
				{t=a[i];a[i]=a[j];a[j]=t;}
	} 
		for(i=0;i<3;i++) printf("%d\n",a[i]); 
return 0;
} 


Measured memory_bytes: 2024
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <numeric>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecvec vector<vec>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecpll vector<pll>
#define vecbl vector<bool>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}

const ll mod = 1000000007;
int n,k;
vec par,num;
vector<vec> chi;
vecll P;

void makeChi(int x){
    if(x!=0)num[x]--;
    REP(e,chi[x])if(e!=par[x]){
        par[e]=x;
        makeChi(e);
    }
    return;
}

void makePerm(int m){
    P.resize(m);
    P[0]=1;
    rep(i,m-1){
        P[i+1]=P[i]*(i+1)%mod;
    }
    return;
}

ll modpow(ll a,ll b){
    if(b==0)return 1;
    if(b%2==0){
        ll d=modpow(a,b/2);
        return d*d%mod;
    }
    return modpow(a,b-1)*a%mod;
}

ll di(ll a,ll b){
    return a*modpow(b,mod-2)%mod;
}

ll Perm(ll a,ll b){
    if(a<b)return 0;
    return di(P[a],P[a-b]);
}

ll func(int x){
    ll res=x==0?Perm(k,num[0]+1):Perm(k-2,num[x]);
    REP(e,chi[x])if(e!=par[x]){
        res = res*func(e)%mod;
    }
    return res;
}

int main(){
    n=in();
    k=in();
    par.resize(n);
    num.resize(n);
    chi.resize(n);
    rep(i,n-1){
        int a=in()-1,b=in()-1;
        chi[a].pb(b);
        chi[b].pb(a);
        num[a]++;
        num[b]++;
    }
    makePerm(max(n,k)+1);
    par[0]=-1;
    makeChi(0);
    cout<<func(0)<<endl;
}


Measured memory_bytes: 13832
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

	REP(i, n) {
		vi hen(3);
		cin >> hen[0] >> hen[1] >> hen[2];
		sort(RALL(hen));

		if(hen[0]*hen[0] == hen[1]*hen[1] + hen[2]*hen[2]) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
using namespace std;
#define mem(a) memset(a,0,sizeof(a))
#define dbg(x) cout<<#x<<" = "<<x<<endl
#define ll long long
//不要再爆long long了！！！！！！！！不要再爆long long了！！！！！！！ 
int a[10010]={0};
int main()
{
	int i,j,k,s,n;
	for(i=1;i<=100;i++)
	{
		for(j=1;j<=100;j++)
		{
			for(k=1;k<=100;k++)
			{
				s=i*i+j*j+k*k+i*j+j*k+k*i;
				if(s<=10000)a[s]++;
			}
		}
	}
	cin>>n;
	for(i=1;i<=n;i++)
	{
		printf("%d\n",a[i]);
	}
	return 0;
}

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

int main()
{
	int n;
	scanf("%d",&n);
	if(n % 7 == 0) n /= 7;
	int rem = 1;
	int pos = 1;
	for(int i = 2; i <= n; i++){
		rem = rem*10 + 1;
		rem = rem % n;
		pos++;
		if(rem == 0 || rem == 1) break;
	}
	if(n == 1) printf("1\n");
	else if(rem == 0) printf("%d\n",pos);
	else printf("-1\n");
}

Measured memory_bytes: 3784
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>

using namespace std;

int main() {
	int n, a, b, tmp1, tmp2, ans = 0;
	cin >> n >> a >> b;
	for (int i = 1; i <= n; i++) {
		tmp1 = 0;	tmp2 = i;
		for (int j = 0; j < 5; j++) {
			tmp1 += tmp2 % 10;
			tmp2 /= 10;
		}
		if (a <= tmp1 && tmp1 <= b) {
			ans += i;
		}
	}
	cout << ans << endl;
	return 0;
}

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

public class Main{
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int A = scanner.nextInt();
		int B = scanner.nextInt();
		int C = scanner.nextInt();
		scanner.close();
		int []n = {A, B, C};
		Arrays.sort(n);
		int ans = 0;
		int x = n[2] - n[1];
		int y = n[2] - n[0];
		if((x % 2 == 0 && y % 2 == 0) || (x % 2 == 1 && y % 2 == 1)) {
			ans = (x + y) / 2;
		}else {
			if(x == 1) {
				ans = 1 + y / 2 + 1;
			}else {
				ans = x / 2 + y / 2 + 2;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23764
# -*- coding:utf-8 -*-
x, y = map(int, input().split())
ans = []
index = 0
for tmp in range(x, y+1):
    factor = (2**index)*x
    if x <= factor and factor <= y:
        ans.append(factor)
        index += 1
    else:
        break
print(len(ans))

Measured memory_bytes: 2940
h,w=map(int,input().split())
l=[input() for i in range(h)]
cl=[[0]*w for i in range(h)]
for i in range(h):
    for j in range(w):
        if l[i][j]=="#":
            for a in {max(0,i-1),i,min(h-1,i+1)}:
                for b in {max(0,j-1),j,min(w-1,j+1)}:
                    cl[a][b]+=1
cl=[[str(cl[i][j]) if l[i][j]!="#" else "#" for j in range(w)] for i in range(h)]
for i in range(h):
    print("".join(cl[i]))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define INF 1e8
typedef long long int ll;
const double PI = acos(-1);

using Graph = vector<vector<int>>;
int main()
{
  ll n, k;
  cin >> n >> k;
  n %= k;
  while (n > abs(n - k))
  {
    n = abs(n - k);
  }
  cout << n << endl;
}


Measured memory_bytes: 3552
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define each(it,o) for(auto it= (o).begin(); it != (o).end(); ++ it)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define inrep int t;cin>>t; while(t--)
#define pb emplace_back
using namespace std;
using namespace __gnu_pbds; 


typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii > vpii;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pll > vpll; 
typedef vector<string> vs;
typedef long double ld;
const ll MOD = 1e9+7;
template<typename T> istream& operator>> ( istream &in,vector<T> &v ) {

    for ( unsigned   i=0; i<v.size(); i++ )
        in>>v[i];
    return in;
}

ll extended_GCD(ll a , ll b , ll &x , ll &y){
    if(a == 0){
        x = 0;
        y = 1;
        return b;
    }
    ll x1 , y1;
    ll gcd = extended_GCD(b%a , a , x1 , y1);
    x = y1 - (b/a)*x1; 
    y = x1;
    return gcd;
}
ll power(ll a, ll b, ll m = MOD) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll modinv(ll a , ll mod ){
    ll x , y;
    extended_GCD(a , mod , x , y);
    if(x < 0) x += mod;
    return x;
}

ll mul(ll a,ll b,ll m)
{
    return (a%m*b%m)%m;
}
  
 


int main()
{
   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    string t;
    cin>>s>>t;
    int n=s.length();
    int ans=0;
    for(int i=0;i<n;i++)
    {
        ans+=(s[i]!=t[i]);
    }
    cout<<ans;
    
    
    return 0;
}

Measured memory_bytes: 3800
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(void){
    string s;
    cin>>s;
    vector<bool> ok(s.size(), false);
    vector<string> find_word = {"dream", "erase", "er"};
    rep(i, 2){
        auto pos = s.find(find_word[i]);
        while(pos != string::npos){
            for(int j = (int)pos;j<=pos+find_word[i].size()-1;j++){
                ok[j] = true;
            }
            pos = s.find(find_word[i], pos + find_word[i].size());
        }
    }
    auto pos = s.find(find_word[2]);
    while(pos != string::npos){
        if(!ok[pos] && ok[pos-1] && s[pos-1] == 'm' || ok[pos] && s[pos-1] == 's') {
            for(int j = (int)pos;j<=pos+find_word[2].size()-1;j++){
                ok[j] = true;
            }
        }
        pos = s.find(find_word[2], pos + find_word[2].size());
    }
    rep(i, s.size()){
        if(!ok[i]) {
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}

Measured memory_bytes: 512