akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
    #include <vector>
    #include <bits/stdc++.h>
    #define rep(i, n) for (int i = 0; i < (n); ++i)
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> P;
     
    #define pb push_back
    #define eb emplace_back
    #define fi first
    #define se second
    #define bg begin()
    #define ed end()
    #define all(x) x.bg, x.ed
    #ifdef LOCAL
    #define dmp(x) cerr << __LINE__ << " " << #x << " " << x << endl
    #else
    #define dmp(x) void(0)
    #endif
     
    template <class t, class u>
    void chmax(t &a, u b)
    {
      if (a < b)
        a = b;
    }
    template <class t, class u>
    void chmin(t &a, u b)
    {
      if (b < a)
        a = b;
    }
    const int mod = 1000000007;
    struct mint
    {
      ll x; // typedef long long ll;
      mint(ll x = 0) : x((x % mod + mod) % mod) {}
      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)
      {
        assert(n < mod);
        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];
      }
    };
     
    template <class t>
    using vc = vector<t>;
    template <class t>
    using vvc = vc<vc<t>>;
     
    using vi = vc<int>;
    int gcd(int a, int b)
    {
      if (b == 0)
        return a;
      return gcd(b, a % b);
    }
    int lcm(int a, int b)
    {
      return (a * b) / gcd(a, b);
    }
     
    int main()
    {
      int n, m;
      cin >> n >> m;
      if(n == m)cout << "Yes" <<endl;
      else cout<<"No"<<endl;
    }

Measured memory_bytes: 256
fn serial_to_point(serial: usize, w: usize) -> (usize, usize) {
    (serial%w, serial/w)
}

fn calc_distance(s: usize,  g: usize, m: &Vec<Vec<char>>) -> usize {
    let h = m.len() as isize;
    let w = m[0].len() as isize;
    let dist_none = w*h*10;
    let mut dist_map = vec![vec![dist_none; w as usize]; h as usize];

    let (sx_t, sy_t) = serial_to_point(s, w as usize);
    let (sx, sy) = (sx_t as isize, sy_t as isize);
    let (gx_t, gy_t) = serial_to_point(g, w as usize);
    let (gx, gy) = (gx_t as isize, gy_t as isize);

    let mut q = std::collections::VecDeque::<(isize, isize)>::new();
    dist_map[sy as usize][sx as usize] = 0;
    q.push_front((sx, sy));

    loop {
        if let Some((x, y)) = q.pop_back() {
            let dist = dist_map[y as usize][x as usize];
            if (x, y) == (gx, gy) {
                return dist as usize;
            }

            for i in 0..4 {
                let (nx, ny) = match i {
                    0 => (x-1, y),
                    1 => (x, y-1),
                    2 => (x+1, y),
                    _ => (x, y+1),
                };

                if nx < 0 || nx >= w || ny < 0 || ny >= h {
                    continue;
                }

                if dist_map[ny as usize][nx as usize] != dist_none {
                    continue;
                }

                if m[ny as usize][nx as usize] != '.' {
                    continue;
                }

                dist_map[ny as usize][nx as usize] = dist+1;
                q.push_front((nx, ny));
            }
        }
        else {
            break
        }
    }

    // unreachable to goal
    0
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let h: usize = iter.next().unwrap().parse().unwrap();
    let w: usize = iter.next().unwrap().parse().unwrap();

    let mut maze = vec![vec!['.'; w]; h];

    for y in 0..h {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        maze[y] = buf.trim().chars().collect();
    }

    let mut ans = 0usize;
    for s in 0..(w*h-1) {
        let (sx, sy) = serial_to_point(s, w);
        if maze[sy][sx] == '.' {
            for g in (s+1)..(w*h) {
                let (gx, gy) = serial_to_point(g, w);
                if maze[gy][gx] == '.' {
                    ans = std::cmp::max(ans, calc_distance(s, g, &maze));
                }
            }
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"---------------"#x"---------------"<<endl
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
						For(_x,L,R)cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector <int> vi;
typedef long double LD;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f|=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int N=200005;
int n;
vector <int> v;
int f[N];
int main(){
	n=read();
	if (n==3)
		return puts("2 5 63"),0;
	For(i,1,30000)
		f[i]=i%2==0||i%3==0||i%5==0;
	For(i,1,29970)
		if (f[i])
			v.pb(i);
	while (1){
		random_shuffle(v.begin()+3,v.end());
		int sum=0;
		For(i,0,n-2)
			sum+=v[i];
		sum=30000-sum%30;
		if (f[sum]){
			For(i,0,n-2)
				printf("%d ",v[i]);
			printf("%d\n",sum);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 640
s = list(input())

d = len(s)-1
ans = 0

for i in range(2**d):
    op = ['']*(d+1)
    for j in range(d):
        if (i >> j) & 1:
            op[j] = '+'

    formula = ''
    for a, b in zip(s, op):
        formula += a + b

    ans += eval(formula)

print(ans)


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

int main(void) {
	int N;
	int a = 1 * 3 * 5 * 7;		// 105
	int b = 1 * 3 * 3 * 3 * 5;	// 135
	int c = 1 * 3 * 5 * 11;		// 165
	int d = 1 * 3 * 3 * 3 * 7;	// 189
	int e = 1 * 3 * 5 * 13;		// 195

	cin >> N;
	int ans = 0;
	if (N >= a) ++ans;
	if (N >= b) ++ans;
	if (N >= c) ++ans;
	if (N >= d) ++ans;
	if (N >= e) ++ans;

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>

int main()
{
    double L[10];
    double V1, V2;
    double meet_pos;
    double railway_lenth;
    int cnt1, cnt2;
    int output[50];
    
    cnt2 = 0;
    while(scanf("%lf,", &L[0]) != EOF){
    	for(cnt1 = 1; cnt1 < 10; cnt1++)
    	{
			scanf("%lf,", &L[cnt1]);
		}
		scanf("%lf,%lf", &V1, &V2);
    	
    	railway_lenth = 0;
    	for(cnt1 = 0; cnt1 < 10; cnt1++)
    	{
			railway_lenth += L[cnt1];
		}
    	meet_pos = railway_lenth * V1 / (V1 + V2);
    	
    	cnt1 = 0;
    	railway_lenth = 0;
    	while(railway_lenth < meet_pos)
    	{
			railway_lenth += L[cnt1];
			cnt1++;
    	}
    	output[cnt2] = cnt1;
    	cnt2++;
    }
    
    for(cnt1 = 0; cnt1 < cnt2; cnt1++)
    {
		printf("%d\n", output[cnt1]);
	}
    
	
    return 0;
} 

Measured memory_bytes: 624
#include <bits/stdc++.h>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#define N 100005
using namespace __gnu_pbds;
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
LL z = 1;
int read(){
	int x, f = 1;
	char ch;
	while(ch = getchar(), ch < '0' || ch > '9') if(ch == '-') f = -1;
	x = ch - '0';
	while(ch = getchar(), ch >= '0' && ch <= '9') x = x * 10 + ch - 48;
	return x * f;
}
char s[N];
int main(){
	int i, j, n, m;
	scanf("%s", s + 1);
	n = strlen(s + 1);
	for(i = 1; i <= n; i++){
		if(s[i] == s[i + 1]){
			printf("%d %d", i, i + 1);
			return 0;
		}
		if(s[i] == s[i + 2]){
			printf("%d %d", i, i + 2);
			return 0;
		}
	}
	printf("-1 -1");
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
 
int main() {
  string C1, C2; cin >> C1 >> C2;

  string result = "NO";
  if ( C1[0] == C2[2] && C1[1] == C2[1] && C1[2] == C2[0] ) {
    result = "YES";
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main()
{
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> vc(N + 1);
  for (int i = 0; i < M; i++)
  {
    int A;
    cin >> A;
    vc[A]++;
  }
  int ans1 = 0;
  int ans2 = 0;
  for (int i = 1; i < X; i++)
  {
    if (0 < vc[i])
      ans1++;
  }
  for (int i = X + 1; i < N; i++)
  {
    if (0 < vc[i])
      ans2++;
  }
  cout << min(ans1, ans2) << endl;
  return 0;
}

Measured memory_bytes: 256
import fractions

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

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

if N==1:
  print(abs(X-x[0]))
  exit()

distance=[0]*N

for i in range(N):
  distance[i]=abs(x[i]-X)

distance.sort()

D=distance[0]
for i in range(N):
  D=min(D,fractions.gcd(D,distance[i]))
print(D)

Measured memory_bytes: 16296
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;

int main()
{
    int q;
    while (cin >> q && q != -1) {
        double x1 = q / 2.0;
        while (true) {
            if (abs(x1*x1*x1 - q) < 0.00001*q) {
                break;
            }
            double t1 = 3*x1*x1;
            x1 = x1 - (x1 / 3.0 - q / t1);
        }
        printf("%.06lf", x1);
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
#define myCeil(dividend, divisor) ceil((double)(dividend) / (double)(divisor))
#define myFloor(dividend, divisor) floor((double)(dividend) / (double)(divisor))
#define calcDigits(num) floor(log10(num))+1

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl;
#define dv(name, value) cerr << (name) << " is " << (value) << endl;
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl;
#define dpa(v) cerr << "[ " << endl;REPI(itr, v) { cerr << "  [" << (*itr).first << ", " << (*itr).second << ']' << (itr != --v.end() ? "," : "") << endl; } cerr << "]" << endl;


void solve(long long a, std::string s){
  cout << (a >= 3200 ? s : "red") << endl;
}

signed main(){
  long long a;
  scanf("%lld",&a);
  std::string s;
  std::cin >> s;
  solve(a, s);
}


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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)

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

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 55, M = 3e3, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;

int main(){
    init();

    int h, w;   cin >> h >> w;
    for(int i = 0;i < h;i++){
        string s;   cin >> s;
        cout << s << '\n' << s << '\n';
    }
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e16+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll h,w;
    cin>>h>>w;
    VVi grid(h+2,Vi(w+2,-1));

    REP(i,1,h+1){
        REP(j,1,w+1){
            int tmp;
            cin>>tmp;
            grid[i][j] = tmp;
        }
    }

    ll cnt=0;
    vector<Pi> bef;
    vector<Pi> aft;
    //i 上下 //w 左右
    REP(i,1,h+1){
        REP(j,1,w+1){
            if(grid[i][j]%2==0){
                continue;
            }
            if(grid[i][j+1]!=-1){
                grid[i][j+1]++;
                grid[i][j]--;
                bef.emplace_back(i,j);
                aft.emplace_back(i,j+1);
                cnt++;
                continue;
            }
            if(grid[i+1][j]!=-1){
                grid[i+1][j]++;
                grid[i][j]--;
                bef.emplace_back(i,j);
                aft.emplace_back(i+1,j);
                cnt++;
                continue;
            }
        }
    }


    cout<<cnt<<endl;
    rep(i,cnt){
        Pi &be = bef[i];
        Pi &af = aft[i];
        cout<<be.fi<<" "<<be.se<<" "<<af.fi<<" "<<af.se<<endl;
    }

    return  0;
}


Measured memory_bytes: 5356
#include<stdio.h>
#include<string.h>

int main()
{
    char s[10000];
    scanf("%s",&s);
    int len;
    len = strlen(s);
    int count = 0;

    int start = 0,end = len-1;
    while(start<end)
    {
        if(s[start]==s[end])
        {
            start++;
            end--;

        }
        else{
            count++;
            start++;
            end--;

        }

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

}


Measured memory_bytes: 128
p = []
for i in range(3):
    a1, b1 = map(int, input().split())
    p.append(a1)
    p.append(b1)

point = [0, 0, 0, 0]
for town in p:
    point[town-1] += 1
    if point[town-1] > 2:
        print('NO')
        quit()

print('YES')

Measured memory_bytes: 3060
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>  // https://boostjp.github.io/tips/math.html
#include <boost/dynamic_bitset.hpp>  // https://boostjp.github.io/tips/dynamic_bitset.html

constexpr int64_t DIV1097 = 1000000007LL;

using namespace std;

int main()
{
    int64_t N;
    std::cin >> N;

    // std::cout.precision(20);

    // std::string S;
    // std::cin >> S;

    std::unordered_map<int64_t, int64_t> M;


    for (decltype(N) i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;

        M[t]++;
    }

    int64_t ans = 0;
    for (auto m: M) {
        if (m.second % 2 != 0) {
            ans++;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 4388
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int m, k; cin >> m >> k;
  int mx = 1;
  REP(i, m) mx *= 2;
  if (mx <= k) {
    cout << -1 << '\n';
    return 0;
  }
  if (k == 0) {
    REP(i, mx) cout << i << ' ' << i << (i == mx - 1 ? '\n' : ' ');
    return 0;
  }
  int judge = 0;
  REP(i, mx) judge ^= i;
  if (judge != 0) {
    cout << -1 << '\n';
    return 0;
  }
  vector<int> ans{k};
  REP(i, mx) if (i != k) {
    ans.emplace_back(i);
  }
  ans.emplace_back(k);
  for (int i = mx - 1; i >= 0; --i) if (i != k) {
    ans.emplace_back(i);
  }
  REP(i, ans.size()) cout << ans[i] << (i == ans.size() - 1 ? '\n' : ' ');
  return 0;
}


Measured memory_bytes: 2932
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
        int a = ni();
        String op = ns();
        int b = ni();

        if ("+".equals(op)) {
            out.println(a + b);
        } else {
            out.println(a - b);
        }
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 8148
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll N, D;
  cin>>N>>D;
  ll X, Y;
  int ans = 0;
  for(int i=0;i<N;++i) {
    cin>>X>>Y;
    if(X*X+Y*Y<=D*D) ans++;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3632
#include <iostream>
#include <string>

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()

using namespace std;

char getAppendChar(string S) {
    REP(i, 26)
        if (S.find('a' + i) == string::npos)
            return 'a' + i;
    return '\0';
}

char getAppendChar2(string S, char startChar) {
    FOR(i, 1, 26)
        if (S.find(startChar + i) == string::npos)
            return startChar + i;
    return '\0';
}

int main() {
    string S;
    cin >> S;

    if (getAppendChar(S) != '\0')
        cout << S << getAppendChar(S) << endl;
    else {
        int index = -1;
        for (int i = S.size() - 2; i >= 0; i--) {
            if (S[i] < S[i + 1]) {
                index = i;
                break;
            }
        }
        if (index == -1) {
            cout << -1 << endl;
            return 0;
        }

        cout << S.substr(0, index) << getAppendChar2(S.substr(0, index), S[index]) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>//for queue and priority_queue
#include <fstream>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#define endl "\n"
typedef long long ll;
using namespace std;
void Lancer() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
bool isPrime(ll n){
	if (n == 2 || n == 3 || n == 5)
		return true;
	else if (n % 2 == 0 || n % 3 == 0 || n % 5 == 0 || n == 1)
		return false;
	else {
		for (int i = 5; i <= sqrt(n); i += 2){
			if (n%i == 0)
				return false;
		}
		return true;
	}
}

char arr[107][107];
int main(){
	Lancer();
	int n, m, x, y, mn = 105, mx = -105;
	cin >> n >> m >> x >> y;
	vector<int> vec(n + m);
	for (int i = 0; i < n; i++){
		cin >> vec[i];
		mx = max(vec[i], mx);
	}
	for (int i = n; i < m + n; i++){
		cin >> vec[i];
		mn = min(vec[i], mn);
	}
	bool ch = false;
	for (int i = 0; i < n + m; i++){
		if (vec[i] > x &&vec[i] <= y && vec[i]>mx && mn >= vec[i]){
			ch = true;
			break;
		}
	}
	if (ch)cout << "No War";
	else cout << "War";
	cout << endl;
	return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define loop(i, a, b) for(int i = a; i < b; i++) 
#define rep(i, a) loop(i, 0, a)
using namespace std;
int MOD = 1000000007;
using vi = vector <int>;
using vvi = vector <vi>;
using vc = vector <char>;
using vvc = vector <vc>;
//g++ -std==c++14
//setprecision(10)
long long int n, one, two, matoba, risa;
vi a;
int main(){
    cin >> n;
    a = vi (n);
    rep(i, n) cin >> a[i];
    rep(i, n){
        if(!i){
            if(a[i] <= 0){
                one += abs(a[i]) + 1;
                matoba = 1;
            }
            else
                matoba += a[i];
        }
        else{
            if(i % 2){
                if(matoba + a[i] >= 0){
                    matoba += a[i];
                    one += 1 + matoba;
                    matoba -= 1 + matoba;
                }
                else
                    matoba += a[i];
            }
            else{
                if(matoba + a[i] <= 0){
                    matoba += a[i];
                    one += 1 + abs(matoba);
                    matoba += 1 + abs(matoba);
                }
                else
                    matoba += a[i];
            }
        }
        //cout << matoba << " " << one << endl;
    }
    //cout << endl;
    matoba = 0;
    rep(i, n){
        if(!i){
            if(a[i] >= 0){
                two += abs(a[i]) + 1;
                matoba = -1;
            }
            else
                matoba += a[i];
        }
        else{
            if(i % 2){
                if(matoba + a[i] <= 0){
                    matoba += a[i];
                    two += 1 + abs(matoba);
                    matoba += 1 + abs(matoba);
                }
                else
                    matoba += a[i];
            }
            else{
                if(matoba + a[i] >= 0){
                    matoba += a[i];
                    two += 1 + abs(matoba);
                    matoba -= 1 + abs(matoba);
                }
                else
                    matoba += a[i];
            }
        }
        //cout << matoba << " " << two << endl;
    }
    //cout << one << " " << two << endl;
    cout << min(one, two) << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll k, n;
    cin >> k >> n;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];

    ll ma = a[0] + k-a[n-1];
    FOR(i, 1, n) chmax(ma, a[i]-a[i-1]);
    cout << k-ma << endl;

    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

 public class Main{
    public static void main(String[] args){
Scanner sc = new Scanner(System.in);
      int n ;
      int m ;
      boolean boo = true;
      int cnt = 0;
while(boo){
  n = sc.nextInt();
  m = sc.nextInt();
  cnt =0;
  if(n==0 && m==0) break;

  for(int i = 1;i <= n; i++){
    for(int l =1; l <= n; l++){
      if(l == i) break;
      for(int q = 1;q <= n; q++ ){
        if(q ==i || q ==l)break;
        if(i + l + q == m) cnt++;
      }

    }

  }
  System.out.println(cnt);
}
    }//main


 }//class



Measured memory_bytes: 26776
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.function.BiFunction;

public class Main {
  Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {
    new Main().run();
  }

  void run() {
    char[] str = sc.next().toCharArray();
    int n = str.length;
    int g = 0;
    int p = 0;
    for (int i = 0; i < n; ++i) {
      if (str[i] == 'g') {
        ++g;
      } else {
        ++p;
      }
    }
    int v = n / 2 - p;
    System.out.println(v);
  }

  int ni() {
    return Integer.parseInt(sc.next());
  }

  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }

  class BIT<T> {
    int n;
    ArrayList<T> bit;
    BiFunction<T, T, T> bif;

    BIT(int n, BiFunction<T, T, T> bif, T defaultValue) {
      this.n = n;
      bit = new ArrayList<>(n + 1);
      for (int i = 0; i < n + 1; ++i) {
        bit.add(defaultValue);
      }
      this.bif = bif;
    }

    void update(int i, T v) {
      for (int x = i; x <= n; x += x & -x) {
        bit.set(x, bif.apply(bit.get(x), v));
      }
    }

    T reduce(int i, T defaultValue) {
      T ret = defaultValue;
      for (int x = i; x > 0; x -= x & -x) {
        ret = bif.apply(ret, bit.get(x));
      }
      return ret;
    }
  }

}

Measured memory_bytes: 13996
package main

import (
	"fmt"
)

func main() {

	var N, P int
	fmt.Scanf("%d", &N)

	var count int = 0
	var min int = 1000000
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &P)
		if min > P {
			count++
			min = P
		}
	}

	fmt.Println(count)
}


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

int main() {
  int n;
  cin >> n;
  for(int i = 1; i < 10; i++) for(int j = 1; j < 10; j++) {
    if(i*j == n) {
      cout << "Yes" << endl;
      exit(0);
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
using std::endl;
using std::cin;
using std::cout;
using std::vector;
using std::pair;
using std::string;
using std::map;

int main(void)
{
    uint32_t s;
    cin >> s;

    uint32_t idx = 1;

    std::map<uint32_t, bool> myMap;
    myMap.insert(std::make_pair(s, true)); 
    
    while(true)
    {
        idx++;
        
        if (s%2 == 0){
            s = s/2;
        } else {
            s = s*3+1;
        }
        if (myMap.count(s) > 0) {
            cout << idx << endl;
            return 0;
        }
        
        myMap.insert(std::make_pair(s, true));
    }
    
    return 0;
}



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

if N < 10:
    print(len(range(1, N+1)))
elif N < 100:
    print("9")
elif N < 1000:
    print(str(9 + len(range(100, N+1))))
elif N < 10000:
    print(str(9+900))
elif N < 100000:
    print(str(9+900+len(range(10000, N+1))))
else:
    print("90909")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n, a, b;
    std::cin >> n >> a >> b;
    std::vector<i64> v(n);
    std::unordered_map<i64, int> cnt;
    for (int i = 0; i < n; i++) {
        std::cin >> v[i];
        cnt[v[i]]++;
    }
    std::sort(v.begin(), v.end(), std::greater<>());

    std::vector<i64> w(n + 1), ss(n + 1);
    i64 mm = 0;
    for (int i = a; i <= b; i++) {
        i64 tmp = 0, tc = 0;
        for (int j = 0; j < i; j++) {
            tmp += v[j];
            if (j && v[j] != v[j - 1]) tc = 1;
            else tc++;
        }
        w[i] = tmp;
        ss[i] = 1;
        for (i64 j = 1; j <= tc; j++) {
            ss[i] = ss[i] * (cnt[v[i - 1]] - j + 1) / j;
        }
        if (!mm || (double)1.0 * tmp / i > (double)1.0 * w[mm] / mm) mm = i;
    }

    printf("%.10lf\n", (double)w[mm] / mm);
    i64 ret = 0;
    for (int i = a; i <= b; i++) {
        if (w[mm] * i == w[i] * mm) ret += ss[i];
    }
    std::cout << ret << std::endl;

    return 0;
}

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

int dp[17][17];

int main(){
	int a,b,n;
	while(cin>>a>>b,a,b){
		for(int i=0;i<17;i++){
			for(int j=0;j<17;j++){
				dp[i][j]=1;
				}
			}
		
		cin>>n;
		int c,d;
		for(int i=0;i<n;i++){
			cin>>c>>d;
			dp[c-1][d-1]=0;
			
			if(c==1){
				for(int ia=d-1;ia<b;ia++){
					dp[0][ia]=0;
					}
				}
				
			if(d==1){
				for(int ia=c-1;ia<a;ia++){
					dp[ia][0]=0;
					}
				}	
			}
			
		for(int i=1;i<a;i++){
			for(int j=1;j<b;j++){
				if(dp[i][j]!=0){dp[i][j]=dp[i-1][j]+dp[i][j-1];}
				}
			}
			
			cout<<dp[a-1][b-1]<<endl;	
		}
		return 0;
	}

Measured memory_bytes: 2984
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 ans=0;
		for(int i=0;i!=a+1;i++) {
			for(int j=0;j!=a+1;j++) {
				if(b-i-j>=0&&b-i-j<=a) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define x first
#define y second
using namespace std;
int n;
vector<pii> g[20];
int main(){
cin>>n;
for(int k=1;k<=n;k++){
    int m;
    cin>>m;
    for(int i=1;i<=m;i++){
        int x,y;
        cin>>x>>y;
        g[k].push_back({x,y});
    }
}
int N=1<<(n);
int ans=0;
for(int k=0;k<N;k++){
    bitset<20> b=k;
    int ind=0;
    for(int k=1;k<=n;k++){
            if(b[k-1])
       for(int i=0;i<g[k].size();i++){
        if(g[k][i].y!=b[g[k][i].x-1]){
            ind=1;
        break;
        }
       }
    }
    int h=b.count();
    if(ind==0)
        ans=max(ans,h);
}
cout<<ans;
return 0;
}


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


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int n,k;
    cin>>n>>k;
    int a[n];
    int ans=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int cnt=1;
    for(int i=1;i<n;i++){
        if(a[i]>a[i-1])cnt++;
        else {
            if(cnt>=k) ans++;
            cnt=1;
        }
    }
    if(cnt>=k) ans++;
    if(ans) ans--;
    queue<int> q;
    int mi=99999999,ma=0;
    set<int> st;
    for(int i=0;i<k;i++){
        st.insert(a[i]);
        mi = min(a[i],mi);
        ma = max(ma,a[i]);
    }
    for(int i=k;i<n;i++){
        // for(int j=0;j<i-k;j++) cout << a[j]<<" ";
        // for(auto j:st) cout << j << " ";
        // for(int j=i;j<n;j++) cout << a[j]<<" ";
        // cout << endl;

        int era=a[i-k];
        st.erase(a[i-k]);
        st.insert(a[i]);
        auto itr = st.end();
        itr--;
        ma = *itr;
        if(mi == era && ma==a[i])ans++;
        mi = *st.begin();
    }
    // for(int j=0;j<n-k;j++) cout << a[j]<<" ";
    // for(auto j:st) cout << j << " ";
    // //for(int j=i;j<n;j++) cout << a[j]<<" ";
    // cout << endl;
    
    ans = n-k-ans+1;
    cout << ans << endl;


}

Measured memory_bytes: 10368
import math

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

n = int(input())

if n == 2:
    print(1)
    exit()
"""elif n == 3:
    print(2)
    exit()
elif n==4:
    print(3)
    exit()
elif n==5:
    print(3)
    exit()
elif n==9:
    print(5)
    exit()
"""
a = prime_factorize(n-1)
b = [[a[0],1]]

for i in range(1,len(a)):
    if a[i]==b[-1][0]:
        b[-1][1]+=1
    else:
        b.append([a[i],1])

ans = 1
for i in range(len(b)):
    ans *= b[i][1]+1
ans-=1

g = []
for i in range(2,int(math.sqrt(n))+1):
    if n%i==0:
        x = n//i
        y = i
        x,y = min(x,y),max(x,y)
        if 1 in [x,y]:
            continue
        while y%x==0:
            y//=x
        if (y-1)%x==0:
            ans += 1
            g.append(i)

if n not in g:
    ans += 1
print(ans)


Measured memory_bytes: 40428
import sys
input = sys.stdin.readline
from collections import deque
h,w,k = map(int,input().split())
sx,sy,gx,gy = map(int,input().split())
grid = [input().rstrip() for i in range(h)]
dp = [[10**6 for i in range(w)] for j in range(h)]
dp[sx-1][sy-1] = 0
q = deque()
q.append((sx-1,sy-1))
while q:
  px,py = q.popleft()
  d = dp[px][py]
  for j in range(1,k+1):
    if px+j >= h or grid[px+j][py] == "@" or dp[px+j][py] <= d:
      break
    if dp[px+j][py] == 10**6:
      dp[px+j][py] = d+1
      q.append((px+j,py))
  for j in range(1,k+1):
    if px-j < 0 or grid[px-j][py] == "@" or dp[px-j][py] <= d:
      break
    if dp[px-j][py] == 10**6:
      dp[px-j][py] = d+1
      q.append((px-j,py))
  for j in range(1,k+1):
    if py+j >= w or grid[px][py+j] == "@" or dp[px][py+j] <= d:
      break 
    if dp[px][py+j] == 10**6:
      dp[px][py+j] = d+1
      q.append((px,py+j))
  for j in range(1,k+1):
    if py-j < 0 or grid[px][py-j] == "@" or dp[px][py-j] <= d:
      break
    if dp[px][py-j] == 10**6:
      dp[px][py-j] = d+1
      q.append((px,py-j))
if dp[gx-1][gy-1] == 10**6:
  print(-1)
else:
  print(dp[gx-1][gy-1])

Measured memory_bytes: 150224
/* ALDS1_9_A: CompleteBinaryTree */
/* 20181129 AOJ */

#define _CRT_SECURE_NO_WARNINGS
#define H 500000
#include <stdio.h>

void maxHeapify(int *heap, int i);
void buildMaxHeap(int *heap);
void swap(int *x, int * y);

int n;
int main(void) {
	int i;
	int heap[H] = {0};

	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		scanf("%d", heap + i);
	}

	buildMaxHeap(heap);

	for (i = 1; i <= n; i++) {
		printf(" %d", heap[i]);
	}

	printf("\n");

	return 0;
}

void maxHeapify(int *heap, int i) {
	int left, right, maxId;
	
	left = 2 * i;
	right = left + 1;
	if(left <= n && heap[left] > heap[i]) maxId = left;
	else maxId = i;

	if(right <= n && heap[right] > heap[maxId]) maxId = right;

	if(maxId != i) {
		swap(heap + i, heap + maxId);
		maxHeapify(heap, maxId);
	}
}

void buildMaxHeap(int *heap) {
	int id;
	for(id = n / 2; id > 0; id--) {
		maxHeapify(heap, id);
	}
}

void swap(int *x, int * y) {
	int temp = *x;
	*x = *y;
	*y = temp;
}


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

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
template<typename T> auto operator<<(ostream& os, const T& t)
    -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }

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

    int N;
    std::cin >> N;

    int index = (N % 2 == 1) ? 0 : 1;
    vector<pair<int, int>> ans;
    for(int i = N; i > 0; i--) {
        for(int j = 1; j <= i; j++) {
            if(j == i || j == index) continue;
            ans.emplace_back(i, j);
        }
        index++;
    }

    std::cout << ans.size() << std::endl;
    for_each(ALL(ans), [](auto& p) {std::cout << p.first << " " << p.second << std::endl;});

    return 0;
}


Measured memory_bytes: 384
n,k =map(int, input().split())
sunuke_l =[0 for i in range(n)]
l = [input() for _ in range(2*k)]
for i in range(k):
#  d = int(l[2*k])
  a = list(map(int, l[2*i +1].split()))
  for j in a:
    sunuke_l[j-1] = 1
print(n -sum(sunuke_l))

Measured memory_bytes: 9220
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        String[] s = new String[h];
        boolean[] row = new boolean[h];
        boolean[] col = new boolean[w];
        Arrays.fill(row, false);
        Arrays.fill(col, false);
        
        for(int i=0; i<h; i++){
            s[i] = sc.next();
            for(int j=0; j<w; j++){
                if(s[i].charAt(j) == '#'){
                    row[i] = true;
                    col[j] = true;
                }
            }
        }
        
        for(int i=0; i<h; i++){
            if(row[i]){
                for(int j=0; j<w; j++){
                    if(col[j]){
                        System.out.print(s[i].charAt(j));
                    }
                }
                System.out.println();
            }
        }
    }
}

Measured memory_bytes: 24020
#include <iostream>

using namespace std;

int main()
{
  int N, X;
  cin >> N >> X;

  int L = 0;
  int l = 0;
  int count = 1;

  for(int i = 0; i < N; i++)
  {
    cin >> L;
    if (l + L <= X)
    {
      count++;
      l += L;
    } else
    {
      break;
    }
  }

  cout << count << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;

int main() {
    int n, a[100] = {},ans=0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        int v = a[i];
        int j = i - 1;
        while (j >= 0 && a[j] < v) {
            a[j + 1] = a[j];
            j--;
        }
        a[j + 1] = v;
    }
    for (int i = 0; i < n; i++) {
       if (i % 2 == 0) ans += a[i];
       else ans -= a[i];
    }
    cout << ans << endl;
}
  


    

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int counter;
int gcd(int a, int b)
{       if (b == 0) return a;
       counter++;
       return gcd(b, a%b);
   }
   
int main(void){
   int a, b, x;
    while(cin>>a>>b){
        if(a < b){
            x = a;
            a = b;
            b = x;
        }
        if(a == 0 && b == 0)
    return 0;
        counter = 0;
        cout<<gcd(a,b)<<" ";
       cout<<counter<<endl;
    }
    return 0;
}


Measured memory_bytes: 3076
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

const int INF = 1e9 + 239;

struct Node {
	int len;
	int min_f;
	int min_s;
	pair<int, int> fans;
	pair<int, int> sans;


	Node() {
		len = 0;
		min_f = INF;
		min_s = INF;
		fans = {INF, INF};
		sans = {INF, INF};
			
	}

	Node(int x) {
		len = 1;
		min_f = x;
		min_s = INF;
		fans = {INF, INF};
		sans = {INF, INF};
	}

	Node(int len_, int min_f_, int min_s_, pair<int, int> fans_, pair<int, int> sans_) {
		len = len_;
		min_f = min_f_;
		min_s = min_s_;
		fans = fans_;
		sans = sans_;
	}

	friend Node conq(const Node &a, const Node &b) {
		if (a.len & 1) {
			pair<int, int> nfans = {a.min_f, b.min_f};
			pair<int, int> nsans = {a.min_s, b.min_s};
			return Node(a.len + b.len, min(a.min_f, b.min_s), min(a.min_s, b.min_f), min({a.fans, b.sans, nfans}), min({a.sans, b.fans, nsans}));
		} else {
			pair<int, int> nfans = {a.min_f, b.min_s};
			pair<int, int> nsans = {a.min_s, b.min_f};
			return Node(a.len + b.len, min(a.min_f, b.min_f), min(a.min_s, b.min_s), min({a.fans, b.fans, nfans}), min({a.sans, b.sans, nsans}));
		}
	}
};

namespace SegmentTree {
	int n;
	vector<int> a;
	vector<Node> t;

	void pull(int v) {
		t[v] = conq(t[2 * v + 1], t[2 * v + 2]);
	}

	void build(int v, int l, int r) {
		if (l + 1 == r) {
			t[v] = Node(a[l]);
		} else {
			int m = (r + l) >> 1;
			build(2 * v + 1, l, m);
			build(2 * v + 2, m, r);
			pull(v);
		}
	}

	void query(int v, int l, int r, int ql, int qr, Node &ans) {
		if (r <= ql || qr <= l) {
			return;
		} else if (ql <= l && r <= qr) {
			ans = conq(ans, t[v]);
		} else {
			int m = (r + l) >> 1;
			query(2 * v + 1, l, m, ql, qr, ans);
			query(2 * v + 2, m, r, ql, qr, ans);
		}
	}

	void init(vector<int> &a_) {
		a = a_;
		n = (int)a.size();
		t.resize(4 * n);
		build(0, 0, n);
	} 

	pair<int, int> solve(int l, int r) {
		Node ans;
		query(0, 0, n, l, r, ans);
		return ans.fans;
	}
}

typedef pair<pair<int, int>, pair<int, int>> st;
priority_queue<st, vector<st>, greater<st>> pq;
	
void add(int l, int r) {
	if (l < r) {
		pq.push(make_pair(SegmentTree::solve(l, r), make_pair(l, r)));
	}
}

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

	int n;
	cin >> n;
	vector<int> a(n);
	for (auto &t : a) {
		cin >> t;
		t--;
	}
	vector<int> wr(n);
	for (int i = 0; i < n; i++) {
		wr[a[i]] = i;
	}
	SegmentTree::init(a);
	add(0, n);
	vector<int> to(n);
	for (int i = 0; i < n; i += 2) {
		auto cur = pq.top();
		pq.pop();
		tie(to[i], to[i + 1]) = cur.first;
		int l, r;
		tie(l, r) = cur.second;
		int ml = wr[to[i]];
		int mr = wr[to[i + 1]];
		add(l, ml);
		add(ml + 1, mr);
		add(mr + 1, r);
	}
	for (int i = 0; i < n; i++) {
		cout << to[i] + 1 << ' ';
	}
	cout << endl;
}


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

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

using namespace std;

int main(){
    int N;
    cin>>N;
    int L[N+10];
    REP(i,N){
        cin>>L[i];
    }
    sort(L,L+N);
    int tmp=0;
    REP(i,N-1) {
        tmp += L[i];
    }
    if(L[N-1]<tmp){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int i,wrong=0;

  int n;
  scanf("%d\n",&n);

  int p;
  for(i=1;i<=n;i++){
    scanf("%d",&p);
    if(p!=i){
      wrong++;
    }
  }

  if(wrong==0||wrong==2){
    printf("YES\n");
  }else{
    printf("NO\n");
  }

  return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 998244353
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 500


int main() {
	long long a[N];
	long long dp[100000];
	f(i, 100000)dp[i] = 0;
	f(i, N)a[i] = 0;
	int n, k;
	long long x, y, z;
	long long s,ans;
	bool v = true;
	s = 0;
	ans = 0;
	scanf("%d", &n);
	f(i, n) {
		scanf("%lld", &a[i]);
		s += a[i];
	}
  if(s%2==0){
  	dp[0] = 1;
	f(i, n) {
		for(int j=s;j>=0;j--) {
          			dp[j + a[i]] += dp[j];
			dp[j + a[i]] = dp[j + a[i]] % MOD;
		}
	}
  z=dp[(s/2)];
  z*=3;
  z=z%MOD;
  }
  else z=0;
  f(i,s+1)dp[i]=0;
	dp[0] = 1;
	f(i, n) {
		for(int j=s;j>=0;j--) {
          			dp[j + a[i]] += dp[j];
			dp[j + a[i]] = dp[j + a[i]] % MOD;
			dp[j] = dp[j] * 2;
			dp[j] = dp[j] % MOD;
		}
	}
	f(i, s + 1) {
		if ((2 * i) < s) {
			ans += dp[i];
			ans = ans % MOD;
		}
		else break;
	}
	s = 1;
	f(i, n)s = (s * 3) % MOD;
	ans = (ans * 3) - (s * 2);
  ans+=z;
  while(ans<0)ans+=MOD;
  ans=ans%MOD;
	printf("%lld\n", ans);


	return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    ll N,M;
    cin >> N;
    ll i,j;
    string A[N];
    for(i=0;i<N;i++){
      cin >> A[i];
    }
    cin >>M;
    string B[M];
    for(i=0;i<M;i++){
      cin >> B[i];
    }
    ll ans=0;
    ll tmp;
    for(i=0;i<N;i++){
      tmp=0;
      for(j=0;j<N;j++){
        if(A[i]==A[j])tmp++;
      }
      for(j=0;j<M;j++){
        if(A[i]==B[j])tmp--;
      }
      ans=max(tmp,ans);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
from collections import*
from bisect import*
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ca=Counter(a)
cb=Counter(b)
for i in a:
  if ca[i]+cb[i]>n:
    print('No')
    exit()
print('Yes')
ba=[bisect(a,i+1) for i in range(n)]
bb=[bisect_left(b,i+1) for i in range(n)]
i=0
for x,y in zip(ba,bb):
  i=max(i,x-y)
ans=b[n-i:]+b[:n-i]
print(*ans)

Measured memory_bytes: 153516
// デバッグ実行：Ctrl+F5

using System;

class Program
{
    static void Main(string[] args)
    {
        String line;
        line = Console.ReadLine();
        String[] words = line.Split(' ');

        int N = int.Parse(line);
        if (N == 3 || N == 5 || N == 7)
        {
            Console.WriteLine("YES");
        }
        else
        {
            Console.WriteLine("NO");
        }
    }
}

Measured memory_bytes: 13140