akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<math.h>

int main(void)
{

int i,j,n,m,num,k,s,ans=0,judge=0,on=1;

scanf("%d%d",&n,&m);

int bul[m][n];
int p[m];
num = (int)pow(2,n);
int a[num][n];


for(i=0;i<m;i++){
  for(j=0;j<n;j++)
    bul[i][j]=0;
}



for(i=0;i<num;i++){
        for(j=0;j<n;j++){
            if(i%(int)pow(2,j+1)>=pow(2,j))
                  a[i][n-1-j]=1;
            else
                  a[i][n-1-j]=0;
        }
}

for(i=0;i<m;i++){
  scanf("%d",&k);
  for(j=0;j<k;j++){
    scanf("%d",&s);
    bul[i][s-1]=1;
  }
}

for(i=0;i<m;i++)
  scanf("%d",&p[i]);

for(i=0;i<num;i++){
  for(j=0;j<m;j++){
    for(k=0;k<n;k++){
      judge+=bul[j][k]*a[i][k];
    }
    if(judge%2==p[j])
      on*=1;
    else
      on*=0;
    judge=0;
  }
  if(on==1)
    ans++;
  on=1;
}

printf("%d",ans);
return 0;
}


Measured memory_bytes: 256
/*program by mangoyang*/
#include<bits/stdc++.h>
#define inf (0x7f7f7f7f)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long ll;
using namespace std;
template <class T>
inline void read(T &x){
	int f = 0, ch = 0; x = 0;
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = 1;
	for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
	if(f) x = -x;
}
int a[100005], n;
int main(){
	read(n); int ans = 0;
	for(int i = 1; i <= n; i++) read(a[i]);
	for(int i = 2; i <= n; i++)
		if(a[i] == a[i-1]) a[i] = -1, ans++; 
	cout << ans << endl;
	return 0;
}

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

using namespace std;
#define int long long 
#define N 1000005
int su[N],cnt;
int n;
bool isprime[N];
void prime(){
    cnt=1;
    memset(isprime,1,sizeof(isprime));//初始化认为所有数都为素数
    isprime[0]=isprime[1]=0;//0和1不是素数
    for(int i=2;i<=N;i++){
        if(isprime[i])
            su[cnt++]=i;//保存素数i
        for(int  j=1;j<cnt&&su[j]*i<N;j++){
            isprime[su[j]*i]=0;//筛掉小于等于i的素数和i的积构成的合数
        }
    }
}
vector<int> v;
signed main(){
	prime();
	for(int i=1;i<cnt;i++){
		if(su[i]%10==1){
			v.push_back(su[i]);
			//if(v.size()==55) cout<<su[i]<<'\n';
		}
	}	
	int n;
	cin>>n;
	for(int i=0;i<n;i++) cout<<v[i]<<" ";
	return 0;
}

Measured memory_bytes: 2176
#include <stdio.h>

int main(void) {
  int n, k, ktmp, count = 0, ans = 1, i;
  scanf("%d\n%d", &n, &k);
  ktmp = k;
  if (n == 1) {
    printf("2\n");
    return 0;
  } else {
    // kが2の何乗ぐらいか調べる
    while (ktmp != 0) {
      ktmp = ktmp / 2;
      count++;
    }
    //その回数だけ2倍する
    for (i = 0; i < count; i++) ans = ans * 2;
    //残りの回数kを足す
    ans = ans + (n - count) * k;
    printf("%d\n", ans);
    return 0;
  }
}

Measured memory_bytes: 128
#include <cstdio>
typedef long long LL;
#define MOD 998244353

int n, m, k;
LL ans;

LL mypow(LL e, LL x) {
    if (!x) return 1;
    LL tmp = mypow(e, x / 2);
    tmp *= tmp, tmp %= MOD;
    if (x & 1) tmp *= e, tmp %= MOD;
    return tmp;
}


int main() {
    scanf("%d%d%d", &n, &m, &k);
    ans = mypow(m - 1, n - 1) % MOD;
    LL c = 1;
    for (int i = 1, j = n - 1 ; i <= k ; i++, j--) {
        c *= j, c %= MOD;
        c *= mypow(i, MOD - 2), c %= MOD;
        ans += (mypow(m - 1, n - 1 - i) * c) % MOD;
        ans %= MOD;
    }
    printf("%lld", ans * m % MOD);
}


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

using namespace std;

const int maxn = 300050;

char dir[maxn];
int numA[maxn];
int n;
string s;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> s;
    for (int i = 0; i < n; i++) {
        dir[i] = s[i];
    }
    int away = 0;
    int minAway = maxn;
    for (int i = 1; i < n; i++) {
        if (dir[i] == 'E') away++;
    }
    numA[0] = away;
    minAway = min(away, minAway);
    for (int i = 1; i < n; i++) {
        if (dir[i - 1] == 'W') away++;
        if (dir[i] == 'E') away--;
        numA[i] = away;
        minAway = min(away, minAway);
    }
    cout << minAway << "\n";
}

Measured memory_bytes: 2196
#include <iostream>
using namespace std;
int main() {
    string s;
    int n;
    int r = 0;
    int b = 0;
    cin >> n >> s;
    for (int i = 0; i < n; ++i) {
        if(s[i] == 'R'){
            r++;
        } else {
            b++;
        }
    }

    if(r > b) {
        cout << "Yes" << endl;
    } else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
fun main() {
    val (n, t) = readLine()!!.split(' ').map { it.toInt() }
    val ts = readLine()!!.split(' ').map { it.toInt() }

    var ans = 0L
    for (i in 1 until n) {
        ans += (ts[i] - ts[i - 1]).coerceAtMost(t)
    }
    ans += t
    println(ans)
}


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

int main()
{
	int a, b, c;
	int tmp;
	
	cin >> a >> b >> c;
	
	if(a>b){
		tmp=a;
		a=b;
		b=tmp;
	}
	
	if(b>c){
		tmp=b;
		b=c;
		c=tmp;
	}
	
	if(a>b){
		tmp=a;
		a=b;
		b=tmp;
	}
	
	cout << a << ' ' << b << ' ' << c << endl;
	
	return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int n; cin >> n;
	vector<int> d(n);
	for (int i = 0; i < n; i++) cin >> d.at(i);
	sort(d.begin(), d.end());
	
	cout << d.at(n / 2) - d.at((n / 2) - 1) << endl;
}

Measured memory_bytes: 3792
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
e=Counter(v[0::2]).most_common(2)
o=Counter(v[1::2]).most_common(2)
if len(set(v))==1:
    print(n//2)
else:
    if e[0][0]==o[0][0]:
        print(n-max(e[1][1],o[1][1])-e[0][1])
    else:
        print(n-e[0][1]-o[0][1])

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

#define ll long long int
#define ull unsigned long long int
#define forr(i,n) for(int i=0;i<n;i++)
#define f(i,a,b) for(ll i=a;i<b;i++)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define ce(ele) cout<<ele<<' '
#define cs(ele) cout<<ele<<'\n'
#define CASE(t) int t; cin>>t; while(t--)
#define sor(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vi vector<ll>
const ll md=1e9 +7;const ll M1=998244353;
ll mod(ll n){return ((n%md)+md)%md;}
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=res*x;x=x*x;y=y>>1;}return res;}

const int d[4][2]={{1,1},{1,-1},{-1,1},{-1,-1}};

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

    ll n;cin>>n;ll res=0;
    vi lo(4,1e12),hi(4,-1e12);
    f(i,0,n){
        int x,y;cin>>x>>y;
        f(j,0,4){
            ll a=d[j][0]*x+d[j][1]*y;
            lo[j]=min(lo[j],a);
            hi[j]=max(hi[j],a);
        }
    }
    
    f(j,0,4){
            res=max(res,hi[j]-lo[j]);
    }
    cs(res);
}

Measured memory_bytes: 3672
#include <iostream>

using namespace std;

int main(void) {
  int m,f,r;
  int sum;
  while(cin >> m >> f >> r && (m != -1 || f != -1 || r != -1)) {
    sum = m + f;
    if(m == -1 || f == -1 || sum < 30)
      cout << 'F' << endl;
    else if(sum >= 80)
      cout << 'A' << endl;
    else if(sum >= 65 && sum < 80)
      cout << 'B' << endl;
    else if(sum >= 50 && sum < 65)
      cout << 'C' << endl;
    else if(sum >= 30 && sum < 50) {
      if(r >= 50)
        cout << 'C' << endl;
      else
        cout << 'D' << endl;
    }
  }
  return 0;
}

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

int main() {
  string S;
  cin >> S;
  for(char c='a'; c<='z'; c++) {
    bool found = false;
    for(int i = 0; i<S.length(); i++) {
      if(S[i] == c) found = true;
    }
    if(!found) {
      cout << c << endl;
      return 0;
    }
  }
  cout << "None" << endl;
}

Measured memory_bytes: 3668
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{

    static void Main(string[] args)
    {
        //入力
        var s = crS();
        var t = crS();
        int count = 0;
        for(int i = 0; i < s.Length; i++)
        {
            if (s[i] != t[i]) count++;
        }
        Console.WriteLine(count);
       
    }

   
  



        //入力受け取り用
    static string crS() { return Console.ReadLine(); }
    static int crI() { return int.Parse(Console.ReadLine()); }
    static int[] arrInt(){return Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();}
    static long[] arrLong(){ return Console.ReadLine().Split(' ').Select(v => long.Parse(v)).ToArray(); }
    static string[] arrStr(){return Console.ReadLine().Split(' ').ToArray();}
    static List<int[]> mapInt(int h)
    {
        List<int[]> mapInt = new List<int[]>();
        for (int i = 0; i < h; i++)
        {
            mapInt.Add(arrInt());
        }
        return mapInt;
    }
}

Measured memory_bytes: 27440
#include<bits/stdc++.h>
using namespace std;
int main(){
  int q,c,a,n;
  cin>>q;
  for(int i=0;i<q;++i){
    int cnt=0;
    cin>>c>>a>>n;
    while(c&&a&&n){
      ++cnt;
      --c;
      --a;
      --n;
    }
    while(c>=2&&a>=1){
      ++cnt;
      c-=2;
      --a;
    }
    while(c>=3){
      ++cnt;
      c-=3;
    }
    cout<<cnt<<endl;
  }
  return 0;
}



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

void count(int x, vector<int>& V) {
  int i = 2;
  while (1 < x) {
    if (x % i == 0) {
      V[i]++;
      x /= i;
    } else {
      i++;
    }
  }
}

int main() {
  int N;
  cin >> N;
  if (N < 10) {
    cout << 0 << endl;
    return 0;
  }
  vector<int> V(N+1, 0);
  for (int i = 2; i < N+1; i++) {
    count(i, V);
  }

  int ans = 0;

  int n2 = 0, n4 = 0, n14 = 0, n24 = 0, n74 = 0;
  for (int i = 0; i < V.size(); i++) {
    n2 += 2 <= V[i];
    n4 += 4 <= V[i];
    n14 += 14 <= V[i];
    n24 += 24 <= V[i];
    n74 += 74 <= V[i];
  }
  ans += n4*(n4-1)/2*(n2-2);
  ans += n24 * (n2-1);
  ans += n14 * (n4-1);
  ans += n74;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ul unsigned long long int
#define ld long double
#define f(t) for(ll i =0;i<t;i++)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define inf 4e18
#define EPS 1e-3
#define PI 3.1415926535897932385
#define display(v) f(v.size())cout << v[i]<<" "
const double h = 1e-6;
const int MAX_  = 200005;
#define all(v) v.begin(),v.end()

inline ll mul(ll a, ll b){ return (a * 1ll * b) % MOD; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += MOD; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > MOD) c -= MOD; return c; }
ll sqr(ll x)
{
    return x*x;
}
 //////////////////////*********CODE***********/////////////////////
 //////////////////////////////////////////////////////////////////

struct UnionFind {
    vector<int> par;
    vector<int> sz;
 
    UnionFind(int n=0){ if(n>0) initialize(n); }
    void initialize(int n){
        par.resize(n);
        sz.assign(n, 1);
        for(int i=0; i<n; i++){
            par[i] = i;
        }
    }
 
    int find(int x){
        if(par[x] == x){
            return x;
        }else{
            return par[x] = find(par[x]);
        }
    }
 
    bool unite(int x, int y){
        x = find(x), y = find(y);
        if(x == y) return false;
        if(sz[x] > sz[y]) swap(x, y);
        par[x] = y;
        sz[y] += sz[x];
        return true;
    }
 
    bool same(int x, int y){ return find(x) == find(y); }
    int size(int x){ return sz[find(x)]; }
};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;   cin>>n;
    int e = 1e5;
    int si = 2e5;
    UnionFind uf(si);
    f(n){
        int x,y;
        cin>>x>>y;
        uf.unite(x,y+e);
    }
    vl x(si);
    vl y(si);
    for(int i =1;i<=e;i++){
        ++x[uf.find(i)];
    }
    for(int i = e+1;i<=si;i++){
        ++y[uf.find(i)];
    }
    ll ans = 0;
    for(int i =0;i<si;i++){
        ans += x[i]*y[i];
    }
    cout << ans - n ;

    


    return 0;
}
    


Measured memory_bytes: 4992
b = []
c = []
while True:
    inp = input()
    a = inp.split()
    a[0] = int(a[0])
    a[1] = int(a[1])
    if a[0] == 0 and a[1] == 0:
        break
    else:
        a.sort()
        b.append(a[0])
        c.append(a[1])
for i in range(len(b)):
    print(b[i],c[i])


Measured memory_bytes: 6124
import math
a, b, h, m = map(int, input().split())
minutes = 60*h+m
h_deg = minutes/2 % 360
m_deg = minutes*6 % 360
deg = h_deg-m_deg
print((a**2+b**2-2*a*b*math.cos(math.radians(deg)))**.5)


Measured memory_bytes: 9508
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long 
int l[100005] = {};
vector<vector<int>> g(100005);

int main() {
  int n;
  cin >> n;
  int a[n+1];
  int c =0;
  for(int i = 1 ;i<n+1;i++){
    cin >> a[i];
    if(i%2 !=0 && a[i]%2 != 0){
      c++;
    }
  }
  
  
  cout << c;
}


Measured memory_bytes: 5392
n=int(input())
s=input()
ans=0
for i in range(n-1):
    x=s[0:i+1]
    y=s[i+1:]
    x=''.join(set(x))
    cnt=0
    for j in range(len(x)):
        if x[j] in y:
            cnt+=1
    ans=max(cnt,ans)
print(ans)

Measured memory_bytes: 3064
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: usize,
        k: usize,
        
    }

    let mut rec =  vec![0; n+1];

    for _i in 0..k {
        input! {
            d: usize,
            a: [usize; d],
        }

        for i in a {
            rec[i] += 1;
        }
    }

    let mut ans = Vec::new();
    for i in 1..n+1 {
        if rec[i] == 0 {
            ans.push(i);
        }
    }

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



}


Measured memory_bytes: 2200
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>
#include <cstring>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int ans = n;
    for (int i = 1; i < n; ++i) {
        if (s[i] != s[i-1]) {
            ans = min(ans, max(i, n-i));
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size() 

ll power(ll x,ll y,ll p) 
{ 
    ll res = 1;      
    x = x % p;  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p;   
    } 
    return res; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
	ll n,i,j,k,x,y,t,m;

	string s,e,f,g="",h="";
	cin >> s;
	n=sz(s);
	for(i=0;i<(n-1)/2;i++)
		g+=s[i];
	for(i=(n+3)/2-1;i<n;i++)
		h+=s[i];

	string p=s;
	e=g,f=h;
	reverse(all(h));
	reverse(all(g));
	reverse(all(p));
	// cout<<h<<endl;
	if(g==e && h==f && p==s)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n, k;
    cin >> n  >> k;
    vector<int> a(n);
    for (int i=0;i <n; i++) cin >> a[i];
    
    
    int first_idx = 0;
    int last_idx = k;
    
    while(last_idx < n){
        if (a[first_idx] < a[last_idx]){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
        first_idx++;
        last_idx++;
    }
    
}


Measured memory_bytes: 4004
import numpy
import re
import math

def main():
	"""
	テストコード実行
	:return:
	"""
	n, y = map(int, input().split())
	for i in range(n + 1):
		for j in range(n + 1):
			if (10000 * i + 5000 * j + 1000 * (n - i - j)) == y and 0 <= (n - i - j):
				print(" ".join([str(i), str(j), str(n - i - j)]))
				exit()
	print("-1 -1 -1")

if __name__ == '__main__':
	main()


Measured memory_bytes: 21840
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include <string.h>
#include <iomanip>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
const ll mod=1e9+7;

ll gcm(ll C,ll D){
    if(D==0) return C;
    return gcm(D,C%D);
}

ll NOTCD(ll m,ll C,ll D){
    ll ans=m;
    ans-=m/C;
    ans-=m/D;
    ans+=m/((C*D)/gcm(C,D));
    return ans;
}


int main(void){
    ll A,B,C,D;
    cin>>A>>B>>C>>D;
    cout<<NOTCD(B,C,D)-NOTCD(A-1,C,D)<<endl;
    return 0;
    }


Measured memory_bytes: 256
#set

n,a,b = gets.chomp.split(" ").map(&:to_i)
chk_num = 0
counter = 0
( 1 .. n ).each do |num|
    chk_num = 0
    num.to_s.split("").map(&:to_i).each do |i|
        chk_num += i
    end
    if chk_num >= a && chk_num <= b then
        counter += num
    end
end

print ("#{counter}\n")

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

using namespace std;

struct thing
{
    int r, c, x;
};

int R, C, N;
vector<thing> row[100000], col[100000];
long long A[100000];
long long B[100000];
set<int> rows, cols;

void ensure(bool b)
{
    if(!b)
    {
        printf("No\n");
        exit(0);
    }
}

void go(int r)
{
    long long minr=0x3f3f3f3f3f3f3f3fLL;
    long long minc=0x3f3f3f3f3f3f3f3fLL;
    queue<pair<int, int>> Q;
    Q.push({r, 0});
    rows.erase(r);
    A[r]=0;
    while(!Q.empty())
    {
        int t;
        tie(r, t)=Q.front();
        Q.pop();
        if(t==0)
        {
            minr=min(minr, A[r]);
            for(auto& it: row[r])
            {
                if(!cols.count(it.c))
                    ensure(B[it.c]==it.x-A[it.r]);
                else
                {
                    B[it.c]=it.x-A[it.r];
                    Q.push({it.c, 1});
                    cols.erase(it.c);
                }
            }
        }
        else
        {
            minc=min(minc, B[r]);
            for(auto& it: col[r])
            {
                if(!rows.count(it.r))
                    ensure(A[it.r]==it.x-B[it.c]);
                else
                {
                    A[it.r]=it.x-B[it.c];
                    Q.push({it.r, 0});
                    rows.erase(it.r);
                }
            }
        }
    }
    ensure(minr+minc>=0);
}

int main()
{
    scanf("%d%d%d", &R, &C, &N);
    for(int i=0; i<N; i++)
    {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        a--, b--;
        row[a].push_back((thing){a, b, c});
        col[b].push_back((thing){a, b, c});
        rows.insert(a);
        cols.insert(b);
    }
    while(!rows.empty())
        go(*rows.begin());
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 22144
from fractions import gcd
from functools import reduce


def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def main():
    N = int(input())
    A = list(map(int, input().split()))
    D = lcm_list(A)
    ans = 0
    MOD = 10 ** 9 + 7
    D %= MOD
    for a in A:
        ans += D * pow(a, MOD - 2, MOD)
        ans %= MOD
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 67432
import itertools
ans = []
while True:
    n, x = map(int, input().split())
    if n == x == 0:
        break
    cnt = 0
    for l in list(itertools.combinations(list(range(1,n+1)), 3)):
        if sum(l) == x:
            cnt += 1
    ans.append(cnt)
for a in ans:
    print(a)


Measured memory_bytes: 18428
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<deque>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;

#define vvint(vec,n,m,l) vector<vector<int>> vec(n,vector<int>(m,l));
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>;
#define pint pair<int,int>;
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")
#define ret return 0


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

	ll n, m;
	cin >> n >> m;
	vector<ll> x(m+2);
	rep(i,m)
	{
		cin >> x[i];
	}
	x[m] = INF; x[m + 1] = -INF;


	sort(x.begin(), x.end());

	vector<ll> suki(m+1);
	for (int i = 1; i <= m+1; i++)
	{
		suki[i-1] = x[i] - x[i - 1];
	}
	sort(suki.begin(), suki.end(), greater<int>());
	ll ans = 0;
	for (int i = 0; i < min(n + 1,m+1); i++)
	{
		ans += suki[i];
	}

	cout << 2 * INF - ans << endl;

	ret;
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
   double x=n/1.08;
	int y=x;
	if(y-x<-0.5)
	{
		if(int((y+1)*1.08)>n){
		
		cout<<":(";
		}
		else{
			cout<<y+1;
		}
	}
	else if(y-x>=-0.5&&y-x<0)
	{
		if(int((y+1)*1.08)>n){
		
		cout<<":(";
		}
		else{
			cout<<y+1;
		}
	}
	else if(y==x)
	{
		cout<<y;
	
	}
}



Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n = int(input())
s = input()
ans = 0

for i in range(1000):
    cnt = 0
    if i < 100:
        if i < 10:
            match = '00' + str(i)
        else:
            match = '0' + str(i)
    else:
        match = str(i)

    for S in s:
        if S == match[cnt]:
            cnt += 1

        if cnt == 3:
            ans += 1
            break

print(ans)


Measured memory_bytes: 41180
#include <bits/stdc++.h>
using namespace std;
signed main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a>=b && a>=c)
    cout<<b*c/2<<endl;
  else if(b>=a && b>=c)
    cout<<a*c/2<<endl;
  else
    cout<<a*b/2<<endl;
  return(0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;

int main(){
  ll n; cin >> n;
  vector<ll> a(n);
  map<ll,ll> num;
  rep(i,n){
    cin >> a.at(i);
    num[a.at(i)]++;
  }

  ll sum =0;
  for(auto c:num){
    ll x = c.second;
    if(x<2) continue;
    if(x==2){
      sum++;
      continue;
    }
    sum+=x*(x-1)/2;
  }

  rep(i,n){
    cout << sum -(num[a.at(i)]-1) << endl;
  }
}

Measured memory_bytes: 11008
#include<bits/stdc++.h>
#define int long long 
using namespace std;
const int ms = 1e5+9;
int vet[ms];
int a,b,n;

bool p(int t){
	int sz = 0;
	for(int i = 0;i<n;i++){
		if(vet[i] - b*t>0){
			sz += ((vet[i]-b*t)+(a-b)-1)/(a-b);
		
		}
	}
	//cout<<t<<" "<<sz<<endl;

	return sz<=t;

}
main(){
	cin >> n >> a >> b;
	for(int i= 0;i<n;i++) cin >> vet[i];
	int l = 0, r = 1e9+9,m;
	while(r - l > 1){
		m = (r+l)/2;
		if(p(m))
			r = m;
		else
			l = m;
	}
	//cout<<p(2)<<endl;
	
	cout<<r;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

ll power(ll k,int n,ll M){
  if(n==0) return 1;
  if(n==1) return (ll)k;
  
  ll ret = power(k,n/2,M);
  
  ret=(ret*ret)%M;
  
  if(n%2==1) ret=(ret*k)%M;
  
  return ret;
}

map<pair<int,pair<ll,int> >, ll> memo;

// revN - N = D

ll dfs(int m, ll d, ll sum = 0, int h=0, string s1 = "", string s2 = ""){
  ll t = power(10,h,LLINF);
  ll p = power(10,m-h-1,LLINF);
  ll ret = 0;

  if(memo.find({m,{sum,h}}) != memo.end()){
    return memo[make_pair(m,make_pair(sum,h))];
  }
  
  if(m/2 == h){
    if(d == sum){
      if(m%2){
        //debug(s1+"_"+s2);
        return 10;
      }else{
        //debug(s1+s2);
        return 1;
      }
    }
    return 0;
  }
  
  for(int i=(h==0);i<=9;i++){ //N
    for(int j=0;j<=9;j++){ //revN
      ll rest = d - sum;
      if((rest - (10+i-j)%10*t)%(t*10) == 0 &&
         rest/p - (j-i) <= 1
         ){
        ll new_sum = sum + (i-j)*t + (j-i)*p;
        string new_s1 = s1 + "0";
        string new_s2 = "0" + s2;

        new_s1[new_s1.size()-1] += j;
        new_s2[0] += i;
        
        ret += dfs(m, d, new_sum, h+1, new_s1, new_s2);
      }
    }
  }

  return memo[make_pair(m,make_pair(sum,h))] = ret;
}

int main(){
  ll d;
  
  scanf("%lld",&d);

  ll ans = 0;
  
  for(int m=1;m<=18;m+=1){
    ans += dfs(m,d);
  }

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


Measured memory_bytes: 256
import math

def solve():
  ABCDE = [int(input()) for i in range(5)]
  s = sum(map(lambda v: math.ceil(v * 0.1) * 10, ABCDE))
  k = 10
  for i in ABCDE:
    _i = i % 10
    if _i == 0: continue
    if k == 0: k = _i
    else: k = min(k, _i)
  s = s + k - 10
  return s

print(solve())


Measured memory_bytes: 3060
#include <stdio.h>

int main(void){

  char s[101];
  int end;
  for (int i = 0; i < 101; i++) {
    scanf("%c", &s[i]);
    if (s[i] < 'a' || s[i] > 'z') {
      end = i;
      break;
    }
    s[i] = 'x';
  }

  for (int i = 0; i < end; i++) {
    printf("%c", s[i]);
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <time.h> 
#define ll long long int
#define F first
#define S second
#define pb push_back
#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y);
#define sdl(x) scanf("%lld",&x)
#define sd2l(x,y) scanf("%lld%lld",&x,&y);
#define sz(x) (int)(x.size())
#define nax 200010
#define inf 1001000100
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
#define mp make_pair
#define pc pair<char ,int>
#define pi pair<int ,int>
#define pii pair <pi,pi>
using namespace std;
int arr[404];
ll dp[404][404];
ll sum[404];
int main(int argc, char const *argv[])
{
  //freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  int n;
  sd(n);
  for(int i = 1; i <= n; i++)
  {
      sd(arr[i]);
      sum[i] = sum[i - 1] + arr[i];
  }

  for(int i = 2; i <= n; i++) // size
  {
      for(int j = 1; j + i <= n + 1; j++)
      {
          int en = j + i - 1;
          ll mi = inf * 1ll * inf;
          for(int k = 1; k < i; k++)
              mi = min(mi, dp[j][j + k - 1] + dp[j + k][en]);
          dp[j][en] += mi + sum[j + i - 1] - sum[j - 1];
      }
  }
  printf("%lld\n", dp[1][n]);
  return 0;
}

Measured memory_bytes: 1536
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace B
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var XY = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var X = XY[0];
            var Y = XY[1];
            var answer = false;

            for (var i = 0; i <= X; i++)
            {
                var turu = i;
                var kame = X - i;
                if (2 * turu + 4 * kame == Y) answer = true;
            }
            Console.WriteLine(answer ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 28144
object Main extends App {
  val inputs: Seq[String] = io.Source.stdin.getLines().toList
  val N      = inputs(0).toInt
  val values = inputs(1).split(" ").map(_.toInt).toIndexedSeq
  val costs  = inputs(2).split(" ").map(_.toInt).toIndexedSeq

  println(solve(N, values, costs))

  def solve(N: Int, values: IndexedSeq[Int], consts: IndexedSeq[Int]): Int = {
    var result = 0
    values.zipWithIndex.foreach { case (value, index) =>
        val cost = consts(index)
      (value - cost) match {
        case gain if 0 < gain => result = result + gain
        case _                => result = result + 0
      }
    }
    result
  }
}

Measured memory_bytes: 27340
#include "bits/stdc++.h"
#define _USE_MATH_DEFINES
#include <math.h>
 
using namespace std;
 
using LL = long long;
using VLL = std::vector<LL>;
using VVLL = std::vector<VLL>;
using VVVLL = std::vector<VVLL>;
using LD = long double;
using VLD = std::vector<LD>;
using VVLD = std::vector<VLD>;
using VVVLD = std::vector<VVLD>;
 
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; }return false; }

//template<class T=LL> inline vector<T> cinv(LL N){ vector<T> v(N); REP(i, N)cin>>v[i]; return move(v);}
//template<class T=LL> inline vector<T> cinv(LL N){ vector<T> v(N); REP(i, N)cin>>v[i]; return move(v);}
#define REP(i,n) for(LL (i)=0;(i)<(n);(i)++)
#define ALL(v) v.begin(), v.end()
#define PRINTLN(v) {LL i=0; for(auto (a): v ){   cerr <<i << " : "<<  a << endl; i++;}}
#define PRINTSP(v) for(auto (a): v ) {cerr << a << " ";} cerr << endl
#define cmax(a,b) {if(a<b){a=b;}}
#define cmin(a,b) {if(a>b){a=b;}}
#define EACH(a,A) for(auto a: A)
//#define cmax(a,b) a = (a>b ? a:b)
//#define cmin(a,b) a = (a<b ? a:b) 
//cin,cout高速化のおまじない＋桁数指定
inline VLL cinvll(LL N){
  VLL A(N);
  REP(i,N){
    cin >> A[i];
  }
  return move(A);
}
struct Fast{
	Fast(){
		cin.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(std::numeric_limits<double>::max_digits10);
	}
} fast;


struct IntegralImage{
  VVLL I; 
  
  IntegralImage(VVLL M){
    I = M;
    LL H = M.size();
    LL W = M[0].size();
    REP(i,H){
      REP(j,W-1){
        I[i][j+1] += I[i][j];
      }
    }
    REP(j,W){
      REP(i,H-1){
        I[i+1][j] += I[i][j];
      }
    }
  }
  LL get_sum( LL y, LL h, LL x, LL w){
    LL a1 = I[y+h][x+w];
    LL a2 = 0;
    if(y>0){
      a2 = I[y-1][x+w];
    }            
    LL a3 = 0;
    if(x>0){
      a3 = I[y+h][x-1];
    }            
    LL a4 = 0;
    if(y>0 && x>0){
      a4 = I[y-1][x-1];
    }
    return (a1 + a4 - a2 -a3);
  }
  void print( ){
    REP(i,I.size()){
      PRINTSP(I[i]);
    }  
  }
  
};


void func(){
  LL N;
  cin >> N;
  LL M;
  cin >> M;
  LL Q;
  cin >> Q;

  VVLL A(N,VLL(N,0));
  REP(i,M){
    LL l,r;
    cin >> l;
    cin >> r;
    l--;
    r--;
    A[l][r]++;
  }
  REP(i,N){
    //PRINTSP(A[i]);
  }
  IntegralImage II(A);
  //II.print();
  REP(j,Q){
    LL p,q;
    cin >>p;
    cin >>q;
    p--;
    q--;
    cout << II.get_sum(p,q-p,p,q-p) << endl;

  }




  //IntegralImage II();  
  


} 

int main()
{
  func();
  return 0;
}
 

Measured memory_bytes: 6912
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#define _USE_MATH_DEFINES
#include<math.h>
#include<cmath>
#include<ctime>
#include<map>
#include<typeinfo>
#define R(i, n) for(int i = 0;i < n; i++)
#define R1(i, n) for(int i = 1; i <= n; i++)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define SL(a) scanf("%lld", &a)
#define SL2(a, b) scanf("%lld%lld", &a, &b)
#define SL3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define SC(a) scanf("%c", &a)
#define P(a) printf("%d", a)
#define PL(a) printf("%lld", a)
#define PY printf("YES")
#define PN printf("NO")
#define Py printf("Yes")
#define Pn printf("No")
using namespace std;
using ll = long long;
using PR = pair<int, int>;
const ll MOD = 1e+9 + 7;
const int INF = 1e+9;
const double PI = acos(-1);

int main() {
	int n;
	S(n);
	int a[100000] = { 0 };
	R(i, n) {
		int num;
		S(num);
		if(num != 0) a[num - 1]++;
		a[num]++;
		if(num != 99999) a[num + 1]++;
	}
	int ans = 0;
	R(i, 100000) ans = max(ans, a[i]);
	P(ans);
}

Measured memory_bytes: 4112
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod = (int)1e9 + 7;
int n, m;
map<int, int> Hash;
int mod_pow(int x, int k) {
	int ret = 1;
	for( ; k > 0; k >>= 1, x = (LL)x * x % mod)
		(k & 1) && (ret = (LL)ret * x % mod);
	return ret;
}
int F(int x) {
	if(Hash.count(x))
		return Hash[x];
	int ret = mod_pow(m, (x + 1) >> 1);
	x > 1 && (ret -= F(1)) < 0 && (ret += mod);
	for(int i = 2; i * i <= x; ++i) {
		if(x % i > 0)
			continue;
		(ret -= F(i)) < 0 && (ret += mod);
		i * i < x && (ret -= F(x / i)) < 0 && (ret += mod);
	}
	return Hash[x] = ret;
}
int main() {
	scanf("%d%d", &n, &m);
	int ans = 0;
	for(int i = 1; i * i <= n; ++i) {
		if(n % i > 0)
			continue;
		ans = (ans + (LL)F(i) * (i >> !(i & 1))) % mod;
		if(i * i < n)
			ans = (ans + (LL)F(n / i) * ((n / i) >> !((n / i) & 1))) % mod;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <math.h>
#include <string>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <stdlib.h>
#include <time.h> 
#include <assert.h>

#define nmax 500010
#define eps 1e-8
#define MOD 998244353

#define P1 25671
#define P2 191
#define MOD1 666013
#define MOD2 1000000007
#define B_SIZE 315

#define SZ(x) ((int)(x.size()))

#define fst first
#define snd second
#define pb push_back
#define mp make_pair

using namespace std;

int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a % b); }

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

int n, w;
bool b[nmax];
ll dp[nmax];
pii item[nmax];

int main()
{
	scanf("%d %d", &n, &w);

	for (int i = 1; i <= n; i++) scanf("%d %d", &item[i].fst, &item[i].snd);

	b[0] = true;

	for (int i = 1; i <= n; i++)
		for (int j = w - item[i].fst; j >= 0; j--)
			if (b[j]) {

				dp[j + item[i].fst] = max(dp[j + item[i].fst], dp[j] + item[i].snd);

				b[j + item[i].fst] = true;
			}

	ll x = 0;

	for (int i = 0; i <= w; i++) x = max(x, dp[i]);

	printf("%lld", x);

	return 0;
}

Measured memory_bytes: 6400
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  ll n,l,t;
  cin >> n >> l >> t;
  ll x[n], w[n];
  REP(i,n) cin >> x[i] >> w[i];
  ll x_t[n];
  REP(i,n){
    if(w[i]==1){
      x_t[i] = (x[i] + t)%l;
    }else{
      x_t[i] = (x[i] - t + t * l)%l;
    }
  }
  ll zero_pos = x_t[0];
  sort(x_t,x_t+n);
  ll cross_cnt = 0;
  for(ll i = 1; i < n; i++){
    if(w[0]==1&&w[i]==2){
      cross_cnt += floor((t-(x[i]-x[0]+l)%l/2.0)/(l/2.0))+1;
    }else if(w[0]==2&&w[i]==1){
      cross_cnt -= floor((t-(x[0]-x[i]+l)%l/2.0)/(l/2.0))+1;
    }
  }
  //cout << cross_cnt << endl;
  ll zero_ind = cross_cnt>=0 ? cross_cnt%n : n+cross_cnt%n ;
  ll zero_ord = lower_bound(x_t,x_t+n,zero_pos) - x_t;
  if(x_t[zero_ord]==x_t[(zero_ord+1)%n]){
    if(w[0]==1){
      zero_ord++;
      zero_ord%=n;
    }
  }
  vector<pair<ll,ll> > ants;
  ants.push_back(pair<ll,ll>(zero_ind,zero_pos));
  REP(i,n-1){
    zero_ord++;
    zero_ord%=n;
    zero_ind++;
    zero_ind%=n;
    ants.push_back(pair<ll,ll>(zero_ind,x_t[zero_ord]));
  }
  sort(ants.begin(),ants.end());
  REP(i,n){
    cout << ants[i].second << endl;
  }
  return 0;
}


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

int main(void){
	int n;
	double ave = 0;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; ++i){
		cin >> a[i];
		ave += a[i];
	}
	ave /= n;
	double a_m = 10000.0;
	int i_m;
	for(int i = n-1; i >= 0; i--){
		a_m = min(a_m, abs(a[i] - ave));
		if(a_m == abs(a[i] - ave)){
			i_m = i;
		}
	}
	cout << i_m << endl;
	return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,A=0,B=0;
	cin >> n;
	int a[n];
	for(int i=0;i<n;i++)
		cin >> a[i];
	sort(a,a+n);
	for(int i=n-1;i >= 0;i--)
	{
		if((n-i)%2 != 0)
			A += a[i];
		else
			B += a[i]; 
	}
	cout << A-B << endl;
	return 0;
}

Measured memory_bytes: 256
Scanf.scanf "%d" (fun n ->
    let a = Array.init 2 (fun _ -> Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a))) in
    let rec loop i ma =
        if i = n then ma else
            let rec loop2 j acc =
                if j >= n then acc else
                    let acc = if j <= i then acc + a.(0).(j) else acc in
                    let acc = if j >= i then acc + a.(1).(j) else acc in
                    loop2 (j + 1) acc
            in
            let acc = loop2 0 0 in
            loop (i + 1) (max ma acc)
    in
    loop 0 0 |> Printf.printf "%d\n"
)

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define mod 1000000007
#define pb emplace_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll> 
#define vi vector< ll > 
#define vvi vector< vi > 
#define vpi vector< pii > 
#define vvpi vector< vpi > 
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define test(t) ll t;cin>>t;while(t--)
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
#define fr(i,n) for(ll i=0;i<(n);++i)
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b)))
#ifndef ONLINE_JUDGE
#define debarr(a,n)cerr<<#a<<":";for(int i=0;i<n;i++)cerr<<a[i]<<" ";cerr<<endl;
#define debmat(mat,row,col)cerr<<#mat<<":\n";for(int i=0;i<row;i++){for(int j=0;j<col;j++)cerr<<mat[i][j]<<" ";cerr<<endl;}
#define pr(...)dbs(#__VA_ARGS__,__VA_ARGS__)
template<class S,class T>ostream &operator<<(ostream &os,const pair<S,T> &p){return os<<"("<<p.first<<","<<p.second<<")";}
template<class T>ostream &operator<<(ostream &os,const vector<T> &p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>ostream &operator<<(ostream &os,const set<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>ostream &operator<<(ostream &os,const multiset<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class S,class T>ostream &operator<<(ostream &os,const map<S,T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>void dbs(string str,T t){cerr<<str<<":"<<t<<"\n";}
template<class T,class...S>void dbs(string str,T t,S... s){int idx=str.find(',');cerr<<str.substr(0,idx)<<":"<<t<<",";dbs(str.substr(idx+1),s...);}
#else
#define pr(...){}
#define debarr(a,n){}
#define debmat(mat,row,col){}
#endif
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
signed main()
{
    fast;
    ll n,m;
    cin>>n>>m;
    ll i;
    vector < vector < string > > arr(n+1);
    ll ans = 0,penal = 0;
    for(i=0;i<m;i++)
    {
        ll p;
        string s;
        cin>>p>>s;
        arr[p].pb(s);
    }
    for(i=1;i<=n;i++)
    {
        ll cnt = 0;
        bool pos = 0;
        for(auto v:arr[i])
        {
            if(v=="AC")
            {
                pos = 1;
                break;
            }
            cnt++;
        }
        ans+=pos;
        penal+=(pos*cnt);
    }
    cout<<ans<<" "<<penal;
    
}


Measured memory_bytes: 10368
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>
#include <algorithm>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    int a,b,c,d;
    cin >>a>>b>>c>>d;
    cout << max((min(b,d) - max(a,c)),0)<<endl;
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
a,b=map(int,input().split())
sai=gcd(a,b)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

kou=make_divisors(sai)

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

ans=0
for i in kou:
    if is_prime(i):
        ans+=1
print(ans+1)

Measured memory_bytes: 3272
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(x) cerr << "[(" << __LINE__ << ") " << (#x) << "]: " << x << endl;

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

    int l, r, d;
    cin >> l >> r >> d;

    cout << r/d - (l+d-1)/d + 1 << "\n";
}


Measured memory_bytes: 3664
N = int(input())
D = input().split()
D = [int(d) for d in D]

hantei = 1
if(D[0] != 0):
    print(0)
else:
    D = sorted(D[1:])
    if(D[-1]==1):
        print(1)
    else:
        n = 0
        k = 0
        mul = 1
        k_count_before = 1
        while(n<len(D)):
            k += 1
            k_count = 0
            
            while(n<len(D) and D[n]==k):
                k_count += 1
                n += 1

            if(k_count==0):
                mul = 0
                hantei = 0
                break
            else:

                mul *= k_count_before**k_count
                k_count_before = k_count

        print(mul%998244353) 

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define line cout << __LINE__;
#define prv(a) for(auto x : a) cout << x << ' ';cout << '\n';
#define decimal_digits cout << fixed << setprecision(15);


typedef unordered_map<int,int> umi;
typedef unordered_map<ll,ll> uml;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

const ll INF = 1e16;

int main(int argc, char const *argv[])
{
	IOS;
	ll n,i,j,k,l;
	cin >> n;
	vl a(n + 5,0);
	forn(1,n + 1,i){
		cin >> a[i];
		if(i)
			a[i] += a[i - 1];

	}

	ll dp[n + 5][n + 5];
	memset(dp,0,sizeof(dp));
	forn(0,n + 1,i){
		dp[i][i] = 0;
	}
	ll t;
	forn(2,n + 1,l){
		forn(1,n - l + 2,i){
			j = i + l - 1;
			dp[i][j] = INF;
			// cout << l << '\n';
			// cout << i << ' ' << j << '\n';
			forn(i,j + 1,k){
				t = dp[i][k] + dp[k + 1][j] + a[j] - a[i - 1];
				if(t < dp[i][j]){
					dp[i][j] = t;
				}
			}
		}
	}
	// forn(1,n + 1,i){
	// 	forn(1,n + 1,j){
	// 		cout << dp[i][j] << ' ';
	// 	}
	// 	cout << '\n';
	// }
	cout << dp[1][n] << '\n';
	return 0;
}

Measured memory_bytes: 1536
# include <stdio.h>

int main(void){

int H, W;
 int i, j; //i ?????? ,j ???

while(1){
  scanf("%d %d", &H, &W);
  if (0 == H && 0 == W){break;}

  for(i = 0; i < H; i++){
    for (j = 0; j < W; j++){
      //i + j ?????¶??°?????????#.#.????????????
      //i + j????\???°?????????.#.#????????????
      if(0 == ( i + j ) % 2 ){printf("#");}
      else {printf(".");}
}
  printf("\n");
  }

  printf("\n");
}
  return 0;
}

Measured memory_bytes: 572
import java.util.*;

public class Main{
  
  public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();
    
    int ans = 0;
    for(int i = 0; i < N; i++){
      int next = sc.nextInt();
      int a = next - 1;
      ans += a;
    }
    
    System.out.println(ans);
    
  }
  
}

Measured memory_bytes: 40380
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let x: isize = iterator.next().unwrap().parse().unwrap();
    let y: isize = iterator.next().unwrap().parse().unwrap();

    if (y - 2 * x) % 2 != 0 {
        return "No".to_string();
    }
    let t = (y - 2 * x) / 2;
    let s = x - t;
    if s >= 0 && t >= 0 {
        return "Yes".to_string();
    }
    return "No".to_string();
}


Measured memory_bytes: 2160
#include<stdio.h>
struct Node
{
  int p;
  int l;
  int r;
};

struct Node T[100000];

int depth(int id)
{
  int dep=0;
  while(T[id].p!=-1)
    {
      dep++;
      id=T[id].p;
    }
  return dep;
}


int sibling(int id)
{
  if(T[id].p==-1) return -1;
  if(T[T[id].p].r==id) return T[T[id].p].l;
  if(T[T[id].p].l==id) return T[T[id].p].r;
}

int degree(int id)
{
  int deg=0;
  if(T[id].l!=-1) deg++;
  if(T[id].r!=-1) deg++;
  return deg;
}

int height(int id)
{
  int lheight=0;
  int rheight=0;

  if(T[id].l!=-1) lheight=height(T[id].l)+1;
  if(T[id].r!=-1) rheight=height(T[id].r)+1;
  if(lheight>rheight) return lheight;
  else return rheight;
}

main()
{
  int n,i,id;

  scanf("%d",&n);

  for(i=0;i<n;i++)
    {
      T[i].p=T[i].l=T[i].r=-1;
    }

  for(i=0;i<n;i++)
    {
      scanf("%d",&id);
      scanf("%d %d",&T[id].l,&T[id].r);
      T[T[id].l].p=id;
      T[T[id].r].p=id;
    }

  for(i=0;i<n;i++)
    {
      printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,T[i].p,sibling(i),degree(i),depth(i),height(i));

      if(T[i].p==-1)
	{ 
	  printf("root\n");
	}
      else if(T[i].l==-1&&T[i].r==-1)
	{
	  printf("leaf\n");
	}
      else printf("internal node\n");
    }
  return 0;
}

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

typedef struct{
  int num;
  int left;
  int right;
} nodeinfo;

vector<nodeinfo> nodes;

void output_preorder(int from, int n){
  if(from == -1) return;
  int idx;
  for(int i = 0; i < n; i++) if(nodes[i].num == from) idx = i;
  int left = nodes[idx].left;
  int right = nodes[idx].right;
  cout << " " << from;
  output_preorder(left, n);
  output_preorder(right, n);
}

void output_inorder(int from, int n){
  if(from == -1) return;
  int idx;
  for(int i = 0; i < n; i++) if(nodes[i].num == from) idx = i;
  int left = nodes[idx].left;
  int right = nodes[idx].right;
  output_inorder(left, n);
  cout << " " << from;
  output_inorder(right, n);
}

void output_postorder(int from, int n){
  if(from == -1) return;
  int idx;
  for(int i = 0; i < n; i++) if(nodes[i].num == from) idx = i;
  int left = nodes[idx].left;
  int right = nodes[idx].right;
  output_postorder(left, n);
  output_postorder(right, n);
  cout << " " << from;
}

int main(){
  int n;
  cin >> n;
  vector<bool> root(n, true);
  for(int i = 0; i < n; i++){
    nodeinfo node;
    int num, left, right;
    cin >> num >> left >> right;
    if(left != -1) root[left] = false;
    if(right != -1) root[right] = false;
    node.num = num;
    node.left = left;
    node.right = right;
    nodes.push_back(node);
  }
  int idx;
  for(int i = 0; i < n; i++) if(root[i]) idx = i;
  cout << "Preorder" << endl;
  output_preorder(idx, n);
  cout << endl;
  cout << "Inorder" << endl;
  output_inorder(idx, n);
  cout << endl;
  cout << "Postorder" << endl;
  output_postorder(idx, n);
  cout << endl;
  return 0;
}

Measured memory_bytes: 3124