akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

template<int char_size,int margin>
class Trie{
private:
    struct Node{
        int ne[char_size];
        int num;
        vec<int> accept;
        Node():num(0){
            memset(ne,-1,sizeof(ne));
        }
    };

    vec<Node> nodes;
    int root;
public:
    Trie():root(0){
        nodes.push_back(Node());
    }

    void update_direct(int node,int id){
        nodes[node].accept.push_back(id);
        nodes[node].num++;
    }

    void update_child(int node,int child){
        nodes[node].num++;
    }

    void add(const string& S,int s_id,int node_id,int id){
        if(s_id==S.size()) update_direct(node_id,id);
        else{
            int c = S[s_id]-margin;
            if(nodes[node_id].ne[c]==-1){
                nodes[node_id].ne[c] = (int) nodes.size();
                nodes.push_back(Node());
            }
            add(S,s_id+1,nodes[node_id].ne[c],id);
            update_child(node_id,nodes[node_id].ne[c]);
        }
    }

    void add(const string& S,int id){
        add(S,0,0,id);
    }

    void add(const string &S){
        add(S,nodes[0].num);
    }

    template<class F>
    void query(const string& S,F& f,int s_id,int node_id){
        for(auto& id:nodes[node_id].accept) f(id);
        if(s_id==S.size()) return ;
        else{
            int c = S[s_id]-margin;
            if(nodes[node_id].ne[c]==-1) return ;
            query(S,f,s_id+1,nodes[node_id].ne[c]);
        }
    }

    void dfs(const string& S,int s_id,int node_id,vvec<int>& sum,vec<int>& q,vec<int>& ans){
        if(s_id==S.size()){
            for(auto& x:q) ans[x] -= nodes[node_id].num;
            return ;
        }
        for(int c=0;c<26;c++){
            int ne = nodes[node_id].ne[c];
            if(ne!=-1){
                sum[S[s_id]-'a'][c] += nodes[ne].num;
            }
        }
        int c = S[s_id]-margin;
        if(nodes[node_id].ne[c]==-1) return ;
        dfs(S,s_id+1,nodes[node_id].ne[c],sum,q,ans);
    }

    template<class F>
    void query(const string& S,F& f){
        query(S,f,0,0);
    }

    int count()const{
        return nodes[0].num;
    }

    int size()const{
        return (int) nodes.size();
    }

};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<string> S(N);
    Trie<26,'a'> trie;
    vvec<int> sum(N,vec<int>(26));
    for(int i=0;i<N;i++){
        cin >> S[i];
        trie.add(S[i]);
    }
    int Q;
    cin >> Q;
    vvec<int> pos(Q,vec<int>(26));
    vvec<int> q(N);
    for(int i=0;i<Q;i++){
        int a;
        cin >> a;
        a--;
        q[a].push_back(i);
        string P;
        cin >> P;
        for(int j=0;j<26;j++) pos[i][P[j]-'a'] = j;
    }
    vec<int> ans(Q,N);
    for(int i=0;i<N;i++){
        vvec<int> sum(26,vec<int>(26));
        trie.dfs(S[i],0,0,sum,q[i],ans);
        for(auto& x:q[i]){
            for(int a=0;a<26;a++) for(int b=0;b<26;b++) if(pos[x][a]<pos[x][b]) ans[x] -= sum[a][b];
        }
    }
    for(auto& x:ans) cout << x+1 << "\n";
}

Measured memory_bytes: 158420
#include <iostream>
#include <iomanip>
#include <climits>
#include <limits>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <unordered_map>
#include <random>
#define _USE_MATH_DEFINES
#include <cmath>
#include <complex>

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define INFL (int)1e9
#define INFLL (ll)1e18
#define INFD numeric_limits<double>::infinity()
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loopll(i, n) for(ll i = 0; i < (ll)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopll1(i, n) for(ll i = 1; i <= (ll)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Looprll(i, n) for(ll i = (ll)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define Looprll1(i, n) for(ll i = (ll)n; i >= 1; i--)
#define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++)
#define printv(vector) Loop(i, vector.size()) { cout << vector[i] << " "; } cout << endl;
#define rnd(d) (ll)((double)d + (d >= 0 ? 0.5 : -0.5))
#define floorsqrt(x) ((ll)sqrt((double)x) + ((ll)sqrt((double)x) * (ll)sqrt((double)x) <= (ll)x ? 0 : -1))
#define ceilsqrt(x) ((ll)sqrt((double)x) + ((ll)x <= (ll)sqrt((double)x) * (ll)sqrt((double)x) ? 0 : 1))
#define ceildiv(a, b) ((ll)a / (ll)b + ((ll)a % (ll)b == 0 ? 0 : 1))
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)

/*******************************************************/

int main() {
  string s; cin >> s;
  vector<bool> used(26, false);
  Loop(i, s.length()) used[s[i] - 'a'] = true;
  string ans = "";
  if (s.length() < 26) {
    Loop(i, 26) {
      if (used[i] == false) {
        ans = s + (char)('a' + i);
        break;
      }
    }
  }
  else {
    Loopr(i, 25) {
      if (ans != "") break;
      if (s[i] < s[i + 1]) {
        for (int j = i + 1; j < 26; j++) {
          used[s[j] - 'a'] = false;
        }
        Loop(j, 26) {
          if (used[j] == false && 'a' + j > s[i]) {
            ans = s.substr(0, i) + (char)('a' + j);
            break;
          }
        }
      }
    }
  }
  if (ans == "") cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int n;
	cin >> n;
	if (n == 22)
	{
		cout << "Christmas Eve Eve Eve";
	}
	else if (n == 23)
	{
		cout << "Christmas Eve Eve";
	}
	else if (n == 24)
	{
		cout << "Christmas Eve";
	}
	else if (n == 25)
	{
		cout << "Christmas";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a) (a).begin(),(a).end()

int main() {
  long long N, M;
  cin >> N >> M;
  if (abs(N - M) > 1) {
    cout << 0 << endl;
    return 0;
  }

  long long ans = 1;
  if (N == M) {
    for (long long i = 1; i <= N; i++) {
      ans *= i * i % 1000000007;
      ans %= 1000000007;
    }
    ans = ans * 2 % 1000000007;
    cout << ans << endl;
    return 0;
  }

  if (N < M) swap(N, M);
  for (long long i = 1; i < N; i++) {
    ans *= i * i % 1000000007;
    ans %= 1000000007;
  }

  ans = ans * N % 1000000007;
  cout << ans << endl;
  return 0;
}


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

typedef long long ll;
ll n, a, b;
int main()
{
	cin >> n >> a >> b;
	if (a > b) {cout << '0'; return 0;}
	if (n == 1) {cout << (a == b); return 0;}
	if (n == 2) {cout << '1'; return 0;}
    cout << (n - 2) * (b - a) + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define N 305
using namespace std;

int n, k, dp[N][N][N];
char s[N];

int f(int bas, int son, int k){
	if(bas == son)
		return 1;
	if(bas > son)
		return 0;
	int &r = dp[bas][son][k];
	if(r != -1)
		return r;
	if(s[bas] == s[son])
		r = f(bas + 1, son - 1, k) + 2;
	if(k)
		r = max(r, f(bas + 1, son - 1, k - 1) + 2);
	r = max(r, f(bas + 1, son - 1, k));
	r = max(r, f(bas, son - 1, k));
	r = max(r, f(bas + 1, son, k));
	return r;
}

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	memset(dp, -1, sizeof dp);
	scanf("%s %d",s + 1, &k);
	n = strlen(s + 1);
	printf("%d\n", f(1, n, k));
	return 0;
}

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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n - 1);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  rep(i, n - 1) cin >> c[i];

  int result = 0;
  int beforeIndex = -1;
  rep(i, n) {
    int currentIndex = a[i] - 1;
    result += b[currentIndex];
    if (i != 0 && beforeIndex == (currentIndex - 1)) {
      result += c[currentIndex - 1];
    }
    beforeIndex = currentIndex;
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const int MOD=1e9+7;
const long double Pi=acos(-1);
using  P=pair<ll,ll>;
ll gcd(ll a,ll b){//aとbの最大公約数を返す
  if(a%b==0){return b;}
  else{return gcd(b,a%b);}
}
ll lcm(ll a,ll b){//aとbの最小公倍数を返す
  return a*b/gcd(a,b);
}
ll pow(ll x,ll y){//x^yを返す
  ll tmp=x,res=1;
  while(y){
    if(y%2){res=res*tmp%MOD;}
    y>>=1;
    tmp=tmp*tmp%MOD;
  }
  return res;
}
ll nature(ll a){//絶対値を返す
  if(a>=0){return(a);}
  else{return(-1*a);}
}
ll prime(ll a){//素数なら1を返す
  if(a==2){return 1;}
  else if(a%2==0 || a==1){return 0;}
  for(ll i=3;i*i<=a;i+=2){if(a%i==0){return 0;}}
  return 1;
}
int main(){
  ll N;
  cin>>N;
  cout<<N*(N-1)/2<<endl;
}

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

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

//マクロ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main(int argc, char const *argv[])
{
    // スイッチの個数n, 電球の個数m
    int n, m, k;
    scanf("%d%d", &n, &m);
    vector<vector<int>> s(m);

    REP(i,m)
    {
        scanf("%d", &k);
        REP(j,k)
        {
            int tmp;
            scanf("%d", &tmp);
            s[i].PB(tmp - 1);
        }
    }

    int p[m];
    REP(i,m)
        scanf("%d", &p[i]);
    

    int ans = 0;
    // 全探索
    REP(i,pow(2,n))
    {   
        int swch_cnt[m] = {0};
        // スイッチ jはスイッチのインデックス
        REP(j, n)
        {
            // 1の時スイッチおん
            if (i & (1 << j))
            {
                // k:電球の番号
                REP(k,m)
                {
                    // l:k番目の電球につながっているスイッチのインデックス
                    REP(l,SIZE(s[k]))
                    {
                        if (j == s[k][l])
                            swch_cnt[k]++;
                    }
                }
            }
            
        }
        // 設定に有っているかどうかを判定する
        bool flag = true;
        REP(k,m)
        {
            if (p[k] != (swch_cnt[k] % 2))
                flag = false;
        }
        if (flag)
            ans++;
    }


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


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    ll k; cin >> k;
    
    priority_queue<ll, vector<ll>, greater<ll>> que;
    for (ll i = 1; i <= 9; ++i) {
        que.push(i);
    }

    for (ll i = 0; i < k; ++i) {
        ll t = que.top(); que.pop();

        if (i == k - 1) {
            cout << t << endl;
            return 0;
        }

        for (ll j = -1; j <= 1; ++j) {
            ll k = t % 10 + j;

            if (0 <= k && k <= 9) que.push(t * 10 + k);
        }
    }
}

Measured memory_bytes: 2420
A, B, K =map(int, input().split())
if K<A:
    A_after=A-K
    B_after=B
elif K>=A:
    A_after=0
    if K-A<B:
        B_after=B-(K-A)
    elif K-A>=B:
        B_after=0
print(A_after, B_after)

Measured memory_bytes: 2940
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

class Main {

    public static void main(String[] args) throws IOException {
        ReaderD.init(System.in);
        int h = ReaderD.nextInt();
        int w = ReaderD.nextInt();
        int d = ReaderD.nextInt();
        Map<Integer, Pair> coord = new HashMap<>();

        int[][] grid = new int[h][w];
        for (int i = 0; i < grid.length; i++) {
            for (int j = 0; j < grid[i].length; j++) {
                grid[i][j] = ReaderD.nextInt();
                coord.put(grid[i][j], new Pair(i + 1, j + 1));
            }
        }

        Map<Integer, ArrayList<Integer>> distTo = new HashMap<>();
        for (int i = 1; i <= d; i++) {
            distTo.put(i, new ArrayList<>());
            distTo.get(i).add(0);
            for (int j = i + d; j <= h*w; j += d) {
                int dist = Math.abs(coord.get(j).x - coord.get(j - d).x) + Math.abs(coord.get(j).y - coord.get(j - d).y);
                int size = distTo.get(i).size();
                distTo.get(i).add(distTo.get(i).get(size - 1) + dist);
            }
        }

        int q = ReaderD.nextInt();
        for (int i = 0; i < q; i++) {
            int l = ReaderD.nextInt();
            int distToL = distTo.get(l % d == 0 ? d : l % d).get(l % d == 0 ? l/d - 1 : l/d);
            int r = ReaderD.nextInt();
            int distToR = distTo.get(r % d == 0 ? d : r % d).get(r % d == 0 ? r/d - 1 : r/d);
            System.out.println(distToR - distToL);
        }
    }
}

class Pair {
    int x, y;
    Pair(int x, int y) {
        this.x = x;
        this.y = y;
    }
}

/**
 * Reader class based on the article at "https://www.cpe.ku.ac.th/~jim/java-io.html"
 */
class ReaderD {
    private static BufferedReader reader;
    private static StringTokenizer tokenizer;

    static void init(InputStream inputStream) {
        reader = new BufferedReader(new InputStreamReader(inputStream));
        tokenizer = new StringTokenizer("");
    }

    private static String next() throws IOException {
        String read;
        while (!tokenizer.hasMoreTokens()) {
            read = reader.readLine();
            if (read == null || read.equals(""))
                return "-1";
            tokenizer = new StringTokenizer(read);
        }

        return tokenizer.nextToken();
    }

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

//    static long nextLong() throws IOException {
//        return Long.parseLong(next());
//    }
//
//    //    Get a whole line.
//    static String line() throws IOException {
//        return reader.readLine();
//    }
//
//    static double nextDouble() throws IOException {
//        return Double.parseDouble(next());
//    }
}



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

int main() {
  int N;
  int count = 1;
  cin >> N;
  
  vector<int> d(N);
  for (int i = 0; i < N; i++) {
  	cin >> d.at(i);
  }
  
  sort(d.begin(), d.end());
  reverse(d.begin(), d.end());
  
  for (int i = 0; i < N-1; i++) {
  	if (d.at(i) > d.at(i+1)) {
      count++;
    }
  }
  
  cout << count << endl;
}
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LD long double
#define LL long long int
#define ULL unsigned long long
#define vi vector<int>
#define mod 1000000007

int main(){
	int a,b,c;
  	cin>>a>>b>>c;
  	if(a+b+c >= 22)
      	cout << "bust" <<endl;
 	else
      	cout << "win" <<endl;
  
  
  
}
  

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
	string s,n;
	cin>>s>>n;
	int ans=0;
	if(s[0]==n[0])ans++;
	if(s[1]==n[1])ans++;
	if(s[2]==n[2])ans++;
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>

//#define INF 100000000
//#define MOD (int) (1e9+7)
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;

const int MAX = 1000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    double l;
    cin >> l;

    double ans;

    ans = (l/3.0) * (l/3.0) * (l/3.0);

    printf("%.12f\n", ans);
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace procon
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var x = inputs[0];
            var y = inputs[1];
            
            for (int i = Math.Min(x,y); i >= 0; i--)
            {
                if(x % i == 0 && y % i == 0)
                {
                    Console.WriteLine(i);
                    return;
                }
            }
        }
    }
}

Measured memory_bytes: 9532
import Control.Applicative
import Data.Char

main :: IO()
main = do
    [a,b] <- map read . words <$> getLine
    s <- getLine
    if all isDigit (take a s) && s !! a == '-' && all isDigit (drop (a+1) s)
    then putStrLn "Yes"
    else putStrLn "No"

Measured memory_bytes: 508
use std::cmp;
use std::collections::*;

pub struct Scanner {
    line: Vec<String>,
    idx: usize,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        return Scanner {
            line: vec![],
            idx: 0,
        };
    }
    fn next<T: std::str::FromStr>(&mut self) -> T {
        if self.idx == self.line.len() {
            let mut buffer = String::new();
            std::io::stdin().read_line(&mut buffer).ok();
            let a: Vec<&str> = buffer.trim().split(' ').collect();
            self.line = a.iter().map(|&s| String::from(s)).collect();
            self.idx = 0;
        }
        let ret: T = self.line[self.idx].parse::<T>().ok().expect("Parse error.");
        self.idx += 1;
        ret
    }
    fn next_string(&mut self) -> Vec<char> {
        let s: String = self.next();
        return s.chars().collect::<Vec<char>>();
    }
    fn next_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        let mut v: Vec<T> = Vec::with_capacity(n);
        for _i in 0..n {
            v.push(self.next());
        }
        v
    }
}



fn main(){
    let mut scan = Scanner::new();
    let n: i32 = scan.next();
    let m: usize = scan.next();
    

    if n % 2 == 1{
       for i in 0..m {
            println!("{} {}", i + 1 , n - i as i32);
        }
    } else{
        let mut v: Vec<(i32, i32)> = Vec::new();

        let mut i = 0;
        let mut len = n/2-1;
        while len > 0{
            v.push((i, i+len));
            i += 1;
            len -= 2;
        }
        i = n/2;
        len = n/2 - 2;
        while len > 0{
            v.push((i, i+len));
            i += 1;
            len -= 2;
        }
        for i in 0..m {
            println!("{} {}", v[i].0 + 1 , v[i].1 + 1);
        }
    }
}


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



int main() {
#ifdef HOME
    freopen("in", "r", stdin);
#endif

    string s;
    while (cin >> s) {
        int n = s.length();
        vector<int> a(n);
        for (int i = 0; i < n; i++) {
            a[i] |= 1 << (s[i] - 'a');
        }
        int ans = 0;
        while (1) {
            int mask = -1;
            for (int i = 0; i < (int)a.size(); i++) mask &= a[i];
            if (mask != 0) break;
            for (int i = 1; i < (int)a.size(); i++) a[i - 1] |= a[i];
            a.pop_back();
            ans++;
        }
        printf("%d\n", ans);
    }

#ifdef HOME
    cerr << clock() / (double)CLOCKS_PER_SEC << endl;
#endif
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N,M;
	cin >> N >> M;
	vector<int> cont(N,0);
	cont[0] =1;
	vector<int> poc(N,1);
	for(int i =0; i < M; i++) {
		int x,y;
		cin >> x >> y;
		x--, y--;
		if(cont[x] == 0) {
			poc[x]--;
			poc[y]++;
			continue;}
		if(x == y) continue;
		cont[y] =1;
		if(poc[x] == 1) cont[x] =0;
		poc[x]--;
		poc[y]++;}
	int ans =0;
	for(int i =0; i < N; i++) if(cont[i] == 1) ans++;
	cout << ans << "\n";
	return 0;}

// look at my code
// my code is amazing


Measured memory_bytes: 1024
#ifdef __APPLE__
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <iomanip>
#include <cmath>
#include <ctgmath>
#include <math.h>
#include <cassert>
#include <chrono>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define io ios_base::sync_with_stdio(false), cin.tie(NULL)
#define GFOR(i,a,n) for (i=a;i<n;i++)
#define FOR(i,a,n) for (int i=a;i<n;i++)
#define RFOR(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define tc(t) for (int tc=1; tc<=t; tc++)
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<long long int> vll;
typedef vector<pair<int, int> > vpi;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll modInverse (ll a) {ll p = mod - 2; return powmod(a, p);}
// head
void dfs(int s, vector<vi>& graph, vector<bool>& visited, int& cnt) {
    cnt ++;
    visited[s] = true;
    for (auto x : graph[s]) {
        if (!visited[x]) {
            dfs(x, graph, visited, cnt);
        }
    }
}

void solve() {
    int n, m;
    cin >> n >> m;
    vector<vi> graph(n+1);
    int u, v;
    while (m--) {
        cin >> u >> v;
        graph[u].pb(v);
        graph[v].pb(u);
    }
    int max = 0;
    vector<bool> visited(n+1);
    for (int i = 1; i <= n; i++) {
        if (!visited[i]) {
            int cnt = 0;
            dfs(i, graph, visited, cnt);
            max = std::max(max, cnt);
        }
    }
    cout << max << "\n";
}

int main() {
    #ifdef LOCAL
    auto t1 = std::chrono::high_resolution_clock::now();
    #endif

    io;
    solve();

    #ifdef LOCAL
    auto t2 = std::chrono::high_resolution_clock::now();
    auto duration = std::chrono::duration_cast<std::chrono::milliseconds>( t2 - t1 ).count();

    std::cout << "Time Taken: " << duration << "\n";
    #endif

}
// check for edge cases in limits
// printing double may print 1.223232e9 like values, beware of that
// carefully observe simulation of test cases
// multiset erase is does not do what it is supposed to


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

#ifdef LOCAL 
string to_string(char a) { return string(1,a); }
string to_string(bool a) { return a ? "1" : "0"; }
string to_string(const char* a) { return (string)a; }
string to_string(string a) { return a; }
string to_string(vector<bool> v) {
	string s = "["; for(unsigned i=0;i<v.size();i++){ s += ((i>0)?" ":"");
    s += char('0'+v[i]); } 	s += "]"; return s; }
template<class A, class B> string to_string(pair<A,B> p);
template<class T> string to_string(T v) {
	bool b = 1; string s = "["; for (const auto& x: v) {
		if (!b) {s += ", ";} b = 0; s += to_string(x); } s += "]"; return s; }
template<class A, class B> string to_string(pair<A,B> p) {
	return "("+to_string(p.first)+", "+to_string(p.second)+")"; }
void dbgf() { cerr << endl; }
template<class H, class... T> void dbgf(H h, T... t) {
	cerr << to_string(h); if (sizeof...(t)) cerr << ", ";
	dbgf(t...); }
#define dbg(...) cerr << #__VA_ARGS__ << " = ", dbgf(__VA_ARGS__)
#else
#define dbg(...) 0
#endif
#define boolout(x) cout<<(x?"YES":"NO")<<endl;
typedef long long ll;


void solve()
{
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }

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

    cout << dp[n-1] << endl;

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t; // read t. cin knows that t is an int, so it reads it as such.
    for (int i = 1; i <= t; ++i) {
        solve();
    }
    return 0;
}



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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
ll K;
ll A[202020],B[202020];

void solve() {
	int i,j,k,l,r,x,y; string s;

	cin>>N>>M>>K;
	FOR(i,N) {
		cin>>x;
		A[i+1]=A[i]+x;
	}
	FOR(i,M) {
		cin>>x;
		B[i+1]=B[i]+x;
	}

	int ma=0;
	FOR(i,N+1) if(A[i]<=K) {
		x=lower_bound(B,B+M+1,K-A[i]+1)-B-1;
		ma=max(ma,i+x);
	}
	cout<<ma<<endl;

}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

Measured memory_bytes: 6792
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	int ans = 0;
    	int N = sc.nextInt();
    	sc.nextLine();
    	String[] ary = new String[N];
    	for(int i = 0; i < N; i++){
    		ary[i] = sc.nextLine();
    	}
    	int M = sc.nextInt();
    	sc.nextLine();
    	String[] ary2 = new String[M];
    	for(int i = 0; i < M; i++){
    		ary2[i] = sc.nextLine();
    	}
    	sc.close();
    	for(int i = 0; i < N; i++){
    		int score = 0;
    		for(int j = 0; j < N; j++){
    			if(ary[i].equals(ary[j])){
    				score++;
    			}
    		}
    		for(int j = 0; j < M; j++){
    			if(ary[i].equals(ary2[j])) score--;
    		}
    		ans = Math.max(ans, score);
    	}
    	System.out.println(ans);
    }
}

Measured memory_bytes: 21844
N,A,B=map(int,input().split())
x=map(int,input().split())
ls=[]
a=0
for i in x:
     ls.append(i)
for i in range(len(ls)-1):
     result=ls[i+1]-ls[i]
     if result*A>B:
          a+=B
     else:
          a+=result*A
print(a)

Measured memory_bytes: 14252
n, k = map(int, input().split())

data = [0] * n

for i in range(k):
    d = int(input())
    people = list(map(int, input().split()))

    for j, val in enumerate(people):
        tar = val - 1
        data[tar] += 1

ans = 0

for i in data:
    if (i == 0):
        ans += 1
print(ans)


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

int main(){

  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  int wa, wb, sc, sd;
  int sum_w = 0, sum_s = 0, s = 0;
  int sum = 0;
  a *= 100;
  b *= 100;
  sum_w = a;
  for(wa = 0; wa <= 100; wa++){
    for(wb = 0; wb <= 100; wb++){
      for(sc = 0; sc <= 100; sc++){
        for(sd = 0; sd <= 100; sd++){
          sum_w = wa * a + wb * b;
          sum_s = sc * c + sd * d;
          if(sum_w + sum_s <= f){
            if(sum_s*100 <= sum_w*e){
              if(s*(sum_w+sum_s) <= sum*sum_s){
                s = sum_s;
                sum = sum_w + sum_s;
              }
            }
          }
        }
      }
    }
  }
  cout << sum << " " << s << endl;
  return 0;
}


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

int main(int argc,char* argv[]){
  int a,b,c;
  cin >> a >> b >> c;
  if(a==b) cout << c << endl;
  else if(a==c) cout << b << endl;
  else cout << a << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	while(1) {
		int h,w; cin>>h>>w;
		if(h==0&&w==0) break;
		
		for(int i=0;i<h;i++) {
			bool flag = (i+1)%2;
			for(int j=0;j<w;j++) {
				if(flag) cout<<"#";
				else cout<<".";
				flag = !flag;
			}
			cout<<endl;
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 3100
import java.util.*;
import java.lang.*;

import static java.lang.StrictMath.abs;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //ｎは偶数
        int n = sc.nextInt();
        int[] d = new int[n];
        int[] d2 = new int[n];
        int count =0;
        //格納
        for(int i=0; i < n; i++){
            d[i] = sc.nextInt();
            d2[i] = d[i];
        }

        //sort
        Arrays.sort(d2);
//        for(int h=0; h < n ;h++) {
//            System.out.print(d[h]);
//            System.out.println(d2[h]);
//        }
      //  真ん中の数字の判定
        int std = d2[(n/2)-1]+1;
        int std2 = d2[n/2];

            System.out.println(std2 - std+1 );

//        int ans = 0;
//        //判定
//        two: for(int l = std; l < d2[n-1]; l++) {
//            count =0;
//            for (int k = 0; k < n; k++) {
//                if (d2[k] < l) {
//                    count++;
//                }
//            }
//
//            if (count == n / 2) {
//                ans ++;
//                continue two;
//            } else if(count > n/2){
//                break two;
//
//            }
//        }
//        //出力
//        System.out.println(ans);
    }
}



Measured memory_bytes: 60816
#ライブラリインポート
from collections import defaultdict

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	S = list(input())
	LR = [0] * (N + 1)
	LG = [0] * (N + 1)
	LB = [0] * (N + 1)
	for i in range(N):
		LR[i + 1] = LR[i]
		LG[i + 1] = LG[i]
		LB[i + 1] = LB[i]
		if S[i] == "R":
			LR[i + 1] += 1
		elif S[i] == "G":
			LG[i + 1] += 1
		else:
			LB[i + 1] += 1

	# print(LR)
	# print(LG)
	# print(LB)
	ans = 0
	for i in range(N):
		if S[i] == "R":
			ans += LG[i] * (LB[N] - LB[i + 1]) + LB[i] * (LG[N] - LG[i + 1])
		elif S[i] == "G":
			ans += LR[i] * (LB[N] - LB[i + 1]) + LB[i] * (LR[N] - LR[i + 1])
		else:
			ans += LR[i] * (LG[N] - LG[i + 1]) + LG[i] * (LR[N] - LR[i + 1])

	#引く作業
	for i in range(N):
		for j in range(1, N + 1):
			if i + 2 * j > N - 1:
				break
			if S[i] != S[i + j] and S[i + j] != S[i + 2 * j] and S[i] != S[i + 2 * j]:
				ans -= 1

	print(ans)



if __name__ == '__main__':
	main()

Measured memory_bytes: 68764
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
N,M = map(int,input().split())
arrAB = []
for i in range(N):
    arrAB.append(list(map(int,input().split())))

arrAB = sorted(arrAB, key=lambda lis: lis[0])

drink = M
ans = 0
for lis in arrAB:
    if drink<=0:
        break
    num = min(drink,lis[1])
    ans += lis[0] * num
    drink -= num

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 29788
import java.util.*;
import java.util.regex.*;

class Main{
	private final static Pattern addsubmuldiv = Pattern.compile("^(.*?)(-?\\d+)([+Z*/])(-?\\d+)(.*)$");
	private final static Pattern addsub = Pattern.compile("^(.*?)(-?\\d+)([+Z])(-?\\d+)(.*)$");
	private final static Pattern muldiv = Pattern.compile("^(.*?)(-?\\d+)([*/])(-?\\d+)(.*)$");

	private static String process(String s){
		Matcher m=muldiv.matcher(s);
		while(m.find()){
			if(m.group(3).equals("*"))
				s=m.group(1)+(Integer.parseInt(m.group(2))*Integer.parseInt(m.group(4)))+m.group(5);
			else
				s=m.group(1)+(Integer.parseInt(m.group(2))/Integer.parseInt(m.group(4)))+m.group(5);
			m=muldiv.matcher(s);
		}

		m=addsub.matcher(s);
		while(m.find()){
			if(m.group(3).equals("+"))
				s=m.group(1)+(Integer.parseInt(m.group(2))+Integer.parseInt(m.group(4)))+m.group(5);
			else
				s=m.group(1)+(Integer.parseInt(m.group(2))-Integer.parseInt(m.group(4)))+m.group(5);
			m=addsub.matcher(s);
		}
		return s;
	}

	private static String process2(String s){
		Matcher m=addsubmuldiv.matcher(s);
		while(m.find()){
			if(m.group(3).equals("*"))
				s=m.group(1)+(Integer.parseInt(m.group(2))*Integer.parseInt(m.group(4)))+m.group(5);
			else if(m.group(3).equals("/"))
				s=m.group(1)+(Integer.parseInt(m.group(2))/Integer.parseInt(m.group(4)))+m.group(5);
			else if(m.group(3).equals("+"))
				s=m.group(1)+(Integer.parseInt(m.group(2))+Integer.parseInt(m.group(4)))+m.group(5);
			else
				s=m.group(1)+(Integer.parseInt(m.group(2))-Integer.parseInt(m.group(4)))+m.group(5);
			m=addsubmuldiv.matcher(s);
		}
		return s;
	}

	public static void main(String[]z){
		Scanner x=new Scanner(System.in);
		String s=x.next().replaceAll("-","Z");
		String ans=x.next();
		boolean a=process(s).equals(ans);
		boolean b=process2(s).equals(ans);
		if(a&&b)System.out.println("U");
		if(a&&!b)System.out.println("M");
		if(!a&&b)System.out.println("L");
		if(!a&&!b)System.out.println("I");
	}
}

Measured memory_bytes: 17340
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security.Cryptography.X509Certificates;
using System.Xml;

namespace hello_world
{
	class Program
	{

		static void Main(string[] args)
		{
			int x = int.Parse(Console.ReadLine());
			int m = x / 500;
			int n = x % 500;
			int k = n / 5;
			int sum = m * 1000 + k*5;
			Console.WriteLine(sum);

		}
	}

}



Measured memory_bytes: 11220
N,K = map(int,input().split())
A = list(map(int,input().split()))
lis = [-1] * len(A)
nex = 1
start = 0
loop = 0
result = -1
for i in range(len(A)):
    if i == K:
        result = nex
    if lis[nex-1] ==-1:
        lis[nex-1]=i
        nex = A[nex-1]
    else :
        start = nex
        loop = i - lis[nex-1]
        break
nex = start
end = (K-lis[start-1])%loop
for i in range(end):
    nex = A[nex-1]
if result ==-1:
    result = nex
print(result)



Measured memory_bytes: 32372
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
int main(){
    int n;
    scanf("%d",&n);
    ii a[n];
    for (int i = 0; i < n; i++){
        scanf("%d",&a[i].first);
        a[i].second = i;
    }
    sort(a,a+n);
    int ans = 0;
    for (int i = 0; i < n; i++){
        ans += (a[i].second^i)&1;
    }
    printf("%d",ans/2);
}


Measured memory_bytes: 1152
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int a, b, c;
  cin >> a >> b >> c;
  auto f = [&]() {
    if (a && !b && !c) return "Close";
    if (!a && b && !c) return "Close";
    if (a && b && !c) return "Open";
    if (!a && !b && c) return "Open";
    if (!a && !b && !c) return "Close";
  };
  cout << f() << endl;
}

Measured memory_bytes: 3116
/**
 *
 * AtCoder Beginner Contest 103 - Problem A: Task Scheduling Problem (https://abc103.contest.atcoder.jp/tasks/abc103_a)
 *
 * Find if the S(N) = sum of digit of N, divides N.
 *
 * Math solution: compute S(N) and check if it divides N.
 */
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int MAX { 10 };

int as[MAX];

void solve()
{
    vector<int> ps { 0, 1, 2 };

    int min_cost = 3000;

    do {
        int cost = 0 + abs(as[ps[0]] - as[ps[1]]) + abs(as[ps[1]] - as[ps[2]]);
        min_cost = min(min_cost, cost);
    } while (next_permutation(ps.begin(), ps.end()));

    cout << min_cost << endl;
}

int main()
{
    ios::sync_with_stdio(false);

    for (int i = 0; i < 3; ++i)
        cin >> as[i];

    solve();

    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <iostream> 
#include <iomanip>  
#include <string>
#include <sstream>  
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <cstring>
#include <cmath>
#include <cassert>


#define INF              (int)1000000007
#define EPS              1e-9
#define pb               push_back
#define mp               make_pair
#define all(c)           c.begin(), c.end()
#define forall(i,a,b)    for(int i=a;i<(b);++i)
#define trav(a,x)        for(auto & a: x)
#define in(a,b)          ((b).find(a) != (b).end())
#define sz(c)            (int)(c).size()
#define input(a)         for(auto & x : a) cin >> x;

using namespace std;

typedef vector<int>      vi;
typedef pair<int,int>    ii;
typedef vector<vi>       vvi;
typedef vector<ii>       vii;
typedef long long        ll;

#ifdef DEBUG
#define trace(...)       __f(#__VA_ARGS__, __VA_ARGS__)
#define debug(args...)   {dbg,args; clog<<endl;}
#define print_( a )      for( auto & x : a ) clog << x << ' '; clog << '\n';
#define printPair_( a )  for( auto & x : a ) clog << '(' << x.first << ',' << x.second << ')' << ' '; clog << '\n';
#else
#define trace(...)       
#define debug(args...)            
#define print_( a )               
#define printPair_( a )           
#endif

struct debugger {
  template<typename T> debugger& operator , (const T& x) {    
    clog << x << " ";    return *this;    
  }
}dbg;

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << ": " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " | ";
    __f(comma + 1, args...);
}

auto ____ =[]() { std::ios::sync_with_stdio(0); cin.tie(0); return nullptr; }();

int main( int argc, char * argv[] ){
  int n, m; cin >> n >> m; 
  vi v(n); input(v);
  vi dp(m+1,0);
  forall(i,1,m+1){
    bool flag = false; // win
    for(auto x : v){ // if any of prv is lose,
      if( i-x < 0 ) continue;
      if( dp[i-x] == 0 ){
        flag = true;
        break;
      }
    }
    dp[i] = flag;
  }
  print_(dp);
  cout << ( dp[m] ? "First" : "Second" ) << endl;


  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  int m=0;
  int l=0;
  cin >> n ;
  vector<char>a(n);
  for (int i=0;i<n;i++) {
    cin >> a.at(i) ; 
    if(a[i]=='R'){
      m++;
    }
  }
  for (int i=0;i<m;i++) {
    if(a[i]=='W'){
      l++;
    }
  }
  cout << l << endl;
}

Measured memory_bytes: 3548
from math import ceil
from collections import deque
count = 0
ans = 0

N, D, A = map(int, input().split())
Monster = [0]*N
for i in range(N):
    Monster[i] = list(map(int, input().split()))
Monster = [[x, ceil(h/A)] for x, h in Monster]
Monster.sort()
que = deque([])

for x,h in Monster:
    # 範囲外となったダメージを削除する
    while que and x > que[0][0]:
        a, b = que.popleft()
        count -= b
    # 範囲内で既に起きたダメージを受ける
    need = max(0, h-count)
    ans += need
    count += need
    # 爆発が届く限界と起きた回数を記録しておく
    que.append([x + 2*D, need])
print(ans)


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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

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

int main(){
    ll N, L;
    cin >> N >> L;
    ll m = 1e10;
    ll s = 0;
    ll t = 0;
    REP(i, 1, N+1){
        s += L + i - 1;
    }
    REP(i, 1, N+1){
        ll a = abs(L+i-1);
        if(m>a){
            m = a;
            t = L + i - 1;
        }
    }
    cout << (s-t) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    if(n > 81)
    {
        cout << "No";
    }
    else
    {
        for(double i = 1.0;i <= 9;i++)
        {
            if(n / i == int(n / i) && n / i <= 9)
            {
                cout << "Yes";
                return 0;
            }
        }
        cout << "No";
    }
    
    return 0;
}

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

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


#define pb push_back
#define ff first
#define ss second
#define INF int(3e9)
#define BIG_INF ll(9e18)
#define SIZE 100001
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define len(v) int((v).size())
#define sqr(x) (x) * (x)
#define cube(x) (x) * (x) * (x)
#define filein freopen("input.txt", "r", stdin)
#define fileout freopen("output.txt", "w", stdout);


ll binpow(ll a, ll b, ll MOD = BIG_INF)
{
    ll res = 1;

    while(b)
    {
        if(b & 1)
            res *= a;
        a *= a;
        b >>= 1;
        a %= MOD;
        res %= MOD;
    }

    return res % MOD;
}

const ll mod = 1e9 + 7;


int T = 1;
int n, m;

ll h[SIZE], p[SIZE];
vector<int> g[SIZE];

vector<int> cnt, nxt;


bool OK = 1;


void dfs(int u, int pr, int kGood, int kBad)
{
    for(int v: g[u])
    {
        if(v == pr) continue;

        int good = 0, bad = 0;

        good = cnt[v] + h[v];
        good = (good + 1) / 2;
        bad = cnt[v] - good;
//        cout << good << ' ' << bad << '\n';
        if(good < 0 || bad < 0 || good - bad != h[v])
        {
            OK = 0;
            return;
        }
        kBad -= bad;
        kGood -= good;

        if(kGood < 0)
        {
            OK = 0;
            return;
        }


        if(kBad < 0)
        {
            int d = abs(kBad);
            if(d > kGood)
            {
                OK = 0;
                return;
            }
            kGood -= d;
            kBad = 0;
        }
//        cout << v << " " << good << ' ' << bad << " " << kGood << ' ' << kBad << "\n";
        dfs(v, u, good, bad);

    }

    if(kGood + kBad != p[u])
    {
        OK = 0;
    }
}

void calc(int u, int pr)
{
    for(int v: g[u])
    {
        if(v != pr)
        {
            calc(v, u);
            cnt[u] += cnt[v];
        }
    }

    cnt[u] += p[u];
}


void solve()
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    while(b <= a && k)
    {
        b *= 2;
        k--;
    }

    while(c <= b && k)
    {
        c *= 2;
        --k;
    }


    if(a < b && b < c)
    {
        cout << "Yes\n";
    }else cout << "No\n";

    return;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
//    filein;fileout;

//    cin >> T;
//
    while(T--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 5948
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int MOD = 1000000007;
int INF = numeric_limits<int>::max() / 2;


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

  int N, M;
  cin >> N >> M;
  vector<vector<int>> vec(M);
  for(int i=0;i<M;i++){
    int K;
    cin >> K;
    for(int j=0;j<K;j++){
      int a; cin >> a; a--;
      vec[i].push_back(a);
    }
  }
  int A[M];
  rep(i, M) cin >> A[i];

  int res = 0;
  for(int bit = 0; bit < (1<<N); bit++){
    bool ok = true;
    for(int i=0;i<M;i++){
      int con = 0;
      for(auto v : vec[i]){
        if(bit & (1<<v)) con++;
      }
      if(con % 2 != A[i]) ok = false;

    }
    if(ok) res++;

  }

  cout << res << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, n)cin >> h[i];
    vector<int> dp(n, 1001001001);
    dp[0] = 0;
    dp[1] = abs(h[0] - h[1]);
    for(int i = 2; i < n; i++){
        dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout << dp[n-1] << endl;
}

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

int main(){
  double n, m, d;
  cin >> n >> m >> d;
  cout << fixed << setprecision(10);
  if(d==0)cout << (m-1)/n;
  else cout << 2*(n-d)*(m-1)/(n*n);
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <vector>
#include<algorithm>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define vsort(v) sort(v.begin(), v.end())
#define ll long long
const ll MOD = 1e9 + 7;

int main() {
	int r, g, b;
	cin >> r >> g >> b;
	if ((100 * r + 10 * g + b) % 4 == 0)cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
from collections import Counter
import numpy as np
n = int(input())
ll = []
ans = 0
for _ in range(n):
    c = list(input())
    c.sort()
    ll.append("".join(c))
ans = np.sum([np.arange(v).sum() for v in Counter(ll).values() if v > 1])
print(int(ans))

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

using namespace std;

int main(void)
{
  // input
  string a, b;
  cin >> a >> b;
  string H = "H";
  string D = "D";
  
  if(a == H && b == H)
    printf("H\n");
  if(a == D && b == D)
    printf("H\n");
  if(a == D && b == H)
    printf("D\n");
  if(a == H && b == D)
    printf("D\n");
  
  return 0;
}


Measured memory_bytes: 256