akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
#define __lcm(a,b) ((a)/__gcd(a,b)*(b))
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288419716939937510582097;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
    int x=0;
    char ch=' ';
    bool flag=false;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')flag=true;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return flag?-x:x;
}
#define int LL
const int MAX_N=1005;
int n,m;
int t[MAX_N],x[MAX_N],y[MAX_N],z[MAX_N];
int ans;
void solve(int a1,int a2,int a3)
{
	rep(i,0,n)t[i]=a1*x[i]+a2*y[i]+a3*z[i];
	sort(t,t+n);
	reverse(t,t+n);
	int sum=0;
	rep(i,0,m)sum+=t[i];
	ans=max(ans,sum);
} 
signed main()
{
	cin>>n>>m;
	rep(i,0,n)cin>>x[i]>>y[i]>>z[i];
	solve(-1,-1,-1);
	solve(-1,-1,1);
	solve(-1,1,-1);
	solve(-1,1,1);
	solve(1,-1,-1);
	solve(1,-1,1);
	solve(1,1,-1);
	solve(1,1,1);
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

class vertex {
public:
    bool visited;
    vector<int> neighbors;

    vertex() {
        this->visited = false;
        this->neighbors = vector<int>();
    }
};

int main() {
    int N, M;
    cin >> N >> M;

    vector<vertex> vtx(N);

    for(int i=0; i<M; i++) {
        int u, v, z;
        cin >> u >> v >> z;
        vtx[u-1].neighbors.push_back(v-1);
        vtx[v-1].neighbors.push_back(u-1);
    }


    int count = 0;
    for(int i=0; i<N; i++) {
        if(vtx[i].visited)
            continue;
        count++;
        
        auto que = queue<int>();
        que.push(i);

        while(!que.empty()) {
            auto idx = que.front();
            que.pop();

            vtx[idx].visited = true;
            for(auto next_idx : vtx[idx].neighbors) {
                if(vtx[next_idx].visited)
                    continue;
                que.push(next_idx);
            }   
        }
    }
    
    cout << count << endl;

    return 0;
}

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


using namespace std;

#define endl '\n'
#define PB push_back
#define MP make_pair
#define LL long long
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

typedef long long ll;

bool file=0,rt=1;
clock_t tStart ;
void FAST_IO();
////////////////////////

const int MOD = 1000000007;

int main() {

    //FAST_IO();
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout << setprecision(5);
    cout << fixed;

    //A = 0, C = 1, G = 2, T = 3

    ll dp[110][4][4][4];
    int n;

    cin >> n;



    for(int i = 0; i < 110; i++) {

        for(int j = 0; j < 4; j++) {

            for(int k = 0; k < 4; k++) {

                for(int l = 0; l < 4; l++) {

                    dp[i][j][k][l] = 0;
                }
            }
        }
    }

   for(int j = 0; j < 4; j++) {

        for(int k = 0; k < 4; k++) {

            for(int l = 0; l < 4; l++) {

                if(j == 0 && k == 1 && l == 2) continue;
                else if(j == 0 && k == 2 && l == 1) continue;
                else if(j == 2 && k == 0 && l == 1) continue;

                else dp[3][j][k][l] = 1;
            }
        }
    }


   for (int i = 3; i < n; ++i) {
		for (int j = 0; j < 4; ++j) {
			for (int k = 0; k < 4; ++k) {
				for (int l = 0; l < 4; ++l) {
					for (int m = 0; m < 4; ++m) {
						if (m == 0 && j == 2 && l == 1)continue;
						if (m == 0 && k == 2 && l == 1)continue;
						if (j == 2 && k == 0 && l == 1)continue;
						if (j == 0 && k == 1 && l == 2)continue;
						if (j == 0 && k == 2 && l == 1)continue;
			            dp[i + 1][j][k][l] += dp[i][m][j][k];
						dp[i + 1][j][k][l] %= MOD;
					}
				}
			}
		}
	}

    ll ans = 0;
    for(int j = 0; j < 4; j++) {

        for(int k = 0; k < 4; k++) {

            for(int l = 0; l < 4; l++) {

                ans += dp[n][j][k][l];
                ans %= MOD;
            }
        }
    }

    cout << ans << endl;



    return 0;
}

void FAST_IO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    //cout.tie(NULL);
    //cout.setf(ios::fixed);
    //cout.precision(2);
    if(rt && file){ tStart = clock(); }
    if(file){
    #ifndef _offline
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repi(i,x,n) for(ll i=x;i<(ll)(n);i++)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
//cin.tie(0);ios::sync_with_stdio(false);



signed main(){
    string s,t="CODEFESTIVAL2016";cin>>s;
    int ans=0;
    rep(i,siz(t)){
        if(s[i]!=t[i])ans++;
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<ll,double>
#define pi 3.14
#define maxn 100009
#define eps (long double)1e-9
#define MOD 1000000007
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    pii vet[maxn];
    set<ll> possi;
    for(int i=1;i<=m;i++){
        possi.insert(i);
    }
    priority_queue<pair<ll,ll> >pq;
    for(int i=0;i<n;i++){
        cin>>vet[i].first;
        cin>>vet[i].second;
        if(vet[i].first<=m)pq.push({vet[i].second,vet[i].first});
    }
    ll ans = 0;
    while(!pq.empty()){
        auto e=pq.top();
        pq.pop();
        auto it= possi.lower_bound(e.second);
        if(it!=possi.end()){
            ans+=e.first;
            possi.erase(it);
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

struct node { int x,y,z; }a[100010];

int fa[100010],n,m,q;

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

inline int find(int x) { return (x==fa[x])?x:fa[x]=find(fa[x]); }

int main()
{
	n=rd();m=rd();q=rd();
	if (m==n-1)
	{
		for (int i=1;i<=q;i++)
		{
			rd();rd();int z=rd();
			if (z==1) { puts("No");return 0; }
		}
		puts("Yes");
		return 0;
	}
	for (int i=1;i<=n;i++) fa[i]=i;
	for (int i=1;i<=q;i++) a[i].x=rd()+1,a[i].y=rd()+1,a[i].z=rd();
	for (int i=1;i<=q;i++) if (a[i].z==0) fa[find(a[i].x)]=find(a[i].y);
	int cnt=0,cnt1=0;
	for (int i=1;i<=n;i++) if (find(i)==i) cnt++;
	for (int i=1;i<=q;i++) if (a[i].z==1&&find(a[i].x)==find(a[i].y)) { puts("No");return 0; }
	for (int i=1;i<=q;i++) if (a[i].z==1) cnt1++;
	if (cnt1&&cnt==2) { puts("No");return 0; }
	if (cnt==1) { puts("No");return 0; }
	ll mn=(cnt==2)?1:cnt,mx=(ll)cnt*(cnt-1)/2;
	if (n-cnt+mn<=m&&n-cnt+mx>=m) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main()
{
    int n, u, k, v, adj[110][110]={0};
    cin>>n;
    for (int i=0; i<n; i++)
    {
        cin>>u>>k;
        for (int j=0; j<k; j++)
        {
            cin>>v;
            adj[u][v]=1;
        }
    }
    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=n; j++)
        {
            if (j!=n) cout<<adj[i][j]<<' ';
            else cout<<adj[i][j]<<'\n';
        }
    }
    return 0;
}



Measured memory_bytes: 3164
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

struct card{
	char m;
	int n;
};

void b_sort(card* a , int n){
	for(int i=n;i>=0;--i){
		for(int j=0;j<i-1;++j){
			if(a[j].n>a[j+1].n){
				swap(a[j].n,a[j+1].n);
				swap(a[j].m,a[j+1].m);
			}
		}
	}
}

void s_sort(card* a , int n){
	int lowest;
	for(int i=0;i<n;++i){
		lowest=i;
		for(int j=i+1 ; j<n ;++j){
			if(a[j].n<a[lowest].n){
				lowest=j;
				}
			}
		if(a[i].n>a[lowest].n){
		swap(a[i].n , a[lowest].n);
		swap(a[i].m , a[lowest].m);
		}
	}	
}

bool stable(card* org , card* sorted , int n){
	bool b[10]={false};
	for(int i=0;i<n;++i){
		for(int j=0;j<n;++j){
			if(!b[org[i].n]){
				if(org[i].n==sorted[j].n){
					if(org[i].m==sorted[j].m) {b[org[i].n]=true;break;}
					else return false;
				}
			} else {
				break;
			}
		}
	}
	return true;
}

int main(){
	int n;
	cin >> n;
	card* a = new card [n];
	card* b = new card [n];
	card* c = new card [n];
	for(int i=0;i<n ;++i){
		cin >>a[i].m >> a[i].n;
		b[i].m=a[i].m;
		b[i].n=a[i].n;
		c[i].m=a[i].m;
		c[i].n=a[i].n;
	}
	b_sort(a , n);
	for(int i=0;i<n-1 ; i++){
		cout << a[i].m << a[i].n << " ";
	}
	cout <<a[n-1].m << a[n-1].n << endl;
	cout << ((stable(c , a , n)) ? "Stable" : "Not stable") << endl;

	s_sort(b , n);
	for(int i=0;i<n-1 ; i++){
		cout << b[i].m << b[i].n << " ";
	}
	cout <<b[n-1].m << b[n-1].n << endl;
	cout << (stable(c , b , n) ? "Stable" : "Not stable")<< endl;
	delete [] a; 
	delete [] b;
	delete [] c;
	return 0; 
}

Measured memory_bytes: 1204
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

signed main() {
  string s;
  cin >> s;
  if (s == "AAA" || s == "BBB")
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return (0 ^ _ ^ 0);
}



Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
total = sum(a)
l = 0
for i, ai in enumerate(a):
    l += ai
    if l >= total // 2:
        break
c1 = l - (total - l)
c2 = total - (l - ai) - (l - ai)
print(min(c1, c2))

Measured memory_bytes: 26220
#include <iostream>
#include <vector>
#include <string>
using namespace std; typedef long long ll; const int INF=1e9; typedef pair<ll,ll> P; const ll mod=1e9+7;

int main() {
  string s,t; cin>>s>>t;
  int n=s.size(), m=t.size();
  int a[n], b[m];

  for(int i=0;i<n;i++) {
    if (s[i] == 'A') a[i]=1; else a[i]=2;
  }
  for(int i=1;i<n;i++) a[i]=a[i-1]+a[i];
  for(int i=0;i<m;i++) {
    if (t[i] == 'A') b[i]=1; else b[i]=2;
  }
  for(int i=1;i<m;i++) b[i]=b[i-1]+b[i];

  int q; cin>>q;
  for(int i=0;i<q;i++) {
    int d,f,g,h; cin>>d>>f>>g>>h; d--; f--; g--; h--;
    int x1=a[f]; if (d!=0) x1-=a[d-1];
    int x2=b[h]; if (g!=0) x2-=b[g-1];
    //cout<<x1<<" "<<x2<<" ";
    if (abs(x1-x2)%3 == 0) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
}


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

int read() {
    int ans=0,flag=1;
    char ch=getchar();
    while( (ch>'9' || ch<'0') && ch!='-' ) ch=getchar();
    if(ch=='-') flag=-1,ch=getchar();
    while(ch>='0' && ch<='9') ans=ans*10+ch-'0',ch=getchar();
    return ans*flag;
}

int num[2021];//0~2018
int pick[2021];
int cnt;
int ans = 2019;

int main(){
	int l,r;
	cin >> l >> r;
	for(int i = l;;++i){
		if(i > r)break;
		if(num[i%2019])break;
		num[i%2019] = 1;
	}
	if(num[0]){
		cout << 0;
		return 0;
	}else{
		for(int i = 0;i <= 2018;++i){
			if(num[i]){
				pick[++cnt] = i;
			}
		}
		for(int i = 1;i < cnt;++i){
			for(int j = i+1;j <= cnt;++j){
				ans = min(ans , pick[i]*pick[j] % 2019);
			}
		}
		cout << ans;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD (1000000007)
#define MOD2 (998244353)
#define MOD3 (1000000009)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
ifstream cinn("input.txt");ofstream coutt("output.txt");

signed main(){
    FASTER;
    int n,m,x;cin>>n>>m>>x;
    vvi v(n,vi(m+1));cin>>v;
    
    int mn=INF;
    
    for(int i=1;i<(1LL<<n);i++){
        vi pos;
        
        for(int j=0;j<n;j++){
            if(i&(1LL<<j)){
                pos.push_back(j);
            }
        }
        
        int cst=0;
        for(int ii:pos)cst+=v[ii][0];
        
        vi skill(m,0);
        
        for(int j:pos){
            for(int k=1;k<=m;k++){
                skill[k-1]+=v[j][k];
            }
        }
        
        //cout<<pos<<" - "<<cst<<" - "<<skill<<"\n";
        
        bool ok=1;
        for(int k:skill)ok&=(k>=x);
        
        if(ok){
            mn=min(mn,cst);
        }
        
    }
    
    if(mn==INF)mn=-1;
    cout<<mn;
    
}

Measured memory_bytes: 3680
package main
import "fmt"
func swap(a int, b int) (int, int) {
    return b, a
}
func main(){
	var a,b int
	fmt.Scan(&a,&b)
	if a<b {
		a,b = swap(a,b)
	}
	c := a-b
	if c%2 == 1 {
		fmt.Printf("IMPOSSIBLE\n")
	} else {
		c /= 2
		fmt.Printf("%d\n",a-c)
	}
	
}


Measured memory_bytes: 512
n = int(input())
a = list(map(int,input().split()))
state = 100
count = 1
tmp = a[0]
for i in a:
  if i == tmp:
    pass
  elif i > tmp:
    if state == 1:
      pass
    elif state == 0:
      count += 1
      state = 100
    else:
      state = 1
  else:
    if state == 0:
      pass
    elif state == 1:
      count += 1
      state = 100
    else:
      state = 0
  tmp = i
print(count)

Measured memory_bytes: 14252
#include<iostream>
#include<vector>
#include<algorithm>
#define INF 10000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll ans=10000000000,n,m,r,d[200][200];
  cin >> n >> m >> r;
  vector<ll> tr;
  ll tmp,a[m],b[m],c[m];
  fill(d[0],d[200],INF);
  for(int i=0;i<r;i++){
    cin >> tmp;
    tmp--;
    tr.push_back(tmp);
  }
  for(int i=0;i<n;i++){
    d[i][i]=0;
  }
  for(int i=0;i<m;i++){
    cin >> a[i]>>b[i]>>c[i];
    a[i]--;
    b[i]--;
    d[a[i]][b[i]]=c[i];
    d[b[i]][a[i]]=c[i];
  }
  for(int k=0;k<n;k++){
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
      }
    }
  }
  sort(tr.begin(),tr.end());
  do{
    tmp=0;
    for(int i=1;i<r;i++){
      tmp += d[tr[i-1]][tr[i]];
    }
    ans = min(ans,tmp);
  }while(next_permutation(tr.begin(),tr.end()));
  cout<< ans << endl;
}


Measured memory_bytes: 1024
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

m = 10**8
idx = 0
for i in range(N):
    if A[i] < m:
        m = A[i]
        idx = i

cnt = 0
i = 0
while i < N - 1:
    i += K - 1
    cnt += 1

print(cnt)

Measured memory_bytes: 14004
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    long long solve(vector<int>& A, int m) {
        priority_queue<int> pq;
        for (auto x : A) {
            pq.emplace(x);
        } 

        while (m > 0 && pq.size() > 0) {
            int x = pq.top();
            pq.pop();
            x >>= 1;
            if (x > 0) {
                pq.emplace(x);
            }
            --m;
        }

        long long res = 0;
        while (!pq.empty()) {
            res += pq.top();
            pq.pop();
        }
        return res;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }
    Solution sol;
    cout << sol.solve(A, m) << "\n";

    return 0;
}

Measured memory_bytes: 1276
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <cmath>
#define maxn 100005
#define maxv 100005
using namespace std;
typedef long long ll;

int n;
int a[maxn];
int cnt[maxv][2];

int main()
{
	scanf("%d",&n);
	int mxv=0;
	bool same=true;
	for(register int i=1;i<=n;++i)
	{
		scanf("%d",&a[i]);
		++cnt[a[i]][i&1];
		if(a[i]!=a[1])
			same=false;
		mxv=max(mxv,a[i]);
	}
	if(same)
	{
		printf("%d",n/2);
		return 0;
	}
	int mx1cnt=0,mx0cnt=0,mx1,mx0;
	for(register int i=1;i<=mxv;++i)
	{
		if(cnt[i][1]>=mx1cnt)
		{
			mx1cnt=cnt[i][1];
			mx1=i;
		}
		if(cnt[i][0]>=mx0cnt)
		{
			mx0cnt=cnt[i][0];
			mx0=i;
		}
	}
	if(mx0 != mx1)
		printf("%d",n-mx1cnt-mx0cnt);
	else
	{
		int amx1cnt=0,amx0cnt=0,amx1,amx0;
		for(register int i=1;i<=mxv;++i)
		{
			if(cnt[i][1]>=amx1cnt && i!=mx1)
				amx1cnt=cnt[i][1];
			if(cnt[i][0]>=amx0cnt && i!=mx0)
				amx0cnt=cnt[i][0];
		}
		printf("%d",min(n-mx1cnt-amx0cnt,n-mx0cnt-amx1cnt));
	}
}

Measured memory_bytes: 1408
//2019年5月19日
#include <stdio.h>
int main(int argc, char const *argv[]) {
  int n;
  int k;
  char c[50];

  scanf("%d %d\n",&n,&k);
  scanf("%s",c);

 c[k-1] = c[k-1] + 0x20;

 printf("%s\n",c);


  return 0;
}


Measured memory_bytes: 128
/* 

*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <bitset>
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define LSOne(S) (S & (-S))
#define EPS 1e-9
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pd;
typedef tree<pi, null_type, less<pi>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0); // BEFORE SUBMIT DON'T FORGET TO UNCOMMENT THIS
    ll x;
    cin >> x;
    ll d500 = x / 500;
    ll ans = 0;
    ans += 1000L * (x/500);
    x %= 500;
    ans += 5L *(x/5);
    cout << ans << "\n";
    return 0; 
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cassert>
using namespace std;

struct LowestCommonAncestor {
    size_t n;
    size_t size() const { return n; }
    enum { B = 500 };
    vector<int> color, par, depth, depthTop, goUp, vis;
    vector<vector<int>> g;
    LowestCommonAncestor(size_t n_) : n(n_), g(n) {}
    void addEdge(int u, int v){
        g[u].push_back(v); g[v].push_back(u);
    }
    void decomp(int root){
        color.assign(n,0); par.assign(n,-1); depth.assign(n,0);
        depthTop.assign(n,0); goUp.assign(n,-1); vis.assign(n,0);
        for(size_t i = 0; i < n; i++) vis[i] = false, par[i] = -1;
        vector<int> q(n+1); int l = 0, r = 0;
        q[r++] = root;
        vector<int> tord;
        while(l != r){
            int v = q[l++]; vis[v] = true;
            tord.push_back(v);
            for(int c : g[v]){
                if(vis[c]) continue;
                q[r++] = c;
                par[c] = v; depth[c] = depth[v] + 1;
            }
        }
        for(size_t i = 0; i < n; i++) vis[i] = false;
        int c = 0;
        for(int u : tord){
            if(vis[u]) continue;
            l = 0, r = 0;
            q[r++] = u;
            for(int i = 0; i < B && l != r; i++){
                int v = q[l++];
                vis[v] = true; color[v] = c; goUp[v] = par[u]; depthTop[v] = depth[u];
                for(int c : g[v]) if(!vis[c]) q[r++] = c;
            }
            c++;
        }
    }
    int solve(int u, int v){
        while(color[u] != color[v]){
            if(depthTop[u] > depthTop[v]) u = goUp[u];
            else v = goUp[v];
        }
        while(u != v){
            if(depth[u] > depth[v]) u = par[u];
            else v = par[v];
        }
        return u;
    }
};

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

int main(){
    int n;
    cin >> n;
    LowestCommonAncestor g(n);
    rep(i,n){
        int k;
        cin >> k;
        rep(j,k){
            int c;
            cin >> c;
            g.addEdge(i,c);
        }
    }
    g.decomp(0);
    int q;
    cin >> q;
    rep(i,q){
        int u,v;
        cin >> u >> v;
        cout << g.solve(u,v) << endl;
    }
}

Measured memory_bytes: 10292
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] A = new int[n];
		for (int i = 0; i < n; i++)
			A[i] = scanner.nextInt();
		StringBuilder builder = new StringBuilder();
		trace(A, n, builder);

		for (int i = 1; i < n; i++) {
			int v = A[i];
			int j = i - 1;
			while (j >= 0 && A[j] > v) {
				A[j + 1] = A[j];
				j--;
			}
			A[j + 1] = v;
			trace(A, n, builder);
		}
		System.out.print(builder);
	}

	private static void trace(int[] A, int n, StringBuilder builder) {
		for (int i = 0; i < n; i++) {
			if (i > 0)
				builder.append(" ");
			builder.append(A[i]);
		}
		builder.append("\n");
	}
}

Measured memory_bytes: 18956
n = int(input())
counts = {'AC': 0, 'TLE': 0, 'WA': 0, 'RE': 0}
for i in range(n):
  s = input()
  counts[s] += 1
print("AC x "+str(counts['AC']))
print("WA x "+str(counts['WA']))
print("TLE x "+str(counts['TLE']))
print("RE x "+str(counts['RE']))

Measured memory_bytes: 9212
#NとLを入力
N, L = map(int, input().split())


# 空のリストを生成
S = []

#入力
for i in  range(N):
    array = input()
    S.append(array)

#辞書順に並べ替え
S.sort()

#pythonのリストの出力では[と,が出力されるので取る
S=''.join(S)

#出力
print(S)

Measured memory_bytes: 8748
cnt = 0
n = int(input())
for i in range(0,n):
    d1, d2 = map(int, input().split())
    if d1 == d2:
        cnt += 1
        if cnt == 3 :
            print("Yes")
            break
    elif  cnt >= 0 and d1 != d2:
        cnt = 0 
    if i == n-1:
        print("No")

Measured memory_bytes: 62424
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		double[] v = new double[N];

		for (int i = 0; i < N; i++)
			v[i] = sc.nextDouble();

		Arrays.parallelSort(v);

		double x = (v[0] + v[1]) / 2;
		for (int i = 2; i < N; i++) {
			x = (x + v[i]) / 2;
		}
		System.out.println(x);
	}

}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,x;
  cin>>n;
  for(int i=1;i<=n;++i){
    x=i;
    if(x%3==0||x%10==3){
      cout<<" "<<i;
      continue;
    }
    x/=10;
    while(x){
      if(x%10==3) {
	cout<<" "<<i; break;
      }
      x/=10;
    }
  }
  cout<<endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vst;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;


const ll mod=1e9+7;
const ll inf=1e16; 

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)


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

 ll N;
  cin >> N;
  vll A(N),B(N),C(N);
  rep(i,0,N) cin >> A[i];
   rep(i,0,N) cin >> B[i];
   rep(i,0,N) cin >> C[i];
  
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  sort(C.begin(),C.end());
  
  ll res=0;
  rep(i,0,N){
   ll l=lower_bound(A.begin(),A.end(),B[i])-A.begin();
   ll r=N-(upper_bound(C.begin(),C.end(),B[i])-C.begin());
   res+=l*r;
  }
  cout << res << endl;
}


Measured memory_bytes: 2560
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let S: String = read();
    let cnt = S
        .chars()
        .zip(['0', '1'].iter().cycle())
        .filter(|&(a, b)| &a==b)
        .count();
    println!("{}", std::cmp::min(cnt, S.len()-cnt));
}


Measured memory_bytes: 4352
import itertools
n = int(input())
p_li = int("".join(input().split()))
q_li = int("".join(input().split()))

all_list=itertools.permutations(range(1,n+1))
cnt_p,cnt_q=0,0

for i in all_list:
    i_li = int("".join(map(str, i)))
    if p_li > i_li:
        cnt_p += 1
    if q_li > i_li:
        cnt_q += 1
    

print(abs(cnt_p-cnt_q))

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        int X = ni();
        int Y = ni();

        String ans = "Yes";
        int b2 = Y-2*X;
        if(b2%2==1 || b2<0){
            ans = "No";
        }
        else{
            int a = X-(Y-2*X)/2;
            if(a<0) ans ="No";
        }
        

 
        out.println(ans);
    }

 
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 32720
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define F  first
#define S  second
#define ff(i,n) for(i=0;i<n;i++)
ll bg=1000000000000000000;
ll power(ll x,ll y)
{
	if(y==0)
		return 1;
	ll h=power(x,y/2)%bg;	
	h=(h*h)%bg;
	if(y%2==1)
	  return (x*h)%bg;
	else
	  return h%bg;  
}
ll modinv(ll m)
{
	return power(m,bg-2)%bg;
}
int main()
{ 
	ll t;
	t=1;
	while(t--)
	{
		ll n,i,vertex = 0;
		cin>>n;
		ll a[n+1],b[n+1];
		ff(i,n+1)
		   cin>>a[i];
		b[0] = 1-a[0];
		if(b[0]<0)
		{
			cout<<"-1";
			return 0;	
		}   
		for(i=1;i<=n;i++)
		{
			b[i] = min(bg,2*b[i-1]-a[i]);
			if(b[i]<0)
			{
				cout<<"-1";
				return 0;
			}
		}
		b[n] = 0;
		for(i=n-1;i>=0;i--)
			b[i]=min(b[i],a[i+1]+b[i+1]);
		for(i=0;i<n;i++)
			vertex+=(a[i]+b[i]);
		vertex+=a[n];
		cout<<vertex;			
	}   
	return 0;
}

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

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

set<ll> v {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
ll c = 0;
int g;

void rec(int n, int k){
    if(k == 0){
        v.insert(c);
        return;
    } else if(k < g){
        if(n > 0){
            c += (n-1)*pow(10, k-1);
            rec(n-1, k-1);
            c -= (n-1)*pow(10, k-1);
        }
        c += (n)*pow(10, k-1);
        rec(n, k-1);
        c -= (n)*pow(10, k-1);
        if(n < 9){
            c += (n+1)*pow(10, k-1);
            rec(n+1, k-1);
            c -= (n+1)*pow(10, k-1);
        }
    } else {
        for(int i = n; i <= 9; ++i){
            if(i > 0){
                c += (i-1)*pow(10, k-1);
                rec(i-1, k-1);
                c -= (i-1)*pow(10, k-1);
            }
            c += (i)*pow(10, k-1);
            rec(i, k-1);
            c -= (i)*pow(10, k-1);
            if(i < 9){
                c += (i+1)*pow(10, k-1);
                rec(i+1, k-1);
                c -= (i+1)*pow(10, k-1);
            }
        }
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int k;
    cin >> k;
    g = 2;
    while(v.size()<k+1){
        rec(1, g);
        ++g;
    }
    vector<ll> a(v.size());
    int i = 0;
    for(auto& el : v){
        a[i] = el;
        ++i;
    }
    cout << a[k] << endl;
}

Measured memory_bytes: 11136
while True:
    IN = list(map(int,input().split()))
    a = IN[0]+IN[1]
    if IN[0]==-1 and IN[1]==-1 and IN[2]==-1:
        break
    elif IN[0]==-1 or IN[1]==-1 or a < 30:
        print("F")
    elif a >= 80:
        print("A")
    elif a >=65:
        print("B")
    elif a >=50 or IN[2]>=50:
        print("C")
    else:
        print("D")



Measured memory_bytes: 5596
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		// スペース区切りの整数の入力
		int b = sc.nextInt();
		
		// 出力
		System.out.println(a-b+1);
	}
}

Measured memory_bytes: 21204
#include <stdio.h>

int main()
{
    int i;

    //入力
    int n;
    scanf("%d", &n);
    int R[n];
    for( i = 0; i < n; ++i )
        scanf("%d", &R[i]);

    //minが最小になるようにmaxを選ぶ
    int min = R[0], max = R[1] - R[0];
    for( i = 1; i < n; ++i ){
        max = max < R[i] - min ? R[i] - min : max;
        min = min > R[i] ? R[i] : min; //minは後から更新しないと R[i]-min == min-min になる
    }

    printf("%d\n", max);

    return 0;
}



Measured memory_bytes: 2572
#include <bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
using namespace std;
 
int main() {
    fast();
    string s;
    cin >> s;
    int flag=0;
    ll n = s.length();
    for(ll i=0;i<n;i++){
        if(s[i] != s[n-1-i])
        	flag=1;
    }
    int j = (s.length()+3)/2-1;
    int i = 0;
    for(; j < s.length() && i < s.length(); j++, i++){
        if(s[j]!=s[s.length()-1-i]){
            flag=1;
        }
    }
    if(flag)
    	cout<<"No";
    else
    	cout<<"Yes";
  	return 0;
}

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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

int main(){
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    rep(i,ty-sy) cout << "U";
    rep(i,tx-sx) cout << "R";
    rep(i,ty-sy) cout << "D";
    rep(i,tx-sx) cout << "L";
    cout << "L";
    rep(i,ty-sy+1) cout << "U";
    rep(i,tx-sx+1) cout << "R";
    cout << "D";
    cout << "R";
    rep(i,ty-sy+1) cout << "D";
    rep(i,tx-sx+1) cout << "L";
    cout << "U";
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    Map<Integer, Integer> odds = new HashMap<>();
    Map<Integer, Integer> evens = new HashMap<>();
    int N = scanner.nextInt();
    for (int i = 0; i < N; i++) {
      int a = scanner.nextInt();
      if (i % 2 == 0) {
        evens.put(a, evens.getOrDefault(a, 0) + 1);
      } else {
        odds.put(a, odds.getOrDefault(a, 0) + 1);
      }
    }

    List<Map.Entry<Integer, Integer>> o = new ArrayList<>(odds.entrySet());
    List<Map.Entry<Integer, Integer>> e = new ArrayList<>(evens.entrySet());
    o.sort((o1, o2) -> o2.getValue() - o1.getValue());
    e.sort((o1, o2) -> o2.getValue() - o1.getValue());

    int o1 = o.get(0).getValue();
    int o2 = o.size() == 1 ? 0 : o.get(1).getValue();
    int e1 = e.get(0).getValue();
    int e2 = e.size() == 1 ? 0 : e.get(1).getValue();

    if (!o.get(0).getKey().equals(e.get(0).getKey())) {
      System.out.println(N - o1 - e1);
    } else {
      System.out.println(N - Math.max(o1 + e2, o2 + e1));
    }
  }
}


Measured memory_bytes: 63284
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>

using namespace std;
typedef pair<int, int> P;

void solve()
{
	int N;
	cin >> N;
	set<long long int> Set;
	Set.insert(0);
	for (int i = 0; i < 10; ++i)
	{
		set<long long int> SetNext;
		set<long long int>::iterator it = Set.begin();
		while (it != Set.end())
		{
			long long int num = *it;
			SetNext.insert(num * 10 + 3);
			SetNext.insert(num * 10 + 5);
			SetNext.insert(num * 10 + 7);
			++it;
		}
		it = SetNext.begin();
		while (it != SetNext.end())
		{
			Set.insert(*it);
			++it;
		}
	}
	set<long long int>::iterator it = Set.begin();
	int ans = 0;
	while (*it <= N)
	{
		long long int num = *it;
		++it;
		bool isThree = false;
		bool isFive = false;
		bool isSeven = false;
		while (num > 0)
		{
			if (num % 10 == 3)
			{
				isThree = true;
			}
			else if (num % 10 == 5)
			{
				isFive = true;
			}
			else if (num % 10 == 7)
			{
				isSeven = true;
			}
			num /= 10;
		}
		if (isThree && isFive && isSeven)
		{
			++ans;
		}
	}
	cout << ans << endl;
}

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

Measured memory_bytes: 8576
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default
s=list(input())
n=len(s)
t=input()
m=len(t)
dic={}
ans=0
for i in range(len(s)):
    if s[i] not in dic:
        dic[s[i]]=[i]
    else:
        dic[s[i]].append(i)
b=-1
for i in range(m):
    if t[i] not in dic:
        print(-1)
        exit()
    res=dic[t[i]]
    if res[-1]<=b:
        ans+=res[0]+1+(n-b-1)
        b=res[0]
    else:
        idx=bisect.bisect_right(res,b)
        ans+=res[idx]-b
        b=res[idx]
print(ans)

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

int countTriangles(int* arr, int n)
{
 
    if(n<3) return 0;    
    sort(arr,arr+n);
    int count = 0;
    int i = 0;
    int j = i+1;
    while(i<n-2)
    {
        int k = j+1;
        while(k<n && arr[k] < arr[i] + arr[j])
            k++;
        count += k-j-1;
        j++;
        
        if(j>=n)
        {
            i++;
            j = i+1;
        }
    }
    return count;
}



int main(){
    int n,i, x,l;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++) cin>>a[i];
    
    int ans = countTriangles(a,n);
    cout<<ans;
    
    
  return 0;
	}
    

Measured memory_bytes: 256
def fact_mod(n: int, mod: int)->int:
    ret = 1
    while n > 0:
        ret = (ret * n) % mod
        n -= 1
    return ret


def reconciled(N: int, M: int)->int:
    MOD = 10**9 + 7
    if abs(N - M) > 1:
        return 0
    if abs(N - M) == 1:
        return (fact_mod(N, MOD) * fact_mod(M, MOD)) % MOD

    return (2 * fact_mod(N, MOD) * fact_mod(M, MOD)) % MOD


if __name__ == "__main__":
    N, M = map(int, input().split())
    ans = reconciled(N, M)
    print(ans)


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

int main()
{
	int a, b, c, x, ans = 0;;
	cin >> a >> b >> c >> x;
	for (int i = a; i >= 0; i--) {
		for (int j = b; j >= 0; j--) {
			for (int k = c; k >= 0; k--) {
				if (x == 500 * i + 100 * j + 50 * k) ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int         long long int
#define vi           vector<int>
#define pii          pair<int,int>
#define vpp          vector<pii>
#define mii          map<int,int>
#define pb           push_back
#define endl        '\n'
#define rep(i,a,bb)  for(int i=a;i<bb;i++)
#define ff           first
#define ss           second
#define fast         ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test         int T;cin>>T;while(T--)
#define __sort(v)    sort(v.begin(),v.end())
#define __rsort(v)   sort(v.rbegin(),v.rend())
#define setbits(x)   __builtin_popcount(x)
#define zrobits(x)   __builtin_ctzint(x)
//const int inf = 5 * (1e+18);
const int mod = 7 + 1e+9;

int32_t main()
{
  fast;

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif


  string s, t;
  cin >> s >> t;
  if (s == t.substr(0, s.size()))
    cout << "Yes";
  else cout << "No";







}




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

using namespace std;

const int max_n=1e5+10;
int a[max_n],ans1,ans2;
bool b[max_n];

int main(){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int p;string s;
        cin>>p>>s;
        if(s[0]=='W')
            a[p]++;
        if(s[0]=='A'&&!b[p]){
            ans1++,ans2+=a[p];
            b[p]=true;
        }
    }
    cout<<ans1<<' '<<ans2<<endl;

    return 0;
}


Measured memory_bytes: 768
from numpy.linalg import solve
X,Y = map(int,(input().split()))
left = [[1, 1],[2, 4]]
 
right = [X, Y]

if(int(solve(left, right)[0])>=0 and int(solve(left, right)[1])>=0 and solve(left, right)[0].is_integer() and solve(left, right)[1].is_integer()):
  print("Yes")
else:
  print("No")

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

const int N = 100010;
typedef long long ll;

int aux[N];

struct perm{
	static const int N = 100010;

	int &operator [](const int &n){return a[n];}

	int n;
	int a[N];
};

void change(perm &p, perm &q){
	for (int i = 1; i <= p.n; ++ i){
		aux[i] = p[q[i]];
	}
	for (int i = 1; i <= p.n; ++ i){
		p[i] = aux[i];
	}
}

perm p, q, aaux;
int x[N];

int main(){
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; ++ i){
		scanf("%d", &x[i]);
	}
	int m;
	ll k;
	scanf("%d%lld", &m, &k);
	p.n = n;
	for (int i = 1; i <= n; ++ i){
		p[i] = i;
	}
	for (int i = 0, x; i < m; ++ i){
		scanf("%d", &x);
		std::swap(p[x - 1], p[x]);
	}
	q.n = n;
	for (int i = 1; i <= n; ++ i){
		q[i] = i;
	}
	for ( ; k > 0; k >>= 1){
		if (k & 1){
			change(q, p);
		}
		aaux = p;
		change(p, aaux);
	}
	ll now = x[1];
	for (int i = 1; i <= n; ++ i){
		printf("%lld.0\n", now);
		now += x[q[i] + 1] - x[q[i]];
	}
	return 0;
}

Measured memory_bytes: 3456
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////


int main() {

	ll N;
	cin >> N;
	vector<ll> A(N + 1), B(N + 1);
	repn(i, N) cin >> A[i] >> B[i];

	ll ans = 0;

	for(ll i=N; i>=1; i--) {
		A[i] += ans;
		ll d = A[i] % B[i];
		if (d > 0) { ans += B[i] - d; }
	}

	cout << ans;


	system("PAUSE");

}





Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;


int main(){
    //整数の2乗の数のリストを作る(100は適当)
    vector<int> pow(200);
    for(int i=1; i<=200; i++){
            pow[i] = i*i;
    }

    int n, d;
    cin >> n >> d;
    //vector<vector<要素の型>> 変数名(要素数1, vector<要素の型>(要素数2, 初期値))
    vector<vector<int>> x(n,vector<int>(d,0));

    //入力
    for(int i=0; i<n; i++){
        for(int j=0; j<d; j++){
            cin >> x[i][j];
        }
    }
    int ans=0;
    //距離を計算 iが比べる点、jが比べられる点
    for(int i=0; i<n-1; i++){
        for(int j=i+1; j<n; j++){
            int dif=0;
            for(int k=0; k<d; k++){
                dif += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            }
            //difがpowに含まれる(=平方数)ならans++
            for(int l=1; l<200; l++){
                if(pow[l]==dif) ans ++;
            }
        }
    }
    cout << ans << endl;


}

Measured memory_bytes: 3608
#include <stdio.h>

int main(void){
    int a[3][3];
    int f[3][3];
    int n;
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            scanf("%d",&a[i][j]);
            f[i][j]=0;
        }
    }
    scanf("%d",&n);
    int b[n];
    for(int i=0; i<n; i++){
        scanf("%d",&b[i]);
        for(int j=0; j<3; j++){
            for(int k=0; k<3; k++){
                if(b[i]==a[j][k]){
                    f[j][k]=1;
                }
            }
        }
    }
    if(f[0][0]==1&&f[0][1]==1&&f[0][2]==1 ||
    f[0][0]==1&&f[1][0]==1&&f[2][0]==1 ||
    f[0][0]==1&&f[1][1]==1&&f[2][2]==1 ||
    f[0][1]==1&&f[1][1]==1&&f[2][1]==1 ||
    f[0][2]==1&&f[1][2]==1&&f[2][2]==1 ||
    f[1][0]==1&&f[1][1]==1&&f[1][2]==1 ||
    f[2][0]==1&&f[2][1]==1&&f[2][2]==1 ||
    f[2][0]==1&&f[1][1]==1&&f[0][2]==1){
        printf("Yes\n");
    } 
    else{
        printf("No\n");
    }
}


Measured memory_bytes: 128
#include<cmath>
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#include<stack>
#include<vector>
#include<string.h>
#include<string>
#include<iomanip>
#include <sstream>
#include<map>
#include<complex>
using namespace std;
#define rep(i,t,n)  for(ll i =(t);i<=(n);++i)
#define per(i,n,t)  for(int i =(n);i>=(t);--i)
#define mmm(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define Decimal fixed<<setprecision(20)
#define debug(x) cerr<<#x<<":"<<x<<endl
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0)
typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 2e3 + 5;
typedef double db;



const int N = 10;
bool ok(int x) { return x >= 1 && x <= 9; }
int main() {
	FAST_IO;
	int a, b;
	cin >> a >> b;
	cout << (ok(a) && ok(b) ? a * b : -1) << endl;

}         
/*
2
A 0 0 2
B 1 0 2


*/


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int h1 = in.nextInt();
        int m1 = in.nextInt();
        int h2 = in.nextInt();
        int m2 = in.nextInt();
        int k = in.nextInt();
        int hm1 = h1*60 + m1;
        int hm2 = h2*60 + m2;
        int ans = Math.max(0, hm2 - hm1 - k);
        System.out.println(ans);
    }
}


Measured memory_bytes: 35716
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

#define PI 3.141592653589793238
#define INF 1050000000

using namespace std;



//cout << fixed << setprecision(15) << << endl;
//cout << << endl;

int main() {

	string a,b,c;

	cin >> a >> b >>c;

	if (a.back() == b.front() && b.back() == c.front()) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}



	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main()
{

    string s,t;
    cin>>s;
    cin>>t;
    int i,c=0;
    for(i=0;i<3;i++){
        if(s[i]==t[i]){
            c++;
        }
    }
    cout<<c;

}

Measured memory_bytes: 256
import sys
from math import gcd
from itertools import combinations


def main():
    input = sys.stdin.buffer.readline
    k = int(input())
    dp = [1]*(k+1)
    for i in range(2, k+1):
        dp[i] = dp[i-1]+i
        for e in combinations(range(1, i), 2):
            dp[i] += 6*gcd(gcd(e[0], e[1]), i)
        for j in range(1, i):
            dp[i] += 6*gcd(i, j)
    print(dp[k])


if __name__ == '__main__':
    main()


Measured memory_bytes: 9136
#include <stdio.h>

int main( void ) {
	double n;
	int i, ni;
	char res[ 14 ] = { "        ." };

	while ( scanf( "%lf", &n ), ( n *= 16 ) >= 0 )
		if ( n - ( ni = n ) > 0.000001 || ni > 4095 )
			puts( "NA" );
		else {
			for ( i = 13; i--; i != 8 ? res[ i ] = '0' + ni % 2, ni /= 2 : 0 ) ;

			printf( "%s\n", res );
		}

	return 0;
}

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

// Top Down DP
int frog2TopDown(int cur, int heights[], int N, int K, int dp[]) {
    // Base Case
    if(cur >= N) return 0;
    // Recursive Case
    if(dp[cur] != 0) return dp[cur]; // Look Up
    int ans = INT_MAX;
    for(int steps = 1; steps <= K; steps++) {
        ans = min(ans, (abs(heights[cur] - heights[cur + steps]) + frog2TopDown((cur + steps), heights, N, K, dp)));
    }
    return (dp[cur] = ans);
}

// Bottom Up DP
int frog2BottomUp(int heights[], int N, int K) {
    int dp[100005] = {0};
    dp[0] = 0; // Base Case
    for(int i = 1; i <= N; i++) {
        dp[i] = INT_MAX;
        for(int steps = 1; steps <= K; steps++) {
            int cur_ans = (i < steps) ? INT_MAX : (abs(heights[i] - heights[i - steps]) + dp[i - steps]);
            dp[i] = min(dp[i], cur_ans);
        }
        // for(int step = (i - 1); (step >= 1 && (i - step) <= K); step--) {
            // dp[i] = min(dp[i], abs(heights[i] - heights[step]) + dp[step]);
        // }
    }
    return dp[N];
}

int main() {
    int N, K;
    cin >> N >> K;
    int heights[100005];
    for(int i = 0; i < N; i++) cin >> heights[i];
    // Top Down Approach
    // int dp[100005] = {0};
    // cout << frog2TopDown(0, heights, N - 1, K, dp) << endl;
    // Bottom Up Approach
    cout << frog2BottomUp(heights, N - 1, K) << endl;
    return 0;
}

Measured memory_bytes: 4364