akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var func = new Function();
            var N = cin.ReadInt;
            var A = cin.ReadInt;
            var B = cin.ReadInt;
            var count =0;
            
            var ans = Enumerable.Range(1, N).Where(n => {
                      return A <=func.findSumOfDigits(n) && func.findSumOfDigits(n) <= B;
            }).Sum();
            WriteLine(ans);
        }
        
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
    
    public class Function
    {
        public int findSumOfDigits(int n) {
            int sum = 0;
            while (n > 0) { // n が 0 になるまで
            sum += n % 10;
            n /= 10;
                
            }
            return sum;
            
        }
    }
}

Measured memory_bytes: 11348
"""
author : halo2halo
date : 29, Jan, 2020
"""

import sys

# import itertools
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())
A = np.array(readline().split(), dtype=np.int64)

ans=0
while np.all(A%2==0):
    A//=2
    ans+=1
print(ans)

Measured memory_bytes: 12396
import sys
from itertools import combinations
  
def solve():
    input = sys.stdin.readline
    N = int(input())
    A = dict()
    for i in range(N):
        A[i] = dict()
        for j, a in enumerate(list(map(int, input().split()))): A[i][j] = a

    length = 0
    possible = True
    for a, b in combinations(range(N), 2):
        Lab = A[a][b]
        for k in range(N):
            if k != a and k != b:
                if Lab < A[a][k] + A[k][b]: continue
                if Lab >  A[a][k] + A[k][b]: possible = False
                break
        else: length += Lab
        if possible: continue
        print(-1)
        break
    else: print(length)
    
    return 0
 
if __name__ == "__main__":
    solve()


Measured memory_bytes: 49244
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second

int n,m;
string s[1005];
int dp[1005][1005];

int findpath(int x, int y){
	if(x<0 || y<0 || x>=n || y>=m)
		return 0;
	if(dp[x][y]!=-1)
		return dp[x][y];
	if(s[x][y]=='#')
		return dp[x][y]=0;
	if(x==0 && y==0){
		return dp[x][y]=1;
	}

	return dp[x][y] = (findpath(x-1,y)%hell + findpath(x,y-1)%hell)%hell;
	
}
void solve(){
	
	cin>>n>>m;
	rep(i,0,n)
		cin>>s[i];

	memset(dp,-1,sizeof dp);
	cout<<findpath(n-1,m-1)<<endl;
	

}
signed main(){
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    srand (static_cast <unsigned> (time(0)));
    int t=1;
    while(t--){
        solve();
    }
    return 0;
}

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

using namespace std;

int Par(int n, vector<int> &a) {
	if (n == a[n])
		return n;
	int ans = Par(a[n], a);
	a[n] = ans;
	return ans;
}

int main(void) {
	int num, m, i, x, y, ans = 0;
	cin >> num >> m;
	vector<int> d(num + 1), a(num + 1), h(num + 1, 0);
	for (i = 1; i <= num; i++) {
		scanf("%d", &d[i]);
		a[i] = i;
	}
	for (i = 0; i < m; i++) {
		scanf("%d%d", &x, &y);
		x = Par(x, a);
		y = Par(y, a);
		if (x != y) {
			if (h[x] == h[y]) {
				a[max(x, y)] = min(x, y);
				h[max(x, y)]++;
			}
			else if (h[x] < h[y])
				a[x] = y;
			else
				a[y] = x;
		}
	}
	for (i = 1; i <= num; i++) {
		if (Par(i, a) == Par(d[i], a))
			ans++;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 1408
def lcm(a, b): #lcm(int, int)
    if a<b:
        a,b = b,a
    x = a*b
    r = a%b
    while r != 0:
        a = b
        b = r
        r = a % b
    return x//b
n = int(input())
t = [0]*n
for i in range(n):
    t[i] = int(input())
ans = t[0]
for i in range(1,n):
    ans = lcm(ans,t[i])
print(ans)

Measured memory_bytes: 3064
N,M=map(int,input().split())
if N%2==1:
    for i in range(1,M+1):
        print(i,N-i)
else:
    ANS=[]
    for i in range(1,N//4+1):
        ANS.append((i,N//2-i))
    for i in range(1,N//4+1):
        ANS.append((N//2+i,N+1-i))

    check=0
    for a,b in ANS:
        if a!=b:
            print(a,b)
            check+=1

        if check==M:
            break

Measured memory_bytes: 18040
package main

import (
	"container/list"
	"fmt"
)

func main() {
	var k int
	fmt.Scan(&k)

	ls := list.New()
	for i := 1; i <= 9; i++ {
		ls.PushBack(i)
	}

	var x int
	for i := 0; i < k; i++ {
		x = ls.Remove(ls.Front()).(int)
		d := x % 10
		if d > 0 {
			ls.PushBack(10*x + d - 1)
		}
		ls.PushBack(10*x + d)
		if d < 9 {
			ls.PushBack(10*x + d + 1)
		}
	}
	fmt.Println(x)
}


Measured memory_bytes: 13568
/**Which of the favors of your Lord will you deny ?**/

#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define MP make_pair
#define F first
#define S second
#define INF INT_MAX

#define ALL(x) (x).begin(), (x).end()
#define DBG(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << endl

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class TIn>
using indexed_set = tree<
                    TIn, null_type, less<TIn>,
                    rb_tree_tag, tree_order_statistics_node_update>;

/*
PBDS
-------------------------------------------------
1) insert(value)
2) erase(value)
3) order_of_key(value) // 0 based indexing
4) *find_by_order(position) // 0 based indexing

*/

inline void optimizeIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int nmax = 2e5+7;
const LL LINF = 1e17;

string to_str(LL x)
{
    stringstream ss;
    ss<<x;
    return ss.str();
}

//bool cmp(const PII &A,const PII &B)
//{
//
//}

int mat[150][150];

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

    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            mat[i][j] = 1;

    if(n%2==0)
    {
        for(int i=1;i<=n/2;i++)
            mat[i][n-i+1] = 0 , mat[n-i+1][i] = 0;
    }
    else
    {
        for(int i=1;i<=n/2;i++)
            mat[i][n-i] = 0 , mat[n-i][i] = 0;

    }

    int cnt = 0;

    for(int i=1;i<=n;i++)
        for(int j=1;j<i;j++)
            cnt += mat[i][j];

    cout<<cnt<<endl;

    for(int i=1;i<=n;i++)
        for(int j=1;j<i;j++)
            if(mat[i][j])
                cout<<j<<" "<<i<<endl;


    return 0;
}





Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();

		System.out.println(a + a*a + a*a*a);
	}

}

Measured memory_bytes: 35692
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

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

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

    cin>>a>>b;
    if(a<=5)Cout(0);
    else if(a>=13)Cout(b);
    else Cout(b/2);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
    int S,N;
    S=100000;
    scanf("%d",&N);
    for (int i=0; i<N; i++) {
        S*=1.05;
        if (S%1000!=0) {
            S=((S/1000)+1)*1000;
        }
    }
    printf("%d\n",S);
    return 0;
}



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

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

using namespace std;

template<class G>
class Fenwick_tree{
	vector<G> a;
public:
	Fenwick_tree(int n):a(n){}
	void add(int i,G val){
		for(i++;i<=a.size();i+=i&-i) a[i-1]+=val;
	}
	G sum(int l,int r)const{
		if(l==0){
			G res{};
			for(;r>0;r-=r&-r) res+=a[r-1];
			return res;
		}
		return sum(0,r)-sum(0,l);
	}
	int lower_bound(G val)const{
		if(val<=G{}) return 0;
		int x=0,k;
		for(k=1;k<=a.size();k<<=1);
		for(k>>=1;k>0;k>>=1) if(x+k<=a.size() && a[x+k-1]<val) val-=a[x+k-1], x+=k;
		return x;
	}
	int upper_bound(G val)const{
		if(val<=G{}) return 0;
		int x=0,k;
		for(k=1;k<=a.size();k<<=1);
		for(k>>=1;k>0;k>>=1) if(x+k<=a.size() && a[x+k-1]<=val) val-=a[x+k-1], x+=k;
		return x;
	}
};

int main(){
	int n; scanf("%d",&n);
	vector<int> x(n);
	rep(i,n) scanf("%d",&x[i]);
	int L; scanf("%d",&L);

	Fenwick_tree<int> F(n);
	F.add(0,x[0]);
	rep(i,n-1) F.add(i+1,x[i+1]-x[i]);

	vector<int> next(n,n);
	for(int i=n-2;i>=0;i--){
		next[i]=F.upper_bound(x[i]+L)-1;
	}

	vector<vector<int>> dbl(20,vector<int>(n+1,n)); // doubling
	rep(i,n) dbl[0][i]=next[i];
	rep(dep,19) rep(i,n) dbl[dep+1][i]=dbl[dep][dbl[dep][i]];

	int q; scanf("%d",&q);
	rep(_,q){
		int a,b; scanf("%d%d",&a,&b); a--; b--;
		if(a>b) swap(a,b);
		int ans=0;
		for(int dep=19;dep>=0;dep--){
			if(dbl[dep][a]<=b){
				a=dbl[dep][a];
				ans+=1<<dep;
			}
		}
		if(a<b) ans++;
		printf("%d\n",ans);
	}

	return 0;
}


Measured memory_bytes: 9848
#include<bits/stdc++.h>
using namespace std;
main() {
	int n; cin >> n;
	long long  mn = INT_MAX,sum = 0;
	vector<int> v(n);
	multiset<int,greater<int>> s;
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	sort(v.rbegin(),v.rend());
	sum += v[0];
	s.insert(v[1]); 
	s.insert(v[1]); 
	for (int i = 2 ; i < n; i++) {
		auto x = *s.begin();
		s.erase(s.begin());
		sum += x;
		s.insert(v[i]);
		s.insert(v[i]);
	}
	cout << sum;
}

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

#define froop1(a,n) for(int i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)
int main(){
	int N,M,n;
  char m;
  cin >> N >> M;
  char num[N];
  vector<int> check(N,0);
      froop1(0,N){
    num[i] = '0';
  }
  froop1(0,M){
    cin >> n >> m;
    n--;
   	if(check.at(n) == 0){
      num[n] = m;
      check.at(n) = 1;
    }else if(check.at(n) == 1 && num[n] != m){
      cout << -1 << endl;
      return 0;
    }
  }
  if(check.at(0) == 1 && num[0] == '0' && N != 1){
	cout << -1 << endl;
    return 0;
  }else if(num[0] == '0' && N != 1){
	num[0] = '1';
  }
  froop1(0,N){
	cout << num[i];
  }
  cout << endl;
return 0;
}

Measured memory_bytes: 256
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const field = input.slice(0, -1).map((line) => line[0]);

  let answer: string[] = [];

  field.forEach((row, index) => {
    answer.push(row[index]);
  });

  return answer.join("");
};

console.log(main(read()));


Measured memory_bytes: 29576
#include<cstdio>

long n;

int main() {
    scanf("%ld", &n);
    long a = 0;
    for (long i = 1; i * i <= n; i++) {
        if (n % i == 0) a = i;
    }
    printf("%ld\n", a + n / a - 2);
    return 0;
}


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

typedef long long ll;

int n, kac, ans, a[N], say[N];

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%d",&n);
	for(int i = 1; i <= n; i++){
		scanf("%d",a + i);
		say[a[i]]++;
	}
	for(int i = 1; i < N; i++){
		while(say[i] >= 3){
			say[i] -= 2;
			ans += 2;
		}
		if(say[i] > 1)
			kac++;
	}
	ans += (kac/2)*2;
	if(kac%2)
		ans += 2;
	printf("%d\n", n - ans);
	return 0;
}

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

int main(int argc, char const *argv[]) {
	char S[3];
	cin >> S[0] >> S[1] >> S[2];
	int count = 0;
	for (int i = 0; i < 3; ++i){
		if (S[i]=='a')count++;
		else if (S[i]=='b')count += 2;
		else count += 3;
	}
	if (count == 6) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 768
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split())) # len: n-1
point = 0
for i in range(n):
    index = a[i] -1
    point += b[index] # 基礎ポイント
    if i>=1 and a[i] == a[i-1]+1:
        point += c[a[i-1]-1]
print(point)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
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;}
const int inf = 1001001001;

int main() {
    ll n,m;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(all(a));
    vector<P> ch(m);
    rep(i,m) cin >> ch[i].second >> ch[i].first;
    sort(all(ch));
    reverse(all(ch));
    ll ans = 0;
    ll now = -1;
    rep(i,m) {
        if(now >= n-1) break;
        ll nf = ch[i].first;
        ll ns = ch[i].second;
        if(a[now+1] >= nf) break;
        auto it = lower_bound(all(a),nf);
        ll chab = (it == a.end() ? n : it-a.begin());
        chab -= (now+1);
        int j = min(chab,ns);
        now += j;
        ans += j*nf;
    }
    rep2(i,now+1,n) {
        ans += a[i];
    }
    cout << ans << endl;
}

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

using namespace std;

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

vector<int> v[200005];
int ans[200005];

void f(int cur, int par, int value) {
  ans[cur] += value;
  for (auto e : v[cur]) {
    if (e == par) {
      continue;
    }
    f(e, cur, ans[cur]);
  }
}

int main(){
  int n, q, a, b, p, x;
  cin >> n >> q;

  rep(i, n-1) {
    cin >> a >> b;
    v[a-1].push_back(b-1);
    v[b-1].push_back(a-1);
  }
  
  rep(i, q) {
    cin >> p >> x;
    ans[p-1] += x;
  }

  f(0, -1, 0);
  rep(i, n) {
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 23424
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <set>
#include <bitset>

using namespace std;
#define lowbit(i) (i & (-i))
#define eps 1e-7
#define GETMID int mid = (l + r) >> 1
#define lson u << 1
#define rson u << 1 | 1
#define Lson u << 1, l, mid
#define Rson u << 1 | 1, mid + 1, r
#define Maxn (100000 + 10)
#define MP(a, b) make_pair(a, b)
#define PB(a) push_back(a);
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, int> pli;
const double PI = acos(-1.0);
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;

int n;
char s[100010];
int a[100010], cnt[30] = {0};
int ans = 0;

int main() {
	scanf("%d", &n);
	scanf("%s", s);
	for(int i = 0; i < n; ++i)
		a[i] = s[i] - 'a';
	
	for(int i = 0, cur; i < n; ++i) {
		cur = 1;
		for(int j = 0; j < 26; ++j) {
			if(j == a[i]) continue;
			cur = 1ll * cur * (cnt[j] + 1) % mod;
		}
		
		ans = (1ll * ans + cur) % mod;
		++cnt[a[i]];
	}
	
	printf("%d\n", ans);
	
	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using vb = vector<bool>;
using boolGraph = vector<vb>;
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main() {
  int N; cin >> N;
  Graph point(N, vi(2));
  rep(i,N) rep(j,2) cin >> point[i][j];

  int odd = abs(point[0][0] + point[0][1]) % 2;
  rep(i,N) {
    if (abs(point[i][0] + point[i][1]) % 2 != odd) {
      cout << -1 << endl;
      return 0;
    }
  }

  const int sz = 31;
  vl arm(sz);
  arm[0] = 1;
  rep(i,sz-1) arm[i+1] = arm[i] * 2;
  ll sum = accumulate(all(arm), 0LL);

  if (!odd) {
    arm.push_back(1);
    rep(i,N) --point[i][1];
  }

  cout << arm.size() << endl;
  rep(i,arm.size()-1) cout << arm[i] << ' ';
  cout << arm.back() << endl;

  rep(i,N) {
    string mode(arm.size(), 'U');

    int dist = abs(point[i][0]) + abs(point[i][1]);

    bitset<sz> goback((sum - dist) / 2);
    int X = point[i][0];
    int Y = point[i][1];
    vb plus = {X>0, Y>0};

    rep(j,sz) {
      if (abs(X)%2) {
        if (goback[j] ^ plus[0]) {
          mode[j] = 'R';
          --X;
        }
        else {
          mode[j] = 'L';
          ++X;
        }
      }
      else {
        if (goback[j] ^ plus[1]) {
          mode[j] = 'U';
          --Y;
        }
        else {
          mode[j] = 'D';
          ++Y;
        }
      }

      X /= 2;
      Y /= 2;
    }

    cout << mode << endl;
  }
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//CODE

void solve(void)
{
  int N;
  cin>>N;
  vector<int> C(N,0),F(N,0),S(N,0);
  for (int i = 0; i < N-1; i++)
  {
    cin>>C[i]>>S[i]>>F[i];
  }
  for (int i = 0; i < N; i++)
  {
    int time = 0;
    int place = i;
    for (int k = i; k < N-1; k++)
    {
      if(time < S[k])
      {
        time = S[k];
      }
      if(time%F[k] != 0)
      {
        time += F[k] - time%F[k];
      }
      time += C[k];
    }
    cout<<time<<endl;
    
  }
  
  
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


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

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

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  if (c - a - b > 0) {
    if (4 * a * b < (c - a - b) * (c - a - b)) {
      cout << "Yes" << endl;
      return 0;
    } else {
      cout << "No" << endl;
      return 0;
    }
  } else {
      cout << "No" << endl;
      return 0;
  }

  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("03")
#include <bits/stdc++.h>
#define ll long long 
#define fi first
#define se second

using namespace std;

int n;
long double a[1010], t, v;

int main() {
	//ifstream cin("tst.in");
	//ofstream out("tst.out");
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cin >> n >> t >> v;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	int bst = 1;
	for (int i = 1; i <= n; i++)
		if (abs(t - 0.006 * a[i] - v) < abs(t - 0.006 * a[bst] - v))
			bst = i;
	cout << bst;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <bitset>

using namespace std;

int main() {
	long long q;
	cin >> q;
	bitset<64> N(0);
	int query, i;

	for (int j = 0; j < q; j++) {
		cin >> query;
		if (query <= 3) {
			cin >> i;
			if (query == 0) {
				cout << N.test(i) << endl;
			}
			else if (query == 1) {
				N.set(i);
			}
			else if (query == 2) {
				N.reset(i);
			}
			else {
				N.flip(i);
			}
		}
		else {
			if (query == 4) {
				cout << N.all() << endl;
			}
			else if (query == 5) {
				cout << N.any() << endl;
			}
			else if (query == 6) {
				cout << N.none() << endl;
			}
			else if (query == 7) {
				cout << N.count() << endl;
			}
			else {
				cout << N.to_ullong() << endl;
			}
		}

	
	}

}


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

long long n;
vector<long long> a;
int ok[100100];
long long qs[100100];

main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		long long x;
		scanf("%lld",&x);
		a.push_back(x);
	}
	sort(a.begin(),a.end());
	qs[0]=a[0];
	for(int i=1;i<n;i++)
		qs[i]=qs[i-1]+a[i];
	ok[n-1]=1;
	int cou=1;
	for(int i=n-2;i>=0;i--)
	{
		if(qs[i]*2>=a[i+1])
		{
			ok[i]=ok[i+1];
		}
		if(ok[i]==1)cou++;
	}
	printf("%d",cou);
}

Measured memory_bytes: 2292
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = LLONG_MAX;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */

int main() {
    int n;
    cin >> n;
    int count = 0;
    rep(i, n) {
        int a;
        cin >> a;
        if((i+1)%2==1&&a%2==1)count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3612
x,y = map(str,input().split())
dic = {}
dic.setdefault('A',1)
dic.setdefault('B',2)
dic.setdefault('C',3)
dic.setdefault('D',4)
dic.setdefault('E',5)
dic.setdefault('F',6)
if dic[x]<dic[y]:
    print('<')
elif dic[x]>dic[y]:
    print('>')
else:
    print('=')

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

int hoge(int a, int b, int acc = 0) {
    if (b == 0) return acc;
    return hoge(a, b - 1, 10 * acc + a);
}

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

    int a, b;
    cin >> a >> b;

    cout << min(to_string(hoge(a, b)), to_string(hoge(b, a))) << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
const int MAX=2147483647;
int n,q;
int d[600000];
void init(){
  for(int i=0;i<2*n-1;i++)d[i]=0;
}
void add(int i,int x){
  while(i<=n){
    d[i]+=x;
    i += i & -i;
  }
}
int sum(int i){
  if(i==0)return 0;
  int s=0;
  while(i>0){
    s+=d[i];
    i -= i&-i;
  }
  return s;
}
int getsum(int x,int y){
  return sum(y)-sum(x);
}
int main(){
  scanf("%d %d",&n,&q);
  init();
  for(int i=0;i<q;i++){
    int c,x,y;
    scanf("%d %d %d",&c,&x,&y);
    if(c==0)add(x,y);
    else printf("%d\n",getsum(x-1,y));
  }
  return 0;
}

Measured memory_bytes: 3940
#include<iostream>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  while(true){
    if(!a&&!b)break;
    a--;
    if (b/4-a/4-b/100+a/100+b/400-a/400){
      for(int i=a/4*4+4;i<b+1;i+=4)
	if(i%100)cout<<i<<endl;
	else if(!(i%400))cout<<i<<endl;
    }
    else{
      cout<<"NA"<<endl;
    }
    cin>>a>>b;
    if(!a&&!b)break;
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;


void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    if(n==3||n==5||n==7){
        cout << "YES";
    }
    else{
        cout << "NO";
    }


    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int n,h,w,a,b,ans=0;
  scanf("%d %d %d",&n,&h,&w);
  for(int i=0;i<n;i++){
    scanf("%d %d",&a,&b);
    if(a>=h&&b>=w) ans++;
  }
  printf("%d\n",ans);
  return 0;
  
}

Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=200005;
int n,m,a[maxn],b[maxn];
inline int _read(){
	int num=0;char ch=getchar();
	while (ch<'0'||ch>'9') ch=getchar();
	while (ch>='0'&&ch<='9') num=num*10+ch-48,ch=getchar();
	return num;
}
int main(){
	n=_read();for (int i=1;i<=n;i++) a[i]=_read();
	m=_read();for (int i=1;i<=m;i++) b[i]=_read();
	sort(a+1,a+1+n);sort(b+1,b+1+m);
	int j=1;
	for (int i=1;i<=m;i++){
		while(j<=n&&a[j]!=b[i]) j++;
		if (j>n) return printf("NO"),0;
		j++;
	}
	printf("YES");
}

Measured memory_bytes: 1664
#include <algorithm>
#include   <cstring>
#include    <cstdio>
using namespace std;

int n,m;

int main(){
	scanf("%d%d",&n,&m);
	if(n==1 && m==1){
		puts("1");
		return 0;
	}
	if(n==1 || m==1){
		if(m==1)
			swap(n,m);
		printf("%d\n",m-2);
		return 0;
	}
	if(n==2 || m==2){
		puts("0");
		return 0;
	}
	printf("%lld\n",1LL*(n-2)*(m-2));
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>

#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define mod 1000000007
#define show(n) cerr<<#n<<" = "<<n<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl

//ここからAtCoder向けdefine
#define yes cout << "Yes" << endl
#define no cout << "No" << endl

using namespace std;

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using pint = pair<int,int>;

const int INF = (1 << 30);

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    char c;
    set<char> s;
    rep(i,3){
        cin>>c;
        s.insert(c);
    }
    if(s.find('a') == s.end()||s.find('b')==s.end()||s.find('c')==s.end()){
        no;
    }else{
        yes;
    }

    return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
/*
alias g='g++ -std=c++17 -O2 pra.cpp'
cd programming
cd cpp
cd practice

*/
#define rep(i, n) for(int i=0; i<(n); i++)
using veci = vector<int>;
using ll = long long;
int c[10010];
int a[2020202];
int b[2000200];
void countingsort(int a[], int b[], int k, int n){//計数ソート
    for (int i=0; i<k; i++){//記録用配列の全要素を0で初期化
        c[i] = 0;
    }
    for (int j=1; j<= n; j++){//要素数を数えて配列に記録する
        c[a[j]]++;
    }
    for (int i=1; i<=k; i++){//要素数の配列を用いて累積和をとる
        c[i] = c[i] + c[i-1];//これはコピーをとるとき、添え字の場所を示す
        //新しい住所のようなもの
    }
    for (int j=n; j>=1; j--){//まずもともとの配列を見て、
    //その値が示す要素数の配列の場所(新しい住所)を見て、
    //その場所にコピーをとる
    //後ろから選ぶことで安定なソートになる(住所を一個ずつ減らしていくため)
        b[c[a[j]]] = a[j];
        c[a[j]]--;//新しい住所の場所は既に使われてしまったので、
        //その一個前に変更する
    }
}
int main(){
    int n;
    cin >> n;
    rep(i, n)cin >> a[i+1];//使うのが1オリジンの配列なので、
    //1から始まるようにする
    countingsort(a, b, 10010, n);
    rep(i, n){
        cout << b[i+1];
        if (i != n-1) cout << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 18760
# AtCoder Beginner Contest 074 D - Restoring Road Network　

import sys

N = int(input())
A = []
for _ in range(N):
    a = list(map(int, sys.stdin.readline().strip().split()))
    b = a
    A.append(a)

needless = [[False] * N for _ in range(N)]

# ワーシャルフロイド
for k in range(N):
    for i in range(N):
        for j in range(N):
            if A[i][j] > A[i][k] + A[k][j]:
                print(-1)
                sys.exit()
            elif (A[i][j] == A[i][k] + A[k][j]) and (A[i][k] != 0) and (A[k][j] != 0):
                needless[i][j] = True

# for i in needless:
#     print(i)

ans = 0
for h in range(N):
    for w in range(N):
        if needless[h][w] is False:
            ans += A[h][w]

print(ans // 2)


Measured memory_bytes: 75664
N, M, C = map(int, input().split())
B = [int(i) for i in input().split()]

list = [input() for _ in range(N)]

count = 0
for l in list:
  sum = 0
  for index, num in enumerate(l.split()):
    sum += int(num) * B[index]
  sum += C
  if sum > 0:
    count += 1
print(count)

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

int main(){
  vector<int> abc(3);
  for(int i=0;i<3;i++){
    cin >> abc.at(i);
  }
  sort(abc.begin(), abc.end());
  if(abc.at(0)==abc.at(1) && abc.at(1) < abc.at(2)){
    cout << "Yes" << endl;
  }else if(abc.at(0) < abc.at(1) && abc.at(1)==abc.at(2)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
# coding=utf-8
while True:
    a, op, b = raw_input().rstrip().split()
    if op == '+':
        print int(a) + int(b)
    elif op == '-':
        print int(a) - int(b)
    elif op == '*':
        print int(a) * int(b)
    elif op == '/':
        print int(a) / int(b)
    else:
        break

Measured memory_bytes: 4204
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll n;
    string s;
    cin >> n >> s;
    ll left = 0;
    ll right = 0;
    ll pi = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == '(')
        left++;
        if(s[i] == ')')
        right++;
        if(left < right){
        left++;
        pi++;
    }
    }
    for(int i = 0; i < pi; i++){
        cout << '(';
    }
    cout << s;
    for(int i = 0; i < left - right; i++)
    cout << ')';
    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lli long long int

using namespace std;

int main()
{
    lli n, a, b; cin>>n>>a>>b;
    if((b-a)%2==0)
    {
        cout<<"Alice\n";
    }
    else
    {
        cout<<"Borys\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, k, co=0; cin >> a >> b >> c >> k;
  while(a >= b) {
    b *= 2;
    co++;
  }
  while(b >= c) {
    c *= 2;
    co++;
  }
  if(co <= k) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define endl '\n'

using namespace std;

main()
{
  fast;
  int p[3];
  cin>>p[0]>>p[1]>>p[2];
  sort(p,p+3);
  if (p[0]==5 && p[1]==5 && p[2]==7)
    cout<<"YES\n";
  else
    cout<<"NO\n";
}

Measured memory_bytes: 256
n= input()

n_list=list(n)

a=(n_list.count(n_list[0]))
b=(n_list.count(n_list[1]))
c=(n_list.count(n_list[2]))
d=(n_list.count(n_list[3]))

if a==2:
    if b==2:
        if c==2:
            if d==2:
                print("Yes")
            else:
                print("No")
        else:
            print("No")
    else:
        print("No")
else:
    print("No")


Measured memory_bytes: 3060
open System
[<EntryPoint>]
let main fsharp_saikooooo =
   let n = Console.ReadLine() |> int 

   [1..9] |> List.map (fun x -> if n % x = 0 then n / x else 100) 
   |> List.filter (fun x -> x < 10) 
   |> List.length 
   |> fun x -> (if x = 0 then "No" else "Yes") 
   |> stdout.WriteLine
   
   0

Measured memory_bytes: 11348
N,M=gets.split.map(&:to_i)
ms = []
M.times do
    k,*ss=gets.split.map(&:to_i)
    m = 0
    ss.each do |s|
        m += 1 << (s-1)
    end
    ms << m
end
*ps=gets.split.map(&:to_i)
mps = ms.zip(ps)

def bit_count(n)
    (0..N-1).to_a.count {|i| n[i] == 1}
end

count = 0
0.upto(2**N-1) do |i|
    count += 1 if mps.all? {|m,p| bit_count(m&i) % 2 == p }
end

puts count

Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define ll long long
#define fort(i,n) for (int i = 1; i <= n; ++i)
#define pi pair<int,int>
#define vi vector<int>
#define pb push_back
#define sz size()
#define er erase
#define fr first
#define sc second
#define rc(x) return cout << x, 0
using namespace std;

int n,a,ans;

int32_t main()
{
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n;
    fort (i,n)
    {
        cin >> a;
        if (a%2==0) ++ans;
    }
    if (ans!=n) cout << "first";
    else cout << "second";
}


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

int main(){
	string s;
	while(cin >> s){
		int i = 0,num[100] = {},j = 0;
		while(s[i] != '\0'){
			if(s[i] == 'I'){
				i++;
				num[j] += 1;
				while(s[i] == 'I'){
					i++;
					num[j] += 1;
				}
				j++;
			}else if(s[i] == 'V'){
				i++;
				num[j] += 5;
				while(s[i] == 'V'){
					i++;
					num[j] += 5;
				}
				j++;
			}else if(s[i] == 'X'){
				i++;
				num[j] += 10;
				while(s[i] == 'X'){
					i++;
					num[j] += 10;
				}
				j++;
			}else if(s[i] == 'L'){
				i++;
				num[j] += 50;
				while(s[i] == 'L'){
					i++;
					num[j] += 50;
				}
				j++;
			}else if(s[i] == 'C'){
				i++;
				num[j] += 100;
				while(s[i] == 'C'){
					i++;
					num[j] += 100;
				}
				j++;
			}else if(s[i] == 'D'){
				i++;
				num[j] += 500;
				while(s[i] == 'D'){
					i++;
					num[j] += 500;
				}
				j++;
			}else if(s[i] == 'M'){
				i++;
				num[j] += 1000;
				while(s[i] == 'M'){
					i++;
					num[j] += 1000;
				}
				j++;
			}
		}
		i = 0;
		int pre = 1e9,res = 0;
		while(num[i] != 0){
			if(pre < num[i]){
				res -= pre * 2;
			}
			res += num[i];
			pre = num[i];
			i++;
		}
		cout << res << endl;
	}
}


Measured memory_bytes: 3016
#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! get_char {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().chars().collect::<Vec<_>>()
        }
    };
}

fn main() {
    let (mut a, b, mut c, d) = get!(i64, i64, i64, i64);

    loop {
        c -= b;
        if c <= 0 {
            println!("{}", "Yes");
            std::process::exit(0);
        }
        a -= d;
        if a <= 0 {
            println!("{}", "No");
            std::process::exit(0);
        }
    }

}


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

int main() {
  int N;
  cin >> N;
  vector<int> D1(N), D2(N);
  
  for(int i=0; i<N; i++){
  	cin >> D1.at(i) >> D2.at(i);
  }
  
  bool tripl = false;
  int ren = 0;
  
  for(int i=0; i<N; i++){
    if(D1.at(i) == D2.at(i)) ren++;
    else ren = 0;
    if(ren == 3){
      tripl = true;
      break;
    }
  }

  if(tripl == true) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

using namespace std;



int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);cout.tie(NULL);
   
   long long int n,i,m1,cnt1=0,cnt2=0;
   cin>>n>>m1;
   long long int p[m1];
   long long int h[n+1]={0};
   string s[m1];
   set<long int > st;

    
    for(i=0;i<m1;++i)
     {
         cin>>p[i]>>s[i];
     }
     
    for(i=0;i<m1;++i)
     {
         if(s[i]=="AC")
           {
              if(st.count(p[i])==0)
                {
                    st.insert(p[i]);
                    
                }
           }
           
          else
           {
               if(st.count(p[i])==1)
                 continue;
                 
               else
                 h[p[i]]++;
           }
     }
     
     for(i=1;i<=n;++i)
      {
          if(st.count(i)==1)
            cnt1+=h[i];
      }
      
      cout<<st.size()<<" "<<cnt1;
    
        
   
     return 0;
}

Measured memory_bytes: 12976
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
li = sorted(rl())
print(li[-1] - li[0])









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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amin(T& a,T2 b){ if(a > b) a = b;}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, k;
	cin >>n >>k;
	VI a(n);
	rep(i, n) cin >>a[i];
	a.push_back(k); n++;
	sort(all(a));
	
	auto f=[&](int m){
		if(a[m] >= k) return true;
		vector<int> dp(k+3, 0);
		dp[0] = 1;
		rep(i, n) if(i !=m){
			repr(j, k, 0) if(dp[j] >0){
				int nj = min(j+a[i], k);
				dp[nj] = 1;
				if(nj >= k-a[m] && nj < k) return true;
			}
		}
		return false;
	};
	
	int lf = -1, rg = n-1;
	while(rg - lf >1){
		int md = (rg + lf) >> 1;
		if( f(md) ) rg = md; else lf = md; 
	}

	cout << rg <<"\n";
	return 0;
}


Measured memory_bytes: 384
#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[i];
    }

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

Measured memory_bytes: 3600
#include<iostream>
#include<algorithm>
#include<cstdio>

using namespace std;

const int NMAX=101010;
const int IMAX=2147483647;

int n,q,x,y,c,N=1;
int seg[NMAX*4-1];

void init(int n){
    while(N<n)N*=2;
    for(int i=0;i<2*N-1;++i)seg[i]=IMAX;
}

void upd(int i,int x){
    i+=N-1;
    seg[i]=x;
    while(i>0){
        i=(i-1)/2;
        seg[i]=min(seg[2*i+1],seg[2*i+2]);
    }
}

int query(int a,int b,int k,int l, int r){
    if(r<=a||b<=l)return IMAX;
    if(a<=l&&r<=b)return seg[k];
    else{
        int vl=query(a,b,2*k+1,l,(l+r)/2);
        int vr=query(a,b,2*k+2,(l+r)/2,r);
        return min(vl,vr);
    }
}

int main(){

    
    cin>>n>>q;
    init(n);
    for(int i=0;i<q;++i){
        scanf("%d%d%d",&c,&x,&y);
        if(c==0)upd(x,y);
        else printf("%d\n",query(x,y+1,0,0,N));
    }

    return 0;
}



Measured memory_bytes: 4244
#include <stdio.h>
int main(void)
{
	int a,b,c,i,j;
	int array[10];
	for(i = 0;i < 10;i++)
	{
		scanf("%d",&array[i]);
	}
	for(i = 0;i < 9;i++)
	{
		for(j = 0;j < 9 - i;j++)
		{
			if(array[j] > array[j + 1])
			{
				a = array[j];
				array[j] = array[j + 1];
				array[j + 1] = a;
			}
		}
	}
	printf("%d\n",array[9]);
	printf("%d\n",array[8]);
	printf("%d\n",array[7]);

	return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
int main(void){
    /* 変数宣言，ちゃんと初期化しよう */
    int A = 0;
    int B = 0;
    int ans = 0;
    /* 変数宣言終わり */
    
    /* 入力を受け付ける部分*/
    
    // %dはdecimalの略．つまり，入力を10進数として扱うよという意味．
    scanf("%d %d", &A, &B);
    
    /* 入力を受け付ける部分終わり*/
    
    
    /* 何か処理*/
    ans = A % B;
    
    if(ans == 0){ans = 0;
      /* 真の場合の処理 */
      
    }else{ans = 1;
      /* 偽の場合の処理 */
      
    }
    
    for(int i = 0; i < 10; i++){ 
      // i = 0,1,2,3,4,5,6,7,8,9のとき処理される
      
    }
    
    /* 何か処理終わり*/
    
    
    /* 出力する部分*/
    
    printf("%d", ans); // %dの部分にansの値が表示される
    
    /* 出力する部分*/
    
    
    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M; cin >> N >> M;
  int ac = 0;
  int pena = 0;
  vector<int> wa(N, 0), isac(N, 0);
  for (int i = 0; i < M; ++i){
    int p; string s;
    cin >> p >> s;
    --p;
    if (s == "AC"){
      if (!isac[p]){
        ++ac;
        pena += wa[p];
        isac[p] = true;
      }
    } else {
      ++wa[p];
    }
  }      
  cout << ac << " " << pena << endl;
}

Measured memory_bytes: 1024
M,D = list(map(int, input().strip().split()))
count = 0
for m in range(2,M+1):
    for d in range(22, D+1):
        if ((d%10) >= 2) and (int(d/10) >= 2) and (m == int(d/10) * (d%10)):
            count+=1
print(count)


Measured memory_bytes: 2940
function main()
  
  N = parse(Int, readline())
  a = map(x -> parse(Int, x), split(readline()))
  
  cnt = 0
  check  = 1
  
  for i in a
    if i == check
      check += 1
    else
      cnt += 1
    end
  end
  
  if cnt == N
    println(-1)
  else
    println(cnt)
  end
  
end

main()

Measured memory_bytes: 166136
#include <iostream>

int main(void){
  int n;
  std::cin >> n;
  int *h = new int[n];
  int *max = new int[n];
  int count = 0;
  for(int i = 0; i < n; i++){
    std::cin >> h[i];
    if(i == 0){
      max[i] = h[i];
    }else{
      max[i] = (max[i - 1] > h[i]) ? max[i-1] : h[i];
    }
  }
  for(int i = 0; i < n; i++){
    if(i == 0){
      count++;
    }else if(h[i] >= max[i-1])
      count++;
  }
  std::cout << count << std::endl;
  return 0;
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
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;}


struct Precision{
  Precision(){
    cout<<fixed<<setprecision(12);
  }
}precision_beet;

//INSERT ABOVE HERE
signed main(){

  using D = double;
  using P = complex<D>;

  int n;
  D l;
  cin>>n>>l;
  vector<D> ts(n);
  for(int i=0;i<n;i++) cin>>ts[i];

  D pi=asin(1)*2;
  vector<P> ps(n);
  for(int i=0;i<n;i++)
    ps[i]=P(cos(2*pi*ts[i]/l),sin(2*pi*ts[i]/l));

  P ans(0,0);
  for(int i=0;i<n;i++){
    for(int j=0;j<i;j++){
      int x=i-j-1;
      int y=n-2-x;

      P c=P(cos(2*pi*(ts[i]+ts[j])/2/l),sin(2*pi*(ts[i]+ts[j])/2/l));
      c/=abs(c);

      ans+=+c*D(y);
      ans+=-c*D(x);
    }
  }

  ans/=n-0;
  ans/=n-1;
  ans/=n-2;
  ans*=6;

  cout<<ans.real()<<" "<<ans.imag()<<endl;
  return 0;
}


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

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

int main() {
  int n, a;
  cin >> n >> a;
  cout << n * n - a << endl;
}



Measured memory_bytes: 892
#include <stdio.h>

int main(void) {
    int n, num;
    char c;
    int kind[4] = {'S', 'H', 'C', 'D'};
    int data[4][13] = {};
    int i, j;

    scanf("%d", &n);

    while (n--){
        scanf(" %c %d", &c, &num);
        num--;

        switch(c) {
            case 'S': data[0][num] = 1; break;
            case 'H': data[1][num] = 1; break;
            case 'C': data[2][num] = 1; break;
            case 'D': data[3][num] = 1; break;
        }
    }

    for (i = 0; i < 4; i++){
        for (j = 0; j < 13; j++){
            if (!data[i][j]){
                printf("%c %d\n", kind[i], j+1);
            }
        }
    }

    return 0;
}

Measured memory_bytes: 596