akhauriyash/Code-Regression huggingface dataset:
# ABC138D - Ki (main, dfs inside main())
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    # Ai (A[i][0]) may be not a parent of Bi (A[i][1])
    def dfs(v: int, p: int) -> None:
        for u in T[v]:
            if u != p:  # p: parent -> skip
                cnt[u] += cnt[v]  # cumulative sum
                dfs(u, v)

    N, Q = tuple(map(int, input().split()))  # vertices and queues
    E = tuple(tuple(map(int, input().split())) for _ in range(N - 1))
    P = tuple(tuple(map(int, input().split())) for _ in range(Q))
    T = [[] for _ in range(N + 1)]  # tree, (N+1: 1-idx -> 0-idx)
    for a, b in E:
        T[a] += [b]
        T[b] += [a]
    cnt = [0] * (N + 1)
    for p, x in P:
        cnt[p] += x  # increase vertex p by x
    dfs(1, -1)
    print(*cnt[1:])


if __name__ == "__main__":
    main()


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

int main()
{
  int a,b,c;
  
  cin>>a>>b>>c;
  
  int temp;
  temp = a;
  a=c;
  c=b;
  b=temp;
 cout<<a<<" "<<b<<" "<<c;
  
}
  
  
  


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

int main(){
	
	int hit,blow;
	int a[4],b[4];
	
	while(cin>>a[0]){
		cin>>a[1]>>a[2]>>a[3];
		cin>>b[0]>>b[1]>>b[2]>>b[3];
			hit=0;
			blow=0;
		for(int i=0;i<4;i++){
			for(int j=0;j<4;j++){
				if(a[i]==b[j]){
					if(i==j)
						hit++;
					else
						blow++;
					j=4;
				}
			}
		}
		cout<<hit<<" "<<blow<<endl;
	}
	
		

}

Measured memory_bytes: 1160
n=int(input())
a=list(map(int,input().split()))
m=10**9+7
bo=[0]*61
bz=[0]*61
for i in a:
  t=format(i,'061b')
  for j in range(61):
    if t[j]=='0':
      bz[j]+=1
    else:
      bo[j]+=1
bo=bo[::-1]
bz=bz[::-1]
x=0
for i in range(61):
  x+=bo[i]*bz[i]*(2**i)
  x%=m
print(x%m)

Measured memory_bytes: 122808
#include<bits/stdc++.h>
using namespace std;
int a[100000+1], b[100000+1], s[100000+1];

int main(){
	int i, j;
	
	for (i=2; i<=100000; i++)  a[i]=1;
	
	for (i=2; i<=int(sqrt(100000)); i++){
	  if (a[i]==1)
	    for (j=i+i; j<=100000; j+=i)  a[j] = 0;
    }
    
    b[1]=0; b[2]=0;
    for (i=3; i<=100000; i++)
       if (a[i]==1 && a[(i+1)/2]==1)  b[i]=1;
    
    s[1]=0; s[2]=0;
    for (i=3; i<=100000; i++)
       s[i]= s[i-1] + b[i];
    
    int q, L, r;
    cin >> q;
    
    for (i=1; i<=q; i++){
    	cin >> L >> r;     //5 21
    	cout << s[r] - s[L-1] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1792
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>
#define typeof(x) __typeof__(x)
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) UB(c,x)-LB(c,x)
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define PB push_back
#define MP make_pair
#define vec vector

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

using namespace std;

typedef pair<int,int> P;
struct edge {
  int to, cost;
};

const int INF = 1e18;
const int MOD = 3;

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


signed main()
{
  string S, T; cin >> S >> T;
  int q; cin >> q;
  vec<int> a(q), b(q), c(q), d(q);
  rep(i, 0, q) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }

  vec<int> s(SZ(S)+1), t(SZ(T)+1);
  s[0] = 0; t[0] = 0;
  rep(i, 0, SZ(S)) {
    int m = (S[i] == 'A') ? 1 : -1;
    s[i+1] = mod(s[i] + m);
  }
  rep(i, 0, SZ(T)) {
    int m = (T[i] == 'A') ? 1 : -1;
    t[i+1] = mod(t[i] + m);
  }

  rep(i, 0, q) {
    if (mod(s[b[i]]-s[a[i]-1]) == mod(t[d[i]]-t[c[i]-1])) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
#define Sort(v) sort(all(v))
#define Reverse(v) reverse(all(v))
#define Rsort(v) sort(all(v),greater)
#define pub(v) push_back(v)
#define pob(v) pop_back(v)
typedef long long ll;
typedef vector<ll> vel;
typedef vector<vector<ll>> vel2d;
typedef string str;
typedef pair<ll,ll> pal;

int main() {
    ll R,G,B,N,cnt=0;
    cin>>R>>G>>B>>N;
    for(ll r=0;r*R<=N;r++){
        for(ll g=0;g*G<=N;g++){
            ll bB=N-(r*R+g*G);
            if(bB%B==0&&bB>=0){cnt++;}
            
        }
    }
    cout<<cnt<<endl;
}



Measured memory_bytes: 256
//#pragma warning(disable:4996)
//#pragma comment(linker, "/STACK:336777216")
//#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))
#define sz(x) (int)(x.size())
#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
const int N=200005;

void solve()
{
    int m,n;
    cin>>m>>n;
    if(m==n)
    {
        cout<<"Yes";
    }
    else
        cout<<"No";
    cout<<endl;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	cout << max(a - 2 * b, 0) << endl;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define NL            "\n"
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
int main()
{
    _SAD()
    string s;
    int n;
    cin>>n>>s;
    for(int i=0;i<SZ(s);i++)
    {
        if(s[i]+n<=90)
        {
            s[i]+=n;
        }
        else
        {
            int x=s[i]-'0';
            x+=47;
            //cout<<x<<NL;
            x+=n;
            x%=90;
            s[i]=65+x;
        }
    }
    cout<<s<<NL;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX = 10000;
int A[MAX];
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	if (n % 2 == 0 || m % 2 == 0)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;
 	return 0;
}

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

using namespace std;
using ll = long long;

const int N = 22, MOD = 1e9 + 7;

int n, a[ N ][ N ];
ll dp[ N ][ 1 << N ];

ll dfs(int pos, int mask) {
    // cout << pos << " " << mask << '\n';
    if( pos == n )
        return 1LL;
    ll &ret = dp[ pos ][ mask ];
    if( ~ret ) return ret;
    ret = 0LL;
    for(int i = 0; i < n; i += 1)
        if( (mask & (1 << i)) == 0 && a[ pos ][ i ] == 1 )
            ret = (ret + dfs(pos + 1, mask | (1 << i))) % MOD;
    return ret;
}

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

    cin >> n;
    for(int i = 0; i < n; i += 1)
        for(int j = 0; j < n; j += 1)
            cin >> a[ i ][ j ];
    memset(dp, -1, sizeof dp);
    ll ans = dfs(0, 0);
    cout << ans % MOD << '\n';
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 1;
    for(int i=0;i<n-1;i++){
        char s1 = s.at(i);
        char s2 = s.at(i+1);
        if(s1 == s2) continue;
        ans ++;
    }
    cout << ans << endl;

}

Measured memory_bytes: 512
n=int(input())
l=[int(x) for x in input().split()]
ans=0
for i in range(n-2):
  for j in range(i,n-1):
    for k in range(j,n):
      if l[i]>l[j] and  l[i]>l[k] and l[j]!=l[k]:
        if abs(l[j]-l[k])<l[i] and l[i]<l[j]+l[k]:
          ans+=1
      elif l[j]>l[i] and  l[j]>l[k] and l[i]!=l[k]:
        if abs(l[i]-l[k])<l[j] and l[j]<l[i]+l[k]:
          ans+=1
      elif l[k]>l[j] and  l[k]>l[i] and l[i]!=l[j]:
        if abs(l[j]-l[i])<l[k] and l[k]<l[j]+l[i]:
          ans+=1
print(ans)

Measured memory_bytes: 9256
#include <bits/stdc++.h>
#define err(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

using namespace std;

typedef long long ll;

vector<int> cnt = { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	
	
	vector<int> A(m);
	for (int i = 0; i < m; i++) cin >> A[i];
	
	sort(A.rbegin(), A.rend());
	
	vector<int> p(n + 1, -1);
	
	auto calc = [&](vector<int> &P) {
		P.assign(n + 1, -1);
		P[0] = 0;
		for (int i = 0; i < n; i++) if (P[i] != -1) 
			for (int c : A) if (i + cnt[c] <= n && P[i + cnt[c]] < P[i] + 1)
				P[i + cnt[c]] = P[i] + 1;
		return P;
	};
	
	vector<int> S, P;
	calc(S);
	calc(P), reverse(P.begin(), P.end());
	
	vector<int> Q;
	Q.push_back(0);
	
	while (Q.size()) {
	
		int cur = -1;
		for (int w : Q) {
			for (int c : A) if (w + cnt[c] <= n && S[w] + P[w + cnt[c]] + 1 == S[n])
				cur = max(cur, c);
		}
		if (cur == -1) break;
			
		set<int> SS;
		for (int w : Q) {
			for (int c : A) if (c == cur && w + cnt[c] <= n && S[w] + P[w + cnt[c]] + 1 == S[n])
				p[w + cnt[c]] = c, SS.insert(w + cnt[c]);
		}
		Q.clear();
		for (auto c : SS) Q.push_back(c);
	}
	
	string ans;
	for (int i = n; i; i -= cnt[p[i]]) ans += (char)('0' + p[i]);
	reverse(ans.begin(), ans.end());
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
 
 
int A[2000002],B[2000002];
int C[10001];
int n;
void Counting_Sort(int A[], int B[], int n);
 
int main(){
  int i;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
 
    scanf("%d",&A[i]);
 
}
  Counting_Sort(A, B, 10000);
 
  for(i=1;i<n;i++){
    printf("%d ",B[i]);
}
  printf("%d\n",B[n]);
 
  return 0;
}
 
 
void Counting_Sort(int A[],int B[],int k){
  int i,j;
  for(i=0;i<=k;i++){
    C[i]=0;
  }
 
  for(j=1;j<=n;j++){
    C[A[j]]++;
  }
 for(i=1;i<=k;i++){
    C[i] =C[i]+ C[i-1];
  }
  
 for(j=n;j>=0;j--){
   B[C[A[j]]] = A[j];
   C[A[j]] = C[A[j]] -1;
 }
 
 return;
}

Measured memory_bytes: 16260
import sys
sys.setrecursionlimit(10**7)
def dfs(i):
    w=b=1
    for j in e[i]:
        if j in d:continue
        d.add(j)
        x,y=dfs(j)
        w*=x+y
        b*=x
    return w%M,b%M
M=10**9+7
n,*t=map(int,open(0).read().split())
e=[[]for _ in range(n)]
for x,y in zip(*[iter(t)]*2):
    e[x-1]+=y-1,
    e[y-1]+=x-1,
d={0}
print(sum(dfs(0))%M)

Measured memory_bytes: 112984
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const int NINF = -1*INF;
const long long LLINF = 1ll << 60;
const long long LLNINF = -1*LLINF;

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
	return os << "[ " << p.first << ", " << p.second << "]" ;
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
typedef vector<vll> vvll;
typedef vector<vd> vvd;
typedef vector<vld> vvld;
 
#define mp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()
#define revAll(x) x.rbegin(), x.rend()
#define gcd(a, b) __gcd(a, b)
#define popcount(x) __builtin_popcount(x)
#define isize(x) (int)(x.size())
#define rep(i,n) for(int i = 0; i < n; i++)
#define exists(x,m) m.find(x) != m.end()
#define umap unordered_map
#define uset unordered_set
#define pq priority_queue

const ll MOD = 1e9 + 7;

vll primes_up_to(ll lim) {
	vll primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37,
					41, 43, 47, 53, 59, 61, 67, 71};
	if (lim <= 71) return {primes.begin(), upper_bound(all(primes), lim)};
	for (int num = 73; num <= lim; num++) {
		bool is_prime = true;
		for (int i = 0; primes[i]*primes[i] <= num; i++) {
			if (num % primes[i] == 0) {
				is_prime = false;
				break;
			}
		}
		if (is_prime) primes.pb(num);
	}	
	return primes;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);
	int n; cin >> n;
	vi A = vi();
	int maxx = 0;
	rep(i, n) {
		int x; cin >> x;
		A.pb(x);
		maxx = max(maxx, x);
	}	
	vll primes = primes_up_to(min(ceil(sqrt(maxx))+100, 1e3 + 100));
	umap<int, int> prime_freq = umap<int, int>();
	for (const int& a : A) {
		int b = a;
		for (int i = 0; primes[i]*primes[i] <= b; i++) {
			if (b % primes[i] == 0) prime_freq[primes[i]]++;
			while(b % primes[i] == 0) b /= primes[i];
		}
		if (b != 1) prime_freq[b]++;
	}
	int max_freq = 0;
	for (const auto& [p, freq] : prime_freq) {
		max_freq = max(max_freq, freq);
	}
	if (max_freq <= 1) {
		cout << "pairwise coprime";
	} else {
		cout << (max_freq < n ? "setwise coprime" : "not coprime");
	}
}

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

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

int main() {
    lint k, n;
    cin >> k >> n;
    vector<lint> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    lint dist = (k - a[n - 1]) + a[0];
    for (int i = 0; i < n - 1; i++) {
        chmax(dist, a[i + 1] - a[i]);
    }
    cout << k - dist << endl;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=1000000007;

int main(){
  int n;
  cin>>n;
  
  queue<string> q;
  q.push("a");
  
  while(!q.empty()){
    string s=q.front();q.pop();
    if(s.size()==n){
      cout<<s<<endl;
      continue;
    }
    
    char now='a';
    rep(i,s.size()) {
      if(s[i]==now) now++;
    }
    
    for(char u='a';u<=now;u++){
      q.push(s+u);
    }
  }
  
}





Measured memory_bytes: 9728
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define mod 1000000007
#define lol 200005
#define debug(x) cout<<#x<<" is "<<x<<endl;
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=b;i>=a;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vp vector<pair<double,double>>
#define vpp vector<pair<int, pair<int,int>>>
#define pp pair<int,int>

vector<int> dp(100005 , INT_MAX);

int fun(int A[], int n, int k)
{
   dp[0]=0;
   ffor(i,1,k+1)
    dp[i]=abs(A[i]-A[0]);
   
   ffor(i,k+1,n+1)
   	 ffor(j,1,k+1)
   	  dp[i]=min(dp[i], abs(A[i]-A[i-j]) + dp[i-j]);
   
   return dp[n];
}

int main()
{
	int n,k;
	cin>>n>>k;
	int A[n];
	ffor(i,0,n) cin>>A[i];
	cout<<fun(A,n-1,k)<<endl;
}

Measured memory_bytes: 4032
#include<stdio.h>
 
int main(){
	int a, i, b;
	unsigned long long int ans = 0;
	scanf("%d", &a);
	for(i = 0; i < a; i++){
		scanf("%d", &b);
		ans += b;
	}
	printf("%lld\n", ans / a);
	return 0;
}

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

int main(){
	int n,d,ans=0;
	cin >> n >> d;
	vector<vector<int>> x(n,vector<int>(d));
	for(int i = 0 ; i < n ; i += 1){
		for(int j = 0 ; j < d ; j += 1){
			cin >> x[i][j];
		}
	}
	for(int i = 0 ; i < n ; i += 1){
		for(int j = i + 1 ; j < n ; j += 1){
			int val = 0;
			for(int k = 0 ; k < d ; k += 1){
				val += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
			}
			if(sqrt(val) == ceil(sqrt(val))){
				ans += 1;
			}
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    cout << fixed << setprecision(10);
    
    ll N, A, B; cin >> N >> A >> B;
    ll ab = A+B;

    ll ans = 0;
    ans += (N / ab) * A;
    ans += min((N % ab), A);
    cout << ans << endl;
    return 0;
}

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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define Fix( x ) setprecision( x ) << fixed
#define mem( a , x ) memset( a , x , sizeof( a ) )
#define bug( a , b ) cerr<< #a <<" = "<<a<<" , "<< #b <<" = "<<b<<"\n";
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define FOR( i , a , b ) for( int i = a; i <= b; i++ )
#define ROF( i , a , b ) for( int i = a; i >= b; i-- )
#define sz( V ) (int)V.size( )
#define all( V ) V.begin( ),V.end( )
#define Found( S , val ) S.find( val ) != S.end( )
#define Unique( V ) sort( all( V ) ), V.erase( unique( all( V ) ), V.end() )
typedef pair < int , int > ii;
typedef pair < int , ii > iii;
typedef long long int LL;
typedef unsigned long long uLL;
const int inf = (int)1e9;
const LL INF = (LL)1e18;
const int N = 100005;
const int mod = 1000000007;
const double eps = 1e-8;
const double pi = acos( -1.0 );

int n , k;
int a[ N ];
int Table[ N+5 ][ 30 ] , ID[ N+5 ][ 30 ] , lg[ N+5 ];
int MN = inf;
int ans = 0;

void Build_Table( ) {
    for( int i = 1; i <= N; i++ ) Table[i][0] = a[i] , ID[i][0] = i;
    for( int i = 2; i <= N; i++ ) lg[i] = lg[i/2] + 1;
    for( int j = 1; ( 1 << j ) <= N; j++ ) {
        for( int i = 1; i+( 1 << j )-1 <= N; i++ ) {
            if( Table[i][j-1] > Table[i+(1<<(j-1))][j-1] ) {
                Table[i][j] = Table[i][j-1];
                ID[i][j] = ID[i][j-1];
            }
            else {
                Table[i][j] = Table[i+(1<<(j-1))][j-1];
                ID[i][j] = ID[i+(1<<(j-1))][j-1];
            }
        }
    }
}
int QueryMin( int l , int r ) {
    if( l > r ) swap( l , r );
    int k = lg[r-l+1];
    return min( Table[l][k] , Table[r-(1<<k)+1][k] );
}
int QueryMax( int l , int r ) {
    if( l > r ) swap( l , r );
    int k = lg[r-l+1];
    return max( Table[l][k] , Table[r-(1<<k)+1][k] );
}
int main( int argc, char const *argv[] ) {
        fast_io;
        cin >> n >> k;
        for( int i = 1; i <= n; i++ ) cin >> a[i] , MN = min( MN , a[i] );
        Build_Table( );
        int l = 1 , r = k;
        while( r <= n ) {
                int mx = QueryMax( l , r );
                //cout << mx << " "<< l << " " << r << " " << ans << endl;
                if( mx != MN ) ans++;
                if( r == n ) break;
                l = r , r = min( n , l+k-1 );
        }
        cout << ans << endl;
        return 0;
}








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

struct stu
{
	int index;
	int a;

	bool operator<(const struct stu&t)const
	{
		return a < t.a;
	}
}b[100010];
int main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		int x;
		cin >> x;
		b[i].a = x;
		b[i].index = i;

	}
	sort(b + 1, b + n + 1);

	for (int i = 1; i <= n; i++)
		cout << b[i].index << " ";
	cout << endl;
	//system("Pause");
}

Measured memory_bytes: 1664
#include<algorithm> 
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cstdio>
#include<ctime>

using namespace std;

const int maxn=15;
int n,a[maxn];

inline int read() {
	int res=0,fh=1;
	char ch=getchar();
	while((ch>'9'||ch<'0')&&ch!='-')ch=getchar();
	if(ch=='-')fh=-1,ch=getchar();
	while(ch>='0'&&ch<='9')res=res*10+ch-'0',ch=getchar();
	return fh*res;
}

int main()
{
	int a=read(),b=read();
	if((a+b)&1) return puts("IMPOSSIBLE"),0;
	else printf("%d\n",(a+b)/2);
	return 0;
}

Measured memory_bytes: 256
# 自力実装（Numpy使用）
import numpy as np
H, W = map(int, input().split())

M = np.ones((H+2,W+2),dtype=int)
for i in range(H):
  s = input()
  for j in range(W):
    M[i+1,j+1] = int(s[j] == "#")

ans = []
for i in range(1,H+1):
  for j in range(1,W+1):
    if M[i,j] == 1:
      continue
    Q = [(i,j)]
    dist = np.ones_like(M,dtype=int)*(-1)
    dist[i,j] = 0
    while len(Q) > 0:
      x,y = Q.pop(0)
      for k,l in [(1,0),(-1,0),(0,1),(0,-1),]:
        if M[x+k,y+l] == 0 and dist[x+k,y+l] == -1:
          Q.append((x+k,y+l))
          dist[x+k,y+l] = 1 + dist[x,y]
    ans.append(dist.max())
    
print(max(ans))

Measured memory_bytes: 12496
#include <iostream>
#include <algorithm>

using namespace std;

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

	int mini = 1e7;
	int maxi = -1;

	for (int i = 0; i < n; i++) {
		cin >> a;

		mini = min(mini, a);
		maxi = max(maxi, a);
	}

	cout << maxi - mini << endl;
	return 0;
}


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

int n, m, u, v;
vector<int> edge[110000];

int memo[110000];
bool done[110000];

int dp(int v){
    if(done[v])return memo[v];
    int ans = 0;
    for(int to: edge[v]){
        ans = max(ans, dp(to) + 1);
    }
    done[v] = true;
    memo[v] = ans;
    return ans;
}

int main(){
    cin >> n >> m;
    for(int i = 0;i < m;i++){
        cin >> u >> v;
        edge[u].push_back(v);
    }
    int ans = 0;
    for(int v = 1;v <= n;v++){
        ans = max(ans, dp(v));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8448
n,k=map(int,input().split())
s=input()
a=[]
cnt=0
flag=s[0]
for i in range(1,n):
  if flag==s[i]:cnt+=1
  else:
    flag=s[i]
    a+=[cnt]
    cnt=0
a+=[cnt]
print(min(sum(a)+2*k,n-1))

Measured memory_bytes: 76604
function yakusu(n) {
  var list = []
  for (var i = 1; i < n; i++) {
    if (n % i != 0) continue
    var wari = Math.floor(n / i)
    list.push(wari)
    if (wari <= 1) {
      break
    }
  }
  return list
}


function gcd(a, b) {
  if (b == 0) return a
  return gcd(b, a % b)
}

function saikou(list) {
  var hash = {}
  var len = list.length

  var tmp = 0
  for (var i = 0; i < len; i++) {
    if (tmp == 0) {
      tmp = list[i]
    } else {
      tmp = gcd(tmp, list[i])
    }
  }

  return tmp
}

function pr(s) {
  console.log(s)
}

(function(input) {
  'use strict';

  var N = null
  var X = null
  var xs = []
  input.split("\n").some(function(line) {
    if (N == null) {
      var list = line.split(' ')
      N = parseInt(list[0], 10)
      X = parseInt(list[1], 10)
      return false
    } else {
      xs = line.split(' ').map((x) => { return parseInt(x, 10) })
      return true
    }
  })

  // xs.length <= 1の処理
  if (xs.length <= 1) {
    pr(Math.abs(xs[0] - X))
    return
  }

  var abss = []
  xs.forEach((x) => {
    if (x < X) {
      abss.push(X - x)
    } else {
      abss.push(x - X)
    }
  })

  // debug
  // console.log('N')
  // console.log(N)
  // console.log('X')
  // console.log(X)
  // console.log(xs)

  console.log(saikou(abss))
})(require('fs').readFileSync('/dev/stdin', 'utf8'))



Measured memory_bytes: 28116
#include<iostream>
// #include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<deque>


#define REP(i,a,b) for(int i = (a); i < b; ++i)
#define inf 1e9+10
#define MOD 1000000007

using ll = long long;
using ull = unsigned long long;
using namespace std;

inline ll modpow(ll x, ll n, ll mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % mod;
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}

inline ll mod(ll val, ll m) {
	ll res = val % m;
	if (res < 0) res += m;
	return res;
}


int main() {
	int n;
	cin >> n;
	if (n % 2 == 0) {
		cout << n / 2;
	}
	else {
		cout << n / 2 + 1;
	}

	return 0;
}

Measured memory_bytes: 3512
#include <stdio.h>
#define MAX_LENGTH 201
int key;
int num;
int A[MAX_LENGTH];
int IsQualified(int index, int sum)
{
    if(index == num){return sum==key;}
    if(IsQualified(index + 1, sum)){return 1;}
    if(IsQualified(index + 1, sum + A[index])){return 1;}
    return 0;
}
int main() {
    int q = 0;
    int M[MAX_LENGTH];
    scanf("%d", &num);
    for(int i=0;i<num;i++){scanf("%d ", &A[i]);}
    scanf("%d", &q);
    for(int i=0;i<q;i++){scanf("%d ", &M[i]);}
    for(int i=0;i<q;i++)
    {
        key = M[i];
        if(IsQualified(0,0)==1)
            printf("yes\n");
        else
            printf("no\n");
    }
    return 0;
}



Measured memory_bytes: 2140
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

#define MOD 1000000007
#define INF 2000000000

int GLL(LL& x) {
    return scanf("%lld", &x);
}

int GI(int& x) {
    return scanf("%d", &x);
}

const int MAXN = 100010;
int a[MAXN];

int n;

int main() {
    GI(n);

    FOR1(i, n) {
        GI(a[i]);
    }

    int res = 0;

    FOR1(i, n) {
        res += (a[a[i]] == i);
    }
    
    cout << res / 2 << "\n";

    return 0;
}

Measured memory_bytes: 640
N=int(input())
ans=N
for i in range(N+1):
    cnt=0
    t=i
    while t>0:
        cnt+=t%6
        t//=6
    j=N-i
    while j>0:
        cnt+=j%9
        j//=9
    ans = min(ans,cnt)
print(ans)

Measured memory_bytes: 41068
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int n, m;
double table[128][128], memo[128][128];

double rec(int p, int prv)
{
	if(p == 0) return 1.0;
	if(memo[p][prv] != -1) return memo[p][prv];
	
	double res = -1;
	for(int i = 0; i < n; i++) chmax(res, table[prv][i] * rec(p - 1, i));
	
	return memo[p][prv] = res;
}

int main()
{
	int i, j;
	while(cin >> n >> m && n)
	{
		rep(i, n) rep(j, n) cin >> table[i][j];
		
		rep(i, 128) rep(j, 128) memo[i][j] = -1;
		
		double ans = -1;
		
		rep(i, n) chmax(ans, rec(m - 1, i));
		
		printf("%.2lf\n", ans);
	}	
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		
		System.out.println("" + a.charAt(0) + b.charAt(1) + c.charAt(2));
	}
	
}

Measured memory_bytes: 25044
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

const ll mod = 1e9 + 7;
const int N = 3010;
ll dp[N][N];

int main() {
    int n;
    string s;
    cin >> n >> s;
    dp[0][0] = 1;
    REP(i,n-1){
        ll tmp = 0;
        if (s[i] == '<'){
            REP(j,i+2){
                dp[i+1][j] = tmp;
                tmp = (tmp + dp[i][j]) % mod;
            }
        }else{
            FORR(j,i+1,0){
                tmp = (tmp + dp[i][j]) % mod;
                dp[i+1][j] = tmp;
            }
        }
    }
    ll ans = 0;
    REP(j,n) ans = (ans + dp[n-1][j]) % mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 69120
#include <iostream>
using namespace std;
int main() {
    long long x, k, d, result;
    cin >> x >> k >> d;
    x = abs(x);
    if (k > x/d) {
        long long tmpx = x;
        x %= d;
        k -= tmpx/d;
        if (k%2 == 0) {
            result = x;
        } else {
            result = d - x;
        }
    } else {
        result = x - k*d;
    }
    cout << result << endl;
}

Measured memory_bytes: 3620
#include<iostream>
#include<functional>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<iomanip>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<ll,ll>P;
using namespace std;

int main()
{
    ll n,q;
    cin>>n>>q;
    vector< vector<ll> > tree(n);
    vector<ll> ans(n,0);
    vector<ll> damage(n,0);
    vector<bool> visit(n,false);
    rep(i,n-1)
    {
        ll a,b;
        cin>>a>>b;
        a--,b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    rep(i,q)
    {
        ll a,b;
        cin>>a>>b;
        a--,b;
        damage[a]+=b;
    }
    function<void(int,int)> dfs=[&](int v,int pv)
    {
        visit[v]=true;
        if(v!=0)damage[v]+=damage[pv];
        for(auto nv:tree[v])
        {
            if(visit[nv]==false)dfs(nv,v);
        }
    };
    dfs(0,0);
    rep(i,n)
    {
        cout<<damage[i]<<" ";
    }
}

Measured memory_bytes: 28928
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;
#define _GLIBCXX_DEBUG
#define N 200010


int main() {
  ll n;
  cin >> n;
  vector<ll> A(N);
  vector<ll> B(N, 0);

  for (ll i=2;i<=n;i++){
    ll t;
    cin >> t;
    B[t] += 1;
  }

  for (ll i=1;i<=n;i++){
    cout << B[i] << endl;
  }
  
  

  return 0;
}


Measured memory_bytes: 6396
#include <cstdio>
#include <cctype>
#include <algorithm>
int N,A[200005],K;
long long Ans;
inline void read(int &Res){
	char ch=getchar();
	for (Res=0;!isdigit(ch);ch=getchar());
	for (;isdigit(ch);ch=getchar()) Res=(Res<<3)+(Res<<1)+ch-48;
}
int main(){
	read(N);
	for (int i=1;i<=N;++i) read(A[i]),A[i]-=i;
	std::sort(A+1,A+1+N);
	K=A[(N+1)/2];
	for (int i=N;i;--i) Ans+=abs(K-A[i]);
	printf("%lld",Ans);
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm>
#include <numeric>  // std::accumulate(m.begin(), m.end(), 0LL);
#include <functional>
#include <cassert>
#include <cctype>  // std::islower(), std::isupper(), std::tolower, std::toupper
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;

int main (void) {
  int N, D, X; std::cin >> N >> D >> X;
  std::vector<int> A(N); for(int i=0; i<N; i++) std::cin >> A[i];

  std::vector<int> K(D+1);
  for(int i=0; i<N; i++) {
    for(int p=0; ; p++) {
      if ( A[i]*p + 1 > D ) break;
      K[A[i]*p+1]++;
    }
  }
  
  std::cout << X + std::accumulate(K.begin(), K.end(), 0LL) << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
    char sen[20]={0},f[20]={0};
    int a,i,count=0;
    scanf("%s",sen);
    scanf("%d",&a);
    for(i=0;i<a;i++){
        scanf("%s",f);
        strncat(f,f,9);
        if(strstr(f,sen)!=NULL){
            count++;
        }
    }
    printf("%d\n",count);
return 0;
}

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

 
int main()
{
  char s1[100],s2[100]="Sunny",s3[100]="Cloudy",s4[100]="Rainy";
  cin>>s1;
  if(strcmp(s1,s2)==0)
    cout<<"Cloudy";
   else if(strcmp(s1,s3)==0)
    cout<<"Rainy";
   else if(strcmp(s1,s4)==0)
    cout<<"Sunny";
    else{}
 return 0; }

Measured memory_bytes: 256
n=int(input())
a,b=map(int,input().split())
arr=list(map(int,input().split()))
count1=0
count2=0
count3=0
for i in range(n):
    if(arr[i]<=a):
        count1+=1
    elif(arr[i]>a and arr[i]<=b):
        count2+=1
    else:
        count3+=1
print(min(min(count1,count2),count3))

Measured memory_bytes: 3064
/*
By Tianyi Chen. All rights reserved.
Date: 2018-07-14
*/
#include<bits/stdc++.h>
using namespace std;
int p,ans,t,cnt;
int main(){
 int ___L___37;scanf("%d",&___L___37);while(___L___37--){
  scanf("%d",&t);if(t==p)++cnt;
  else ans+=cnt/2,cnt=1,p=t;
 }
 ans+=cnt/2;
 printf("%d\n",ans);
}

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

int main(){
    int K,N,A;
    cin >>K >>N;
    A=0;
    vector<int> vec(N);
    for( int i=0;i<N;i++){
        cin >> vec.at(i);
    }
    for(int i=0 ;i<N-1;i++){
        if(vec.at(i+1)-vec.at(i) > A){
            A = vec.at(i+1)-vec.at(i);
        }
    }
    if(K-vec.at(N-1)+vec.at(0) > A){
        A = K-vec.at(N-1)+vec.at(0);
    }
    cout << K-A << endl;
}

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

using namespace std;

int main(){
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<pair<char, char>> v(q);
    for(int i = 0; i < q;i++){
        cin >> v[i].first >> v[i].second;
    }
    int l, r;
    l = -1, r = n;
    while(l+1!=r){
        int m = (l + r) / 2;
        int pos = m;
        for(auto x : v) {
            if(x.first==s[pos]){
                if(x.second == 'L'){
                    pos--;
                }else {
                    pos++;
                }
                if(pos == -1){
                    l = m;
                    break;
                }
            }
        }
        if(l!=m){
            r = m;
        }
    }
    int left = l; // l文字目の位置までは絶対落ちる
    l = left, r = n;
    while(l+1!=r){
        int m = (l + r) / 2;
        int pos = m;
        for(auto x:v){
            if(x.first==s[pos]){
                if(x.second=='L'){
                    pos--;
                }else{
                    pos++;
                }
            }
            if(pos == n){
                r = m;
                break;
            }
        }
        if(r!=m){
            l = m;
        }
    }
    int right = r; // r文字目の位置は右に絶対落ちる
    //cout << right << endl;
    cout << max(0, n - (left + 1) - (n - right)) << endl;
    return 0;
}

Measured memory_bytes: 900
function Main(input) {
    input = input.split("\n");
    var N = input[0].split(" ")[0];
    var K = input[0].split(" ")[1];
    var h = input[1].split(" ");
    var res = 0;
    
    for(var i = 0; i < N; i++){
        h[i] = parseInt(h[i]);
        if(K <= h[i]){
            res++
        }
    }
    console.log(res);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 16704
//
//AtCoder Beginner Contest 148
//B - Strings with the Same Length
//

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

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

using ll = long long;

const double PI = 3.14159265358979323846;
const int MOD = 1000000007;

int main()
{
    int n;
    string s, t;

    cin >> n;
    cin >> s >> t;

    string ans = "";

    rep(i, n){
        ans += s.substr(i,1) + t.substr(i,1);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  String s = sc.next();
  String t = sc.next();
  char[] c1 = s.toCharArray();
  char[] c2 = t.toCharArray();
  Arrays.sort(c1);
  Arrays.sort(c2);
  c2[0] = c2[c2.length - 1];
  String S = String.valueOf(c1);
  String T = String.valueOf(c2);
  if(S.compareTo(T) < 0)System.out.println("Yes");
  else System.out.println("No");
}}


Measured memory_bytes: 25684
#include<bits/stdc++.h>
using namespace std;
int i,j,n,m;
int main()
{
    std::cin.sync_with_stdio(false);
    std::cin.tie(0);
    cin >> n >> m;
    if (max(n,m)<=8)
    {
        cout << "Yay!";
    }
    else
    {
        cout << ":(";
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int l,n;
  int i,j;
  string s[100],tmp;
  cin>>n>>l;
  for(i=0;i<n;++i){
    cin>>s[i];
  }
  for(i=0;i<n;++i){
    for(j=i+1;j<n;++j){
      if(s[i]>=s[j]){
        tmp=s[i];
        s[i]=s[j];
        s[j]=tmp;
      }
    }
  }
  for(i=0;i<n;++i)cout<<s[i];
  cout<<endl;
  return 0;
}

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

int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    rep(i,n)cin>>a[i];
    sort(a.rbegin(),a.rend());
    ll ans=0;
    int cnt=n-1;
    rep(i,n){
        ans+=a[i];
        cnt--;
        if(cnt==0)break;
        if(i!=0)ans+=a[i],cnt--;
        if(cnt==0)break;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4040
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;


char board[50][50];

int main(void){
    int h,w;
    cin>>h>>w;
    int num = 0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>board[i][j];
            if(board[i][j]=='#')num++;
        }
    }
    if(num!=h+w-1)cout<<"Impossible"<<endl;
    else cout<<"Possible"<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

   private static final String INPUT_FILE_PATH = "";

   static void solve(InputReader in, PrintWriter out) {
      int x = in.nextInt();
      int y = in.nextInt();

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

   private static class InputReader {
      private BufferedReader br;
      private StringTokenizer st;

      public InputReader(InputStream inputStream) {
         this.br = new BufferedReader(new InputStreamReader(inputStream), 32768);
         this.st = null;
      }

      public String nextToken() {
         while (st == null || !st.hasMoreTokens()) {
            try {
               st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
               throw new RuntimeException(e);
            }
         }
         return st.nextToken();
      }

      public int nextInt() {
         return Integer.parseInt(nextToken());
      }

      public long nextLong() {
         return Long.parseLong(nextToken());
      }

      public double nextDouble() {
         return Double.parseDouble(nextToken());
      }
   }

   public static void main(String[] args) throws Exception {
      InputStream inputStream = INPUT_FILE_PATH.isEmpty()
         ? System.in
         : new FileInputStream(new File(INPUT_FILE_PATH));
      OutputStream outputStream = System.out;

      InputReader inputReader = new InputReader(inputStream);
      PrintWriter printWriter = new PrintWriter(outputStream);

      solve(inputReader, printWriter);

      printWriter.close();
   }

}


Measured memory_bytes: 32960
#include <stdio.h>
#include <stdlib.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
typedef long long ll;

int main(void)
{
    int ans = 0;

    char s[10];
    scanf("%s", s);

    if (s[2] == s[3] && s[4] == s[5])
        puts("Yes");
    else
        puts("No");

    return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python

from collections import deque
import itertools as ite
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

M, K = map(int, raw_input().split())
if M == 1 and K == 1:
    print -1
    exit()
if M == 1 and K == 0:
    print "0 0 1 1"
    exit()
if K >= 2 ** M:
    print -1
    exit()
ls = range(K) + range(K + 1, 2 ** M)
ls2 = list(ls[::-1])
ans = ls2 + [K] + ls + [K]
print " ".join(map(str, ans))

Measured memory_bytes: 26100
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for i in range(M)]

BC.sort(key=lambda x:-x[1])
temp = []
for i in range(M):
    temp += [BC[i][1]]*BC[i][0]
    if len(temp) > N:
        break
    
A += temp

A.sort(reverse = True)

print(sum(A[:N]))

Measured memory_bytes: 36148
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        int N = sc.nextInt();
        int[] s = new int[N];
        for (int i = 0; i < N; ++i) {
            s[i] = sc.nextInt();
        }

        int sum = Arrays.stream(s).sum();
        if (sum % 10 != 0) {
            _out.println(sum);
        } else {
            Arrays.sort(s);
            for (int i = 0; i < N; ++i) {
                if (s[i] % 10 != 0) {
                    _out.println(sum - s[i]);
                    return;
                }
            }
            _out.println(0);
        }
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 27220
#include<bits/stdc++.h>
using namespace std;
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long int ll;
typedef unsigned long long ull;
typedef std::vector<int> vi;
typedef std::vector<ll> vll;
typedef std::vector<vi > vvi;
typedef std::vector<vll > vvll;
typedef std::pair<int,int> ii;
typedef std::pair< ll, ll > lp;
typedef std::vector<ii> vii;
typedef std::vector<vii > vvii;


#define pb push_back 
#define PB pop_back
#define pf push_front
#define PF pop_front
#define mp make_pair
#define ub(a,b) upper_bound(all(a),b)
#define lb(a,b) lower_bound(all(a),b)
#define bs(a,b) binary_search(all(a),b)
#define mem(a,b) memset(a,b,sizeof(a))
#define in(a,n) f(i,0,n-1)cin>>a[i]
#define in1(a,n) f(i,1,n)cin>>a[i]
#define out(a,n) f(i,0,n-1)cout<<fixed<<setprecision(20)<<a[i]<<" ";cout<<"\n"
#define ff first
#define ss second
#define f(i,a,b) for (int i=a;i<=b;i++)
#define rf(i,a,b) for(int i=a;i>=b;i--)
#define rep(i,n) f(i,0,n-1)
#define clr(a) (a).clear()
#define rz resize
#define sqr(a) ((a) * (a))
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin() ,(a).rend()
#define endl '\n'

const int W=(int)1e5+5;
const int N=105;

ll dp[N][W];
ll a[N][2];

int main(int argc, char const *argv[])
{
	crap;
	int n,w;
	cin>>n>>w;
	int val,wei;
	f(i,1,n)
	{
		cin>>wei>>val;
		a[i][0]=wei,a[i][1]=val;
	}

	f(i,1,n)
	{
		f (j,1,w)
		{
			dp[i][j]=dp[i-1][j];
			if (j-a[i][0]>=0)
			{
				dp[i][j]=max(dp[i][j],a[i][1]+dp[i-1][j-a[i][0]]);
			}
		}
	}

	cout<<dp[n][w]<<endl;
	return 0;
}



Measured memory_bytes: 79360