akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    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 {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }

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

    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

struct combination {
    vector<mint> fact, ifact;

    combination(int n) : fact(n + 1), ifact(n + 1) {
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }

    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
} comb(2000005);

mint f(int n, int k) {
    if (n < 0) return 0;
    // nPk = nCk * k!
    mint res = comb(n, k);
    res *= comb.fact[k];
    return res;
}

int main() {
    int n, k;
    cin >> n >> k;
    k = min(k, n - 1);
    mint ans;
    rep(i, k + 1) ans += comb(n, i) * comb((n - i - 1) + i, i);
    cout << ans.x << endl;
}


Measured memory_bytes: 31488
N = int(input())
A_list = list(map(int, input().split()))
A_list.insert(0, 0)

cum_sum = 0
cum_sum_list = []
for i in range(N + 1):
    cum_sum += A_list[i]
    cum_sum_list.append(cum_sum)

ans = 0
for i in range(1, N+1):
    ans += A_list[i] * (cum_sum_list[N] - cum_sum_list[i])
    ans = ans % 1000000007
print(ans)

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

def main():
    W, H, N = [int(x) for x in input().split()]
    XYA = [[int(x) for x in input().split()] for _ in range(N)]

    sx, sy, lx, ly = 0, 0, W, H
    for x, y, a in XYA:
        if a == 1:
            sx = max(sx, x)
        elif a == 2:
            lx = min(lx, x)
        elif a == 3:
            sy = max(sy, y)
        else:
            ly = min(ly, y)

    print(max(0, lx - sx) * max(0, ly - sy))
    

if __name__ == '__main__':
    main()




Measured memory_bytes: 3064
// @snippet<sh19910711/contest:headers.cpp>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <limits>
#include <complex>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

// @snippet<sh19910711/contest:solution/interface.cpp>
namespace solution {
  class SolutionInterface {
  public:
    virtual int run() = 0;
    
  protected:
    virtual void pre_calc() {}
    virtual bool action() = 0;
    virtual void init() {};
    virtual bool input() { return false; };
    virtual void output() {};
    
    SolutionInterface() {}
    
  private:
    
  };
}

// @snippet<sh19910711/contest:solution/solution-base.cpp>
namespace solution {
  class SolutionBase: public SolutionInterface {
  public:
    virtual int run() {
      pre_calc();
      while ( action() );
      return 0;
    }
    
  };
}

// @snippet<sh19910711/contest:solution/typedef.cpp>
namespace solution {
  typedef std::istringstream ISS;
  typedef std::ostringstream OSS;
  typedef std::vector<std::string> VS;
  typedef long long LL;
  typedef int INT;
  typedef std::vector<INT> VI;
  typedef std::vector<VI> VVI;
  typedef std::pair<INT,INT> II;
  typedef std::vector<II> VII;
}

// @snippet<sh19910711/contest:solution/namespace-area.cpp>
namespace solution {
  // namespaces, types
  using namespace std;
  typedef std::pair<int, II> III;
}

// @snippet<sh19910711/contest:solution/variables-area.cpp>
namespace solution {
  // constant vars
  const int INF = std::numeric_limits<int>::max();
  // storages
  int h, w;
  III result;
}

// @snippet<sh19910711/contest:solution/solver-area.cpp>
namespace solution {
  class Solver {
  public:
    void solve() {
      result = III(INF, II(INF, INF));
      for ( int i = 1; i < 1000; ++ i ) {
        for ( int j = 1; j < 1000; ++ j ) {
          if ( check(i, j) ) {
            result = std::min(result, III(get_diagonal_length(i, j), II(i, j)));
          }
        }
      }
    }

    int get_diagonal_length( int x, int y ) {
      return x * x + y * y;
    }

    bool check( int y, int x ) {
      if ( y >= x )
        return false;
      if ( y == h && x == w )
        return false;
      if ( get_diagonal_length(y, x) == get_diagonal_length(h, w) ) {
        return y > h;
      }
      return get_diagonal_length(y, x) > get_diagonal_length(h, w);
    }

  private:
    
  };
}

// @snippet<sh19910711/contest:solution/solution.cpp>
namespace solution {
  class Solution: public SolutionBase {
  public:
  protected:
    virtual bool action() {
      init();
      if ( ! input() )
        return false;
      solver.solve();
      output();
      return true;
    }

    bool input() {
      return cin >> h >> w && h;
    }

    void output() {
      cout << result.second.first << " " << result.second.second << endl;
    }
    
  private:
    Solver solver;
    
  };
}

// @snippet<sh19910711/contest:main.cpp>
#ifndef __MY_UNIT_TEST__
int main() {
  return solution::Solution().run();
}
#endif

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

int main(){

    int H,W;
    cin >> H >> W;
    
    string s[H][W],S;
    for(int i=0;i<H;i++){
        cin >> S;
        for(int j = 0;j<W;j++){
            s[i][j] = S[j];
        }
    }
    /*
    for(int i = 0;i<H;i++){
        for(int j = 0;j<W;j++){
            cin >> s[i][j];
        }
    }
    */
    string a,b,c,d,e;
    bool flag = false;
    for(int i = 0;i<H;i++){
        for(int j = 0;j<W;j++){
            a = s[i][j];
            if(a == "#"){
                if(i == 0) d = ".";
                else d = s[i-1][j];

                if(i == H-1) e = ".";
                else e = s[i+1][j];

                if(j == 0) b = ".";
                else b = s[i][j-1];

                if(j == W-1) c = ".";
                else c = s[i][j+1];

                if(d == "#" || e == "#" || c == "#" || b == "#") flag = false;
                else flag = true;

                if(flag) break;
            }
        }
        if(flag) break;
    }

    if(flag) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;
}

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

int main()
{
    int n;
    cin >> n;
    int64_t sum = 0;
    for (int i = 1; i <= n; i++)
    {
        if (i % 3 != 0 && i % 5 != 0)
        {
            sum += i;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    ll p=1000000007;
    ll p2[200100];
    p2[0]=1;
    for(ll i=1;i<200100;i++)
    {
        p2[i]=p2[i-1]*2%p;
    }
    map<pair<ll,ll>,pair<ll,ll>>m;
    ll n;
    cin>>n;
    ll cnt=0;
    ll a,b;
    for(ll i=1;i<=n;i++)
    {
        cin>>a>>b;
        if(a==0 && b==0)
        {
            cnt++;
            continue;
        }
        ll g=__gcd(a,b);
        a/=g;
        b/=g;
        if(b<0)
        {
            a=-1*a;
            b=-1*b;
        }
        if(a>0)
        {
            m[{a,b}].first++;
        }
        else
        {
            m[{b,-a}].second++;
        }
    }
    ll ans=1;
    for(auto i=m.begin();i!=m.end();i++)
    {
        //cout<<(i->first).first<<" "<<(i->first).second<<" "<<p2[(i->second).first]<<" "<<p2[(i->second).second]<<endl;
        ans=ans*((p2[(i->second).first]+p2[(i->second).second]-1+p)%p)%p;
    }
    //cout<<ans<<endl;
    cout<<(ans+cnt-1+p)%p;
}

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

int main(){

    int n,k;
    long long ans=0;
    cin>>n>>k;
    vector<int> h(n);
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    sort(h.begin(),h.end());
    for(int i=0;i<n-k;i++){
        ans+=h[i];
    }
    cout<<ans<<endl;



    return 0;
}

Measured memory_bytes: 1024
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef vector<LL> VLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define MT(a,b,c) MP(a, MP(b, c))

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

class SegTree{
	public:
	VLL dat;
	int n;
	LL DEF;
	SegTree(int N){
		n = 1;
		DEF = 0;
		while(n<N)n*=2;
		dat = VLL(2*n-1, DEF);
	}
	void update(int index, LL v){
		int k=index+n-1;
		dat[k]=v; 
		while(1){
			k=(k-1)/2;//上に登る
			dat[k] = value(k);
			if(k==0)break;
		}
	}
	inline LL value(int idx){//Update value with (2*idx+1, 2*idx+2) 
		return value(dat[2*idx+1], dat[2*idx+2]);
	}
	inline LL value(LL v1, LL v2){
		return max(v1, v2);
	}
	LL query(int idx1, int idx2, int node=0, int range1=0, int range2=-10){
		if(range2 == -10 )range2 = n;
		if(range2 <= idx1 || idx2 <= range1)return DEF;//交差しない
		if(idx1 <= range1 && range2 <= idx2)return dat[node];
		else{
			LL vl = query(idx1, idx2, node*2+1, range1, (range1+range2)/2);
			LL vr = query(idx1, idx2, node*2+2, (range1+range2)/2, range2); 
			return value(vl, vr);
		}
	}
};

int main(){
	int n;
	cin >> n;
	SegTree seg(n);
	REP(i,n){
		int tmp;
		scanf("%d", &tmp);
		LL v = seg.query(0, tmp-1);
		seg.update(tmp-1, v+tmp);
	}
	cout << ((LL)n)*(n+1)/2-seg.query(0, n)<< endl;
	return 0;
}

Measured memory_bytes: 5228
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
char s[10004][11];
int n, ans, tmp, c1, c2, c3, len[10004];
int main(){
	scanf("%d", &n);
	for(Rint i = 1;i <= n;i ++)
		scanf("%s", s + i), len[i] = strlen(s[i]);
	for(Rint i = 1;i <= n;i ++)
		for(Rint j = 0;j < len[i] - 1;j ++)
			if(s[i][j] == 'A' && s[i][j + 1] == 'B') ++ ans;
	for(Rint i = 1;i <= n;i ++)
		if(s[i][0] == 'B' && s[i][len[i] - 1] == 'A') ++ c1;
		else if(s[i][0] == 'B') ++ c2;
		else if(s[i][len[i] - 1] == 'A') ++ c3;
	if(c2 && c3) tmp = max(tmp, c1 + 1 + min(c2 - 1, c3 - 1));
	tmp = max(tmp, min(c3 - 1, c2) + c1);
	tmp = max(tmp, min(c2 - 1, c3) + c1);
	if(c2 == 0 && c3 == 0) tmp = max(tmp, c1 - 1);
	printf("%d", ans + tmp);
}

Measured memory_bytes: 384
unittest
{
	assert( [ "3", "1 2 3" ].parse.expand.solve == "Yes" );
	assert( [ "4", "1 2 4 8" ].parse.expand.solve == "No" );
	
	assert( [ "4", "0 0 0 0" ].parse.expand.solve == "Yes" );		// 追加ケース
	assert( [ "3", "2 0 2" ].parse.expand.solve == "Yes" );			// 追加ケース
	assert( [ "4", "2 0 2 2" ].parse.expand.solve == "No" );		// 追加ケース
	assert( [ "3", "1 0 2" ].parse.expand.solve == "No" );			// 追加ケース
	assert( [ "3", "1 4 6" ].parse.expand.solve == "No" );			// 追加ケース
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( as );
}

auto solve( long[] as )
{
	auto ans = false;
	auto gs = as.sort().group.array;
	switch( gs.length )
	{
		case 3:		// 値が3種類 かつ [ x, y, z ]( x ^ y ^ z == 0 )のセットにできる ならOK
			ans = ( ( gs[ 0 ][ 0 ] ^ gs[ 1 ][ 0 ] ^ gs[ 2 ][ 0 ] ) == 0 &&
			        gs[ 0 ][ 1 ] == gs[ 1 ][ 1 ] && gs[ 1 ][ 1 ] == gs[ 2 ][ 1 ] );
			break;
		case 2:		// 値が2種類 かつ [ x, 0, x ]のセットにできる ならOK
			ans = ( gs[ 0 ][ 0 ] == 0 && gs[ 0 ][ 1 ] * 2 == gs[ 1 ][ 1 ] );
			break;
		case 1:		// 値が1種類 かつ オール0 ならOK
			ans = ( gs[ 0 ][ 0 ] == 0 );
			break;
		default:
			ans = false;
			break;
	}
	return ans ? "Yes" : "No";
}


Measured memory_bytes: 5772
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
int main()
{
	int n,i,sum1=0,sum2=0;
	for(i=1;i<=3;i++)
	{
		scanf("%d",&n);
		if(n==5)
		sum1++;
		if(n==7)
		sum2++;
	}
	if(sum1==2&&sum2==1)
	printf("YES");
	else
	printf("NO");
	return 0;


	return 0;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define int long long int
#define si(x)   scanf("%d",&x)
#define sl(x)   scanf("%lld",&x)
#define ss(s)   scanf("%s",s)
#define pi(x)   printf("%d\n",x)
#define pl(x)   printf("%lld\n",x)
#define ps(s)   printf("%s\n",s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define INF 1e9+7
typedef pair<int, int>  pii;
typedef vector<int>     vi;
typedef vector<pii>     vpii;
typedef vector<vi>      vvi;
int mpow(int base, int exp);
void ipgraph(int m);
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
const int mod = 1000000007;
const int N = 2e5+5, M = N;
//=========================================

const int MAXV = 1e5 + 10;
const int MAXN = 1e3 + 10;

int dp[MAXV];
int n, W, V, wi[MAXN], value[MAXN];


int32_t main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    //int n, W;
    cin >> n >> W;

    for(int i = 1; i <= n; ++i){
        cin >> wi[i] >> value[i];
        V += value[i];
    }

    for(int i = 1; i <= V; ++i) dp[i] = 1e13;
    dp[0] = 0;

    for(int item = 1; item <= n; ++item){
        int w = wi[item], v = value[item];
        for(int i = V; i >= v; --i)
            dp[i] = min(dp[i], dp[i - v] + w);
    }

    for(int i = V; i >= 0; --i){
        if(dp[i] <= W){
            cout << i << endl;
            break;
        }
    }


    return 0;
}


Measured memory_bytes: 1024
a,b,c,x,y = map(int, input().split() )

#print(a,b,c,x,y)

cost = a*x + b*y

for i in range( max(x,y) +1):
  tmp = i * 2*c + max(0, x-i)*a + max(0, y-i)*b
  if tmp < cost:
    cost = tmp
    
print( cost )

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using P=pair<int,int>;

const int maxh=50,maxw=50,INF=1000000001;
int gx,gy,h,w;

char m[maxh][maxw];
int dis[maxh][maxw];

int bfs(){
  queue<P> que;
  que.push(P(0,0));
  int mx[4]={1,0,-1,0};
  int my[4]={0,1,0,-1};
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      dis[i][j]=INF;
    }
  }dis[0][0]=1;
  while(!que.empty()){
    P p=que.front(); que.pop();
    int x=p.first,y=p.second;
    if(x==gx && y==gy) break;
    for(int i=0;i<4;i++){
      int nx=x+mx[i],ny=y+my[i];
      if(dis[nx][ny]==INF && nx>=0 && ny>=0 && h>=nx && w>=ny && m[nx][ny]=='.'){
        dis[nx][ny]=1+dis[x][y];
        que.push(P(nx,ny));
      }
    }
  }
  return dis[gx][gy];
}

int main(){
  cin>>h>>w;
  int count=0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>m[i][j];
      if(m[i][j]=='#') count++;
    }
  }gx=h-1; gy=w-1;
  int ans=bfs();
  if(ans==INF){
    cout<<-1<<endl;
  }else{
    ans=h*w-ans-count;
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
//#include<string>
#include<algorithm>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main() {
	int M, D;
	cin >> M >> D;
	int d1, d10;
	int count = 0;
	for (int i = 4; i <= M; ++i) {
		for (int j = 10; j <= D; ++j) {
			d1 = j % 10;
			d10 = (j - d1)/10;
			if (i == d1 * d10&&d1>=2&&d10>=2) {
				++count;
			}
		}
	}
	cout << count << endl;
}


Measured memory_bytes: 256
main = do
  [a,b,c,d] <- map read.words<$>getLine :: IO [Integer]
  print $ solve a b c d

solve a b c d = cs + ds - cds
  where
  [cs, ds, cds] = map f [c, d, lcm c d]
  f n = (b-a+1) - ( b`div`n - (a-1)`div`n)

Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
void print() { cout << "\n"; }
template <class T> void print(const T &x) { cout << x << "\n"; }
template <class T, class... Args> void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
template <class T> void printVector(const vector<T> &v) {
    for(const T &x : v) {
        cout << x << " ";
    }
    cout << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int n;
vector<int> a, ans;
vector<vector<int>> g;

void dfs(int v, int p, vector<int> &dp) {
    int tmp = -INF;
    auto it = lower_bound(ALL(dp), a[v]);
    int id = it - dp.begin();
    if(it == dp.end()) {
        dp.emplace_back(a[v]);
    } else {
        tmp = *it;
        dp[id] = a[v];
    }
    ans[v] = dp.size();
    for(const auto &u : g[v]) {
        if(u == p) {
            continue;
        }
        dfs(u, v, dp);
    }
    if(tmp == -INF) {
        dp.pop_back();
    } else {
        dp[id] = tmp;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    a.resize(n);
    g.resize(n);
    ans.resize(n, -1);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for(int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        g[--u].emplace_back(--v);
        g[v].emplace_back(u);
    }
    vector<int> dp;
    dfs(0, -1, dp);
    for(int i = 0; i < n; i++) {
        print(ans[i]);
    }
}

Measured memory_bytes: 30092
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        List<Integer> min = new ArrayList<>();
        List<Integer> max = new ArrayList<>();
        for(int i=0;i<N;i++){
            min.add(sc.nextInt());
            max.add(sc.nextInt());
        }
        Collections.sort(min);
        Collections.sort(max);
        if(N%2 == 1){
            System.out.println(max.get(N/2) - min.get(N/2) + 1);
        }else{
            System.out.println(((max.get(N/2) + max.get(N/2-1)) - (min.get(N/2) + min.get(N/2-1)))+ 1);
        }
    }
}

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

int main() 
{
	int n;
	set<int> a;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		a.insert(x);
	}
	if(a.size()==n)
	{
		cout<<"YES"<<endl;
	}
	else
	{
		cout<<"NO"<<endl;
	}
	return 0;
}
	

Measured memory_bytes: 9600
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include <limits>
#include <iomanip>
#include <cassert>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n-1;i >= 0;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second

const long double pi = 3.141592653589793;
const int mod = 1e9 + 7;

bool avada(int x, int y, int z) {
  return (x + y) > z;
}

int main() {

 // freopen("input.in","r",stdin);
 // freopen("output.out","w",stdout);

 ios_base::sync_with_stdio(false);
 cin.tie(nullptr);

  ll X, K, D;cin>>X>>K>>D;
  X = abs(X);

  if(K <= X/D) cout << X - K*D << endl;
  else {
    K -= X/D;
    X = X - (X/D)*D;
    if(K%2 == 0) cout << X << endl;
    else cout << abs(X-D) << endl;
  }


 return 0;
}


Measured memory_bytes: 3604
N,M=list(map(int,input().split()))
l=[list(input()) for i in range(N)]
mini=[list(input()) for i in range(M)]
mini="".join(sum(mini,[]))
for i in range(N-M+1):
   for j in range(N-M+1):
      let=""
      for k in range(i,M+i):
         let+="".join(l[k][j:j+M])
      if mini == let:
         print("Yes")
         exit()
print("No")

Measured memory_bytes: 3064
n = int(input())
a = list(map(int, input().split()))

max_node = [0 for _ in range(n+1)]
for i in range(n-1, -1, -1):
    max_node[i] = max_node[i+1] + a[i+1]

ans = 1
node = 1
for i in range(n+1):
    node -= a[i]
    if (i < n and node <= 0) or node < 0:
        print(-1)
        exit(0)
    node = min(node * 2, max_node[i])
    ans += node
print(ans)

Measured memory_bytes: 20060
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

	int N;
	ll K;
	cin >> N >> K;
	vector<int> A(N + 1);
	REP(i, N) { cin >> A[i + 1]; }
	int cnt = 0;
	int b;
	int res;
	int i = 1;
	vector<int> memo(N + 1, -1);
	while (true) {
		if (memo[i] >= 0) {
			cnt = cnt - memo[i];
			b = memo[i];
			res = i;
			break;
		}
		memo[i] = cnt;
		++cnt;
		i = A[i];
	}
	if (K < b) {
		res = 1;
		REP(i, K) { res = A[res]; }
	} else {
		K -= b;
		K %= cnt;
		REP(i, K) { res = A[res]; }
	}
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 4784
H, W, K = list(map(int, input().split()))
S = [input() for _ in range(H)]
nrow = [s.count('#') for s in S]
hline = [-1]+[i for i in range(H) if nrow[i]>0][:-1] + [H-1]

ans = [[None]*W for _ in range(H)]

k=1
for ihline in range(1, len(hline)):
    ncol = [0]*W
    for r in range(W):
        for ih in range(hline[ihline-1]+1, hline[ihline]+1):
            if S[ih][r]=='#': ncol[r]+=1
    vline = [-1]+[i for i in range(W) if ncol[i]>0][:-1] + [W-1]

    for ivline in range(1, len(vline)):
        for ih in range(hline[ihline-1]+1, hline[ihline]+1):
            for ir in range(vline[ivline-1]+1, vline[ivline]+1):
                ans[ih][ir] = k
        k+=1

for r in ans:
    print(*r)

Measured memory_bytes: 7568
import java.util.*;
 
public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int w = sc.nextInt();
        int weight[] = new int[n];
        int value[] = new int[n];
        for(int i=0; i<n; i++){
            weight[i] = sc.nextInt();
            value[i] = sc.nextInt();
        }
        long dp[][] = new long[110][100100];
        for(int i=0; i<n; i++){
            for(int sum_w=0; sum_w<=w; sum_w++){
                if(sum_w - weight[i]>=0){
                    dp[i+1][sum_w] = Math.max(dp[i+1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
                }
                dp[i+1][sum_w] = Math.max(dp[i+1][sum_w], dp[i][sum_w]);
            }
        }
        System.out.println(dp[n][w]);
    }
}


Measured memory_bytes: 127568
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int a, b;
		Scanner scanner = new Scanner (System.in);
		a = scanner.nextInt();
		b = scanner.nextInt();

		if(a >= 13) {
			System.out.println(b);
		}else if(a >=6 && a <= 12) {
			System.out.println(b/2);
		}else {
			System.out.println("0\n");
		}
	}
}

Measured memory_bytes: 21844
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;

namespace ABC103A
{
    class Program
    {
        static void Main(string[] args)
        {
            var A = RInts;
            int ans = A.Max() - A.Min();
            Console.WriteLine(ans);
        }


    }


}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String RNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int RInt => int.Parse(RNext());
        public static long RLong => long.Parse(RNext());
        public static int[] RInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] RLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
        public static string RString => RNext();
        //以下未テスト
        public static int[] RIntsC(int c) => Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
        public static long[] RLongsC(int c) => Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
        public static char[][] RMap(int h) => Enumerable.Repeat(0, h).Select(x => Console.ReadLine().ToCharArray()).ToArray();
    }

    static class Debug
    {
        static public void Draw2D<T>(T[,] map, int mode = 1)
        {
#if DEBUG
            int W = map.GetLength(0);
            int H = map.GetLength(1);

            string[,] map2 = new string[W + 1, H + 1];
            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (i == 0 && j == 0) map2[i, j] = 0.ToString();
                    else if (i == 0) map2[i, j] = (j - 1).ToString();
                    else if (j == 0) map2[i, j] = (i - 1).ToString();
                    else map2[i, j] = map[i - 1, j - 1].ToString();
                }
            }

            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (mode == 0) Console.Write(map2[i, j].Last());
                    if (mode == 1) Console.Write(map2[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
#endif
        }

        public static void Draw1D<T>(T[] array, int mode = 0)
        {
#if DEBUG
            Console.WriteLine(string.Join(" ", array));
#endif
        }
    }
}


Measured memory_bytes: 13268
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000000ll
#define all(x) x.begin(),x.end()
#define fi first
#define se second
using pint = pair<int,int>;
using vec = vector<int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
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 dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


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

    ll n,x;
    cin>>n>>x;
    vll a(n);
    rep(i,n) cin>>a[i];
    ll ans= 0;
    if(a[0] > x){
        ans += a[0] - x;
        a[0] = x;
    }

    rep(i,n-1){
        if(a[i] + a[i + 1] > x){
            ans += (a[i] -x)+ a[i + 1];
            a[i+1] = x - a[i];
        }
    }

    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4000
#include<iostream>
#include<cstring>
bool good[10000000];
using namespace std;
int main(){
	int m,n;
	int i,j,k;
	int a,b,c;
	while(cin>>m>>n){
		if(!m)break;
		memset(good,false,sizeof(good));
		for(i=m,j=0;;i++){
			if(!good[i]){
				if(j==n)break;
				j++;
				for(k=i;k<1e7;k+=i)good[k]=true;
			}
		}
		cout<<i<<endl;
	}
}



Measured memory_bytes: 12868
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(void){
    vector<int> abc(3);
    cin >> abc[0] >> abc[1] >> abc[2];
    int k;
    cin >> k;

    sort(abc.begin(),abc.end());

    for(int i = 0; i < k; i++){
        abc[2] *= 2;
    }

    cout << abc[0] + abc[1] + abc[2]<< endl;
    return 0;
}


Measured memory_bytes: 384
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

main {
  int n;
  cin >> n;
  auto v = vectors(4, 3, 10, 0LL);
  rep(i, n) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    --a, --b, --c;
    v[a][b][c] += d;
  }
  rep(i, 4) {
    if (i) cout << "####################" << endl;
    rep(j, 3) {
      rep(k, 10) cout << ' ' << v[i][j][k];
      cout << endl;
    }
  }
}



Measured memory_bytes: 3168
// knapsack

#include<cstdio>
#include<vector>
#include<algorithm>
#include<functional>

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

using namespace std;

const int INF=1<<29;

int main(){
	int n,k; scanf("%d%d",&n,&k);
	vector<int> genre[10];
	rep(i,n){
		int val,g; scanf("%d%d",&val,&g); g--;
		genre[g].push_back(val);
	}

	int dp[11][2001];
	rep(j,k+1) dp[0][j]=(j==0?0:-INF);
	rep(g,10){
		rep(j,k+1) dp[g+1][j]=dp[g][j];

		sort(genre[g].begin(),genre[g].end(),greater<int>());
		int sum=0;
		rep(i,genre[g].size()){
			sum+=genre[g][i];

			int val=sum+i*(i+1),cost=i+1;
			for(int j=k;j>=cost;j--) dp[g+1][j]=max(dp[g+1][j],dp[g][j-cost]+val);
		}
	}
	printf("%d\n",dp[10][k]);

	return 0;
}

Measured memory_bytes: 0
def solve():
  N = int(input())
  A = [int(input()) for _ in range(N)]
  ans = A[0]//2
  A[0] = A[0]%2
  for i in range(1,N):
    ans += (A[i]+A[i-1])//2
    if (A[i]+A[i-1])//2>0:
      A[i] = (A[i]+A[i-1])%2
  return ans
print(solve())

Measured memory_bytes: 13012
n, k = [int(i) for i in input().split()]

ans = 0
if k == 0:
    ans = n ** 2
else:
    for b in range(1, n+1):
        if b > k:
            loop_num = n // b #繰り返し回数
            loop_last = n - loop_num * b #ラストの途中で途切れてる部分
            ans += (b-k) * loop_num + max(0, loop_last - k + 1)

print(ans)


Measured memory_bytes: 9112
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int sum = n + (int) Math.pow(n, 2) + (int) Math.pow(n, 3);
        System.out.println(sum);

    }
}

Measured memory_bytes: 35672
void main(){
	int n, m;
	readf("%d %d\n", &n, &m);
	int[] a = _scanln();
	int ans;
	int allsum = a.sum();
	foreach(elm; a){
		if(elm*4*m >= allsum)ans++;	
	}
	writeln(ans>=m? "Yes": "No");
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


Measured memory_bytes: 2852
//https://atcoder.jp/contests/nikkei2019-2-qual/tasks/nikkei2019_2_qual_a

#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>
#include <stack>
#include <math.h>
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define RREP(i,n) for(ll i=(n)-1; i>=0; --i)
#define SREP(i,s,n) for(ll i=(s), i##_len=(n); i<i##_len; ++i)
#define ALL(v) (v).begin(),(v).end()

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

bool comp(pair<ll, ll> a, pair<ll, ll> b) {
    return a.second < b.second;
}

struct UnionFind {
    vector<int> par;
    vector<int> rank;
    
    UnionFind(int n = 1) {
        init(n);
    }
    
    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
        }
    }
    
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};

#define MOD (1000000007)
#define BIGNUM (ll(1e18))

int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;
    if (N%2) {
        cout << N/2 << endl;
    } else {
        cout << N/2-1 << endl;
    }
}


Measured memory_bytes: 256
{-# LANGUAGE FlexibleInstances    #-}
{-# LANGUAGE TypeSynonymInstances #-}

import           Control.Applicative
import           Control.DeepSeq
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                  as A
import qualified Data.Array.IArray           as IA
import qualified Data.Array.IO               as AI
import qualified Data.Array.MArray           as MA
import qualified Data.Array.ST               as STA
import qualified Data.Array.Unboxed          as AU
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import qualified Data.Graph                  as G
import           Data.Int
import qualified Data.IntMap                 as IM
import qualified Data.IntSet                 as IS
import           Data.List
import qualified Data.Map.Strict             as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Sequence               as SQ
import qualified Data.Set                    as S
import           Data.Time
import qualified Data.Tree                   as T
import qualified Data.Vector                 as V
import qualified Data.Vector.Mutable         as VM
import qualified Data.Vector.Unboxed         as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readInteger :: IO [Integer]
readInteger = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegers :: Int -> IO [[Integer]]
readIntegers n = replicateM n readInteger

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

put :: Show a => a -> IO ()
put = putStr . show

putLn :: Show a => a -> IO ()
putLn = print

putList :: Show a => [a] -> IO ()
putList [n] = put n
putList (n:ns) = do
  put n
  putStr " "
  putList ns

putStrList :: [String] -> IO ()
putStrList [n] = putStr n
putStrList (n:ns) = do
  putStr n
  putStr " "
  putStrList ns

yesNoUpper b
  | b = putStrLn "YES"
  | otherwise = putStrLn "NO"

yesNo b
  | b = putStrLn "Yes"
  | otherwise = putStrLn "No"

main = do
  n <- getLine
  putStrLn $ "ABC" ++ n


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

int main(){
    int a,b,d,r;
    double f;
    cin >> a >> b;
    d = a / b;
    r = a % b;
    f = (double)a / b;
    cout << d << " " << r << " " << fixed << f << endl;
    return 0;
}


Measured memory_bytes: 3248
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

ll dp[1010][1010];


int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int H,W; cin >> H >> W;
    string grid[1010];
    REP(i,H) cin >> grid[i];
    dp[0][0] = 1;
    REP(i,H){
        REP(j,W){
            if(grid[i+1][j]!='#') (dp[i+1][j] += dp[i][j]) %= MOD;
            if(grid[i][j+1]!='#') (dp[i][j+1] += dp[i][j]) %= MOD;
        }
    }
    cout << dp[H-1][W-1] << endl;
    return 0;
}

Measured memory_bytes: 9216
#include <stdio.h>

//配列とスタートの要素番号を入力すると、半角スペースの要素番号を出力
int yomisute(char str[],int i)
{
	while(str[i] != ' ')
	{
		i++;
	}
	return i;
}

int main(void)
{
	int a_num,b_num,c_num,d_num;
	char a,b,c,d;
	char str[72];
	
	fgets(str,sizeof(str),stdin);
	
	a_num = yomisute(str,0) - 1;
	a = str[a_num];
	
	b_num = a_num + 2;
	b = str[b_num];
	
	c_num = yomisute(str,b_num) - 1;
	c = str[c_num];
	
	d_num = c_num + 2;
	d = str[d_num];
	

	if((a == b)&&(c == d))
	{
		puts("YES");
	}else
	{
		puts("NO");
	}
	return 0;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

// Problem Specific Parameter:

int main() {
  char c; cin >> c;
  if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') cout << "vowel" << endl;
  else cout << "consonant" << endl;

  return 0;
}




Measured memory_bytes: 256
def SumofNthDecimal( a, b, n )
	r = a % b
	s = 0
	i = 0
	while r != 0 && i < n
		a1 = r * 10

		d  = a1 / b 
		r  = a1 % b 
		s  += d
		i += 1
	end
	return s
end

def main
	answer = Array.new
	while line = $stdin.gets
		nums = line.chomp.split( /\s/ ).map{ |n| n.to_i }
		answer << SumofNthDecimal( nums[ 0 ], nums[ 1 ], nums[ 2 ] )
	end
	answer.each{ |a| puts a }
end
main


Measured memory_bytes: 6092
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int dp[5][105][2];
int main(){
    string s;
    cin >> s;
    int k;
    cin >> k;
    dp[0][0][0] = 1;
    rep(i,k+1){
        rep(j,s.size()){
            int x = s[j] - '0';
            rep(k,2){
//                show(i,j,k,x,dp[i][j][k]);
                if(k == 0){
                    for(int l = 0; l < x; l++){
                        dp[i + (l == 0 ? 0 : 1)][j+1][1] += dp[i][j][k];
                    }
                    dp[i + (x == 0 ? 0 : 1)][j+1][0] += dp[i][j][k];
                }else{
                    dp[i][j+1][1] += dp[i][j][1];
                    if(i+1<=3)dp[i+1][j+1][1] += dp[i][j][1]*9;
                }
            }
        }
    }
    cout << dp[k][s.size()][0] + dp[k][s.size()][1] << endl;
}


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

using namespace std;

vector<int> G[100000];
vector<int> H[100000];
int d[100000];
bool used[100000];
bool used1[100000];
bool used2[100000];

queue<int> que;
queue<int> que1;
queue<int> que2;

void dfs(int v, int d){

}

int main(){
    int N, M;
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        G[u].push_back(v);
    }
    int S, T;
    cin >> S >> T;
    S--;
    T--;
    que.push(S);
    used[S] = true;
    int dst = 0;
    while(!que.empty()){
        int top = que.front();
        //cout << top << endl;
        que.pop();
        for(int i = 0; i < G[top].size(); i++){
            int v = G[top][i];
            if(!used1[v])que1.push(v);
            used1[v] = true;
        }
        while(!que1.empty()){
            int t = que1.front();
            que1.pop();
            for(int i = 0; i < G[t].size(); i++){
                int v = G[t][i];
                if(!used2[v])que2.push(v);
                used2[v] = true;
            }
        }
        while(!que2.empty()){
            int t = que2.front();
            que2.pop();
            for(int i = 0; i < G[t].size(); i++){
                int v = G[t][i];
                if(!used[v]){
                    //cout << v << endl;
                    que.push(v);
                    d[v] = d[top]+1;
                }
                used[v] = true;
            }
        }
    }
    if(d[T] == 0){
        cout <<   -1 << endl;
    }else{
        cout << d[T] << endl;
    }
}

Measured memory_bytes: 8704
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <set>
using namespace std;
const int Maxn = 100010;
int a[Maxn], n;
set <int> S;
set <int> :: iterator it;
int _abs(int x) { return x < 0 ? -x : x; }
int main() {
	int i, j, k;
	scanf("%d", &n);
	for(i = 1; i <= n; i++) scanf("%d", &a[i]);
	sort(a+1, a+n+1);
	for(i = 1; i < n; i++) S.insert(a[i]);
	it = S.lower_bound(a[n]+1>>1);
	int ans = 0;
	if(it != S.end()) ans = (*it);
	if(it != S.begin()){
		it--;
		if(_abs(2*(*it)-a[n]) < _abs(2*ans-a[n])) ans = (*it);
	}
	printf("%d %d\n", a[n], ans);
	return 0;
}

Measured memory_bytes: 5376