akhauriyash/Code-Regression huggingface dataset:
n, m = gets.split.map(&:to_i)
P = []
for i in 1..n
  P[i] = {ac: 0, penalty: 0}
end
for i in 0..m-1
  p, s = gets.split
  if P[p.to_i][:ac] == 0
    if s == 'AC'
      P[p.to_i][:ac] = 1
    else
      P[p.to_i][:penalty] += 1
    end
  end
end
acCount = 0
penCount = 0
P.each do |x|
  next if x == nil
  acCount += x[:ac]
  penCount += x[:penalty] if x[:ac] == 1
end
puts "#{acCount} #{penCount}"


Measured memory_bytes: 31868
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let v = read_vec::<i32>();
    let a = v[0];
    let b = v[1];
    println!("{}", std::cmp::max(a - b * 2, 0));
}


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

#define mod 1'000'000'007
typedef long long ll;

template<typename T>
void deb(initializer_list<T> l)
{
	for (auto &e : l)
		cout << e << ' ';
	cout << endl;
}

ll divide(ll &n, ll i)
{
	ll cnt = 0;
	while (n % i == 0)
	{
		n /= i;
		++cnt;
	}
	return cnt;
}

void solve()
{
	ll n;
	cin >> n;

	ll temp = n;
	ll ans = 0;
	for (ll i = 2; i * i <= n; ++i)
	{
		if (temp % i != 0)
			continue;
		ll cnt = divide(temp, i);
		ll x = (-1 + sqrt(1 + 8 * cnt)) / 2;
		ans += x;
	}

	if (temp > 1)
		++ans;
	cout << ans << '\n';
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	int t = 1;
	// cin >> t;
	while (t--)
		solve();

	return 0;
}


Measured memory_bytes: 3696
/** omgursocute **/
#include <bits/stdc++.h>

using namespace std;
typedef int64_t ll;
typedef uint64_t ull;
typedef long double ld;

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

	int n;
	cin >> n;
	int a[n];

	int ct = 0;
	int res = 0;
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < n-1; i++) {
		if(a[i] < a[i+1]) {
			res = max(res, ct);
			ct = 0;
		}
		else ++ct;
	}

	cout << max(res, ct);

	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << " ms.\n";
}

// g++ o .cpp -O2 -std=c++11 -D cute -Wall -Wno-unused-result



Measured memory_bytes: 640
#include <iomanip>
#include <limits>
#include <thread>
#include <utility>
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <numeric>
#include <cassert>
#include <random>
#include <chrono>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <list>
#include <functional>
#include <bitset>
#include <complex>
#include <tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double D;
typedef complex<D> P;
const ll E = 1e18 + 7;
const ll MOD = 1000000007;
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define fill(x, y) memset(x, y, sizeof(x))
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
template <class... A>
void prints() { cout << endl; }
template <class... A>
void prints_rest() { cout << endl; }
template <class T, class... A>
void prints_rest(const T &first, const A &... rest) { cout << " " << first; prints_rest(rest...); }
template <class T, class... A>
void prints(const T &first, const A &... rest) { cout << first; prints_rest(rest...); }

template <class T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

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

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

    vector<int> ans(N, 0);

    int nowodd = 0, noweven = 0;
    int l = 0;
    rep(i, N) {
        char c = S[i];
        if ( c == 'L' ) {
            if (l%2 == 0) {
                ans[i] += noweven;
                ans[i-1] += nowodd;
            } else {
                ans[i] += nowodd;
                ans[i-1] += noweven;
            }
            noweven = 0;
            nowodd = 0;
            l = 0;
        } else {
            if (l % 2 == 0){
                ++noweven;
            }
            else {
                ++nowodd;
            }
            ++l;
        }
    }

    nowodd = 0;
    noweven = 0;
    l = 0;

    for (int i = N-1; i >= 0; --i) {
        char c = S[i];
        if (c == 'R')
        {
            if (l % 2 == 0)
            {
                ans[i] += noweven;
                ans[i+1] += nowodd;
            }
            else
            {
                ans[i] += nowodd;
                ans[i+1] += noweven;
            }
            noweven = 0;
            nowodd = 0;
            l = 0;
        }
        else
        {
            if (l % 2 == 0)
            {
                ++noweven;
            }
            else
            {
                ++nowodd;
            }
            ++l;
        }
    }

    rep(i, N) {
        cout << ans[i] << " ";
    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 1104
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)



int main(){
	int n,m,x;
	cin >> n >> m >> x;
	vector<vector<int>>in;
	REP(i,n){
		vector<int> tmp(m+1);
		REP(j,m+1){
			int input;
			
			cin >> tmp[j];
			
		}
		in.push_back(tmp);
	}
	
	int nedan = (int)1e+7;
	for(int bit=0; bit<(1<<n); ++bit){
		vector<int> takahashi(m,0);
		int tmp_nedan=0;
		REP(i,n){
			if(bit & (1<<i)){
				tmp_nedan += in[i][0];
				REP(j,m){
					takahashi[j] += in[i][j+1];
				}
			}
		}
		
		int tassei = 1;
		REP(j,m){
			if(takahashi[j] < x){
				tassei = 0;
			}
		}
		if(tassei){
			nedan = min(tmp_nedan,nedan);
		}
	}
	
	if(nedan==(int)1e+7){
		cout << "-1\n";
	}else{
		cout << nedan << endl;
	}
	
	return 0;
	
}

Measured memory_bytes: 3636
import sys

# 関数 solve は，もちろん，問題に応じて書き換える
def solve(a,b,c,d):
    x = c-a
    y = d-b
    x3 = 0
    x4 = 0
    y3 = 0
    y4 = 0
    #print(x,y)
    x3 = c-y
    y3 = d+x
    x4 = x3-x
    y4 = y3-y
    return str(x3) + ' '  + str(y3) + ' ' + str(x4) + ' ' + str(y4) + ' '

# ここから下は，入力・出力形式が同じであれば，変えなくて良い．
def readQuestion():
    line = sys.stdin.readline().rstrip()
    [str_a, str_b, str_c, str_d] = line.split(' ')
    return (int(str_a), int(str_b), int(str_c), int(str_d))

def main():
    a, b, c, d = readQuestion()
    answer = solve(a, b, c, d)
    print(answer)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h> 
 
using namespace std;
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
const long INF=LONG_MAX;

struct edge{int to;long double cost;};
typedef pair<long double,int> P;//firstは最短距離,secondは頂点番号

const int MAX_V=1003;
int V;

vector<edge> G[MAX_V];
long double d[MAX_V];

void dijkstra(int s){
    priority_queue<P,vector<P>,greater<P> > que;
    fill(d,d+V,INF);
    d[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
        P p=que.top();que.pop();
        int v=p.second;
        if(d[v]<p.first)continue;
        REP(i,G[v].size()){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}

int main(){
    long x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    int N;cin>>N;
    long x[1003],y[1003],r[1003];
    map<pair<long,long>,int>mp;
    REP(i,N){
        cin>>x[i]>>y[i]>>r[i];
        mp[MP(x[i],y[i])]=i;
    }
    if(mp.find(MP(x1,y1))==mp.end()){
        mp[MP(x1,y1)]=N;
        x[N]=x1;y[N]=y1;r[N]=0;
        N++;
    }
    if(mp.find(MP(x2,y2))==mp.end()){
        mp[MP(x2,y2)]=N;
        x[N]=x2;y[N]=y2;r[N]=0;
        N++;
    }
    V=N;
    for(int i=0;i<N;i++)for(int j=i+1;j<N;j++){
        long double dx,dy;
        dx=x[i]-x[j];dy=y[i]-y[j];
        long double dd=max((long double)0.0,sqrt(dx*dx+dy*dy)-(r[i]+r[j]));
        G[i].PB(edge{j,dd});G[j].PB(edge{i,dd});
    }
    dijkstra(mp[MP(x1,y1)]);
    cout<<fixed<<setprecision(10)<<d[mp[MP(x2,y2)]]<<endl;
    return 0;
}


Measured memory_bytes: 42988
N , T = map(int, input().split())
l =[]
for index in range(N):
    n , t  =map(int ,input().split())
    l .append([n,t])
ans = []
for elt in l :
    if elt[1]<=T :
        ans.append(elt[0])
if ans == []:
    print("TLE")
else:
    print(min(ans))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <math.h>
typedef long long ll;
using namespace std;

int main() {
	ll n,ans=0,sum=0,l1,l2;
	string s,s1,s2;
	cin>>n>>s;
	ll a[30]={0};
	for(int i=1;i<n;i++){
		s1=s.substr(0,i);
		s2=s.substr(i,n-i);
		l1=s1.length();
		l2=s2.length();
		for(int j=0;j<l1;j++){
			a[s1[j]-'a']=-1;
		}
		for(int j=0;j<l2;j++){
			if(a[s2[j]-'a']==-1){
				a[s2[j]-'a']=1;
			}
		}
		for(int j=0;j<30;j++){
			if(a[j]==1){
				sum++;
			}
		}
		ans=max(ans,sum);
		sum=0;
	}
	cout << ans<<endl;
 	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String temp = sc.next();
    String[] str = {"SAT","FRI","THU","WED","TUE","MON","SUN"};
    for(int i=0;i<7;i++){
      if(str[i].equals(temp)) System.out.println(i+1);
    }
  }
}


Measured memory_bytes: 21972
import java.util.Scanner;
import java.util.TreeMap;

class Main {
    private static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
       int n = scan.nextInt();
       int[] ar = new int[n];
        for (int i = 0; i < n; i++) {
            ar[i] = scan.nextInt();
        }

        TreeMap<Integer,Integer> ax = new TreeMap<>();

        for (int i = 0; i < ar.length; i++) {
            Integer x = ax.get(ar[i]);
            ax.put(ar[i],x==null?1:x+1);
        }

        int result = 0;
       while (!ax.isEmpty()){
            Integer cur = ax.lastKey();
            if(ax.get(cur) == 1){
                ax.remove(cur);
            }else{
                ax.put(cur,ax.get(cur)-1);
            }

            int pos = 1;
            while (pos <= cur) pos*=2;
            int need = pos-cur;
            Integer got = ax.get(need);
            if(got == null){
                continue;
            }
            result++;
            if(got == 1){
                ax.remove(need);
            }else{
                ax.put(need,got-1);
            }
       }

        System.out.println(result);
    }
}

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

#define count_ones __builtin_popcountl
#define all(a) a.begin(), a.end()
#define gcd(a, b) __gcd(a, b)
#define lca(a, b) a / __gcd(a, b) * b
typedef long long ll;
typedef long double ld;
using namespace std;

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

    ll n;
    cin >> n;
    vector<int> b(n - 1);
    for (ll i = 0; i < n - 1; i++) cin >> b[i];
    vector<int> res(n, 0);
    res[0] = b[0];
    for (ll i = 1; i < n - 1; i++) {
        res[i] = min(b[i - 1], b[i]);
    }
    res[n - 1] = b[n - 2];
    ll total = 0;
    for (ll i = 0; i < n; i++) {
        total += res[i];
    }
    cout << total;

    return 0;
}

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

int main() {
  int n,k,pp = -1;
  bool pf = false;
  ll ans = 1e16;
  cin >> n >> k;
  vector<ll>data(n);
  for(int i = 0;i < n;i++){
    cin >> data[i];
    if(data[i] > 0 && !pf){
      pp = i;
      pf = true;
    }
  }
  if(pp == -1){
    cout << abs(data[n-k]) << endl;
    return 0;
  }
  if(pp == 0){
    cout << data[k-1] << endl;
    return 0;
  }
  for(int i = 0;i < n;i++){
    if(i+k-1 < pp-1) continue;
    if(i+k-1 == n) break;
    if(i <= pp-1){
      ans = min(ans,abs(2*data[i])+data[i+k-1]);
      ans = min(ans,abs(data[i])+2*data[i+k-1]);
    }
    if(i == pp){
      ans = min(ans,data[i+k-1]);
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**7) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import deque, defaultdict

n,m = li()
mod = 10**7

table = defaultdict(set)
visit = defaultdict(int)

for i in range(m):
    a,b,c = li()
    
    table[a].add(a + c*mod)
    table[b].add(b + c*mod)
    table[a + c*mod].add(a)
    table[b + c*mod].add(b)
    table[a + c*mod].add(b + c*mod)
    table[b + c*mod].add(a + c*mod)
    
    visit[a] = 0
    visit[b] = 0
    visit[b + c*mod] = 0
    visit[a + c*mod] = 0
    
que = deque()
que.append((1,0))

visit[1] = 1
ans = mod

while que:
    x, cost = que.popleft()
    visit[x] = 1
    
    if x == n:
        ans = min(ans, cost)
        break
    
    for y in table[x]:
        if visit[y] == 1:
            continue
        
        if x <= 10**5 and mod <= y:
            que.append((y, cost+1))
            
        else:
            que.appendleft((y, cost))
        
print(-1 if ans == mod else ans)


Measured memory_bytes: 214252
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;

int main()
{
	int n, a, b;
	cin >> n;
	if (n == 1)
	{
		cout << "Hello World" << endl;
	}
	else
	{
		cin >> a >> b;
		cout << a + b << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 100005;

int n, m;
int permutation[MAX_N];
int parent[MAX_N];
int treeSize[MAX_N];

int leader(int u)
{
	return parent[u] == u ? u : parent[u] = leader(parent[u]);
}

void unite(int u, int v)
{
	u = leader(u);
	v = leader(v);
	if (u == v)
		return;
	if (treeSize[u] >= treeSize[v])
	{
		parent[u] = v;
		treeSize[v] += treeSize[u];
	}
	else
	{
		parent[v] = u;
		treeSize[u] += treeSize[v];
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		cin >> permutation[i];
		permutation[i]--;
	}
	for (int i = 0; i < n; i++)
	{
		parent[i] = i;
		treeSize[i] = 1;
	}
	for (int i = 0; i < m; i++)
	{
		int u, v;
		cin >> u >> v;
		u--; v--;
		unite(u, v);
	}

	int result = 0;
	for (int i = 0; i < n; i++)
		if (leader(i) == leader(permutation[i]))
			result++;
	cout << result << endl;
}

Measured memory_bytes: 1408
#include<stdio.h>

#define MAX  500
static const int INFTY = (1<<21);

int H[MAX],n,bbb=1;
int NOT(int k){
  int i;
  for(i=0;i<bbb;i++){
    if(H[i]==k)return 0;
  }
  return 1;
}

main(){
  int i, j, e, sum,min,k;
  int V[MAX][MAX];
  int M[MAX];
  int aaa=0;
  H[0]=0;
  int flag=0;

  scanf("%d", &n);

  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      scanf("%d", &e);
      V[i][j] = (e==-1)?INFTY:e;
    }
  }
  i=0;
  while(i<n){
    min=INFTY;
    for(j=0;j<bbb;j++){
      for(k=0;k<n;k++){
	if(NOT(k) && V[H[j]][k]<min){
	  min=V[H[j]][k];
	  flag=k;
	}
      }
    }
    M[i]=min;
    H[bbb]=flag;
    bbb++;
    i++;
  }

  sum = 0;
  
  for ( i = 0; i < n-1; i++ ){
    sum+=M[i];
  }
  
  printf("%d\n",sum);
  
  return 0;
}

Measured memory_bytes: 800
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}
func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0
	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	a := getNextInt(scanner)
	b := getNextInt(scanner)
	if a >= 13 {
		fmt.Fprintln(writer, b)
		return
	}
	if a >= 6 {
		fmt.Fprintln(writer, b>>1)
		return
	}
	fmt.Fprintln(writer, 0)
}


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

using namespace std;

#define vi vector<int>
#define pb push_back
#define ll long long
#define qi queue<int>
#define vll vector<long long>
#define si set<int>
#define mi map<int,int>
#define mod %
#define pow ^
#define frt(i,a,b) for(int i=a;i<b;i++)
#define fre(i,a,b) for(int i=a;i<=b;i++)
#define pair_int pair<int,int>
#define pair_ll pair<ll,ll>
#define pq priority_queue
#define N 100007

ll dp[N];


int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);

   int n,mx;
   cin >> n >> mx;

   ll w[n+1];
   ll c[n+1];

   for(int i=1;i<=n;i++)
   {
   	  cin >> w[i] >> c[i];
   }

   for(int i=1;i<=n;i++)
   {
   	  for(int j=N;j>c[i];j--)
   	  {
   	  	 if(dp[j-c[i]]!=0)
   	  	 {
   	  	 	if(dp[j]==0)
   	  	 	{
   	  	 		dp[j] = dp[j-c[i]] + w[i];
   	  	 		
   	  	 		if(dp[j] > mx)
   	  	 			dp[j] = 0;
   	  	 	}
   	  	 	else
   	  	 	{
   	  	 		dp[j] = min(dp[j], dp[j-c[i]] + w[i]);
   	  	 	}
   	  	 }
   	  }
   	  if(dp[c[i]]==0)
   	  	dp[c[i]] = w[i];
   	  else
   	  	dp[c[i]] = min(w[i],dp[c[i]]);
   }

   int ans=0;
   for(int i=1;i<=N;i++)
   {
   	  if(dp[i]!=0)
   	  	ans = i;
   }
   cout << ans << endl;

   return 0;
}


  


Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

int main(void)
{
    cin.sync_with_stdio(false);
    int N, M;
    cin >> N >> M;



    vector<int> ac_flags(N);
    vector<int> wa_count(N);

    int ac = 0;
    REP(m, M) {
        int p; string s;
        cin >> p >> s;
        --p;
        if (ac_flags[p]) continue;

        if (s == "WA") {
            ++wa_count[p];
        }
        else {
            ac_flags[p] = 1;
            ++ac;
        }
    }

    int wa = 0;
    REP(n, N) {
        if (ac_flags[n]) wa += wa_count[n];
    }
    cout << ac << " " << wa << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(998244353)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	int n; cin>>n;
	vector<PII> p,z,m;
	rep(i,n){
		string s; cin>>s;
		int u=0, b=0, now=0;
		rep(j,s.size()){
			if(s[j]=='(') now++;
			else now--;
			chmax(u,now); chmin(b,now);
		}
		if(now>0) p.PB(MP(b,now));
		else if(now<0) m.PB(MP(b-now,now));
		else z.PB(MP(b,now));
	}
	sort(RALL(p)); sort(ALL(m)); sort(ALL(z));

	int now=0;
	bool flg=true;
	rep(i,p.size()){
		if(now+p[i].first<0) flg=false;
		now+=p[i].second;
		// cerr<<p[i].first<<' ';
	}
	cerr<<endl;
	if(z.size())if(now+z[0].first<0) flg=false;
	// if(z.size())cerr<<z[0].first<<endl;
	rep(i,m.size()){
		now+=m[i].second;
		if(now+m[i].first<0) flg=false;
		// cerr<<m[i].first<<' ';
	}
	cerr<<endl;
	if(now!=0) flg=false;
	if(flg) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 11280
unittest
{
	assert( [ "1900" ].solve == 100 );
	assert( [ "3000" ].solve == 0 );
}



import std.conv;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	
	n %= 1000;
	if( n == 0 ) return 0L;
	else         return 1000 - ( n % 1000 );
}


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

#define pb push_back
#define mk make_pair
#define lob lower_bound
#define upb upper_bound
#define fst first
#define scd second

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

inline int read(){
	int f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
inline ll readll(){
	ll f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int k,n,ans[505][505];
int main() {
	k=read();
	if(k==1)return printf("%d\n%d\n",1,1),0;
	n=ceil(k/2.0);
	//cout<<n<<endl;
	assert(n<=500);
	if(!(n&1)){
		if(k&1){
			for(int i=n-1,j=0;i>=0;--i,++j)ans[i][j]=1;
			for(int st=1,num=2;st<n;++st,num+=2){
				for(int i=n-1,j=st;i>=0;--i,j=(j+1)%n)if(i&1)ans[i][j]=num;else ans[i][j]=num+1;
			}
		}else{
			for(int st=0,num=1;st<n;++st,num+=2){
				for(int i=n-1,j=st;i>=0;--i,j=(j+1)%n)if(i&1)ans[i][j]=num;else ans[i][j]=num+1;
			}
		}
	}else{
		++n;
		if(k&1){
			for(int st=0,num=1;num<=3;++st,num++){
				for(int i=n-1,j=st;i>=0;--i,j=(j+1)%n)ans[i][j]=num;
			}
			for(int st=3,num=4;st<n;++st,num+=2){
				for(int i=n-1,j=st;i>=0;--i,j=(j+1)%n)if(i&1)ans[i][j]=num;else ans[i][j]=num+1;
			}
		}else{
			for(int st=0,num=1;num<=2;++st,num++){
				for(int i=n-1,j=st;i>=0;--i,j=(j+1)%n)ans[i][j]=num;
			}
			for(int st=2,num=3;st<n;++st,num+=2){
				for(int i=n-1,j=st;i>=0;--i,j=(j+1)%n)if(i&1)ans[i][j]=num;else ans[i][j]=num+1;
			}
		}
	}
	printf("%d\n",n);
	for(int i=0;i<n;++i){
		for(int j=0;j<n;++j)printf("%d ",ans[i][j]);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 2176
#include<cstdio>
#include<iostream>
using namespace std;
const int MAXN=105;
bool flag[MAXN];
int main(){
	int n;
	scanf("%d",&n);
	flag[0]=true;
	for(int i=0;i<=n;++i){
		if(flag[i]==false) continue;
		if(i+4<=n) flag[i+4]=true;
		if(i+7<=n) flag[i+7]=true;
	}
	if(flag[n]) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,m,a[1001],b[1001],i,j,x,z;
	scanf("%d %d",&n,&m);
	for(i=0;i<m;i++){
		scanf("%d %d",&a[i],&b[i]);
	}
	for(i=0;i<m;i++){
		for(j=i+1;j<m;j++){
			if(a[i]<=a[j]){
				x=a[i];
				a[i]=a[j];
				a[j]=x;
			}
		}
	}
	z=0;
	for(i=0;i<m-1;i++){
		// printf("%d\n",a[i]);
		if(a[i]<=n)	z+=n-a[i];
	}
	printf("%d\n",z);
	return 0;
}
			


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

int main()
{
    int a[5];

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

    }
    sort(a,a+3);
    if(a[2]==a[0]+a[1])cout<<"Yes";
    else cout<<"No";
    return 0;
}


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

int main(){
  ll x,k,d;
  cin >> x >> k >> d;
  x = abs(x);
  if(x/d - k >= 0){
    cout << x-(k*d) << endl;
  }
  else{
    ll memo = x/d;
    k -= memo;
    x %= d;
    if(k%2 == 0){
      cout << x << endl;
    }
    else {
      cout << d-x << endl;
    }
  }
  
  return 0;
}


Measured memory_bytes: 3544
#include<iostream>
#include<vector>

using namespace std;

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

int N, M;
vector<vector<int>> E;
bool visited[100000];

int main() {
	cin >> N >> M;
	E.resize(N);
	for (int i = 0; i < M; i++) {
		int A, B;
		cin >> A >> B;
		A--, B--;
		E[A].push_back(B);
		E[B].push_back(A);
	}

	int l = 0, r = E[0][0];//-1になったらループに入ってる判定
	int befl = r, befr = l;
	visited[l] = true, visited[r] = true;
	vector<int> ansl, ansr;
	ansl.push_back(l), ansr.push_back(r);
	while (true) {
		//expends a
		bool updatel = false, updater = false;
		for (int i = 0; i < E[l].size(); i++) {
			if (E[l][i] == befl)continue;
			
			if (!visited[E[l][i]]) {
				visited[E[l][i]] = true;
				ansl.push_back(E[l][i]);
				befl = l;
				l = E[l][i];
				updatel = true;
				break;
			}
		}
		for (int i = 0; i < E[r].size(); i++) {
			if (E[r][i] == befr)continue;

			if (!visited[E[r][i]]) {
				visited[E[r][i]] = true;
				ansr.push_back(E[r][i]);
				befr = r;
				r = E[r][i];
				updater = true;
				break;
			}
		}
		if (!updatel && !updater)break;
	}

	cout << ansl.size() + ansr.size() << endl;
	for (int i = ansl.size() - 1; i >= 0; i--) {
		cout << ansl[i] + 1 << " ";
	}
	for (int i = 0; i < ansr.size(); i++) {
		cout << ansr[i] + 1 << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 6972
#include<bits/stdc++.h>
#pragma O3
#define int long long
using namespace std;
const int N=6000,mod=1e9+7;
int dp[N][N],l;
signed main(){
//	freopen(".inp","r",stdin);
//	freopen(".out","w",stdout);
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;
	string s;
	cin>>n>>s;
	l=s.length();
	dp[0][0]=1;
	for(int i=1;i<=n;i++){
		dp[i][0]=(dp[i-1][0]+dp[i-1][1])%mod;
		for(int j=1;j<=n;j++){
			dp[i][j]=(dp[i-1][j-1]*2+dp[i-1][j+1])%mod;
		}
	}
	for(int i=1;i<=l;i++){
		dp[n][l]=(dp[n][l]*(mod+1)/2)%mod;
	}
	cout<<dp[n][l];
}


Measured memory_bytes: 235648
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
signed main(){
    ll N, M; cin>>N>>M;
    vector<ll> A(N);
    priority_queue<ll> pq;
    REP(i, N) {
        cin >> A[i];
        pq.push(A[i]);
    }
    REP(i, M){
        ll x = pq.top(); pq.pop();
        pq.push(x/2);
    }
    ll res = 0;
    while(!pq.empty()){
        ll x = pq.top(); pq.pop();
        res += x;
    }
    cout << res << endl; 
    return 0;
    return 0;
}

Measured memory_bytes: 2168
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 200200;
typedef long long ll;
const int mod = 998244353;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
int r, c, n;
struct node {
	int x, y;
	inline int good() const {
		if(x == 0) return y + 1;
		if(y == c) return x + c + 1;
		if(x == r) return r + c + c - y + 1;
		if(y == 0) return r + r + c + c - x + 1;
		return 0;
	}
} a[maxn], b[maxn];
int stack[maxn], top;
std::mt19937 rd(time(0));
inline bool ok(std::vector<std::pair<int, int>> v) {
	if(v.empty()) return 1;
	std::vector<std::pair<int, int>> v0, v1;
	std::swap(v[rd() % v.size()], v.front());
	int L = v[0].first, R = v[0].second;
	for(int i = 1;i < v.size();++i) {
		if(L <= v[i].first && v[i].second <= R) {
			v0.push_back(v[i]);
		} else {
			if(L < v[i].first && v[i].first < R || L < v[i].second && v[i].second < R) return 0;
			v1.push_back(v[i]);
		}
	}
	return ok(v0) && ok(v1);
}
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> r >> c >> n;
	std::vector<std::pair<int, int>> v;
	rep(i, 1, n) {
		cin >> a[i].x >> a[i].y >> b[i].x >> b[i].y;
		int x = a[i].good(), y = b[i].good();
		if(x > y) std::swap(x, y);
		if(x && y) v.emplace_back(x, y);
	}
	cout << (ok(v) ? "YES" : "NO") << '\n';
}


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

const int N = 500005;
const int base1 = 12345678, ibase1 = 749734780, mod1 = 998244353;
const int base2 = 90123456, ibase2 = 314509124, mod2 = 1000000007;
typedef long long LL;
typedef std::pair<int, int> hashing;
#define x first
#define y second

const hashing base(base1, base2);
const hashing ibase(ibase1, ibase2);

int add(int x, int y, int mod) { x += y - mod; return x + (x >> 31 & mod); }
int minus(int x, int y, int mod) { x -= y; return x + (x >> 31 & mod); }

hashing operator * (const hashing &lhs, const hashing &rhs) {
	return {(LL) lhs.x * rhs.x % mod1, (LL) lhs.y * rhs.y % mod2};
}
hashing operator + (const hashing &lhs, const hashing &rhs) {
	return {add(lhs.x, rhs.x, mod1), add(lhs.y, rhs.y, mod2)};
}
hashing operator - (const hashing &lhs, const hashing &rhs) {
	return {minus(lhs.x, rhs.x, mod1), minus(lhs.y, rhs.y, mod2)};
}
hashing rshift(hashing h) { return h * base; }
hashing lshift(hashing h) { return h * ibase; }

hashing pow_[N], *power = pow_ + 250000, target, backup, prefix[N];
std::map<hashing, int> map;

int n;
std::string s;
LL ans = 0;

typedef std::pair<int, hashing> tag; // X <- base^x * X + y

tag inv(tag t) { return {-t.x, hashing(0, 0) - power[-t.x] * t.y}; }
hashing apply(tag t, hashing h) { return h * power[t.x] + t.y; }

tag alltag;

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n >> s, power[0] = hashing(1, 1);
	for (int i = 1; i <= n; ++i) power[i] = power[i - 1] * base;
	for (int i = 1; i <= n; ++i) power[-i] = power[1 - i] * ibase;
	for (int i = 0, p = 0; i < n; ++i) {
		if (s[i] & 1)
			target = s[i] == 43 ? target + power[p] : target - power[p];
		else
			p += s[i] == 60 ? -1 : 1;
	}
	for (int i = n - 1; ~i; --i) {
		++map[apply(inv(alltag), hashing(0, 0))];
		if (s[i] & 1) alltag.y = alltag.y + (s[i] == 43 ? hashing(1, 1) : hashing(mod1 - 1, mod2 - 1));
		else alltag.y = alltag.y * (s[i] == 60 ? ibase : base), alltag.x += s[i] == 60 ? -1 : 1;
		ans += map[apply(inv(alltag), target)];
	}
	std::cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 37524
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define MOD 1000000007
#define int int64_t
signed main(){
  int N;
  cin>>N;
  vector<int> A(6);
  rep(i,0,5) cin>>A[i];
  A[5]=1000000000000001;
  int time=0,sum=N;
  rep(i,0,5){sum==0?
             time++:
             time+=(sum-1)/A[i]+1;
             sum%=A[i];
             //cout<<time<<endl;
             if(A[i]>A[i+1]){
                 int Y=A[i+1]*(time-i-1);
                 if(Y<N-sum) sum+=N-sum-Y;
               }
             //cout<<sum<<endl;
  }
  cout<<time<<endl;
}

Measured memory_bytes: 256
#D
#バケットnum[v]:=A1,A2,...,Anの中に値vが何個あるか　を作って考える
n = int(input())
a = list(map(int,input().split()))
q = int(input())
#合計を計算しておく
sum_a = sum(a)
#バケットの作成
v = [0 for _ in range(10**5)]
for i in range(n):
    v[a[i]-1] += 1
# main loop    
for i in range(q):
    b,c = map(int,input().split())
    sum_a += (c - b)* v[b-1]
    v[c-1] += v[b-1]
    v[b-1] = 0
    print(sum_a)

Measured memory_bytes: 20800
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    long long x;
    cin >> x;

    long long ans = x / 11 * 2;
    if(6 < x % 11)
        ans += 2;
    else if(0 < x % 11)
        ++ ans;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int a[N],b[N],c[N*3],d[N*3],n;
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(int i=0;i<n;i++)
		scanf("%d",&b[i]);
	for(int i=0;i<n;i++)
		c[i]=a[i]^a[(i+1)%n],c[i+n*2]=c[i+n]=b[i]^b[(i+1)%n];
	int j;d[0]=c[n]=j=-1;
	for(int i=0;i<3*n;d[++i]=++j)
		while(j>=0&&c[i]!=c[j])
			j=d[j];
	for(int i=0;i<n;i++)
		if(d[n*3-i]==n)
			printf("%d %d\n",i,a[i]^b[0]);
	return 0;
} 


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

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = ReadLineIntSpilit();



            var list = new List<int>();

            for (int i = 0; i < n[1]; i++) {
                var d = ReadLineInt();
                var a = ReadLineIntSpilit();

                for (int q = 0; q < d; q++) {
                    list.Add(a[q]);
                }
            }

            list.Distinct();

            var re = 0;
            for (int i = 1; i <= n[0]; i++) {
                if (!list.Contains(i)) {
                    re++;
                }
            }

            Console.WriteLine(re);
            ReadLine();
        }

        //最大公約数
        static int gcd(int a, int b)
        {
            if (a > b) {
                return gcd(b, a);
            }

            while (b != 0) {
                var remainder = a % b;
                a = b;
                b = remainder;
            }

            return a;
        }

        //最小公倍数
        static int lcm(int a, int b) => a * b / gcd(a, b);

        /// <summary>
        /// コンビネーション
        /// </summary>
        static int nCm(int n, int m)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            return n * nCm(n - 1, m - 1) / m;
        }

        public static string ReadLine() => Console.ReadLine();
        public static int ReadLineInt() => int.Parse(Console.ReadLine());
        public static long ReadLineLongInt() => long.Parse(Console.ReadLine());
        public static string[] ReadLineStringSplit(char a = ' ') => ReadLine().Split(a).ToArray();
        public static int[] ReadLineIntSpilit(char a = ' ') => ReadLine().Split(a).Select(x => int.Parse(x)).ToArray();
        public static long[] ReadLineLongSpilit(char a = ' ') => ReadLine().Split(a).Select(x => long.Parse(x)).ToArray();
        static string[] GetAplhaLowerArray() => new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
        static string[] GetAplhaUpperArray() => new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
    }
}


Measured memory_bytes: 28544
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  ll n; cin >> n;
  vector<ll> c(n-1), s(n-1), f(n-1);
  rep(i, n-1) cin >> c[i] >> s[i] >> f[i];
  rep(i, n-1) {
    ll ans = s[i] + c[i];
    for (int j = i + 1; j < n-1; j++) {
      ans += (f[j] - ans % f[j]) % f[j];
      ans = max(ans, s[j]);
      ans += c[j];
    }
    outl(ans);
  }
  outl(0);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


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

using namespace std;

#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define dump(x) cerr << #x << "=" << x << endl

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

int main() {
    int n, m, x;
    cin >> n >> m >> x;

    vi a(m);
    rep(i, m) {
        cin >> a[i];
    }
    
    vi box(n+1);
    rep(i, m) {
        box[a[i]] = 1;
    }
    
    int former = count(box.begin(), box.begin()+x, 1);
    int latter = count(box.begin()+x, box.end(), 1);

    cout << min(former, latter) << endl;
}

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

using namespace std;
int a_c[26];
int four,two,one;
int h,w;

int main() {
  cin >> h >> w;

  if(h % 2 == 0 && w % 2 == 0) {
    four = (h / 2) * (w / 2);
  }
  if(h % 2 == 1 && w % 2 == 0) {
    four = (h / 2) * (w / 2);
    two = w / 2;
  }
  if(h % 2 == 0 && w % 2 == 1) {
    four = (h / 2) * (w / 2);
    two = h / 2;
  }
  if(h % 2 == 1 && w % 2 == 1) {
    four = (h / 2) * (w / 2);
    two = h / 2 + w / 2;
    one = 1;
  }
  //cout << four << two << one <<endl;
  for(int i = 0; i < h; i++) {
    string s;
    cin >> s;
    for(int j = 0; j < s.size(); j++) {
      a_c[s[j] - 'a']++;
    }
  }
  int f = 0,t = 0,o = 0;
  for(int i = 0; i < 26; i++) {
    int tmp = a_c[i];
    //cout << tmp << endl;
    f += tmp / 4;
    tmp = tmp - (4 * (tmp / 4));
    t += tmp / 2;
    tmp = tmp - (2 * (tmp / 2));
    o += tmp;
  }
  //cout << f << t << o <<endl;
  if(f == four && t == two && o == one) cout << "Yes" <<endl;
  else {
    while(f > 0) {
      f--;
      t += 2;
      if(f == four && t == two && o == one) {
	cout << "Yes" << endl;
	return 0;
      }
    }
    cout << "No" <<endl;
  }
}
  
   
      

  
 


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

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef pair<ld,ld> id;

#define FOR(i, a, b) for(int i=(a); i<=(b); i++)
#define ROF(i, a, b) for(int i=(a); i>=(b); i--)
#define MEM(x, v) memset(x, v, sizeof(x))
#define FILL(x, n, v) fill(x, x+n, v);
#define ALL(x) x.begin(), x.end()
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define f first
#define s second
#define ins insert
#define e emplace
#define eb emplace_back
#define ef emplace_front
#define p push
#define pf push_front
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ft front
#define bk back
#define pp pop
#define ppb pop_back
#define ppf pop_front

#define db cout<<"YEET\n";
#define ct(x) cout<<x<<'\n';

const ll MOD = 1e9+7; //998244353
const ll MAXN = 2e5+5;
const ll INF = 1e18;
const ld PI = acos((ld)-1);

ll digits[11];
ll k, ans, cnt;
bool found;

void dp(ll prevv, bool start, ll pos){
    if (pos==11){
        cnt++;
        if (cnt == k) found=1;
        return;
    }
    ll lower = max(prevv-1, 0ll);
    ll upper = min(prevv+1, 9ll);

    if (!start && pos==10){
        lower=1;
        upper=9;
    } else if (!start) {
        lower=0;
        upper=9;
    }

    FOR(i,lower,upper){
        bool isstart;
        if (!start && i!=0) {
            isstart=1;
        } else isstart=start;

        digits[pos] = i;
        dp(i,isstart,pos+1);
        if (found) return;
    }
}

int main(){
    FAST
    cin >> k;
    dp(0,0,1);
    FOR(i,0,10){
        ans = ans*10 + digits[i];
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define _GLIBCXX_DEBUG
#define int long long
using namespace std;
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MAXIN(x) max_element(ALL(x)) - x.begin();
#define MIN(x) *min_element(ALL(x))
#define MININ(x) min_element(ALL(x)) - x.begin();
#define INF 1000000000000
#define MOD 100000070

#define MAXR 100000
#define PI 3.14159265358979323846

using namespace std;

signed main()
{
    int n;
    cin >> n;
    vector<int> A(n);
    int max = 0;
    int ans = 0;
    REP(i, n){
        if (i == 0){
            cin >> A[i];
            max = A[i];
        } 
        else{
            cin >> A[i];
            if (max > A[i]){
                ans += max - A[i];
            }else if(max < A[i]){
                max = A[i];
            }else{

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

Measured memory_bytes: 4836
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE MultiWayIf #-}


import Control.Arrow
import Control.Concurrent
import Control.Monad
import qualified Data.ByteString.Builder as B
import qualified Data.ByteString.Char8 as C
import Data.Complex
import Data.Function
import Data.Function.HT
import qualified Data.IntMap.Strict as IM
import qualified Data.IntSet as IS
import Data.List
import Data.Monoid
import Data.Ord
import qualified Data.Sequence as Sq
import Data.Vector.Algorithms.Search
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import Debug.Trace
import System.IO


r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine


main :: IO ()
main = do
    [x,n] <- r'
    as <- sort<$>r'
    --print as
    print $ snd $ head $ sort $ map ((abs.(x -))&&&id) ([-1..101]\\as)



Measured memory_bytes: 3784
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, [ $t:tt ]) => {{
    let len = read_value!($iter, usize);
    (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  }};

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: usize1,
  }
  let v = vec![1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51];

  puts!("{}\n", v[n]);
}


Measured memory_bytes: 4352
#include<stdio.h>
#define M 3000+5
int main(){
	int n;
	scanf("%d",&n);
	int a[M],sum=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		sum=sum+a[i]-1;
	}
	printf("%d",sum);
}


Measured memory_bytes: 128
S = str(input())
n = int(len(S))
ans = [str(0) for i in range(n)]
cntLo = 0
cntRo = 0
cntLe = 0
cntRe = 0
for i in range(n-1):
    if S[i] == "R" and S[i+1] == "L":
        j = 1
        k = 1
        while i-j >= 0 and S[i-j] == "R":
            if j % 2 == 0:
                cntRe += 1
            else:
                cntRo += 1
            j += 1
        while i+1+k <= n-1 and S[i+1+k] == "L":
            if k % 2 == 0:
                cntLe += 1
            else:
                cntLo += 1
            k += 1
        ans[i] = str(cntRe + cntLo+1)
        ans[i+1] = str(cntRo + cntLe+1)
        cntLo = 0
        cntRo = 0
        cntLe = 0
        cntRe = 0
print(" ".join(ans))

Measured memory_bytes: 49024
#include<cstdio>
#include<cstring>
using namespace std;
const int N=3005,mod=1e9+7;
int f[2][N][2],n,m,ans;
inline void inc(int &x,int y)
{
	x+=y; x-=x>=mod?mod:0;
}
int main()
{
	register int i,j,k;
	scanf("%d%d",&n,&m);
	for (i=1;i<=n;++i)
	f[0][i][0]=1; f[0][0][1]=1;
	for (i=0;i<m;++i)
	{
		int now=i&1,nxt=now^1;
		memset(f[nxt],0,sizeof(f[nxt]));
		for (j=0;j<=n;++j)
		for (k=0;k<=1;++k)
		{
			if (j) inc(f[nxt][j-1][k|(j==1)],f[now][j][k]);
			if (j) inc(f[nxt][j][k|(j==1)],f[now][j][k]);
			if (n-j) inc(f[nxt][j+1][k],f[now][j][k]);
			if (n-j) inc(f[nxt][j][k],f[now][j][k]);
		}
	}
	for (i=0;i<=n;++i)
	inc(ans,f[m&1][i][1]);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256