akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
typedef long long ll;

template <class T> struct RangeAddFenwickTree {

   vector<T> node1, node2;
   RangeAddFenwickTree (int n) : node1(n,0), node2(n,0) {}

    void add(int l, int r, T val) {
      for (int i = l; i < node1.size(); i |= i + 1) {
         node1[i] += -l * val;
         node2[i] += val;
      }
      for (int i = r; i < node1.size(); i |= i + 1) {
         node1[i] += r * val;
         node2[i] += -val;
      }
   }

   T sum(int idx) {
      T sum1 = 0, sum2 = 0;
      for (int i = idx; i >= 0; i = (i & (i + 1)) - 1) {
         sum1 += node1[i];
         sum2 += node2[i] * idx;
      }
      return sum1 + sum2;
   }

};

int main() {
 
  int n,q; cin >> n >> q;
 
  RangeAddFenwickTree<ll> inst(100010);
  REP(i,q) {
    ll com,s,t,x;
    cin >> com;
    if(com == 0) {
      cin >> s >> t >> x;
      inst.add(s,t+1,x);
    } else {
      cin >> s >> t;
      cout << inst.sum(t+1) - inst.sum(s) << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 4416
// 7/4 Tuesday
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main() {
	int n,ans,x=0,kizon=0;
	int color[8] = {};
	cin >> n;
	vector <int> rate(n);
	for (int i = 0; i < n; i++) {
		cin >> rate[i];
	}

	for (int i = 0; i < n; i++) {
		if (rate[i] <= 399) { color[0] = 1; }
		else if (rate[i] <= 799) { color[1] = 1; }
		else if (rate[i] <= 1199) { color[2] = 1; }
		else if (rate[i] <= 1599) { color[3] = 1; }
		else if (rate[i] <= 1999) { color[4] = 1; }
		else if (rate[i] <= 2399) { color[5] = 1; }
		else if (rate[i] <= 2799) { color[6] = 1; }
		else if (rate[i] <= 3199) { color[7] = 1; }
		else x++;
	}

	for (int i = 0; i < 8; i++) {
		if (color[i] == 1) { kizon++; }
	}

	if (kizon == 0) { kizon = 1; ans = x; }
	else  ans = kizon + x;

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

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

def main():
    N = int(input())
    p = [int(i) for i in input().split()]
    ans = 0
    for i in range(N-1):
        if p[i] == i + 1 and p[i+1] == i+2:
            p[i], p[i+1] = p[i+1], p[i]
            ans += 1
    for i in range(N-1):
        if p[i] == i + 1:
            p[i], p[i+1] = p[i+1], p[i]
            ans += 1
    if p[N - 1] == N:
        p[N-2], p[N-1] = p[N-1], p[N-2]
        ans += 1
    print(ans)
if __name__=="__main__":
    main()

Measured memory_bytes: 19908
#include<algorithm>
#include<iostream>
#include<vector>

using namespace std;

int main(){
  vector<int> a(10, 0);
  for (int i = 0; i < 10; i++){
    cin >> a[i];
  }
  sort(a.begin(), a.end(), greater<int>());
  cout << a[0] << endl << a[1] << endl << a[2] << endl;
}

Measured memory_bytes: 1208
X, Y, N = map(int, input().split())
lst = [[0 for i in range(X)] for j in range(Y)]

for i in (range(N)):
    x, y, a = map(int, input().split())
    if a == 1:
        for j in range(Y):
            for k in range(x):
                lst[j][k] = 1
    elif a == 2:
        for j in range(Y):
            for k in range(X-1, x-1, -1):
                lst[j][k] = 1
    elif a == 3:
        for j in range(y):
            for k in range(X):
                lst[j][k] = 1
    elif a == 4:
        for j in range(Y-1, y-1, -1):
            for k in range(X):
                lst[j][k] = 1

count = 0
for i in lst:
    count += i.count(0)
print(count)



Measured memory_bytes: 9172
N = int(input())
r = [list(map(int,input().split())) for _ in range(N)]
b = [list(map(int,input().split())) for _ in range(N)]
r.sort(key = lambda x:x[1],reverse = True)
b.sort(key = lambda x:x[0])
cnt = 0
fin = []
for i in range(N):
    for j in range(N):
        if b[i][0] > r[j][0] and b[i][1] > r[j][1]:
            if not(j in fin):
                cnt += 1
                fin.append(j)
                break
print(cnt)

Measured memory_bytes: 3064
h,w=map(int,input().split())
c=[list(map(int,input().split())) for _ in range(10)]
a=[list(map(int,input().split())) for _ in range(h)]

for k in range(10):
  for i in range(10):
    for j in range(10):
      c[i][j]=min(c[i][j],c[i][k]+c[k][j])
ans=0
for i in range(h):
  for j in range(w):
    if a[i][j]==-1:continue
    ans+=c[a[i][j]][1]
print(ans)

Measured memory_bytes: 9568
/* monkukui 競技プログラミング用のテンプレート  (ここから) */
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
using ll = long long int;
using lnt = long long int;
using graph = vector<vector<int>>;
using wgraph = vector<vector<pair<int, long long int>>>;
long long int INF = 1001001001001001LL;
int inf = 100100100;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;
long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
inline void yes(){ cout << "yes" << endl; }
inline void Yes(){ cout << "Yes" << endl; }
inline void YES(){ cout << "YES" << endl; }
inline void no(){ cout << "no" << endl; }
inline void No(){ cout << "No" << endl; }
inline void NO(){ cout << "NO" << endl; }
inline void possible(){ cout << "possible" << endl; }
inline void Possible(){ cout << "Possible" << endl; }
inline void POSSIBLE(){ cout << "POSSIBLE" << endl; }
inline void impossible(){ cout << "impossible" << endl; }
inline void Impossible(){ cout << "Impossible" << endl; }
inline void IMPOSSIBLE(){ cout << "IMPOSSIBLE" << endl; }

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for(int i = s; i < t; i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back

/* monkukui 競技プログラミング用のテンプレート (ここまで)*/

int main(){
  
  int a, b, c; cin >> a >> b >> c;

  for(int t = 0; t <= 10000000; t++) {
    if((60 * t + c) % (a + b) <= a) {
      cout << 60 * t + c << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}



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


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

using namespace std;
using ll = long long;


int main()
{
	int n; cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i++)cin >> a[i];

	int cnt = 0;

	for(int i = 0; i < n;) {
		int j = i;
		while(a[j] == a[i] && j < n) {
			j++;
		}
		cnt += (j - i) / 2;
		i = j;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int[] x = new int[n];

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

        sc.close();

        int ans = 0;

        for (int i = 0; i < n; i++) {
            int A = Math.abs(0 - x[i]);
            int B = Math.abs(k - x[i]);

            if (A < B) {
                ans += A * 2;
            } else {
                ans += B * 2;
            }
        }

        System.out.println(ans);
    }
}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;
long long int n,cnt=0,ans=0,a[ohara],b[ohara],c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
  
       cin.tie(0);
    ios::sync_with_stdio(false);
      
      cin>>n;
      rep(i,n){
        cin>>a[i];
        b[i]=a[i];
      }
      sort(a,a+n);
      cmp=a[n/2];
      cmpp=a[n/2-1];
      rep(i,n){
        if(cmp==b[i])Cout(cmpp);
        else if(cmpp==b[i])Cout(cmp);
        else{
          if(cmp<b[i])Cout(cmpp);
          else Cout(cmp);
        }
        //cout<<cmp<<" "<<cmpp<<"\n";
      }
    
       
return 0;
}


Measured memory_bytes: 7936
use std::io;

fn main() {
    let _ = read_vec::<i32>();
    let mut a = read_vec::<i32>();
    let len = a.len();

    let count = merge_sort(&mut a, 0, len);
    // print_vec(a);
    println!("{}", count);
}

pub fn merge(a: &mut [i32], left: usize, mid: usize, right: usize) -> usize {
    let mut count = 0;
    let mut l = a[left..mid].to_vec();
    let mut r = a[mid..right].to_vec();
    // 番兵の挿入
    l.push(std::i32::MAX);
    r.push(std::i32::MAX);
    let mut i = 0;
    let mut j = 0;
    for k in left..right {
        if l[i] <= r[j] {
            a[k] = l[i];
            i += 1;
        } else {
            // 左のi番目と右のj番目を入れ替える
            a[k] = r[j];
            j += 1;
            count += mid - left - i;
        }
    }
    count
}

pub fn merge_sort(a: &mut [i32], left: usize, right: usize) -> usize {
    let mut count = 0;
    if left + 1 < right {
        let mid = (left + right) / 2;
        count += merge_sort(a, left, mid);
        count += merge_sort(a, mid, right);
        count += merge(a, left, mid, right);
    }
    count
}

/// 標準入力から一行を読み取り、空白文字で分割し、各要素を指定の型に変換する関数
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut line = String::new();
    io::stdin().read_line(&mut line)
        .ok()
        .expect("Faild to read Vec");
    line.trim().split_whitespace()
        .map(|i| i.parse().ok().unwrap()).collect()
}



Measured memory_bytes: 9016
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
	    
	    int N = scanner.nextInt();
	    int K = scanner.nextInt();
	    if(K>N) {
	    	System.out.println(0);
	    }else {
	    List<Integer> list = new ArrayList<Integer>();
	    for(int i=0;i< N;i++){
	    	list.add(i,scanner.nextInt());
	    }
	    Collections.sort(list,Collections.reverseOrder());
	     long sum = 0;
	     for(int i = K;i < N; i++) {
	    	 sum = list.get(i) + sum;
	     }
	     System.out.println(sum);
	}
	}
}


Measured memory_bytes: 92516
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const int MOD=1e9+7;
 

vector<ll> divisor(ll n) {
    vector<ll> res;
    int sn=sqrt(n);
    if (n%sn==0) ++sn;
    repr(i,1,sn) {
        if (n%i==0) {
            res.push_back(i);
            if (i!=n/i) res.push_back(n/i);
        }
    }
    sort(res.begin(),res.end());
    return res;
}


int main() {
    ll n;
    cin >> n;
    vector<ll> dv1=divisor(n);
    vector<ll> dv2=divisor(n-1);
    int ans=dv2.size()-1;
    repr(i,1,dv1.size()) {
        ll m=n;
        while (m%dv1[i]==0) m/=dv1[i];
        if (m%dv1[i]==1) ++ans;
    }
    cout << ans << endl;

}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
#include <climits>
#define LIM 1000007
#define ll long long
using namespace std;
int main() {
  string s;
  vector<bool> v;
  cin >> s;
  for (int i = 0; i < 'z' - 'a' + 1; i++) {
    v.push_back(false);
  }
  for (char c : s) {
    v[c - 'a'] = !v[c - 'a'];
  }
  for (bool b : v) {
    if (b) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

INF = 1000000

s = int(input())
a = [s] * (INF + 1)

answer = 0

for i in range(INF):
    if a[i] % 2 == 0:
        a[i+1] = int(a[i] / 2)
    else:
        a[i+1] = 3 * a[i] + 1
    for j in range(0,i):
        if a[i] == a[j]:
            answer = i+1
            break
    if answer != 0:
        break

print(answer)


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

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

  for (int i = 0; i < n; i++) {
  ans = ans + s.at(i) + t.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
l,r=map(int,input().split())
ans=2019*2020
if r-l+1<2019:
  if r%2019<l%2019:
    print(0)
  else:
    for i in range(l,r):
      for j in range(i+1,r+1):
        res = i%2019 * j%2019
        if res<ans:
          ans=res
    print(ans)
    
else:
  print(0)
  exit()

Measured memory_bytes: 3060
require 'set'

n, m, tax = gets.strip.split.map(&:to_i)
abc = readlines.map {|line| line.strip.split.map(&:to_i) }
abc = abc.map {|a, b, c| [a, b, -1*(c-tax)] }

graph = Array.new(n+1) { [] }
r_graph = Array.new(n+1) { [] }
abc.each do |a, b, c|
  graph[a] << b
  r_graph[b] << a
end

# get available nodes, and edges
def reachable(s, g)
  q = [s]
  visited = Set.new(q)
  until q.empty?
    c=q.shift
    g[c].each do |to|
      next if visited.include?(to)
      visited.add(to)
      q.push(to)
    end
  end
  visited
end

from_1 = reachable(1, graph)
from_n = reachable(n, r_graph)
available_nodes = from_1 & from_n
edges = abc.select {|a, b, c| available_nodes.include?(a) && available_nodes.include?(b) }

# v-f
INF = 10**12
updated=false
dist = Array.new(n+1, INF)
dist[1]=0
n.times do
  updated = false
  edges.each do |from, to, cost|
    next if dist[from]==INF
    if dist[to] > dist[from] + cost
      dist[to] = dist[from] + cost
      updated=true
    end
  end
  break unless updated
end

if updated
  p -1
  exit
end

# answer
p [-dist[n], 0].max



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

int a[200005];

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int n;
	cin >> n;
	for(int i=1;i<=n;i++)cin >> a[i];
	long long ans=0;
	for(int i=2;i<=n;i++){
		if(a[i]<a[i-1]){
			ans+=(a[i-1]-a[i]);
			a[i]=a[i-1];
		}
	}
	cout << ans << '\n';
	return 0;
}



Measured memory_bytes: 4336
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
#define rep(i, n) for (int i=1;i <= (int)n;i++)
int n, m;
typedef long long ll;
ll a;
typedef long long ll;
priority_queue<ll>P;

int main(){
  cin >> n >> m;
  rep(i, n){
    cin >> a;
    P.push(a);
  }

  rep(i, m){
    ll b = P.top();
    P.pop();
    b = b / 2;
    P.push(b);
  }
  ll total = 0;
  rep(i, n){
    int t = P.top();
    P.pop();
    total += t;
  }
  cout << total << endl;
}


Measured memory_bytes: 1400
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())

ct, cx, cy = (0, 0, 0)

ok = True
for i in range(N):
    t, x, y = map(int, input().split())

    d = abs(cx - x) + abs(cy - y)
    dt = t - ct

    if d > dt or (d - dt) % 2 == 1:
        ok = False
    ct, cx, cy = t, x, y

print("Yes" if ok else "No")


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


int main()
{
    int a,b; cin >> a>>b;
    string s; cin>>s;
    if(s[a] != '-') cout << "No" << endl;
    else{
        bool y = true;
        for(int i = 0; i< a;i++) if(s[i] == '-') y = false;
        for(int i = a + 1; i< a + b + 1;i++) if(s[i] == '-') y = false;
        cout << (y?"Yes":"No")<< endl;
    }
    return 0;
    
}

Measured memory_bytes: 256
package main

import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}

func MaxInt(A ...int32) int32 {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}

func Factorial(N int) (F, Finv, Inv []int) {
  F = make([]int, N + 1)
  Finv = make([]int, N + 1)
  Inv = make([]int, N + 1)
  F[0] = 1
  F[1] = 1
  Finv[0] = 1
  Finv[1] = 1
  Inv[0] = 1
  Inv[1] = 1
  for i := 2; i < N + 1; i++ {
    F[i] = F[i - 1] * i % p
    Inv[i] = p - Inv[p % i] * (p / i) % p
    Finv[i] = Finv[i - 1] * Inv[i] % p
  }
  return
}

func Pow(x, n int) int {
  k := 1
  for _n := n; 0 < _n; k++ {
    _n /= 2
  }
  P := make([]int, k)
  P[0] = x
  for i := range P[1:] {
    P[i + 1] = P[i] * P[i] % p
  }
  xn := 1
  for i, _n := 0, n; 0 < _n; i++ {
    if _n % 2 == 1 { xn = xn * P[i] % p }
    _n /= 2
  }
  return xn
}

const p = 1000003

func Solve() {
  var Q int
  NextInt(&Q)
  F, Finv, Inv := Factorial(p - 1)
  var x, d, n int
  for i := 0; i < Q; i++ {
    NextInt(&x, &d, &n)
    if d == 0 {
      Write(Pow(x, n))
      continue
    }
    X := x * Inv[d] % p
    if X == 0 || p < X + n {
      Write(0)
      continue
    }
    Write(Pow(d, n) * (F[X + n - 1] * Finv[X - 1] % p) % p)
  }
  return
}

func main() {
  Solve()
  Output()
}

Measured memory_bytes: 43392
a = int(input())
b = int(input())
c = int(input())
x = int(input())/50

count = 0
for i in range(a+1):
 if 10*i>x: break
 for j in range(b+1):
  if 10*i+2*j>x: break
  for k in range(c+1):
   if 10*i+2*j+k == x:
    count += 1

print(count)


Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template
int a[3] = {300000, 200000, 100000};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    ll sum = 0;
    ll ans = 1LL << 62;
    rep(i, N) sum += A[i];
    ll cur = 0;
    rep(i, N) {
        cur += A[i];
        ll rem = sum - cur;
        ans = min(ans, abs(cur - rem));
    }
    output(ans);
    
    
    return 0;
}


Measured memory_bytes: 1792
import numpy as np
W,H,N=map(int,input().split())
A=np.zeros((W,H))
B=[list(map(int,input().split())) for _ in range(N)]
for b in B:
    if b[2]==1:
        A[:b[0],:]=1
    elif b[2]==2:
        A[b[0]:,:]=1
    elif b[2]==3:
        A[:,:b[1]]=1
    elif b[2]==4:
        A[:,b[1]:]=1
print(np.count_nonzero(A==0))

Measured memory_bytes: 27240
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, m; cin >> n >> m;
	vector<int> a(n);
	for(int &i: a) cin >> i;

	bool flg=1;
	int cnt=0, sum=accumulate(a.begin(),a.end(),0);
	sort(a.begin(),a.end(),greater<int>());
	for(int i=0; i<m; ++i){
		if(a[i]*4*m<sum){
			flg=0;
			break;
		}
	}
	cout << (flg==1? "Yes" : "No") << endl;
}

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

int main(){
  int n;
  cin >> n;
  int h[n];
  for(int i=0;i<n;i++){
    cin >> h[i];
  }
  int ans = 0;
  int active = 0;
  for(int i=0;i<n;i++){
    // cout << ans << active << endl;
    if(active >= h[i]){
      active = h[i];
    }
    else{
      ans += h[i]-active;
      active = h[i];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <string>

using namespace std;

int q;
int main() {
	cin >> q;
	for (int i = 0; i < q; i++) {
		string x, y;
		cin >> x >> y;
		int m = x.size();
		int n = y.size();
		x = ' ' + x;
		y = ' ' + y;
		int maxl = 0;
		int c[1001][1001];
		c[0][0] = 0;
		for (int i = 1; i <= m; i++) {
			c[i][0] = 0;
		}
		for (int j = 1; j <= n; j++) {
			c[0][j] = 0;
		}
		for (int i = 1; i <= m; i++) {
			for (int j = 1; j <= n; j++) {
				if (x[i] == y[j]) {
					c[i][j] = c[i-1][j-1] + 1;
				} else {
					c[i][j] = max(c[i][j - 1], c[i - 1][j]);
				}
				maxl = max(maxl, c[i][j]);
			}
		}
		cout << maxl << endl;
	}
	return 0;
}

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

int main(void){
    string s;
    int sum = 0;
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        sum += s[i] - '0';
        sum %= 3;
    }
    if(sum % 3 == 0){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3748
#include <stdio.h>
#include <stdlib.h>
#define N 100001
#define NIL -1

typedef struct {
	int parent;
	int leftChild;
	int rightSilbing;
} Node;

Node node[N];
int depth, n;

void initNode(Node* node) {
	int i;

	for (i = 0; i < n; i++) {
		node[i].parent = NIL;
		node[i].leftChild = NIL;
		node[i].rightSilbing = NIL;
	}

}

int getDepth(int d) {

	if (node[d].parent == NIL) {
		return 0;
	}

	if (node[node[d].parent].parent != NIL) {
		depth++;
		getDepth(node[d].parent);
	}

	return depth;
}

int judgeNode(Node node) {

	if (node.parent == NIL) {
		return 0;
	}

	if (node.parent != NIL && node.leftChild != NIL) {
		return 1;
	} else if (node.leftChild == NIL) {
		return -1;
	}

	return 0;
}

void displayNode(int id) {
	int nodeType;

	depth = 1;
	printf("node %d: parent = %d, depth = %d, ", id, node[id].parent, getDepth(id));

	nodeType = judgeNode(node[id]);

	switch (nodeType) {
	// nodeが内部ノードの場合
	case 1:
		printf("internal node, [%d", node[id].leftChild);
		while (node[node[id].leftChild].rightSilbing != NIL) {
			printf(", %d", node[node[id].leftChild].rightSilbing);
			node[id].leftChild = node[node[id].leftChild].rightSilbing;
		}
		break;
	// nodeがリーフの場合
	case -1:
		printf("leaf, [");
		break;
	// nodeがルートの場合
	case 0:
		printf("root, [");
		if (node[id].leftChild != NIL) {
			printf("%d", node[id].leftChild);
			while (node[node[id].leftChild].rightSilbing != NIL) {
				printf(", %d", node[node[id].leftChild].rightSilbing);
				node[id].leftChild = node[node[id].leftChild].rightSilbing;
			}
		}
		break;
	}
	printf("]\n");
}

int main() {
	int nodeId, k, child, sibling;
	int i, j;

	scanf("%d", &n);

	initNode(node);

	for (i = 0; i < n; i++) {
		scanf("%d %d", &nodeId, &k);
		if (k == 0) {
			continue;
		}
		for (j = 0; j < k; j++) {
			scanf("%d", &child);
			node[child].parent = nodeId;
			if (j == 0) {
				node[nodeId].leftChild = child;
			} else {
				node[sibling].rightSilbing = child;
			}
			sibling = child;
		}
	}

	for (i = 0; i < n; i++) {
		displayNode(i);
	}

	return 0;
}

Measured memory_bytes: 1784
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  for(int i=0;i<s.size();i++){
    if(i%2==1){
      if('R'==s[i]){
        cout << "No" << endl;
        return 0;
      }
    }else{
      if('L'==s[i]){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 3624
from heapq import heappop, heappush


def main():
    n, c = map(int, input().split())
    program = [[] for _ in range(c)]
    for _ in range(n):
        s, t, cc = map(int, input().split())
        cc -= 1
        s *= 2
        t *= 2
        program[cc].append([s - 1, t])
    all_p = []
    for i in range(c):
        if len(program[i]) == 0:
            continue
        now = program[i]
        now.sort(key=lambda x: x[1])
        last_begin, last_end = now[0]
        for begin, end in now[1:]:
            if begin + 1 == last_end:
                last_end = end
            else:
                all_p.append([last_begin, last_end, i])
                last_begin = begin
                last_end = end
        all_p.append([last_begin, last_end, i])
    all_p.sort()
    q = [(-1, -1)]
    for begin, end, now_channel in all_p:
        last_end, last_channel = q[0]
        if last_end < begin or now_channel == last_channel:
            heappop(q)
        heappush(q, (end, now_channel))
    print(len(q))


if __name__ == '__main__':
    main()


Measured memory_bytes: 35388
#include<bits/stdc++.h>
using namespace std;
long long k,_min,_max,x_y,x[2],fib[2],a,i;double mid;
#define MOD 1000000007
int dp[3];
int main(){
    cin>>k;
    a=sqrt(k)/16;
    x_y=(long long)(2*sqrtl(k-a-0.01))-1;
    _max=(x_y+2)*(x_y+2)/4;
    _min=(x_y+1)*(x_y+1)/4+1;
    mid=1.0*(_max+_min)/2;
    if(k<=mid){x[1]=(k-_min)*2;}
    else{x[1]=(_max-k)*2+1;}
    x[0]=x_y-x[1];
    
    if(x[0]<3){
        fib[0]=x[0]+1;
    }
    else{
        dp[0]=1;
        dp[1]=2;
        dp[2]=3;
 
        for(i=3;i<=x[0];i+=3)
        {
            dp[0]=(dp[1]+dp[2])%MOD;
            dp[1]=(dp[2]+dp[0])%MOD;
            dp[2]=(dp[0]+dp[1])%MOD;
        }
 
        fib[0]=dp[x[0]%3];
    }
    if(x[1]<3)
    {
        fib[1]=x[1]+1;
    }
    else{
        dp[0]=1;
        dp[1]=2;
        dp[2]=3;
 
        for(i=3;i<=x[1];i+=3)
        {
            dp[0]=(dp[1]+dp[2])%MOD;
            dp[1]=(dp[2]+dp[0])%MOD;
            dp[2]=(dp[0]+dp[1])%MOD;
        }
 
        fib[1]=dp[x[1]%3];
    }
 
    cout<<(fib[0] * fib[1])%MOD<<endl;
}

Measured memory_bytes: 3092
import heapq

num_V, num_E = map(int, input().split())
E = [[] for _ in range(num_V)]
for _ in range(num_E):
	ts,tt,tw = map(int, input().split())
	E[ts].append([tt,tw])
	E[tt].append([ts,tw])

flg = [0] * num_V
ans = []
q = []
heapq.heappush(q,[0,0])

while q:
	cd, cp = heapq.heappop(q)
	if flg[cp] == 0:
		flg[cp] = 1
		ans.append(cd)
	else:
		continue

	for np, nd in E[cp]:
		if flg[np] == 0:
			heapq.heappush(q,[nd, np])

print(sum(ans))



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

typedef long long int ll;

#define endl '\n'

int main()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);


    ll n,x;

    cin>>n>>x;

    ll arr[n+1];

    for(ll i=0;i<n;i++)cin>>arr[i];

    ll pre = 0;
    ll ans = 0;
    if(pre<=x)
        ans++;


    for(ll i=0;i<n;i++)
    {
        pre = pre+arr[i];

        if(pre<=x)
            ans++;


    }

    cout<<ans<<endl;


}


Measured memory_bytes: 256
#include <stdio.h>

#define H 500000

int parent(int);
int left(int);
int right(int);
void maxHeapify(int *, int);
void buildMaxHeap(int *);

int h;

int main()
{

  int i;
  int A[H];


  scanf("%d", &h);

  for(i=1; i<=h; i++){
    scanf("%d", &A[i]);
  }

  buildMaxHeap(A);

  for(i=1; i<=h; i++){ 
    printf(" %d",A[i]);
  }

  printf("\n");

  return 0;
}

int left(int i){

  return 2 * i;
  
}

int right(int i){

  return 2 * i + 1;

}

void maxHeapify(int *A, int i){

  int l, r, tmp, largest;

  l = left(i);
  r = right(i);

  if((l <= h) && (A[l] > A[i]))
    largest = l;
  else largest = i;

  if((r <= h) && (A[r] > A[largest]))
    largest = r;

  if(largest != i){
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    maxHeapify(A, largest);
  }

}

void buildMaxHeap(int *A){

  int i, x;

  x = h / 2;

  for(i=x; i>=1; i--){
    maxHeapify(A, i);
  }

}

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

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
using namespace std;

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

int main(void)
{
	ll n,l[10000]={},x[4]={};//0..x 1..end a 2...start b 3...both
	ll ans=0;
	string s[10000];
	cin >> n;
	rep(i,n){
		cin>>s[i];
		l[i]=s[i].size();
		if(s[i].back()=='A' && s[i].front()=='B') x[3]++;
		else if(s[i].back()=='A') x[1]++;
		else if(s[i].front()=='B') x[2]++;
		else x[0]++;
		rep(j, l[i]-1){
			if(s[i][j]=='A' && s[i][j+1]=='B') ans++;
		}
	}
	ans+=(x[3]+min(x[1],x[2]))-(x[3]!=0&&x[1]+x[2]==0);
	cout << ans << endl;
	return 0;
}

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

using namespace std;

typedef pair<int, int> P;
typedef long long ll;

int N, K;
int A[100];




int main(){
    for (int i = 0; i < 100; i++)
    {
        A[i] = 0;
    }
    

    cin >> N >> K;
    for(int i = 0; i < K; i++){
        int d;
        cin >> d;

        for (int j = 0; j < d; j++)
        {
            int a;
            cin >> a;
            A[a - 1] = 100;
        }
        
    }
    int ret = 0;
    for (int i = 0; i < N; i++)
    {   
        if(A[i] == 0) ret ++;
    }

        cout << ret << endl;

    return 0;

}

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

int main() {
  int N;
  cin >> N;
  vector<int>H(N);
  for(int i=0;i<N;i++){
    cin >> H.at(i);
  }
  int count = 0;
  int highest =0;
  for(int i =0;i<N;i++){
   if(highest <= H.at(i)){
     count ++;
     highest = H.at(i);
   }
  }
  cout << count << endl;
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in(),T=in();
	vector<pair<int,int>> C(T+1,make_pair(0,0));
	LOOP(N){
		int L=in(),R=in();
		C[L].first++;
		C[R].second++;
	}

	int sum=0,msum=0;
	REP(i,T+1){
		sum += C[i].first-C[i].second;
		msum = max(msum,sum);
	}

	out(msum);
	return 0;
}


Measured memory_bytes: 3616
A = int(input())
B = int(input())
C  =int(input())
X = int(input())
count = 0

for i in range(A + 1):
    total = i * 500
    if total == X:
        count += 1
        continue
    if total > X:
        break

    for j in range(B + 1):
        total = i * 500
        total += j * 100

        if total == X:
            count += 1

        if total > X:
            break

        for k in range(1,C + 1):
            total += 50

            if total == X:
                count += 1


            if total > X:
                break
print(count)




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

using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<int> x1(N), y1(N), x2(N), y2(N), xv, yv;
    set<int> xs, ys;
    rep(i, N) {
        cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
        xs.insert(x1[i]);
        xs.insert(x2[i]);
        ys.insert(y1[i]);
        ys.insert(y2[i]);
    }
    for (auto i : xs) xv.push_back(i);
    for (auto i : ys) yv.push_back(i);
    map<int, int> xm, ym;
    int m = xv.size(), n = yv.size();
    rep(i, xv.size()) xm[xv[i]] = i;
    rep(i, yv.size()) ym[yv[i]] = i;
    vector<vector<int>> d(m + 1, vector<int>(n + 1, 0));
    rep(i, N) {
        d[xm[x1[i]]][ym[y1[i]]]++;
        d[xm[x1[i]]][ym[y2[i]]]--;
        d[xm[x2[i]]][ym[y1[i]]]--;
        d[xm[x2[i]]][ym[y2[i]]]++;
    }
    /*
    rep(i, m + 1) {
        rep(j, n + 1) {
            cout << d[i][j];
        }
        cout << "\n";
    }
    cout << "\n";
    */
    vector<vector<int>> s(m + 1, vector<int>(n + 1, 0));
    rep(i, m) {
        rep(j, n) {
            s[i][j + 1] = s[i][j] + d[i][j];
        }
    }
    /*
    rep(i, m + 1) {
        rep(j, n + 1) {
            cout << s[i][j];
        }
        cout << "\n";
    }
    cout << "\n";
    */
    vector<vector<int>> t(m + 1, vector<int>(n + 1, 0));
    rep(j, n) {
        rep(i, m) {
            t[i + 1][j] = t[i][j] + s[i][j];
        }
    }
    /*
    rep(i, m + 1) {
        rep(j, n + 1) {
            cout << t[i][j];
        }
        cout << "\n";
    }
    cout << "\n";
    */
    ll ans = 0;
    rep(i, m - 1) {
        rep(j, n - 1) {
            if (t[i + 1][j + 1] > 0) {
                ans += 1LL * (xv[i + 1] - xv[i]) * (yv[j + 1] - yv[j]);
            }
        }
    }
    cout << ans << "\n";
    /*
    rep(i, m) cout << xv[i] << " ";
    cout << "\n";
    rep(i, n) cout << yv[i] << " ";
    cout << "\n";
    */
}


Measured memory_bytes: 191576
a = list(map(int, input().split()))
count = 0
while True:
    a.sort(reverse=True)
    max_elem_count = a.count(max(a))
    if max_elem_count == len(a):
        break
    elif max_elem_count == 2:
        a[2] += 2
    elif max_elem_count == 1:
        a[1] += 1
        a[2] += 1
    count += 1
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int INF (1<<30);
const ll mod = 1e9+7;

int main() {
  int N; cin >> N;
  vector<int> A(N);
  rep(i,N) cin >> A[i];
  vector<int> dp(N+1, 0);


  ll ans = 3LL;
  if (A[0] != 0) ans = 0LL;
  dp[0]++;

  for (int i = 1; i < N; i++) {

    if (A[i] == 0) {
      if (dp[0] == 1) ans *= 2LL;
      dp[0]++;
    } else {
      int r = dp[A[i]];
      int l = dp[A[i]-1];
      ans *= (ll)(l-r); 
      dp[A[i]]++;
    }

    if (dp[A[i]] > 3) ans = 0LL;

    ans %= mod;
  }

  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 10100000
#define INF 1e15
#define MAP 110
#define initial_value -1
#define LINF 1LL << 60
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
ll n,a,b,ans;
ll ch[100] = {0};
vector<Pair> r,br;
int main(){
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a >> b;
        r.push_back({b,a});
    }
    for(int i = 0; i < n; i++){
        cin >> a >> b;
        br.push_back({a,b});
    }
    sort(r.begin(),r.end());
    sort(br.begin(),br.end());
    reverse(r.begin(),r.end());
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(br[i].second > r[j].first && br[i].first > r[j].second && ch[j] == 0){
                ch[j] = 1;
                break;
            }
        }
    }
    for(int i = 0; i < 100; i++){
        ans += ch[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
N = int(input())
A = [int(x) for x in input().strip().split()]

for a in A:
    if a % 2:
        continue
    if a % 3 != 0 and a % 5 != 0:
        print('DENIED')
        exit()
else:
    print('APPROVED')


Measured memory_bytes: 2940
import networkx as nx

n = int(input())
graph = nx.DiGraph()
AB = [list(map(int, input().split())) for _ in range(n)]
CD = [list(map(int, input().split())) for _ in range(n)]

start = 10 ** 4
goal = 10 ** 4 + 1
for i in range(n):
    a, b = AB[i]
    graph.add_edge(start, i, weight=0, capacity=1)
    for j in range(n):
        c, d = CD[j]
        graph.add_edge(200 + j, goal, weight=0, capacity=1)
        if c > a and d > b:
            graph.add_edge(i, 200 + j, weight=0, capacity=1)

ans = nx.maximum_flow(graph, start, goal, capacity="capacity")
print(ans[0])



Measured memory_bytes: 56584
#include<stdio.h>
#define max 1000000
int main()
{
	char furui[max];
	int n=2,i,end,ans;
	
	for(i=0;i<max;i++)
	{
		furui[i]=1;
	}
	furui[0]=0;
	while(n<=max)
	{
		if(furui[n-1]==1)
		{
			for(i=n*2;i<=max;i+=n)
			{
				furui[i-1]=0;
			}
		}
		n++;
	}
		
	while(scanf("%d",&end)!=EOF)
	{
		ans=0;
		for(i=0;i<end;i++)
		{
			if(furui[i]==1)
			{
				ans++;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1380
#include <iostream>
#include <cstring>
#include <stdio.h>
#include <cmath>
using namespace std;
const int N=1e5+200;
int n,k,oo,h[N];
int memo[N];
int dp(int i)
{
    if(i>n)
        return oo;
    if(i==n)
        return 0;
    int &ret=memo[i];
    if(ret!=oo)
        return ret;
    for (int j=1;j<=k;++j)
    ret=min(dp(i+j)+abs(h[i]-h[i+j]),ret);
        return ret;

}
int main()
{
    memset(memo,'?',sizeof memo);
    oo=memo[0];

    scanf("%d %d",&n,&k);
    for(int i=1;i<=n;++i)
    {
         scanf("%d",h+i);
    }
    printf("%d\n",dp(1));
    return 0;
}


Measured memory_bytes: 10652
#include<stdio.h>

int main(void)
{
  int n,m,X,Y;
  scanf("%d%d%d%d",&n,&m,&X,&Y);

  int i,x[n],y[m];
  for(i=0;i<n;i++){
    scanf("%d",&x[i]);
    if(X<x[i])
      X = x[i];
  }
  for(i=0;i<m;i++){
    scanf("%d",&y[i]);
    if(Y>y[i])
      Y = y[i];
  }

  if(X>=Y)
    printf("War\n");
  else
    printf("No War\n");

  return 0;
}

Measured memory_bytes: 1592
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;

long long GCD(long long a, long long b) {
    if(b == 0)
        return a;
    else
        return GCD(b, a % b);
}
long long LCM(long long a, long long b) {
    long long g = GCD(a, b);
    return a / g * b;
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> p(M);
    vector<string> s(M);
    vector<pair<int, int>> ten(N);
    rep(i, 0, M) {
        int pp;
        cin >> pp;
        p[i] = pp - 1;
        cin >> s[i];
    }
    rep(i, 0, N) {
        ten[i].first = 0;
        ten[i].second = 0;
    }
    int ac = 0;
    int pe = 0;
    rep(i, 0, M) {
        if(s[i] == "AC") {
            if(ten[p[i]].first == 0) {
                ac++;
                pe += ten[p[i]].second;
                ten[p[i]].first = 1;
            }
        } else {
            if(ten[p[i]].first == 0) {
                ten[p[i]].second++;
            }
        }
    }
    cout << ac << " " << pe << endl;
}


Measured memory_bytes: 6912
#include <cstdio>
#include <vector>
#include <queue>

struct segtree {
private:
    std::vector< std::vector<int> > array;
    int n, m;
public:
    segtree(int N, int M) {
        n = m = 1;
        while(n <= N) n *= 2;
        while(m <= M) m *= 2;
        array.resize(2*n-1, std::vector<int>(2*m-1));
    }

    // add
    void add(int x, int y, int val) {
        int nx = x+n-1;
        y += m-1;
        while(y >= 0) {
            x = nx;
            array[x][y] += val;
            while(x > 0) {
                x = (x - 1) / 2;
                array[x][y] += val;
            }
            if(y == 0) break;
            y = (y - 1) / 2;
        }
    }

    // x-query
    int query(int x1, int y1, int x2, int y2, int l=0, int r=-1, int k=0) {
        if(r < 0) r = n;
        if(x2 <= l || r <= x1) return 0;
        if(x1 <= l && r <= x2) return query2(y1, y2, k);
        int mid = (l + r) / 2;
        int vl = query(x1, y1, x2, y2, l, mid, 2*k+1);
        int vr = query(x1, y1, x2, y2, mid, r, 2*k+2);
        return vl + vr;
    }

    // y-query
    int query2(int y1, int y2, int x, int l=0, int r=-1, int k=0) {
        if(r < 0) r = m;
        if(y2 <= l || r <= y1) return 0;
        if(y1 <= l && r <= y2) return array[x][k];
        int mid = (l + r) / 2;
        int vl = query2(y1, y2, x, l, mid, 2*k+1);
        int vr = query2(y1, y2, x, mid, r, 2*k+2);
        return vl + vr;
    }
};

struct Elem {
    int x, y, time;
};

int H, W, T, Q;

int main() {
    scanf("%d%d%d%d", &H, &W, &T, &Q);
    std::queue<Elem> que;
    segtree noeat(H, W), caneat(H, W);

    for(int i=0; i<Q; i++) {
        int t, q; scanf("%d%d", &t, &q);
        while(!que.empty()) {
            Elem cur = que.front();
            if(cur.time + T <= t) {
                que.pop();
                noeat.add(cur.x, cur.y, -1);
                caneat.add(cur.x, cur.y, 1);
            }
            else break;
        }
        
        if(q == 0 || q == 1) {
            int h, w; scanf("%d%d", &h, &w);
            h--; w--;
            if(q == 0) {
                noeat.add(h, w, 1);
                que.push(Elem{h, w, t});
            }
            else {
                int val = caneat.query(h, w, h+1, w+1);
                if(val != 0) caneat.add(h, w, -1);
            }
        }
        else {
            int h1, w1, h2, w2; scanf("%d%d%d%d", &h1, &w1, &h2, &w2);
            h1--; w1--;
            int ans_noeat  = noeat.query(h1, w1, h2, w2);
            int ans_caneat = caneat.query(h1, w1, h2, w2);
            printf("%d %d\n", ans_caneat, ans_noeat);
        }
    }
    return 0;
}


Measured memory_bytes: 134960
N,K = map(int,input().split())

sunuke = [i+1 for i in range(N)]

for i in range(K):
    d = int(input())
    A = list(map(int,input().split()))
    for a in A:
        if sunuke[a-1] != 0:
            sunuke[a-1] = 0

ans = 0
for i in sunuke:
    if i != 0:
        ans += 1

print(ans)

Measured memory_bytes: 9128
#include<stdio.h>
#include <iostream>

using namespace std;

#define BUF_SIZE 1024

class Stack{
public:
	Stack(int stack_size):
		m_index(0){
		m_array = new int[stack_size];
		m_size = stack_size;
	};
	~Stack(){
		delete[] m_array;
	};
	void push(int var){
		m_array[m_index] = var;
		m_index++;
	};
	int pop(){
		m_index--;
		return m_array[m_index];
	};

	bool isEmpty(){	//?????????true
		return m_index == 0;
	};

private:
	int m_size;
	int* m_array;
	int m_index;
};

int main(){
	char buf[BUF_SIZE];


	for(int i = 0; i < BUF_SIZE; i++){
		buf[i] = 'e';
	}
	fgets(buf,BUF_SIZE,stdin);

	Stack stack(BUF_SIZE);	//?????????????????????

	bool numFLG = false;
	int S = 0,op1=0,op2=0;

	for(int i = 0;buf[i] != 'e'; i++){
		if(buf[i] >= '0' && buf[i] <= '9'){	//??°?????§????????´???
			numFLG = true;
			S = 10*S + (buf[i] - '0');//?????????????????????
		}else{

			if(numFLG){	//??°????????????????????????????????£?????´???
				stack.push(S);
				S = 0;
				numFLG = false;
			}


			if(buf[i] == '+'){
				op2 = stack.pop();
				op1 = stack.pop();
				stack.push(op1+op2);
			}else if(buf[i] == '-'){
				op2 = stack.pop();
				op1 = stack.pop();
				stack.push(op1-op2);
			}else if(buf[i] == '*'){
				op2 = stack.pop();
				op1 = stack.pop();
				stack.push(op1*op2);
			}//????????????????£???°???
		}
	}

	op1 = stack.pop();
	cout << op1 << endl;
}

Measured memory_bytes: 1168
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	cout<<(regex_match(s,regex(".*keyence|k.*eyence|ke.*yence|key.*ence|keye.*nce|keyen.*ce|keyenc.*e|keyence.*"))?"YES":"NO")<<endl;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AtCoder solver = new AtCoder();
        solver.solve(1, in, out);
        out.close();
    }

    static class AtCoder {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();

            out.println((a + b) % 24);
        }

    }
}



Measured memory_bytes: 23380
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
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;
}
void print() { std::cout << '\n'; }
void vprint() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
template <class H, class... T> void vprint(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << '\n';
    vprint(std::forward<T>(args)...);
}
template <class T> void vprint(std::vector<T> &v) {
    for (auto &&i : v) {
        std::cout << i << '\n';
    }
}
template <class T> void mprint(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << "";
        }
    }
}

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

    int N;
    cin >> N;
    vector<int> a(N);
    for (auto &&i : a) {
        cin >> i;
    }
    SORT(a);
    int ans = 0;
    REP(i, N) {
        int cnt = upper_bound(ALL(a), a[i] + 2) - lower_bound(ALL(a), a[i]);
        chmax(ans, cnt);
    }
    print(ans);

    return 0;
}

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

s = list(input())

if s[k-1] == "A":
    s[k-1] = "a"
elif s[k-1] == "B":
    s[k-1] = "b"

elif s[k-1] == "C":
    s[k-1] = "c"


for i in range(len(s)):
    print(s[i], end="")

print()

Measured memory_bytes: 3060