akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = map(int, input().split())
    A = list(map(int, input().split()))

    A_sum = [0]
    D = defaultdict(int)
    D[A_sum[-1]] += 1
    for a in A:
        A_sum.append((A_sum[-1] + a) % m)
        D[A_sum[-1]] += 1

    res = 0
    for v in D.values():
        res += v * (v - 1) // 2
    print(res)


if __name__ == '__main__':
    resolve()


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

int main() {

	ll n, k; cin >> n >> k;
	vector<ll> a(n);
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
	}
	//ll tmp = 1;
	//for (ll i = 0; i < k; i++) {
	//	tmp *= a[k - 1 - i];
	//}
	//ll prev = tmp;
	for (ll i = 0; i < n - k; i++) {		
		//ll now = prev / a[i] * a[i + k];
		if (a[i] < a[i+k]) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
		//prev = now;
	}
	return 0;
}

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

int main(void){
	string S;
	cin >> S;
	string head,tail;
	head = S.substr(0,2);
	tail = S.substr(2,2);
	
	int head_i,tail_i;
	head_i = stoi(head);
	tail_i = stoi(tail);
	
	if(head_i <= 12 && head_i > 0){ // head_i = MM , tail_i =YY
		if(tail_i <= 12 && tail_i > 0){ // tail_i =MM
				cout << "AMBIGUOUS";
				return 0;
		}
		cout << "MMYY";
		return 0;
	}
	
	if(tail_i <= 12 && tail_i > 0){ // tail_i =MM
			cout << "YYMM";
			return 0;
	}
	
	cout << "NA";
	return 0;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/m-solutions2019/submissions/5741430
from functools import reduce
from operator import mul
import sys

input = sys.stdin.readline

MOD = 10 ** 6 + 3


def inv(n):
    return pow(n, MOD - 2, MOD)


fact = [1]
for n in range(1, MOD):
    fact.append((fact[-1] * n) % MOD)
    # d>1 の数列を d=1 となる数列に変換する
    # MODの倍数を含む数列の積は0になるので,
    # MODの倍数を含まない区間の積が計算できればよい
    # そのような区間の右端はMOD-1であり,fact[MOD-1]が計算できればよい

inv_fact = [-1] * MOD
inv_fact[MOD - 1] = inv(fact[-1])
for n in range(MOD - 2, -1, -1):
    inv_fact[n] = ((inv_fact[n + 1] * (n + 1)) % MOD)
    # inv_factは,inv(n!)にn,n-1,...を掛けるイメージ

Q = int(input())
for _ in range(Q):
    x, d, n = map(int, input().split())

    if x == 0:
        print(0)
        continue

    if d == 0:
        print(pow(x, n, MOD))
        continue

    xd = (x * inv(d)) % MOD
    if xd == 0:
        print(0)
        continue
        
    if MOD - xd < n:
        print(0)
        continue

    dn = pow(d, n, MOD)
    print((((fact[xd + n - 1] * inv_fact[xd - 1]) % MOD) * dn) % MOD)


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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DMP(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(int x,int suc=1){
	printf("%lld",x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

const int inf=LLONG_MAX/3;

int Solve(string s,char c){
	vi t;
	for(auto w:s)t.PB(w==c);
	int res=0;
	while(!t.empty()){
		if(t==vi(t.size(),1))return res;
		REP(i,int(t.size())-1)t[i]|=t[i+1];
		t.pop_back();
		res++;
	}
	return inf;
}

signed main(){
	string s=readString();
	vi has(26,0);for(auto c:s)has[c-'a']=1;
	int ans=inf;
	REP(i,26)if(has[i])chmin(ans,Solve(s,'a'+i));
	cout<<ans<<endl;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    string S;
    cin >> S;
    int cnt = 0;
    char pre = S[0];
    rep(i,S.size()){
        if(S[i]!=pre){
            cnt++;
            pre = S[i];
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdlib>

using namespace std;

int main(int argc, char **argv)
{
  int n, m, *a, t, p;

  while(1){
    cin >> n >> m >> p;
    if(n == 0 && m == 0 && p == 0){
      break;
    }
    a = (int *)calloc(n+1, sizeof(int));
    t = 0;
    for(int i = 1; i <= n; i++){
      cin >> a[i];
      t += a[i]*100;
    }
    if(a[m] == 0){
      cout << a[m] << endl;
      free(a);
      continue;
    }
    t -=(t*p/100);
    t /= a[m];
    cout << t << endl;

    free(a);
  }

  return 0;
}

Measured memory_bytes: 0
function Main(input) {
  let args = input
    .trim()
    .split(" ")
    .map((x) => parseInt(x, 10));
  let a = args[0];
  let b = args[1];

  let f = (a / b).toFixed(5);
  let d = parseInt(f, 10);
  let r = a % b;
  console.log(d + " " + r + " " + f);
}

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


Measured memory_bytes: 15428
//
//  main.cpp
//  B - 0 or 1 Swap
//
//  Created by Hashizo on 2019/07/27.
//  Copyright © 2019 Hashizo. All rights reserved.
//

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

using namespace std;

#undef INT_MAX
#undef INT_MIN

#define INT_MAX	2147483647
#define INT_MIN	(-INT_MAX  -1)

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define REPLACE(s, f, t) regex_replace(s, regex(f), t)

int main(int argc, const char * argv[]) {
	int n;
	cin >> n;
	
	vector<int> p(n);
	
	REP(i, n) {
		cin >> p[i];
	}

	vector<int> sort_p;
	
	copy(p.begin(), p.end(), back_inserter(sort_p));
	
	SORT(sort_p);

	int cnt=0;
	REP(i,n) {
		if(p[i] != sort_p[i]) {
			cnt++;
		}
	}
	
	if (cnt <= 2) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	
	return 0;
}


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

int main() {
 int A,B,C;
 cin >> A >> B >> C;
  if(A == B && B != C||A == C && A != B||A != B && B == C){
    cout << "Yes" << endl;
  }
  else{
    cout <<"No"<< endl;
  }
}
 

Measured memory_bytes: 3568
# speed-test
# https://abc089.contest.atcoder.jp/submissions/2206669

h,w,d = map(int,input().split())
 
dic = {}
for i in range(h):
    a = input().split()
    for j in range(w):
        dic[int(a[j])] = (i+1,j+1)
        
q = int(input())
c = [0]*(h*w+1)
for i in range(d+1,h*w+1):
    pi,pj = dic[i]; qi,qj = dic[i-d]
    c[i] = c[i-d] + abs(pi-qi) + abs(pj-qj)
    
for i in range(q):
    l,r = map(int,input().split())
    print(c[r]-c[l])


Measured memory_bytes: 24512
#include<bits/stdc++.h>
using namespace std;
inline int Read()
{
	int f=1,num=0;
	char ch=getchar();
	while(0==isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(0!=isdigit(ch)) num=(num<<1)+(num<<3)+ch-'0',ch=getchar();
	return num*f;
}
string s;
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>s;
	if(s[0]==s[s.size()-1]){
		if(s.size()%2==1)cout<<"Second"<<endl;
		else cout<<"First"<<endl;
	}
	else{
		if(s.size()%2==1)cout<<"First"<<endl;
		else cout<<"Second"<<endl;
	}
	return 0;
}


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

using ll = long long int;
using ull = unsigned long long int;
using P = pair<ll, ll>;
using P3 = pair<P,ll>;
using PP = pair<P, P>;
constexpr int INF = 1 << 30;
constexpr ll MOD = ll(1e9)+7;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};
constexpr int di8[] = {0, 1, 1, 1, 0, -1, -1, -1};
constexpr int dj8[] = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr double EPS = 1e-9;

int n, x, y;

vector<vector<int> > d;

void bfs(int s){
    d[s].resize(n, INF);
    d[s][s] = 0;
    queue<int> que;
    que.push(s);
    while(!que.empty()){
        int i = que.front();
        que.pop();
        if(i+1<n && d[s][i+1] > d[s][i]+1){
            d[s][i+1] = d[s][i]+1;
            que.push(i+1);
        }
        if(i-1>=0 && d[s][i-1] > d[s][i]+1){
            d[s][i-1] = d[s][i]+1;
            que.push(i-1);
        }
        if(i==x && d[s][y] > d[s][x]+1){
            d[s][y] = d[s][x]+1;
            que.push(y);
        }
        if(i==y && d[s][x] > d[s][y]+1){
            d[s][x] = d[s][y]+1;
            que.push(x);
        }
    }
}

int main(){
    cin >> n >> x >> y;
    x--; y--;
    d.resize(n);
    for(int i=0;i<n;i++){
        bfs(i);
    }
    vector<int> cnt(n);
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            cnt[d[i][j]]++;
        }
    }
    for(int i=1;i<n;i++){
        cout << cnt[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 16000
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

#ifdef DEBUG
mt19937 mrand(300); 
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); 
#endif

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 2e5 + 5;
int n;
vector<int> g[maxn];

bool read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    g[i].clear();
  }
  for (int i = 0; i < n - 1; i++) {
    int v, u;
    scanf("%d%d", &v, &u);
    v--;
    u--;
    g[v].push_back(u);
    g[u].push_back(v);
  }
  return true;
}

int d[maxn];

void dfs(int v, int p) {
  for (int i = 0; i < sz(g[v]); i++) {
    int u = g[v][i];
    if (u == p) {
      continue;
    }
    d[u] = d[v] + 1;
    dfs(u, v);
  }
}

void solve() {
  int diam;
  {
    int v = 0;
    d[v] = 0;
    dfs(v, -1);
    int u = 0;
    for (int i = 1; i < n; i++) {
      if (d[i] > d[u]) {
        u = i;
      }
    }
    swap(v, u);
    d[v] = 0;
    dfs(v, -1);
    u = 0;
    for (int i = 1; i < n; i++) {
      if (d[i] > d[u]) {
        u = i;
      }
    }
    diam = d[u];
  }
  if (diam % 3 == 1) {
    printf("Second\n");
    return;
  }
  printf("First\n");
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 27648
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
	int n,count=0,row[100];

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> row[i];
	}
	
	for (int i = 0; i < n - 1; i++) {
		for (int j = 0; j < n - 1 - i; j++) {
			if (row[n - 1 - j] < row[n - 2 - j]) { swap(row[n - 1 - j], row[n - 2 - j]); count += 1; }
		}
	}

	for (int i = 0; i < n; i++) {
		if (i == n - 1) { printf("%d\n", row[i]); }
		else { printf("%d ", row[i]); }
	}
	printf("%d\n", count);

	return 0;
}

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

#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())
#define endl "\n"

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
void initialize( void );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;
template <typename T, typename K> struct P {
	T a; K b;
};
typedef struct {
	vector <int> to;
	int cost;
} edge;

int main( void ){
	// initialize();
	int N, X, T;
	cin >> N >> X >> T;
    cout << ((int)(N+X-1)/X)*T << endl;
}

template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}
void initialize( void ){
	cout << fixed << setprecision( 10 );
}


Measured memory_bytes: 3612
using namespace std;
#include 		<bits/stdc++.h>
#define	fi 		first
#define se 		second
#define pb 		push_back
#define mp 		make_pair
#define maxn	500005
#define inf		int(21e8)
#define mod		int(1e9+7)
#define db		double
#define ll		long long
#define si 		stack<int>
#define qi 		queue<int>
#define vi 		vector<int>
#define pi 		pair<int, int>
#define pq  	priority_queue< int, vector<int>, greater<int> >
ll powmod(ll a, ll b) {
	ll res = 1; a %= mod;
	for (; b; b >> 1)
		res = (res * ((b & 1) ? a : 1)) % mod,
		a = a * a % mod;
	return res;
}
ll gcd(ll a, ll b) {return b ? gcd(a, b) : a;}
int main() {
	int n;
	cin >> n;
	cout << 1000 - (n - 1) % 1000 - 1;
	system("pause");
	return 0;
}

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

#define M 1000000007

int main()
{
	int N;
	char s[100002];
	char t[100002];
	int  cnt[128];
	int i;

	scanf("%d%s%s", &N, s, t);

	cnt[s[0]] = 1;
	for (N--, i = 1; i < N; i++) {
		cnt[s[i]] += cnt[t[i]];
		if (cnt[s[i]] >= M)
		{
		    cnt[s[i]] -= M;
		}
	}

	printf("%d\n", cnt[t[N]]);

	return 0;
}


Measured memory_bytes: 2112
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;


int main(void)
{
    int n,a,b;
    cin >> n >> a >> b;
    string s;
    cin >> s;
    
    int cnt = 0,b_cnt = 0;
    for (int i = 0;i < n;i++)
    {
        if (s[i] == 'c')
        {
            cout << "No" << endl;
        }
        else
        {
            if (s[i] == 'a')
            {
                if (cnt < a + b)
                {
                    cout << "Yes" << endl;
                    cnt++;
                }
                else
                {
                    cout << "No" << endl;
                }
            }
            else
            {
                b_cnt++;
                if (cnt < a + b && b_cnt <= b)
                {
                    cout << "Yes" << endl;
                    cnt++;
                }
                else
                {
                    cout << "No" << endl;
                }                
            }
        }

        
    }
    
    return 0;
}


Measured memory_bytes: 896
# coding: utf-8

N = int(input())

ma = -1
res = 1
for i in range(1, N+1):
    num = i
    tmp = num
    count = 0
    while num % 2 == 0:
        count += 1
        num = num / 2

    if count > ma:
        res = tmp
        ma = count

print(res)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
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 (a>b) { a=b; return 1; } return 0; }

using Lint=long long;
using Graph=vector<vector<int>>;

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

    int N; cin>>N;
    Graph G(N);
    vector<int> a(N-1),b(N-1);
    for(int i=0;i<N-1;i++){
        cin>>a[i]>>b[i];
        a[i]--; b[i]--;
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
    }    
    
    int K=0;
    for(int i=0;i<N;i++) chmax(K,(int)G[i].size());

    map<pair<int,int>,int> color;
    function<void(int,int,int)> dfs=[&](int v,int p,int pre)
    {
        int col=1;
        for(int u:G[v]) if(u!=p){
            if(col==pre) col++;
            // cout<<u+1<<' '<<v+1<<' '<<col<<endl;
            color[minmax(u,v)]=col;
            dfs(u,v,col);
            col++;
        }
    };
    dfs(0,-1,0);
    cout<<K<<endl;
    for(int i=0;i<N-1;i++) cout<<color[minmax(a[i],b[i])]<<endl;
    return 0;
}

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

int main(){
    int n; cin >> n;
    int ans = 1;
    while(ans < n){
        //2の累乗になる数の中で一番nに近い数を探す
        if(ans * 2 > n) break;
        ans = ans * 2;
    }
    cout << ans;
}

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

using namespace std;

int main() {
	vector<int>d, e;
	int n, i, j;

	cin >> n;

	for (i = 0; i < n; i++) {
		cin >> j;
		if (j % 10 == 0) {
			d.push_back(j);
		}
		else {
			e.push_back(j);
		}
	}

	if (e.size() == 0) {
		cout << 0;
		return 0;
	}

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

	j = 0;
	for (i = 0; i < e.size(); i++) {
		j += e[i];
	}
	if (j % 10 == 0) {
		j -= e[0];
	}
	for (i = 0; i < d.size(); i++) {
		j += d[i];
	}
	cout << j;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
using namespace std;

int main() {
	
	string S;
	string T;

	cin >> S;
	cin >> T;

	int ans = 0;

	for (int i = 0; i < S.size(); i++) {
		if (S[i] == T[i]) {
			ans += 1;
		}
	}

	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
const ll INF = 1LL<<60;
const ll M = 1000000007;
ll mpow(ll a,ll b){ll res=1;while(b!=0){if(b&1)res=res*a%M;a=a*a%M;b=b>>1;}return res;}
ll mcomb(ll n,ll k){if(k>n/2)return mcomb(n,n-k);ll res=1;for(ll i=0;i<k;i++){res=res*(n-i)%M;res=res*mpow(k-i,M-2)%M;}return res;}
/*template*/

int main()
{
  ll n;string s;cin>>n>>s;
  string ans="";
  for(ll i=0;i<s.length();i++){
    ll j=s[i]-'A';
    j='A'+(j+n)%26;
    char k=j;
    ans+=k;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

class WeightedUnionFind{
public:
  int n;
  vector<int> u;
  vector<Int> weight;
  WeightedUnionFind(int n = 0):n(n){
    u = vector<int>(n);
    weight = vector<Int>(n,0);
    for(int i = 0;i < n;i++)u[i] = i;
  }
  int r(int x){
    if(u[x] == x)return x;
    r(u[x]);
    weight[x] += weight[u[x]];
    return u[x] = r(u[x]);
  }

  Int dif(Int x, Int y){
    if(r(x) != r(y))return INF;
    return weight[x] - weight[y];
  }

  //x - y == w
  bool isOK(int x, int y, Int w){
    if(r(x) != r(y))return false;
    return dif(x,y) == w;
  }

  int unite(int x, int y, Int w){
    r(x);
    r(y);
    w += weight[y];
    w -= weight[x];
    x = r(x);
    y = r(y);
    u[x] = y;
    weight[x] = w;
  }
};

void ok(){
  cout << "Yes" << endl;
  exit(0);
}

void ng(){
  cout <<  "No" << endl;
  exit(0);
}

Int n, m, l, r, d;
int main(){
  cin >> n >> m;
  WeightedUnionFind wuf(n);
  for(int i = 0;i < m;i++){
    cin >> l >> r >> d;l--, r--;
    if(wuf.r(l) == wuf.r(r)){
      if(!wuf.isOK(r, l, d))ng();
    }
    else{
      wuf.unite(r, l, d);
    }
  }
  ok();
  return 0;
}

Measured memory_bytes: 1408
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.*;

import javax.sound.sampled.ReverbType;

public class Main {

	 static Scanner scan=new Scanner(System.in);
	 static int cnt=0;
	 static int M=(int)1e9+7;
	static boolean issamedi(int i,int j){
		if(i>0&&j<0)
			return false;
		if(i>0&&j>0&&i>j)
			return false;
		return true;
		
		
	}

	
		static boolean isvowel(char c) {
			return c=='a'||c=='e'||c=='i'||c=='o'||c=='u';
			
		}
	 public static int maxVowels(String s, int k) {
	        int i=0;
	        ArrayList<Integer>lenghts=new ArrayList<Integer>();
	        for(int j=0;j<s.length();j++) {
	        	if(i==k)
	        		i=0;
	        	if(!isvowel(s.charAt(j)))
	        		i=0;
	        	if(isvowel(s.charAt(j))) {
	        		i++;
	        		lenghts.add(i);
	        		}
	        	
	        }
	        try {
	        return Collections.max(lenghts);
	        }
	        catch (NoSuchElementException e) {
	        return 0;}
	    }
	
	 static int convert(int n) {
		 String s=String.valueOf(n);
		 String s1="";
		 s1+=s.charAt(0);
		 int c=0;
		 for(int i=1;i<s.length();i++)
		 s1+='0';
		 return Integer.parseInt(s1);
	 }
	 static  boolean ispositive(ArrayList<Integer>ar) {
		 for(int i=0;i<ar.size();i++) {
			 if(ar.get(i)>0)
				 return true;
			 }
		 return false;
		 
	 }
	public static void main(String[] args) throws IOException {
int x=scan.nextInt();
int y=scan.nextInt();

		for(int i=0;i<x+1;i++) {
			int a=x-i;
			if (2 * i + 4 * a == y) {
				System.out.println("Yes");
			return;	
			}
			
		}
		System.out.println("No");
		
		
		}
		
 




	
	

	
	

	

	
}


Measured memory_bytes: 35636
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<cctype>
using namespace std;
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;}
const long long INF = 1LL << 60;

int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int i,ans=0;
	string s;
	cin>>s;
	for(i=0;i<4;i++){
		if(s[i]=='+')ans++;
		else ans--;
	}
	cout<<ans<<endl;
	
	
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>

#define M 1000010
#define L 20
int answer[M];
char dictionary[M][L];
int getChar(char ch)
{
	if(ch=='A')
		return 1;
	if(ch=='C')
		return 2;
	if(ch=='G')
		return 3;
	if(ch=='T')
		return 4;
	return 0;
}
long long int getkey(char str[])
{
	long long int sum=0,p=1,i;
	for(i=0;i<=strlen(str)-1;i++)
	{
		sum+=p*getChar(str[i]);
		p*=5;
	}
	return sum;
}
int h1(int key)
{
	return key%M;
}
int h2(int key)
{
	return 1+(key%(M-1));
}
int find(char str[20])
{
	long long int key,i,h;
	key=getkey(str);
	for(i=0;;i++)
	{
		h=(h1(key)+i*h2(key))%M;
		if(strcmp(str,dictionary[h])==0)
			return 1;
		if(strlen(dictionary[h])==0)
			return 0;
	}
	return 0;
}
void insert(char str[20])
{
	long long int key,i,h;
	key=getkey(str);
	for(i=0;;i++)
	{
		h=(h1(key)+i*h2(key))%M;
		if(strcmp(str,dictionary[h])==0)
			return;
		if(strlen(dictionary[h])==0)
		{
			strcpy(dictionary[h],str);
			return;
		}
	}
	return;
}
int main()
{
	char str[L],com[9];
	int n,i,answern=0;
	//for(i=0;i<M;i++)
	//	dictionary[i][0]='\0';

	scanf("%d",&n);	
	for(i=1;i<=n;i++)
	{
		scanf("%s %s",com,str);
		if(strcmp(com,"insert")==0)
			insert(str);
		if(strcmp(com,"find")==0)
		{
			answern++;
			answer[answern]=find(str);
		}
	}
	for(i=1;i<=answern;i++)
	{
		if(answer[i])
			printf("yes\n");
		else
			printf("no\n");
	}
	return 0;
}


Measured memory_bytes: 22532
#include<iostream>
#include<vector>
#include<algorithm>
#define _USE_MATH_DEFINES
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)

int main() {
	int k, x;
	cin >> k >> x;
	int min, max;
	min = x-k + 1;
	max = x+k - 1;
	if (max > 100000)max = 100000;
	if (min < -100000)min = -100000;
	for (int i = min; i <= max; ++i) {
		cout << i << endl;
	}
	return 0;
}

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

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

    bool ok = false;
    for (int i=1; i<=9; ++i) {
        for (int j=1; j<=9; ++j) {
            if (i*j == N) ok = true;
        }
    }

    cout << (ok ? "Yes" : "No") << endl;
}


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


void solve(long long A, long long B, long long C){
  auto result = C - (A - B);

  std::cout << (result > 0 ? result : 0) << std::endl;
}

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


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner scan = new Scanner(System.in);
        int l=scan.nextInt();
        String a=scan.next();
        String b=scan.next();
        for (int i=0;i<l;i++){
            System.out.print(a.substring(i,i+1) + b.substring(i,i+1));
        }
    }
}

Measured memory_bytes: 21972
#include <iostream>
#include <set>
#include <vector>
#include <map>
using namespace std;
 
#define int long long
#define rep(i, a) for (int i = 0; i < (a); i++)
#define repd(i, a) for (int i = (a)-1; i >= 0; i--)
#define reps(i, a, j) for (int i = (j); i < (a); i++)
#define deb(x) cout << #x << " " << x << endl;
#define debs(x) cout << #x << " " << x << " ";
#define deba(x) for (auto _i:x) cout << _i << " "; cout << endl;
#define ms(a) memset(a,0,sizeof(a));
#define mp make_pair
#define eb emplace_back
#define FastOpen freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define pii pair < int , int >
//int power(int x,int p){if(p==0)return 1;if(p==1)return x;if(p%2)return x*power(x,p-1);int y=power(x,p/2);return y*y;}
/*
*/

const int inf = 1e9 +7;
void solve() {
    int n,k; cin >> n >> k;
    int arr[n]; rep(i,n) cin >> arr[i];
    int dp[n];
    dp[0] = 0;
    reps(i,n,1) {
        dp[i] = inf;
        reps(j,k+1,1) {
            if (i-j < 0) continue;
            dp[i] = min(dp[i],dp[i-j] + abs(arr[i] - arr[i-j]) );
        }
    }
//    deba(dp);
    cout << dp[n-1] << endl;
}

signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//    FastOpen
    int t; t=1;
    while (t--) solve();
}





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

int main() {
  int H, W;

  while (true) {
    cin >> H >> W;
    if (H == 0 && W == 0) break;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (i == 0 || i == H - 1 || j == 0 || j == W - 1)
          cout << '#';
        else
          cout << '.';
      }
      cout << endl;
    }
    cout << endl;
  }
}


Measured memory_bytes: 3080
def small_and_large_integers(A: int, B: int, K: int) -> list:
    l, r = [], []
    for k in range(K):
        if A + k == B - k:
            l = l + [A+k]
            break
        if B - k < A + k:
            break

        l = l + [A+k]

        r = [B-k] + r
    return l + r


if __name__ == "__main__":
    A, B, K = map(int, input().split())
    ans = small_and_large_integers(A, B, K)
    for a in ans:
        print(a)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	for(int i = 1; i <= 10000; i++){
		int ta = i * 108 / 100;
		int tb = i * 11 / 10;
		if(ta - i == a && tb - i == b){
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}

Measured memory_bytes: 764
#include<stdio.h>
#define N 100001
#define SWAP(a,b){int temp=a; a=b; b=temp;}

int A[N];

int main(){
  int n, i, p;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  
  p = Partition(A, 0, i-1);

  for(i=0;i<n;i++){
    if(i==p) printf("[%d]",A[i]);
    else printf("%d",A[i]);
    if(i<n-1) printf(" ");
  }
  printf("\n");
  return 0;
}


int Partition(int A[], int p, int r){
  int x, i, j;
  
  x = A[r];
  i = p - 1;
  
  for(j=p;j<=r-1;j++){
    if(A[j]<=x){
      i++;
      SWAP(A[i],A[j]);
    }
  }
  SWAP(A[i+1],A[r]);
  
  return i+1;
}







Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define L long long

using namespace std;

struct S{
	L idx,val;
}a[100010];

bool operator<(S a,S b){
	return a.val<b.val;
}

L n,m,k,ans;

vector<L>v[100010];

L chk[100010],trtop;
L comsz[100010];
L mi[100010],mid[100010];
L edgechk[100010];

void dfs(L x){
	if(mi[trtop]>a[x].val)
	{
		mi[trtop]=a[x].val;
		mid[trtop]=x;
	}
	L i;
	for(i=0;i<v[x].size();i++)
	{
		if(!chk[v[x][i]])
		{
			chk[v[x][i]]=trtop;
			dfs(v[x][i]);
		}
	}
}

int main()
{
	scanf("%lld %lld",&n,&m);
	k=n-1-m;//2k개 골라야함 한 컴포넌트 k개 이하 
	if(k==0)
	{
		puts("0");
		return 0;
	}
	L i;
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&a[i].val);
		a[i].idx=i;
	}
	for(i=1;i<=m;i++)
	{
		L s,e;
		scanf("%lld %lld",&s,&e);
		s++;
		e++;
		v[s].push_back(e);
		v[e].push_back(s);
	}
	for(i=1;i<=n;i++)
	{
		if(!chk[i])
		{
			trtop++;
			mi[trtop]=a[i].val;
			mid[trtop]=i;
			chk[i]=trtop;
			dfs(i);
		}
	}
	L cnt=0;
	for(i=1;i<=trtop;i++)
	{
		edgechk[mid[i]]=1;
		comsz[i]++;
		cnt++;
		ans+=a[mid[i]].val;
	}
	if(cnt>k*2)
	{
		puts("Impossible");
		return 0;
	}
	if(cnt==k*2)
	{
		printf("%lld\n",ans);
		return 0;
	}
	sort(a+1,a+n+1);
	for(i=1;i<=n;i++)
	{
		if(!edgechk[a[i].idx]&&comsz[chk[a[i].idx]]<k)
		{
			comsz[chk[a[i].idx]]++;
			edgechk[a[i].idx]=1;
			cnt++;
			ans+=a[i].val;
			if(cnt==k*2) break;
		}
	}
	if(cnt==k*2) printf("%lld\n",ans);
	else puts("Impossible"); 
}

Measured memory_bytes: 10112
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
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(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h,w,k;cin>>h>>w>>k;
    vector<vector<ll>> dp(h+1,vector<ll>(w,0));
    dp[0][0]=1;
    rep(i,h){
        rep(j,w){
            rep(k,1<<w-1){
                ll mask = 3;
                bool flg = false;
                rep(l,w-1){
                    flg |= (k>>l&3)==3;
                }
                if(flg){
                    DEBUG{
                        printf("continue k: %d\n",k);
                    }
                    continue;
                }
                if(j<w-1&&k>>j&1){
                    dp[i+1][j+1] += dp[i][j];
                    dp[i+1][j+1] %= MOD;
                }else if(j>0&&k>>(j-1)&1){
                    dp[i+1][j-1] += dp[i][j];
                    dp[i+1][j-1] %= MOD;
                }else{
                    dp[i+1][j] += dp[i][j];
                    dp[i+1][j] %= MOD;
                }
            }
        }
    }
    cout << dp[h][k-1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct edge{int to,cost;};
typedef pair<int,int> P;
int n;
int p[1000],d[1000];
vector<edge> G[1000];

P rec(int pos,int prev){
  int maxm=0,sum=0;
  for(int i=0;i<(int)G[pos].size();i++){
    edge e=G[pos][i];
    if(e.to==prev)continue;
    if(1==G[e.to].size()){
      sum+=e.cost;
    }else{
      P p=rec(e.to,pos);
      sum+=p.first+e.cost+e.cost+e.cost;
      maxm=max(maxm,p.first-p.second+e.cost);
    }
  }
  
  return P(sum,sum-maxm);
}


void init(){
  for(int i=0;i<1000;i++)G[i].clear();
}
int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    init();
    for(int i=1;i<n;i++)cin>>p[i];
    for(int i=1;i<n;i++)cin>>d[i];
    for(int i=1;i<n;i++){
      p[i]--;
      G[i].push_back((edge){p[i],d[i]});
      G[p[i]].push_back((edge){i,d[i]});
    }
    int ans=(1<<28);
    for(int i=0;i<n;i++){
      ans=min(ans,rec(i,-1).second);
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1392
#include<bits/stdc++.h>
#include<atcoder/segtree>

using namespace std;
using ll = long long;

template<class T> class RMaxQ { public:
using value_type = T;
	static T op(T l, T r){ return max(l, r); }
	static T id(){return (T)-1e9;}
};
int target;

bool f(int v) { return v < target; }


int main()
{
	int n, q; cin >> n >> q;
	vector<int> a(n);
	for(int i = 0; i < n; i++)cin >> a[i];
	atcoder::segtree<int, RMaxQ<int>::op, RMaxQ<int>::id> tree(a);

	for(int i = 0; i < q; i++) {
		int t; cin >> t;
		if(t == 1) {
			int x, v; cin >> x >> v;
			x--;
			tree.set(x, v);
		}
		if(t == 2) {
			int l, r; cin >> l >> r;
			l--;
			cout << tree.prod(l, r) << endl;
		}
		if(t == 3) {
			int x; cin >> x >> target;
			x--;
			cout << tree.max_right<f>(x) + 1 << endl;
			
		}
	}
	
}

Measured memory_bytes: 6056
package main

import(
    "fmt"
    "sort"
    "strings"
)



func main() {
    var a,b,c int64
    var k uint
    fmt.Scan(&a,&b,&c,&k)
    ans := a + b + c + (max64(a,max64(b,c))<<k) - max64(a,max64(b,c))
    fmt.Println(ans)
}





// Pairsort
type Pair struct {
    first,second int64
}

type By func(p1, p2 *Pair) bool

func (by By) Sort(pairs []Pair) {
    ps := &pairSorter{
            pairs : pairs,
            by: by,
    }
    sort.Sort(ps)
}

type pairSorter struct {
    pairs []Pair
    by func(p1, p2 *Pair) bool
}

func (s *pairSorter) Len() int {
    return len(s.pairs)
}

func (s *pairSorter) Swap(i, j int) {
    s.pairs[i], s.pairs[j] = s.pairs[j], s.pairs[i]
}

func (s *pairSorter) Less(i, j int) bool {
    return s.by(&s.pairs[i], &s.pairs[j])
}

func first (p1, p2 *Pair) bool {
        return p1.first < p2.first
}

func second (p1, p2 *Pair) bool {
        return p1.second < p2.second
}
// end



func abs32(a int) int {
    if a<0{
        return -a
    }
    return a
}

func abs64(a int64) int64 {
    if a<0{
        return -a
    }
    return a
}

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

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

func min64(a, b int64) int64 {
    if a >= b {
        return b
    }
    return a
}

func max64(a, b int64) int64 {
    if a >= b {
        return a
    }
    return b
}

func gcd(a, b int64) int64 {
    if a % b == 0 {
        return b
    } else {
        return gcd(b, a%b)
    }
}

func lcm(a, b int64) int64 {
    return a / gcd(a, b) * b
}

func scanNums(len int) (nums []int){
    var num int
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanNums64(len int) (nums []int64){
    var num int64
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanString(len int) (str []string){
    var s string
    for i:=0; i<len; i++{
        fmt.Scan(&s)
        str = append(str,s)
    }
    return
}

func scanTwoNums(n,m int) ([][]int){
    Nums := make([][]int, n)
    for i:=0; i<n; i++{
        Nums[i] = make([]int, m)
    }
    return Nums
}

func SortString(s string) string{
    t := strings.Split(s, "")
    sort.Strings(t)
    return strings.Join(t, "")
}


Measured memory_bytes: 640
#include<stdio.h>

#define LIM 1000001
struct Process {
  char name[11];
  int time;
};
Process A[LIM];


class Queue {
  int head, tail;
  public:
  Queue() {
    head = 0;
    tail = 0;
  }
  void enqueue(Process p) {
    A[tail] = p;
    tail = (tail + 1) % LIM;
  }
  Process dequeue() {
    Process p = A[head];
    head = (head + 1) % LIM;
    return p;
  }
  bool empty() {
    return head == tail;
  }
};
int main() {
  int n, q, sum = 0;
  Process p;
  Queue queue;

  scanf("%d %d", &n, &q);

  for ( int i = 0; i < n; i++ ) {
    scanf("%s %d", p.name, &p.time);
    queue.enqueue(p);
  }

  while(!queue.empty()) {
    p = queue.dequeue();
    bool running_out = p.time <= q;
    if (running_out) {
      sum += p.time;
      printf("%s %d\n", p.name, sum);
    } else {
      p.time -= q;
      sum += q;
      queue.enqueue(p);
    }
  }

  return 0;
}



Measured memory_bytes: 5516
a = int(input())
b = int(input())
c = int(input())
x = int(input())

pattern = 0

for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            if i * 500 + j * 100 + k * 50 == x:
                pattern += 1

print(pattern)


Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;


int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};

const int MAX_N = 110000;

int memo[MAX_N];

int rec(int n) {
	if (n == 0)return 0;
	if (memo[n] != -1)return memo[n];

	int res = n;

	for (int pow6 = 1; pow6 <= n; pow6 *= 6)res = min(res, rec(n - pow6) + 1);

	for (int pow9 = 1; pow9 <= n; pow9 *= 9)res = min(res, rec(n - pow9) + 1);

	return memo[n] = res;
}

int func(int n, int a) {
	int res = 0;
	while (n > 0) {
		res += n % a;
		n /= a;
	}

	return res;
}


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

	cin >> a >> b;
	if (a <= 8 && b <= 8)cout << "Yay!" << endl;
	else cout << ":(" << endl;



	

		
	

	
	
}
	

Measured memory_bytes: 256
import java.util.Scanner

object Main extends App{
  val sc = new Scanner(System.in)

  val n = sc.nextInt

  val s = sc.next

  val sVec = s.toVector
  val res =  sVec.tail.foldLeft((1, sVec.head)) { case ((cnt, preCh), ch) =>
    (cnt + (if(ch != preCh) 1 else 0), ch )
  }._1

  println(res)
}


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

int main(){
    int a, b, c, k;
    cin >> a >> b >> c >> k;

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

Measured memory_bytes: 3596
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG keyence/b.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする
    string s;
    cin >> s;
    string k = "keyence";
    if(s.length() < 7){
        cout << "NO" << "\n";
        return 0;
    }

    if(s.substr(0, 7) == k){
        cout << "YES" << "\n";
        return 0;
    }else if(s.substr(s.length() - 7, 7) == k){
        cout << "YES" << "\n";
        return 0;
    }else{
        int cnt = 0;
        for(int i = 0; i < s.length(); i++){
            if(s[i] == k[cnt]){
                cnt++;
            }else{
                break;
            }
        }
        for(int i = s.length()-7+cnt; i < s.length(); i++){
            if(s[i] == k[cnt]){
                cnt++;
            }else{
                break;
            }
        }

        if(cnt == 7){
            cout << "YES" << "\n";
        }else{
            cout << "NO" << "\n";
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 1ll<<61;
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef pair<int, PP> PPP;
typedef vector<int> vec;
typedef vector<vec>mat;
struct edge { int to; int to2; int cost; };
vector<int> a(105);

signed main() {
	int n; cin >> n;
	rep(i, n)cin >> a[i];
	rep(i, n)a[i]--;
	
	vector<int>ans;
	while(n){
		int flg = 0;
		for(int j=n-1;j>=0;j--) {
			if (a[j] == j) {
				ans.push_back(j);
				a.erase(a.begin()+j);
				flg++;
				break;
			}
		}
		if (!flg) {
			cout << -1 << endl; return 0;
		}
		n--;
	}
	reverse(ans.begin(), ans.end());
	rep(i, ans.size())cout << ans[i] + 1 << endl;
}

Measured memory_bytes: 256
//作者：中国江苏省南京市李硕睿
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
typedef long long ll;
int main(){
 	long long n,a,b,c,d;
 	cin>>n>>a>>b>>c>>d;
 	if (c>d){
 		swap(c,d);
 	}
	for(int i=0;i<n;i++){
		if(-(n-1-i)*d+i*c<=(a-b)&&(a-b)<=-(n-1-i)*c+i*d){
			cout<<"YES"<<endl;
			return 0;
		}
	}
	cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
li = [0 for i in range(N+10)]

for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            mm = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if mm <= N:
                li[mm] += 1

for i in range(1,N+1):
    print(li[i])



Measured memory_bytes: 69332
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;

#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////

int main(){
    ll m,k;cin>>m>>k;
    if(k%2==1){
        cout<<0<<endl;return 0;
    }
    ll N=k/2;
    ll dp[m+1][N+1][m+1];memset(dp,0,sizeof(dp));
    dp[0][0][0]=1;
    rep(n,0,m){
        rep(d,0,N){
            rep(l,0,m){
                ll ad1=0;
                rep(li,l,n/2){
                    if(n-1>=0&&d-l>=0)Add(ad1,(dp[n-1][d-l][li]));
                }
                Add(dp[n][d][l],mod(ad1*(2*l+1)));
                ll ad2=0;
                rep(li,l-1,n/2){
                    if(n-2>=0&&(d-(2*l-1))>=0&&li>=0)Add(ad2,dp[n-2][d-(2*l-1)][li]);
                }
                Add(dp[n][d][l],mod(l*l*ad2));
            }
        }
    }
    /*rep(i,0,N){
        rep(j,0,m){
            cout<<dp[m][i][j]<<" ";
        }cout<<endl;
    }*/
    ll ans=0;
    rep(i,0,m){
        Add(ans,dp[m][k/2][i]);
    }
    cout<<ans<<endl;
    
    return 0;
}







Measured memory_bytes: 25728
#include <bits/stdc++.h>
#define X first
#define Y second
#define pb push_back

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    vector <int> a(n + 2, 0);
    for (int i = 1; i <= n; i++)
        cin >> a[i];

    int sum = 0;
    for (int i = 1; i <= n + 1; i++)
        sum += abs(a[i] - a[i - 1]);

    for (int i = 1; i <= n; i++)
    {
        int ans = sum;
        sum -= abs(a[i + 1] - a[i]) + abs(a[i] - a[i - 1]);
        sum += abs(a[i + 1] - a[i - 1]);
        cout << sum << '\n';
        sum = ans;
    }

    return 0;
}


Measured memory_bytes: 1664
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def main():
    n, k = [int(_) for _ in input().split()]
    r, s, p = [int(_) for _ in input().split()]
    t = input()

    #相手と同じ手を出したら勝ち
    point = {'p': s, 'r': p, 's': r}
    prevhand = ['o'] * k
    score = 0

    for i in range(n):
        if i + 1 <= k:
            prevhand[i%k] = t[i]
            score += point[t[i]]
        elif prevhand[i%k] != t[i]:
            prevhand[i%k] = t[i]
            score += point[t[i]]
        else:
            prevhand[i%k] = 'o'

    print(score)

if __name__ == '__main__':
    main()

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

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

    int x[n][d];
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < d; ++j) {
            cin >> x[i][j];
        }
    }

    int count = 0;
    for (int i = 0; i < n - 1; ++i) {
        for (int j = i + 1; j < n; ++j) {
            double dist;
            int dist2 = 0;
            for (int k = 0; k < d; ++k) {
                dist2 += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            }
            dist = sqrt(dist2);
            if (dist == (int)dist) ++count;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
def f(a,b):
    if b:return f(b,a%b)
    p=set()
    for i in range(2,int(a**0.5)+1):
        while True:
            if a%i==0:
                a//=i
                p.add(i)
            else:
                break
    if a!=1:
        return len(p)+2
    return len(p)+1
print(f(*map(int,input().split())))

Measured memory_bytes: 3060
import Data.List (sort)

main :: IO ()
main = interact $ format . solve . parse

parse :: String -> (Int, Int, [Int])
parse input = (n, k, h) where
    lns = lines input
    [n, k] = map read . words $ lns !! 0
    h = map read . words $ lns !! 1

solve :: (Int, Int, [Int]) -> Int
solve (n, k, h) = sum . take (n - k) . sort $ h

format :: Int -> String
format = (++ "\n") . show


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

using namespace std;
typedef long long ll;
const ll INF = 1e10;
const ll MOD = 1e9 + 7;

int main(){
    int K, X;
    cin >> K >> X;

    int start = max(-1000000, X - K + 1);
    int end   = min( 1000000, X + K - 1);
    // cout << start << " " << end << endl;

    for (int i = start; i <= end; i++)
        cout << i << " ";
    cout << endl;
}


Measured memory_bytes: 256