akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_bacm
#define mp mame_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head

void solve(){
    int h, w;
    cin >> h >> w;
    vector<string> grid(h);
    int a[h][w];
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            a[i][j] = 0;
        }
    }
    for (int i = 0; i < h; i++){
        cin >> grid[i];
        int c = 0;
        for (int j = 0; j < w; j++){
            if (grid[i][j] == '.'){
                a[i][j] += c;
                c++;
            }
            else a[i][j] = c = 0;
        }
        c = 0;
        for (int j = w-1; j >= 0; j--){
            if (grid[i][j] == '.'){
                a[i][j] += c;
                c++;
            }
            else a[i][j] = c = 0;
        }
    }

    for (int i = 0; i < w; i++){
        int c = 0;
        for (int j = 0; j < h; j++){
            if (grid[j][i] == '.'){
                a[j][i] += c;
                c++;
            }
            else a[j][i] = c = 0;
        }
        c = 0;
        for (int j = h-1; j >= 0; j--){
            if (grid[j][i] == '.'){
                a[j][i] += c;
                c++;
            }
            else a[j][i] = c = 0;
        }
    }
    int ans = 0;
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            if (a[i][j] > ans){
                ans = a[i][j];
            }
        }
    }
    cout << ans+1 << '\n';
}

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

    //int t; cin >> t; while (t--)
        solve();
}


Measured memory_bytes: 23252
#include <stdio.h>
#include <stdlib.h>

int main(void){
  int c, N, i, j, k;
  int x[3];
  char tmp[5];

  i = 0;
  while(( c = getchar()) != '\n'){
    tmp[i++] = c;
  }
  tmp[i] = '\0';
  N = atoi(tmp);
  for(k = 0; k < N; k++){
    i = 0;
    for(j = 0; j < 3; j++){
      while(( c = getchar()) != ' ' && c != '\n' && c != EOF){
        tmp[i++] = c;
      }
      tmp[i] = '\0';
      x[j] = atoi(tmp);
      i = 0;
    }
    if(x[0] <= x[1] && x[2] <= x[1]){
      if(x[0] * x[0] + x[2] * x[2] == x[1] * x[1]){
        printf("YES\n");
      }
      else{
        printf("NO\n");
      }
    }
    else if(x[1] <= x[0] && x[2] <= x[0]){
      if(x[2] * x[2] + x[1] * x[1] == x[0] * x[0]){
        printf("YES\n");
      }
      else{
        printf("NO\n");
      }
    }
    else if(x[0] <= x[2] && x[1] <= x[2]){
      if(x[0] * x[0] + x[1] * x[1] == x[2] * x[2]){
        printf("YES\n");
      }
      else{
        printf("NO\n");
      }
    }
  }
  return 0;
}

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

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;

int main(){

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

  sort(d,d+n);
  if(n%2==1)cout << 0 << endl;
  else{
    cout << d[n/2]-d[n/2-1] << endl;
  }


}

Measured memory_bytes: 4436
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>
#include <deque>
#include <iomanip>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);

int main() {
    ll N,K,Q;
    cin >> N >> K >> Q;

    vector<ll> A(N,0);
    for(int i=0;i<Q;i++){
        ll a;
        cin >> a;
        a--;
        A[a]++;
    }
    
    for(int i=0;i<N;i++){
        if(Q-K<A[i]) cout << "Yes";
        else cout << "No";

        cout << endl;
    }


    return 0;
}

Measured memory_bytes: 1536
/*
 _____ _             _              _           _ 
|_   _| |__   ___   / \   _ __  ___| |__  _   _| |
  | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
  | | | | | |  __// ___ \| | | \__ \ | | | |_| | |
  |_| |_| |_|\___/_/   \_\_| |_|___/_| |_|\__,_|_|                                                

*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll,ll>
#define msi         map<string,ll>
#define mis         map<ll, string>
#define rep(i,a,b)    for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)
#define trav(a, x) 	for(auto& a : x)
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pair<ll, ll>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define max(a,b)	(a>b?a:b)
#define min(a,b)	(a<b?a:b)

/*	For Debugging	*/
#define DEBUG 		cerr<<"\n>>>I'm Here<<<\n"<<endl;
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
#define what_is(x)  cerr << #x << " is " << x << endl;

std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define DECIMAL(n)  cout << fixed ; cout << setprecision(n);
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace __gnu_pbds;
using namespace std;
#define PI 3.141592653589793
#define N  100005

ll ans;
ll n,m,q;
vi v[4];
vi a;

void fun2(){
	ll tmp,num=0;
	rep(i,0,q)
	{
		tmp=0;
		rep(j,v[0][i]-1,v[1][i]-1){
			tmp+=a[j];
		}
		if(tmp==v[2][i])
			num+=v[3][i];
	}
	ans=max(ans,num);
}


void fun(ll i,ll num){
	if(num<0)
		return;
	if(i==n){
		fun2();
		return;
	}
	rep(j,0,num+1){
		a.pb(j);
		fun(i+1,num-j);
		a.ppb();
	}
	return;
}

void solve()
{
	cin>>n>>m>>q;
	n--;
	rep(i,0,4)
	v[i]=vi(q);
	rep(i,0,q)
	{
		rep(j,0,4)
		cin>>v[j][i];
	}
	fun(0,m-1);
	cout<<ans<<endl;
	return;
}
int main()
{
	FAST
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	TIME
	return 0;
}

Measured memory_bytes: 3796
def partition(A,p,r):
    x=A[r]
    i=p-1
    for j in range(p,r):
        if A[j]<=x:
            i+=1
            m=A[i]
            A[i]=A[j]
            A[j]=m
    m=A[i+1]
    A[i+1]="["+str(x)+"]"
    A[r]=m
n=int(input())
A=list(map(int,input().split()))
partition(A,0,n-1)
print(*A)


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

int main() {
  int A, B;
  cin >> A >> B;
  int ans = 0;
  rep(i, B-A+1){
    int tmp = A + i;
    if(tmp/10000 == tmp%10){
      if(tmp/1000 - (tmp/10000)*10 == (tmp%100-tmp%10)/10){
        ans += 1;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    long long n,a;
    scanf("%lld", &n);
    if(n%2==1){
        a = 2*n;
    }
    else if(n%2==0){
        a = n;
    }
    printf("%lld\n", a);
    return 0;
}


Measured memory_bytes: 128
N,M = map(int,input().split())
AC,WA = 0,0
was = [0]*(N+1)
acs = [0]*(N+1)
for i in range(M):
    p,S = input().split()
    p = int(p)
    if S=="AC":
        if acs[p]==0:
            AC+=1
            WA+=was[p]
            acs[p]=1
    else:
        was[p] += 1
print(AC,WA)

Measured memory_bytes: 4596
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut 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)*}
    };
}

#[warn(unused_macros)]
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:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: i64,
        b: i64,
    }
    let mut ans = 0;
    let mut now = 1;
    while now < b {
        now += a - 1;
        ans += 1;
    }
    println!("{}", ans);
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef pair<int, int> P;

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

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

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

int main()
{   
    //0 01 10 11
    string s;
    cin >> s;
    int n = s.size(); --n;
    
    ll ans = 0;
    rep(bit, 1<<n) {
        ll t = (s[0]-'0');
        rep(i, n) {
            if(bit & (1<<i)) {
                ans += t;
                t = 0;
            }
            t *= 10;
            t += (s[i+1]-'0');
            //cout << t << endl;
        }
        ans += t;
        //cout << endl;
    } 

    cout << ans << endl;

    return 0;
}


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

int main()
{
	int N;
	scanf("%d", &N); 
	std::vector<int64_t> A(N);
	for (auto& e: A) scanf("%lld", &e);
	std::set<int64_t> primeSet;
	for (auto e: A)
	{
		for (int i{2}; i * i <= e; i++)
		{
			if (e % i) continue;
			primeSet.insert(i);
			while (e % i == 0) e /= i;
		}
		if (e > 1) primeSet.insert(e);
	}
	int64_t max{};
	for (auto& e: primeSet)
	{
		int64_t sum{};
		for (auto& f: A)
			if (f % e == 0)
				sum += f;
		max = std::max(max, sum);
	}
	printf("%lld\n", max);

	return 0;
}


Measured memory_bytes: 3252
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
3
0.0 0.0
2.0 0.0
1.0 1.0

output:
1.41421356237
"""

import math
import sys
from operator import attrgetter


class ClosestPair(object):
    def __init__(self, ):
        """
        Init closest pairs points set.
        """
        _input = sys.stdin.readlines()
        p_num = int(_input[0])
        points = map(lambda x: x.split(), _input[1:])
        p_list = [complex(float(x), float(y)) for x, y in points]
        p_list.sort(key=attrgetter('real'))
        # assert len(p_list) == p_num
        # print(p_list)
        ans = self.closest_pair(array=p_list, array_length=p_num)
        print(('{:.6f}'.format(ans)))

    def closest_pair(self, array, array_length):
        if array_length <= 1:
            return float('inf')
        mid = array_length // 2
        mid_real = array[mid].real
        d = min(self.closest_pair(array[:mid], mid).real,
                self.closest_pair(array[mid:], array_length - mid).real)

        return self.brute_force(array, mid_real, d)

    @staticmethod
    def brute_force(array, mid_real, d=float('inf')):
        array.sort(key=attrgetter('imag'))
        min_stack = list()
        for ele in array:
            size = len(min_stack)
            if abs(ele.real - mid_real) >= d:
                continue

            for j in range(size):
                dx = ele.real - min_stack[size - j - 1].real
                dy = ele.imag - min_stack[size - j - 1].imag
                if dy >= d:
                    break
                d = min(d, math.sqrt(dx ** 2 + dy ** 2))

            min_stack.append(ele)

        return d


if __name__ == '__main__':
    case = ClosestPair()

Measured memory_bytes: 23592
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll int64_t
#define all(v) v.begin(), v.end()
#define bitrep(n) for(int bit=0;bit<(1<<n);bit++)


int main() {

  double N; cin >> N;

 cout << setprecision(18) << endl;

 cout << 2*N*3.1415926535 << endl;

  return 0;
}

Measured memory_bytes: 3784
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string S;
    cin>>S;
    if(S=="Sunny")cout<<"Cloudy"<<endl;
    else if(S=="Cloudy")cout<<"Rainy"<<endl;
    else if(S=="Rainy")cout<<"Sunny"<<endl;
}


Measured memory_bytes: 256
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

a = 0
b = 0
c = 0

ans = 0
for _ in range(X+Y):
    if a < X and b < Y and c < C:
        if p[a] >= q[b] and p[a] >= r[c]:
            ans += p[a]
            a += 1
        elif q[b] >= p[a] and q[b] >= r[c]:
            ans += q[b]
            b += 1
        else:
            ans += r[c]
            c += 1
    elif a >= X and b < Y and c < C:
        if q[b] >= r[c]:
            ans += q[b]
            b += 1
        else:
            ans += r[c]
            c += 1
    elif a < X and b >= Y and c < C:
        if p[a] >= r[c]:
            ans += p[a]
            a += 1
        else:
            ans += r[c]
            c += 1
    elif a < X and b < Y and c >= C:
        if p[a] >= q[b]:
            ans += p[a]
            a += 1
        else:
            ans += q[b]
            b += 1
    elif a >= X and b < Y and c >= C:
        ans += q[b]
        b += 1
    elif a < X and b >= Y and c >= C:
        ans += p[a]
        a += 1
print(ans)

Measured memory_bytes: 105444
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}


int main() {
  ll k,n;
  cin >> k >> n;
  vl a(n);
  rep(i,n){
    cin >> a[i];
  }
  vl ii_(n);
  ii_[0]=(k-a[n-1])+a[0];
  rep2(i,1,n){
    ii_[i]=a[i]-a[i-1];
  }
  sort(ii_.begin(),ii_.end());
  cout << k-ii_[n-1] << endl;
}


Measured memory_bytes: 3328
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
#define fi first
#define se second
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef vector<vi> vvi;
int main() {
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int a,b;
	cin>>a>>b;
	a=(a+1)/2;
	if(b>a)cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
    return 0;
}

Measured memory_bytes: 256
import fractions
x,y=map(int,input().split())
cnt=1
a,b=x,x*2
while True:
    if b<=y:
        g=a*b//fractions.gcd(a,b)#最小公倍数
        a,b=b,2*g
        cnt+=1
    else:
        break
print(cnt)

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

int main(){
	int a,b; cin>>a>>b;
	int h=a*b;
	int r=a*1+b*1-1;
	cout << h-r << endl;	
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int i,t,arr[200001],count=0,mn;
    scanf("%d",&t);
    for(i=0;i<t;i++)
    {
        scanf("%d",&arr[i]);
    }

     mn = 300000;
    for(i=0;i<t;i++)
    {
        if(arr[i]<=mn)
        {
            count++;
            mn = arr[i];
        }
    }
    printf("%d\n",count);
return 0;
}


Measured memory_bytes: 896
/*ANKON GHOSH
  KUET,ECE 2K16*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define MAX 3100
#define mod 1000000007
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define Case(i) cout<<"Case #"<<i<<": "
#define pf(a) printf("%lld\n",a)
#define pfsn printf("NO\n")
#define pfs  printf("YES\n")
#define pff(a,b) printf("%lld %lld\n",a,b)
#define pfff(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define pffff(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define LOOP(x,y) for(ll r=x;r<=y;r++)
#define RFOR(i,n) for(ll i=n-1;i>=0;i--)
#define RFOR1(i,n) for(ll i=n;i>0;i--)
#define RLOOP(x,y) for(ll i=y;i>=x;i--)
#define m_p(a,b) make_pair(a,b)
#define p_b(a) push_back(a)
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
map<ll,ll>mp1,mp;
vector<pair<ll,pair<ll,ll> > >vpp,vpp1;
vector<pair<ll,ll> >vp,fin;
vector<ll>v1,v2,dummy;
map<pair<ll,ll>,bool>mbb;
map<ll,bool>mb;
vector<double>v;
ll n,k,a,b,c,d,ta,sum=0,cnt=0,m,l,req,sz,maxi;
bool sortbysec(const pair<pair<ll,ll>,ll> &a,const pair<pair<ll,ll>,ll> &b)
{
    return (a.second < b.second);
}
///vector<pair<ll,ll> >adj[MAX+10];
double dp[MAX][MAX];
bool visited[MAX][MAX];
double calc(ll pos,ll nisi)
{
    if(pos>=n)
    {
        if(nisi>=req) return 1.0;
        else return 0.0;
    }
    else if(visited[pos][nisi]==true) return dp[pos][nisi];
    double r1=0.00,r2=0.0;
    double head=v[pos];
    double tail=1.00-v[pos];
    r1+=(calc(pos+1,nisi+1)*head);
    r2+=(calc(pos+1,nisi)*tail);
    visited[pos][nisi]=true;
    return dp[pos][nisi]=r1+r2;
}
int main()
{
    sf(n);
    req=(n+2)/2;
    memset(dp,-1.0,sizeof dp);
    memset(visited,false,sizeof visited);
    FOR(i,n)
    {
        double a;
        scanf("%lf",&a);
        v.p_b(a);
    }
    double ans=calc(0,0);
    printf("%.10lf",ans);
    return 0;
}


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

n = int(input())
a = list(map(int,input().split()))

a_sum = sum(a)

flag = True
sum2 = 0
for i in range(n):
    sum2 += a[i] ** 2
    if i >= 1:
        if a[i] != a[i-1]:
            flag = False

cand = []
for i in range(-100,101):
        cand.append(sum2 - 2 * i * a_sum + n * (i ** 2))

print(min(cand))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll ;
int main() {
  int x1 , y1 , x2 , y2 ;
  cin >> x1 >> y1 >> x2 >> y2 ;
  cout << x2 + y1 - y2 << endl;
  cout << y2 + x2 - x1 << endl;
  cout << x1 + y1 - y2 << endl;
  cout << y1 + x2 - x1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int N,A,B;
  cin >> N >> A >> B;
  if(N*A>=B){cout <<  B << endl;}
  else{cout << N*A <<endl;}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define INF 1000000000000000
#define fi first
#define se second
#define all(v) v.begin(),v.end()
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
struct edge{int to,cost;};
typedef pair<int,int> P;
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){//線分の交差判定
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
int kaijo(int n){
	int ans=1;
	for(int i=2;i<=n;i++){
		ans*=i;
		ans%=MOD;
	}
	return ans;
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	return modpow(a,b/2)*modpow(a,b/2)%MOD;
}
int comb(int a,int b){
	return kaijo(a)*modpow(kaijo(a-b),MOD-2)%MOD*modpow(kaijo(b),MOD-2)%MOD;
}
int n;
vector<P>v[111111];
int memo[111111];
void dfs(int x){
	for(P p:v[x]){
		if(memo[p.first]!=2)continue;
		if(p.second%2==0){
			memo[p.first]=memo[x];
			dfs(p.first);
		}
		else{
			memo[p.first]=1-memo[x];
			dfs(p.first);
		}
	}
}
signed main(){
	cin>>n;
	fill(memo,memo+n,2);
	rep(i,n-1){
		int a,b,c;
		cin>>a>>b>>c;
		a--,b--;
		v[a].push_back({b,c});
		v[b].push_back({a,c});
	}
	memo[0]=0;
	dfs(0);
	rep(i,n)cout<<memo[i]<<endl;
	return 0;
}


Measured memory_bytes: 10496
#include <bits/stdc++.h>
using namespace std;
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        string s;
        in >> s;
        stack<char> st;
        for (int i = 0; i < s.size(); i++) {
            if (s[i] == 'S') {
                st.emplace(s[i]);
            }
            else {
                if (st.size() == 0) {
                    st.emplace(s[i]);
                }
                else if (st.top() == 'S') {
                    st.pop();
                }
                else {
                    st.emplace(s[i]);
                }
            }
        }
        out << st.size() << '\n';
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


Measured memory_bytes: 720
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
public class Main {
	public static void main(final String[] args){
    int sum = 0;
    Scanner sc = new Scanner(System.in);
    int[][] bingo = new int[3][3];
    int[] num = new int[10];
    for(int i = 0; i < 3 ; i++){
        for(int j = 0; j < 3 ; j++){
            bingo[i][j] = sc.nextInt();
        }
    }

    int n = sc.nextInt();

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

    for(int i = 0; i < n ; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3 ; k++){
                if(num[i] == bingo[j][k]){
                    bingo[j][k] = 0;
                }
            }
        }
    }
    if(bingo[0][0]==0 && bingo[0][1]==0 && bingo[0][2]==0){
        System.out.println("Yes");
    }else if(bingo[1][0]==0 && bingo[1][1]==0 && bingo[1][2]==0){
        System.out.println("Yes");
    }else if(bingo[2][0]==0 && bingo[2][1]==0 && bingo[2][2]==0){
        System.out.println("Yes");
    }else if(bingo[0][0]==0 && bingo[1][0]==0 && bingo[2][0]==0){
        System.out.println("Yes");
    }else if(bingo[0][1]==0 && bingo[1][1]==0 && bingo[2][1]==0){
        System.out.println("Yes");
    }else if(bingo[0][2]==0 && bingo[1][2]==0 && bingo[2][2]==0){
        System.out.println("Yes");
    }else if(bingo[0][0]==0 && bingo[1][1]==0 && bingo[2][2]==0){
        System.out.println("Yes");
    }else if(bingo[2][0]==0 && bingo[1][1]==0 && bingo[0][2]==0){
        System.out.println("Yes");
    }else{
        System.out.println("No");
    }
    
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
int n,tot;
ll k;
ll a[N],b[N],hs[N],t[N<<2];
int vis[N];
void build(int l,int r,int k)
{
    if(l==r) {t[k]=vis[l];return;}
    int m=l+r>>1;
    build(l,m,k<<1);build(m+1,r,k<<1|1);
    t[k]=t[k<<1]+t[k<<1|1];
}
ll query(int l,int r,int k,ll x)
{
    if(hs[l]>x||!t[k]) return -1;
    if(l==r) {t[k]--;return hs[l];}
    int m=l+r>>1;
    ll ans=query(m+1,r,k<<1|1,x);
    if(ans==-1) ans=query(l,m,k<<1,x);
    t[k]=t[k<<1]+t[k<<1|1];
    return ans;
}
ll querymn(int l,int r,int k)
{
    t[k]--;
    if(l==r) return hs[l];
    int m=l+r>>1;
    if(t[k<<1]) return querymn(l,m,k<<1);
    return querymn(m+1,r,k<<1|1);
}
bool judge(ll m)
{
    ll p=k;
    build(1,tot,1);
    for(int i=n;i>=1;i--)
    {
        ll x=query(1,tot,1,m/a[i]);
        if(x==-1)
        {
            x=querymn(1,tot,1);
            x=m/x;
            p-=a[i]-x;
            if(p<0) return false;
        }
    }
    return true;
}
int main()
{
    scanf("%d%lld",&n,&k);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    for(int i=1;i<=n;i++) scanf("%lld",&b[i]),hs[i]=b[i];
    sort(a+1,a+1+n);
    sort(hs+1,hs+1+n);
    tot=unique(hs+1,hs+1+n)-hs-1;
    for(int i=1;i<=n;i++) b[i]=lower_bound(hs+1,hs+1+tot,b[i])-hs;
    for(int i=1;i<=n;i++) vis[b[i]]++;
    ll l=0,r=4e17,ans;
    while(l<=r)
    {
        ll m=l+r>>1;
        if(judge(m)) ans=m,r=m-1;
        else l=m+1;
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 11904
/* Author : Prasuk Jain */
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define int              long long int
#define ull              unsigned long long
#define ld               long double
#define fo(i, n)         for(int i=0; i<n; i++)
#define FOR(i, a, b)     for(int i=a; i<b; i++)
#define rfor(i, n)       for(int i=n-1; i>=0; i--)
#define RFOR(i, a, b)    for(int i=b-1; i>=a; i--)
#define tr(it, v)        for(auto it=a.begin(); it!=a.end(); it++)
#define vi               vector<int>
#define pii              pair<int,int>
#define mii              map<int,int>
#define pqb              priority_queue<int>
#define pqs              priority_queue<int,vi,greater<int>>
#define mp               make_pair
#define pb(x)            push_back(x)
#define hcf(x, y)        __gcd(x, y)
#define lcm(x, y)        boost::math::lcm(x,y)
#define setpre(x, y)     fixed << setprecision(y) << x
#define setbits(x)       __builtin_popcountll(x)
#define zerolead(x)      __builtin_clzll(x)
#define zerotrail(x)     __builtin_ctzll(x)
#define all(x)           x.begin(), x.end()
#define sortall(x)       sort(all(x))
#define PI               3.1415926535897932384626
const int mod = 1e9+7;
const int inf = 1e18;
int mpow(int base, int exp);
bool isprime(int num);
void prifact(int num);

//*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!//

void coderprasukj(){ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

int32_t main() {
    //coderprasukj();
    int s,w;
    cin >> s >> w;
    if(w>=s) cout << "unsafe\n";
    else cout << "safe\n";
    return 0;
}

//*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!//

int mpow(int base, int exp) {
    base %= mod;
    int result = 1;
    while (exp > 0) {
        if (exp & 1) result = ((int)result * base) % mod;
        base = ((int)base * base) % mod;
        exp >>= 1;
    }
  return result;
}

bool isprime(int num) {
    if(num <= 1) return false;
    for(int i=2; i*i <= num; i++)
        if(num%i == 0) return false;
    return true;
}

void prifact(int num){
    for(int i=2; i<=num; i++)
    if(num%i == 0){
        int cnt = 0;
        while(num%i == 0)
        cnt++ , num /= i;
        cout << i << "^" << cnt << " ";
    }
    if(num > 1)
    cout << num << "^" << "1" << " ";
}


Measured memory_bytes: 3632
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] dlist = Console.ReadLine().Split(' ');

            int[] ds = new int[N];

            for(int i = 0; i<N; i++)
            {
                ds[i] = int.Parse(dlist[i]);
            }

            long sum = 0;
            for(int i = 0; i<N; i++)
            {
                for(int j = i + 1; j<N; j++)
                {
                    sum += ds[i] * ds[j];
                }
            }

            Console.WriteLine(sum);
            //Console.ReadKey();

        }
    }
}


Measured memory_bytes: 11092
import java.io.*;
import java.util.*;
import java.math.*;
     
public class Main{
	public static void main(String[] args) throws Exception {
	IO io = new IO();
	PrintWriter out = new PrintWriter(System.out);
	Solver sr = new Solver();
	sr.solve(io,out);
	out.flush();
	out.close();
    	}

	static class Solver
	{
      	int dfs(int[][] ar, int i, int m, int n, int dp[][])
        {
          if(i>n)
            return 0;
          if(dp[i][m]!=-1)
            return dp[i][m];
          int max = -1;
          for(int j=1 ; j<=3 ; j++){
            if(j!=m)
            	max = Math.max(max,ar[i][j]+dfs(ar,i+1,j,n,dp));
          }
          return dp[i][m] = max;
        }
        void solve(IO io, PrintWriter out)
        {
            int t = 1;
            while(t-->0)
            {
                int n = io.nextInt();
              	int[][] ar = new int[n+1][4];
              	for(int i=1 ; i<=n ; i++)
                  for(int j=1 ; j<=3 ; j++)
                  	ar[i][j] = io.nextInt();
                
              	int dp[][] = new int[n+1][4];
              	for(int i=0 ; i<=n ; i++)
              		Arrays.fill(dp[i],-1);
              	
              	out.print(dfs(ar,1,0,n,dp));
            }
	    }
	}
	//Special thanks to Petr (on codeforces) who inspired me to implement IO class!
	static class IO
	{
    	private static final int BUF_SIZE = 2048;
        BufferedReader br;
        private IO() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        private boolean isSpace(char c) {
            return c == '\n' || c == '\r' || c == ' ';
        }
        String next() {
            try {
                StringBuilder sb = new StringBuilder();
                int r;
                while ((r = br.read()) != -1 && isSpace((char) r));
                if (r == -1) {
                    return null;
                }
                sb.append((char) r);
                while ((r = br.read()) != -1 && !isSpace((char) r)) {
                    sb.append((char) r);
                }
                return sb.toString();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
	}
}

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

int main(){
  int N,a,b,c,d;
  
  cin >> N;
  
  a=N/1000;
  b=N/100-10*a;
  c=N/10-100*a-10*b;
  d=N-1000*a-100*b-10*c;
  
  if((a==b && b==c)||(b==c && c==d)){
    cout <<"Yes"<<endl;
  }
  else {
    cout <<"No"<<endl;
  }
}

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

int main(int argc, char **argv)
{
    int N;
    std::cin >> N;

    std::vector<int> A(N);
    for(int i = 0; i < N; i++){
        std::cin >> A.at(i);
    }

    int odds = 0;
    for(int i = 0; i < N; i++){
        if(A.at(i) % 2 == 1) odds++;
    }

    if(odds % 2 == 1){
        std::cout << "NO" << std::endl;
    }else{
        std::cout << "YES" << std::endl;
    }
    
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
using namespace std;
const int MAX = 1e5 + 10;
const int MOD = 1e9 + 7;
int N, M, K, Q;
int A[MAX];
int idx[MAX];
ll nc[MAX], rc[MAX];
ll fexp(ll b, ll e) {
	if (e == 0) return 1LL;
	if (e == 1) return b;
	ll tmp = fexp(b, e/2);
	return tmp * tmp % MOD * fexp(b, e % 2) % MOD;
}

void comb(ll n, ll *xc) {
	xc[0] = 1LL;
	for (ll i = 1; i <= n; ++i) {
		xc[i] = xc[i-1] * (n - i + 1) %MOD * fexp(i, MOD - 2) %MOD;
	}
}

int main()
{
	int i, j, k;
	int fc, bc;
	scanf("%d", &N);

	for (i = 1; i <= N + 1; ++i) {
		scanf("%d", &A[i]);
		if (idx[A[i]]) {
			fc = (idx[A[i]] - 1);
			bc = (N + 1 - i);
		}
		else idx[A[i]] = i;
	}
	
	comb((ll)(N + 1), nc);
	comb((ll)(fc + bc), rc);

	for (k = 1; k <= N + 1; ++k) {
		printf("%lld\n", (nc[k] - rc[k - 1] + MOD) % MOD);
	}

}

Measured memory_bytes: 3584
#include<cmath>
#include<cstdio>
#include<vector>
using namespace std;
struct node{
    int u, v, w;
    node(int _u, int _v, int _w):u(_u), v(_v), w(_w){}
};
vector<node>ans;
inline int lowbit(int x) {
    return x & -x;
}
int main() {
    int L;
    scanf("%d", &L);
    for(int i=19;i>1;i--) {
        ans.push_back(node(i, i+1, 0));
        ans.push_back(node(i, i+1, (1<<(20-i-1))));
    }
    while( L ) {
        int p = int(log2(lowbit(L)));
        if( p == 19 ) {
            ans.push_back(node(1, 2, 0));
            ans.push_back(node(1, 2, 1<<18));
        }
        else ans.push_back(node(1, 20-p, L^lowbit(L)));
        L ^= lowbit(L);
    }
    printf("%d %d\n", 20, ans.size());
    for(int i=0;i<ans.size();i++)
        printf("%d %d %d\n", ans[i].u, ans[i].v, ans[i].w);
} 

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
using namespace std;
typedef pair<int,int> P;//Pでpair<-,->を表す。
typedef long long LL; 
LL MOD=1000000007;

int main()
{ 
    int n;
    cin>>n;
    cout<<n*n*n<<endl;
    return 0;
}

Measured memory_bytes: 256
# include <cstdio>
# include <iostream>
# define R register int

using namespace std;

const int maxn=102;
int n,w;
int x[maxn],y[maxn],h[maxn];

inline int ab (int a) { if(a<0) return -a; return a; }

inline bool check (int cx,int cy)
{
	int hh,X=2000000005;
	w=-1;
	for (R i=1;i<=n;++i)
	{
		if(h[i]==0)
		{
			if(w==-1)
			{
				X=min(X,ab(x[i]-cx)+ab(y[i]-cy));
				continue;
			}
			if(w-ab(x[i]-cx)-ab(y[i]-cy)>0) return false;
			continue;
		}
		hh=ab(x[i]-cx)+ab(y[i]-cy)+h[i]; 
		if(w==-1) w=hh;
		if(hh!=w) return false;
	}
	if(w==-1) return false;
	if(w>X) return false;
	return true;
}

int main()
{
	scanf("%d",&n);
	for (R i=1;i<=n;++i)
		scanf("%d%d%d",&x[i],&y[i],&h[i]);
	for (R i=0;i<=100;++i)
		for (R j=0;j<=100;++j)
		{
			if(check(i,j))
			{
				printf("%d %d %d",i,j,w);
				return 0;
			}
		}
	return 0;
} 

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

using namespace std;

int main() {
	int n;
	vector<int> a;
	int minval = 10000000;
	int maxval = -10000000;
	int maxvalpos = 0;
	int minvalpos = 0;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int ai;
		cin >> ai;
		if (minval > ai) {
			minval = ai;
			minvalpos = i;
		}
		if (maxval < ai) {
			maxval = ai;
			maxvalpos = i;
		}
		a.push_back(ai);
	}

	vector<pair<int, int>> res;
	if (abs(maxval) > abs(minval)) {
		for (int i = 0; i < n; ++i) {
			res.push_back(make_pair(maxvalpos, i));
		}
		for (int i = 0; i + 1 < n; ++i) {
			res.push_back(make_pair(i, i+1));
		}
	}
	else {
		for (int i = 0; i < n; ++i) {
			res.push_back(make_pair(minvalpos, i));
		}
		for (int i = n-1; i-1>=0 ; --i) {
			res.push_back(make_pair(i, i-1));
		}
	}
	cout << res.size() << endl;
	for (auto val : res) {
		cout << val.first + 1 << " " << val.second + 1 << endl;
	}
	return 0;
}

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

int main() 
{
    int a,b,k;
    cin >> a >> b >> k;
    if (a+k>b-k)
    {
        for (int i=a; i<=b; i++)
            cout << i << endl;
        return 0;
    }
    for (int i=a; i<a+k; i++)
        cout << i << endl;
    // int x = max(a+k-1,b-k-1);
    // cout << "ab";
    for (int i=b-k+1; i<=b; i++)
        cout << i << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    string str;
    cin >> str;
    int num = static_cast<int>(str.back() - '0');

    if(num == 3)
        str = "bon";
    else if (num == 0 || num == 1 || num == 6 || num == 8)
        str = "pon";
    else {
        str = "hon";
    }
    cout << str << endl;
    return 0;

}

Measured memory_bytes: 3584
#include <iostream>
#include <map>
#define MM multimap<int,int>
using namespace std;
int k[101];
int main()
{
  int n,m,a,h,p,q,i,j;
  for(;;){
    cin >> n >> m >> a;
    if(n==0 && m==0 && a==0)break;
    for(i=1;i<=n;i++){
      k[i] = i;
    }
    multimap<int,int,greater<int> > mp;
    for(i=0;i<m;i++){
      cin >> h >> p >> q;
      mp.insert(MM::value_type(h,p));
    }
    MM::iterator it = mp.begin();
    while(it != mp.end()){
      j = k[(*it).second];
      k[(*it).second] = k[(*it).second+1];
      k[(*it).second+1] = j;
      it++;
    }
    for(i=1;i<=n;i++){
      if(k[i] == a) break;
    }
    cout << i << endl;
  }
  return 0;
}

Measured memory_bytes: 936
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define mxn 12
using namespace std;
char s[mxn][mxn];
int n,m,p[mxn],a[mxn];
string t[mxn|1];
bool mirror(int l,int r) {
	for(int i=0;i<n;i++)
		if(s[i][l]!=s[p[i]][r])
			return 0;
	return 1;
}
void dfscol(int d,bool b) {
	if(d==m) {	puts("YES");	exit(0);	}
	if(~a[d]) {	dfscol(d+1,b);	return;	}
	for(int i=d+1;i<m;i++)
		if(a[i]==-1&&mirror(d,i)) {
			a[d]=i,a[i]=d;
			dfscol(d+1,b);
			a[d]=-1,a[i]=-1;
		}
	if(b&&mirror(d,d))	a[d]=d,dfscol(d+1,0),a[d]=0;
}
void dfsrow(int d,bool b) {
	if(d==n) {	dfscol(0,m&1);	return;	}
	if(~p[d]) {	dfsrow(d+1,b);	return;	}
	for(int i=d+1;i<n;i++)
		if(p[i]==-1&&t[d]==t[i]) {
			p[d]=i,p[i]=d;
			dfsrow(d+1,b);
			p[d]=-1,p[i]=-1;
		}
	if(b)	p[d]=d,dfsrow(d+1,0),p[d]=0;
}
int main() {
	memset(p,-1,sizeof(p));
	memset(a,-1,sizeof(a));
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++) {
		scanf("%s",s[i]);
		for(int j=0;j<m;j++)
			t[i]+=s[i][j];
		sort(t[i].begin(),t[i].end());
	}
	dfsrow(0,n&1);
	puts("NO");
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")   //Comment optimisations for an interative problem/use endl
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;  
typedef pair<ll, ll> pll; 
typedef pair<string, string> pss;  
typedef vector<pll> vpll; 
typedef vector<ll> vll; 
typedef vector<vll> vvll; 
typedef unordered_map<ll,ll> um;

#define fastio ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define sqr(x) ((ll)(x) * (x)) 
#define reset(a, b) memset(a, b, sizeof(a)) 
#define f first 
#define s second 
#define mp make_pair 
#define pb push_back 
#define all(v) v.begin(), v.end() 
#define alla(arr, sz) arr, arr + sz 
#define showv(v) for(auto it: (v))cout<<it<<" ";newl;
#define newl cout<<"\n"

const ll MAXN=1e+2+7;
const ll MOD=1e+9+7, INF=0x7f7f7f7f7f7f7f7f;const int INFi=0x7f7f7f7f;
double EPS = 1e-9;  
double PI = acos(-1); 

vll adj[MAXN];ll visit[MAXN]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1},dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

//<<-----Declare Variable Here------->>//
ll t,n;
ll i,j;
string s;
ll p;
map<ll,ll>map1;
ll count1,count2;
ll visited[100007] = {};
 
//<<-----Implement Functions Here---->>//
 
 
//<<-----Start of Main--------------->>//

int main()
{
	

	fastio;
	ll n,m;cin >> n >> m;
	for(i=0;i<m;i++)
	{
		cin >>p>>s;
		if(!visited[p])
		{
			if(s == "WA")map1[p]++;
			else visited[p] =1;
		}
	}
	for(i = 1;i<=n;i++)
	{
		if(visited[i])
		{
			count1++;count2+=map1[i];
		}
	}
	cout<<count1<<" "<<count2;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,A,B,L;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MOD = (1e+9) + 7;

int main() {
    cin>>N>>K;
    vec a(N,0);
    rep(i,N) cin>>a[i];
    mat next(60,vec(N,0));
    ll INF = 3LL * (1e+17);
    rep(i,N) next[0][i] = i+N;
    //if(K == 1) rep(i,N) next[0][i] = INF;
    vec last(200010,-1), first(200010,-1);
    rep(i,N){
        if(last[a[i]] == -1){
            last[a[i]] = i;
            first[a[i]] = i;
        }else{
            next[0][last[a[i]]] = i;
            next[0][i] = first[a[i]]+N;
            last[a[i]] = i;
        }
    }
    reps(i,1,60){
        rep(j,N){
            ll ne = next[i-1][j] + 1;
            next[i][j] = min(INF,next[i-1][ne%N] + (ne/N)*N);
        }
    }
    //ポイント：ダブリング作成のためにmat全体を求めるが、使うのはnext[i][0]のみ
    ll begin = 0;
    while(begin < N*(K-1)) {
        ll ub = 60, lb = -1; // [lb,ub)ではある
        while (ub - lb > 1) {
            ll cen = (ub + lb) / 2;
            if (next.at(cen)[begin%N] + (begin/N)*N >= N * K) ub = cen;
            else lb = cen;
            //if(begin == 33) cout<<ub<<' '<<lb<<endl;
        }
        if(lb == -1) {
            begin = 0;
            break;
        }else{
            begin = next[lb][begin%N] + (begin/N)*N + 1;
        }
        //cout<<begin<<endl;
    }
    if(begin == N*K){
        cout<<' '<<endl;
        return 0;
    }
    begin %= N;
    vec ans(0);
    /*rep(i,N) cout<<next[0][i]<<' ';
    cout<<endl;
    rep(i,N) cout<<next[1][i]<<' ';
    cout<<endl;
    rep(i,N) cout<<next[2][i]<<' ';
    cout<<endl;
    rep(i,N) cout<<next[3][i]<<' ';
    cout<<endl;
    rep(i,N) cout<<next[4][i]<<' ';
    cout<<endl;*/
    reps(i,begin,N){
        ll ne = next[0][i];
        //cout<<ne<<' '<<i<<endl;
        if(ne < N){
            i = ne;
        }else{
            ans.push_back(a[i]);
        }
    }
    rep(i,ans.size()) cout<<ans[i]<<' ';
    cout<<endl;
}


Measured memory_bytes: 103652
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    // cominit();
    ll ans = 0;
    ll mmin = 0;
    ll mmax = 0;
    rep(i, k){
        mmin += i;
        mmax += n-i;
    }
    for(ll i=k; i<=n+1; i++){
        ans = (ans + mmax - mmin + 1)%mod;
        mmax += n-i;
        mmin += i;

    }

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


Measured memory_bytes: 3608
def root(x):
    if r[x] < 0:
        return x
    else:
        r[x] = root(r[x])
        return r[x]
def unite(x, y):
    x = root(x)
    y = root(y)
    if x != y:
        if r[x] > r[y]:
            x,y = y,x
        r[x] += r[y]
        r[y] = x
n,m = map(int,input().split())
r = [-1] * n
for i in range(m):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    unite(a,b)
ans = 0
for i in r:
    if i < 0:
        ans += 1
print(ans-1)


Measured memory_bytes: 10648
#include<stdio.h>
#include<string.h>
int main ()
{
    int i,n,count=0;
    char str[200];
    int ara[225];
    for(i=65; i<=122; i++)
    {
        ara[i]=0;
    }
    scanf("%s",str);
    n=strlen(str);
    for(i=0; i<n; i++)
    {
        ara[str[i]]++;
    }
    for(i=65; i<=122; i++)
    {
        if(ara[i]%2==1){
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}


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

int n, x ;

int a[110] ;

int main(){
	#define NAME "agc027"
	//freopen( NAME".inp" , "r" , stdin ) ; freopen( NAME".out" , "w" , stdout ) ;

	ios_base :: sync_with_stdio(false) ;

	cin >> n >> x ;

	for (int i = 1; i <= n; ++ i) cin >> a[i] ;

	sort(a + 1, a + n + 1) ;
	
	int sum = 0 ;

	for (int i = 1; i <= n; ++ i){
		sum += a[i] ;
		if(sum > x) return cout << i - 1, 0 ;
	}
	if(sum == x) cout << n << endl ;
	else cout << n - 1 << endl ;

	return 0 ;
}


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

int main()
{
    string str;
    cin>>str;

    int i, j=str.length()-1, count=0;

    for(i=0; i<str.length()/2; i++)
    {
        if(str[i] != str[j])
            count++;
        j--;
    }

    cout<<count;
}


Measured memory_bytes: 256
//a.c A-AtCoder Beginner Contest 999
#include<stdio.h>

int main(void){
    int n,co=1;
    scanf("%d",&n);
    int m=0;
    for(int i=0;i<3;++i){
        if(n%10==1){
            m += 9*co;
        }else{
            m += 1*co;
        }
        n /= 10;
        co *= 10;
    }
    printf("%d\n",m);
    return 0;
}

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

int main() {
  int k, t;
  cin >> k >> t;
  int a[t];
  for (int i = 0; i < t; i++) {
    cin >> a[i];
  }
  sort(a, a + t);
  int sum = 0;
  for (int i = 0; i < t - 1; i++) {
    sum += a[i];
  }
  int ans = a[t - 1] - sum - 1;
  cout << max(0, ans) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    if(A==B&&A!=C){
        cout << "Yes" << endl;
        return 0;
    }
    if(B==C && A!=C){
        cout <<"Yes"<<endl;
        return 0;
    }
    if(C==A && B!=C){
        cout <<"Yes"<<endl;
        return 0;
    }
    cout << "No"<<endl;


    return 0;
}


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

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



int N,M;
vector<int> ev[602020];
int did[602020];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	int ret=0;
	cin>>N>>M;
	FOR(i,N) {
		cin>>x>>y;
		x+=M;
		ev[y].push_back(x);
		ev[y+M].push_back(x+M);
	}
	
	multiset<int> ed;
	int ma=0;
	FOR(i,3*M) {
		FORR(e,ev[i]) ed.insert(e);
		while(ed.size() && *ed.begin()<i) ed.erase(ed.begin());
		
		if(i) did[i]=did[i-1];
		if(ed.size()) {
			did[i]++;
			ed.erase(ed.begin());
		}
		if(i>M) ma=max(ma,did[i]-did[i-M]);
	}
	
	cout<<N-ma<<endl;
}


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


Measured memory_bytes: 31084
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define MOD 1000000007
#define REP(i,n) for(i=1;i<=n;i++)
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define REPD(i,n) for(i=n;i>=1;i--)
#define FORD(i,a,b) for(i=a;i>=b;i--)
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define gcd(a,b) __gcd(a,b)
#define vl vector<LL>
#define itr ::iterator it
#define lb lower_bound
#define ub upper_bound
#define print(vec) for(auto it = arr.begin();it!=arr.end();it++)  cout<<*it<<" ";  cout<<endl;
#define print2(x,y)  cout<<x<<" "<<y<<endl;
#define print3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define LL long long
#define ULL unsigned long long
LL n,i,j,ans = 0;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    LL sum = 0 ;
    LL cnt = 0 ;
    LL temp = n,x;
    while(n!=0)
    {   x = n%10 ;
        sum+=x;
        n = n/10;
        cnt++ ;
    }
    //LL y = temp/(x*10) ;
    //cout<<sum<<" "<<cnt<<" "<<<<endl;
    cout<<max(sum,(cnt-1)*9+x-1LL)<<endl ;

}


Measured memory_bytes: 256