akhauriyash/Code-Regression huggingface dataset:
from collections import deque


class Dinic:
    def __init__(self, n: int):
        self.INF = 10**9 + 7
        self.n = n
        self.graph = [[] for _ in range(n)]
 
    def add_edge(self, _from: int, to: int, capacity: int):
        """残余グラフを構築
        1. _fromからtoへ向かう容量capacityの辺をグラフに追加する
        2. toから_fromへ向かう容量0の辺をグラフに追加する
        """
        forward = [to, capacity, None]
        forward[2] = backward = [_from, 0, forward]
        self.graph[_from].append(forward)
        self.graph[to].append(backward)
 
    def bfs(self, s: int, t: int):
        """capacityが正の辺のみを通ってsからtに移動可能かどうかBFSで探索
        level: sからの最短路の長さ
        """
        self.level = [-1] * self.n
        q = deque([s])
        self.level[s] = 0
        while q:
            _from = q.popleft()
            for to, capacity, _ in self.graph[_from]:
                if capacity > 0 and self.level[to] < 0:
                    self.level[to] = self.level[_from] + 1
                    q.append(to)
 
    def dfs(self, _from: int, t: int, f: int) -> int:
        """流量が増加するパスをDFSで探索
        BFSによって作られた最短路に従ってfを更新する
        """
        if _from == t:
            return f
        for edge in self.itr[_from]:
            to, capacity, reverse_edge = edge
            if capacity > 0 and self.level[_from] < self.level[to]:
                d = self.dfs(to, t, min(f, capacity))
                if d > 0:
                    edge[1] -= d
                    reverse_edge[1] += d
                    return d
        return 0
 
    def max_flow(self, s: int, t: int):
        """s-tパス上の最大流を求める
        計算量: O(|E||V|^2)
        """
        flow = 0
        while True:
            self.bfs(s, t)
            if self.level[t] < 0:
                break
            self.itr = list(map(iter, self.graph))
            f = self.dfs(s, t, self.INF)
            while f > 0:
                flow += f
                f = self.dfs(s, t, self.INF)
        return flow


h, w = map(int, input().split())
a = [list(input()) for i in range(h)]

di = Dinic(h + w + 2)
for i in range(h):
    for j in range(w):
        if a[i][j] == "o":
            di.add_edge(i, h + j, 1)
            di.add_edge(h + j, i, 1)
        if a[i][j] == "S":
            di.add_edge(h + w, i, 10 ** 5)
            di.add_edge(h + w, h + j, 10 ** 5)
        if a[i][j] == "T":
            di.add_edge(i, h + w + 1, 10 ** 5)
            di.add_edge(h + j, h + w + 1, 10 ** 5)

ans = di.max_flow(h + w, h + w + 1)
if ans >= 10 ** 5:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 48732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}
//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}
bool isPrime(int x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

int main(){
    static const double pi = 3.141592653589793;
    double a,b,h,m;
    cin >> a >> b >> h >> m;

    double sh = h*30+m*0.5;
    double sm = m*6;

    double s = min(abs(sh-sm),360-abs(sh-sm));
    
    double d = cos(s/180*pi);

    double ans = sqrt((a*a)+(b*b)-(2*a*b*d));

    cout << setprecision(10) << ans << endl;

    return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
// typedef Graph vector<vector<int>>; // グラフ型
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
double pi = 3.141592653589793;
ll mod = 1000000007;
ll INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;



int main(){
    int n, ans = 1;
    cin >> n;
    string s;
    cin >> s;
    REP(i, 1, n){
        if(s[i-1]!=s[i])ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
N,Q=map(int,input().split())
E=[[] for i in range(N)]
for i in range(N-1):
  a,b=map(int,input().split())
  E[a-1].append(b-1)
  E[b-1].append(a-1)
X=[0]*N
for i in range(Q):
  p,x=map(int,input().split())
  X[p-1]+=x
  
stack=[]
stack.append([0,0,-1])
ans=[0]*N
while stack:
  node=stack.pop()
  v=node[0]
  val=node[1]
  parent=node[2]
  ans[v]+=val+X[v]
  children=E[v]
  for child in children:
    if child==parent:
      continue
    stack.append([child,ans[v],v])

print(*ans)

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

int m, n;
int blue[505];
int red[505];

bool bluematch[505];
int redpair[505];

int path[505][505];

int gcd(int a, int b)
{
    int m;
    
    while(1){
        m = a%b;
        if(m==0)
            return b;
        a = b;
        b = m;
    }
    return 1;
}

bool match(int x){
    if(x<0) return true;
    
    if(bluematch[x]){
        return false;
    }
    bluematch[x]=true;
    
    for(int y=0; y<n; y++){
        if(!path[x][y]) continue;
        if(match(redpair[y])){
            redpair[y]=x;
            return true;
        }
    }
    
    return false;
}

int main() {
    ios_base::sync_with_stdio(0);
    
    int i, j, cnt;
    while(1){
        cin >> m >> n;
        if(m==0)
            return 0;
        
        for(i=0;i<m;i++){
            cin >> blue[i];
        }
        
        for(i=0;i<n;i++){
            cin >> red[i];
        }
        
        for(i=0; i<m; i++){
            for(j=0; j<n; j++){
                if(gcd(blue[i],red[j])!=1){
                    path[i][j]=1;
                }
                else{
                    path[i][j]=0;
                }
            }
        }
        
        fill(redpair, redpair+n, -1);
        cnt=0;
        for(i=0; i<m; i++){
            fill(bluematch, bluematch+m, 0);
            if(match(i)){
                cnt++;
            }
        }
        cout << cnt << endl;
    }
    
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)
#define All(x) (x).begin(),(x).end()
#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))
#define End '\n'
#define Out(x) cout<<(x)<<End
template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair
#define X first
#define Y second

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);

    long n;

    cin >> n;

    ll a[n];
    list<ll> ans0;
    list<ll> ans1;
    long index;

    long i, j;

    rep(i, n) cin >> a[i];

    sort(a, a + n);

    ans0.push_front(a[0]);

    i = 1;
    j = n - 1;
    repi(index, n, 1) {
        if (index % 2 == 1) {
            if (i <= j) ans0.push_back(a[j]);
            j--;
            if (i <= j) ans0.push_front(a[j]);
            j--;
        } else {
            if (i <= j) ans0.push_back(a[i]);
            i++;
            if (i <= j) ans0.push_front(a[i]);
            i++;
        }

        if (j < i) break;
    }

    ans1.push_front(a[n - 1]);

    i = 0;
    j = n - 2;
    repi(index, n, 1) {
        if (index % 2 == 1) {
            if (i <= j) ans1.push_back(a[i]);
            i++;
            if (i <= j) ans1.push_front(a[i]);
            i++;
        } else {
            if (i <= j) ans1.push_back(a[j]);
            j--;
            if (i <= j) ans1.push_front(a[j]);
            j--;
        }

        if (j < i) break;
    }

    V<ll> v = V<ll>(All(ans0));
    V<ll> vv = V<ll>(All(ans1));
    ll sum0 = 0;
    ll sum1 = 0;

    repi(i, n, 1) {
        sum0 += Abs(v[i] - v[i - 1]);
        sum1 += Abs(vv[i] - vv[i - 1]);
    }

    Out(max(sum0, sum1));

    return 0;
}


Measured memory_bytes: 8832
#include <iostream>
#include <vector>
#include <numeric>
#include <math.h>
#include <algorithm> 
#include <string>

#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define sum(n) accumulate((n).begin(), (n).end(), 0)
using namespace std;


int main(){
	int a, b;
	cin >> a >> b;
	if (a == b || a % b == 0) {
		cout << 0 << endl;

	}
	else {
		cout << 1 << endl;
	}
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 1000000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    ll n, k; cin >> n >> k;
    vector<ll> s(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> s[i];
        s[i] += s[i - 1];
    }
    map<ll, ll> cnt;
    for (ll i = 0; i < min(n + 1, k); ++i) {
        ++cnt[(s[i] - i)% k];
    }
    ll ans = 0;
    for (ll i = 0; i <= n; ++i) {
        ll v = (s[i] - i) % k;
        ans += cnt[v] - 1;
        --cnt[v];
        if (i + k <= n) ++cnt[(s[i + k] - i - k) % k];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 14336
#include <iostream>

int main() {
    int n;
    std::cin >> n;

    int sum = 0, max = 0;
    for (int i = 0; i < n; ++i) {
        int l;
        std::cin >> l;
        sum += l;
        max = std::max(max, l);
    }

    std::cout << (max < sum - max ? "Yes" : "No") << std::endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
monster = list(map(int, input().split()))
yuusha = list(map(int, input().split()))
a = sum(monster)
for i in range(n):
    if monster[i] < yuusha[i]:
        yuusha[i] -= monster[i]
        monster[i] = 0
        if monster[i+1] < yuusha[i]:
            yuusha[i] -= monster[i+1]
            monster[i+1] = 0
        else:
            monster[i+1] -= yuusha[i]
            yuusha[i] = 0
    else:
        monster[i] -= yuusha[i]
        yuusha[i] = 0
a -= sum(monster)
print(a)


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

string s;

int main()
{
    cin >> s;
    long long result = 0, count_a = 0;

    string s_2 = s;
    for (int i = 0; i < (int)s.size() - 2; ++i)
    {
        if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
        {
            result += count_a + 1;
            s[i + 2] = 'A';
            ++i;
        }
        else if (s[i] == 'A')
        {
            ++count_a;
        }
        else
        {
            count_a = 0;
        }
    }
    cout << result << endl;

    
}

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

int n;

bool isprime(int x) {
	for (int i = 2; i * i <= x; i++)
		if (x % i == 0)
			return false;
	return true;
}

int main() {
	cin >> n;
	for (int i = n; ; i++)
		if (isprime(i)) {
			cout << i;  
			return 0;
		}
}


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

int main(){
  int n, y, m, d, mille, birth;
  mille = 195 * 999 + (999/3 * 5) + 1;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> y >> m >> d;

    birth = 195 * (y-1) + ((y-1)/3 * 5);
    if(y%3 == 0){
      birth += (m-1) * 20;
    }else{
      birth += ((m-1)*20) - ((m-1)/2);
    }
    birth += d;

    cout << (mille-birth) << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <string.h>
char s[100001];
int words[30]={};
int main(){
    scanf("%s",s);
    int len=strlen(s);
    if (s[0]==s[1]) {
        printf("1 2");
        return 0;
    }
    words[s[0]-'a']++,words[s[1]-'a']++;
    for (int i=2; i<len; i++) {
        if ((++words[s[i]-'a'])>1) {
            printf("%d %d\n",i-1,i+1);
            return 0;
        }
        words[s[i-2]-'a']--;
    }
    printf("-1 -1");
}

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

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

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

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}


int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  string S;
  cin >> S;
  int K;
  cin >> K;

  int cnt=0;
  rep(i,sz(S)){
    if(S.at(i)=='1')  cnt++;
    else  break;
  }
  if(K<=cnt)  cout << 1 << endl;
  else  cout << S.at(cnt) << endl;

  return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

int main(){
	string s, p;
	bool flag=false;
	int i=0;
	
	cin >> s;
	cin >> p;
	
	int len=s.size();
	int len2=p.size();
	//printf("len=%d, %d\n", len, len2);
	
	while(i<len && !flag){
		if(s[i] == p[0]){
			for(int a=0; a<len2; ++a){
				if(s[ (i+a)%len ] != p[a]){
					flag = false; 
					break;
				}
				else flag = true;
			}
		}
	
		++i;
	}
	
	if(flag) printf("Yes\n");
	else printf("No\n");

	return 0;
}

Measured memory_bytes: 1160
#include<iostream>  
#include<cstdio>  
#include<algorithm>  
#include<cstring>  
#include<string>  
#include<cmath>  
#include<cstdlib>  
using namespace std;  
  int main()
  {
  	 int a,b,c,d,e;
  	 cin>>e;
  	 d=e%10;c=(e/10)%10;b=(e/100)%10;a=(e/1000)%10;
  	 if(a+b+c+d==7) cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;
  	 else if(a-b+c+d==7) cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;
  	 else if(a+b-c+d==7) cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;
  	 else if(a+b+c-d==7) cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;
  	 else if(a-b-c+d==7) cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;
  	 else if(a-b+c-d==7) cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;
  	 else if(a-b-c-d==7) cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;
  	 else if(a+b-c-d==7) cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;
  	return 0;
  	
  	
  	
  	
  	
  }

Measured memory_bytes: 256
n,d = map(int,input().split())
x_list_kai = [list(map(int,input().split())) for x in range(n)]


import itertools,math
dis = []
for x in itertools.combinations(x_list_kai,2):
    distance = 0
    for dim in range(0,d):
        result  = 0
        for y in x:
            if result == 0:
                result = y[dim]
            else:
                result -= y[dim]
            
        result  = result **2
        distance += result
    dis.append(math.sqrt(distance))
    
counter = 0
for i in dis:
    if i.is_integer() == True:
        counter += 1
print(counter)

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;

ll n, k;
vector<ll> a;

bool is_ok(int x){
	ll coun = 0;
	for (int i = 0; i < n; i++){
		coun += (a[i]+x-1)/x-1;
	}
	if (coun <= k) return true;
	return false;
}

int nibutan(int ok, int ng){
	if (ok-ng == 1) return ok;
	int mid = (ok+ng)/2;
	if (is_ok(mid)) return nibutan(mid, ng);
	return nibutan(ok, mid);
}


int main(){
	cin >> n >> k;
	int max_a = 0;
	for (int i = 0; i < n; i++){
		int x;
		cin >> x;
		a.push_back(x);
		max_a = max(x, max_a);
	}
	
	cout << nibutan(max_a, 0) << endl;

	return 0;
}

Measured memory_bytes: 5308
#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 pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define int               long long
#define fr                first
#define sc                second
#define vc                vector
#define endl              '\n'
#define pii               pair<int,int>
#define msi               map<string,int>
#define mii               map<int,int>
#define psi               pair<string,int>
#define pis               pair<int,string>
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define LSB(i)            ((i)&-(i))

template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 1e5 + 5;
int dp[N];
int a[N];
int n, k;

int dynamic(int pos)
{
    if (pos > n)
        return INT_MAX;
    if (pos == n)
        return 0;
    if (dp[pos] != -1)
        return dp[pos];
    int ans = INT_MAX;
    for (int i = 1; i <= k; i++)
    {
        ans = min(ans, dynamic(pos + i) + abs(a[pos + i] - a[pos]));
    }
    dp[pos] = ans;
    return ans;
}

void solve()
{
    cin >> n >> k;
    for (int i = 1 ; i <= n; i++)
        cin >> a[i];
    mem1(dp);
    cout << dynamic(1);

}
signed main() {
    ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t = 1;
    //cin>>t;
    while (t--) solve();
    return 0;
}

Measured memory_bytes: 6528
#include<cstdio>
#include<vector>
#include<map>
#include<algorithm>
#include<cstring>
#define INF 1<<28
#define F first
#define S second
using namespace std;
 
int sx, sy, gx, gy;
typedef pair < int, int > P;
vector < P > p[5];
int memo[5][5][1111];

int dist(P a, P b){
  return abs(a.F - b.F) + abs(a.S - b.S);
}


int solve(int k, int t, int q){
 
  if(k == 4) return dist(p[t][q], P(gx, gy));
  if(memo[k][t][q]) return memo[k][t][q];
 
  int ans = INF, d = (t+1)%5, c;
  for(int i=0;i<p[d].size();i++){
    if(!k) c = dist(P(sx, sy), p[d][i]);
    else c = dist(p[t][q], p[d][i]);
    ans = min(ans, solve(k+1, d, i) + c);
  }
 
  return memo[k][t][q] = ans;
}
 
int main(){
 
  int w, h;
  char c;
 
  while(scanf("%d %d", &w, &h), w){
    
    for(int i=0;i<5;i++) p[i].clear();
    
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	scanf(" %c", &c);
	if(c == '.') continue;
	else if(c == 'S') sx = j, sy = i;
	else if(c == 'G') gx = j, gy = i;
	else p[c-'1'].push_back(P(j,i));
      }
    }
    
    int a, b = INF;
    for(int i=0;i<5;i++){
      memset(memo, 0, sizeof(memo));
      if(b > solve(0,i,0)) a = i+1, b = solve(0,i,0);
    }
 
    if(b == INF) puts("NA");
    else printf("%d %d\n", a, b);
 
  }
}

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

int main() {
  int R;
  int G;
  double x;
  
  cin >> R >> G;
  //(R + x) / 2 = G
  //R + x = 2 * G
  x = 2 * G - R;
  cout << x << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

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

	
	int N;
	cin >> N;

	map<int, int> A;

	rep(i, N) {
		int a;
		cin >> a;
		A[a]++;
	}

	int kotae = 0;
	for (auto itr: A) {
		while (itr.second != 0 && itr.second != itr.first) {
			itr.second--;
			kotae++;
		}
	}
	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 4736
#include<stdio.h>

int main(void)
{
	int K,T;
	int a[10001];
	int i,tmp,flag,day;
	
	flag = 0;
	day = 0;
	
	
	scanf("%d %d",&K,&T); // K,T
	for(i=0; i < T; i++){
		scanf("%d",&a[i]);
	}
	
	
	tmp = a[0];
	for(i=0; i < T; i++){
		if(a[i] > tmp){
			flag = i;
			tmp = a[i];
		}
	}

	day = a[flag] - 1 -(K-a[flag]);
	if( day < 0){
		printf("0\n");
	}else{
		printf("%d\n",day);
	}
	
	
	
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

#include <sstream>
#include <istream>

using namespace std;

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


int main(){
	ll N;
	cin >> N;

	stack<int> s;

	ll dig = 2;
	bool minus = false;
	while(N!=0){
		ll rem = abs(N%dig);
		s.push(rem/(dig/2));
		if(minus) N += rem;
		else N -= rem;
		dig *= 2;
		minus = !minus;
	}

	if(s.size()==0){
		s.push(0);
	}

	while(s.size()!=0){
		int p = s.top();
		s.pop();
		cout << p;
	}
	cout << endl;

	return 0;
}



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

int N;
vector<pair<ll,ll> > xy;
signed
main(){
	cin >> N;
	for(int i=0;i<N;i++){
		ll x,y;
		cin >> x >> y;
		xy.push_back(make_pair(x,y));
	}
	vector<vector<pair<ll,ll> > > z(N,vector<pair<ll,ll> >(N,make_pair(0,0) ) );
	for(int i=0;i<N;i++){
		for(int j=i+1;j<N;j++){
			z[i][j].first = xy[i].first - xy[j].first;
			z[i][j].second = xy[i].second - xy[j].second;
			z[j][i].first = xy[j].first - xy[i].first;
			z[j][i].second = xy[j].second - xy[i].second;
		}
	}
	
	int ans = 0;
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if(i==j){
				continue;
			}
			//cout << z[i][j].first << " " << z[i][j].second << endl;
			ll x = z[i][j].first;
			ll y = z[i][j].second;
			int cnt = 0;
			for(int k=0;k<N;k++){
				for(int l=0;l<N;l++){
					if(k==l) continue;
					if(x==z[k][l].first && y==z[k][l].second){
						cnt++;
					}
				}
			}
			ans = max(ans,cnt);
		}
		cout << endl;
	}
	cout << N-ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
#define prique priority_queue<ll>
#define ALL(a)  (a).begin(),(a).end()
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
long nCr(int n, int r) {
	int ans = 1;
	for (ll i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};
int n, m;
int a[50],b[50];
bool g[50][50];
bool v[50];
void dfs(int x) {
	v[x] = true;
	rep(i, n) {
		if (!g[x][i])continue;
		if (v[i])continue;
		dfs(i);
	}
}
signed main() {
	cin >> n >> m;
	rep(i, m) {
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
		g[a[i]][b[i]] = g[b[i]][a[i]] = true;
	}
	int ans = 0;
	rep(i, m) {
		g[a[i]][b[i]] = g[b[i]][a[i]] = false;
		rep(j, n)v[j] = false;
		dfs(0);
		bool bridge = false;
		rep(j, n)if (!v[j])bridge = true;
		if (bridge)ans += 1;
		g[a[i]][b[i]] = g[b[i]][a[i]] = true;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
/*
AtCoderBeginnerContest168
Problem C - : (Colon) / Colon
Time Limit: 2 sec / Memory Limit: 1024 MB
Score:
300
points
*/

#include <iostream>
#include <iomanip>
#include <cmath>

int main()
{
    double A, B, H, M;
    std::cin >> A >> B >> H >> M;

    double pi = 3.1415926535897932384626;
    H *= 60;
    H += M;
    double h = (pi/360.)*H;
    double m = (pi/30.)*M;
    double theta = m-h;
    double d = sqrt(A*A + B*B -2*A*B*cos(theta));
    std::cout << std::setprecision(12) << d << "\n";
}


Measured memory_bytes: 4156
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(){
    char str[] = "abcdefghijklmnopqrstuvwxyz";
    char str_input[26];
    int *str_num, flag = 0;
    str_num = (int *)malloc(sizeof(int) * strlen(str));
    for(int i = 0; i < strlen(str); i++) str_num[i] = 0;
    scanf("%s", &str_input);
    for(int i = 0; i < strlen(str_input); i++){
        for(int j = 0; j < strlen(str); j++){
            if(str[j] == str_input[i]) str_num[j]++;
            if(str_num[j] > 1){
                flag = 1;
                puts("no");
                break;
            }
        }
        if(flag) break;
    }
    if(flag == 0) puts("yes");
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<math.h>

int main(){
	double ansx=0,ansy=0;
	double lenge=0,way=0;
	double wbuf=0;
	while(1){
		scanf("%lf,%lf",&lenge,&wbuf);
		if(lenge==0){
			break;
		}
		
		ansx+=lenge*cos((way/180.0)*M_PI);
		ansy+=lenge*sin((way/180.0)*M_PI);
		way += wbuf;
	}
	printf("%d\n%d\n",(int)ansy,(int)ansx);
	return 0;
}

Measured memory_bytes: 632
#include <stdio.h>
#include <string.h>
using namespace std;
int m,n,i,j,k;
char a[60][60],b[60][60];
bool flg=false;
//char tmp[60];
int main(){
  scanf("%d %d",&n,&m);
  for (i=0;i<n;i++){
    scanf("%s",&a[i]);
  }
  for (i=0;i<m;i++){
    scanf("%s",&b[i]);
  }
  for (i=0;i<n-m+1;i++){
    for (j=0;j<n-m+1;j++){
      k=0;
      while(k<m*m && a[i+k/m][j+k%m]==b[k/m][k%m] ){
        k++;
      }
      if (k==m*m  ){flg=true;break;}
    }
    if (flg){break;}
  }
  if (flg){printf("%s\n","Yes");}
  else{printf("%s\n","No" );}
}


Measured memory_bytes: 128
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    k = i_input()

    if k % 2 == 0:
        print(-1)
        exit()

    tmp = 7
    count = 1        

    while count < 10 ** 6:
        tmp %= k
        if tmp == 0:
            print(count)
            exit()
        count += 1
        tmp = tmp * 10  + 7

    print(-1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 77168
#include <bits/stdc++.h>
#define ff { ios_base::sync_with_stdio(false);cin.tie(NULL);}
using namespace std;

typedef long long ll;
 ll  pp=1e9+7; 
double pi=3.141592653589793238;
  
 int main() {
        ff;
        ll n;
        cin>>n;
        ll v=7%n;
        ll f=0;
        for(int i=1;i<1000005;i++){
            if(v==0){
                f=1;
                cout<<i<<endl;
                break;
            }
            v=(v*10+7)%n;
        }
        if(f==0)cout<<"-1"<<endl;
        
		
    return 0;
}

            
		
        
           
  

Measured memory_bytes: 3620
input_line=input().split(" ")
N,K=int(input_line[0]),int(input_line[1])
P=input().split(" ")
cumsum=[0]
tol=0
for i in range(N):
    P[i]=(int(P[i])+1)/2
    tol=tol+P[i]
    cumsum.append(tol)
    
k_sum=[]

for i in range(N-K+1):
  k_sum.append(cumsum[i+K]-cumsum[i])  

ans=max(k_sum)
print(ans)


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

int N, M, Q;
vector<int> a;
vector<int> b;
vector<int> c;
vector<long long> d;

vector<int> v;
long long answer;

void dfs (vector<int> v) {

  if ((int) v.size() == N + 1) {
    long long ans = 0;
    for (int i = 0; i < Q; i++) {
      if ((v[b[i] - 1] - v[a[i] - 1]) == c[i]) {
        ans += d[i];
      }
    }
    answer = max(answer, ans);
    return;
  }

  v.push_back(v.back());
  while(v.back() <= M) {
    dfs(v);
    v.back()++;
  }

}

int main() {

  cin >> N >> M >> Q;

  a.resize(Q);
  b.resize(Q);
  c.resize(Q);
  d.resize(Q);

  for (int i = 0; i < Q; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }

  v.push_back(1);
  dfs(v);

  cout << answer << endl;

  return 0;
  
}

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

struct unionFind {
  vector<int> d;  // 根： 木のサイズ x -1, それ以外： 親のID
  unionFind(int n = 0) : d(n, -1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    // root化しておく
    x = find(x);
    y = find(y);
    if (x == y) return false;

    // x を y に unite
    // d[x] のほうが多きい（=サイズが小さい）場合はswap
    if (d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -d[find(x)]; }
} uf;

const int MAX_N = 1e4;
vector<edge> G;
int V, E;

void kruskal() {
  ll ans = 0;
  uf = unionFind(V);
  uf.d = vector<int>(V);
  rep(i, V) uf.d[i] = -1;
  sort(G.begin(), G.end());
  for (edge e : G) {
    int w = get<0>(e), s = get<1>(e), t = get<2>(e);
    if (!uf.same(s, t)) {
      uf.unite(s, t);
      ans += w;
    }
  }
  cout << ans << endl;
}

int main() {
  cin >> V;
  vector<P> xy(V);
  vector<P> yx(V);
  map<P, int> idx, idy;
  rep(i, V) {
    int x, y;
    cin >> x >> y;
    xy[i] = P(x, y);
    yx[i] = P(y, x);
    idx[xy[i]] = i;
    idy[yx[i]] = i;
  }

  // X軸Y軸でソートして隣り合った点だけが候補
  sort(xy.begin(), xy.end());
  sort(yx.begin(), yx.end());
  G = vector<edge>(V * 2);
  rep(i, V - 1) {
    int a = idx[xy[i]], b = idx[xy[i + 1]];
    G[i * 2] = edge(min(abs(xy[i].first - xy[i + 1].first),
                        abs(xy[i].second - xy[i + 1].second)),
                    a, b);
    int c = idy[yx[i]], d = idy[yx[i + 1]];
    G[i * 2 + 1] = edge(min(abs(yx[i].first - yx[i + 1].first),
                            abs(yx[i].second - yx[i + 1].second)),
                        c, d);
  }
  kruskal();
  return 0;
}

Measured memory_bytes: 17408
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define rrep(i,m,n) for(int i = m; i >= n; i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef struct{
    ll to;
    ll cost;
} edge;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll K;
    ll A[100010];
    cin >> K;
    rep(i,0,K){
        cin >> A[i];
    }
    ll lv = -1, rv = INF;
    while(rv - lv > 1){
        ll mid = (rv + lv)/2;
        ll v = mid;
        rep(i,0,K){
            v -= (v % A[i]);
            if(v < 0) v = 0;
        }
        
        if(v >= 2){
            rv = mid;
        }else{
            lv = mid;
        }
    }
    ll l1 = lv, r1 = rv;
    // print2(lv,rv);
    lv = -1, rv = INF;
    while(rv - lv > 1){
        ll mid = (rv + lv)/2;
        ll v = mid;
        rep(i,0,K){
            v -= (v % A[i]);
            if(v < 0) v = 0;
        }
        
        if(v >= 3){
            rv = mid;
        }else{
            lv = mid;
        }
    }
    ll l2 = lv, r2 = rv;
    if(r1 > l2){
        print("-1");
    }else{
        cout << r1 << " " << l2 << endl;
    }
    
    // bool ok = true;
    // rrep(i, K-2, 0){
    //     if(A[i] >= 2 * A[i+1]){
    //         ok = false;
    //     }
    // }
    // if(!ok){
    //     print("-1");
    //     return 0;
    // }
    // ll v1 = A[0];
    // ll v2 = A[1];
    // ll amari = v2 % v1;
    // if(amari == 0) amari = v1;
    // ll ans1 = v2 + (v1 - amari);
    // v2 *= 2;
    // amari = v2 % v1;
    // if(amari == 0) amari = v1;
    // ll ans2 = v2 + (v1 - amari) - 1;
    // cout << ans1 << " " << ans2 << endl;

    

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;

signed main() {
    int A, B;
    cin >> A >> B;

    int res = 0;
    FOR(i, A, B+1) {
        string s = to_string(i);
        string t = "";
        rep(i, 5) t += s[s.size()-1-i];
        if(s == t) res++;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <float.h>
#include <stdlib.h>
using namespace std;
int main(){
     int n,x,y;
     cin >> n >> x >> y;
     x=x-1;
     y=y-1;
        int a[n-1];
     for(int i=0;i<n-1;i++){
            a[i]=0;
     }
   
    
    for(int i=0;i<n;i++){     
        for(int j=1;j<n;j++){
            if(i<j){
            int l=min(j-i,abs(j-y)+abs(i-x)+1);
            a[l-1]=a[l-1]+1;
             
             }
    
             
         }   
     }
         
     
     for(int i=0;i<n-1;i++){
         cout << a[i] << endl;
     }


}


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

using namespace std;

typedef long long ll;

int main() {
  ll a, b;
  char op[5];
  scanf("%lld%s%lld", &a, op, &b);
  printf("%lld\n", op[0] == '-' ? a - b : a + b);
}


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

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

        public static void Solve()
        {
            var RGB = int.Parse(Console.ReadLine().Replace(" ", ""));
            Console.WriteLine(RGB % 4 == 0 ? "YES" : "NO");

        }
    }
}


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

int main(){
    long long n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    long long score = 0;

    for(long long i = 0; i < n; i++){
        if(s[i] == 'L' and s[i-1] == 'L' and i-1 >= 0){
            score++;
        }

        if(s[i] == 'R' and s[i+1] == 'R' and i+1 < n){
            score++;
        }

    }

    cout << min(score+2*k, n-1) << endl;
    return 0;
}

Measured memory_bytes: 3704
N, M = map(int, input().split())
H = list(map(int, input().split()))

import numpy as np
H_ = np.zeros(len(H))

A = []
B = []
for i in range(M):
    a, b = map(int, input().split())
    
    if H[a-1] > H[b-1]:
        H_[b-1] = 1
    elif H[a-1] < H[b-1]:
        H_[a-1] = 1
    elif H[a-1] == H[b-1]:
        H_[a-1] = 1
        H_[b-1] = 1
        
count = 0
for i in H_:
    if i == 0:
        count += 1
    
print(count)

Measured memory_bytes: 31704
n,k=map(int,input().split())
x=list(map(int,input().split()))
a=[]
for i in range(n-k+1):
  l=x[i]
  r=x[i+k-1]
  a.append(min(abs(l)+abs(r-l),abs(r)+abs(r-l)))
print(min(a))


Measured memory_bytes: 19956
#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 speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long 
#define ull unsigned long long
#define db double
#define vi vector<ll>
#define vvi vector<vector<int> >
#define vvii vector<vector<pii> >
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl "\n"
#define pii pair<ll,ll>
#define piii pair<ll,pair<ll,ll> >
#define mem(a,b) memset(a , b , sizeof a ) ; 
#define pb push_back
#define pf push_front
#define F first 
#define S second 
#define mp make_pair
#define all(v) v.begin(),v.end()

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}



#define deb1(a) cout<<#a<<"=*"<<a<<endl;
#define deb2(a) cout<<#a<<"=@"<<a<<endl;
#define deb3(a) cout<<#a<<"=#"<<a<<endl;
#define deb4(a,b) cout<<#a<<"="<<a<<" and "<<#b<<"="<<b<<endl;
#define deb5(a,b) cout<<#a<<"="<<a<<" and "<<#b<<"="<<b<<endl;


typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


ll mod=1000000007;
ll vis[212345]={0};
vvi v(212345);
ll d[212345]={0};


ll pow(ll a, ll b, ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}





int main()
{
speed
ll n,k;
cin>>n>>k;
priority_queue<ll,vector<ll> ,greater<ll> > pq;
rep(i,0,n)
{
	ll z;
	cin>>z;
	pq.push(z);
}
ll s=0;
rep(i,0,k)
{
	s+=pq.top();
	pq.pop();
}
cout<<s<<endl;
}



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

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

    cout << c << ' ' << a << ' ' << b << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
#include <stack>
 
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
 
string S;
ll N,M,ans;
ll A[169];
ll B[10001];
ll C[10001][169];
ll D[169];
ll E[10001];
ll F[10001];
ll now;
ll G[10001];

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll a = 1;
    while(n != 0){
        if(n&1) a = a*x % 1000000007;
        x = x*x % 1000000007;
        n = n >> 1;
    }
    return a;
}

 
 
int main(){
    cin >> N;
    M = sqrt(1000001);
    ll m = 0;
    for(int i = 2;i<M;i++){
        bool found = false;
        for(int j = 0;j<m;j++){
            if(i%A[j]==0){
                found = true;
                break;
            }
        }
        if(!found){
            A[m] = i;
            m++;
        }
    }
    
    for(int i = 0;i<N;i++){
        cin >> B[i];
    }
    for(int i = 0;i<m;i++){
        ll s = 0;
        for(int j = 0;j<N;j++){
            ll t = 0;
            while(B[j]%A[i] == 0){
                t++;
                B[j]/=A[i];
            }
            C[j][i] = t;
            if(t > s) s = t;
        }
        D[i] = s;
    }
    for(int i = 0;i<N;i++) G[i] = B[i];
    sort(G,G+N);
    now = 1;
    ll s = 0;
    for(int i=0;i<N;i++){
        if(G[i]!=now){
            E[s] = G[i];
            now = E[s];
            s++;
        }
    }
    
    for(int i = 0;i<N;i++){
        
        ll ansl = 1;
        for(int j = 0;j<m;j++){
            ansl = (ansl * mpow(A[j],D[j]-C[i][j]))%1000000007;
        }
        
        
        for(int j=0;j<s;j++){
            if(E[j]!=B[i]){
                ansl = (ansl*E[j])%1000000007;
            }
        }
        ans = (ans + ansl)%1000000007;
    }
    cout << ans << endl;
    
}



Measured memory_bytes: 13696
#include <algorithm>
#include <cstdio>
using namespace std;
int main() {
  int n, ans = 0;
  scanf("%d", &n);
  if (n >= 99999) {
    ans += 90000;
  } else {
    ans += max(0, n - 9999);
  }
  if (n >= 999) {
    ans += 900;
  } else {
    ans += max(0, n - 99);
  }
  if (n >= 9) {
    ans += 9;
  } else {
    ans += n;
  }
  printf("%d\n", ans);
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{
    public static void main(String[] args) throws IOException
    {
        int ans = 0;
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);

        String str = null;

        str = br.readLine();

        int r = Integer.parseInt(str);

        ans = r*r;

        System.out.println(ans);
    }

}

Measured memory_bytes: 22612
#include <cstdio>           // printf(), scanf()
#include <set>
#include <iterator>         // distance()
#include <algorithm>        // swap(), sort(), lower_bound(), upper_bound()

using namespace std;
static const int MAX_N = 100000;
enum { BOTTOM = 0, LEFT, RIGHT, TOP };

struct Point
{
	int x;
	int y;
};

struct Segment
{
	Point p1, p2;
};

class EndPoint
{
public:
	Point p;
	int seg; // ??\????????????ID
	int st;  // ??????????¨????

	EndPoint() {}
	EndPoint(Point p, int seg, int st): p(p), seg(seg), st(st) {}
	bool operator < (const EndPoint &ep) const
	{
		// y ??§?¨?????°???????????????´???
		if (p.y != ep.p.y)
			return p.y < ep.p.y;
		else
			return st < ep.st; // y ??????????????´????????????????????????????????????????????????????????????????????????
	}
};

Segment S[MAX_N];
EndPoint EP[2 * MAX_N]; // ??????????????????
int n;

// ??????????????????: ????????????????????????
int
manhattanIntersection()
{
	int k = 0;
	for (int i = 0; i < n; ++i)
	{
		// ?????? p1,p2 ??????????????????????????¶??????????????´
		if (S[i].p1.y == S[i].p2.y)
		{
			if (S[i].p1.x > S[i].p2.x)
				swap(S[i].p1, S[i].p2);
		}

		else if (S[i].p1.y > S[i].p2.y)
			swap(S[i].p1, S[i].p2);

		if (S[i].p1.y == S[i].p2.y) // ?°´????????????????????????????????????
			EP[k++] = EndPoint(S[i].p1, i, LEFT);

		else // ?????´?????????????????????????????????
		{
			EP[k++] = EndPoint(S[i].p1, i, BOTTOM);
			EP[k++] = EndPoint(S[i].p2, i, TOP);
		}
	}

	sort(EP, EP + k); // ????????? y ??§?¨??????¢?????????????????´???

	set<int> BT; // ????????¢?????¨
	BT.insert(1000000001); // ??????????¨????

	int cnt = 0;
	for (int i = 0; i < k; ++i)
	{
		if (EP[i].st == TOP)
			BT.erase(EP[i].p.x); // ??????????????????
		else if (EP[i].st == BOTTOM)
			BT.insert(EP[i].p.x); // ??????????????????
		else if (EP[i].st == LEFT)
		{
			set<int>::iterator b = BT.lower_bound(S[EP[i].seg].p1.x); // O(log n)
			set<int>::iterator e = BT.upper_bound(S[EP[i].seg].p2.x); // O(log n)
			cnt += distance(b, e); // b ??¨ e ????????¢(????????°)????????????O(k)
		}
	}

	return cnt;
}

int
main(int argc, char** argv)
{
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%d %d %d %d", &S[i].p1.x, &S[i].p1.y, &S[i].p2.x, &S[i].p2.y);

	printf("%d\n", manhattanIntersection());
	return 0;
}

Measured memory_bytes: 10088
//NAME-DEEPESH BHATT
//Institute-IIT Dhanbad
//MOTTO-THINK FIRST,CODE LATER

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1000000007  ;
/*#define endl '\n'*/
#define pb push_back
#define mp make_pair

//Check for signed int overflow
// use __builtin_popcount(num) to calculate no.of setbits in num
//s.lower_bound() works in O(logn) whereas lower_bound(s.begin(),s.end(),x) works in O(n)
//      if(!lazy)
//         solve 1600+(rating) problems in codeforces.
//      else
//         solve 1400+(rating) problems in codeforces.

ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll lcm(ll a ,ll b)
{
    return a/gcd(a,b)*b;
}
/*ll power(ll a,ll n){
    if (n == 0)
        return 1;
    ll p = power(a, n / 2);
    p = (p * p)%MOD;
    if (n % 2)
        return (p * a)%MOD;
    else
        return p%MOD;
}*/

long double dp[301][301][301];

int32_t main()
{
    /*freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);*/
    ios_base::sync_with_stdio(false);    //for fast I/O operation
    cin.tie(nullptr);
    ll test=1;
    /*cin>>test;*/
    while(test--){
        ll n;
        cin>>n;
        int cnt[4]={0};
        for(ll i=0;i<n;i++){
            ll x;
            cin>>x;
            cnt[x]++;
        }
        dp[0][0][0]=0;
        //dp[x][y][z] is E.V of x->3s,y->2s,z->1s,n-x-y-z->0s
        //dp[x][y][z]=1+p3(dp[x-1][y+1][z])+p2(dp[x][y-1][z+1]+p1(dp[x][y][z-1])+p0(dp[x][y][z]));
        //dp[x][y][z]=(1+p3(dp[x-1][y+1][z])+p2(dp[x][y-1][z+1]+p1(dp[x][y][z-1]))/(1-p0);
        for(ll x=0;x<=n;x++){
            for(ll y=0;y<=n;y++){
                for(ll z=0;z<=n;z++){
                    if(x+y+z>n){
                        /*cout<<dp[x][y][z]<<" ";*/
                        continue;
                    }
                    long double p3=(long double)(x)/(n);
                    long double p2=(long double)(y)/(n);
                    long double p1=(long double)(z)/n;
                    long double p0=(long double)(n-x-y-z)/(n);
                    if(x>0||y>0||z>0)
                        dp[x][y][z]=1;
                    if(x>0){
                        dp[x][y][z]+=p3*(dp[x-1][y+1][z]);
                    }
                    if(y>0){
                        dp[x][y][z]+=p2*(dp[x][y-1][z+1]);
                    }
                    if(z>0){
                        dp[x][y][z]+=p1*(dp[x][y][z-1]);
                    }
                    if(x+y+z!=0)
                        dp[x][y][z]/=(1-p0);
                    /*cout<<dp[x][y][z]<<" ";*/
                }
            }
        }
        /*cout<<endl<<cnt[3]<<" "<<cnt[2]<<" "<<cnt[1]<<endl;*/
        cout<<setprecision(9)<<fixed<<dp[cnt[3]][cnt[2]][cnt[1]];
    }
    return 0;
}


Measured memory_bytes: 212824