akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <functional>
#include <map>
#include <queue>
#include <cstring>
#include <stack>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cassert>
#include <cstring>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define show(x) cout << #x << " = " << x << endl;
typedef long long ll;
typedef pair<int,int> pii;
int main(){
    int n,m;
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    vector<int>a(n);
    vector<int>x(m),y(m);
    vector<int>c(n+1,0);
    rep(i,n){
        cin >> a[i];
        c[a[i]]++;
    }
    int ans = 0;
    map<int,int>k;
    for(int i = 1; i <= n; i++){
        for(int j = i-1; j >= i-c[i] ; j--){
            k[j]++;
        }
    }
    for(int i = 0; i < n; i++){
        if(k[i] == 0){
            ans++;
        }
    }
    rep(i,m){
        cin >> x[i] >> y[i];
        x[i]--;
        int old = a[x[i]];
        int now = y[i];
        if(old == now){
            cout << ans << endl;
            continue;
        }
        k[now-c[now]-1]++;
        if(k[now-c[now]-1]==1 && now-c[now]-1>=0)ans--;
        k[old-c[old]]--;
        if(k[old-c[old]]==0 && old-c[old] >= 0)ans++;
        cout <<ans << endl;
        c[a[x[i]]]--;
        c[y[i]]++;
        a[x[i]] = y[i];
    }
    return 0;
}

Measured memory_bytes: 23424
N = int(input())
W_list = list(map(int, input().split()))

res = 200

for i in range(1, N):
    S1 = sum(W_list[:i+1])
    S2 = sum(W_list[i+1:])
    abs_val = abs(S1-S2)
    if abs_val < res:
        res = abs_val

print(res)


Measured memory_bytes: 2940
x = {'A':10, 'B':11, 'C':12, 'D':13, 'E':14, 'F':15}
a,b = map(str, input().split())
if x[a] > x[b]:
  print(">")
elif x[a] < x[b]:
  print("<")
elif x[a] == x[b]:
  print("=")

Measured memory_bytes: 9044
main :: IO ()
main = do
  [a, b] <- map read . words <$> getLine
  putStrLn $ solve a b

solve :: Int -> Int -> String
solve a b
  | (a `mod` 3 == 0) ||
    (b `mod` 3 == 0) ||
    ((a + b) `mod` 3 == 0) = "Possible"
  | otherwise = "Impossible"

Measured memory_bytes: 508
package main

import (
        "fmt"
)

func solution(n int, a []int) int {
        memo := make(map[int]bool, n)
        i, c := 0, 0
        for i != 1 {
                if memo[i] {
                        return -1
                }
                memo[i] = true
                i = a[i] - 1
                c++
        }
        return c
}

func main() {
        var n int
        fmt.Scan(&n)
        a := make([]int, 0, n)
        for i := 0; i < n; i++ {
                t := 0
                fmt.Scan(&t)
                a = append(a, t)
        }
        fmt.Println(solution(n, a))
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
#include <array>
#include <bitset>
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
using namespace std;
template <typename T> istream & operator >> (istream & is, vector<T> & vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;
using VI = vector<int>;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
	int n; CI n;
	string b = "MARCH";
	vector<string> s(n);
	int counts[5] = {};
	int m = 0,a=0,r=0,c=0,h=0;
	REP(i, n) {
		CI s[i];
		REP(j, b.size()) {
			if (s[i][0] == b[j])counts[j]++;
		}
	}

	ll ans = 0;

	REP(i, 5) {
		for (int j = i + 1; j < 5; j++) {
			for (int k = j + 1; k < 5; k++) {
				ans +=(ll)counts[i] * counts[j] * counts[k];
			}
		}
	}

	CO ans EN;

}

Measured memory_bytes: 6144
import sys

N = int(sys.stdin.readline())

A = map(int, sys.stdin.readline().strip().split(" "))

avg = 1. * sum(A) / N

near = 9999999
idx = -1
for i, a in enumerate(A):
    if near > abs(a-avg):
        near = abs(a-avg)
        idx = i

print(idx)


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

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
#define sz(x) ((int)(x).size())
#define ten(n) ((int)1e##n)
#define fst first
#define snd second
using ll=long long;
using pii=pair<int,int>;using pll=pair<ll,ll>;using pil=pair<int,ll>;using pli=pair<ll,int>;
using vs=vector<string>;using vvs=vector<vs>;using vvvs=vector<vvs>;
using vb=vector<bool>;using vvb=vector<vb>;using vvvb=vector<vvb>;
using vi=vector<int>;using vvi=vector<vi>;using vvvi=vector<vvi>;
using vl=vector<ll>;using vvl=vector<vl>;using vvvl=vector<vvl>;
using vd=vector<double>;using vvd=vector<vd>;using vvvd=vector<vvd>;
using vpii=vector<pii>;using vvpii=vector<vpii>;using vvvpii=vector<vvpii>;
template<class T> bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
ll ri(){ll l;cin>>l;return l;} string rs(){string s;cin>>s;return s;}
template<class T>T read(){T t;cin>>t;return t;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<'('<<p.fst<<", "<<p.snd<<')';}
ostream&operator<<(ostream&o,const vb&t){forr(e,t)o<<"#."[e];return o;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&t){o<<"{";forr(e,t)o<<e<<",";o<<"}"<<endl;return o;}
#ifdef LOCAL
vs s_p_l_i_t(const string&s,char c){vs v;stringstream ss(s);string x;while(getline(ss,x,c))v.emplace_back(x);return move(v);}
void e_r_r(vs::iterator it){cerr<<endl;}
template<class T,class... Args>void e_r_r(vs::iterator it,T a,Args... args){cerr<<it->substr((*it)[0]==' ',it->length())<<" = "<<a<<", ";e_r_r(++it,args...);}
#define out(args...){vs a_r_g_s=s_p_l_i_t(#args,',');e_r_r(a_r_g_s.begin(),args);}
#else
#define out(args...)
#endif

ll d(ll x, ll y, ll z) {
  return max({x, y, z}) - min({x, y, z});
}

void Main() {
  ll h = ri();
  ll w = ri();

  ll ans = 1e18;

  rep(_, 2) {
    rep(a, w) {
      ll r = w - a;
      ll a1 = h * a;

      {
        ll s = r / 2;
        ll t = r - s;
        amin(ans, d(a1, h*s, h*t));
      }
      {
        ll s = h / 2;
        ll t = h - s;
        amin(ans, d(a1, r*s, r*t));
      }
    }
    swap(h, w);
  }

  cout << ans << endl;
}
int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Main(); return 0; }


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
const int MAX_N = 200025;
long long arr[MAX_N];
int main()
{
    int n;
    long long ans = 0;
    long long now;
    scanf("%d",&n);
    for(int i = 1;i<=n;++i)
        scanf("%lld",&arr[i]);
    int l = 1,r = 2;
    now = arr[1];
    for(;l<=n;)
    {
        while(r<=n&&(now+arr[r])==(now|arr[r]))
        {
            //dbg2(now,arr[r]);
            now+=arr[r];
            r++;
        }
        //dbg2(r,l);
        ans += r-l;
        now-=arr[l];
        arr[l++];
    }
    printf("%lld\n",ans);
    return 0;
}



Measured memory_bytes: 1792
n, m = map(int, input().split())
cntAppearance = []
for i in range(m):
        cntAppearance.append(0)
for _ in range(n):
        k = list(map(int, input().split()))
        for i in k[1:]:
                cntAppearance[i-1] += 1
cnt = 0
for i in cntAppearance:
        if i == n:
                cnt += 1
print(cnt)

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

vector<int> G[100000];
int color[100000];
bool vis[100000];

void dfs(int v, int p, int cl){
	vis[v] = 1;
	color[v] = cl;
	for(auto c : G[v]){
		if(c == p || vis[c]) continue;
		dfs(c, v, 1 - cl);
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	ll N, M;
	cin >> N >> M;
	for(int i = 0; i < M; i++){
		int a, b;
		cin >> a >> b;
		a--, b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	dfs(0, -1, 0);
	ll sum[2] = { 0 };
	for(int i = 0; i < N; i++){
		for(auto c : G[i]){
			if(color[i] == color[c]){
				cout << N * (N - 1) / 2 - M << endl;
				return 0;
			}
		}
		sum[color[i]]++;
	}
	cout << sum[0] * sum[1] - M << endl;
}


Measured memory_bytes: 7040
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

const int N = 5e3 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 3e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 100000;
const int P = 199;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, 67-1};
const double EPS = 1e-4;
const double PI = acos(-1.0);

#define int ll

template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

string s;
int cnt[33], ans = 1;
main() {
    file("balance");
    ios;
    cin >> s;
    for (int i = 0; i < s.size(); ++i) {
        int num = s[i] - 'a';
        ans += i - cnt[num];
        ++cnt[num];
    }
    cout << ans;
    return 0;
}
/**

*/


Measured memory_bytes: 720
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
 
using namespace std;
using ll = long long;
// constexpr int MOD = 1e9+7;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
ll gcd(ll a, ll b){ return (b == 0) ? a : gcd(b, a % b); }
ll lcm(ll a, ll b){ return a/gcd(a, b)*b; };

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Unique(a) a.erase(unique(Range(a)), a.end());
#define Reverse(c) reverse(Range(c))
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

using Umap = unordered_map<int, ll>;

int main(void){
    Cin(int, n);
    Cins(int, n, a);
    
    int ans = 1e8;
    for(int k = -100; k <= 100; k ++){
        int r = 0;
        For(i, n) r += Sq(a[i]-k);
        ans = min(r, ans);
    }
    Cout(ans);
}


Measured memory_bytes: 256
//Square Root

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#include <cstdio>
//#include <iomanip>//"cout<<fixed<<setprecision(n)<<sth<<endl;"
//#include <string>//"reverse(s's it,s's it)"
//#include <functional>//"greater<T>" "sort(a,a+n,greater<int>());""
//#include <cmath>//"abs" "sqrt"
//#include <numeric>//"accumulate(inputit,inputit,init,(optional) object)"
//#include <algorithm>//"lower_bound(it,it,v)" "next_permutation(a,a+n)"
//"reverse(v's it,v's it)"(v: vector)
using namespace std;
#define pb push_back//also for STRING
#define fi first
#define sc second
#define mp make_pair
#define is insert
#define ps push//TMP//stack,(priority) queue,
#define fr front//TMP//queue//for priority, use top().
typedef long long ll;//not necessarily
typedef pair<int,int> pii;
//Add other types in the same way.

#define MAX_N 1500
#define MAX_M 1500

void solve(int n,int m){
	int h[MAX_N],w[MAX_M];
	for(int i=0;i<n;++i) cin>>h[i];
	for(int i=0;i<m;++i) cin>>w[i];
	map<int,int> mp;
	for(int i=0;i<n;++i){
		int sm=0;
		for(int j=i;j<n;++j){
			sm+=h[j];
			++mp[sm];
		}
	}
	int ans=0;
	for(int i=0;i<m;++i){
		int sm=0;
		for(int j=i;j<m;++j){
			sm+=w[j];
			ans+=mp[sm];
		}
	}
	cout<<ans<<endl;
	return;
}

int main(){
	while(true){
		int n,m;
		cin>>n>>m;
		if(n!=0) solve(n,m);
		else break;
	}
}

Measured memory_bytes: 20856
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main() {
	int n, x, a, b, c, i, j, k, count=0;

	while (1) {
		scanf("%d %d", &n, &x);
		if (n == 0 && x == 0) {
			break;
		}
		for ( i = 1; i <= n; i++) {
			for ( j = i + 1; j <= n; j++) {
				for ( k = j + 1; k <= n; k++) {
					if (i + j + k == x ) {
						count++;
					}
				}

			}

		}
		printf("%d\n", count);
		count = 0;
	}
}


Measured memory_bytes: 1968
#include <stdio.h>
 
int main(void){
   int N;

   scanf("%d",&N);

   if(N%10==3)
     printf("bon");
   else if(N%10==0||N%10==1||N%10==6||N%10==8)
     printf("pon");
   else
     printf("hon");
     
   return 0;
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n, k, cnt=0, p ;
    cin>>n>>k;
    for( ll i=0; i<n; i++ )
    {
        ll x, y ;
        cin >> x >> y ;
        p = (x*x) + (y*y);
        if( p <= k*k)
            cnt++;

    }
    cout<<cnt<<endl;
    return 0;
}


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

const long long MAX= 1e5 + 5;

int main(void){
  int N;
  cin >> N;
  vector<long long> a(N);
  vector<long long> bucket(MAX);

  for(long long i=0; i<N; i++){
     cin >> a[i];
     bucket[a[i]]++;
  }//for
   
  long long ans = bucket[0] + bucket[1];
  for(long long i=1; i<=MAX; i++){
     long long count = bucket[i-1] + bucket[i] + bucket[i+1];
     ans = max(ans, count);
  }//for

  cout << ans << "\n";
}//main


Measured memory_bytes: 4752
#include <iostream>
#include <iomanip>
#include <math.h>

using namespace std;

int main(void) {
	while(1) {
		int a, b, c, d, e, f;
		double x, y;
		cin >> a >> b >> c >> d >> e >> f;
		if(cin.eof()) break;

		x = (double)(e * c - b * f) / (a * e - b * d);
		y = (double)(a * f - d * c) / (a * e - b * d);
		if(x == 0) { x = 0; }
		if(y == 0) { y = 0; }

		cout << fixed << setprecision(3) << x << " " << y << endl;
	}
	return 0;
}

Measured memory_bytes: 1236
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
#include<bits/stdc++.h>
//#include <bits/extc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define mt make_tuple
//#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
#define bpc __builtin_popcount
#define base 1000000000000000000ll
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define mr mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
inline ll mul(ll a,ll b,ll c){return (a*b-(ll)((ld)a*b/c)*c+c)%c;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=mul(ans,a,c);a=mul(a,a,c),b>>=1;}return ans;}

using namespace std;
//using namespace __gnu_pbds;

const ld pi = acos(-1);
const ull ba=233;
const db eps=1e-5;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=400000+10,maxn=2000000+10,inf=0x3f3f3f3f;

int a[N],b[N],c[N],to[N];
int main()
{
    ll k;
    int n;scanf("%d%lld",&n,&k);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    for(int i=n;i;i--)b[a[i]]=i+n;
    for(int i=n;i;i--)to[i]=b[a[i]],b[a[i]]=i;
    int now=1;
    ll sum=0,res=0;
    while(!c[now])
    {
        c[now]=1;
        sum+=to[now]-now+1;
        now=to[now]+1;
        while(now>n)now-=n;
    }
    int ty=now;
    while(1)
    {
        res+=to[ty]-ty+1;
        ty=to[ty]+1;
        while(ty>n)ty-=n;
        if(ty==now)break;
    }
    auto gao = [&](int p,ll s)
    {
        while(to[p]-p+1<=s)
        {
            s-=to[p]-p+1;
            p=to[p]+1;
            while(p>n)p-=n;
        }
        memset(c,0,sizeof c);
        int top=0;
        for(int i=1;i<=s;i++)
        {
            if(!c[a[p]])b[++top]=a[p],c[a[p]]=top;
            else
            {
                int te=c[a[p]]-1;
                for(int i=c[a[p]];i<=top;i++)c[b[i]]=0;
                top=te;
            }
            p++;
            if(p>n)p-=n;
        }
        for(int i=1;i<=top;i++)printf("%d ",b[i]);
    };
    if(k*n<=sum)gao(1,k*n);
    else gao(1,(k*n-sum)%res);
    return 0;
}
/********************

********************/


Measured memory_bytes: 6912
#include <iostream>
using namespace std;
int main()
{
  int a, b;
  cin >> a >> b;
  if( a == b )
    cout << "Draw";
  else if( a == 1 )
    cout << "Alice";
  else if( b == 1 )
    cout << "Bob";
  else if( a > b )
    cout << "Alice";
  else cout << "Bob";
}

Measured memory_bytes: 3048
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int main(int argc, const char * argv[]) {
    long D,N;
    cin >> D >> N;
    
    vector<long> ans;
    int i = 0;
    long s = 0;
    while (1) {
        s += 100;
        if (s % 10000 != 0 && s % 1000000 != 0) {
            i++;
            ans.push_back(s);
        }
        if (i==100) break;
    }
    /*
    cout << ans.size() << "\n";
    
    for (int ind = 0; ind < ans.size(); ind++) {
        cout << ans[ind] << "\n";
    }
    */
    if (D == 0) {
        if (N < 100) {
            cout << N << "\n";
        } else {
            cout << 101 << "\n";
        }
    } else if (D == 2) {
        if (N < 100) {
            cout << N * 10000 << "\n";
        } else {
            cout << 1010000 << "\n";
        }
    } else {
        cout << ans[N-1] << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 256
H, W = gets.split.map(&:to_i)
board = H.times.map { gets.chomp.chars }

def bfs(board, s)
  distance = [
    [-1, 0],
    [1, 0],
    [0, -1],
    [0, 1]
  ]
  ret = 0
  used = {}
  used[s] = true
  # pos, distance
  queue = [[s, 0]]
  while !queue.empty?
    pos, d = queue.shift
    ret = d if d > ret
    i, j = pos
    distance.each do |(id, jd)|
      new_i = i + id
      new_j = j + jd
      next if new_i < 0 || new_i >= H || new_j < 0 || new_j >= W
      next if board[new_i][new_j] == '#'
      new_pos = [new_i, new_j]
      next if used[new_pos]
      used[new_pos] = true
      queue.push([new_pos, d + 1])
    end
  end
  ret
end

ans = 0
(0...H).each do |i|
  (0...W).each do |j|
    if board[i][j] == '.'
      pos = [i, j]
      ret = bfs(board, pos)
      ans = ret if ret > ans
    end
  end
end
puts ans

Measured memory_bytes: 2172
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
	int N, M, K[10], P[10], s[10][10];
	int i, j, k;
	int ans = 0,sw,ch;
	cin >> N >> M;
	for (i = 0; i < M; i++) {
		cin >> K[i];
		for (j = 0; j < K[i]; j++) {
			cin >> s[i][j];
		}
	}
  
	for (i = 0; i < M; i++) cin >> P[i];
	for (i = 0; i < pow(2,N); i++) {
		ch = 1;
		for (j = 0; j < M; j++) {
			sw = 0;
			for (k = 0; k < K[j]; k++) {
				if ((i / (int)pow(2, s[j][k] - 1)) % 2) sw++;
			}
			if (sw % 2 != P[j]) ch = 0;
		}
		ans += ch;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
package main

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

func main() {
	io := newIo()
	defer io.Flush()
	N, Q := io.NextInt(), io.NextInt()
	points := map[int]int{}
	edges := map[int][]int{}
	for i := 0; i < N-1; i++ {
		a, b := io.NextInt(), io.NextInt()
		edges[a] = append(edges[a], b)
		edges[b] = append(edges[b], a)
	}
	for i := 0; i < Q; i++ {
		a, point := io.NextInt(), io.NextInt()
		points[a] = points[a] + point
	}
	totalPoints := map[int]int{}
	totalPoints[1] = points[1]
	q := []int{1}
	log("edges", edges)
	log("points", points)
	for len(q) > 0 {
		qq := q[0]
		q = q[1:]
		currentPoint := totalPoints[qq]
		for _, edge := range edges[qq] {
			_, exists := totalPoints[edge]
			if exists {
				continue
			}
			log("edge", edge)
			totalPoints[edge] = currentPoint + points[edge]
			q = append(q, edge)
		}
	}
	for i := 1; i < N+1; i++ {
		fmt.Print(totalPoints[i])
		if i < N {
			fmt.Print(" ")
		}
	}
	fmt.Println("")
}

type io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func newIo() *io {
	return &io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *io) PrintIntLn(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func (io *io) PrintStringLn(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func log(name string, value interface{}) {
	// fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}


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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

string a;

int main() {
	cin >> a;
	if (a[0]==a[2]) cout << "Yes" << ln;
	else cout << "No" << ln;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;


int main(){
	int x, a, b;
	cin >> x >> a >> b;
	cout << (x - a) % b << endl;
	return 0;
}

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

using namespace std;

int a[4][50][50];
int main() {
	int n, p = 1e9 + 7;
	long k;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		a[2][i][i] = 1;
		for (int j = 0; j < n; j++)
			cin >> a[0][i][j];
	}
	int x = 0, y = 2;
	auto f = [&](int &z) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				long t = 0;
				for (int l = 0; l < n; l++)
					(t += a[x][i][l] * (long)a[z][l][j]) %= p;
				a[z ^ 1][i][j] = t;
			}
		}
		z ^= 1;
	};
	while (k) {
		if (k & 1) f(y);
		if (k >>= 1) f(x);
	}
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			k += a[y][i][j];
	cout << k % p << endl;
	return 0;
}


Measured memory_bytes: 256
// ABC076B - 

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

typedef unsigned long long int ull;
typedef long long int ll;

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

	int ans = 1;

	for (int i = 0; i < N; i++) {
		ans = min(2 * ans, ans + K);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

int n;
int f[110][12];
int p[110][12];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    rep(i, 0, n){
        rep(j, 0, 10){
            cin >> f[i][j];
        }
    }
    rep(i, 0, n){
        rep(j, 0, 11){
            cin >> p[i][j];
        }
    }
    int ans = -INF;
    rep(i, 1, (1LL << 10)){
        int tmp = 0;
        rep(j, 0, n){
            int cnt = 0;
            rep(k, 0, 10){
                if((i & (1LL << k)) && f[j][k]) cnt++;
            }
            tmp += p[j][cnt];
        }
        chmax(ans, tmp);
    }
    cout << ans << endl;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll W, H, N;
    cin >> W >> H >> N;
    ll Xl = 0, Xu = W, Yl = 0, Yu = H;
    REP(i,0,N) {
        ll x, y, a;
        cin >> x >> y >> a;
        if(a == 1) Xl = MAX(Xl,x);
        if(a == 2) Xu = MIN(Xu,x);
        if(a == 3) Yl = MAX(Yl,y);
        if(a == 4) Yu = MIN(Yu,y);
    }

    ll yoko = MAX(Xu-Xl,0);
    ll tate = MAX(Yu-Yl,0);
    PR(tate*yoko);

    return 0;
}

/*



*/

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  int flag = 0;
  cin >> n;
  for(int i = 0 ; (n - 4*i) >= 0 ; i++){
    if( (n - 4*i) % 7 == 0){
      cout << "Yes" << endl;
      flag = 1;
      break;
    }
  }
      if( flag == 0 ){
      cout << "No" << endl;
    }
}

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

using namespace std;

typedef long long ll;

template<typename T>
void _dump(const char* s, T&& head)
{
  cerr << s << "=" << head << endl;
}

template<typename T, typename... Args>
void _dump(const char* s, T&& head, Args&&... tail)
{
  while (*s != ',')
    cerr << *s++;
  cerr << "=" << head << ",";
  _dump(s + 1, tail...);
}

template<typename T>
void _dumpv(const char* s, T&& v)
{
  cerr << *s << "=";
  for (auto it = v.begin(); it != v.end(); it++) {
    cerr << *it << " ";
  }
  cerr << endl;
}

template<typename T>
void _dumpv2(const char* s, T&& v)
{
  cerr << *s << "=";
  for (auto it = v.begin(); it != v.end(); it++) {
    cerr << it->first << ":" << it->second << " ";
  }
  cerr << endl;
}

#define dump(...) _dump(#__VA_ARGS__, __VA_ARGS__)
#define dumpv(...) _dumpv(#__VA_ARGS__, __VA_ARGS__)
#define dumpv2(...) _dumpv2(#__VA_ARGS__, __VA_ARGS__)

const ll MOD = 1000000007;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("template.1", "r", stdin);

  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> A(N + 1);
  vector<int> B(N + 1);
  dump(N, M);
  // dumpv(A);
  dumpv(B);
  int i;
  for (i = 1; i <= N; i++) {
    int a;
    cin >> a >> B[i];
    A[i] = make_pair(a, i);
  }
  sort(A.begin(), A.end());
  dumpv2(A);
  dumpv(B);
  ll ans = 0;
  for (i = 1; i <= N; i++) {
    if (B[A[i].second] < M) {
      M -= B[A[i].second];
      ans += ((ll)A[i].first * (ll)B[A[i].second]);
    } else {
      ans += ((ll)A[i].first * (ll)M);
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1536
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

template<typename Monoid> class SegTree {
  using T = typename Monoid::value_type;

  Monoid m;
  std::vector<T> tree; // 1-indexed
  int size = 1;

  void _update(int i) { tree[i] = m(tree[i * 2], tree[i * 2 + 1]); }

public:
  SegTree(const int n = 0) {
    while (size < n) size *= 2;
    tree.assign(size * 2, m.id());
  }

  template<typename InputIterator> SegTree(InputIterator first, InputIterator last) {
    int n = std::distance(first, last);
    while (size < n) size *= 2;
    tree.resize(size * 2, m.id());
    std::copy(first, last, tree.begin() + size);
    for (int i = size - 1; i >= 1; i--) _update(i);
  }

  T fold(int l, int r) { // [l, r)
    T accl = m.id(), accr = m.id();
    for (l += size, r += size; l < r; l /= 2, r /= 2) {
      if (l & 1) accl = m(accl, tree[l++]);
      if (r & 1) accr = m(tree[--r], accr);
    }
    return m(accl, accr);
  }

  void update(int i, const T &x) {
    tree[i += size] = x;
    while (i /= 2) _update(i);
  }

  const T &operator[](int i) const { return tree[i + size]; }
};

template<typename T, T upperInf = std::numeric_limits<T>::max()> struct minMonoid {
  using value_type = T;
  constexpr value_type id() { return upperInf; }
  constexpr value_type operator()(const value_type &a, const value_type &b) { return a < b ? a : b; }
};

main {
  using RMQ = SegTree<minMonoid<int, 2147483647>>;
  int n, q;
  cin >> n >> q;
  RMQ t(n);
  while (q--) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com) {
      cout << t.fold(x, y + 1) << endl;
    } else {
      t.update(x, y);
    }
  }
}

Measured memory_bytes: 4876
import sys


def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    I = range(1, N+1)
    dic = dict(zip(I, A))
    dic2 = sorted(dic.items(), key=lambda x: x[1])
    ans = []
    for i in dic2:
        ans.append(i[0])
    print(*ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 78824
n = gets().to_i
a = gets().split(" ")
b = gets().split(" ")
c = gets().split(" ")

sum = 0

index0 = 0
index1 = 0

for i in 0..n-1 do
  if i != 0
    index0 = a[i].to_i-1
  end

  sum += b[a[i].to_i-1].to_i

  if index0-1 == index1
    sum += c[a[i].to_i-2].to_i
  end
    
  index1 = a[i].to_i-1
end

p sum

Measured memory_bytes: 1788
#include <stdio.h>

int main() {
	int weight, input;

	while(scanf("%d", &input) != EOF) {
		weight = 1024;
		int i = 0;
		int out[10] = {0};
		int j;

		while(weight = weight / 2) {
			if(input / weight) {
				out[i] = weight;
				i++;
			}

			input = input % weight;
		}

		while(out[i]) i++;
		
		for(j = 0; i - 1 - j > 0; j++)
			printf("%d ", out[i - 1 - j]);
		printf("%d\n", out[0]);
	}

	return 0;
}

Measured memory_bytes: 596
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib> 
#include <ctime>
#include <unordered_map>
using namespace std;
typedef long long ll;
int N; ll A[300000];
const ll MOD = (ll)1e9 + 7;
int main() {
	cin >> N;
	int i, j;
	for (i = 0; i < N; i++) cin >> A[i];
	ll x[64][2];
	for (i = 0; i < 60; i++) x[i][0] = x[i][1] = 0;
	for (i = 0; i < 60; i++) {
		for (j = 0; j < N; j++) {
			int a = (A[j] >> i) & 0x1;
			x[i][a]++;
		}
	}
	ll ans = 0;
	for (i = 0; i < 60; i++) {
		ll a = x[i][0] * x[i][1];
		a %= MOD;
		a = a * ((1ll << i) % MOD);
		a %= MOD;
		ans += a;
		ans %= MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
main()
{
	int n,k;
	cin>>n>>k;
	int h[n+1];
	h[0]=0;
	for(int i=1;i<=n;i++)
	cin>>h[i];
	int dp[n+1];
	dp[0]=0;
	int min1;
	dp[1]=0;
	if(k<=n)
	{
	for(int i=2;i<=k;i++)
	{
		min1=dp[i-1]+abs(h[i]-h[i-1]);
		for(int j=1;j<=i-1;j++)
		{
			if(min1>dp[i-j]+abs(h[i]-h[i-j]))	
			min1=dp[i-j]+abs(h[i]-h[i-j]);
		}
		dp[i]=min1;	
	}
	for(int i=k+1;i<=n;i++)
	{
		min1=dp[i-1]+abs(h[i]-h[i-1]);
		for(int j=1;j<=k;j++)
		{
			if(min1>dp[i-j]+abs(h[i]-h[i-j]))
			min1=dp[i-j]+abs(h[i]-h[i-j]);
		}
		dp[i]=min1;
	}
	cout<<dp[n];
	}
	else
	{
		for(int i=2;i<=n;i++)
	{
		min1=dp[i-1]+abs(h[i]-h[i-1]);
		for(int j=1;j<=i-1;j++)
		{
			if(min1>dp[i-j]+abs(h[i]-h[i-j]))	
			min1=dp[i-j]+abs(h[i]-h[i-j]);
		}
		dp[i]=min1;	
	}
      cout<<dp[n];
	}
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;

int main(){
    int rep;
    cin >> rep;
    for(int r=0; r<rep; r++){
        vector<pair<int, char> > card(9);
        for(int i=0; i<9; i++) cin >> card[i].first;
        for(int i=0; i<9; i++) cin >> card[i].second;
        sort(card.begin(), card.end());
        bool win = false;
        do{
            bool flag = true;
            for(int i=0; i<9; i+=3){
                if(card[i].second == card[i+1].second && card[i].second == card[i+2].second){
                    if((card[i].first +1 == card[i+1].first && card[i].first +2 == card[i+2].first)
                       || (card[i].first == card[i+1].first && card[i].first == card[i+2].first)){
                    }else{
                        flag = false;
                    }
                }else{
                    flag = false;
                }
            }
            if(flag) win = true;

        }while(next_permutation(card.begin(), card.end()));
        if(win){
            cout << 1 << endl;
        }else{
            cout << 0 << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3052
#include <iostream>

using namespace std;

int main(void){
  int N;
  cin >> N;
  int A[N];
  int i, j;
  for(i=0; i<N; i++)
    cin >> A[i];

  int max_abs = 0;
  for(i=0; i<N; i++){
    for(j=i; j<N; j++){
      if(max_abs < abs(A[i]-A[j])) //max_absよりも大きい差があれば
	max_abs = abs(A[i]-A[j]); //max_absを更新
    }
  }

  cout << max_abs << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define MAX 10000
#define NIL -1

typedef struct { int parent, left, right;} Node;

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u,int d) {
	if(u == NIL) return;
	D[u] = d;
	setDepth(T[u].left, d+1);
	setDepth(T[u].right,d+1);
}

int setHeight(int u) {
	int h1 = 0, h2 = 0;
	if(T[u].left != NIL)
	h1 = setHeight(T[u].left) + 1;
	if(T[u].right != NIL)
	h2 = setHeight(T[u].right) + 1;
	return H[u] = (h1 > h2 ? h1 : h2);
}

// 接点 u の兄弟を返す
int getSibling(int u) {
	if( T[u].parent == NIL ) return NIL;
	if(T[T[u].parent].left != u && T[T[u].parent].left != NIL )
	return T[T[u].parent].left;
	if(T[T[u].parent].right != u && T[T[u].parent].right != NIL )
	return T[T[u].parent].right;
	return NIL;
}

void print(int u) {
	printf("node %d: ",u);
	printf("parent = %d, ",T[u].parent);
	printf("sibling = %d, ",getSibling(u));
	int deg = 0;
	if(T[u].left  != NIL) deg++;
	if(T[u].right != NIL) deg++;
	printf("degree = %d, ",deg);
	printf("depth = %d, ",D[u]);
	printf("height = %d, ",H[u]);
	  if(T[u].parent == NIL) {
	  	printf("root\n");
	  } else if(T[u].left == NIL && T[u].right == NIL) {
	  	printf("leaf\n");
	  } else {
	  	printf("internal node\n");
	  }
}

int main(void) {
	int v, l, r, root = 0;
	scanf("%d",&n);
	for(int i=0;i<n;i++) T[i].parent = NIL;
	for(int i=0;i<n;i++) {
		scanf("%d %d %d",&v,&l,&r);
		T[v].left  = l;
		T[v].right = r;
		if(l != NIL) T[l].parent = v;
		if(r != NIL) T[r].parent = v;
	}
	
	for(int i=0; i<n; i++)
	if(T[i].parent == NIL) root = i;
	
	setDepth(root,0);
	setHeight(root);
	
	for(int i=0;i<n;i++) print(i);

	return 0;
}


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

int main(){
  string s;
  cin>>s;
  bool val=true;
  for(int i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      val=false;
      break;
    }
  }
  
  if(val){
    cout<<"Good";
  }
  else{
    cout<<"Bad";
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+5; 
vector<array<int,2> > adj[N]; 
vector<int> ans(N,0); 
void dfs(int u,int p,int prev,int mx){
for(auto& i: adj[u]){
if(i[0]!=p){
prev=(prev%mx)+1; 
ans[i[1]]=prev; 
dfs(i[0],u,ans[i[1]],mx); 
}
}
}
int main(){
int n; cin>>n;
int u,v; 
for(int i=0;i<n-1;i++){ cin>>u>>v; adj[u].push_back({v,i}); adj[v].push_back({u,i}); }
int mx=0; 
for(int i=1;i<=n;i++) mx=max(mx,(int)adj[i].size()); 
dfs(1,0,0,mx);
cout<<mx<<endl; 
for(int i=0;i<n-1;i++) cout<< ans[i]<<endl ;
return 0; 
}

Measured memory_bytes: 11332
n=int(input())
a=[int(input()) for i in range(n)]
if a[0]!=0:
    print(-1)
    exit()

ans=0
for i in range(n)[::-1]:
    if a[i]-a[i-1]>1:
        print(-1)
        exit()
    elif a[i]<=a[i-1]:
        ans+=a[i]
    else:
        ans+=1
print(ans)




Measured memory_bytes: 11052
n,m = map(int, input().split())

S = [[] for _ in range(n)]

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

rows = [[] for _ in range(n)]
cols = [[] for _ in range(m)]

start = [[] for _ in range(n)]
end = [[] for _ in range(n)]

for i in range(n):
    rows[i].append(-1)
    for j in range(m):
        if(S[i][j] == '#'):
            rows[i].append(j)
    rows[i].append(m)

    l = 0
    r = 1
    cnt = 0

    for j in range(m):
        if(S[i][j] != '#'):
            start[i].append(rows[i][r] - rows[i][l])
        else:
            start[i].append(0)
        if(j == rows[i][r]):
            l = r
            r = r + 1
ans = 0
for i in range(m):
    cols[i].append(-1)

    for j in range(n):
        if(S[j][i] == '#'):
            cols[i].append(j)
    cols[i].append(n)

    l = 0
    r = 1
    cnt = 0

    for j in range(n):
        if(S[j][i] != '#'):
            end[j].append(cols[i][r] - cols[i][l])
            # ans = max(ans, start[j][i], end[j][i])
        else:
            end[j].append(0)
        if(j == cols[i][r]):
            l = r
            r = r + 1
        



for i in range(n):
    for j in range(m):
        # if(S[i][j] != '#'):
            ans = max(ans, start[i][j] + end[i][j])

print(ans - 3)




Measured memory_bytes: 504788
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

    public static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        String c = sc.next();
        PriorityQueue<Integer> w = new PriorityQueue<>();
        PriorityQueue<Integer> r = new PriorityQueue<>(Collections.reverseOrder());
        for (int i = 0; i < n; i++) {
            if (c.charAt(i) == 'W') {
                w.add(i);
            } else {
                r.add(i);
            }
        }
        if (w.isEmpty() || r.isEmpty()) {
            System.out.println(0);
            return;
        }
        int cnt = 0;
        while (true) {
            if (w.isEmpty() || r.isEmpty()) {
                System.out.println(cnt);
                return;
            }
            int ww = w.poll();
            int rr = r.poll();
            if (ww > rr) {
                System.out.println(cnt);
                return;
            }
            cnt++;
        }
    }
}

Measured memory_bytes: 47960
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

using namespace std;
typedef long long ll;
const ll MAX_N = 100 + 1;
const ll MAX_W = 100000 + 1;
ll w[MAX_N];
ll v[MAX_N];
ll dp[MAX_N][MAX_W];

int main() {

  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  ll N, W;
  cin >> N >> W;
  for(ll i = 1; i <= N; i++) cin >> w[i] >> v[i];

  dp[0][0] = 0;
  for(ll i = 1; i <= N; i++) {
    for(ll j = 0; j <= W; j++) {
      if(j - w[i] < 0) dp[i][j] = dp[i-1][j];
      else dp[i][j] = max(dp[i-1][j-w[i]] + v[i], dp[i-1][j]);
    }
  }

  ll ans = 0;
  for(ll j = 0; j <= W; j++) ans = max(ans, dp[N][j]);
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 81184
<?php
$a = (int)trim(fgets(STDIN));
$b = (int)trim(fgets(STDIN));
$c = (int)trim(fgets(STDIN));
$d = (int)trim(fgets(STDIN));
$e = (int)trim(fgets(STDIN));
$k = (int)trim(fgets(STDIN));

if ($e-$a > $k) {
	echo ':(';
}else{
	echo 'Yay!';
}


Measured memory_bytes: 4604
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  int sum = 0;
  for(int i=1;i<N+1;i++)
  {
    for(int j=1;j<N+1;j++)
    {
      for(int k=1;k<N+1;k++)
      {
        int l = gcd(i,j);
        sum += gcd(l,k);
      }
    }
  }
  cout << sum << endl;
  return 0;
}


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

void solve() {
    long long int n;
    cin >> n;
    
    long long int mod = 1e9+7;
    
    long long int ten = 1, nine = 1, eight = 1;
    for(int i=1; i<=n; i++) {
        ten = (ten*10)%mod;
        nine = (nine*9)%mod;
        eight = (eight*8)%mod;
    }
    
    nine = (2*nine)%mod;
    
    // cout << ten << endl << nine<< endl << eight << endl;
    
    cout << (ten-nine+eight+mod)%mod << endl;
}

int main() {
	// your code goes here
	
	solve();
	
	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	sort(A.begin(), A.end());
	int ans = A[N - 1] - A[0];
	for (int i = 1; i < N - 1; i++) ans += abs(A[i]);
	cout << ans << endl;
	int n = 0, m = N - 1;
	int MIN = A[n], MAX = A[m];
	for (int i = 0; i < N - 2; i++) {
		if (A[n + 1] < 0) {
			cout << MAX << " " << MIN << endl;
			MAX = MAX - MIN;
			n++;
			MIN = A[n];
		}
		else {
			cout << MIN << " " << MAX << endl;
			MIN = MIN - MAX;
			m--;
			MAX = A[m];
		}
	}
	cout << MAX << " " << MIN << endl;
}


Measured memory_bytes: 2304
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<string> mp(n), mp2(n);
  for (int i = 0; i < n; i++)
    cin >> mp[i];
  for (int i = 0; i < n; i++)
    mp2[i] = mp[i];

  long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++)
      mp2[j] = mp[(j + i) % n];
    bool b = true;
    for (int j = 0; j < n; j++)
      for (int k = 0; k < n; k++)
        if (mp2[j][k] != mp2[k][j])
          b = false;
    if (b)
      ans += n;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include<cmath>
using namespace std;
#define ll long long int 
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main()
{
 	fastio;
 	int n;
 	cin>>n;
 	int a[n+1];
 	for (int i = 1; i <=n; ++i)
 	{
 		cin>>a[i];
 	}
 	int cnt=0;
 	for (int i = 1; i <=n; i+=2)
 	{
 		if(a[i]&1)
 			cnt++;
 	}
 	cout<<cnt;
 	
	return 0;
	
}

Measured memory_bytes: 3608