akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  int n;
  char boin[5]={'a','i','u','e','o'};
  int maxlength=0;
  while(1){
    cin >> n;
    if(!n) return 0;
    string s;
    vector<string> code(n,"");
    for(int i=0;i<n;i++){
      cin >> s;
      maxlength=max(maxlength,s.length());
      code[i]+=s[0];
      for(int j=0;j<s.length()-1;j++){
        for(int k=0;k<5;k++){
          if(s[j]==boin[k]){
            code[i]+=s[j+1];
          }
        }
      }
      //cout << code[i] << endl;
    }
    int flag=false;
    int ans;
    for(int i=1;i<=maxlength;i++){
      flag=false;
      for(int j=0;j<n;j++){
        for(int k=j+1;k<n;k++){
          if(code[j].substr(0,i)==code[k].substr(0,i)) flag=true;
        }
      }
      if(!flag){
        ans=i;
        break;
      }
    }
    if(!flag){
      cout << ans << endl;
    }else{
      cout << -1 << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3144
#include <stdio.h>

int main(void){
	int i,j;
	int n,m;
	int count[10];

	while(scanf("%d",&n), n){
		for(i=0;i<10;i++) count[i] = 0;
		for(i=0;i<n;i++){
			scanf("%d",&m);
			count[m]++;
		}
		for(i=0;i<10;i++){
			if(count[i] == 0) printf("-");
			else for(j=0;j<count[i];j++) putchar('*');
			putchar('\n');
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
int main() {
  int x,y,a,b;
  int total;
	scanf("%d %d\n",&x,&y);
  if(x==1){
a=300000;
  }
  else if(x==2){
    a=200000;
  }
  else if(x==3){
    a=100000;
  }
  else{
    a=0;
  }
  
  if(y==1){
    b=300000;
  }
  else if(y==2){
    b=200000;
  }
  else if(y==3){
    b=100000;
  }
  else{
    b=0;
  }
  total=a+b;
  
  if(x==1 && y==1){
    total=total+400000;
  }
  
	printf("%d\n",total);
	return 0;
}

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

int main(){
  int N,L;
  cin >> N >> L;
  vector<string> S(N);
  for(int i=0;i<N;i++){
    cin >> S.at(i);
  }
  sort(S.begin(),S.end());
  string answer;
  for(int i=0;i<N;i++){
    answer += S.at(i);
  }
  cout << answer << endl;
}

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

int main() {
  ll N, x;
  cin >> N >> x;

  ll a[N];
  for (int i = 0; i < N; i++) cin >> a[i];

  ll ans = 0;
  for (int i = 0; i < N - 1; i++) {
    if (a[i] + a[i + 1] > x) {
        
      ans += a[i + 1] + a[i] - x;

      if (a[i] >= x) {
        a[i + 1] = 0;
        a[i] = x;
      } else
        a[i + 1] = x - a[i];
    }
  }

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

Measured memory_bytes: 1024
#include <iostream>
#include <utility>
#include <algorithm>

using namespace std;

int N, M;
pair<int, int> PD[10010];

int main(void) {
  while (1) {
    cin >> N >> M;
    if (N == 0 && M == 0) break;
    int d, p;
    for (int i = 0; i < N; i++) {
      cin >> d >> p;
      PD[i] = make_pair(p, d);
    }
    sort(PD, PD + N);
    long long sum = 0;
    for (int i = 0; i < N; i++) {
      sum += PD[i].first * PD[i].second;
    }
    int i = N-1;
    while (M) {
      if (M >= PD[i].second) {
	M -= PD[i].second;
	sum -= PD[i].first * PD[i].second;
      } else {
	sum -= PD[i].first * M;
	M = 0;
      }
      i--;
      if (i == -1) break;
    }
    cout << sum << endl;
  }
  return 0;
}
      

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


int main() {
	int i;
	int n,x;
	cin >> n;
	for (i = 1; i <= n; i++) {
		x = i;
		if (x % 3 == 0) {
			cout << " " << i;
		}
		else {
			while (x) {


				if (x % 10 == 3) {
					cout << " " << i;
					break;
				}
				else {
					x /= 10;
				}
			}

		}
	}
	cout << endl;
	return 0;

}


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

s = raw_input()
n = len(s)

cnt = 0;
maxCnt = 0;
for i in range(n):
    if s[i] == 'A' or s[i] == 'C' or s[i] == 'G' or s[i] == 'T':
        cnt += 1
        maxCnt = max(maxCnt, cnt)
    else:
        cnt = 0

print maxCnt

    


Measured memory_bytes: 2696
#include <cstdio>
int n, a[100010];
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++ i) scanf("%d", &a[i]);
	int ans = 1, pre = a[1], how = 0;
	for (int i = 2; i <= n; ++ i) {
		if (a[i] == pre) {
			continue ;
		}
		if (a[i] < pre) {
			if (how == 1) {
				++ ans;
				pre = a[i];
				how = 0;
			} else {
				how = -1;
				pre = a[i];
			}
		}
		if (a[i] > pre) {
			if (how == -1) {
				++ ans;
				pre = a[i];
				how = 0;
			} else {
				how = 1;
				pre = a[i];
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll n,s;
ll data[3005];
ll dp[3005][3005];
const ll mod=998244353;
int main(){
	//freopen("input.txt","r",stdin);
	cin>>n>>s;
	for(ll i=1;i<=n;i++) cin>>data[i];
	dp[0][0]=1;
	for(ll i=1;i<=n;i++) for(ll j=0;j<=s;j++)
	{
		dp[i][j]=dp[i-1][j];
		if(j-data[i]>=0) dp[i][j]+=dp[i-1][j-data[i]];
		if(j==0) dp[i][j]++;  //因为当j-data[i]==0时，a[i]这一个也要算上 
		dp[i][j]%=mod;
	}
	ll ans=0;
	for(ll i=1;i<=n;i++) ans=(ans+dp[i][s])%mod;
	cout<<ans%mod<<endl;
	return 0;
}

Measured memory_bytes: 70656
n = int(input())
a = list(map(int,input().split()))
b = [0]*(n+1)
if n == 0:  # ねっこだけ
    x = a[0]
    if x == 1:
        print(1)
    else:
        print(-1)
    exit()

nows = sum(a)
s = nows
for i in range(n+1):
    if i == 0:
        b[i] = 1 - a[i]
    else:
        nows -= a[i]
        b[i] = min(nows, 2*b[i-1]-a[i])
        if b[i] < 0:  # だめ
            print(-1)
            exit()
print(sum(b) + s)

Measured memory_bytes: 20076
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define all(a) a.begin(), a.end()
#define forn(l, r) for(int i = l; i < (r); ++i)
#define F first
#define S second
#define $ ios::sync_with_stdio(0);
///#define int long long int

using namespace std;
using namespace __gnu_pbds;
using ll = long long int;
using ii = pair<int, int>;
using li = pair<ll, int>;
using vi = vector<int>;
using graph = vector<vi>;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll mod =  1000000007;
const int INF = 0x3f3f3f3f;
const int MAXN = 212345;
// const double pi = 3.14159265359;
const double eps = 0.00000001;

pair<ll, pair<ll, ll>> arr[MAXN];
vector<pair<ll, int>> d;
vector<ll> ans;

int32_t main() {
    
    int n, q;
    cin >> n >> q;
    ans.assign(q, -10);
    ll x;
    ll s, t;
    forn (0, n) {
        scanf("%lld %lld %lld", &s, &t, &x);
        x *= 10ll;
        s *= 10ll;
        t *= 10ll;
        arr[i] = {x, {s - 5ll - x, t - 5ll - x}};
    }
    sort (arr, arr + n);
    set<pair<ll, ll>> st;
    forn (0, q) {
        scanf("%lld", &x);
        x *= 10ll;
        st.insert({x, i});
    }
    set<pair<ll, ll>>::iterator it, kp;
    forn (0, n) {
        if (!st.size()) break;
        s = arr[i].S.F; t = arr[i].S.S; x = arr[i].F;
        kp = it = st.lower_bound({s, 0});
        //cout << "X: " << x << ' ' << ' ' << s << ' ' << t << endl;
        while (it != st.end() && (*it).F <= t) {
            //cout << (*it).S << ' ';
            ans[(*it).S] = x;
            ++it;
        }
        //cout << endl;
        st.erase(kp, it);
    }
    forn (0, q) {
        cout << ans[i]/10ll << '\n';
    }
}



Measured memory_bytes: 20608
#include<iostream>
using namespace std;
int main(void){
	int N, mi = 10000, ma = 0;
	cin >> N;
	for(int i = 0; i < N; i++){
		int a;
		cin >> a;
		mi = min(mi, a);
		ma = max(ma, a);
	}
	cout << ma - mi << endl;
}

Measured memory_bytes: 256
n = int(input())

count = 0
max_count = 0
for i in range(n):
    input_elements = input().split()
    if input_elements[0] == input_elements[1]:
        count += 1
    else:
        if max_count < count:
            max_count = count
        count = 0

if max_count < count:
    max_count = count

if max_count >= 3:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9112
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";}

// #define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
typedef long long ll;
typedef double ld;
#define pll pair<ll,ll>
#define pii pair<int, int>
#define pb push_back
#define mp(x, y) make_pair((x), (y))
#define F first
#define S second
#define I insert
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
   
const ll Mod = 1e9 + 7;
const int N = 1e4 + 7;
const int D = 102;

ll dp[N][D] , ans[N][D];

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
    string s; cin >> s;
    int d; cin >> d;

    reverse(all(s));
    
    for(int i = 0 ;i <= 9 ; i++)
        dp[0][i%d]++;
    
    for(int i = 1; i < s.size() ; i++){
        for(int j = 0;j <= 9 ; j++){
            for(int k = 0 ;k < d ; k++){
                dp[i][k] += dp[i-1][(k-j+10*d)%d];
                if(dp[i][k] >= Mod)
                    dp[i][k] -= Mod;
                
            }
            
        }
    }

    for(int i = 0 ;i <= s[0]-'0' ; i++)
        ans[0][i%d]++;

    for(int i =1 ; i < s.size() ; i++){
        for(int k = 0 ; k < d; k++)
            ans[i][k] = ans[i-1][ (k-(s[i]-'0') + 10*d)%d];
        
        for(int j = 0 ;j < s[i]-'0' ; j++){
            for(int k = 0 ; k < d ; k++){
                ans[i][k] += dp[i-1][(k-j+10*d)%d];
                if(ans[i][k] >= Mod)
                    ans[i][k] -= Mod;
            }   
        }
    }
    cout << (ans[s.size()-1][0]-1+Mod)%Mod << endl;

    return 0;
}

Measured memory_bytes: 16256
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);

int main() {
    cin>>N;
    ll res = 0;
    rep(i,N){
        cin>>A;
        if(i%2 == 0 && A&1){
            ++res;
        }
    }
    cout<<res<<endl;
}


Measured memory_bytes: 3632
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

ll dp[3005][3005][5];
ll v[3005][3005];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int R, C, K;
	cin >> R >> C >> K;
	rep(i,K){
		int r, c;
		ll V;
		cin >> r >> c >> V;
		--r; --c;
		v[r][c] += V;
	}
	ll ans = 0;
	rep(i,R){
		rep(j,C){
			rep(k,4){
				chmax(dp[i+1][j][0], dp[i][j][k]);
				if(k < 3) chmax(dp[i+1][j][0], dp[i][j][k] + v[i][j]);
				chmax(dp[i][j+1][k], dp[i][j][k]);
				chmax(dp[i][j+1][k+1], dp[i][j][k] + v[i][j]);
				chmax(ans, dp[i][j][k]);
				if(k < 3) chmax(ans, dp[i][j][k] + v[i][j]);
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 426272
#!/usr/bin/perl
use Data::Dumper;
my ($n,$m) = map {$_ - 0} split(/\s+/o,<STDIN>);

my @tr = ();
$#tr = $n-1;
my @par = ();
$#par = $n-1;

for(my $i=0;$i<$n;$i++){
  $par[$i] = $i;
}

for(my $i=0;$i<$m;$i++){
  my ($x,$y,$z) = map {$_ - 0} split(/\s+/o,<STDIN>);
  unite($x-1,$y-1);
}

my %dum = ();
for(my $i=0;$i<$n;$i++){
  $dum{&root($i)} = 1;
}
my @d2 = keys %dum;
my $res = 1 + $#d2;
print "$res\n";

exit(0);

sub root {
  my $x = shift;
  return $x if $par[$x] == $x;
  my $r = &root($par[$x]);
  $par[$x] = $r;
  return $r;
}

sub unite {
  my $x = shift;
  my $y = shift;
  my $rx = &root($x);
  my $ry = &root($y);
  return if( $rx == $ry );
  $par[$rx] = $ry;
}



Measured memory_bytes: 27520
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
//typedef pair<int,int> P;
//priority_queue<int> pque;
//priority_queue<int, vector<int>, greater<int>> pque;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2000000000;//10^9
ll MOD  = 1000000007;
int main(void){
    int N, M;
    cin >> N >> M;
    vector<ll> Y(M);
    vector<int> P(M);
    for(int i = 0; i < M; i++){
        cin >> P.at(i) >> Y.at(i);
    }
    vector<ll> X[N+1];
    for(int i = 0; i < M; i++){
        X[P.at(i)].push_back(Y.at(i));
        
    }
    
    for(int i = 0; i < N; i++){
        sort(X[i+1].begin(), X[i+1].end());
    }
    
    for(int i = 0; i < M; i++){
        int p = P.at(i);
        for(int j = 5; j >= 0; j--){
            if(p < pow(10, j)){
                cout << 0;
            }else{
                cout << p;
                break;
            }
        }
        
        int left = -1, right = X[P.at(i)].size() + 1, mid;
        
        while(right - left > 1){
            mid = (left + right) / 2;
            if(X[P.at(i)][mid] < Y.at(i)){
                left = mid;
            }else{
                right = mid;
            }
        }
        right++;
        for(int j = 5; j >= 0; j--){
            
            if(right < pow(10, j)){
                cout << 0;
            }else{
                cout << right;
                break;
            }
        }
        cout << endl;
        
    }
    
}


Measured memory_bytes: 8192
#include<iostream>
#include<cstdio>

using namespace std;

int main(){
  int a, b;
  char op;

  while(1){
    cin  >> a >> op >> b;
    if ( op == '?') break;
    
    if ( op == '+') cout << a + b << endl;
    else if ( op == '-') cout << a - b << endl;
    else if ( op == '*') cout << a * b << endl;
    else cout << a / b << endl;
  }
  
  return 0;

}



Measured memory_bytes: 2976
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;
#define deb(x) cout << #x": " << (x) << endl;

const int N = 1e3+5;
const lli INF = 1e18;
const lli MOD = 1e9+7;

bool m[N];
vi primes(1,2);
ld nk[N][N];
void sieve(){
	for(int i = 4; i<N; i+=2)m[i]=1;
	for(int i = 3; i*i<=N; i+=2)if(!m[i])for(int j = i*i; j<N; j+=i)m[j]=1;
	for(int i = 3; i<N; i+=2)if(!m[i])primes.pb(i);
}

void pascal(){
	fore(i,0,N)nk[i][0]=nk[i][i]=1.0;
	fore(i,1,N)fore(j,1,i)nk[i][j]=nk[i-1][j-1]+nk[i-1][j];
}

lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}

lli lcm(lli a, lli b){
	if(a<b)swap(a,b);
	lli c = gcd(a,b);
	a/=c;
	return a*b;
}

int popcount(lli x) { return __builtin_popcountll(x); }

lli poww(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = res * a;
		a = a*a;
		b/=2;
	}
	return res;
}

lli powm(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = (res * a)%MOD;
		a = (a*a)%MOD;
		b/=2;
	}
	return res;
}

bool isPrime(lli x){
	if(x==1)return 0;
	for(auto i:primes){
		if(i*i>x)return 1;
		if(x%i==0)return 0;
	}
	return 1;
}

// ---- コーディングはここから！ ('-')7

int main(){_
	int n; cin>>n;
	vl v(n); fore(i,0,n)cin>>v[i];
	lli sum = 0;
	fore(i,0,n)sum^=v[i];
	fore(i,0,n)cout<<lli(sum^v[i])<<" ";cout<<ENDL;

}


Measured memory_bytes: 4784
#include <iostream>

using namespace std;

long long int GCD(long long int a, long long int b) {
    if(a<b) {
        long long int tmp=a;
        a=b;
        b=tmp;
    }
    
    if(b==0) {
        return a;
    }
    
    return GCD(b, a%b);
}

int main() {
    long long int A, B;
    cin >> A >> B;
         
    cout << A*B/GCD(A, B) << endl;


    return 0;
    
}

Measured memory_bytes: 256
data class A(var param: Boolean, val target: Int)
fun main( args : Array<String> ) {
  val n  = readLine()!!.toInt()
  val ba = (1..n).map {
    A(false, readLine()!!.toInt() - 1)
  }
  var cur = 0
  for( i in (1..n) ) {
    if( cur == 1 ) {
      println(i-1)
      break
    }else if( ba[cur].param == true ) {
      println(-1)
      break
    }
    ba[cur].param = true
    cur = ba[cur].target
  }
}


Measured memory_bytes: 39348
n = int(input())
cnt = [[0] * 10 for i in range(10)]

#int(str(n)[i]) nのi桁目
for n in range(1, n+1):
  cnt[int(str(n)[0])][int(str(n)[-1])] += 1

ans = 0
for i in range(10):
  for j in range(10):
    ans += cnt[i][j]*cnt[j][i]

print(ans)


Measured memory_bytes: 9192
#include <iostream>
#include <atcoder/dsu>

using namespace std;

int main(){
    int N, Q; cin >> N >> Q;
    atcoder::dsu d(N);
    for(int _=0;_<Q;_++){
        int t, u, v; cin >> t >> u >> v;
        if(t == 0){
            d.merge(u, v);
        } else {
            cout << d.same(u, v) << endl;
        }
    }
}

Measured memory_bytes: 3944
// AOJ 2564 Tree Reconstruction
// 2018.5.7 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_V 505

/* UNION-FIND library */
int id[MAX_V], size[MAX_V];
void init(int n) { int i; for (i = 0; i < n; i++) id[i] = i, size[i] = 1; }
int root(int i) { while (i != id[i]) id[i] = id[id[i]], i = id[i]; return i; }
int connected(int p, int q) { return root(p) == root(q); }
void unite(int p, int q)
{
    int i = root(p), j = root(q); if (i == j) return;
    if (size[i] < size[j]) id[i] = j, size[j] += size[i]; else id[j] = i, size[i] += size[j];
}

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

int main()
{
	int n, m, s, t, i, ans;

	n = in(), m = in();
	init(n);
	for (i = 0; i < m; i++) {
		s = in()-1, t = in()-1;
		unite(s, t);
	}
	
	ans = m-n;
	for (i = 0; i < n; i++) {
		if (root(i) == i) ans++;
	}
	printf("%d\n", ans);
	return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <climits>
using namespace std;
int main (void) {
    int N;
    int X;

    cin >> N >> X;
    int mi = INT_MAX;
    for (int i = 0; i < N; i++) {
        int m;
        cin >> m;
        X -= m;
        mi = min(mi, m);
    }
    int ans = N + X / mi;

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


Measured memory_bytes: 256
N = int(input())
ans = 0
for i in range(1, N+1):
    count = 0
    for j in range(1, i+1):
        if i % j == 0 and i % 2 != 0:
            count += 1
    if count == 8 and i % 2 != 0:
        ans += 1
print(ans)

Measured memory_bytes: 38896
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template<class T> bool INRANGE(T x,T a,T b) { return a<=x&&x<=b; }
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;
}

#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>=0;--i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;


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

map<int, int> prime_factorization(int n){
    map<int, int> res;
    if (n == 0 or n == 1) return res;
    int a = 2;
    while (n != 1){
        if (n%a == 0) {
            res[a]++;
            n /= a;
        }
        else a++;
    }

    return res;
}

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

    int N;
    cin >> N;

    vector<map<int,int>> pf(N+2);
    REP(i,pf.size()) pf[i] = prime_factorization(i);

    REP(i,pf.size()-1) {
        for (auto x : pf[i]) {
            pf[i+1][x.first] += x.second;
        }
    }

    int ans = 0;
    int c2 = 0, c4 = 0, c14 = 0, c24 = 0, c74 = 0;

    for (auto x : pf[N]){
        if (x.second >= 74) c74++;
        if (x.second >= 24) c24++;
        if (x.second >= 14) c14++;
        if (x.second >=  4)  c4++;
        if (x.second >=  2)  c2++;
    }

    ans += c74 + c24*(c2-1) + c14*(c4-1) + c4*(c4-1)/2*(c4-2) + c4*(c4-1)/2*(c2-c4);
    
    cout << ans << endl;

    return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n;
  cin >> n;
  vector<ll> s(n);
  REP(i, n)
    cin >> s[i];

  sort(s.begin(), s.end());
  ll sum = accumulate(s.begin(), s.end(), 0LL);
  if(sum % 10 == 0){
    REP(i, n){
      if(s[i] % 10 != 0){
        sum -= s[i];
        break;
      }
    }

    if(sum % 10 == 0)
      cout << 0 << endl;
    else
      cout << sum << endl;
  }
  else
    cout << sum << endl;
    
  
}


Measured memory_bytes: 256
#include<stdio.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

int head, tail, n;
P Q[LEN];


void enqueue(P x){
  Q[tail]=x;
  tail=(tail+1)%LEN;
}

P dequeue(){
  P x=Q[head]; 
  head=(head+1)%LEN;
  return x;
}



int min(int a, int b){
  if(a<b)return a;
  else return b;
}
int main(){
  
  int l = 0;
  int c;
  int i;
  int q;
  P a;
  scanf("%d%d", &n, &q);

  
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  
  head=1;
  tail=n+1;

  while(head != tail){
    a=dequeue();
    
    c=min(q,a.t);    
    a.t-=c;
    
    l+=c;
    
    if(a.t>0){
      enqueue(a);
    }
    
    else{
      printf("%s %d\n",a.name,l);
    }
  }
  return 0;
}



Measured memory_bytes: 11848
#![allow(non_snake_case,unused_imports,dead_code)]
use std::str::FromStr;
use std::io::Read;
use std::collections::{HashMap,HashSet,VecDeque,BinaryHeap};
use std::cmp::{max,min,Reverse,Ordering};
use std::time::{Duration, Instant};
use rand::Rng;

use proconio::input;
use proconio::marker::{Chars,Usize1,Isize1};

fn main() {

    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut buf_it = buf.split_whitespace();

    let T = buf_it.next().unwrap().parse::<usize>().unwrap();

    let INF = 1e9 as isize +10;
    for _ in 0..T{
        let N = buf_it.next().unwrap().parse::<usize>().unwrap();
        let KLR = (0..N).map(|_|
            (buf_it.next().unwrap().parse::<usize>().unwrap(),
            buf_it.next().unwrap().parse::<isize>().unwrap(),
            buf_it.next().unwrap().parse::<isize>().unwrap())
        ).collect::<Vec<_>>();
        let mut ans = 0;

        let mut KdLR = Vec::new();
        for (k,l,r) in KLR{
            KdLR.push((r-l,k,l,r));
        }
        KdLR.sort_by_key(|x| -(x.0.abs()));
        let mut TR = SegmentTree::new(N,min,INF);
        let mut TL = SegmentTree::new(N,max,-1isize);

        for i in 0..N{
            TR.set(i,i as isize);
            TL.set(i,i as isize);
        }

        for (dlr,k,L,R) in KdLR{
            if dlr>0{
                let r = TR.get(k,N);
                if r==INF{
                    ans += L;
                    continue;
                }
                ans += R;
                TR.set(r as usize,INF);
            }
            else{
                let l = TL.get(0,k);
                if l == -1{
                    ans += R;
                    continue;
                }
                ans += L;
                TL.set(l as usize,-1);
            }
        }

        println!("{}",ans);
    }

}

struct SegmentTree<N,F>
where F:Fn(N,N) ->N{
    n: usize,
    T: Vec<N>,
    func: F,
    identity: N,
}

impl<N:Copy,F> SegmentTree<N,F>
where F:Fn(N,N) ->N {
    fn new(n:usize,func:F,identity:N) -> SegmentTree<N,F>{
        let mut T = SegmentTree { n:n,T:Vec::new(),func:func,identity:identity};
        T.init();
        T
    }
    fn init(&mut self){
        self.n = 1<<format!("{:b}",self.n-1).len();
        self.T = (0..(2*self.n-1)).map(|_| self.identity).collect();
    }
    fn set(&mut self,index:usize,value:N){
        let i = index + self.n - 1;
        self.T[i] = value;
        self._update_parent((i-1)/2);
    }
    fn _update_parent(&mut self,i:usize){
        self.T[i] = (self.func)(self.T[i*2+1],self.T[i*2+2]);
        if i>0 { self._update_parent((i-1)/2)}
    }
    fn get(&self,l:usize,r:usize) -> N{
    self._get(l,r,0,0,self.n)
    }
    fn _get(&self,l:usize,r:usize,i:usize,a:usize,b:usize) -> N{
        if l<=a && b<=r {
            self.T[i]
        } else if b<=l || r<=a {
            self.identity
        } else{
            (self.func)(self._get(l,r,2*i+1,a,(a+b)/2),
                        self._get(l,r,2*i+2,(a+b)/2,b))
        }
    }
}

Measured memory_bytes: 22656
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

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

int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

static const double EPS = 1e-8;

struct Jinfo{
	int start;
	int len;
};

int main(){
	int n;
	while(~scanf("%d",&n)){
		if(n==0) break;
		//0:white
		//1:black

		bool field[100000];
		memset(field,0,sizeof(field));
		for(int i=0;i<n;i++){
			bool color;
			cin >> color;

			field[i] = color;

			if((i+1) % 2==0){
				if(i-1 >= 0 && field[i-1] != color){
					for(int j=i-1;j>=0;j--){
						if(field[j] == color) break;
						field[j] = color;
					}
				}
			}
		}

		printf("%d\n",count(field,field+n,false));
	}
}

Measured memory_bytes: 1332
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <queue>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
//#define ARRAY(type,n) (type *)malloc(sizeof(type)*n)
template<typename T>
T* ARRAY(int n){
	(T*)malloc(sizeof(T)*n);
}
template<typename T>
T** ARRAY2(int m,int n){
	T** type = (T**)malloc(sizeof(T*)*m);
	for(int i=0;i<m;i++){
		type[i]=(T*)malloc(sizeof(T)*n);
	}
	return type;
}
class llm{
public:
llm(ll value){this->value = (ll)value;}
ll value;
llm operator + (llm obj){return llm((this->value + (ll)(obj.value))%MOD);}
llm operator + (ll obj){return llm((this->value + obj)%MOD);}
llm operator - (llm obj){return llm(((this->value + MOD - (ll)(obj.value)))%MOD);}
llm operator - (ll obj){return llm(((this->value + MOD - obj))%MOD);}
llm operator * (llm obj){return llm((this->value * (ll)(obj.value))%MOD);}
llm operator * (ll obj){return llm((this->value * obj)%MOD);}
llm operator / (llm obj){return llm(this->value / (ll)(obj.value));}
llm operator / (ll obj){return llm(this->value / obj);}
llm operator % (llm obj){return llm(this->value % (ll)(obj.value));}
llm operator % (ll obj){return llm(this->value % obj);}};
ostream& operator<<(ostream& os, llm l){os << l.value;return os;} 
llm operator+(ll a,llm l){return llm((a + l.value)%MOD);} 
llm operator*(ll a,llm l){return llm((a * l.value)%MOD);}
 


 
int main(void){
	int n,a,b;
	cin>>n>>a>>b;
	cout<<(n*a<b?n*a:b)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;

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

  rep(i, m) {
    int t = q.top(); q.pop();
    t /= 2;
    q.push(t);
  }

  ll ans = 0;
  
  while (!q.empty()) {
    ans += q.top();
    q.pop();
  }
  cout << ans << endl;

}

Measured memory_bytes: 892
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		var sc = new Scanner(System.in);
		var n = sc.nextLong();
		var x = sc.nextLong();
		var m = sc.nextLong();
		sc.close();

		var list = new ArrayList<Long>();
		var set = new HashSet<Long>();
		var sum = 0L;
		var a = x;
		for (var i = 1L; i <= n; i++) {
			if (set.contains(a)) {
				var index = list.indexOf(a);
				var count = list.size() - index;
				var nd = (n - i + 1) / count;
				var nm = (n - i + 1) % count;
				for (var j = index; j < list.size(); j++) {
					var v = list.get(j);
					sum += v * nd;
					if (j < index + nm) {
						sum += v;
					}
				}
				break;
			}
			list.add(a);
			set.add(a);
			sum += a;
			a = (a * a) % m;
		}

		System.out.println(sum);
	}
}


Measured memory_bytes: 44072
#include<stdio.h>
int main()
{
    int n;
    int i,j;
    float f;
    scanf("%d",&n);
    int k=0;
    for(i=1;i<=9;i++)
    {
        j=n/i;
        if((n%i==0)&& (j>=1 && j<=9))
        {
        k++;
        break;
        }

    }
    if(k>0)
        printf("Yes");
    else
        printf("No");
}


Measured memory_bytes: 128
#include <stdio.h>
int main (){
  int n,m,i,j,s[1000],p[1000],loc,count;

  while(1){
    scanf("%d %d",&n,&m);
    if(n==0 && m==0)break;

    for(i=0;i<n;i++){
      scanf("%d",&s[i]);
    }

    for(j=0;j<m;j++){
      scanf("%d",&p[j]);
    }
    
    loc=0;
    count=0;
    
   for(j=0;j<m;j++){
      
      count++;
      
      loc+=p[j];
      
      if(loc>=n)break;
      
      i=loc;
      loc+=s[i];

      if(loc>=n)break;
      
    }

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

Measured memory_bytes: 604
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "ctime"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 1e-8;

long long int N, M, K, H, W, L, R;


struct box {
	long long int sy, sx, gy, gx;
};

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

	cin >> H >> W;
	vector<vector<int>>v(H, vector<int>(W));
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> v[i][j];
		}
	}
	vector<box>ans;
	for (int i = 0; i < H; i++) {
		if (i % 2) {
			for (int j = W - 1; j > 0; j--) {
				if (v[i][j] % 2) {
					ans.push_back({ i, j, i, j - 1 });
					v[i][j]--;
					v[i][j - 1]++;
				}
			}
			if (v[i][0] % 2 && i + 1 != H) {
				ans.push_back({ i, 0, i + 1, 0 });
				v[i][0]--;
				v[i + 1][0]++;
			}
		}
		else {
			for (int j = 0; j < W-1; j++) {
				if (v[i][j] % 2) {
					ans.push_back({ i, j, i, j + 1 });
					v[i][j]--;
					v[i][j + 1]++;
				}
			}
			if (v[i][W - 1] % 2 && i + 1 != H) {
				ans.push_back({ i, W - 1, i + 1, W - 1 });
				v[i][W - 1]--;
				v[i + 1][W - 1]++;
			}
		}
	}
	cout << ans.size() << endl;
	for (auto i : ans) {
		cout << i.sy+1 << " " << i.sx+1 << " " << i.gy+1 << " " << i.gx+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 7412
N, M, X = map(int, input().split())
lst = [[int(x) for x in input().split()] for _ in range(N)]
ret = 100 ** 100
for mask in range(2 ** N):
    C = [0] * M
    cst = 0
    for i in range(N):
        if (mask >> i) & 1:
            cst += lst[i][0]
            for j in range(1, M + 1):
                C[j - 1] += lst[i][j]
    if min(C) >= X:
        ret = min(ret, cst)
if ret < 100 ** 100:
    print(ret)
else:
    print(-1)


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

void solve()
{
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int p = (h2 - h1) * 60 + (m2 - m1) - k;
    cout << p << endl;
}

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

    /* int T; */
    /* cin >> T; */
    /* for (int t = 0; t < T; ++t) { */
        solve();
    /* } */
    return 0;
}


Measured memory_bytes: 3648
import numpy as np

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

l = [0]*n
r = [0]*n

for i in range(1,n):
    l[i]=gcd(l[i-1],s[i-1])

tmp = list(range(0,n-1))
tmp.reverse()
for i in tmp:
    r[i]=gcd(r[i+1],s[i+1])
    
m = list([])

for i in range(n):
    m.append(gcd(l[i],r[i]))

print(max(m))

Measured memory_bytes: 23144
#include <array>
#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 <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

int main()
{
    int N, M;
    cin >> N >> M;
    vector<pair<int, pair<int, int> > > v(M);
    int P, Y;
    REP(i, M)
    {
        cin >> P >> Y;
        v[i] = make_pair(Y, make_pair(i, P));
    }
    sort(v.begin(), v.end());
    vector<int> nums(N);
    nums.assign(N, 0);
    vector<pair<int, int> > ans(M);
    REP(i, M)
    {
        ans[v[i].second.first] = make_pair(v[i].second.second, ++nums[v[i].second.second - 1]);
    }
    REP(i, M)
    {
        printf("%06d%06d\n", ans[i].first, ans[i].second);
    }
    return 0;
}


Measured memory_bytes: 3840
S = input()
lens = len(S)
kazuR = 1
kazuL = 0
ans = [0 for i in range(lens)]
flag = 0
for i in range(1,lens):
    if S[i] == 'R' and S[i-1] == 'L':
        ans[flag-1] += (kazuR+1)//2 + kazuL // 2
        ans[flag] += kazuR // 2 + (kazuL+1) // 2
        kazuR = 1
        kazuL = 0
    elif S[i] == 'R':
        kazuR += 1
    elif S[i] == 'L' and S[i-1] == 'R':
        flag = i
        kazuL += 1
    else:
        kazuL += 1
ans[flag-1] += (kazuR+1)//2 + kazuL // 2
ans[flag] += kazuR // 2 + (kazuL+1) // 2
print(*ans)


Measured memory_bytes: 6408
#include <iostream>
#include <typeinfo>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;

int N, M;
vector<int> a, b;

int main()
{
  cin >> N >> M;
  a.resize(M);
  b.resize(M);
  for (int i = 0; i < M; i++)
  {
    cin >> a[i];
    a[i]--;
    cin >> b[i];
    b[i]--;
  }

  vector<int> order(N);
  for (int i = 0; i < N; i++)
  {
    order[i] = i;
  }

  int ans = 0;
  do
  {
    // 始点が0でなくなれば終了
    if (order[0] != 0)
    {
      break;
    }
    // order[i]からorder[i+1]への道があるかどうか、i=0, ... ,N-1について確かめる
    bool ok = true;
    for (int i = 0; i < N - 1; i++)
    {
      // (a[j],b[j])の組が(order[i],order[i+1])の組と一致するかどうか
      bool flag = false;
      for (int j = 0; j < M; j++)
      {
        if (a[j] == order[i] && b[j] == order[i + 1])
        {
          flag = true;
        }
        else if (b[j] == order[i] && a[j] == order[i + 1])
        {
          flag = true;
        }
      }
      if (!flag)
      {
        ok = false;
        break;
      }
    }
    if (ok)
    {
      ans++;
    }
  } while (next_permutation(order.begin(), order.end()));

  cout << ans << endl;
}

Measured memory_bytes: 384
N = int(input())
S1 = input()
S2 = input()

if S1[0] == S2[0]:
    ans = 3
    t = 1
else:
    ans = 6
    t = 2 

for i in range(1, N):
    if S1[i] == S1[i-1]:
        continue
    if S1[i] == S2[i]:
        if t == 1:
            ans *= 2
        t = 1
    else:
        if t == 1:
            ans *= 2
        else:
            ans *= 3
        t = 2
    ans %= 10 ** 9 + 7

print(ans)


Measured memory_bytes: 9092
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int a[109];
int main()
{
    int i,q;
    for(i=1; i<=3; i++)
        cin>>a[i];
    sort(a+1,a+3+1);
    q=a[1]+a[2];
    cout<<q<<endl;
}


Measured memory_bytes: 256
def aux(x0,y0,x1,y1)
  Math.sqrt((x1-x0)**2+(y1-y0)**2)
end

def main
  fh=STDIN
  x0,y0,x1,y1 = fh.gets.chomp.split.map(&:to_f)
  puts aux(x0,y0,x1,y1)
end

if $0 == __FILE__ then
  main
end


Measured memory_bytes: 6888
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.15f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto S = RD!string;

	bool ans = true;
	foreach (i, c; S)
	{
		if (i % 2 == 0)
		{
			if (c == 'L')
			{
				ans = false;
				break;
			}
		}
		else
		{
			if (c == 'R')
			{
				ans = false;
				break;
			}
		}
	}

	writeln(ans ? "Yes" : "No");
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.function.Supplier;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final int tVertex = scanner.nextInt();
        final int aVertex = scanner.nextInt();

        final List<Integer>[] tree = new List[n + 1];
        for (int i = 1; i < tree.length; i++) {
            tree[i] = new ArrayList<>();
        }
        for (int i = 0; i < n - 1; i++) {
            final int a = scanner.nextInt();
            final int b = scanner.nextInt();
            tree[a].add(b);
            tree[b].add(a);
        }

        final List<Integer> route = new ArrayList<>();
        final boolean[] isVisited = new boolean[n + 1];
        search(tree, aVertex, tVertex, route, isVisited);

        Arrays.fill(isVisited, false);
        final int upper = (route.size() - 1) / 2;
        if (upper + 1 < route.size()) {
            final int selectable = route.get(upper + 1);
            for (final int vertex : tree[route.get(upper)]) {
                if (vertex == selectable) {
                    continue;
                }
                isVisited[vertex] = true;
            }
        }

        final int longestDistance = searchLongest(tree, route.get(upper), 0, isVisited);

        System.out.println(longestDistance + upper - 1);
    }

    private static int searchLongest(final List<Integer>[] tree, final int current, final int distance, final boolean[] isVisited) {
        isVisited[current] = true;
        int longest = distance;
        for (final int next : tree[current]) {
            if (isVisited[next]) {
                continue;
            }

            final int tmp = searchLongest(tree, next, distance + 1, isVisited);
            if (tmp > longest) {
                longest = tmp;
            }
        }
        return longest;
    }

    private static boolean search(final List<Integer>[] tree, final int current, final int dest, final List<Integer> route, final boolean[] isVisited) {
        isVisited[current] = true;
        route.add(current);
        if (current == dest) {
            return true;
        }
        for (final int next : tree[current]) {
            if (isVisited[next]) {
                continue;
            }

            if (search(tree, next, dest, route, isVisited)) {
                return true;
            }
        }
        route.remove(route.size() - 1);
        return false;
    }
}


Measured memory_bytes: 109260
#include <iostream>
#include <iomanip>
#include <bits/stdc++.h>

using namespace std; 
int main(){
    cout << fixed << setprecision(5) ;
    double r;
    double l,s;
    cin >> r;
    l = 2*r*M_PI;
    s = r * r * M_PI;
    cout << s <<" "<< l << endl;
    return 0;
}


Measured memory_bytes: 3280
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#include <assert.h>
using namespace std;

typedef unsigned long long int ulint;
typedef long long int lint;

int main(){
  ulint N, T;
  cin >> N >> T;

  vector<ulint> A;
  vector<ulint> B;
  
  for (ulint i = 0; i < N; ++i) {
    ulint a, b;
    cin >> a;
    cin >> b;
    A.push_back(a);
    B.push_back(b);
    // cout << a << "-" << b << endl; 
  }

  // Knapsack

  // DP[i][j] : using i items with j minutes.
  vector<vector<ulint>> DP1(N, vector<ulint>(T, 0));
  vector<vector<ulint>> DP2(N, vector<ulint>(T, 0));
  
  for (ulint n = 0; n < N; ++n) {
    for (ulint t = 0; t < T; ++t) {
      if (t == 0) {
	DP1[n][t] = 0;
      } else if (n == 0) {
	if (A[n] <= t) {
	  DP1[n][t] = B[n];
	} else {
	  DP1[n][t] = 0;
	}
      } else {
	assert(0 <= n - 1);
	assert(0 <= n);
	assert(n - 1 < N);
	assert(n < N);
	ulint without_n = DP1[n - 1][t];
	ulint with_n = 0;
	if (t >= A[n]) {
	  with_n = DP1[n - 1][t - A[n]] + B[n];
	}
	DP1[n][t] = max(without_n, with_n);       
      }
      // cout << n << " " << t << " " << DP1[n][t] << endl;
    }
  }

  // cout << "DP2" << endl;
  // DP2
  for (int n = (int) N - 1; n >= 0; --n) {
    // cout << "n=" << n << endl; 
    for (ulint t = 0; t < T; ++t) {
      if (t == 0) {
	DP2[n][t] = 0;
      } else if (n == N - 1) {
	if (A[n] <= t) {
	  DP2[n][t] = B[n];
	} else {
	  DP2[n][t] = 0;
	}
      } else {
	ulint without_n = DP2[n + 1][t];
	ulint with_n = 0;
	if (t >= A[n]) {
	  with_n = DP2[n + 1][t - A[n]] + B[n];
	}
	DP2[n][t] = max(without_n, with_n);       
      }
      // cout << n << " " << t << " " << DP2[n][t] << endl;
    }
  }

  ulint max_val = 0;
  for (int i = 0; i < N; ++i) {
    // Use i-th item in the end.
    for (int j = 0; j < T; ++j) {
      // Take j minutes for the first (1...i) th item
      // and take T-j-1 minutes for the (i+1...N) th item
      ulint score = B[i];
      if (i >= 1) {
	score += DP1[i-1][j];
      }
      if (i < N - 1) {
	score += DP2[i+1][T-j-1];
      }
      max_val = max(score, max_val);
    }
  }
  cout << max_val << endl;
}


Measured memory_bytes: 141184
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
//typedef long double ld;
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; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
void solve(const vector<int> &v){

}
int main(){
  int H,W,K;  cin>>H>>W>>K;
  string s[H];
  rep(i,0,H) cin>>s[i];
  int d[H][W];
  memset(d, 0, sizeof(d));
  int now = 1;
  rep(i,0,H)rep(j,0,W){
    if(s[i][j]=='#') d[i][j] = now++;
  }
  rep(i,0,H)rep(j,0,W){
    if(d[i][j]!=0){
      while(d[i][j+1]==0 && j+1<W) d[i][j+1] = d[i][j], j++;
    }
  }
  rep(i,0,H)rep(j,0,W){
    if(d[i][j]!=0){
      while(d[i][j-1]==0 && j-1>=0) d[i][j-1] = d[i][j], j--;
    }
  }
  rep(j,0,W)rep(i,0,H){
    if(d[i][j]!=0){
      while(d[i+1][j]==0 && i+1<H) d[i+1][j] = d[i][j], i++;
    }
  }
  rep(j,0,W)rep(i,0,H){
    if(d[i][j]!=0){
      while(d[i-1][j]==0 && i-1>=0) d[i-1][j] = d[i][j], i--;
    }
  }
  rep(i,0,H){
    rep(j,0,W){
      cout<<d[i][j]<<" ";
    }
    cout<<'\n';
  }
  return 0;
}


Measured memory_bytes: 1280
from collections import Counter

N, M = map(int, input().split())
pS = [input().split() for _ in range(M)]

ac = 0
state = Counter()
penalty = 0
for p, S in pS:
    if state[p] != -1:
        if S == "WA":
            state[p] += 1
        else:
            penalty += state[p]
            ac += 1
            state[p] = -1

print(ac, penalty)


Measured memory_bytes: 41860