akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#include<numeric>
#define INF 1e9
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using namespace std;
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 (b<a) { a=b; return 1; } return 0; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  return s;
}

template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
  s << vv[i] << endl;
  }
  return s;
}

int N,C;
signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin >> N >> C;
  vector<vector<int>> D(C,vector<int>(C,0));
  for(int i = 0 ; i < C ; i++){
    for(int j = 0 ; j < C ; j++){
      int d;
      cin >> d;
      D[i][j] = d;
    }
  }
  vector<vector<int>> fi(N,vector<int>(N,0));
  for(int i = 0 ; i < N ; i++){
    for(int j = 0 ; j < N ; j++){
      cin >> fi[i][j];
      fi[i][j]--;
    }
  }
  vector<vector<int>> cost(3,vector<int>(C,0));
  for(int c = 0 ; c < C; c++){
    for(int i = 0 ; i < N; i++){
      for(int j = 0 ; j < N ; j++){
        cost[(i+j) % 3][c] += D[fi[i][j]][c];
      }
    }
  }

  int res = 1<<30;
  int c[3];
  for (c[0] = 0; c[0] < C; ++c[0]) {
    for (c[1] = 0; c[1] < C; ++c[1]) {
      if (c[1] == c[0]) continue;
      for (c[2] = 0; c[2] < C; ++c[2]) {
        if (c[2] == c[0] || c[2] == c[1]) continue;
        int tmp = 0;
        for (int it = 0; it < 3; ++it) tmp += cost[it][c[it]];
        res = min(res, tmp);
      }
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <vector>

using namespace std;
 
int main(){
    int H,W;
    vector<string> A;
  
    cin >> H >> W;

    for(int i = 0; i < H; i++){
        string a;
        cin >> a;
        A.push_back(a);
    }

    for(int i = 0; i < W+2; i++){
        cout << '#';
    }

    cout << endl;

    for(int i = 0; i < H; i++){
        cout << '#' << A[i] << '#' << endl;
    }

    for(int i = 0; i < W+2; i++){
        cout << '#';
    }

    cout << endl;

    return 0;
}


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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define pb push_back

using namespace std;
using ll=long long;
using pii= pair<int, int>;
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
template<typename... T> void rd(T&... args) {((cin>>args), ...);}
template<typename... T> void wr(T... args) {((cout<<args<<" "), ...);cout<<endl;}


const int mod=1e9+7;
template <int MOD>
struct ModInt {
    int val;
    // constructor
    ModInt(ll v = 0) : val(int(v % MOD)) {
        if (val < 0) val += MOD;
    };
    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt inv() const { return this->pow(MOD - 2); }
    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
    ModInt pow(ll n) const {
        auto x = ModInt(1);
        auto b = *this;
        while (n > 0) {
            if (n & 1) x *= b;
            n >>= 1;
            b *= b;
        }
        return x;
    }
    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = int(ll(val) * x.val % MOD);
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }
    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }
    // I/O
    friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept { return is >> x.val; }
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};
using mint=ModInt<mod>;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    for(auto& it:a) cin>>it;
    vector<mint> dp(k+1);
    dp[0]=1;
    for(int i=0;i<n;i++){
        vector<mint> sum(k+2),ndp(k+1);
        partial_sum(all(dp),sum.begin()+1);
        for(int j=0;j<=k;j++){
            ndp[j]+=sum[j+1];
            if(j>=a[i]) ndp[j]-=sum[j-a[i]];
        }
        dp=ndp;
    }
    cout<<dp[k];
    return 0;
}



Measured memory_bytes: 4536
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<sstream>
#include<climits>
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 2000;
int N;
int a[MAX_N+2];
int dp[MAX_N+2][MAX_N+2];

int main() {
  cin >> N >> a[0] >> a[1];
  for (int i = 2; i < N+2; ++i) cin >> a[i];

  for (int i = 0; i < N+2; ++i) {
    dp[i][N+1] = dp[N+1][i] = (a[i]-a[N+1]>0 ? a[i]-a[N+1] : a[N+1]-a[i]);
  }

  for (int i = N; i >= 0; --i) {
    for (int j = N; j >= 0; --j) {
      if (i > j) {
        if (i == j+1) {
          int t = 1e9;
          for (int k = i+1; k < N+2; ++k) t = min(t,dp[i][k]);
          dp[i][j] = t;
        } else  dp[i][j] = dp[i][j+1];
      } else if (i < j) {
        if (j == i+1) {
          int t = 0;
          for (int k = j+1; k < N+2; ++k) t = max(t,dp[k][j]);
          dp[i][j] = t;
        } else dp[i][j] = dp[i+1][j];
      }
    }
  }

  cout << dp[0][1] << endl;

  return 0;
}


Measured memory_bytes: 15872
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp make_pair
#define fi first
#define se second
#define pt(num) cout << num << "\n"
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;



int main(void) {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    
    pt(max(min(b, d)-max(a, c), 0));
    
    
    
    
}









Measured memory_bytes: 256
N,W = map(int,input().split())
a=[[0,0]]
for i in range(0,N):
    v,w = map(int,input().split())
    a.append([v,w])

dp=[[0]*10010 for _ in range(110)]
for i in range(1,N+1):
    for j in range(0,W+1):
        if j < a[i][1]:
            dp[i][j]= dp[i-1][j]
        else:
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-a[i][1]]+a[i][0])
print(dp[N][W])



Measured memory_bytes: 26244
from collections import deque
S = input()
cnt = 0
dq = deque()
for i in range(len(S)):
    if not dq:
        dq.append(S[i])
    elif dq[-1] == "0" and S[i] == "0":
        cnt += 1
        dq.append("1")
    elif dq[-1] == "1" and S[i] == "1":
        cnt += 1
        dq.append("0")
    else:
        dq.append(S[i])
print(cnt)

Measured memory_bytes: 4212
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def input():
    return sys.stdin.readline()


def resolve():
    n, m = map(int, input().split())
    h_list = list(map(int, input().split()))
    a_list = []
    b_list = []
    ans_list = [1 for i in range(n)]
    iso_list = [1 for i in range(n)]

    count = 0
    for i in range(m):
        a, b = map(int, input().split())
        if h_list[a-1] > h_list[b-1]:
            ans_list[b-1] = 0
        elif h_list[a-1] < h_list[b-1]:
            ans_list[a-1] = 0
        elif h_list[a-1] == h_list[b-1]:
            ans_list[a-1] = 0
            ans_list[b-1] = 0



    count = 0
    for i in ans_list:
        if i == 1:
            count += 1


    print(count)




if __name__ == "__main__":
    resolve()



Measured memory_bytes: 97488
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int N, M, K;
vi X;
void input() {
  cin >> N >> K;
  X.resize(N);
  rep(i, 0, N - 1) { cin >> X[i]; }
}
int dp[101][101][5050];
void solve() {
  dp[0][0][0] = 1;
  rep(i, 0, N - 1) {
    ;
    ;
    rep(k, 0, i) {
      ;
      ;
      rep(s, 0, 5050) {
        if (dp[i][k][s] == 0) continue;
        dp[i + 1][k + 1][s + X[i]] += dp[i][k][s];
        dp[i + 1][k][s] += dp[i][k][s];
        ;
        ;
      }
    }
  };
  int sum = 0;
  rep(i, 1, N) { sum += dp[N][i][K * i]; };
  cout << sum << endl;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 151808
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

cnt = b[a[0] - 1]
for i in range(1, n):
  cnt += b[a[i] - 1]
  if a[i] == a[i - 1] + 1:
    cnt += c[a[i] - 2]

print(cnt)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int r;
    cin >> r;
    cout << (3 * r * r) << endl;
    return 0;
}

Measured memory_bytes: 3544
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include <vector>   
using namespace std;
int main()
{
	long long n,k;
	cin>>n>>k;
	pair<long long,long long> a[100005];
	for(int i=0;i<n;i++){
		int c,b;
		cin>>c>>b;
		a[i]=make_pair(c,b);
	}
	sort(a,a+n);
	long long ans=0;
	int i=0;
	while(k>0){
		if(a[i].second<k){
			ans+=a[i].second*a[i].first;
			k-=a[i].second;
			i++;
		}
		else {
			ans+=k*a[i].first;
			k=0;
			i++;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 1792
N = int(input())
A = list(map(int,input().split()))

ans = 0
xor = 0
l,r = 0,0

while r < N:
    if xor^A[r] == xor+A[r]:
        ans += r-l+1
        xor ^= A[r]
    else:
        while xor^A[r] != xor+A[r]:
            xor ^= A[l]
            l += 1
        xor ^= A[r]
        ans += r-l+1
    r += 1

print(ans)

Measured memory_bytes: 23560
#include<bits/stdc++.h>
#define N 18
using namespace std;
int dis[N][N];
int n,m;
int tot[(1<<15)+3];
int dp[(1<<15)+3][N];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1,f,t,d;i<=m;i++){
		scanf("%d%d%d",&f,&t,&d);
		dis[f-1][t-1]=dis[t-1][f-1]=d;
	}
	
	for(int i=1;i<(1<<n);i++){
		int pos=-1,aim=i-(i&(-i));
		for(int j=0;j<n;j++)
			if((i&(-i))>>j == 1){
				pos=j;break;
			}
		if(pos!=-1){
			tot[i]=tot[aim];
			for(int j=0;j<n;j++)
				if(aim&(1<<j)) tot[i]+=dis[pos][j];
		}
	}
	
	memset(dp,0xc0,sizeof(dp));
	for(int i=1;i<(1<<n);i+=2)
		dp[i][0]=tot[i];
	for(int i=1;i<(1<<n);i++)
		for(int j=0;j<n;j++)
			if(i&(1<<j)&&dp[i][j]!=dp[0][0]){
				for(int k=0;k<n;k++)
					if((i&(1<<k)) == 0&&dis[j][k] != 0){
						for(int mask=((1<<n)-1)^(i|(1<<k)),v=mask;;v=(v-1)&mask){
							dp[i|(1<<k)|v][k]=max(dp[i|(1<<k)|v][k],dp[i][j]+dis[j][k]+tot[v|(1<<k)]);
							if(v==0) break;
						}
					}
			}
		
	int ans=-1e9;
	for(int i=(1<<(n-1));i<(1<<n);i++) ans=max(ans,dp[i][n-1]);
	cout<<tot[(1<<n)-1]-ans<<endl;
	return 0;
}

Measured memory_bytes: 2688
#include <iostream>
using namespace std;
int main(){
	int n,a,b,c,i,s,e;
	while(cin>>n,n){
		for(i=0;i<n;i++){
			cin>>a>>b>>c;
			s=(a+b+c)/3,e=(a+b)/2;
			if(s>=80||e>=90||a==100||b==100||c==100)cout<<'A'<<endl;
			else if(s>=70||(s>=50&&(a>=80||b>=80)))cout<<'B'<<endl;
			else cout<<'C'<<endl;
		}
	}
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  long long n, ans = 0, last;
  cin>>n;
  vector<string> s(n);
  for (int i = 0;i<n;i++){
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
  }
  sort(s.begin(), s.end());
  for (int i = 1; i < n;i++){
    if(s[i]==s[i-1]){
      last = i;
      while(s[i]==s[i-1]){
        i++;
      }
      ll N = i - last;
      ans += (2 + (N - 1)) * N / 2;
      //cout << "N=" << N << endl;
      //cout << "i=" << i <<" ans="<<ans<< endl;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6404
#include <bits/stdc++.h>
using namespace std;
 
#define io ios::sync_with_stdio(false)
#define pb push_back
#define pqueue priority_queue
#define fi first
#define se second
#define ls rt<<1
#define rs rt<<1|1
#define sz(x) (int)(x).size()
#define dbg(x) cout<<#x<<" --- "<<x<<endl
#define mst(x,a) memset(x,a,sizeof(x))
#define fin(a) freopen(a,"r",stdin)
#define fout(a) freopen(a,"w",stdout)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll gcd(ll a,ll b){ return b==0?a:gcd(b,a%b); }
ll qpow(ll a,ll b,ll m){ ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r; }
const int inf=0x7fffffff;
const int maxn=2e5+10;
map<ll,ll> mp,mm;
ll a[maxn];
ll n,k;
 
int main(){
	io;
	cin>>n>>k;
	for(ll i=1;i<=n;i++)cin>>a[i];
	for(ll i=1;i<=n;i++)a[i]=(a[i]+a[i-1])%k;
	mp[0]++;
	ll ans=0;
	for(ll i=1;i<=n;i++){
		ll x=a[i]-i,y=a[i]-i+k;
		ans+=mp[x];
		ans+=mm[y];
		mp[x]++;
		mm[x]++;
		if(i+1-k>=1)mm[a[i+1-k]-i-1+k]--;
	}
	cout<<ans<<endl;
	return 0;
}


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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    double ans;ans=0;
    int N=in();
    double a;
    REP(i,N){
        cin>>a;
        a=1/a;
        ans+=a;
    }
    ans=1/ans;
    cout<<setprecision(100);
    print(ans);
    return 0;
}


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

int main() {
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a+3);
	cout << a[0] << " " << a[1] << " " << a[2] << endl;
	return 0;
}


Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
int n,m,ans;
map<int,int>mp;
int main()
{
    string s;
    cin>>s;
    reverse(s.begin(),s.end());
    int now=0,base=1;
    long long ans=0;
    mp[0]=1;
    for(char c:s)
    {
        now+=(c-'0')*base;
        base*=10;
        now%=2019,base%=2019;
        //cout<<c<<" "<<now<<" ---"<<(2019-now)%2019<<endl;
        if(mp.count(now))ans+=mp[now];
        mp[now]++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define F first
#define S second
#define db double
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
using namespace std;
 
 ll mod=1e9 +7;
 
ll expo(ll base,ll exponent,ll mod){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
 
vector<bool>  prime(90000002,true);
void Sieve() 
{ 
   
    for (int p=2; p*p<=90000001; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=90000001; i += p) 
                prime[i] = false; 
        } 
    } 
}

const ll M=200006;
ll f[M],inv[M];

void compute(){
    f[0]=1;
    rep(i,1,M-1){
        f[i]=(1LL*i*f[i-1])%mod;
    }
    inv[M-1]=expo(f[M-1],mod-2,mod);
    for(ll i=M-2;i>=0;i--){
        inv[i]=(1LL*(i+1)*inv[i+1])%mod;
    }
}
ll C(ll n,ll r){
    return (1LL*((1LL*f[n]*inv[r])%mod)*inv[n-r])%mod;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // compute();
    // Sieve();
    ll tests=1;
    // cin>>tests;
    while(tests--)
    {
      string s,t;
      cin>>s>>t;
      cout<<t<<s;

    }
    return 0;
   }

Measured memory_bytes: 14080
import numpy as np
A,V = map(int,input().split())
B,W = map(int,input().split())
T = int(input())

if V*T <= W*T:
    print("NO")
elif A > B:
    if A - V*T > B - W*T:
        print ("NO")
    else:
        print("YES")
else:
    if A + V*T >= B + W*T:
        print("YES")
    else:
        print("NO")
        

Measured memory_bytes: 27120
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>
#include<unordered_map>

#define for0(i,n) for(ll i = 0;i < (n);i++)
#define for1(i,n) for(ll i = 1;i<=(n);i++)
#define for2(i,n) for(ll i = 2;i<=(n);i++)
#define rep(i,st,en,cnt) for(ll i = st;i <= en;i+=cnt)
#define PB push_back
#define MP make_pair
#define fastio cin.tie(0);cout.tie(0);ios::sync_with_stdio(0)
#define F first
#define S second
#define bit(x,n) (x & (1<<(n)))
#define EPS 1e-8
#define all(x) (x).begin(),(x).end()
#define INF 0x3f3f3f3f3f3f3
#define NEGINF -INF
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define inp_arr(a,n) for0(i,n) {cin>>a[i];}
#define out_arr(a,n) for0(i,n) {cout<<a[i]<<" ";}
#define deb1(a) cout<<(a)<<endl;
#define deb2(a,b) cout<<(a)<<" "<<(b)<<endl;
#define deb3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl;
#define RAND(x,y) ((x) + (rand()%(y-x+1)))

using namespace std;

typedef pair<int,int> ii;
typedef pair<long long,long long> pll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<long long> vl;
typedef vector<vector<ll> > vvl;
typedef vector<pair<long long, long long> > vll;

ii DR8[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
ii DR4[] = {{-1,0},{0,-1},{0,1},{1,0}};

const ll mod = 1e9+7;

ll nop = 2;
vi primes(nop,1);

void sieve(){
    primes[1] = primes[0] = 0;
    for(ll i = 2;i * i <= nop;i++){
        if(primes[i]){
            for(ll j = i*i; j <= nop;j+=i){
                primes[j] = 0;
            }
        }
    }
}


bool isVowel(char ch) { ch = tolower(ch);return (ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u'); }

ll gcd(ll a,ll b){    //a larger, b smaller
    if(b>a) swap(b,a);
    if(b==0) return a;
    return gcd(b,a%b);
}

void extgcd(ll a,ll b,ll& x,ll& y){  //a smaller b larger
    if(a==0) {
        x = a;y = b;
        return;
    }
    extgcd(b%a,a,x,y);
    ll y1 = y,x1 = x;
    x = y1 - (b/a)*x1;
    y = x1;
}

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

ll bexp(ll num,ll e){
    ll ans = 1;
    while(e>0){
        if(e&1){
            ans *= num;
        }
        num *= num;
        e>>= 1;
    }
    return ans;
}

ll mexp(ll num,ll e){
    ll ans = 1;
    while(e>0){
        if(e&1){
            ans = (ans *num)%mod;
        }
        num = (num*num)%mod;
        e>>=1;
    }
    return ans%mod;
}

ll modinv(ll a){
    return mexp(a,mod-2);
}

void solve() {
    int n;
    cin>>n;
    ll ans = 0;
    for1(i,n) {
        ll a = i,l = (n/i)*i,no = (n/i);
        ans += (no*(a+l)/2);
    }
    deb1(ans);
}

int main() {
    fastio;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int t = 1;
    //cin>>t;
    for1(T,t){
        //cout<<"Case #"<<T<<": ";
        solve();
    }
    /* #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif */
    return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll const mod = 1e9+7;
ll const N = 50;
ll const inf = 2e16;
#define UNASSIGNED -1
ll n0,k0;
pair<ll,ll>  dp[3002][3002];
bool mark[3002][3002];
pair<ll,ll> fun(ll arr[],ll s,ll e,ll play)
{
    if(s>e) 
    {
        return make_pair(0,0);
    }
    if(mark[s][e]!=0) return dp[s][e];
    pair<ll,ll> a,b,c;
    a=fun(arr,s+1,e,(play+1)%2);
    b=fun(arr,s,e-1,(play+1)%2);
    
    if(play==0)
    {
        
    if(a.first+arr[s]>b.first+arr[e])
    {
        c=a;
        c.first+=arr[s];
    }
    else
    {
        c=b;
        c.first+=arr[e];
        
    }
    
    }
    else
    {
        
    if(a.second+arr[s]>b.second+arr[e])
    {
        c=a;
        c.second+=arr[s];
    }
    else
    {
        c=b;
        c.second+=arr[e];
        
    }
    
    }
    //cout<<play<<" "<<c.first<<" "<< c.second<<"\n";
    
    mark[s][e]=1;
    dp[s][e]=c; 
    return dp[s][e];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a,b,c,d,e,f,x,n,m,p,k,t,q;
    t=1;
    //cin>>t;
    //string s1,s2,s3;
    //simpleprime(sqrt(1000000000)+1);
	for(ll t0=0;t0<t;t0++)
    {
        cin>>n;
        memset(mark,0,sizeof(mark));
        n0=n;
        k0=k;
        ll arr[n];
        for(int i=0;i<n;i++) cin>>arr[i];
        
        
        pair<ll,ll> a11=fun(arr,0,n-1,0);
        
        cout<<a11.first-a11.second;
    }
    return 0;
}


Measured memory_bytes: 150016
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  ll N;
  cin >> N;
  vector<ll> A(N);
  vector<vector<ll>> x(N), y(N);
  for (ll i = 0; i < N; i++)
  {
    cin >> A.at(i);
    x.at(i).resize(A.at(i)), y.at(i).resize(A.at(i));
    for (ll j = 0; j < A.at(i); j++)
    {
      cin >> x.at(i).at(j) >> y.at(i).at(j);
      x.at(i).at(j)--;
    }
  }

  ll ans = 0;
  for (ll b = 0; b < (1LL << N); b++)
  {
    bitset<15> B(b);
    //cerr << B << endl;

    bool ok = true;
    for (ll i = 0; i < N; i++)
    {
      for (ll j = 0; j < A.at(i); j++)
      {
        if (B.test(i) && (B.test(x.at(i).at(j)) != y.at(i).at(j)))
        {
          ok = false;
          break;
        }
      }
      if (!ok)
        break;
    }

    if (ok)
    {
      chmax(ans, (ll)B.count());
      //cerr << B << endl;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define F first
#define S second
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr> 
#define pr pair<int, int> 
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;
vi  a[N];

int solve() 
{
	//happy coding

	int n,m;
	cin>>n>>m;
	while(m--){
		int x,y;
		cin>>x>>y;--x;--y;
		a[x].pb(y);
		a[y].pb(x);
	}

	queue<int>q;
	vi vis(n,-1);
	vis[0] = 0;
	q.push(0);
	while(q.size()){
		int u = q.front();
		q.pop();
		for(auto& v: a[u]){
			if(vis[v]>=0)continue;
			vis[v] = u;
			q.push(v);
		}
	}

	bool found = false;
	for(int i=0;i<n;i++){
		if(vis[i]<0)found = true;
	}

	if(found){
		cout<<"No"<<endl;
	}else{
		cout<<"Yes"<<endl;
		for(int i=1;i<n;i++){
			cout<<vis[i]+1<<endl;
		}
	}

	
	return 0;
}
int main(){
	int test = 1;
	//scanf("%d", &test);
	while (test--)solve();return 0;
}

Measured memory_bytes: 12572
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>  
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <list>
#include <cmath>
#include <bitset>
#include <queue>
#include <stack>
#include <sstream>
#include <functional>
#include <cassert>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<char, char> pcc;
const int inf = 0x3f3f3f3f;
const LL lnf = 0x3f3f3f3f3f3f3f3fLL;
const double pi = 3.14159265358979323846;
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int maxn = 10 + 10;

int n;
LL f[2][maxn];

int main() {
	int CAS = 0;
	//std::ios::sync_with_stdio(0);  
	//std::cin.tie(0);  
#ifdef NIGHT_13  
	freopen("in.txt", "r", stdin);
	//freopen("out2.txt", "w", stdout);
	int time_night_13 = clock();
#endif // NIGHT_13  

	while (scanf("%d", &n) == 1) {
		memset(f, 0, sizeof f);

		int a; scanf("%d", &a);
		if (a & 1) f[0][1] = 2, f[1][1] = 1;
		else f[0][1] = 1, f[1][1] = 2;

		for (int i = 2; i <= n; ++i) {
			scanf("%d", &a);
			if (a & 1) { //odd1 even2
				f[0][i] += f[0][i - 1] * 3 + f[1][i - 1] * 2;
				f[1][i] += f[1][i - 1];
			}
			else { //odd2 even1
				f[0][i] += f[0][i - 1] * 3 + f[1][i - 1];
				f[1][i] += f[1][i - 1] * 2;
			}
		}
		printf("%lld\n", f[0][n]);
	}


#ifdef NIGHT_13  
	fprintf(stderr, "\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
	fprintf(stderr, "\t   Time: %d ms", (int)clock() - time_night_13);
	fprintf(stderr, "\n...........................................\n\n");
#endif // NIGHT_13  
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector> // 可変長配列
using namespace std;
static const int MAX = 1000000;


void printLine(int A[], int N) {
    for (int i = 0; i < N; i++) {
        if (i > 0) {
            printf(" ");
        }
        printf("%d", A[i]);
    }
    printf("\n");
}

int insertionSort(int A[], int N, int g) {
    int cnt = 0;
    for (int i = g; i < N;i++) {
        int seq = A[i];
        int j = i - g;
        while(j >= 0 && A[j] > seq) {
            A[j + g] = A[j];
            j = j - g;
            cnt++;
        }
        A[j + g] = seq;
    }
    return cnt;
}

int shellSort(int A[], int N) {
    // 可変長配列でshell sortの幅を生成
    // この段階では昇順[1, 3, 9...]
    vector<int> vec; 
    vec.push_back(1); // append
    for (int i = 1;;) {
        i = i * 6;
        if (i > N) {
            break;
        }
        vec.push_back(i); // append
    }
    
    // 幅リストのサイズ
    int s = vec.size();
    printf("%d\n", s);
    
    int cnt = 0;
    // 降順に評価
    
    for (int i = s - 1;i >= 0;i--) {
        if (i < s - 1) {
            printf(" ");
        }
        printf("%d", vec[i]);
        cnt += insertionSort(A, N, vec[i]);
    }
    printf("\n");
    return cnt;
}

int main() {
    int N;
    scanf("%d", &N);
    
    int A[MAX];
    for (int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }
    
    //insertionSort(A, N, 1);
    int cnt = shellSort(A, N);
    printf("%d\n", cnt);
    for (int i = 0; i < N; i++) {
        printf("%d\n", A[i]);
    }
     
    return 0;
}



Measured memory_bytes: 7164
/* 模範解答 */
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using st = string;
using P = pair<int, int>;
#define mrep(i, m, n) for(int i = m; i < n; i++)
#define rep(i, n) mrep(i, 0, n)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

const int A = 1e6 + 5;

/*int gcd(int x, int y) {
    if(y == 0){
        return x;
    }
    return gcd(y, x % y);
}*/

/*int gcd(int x, int y) {
    int g;
    vector<int> x_list;
    vector<int> y_list;
    int cnt = 1;
    while(x > cnt){
        if(x % cnt == 0) x_list.push_back(cnt);
        cnt++;
    }
    cnt = 1;
    while(y > cnt){
        if(y % cnt == 0) y_list.push_back(cnt);
        cnt++;
    }
    vector<int> gcd_list;
    int szx = x_list.size();
    int szy = y_list.size();
    rep(i, szx){
        rep(j, szy){
            if(x_list.at(i) == y_list.at(j)) gcd_list.push_back(x_list.at(i));
        }
    }
    int n = gcd_list.size() - 1;
    g = gcd_list.at(n);  
    return g;
}*/

const st pc = "pairwise coprime";
const st sc = "setwise coprime";
const st nc = "not coprime";

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> c(A);
    rep(i, n){
        cin >> a.at(i);
        c.at(a.at(i))++;
    }
    bool pairwise = true;
    mrep(i, 2, A){
        int cnt = 0;
        for(int j = i; j < A; j += i){
            cnt += c.at(j); // iの倍数が何個あるかを調べる
        }
        if(cnt > 1) pairwise = false; // 2個以上あったらpairwiseではない
    }
    if(pairwise){
        cout << pc << endl;
        return 0;
    }
    int g = 0;
    rep(i, n) g = gcd(g, a.at(i));
    if(g == 1){
        cout << sc << endl;
        return 0;
    }
    cout << nc << endl;
    return 0;
}

Measured memory_bytes: 11060
#include <iostream>
#include <stack>
#include <vector>

using namespace std;

int main(int argc, const char *argv[]) {
  int n;
  cin >> n;
  vector<vector<pair<int, long long>>> tree(n);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    long long w;
    cin >> u >> v >> w;
    u--;
    v--;
    tree[u].push_back({v, w});
    tree[v].push_back({u, w});
  }

  stack<pair<int, long long>> st;
  vector<long long> results(n, 0);
  vector<bool> visited(n, false);
  st.push({0, 0});
  while (!st.empty()) {
    int node = st.top().first;
    long long d = st.top().second;
    st.pop();
    if (visited[node]) {
      continue;
    }

    results[node] = d;
    visited[node] = true;
    for (auto p : tree[node]) {
      st.push({p.first, p.second + d});
    }
  }

  for (auto r : results) {
    cout << r % 2 << '\n';
  }
  return 0;
}

Measured memory_bytes: 8704
import java.util.*;
public class Main {
	public static void main(String[] args){
		strangeBank();
	}
	
	public static void strangeBank() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		System.out.println(strangeBankhelper(n, 0));
	}
	
	public static int strangeBankhelper(int n, int res) {
		if (n < 6) {
			return n + res;
		}
		int ninetemp = 9;
		while (n - ninetemp >= 0) {
			ninetemp *= 9;
		}
		ninetemp /= 9;
		int sixtemp = 6;
		while (n - sixtemp >= 0) {
			sixtemp *= 6;
		}
		sixtemp /= 6;
		return Math.min(strangeBankhelper(n-sixtemp, res+1), strangeBankhelper(n-ninetemp, res+1));
	}
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<char> vc;
typedef vector<string> vs;
const ll mod = 1e9+7;
const ll inf = 1e17;
const int INF = 1e9;
const double PI = acos(-1);
#define fo(i, a, b) for(int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(s) s.begin(), s.end()
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
int main()
{
  int k, s;
  cin >> k >> s;

  int cnt = 0;
  re(i, k+1) {
    re(j, k+1) {
      if(i + j >= s - k && i + j <= s) cnt++;
    }
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

const long INF = 1e9 + 1;

int main() {
  int n,m,X,Y,x[200],y[200];
  cin >> n >> m >> X >> Y;
  for(int i = 0; i < n; i++)
    cin >> x[i];
  for(int i = 0; i < m; i++)
    cin >> y[i];
  
  sort(x,x+n); sort(y,y+m);

  if(x[n-1] < y[0] & X < y[0] & x[n-1] < Y)
    cout << "No War" << endl;
  else 
    cout << "War" << endl;
}

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

using namespace std;

int main(){
	long long k;
	cin >> k;
    vector<long long> a(50, 49);
    long long x = (k + 50) / 50, y = (k % 50);
    for(int i = 0; i < 50; i++){
        a[i] += x;
        if(i >= y) a[i] -= y + 1;
    }
	cout << 50 << endl;
    for(int i = 0; i < 49; i++){
        cout << a[i] << " ";
    }
    cout << a[49] << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <iostream>
#include <list>
#include <functional>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
typedef long long ll;
const ll mll = 9223372036854775807;
const int mint = (2 << 31) - 1;
using namespace std;
vector<ll> v;
int gcd(int m, int n)
{
	return (m == 0) ? n : gcd(n%m, m);
}
int main()
{
	int n;
	ll t;
	scanf("%d", &n);
	ll m = 1;
	ll nt = 0;
	for (int i = 0; i < n; i++)
	{
		scanf("%lld", &t);
		v.push_back(t);
		nt += t - 1;
	}
	printf("%lld\n", nt);
}

Measured memory_bytes: 256
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    a = [0] * n
    a[0] = 0
    for i, hi in enumerate(h[1:], 1):
        s = max(0, i - k)
        a[i] = min(aj + abs(hi - hj) for hj, aj in zip(h[s:i], a[s:i]))
    print(a[-1])

if __name__ == '__main__':
    main()


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

#define ll long long
#define all(x) (x).begin(), (x).end()

// ----- Tools ----- //
template <typename Key, typename Value, typename Arg>
bool containsKey(const unordered_map<Key, Value>& m, const Arg& value) {return m.find(value) != m.end();}
template <typename Key, typename Value, typename Arg>
bool containsKey_tm(const map<Key, Value>& m, const Arg& value) {return m.find(value) != m.end();}
bool startsWith(string str, string tar) {return (str.rfind(tar, 0) == 0);}
bool contains(string str, string tar) {return (str.find(tar) != std::string::npos);}
vector<string> split(string str, char ch) {vector<string> res; stringstream ss(str); string s; while (getline(ss, s, ch)) res.push_back(s); return res; }
char toLower(char& ch) {if ('A' <= ch && ch <= 'Z') return ch - 'A' + 'a'; else return ch;}
char toUpper(char& ch) {if ('a' <= ch && ch <= 'z') return ch - 'a' + 'A'; else return ch;}

// -------- Main Code -------- //

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

void runcase() {
    ll X, K, D;
    cin >> X >> K >> D;
    ll to_mv = fabs(X);
    ll need_step_a = to_mv / D;
    ll need_step_b = need_step_a + 1;

    ll res;
    
    if (K < need_step_a) {
        res = fabs(to_mv - K * D);
    } else {
        ll left = K - need_step_a;
        ll a = fabs(to_mv - need_step_a * D);
        ll b = fabs(to_mv - need_step_b * D);
        
        left %= 2;

        if (left == 0) {
            res = a;
        } else {
            res = b;
        }

        // if (left % 2 == 0) {
        //     if (left == 0) {
        //         res = a;
        //     } else {
        //         res = min(a, b);
        //     }
        // } else {
        //     res = min(a, b);
        // }
    }

    cout << res << '\n';
}

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

    // int t;
    // cin >> t;
    // while (t-- > 0)
        runcase();

    return 0;
}


Measured memory_bytes: 3612
n=gets.to_i
a=gets.split.map(&:to_i)
b=gets.split.map(&:to_i)
aa,bb=0,0
n.times do |i|
  if a[i]<b[i]
    bb+=1 if (b[i]-a[i]).odd?
    aa+=(b[i]-a[i]+1)/2
  else
    bb+=a[i]-b[i]
  end
end
if aa>=bb
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 3836
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define SP << " " <<
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

#define int long long
int MOD = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  int ans = K;
  vector<vector<int>> graph(N, vector<int>());
  REP(i, N - 1) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  queue<int> Q;
  vector<bool> used(N, false);
  Q.push(0);
  while(Q.size()) {
    int v = Q.front();
    Q.pop();
    if(used[v]) { continue; }
    int i = graph[v].size();
    for(auto x : graph[v]) {
      if(i <= 0) { ans = 0; }
      if(used[x]) { continue; }
      ans = ans * (K - i) % MOD;
      i--;
      Q.push(x);
    }
    used[v] = true;
  }
  cout << ans << endl;
}

Measured memory_bytes: 7412
# -*- coding: utf-8 -*-
# 整数の入力
# a = int(input())
# スペース区切りの整数の入力
# b, c = map(int, input().split())
# 文字列の入力
# s = input()
# 出力
# print("{} {}".format(a+b+c, s))
import sys
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
    if A[i] == 0:
        print(0)
        sys.exit(0)
answer = 1
for i in range(N):
    answer *= A[i]
    if answer > 1000000000000000000:
       print(-1)
       sys.exit(0)

print(answer)


Measured memory_bytes: 21720
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int x1 = scan.nextInt();
        int y1 = scan.nextInt();
        int x = scan.nextInt();
        int y = scan.nextInt();
        int dx = x - x1;
        int dy = y - y1;
        int[] answer = new int[4];
        for (int i = 0; i < 2; i++) {
            x = x - dy;
            y = y + dx;
            int dx_bck = dx;
            dx = -dy;
            dy = dx_bck;
            answer[2*i] = x;
            answer[2*i + 1] = y;
        }
        System.out.printf("%d %d %d %d\n",answer[0],answer[1],answer[2],answer[3]);
    }
}


Measured memory_bytes: 23380
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <algorithm>
#define INF 0x3f3f3f3f
using namespace std;

//firstにh、secondにwを入れる
typedef pair<int, int> PII;

//S、1...Nまでの座標を格納する
PII cheese[10];

const int MAX_H = 1010, MAX_W = 1010;
int H, W, N;
char field[MAX_H][MAX_W];
int d[MAX_H][MAX_W];

int dh[] = {1, 0, -1, 0};
int dw[] = {0, 1, 0, -1};

bool infield(int h, int w){
    return (0<=h && h<H && 0<=w && w<W);
}

//sからgまでの最短手数を返す
int bfs(PII s, PII g){
    queue<PII> que;
    //infで初期化
    memset(d, 0x3f, sizeof(d));
    que.push(s);
    d[s.first][s.second] = 0;
    
    while(!que.empty()){
        PII p = que.front(); que.pop();
        if(p == g)
            break;
        for(int i=0; i<4; i++){
            int nh = p.first+dh[i];
            int nw = p.second+dw[i];
            
            if(infield(nh, nw) && field[nh][nw]!='X' && d[nh][nw]==INF){
                que.push(PII(nh, nw));
                d[nh][nw] = d[p.first][p.second] + 1;
            }
        }
    }
    
    return d[g.first][g.second];
}

void solve(){
    int ans = 0;
    
    //cheeseリストを作る
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(field[i][j] == 'S')
                cheese[0] = PII(i, j);
            
            for(char c='1'; c<='9'; c++){
                if(field[i][j] == c)
                    cheese[c-'0'] = PII(i, j);
            }
        }
    }
    for(int i=0; i<N; i++)
        ans += bfs(cheese[i], cheese[i+1]);
    printf("%d\n", ans);
}

int main(){
    scanf("%d%d%d", &H, &W, &N);
    for(int i=0; i<H; i++)
        scanf("%s", field[i]);
    solve();
    return 0;
}

Measured memory_bytes: 6032
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <utility>

typedef long long ll;
using namespace std;

int main(){
  ll n,k,i,j;
  cin >> n >> k;
  vector<pair<ll,ll> > v(n);
  for(i=0;i<n;i++){
    pair<ll,ll> p;
    cin >> p.second >> p.first;
    v[i]=p;
  }
  sort(v.begin(),v.end());
  reverse(v.begin(),v.end());
  vector<bool> ch(n+1,0);
  priority_queue<pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> > >  que;
  ll cnt=0,ret=0,sum=0;
  for(i=0;i<k;i++){
    if(ch[v[i].second]==0){
      cnt++;
      ch[v[i].second]=true;
    }
    else que.push(v[i]);
    sum+=v[i].first;
  }
  ret = sum+cnt*cnt;
  for(i=k;i<n;i++){
    if(que.empty())break;
    if(ch[v[i].second]==0){
      cnt++;
      ch[v[i].second]=true;
      sum+=v[i].first;
      sum-=que.top().first;
      if(ret<sum+cnt*cnt){
        ret=sum+cnt*cnt;
        que.pop();
      }
    }
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 2940
l,r = map(int,input().split())
p = 2019
if r - l >= 2019:
    for i in range(l,l+2019):
        for j in range(i+1,l+2020):
            p = min(p,i*j%2019)
            if p == 0:
                print(0)
                exit(0)
else:
    for i in range(l,r):
        for j in range(i+1,r+1):
            p = min(p,i*j%2019)
            if p == 0:
                print(0)
                exit(0)
print(p)

Measured memory_bytes: 8992
#include <bits/stdc++.h>
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>

#define fr(i,b,e) for(int i=(b); i!=(e); ++i)
#define rp(i,e) for(int i=0; i!=(e); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long int li;
typedef long long ll;
const int INF=1000000;
const int MOD=998244353;


int main(void){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,x,y;
    cin >> n >> x >> y;
    vector<int> count(n+1,0);
    fr(i,1,n+1){
        fr(j,i+1,n+1){
            ++count.at( min( {abs(j-i) , abs(x-i)+1+abs(j-y) , abs(y-i)+1+abs(j-x)} ) );
        }
    }
    fr(i,1,n) cout << count.at(i) << "\n";
}   

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
	"sort"
)

func main() {
	n, w := scInt2()
	wlist, vlist := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		wlist[i], vlist[i] = scInt2()
	}

	// DPテーブルの初期化
	// dp[i][sumW] := i-1 番目までの品物から重さが sumW を
	// 超えないように選んだときの、価値の総和の最大値
	dp := make([][]int, n+1)
	for i := 0; i < n+1; i++ {
		// 重さの範囲内でテーブルを作る
		dp[i] = make([]int, w+1)
	}

	for i := 0; i < n; i++ {
		// i番目の商品の重さごとの価値を確認する
		for sumW := 0; sumW < w+1; sumW++ {
			// i番目の商品を選択できる場合
			if sumW-wlist[i] >= 0 {
				// i番目の商品を選択する場合
				nv := dp[i][sumW-wlist[i]] + vlist[i]
				dp[i+1][sumW] = max(dp[i+1][sumW], nv)
			}
			dp[i+1][sumW] = max(dp[i+1][sumW], dp[i][sumW])
		}
	}
	fmt.Println(dp[n][w])
}

func scStr() string {
	var s string
	fmt.Scan(&s)
	return s
}

func scInt() int {
	var x int
	fmt.Scan(&x)
	return x
}

func scInt2() (int, int) {
	var x, y int
	fmt.Scan(&x, &y)
	return x, y
}

func scInt3() (int, int, int) {
	var x, y, z int
	fmt.Scan(&x, &y, &z)
	return x, y, z
}

func scInts(n int) (slice []int) {
	slice = make([]int, n)
	for i := range slice {
		fmt.Scan(&slice[i])
	}
	return slice
}

func hw(h int, w int, init int) [][]int {
	hw := make([][]int, h)
	for i := 0; i < h; i++ {
		hw[i] = make([]int, w)
		for j := 0; j < w; j++ {
			hw[i][j] = init
		}
	}
	return hw
}

func sum(slice []int) (sum int) {
	sum = 0
	for i := range slice {
		sum += slice[i]
	}
	return
}

func uniqueInts(ints []int) (unique []int) {
	m := map[int]bool{}
	for _, v := range ints {
		if !m[v] {
			m[v] = true
			unique = append(unique, v)
		}
	}
	return unique
}

func uniqueStrs(strs []string) (unique []string) {
	m := map[string]bool{}
	for _, v := range strs {
		if !m[v] {
			m[v] = true
			unique = append(unique, v)
		}
	}
	return unique
}

func min(x, y int) int {
	if x > y {
		return y
	}
	return x
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func minInts(ints []int) int {
	sort.Ints(ints)
	return ints[0]
}

func maxInts(ints []int) int {
	sort.Ints(ints)
	n := len(ints)
	return ints[n-1]
}

func powi(x, pow int) int {
	return int(math.Pow(float64(x), float64(pow)))
}


Measured memory_bytes: 83076
#include <bits/stdc++.h>
using namespace std;
int main() {
    string S; cin >> S;
    bool ok = true;
    for (int i = 0; i < S.size(); i++) {
        if (i % 2 == 0) {
            if (S[i] == 'L') ok = false;
        } else {
            if (S[i] == 'R') ok = false;
        }
    }
    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256