akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<stack>
#include<functional>
#include<list>
#include<map>
using namespace std;

int main() {
	int a;
	while (cin >> a, a) {
		vector<int>b[30];
		for (int c = 0; c < a; c++) {
			int d; cin >> d;
			for (int e = 0; e < d; e++) {
				int f; cin >> f; f--;
				b[f].push_back(c);
			}
		}
		for (int c = 0; c < 30; c++) {
			bool e[50]{};
			if (b[c].size())e[b[c][0]] = true;
			for (int d = c; d >= 0; d--) {
				bool f = false;
				for (int g = 0; g < b[d].size(); g++) {
					if (e[b[d][g]])f = true;
				}
				if (f) {
					for (int g = 0; g < b[d].size(); g++) {
						e[b[d][g]] = true;
					}
				}
			}
			bool k = true;
			for (int i = 0; i < a; i++) {
				if (!e[i])k = false;
			}
			if (k) { cout << c + 1 << endl; goto l; }
		}
		puts("-1");
	l:;
	}
}

Measured memory_bytes: 3000
#include<bits/stdc++.h>
using namespace std;
int main()
{
  map<string,int>mp;
  string a,b; cin>>a>>b;
  int x,y; cin>>x>>y;
  mp[a]=x;
  mp[b]=y;
  string t; cin>>t;
  mp[t]--;
  cout<<mp[a]<<" "<<mp[b];
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int h,w,count=0;
	char a[1010][60];
	cin>>h>>w;
	for(int i=1;i<=h;i++)
		for(int k=1;k<=w;k++)
			cin>>a[i][k];
	for(int i=1;i<=h;i++)
	{
		for(int k=1;k<=w;k++)
		{
			if(a[i][k]=='#') cout<<a[i][k];
			else
			{
				if(a[i-1][k-1]=='#') count++;
				if(a[i-1][k]=='#') count++;
				if(a[i-1][k+1]=='#') count++;
				if(a[i+1][k]=='#') count++;
				if(a[i+1][k-1]=='#') count++;
				if(a[i+1][k+1]=='#') count++;
				if(a[i][k-1]=='#') count++;
				if(a[i][k+1]=='#') count++;
				cout<<count;
			}
			count=0;
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main(){
  int n,k,i;
  std::cin>>n>>k;
  char a[n];
  for (i=0;i<n;i++)std::cin>>a[i];
  a[k-1]+='a'-'A';
  for (i=0;i<n;i++)std::cout<<a[i];
  std::cout<<'\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <cstdio>

using namespace std;

int main(void) {

    int n;
    cin >> n;

    int max = -1e+6-1, min = 1e+6+1;
    long long total = 0;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        if (a > max) { max = a; }
        if (a < min) { min = a; }
        total += a;
    }

    printf("%d %d %lld\n", min, max, total);

    return 0;
}

Measured memory_bytes: 1148
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< long long > vll;
typedef pair< int,int > ii;
typedef long long ll;
#define sz(a) int((a).size())
#define pb push_back
#define mp  make_pair
#define mod 1000000007
#define mod2 998244353
#define all(c) c.begin(),c.end()
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) (c.find(x) != c.end())
#define cpresent(c,x) (find(all(c),x) != c.end())


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string a,b;
    cin>>a>>b;
    int f=0;
    for(int i=0;i<(int)a.length();i++){
        if(a[i]!=b[i]){
            f=1;
            break;
        }
    }
    if(f){
        cout<<"No\n";
    }
    else{
        cout<<"Yes\n";
    }
	return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
int vis[10];
int n;
int cnt;
int dfs(int num,vector<int> &v,vector<int> tmp){
	if((int)v.size() == n){
		
		if(v == tmp)return cnt;
		cnt++;
		return -1;
	}
	int ret = -1;
	for(int i = 1;i <=n;i++){
		if(vis[i])continue;
		vis[i] = 1;
		v.push_back(i);
		ret = max(ret,dfs(num,v,tmp));
		v.pop_back();
		vis[i] = 0;
	}
	return ret;
	
}
signed main(){
	cin >> n;
	vector<int> a(n),b(n);
	rep(i,n)cin >> a[i];
	rep(i,n)cin >> b[i];
	vector<int> v;
	int A = dfs(0,v,a);
	v.clear();
	cnt = 0;
	int B = dfs(0,v,b);
	//trace(A,B);
	cout << abs(A-B) << endl;
	return 0;
}

Measured memory_bytes: 3580
# -*- coding:utf-8 -*-
n, m, k = map(int, input().split())
factor = []
factor.append(n*m)
#for tmp in range(min(n,m)):
#    sides = tmp+1
#    factor.append(sides**2+((n-sides)*(m-sides)))
factor.append((n//2)*(m//2)*2 + ((((n%2)*m+(m%2)*n)-1)//2 + 1))
for tmp in range(1,n+1):
    for tmp2 in range(1, m+1):
        factor.append(tmp*tmp2 + (n-tmp)*(m-tmp2))
factor = list(set(factor))
if k in factor or k%n == 0 or k%m == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 54956
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n,buf, sum=0;
    cin>>n; buf=n;
    int k=0;
    while((buf=buf/10)>0)k++;
    for(int s=0; s<1<<k; s++){
        long long div=10; buf=n;
        for(int i=k-1; i>=0; i--){
            if(s&(1<<i)){
                sum+=buf%div; buf/=div; div=10;
            }
            else div*=10;
        }
        sum+=buf%div;
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl enjoy_codeforces
int main(){
    int n;std::cin>>n;
    std::vector<std::vector<std::pair<int,int>>>g(n);
    for(int i=0;i<n-1;i++){
        int u,v;std::cin>>u>>v;u--,v--;
        g.at(u).emplace_back(v,i);
        g.at(v).emplace_back(u,i);
    }

    int q;std::cin>>q;
    int Q=1<<q;
    std::vector<long long>a(n-1);
    for(int i=0;i<q;i++){
        int u,v;std::cin>>u>>v;u--,v--;
        auto dfs=[&](auto&&dfs,int x,int p)->bool{
            if(x==v)return true;
            for(auto&&pair:g.at(x)){
                int y,id;std::tie(y,id)=pair;
                if(y==p)continue;
                if(dfs(dfs,y,x)){
                    a.at(id)^=1ll<<i;
                    return true;
                }
            }
            return false;
        };
        dfs(dfs,u,u);
    }

    long long ans=0;
    for(int i=0;i<Q;i++){
        int counter=n-1;
        for(int j=0;j<n-1;j++){
            counter-=!!(a.at(j)&i);
        }
        ans+=(__builtin_popcount(i)&1?-1ll:1ll)*(1ll<<counter);
    }
    std::cout<<ans<<'\n';
}



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

using namespace std;

typedef long long ll;
ll n, k;

int main(){
	cin >> n >> k;
	if(n > k){
		n %= k;
	}
	
	if(n <= k){
		if(n <= k/2)
			cout << n;
		else
			cout << k-n;
	}
	
	return 0;
}

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

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,inp;
	cin >> n;
	map<int,int> m;
	priority_queue<int> pq;
	for(int t=0;t<n;t++){
		cin >> inp;
		m[inp]++;
		if(m[inp]==2){
			pq.emplace(inp);
			m[inp]=0;
		}
	}
	long long w,l;
	if(pq.size()){
		w=pq.top();
		pq.pop();
	}
	else{
		cout << "0\n";
		return 0;
	}
	if(pq.size()){
		l=pq.top();
		cout << w*l << '\n';
	}
	else cout << "0\n";
}

Measured memory_bytes: 4992
S = str(input())

flag = True
for i in range(len(S)):
    if i%2 == 0:
        if S[i] != "R" and S[i] != "U" and S[i] != "D":
            flag = False 
    elif i%2 == 1:
        if S[i] != "L" and S[i] != "U" and S[i] != "D":
            flag = False

if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
s = input().strip()

def check(s):
    t = len(s)
    for i in range(0, t // 2):
        if s[i] != s[t - 1 - i]:
            return False

    return True

n = len(s)
if check(s) and check(s[0:(n - 1) // 2]) and check(s[((n + 3) // 2):-1]):
    print('Yes')
else:
    print('No')



Measured memory_bytes: 38384
from collections import deque

# input
condition=list(map(int, input().split()))
queue=deque([input().split() for i in range(condition[0])])
timer=0

# process
while len(queue) > 0:
    task=queue.popleft()
    name=task[0]
    cost=int(task[1])
    if cost <= condition[1]:
        timer+=cost
        print(name + ' ' + str(timer))
    else:
        timer+=condition[1]
        queue.append([name, cost-condition[1]])
        
    


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

using namespace __gnu_pbds;
using namespace std;
 
#define int long long int
#define pb push_back
#define mp make_pair
#define loop(i,x,n) for(int i=x;i<=n;i++)
#define rloop(i,x,n) for(int i=x;i>=n;i--)
#define ff first
#define ss second
#define N4RUTO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 
typedef tree<int, null_type, less<int>, rb_tree_tag,  
// typedef tree<int, null_type, less_equal<int>, rb_tree_tag,  
tree_order_statistics_node_update>
ordered_set;
 
int32_t main(){
    N4RUTO;
    int t;
    t=1;
    // cin>>t;
    while(t--){
        long double a,b,c,d;
        cin>>a>>b>>c>>d;
        // cout<<ceil(a/d)<<" "<<ceil(c/b)<<"\n";
        if(ceil(a/d)<ceil(c/b)) cout<<"No\n";
        else
        {
            cout<<"Yes\n";
        }
        
    }
    return 0;
}

Measured memory_bytes: 3744
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n,m;
    while(cin >> n >> m, n){
        vector<int> x(m+1,0);
        for(int i = 0; i < n; i++){
            int d,v;
            cin >> d >> v;
            x[d] = max(x[d], v);
        }
        int ans = 0;
        for(int i = 1; i <= m ; i++) ans += x[i];
        cout << ans << endl;
    }
}



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

int main(){
    int n,m,c,B[20],ans=0,sum,a;
    cin>>n>>m>>c;
    for(int i=0;i<m;i++){
        cin>>B[i];
    }
    for(int i=0;i<n;i++){
        sum=c;
        for(int j=0;j<m;j++){
            cin>>a;
            sum+=a*B[j];
        }
        if(sum>0)ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#pragma comment (linker, "/STACK:256000000")
#define  _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()
void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(100);
}

#define int ll

void solve() {
	int n;
	cin >> n;
	int now_max = 0;
	int ans = 0;
	REP(i, n) {
		int a;
		cin >> a;
		a = n - a+1;
		if (a > now_max) {
			ans++;
			now_max = a;
		}
	}
	cout << ans << endl;
}

#undef int
int main() {
	init();
	solve();
}

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

#define ll long long
#define p_q priority_queue
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define str string
#define s_vec(data,name,vertical,horizontal) vector<vector<(data)>> (name)((vertical),vector<(data)>((horizontal)));
#define MOD 1000000007




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

        ll ax, ay;

        ax = (2 * x - y) / 3;
        ay = (2 * y - x) / 3;
    if((x+y)%3==0&&((ax>=0)&&(ay>=0))){

        ll vc = 1, vp = 1;
        for (ll i = 1; i <= ay; i++) {
            vc *= (ax + i);
            vc %= MOD;
            vp *= i;
            vp %= MOD;
        }

        for(ll i = 1; i < MOD; i++) {
            if((vp * i) % MOD == 1){
                vp = i;
                break;
            }
        }

        cout << (vc * vp) % MOD << endl;
    }else{
        cout<<0<<endl;
    }

}




Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static MyUtil;

class MyUtil
{
    public static void Swap<T>(ref T a, ref T b)
    {
	var t = a;
	a = b;
	b = t;
    }

    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }

    public static long[] ReadLongArray()
    {
	return ReadLine().Split().Select(x => long.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
	var t = ReadIntArray();
	int n = t[0], m= t[1], c = t[2];

	var b = ReadIntArray();

	int ans = 0;
	
	for (int i = 0; i < n; i++)
	{
	    var a = ReadIntArray();
	    int x = c;
	    for (int j = 0; j < m; j++)
	    {
		x += a[j] * b[j];
	    }

	    if (x > 0){ ans++; }
	}

	WriteLine(ans);
    }
}


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

typedef long long ll;
typedef unsigned long long ull;

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

    int A[100][100], v[100];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin >> A[i][j];
        }
    }
    for(int i=0;i<m;i++) cin >> v[i];

    for(int i=0;i<n;i++){
        int ans=0;
        for(int j=0;j<m;j++){
            ans+=A[i][j]*v[j];
        }
        cout << ans << endl;
    }
    
    return 0;
}


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

int main(){

  int n, tmp;
  ll ans = 0;
  vector<int> a, b, c;
  cin >> n;
  a.resize(n); b.resize(n); c.resize(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  rep(i,n) cin >> c[i];
  sort(a.begin(),a.end());
  sort(c.begin(),c.end());
  
  for(auto itr = b.begin(); itr != b.end(); itr++){
    ll d1 = distance(a.begin(), lower_bound(a.begin(),a.end(), *itr));
    ll d2 = distance(upper_bound(c.begin(),c.end(),*itr),c.end());
    ans += d1*d2;
  }

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

Measured memory_bytes: 1536
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <cstdlib>
#include <utility>
#include <map>
#include <set>
#include <ios>
#include <iomanip>
#include <functional>
#include <queue>

#define int long long

int inf = (1LL <<  62);

using namespace std;

signed main(){
    
    int n;
    cin >> n;
    map<int, int> mp;
    set<int> st;
    for(int i = 0; i < n; i++){
        int x[3];
        cin >> x[0];
        x[1] = x[0] - 1;
        x[2] = x[0] + 1;
        for(int j = 0; j < 3; j++){
            st.insert(x[j]);
            if(mp.find(x[j]) == mp.end()){
                mp[x[j]] = 1;
            }else{
                mp[x[j]]++;
            }
        }
    }
    int mx = 0;
    for(auto itr = st.begin(); itr != st.end(); ++itr) {
        mx = max(mx, mp[*itr]);
    }
    cout << mx;
    
}

Measured memory_bytes: 10624
#include<bits/stdc++.h>
    using namespace std;
    int main()
    {
      int n;
      cin>>n;
      int arr[n];
      for(int i=0;i<n;i++)
      {
          cin>>arr[i];
      }
      for(int i=n-1;i>=1;i--)
      {
          if(arr[i-1]==arr[i]+1)
          {
              arr[i-1]=arr[i];
              //cout<<arr[i-1]<<endl;
          }
          else if(arr[i-1]>arr[i]+1)
          {
              cout<<"No";
              return 0;
          }
      }
      cout<<"Yes";
      return 0;
    }

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#define For(N) for (int i = 0; i < N; i++)

using namespace std;
using ll = long long int;

void say(string);

int main() {
	int a, b;
	int x;
	cin >> a >> b;
	x = a + b;
	if (x % 2 == 0)say(to_string(x / 2));
	else say(to_string(x / 2 + 1));
	return 0;
}

void say(string s) {
	cout << s << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int m,n,i,j,t,y;
	int e[5];
	for(i=0;i<4;i++){
		scanf("%d",&e[i]);
	}
	sort(e,e+4);
	if(e[0]==e[1] && e[2]==e[3]){
		printf("yes\n");
	}
	else{
		printf("no\n");
		}
	}
	

Measured memory_bytes: 3188
#include<stdio.h>


int main(){
	int i,j,k,l,N,K,tmp,sum;
	sum = 0;
	int p[1000];
	
	if(scanf("%d%d",&N,&K) == -1){
    	return 0;
    }
	
	for(k = 0;k < N;k++){
		if(scanf("%d",&p[k]) == -1){
	    	return 0;
	    }
	}

	
	for(i = 0;i < (N-1);i++){
		for(j = (N-1);j > i;j--){
            if(p[j-1]>p[j]){
              tmp = p[j-1];
              p[j-1] = p[j];
              p[j] = tmp;
            }
		}
	}
	
	for(l = 0;l < K;l++){
		sum = sum + p[l];
	}
	
	printf("%d",sum);
	
}

Measured memory_bytes: 1736
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>

using namespace std;

int main()
{
    int n;
    int a[100010];
    int buc[100010] = {};
    int max = -1;

    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> a[i];
        buc[a[i]]++;
        buc[a[i]-1]++;
        buc[a[i]+1]++;
    }

    for (int i = 1; i < 100001; i++) {
        if (max < buc[i]) {
            max = buc[i];
        }
    }

    cout << max << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int q;
const ll MOD=1e9+7;
#define S 91
ll fib[S];
typedef pair<ll,ll> pll;
#define pb push_back
#define fi first
#define se second
vector<pll> ex[S];
void sol()
{
	ll a,b;
	scanf("%lld%lld",&a,&b);
	if(a>b) swap(a,b);
	int ans=1;
	for(int i=2;i<S;i++)
	{
		if(fib[i]<=a&&fib[i+1]<=b) ans=i;
		else break;
	}
	printf("%d ",ans);
	ll tot=0;
	if(ans==1)
		tot=(a%MOD)*(b%MOD)%MOD; //small enough
	else
	{
		for(unsigned _=0;_<ex[ans-1].size();++_)
		{
			ll x=ex[ans-1][_].fi,y=ex[ans-1][_].se;
			//(y,x+ky)
			if(y<=a) tot+=(b-x)/y, tot%=MOD;
			if(y<=b) tot+=(a-x)/y, tot%=MOD;
		}
	}
	tot=(tot%MOD+MOD)%MOD;
	printf("%d\n",int(tot));
}
int calc(ll x,ll y)
{
	if(x<y) swap(x,y);
	if(x&&y) return calc(y,x%y)+1;
	return 0;
}
void gen(int x)
{
	vector<pll>&s=ex[x-1],&t=ex[x];
	for(unsigned _=0;_<s.size();++_)
	{
		pll g=s[_];
		if(g.fi>g.se) throw "!!!";
		ll tmp=g.se; swap(g.fi,g.se);
		for(g.se+=tmp;g.se<=fib[x+2];g.se+=tmp)
		{
			if(calc(g.fi,g.se)!=x) continue;
			t.pb(g);
		}
	}
	sort(t.begin(),t.end());
	t.erase(unique(t.begin(),t.end()),t.end());
}
int main()
{
	fib[0]=1; fib[1]=1;
	for(int i=2;i<S;i++) fib[i]=fib[i-1]+fib[i-2];
	ex[1].pb(pll(1,2)); ex[1].pb(pll(1,3));
	for(int i=2;i+2<S;i++)
		gen(i);
	scanf("%d",&q);
	while(q--) sol();
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<long double, long double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int MOD = 1000000007;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

struct UnionFind {
  vector<int> d;
  UnionFind(int n = 0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

struct graph{
    int deg;
    int kouho;
    vector<int> block;
};

int main(){
    int n, m, k; cin >> n >> m >> k;
    vector<graph> vs(n);
    UnionFind uf(n);
    rep(i,m){
        int a, b; cin >> a >> b;
        a--; b--;
        vs[a].deg++;
        vs[b].deg++;
        uf.unite(a,b);
    }
    rep(i,k){
        int a, b; cin >> a >> b;
        a--; b--;
        vs[a].block.emplace_back(b);
        vs[b].block.emplace_back(a);
    }
    rep(i,n){
        vs[i].kouho = uf.size(i) - 1 -vs[i].deg;
        for (int x : vs[i].block){
            if (uf.same(i,x)) vs[i].kouho--;
        }
    }
    rep(i,n) printf("%d%c", vs[i].kouho, i == n-1 ? '\n':' ');
}

Measured memory_bytes: 7168
#include<stdio.h>
int main(){
  char a[3],b[3],count;
  scanf("%s",a);
  scanf("%s",b);
  for(int i = 0;i < 3;i++){
    if(a[i] == b[i]){
      count++;
    }
  }
  printf("%d",count);
  return 0;
}


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

int H;
int A[500001];

void maxHeapify(int i){
    int left, right, largest;
    left = i * 2;
    right = i * 2 + 1;
    
    if((left <= H) && (A[left] > A[i])) largest = left;
    else largest = i;
    if((right <= H) && (A[right] > A[largest])) largest = right;
    
    if(largest != i){
        swap(A[i], A[largest]);
        maxHeapify(largest);
    }
}

int main(){
    cin >> H;
    
    for(int i = 1; i <= H; i++) cin >> A[i];
    
    for(int i = (H/2); i >= 1; i--) maxHeapify(i);
    
    for(int i = 1; i <= H; i++) cout << " " << A[i];
    cout << endl;
    
    return 0;
}


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

int ppl[55]={0};
int n,p,now,num;

int main(){
  int i,j,k;
  while(1){
    cin >> n >> p;
    if(n+p==0)break;
    now = p;
    num = 0;
    while(1){
      if(now>0){
	ppl[num]++;
	now--;
      }
      else if(ppl[num]==p)break;
      else{
	now = ppl[num];
	ppl[num]=0;
      }
      num++;
      num%=n;
    }
    printf("%d\n",num);
    for(i=0;i<n;i++)ppl[i]=0;
  }
  return 0;
}



Measured memory_bytes: 3116
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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

int main() {
  int k, s;
  cin >> k >> s;
  int ans = 0;
  rep (i, k + 1) {
    rep (j, k + 1) {
      if (i + j <= s && s - (i + j) <= k) ans++;
    }
  }
  P(ans);
  return 0;
}


Measured memory_bytes: 256
module.exports=function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(r,i,function(e){return t[e]}.bind(null,i));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";var r=n(1),i=new(n(2))(r.readFileSync("/dev/stdin","utf8").trim().split(/\s+/g));n(4)(i)},function(t,e){t.exports=require("fs")},function(t,e,n){"use strict";var r=n(3);t.exports=class{constructor(t){this.inp=new r(t)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}add(t){this.inp.enq(t)}}},function(t,e,n){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=t.length,this.items=t,this.ind=0}enq(t){this.size+=1,this.items.push(t)}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}}},function(t,e,n){"use strict";t.exports=function(t){for(var e=t.in(),n=0;n<e;n++){if(t.in()%2==1)return void console.log("first")}console.log("second")}}]);

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

void swap(int &a, int &b)
{
	int tmp(a);
	a = b;
	b = tmp;
}

int main(){
  char m,n;
  int ball[3]={1,0,0};
  while(scanf("%c,%c",&m,&n) != EOF)
    swap(ball[m-'A'],ball[n-'A']);
  for(int i=0; i<3; i++){
    if(ball[i] == 1)
      m = i+'A';
  }
  cout << m << endl;
}

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

int a[500+50];

signed main(){
    ios::sync_with_stdio(false);
    
	int h,w,n;
	cin>>h>>w>>n;
	if(h>w){
		swap(h,w);
	}
	cout<<(n/w)+(n%w!=0);
}
/*

Mistakes to take care of-

1. For string s, s+=a is similar to appending to s. s = s + a takes O|s| + O|a| time. 
Relevant problem where I made mistake - https://codeforces.com/contest/1326/problem/D2

2. Try using constant value of N to declare arrays, etc. Else you might get hacked / FST.
Relevant problem where I made a mistake - https://codeforces.com/contest/1307/problem/D

3. While exponentiation, avoid modding the exponent. Or mod with mod-1.
Relevant problem where I made a mistake - https://codeforces.com/contest/1332/problem/E

4. modulo operator (%) in c++ returns the sign of the divisor.
Eg. (-1%8) = -1
Relevant problem where I made a mistake - https://codeforces.com/contest/1345/submission/79809463
*/

Measured memory_bytes: 256
# C - Big Array
def main():
    n, k = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in range(n)]
    ab.sort()

    i = 0

    while k > 0:
        k -= ab[i][1]
        i += 1
    else:
        print(ab[i-1][0])

if __name__ ==  "__main__":
    main()

Measured memory_bytes: 27496
using System;
using System.Collections.Generic;

class Program
{
	static void Main(string[] args)
	{
		int n = int.Parse(Console.ReadLine());

		LinkedList<int> list = new LinkedList<int>();

		for (int i = 0; i < n; i++)
		{
			string[] input = Console.ReadLine().Split(' ');

			switch (input[0])
			{
				case "insert":
					list.AddFirst(int.Parse(input[1]));
					break;
				case "delete":
					list.Remove(int.Parse(input[1]));
					break;
				case "deleteFirst":
					list.RemoveFirst();
					break;
				case "deleteLast":
					list.RemoveLast();
					break;
			}
		}

		bool space = false;
		foreach (int i in list)
		{
			Console.Write((space ? " " : "") + i);
			space = true;
		}

		Console.WriteLine();
	}
}



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

int main()
{
  int n;
  std::cin >> n;
  std::vector<int> t(n);
  int total = 0;
  for (auto& time : t)
  {
    std::cin >> time;
    total += time;
  }
  int m;
  std::cin >> m;
  for (int i = 0; i < m; ++i)
  {
    int p, x;
    std::cin >> p >> x; --p;
    std::cout << total - t[p] + x << std::endl;
  }
  return 0;
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)
typedef long long lint;

int N, a[200005], b[200005];

int main() {
	cin >> N;
	for_(i,0,N) {
		cin >> a[i];
		b[a[i]] = i;
	}
	
	lint ans = 0;
	set< lint > index = {-1,N};
	for_(i,1,N+1) {
		auto R = index.upper_bound(b[i]);
		auto L = R; --L;
		index.insert(b[i]);
		ans += ((*R) - b[i]) * (b[i] - (*L)) * i;
	}
	cout << ans << endl;
}

Measured memory_bytes: 11136
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<string> c(n);
	for (auto &x : c) cin >> x;
	int ans = 999999;
	for (int i = 1; i <= n - 2; i++) {
		for (int j = 1; i + j <= n - 1; j++) {
			int pans = 0;
			for (int k = 0; k < n; k++)
				for (int l = 0; l < m; l++)
					if (k < i && c[k][l] != 'W' || k >= i && k < i + j && c[k][l] != 'B' || k >= i + j && c[k][l] != 'R')
						pans++;
			ans = min(pans, ans);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3168
#include <iostream>
using namespace std;
int main(){
  string S;
  cin>>S;
  
  for(int i=0;i<S.length();i++){
    if(i%2==0 && S[i]=='L'){
      cout<<"No"<<endl;
      return 0;
    }else if(i%2==1 && S[i]=='R'){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
}

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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int n,W;
    cin >> n >> W;
    vector<vector<ll>> dp(n+1,vector<ll>(W+1,0));
    for (int i = 0;i < n;++i) {
        int w,v;
        cin >> w >> v;
        dp[i+1] = dp[i];
        for (int j = 0;j <= W-w;++j) dp[i+1][j+w] = max(dp[i+1][j+w],dp[i][j]+v);
    }
    cout << dp[n][W] << endl;
    return 0;
}

Measured memory_bytes: 80256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>

using namespace std;

void solve(int N) {
  int s = 0;
  int n = N;
  while (n > 0) {
    s += n % 10;
    n /= 10;
  }
  if (N % s == 0) {
    printf("Yes\n");

  } else {
    printf("No\n");
  }
}

int main() {
  int N;
  cin >> N;
  solve(N);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B,K;
  cin>>A>>B>>K;
  
  for(int i=A;i<A+K;i++){
    if(i<=B){
      cout<<i<<endl;
    }
    
  }
  for(int i=B-K+1;i<=B;i++){
    if(i>A+K-1){
      cout<<i<<endl;
    }
  }
}

Measured memory_bytes: 256
import java.util.*;


/**
 * Created by takaesumizuki on 2017/06/14.
 */
public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        Long facN = this.calcfac(N);
        Long facM = this.calcfac(M);
        if( N == M ){
            System.out.println(2 * facN * facM % 1000000007);
        }else if(N + 1 == M || N == M + 1){
            System.out.println(facN * facM % 1000000007);
        }else{
            System.out.println(0);
        }

    }

    Long calcfac(int num){
        Long sum = new Long(1);
        for(int i = num ; i > 0; i--){
            sum *= i;
            sum %= 1000000007;
        }
        return sum;
    }

    public static void main(String[] args) {
        new Main().run();
    }


}



Measured memory_bytes: 31956
#include <iostream>
using namespace std;
int main(){
  int n, m;
  cin >> n >> m;
  int s[m];
  char c[m];
  
  char number[n];
  for(int i = 0; i < n; i++)number[i] = 'a';
  for(int i = 0; i < m; i++){
    cin >> s[i] >> c[i];
    if(s[i] == 1 && c[i] == '0'&&n!=1){
      cout << -1 << endl;
      exit(0);
    }
    if(number[s[i]-1] == 'a')number[s[i]-1] = c[i];
    else if(number[s[i]-1] == c[i]){
      number[s[i]-1] = c[i];
    }else{
      cout << -1 << endl;
      exit(0);
    }
  }
  for(int i = 0; i < n; i++){
    if(number[i] == 'a')number[i]='0';
  }
  if(n!=1 && number[0]=='0')number[0] = '1';
  for(int i = 0; i < n; i++){
    cout << number[i];
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 256
//Utkarsh.25dec
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
using namespace std;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
bool vis[N];
vector <int> adj[N];
void solve()
{
    ll n,m;
    cin>>n>>m;
    if(min(n,m)==1)
    {
        cout<<1;
        return;
    }
    ll t=(n*m);
    if((t%2)==0)
    {
        cout<<t/2;
    }
    else
        cout<<(t/2+1);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

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

#define MAXN (100010)

int n;
char str[MAXN];
char word_5[2][6] = {"dream", "erase"};
char word_6[] = {"eraser"};
char word_7[] = {"dreamer"};
int f[MAXN]; 

bool check(char *s, int pos, int len){
	char tmp = str[pos + len];
	str[pos + len] = '\0';
	int res = strcmp(s, str + pos);
	str[pos + len] = tmp;
	return res == 0;
}

int main(){
	scanf("%s", str);
	n = strlen(str);
	f[0] = true;
	for(int i = 5; i <= n; ++ i){
		if(f[i - 5] && check(word_5[0], i - 5, 5)){
			f[i] = true;
			continue;
		}
		if(f[i - 5] && check(word_5[1], i - 5, 5)){
			f[i] = true;
			continue;
		}
		if(i >= 6 && f[i - 6] && check(word_6, i - 6, 6)){
			f[i] = true;
			continue;
		}
		if(i >= 7 && f[i - 7] && check(word_7, i - 7, 7)){
			f[i] = true;
			continue;
		}
	}
	printf(f[n] ? "YES\n" : "NO\n");
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <functional>
#include <algorithm>
using namespace std;

typedef long long ll;

vector<int> score;

int main()
{
    int n;
    while(cin >> n && n) {
        score.resize(n);
        for(int i = 0; i < n; i++) 
            cin >> score[i];

        sort(score.begin(), score.end());
        int sum = 0;
        for(int i = 1; i < n - 1; i++) 
            sum += score[i];
             
        cout << sum / (n - 2) << endl;
           
    }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define vl vector
using namespace std;

int main()
{
    ll t,i,n;
    ll a,b,c;
    cin>>n;
    map<string,ll> mp;
    for(i=0;i<n;i++)
    {
        string s;
        cin>>s;
        mp[s]++;
    }
    ll mx=INT_MIN;
    vl<string> ans;
    for(auto itr=mp.begin();itr!=mp.end();itr++) mx=max(mx,itr->second);
    for(auto itr=mp.begin();itr!=mp.end();itr++) if(itr->second==mx) ans.pb(itr->first);
    sort(ans.begin(),ans.end());
    for(i=0;i<ans.size();i++) cout<<ans[i]<<endl;
}

Measured memory_bytes: 27248
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  for(int i = 0; i < n; i++){
    cin >> p.at(i);
  }
  int counter = 0;
  for(int i = 1; i < n - 1; i++){
    if(p.at(i-1) < p.at(i) && p.at(i) < p.at(i+1)) counter++;
    else if(p.at(i-1) > p.at(i) && p.at(i) > p.at(i+1)) counter++;
  }
  cout << counter << endl;
}

Measured memory_bytes: 256
/*
 *  Author : Jun_SH
 *  Solution for sumitrust2019 146 A
 */
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
    int f=1,x=0;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return f*x;
}
main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,m,d;
    cin>>n>>d;
    cin>>m>>d;
    if(m==n+1)cout<<(1)<<endl;
    else cout<<(0)<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl "\n"
#ifdef ONLINE_JUDGE
#define DEBUG(x)
#else
#define DEBUG(x) cout<<#x<<" : {"<<x<<"}"<<endl;
#endif
using namespace std;
typedef long long int lli;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int l, r, d;
	cin >> l >> r >> d;
	int cnt = 0;
	bool f = false;
	if(l % d != 0) f = true;
	int start = (l / d) * (d + f);
	for(int i=max(start, d); i<=r; i+=d){
		cnt++;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 3604
N, K = map(int, input().split())
H = [int(h) for h in input().split()]
dp = [0]*N
dp[1] = abs(H[1]-H[0])
for i in range(2, N):
    dp[i] = min([dp[i-j]+abs(H[i]-H[i-j]) for j in range(1, min(K, i)+1)])
print(dp[N-1])

Measured memory_bytes: 52448
#include<bits/stdc++.h>
#define int long long
#define N 51
using namespace std;

int n, a, x[N], dp[N][N][N*N];

signed main(){
  
  cin>>n>>a;
  
  for(int i=0;i<n;i++) cin>>x[i];
  
  dp[0][0][0]=1;
  
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      for(int k=0;k<N*N;k++){
	dp[i+1][j][k]+=dp[i][j][k];
	dp[i+1][j+1][k+x[i]]+=dp[i][j][k];
      }
    }
  }
  
  int ans=0;
  
  for(int i=1;i<=n;i++)
    for(int j=0;j<N*N;j++)
      if(j%i==0&&j/i==a) ans+=dp[n][i][j];

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


Measured memory_bytes: 52096
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
#define PB push_back
#define MP make_pair
int main(){
  int n;
  while(cin>>n,n){
    int sum=0,m=-1;
    for(int i=0;i<n;i++){
      int k;
      cin>>k;
      if(k!=0)sum++;
      m=max(m,k);
    }
    if(m<2)cout<<"NA"<<endl;
    else cout<<sum+1<<endl;
  }
}

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N; scanf("%d", &N);
  map<int, int> freqs;
  for (int i = 0; i < N; ++i) {
    int val; scanf("%d", &val);
    ++freqs[val];
  }
  int ans = 0;
  for (map<int, int>::iterator iter = freqs.begin(); iter != freqs.end(); ++iter) {
    int val = iter->first, cnt = iter->second;
    if (val == cnt) { continue; }
    else if (val < cnt) { ans += (cnt - val); }
    else { ans += cnt; }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
void alert(vector<int> vec){
  int64_t N = vec.size();
  for(int64_t i=0; i<N-1; i++) cout << vec.at(i) << " ";
  cout << vec.at(N-1) << endl;
}

int main(){
  int N, M;
  cin >> N >> M;
  cout << N*(N-1)/2+M*(M-1)/2 << endl;
}

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

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


Measured memory_bytes: 3044
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

func main() {
	N := nextInt()
	A := nextInt()
	B := nextInt()

	vs := make([]int, N)
	for i := 0; i < N; i++ {
		vs[i] = nextInt()
	}

	sort.Sort(sort.Reverse(sort.IntSlice(vs)))

	var avg float64
	for i := 0; i < A; i++ {
		avg += float64(vs[i])
	}

	avg /= float64(A)

	// Make dp.
	dp := make([][]int, N+1)
	for i := 0; i <= N; i++ {
		dp[i] = make([]int, i+1)
		for j := 0; j <= i; j++ {
			if j == 0 || j == i {
				dp[i][j] = 1
			} else {
				dp[i][j] = dp[i-1][j-1] + dp[i-1][j]
			}
		}
	}

	// Calc N and k.
	An, Ak := 0, 0
	for i := 0; i < N; i++ {
		if vs[i] == vs[A-1] {
			An++
			if i < A {
				Ak++
			}
		}
	}

	cnt := 0
	if Ak == A {
		for ; Ak <= B; Ak++ {
			if Ak >= len(dp[An]) {
				break
			}

			cnt += dp[An][Ak]
		}
	} else {
		cnt = dp[An][Ak]
	}

	fmt.Printf("%f\n%d\n", avg, cnt)
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func min(x, y int) int {
	if x < y {
		return x
	}

	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}

	return y
}

func abs(x int) int {
	return int(math.Abs(float64(x)))
}

// ---------- Util.


Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

int n,k[111];
string s;

int dec(char c){
	if(islower(c))return c-'a';
	return c-'A'+26;
}

char code(int x){
	if(x<26)return 'a'+x;
	return 'A'+x-26;
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	while(cin>>n && n){
		rep(i,n)cin>>k[i];
		cin>>s;
		rep(i,sz(s)){
			int d=dec(s[i]);
			d=(d-k[i%n]+52)%52;
			cout<<code(d);
		}
		cout<<endl;
	}
}

Measured memory_bytes: 1204
using System;

public class Program
{
    /// <summary>
    /// プログラムエントリポイント
    /// </summary>
    public static void Main()
    {
        //サイコロの目を入力
        string[] aryStrDice = Console.ReadLine().Split(' ');

        //EWSN(東西南北)の命令を入力
        char[] aryCharOperation = Console.ReadLine().ToCharArray();

        //Diceクラスインスタンス生成　引数はサイコロの目
        Dice insDice = new Dice(aryStrDice, aryCharOperation);

        //戻り値を出力
        Console.WriteLine(insDice.doComand());

    }
}

/// <summary>
/// Diceクラス
/// </summary>
class Dice
{

    private int[] aryIntDice;
    private char[] aryCharOperation;

    /// <summary>
    /// コンストラクタ
    /// </summary>
    /// <param name="aryStrDice">サイコロの目</param>
    public Dice(string[] aryStrDice, char[] aryCharOperation)
    {

        aryIntDice = new int[aryStrDice.Length];

        //引数 string[] aryDice を int[] に置き換える
        for (int i = 0; i < aryStrDice.Length; i++)
        {
            this.aryIntDice[i] = int.Parse(aryStrDice[i]);
        }

        //引数 char[] aryCharOperation を Diceクラスの
        //aryCharOperationに置き換える
        this.aryCharOperation = aryCharOperation;

    }

    /// <summary>
    /// サイコロに対して方向の命令を実行する
    /// </summary>
    public int doComand()
    {

        foreach (char c in this.aryCharOperation)
        {
        //命令ごとに動き方を分ける
            switch ( c )
            {
                case 'E' :
                    runOperationE();
                    break;

                case 'N' :
                    runOperationN();
                    break;

                case 'S' :
                    runOperationS();
                    break;

                case 'W' :
                    runOperationW();
                    break;
            }
        }

        return this.aryIntDice[0];

    }

    /// <summary>
    /// サイコロを命令に従って動かす E方向
    /// </summary>
    private void runOperationE()
    {
        int tmpStorage = aryIntDice[0];
        aryIntDice[0] = aryIntDice[3];
        aryIntDice[3] = aryIntDice[5];
        aryIntDice[5] = aryIntDice[2];
        aryIntDice[2] = tmpStorage;
    }
    /// <summary>
    /// サイコロを命令に従って動かす N方向
    /// </summary>
    private void runOperationN()
    {
        int tmpStorage = aryIntDice[0];
        aryIntDice[0] = aryIntDice[1];
        aryIntDice[1] = aryIntDice[5];
        aryIntDice[5] = aryIntDice[4];
        aryIntDice[4] = tmpStorage;
    }
    /// <summary>
    /// サイコロを命令に従って動かす S方向
    /// </summary>
    private void runOperationS()
    {
        int tmpStorage = aryIntDice[0];
        aryIntDice[0] = aryIntDice[4];
        aryIntDice[4] = aryIntDice[5];
        aryIntDice[5] = aryIntDice[1];
        aryIntDice[1] = tmpStorage;
    }
    /// <summary>
    /// サイコロを命令に従って動かす W方向
    /// </summary>
    private void runOperationW()
    {
        int tmpStorage = aryIntDice[0];
        aryIntDice[0] = aryIntDice[2];
        aryIntDice[2] = aryIntDice[5];
        aryIntDice[5] = aryIntDice[3];
        aryIntDice[3] = tmpStorage;
    }

}

Measured memory_bytes: 9248
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,M = map(int, readline().split())

    if N % 2 == 1:
        for i in range(M):
            print(i + 1, N - i)
    else:
        for i in range(M):
            if i < M / 2:
                print(i + 1, N - i)
            else:
                print(i + 2, N - i)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9168