akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main()
{
	int n,p,flag=0,mayor;
	while(cin>>n>>p , n!=0 && p!=0)
	{
		int stone[50]={0};
		while(1)
		{
			for(int i=0;i<n;i++)
			{
				if(p>0)//石があれば取る
				{
					stone[i]++;
					p--;
					if(p==0)//お椀の石がなくなったとき
					{
						flag=1;
						for(int j=0;j<i;j++)
							if(stone[j]!=0)//他に石を持っている人がいたら
							{
								flag=0;
								break;
							}
						for(int j=i+1;j<n;j++)
							if(stone[j]!=0)
							{
								flag=0;
								break;
							}
						if(flag==1)
						{
							mayor=i;
							break;
						}
					}
								
				}
				else//お椀の石がないとき
				{
					p=stone[i];//お椀に石を入れる
					stone[i]=0;
				}
			}
			if(flag==1)
			{
				cout<<mayor<<endl;
				flag=0;
				break;
			}
		}
	}
}

Measured memory_bytes: 1160
use proconio::input;

fn main() {
    input! {
        a: isize,
        b: isize,
        c: isize,
        k: isize,
    }
    let mut r = 0;
    r += a.min(k);
    if k - a - b > 0 {
        r -= k - a - b;
    }
    println!("{}", r);
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;

// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>

vector <ll> v;

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

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

	ll n,i,m,j,k,x,y,a,b,c,d,t;
	string s;
	
	cin >> a >> b >> c >> d;
	
	i=0;
	while(a>0 && c>0)
	{
		if(i%2==0)
			c-=b;
		else
			a-=d;
		i++;
	}
	if(a>0)
		cout << "Yes";
	else
		cout << "No";

	return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int subToZero(int a, int b)
{
    return max(0, a-b);
}

int main(int argc, const char * argv[]) {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin >> N;
    
    vector<int> A(N+1), B(N);
    rep(i, N+1) cin >> A[i];
    rep(i, N)   cin >> B[i];
    
    ll sum = 0;
    
    for (int i = 0; i < N; ++i)
    {
        int prevA = A[i];
        int delta;
        A[i] = subToZero(A[i], B[i]);
        delta = prevA - A[i];
        B[i] = B[i] - delta;
        sum += delta;
        
        prevA = A[i + 1];
        A[i + 1] = subToZero(A[i + 1], B[i]);
        delta = prevA - A[i + 1];
        B[i] = B[i] - delta;
        sum += delta;
        
    }
    
    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue> //priority_queue
#include <map>
#include <set> //multiset set<int,greater<int>>大到小
#include <vector>// vector<int>().swap(v);清空释放内存
#include <stack>
#include <cmath> // auto &Name : STLName  Name.
#include <utility>
#include <sstream>
#include <string>//__builtin_popcount(ans);//获取某个数二进制位1的个数
#define mod 1000000007
#define mod9 998244353
typedef unsigned long long ull;
typedef long long ll;
typedef double db;
typedef long double ld;
const db eps=1e-10;
const int INF = 0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
#define rep(i,be,en) for (int i=be;i<=en;i++)
#define per(i,be,en) for (int i=en;i>=be;i--)
using namespace std;
const int N=1e6+7;

int t,n,m,k=0,fl=0;

int main(){
    scanf("%d%d",&n,&m);
    rep(i,1,m){
        scanf("%d",&k);
        n-=k;
    }
    if(n>=0) printf("%d\n",n);
    else printf("-1\n");

    return 0;
}

Measured memory_bytes: 3236
def create_z_array(s):
    n = len(s)
    z_array = [0] * n
    left = 0
    right = 0
    for i in range(1, n):
        if i > right:
            left, right = i, i
            while right < n and s[right - left] == s[right]:
                right += 1
            z_array[i] = right - left
            right -= 1
        else:
            k = i - left
            if z_array[k] < right - i + 1:
                z_array[i] = z_array[k]
            else:
                left = i
                while right < n and s[right - left] == s[right]:
                    right += 1
                z_array[i] = right - left
                right -= 1
    return z_array


n = int(input())
s = input().rstrip()
res = 0
for i in range(n):
    z_array = create_z_array(s[i:])
    for j in range(1, len(z_array)):
        res = max(res, min(j, z_array[j]))
print(res)

Measured memory_bytes: 49884
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long k = sc.nextLong();
		long mod = n % k;
		long result = Math.min(mod, Math.abs(mod - k));
		sc.close();

		System.out.println(result);
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
long long inf = pow(10, 9);

int n, a[81];
long long dp[81];
int main(){
    cin >> n;
    rep(i, n) cin >> a[i];
    dp[0] = 1000;
    rep(i, n){
        rep(j, i){
            dp[i] = max(dp[i], dp[j]);
            dp[i] = max(dp[i], (dp[j] / a[j]) * a[i] + dp[j] % a[j]);
        }
    }
    cout << dp[n - 1] << endl;
}

Measured memory_bytes: 3636
/*
    OUTLAW!!
           ---SIDHU MOOSEWALA
                                */
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
//#include <boost/functional/hash.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
lli M=1000000007;   
lli INF=1e17;
#define sqr(x) (x) * (x)
#define bip(n) __builtin_popcount(n)//no of ones bit in binary!!
#define bictz(n) __builtin_ctz(n)//no of trailing zeroes in binary!!
#define biclz(n) __builtin_clz(n)//no of leading zeroes in binary!!
#define bffs(n) __builtin_ffs(n)//index of first one bit!!
typedef pair<lli,lli> ll;
#define mem1(a,x) fill(&a[0], &a[0] + sizeof(a) / sizeof(a[0]), x)
#define mem2(a,x) fill(&a[0][0], &a[0][0] +sizeof(a)/sizeof(a[0][0]),x)
#define mem3(a,x) fill(&a[0][0][0], &a[0][0][0] +sizeof(a)/sizeof(a[0][0][0]),x)
#define fi1 ifstream fin("input.txt")
#define of1 ofstream fout("output.txt")
typedef tree<lli,null_type,less<lli>,rb_tree_tag,tree_order_statistics_node_update> ost;
lli n,q,z,y,k,m;
const double pi1=3.14159265358979323846;
//unordered_map<pair<ll,lli>,lli> mp;
lli me(lli a,lli b,lli M)
{
    if(b==0)
    return 1;
    else if(b%2==0)
    return me((a*a)%M,b/2,M);
    else
    return (a%M*me((a*a)%M,(b-1)/2,M)%M)%M;
}
lli mI(lli a,lli m)
{
    return me(a,m-2,m);
}
//lli tot=0;
vector<lli> pf(string s) {
    int n = (int)s.length();
    vector<lli> pi(n);
    for (int i = 1; i < n; i++) {
        int j = pi[i-1];
        while (j > 0 && s[i] != s[j])
            j = pi[j-1];
        if (s[i] == s[j])
            j++;
        pi[i] = j;
    }
    return pi;
}
//map<ll,lli> dp;
//set<lli> s[100005];
//lli dp[3005][3005];
//ost s[500005];
bool cmp(ll a,ll b)
{
    if(a.second==b.second)
    return a.first<b.first;
    return a.second<b.second;
}
//string sdp[3005][3005];
lli vis[3000004];
vector<lli> v[500000];
lli cx,cy;
void dfs(lli i)
{
    if(vis[i])
    return;
    if(i>=200000)
    cy++;
    else
    cx++;
    vis[i]=1;
    for(auto &j: v[i])
    dfs(j);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin>>n;
    lli x,y;
    ll p[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>x>>y;
        p[i].first=x;
        p[i].second=y;
        v[x].push_back(200000+y);
        v[200000+y].push_back(x);
    }
    lli res=0;
    for(int i=1;i<=n;i++)
    {
        if(vis[p[i].first]==0)
        {
            cx=cy=0;
            dfs(p[i].first);
            res+=cx*cy;
        }
    }
    res-=n;
    cout<<res;
    //for(int i=1;i<=n;i++)
}

Measured memory_bytes: 22400
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

const int MAX = 303030;
const ll MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];

void combinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
ll comb(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll modpow(ll a, ll n) {
	ll res = 1;
	a %= MOD;
	while (n > 0) {
		if (n & 1) res = res * a % MOD;
		a = a * a % MOD;
		n >>= 1;
	}
	return res;
}


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

	
	int N, R;
	cin >> N >> R;
	if (N >= 10)puts(R);
	else puts(R + 100*(10 - N));


	return 0;
}


Measured memory_bytes: 384
ip=input()

pal=ip[::-1]

a=int((len(ip)-1)//2)
b=int((len(ip)+3)//2)-1
pal1=ip[:a]
pal2=ip[b:]

if ip==pal and pal1==pal1[::-1] and pal2==pal2[::-1]:
    print('Yes',end='')
    
else:
    print('No',end='')

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
//adds two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set]
//(2)set.order_of_key(k)[count of elements strictly less than k]
#define ll long long
#define ld long double
#define vv vector
#define pp pair
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
typedef pair<ll, ll> pll;
typedef vv<bool> vbool;
typedef vv<ll> vll;
typedef vv<ld> vld;
typedef vv<pll> vpll;
#ifdef LOCAL
#include "prettyprint.hpp"
#define LG(args...)                           \
{                                             \
	string _s = #args;                        \
	replace(_s.begin(), _s.end(), ',', ' ');  \
	stringstream _ss(_s);                     \
	err(istream_iterator<string>(_ss), args); \
	cerr << endl;                             \
}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << "(" << *it << ":" << a << ") ";
	err(++it, args...);
}
#define fastio
#else
#define LG(...)
#define fastio                    \
	ios_base::sync_with_stdio(0); \
	cin.tie(0);
#define endl "\n"
#endif
//:::::::::::::::::::::::::::::::::::::::::::::
const ll INF = 9e18;
const ll MOD = 1e9 + 7;

int main(){
	fastio;
	ll t;
	t=1;
	while(t--){
			ll n;
	cin>>n;
	ll mxa=-INF, mxb =-INF, mna=INF, mnb=INF;
	for(ll i=0; i<n; i++){
		ll x,y;
		cin>>x>>y;
		mxa = max(mxa, x+y);
		mna = min(mna, x+y);
		mxb = max(mxb, (x-y));
		mnb = min(mnb, (x-y));
	}
	LG(mxa, mna, mxb, mnb);
	cout << max( mxa - mna, mxb - mnb);
	cout<<endl;

	}
}

Measured memory_bytes: 3648
W=87,i,n;char a[100001],s[100001];f(x,y){*a=x;a[1]=y;for(i=0;++i<n-1;)a[i+1]=a[i]==W^a[i-1]==W^s[i]=='o'?83:W;*a!=W^*s=='o'^a[n-1]==a[1]&&a[n-1]!=W^s[n-1]=='o'^a[n-2]==*a?puts(a),exit(0):0;}main(){scanf("%d%s",&n,&s);f(83,83);f(83,W);f(W,83);f(W,W);puts("-1");}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define f(i,a,b) for(i=a;i<=b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define ll long long
#define mod (1000*1000*1000+7)
#define scan1(x) scanf("%lld",&x)
#define scan2(x,y) scanf("%lld %lld",&x,&y)
#define scan3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define print(x) printf("%lld\n",x)
#define ff first
#define ss second
using namespace std;


int main(){
    ll a;
    scan1(a);
    cout<<a+a*a+a*a*a<<"\n";
    return 0;
}

Measured memory_bytes: 3764
using System;
class ordinary{
  public static void Main(){
    int n = int.Parse(Console.ReadLine());
    String[] str = Console.ReadLine().Split(' ');
    int[] num = new int[n];
    int count = 0;
    for(int i=0; i<n; i++){
      num[i] = int.Parse(str[i]);
    }
    for(int i=1; i<n-1; i++){
      if((num[i-1] <= num[i] && num[i] <= num[i+1]) || num[i-1] >= num[i] && num[i] >= num[i+1]){
        count++;
      }
    }
    Console.WriteLine(count);
  }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr int INF = 1e9;
int main(){
  int n, e;
  cin >> n >> e;
  vector<vector<int>> d(n,vector<int>(n,INF));
  rep(i,e) {
    int u, v, c;
    cin >> u >> v >> c;
    d[u][v] = c;
  }
  vector<vector<int>> dp(1<<n, vector<int>(n,-1));

  auto rec = [&](auto &&f, int s, int v)->int {
    if (dp[s][v] >= 0) return dp[s][v];
    else if (s == (1<<n)-1 && v == 0) return dp[s][v] = 0;

    int res = INF;
    for (int u = 0; u < n; u++) {
      if (!(s & (1<<u))) res = min(res, f(f, s | (1<<u), u) + d[v][u]);
    }
    return dp[s][v] = res;
  };
  int ans = rec(rec,0,0);
  cout << (ans == INF ? -1 : ans) << endl;
  return 0;
} 


Measured memory_bytes: 6308
result = 0
A = int(input()) #500
B = int(input()) #100
C = int(input()) #50
X = int(input()) 
  
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
          if 500*a + 100*b + 50*c == X:
            result += 1
 
print(result)

Measured memory_bytes: 3060
#include <bits/stdc++.h> // Ishaan Gupta
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cout << *x, 0);
sim > char dud(...);
struct debug {
#ifdef IG_PC
~debug() { cout << endl; }
eni(!=) cout << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define endl '\n'
#define pb push_back
using ll = long long;
using ld = long double;
const ll MOD = 1e9l + 7;
const ll INF = 1e18l + 5;
inline ll add(ll a,ll b){return (a%MOD+b%MOD)%MOD;}
inline ll sub(ll a,ll b){return (a%MOD-b%MOD+MOD)%MOD;}
inline ll mult(ll a,ll b){return ((a%MOD)*(b%MOD))%MOD;}
inline ll power(ll a,ll b){a%=MOD;ll r=1;while(b){if(b&1)r=mult(r,a);a=mult(a,a);b>>=1;}return r;}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed;
#ifdef IG_PC
    freopen("input", "r", stdin);
    freopen("output", "w", stdout);
#endif
    ll n,k;
    cin >> n >> k;
    vector<ll>st(n);
    for(ll &i : st)
        cin >> i;
    vector<ll>dp(k+1);
    // dp[i] true if the player playing first wins

    for(ll stones = 0; stones <= k; ++stones)
    {
        for(ll i : st)
        {
            if(stones - i >= 0 && !dp[stones-i])
                dp[stones]=1;
        }
    } 
    if(dp[k])
        cout<<"First";
    else
        cout<<"Second";
    return 0;
}

Measured memory_bytes: 1024
n, m = map(int, input().split())
s = [list(map(int, input().split())) for i in range(n)]

s.sort(key=lambda x: x[0])

total = 0
for i in s:
    total+=i[0]*i[1]
    m-=i[1]
    if m <= 0:
        total+=i[0]*m
        break
        
print(total)

Measured memory_bytes: 29020
#include <cstdio>
#include <algorithm>

using namespace std;

int getL(int n)
{
	return ((n > 60) + (n > 80) + (n > 100) + (n > 120) + (n > 140) + (n > 160));
}

int getW(int n)
{
	return ((n > 2) + (n > 5) + (n > 10) + (n > 15) + (n > 20) + (n > 25));
}

int main()
{
	int n;
	int a[7] = {600, 800, 1000, 1200, 1400, 1600, 0};
	
	while (scanf("%d", &n) && n){
		int ans = 0;
		for (int i = 0; i < n; i++){
			int x, y, z, w;
			scanf("%d %d %d %d", &x, &y, &z, &w);
			ans += a[max(getL(x + y + z), getW(w))];
		}
		
		printf("%d\n", ans);
	}
	
	return (0);
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    int c[a];
    for(int i=0;i<a;i++){
        cin>>c[i];
        b-=c[i];
    }
    sort(c,c+a);
    cout<<b/c[0]+a<<endl;
}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
//V,P(大文字)使用不可

const ll INF=1e18;

signed main(){
    ll n;
    cin>>n;
    ll ans=12;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            ll s=i,t=n/i;
            string u=to_string(s);
            string v=to_string(t);
            ll a=u.size(),b=v.size();
            chmin(ans,max(a,b));
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define LEN 100000
struct Queue {
	char name[10];
	int v;
};
Queue Q[LEN],q;
int head, tail, n,elaps=0;
void Enqueue(Queue x) {
	Q[tail] = x;
	tail = (tail + 1) % LEN;
}
Queue Dequeue() {
	q = Q[head];
	head = (head + 1) % LEN;
	return q;
}
int Min(int x, int y) {
	return x < y ? x : y;
}
int main() {
	int p;
	cin >> n;
	cin >> p;
	for (int i = 0; i < n; i++) {
		cin >> Q[i].name >> Q[i].v;
	}
	head = 0;
	tail = n;
	while (head != tail) {
		Queue qq = Dequeue();
		int min = Min(qq.v, p);
		if (min == qq.v) {
			elaps += qq.v;
			cout << qq.name << ' ' << elaps << endl;
		}
		else {
			elaps += p;
			qq.v -= p;
			Enqueue(qq);
		}
	}
	return 0;
}


Measured memory_bytes: 4624
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7, N = 1e5 + 7;

vi G[N];

int ans = 0, n, k;
int a[N];

int dfs(int u) {
	int mx = 0;
	for(int v:G[u]) {
		mx = max(mx, dfs(v) + 1);
	}
	if(mx == k - 1 && a[u] != 1) {
		ans++;
		mx = -1;
	}
	return mx;
}

signed main()
{
	IO_OP;
	
	cin >> n >> k;	
	for(int i = 1; i <= n; i++) cin >> a[i];
	if(a[1] != 1) {
		ans++;
		a[1] = 1;
	}
	for(int i = 2; i <= n; i++) G[a[i]].PB(i);
	dfs(1);
	cout << ans << endl;


}





Measured memory_bytes: 14188
#include<bits/stdc++.h>
using namespace std;
#define int long long
int h;
void maxHeapify(int *A,int i){
  int l=i*2+1;
  int r=i*2+2;
  int largest;
  if(l<h&&A[l]>A[i]) largest=l;
  else largest=i;
  if(r<h&&A[r]>A[largest]) largest=r;
  if(largest!=i){
    swap(A[i],A[largest]);
    maxHeapify(A,largest);
  }
}
void buildMaxHeap(int *A){
  for(int i=h/2;i>=0;i--)
    maxHeapify(A,i);
}
signed main(){
  cin>>h;
  int A[h];
  for(int i=0;i<h;i++) cin>>A[i];
  buildMaxHeap(A);
  for(int i=0;i<h;i++) cout<<" "<<A[i];
  cout<<endl;
  return 0;
}



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

long long gcd(long long aaa,long long bbb) {
    if(bbb==0) {
        return aaa;
    }
    return gcd(bbb,aaa%bbb);
}

int main (){

    ll N,X;
    cin >> N >> X;
    ll x[N],x2[N+1],m=1e9,mn;
    for(ll i = 0; i < N; i++) {
        cin >> x[i];
        if(abs(x[i] - X) < m) {
            m = abs(x[i] - X);
        }
    }

    sort(x,x+N);

    for(ll i = 1; i < N; i++) {
        m = gcd(abs(x[i-1] - x[i]),m);
    }

    cout << m << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	string s;
	cin>>s;
	int d=s.size();
	int c;
	cin>>c;
	ll ans=0;
	if(c==3){
		for(int i=0; i<d; i++){
			for(int j=i+1; j<d; j++){
				for(int k=j+1; k<d; k++){
					if(i>0) ans+=9*9*9;
					else{
						ans+=(s[0]-'0'-1)*9*9;
						
						for(int l=1; l<10; l++){
							for(int m=1; m<10; m++){
								string t; t+=s[0];
								for(int n=1; n<d; n++){
									if(n==j) t+=(char)('0'+l);
									else if(n==k) t+=(char)('0'+m);
									else t+='0';
								}
								if(t<=s) ans++;
							}
						}
					}
				}
			}
		}
	}else if(c==2){
		for(int i=0; i<d; i++){
			for(int j=i+1; j<d; j++){
					if(i>0) ans+=9*9;
					else{
						ans+=(s[0]-'0'-1)*9;
						
						for(int l=1; l<10; l++){
                          string t; t+=s[0];
								for(int n=1; n<d; n++){
									if(n==j) t+=(char)('0'+l);
									else t+='0';
								}
								if(t<=s){
                                  ans++;
                                }
						}
					}
			}
		}
	}else{
		ans=(s[0]-'0');
		ans+=9*(d-1);
	}
	cout<<ans<<endl;
	return 0;
}

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

int main (){
  int N,M,city[50];
  cin >> N >> M ;
  for(int i=0;i<N;++i) city[i]=0;
 for(int i=0; i<M ; ++i){
   int a,b;
   cin >> a >> b ;
   city[a-1]++;
   city[b-1]++;
 }
  for(int i=0; i < N ;i++)cout << city[i] << endl;
}
  

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <math.h>

#define mp                  make_pair
#define F                   first
#define S                   second
#define pb                  push_back
#define FOR(i,j,n)          for(int i=j;i<n;i++)
#define F0R(i,j,n)          for(int i=j;i<=n;i++)
#define RFOR(i,j,n)         for(int i=n-1;i>=j;i--)
#define RF0R(i,j,n)         for(int i=n;i>=j;i--)
#define FOREACH(x,v)        for(auto x:v)
#define ITFOR(it,v)         for(v::iterator it =v.begin();it!=v.end();++it)
#define __in_arr__(a,j,n)   FOR(i,j,n)cin >> a[i];
#define __out_arr__(a,j,n)  FOR(i,j,n)cout << a[i];
#define LOG                 cout << "[ !" << __LINE__ << "L ] " << endl;
#define PLOG(x)             cout << "[ !" << __LINE__ << "L ] " \<<x<<endl;

using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int c;
    cin >> c;
    int c1 = c/10 ,c2 = c%10;
    if(c1 == 9 || c2 == 9)
        cout << "Yes" << endl;
    else 
        cout << "No"  << endl;
    return 0;
}


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

int main() {
  std::cin.tie(nullptr); std::ios::sync_with_stdio(false);
  int X, A, B;
  std::cin >> X >> A >> B;
  std::cout << (B - A <= 0 ? "delicious" : B - A <= X ? "safe" : "dangerous") << std::endl;
}


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

int main(){
  int a[10];
  char b[10];
  while(cin>>b[0]){
    for(int i=1;i<=9;i++)cin>>b[i];
    for(int i=0;i<=9;i++)a[i]=b[i]-'0';
    for(int i=8;i>=0;i--){
      for(int j=0;j<=i;j++){
	a[j]=(a[j]+a[j+1])%10;
      }
    }
    cout<<a[0]<<endl;
  }
  return 0;
}

Measured memory_bytes: 3012
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<vector<int>> v(10,vector<int>(10,0));
    rep(j,n+1){
        int i = j;
        vector<int> copy;
        while(i>0){
            copy.push_back(i%10);
            i/=10;
        }
        if(j==0) continue;
        int a = copy[0];
        int b = copy.back();
        if(a==0) continue;
        v[a][b]++;
    }
    int ans = 0;
    rep(i,10){
        rep(j,10){
            ans += v[i][j] * v[j][i];
        }
    }
    cout << ans << endl;
    return 0;
}

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

deque<int> dq;
vector<int> G[100010];
bool used[100010];
int n, m;

void dfs(int k, bool f) {
  used[k] = 1;
  for (int i = 0; i < G[k].size(); i++) {
    if (!used[G[k][i]]) {
      if (f) dq.push_back(G[k][i]);
      else dq.push_front(G[k][i]);
      dfs(G[k][i], f);
      return;
    }
  }
}

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

  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  dq.push_back(1);
  dfs(1, 1);
  dfs(1, 0);
  cout << dq.size() << endl;
  while (1) {
    cout << dq.front();
    dq.pop_front();
    if (!dq.empty()) cout << " ";
    else {
      cout << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 6784
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
int main () {
	string s;
	cin >> s;
	for(int i = 0; i < (int)s.size(); i++){
		cout << s[(int)s.size() - i - 1];
	}
	cout << endl;
}


Measured memory_bytes: 3236
#include <iostream>
using namespace std;
long long most(long long p025,long long p05,long long p1,long long p2)
{
    int mi=p2;
    p1*=2;
    if(p1<mi)
        mi=p1;
    p05*=4;
    if(p05<mi)
        mi=p05;
    p025*=8;
    if(p025<mi)
        mi=p025;
    ///025 05 1 2
    if(p025==mi)
        return 1;
    if(p05==mi)
        return 2;
    if(p1==mi)
        return 3;
    if(p2==mi)
        return 4;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    long long p025,p05,p1,p2,n;
    cin>>p025>>p05>>p1>>p2>>n;
    long long x=most(p025,p05,p1,p2);
    if(n%2==0)
    {
        if(x==4)
            cout<<p2*n/2;
        if(x==3)
            cout<<p1*n;
        if(x==2)
            cout<<p05*n*2;
        if(x==1)
            cout<<p025*n*4;
        return 0;
    }
    if(x!=4)
    {
        if(x==3)
            cout<<p1*n;
        if(x==2)
            cout<<p05*n*2;
        if(x==1)
            cout<<p025*n*4;
        return 0;
    }
    long long sum=(n/2)*p2,mi=p1;
    n=n%2;
    p05*=2;
    if(p05<mi)
        mi=p05;
    p025*=4;
    if(p025<mi)
        mi=p025;
    cout<<sum+mi;
    return 0;
}


Measured memory_bytes: 256
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter

# import numpy as np
# import scipy as scp

# 入力の受け取り
n = int(input())

strlist = "abcdefghij"

def dfs(s,num):
    if len(s) >= n:
        print(s)
        return
    elif num ==0:
        dfs("a",1)
    else:
        for i in range(num):
            dfs(s+strlist[i],num)
        dfs(s+strlist[num],num+1)

dfs("",0)

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

using vec2 = pair<int, int>;

int main()
{
    int H, W, M;
    cin >> H >> W >> M;

    vector<vec2> bs(M);
    vector<int> xs(W + 1, 0);
    vector<int> ys(H + 1, 0);

    int xmax = 0, ymax = 0;
    for (auto& b : bs)
    {
        cin >> b.second >> b.first;
        xmax = max(xmax, ++xs[b.first]);
        ymax = max(ymax, ++ys[b.second]);
    }

    int xn = 0, yn = 0;
    for (const auto& x: xs) { if (x == xmax) { ++xn; } }
    for (const auto& y: ys) { if (y == ymax) { ++yn; } }

    int zn = 0;
    for (const auto& b : bs) { if (xs[b.first] == xmax && ys[b.second] == ymax) { ++zn; } }

    cout << xmax + ymax - (zn == xn * yn ? 1 : 0) << endl;

    return 0;
}

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

using namespace std;
 
#define MAX 150
 
char sp[MAX][MAX];
//u r d l
const int dx[] = {0, 1, 0, -1};
const int dy[] = {-1, 0, 1, 0};
 
bool range(int x, int y, int n)
{
    if (0 > x || x >= n || 0 > y || y >= n) {
	return 0;
    }
    return 1;
}
 
void make(int n)
{
    int x = 0, y = n-1, dir = 0;
 
    for (int i = 0; i < n; i++) {
	for (int j = 0; j < n; j++) {
	    sp[i][j] = '.';
	}
    }
    int end = 0;
    sp[y][x] = '#';
    while (1) {
	int nx = x + dx[dir];
	int ny = y + dy[dir];  
 
	bool flg = 1;
	if (!range(nx, ny, n)) {
	    flg = 0;
	}
 
	for (int i = 0; i < 4; i++) {
	    int nnx = nx + dx[i];
	    int nny = ny + dy[i];
 
	    if ((x == nnx && y == nny) 
	       || !range(nnx, nny, n)) {
		continue;
	    }
 
	    if (sp[nny][nnx] == '#') {
		flg = 0;
		break;
	    }
	}
 
	if (!flg) {
	    dir++;
	    dir = dir % 4;
	    end++;
	    if (end == 4) return;
	} else {
	    end = 0;
	}
 
	if (flg) {
	    sp[ny][nx] = '#';
	    x = nx;
	    y = ny;
	}
    }
}
 
int main()
{
    int d, n;
    bool ok = 0;
 
    scanf("%d", &d);
    while (d--) {
	scanf("%d", &n);
 
	if (ok) {
	    puts("");
	}
	ok = 1;
	make(n);
	for (int i = 0; i < n; i++) {
	    for (int j = 0; j < n; j++) {
		if (sp[i][j] == '.') {
		    printf(" ");
		} else {
		    printf("%c", sp[i][j]);
		}
	    }
	    puts("");
	}   
    }
    return 0;
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
#define rei register int
using namespace std;
const int maxn = 200010;
int n,m;
int fa[maxn],sz[maxn];
int getf(int x){
	return fa[x] == x ? x : fa[x] = getf(fa[x]);
}
int main(){ int ans(1);
	cin >> n >> m;
	for(rei i = 1;i <= n;++i) fa[i] = i,sz[i] = 1;
	for(rei i = 1;i <= m;++i){
		int x,y; scanf("%d%d",&x,&y);
		int fx = getf(x),fy = getf(y);
		if(fx == fy) continue; fa[fy] = fx,sz[fx] += sz[fy];
		ans = max(ans,sz[fx]);
	} cout << ans; return 0;
}

Measured memory_bytes: 5212
#include <iostream>
#include <string>
#include <array>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <cctype>
#include <map>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <queue>


#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long

using namespace std;

bool is_integer( float x ){
    return floor(x)==x;
}

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

//yakusuu rekkyo
vector<long long> enum_divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // push its partner
            if (N/i != i) res.push_back(N/i);
        }
    }

    sort(res.begin(), res.end());
    return res;
}


vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // exponential

        // divide as much as you can
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // push the result
        res.push_back({a, ex});
    }

    // last num (if the lasting n is prime number and not 1)
    if (N != 1) res.push_back({N, 1});
    return res;
}



int main() {
    ll d = 1000000007;
    ll n;
    ll ans = 1;

    cin >> n;
    rep(i,n) {
        ans *= (i+1);
        if(ans >= d){
            ans %= d;
        }
    }

    cout <<(ans %= d);
    return 0;
}



Measured memory_bytes: 3556
#pragma GCC optimize ("03")
#pragma GCC target("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
 
#define sz(x) (ll)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define nl "\n"
 
const int mod=10e7+7;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a+3);
	cout << a[0]+a[1];
}


Measured memory_bytes: 3604
#include <stdio.h>
int main() {
	int i;
	double a, s;

	while (scanf(" %lf ", &a) != EOF) {
		s = a;
		for (i = 0; i < 9; i++) {
			if (i % 2 == 0)
				a *= 2.0;
			else
				a /= 3.0;
			s += a;
		}
		printf("%.8lf\n", s);
	}
	return 0;
}

Measured memory_bytes: 656
#include<iostream>
#include<algorithm>
#include<string>
#include<initializer_list>

using ull = unsigned long long;

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

	ull x = 0;



	auto sgs = [](const auto x) {
		auto s = std::to_string(x);

		auto exist = [&](std::initializer_list<char> ilist)->bool {
			bool is_sgs = true;
			for (auto&&e : ilist) 
				is_sgs &= std::count(std::begin(s), std::end(s), e)>0;
			
			return is_sgs;
		};

		return exist({ '7','5','3' }) ;
	};
	/*
	std::cout << std::boolalpha;
	for (auto&&e : { 357,735,535,773 }) {
		std::cout << e << " is sgs => "<< sgs(e) << "\n";
	}*/

	auto res = [](auto g) {
		return [=](auto&&... arg)->ull {
			return g(g, std::forward < decltype(arg) >(arg)... );
		};
	}(
		[&](auto f, const auto x)->ull {
			if (x > n)
				return 0;

			auto ret = sgs(x) ? 1 : 0;

			return ret
				+ f(f, x * 10 + 3)
				+ f(f, x * 10 + 5)
				+ f(f, x * 10 + 7);
			}
	)(0);

	
	std::cout << res << "\n";
	

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header
int f(vector<vector<char>> s, ll i, ll j, int w, int h){
	if(s[i][j]=='#') return -1;
	int dx[8] = {1, 1, 1, 0, 0, -1, -1, -1};
	int dy[8] = {0, -1, 1, 1, -1, 0, 1, -1};
	int ans=0;
	rep(k,8){
		ll nx = j+dx[k];
		ll ny = i+dy[k];
		if((nx<0 || nx>w-1) || (ny<0 || ny>h-1)) continue;
		else if (s[ny][nx] == '#') ans+=1;
	}
	return ans;
}
int main() {
	int h, w;
	cin >> h >> w;
	vector<vector<char>> s(h, vector<char>(w));
	rep(i,h) rep(j,w) cin >> s[i][j]; 
	rep(i,h){
		rep(j,w){
			int q = f(s, i, j, w, h);
			if(q==-1) cout << '#';
			else cout << q;
		}
		cout << endl;
	}
 	return 0;
}

Measured memory_bytes: 3548
#include <algorithm>
#include <iostream>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < (n); ++(i))
using namespace std;
template <class T>
void setmax(T &a, T const &b) {
    if (a < b) a = b;
}

template <class T>
void setmin(T &a, T const &b) {
    if (a > b) a = b;
}

template <typename T, typename X>
auto vectors(T a, X x) { return vector<T>(x, a); }

template <typename T, typename X, typename Y, typename... Zs>
auto vectors(T a, X x, Y y, Zs... zs) {
    auto cont = vectors(a, y, zs...);
    return vector<decltype(cont)>(x, cont);
}

int main() {
    int N, X, T;
    cin >> N >> X >> T;
    cout << (N + X - 1) / X * T << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++)
#define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--)
typedef pair<ll, ll> pi;
typedef pair<ll, pi> pii;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define INF (ll) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

ll a, b, v, w, t;

int main() {
	fastio; cin >> a >> v >> b >> w >> t;
	ll x = (v-w)*t;
	if (x >= llabs(a - b)) cout << "YES";
	else cout << "NO";
}


Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstring>
#include<cstdlib>
using namespace std;

int main(void){
   
   string s;
   int T,P,R,tID,pID,time,cor[51][501],wr[51][501],pena[51][501],corcnt[51];   

   while(cin >> T >> P >> R,T|P|R){

      memset(cor,0,sizeof(cor));
      memset(wr,0,sizeof(wr));
      memset(pena,0,sizeof(pena));
      memset(corcnt,0,sizeof(corcnt));
      
      for(int i=0;i<R;i++){
	 cin >> tID >> pID >> time >> s;
	 if(s=="CORRECT"){
	    corcnt[tID]++;
	    cor[tID][pID]++;
	    pena[tID][pID]+=wr[tID][pID]*1200+time;
	 }
	 else wr[tID][pID]++;
      }

      int pena2[51];
      memset(pena2,0,sizeof(pena2));
      for(int i=1;i<=T;i++){
	 for(int j=1;j<=P;j++){
	    pena2[i]+=pena[i][j];
	 }
      }

      int m,n,a;

      for(int i=1;i<=T;i++){
	 m=0;
	 for(int j=1;j<=T;j++){
	    m=max(corcnt[j],m);
	 }
	 n=1000000000;
	 for(int j=1;j<=T;j++){
	    if(corcnt[j]==m && pena2[j]<n){
	       a=j;
	       n=pena2[j];
	    }
	 }
	 cout << a <<" "<< corcnt[a] <<" "<< pena2[a] << endl;
	 corcnt[a]=-1;
      }
   }
   return 0;
}

Measured memory_bytes: 1224
#ifndef _WIN32
#include<iostream>
#endif
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<string>
#include<stdlib.h>

using namespace std;
#define rep(i,n) for(auto i=(n)*0;i<n;i++)
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	cout << fixed << setprecision(30);
	int n;
	while (cin >> n, n){
		int top = 0, bottom = 1000,sum=0;
		rep(i, n){
			int s;
			cin >> s;
			sum += s;
			top = max(top, s);
			bottom = min(bottom, s);
		}
		cout << (sum - top - bottom)/(n-2) << endl;
	}
	return 0;
}

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

void main_()
{
    string S;
    cin >> S;

    for (size_t i = S.size() / 2 - 1; i > 0; --i) {
        if (S.substr(0, i) == S.substr(i, i)) {
            cout << i * 2 << endl;
            return;
        }
    }
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  int x;
  cin >> x;

  int ans = 0;
  if (x < 100) ans = 0;
  else if (x < 2000) {
    int q = x / 100;
    int r = x % 100;
    if (r > q * 5) ans = 0;
    else ans = 1;
  }
  else ans = 1;

  cout << ans << endl;

  return 0;
}


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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> llVEC;
typedef vector<P> PVEC;
typedef priority_queue<P,PVEC,greater<P> > PPQ;
typedef priority_queue<ll, llVEC, greater<ll> > llPQ;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue;
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

template<typename T>
ll sz(vector<T> &vec){ return (ll)vec.size(); }
ll sz(string &s){ return (ll)s.size(); }
ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b; }

int main(){
    ll n;
    cin >> n;
    string s[n];
    ll t[n];
    ll ans = 0;
    rep(i,0,n){
        cin >> s[i] >> t[i];
    }
    string x;
    cin >> x;
    bool flag = false;
    rep(i,0,n){
        if(flag) ans += t[i];
        if(x == s[i]) flag = true;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll max(ll a, ll b){
    return a > b? a : b;
}
int main()
{
    int a, b;
    cin >> a >> b;
    if(a >= 13) cout << b;
    else if(a >= 6 && a <= 12) cout << b / 2;
    else cout << 0;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0;i--)
using namespace std;

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  fspcnt = 0;
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}*/


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int h1 = max(a,c);
  int h2 = min(b,d);
  cout << max(0,h2-h1) << endl;
  
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<unordered_set>
#include<unordered_map>
#include<set>
#include<map>
#include<list>

using namespace std;

#define in(s) cin >> s
#define out(s) cout << s << endl
#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
    int x, y, z;
    in(x); in(y); in(z);
    cout << z << ' ' << x << ' ' << y << endl;

	return 0;
}


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

  int main() {
    // int Ans = -1;  // 回答：
    string Ans = "";  // 回答：
    int N; cin >> N; // 桁数（１～３）
    int M; cin >> M; // 条件数（０～５）
    vector<int> S(M); // 桁位置
    vector<char> C(M); // 指定数値
    rep(i,M){
      cin >> S.at(i) >> C.at(i);
    }

    vector<char> A(N);  // 作業用文字列
    rep(i,N) {A.at(i) = '0';}
    rep(i,M){
//      cout << "S.at(i):" << S.at(i) << " A.at(S.at(i)-1):" << A.at(S.at(i)-1) << " C.at(i):" << C.at(i) << endl;
      if ( S.at(i) == 1 && C.at(i) == '0' && N != 1 ) {
        Ans = "-1";
        break;
      } else if ( A.at(S.at(i)-1) == '0' ) {
        A.at(S.at(i)-1) = C.at(i);
      } else if ( A.at(S.at(i)-1) != C.at(i) ) {
        Ans = "-1";
        break;
      }
    }
    // ２桁・３桁で、１桁目が０は１にする。
    if ( A.at(0) == '0' && N != 1 ) { A.at(0) = '1';}

    if ( Ans == "-1" ) { cout << Ans << endl; }
    else {
      rep(i,N){cout << A.at(i);}
      cout << endl;
    }
  }


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define double long double
using namespace std;
signed main() {
	ll x, sanada = 3;
	cin >> x;
		for (int i = 1; i < x; i++) {
			sanada += sanada + 1;
		}
		cout << sanada * 2 << endl;
	getchar(); getchar(); return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
    int r, s, p;
    cin >> r >> s >> p;

    vi ds;
    while (p--) {
        int i, j;
        cin >> i >> j;
        i--, j--;
        if (j >= s) {
            j++;
        }
        int d = abs(r - i) + abs(s - j);
        ds.push_back(d);
    }
    sort(ds.begin(), ds.end());
    
    int pre = 0;
    for (int d : ds) {
        if (pre < d) {
            pre = d;
        } else {
            pre++;
        }
    }
    cout << pre << endl;
}


Measured memory_bytes: 4884
H, W = gets.split.map(&:to_i)
s = H.times.map{gets.chomp.chars}
white = s.map{|v| v.map{|c| c == "#" ? 0 : 1}.inject(&:+)}.inject(&:+)

INF = 1e9
dy = [-1, 0, 1, 0]
dx = [0, 1, 0, -1]
d = H.times.map{Array.new(W, INF)}
d[0][0] = 1 
que = [[0,0]]
while !que.empty?
    y, x = que.shift
    4.times{|i|
        ny = y + dy[i]
        nx = x + dx[i]
        next if ny < 0 || H <= ny || nx < 0 || W <= nx
        if s[ny][nx] != "#" && d[y][x] + 1 < d[ny][nx] then
            d[ny][nx] = d[y][x] + 1
            que << [ny, nx]
        end
    }
end
puts d[H-1][W-1] == INF ? -1 : white - d[H-1][W-1]

Measured memory_bytes: 2172
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt();
		int b=scan.nextInt();
		int c=b;
		for(int i=0;;i++) {
			if(c!=0) {
			a*=10;
			}
			else {
				break;
			}
			c/=10;
		}double d=0;
		int e=a+b;
		d=Math.sqrt(e);
		if(d==(int)d) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 22864
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
//xにはvectorなどのコンテナ
#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 INF 1000000000000 //10^12:極めて大きい値,∞
#define inf 2147483647    //int値の最大値
#define MOD 1000000007    //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の二つ目の要素

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 gcd(int a, int b)
{
    if (b == 0)
        return a;
    else
        return gcd(b, a % b);
}
int lcm(int a, int b)
{
    return a * b / gcd(a, b);
}
int main()
{
    int n;
    cin >> n;
    cout << (1000 - n % 1000) % 1000 << endl;
    return 0;
}


Measured memory_bytes: 3628