akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

typedef long long ll;

const int INF = 2e9 + 5;
const int alength=100100;

int main() {
	int h,w;
	bool f[60][60]={};
	cin>>h>>w;
	fori(h){
		string s;cin>>s;
		forj(w){
			f[i][j]=(s[j]=='#');
		}	
	}

	fori(h){
		forj(w){
			if(f[i][j]){
				cout<<'#';
				continue;
			}
			int ans=0;
			bool a,b,c,d;
			a=i==0;b=(i==h-1);c=j==0;d=(j==w-1);
			//上段
			if(!a){
				if(!c){
					ans+=f[i-1][j-1];
				}
				ans+=f[i-1][j];
				if(!d){
					ans+=f[i-1][j+1];
				}
			}
			//中段
			if(!c){
				ans+=f[i][j-1];
			}
			if(!d){
				ans+=f[i][j+1];
			}
			//下段
			if(!b){
				if(!c){
					ans+=f[i+1][j-1];
				}
				ans+=f[i+1][j];
				if(!d){
					ans+=f[i+1][j+1];
				}
			}
			cout<<ans;
		}
		cout<<'\n';
	}
}

Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        var s = Console.ReadLine().Trim();
        var cp = s.IndexOf('C');
        var fp = s.LastIndexOf('F');
        Console.WriteLine(cp < fp && cp >= 0 && fp >= 0 ? "Yes" : "No");
    }
}


Measured memory_bytes: 13140
import numpy as np

N = int(input())
dp = np.zeros((N+1, 3))  # （i日目にa, b, cを行って）i日目までに得られる幸福度の最大値
"""
i日目にaを選んだ場合
dp[i, 0] = max(dp[i-1, 1], dp[i-1, 2]) + a
i日目にbを選んだ場合
dp[i, 1] = max(dp[i-1, 0], dp[i-1, 2]) + b
i-1日目にcを選んだ場合
dp[i, 2] = max(dp[i-1, 0], dp[i-1, 1]) + c
"""

for i in range(1, N+1):
    a, b, c = map(int, input().split())
    dp[i, 0] = max(dp[i-1, 1], dp[i-1, 2]) + a
    dp[i, 1] = max(dp[i-1, 0], dp[i-1, 2]) + b
    dp[i, 2] = max(dp[i-1, 0], dp[i-1, 1]) + c

print(int(max(dp[-1, :])))


Measured memory_bytes: 15928
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,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;
}

void Main()
{
  i64 N;
  cin >> N;
  vvi A(N, vi(3));
  cin >> A;

  vvi dp(N, vi(3, 0));
  dp[0][0] = A[0][0];
  dp[0][1] = A[0][1];
  dp[0][2] = A[0][2];

  rep(i,1,N){
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + A[i][0];
    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + A[i][1];
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + A[i][2];
  }

  sort(rng(dp[N-1]));

  cout << dp[N-1][2] << "\n";
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}

Measured memory_bytes: 11264
N, K = map(int,input().split())

Map = list(map(int,input().split()))

Visited = [-1]*N
now = 1
Order = [0]*N

loopcount = 1
Order[0] = 1
Visited[0] = 1
for i in range(1,N):
    nt = Map[now-1]
    Order[i] = nt
    loopcount += 1
    if Visited[nt-1] == -1:
        Visited[nt-1] = loopcount
    else:
        break
    now = nt
    

ns = Visited[nt-1]
period = loopcount - ns

if period == 0:
    period = loopcount
    ns = 0

Kmod = K - ns
if Kmod > 0:
    Kmod %= period

print(Order[ns+Kmod])




Measured memory_bytes: 32400
#include<iostream>
#include<algorithm>
#include<vector>
#include <utility>
using namespace std;

vector<pair<int,int>> group;
int main(){
    string s;
    int k,n,ans=0;
    cin>>n>>k>>s;
    
    for(int i=0;i<n;){
        char k=s[i];
        int c=0;
        while(1){
            c++;
            if(s[i]==k)
                i++;
            else
                break;
        }
        //cout<<i<<' '<<c<<'\n';
        group.push_back({k-'0',c-1});
    }
    int cur=0,m=k;
    for(int i=0;i<group.size();i++){
        if(group[i].first==0){
            cur+=group[i].second;
            if(m==0){
                if(i-2*k>=0)
                    cur-=group[i-2*k].second;
                if(i-2*k-1>=0)
                    cur-=group[i-2*k-1].second;
                m++;
            }
            m--;
            
        }else{
            cur+=group[i].second;
        }
        ans=max(ans,cur);
    }
    printf("%d",ans);
    
}


Measured memory_bytes: 1528
fn main() {
    let buf = io::read_string();
    let mut sc = io::Scanner::new(&buf);
    let n: usize = sc.read();
    let a: Vec<usize> = sc.read_vec(n);

    let mut res = 0;
    for i in 0..n {
        res += a[i] - 1;
    }
    println!("{}", res);
}

#[allow(dead_code)]
mod io {
    use std;
    use std::io::Read;
    use std::str::{FromStr, SplitWhitespace};
    pub struct Scanner<'a> {
        pub iter: SplitWhitespace<'a>,
    }
    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }
        pub fn read<T: FromStr>(&mut self) -> T {
            self.iter
                .next()
                .unwrap()
                .parse()
                .ok()
                .expect("parsing failed")
        }
        pub fn read_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.read()).collect()
        }
    }
    pub fn read_string() -> String {
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
 
#define ll long long
#define ii pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pi 3.14159265
#define oo 1000000007
#define loo 1000000000000000007
 
using namespace std;
#define prime 1000000007
 
#define W(x) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << "\n";

ll v[2001],n;
ii p[2001];

bool f(ii a, ii b){
	return a.ff < b.ff;
}

int main(){
	cin >> n;
	for (int i = 0; i < n; ++i){
		cin >> v[i];
	}
	sort(v, v+n);
	for (int i = 0; i < n; ++i){
		p[i] = {v[i], i};
	}
	p[n] = {prime, n};
	ll ans = 0;
	for (int i = 0; i < n; ++i){
		for (int j = i+1; j < n; ++j){
			ii tmp = mp(p[i].ff+p[j].ff, (ll)-1);
			ii *aux = lower_bound(p+j+1, p+n+1, tmp, f);
			//if(aux->ss != j){
				ans+=aux->ss-p[j].ss-1;
			//}
		}
	}

	cout << ans << endl;

	return 0;	
}


Measured memory_bytes: 256
N = int(input())

count = 0
if N < 10:
    count = N
elif 10 <= N < 100:
    count = 9
elif 100 <= N < 1000:
    count += 9
    count += N - 99
elif 1000 <= N < 10000:
    count += 999 - 99 + 9
elif 10000 <= N < 100000:
    count += 999 - 99 + 9
    count += N - 9999
else:
    # N == 100000
    count = 99999 - 9999 + 999 - 99 + 9

print(count)


Measured memory_bytes: 3060
import sys
input=sys.stdin.readline
n=int(input())
G=[[] for i in range(n)]
for i in range(n-1):
    a,b,c=map(int,input().split())
    G[a-1].append((b-1,c))
    G[b-1].append((a-1,c))
q,k=map(int,input().split())
k=k-1
stack=[k]
dis=[-1]*n
dis[k]=0
while len(stack)>0:
    now=stack.pop()
    d=dis[now]
    for i in G[now]:
        if dis[i[0]]==-1:
            dis[i[0]]=d+i[1]
            stack.append(i[0])
for i in range(q):
    x,y=map(int,input().split())
    x=x-1
    y=y-1
    print(dis[x]+dis[y])



Measured memory_bytes: 70284
#pragma region header
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define ts to_string
#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vs vector <string>
#define vvs vector <vector<string>>
#define pq  priority_queue<int>
using ll = long long;
/* ----------------よく使う数字や配列----------------- */
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
const int INF = 2000000000;
const int MINF=-2000000000;
constexpr ll mod = 1e9 + 7;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */
/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if (b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
bool isprime(ll a)//素数判定、primeならtrue,違うならfalse
{
    if (a < 2) return false;
    else if (a == 2) return true;
    else if (a % 2 == 0) return false;
    double m = sqrt(a);
    for (int i = 3; i <= m; i += 2)
    {
        if (a % i == 0)
        {
            return false;
        }
    }
    // 素数である
    return true;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
ll kind(vi SYURUI) {//vector<int>型の配列の要素の種類数
    int size = SYURUI.size();
    sort(all(SYURUI));
    int cnt = 1;
    rep(i, size-1) {
        if (SYURUI[i] != SYURUI[i + 1])cnt++;
    }
    return cnt;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int N, X; cin >> N >> X;
    vi L(N); rep(i, N)cin >> L[i];
    int ans = 0;
    int cnt = 1;
    rep(i, N) {
        ans += L[i];
        if (ans > X)break;
        else cnt++;
    }
    cout << cnt << endl;
}



Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
using namespace std;

int main() {
  string s;
  cin >> s;
if(s.length()==2){
  cout << s << endl;
}else{
  reverse(s.begin(),s.end());
  cout << s << endl;
}
}


Measured memory_bytes: 256
import heapq
N, M = [int(i) for i in input().split()]
zaiko={}
value = []
heapq.heapify(value)
for i in range(N):
    #在庫の本数。一本あたりの代金
    b,a=[int(i)for i in input().split()]
    if  b not in zaiko:
        heapq.heappush(value,b)
        zaiko[b]=a
    else:
        zaiko[b]+=a

cnt=0
sumval=0
while True:
    if cnt == M: 
       print(sumval)
       exit()
    minival = heapq.heappop(value)
    minicnt = zaiko[minival]
    #print("minival,minicnt={},{}".format(minival,minicnt))
    if cnt + minicnt <= M:
       cnt+=minicnt
       sumval += minival * minicnt
    else:
       sumval += minival * (M-cnt)
       cnt=M

Measured memory_bytes: 18568
#include <iostream>

using namespace std;

int main() {
    int i;
    int c1, c2, c3;
    int count;
    int sum = 0;

    while (cin >> c1 >> c2 >> c3) {
        count = 0;
        for(i = 1; i < 11; i++) {
            if (c1 == i || c2 == i) {
                continue;
            } else if (c1 + c2 + i <= 20) {
                count++;
            }
        }

        if ((double)count/7.0 >= 0.5) {
            cout<<"YES"<<endl;
        } else {
            cout<<"NO"<<endl;
        }
    }
    return(0);
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n; cin >> n;
    string s; cin >> s;
    vector<int> r,g,b;
    REP(i,n) {
        if (s[i] == 'R') r.push_back(i);
        else if (s[i] == 'G') g.push_back(i);
        else b.push_back(i);
    }
    ll ans = 0;
    if (b.size() == 0) {
        OUT(0)
        return 0;
    }
    for (auto i:r) {
        for (auto j:g) {
            //if (i > j) swap(i,j);
            int d = j-i;
            int bs = b.size();
            auto it1 = lower_bound(ALL(b),i-d);
            if (*it1  == i-d) bs--;
            auto it2 = lower_bound(ALL(b),j+d);
            if (*it2 == j+d )bs--;
            if (d % 2 == 0) {
                auto it3 = lower_bound(ALL(b),i+d/2);                
                if (*it3 == i+d/2) bs--;
            }
            ans += bs;
        }
    }

    cout << ans << '\n';

    return 0;
}


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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

int f(int X) {
  int res = 0;
  while (X > 10) {
    res += X % 10;
    X /= 10;
  }
  return res + X;
}

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

  CIN(X);
  OK(X % f(X) == 0);

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
vector<ll> vec;
vector<ll> check;
ll dfs1(ll from,ll to){
  check.at(from-1)=54;
  if(check.at(to-1)==54){return to;}
  dfs1(to,vec.at(to-1));
}
ll dfs2(ll from,ll to,ll count){
  count++;
  check.at(from-1)=69;
  if(check.at(to-1)==69){return count;}
  dfs2(to,vec.at(to-1),count);
}
ll dfs3(ll from,ll to,ll cc){
  cc++;
  check.at(from-1)=5;
  if(check.at(to-1)==5){return cc;}
  dfs3(to,vec.at(to-1),cc);
}
int main() {
  ll N,K,answer;
  cin>>N>>K;
  vec.resize(N);
  check.resize(N);
  for(ll i=0;i<N;i++){
    cin>>vec.at(i);
  }
  ll a=dfs1(1,vec.at(0));
  ll b=dfs2(1,vec.at(0),0);
  ll c=dfs3(a,vec.at(a-1),0);
  K-=b-c;
  if(K==0){
    cout<<a<<endl;
    return 0;
  }
  if(K<0){
    K+=b-c;
    if(K==0){
      cout<<1<<endl;
      return 0;
    }
    answer=1;
    for(ll i=0;i<K;i++){
      answer=vec.at(answer-1);
    }
    cout<<answer<<endl;
    return 0;
  }
  ll ans=K%c;
  answer=a;
  if(ans==0){ans+=c;}
  for(ll i=0;i<ans;i++){
    answer=vec.at(answer-1);
  }
  cout<<answer<<endl;
}

Measured memory_bytes: 9476
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PI 3.1415926535897932384626433832795
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
long long MOD = 1e9+7;
pair<int,int> dx[4] = {{1,0},{-1,0},{0,1},{0,-1}};
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct chash {
    int operator()(int x) const { return x ^ RANDOM; }
};
string toString(long long x)
{
stringstream ss;
ss << x;
string str = ss.str();
return str;
}
long long fastpow(long long x,long long k)
{
    if(!k)
        return 1;
    if(k & 1)
        return ((x * fastpow(x,k-1) % MOD) % MOD) % MOD;
    long long ans = fastpow(x,k/2);
    ans %= MOD;
    ans *= ans;
    ans %= MOD;
    return ans;
}
long long sumF(long long x)
{
    int s = 0;
    while(x)
        s += x%10,x /= 10;
    return s;
}
int Freq[5];
int main()
{
    IO;
    for(int i = 1;i <= 6;i++)
    {
        int x;
        cin >> x;
        Freq[x]++;
    }
    for(int i = 1;i <= 4;i++)
    {
        if(Freq[i] >= 3)
        {
            cout << "NO";
            return 0;
        }
    }
    cout << "YES";


    return 0;
}


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

int main() {
	int N; cin >> N;
	vector<int> A(N);
	vector<int> B(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		B[i] = A[i];
	}

	sort(B.begin(), B.end());
	for (int i = 0; i < N; i++) {
		if (A[i] != B[N - 1]) cout << B[N - 1] << endl;
		else cout << B[N - 2] << endl;
	}
}

Measured memory_bytes: 3200
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int num[]={0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
string s[10010];

int main(){
	int n, m;
	cin >> n >> m;
	int a[m];
	for(int i=0; i<m; i++) cin >> a[i];
	for(int i=0; i<=1010; i++) s[i]="0";
	s[0]="";
	
	for(int i=1; i<=n; i++){
		for(int j=0; j<m; j++){
			int k=i-num[a[j]];
			if(k<0) continue;
			if(s[k]=="0") continue;
 
			string t=s[k]+to_string(a[j]);
			if(s[i]=="") s[i]=t;
			else if(s[i].length()==t.length()){
				s[i]=max(s[i], t);
			}else if(s[i].length()<t.length()){
				s[i]=t;
			}
		}
	}
	cout << s[n] << endl;
	return 0;
}

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

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

            int[] p = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            //数字が昇順に並んだ配列
            int[] A = Enumerable.Range(1, N).ToArray();

            //順列の数列と異なる数字の場所の個所を記録する
            int ans = 0;

            for (int i = 0; i < N; i++) {
                if (p[i] != A[i]) {
                    ans++;
                }
            }

            if (ans == 0 || ans == 2) {
                Console.WriteLine("YES");
            } else {
                Console.WriteLine("NO");
            }
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define int long long
#define N 1000
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}

#define rank Asdfiasofsad
class UF{
public:
  int V;
  vector<int> par,rank;
  UF(){}
  UF(int V):V(V),par(V),rank(V,0){for(int i=0;i<V;i++)par[i]=i;}
  
  int find(int x){
    assert(x < V);
    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(rank[x]<rank[y])par[x]=y;
    else{
      par[y]=x;
      if(rank[x]==rank[y])rank[x]++;
    }
  }

  bool same(int x,int y){return find(x)==find(y);}
};

int n,m;
vector<int> G[N];

int used[N];
int dfs(int pos){
  if(used[pos]++) return 0;
  int res = G[pos].size() - 1;
  for(int to:G[pos]) res += dfs(to);
  return res;
}

signed main(){
  cin>>n>>m;
  UF uf(n);
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b; a--,b--;
    G[a].push_back(b);
    uf.unite(a,b);
  }
  
  map<int,int> val;
  for(int i=0;i<n;i++){
    memset(used,0,sizeof(used));
    int v = dfs(i);
    if(val.count(uf.find(i))) Min(val[uf.find(i)],v);
    else val[uf.find(i)] = v;
  }

  int sum = 0;
  typedef pair<int,int> P;
  for(P p:val) sum += p.second+1;
  cout<<sum<<endl;
  
  return 0;
}

Measured memory_bytes: 3224
N,M,K = gets.split.map(&:to_i)

友達,ブロック = [M,K].map{|k|
	r = Array.new(N){ [] }
	k.times{
		a,b = gets.split.map(&:to_i)
		r[a-1] << b-1
		r[b-1] << a-1
	}
	next r
}

友達の輪 = [nil]*N
F = lambda{|n|
	友達の輪[n] ||= n
	友達[n].select{|m|
		友達の輪[m] = 友達の輪[n] unless 友達の輪[m]
	}.each(&F)
}
N.times(&F)
輪の大きさ = 友達の輪.tally

puts N.times.map{|n|
	輪の大きさ[友達の輪[n]] - 1 - 友達[n].size - ブロック[n].count{|m| 友達の輪[m] == 友達の輪[n] }
}.join(' ')


Measured memory_bytes: 54116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define REP(i, n) for(int i=0; i<n; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
using P = pair<int, int>;
const int inf = 1e9;
const ll INF = 1e18;
const ll MOD = 1e9+7;
const ll MAX = 1e9+7;

struct edge{
    int to;
    int cost;
};
using graph = vector<vector<edge>>;

int main(){
  int n; cin >> n;
  vector<int> x;
  vector<int> y;
  vector<int> city_arange;
  int tmp1, tmp2;
  REP(i, n){
    cin >> tmp1 >> tmp2;
    x.push_back(tmp1);
    y.push_back(tmp2);
    city_arange.push_back(i);
  }
  double ans = 0;
  int num_ways = 0;
  do {
    // 拡張for文を利用してもよい.
    for(int i=0; i<city_arange.size()-1; i++){
      int cur_city = city_arange[i];
      int next_city = city_arange[i+1];
      ans += (double)sqrt(pow(x[next_city]-x[cur_city], 2)+pow(y[next_city]-y[cur_city], 2));
    }
    num_ways++;
  } while (next_permutation(city_arange.begin(), city_arange.end()));
  ans /= num_ways;
  cout << setprecision(11) << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n, c, k; cin >> n >> c >> k;
	vi t(n); rep(i, n) cin >> t[i];
	sort(all(t));
	
	int lim = 0, cnt = 0, ans = 0;
	rep(i, n){
		if(lim < t[i] || cnt == c){
			cnt = 0;
		}
		if(cnt == 0){
			lim = t[i] + k;
			ans++;
		}
		cnt++;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i = 0;i < n;i++)
#define PRN(n) printf("%d\n",n)
#define PRS(s) printf("%s\n",s)
typedef long long int llint;
int max(int a,int b){
  if(a > b)return a;
  return b;
}
int min(int a,int b){
  if(a > b)return b;
  return a;
}
int zet(int a){
  if(a < 0)return -a;
  return a;
}
int main(void){
  llint n;
  scanf("%d",&n);
  llint a = n,ans = 0;
  while(a > 0){
    ans += a % 10;
    a /= 10;
  }
  if(n % ans){
    PRS("No");
  }else{
    PRS("Yes");
  }
  return 0;
}

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

const int N = 2e5 + 10;
const long long INF = 1e18;

int a[N];
long long sum[N];
long long ans;
int n;

void update(int pos, int d1, int d2){
	long long maxx, minx;
	maxx = max(sum[d1], sum[pos] - sum[d1]);
	maxx = max(maxx, sum[d2] - sum[pos]);
	maxx = max(maxx, sum[n] - sum[d2]);
	minx = min(sum[d1], sum[pos] - sum[d1]);
	minx = min(minx, sum[d2] - sum[pos]);
	minx = min(minx, sum[n] - sum[d2]);
	ans = min(ans, maxx - minx);
}

int main(){
	int d1, d2;
	scanf("%d",&n);
	for (int i = 1; i <= n; i++) scanf("%d",&a[i]);
	sum[0] = 0;
	for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];
	ans = INF;
	for (int i = 2; i <= n - 2; i++){
		d1 = lower_bound(sum + 1, sum + i + 1, sum[i] / 2) - sum;
		d2 = lower_bound(sum + i + 2, sum + n + 1, (sum[n] + sum[i]) / 2) - sum;
		if (d1 > 1 && d2 > i) update(i, d1 - 1, d2 - 1);
		if (d1 > 1 && d2 < n) update(i, d1 - 1, d2);
		if (d1 < i && d2 > i) update(i, d1, d2 - 1);
		if (d1 < i && d2 < n) update(i, d1, d2);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 2560
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <queue>
#include <iostream>
#include <cmath>

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
typedef long long ll;
using namespace std;


void solve(int N, std::vector<long double> A) {
    long double res = 1;
    REP(i, N) { 
        if (A[i] == 0) { 
            cout << 0 << endl;
            return;
        }
    }

    REP(i, N) { 
        res *= A[i];
        // cout << res << endl;
        if (res > (long double)1e18) { 
            cout << -1 << endl;
            return ;
        }
    }
    cout << (long long)res << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    int N;
    scanf("%d",&N);
    std::vector<long double> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%Lf",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 4872
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)                  cerr<<#x<<": "<<x<<endl
#define trace2(x, y)              cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)              cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)          cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)     cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}

ll n,m;
ll a[51],b[51],c[51],d[51];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    rep(i,0,n){
        cin >> a[i] >> b[i];
    }
    rep(i,0,m){
        cin >> c[i] >> d[i];
    }
    ll ans[n];
    for(ll i=0; i<n; i++){
        ll mini=inf;
        for(ll j=0; j<m; j++){
            ll x=abs(a[i]-c[j])+abs(b[i]-d[j]);
            if(x<mini){
                mini=x;
                ans[i]=j+1;
            }
        }
    }
    for(ll i=0; i<n; i++) cout << ans[i] << "\n";
    return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
import math

def main():
    N,A,B = map(int,input().split())
    h = [int(input()) for _ in range(N)]
    left = 0
    right = math.ceil(max(h)/B)
    while right-left > 1:
        do = math.ceil((left+right)/2)
        count = 0
        for i in h:
            if i > do*B:
                count += math.ceil((i-do*B)/(A-B))
        if count > do:
            left = do
        else:
            right = do

    print(right)

if __name__ == "__main__":
    main()

Measured memory_bytes: 7052
n=int(input())
l=[]
for _ in range(n):
  l.append(int(input()))
m=max(l)
mc=l.count(m)
tin=set(l)
if len(tin)==1:
  s=m
else:
  s=sorted(tin)[-2]
for i in l:
  if i==m:
    if mc>1:
      print(m)
    else:
      print(s)
  else:
    print(m)


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

int main()
{
	long a, b, c, x, y, m;

	cin >> a >> b >> c >> x >> y;

	m = a * x + b * y;

	if (c * 2 <= a + b) {
		m -= (a + b - c * 2) * min(x, y);
		m = min(m, 2 * c * max(x, y));
	}

	cout << m << endl;

	return 0;
}

Measured memory_bytes: 256
N = input()

from collections import Counter

counter = Counter(N)
answer = float("inf")

for c in counter:

    margin = 0

    items = list(N.split(c))
    first = items.pop(0)
    last = items.pop()
    margin = max(len(first), len(last))

    for item in items:
        margin = max(margin, len(item))

    answer = min(answer, margin)

print(answer)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
    #define rep(i,n) for(int i=0;i<(int)(n);++i)
    #define repone(i,n) for(int i=1;i<(int)(n);++i)

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

    #define int long long

    using namespace std;

    signed main()
    {
        int x=0,y=0,z=0,w,i,j;
        cin>>x>>y>>z;
      if(x>y&&x>z){
              cout<<y*z/2<<endl;
      }else if(y>x&&y>z){
      cout<<x*z/2;
      }else{
      cout<<x*y/2;
      }


        return 0;
    }


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int L,LP,R,RP;
	
	cin>>L>>LP>>R>>RP;
	if((L+LP)==(R+RP)) cout<<"Balanced";
	else if((L+LP)>(R+RP)) cout<<"Left";
	else cout<<"Right";
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    final int N = sc.nextInt();
    final int K = sc.nextInt();
    int S[] = new int[N];
    for(int i=0;i<K;i++) {
    	int d = sc.nextInt();
    	for(int j=0;j<d;j++) {
    		int a = sc.nextInt();
    		S[a-1]++;
    	}
    }
    sc.close();
    int ans = 0;
    for(int a : S) {
    	if(a==0) {
    		ans++;
    	}
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 46160
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()
#define MOD 1000000007

vector<int> prime = {2};
ll fact[1100001], fact_i[1100001];

ll power(int x, int y) {
    if (y == 1) return x;
    ll p = power(x, y >> 1);
    if (y & 1) return p * p % MOD * x % MOD;
    else return p * p % MOD;
}

ll inv(ll n) {
    return power(n, MOD - 2);
}

ll nCr(ll n, ll r) {
    return fact[n] * fact_i[r] % MOD * fact_i[n - r] % MOD;
}

void init(int n) {
    fact[0] = 1;
    REP(i, n) fact[i + 1] = fact[i] * (i + 1) % MOD;
    fact_i[n] = inv(fact[n]);
    REP(i, n) fact_i[n - i - 1] = fact_i[n - i] * (n - i) % MOD;

    for (int i = 3; i * i <= 1000000000; i++) {
        bool ok = true;
        for (int p : prime) ok &= i % p != 0;
        if (ok) prime.push_back(i);
    }
}

vector<int> factor_counts(int n) {
    map<int, int> m;
    for (int p : prime) {
        while (n % p == 0) {
            m[p]++;
            n /= p;
        }
    }
    if (n != 1) m[n]++;

    vector<int> ret;
    for (auto p : m) ret.push_back(p.second);
    return ret;
}

int main() {
    init(110000);
    int N, M;
    cin >> N >> M;
    ll ans = 1;
    for (int fc : factor_counts(M)) {
        ans *= nCr(fc + N - 1, fc);
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3200
//header{{{
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
 
#include <boost/sort/spreadsort/spreadsort.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
//#include <boost/graph/graph_utility.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
#include <ext/pb_ds/trie_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
//using namespace boost::multiprecision;
//using namespace boost::math;
 
typedef boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS,
        boost::no_property, boost::property<boost::edge_weight_t, int> > Graph;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define bsort boost::sort::spreadsort::spreadsort
#define int int_fast64_t
using pii = pair<int,int>;
 
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;
template <class Func>
 
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}
 
    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};
 
template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
 
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
 
template <typename T> using Set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename K, typename V> using Umap = gp_hash_table<K, V>;
using Trie = trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update>;
  
inline int square(int a){ return a * a;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }
 
constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
constexpr int dy[] = {0,-1,0,1,1,-1,-1,1};
 
struct negrightshift {
    inline int operator() (const int &x, const unsigned offset) {
        return -(x >> offset);
    }
};
//}}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	umap<string,int> mp;
    mp.reserve(n);
	int sum = 0;
	rep(i,n){
		string s;
		cin >> s;
		bsort(all(s));
		++mp[s];
		sum += mp[s]-1;
	}
	cout << sum << '\n';
	return 0;
}


Measured memory_bytes: 10312
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (long long int i = f; i < t; i++)
#define pr(i, f, t) for (long long int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
#define ce(a) cout << (a) << endl
int main()
{
    string s;
    cin >> s;
    cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl;
}

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

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("4");
            WillReturn.Add("3 3 3 3");
            //1
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("5");
            WillReturn.Add("2 4 1 4 2");
            //2
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("6");
            WillReturn.Add("1 2 2 3 3 3");
            //0
        }
        else if (InputPattern == "Input4") {
            WillReturn.Add("1");
            WillReturn.Add("1000000000");
            //1
        }
        else if (InputPattern == "Input5") {
            WillReturn.Add("8");
            WillReturn.Add("2 7 1 8 2 8 1 8");
            //5
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] AArr = InputList[1].Split(' ').Select(X => int.Parse(X)).ToArray();

        int Answer = 0;
        foreach (var Each in AArr.GroupBy(X => X)) {
            int Cnt=Each.Count();
            int Key=Each.Key;

            if (Cnt > Key)
                Answer += Cnt - Key;
            if (Cnt < Key)
                Answer += Cnt;
        }
        Console.WriteLine(Answer);
    }
}


Measured memory_bytes: 33244
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int a, b, c, d;
//cin >> a; cin >> b; cin >> c; cin >> d;
	cin >> a >> b >> c >> d; 
	string result = "No"; 
	bool flag;
       	flag = (abs(a-c) <= d) || (abs(a-b) <= d && abs(b-c) <= d);
	if (flag) {
		result = "Yes";
	}
	cout << result << endl;
	return 0;
}


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

using namespace std;

int main(){
	int n;
	cin>>n;
	map<int,int> check;

	for(int i=0;i<n;i++){
		int hoge;
		cin>>hoge;
		if(check.count(hoge)) check.at(hoge)++;
		else check[hoge]=1;
	}

	bool ok=true;
	int a=n%2==0 ? 1 : 0;

	for(int i=0+a;i<n;i+=2){
		if(!check.count(i)){
			ok=false;
			break;
		}

		if(i==0){
			if(check.at(i)!=1) ok=false;
		}else{
			if(check.at(i)!=2) ok=false;
		}
	}

	long long ans=0;

	if(ok){
		ans++;
		for(int i=0;i<floor((double)n/2);i++){
			ans*=2;
			ans%=1000000007;
		}
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 3200
#include <stdio.h>
main(){
   int a,b,c,x,y,z;
   scanf("%d %d %d",&x,&y,&z);
   
   if(x>y){
        a=x;
        x=y;
        y=a;
   }
   if(x>z){
        c=x;
        x=z;
        z=c;
   }
   if(y>z){
        b=y;
        y=z;
        z=b;
   }

   printf("%d %d %d\n",x,y,z);

   return 0;
}

Measured memory_bytes: 596
import sys
input = sys.stdin.readline

mod = 10**9+7

N, K = map(int, input().split())

A = [0]
for i in range(1, N+1):
    A.append((A[-1]+i)%mod)

ans = 0
for k in range(K, N+2):
    if k == N+1:
        ans = (ans + 1)%mod
    else:
        ans = (ans + (A[-1]-A[-k-1]) - A[k-1] + 1) % mod
print(ans)

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

int main(){
  map<char,char>mp;
  mp['A'] = 'T',mp['T'] = 'A',
  mp['C'] = 'G',mp['G'] = 'C';
  char a;cin>>a;
  cout << mp[a] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>

int main(){
    int n, m;
    std::cin >> n >> m;
    std::vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        std::cin >> a[i];
    }
    int sum = std::accumulate(a.begin(), a.end(), 0);
    int count = 0;
    for (int i = 0; i < n; i++)
    {
        if (sum <= 4 * m * a[i])
        {
            count++;
        }
    }
    if (m <= count)
    {
        std::cout << "Yes" << std::endl;
    }
    else
    {
        std::cout << "No" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 3608
N,K=map(int,input().split())
from collections import defaultdict
cnt=defaultdict(int)
for a in map(int,input().split()):
    cnt[a]+=1
res=[]
for a in cnt.keys():
    res.append(cnt[a])
res.sort()
if len(res)>K:
    ans=sum(res[0:-1*K])
else:
    ans=0
print(ans)

Measured memory_bytes: 41508
INF = 10 ** 10

def solve(ns):
    n = len(ns)
    dp = [ set([(1000, 0)]), set([]) ]
    p = 0
    for price in ns:
        q = p ^ 1
        dp[q] = set()
        for (money, stock) in dp[p]:
            m1 = money + stock * price
            dp[q].add((m1, 0))
            m2 = money % price
            s2 = stock + money / price
            dp[q].add((m2, s2))
            dp[q].add((money, stock))
        p = q
    maxi = -INF
    for (money, stock) in dp[p]:
        maxi = max(maxi, money)
    return maxi

def solve2(ns):
    n = len(ns)
    dp = [1000] + [-INF for i in xrange(n)]
    for i in xrange(1, n + 1):
        for j in xrange(i + 1, n + 1):
            if ns[j - 1] <= ns[i - 1]:
                continue
            money = dp[i - 1]

            # buy in day[i]
            stock = money / ns[i - 1]
            money = money % ns[i - 1]

            # sell in day[j]
            money = money + stock * ns[j - 1]
            stock = 0

            dp[j] = max(dp[j], money)
        dp[i] = max(dp[i], dp[i - 1])
    return max(dp)

assert solve2([200, 188, 181, 115, 160]) == 1360
assert solve2([200, 180, 160, 140, 120, 100]) == 1000
assert solve2([100, 130, 130, 130, 115, 115, 150]) == 1685
# assert solve([200, 180, 160, 140, 120, 100]) == 1000
assert solve2([157, 193]) == 1216

n = int(raw_input())
ns = map(int, raw_input().split())

# print solve(ns[:])
print solve2(ns[:])


Measured memory_bytes: 68896
## ABC 072 c
from collections import Counter

n = int(input())
a = [int(i) for i in input().split()]
a.sort()

ad = Counter(a)
cnt = 0
for x in range(a[0]-1, a[-1]+2):
    c = ad[x]+ad[x-1]+ad[x+1]
    cnt = max(c,cnt)

print(cnt)


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



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

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

int W,H,N;
int x[110],y[110],a[110];

int main()
{
    cin>>W>>H>>N;

    int left=0,right=W,top=H,bottom=0;
    for (int i = 0; i < N; i++)
    {
        cin>>x[i]>>y[i]>>a[i];
    }

    for (int i = 0; i < N; i++)
    {
        if(a[i] == 1){
            if(x[i]>=left) left = x[i];
        } else if(a[i] == 2){
            if(x[i]<=right) right = x[i];
        } else if(a[i] == 3){
            if(y[i]>=bottom) bottom = y[i];
        } else {
            if(y[i]<=top) top = y[i];
        }
    }
    
    if((right-left)>0 && (top-bottom)>0){
        cout << (right-left) * (top-bottom) << endl;
    } else {
        cout << 0 << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s string
	fmt.Scan(&s)

	data := strings.Split(s, "")
	num := len(data)
	if data[num-1] == "s" {
		fmt.Println(s+"es")
	} else {
		fmt.Println(s+"s")
	}
}


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


int main()
{
    ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);

    double d, t, s;

    cin >> d >> t >> s;

    double z = d/s;

    if(z>t)
    {
        cout << "No";
    }

    else
    {
        cout << "Yes";
    }


}



Measured memory_bytes: 3696
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  vector<int> cnt(n);
  for (int i = 1; i < n; ++i) {
    int a;
    cin >> a;
    a--;
    cnt[a]++;
  }
  for (int i = 0; i < n; ++i) {
    cout << cnt[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std ;
int n, t, ans, maxn, maxn1, lastans;
int a[100010];
int main(){
    cin >> n >> t;
    for(int i=1; i<=n; i++) cin >> a[i];
    for(int i=n; i; i--){maxn=max(a[i], maxn); ans=max(maxn-a[i], ans);}
    for(int i=n; i; i--){maxn1=max(a[i], maxn1); if(maxn1-a[i]==ans) lastans++;}
    cout<<lastans;
    return 0 ;
}


Measured memory_bytes: 640
#include<complex>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<vector>
#include<map>
#include<sstream>
#include<ctime>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<deque>
#include<queue>
#include<climits>
#include<list>
#include<stack>
#include<ctime>
#define all(n) n.begin(),n.end()
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define F first
#define S second
#define Iter(c) __typeof__((c).begin())
#define foreach(i,c) for(Iter(c) i = (c).begin();i != (c).end();++i)
#define pb push_back
#define INF (1<<27)
#define EPS 1e-10
#define equals(a,b) (fabs((a)-(b)) < EPS)

using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
typedef unsigned long long ull;
typedef long long ll;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};

typedef pair<string,int> SI;

bool ok(string s)
{
  char c = s[0];
  for(int i=0;i<s.length();i++)
    if(c != s[i])
      return false;
  return true;
}

char getc(char c,char cc)
{
  map<char,bool> index;
  index['r'] = false,index['b'] = false,index['g'] = false;
  index[c] = true;
  index[cc] = true;
  foreach(i,index)
    if(!(*i).S)
      return (*i).F;

}

int solve(string s)
{

  queue<SI> que;
  que.push(SI(s,0));
  map<string,bool> used;
  while(!que.empty())
    {
      SI si = que.front(); que.pop();

      if(used[si.F])
	continue;

      used[si.F] = true;
 
      if(ok(si.F))
	{
	  return si.S;
	}

      if(si.S > 30)
	continue;

      rep(i,si.F.length()-1)
	{
	  if(si.F[i] == si.F[i+1])
	    continue;
	  string news = si.F;
	  news[i] = news[i+1] = getc(si.F[i],si.F[i+1]);
	  que.push(SI(news,si.S+1));
	}

    }

  return -1;
}


int main(){

  while(true)
    {
      string s;
      cin >> s;
      if(s[0] == '0')
	break;

      int ans = solve(s);
      ans != -1?cout << ans << endl:cout << "NA" << endl;

    }

return 0;
}

Measured memory_bytes: 3336