akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        int N = Integer.parseInt(s.next());
        int Q = Integer.parseInt(s.next());
        TreeSet<Integer> set = new TreeSet<Integer>();
        for(int i = 0; i < N; i++){
            int c = Integer.parseInt(s.next());
            set.add(c);
        }
        int max_val = Collections.max(set);
        for(int i = 0; i < Q; i++){
            int q = Integer.parseInt(s.next());
            int ans = max_val % q;
            for(int j = q; j <= max_val; j += q){
                Integer v = set.lower(j);
                if(v != null) ans = Math.max(ans, v % q);
            }
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 127760
N, M = map(int, input().split())
edges = [list(map(int, input().split())) for _ in range(M)]

import heapq
from collections import defaultdict
nodes = defaultdict(list)


for e in edges:
    nodes[e[0] - 1].append((1, e[1] - 1))
    nodes[e[1] - 1].append((1, e[0] - 1))


INF = float('inf')

def dijkstra(x):
    que = []
    heapq.heapify(que)
    dist = [INF for _ in range(N)]
    dist[x] = 0
    heapq.heappush(que, (0, x))

    while que:
        p = heapq.heappop(que)
        v = p[1]
        if dist[v] < p[0]:
            continue
        for e in nodes[v]:
            if dist[e[1]] > dist[v] + e[0]:
                dist[e[1]] = dist[v] + e[0]
                heapq.heappush(que, (dist[e[1]], e[1]))

    return dist

dist = dijkstra(0)

if dist[-1] <= 2:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')


Measured memory_bytes: 126068
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

h,w=mp()
s=["#"*(w+2)]
for i in range(h):
    s.append("#"+input()+"#")
s.append("#"*(w+2))
ans=[[0]*(w+2) for i in range(h+2)]

for i in range(h+2):
    ran=[]
    c=1
    for j in range(1,w+2):
        if s[i][j]==s[i][j-1]:
            c+=1
        else:
            ran.append(c)
            c=1
    ran.append(c)
    p=0
    for j in range(len(ran)):
        for k in range(ran[j]):
            if j%2==1:
                ans[i][p]+=ran[j]
            p+=1

for i in range(w+2):
    ran=[]
    c=1
    for j in range(1,h+2):
        if s[j][i]==s[j-1][i]:
            c+=1
        else:
            ran.append(c)
            c=1
    ran.append(c)
    p=0
    for j in range(len(ran)):
        for k in range(ran[j]):
            if j%2==1:
                ans[p][i]+=ran[j]
            p+=1
print(max(list(itertools.chain.from_iterable(ans)))-1)

Measured memory_bytes: 221420
#include<iostream>
using namespace std;
long ans,n,k;
main()
{
	cin>>n>>k;
	for(int i=0;i<11;i++)
	{
		long t=0;
		for(int j=1;j<=5;j++)
		{
			long now=0;
			for(int l=0;l<3;l++)for(int m=0;m<3;m++)now+=(i+l)*7+j+m;
			t+=now%11==k;
		}
		ans+=t*=n<i+3?0:(n-i-3)/11+1;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define intarr(arr, n)  ll arr[n];  for (ll i = 0; i < n; i++)  cin >> arr[i]
#define inpvec(vec,n) for(ll i=0;i<n;i++){ll var;cin>>var;vec.push_back(var);}
#define ff first
#define ss second
#define pb push_back
#define mkp make_pair
#define vec vector<ll>
#define pi pair<ll,ll>
#define changeline cout<<endl
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define all(v) v.begin(),v.end()
#define mod2 998244353
#define NO cout << "NO" <<endl
#define YES cout << "YES" <<endl
#define mem(arr,val) memset(arr,val,sizeof(arr));
const ll mod=1e9+7;
#define piii 3.14159265358979323846264338327950


bool prime(ll n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
bool subsequence_checker(string str1, string str2, ll m, ll n) 
{ 
    if (m == 0) return true; 
    if (n == 0) return false; 
    if (str1[m-1] == str2[n-1]) 
        return subsequence_checker(str1, str2, m-1, n-1); 
    return subsequence_checker(str1, str2, m, n-1); 
}

//////////////////////////////////////////////////// Lets Do It ////////////////////////////////////////////////////////
bool cmp(const pair<int,int> &a,  const pair<int,int> &b) 
{ 
    if(a.ff == b.ff)
        return a.ss>b.ss;
    return (a.ff < b.ff); 
} 
string str = "";

void fun(ll now) {
  if (now == 0) 
    return;
  if (now >= 1 and now <= 26) 
  {
    str += now - 1 + 'a';
    return;
  }
  ll var = now / 26;
  
  if (var != 0 and now % 26 == 0) {
    fun(var - 1);
    fun(26);
  }
  else {
    fun(var);
    fun(now % 26);
  }

}
void solve(){

    ll n;
    cin>>n;
    fun(n);
    cout<<str;

    return;    
} 
 
int main()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
    IOS;
    ll t;
    //cin>>t;
    t=1;

    while(t--){
        solve();
        cout<<endl;
    }

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
} 

Measured memory_bytes: 3640
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    string a;
    int ai, zi;
    bool ba = true,bz = false;
    cin >> a;
    rep(i, a.size()) {
        if (ba && a[i] == 'A') {
            ba = false;
            ai = i;
        }
        if (a[i] == 'Z')zi = i;
    }

    cout << zi - ai+1 << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

#if MYDEBUG
#include "lib/cp_debug.h"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

struct Problem {
  string s;
  int n;
  vector<vector<int>> nxt;

  vector<int> memo, ans;
  Problem(string s) : s(s), n(s.length() + 1), nxt(n, vector<int>(26)), memo(n, -1), ans(n){};
  void solve() {
    s = "*" + s;
    vector<int> tmp(26, INF);
    for (int i = n - 1; i >= 0; --i) {
      nxt[i] = tmp;
      if (i > 0) tmp[s[i] - 'a'] = i;
    }
    dfs(0);
    for (int i = 0; i < INF; i = nxt[i][ans[i]]) {
      cout << (char)('a' + ans[i]);
    }
    cout << endl;
  }
  int dfs(int p) {
    if (p == INF) return 0;
    if (memo[p] >= 0) return memo[p];
    int amin = 0, mini = INF;
    for (int i = 0; i < 26; ++i) {
      int res = dfs(nxt[p][i]);
      if (res < mini) {
        amin = i;
        mini = res;
      }
    }
    ans[p] = amin;
    return memo[p] = mini + 1;
  }
};

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  std::string s;
  cin >> s;
  Problem p(s);
  p.solve();
  return 0;
}


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

int main() {
	int n;
	cin >> n;
	int ac=0,wa=0,tl=0,re=0;
	for(int i=0;i<n;i++)
	{
		string s;
		cin >> s;
		if(s=="AC")
		{
			ac++;
		}
		else if(s=="WA")
		{
			wa++;
		}
		else if(s=="TLE")
		{
			tl++;
		}
		else
		{
			re++;
		}
	}
	cout << "AC x " << ac << endl;
	cout << "WA x " << wa << endl;
	cout << "TLE x " << tl << endl;
	cout << "RE x " << re << endl;
	return 0;
}

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

int main() {
  int x;
  cin >> x;
  int a, b, c;
  a = x / 3600;
  b = x % 3600 / 60;
  c = x % 3600 % 60; 
  cout << a << ":" << b << ":" << c << endl;
}


Measured memory_bytes: 3096
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

int N;
vector<int> P, X;
vector<vector<int>> Q;
vector<pair<int, int>> a;
bool flag;

void dfs(int s){
    if(!flag) return;

    if(Q[s].empty()){
        a[s] = make_pair(X[s], 0);
        return;
    }

    vector<pair<int, int>> b;
    for(int t : Q[s]){
        dfs(t);
        if(!flag) return;
        b.push_back(a[t]);
    }

    int M = b.size();
    for(int i=0; i<M; i++)
        if(b[i].first > b[i].second)
            swap(b[i].first, b[i].second);
    vector<int> c(M);
    for(int i=0; i<M; i++) c[i] = b[i].second - b[i].first;


    int sm = 0;
    for(int i=0; i<M; i++) sm += b[i].first;
    if(sm > X[s]){
        flag = false;
        return;
    }

    int targ = X[s]-sm;
    vector<bool> dp(targ+1, false);
    dp[0] = true;
    for(int i=0; i<M; i++){
        for(int j=targ; j>=0; j--){
            if(j-c[i] >= 0 && dp[j-c[i]]) dp[j] = true;
        }
    }
    int opt = -1;
    for(int i=targ; i>=0; i--){
        if(dp[i]){
            opt = i;
            break;
        }
    }
    if(opt==-1){
        flag = false;
        return;
    }
    opt += sm;
    for(int i=0; i<M; i++) sm += b[i].second;

    //vector<bool> dp(X[s]+1, false);
    //if(b[0].first <= X[s])
    //    dp[b[0].first] = true;
    //if(b[0].second <= X[s])
    //    dp[b[0].second] = true;
    //for(int i=1; i<M; i++){
    //    int x = b[i].first;
    //    int y = b[i].second;
    //    for(int j=X[s]; j>=0; j--){
    //        if(j-x >= 0 && dp[j-x]) dp[j] = true;
    //        if(j-y >= 0 && dp[j-y]) dp[j] = true;
    //    }
    //}

    //int opt = -1;
    //for(int i=X[s]; i>=0; i--){
    //    if(dp[i]){
    //        opt = i;
    //        break;
    //    }
    //}
    //if(opt == -1){
    //    flag = false;
    //    return;
    //}
    //int sm = 0;
    //for(int i=0; i<M; i++){
    //    sm += b[i].first;
    //    sm += b[i].second;
    //}
    int Y = sm - opt;
    a[s] = make_pair(X[s], Y);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    flag = true;
    cin >> N;
    P.resize(N); X.resize(N); Q.resize(N); a.resize(N);
    for(int i=1; i<N; i++) cin >> P[i];
    for(int i=1; i<N; i++) P[i]--;
    for(int i=0; i<N; i++) cin >> X[i];

    for(int i=1; i<N; i++) Q[P[i]].push_back(i);

    dfs(0);
    if(flag) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
    return 0;
}

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

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

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  int x;
  cin >> x;
  if(x%2==0){
    cout << (double)(1) / 2 << endl;
  } else { 
    cout << ( (double)(x+1)/2 ) / (double)x << endl;
  }
}


Measured memory_bytes: 256
# Problem E - Red and Green Apples

from collections import deque

# input
X, Y, A, B, C = map(int, input().split())
red_apples = sorted(list(map(int, input().split())), reverse=True)
green_apples = sorted(list(map(int, input().split())), reverse=True)
mushoku_apples = list(map(int, input().split()))

# initialization
red_apples = red_apples[:X]
green_apples = green_apples[:Y]
ans_list = deque([])

# sort
for r in red_apples:
    ans_list.append(r)
for g in green_apples:
    ans_list.append(g)
for m in mushoku_apples:
    ans_list.append(m)
ans_list = sorted(ans_list, reverse=True)

# output
ans = sum(ans_list[:X+Y])
print(ans)


Measured memory_bytes: 110956
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

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

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >>n;
    vector<int> w(n);
    for(int i = 0; i < n; i++)
        cin >>w[i];
    vector<int> left;
    left.push_back(w[0]);
    for(int i = 1; i < n; i++)
        left.push_back(left[i-1] + w[i]);
    int total = accumulate(w.begin(), w.end(), 0);
    int ans = INT_MAX;
    for(int i = 0; i < n; i++){
        int s1 = left[i];
        int s2 = total - s1;
        ans = min(ans, abs(s2-s1));
    }
    cout <<ans;
    return 0;
}


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

int main()
{
    int n,m,l;
    cin >> n >> m >> l;
    vector<vector<int>> A(n, vector<int>(m));
    vector<vector<int>> B(m, vector<int>(l));
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<m; j++)
        {
            cin >> A.at(i).at(j);
        }
    }

    for (int i=0; i<m; i++)
    {
        for (int j=0; j<l; j++)
        {
            cin >> B.at(i).at(j);
        }
    }

    vector<vector<long>> product(n, vector<long>(l, 0));
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<l; j++)
        {
            for (int k=0; k<m; k++)
            {
                product.at(i).at(j) += A.at(i).at(k)*B.at(k).at(j);
            }
        }
    }

    for (int i=0; i<n; i++)
    {
        for (int j=0; j<l; j++)
        {
            cout << product.at(i).at(j);
            if (j<l-1)
            {
                cout << " ";
            }
        }
        cout << endl;
    }


}



Measured memory_bytes: 3264
from copy import deepcopy
n = int(input())
a = list(map(int,input().split()))

for i in range(int(input())):
    b,e,t = map(int,input().split())
    tmp = deepcopy(a)
    for k in range(e-b):
        a[t+k] = tmp[b+k]
        a[b+k] = tmp[t+k]

print(*a)


Measured memory_bytes: 6492
n,q=map(int,input().split())
s=input()
l=[0]*n
tmp="hoge"
for i,j in enumerate(s):
    if j=="C" and tmp=="A":
        l[i]=1
    tmp=s[i]
ls=[0]
tmp=0
for i in l:
    tmp+=i
    ls.append(tmp)
for i in range(q):
    a,b=map(int,input().split())
    print(ls[b]-ls[a])

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

using namespace std;

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

const ll mod = 998244353;

vector<P> po;
ll n;
ll bitl[200005];
ll bitr[200005];
ll ans;

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

ll sum(int i, bool LorR) {
  ll s = 0;
  if(LorR) {
    while(i > 0) {
      s += bitl[i];
      i -= i & -i;
    }
  }
  else {
    while(i > 0) {
      s += bitr[i];
      i -= i & -i;
    }
  }
  return s;
}

void add(int i, int x, bool LorR) {
  if(LorR) {
    while(i <= n) {
      bitl[i] += x;
      i += i & -i;
    }
  }
  else {
    while(i <= n) {
      bitr[i] += x;
      i += i & -i;
    }
  }
  return;
}

int main() {
  cin >> n;
  for(int i = 0; i < n; i++) {
    ll x, y;
    cin >> x >> y;
    po.push_back(P(x,y));
  }
  sort(po.begin(),po.end());

  for(int i = 0; i < po.size(); i++) {
    po[i] = P(i,po[i].second);
    po[i] = P(po[i].second,po[i].first);
  }

  sort(po.begin(),po.end());
  for(int i = 0; i < po.size(); i++) {
    po[i] = P(i,po[i].second);
    po[i] = P(po[i].second,po[i].first);
  }

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

   for(int i = 0; i < po.size(); i++) {
     add(po[i].second + 1,1,false);
   }

   for(int i = 0; i < po.size(); i++) {
     add(po[i].second + 1,-1,false);
     if(i > 0) add(po[i-1].second + 1,1,true);
     int Y = po[i].second + 1;
     ll C = sum(Y - 1,true);
     ll D = sum(Y - 1,false);
     ll A = sum(n,true) - sum(Y,true);
     ll B = sum(n,false) - sum(Y,false);
     //  cout << A << "  "<<B<<"  "<<C<<"  "<<D<<endl;
     ll T1 = p(2,n - 1);
     ll T2 = (p(2,A)-1) * (p(2,D)-1) % mod * p(2,B) % mod * p(2,C) % mod;
     ll T3 = p(2,A) * p(2,D) % mod * (p(2,B)-1) % mod * (p(2,C)-1) % mod;
     ll T4 = (p(2,A)-1) * (p(2,D)-1) % mod * (p(2,B)-1) % mod * (p(2,C)-1) % mod;
     ans = (ans + T1 + (T2 + T3 - T4) % mod) % mod;
   }

   cout << ans << endl;

  
}
  


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

int n,l;
string s[110];

int main()
{
	cin>>n>>l;
	for(int i=1;i<=n;i++) cin>>s[i];
	sort(s+1,s+n+1);
	for(int i=1;i<=n;i++) cout<<s[i];
	return 0;
}

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

int main(){
int n,a;
cin>>n;
string s;
double b,sum=0.0;
while(n--){
  cin>>b>>s;
  if(s=="BTC"){
    sum=sum+b*380000.0;
  }
  sum=sum+b;
}
cout<<sum<<endl;







return 0;}


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

namespace CSharp_AtCoder
{

    class Edge
    {
        public int to;
        public int id;
        public Edge(int to, int id)
        {
            this.to = to;
            this.id = id;
        }
    }
    
    class Program
    {
        static List<Edge>[] g;
        static int[] colors;
        static int max_color;

        
        static void DFS(int now, int parent_color = -1, int parent = -1)
        {
            int color = 1;  
            foreach(Edge to_node in g[now])
            {
                int to = to_node.to;
                int edge_id = to_node.id;
                if (to == parent) continue;  
                if (color == parent_color) color++; 
                colors[edge_id] = color;  
                if (max_color < color) max_color = color;
                color++;  
                DFS(to, colors[edge_id], now);
            }
        }

        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            g = new List<Edge>[N];
            for (int i = 0; i < N; i++) g[i] = new List<Edge>();
            colors = new int[N - 1];
            max_color = 1;

            for(int i = 0; i < N - 1; i++)
            {
                int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x) - 1).ToArray();
                int node_a = input[0];
                int node_b = input[1];
                g[node_a].Add(new Edge(node_b, i));
                g[node_b].Add(new Edge(node_a, i));
            }

            //0を親ノードとしてDFS
            DFS(0);

            //表示
            Console.WriteLine(max_color);
            Console.WriteLine(string.Join("\n", colors));
        }
    }
}


Measured memory_bytes: 33808
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
int32_t main()
{
    string s;
    cin >> s;
    if(s[0] == '7' || s[1] == '7' || s[2] == '7')
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

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

constexpr ll MOD = 1000000007;

ll H, W;
char field[1010][1010];
ll dp[1010][1010];

int main(int argc, char **argv)
{
	ll H, W; cin >> H >> W;
	for (ll i = 0; i < H; ++i)
		for (ll j = 0;j < W; ++j)
			cin >> field[i][j];

	dp[0][0] = 1;
	for (ll i = 0; i < H; ++i)
	{
		for (ll j = 0; j < W; ++j)
		{
			if (i+1 < H && field[i+1][j] == '.')
				(dp[i+1][j] += dp[i][j]) %= MOD;
			if (j+1 < W && field[i][j+1] == '.')
				(dp[i][j+1] += dp[i][j]) %= MOD;
		}
	}

	std::cout << dp[H-1][W-1] << std::endl;
}


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

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

   if (a <= c && c <= b) {
       cout << "Yes" << endl;
   } else {
       cout << "No" << endl;
   }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N;
    cin >> N;
    map<char, ll> S;
    for(size_t i=0;i<N; i++)
    {
        string s;
        cin >> s;
        if(s[0]=='M'||s[0]=='A'||s[0]=='R'||s[0]=='C'||s[0]=='H')
            S[s[0]]++;
    }
    //cerr <<S.size()<< endl;
    //for(auto s : S) cerr <<s.first << ":" << s.second << endl;
    ll comb=0;
    if(S.size()<3)
    {
        cout << 0 << endl;
        return 0;
    }
    else
    {
        cerr << S.size() << endl;
        ll Ssize = S.size();
        vector<char> march={'M', 'A', 'R', 'C', 'H'};
        for(ll i=0;i<march.size(); i++)
        {
            for(ll j=i+1;j<march.size(); j++)
            {
                for(ll k=j+1;k<march.size(); k++)
                {
                    //cerr << march[i] << "," << march[j] << "," << march[k] << endl;
                    //cerr << S[march[i]] << "," << S[march[j]] << "," << S[march[k]] << endl;
                    comb+=S[march[i]]*S[march[j]]*S[march[k]];
                }
            }
        }
    }
    cout << comb << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn.{readLine, readInt};
import scala.annotation.tailrec;
import scala.collection.immutable.Queue;

object Main {
    def main(args: Array[String]): Unit = {
        val input = readLine.split(" ").map(_.toInt);
        val size = input(0);
        val relationNum = input(1);
        val g = new Graph(size);
        (0 until relationNum).foreach { i =>
            readLine.split(" ").map(_.toInt) match {
                case Array(src, dst) => g.add(src, dst);
                case _ => ();
            }
        }
        g.createConnectedList();
        val f = (a: Int, b: Int) => a == b;
        (0 until readInt).foreach { i =>
            readLine.split(" ").map(_.toInt) match {
                case Array(src, dst) => if (g.isSameGroup(src, dst)) println("yes") else println("no");
                case _ => ()
            }
        }
        
    }
}

class Graph(val size: Int) {
    val al = new Array[List[Int]](size);
    val visited = new Array[Int](size);

    def dump = al.zipWithIndex.filterNot(a => a._1 == null).foreach { e => println("%d -> %s".format(e._2, e._1.mkString(" ")))}

    def add(src: Int, dst: Int): Unit = {
        al(src) = dst :: (if (al(src) == null) Nil else al(src));
        al(dst) = src :: (if (al(dst) == null) Nil else al(dst));
    }
    
    def isSameGroup(n1: Int, n2: Int) = if (visited(n1) == visited(n2) && visited(n1) != 0 && visited(n2) != 0) true else false;
    
    def createConnectedList(): Unit = {
        @tailrec
        def _bfs(que: Queue[Int], group: Int): Unit = que.dequeueOption match { // 幅優先での探索
            case None => ();
            case Some((curr, que1)) => {
                val nextNodes = if (al(curr) == null) Nil else al(curr);
                val nextQue = nextNodes.filter(visited(_) == 0).
                    foldLeft(que1) { (tmpQue, nextNode) =>
                        visited(nextNode) = group;
                        tmpQue.enqueue(nextNode);
                    }
                _bfs(nextQue, group);
            }
        }
        (0 until size).foreach { i =>
            if (al(i) != null && visited(i) == 0) {
                visited(i) = i + 1;
                _bfs(Queue[Int](i), i + 1);
            }
        }
    }
}


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

#define EPS 1.0e-10

using namespace std;

bool is_parallel(double ax, double ay, double bx, double by, double cx, double cy, double dx, double dy){
    double cp = (bx-ax)*(dy-cy) - (by-ay)*(dx-cx);
    return fabs(cp) < EPS;
}

int main(){
    int n;
    cin >> n;
    for(int i=0;i<n;++i){
        double x1, y1, x2, y2, x3, y3, x4, y4;
        cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
        if(is_parallel(x1,y1,x2,y2,x3,y3,x4,y4))
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 3164
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    S = input().strip()
    ans = 0
    for i in range(1, len(S)):
        if S[i] != S[i-1]:
            ans += 1
    return ans


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 68252
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <complex>
#include <cmath>
#include <cfloat>
using namespace std;

#define EPS 1e-7

typedef complex<double> P;

int n;
vector<P> pts;
double ans;

double dot(P a, P b){
	return real(a) * real(b) + imag(a) * imag(b);
}

double cross(P a, P b){
	return real(a) * imag(b) - imag(a) * real(b);
}

double intersect(P pa1, P pa2, P pb1, P pb2){
	P da12 = pa2 - pa1;
	P db21 = pb1 - pb2;
	P dab1 = pb1 - pa1;
	double D = cross(da12, db21);
	if(abs(D) > EPS){
		double t = cross(dab1, db21) / D;
		double s = cross(da12, dab1) / D;
		if(EPS < t && t < 1.0 - EPS && EPS < s && s < 1.0 - EPS){
			return t;
		}
	}
	return DBL_MAX;
}

void reflect(vector<P> &p, P mr1, P mr2){
	P u = mr1 - mr2;
	u /= abs(u);
	
	for(int i = 1; i < p.size(); ++i){
		p[i] = 2.0 * (mr1 - dot(mr1 - p[i], u) * u) - p[i];
	}
}

void check(P to, const vector<int> &seq){
	vector<P> p = pts;
	double dist = abs(to - p[0]);
	if(dist >= ans){ return; }

	P from = p[0];
	for(int k = 0; ; ++k){
		double minr = 1.0;
		int idx = 0;
		for(int i = 1; i <= n; ++i){
			double r = intersect(from, to, p[i*2], p[i*2+1]);
			if(minr > r){
				minr = r;
				idx = i;
			}
		}

		if(k == seq.size()){
			if(idx == 0){ ans = dist; }
			break;
		}
		else if(seq[k] != idx){
			break;
		}
		reflect(p, p[idx*2], p[idx*2+1]);
		from += minr * (to - from);
	}
}

void dfs(const vector<P> &p, vector<int> &seq){
	check(p[1], seq);
	
	if(seq.size() < 5){
		for(int i = 1; i <= n; ++i){
			vector<P> q = p;
			reflect(q, p[i*2], p[i*2+1]);
			seq.push_back(i);
			dfs(q, seq);
			seq.pop_back();
		}
	}
}

int main(){
	int x, y;
	while(scanf("%d", &n), n){
		pts.resize(2 * n + 2);
		for(int i = 0; i < 2 * n; ++i){
			scanf("%d%d", &x, &y);
			pts[i+2] = P(x, y);
		}
		scanf("%d%d", &x, &y);
		pts[1] = P(x, y);
		scanf("%d%d", &x, &y);
		pts[0] = P(x, y);

		ans = DBL_MAX;
		vector<int> seq;
		dfs(pts, seq);
		printf("%f\n", ans);
	}
}

Measured memory_bytes: 1252
program BBuBBBlesort
  implicit none
  integer :: n, a(100000,2), i, j, m
  a = 0
  read(*,*) n
  do i = 1, n
    read(*,*) a(i,1)
    a(i,2) = i
  end do
  call quick_sort(a(1:n,1:2),1)
  m = 0
  do i = 1, n
    if (mod(i+a(i,2),2).eq.1) m = m+1
  end do
  write(*,'(i0)') m/2
  stop
contains
  recursive subroutine quick_sort(a,i)
    implicit none
    integer, intent(inout) :: a(:,:)
    integer, intent(in) :: i
    integer :: p, c(size(a(1,:)))
    integer :: n, l, r
    n = size(a(:,1))
    l = 1
    r = n
    p = a((l+r)/2,i)+a(l,i)+a(r,i)-max(a((l+r)/2,i),a(l,i),a(r,i))-min(a((l+r)/2,i),a(l,i),a(r,i))
    do
      do while (a(l,i).lt.p)
        l = l+1
      end do
      do while (a(r,i).gt.p)
        r = r-1
      end do
      if (l.ge.r) exit
      c = a(l,:)
      a(l,:) = a(r,:)
      a(r,:) = c
      l = l+1
      r = r-1
    end do
    if (l.gt.2) call quick_sort(a(1:l-1,:),i)
    if (n.gt.r+1) call quick_sort(a(r+1:n,:),i)
    return
  end subroutine quick_sort
end program BBuBBBlesort

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication74
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int[] a = new int[5];
                int[] ans = new int[5];
                for (int tu = 0; tu < 5; tu++)
                {
                    a[tu] = int.Parse(Console.ReadLine());
                    if (a[tu] == 0)
                        break;
                }       /*????????????*/
                if (a[0] == 0)
                    break;
                int[] che2 = new int[3];
                for (int cho2 = 0; cho2 < 5; cho2++)
                    che2[a[cho2] - 1] += 1;   /*0=??°??????1=?????§??????2=??????*/
                    if ((che2[0] == 5 || che2[1] == 5 || che2[2] == 5) || (che2[0] != 0 && che2[1] != 0 && che2[2] != 0))
                        for (int o = 0; o < 5; o++)
                        {
                            ans[o] = 3;
                        } /*??¨??¨???????????£??????*/
               else if (che2[2] == 0)
                    for (int j = 0; j < 5; j++)
                    {
                        if (a[j] == 2)
                            ans[j] = 2;
                        else ans[j] = 1;
                    }
                else if (che2[1] == 0)
                    for (int g = 0; g < 5; g++)
                    {
                        if (a[g] == 1)
                            ans[g] = 2;
                        else ans[g] = 1;
                    }
                else if (che2[0] == 0)
                    for (int i = 0; i < 5; i++)
                    {
                        if (a[i] == 2)
                            ans[i] = 1;
                        else ans[i] = 2;
                    }
                    for (int u = 0; u < 5; u++)
                        Console.WriteLine(ans[u]);
            }
        }
    }
}

Measured memory_bytes: 9040
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }
template<class T>
ostream &operator<<(ostream &os,const vector<T> &v){
	for(int i = 0;i < v.size();i++) os << (i ? "," : "[") << v[i];
	os << "]";
	return os;
}

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }

const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int k,n,a[200010];
	cin >> k >> n;
	for(int i = 0;i < n;i++) cin >> a[i];
	a[n] = a[0] + k;
	int ma = 0;
	for(int i = 0;i < n;i++) chmax(ma,a[i + 1] - a[i]);
	cout << k - ma << endl;
}

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

// clang-format off
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define endl '\n'
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

constexpr int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}; 
constexpr int dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

void solver() {
    i64 N = input();

    if (N == 0) {
        cout << 0 << endl;
        return;
    }

    i64 k = 2, d = 1;
    vector< i32 > ans;

    while (N) {
        int b = (N % k != 0);
        N -= b * d;
        d *= -2;
        k *= 2;
        ans.push_back(b);
    }

    whole(reverse, ans);
    for (auto a: ans) cout << a;
    cout << endl;
}

signed main(int argc, char *argv[]) {
  solver();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<string> vecS(N);
  for (int i=0;i<N;i++)
    cin >> vecS.at(i);
  
  int M;
  cin >> M;
  vector<string> vecT(M);
  for (int i=0;i<M;i++)
    cin >> vecT.at(i);
  
  int maxgainS=0;
  for (int i=0;i<N;i++){
   int countS=0, countT=0;
   for (int j=0;j<N;j++){
     if (vecS.at(i) == vecS.at(j))
       countS++;
   }
   for (int j=0;j<M;j++){
     if (vecS.at(i) == vecT.at(j))
       countT++;
   }
   if (maxgainS < countS - countT)
     maxgainS = countS - countT;
  }
    
  int maxgainT=0;
  for (int i=0;i<M;i++){
   int countS=0, countT=0;
   for (int j=0;j<N;j++){
     if (vecT.at(i) == vecS.at(j))
       countS++;
   }
   for (int j=0;j<M;j++){
     if (vecT.at(i) == vecT.at(j))
       countT++;
   }
   if (maxgainT < countS - countT)
     maxgainT = countS - countT;
  }
  
  int maxgain;
  if (maxgainS > maxgainT)
    maxgain = maxgainS;
  else
    maxgain = maxgainT;
  
  if (maxgain > 0)
    cout << maxgain << endl;
  else
    cout << 0 << endl;
}

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

int main() {
    int d, n;
    cin >> d >> n;
    int ans = pow(100, d);
    ans *= n;
    if (n == 100) ans += pow(100, d);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
 
  // 1の数を表す変数
  int count = 0;
 
  // 9文字の式に限定していることに注意
  for (int i = 0; i < S.size(); i++) {
 
    // 1があればcountを増やす
    if (S.at(i) == 'o') {
      count++;
    }
 
  }
  //cout << count << endl;
  if((15 - S.size()) + count > 7)
  {
    cout << "YES" << endl;
  }
  else
  {
    cout << "NO" << endl;
  }
  
 

  
}


Measured memory_bytes: 256
// 2014/09/12 Tazoe

#include <iostream>
#include <queue>
#include <string>
#include <map>
using namespace std;

struct state{
	string G;
	int N;
};

bool is_over(string G)
{
	bool flg = true;

	for(int i=1; i<G.size(); i++){
		if(G[i]!=G[0]){
			flg = false;
			break;
		}
	}

	return flg;
}

void DFS(char g[12][12], char F, char T, int x, int y)
{
	if(g[y][x]!=F)
		return;

	g[y][x] = T;

	DFS(g, F, T, x-1, y);
	DFS(g, F, T, x+1, y);
	DFS(g, F, T, x, y-1);
	DFS(g, F, T, x, y+1);
}

string fill(string G, char C, int X, int Y)
{
	char g[12][12];
	for(int y=0; y<Y+2; y++){
		for(int x=0; x<X+2; x++){
			g[y][x] = 'N';
		}
	}

	// 文字列から2次元配列へ
	for(int y=0; y<Y; y++){
		for(int x=0; x<X; x++){
			g[y+1][x+1] = G[y*X+x];
		}
	}

	DFS(g, G[0], C, 1, 1);

	// 2次元配列から文字列へ
	for(int y=0; y<Y; y++){
		for(int x=0; x<X; x++){
			G[y*X+x] = g[y+1][x+1];
		}
	}

	return G;
}

int main()
{
	while(true){
		int X, Y;
		cin >> X >> Y;

		if(X==0 && Y==0)
			break;

		string G = "";
		for(int y=0; y<Y; y++){
			for(int x=0; x<X; x++){
				string c;
				cin >> c;

				G += c;
			}
		}

		queue<struct state> que;
		map<string, bool> memo;

		struct state ini;
		ini.G = G;
		ini.N = 0;
		que.push(ini);
		memo[ini.G] = true;

		while(!que.empty()){
			struct state now = que.front();
			que.pop();

			if(is_over(now.G)){
				cout << now.N << endl;
				break;
			}

			struct state nex1, nex2;

			if(now.G[0]=='R'){
				nex1.G = fill(now.G, 'G', X, Y);
				nex2.G = fill(now.G, 'B', X, Y);
				nex1.N = nex2.N = now.N+1;
			}
			else if(now.G[0]=='G'){
				nex1.G = fill(now.G, 'R', X, Y);
				nex2.G = fill(now.G, 'B', X, Y);
				nex1.N = nex2.N = now.N+1;
			}
			else if(now.G[0]=='B'){
				nex1.G = fill(now.G, 'R', X, Y);
				nex2.G = fill(now.G, 'G', X, Y);
				nex1.N = nex2.N = now.N+1;
			}

			if(memo.find(nex1.G)==memo.end()){
				que.push(nex1);
				memo[nex1.G] = true;
			}
			if(memo.find(nex2.G)==memo.end()){
				que.push(nex2);
				memo[nex2.G] = true;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<list>
#include<vector>
#include<stack>
#include<queue>
#include<ctime>
#include<cstdlib>
#include<sstream>
#include<functional>
#define D long long
#define F double
#define MAX 0x7fffffff
#define MIN -0x7fffffff
#define mmm(a,b) memset(a,b,sizeof(a))
#define for1(i,a,b) for(int i=a;i<=b;i++)
#define for2(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
#define N 60100
#define MOD ((int)1e9+7)
#define mod ((int)1e9+7)
typedef long long ll;
const double pi=acos(-1);
const F eps=1e-6;
D read(){ D ans=0; char last=' ',ch=getchar();
while(ch<'0' || ch>'9')last=ch,ch=getchar();
while(ch>='0' && ch<='9')ans=ans*10+ch-'0',ch=getchar();
if(last=='-')ans=-ans; return ans;
}


int f[2000009];//1Ст -1АЗ
int n;
int ok;
string x;
void fin(int l,int r){
    if(ok==1)return;
    mmm(f,0);
    f[1]=l,f[n]=r;
    if(f[1]==1){
        if(x[1]=='o')f[2]=f[n]*1;
        else f[2]=f[n]*(-1);
    }
    else{
        if(x[1]=='x')f[2]=f[n]*1;
        else f[2]=f[n]*(-1);
    }
    int ar=1;
    while(1){
        ar++;if(ar==n-1)break;
        if(f[ar]==1){
            if(x[ar]=='o')f[ar+1]=f[ar-1]*1;
            else f[ar+1]=f[ar-1]*(-1);
        }
        else{
            if(x[ar]=='x')f[ar+1]=f[ar-1]*1;
            else f[ar+1]=f[ar-1]*(-1);
        }
    }
    if(f[n-1]==1){
        if(x[n-1]=='o'){
            if(f[n-2]!=f[n])return;
        }
        else{
            if(f[n-2]==f[n])return;
        }
    }
    else{
        if(x[n-1]=='x'){
            if(f[n-2]!=f[n])return;
        }
        else{
            if(f[n-2]==f[n])return;
        }
    }

    if(f[n]==1){
        if(x[n]=='o'){
            if(f[n-1]!=f[1])return;
        }
        else{
            if(f[n-1]==f[1])return;
        }
    }
    else{
        if(x[n]=='x'){
            if(f[n-1]!=f[1])return;
        }
        else{
            if(f[n-1]==f[1])return;
        }
    }
    ok=1;return;
}

int  main(){
    cin>>n>>x;x=' '+x;
    ok=0;
    fin(1,1);
    fin(-1,1);
    fin(-1,-1);
    fin(1,-1);
    if(ok==0)printf("%d\n",-1);
    else{
        for(int i=1;i<=n;i++){
            if(f[i]==1)printf("S");
            else printf("W");
        }
        printf("\n");
    }
    return 0;
}
/*
oxxxooxxox
SSWSSSSWSW*/




Measured memory_bytes: 8320
def decode(x):
    return ord(x) - 97


def encode(x):
    return chr(x + 97)


S = list(map(decode, input()))
K = int(input())
for i in range(len(S) - 1):
    if S[i] == 0:
        continue
    if 26 - S[i] <= K:
        K -= 26 - S[i]
        S[i] = 0
S[-1] = (S[-1] + K) % 26
print("".join(map(encode, S)))


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

int main(){
   int n;
   cin >> n;
   vector<ll> b(n-1);
   rep(i,n-1) cin >> b[i];
   ll sum =b[n-2];
   for(int i=n-2;i>0;i--){
      sum += min(b[i-1],b[i]);
   }
   sum+=b[0];
   cout << sum << endl;
   return 0;
}


Measured memory_bytes: 256
module.exports=function(r){var e={};function t(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return r[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=r,t.c=e,t.d=function(r,e,n){t.o(r,e)||Object.defineProperty(r,e,{enumerable:!0,get:n})},t.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},t.t=function(r,e){if(1&e&&(r=t(r)),8&e)return r;if(4&e&&"object"==typeof r&&r&&r.__esModule)return r;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:r}),2&e&&"string"!=typeof r)for(var o in r)t.d(n,o,function(e){return r[e]}.bind(null,o));return n},t.n=function(r){var e=r&&r.__esModule?function(){return r.default}:function(){return r};return t.d(e,"a",e),e},t.o=function(r,e){return Object.prototype.hasOwnProperty.call(r,e)},t.p="",t(t.s=0)}([function(r,e,t){t(1)(t(2).readFileSync("/dev/stdin","UTF-8"))},function(r,e){function t(r,e){return function(r){if(Array.isArray(r))return r}(r)||function(r,e){var t=[],n=!0,o=!1,u=void 0;try{for(var i,f=r[Symbol.iterator]();!(n=(i=f.next()).done)&&(t.push(i.value),!e||t.length!==e);n=!0);}catch(r){o=!0,u=r}finally{try{n||null==f.return||f.return()}finally{if(o)throw u}}return t}(r,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}r.exports=function(r){for(var e=r.split("\n"),n=t(e[0].split(" ").map(function(r){return Number(r)}),2),o=n[0],u=n[1],i=[],f=0;f<o;f++){var a=e[f+1].split("");i.push(a)}for(var l=new Array(o).fill(0),c=0;c<o;c++)for(var p=0;p<u;p++)if("#"==i[c][p]){l[c]=1;break}for(var s=new Array(u).fill(0),d=0;d<u;d++)for(var y=0;y<o;y++)if("#"==i[y][d]){s[d]=1;break}for(var v=0;v<o;v++)if(0!=l[v]){for(var b="",m=0;m<u;m++)0!=s[m]&&(b+=i[v][m]);console.log(b)}}},function(r,e){r.exports=require("fs")}]);

Measured memory_bytes: 7808
b = {}
n = int(input())
a = list(map(int,input().split()))

for i in range(n):
    if a[i] not in b:
        b[a[i]] = 1
    else:
        b[a[i]] += 1
count = 0
for i in b:
    if b[i] < i:
        count += b[i]
    else:
        count += b[i] - i

print(count)

Measured memory_bytes: 18172
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1000000009
using namespace std;
using ll = long long;
int main()
{
    int n;
    cin >> n;
    vector<vector<int>> f(n, vector<int>(10));
    vector<vector<int>> p(n, vector<int>(11));
    rep(i,n){
        rep(j,10){
            cin >> f[i][j];
        }
    }
    rep(i,n){
        rep(j,11){
            cin >> p[i][j];
        }
    }
    int len = 1 << 10;
    int ans = -INF;
    rep(i,len-1){
        int tmp = 0;
        rep(j,n){
            int x = i + 1;
            int cnt = 0;
            rep(k,10){
                if(x&1 && f[j][k]){
                    cnt++;
                }
                x = x >> 1;
            }
            tmp += p[j][cnt];
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}


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

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(NULL);
#define endl            "\n"
#define NUM             100005
typedef long long ll;

int a[NUM][3],dp[NUM][3];

int main()
{
    FastRead

    int n;

    cin>>n;

    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<3;j++)
            cin>>a[i][j];
    }

    for(ll i=0;i<n;i++)
    {

            dp[i+1][0] = max(dp[i][1]+a[i][1],dp[i][2]+a[i][2]);
            dp[i+1][1] = max(dp[i][0]+a[i][0],dp[i][2]+a[i][2]);
            dp[i+1][2] = max(dp[i][0]+a[i][0],dp[i][1]+a[i][1]);
    }

    /*for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<3;j++)
        {
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }*/

    cout<<max({dp[n][0],dp[n][1],dp[n][2]});
}


Measured memory_bytes: 2688
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <tuple>
#include <math.h>
#include <set>
#include <map>
using namespace std ;
using ll = long long ;
using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using vc = vector<char> ;
using vvc = vector<vc> ;
using vb = vector<bool> ;
using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end() 
const ll INF = 1e18 ;
const ll mod = 1e9+7 ;
const double pie = acos(-1); 
vll dx4 = {-1,0,1,0} ;
vll dy4 = {0,-1,0,1} ;
vll dx8 = {-1,0,1,1,1,0,-1,-1} ;
vll dy8 = {-1,-1,-1,0,1,1,1,0} ; 

void fix_cout(){cout << fixed << setprecision(20) ; }
ll gcd(ll a,ll b){if(b==0) return a ; return gcd(b,a%b) ; }
ll lcm(ll a,ll b){return a/gcd(a,b)*b ; }
void chmax(ll &a,ll b){if(a<b) a = b ; }
void chmin(ll &a,ll b){if(a>b) a = b ; }

int main(){
	ll n ; cin >> n ; 
	vll a(n) ;
	for(auto &i:a) cin >> i ;
	sort(all(a)) ;
	ll ans = 0 ;
	vb ok(1e6+1,true) ;
	for(int i=0;i<n;i++){
		if(!ok.at(a.at(i))) continue ;
		ans++ ;
		if(i+1<n&&a.at(i+1)==a.at(i)) ans-- ;
		ll num = a.at(i) ;
		while(num<=1e6){
			ok.at(num) = false ;
			num += a.at(i) ;
		}
	}
	cout << ans << endl ;
}

Measured memory_bytes: 4844
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    class Program
    {
        static void Main(string[] args)
        {
            var cin = new Scanner();
            var A = cin.next();
            var B = cin.next();

            var ans = "";
            if(A.Length > B.Length)
            {
                ans = "GREATER";
            }
            else if (A.Length == B.Length)
            {
                for (int i = 0; i < A.Length; i++)
                {
                    int a = A[i];
                    int b = B[i];
                    if (a > b)
                    {
                        ans = "GREATER";
                        break;
                    }
                    else if (a < b)
                    {
                        ans = "LESS";
                        break;
                    }
                    else
                    {
                        ans = "EQUAL";
                        break;
                    }
                }
            }
            else
            {
                ans = "LESS";
            }
            Console.WriteLine(ans);
        }
    }

    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: 13140