akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

// aのn乗を求める。計算量はO(logn)
ll modpow(ll a, ll n) {
    if(n == 0) {
        return 1;
    }
    if(n%2 == 1) {
        return (a * modpow(a, n-1))%mod;
    }
    return (modpow(a, n/2) * modpow(a, n/2))%mod;
}

ll inverse(ll a) {
    return modpow(a, mod-2);
}

ll inv[MAX_N];  // inv[i] : iの逆数のmod
ll fact[MAX_N];  // fact[i] : iの階乗のmod
ll invfact[MAX_N];

void init() {
    inv[0] = fact[0] = invfact[0] = 1;
    inv[1] = 1;
    for(ll i = 1; i < MAX_N; i++) {
        if(i >= 2) {
            inv[i] = mod - inv[mod%i]*(mod/i)%mod;
        }
        fact[i] = (i * fact[i-1])%mod;
        invfact[i] = inverse(fact[i]);
    }
}

//--- main関数でinit()を呼び出すのを忘れるな ---//
int main() {
    ll n, m;
    cin >> n >> m;

    init();

    if(abs(n-m) > 1) {
        out(0);
    }
    else if(n == m) {
        ll ans = (2*fact[n]*fact[m])%mod;
        out(ans);
    }
    else {
        ll ans = (fact[n]*fact[m])%mod;
        out(ans);
    }

    re0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch GatheringChildren | diff GatheringChildren.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address GatheringChildren.cpp && ./a.out

/*
 
 8/6/2019
 
 12:02-
 
 */

//const int MAX_N=1e6+1;
string S;
int N;

void solve() {
  N=SZ(S);
  vector<LL> res(N,0);
  REP(i,N-1) if(S[i]=='R'&&S[i+1]=='L') {
    LL l=0,r=0;
    for(int j=i; j>=0&&S[j]=='R'; --j) ++l;
    for(int j=i+1; j<N&&S[j]=='L'; ++j) ++r;
    LL a=(l+r)/2,b=l+r-a;
    res[i]=a,res[i+1]=b;
    if(a<b) {
      if(l>r&&(l-1)%2==0) swap(res[i],res[i+1]);
      else if(l<r&&(r-1)%2==1) swap(res[i],res[i+1]);
    }
  }
  REP(i,N) printf("%lld ", res[i]);
  println("");
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>S;
  solve();
  
  return 0;
}


Measured memory_bytes: 1488
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

vector<P> graph[100001];
vector<bool> used(100001);
vector<int> color(100001);
bool flag = true;

void dfs(int p, int c) {
  if (color[p] == 0) {
    color[p] = c;
  } else if (color[p] != c) {
    flag = false;
    return;
  }
  for(auto e: graph[p]) {
    int to = e.first;
    int num = e.second;
    if (!used[num]) {
      used[num] = true;
      dfs(to, -c);
    }
  }
}

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

  ll n, m; cin >> n >> m;
  rep(i, m) {
    int a, b; cin >> a >> b;
    graph[a].emplace_back(b,i);
    graph[b].emplace_back(a,i);
  }
  dfs(1, 1);
  if (!flag) {
    auto tmp = n*(n-1)/2;
    cout << tmp - m << endl;
  } else {
    ll red = 0, blue = 0;
    for(int i=1; i<=n; i++) {
      if (color[i] == 1) {
        red++;
      } else {
        blue++;
      }
    }
    auto tmp = red*blue;
    cout << tmp - m << endl;
  }
}


Measured memory_bytes: 11648
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i < n; i++)
typedef long long ll;
// Welcome to my source code!

int main() {
    int n;
    string com, str;
    map<string, bool> D;
    cin >> n;
    REP(i,n) {
        cin >> com >> str;
        if (com == "insert") D[string(str)] = true;
        else {
            if (D[string(str)]) cout << "yes" << endl;
            else cout << "no" << endl;
        }
    }
}


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

int func(int x){
  int sum=0;
  while(x>0){
    sum+=x%10;
    x/=10;
  }
  return sum;
}

int main(){
  int N, A, B, c;
  int ans=0;
  cin >> N >> A >> B;
  for (int i=1; i<=N; i++){
    c=func(i);
    if (c<=B && A<=c){
      ans+=i;
    }
  }
  cout << ans << endl;
}
  

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

struct UnionFind{
	vector<int> par;
	int sz;
	
	UnionFind(int N) : par(N) , sz(N) {
		for(int i=0;i<N;i++) par[i]=i;
	}
	
	int root(int x){
		if(par[x]==x) return x;
		else{
			return par[x]=root(par[x]); //ここは同時に経路圧縮もやってるらしい
		}
	}
	
	void unite(int x,int y){
		int rx=root(x);
		int ry=root(y);
		if(rx==ry) return;
		else { par[rx]=ry; sz--; }
	}
	
	bool same(int x,int y){
		int rx=root(x);
		int ry=root(y);
		return rx==ry;
	}
	
	int size() { return sz; }
};

int main(){
	UnionFind uf(13);
	uf.unite(1,3);
	uf.unite(3,5);
	uf.unite(5,7);
	uf.unite(7,8);
	uf.unite(8,10);
	uf.unite(10,12);
	uf.unite(4,6);
	uf.unite(6,9);
	uf.unite(9,11);
	
	int x,y;
	cin >> x>>y;
	cout<<(uf.same(x,y) ? "Yes":"No")<<endl;
}



Measured memory_bytes: 256
n = int(input())

t, a = map(int,input().split())
vote1 = t
vote2 = a

for i in range(n - 1):
    t, a = map(int,input().split())

    num1 = (vote1 + t - 1) // t
    num2 = (vote2 + a - 1) // a

    if num1 >= num2:
        vote1 = num1 * t
        vote2 = num1 * a
    else:
        vote1 = num2 * t
        vote2 = num2 * a

print(vote1 + vote2)


Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define INF 1000000007
#define fi first
#define se second

using namespace std;

typedef pair<int,int>P;
typedef pair<P,int>pi;

struct edge
{
    int to,dist;
};

int dp[6001][2001];
bool ok[6001];
vector<edge> G[6001];
map<string,int> mp;
int id,n,m,cap,s,g;

void Dijkstra()
{
    rep(i,id){
        rep(j,cap+1){
            dp[i][j] = INF;
        }
    }
    priority_queue<pi,vector<pi>,greater<pi> > que;
    dp[s][cap] = 0;
    que.push(pi(P(0,s),cap));
    while(!que.empty()){
        auto pp = que.top();
        que.pop();
        P p = pp.fi;
        int q = pp.se;
        if(dp[p.se][q] < p.fi) continue;
        if(p.se == g){
            cout << p.fi << "\n";
            return;
        }
        for(auto& e : G[p.se]){
            if(q >= e.dist){
                int nx = q-e.dist;
                if(ok[e.to]) nx = cap;
                if(dp[e.to][nx] > p.fi+e.dist){
                    dp[e.to][nx] = p.fi+e.dist;
                    que.push(pi(P(dp[e.to][nx],e.to),nx));
                }
            }
        }
    }
    cout << "-1\n";
}


int main()
{
    while(1){
        cin >> n >> m >> cap;
        if(n == 0){
            break;
        }
        cap *= 10;
        mp.clear();
        id = 0;
        string p,q;
        cin >> p >> q;
        if(mp.find(p) == mp.end()){
            mp[p] = id++;
        }
        if(mp.find(q) == mp.end()){
            mp[q] = id++;
        }
        s = mp[p], g = mp[q];
        rep(i,6001){
            G[i].clear();
        }
        rep(i,n){
            string x,y;
            int z;
            cin >> x >> y >> z;
            if(mp.find(x) == mp.end()){
                mp[x] = id++;
            }
            if(mp.find(y) == mp.end()){
                mp[y] = id++;
            }
            G[mp[x]].push_back((edge){mp[y],z});
            G[mp[y]].push_back((edge){mp[x],z});
        }
        rep(i,id){
            ok[i] = false;
        }
        rep(i,m){
            string s;
            cin >> s;
            ok[mp[s]] = true;
        }
        Dijkstra();
    }
}



Measured memory_bytes: 75468
import math


all = list(map(int, input().split()))
A = all[0]
B = all[1]
H = all[2]
M = all[3]

short_time = H*0.5*60 + M*0.5
long_time = M*6
degree = abs(short_time-long_time)

x = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(math.radians(degree)))

print(x)

Measured memory_bytes: 9508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = 100 * 1000 + 7;
char s[MAXN];
int main()
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
#endif
	scanf("%s", s);
	int k;
	scanf("%d", &k);
	int n = strlen(s);
	for (int i = 0; i < n - 1; i++)
	{
		int x = s[i] - 'a';
		int need = 26 - x;
		if (need == 26) need = 0;
		if (k >= need)
		{
			s[i] = 'a';
			k -= need;
		}
	}
	int xx = s[n - 1] - 'a';
	xx = (xx + k) % 26;
	s[n - 1] = 'a' + xx;
	printf("%s\n", s);
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int S;
	bool upperMM = false;
	bool lowerMM = false;

	cin >> S;

	if (1 <= S / 100 && S / 100 <= 12) upperMM = true;
	if (1 <= S % 100 && S % 100 <= 12) lowerMM = true;

	if (upperMM && lowerMM) cout << "AMBIGUOUS" << endl;
	else if (upperMM) cout << "MMYY" << endl;
	else if (lowerMM) cout << "YYMM" << endl;
	else cout << "NA" << endl;

	return 0;
}

Measured memory_bytes: 256
n = int(input())
tasks = []
for i in range(n):
    task = []
    a, b = map(int, input().split())
    task.append(b)
    task.append(a)
    tasks.append(task)
tasks.sort()
time = 0
for i in range(n):
    time += tasks[i][1]
    if time > tasks[i][0]:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 38800
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9;
using namespace std;
using ll = long long;
vector <int> x(10000);
int main() {
    int n , a = 0;
    cin >> n;
    for(int i = 1; i <= 99; i++){
        for (int j = 1; j <= 99; ++j) {
            for (int k = 1; k <= 99; ++k) {
                if(i * i + j * j + k * k + i * j + i * k + j * k <= n){
                    x[i * i + j * j + k * k + i * j + i * k + j * k - 1]++;
                }
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        cout << x[i] << endl;
    }
}

Measured memory_bytes: 3636
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

//Code Short
#define REP(i,n) for(int i = 0;i < n;++i)
#define PB(s) push_back(s)
#define DSORT(n) sort(n.begin(),n.end())
#define QECHO(n) cout << n
#define QECHOS(n) cout << n << " "

//Define Math
const double EPS = 1e-10;
const double PI  = acos(-1.0);

using namespace std;
typedef long long ll;
/* prototype */
int EDSum(ll);//各桁の和
vector<int> SOE(int,int);//素数 (Min,Max)
int MinCM(int,int);//最小公倍数(num1,num2)
int MaxCD(int,int);//最大公約数(num1,num2)
vector<int> igets(int);//cin * N
ll nPr(ll,ll); //(n,r)
ll nE(ll); //(n)
ll nCr(ll,ll); //(n,r)

void solve(){
    //START
    int a;
    cin >> a;
    if(a<1200)cout << "ABC" << endl;
    else if(a<2800)cout << "ARC" << endl;
    else cout << "AGC" << endl;
}

int main(void){cin.tie(0);ios::sync_with_stdio(false);solve();}
int EDSum(ll number) {
  int ans = 0;
  while (1) {
    ans += number % 10;
    number /= 10;
    if (number == 0) break;
  }
  return ans;
}

vector < int > SOE(int min, int max) {
  if (min < 2) min = 2;
  vector < int > int_array;
  for (int i = min; i <= max; i++) int_array.push_back(i);
  vector < int > sosu;
  double stop = sqrt(max);
  while (true) {
    sosu.push_back(int_array.front());
    int_array.erase(int_array.begin());
    if (stop < (double)(sosu.back())) break;
    for (int i = 0; i < (int) int_array.size(); i++) {
      if (int_array[i] % sosu.back() == 0)
        int_array.erase(int_array.begin() + i);
    }
  }
  sosu.insert(sosu.end(), int_array.begin(), int_array.end());
  return sosu;
}

int MinCM(int a, int b) {
  int c = a * b;
  if (a < b)
    swap(a, b);
  int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return c / b;
}

int MaxCD(int a, int b) {
  if (a < b)
    swap(a, b);
  int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
vector < int > igets(int N) {
  vector < int > A;
  int temp;
  for (int i = 0; i < N; ++i) {
    cin >> temp;
    A.push_back(temp);
  }
  return A;
}

ll nPr(ll n, ll r) {
  ll ans = 1;
  r = n - r;
  while (n != r) {
    ans *= n;
    --n;
  }
  return ans;
}

ll nE(ll n) {
  return nPr(n, n);
}

ll nCr(ll n, ll r) {
  if (r == 0) return -1;
  else {
    if (0 != n - r && n - r < r) r = n - r;
    return nPr(n, r) / nE(r);
  }
}

Measured memory_bytes: 256
/*
CF ID: Ankit717
LANG: C++
*/
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define mod 1000000007
#define maxn 100005
#define f(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rf(i,a,b) for(ll i=(ll)(a);i>=(ll)(b);i--)
#define pb push_back
#define pf push_front
#define nl cout << "\n";

const ll INF=1e18L+5;
 
struct Data{
	ll p;
	ll h;
};

void ini(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
}

bool comp(pll &a,pll &b){
	// if(a.first==b.first){
	// 	return a.second<b.second;
	// }else{
		return a.first>b.first;
	//}
}

// vector<pll> adj[maxn];
// vector<ll> par;
// vector<bool> vis;

ll gcd(ll a,ll b){
    while(a!=0){
        ll temp=a;
        a = b % a;
        b = temp;
    }

    return b;
}

// bool prime[maxn],near[maxn];
// void sieve(){
// 	f(i,0,maxn+1){
// 		prime[i]=true;
// 	}
// 	prime[0]=falsrime[1]=false;
// 	for(ll i=2;i*i<=maxn;i++){
// 		if(prime[i]){
// 			for(j=i*i;j<=maxn;j+=i){
// 				prime[j]=false;
// 			}
// 		}
// 	}
// }

void solve(){
	ll n;
	cin >> n;
	ll l[n];
	f(i,0,n){
		cin >> l[i];
	}
	ll ans=0;
	vector<ll> side;
	f(i,0,n-2){
		f(j,i+1,n-1){
			f(k,j+1,n){
				if(l[i]!=l[j] && l[j]!=l[k] && l[i]!=l[k]){
					side.pb(l[i]);
					side.pb(l[j]);
					side.pb(l[k]);

					//cout << l[i]<<" "<<l[j]<<" "<<l[k];nl;

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

					if(side[0]+side[1]>side[2]){
						ans++;
					}

					side.clear();
				}
			}
		}
	}

	cout << ans;
}

int main(){
	ini();
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	
    
	// ll t;
	// cin >> t;
	// f(i,0,t){
		solve();
	//}
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, b, n) for (int i = b; i < (n); ++i)

using namespace std;

void solve(int H, int W, vector<string> S) {
  // store horizontal connected cells
  vector<vector<int>> horiz(H, vector<int>(W, 0));
  REP(h, H) {
    REP(w, W) {
      // find obstacle
      const auto obs = S[h].find('#', w);
      const int end = (obs == string::npos ? W : (int)obs);
      // store num of connection
      FOR (i, w, end)
	horiz[h][i] = end - w;
      w = end;
    }
  }

  // store vertical connected cells
  vector<vector<int>> verti(H, vector<int>(W, 0));
  REP(w, W) {
    REP(h, H) {
      // find obstacle
      int end = h - 1;
      FOR(i, h, H) {
	if (S[i][w] != '#')
	  continue;
	end = i;
	break;
      }
      if (end == h - 1)
	end = H;
      // store num of connection
      FOR (i, h, end)
	verti[i][w] = end - h;
      h = end;
    }
  }

  int ans = 0;
  REP(h, H) {
    REP(w, W) {
      // skip obstalce cell
      if (S[h][w] == '#')
	continue;
      // count lighted cells (decrese itself which is coutned twice)
      int num_lighted_cells = -1;
      // vertical cells
      num_lighted_cells += verti[h][w];
      // horizontal cells
      num_lighted_cells += horiz[h][w];

      ans = max(ans, num_lighted_cells);
    }
  }
  cout << ans << endl;
}

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

  int H, W;
  cin >> H >> W;

  vector<string> S(H);
  for(int i = 0 ; i < H ; i++)
    cin >> S[i];

  solve(H, W, move(S));
  return 0;
}


Measured memory_bytes: 35968
#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    ll a[100002], b[100002];
    ll sum = 0;
    for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
    for(int i = n - 1; i >= 0; i--){
        sum += (b[i] - (a[i] + sum) % b[i]) % b[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	int N;long K; cin>>N>>K;
	int a,b; int cnt[N] = {};
	rep(i,0,N-1){
		cin>>a>>b;
		cnt[a-1]++; cnt[b-1]++;
	}
	long fact[K]; fact[1] = 1;
	rep(i,2,K) fact[i] = (fact[i-1] * (K-i)) % mod;
    if(N == 1){ cout<<K<<endl; return 0; }
	long ans = (K * (K - 1)) % mod;
	rep(i,0,N){
		if(K <= cnt[i]) ans = 0;
		else if(1 < cnt[i]) (ans *= fact[cnt[i]]) %= mod;
	}cout<<ans<<endl;
}

Measured memory_bytes: 1536
#define _CRT_NO_SECURE_WARNINGS
#pragma warning(disable:4996)
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <string>
#include <iomanip>
#include <set>
#include <random>
#include <queue>
#include <map>
#include <ctime>
#include <sstream>
#include <cstdlib>
using namespace std;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using namespace std; int INF = 1e6; typedef long long ll; typedef double d; typedef unsigned long long ull;

void solve() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	//int counter = 1;
	while (1) {
		c -= b;
		if (c <= 0) {
			cout << "Yes" << endl;
			return;
		}
		a -= d;
		if (a <= 0) {
			cout << "No" << endl;
			return;
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	solve();
	return 0;
}

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

int main(void){
    ll n;
    cin >> n;
    
    vector<ll> prime(n+1,2);
    ll ans = 0;
    for(ll i = 2;i <= n;i++){
        //prime[i]++;
        //ans += (prime[i])*i;
        //if(prime[i] <= 2){
            for(ll j = 2*i;j <= n;j+=i){
                //if(j == 12)cout << "a";
                prime[j]++;
            }
        //}
    }
    for(int i = 1;i <= n;i++){
        ans += (prime[i])*i;
        //cout << prime[i] << endl;
    }
    cout << ans-1;
}

Measured memory_bytes: 81372
program sample
    implicit none
  
    integer(8) :: i,j,m,n,a,b,c,k
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) a,b,c
    read(*,*)k
    do i=1,k
        if(a>=b)then
            b=b*2
            cycle
        else if(b>=c)then
            c=c*2
            cycle
        end if
    end do
    if(a<b .and. b<c)then
        write(*,*)'Yes'
    else
        write(*,*)'No'
    end if
  
    stop
end program sample
  



Measured memory_bytes: 2860
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int N;
  cin >> N;
  vector <int> p(N);
  rep(i,N) cin >> p[i];

  vector <int> sorted(N);
  sorted = p;
  sort(all(sorted));

  int ans = 0;  //昇順になっていないp_iの個数
  rep(i,N){
    if (p[i] != i + 1){
      ans ++;
    }
  }
  if (ans == 0 || ans == 2){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }

}


Measured memory_bytes: 3632
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> ump;
typedef pair<ll, ll> P;

ump mp;
struct edge {
    ll u, v;
};
vector<edge> g;
ll n, m;

class UnionFind {
public:
    vector<ll> par; // 親
    vector<ll> rank; // 木の深さ
    vector<ll> _size;

    explicit UnionFind(unsigned int n) {
        par.resize(n);
        rank.resize(n);
        _size.resize(n);
        rep(i, n) {
            par[i] = i;
            rank[i] = 0;
            _size[i] = 1;
        }
    }

    // 木の根を求める
    ll find(ll x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    }

    ll size(ll x) {
        return _size[find(x)];
    }

    // xとyの属する集合を併合
    void unite(ll x, ll y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (rank[x] < rank[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if (rank[x] == rank[y]) rank[x]++;
        }
        _size[x] = _size[y] = _size[x] + _size[y];
    }

    // xとyが同じ集合に属するか否か
    bool is_same(ll x, ll y) {
        return find(x) == find(y);
    }
};


void solve() {
    ll ans[m];
    rep(i, m) ans[i] = n * (n - 1) / 2;
    UnionFind tree = UnionFind(n);
    for (int i = m - 2; i >= 0; --i) {
        ll a = g[i + 1].u, b = g[i + 1].v;
        if (tree.is_same(a, b)) {
            ans[i] = ans[i + 1];
        } else {
            ans[i] = ans[i + 1] - tree.size(a) * tree.size(b);
            tree.unite(a, b);
        }
    }
    rep(i, m) cout << ans[i] << endl;
}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif
        cin >> n >> m;
        g.resize(m);
        rep(i, m) {
            ll a, b;
            cin >> a >> b;
            a--, b--;
            edge e = {a, b};
            g[i] = e;
        }

        solve();

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 6016
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que)  priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
const int MOD = 1e9+7;

int main(){
 int n; cin>>n;
 int s[n];
 int min_s=100;
 int sum=0; 
 REP(i,n){
   cin>>s[i];
   if(s[i]%10!=0&&s[i]<=min_s)min_s=s[i];
   sum+=s[i];
 }
  if(sum%10!=0)cout<<sum<<endl;
  else if(min_s==100)cout<<0<<endl;
   else cout<<sum-min_s<<endl;
}

Measured memory_bytes: 256
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
result, index = 0, 1
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    if v > 0:
        if result < data[a-1]:
            result, index = data[a-1], a
        elif result == data[a-1]:
            index = min(index, a)
    else:
        if index == a:
            result = max(data)
            index = data.index(result) + 1
    print(index, result)

Measured memory_bytes: 15352
#include <iostream>
typedef long long LL;
using namespace std;

int main(){
    LL w;
    LL h;
    LL x;
    LL y;
    double ans1;
    int ans2 = 0;

    cin >> w >> h >> x >> y;
    ans1 = double(w*h)/2.0;
    if((2*x==w) && (2*y==h)){
        ans2 = 1;
    }
    cout << ans1 << " " << ans2 << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

def solve():
    N, A, B, C, D = map(int, raw_input().split()) 
    A, B = 0, B - A
    if B < 0: B *= -1
    M = N - 1

    for i in xrange(N):
        if C*(M - i) - D*i <= B <= D*(M - i) - C*i:
            return True

    return False

print "YES" if solve() else "NO"



Measured memory_bytes: 4392
#include <iostream>

using namespace std;

int main(void)
{
    int W, a, b;
    cin >> W >> a >> b;

    int aw = a + W;
    int bw = b + W;
    int ans = 0;
    if(a < b)
    {
        ans = max(b - aw, 0);
    }
    else if(a >= b)
    {
        ans = max(a - bw, 0);
    }

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

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

int dp[309][309][309];

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

    string s;
    cin >> s;
    int n = s.size(), k;
    cin >> k;

    rep(i, n) dp[i][i + 1][0] = 1;

    for(int sz = 2; sz <= n; sz++)
        for(int l = 0; l + sz <= n; l++) {
            int r = l + sz;
            rep(i, k + 1) {
                if(s[l] == s[r - 1])
                    chmax(dp[l][r][i], dp[l + 1][r - 1][i] + 2);
                if(i) chmax(dp[l][r][i], dp[l + 1][r - 1][i - 1] + 2);
                chmax(dp[l][r][i], dp[l + 1][r][i]);
                chmax(dp[l][r][i], dp[l][r - 1][i]);
            }
        }

    cout << *max_element(ALL(dp[0][n])) << endl;

    return 0;
}

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

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	int h[n], dp[n];
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	dp[0] = 0;
	for (int i = 1; i < n; i++) {
		dp[i] = abs(h[i] - h[i - 1]) + dp[i - 1];
		for (int j = 2; j <= k && i - j >= 0; j++) {
			dp[i] = min(dp[i], abs(h[i] - h[i - j]) + dp[i - j]);
		}
	}
	cout << dp[n - 1] << "\n";
	return 0;
}

Measured memory_bytes: 4404
#include<stdio.h>
#define MAX 100005
#define NIL -1
struct Node_struct{int p, l, r;}; /*p: 親(parent), l: 一番左の子(left child), r:右の兄弟(right sibling)*/
typedef struct Node_struct Node;
Node T[MAX];
int D[MAX];

void print(int u){
  int i, c;
  printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);

  if(T[u].p == NIL) printf("root, ");
  else if(T[u].l == NIL) printf("leaf, ");
  else printf("internal node, ");
  
  printf("[");
  for (i=0, c = T[u].l; c != NIL; i++, c = T[c].r){
    if(i) printf(", ");
    printf("%d", c);
  }
  printf("]\n");
  
}

void calcDepth(int u, int p){
  D[u] = p;
  if(u != NIL) calcDepth(T[u].l,p + 1);
  if(u != NIL) calcDepth(T[u].r,p);
}

int main(){
  int i, j, k;
  int n;
  int id, sib, child;
  int root = NIL;
  scanf("%d", &n);
  for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL;
  
  for(i=0; i<n; i++){
    scanf("%d %d", &id, &k);
    for(j = 0, sib = NIL; j<k; j++){ //子を入力する (input children)
      scanf("%d", &child);
      T[child].p = id;
      if(j == 0) T[id].l = child; //idの一番左の子 (the most left child of id)
      else T[sib].r = child; //左の兄弟に繋げる (connect to left sibling)
      sib = child;//次の子供の左の兄弟 (the left sibling of the next child)
    }
  }

  //根を求める (find the root)
  for(i=0; i<n; i++){
    if(T[i].p == -1) root = i;
  }
  
  //それぞれのノードの深さを求める (find depth of each node)
  calcDepth(root, 0);

  //出力 (output)
  for(i=0; i<n; i++) print(i);
  
  return 0;
}



Measured memory_bytes: 3260
use std::io;

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();

    let mut iter = input.split_whitespace();

    let a: usize= iter.next().unwrap().parse().unwrap();
    let b: usize= iter.next().unwrap().parse().unwrap();
    let c: usize= iter.next().unwrap().parse().unwrap();

    if a + b >= c {
        println!("Yes");
    } else {
        println!("No");
    }

}


Measured memory_bytes: 4352
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <climits>
#include <random>
#include<algorithm>

#define int_max 2147483647;

//AGC 30

void Problem_A(void)
{
    int A ,B ,C;
    std::cin>>A>>B>>C;

    int X;

    if(A+B>=C)
    {
        std::cout<<C+B;
    }
    else{
        std::cout<<A+2*B+1;
    }

    return;

}
int main(int argc, char const *argv[])
{
    Problem_A();

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	char a[100];
	scanf("%s",a);
	if(strlen(a)%2)
	printf("No");
	else
	{
		for(int i=0;a[i]!='\0';i+=2)
		{
			if(a[i]=='h'&&a[i+1]=='i')
			;
			else
			{
				printf("No");
				return 0;
			}
		}
		printf("Yes");
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Rep(i, sta, n) for (int i = sta; i < (n); ++i)
#define all(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
const int mod = 1000000007;

ll dp[101][100100];

int main() {
    int n, W;
    cin >> n >> W;
    vector<int> w(n);
    vector<ll> v(n);

    rep(i,n) cin >> w[i] >> v[i];
    rep(i,n) {
        rep(j, W+1) {
            dp[i+1][j] = dp[i][j];
            if (j-w[i]>=0) dp[i+1][j] = max(dp[i+1][j], dp[i][j-w[i]]+v[i]);
        }
    }
    cout << dp[n][W] << endl;
    return 0;
}


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

using namespace std;


#define PI 3.14159265
#define int long long



main(){

	int n; cin >> n;

	vector <int> a(n);

	int cnt = 0;

	for(int i = 0; i < n; i++){
		cin >> a[i];
		if(a[i] % 2 == 0) cnt++;
	}

	
	for(int i = 0; i < n; i++){
		if(a[i] % 2 == 0 and (a[i] % 3 == 0 or a[i] % 5 == 0)){
			cnt--;
		}
	}
	

	cout << (cnt == 0 ? "APPROVED" : "DENIED") << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <assert.h>
#include <algorithm>
#include <unordered_map>

using cnt_map_type = std::unordered_map<int32_t, int32_t>;
void get_max_second(cnt_map_type& cnt_map, int32_t& max, int32_t& second, int32_t& key){
    for(auto it = cnt_map.begin(); it != cnt_map.end(); it++){
        if(it->second >= max){
            second = max;
            key = it->first;
            max = it->second;
        }
        else{
            second = std::max(second, it->second);
        }
    }
    return;
}

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

    int32_t N;
    std::cin >> N;
    assert(N % 2 == 0);
    cnt_map_type odd_map;
    cnt_map_type even_map;
    for(int32_t i = 0; i < N/2; i++){
        int32_t even;
        int32_t odd;
        std::cin >> even >> odd;
        odd_map[odd]++;
        even_map[even]++;
    }

    int32_t odd_max = 0;
    int32_t odd_key = 0;
    int32_t odd_second = 0;
    int32_t even_max = 0;
    int32_t even_key = 0;
    int32_t even_second = 0;
    get_max_second(odd_map, odd_max, odd_second, odd_key);
    get_max_second(even_map, even_max, even_second, even_key);
    if(odd_key == even_key){
        if(odd_max > even_max){
            std::cout << N - odd_max - even_second << std::endl;
        }
        else if(odd_max < even_max){
            std::cout << N - odd_second - even_max << std::endl;
        }
        else{
            std::cout << N - odd_max - std::max(odd_second, even_second) << std::endl;
        }
    }
    else{
        std::cout << N - odd_max - even_max << std::endl;
    }


    return 0;

}


Measured memory_bytes: 4376
#include <iostream>
using namespace std;
#include<string.h>
#include<set>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include <cstdio>
#include <cstdlib>
#include<stack>
#include<vector>
int main()
{
    int n;
    cin>>n;
    cout<<(int)sqrt(n)*(int)sqrt(n)<<endl;
    return 0;
}


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

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

    int negCnt = 0;
    vector<ll> a(n);
    rep (i, n)
    {
        int x;
        cin >> x;
        if (x < 0)
        {
            a[i] = x * -1;
            negCnt++;
        }
        else
            a[i] = x;
    }

    ll ans;
    sort(a.begin(), a.end());
    if (negCnt % 2)
        ans = accumulate(a.begin() + 1, a.end(), 0LL) + a[0] * -1;
    else
        ans = accumulate(a.begin(), a.end(), 0LL);

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

Measured memory_bytes: 4032
import sys
from collections import Counter

sys.setrecursionlimit(2502)


def paint(field, i, j, b, f, moves={(-1, 0), (1, 0), (0, 1), (0, -1)}):
    fij = field[i][j]
    if fij & f:
        return
    if fij & 4 and not fij & b:
        return
    field[i][j] |= b | f
    for di, dj in moves:
        ni = i + di
        nj = j + dj
        if nj < 0 or w <= nj or ni < 0 or h <= ni:
            continue
        paint(field, ni, nj, b, f)


buf = []
chardict = {'.': 0, 'W': 5, 'B': 6}
while True:
    w, h = map(int, input().split())
    if w == 0:
        break
    field = [[chardict[c] for c in input()] for _ in range(h)]
    for i in range(h):
        for j in range(w):
            fij = field[i][j]
            if fij & 4 and not fij & 24:
                paint(field, i, j, fij & 3, (fij & 3) << 3)
    result = Counter(b & 7 for row in field for b in row)
    buf.append('{} {}'.format(result[2], result[1]))
print('\n'.join(buf))

Measured memory_bytes: 10936
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int N, A, B;
  while (cin >> N >> A >> B) {
    string S;
    cin >> S;
    int rem = A + B;
    int b = 0;
    for (char c : S) {
      if (c == 'a') {
        if (rem > 0) {
          --rem;
          cout << "Yes" << endl;
        } else {
          cout << "No" << endl;
        }
      }
      if (c == 'b') {
        ++b;
        if (rem > 0 && b <= B) {
          --rem;
          cout << "Yes" << endl;
        } else {
          cout << "No" << endl;
        }
      }
      if (c == 'c') {
        cout << "No" << endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 896
use std::io::BufRead;

fn main() {
    let stdin = std::io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let _: u32 = iter.next().unwrap().parse().unwrap();
    let g: u32 = iter.next().unwrap().parse().unwrap();

    let mut ps: Vec<u32> = Vec::new();
    let mut cs: Vec<u32> = Vec::new();
    for result in stdin.lock().lines() {
        let line = result.unwrap();
        let mut iter = line.split_whitespace();
        let p: u32 = iter.next().unwrap().parse().unwrap();
        let c: u32 = iter.next().unwrap().parse().unwrap();
        ps.push(p);
        cs.push(c);
    }

    let res = solve(g, &ps, &cs);
    println!("{}", res);
}

fn solve(target: u32, ps: &Vec<u32>, cs: &Vec<u32>) -> u32 {
    let mut min = std::u32::MAX;
    for bit in 0..(1<<ps.len()) {
        let mut sum = 0;
        let mut count = 0;
        for i in 0..ps.len() {
            if bit & (1<<i) != 0 {
                sum += (i as u32 + 1) * 100 * ps[i] + cs[i];
                count += ps[i];
            }
        }
        if sum >= target {
            min = std::cmp::min(min, count);
        } else {
            // 中途半端に解く
            for i in (0..ps.len()).rev() {
                if bit & (1<<i) == 0 {
                    if target > sum + (i as u32 + 1) * 100 * ps[i] {
                        break;
                    } else {
                        let tmp = ((target - sum) as f64 / ((i as u32 + 1) * 100) as f64).ceil() as u32;
                        min = std::cmp::min(min, count + tmp);
                    }
                }
            }
        }
    }
    min
}


Measured memory_bytes: 4352
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

use std::iter::Iterator;

fn main() {

    input!{
       n:usize,
       k:usize
    }

    if n % k != 0{
        println!("1")
    }else{
        println!("0")
    }


}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll d,n; cin>>d>>n;
    ll res=n;
    if(n==100) res=101;
    rep(i,d) res*=100;
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 256
# frozen_string_literal: true

# https://github.com/universato/ac-library-rb/blob/master/src/segtree.rb
# Segment Tree
class Segtree
  def initialize(arg, e, &block)
    case arg
    when Integer
      v = Array.new(arg) { e }
    when Array
      v = arg
    end

    @e  = e
    @op = proc(&block)

    @n = v.size
    @log = @n.bit_length
    @leaf_size = 1 << @log
    @d = Array.new(@leaf_size * 2) { e }
    v.each_with_index { |v_i, i| @d[@leaf_size + i] = v_i }
    (@leaf_size - 1).downto(1) { |i| update(i) }
  end

  def set(q, x)
    q += @leaf_size
    @d[q] = x
    1.upto(@log) { |i| update(q >> i) }
  end

  def get(pos)
    @d[@leaf_size + pos]
  end

  def prod(l, r)
    sml = @e
    smr = @e
    l += @leaf_size
    r += @leaf_size

    while l < r
      if l[0] == 1
        sml = @op.call(sml, @d[l])
        l += 1
      end
      if r[0] == 1
        r -= 1
        smr = @op.call(@d[r], smr)
      end
      l /= 2
      r /= 2
    end

    @op.call(sml, smr)
  end

  def all_prod
    d[1]
  end

  def max_right(l, &block)
    return @n if l == @n

    f = proc(&block)

    l += @leaf_size
    sm = @e
    loop do
      l /= 2 while l.even?
      unless f.call(@op.call(sm, @d[l]))
        while l < @leaf_size
          l *= 2
          if f.call(@op.call(sm, @d[l]))
            sm = @op.call(sm, @d[l])
            l += 1
          end
        end
        return l - @leaf_size
      end
      sm = @op.call(sm, @d[l])
      l += 1
      break if (l & -l) == l
    end

    @n
  end

  def update(k)
    @d[k] = @op.call(@d[2 * k], @d[2 * k + 1])
  end

  def inspect
    t = 0
    res = "SegmentTree\n  "
    a = @d[1, @d.size - 1]
    a.each_with_index do |e, i|
      res << e.to_s << ' '
      if t == i && i < @leaf_size
        res << "\n  "
        t = t * 2 + 2
      end
    end
    res
  end
end

SegTree     = Segtree
SegmentTree = Segtree

INF = (1 << 60) - 1
_, q = gets.to_s.split.map{ |t| t.to_i }
a    = gets.to_s.split.map{ |t| t.to_i }
st = Segtree.new(a, -INF) { [_1, _2].max }
ans = []
q.times do
  query = gets.to_s.split.map{ |t| t.to_i }
  if query[0] == 1
    _, x, v = query
    st.set(x - 1, v)
  elsif query[0] == 2
    _, l, r = query
    ans << st.prod(l - 1, r)
  else
    _, x, v = query
    ans << st.max_right(x - 1) { _1 < v } + 1
  end
end
puts ans


Measured memory_bytes: 39912
from collections import namedtuple, defaultdict
from bisect import bisect

City = namedtuple('City', 'y p')

N, M = map(int,  input().split())

cities = []
cities_by_P = defaultdict(list)

for _ in range(M):
  p, y = map(int, input().split())
  city = City(y, p)
  cities.append(city)
  cities_by_P[p].append(city)
  
for p in cities_by_P.keys():
  cities_by_P[p].sort()

# MlogM  
for city in cities:
  i = bisect(cities_by_P[city.p], city)
  print('%06d' % city.p + '%06d' % i)

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

using namespace std;
typedef long long ll;
ll m,k,nr;
int main()
{
    cin>>m>>k;
    nr=(1<<m)-1;
    if(k>nr)
    {
        cout<<-1;
        return 0;
    }
    if(m>=2)
    {
        for(int i=nr;i>=0;i--)
            if(i!=k)
                cout<<i<<" ";
        cout<<k<<" ";
        for(int i=0;i<=nr;i++)
            if(i!=k)
                cout<<i<<" ";
        cout<<k;
    }
    else if(m==0&&k==0)
    {
        cout<<"0 0";
    }
    else if(m==1)
    {
        if(k==0)
            cout<<"0 0 1 1";
        else
            cout<<-1;
    }
    return 0;
}


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


using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  srand((unsigned)time(NULL));
  int d;
  int res = 0;
  cin >> d;
  vector<int> c(26);
  rep(i,26)cin >> c[i];
  vector<vector<int>> v(d,vector<int>(26));
  vector<int> contest(d,0);
  vector<int> last(26,0);
  vector<int> satisfy(26,0);
  rep(i,d)rep(j,26){
    int x;cin >> x;
    v[i][j] = x;
  }/*
  for(int i = 1;i <= d;i++){
    rep(j,26)if(v[i-1][contest[i-1]] < v[i-1][j])contest[i-1] = j;
    last[contest[i-1]] = i;
    res += v[i-1][contest[i-1]];
    rep(j,26)res -= c[j]*(i-last[j]),satisfy[j] += c[j]*(i-last[j]);
  }
  while(1.0*clock()/CLOCKS_PER_SEC <= 1.7){
    //int now_time = clock();
    //if(1.0*now_time/CLOCKS_PER_SEC > 1.7)break;
    int day = rand()%d,pos = rand()%26;
    vector<int> new_contest = contest;
    int res_ = res;
    int pre = new_contest[day];
    res_ += satisfy[pos];
    res_ += satisfy[pre];
    res_ -= v[day][pre];
    res_ += v[day][pos];
    int pos_satisfy = 0,pre_satisfy = 0;
    last[pos] = last[pre] = 0;
    new_contest[day] = pos;
    for(int i = 1;i <= d;i++)last[pos] = (new_contest[i-1] == pos ? last[pos] = i : last[pos]),pos_satisfy += c[pos]*(i-last[pos]);
    for(int i = 1;i <= d;i++)last[pre] = (new_contest[i-1] == pre ? last[pre] = i : last[pre]),pre_satisfy += c[pre]*(i-last[pre]);
    res_ -= (satisfy[pos]+satisfy[pre]);
    if(res < res_){
      res = res_;
      contest = new_contest;
      satisfy[pre] = pre_satisfy;
      satisfy[pos] = pos_satisfy;
    }
  }
  rep(i,d)cout << contest[i]+1 << endl;*/
  int j = 365;
  for(int i = 0;j;i++){
    cout << (i%26) + 1 << endl;
    j--;
  }
  


  return 0;
}


Measured memory_bytes: 3684
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll INF=1e18;
const int MOD=1e9+7;
const double pi=acos(-1);

int main(){
  ll n,k;
  cin >> n >> k;
  vector<ll>h(n);
  rep(i,n) cin >> h[i];
  sort(h.begin(),h.end());
  ll ans=INF;
  rep(i,n-k+1){
    ans=min(ans,h[i+k-1]-h[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
import sys
import math
a,b,c,k=map(int,input().split())
if a>k:
    print(k)
elif a+b>=k or a>=k:
    print(a)
elif c>(k-(a+b)):
    s=k-(a+b)
    print(a-1*s)
else:
    print(a-c)

Measured memory_bytes: 9184