akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(b<a) { a=b; return 1; } return 0; }

int main(){
  int n; cin >> n;
  map<int,int> mp;
  rep(i,n){
    int a; cin >> a;
    mp[a]++;
  }
  int ans = 0;
  for(auto x : mp){
    if(x.first <= x.second) ans += x.second-x.first;
    else ans += x.second;
  }
  cout << ans;
  cout << "\n";
  return 0;
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
    int a, b;
    cin >> a >> b;

    cout << ((13 <= a) ? b : (6 <= a) ? b / 2 : 0) << '\n';
    return 0;
}


Measured memory_bytes: 3624
n = int(input())
p = list(map(int, input().split(' ')))
p_sort = sorted(p)
counter = 0
for i in range(len(p)):
    if p[i] != p_sort[i]:
        counter += 1
    if counter > 2:
        break
if counter == 2 or counter == 0:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll n, A[200005] = {}, twofive[40][40] = {}, ans = 0, sum[40][40] = {};
lldo a;
pair<ll, ll> twofiveNum[200005] = {};

int main() {
	cin >> n;
	rep(i, n) {
		cin >> a;
		A[i] = a * 1e9 + 0.5;
		ll box1 = A[i], two = 0;
		while (box1 % 2 == 0) {
			box1 /= 2;
			two++;
		}
		ll box2 = A[i], five = 0;
		while (box2 % 5 == 0) {
			box2 /= 5;
			five++;
		}
		twofive[two][five]++;
		twofiveNum[i] = mp(two, five);
	}
	rep(i, 39) {
		rep(j, 39) sum[40 - i - 2][40 - j - 2] = sum[40 - i - 1][40 - j - 2] + sum[40 - i - 2][40 - j - 1] - sum[40 - i - 1][40 - j - 1] + twofive[40 - i - 2][40 - j - 2];
	}
	rep(i, n) {
		ans += sum[max((ll)0, 18 - twofiveNum[i].first)][max((ll)0, 18 - twofiveNum[i].second)];
		if (twofiveNum[i].first >= 9 && twofiveNum[i].second >= 9)ans--;
	}
	cout << ans / 2 << endl;
	return 0;
}

Measured memory_bytes: 8420
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

int main()
{
    int A, B;
    cin >> A >> B;
    vector<int> f(3, 1);
    f[A-1] = 0;
    f[B-1] = 0;
    for(int i=0; i<3; i++){
        if(f[i] == 1) cout << i+1 << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
		int n,t,i,k,j,g,s,r,a;
	while(1)	{
		scanf("%d",&t);
		if(t==0)	break;
		scanf("%d",&n);
		g=0;
		for(i=0;i<n;i++){
			scanf("%d %d",&a,&s);
			k=s-a;
			g+=k;
		}
		if(g>=t){
			printf("OK\n");
		}
		if(g<t){
			r=t-g;
			printf("%d\n",r);
		}
		k=0;	
	}	
	return 0;
}

Measured memory_bytes: 1040
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  ll A,B,K;
  cin >> A >> B >> K;
  if(A>=K) {
    cout << A-K << " " << B << endl;
  } else {
    ll d = K-A;
    cout << 0 << " " << max(0ll,B-d) << endl;
  }
  return 0;
}

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

int main(void){
    int n;
    cin >> n;
    
    int max = -1, p, sum = 0;
    for(int i = 0; i < n; i ++){
        cin >> p;
        if(max < p) max = p;
        sum += p;
    }
    
    cout << sum - max/2 << "\n";
}


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

int main(){
  int N;
  cin >>N;
  vector<pair<int,int>>vec(N);

  for (int i=0;i<N;i++){
    cin>>vec[i].second>>vec[i].first;//逆順で入力
  }
  sort(vec.begin(),vec.end());
  int now=0;
  for (int i=0;i<N;i++){
    now=now+vec[i].second;
    if(now>vec[i].first){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 1792
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A&lang=jp

class Dijkstra():
    """ ダイクストラ法
    重み付きグラフにおける単一始点最短路アルゴリズム

    * 使用条件
        - 負のコストがないこと
        - 有向グラフ、無向グラフともにOK
    
    * 計算量はO(E*log(V))

    * ベルマンフォード法より高速なので、負のコストがないならばこちらを使うとよい
    """
    class Edge():
        """ 重み付き有向辺 """
        def __init__(self, _to, _cost):
            self.to = _to
            self.cost = _cost

    def __init__(self, V):
        """ 重み付き有向辺
        無向辺を表現したいときは、_fromと_toを逆にした有向辺を加えればよい

        Args:
            V(int): 頂点の数
        """
        self.G = [[] for i in range(V)]  # 隣接リストG[u][i] := 頂点uのi個目の隣接辺
        self._E = 0  # 辺の数
        self._V = V  # 頂点の数

    @property
    def E(self):
        """ 辺数
        無向グラフのときは、辺数は有向グラフの倍になる
        """
        return self._E
    
    @property
    def V(self):
        """ 頂点数 """
        return self._V
    
    def add(self, _from, _to, _cost):
        """ 2頂点と、辺のコストを追加する """
        self.G[_from].append(self.Edge(_to, _cost))
        self._E += 1
        
    def shortest_path(self, s):
        """ 始点sから頂点iまでの最短路を格納したリストを返す 
        Args:
            s(int): 始点s
        Returns:
            d(list): d[i] := 始点sから頂点iまでの最短路
        """
        import heapq
        que = []  # プライオリティキュー（ヒープ木）
        d = [float("inf")] * self.V
        d[s] = 0
        heapq.heappush(que, (0, s))  # (最短距離, 頂点の番号)をヒープに追加する

        while len(que) != 0:
            prov_cost, v = heapq.heappop(que)  # prov_cost := 暫定的な最短距離
            # キューに格納されている暫定的な最短距離が、現在計算できている最短距離より大きければ、dの更新をする必要はない
            if d[v] < prov_cost: continue

            # 他の頂点の探索
            for i in range(len(self.G[v])):
                """(1)遅い
                try:
                    self.edges[(v,i)]
                except KeyError:
                    continue
                """
                """ vからiへのコストは全探索せずに、存在するもののみ探したい """
                e = self.G[v][i]  # vのi個目の隣接辺e
                if d[e.to] > d[v] + e.cost:
                    d[e.to] = d[v] + e.cost # dの更新
                    heapq.heappush(que, (d[e.to], e.to)) # キューに新たな仮の距離の情報をpush
        return d

if __name__ == "__main__":
    V, E, s = list(map(int, input().split()))
    v_set = set()  # 頂点の集合
    djk = Dijkstra(V)
    if V == 1:
        print(0)
        exit()
        
    if E == 0:
        for i in range(V-1):
            djk.add(i, i+1, float("INF"))
    else:
        for i in range(E):
            _from, to, cost = list(map(int, input().split()))
            djk.add(_from, to, cost)
            v_set.add(_from)
            v_set.add(to)

        for i in range(V):
            # 入力に存在しない頂点があるとき、適当にINFの辺を作成する
            if not i in v_set:
                djk.add(i, 0, float("inf"))

    d = djk.shortest_path(s)
    
    for i in range(V):
        if i >= len(d):
            print("INF")
            continue

        cost = d[i]
        if cost == float("inf"):
            print("INF")
        else:
            print(cost)



Measured memory_bytes: 144916
n, k = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]

j = 0
for i in range(k):
    j += p[i]
ma = j

for i in range(k, n):
    j = j - p[i - k] + p[i]
    ma = max(ma, j)
print((ma+k)/2)

Measured memory_bytes: 71792
N = int(raw_input())
a = map(int,raw_input().split())
con = 1
ans = 0
for i in range(0,N):
  if a[i] == con:
    con = con + 1
    continue
  else:
    ans = ans + 1
if ans == N:
  print -1
else:
  print ans

Measured memory_bytes: 20008
import sys
C=[]
A=[0]*3
B=[0]*3
for i in range(3):
    C.append(list(map(int,input().split())))
for i in range(3):
    A[i]=min(C[i])
#print(C)
for i in range(3):
    B[i]=C[0][i]-A[0]
#print(A)
#print(B)
for i in range(3):
    for j in range(1,3):
        if B[i]+A[j]!=C[j][i]:
            print('No')
            sys.exit()
print('Yes')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n>>k;
    cin>>S;

    cnt = 1;

    for(int i=1;i<n;i++)
        if(S[i]!=S[i-1])cnt++;

    int ans = max(1,cnt-2*k);

    cout<<n-ans<<"\n";

    return 0;
}


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

int main(void)
{
  long long H, W, N;
  cin >> H >> W >> N;
  unordered_map<long long, int> m;
  long long Y, X;
  string l;
  for(int i=0; i<N; ++i)
  {
    cin >> Y >> X;
    for(long long j=-1; j<=1; ++j)
    for(long long k=-1; k<=1; ++k)
    {
      if(Y + j < 2 || X + k < 2 || H - 1 < Y + j || W - 1 < X + k) continue;
      ++m[(Y + j) | ((X + k) << 32)];
    }
  }

  cout << l;

  vector<long long> v;
  v.assign(10, 0);
  long long j = 0;
  for(auto elm : m)
  {
    ++v[elm.second];
    ++j;
  }
  v[0] = (H - 2) * (W - 2) - j;

  for(auto elm : v)
  {
    cout << elm << endl;
  }
  return 0;
}


Measured memory_bytes: 36624
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	n*=2;
	vector<int> arr;
	for(int i =0;i<n;i++)
	{
		int a;
		cin>>a;
		arr.push_back(a);
	}
	sort(arr.begin(),arr.end());
	int cnt = 0;
	for(int i =0; i < arr.size();i+=2)
		cnt += min(arr[i],arr[i+1]);
	
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
	string A;
	cin >> A;
	int n = A.size();
    ll ans = 1;
	vector<int> c(256,0);
	rep(i,n) {
		ans += i - c[A[i]];
		c[A[i]]++;
	}
	cout << ans << endl;
	return 0;
}


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

namespace ABC
{
    class ProgramB
    {
        static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split(" ");
            var a = long.Parse(inputs[0]);
            var b = long.Parse(inputs[1]);
            var c = long.Parse(inputs[2]);
            var d = long.Parse(inputs[3]);
            var list = new List<long>();
            list.Add(a * c);
            list.Add(a * d);
            list.Add(b * c);
            list.Add(b * d);
            Console.WriteLine(list.Max());
        }
    }
}


Measured memory_bytes: 28292
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
static const int fast_io = [](){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);return 0;}();
static const int precise_doubles = [](){cout<<fixed<<setprecision(20);return 0;}();
typedef pair<int, int> PII;
typedef tree<PII, null_type, less<PII>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order(k) - iterator to k'th element (0-based), order_of_key(k) - #things < k
typedef long double LD;
typedef long long LL;
#define EVAL(x) x
#define NEWL EVAL({cout << '\n';})
#define SPA(x) EVAL({cout << #x" = " << x << ' ';})
#define SPAR(a, b) EVAL({cout<<#a" = ";for(auto it=a;it!=b;)cout<<*(it++)<<" ";cout<<'\n';})
#define SPAV(v) EVAL({cout<<#v" = ";for(auto it=v.begin();it!=v.end();)cout<<*(it++)<<" ";cout<<'\n';})
const int INF = 0x3f3f3f3f; // 1.0e9
const LL LINF = 0x3f3f3f3f3f3f3f3fll; // 4.5e18
const LD eps = 1e-20;
const int mod = 1e9 + 7;
inline int msum(int x, int y) {return (x+y<mod ? x+y : x+y-mod);}
inline int mdif(int x, int y) {return (x>=y ? x-y : x-y+mod);}
inline int mprod(int x, int y) { return (1ll*x*y) % mod; }
inline int mpow(int x, LL y) {LL r=1;while(y){if(y&1)r=mprod(r,x);x=mprod(x,x);y>>=1;}return r;}
inline int minv(int x) { return mpow(x, mod-2); }
//------------------------------------------------------------------------------------------------------

const int N = 20;

int n;
int s[1<<N];

void die() {
    cout << "No\n";
    exit(0);
}

int main() {
    cin >> n;
    REP(i, 1<<n) cin >> s[i];
    sort(s, s+(1<<n));
    reverse(s, s+(1<<n));
    multiset<int, greater<int>> S;
    S.insert((1<<(n+1))-1);
    for (int i = 0; i < (1<<n); i++) {
        int j = i;
        while(j+1 < (1<<n) and s[j+1] == s[i]) j++;

        int l = j - i + 1;
        if ((int)S.size() < l) die();
        vector<int> remove;
        while(l--) {
            remove.push_back(*S.begin());
            S.erase(S.begin());
        }
        for (int x : remove) {
            for (int y = (x+1)/2; y >= 2; y /= 2) {
                S.insert(y-1);
            }
        }

        i = j;
    }
    cout << "Yes\n";
}





























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

class PaizaSample
{

    static void Main()
    {

        string input;
        bool first = true;
        while ((input = Console.ReadLine()) != null)
        {
            if (!first)
            {
                Console.WriteLine();
            }
            else
            {
                first = false;
            }

            int length = input.Length;
            for (int i = 0; i < 5 - length; i++)
            {
                input = "0" + input;
            }

            List<string> list = new List<string>();
            for (int i = 0; i < 5; i++)
            {
                string temp = "";
                int n = int.Parse(input[i].ToString());

                temp += n >= 5 ? " *" : "* ";

                temp += "=";

                for (int j = 0; j < 5; j++)
                {
                    temp += n % 5 == j ? " " : "*";
                }

                list.Add(temp);
            }

            for (int i = 0; i < list[0].Length; i++)
            {
                for (int j = 0; j < list.Count; j++)
                {
                    Console.Write(list[j][i]);
                }
                Console.WriteLine();
            }


        }


        // Console.ReadKey();

    }
}

Measured memory_bytes: 9016
N = int(input())
sin_list = list(map(int, input().split()))
max_height = 0
total_additional_height = 0

for sin in sin_list:
  if max_height == 0:
    max_height = sin
  else:
    if sin >= max_height:
      max_height = sin
    else:
      total_additional_height += (max_height - sin)

print(total_additional_height)


Measured memory_bytes: 32224
package main

import (
    "fmt"
)

func main() {
    var n, count int
    fmt.Scan(&n)
    var a = make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Scan(&a[i])
    }
LOOP:
    for {
        for i := 0; i < n; i++ {
            if a[i]%2 == 0 {
                a[i] /= 2
            } else {
                break LOOP
            }
        }
        count++
    }
    fmt.Println(count)
}

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

int main() {
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a, a+n);
    lli ans = 0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            int p = a[i] + a[j];
            int l=j+1,r=n-1,val=-1,mid;
            while(l<=r){
                mid = (l+r)/2;
                if(a[mid] >= p){
                    r = mid - 1;
                }else{
                    val = mid;
                    l = mid + 1;
                }
            }
            if(val != -1){
                ans += (val-j);
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}


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

int main() {
  int a,b;
  cin>>a>>b;
  cout << 6-a-b <<endl;
}

Measured memory_bytes: 256
S = input()
N = len(S)
K = int(input())
cnt = {i: [] for i in range(N)}
for i in range(N):
    for j in range(N - i):
        s = S[j:j+i+1]
        l = len(s)
        if s not in cnt[l-1]:
            cnt[l-1].append(s)
    if i > K:
        break
ttl = []
for k, v in cnt.items():
    ttl.extend(v)
ttl.sort()
print(ttl[K-1])

Measured memory_bytes: 5564
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//ここまでテンプレ
int main(){
	int A,B,C,D;
	cin>>A>>B>>C>>D;
	if(A+B>C+D)
		cout<<"Left"<<endl;
	else if(A+B==C+D)
		cout<<"Balanced"<<endl;
	else
		cout<<"Right"<<endl;
	return 0;
}

Measured memory_bytes: 256
N,W = gets.split.map(&:to_i)
value = Array.new(N)
weight = Array.new(N)

N.times {|i| value[i], weight[i] = gets.split.map(&:to_i) } 

dp = Array.new(N+1) {Array.new(W+1){0}}

(0...N).each do |i|
  (0..W).each do |w|
    if w >= weight[i]
      dp[i+1][w] = [dp[i+1][w-weight[i]] + value[i], dp[i][w]].max
    else
      # w よりも weight[i] が大きいとき、品物iが選ばれていることはありえない
      dp[i+1][w] = dp[i][w]
    end
  end
end

puts dp[N][W]




Measured memory_bytes: 14760
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int k, s, cnt;
    int z;
    cnt = 0;
    cin >> k >> s;
    
    for (int x = 0; x <= k; ++x)
    {
        for (int y = 0; y <= k; ++y)
        {
            z = s - x - y;
            if (z >= 0 && z <= k) ++cnt;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int INF = 1000000007;
const int MOD = (int)1e9+7;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
int dy[4] = {-2, -1};
int dx[4] = {-1, -2};

int n, k;
string s;

int main(void) {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//freopen("in.txt", "r", stdin);
	cin >> n >> k;
	cin >> s;

	int ret = 0;
	rep(i,0,sz(s)-1) {
		if(s[i] == s[i+1]) {
			ret++;
		}
	}

	s.erase(unique(all(s)), s.end());
	int a = s.size()/2;
	a = min(a, k);
	if(2*a == s.size()) {
		ret += 2*a-1;
	} else {
		ret += 2*a;
	}
	
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int n = s.size();
	int ans = 0;
	rep(i,n/2){
		if(s[i] != s[n-1-i]) ++ans;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int n,i,a[100],v,j,k,s,x;//n????????°


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

	for (k = 0; k < n; k++){
		if(k>=1) printf(" ");
		printf("%d", a[k]);
	}
	printf("\n");
	for (s = 1; s< n; s++){
		v = a[s];
		j=s-1;
		while(j>=0 && a[j]>v){
			a[j+1]=a[j];
			j--;
		}
		a[j+1]=v;
		for(x=0; x<n; x++){
			if(x>=1) printf(" ");
			printf("%d", a[x]);
		}
		printf("\n");

	}
}

Measured memory_bytes: 1812
#ABC100 B
#よい整数とは,100でちょうどD回割り切れる自然数をいう
#与えられたDに対し,N番目に小さいよい整数を求めよ
#
#D=0のときはよい整数は1,...,99,101
#D=1のときは100,200,...,9800,9900,10100
#D=2のときは10000,20000,...,990000,1010000

D,N = map(int,input().split(' '))

if N == 100:
	print(101*(100**D))
else:
	print(N*(100**D))

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> fibo(n+2);
  fibo[0]=1;
  fibo[1]=1;
  for(int i=2;i<n+2;i++){
    fibo[i]=fibo[i-1]+fibo[i-2];
  }
  
  cout << fibo[n] << endl;
  return 0;
}

Measured memory_bytes: 3076
# include <iostream>
using namespace std;
const int N=55556,M=56;
int a[N],b[N],c[M];
int n,l;
void work (void)
{
	int i,j;
	i=1;
	j=1;
	while (i<=n)
	{
		if (b[j]%5==1)
		{
			c[i]=b[j];
			i++;
		}
		j++;
	}
	for (i=1;i<=n;i++)
	cout<<c[i]<<" ";
}
int main (void)
{
	int i,j,t;
	l=1;
	cin>>n;
	for (i=2;i<=55555;i++)
	{
		j=1;
		if (a[i]==0)
		{
			b[l]=i;
			l++;
		}
		for (j=1;j<l;j++)
		{
			t=i*b[j];
			if (t<=55555)
			a[t]=1;
	   else break;
	        if (i%b[j]==0)
	        break;
		}
	}
	work ();
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int maxn = 2e5 + 10;
int main()
{
    int S, W;
    scanf("%d %d", &S, &W);
    if(W >= S)
        printf("unsafe");
    else
        printf("safe");
    return 0;
}


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

int main() {

    string S, T;
    cin >> S >> T;

    int cnt = 0;

    if (S[0] == T[0]) cnt++;
    if (S[1] == T[1]) cnt++;
    if (S[2] == T[2]) cnt++;

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
MOD = 10**9 + 7
N = int(input())
*A, = map(int, input().split())
hats = [0] * 3
ans = 1
for a in A:
    ans = (ans * hats.count(a)) % MOD
    for i in range(3):
        if hats[i] == a:
            hats[i] += 1
            break
print(ans)

Measured memory_bytes: 13964
d=int(input())
c=list(map(int,input().split()))
s=[]
for i in range(d):
  s.append(list(map(int,input().split())))

ans=[]
l=[-1 for i in range(26)]
for i in range(d):
  ms=-10**9
  mt=None
  for j in range(26):
    js=c[j]*(i-l[j])+s[i][j]
    if ms<js:
      ms=js
      mt=j
  l[mt]=i
  ans.append(mt)

for i in ans:
  print(i+1)

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

int main ()
{
   int A, B;
   cin >> A;
   cin >> B;
   int c ;
   c = A+B;
   if (c >= 10)
   {
       cout << "error" << endl;
   }
   else
   {
       cout << c << endl;
   }
   return 0;
}


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

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()

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

    //色が違うところを数え上げる
    int ans = 0;
    char c = s[0];
    for(int i = 1; i < s.size(); i++){
        char tmp = s[i];
        if(tmp != c){
            ans++;
            c = tmp;
        }
    }

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

Measured memory_bytes: 512
#include <iostream>
using namespace std;
 
int K;
int l[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
 
int main(){
  
  cin >> K;
  cout << l[K - 1] << endl;
  
  return 0;
}

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

int D;
double V[16];
double interpolate(int n,int E){
    double sum=0.0;
    for(int k=0;k<3+D;k++){
        if(k==n||k==E)continue;
        double p=V[k];
        for(int i=0;i<D+3;++i)
        {
            if(!(i==k||i==n||i==E))
                p*=(n-i)/(double)(k-i);//care here
        }
        sum+=p;
    }
    return sum;
}

bool outlier(int E) {
    for (int i=0; i<D+3; ++i) {
            if (i==E) continue;
            double p = interpolate(i, E);
            if(abs(p-V[i])>0.1)
                return false;
    }
    return true;
}

int main()
{
    while(cin>>D&&D){
        for(int i=0;i<D+3;i++)cin>>V[i];
        for(int i=0;i<D+3;i++){
        if(outlier(i)){
            cout<<i<<endl;
            break;
        }
        }
    }
}

Measured memory_bytes: 3148
/**
*
* Author: Mouhanad
* Lang: GNU C++14
*
**/
#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define ii pair < int , int >
#define LS pair < ll , string >
typedef long long ll;
const int inf = 1<<30;
const int N =100100;
int n , a[N] , q ;

int main ( ){
 int x , y ;
cin >> n >> x >> y ;
if ( (abs(x-y)-1)  &1 ) puts("Alice");
else puts("Borys");
return 0 ;
}


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

int main(){
    int n,k,q;
    cin >> n >> k >> q;
    int count[n];
    rep(i,n) count[i] = 0;
    int a[q];
    rep(j,q){
	cin >> a[j];
	count[a[j]-1] += 1;
    }

    int accumulate[n+1];
    rep(l,n+1) accumulate[l] = 0;
    REP(m,1,n+1) accumulate[m] = accumulate[m-1] + count[m-1];

    int s = 0;
    REP(p,1,n+1){
	s = accumulate[n] - accumulate[p] + accumulate[p-1];
	if (k <= s){
	    cout << "No" << endl;
	}else{
	    cout << "Yes" << endl;
	}
    }
    
    return 0;
}

Measured memory_bytes: 1792
Module _20190425

    Sub Main()

        Dim sRead As String = Console.ReadLine()
        Dim iACityCount As Integer = sRead.Split(" ")(0)
        Dim iBCityCount As Integer = sRead.Split(" ")(1)
        Dim iX As Integer = sRead.Split(" ")(2)
        Dim iY As Integer = sRead.Split(" ")(3)

        Dim iAMax As Integer = -100
        Dim sAList() As String = Console.ReadLine().Split

        For i As Integer = 0 To iACityCount - 1

            If sAList(i) > iAMax Then

                iAMax = sAList(i)

            End If

        Next

        If iX > iAMax Then

            iAMax = iX

        End If

        Dim iBMin As Integer = 100
        Dim sBList() As String = Console.ReadLine().Split

        For j As Integer = 0 To iBCityCount - 1

            If sBList(j) < iBMin Then

                iBMin = sBList(j)

            End If

        Next

        If iY < iBMin Then

            iBMin = iY

        End If

        If iBMin > iAMax Then

            Console.WriteLine("No War")

        Else

            Console.WriteLine("War")

        End If

    End Sub

End Module

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

#define rep(i, s, n) for (int i = s; i < n; ++i)
#define rrep(i, n) for (int i = n - 1; i > -1; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const long long INF = 1000000000;
typedef long long ll;
typedef pair<int, int> P;

void func(long long N, std::vector<long long> s) {
    ll sum = 0;
    sort(rall(s));
    ll m = INF;
    rep(i, 0, N) {
        sum += s[i];
        if (s[i] % 10 != 0) {
            m = s[i];
        }
    }
    if (sum % 10 != 0)
        cout << sum << endl;
    else {
        if (m == INF) {
            cout << 0 << endl;
        } else {
            cout << sum - m << endl;
        }
    }
}

int main() {
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld", &N);
    std::vector<long long> s(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &s[i]);
    }
    func(N, std::move(s));
    return 0;
}


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

using namespace std;

int main()
{
  vector<int> cnt(5);
  for (int i = 0; i < 6; i++)
  {
    int t;
    cin >> t;
    cnt[t]++;
  }
  if (cnt[1] < 3 && cnt[2] < 3 && cnt[3] < 3 && cnt[4] < 3)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	
	int n,k;
	cin>>n>>k;
	vector<int>a(n);
	for(int &x:a){
		scanf("%d",&x);
	}
	vector<bool>dp(k+1);
	for(int stones=0;stones<=k;stones++){
		for(int x:a){
			if(stones>=x && !dp[stones-x]){
				dp[stones]=true;
			}
		}
		
	}
	puts(dp[k] ? "First" : "Second");
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int A,B;
    cin >> A >> B;
    if(A == 1){ A = 14;
    }
    if(B == 1){ B = 14;
    }
    if(A > B){
     cout << "Alice" << endl;
    }
    if(B > A){
     cout << "Bob" << endl;
    }
    else if(A==B){
     cout << "Draw" << endl;
    }
}

Measured memory_bytes: 256
h, w = [int(x) for x in input().split()]
matrix = [list(input()) for _ in range(h)]
surroundings = ((-1, 0), (1, 0), (0, -1), (0, 1))


def check_surroundings(i, j):
    for dis in surroundings:
        si = i + dis[0]
        sj = j + dis[1]
        if si < 0 or si >= h or sj < 0 or sj >= w:
            continue
        if matrix[si][sj] == '#':
            break
    else:
        yield True  # Can't paint.


for i in range(h):
    for j in range(w):
        if matrix[i][j] == '#':
            if sum(check_surroundings(i, j)):
                break
            else:
                continue
    else:
        continue

    print('No')
    break

else:
    print('Yes')


# 問題の意味を理解できていなかった。空中分解した黒マスがあるかどうかの判定。
# 隣のマスが無いか白か。


Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#define INF 1000000007
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
int n;
int c[500];
int s[500];
int f[500];
int time (int p,int t){
    if(p==n-1){
        return t;
    }else{
        int k;
        if(t<s[p])k=s[p];
        else k=(t+f[p]-1)/f[p]*f[p];
        return time(p+1,k+c[p]);
    }
}
signed main(){
    cin>>n;
    for(int i=0;i<n-1;i++)cin>>c[i]>>s[i]>>f[i];
    for(int i=0;i<n;i++){
        cout<<time(i,0)<<endl;
    }
    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <math.h>
using namespace std;

int main () {
  int N,M;
  cin >> N;
  if (N < 1000 || N > 9999) {
    cout << "wrong entry\n";
    return 0;
  }
  int a[4];
  for (int i = 3; i >= 0; i--) {
    a[i] = N / (int) pow(10,i);
    N -= a[i] * (int) pow(10,i);
  }
  if ( (a[1] == a[2]) && (a[0] == a[1] || a[3] == a[2])) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
ans=set()
b=set(range(1,m+1))
#print(b)
ans=ans.union(b)
for n in range(n):
  #print(ans)
  s=list(map(int,input().split()))
  ex=b - set(s[1:])
  ans=ans-ex
print(len(ans))



Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define pb push_back

bitset<10000> bs;
vector<int> V;
int N;

int main(){
  bs.set();
  bs[0] = bs[1] = 0;
  for (int i=2;i<1500;++i){
    if (bs[i] == 0)continue;
    if (i%5 == 1)V.pb(i);
    for (int j=i*i; j < 10000; j += i)bs[j] = 0;
  }
  cin>>N;
  for (int i=0;i<N;++i)cout<<V[i]<<' ';  
}

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

using namespace std;

int num[20];
int res[100000];

int main(){

    int n,m,temp;
    cin >> n >> m;
    for(int i=0;i<m;i++){
	cin >> temp;
	num[i] = temp;
	res[temp] = 1;
    }
    bool flag=true;
    while(flag){
	for(int i=0;i<n;i++){
	    for(int j=0;j<m;j++){
		if(res[i] > 0 ){
		    if(res[i+num[j]] == 0) res[i+num[j]] = res[i]+1;
		    else{res[i+num[j]] = min(res[i+num[j]],res[i]+1);
			if(i+num[j] == n) flag = false;
		    }
		}
	    }
	}
    }
    
    cout << res[n]<< endl;

    return 0;
}

Measured memory_bytes: 1396
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int rem=n;
        int hap=0;
        int ans=0;
        if (n>=500){
            hap=n/500;
            ans=hap*1000;
            n=n-((n/500)*500);
        }
        if (n>=5){
            hap=n/5;
            ans=ans+hap*5;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23252
n = input()
a = list(map(int,input().split()))
b = set(a)
if 0 in b:
    print(0)
else:
    cnt = 1
    for i in a:
        cnt *= i
        if cnt > 10 ** 18:
            break
    if cnt > 10**18:
        print(-1)
    else:
        print(cnt)

Measured memory_bytes: 21632
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, c, b[100], a[100];
    cin >> n >> m >> c;
    for (int i = 0; i < m; ++i)
        cin >> b[i];

    int sol = 0;
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < m; ++j)
            cin >> a[j];

        int sum = c;
        for (int j = 0; j < m; ++j)
            sum += a[j] * b[j];
        if (sum > 0)
            sol++;
    }
    cout << sol;
}


Measured memory_bytes: 256
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Contest.D
{
	class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			Scanner cin = new Scanner();

			int n = cin.nextInt();
			var l = cin.ArrayInt(n);
			Array.Sort(l);
			long ans = 0;
			for (int i = 0; i < n; i++)
			{
				for (int j = i + 1; j < n; j++)
				{
					int min = l[j] - l[i];
					int max = l[j] + l[i];
					int le = UpperBound(l, min);
					int ri = LowerBound(l, max) - 1;
					ans += Math.Max(Math.Min(ri - le + 1, ri - j), 0);
				}
			}
			Console.WriteLine(ans);

			Console.Out.Flush();
		}

		public static int UpperBound<T>(T[] a, T v) where T : IComparable
		{
			var l = 0;
			var r = a.Length - 1;
			while (l <= r)
			{
				var mid = l + (r - l) / 2;
				var res = a[mid].CompareTo(v);
				if (res <= 0) l = mid + 1;
				else r = mid - 1;
			}
			return l;
		}

		public static int LowerBound<T>(T[] a, T v) where T : IComparable
		{
			var l = 0;
			var r = a.Length - 1;
			while (l <= r)
			{
				var mid = l + (r - l) / 2;
				var res = a[mid].CompareTo(v);
				if (res == -1) l = mid + 1;
				else r = mid - 1;
			}
			return l;
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return next();
			i = 0;
			return s[i++];
		}

		public int nextInt()
		{
			return int.Parse(next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = nextInt() + add;
			}
			return Array;
		}

		public long nextLong()
		{
			return long.Parse(next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = nextLong() + add;
			}
			return Array;
		}

		public double nextDouble()
		{
			return double.Parse(next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = nextDouble() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 19464
import math
n,m=map(int,input().split())
arr=[None]*n
flag=True
ar=[]
for i in range(m):
	s,c=map(int,input().split())
	ar.append([s,c])
if m==0 and n==1:
	print(0)
	exit()
for  i in range(len(ar)):
	s=ar[i][0]
	c=ar[i][1]
	s-=1
	if s==0 and c==0 and n!=1:
		flag=False
		break
	if arr[s]==None:
		arr[s]=c 
	else:
		if arr[s]!=c:
			flag=False
			break
		else:
			continue 
if not flag:
	print(-1)
	exit()
# if arr[0]==0 and n!=1:
# 	print(-1)
# 	exit()
if arr[0]==None:
	arr[0]=1
if flag:
	for i in arr:
		if i==None:
			print(0,end="")
		else:
			print(i,end="")
	print()
else:
	print(-1)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    static Collection<Integer> generateModulusArray(String word) {
        HashMap<Integer, Integer> seen = new HashMap<>();
        seen.put(0, 1);
        int prevMod = 0;
        int tensMod = 1;
        for (int i = word.length()-1; i >= 0; i--) {
            prevMod = (tensMod * (word.charAt(i) - '0') + prevMod) % 2019;
            seen.merge(prevMod, 1, Integer::sum);
            tensMod = (tensMod * 10) % 2019;
        }
        return seen.values();
    }

    public static void main(String[] args) {
        int result = 0;
        Scanner sc = new Scanner(System.in);
        String word = sc.next();
        Collection<Integer> reps = generateModulusArray(word);
        for (Integer r: reps) result += (r * (r - 1))/2;
        System.out.println(result);
    }
}


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

int main(){
    ios::sync_with_stdio(false);
	ll sum=1,mod=1000000007,A=0,AB=0,ABC=0;
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++){
		if(s[i]=='A') A+=sum;
		if(s[i]=='B') AB+=A;
		if(s[i]=='C') ABC+=AB;
		if(s[i]=='?'){
			ABC=ABC*3+AB;
			AB=AB*3+A;
			A=A*3+sum;
			sum*=3;
		}
		A%=mod;
		AB%=mod;
		ABC%=mod;
		sum%=mod;
	}
	cout<<ABC;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include<numeric>
using namespace std;
using P = pair<int, int>;
#define rep(i,n) for(int i=0; i<(n);i++)
typedef long long ll;

const int M = 1000005;

int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> cnt(M);
    sort(a.begin(), a.end());
    for(int x : a){
        if(cnt[x] != 0){
            cnt[x] = 2;
            continue;
        }
        for(int i=x; i < M; i += x) cnt[i]++;
    }
    int ans = 0;
    for(int x : a){
        if(cnt[x] == 1) ans++;
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 7576
n = gets.chomp.to_i

a = []

n.times do
  a.push(gets.chomp)
end

h = a.tally
h.default = 0

puts "AC x #{h['AC']}"
puts "WA x #{h['WA']}"
puts "TLE x #{h['TLE']}"
puts "RE x #{h['RE']}"

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

int main(){
  int N, M; cin >> N >> M;
  int n = 1, m = 1;
  rep(i, N) n *= 2;
  rep(i, M) m *= 2;
  rep(i, n - 1) {
    rep(j, m - 1) {
      bitset<11> a(i + 1), b(j + 1);
      int k = 0;
      while (a[k] == 0 && b[k] == 0) k++;
      cout << !(a[k] ^ b[k]);
    }
    cout << endl;
  }
}

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

ll solve(ll h,ll w) {
  ll b1,b2,b3,res=1001001001;
  ll sum=h*w;
  for (int i=1; i<h; i++) {
    b1 = i*w;

    b2 = (h-i)*(w/2);
    b3 = sum-b2-b1;
    if (b2>0 && b3>0) res = min(res, max(b1,max(b2,b3)) - min(b1,min(b2,b3)));

    b2 = ((h-i)/2)*w;
    b3 = sum-b2-b1;
    if (b2>0 && b3>0) res = min(res, max(b1,max(b2,b3)) - min(b1,min(b2,b3)));
  }
  return res;
}

int main() {
  ll h,w; cin >> h >> w;
  ll ans = min(solve(h,w),solve(w,h));
  cout << ans << endl;
  return 0;
}

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

int main() {
  int N;
  int K;
  int a = 1;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    if (a < K)
      a += a;
    else
      a += K;
  }
  cout << a << endl;
}





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

int main()
{
	ios::sync_with_stdio(false);
	int n,h,i,j,maxi=-1,s=0;
	bool f=0;
	cin>>n>>h;
	int a[n+1],b[n+1];
	for (i=1;i<=n;i++) 
	{
		cin>>a[i]>>b[i];
		if (maxi<a[i]) maxi=a[i];
	}
	
	sort(b+1,b+n+1);
	i=n+1;
	while (i>1 && f==0)
	{
		i--;
		if (b[i]<=maxi) f=1;
		else  if (h<=0) f=1;
		else h-=b[i],s++;
	}
	
	while(h>0)
	{
		s++;
		h-=maxi;
	}
	
	cout<<s;
	return 0;
}

Measured memory_bytes: 1024
# A - Table Tennis Training
N,A,B = map(int, input().split())

if (B-A) % 2 == 0:
    ansA = int((B-A)//2)
else:
    ansA = 10**19

if N-B > A-1:
    ans1 = A-1
    ans2 = int(((B-1) - (A-1))//2)
    ansB = ans1+1+ans2

elif N-B < A-1:
    ans1 = N-B
    ans2 = int(((N-A) - (N-B))//2)
    ansB = ans1+1+ans2
else:
    ans1 = N - B
    ans2 = int(((N - A) - (N - B)) // 2)
    if (B-A) % 2 == 0:
        ansB = ans1 + ans2
    else:
        ansB = ans1 +1+ans2

ans = min(ansA,ansB)
print(ans)


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

namespace AOJ0519
{
    class Program
    {
        static void Main()
        {
            var teams = int.Parse(Console.ReadLine() ?? "");
            var nodes = Enumerable.Range(1, teams).Select(i => new Node(i)).ToArray();

            var count = int.Parse(Console.ReadLine() ?? "");
            for (var i = 0; i < count; i++)
            {
                var values = (Console.ReadLine() ?? "").Split(' ').Select(int.Parse).ToArray();
                Node.Connect(nodes[values[0] - 1], nodes[values[1] - 1]);
            }

            var noInputs = new Queue<Node>(from node in nodes
                                           where node.Inputs.Count == 0
                                           select node);

            var sorted = new List<Node>();

            var unique = true;
            while (noInputs.Any())
            {
                if (unique && noInputs.Count != 1) unique = false;
                var node = noInputs.Dequeue();
                sorted.Add(node);
                foreach (var next in new List<Node>(node.Outputs))
                {
                    Node.Disconnect(node, next);
                    if(next.Inputs.Count == 0) noInputs.Enqueue(next);
                }
            }

            foreach (var node in sorted)
            {
                Console.WriteLine(node.Value);
            }

            Console.WriteLine(unique ? 0 : 1);
        }
    }

    public class Node
    {
        public List<Node> Inputs { get; set; }
        public List<Node> Outputs { get; set; }
        public int Value { get; set; }

        public Node(int value)
        {
            Inputs = new List<Node>();
            Outputs = new List<Node>();
            Value = value;
        }

        public static void Connect(Node from, Node to)
        {
            from.Outputs.Add(to);
            to.Inputs.Add(from);
        }

        public static void Disconnect(Node from, Node to)
        {
            from.Outputs.Remove(to);
            to.Inputs.Remove(from);
        }
    }
}

Measured memory_bytes: 12320
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	ll a, b, c, d;
	char ch;
	ch = getchar();
	a = ch - '0';
	ch = getchar();
	b = ch - '0';
	ch = getchar();
	c = ch - '0';
	ch = getchar();
	d = ch - '0';
	for (ll i = 0; i < 2; i++) {
		for (ll j = 0; j < 2; j++) {
			for (ll k = 0; k < 2; k++) {
				ll x = a;
				if (i) x += b;
				else x -= b;
				if (j) x += c;
				else x -= c;
				if (k) x += d;
				else x -= d;
				if (x == 7) {
					cout << a;
					cout << (i ? "+" : "-") << b;
					cout << (j ? "+" : "-") << c;
					cout << (k ? "+" : "-") << d;
					cout << "=7" << endl;
					return 0;
				}
			}
		}
	}
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <functional>
#include <map>
#include <cmath>
#include <iostream>
 
 
using namespace std;
 
 
string S;
long long int K;
int R[100]={0};


int main()
{
	cin >> S;
	cin >> K;
	int lns = S.size();
	for(int i = 0; i < lns; i++){
		R[i] = int(S[i]) - 48;
	}
	//  cout << R[2] << endl;
	int ans = 0;
	int s = 0;
	for (int i = 0; i < lns; i++)
	{
		if (R[i] == 1 && K == 1 ){
			ans = K;
			break;
		}else if(R[i] == 1 && K != 1){
			K -= 1;
		}else{
			ans = R[i];
			break;
		}
	}
	cout << ans << endl;

}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n,q;
int s[100000],t[50000];
int main(){
    cin>>n;
    for (int i=0; i<n; i++) {
        cin>>s[i];
    }
    cin>>q;
    for (int i=0; i<q; i++) {
        cin>>t[i];
    }
    
    int left = 0;
    int right = n;
    int mid=(left+right)/2;
    int c=0;
    for (int i=0; i<q; i++) {
        if(s[mid]==t[i]){
            c++;
        }else if(s[mid]>t[i]){
            right=mid;
            for(int k=0;k<right;k++){
                if(t[i]==s[k]){
                    c++;
                    break;
                }
            }
        }else{
            left=mid+1;
            for(int k=left;k<n;k++){
                if(t[i]==s[k]){
                    c++;
                    break;
                }
            }
        }
    }
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 3520