akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <chrono>
//#include<math.h>
using namespace std::chrono;
using namespace std;
#define fr(x,i,n) for(int x = i; x < n; ++x)
#define fb(x,i,n) for(int x = i; x >= n; --x)
#define pr pair<int,int>
#define ll long long int
#define ld long double
const ll mod=1e9+7;
//const ld M_PI=3.14159265358979323;

/*    auto start = high_resolution_clock::now();
    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop - start);
    cout << "\nduration="<<duration.count()/1e6 << endl;
*/
ll f(ll x,ll n){
    ll r=1;
    while(n){
        if(n%2==1)
        r=(r*x)%mod;
        x=(x*x)%mod;
        n/=2;
    }
    return r;

}

vector<ll> fact(2e5+10,1),ifact(2e5+10);
void build(){
    for(ll i=2;i<fact.size();i++)
    fact[i]=(i*fact[i-1])%mod;
    fr(i,0,fact.size()){
        ifact[i]=f(fact[i],mod-2);
    }
}
ll C(int n, int r){
    if(n<r)
    return 0;
    return (((fact[n]*ifact[r])%mod)*ifact[n-r])%mod;
}

/*ll C[1001][1001];
void build(){
    memset(C,0,sizeof(C));
    fr(i,0,1001)
    C[i][i]=1;
    fr(i,0,1001)
    C[i][0]=1;
    fr(i,2,1001){
        fr(j,1,i){
            C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
        }
    }
}*/
void solve(){
    int n;
    cin>>n;
    int x=n%10;
    if(x==2||x==4||x==5||x==7||x==9){
        cout<<"hon";
    }
    else if(x==3){
        cout<<"bon";
    }
    else cout<<"pon";
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
//    build();
    int t=1;
//    cin>>t;
    while(t--)
    solve();

}


Measured memory_bytes: 6284
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, a, b) for (int i = (a); i < (int)(b); i++)
typedef vector<int> VI;
typedef vector<VI> VVI;

VI Main(int N, VI A)
{
    VI ans(N, 0);
    REP(i, N) ans[A[i]-1] = i+1;
    return ans;
}

int main(void){
    int N;
    cin >> N;
    VI A(N);
    REP(i, N) cin >> A[i];
    VI out = Main(N, A);
    REP(i, N) cout << out[i] << ' ';
    cout << endl;
    return 0;
}

Measured memory_bytes: 1656
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
const double pi=acos(-1);
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<MOD>;

mint calc(long long N, long long K) {
    mint res = 1;
    for (long long n = 0; n < K; ++n) {
        res *= (N - n);
        res /= (n + 1);
    }
    return res;
}
int main() {
//cout << fixed << setprecision(12);
ll n;
cin>>n;
vector<pair<ll,ll>> c;
ll ma = 0;
ll a,b;
rep(i,n){
cin>>a>>b;
c.pb(make_pair(b,a));
}
sort(all(c));
ll ca = 0;
for(auto p: c){
ca+=p.se;
//cout << p.fi << " " << p.se <<" " << ca<< endl;
if(ca>p.fi){
ma++;
break;}
}
if(ma!=1){
cout << "Yes" << endl;}
else{
cout << "No" << endl;}}


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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;
//#define DEBUG(x) ;

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


int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll N; cin >> N;
	vector<ll> A(N); REP(i, N) cin >> A[i];
	sort(ALL(A));

	if (N == 2)
	{
		std::cout << A[1] << " " << A[0] << std::endl;
		return 0;
	}
	
	auto it = upper_bound(ALL(A), A.back()/2);
	if (it == A.end())
	{
		std::cout << A.back() << " " << *prev(it, 2) << std::endl;
		return 0;
	}

	double tmp = A.back() / 2.0;
	DEBUG(tmp);
	if (abs(*it - tmp) < abs(*prev(it) - tmp))
		std::cout << A.back() << " " << *it << std::endl;
	else
		std::cout << A.back() << " " << *prev(it) << std::endl;
	
	
	
	return 0;
}


Measured memory_bytes: 3948
#include<iostream>
#include<algorithm>
#include<functional>

using namespace std;
typedef long long ll;

int H, W;
ll MOD = 1000000007;
int A[1001], B[1001];

int main() {
	cin >> H >> W;
	for (int i = 0; i < H; i++)cin >> A[i];
	for (int i = 0; i < W; i++)cin >> B[i];
	sort(A, A + H + 1, greater<int>()), sort(B, B + W + 1, greater<int>());
	ll ans = 1;
	int Apos = 0, Bpos = 0;
	for (int n = H * W; n > 0; n--) {
		ll tmp = 1;
		if (n == A[Apos] && n == B[Bpos]) {
			Apos++, Bpos++;
		}
		else if (n == A[Apos]) {
			tmp *= Bpos;
			Apos++;
		}
		else if (n == B[Bpos]) {
			tmp *= Apos;
			Bpos++;
		}
		else {
			tmp *= (Apos * Bpos - (H * W - n));
		}
		ans *= tmp;
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

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

#define INF 1000000000
#define MIN(X,Y) ((X)<(Y)?(X):(Y))

int main(void){
  int dp[10010];
  int n,h;
  
  cin >> h >> n;
  dp[0] = 0;
  for (int i=1; i<=h; i++) dp[i] = INF;
  for (int i=0; i<n; i++){
    int a,b;
    cin >> a >> b;
    for (int j=0; j<=h; j++){
      if (j-a>=0){
        dp[j] = MIN(dp[j], dp[j-a]+b);
      } else {
        dp[j] = MIN(dp[j], b);
      }
//      cout << dp[j] << " ";
    }
//    cout << endl;
  }
  cout << dp[h] << endl;
  return 0;
}

Measured memory_bytes: 256
package main

import (
    "fmt"
)

func main() {
    var s, t []byte
    fmt.Scan(&s)
    fmt.Scan(&t)
    m := make(map[byte]byte)
    m2 := make(map[byte]byte)
    var ng bool
    for i := 0; i < len(s); i++ {
        if b, ok := m[s[i]]; ok {
            if t[i] != b { 
                ng = true
            }   
        } else {
            m[s[i]] = t[i]
        }   
        if b, ok := m2[t[i]]; ok {
            if s[i] != b { 
                ng = true
            }   
        } else {
            m2[t[i]] = s[i]
        }   
    }   
    if ng {
        fmt.Println("No")
    } else {
        fmt.Println("Yes")
    }   
}


Measured memory_bytes: 3712
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n, k; cin >> n >> k;
  vector<int> p(n); REP(i, n) cin >> p[i];
  sort(ALL(p));
  cout << accumulate(p.begin(), p.begin() + k, 0) << '\n';
  return 0;
}


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

int main(){
	string S;
	cin >> S;
	set<char> s;
	rep(i, S.size()) s.insert(S.at(i));
	if (s.size() == 4) puts("Yes");
	else if (s.size() == 2) {
		if ((s.count('E') && s.count('W')) || (s.count('N') && s.count('S'))) puts("Yes");
		else puts("No");
	}
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

ll calc(ll A){
    return (ll)(A*1.08);
}
int main() { 
    ll N, A;
    cin >> N ;
    A = (ll) N/1.08;
    if(calc(A-1)==N) cout << A-1 << endl;
    else if(calc(A-0)==N) cout << A-0 << endl;
    else if(calc(A+1)==N) cout << A+1 << endl;
    else cout << ":(" << endl;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

answer = 0

for i in range(N+1):
    if i == 0:
        if A[i] < B[i]:
            answer += A[i]
            B[i] -= A[i]
            A[i] = 0
        else:
            answer += B[i]
            A[i] -= B[i]
            B[i] = 0
    elif i == N:
        

        if A[i] < B[i-1]:
            answer += A[i]
            B[i-1] -= A[i]
            A[i] = 0

        else:
            answer += B[i-1]
            A[i] -= B[i-1]
            B[i-1] = 0

    else:
        if A[i] < B[i] + B[i-1]:
            answer += A[i]
            if A[i] < B[i-1]:
                B[i-1] -= A[i]
                A[i] = 0
            else:
                B[i] -= (A[i]-B[i-1])
                B[i-1] = 0
                A[i] = 0
        else:
            answer += (B[i]+B[i-1])
            A[i] -= (B[i]+B[i-1])
            B[i],B[i-1] = 0,0

print(answer)

Measured memory_bytes: 18476
def main():
    s = input()
    n = len(s)
    sum = 0
    for i in range((1<<(n-1))):
        prev = 0
        exp = ""
        for j in range(n-1):
            if (i>>j)&1:
                exp += s[prev:j+1]
                prev = j+1
                exp += "+"
        exp += s[prev:]
        sum += eval(exp)
    print(sum)
        

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
#include <typeinfo>

#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REP1(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREP1(i, x) for (int i = ((int)(x)); i > 0; i--)
/*
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

#define all(x) (x).begin(),(x).end()
*/

using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    long long k;
    cin >> k;
    char ans;
    for (int i = 0; k > 0; i++)
    {
        if (s[i] == '1')
        {
            k--;
            if (k <= 0)
                ans = s[i];
        }
        else{
            ans = s[i];
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
from fractions import gcd

def segfunc(x, y):
    return gcd(x, y)
ide_ele = 0
"""
最小値 min(x, y),float('inf) RMQ
最大値 max(x, y),float('inf)
区間和 x + y,0 BIT
区間積 x * y,1
最大公約数 math.gcd(x, y),0
"""

class SegTree:

    def __init__(self, init_val, segfunc, ide_ele):
 
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        # 葉の数 2**n個
        self.tree = [ide_ele] * 2 * self.num
        # 木の要素数は1originだとこう
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築 葉に数列の値を
        # 葉のindexはnum ~ num + n
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])
        # 節は子の値を参照する

    def update(self, k, x):
        """
        k番目の値をxに更新
        k: index(0-index)
        x: update value
        """
        k += self.num
        # 葉のスタートのindexはnumのため
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1
            # 親へ
            # 1とのXORは兄弟になる

    def query(self, l, r):
        """
        [l, r)のsegfuncしたものを得る
        l: index(0-index)
        r: index(0-index)
        """
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

N = int(input())
A = list(map(int, input().split()))
seg = SegTree(A, segfunc, ide_ele)
ans = 0
for i in range(N):
    left = seg.query(0, i)
    right = seg.query(i + 1, N)
    ans = max(ans, gcd(left, right))

print(ans)


Measured memory_bytes: 16140
#include<iostream>
using namespace std;
int main(){
int n;
  cin >> n;
  int h[n];
  for (int i = 0; i < n; i++)
    cin >> h[i];
  int ans = 1, maxi = h[0];
  for (int i = 1; i< n; i++){
    if(maxi < h[i]+1){
    	maxi = h[i];
      	ans += 1;
    }
  }
  cout << ans <<'\n';
    
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())

cake = []

for _ in range(N) :
    x, y, z = map(int, input().split())
    cake.append((x, y, z))


ans = 0

for i in [0, 1] :
    for j in [0, 1] :
        for k in [0, 1] :
            sgn = ((-1)**i, (-1)**j, (-1)**k)  # 符号
            val = lambda A : sum([ A[i] * sgn[i] for i in range(3)])
            sortedCake = sorted(cake, key=val, reverse=True)
            xSum, ySum, zSum = 0, 0, 0
            for x, y, z in sortedCake[:M] :
                xSum += x
                ySum += y
                zSum += z
            sumCakeVal = abs(xSum) + abs(ySum) + abs(zSum)
            ans = max(ans, sumCakeVal)

print(ans)

Measured memory_bytes: 3276
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
#define mod 1000000007
int main() {
    fio;
    ll n;
    cin >> n;
    ll a[n];
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll ans = 0;
    for (ll i = 0; i < n; i++) {
        for (ll j = i + 1; j < n; j++) {
            for (ll k = j + 1; k < n; k++) {
                if ((a[i] + a[j] > a[k]) and (a[i] != a[j]) and (a[i] != a[k]) and (a[j] != a[k]) and (a[k] + a[j] > a[i]) and (a[i] + a[k] > a[j])) {
                    //cout << i + 1 << " " << j + 1 << " " << k + 1 << endl;
                    ans++;
                }
            }
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define All(v) v.begin(), v.end()
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;


map<string, map<int, int>> mp;

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int N; cin >> N;
    for(int i=0;i<N;i++){
        string s; cin >> s;
        int p; cin >> p;
        mp[s][-p] = i + 1;
    }
    for(auto &p : mp){
        for(auto pp : p.second){
            cout << pp.second << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int ans=0,f=0;s='0'+s;
	for(int i=s.size()-1;i>=0;i--)
		if(s[i]+f<'5'||s[i]+f=='5'&&s[i-1]<'5')
		{ans+=f+s[i]-'0';f=0;}
		else
		{ans+=10-s[i]-f+'0';f=1;}
	cout<<ans+f<<endl;
	return 0;
}


Measured memory_bytes: 2308
let ans, n, xss = Scanf.(scanf "%d %d" @@ fun n d -> ref 0, n, Array.(init n @@ fun _ -> init d @@ fun _ -> scanf " %d" (+) 0))
let rec f i n = if i * i >= n then i * i = n else f (i + 1) n
let g n = n * n
let _ = Array.(iteri (fun i xs -> for j = i + 1 to n - 1 do if f 1 @@ fold_left (+) 0 @@ mapi (fun k x -> g (x - xss.(j).(k))) xs then incr ans done) xss); Printf.printf "%d\n" !ans

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

int main () {
  long long n,k;
  cin >> n >> k;
  vector<long long> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  long long right=1000000000,left=0;
  double m;
  while(true){
    m=ceil((right+left)/2);
    long long sum=0;
    for(int i=0;i<n;i++){
      sum+=ceil(a[i]/m)-1;
    }
    if(sum<=k) right=m;
    else left=m;
    if(right-left==1){
      cout << right << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 4840
#include<stdio.h>
#include<string.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
int main(void)
{
  char S[1001],T[1001];int diff=1000;
  if(!scanf("%s %s",S,T))return -1;
  rep(i,(int)strlen(S)-(int)strlen(T)+1)
  {
    int change=strlen(T);
    rep(j,(int)strlen(T))
    {
      if(S[i+j]==T[j]){change--;}
    }
    diff=diff<change?diff:change;
  }
  return printf("%d\n",diff),0;
}

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

int main()
{
   int n,k,x,y;
   cin>>n>>k>>x>>y;
   int sum=0;
   if (n>k)  sum=k*x+(n-k)*y;
   else sum=n*x;
   cout<<sum<<endl;
}

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

using namespace std;

class Edge {
public:
    int from, to, weight;
    Edge(int f, int t, int w) : from(f), to(t), weight(w) {}
};

int memo[100001] = {0};

inline int height(vector< vector<Edge> > &Graph, const int parent) {
    if (memo[parent]) return memo[parent];
    int ret = 0;
    for (int i=0; i<(int)Graph[parent].size(); ++i) {
        ret = max(ret, Graph[parent][i].weight + height(Graph, Graph[parent][i].to));
    }
    return memo[parent] = ret;
}

inline int diameter(vector< vector<Edge> > &Graph, const int parent) {
    int ret = 0;
    int h1 = 0, h2 = 0;
    for (int i=0; i<(int)Graph[parent].size(); ++i) {
        int h = Graph[parent][i].weight + height(Graph, Graph[parent][i].to);
        if (h1 < h) {
            h2 = h1;
            h1 = h;
        } else if (h2 < h) {
            h2 = h;
        }
        ret = max(ret, diameter(Graph, Graph[parent][i].to));
    }
    ret = max(ret, h1 + h2);
    return ret;
}

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

    int n, s, t, w;
    cin >> n;
    vector< vector<Edge> > Graph(n + 1);
    for (int i=1; i<=n-1; ++i) {
        cin >> s >> t >> w;
        Graph[s].push_back(Edge(s, t, w));
    }
    cout << diameter(Graph, 0) << endl;

    return 0;
}

Measured memory_bytes: 12760
{-# LANGUAGE OverloadedStrings #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.Map.Strict               as M
import           Data.Char


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

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

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las

solve :: Int -> [Int] -> [Int] -> Int
solve n ps qs =
    let intListToStr xs = intercalate "" $ show <$> xs
        nList        = sort $ intListToStr <$> permutations [1 .. n]
        listAndOrder = M.fromList $ zip nList [1 ..]
        pstr         = intListToStr ps
        qstr         = intListToStr qs
    in  abs $ (listAndOrder M.! pstr) - (listAndOrder M.! qstr)


main = do
    (a, b, c) <- readTuple3
    let a' = show a
    let b' = show b
    let c' = show c
    putStrLn $ c' ++ " " ++ a' ++ " " ++ b'





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

int main()
{
   long long int n, i, a, b, c, j,k,p;

   cin>>n;


   for(j=1;j<=3500;j++){

   for(i=1; i<=3500; i++){
        p=(4*i*j-n*i-n*j); k=(n*i*j);
    if(p>0 && (k%p)==0) {
        a=i; b=k/p; c=j; cout<<a<<' '<<b<<' '<<c<<endl;return 0;
    }
   }
   }


    return 0;
}









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

int fr[26], tfr[26];
char s[51];

int main(){
	f(i, 0, 26)fr[i] = 1e9;
	int n;
	scanf("%d", &n);
	f(i, 0, n){
		scanf("%s", s);
		int l = strlen(s);
		f(j, 0, 26)tfr[j] = 0;
		f(j, 0, l)++tfr[s[j] - 'a'];
		f(j, 0, 26)fr[j] = min(fr[j], tfr[j]);
	}
	string an;
	f(i, 0, 26)while (fr[i]){
		an += 'a' + i;
		--fr[i];
	}
	printf("%s\n", an.c_str());
}


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

using namespace std;

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

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

	vector<int> sorted(A.size());
	copy(A.begin(), A.end(), sorted.begin());
	sort(sorted.begin(), sorted.end(), greater<int>());

	int max = sorted[0];
	int second = sorted[1];

	for (const int& a : A)
	{
		if (a == max)
		{
			cout << second << endl;
			continue;
		}
		cout << max << endl;
	}
}

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


int main() {
  int N,l,r,ans;
  ans=0;
  cin>>N;
  rep(i,N){
      cin>>l>>r;
      ans=ans+r-l+1;
  }
  cout << ans << endl;
}

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

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 
#define REP(i, n) for (int i = 0; i < (n); i++)

int main(int argc, char const *argv[])
{
    int A, B; cin >> A >> B;
    cout << (A - 1) * (B - 1) << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
//        repeat(readInteger()) { solve() }
        solve()
        out.flush()
    } }
}

fun solve() {
    val (n, k) = readIntegerList()
    val aList = readLongList()
    for (i in k until n) {
        val ans = if (aList[i] > aList[i - k]) "Yes" else "No"
        out.println(ans)
    }
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


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

int main()
{
  int a,b;
  cin>>a>>b;
  if((b-1)%(a-1)==0)
    cout<<(b-1)/(a-1)<<endl;
  else
    cout<<(b-1)/(a-1)+1<<endl;
}


Measured memory_bytes: 3496
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
typedef pair<int,int> P;
struct edge{int to, id;};
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mod 1000000007

using graph = vector<vector<ll>>;

int main(){
    int n;
    cin >> n;
    int ans = 0;
    rep(i,n){
        int temp;
        cin >> temp;
        if((i+1) % 2 == 1 && temp % 2 == 1 ) ans++;
    }
    cout << ans << endl;
}

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

int main() {
  int N;
  string S;
  cin >> N;
  vector<string> X(N);
  for(int i = 0;i < N;i++){
    cin >> S;
    X.at(i) = S;
  }
  sort(X.begin(),X.end());
  X.erase(unique(X.begin(),X.end()),X.end());
  
  cout << X.size() << endl;
  
}


Measured memory_bytes: 9600
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;

void MAIN() {
    scanf("%d", &N);
    for (int x=0; x<=N; x++) {
	int t = x * 108 / 100;
	if (t == N) {
	    printf("%d\n", x);
	    return;
	}
    }

    puts(":(");
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cmath>
#include<vector> 
#include<algorithm>

 
#define fastio()                ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll                      long long int
#define ull                     unsigned long long int
#define inp(n)                  ll n; cin >> n
#define inpc(c)                 char c; cin >> c
#define inps(s)                 string s; cin >> s
#define print(x)                cout << x << " "
#define nl                      cout << '\n'
#define pyes                    cout << "YES"
#define pno                     cout << "NO"
#define fr(i,a,b)               for(ll i=a; i<b; ++i)
#define frrev(i,b,a)            for(ll i=b; i<=a; --i)
#define strrev(s)               reverse(s.begin(), s.end())
#define pb(x)                   push_back(x)
#define vin(A, n)               vector<ll> A; fr(i,0,n){ ll x; cin >> x; A.pb(x); }
#define vinc(A, n)              vector<char> A; fr(i,0,n){ char x; cin >> x; A.pb(x); }
#define vpairin(A, n, t1, t2)   vector<pair<t1,t2> > A; fr(i,0,n) {t1 x; t2 y; cin >> x >> y; A.pb(make_pair(x,y));}
#define srt(A)                  sort(A.begin(), A.end())
#define vout(A, n)              fr(i,0,n){ print(A[i]); }
#define vpairout(A, n)          fr(i,0,n){ print(A[i].first); print(A[i].second); nl; }
 
using namespace std;

void solve()
{
	ll n, k;
	cin >>n>>k;
	vector <int>num(n+1,0);
	for (int i = 1; i< n+1; i++)
	{
		int temp;
		cin >> temp;
		num[temp]++;
	}
	vector <int>a;
	for (int i = 0; i < n+1; ++i)
	{
		if (num[i] != 0)
		{
			a.push_back(num[i]);
		}
	}

	int exnum = 0;

	sort(a.begin(),a.end());
	if ( k < a.size())
	{
		int g = a.size() - k;
		for (int i = 0; i < g; ++i)
		{
			exnum += a[i];
		}
		cout << exnum;
	}
	else
		cout << "0";



}
 
int main()
{
 
   fastio();
   solve();
   return 0;
}
 

Measured memory_bytes: 4684
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define LINF 1e18
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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


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

int dp[202020];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int a=n/100,b=n%100;
    if(0<a&&a<=12&&0<b&&b<=12){
        cout<<"AMBIGUOUS";
    }
    else if(0<b&&b<=12){
        cout<<"YYMM";
    }
    else if(0<a&&a<=12){
        cout<<"MMYY";
    }
    else cout<<"NA";
}

Measured memory_bytes: 256
import math
def bi(x, y):
  if x < y or y < 0 or x < 0: return 0
  if y == 0: return 1
  return math.factorial(x) // math.factorial(y) // math.factorial(x - y)

n, k = list(map(int, input().split(' ')))
for i in range(1, k + 1):
  print(bi(k - 1, i - 1) * bi(n - k + 1, i) % (10**9 + 7))


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define faster ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define FO(n) for (ll i = 0; i < n; i++)
#define endl "\n"
const long long int M = 10e9 + 7;
void solve()
{
string s;
cin>>s;
if(*s.rbegin()=='s'){
    cout<<s<<"es"<<endl;
}else cout<<s<<"s"<<endl;
}
int main()
{
    faster;
    //int t;
    //cin >> t;
    //while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 3648
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-04-01 19:46:57
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

int dp[110][2][5];

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

  string s; cin >> s;
  int n = s.size();
  int k; cin >> k;

  dp[0][0][0] = 1;

  for (int i = 0; i < n; ++i) {
    int D = s[i] - '0';
    for (int j = 0; j < 2; ++j) {
      for (int l = 0; l <= 3; ++l) {
        for (int d = 0; d <= (j ? 9 : D); ++d) {
          dp[i + 1][j || (d < D)][l + (d != 0)] += dp[i][j][l];
        }
      } 
    }
  }

  cout << dp[n][0][k] + dp[n][1][k] << endl;

  return 0;
}

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

typedef long long ll;

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    bool of = false;
    ll n, a, ans = 1;
    double l = 0;
    cin >> n;
    for (ll i = 0; i < n; ++i) {
        cin >> a;
        if (!a) {
            cout << "0\n";
            return 0;
        } else if ((l += log10(a)) > 18) {
            of = true;
        } else ans *= a;
    }
    cout << (of || ans > 1000000000000000000 ? -1 : ans) << endl;
    return 0;
}


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

int main() {
    int a, b;
    cin >> a >> b;
    if((a > 0 && a < 10) && (b > 0 && b < 10)){
        cout << a*b << "\n";
    }else{
        cout << -1 << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

#define DIV 1000000007

using namespace std;

long long N;

string S0[4] = {".", "#", ".", "#"};
string S1[4] = {".", ".", "#", "#"};

int main(){
	cin >> N;
	long long len = 0;
	bool right = true;
	long long tmp = 0;

	string s0 = "";
	string s1 = "";

	while(1){
		string S;

		if(right == true){
			cout << s0 << S0[tmp] << endl;
			cout << s1 << S1[tmp] << endl;
		}else{
			cout << S0[tmp] << s0 << endl;
			cout << S1[tmp] << s1 << endl;
		}

		cin >> S;
		if(S == "F"){
			tmp++;
			if(tmp == 4){
				tmp = 0;
				right = false;
			}
		}else if(S == "end"){
			break;
		}else{
			if(right == true){
				s0 += S0[tmp];
				s1 += S1[tmp];
			}else{
				s0 = S0[tmp] + s0;
				s1 = S1[tmp] + s1;
			}
			tmp = 0;
		}
	}
}



Measured memory_bytes: 596
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int S = sc.nextInt();
		int h = S/3600;
		int m = (S-h*3600)/60;
		int s = S-h*3600-m*60;
		System.out.println(h+":"+ m +":"+s);
	}
}

Measured memory_bytes: 26208
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define endl "\n"

int mx=1;

int func(vector<vector<int>> &v, int e, vector<int> &f, vector<int> &v1)
{
	f[e]=1;
	int m1=0;
	for(int i=0;i<v[e].size();i++)
	{
		int x=0;
		if(f[v[e][i]]==0)
			func(v, v[e][i], f, v1);
		x=v1[v[e][i]];
		m1=max(x+1, m1);
		// if(x>m1)
		// {
		// 	m2=m1;
		// 	m1=x;
		// }
		// else if(x>m2)
		// 	m2=x;
	}
	// cout<<e<<' '<<m1<<endl;
	v1[e]=m1;
	mx=max(mx, m1);
}
 
int32_t main()
{
	fast;
	int n, m;
	cin>>n>>m;
	vector<vector<int>> v(n+1);
	for(int i=0;i<m;i++)
	{
		int a, b;
		cin>>a>>b;
		v[a].push_back(b);
	}
	vector<int> f(n+1, 0);
	vector<int> v1(n+1, 0);
	for(int i=1;i<=n;i++)
	{
		if(!f[i])
			func(v, i, f, v1);
	}
	cout<<mx<<endl;
	return 0;
}

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

int main(){
  string moji[]={".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
  int i,j,n;
  string figure;
  cin >> n;
  for(i = 0; i < n; i++){
    cin >> figure;
    int count=0;
    for(j = 0; j < figure.size(); j++){
      if(figure[j]-'0'==0){
	continue;
      }else if(figure[j]-'0'!=0){
	char suuji=figure[j];
	if(figure[j+1]-'0'==0){
	  cout << moji[suuji-'0'-1][count%(moji[suuji-'0'-1]).size()];
	  count=-1;
	}
	count++;
      }
    }
    cout << endl;
      }
  return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
#include <random>
using namespace std;
#define M 1000000007
#define pb emplace_back
#define F first
#define S second
#define PI acosl(-1.0)
#define mp(a, b) make_pair(a, b)
#define eps 1e-9
#define all(vec) vec.begin(), vec.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
const int N = 2e5 + 10;
const int INF = 1LL << 60;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int RANDOM_GEN = uniform_int_distribution<int>(0, 10000)(rng);
int t = 1;

int ppow[N];

void solve()
{
	string s;
	cin >> s;
	int Mod = 2019;
	int ans = 0;
	int pmod = 0;
	map<int, int> mp;
	mp[0] = 1;
	ppow[0] = 1;
	reverse(s.begin(), s.end());
	for(int i=1; i<s.length(); i++){
		ppow[i] = ppow[i-1] * 10 % Mod;
	}
	for(int i=0; i<s.length(); i++){
		int curr = ppow[i];
		int num = s[i] - '0';
		int total = curr * num % Mod;
		total = (total + pmod) % Mod;
		ans += mp[total];
		//cout << i << ": " << ans << endl;
		mp[total]++;
		pmod = total;
	}
	cout << ans << '\n';
}


signed main()
{
    FAST
    int Tests = 1;
    //cin>>Tests;
    while(Tests--)
    {
		//cout<<"Case #"<<(t++)<<": ";  
        solve();
    }
    return 0;
}


Measured memory_bytes: 5204
a,b,c,x = 4.times.map {gets.to_i}
cnt = 0
(0..a).each do |i|
    (0..b).each do |j|
        (0..c).each do |k|
            cnt += 1 if 500*i + 100*j + 50*k == x
        end
    end
end

puts cnt

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

int main(){
    std::string N;
    std::cin >> N;
    
    std::vector< std::vector< int > > dp(N.size()+1, std::vector< int >(2, 0));
    dp[0][1] = 1;
    for(int i=0; i<N.size(); i++){
        int tmp = N[i] - '0';
        int pat00 = tmp;
        int pat01 = tmp + 1;
        int pat10 = 10 - tmp;
        int pat11 = 10 - tmp - 1;
        if(i == N.size() - 1){
            dp[i+1][0] = dp[i][0] + pat00;
            dp[i+1][1] = dp[i][1] + pat10;
        }else{
            if(dp[i][0] + pat00 > dp[i][1] + pat10){
                dp[i+1][0] = dp[i][1] + pat10;
            }else{
                dp[i+1][0] = dp[i][0] + pat00;
            }
    
            if(dp[i][0] + pat01 > dp[i][1] + pat11){
                dp[i+1][1] = dp[i][1] + pat11;
            }else{
                dp[i+1][1] = dp[i][0] + pat01;
            }
        }
    }

    if(dp[N.size()][0] > dp[N.size()][1]){
        std::cout << dp[N.size()][1] << std::endl;
    }else{
        std::cout << dp[N.size()][0] << std::endl;
    }
    
    return 0;
}



Measured memory_bytes: 55940
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <unordered_map>
#include <cmath>
#include <algorithm>

typedef long long ll;
typedef long double ld;

using namespace std;
int main()
{
  int a, b;
  cin >> a >> b;
  if (a > 9 || b > 9)
  {
    cout << "-1";
  }
  else
  {
    cout << a * b;
  }
}


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

int main(){
	char str[1201];
	char komoji[27]="abcdefghijklmnopqrstuvwxyz";
	char oomoji[27]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	int mojisuu,i,j;
	
	fgets(str,sizeof(str),stdin);
	mojisuu=(int)strlen(str);
	
	for(i=0;i<mojisuu;i++){
		for(j=0;j<26;j++){
			if(str[i]==komoji[j]){
				str[i]=oomoji[j];
				break;
			}else if(str[i]==oomoji[j]){
				str[i]=komoji[j];
				break;
			}
			
		}
		printf("%c",str[i]);
	}
	
	//printf("\n");
	return 0;
}

Measured memory_bytes: 2628
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define test ll tx; tx=1; while(tx--)
typedef long long int ll;
ll solve(vector<ll>adj[],bool vis[],ll dp[],ll v){
    if(vis[v]){
        return dp[v];
    }
    vis[v]=true;
    ll best=0;
    for(int u:adj[v]){
        ll p=solve(adj,vis,dp,u);
        ++p;
        best=max(best,p);
    }
    dp[v]=best;
    return best;
}
int main() {
    FIO;
    test{
        ll n,m,i,l,r;
        cin>>n>>m;
        vector<ll>adj[n+1];
        ll dp[n+1];
        bool vis[n+1];
        for(i=1;i<=n;i++){
            dp[i]=-1;
            vis[i]=false;
        }
        for(i=0;i<m;i++){
            cin>>l>>r;
            adj[l].push_back(r);
        }
        //Directic acyclic graph
        ll ans=0;
        for(i=1;i<=n;i++){
            ans=max(ans,solve(adj,vis,dp,i));
        }
        cout<<ans<<endl;
    }
	return 0;
}


Measured memory_bytes: 9984
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define nyan "(=^･ω･^=)"
typedef long long ll;
typedef long double ld;
using namespace std;

int main()
{
    int n;
    int xo = 0, io = 0, ix = 0;

    cin >> n;
    int ans = 0;
    for(int i = 0; i < n; i++) {
        string str;
        cin >> str;

        int l = str.length();
        for(int j = 0; j < l-1; j++) 
            if(str[j] == 'A' && str[j+1] == 'B') ans++;

        if(str[0] == 'B' && str[l-1] == 'A') io++;
        else if(str[l-1] == 'A') xo++;
        else if(str[0] == 'B') ix++;
    } 

    if(xo > 0 && ix > 0) {
        ans += io + 1;
        ans += min(xo-1, ix-1);

        cout << ans << endl;
        return 0;
    } 
    else if(xo > 0) {
        ans += io;
        cout << ans << endl;
        return 0;
    } 
    else if(ix > 0) {
        ans += io;
        cout << ans << endl;
        return 0;
    }
    else {
        if(io) ans += io-1;

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

Measured memory_bytes: 256
/*
    JAI JAGANNATH!
*/
//@Author : zanj0
#include <bits/stdc++.h>
#define fastio  ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;
typedef long long int lli;
template <typename T>
void out(vector <T> v){
    for(lli i = 0; i < v.size(); i++){
        cout << v[i] << " ";
    }
    cout << endl;
}
void solve(){
    lli x, n;
    cin >> x >> n;
    vector <lli> v(n);
    for(lli i = 0; i < n; i++) cin >> v[i];
    lli ret = 0;
    sort(v.begin(), v.end());
    lli maxVal = INT_MIN;
    for(lli i = 1; i < n; i++){
        ret += v[i] - v[i - 1];
        maxVal = max(v[i] - v[i - 1], maxVal);
    }
    ret += x - v[n - 1] + v[0];
    maxVal = max(x - v[n - 1] + v[0], maxVal);
    cout << ret - maxVal << endl;
}
int main(){
	#ifdef zanj0
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
    fastio
    lli t;
    t = 1;
    while(t--){
        solve();
    }
    return 0;
}



Measured memory_bytes: 1792
function main(input) {
  var input = input.split("\n");
 
  var N = parseInt(input[0], 10)
  var s = input.slice(1, N + 1);
  var M = parseInt(input[N + 1], 10);
  var t = input.slice(N + 2, N + 2 + M);
 
  var array = {};
  s.map(
    function(value, index){ array[value] = (array[value] || 0) + 1}
  );
  t.map(
    function(value, index){ array[value] = (array[value] || 0) - 1}
  );
 
  var a = 0;
  for (var key in array) {
    a = Math.max(a, array[key]);
  }
 
  console.log(a);
}
 
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
from itertools import product

n = int(input())
al = list(map(int, input().split()))
res = 0
for p in product([-1,0,1], repeat=n):
    bl = [al[i]+p[i] for i in range(n)]
    m = 1
    for b in bl:
        m *= b
    if m%2==0:
        res += 1
print(res)

Measured memory_bytes: 3060
def Jud(S,n,k):#S:証言、n:人数、
  ans=True
  k2d=format(k,'b').zfill(n)
  people=[]
  for i in range(n):
    if k2d[i]=='1':
      people.append(i)
  for j in people:
        for k in range(len(S[j])):
          if S[j][k][1]==1:
            if S[j][k][0]-1 not in people:
              ans=False
              break
          elif S[j][k][1]==0:
            if S[j][k][0]-1 in people:
              ans=False
              break
  return ans
                
n=int(input())#読み込み
S=[[] for i in range(n)]
for i in range(n):
  s=int(input())
  for j in range(s):
    S[i].append(list(map(int,input().split())))
#print(S)   
honests=[]

for i in range(2**n):
  if Jud(S,n,i)==True:
    i2d=format(i,'b')
    honests.append(i2d.count('1'))
#print(honests)
print(max(honests))

Measured memory_bytes: 3480
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1000000000;
typedef double D;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
//typedef pair<int, int> P;

/** Problem1244 : Molecular Formula **/
typedef long long ll;
map<string, int> list;
string s;
int pos;

ll formula()
{
	if ('A' <= s[pos] && s[pos] <= 'Z') {
		string t;
		t += s[pos++];
		if ('a' <= s[pos] && s[pos] <= 'z')
			t+=s[pos++];
		
		int times=0;
		while (isdigit(s[pos])) {
			times*=10;
			times+=s[pos]-'0';
			pos++;
		}
		
		return list[t]*(times!=0?times:1);
	} else if (s[pos] == '(') {
		pos++;
		ll a = 0;
		while (s[pos]!=')') {
			a+= formula();
		}
		pos++;
				
		int times=0;
		while (isdigit(s[pos])) {
			times*=10;
			times+=s[pos]-'0';
			pos++;
		}
		return a*(times!=0?times:1);
	}
}

int main()
{
	string t;
	while (cin>>t) {
		if (t == "END_OF_FIRST_PART")
			break;
		int a; cin>>a;
		list[t] = a;
	}
	
	while (cin>>s, s!="0") {
		s+='*';
		pos = 0;
		ll ans=0;
		while (s[pos] != '*') {
			ll a = formula();
			if (a==0) {
				cout << "UNKNOWN" << endl;
				goto end;
			} else {
				ans += a;
			}
		}
		cout << ans << endl;
	end:;
	}
}

Measured memory_bytes: 1228
n,m,q = map(int, input().split())

sets = [list(map(int, input().split())) for i in range(q)]

score = 0

a = [1] * n

def sco(a):
    scotem = 0
    for i in sets:
        if(a[i[1]-1] - a[i[0]-1] == i[2]):
            scotem += i[3]
    return scotem

flag = 1

while True:
    for i in range(n-1,-1,-1):
        flag = 0
        if(a[i] < m):
            flag = 1
            a[i] = a[i] + 1
            for j in range(n-1,i,-1):
                a[j] = a[i]
            if(sco(a) > score):
                score = sco(a)
            break
    if (flag == False):
        if(sco(a) > score):
            score = sco(a)
        break

print(str(score))


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

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

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

#define MAX 100005
#define INF 1001001001

int main(int, char**)
{
  int n;
  cin >> n;
  vector<int> a(n+1);
  rep(i,n) cin >> a[i];

  int q;
  cin >> q;
  int b, e;
  rep(i,q) {
    cin >> b >> e;
    reverse(a.begin()+b, a.begin()+e);
  }
  rep(i,n) {
    cout << a[i];
    if (i==n-1) cout << endl;
    else cout << " ";
  }

  return 0;
}



Measured memory_bytes: 3092