akhauriyash/Code-Regression huggingface dataset:
// 根付き木の表現
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>

using namespace std;

#define MAX_N 100005
const int NIL = -1;

typedef struct v_node_num
{
    // 節点の親
    int parent;
    // 節点の左の子
    int left_child;
    // 節点の右の兄弟
    int right_brother;
}Node;

Node T[MAX_N];
int n;
int D[MAX_N];

// u : 要素No.
void print(int u)
{
    int i, c;

    cout << "node " << u << ": ";
    cout << "parent = " << T[u].parent << ", ";
    cout << "depth = " << D[u] << ", ";

    // -----▼▼▼▼▼ ノード情報の表示 ▼▼▼▼▼-----

    if( T[u].parent == NIL )
    {
        // 親が存在しないので、root
        cout << "root, ";
    }
    else if( T[u].left_child == NIL )
    {
        // 左の子がいないので、leaf
        cout << "leaf, ";
    }
    else
    {
        cout << "internal node, ";
    }

    // -----▲▲▲▲▲ ノード情報の表示 ▲▲▲▲▲-----

    // -----▼▼▼▼▼ 各節点の子の要素の表示 ▼▼▼▼▼-----

    cout << "[";

    for ( i = 0, c = T[u].left_child; c != NIL; i++, c = T[c].right_brother )
    {

        if( i )
        {
            cout  << ", ";
        }

        cout << c;
    }

    cout << "]" << endl;

    // -----▲▲▲▲▲ 各節点の子の要素の表示 ▲▲▲▲▲-----

    return;

}

// 再帰的に深さを求める
// u : 要素No.
// p : 要素の深さ
int rec(int u, int p)
{
    D[u] = p;

    if( T[u].right_brother != NIL )
    {
        // 右の兄弟に同じ深さを設定
        rec(T[u].right_brother, p);
    }

    if( T[u].left_child != NIL)
    {
        // 最も左の子に[ 自分の深さ + 1 ]を設定
        rec(T[u].left_child, p + 1);
    }

    return 0;
}

int main(void)
{
    int i, j, d, node_num, node, left, right;

    cin >> n;

    for( i = 0; i < n; i++)
    {
        // 全要素の初期化
        T[i].parent = NIL;
        T[i].left_child = NIL;
        T[i].right_brother = NIL;
    }

    for( i = 0; i < n; i++ )
    {
        cin >> node_num >> d;

        for( j = 0; j < d; j++ )
        {
            cin >> node;

            if( j == 0 )
            {
                // 左の子を設定する
                T[node_num].left_child = node;
            }
            else
            {
                // 右の兄弟を設定する
                T[left].right_brother = node;
            }

            // 右の兄弟を設定するために, nodeの情報を設定する
            left = node;
            // 親の情報を設定
            T[node].parent = node_num;
        }
    }

    for( i = 0; i < n; i++ )
    {
        if( T[i].parent == NIL )
        {
            // ルートの要素を検索する
            right = i;
        }
    }

    rec(right, 0);

    for( i = 0; i < n; i++ )
    {
        print(i);
    }

    return 0;
}



Measured memory_bytes: 7764
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,t;
    cin >> n >> t;
    vint mx(n+1,0);
    vint a(n,0);
    REP(i,n) cin >> a[i];
    REP(i,n){
        mx[n-1-i] = max(a[n-1-i], mx[n-i]);
    }
    int cnt = 0;
    int x = 0;
    REP(i,n-1){
        if(mx[i+1]-a[i]==x){
            cnt++;
        }else if(mx[i+1]-a[i]>x){
            cnt = 1;
            x = mx[i+1]-a[i];
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
char a[100005];
int x=0,y=0,ans=0;
int main() {
	cin>>a;
	for (int i=0; i<sizeof(a); i++)
		if (x==y) {
			x++;  
			if(a[i]=='p') ans--;
		} else {
			y++;   
			if(a[i]=='g') ans++;
		}
	printf("%d\n",ans);                     
	return 0;
}

Measured memory_bytes: 384
#!/usr/bin/env python3
import sys

            

def dfs(s,n):
    ret = 0
    if int(s) > n:
        return 0
    else:
        
        ret = 1 if all(s.count(c) > 0 for c in '753') else 0
        for c in "753":
            ret += dfs(s+c,n)

    return ret
            




def solve(N: str):
    print(dfs("0",int(N)))


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = next(tokens)  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
N = int(input())

def checkAGC(string):
    str0 = string[0] +string[1] +string[2] +string[3]
    str1 = string[1] +string[0] +string[2] +string[3]
    str2 = string[0] +string[2] +string[1] +string[3]
    str3 = string[0] +string[1] +string[3] +string[2]
    
    if "AGC" in str0 or "AGC" in str1 or "AGC" in str2 or "AGC" in str3:
        return True
    else:
        return False

def checkAGC3(string):
    str0 = string[0] +string[1] +string[2]
    str1 = string[1] +string[0] +string[2] 
    str2 = string[0] +string[2] +string[1] 
    
    if "AGC" in str0 or "AGC" in str1 or "AGC" in str2 :
        return True
    else:
        return False
      

import itertools

words = list(itertools.product("ATGC", "ATGC","ATGC"))

#3文字のインデックスを返す
nucleotide_dict =  dict(list( (words[i],i) for i in range(len(words))))

import numpy as np
# 重み行列を求める
W = np.zeros((len(words),len(words)))
for word_prev in words:
    for word_next in words:
        if word_prev[1:] == word_next[:-1] and not checkAGC(word_prev[:-1]+word_next[1:]):
            #print(nucleotide_dict[word_next],nucleotide_dict[word_prev],word_prev[:-1]+word_next[1:] )
            W[nucleotide_dict[word_next],nucleotide_dict[word_prev]] = 1
b = np.array([0 if checkAGC3(i) else 1 for i in words])

def mod(num):
    return num % int(pow(10,9)+7)
  
res = b
for i in range(N-3):
    res = np.vectorize(lambda x: mod(x))(np.dot(W,res))
print(int(mod(np.sum(res))))


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

int main() {
    int n;cin>>n;
    int a[n];rep(i,n)cin>>a[i];
    
    sort(a,a+n);
    rep(i,n-1){
        if(a[i+1]==a[i]){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 4392
#!/usr/bin/env python3
# coding: utf-8
# ?§£??¬??????????????????????????¨????????¨??¬??¬????????§??????

# input & calc
n = int(input())
max_diff = -20**9
minv = 20**9
for i in range(n):
    r = int(input())
    max_diff = max(max_diff, r - minv)
    minv = min(minv, r)

# output
print(max_diff)

Measured memory_bytes: 7664
#include <iostream>
#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 R;
	cin >> R ;
	float result;
	result = 2*3.14*(float)R;
	cout << result << endl;
	return 0 ;

}


Measured memory_bytes: 3788
#include <iostream>
#include <algorithm>
using namespace std;
 
int main() {
	int w, h, n;
	cin >> w >> h >> n; 
	int w1 = 0, w2 = w, h1 = 0, h2 = h; 
	for(int i = 0; i < n; i++){
		int x, y, a; 
		cin >> x >> y >> a; 
		if(a == 1) w1 = max(w1, x);
		else if(a == 2) w2 = min(w2, x);
		else if(a == 3) h1 = max(h1, y);
		else if(a == 4) h2 = min(h2, y);
	}
	cout << max(w2 - w1, 0) * max(h2 - h1, 0) << endl; 
}

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

int main() {
    string s;
    int i, cnt;
    cin >> s;
    for (i = 0; i < s.length(); i++) {
        if (s[i] == '1') {
            ++cnt;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define MAX_N 100000

using namespace std;
typedef pair<int, int> ipair;

class Node {
public:
    vector<int> children;
    vector<int> distance;
};

int N;
Node nodes[MAX_N + 1];
bool is_black[MAX_N + 1];
bool is_visited[MAX_N + 1];

void solve(int node) {
    is_visited[node] = true;
    
    for(int i = 0; i < nodes[node].children.size(); ++i)
    if(!is_visited[nodes[node].children[i]]) {

        if(nodes[node].distance[i] % 2 == 0)
            is_black[nodes[node].children[i]] = is_black[node];
        else
            is_black[nodes[node].children[i]] = !is_black[node];

        solve(nodes[node].children[i]);
    }
}

int main(int argc, char **argv) {
    cin >> N;
    for(int i = 0; i < N - 1; ++i) {
        int u, v, w;
        cin >> u >> v >> w;
        nodes[u].children.push_back(v);
        nodes[u].distance.push_back(w);

        nodes[v].children.push_back(u);
        nodes[v].distance.push_back(w);
    }

    is_black[1] = true;
    is_visited[1] = true;
    solve(1);

    for(int i = 1; i <= N; ++i)
        printf("%d\n", is_black[i]);
    
}

Measured memory_bytes: 13440
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(i, x, n) for (int i = x; i < n; i++)
#define fb(i, x, n) for (int i = n - 1; i >= 0; i--)
#define w(t) int t; cin >> t; while (t--)



typedef unsigned long long ull;
typedef vector<long long> vi;
#define ull unsigned long long
#define msi map<string, long long>
#define mii map<long long, long long>
const int MX = 2e5 + 5;
const int INF = 1e18;
#define pb push_back
#define endl "\n"
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define all(x) x.begin(), x.end()
#define ff first
#define ss second


int32_t main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    // online submission
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    string s;
    cin >> s;
    int cnt{0};
    int mx = 0;
    f(i,0,s.size())
    {
        if(s[i]=='R')
        {
            cnt++;
            mx = max(mx, cnt);
        }
        else
        {
            cnt = 0;
        }
        
    }
    cout << mx << endl;

    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
    return 0;
}

Measured memory_bytes: 3788
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<map>
#include<unordered_map>
#include<queue>
#include<deque>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()
 
int main(){
    ll n, t;
    cin >> n >> t;
    vector<ll> a(n), b(n);

    rep(i, n)cin >> a[i] >> b[i];

    vector<ll> ord(n);
    iota(ALL(ord), 0);
    sort(ALL(ord), [&](ll x, ll y){
        if(a[x] == a[y])return b[x] < b[y];
        return a[x] < a[y];
    });

    ll dp[n+1][t];
    rep(i, t)dp[0][i] = 0;

    rep(i, n-1){
        // cout << b[ord[i+1]] << endl;
        rep(j, t){
            ll pos = ord[i];
            if(j-a[pos]>=0)dp[i+1][j] = max(dp[i][j], dp[i][j-a[pos]]+b[pos]);
            else dp[i+1][j] = dp[i][j];
        }
    }
    ll ans = 0;
    rep(i, n-1)ans = max(ans, dp[i+1][t-1]+b[ord[i+1]]);
    cout << ans << endl;
}

Measured memory_bytes: 70656
N = int(input())
S = input()

L = 0
R = 0
cnt = 0
d = []
for s in S:
    if s == "(":
       cnt += 1
    else:
        cnt -= 1
        if cnt < 0:
            cnt = 0
            L += 1

R += cnt

print(L*"(" + S + R*")")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const long double PI = 3.14159265358979323846;
const int mod = 1e9 + 7;
const ll maxSize = 3e5;
ll h, w, a, b, modInv[maxSize], fact[maxSize], factInv[maxSize];

ll nCm(ll n, ll m) {
    return (n - m >= 0 && m >= 0) ? fact[n] * factInv[m] % mod * factInv[n - m] % mod : 0;
}

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

    fact[0] = 1; fact[1] = 1;
    for (int i = 2; i < maxSize; ++i) {
        fact[i] = fact[i - 1] * i % mod;
    }
    modInv[1] = 1;
    for (int i = 2; i < maxSize; ++i) {
        modInv[i] = modInv[mod % i] * (mod - mod / i) % mod;
    }
    factInv[0] = 1;
    for (int i = 1; i < maxSize; ++i) {
        factInv[i] = factInv[i - 1] * modInv[i] % mod;
    }
    cin >> h >> w >> a >> b;
    ll sum = 0;
    for (int i = 0; i < h - a; ++i) {
        sum += nCm(b + i - 1, b - 1) * nCm(w - b - 1 + h - 1 - i, w - b - 1);
        sum %= mod;
    }
    cout << sum << '\n';

    return 0;
}


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

#if DEBUG && !ONLINE_JUDGE
    #include "header.h"
#else
    #define debug(args...)
#endif

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long lli;
typedef long double ld;

#define pb push_back
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x).size()
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b) for(auto i=(a);i<b;i++)

#define INF (int)1e9
#define EPS 1e-9
#define MOD 1000000007
void preprocess(void) {
    return;
}
#define maxW 100002
lli dp[105][maxW];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(20);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    preprocess();
    int n,W; cin>>n>>W;
    vi w(n+2), v(n+2);
    rep(i,1,n+1) {
        cin>>w[i]>>v[i];
    }
    memset(dp,0,sizeof dp);
    rep(i,1,n+1) {
        rep(j,0,W+1) {
            if(j>=w[i]) {
                dp[i][j] = max(dp[i-1][j-w[i]] + v[i], dp[i-1][j]);
                debug(i,j,dp[i][j]);
            }
            else dp[i][j] = dp[i-1][j];
        }
    }
    cout<<dp[n][W]<<endl;
}



Measured memory_bytes: 82304
import itertools
N = int(input())
A = [3,5,7]
s = len(str(N))
ALL = []
for keta in range(3,s+1):
  ALL.extend(list(itertools.product(A, repeat=keta)))
#print(ALL)
ans = 0
for num in ALL:
  L = set(num)
  if 3 not in L or 5 not in L or 7 not in L:
    continue
  temp = ""
  for i in num:
    temp += str(i)
  number = int(temp)
  if number <= N:
    #print(number)
    ans += 1
print(ans)

Measured memory_bytes: 12488
#include<stdio.h>
int main(void){
  int i,j,n,c=0,b=0,s=0;
  char in[100];
  int ten[100]={0};
  
  scanf("%d",&n);
  while(c!=n){
    scanf("%s",in);
    switch(in[1]-'A'){
    case 8:b++;break;  //i hit
    case 20:s++;break;  //u out   
    case 14:ten[c]+=b+1;b=0;break;//o homerun
    }
    if(b==4){ten[c]++;b=3;}
    if(s==3){c++;b=0;s=0;}
  }

  for(i=0;i<n;i++){
    printf("%d\n",ten[i]);
  }
  return 0;

}

Measured memory_bytes: 596
// https://atcoder.jp/contests/abc161/tasks/abc161_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    cout << c << " " << a << " " << b << endl;
    return 0;
}


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

typedef long long ll;

ll N;
ll Sum;
const ll INF = 1ll << 60;
ll MinNonTen = INF;

int main() {
  cin >> N;
  for (ll i = 0; i < N; ++i) {
    ll s;
    cin >> s;
    Sum += s;
    if (s % 10 != 0) MinNonTen = min(MinNonTen, s);
  }
  cout << (Sum % 10 != 0 ? Sum : MinNonTen != INF ? Sum - MinNonTen : 0)
       << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
A = list(map(int,input().split()))

def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

pc = True

fac = [0]*(10**6+1)
for a in A:
    lst = factorize(a)
    for p in lst:
        if not fac[p[0]]:
            fac[p[0]] = 1
        else:
            pc = False
            break
    if not pc:
        break
if pc:
    print('pairwise coprime')
else:
    g = A[0]
    for i in range(1,n):
        g = gcd(g, A[i])
    if g == 1:
        print('setwise coprime')
    else:
        print('not coprime')

Measured memory_bytes: 189256
#include<bits/stdc++.h>
using namespace std;
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
#define sz(a) ll(a.size())
ll a[200005],nxt[200005];
vector<vector<ll>> v(200005);
void solve(){
	ll n,res=0;
	cin>>n;
	for(ll i=1;i<=n;i++)
		cin>>a[i];
	for(ll i=1;i<=n;i++)
		if(!a[i]){
			ll j=i;
			while(j<=n&&a[j]==0)
				j++;
			while(i<j){
				nxt[i]=j;
				i++;
			}
			i--;
		}
		else
			nxt[i]=i+1;
	for(ll i=1;i<=n;i++){
		ll x=a[i];
		while(x){
			if(x&1)
				v[i].push_back(1);
			else
				v[i].push_back(0);
			x>>=1;
		}
		while(sz(v[i])<20)
			v[i].push_back(0);
		reverse(v[i].begin(),v[i].end());
	}
	for(ll i=1;i<=n;i++){
		vector<ll> cur(20,0);
		ll j=i;
		while(j<=n){
			ll f=0;
			for(ll k=0;k<20;k++)
				if(cur[k]==1&&v[j][k]==1){
					f=1;
					break;
				}
				else
					cur[k]^=v[j][k];
			if(f)
				break;
			j=nxt[j];
		}
		res+=j-i;
	}
	cout<<res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
    clock_t z=clock();
    ll qc=1;
    //cin>>qc;
    for(ll i=1;i<=qc;i++){
        solve();
    }
    debug("Total Time:%.4Lf\n",(ld)(clock()-z)/CLOCKS_PER_SEC);
}

Measured memory_bytes: 64224
#include <iostream>

using namespace std;

int main(){
    int n;
    int A[100];
    int i, j, key;

    cin >> n;
    
    for(i=0; i<n; i++){
        cin >> A[i];
    }

    for(i=0; i<n; i++){
        key = A[i];
        j = i - 1;
        while(j>=0 && A[j] > key){
            A[j+1] = A[j];
            j = j - 1;
        }
        A[j+1] = key;
        for(j=0; j<n; j++){
            cout << A[j];
            if(j!=n-1){
                cout << ' ';
            }
        }
        cout << "\n";
    }
}

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

// using mint = modint1000000007;
// using mint = modint998244353;

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << '\n'; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) std::cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << '\n';
}

Int d[101][101];

void solve() {
    Int h, w;
    cin >> h >> w;
    vector<string> v(h);
    for (Int i = 0; i < h; i++) {
        cin >> v[i];
    }
    for (Int i = 0; i < h; i++) {
        for (Int j = 0; j < w; j++) {
            d[i][j] = INF;
        }
    }
    d[0][0] = 0;
    deque<pair<Int, Int>> q;
    q.push_front({0, 0});
    while (not q.empty()) {
        pair<Int, Int> p = q.front();
        q.pop_front();
        Int dy[] = {1, 0};
        Int dx[] = {0, 1};
        for (Int i = 0; i < 2; i++) {
            Int ny = dy[i] + p.first;
            Int nx = dx[i] + p.second;
            if (ny < 0 or ny == h or nx < 0 or nx == w) continue;
            if (v[p.first][p.second] == '#' and v[ny][nx] == '.') {
                if (d[ny][nx] > d[p.first][p.second] + 1) {
                    d[ny][nx] = d[p.first][p.second] + 1;
                    q.push_back({ny, nx});
                }
            } else {
                if (d[ny][nx] > d[p.first][p.second]) {
                    d[ny][nx] = d[p.first][p.second];
                    q.push_front({ny, nx});
                }
            }
        }
    }
    if (v[h  -1][w - 1] == '#') d[h - 1][w - 1]++;
    print(d[h - 1][w - 1]);
}   

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

class UnionFind {
public:
    vector<int> par;
    int num;

    UnionFind(int n) : par(n, -1), num(n) {};

    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }

    int size(int x) {
        return -par[root(x)];
    }

    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (size(x) < size(y)) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        num--;
        return true;
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    int a[m], b[m];
    rep(i, 0, m) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }

    int ans = 0;
    rep(i, 0, m) {
        UnionFind uf(n);
        rep(j, 0, m) {
            if (i == j) continue;
            uf.unite(a[j], b[j]);
        }
        if (uf.num >= 2) ans++;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    char c[5];
    scanf("%s",c);
    if(strcmp("abc",c)==0)
    {
        printf("Yes\n");}
        else if(strcmp("acb",c)==0)
        {
            printf("Yes\n");
        }
        else if(strcmp("bac",c)==0)
        {
            printf("Yes\n");
        }
        else if(strcmp("bca",c)==0)
        {
            printf("Yes\n");
        }
        else if(strcmp("cab",c)==0)
        {
            printf("Yes\n");
        }
        else if(strcmp("cba",c)==0)
        {
            printf("Yes\n");
        }
        else
        {
            printf("No\n");
        }

    return 0;
}


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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }

int main(){
  ll i, j;
  ll n;
  cin >> n;
  ll result = 0;
  bool judge = true;

  
  vector<ll> a(n),b(n + 1);
  for(i = 0; i < n; i++)
    cin >> a[i];
  b[0] = 0;
  for(i = 0; i < n; i++)
    b[i + 1] = b[i] + a[i];
  unordered_map<ll, ll> p, q;
  ll count = 0;
  for(i = 0; i < n + 1; i++){
    if(b[i] == 0)
      count++;
    else{
      if(p.find(b[i]) == p.end()){
        p.insert(make_pair(b[i], 1));
      }
      else
        p[b[i]]++;
    }
  }
  
  result += count * (count - 1) / 2;
  for(auto itr = p.begin(); itr != p.end(); itr++){
    result += itr->second * (itr->second - 1) / 2;
  }
    
                    
  
  
  /*
  if(judge)
    //cout << "Yes" << endl;
    //cout << "YES" << endl;
    //cout << "Yay!" << endl;
  else
    //cout << "No" << endl;
    //cout << "NO" << endl;
    //cout << ":(" << endl;
  */
  
  cout << result << endl;

  return 0;
}

Measured memory_bytes: 11592
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

int main ()
{
	char S[100000+521];
	memset(S,0,sizeof(S));
	cin >> S;
	int ans=0;
	for(int i = 0;S[i+1]!=0;i++)
	{
		if(S[i]!=S[i+1])
			ans++;
	}
	cout << ans;
	return 0;
}

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

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  int a[m], b[m];
  for (int i = 0; i < m; i++) cin >> a[i] >> b[i];
  vector<int> v[n];
  for (int i = 0; i < m; i++) {
    v[a[i] - 1].push_back(b[i] - 1);
    v[b[i] - 1].push_back(a[i] - 1);
  }
  bool memo[n]; memset(memo, 0, sizeof(memo));
  deque<int> res;
  int vv = 0; 
  memo[vv] = 1; res.push_back(vv + 1);
  while (1) {
    bool flag = 1;
    for (auto i : v[vv]) {
      if (not memo[i]) {
        vv = i;
        memo[vv] = 1; res.push_back(vv + 1);
        flag = 0; break;
      }
    }
    if (flag) break;
  }
  vv = 0;
  while (1) {
    bool flag = 1;
    for (auto i : v[vv]) {
      if (not memo[i]) {
        vv = i;
        memo[vv] = 1; res.push_front(vv + 1);
        flag = 0; break;
      }
    }
    if (flag) break;
  }
  cout << res.size() << "\n";
  for (auto i : res) cout << i << " ";
  cout << "\n";
  return 0;
}

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

using namespace std ;

const int MAX = 2e5 + 10 ;

int arr[MAX] , ans[MAX] ;
int n ;

string s ;


int calc(int x)
{
	int cnt = 1 ;
	while(x > 0)
	{
		x %= __builtin_popcount(x) ;
		cnt++ ;
	}
	return cnt ;
}

void solve(char c)
{
	int mod = count(s.begin() , s.end() , '1') ;
	if(c == '1')
		mod-- ;
	else
		mod++ ;
	if(mod <= 0)
		return ;
	int cur = 1 , sum = 0 ;
	for(int i = n-1 ; i >= 0 ; --i)
	{
		arr[i] = cur ;
		if(s[i] == '1')
			sum = (sum + arr[i]) % mod ;
		cur = (cur * 2) % mod ;
	}
	for(int i = 0 ; i < n ; ++i)
	{
		int x = sum ;
		if(s[i] == c)
		{
			if(c == '1')
				x = (x - arr[i] + mod) % mod ;
			else
				x = (x + arr[i]) % mod ;
			ans[i] = calc(x) ;
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n ;
	cin>>s ;
	solve('0') ;
	solve('1') ;
	for(int i = 0 ; i < n ; ++i)
		cout<<ans[i]<<"\n" ;
	return 0 ;
}		

Measured memory_bytes: 5352
from itertools import permutations
N,Col = map(int,input().split())
D = [[0 for _ in range(Col+1)]]
for _ in range(Col):
    d = list(map(int,input().split()))
    d.insert(0,0)
    D.append(d)
A = [list(map(int,input().split())) for _ in range(N)]
C = {0:{},1:{},2:{}}
for i in range(N):
    for j in range(N):
        c = (i+j)%3
        a = A[i][j]
        if a not in C[c]:
            C[c][a] = 0
        C[c][a] += 1
dmin = 10**10
for x in permutations(range(1,Col+1),3):
    cnt0 = 0
    for c in C[0]:
        cnt0 += C[0][c]*D[c][x[0]]
    cnt1 = 0
    for c in C[1]:
        cnt1 += C[1][c]*D[c][x[1]]
    cnt2 = 0
    for c in C[2]:
        cnt2 += C[2][c]*D[c][x[2]]
    dmin = min(dmin,cnt0+cnt1+cnt2)
print(dmin)

Measured memory_bytes: 76436
#include<cstdio>
#include<cstring>

int v[3001],a[3001][3001],n,x,y,fa[3001],f[3001];

bool dfs(int x)
{
	for (int i=1; i<=a[x][0]; i++)
		if (a[x][i]!=fa[x]&&v[a[x][i]]<v[x]) {fa[a[x][i]]=x; if (!dfs(a[x][i])) return 1;}
	return 0;
}

int main()
{
	scanf("%d",&n);
	for (int i=1; i<=n; i++) scanf("%d",&v[i]),a[i][0]=0;
	for (int i=1; i<n; i++) scanf("%d%d",&x,&y),a[x][++a[x][0]]=y,a[y][++a[y][0]]=x;
	for (int i=1; i<=n; i++)
	{
		memset(f,0,sizeof(f));
		memset(fa,0,sizeof(fa));
		if (dfs(i)) printf("%d ",i);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 33792
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

long long dp[51][51][50 * 50 + 1]; // dp[index][num of cards][sum] = 総数

int main() {
    int n, a; cin >> n >> a;
    vector<int> x(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }

    dp[0][0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int sum = 0; sum < 50 * 50 + 1; sum++) {
                if (sum + x[i] < 50 * 50 + 1) {
                    dp[i + 1][j + 1][sum + x[i]] += dp[i][j][sum];
                }

                dp[i + 1][j][sum] += dp[i][j][sum];
            }
        }
    }

    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int sum = 1; sum <= 50 * 50 + 1; sum++) {
            if (sum == a * i) {
                ans += dp[n][i][sum];
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 50048
#include <bits/stdc++.h>
//#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<double,double> P;
const ll INF = 4*1e18;
const int MOD = 1000000007;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

int n,m,s[2100],t[2100],dp[2100][2100];
signed main(){
  cin>>n>>m;
  rep(i,n)cin>>s[i+1];
  rep(j,m)cin>>t[j+1];
  rep(i,n+1)dp[i][0] = 1;
  rep(i,m+1)dp[0][i] = 1;
  repd(i,1,n+1){
    repd(j,1,m+1){
      dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD;
      if(s[i] != t[j])dp[i][j] = (dp[i][j] - dp[i-1][j-1] + MOD) % MOD;
    }
  }
  cout << dp[n][m] << endl;
}


Measured memory_bytes: 33152
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<string, int, int> TU;
typedef tuple<int, int, int> TI;

int main()
{
    ll N;
    cin >> N;
    if(N%2==0){
        cout <<N << endl;
    }else{
        cout << N*2 << endl;
    }

}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int A, B, K;
    cin >> A >> B >> K;
    int cnt = 0;
    for (int i = min(A, B); i >= 1; i--) {
        if (((A % i) == 0) && ((B % i) == 0)) cnt++;
        if (cnt == K) {
            cout << i << '\n';
            return 0;
        }
    }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
	Scanner kbd = new Scanner(System.in);
	
	int a, d, n;
	while(kbd.hasNext()) {
	    a = kbd.nextInt();
	    d = kbd.nextInt();
	    n = kbd.nextInt();
	    if(a!=0 && d!=0 && n!=0)
		solve(a,d,n);
	}
    }

    static void solve(int a, int d, int n) {
	while(n>0) {
	    if(a!=1)
		if(isPrime(a)) n--;
	    if(n == 0) System.out.println(a);
	    a = a+d;
	}
    }

    static boolean isPrime(int a) {
	int f = (int)Math.sqrt(a);
	while(a%f > 0) f--;
	return f == 1;
    }
}

	

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

int main(){
    int A,B,a,b,n=-1;
    cin >> A >> B;
    for(int i=0;i<10000;i++){
        a=i*0.08;
        b=i*0.1;
        if(A==a && B==b){
            n=i;
            break;
        }
    }
    cout << n;
}

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


main()
{
	int n,mx=0,sum=0;
	cin >> n;
	for(int i=0;i<n;i++)
	{
		int a;
		cin >> a;
		sum+=a;
		mx=max(mx,a);
	}
	cout<< sum-mx/2;
	
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define pb push_back

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b); i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a-1)
#define trav(x, a) for (auto& x: a)

const int MX  = 2e5+5;
const int MOD = 1e9+7;
const ll  INF = 1061109567; // 4557430888798830399LL
const ld  EPS = 1e-9;
const ld  PI  = acos(-1);

ll arr[MX];

int main() {

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

    int N,T; cin >> N >> T;

    F0R(i,N) {
        cin >> arr[i];
    }

    ll res = T, ac = T;
    FOR(i,1,N) {
        if (arr[i] < ac) {
            res -= abs(arr[i]-ac);
        }
        res += T; ac = arr[i]+T;
    }

    cout << res << "\n";
}


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

int main(){
	list<int> l;
	int commands;
	char command[20];
	int data;
	cin >> commands;

	for(int i=0;i<commands;i++){
		cin >> command;
		if(command[0]=='i'){
			cin >> data;
			l.push_front(data);
		}else if(command[6]=='F'){
			l.pop_front();
		}else if(command[6]=='L'){
			l.pop_back();
		}else if(command[0]=='d'){
			cin >> data;
			for(list<int>::iterator itr=l.begin();itr!=l.end();++itr){
				if(*itr==data){
					l.erase(itr);
					break;
				}
			}	
		}
	}
	list<int>::iterator last=l.end();--last;
	for(list<int>::iterator itr=l.begin();itr!=l.end();++itr){
		cout << *itr;
		if(itr!=last)cout<<" ";
	}
	cout << endl;
	return 0; 
}

Measured memory_bytes: 34232
#include <bits/stdc++.h>
#define rep(i,n)for(unsigned long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const int MAX = 510000;


int main() {
  string s;
  cin >> s;
  int n = s.size();
  ll sum = 0;
  ll sumA=0;
  for(int i=0;i<n-1;i++){
    if(s[i]=='A'){
      sumA++;
    }
    else if(s[i]=='B' && s[i+1]=='C'){
      sum += sumA;
      i++;
    }
    else sumA=0;
  }
  cout << sum << endl;  
}


Measured memory_bytes: 640
n,k = gets.split.map(&:to_i)
k = k+1
a = gets.split.map(&:to_i)

t = 50.times.map{|i| [
  a.map{|a|  a & (1<<i)}.inject(&:+),
  a.map{|a| ~a & (1<<i)}.inject(&:+),
]}


puts 50.times.map {|i|
  next 0 if k[i] == 0

  sum = 0
  sum += (i+1..49).map{|i| t[i][k[i]]}.inject(0,&:+)
  sum += t[i][0]
  sum += (0..i-1).map{|i| t[i].max}.inject(0,&:+)

  sum
}.max


Measured memory_bytes: 42428
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

    int k, a, b; cin>>k>>a>>b;

    for(int i=a; i<=b; i++){
        if(i % k == 0){
            cout << "OK" << endl;
            return 0;
        }
    }

    cout << "NG" << endl;

    return 0;
}

Measured memory_bytes: 3612
#define N 2000005
#include <stdio.h>

int A[N];
int B[N];
int C[10005];

//输入数组，输出数组，数组长度，元素最大值
void CountingSort(int A[], int B[], int n, int k) {
    for (int i = 0; i <= k; i++) {
        C[i] = 0;
    }
    for (int i = 0; i < n; i++) {
        C[A[i]]++;
    }
    for (int i = 1; i <= k; i++) {
        C[i] = C[i - 1] + C[i];
    }
    for (int i = n - 1; i >= 0; i--) {
        B[C[A[i]]] = A[i];
        C[A[i]]--;
    }
}


int main() {
    int n = 0;    
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }
    CountingSort(A, B, n, 10005);
    for (int i = 1; i <= n; i++) {
        if (i > 1) {
            printf(" ");
        }
        printf("%d", B[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 17452
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;

#define lld long long

int main() {
    int N;
    int sum[200001];
    memset(sum,0,sizeof(sum));
    cin >> N;
    for(int i=0;i<N-1;i++){
        int a;
        cin >> a;
        sum[a-1]++;
    }
    for(int i=0;i<N;i++){
        cout << sum[i] << endl;
    }
    return 0;
}

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

#define HEAP priority_queue
#define rep(i, n) for(int i = 0, _end_ = (n); i < _end_; ++i)
#define per(i, n) for(int i = (n) - 1; i >= 0 ; --i)
#define forn(i, l, r) for(int i = (l), _end_ = (r); i <= _end_; ++i)
#define nrof(i, r, l) for(int i = (r), _end_ = (l); i >= _end_; --i)
#define FOR(a, b) for(auto (a): (b))
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define X first
#define Y second
#define eps 1e-6
#define pi 3.1415926535897932384626433832795
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(), x.end()
#define FILL(a, b) memset((a), (b), sizeof((a)))
#define MCPY(a, b) memcpy((a), (b), sizeof((b)))

using namespace std;

typedef long long LL;
typedef double flt;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef pair<int,int> pii;
typedef pair<int,LL> pil;
typedef pair<LL,int> pli;
typedef pair<LL,LL> pll;
typedef vector<pil> vil;
typedef vector<pii> vii;
typedef vector<pli> vli;
typedef vector<pll> vll;

const int iinf = 1e9 + 7;
const int oo = 0x3f3f3f3f;
const LL linf = 1ll << 60;
const flt dinf = 1e60;

template <typename T>
inline void scf(T &x)
{
	bool f = 0; x = 0; char c = getchar();
	while((c < '0' || c > '9') && c != '-') c = getchar();
	if(c == '-') { f = 1; c = getchar(); }
	while(c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
	if(f) x = -x; return;
}
template <typename T1, typename T2>
void scf(T1 &x, T2 &y) { scf(x); return scf(y); }
template <typename T1, typename T2, typename T3>
void scf(T1 &x, T2 &y, T3 &z) { scf(x); scf(y); return scf(z); }
template <typename T1, typename T2, typename T3, typename T4>
void scf(T1 &x, T2 &y, T3 &z, T4 &w) { scf(x); scf(y); scf(z); return scf(w); }

inline char mygetchar(){ char c = getchar(); while(c == ' ' || c == '\n') c = getchar(); return c; }

template <typename T> inline bool chkmax(T &x, const T &y){ return y > x ? x = y, 1 : 0; }
template <typename T> inline bool chkmin(T &x, const T &y){ return y < x ? x = y, 1 : 0; }

#ifdef ONLINE_JUDGE
#define debug(...) ;
#else
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define DEBUG
#endif

//---------------------------------------------------------head----------------------------------------------------

const int maxn = 1e5 + 100;

int n;
int a[3][maxn];
bool f[2], g[2];
vi b[2];

namespace BIT
{
	int num[maxn];
	int lowbit(int i){ return i & (-i); }
	void M(int i, int x)
	{
		for(; i; i ^= lowbit(i)) num[i] += x;
		return;
	}
	int Q(int i)
	{
		int ret = 0;
		for(; i <= n; i += lowbit(i)) ret += num[i];
		return ret;
	}
	void C(){ FILL(num, 0); }
}

void solve(vi &a, bool &f)
{
	BIT::C();
	for(int x: a)
	{
		f ^= (BIT::Q(x) & 1);
		BIT::M(x, 1);
	}
	return;
}

int main()
{
	scf(n);
	rep(i, 3) forn(j, 1, n) scf(a[i][j]);
	forn(i, 1, n)
	{
		int x = a[1][i] - a[0][i], y = a[2][i] - a[1][i];
		if(x != y || abs(x) != 1){ puts("No"); return 0; }
		if(x == -1) f[i & 1] ^= 1;
		a[1][i] -= 2;
		if(a[1][i] % 3 != 0){ puts("No"); return 0; }
		a[1][i] /= 3;
		if(!((a[1][i] ^ i) & 1)){ puts("No"); return 0; }
		b[i & 1].pb(a[1][i] + 1);
	}
	rep(_, 2) solve(b[_], g[_]);
	puts(g[0] == f[1] && g[1] == f[0] ? "Yes" : "No");
	return 0;
}

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

int main() {
    ll n; cin >> n;
	ll ans = 0;
  
    if (n == 1) ans = 0;
	
    else {
        queue<ll> que;

        ll d = 2;
        while(n >= d * d) {
            if(n % d == 0) {
                ll t = 0;
               while(n % d == 0) {
                  n /= d;
                  ++t;
                }   
                que.push(t);
            }
            else {
                if (d == 2) ++d;
                else d += 2;
            }
        }
      	if (n != 1)
        	que.push(1);

        while(!que.empty()) {
            ll x = que.front();
            que.pop();

            ans += (ll)((-1.0 + sqrt(1.0 + 8.0 * x)) / 2);
        }
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("2");
            WillReturn.Add("10 30");
            //7.5
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("3");
            WillReturn.Add("200 200 200");
            //66.66666666666667
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("1");
            WillReturn.Add("1000");
            //1000
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();

        decimal[] AArr = InputList[1].Split(' ').Select(X => decimal.Parse(X)).ToArray();

        decimal Answer = 0;

        for (int I = 0; I <= AArr.GetUpperBound(0); I++) {
            Answer += 1 / AArr[I];
        }
        Console.WriteLine(1 / Answer);
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int main(void)
{
    int n; cin >> n;
    do {
        int a[n+1][n+1];
        memset(a, 0, sizeof(a));
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                cin >> a[i][j];
                a[i][n] += a[i][j];
                a[n][j] += a[i][j];
                a[n][n] += a[i][j];
            }
        }
        for (int i = 0; i < n+1; i++) {
            for (int j = 0; j < n+1; j++) {
                cout << right << setw(5) << a[i][j];
            }
            cout << endl;
        }
        cin >> n;
    } while (n != 0);
    return 0;
}

Measured memory_bytes: 3068
#include<bits/stdc++.h>
using namespace std;
int m[100005]={0};
int main()
{
	int n,k,q,a;
	scanf("%d %d %d",&n,&k,&q);
	for(int i=0;i<q;i++){
		scanf("%d",&a);
		m[a]++;
	}
	for(int i=1;i<=n;i++)
		if(k-q+m[i]>0) printf("Yes\n");
		else printf("No\n");
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int a[10];
bool flag;

void dfs(int n, int l, int r) 
{
    if (n == 10) {
        flag = true;
        return ;
    }

    if (a[n] > l)
        dfs(n + 1, a[n], r);
    if (a[n] > r)
        dfs(n + 1, l, a[n]);

    return ;
}

int main()
{
    int n;

    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 10; j++)
            cin >> a[j];

        flag = false;
        dfs(0, 0, 0);
        if (flag)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 1152
package main

import (
	"fmt"
	"math"
	"math/big"
)

var memo2 map[uint64]uint64

func main() {
	var n uint64
	fmt.Scan(&n)
	memo2 = map[uint64]uint64{}
	var sum uint64
	var a, b, c uint64
	for a = 1; a <= n; a++ {
		for b = 1; b <= n; b++ {
			for c = 1; c <= n; c++ {
				sum += gcd(a, gcd(b, c))
			}
		}
	}
	fmt.Println(sum)

}

func gcd(m, n uint64) uint64 {
	if v, ok := memo2[m*1000+n]; ok {
		return v
	}
	x := new(big.Int)
	y := new(big.Int)
	z := new(big.Int)
	a := new(big.Int).SetUint64(m)
	b := new(big.Int).SetUint64(n)
	res := z.GCD(x, y, a, b).Uint64()
	memo2[m*1000+n] = res
	return res
}

//-------------------------------------------
// util tools

// abs 絶対値を返す
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// sliceInt []intをスライスする
func sliceInt(k int) []int {
	s := make([]int, getDigit(k))
	count := 0
	for k > 0 {
		i := k % 10
		s[len(s)-1-count] = i
		count++
		k = k / 10
	}
	return s
}

// sliceIntSum []intの合計を出す
func sliceIntSum(v []int) int {
	sum := 0
	for _, x := range v {
		sum += x
	}
	return sum
}

// reverse []intを反転
func reverse(s []int) []int {
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		s[i], s[j] = s[j], s[i]
	}
	return s
}

// getDigit intの桁数を取得
func getDigit(num int) int {
	digit := 0
	for num != 0 {
		num /= 10
		digit++
	}
	return digit
}

// getSumDigit intの各位の和を返す
func getSumDigit(num int) int {
	sum := 0
	for num != 0 {
		t := num % 10
		num /= 10
		sum += t
	}
	return sum
}

// lastPrime 素数 エラトステネスの篩
func lastPrime(max int64) int64 {
	if max <= 1 {
		return 2
	}
	primes := make([]int64, 1, max)
	primesF := make([]float64, 1, max)
	primes[0] = 2
	primesF[0] = 2.0

	count := int64(1)
	for n := int64(3); ; n += 2 {
		flag := true
		f := float64(n)
		rf := math.Sqrt(f)
		for i := 1; i < len(primes); i++ {
			if primesF[i] > rf {
				break
			} else if (n % primes[i]) == 0 {
				flag = false
				break
			}
		}
		if flag {
			count++
			if count >= max {
				return n
			}
			primes = append(primes, n)
			primesF = append(primesF, f)
		}
	}
}


Measured memory_bytes: 6436
<?php
// D
fscanf(STDIN, '%d %d %d', $N, $M, $Q);
$l = array_fill(0, $N, array_fill(0, $N, 0));
for ($i  = 0; $i < $M; $i++) {
    fscanf(STDIN, '%d %d', $L, $R);
    $L--;
    $R--;
    $l[$L][$R - $L]++;
}
for ($i = 0; $i < $N; $i++) {
    for ($j = 0; $j < $N; $j++) {
        $cusum[$i][$j] = $l[$i][$j] + $cusum[$i][$j - 1] ?? 0;
    }
}
for ($i  = 0; $i < $Q; $i++) {
    fscanf(STDIN, '%d %d', $p, $q);
    $p--;
    $q--;
    $d = $q - $p;
    $sum = $cusum[$p][$d];
    for ($j = 1; $j <= $d; $j++) {
        $sum += $cusum[$p + $j][$d - $j];
    }
    $ans[] = $sum;
}
echo implode(PHP_EOL, $ans);

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

int main(){
  
  int n;
  cin>>n;
  int a[n],b[n]={0}; 
  vector<int> P={};
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=n;i>0;i--){
    
    if(a[i-1]==1&&b[i-1]%2==0||a[i-1]==0&&b[i-1]%2==1){
      P.push_back(i);
      for(int j=1;j<=sqrt(i);j++){
        if(i%j==0){
          if(j*j!=i){ b[j-1]++;}
          b[i/j-1]++;
        }
      }
    }
    
  }
  
  if(b[0]%2==a[0]){
    cout<<P.size()<<endl;
    for(int i=P.size()-1;i>=0;i--){
      cout<<P[i]<<" ";
    }
    cout<<endl;
  }
  else cout<<-1<<endl;
}

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

int main() {
    string s;
    vector<string> words = {"dream", "dreamer", "erase", "eraser"};
    cin >> s;
    int n = s.size();
    reverse(s.begin(), s.end());
    for (int i = 0; i < 4; ++i) reverse(words[i].begin(), words[i].end());
    for (int j = 0; j < n;) {
        bool test = false;
        for (const string& t : words) {
            if (t == s.substr(j, t.size())) {
                test = true;
                j += t.size();
                break;
            }
        }
        if (!test) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}


Measured memory_bytes: 512