akhauriyash/Code-Regression huggingface dataset:
N, M = map(int, input().split())
E = [set() for i in range(N)]
for i in range(M):
  s, t = map(int, input().split())
  s, t = s-1, t-1
  E[s].add(t)
Vs = [1000000.0]*N
Vs[-1] = 0
for i in reversed(range(N-1)):
  js = E[i]
  v = 0
  for j in js:
    v += Vs[j]
  v = 1+v/len(js)
  Vs[i] = v
r = Vs[0]
rs = [r]
Vs0 = Vs
for n in range(N-1):
  Vs = [1000000.0]*N
  for i in range(n+1, N):
    Vs[i] = Vs0[i]
  for i in reversed(range(n+1)):
    js = E[i]
    if i == n:
      jmin = max(js, key=lambda j: Vs[j])
      js = js-{jmin}
    if len(js) == 0:
      break
    #p = 1/len(js)
    v = 0
    for j in js:
      v += Vs[j]
    v = 1+v/len(js)
    Vs[i] = v
  r = Vs[0]
  rs.append(r)
#print(rs)
r = min(rs)
print(r)


Measured memory_bytes: 67928
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int n, k, r, s, p;

int calc(string t){
    int n = t.length();
    VVI dp(n + 1, VI(4, -1e9));
    dp[0][3] = 0;
    REP(i,n) REP(j,4) REP(k,3){
        if (j == k) continue;
        int x = 0;
        if (k == 0 && t[i] == 's') x = r;
        if (k == 1 && t[i] == 'p') x = s;
        if (k == 2 && t[i] == 'r') x = p;
        chmax(dp[i + 1][k], dp[i][j] + x);
    }
    int ret = 0;
    REP(k,3) chmax(ret, dp[n][k]);
    return ret;
}

int main() {
    string t;
    cin >> n >> k >> r >> s >> p >> t;
    vector<string> v(k);
    REP(i,n){
        v[i % k] += t[i];
    }
    int ans = 0;
    REP(i,k){
        ans += calc(v[i]);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6016
N = int(input())
capacities = [int(input()) for i in range(5)]

min_cap = None
min_i = 0
for i, c in enumerate(capacities):
    if min_cap is None or c < min_cap:
        min_i = i
        min_cap = c

# 全員が移動する時間 = (1) + (2) + (3)
# (1) 定員 min_cap の乗り物が出発する都市に人が到達する時刻
t1 = min_i
# (2) (1) から N 人を min_cap 人ずつ送り出していくとき最後のグループを送り出すまでにかかる時間
t2 = (N + min_cap - 1) // min_cap
# (3) (2) から最後のグループが都市 6 に到達するまでの時間
t3 = 5 - (min_i + 1)

print(t1 + t2 + t3)

Measured memory_bytes: 3064
n = int(input())
a = list(map(int,input().split()))
a.insert(0,0)
a.append(0)
c = 0
d = 0
for spot in a:
  c += abs(d-spot)
  d = spot
for i in range(1,n+1):
  p = c-abs(a[i]-a[i-1])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1])
  print(p)

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

string S;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>S;
	sort(ALL(S));
	if(S[0]==S[1] && S[2]==S[3] && S[0]!=S[3]) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <set>
#include <iostream>
#include <algorithm> 
#define debug	 0
#define 	MAXN		10001
using namespace std;
long long  N,A,B;
set<int>ans;
int cnt = 0;

int main()
{	
#if debug	
freopen("data.txt","r",stdin);
#endif
	cin>>N>>A>>B;
	long long maxx,min;
	maxx = B*(N - 1) + A;
	min = A*(N - 1) + B;
	if ((maxx - min + 1) > 0)
	{	cout<<(maxx - min + 1);

	 } 
	else cout<<0;
//	cout<<(maxx - min + 1) >(long long) 0 ? (maxx - min + 1) : 0;
}

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

int main(){
  int N;
  cin >> N;
  
  vector<int> arr(N);
  int x=0;
  for(int i=0;i<N-1;i++){
    cin >> x;
    arr[x-1] += 1;
  }
  for(int i=0;i<N;i++){
    cout << arr[i] << endl;
  }
}

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

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	string s;
	cin>>s;
	for (char c : s){
		if (c=='7'){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    for(int i=0;i<365;i++) cout<<1<<endl;
}


Measured memory_bytes: 3652
n,m = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(n)]
cd = [tuple(map(int, input().split())) for _ in range(m)]

def dist(a,b,c,d):
    return abs(a-c)+abs(b-d)

for a,b in ab:
    idx = 0
    for i in range(m):
        if dist(a,b,cd[i][0],cd[i][1]) < dist(a,b,cd[idx][0],cd[idx][1]):
            idx = i
    print(idx+1)

Measured memory_bytes: 3064
#include <iostream>
#include<bits/stdc++.h>
#include<string>
#define ll long long

using namespace std;

int main()
{
   string s,t;
   cin>>s>>t;
   string t1=t.substr(0,t.size()-1);
   if(s.compare(t1)==0 && t.size()==s.size()+1)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
    return 0;
   
   return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)










const ll table_size = 1000005;
ll fact[table_size], finv[table_size], inv[table_size];

// 前処理
void make_table(ll mod) {
	fact[0] = fact[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < table_size; i++) {
		fact[i] = fact[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}

ll comb(ll n, ll r, ll mod) {
	if (n < r || n < 0 || r < 0) return 0;
	return fact[n] * (finv[r] * finv[n - r] % mod) % mod;
}

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

	if ((x + y) % 3 != 0) {
		cout << 0 << endl;
		return 0;
	}

	make_table(MOD);

	ll a = (2 * x - y) / 3;
	ll b = x - 2 * a;
	if (a < 0 || b < 0) {
		cout << 0 << endl;
	}
	else {
		cout << comb(a + b, b, MOD) << endl;
	}
}

Measured memory_bytes: 23680
#include<stdio.h>
 
#define MAX 100
#define INF 1000000
#define white 0
#define gray 1
#define black 2
 
int n,u,M[MAX][MAX];
 
void dijkstra(void);
 
int main(){
  int i,j,k,v,c;
 
  scanf("%d",&n);
 
  for(i=0;i<n;i++)
    for(j=0;j<n;j++)
      M[i][j] = INF;
 
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d %d",&v,&c);
      M[u][v] = c;
    }
  }
 
  dijkstra();
 
  return 0;
}
 
void dijkstra(){
  int i,min,d[MAX],color[MAX] = {white};
 
  for(i=0;i<n;i++)
    d[i] = INF;
 
  d[0] = 0;
  color[0] = gray;
 
  while(1){
    min = INF;
    u = -1;
    for(i=0;i<n;i++)
      if(min > d[i] && color[i] != black){
    u = i;
    min = d[i];
      }
    if(u == -1)break;
    color[u] = black;
    for(i=0;i<n;i++)
      if(color[i] != black && M[u][i] != INF){
    if(d[i] > d[u] + M[u][i]){
      d[i] = d[u] + M[u][i];
      color[i] = gray;
    }
      }
  }
  for(i=0;i<n;i++){
    if(d[i] == INF)printf("%d -1\n",i);
    else printf("%d %d\n",i,d[i]);
  }
 
}


Measured memory_bytes: 2044
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <complex>
#include <vector>
#include <tuple>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <time.h>
#define all(c) ((c).begin(),(c).end())
#define rall(c) (c).rbegin(),(c).rend()
#define sort(v,n) sort(v,v+n)
#define vsort(v) sort(v.begin(),v.end())
#define vvsort(v) sort(v.begin(),v.end(),greater<int>())
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int w, h;


int main() {
	while (cin >> h >> w, w) {
		int p = h*h + w*w;
		ll hh = 151, ww = 151;
		for (int i = 1; i < 151; i++) {//w
			for (int j = 1; j < i; j++) {//h
				if (i*i + j*j > p) {
					if (hh*hh + ww*ww > i*i + j*j) {
						hh = j; ww = i;
					}
					else if (hh*hh + ww*ww == i*i + j*j) {
						if (hh > j) {
							hh = j; ww = i;
						}
					}
				}
				else if (i*i + j*j == p && j>h) {
					if (hh*hh + ww*ww > i*i + j*j) {
						hh = j; ww = i;
					}
					else if (hh*hh + ww*ww == i*i + j*j) {
						if (hh > j) {
							hh = j; ww = i;
						}
					}
				}
			}
		}
		cout << hh << " " << ww << endl;
	}
}

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

#define el '\n'
#define pb push_back
#define sp ' '
#define all(x) (x).begin(), (x).end()
#define mset(x, y) memset(x, y, sizeof(x))
#define ff first
#define ss second

// clang-format off
#ifndef ONLINE_JUDGE
template <typename T, size_t N> int SIZE(const T (&t)[N]){ return N; } template<typename T> int SIZE(const T &t){ return t.size(); } string to_string(const string s, int x1=0, int x2=1e9){ return '"' + ((x1 < (int)s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c){ return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9){ string t = ""; for(int __iii__ = min(x1,SIZE(b)),  __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__){ t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += el; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l){ if(rnk > 1) { res += el; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += el; return res; } void dbgm(){;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgm(T...); } 
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; cout << to_string(__VA_ARGS__) << endl
#define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cout << endl
#else
#define dbg(...) ;
#define dbgm(...) ;
#endif
// clang-format on

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppi;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vll> vvll;

const int inf = 1e09 + 5e3;
const ll linf = 2e18 + 5e3;
const int mod = 1e9 + 7;
const int mxn = 1e5;

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

    int n, m;
    cin >> n >> m;
    cout << (n == m ? "Yes" : "No");
}


Measured memory_bytes: 3620
use v5.18; # strict say state
use warnings;
use List::Util qw(reduce first max min sum0);

chomp (my ($n, $k) = split / /, <STDIN>);
chomp (my @a = split / /, <STDIN>);

my @b = grep {$_ >= $k} @a;
if (min(@b)==$k) {
  say "POSSIBLE";
  exit;
} elsif (@b==0) {
  say 'IMPOSSIBLE';
  exit;
}
my $gcd = sub {
  my ($x, $y) = @_;
  while ($y) {
    my $r = $x % $y;
    $r += $y if $r < 0;
    $x = $y;
    $y = $r;
  }
  return $x;
};
my $g = $a[0];
for my $i (1..($n-1)) {
  $g = $gcd->($g, $a[$i]);  
}
if ($k%$g==0) {
  say "POSSIBLE";
} else {
  say 'IMPOSSIBLE';
}

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

ll solve(ll a, ll n)
{
    ll s = 1;
    while(n) s = s * ((n % 2) ? a : 1) % 1000000007, a = a * a % 1000000007, n >>= 1;
    return s;
}

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

    //Input
    ll n, k;
    cin >> n >> k;
    ll sum = 0;

    vector<ll> a(k + 1);
    for(int i = k; i > 0; i--)
    {
        a[i] = solve(k / i, n);
        for(int j = i * 2; j <= k; j += i)
        {
            a[i] -= a[j];
        }
        a[i] = (a[i] % 1000000007 + 1000000007) % 1000000007;
        sum += i * a[i];
    }

    cout << sum % 1000000007 << "\n";
}


Measured memory_bytes: 3920
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int H[] = new int[N];
        for (int i=0; i<N; i++) {
            H[i] =  Integer.parseInt(sc.next());
        }
        sc.close();

        Integer C[] = new Integer[N];

        for (int i=0; i<N-1; i++) {
            if (H[i]>=H[i+1]) {
                C[i] = 1;
            } else {
                C[i] = 0;
            }
        }

        int max = 0;
        int cnt = 0;
        for (int i=0; i<N-1; i++) {
            if (C[i]==1) {
                cnt++;
                if (max < cnt)
                    max = cnt;
            } else {
                cnt = 0;
            }
        }
        
        System.out.println(max);
    }
}

Measured memory_bytes: 46636
def main
  s = ARGF.gets.chomp   # 1文字 〜 5000文字
  s_len = s.length

  k = ARGF.gets.to_i  # 1 <= K <= 5
  top_n = [k, 5].min

  top_n_subs = []
  'a'.upto('z') do |c|
    pos = 0
    while pos = s.index(c, pos)
      # puts "#{c}: #{pos}"

      # 何パターンある？
      pat_num = s_len - pos

      needs_num =
          if top_n <= pat_num
            # TOP5(or TOPK)だけをリストアップ
            top_n
          else
            # 全部リストアップ
            pat_num
          end

      subs = needs_num.downto(1).inject([]) do |subs, n|
        subs << s.slice(pos, n)
      end

      top_n_subs.concat(subs)
      top_n_subs.uniq!

      # 次の文字から探索
      pos += 1
    end

    # 1つの文字種が終わった段階でリストを確認する
    if top_n <= top_n_subs.length
      top_n_subs.sort!
      puts top_n_subs[top_n-1]
      return
    else
      # 次の文字種で求められるuniq数
      top_n -= top_n_subs.length
      top_n_subs = []   # リストはクリアしちゃってOK
    end
  end

  # ここまで来ることはない！
  puts "error"
end

if __FILE__ == $0
  main
end


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

using namespace std;

map<pair<int, int>, int>fnd;
int n, m, x[1 << 20], y[1 << 20];
int main()
{
    cin >> n >> m;

    for(int i = 1; i <= m; ++i)
    {
        cin >> x[i] >> y[i];
        fnd[ {x[i], y[i]}] = i;
    }

    for(int i = 1; i <= m; ++i)
    {
        if(x[i] == 1 && fnd[ {y[i], n}])
        {
            cout << "POSSIBLE";
            return 0;
        }

    }

    cout << "IMPOSSIBLE";
}


Measured memory_bytes: 21888
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 100000000;//10^8
ll MOD  = 1000000007;
ll dp[110][4][4][4][4]; //ijkに１つ追加
//0123 ACGT


int main(void){
    int N;
    cin >> N;
    for(int i = 0; i < 4; i++){
        for(int j = 0; j < 4; j++){
            for(int k = 0; k < 4; k++){
                for(int l = 0; l < 4; l++){
                    dp[4][i][j][k][l] = 1;
                    if( (j == 0 && k == 2 && l == 1)
                     || (i == 0 && j == 2 && k == 1)
                     || (j == 2 && k == 0 && l == 1)
                     || (i == 2 && j == 0 && k == 1)
                     || (j == 0 && k == 1 && l == 2)
                     || (i == 0 && j == 1 && k == 2)
                     || (i == 0 && k == 2 && l == 1)
                     || (i == 0 && j == 2 && l == 1) ){
                            dp[4][i][j][k][l] = 0;
                        }
                }
            }
        }
    }
    
    
    
    for(int n = 5; n <= N; n++){
        for(int i = 0; i < 4; i++){
            for(int j = 0; j < 4; j++){
                for(int k = 0; k < 4; k++){
                    for(int l = 0; l < 4; l++){
                        dp[n][i][j][k][l] = dp[n-1][0][i][j][k] + dp[n-1][1][i][j][k] + dp[n-1][2][i][j][k] + dp[n-1][3][i][j][k];
                        dp[n][i][j][k][l] %= MOD;
                        if( (j == 0 && k == 2 && l == 1 ) || (j == 2 && k == 0 && l == 1) || (j == 0 && k == 1 && l == 2) || (i == 0 && k == 2 && l == 1) || (i == 0 && j == 2 && l == 1) ){
                            dp[n][i][j][k][l] = 0;
                        }
                    }
                }
            }
        }
    }
    ll ans = 0;
    for(int i = 0; i < 4; i++){
        for(int j = 0; j < 4; j++){
            for(int k = 0; k < 4; k++){
                for(int l = 0; l < 4; l++){
                    ans += dp[N][i][j][k][l];
                    ans %= MOD;
                }
            }
        }
    }
    if(N == 3){
        ans = 61;
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#define _USE_MATH_DEFINES

#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>


using namespace std;

/* cout << fixed << setprecision(5); */



int main()
{	
	int H, W;

	while (cin >> H >> W)
	{
		if (H == 0 && W == 0)
		{
			break;
		}

		for (int i = 0; i < W; i++)
		{
			cout << "#";
		}

		cout << endl;



		for (int j = 0; j < H-2; j++)
		{
			cout << "#";
			
			for (int i = 0; i < W-2; i++)
			{
				cout << ".";
			}

			cout << "#" << endl;

		}



		for (int i = 0; i < W; i++)
		{
			cout << "#";
		}


		cout << endl << endl;


	}

	

	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int64_t n;
  cin >> n;
  vector<int64_t> a(n),b(n,0);
  rep(i,n){
    cin >> a.at(i);
  }
  rep(i,n){
    b.at(a.at(i)-1)++;
  }
  int64_t ans;
  rep(i,n){
    ans+=b.at(i)*(b.at(i)-1)/2;
  }
  for(int64_t x:a){
    int64_t cp=ans;  
    cp=cp-(b.at(x-1)-1);
    cout << cp  << endl;
  }
}
  


Measured memory_bytes: 5760
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

//#define DEBUG
#ifdef DEBUG
#define debug_printf printf
#else
#define debug_printf 1 ? 0 : printf
#endif

using namespace std;
typedef long long int ll;
typedef vector<ll> Vl;
typedef vector<int> Vi;
typedef pair<int, int> Pi;

#define INF   (1e9 + 7)
#define MAX_N (5000)
#define MAX_K (5000)

int N, K;
int A[MAX_N];
bool DP[MAX_N + 1][MAX_K];

bool check(int x) {
  for (int i = 0; i <= N; i++) 
    for (int j = 0; j < K; j++) DP[i][j] = false;
  DP[0][0] = true;

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < K; j++) {
      bool flag = DP[i][j];
      int k = j - A[i];
      if (i != x && k >= 0) flag |= DP[i][k];
      DP[i + 1][j] = flag;
    }
  }

  debug_printf("x = %d\n", x);
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j < K; j++) debug_printf("%s ", DP[i][j]? "o": "x");
    debug_printf("\n");
  }
  debug_printf("\n");

  for (int k = max(0, K - A[x]); k < K; k++) 
    if (DP[N][k]) return true;
  
  return false;
}

void solve() {
  sort(A, A + N);
  
  int xl = -1, xr = N;    
  while (xr - xl > 1) {
    int xm = (xl + xr) / 2;
    if (check(xm)) {
      xr = xm;
    } else {
      xl = xm;
    }
  }  

  printf("%d\n", xr);
}

int main() {
  scanf("%d %d", &N, &K);
  for (int i = 0; i < N; i++) scanf("%d", &A[i]);

  solve();

  return 0;
}


Measured memory_bytes: 24832
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

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

	int n;
	cin >> n;

	vector<ll> as(n);
	for (ll& a : as) cin >> a;

	ll v = 1000;
	for (int i = 0; i+1 < n; ++i) {
		if (as[i] < as[i+1]) {
			ll cou = (v / as[i]);
			v += cou * (as[i+1] - as[i]);
		}
	}
	cout << v << '\n';
}


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

const int maxn = 3010;
char str1[maxn];
char str2[maxn];
int dp[maxn][maxn];
char path[maxn];

int main()
{
	cin.getline(str1,maxn);
	cin.getline(str2,maxn);
    int len1 = strlen(str1);
    int len2 = strlen(str2);
    
    //LCS 
    for(int i = 0; i < len1; ++i){
        for(int j = 0; j < len2; ++j){
            if(str1[i] == str2[j])
                dp[i+1][j+1] = dp[i][j]+1;
            else
                dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1]);
        }
    }
    
    int i = len1-1;
    int j = len2-1;
    int plen = 0;
    //记录路径
    while(i >= 0 && j >= 0){
        if(str1[i] == str2[j]){
            path[plen++] = str1[i];
            --i;
            --j;
        }
        else if(dp[i+1][j] >= dp[i][j+1])//说明lcs是str1[0~i]和str2[0~j-1]的lcs
            --j;
        else
            --i;
    }
    for(int i = plen-1; i >= 0; --i)
        cout<<path[i];
    cout<<endl;
    return 0;
}

Measured memory_bytes: 38852
def main():
    D, N = map(int, input().split())
    if D == 0:
        if N != 100:
            print(N)
        else:
            print(101)
    elif D == 1:
        if N != 100:
            print(100*N)
        else:
            print(10100)
    elif D == 2:
        if N != 100:
            print(10000*N)
        else:
            print(1010000)
main()

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
  for(;;){
    int n,m;
    cin >> n >> m;
    if(n == 0 && m == 0) break;
    vector<int> v(n),w(m);
    int vsum=0,wsum=0;
    for(int i=0; i<n; i++){
      cin >> v[i];
      vsum += v[i];
    }
    for(int i=0; i<m; i++){
      cin >> w[i];
      wsum += w[i];
    }
    int d = vsum - wsum;
    int retv = 101,retw = 101;
    for(int i=0; i<n; i++){
      for(int j=0; j<m; j++){
        if((v[i] - w[j])*2 == d && retv + retw > v[i] + w[i]){
          retv = v[i];
          retw = w[j];
        }
      }
    }
    if(retv == 101){
      cout << -1 << endl;
      continue;
    }
    cout << retv << " " << retw << endl;
  }
  return 0;
}

Measured memory_bytes: 1196
Ns = input()
N = int(Ns)
Nl = len(Ns)
ret = set()
def doit(t, f , s, now):
    if t + f + s == 0:
        if int(now) <= N:
            ret.add(now)
        return
    if t > 0:
        doit(t - 1, f, s, now + str(3)) 
    if f > 0:
        doit(t, f - 1, s, now + str(5)) 
    if s > 0:
        doit(t, f, s - 1, now + str(7)) 
    
for seven in range(1, Nl - 1):
    for five in range(1, Nl - seven):
        least = Nl - seven - five
        for three in range(1, least + 1):
            doit(three, five, seven, '')

print(len(ret))



Measured memory_bytes: 6896
#include <bits/stdc++.h>
typedef long long int ll;
#define vaibhavv06               \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(0);
#define int long long
#define MM(a,b) memset(a,b,sizeof(a))
const ll MOD = 1000000007;
using namespace std;



int32_t main(){
    vaibhavv06;
	int n,m; cin>>n>>m;
	int pen=0,cor=0;
	pair<int,int> arr[n+1];
	MM(arr,0);
	for(int i=0;i<m;i++){
		int x; cin>>x;
		string s; cin>>s;
		if(s=="WA") arr[x].second++;
		if(s=="AC") {
			if(arr[x].first==0){
				cor++;
				arr[x].first++;
				pen+=arr[x].second;
			}
			
		}
		// cout<<cor<<" "<<pen<<endl;
	}
	cout<<cor<<" "<<pen<<endl;
	
}

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

int main()
{
    int n; cin>>n;
    vector<int> cnt(128, INT_MAX);
    for(string s; n--; ) {
        cin>>s;
        array<int, 128> t={};
        for(auto& c: s) ++t[c];
        for(int i=0; i<128; ++i) cnt[i]=min(cnt[i], t[i]);
    }
    for(int i=0; i<128; ++i) if (cnt[i]) cout<<string(cnt[i], i);
    cout<<endl;
}

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

using namespace std;
typedef long long ll;
//ループ
#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--)
//コンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define D()
//定数
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

//2値の最大公約数(順序関係なし・0はダメ)
int gcd(int a, int b){
    return b ? gcd(b, a%b) :a;
}

//n個の最大公約数
int ngcd(vector<int>& a){
    int res;
    res = a.at(0);
    for(int i = 1; i< a.size() && res != 1; i++){
        res = gcd(a.at(i), res);
    }
    return res;
}

//2値の最小公倍数
int lcm(int a, int b) {
    return a / gcd(a, b) * b;
}

//n個の最小公倍数
int nlcm(vector<int> numbers){
    int res;
    res = numbers.at(0);
    for(int i = 0; i< numbers.size();i++){
        res = lcm(res, numbers[i]);
    }
    return res;
}

//素数判定O(√N)
bool isPrime(int x){
    if(x<2) return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(int i = 3; i*i <= x; i+=2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(int n){
    int res = 0;
    while(n>0){
        res += n%10;
        n /= 10;
    }
    return res;
}

//約数全列挙
vector<int> enum_div(int n){
    vector<int> ret;
    for(int i = 1 ; i*i <= n ; ++i){
        if(n%i == 0){
            ret.push_back(i);
            if(i != 1 && i*i != n){
                ret.push_back(n/i);
            }
        }
    }
    return ret;
}

//繰り返し自乗法
long long int mod_pow(long long int x, long long int n, long long int mod){
    long long int res = 1;
    while(n > 0){
        if(n & 1) res = res*x%mod;
        x = x*x%mod;
        n >>= 1;
    }
    return res;
}

//文字列の中で何回文字が出てきたのかを数える
int stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c); //覚える
}

int main(){
    int x; cin >> x;
    if(x>=30) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

struct sw {
    long long x, y, z;
    long long sum ;
};

bool cmp(sw a, sw y) {
    return a.sum > y.sum;
}
int main() {
    int N, M;
    cin >> N >> M;
    vector<sw> sws;

    for (int i = 0; i < N; ++i) {
        long long a, b, c;
        cin >> a >> b >> c ;
        struct sw s = {a,b,c, 0};
        sws.push_back(s);
    }

    int xd[] = {1,-1};
    int yd[] = {1,-1};
    int zd[] = {1,-1};
    long long summax = INT_MIN;
    for (int j = 0; j < 2; ++j) {
        for (int i = 0; i < 2; ++i) {
            for (int k = 0; k < 2; ++k) {
                for (int l = 0; l < N; ++l) {
                    sws[l].sum = sws[l].x * xd[j] +  sws[l].y * yd[i] +  sws[l].z * zd[k];
                }
                sort(sws.begin(), sws.end(), cmp);
                long long sum = 0;
                for (int m = 0; m < M; ++m) {
                    sum += sws[m].sum ;
                }
                summax = max(summax, sum);
            }
        }
    }
    cout << summax << endl;

    return 0;
}


Measured memory_bytes: 256
#ABC065

n = int(input())
a = [int(input()) for _ in range(n)]
b = []

i = 1
for _ in range(n):
    
    b.append(i)
    i = a[i-1]
    
    
        
if 2 in b:
    print(b.index(2))
else:
    print(-1)

Measured memory_bytes: 7852
//Similar Arrays

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
#define nvarep(n,a) int n;cin>>n;vector<int>a(n);rep(i,0,n)cin>>a[i]
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<int,string> p;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

int main (){
    nvarep(n,a);
    ll ans = pow(3,n);
    ll mi = 1;
    rep(i,0,n)if(a[i]%2==0)mi*=2;
    cout<<ans-mi<<nnn;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	int A[m],i;
	int s=0;
	for(i=0;i<m;i++)
	{
		cin>>A[i];
		s=s+A[i];
	}
	if(n<s)
	cout<<"-1"<<endl;
	else
	cout<<n-s<<endl;
}

Measured memory_bytes: 3652
"use strict";

function Main(input) {
  let x = input.trim().split(' ')[0]*1;
  let y = input.trim().split(' ')[1]*1;
  let ans = "No";
  if(x == y){
  	ans = "Yes";
  }
  console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
use std::str::FromStr;
use std::cmp::max;

fn get_one<T : FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().parse().ok().unwrap();
}

fn get_vec<T : FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
}


fn main() {
    let n : usize = get_one();
    let mut v : Vec<i64> = get_vec();
    v.sort();
    let mut ans = true;
    let mut prev = -1;
    for x in v {
        if prev == x {
            ans = false;
            break;
        }
        prev = x;
    }
    println!("{}", if ans {"YES"} else {"NO"});
}


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

int main(){
    int n,q;
    string s;
    cin>>n>>s>>q;
    vector<set<int>>se(26);
    rep(i,n)se[s[i]-'a'].insert(i);
    rep(i,q){
        int a,b; cin>>a>>b;
        b--;
        if(a==1){
            char c; cin>>c;
            se[s[b]-'a'].erase(b);
            s[b]=c;
            se[s[b]-'a'].insert(b);
        }
        else{
            int c; cin>>c;
            c--;
            int ans=0;
            rep(j,26){
                auto it=se[j].lower_bound(b);
                if(*it<=c&&it!=se[j].end())ans++;
            }
            printf("%d\n",ans);
        }
    }
}

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

using namespace std;

int gcd(int a, int b) {
  if(b > a)
    return gcd(b, a);
  if(a % b == 0)
    return b;
  return gcd(a % b, b);
}

int main() {
  int k;
  cin >> k;
  int ans = 0;
  for(int p = 1; p <= k; p++) {
    for(int q = 1; q <= k; q++) {
      for(int r = 1; r <= k; r++) {
        ans += gcd(p, gcd(q, r));
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  long long count=0;
  long long A,B,C,D;
  cin>>A>>B>>C>>D;
  long long X,Y,g=1,tmp;
  A--;
  X=C;
  Y=D;
  while(1){
    tmp=Y%X;
    Y=tmp;
    if(Y==0){
    g=X;
      break;
    }
    else {
      tmp=X%Y;
      X=tmp;
    }
    if(X==0){
    g=Y;
      break;
    }
  }
  count=(B-B/C-B/D+B/(C*D/g))-(A-A/C-A/D+A/(C*D/g));
 cout<<count;
}

Measured memory_bytes: 256
d,g=map(int,input().split())
data=[]
for i in range(d):
    p,c=map(int,input().split())
    data.append((p,c))
n=0
mn=99999999
while n<2**d:
    point=0
    count=0
    for i in range(d):
        if n&(1<<i):
            point+=data[i][0]*100*(i+1)+data[i][1]
            count+=data[i][0]
    if point<g:
        for i in range(d):
            i=d-1-i
            if not n&(1<<i):
                for j in range(data[i][0]-1):
                    point+=(i+1)*100
                    count+=1
                    if point>=g:
                        mn=min(mn,count)
                        break
                else:
                    break
                break
    else:
        mn=min(mn,count)
    n+=1
print(mn)



Measured memory_bytes: 3064
#include<stdio.h>

int main(){
  int x,y,n;
  scanf("%d%d",&x,&y);
  if(x > y){
    while(1){
      n = x % y;
      if(n == 0)break;
      x = y;
      y = n;
    }
    printf("%d\n",y); 
  }
    else{
      while(1){
	n = y % x;
	if(n == 0)break;
	y = x;
	x = n;
      }
      printf("%d\n",x);
    }
}
  



Measured memory_bytes: 2124
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Map<Integer,Integer> map = new HashMap<>();

		for (int i = 0; i < N; i++) {
			map.put(i, sc.nextInt());
		}

		int cnt = 0;
		cnt += map.get(0);


		for (int i = 1; i < N; i++) {
			if (map.get(i-1) < map.get(i)) {
				cnt += map.get(i) - map.get(i-1);
			}
		}
		System.out.println(cnt);
	}
}


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

#define ll long long
#define ull unsigned long long
#define pb push_back
#define pf push_front
#define pof pop_front
#define pob pop_back
#define mp make_pair
#define pll pair<ll,ll>
#define pii pair<int,int>
#define all(s) s.begin(),s.end()
#define vll vector<ll>
#define vi vector<int>
#define vpii vector<pii>
#define vpll vector<pll>
#define vd vector<double>
#define vull vector<ull>
#define vc vector<char>
#define vs vector<string>
#define fi first
#define se second
#define sz(x) x.size()
#define cinarr(n,a) for(int i = 0; i < n; i++) cin >> a[i];
#define coutarr(n,a) for(int i = 0; i < n; i++) cout << a[i] << (i+1==n?'\n':' ');
#define fori(i,a,b,x) for(int i = a; i <= b; i+=x)
#define ford(i,a,b,x) for(int i = a; i >= b; i-=x)
#define tc int t; cin >> t; for(int cs = 1; cs <= t; cs++)
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define ld long double
#define reset(x,y) memset(x,y,sizeof x);
#define sqr(x) 1LL*(x)*(x)
#define cube(x) 1LL*(x)*(x)*(x)
#define ub(v, a) upper_bound(all(v), a)
#define lb(v, a) lower_bound(all(v), a)
#define EPS 1e-10
#define INF 2000000000
#define mod 1000000007
#define minof(a) min_element(all(a))
#define maxof(a) max_element(all(a))
#define debug(val) cerr << "The value of " << #val << " is = " << val << endl;
#define testing cerr << "--------------------------\n";

//input space ---> scanf("%[^\n]%*c",s);

ld dp[3005][3005],ph[3005],pt[3005];
bool vis[3005][3005];
ll n;

ld f(ll h, ll cur) {
//	debug(h)
//	debug(cur)
//	testing
	if(h < 0)
		return 0.0;
	if(cur == n) {
		return (h ? 0.0 : 1.0);
	}
	if(vis[h][cur])
		return dp[h][cur];
	vis[h][cur]=1;
	return dp[h][cur] = f(h-1,cur+1)*ph[cur] + f(h,cur+1)*pt[cur];
}

int main() {
	IOS
	reset(dp,-1);
	cin >> n;
	fori(i,0,n-1,1) {
		cin >> ph[i];
		pt[i] = 1-ph[i];
	}
	ld ans = 0;
	fori(i,n/2+1,n,1) {
		ans += f(i,0);
	}
	cout << fixed << setprecision(9) << ans << endl;
}


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

// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000000000000ll
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
//#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
bool x;
cin >> x;
if (x) cout << "0\n";
else
  cout << "1\n";
return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>
#include <vector>
#include <map>
#include <string>
#include <iostream>
#include <limits.h>
#include <algorithm>

using namespace std;

int main()
{
    int a[3];
    cin >> a[0] >> a[1] >> a[2];

    sort(a, a + 3, greater<int>());
    cout << a[1] + a[2] << endl;

    return 0;
}

Measured memory_bytes: 256
import sys

class Dice():
    top=0
    n=1
    e=3
    w=2
    s=4
    bottom=5
    dice=[1,2,3,4,5,6]
    def __init__(self,num):
        self.dice=num

    def roll(self,direction):
        if(direction=="N"):
            self.top,self.bottom,self.n,self.s = self.n,5-self.n,5-self.top,self.top
        elif(direction=="E"):
            self.top,self.bottom,self.e,self.w = self.e,5-self.e,5-self.top,self.top
        elif(direction=="W"):
            self.top,self.bottom,self.e,self.w = self.w,5-self.w,self.top,5-self.top
        elif(direction=="S"):
            self.top,self.bottom,self.n,self.s = self.s,5-self.s,self.top,5-self.top

    def equal(self,another):
        if(self.dice[self.top] != another.dice[another.top]):
            return False
        if(self.dice[self.n] != another.dice[another.n]):
            return False
        if(self.dice[self.e] != another.dice[another.e]):
            return False
        if(self.dice[self.w] != another.dice[another.w]):
            return False
        if(self.dice[self.s] != another.dice[another.s]):
            return False
        if(self.dice[self.bottom] != another.dice[another.bottom]):
            return False

        return True

n=int(input())
dicea=Dice(list(map(int,input().split())))

for i in range(n-1):
    diceb=Dice(list(map(int,input().split())))

    roll_order="NNNNWNNNWNNNENNNENNNWNNNN"
    for j in range(len(roll_order)):
        if(dicea.equal(diceb)):
            print("No")
            sys.exit()
        else:
            diceb.roll(roll_order[j])
print("Yes")


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

#define double long double
#define int long long
#define ALL(x) x.begin(),x.end()
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb(x) push_back(x)
#define eb emplace_back
#define SORT(ls) sort(ls.begin(), ls.end())
#define DESC(ls) sort(ls.rbegin(), ls.rend()) 
#define mp(x, y) make_pair(x, y)
#define INF 1000000000
#define MOD 998244353 
#define F(i, a, n) for(i=a;i<n;i++)
#define SI(x) cin>>x
#define DI(x, y) cin>>x>>y
#define TI(x, y, z) cin>>x>>y>>z
#define FI(w, x, y, z) cin>>w>>x>>y>>z
#define SO(x) cout<<x<<"\n"
#define DO(x, y) cout<<x<<" "<<y<<"\n"
#define TO(x, y, z) cout<<x<<" "<<y<<" "<<z<< "\n"
#define FO(w, x, y, z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<"\n"
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)


int32_t main(void)
{
    FASTER;
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int i, j;
    int x, n;
    DI(x, n);
    int nearestAbove = x;
    int nearestBelow = x;
    set<int> vals;
    F(i, 0, n)
    {
    	int y;
    	SI(y);
    	vals.insert(y);
    }
    while(vals.count(nearestAbove))
    	++nearestAbove;
    while(vals.count(nearestBelow))
    	--nearestBelow;
    if(abs(nearestBelow - x) <= abs(nearestAbove - x))
    	SO(nearestBelow);
    else
    	SO(nearestAbove);
    
    #ifdef LOCAL
    	cout<<endl<<endl<<"Time: "<<(float)clock()/CLOCKS_PER_SEC<<" seconds"<<endl;
    #endif
    return 0;
}

Measured memory_bytes: 3656
n, m = map(int, input().split())
height = list(map(int, input().split()))
anslist = [1] * n
for x in range(m):
    a, b = map(int, input().split())
    if height[a - 1] == height[b - 1]:
        anslist[a - 1] = 0
        anslist[b - 1] = 0
    elif height[a - 1] < height[b - 1]: anslist[a - 1] = 0
    else: anslist[b - 1] = 0
print(sum(anslist))


Measured memory_bytes: 20124
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>

using namespace std;

int pow2(int a) {
	if (a == 0) { return 1; }
	return 2 * pow2(a - 1);
}

int main() {
	int N, D, G[13];
	int cn, P[13];
	int k,M[13],L[13];
	int s, ans, last;

	scanf("%d", &N);
	
	for (int i = 0; i < 13; i++) {
		G[i] = 0;
	}


	for (int i = 0; i < N; i++) {
		scanf("%d", &D);
		G[D]++;
	}

	if (G[0] > 0) { printf("0\n"); return 0; }
	for (int i = 1; i < 12; i++) {
		if (G[i] > 2) {
			printf("0\n");
			return 0;
		}
	}
	if (G[12] > 1) { printf("0\n"); return 0;}

	cn = 0;
	for (int i = 1; i < 12; i++) {
		if (G[i] == 1) {
			P[cn] = i;
			cn++;
		}
	}

	ans = 0;
	for (int i = 0; i < pow2(cn); i++) {
		k = i;
		for (int j = 0; j < cn; j++) {
			M[j] = k % 2;/*M[j]が0なら午前*/
			k = k / 2;
		}

		for (int j = 0; j < 24; j++) {
			L[j] = 0;
		}

		L[0] = 1;
		for (int j = 1; j < 12; j++) {
			if (G[j] == 2) {
				L[j] = 1; L[24 - j] = 1;
			}
		}
		if (G[12] == 1) { L[12] = 1; }
	
		for (int j = 0; j < cn; j++) {
	
			if (M[j] == 0) { L[P[j]] = 1; }
			else { L[24 - P[j]] = 1; }
		}


		s = 24;
		last = 0;
		for (int j = 1; j < 24; j++) {
			if (L[j] == 1) { 
				if (s > j - last) { s = j - last; } 
				last = j;
			}
		}
		if (s > 24 - last) { s = 24 - last; }
		if (ans < s) { ans = s; }
		
	}

	printf("%d\n", ans);
	
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int A,B,C,X;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A>>B>>C>>X;
	int ret=0;
	for(x=0;x<=A*500;x+=500) {
		for(y=0;y<=B*100;y+=100) {
			for(int z=0;z<=C*50;z+=50) {
				ret+=(x+y+z==X);
			}
		}
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int a, b;
    
    scanf("%d %d", &a, &b);
    
    if(a < b){
        printf("a < b\n");
    }
    
    else if(a > b){
        printf("a > b\n");
    }
    
    else {
        printf("a == b\n");
    }
    
    return 0;
}


Measured memory_bytes: 2108
#include <iostream>
#include <cstdio>
using namespace std;
const int MAX = 10005;
int c[MAX];
int main(void)
{
	int n;
	int *a, *b;
	scanf("%d", &n);
	a = new int[n + 1];
	b = new int[n + 1];
	for (int i = 0; i < n; ++i)
	{
		scanf("%d", &a[i]);
		++c[a[i]];
	}
	
	for (int i = 1; i <= MAX; ++i)
		c[i] += c[i - 1];
	
	for (int i = 0; i < n; ++i)
	{
		b[c[a[i]]--] = a[i];
	}
	printf("%d", b[1]);
	for (int i = 2; i <= n; ++i)
	{
		printf(" %d", b[i]);
	}
	putchar('\n');
	return 0;
}

Measured memory_bytes: 18816
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

ll mod(ll a){
  return (a % 1000000007);
}

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


int main(){
  ll n; string s; cin >> n >> s;
  
  ll maxcommon = 0;
  
  for(ll i=1; i < n; i++){
    
    set<char> first; 
    ll common = 0;
    
    for(ll j=0; j < i; j++){
      first.insert(s[j]);
    }
    for(ll j=i; j < n; j++){
      if(first.count(s[j])){
        common++;
        first.erase(s[j]);
      }
    }
    
    maxcommon = max(maxcommon,common);
    
  }
  
  cout << maxcommon << endl;

  
}

Measured memory_bytes: 256
#E
N=int(input())
x=[0]*N
y=[0]*N
z=[0]*N

for i in range(N):
    x[i],y[i] = map(int,input().split())
    z[i]=  [x[i],y[i],x[i]+y[i]] 

z.sort(key=lambda x:(x[0]+x[1]) )
a=z[0]
b=z[-1]

z.sort(key=lambda x:(x[0]-x[1]) )
c=z[0]
d=z[-1]

al=[a,b,c,d]
#print(al)
ans=0

l=len(al)
for i in range(l):
    for j in range(i+1,l):
        tmp= abs(al[i][0]-al[j][0])+ abs(al[i][1]-al[j][1])
        ans= max(ans,tmp)
print(ans)

Measured memory_bytes: 113092
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n); ++i)
#define rep1(i,n) for (int i=1; i<=(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";
const ll mod = 998244353;
const double e = 0.000000001;
int main(){
  ll a,b,c,d; cin >> a >> b >> c >> d;
  cout << ((abs(a-b)<=d&&abs(c-b)<=d)||abs(a-c)<=d ? yes:no);
  return 0;
}


Measured memory_bytes: 3636
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
        int ans = 0;
        for(int i = 105; i <= n; i++){
            if(i % 2 == 1){
            	int count = 0;
        		for(int j = 1; j <= i; j++){
            		if(i % j == 0){
                		count++;
                	}
            	}
            	if(count == 8){
            		ans++;
            	}
            }
        }
        System.out.println(ans);
    }
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;

int search(vector<int>& v, int key)
{
  int n = v.size();
  int left = 0, right = n - 1;
  while (left <= right) {
    int mid = (left + right) / 2;
    if (key == v[mid]) { return 1; }
    else if (key < v[mid]) { right = mid - 1; }
    else { left = mid + 1; }
  }
  return 0;
}

int main()
{
  int n, q;
  fscanf(stdin, "%d", &n);
  vector<int> S(n);
  for (int i = 0; i < n; ++i) {
    fscanf(stdin, "%d", &S[i]);
  }
  fscanf(stdin, "%d", &q);
  int val = 0, ans = 0;
  for (int i = 0; i < q; ++i) {
    fscanf(stdin, "%d", &val);
    ans += search(S, val);
  }
  fprintf(stdout, "%d\n", ans);
  return 0;
}

Measured memory_bytes: 1528
#include<stdio.h>
int main()
{
    int p,q,r,maxx=0;
    scanf("%d%d%d",&p,&q,&r);
    if(p>maxx)
    {
        maxx=p;

    } if(q>maxx)
    {
        maxx=q;
    } if(r>maxx)
    {
        maxx=r;
    }
    printf("%d\n",p+q+r-maxx);

    return 0;
}




Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define f(i,j,k) for(int i=j;i<k;i++)
int main(){
    long long h,w;
    cin>>h>>w;
    if(h==1||w==1){
        cout<<1<<endl;
    }
    else if(h%2==1&&w%2==1){
        cout<<(h*w+1)/2<<endl;
    }
    else{
        cout<<h*w/2<<endl;
    }
    return 0;
}

Measured memory_bytes: 256