akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;
template<class T>struct SegTree{
	T *dat;
	int n;
	SegTree(int size = 1000000){
		for(n = 1; n < size; n *= 2);
		dat = new T[2 * n - 1];
		init();
	}
	~SegTree(){ delete [] dat; }
	
	void init(){
		rep(i, 2 * n - 1) dat[i] = 0;
	}
	void update(int k, T a){
		k += n - 1;
		dat[k] = a;
		
		while(k > 0){
			k = (k - 1) / 2;
			dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}
	T query(int a, int b, int k, int l, int r){
		if(r <= a || b <= l) return 0;
		if(a <= l && r <= b) return dat[k];
		
		T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
		T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
		
		return max(vl, vr);
	}
	T query(int a, int b){ return query(a, b, 0, 0, n); }
};
int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n; cin >> n;
	vi d(n); rep(i, n) cin >> d[i];
	bool res = 1;
	auto sol = [&](){
		SegTree<int> seg(n);
		for(int i = n - 1; i >= 0; i--){
			int m = min(n - 1, i + d[i] / 10) + 1;
			seg.update(i, max(i, seg.query(i, m)));
		}
		return seg.query(0, 1) >= n - 1;
	};
	res &= sol(); reverse(all(d));
	res &= sol();
	cout << (res ? "yes" : "no") << endl;
	
	return 0;
}


Measured memory_bytes: 8056
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <cmath>
#include <ios>
#include <ctype.h>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
#include <functional>
#include <bitset>
#include <list>
#include <deque>
#include <time.h>
#include <random>
#include <iomanip>
#include <fstream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define pint pair<int,int>
#define SEG_LEN (1 << 18)
const int INF = 1000000007;
const long double EPS = 1e-15;
const long double PI = acos(-1);
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
using Graph_weighted = vector<vector<pair<int,int>>>;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll ceil(const ll a, const ll b) { return (a + b - 1) / b; }
int main(){
  string s;
  cin >> s;
  string back = "XXOXOXOOOXOXOXOXXOXXOXOO";
  int n = s.size();
  int ans = 0;
  rep(i,n){
    if(i == n - 1){
      if(back != s.substr(i,1))ans++;
    }
    else{
      if(back != s.substr(i,1)){
        ans++;
        back = s.substr(i,1);
      }
      else{
        ans++;
        back = s.substr(i,2);
        i++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
 

Measured memory_bytes: 640
N = int(input())
A = list(map(int,input().split()))
for k in range(N-1):
    print(f"{A[k]} ",end="")
print(f"{A[N-1]}")
for i in range(1,N):
    v = A[i]
    j = i-1
    while (j>=0)*(A[j]>v):
        A[j+1]=A[j]
        j-=1
        A[j+1]=v
    for k in range(N-1):
        print(f"{A[k]} ",end="")
    print(f"{A[N-1]}")


Measured memory_bytes: 5992
/**
   _           _
  / /         \ \
 / /  _   _  _ \ \
< < (_) (_) (_) > >
 \ \           / /
  \_\         /_/

    Nerede Gitsen Çukur Orda
**/

#include<bits/stdc++.h>
#include<fstream>
///#include<conio.h>
///#include "windows.h"
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define fr first
#define sc second
#define Zohiri_dzd cout.tie(NULL);
#define Belafz cin.tie(NULL);
#define CODER ios_base::sync_with_stdio(0)  ;
#define p_b pop_back
#define p_f pop_front
#define quluq return 0;
using namespace std ;

    const ll N = 1e4 + 0.000001 ;

int main ()
{
    Zohiri_dzd
    Belafz
    CODER
    ///freopen("input.txt" , "r" , stdin );
    ///freopen("output.txt", "w" , stdout );
    ///4294967295
    ///4294967295
    ll n ;
    cin >> n ;
    ll cnt = 0 ;
    for (ll i = 1 ; i <= n ; i ++ )
    {
        ll a ;
        cin >> a ;
        if (a & 1 and i & 1)
            cnt ++ ;
    }
    cout << cnt << endl ;
}
///MaaN studios
///Eco students


Measured memory_bytes: 3616
N,K=map(int,input().split())
A=list(map(int,input().split()))
A=[A[i]-1 for i in range(N)]

doubling=[[0 for i in range(N)] for i in range(0,70)]
for i in range(N):
    doubling[0][i]=A[i]

for i in range(1,70):
    for j in range(N):
        doubling[i][j]=doubling[i-1][doubling[i-1][j]]

ans=0
for i in range(0,70):
    if K>>i &1==1:
        ans=doubling[i][ans]

print(ans+1)


Measured memory_bytes: 223496
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
#define pq priority_queue<long long, vector<long long>, greater<long long> >

int main(){
    long long T;
    cin >> T;
    long long t;
    long long N, K, L, R;
    pq left, right;
    long long i,j;
    long long ans;
    for(t=1; t<=T; t++){
        //input
        vector<pair<long long, long long> > left_sub, right_sub;
        ans = 0;
        cin >> N;
        for(i=1; i<=N; i++){
            cin >> K >> L >> R;
            if(K>=N){
                ans += L;
            }else{
                ans += min(L,R);
                if(L>R){
                    left_sub.push_back(make_pair(K,L-R));
                }else if(L<R){
                    right_sub.push_back(make_pair(N-K,R-L));
                }
            }
        }
        sort(left_sub.begin(),left_sub.end());
        sort(right_sub.begin(),right_sub.end());

        //left
        j=0;
        for(i=1; i<=(long long)left_sub.size(); i++){
            for(; j<(long long)left_sub.size(); j++){
                if(left_sub[j].first<=i){
                    left.push(left_sub[j].second);
                }else{
                    break;
                }
            }
            while(left.size()>i){
                left.pop();
            }
        }
        for(; j<(long long)left_sub.size(); j++){
            ans += left_sub[j].second;
        }
        while(!left.empty()){
            ans += left.top();
            left.pop();
        }

        //right
        j=0;
        for(i=1; i<=(long long)right_sub.size(); i++){
            for(; j<(long long)right_sub.size(); j++){
                if(right_sub[j].first<=i){
                    right.push(right_sub[j].second);
                }else{
                    break;
                }
            }
            while(right.size()>i){
                right.pop();
            }
        }
        for(; j<(long long)right_sub.size(); j++){
            ans += right_sub[j].second;
        }
        while(!right.empty()){
            ans += right.top();
            right.pop();
        }
        cout << ans << endl;
    }
    system("pause");
    return 0;
}

Measured memory_bytes: 7992
const Main = (input) => {
  const tmp = input.trim().split('')

  let result = ''

  if (tmp.indexOf('7') === -1) {
    result = 'No'
  } else {
    result = 'Yes'
  }

  console.log(result)
  return result
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 29572
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int len = s.length();
    long sum = 0;
    for (int i = 0; i < len; i++)
    {
        sum += s[i] - '0';
    }
    if (sum % 9 == 0)
    {
        cout << "Yes";
    }
    else
        cout << "No";
    return 0;
}

Measured memory_bytes: 3732
x = int(input())
if 400 <= x and x < 600:
  print(8)
if 600 <= x and x < 800:
  print(7)
if 800 <= x and x < 1000:
  print(6)
if 1000 <= x and x < 1200:
  print(5)
if 1200 <= x and x < 1400:
  print(4)
if 1400 <= x and x < 1600:
  print(3)
if 1600 <= x and x < 1800:
  print(2)
if 1800 <= x and x < 2000:
  print(1)



Measured memory_bytes: 9144
#include"bits/stdc++.h"
using namespace std;

int main() {
    int N;
    cin >> N;
    int h[100000];
    for(int i=0; i<N; i++){
        cin >> h[i];
    }
    int dp[100000];
    dp[0] = 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;
    return 0;
}

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

int main()
{  
  int N,i,j,sa,k,flag,dec;
  cin >> N;
  sa=0;
  flag=0;

   vector<char> w(N);
  vector<char> per(N);
   for(i=0;i<N;i++)
   {
    w.at(i)='a';
     cout << w.at(i);
   }
  cout << endl;

  while(flag==0)
  {
    flag=1;
    for(i=0;i<N-1;i++)
    { 
      dec=0;
      for(j=0;j<N-1-i;j++)
      {
        if(w.at(j)>=w.at(N-1-i))
        {
          dec=1;
          break;
        }
      }
       
      if(dec==1)
      {
        w.at(N-1-i)++;
        
        for(j=N-i;j<N;j++)
        {
          w.at(j)='a';
        }
        
         for(k=0;k<N;k++)
         {
     cout << w.at(k);
         }
        cout << endl;
        flag=0;
        sa++;
        break;
      }
    }
  }
 //   cout << sa;
  
  
  

}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main(){
  long n,a[5];
  cin>>n;
  for(int i=0;i<5;++i){
    cin>>a[i];
    if(i&&a[i]>a[i-1])a[i]=a[i-1];
  }
  cout<<n/a[4]+(n%a[4]?1:0)+4;
  return 0;
}

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

using namespace std;

int main(void)
{
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    int beakerA;
    int beakerB;
    int beakerC;
    int beakerD;
    int ansSugarWater = 100*A;
    int ansSugar = 0;
    for (int a = 0; (beakerA = 100*A*a) <= F; a++) {
        for (int b = 0; (beakerB = beakerA + 100*B*b) <= F; b++) {
            for (int c = 0; (beakerC = beakerB + C*c) <= F; c++) {
                for (int d = 0; (beakerD = beakerC + D*d) <= F; d++) {
                    int water = 100*A*a + 100*B*b;
                    int sugar = C*c + D*d;
                    int sugarWater = water + sugar;
                    if (water / 100 * E < sugar) { // undissolved
                        break;
                    } else {
                        /*
                        cout << "a = " << a << endl;
                        cout << "b = " << b << endl;
                        cout << "c = " << c << endl;
                        cout << "d = " << d << endl;
                        */
                        if (ansSugar * sugarWater < sugar * ansSugarWater) {
                            ansSugarWater = sugarWater;
                            ansSugar = sugar;
                        }
                    }
                }
            }
        }
    }
    cout << ansSugarWater << " " << ansSugar << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long dp[2][301][301] = {};

void add(long long &a, long long b) {
    a = (a + b) % MOD;
}

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

    dp[0][1][1] = 1;
    for(int n=0; n<M; ++n) {
        for(int x=0; x<=N; ++x) 
            for(int y=0; y<=N; ++y) dp[(n+1)&1][x][y] = 0;

        for(int x=1; x<=N; ++x) {
            for(int y=1; y<=N; ++y) {
                if(x < N) add(dp[(n + 1)&1][x + 1][y], dp[n&1][x][y] * (N - x));
                add(dp[(n + 1)&1][x][y], dp[n&1][x][y] * (x - y));
                add(dp[(n + 1)&1][x][x], dp[n&1][x][y] * y);
            }
        }
    }
    cout << dp[M&1][N][N] << endl;
}

Measured memory_bytes: 1664
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int c = sc.nextInt();
        int[] b = new int[m];
        for (int i = 0; i < m; i++) {
            b[i] = sc.nextInt();
        }
        int[][] a = new int[n][m];

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                a[i][j] = sc.nextInt();
            }
        }

        int count = 0;
        for (int i = 0; i < n; i++) {
            int temp = 0;
            for (int j = 0; j < m; j++) {
                temp += a[i][j] * b[j];
            }
            if (temp + c > 0)
                count++;
        }

        System.out.println(count);
    }
}


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

namespace AltCoder
{
    public sealed class E_Knapsack2
    {
        public static void Main()
        {
            long[] NW = Console.ReadLine().Split(new char[] { ' ' }).Select(x => Convert.ToInt64(x)).ToArray();
            long N = NW[0];
            long maxWeight = NW[1];

            long[] weights = new long[N];
            int[] values = new int[N];

            for (long i = 0; i < N; i++)
            {
                var input = Console.ReadLine().Split(new char[] { ' ' }).ToArray();
                weights[i] = Convert.ToInt64(input[0]);
                values[i] = Convert.ToInt32(input[1]);
            }

            int sum = values.Sum();
            long[] d = new long[sum + 1];
            for (int i = 0; i < d.Length; i++)
            {
                d[i] = int.MaxValue;
            }
            d[0] = 0;

            for (long item = 0; item < N; item++)
            {
                for (long i = sum - values[item]; i >= 0; i--)
                {
                    d[i + values[item]] = Math.Min(d[i + values[item]], d[i] + weights[item]);
                }
            }

            int result = 0;
            for (int i = 0; i < d.Length; i++)
            {
                if (d[i] <= maxWeight)
                {
                    result = i;
                }
            }
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 14048
#include <iostream>
#include <string>

using namespace std;

#define RPT(i, b, e) for (int i = (b); i <= (e); i++)
#define RPT0(i, n) RPT(i, 0, n - 1)
#define RPT1(i, n) RPT(i, 1, n)

void resolve()
{
    string S;
    cin >> S;
    int len = S.length();
    int len2 = len / 2;

    RPT0(i, len2)
    {
        if (S[i] != S[len - i - 1]) {
            cout << "No" << endl;
            return;
        }
    }

    RPT0(i, len2 / 2)
    {
        if (S[i] != S[len2 - i - 1]) {
            cout << "No" << endl;
            return;
        }
    }

    RPT0(i, len2 / 2)
    {
        if (S[len2 + 1 + i] != S[len - i - 1]) {
            cout << "No" << endl;
            return;
        }
    }

    cout << "Yes" << endl;
}

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


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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007;

bool ssort(pair<int,int> a,pair<int,int> b){
    return a.second>b.second;
}

int main(){
    
    int N;cin>>N;
    vector<pair<int,int>> S(N),T(N);
    for(int i=0;i<2*N;i++){
        if(i<N) cin>>S[i].first>>S[i].second;
        else cin>>T[i-N].first>>T[i-N].second;
    }
    sort(all(S),ssort);
    sort(all(T));
    int cnt=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(S[i].first<T[j].first&&S[i].second<T[j].second){
                cnt++;
                T[j]=make_pair(-1,-1);
                break;
            }
        }
    }
    cout<<cnt<<endl;
}


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

int main(){
    int a1,a2,a3;
    int sum;
    cin >> a1 >> a2 >> a3;
    sum = a1 + a2 + a3;

    if(sum>21){cout<<"bust"<<endl;}
    else {cout<<"win"<<endl;}

    return 0;
}

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

int main(void) {
	int A, B;
	cin >> A >> B;

	int ans = 0;
	if (A >= 6)
		ans += B / 2;
	if (A >= 13)
		ans += B / 2;

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
  string o,e;
  cin >> o >> e;
  
  rep(i,0,o.size()){
    cout << o[i];
    if(i < e.size())
      cout << e[i];
  }
  cout << endl;
  ret 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
char a[100][100];
int ans[100][100];
int dx[10]={1,1,1,0,0,-1,-1,-1};
int dy[10]={-1,0,1,1,-1,-1,0,1};
int main(){
    int m,n;
    cin>>m>>n;
    for(int i=0;i<m;i++)
        cin>>a[i];
    for(int i=0;i<m;i++)
    for(int j=0;j<n;j++){
        if(a[i][j]=='.')
        for(int k=0;k<8;k++){
            int x=i+dx[k],y=j+dy[k];
            if(x<m&&x>=0&&y<n&&y>=0){
                if(a[x][y]=='#')
                    ans[i][j]++;
            }
        }
    }
    for(int i=0;i<m;i++){
    for(int j=0;j<n;j++)
        if(a[i][j]!='#')
            cout<<ans[i][j];
        else cout<<"#";
        cout<<endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){

  int n;
  cin>>n;
    pair <double,double> Pair[n];
 double fact=1;
  for(int i=1;i<n;i++)
  {
    fact*=i;
  }
         double d=0;
  for(int i=0;i<n;i++)
  {
      
    cin>>Pair[i].first; 
    cin>>Pair[i].second; 
  } 
  for(int i=0;i<n;i++)
  {
      for(int j=i+1;j<n;j++)
      {
        d+=sqrt((Pair[i].first-Pair[j].first)*(Pair[i].first-Pair[j].first)+(Pair[i].second-Pair[j].second)*(Pair[i].second-Pair[j].second))*fact*2;
      }
  }
 
d=d/(fact*n);
cout <<fixed;
cout << setprecision(10);

cout<<d;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair
#define int         int64_t

using namespace std;

typedef pair<int, int> pii;
const int N = int(1e5) + 2;
const int inf = (int)1e15;

int n, a[N], sumxor, basis[N];

void Ins(int x) {
    for(int i = 59; i >= 0; --i) {
        if(!(x >> i & 1)) continue;
        if(basis[i] == 0) {
           basis[i] = x; return;
        }
        x ^= basis[i];
    }
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        sumxor ^= a[i];
    }
    for(int i = 1; i <= n; ++i) {
        for(int j = 0; j < 60; ++j)
            if(sumxor & a[i] & (1ll << j)) a[i] ^= (1ll << j);
        Ins(a[i]);
    }
    int ans = 0;
    for(int i = 59; i >= 0; --i) {
        if(!basis[i]) continue;
        if(ans >> i & 1) continue;
        ans ^= basis[i];
    }
    cout << ans * 2  + sumxor;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int n,h[100005];
main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    bool f=1;
    for(int i=n-1;i>0;i--){
        if(h[i]-h[i-1]==-1)h[i-1]--;
        else if(h[i]-h[i-1]<-1){
            f=0;break;
        }
    }
    cout<<(f?"Yes":"No")<<endl;
    
}

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

int main(void){

    int k, a, b;
    scanf("%d",&k);
    scanf("%d %d", &a, &b);
    if(a/k==b/k&&((a/k)*k!=a)){
        printf("NG");
    }else{
        printf("OK");
    }

    return 0;
}

Measured memory_bytes: 1732
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[][][] room = new int[4][3][10];  
		int n = sc.nextInt();  //n???????????±
		int b ;  //?£???°
		int f ;  //?????°
		int r ;  //??¨?±???°
		int v ; //?????°
	//??\???????????????	
		for(int i = 0 ; i < n ; i++) {
			b = sc.nextInt();
			f = sc.nextInt();
			r = sc.nextInt();
			v = sc.nextInt();
			
			room[b-1][f-1][r-1] += v ; 
		}
		
	//??????????????????	
	for(int i = 0; i < 4 ; i++) {
		for (int k = 0 ; k < 3 ; k++) {
			for(int rN = 0 ; rN < 10 ; rN++) {
				System.out.print(" " + room[i][k][rN]);
			}
			System.out.println("");
		}
	//????????????(#)???4?£????????????????????????????????????????????????????	
		if(i != 3 ) {
			System.out.println("####################");
		}
	}
	
     sc.close();
  }

}

Measured memory_bytes: 29552
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int x,n;
  cin >> x >> n;
  vi v(101, 0);
  rep(i, n){
    int p;
    cin >> p;
    v[p] =  1;
  }
  int ans = x + 1;
  int value = -1;
  for(int i = 0; i < 103; i++){
    if(!v[i]){
      if(ans > abs(x - i)){
        ans = abs(x - i);
        value = i;
      }
    }
  }
  cout << value << endl;
}

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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int MAX = 2010;
int wst[MAX],il[MAX],ok[MAX],a[MAX],p[MAX],syn[MAX];
int n;
void dfs(int v){
  ok[v] = 1;
  debug("ok",v);
  if(p[v] != 0 && il[p[v]] == 1){
    dfs(p[v]);
    syn[p[v]] = v;
  }
}
vector<int> out;
void rusz(int x){
   debug("rusz",x);
  out.PB(x);
  int pom = a[0];
  bool cz = 1;
  while(x != 0){
    swap(pom,a[x]);
    if(wst[x] == 0 && cz){
      if(il[x] == 0){
        wst[x] = 1;
        il[p[x]]--;
      }
      cz = 0;
    }
    x = p[x];
  }
  a[0] = pom;
//   R(i,n){
//     cerr << a[i] << " ";
//   }
//   cerr << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n;
  p[0] = -1;
  R(i,n-1){
    cin >> p[i+1];
  }
  R(i,n){
    cin >> a[i];
  }
  vector<int> todo;
  R(i,n)if(i)todo.PB(i);
  while(SZ(todo)){
    debug(todo);
    for(int ak:todo){
      wst[ak] = 0;
      il[ak] = 0;
      ok[ak] = 0;
      syn[ak] = -1;
    }
    for(int ak:todo){
      il[p[ak]]++;
    }
    for(int ak:todo){
      if(il[ak] == 0){
        dfs(ak);
      }
    }
    int gd = SZ(todo)-1;
    while(1){
      if(ok[a[0]]){
        int ak = a[0];
        debug(ak);
        while(syn[ak] != -1 && (wst[syn[ak]] == 0 || !ok[a[syn[ak]]] || a[syn[ak]] < a[0])){
          ak = syn[ak];
          debug(ak);
        }
        rusz(ak);
      }else{
        while(gd >= 0 && wst[todo[gd]]){
          gd--;
        }
        if(gd != -1){
          rusz(todo[gd]);
        }else
          break;
      }
    }
    vector<int> td;
    for(int el:todo){
      if(!ok[el])
        td.PB(el);
      else
        assert(a[el] == el);
    }
    swap(td,todo);
  }
  cout << SZ(out) << "\n";
  for(int el:out){
    cout << el << "\n";
  }
#ifdef LOCAL
  R(i,n){
    assert(i == a[i]);
  }
#endif
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <functional>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

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

#define pi 3.141592653589793)
#define mod 1000000007

int N;
int cnt;
vector<pair<int, int>> a, b;
vector<pair<int, int>>::iterator itr;

void solve() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		int tmp1, tmp2;
		cin >> tmp1 >> tmp2;
		a.push_back(P(tmp2, tmp1));
	}
	sort(a.begin(), a.end(),greater<pair<int, int>>()); 

	for (int i = 0; i < N; i++) {
		int tmp1, tmp2;
		cin >> tmp1 >> tmp2;
		b.push_back(P(tmp1, tmp2));
	}
	sort(b.begin(), b.end());

	for (int i = 0; i < N; i++) {
		int b_x = b[i].first, b_y = b[i].second;
		for (itr = a.begin(); itr != a.end(); ++itr) {
			int a_y = itr->first, a_x = itr->second;
			if (b_y > a_y && b_x > a_x) {
				cnt++;
				a.erase(itr);
				break;
			}
		}
	}
	cout << cnt << endl;
}

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

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

using namespace std;

template< typename cost_t >
struct Dinic {
  const cost_t INF;

  struct edge {
    int to;
    cost_t cap;
    int rev;
    bool isrev;
  };

  vector< vector< edge > > graph;
  vector< cost_t > min_cost;
  vector< int > iter;

  Dinic(int V) : INF(numeric_limits< cost_t >::max()), graph(V) {}

  void add_edge(int from, int to, cost_t cap) {
    graph[from].emplace_back((edge) {to, cap, (int) graph[to].size(), false});
    graph[to].emplace_back((edge) {from, 0, (int) graph[from].size() - 1, true});
  }

  bool bfs(int s, int t) {
    min_cost.assign(graph.size(), -1);
    queue< int > que;
    min_cost[s] = 0;
    que.push(s);
    while(!que.empty()) {
      int p = que.front();
      que.pop();
      for(auto &e : graph[p]) {
        if(e.cap > 0 && min_cost[e.to] == -1) {
          min_cost[e.to] = min_cost[p] + 1;
          que.push(e.to);
        }
      }
    }
    return (min_cost[t] != -1);
  }

  cost_t dfs(int idx, const int t, cost_t flow) {
    if(idx == t) return (flow);
    for(int &i = iter[idx]; i < graph[idx].size(); i++) {
      edge &e = graph[idx][i];
      if(e.cap > 0 && min_cost[idx] < min_cost[e.to]) {
        cost_t d = dfs(e.to, t, min(flow, e.cap));
        if(d > 0) {
          e.cap -= d;
          graph[e.to][e.rev].cap += d;
          return (d);
        }
      }
    }
    return (0);
  }

  cost_t max_flow(int s, int t) {
    cost_t flow = 0;
    while(bfs(s, t)) {
      iter.assign(graph.size(), 0);
      cost_t f = 0;
      while((f = dfs(s, t, INF)) > 0) {
        flow += f;
      }
    }
    return (flow);
  }

  void output() {
    for(int i = 0; i < graph.size(); i++) {
      for(auto &e : graph[i]) {
        if(e.isrev) continue;
        auto &rev_e = graph[e.to][e.rev];
        cout << i << "->" << e.to << " (flow: " << rev_e.cap << "/" << e.cap + rev_e.cap << ")" << endl;
      }
    }
  }
};

int main() {
  int V, E;
  scanf("%d %d", &V, &E);
  Dinic< int > g(V);
  for(int i = 0; i < E; i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    g.add_edge(a, b, c);
  }
  printf("%d\n", g.max_flow(0, V - 1));
}


Measured memory_bytes: 3336
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

int main(){
    int N,M;
    cin>>N>>M;
    vector<int> A[N];
    REP(i,N){
        REP(j,M){
            int a;
            cin>>a;
            A[i].push_back(a);
        }
    }
    int cnt[M+1];
    int maxmem=N;

    REP(i,M){
        int mem=0;
        int maxkind;
        fill_n(cnt,M+1,0);
        REP(j,N){
            cnt[A[j][0]]++;
            if(mem < cnt[A[j][0]]){
                mem =cnt[A[j][0]];
                maxkind =A[j][0];
            }
        }
        maxmem=min(maxmem,mem);

        REP(j,N)A[j].erase(find(ALL(A[j]),maxkind));

    }

    cout<<maxmem<<endl;

    return 0;
}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
int a[125252];
int b[125252];

int main(){
  scanf("%d",&n);
  REP(i,n)scanf("%d",a+i);
  REP(i,n)scanf("%d",b+i);
  sort(a,a+n);
  sort(b,b+n);
  int ait = 0, bit = 0;
  int acnt = 0, bcnt = 0;
  ll ans = 1;
  REP(_,2*n){
    if(ait<n && (bit==n || a[ait]<b[bit])){
      // choose a
      if(bcnt > 0){
        ans = ans*bcnt%MOD;
        bcnt--;
      }else{
        acnt++;
      }
      ait++;
    }else{
      // choose b
      if(acnt > 0){
        ans = ans*acnt%MOD;
        acnt--;
      }else{
        bcnt++;
      }
      bit++;
    }
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 1024
# LRLRRL
# 123456
# LLLRLL
n, k = map(int, input().split())
s = input()

def rev(s, k):
    n = len(s)
    happy = 0
    for i in range(n):
        if i < n - 1 and s[i] == s[i + 1]:
            happy += 1
    return min(n - 1, happy + 2 * k)

ans = rev(s, k)
print(ans)



Measured memory_bytes: 39408
def gcd(a,b):
    lt,gt = sorted([a,b])
    if lt == 0:
        return gt
    else:
        return gcd(gt % lt,lt)

def q3():
    N = int(input())
    A = list(map(int,input().split()))
    assert(N == len(A))
    ret = A[0]
    for n in range(1,N):
        ret = gcd(ret,A[n])
    print(ret)
    
q3()

Measured memory_bytes: 14252
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
#define inf 0x3f3f3f
#define N 10000
int fa[2*N+5],t,n,m,k;
double s[N+5][2],s1;
struct mzls
{
	int u,v;
	double w;
	bool operator<(const mzls &a)const
	{
		return a.w<w;
	}
}g[N*N+5],as;
inline int find(int x)
{
	if(fa[x]==-1)
		return x;
	return fa[x]=find(fa[x]);
}
inline double K()
{
	double sum=0.0;
	sort(g+1,g+t+1);
	memset(fa,-1,sizeof(fa));
	int j=0;
	for(int i=1;i<=t;i++)
	{
		int u=g[i].u,v=g[i].v;
		int r1=find(u),r2=find(v);
		if(r1!=r2)
		{
			fa[r2]=r1;
			sum+=g[i].w;
			j++;
			if(j>=n-1)
				break;
		}
	}
	return sum;
}
inline void insert(int x,int y,double z)
{
	as.u=x,as.v=y,as.w=z;
	g[++t]=as;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%lf%lf",&s[i][0],&s[i][1]);
	for(int i=1;i<=m;i++)
	{
		int x,y;
		double z;
		scanf("%d%d",&x,&y);
		z=sqrt((s[x][1]-s[y][1])*(s[x][1]-s[y][1])+(s[x][0]-s[y][0])*(s[x][0]-s[y][0]));
		s1+=z;
		insert(x,y,z);
	}
	printf("%lf\n",s1-K());
	return 0;
}


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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

int main()
{
    string s, t;
    cin >> s;
    cin >> t;

    int ans = 0;
    for (int i = 0; i < 3; i++)
    {
        if (s[i] == t[i])
        {
            ans++;
        }
    }
    cout << ans << endl;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
    ost<<"{"<<p.first<<","<<p.second<<"}";
    return ost;
}

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

inline int topbit(unsigned long long x){
    return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
    return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){
    return __builtin_parity(x);
}

const int INF=1001001001001001001ll;

int N;
int A[333];
int dp[55][2][2];
signed main(){
	cin>>N;
	rep(i,N)cin>>A[i];

	for(int i=3;i<N;i++)A[2]^=A[i];

	fill_n(**dp,55*2*2,INF);
	dp[0][0][0]=0;
	rep(i,40){
		int a0=A[0]>>i&1;
		int a1=A[1]>>i&1;
		int a2=A[2]>>i&1;
		rep(j,2){
			rep(k,2){
				rep(l,2){
					int b0=a0^j^l;
					int b1=a1^k^l;
					if((b0^b1^a2))continue;
					chmin(dp[i+1][(a0-j-l<0)][(a1+k+l>1)],dp[i][j][k]+(l<<i));
				}
			}
		}
	}

	int ans=dp[40][0][0];
	if(ans>=A[0])cout<<-1<<endl;
	else cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int a=0;
    int b=0;
    rep(i,s.size()){
        if(s.at(i)=='R')a++;
        else b++;
    }
    if(a>b) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3532
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "x", long, "y", long, "cost");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    long n, m;
    scan(n, m);
    auto a = aryread.sort().array();
    long cnt, lim = (a.sum() + (4 * m - 1)) / (4 * m);
    foreach (e; a)
    {
        cnt += e >= lim ? 1 : 0;
    }
    if (cnt >= m)
        writeln("Yes");
    else
        writeln("No");
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
string s[4];
int x[16],y[16];
int d[1<<16];
int main(){
	int N;
	cin>>N;
	rep(i,N) cin>>x[i]>>y[i];
	rep(i,4) cin>>s[i];
	rep(i,1<<16) d[i]=1e9;
	d[0]=0;
	rep(i,1<<16){
		bool p[4][4]={};
		rep(j,4) rep(k,4) p[j][k]=(i>>(j*4+k))&1;
		rep(j,N){
			for(int a=-3;a<=3;a++) for(int b=-3;b<=3;b++){
				char c='W';
				bool can=1;
				int ni=i;
				rep(X,x[j]) rep(Y,y[j]){
					if(X+a<0||X+a>=4||Y+b<0||Y+b>=4) continue;
					if(!p[X+a][Y+b]){
						ni|=1<<((X+a)*4+Y+b);
						if(c=='W') c=s[X+a][Y+b];
						else if(c!=s[X+a][Y+b]){
							can=0;
							goto done;
						}
					}
				}
				done:
				if(can) chmin(d[ni],d[i]+1);
			}
		}
	}
	cout<<d[65535]<<endl;
}

Measured memory_bytes: 1464
#include<bits/stdc++.h>
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {

        string s;
        cin >> s;

        for(int i = 0; i < s.size(); i++)
        {
            s[i]= tolower(s[i]);
        }
        int cnt = 0;

        string s1, s2, s3, s4, s5, s6;
        string temp = s;
        s1 = s;
        reverse(s1.begin(), s1.end());
        //cout << endl <<endl << endl;
        //cout << temp <<" " <<s1  <<endl;


        if(s1 == temp)
            cnt++;

        int x = ((s.size()-1)/2);
        s3 = s.substr(0, x);
        s4 = s3;
        reverse(s3.begin(), s3.end());

        //cout << s3 <<" " << s4 <<endl;
        if(s3 == s4)
            cnt++;

        s5 = s.substr((s.size()+3/2 - 1), s.size());
        s6 = s5;
        reverse(s5.begin(), s5.end());

        //cout << endl <<endl <<endl;
       // cout << s5 <<endl;;

        if(s6 == s5)
            cnt++;




        if(cnt == 3)
            cout << "Yes" <<endl;
        else
            cout << "No" <<endl;







        return 0;
    }


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int height,width;
  cin >> height >> width;
  char w[width * height];
  for(int i = 0; i < width * height; i++){
    cin >> w[i];
  }
  for(int i = 0; i < width + 2; i++){
    cout << "#";
  }
  cout << endl;
  for(int i = 0; i < height; i++){
    cout << "#";
    for(int j = 0; j < width; j++){
      cout << w[i * width + j];
    }
    cout << "#" << endl;
  }
  for(int i = 0; i < width + 2; i++){
    cout << "#";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
N = 10007

sieve = [*0..N]
2.upto(Math.sqrt(N).to_i) do |i|
  next if sieve[i].zero?
  2.upto(N / i) {|j| sieve[i * j] = 0}
end
sieve = sieve[2..-1].reject {|x| x.zero?}

until (n = $<.gets.to_i).zero?
  idx = sieve.index {|i| i > n}
  i = 1
  i += 1 until sieve[idx - i] - sieve[idx - i - 1] == 2
  puts "#{sieve[idx - i - 1]} #{sieve[idx - i]}"
end


Measured memory_bytes: 7028
use std::collections::VecDeque;

fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: usize = read(&mut stdin_lock, &mut buf, b' ');
    let q: usize = read(&mut stdin_lock, &mut buf, b'\n');
    let mut vv = vec![Vec::new(); n + 1];
    for _ in 0..n - 1 {
        let a: usize = read(&mut stdin_lock, &mut buf, b' ');
        let b: usize = read(&mut stdin_lock, &mut buf, b'\n');
        vv[a].push(b);
    }
    let mut cv = vec![0i64; n + 1];
    for _ in 0..q {
        let p: usize = read(&mut stdin_lock, &mut buf, b' ');
        let x: i64 = read(&mut stdin_lock, &mut buf, b'\n');
        cv[p] += x;
    }

    let mut ans = vec![0i64; n + 1];
    let mut queue = VecDeque::new();
    ans[1] = cv[1];
    for &b in vv[1].iter() {
        let pair = (b, cv[1]);
        queue.push_back(pair);
    }
    while !queue.is_empty() {
        match queue.pop_front() {
            Some(pair) => {
                let (b, c) = pair;
                let s = c + cv[b];
                ans[b] = s;
                for &bc in vv[b].iter() {
                    queue.push_back((bc, s));
                }
            }
            None => unreachable!(),
        }
    }
    for i in 1..n {
        print!("{} ", ans[i]);
    }
    println!("{}", ans[n]);
}


Measured memory_bytes: 24044
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////

ll gcd (ll a, ll b) { return b?gcd(b,a%b): a;}

int main() {
    int k; cin >> k;
    vector<vector<ll>> a(210, vector<ll>(210, 1));
    repf(i,1,201) repf(j,i,201) {
        a[i][j] = a[j][i] = gcd(i,j);
    }

    ll ans = 0;
    repf(i,1,k+1) repf(j,1,k+1) repf(l,1,k+1) {
        ans += gcd(i, a[j][l]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3988
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
double p,q,a;
int n;
int dfs(double x,double y,double sum,int d){
  int res=0;
  if(abs(p/q-x)<1e-9)return 1;
  if(p/q<x)return 0;
  for(double i=y;i*sum<=a;i++)
    if(d)res+=dfs(x+1/i,i,sum*i,d-1);
  return res;
}
main(){
  while(cin>>p>>q>>a>>n,p)
  cout<<dfs(0,1,1,n)<<endl;
}

Measured memory_bytes: 3208
#include<bits/stdc++.h>
#include<vector>
#include<iostream>
#include<map>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<deque>
#define ll long long
using namespace std;
#define BUF_SIZE 1048576
char _buf[BUF_SIZE],*_is=_buf,*_it=_buf;
inline char rdc(){
	if (_is==_it) _it=(_is=_buf)+fread(_buf,1,BUF_SIZE,stdin);
	return *_is++;
}
inline int rdi(){
	int x=0,f=0;
	register char ch=rdc();
	while ((ch<'0' or ch>'9') and (ch^'-')) ch=rdc();
	if (ch=='-') f=1,ch=rdc();
	while (ch>='0' and ch<='9') x=(x<<3)+(x<<1)+(ch^'0'),ch=rdc();
	return f?-x:x;
}
inline void write(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
inline void _write(int x){
	write(x);
	putchar(' ');
}
inline void print(int x){
	write(x);
	putchar('\n');
}
int n,a[22][22];
ll dp[1<<21];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	int i,j;
	for(i=0;i<n;++i) for(j=0;j<n;++j) cin>>a[i][j];
	dp[0]=1;
	for(i=1;i<1<<n;++i) for(j=0;j<n;++j) if(i&1<<j and a[__builtin_popcount(i)-1][j]) dp[i]=(dp[i]+dp[i^1<<j])%1000000007;
	cout<<dp[(1<<n)-1]<<endl;
	return 0;
}

Measured memory_bytes: 16640
#include <iostream>

int main(){
  int A = 0;
  int B = 0;
  int wa = 0;
  std::cin >> A >> B;
  A > B ? wa = A: wa = B;
  A > B ? A-- : B--;
  A > B ? wa +=A: wa +=B;
  std::cout << wa << std::endl;


}


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

int main()
{
    int n; cin >> n;
    map<string,int> s;
    string tmp;
    rep(i,n) {
        cin >> tmp;
        s[tmp]++;
    }
    int m = 1;
    for(pair<string, int> x: s) {
        m = max(m, x.second);
    }
    vector<string> ans;
    for(pair<string, int> x: s) {
        if(x.second == m) ans.push_back(x.first);
    }
    sort(ans.begin(), ans.end());
    for(string x: ans) cout << x << endl;
}

Measured memory_bytes: 27240
#include <bits/stdc++.h>
using namespace std;
int check_digit(int t){
    int res=0;
    while(t!=0){
        t/=10;
        res++;
    }
    return res;
}
int sol(int t){
    int cd=check_digit(t);
    int c10=10;
    int res=0;
    for(int i=1;i<cd;i++){
        int t1=t%c10;
        int t2=t/c10;
        res=max(res,t1*t2);
        c10*=10;
    }
    return res;
}
int main(void){
    // Your code here!
    int q;
    cin>>q;
    int n[110];
    for(int i=0;i<q;i++){
        cin>>n[i];
        int ans=0;
        while(n[i]/10!=0){
            n[i]=sol(n[i]);
            ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3100
#include "bits/stdc++.h"

// Begin {{{
using namespace std;
#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, b, e) for (i64 i = (b); i <= (e); ++i)
#define repr(i, b, e) for (i64 i = (b); i >= (e); --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
inline i64 sigma(i64 n) { return n * (1 + n) >> 1; }
inline i64 updiv(i64 n, i64 d) { return (n + d - 1) / d; }
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;
#ifndef DEBUG
#define dump(...)
#endif

inline void input() {}
template <class Head, class... Tail>
inline void input(Head&& head, Tail&&... tail) {
  cin >> head;
  input(forward<Tail>(tail)...);
}

inline void outs() { cout << "\n"; }
template <class Head, class... Tail>
inline void outs(Head&& head, Tail&&... tail) {
  cout << head << (sizeof...(tail) ? " " : "");
  outs(forward<Tail>(tail)...);
}

template <class T>
inline void outs(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e == &vec.back()]; }

template <class T>
inline void outs(vector<vector<T>> &df) { for (auto &vec : df) outs(vec); }

inline void outl() { cout << "\n"; }
template <class Head, class... Tail>
inline void outl(Head&& head, Tail&&... tail) {
  cout << head << (sizeof...(tail) ? "\n" : "");
  outl(forward<Tail>(tail)...);
}

template <class T>
inline void outl(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

inline void outn() {}
template <class Head, class... Tail>
inline void outn(Head&& head, Tail&&... tail) {
  cout << head;
  outn(forward<Tail>(tail)...);
}

template <class T>
inline void outn(vector<T> &vec) { for (auto &e : vec) cout << e; }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
  return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
  return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}
// }}} End

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  var(string, s);

  bool odd = true;
  bool even = true;
  rep(i, s.length()) {
    if (i % 2 == 0) {
      if (s[i] != 'R' && s[i] != 'U' && s[i] != 'D') odd = false;
    }
    else {
      if (s[i] != 'L' && s[i] != 'U' && s[i] != 'D') even = false;
    }
  }

  outl((odd && even) ? "Yes" : "No");

  return 0;
}


Measured memory_bytes: 256