akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e6;
int main() {
  int h, w;
  while (cin >> w) {
    cin >> h;
    if (h == 0 && w == 0) return 0;
    vector<vector<bool>> A(h * 2 - 1);
    REP(i, w - 1) {
      bool t;
      cin >> t;
      A[0].push_back(t);
    }
    REP(i, h - 1) {
      bool t;
      int id = i * 2 + 1;
      REP(i, w) {
        cin >> t;
        A[id].push_back(t);
      }
      REP(i, w - 1) {
        cin >> t;
        A[id + 1].push_back(t);
      }
    }
    vector<vector<int>> dis(h, vector<int>(w, -INF));
    queue<P> que;
    que.push(P(0, 0));
    dis[0][0] = 1;
    while (!que.empty()) {
      P p = que.front();
      que.pop();
      int x = p.second, y = p.first;
      if (0 < x) {
        int nx = x - 1, ny = y;
        if (A[y * 2][x - 1] == 0) {
          if (dis[ny][nx] == -INF) {
            dis[ny][nx] = dis[y][x] + 1;
            que.push(P(ny, nx));
          }
        }
      }
      if (x < w - 1) {
        int nx = x + 1, ny = y;
        if (A[y * 2][x] == 0) {
          if (dis[ny][nx] == -INF) {
            dis[ny][nx] = dis[y][x] + 1;
            que.push(P(ny, nx));
          }
        }
      }
      if (0 < y) {
        int nx = x, ny = y - 1;
        if (A[y * 2 - 1][x] == 0) {
          if (dis[ny][nx] == -INF) {
            dis[ny][nx] = dis[y][x] + 1;
            que.push(P(ny, nx));
          }
        }
      }
      if (y < h - 1) {
        int nx = x, ny = y + 1;
        if (A[y * 2 + 1][x] == 0) {
          if (dis[ny][nx] == -INF) {
            dis[ny][nx] = dis[y][x] + 1;
            que.push(P(ny, nx));
          }
        }
      }
    }
    if (dis[h - 1][w - 1] == -INF) {
      cout << 0 << endl;
    } else {
      cout << dis[h - 1][w - 1] << endl;
    }
  }
}


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

int main()
{
  int n;
  long long C,K;
  scanf("%d%lld%lld",&n,&C,&K);
  static long long T[100000];
  for(int i=0;i<n;i++){
    scanf("%lld",T+i);
  }
  sort(T,T+n);
  int ans=1,m=1;
  long long x=0;
  for(int i=1;i<n;i++){
    if(m==C||T[i]>T[x]+K){
      ans++;
      m=1;
      x=i;
    }
    else{
      m++;
    }
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
  
#define lol long long
#define gcd(x,y) __gcd(x,y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed fixed<<setprecision(14)
using namespace std;
using pii=pair<int,int>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A> inline lol abs(A &a) { return (a < 0 ? -a : a); }
template <class A, class B> inline A max(A a, B b){return(a>b?a:b);}
template <class A, class B> inline A min(A a, B b){return(a<b?a:b);}
const lol inf=(1LL<<60);
const lol MOD=(1e9)+7;
const lol mod=998244353;
const int dx[]={1,0,-1,0,1,1,-1,-1};
const int dy[]={0,1,0,-1,1,-1,1,-1};
lol n,m,k,r;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s,t;
  cin >>s>>t;
  bool yes=false;
  for(int i=0;i<26;i++){
    string tmp=s+(char)('a'+i);
    if(tmp==t) yes=true;
  }
  if(yes) cout <<"Yes\n";
  else cout <<"No\n";
  return (0);
}

Measured memory_bytes: 3636
#include <stdio.h>

int main(void){

  int N;
  scanf("%d",&N);
  int i;
  double A[N];
  double count=0;
  for(i=0;i<N;i++){
    scanf("%lf",&A[i]);
    count+=1/A[i];
  }
  double ans;
  printf("%f",1/count);
  

  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;
 
 
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,x,ans[299919];
    cin>>n>>x;
    if(x==1 ||x==2*n-1){
        cout<<"No"<<endl;
        return 0;
    }
    if(x==2*n-2){
        ans[n-2]=2*n-3;
        ans[n-1]=2*n-2;
        ans[n]=2*n-1;
        ans[n+1]=2*n-4;
        ll now=1;
        rep(i,n-2){
            ans[i]=now;
            now++;
        }
        rep2(i,n+2,2*n-1){
            ans[i]=now;
            now++;
        }
    } else{
        ans[n-2]=x+2;
        ans[n-1]=x-1;
        ans[n]=x;
        ans[n+1]=x+1;
        ll now=1;
        rep(i,n-2){
            if(now>=x-1 && now<=x+2)  now=x+3;
            ans[i]=now;
            now++;
        }
        rep2(i,n+2,2*n-1){
            if(now>=x-1 && now<=x+2)  now=x+3;
            ans[i]=now;
            now++;
        }
    }
    cout<<"Yes"<<endl;
    rep(i,2*n-1) cout<<ans[i]<<endl;
    return 0;
}


Measured memory_bytes: 3072
package main

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

var sc = NewScanner(os.Stdin)

func main() {
	n := sc.ScanInt()

	red := make(map[int]int)
	for i := 0; i < n; i++ {
		red[sc.ScanInt()] = sc.ScanInt()
	}

	blue := make(TupleArray, n)
	for i := range blue {
		blue[i] = []int{sc.ScanInt(), sc.ScanInt()}
	}
	sort.Sort(blue)

	ans := 0

	for _, t := range blue {
		x, maxY := -1, -1
		for a, b := range red {
			if a < t[0] && b < t[1] && b > maxY {
				x, maxY = a, b
			}
		}
		if maxY != -1 {
			ans++
			delete(red, x)
		}
	}

	fmt.Println(ans)
}

type TupleArray [][]int

func (a TupleArray) Len() int {
	return len(a)
}

func (a TupleArray) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func (a TupleArray) Less(i, j int) bool {
	return a[i][0] < a[j][0]
}

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner(r io.Reader) *Scanner {
	s := &Scanner{bufio.NewScanner(r)}
	s.sc.Split(bufio.ScanWords)
	return s
}

func (s *Scanner) ScanInt() int {
	s.sc.Scan()
	i, e := strconv.Atoi(s.sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 640
def dfs(v, cnt):
  D[v] = cnt
  cnt += 1
  for c in edge[v]:
    if D[c] == -1:
      cnt = dfs(c, cnt)
  F[v] = cnt
  cnt += 1
  return cnt

N = int(input())
edge = [[] for _ in range(N)]
for _ in range(N):
  u, _, *v = map(lambda x:int(x)-1, input().split())
  edge[u] = sorted(v)
D, F = [-1] * N, [-1] * N
c = 1
for i in range(N):
  if D[i] == -1:
    c = dfs(i, c)
for i, (d, f) in enumerate(zip(D, F)):
  print(i + 1, d, f)



Measured memory_bytes: 5660
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n ;
  cin >> n ;
  int max =0;
  int ans = 1;
  for(int i=1;i<=n;++i){
   int count = 0 ;
   int target = i ;
    while(target%2==0){
      target/=2;
      count++ ;
    }
   if(max<count){
     max = count ;  
     ans = i;
   }
  }
  cout << ans << "\n" ;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MAX=200000;
int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    vector<int> memo(MAX,0);
    for(int i=0;i<n;i++){
        if(a[i]-1>=0) memo[a[i]-1]++;
        memo[a[i]]++;
        memo[a[i]+1]++;
    }
    sort(memo.begin(),memo.end());
    cout<<memo.back()<<endl;
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>

using namespace std;

const int INF = 1e5 + 9;

bool valid(const vector<int> &v) {
	int cnt = 0, table[109];
	for (int i = 0; i < 109; i++) {
		table[i] = 0;
	}
	for (auto ch : v) {
		if (ch == INF) continue;
		table[ch]++;
		cnt++;
	}
	if (cnt == 1 && table[0] == 1) return true;
	if (cnt == 2 && table[1] == 2) return true;
	return false;
} 

void print_vec(const vector<int> &v) {
	for (auto vi : v) {
		cout << vi << ' ';
	}
	cout << '\n';
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	
	int n, len = 0;
	cin >> n;
	vector<int> v;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (a >= n) {
			cout << "Impossible\n";
			return 0;
		}
		len = max(len, a);
		v.push_back(a);
	}
	int size = n;
	while (size >= 0 && len >= 0) {
		if (valid(v)) {
			cout << "Possible\n";
			return 0;
		}
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			if (v[i] == INF) continue; 
			if (v[i] == len) {
				v[i] = INF;
				size--;
				cnt++;
			} else {
				v[i]--;
			}
		}
		len -= 2;
		if (!cnt) {
			cout << "Impossible\n";
			return 0;
		}
//		print_vec(v);
	}
	cout << "Impossible\n";
	
	return 0;
}


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

int main(){
    int n;
    ll k, q;
    cin >> n >> k >> q;
    vector<int> cnt(n+1, 0);

    rep(i,q){
        int tmp;
        cin >> tmp;
        cnt[tmp]++;
    }

    rep(i,n){
        if(k - q + (ll)cnt[i+1] > 0) cout << "Yes\n";
        else cout << "No\n";
    }


}



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

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

const int MAXN = 1e5;

int N, H[MAXN+10], dp[MAXN+10];

int main()
{
    int i, j;

    scanf("%d", &N);
    for(i=1; i<=N; i++) scanf("%d", &H[i]);

    dp[2]=abs(H[1]-H[2]);
    for(i=3; i<=N; i++) dp[i]=min(dp[i-1]+abs(H[i]-H[i-1]), dp[i-2]+abs(H[i]-H[i-2]));
    printf("%d", dp[N]);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;
 
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;
 
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;
 
#define _  %  MOD
#define __ %= MOD
 
#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))
 
#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
#define fbo find_by_order
#define ook order_of_key
 
ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;} // modular exponent
 
int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
    
	ll s;cin>>s;
	ll dp[s+1];
	for(ll i=1;i<=s;i++) dp[i]=1;
	dp[0]=0;dp[1]=0;dp[2]=0;dp[3]=1;
	for(ll i=4;i<=s;i++)
	{
		ll ans=1ll;
		for(ll j=3;j<=i-3;j++)
		{
			ans+=dp[j];ans%=INF;
		}
		dp[i]=ans;
	}
	cout<<dp[s]<<'\n';
	return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!



Measured memory_bytes: 3656
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
from numba import njit


def EulerTour(graph, root=1):
    N = len(graph) - 1
    parent = [0] * (N + 1)
    stack = [-root, root]
    tour = []
    ind_L = [0] * (N + 1)
    ind_R = [0] * (N + 1)
    i = -1
    while stack:
        v = stack.pop()
        tour.append(v)
        i += 1
        if v > 0:
            ind_L[v] = i
            p = parent[v]
            for w in graph[v]:
                if w == p:
                    continue
                parent[w] = v
                stack.append(-w)
                stack.append(w)
        else:
            ind_R[-v] = i
    return tour, ind_L, ind_R, parent


N = int(readline())
graph = [[] for _ in range(N + 1)]
C = np.zeros(N + 1, np.int64)
C[1:] = np.array(readline().split(), np.int64)
m = map(int, read().split())
for a, b in zip(m, m):
    graph[a].append(b)
    graph[b].append(a)

tour, ind_L, ind_R, parent = map(lambda x: np.array(x, np.int64), EulerTour(graph))


@njit(cache=True)
def main(C, tour, ind_L, ind_R, parent):
    removed = np.zeros(N + 1, np.int64)
    answer = np.full_like(removed, N * (N + 1) // 2)
    memo = np.zeros_like(answer)
    for v in tour:
        if v > 0:
            memo[v] = removed[C[parent[v]]]
        else:
            v = -v
            removed[C[v]] += 1
            p = parent[v]
            x = (ind_R[v] - ind_L[v]) // 2 + 1  # subtree size
            x -= removed[C[p]] - memo[v]
            answer[C[p]] -= x * (x + 1) // 2
            removed[C[p]] += x
    for i, x in enumerate(removed):
        x = N - x
        answer[i] -= x * (x + 1) // 2
    return answer


answer = main(C, tour, ind_L, ind_R, parent)
print('\n'.join(answer[1:].astype(str)))


Measured memory_bytes: 198496
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <vector>
#include <queue>
#include <unordered_map> 
#include <iomanip>
#include <random>
#include <future>
#include <thread>
#include <utility>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF (INT_MAX/3)
#define INF_L (LLONG_MAX/3)
#define PSB push_back
#define PN 1000000007
typedef long long LL;
#define int long long


// booooooooooooost
// #include <boost/multiprecision/cpp_int.hpp>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// namespace mp = boost::multiprecision;	//多倍長整数(mp::cpp_int), 多倍長小数(mp::cpp_dec_float_100)


signed main() {

	int N, M;
	vector<vector<int>> graph;
	cin >> N >> M;
	graph.resize(N + 1);
	for (int i = 0; i < M; ++i) {
		int na, nb;
		cin >> na >> nb;
		if (na < nb) {
			graph[na].push_back(nb);
		}
		else {
			graph[nb].push_back(na);
		}
	}

	bool ans = false;
	for (int i = 0; i < N + 1; ++i) {
		sort(graph[i].begin(), graph[i].end());
	}
	for (auto p : graph[1]) {
		if (!graph[p].empty() && graph[p].back() == N) {
			ans = true;
		}
	}
	cout << (ans ? "POSSIBLE" : "IMPOSSIBLE") << endl;



	return 0;
}

Measured memory_bytes: 8960
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
static const int MAX_H = 400;
static const int MAX_W = 400;

int H, W;
char S[MAX_H][MAX_W + 1];
P num[MAX_H * MAX_W];
int dy[] = {0, -1, 0, 1};
int dx[] = {1, 0, -1, 0};

int par[MAX_H * MAX_W];
int rnk[MAX_H * MAX_W];
 
void init(int N){
	for(int i = 0; i < N; i++){
		par[i] = i;
		rnk[i] = 0;
	}
}
int find(int x){
	if(par[x] == x){
		return x;
	}else{
		return par[x] = find(par[x]);
	}
}
void unite(int x, int y){
	x = find(x);
	y = find(y);
	if(x == y) return;
	if(rnk[x] < rnk[y]){
		par[x] = y;
	}else{
		par[y] = x;
		if(rnk[x] == rnk[y]) rnk[x]++;
	}
}
bool same(int x, int y){
	return find(x) == find(y);
}

int main(){
	scanf("%d %d", &H, &W);
	for(int i = 0; i < H; i++) scanf("%s", S[i]);
	init(H * W);
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			for(int k = 0; k < 4; k++){
				int ny = i + dy[k], nx = j + dx[k];
				if(ny < 0 || nx < 0 || ny >= H || nx >= W) continue;
				if(S[ny][nx] == S[i][j]) continue;
				unite(i * W + j, ny * W + nx);
			}
		}
	}
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(S[i][j] == '.') num[find(i * W + j)].first++;
			else num[find(i * W + j)].second++;
		}
	}
	ll res = 0LL;
	for(int i = 0; i < H * W; i++) res += num[i].first * num[i].second;
	printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int a, b; 
    char op;
    cin >> a >> op >> b;
    if(op=='+') cout << a+b << endl;
    else cout << a - b << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct _node {
  int right, left, parent;
  int depth, height;
} node;

node tree[25];

void setDepth(int id, int d) {
  tree[id].depth = d;
  if(tree[id].right != -1)
    setDepth(tree[id].right, d + 1);
  if(tree[id].left != -1)
    setDepth(tree[id].left, d + 1);

  return;
}

int setHeight(int id) {
  if(tree[id].right == -1 && tree[id].left == -1) {
    tree[id].height = 0;
    return 0;
  }

  int rightHeight, leftHeight, height;
  rightHeight = leftHeight = height = 0;

  if(tree[id].right != -1)
    rightHeight = setHeight(tree[id].right);
  if(tree[id].left != -1)
    leftHeight = setHeight(tree[id].left);

  height =  rightHeight > leftHeight ? rightHeight : leftHeight;
  tree[id].height = height + 1;
  return tree[id].height;
}

int main() {
  int i, n, id, left, right, root, sibling, degree;
  char type[20] = "";

  scanf("%d", &n);
  for(i = 0;i < n;i++) {
    tree[i].depth = -1;
    tree[i].height = -1;
    tree[i].parent = -1;
    tree[i].right = -1;
    tree[i].left = -1;
  }

  for(i = 0;i < n;i++) {
    scanf("%d %d %d", &id, &left, &right);
    tree[id].left = left;
    tree[id].right = right;
    if(left != -1)
      tree[left].parent = id;
    if(right != -1)
      tree[right].parent = id;
  }

  for(i = 0;i < n;i++)
    if(tree[i].parent == -1)
      root = i;

  setDepth(root, 0);
  setHeight(root);

  for(i = 0;i < n;i++) {
    sibling = -1;
    if(tree[i].parent != -1) {
      if(tree[tree[i].parent].right == i)
        sibling = tree[tree[i].parent].left;
      if(tree[tree[i].parent].left == i)
        sibling = tree[tree[i].parent].right;
    }

    degree = 0;
    if(tree[i].right != -1)
      degree++;
    if(tree[i].left != -1)
      degree++;

    if(tree[i].parent == -1)
      strcpy(type, "root");
    else if(tree[i].right != -1 || tree[i].left != -1)
      strcpy(type, "internal node");
    else if(tree[i].right == -1 && tree[i].left == -1)
      strcpy(type, "leaf");

    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n", i, tree[i].parent, sibling, degree, tree[i].depth, tree[i].height, type);
  }

  return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
#define re register
#define int long long
using namespace std;
inline int read(){
	re int t=0;re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
	return t;
}
int n,m,ans;
signed main(){
	n=read();m=100;
	while(m<n)++ans,m=1.01*m;
	printf("%lld",ans);
}


Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void) {
    int n;
    cin >> n;
    vector<int> odd, even;
    for(int i=0; i<n; i++) {
        int a;
        cin >> a;
        if(i%2) {
            odd.push_back(a);
        } else {
            even.push_back(a);
        }
    }


    if(n%2) {
        reverse(even.begin(), even.end());
        for(auto e: even) {
            cout << e << " ";
        }
        for(auto e: odd) {
            cout << e << " ";
        }
    } else {
        reverse(odd.begin(), odd.end());
        for(auto e: odd) {
            cout << e << " ";
        }
        for(auto e: even) {
            cout << e << " ";
        }
    }
    return 0;
}


Measured memory_bytes: 3188
N,M,Q = map(int,input().split())
ans = 0
C = [list(map(int,input().split())) for i in range(Q)]

from itertools import combinations_with_replacement
AA = combinations_with_replacement(list(range(1,M+1)),N)
ans = 0
for A in AA:
    now = 0
    for q in range(Q):
        a,b,c,d = C[q]
        if A[b-1]-A[a-1]==c:
            now += d
    ans = max(ans,now)
print(ans)


Measured memory_bytes: 68200
import sys
from collections import Counter
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    n = readint()
    v = list(readnums())
    ve = [x for i, x in enumerate(v) if not i % 2]
    vo = [x for i, x in enumerate(v) if i % 2]
    cve = Counter(ve)
    cvo = Counter(vo)
    if cve.most_common()[0][0] == cvo.most_common()[0][0]:
        if len(cve) == 1:
            print(n // 2)
        else:
            print(min(len(ve) - cve.most_common()[1][1] + len(vo) - cvo.most_common()[0][1], len(ve) - cve.most_common()[0][1] + len(vo) - cvo.most_common()[1][1]))
    else:
        print(len(ve) - cve.most_common()[0][1] + len(vo) - cvo.most_common()[0][1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 19096
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,a,b) for(i64 i=(int64_t)(a);i<(int64_t)(b);i++)
#define repn(i,n) rep(i,0,n)

vector<vector<i64>> dp;


int main()
{
	int h, w, k;
	cin >> h >> w >> k;

	int h0[] = { 1,1,2,3,5,8,13,21,34 };
	constexpr auto DIF = 1000000007;
	dp = vector<vector<i64>>(h, vector<i64>(w, 0));

	dp[0][0] = h0[w - 1];
	dp[0][1] = h0[w - 2];

	rep(i, 1, h)
	{
		repn(j, w)
		{
			dp[i][j] = (j > 0 ? dp[i - 1][j - 1] * h0[j - 1] * h0[w - j - 1] : 0) % DIF
				+ (dp[i - 1][j] * h0[j] * h0[w - j - 1]) % DIF
				+ (j < w - 1 ? dp[i - 1][j + 1] * h0[j] * h0[w - j - 2] : 0) % DIF;
		}
	}
	cout << dp[h-1][k-1] % DIF << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n,a=0,b=0,aa,bb;
  cin>>n;
  while(n!=0){
    for(int i=0;i<n;i++){
    cin>>aa>>bb;
    if(aa<bb){
      b+=aa+bb;
    }else if(aa>bb){
      a+=aa+bb;
    }else if(aa==bb){
      a+=aa;
      b+=bb;
    }
  }
    cout<<a<<" "<<b<<endl;
    cin>>n;
    a=0;
    b=0;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

int main()
{
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int n,k;
        cin>>n>>k;
        cout<<n-k+1<<"\n";
        return 0;
}
/**

**/


Measured memory_bytes: 256
n=gets.to_i
m=0
a=0
r=0
c=0
h=0
n.times{
  s=gets
  case s[0]
  when 'M' then
    m+=1
  when 'A' then
    a+=1
  when 'R' then
    r+=1
  when 'C' then
    c+=1
  when 'H' then
    h+=1
  else
  end
}
p=[m,a,r,c,h]
ans=0
p.permutation(3).each{|l|
  q=l[0]
  w=l[1]
  e=l[2]
  ans+=q*w*e
}
p ans/6

Measured memory_bytes: 1788
from collections import deque

def main():
  N=int(input())
  for n in range(N):
    x=ans.popleft()
    if x%10!=0:
      ans.append(10*x+(x%10)-1) # x equal y-1
    ans.append(10*x+(x%10)) # x equal y
    if x%10!=9:
      ans.append(10*x+(x%10)+1) # x equal y+1
  print(x)
  
if __name__=='__main__':
  ans=deque([1,2,3,4,5,6,7,8,9])
  main()


Measured memory_bytes: 18764
n=int(input())
s=input()
i=0
j=n-1
c=0
while True:
  while j>=0 and s[j]!="R":
    j-=1
  while i<n and s[i]!="W":
    i+=1
  if i>j:
    break
  c+=1
  j-=1
  i+=1
print(c)

Measured memory_bytes: 9476
#include <cstdio>
#include <cstring>

void swap(char *, char *);

int main(void){
	int n,l;
	scanf("%d%d",&n,&l);
	char s[100][101];
	for(int i = 0; i < n; i++){
        scanf("%s", s[i]);
    }
	for(int i = 0; i < n; i++){
		for(int j = 0; j < i; j++){
			if(strcmp(s[i], s[j]) < 0){
                swap(s[i],s[j]);
            }
		}
	}
	
	for(int i = 0; i < n; i++){
        printf("%s",s[i]);
    }
    printf("\n");

	return 0;
}

void swap(char *a, char *b){
	char c[101];
	strcpy(c, a);
	strcpy(a, b);
	strcpy(b, c);
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	char a[26],s[101];
	int i;
	for (i = 0;i < 26;i++) a[i] = 0;
	bool flag = true;
	std::cin >> s;
	i = 0;
	while (s[i] != '\0')
	{
		a[s[i] - 'a']++;
		i++;
	}
	for (i = 0;i < 26;i++)
	{
		if (a[i] % 2 == 1) flag = false;
	}
	if (flag == true) std::cout << "Yes" << std::endl;
	else std::cout << "No" << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int m,na,nb,p[200];
	while(1){
		scanf("%d %d %d",&m,&na,&nb);
		if(!m) break;
		for(int i=0;i<m;i++)
			scanf("%d",&p[i]);
		int max=0;
		int ans;
		for(int i=na;i<=nb;i++){
			if(max<=p[i-1]-p[i]){
				max=p[i-1]-p[i];
				ans=i;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

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

int main() {
    int n, m;
    int k;
    cin >> n >> m >> k;
    ll a[n+1], b[m+1];
    a[0] = 0;
    b[0] = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        a[i] += a[i - 1];
    }
    for (int i = 1; i <= m; i++) {
        cin >> b[i];
        b[i] += b[i - 1];
    }

    int best = m;
    int ans = 0;
    for (int i = 0; i <= n; i++) {
        for (int j = best; j >= 0; j--) {
            if (b[j] <= k - a[i]) {
                best = j;
                ans = max(ans, i + j);
                break;
            }
        }
    }

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

Measured memory_bytes: 6640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <functional>
#include <array>

using namespace std;

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

    vector<int64_t> A(N);
    for(auto& a : A) cin >> a;
    for(int i = 1; i < N; ++i){
        A[i] += A[i-1];
    }
    int64_t ans = 0;
    map<int64_t, int64_t> m;
    m[0] = 1;
    for(int i = 0; i < N; ++i){
        ans += m[A[i]];
        m[A[i]]++;
    }
    cout << ans << endl;
}

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

using namespace std;

int main(){
   ios::sync_with_stdio(0);
   cin.tie(0);
   int n,w;
   cin>>n>>w;
   long long int W[110], P[110];
   long long int dp[100005]={0};
   for(int i=0; i<n; i++)
   {
       cin>>W[i]>>P[i];
   }
   
   for(int i=0; i<n; i++) {
    for(int j=w; j>=0; j--) {
        if(j - W[i] >= 0) {
            dp[j] = max(dp[j], dp[j-W[i]] + P[i]);
        }
    }
}  long long int sum=0;
   for(int i=0; i<=w; i++)
   {
       sum=max(sum,dp[i]);
   }
   cout<<sum<<endl;
 return 0;
}


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

typedef long long ll;
const int MAX = 3005;
ll dp[MAX][MAX][2];

ll solv(int s,int e,bool player,vector<ll>&a){
    if(s == e){
        if(player)
            return a[s];
        return -a[s];
    }
    if(dp[s][e][player] != INT64_MIN){
        return dp[s][e][player];
    }    
    if(player){
        ll ans = max(a[s] + solv(s + 1,e,!player,a),a[e] + solv(s,e - 1,!player,a));
        dp[s][e][player] = ans;
        return ans;
    }
    ll ans = min(solv(s + 1,e,!player,a) - a[s],solv(s,e - 1,!player,a) - a[e]);
    dp[s][e][player] = ans;
    return ans;
}

int main(void){
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            for(int k = 0; k < 2; k++){
                dp[i][j][k] = INT64_MIN;
            }
        }
    }
    cout << solv(0,n - 1,1,a) << endl;   
}

Measured memory_bytes: 141440
#include<bits/stdc++.h>
#define For(i,m,n) for(int i=m;i<n;i++)
#define FOR(i,n) for(int i=0;i<n;i++)
#define ll long long
#define ull unsigned long long
#define lli long long int
#define pb push_back
#define all(x) x.begin(),x.end()
ll mob=1000000007;
using namespace std;
int main()
{ 
ll x;
cin>>x;
for(int i=-500;i<=500;i++)
{
    for(int j=-500;j<=500;j++)
    {
        ll o=pow(i,5)-pow(j,5);
        if(o==x) {
            cout<<i<<" "<<j;
            goto end;
        }
    }
}
end:;
return 0;
}











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

// Bit Matrix
const int MAX_ROW = 210; // to be set appropriately
const int MAX_COL = 110; // to be set appropriately
struct BitMatrix {
    int H, W;
    bitset<MAX_COL> val[MAX_ROW];
    BitMatrix(int m = 1, int n = 1) : H(m), W(n) {}
    inline bitset<MAX_COL>& operator [] (int i) {return val[i];}
};

int GaussJordan(BitMatrix &A, bool is_extended = false) {
    int rank = 0;
    for (int col = 0; col < A.W; ++col) {
        if (is_extended && col == A.W - 1) break;
        int pivot = -1;
        for (int row = rank; row < A.H; ++row) {
            if (A[row][col]) {
                pivot = row;
                break;
            }
        }
        if (pivot == -1) continue;
        swap(A[pivot], A[rank]);
        for (int row = 0; row < A.H; ++row) {
            if (row != rank && A[row][col]) A[row] ^= A[rank];
        }
        ++rank;
    }
    return rank;
}


const int MD = 65;

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

  int t;
  cin >> t;

  rep(ti,t){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    string s;
    cin >> s;
    BitMatrix A(n+1,MD+1);//1
    BitMatrix B(n+1,MD+1);//0
    rep(i,s.size()){
      rep(j,MD){
        A[i][j] = 0;
        B[i][j] = 0;
      }
    }
    int ans = 0;
    for(int i = s.size()-1;i>=0;i--){
      if(s[i]=='1'){
        ll cv = 0;
        rep(j,63){
          if((1LL<<j)&a[i]){
            if(((1LL<<j)&cv) == 0){
              rep(l,n){ // bs 可能?
                if(B[l][j]){
                  rep(k,63) {
                    if(B[l][k]){
                      cv ^= (1LL<<k);
                    }
                  }
                  break;
                }
                else if(l==n-1){
                  ans = 1;
                }
              }
            }
            cv ^= (1LL<<j);
          }
        }
        if(cv!=0) ans = 1;
      }
      else{
        rep(j,63){
          if(a[i] & (1LL<<j)) B[n][j] = 1;
        }
        GaussJordan(B, true);
      }
    }
      cout << ans << endl;


  }


  

  
  
  return 0;
    

}


Measured memory_bytes: 3640
/* Dynamic Programming implementation of LCS problem */
#include<iostream> 
#include<cstring> 
#include<cstdlib> 
using namespace std; 


void lcs( string X, string Y, int m, int n ) 
{ 
int L[m+1][n+1]; 


for (int i=0; i<=m; i++) 
{ 
	for (int j=0; j<=n; j++) 
	{ 
	if (i == 0 || j == 0) 
		L[i][j] = 0; 
	else if (X[i-1] == Y[j-1]) 
		L[i][j] = L[i-1][j-1] + 1; 
	else
		L[i][j] = max(L[i-1][j], L[i][j-1]); 
	} 
} 


int index = L[m][n]; 


char lcs[index+1]; 
lcs[index] = '\0'; 


int i = m, j = n; 
while (i > 0 && j > 0) 
{ 
	
	if (X[i-1] == Y[j-1]) 
	{ 
		lcs[index-1] = X[i-1]; 
		i--; j--; index--;	
	} 

	
	else if (L[i-1][j] > L[i][j-1]) 
		i--; 
	else
		j--; 
} 


cout << lcs; 
} 


int main() 
{ 
string X,Y;
cin>>X;
cin>>Y; 
int m = X.length(); 
int n = (Y).length(); 
lcs(X, Y, m, n); 
return 0; 
} 


Measured memory_bytes: 38808
#include<bits/stdc++.h>
using namespace std;
int main()
{   unsigned long long int n,m,c=1,i=1,x,t;
    cin>>n>>x>>t;
    while(i*x<n)
    {
        i++;
    }printf("%d\n",i*t);
    
    
    
    
    
	
}

Measured memory_bytes: 3756
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//ここまでテンプレ
int main(){
	int N,A,B;
	cin>>N>>A>>B;
	int ans=0;
	for(int i=1;i<=N;i++){
		char S[10];
		sprintf(S,"%d",i);
		int sum=0;
		for(int j=0;S[j]!='\0';j++){
			sum+=S[j]-'0';
		}
		if(A<=sum && sum<=B)
			ans+=i;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int a[10001];

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

    int h, n, x, y;
    cin >> h >> n;
    for (int i = 1; i <= 10000; i++) a[i] = -1;
    for (int i = 0; i < n; i++) {
        cin >> x >> y;
        if (a[x] == -1) a[x] = y;
        else a[x] = min(a[x], y);
    }
    int c[h + 1];
    c[0] = 0;
    for (int i = 1; i <= h; i++) c[i] = -1;
    for (int i = 1; i <= 10000; i++) {
        if (a[i] == -1) continue;
        for (int j = 0; j < h; j++) {
            if (c[j] == -1) continue;
            if (c[min(h, i + j)] == -1) c[min(h, i + j)] = c[j] + a[i];
            else c[min(h, i + j)] = min(c[min(h, i + j)], c[j] + a[i]);
        }
    }
    cout << c[h] << "\n";
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <map>

int main(int c,char *argv[]){
  std::string S;
  std::cin >> S;
  std::map<char,int> s_map;
  for(auto &s:S){
    s_map[s] += 1;
  }
  for(auto &m: s_map){
    if(m.second != 2){
      std::cout << "No" << std::endl;
      return 0;
    }
  }
  std::cout << "Yes" << std::endl;    
}

Measured memory_bytes: 256
#include <stdio.h>

int fibonacci(int);

int fibo[44];

int main(){
  int n,i;
  scanf("%d",&n);
  for(i=0;i<=44;i++)
    fibo[i]=-1;
  printf("%d\n",fibonacci(n));
  return 0;
}

int fibonacci(int n){
  if(n==0||n==1)
    return fibo[n]=1;
  if(fibo[n]!=-1)
    return fibo[n];
  return fibo[n] = fibonacci(n-1)+fibonacci(n-2);
}



Measured memory_bytes: 2132
#include<bits/stdc++.h>
using namespace std;
int main()
{

    int a,b,c,d;
    cin>>a>>b;
    c = a*4;
    d = a*2;
    if(b%2==0 && d<=b && b<=c)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    return 0;
}


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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

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

const ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// head
void add(int& a, int b) {
    a += b;
    if(a >= mod) a -= mod;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    string s;
    cin >> s;
    int d;
    cin >> d;

    int n = s.size();
    vector<vi> dp(d, vi(2)); // # of ways so far
    dp[0][0] = 1;
    rep(digit,0,n) { // for each nxt digit
        vector<vi> cnt(d, vi(2));
        rep(i,0,d) {
            for(bool seenSmaller : {false, true}) {
                rep(j,0,10) {
                    if(j > (s[digit] - '0') && !seenSmaller) {
                        break;
                    } else {
                        add(cnt[(i + j) % d][seenSmaller || (j < (s[digit] - '0'))], dp[i][seenSmaller]);
                    }
                }
            }
        }
        dp = cnt;
    }
    int ans = (dp[0][0] + dp[0][1]) % mod;
    ans--;
    if(ans < 0) ans += mod;
    cout << ans << endl;
    return 0;
}


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

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

using namespace std;

int main()
{
    cout << fixed;
    cout << setprecision(20);
    double a,b,h,m;
    cin >> a >> b >> h >> m;
    double deg_hr = (h*30) + (m*6)/12;
    double deg_min = m*6;
    double deg = abs(deg_hr-deg_min);
    double cos_deg = cos(deg*pi/180);
    double asqr = a*a;
    double bsqr = b*b;
    double c = sqrt(asqr+bsqr - 2*a*b*cos_deg);

    cout << c << endl;
    return 0;
}


Measured memory_bytes: 4140
#include <algorithm>
  #include <functional>
  #include <iostream>
  using namespace std;
  int main()
  {
    int N;
    cin>>N;
    int a[N];
    for(int i = 0; i < N; i++) {
      int d;
      cin>>d;
      a[i] = d;
    }
    int len=sizeof(a)/sizeof(int);
    sort(a, a + len);
    // cout<<a[0]<<a[1]<<endl;

    int alice = 0;
    int bob = 0;

    for(int i = N - 1; i > -1; i--) {
      if(i % 2 == (N - 1) % 2) {
        alice += a[i];
      }
      else {
        bob += a[i];
      }
    }


    int ans = alice - bob;
    cout<<ans<<endl;
    return 0;
  }


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

using namespace std;
const int N = 200010;
const int MOD = 1e9+7;
int _w;

int n, c[N], f[N], last[N];

int main() {
	_w = scanf( "%d", &n );
	for( int i = 1; i <= n; ++i )
		_w = scanf( "%d", c+i );
	f[1] = 1, last[c[1]] = 1;
	for( int i = 2; i <= n; ++i ) {
		if( last[c[i]] ) {
			f[i] = (f[i] + f[last[c[i]]]) % MOD;
		}
		if( last[c[i]] != i-1 ) {
			f[i] = (f[i] + f[i-1]) % MOD;
		}
		// printf( "f[%d] = %d\n", i, f[i] );
		last[c[i]] = i;
	}
	cout << f[n] << endl;
	return 0;
}


Measured memory_bytes: 5992
// C - Together
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, n, w, ans = 0, count = 0;
  string s, t;
  vector<pair<string, pair<lli, lli>>> pr;
  cin >> n;
  vlli d(n), e(100010, 0), f(100010, 0), g(100010, 0), k, l(100010, 0);
  rep(i, 0, n)
  {
    cin >> d[i];
    // e[d[i] - 1]++;
    // f[d[i] + 1]++;
    // g[d[i]]++;
    if (d[i] >= 1)
    {
      l[d[i] - 1]++;
    }
    l[d[i] + 1]++;
    l[d[i]]++;
  }
  // SORTR(e);
  // SORTR(f);
  // SORTR(g);
  SORTR(l);
  // k.pb(e[0]);
  // k.pb(f[0]);
  // k.pb(g[0]);
  // SORTR(k);
  cout << l[0] << endl;
}

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

int main() {
    int n; scanf("%d", &n);
    int l = 1, r = 50000;
    while(l < r) {
        int m = l + r >> 1;
        int val = (1ll * m * (m + 1)) >> 1;
        if(val >= n) r = m;
        else l = m + 1;
    }
    printf("%d\n", r);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long int ;
 
 
int main(void){
	cin.tie(0);ios::sync_with_stdio(false);

    string s;

    cin >> s;

    for(int i=0; i<s.length(); i++){
        if(s[i] != 'h' || s[i+1] != 'i'){
            cout << "No" << endl;
            return 0;
        }
        i++;   
    }
    cout << "Yes" << endl;
 
    return 0;
}

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

int main() {
  int a,b,c,d;
  string ret;

  cin >> a;
  cin >> b;
  cin >> c;
  cin >> d;

  while(1) {
    c = c - b; 
    if(c <= 0) {
      ret = "Yes";
      break;
    }
    a = a - d; 
    if(a <= 0) {
      ret = "No";
      break;
    }
  }
  cout << ret << endl;
}


Measured memory_bytes: 3632
#pragma comment(linker, "/STACK:64000000")
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <sstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define y1 stupid_cmath
#define left stupid_left
#define right stupid_right
#define vi vector <int>
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))

const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);

int n, a[200200], two[200200], dp[20][200200];

void precalc() {
    two[0] = -1;
    for (int i = 1; i < 200200; i++) two[i] = 1 + two[i / 2];
    for (int i = 0; i < n; i++) dp[0][i] = a[i];
    for (int lvl = 1; (1 << lvl) <= n; lvl++) {
        for (int i = 0; i + (1 << lvl) <= n; i++) {
            dp[lvl][i] = min(dp[lvl - 1][i],
                             dp[lvl - 1][i + (1 << (lvl - 1))]);
        }
    }
}

int getmin(int l, int r) {
    if (l > r) return inf;
    int lvl = two[r - l + 1];
    int ans1 = dp[lvl][l];
    int ans2 = dp[lvl][r - (1 << lvl) + 1];
    return min(ans1, ans2);
}

int main(){

    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", a + i);

    precalc();

    ll ans = 0;

    for (int i = 0; i < n; i++) {
        int L = i, R = i;
        int l = 0, r = i - 1;
        while (l <= r) {
            int mid = (l + r) >> 1;
            if (getmin(mid, i) == a[i]) {
                L = mid;
                r = mid - 1;
            } else l = mid + 1;
        }
        l = i; r = n - 1;
        while (l <= r) {
            int mid = (l + r) >> 1;
            if (getmin(i, mid) == a[i]) {
                R = mid;
                l = mid + 1;
            } else r = mid - 1;
        }
        ans += (R - i + 1) * 1ll * (i - L + 1) * a[i];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 14848
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace csharp
{
    class Program
    {
        static void Main(string[] args)
        {
            var csl = Console.ReadLine();
            var N = int.Parse(csl);

            var cards = new List<long>();
            csl = Console.ReadLine();
            foreach (var a in csl.Split(' '))
            {
                cards.Add(long.Parse(a));
            }

            var sunuke = (long)0;
            var arai = (long)0;

            sunuke += cards[0];
            for (var a_pos = 1; a_pos < cards.Count; a_pos++)
            {
                arai += cards[a_pos];
            }
//            Console.WriteLine(sunuke+ " " +arai);

            var result = sunuke - arai;
            if (result < 0)
            {
                result *= -1;
            }

            for (var pos = 1; pos < cards.Count - 1; pos++)
            {
                sunuke += cards[pos];
                arai -= cards[pos];

                var one_result = sunuke - arai;
                if (one_result < 0)
                {
                    one_result *= -1;
                }

                if (result > one_result)
                {
                    result = one_result;
                }
            }


            Console.WriteLine(result);

        }
    }
}

Measured memory_bytes: 35548
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;


int main()
{
  // 整数の入力
  ll N;
  cin >> N;
  ll ans = 0;
  for(int i = 1;i <= N;i++){
    ll count = N/i;
    ans += i * count * (count + 1)/2;
  }
  cout << ans << endl;
  return 0;
}

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

int h, n;
vector<int> b;

int dp[101010][10];

int dfs(int i = 1, int bit = 0) {
  if (i == h) {
    return 0;
  }
  bit |= b[i];

  int &ret = dp[i][bit];
  if (~ret)
    return ret;

  ret = 0;
  if (bit == 0)
    ret = max(ret, dfs(i + 1, 0b111) + 2);
  if ((bit & (0b100)) == 0)
    ret = max(ret, dfs(i + 1, 0b110) + 1);
  if ((bit & (0b010)) == 0)
    ret = max(ret, dfs(i + 1, 0b111) + 1);
  if ((bit & (0b001)) == 0)
    ret = max(ret, dfs(i + 1, 0b011) + 1);
  ret = max(ret, dfs(i + 1, 0));

  return ret;
}

int main() {
  memset(dp, -1, sizeof(dp));
  cin >> h >> n;

  int ei[4] = {0b100, 0b110, 0b011, 0b001};
  b.assign(h + 1, 0);
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    b[y + 1] |= ei[x];
    b[y] |= ei[x];
  }

  cout << dfs() << endl;
}

Measured memory_bytes: 7564
#include <iostream>
#include <stdio.h>
#include <numeric>
#include <queue>
#include <string>
#include <cmath>
#include <vector>
#include <deque>
#include <iomanip>
#include <set>
#include <queue>
#include <bitset>
#include <iomanip>
#include <map>
#include <string.h>
#include <stack>
#include <algorithm>

//#include <unordered_map>
//#include <unordered_set>

using namespace std;

int main()
{
	int a , b;
	while (scanf("%d%d" , &a , &b) != EOF)
	{
		if (b < 0)
		{
			int tot = (b - a + 1);
			if (tot % 2 == 0)
				printf("Positive\n");
			else
				printf("Negative\n");
		}
		else if (a > 0)
			printf("Positive\n");
		else
			printf("Zero\n");
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long a = in.nextLong();
        long b = in.nextLong();
        long x = in.nextLong();
        long result = 0;
        if (a % x == 0) {
            result = (b / x) - (a / x) + 1;
        } else {
            result = (b / x) - (a / x);
        }
        System.out.println(result);
    }
}

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

int main(){
    int N, K;
    cin >> N >> K;
    int ans = 0;
    for(int i=0; i<N; i++){
        int h;
        cin >> h;
        if(h >= K) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
#include <chrono>
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
int main(){
    map<string,int>mp;
    int N;cin>>N;
    REP(i,N){
        string s;
        cin>>s;
        mp[s]++;
    }
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;
    return 0;
}


Measured memory_bytes: 3624