akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int h, w, n;

void fall(vector<string>& field) {
	for(int j = 0; j < w; ++j) {
		for(int i = 1; i < h; ++i) {
			if(field[i][j] == '.') {
				int k = 1;
				while(i - k >= 0 && field[i - k][j] != '.') {
					swap(field[i - k][j], field[i - k + 1][j]);
					++k;
				}
			}
		}
	}
}

void simulate(vector<string>& field) {
	fall(field);

	while(true) {
		bool update = false;
		vector<vector<bool> > remove(h, vector<bool>(w, false));
		for(int i = 0; i < h; ++i) {
			for(int j = 0; j < w - n + 1; ++j) {
				if(field[i][j] == '.')
					continue;

				for(int k = 1; k < n; ++k)
					if(field[i][j + k] != field[i][j])
						goto ng_horizontal;

				update = true;
				for(int k = 0; k < n; ++k)
					remove[i][j + k] = true;

			ng_horizontal:;
			}
		}

		for(int j = 0; j < w; ++j) {
			for(int i = 0; i < h - n + 1; ++i) {
				if(field[i][j] == '.')
					continue;
				
				for(int k = 1; k < n; ++k)
					if(field[i + k][j] != field[i][j])
						goto ng_vertical;
				
				update = true;
				for(int k = 0; k < n; ++k)
					remove[i + k][j] = true;
				
			ng_vertical:;
			}
		}

		if(!update)
			break;

		for(int i = 0; i < h; ++i)
			for(int j = 0; j < w; ++j)
				if(remove[i][j])
					field[i][j] = '.';

		fall(field);
	}
}

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

	cin >> h >> w >> n;

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

	vector<string> success(h, string(w, '.'));
	
	for(int i = 0; i < h; ++i) {
		for(int j = 0; j < w - 1; ++j) {
			vector<string> tmp(field);
			swap(tmp[i][j], tmp[i][j + 1]);
			simulate(tmp);
			if(tmp == success) {
				cout << "YES" << endl;
				return EXIT_SUCCESS;
			}
		}
	}

	cout << "NO" << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1232
using System;
using System.Collections.Generic;

public class CSharp
{
    public static void Main()
    {
        Kyopuro chokudai = new Kyopuro();
        chokudai.AtCoder();
    }
}

public class Kyopuro
{
    public void AtCoder()
    {
        string[] s;
        s = Console.ReadLine().Split(' ');

        int h, w;
        h = int.Parse(s[0]);
        w = int.Parse(s[1]);

        int[][] x = new int[h + 2][];
        x[0] = new int[w + 2];
        x[h + 1] = new int[w + 2];

        var p = new List<int>();
        var q = new List<int>();
        var p2 = new List<int>();
        var q2 = new List<int>();

        string t;
        char c;
        for(int i=1; i<=h; i++)
        {
            x[i] = new int[w + 2];
            t = Console.ReadLine();
            for (int j = 1; j <= w; j++)
            {
                c = t[j - 1];
                if (c == '#')
                {
                    x[i][j] = 1;
                    p.Add(i);
                    q.Add(j);
                }
                else x[i][j] = -1;
            }
        }

        int[] d1 = new int[] { -1, 1, 0, 0 };
        int[] d2 = new int[] { 0, 0, -1, 1 };

        int ans = -1;
        while(p.Count > 0)
        {
            DebugWL(p.Count);
            for(int i=0; i<p.Count; i++)
            {
                for(int j=0; j<4; j++)
                {
                    if (x[p[i] + d1[j]][q[i] + d2[j]] == -1)
                    {
                        p2.Add(p[i] + d1[j]);
                        q2.Add(q[i] + d2[j]);
                        x[p[i] + d1[j]][q[i] + d2[j]] = 1;
                    }
                }
            }
            p = new List<int>();
            q = new List<int>();
            for(int i=0; i<p2.Count; i++)
            {
                p.Add(p2[i]);
                q.Add(q2[i]);
            }
            p2 = new List<int>();
            q2 = new List<int>();
            ans++;
        }
        Console.WriteLine(ans);
    }
    public static void DebugWL(object x) { System.Diagnostics.Debug.WriteLine(x); }
}


Measured memory_bytes: 40408
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

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

int main() {
    int M, D;
    cin >> M >> D;
    int count = 0;
    for (int i = 1; i <= M; i++) {
        for (int j = 2; j * 10 + 2 <= D; j++) {
            for (int k = 2; k <= 9 && j * 10 + k <= D; k++) {
                if (j * k == i) count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse4")
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
 
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(), a.end()
 
typedef long long LL;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int MAX = 1 << 18;
const int p = 200003;
const int LEN = MAX << 1;

int mult(int a, int b)
{
	return (LL)a * b % p;
}

typedef complex<double> BASE;

BASE pw[LEN];

void fft(vector<BASE>& a, bool invert)
{
	int lg = 0;
	while((1 << lg) < SZ(a))
		lg++;
	FOR(i, 0, SZ(a))
	{
		int x = 0;
		FOR(j, 0, lg)
			x |= ((i >> j) & 1) << (lg - j - 1);
		if(x < i)
			swap(a[i], a[x]);
	}
	for(int len = 2; len <= SZ(a); len <<= 1)
	{
		int diff = LEN / len;
		if(invert)
			diff = LEN - diff;
		for(int i = 0; i < SZ(a); i += len)
		{
			int pos = 0;
			FOR(j, 0, len >> 1)
			{
				BASE u = a[i + j], v = a[i + j + (len >> 1)] * pw[pos];
				a[i + j] = u + v;
				a[i + j + (len >> 1)] = u - v;
				pos += diff;
				if(pos >= LEN)
					pos -= LEN;
			}
		}
	}
	if(invert)
		FOR(i, 0, SZ(a))
			a[i] /= SZ(a);
}

void initFFT()
{
	double angle = 2 * PI / LEN;
	FOR(i, 0, LEN)
	{
		double ca = i * angle;
		pw[i] = BASE(cos(ca), sin(ca));
	}
}

vector<LL> sqr(vector<int> a)
{
	vector<BASE> A(ALL(a));
	int lg = 0;
	while((1 << lg) < 2 * SZ(a) - 1)
		lg++;
	A.resize(1 << lg);
	fft(A, false);
	FOR(i, 0, SZ(A))
		A[i] *= A[i];
	fft(A, true);
	vector<LL> res(SZ(A));
	FOR(i, 0, SZ(A))
		res[i] = (LL)(A[i].real() + 0.5);
	return res;
}

int a[MAX];
int pw2[MAX], inv[MAX];
LL ans[MAX];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	pw2[0] = 1;
	inv[1] = 0;
	FOR(i, 1, p - 1)
	{
		pw2[i] = mult(pw2[i - 1], 2);
		inv[pw2[i]] = i;
	}
	int n;
	cin >> n;
	vector<int> b(p - 1, 0);
	FOR(i, 0, n)
	{
		cin >> a[i];
		if(a[i])
		{
			b[inv[a[i]]]++;
		}
	}
	initFFT();
	auto c = sqr(b);
	while(SZ(c) > p - 1)
	{
		c[SZ(c) - p] += c.back();
		c.pop_back();
	}
	FOR(i, 0, p - 1)
	{
		ans[pw2[i]] = c[i];
	}
	FOR(i, 0, n)
		ans[mult(a[i], a[i])]--;
	LL sum = 0;
	FOR(i, 1, p)
	{
		assert(ans[i] % 2 == 0);
		sum += (ans[i] / 2) * i;
	}
	cout << sum << "\n";
	return 0;
}

Measured memory_bytes: 27976
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////

//int n;
int main(){

    ll n,m;
    cin >>n >> m;
   
    ll cnt = (m+(n-1))/n;
   
    while(1){
        if((m - cnt*(n-1)) > 0){
            if((m - cnt*(n-1))%cnt == 0){
                P(cnt);
                ret 0;
            }
        }
       
        cnt--;
    }
  

    
    /*cin >> n;
    ll x[n],y[n],h[n];
    rep(i,0,n)cin >> x[i] >> y[i] >> h[i];
    */
    
	return  0;
}

Measured memory_bytes: 256
from heapq import heappush,heappop
import queue
import re

def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, ss_raw()))

INF = 1<<29

def make1d_arr(n,val=INF):
    return [val for i in range(n)]

def make2d_arr(h,w,val =INF):
    return [[val for i in range(w)]for i in range(h)]


N = int_raw()
V = ints_raw()
C = ints_raw()


def main():
    D= [V[i]-C[i] for i in range(N)]
    return sum([d for d in D if d > 0])
    
print(main())


Measured memory_bytes: 4200
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <climits>

long table[101][100001];
long W[101];
long V[101];
long N,Wnum;

long solve(long goods, long weight)
{
    if(table[goods][weight]<0){
        if(goods==0){
            table[goods][weight]=0;
        }else{
            if(weight-W[goods]>=0){
                table[goods][weight]=std::max(solve(goods-1,weight),solve(goods-1,weight-W[goods])+V[goods]);
            }else{
                table[goods][weight]=solve(goods-1,weight);
            }
        }
    }
    return table[goods][weight]; 
}


int main()
{
    std::cin >> N >> Wnum;
    W[0]=0;V[0]=0;
    for(long i=1; i<=N; i++){
        std::cin >> W[i] >> V[i];
    }
    for(long i=0; i<101; i++){
        for(long j=0; j<100001;j++){
            table[i][j]=-1;
        }
    }
    std::cout << solve(N,Wnum) << std::endl;
    return 0;
}

Measured memory_bytes: 79104
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <numeric>
#include <cstring>
#include <cmath>
#include <set>
#include <queue>
#include <stack>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using edge = struct{int to; int cost;};

int main()
{
    //dp[i]:=長さがi+1であるような増加部分列における最終要素の最小値．
    int n, dp[1000010]; 
    cin >> n;
    vector<int> a(n);
    fill(dp, dp + n, iINF);
    rep(i, n) cin >> a[i];
    for(int i = 0; i < n; i++)
        *lower_bound(dp, dp + n, a[i]) = a[i];
    
    cout << lower_bound(dp, dp + n, iINF) - dp << endl;

    return 0;
}


Measured memory_bytes: 3620
n = int(input())
w = []
w.append(input())
flag = True
for i in range(1, n):
    w.append(input())
    if len(set(w)) != i + 1 or w[i - 1][-1] != w[i][0]:
        flag = False
        break
print('Yes' if flag else 'No')    

Measured memory_bytes: 3060
N = input()
B =list(map(int,input().split()))
max_count=0
last = B[0]-1
count=0
for x in B:
    if x <=last:
        count +=1
    elif count !=0:
        count = 0
        
    if count >max_count:
        max_count = count
    last = x
print(max_count)

Measured memory_bytes: 14252
n = gets.chomp.to_i

x = []
n.times do |i|
    x.push(gets.split(" ").map(&:to_i))
end

def rotation(a, i)
    if i.eql?("N") then
        a[0], a[1], a[5], a[4] = a[1], a[5], a[4], a[0]
    elsif i.eql?("S") then
        a[0], a[1], a[5], a[4] = a[4], a[0], a[1], a[5]
    elsif i.eql?("E") then
        a[0], a[2], a[5], a[3] = a[3], a[0], a[2], a[5]
    elsif i.eql?("W") then
        a[0], a[2], a[5], a[3] = a[2], a[5], a[3], a[0]
    elsif i.eql?("R") then
        a[3], a[1], a[2], a[4] = a[4], a[3], a[1], a[2]
    elsif i.eql?("L") then
        a[3], a[1], a[2], a[4] = a[1], a[2], a[4], a[3]
    end
    
    a
end

def f(a, b)
    "EEEESEEEESEEEESEEEESREEERREEE".each_char do |i|
        a = rotation(a, i)
        if a == b then
            return true
        end
    end

    false
end

x.size.times do |i|
    ((i + 1)...x.size).each do |j|
        if f(x[i], x[j]) then
            print "No\n"
            exit
        end
    end
end

print "Yes\n"



Measured memory_bytes: 8900
#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#include <bits/stdc++.h>
using namespace std;typedef long long ll;ll N,L,T;int main(){cin >> N >> L >> T;vector<ll> ans;ll diff = 0;REP(i, N) {ll x,w;cin>>x>>w;ll pos;if(w==1){pos = (x+T)%L;diff += (x+T)/L;}else{pos=((x-T)%L+L)%L;diff -= (T-x+L-1)/L;}ans.push_back(pos);}sort(ans.begin(),ans.end());diff=(diff%N+N)%N;rotate(ans.begin(), ans.begin()+diff, ans.end());REP(i,N) cout << ans[i] << endl;return 0;}

Measured memory_bytes: 2164
#include<stdio.h>

typedef long long int int64;

char ffc;
int fff;
int nextInt();

int N, K, i, j, k, l, c;
int64 answer, sum;
int a[1000];
int64 b[500500];

int main(void){
	N = nextInt();
	K = nextInt();
	for(i=0; i<N; i++){
		a[i] = nextInt();
	}
	l = N*(N+1)/2;
	k = 0;
	for(i=0; i<N; i++){
		sum=0;
		for(j=i; j<N; j++){
			sum+=a[j];
			b[k++]=sum;
		}
	}
	answer = 0;
	for(k=39; k>=0; k--){
		c=0;
		for(i=0; i<l; i++){
			if((b[i]>>k)&1){c++;}
		}
		if(c>=K){
			answer+=((int64)1)<<k;
			j=0;
			for(i=0; i<l; i++){
				if((b[i]>>k)&1){b[j++]=b[i];}
			}
			l=j;
		}
	}
	printf("%lld\n", answer);
	return 0;
}

int nextInt(){
	fff=0;
	ffc = getchar();
	while((ffc<'0')||('9'<ffc)){
		ffc=getchar();
	}
	while((ffc>='0')&&(ffc<='9')){
		fff=fff*10+(ffc-'0');
		ffc=getchar();
	}
	return fff;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
 
#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(v)              (v).begin(),(v).end()
#define pi          3.14159265359
ll INF=1e18+10;
ll MOD=998244353;

int main()
{
    fastio;
    ll n,m;cin>>n>>m;
    vector<ll> a(n);rep(i,0,n)cin>>a[i];
    sort(all(a));
    ll l=0,r=INF;
    while(l<r)
    {
        ll mid=(l+r+1)/2;
        ll cnt=0;
        rep(i,0,n)
        {
            auto x=lower_bound(all(a),mid-a[i]);
            cnt+=(n-(x-a.begin()));
        }
        if(cnt<m)
            r=mid-1;
        else
            l=mid;
    }
    vector<ll> suf(n+1);suf[n]=0;
    for(int i=n-1;i>=0;i--)suf[i]+=(a[i]+suf[i+1]);
    ll ans=0,cnt=0;
    for(int i=0;i<n;i++)
    {
        auto x=lower_bound(all(a),l-a[i]);
        int in=x-a.begin();
        cnt+=(n-in);
        ans+=(suf[in]+(n-in)*a[i]);
    }
    ans-=(cnt-m)*l;
    cout<<ans;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int tmp=1;
	int cnt=0;
	for(int i=0;i<n;i++)
	{
		int a;
		cin >> a;
		if(a!=tmp)
			cnt++;
		else
			tmp++;
	}
	if(cnt==n)
		cout << -1 << endl;
	else
		cout << cnt << endl;





}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

#define pb push_back
#define mp make_pair
#define mod 1000000007

int main() {

    string s;
    cin>>s;

    vector<char> v;
    v.pb(s[0]);

    for(int i=1;i<s.size();i++) {
        if(s[i] != v[v.size()-1]) {
            v.pb(s[i]);
        }
    }

    cout<<v.size()-1;

    return 0;
}



Measured memory_bytes: 640
#include <stdio.h>

int start[200010],end[200010];
char x[200010];
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	scanf("%s",x+1);
	
	int p = 1;
	for(int i=1;i<=b;i++)
	{
		while(p<=a)
		{
			if(x[p]=='o')
			{
				start[i] = p;
				p += (c+1);
				break;
			}
			else p++;
		}
	}
	
	p = a;
	for(int i=b;i>=1;i--)
	{
		while(p>=1)
		{
			if(x[p]=='o')
			{
				end[i] = p;
				p -= (c+1);
				break;
			}
			else p--;
		}
	}
	
	for(int i=1;i<=b;i++)
	{
		if(start[i]==end[i]) printf("%d\n",start[i]);
	}
}

Measured memory_bytes: 3200
#include <bits/stdc++.h> 
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;

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

int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n)cin>>a[i];
    vector<ll> l(n+1),r(n+1);
    l[0]=a[0];
    r[0]=a[n-1];
    rep(i,n){
        l[i+1]=__gcd(l[i],a[i+1]);
        r[i+1]=__gcd(r[i],a[(n-1)-(i+1)]);
    }
    vector<ll> ans(n);
    ans[0]=r[n-2];
    ans[n-1]=l[n-2];
    for(int i=1;i<n-1;++i){
        ans[i]=__gcd(l[i-1],r[n-3-(i-1)]);
    }
    ll ret=0;
    rep(i,n){
        ret=max(ret,ans[i]);
    }
    cout<<ret<<endl;
}




Measured memory_bytes: 6304
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define PB push_back
#define MAXN 100005
#define MP make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define SQ(a) (a)*(a)
#define nl "\n"
#define INF std::numeric_limits<int>::max()
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
ll mod=1000000009;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin>>s;
	if(s[0] == s[1] && s[1]== s[2]){
		cout<<"No"<<nl;
	}
	else cout<<"Yes"<<nl;
	return 0;
}






Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <istream>
#include <map>
#include <numeric>
#include <ostream>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;


class Solution {
public:
    int alpha['z' + 1] = {};
    void solve(std::istream& in, std::ostream& out) {
        string s;
        in >> s;
        bool ret = false;
        for (int i = 0; i < s.length(); i++)
        {
            alpha[s[i]]++;
            if (alpha[s[i]] > 1)
            {
                ret = true;
            }
        }
        out << (ret ? "no" : "yes");
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}


#include <fstream>
#include <iostream>


int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);


    istream& in = cin;


    ostream& out = cout;

    solve(in, out);
    return 0;
}




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

int main() {
  vector<int> x(5);
  int k;
  for(int i = 0; i < 5; i++){
    cin >> x.at(i);
  }
  cin >> k;
  bool flag = true;
  for(int i = 0; i < 5; i++){
    for(int j = 0; j < 5; j++){
      if(abs(x.at(i) - x.at(j)) > k) flag = false;
    }
  }
  if(flag) cout << "Yay!" << endl;
  else cout << ":(" << endl;
}


Measured memory_bytes: 256
from math import *



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

l=[]

prev=n
new=0
while(prev!=new):
	prev=len(a)

	for i in range(len(a)-1,-1,-1):
		if(i+1==a[i]):
			l.append(a[i])
			a.pop(i)
			break
	new=len(a)

if(len(a)==0):
	l=l[::-1]
	for i in l:
		print(i)
else:
	print(-1)


Measured memory_bytes: 38768
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
const int M=1e5+5;
const ll mod=998244353;
ll ct[M];
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int mx=0;
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int d;
		cin>>d;
		if(i==1 && d)
		{
			cout<<"0\n";
			return 0;
		}
		if(i>1 && d==0)
		{
			cout<<"0\n";
			return 0;
		}
		ct[d]++;
		mx=max(mx,d);
	}
	ll res=1;
	for(ll i=1;i<=mx;i++)
	{
		if(ct[i]==0)
			res=0;
		for(int j=1;j<=ct[i];j++)
			res=(res*ct[i-1])%mod;
	}
	cout<<res<<"\n";
	return 0;
}

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

#define FOR(i, a, b) for (int i = a; i < (int) b; i++)
#define F0R(i, a) FOR (i, 0, a)
#define GO(to, a) for (auto to : a)

#define f first
#define s second
#define eb emplace_back
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()

int main () {
	string w;
	cin >> w;
	cout << string (sz(w), 'x') << '\n';
  return 0;
}

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
//------------------------------------------

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//------------------------------------------

//debug
//------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
//------------------------------------------


int main() {
  LL N, A, B;
  cin >> N;
  
  if (N == 1) {
    cout << "Hello World";
  }
  else
  {
    cin >> A >> B;
    cout << A + B << endl;
  }
  
  return 0;
}

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


int main()
{
    string s;
    cin >> s;
    const long num = 2019;
    long n = s.length();
    vector<vector<long>> dp(2, vector<long> (num, 0));
    long fans = 0;

    for (long i = 1; i <= n; i++)
    {
        long d = s[i-1] - '0';
        for (long r = 0; r < num; r++)
            dp[1][(r*10 + d) % num] = dp[0][r];
        dp[1][d] ++;
        dp[0] = dp[1];
        fans += dp[1][0];
    }


    cout << fans;
    return 0;
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
	int w,h,x,y;
	cin >> w >> h >> x >> y;
	printf("%.15lf ",(double)(w * h) / 2.0);
	if(x * 2 == w && y * 2 == h) cout << 1 << endl;
	else cout << 0 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	int n, m;
	cin >> n >> m;
	int co = 0;
	for (int i = 0; i < m; i++) {
		int a;
		cin >> a;
		co += a;
	}
	if (co > n) {
		cout << "-1" << endl;
	}
	else {
		cout << n - co << endl;
	}
	return 0;
}

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

int main() {
  char s;
  cin >> s;

  if (s == 'A'){
    cout << 'T' << endl;
  }
  else if ( s == 'T'){
    cout << 'A' << endl;
  
  }
  else if (s == 'G'){
    cout << 'C' << endl;
}
 else{
   cout << 'G' << endl;
 }
}
  




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
    int s,e,m,v,la;
    node  *l, *r;
    node (int _s, int _e): s(_s), e(_e){
        m = (s+e)/2;
        la = 0;
        if (s == e){
            if (s == 0) v =0;
            else v = -1;
        }
        else{
            l = new node(s,m);
            r = new node(m+1,e);
            v = l->v + r->v;
        }
    }
    void prop(){
        if (la){
            v = 0;
            if (s != e ){
                l -> la = 1;
                r -> la = 1;
            }
            la = 0;
        }
    }
    void up(int qs, int qe){
        prop();
        if (qs == s && qe == e){
            la = 1;
            return;
        }
        if (qs  > m) r->up(qs,qe);
        else if (qe <= m)  l->up(qs,qe);
        else l->up(qs,m), r->up(m+1,qe);
        l->prop(); r->prop();
        v = l->v+r->v;
    }
    int qu(int qs, int qe){
        prop();
        if (qs == s && qe == e)  return v;
        if (qs > m) return r->qu(qs,qe);
        else if (qe <= m) return l->qu(qs,qe);
        else return l->qu(qs,m) + r->qu(m+1,qe);
    }
} *root;
int n;
int a[200005];

int main(){
    scanf("%d",&n);
    for (int i = 0; i < n; i++){
        //a[i] = min(i,n/2);
        scanf("%d",&a[i]);
    }
    root = new node(0,n-1);
    ll ans = 0;
    for (int i = n-1; i >=0; i--){
        int expect = i+root->qu(0,i);
        //printf("%d: %d %d\n",i,expect,a[i]);
        if (expect != a[i]){
            ans += a[i];
            root->up(min(i,max(0,i-a[i]+1)),i);
            if (i+root->qu(0,i) != a[i]){
                printf("-1\n");
                return 0;
            }
        }
    }
    printf("%lld",ans);
}


Measured memory_bytes: 23296
/*_BELIEVE_*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

#define     int          long long int
#define     fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     __gcd((a),(b))
#define     lcm(a,b)     ((a)*(b))/gcd((a),(b))
#define     pb           push_back
#define     ins          insert
#define     F            first
#define     S            second

const int inf=1e18,M=1e9+7;
const int N=2e5+5;

vector<int> v[N],dp(N,0);

void dfs(int x,int p)
{
    if(p!=-1)
        dp[x]+=dp[p];
        
    for(auto u:v[x])
    {
        if(u==p)
            continue;
            
        dfs(u,x);
    }
}

void solve()
{
    int n,q;
    cin>>n>>q;
    
    int a,b;
    for(int i=1;i<n;++i)
    {   
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }
    
    int x,y;
    for(;q;--q)
    {
        cin>>x>>y;
        
        dp[x]+=y;
    }
    
    dfs(1,-1);
    
    for(int i=1;i<=n;++i)
        cout<<dp[i]<<" ";
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }

    return 0;
}


Measured memory_bytes: 24320
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,k = inpl()
a = inpl()
if k in a:
    print('POSSIBLE')
    quit()
if k > max(a):
    print('IMPOSSIBLE')
    quit()
if 1 in a:
    print('POSSIBLE')
    quit()
tmp = a[0]
for i in range(1,n):
    tmp = fractions.gcd(tmp,a[i])
if k%tmp == 0: 
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')


Measured memory_bytes: 84332
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

struct Info{
	char name[21];
	int length;
};

void strcpy(char* to,char* str){
	for(int i=0;str[i] != '\0';i++){
		to[i] = str[i];
		to[i+1] = '\0';
	}
}

int main(){

	int N,cost[14][14],limit,count,tmp,ans,next_state,num_town;
	int table[14] = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192};
	int** dp = new int*[14];
	for(int i = 0; i < 14; i++){
		dp[i] = new int[16384];
	}

	Info first_info[14],info[14];
	bool FLG,part_sentence[14];

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		for(int i = 0; i < N; i++){
			scanf("%s",first_info[i].name);
			for(first_info[i].length = 0; first_info[i].name[first_info[i].length] != '\0';first_info[i].length++);
		}

		for(int i = 0; i < 14;i++)part_sentence[i] = false;

		for(int i = 0; i < N; i++){
			for(int k = 0; k < N; k++){
				if(i != k && first_info[i].length <= first_info[k].length){
					for(int left = 0; first_info[k].length-left >= first_info[i].length;left++){
						FLG = true;

						for(int a = 0; a < first_info[i].length; a++){
							if(first_info[i].name[a] != first_info[k].name[left+a]){
								FLG = false;
								break;
							}
						}

						if(FLG){
							part_sentence[i] = true;
							break;
						}
					}

				}
			}
		}

		num_town = 0;

		for(int i = 0; i < N; i++){
			if(part_sentence[i] == false){
				strcpy(info[num_town].name,first_info[i].name);
				info[num_town].length = first_info[i].length;
				num_town++;
			}
		}

		N = num_town;

		for(int i = 0; i < N; i++){
			for(int k = 0; k < N; k++){
				if(i == k)continue;

				count = 0;

				for(int left = 0; left < info[i].length;left++){
					FLG = true;
					for(int a = left; a < info[i].length && (a-left) < info[k].length;a++){
						if(info[i].name[a] != info[k].name[a-left]){
							FLG = false;
							break;
						}
					}
					if(FLG){
						count = info[i].length-left;
						break;
					}
				}

				cost[i][k] = count;
			}
		}

		limit = pow(2,N);

		for(int i = 0; i < N;i++){
			for(int k = 0; k < limit; k++){
				dp[i][k] = BIG_NUM;
			}
		}

		for(int i = 0; i < N; i++){
			tmp = pow(2,i);
			dp[i][tmp] = info[i].length;
		}

		for(int state = 0; state <= limit-2; state++){
			for(int k = 0; k < N; k++){
				if(dp[k][state] == BIG_NUM)continue;
				for(int a = 0; a < N; a++){
					if(state & (1 << a)){
						//Do nothing
					}else{
						next_state = state + table[a];
						if(dp[a][next_state] > dp[k][state] + info[a].length - cost[k][a]){
							dp[a][next_state] = dp[k][state] + info[a].length - cost[k][a];
						}
					}
				}
			}
		}

		ans = BIG_NUM;
		for(int i = 0; i < N; i++){
			ans = min(ans,dp[i][limit-1]);
		}

		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 3688
inp = input()
large_n = int(inp)
inp = input()
split_input = inp.split()
a_list = [int(i) for i in split_input]
plus_list = []
minus_list = []
zero_count = 0
for n in a_list:
    if n > 0:
        plus_list.append(n)
    elif n < 0:
        minus_list.append(n)
    else:
        zero_count += 1
if zero_count == large_n:
    print(0)
    for _ in range(large_n-1):
        print("0 0")
    exit()
print_list = []
m = 0
if zero_count == 0:
    if len(plus_list) == 0:
        max_number = max(minus_list)
        hoge = minus_list.pop(minus_list.index(max_number))
        present_number = max_number
        for number in minus_list:
            print_list.append(str(present_number) + " " + str(number))
            present_number = present_number - number
        m = present_number
    elif len(minus_list) == 0:
        mini_number = plus_list.pop(plus_list.index(min(plus_list)))
        present_number = mini_number
        for number in plus_list[:-1]:
            print_list.append(str(present_number) + " " + str(number))
            present_number = present_number - number
        print_list.append(str(plus_list[-1]) + " " + str(present_number))
        m = plus_list[-1] - present_number
    else:
        present_number = minus_list.pop()
        for number in plus_list[:-1]:
            print_list.append(str(present_number) + " " + str(number))
            present_number -= number
        print_list.append(str(plus_list[-1]) + " " + str(present_number))
        present_number = plus_list[-1] - present_number
        for number in minus_list:
            print_list.append(str(present_number) + " " + str(number))
            present_number -= number
        m = present_number
else:
    for _ in range(zero_count-1):
        print_list.append("0 0")
    # 0 一つ残る
    plus_number = 0
    if len(plus_list) > 0:
        plus_number = plus_list.pop()
    present_number = 0
    # plus なくす
    for number in plus_list:
        print_list.append(str(present_number) + " " + str(number))
        present_number -= number
    if plus_number != 0:
        print_list.append(str(plus_number) + " " + str(present_number))
        present_number = plus_number - present_number
    for number in minus_list:
        print_list.append(str(present_number) + " " + str(number))
        present_number -= number
    m = present_number


print(m)
for p in print_list:
    print(p)


Measured memory_bytes: 24984
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define MOD 1000000007
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> h(N);
    rep(i, N) cin >> h[i];
    int MAX = 1e9+7;
    vector<int> dp(N, MAX);
    dp[0] = 0;
    rep(i, N)
    {
        for (int j:{i+1,i+2}){
            if(j<N){
                dp[j]=min(dp[j],dp[i]+abs(h[j]-h[i]));
            }
        }
        // dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
        // dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
    }

    std::cout << dp[N - 1] << endl;
 //   std::system("pause");
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using f80 = __float80;
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define pb push_back
#define rng(a) a.begin(),a.end()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define sz(x) (i64)(x).size()
#define bit(n) (1LL<<(n))
#define fi first
#define se second
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
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;}

i64 pow_mod(i64 n, i64 k, i64 m){
  i64 r = 1;
  for(;k;k>>=1){
    if(k&1) r=(r*n)%m;
    n=(n*n)%m;
  }
  return r;
}

struct uf{
  private:
    vi par, rank, size;
  public:
    uf(i64 n){ init(n); }
    void init(i64 n){
      par.resize(n);
      rank.resize(n,0);
      size.resize(n,1);
      rep(i,n) par[i] = i;
    }
    i64 root(i64 x){
      if(par[x] == x) return x;
      return par[x] = root(par[x]);
    }
    bool same(i64 x, i64 y){ return root(x) == root(y); }
    void unite(i64 x, i64 y){
      x = root(x), y = root(y);
      if(x==y) return;
      if(rank[x]==rank[y]) rank[x]++;
      if(rank[x]<rank[y]) swap(x,y);
      par[y] = x;
      size[x] += size[y];
    }
    i64 num(i64 x){ return size[root(x)]; }
};

void Main()
{
  i64 A,B,M;
  cin >> A >> B >> M;
  vi a(A);
  rep(i,A) cin >> a[i];
  vi b(B);
  rep(i,B) cin >> b[i];

  i64 ans = (*min_element(rng(a))) + (*min_element(rng(b)));

  i64 x,y,c;
  rep(i,M){
    cin >> x >> y >> c;
    x--;y--;
    chmin(ans,a[x]+b[y]-c);
  }
  cout << ans << endl;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}


Measured memory_bytes: 1792
#include<stdio.h>

main(){
	
	int n, m, l, i, j, k, a[101][101]={0}, b[101][101]={0};
	long int c[101][101]={0};
	
	
	scanf("%d%d%d",&n,&m,&l);
	
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			scanf("%d",&a[i][j]);
		}
	}
	
	for(i=0;i<m;i++){
		for(j=0;j<l;j++){
			scanf("%d",&b[i][j]);
		}
	}
	
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			for(k=0;k<l;k++){
				c[i][k]+=a[i][j]*b[j][k];
			}
		}
	}
	
	for(i=0;i<n;i++){
		for(j=0;j<l-1;j++){
			printf("%ld ",c[i][j]);
		}
		printf("%ld\n",c[i][l-1]);
	}
	
	return 0;
}

Measured memory_bytes: 768
/*
        karmany evadhikaras te
        ma phalesu kadacana 
        ma karma-phala-hetur bhur
        ma re sango'stv akarmani (B.G.-2.47)
 
Translation:
        Lord Krsna to Arjuna.
You have a right to perform your prescribed duty, 
but you are not entitled to the fruits of action. 
Never consider yourself the cause of the results of your activities, 
and never be attached to not doing your duty.    
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
const int N = 1000005;
#define ld long double
#define PI 3.14159265358979323846
const int INF = 1e9+7;

void flash()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(12);
}

//3. Structure or classes
//3. Ends here

//1. Data structures declaration here
//1. Ends here


//2. Extra Functions here
//2. Ends here


void solve();
int32_t main()
{
    flash();
    int t;
    t = 1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

void solve()
{
    
    int n;
    cin>>n;
    int ans=0;
    if(n==1){
        cout<<"0\n";return;
    }
    for(int i=2;i*i<=n;i++){
        int cnt=0;
        while(n%i==0){
            n/=i;
            cnt++;
        }
        ans += (sqrtf(1+8*cnt)-1)/2;
    }
    if(n!=1){
        ans++;
    }
    cout<<ans;
    return;
}

Measured memory_bytes: 3692
import java.util.Scanner;

public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int H = sc.nextInt();
        int W = sc.nextInt();
        int[] A = new int[N];
        int[] B = new int[N];
        for (int i=0; i<N; i++) {
            A[i] = sc.nextInt();
            B[i] = sc.nextInt();
        }

        System.out.println(solve(N, H, W, A, B));
    }

    private static int solve(int N, int H, int W, int[] A, int[] B) {
        int count = 0;

        for (int i=0; i<N; i++) {
            if (A[i] >= H && B[i] >= W) count++;
        }

        return count;
    }
}

Measured memory_bytes: 24404
#include<stdio.h>
#include<stdlib.h>
int MIN(int a,int b){return a<b?a:b;}
int main(){
  int n,i,h[100010],d[100010]={};
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&h[i]);
  d[1]=abs(h[0]-h[1]);
  for(i=2;i<n;i++)d[i]=MIN(d[i-1]+abs(h[i]-h[i-1]),d[i-2]+abs(h[i]-h[i-2]));
  printf("%d\n",d[n-1]);
  return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define f1(a,b,c) for(int c=a;c<=b;c++)
#define f2(a,b,c) for(int c=a;c>=b;c--)
#define f3(a,b,c) for(int c=a;c;c=b)
#define so1(a,n) sort(a+1,a+n+1,mycmp);
#define so2(a,n) sort(a+1,a+n+1);
#define ll long long
#define itn int
#define ubt int 
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
const int twx=5e3+100;
const int inf=0x3f3f3f3f;
ll read()
{
    ll sum=0;
    ll flag=1;
    char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-')
        {
            flag=-1;
        }
        c=getchar();
    }
    while(c>='0'&&c<='9')
    {
        sum=((sum*10)+c-'0');
        c=getchar();
    }
    return sum*flag;
}
int n;
int xs[twx];
struct LV
{
    int y;
    int Next;
}a[twx];
int Link[twx];
int len;
int asd[twx];
int qwe[2][twx];
void Insert(int x,int y)
{
    a[++len].y=y;
    a[len].Next=Link[x];
    Link[x]=len;
}
void dfs(int x)
{
    f3(Link[x],a[i].Next,i)
    {
        int y=a[i].y;
        dfs(y);
    }
    memset(qwe[0],0x3f,sizeof qwe[0]);
    int tmp=0;
    qwe[tmp][0]=0;
    f3(Link[x],a[i].Next,i)
    {
        int y=a[i].y;
        tmp^=1;
        memset(qwe[tmp],0x3f,sizeof qwe[tmp]);
        f1(0,xs[x],j)
        {
            if(j-xs[y]>=0)
            {
                qwe[tmp][j]=min(qwe[tmp][j],qwe[1-tmp][j-xs[y]]+asd[y]);
            }
            if(j-asd[y]>=0)
            {
                qwe[tmp][j]=min(qwe[tmp][j],qwe[1-tmp][j-asd[y]]+xs[y]);
            }
        }
    }
    f1(0,xs[x],i)
    {
        asd[x]=min(asd[x],qwe[tmp][i]);
    }
}
void init()
{
	n=read();
    f1(2,n,i)
    {
        int p=read();
        Insert(p,i);
    }
    f1(1,n,i)
    {
        xs[i]=read();
    }
    memset(asd,0x3f,sizeof asd);
    dfs(1);
    if(asd[1]!=inf)
    {
        puts("POSSIBLE");
    }
    else
    {
        puts("IMPOSSIBLE");
    }
}
int main()
{
    init();
	return 0;
}


Measured memory_bytes: 384
h, w, k = map(int, input().split())
MOD = 10**9+7
memo = [[0]*(w+1) for _ in range(h+1)]
dp = [[1]*2 for _ in range(w+1)]
dp[0][0] = 0
for i in range(2, w+1):
    for j in range(2):
        dp[i][0] = dp[i-1][0] + dp[i-1][1]
        dp[i][1] = dp[i-1][0]
#print(dp)
def poss_of_ok_spaces(idx,straight):
    if straight:
        ok_spaces_l = max(idx - 1 - 1, 0)
        ok_spaces_r = max(w - idx - 1, 0)
        return sum(dp[ok_spaces_l])%MOD * sum(dp[ok_spaces_r])%MOD
    else:
        #右の数値を飛ばす前提
        ok_spaces_l = max(idx - 1 - 2, 0)
        ok_spaces_r = max(w - idx - 1, 0)
        return sum(dp[ok_spaces_l])%MOD * sum(dp[ok_spaces_r])%MOD

def rc(n,idx):
    if memo[n][idx] != 0:
        return memo[n][idx]
    if n == 1:
        if idx == k:
            return poss_of_ok_spaces(idx,True)%MOD
        elif k == idx + 1:
            return poss_of_ok_spaces(k,False)%MOD
        elif k == idx - 1:
            return poss_of_ok_spaces(idx,False)%MOD
        else:
            return 0
    ret = rc(n-1,idx)%MOD*poss_of_ok_spaces(idx,True)%MOD
    if idx + 1 <= w:
        ret += rc(n-1,idx+1)%MOD*poss_of_ok_spaces(idx+1,False)%MOD
    if idx - 1 >= 1:
        ret += rc(n-1,idx-1)%MOD*poss_of_ok_spaces(idx,False)%MOD
    ret %= MOD
    memo[n][idx] = ret
    return ret
print(rc(h,1))

Measured memory_bytes: 74584
#include <iostream>
#include <string>
using namespace std;
int main(){
    int n;
    string a;
    while(cin >> n){
        if(n==0)
            break;
        cin >> a;
        for(int i=0;i<n;i++){
            string strtmp;
            int x=0;int y=0;
            while (y!=a.length()){
                if(a[x]==a[y]){
                    y++;
                    if(y==a.length()){
                        strtmp += to_string(y-x);
                        strtmp += a[x];
                        x=y;
                    }
                    else
                        continue;
                }
                else{
                    strtmp += to_string(y-x);
                    strtmp += a[x];
                }
                x = y;
            }
            a = strtmp;
        }
        cout << a << endl;
    }
}

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

int main(){
    int n;
    cin>>n;
    vector<int> p(n), q(n), a(n, 0);
    
    for(int i=0;i<n;i++){
        cin>>p[i];
    }
    for(int i=0;i<n;i++){
        cin>>q[i];
    }
    for(int i=0;i<n;i++){
        a[i]+=i+1;
    }
    
    int indp=0, indq=0, ind=0;
    
    while(1){
        if(p==a)indp = ind;
        if(q==a)indq = ind;
        ind++;
        if(!next_permutation(a.begin(), a.end()))break;
    }
    
    cout<<abs(indp - indq)<<endl;
    return 0;
}


Measured memory_bytes: 256
from decimal import *
import sys
a,b,c = map(int,input().split())
getcontext().prec = 500
if a + b >= c:
  print('No')
  sys.exit(0)
if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt():
  print('Yes')
  sys.exit(0)
print('No')


Measured memory_bytes: 5076
#pragma warning(disable: 4996)

#include <iostream>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <functional>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <vector>
#include <bitset>
#include <numeric>
#include <string>
#include <set>
#include <tuple>
#include <utility>
#include <regex>
#include <deque>
#include <map>
#include <queue>
using namespace std;

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, k;
	cin >> n >> k;
	long long sum = 0;
	vector<int> h(n);
	for (int i = 0; i < n; ++i) {
		cin >> h[i];
		sum += h[i];
	}
	sort(h.begin(), h.end(), greater<int>());
	int limit = min(k, n);
	for (int i = 0; i < limit; ++i) {
		sum -= h[i];
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 1024
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

#define MAXN 100000
#define MAXM 200000
vector<vector<int>> g;
int l[MAXM], r[MAXM], d[MAXM];

int n, m;

int input() {
	if (scanf("%d %d", &n, &m) < 0) return 0;
	g.resize(n);
	for (int i=0; i<m; i++) {
		scanf("%d %d %d", &l[i], &r[i], &d[i]);
		l[i]--, r[i]--;
		g[l[i]].push_back(i);
		g[r[i]].push_back(i);
	}
	return 1;
}

void init() {
}

long val[MAXN];
long maxv, minv;

int dfs(int v,int f) {
	for (auto e: g[v]) {
		int c = d[e], u = r[e];
		if (u == v) {
			c = -c;
			u = l[e];
		}
		long x = val[v] + c;
		if (val[u] != LONG_MAX) {
			if (val[u] != x) return 0;
			continue;
		}
		val[u] = x;
		minv = min(minv, x);
		maxv = max(maxv, x);
		if (!dfs(u, v)) return 0;
	}
	return 1;
}

long solve() {
	for (int i=0; i<n; i++)
		val[i] = LONG_MAX;
	for (int i=0; i<n; i++)
		if (val[i] == LONG_MAX) {
			maxv = minv = val[i] = 0;
			if (!dfs(i, -1)) return 0;
			if (maxv-minv > 1000000000) return 0;
		}
	//printa(val, n);
	return 1;
}

void output(long ans) {
	printf("%s\n", ans? "Yes":"No");
}

void cleanup() {
	g.clear();
}

int main() {
	//int ca; scanf("%d", &ca);
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}





Measured memory_bytes: 12672
while True:
    n,m = map(int, input().split())
    if n==0 and m==0:
        break
    cnt = 0
    for i in reversed(range(1,n+1)):
        for j in reversed(range(1,i)):
            for k in reversed(range(1,j)):
                if i+j+k == m:
                    cnt += 1
                    break
    print(cnt)

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

int main()
{
  long long n;
  cin >> n;
  
  int ans = 0;
  
  for(long long i = 2; i * i <= n; i++)
  {
    int e = 0;
    while(n % i == 0)
    {
      n/= i;
      e++;
    }
    int a = 1;
    while((e - a) >= 0)
    {
      e -= a;
      a++;
      ans++;
    }
  }
  if(n != 1)
  {
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3644
n = int(input())
S = [''] * n

word_list = 'abcdefghijklmnopqrstuvwxyz'
d = {}

for i in range(n):
    S[i] = input()

for w in word_list:
    d[w] = float('inf')
    for s in S:
        if d[w] > s.count(w):
            d[w] = s.count(w)
    print(w*d[w],end="")

print()

Measured memory_bytes: 3060