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

#define MAXN 100000

using namespace std;

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

    int n;
    int c[MAXN], h[MAXN];

    cin >> n;
    for(int i=0 ; i<n ; i++) cin >> h[i];
    c[0] = 0;
    c[1] = abs(h[1] - h[0]);
    for(int i=2 ; i<n ; i++)
        c[i] = min(c[i-1] + abs(h[i]-h[i-1]), c[i-2] + abs(h[i] - h[i-2]));
    cout << c[n-1];

    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
int main(void){
    int color[3],n=3,i=0,k=0,temp,ans=1;
    scanf("%d %d %d",&color[0],&color[1],&color[2]);
    for(k=0;k<n-1;k++){
        for(i=0;i<n-k-1;i++){
            if(color[i]>color[i+1]){
                temp=color[i];
                color[i]=color[i+1];
                color[i+1]=temp;
            };
        };
    };
    //printf("%d %d %d",color[0],color[1],color[2]);
    for(i=0;i<n-1;i++){
        if(color[i]!=color[i+1]){
            ans++;
        };
    };
    printf("%d",ans);
    return 0;
};


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int[] X = new int[5];

        for(int i=0; i<5; i++){
            X[i] = sc.nextInt();
        }
        sc.close();
        for(int i=0; i<5; i++){
            if(X[i] == 0){
                System.out.println(i+1);
            }
        }
    }
}


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

int main() {
    unsigned int N, M;
    cin >> N >> M;

    if (M % 2 != 0){
        if (N % 2 == 0){
            N ++;
        }
        for (unsigned int i = N; i <= M; i++,i++){
            if (M % i == 0){
                cout << M / i << endl;
                return 0;
            }
        }
    }else{
        for (unsigned int i = N; i <= M; i++){
            if (M % i == 0){
                cout << M / i << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int w,h,x,y,r;
        scanf("%d%d%d%d%d",&w,&h,&x,&y,&r);
        int a = 0;
        a += (x-r<0);
        a += (y-r<0);
        a += (x+r>w);
        a += (y+r>h);
        if(a){
            printf("No\n");
        }else{
            printf("Yes\n");
        }
	return 0;
}


Measured memory_bytes: 2148
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[405],b[405],dp[405][405];
int n;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
	{
        cin>>a[i];
        b[i]=a[i]+b[i-1];
    }
    for(int i=1;i<n;i++)
	{
        for(int j=1;i+j<=n;j++)
		{
            dp[j][j+i]=1e18;
            for(int k=j;k<i+j;k++)
                dp[j][j+i]=min(dp[j][j+i],dp[j][k]+dp[k+1][j+i]);
            dp[j][j+i] += (b[j+i]-b[j-1]);
        }
    }
    cout<<dp[1][n];
    return 0;
}

Measured memory_bytes: 4912
#include <bits/stdc++.h>
using namespace std;
long long a, v, b, w, t;
int main(){
	cin >> a >> v >> b >> w >> t;
	if(llabs(a-b)<=(v-w)*t) cout << "YES" << endl;
	else cout<<"NO" << endl;
	return 0;
}

Measured memory_bytes: 3620
#include<stdio.h>
#include<string.h>
int main()
{
  char S[100000];
  int i;
  int sum_1=0,sum_2=0;
  scanf("%s",S);
     for(i=0; S[i]!='\0'; i++){
        if((i%2==0 && S[i]=='1') || (i%2==1 && S[i]=='0'))
          sum_1++;}
     for(i=0; S[i]!='\0'; i++){
        if((i%2==0 && S[i]=='0') || (i%2==1 && S[i]=='1'))
           sum_2++;}
  
  if(sum_1>sum_2)
  	printf("%d",sum_2);
  else if(sum_1<=sum_2)
    printf("%d",sum_1);
         
  return 0;
}

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

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

	priority_queue<int> q;
	for(int i = 0; i < N; ++i) {
		int a;
		cin >> a;
		q.push(a);
	}

	for(int m = 0; m < M; ++m) {
		auto val = q.top();
		q.pop();
		
		val /= 2;
		q.push(val);
	}
	
	long long int ans = 0;
	while(!q.empty()) {
		ans += q.top();
		q.pop();
	}
	
	cout << ans << endl;
	
	// your code goes here
	return 0;
}

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

#define ll long long
//~ #define endl '\n'
vector< pair< int, int > > G[100005];
vector< int > color(100005, -1), vis(100005);

void dfs(int node, int dist, int par = -1){
	//~ cout<<node<<endl;
	if(par == -1){
		color[node] = 1;
	}else{
		if(dist&1){
			color[node] = color[par]^1;
		}else{
			color[node] = color[par];
		}
	}
	for(pair< int, int > i : G[node]){
		if(i.first != par){
			dfs(i.first, i.second, node);
		}
	}
}

void solve(){
	int n; cin>>n;
	for(int i = 1; i<n; i++){
		int u, v, w; cin>>u>>v>>w;
		G[u].push_back({v, w});
		G[v].push_back({u, w});
	}
	dfs(1, 0);
	for(int i = 1; i<=n; i++){
		cout<<color[i]<<endl;
	}
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t = 1; //cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 11564
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,q,a;
main(){
	cin>>n;
	vector<int>v(n);
	r(i,n)cin>>v[i];;
	cin>>q;
	while(q--){
		cin>>a;
		vector<int>::iterator it1= lower_bound(v.begin(),v.end(),a);
		vector<int>::iterator it2= upper_bound(v.begin(),v.end(),a);
		cout<<it1-v.begin()<<' '<<it2-v.begin()<<endl;
	}
}


Measured memory_bytes: 3100
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <cmath>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
const ll MOD = 998244353;

int main() {
    ll n;
    cin >> n;
    vector<ll> A(n);
    for (auto &a : A) {
        cin >> a;
    }
    std::sort(A.begin(), A.end());
    for (ll i = 1; i < n; ++i) {
        if (A[i-1] == A[i]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define iii tuple<int, int, int>
#define ii pair<int, int>
#define fi first
#define se second

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve() {
    int n, M = 1e9 + 7;
    cin >> n;

    vector<vector<int>> a(n, vector<int>(n));

    for (auto& i : a)
        for (auto& j : i) cin >> j;

    vector<int> dp(1 << n), p2(n + 1);
    for (int i = 0; i <= n; ++i) p2[i] = 1 << i;
    dp[0] = 1;

    queue<int> q;
    q.push(0);
    auto cnt = [](int x) {
        int res = 0;
        while (x) {
            res += x & 1;
            x >>= 1;
        }
        return res;
    };

    while (!q.empty()) {
        int msk = q.front(), i = cnt(msk);
        q.pop();

        if (i == n) break;
        if (!dp[msk]) continue;

        for (int j = 0; j < n; ++j) {
            if (a[i][j] && !(msk & p2[j])) {
                q.push(msk | p2[j]);
                dp[msk | p2[j]] = (dp[msk | p2[j]] + dp[msk]) % M;
            }
        }
        dp[msk] = 0;
    }   
    cout << dp[p2[n] - 1] << '\n';
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    // freopen("in", "r", stdin);

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

    return 0;
}

Measured memory_bytes: 25108
import java.util.Scanner;

class Main{
	public static void main(String[] args) 	{
		Scanner sc = new Scanner(System.in);
		while(0 < 1) {
			int tate = sc.nextInt();
			int yoko = sc.nextInt();
			if(tate == 0 && yoko == 0) break;
			for(int i = 0 ; i < tate ; i++ ) {
				if(i % 2 == 0) {
					for(int j = 0 ; j < yoko ; j++) {
						if(j % 2 == 0) System.out.printf("#");
						else System.out.printf(".");
					}
					System.out.printf("\n");
				}
				else {
					for(int j = 0 ; j < yoko ; j++) {
						if(j % 2 == 0) System.out.printf(".");
						else System.out.printf("#");
					}
					System.out.printf("\n");
				}
			}
			System.out.printf("\n");
		}
		sc.close();
	}	
}


Measured memory_bytes: 59808
import sys
N, x = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
ans = 0
a.sort()
if a[0]>x:
  print(0)
  sys.exit()
for i in range(N):
  x -= a[i]
  if x < 0:
    print(ans)
    sys.exit()
  ans += 1
if x > 0:
  print(ans-1)
else:
  print(ans)

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

using namespace std;

int main() {
	int n; cin >> n;
	vector<int> h(n);
	for (auto &x : h) { cin >> x; }
	vector<int> DP(n, 0);
	DP[1] = abs(h[0] - h[1]);

	for (int i = 2; i < n; i++) {
		DP[i] = min(DP[i - 1] + abs(h[i] - h[i - 1]), DP[i - 2] + abs(h[i] - h[i - 2]));
	}

	cout << DP[n - 1] << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a) ; i < (int)(b) ; i++)


#define SZ(x) ((int)(x).size())


typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
struct Vector{
    double x, y;
};

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
using namespace std;

int Combination(int n, int r) {
  if ( r * 2 > n ) r = n - r;
  int dividend = 1;
  int  divisor  = 1;
  for (int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}


ll Choice(ll a)
{
    return a * (a-1)/2;
}

int main()
{
    int n, t;
    ll ans, sum =0;
    cin >> n;
    vector <int> A(n);
    rep(i, n){
         cin >> t; 
         A[i] = t-1;
    }
    vector <int> d(n);
    rep(i, n) d[A[i]]++;
    rep(i, n) sum += Choice(d[i]);

    rep(i, n) {
        ans = sum;
        ans -= Choice(d[A[i]]);
        ans += Choice(d[A[i]] - 1);
        cout << ans << endl;
    }
    

}


Measured memory_bytes: 4776
#include <bits/stdc++.h>
using namespace std;
long long n, m, v, p;
int a[100001];

vector <int> study;
int main() {
	cin >> n >> m >> v >> p;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	long long st = 0;
	long long en = n - 1;
	while (st < en) {
		study.clear();
		int mid = (st + en) >> 1;
		for (int i = 0; i < n; i++) {
			if (i != mid)
				study.push_back(a[i]);
		}
		//cout << "THING: " << endl;
		//for (int i = 0; i < study.size(); i++) {
		//	cout << study[i] << ' ';
		//} cout << endl;
		long long cost = 0;
		for (int i = study.size() - 1; i >= 0; i--) {
			if (study.size() - i <= p - 1) {
				cost += m;
			}
			else {
				if (study[i] > a[mid] + m) {
					cost = -1;
					break;
				}
				cost += min(m, a[mid] + m - study[i]);
			}
			//cout << "ITERATION " << i << " " << cost << endl;
		}
		//cout << mid << ' ' << cost << '\n';
		if (cost >= m * (v - 1)) {
			en = mid;
		} else
			st = mid + 1;
	}
	cout << n - en << '\n';
	
}

Measured memory_bytes: 1276
#include <iostream>
#include <cstdio>
#include <algorithm>
typedef long long ll;
using namespace std;
const int maxn = 100009;
int k;
ll sum;
int main(){
    scanf("%d",&k);
    for(int i = 1; i <= k; i++){
        if(i%3 != 0 && i%5 != 0)sum += i;
    }
    printf("%lld",sum);
    return 0;
}

Measured memory_bytes: 3828
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace aizu1
{
    public class Solution
    {
        public static void Main(string[] args)
        {
            int H = int.Parse(Console.ReadLine());
            int[] A = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            StringBuilder builder = new StringBuilder(); 

            for(int i = 0; i < H; i++)
            {
                builder.Append("node ").Append(i + 1).Append(": key = ").Append(A[i]).Append(", ");
                if (i!=0&&(i+1) / 2 >= 0) builder.Append("parent key = ").Append(A[(i+1)/2-1]).Append(", ");
                if (i * 2+1 < H) builder.Append("left key = ").Append(A[i*2+1]).Append(", ");
                if (i * 2 + 2 < H) builder.Append("right key = ").Append(A[i*2+2]).Append(", ");
                builder.Append("\n");
            }
            Console.Write(builder.ToString());
        }
    }
}

Measured memory_bytes: 9172
#include <bits/stdc++.h>
#include <vector> 
#include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;

int arr[26];
signed main(){
    string s, t;
    cin>>s >>t;
    vector<vector<int>> arr(26);
    rep(i,s.length()) arr[s[i]-'a'].push_back(i);
    rep(i,s.length()) arr[s[i]-'a'].push_back(i+s.length());

    int ans = 0;
    int p =0;
    rep(i,t.length()) {
        int c = t[i]-'a';
        if(arr[c].size()==0) {
            cout << -1 << endl;
            return 0;
        } 
        p = *lower_bound(arr[c].begin(), arr[c].end(), p)+1;
        if(p>=s.length()) {
            p-=s.length();
            ans += s.length();
        }
    }
    ans += p;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5668
#include <bits/stdc++.h>
#define int int64_t
#define pb push_back
#define pii pair<int, int>
#define F first
#define S second
#define vecsort(x) sort(x.begin(), x.end())
#define vecrsort(x) sort(x.rbegin(), x.rend())
#define massort(x, n) sort(x, x + n)
#define FOR(i, n) for(int i = 0; i < n; i ++)
using namespace std;
int max(int32_t a, int b){
   return max((int)a, b);
}
int max(vector<int> a){
   cout << *max_element(a.begin(), a.end());
}

const int INF = 1e9 + 7;
const int N = 1e5 + 2000;

int32_t main(){
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   int n, W;
   cin >> n >> W;
   vector<int> dp(W+1, 0);
   for(int i = 0; i < n; i ++){
      int val; int weight;
      cin >> weight >> val;
      for(int cur = W - weight; cur >= 0; cur --){
         dp[cur+weight] = max(dp[cur+weight], dp[cur] + val);
      }
   }
   int ans = 0;
   for(int i = 0; i <= W; i ++)
      ans = max(ans, dp[i]);
   cout << ans;
}



Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastReader s = new FastReader();
        int a = s.nextInt();
        int b = s.nextInt();
        int c = s.nextInt();
        int k = s.nextInt();
        int moves=0;
        while(b<=a){
            b*=2;
            moves++;
        }
        while(c<=b){
            c*=2;
            moves++;
        }
        if(moves<=k)
            System.out.println("Yes");
        else
            System.out.println("No");
    }

    private static boolean isPrime(int n) {
        if (n == 2)
            return true;
        else if ((n % 2 == 0 && n > 2) || n < 2)
            return false;
        else {
            for (int i = 3; i <= (int) Math.sqrt(n); i += 2) {
                if (n % i == 0)
                    return false;
            }
            return true;
        }


    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}

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

int main(void){
    map<int, pair<int,int>> mp;
    int H,W,D;
    cin >> H >> W >> D;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            int a;
            cin >> a;
            mp[a].first = i;
            mp[a].second = j;
        }
    }

    vector<int> cost(H*W+1), sum(H*W+1);
    for(int i=D+1; i<=H*W; i++){
        cost.at(i) = abs(mp[i].first - mp[i-D].first) + abs(mp[i].second - mp[i-D].second);
        sum.at(i) = cost.at(i) + sum.at(i-D);
    }  

    int Q;
    cin >> Q;
    vector<int> start(Q), goal(Q);
    for(int i=0; i<Q; i++){
        cin >> start.at(i) >> goal.at(i);
    }

    for(int i=0; i<Q; i++){
        cout << sum[goal.at(i)] - sum[start.at(i)] << endl;
    }
    
    return 0;
}

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

int main() {
   
	long long n,i,j,k,ans,count=0,sum=0,b,c,d,mx=0;
	cin>>n;
	long long t[n];
	string s[n],x;
	for(i=0;i<n;i++)
	cin>>s[i]>>t[i];
	
	cin>>x;
	for(i=0;i<n;i++)
	{
	    if(s[i]==x)
	    break;
	}
	for(j=i+1;j<n;j++)
	count+=t[j];
	cout<<count;
	
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Y = sc.nextInt();
        int m = -1, f = -1, t = -1;
        for (int i = 0; i <= N; i++) {
            for (int j = 0; j <= N; j++) {
                if (i + j <= N) {
                    int k = N - i - j;
                    if (i + j + k == N) {
                        if (10000 * i + 5000 * j + 1000 * k == Y) {
                            m = i;
                            f = j;
                            t = k;
                        }
                    }
                }

            }
        }
        System.out.println(m + " " + f + " " + t);

        // List<Integer> list = new ArrayList<>();
        // for (int i = 0; i < N; i++) {
        // list.add(sc.nextInt());
        // }
    }
}

Measured memory_bytes: 21716
def solve(mid):
    if mid <= p:
        return True
    max_ = a[mid - 1] + m
    b = [max_ - a[i] for i in range(p - 1, mid - 1)]
    new_v = v - p - n + mid
    # print(mid)
    # print(b, m, new_v)
    if min(b) < 0:
        return False
    if new_v <= 0:
        return True

    cnt = 0
    for num in b:
        cnt += min(num, m)
    return cnt >= m * new_v
       


n, m, v, p = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
# print(a)
ok = 1
ng = n + 1
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if solve(mid):
        ok = mid
    else:
        ng = mid
print(ok)


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

int main(void){
    int n;
    int flag=0;
    cin>>n;
    //1回目
    n-=7;
    if(n%10==0)flag=1;
    n+=7;
    //2回目
    n/=10;
    n-=7;
    if(n%10==0)flag=1;
    n+=7;
    //last
    n/=10;
    n-=7;
    if(n==0)flag=1;
    if(flag==1)cout<<"Yes";
    else cout<<"No";
}


Measured memory_bytes: 3636
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)
var n, q int
var ki [][]int
var points []int

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	n, q = nextInt(), nextInt()
	ki = make([][]int, n)
	points = make([]int, n)
	for i := 0; i < n; i++ {
		// 最初隣接行列でやってたんだけどREとTLEの山を築く原因ぽかったので隣接リストにした
		ki[i] = []int{}
	}
	for i := 0; i < n-1; i++ {
		a, b := nextInt()-1, nextInt()-1
		ki[a] = append(ki[a], b)
		ki[b] = append(ki[b], a)
	}

	for j := 0; j < q; j++ {
		p, x := nextInt()-1, nextInt()
		points[p] += x
	}
	stamped := make([]bool, n)
	stamped[0] = true

	path := []int{0}
	for len(path) > 0 {
		t := path[len(path)-1]
		path = path[:len(path)-1]
		// for i := 0; i < n; i++ {
		for _, v := range ki[t] {
			if !stamped[v] {
				stamped[v] = true
				points[v] += points[t]
				path = append(path, v)
			}
		}
	}

	ans := make([]string, n)
	for i, p := range points {
		ans[i] = strconv.Itoa(p)
	}
	PrintOut(ans, " ")
}

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func split(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}

// -*-*-*-*-*-
// * nibutan *
// -*-*-*-*-*-
func lower_bound(arr []int, target int) int {
	l, r := 0, len(arr)
	for l < r {
		mid := (l + r) / 2
		if arr[mid] < target {
			l = mid + 1
		} else {
			r = mid
		}
	}
	return l
}

func upper_bound(arr []int, target int) int {
	l, r := 0, len(arr)
	for l < r {
		mid := (l + r) / 2
		if target < arr[mid] {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return l
}

// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
// * math flavor typical theories *
// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
func gcd(a, b int) int {
	if a > b {
		return gcd(b, a)
	}
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

func pow(a, b int) (ret int) {
	ret = a
	// 10^2 = 100ってことは10に10を1回掛けることだね
	// なので初期値を含めると上限b-1未満
	for i := 0; i < b-1; i++ {
		ret *= a
	}
	return
}

func powMod(n, m, mod int) (ret int) {
	ret = 1
	for m > 0 {
		if m&1 == 1 {
			ret *= n
			ret %= mod
		}
		n *= n
		n %= mod
		m >>= 1
	}
	return ret
}


Measured memory_bytes: 30336
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
func exponentiate(_ lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
    func uppercased() -> String {
        return self.uppercaseString
    }
    func lowercased() -> String {
        return self.lowercaseString
    }
}
//extension Array where Element == String {
//    func joined(separator separator: String) -> String {
//        return self.joinWithSeparator(separator)
//    }
//}
extension Array where Element: Comparable {
    func max() -> Element {
        return self.maxElement()!
    }
    func min() -> Element {
        return self.minElement()!
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
func exponentiate(lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}

/*************** テストスペース ***************/



/*************** メインプログラム ***************/

let N = readInt()!
var button = [Int]()
for _ in 0..<N {
    button += [readInt()!]
}
var i = 1
for ans in 1...N {
    i = button[i-1]
    if i == 2 {
        print(ans)
        break
    }
    if ans == N {
        print(-1)
    }
}


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

int main() {
	
	string c[3];
	rep(i, 3) cin >> c[i];
	cout << c[0][0] << c[1][1] << c[2][2] << endl;
	return 0;
}

Measured memory_bytes: 256
A,B,M = map(int,input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s = [input().split() for i in range(M)]

mini = min(a) + min(b)

total = []
for i in s:
    total.append(a[int(i[0])-1]+b[int(i[1])-1]- int(i[-1]))
    
mini_2 = min(total)

if mini <= mini_2:
    print(mini)
else:
    print(mini_2)

Measured memory_bytes: 50220
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>

using namespace std;
int main() {
	
	int a, b;
	int N, M;
	cin >> N >> M;
	vector<vector<int>> ab(N);
	for (int i = 0; i < M;i++) {
		cin >> a >> b;
		ab[a-1].push_back(b-1);
	}
	
	for (auto& i : ab[0]) {
		for (auto& j : ab[i]) {
			if (j == N - 1) {
				cout << "POSSIBLE" << endl;
				return 0;
			}
		}
	}
	cout << "IMPOSSIBLE" << endl;
	return 0;
}



Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#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)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int a[N];
    rep(i, N) cin  >> a[i];
    int absmax = -1;
    int maxindex = 1;
    rep(i, N) {
        if (abs(absmax) < abs(a[i])) {
            absmax = a[i];
            maxindex = i;
        }
    }
    cout << N*2-1 << endl;
    rep(i, N) cout << maxindex+1 << " " << i+1 << endl;
    rep(i, N-1) {
        if (absmax < 0) cout << N-i << " " << N-i-1 << endl;
        else cout << i+1 << " " << i+2 << endl;
    }

    


    return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> Pint;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (ll i = begin; i < (ll)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    string s;
    cin >> s;
    ll N = s.size();
    string ans = "";
    rep(0, i, N)
    {
        if (s.at(i) == '0')
        {
            ans += '0';
        }
        else if (s.at(i) == '1')
        {
            ans += '1';
        }
        else if (ans.size() != 0)
        {
            ans.pop_back();
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3568
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

//エラトステネスの篩
bool isPrime[ (int)1e5 + 1 ];
vector<int> P;
void Eratosthenes( const int N )
{
    for( int i = 2; i <= N; i++ )
    {
        isPrime[ i ] = true;//初期化
    }
    
    isPrime[0] = isPrime[1] = false;

    for( int i = 2; i <= N; i++ )
    {
        if( isPrime[ i ] )
        {
            for( int j = 2 * i; j <= N; j += i )
            {
                isPrime[ j ] = false;
            }
            P.emplace_back( i );
        }
    }
}

int cumsum[(int)1e5+1] = {};

int main()
{
    Eratosthenes((int)1e5);
    cumsum[0] = 0;
    for (int i=1; i<(int)1e5+1; ++i)
    {
        if(i%2==0)
        {
            cumsum[i] = cumsum[i-1];
            continue;
        }

        if(isPrime[i] && isPrime[(int)(i+1)/2])
        {
            cumsum[i] = cumsum[i-1] + 1;
        }
        else
        {
            cumsum[i] = cumsum[i-1];
        }
        
    }
    int q,l,r;
    cin >> q;
    int ans[q];
    for (int i=0; i<q; ++i)
    {
        cin >> l >> r;
        ans[i] = cumsum[r] - cumsum[l-1];
    }
    rep(i,q)
    {
        cout << ans[i] << endl;
    }

    // for (int i=0; i<1000; ++i)
    // {
    //     cout << "i= " << i << " : "<< cumsum[i] << endl;
    // }
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

int main(){
    fastcin();

    int n, m;
    cin >> n >> m;
    vector<int> H(n);
    rep(i, n) cin >> H[i];

    Graph G(n);
    rep(i, m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<int> f(n, 1);
    int ans = 0;
    rep(i, n){
        if(f[i])repe(j, G[i]){
            if(H[i] <= H[j]){
                f[i] = 0;
                break;
            }else{
                f[j] = 0;
            }
        }
        if(f[i]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 9268
from collections import deque
 
h, w = map(int, input().split())
a = ['#' * (w + 2)] * 2
a[1: 1] = ['#' + input() +  '#' for _ in range(h)]
r = 0
for i in range(1, h + 1):
  for j in range(1, w + 1):
    if a[i][j] == '.':
      b = list(map(list, a))
      q = deque()
      b[i][j] = 0
      q.append((i, j))
      while(q):
        i, j = q.popleft()
        r = max(r, b[i][j])
        d = 0
        for i1 in range(i - 1, i + 2):
          for j1 in range(j - d, j + 2, 2):                
            if b[i1][j1] == '.':
              b[i1][j1] = b[i][j] + 1
              q.append((i1, j1))
          d ^= 1
print(r)

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;

#define INF 1<<28

int dp[5001];

int cost(int w) {
    switch (w) {
        case 0: return 0;
        case 200: return 380;
        case 300: return 550;
        case 500: return 850;
        case 1000: return 1520;
        case 1200: return 1870;
        case 1500: return 2244;
    }
    if (w < 0) return INF;
    if (dp[w] != -1) {
        return dp[w];
    }
    vector<int> costs(6);
    costs[0] = cost(w-200) + 380;
    costs[1] = cost(w-300) + 550;
    costs[2] = cost(w-500) + 850;
    costs[3] = cost(w-1000) + 1520;
    costs[4] = cost(w-1200) + 1870;
    costs[5] = cost(w-1500) + 2244;
    int min_cost = *min_element(costs.begin(), costs.end());
    dp[w] = min_cost;
    return min_cost;
}

int main() {
    int w;
    memset(dp, -1, sizeof(dp));
    while (cin >> w, w != 0) {
        cout << cost(w) << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#define MAX 100005
#define NIL -1
struct Node_struct{int p, l, r;}; /*p: 親(parent), l: 一番左の子(left child), r:右の兄弟(right sibling)*/
typedef struct Node_struct Node;

Node T[MAX];
int D[MAX];

void print(int u){
  int i, c;
  printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);

  if(T[u].p==NIL/*ここを埋める (fill this blank)*/) printf("root, ");
  else if(T[u].l==NIL/*ここを埋める(fill this blank)*/) printf("leaf, ");
  else printf("internal node, ");
  
  printf("[");
  for (i=0, c = T[u].l; c != NIL; i++, c = T[c].r){
    if(i) printf(", ");
    printf("%d", c);
  }
  printf("]\n");
  
}

void calcDepth(int u, int p){
  D[u] = p;
  if(T[u].l != NIL/*ここを埋める(fill this blank)*/) calcDepth(T[u].l,p+1/*ここを埋める(fill this blank)*/);
  if(T[u].r != NIL/*ここを埋める(fill this blank)*/) calcDepth(T[u].r,p/*ここを埋める(fill this blank)*/);
}

int main(){
  int i, j, k;
  int n;
  int id, sib, child;
  int root = NIL;
  scanf("%d", &n);
  for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL;
  
  for(i=0; i<n; i++){
    scanf("%d %d", &id, &k);
    for(j = 0, sib = NIL; j<k; j++){ //子を入力する (input children)
      scanf("%d", &child);
      T[child].p = id;
      if(j == 0) T[id].l = child; //idの一番左の子 (the most left child of id)
      else T[sib].r = child; //左の兄弟に繋げる (connect to left sibling)
      sib = child;//次の子供の左の兄弟 (the left sibling of the next child)
    }
  }

  //根を求める (find the root)
  for(i=0; i<n; i++){
    if(T[i].p == -1) root = i;
  }
  
  //それぞれのノードの深さを求める (find depth of each node)
  calcDepth(root, 0);

  //出力 (output)
  for(i=0; i<n; i++) print(i);
  
  return 0;
}



Measured memory_bytes: 3360
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <random>
#include <bitset>
#include <time.h>
#include <string>
#include <chrono>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
#define itn int
#define endl '\n'
#define mp make_pair
#define pbc push_back
#define pob pop_back()
#define empb emplace_back
#define sp system("pause")
#define queuel queue<long long>
#define matrix vector<vector<ll>>
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pin(p) cin >> p.first >> p.second;
#define rev(v) reverse(v.begin(),v.end());
#define mx(v) max_element(v.begin(), v.end())
#define mn(v) min_element(v.begin(), v.end())
#define dig(c) (c >=' 0' && c <= '9') ? 1 : 0
#define sout(s, c) for(auto i : s) cout << i << c;
#define pout(p) cout << p.first << " " << p.second;
#define er(v, l, r) erase(v.begin() + l, v.begin() + r);
#define vin(v) for(ll i = 0; i < v.size(); i++) cin >> v[i];
#define vout(v, c) for(int i = 0; i < v.size(); i++) cout << v[i] << c;
#define pushi(v, a) for(int i = 0; i < a.size(); i++) v.push_back(a[i]);
#define sin(s, n) for(int i = 0; i < n; i++){int a; cin >> a; s.insert(a);}
#define fastio() ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
using namespace std;
/*▄███████▀▀▀▀▀▀███████▄
░▐████▀▒ЗАПУСКАЕМ▒▀██████▄
░███▀▒▒▒▒▒ДЯДЮ▒▒▒▒▒▒▀█████
░▐██▒▒▒▒▒▒БОГДАНА▒▒▒▒▒████▌
░▐█▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▌
░░█▒▄▀▀▀▀▀▄▒▒▄▀▀▀▀▀▄▒▐███▌
░░░▐░░░▄▄░░▌▐░░░▄▄░░▌▐███▌
░▄▀▌░░░▀▀░░▌▐░░░▀▀░░▌▒▀▒█▌
░▌▒▀▄░░░░▄▀▒▒▀▄░░░▄▀▒▒▄▀▒▌
░▀▄▐▒▀▀▀▀▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒█
░░░▀▌▒▄██▄▄▄▄████▄▒▒▒▒█▀
░░░░▄██████████████▒▒▐▌
░░░▀███▀▀████▀█████▀▒▌
░░░░░▌▒▒▒▄▒▒▒▄▒▒▒▒▒▒▐
░░░░░▌▒▒▒▒▀▀▀▒▒▒▒▒▒▒▐*/
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
const ll INF = 1000LL * 1000 * 1000 * 1000 * 1000 * 1000;
const int inf = 1000000000 + 228;
const ld PI = acos(-1.0);
const int mod7 = 1000000000 + 7;
const int mod9 = 1000000000 + 9;
const int MAXN = 200005;
const ld EPS = 1e-10;
const int N = 300228;
ll hp = 29;
signed main()
{
	fastio();
	char c;
	cin >> c;
	if (c == 'A')
	{
		cout << 'T';
	}
	else if (c == 'T')
	{
		cout << 'A';
	}
	else if (c == 'G')
	{
		cout << "C";
	}
	else
	{
		cout << "G";
	}
//	sp;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
#define MOD 1000000007

int main(){
  int X,Y;
  cin>>X>>Y;
  bool flag=false;

  for(int i=0;i<=100;i++){
    for(int j=0;j<=100;j++){
      if(i+j==X&&2*i+4*j==Y){
        flag=true;
      }
    }
  }

  if(flag){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 3604
k,n = map(int, input().split())
lst = list(map(int, input().split()))

maxDis = (k-lst[-1]) + lst[0]
for i in range(n-1):
  if lst[i+1] - lst[i] > maxDis:
    maxDis = lst[i+1] - lst[i]
print(k-maxDis)

Measured memory_bytes: 25836
#include <regex>
#include "bits/stdc++.h"
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define LINF (LLONG_MAX / 2)
#define EPS (1.0e-8)
#define mkpr make_pair
const int MGN = 10;
const int ARY_SZ_MAX = (int)1e7;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>;
using vc = vector<char>; using vvc = vector<vc>;
using vb = vector<bool>; using vvb = vector<vb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using psl = pair<string, ll>;


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


    int N, K; cin >> N >> K;
    
    double ans = 0;    
    FOR(i, 1, N+1) {  // i : サイコロの出た目
        int scr = i;  // 現在のスコア
        double p = 1.0;   // 現在のスコアとなる確率        
        bool win = true;  // 勝ち続けているか
        while (true) {
            if (K <= scr) break;  // 勝ち
            else if (0 < scr && scr < K) {  // 継続
              scr *= 2;
              p *= 0.5;
            } else {  // 負け
              win = false;
              scr = 0;
              break;
            }
        }

        if (win) ans += p / N;
    }
    printf("%.12lf\n", ans);


  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 300000
int main(void) {
    int n, i, cnt=0, ans=MAX-1;
    char s[MAX];
    scanf("%d %s", &n, s);
    
    for(i=1; i<n; i++) {
        if(s[i]=='E')
            cnt++;
    }
    ans = cnt;
    for(i=1; i<n; i++) {
        if(s[i]=='E')
            cnt--;
        if(s[i-1]=='W')
            cnt++;
        if(cnt<ans)
            ans = cnt;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define int long long
using namespace std;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
vector<string> m;
queue<int> queueX;
queue<int> queueY;
int h,w,ans,white;
void Bfs()
{
    while (white > 0)
    {
        queue<int> cx;
        queue<int> cy;
        ans++;
        while (!queueX.empty())
        {
            cx.push(queueX.front());
            cy.push(queueY.front());
            queueX.pop();
            queueY.pop();
        }
        while (!cx.empty())
        {
            int x = cx.front();
            int y = cy.front();
            cx.pop();
            cy.pop();
            for(int i = 0;i < 4; i++)
            {
                int nx = x + dx[i];
                int ny = y + dy[i];
                if (nx < 0 || ny < 0 || nx >= w || ny >= h)
                    continue;
                if (m[ny][nx] == '#')
                    continue;
                m[ny][nx] = '#';
                white--;
                queueX.push(nx);
                queueY.push(ny);
            }
        }
    }
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> h >> w;
    for(int i = 0;i < h; i++)
    {
        string s;
        cin >> s;
        m.push_back(s);
    }
    for(int i = 0;i < h; i++)
    {
        for(int j = 0;j < w; j++)
        {
            if (m[i][j] == '#')
            {
                queueX.push(j);
                queueY.push(i);
            }
            else
                white++;
        }
    }
    Bfs();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 17696
#include <iostream>
#include <stdio.h>
#include <algorithm>

using namespace std;

int a, b;

string tostr(int x)
{
	char buf[50];
	sprintf(buf, "%d", x);
	return buf;
}

int main(void)
{
	cin >> a >> b;
	
	int ans = 0;
	for(int i = a; i <= b; i++){
		string s = tostr(i);
		string t = s;
		reverse(t.begin(), t.end());
		if(s == t) ans++;
	}
	cout << ans << endl;
}

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

const int inf = (int) 1e9 + 7;

int dp[1003][10004];
int A[1003], B[1003];

int solve(int N, int H)
{
    if(H <= 0)
        return 0;
    
    if(N == 0)
        return inf;
    
    if(dp[N][H] != -1)
        return dp[N][H];
    
    int ans = solve(N-1, H);
    ans = min(ans, solve(N, H - A[N]) + B[N]);

    return dp[N][H] = ans;
}

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

    int N, H;
    cin >> H >> N;

    for(int i=1; i<=N; i++)
        cin >> A[i] >> B[i];

    memset(dp, -1, sizeof(dp));

    cout << solve(N, H) << "\n";
    return 0;
}


Measured memory_bytes: 39936
import scala.io.StdIn.{readInt,readLine}

object Main {
  val alist = List(1,3,5,7,9,11,15,17,19,21,23,25)
  val blist = 0 to 25
  val invs = (for{
    i<-alist
    j<-1 to 25 by 2
    if (i*j) % 26 == 1
  } yield (i,j)).toMap
  def encode(c:Int,a:Int,b:Int) = (((a*(c-97)+b) % 26)+97).toChar
  def decode(c:Int,a:Int,b:Int) = ((a*(c-97-b+26) % 26)+97).toChar

  def main(args:Array[String]) = {
    val n = readInt
    (0 until n).foreach { _ =>
      val l = readLine
      val (a,b) = {for(i<-alist;j<-blist) yield (i,j)}.find{ case (i,j) =>
            l.contains("that".map{encode(_,i,j)}) || l.contains("this".map{encode(_,i,j)})
      }.get
      println( l.map { c=> if(c>=97 && c<=122) decode(c,invs(a),b) else c })
    }
  }
}

Measured memory_bytes: 45260
#include <iostream>
#include <vector>
#include <array>

using namespace std;

int main() {
    int N;
    cin >> N;
    int num[N];
    bool p = true;
    
    for (int i = 0; i < N; i++) {
        cin >> num[i];
    }
    
    for (int i = 0; i < N; i++) {
        if (num[i] % 2 == 0) {
            if (!(num[i] % 3 == 0 || num[i] % 5 == 0)) {
                p = false;
                break;
            }
        }
    }
    
    cout << (p ? "APPROVED" : "DENIED") << "\n";
    return 0;
}


Measured memory_bytes: 256
from math import sqrt, ceil

N = 10100000
temp = [True]*(N+1)
temp[0] = temp[1] = False
for i in range(2, ceil(sqrt(N+1))):
    if temp[i]:
        temp[i+i::i] = [False]*(len(temp[i+i::i]))

quadruplet = [True, False, True, False, False, False, True, False,True]
ans = [0]*N
for i in range(8,N):
    if temp[i] and temp[i-8:i+1] == quadruplet: ans[i] = i
    else: ans[i] = ans[i-1]
while True:
    n = int(input())
    if not n: break
    print(ans[n])


Measured memory_bytes: 194948
#include <stdio.h>
#include <string.h>

int main(void) {
  int N, n, t=0, h=0;
  scanf("%d\n", &N);
  for (n=0;n<N;n++) {
    char T[128], H[128]; int s;
    scanf("%s %s\n", T, H);
    if((s=strcmp(T,H))>0) t+=3;
    else if(s<0) h+=3;
    else { t++; h++; }
  }
  printf("%d %d\n",t,h);
  return 0;
}

Measured memory_bytes: 608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define F first
#define S second
//cout<<fixed<<setprecision(11);
const string nl="\n";
const ll MOD=1e9+7;
const int ARR_MAX = 3003;
const ll VAL_MAX = 1e5+1;
const ll INF=1e14;

ll dp[ARR_MAX],cum_dp[ARR_MAX+2];
//dp[j] = number of permutations with j as the last element of the sequence.
//dp[i][j] = number of ways to get prefix of size i such that last number is j.

void solve(){
    int n;cin>>n;
    string s;
    cin>>s;
    memset(dp,0,sizeof(dp));    
    dp[0]=1;
    for(int i=0;i<n-1;i++){
        //length of string processed so far = i+1;
        //numbers used so far are 0,...,i.
        cum_dp[0]=0;
        for(int j=0;j<=i;j++){
            cum_dp[j+1]=(cum_dp[j] + dp[j])%MOD;
        }
        for(int j=0;j<=i+1;j++){
            if(s[i]=='<'){
                dp[j]=cum_dp[j];
            }
            else{
                dp[j]=(cum_dp[i+1]-cum_dp[j]+MOD)%MOD;
            }
        }
    }
    ll ans=0;
    for(int i=0;i<n;i++){
        ans+=dp[i];
        ans%=MOD;
    }
    cout<<ans<<nl;
}

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

Measured memory_bytes: 384
import qualified Data.Map as M

select :: [a] -> [(a, [a])]
select [x]    = [(x, [])]
select (x:xs) = (x, xs) : map (\(y, ys) -> (y, x:ys)) (select xs)

permutations :: [a] -> [[a]]
permutations [] = [[]]
permutations xs =
  concatMap (\(y, ys) -> map (y:) (permutations ys)) $ select xs

main = do
 n <- read <$> getLine :: IO Int 
 let permutationsList = M.fromList $ zip (permutations [1..n]) [1..]
 pList <- map read . words <$> getLine :: IO[Int]
 qList <- map read . words <$> getLine :: IO[Int] 
 print $ abs $ (permutationsList M.! pList) - (permutationsList M.! qList)

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

int main(){
    int n;
    cin >> n;
    bool f = 1;
    int val;
    for(int i = 0;i<n;i++){
        cin >> val;
        if(val%2 == 0 and (val%3!=0 and val%5!=0))
            f = 0;
    }
    if(f)
        cout<<"APPROVED";
    else cout<<"DENIED";
}

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

int n, arr[100005];
int dp[100005];

void solve()
{
    dp[0] = 0;
    for(int i = 1; i < n; i++)
    {
        dp[i] = dp[i - 1] + abs(arr[i] - arr[i - 1]);
        if(i > 1)
        {
            dp[i] = min(dp[i], dp[i - 2] + abs(arr[i] - arr[i - 2]));
        }
    }
}

int main()
{
    cin >> n;

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

    solve();
    cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1024