akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;

int n;

map<pair<string, string>, long long> clct(string s) {
    map<pair<string, string>, long long> res;
    function<void(int)> go;
    string a, b;
    go = [&](int k) {
        if (k == n) {
            res[{a,b}]++;
        } else {
            a.push_back(s[k]);
            go(k+1);
            a.pop_back();
            b.push_back(s[k]);
            go(k+1);
            b.pop_back();
        }
    };
    go(0);
    return res;
}


int main() {
    ios_base::sync_with_stdio(false);
    string s;
    cin >> n >> s;
    auto ml = clct(s.substr(0, n));
    auto mr = clct(s.substr(n));
    long long res = 0;
    for (auto pr: ml) {
        auto sa = pr.first.first, sb = pr.first.second;
        reverse(sa.begin(), sa.end());
        reverse(sb.begin(), sb.end());
        auto cnt = pr.second;
        res += mr[{sb, sa}]*cnt;
    }
    cout << res << endl;
}

Measured memory_bytes: 127232
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
ll n,k;
ll a[5001];
ll p[5001];
int main()
{
	ios::sync_with_stdio(0);
	cin>>n>>k;
	rep(i,n){
		cin>>a[i];
	}
	sort(a,a+n);
	rep(i,n){
		if(i!=0)
		p[i]=p[i-1]+a[i];
		else
		p[i]=a[i];
	}
	
    if(p[n-1]<k){
		cout<<n;
		re 0;
	}
	ll ans=0;
	rep(i,n){
		ll n1,n2; 
		if(p[i]<k){
			n1=k;
			n2=0;
		}else{
			n1=k-a[i];
			n2=a[i];
		}
		ll pos=lower_bound(p,p+n,n1)-p;
		if(n2==0){
			bool pos1=false,pos2=false;
			for(int j=pos;j>=0;j--){
				if(j==i)
				continue;
				if(p[pos]-n2-a[j]>=k)
				n2+=a[j];
			}
			if(p[pos]-n2-a[i]>=k)
			pos1=true;
			ll sum=a[i];
			for(int j=n-1;j>=0;j--){
				if(j==i)
				continue;
				if(sum+a[j]<k+a[i])
				sum+=a[j];
			}
			if(sum<k)
			pos2=true;
			if(pos1&&pos2)
			ans++;
		}
	}
    cout<<ans;
    re 0;
}

Measured memory_bytes: 384
N, M = list(map(int, input().split()))
K = [list(map(int, input().split())) for _ in range(M)]
P = list(map(int, input().split()))
count = 0
for i in range(2 ** N):
    S = [0] * N
    E = [0] * M
    for j in range(N):
        if i >> j & 1:
            S[j] = 1
    for m in range(M):
        SN = [k - 1 for k in K[m][1:]]
        if sum([S[sn] for sn in SN]) % 2 == P[m]:
            E[m] = 1
    if all(E):
        count += 1
print(count)


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

#define st first
#define nd second
typedef long long LL;
typedef pair <int, int> PII;
typedef pair <LL, LL> PLL;

int main()
{
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d", max(a + b, max(a - b, a * b)));

    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

class Main {

    public static int[] On;
    public static int n;
    public static int m;
    public static int k[];
    public static int s[][];
    public static int p[];

    public static int ans;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        k = new int[m];
        On = new int[n];
        Arrays.fill(On, 0);
        s = new int[m][n];
        for (int i = 0; i < m; i++) {
            k[i] = sc.nextInt();
            for (int j = 0; j < k[i]; j++) {
                int tmp = sc.nextInt();
                s[i][tmp - 1] = 1;
            }
        }
        p = new int[m];
        for (int i = 0; i < m; i++) {
            p[i] = sc.nextInt();
        }
        // 全探索する
        ans = 0;
        Solve(-1);
        System.out.println(ans);
        sc.close();
    }

    public static void Solve(int pos) {
        if (pos == n - 1) {
            if (Check()) {
                ans++;
            }
            return;
        }
        On[pos + 1] = 1;
        Solve(pos + 1);
        On[pos + 1] = 0;
        Solve(pos + 1);
    }

    public static boolean Check() {
        for (int i = 0; i < m; i++) {
            int wa = 0;
            for (int j = 0; j < n; j++) {
                if (s[i][j] == 1 && On[j] == 1) {
                    wa++;
                }
            }
            if (wa % 2 != p[i]) {
                return false;
            }
        }
        return true;
    }
}

Measured memory_bytes: 23764
/* 数を左から順番にスタックに入れていく。
'+' が入るならスタックが空になるまで取り出して10 の累乗をしながら加える。
*/

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

ll ans = 0;

int main(){
    string str;
    cin >> str;
    int n = str.size();

    vector<int> v;
    for (int i = 0; i < str.size(); i++) v.push_back(str[i] - '0');

    stack<int> s;
    for (int bit = 0; bit < 1<<(n - 1); bit++){
        s.push(v[0]);
        for (int i = 0; i < n; i++){
            if (bit & (1<<i) || i == n - 1){
                ll cnt = 1;
                while(s.size()){
                    int p = s.top(); s.pop();
                    ans += p * cnt;
                    cnt *= 10;
                }
            }
            if (i < n - 1) s.push(v[i + 1]);
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
	int n;
	cin >> n;
	int A[100];
	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}
	for (int i = n-1; i >= 0; i--) {
		if (i != n - 1) cout << " ";
		cout << A[i];
	}
	cout << endl;

	return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<int> e(N + 1);
	for (int i = 2; i <= N; i++) {
        int x = i;
		for (int j = 2; j <= i; j++) {
			while (x % j == 0) {
				e.at(j)++;
				x /= j;
			}
		}
	}
	int ans = 0;
    vector<vector<vector<bool>>> _442(N + 1, vector<vector<bool>>(N + 1, vector<bool>(N + 1, false)));
	for (int i = 2; i <= N; i++) {
		for (int j = 2; j <=N; j++) {
			for (int k = 2; k <= N; k++) {
				if ((i != j) && (j != k) && (i != k)) {
					if ((e.at(i) >= 4) && (e.at(j) >= 4) && (e.at(k) >= 2)) {
						if (_442.at(i).at(j).at(k) == false) {
                            ans++;
							_442.at(i).at(j).at(k) = true;
							_442.at(j).at(i).at(k) = true;
						}
					}
				}
			}
		}
	}
	for (int i = 2; i <= N; i++) {
		for (int j = 2; j <= N; j++) {
			if (i != j) {
				if (e.at(i) >= 14 && e.at(j) >= 4) {
					ans++;
				}
			}
		}
	}
	for (int i = 2; i <= N; i++) {
		for (int j = 2; j <= N; j++) {
			if (i != j) {
				if (e.at(i) >= 24 && e.at(j) >= 2) {
					ans++;
				}
			}
		}
	}
	for (int i = 2; i <= N; i++) {
		if (e.at(i) >= 74) {
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
 
int n,q;
std::string s;
std::vector<std::pair<int,int>> query;
std::vector<int> ac; //どれだけACがあったか
 
void input(){
    std::cin>>n>>q;
    std::cin>>s;
    query.resize(q);
    ac.resize(n+1);
 
    for(int i=0;i<q;i++){
        int a,b;
        std::cin>>a>>b;
        a--;b--;
        query[i] = {a,b};
    }
 
    int cnt = 0;
    for(int i=1;i<n+1;i++){
        if(s[i-1]=='A' && s[i]=='C')cnt++;
        ac[i+1]=cnt;
    }
}
 
int main(){
    input();
    for(int i=0;i<q;i++){
        int l = query[i].first;
        int r = query[i].second;
        std::cout<<ac[r+1] - ac[l+1]<<std::endl;
    }
}

Measured memory_bytes: 2176
# include <iostream>
# include <vector>
using namespace std;
int main() {
	char a,b;
	cin >> a;
	if (a == 'H') {
		cin >> b;
		if (b == 'H') {
			cout << "H" << endl;
		}
		else {
			cout << "D" << endl;
		}
	}
	else {
		cin >> b;
		if (b == 'H') {
			cout << "D" << endl;
		}
		else {
			cout << "H" << endl;
		}
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<climits>

#define bigprime  1000000007
using ll = long long;
using namespace std;

void solve(vector<vector<char>> &v,int h,int w)
{
    vector<vector<ll>> dp(h+1,vector<ll>(w+1,0));
    dp[0][1] = 1;
    for(int i=1;i<=h;++i)
    {
        for(int j=1;j<=w;++j)
        {
            ll x = 0,y=0;
            if(v[i-1][j] == '.')
                x = dp[i-1][j];
            if(v[i][j-1] == '.')
                y = dp[i][j-1];
            dp[i][j] = (x % bigprime + y % bigprime) % bigprime;
        }
    }
    // for(int i=1;i<=h;++i)
    // {
    //     for(int j=1;j<=w;++j)
    //         cout<<dp[i][j]<<" ";
    //     cout<<"\n";
    // }
    cout<<dp[h][w];
}

int main()
{
    int h{},w{};
    cin>>h>>w;
    vector<vector<char>> v(h+1,vector<char>(w+1,'.'));
    for(int i=1;i<=h;++i)
    {
        for(int j=1;j<=w;++j)
            cin>>v[i][j];
    }
    solve(v,h,w);
    return 0;
}

Measured memory_bytes: 9088
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using namespace std;


int main()
{
    string s;
    cin >> s;
    ll k;
    cin >> k;
    ll ans = 0;
    ll cnt = 0;
    int n = s.size();
    bool every = true;
    for(int i = 0; i < n-1; i++){
        if(s[i] != s[i+1]){
            every = false;
        }
    }
    for(int i = 0; i < n; i++){
        if(s[i] == s[i+1]){
            cnt++;
            i++;
        }
    }
    if(every && n % 2 != 0){
        ans = (2 * cnt + 1) * (k / 2);
        if(k % 2 != 0){
            ans += cnt;
        }
        cout << ans << endl;
    }else{
        ll cnt2 = 0;
        string t;
        t = s + s;
        for(int i = 0; i < 2*n; i++){
            if(t[i] == t[i+1]){
                cnt2++;
                i++;
            }
        }
        cnt2 -= cnt;
        ans = cnt2*(k-1) + cnt;
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
///mAAria...
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(),v.end()
#define allr(v) v.begin(),v.end()
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pii pair<int,int>
#define pi 3.1415926535897932384626433832
#define mod 1000000007
//#define mod 998244353
#define inf 1000000000
#define pr1(a) cout << a << endl
#define pr2(a,b)cout << a <<  " " <<b<< endl
#define pr3(a,b,c) cout << a <<" " << b << " " << c << endl

const long double PI = acos(-1);

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

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

bool power_of_two(int n){
    return ((n&(n-1))==0);

}

void solve(){

    int n,x,t;
    cin >> n >> x >> t;
    
    int ans = (n+x-1)/x;
    cout << ans*t << endl;

} 

signed main() 
{   
    IOS;
    int t = 1;
   // cin >> t;

    for(int i = 1;i<=t;i++){
        solve();
    }
    return 0;
} 

 
    

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

int main() {
    int n; cin >> n;
    vector<int> d(n);
    rep(i, d.size())
        cin >> d.at(i);
    
    sort(d.begin(), d.end());

    int ans = 0;
    for (int i = d.at(d.size() / 2 - 1) + 1; i<= d.at(d.size() / 2); i++)
        ans++;

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

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(){
int N,M;
  cin>>N>>M;
  int ans[N+1];
  ans[0]=-1;
  for(int i=0;i<N;i++){ans[i]=0;}
  int H[N+1];
  int A,B;
  for(int i=1;i<=N;i++){cin>>H[i];}
  for(int i=0;i<M;i++){cin>>A>>B;
             if(H[A]>H[B]){
               ans[B]=-1;
                       if(ans[A]>=0){ans[A]=1;}
             }
             if(H[A]<H[B]){
               ans[A]=-1;
             if(ans[B]>=0){ans[B]=1;}
            }
                       if(H[A]==H[B]){ans[A]=-1;
                                     ans[B]=-1;}
                      }
int answer=0;
  for(int i=1;i<=N;i++){if(ans[i]>=0){answer++;}}
    cout<<answer;

}

Measured memory_bytes: 3924
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    long long int a[n+1],b[n+1],c[n+1];
    for(int i=1;i<=n;i++)
    cin>>a[i]>>b[i]>>c[i];
    long long ans[n+1][3];
    ans[1][1]=b[1];
    ans[1][0]=a[1];
    ans[1][2]=c[1];
    for(int i=2;i<=n;i++){
        ans[i][0]=a[i]+max(ans[i-1][1],ans[i-1][2]);
        ans[i][1]=b[i]+max(ans[i-1][0],ans[i-1][2]);
        ans[i][2]=c[i]+max(ans[i-1][1],ans[i-1][0]);
    }
    long long int gh = max(ans[n][0],max(ans[n][1],ans[n][2]));
    cout<<gh<<endl;
    return 0;
}


Measured memory_bytes: 4992
xyas = []

w, h, n = list(map(int, input().split()))
for _ in range(n):
  xyas.append(list(map(int, input().split())))

x = [0, w]
y = [0, h]
  
for xya in xyas:
  if xya[2] == 1:
    if x[0] < xya[0]:
      x[0] = xya[0]
  elif xya[2] == 2:
    if x[1] > xya[0]:
      x[1] = xya[0]
  elif xya[2] == 3:
    if y[0] < xya[1]:
      y[0] = xya[1]
  else:
    if y[1] > xya[1]:
      y[1] = xya[1]

width = (x[1] - x[0]) 
height = (y[1] - y[0])
if width <= 0 or height <= 0:
  print(0)
else:
  print(width * height)

Measured memory_bytes: 3064
#include<stdio.h>
int main(){
	int s,m,h,sec;
	scanf("%d",&sec);
	h=(int) sec/3600;
	m=(int) (sec-h*3600)/60;
	s=sec-h*3600-m*60;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}


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

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

	bool res = false;
	for(int i = 0; i <= n; i+=4){
		for(int j = 0; j <= n-i; j+=7){
			if(i+j == n){
				res = true;
				break;
			}
		}
	}

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

Measured memory_bytes: 256
from math import gcd # Python3.6以降
# --------------------------------------------------------------

# n以下の素数列挙: O-nlogn
def primes(n):
    prs = []
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]:
            continue
        for j in range(i*2, n+1, i):
            is_prime[j] = False
    for i in range(len(is_prime)):
        if is_prime[i]:
            prs.append(i)
    return prs

n    = int(input())
lis  = list(map(int,input().split()))
A    = 10**6
nlis = [0]*A
flg_pairwise = True

for i in range(n):
    nlis[lis[i]-1] += 1

for i in primes(A):
    cnt = 0
    for j in range(i-1,A,i):
        cnt += nlis[j]
    if cnt > 1:
        flg_pairwise = False
        break

if flg_pairwise:
    print('pairwise coprime')
else:
    for i in range(n-1):
        if i==0:
            tmp = gcd(lis[i],lis[i+1])
        else:
            tmp = gcd(tmp,lis[i+1])

    if tmp==1:
        print('setwise coprime')
    else:
        print('not coprime')

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

bool is_prime(int x) {
	for (int i = 2; i < x; ++i) {
		if (x % i == 0)
			return false;
	}
	return true;
}

int main(int argc, char const *argv[])
{
	int x; cin >> x;
	while (not is_prime(x)) {
		x++;
	}
	cout << x << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
    int r,g,b,n;
    cin >> r >> g >> b >> n;
    int num = 0;
    int sum = n;
    for (int i = 0; i <= n/r; i++){
        sum = n;
        for (int j = 0; j <= (n-r*i)/g; j++){
            sum = n - r*i -g*j;
            if (sum % b == 0){
                num += 1;
            }
        }
    }
    cout << num << endl;
}

Measured memory_bytes: 256
PROGRAM piyo
      IMPLICIT NONE
      logical ::flag = .false.
      character(3) :: s
      integer :: i
      
      read*,s
      
      
      do i = 1,2
        if( s(i:i)/=s(i+1:i+1) ) flag = .true.
      end do
      
      if( flag )then
        print*,'Yes'
      else
        print*,'No'
      end if
      
      
      
      
      END PROGRAM

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

bool solve(string S) {
  string T = S;
  reverse(T.begin(), T.end());
  if (S != T) return false;
  
  S = S.substr(0, S.size()/2);
  T = S;
  reverse(T.begin(), T.end());
  if (S != T) return false;
  
  return true;
}

int main() {
  string S;
  cin >> S;
  if (solve(S)) puts("Yes");
  else puts("No");
}

Measured memory_bytes: 3612
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <random>
#include <utility>
#include <set>
#include <map>
//#include <queue>
#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using vc = vector<char> ;
using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
ll INF = 1ll<<61 ;

void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
void fix_cout(){cout << fixed << setprecision(20) ;}
void chmax(ll &a,ll b){	if(a<b) a = b ;}
void chmin(ll &a,ll b){ if(a>b) a = b ;}

int main(){
	ll m,h,w ;
	cin >> h >> w >> m ;
	map<ll,ll> y,x ;
	set<pll> s ;
	for(int i=0;i<m;i++){
		ll a,b ;
		cin >> a >> b ;
		s.insert({a,b}) ;
		y[a]++ ;
		x[b]++ ;
	}
	vector<pll> a,b ;
	for(auto p:y) a.emplace_back(p.second,p.first) ;
	for(auto p:x) b.emplace_back(p.second,p.first) ;
	ll ans = 0 ;
	sort(all(a)) ; reverse(all(a)) ;
	sort(all(b)) ; reverse(all(b)) ;
	for(int i=0;i<a.size();i++){
		ll sub = a.at(i).first ;
		sub += b.at(0).first ;
		if(s.count({a.at(i).second,b.at(0).second})) sub-- ;
		chmax(ans,sub) ;
		sub = a.at(i).first ;
		if(b.size()>1){
			sub += b.at(1).first ;
			if(s.count({a.at(i).second,b.at(1).second})) sub-- ;
			chmax(ans,sub) ;
		}
	}
	for(int i=0;i<b.size();i++){
		ll sub = b.at(i).first ;
		sub += a.at(0).first ;
		if(s.count({a.at(0).second,b.at(i).second})) sub-- ;
		chmax(ans,sub) ;
		sub = b.at(i).first ;
		if(a.size()>1){
			sub += a.at(1).first ;
			if(s.count({a.at(1).second,b.at(i).second})) sub-- ;
			chmax(ans,sub) ;
		}
	}
	cout << ans << endl ;
}


Measured memory_bytes: 76548
#include<stdio.h>

#define N 100000
#define Q 50000

int num, renum;

int BinaryS(int *x, int *y){
  int rslt=0, left, right, mid, i;

  for(i=0; i<renum; i++){
    left = 0;
    right = num;
    
    while(left<right){
      mid = (left+right)/2;
      if(*(x+mid) == *(y+i)){
	rslt++;
	break;
      }else if(*(y+i)<*(x+mid)){
	right = mid;
      }else left = mid+1;
    }
  }

  return rslt;
  
}


int main (){

  int i, rslt;
  int num1[N], num2[Q];

  scanf("%d", &num);

  for(i=0; i<num; i++)
    scanf("%d", &num1[i]);

  scanf("%d", &renum);

  for(i=0; i<renum; i++)
    scanf("%d", &num2[i]);

  rslt = BinaryS(num1, num2);

  printf("%d\n", rslt);
  
  return 0;
  
}

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

int dh[] = {1, 0, -1, 0};
int dw[] = {0, 1, 0, -1};

int main(){
  int H, W;
  string s[50];
  cin >> H >> W;
  for(int h = 0; h < H; h++){
    cin >> s[h];
  }
  bool yes = true;
  for(int h = 0; h < H; h++){
    for(int w = 0; w < W; w++){
      if(s[h][w] == '.'){
	continue;
      }
      bool has_neigh_black = false;
      for(int i = 0; i < 4; i++){
	int h_ = h + dh[i];
	int w_ = w + dw[i];
	if(h_ < 0 || h_ >= H || w_ < 0 || w_ >= W){
	  continue;
	}
	if(s[h_][w_] == '#'){
	  has_neigh_black = yes;
	}
      }
      if(!has_neigh_black){
	//cout << h << ", " << w << endl;
	yes = false;
      }
    }
  }
  if(yes){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}



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

int main() {
    int n;
    cin >> n;
    double sum = 0;
    for (int i = 0; i < n; i++) {
        double a;
        cin >> a;
        sum += 1 / a;
    }
    printf("%.10f\n", 1 / sum);
}            

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
#include<unordered_set>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

int a[100010], b[100010];
signed main(void)
{
	int n, w, h;
	cin >> n >> w >> h;
	REP(i, n) {
		int x, y, ww;
		cin >> x >> y >> ww;
		a[max(0, x-ww)]++;
		a[min(w, x+ww)]--;
		b[max(0, y-ww)]++;
		b[min(h, y+ww)]--;
	}

	FOR(i, 1, w) a[i] += a[i-1];
	FOR(i, 1, h) b[i] += b[i-1];
	bool f1 = true, f2 = true;
	REP(i, w) if(!a[i]) {
		f1 = false;
		//cout << "w:" << i << endl;
	}
	REP(i, h) if(!b[i]) {
		f2 = false;
		//cout << "h:" << i << endl;
	}
	if(f1 || f2) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3888
#include<cstdio>  
#include<string>  
#include<iostream>  
#include<cstring>  
#include<algorithm>  
using namespace std;  
typedef long long LL;  
const int INF = 0x7FFFFFFF;  
const int maxn = 1e5 + 10;  
   
int a[11],vis[11],flag;  
  
void dfs(int x,int l,int r)  
{  
    int i;  
    if(x==11)return;   
    if(flag)return;  
    if(a[x]>l)dfs(x+1,a[x],r);  
    else if(a[x]>r)dfs(x+1,l,a[x]);  
    else{flag=1;return;}  
}  
  
int main()  
{  
  int T,i,j,k;  
  scanf("%d",&T);  
  while(T--)  
  {  
    flag=0;  
    for(i=1;i<=10;i++)  
      scanf("%d",&a[i]);  
    memset(vis,0,sizeof(vis));  
    dfs(1,0,0);  
    if(flag)printf("NO\n");  
    else printf("YES\n");  
  }  
 return 0;  
}  


Measured memory_bytes: 3104
b = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
count=0
list=[]
for i in range(1,len(a)-1):
    list.append(a[i-1])
    list.append(a[i])
    list.append(a[i+1])
    if not max(list) == a[i] and not min(list)==a[i]:
        count+=1
    list=[]
print(count)


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

long long dp[110][100010];
int main(){
  int n,w;
  int n_w[110];
  long long n_v[110];
  memset(dp,0,sizeof(dp));
  scanf("%d %d",&n,&w);
  for(int i=0;i<n;i++){
    scanf("%d %lld",&n_w[i],&n_v[i]);
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<=w;j++){
      if(n_w[i]<=j){
          dp[i+1][j]=max(dp[i][j],dp[i][j-n_w[i]]+n_v[i]);
      }else{
          dp[i+1][j]=dp[i][j];
      }
    }
  }
  printf("%lld\n",dp[n][w]);
  return 0;
}


Measured memory_bytes: 86144
#c[i][j]=数字iから数字jにかえるのに必要な最小の魔力
H,W=list(map(int,input().split()))
c=[[i for i in range(10)] for j in range(10)]
for i in range(10):
  s=list(map(int,input().split()))
  for j in range(10):
    c[i][j]=s[j]

#ワーシャルフロイド法
for k in range(10):
  for i in range(10):
    for j in range(10):
      c[i][j]=min(c[i][k]+c[k][j],c[i][j])

ans=0
for i in range(H):
  a=list(map(int,input().split()))
  for j in range(W):
    if a[j]!=-1:
      ans=ans+c[a[j]][1]
print(ans)



Measured memory_bytes: 73624
PROGRAM-ID.                      ABC_106_D.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 INP1    PIC X(17).
    01 N       PIC 9(3).
    01 M       PIC 9(6).
    01 Q       PIC 9(6).

    01 INP2    PIC X(7).
    01 X       PIC 9(3).
    01 Y       PIC 9(3).

*> 2次元累積和用
    01 train1.
        03 train11 OCCURS 500 INDEXED YX1 YX2.
            05 train PIC 9(6) OCCURS 500 INDEXED XX1 XX2 VALUES ZERO.

    01 i       PIC 9(3) BINARY.
    01 j       PIC 9(3) BINARY.

    01 k       PIC 9(6) BINARY.

    01 tmp     PIC 9(3) BINARY.

    01 t       PIC 9(6).

    01 ans     PIC X(6).

    01 ZS      PIC Z(6)9.
    01 DUMMY   PIC X(1).

PROCEDURE                        DIVISION.
    ACCEPT INP1.

    UNSTRING INP1
    DELIMITED BY SPACE
    INTO N M Q.

    PERFORM VARYING k FROM 1 BY 1 UNTIL M < k
        ACCEPT INP2

        UNSTRING INP2
        DELIMITED BY SPACE
        INTO X Y

*> train(Y X)
        SET XX1 TO X
        SET YX1 TO Y
        ADD 1 TO train(YX1 XX1)
    END-PERFORM.

*> 2次元累積和 横
    PERFORM VARYING i FROM 1 BY 1 UNTIL N < i
        PERFORM VARYING j FROM 2 BY 1 UNTIL N < j
            SUBTRACT 1 FROM j GIVING tmp
            SET XX1 TO tmp
            SET XX2 TO j
            SET YX1 TO i
            ADD train(YX1 XX1) TO train(YX1 XX2)
        END-PERFORM
    END-PERFORM.

*> 2次元累積和 縦
    PERFORM VARYING i FROM 2 BY 1 UNTIL N < i
        PERFORM VARYING j FROM 1 BY 1 UNTIL N < j
            SUBTRACT 1 FROM i GIVING tmp
            SET YX1 TO tmp
            SET YX2 TO i
            SET XX1 TO j
            ADD train(YX1 XX1) TO train(YX2 XX1)
        END-PERFORM
    END-PERFORM.

*> A        - B        - C        + D        = E
*> □□□□   □□□□   □□□□   □□□□   □□□□
*> ■■■□   ■□□□   □□□□   □□□□   □■■□
*> ■■■□   ■□□□   □□□□   □□□□   □■■□
*> ■■■□   ■□□□   ■■■□   ☆□□□   □□□□

    PERFORM VARYING k FROM 1 BY 1 UNTIL Q < k
        ACCEPT INP2

        UNSTRING INP2
        DELIMITED BY SPACE
        INTO X Y

        SET XX1 TO Y
        SET YX1 TO Y

        IF 1 = X THEN
            MOVE train(YX1 XX1) TO t
        ELSE
            SUBTRACT 1 FROM X GIVING tmp
            SET XX2 TO tmp
            SET YX2 TO tmp
            COMPUTE
                t = train(YX1 XX1) - train(YX1 XX2)
                    - train(YX2 XX1) + train(YX2 XX2)
        END-IF

        MOVE t TO ZS
        PERFORM UNANS

        DISPLAY ans(1:FUNCTION STORED-CHAR-LENGTH(ans))
    END-PERFORM.

    STOP RUN.

UNANS                            SECTION.
    UNSTRING
        ZS DELIMITED BY ALL SPACE
        INTO DUMMY ans
    END-UNSTRING.


Measured memory_bytes: 2432
#bin/usr/env python3

n = int(input())

s =[]
p =[]

for i in range(n):
    a = input().split()
    s.append([a[0],int(a[1])])

s_list = sorted(s, key=lambda x:(x[0],-x[1]))
rank =[0 for i in range(n)]

for i in range(n):
    for j in range(n):
        if (s_list[i] == s[j]):
            rank[i] = j+1
            
for i in range(n):
    print(rank[i])



Measured memory_bytes: 3064
import sys

sys.setrecursionlimit(1000000)

import bisect
import math
import collections
import heapq


def prime_factors(n):
    c = collections.Counter()
    while n > 1:
        for i in range(2, n + 1):
            if n % i == 0:
                c.update([i])
                n //= i
                break
    return c

def solve(N, As):
    As.sort()
    k = As[-1]
    data = [True for _ in range(k + 1)]
    count = collections.Counter(As)
    if count[1] >= 2:
        return 0

    ans = []
    done = set()
    for a in As:
        if count[a] == 1 and data[a]:
            ans.append(a)
        if a not in done:
            for n in range(a, len(data), a):
                data[n] = False
        if a == 1:
            break
    return len(ans)

#
# def solve(N, As):
#     As.sort()
#     count = collections.Counter(As)
#     past_primes = {}
#     past_primes_keys = {}
#     ans = []
#
#     for a in As:
#         prime = prime_factors(a)
#         success = True
#         if count[a] > 1:
#             success = False
#         if a == 1:
#             ans.append(a)
#             continue
#         if count[1] >= 1:
#             success = False
#
#         for k in prime.keys():
#             if k not in past_primes:
#                continue
#             if past_primes[k] <= prime[k]:
#                 another_check = past_primes_keys[k]
#                 for past_a in another_check:
#                     if a % past_a == 0:
#                         success = False
#                         break
#         # print(prime)
#         if success:
#             # print(a)
#             ans.append(a)
#
#         for k in prime.keys():
#             if k not in past_primes:
#                 past_primes[k] = prime[k]
#             past_primes_keys.setdefault(k, []).append(a)
#     print(ans)
#     return len(ans)

def dummy(N, R=100):
    import random
    return [random.randint(1, R) for _ in range(N)]

def slow_solve(N, As):
    ans = 0
    for i, a in enumerate(As):
        if all(i == j or a % b != 0 for j, b in enumerate(As)):
            ans += 1
    return ans

# for _ in range(10000):
#     for R in [10, 100, 1000]:
#         N = 10
#         d = dummy(N, R)
#         if (solve(N, d) != slow_solve(N, d)):
#             print("Out!!")
#             print(f"N = {N}")
#             print(f"As = {d}")
#             print(f"solve(N, As) = {solve(N, d)}")
#             print(f"slow_solve(N, As) = {slow_solve(N, d)}")
#             break

# assert(solve(5, [24, 11, 8, 3, 16]) == 3)
# assert(solve(3, [36, 36, 72]) == 0)
# assert(solve(10, [33, 18, 45, 28, 8, 19, 89, 86, 2, 4]) == 5)
# assert(solve(5, [9, 9, 70, 76, 81]) == 2)
# assert(solve(5, [1, 9, 27, 35, 48]) == 1)
# assert(solve(5, [17, 18, 24, 48, 71]) == 4)
# assert(solve(10, [16, 27, 30, 36, 36, 41, 41, 70, 72, 91]) == 5)
# assert(solve(5, [2, 3, 5, 7, 11, 1000000]) == 5)

# print("OK")
if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split(" ")))

    print(solve(N, As))


Measured memory_bytes: 44888
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define endl '\n'
#define mod 998244353
#define inf -1000000000000000000
int n,k;

int main() {
	io
	int x;
	cin>>x;
	for(int i = -4000; i<=4000; i++) {
		bool flag = false;
		for(int j = -4000; j<=4000; j++) {
			if(i>=j)
			if((ll)((ll)pow(i, 5) - (ll)(pow(j, 5))) == x) {
				cout<<i<<' '<<j;
				flag = true;
				break;
			}
		}
		if(flag) break;
	}
}


Measured memory_bytes: 4240
#include <stdio.h>

int main(void){
  int a, b;
  char op;

  while(1){
    scanf("%d %c %d", &a, &op, &b);
    switch(op){
    case '+':
      printf("%d\n", a+b);
      break;
    case '-':
      printf("%d\n", a-b);
      break;
    case '*':
      printf("%d\n", a*b);
      break;
    case '/':
      printf("%d\n", a/b);
      break;
    case '?':
      return 0;
    }
  }
}

Measured memory_bytes: 600
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

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

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

const int N=2e5+5;
const int mod=1e9+7;

signed main(){
    FastIO;
    int n,m;
    cin>>n>>m;
    int h[n+5]{0};
    vector<int>v[n+5];
    rep(i,1,n) cin>>h[i];
    rep(i,1,m){
        int a,b;
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }
    int ans=0;
    rep(i,1,n){
        bool ok=1;
        for(int j:v[i]) if(h[i]<=h[j]) ok=0;
//        if(ok) cout<<i<<"::";
        ans+=ok;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 9140
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 要素の入力、格納
		int a = sc.nextInt();
		int b = sc.nextInt();
		String ans = "";

		if(a*b%2==0){
			ans = "Even";
		}else{
			ans = "Odd";
		}

		// 出力
		System.out.println(ans);
	}
}


Measured memory_bytes: 21972
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
using std::cin;
typedef long long ll;
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
const int INF=1e+9;
const ll INFLL=1e+17;
int N,M;
int a[51],b[51],c[51],d[51];
int solve(int i){
  int res,min=INF,aa=a[i],bb=b[i];
  rep(j,M){
    int dist=std::abs(aa-c[j])+std::abs(bb-d[j]);
    if(dist<min){
      min=dist;
      res=j;
    }
  }
  return res+1;
}
int main(){
  cin>>N>>M;
  rep(i,N) cin>>a[i]>>b[i];
  rep(i,M) cin>>c[i]>>d[i];
  rep(i,N) prin(solve(i));
  return 0;
}


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

  int n,m;
  while(1){
    P cnt[101];
    cin>>n>>m;
    if(!n&&!m)break;
    for(int i=0;i<n;i++)
      for(int j=0,a;j<m;j++)cin>>a,cnt[j]=P(cnt[j].first+a,-j-1);
  
    sort(cnt,cnt+m,greater<P>());
    for(int i=0;i<m-1;i++)cout <<-cnt[i].second<<" ";
    cout <<-cnt[m-1].second<<endl;
  }
  return 0;
}

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

int main(){
  
  long N;
  cin >> N;
  vector<int> L(N);
  int a = 0;
  int sum = 0;
  for(int i = 0; i < N; ++i){
  	cin >> L[i];
      a += L[i];
  }
  
  for(int i = 0; i < N; ++i){
    a -= L[i];
    sum += a * L[i];
  }
  
  cout << sum << endl;
  
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		int H = sc.nextInt();
		int W = sc.nextInt();
		int h = sc.nextInt();
		int w = sc.nextInt();

		System.out.println((H - h)*(W - w));
}
}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		double x1 = sc.nextDouble();
		double y1 = sc.nextDouble();
		double x2 = sc.nextDouble();
		double y2 = sc.nextDouble();
		double x = (double) Math.pow(Math.abs(x2-x1), 2);
		double y = (double) Math.pow(Math.abs(y2-y1), 2);
		double dis =  Math.sqrt(x + y);
		System.out.print(dis);
	}
}



Measured memory_bytes: 28120
#include <stdio.h>
#define SIZE 305

 double p[SIZE][SIZE][SIZE], ev[SIZE][SIZE][SIZE];
 int cnt[4];

 int main(void) {
        int n;
        scanf("%d",&n);
        for(int i=1; i<=n; i++) {
                int tmp;
                scanf("%d",&tmp);
                cnt[tmp]++;
        }

        p[cnt[1]][cnt[2]][cnt[3]] = 1.0;

        for(int c=n; c>=0; c--) {
                for(int b=n; b>=0; b--) {
                        for(int a=n; a>=0; a--) {
                                if(!(a+b+c) || a+b+c>n) continue;

                                double waste = (double) (n - (a + b + c)) / n;
                                double waste_ev = waste / (1.0 - waste) + 1.0;
                                ev[a][b][c] += waste_ev * p[a][b][c];

                                if(a>0) {
                                        double go = (double) a / (a + b + c);
                                        p[a - 1][b][c] += p[a][b][c] * go;
                                        ev[a - 1][b][c] += ev[a][b][c] * go;
                                }

                                if(b>0) {
                                        double go = (double) b / (a + b + c);
                                        p[a + 1][b - 1][c] += p[a][b][c] * go;
                                        ev[a + 1][b - 1][c] += ev[a][b][c] * go;
                                }

                                if(c>0) {
                                        double go = (double) c / (a + b + c);
                                        p[a][b + 1][c - 1] += p[a][b][c] * go;
                                        ev[a][b + 1][c - 1] += ev[a][b][c] * go;
                                }
                        }
                }
        }

        printf("%.9lf", ev[0][0][0]);
        return 0;
 }








Measured memory_bytes: 438400
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323846264338327950288
 
int main(){
	double a, b, h, m;
  	cin >> a >> b >> h >> m;
  	double hA = 2*PI * (h+(m/60)) / 12;
  	double mA = 2*PI * m / 60;
  	double angle = min(abs(hA-mA), 2*PI-abs(hA-mA));
  	double ans = sqrt(a*a + b*b - 2*a*b*cos(angle));
  	printf("%.10f",ans);
}

Measured memory_bytes: 4248
#include <iostream> // cout, endl, cin
#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> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
#define int long long



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

    int x,y,a,b,c; cin >> x >> y >> a >> b >> c;

    vector<int> p(a),q(b),r(c);
    for(int i = 0;i < a;i ++) cin >> p.at(i);
    for(int i = 0;i < b;i ++) cin >> q.at(i);
    for(int i = 0;i < c;i ++) cin >> r.at(i);

    sort(p.begin(),p.end(),greater<int>());
    sort(q.begin(),q.end(),greater<int>());
    sort(r.begin(),r.end(),greater<int>());
    

    vector<int> all(x+y);
    for(int i = 0;i < x;i ++){
        all.at(i) = p.at(i);
    }
    for(int i = 0;i < y;i ++){
        all.at(i+x) = q.at(i);
    }

    sort(all.begin(),all.end());

    for(int i = 0;i < c;i ++){

        if(i >= x+y)break;

        if(all.at(i) < r.at(i)) all.at(i) = r.at(i);
    }

    int ans = 0;
    for(int i = 0;i < x+y;i ++) ans += all.at(i);

    cout << ans << endl;
}


Measured memory_bytes: 3968
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_064_A.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 INP    PIC X(5).
    01 r      PIC 9(3).
    01 g      PIC 9(2).
    01 b      PIC 9(1).
    01 num    PIC 9(3) VALUE 0.
PROCEDURE                        DIVISION.
MAIN.
    ACCEPT INP.

    UNSTRING INP
    DELIMITED BY SPACE
    INTO r g b.

    MULTIPLY 100 BY r.
    MULTIPLY 10 BY g.

    ADD r g TO b GIVING num.

    IF FUNCTION MOD(num, 4) = 0 THEN
        DISPLAY "YES"
    ELSE
        DISPLAY "NO"
    END-IF.

    STOP RUN.


Measured memory_bytes: 636
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;

ll n,q;
vvll v(200010);
vll cnt(200010,0);

void dfs(ll now, ll next){

    for(auto p:v[now]){
        if(p != next){
            cnt[p] += cnt[now];
            dfs(p,now);
        }
    }
}

int main(){FIN

    cin>>n>>q;

    REP(i,n-1){
        ll a,b;
        cin>>a>>b;
        a--; b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }

    REP(i,q){
        ll p,x;cin>>p>>x;
        p--;
        cnt[p] += x;
    }
    dfs(0,-1);
    
    REP(i,n) cout<<cnt[i]<<endl;
    return 0;
}

Measured memory_bytes: 24320
#include <cstdio>
#include <vector>

using namespace std;

int main() {
    size_t n;
    scanf("%zu", &n);

    vector<int> a(n);
    for (size_t i=0; i<n; ++i)
        scanf("%d", &a[i]);

    for (size_t i=n; i--;)
        printf("%d%c", a[i], i? ' ':'\n');

    return 0;
}

Measured memory_bytes: 2684
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE Unsafe #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE FlexibleContexts #-}

import Data.Bits
import Data.List
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as BSL
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IMS
import Data.IntSet (IntSet)
import qualified Data.IntSet as IS
import qualified Data.Sequence as Seq
import Data.Sequence (Seq)
import qualified Data.Array.IArray as A
import qualified Data.Array.MArray.Safe as A
import qualified Data.Array.MArray as A
import Data.Array (Array)
import Data.Array.Unboxed (UArray)
import Data.Array.IArray (IArray)
import Data.Array.MArray.Safe (MArray)
import Data.Array.IO.Safe (IOArray, IOUArray)
import Data.Array.ST.Safe (STArray, STUArray, runSTArray, runSTUArray)
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
import Control.Monad.ST
-- import Control.Monad.ST.Safe
import Control.Applicative
import Data.Maybe
import Data.Tuple
import Data.Ord
import Control.Monad.State.Strict
import Data.Int
import System.IO
import Data.Function
import Control.Monad.Primitive
import qualified Data.Vector.Primitive.Mutable as VPM
import qualified Data.Vector.Generic.Mutable as VGM
import Data.STRef

main :: IO ()
main = do
  n <- read <$> getLine
  hs <- VU.unfoldrN n (BS.readInt . BS.dropWhile (<'!')) <$> BS.getLine
  print $ query hs

query :: VU.Vector Int -> Int
query vec = loop 2 (abs $ vec VU.! 0 - vec VU.! 1) 0
  where
  -- The flog is at k
    loop !k !cost_km1 !cost_km2
      | k >= VU.length vec = cost_km1
      | otherwise =
        loop (k+1) (min (cost_km1 + abs (vec VU.! k - vec VU.! (k-1)))
                        (cost_km2 + abs (vec VU.! k - vec VU.! (k-2))))
                   cost_km1


Measured memory_bytes: 2684
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String input = sc.nextLine();
    
    if(input.equals("ABC")){
      System.out.println("ARC");
    } else {
      System.out.println("ABC");
    }
  }
}

Measured memory_bytes: 35692
void solve();

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

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
using namespace std;

int N, Q;
vector<vector<int>> Edges;
vector<int> in;
vector<int> sum;
vector<bool> check;
queue<pair<int, int>> que;

void solve() {
	cin >> N >> Q;
	Edges.resize(N);
	for (int n = 1; n <= N - 1; n++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		Edges[a].push_back(b);
		Edges[b].push_back(a);
	}
	in.resize(N,0);
	for (int q = 0; q < Q; q++) {
		int p, x;
		cin >> p >> x;
		p--;
		in[p] += x;
	}
	sum.resize(N,0);
	check.resize(N, false);
	que.push(pair<int, int>(0, 0));
	while (!que.empty()) {
		int cur = que.front().first;
		int s = que.front().second;
		que.pop();
		sum[cur] += (s+in[cur]);
		check[cur] = true;
		for (auto itr = Edges[cur].begin(); itr != Edges[cur].end(); itr++) {
			if (check[*itr])continue;
			que.push(pair<int, int>(*itr, sum[cur]));
		}
	}
	for (int n = 0; n < N; n++)cout << sum[n] << " ";
	return;
}

Measured memory_bytes: 17140
#include<bits/stdc++.h>
using namespace std;
vector<int> vt;
int n;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	int k;
	for(int i=0;i<n;i++)
	{
		//int k;
		cin>>k;
		vt.push_back(k);
	}
	int c=1;
	for(int i=0;i<n;i++)
	{
		if(vt[i]==c)
		{
			c++;
		}
	}
	if(c==1)
	{
		cout<<-1<<endl;
	}
	else
	cout<<n-c+1<<endl;
	return 0;
}

Measured memory_bytes: 1400
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        String s = scanner.next();

        int count = 0;
        int current = 0;

        int[] mod = new int[2020];
        mod[2019]++;
        mod[0]++;

        int rem = 1;

        for (int i = s.length()-1; i >=0; i--) {

            int a = s.charAt(i) - '0';
            rem *= 10;
            rem %= 2019;

            current = (a*rem + current ) % 2019;

            count+=mod[current];

            mod[current ]++;
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 40392
using System;

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var n = int.Parse(line[0]);
            var m = int.Parse(line[1]);
            if (n == 0 && m == 0) break;
            var a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = int.Parse(Console.ReadLine().Trim());
            var p = 0;
            var putans = false;
            for (int i = 1; i <= m; i++)
            {
                var t = int.Parse(Console.ReadLine().Trim());
                if (putans) continue;
                if (p + t >= n - 1 || (p + t < n - 1 && a[p + t] + p + t >= n - 1)) { Console.WriteLine(i); putans = true; continue; }
                p = a[p + t] + p + t;
            }
        }
    }
}




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

int main(){
    string s;
    cin >> s;
    if(s == "Sunny") cout << "Cloudy" << endl;
    else if(s == "Cloudy") cout << "Rainy" << endl;
    else cout << "Sunny" << endl;
}



Measured memory_bytes: 256