akhauriyash/Code-Regression huggingface dataset:
#include <string>
#include <iostream>

using namespace std;

int divide2(int x) {
    int count = 0;
    while (x % 2 == 0) {
        x /= 2;
        count++;
    }
    return count;
}

int main(void) {
    int N;
    int count = 0;
    cin >> N;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        count += divide2(a);
    }
    cout << count << endl;
    return 0;
}

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

int main(void) {
	int r, g, b;
	scanf("%d %d %d", &r, &g, &b);
	printf((100*r + 10*g + b) % 4 == 0 ? "YES\n" : "NO\n");
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    string s; cin >> s; 
    int ans = 0;
    for (int i = 0, j = s.length() - 1; i < j; ++i, --j)
        if (s[i] != s[j])
            ++ans;
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <stack>
#include <queue>

using namespace std;

#define MAX 2048
string button[10] = {"", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};

int main(void) {
	int n, num = 0, count = 0;
	char nums[MAX];
	scanf("%d", &n);
	while(n--) {
		scanf("%s", nums);
		for(int i = 0; nums[i] != '\0'; i++) {
			if(nums[i] == '0') {
				if(num >= 1 && num <= 9) {
					printf("%c", button[num][(count + button[num].size() - 1) % button[num].size()]);
				}
				num = 0;
				count = 0;
			}
			else if(nums[i] == num + '0') {
				count++;
			} else {
				num = nums[i] - '0';
				count = 1;
			}
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};

bool p[1001000];
bool used[1000100];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int g = 0;
    int n;
    cin>>n;
    vector<int> pri;
    for(int i=2;i*i<=1000000;i++){
        if(p[i] == false){
            pri.push_back(i);
            for(int j=i+i;j<=1000000;j+=i)p[j] = false;
        }
    }

    int a;
    bool pos = 1;
    for(int i=0;i<n;i++){
        cin>>a;
        g = gcd(g,a);
        if(a == 1)continue;
        if(pos){
            if(used[a])pos=false;
            for(auto j:pri){
                if(a % j == 0){
                    if(used[j])pos=false;
                    used[j] = 1;
                }
                while(a % j ==0)a /= j;
            }
            if(a != 1 && used[a])pos=false;
            used[a] = 1;
        }
    }
    if(pos)cout<<"pairwise coprime"<<endl;
    else if(g == 1)cout << "setwise coprime" << endl;
    else cout << "not coprime" << endl;

}


Measured memory_bytes: 5556
#include <bits/stdc++.h>
/*
#include<algorithm>
#include<array>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<typeinfo>
#include<utility>
#include<vector>
*/
#define int long long int
#define double long double
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i, n) for (int(i) = 0, i##_len = (n); (i) < i##_len; (i)++)
#define reps(i, x) for (int(i) = 1; (i) <= (int)(x); (i)++)
#define rrep(i, x) for (int(i) = ((int)(x)-1); (i) >= 0; (i)--)
#define rreps(i, x) for (int(i) = ((int)(x)); (i) > 0; (i)--)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1) << (n))
#define all(x) (x).begin(), (x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl
#define nint int
using namespace std;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
typedef pair<int, int> pii;
typedef pair<double, double> dop;
template <class T>
bool chmax(T& a, const T& b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b)
{
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
struct aaa {
    aaa()
    {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} aaaaaaa;


signed main()
{
    std::string s;
    int out = INF;
    cin >> s;
    for (int i = 0; i < 26; i++) {
        std::string temp(s);
        int tcount = 0;
        for (int j = 0; j < s.length(); j++) {
            std::string ca;
            int flag = 0;
            for (int k = 0; k < temp.length() - 1; k++) {
                if (temp[k] != temp[k + 1]) {
                    flag = 1;
                    break;
                }
            }
            if (!flag) {
                break;
            }
            for (int k = 0; k < temp.length() - 1; k++) {
                if (temp[k] == (char)('a' + i)) {
                    ca.pb((char)('a' + i));
                } else if (temp[k + 1] == (char)('a' + i)) {
                    ca.pb((char)('a' + i));
                } else {
                    ca.pb(temp[k]);
                }
            }
            tcount++;
            temp = ca;
        }
        chmin(out, tcount);
    }
    cout << out << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
int N;
int W[100];
int s[101];
int main(){
  int i, j, k, res=1073709056;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      rd(W[Lj4PdHRW]);
    }
  }
  for(i=0;i<N;i++){
    s[i+1] = s[i] + W[i];
  }
  for(i=0;i<N+1;i++){
    k = (s[N] - s[i]) - (s[i] - s[0]);
    if(k < 0){
      k = -k;
    }
    chmin(res, k);
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190609-2 [beta]

// --- original code ---
// int N, W[100];
// int s[101];
// {
//   int i, j, k, res = int_inf;
// 
//   rd(N,W(N));
//   rep(i,N) s[i+1] = s[i] + W[i];
// 
//   rep(i,N+1){
//     k = (s[N] - s[i]) - (s[i] - s[0]);
//     if(k < 0) k = -k;
//     res <?= k;
//   }
// 
//   wt(res);
// }


Measured memory_bytes: 256
S = input()
T = input()
dic1={}
dic2={}
for i in range(len(S)):
    s = S[i]
    t = T[i]
    if s!=t:
        if (s not in dic1) and (t not in dic2):
            dic1[s]=t
            dic2[t]=s
        elif (s in dic1) and (t in dic2):
            if dic1[s]!=t:
                print('No')
                break
            else:
                continue
        else:
            print('No')
            break
    else:
        dic1[s]=t
        dic2[t]=s
else:
    print('Yes')

Measured memory_bytes: 3632
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)


int main(){
	long long x;
	cin >> x;
	
	long long i=100;
	long long ans = 0;
	while(x > i){
		i = (long long)(i *1.01);
		ans++;
	}
	
	cout << ans << endl; 
	
	
	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	vector<int> a(3);
	for (int i = 0; i < 3; i++) {
		cin >> a[i];
	}

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

		if (a[0] == a[1]) {
			if (a[1] == a[2]) {
				cout << "No" << endl;
			}
			else {
				cout << "Yes" << endl;
			}
		}
		else if (a[1] == a[2]){
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}

}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
long long a[100001],dp[100001],i,j,n,k;
long long cal(long long i)
{
    if (i>=n) return 0;
    if (dp[i]!=-1) return dp[i];
    else dp[i]=0;
    if (i+2<=n) dp[i]=min(cal(i+1)+abs(a[i+1]-a[i]),cal(i+2)+abs(a[i+2]-a[i]));
    else dp[i]=cal(i+1)+abs(a[i+1]-a[i]);
    return dp[i];
}
int main()
{
    cin>>n;
    for (i=1;i<=n;i++)
    {
        //scanf("%d",&a[i]);
        cin>>a[i];
        dp[i]=-1;
    }
    //printf("%d", cal(1));
    cout<<cal(1);
}


Measured memory_bytes: 3328
k , s = gets.chomp.split(" ").map(&:to_i)
count = 0
(0..k).each do |i|
    (0..k).each do |e|
        z = s - i - e
        if z >= 0 && i + e + z == s && z <= k
            count += 1
        end
    end
end
puts count


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

using namespace std;

struct cons {
    int a;
    int b;
    int c;
    int d;
    cons(int a,int b,int c,int d) : a(a),b(b),c(c),d(d) {}
};

void generator(int*,int*,int,int,int,vector<cons>);

int main()
{
    int N,M,Q;
    cin>>N>>M>>Q;
    vector<cons> V;

    for(int i=0;i<Q;i++){
        int a,b,c,d;cin>>a>>b>>c>>d;
        V.push_back(cons(a,b,c,d));
    }

    int *ans; ans=new int[1]; ans[0]=0;
    int A[N];
    generator(ans,A,0,N,M,V);

    cout << *ans << endl;

    return 0;
}

int check(int *A, vector<cons> V)
{
    int tmp=0;
    for(auto iter : V){
        if((A[iter.b-1]-A[iter.a-1])==iter.c){
            tmp += iter.d;
        }
    }
    //cout << tmp << endl;
    return tmp;
}

void generator(int *ans,int *A, int i, int N, int M, vector<cons> V)
{
    if(i==0){
        for(int j=1;j<=M;j++){
            A[i]=j;
            generator(ans,A,i+1,N,M,V);
        }
    }else if(i==N-1){
        for(int j=A[i-1];j<=M;j++){
            A[N-1]=j;

            int tmp = check(A,V);
            if(tmp > *ans){
                *ans = tmp;
            }
        }
    }else{
        for(int j=A[i-1];j<=M;j++){
            A[i]=j;
            generator(ans,A,i+1,N,M,V);
        }
    }
}

Measured memory_bytes: 3612
import math

a, b, n = list(map(int, input().split()))

m = 0
x = n

while x >= n-b:
    if m > (a*x) // b:
        break
    else:
        y =  math.floor((a * (x / b - math.floor(x / b))))
        if m < y:
            m = y
            x = b * math.floor(x / b) - 1
        else:
            x-=1  

print(m)

Measured memory_bytes: 9116
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int n,m; cin >> n >> m;
  Graph g(n);
  vector<P> p(m);
  int a, b;
  REP(i,m) {
    cin >> a >> b; a--; b--;
    p[i] = {a, b};
    g[a].push_back(b);
    g[b].push_back(a);
  }

  int ans = 0;
  REP(i,m) {
    queue<int> q;
    vector<int> visited(n, 0);
    const auto push = [&](int next){
      if (visited[next]) return;
      q.push(next); visited[next] = 1;
    };
    push(0);
    while(!q.empty()) {
      int v = q.front(); q.pop();
      for(auto nv : g[v]) {
        if (make_pair(v,nv) == p[i] || make_pair(nv,v) == p[i]) continue;
        push(nv);
      }
    }
    int add = false;
    REP(j,n) if (!visited[j]) add = true;
    if (add) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;
int		n, m, q;
vector<int> a, b, c, d;
int ans;

void	dfs(vector<int> A)
{
	if ((int)A.size() == n + 1) {
		int now = 0;
		rep(i, q) {
			if (A[b[i]] - A[a[i]] == c[i])
				now += d[i];
		}
		chmax(ans, now);
		return;
	}
	A.push_back(A.back());
	while(A.back() <= m) {
		dfs(A);
		A.back()++;
	}
}

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

	cin >> n >> m >> q;
	a = b = c = d = vector<int>(q);
	rep(i, q) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	}
	dfs(vector<int>(1, 1));
	cout << ans << endl;
}


Measured memory_bytes: 3660
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iterator>
#include <regex>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT* delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

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

int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int ans = 1e9;
  REP(i,1,n/2+1) {
    ans = min(ans, sum(i) + sum(n-i));
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#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());

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

  string s; cin >> s;
  int n = s.size();
  int ans1 = 0;
  int ans2 = 0;
  rep(i, n) {
    if ((i&1) ^ (s[i] == '0')) {
      ans1++;
    } else {
      ans2++;
    }
  }
  cout << min(ans1, ans2) << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <string>
#include <numeric>
#include <algorithm>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <complex>
#include <ctime>
#define ll long long
#define inf 0x3f3f3f3f
#define N 100010
#define int long long
//ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

signed main(){
	int n,a=0,ans=0;
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
    {
        int x;
        scanf("%lld",&x);
        ans+=max(0LL,a-x);
        a=x+max(0LL,a-x);
    }
    printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, l, r) for (int i = l; i <= (int)(r); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define all(v) v.begin(), v.end()
#define MOD (int) (1e9+7)
#define INF (int) 1e9
#define LLINF (ll) 1e18

int main(){
    ll n, d;
    cin >> n >> d;
    int ans = 0;
    rep(i, n){
        ll x, y;
        cin >> x >> y;
        if( x*x + y*y <= d*d) ans++;
    }
    cout << ans << endl;
    // printf("%d\n", N);
    return 0;
}

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

int S[500000];
int n;
int cnt;

void merge(int l, int m, int r){
    int n1 = m - l;
    int n2 = r - m;
    int *L = (int *)malloc(sizeof(int)*(n1+1));
    int *R = (int *)malloc(sizeof(int)*(n2+1));
    for(int i=0; i<n1; i++)
        L[i] = S[l+i];
    for(int i=0; i<n2; i++)
        R[i] = S[m+i];
    L[n1] = INT_MAX;
    R[n2] = INT_MAX;
    int i = 0, j = 0;
    for(int k = l; k < r; k++){
        if(L[i] <= R[j]){
            S[k] = L[i];
            i++;
        }else{
            S[k] = R[j];
            j++;
        }
        cnt++;
    }
    free(L);
    free(R);
}

void mergesort(int l, int r){
    if(l + 1 < r){
        int m = (l + r) / 2;
        mergesort(l, m);
        mergesort(m, r);
        merge(l, m, r);
    }
}

int main(){
    cin >> n;
    for(int i=0; i<n; i++)
        cin >> S[i];
    mergesort(0, n);
    for(int i=0; i<n-1; i++){
        cout << S[i] << ' ';
    }
    cout << S[n-1] << endl;
    cout << cnt << endl;
}

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

long long gcd(long long a,long long b){
  if (a%b==0 )return b;
  else return gcd(b,a%b);
}
int main() {
  long long a,b,c; cin>>a>>b>>c;
  
  if(c-(a-b)>0)cout<<c-(a-b)<<endl;
  else cout<<0<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int n;
vector< vector<int> > v;
vector<int> day, deg;
int f(int a, int b){
    int res = n*(n-1)/2;
    if(a > b){
        int t = a;
        a = b;
        b = t;
    }
    return n*(a-1) - (a-1)*a/2 + b - a - 1;
}
int main(void){
    int m, ans = 0;
    queue<int> q;
    cin >> n;
    m = n*(n-1)/2;
    v.assign(m, vector<int>());
    day.assign(m, 1);
    deg.assign(m, 0);
    for(int i=1;i<=n;i++){
        int b;
        cin >> b;
        for(int j=0;j<n-2;j++){
            int a;
            cin >> a;
            v[f(i, b)].push_back(f(i, a));
            deg[f(i, a)]++;
            b = a;
        }
    }

    for(int i=0;i<m;i++){
        if(deg[i] == 0){
            q.push(i);
        }
    }

    while(!q.empty()){
        int x = q.front(); q.pop();
        m--;
        for(int i=0;i<v[x].size();i++){
            int y = v[x][i];
            if(--deg[y] <= 0){
                q.push(y);
            }
            ans = max(ans, day[y] = max(day[y], day[x] + 1));
        }
    }
    if(m > 0)ans = -1;
    cout << ans << endl;
}


Measured memory_bytes: 31488
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	k, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return k
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

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

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(k int) bool {
		return a[k] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(k int) bool {
		return a[k] > x
	})
	return idx
}

const mod = 998244353

// func mpow(n, p int) int {
// 	if n == 0 {
// 		return 0
// 	}
// 	ret := 1
// 	x := n
// 	for p > 0 {
// 		if p%2 == 1 {
// 			ret *= x
// 			ret %= mod
// 		}
// 		x *= x
// 		x %= mod
// 		p /= 2
// 	}
// 	return ret
// }
func mpow(a, b int) int {
	if b == 0 {
		return 1
	} else if b%2 == 0 {
		tmp := mpow(a, b/2)
		return tmp * tmp % mod
	}
	return mpow(a, b-1) * a % mod
}

var fact [maxval]int
var ifact [maxval]int

func nCk(n, k int) int {
	if n < k || k < 0 {
		return 0
	}
	ret := (fact[n] * ifact[k]) % mod
	ret *= ifact[n-k]
	ret %= mod
	return ret
}

const maxval = 220000

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

	fact[0] = 1
	for k := 1; k < maxval; k++ {
		fact[k] = (k * fact[k-1]) % mod
	}
	ifact[maxval-1] = mpow(fact[maxval-1], mod-2)
	for k := maxval - 2; k >= 0; k-- {
		ifact[k] = ((k + 1) * ifact[k+1]) % mod
	}

	N, M, K := getInt(), getInt(), getInt()

	ans := 0
	for k := 0; k <= K; k++ {
		if N < k {
			break
		}
		x := M * mpow(M-1, N-1-k)
		x %= mod
		x *= nCk(N-1, k)
		x %= mod
		ans += x
		ans %= mod
	}

	out(ans)
}


Measured memory_bytes: 5212
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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 n,m,k;
    cin >> n >> m >> k;
    vector<ll> a(n+1,0);
    repp(i,1,n+1){
        cin >> a[i];
        a[i] += a[i-1];
    }
    vector<ll> b(m+1,0);
    repp(i,1,m+1){
        cin >> b[i];
        b[i] += b[i-1];
    }
    ll b_pos = m;
    ll res = 0;
    rep(i,n+1){
        if(a[i] > k)break;
        while(b[b_pos] > k - a[i])b_pos--;
        res = max(res, i + b_pos);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 6432
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <string>
#include <limits>
#include <numeric>
#include <type_traits>

using namespace std;
#define ll long long int

int main(){
  string s;
  cin >> s;
  int n = s.length();
  int num_o = 0,num_z = 0;
  for(int i = 0; i < n; ++i){
    if( s[i] == '1' ) ++num_o;
    else ++num_z;
  }
  int ans = n - abs( num_o - num_z);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1144
package main

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

func main() {
	var h, w, a, b int
	fmt.Scan(&h, &w, &a, &b)

	wr := bufio.NewWriter(os.Stdout)
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if (i+1 <= b && j+1 <= a) || (i+1 > b && j+1 > a) {
				wr.WriteString("1")
				continue
			}
			wr.WriteString("0")
		}
		wr.WriteString("\n")
	}
	wr.Flush()
}


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

int main(){
    ll N;
    cin>>N;
    vector<ll> A(N);
    rep(i,N)cin>>A[i];
    ll res=0;
    rep(i,N){
       if((i+1)%2!=0 && A[i]%2 !=0)++res;
    }
    cout<<res;
    return 0;
}

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

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

  for(int i = 0; i < 10e100; i++) {
    int t = 0;
    for(int j = 2; j < x; j++) {
      if(x % j == 0) {
        t++;
        break;
      }
    }
    if(t <= 0) {
      cout << x << endl;
      return 0;
    }
    x++;
  }
}

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

using namespace std;

typedef long long int64;

int main()
{
  int N;
  int64 T[100];

  cin >> N;
  for(int i = 0; i < N; i++) cin >> T[i];

  int64 gcd = 1;
  for(int i = 0; i < N; i++) {
    gcd = T[i] / __gcd(T[i], gcd) * gcd;
  }

  cout << gcd << endl;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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; }
// ---------------------------------------------------------------------------

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};




int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H,W,A,B;
    cin >> H >> W >> A >> B;
    mint ans = 0;
    combination c(H+W);
    for(int i=B+1; i<=W; i++){
        ans += c(H-(A+1)+i-1,i-1) * c(A-1+W-i,W-i);
    }
    cout << ans.x << "\n";
    return 0;
}

Measured memory_bytes: 6328
#include <iostream>

int main(int argc, char const *argv[]) {
    int a, b;
    std::cin >> a;
    std::cin >> b;

    if (a < b) {
        std::cout << "a < b" << std::endl;
    }else if (a > b) {
        std::cout << "a > b" << std::endl;
    }else if (a == b) {
        std::cout << "a == b" << std::endl;
    }

    return 0;
}

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

    int n;
    int[] di;
    int[] tetra;

    void run(){
	di = new int[4000+1];
	tetra = new int[4000+1];
	setDi();
	setTetra();
	while(sc.hasNext()){
	    n = sc.nextInt();
	    System.out.println(tetra[n]);
	}
    }

    void setDi(){
	for(int i=0; i<=1000; i++)
	    for(int k=0; k<=1000; k++)
		di[i+k]++;
    }

    void setTetra(){
	for(int i=0; i<di.length; i++)
	    for(int k=0; k<di.length; k++)
		if(i+k<tetra.length)
		    tetra[i+k] += di[i]*di[k];
    }
}
	    

Measured memory_bytes: 19596
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bitset>
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

const int maxN = 1e5 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b) {return !b ? a : gcd(b, a % b);}
ll sq(ll x) {return (x * x) % MOD;}
ll modP(ll a, ll b) {return (!b ? 1 : (sq(modP(a, b / 2)) * (b % 2 ? a : 1)) % MOD);}

vector <pii> G[maxN];
ll cnt[maxN], dis[maxN];
set <pll> S;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	memset(dis, 63, sizeof dis);
	int n, m; cin >> n >> m;
	while (m--){
		int l, r, c; cin >> l >> r >> c;
		G[l].push_back({r, c});
		cnt[r]--; cnt[l--]++;
	}
	for (int i = 0; i < n; i++){
		cnt[i + 1] += cnt[i];
		if (cnt[i + 1] > 0) G[i + 1].push_back({i, 0});
	}
	dis[1] = 0;
	S.insert({0, 1});
	while (!S.empty()){
		int v = (*S.begin()).second;
		S.erase(S.begin());
		for (auto pp : G[v]){
			int u = pp.first;
			int w = pp.second;
			if (dis[u] > dis[v] + w){
				dis[u] = dis[v] + w;
				S.insert({dis[u], u});
			}
		}
	}
	cout << (dis[n] > INF ? -1 : dis[n]) << endl;
	return 0;
}
 



Measured memory_bytes: 10880
#include <bits/stdc++.h>
#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()
using namespace std;
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n; cin >> n;
  int k = 1;
  while(k*(k+1)/2 < n) k++;
  int sub =k*(k+1)/2 - n;
  REP(i,k){
    if(i+1==sub) continue;
    cout << i+1 << '\n';
  }

  return 0;
}


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

int main(){
  int n, m;
  cin >> n >> m;
  int road[50][2] = {};//m
  int result[50] = {};//n

  for(int i = 0; i < m; i++){
    cin >> road[i][0] >> road[i][1];
  }
  for(int j = 0; j < m; j++){
    result[road[j][0]-1]++;
    result[road[j][1]-1]++;
  }
  for(int i = 0; i < n; i++){
    cout << result[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
h, w = map(int,input().split())
# In[]
s = [list(input()) for _ in range(h)]
dx = [0,1,0,-1]
dy = [1,0,-1,0]

count = 0

for y in range(h):
    for x in range(w):
        cnt = 0
        for k in range(4):
            ny = y + dy[k]
            nx = x + dx[k]
            if nx < 0 or nx>=w or ny < 0 or ny >=h:
                continue
            if s[y][x] == '.':
                cnt +=1
                continue
            if s[y][x] == '#':
                if s[ny][nx] == '#':
                    cnt += 1
        if cnt == 0:
            print('No')
            exit()

                        
print('Yes')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define de(a) cout<<#a<<" = "<<a<<endl
typedef unsigned us;
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

const int N=100005;

int a,b,c,d,e,f,ans1,ans2;

int main(){
	scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
	rep(i,0,31) 
		rep(j,0,31)
			rep(k,0,3001) if (a*i*100+b*j*100+c*k<=f && (a*i+b*j)*e>=c*k)
				rep(l,0,3001) {
					if (a*i*100+b*j*100+c*k+d*l<=f && (a*i+b*j)*e>=c*k+d*l){
						if ((ans1==0 && ans2==0) ||(c*k+d*l)*(ans2)>ans1*(a*i+b*j)) {
			//				de(i);de(j);de(k);de(l);
							ans1=c*k+d*l;	
							ans2=a*i+b*j;
						}
						
					}else break;
					
				}else break;
	printf("%d %d",ans2*100+ans1,ans1);
	
}

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

using namespace std;

int n, a, b;

int ans[1 << 17];

inline void Solve (int n, int a, int b, int l, int r) {
	if (n == 1) { ans[l] = a, ans[r] = b; return; }
	int mid = (l + r) >> 1, x;
	for (x = 0; x < n; ++x) if (((a >> x) & 1) != ((b >> x) & 1)) break;
	int xa = (a >> (x + 1) << x) | (a & ((1 << x) - 1));
	int xb = (b >> (x + 1) << x) | (a & ((1 << x) - 1));
	Solve (n - 1, xa, xa ^ 1, l, mid);
	Solve (n - 1, xa ^ 1, xb, mid + 1, r);
	for (int i = l; i <= mid; ++i) ans[i] = (ans[i] >> x << (x + 1)) | (ans[i] & ((1 << x) - 1)) | (a & (1 << x));
	for (int i = mid + 1; i <= r; ++i) ans[i] = (ans[i] >> x << (x + 1)) | (ans[i] & ((1 << x) - 1)) | (b & (1 << x));
}

int main () {
	scanf ("%d%d%d", &n, &a, &b);
	
	int numa = 0, numb = 0;
	for (int i = 0; i < n; ++i) {
		if ((a >> i) & 1) ++numa;
		if ((b >> i) & 1) ++numb;
	}
	if ((numa & 1) == (numb & 1)) { printf ("NO\n"); return 0; }
	
	Solve (n, a, b, 0, (1 << n) - 1);
	
	printf ("YES\n");
	for (int i = 0; i < (1 << n); ++i) printf ("%d%c", ans[i], " \n"[i == (1 << n) - 1]);
	
	return 0;
}

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

typedef long long ll;

const ll INF = 1e18;

using namespace std;

ll n, a[20];

ll calc(int l, int xl, int r, int xr)
{
    ll ans = INF;
    if (l + 1 == r)
    {
        return 0;
    }
    int xk = xl + xr;
    for (int k = l + 1; k < r; k++)
    {
        ans = min(ans, calc(l, xl, k, xk) + a[k] * xk + calc(k, xk, r, xr));
    }
    return ans;
}

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    cout << a[0] + calc(0, 1, n - 1, 1) + a[n - 1];
}


Measured memory_bytes: 384
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int r, g, b, n;
    cin >> r >> g >> b >> n;
    int ans = 0;
    rep(i, n+1) rep(j, n+1) {
        if ( n - i * r - j * g < 0 ) continue;
        if ( ( n - i * r - j * g ) % b == 0 ) {
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}


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

typedef long long int ll;

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

ll lcm2(ll a, ll b) {
    ll d = gcd(a, b);
    return a / d * b;
}

ll lcm(const vector<ll> &v) {
    ll l = v[0];
    for (int i = 0; i < v.size() - 1; i++) {
        l = lcm2(l, v[i + 1]);
    }
    return l;
}

int main() {
    ll n = 0, m = 0;
    ll a[100000];
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> a[i];

    vector<ll> v;
    for (int i = 0; i < n; i++) {
        v.push_back(a[i] / 2);
    }

    ll l = lcm(v);
    
    for (int i = 0; i < n; i++) {
        if ((l / (a[i] / 2)) % 2 == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    if (l > m) cout << 0 << endl;
    else if ((m / l) % 2 != 0) cout << (m / l) / 2 + 1 << endl;
    else cout << (m / l) / 2 << endl;
}

Measured memory_bytes: 2168
#include<stdio.h>
  #define NUMBER 10000
  int main(void){
      int a,b,d,r;
      double f;
      scanf("%d %d",&a,&b);
      d=a/b;
      r=a%b;
      f=a/(double)b;
      printf("%d %d %.5f\n",d,r,f);
      return 0;
  }


Measured memory_bytes: 2132
def ball(nums):
    b, c = 0, 0
    for i in range(len(nums)):
        if b < nums[i]:
            b = nums[i]
            continue
        if c < nums[i]:
            c = nums[i]
            continue
        return "NO"
    return "YES"

N = int(input())

for _ in range(N):
    a = list(map(int, input().split()))
    print(ball(a))

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

//-----------------------------------LIBRARY OF INPUT-----------------------------------
void reader(int *x) {
	int k = getchar_unlocked(); *x = k - '0';
	while (true) {
		k = getchar_unlocked();
		if (k < '0' || k > '9') break;
		*x = ((*x) << 1) + ((*x) << 3) + k - '0';
	}
}

int n, m, q, dist[110003], mark[110003], u[210003], v[210003];
vector<pair<int, int>>x[110003], y[110003], z[110003]; bool used[210003];
inline bool isgood(int f) {
	for (int i = 0; i < z[f].size(); i++) {
		if (mark[z[f][i].first] == 0 && used[z[f][i].second] == false)return true;
	}
	return false;
}
int main() {
	reader(&n); reader(&m); reader(&q); queue<int>Q;
	for (int i = 0; i < m; i++) {
		int a = 0, b = 0;
		reader(&a);
		reader(&b);
		u[i + 1] = a; v[i + 1] = b;
		x[a].push_back(make_pair(b, i + 1)); x[b].push_back(make_pair(a, i + 1));
	}
	Q.push(1); for (int i = 1; i <= n; i++)dist[i] = 999999; dist[1] = 0;
	while (!Q.empty()) {
		int a1 = Q.front(); Q.pop();
		for (int i = 0; i < x[a1].size(); i++) {
			if (dist[x[a1][i].first] > dist[a1] + 1) { dist[x[a1][i].first] = dist[a1] + 1; Q.push(x[a1][i].first); }
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < x[i].size(); j++) {
			if (dist[i] < dist[x[i][j].first]) { y[i].push_back(x[i][j]); }
			if (dist[i] > dist[x[i][j].first]) { z[i].push_back(x[i][j]); }
		}
	}
	int cnt = 0;
	for (int i = 0; i < q; i++) {
		int a = 0;
		reader(&a);
		used[a] = true;
		int E1 = u[a], E2 = v[a];
		if (dist[E1] == dist[E2]) { cnt += 0; }
		else {
			int a1 = 0; if (dist[E1] < dist[E2])a1 = E2; else a1 = E1;
			if (mark[a1] == 0 && isgood(a1) == false) {
				queue<int>Q; Q.push(a1); cnt++; mark[a1] = 1;
				while (!Q.empty()) {
					int a2 = Q.front(); Q.pop();
					for (int j = 0; j < y[a2].size(); j++) {
						if (mark[y[a2][j].first] == 0 && isgood(y[a2][j].first) == false) {
							mark[y[a2][j].first] = 1; Q.push(y[a2][j].first); cnt++;
						}
					}
				}
			}
		}
		printf("%d\n", cnt);
	}
	return 0;
}

Measured memory_bytes: 25544
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MP make_pair
#define pb push_back
#define F first
#define S second
#define pii pair<int,int>
#define REP(i,a,b) for(int i=a; i<b; i++)

const int MX=1e2+3;

ll n, k, dp[MX], p[MX], ans;

void pre();

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>k;
	pre();
	while(k){
		if(k>=dp[n]){
			ans+=p[n], k=0;
			break;
		}
		else if(k-1<dp[n-1]){
			n--, k--;
			continue;
		}
		else if(k==dp[n-1]+1){
			ans+=p[n-1];
			k=0;
			break;
		}
		else{
			ans+=p[n-1]+1;
			k-=dp[n-1]+2;
			n--;
		}
	}
	cout<<ans<<endl;
	return 0;
}

void pre(){
	dp[0]=p[0]=1;
	REP(i,1,n+1) p[i]=p[i-1]*2+1, dp[i]=dp[i-1]*2+3;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

const int MAX_N = 212345;
vector<int> g[MAX_N];
int memo[MAX_N];
int ans[MAX_N];

int main2() {
  REP(i, MAX_N) g[i].clear();

  int N = nextInt();
  int M = nextInt();

  REP(i, M) {
    int a = nextInt() - 1;
    int b = nextInt() - 1;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  REP(i, MAX_N) memo[i] = 1001001001;
  queue<int> q;
  q.push(0);
  memo[0] = 0;
  while (!q.empty()) {
    int cur = q.front(); q.pop();
    for (int nxt : g[cur]) {
      if (memo[nxt] > memo[cur] + 1) {
        memo[nxt] = memo[cur] + 1;
        ans[nxt] = cur;
        q.push(nxt);
      }
    }
  }
  cout << "Yes" << endl;
  for (int i = 1; i < N; i++) {
    cout << (1 + ans[i]) << endl;
  }
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

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

using namespace std;

int main() {
  string S(4,'a');
  cin >> S;

  char c = S[0];
  for (int i = 1; i < 4; i++) {
    if (S[i] == c) {
      cout << "Bad" << endl;
      return 0;
    } else {
      c = S[i];
    }
  }

  cout << "Good" << endl;

  return 0;
}


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

int main(){
	int s;
	cin >> s;
	int a[MAX + 1] = {};
	a[1] = s;
	for(int i = 2; ; i++){
		if(a[i - 1] % 2 == 0) a[i] = a[i - 1] / 2;
		else a[i] = 3 * a[i - 1] + 1;
		REP(j,i){
			if(a[i] == a[j]){
				cout << i << endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 4096
A,B,C,K = map(int,input().split())

ans = 0
if K > A:
  ans += A
  K -= A
  if K > B:
    ans += 0
    K -= B
    if K > 0:
      ans -= K
  else:
    ans += 0
else:
  ans = K
  
print(ans)

Measured memory_bytes: 9100
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
from itertools import accumulate, product
 
N, W = inpl()
A = []
for _ in range(N):
    A.append(inpl())
B = [[] for _ in range(4)]
w1 = A[0][0]
 
for w, v in A:
    B[w-w1].append(v)
 
B = [sorted(b, reverse=True) for b in B]
C = [[0] + list(accumulate(b)) for b in B]
 
res = 0

for L in product(enumerate(C[0]),
                 enumerate(C[1]),
                 enumerate(C[2]),
                 enumerate(C[3])):
    if sum([(w1+i)*l[0] for i, l in enumerate(L)]) <= W:
        res = max(res, sum([l[1] for l in L]))

print(res)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");

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

  vector<int> graph(n + 1);
  vector<int> visit_nums;
  vector<bool> visit(n + 1);
  rep(i, n) {
    int a;
    cin >> a;
    graph[i + 1] = a;
  }

  int idx = 0;
  for (int i = 1; i <= k; i++) {
    if (i == 1) {
      visit[1] = true;
      visit_nums.push_back(1);
      idx = graph[1];
    } else {
      visit[idx] = true;
      visit_nums.push_back(idx);
      idx = graph[idx];
    }

    if (visit[idx] == true) {
      ////ringBuffer
      //cout << "i=" << i << endl;
      //cout << "idx=" << idx << endl;
      //cout << "graph[idx]=" << graph[idx] << endl;
      auto start_iter = find(visit_nums.begin(), visit_nums.end(), idx);
      visit_nums.erase(visit_nums.begin(), start_iter);
      int ans_idx = (k - i) % visit_nums.size();

      cout << visit_nums[ans_idx] << endl;
      return 0;
    }
  }

  cout << idx << endl;
  return 0;
}


Measured memory_bytes: 5132
n = gets.to_i
break_flag = 0
first_word = gets.chomp
word_list = []
word_list.push(first_word)
last_letter = first_word[first_word.length - 1]
i = 1
while i < n
  w = gets.chomp
  if last_letter != w[0]
      break_flag = 1
  end
  last_letter = w[w.length - 1]
  word_list.push(w)
  i += 1
end
if word_list.size != word_list.uniq.size || break_flag == 1
  puts "No"
else
  puts "Yes"
end

Measured memory_bytes: 14360
#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#a,bの最小公倍数
def lcm(a, b):
    return a // gcd (a, b) * b

n = int(input())
ans = int(input())
for _ in range(n-1):
    t = int(input())
    ans = lcm(t, ans)

print(ans)





    

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

class Line{
	public:
		int h;	//高さ
		int p;	//接点1
		int q;	//接点2
		
};


int comp(const void* a, const void* b){
	Line * aa = (Line*)a;
	Line * bb = (Line*)b;
	return ((bb->h) - (aa->h));
}

int main(){
	int n;	//縦線本数
	int m;	//横線本数
	int a;	//調べる縦線

	while (1){
		cin >> n >> m >> a;

		if (n == 0 && m == 0 && a == 0){
			break;
		}

		Line* lines = new Line[m];
		for (int i = 0; i < m; i++){
			cin >> lines[i].h >> lines[i].p >> lines[i].q;
		}

		qsort(lines, m, sizeof(Line), comp);

		for (int i = 0; i < m; i++){
			if (a == lines[i].p){
				a = lines[i].q;
			}
			else if (a == lines[i].q){
				a = lines[i].p;
			}
		}

		cout << a << endl;
	}

	return 0;
}

Measured memory_bytes: 1748
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		List<Integer> mList = new ArrayList<Integer>();
		int en, n;
		
		n = sc.nextInt();
		en = sc.nextInt();
		while(n != 0 || en != 0) {
			mList.clear();
			for(int i = 0; i < n; i++) {
				mList.add(sc.nextInt());
			}
			
			mList.sort(new Comparator<Integer>() {
				@Override
				public int compare(Integer o1, Integer o2) {
					return o2 - o1;
				}
			});
			
			int count = 0;
			for(int i = 0; i < mList.size() - 1; i++) {
				for(int j = i + 1; j < mList.size(); j++) {
					if(mList.get(i) + mList.get(j) <= en) {
						break;
					}
					count++;
				}
			}
			
			System.out.println(count);
			
			n = sc.nextInt();
			en = sc.nextInt();
		}
	}
}

Measured memory_bytes: 74240
/* C++14 (Clang 3.8.0) for AtCoder */

#include <iostream>
#include <vector>
#include <string>
// #include <cmath>
// #include <math.h>
// #include <map>
// #include <algorithm>

namespace AtCoder {
	using Str = std::vector<std::string>;
	using Num = std::vector<int>;
	using BigNum = std::vector<long long>;
	using DecNum = std::vector<double>;

	class InputData {
	public:
		void getInput(void);
		void skipInput(void);
		Str getStr(void);
		Num getNum(void);
		BigNum getBigNum(void);
		DecNum getDecNum(void);
	private:
		Str str;
		Num num;
		BigNum bNum;
		DecNum dNum;
	};
	Str AtCoder::InputData::getStr(void) {
		return this->str;
	}
	Num AtCoder::InputData::getNum(void) {
		return this->num;
	}
	BigNum AtCoder::InputData::getBigNum(void) {
		return this->bNum;
	}
	DecNum AtCoder::InputData::getDecNum(void) {
		return this->dNum;
	}
	void AtCoder::InputData::skipInput(void) {
		std::string buf = "";
		std::getline(std::cin, buf);
	}
	void AtCoder::InputData::getInput(void) {
		this->str.clear();
		this->num.clear();
		this->bNum.clear();
		this->dNum.clear();

		std::string buf = "", row = "";
		std::getline(std::cin, buf);
		for (unsigned int i = 0; i < buf.size(); i++) {
			if (' ' == buf[i]) {
				this->str.push_back(row);
				this->num.push_back(std::atoi(row.c_str()));
				this->bNum.push_back(std::atoll(row.c_str()));
				row = "";
			} else {
				row += buf[i];
			}
		}
		this->str.push_back(row);
		this->num.push_back(std::atoi(row.c_str()));
		this->bNum.push_back(std::atoll(row.c_str()));
		this->dNum.push_back(std::atof(row.c_str()));
	}

	class Ans {
	public:
		void showResult(void);
		void increment(void);
		void increment(long long);
		void decrement(void);
		void decrement(long long);
		long long getResult(void);
	private:
		long long result;
	};
	void Ans::showResult(void) {
		printf("%lld\n", this->result);
	}
	void AtCoder::Ans::increment(void) {
		this->result++;
	}
	void AtCoder::Ans::increment(long long value) {
		this->result += value;
	}
	void AtCoder::Ans::decrement(void) {
		this->result--;
	}
	void AtCoder::Ans::decrement(long long value) {
		this->result -= value;
	}
	long long AtCoder::Ans::getResult(void) {
		return this->result;
	}

	void exp(std::string* str,  Str* newStr) {
		std::string pre = *str;
		newStr->clear();
		for (unsigned int i = 0; i < pre.length(); i++) {
			newStr->push_back(pre.substr(i, 1));
		}
	}
}

int main(void) {

	AtCoder::InputData* data = new AtCoder::InputData();
	// data->skipInput();
	data->getInput();

	AtCoder::Num num = data->getNum();
	
	const int N = num[0];

	std::vector<bool> f;

	for (int i = 0; i < N; i++) {
		data->getInput();
		num = data->getNum();
		if (num[0] == num[1]) {
			f.push_back(true);
		} else {
			f.push_back(false);
		}
	}

	bool ans = false;

	for (int i = 2; i < N; i++) {
		if (f[i - 2] && f[i - 1] && f[i]) {
			ans = true;
			break;
		}
	}

	if (ans) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}

	delete(data);

	return 0;
}


Measured memory_bytes: 3200