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

int main() {
    int n;
    cin >> n;
    vector<int> w(n);
    for (int i = 0; i < n; ++i) cin >> w[i];
    int MIN = 10000;
    for (int i = 0; i < n-1; ++i) {
        int sum1 = 0;
        int sum2 = 0;
        for (int j = 0; j < n; ++j) {
            if (i >= j) {
                sum1 += w[j];
            }
            else {
                sum2 += w[j];
            }
        }
        MIN = min(MIN, abs(sum1 - sum2));
    }
    cout << MIN << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)

N,K = map(int,input().split())
list = list(map(int,input().split()))

def dfs(N,ans):
    if N <= 0:
        return ans
    return dfs(N-(K -1),ans+1)

print(dfs(N-K,1))

Measured memory_bytes: 54552
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

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

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

int N, C;
int main(){
    ios::sync_with_stdio(false);
    const ll term = 2 * 100000 + 2;

    cin >> N >> C;
    vector<vector<ll> > table(C, vector<ll>(term, 0));
    REP(i, N) {
        int s, t, c;
        cin >> s >> t >> c;
        s*=2;
        t*=2;
        c--;
        table[c][s-1]+=1;
        table[c][t]-=1;

    }

    REP(c, C) {
        int isDup = 0;
        bool isInterval = false;
        REP(i, term) {
            if (isInterval) {
                if (table[c][i] == 1) {
                    table[c][i] = 0;
                    isDup++;
                } else if (table[c][i] == -1) {
                    if (isDup == 0) {
                        isInterval = false;
                    } else {
                        table[c][i] = 0;
                        isDup--;
                    }
                }
            } else {
                if (table[c][i] == 1) isInterval = true;
            }
        }
    }

    ll ans = 0;
    ll tmp = 0;

    REP(i, term) {
        REP(c, C) {
            tmp += table[c][i];
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef double dd;

void solve(ll test_num) {
  (void) test_num;
  string str;
  cin >> str;
  string rev = str;
  reverse(rev.begin(), rev.end());
  for (char& c : rev) {
    if (c == 'b') c = 'd';
    else if (c == 'd') c = 'b';
    else if (c == 'p') c = 'q';
    else c = 'p';
  }
  if (str == rev)cout << "Yes\n";
  else cout << "No\n";
}

void init() {

}

int main() {
#ifdef AZN
  const auto start_time = chrono::system_clock::now();
  freopen("/home/azneye/Documents/Stuff/input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  init();
  ll tests = 1;
  //cin >> tests;
  for (ll test = 1; test <= tests; ++test) {
    solve(test);
  }
#ifdef AZN
  cerr << "Took: " << ((chrono::system_clock::now() - start_time).count() / 1e9) << " s" << endl;
#endif
  return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back

using namespace std;

// #define DEBUG_IS_VALID

#ifdef DEBUG_IS_VALID
#define DEB 1 
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
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; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline void chmax(T& a,T const& b){a=max(a,b);}
template<class T> inline void chmin(T& a,T const& b){a=min(a,b);}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<60; 

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  using dd = double; 
  int N; dd X; cin >> N >> X ;
  vector<double> x(N); rep(i,N) cin >> x[i];
  dd ans = 8e24;
  vector<double> s(N+1); rep(i,N) s[i+1] = s[i] + x[i];
  dump(s);
  function<dd(int,int)> rsum = [&](int l,int r){
    // res : sum of range [l,r)
    if(r<=0) return 0.0;
    l = max(l,0);
    r = min(r,N);
    return s[r] - s[l];
  };
  REP(m,1,N+1){
    dd temp = 0;
    temp += rsum(N-m,N);
    dd k = 1.0;
    dd i=N-1;
    for(;i>=0;i-=m){
      dump(i,k,m);
      temp += (k+1)*(k+1)*(rsum(i-m+1,i+1)-rsum(i-2*m+1,i-m+1));
      k++;
    }
    temp += dd(N+m) * X;
    chmin(ans,temp);
  }
  cout << ll(ans) << endl;
  return 0;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long 
#define M 1000000007
#define P pair<int,int>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) FOR(i,0,n)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

char s[300000];

int main(){
  cin>>s;

  int n = strlen(s);
  int m = n;
  int a = 0;

  for(int i=0;i<n;i++){
    if(s[i]=='S') a++;
    if(s[i]=='T'&&a>0){
      m-=2;
      a--;
    }
  }

  cout<<m<<endl;

  return 0;
}


Measured memory_bytes: 384
import heapq
from collections import deque
n,k = map(int,input().split())
v=list(map(int,input().split()))

res = 0
for i in range(k+1):
    for j in range(k+1-i):
        d = deque(v)
        num = 0
        a = []

        cnt = 0
        while cnt<i and len(d):
            x = d.popleft()
            heapq.heappush(a,x)
            num += x
            cnt += 1
        cnt = 0
        while cnt<j and len(d):
            x = d.pop()
            heapq.heappush(a,x)
            num += x
            cnt += 1

        sub = k-i-j
        while sub > 0 and len(a):
            y = heapq.heappop(a)
            if y <= 0:
                num -= y
            sub -= 1
        
        res = max(res,num)
print(res)

Measured memory_bytes: 3316
#include <stdio.h>

int main(){
    int n;
    scanf("%d",&n);
    char s[105];
    char t[105];
    scanf("%s %s",s,t);
    int i=0;
    int j=0;
    int a=0;
    for(i=0;i<=n-1;i++){
        for(j=0;j<=n-i-1;j++){
            if(t[j]!=s[i+j]){
                a=1;
            }
        }
        if(a==0){
            break;
        }else if(a==1){
            j=0;
            a=0;
        }
    }
    
    printf("%d",n+i);
    return 0;
}


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

int main() {
  int N, L;
  cin >> N >> L;
  string S, ans;
  vector<string> vec(N);

  for(int i = 0; i < N; i++){
    cin >> S;
    vec.at(i) = S;
  }
  
  sort(vec.begin(), vec.end());
  
  for(int i = 0; i < N; i++){
    ans += vec.at(i);
  }
  
  cout << ans << endl;
  
  return 0;
}


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

#define max(a,b) (a >= b ? a : b)
#define min(a,b) (a >= b ? b : a)


typedef long long ll;



int main(void){
    int S, W;
    scanf("%d %d", &S, &W);
    if(S<=W){
        printf("unsafe");
    }else{
        printf("safe");
    }


    return 0;
}


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

int main(){
	int N;
  	cin >> N;
  	vector<int> vec(N);
  
  	for(int i=0;i<N;i++){
    	cin >> vec.at(i);
    }
  
  	int count=0;
  
  	for(int i=0;i<N;i++){
    	if(vec.at(i) != i+1){
        	count++;
        }
    }
    
    if(count == 0 || count == 2){
    	cout << "YES" << endl;
    }
  	else{
    	cout << "NO" << endl; 
    }
      
  	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;
int main() {
    string S;
    cin >> S;
    int count=0;
    for (int i = 0; i < S.length(); i++)
    {
        if (S[i] == '1'){
            count++;
        }
    }
    cout << min(count, (int)S.length() - count) * 2 << endl;
}

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

int main() {
  const unsigned long long MOD = 1000000007;
  unsigned long N;
  unsigned long long A, B, C, D;
  std::cin >> N >> A >> B >> C >> D;
  std::vector<unsigned long long> inv(N + 1);
  inv[1] = 1;
  for (unsigned i = 2; i <= N; ++i) { inv[i] = MOD - (MOD / i) * inv[MOD % i] % MOD; }
  std::vector<unsigned long long> fact(N + 1);
  fact[0] = 1;
  for (unsigned i = 1; i <= N; ++i) { fact[i] = fact[i - 1] * i % MOD; }
  std::vector<unsigned long long> inv_fact(N + 1);
  inv_fact[0] = 1;
  for (unsigned i = 1; i <= N; ++i) { inv_fact[i] = inv_fact[i - 1] * inv[i] % MOD; }
  std::vector<std::vector<unsigned long long>> dp(N + 1, std::vector<unsigned long long>(N + 1, 0));
  for (unsigned i = 0; i <= N; ++i) { dp[0][i] = 1; }
  for (unsigned i = 1; i <= N; ++i) {
    for (auto j = A; j <= B; ++j) {
      dp[i][j] = dp[i][j - 1];
      if (i / j < C) { continue; }
      unsigned long long tmp = 1;
      for (unsigned k = 0; k < C - 1; ++k) {
        tmp *= inv_fact[j];
        tmp %= MOD;
      }
      for (auto k = C; k <= std::min(i / j, D); ++k) {
        tmp *= inv_fact[j];
        tmp %= MOD;
        auto acc = dp[i - k * j][j - 1];
        //choose{i}{k*j} * frac{(k*j)!}{j!**k*k!}
        //i!(k*j)! / (k*j)!(i-k*j)!(j!)**k(k!)
        //i! / (i-k*j)!(j!)**k(k!)
        acc *= fact[i];
        acc %= MOD;
        acc *= inv_fact[i - k * j];
        acc %= MOD;
        acc *= tmp;
        acc %= MOD;
        acc *= inv_fact[k];
        acc %= MOD;
        dp[i][j] += acc;
        dp[i][j] %= MOD;
      }
    }
  }
  std::cout << dp[N][B];
  return 0;
}

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

int main(){
  int a,b,N;
  cin >> N;
  a = N/4 + 1;
  b = N/7 + 1;
  int ans;
  for (int i=0; i<a+1; i++){
    for (int j=0; j<b+1; j++){
      if ((4*i+7*j) == N) ans+=1 ;
    }
  }
  cout << (ans > 0 ? "Yes" :"No") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>

int main()
{
    int a, b, c;
    std::cin >> a >> b >> c;
    if(a > b) std::swap(a, b);
    if(b > c) std::swap(b, c);
    if(a > b) std::swap(a, b);
    printf("%d %d %d\n", a, b, c);
    return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back

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

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

int main(){
	ll a=read(),b=read(),c=read();
	if(a%2==0||b%2==0||c%2==0)
		cout<<0<<endl;
	else
		cout<<min({a*b,b*c,c*a})<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b,x,ans=0;
  cin>>n>>a>>b;
  for(int i=0;i<n;i++){
    cin>>x;
    if(x<a||b<=x){
      ans+=1;
    }
  }
  cout<<ans<<endl;
}


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

bool is_ok(const vector<int>& block, const vector<int>& tmp, int k)
{
  for (int i = 0; i < (int)tmp.size(); i++) {
    if (k < block.at(i) + tmp.at(i)) {
      return false;
    }
  }
  return true;
}

bool tmp_is_ok(const vector<int>& tmp, int k)
{
  for (auto x : tmp) {
    if (k < x) {
      return false;
    }
  }
  return true;
}

int main()
{
  int h, w, k;
  scanf("%d %d %d", &h, &w, &k);
  char linefeed = getchar();
  assert(linefeed == '\n');
  vector<vector<int>> board(h, vector<int>(w));
  for (int x = 0; x < h; x++) {
    for (int y = 0; y < w; y++) {
      char c = getchar();
      if (c != '0' && c != '1') {
        putchar(c);
      }
      assert(c == '0' || c == '1');
      board.at(x).at(y) = c - '0';
    }
    char lf = getchar();
    assert(lf == '\n');
  }
  int res = INT_MAX;
  for (int pattern = 0; pattern < pow(2, h-1); pattern++) {
    vector<int> block(h);

    int cnt = 0;
    for (int i = 1; i <= pattern; i = i << 1) {
      if (pattern & i) {
        cnt++;
      }
    }

    bool is_invalid_division = false;
    for (int y = 0; y < w; y++) {
      int i = 0;
      vector<int> tmp(h, 0);
      tmp.at(0) = board.at(0).at(y);
      for (int x = 1; x < h; x++) {
        if ((1<<(x-1)) & pattern) {
          i++;
        }
        tmp.at(i) += board.at(x).at(y);
      }
      if (!tmp_is_ok(tmp, k)) {
        is_invalid_division = true;
        break;
      }

      if (is_ok(block, tmp, k)) {
        for (int i = 0; i < (int)tmp.size(); i++) {
          block.at(i) += tmp.at(i);
        }
      } else {
        cnt++;
        for (int i = 0; i < (int)tmp.size(); i++) {
          block.at(i) = tmp.at(i);
        }
      }
    }

    if (is_invalid_division) {
      continue;
    }

    res = min(res, cnt);
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# 愚直にいくと、index 0からlen(s)-3 までループして取り出す minを保管
s = input()
#print(s[0::])
min_abs = 999
for i in range(len(s)-2):
    if abs(int(s[i:i+3]) - 753) < min_abs:
        min_abs = abs(int(s[i:i+3]) - 753)
print(min_abs)

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>

using namespace std;
#define REP(i,e,s) for(register int i=e; i<=s; i++)
#define DREP(i,e,s) for(register int i=e; i>=s; i--)
#define DE(...) fprintf(stderr,__VA_ARGS__);
#define DEBUG(a) DE("DEBUG: %d\n",a)
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
#define ll long long

int read() {
	int x=0,f=1,ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int INF=0x3f3f3f;

int main() {
	int a=read(),b=read();
	printf("%d\n",max(a+b,max(a-b,a*b)));
	return 0;
}



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

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

struct Range {
  int l;
  int r;
  Range() {;}
  Range(int l, int r) : l(l), r(r) {;}
  bool operator<(const Range &rhs) const {
    return l < rhs.l;
  }
};

vector<Range> rs;
void Push(int l, int r) {
  rs.push_back(Range(l, r));
}

int main() {
  int n, p, q;
  while (scanf("%d %d %d", &n, &p, &q), n|p|q) {
    rs.clear();
    p = p / 100 * 60 + p % 100;
    q = q / 100 * 60 + q % 100;
    REP(i, n) {
      int k;
      scanf("%d", &k);
      int prev = p;
      REP(j, k) {
        int l, r;
        scanf("%d %d", &l, &r);
        l = l / 100 * 60 + l % 100;
        r = r / 100 * 60 + r % 100;
        l = min(q, max(p, l));
        r = min(q, max(p, r));
        Push(prev, l);
        prev = r;
      }
      Push(prev, q);
    }
    sort(rs.begin(), rs.end());
    int ans = 0;
    int prev = p;
    int lans = 0;
    FORIT(it, rs) {
      if (it->l <= prev) {
        lans += max(0, it->r - prev);
      } else {
        lans = it->r - it->l;
      }
      prev = max(prev, it->r);
      ans = max(ans, lans);
    }
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 1192
#pragma region def
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

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

using llint = long long;
using vint = vector<int>;
using vvint = vector<vector <int>>;
using pint = pair<int, int>;
const int INF = 1e9;
const long long llINF = 1e18;
#pragma endregion

int main () {
    string s; cin >> s;
    int ans = 0;
    for (int i = 0; i < s.size(); i++) {
        int count = 0;
        for (int j = i; j < s.size(); j++) {
            char a = s[j];
            if (a=='A'||a=='C'||a=='G'||a=='T') {
                count++;
            } else {
                break;
            }
        }
        ans = max(ans, count);
    }
    cout << ans << endl;
    return 0;
}

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


void solve(long long a, long long b){
    if(a+b == 15) cout << '+' << endl;
    else if(a*b == 15) cout << '*' << endl;
    else cout << 'x' << endl;
}

int main(){
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    solve(a, b);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int n;
  cin>>n;
  vector<int> a(n);
  map<int,int> freq;
  for(int i = 0; i < n; i++){
  	cin>>a[i];
    freq[a[i]]++;
  }
  int ans = 0;
  for(int i = 0; i < n; i++){
  	if(freq[a[i]]>=2)continue;
    bool flag = true;
    for(int j = 1; j*j <= a[i]; j++){
    	
      	if(a[i]%j == 0){
            int tmp = freq[j];
            if(j == a[i])tmp--;
			      if(tmp>0){
            	flag = false;
              	break;
            }
          	int x = a[i]/j;
            tmp = freq[x];
          	if(x == a[i])tmp--;
          	if(tmp>0){
          		flag = false;
          		break;
            }
        }
    }
    if(flag){
    	ans++;
    }
  }
  cout<<ans;
  // return 0;
}


Measured memory_bytes: 32736
a = gets
b = a.split

w,h,x,y,r = b.map(&:to_i)
# map 要素追加　& 修飾

unless ( -100 <= x || x <= 100 ) || ( -100 <= y || y <= 100 )
  return
end

unless (0 < w || w <= 100 ) || (0 < h || h <= 100 ) || (0 < r || r <= 100 )
  return
end


if  ( (x < r) || (y < r) ) || ( ((w - x) < r) || ((h - y) < r) )
  puts "No"
else
  puts "Yes"
end


Measured memory_bytes: 6876
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdio>
#include <map>
#include <cstring>

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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> P;

void p(vi v){
	rep(i, v.size()){
		cout << v[i] << ' ';
	}
	cout << endl;
}

int field[200][200];

int main(){
	int n;
	while(cin >> n, n){
		memset(field, 0, sizeof(field));
		int w, h;
		cin >> w >> h;
		vector<P> p(n);
		rep(i, n){
			int x, y;
			cin >> x >> y;
			p[i] = P(x, y);
		}
		int s, t;
		cin >> s >> t;
		rep(i, n){
			int x, y;
			x = p[i].first;
			y = p[i].second;
			rep(j, s){
				rep(k, t){
					field[100+y-k][100+x-j]++;
				}
			}
		}

		int maxim = 0;
		rep(j, 100-s){
			rep(k, 100-t){
				maxim = max(maxim, field[100+k][100+j]);
			}
		}

		cout << maxim << endl;
	}
	return 0;
}

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


int main(){
    int n;
    scanf("%d",&n);
    if(n%10==3){
        printf("bon\n");
    }
    else if(n%10==0 || n%10==1 || n%10==6 || n%10==8 ){
        printf("pon\n");
    }
    else{
        printf("hon\n");
    }
    
    return 0;
}

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

void Change(char *conv, char *res)
{
  for (int i = 0; i < 4; i++){
    res[i] = conv[i + 2];
  }
}
int main()
{
  int n, s;

  scanf("%d", &n);

  for (int i = 0; i < n; i++){
    scanf("%d", &s);
    printf("Case %d:\n", i + 1);
    for (int j = 0; j < 10; j++){
      char conv[9], res[5];
      sprintf(conv, "%08d", s * s);
      Change(conv, res);
      s = atoi(res);
      printf("%d\n", s);
    }
  }

  return (0);
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MOD=(int)1e9+7;
const int N=(int)1e5+5;
int fact[N];
void pre()
{   
    fact[0]=fact[1]=1;
    for(int i=2;i<=N-2;i++){
        fact[i]=fact[i-1]*i%MOD;
    }
}
int exp(int a,int n)
{
    if(n==0)    return 1;
    if(n==1)    return a;
    int p=exp(a,n/2);
    p*=p;p%=MOD;
    p*=((n%2)?a:1);p%=MOD;
    return p;
}
int nck(int n,int k)
{
    int den=(fact[n-k]*fact[k])%MOD;
    return (fact[n]*exp(den,MOD-2))%MOD;
}
main()
{
    pre();
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)    cin>>a[i];
    sort(a,a+n);
    int ans=0;
    for(int i=0;i<n;i++){
        if(i>=k-1){
            ans+=(nck(i,k-1)*a[i])%MOD;
            ans%=MOD;
        }
        if(n-i-1>=k-1){
            ans-=(nck(n-i-1,k-1)*a[i])%MOD;
            ans+=MOD;
            ans%=MOD;
        }
    }
    cout<<ans<<"\n";
}   

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

public class Main {

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

  public void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      int id,left,right;
      String[] words;
      Tree tree = new Tree(n);

      for(int i=0,k=0; i<n; i++,k=0){
        words = br.readLine().split(" ");
        id = Integer.parseInt(words[k++]);
        left  = Integer.parseInt(words[k++]);
        right = Integer.parseInt(words[k++]);

        tree.nodeInit(id,left,right);
      }

      tree.dispRoundPath(tree.getTreeRoot());
    }
    catch(IOException e) {
      System.out.println("IOException!");
    }
  }
}

class Tree {

  static final int NIL = -1;
  BTreeNode[] node;
  StringBuilder buf;

  public Tree(int size) {
    node = new BTreeNode[size];
    for (int i=0; i < size; i++) {
      node[i] = new BTreeNode();
    }
    buf = new StringBuilder(size*3);
  }

  void nodeInit(int id, int left, int right) {
    node[id].id = id;
    node[id].left = left;
    node[id].right = right;
    setParent(id);
  }
  int getTreeRoot() {
    int root=0;

    for (BTreeNode e : node)
      if(e.parent == Tree.NIL)
        return root = e.id;

    return root;
  }
  void setParent(int id) {
    if(node[id].left != Tree.NIL)
      node[ node[id].left ].parent = id;
    if(node[id].right != Tree.NIL)
      node[ node[id].right ].parent = id;
  }

  void preParse(int u) {
    if(u != NIL){
      buf.append(" ").append(u);
      preParse(node[u].left);
      preParse(node[u].right);
    }
  }
  void inParse(int u) {
    if(u != NIL) {
      inParse(node[u].left);
      buf.append(" ").append(u);
      inParse(node[u].right);
    }
  }
  void postParse(int u) {
    if(u != NIL) {
      postParse(node[u].left);
      postParse(node[u].right);
      buf.append(" ").append(u);
    }
  }

  void dispRoundPath(int root) {

    buf.append("Preorder\n");
    preParse(root);
    buf.append("\n")
       .append("Inorder\n");
    inParse(root);
    buf.append("\n")
       .append("Postorder\n");
    postParse(root);
    buf.append("\n");

    System.out.print(buf);
  }
}

class BTreeNode {
  int id,parent,left,right;

  public BTreeNode() {
    this.id =
    this.parent =
    this.left =
    this.right = Tree.NIL;
  }
}


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

using ll = long long; 

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

  vector <int> A(N);
  for (int i=0; i<N; ++i){
    cin >> A.at(i);
  }

  bool denied = false;
  for (int i=0; i<N; ++i){
    if (A.at(i)%2==0 && A.at(i)%3!=0 && A.at(i)%5!=0 ){
      denied = true;
      break; 
    }
  }

  if (denied) {
    cout << "DENIED" << endl;
  }
  else {
    cout << "APPROVED" << endl;
  }

}

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

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pb;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpi;
typedef map<int,int> mapii;
typedef map<int,bool> mapib;
typedef priority_queue<int> pq;
typedef priority_queue<int,vector<int>,greater<int> > pqq;

#define small 1e-9
#define big5 1000000005
#define big7 1000000007
#define pi 3.1415926
#define big 10000000

#define inp(arr,n) for(int i=0;i<n;i++)cin>>arr[i];
#define bsdk ios_base::sync_with_stdio(false);cin.tie(NULL);
#define disp(arr) for(auto i:arr)cout<<i<<" ";cout<<"\n"
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define yess cout<<"Yes\n"
#define noo cout<<"No\n"
#define m1 cout<<"-1\n"
#define nl <<endl
#define hs cout<<"#"

#define rep(i,n) for(i=0;i<n;i++)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define sorti(v) sort(v.begin(),v.end())
/*int ncr(int n, int k)
{
    int res = 1;
    if (k > n - k)
        k = n - k;
    for (int i = 0; i < k; ++i) {
        res *= (n - i);
        res /= (i + 1);
    }
    return res;
}
bool isprime[big+1];
vector<int> primes;
void makesieve()
{
    ll i,j;
    rep(i,big+1)
        isprime[i]=false;
    isprime[2]=true;
    for(i=3;i<=big;i+=2)
        isprime[i]=true;
    for(i=3;i<=big;i+=2)
    {
        if(isprime[i])
            for(j=i*i;j<=big;j+=i)
            isprime[j]=false;
    }
    rep(i,big+1)
    {
        if(isprime[i])
            primes.pb(i);
    }
}
vpi fact(ll n)
{
    ll i=0;
    vpi pf;
    ll c;
    while(primes[i]*primes[i]<=n)
    {
        if(n%primes[i]==0)
        {
            c=0;
            while(n%primes[i]==0)
                {
                    n=n/primes[i];
                    c++;
                }
            pf.pb(mp(primes[i],c));
        }
        i++;
    }
    if(n!=1)
        pf.pb(mp(n,1));
    return pf;
}
ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}
ll findlcm(ll arr[], ll n)
{
    // Initialize result
    ll ans = arr[0];

    // ans contains LCM of arr[0], ..arr[i]
    // after i'th iteration,
    for (int i = 1; i < n; i++)
        ans = (((arr[i] * ans)) /
                (gcd(arr[i], ans)));
    return ans;
}
ll poww(ll n,ll m){
    if(m==0)return 1;
    if(m==1)return n;
    ll ans = poww(n,m/2);
    if(m%2==1) return (ans*ans)*n;
    else return (ans*ans);
}*/
void solve()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll ans;
    ans=max(a*c,max(a*d,max(b*c,b*d)));
    cout<<ans nl;
}
int main()
{
    bsdk
    int t;
    //cin>>t;
    t=1;
    //makesieve();
    for(int i=1;i<=t;i++)
       {
           //cout<<"Case #"<<i<<": ";
           solve();
       }
    return 0;
}



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

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

const int MAX = 1e5 + 5;
vector<int> adj[MAX];
bool visited[MAX];
int arr[MAX];
int n, m;

void dfs(int source, set<int> &guys) {
	visited[source] = true;
	guys.insert(source);
	for(auto &each : adj[source]) {
		if(!visited[each]) {
			dfs(each, guys);
		}
	}
}

int main() {
	scanf("%d %d", &n, &m);

	fori(i, 1, n + 1) {
		scanf("%d", arr + i);
	}

	fori(i, 0, m) {
		int u, v;
		scanf("%d %d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	int ans = 0;
	fori(i, 1, n + 1) {
		if(!visited[i]) {
			set<int> guys;
			dfs(i, guys);
			set<int> sons;
			for(auto &each : guys) {
				sons.insert(arr[each]);
			}
			vector<int> fodase;
			set_intersection(guys.begin(), guys.end(), sons.begin(), sons.end(), back_inserter(fodase));
			ans += fodase.size();
		}
	}

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

	return 0;
}


Measured memory_bytes: 19196
import java.util.*;
import java.util.stream.Stream;

public class Main {//ここが Main になっている
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String line1, line2;
        int[] k_n_array = new int[2];
        line1 = sc.nextLine();
        line2 = sc.nextLine();
        String[] k_n_s = line1.split(" ");
        int K = Integer.parseInt(k_n_s[0]);
        int N = Integer.parseInt(k_n_s[1]);

        k_n_s = line2.split(" ");
        // System.out.println(Arrays.asList(k_n_s));
        int[] A_int = Stream.of(k_n_s).mapToInt(Integer::parseInt).toArray();
        // System.out.println(A_int.length);
        int[] diff_A = new int[A_int.length];
        for (int i=0;i<A_int.length-1;i++){
            diff_A[i] = A_int[i+1] - A_int[i];
        }
        diff_A[A_int.length-1] = K - A_int[A_int.length-1] + A_int[0];

        int max = diff_A[0];
        int min = diff_A[1];
        for (int i = 1; i < diff_A.length; i++) {
            int v = diff_A[i];
            if (v > max) {
                max = v;
            }
            if (v < min) {
                min = v;
            }
        }
        System.out.println(K - max);

    }
}




// Scanner sc = new Scanner(System.in);
// String line1, line2;
// int[] k_n_array = new int[2];
// line1 = sc.nextLine();
// line2 = sc.nextLine();
// String[] k_n_s = line1.split(" ");
// int K = Integer.parseInt(k_n_s[0]);
// int N = Integer.parseInt(k_n_s[1]);
//
// // System.out.println(K+" "+N);
//
// k_n_s = line2.split(" ");
// // System.out.println(Arrays.asList(k_n_s));
// int[] A_int = Stream.of(k_n_s).mapToInt(Integer::parseInt).toArray();
// int ist_most_large = 1;
// // System.out.println(A_int.length);
//
// while (true) {
//     int now_distance = A_int[A_int.length - ist_most_large] - A_int[0];
//     // System.out.println(now_distance);
//     ist_most_large++;
//     if (ist_most_large >= A_int.length){
//         System.out.println(now_distance);
//         break;
//     }
//     int next_distance = K - A_int[A_int.length - ist_most_large] + A_int[0];
//     if (next_distance >= now_distance){
//       System.out.println(now_distance);
//       break;
//     }
//     else{
//         now_distance = next_distance;
//         // break;
//     }
//
// }


Measured memory_bytes: 58612
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

/*!
@fn gcd
@brief gcd(x, y)
*/
template<class T>
T gcd(T x, T y)
{
    if (x < y) {
        swap(x, y);
    }

    if (y == 0) {
        return x;
    }

    do
    {
        T r = x % y;
        x = y;
        y = r;
    } while (y);

    return x;
}

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

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

    int ans = abs(x[0] - X);
    for (int i = 1; i < N; ++i) {
        ans = gcd(ans, abs(x[i] - X));
    }

    cout << ans << endl;

    return 0;
}


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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }

using namespace std;

int main(int argc, char** argv) 
{
#ifdef HOME
	if(IsDebuggerPresent())
	{
		freopen("../in.txt", "rb", stdin);
		freopen("../out.txt", "wb", stdout);
	}
#endif
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout << fixed;
	int N;
	cin >> N;
	vector<int> a(N);
	int su = 0;
	forn(i, N)
	{
		cin >> a[i];
		su ^= a[i];
	}
	forn(i, N)
	{
		cout << (su ^ a[i]) << " ";
	}
	cout << endl;

	return 0;
}


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

int main() {
  int A, B, C, D;
    cin >> A >> B >> C >> D;
  if ( A + B == C + D ) {
    cout << "Balanced" << endl;
  }else if( A + B > C + D ){
    cout << "Left" << endl;  
  }else if( A + B < C + D){
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 3560
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		n: usize,
		a: [usize; n],
	}

	// 2の倍数でない
	// 2
	// 4の倍数

	let mut count4 = 0;
	let mut count2 = 0;
	let mut count0 = 0;
	for i in 0..n {
		if a[i] % 4 == 0 {
			count4 += 1;
		}
		else if a[i] % 2 == 0 {
			count2 += 1;
		}
		else {
			count0 += 1;
		}
	}

	if count2 > 0 {
		count0 += 1;
	}
	if count0 <= count4 + 1 {
		println!("Yes");
	}
	else {
		println!("No");
	}
}



Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;

long long n, s;

int main() {
    cin >> n >> s;
    if (n < s)  {cout << -1 << endl; return 0;}
    if (n == s) {cout << n + 1 << endl; return 0;}
    
    long long b = 2;
    for (; b * b <= n; b++) {
        long long tmp = n, f = 0;
        while (tmp > 0) {
            f += tmp % b;
            tmp /= b;
        }
        if (f == s) {cout << b << endl; return 0;}
    }
    
    //nはb進数で2ケタ: n = pb+q かつ s = p+q
    if (b * b == n) --b;
    for (long long p = b; p > 0; p--) {
        if (s < p) continue;
        long long q = s - p;
        if ((n - q) % p == 0) {
            b = (n - q) / p;
            if ( p < b && q < b) {
                cout << (n - q) / p << endl;
                return 0;
            }
        }
    }
    cout << -1 << endl;
}






Measured memory_bytes: 256
MODULE strQsortMod
      implicit none
      
      integer(16),parameter,private :: charLen = 10
      
      contains
      
      recursive function qSort( s ) result( r )
        implicit none
        character(charLen),intent(in) :: s(:)
        character(charLen),allocatable :: r(:)
        character(charLen) :: sample(3),buffer
        integer(16) :: len,i,j
        
        len = size( s(:) )
        if( len>1 )then
          !select pivot
          sample(1) = s(1)
          sample(2) = s(len/2)
          sample(3) = s(len)
          do i = 1,2
            do j = 2,3
              if( sample(i)>sample(j) )then
                buffer = sample(i)
                sample(i) = sample(j)
                sample(i) = buffer
              end if
            end do
          end do
          
          
          r = [ qSort( pack(s(:),s(:)< sample(2)) ), &
                       pack(s(:),s(:)==sample(2))  , &
                qSort( pack(s(:),s(:)> sample(2)) ) ]
          else
            r = s
          end if
        end function
      
      
      end MODULE
      
      
      PROGRAM gacha
      use strQsortMod
      IMPLICIT NONE
      integer(16) :: n,i ,ans = 1
      character(10),allocatable :: s(:)
      character(10) :: buffer
      
      read*,n
      allocate(s(n))
      do i = 1,n
        read*,s(i)(:)
      end do
      
      s = qSort( s )
      
      
      buffer = s(1)
      do i = 2,n
        if( buffer/=s(i) )then
          ans = ans + 1
          buffer = s(i)
        end if
      end do
      
      print*,ans
      
      END PROGRAM

Measured memory_bytes: 13236
#include<stdio.h>
#include<math.h>
#include <stdlib.h>

int main (void)
{
	int top_forward[6][6] =
	{
		{0,3,5,2,4,0},
		{4,0,1,6,0,3},
		{2,6,0,0,1,5},
		{5,1,0,0,6,2},
		{3,0,6,1,0,4},
		{0,4,2,5,3,0}
	};
	int dice[6];
	int com_num,top,forward,top_num,forward_num;
	int i,j;

	scanf("%d %d %d %d %d %d",&dice[0],&dice[1],&dice[2],&dice[3],&dice[4],&dice[5]);
	scanf("%d",&com_num);
	
	for(i = 0 ; i < 6 ; i++)
	{
		for(j = 0 ; j < 6 ; j++)
		{
			switch(top_forward[i][j])
			{
				case 0:
					break;
				case 1:
					top_forward[i][j] = dice[0];
					break;
				case 2:
					top_forward[i][j] = dice[1];
					break;
				case 3:
					top_forward[i][j] = dice[2];
					break;
				case 4:
					top_forward[i][j] = dice[3];
					break;
				case 5:
					top_forward[i][j] = dice[4];
					break;
				case 6:
					top_forward[i][j] = dice[5];
					break;
			}
		}
	}
	
	for(i = 0 ; i < com_num ; i++)
	{
		scanf("%d %d",&top,&forward);
		for(j = 0 ; j < 6 ; j++)
		{
			if(top == dice[j])
			{
				top_num = j;
			}
			if(forward == dice[j])
			{
				forward_num = j;
			}
		}
		printf("%d\n",top_forward[top_num][forward_num]);
	}
	
	return 0;
}


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

class Guruguru
{
public:
  Guruguru(int n);
  ~Guruguru();

  void Show();

private:
  char** m_guruguru;
  int m_n;
  int m_now_i;
  int m_now_j;
  int m_direction;    //  0:上 1:右 2:下 3:左

  void make_guruguru();
  void put_point();
  void move_point();
  void change_direction();
  bool check_point();
};

Guruguru::Guruguru(int n)
{
  m_n = n;
  m_guruguru = new char*[m_n];
  for (int i=0; i<m_n; i++)
  {
    m_guruguru[i] = new char[m_n];
  }

  for (int i=0; i<n; i++)
  {
    for (int j=0; j<n; j++)
    {
      m_guruguru[i][j] = ' ';
    }
  }

  m_now_i = m_n-1;
  m_now_j = 0;
  m_direction = 0;
  make_guruguru();
}

Guruguru::~Guruguru()
{
  for (int i=0; i<m_n; i++)
  {
    delete[] m_guruguru[i];
  }
  delete[] m_guruguru;
}

void Guruguru::make_guruguru()
{
  int num = 0;
  while(true)
  {
    put_point();
    if (! check_point() )
    {
      if ( num == m_n-1 ) return;
      change_direction();
      num++;
    }
    move_point();
  }
}

void Guruguru::put_point()
{
  m_guruguru[m_now_i][m_now_j] = '#';
}

void Guruguru::move_point()
{
  switch(m_direction)
  {
  case 0:
    m_now_i--;
    break;
  case 1:
    m_now_j++;
    break;
  case 2:
    m_now_i++;
    break;
  case 3:
    m_now_j--;
    break;
  }
}

void Guruguru::change_direction()
{
  switch(m_direction)
  {
  case 3:
    m_direction = 0;
    break;
  default:
    m_direction++;
    break;
  }
}

bool Guruguru::check_point()
{
  int next_i = m_now_i;
  int next_j = m_now_j;
  int next_next_i = next_i;
  int next_next_j = next_j;
  switch(m_direction)
  {
  case 0:
    next_i--;
    next_next_i-=2;
    break;
  case 1:
    next_j++;
    next_next_j+=2;
    break;
  case 2:
    next_i++;
    next_next_i+=2;
    break;
  case 3:
    next_j--;
    next_next_j-=2;
    break;
  }
  if ( next_i < 0 || m_n <= next_i || next_j < 0 || m_n <= next_j )
  {
    return false;
  }
  else if ( next_next_i < 0 || m_n <= next_next_i || next_next_j < 0 || m_n <= next_next_j )
  {
    return true;
  }
  else
  {
    if ( '#' == m_guruguru[next_next_i][next_next_j] )
    {
      return false;
    }
    return true;
  }
}

void Guruguru::Show()
{
  for (int i=0; i<m_n; i++)
  {
    for (int j=0; j<m_n; j++)
    {
      cout << m_guruguru[i][j] << flush;
    }
    cout << endl;
  }
}

int main()
{
  int d;  //  データセットの個数
  cin >> d;
  for (int dataset=0; dataset<d; dataset++)
  {
    int n;  //  辺の長さ
    cin >> n;
    Guruguru guruguru(n);

    guruguru.Show();
    if (! (dataset == d-1))
    {
      cout << endl;
    }
  }
}

Measured memory_bytes: 1204
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

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

int main() {
    int n;
    cin >> n;
    auto dp = make_v(n+1, 5, 5, 5, 5, 0);
    dp[0][0][0][0][0] = 1;
    auto dis = make_v(5, 5, 5, 5, 1);
    for (int i = 0; i <= 4; ++i) {
        dis[i][1][3][2] = 0;
        dis[i][3][1][2] = 0;
        dis[i][1][2][3] = 0;
        dis[1][i][3][2] = 0;
        dis[1][3][i][2] = 0;
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 5; ++j) {
            for (int k = 0; k < 5; ++k) {
                for (int l = 0; l < 5; ++l) {
                    for (int m = 0; m < 5; ++m) {
                        for (int x = 1; x < 5; ++x) {
                            if(dis[k][l][m][x]){
                                (dp[i+1][k][l][m][x] += dp[i][j][k][l][m]) %= MOD;
                            }
                        }
                    }
                }
            }
        }
    }
    int ans = 0;
    for (int j = 0; j < 5; ++j) {
        for (int k = 0; k < 5; ++k) {
            for (int l = 0; l < 5; ++l) {
                for (int m = 0; m < 5; ++m) {
                    (ans += dp[n][j][k][l][m]) %= MOD;
                }
            }
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
 ll n,m;
 cin>>n>>m;
 vector<mp> ans;
 if( n % 2 == 0 ){
  ll s=1,t=n/2;
  //ans.push_back( mp( s,t ) );
  while(s<t){
   ans.push_back( mp(s,t) );
   s++,t--;
  }
  s = n/2+2,t=n;
  while(s<t){
   ans.push_back( mp(s,t) );
   s++,t--;
  }
 }else{
  ll s=1,t=n;
  while(s<t){
   ans.push_back( mp(s,t) );
   s++,t--;
  }
 }
 for(ll i=0;i<m;i++)cout<<ans[i].first<<' '<<ans[i].second<<endl;
    return 0;
}


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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) {
        ll d = euclid(b, a % b, y, x);
        return y -= a / b * x, d;
    }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1)
            ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1);
        return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e)
            return Mod(1);
        Mod r = *this ^ (e / 2);
        r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);

    cin >> skipws;

    for (;;) {
        int n;
        cin >> n;
        if (!n)
            break;

        int l = 0, r = 0, ns = 1;

        int ans = 0;
        rep(i, 0, n) {
            string s;
            cin >> s;
            if (s == "lu")
                l = 1;
            if (s == "ru")
                r = 1;
            if (s == "ld")
                l = 0;
            if (s == "rd")
                r = 0;

            if (l == r && r == ns)
                ans++, ns ^= 1;
        }
        cout << ans << endl;
    }
}


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

int main() {
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    int d[100001];
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> d[i];
    }
    sort(d, d + n);

    cout << d[n / 2] - d[n / 2 - 1] << '\n';

    return 0;
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int ans = min(a, b) + min(c, d);
  
  cout << ans << endl;
    
  
  return 0;
}


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

int buck1[300000],buck2[300000],n,m;

int main(){
	scanf("%d",&n);
	for(int i = 1;i <= n;i++) cin >> buck1[i];
	scanf("%d",&m);
	for(int i = 1;i <= m;i++) cin >> buck2[i];
	sort(buck1+1,buck1+1+n);
	sort(buck2+1,buck2+1+m);
	
	int pos = 1;
	for(int i = 1;i <= n && pos <= m;i++){
		if(buck1[i] == buck2[pos]) pos++;
	}
	
	if(pos > m) printf("YES");
	else printf("NO");
	
	return 0;
}

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

using namespace std;

typedef long long Int;
typedef unsigned long long uInt;

int cnt[256000];

int main()
{
	int n, k, x0;

	scanf("%d %d %d", &n, &k, &x0);

	if (x0 == 0) return (!printf("0\n"));

	Int width = LLONG_MAX / 100000;
	uInt x = x0;
	for (int i = 0; i < n; i++){
		cnt[(uInt)((Int)x - LLONG_MIN) / width]++;
		x ^= x << 13;
  		x ^= x >> 7;
  		x ^= x << 17;
	}

	int sum = 0;
	for (int i = 0; i < 256000; i++){
		sum += cnt[i];
		if (sum < k) continue;
		vector<Int> a;
		
		x = x0;
		for (int j = 0; j < n; j++){
			Int xd = (Int)x;
			if ((uInt)((Int)x - LLONG_MIN) / width == i) a.push_back(xd);
			x ^= x << 13;
	  		x ^= x >> 7;
  			x ^= x << 17;
		}
		sort(a.begin(), a.end());
		printf("%lld\n", a[k - (sum - cnt[i]) - 1]);
		return (0);
	}

	return (-1);
}

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

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

    bool check;
    for (int i = 1; i < 10; i++) {
        check = false;
        for (int j = 1; j < 10; j++) {
            if (n == i * j) {
                check = true;
                break;
            }
        }
        if (check == true) break;
    }

    if (check == true) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3604