akhauriyash/Code-Regression huggingface dataset:
n,q = gets.split.map(&:to_i)
s = gets.chomp.split("")
lr = q.times.map{gets.split.map(&:to_i)}

lcnt = Array.new(n+1,0)
for i in 1..(n-1)
  s[i-1..i].join == "AC" ? ps = 1 : ps = 0
  lcnt[i+1] = lcnt[i] + ps
end

lr.each do |rn|
  puts lcnt[rn[1]]-lcnt[rn[0]]
end

Measured memory_bytes: 38652
def count_dividers(n):
    dividers = {i for i in range(1, int(n ** 0.5) + 1) if n % i == 0}
    dividers = dividers | {n // d for d in dividers}
    return len(dividers)


N = int(input())

print(len([0 for n in range(105, N + 1, 2) if count_dividers(n) == 8]))


Measured memory_bytes: 3188
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC084A {
    class Program {
        static void Main(string[] args) {
            int input = int.Parse(Console.ReadLine());
            Console.WriteLine(24 + (24 - input));
        }
    }
}


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

#pragma warning(disable : 4996)

typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))
#define min3(x, y, z) min(x, min(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif

using namespace std;
//#define int long long;

double dist(double x1, double y1, double x2, double y2) {
  return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
ll idist(ll x1, ll y1, ll x2, ll y2) {
  return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}

signed main() {
  ll N;
  cin >> N;
  vector<pair<ll, ll>> p(N);
  rep(i, N) { cin >> p[i].second >> p[i].first;
  }
  sort(all(p), less<pair<ll, ll>>());
  ll t = 0;
  rep(i, N) { t += p[i].second;
    //cout << p[i].first << " " << p[i].second << endl;
    if (t > p[i].first) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}


Measured memory_bytes: 6428
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 100000000

typedef  long long ll;

using namespace std;

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        int tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r != 0){
        r = a % b;
        a = b;
        b = r;
    }
    return r;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    cout<<  ans << endl;
    }
}

void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}

void solve(void){
   int a,b,h;
   cin >>a>>b>>h;
   cout << (a+b)*h/2<<endl;
}

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


Measured memory_bytes: 256
#"."だけで構成されている列があるかどうかの判定
#--------------------------------------------------------------------------------------------------------------------
def check_column(grid):
    H_temp = len(grid)
    W_temp = len(grid[0])
    column_index = []    
    for i in range(W_temp):
        count_dot_column = 0
        for j in range(H_temp):
            if grid[j][i] == ".":
                count_dot_column += 1
        # print(i)
        # print("grid:{}".format(grid))
        # print("count_dot_column:{}".format(count_dot_column))
        # print("Htemp:{}".format(H_temp))
        if count_dot_column == H_temp:
            column_index.append(i)
    if len(column_index) != 0:
        return True,column_index
    else:
        return False,column_index
#--------------------------------------------------------------------------------------------------------------------

#"."だけで構成されている列を削除
#--------------------------------------------------------------------------------------------------------------------
def del_column(grid,del_column_index):
    H_temp = len(grid)
    # print("del_cplumn_index={}".format(del_column_index))
    for i in range(H_temp):
        del grid[i][del_column_index]
    return grid
#--------------------------------------------------------------------------------------------------------------------




H,W = map(int,input().split())
grid = []
judge = True
# index = []
#"."のみで構成される行を削除
#--------------------------------------------------------------------------------------------------------------------
for i in range(H):
    temp_input = input()
    count_dot = temp_input.count(".")
    if count_dot == W:
        pass
    else:
        grid.append(list(temp_input))
# print(grid)
# print(len(grid))#Hの値が返ってくる
# print(len(grid[0]))#Wの値が返ってくる
#--------------------------------------------------------------------------------------------------------------------
while judge:
    judge,del_column_index = check_column(grid)
    # print(judge)
    if judge:
        # print("value")
        grid = del_column(grid, del_column_index[0])
        # print(del_column_index)
#結果を出力
#--------------------------------------------------------------------------------------------------------------------
# aprint()
for i in range(len(grid)):
    print("".join(grid[i]))
#--------------------------------------------------------------------------------------------------------------------




Measured memory_bytes: 3188
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
    char s[100010];
    int n,a=0,b=0;
    scanf("%s",s);
    n=strlen(s);
    for(int i=0;i<n;i++){
        if(s[i]=='1'){
            a++;
        }
        else{
            b++;
        }
    }
    printf("%d\n",2*min(a,b));
}

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

int main()
{
	int n;
	int a,b,c,d;
	int team[100];
	int p[100];
	int sum=0;

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

	for(int i=0 ;i<(n*(n-1))/2 ;i++){
		cin >> a >> b >> c >> d;
		if(c > d)
			team[a] += 3;
		else if(c < d)
			team[b] += 3;

		else if(c == d){
			team[a]++;
			team[b]++;
		}
	}
	for(int i=1 ;i<n+1 ;i++){
		for(int j=1 ;j<n+1 ;j++){
			if(team[i] < team[j]){
				p[i]++;
			}
		}
	}
	for(int i=1 ;i<n+1 ;i++){
		cout << p[i] << endl;
	}


	return 0;
}

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

using namespace std;

typedef long long ll;

const int N = 1e6 + 5;
const int INF = 1e9 + 7;

ll c;

int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    string s, t;
    cin >> s >> t;
    for(int i = 0; i < s.size(); i++){
        if(s[i] != t[i])c++;
    }cout << c;
    return 0;
}


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

int n;
vector<int> h(110), ch(110, 0);

int solve(int l, int r) {
    int mini = 1000;
    for (int i = l; i < r; i++) {
        mini = min(h[i], mini);
    }

    int ans = mini;
    int nr, nl = l;
    for (int i = l; i < r; i++) {
        h[i] -= mini;
        if (h[i] == 0) {
            nr = i;
            if (nl < nr) ans += solve(nl, nr);
            nl = i+1;
        }
    }
    if (nl < r) ans += solve(nl, r);
    return ans;
}

int main() {

    cin >> n;
    for(int i = 0; i < n; i++) cin >> h[i];
    cout << solve(0, n) << endl;
}

Measured memory_bytes: 3596
include Math

ans = 0
num, *ary = $<.map &:to_i

ary.each do|i|

 if !( ( i % 2 == 0 && i != 2 ) || ( i % 10 == 5 && i != 5 ) || i == 1 )

  for j in 2..sqrt(i).floor

   if i % j == 0

    ans -= 1
    break

   end
  end
  
  ans += 1

 end
end

puts ans



Measured memory_bytes: 7028
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7


int main(int argc, char** argv) {
  ll N;
  cin >> N;
  vector<ll> L(N);
  rep(i, N) {
    cin >> L[i];
  }
  sort(all(L)); // Now, L is sorted

  // a < b < c.
  // We fix b and c, then search a.
  // c < a + b <=> c-b < a

  ll ans = 0;
  rep(b, N) {
    int r = b + 1;
    rep(a, b) {
      // Here, a < b < c. a and b are fixed. We search the count of c.
      // c < a + b is required.
      while (r < N && L[r] < L[a] + L[b]) { ++r; }
      int l = b + 1;
      ans += r - l; // c is [l, r)
    }
  }

  cout << ans << endl;
}


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

using namespace std;

int main() {
  string S;
  cin >> S;
  int N = S.length();
  int answer = N;

  for (int k = 0; k < 2; k++) {
    int add = 0;
    for (int i = 0; i < N; i++) {
      if (i % 2 == k) {
        add += S[i] == '0';
      } else {
        add += S[i] == '1';
      }
    }
    answer = min(answer, add);
  }
  cout << answer << endl;

  return 0;
}


Measured memory_bytes: 512
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    S = input()
    search_string=['A','Z']
    position=[]

#Aを探す
    for i,s in enumerate(S):
        if s==search_string[0]:
            position.append(i)
            break

#Zを探す
    for r_i,r_s in enumerate(reversed(S)):
        if r_s==search_string[1]:
            position.append(len(S)-r_i)
            break

    print(position[1]-position[0])

if __name__=="__main__":
    main()

Measured memory_bytes: 9252
import heapq

N, M, S = map(int, input().split())

E = [[] for _ in range(N)]
A = [[0]*N for _ in range(N)]
B = [[0]*N for _ in range(N)]
for i in range(M):
    U, V, a, b = map(int, input().split())
    u = U-1
    v = V-1
    E[u].append(v)
    E[v].append(u)
    A[u][v] = A[v][u] = a
    B[u][v] = B[v][u] = b

C = []
D = []
for i in range(N):
    c, d = map(int, input().split())
    C.append(c)
    D.append(d)

M = 50*N
T = [[-1]*M for _ in range(N)]
h = []
heapq.heappush(h, (0, 0, min(M-1, S))) # (time, inode, snode)
while h:
    dmin, inode, snode = heapq.heappop(h)
    if T[inode][snode]!=-1: continue
    T[inode][snode] = dmin

    # (inode,snode) -> (enode, snode-a) with time b
    for enode in E[inode]:
        a = A[inode][enode]
        b = B[inode][enode]
        esnode = snode-a
        if esnode<0 or T[enode][esnode]!=-1: continue
        heapq.heappush(h, (dmin+b, enode, esnode))

    # (inode, snode) -> (inode, snode+c) with time d
    c = C[inode]
    d = D[inode]
    snode_c = min(M-1, snode+c)
    if T[inode][snode_c]!=-1: continue
    heapq.heappush(h, (dmin+d, inode, snode_c))

for inode in range(1, N):
    print(min([x for x in T[inode] if x>=0]))

Measured memory_bytes: 115152
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		long N = long.Parse(str[0]);
		long P = long.Parse(str[1]);
		var list = PrimeFactors(P);
		list.Sort();
		long ans = 1;
		if(N > list.Count){
			ans = 1;
		} else {
			long cta = 1;
			for(var i=1;i<list.Count;i++){
				if(list[i] == list[i-1]){
					cta++;
				} else {
					if(cta>=N){
						for(var j=1;j<=cta/N;j++){
							ans *= list[i-1];
						}
					}
					cta = 1;
				}
			}
			if(cta>=N){
				ans *= list[list.Count-1];
			}
		}
		Console.WriteLine(ans);
	}

	public static List<long> PrimeFactors(long n){
		long i = 2;
		long tmp = n;
		var list = new List<long>();
		while(i*i<=n){
			if(tmp%i==0){
				tmp /= i;
				list.Add(i);
			} else {
				i++;
			}
		}
		if(tmp != 1){
			list.Add(tmp);
		}
		return list;
	}
}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long



vector<vector<ll> >intervals;
vector<ll>dp;
vector<ll>st;
vector<ll>lazy;
vector<vector<ll> >endings;
void buildst(ll node,ll strt,ll ed){

    if(strt==ed){
        st[node] = dp[strt];
        return;
    }
    ll mid = strt+(ed-strt)/2;
    buildst(2*node,strt,mid);
    buildst(2*node+1,mid+1,ed);
    st[node] = max(st[2*node],st[2*node+1]);
    return;
}

void updaterangest(ll node,ll strt,ll ed,ll l,ll r,ll val){

        if(lazy[node]!=0){
            st[node] += lazy[node];

            if(strt != ed){
                lazy[2*node] += lazy[node];
                lazy[2*node+1] += lazy[node];
            }
            lazy[node] =0;
        }

        if(r<strt || l>ed){
            return;
        }
        if(l<=strt && r>=ed){
            st[node] += val;
            if(strt !=ed){
                lazy[node*2] += val;
                lazy[node*2 +1] += val;
            }else{
                dp[strt] += val;
            }
            return;
        }
        ll mid = strt+(ed-strt)/2;
        updaterangest(2*node,strt,mid,l,r,val);
        updaterangest(2*node+1,mid+1,ed,l,r,val);
        st[node] = max(st[2*node],st[2*node+1]);
}

ll queryrangest(ll node,ll strt,ll ed,ll l,ll r){

        if(r<strt || l>ed){
            return -1;
        }
        if(lazy[node]!=0){
            st[node] += (ed-strt+1)*lazy[node];

            if(strt != ed){
                lazy[2*node] += lazy[node];
                lazy[2*node+1] += lazy[node];
            }
            lazy[node] =0;
        }
        if(strt>=l && r>=ed){
            return st[node];
        }
        ll mid = strt+(ed-strt)/2;
        ll a = queryrangest(node*2,strt,mid,l,r);
        ll b = queryrangest(node*2+1,mid+1,ed,l,r);
        return max(a,b);
}


void solve(){
  ll n,m;cin>>n>>m;
  dp.resize(n);
  endings.resize(n);
  st.resize(4*n+1);
  lazy.resize(4*n+1);
  buildst(1,0,n-1);
  intervals.resize(m,vector<ll>(3));
  for(ll i=0;i<m;i++){
    cin>>intervals[i][0]>>intervals[i][1]>>intervals[i][2];
    intervals[i][0]--;
    intervals[i][1]--;
    endings[intervals[i][1]].push_back(i);
  }
  for(ll i=0;i<endings[0].size();i++){
        ll idx = endings[0][i];
    updaterangest(1,0,n-1,intervals[idx][0],intervals[idx][1],intervals[idx][2]);
  }



  for(ll i=1;i<n;i++){

        ll prevmx = max(0LL,queryrangest(1,0,n-1,0,i-1));
        updaterangest(1,0,n-1,i,i,prevmx);
        for(ll j=0;j<endings[i].size();j++){
            ll idx = endings[i][j];
            updaterangest(1,0,n-1,intervals[idx][0],intervals[idx][1],intervals[idx][2]);
        }

  }
  cout << max(0LL,queryrangest(1,0,n-1,0,n-1))<<"\n";
}

int main(){
//    cin.tie(0);
//    cout.tie(0);
//    cin.sync_with_stdio(0);
//    cout.sync_with_stdio(0);

    //cout.precision(10);
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


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

int main() {
    string s, p;
    cin >> s >> p;
    string t = s + s;
    for (int i = 0; i < t.size() - p.size() + 1; ++i) {
        string part = t.substr(i, p.size());
        if (part == p) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}



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

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

// 操作を繰り返していけば最終的には
// 数列の全要素のgcdが生成できるボールの最小値になる

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++)  cin >> a[i];
    int g = a[0];
    for(int i = 1; i < n; i++)  g = gcd(g, a[i]);
    for(int i = 0; i < n; i++){
        if(a[i] >= k && (a[i]-k)%g == 0){
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		int temp = 0;
		int[] t = new int[N+1];
		int[] x = new int[N+1];
		int[] y = new int[N+1];

		t[0] = 0;
		x[0] = 0;
		y[0] = 0;

		for(int i=1;i<N+1;i++) {
			t[i] = sc.nextInt();
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
		}

		for(int i=1;i<N+1;i++) {
			temp = t[i] - t[i-1];
			int d = Math.abs(x[i] - x[i-1]) + Math.abs(y[i] - y[i-1]);

			if(d > temp) {
				System.out.println("No");
				return;
			}else if((temp - d)%2 != 0) {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}
}


Measured memory_bytes: 90472
n,k = map(int, input().split())
a = list(map(int, input().split()))

d = {}
for t in a:
    if t in d:
        d[t]+=1
    else:
        d[t]=1
ans = 0
if len(d) <= k:
    print(ans)
else:
    dl = sorted(list(zip(d.values(), d.keys())))
    for i in range(len(dl)-k):
        ans += dl[i][0]
    print(ans)

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

pair<string, int> p[1000000];
pair<string, int> key;
int tail;
int head;

void push(string str, int n){
  p[tail].first = str;
  p[tail].second = n;
  tail++;
}

void pop(){
  key = p[head];
  head++;
}


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

  for(int i = 0; i < n; i++){
    cin >> p[i].first >> p[i].second;
  }
  tail = n;

  int cnt = 0;
  int sum = 0;
  while(cnt != n){
    pop();
    string name = key.first;
    int time = key.second;
      // cout << name << " " << time << endl;
    if(time - q > 0){
      sum+=q;
      push(name,time-q);
    }else {
      cnt++;
      sum+=time;
      cout << name << " " << sum << endl;
    }
  }

}

Measured memory_bytes: 19176
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

N = rs()

s = 0
for c in N:
	s += int(c)
if s % 9 == 0:
	print('Yes')
else:
	print('No')


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

int main(){
  string S;
  cin >> S;
  bool flag = false;
  while(1){
    if(S.substr(0,2) == "hi"){
      S.erase(0,2);
    }
    else
      break;
    if(S.empty()){
      flag = true;
      break;
    }
  }
  
  if(flag)
    cout << "Yes";
  else
    cout << "No";
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int inf = 0x3f3f3f3f,oo = inf;
#define pi 3.14159265358979323846
#define IL inline
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define Rep(i,a,b) for(int i=(a);i<=(b);++i)
#define Dep(i,a,b) for(int i=(a);i>=(b);--i)
#define pc putchar
#define gc getchar
IL ll read(){
    ll x=0;char f=0;char c=gc();
    for(;!isdigit(c);c=gc())f|=(c=='-');
    for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
    return f?-x:x;
}
IL void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);pc(x%10+'0');}
IL void writeln(ll x){write(x);pc('\n');}
IL void wri(ll x){write(x),pc(' ');}
#define debug(x) printf(#x" = %d\n",x);
#define rd() read()
#define rdb() readdb()
#define mem(x,v) memset(x,v,sizeof(x))
#define pb push_back
#define mp make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-(x)))
#define y1 ____y1
#define hash __hash
#define union _union
#define ramdom ((double)rand() / RAND_MAX)
#define x first
#define y second
const int maxn = 5e5+233;
struct Edge{
	int to,nxt;
	Edge(){}
	Edge(int to,int nxt):to(to),nxt(nxt){}
}edge[maxn*2];
int first[maxn],nume;
void Addedge(int a,int b){
	edge[nume] = Edge(b,first[a]);
	first[a] = nume++;
}
int mxdep[maxn],wson[maxn],sz[maxn];
int dfn[maxn],dfx[maxn],n,k;
int dp_array[maxn],tag[maxn];
int *f[maxn];
void init(int u,int fa){
	mxdep[u] = 0;wson[u] = 0;sz[u] = 1;
	for(int e=first[u];~e;e=edge[e].nxt){
		int v=edge[e].to;
		if(v == fa) continue;
		init(v,u);
		mxdep[u] = max(mxdep[u],mxdep[v] + 1);
		sz[u] += sz[v];
		if(!wson[u] || mxdep[v] > mxdep[wson[u]])
			wson[u] = v;
	}
}
void pre(int u,int fa){
	dfx[dfn[u] = ++*dfn] = u;
	f[u] = dp_array + dfn[u];
	if(wson[u]) pre(wson[u],u);
	for(int e=first[u];~e;e=edge[e].nxt){
		int v=edge[e].to;
		if(v==fa || v==wson[u]) continue;
		pre(v,u);
	}
}
int g[maxn],h[maxn],ans;
void dfs(int u,int fa){
	if(wson[u]) dfs(wson[u],u);
	tag[u] = tag[wson[u]];
	f[u][0] = (wson[u] ? sz[wson[u]] : 0) - tag[u];
	int m = min(k,mxdep[u]);
	for(int e=first[u];~e;e=edge[e].nxt){
		int v = edge[e].to;
		if(v==wson[u] || v==fa) continue;
		dfs(v,u);
		int len = min(k,mxdep[v] + 1);
		g[0] = sz[v];Rep(i,1,len) g[i] = f[v][i-1] + tag[v];
		Rep(i,0,len) h[i] = f[u][i];
		
		Rep(i,0,len) f[u][i] = min(g[i]+h[min(i,k-i)],g[min(i,k-i)] + h[i]) - g[len];
		Rep(i,1,len) f[u][i] = min(f[u][i],f[u][i-1]);
		tag[u] += g[len];
		Rep(i,max(len+1,k-len),min(m,k)) f[u][i] += g[k-i] - g[len];
		Rep(i,max(len+1,k-len),min(m,k)) f[u][i] = min(f[u][i],f[u][i-1]);
//		Rep(i,len+1,min(m,k-len-1)) f[u][i] += g[len];
	}
	ans = min(ans,n - sz[u] + (f[u][min(k,m)]+tag[u]));
	//从root往上搞一格
}
int main(){
	memset(tag,0,sizeof(tag));
	mem(first,-1);nume = 0;
	n = read();k = read();ans = n;
	rep(i,1,n) {
		int x = read(),y = read();
		Addedge(x,y);
		Addedge(y,x);
	} init(1,0);
	*dfn = 0;
	pre(1,0);
	dfs(1,0);
	writeln(ans);
	return 0;
}

Measured memory_bytes: 7732
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define SORT_DESC(x) sort((x).rbegin(),(x).rend())
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
#define ANS(ans) cout<<ans<<endl;
const ll LINF = (1LL << 62) - 1;
const int INF = (1 << 30) - 1;
template<class T>bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if (b<a){a=b;return 1;}return 0;}
// clang-format on

void solve(long long N) {
  ll a = 0;
  rep1(i, N) {
    if (i % 3 != 0 && i % 5 != 0)
      a += i;
  }
  ANS(a);
}

// clang-format off
int main() {
  long long N;
  scanf("%lld",&N);
  solve(N);
  return 0;
}


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

typedef long long ll;
typedef long double ld;

const int MOD = 1000000007;

int add(int a, int b){
    return (a+b)%MOD;
}

int mul(int a, int b){
    return ((ll)a*b)%MOD;
}

int pw(int a, int b){
    if(b == 0) return 1;
    int res = pw(a, b/2);
    res = mul(res, res);
    if(b%2) res = mul(res, a);
    return res;
}

int fact[200005];
int inv[200005];

int bcof(int n, int k){
    if(n < 0 || k < 0 || n < k) return 0;
    int res = fact[n];
    res = mul(res, inv[k]);
    res = mul(res, inv[n-k]);
    return res;
}

int dp[3005];
pair <int, int> niz[3005];

int main(){
    ios_base::sync_with_stdio(false);
    cout.precision(10);
    cout<<fixed;

    int n, m, k;
    cin >> n >> m >> k;
    fact[0] = 1;
    for(int i=1; i<=n+m; i++) fact[i] = mul(fact[i-1], i);
    for(int i=0; i<=n+m; i++){
        inv[i] = pw(fact[i], MOD-2);
    }
    for(int i=1; i<=k; i++){
        cin >> niz[i].first >> niz[i].second;
        niz[i].first--;
        niz[i].second--;
    }
    sort(niz+1, niz+1+k);
    niz[k+1].first = n-1;
    niz[k+1].second = m-1;
    k++;
    for(int i=1; i<=k; i++){
        dp[i] = bcof(niz[i].first + niz[i].second, niz[i].first);
        //cout << dp[i] << endl;
        for(int j=1; j<i; j++){
            dp[i] = add(dp[i], MOD-mul(dp[j], bcof(niz[i].first-niz[j].first+niz[i].second-niz[j].second, niz[i].first-niz[j].first)));
        }
    }
    cout << dp[k];
    return 0;
}


Measured memory_bytes: 1920
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>
#include <sstream>
 
#define ALL(a)  (a).begin(),(a).end()
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

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

    ll a, b;

    cin >> a >> b;

    (b % a == 0) ? (cout << a+b << endl) : (cout << b-a << endl);

    
}

Measured memory_bytes: 256
n = int(input())

#iでリストを受け取るために、わざと2次元配列にしていることに注意する。
otoshidama = [float(i[0]) if i[1] == "JPY" else float(i[0])*380000 for j in range(n) for i in [input().split()]]
print(sum(otoshidama))


Measured memory_bytes: 2940
#include <iostream>
#include <cmath>
#include <map>
#include <list>
#include <algorithm>

#define INF (1<<30)
#define re(i, n) for(int i=0;i<(n);i++)
#define rep(i, s, n) for(int i=(s);i<(n);i++)
using namespace std;
typedef long long ll;

int main(void) {
    int a, b, c, d;
    int m[10];
    cin >> a >> b >> c >> d;
    for (int i = 0; i < 10; i++)m[i] = 0;
    m[a]++;
    m[b]++;
    m[c]++;
    m[d]++;
    cout << ((m[1] && m[9] && m[7] && m[4]) ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){


  int W,H, x, y, r ;

  scanf("%d%d%d%d%d", &W, &H, &x, &y, &r);

  if ( 0 + r <= x && x <= W-r && 0+r <= y && y <=H-r){
   printf("Yes\n");
  }  else {
   printf("No\n");
  }

  return 0;

}


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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);
    ll N, K;
    cin >> N >> K;

    ll count = 0;
    REP(i,N){
        ll h;
        cin >> h;
        if( h < K ){

        }else{
            count++;
        }
    }

    cout << count << endl;
}


Measured memory_bytes: 256
//  @ /\/\ BESH //

#include <bits/stdc++.h>
#define inp_out_work ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define testCase    int T; cin>>T; while(T--)
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,s,e) for(int i=s;i<=e;i++)
#define endl '\n'
#define debug(P) cout<<#P<<" = "<<P<<endl;
#define pb push_back
#define FILE freopen("in.txt","r",stdin); freopen("out.txt","w",stdout);

using namespace std;

typedef long long ll;

const int MAXN = 200001;
const int mod = 1000000007;


int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    fr(i,n)cin>>a[i];
    vector<int> cnt(n, 0);

    ll ans = 1;

    for(int i = 0; i < n; i++){
        if(a[i] == 0){
            ans = (ans * (3-cnt[0]))%mod;
        }
        else{
            ans = (ans * (cnt[a[i]-1] - cnt[a[i]]))%mod;
        }
        ++cnt[a[i]];
    }

    cout<<ans<<endl;

}


Measured memory_bytes: 1024
#include <stdio.h>
int main(void){
    // Your code here!
    int n, a[100000], i;
    
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&a[i]);
    
    for(i=0;i<n;i++){
        if(a[i]%2==0){
            if((a[i]%3!=0)&&(a[i]%5!=0)){
                printf("DENIED\n");
                return 0;
            }
        }
    }
    printf("APPROVED\n");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstring>
#include <algorithm>
#include <limits.h>
int dp[5001][4],p[5000], n;
using namespace std;
#define chmin( a, b ){ (a) = min( a, b ) ;}
main()
{
    int n;
    cin >> n;
    for( int i = 0; i < n; i++ ) cin >> p[i];
    memset( dp, 0x3f, sizeof( dp ) );
    
    for( int i = 0; i < 4; i++ )dp[0][i] = i;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            chmin(dp[i + 1][max(0, p[i] - j)], dp[i][j] + max(0, p[i] - j) * (i == n - 1 ? 1 : 2));
        }
    }
    printf("%d\n", *min_element(dp[n], dp[n] + 4));

}


Measured memory_bytes: 3300
//----AUTHOR:kkdrummer----/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include<ext/rope>
using namespace __gnu_cxx;
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<int> C;
#define X real()
#define Y imag()
//typedef unordered_set<ll> usll;
//typedef unordered_multiset<ll> umsll;
typedef multiset<ll> msll;
typedef set<ll> sll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pair<ll,ll> > vpll;
typedef priority_queue<ll> pqll;
typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;
//typedef unordered_multiset<int> umsi;
//typedef unordered_set<int> usi;
typedef pair<int,int> pi;
typedef vector<pair<int,int> > vpi;
typedef vector<pair<double,double> > vpd;
typedef pair<double,double> pd;
typedef priority_queue<int> pqi;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ind_set;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ind_setll;
#define in insert
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define be begin
#define en end
#define itr iterator
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mo 1000000007
#define inf 1000000000000000001
#define ninf -1000000000000000001
#define ima INT_MAX
#define imi INT_MIN
#define oncnt __builtin_popcount
#define zerobegin __builtin_clz
#define zeroend __builtin_ctz
#define parity __builtin_parity
const ld pii=3.14159265359;
inline ll modpow(ll x,ll n){if(n==0)return 1;if(n==1)return(x%mo);ll u=(modpow(x,n/2));u=(u*u)%mo;if(n%2!=0)u=(u*x%mo)%mo;return u;}
inline ll modinv(ll x){return modpow(x,mo-2);}
inline ll mmul(ll a,ll b){    if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll madd(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a+b>=mo)return(a+b)%mo;return(a+b);}
inline ll msub(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;return((a-b+mo)%mo);}
inline ll mdiv(ll a,ll bb){if(a>=mo)a=a%mo;ll b=modinv(bb);if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll gcd(ll a,ll b){return __gcd(a,b);}


int main()
{
io
int testcases=1;//cin>>testcases;
while(testcases--)
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
int dp[n];
dp[n-1]=0;
dp[n-2]=abs(a[n-1]-a[n-2]);
for(int i=n-3;i>=0;i--)
{int c1=dp[i+2]+abs(a[i]-a[i+2]);
int c2=dp[i+1]+abs(a[i]-a[i+1]);
	dp[i]=min(c1,c2);
}
cout<<dp[0];

}return 0;}







Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
using namespace std;

char c[200001];

int main()
{
    int n;
    cin >> n >> c;
    int r = 0, w = 0;
    for (int i = 0; i < n; i++)
    {
        if (c[i] == 'W') w++;
        else r++;
    }
    int s = 0;
    for (int i = 0; i < r; i++)
    {
        if (c[i] == 'W') s++;
    }
    cout << s << '\n';
    return 0;
}


Measured memory_bytes: 3808
S=list(input())
T=list(input())
x=len(S)
y=0
for i in range(x):
  S.append(S[0])
  del S[0]
  if S==T:
    y=1
  else:
    pass
  
if y==1:
  print("Yes")
else:
  print('No')


Measured memory_bytes: 2940
import java.util.*;

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

		int n = scan.nextInt();
		String s = scan.next();
		char c[] = new char[n];
		int ans = 0;
		int r = 0;
		int w = 0;
		
		for(int i=0;i<n;i++) {
			c[i] = s.charAt(i);
			if(c[i] == 'R') {
				r++;
			}
		}
		
		for(int i=0;i<r;i++) {
			if(c[i] == 'W') {
				ans++;
			}
		}
		
		
		System.out.println(ans);
	}

}


Measured memory_bytes: 40968
#include <bits/stdc++.h>
#include <vector>
#include <cstdlib> //abs(int)
using namespace std;
int main(void){
  int A, B, X;
  cin >> A >> B >> X;
  if(A <= X && X <= A + B){
    cout << "YES";
  } else {
    cout << "NO";
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <algorithm>  
#include <iterator>    
#include <set>
using namespace std;

int main(){
    int a;
    string s;
    cin >> a;
    cin >> s;

    if (a >= 3200){
        cout << s << endl;
    }else {
        cout << "red" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>

#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n;i++)
#define repf(i, a, b) for (int i = (int)a; i < (int)b;i++)
#define repv(x, arr) for (auto& x:arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a,b) make_pair(a,b)
#define op(i) cout << (i) << endl;

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

const ll mod = 1e9 + 7;

ll fun(ll &b,ll n){
    if (n<b){
        return n;
    }
    else {
        return fun(b, n / b) + n % b;
    }
}

int main(){
    ll N, S;
    cin >> N >> S;
    ll b = 2;
    if (S==N){
        cout << N + 1 << endl;
        return 0;
    }
    else if(S>N){
        cout << -1 << endl;
        return 0;
    }
    ll x = 0;
    while (1){
        if (b*b>N){
            x = b;
            break;
        }
        ll f = fun(b, N);
        if (f==S){
            cout << b << endl;
            return 0;
        }
        b++;
    }
    for (int i = x; i > 0;i--){
        b = 1 + (N - S) / i;
        if (b>1 and fun(b,N)==S){
            cout << b << endl;
            return 0;
        }
    }
        cout << -1 << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
long long int f(long long int a){
  return a<0?-1*a:a;
}
int main(){
  long long int a,b=999,c;
  scanf("%lld",&a);
  while(a>0){
    c=f(753 - (a%1000));
    if(b>c){
      b=c;
    }
    a=a/10;
  }
  printf("%lld",b);
  return 0;}

Measured memory_bytes: 128
n, x, y = map(int, input().split())

ans = [0] * n
for i in range(n-1):
  for j in range(i+1, n):
    d = min(j-i, abs(i-x+1)+abs(j-y+1)+1)
    ans[d] += 1

ans=ans[1:]

for a in ans:
    print(a)
 


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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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

struct Edge {
    ll to, rev;
    long double cap;
    Edge(ll _to, long double _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph &G, ll from, ll to, long double cap, bool revFlag,
              long double revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {
    ll n;
    cin >> n;
    Array a(n), b(n);
    REP(i, n) {
        cin >> a[i];
    }
    REP(i, n) {
        cin >> b[i];
    }
    ll suma = 0, sumb = 0;
    REP(i, n) {
        if(a[i] > b[i]) {
            ll d = a[i] - b[i];
            if(d > sumb) {
                d -= sumb;
                sumb = 0;
                suma += d;
            } else {
                sumb -= d;
            }
        } else {
            ll d = b[i] - a[i];
            d /= 2;
            if(d > suma) {
                d -= suma;
                suma = 0;
                sumb += d;
            } else {
                suma -= d;
            }
        }
    }
    if(suma <= sumb) {
        cout << "Yes" << en;
    } else {
        cout << "No" << en;
    }
}

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

    solve();
    // ll t;cin>>t;REP(i,t) solve();

    return 0;
}


Measured memory_bytes: 3792
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>

int main(void)
{

  while(1){
    int n;
    scanf(" %d", &n);
    if(n == 0)
      break;

    bool prime[2 * n + 1];
    for(int i = 0; i <= 2 * n; i++){
      prime[i] = true;
    }
    prime[0] = prime[1] = false;

    int count = 0;
    for(int i = 2; i <= sqrt(2 * n); i++)
      if(prime[i])
	for(int j = 0; i * (j + 2) <= 2 * n; j++)
	  prime[i * (j + 2)] = 0;

    for(int i = n+1; i <= 2 * n; i++)
      if(prime[i]){
	count++;
	//	printf("%d ", i);
      }
    //puts("");
    printf("%d\n", count);
  }
  
  return 0;
}

Measured memory_bytes: 1268
using System;

namespace abc144_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);

            if(a < 10 && b < 10)
            {
                Console.WriteLine(a * b);
            }
            else
            {
                Console.WriteLine(-1);
            }
            Console.Read();
        }
    }
}

Measured memory_bytes: 13140
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()
l=[]
ans=0
for i in range(N):
    if len(l)<K:
        if T[i]=="r":
            l.append("p")
            ans+=P
        elif T[i]=="s":
            l.append("r")
            ans+=R
        else:
            l.append("s")
            ans+=S
    elif l[-K]=="p" and T[i]=="r":#len(l)>=Kのとき、後ろからK番目がT[i]と同じとき
        l.append("0")#適当な文字入れる
        ans+=0
    elif l[-K]=="r" and T[i]=="s":#len(l)>=Kのとき、後ろからK番目がT[i]と同じとき
        l.append("0")#適当な文字入れる
        ans+=0
    elif l[-K]=="s" and T[i]=="p":#len(l)>=Kのとき、後ろからK番目がT[i]と同じとき
        l.append("0")#適当な文字入れる
        ans+=0
    else:
        if T[i]=="r":
            l.append("p")
            ans+=P
        elif T[i]=="s":
            l.append("r")
            ans+=R
        else:
            l.append("s")
            ans+=S

#print("".join(l))
print(ans)

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

int n;
int ans = 0;
int ary[100000];
vector<int> v;

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) cin >> ary[i];
	for (int i = 0; i < n; i += 2) ary[i] = !ary[i];

	int cnt = 1;
	for (int i = 1; i < n; i++)
	{
		if (ary[i] == ary[i - 1])
		{
			cnt++;
		}
		else
		{
			ans = max(ans, cnt);
			v.push_back(cnt);
			cnt = 1;
		}
	}
	ans = max(ans, cnt);
	v.push_back(cnt);

	for (int i = 0; i < v.size(); i++)
	{
		if (i == v.size() - 2) ans = max(ans, v[i] + v[i + 1]);
		else if (i == v.size() - 1) ans = max(ans, v[i]);
		else ans = max(ans, v[i] + v[i + 1] + v[i + 2]);
	}
	cout << ans << endl;

	return 0;
}

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

int main()
{
	int a, b, c, k;
	long long sum = 0, ans = 0;
	cin >> a >> b >> c;
	cin >> k;
	ans = max(a, max(b, c));
	sum = a + b + c - ans;
	int s = ans;
	for(int i = 1; i <= k; i++) {
		s = s * 2;
	}
	sum = sum + s;
	cout << sum << endl;
}


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

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

    int ans = 0;
    for(int i=0; i<n-2; i++){
        //cout << s.substr(i,3) << endl;
        if(s.substr(i,3) == "ABC") ans += 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
Otoshidama = 0

for _ in range(N):
    xu = input().split(" ")
    x = float(xu[0])
    u = xu[1]
    if u == 'JPY':
        Otoshidama += x
    else:
        Otoshidama += x*380000
    
print(Otoshidama)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(void){
    ll a, v, b, w, t;
    cin>>a>>v>>b>>w>>t;
    if(abs(a-b)>t*(v-w)){
        cout<<"NO"<<endl;
    }
    else cout<<"YES"<<endl;
    return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

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

    ll X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<ll> A(X), B(Y), C(Z);
    REP(i, X) cin >> A[i];
    REP(i, Y) cin >> B[i];
    REP(i, Z) cin >> C[i];

    vector<ll> tmp;
    REP(i, X)REP(j, Y) tmp.push_back(A[i]+B[j]);
    sort(tmp.rbegin(), tmp.rend());
    vector<ll> res;
    ll sa = min(K, (ll)tmp.size());
    REP(i, sa)REP(j, Z) res.push_back(tmp[i]+C[j]);
    sort(res.rbegin(), res.rend());
    ll ta = min(K, (ll)res.size());
    REP(i, ta){
    	cout << res[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 43368
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>

using namespace std;

//配列の中から任意の要素を足していき，最大のものを出力

int main() {

    int n,W ;
    cin >> n >> W ;
    int dp[n+10][W+10]  ;
    int v[n],w[n];
    for (int i = 0; i < n; i++)
    {
        cin >> v[i] >> w[i] ;
    }
    
    
    for (int w = 0; w <= W ; w++)
    {
        dp[0][w] = 0 ;
    }
    

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j <= W; j++)
        {
            if(j>=w[i]) dp[i+1][j] = max(dp[i][j],dp[i+1][j-w[i]]+v[i]) ;
            else dp[i+1][j] = dp[i][j] ;
        }
    }

    cout << dp[n][W] << endl ;
    return 0 ;
}



Measured memory_bytes: 7040
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>

//#include<bits/stdc++.h>




using namespace std;
int main() {

	int n, a, b;
	cin >> n >> a >> b;
	
	n -= a;
	n %= b;
	cout << n << endl;

	return 0;
}

Measured memory_bytes: 256
typedef long long ll;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

int main(){
  const int n = getInt();
  const ll a = getInt();
  const ll b = getInt();

  vector<ll> x(n);
  REP(i,n) x[i] = getInt();

  ll ans = 0;
  REP(i,n-1) ans += min(a * (x[i + 1] - x[i]), b);
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 1024
n, *d = map(int, open(0).read().split())
d.sort()

a = [24 - b if i & 1 else b for i, b in enumerate(d)]
a.append(0)


ans = 24
print(min([abs(a[i] - a[j]) for i in range(n + 1)
           for j in range(i + 1, n + 1)]))


Measured memory_bytes: 9192
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
#define PI 3.141592653589793
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, M, V, P;
  cin >> N >> M >> V >> P;
  vll A(N);
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  sort(ALL(A));
  vll sum(N+1, 0LL);
  for(int i = 0; i < N; i++){
    sum.at(i+1) = sum.at(i) + A.at(i);
  }

  ll total = M * V;
  ll ans = P-1;
  for(int i = 0; i < N-(P-1); i++){
    ll t = total;
    ll num = A.at(i);
    ll p = min(M, t);
    num += p;
    t -= p;
    if(num < A.at(N-P)) continue;
    if(t == 0){
      ans++;
      continue;
    }
    ll pp = min(t, (P-1LL) * M);
    t -= pp;
    if(t == 0){
      ans++;
      continue;
    }
    ll ppp = min(t, M*i);
    t -= ppp;
    if(t == 0){
      ans++;
      continue;
    }
    if(sum.at(N-P+1) - sum.at(i+1) + t <= num * (N-P-i)){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1920
#include<string>
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#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--)

int main() {
    string S;
    cin>>S;
    ll N=S.size();
    //assume ? == 0
    vector<ll> sums(N,-1);
    ll x = 0;
    rep(i,N){
        char c = S[i];
        //x is sum
        if(c=='1'){
            x+=1;
        }else{
            x-=1;
        }
        sums[i]=x;
    }
    vector<ll> maxSums(N,-1);
    ll maxSum=sums[N-1];
    rrep(i,N){
        maxSum=max(maxSum,sums[i]);
        maxSums[i]=maxSum;
    }
    ll limit1 = max(maxSum,(ll) 0);//max(maxSum,(ll)0);
    ll limit2 = limit1+1;//max(maxSum+1,(ll) 0);

    string S1(S);
    string S2(S);

    ll cnt=0;
    rep(i,N){
        if (S[i]!='?') continue;
        ll cur = maxSums[i] + cnt*2;
        if (limit1  >= cur + 2){
            cnt += 1;
            S1[i] = '1';
        }else{
            S1[i] = '0';
        }
    }
    cnt=0;
    rep(i,N){
        if (S[i]!='?') continue;
        ll cur = maxSums[i] + cnt*2;
        if (limit2  >= cur + 2){
            cnt += 1;
            S2[i] = '1';
        }else{
            S2[i] = '0';
        }
    }

    ll min1=0;
    ll max1=0;
    x=0;
    rep(i,N){
        char c = S1[i];
        if(c=='1'){
            x+=1;
        }else{
            x-=1;
        }
        min1 = min(min1,x);
        max1 = max(max1,x);
    }
    ll min2=0;
    ll max2=0;
    x=0;
    rep(i,N){
        char c = S2[i];
        if(c=='1'){
            x+=1;
        }else{
            x-=1;
        }
        min2 = min(min2,x);
        max2 = max(max2,x);
    }
    ll ans = min(max1-min1,max2-min2);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 21928
#include <bits/stdc++.h>
using namespace std;
int n, a[200005], b[200005];
int main(){
    iostream::sync_with_stdio(0);
    cin >> n;
    for(int i=1;i<=n;i++) cin >> a[i];
    for(int i=1;i<=n;i++) cin >> b[i], b[i] -= a[i];
    long long sumpo = 0, sumne = 0;
    for(int i=1;i<=n;i++){
        if (b[i] > 0)  sumpo += b[i] / 2;
        else sumne -= b[i];
    }
    //cerr << sumpo << ' ' << sumne << endl;
    if (sumne <= sumpo) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 384