akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <list>
#include <math.h>
#include <string.h>
using namespace std;

typedef pair<int, int> P;
#define INF (1<<60)
#define int long long
#define ll long long
#define mod 1000000007


signed main(){

	int N;
	vector<int> v(100000);

	cin >> N;
	for (int i = 0; i < N; i++){
		int t;
		cin >> t;
		v[t] ++;
	}

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

	int r = -INF;
	for (int i = 0; i < N; i++){
		if (i==0)
			r = max(r, v[i] + v[i + 1]);
		else if (i==N-1)
			r = max(r, v[i - 1] + v[i]);
		else
			r = max(r, v[i - 1] + v[i] + v[i + 1]);
	}
	cout << r << endl;


	return 0;
}


Measured memory_bytes: 1024
nm = input().split(' ');
n = int(nm[0]);
m = int(nm[1]);

ans = [10]*n;
check = 1;

for i in range(m) :
    sc = input().split(' ');
    s = int(sc[0]);
    c = int(sc[1]);
    if s == 1 and c == 0 and n > 1:
        check = 0;
    elif ans[s-1] < 10 and (not(ans[s-1] == c)) :
        check = 0;
    else :
        ans[s-1] = c;

if n > 1 and ans[0] == 10 :
    ans[0] = 1;
if n == 1 and ans[0] == 10 :
    ans[0] = 0;
for i in range(1,n):
    if ans[i] == 10:
        ans[i] = 0;

if check :
    for i in range(n) :
        print(ans[i], end="");
    print();
else :
    print(-1);



Measured memory_bytes: 3064
dish = []
amari = []
for i in range(5):
  s = int(input())
  dish.append(s)
  if s % 10 != 0:
    a = 10 - s % 10
  else:
    a = 0
  amari.append(a)

final = amari.index(max(amari))
score = 0
for i in range(5):
  if i == final:
    score += dish[final]
  else:
    if dish[i] % 10 == 0:
      score += dish[i]
    else:
      score += (dish[i] // 10 + 1) * 10
      
print(score)

  


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = (ll)1e9+7;
ll sum(ll x)
{
    return x*(x-1)/2;
}
int main()
{
    int n,k;
    cin>>n>>k;
    ll ans=0;
    for(int i=k;i<=n;i++)
    {
        ll t1=sum(i);
        ll t2 = sum(n+1)-sum(n-i+1);
        ans+= t2-t1+1;
    }
    ans++;
    ans%=mod;
    cout<<ans<<endl;
}


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

int main() {

    int i;
    int n;
    int k;
    cin >> n;
    cin >> k;

    int move_sum = 0;
    int x[n];
    for(i=0; i<n; i++){
        cin >> x[i];
        if( x[i] <= ( k - x[i] )){
            move_sum += x[i] * 2;
        }
        else{
            move_sum += ( k - x[i] ) * 2;
        }
    } 

    cout << move_sum << endl;

}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int kata, kecilkan;
	scanf("%d %d", &kata, &kecilkan);
	char huruf[kata+5];
	scanf("%s", huruf);
	huruf[kecilkan-1] += 32;
	printf("%s", huruf);
	
	return 0;
}

Measured memory_bytes: 1680
NumSeq, MaxNum = map(int, input().split())
mod = 10**9 + 7

# List containing the number of sequences for each greatest common divisor.
num_sequence_list = [0] * (MaxNum + 1)

total_value = 0
for i_divisor in range(MaxNum, 0, -1):
    num_sequence = pow(MaxNum//i_divisor, NumSeq, mod)

    for j_multiple in range(2, MaxNum//i_divisor+1):
        num_sequence -= num_sequence_list[i_divisor*j_multiple]

    num_sequence_list[i_divisor] = num_sequence
    total_value += num_sequence * i_divisor

print(total_value % mod)

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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<int,int> p;

int n,T;
int t[200200];

int main(){
  cin >> n >> T;
  ll ans =0;
  cin >> t[0];
  rep(i,1,n){
    cin >> t[i];
    if(t[i]-t[i-1]<T){
      ans += t[i]-t[i-1];
    }else{
      ans += T;
    }
  }
  ans += T;
  cout << ans << endl;
}


Measured memory_bytes: 1024
n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(m)]
ab = list(map(list, set(map(tuple, ab))))
ans = [True] * n

for a, b in ab:
    if h[a-1] == h[b-1]:
        ans[a-1] = False
        ans[b-1] = False
    elif h[a-1] < h[b-1]:
        ans[a-1] = False
    else:
        ans[b-1] = False

print(ans.count(True))

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

int N;
int A[110][2];
int ans[110][2];

int main() {
	std::cin >> N;
	for (int i = 0; i < N; i++) {
		int tmp;
		std::cin >> tmp;
		if (tmp % 2 == 0) {
			A[i][0] = 1;
			A[i][1] = 2;
		}
		else {
			A[i][0] = 2;
			A[i][1] = 1;
		}
	}
	ans[0][0] = A[0][0];
	ans[0][1] = A[0][1];
	for (int i = 1; i < N; i++) {
		ans[i][0] = 3 * ans[i - 1][0] + ans[i - 1][1] * A[i][0];
		ans[i][1] = ans[i - 1][1] * A[i][1];
	}
	std::cout << ans[N - 1][0] << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
const int INF = 2e9;
const int MOD = 1e9 + 7;

const int mod = 1000000007;
struct mint {
   ll x;
   mint(ll x = 0) : x((x % mod + mod) % mod) {}
   mint operator-() const { return mint(-x); }
   mint& operator+=(const mint a) {
      if ((x += a.x) >= mod) x -= mod;
      return *this;
   }
   mint& operator-=(const mint a) {
      if ((x += mod - a.x) >= mod) x -= mod;
      return *this;
   }
   mint& operator*=(const mint a) {
      (x *= a.x) %= mod;
      return *this;
   }
   mint operator+(const mint a) const { return mint(*this) += a; }
   mint operator-(const mint a) const { return mint(*this) -= a; }
   mint operator*(const mint a) const { return mint(*this) *= a; }
   mint pow(ll t) const {
      if (!t) return 1;
      mint a = pow(t >> 1);
      a *= a;
      if (t & 1) a *= *this;
      return a;
   }

   mint inv() const { return pow(mod - 2); }
   mint& operator/=(const mint a) { return *this *= a.inv(); }
   mint operator/(const mint a) const { return mint(*this) /= a; }
};

mint c[4005][4005];
void init() {
   c[0][0] = 1;
   rep(i, 0, 4001) {
      rep(j, 0, i + 1) {
         c[i + 1][j] += c[i][j];
         c[i + 1][j + 1] += c[i][j];
      }
   }
}
mint comb(int n, int k) { return c[n][k]; }
mint f2(int n, int k) { return comb(n + k - 1, k - 1); }
mint f(int n, int k) {
   if (n < k) return 0;
   if (n == 0 && k == 0) return 1;
   if (k < 1) return 0;
   return f2(n - k, k);
}

int main() {
   init();
   int n, k;
   cin >> n >> k;
   rep(i, 1, k + 1) {
      mint blue = f(k, i);
      mint red = 0;

      red += f(n - k, i - 1);
      red += f(n - k, i);
      red += f(n - k, i);
      red += f(n - k, i + 1);
      mint ans = blue * red;
      printf("%lld\n", ans.x);
   }
   return 0;
}

Measured memory_bytes: 125568
#include<stdio.h>

int main(){
    int num = 0;
    char symbol[5];
    scanf("%s", symbol);

    for(int i=0; i<4; i++){
        if('+' == symbol[i]){
            num++;
        }else if('-' == symbol[i]){
            num--;
        }
    }

    printf("%d\n", num);

}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <queue>

using ll = long long;
const ll INF = (ll)1e18;

ll dy[4] = {  0,  0, -1, +1};
ll dx[4] = { -1, +1,  0,  0};

ll H, W, V;

typedef struct {
  ll to;
  ll cost;
} S_Edge;

template<typename Head> void print(Head head){ std::cout << head << std::endl; }

ll pos2idx(ll y, ll x) { return y * W + x; }

void make_map(std::vector< std::string >& grid, std::vector< std::vector<S_Edge> >& vedge)
{
  for (ll y = 0; y < H; y++) {
    for (ll x = 0; x < W; x++) {
      for (ll d = 0; d < 4; d++) {
	ll ny = y + dy[d];
	ll nx = x + dx[d];
	if (ny >= 0 && nx >= 0 && ny < H && nx < W) {
	  S_Edge edge;
	  edge.to   = pos2idx(ny, nx);
	  edge.cost = grid[y][x] == grid[ny][nx] ? INF : 1;
	  vedge[pos2idx(y, x)].push_back(edge);
	}
      }
    }
  }
}

//  #
// #.#.#.#.
//  #
//
// のような場合, 開始地点の候補数(=黒の数) * 終了地点の候補数(=白の数) を求めれば良いので,
// 6 * 4 = 24 通りになる.
// 複雑な経路であっても, 黒白が交互であれば, どの黒から始めても, どの白でも終わることができるため.
ll count_paths_and_upload_visit(ll s, std::string& idx_grid,
				std::vector< std::vector<S_Edge> >& vedge,
				std::vector< bool >& was_visited)
{
  ll black = 0;
  ll white = 0;
  std::queue<ll> que;

  que.push(s);
  was_visited[s] = true;
  black += idx_grid[s] == '#' ? 1 : 0;
  white += idx_grid[s] == '.' ? 1 : 0;

  while (!que.empty()){
    ll v = que.front(); que.pop();
    for (auto it = vedge[v].begin(); it != vedge[v].end(); it++) {
      if (!was_visited[it->to] && it->cost != INF) {
	que.push(it->to);
	was_visited[it->to] = true;
	black += idx_grid[it->to] == '#' ? 1 : 0;
	white += idx_grid[it->to] == '.' ? 1 : 0;
      }
    }
  }

  return black * white;
}

int main()
{
  std::cin >> H >> W;
  V = H * W;

  std::vector< std::string > grid(H, std::string(W, 'X'));
  std::string idx_grid;
  for (ll y = 0; y < H; y++) {
    std::cin >> grid[y];
    idx_grid += grid[y];
  }

  std::vector< std::vector<S_Edge> > vedge(V);
  make_map(grid, vedge);

  std::vector< bool > was_visited(V);

  ll ans = 0;
  for (ll v = 0; v < V; v++) {
    if (was_visited[v]) continue;
    ans += count_paths_and_upload_visit(v, idx_grid, vedge, was_visited);
  }

  print(ans);
  return 0;
}


Measured memory_bytes: 16896
from bisect import bisect
from itertools import product


N = int(input())
S = input()

indices = [list() for _ in range(10)]
for i,c in enumerate(S):
    indices[int(c)].append(i)

cnt = 0
for a,c in product(range(10), repeat=2):

    if not indices[a] or not indices[c]:
        continue

    i = indices[a][0]
    j = indices[c][-1]
    if i == j:
        continue
    for l in indices:
        if l:
            k = bisect(l, i)
            if k < len(l) and l[k] < j:
                cnt += 1
print(cnt)

Measured memory_bytes: 4456
using System;
using System.Linq;

namespace ABC085_D
{
    class Program
    {
        static void Main(string[] args)
        {
            var NH = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var N = NH[0];
            var H = NH[1];
            var k = new int[2];
            var a = new int[N];
            var b = new int[N];

            for (int i = 0; i < N; i++)
            {
                k = Console.ReadLine().Split().Select(int.Parse).ToArray();
                a[i] = k[0];
                b[i] = k[1];
            }

            var ma = a.Max();
            var cnt = 0;
            foreach (var x in b.Where(x => x > ma).OrderByDescending(x => x))
            {
                H -= x;
                cnt++;
                if (H <= 0) break;
            }

            Console.WriteLine(cnt += H <= 0 ? 0 : (H / ma + (H % ma == 0 ? 0 : 1)));
        }
    }
}


Measured memory_bytes: 20036
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////


void solve() {
	int a; cin >> a;
	cout << 3 * a * a << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 256
use proconio::*;
#[allow(unused_imports)]
use proconio::marker::*;

#[allow(unused_macros)]
macro_rules! echo {
    ($ x : expr ) => {
        println!("{}", $x);
    };
}

#[fastout]
#[allow(non_snake_case)]
fn main() {
    input! {
        A: usize, B: usize, C: usize
    }
    echo!(format!("{} {} {}", C, A, B));
}


Measured memory_bytes: 2180
#include <iostream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#define INF 1e+11
#define EPS 1e-11
using namespace std;

struct edge{ int to;double cost; };
typedef pair<double,int> P;

int main(){
	int n;
	double x[1002],y[1002],r[1002],d[1002];
	vector<edge> G[1002];
	cin >> x[0] >> y[0] >> x[1] >> y[1] >> n;
	for(int i = 0;i < n + 2;i++) d[i] = INF;
	d[0] = 0.0;
	r[0] = 0.0;
	r[1] = 0.0;
	for(int i = 0;i < n;i++) cin >> x[i + 2] >> y[i + 2] >> r[i + 2];
	for(int i = 0;i < n + 2;i++){
		for(int j = 0;j < n + 2;j++){
			if(i == j) continue;
			double d = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j])) - r[i] - r[j];
			if(d < 0.0 + EPS) d = 0.0;
			G[i].push_back({j,d});
			G[j].push_back({i,d});
		}
	}
	priority_queue<P,vector<P>,greater<P> > que;
	que.push(P(0.0,0));
	while(!que.empty()){
		P p = que.top();que.pop();
		int v = p.second;
		if(d[v] < p.first) continue;
		for(int i = 0;i < G[v].size();i++){
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost){
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to],e.to));
			}
		}
	}
	printf("%.12f\n",d[1]);
	return 0;
}

Measured memory_bytes: 38452
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<62;
const ll mod=1e9+7;

int main(){
  int i,j;
  ll n,k;
  cin>>n>>k;
  VI a(n);
  for(i=0;i<n;i++) cin>>a[i];
  ll ne=0;
  ll po=0;
  ll po2=0;
  for(i=0;i<n;i++){
    if(a[i]<0) ne++;
    else po++;
    if(a[i]>0) po2++;
  }
  sort(a.begin(),a.end());
  VI b,c;
  for(i=0;i<n;i++){
    if(a[i]<0) b.pb(-a[i]);
    else c.pb(a[i]);
  }
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());
  if(k>=ne*po2+1&&k<=n*(n-1)/2-ne*(ne-1)/2-po2*(po2-1)/2) {
    cout<<0<<endl;
    return 0;
  }
  //for(i=0;i<b.size();i++) cout<<b[i]<<endl;
  if(k>=ne*po+1){
    ll l=0,r=INF;
    k-=ne*po;
    while(r-l>1){
      ll m=(l+r)/2;
      ll cnt=0;
      for(i=0;i<b.size();i++){
        cnt+=upper_bound(b.begin(),b.end(),m/b[i])-b.begin();
        if(b[i]*b[i]<=m) cnt--;
      }
      for(i=0;i<c.size();i++){
        if(c[i]==0) cnt+=c.size();
        else cnt+=upper_bound(c.begin(),c.end(),m/c[i])-c.begin();
        if(c[i]*c[i]<=m) cnt--;
      }
      cnt/=2;
      if(cnt>=k) r=m;
      else l=m;
    }
    cout<<r<<endl;
    return 0;
    }
    else{
      k=ne*po-k+1;
      ll l=0,r=INF;
      while(r-l>1){
      ll m=(l+r)/2;
      ll cnt=0;
      for(i=0;i<b.size();i++){
        cnt+=upper_bound(c.begin(),c.end(),m/b[i])-c.begin();
      }
      if(cnt>=k) r=m;
      else l=m;
    }
    cout<<-r<<endl;
    return 0;
    }
}
  


Measured memory_bytes: 4084
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;

string s;

int parse(int &p, bool& op, int d=1);
 
int num(int &p){
	int res = 0;
	if(p>=s.size()) throw 0;
	if(s[p] == '('){
		bool op=false;
		res = parse(++p, op);
		if(!op || p>=s.size() || s[p++] != ')') throw 0;
	}else{
		if(!isdigit(s[p])) throw 0;
		for(;p<s.size()&&isdigit(s[p]);++p) res = res*2+s[p]-'0';
	}
	return res;
}
 
int parse(int &p, bool& op, int d){
	int res = d?parse(p, op, d-1) : num(p);
	if(res < 0 || 1024 <= res) throw 0;
	while(p<s.size()){
		if(d == 0 && s[p] == '*'){
			op = 1;
			res *= num(++p);
		}else if(d == 1 && s[p] == '+'){
		 	op = 1;
		   res += parse(++p, op, 0);
		}else if(d == 1 && s[p] == '-'){
			op = 1;
			res -= parse(++p, op, 0);
		}else break;
		if(res < 0 || 1024 <= res) throw 0;
	}
	return res;
}

int n;
string tbl = "01+-*()";
int solve(string t){
	REP(i, t.size()){
		if(t[i] == '.'){
			int ans = -1;
			REP(j, 7){
				try{
					t[i] = tbl[j];
					ans = max(ans, solve(t));
				}catch(...){}
			}
			return ans;
		}
	}
	s = t;
	int p = 0;
	bool op;
	int res = parse(p, op);
	if(p != s.size()) throw 0;
	return res;
}
main(){
	string t;
	while(cin >> t){
		try{
			cout << solve(t) << endl;
		}catch(...){
			cout << -1 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	n := readi()
	s := make(map[string]int, n)
	for i := 0; i < n; i++ {
		tmp := reads()
		s[tmp]++
	}
	a := List{}
	b := List{}
	for k, v := range s {
		e := Entry{k, v}
		a = append(a, e)
	}
	sort.Sort(a)

	var max int
	for i := len(a) - 1; i >= 0; i-- {
		if i == len(a)-1 {
			max = a[i].value
		}
		if a[i].value != max {
			break
		}
		e := Entry{a[i].name, a[i].value}
		b = append(b, e)
	}
	sort.Sort(b)
	for i := 0; i < len(b); i++ {
		fmt.Println(b[i].name)
	}
}

// Entry hoge
type Entry struct {
	name  string
	value int
}

// List hoge
type List []Entry

func (l List) Len() int {
	return len(l)
}

func (l List) Swap(i, j int) {
	l[i], l[j] = l[j], l[i]
}

func (l List) Less(i, j int) bool {
	if l[i].value == l[j].value {
		return (l[i].name < l[j].name)
	}
	return (l[i].value < l[j].value)
}

func mid(a []int) int {
	sort.Ints(a)
	return a[len(a)/2]
}

func ave(a []int) (ave int) {
	for i := 0; i < len(a); i++ {
		ave += a[i]
	}
	ave /= len(a)
	return
}
func eq(a []string, b []string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] != b[i] {
			return false
		}
	}
	return true
}

// IO---------------------------------------------------

func readi() (n int) {
	fmt.Scan(&n)
	return
}

func readf() (n float64) {
	fmt.Scan(&n)
	return
}

func reads() (n string) {
	fmt.Scan(&n)
	return
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func readSlice() []string {
	return strings.Split(readLine(), " ")
}

func atoi(a []string) (b []int) {
	b = make([]int, len(a))
	for i := range a {
		b[i], _ = strconv.Atoi(a[i])
	}
	return
}

func atof(a []string) (b []float64) {
	b = make([]float64, len(a))
	for i := range a {
		b[i], _ = strconv.ParseFloat(a[i], 64)
	}
	return
}

func readSlice2(n int) (a []int, b []int) {
	a = make([]int, n)
	b = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

func readFloatSlice2(n int) (a []float64, b []float64) {
	a = make([]float64, n)
	b = make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

func yesOrNo(b bool) {
	if b {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}

func yesorNO(b bool) {
	if b {
		fmt.Println("YES")
		return
	}
	fmt.Println("NO")
}

func yesorno(b bool) {
	if b {
		fmt.Println("yes")
		return
	}
	fmt.Println("no")
}

// calc---------------------------------------------------

func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}

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

func min(a ...int) int {
	min := a[0]
	for i := 1; i < len(a); i++ {
		if min > a[i] {
			min = a[i]
		}
	}
	return min
}

func max(a ...int) int {
	max := a[0]
	for i := 1; i < len(a); i++ {
		if max < a[i] {
			max = a[i]
		}
	}
	return max
}

func sum(a []int) (ans int) {
	for i := range a {
		ans += a[i]
	}
	return
}

Measured memory_bytes: 44416
#include <bits/stdc++.h>
using namespace std;
/******************************************
* AUTHOR : PANDRAVISAM SHIVA SANTHOSH *
* Handle : santhosh_80 *
* INSTITUTION : IIT Palakkad *
******************************************/
#define ll long long int 
#define rep(i,a,b) for(int i=a;i<b;i++)
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define f first
#define s second

const ll mod = 1000000007;
const ll N = 1e6;


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s,t;
	cin >> s >> t;
	int flag = 0;
	for(int i =0 ; i < s.length(); i++){
		if(s[i]!=t[i])flag=1;
	}
	if(flag)cout << "No\n";
	else cout << "Yes\n";
 	return 0;
}

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

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

int main()
{
    ll i,j;
    ll a,b;
    cin >> a >> b;
    cout << 100 << " " << 100 << endl;
    vector<vector<char>> ans(100,vector<char>(100));
    for(i = 0;i < 50;++i){
        rep(j,100) ans.at(i).at(j) = '#';
    }
    for(i = 50;i < 100;++i){
        rep(j,100) ans.at(i).at(j) = '.';
    }
    bool flag = false;
    for(i = 1;i < 50;i += 2){
        for(j = 1;j < 100;j += 2){
            if(a == 1){
                flag = true;
                break;
            }
            ans.at(i).at(j) = '.';
            --a;
        }
        if(flag) break;
    }
    flag = false;
    for(i = 51;i < 100;i += 2){
        for(j = 1;j < 100;j += 2){
            if(b == 1){
                flag = true;
                break;
            }
            ans.at(i).at(j) = '#';
            --b;
        }
        if(flag) break;
    }
    for(i = 0;i < 100;++i){
        rep(j,99){
            cout << ans.at(i).at(j);
        }
        cout << ans.at(i).at(j) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [tuple(map(int, l.split())) for l in sys.stdin]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    a = sorted([I() for _ in range(5)])
    k = I()
    if a[-1] - a[0] > k:
        return ':('

    return 'Yay!'

print(main())




Measured memory_bytes: 5700
use std::io::stdin;

#[allow(dead_code)]
fn input_ints() -> Vec<i32> {
    let mut st = String::new();
    match stdin().read_line(&mut st) {
        Ok(_) => st.split_whitespace().map(|s| s.parse().unwrap()).collect(),
        Err(_) => "".split_whitespace().map(|s| s.parse().unwrap()).collect(),
    }
}

#[allow(dead_code)]
fn input_strs() -> Vec<String> {
    let mut st = String::new();
    match stdin().read_line(&mut st) {
        Ok(_) => st.split_whitespace().map(|s| s.to_string()).collect(),
        Err(_) => "".split_whitespace().map(|s| s.to_string()).collect(),
    }
}

#[allow(dead_code)]
fn input_int() -> i32 {
    let mut st = String::new();
    match stdin().read_line(&mut st) {
        Ok(_) => st.trim().parse().unwrap(),
        Err(_) => 0,
    }
}

fn odd(n: usize) -> bool {
    if n % 2 == 1 {
        true
    }
    else {
        false
    }
}

fn check(v: &Vec<i32>) -> bool {
    let n = v.len();
    let mut check_vec = vec![false; n];
    let usizev: Vec<usize> = v.iter().map(|i| *i as usize).collect();

    for i in usizev {
        if odd(i) == odd(n) {
            return false;
        }
        if check_vec[i] {
            if i == 0 {
                return false;
            }
            if check_vec[i-1] {
                return false;
            }
            else {
                check_vec[i-1] = true;
            }
        }
        else {
            check_vec[i] = true;
        }
    }
    return true;
}

fn expmod(radix: i32, exp: i32, m: i32) -> i32 {
   expmod_(1, radix, exp, m) 
}

fn expmod_(base: i32, radix: i32, exp: i32, m: i32) -> i32 {
    match exp {
        0 => base,
        _ => expmod_((base * radix) % m, radix, exp-1, m),
    }
}
    
#[allow(unused_variables)]
fn solve(){
    let n = input_int();

    let v = input_ints();

    if check(&v) {
        println!("{}", expmod(2, n/2, 1000000007));
    }
    else {
        println!(0);
    }
}

fn main() {
    solve();
}



Measured memory_bytes: 2172
let m = 1000000007
let ( +^ ) x y = (x + y) mod m
let ( -^ ) x y = x +^ (m - y)

let () = Scanf.scanf "%d %d\n" @@ fun n m ->
  let ss = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun s -> s in
  let ts = Array.init m @@ fun _ -> Scanf.scanf "%d " @@ fun t -> t in
  let dp = Array.make_matrix (n + 1) (m + 1) 1 in
  for i = 0 to n - 1 do
    for j = 0 to m - 1 do
      dp.(i + 1).(j + 1) <-
        dp.(i).(j + 1) +^ dp.(i + 1).(j)
        -^ if ss.(i) = ts.(j) then 0 else dp.(i).(j)
    done
  done;
  Printf.printf "%d\n" dp.(n).(m)


Measured memory_bytes: 33404
//嘘
#include <iostream>
#include <algorithm>
using namespace std;

int n, m;
int rui[200001];

int main() {
	cin >> n >> m;
	
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		if (a > b) swap(a, b);
		rui[a - 1]++;
		rui[b - 1]--;
	}
	
	for (int i = 1; i <= n; i++) rui[i] += rui[i - 1];
	
	for (int i = 0; i < n - 1; i++) {
		if (rui[i] % 2 != 0) {
			cout << "NO" << endl;
			return 0;
		}
	}
	
	cout << "YES" << endl;
	return 0;
}

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

if N%10==2 or N%10==4 or N%10==5 or N%10==7 or N%10==9:
  print('hon')
elif N%10==0 or N%10==1 or N%10==6 or N%10==8:
  print('pon')
elif N%10 == 3:
  print('bon')

Measured memory_bytes: 9180
#10**9+7のあまりを忘れていた
import math 
n=int(input())
d=dict()
for i in range(n):
    a,b=map(int,input().split())
    if a==0 and b==0:
        pass
    elif a==0:
        a,b=0,1
    elif b==0:
        a,b=1,0
    else:
        x=math.gcd(abs(a),abs(b))
        a,b=a//x,b//x
        if a<0:
            a,b=-a,-b
    if (a,b) in d:
        d[(a,b)]+=1
    else:
        d[(a,b)]=1
#こっからは数え上げ
#print(d)
ans1,ans2=1,0
for i in d:
    if d[i]==0:
        continue
    if i==(0,0):
        ans2=d[i]
        d[i]=0
        continue
    a,b=i
    if (-b,a) in d:
        ans1*=(2**(d[i])+2**(d[(-b,a)])-1)
        d[(-b,a)]=0
        d[i]=0
    elif (b,-a) in d:
        ans1*=(2**(d[i])+2**(d[(b,-a)])-1)
        d[(b,-a)]=0
        d[i]=0
    else:
        ans1*=(2**(d[i]))
        d[i]=0
print((ans1+ans2-1)%(10**9+7))

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll gcd(ll x,ll y){
  return y==0?x:gcd(y,x%y);
}

ll lcm(ll x,ll y){
  return (x/gcd(x,y))*y;
}

ll calc(ll x,ll y){
  return x/y;
}

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

  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  cout<<(b-a+1)+((calc(a-1,c)+calc(a-1,d)-calc(a-1,lcm(c,d)))-(calc(b,c)+calc(b,d)-calc(b,lcm(c,d))))<<endl;

  return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define FOR(NAME, START, NUM) for (int NAME = START; NAME < (NUM); NAME++)
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); NAME++)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; NAME--)
#define ALL(NAME) (NAME).begin(), (NAME).end()
const ll INF =1000000000000000;

int main(){
  ll n;
  cin >> n;
  int life = 1;
  vector<ll> a(n);
  REP(i,n){
    cin >> a.at(i);
  }
  
  sort(ALL(a));
  reverse(ALL(a));
  
  ll g=a.at(0);
  REP(i,n-1){
    g=__gcd(g,a.at(i+1));
  }
  
  ll x=a.at(0);
  ll y=a.at(1);
  REP(i,n-1){
    if(i!=0)y=x;
    x=__gcd(x,a.at(i+1));
    if(x==g && life==1){
      x=y;
      life=0;
    }
  }
  life=1;
  ll z=a.at(0);
  ll t;
  REP(i,n-1){
    t=z;
    z=__gcd(z,a.at(i+1));
    if(z==g && life==1){
      z=t;
      life=0;
    }
  }
  cout<<max(x,z)<<endl;
}

Measured memory_bytes: 1024
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <iterator>
#include <algorithm>
#include <cfenv>
#include <random>
#include <numeric>
#include <cmath>
#include <iosfwd>
#include <iostream>
#include <ios>
#include <streambuf>
#include <istream>
#include <ostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <cstdlib>
#include<string>
#include <bitset>

#define SIZE 100001
typedef long long ll;
using namespace std;

int main(){
    int N;
    ll L[101];
    ll tri=0;
    cin >> N;
    for(int i = 0 ; i < N ; i++){
        cin >> L[i];
    }
    for(int i = 0 ; i < N ; i++){
        for(int j = i+1 ; j < N ; j++){
            for(int k = j+1 ; k < N ; k++){
                if(L[i] != L[j] && L[j] != L[k] && L[k] != L[i]){
                    ll max = L[i];
                    ll e = L[j] + L[k];
                    if(L[j] > max){
                        max = L[j];
                        e = L[i]+L[k]; 
                    }
                    if(L[k] > max){
                        max = L[k];
                        e = L[j]+L[i];
                    }
                    if(e > max){
                        tri++;
                    }
                }
            }
        }
    }
    cout << tri << endl;
    return 0;
}

Measured memory_bytes: 3556
from sys import stdin
import math
import re
import queue

input = stdin.readline

MOD = 1000000007
INF = 122337203685477580

def solve():
    N,K = map(int, input().split())
    if(K > N%2 + N/2):
        print("NO")
    else:
        print("YES")

    
if __name__ == '__main__':
    solve()


Measured memory_bytes: 3940
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <utility>
#include <algorithm>

const int N = 1e5 + 10, INF = 1e7;
int n, rt, f[N], p[N], k;
std::vector<int> to[N], c[N];
std::pair<int, int> r[N];
bool o1, o2, d[N], h[N], res;

inline std::pair<int, int> merge(std::pair<int, int> a, std::pair<int, int> b) {
    return std::make_pair(std::max(a.first, b.first), std::min(a.second, b.second));
}

void build(int cur) {
    for (int i : to[cur])
        if (i != f[cur]) {
            c[cur].push_back(i);
            f[i] = cur;
            d[i] = !d[cur];
            build(i);
        }
}

void dfs(int cur) {
    for (int i : c[cur]) {
        dfs(i);
        r[cur] = merge(r[cur], std::make_pair(r[i].first - 1, r[i].second + 1));
    }
    if (r[cur].first > r[cur].second)
        res = true;
}

void query(int cur) {
    p[cur] = r[cur].first;
    if (cur != rt && p[cur] == p[f[cur]])
        p[cur]++;
    for (int i : c[cur]) {
        r[i] = merge(r[i], std::make_pair(p[cur] - 1, p[cur] + 1));
        query(i);
    }
}

int main() {
    scanf("%d", &n);
    rt = 1;
    for (int i = 1; i < n; i++) {
        static int t1, t2;
        scanf("%d%d", &t1, &t2);
        to[t1].push_back(t2);
        to[t2].push_back(t1);
    }
    build(rt);
    for (int i = 1; i <= n; i++)
        r[i] = std::make_pair(-INF, INF);
    scanf("%d", &k);
    for (int i = 1; i <= k; i++) {
        static int t1, t2;
        scanf("%d%d", &t1, &t2);
        h[t1] = true;
        p[t1] = t2;
        r[t1] = std::make_pair(t2, t2);
        ((d[t1] ^ (t2 & 1)) ? o1 : o2) = true;
    }
    if (o1 && o2) {
        puts("No");
        return 0;
    }
    dfs(rt);
    if (!res) {
        puts("Yes");
        query(rt);
        for (int i = 1; i <= n; i++)
            printf("%d\n", p[i]);
    } else {
        puts("No");
    }
    return 0;
}



Measured memory_bytes: 19840
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;

int main() {
	int a, b, c;
	int sum = 0;
	cin >> a >> b >> c;
	for (int i = 0; i < 100; i++) {
		sum += a;
		//cout << sum << endl;
		if (sum%b == c) {
			cout << "YES" << "\n";
			return 0;
		}
	}
	cout << "NO\n";
	return 0;
}

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

map < int, int > ps;

int num (int m) {
    int res = 0;
    for (auto pr: ps) {
        if (pr.second >= m - 1)
            ++res;
    }
    return res;
}

signed main () {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        int m = i;
        for (int j = 2; j * j <= m; ++j) {
            while (m % j == 0) {
                ++ps[j];
                m /= j;
            }
        }
        if (m != 1) 
            ++ps[m];
    }
    cout << num(75) + num(25) * (num(3) - 1) + num(15) * (num(5) - 1) + num(5) * (num(5) - 1) * (num(3) - 2) / 2 << '\n';
}


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

namespace Dynamic_Programming
{
    class Fibonacci_Number
    {
        static Dictionary<int, long> fib;

        static void Main(string[] args)
        {
            fib = new Dictionary<int, long>();
            fib.Add(0, 1);
            fib.Add(1, 1);
            Console.WriteLine(Fib(int.Parse(Console.ReadLine())));
        }

        static long Fib(int n)
        {
            if (fib.ContainsKey(n)) return fib[n];
            else  {
                var f= Fib(n - 1) + Fib(n - 2);
                fib.Add(n, f);
                return f;
            }
        }
    }
}

Measured memory_bytes: 9708
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ld err=0.000000001;
#define    N       2000005
#define   ESP     1e-9
#define    pii      pair<int,int>
#define    vi       vector<int>
#define    vl       vector<ll>
#define    pb       push_back
#define    pp       pop_back
vector<pair<ll,ll>> v;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        ll a,b;
        cin>>a>>b;
        v.push_back(make_pair(a,b));
    }
    sort(v.begin(),v.end());
    ll ans=0;
    for(int i=0;i<v.size();i++){
        if(v[i].second<=m) {
            ans+=v[i].first*v[i].second;
            m=m-v[i].second;
        }
        else{
            ans+=v[i].first*m;
            m=0;
            break;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

int arr[100001] = {};
int dp[100001] = {};

int main() {
	int n;
	cin >> n;
	for(int i=0;i<n;i++) {
		cin >> arr[i];
	}
	dp[1] = abs(arr[0]-arr[1]);
	for(int i=2;i<n;i++) {
		dp[i] = min(dp[i-1] + abs(arr[i]-arr[i-1]), dp[i-2] + abs(arr[i]-arr[i-2]));
	}
	printf("%d", dp[n-1]);
}

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

/**
 * Lesson10B 三角形の２辺 a, b とその間の角 C から、
 * その三角形の面積 S、周の長さ L, a を底辺としたときの高さ h を求めるプログラム
 * @author Internship
 *
 */
public class Main{

	/**
	 * プログラムのエントリポイント
	 *
	 * @param args
	 */
	public static void main(String[] args) {

		// 1行目を取得
		try {
			BufferedReader insBR = new BufferedReader(new InputStreamReader(System.in));

			String strLine = insBR.readLine();

			// 分解
			String[] strAryLine1 = strLine.split(" ");

			// intにキャスト
			// Aの値
			double dbA = Double.parseDouble(strAryLine1[0]);

			// Bの値
			double dbB = Double.parseDouble(strAryLine1[1]);

			// 角度
			int intAngle = Integer.parseInt(strAryLine1[2]);

			//面積S
			double dbAreaS = 0.0;

			//周囲L
			double dbSurroundingsL = 0.0;

			//高さH
			double dbHeight = 0.0;

			// 計算

			//sin値
			double dbSin = Math.sin(Math.toRadians(intAngle));
			
			//cos値
			double dbCos= Math.cos(Math.toRadians(intAngle));

			//面積S
			//a * b * sinC
			dbAreaS = dbA * dbB / 2 * dbSin;			

			//cc=aa+bb−2ab cosC
			
			double dbC = (dbA * dbA) +  (dbB * dbB) - (2 * dbA * dbB * dbCos);
			
			dbC = Math.sqrt(dbC);

			//周囲L
			dbSurroundingsL = dbA + dbB + dbC;

			//高さH = 面積 / 1辺 * 2
			dbHeight = dbAreaS / dbA * 2;

			//出力
			System.out.println(dbAreaS);

			System.out.println(dbSurroundingsL);

			System.out.println(dbHeight);


		} catch (IOException e) {
			System.out.println(e);
		} catch (NumberFormatException e) {
			System.out.println("数字で入力して下さい");
		}
	}
}

Measured memory_bytes: 16916
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#define RG register
#define IL inline
#define inf 2147483640
#define LL long long
#define pi acos(-1.0)
#define db double
#define N 1005
using namespace std;
IL int gi()
{
	RG int res=0,w=1;
	RG char ch;
	for(ch=getchar();(ch<'0'||ch>'9')&&ch!='-';ch=getchar());
	if(ch=='-') w=-1,ch=getchar();
	for(;ch>='0'&&ch<='9';ch=getchar()) res=10*res+ch-48;
	return res*w;
}
int n,fa[N],head[N],edge[N][2],num,sum[N],tot[N];
int dp[2][5005];
IL void adde(RG int u,RG int v)
{
	edge[++num][0]=v,edge[num][1]=head[u];head[u]=num;
}
IL int dfs(RG int p)
{
	for(RG int i=head[p];i;i=edge[i][1])
		if(!dfs(edge[i][0])) return 0;
	if(!head[p]) {tot[p]=sum[p]; return 1;}
	for(RG int i=head[p];i;i=edge[i][1])
		tot[p]+=tot[edge[i][0]];
	memset(dp,0,sizeof(dp));
	dp[0][0]=1;
	RG int now=0;
	for(RG int i=head[p];i;i=edge[i][1])
		{
			now^=1;
			for(RG int j=0;j<=sum[p];++j) dp[now][j]=0;
			for(RG int j=sum[p]-sum[edge[i][0]];j>=0;--j)
				dp[now][j+sum[edge[i][0]]]|=dp[now^1][j];
			for(RG int j=sum[p]-(tot[edge[i][0]]-sum[edge[i][0]]);j>=0;--j)
				dp[now][j+(tot[edge[i][0]]-sum[edge[i][0]])]|=dp[now^1][j];
		}
	RG int flag=0;
	for(RG int i=sum[p];i>=0;--i)
		if(dp[now][i]) {tot[p]+=sum[p]-i;flag=1;break;}
	return flag;
}
int main()
{
	//freopen("3.in","r",stdin);
	//freopen("3.out","w",stdout);
	n=gi();fa[1]=0;
	for(RG int i=2;i<=n;++i) fa[i]=gi(),adde(fa[i],i);
	for(RG int i=1;i<=n;++i) sum[i]=gi();
	if( dfs(1) ) printf("POSSIBLE");
	else printf("IMPOSSIBLE");
	//fclose(stdin);fclose(stdout);
	return 0;
}

Measured memory_bytes: 256
n =  int(input())
s = [input() for i in range(n)]
m = int(input())
t = [input() for i in range(m)]

d = {i: s.count(i)-t.count(i) for i in set(s)}
if max(d.values()) <-0:
    print(0)
else:
    print(max(d.values()))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main(){
  ll h,w,k ; cin>>h>>w>>k ;
  int d[h][w] ;
  rep(i,h){
    rep(j,w){
      char q ;cin>>q ;
      d[i][j]= q- '0' ;
    }
  }

ll bns=INF ;
  for( ll tmp = 0 ; tmp <( 1<<h-1) ; tmp++ ){
     bitset<9> s(tmp) ;
     int sum =0 ;
     rep(i,9) sum+= s[i] ;
     vector<ll> A(sum+1) ;
     ll ans=0 ;
     int ii=0 ;
     rep(xx,3*w){
      
       
       bool ok = 0;
       
       A[0] += d[0][ii] ;
       int j=0 ;
       rep(a,h-1){
        
        if(s[a]==1){
          j++ ;
        }

        A[j] += d[a+1][ii] ;
       } 

       rep(c,sum+1){
         if(A[c]>k) ok=1 ;
       }

       if(ok){
         ans++ ;
         rep(b,sum+1) A[b]=0 ;
         ii-- ;
       }
     
     ii++ ;

     if(ii==w) break ;
     
     /* if(xx==3*w-1){
       ans =INF-10 ;
     }
     */
     }
  
  chmin(bns,ans+sum) ;
  }
  cout<<bns<<endl ;
 return 0 ; 
}



Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
int main(){
    ll n;
    cin >> n;
    vector<pair<ll, ll>> ww(n);
    for (ll i = 0; i < n;i++){
        ll a, b;
        cin >> a >> b;
        ww[i].first = b;
        ww[i].second = a;
    }
    sort(ww.begin(), ww.end());
    ll cum = 0;
    for (ll i = 0; i< n;i++){
        cum += ww[i].second;
		if(cum>ww[i].first){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

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

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define fr(i,k) for(i=0;i<k;i++)
#define ALL(c) (c).begin(),(c).end()
#define deb(x) cerr<<#x<<"  = "<<x<<endl;
#define SZ(x) (x).size();
#define ll long long
#define MOD 1000000007
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define em emplace_back
#define ulli unsigned long long int
#define INF 1e18
#define endl "\n"
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> ii;
void solve();

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


int main() {
	fastio;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int t;
	t = 1;

	//cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}

vector<vector<ll>> dp(3005, vector<ll>(3005, -1));

string LCS(string &s1, string &s2, ll l)
{
	string ans = "";
	ll i = 0 , j = 0;

	while (l > 0)
	{
		if (s1[i] == s2[j])
		{
			ans += s1[i];
			i++;
			j++;
			l--;
		}
		else if (dp[i + 1][j] > dp[i][j + 1])
		{
			i++;
		}
		else
			j++;
	}

	return ans;
}

ll calc(string &s1, string &s2, ll i, ll j)
{
	if (i >= s1.size() || j >= s2.size())
		return 0;

	if (dp[i][j] != -1)
		return dp[i][j];

	if (s1[i] == s2[j])
	{
		return dp[i][j] = 1 + calc(s1, s2, i + 1, j + 1);
	}

	return dp[i][j] = max(calc(s1, s2, i, j + 1), calc(s1, s2, i + 1, j));
}

void solve()
{
	ll n, m, len;
	string s1, s2, s;
	cin >> s1 >> s2;

	n = s1.size();
	m = s2.size();

	len = calc(s1, s2, 0, 0);

	s = LCS(s1, s2, len);
	cout << s << endl;

}


Measured memory_bytes: 74620
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using ll = long long;
using namespace std;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

string S;
int main(){
    cin >> S;
    int sum = 0;
    rep(i,S.size()) sum += S[i] - '0';
    if(stoi(S)%sum) cout << "No" << '\n';
    else cout << "Yes" << '\n';
}

Measured memory_bytes: 256
import java.util.Scanner

fun main(args: Array<String>) {
	val scn = Scanner(System.`in`)
	val n = scn.nextInt()
	val m = scn.nextInt()
	val arr = IntArray(n){scn.nextInt()}
	val sum = arr.sum()
	arr.sortDescending()
	println(if (arr[m-1]*4*m >= sum) "Yes" else "No")
}

Measured memory_bytes: 35704
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdlib>

using namespace std;

int main(){

	int n,d;
	char c;
	string s;
	bool prv=true;

	int pd[100000];
	int nd[100000];
	fill(pd,pd+100000,0);
	fill(nd,nd+100000,0);

	while(getline(cin,s)){
		if(s==""){
			prv=false;
		}
		else if(prv){
			int idx=0;
			for(int i = 0; i < s.size(); i++){
				if(s[i]==','){
					idx=i;
					break;
				}
			}
			int num=atoi(s.substr(0,idx).c_str());
			pd[num]++;
		}
		else{
			int idx=0;
			for(int i = 0; i < s.size(); i++){
				if(s[i]==','){
					idx=i;
					break;
				}
			}
			int num=atoi(s.substr(0,idx).c_str());
			nd[num]++;
		}
	}

	int ret[100000];
	fill(ret,ret+100000,0);
	for(int i = 0; i < 100000; i++){
		if(nd[i]!=0&&pd[i]!=0){
			ret[i]=nd[i]+pd[i];
			cout<<i<<" "<<ret[i]<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>

using namespace std;

int main(){
	int n,k;
	cin >> n >> k;
	vector<int> a(n,0);
	
	int sum=0;
	for(int i=0;i<n;i++){
		cin >> a[i];
		sum+=min(a[i],abs(k-a[i]));
	}
	cout << 2*sum << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 250

int HEAP[MAX];
int p(int heap){
	return heap/2;
}
int l(int heap){
	return heap*2;
}
int r(int heap){
	return (heap*2+1);
}

main(){
	int i,heapsize,left,right;
	scanf("%d",&heapsize);
	
	for(i = 1;i <= heapsize;i++){
		scanf("%d",&HEAP[i]);
	}
	
for(i = 1;i <= heapsize; i++){
	 left=l(i);
	 right=r(i);
		printf("node %d: key = %d, ",i,HEAP[i]);
		if(i > 1){
			printf("parent key = %d, ",HEAP[p(i)]);
		}
		if(heapsize >=left){
			printf("left key = %d, ",HEAP[l(i)]);
		}
	if(heapsize >= right){
		printf("right key = %d, ",HEAP[r(i)]);
	}
	printf("\n");
}
return 0;
}

Measured memory_bytes: 600