akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S):
    p = S.count('p')
    return len(S)//2 - p


def main():
    S = read_str()
    print(slv(''.join(S)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 6472
n = int(input())
l = []
for i in range(n):
    a,b = input().split()
    b = int(b)
    l.append([a, b])
s = input()

res = 0
flag = False
for a, b in l:
    if flag:
        res += b
    else:
        if a == s:
            flag = True
print(res)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int n,m,k,num,ans[305][305];
char c[305][305];
int cnt[305];
vector<int>v;
void solve(int a,int b)
{
	vector<int>t;
	for(int i=a;i<=b;i++)
		for(int j=1;j<=m;j++)
			if(c[i][j]=='#')
				t.push_back(j);
	sort(t.begin(),t.end());
	for(int i=0;i<t.size();i++)
	{
		int t1=1,t2=m;
		if(i>=1)
			t1=t[i-1]+1;
		if(i<(int)t.size()-1)
			t2=t[i];
		num++;
		for(int j=a;j<=b;j++)
			for(int k=t1;k<=t2;k++)
				ans[j][k]=num;
	}
}
int main()
{
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			cin>>c[i][j];
			if(c[i][j]=='#')
				cnt[i]++;
		}
	for(int i=1;i<=n;i++)
		if(cnt[i]>=1)
			v.push_back(i);
	for(int i=0;i<v.size();i++)
	{
		int v1=1,v2=n;
		if(i>=1)
			v1=v[i-1]+1;
		if(i<(int)v.size()-1)
			v2=v[i];
		solve(v1,v2);
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
			cout<<ans[i][j]<<' ';
		puts("");
	}
	return 0;
}


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

int a[200001];
int main(){
  long long v,N,i,p,po,n;
  cin >> N;
  
  po = 300;
  v = 1000;
  for(i=0;i<N;i++){
    cin >> p;
    if (p > po)
      v += (p - po) * (v / po);
    po = p;
  }
  
  cout << v << endl;
  
  return 0;
  
}

Measured memory_bytes: 3564
#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 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 VIN(v) for(auto&elem_: (v) )cin>>elem_
#define VOUT(v, sep) for(_loop_int idx=0; idx<(_loop_int)v.size(); idx++) {cout<<v[idx]; if(idx<v.size()-1) cout<<sep;} cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(debugidx,v.size())cout<<" "<<v[debugidx];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(debugidx,n)cout<<" "<<v[debugidx];cout<<endl

const ll MOD = 1000000007ll;
const int IINF = numeric_limits<int>::max()/2-1;
const ll LINF = numeric_limits<ll>::max()/2-1;

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



int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int w1, w2, s1, s2, melt, limit;
    //100gあたりmeltグラム溶けます。ビーカーには水+砂糖でlimitグラムまで入ります。
    //w1<w2
    //s1<s2
    cin>>w1>>w2>>s1>>s2>>melt>>limit;

    vi w;

    for(int i=0; i<=limit; i+=w2*100){
        w.emplace_back(i);
        for(int j=i+w1*100; j<=limit; j+=w1*100){
            w.emplace_back(j);
        }
    }

    sort(ALL(w));
    w.erase(unique(ALL(w)), w.end());
    w.erase(w.begin());//0を消す

    double mx = -5.f;
    pii ans = pii(0,0);
    REP(i,w.size()){
        double per = 0;
        int s = 0;
        //int slimit = limit-w[i];
        int slimit = (w[i]/100)*melt;
        //DEBUG(slimit);
        vector<bool> dp(slimit+1, false);
        //dp[0] = true;
        for(int j=0; j<=slimit; j+=s2){
            dp[j] = true;
            for(int k=j+s1; k<=slimit; k+=s1){
                dp[k] = true;
            }
        }

        //DEBUG_VEC(dp);

        FORR(j, 0, slimit+1){
            if(dp[j]){
                double pertmp = (100.f*j) / ((double)w[i]+j);
                if(w[i]+j <= limit ){
                    if(chmax(mx,pertmp)){
                        ans.first = w[i];
                        ans.second = j;
                    }
                }
            }
        }
    }

    cout << ans.first+ans.second << " " << ans.second << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef vector<int> vec;
int main(){
  int n;cin>>n;
  string ans="Yes";
  vec v(n);
  rep(i,n) cin>>v[i];
  reverse(v.begin(), v.end());
  
  rep(i,n-1){
    if(v[i+1]-v[i]>1){ans="No";break;}
    else v[i+1]=min(v[i],v[i+1]);
  }
  cout<<ans;
}

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

int main() {
  ll n;
  string s;
  cin >> n >> s;
  ll red=0,white=0;
  
  for(ll i=0;i<n;i++){
    if(s[i] == 'R') red++;
  }
  
  ll ans=red;
  for(ll i=0;i<n;i++){
    if(s[i] == 'R'){
      red--;
    }else{
      white++;
    }
    ll now=max(red,white);
    ans = min(ans,now);
  }
  
  cout << ans << endl;
  
  return(0);
}

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

typedef long long ll;
typedef pair <ll, ll> pii;

const ll MAX_N = 2e5 + 10, MOD = 1e9 + 7;
ll n, k, res;
ll r, s, p;
string t, ans;
ll dp[MAX_N][3];
char ch[3] = {'r', 'p', 's'};

bool win(char a, char b) {
    if (a == 'r' && b == 's')
        return true;
    if (a == 'p' && b == 'r')
        return true;
    if (a == 's' && b == 'p')
        return true;
    return false;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> n >> k >> r >> s >> p >> t;

    for (int i = 0; i < n; i++)
        for (int j = 0; j < 3; j++)
            if (win(ch[j], t[i]))
                ans += ch[j];

    for (int i = 0; i + k < n; i++)
        if (ans[i] == ans[i + k]) {
            for (int j = 0; j < 3; j++)
                if (ch[j] != ans[i] && (i + k + k >= n || ch[j] != ans[i + k + k])) 
                    ans[i + k] = ch[j];
        }

    for (int i = 0; i < n; i++)
        if (win(ans[i], t[i])) {
            if (ans[i] == 'r')
                res += r;
            if (ans[i] == 'p')
                res += p;
            if (ans[i] == 's')
                res += s;
        }
    cout << res;
    return 0;
}

Measured memory_bytes: 640
list1 = input()
list2 = list1.split()
a = int(list2[0])
b = int(list2[1])
c = int(list2[2])
d = int(list2[3])

#x = [i for i in range(a,b+1)]
#y = [j for j in range(c,d+1)]

x_min = a
x_max = b
y_min = c
y_max = d

answer_list = [x_max*y_max, x_max*y_min, x_min*y_max, x_min*y_min]

print(max(answer_list))

Measured memory_bytes: 9172
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define P (3)

int b64(char ch) {
    if('A'<=ch && ch<='Z') return ch-'A';
    if('a'<=ch && ch<='z') return ch-'a'+26;
    if('0'<=ch && ch<='9') return ch-'0'+52;
    return ch=='+' ? 62 : 63;
}

int w, h, p, f[1024][1024], m[128][128], tmp[128][128];
char tf[1000][200], tm[100][20];
typedef unsigned long long hash;
hash hori[1024][1024], hs[8];

int main() {
    for(;;) {
        scanf("%d%d%d", &w, &h, &p);
        if(w==0 && h==0 && p==0) return 0;
        rep(i, h) scanf(" %s", tf[i]);
        rep(i, p) scanf(" %s", tm[i]);
        memset(f, 0, sizeof(f));
        rep(i, h) for(int j=0; tf[i][j]; j++) {
            const int x = b64(tf[i][j]);
            rep(k, 6) if(x&(1<<k)) f[i][j*6+5-k] = 1;
        }
        memset(m, 0, sizeof(m));
        rep(i, p) for(int j=0; tm[i][j]; j++) {
            const int x = b64(tm[i][j]);
            rep(k, 6) if(x&(1<<k)) m[i][j*6+5-k] = 1;
        }
        vector<hash> hs;
        rep(d, 8) {
            memcpy(tmp, m, sizeof(m));
            rep(i, p) rep(j, p) m[p-1-j][i] = tmp[i][j];
            if(d==4) {
                memcpy(tmp, m, sizeof(m));
                rep(i, p) rep(j, p) m[i][p-1-j] = tmp[i][j];
            }
            hash k = 0;
            rep(i, p) rep(j, p) k = k*P+m[i][j];
            hs.push_back(k);
        }
        sort(hs.begin(), hs.end());
        hs.erase(unique(hs.begin(), hs.end()), hs.end());
        hash t = 1;
        rep(i, p) t *= P;
        rep(i, h) {
            hash k = 0;
            rep(j, w) {
                k = k*P+f[i][j];
                if(j>=p) k -= t*f[i][j-p];
                hori[i][j] = k;
            }
        }
        hash tt = 1;
        rep(i, p) tt *= t;
        int ans = 0;
        for(int i=p-1; i<w; i++) {
            hash k = 0;
            rep(j, h) {
                k = k*t+hori[j][i];
                if(j>=p) k -= tt*hori[j-p][i];
                if(j>=p-1) rep(z, hs.size()) if(hs[z]==k) { ans++; break; }
            }
        }
        printf("%d\n", ans);
    }
}

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

string str;
int s, n, e, w;

int main(){
	cin >> str;
	for(int i = 0; i < str.size(); i++){
		if(str[i] == 'S') s = true;
		if(str[i] == 'N') n = true;
		if(str[i] == 'E') e = true;
		if(str[i] == 'W') w = true;
	}
	if(!(s ^ n) && !(e ^ w)) return 0*puts("Yes");
	return 0*puts("No");
}

Measured memory_bytes: 256
#include <iostream>
#include <boost/multiprecision/cpp_int.hpp>

signed main(){
  boost::multiprecision::cpp_int n;
  
  std::cin >> n;
  std::cout << (n % 9 == 0 ? "Yes\n" : "No\n") << std::endl;
  
  return (0);
}

Measured memory_bytes: 3740
#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, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i, n) cin >> h[i];

  sort(h.begin(), h.end());
  ll c = 0;
  if (n <= k) {
    cout << 0 << endl;
  } else {
    rep(i, n - k) c += h[i];
    cout << c << endl;
  }
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int b[100001];

int main()
{
    int i,j,n,max=0,c;
    scanf("%d",&n);
    int a[n];
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
        if(a[i] != 0)
        {
            ++b[a[i]-1];
            ++b[a[i]];
            ++b[a[i]+1];
        }
        else
        {
            ++b[a[i]];
            ++b[a[i]+1];
        }
        if( b[a[i]] > max )
        {
            max=b[a[i]];
        }
        if( b[a[i]+1] > max )
        {
            max=b[a[i]+1];
        }
        if( b[a[i]-1] > max && a[i] != 0 )
        {
            max=b[a[i]-1];
        }
    }
    printf("%d",max);
    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long LL;
int main(int argc, char* argv[])
{
	int N,K,i;
	cin>>N>>K;
	vector<LL> h(N);
	LL MinH=0;
	for (i=0;i<N;i++){
		cin>>h[i];
		if (MinH<h[i]){
			MinH=h[i];
		}
	}
	sort(h.begin(),h.end());
	
	for (i=0;i<h.size()-K+1;i++){
		if (MinH>h[K-1+i]-h[i]){
			MinH=h[K-1+i]-h[i];
		}
	}
	cout<<MinH<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
// void assign_str(char limited[], char str[], int n)
// {
//     for (int i = 0; i < n; i++)
//     {
//         limited[i] = str[i];
//     }
//     limited[n] = '\0';
// }
bool is_same(char s[], char p[]) //二つの文字列が同じ文字列かどうかを判別する関数
{
    int len_p = strlen(p);
    if (strncmp(s, p,len_p)) //同でなければ非０(-1か1)を返す
    {
        return false;
    }
    return true;
}
void double_string(char str[])
{
    char tmp[201];

    strcpy(tmp, str); //tmpにstrをコピー
    strcat(str, tmp); //strの後ろにtmpをつなげる
}
int main(void)
{
    char s[201];
    char p[101];

    scanf("%s", s); //輪になっている文字列
    scanf("%s", p); //探す文字列

    int len_s = strlen(s); //文字列sの文字数
    int len_p = strlen(p); //文字列pの文字数
    double_string(s);      //入力した文字列 s を2倍の長さにする（輪になってるので先頭と末尾をまたぐ場合も考えられるので）
    char limited_s[101];   //文字列sから、文字列pと同じ長さ分の文字列を取り出して、代入するために用意したもの

    int i = 0;
    while (1)
    {
        strncpy(limited_s, s + i, len_p);
         //文字列sから、文字列pと同じ長さ分の文字列を取り出す。取り出す開始地点は１ずつずれていく。
        if (is_same(limited_s, p))           //文字列limited_sと文字列pが同じ文字列の時
        {
            printf("Yes\n");
            break;
        }
        else if (i == len_s + 1) //limited_sの開始地点が文字列ｓの文字数を超えた時(i = 0の時とやってることが同じになった時)
        {
            printf("No\n");
            break;
        }
        i++;
    }

    return 0;
}
//もう少し分かりやすいプログラムにならないか。。。


Measured memory_bytes: 2116
month,day = map(int,input().split())

if day < 22:
  print(0)
else:
  s = 0
  for j in range(month+1):
    for i in range(22,day+1):
      num_1 = i%10
      num_2 = (i-num_1)/10
      if  num_1< 2:
        continue
      elif num_1 * num_2 == j:
        s += 1
  print(s)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int mod = 1000000007;
struct mint
{
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint &operator+=(const mint a)
    {
        if ((x += a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator-=(const mint a)
    {
        if ((x += mod - a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator*=(const mint a)
    {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const
    {
        if (!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint &operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

struct Sieve
{
    int n;
    vector<int> f, primes;
    Sieve(int n = 1) : n(n), f(n + 1)
    {
        f[0] = f[1] = -1;
        for (ll i = 2; i <= n; ++i)
        {
            if (f[i])
                continue;
            primes.push_back(i);
            f[i] = i;
            for (ll j = i * i; j <= n; j += i)
            {
                if (!f[j])
                    f[j] = i;
            }
        }
    }
    bool isPrime(int x) { return f[x] == x; }
    vector<int> factorList(int x)
    {
        vector<int> res;
        while (x != 1)
        {
            res.push_back(f[x]);
            x /= f[x];
        }
        return res;
    }
    vector<P> factor(int x)
    {
        vector<int> fl = factorList(x);
        if (fl.size() == 0)
            return {};
        vector<P> res(1, P(fl[0], 0));
        for (int p : fl)
        {
            if (res.back().first == p)
            {
                res.back().second++;
            }
            else
            {
                res.emplace_back(p, 1);
            }
        }
        return res;
    }
};

int main()
{
    long long N;
    cin >> N;
    vector<ll> A(N);
    map<int, int> lcm;
    Sieve sieve(1000000);
    rep(i, N)
    {
        cin >> A[i];
        vector<P> vp = sieve.factor(A[i]);
        for (P p : vp)
            lcm[p.first] = max(lcm[p.first], p.second);
    }

    mint lcm_num = 1;
    for (P p : lcm)
        lcm_num *= pow(p.first, p.second);
    mint ans = 0;
    rep(i, N)
    {
        ans += lcm_num / A[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4984
/**************erik****************/
#include<bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long  int ll;
typedef unsigned long long int ull;
//map<ll,ll> mp1;
//set<int> s1;
//set<int>::iterator it;
#define maxm(a,b,c)  max(a,max(c,b))
#define minm(a,b,c)  min(a,min(c,b))
#define f(i,n)  for(ll i=0;i<n;i++)
#define rf(i,n) for(ll i=n-1;i>=0;i--)

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
    int n,m;
    cin>>n>>m;
    int h[n];
    f(i,n)cin>>h[i];
    vector<int> vec[n+2];
    set<pair<int,int>> ss;
    f(i,m){
        int a,b;
        cin>>a>>b;
        a-=1;
        b-=1;
        if(ss.find({min(a,b),max(a,b)})!=ss.end())continue;
        ss.insert({min(a,b),max(a,b)});
        vec[a].push_back(b);
        vec[b].push_back(a);
    }
    int ct=0;
    f(i,n){
        if(vec[i].size()==0)ct++;
        else {
            bool f = true;
            for(int j=0;j<vec[i].size();j++){
                if(h[i]<=h[vec[i][j]]){f=false;break;}
            }
            if(f){ct++;}
        }
    }
    cout<<ct<<endl;

}

Measured memory_bytes: 13784
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<tuple>
#include<string>
typedef unsigned long long ll;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define repm(i,a,b) for(int i=(a);i>(b);i--)
#define F first
#define S second
using namespace std;
const ll INF = 1e12;
const int i_INF = 2147483647;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
  int k;
  cin>>k;
  if(k%2==0){
    cout<<k*k/4<<endl;
  }else{
    cout<<(k/2)*(k/2+1)<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = 1234567;

ll mpow(ll a, ll b){
	if(b==0) return 1;
	else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
	else return mpow(a,b-1) * a % MOD;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
	if(kaijo_memo.size() > n) return kaijo_memo[n];
	if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
	while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
	return kaijo_memo[n];
}
ll nCr(ll n, ll r){
	if(n < r || r < 0) return 0;
	ll ret = 1;
	ret *= kaijo(n); ret %= MOD;
	ret *= mpow(kaijo(r), MOD-2); ret %= MOD;
	ret *= mpow(kaijo(n-r), MOD-2); ret %= MOD;
	return ret;
}

vector<int> G[N];
ll counter[N];
bool check[N];
ll ans[N];

void saiki(int now, int x){
	if(check[now]) return;
	check[now] = true;
	ans[now] = counter[now] + x;
	rep(i, G[now].size()){
		int next = G[now][i];
		saiki(next, ans[now]);
	}
}

int main(void){
	int n,q;
	cin>>n>>q;
	int a,b,p,x;
	rep(i,n-1){
		cin>>a>>b;a--;b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	rep(i,n){
		counter[i] = 0;
		check[i] = false;
		ans[i] = 0;
	}
	rep(i,q){
		cin>>p>>x;p--;
		counter[p] += x;
	}
	saiki(0, 0);

	rep(i,n){
		cout<<ans[i];
		if(i != n-1){
			cout<<" ";
		}
	}
	cout<<endl;

	return 0;
}


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int l, k;
	cin >> l >> k;
	ll ans = 0;
	vl dp(l + 1, 0);
	dp[1] = 1;
	if(k<=l)dp[k] = 1;
	REP(i, l-1) {
		dp[i + 2] += dp[i];
		if (i + 1 + k <= l)dp[i + 1 + k] += dp[i];
	}

	REP(i, l + 1)ans += dp[i];
	cout << ans << endl;
}

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

int main(){
    int n;
    string s1, s2;
    int a=0,b=0;
    cin >> n;
    
    for(int i=0;i<n;i++){
        cin >>s1 >>s2;
        if(s1>s2)a+=3;
        else if(s1<s2)b+=3;
        else{
            a++,b++;
        }
    }
    cout<<a<<" "<<b<<endl;
    
    return 0;
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<ll>())

#define vfind(v, target) find(v.begin(), v.end(), target)
#define notFound(v, target) (vfind(v, target) == v.end())

#define ll long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define MOD 1000000007
using namespace std;

int main()
{
  ll N, K, h, ans = 0; cin >> N >> K;
  rep(i, 0, N) {
  	cin >> h;
    if (h >= K) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <regex>
#ifdef _DEBUG
#include "debug.h"
#endif
#define int ll
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define all(v) (v).begin(),(v).end()
#define mkpr make_pair
#define mktp make_tuple
#define tv(tp, i) get<(i)>(tp)
#define CLEAR(obj) obj = decltype(obj)()
#define var auto
#define OUT(type) type &
#define IN(type) const type &
#define self (*this)
#define in :
#define True true
#define False false
using namespace std; using int32 = int32_t; using str = string; using cstr = const str;
using ll = long long; using ull = unsigned long long; using cint = const int; using cll = const ll;
using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>;
using vb = vector<bool>; using vvb = vector<vb>; using vd = vector<double>; using vvd = vector<vd>;
using vc = vector<char>; using vvc = vector<vc>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<double, double>; using psl = pair<string, ll>;
using tiii = tuple<int, int, int>; using tlll = tuple<ll, ll, ll>;
static const int MGN = 10; static const int ARYSZ_MAX = (int)1e7;
static const ll LINF = LLONG_MAX/2;
#ifdef int
static const int INF = LINF;
#else
static const int INF = INT_MAX/2;
#endif
static double EPS = 1e-9;
#define FASTCIN() cin.tie(0);ios::sync_with_stdio(false);
#ifdef IMPORT_SAMPLE
#define DEBUG_IMPORT(file) vs args(argv, argv+argc);str sample = make_sample(args, file);ifstream ifs(sample); cin.rdbuf(ifs.rdbuf());
#else
#define DEBUG_IMPORT(file)
#endif
static inline bool DBLEQ(double a, double b) {return abs(a - b) < EPS;}
static inline void EPR(str msg) {cerr << msg << endl;}
static inline void AST(bool exp, str msg) {if(!exp){EPR(msg);} assert(exp);}
static inline void TAST(bool exp, str msg) {if(!exp){EPR(msg);} while(!exp){}}


int32 main(int32 argc, char* argv[]) {
    FASTCIN();
    DEBUG_IMPORT("sample-1");


    int R; cin>>R;

    double ans = 2*R*M_PI;
    printf("%24.20f\n", ans);


    return 0;
}


Measured memory_bytes: 3784
n = int(input())
s = input()
r_num = s.count('R')
g_num = s.count('G')
b_num = s.count('B')
tot = r_num*g_num*b_num
for i in range(n):
    for j in range(i+1,n):
        k = j+(j-i)

        if k<n:
            if s[i]!=s[j] and s[i]!=s[k] and s[j] != s[k]:
                tot -= 1

print(tot)


Measured memory_bytes: 9184
n = int(input())
list_A = list(map(int, input().split()))
d = {}
for i in range(1, pow(10, 6)):
    d[i] = 0

ans = sum(list_A)
for i in list_A:
    d[i] += 1

m = int(input())
list_ANS = []
list_AB = []

for _ in range(m):
    a, b = map(int, input().split())
    list_AB.append([a, b])

for a, b in list_AB:
    ans += (b-a)*d[a]
    list_ANS.append(ans)
    d[b] += d[a]
    d[a] = 0


for i in range(m):
    print(list_ANS[i])


Measured memory_bytes: 105944
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
const int SIZEN = 10000010;
int main(){
    int K;
    scanf("%d",&K);
    int now = 0;
    for(int i = 1;i <= 10000000;i++){
        now = now * 10 + 7;
        now %= K;
        if(now == 0){printf("%d\n",i);return 0;}
    }
    printf("-1\n");
    return 0;
}

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

#define MAX 5002

int n;

vector<int> v[MAX];

int dp[MAX];
int p[MAX];
int mx[MAX];

inline void dfs(int b, int pr = -1) {
	p[b] = pr;
	dp[b] = 0;
	dp[b] = 1;
	mx[b] = 1;
	for (int go : v[b]) {
		if (go == pr)continue;
		dfs(go, b);
		dp[b] += dp[go];
		mx[b] = max(mx[b], dp[go]);
	}
	mx[b] = max(mx[b], n - dp[b]);
}
#define MOD 1000000007
vector<int> vv;

long long int d[MAX][MAX];

long long int c[MAX][MAX];
long long int k[MAX];

long long int W[MAX];

long long int ppow(long long int i, long long int j) {
	long long int r = 1;
	while (j) {
		if(j&1LL)r *= i;
		if (r >= MOD)r %= MOD;
		i *= i;
		i %= MOD;
		j >>= 1LL;
	}
	return r;
}
long long int inv[MAX];
long long int P(int a, int b) {
	long long int u = k[a];
	u *= inv[a - b];
	if (u >= MOD)u %= MOD;
	return u;
}
int main() {
	k[0] = 1;
	inv[0] = 1;
	for (int i = 1; i < MAX; i++) {
		k[i] = k[i - 1];
		k[i] *= i;
		if (k[i] >= MOD)k[i] %= MOD;
		inv[i] = ppow(k[i], MOD - 2);
	}
	c[0][0] = 1;
	for (int i = 0; i + 1 < MAX; i++) {
		for (int j = 0; j <= i; j++) {
			c[i + 1][j] += c[i][j];
			c[i + 1][j + 1] += c[i][j];
			if (c[i + 1][j] >= MOD)c[i + 1][j] %= MOD;
			if (c[i + 1][j + 1] >= MOD)c[i + 1][j + 1] %= MOD;
		}
	}
	cin >> n;
	for (int i = 1; i < n; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		a--;
		b--;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	dfs(0);
	bool flag = false;
	for (int i = 0; i < n; i++) {
		if (mx[i]*2<=n) {
			flag = true;
		}
	}
	if (flag==false) {
		long long int m = n / 2;
		long long int ans = 1;
		for (int i = 1; i <= m; i++) {
			ans *= i;
			if (ans >= MOD)ans %= MOD;
		}
		ans *= ans;
		ans %= MOD;
		ans = MOD - ans;
		ans += k[n];
		ans %= MOD;
		printf("%lld\n", ans);
	//	return 0;
	}
	int r = -1;
	for (int i = 0; i < n; i++) {
		if (mx[i] * 2 <= n) {
			r = i;
		}
	}
	for (int go : v[r]) {
		if (go != p[r]) {
			vv.push_back(dp[go]);
		}
	}
	if (p[r] != -1) {
		vv.push_back(n - dp[r]);
	}
	sort(vv.begin(), vv.end());
	d[0][0] = 1;
	for (int i = 0; i < vv.size(); i++) {
		for (int j = 0; j <= n; j++) {
			if (d[i][j] == 0)continue;
			for (int k = 0; k <= vv[i]; k++) {
				long long int U = d[i][j] * c[vv[i]][k];
				if (U >= MOD)U %= MOD;
				U *= P(vv[i], k);
				if (U >= MOD)U %= MOD;
				d[i + 1][j + k] += U;
				if (d[i + 1][j + k] >= MOD)d[i + 1][j + k] %= MOD;
			}
		}
	}
	long long int way = k[n];
	for (int j = 1; j <= n; j++) {
		long long int B = d[vv.size()][j];
		B *= k[n - j];
		B %= MOD;
		if (j % 2) {
			B = MOD - B;
		}
		way += B;
		way %= MOD;
	}
	printf("%lld\n", way);
	return 0;
	W[n-1] = 1;
	for (int i = n - 2; i >= 1; i--) {
		long long int tmp = d[vv.size()][i]*k[n-i];
		for (int j = i + 1; j <= n; j++) {
			long long int tmpp = W[j] * c[j][i];
			tmpp %= MOD;
			tmpp = MOD - tmpp;
			tmp += tmpp;
			tmp %= MOD;
		}
		W[i] = tmp;
	}
	long long int sum = 0;
	for (int i = 0; i <= n; i++) {
		sum += W[i];
		sum %= MOD;
	}
	sum = MOD - sum;
	sum += k[n];
	sum %= MOD;
	printf("%lld\n", sum);
	return 0;
}

Measured memory_bytes: 390016
#include <algorithm>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long int lli;
typedef pair<lli, lli> P;
lli MOD = 1000000007;
int main()
{
    lli n;
    cin >> n;
    lli a[105];
    rep(i, n) cin >> a[i];
    sort(a, a + n);
    reverse(a, a + n);
    if (n == 2) {
        if (a[0] == 1 && a[1] == 1) {
            cout << "Possible" << endl;
        } else {
            cout << "Impossible" << endl;
        }
        return 0;
    }
    map<lli, lli> m;
    if (a[0] % 2 == 0) {
        m[a[0] / 2]++;
        rep(i, a[0] / 2)
        {
            rep(j, 2)
            {
                m[i + a[0] / 2 + 1]++;
            }
        }
        rep(i, n)
        {
            m[a[i]]--;
        }
        for (auto s : m) {
            if (s.second > 0) {
                cout << "Impossible" << endl;
                return 0;
            } else if (s.second < 0) {
                if (s.first < a[0] / 2 + 1) {
                    cout << "Impossible" << endl;
                    return 0;
                }
            }
        }
    }
    if (a[0] % 2 == 1) {
        rep(i, a[0] / 2)
        {
            rep(j, 2)
            {
                m[i + a[0] / 2 + 1]++;
            }
        }
        rep(i, n)
        {
            m[a[i]]--;
        }
        for (auto s : m) {
            if (s.second > 0) {
                cout << "Impossible" << endl;
                return 0;
            } else if (s.second < 0) {
                if (s.first < a[0] / 2 + 2) {
                    cout << "Impossible" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Possible" << endl;
}


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

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str):
    def pe(string): return string.find(string[::-1])
    if pe(S)==-1:
        print(NO)
    else:
        o=S[:int(((len(S)-1)/2))]
        if pe(o)==-1:
            print(NO)
        else:
            u=S[int((len(S)+3)/2)-1:len(S)]
            if pe(u)==-1:
                print(NO)
            else:
                print(YES)
    return


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N  = sc.nextInt();
		int[] a = new int[N];
		for(int i=0;i<N;i++) {
			a[i] = sc.nextInt();
		}
		
		sc.close();
	
		int ans = Integer.MAX_VALUE;
		for(int y=-100;y<=100;y++) {
			int c = y;
			int b = Arrays.stream(a).map(x-> (x-c)*(x-c)).sum();
			ans = Math.min(ans, b);
		}
		
		out.println(ans);

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

}


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

const int MAX_N = 1 << 18;
static long long N, K, ANS, P[200000], MINDAT[2 * MAX_N - 1], MAXDAT[2 * MAX_N - 1], INF = 1000000000;

void init(int N_) {
	N = 1;
	while (N < N_) N *= 2;
	for (int i = 0; i < 2 * N - 1; i++) MINDAT[i] = INF, MAXDAT[i] = -INF;
}

void MinUpdate(int K, int A) {
	K += N - 1;
	MINDAT[K] = A;
	while (K > 0) {
		K = (K - 1) / 2;
		MINDAT[K] = min(MINDAT[K * 2 + 1], MINDAT[K * 2 + 2]);
	}
}

void MaxUpdate(int K, int A) {
	K += N - 1;
	MAXDAT[K] = A;
	while (K > 0) {
		K = (K - 1) / 2;
		MAXDAT[K] = max(MAXDAT[K * 2 + 1], MAXDAT[K * 2 + 2]);
	}
}

long long MINQuery(int A, int B, int K, int L, int R) {
	if (R <= A || B <= L) return INF;
	if (A <= L && R <= B) return MINDAT[K];
	long long VL = MINQuery(A, B, K * 2 + 1, L, (L + R) / 2);
	long long VR = MINQuery(A, B, K * 2 + 2, (L + R) / 2, R);
	return min(VL, VR);
}

long long MAXQuery(int A, int B, int K, int L, int R) {
	if (R <= A || B <= L) return -INF;
	if (A <= L && R <= B) return MAXDAT[K];
	long long VL = MAXQuery(A, B, K * 2 + 1, L, (L + R) / 2);
	long long VR = MAXQuery(A, B, K * 2 + 2, (L + R) / 2, R);
	return max(VL, VR);
}

int main() {
	cin >> N >> K;
	long long M = N;
	for (int i = 0; i < M; i++) cin >> P[i];
	init(N);
	for (int i = 0; i < M; i++) {
		MinUpdate(i, P[i]);
		MaxUpdate(i, P[i]);
	}
	ANS = M - K + 1;
	for (int i = 1; i < M - K + 1; i++) {
		long long Max = MAXQuery(i, i + K - 1, 0, 0, N);
		long long Min = MINQuery(i, i + K - 1, 0, 0, N);
		if (P[i - 1] < Min && Max < P[i + K - 1]) ANS--;
	}
	long long COUNT = 0, Cur = 1;
	for (int i = 0; i < M - 1; i++) {
		if (P[i] < P[i + 1]) Cur++;
		else Cur = 1;
		if (Cur == K) COUNT++;
	}
	ANS -= max(0LL, COUNT - 1);
	cout << ANS << endl;
}

Measured memory_bytes: 9984
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#include<vector>
#include <iomanip>
using namespace std;
int main(){
    int W,H;
    int x,y;
    cin>>W>>H>>x>>y;

    if(x+x == W && y+y == H)
        cout << (double)W*(double)H/2 << " " << 1 << endl;
    else
        cout << (double)W*(double)H/2 << " " << 0 << endl;
    return 0;

    // // 変な場所にx,y置かれた場合
    // float WArea = min(W*y, W*(H-y));
    // float HArea = min(H*x, H*(W-x));
    // float ZeroZeroDiagonal;
    // if(W/x > H/y){
    //     ZeroZeroDiagonal = H * (H/y) /2;
    // } else{
    //     ZeroZeroDiagonal = W * (W/x) /2;
    // }

    // float WZeroDiagonal;
    // if(W/(W-x) > H/(H-y)){
    //     WZeroDiagonal = H * (H/y) /2;
    // } else {
    //     WZeroDiagonal = W * (W/(W-x)) /2;
    // }

    // float ZeroHDiagonal;
    // if(W/x > H/(H-y)){
    //     ZeroHDiagonal = H * (H/(H-y)) /2;
    // } else {
    //     ZeroHDiagonal = W * (W/x) /2;
    // }
    // float WHDiagonal;
    // if(W/(W-x) > H/(H-y)){
    //     WHDiagonal = H * (H/(H-y)) /2;
    // } else {
    //     WHDiagonal = W * (W/(W-x)) /2;
    // }



    // //結果確認
    // float ans = max({WArea,HArea,ZeroZeroDiagonal,WZeroDiagonal,ZeroHDiagonal,WHDiagonal});
    // vector<float>ans2 = {WArea,HArea,ZeroZeroDiagonal,WZeroDiagonal,ZeroHDiagonal,WHDiagonal};
    // int countnum = count(ans2.begin(),ans2.end(),ans);
    // if(countnum > 1)
    //     cout << setprecision(7) << ans << " " << 1 << endl;
    // else
    //     cout << setprecision(7) << ans << " " << 0 << endl;
}

Measured memory_bytes: 256
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e5 + 10;

ll a[N], suff[N];

int main() {
	fast_cin();
	int n, m, v, p;
	cin >> n >> m >> v >> p;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	sort(a + 1, a + 1 + n);
	suff[n + 1] = 0;
	int ans = 0;
	for (int i = n; i >= 1; --i) {
		suff[i] = suff[i + 1] + m - a[i];
		int have = i + min(p - 1, n - i);
		if (n - p + 1 > i and a[n - p + 1] > a[i] + m) {
			continue;
		} else if (have >= v) {
			++ans;
			continue;
		} else {
			ll need = v - have;
			int j = n - p + 1;
			ll sum = (suff[i + 1] - suff[j + 1]) + ll(a[i]) * (j - i);
			if (sum >= ll(m) * need) {
				++ans;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx2")
// 293206GT
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <unordered_set>
#include <stack>
#include <string>
#include<algorithm>
#include <random>
#include <bitset>
#include <chrono>

typedef long long ll;
//#define int ll
using namespace std;
#define put(a) cout << (a) << '\n'
#define sqr(x) (x) * (x)
typedef pair<int, int> pii;
typedef long double ld;
typedef pair<ld, ld> pld;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<pii> vpii;
#define rep(x, y, a) for (int x = (y); x < (int)(a); ++x)
#define all(a) a.begin(), a.end()
#define chkmax(a, b) a = max(a, (b))
#define chkmin(a, b) a = min(a, (b))

namespace IO {

    template<class A, class B>
    ostream &operator<<(ostream &out, vector<pair<A, B>> a);

    template<class A>
    ostream &operator<<(ostream &out, vector<A> a);

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

    template<class A, class B>
    ostream &operator<<(ostream &out, vector<pair<A, B>> a) {
        for (pair<A, B> x: a)
            out << x.first << " " << x.second << '\n';
        return out;
    }

    template<class A>
    ostream &operator<<(ostream &out, vector<A> a) {
        for (A x: a) out << x << ' ';
        return out;
    }

    template<class A, class B>
    istream &operator>>(istream &in, pair<A, B> &a) {
        in >> a.first >> a.second;
        return in;
    }

    template<class A>
    istream &operator>>(istream &in, vector<A> &a) {
        for (A &x: a) in >> x;
        return in;
    }
}
using namespace IO;


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

void solve() {
    int n;
    cin >> n;
    vi l(n);
    cin >> l;
    sort(all(l));
    int ans = 0;
    rep(i, 0, n) rep(j, i + 1, n)rep(k, j + 1, n) {
        if (l[i] + l[j] > l[k] && l[i] != l[j] && l[j] != l[k]) ++ans;
    }
    put(ans);
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(30);
//    freopen("input.txt", "r", stdin);
    int q = 1;
//    cin >> q;

    while (q--) solve();
}


Measured memory_bytes: 3192
n = int(input())
c = input()

l = 0
r = n-1

cnt = 0

while r > l:
    if c[l] == "R":
        l = l + 1
    else:
        while r > l:
            if c[r] == "W":
                r = r - 1
            else:
                cnt = cnt + 1
                r = r - 1
                l = l + 1
                break

print(cnt)

Measured memory_bytes: 9468
#include <bits/stdc++.h>
#include <algorithm>
#include<string>
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int N, count = 0, mx = 0, t = 0;
    cin >> N;
        if (N == 1) {
            cout << 1 << endl;
            return 0;
        }
        for (int i = 1; i <= N; ++i) {
            int temp = i;
            while (temp % 2 == 0) {
                ++count;
                temp /= 2;
            }
            int top = mx;
            mx = max(mx, count);
            if (top != mx) t = i;
            count = 0;
        }
        cout << t << endl;
    return 0;
}

Measured memory_bytes: 256
// luogu-judger-enable-o2
// luogu-judger-enable-o2
#pragma GCC optimize("-O2")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
#include<map>
#include<bitset>
#include<ctime>
#include<cstdlib> 
#define LL long long
#define DB long double
#define pa pair<LL,int>
#define ctz __builtin_ctz
using namespace std;

inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
inline void Out(LL x){
    if(x>9) Out(x/10);
    putchar(x%10+'0'); 
}
const int N=2e5+10;
LL ans=0,x=0;
char s[N];
int main(){
    scanf("%s",s+1);
    int len=strlen(s+1);
    for(int i=1;i<=len;++i){
    	if(s[i]=='B') ++x;
    	else ans+=x;
	}
	printf("%lld\n",ans);
	return 0;
}
/*
10
100 8 8

*/

Measured memory_bytes: 384
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	int N;
	string S;
	cin>>N>>S;
	int ans=0;
	int maxi=ans;
	fx(S.size()){
		if(S.at(x)=='I'){
			ans++;
		}else{
			ans--;
		}
		maxi=max(ans,maxi);
	}
	ce(maxi)
}

Measured memory_bytes: 256
from collections import deque

def bfs():
	que=deque([])
	que.append(0)
	v[0]=0
	
	while que:
		p=que.popleft()
		for l in L[p]:
			if v[l-1]==-1:
				que.append(l-1)
				v[l-1]=v[p]+1
	
n=int(input())
L=[]
for i in range(n):
	A=[]
	A=list(map(int,input().split()))
	L.append(A[2:])
v=[-1]*n
bfs()
for i in range(n):
	print(i+1,v[i])



Measured memory_bytes: 6036
# https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/1/DPL_1_B
# 王道のナップサック問題
# 解説は螺旋本で十分わかりやすい

# 実装の都合上本とは少しだけ変えて実装する
# items (N,) ,i番目の品物の価値と重さが記録されているlist item[i]
# dp (N+1,W+1), [0,i)までのitemを考慮して大きさwのナップサックに入れる場合の価値の合計の最大値をdp[i][w]とする二次元list

# load data
N, W = list(map(int, input().split()))
items = []
for _ in range(N):
    items.append(tuple(map(int, input().split())))


# dpテーブルの作成
# 今回は最大化が目的なのですべてのマスを-1で埋めることにする
dp = [[-1] * (W + 1) for _ in range(N + 1)]

# dpテーブルの初期化
# dp[:][0]が0 ∵大きさ0のナップサックには何も入れられない
# dp[0][:]が0 ∵なにもitemを考慮しないときはナップサックに何も入らない。
for i in range(N + 1):
    dp[i][0] = 0
for w in range(W + 1):
    dp[0][w] = 0

# dpテーブルの更新
# i番目のitemが入らない場合→dp[i+1][w]=dp[i][w] ∵iを考慮しないときと価値は変わらない
# i番目のitemが入る場合→dp[i+1][w]=max(dp[i][w], dp[i][w-item[i]の重さ]+item[i]の価値)
# ∵iを入れる前の最善はdp[i][w-item[i]の重さ]にあり、それにitem[i]の価値を足すことで最善になる可能性がある。
# ただしちゃんと、iを入れないときのほうが良いかもしれないことに注意しなければいけない。
from itertools import product
for i, w in product(range(N), range(W + 1)):
    dp[i + 1][w] = dp[i][w]
    value, weight = items[i]
    if w - weight >= 0:
        dp[i + 1][w] = max(dp[i][w], dp[i][w - weight] + value)

print(dp[-1][-1])



Measured memory_bytes: 25868
J = [0 for i in range(int(2e5+3))]


def main():
    n = int(input())
    a = list(map(lambda x: int(x)-1, input().split()))

    for i in range(n):
        tmp = i - a[i]
        if 0 < tmp:
            J[tmp] += 1

    cnt = 0
    for i in range(n):
        tmp = a[i]+i+2
        if tmp < len(J)-1:
            cnt += J[tmp]

    print(cnt)
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 95424
#include <algorithm> // std::sort(begin,end), std::min, std::max
#include <iostream>
#include <queue>
#include <string>
#include <unordered_map>
#include <utility> // std::swap
#include <vector>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

template <typename T> // 0<1<2<3<4
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
template <typename T> // 0>1>2>3>4
using pq_dsc = priority_queue<T>;

int main(int argc, char const *argv[]) {
  string s;
  cin >> s;

  bool yes = false;
  yes |= s[0] == s[1] && s[2] == s[3] && s[0] != s[3];
  yes |= s[0] == s[2] && s[1] == s[3] && s[0] != s[1];
  yes |= s[0] == s[3] && s[1] == s[2] && s[0] != s[1];

  if (yes)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

ll ts = 1000000007;

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

  ll n, a;
  cin >> n >> a;

  cout << n * n - a << "\n";
}

Measured memory_bytes: 256
#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 a, b, c;
    cin >> a >> b >> c;
    string ans = "NO";
    if (c % __gcd(a, b) == 0) ans = "YES";
    cout << ans << endl;
}   

Measured memory_bytes: 256