akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;

const ll MOD = 1000000007;
template <typename T>
using vec = std::vector<T>;

struct mint {
    ll x;
    mint(ll x = 0) : x((x % MOD + MOD) % MOD) {
    }
    mint operator-() const {
        return mint(-x);
    }
    mint &operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint &operator-=(const mint a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint &operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t / 2);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime MOD
    mint inv() const {
        return pow(MOD - 2);
    }
    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

ostream &operator<<(ostream &os, const mint &a) {
    return os << a.x;
}

int main() {
    int N;
    cin >> N;
    vec<map<string, mint>> dp(101, map<string, mint>());
    map<string,bool> mp;
    string S = "ACGT";
    smatch smatch;
    for (auto i : S)
        for (auto j : S)
            for (auto k : S)
                for (auto l : S) {
                    string s = "";
                    s += i;
                    s += j;
                    s += k;
                    s += l;
                    dp[0][s] = 0;
                    mp[s] = regex_search(s, smatch, regex("AGC|ACG|GAC|A.GC|AG.C"));
                }
    dp[0]["TTTT"] = 1;

    ll now = 0;
    for (int i = 0; i < 100; ++i)
        for (auto d : dp[i]) {
            string ds = d.first;
            for (auto e : S) {
                ++now;
                string s = ds.substr(1) + e;
                if (!mp[s])
                    dp[i + 1][s] += dp[i][ds];
                else
                    dp[i + 1][s] = 0;
            }
        }

    mint ans = 0;
    for (auto e : dp[N]) {
        ans += e.second;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using namespace boost::multiprecision;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPI(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define ALL(x) (x).begin(),(x).end()

int main () {
  int n, count, breakest;
  int mymax = 0;
  cin >> n;

  REP(i, n) {
    int acc = i+1;
    for(count = 0; acc > 0 && acc % 2 == 0; count++) {
      acc /= 2;
    }

    mymax = max(mymax, count);
    if(count == mymax) breakest = i+1;
  }

  cout << breakest << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{
    string S;
    cin >> S;
    int a = S.length();
    string ans(a,'x');
    cout << ans << endl;

    
    
    
    

    return 0;
}


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

using namespace std;

#define si(a) scanf("%d",&a)

deque<int> Q;

int main()
{
    int i,n,x;
    si(n);
    for(i=0;i<n;i++){
        si(x);
        if(i%2)Q.push_back(x);
        else Q.push_front(x);
    }
    if(n%2==0){
        for(i=0;i<n;i++){
            if(i)printf(" ");
            printf("%d",Q.back());
            Q.pop_back();
        }
        printf("\n");
    }
    else{
        for(i=0;i<n;i++){
            if(i)printf(" ");
            printf("%d",Q.front());
            Q.pop_front();
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2944
import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
	int a = Integer.parseInt(scan.next());
	int b = Integer.parseInt(scan.next());
	int c = Integer.parseInt(scan.next());

	int total = a + b + c;
	boolean ans = (total - a == a) || (total - b == b) || (total - c == c);

	System.out.println(ans ? "Yes" : "No");
	scan.close();
    }
}


Measured memory_bytes: 21844
import bisect
N, Q = map(int, input().split())
S = list(input())
lr = [list(map(int, input().split())) for i in range(Q)]

alst,clst=[],[]
for i in range(N-1):
    if S[i]=="A" and S[i+1]=="C":
        alst.append(i)
        clst.append(i+1)


for j in range(Q):
    l,r = lr[j][0]-1, lr[j][1]-1
    ans = bisect.bisect_right(clst,r) - bisect.bisect_left(alst,l)
    print(ans)


Measured memory_bytes: 32980
import sys

N = int(input())
S = input()

W = [0]*N
E = [0]*N
ans = N
for i in range(1, N):
    W[i] = W[i-1]+1 if S[i-1]=='W' else W[i-1]
    E[-i-1] = E[-i]+1 if S[-i]=='E' else E[-i]

for i in range(N):
    ans = min(W[i]+E[i], ans)

print(ans)





Measured memory_bytes: 23464
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define min(p,q)((p)<(q)?(p):(q))
#define zahyoutype long

typedef struct Point{zahyoutype x,y;}P;
zahyoutype crossproduct(P p,P q,P o){return (p.x-o.x)*(q.y-o.y)-(p.y-o.y)*(q.x-o.x);}
int sgn(zahyoutype x){return x<0?-1:x>0;}
void readpoint(P*p){zahyoutype x=1;scanf(x/2?"%lf%lf":"%ld%ld",&p->x,&p->y);}

P p[110];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)readpoint(p+i);
	int flag[3]={};
	for(int i=0;i<n;i++)flag[sgn(crossproduct(p[(i+1)%n],p[i],p[(i+n-1)%n]))+1]++;
	printf("%d\n",!(flag[0]&&flag[2]));
}


Measured memory_bytes: 2148
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=1e5+9;
int main()
{
    FASTINOUT;
    int x;
    cin>>x;
    cout<<x/3;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define INF 10000000000

ll a, b, c, n, x, y, z, w, h, ans = 0, cnt = 0, mx = 0, mn = INF;
string s;

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

    vector<vector<ll>> board(3, vector<ll>(3));
    rep(i, 3){
        rep(j, 3){
            cin >> board[i][j];
        }
        mn = min({board[i][0], board[i][1], board[i][2]});
        rep(j, 3){
            board[i][j] -= mn;
        }
    }
    if(!equal(all(board[1]), all(board[2])) || !equal(all(board), all(board))){
        cout << "No" << endl;
        return 0;
    }
    rep(j, 3){
        mn = min({board[0][j], board[1][j], board[2][j]});
        rep(i, 3){
            board[i][j] -= mn;
        }
    }
    rep(j, 3){
        if(board[0][j] != board[1][j] || board[1][j] != board[2][j]){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,i,sum;
	while(1){
		scanf("%d",&sum);
		if(sum==0){
			break;
		}
		for(i=1;i<=9;i++){
			scanf("%d",&a);
			sum=sum-a;
		}
		printf("%d\n",sum);
	}
	return 0;
}



Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	int n;
	cin >> n;
	int x = n / 1000;
	if (x * 1000 < n)
		x ++;
	cout << x * 1000 - n << '\n';
	return 0;
}

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

#define int long long
#define sz(x) (int)(x.size())

const int N = 450;
int n;
int a[N], dp[N][N], sum[N];

int solve(int l, int r){
    if(dp[l][r] != -1){
        return dp[l][r];
    }
    if(l == r){
        return dp[l][r] = 0;
    }
    int ans = INT64_MAX;
    for(int i = l; i < r; i++){
        int sm = (l == 0 ? sum[r] : sum[r] - sum[l - 1]);
        ans = min(ans, solve(l, i) + solve(i + 1, r) + sm);
    }
    return dp[l][r] = ans;
}

signed main(){
    ios::sync_with_stdio(false);
    memset(dp, -1, sizeof dp);
    cin >> n;
    for(int i = 0;i < n; i++) {
        cin >> a[i];
    }
    sum[0] = a[0];
    for(int i = 1;i < n;i++){
        sum[i] = sum[i - 1] + a[i];
    }
    cout << solve(0, n - 1) << "\n";
}

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

int main() {
  LL n, m;
  cin >> n >> m;
  LL ans;
  if (n == 1 && m == 1) {
    ans = 1;
  } else if (n == 1 || m == 1) {
    ans = max(n, m) - 2;
  } else {
    ans = (n - 2) * (m - 2);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
from collections import deque



# for #!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
from bisect import bisect_left as bl
from math import log2,ceil
from heapq import heappush, heappop
from itertools import permutations 
def main():
    # for t in range(int(input())):
        n = int(input())
        # d = dict()
        l = [int(j) for j in input().split()]
        l.sort(reverse=True)
        ans = l[0]
        j = 1
        for i in range((n-2)//2):
            # print(i)
            ans+=l[j]*2
            j+=1
        # print(ans)
        if n%2==1:
            ans+=l[j]
        print(ans)

            # heappush(h, l[i])

        


        
        




# endregion

if __name__ == "__main__":
    main()



Measured memory_bytes: 104524
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

long long gcd(long long a, long long b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}

long long lcm(long long a, long long b)
{
	return a * b / gcd(a, b);
}

int main()
{
	long long a, b;
	cin >> a >> b;
	long long ans = lcm(a, b);
	cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, n;
  cin >> a >> b >> c >> n;
  int ret = 0;
  for (int i = 0; i * a <= n; i++) {
    for (int j = 0; i * a + j * b <= n; j++) {
      if ((n - (i * a + j * b)) % c) continue;
      ret++;
    }
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream> 
#include <sstream> // istringstream
#include <string> // 文字列
#include <algorithm> // アルゴリズム
#include <cmath> // 
#include <vector> // vector
#include <set> // set
#include <map> // map

using namespace std;

int main()
{   
    // input sample
    long long N; 
    cin >> N;
    string s;
    cin >> s;

    long long cnt = 0;
    long long i;
    // 時間を節約するために右端を記録
    long long right = N-1;
    long long left = 0;
    for (i = 0; i < N-1; ) {
        // cout << i << " " << s.substr(i, 2) << " " << s << endl;
        if (s.substr(i, 2) == "WR") {
            for (long long j = right; j >= i+1; --j) {
                // これが右端の場合色を変更する
                if (j == i+1) {
                    s[j] = 'W';
                    // s[j-1] = 'R';
                    cnt++;
                    right = j-1;
                    break;
                }
                // 一番右にあるRと交換
                if (s[j] == 'R') {
                    right = j-1;
                    for (long long k = left; k <= j; ++k) {
                        if (s[k] == 'W') {
                            s[k] = 'R';
                            s[j] = 'W';
                            left = k;
                            cnt++;
                            break;
                        }
                    }
                    break;
                }
            }
            if (i != 0) {
                i -= 1;
            }
        } else {
            i += 1;
        }
    } 

    // 連続したWWRの場合先頭のWと交換すべきだった


    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
using P = pair<ll, ll>;
using Vec = vector<ll>;
#define FOR(i, m, n) for(ll (i) = (m); (i) < (n); (i)++)
#define FORN(i, m, n) for(ll (i) = (m); (i) <= (n); (i)++)
#define FORR(i, m, n) for(ll (i) = (m); (i) >= (n); (i)--)
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FORN(i, 1, n)
#define repr(i, n) FORR(i, n, 0)
#define repnr(i, n) FORR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second

const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll n, k;
	cin >> n >> k;
	Vec a(n+1);
	repn(i, n) cin >> a[i];
	Vec s(n+1);
	repn(i, n) s[i] = (s[i-1]+a[i]-1)%k;

	map<ll, ll> mp;
	mp[0] = 1;
	ll ans = 0;
	repn(i, n){
		if(i >= k) mp[s[i-k]]--;
		ans += mp[s[i]]++;
	}
	co(ans);

	return 0;
}


Measured memory_bytes: 15872
# include <bits/stdc++.h>
# define pb push_back
# define ll long long
# define fi first
# define se second
# define all(vc) vc.begin(),vc.end()
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
# define DEBUG

using namespace std;

const ll N = 1e5 + 7;
const ll mod = 1e18 + 7;

ll n, ans;

int main()
{
    speed;
    /// Author: Dilshod--Imomov
    #ifdef DEBUGn
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif // DEBUG
    cin >> n;
    ans = n - 1;
    ans *= n;
    ans /= 2;
    cout << ans;
}


Measured memory_bytes: 384
#include<stdio.h>
int main()
{
double A,B;
scanf("%lf",&A);
scanf("%lf",&B);
if(A>B)
{
printf("GREATER");
} 
else if(A==B)
{
printf("EQUAL");
}
else	
{
printf("LESS");
}
return 0;
} 

Measured memory_bytes: 128
S = gets

a = S[0..1].to_i
b = S[2..3].to_i
mmyy = 0 < a && a <= 12
yymm = 0 < b && b <= 12

puts(
  if yymm && mmyy
    'AMBIGUOUS'
  elsif yymm
    'YYMM'
  elsif mmyy
    'MMYY'
  else
    'NA'
  end
)


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

using pii = pair<int,int>;
using ll = __int128_t;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {
        ll T1, T2, A1, A2, B1, B2;
        {
            long long t1, t2, a1, a2, b1, b2;
            cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
            T1 = t1; T2 = t2; A1 = a1; B1 = b1; A2 = a2; B2 = b2;
        }

        if(A1 < B1) {
            swap(A1, B1);
            swap(A2, B2);
        }

        ll tx_t1 = T1 * A1;
        ll ax_t1 = T1 * B1;

        ll tx_t2 = T1 * A1 + T2 * A2;
        ll ax_t2 = T1 * B1 + T2 * B2;

        ll diff = ax_t2 - tx_t2;


        if(diff == 0) {
            cout << "infinity" << endl;
            return 0;
        }

        bool col = tx_t1 > ax_t1 and tx_t2 <= ax_t2;
        if(not col) {
            cout << 0 << endl;
            return 0;
        }
        assert(A1 > B1 and A2 < B2);

        assert(diff >= 0);



        ll cnt = max<ll>(0, (tx_t1 - ax_t1) / diff - 5);

        ll ans = max<ll>(cnt * 2 - 1, 0); // cnt - 1 サイクルは成功する

        for(ll c = cnt;; c++) {
            ll ds = diff * c;

            ll tx_t1 = T1 * A1;
            ll ax_t1 = T1 * B1 + ds;

            if(ds > 0 and tx_t1 >= ax_t1) ans++;
            else if(ds > 0) break;

            if(tx_t1 == ax_t1) break;

            ll tx_t2 = T1 * A1 + T2 * A2;
            ll ax_t2 = T1 * B1 + T2 * B2 + ds;
            if(tx_t1 >= ax_t1 and tx_t2 < ax_t2) ans++;
            else if(tx_t1 > ax_t1 and tx_t2 <= ax_t2) ans++;
            else break;

            if(tx_t2 == ax_t2) break;
        }

        long long ans2 = ans;
        cout << ans2 << endl;

        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


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

int main()
{
  int n;
  cin >> n;
  int a,b,c,d;

  a = n/25;
  b = n%25/10;
  c = (n-a*25-b*10)/5;
  d = n%5;
  
  cout << a+b+c+d << endl;
  return 0;
}


Measured memory_bytes: 3124
#include<iostream>
using namespace std;
int main(){
  int E,Y;
  cin>>E>>Y;
  if(E==0){
    if((1868<=Y)&&(Y<=1911))
      cout<<'M'<<Y%1867<<endl;
    if((1912<=Y)&&(Y<=1925))
      cout<<'T'<<Y%1911<<endl;
    if((1926<=Y)&&(Y<=1988))
      cout<<'S'<<Y%1925<<endl;
    if((1989<=Y)&&(Y<=2016))
      cout<<'H'<<Y%1988<<endl;
  }
  if(E==1){
    cout<<1867+Y<<endl;
  }
  if(E==2){
    cout<<1911+Y<<endl;
  }
  if(E==3){
    cout<<1925+Y<<endl;
  }
  if(E==4){
    cout<<1988+Y<<endl;
  }
  return 0;
}



Measured memory_bytes: 3084
#include "bits/stdc++.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define repr(i,a,n) for(ll i = n-1;i >= a;i--)
#define LINF (ll)1e17
#define INF 1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second
#define setprecision(d) cout << fixed << setprecision(d);

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
	
}

ll lcm(ll a,ll b){
	return a * b / gcd(a,b);
}

signed main(){
	ll n,memo = 0,ans = 1;
	cin >> n;
	ll d[n];
	ll cnt[n] = {};

	rep(i,0,n){
		cin >> d[i];
		cnt[d[i]]++;

		memo = max(d[i],memo);

		if(d[0] != 0 || (d[i] == 0 && i != 0)){
			cout << 0 << endl;
			return 0;
		}
	}

	rep(i,0,memo){
		rep(j,0,cnt[i+1]){
			ans *= cnt[i];
			ans %= 998244353;
		}
	}

	cout << ans << endl;

	
    return 0;
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		
		
		int[] arr = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
		int k = fs.nextInt() - 1;
		
		System.out.println(arr[k]);
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
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()

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

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

#define MAX_N 100009

int N, T;
int A[MAX_N];
int min_A[MAX_N];
int max_A[MAX_N];
map<int, vector<p> > ans;
unordered_map<int, int> cnt;
int main(){
    ios::sync_with_stdio(false);
    cin >> N >> T;
    REP(i,N) cin >> A[i];
    int min_a = INF;
    int max_a = 0;
    REP(i,N) {
        min_a = min(min_a,A[i]);
        max_a = max(max_a,A[i]);
        min_A[i] = min_a;
        max_A[i] = max_a;
    }
    REP(i,N) {
        ans[A[i]-min_A[i]].pb( p(i,min_A[i]) );
    }
    
    auto itr = ans.end();
    itr--;
    pair<int, vector<p> > l = *itr;
    cout << l.second.size() << endl;
    
    return 0;
}

Measured memory_bytes: 12416
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    set<string> se;
    while(n--) {
        string order;
        cin >> order;
        string s;
        cin >> s;
        if(order == "insert") {
            se.insert(s);
        } else {
            if(se.find(s) == se.end()) {
                cout << "no" << '\n';
            } else {
                cout << "yes" << '\n';
            }
        }
    }
}


Measured memory_bytes: 29032
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())

typedef long long ll;

string S, R;
ll K;

void rep(ll cnt){
  R = "";
  for(int i=0; i<cnt; i++)
    R += S;
}

ll calc(){
  ll cnt = 0;
  for(int i=1; i<sz(R); i++){
    if(R[i] == R[i-1]){
      cnt++;
      i++;
    }
  }
  return cnt;
}

int main(){
  cin >> S >> K;
  if(K < 10){
    rep(K);
    ll res = calc();
    cout << res << endl;
    return 0;
  }
  ll a = 2+ (K%2);
  ll b = a+2;
  rep(a);
  ll cnta = calc();
  rep(b);
  ll cntb = calc();
  ll res = cnta + (K-a)/2 * (cntb-cnta);
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int a,b;
	std::cin >> a >> b;
	print(std::max(a-2*b,0ll));
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main() {
    ll N,M,s;
    cin>>N>>M;
    bool flag=false;
    vector<vector<ll>> data(M,vector<ll>(2));
    vector<ll> a,b;    
    rep0(i,M){cin>>data[i][0]>>data[i][1];}
    rep0(i,M){
        if(data[i][0]==1){
            a.push_back(data[i][1]);
        }
        if(data[i][1]==N){
            b.push_back(data[i][0]);
        }
        
    }
    if(b.size()==0){goto SKIP;}
    sort(all(a)); sort(all(b));
    rep0(i,a.size()){

        s=*lower_bound(b.begin(),b.end(),a[i]);
        if(s==a[i]){flag=true;}
    }
    SKIP:
    if(flag){cout<<"POSSIBLE"<<endl;}
    else{cout<<"IMPOSSIBLE"<<endl;}
}


Measured memory_bytes: 12872
#include <iostream>
#include <string>
#define MAXN 200000
using namespace std;
int main(){
	int N, K, C;
	string s;
	int bk[MAXN];
	cin >> N >> K >> C >> s;
	int last = s.size()+C;
	for(int i=s.size()-1; i>=0; i--)
		if(s[i] == 'o' && last > i+C)
			bk[last=i] = K--;
	//for(int i=0; i<s.size(); i++)
		//cout << bk[i] << " ";
	//cout << endl;
	K = 1;
	last = -C-1;
	for(int i=0; i<s.size(); i++)
		if(s[i] == 'o' && last < i-C)
			if(K++ == bk[last=i])
				cout << i+1 << endl;
}







Measured memory_bytes: 2564
#include<iostream>

using namespace std;

long long gcd(long long x, long long y){
  while(y){
    long long t = x%y;
    x=y;
    y=t;
  }
  return x;
}

int main(){
  long long A, B;
  cin >> A >> B;
  int ans = 1;

  long long g = gcd(A,B);

  for (long long i = 2; i * i <= g; i++){
    if (g%i != 0) continue;
    while (g%i == 0){
      g /= i;
    }
    ans++;
  }
  if (g != 1) ans++;
  
  printf("%d\n", ans);
  
}


Measured memory_bytes: 3724
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

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

ll gcd(ll x,ll y){
    while(y > 0){
        ll tmp = y;
        y = x % y;
        x = tmp;
    }
    return x;
}

ll lcm(ll x, ll y){
    return x / gcd(x,y) * y;
}

int main(){
    ll K;
    cin>>K;
    ll ans = 0;
    rep(i,1,K+1)rep(j,i,K+1)rep(k,j,K+1){
        if(i == j && j == k)ans += gcd(i,gcd(j,k));
        else if(i == j || j == k || k == i){
            ans += gcd(i,gcd(j,k))*3;
        }
        else ans += gcd(i,gcd(j,k))*6;
    }
    cout<< ans;
    return 0;
}

Measured memory_bytes: 3636
//#include <bits/stdc++.h>
#include <stack>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	//入力
	bool flag=true;
	long a[100000], b[100000], x[100000] = {};
	long N, X, M = 1000000000, ans = 0, count = 0;
	cin >> N >>X;
	ans = N+1;
	for (int i = 0; i < N; i++) {
		cin >> M;
		count += M;
		if (flag && count > X) {
			ans = i + 1; flag = false;}
	}
	//処理
	//出力
	cout << ans << endl;
}

Measured memory_bytes: 256
/*
  AUTHOR:SOURABH
  CREATED:07:03:20
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<ll , null_type, less< ll >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 1000000007
#define MAX 100005
#define M 32

using namespace std;
using namespace __gnu_pbds;

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

    //freopen("in.txt","r",stdin);
    //freopen(2 "out.txt","w",stdout);

    ll t,n,a,b,q,r,ans;
    t=1;
    //cin>>t;
    W(t--)
    {
        cin>>n>>a>>b;
        ans=0;
        q=n/(a+b);
        r=n%(a+b);
        ans=q*a;
        ans+=min(r,a);
        cout<<ans;
    }
    return 0;
}













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

using namespace std;

struct Square
{
    int x, y;
    int cost;

    int Points(const Square &other) const
    {
        return abs(x - other.x) + abs(y - other.y);
    }
};

int main()
{
    int rows, cols, step;
    cin >> rows >> cols >> step;

    vector<Square> squares(rows * cols);
    for (int i = 0; i < rows; i += 1) {
        for (int j = 0; j < cols; j += 1) {
            int num;
            cin >> num;
            squares[num - 1] = Square { .x = i, .y = j };
        }
    }

    for (int i = 0; i < rows * cols; i += 1) {
        if (i < step) {
            squares[i].cost = 0;
        } else {
            int points = squares[i].Points(squares[i - step]);
            squares[i].cost = squares[i - step].cost + points;
        }
    }

    int tests;
    cin >> tests;

    for (int i = 0; i < tests; i += 1) {
        int left, right;
        cin >> left >> right;

        left -= 1;
        right -= 1;

        int res = squares[right].cost - squares[left].cost;
        cout << res << "\n";
    }

    return 0;
}


Measured memory_bytes: 2176
A, B, C, X, Y = map(int, input().split())

if A+B > 2*C:
    if X-Y > 0:
        print(min(Y*2*C+(X-Y)*A, X*2*C))
    else:
        print(min(X*2*C+(Y-X)*B, Y*2*C))
else:
    print(A*X+B*Y)


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

int main() {
	ios_base::sync_with_stdio( false );

	map<char, char> mp = {
		{'A', 'T'},
		{'C', 'G'},
		{'G', 'C'},
		{'T', 'A'}
	};

	char b;
	cin >> b;
	cout << mp[b] << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long A,B,K,num[500]={};
int main(){
  cin >> A >> B >> K;
  if(B-A+1>=2*K){
    for(int i=A;i<=A+K-1;i++) cout << i << endl;
    for(int i=B-K+1;i<=B;i++) cout << i << endl;
    return 0;
  }
  else{
    for(int i=A;i<=B;i++) cout << i << endl;
    return 0;
  }
}


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

using namespace std;

const int N = 110;

int num[N];

int ans[N][N];

int k[N];

int mi = 1e9;

int res = 0;

int n, m, x;

void dfs(int y){
	if(y > n) return ;
	res += num[y];
	for (int i = 1; i <= m ;i ++){
		k[i] += ans[y][i];
	}

	int f = 0;
	
	for (int i = 1; i <= m; i++){
		if (k[i] < x){
			f = 1;
		}
	}

	if (f == 0){
		 mi = min(mi,res);

	} 

	dfs(y + 1);

	res -= num[y];
	for (int i = 1; i <= m; i++){
		k[i] -= ans[y][i];
	}

	f = 0;
	
	for (int i = 1; i <= m; i++){
		if (k[i] < x){
			f = 1;
		}
	}

	if (f == 0){
		 mi = min(mi,res);

	}
	dfs(y + 1);
	
}

int main(){
	
	scanf("%d%d%d",&n,&m,&x);
	for (int i = 1; i <= n; i++){
		scanf("%d",&num[i]);
		for (int j = 1; j <= m; j++){
			scanf("%d",&ans[i][j]);
		}
	}

	dfs(1);

	if (mi == 1e9){
		puts("-1");
	}
	else{
		printf("%d\n",mi);
	}
	return 0;
	
}

Measured memory_bytes: 3844
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>
#include <stack>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using Graph = std::vector<std::vector<int> >;
const int INF = 1e17;
/* libraries */

signed main() {
	int k,a,b;
	std::cin >> k >> a >> b;
	for(int i=a;i<=b;i++) {
		if(i%k==0) {
			print("OK");
			return 0;
		}
	}
	print("NG");
	return 0;
}


Measured memory_bytes: 3676
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


int n, k;
int a[200000];


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

	cin >> n >> k;
	rep(i, n)cin >> a[i];
	sort(a, a + n);

	long long ans = 0;
	rep(i, n-k) {
		ans += a[i];
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a,b;
	cin >> a >> b;
	int c = (a+b)/2;
	if(abs(a-c) == abs(b-c))
		cout << c << '\n';
	else
		cout << "IMPOSSIBLE" << '\n';
	return 0;
}


Measured memory_bytes: 256
def solve(x, y, z):
    return z, x, y


def main():
    x, y, z = map(int, input().split())
    res = solve(x, y, z)
    print(z, x, y)


def test():
    assert solve(1, 2, 3) == (3, 1, 2)
    assert solve(100, 100, 100) == (100, 100, 100)


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 2940
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
using namespace std;

template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

vector<int> a(10);
int N;
vector<vector<ll>> F;
vector<vector<ll>> P;
ll ans = -INF64;

auto cal = []() {
    // すべて0のときは題意に合わない
    if (count(ALL(a), 1) == 0)
        return;

    ll score = 0;
    REP(i, N) {
        int cnt = 0;
        REP(j, 10) if (a[j] == 1 && F[i][j] == 1) { cnt++; }
        score += (ll)P[i][cnt];
    }

    chmax(ans, score);
};

auto dfs = [](auto pos) {
    if (pos == 10) {
        cal();
        return;
    }
    a[pos] = 0;
    dfs(pos + 1);
    a[pos] = 1;
    dfs(pos + 1);
};

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

    cin >> N;
    F.resize(N, vector<ll>(10));
    P.resize(N, vector<ll>(11));
    REP(i, N) REP(j, 10) cin >> F[i][j];
    REP(i, N) REP(j, 11) cin >> P[i][j];

    dfs(0);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long n, a, b;
  cin >> n >> a >> b;
  
  long long m = n/(a + b);
  long long l = n - (a + b) * m;
    
  long long res = m * a + min(l, a);
  
  cout << res << endl;
 
  return 0;
}

Measured memory_bytes: 256
/*
@Author
   Sujeet Kushwaha
*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false)
#define fast_input cin.tie(NULL)
#define fast_output cout.tie(NULL)
#define vi vector<long long int> 
#define pb push_back
#define mp make_pair
#define pp pop_back
#define iter vector<int>::iterator
#define pa pair<long long int ,long long int> 
#define f(a,b) for(int a=0;a<b;a++)
#define mod 1000000007
#define F first
#define S second
#define sett set<long long int>
#define um unordered_map<ll,ll>
// ll powmod(ll a, ll b)
// {
//     ll res = 1;
//     while (b) {
//         if (b&1) {
//             res *= a;
//             res %= mod;
//         }
//         b >>= 1;
//         a = (a * a) % mod;
//     }

//     return res;
// }

// ll modInv(ll a)
// {
//     return powmod(a, mod - 2);
// }
// int fastread(){
//     int x=0;
//     int c = getchar_unlocked();
//     while(c<48)
//         c = getchar_unlocked();
//     while(c>=48){
//         x = x*10 + (c - 48);
//         c = getchar_unlocked();
//     }
//     return x;
// }
ll isprime(ll n)
{
  if(n==1)
    return 0;
  for(int i=2;i*i<=n;i++)
  {
     if(n%i==0)
     {
       return 0;
     }
  }
  return 1;
}
void solve()
{
 ll n,k;
 cin>>n>>k;
 ll r,p,sc;
 cin>>r>>sc>>p;
 string s;
 cin>>s;
 char dp[n];
 ll ans=0;
 for(int i=0;i<min(k,n);i++)
 {
 if(s[i]=='r')
 {
   ans+=p;
   dp[i]='p';
 }
 else if(s[i]=='p')
 {
   ans+=sc;
   dp[i]='s';
 }
 else
 {
    ans+=r;
    dp[i]='r';
 }
 }
 for(int i=k;i<n;i++)
 {
  if(s[i]=='r')
 {
   if(dp[i-k]!='p')
   {
   ans+=p;
   dp[i]='p';
   }
   else
   {
     if(i+k<n)
     {
       char ge=s[i+k];
       if(ge=='r')
       {
          dp[i]='s';
       }
       else if(ge=='p')
       {
          dp[i]='r';
       }
       else
       {
         dp[i]='p';
       }
       
     }
     else
     {
       dp[i]='r';
     }
     
   }
 }
 else if(s[i]=='p')
 {
   if(dp[i-k]!='s')
   {
   ans+=sc;
    dp[i]='s';
   }
   else
   {
     if(i+k<n)
     {
       char ge=s[i+k];
       if(ge=='r')
       {
          dp[i]='s';
       }
       else if(ge=='p')
       {
          dp[i]='r';
       }
       else
       {
         dp[i]='p';
       }
       
     }
     else
     {
       dp[i]='s';
     }
   }
   
 }
 else
 {
   if(dp[i-k]!='r')
   {
    ans+=r;
    dp[i]='r';
   }
   else
   {
     if(i+k<n)
     {
       char ge=s[i+k];
       if(ge=='r')
       {
          dp[i]='s';
       }
       else if(ge=='p')
       {
          dp[i]='r';
       }
       else
       {
         dp[i]='p';
       }
       
     }
     else
     {
       dp[i]='p';
     }
   }
 }
 }
//  for(int i=0;i<n;i++)
//    cout<<dp[i]<<" ";
 cout<<ans;
}
int main() {
	fast;
	fast_input;
	fast_output;
	// ll t;
	// cin>>t;
	// while(t--)
	// {
	  solve();
	// }
	return 0;
}


Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define dl double long
#define rep(i, m, n) for(ll i = (ll)(m); i < (ll)(n); ++i)
#define rrep(i, m, n) for(ll i = (ll)(m); i > (ll)(n); --i)
const ll MOD = 1000000007;
const double pi = 3.14159265358979323846;

struct node{
    int parent, left, right;
};

void preorder(node *T, int id){
    cout << ' ' << id;
    if(T[id].left != -1) preorder(T, T[id].left);
    if(T[id].right != -1) preorder(T, T[id].right);
    return;
}

void inorder(node *T, int id){
    if(T[id].left != -1) inorder(T, T[id].left);
    cout << ' ' << id;
    if(T[id].right != -1) inorder(T, T[id].right);
    return;
}

void postorder(node *T, int id){
    if(T[id].left != -1) postorder(T, T[id].left);
    if(T[id].right != -1) postorder(T, T[id].right);
    cout << ' ' << id;
    return;
}

int main(void){
    int n;
    cin >> n;
    node *T = new node[n];
    rep(i, 0, n) T[i].parent = -1;
    rep(i, 0, n){
        int id;
        cin >> id;
        cin >> T[id].left >> T[id].right;
        if(T[id].left != -1) T[T[id].left].parent = id;
        if(T[id].right != -1) T[T[id].right].parent = id;
    }
    int root;
    rep(i, 0, n) {
        if(T[i].parent == -1) root = i;
    }
    cout << "Preorder" << endl;
    preorder(T, root);
    cout << endl << "Inorder" << endl;
    inorder(T, root);
    cout << endl << "Postorder" << endl;
    postorder(T, root);
    cout << endl;
    return 0;
}


Measured memory_bytes: 3100
#include<stdio.h>
#include<stdlib.h>
int main(){
  int *T;
  int i,x;
  scanf("%d",&x);

  T= (int *)malloc(sizeof(int)*x+1);

  for(i=1;i<x+1;i++){
    scanf("%d",&T[i]);
  }
  
for(i=1;i<x+1;i++){
  printf("node %d: key = %d, ",i,T[i]);

  if(i/2>=1) printf("parent key = %d, ",T[i/2]);

  if(i*2<=x) printf("left key = %d, ",T[i*2]);

  if(i*2+1<=x)  printf("right key = %d, ",T[i*2+1]);
  
  printf ("\n");
			    }

 return 0;
}

Measured memory_bytes: 600
(defun main ()
  (let* ((t1 (read))
         (t2 (read))
         (a1 (read))
         (a2 (read))
         (b1 (read))
         (b2 (read))
         (diff (+ (* t1 (- a1 b1)) (* t2 (- a2 b2)))))
    (format t "~A~%" (cond ((zerop diff) "infinity")
                           ((> (* (- a1 b1) (- a2 b2)) 0) 0)
                           ((> (* diff (* t1 (- a1 b1))) 0) 0)
                           (t (+ (if (zerop (mod (abs (* t1 (- a1 b1))) diff)) -1 0) (1+ (* 2 (floor (abs (* t1 (- a1 b1))) (abs diff))))))))))

(main)


Measured memory_bytes: 16100
function Main(input) {
  input = input.split("\n");	
  var input1 = input[1].split(" ");	
  input1 = input1.map(e=>{
    return parseInt(e,10);
  })
  
  input1.sort((a,b)=>{
    return a-b;
  })
  var result=input1.reduce((prev,curr)=>{
    return (prev+curr)/2
  });
  console.log(result)
  
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
n = gets.to_i
array = gets.chomp("").split(" ").map(&:to_i)
array.each_with_index do |i,k|
    print " " unless k == 0
    print i 
end
print "\n" 
(1..n-1).each do |i|
    v = array[i]
    j = i - 1
    while j >= 0 && array[j] > v do
        array[j + 1] = array[j]
        j -= 1
    end
    array[j+1] = v
    array.each_with_index do |i,k|
    print " " unless k == 0
    print i 
end
    print "\n" 
end



Measured memory_bytes: 6872
#include<bits/stdc++.h>
using namespace std;
long inf = 1000000007;

int main() {
    long x; cin >> x;
    long happy = 0;
    happy += (x / 500)*1000;
    x %= 500;
    happy += (x / 5)*5;
    x %= 5;

    cout << happy << endl;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll int n;
    cin>>n;
    ll int arr[n], dp[n];
    for(ll int i=0; i<n; i++)
        cin>>arr[i];
        
    // memset(dp, 1, sizeof(dp));
    for(ll int i=0; i<n; i++)
        dp[i] = 1;
    
    for(ll int i=1; i<n; i++)
    {
        // cout<<dp[i]<<" ";
        if(arr[i-1] >= arr[i])
            dp[i] += dp[i-1];
    }
    
    ll int ans = INT_MIN;
    for(ll int i=0; i<n; i++)
        ans = max(ans, dp[i]);
    cout<<ans-1;
    
}

Measured memory_bytes: 1792
/* 
 * Project: AtCoder Beginners Contest 083 A - Libra
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/06/26
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
using namespace std;

int a, b, c, d;

void solve() {

    int weight_left  = a + b;
    int weight_right = c + d;
    if (weight_left == weight_right) {
        printf("Balanced\n");
        return;
    }
    if (weight_left > weight_right) {
        printf("Left\n");
        return;
    }
    if (weight_left < weight_right) {
        printf("Right\n");
        return;
    }

}

int main() {

    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    scanf("%d", &d);

    solve();

}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;


int main()
{
   int i,j,k,n,m;
   cin>>k;
   if(k%2==0) cout<<(k/2)*(k/2);
   else cout<<(k/2)*(k/2+1);

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N,K;
  cin>>N>>K;
  
  vector<int> L(N);
  for(int i=0;i<N;i++){
    cin>>L[i];
  }
  
  
  sort(L.begin(),L.end());
  reverse(L.begin(),L.end());
  
  
  int sum=0;
  
  for(int i=0;i<K;i++){
    sum+=L[i];
  }
  
  
  cout<<sum<<endl;
}

Measured memory_bytes: 3632