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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
// #define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int a, b; cin >> a >> b;
    if(a%3 == 0 || b%3 == 0 || (a+b)%3 == 0) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


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

int main(){
  long long n;
  long long ans=0;
  cin>>n;
  long long x=(long long)(sqrt(n));
  for(long long i=1;i<=x;i++){
    if(n%i==0&&i<(n/i-1)) ans+=(n/i-1);
  }
  cout<<ans<<endl;
}



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

int main(){
    int n,T;
    cin >> n >> T;
    vector<int> t(n);
    rep(i,n)cin >> t[i];
    sort(t.begin(),t.end());
    int ans = t[t.size()-1] + T;
    rep(i,n-1){
        int temp = t[i+1] - (T+t[i]);
        if(temp > 0)ans -= temp;
    }
    cout << ans << endl;

}

Measured memory_bytes: 1024
s = input()
t = input()

dp = [[0] * (len(t) + 1) for _ in range(len(s) + 1)]
# dp[i][j]: s[:i], t[:j] における最長共通部分列の長さ

for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1)
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j])
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1])

ans = ""
i = len(s)
j = len(t)
while (i>0 and j>0):
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        i -= 1
        j -= 1
        ans = s[i] + ans

print(ans)

Measured memory_bytes: 113628
//?????
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    int n;cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    vector<ll> x;
    ll tmp=1000,stock=0;
    rep(i,n-1){
        if(a[i+1]<a[i]){
            //手持ちをすべて売り飛ばす
            tmp+=a[i]*stock;
            stock=0;
        }else if(a[i]<a[i+1]){
            stock+=tmp/a[i];
            tmp%=a[i];
        }
    }
    tmp+=a[n-1]*stock;
    cout<<tmp<<endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define N 1000000
using namespace std;
int n,m;
int k[N];
int main(){
    cin>>n>>m;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        k[x]++;
    }
    sort(k+1,k+n+1);
    int sum=0;
    for(int i=1;i<=n-m;i++){
        sum+=k[i];
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main()
{
	int n;
	scanf("%d", &n);
	int *a = new int[n + 1];

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

	for (int i = 1; i <= n; ++i)
	{
		printf("node %d: key = %d, ", i, a[i]);
		if (i > 1)
			printf("parent key = %d, ", a[i / 2]);
		if (i * 2 <= n)
		{
			printf("left key = %d, ", a[i * 2]);
			if (i * 2 < n)
				printf("right key = %d, ", a[i * 2 + 1]);
		}
		printf("\n");
	}

	delete[] a;
	return 0;
}


Measured memory_bytes: 2660
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
A = LI()
A_tup = [(0, 0)] * N
for i in range(N):
    A_tup[i] = (A[i], i)
A_tup.sort(reverse=True)

dp = [[0] * (N + 1) for i in range(N + 1)]
dp[0][0] = 0
for i in range(N):
    pi = A_tup[i][1]
    for j in range(i + 1):
        k = i - j
        dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + (pi - j) * A_tup[i][0])
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + (N - k - 1 - pi) * A_tup[i][0])

ans = 0
for i in range(N):
    ans = max(ans, dp[N][i])
print(ans)

Measured memory_bytes: 106388
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<map>
#include <algorithm>
#include<cstdlib>
#include<cmath>
#include<deque>
#include <numeric>
#include<valarray>
typedef unsigned long long ull;
typedef  long long ll;

typedef std::pair<ll, ll> pair;

int main() {
	ll  n , m ;
	std::cin >> n >> m ;

	std::vector<pair> pair_vec(n);

	for (int i = 0; i < n; i++) {

		std::cin >> pair_vec[i].first >> pair_vec[i].second;
	}
	std::sort(
		pair_vec.begin(),
		pair_vec.end(),
		[](const pair& x, const pair& y) {return x.first < y.first; }
	);
	ll tmpm = 0;
	ll outcount = 0;
	while(m > pair_vec[tmpm].second)
	{
		outcount += pair_vec[tmpm].first * pair_vec[tmpm].second;
		m -= pair_vec[tmpm].second;
		tmpm += 1;
	}
	if (m > 0) outcount += m * pair_vec[tmpm].first;

	std::cout << outcount << std::endl;
	return 0;
}

Measured memory_bytes: 1792
//https://arc100.contest.atcoder.jp/tasks/arc100_c
//sos dp维护子集里面的最大的两个值  
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
const int N=1e6;
ll dp[N+100][2],a[N+100];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<(1<<n);i++) cin>>a[i];
	
	for(int i=0;i<1<<n;i++)
	{
		dp[i][0]=a[i];
		dp[i][1]=-0x3f3f3f3f3f3f3f3f;
	}
	for(int i=0;i<n;i++)
	{
		for(int j=(1<<n)-1;j>=0;j--)
		{
			if(j>>i&1)//维护子集里面最大的两个值 
			{
				dp[j][1]=max(dp[j][1],dp[j^(1<<i)][0]);
				if(dp[j][0]<dp[j][1]) swap(dp[j][0],dp[j][1]);
				dp[j][1]=max(dp[j][1],dp[j^(1<<i)][1]);
			}
		}
	}
	ll ans=0;
	for(int i=1;i<1<<n;i++)
	{
		ans=max(ans,dp[i][0]+dp[i][1]);
		cout<<ans<<endl;
	} 
	return 0;
} 

Measured memory_bytes: 13312
#include <bits/stdc++.h>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
int N, M, S;

int main(void){
	//IO("test.in", "test.out");
	scanf("%d", &N);
	for(int i = 0; i < N; i++){
		int n;
		scanf("%d", &n);
		S += n;
		if(n > M) M = n;
	}
	if(S - M > M) printf("Yes\n");
	else printf("No\n");
}

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

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


int main(){
	
	int a, b, max;
	cin >> a >> b;
	
	max = a + b;
	
	if( max < a - b ){
		max = a - b;
	}
	
	if( max < a * b ){
		max = a * b;
	}
	
	cout << max << endl;
	
	return 0;
}

Measured memory_bytes: 256
import sys
table = [0]*26
 
letters = "abcdefghijklmnopqrstuvwxyz"
input_str = sys.stdin.read()
 
for A in input_str:
    index = 0
    for B in letters:
        if A == B or A == B.upper():
            table[index] += 1
            break
        index += 1
 
for i in range(len(letters)):
    print("%s : %d"%(letters[i],table[i]))


Measured memory_bytes: 5560
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

const int VMAX=100100;
int V,E;
vector<vector<pair<int,int>>> edge;
bool used[VMAX];
long long MST(int start){
    if(V==1) return 0;
    rep(i,VMAX) used[i]=0;
    // {cost,{from,to}}
    priority_queue<pair<int,pair<int,int>>,vector<pair<int,pair<int,int>>>,greater<pair<int,pair<int,int>>>> pq;
    for(auto e:edge[start]){
        pq.push({e.second,{start,e.first}});
    }
    long long ret=0;
    int cnt=1;
    while(pq.size()||cnt<V){
        auto e=pq.top(); pq.pop();
        int cost=e.first,from=e.second.first,to=e.second.second;
        used[from]=1;
        if(!used[to]){
            ret+=cost;
            used[to]=1;
            cnt++;
            for(auto e:edge[to]){
                pq.push({e.second,{to,e.first}});
            }
        }
    }
    return (cnt==V?ret:-1);
}
int main(){
    cin>>V;
    pair<pair<int,int>,int> vx[V],vy[V];
    rep(i,V){
        int x,y; cin>>x>>y;
        vx[i]={{x,y},i};
        vy[i]={{y,x},i};
    }
    sort(vx,vx+V); sort(vy,vy+V);
    edge.resize(V);
    rep(i,V-1){
        int from=vx[i].second,to=vx[i+1].second,cost=abs(vx[i].first.first-vx[i+1].first.first);
        edge[from].push_back({to,cost});
        edge[to].push_back({from,cost});
        from=vy[i].second,to=vy[i+1].second,cost=abs(vy[i].first.first-vy[i+1].first.first);
        edge[from].push_back({to,cost});
        edge[to].push_back({from,cost});
    }
    cout<<MST(0)<<endl;
    return 0;
}


Measured memory_bytes: 14580
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef pair<double,double> PD;
typedef priority_queue<P,vector<P>,greater<P> > P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd> > Pd_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-6;

#define _GLIBCXX_DEBUG
#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end())

void Add(ll &a, ll b){
    a=(a+b)%mod;
    return;
}

void Pro(ll &a, ll b){
    a=(a*b)%mod;
    return;
}


int main(){
    ll N; cin>>N;
    vec A,B;
    rep(i,N){
        ll x,y; cin>>x>>y;
        A.pb(x+y);
        B.pb(x-y);
    }
    sort(ALL(A));
    sort(ALL(B));
    ll ans=max(A[N-1]-A[0],B[N-1]-B[0]);
    cout<<ans<<endl;

}

Measured memory_bytes: 6644
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn =1e5+10;
const int mod=1e9+7;
int s;
ll ans[2010];


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ans[3]=ans[4]=ans[5]=1;
    for(int i=6;i<=2000;i++)
    {
        ans[i]=1;
        for(int j=3;j<=i-3;j++)
        {
            ans[i]+=ans[j];
            ans[i]%=mod;
        }
    }
    cin>>s;
    cout<<ans[s]<<'\n';





}


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

#define ULL unsigned long long
#define LL long long

#define P pair<int, int>

#define pb push_back
#define mp make_pair
#define pp pop_back

#define lson root << 1
#define rson root << 1 | 1

#define INF32 (int)1e9 + 7
#define INF64 (long long)1e18

#define sc(x) scanf("%d", &x)
#define pr(x) printf("%d\n", x)

#define mem(arry, in) memset(arry, in, sizeof(arry))

#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define BEGIN() int T; sc(T); while(T--)

#define rep(i, aa, bb) for (int i = aa; i < bb; ++i)
#define Rep(i, aa, bb) for (int i = aa; i <= bb; ++i)

#define Size(x) (int)(x).size()
#define Range(x) (x).begin(), (x).end()

using namespace std;

/*
namespace fastIO {
    #define BUF_SIZE 100000
    bool IOerror = 0;
    inline char nc() {
        static char buf[BUF_SIZE], *p1 = buf + BUF_SIZE, *pend = buf + BUF_SIZE;
        if(p1 == pend) {
            p1 = buf;
            pend = buf + fread(buf, 1, BUF_SIZE, stdin);
            if(pend == p1) {
                IOerror = 1;
                return -1;
            }
        }
        return *p1++;
    }
    inline bool blank(char ch) {
        return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
    }
    inline void read(int &x) {
        char ch;
        while(blank(ch = nc()));
        if(IOerror) return;
        for(x = ch - '0'; (ch = nc()) >= '0' && ch <= '9'; x = x * 10 + ch - '0');
    }
    #undef BUF_SIZE
};
using namespace fastIO;
*/
/*
void print64mul(LL x, LL y) {
#if __SIZEOF_INT128__ == 16
  __int128 res = __int128(x) * y;
  char ch[64];
  int ptr = 0;
  if (res == 0) {
    puts("0");
    return;
  }
  while (res) {
    ch[ptr] = (res % 10) + '0';
    ptr++;
    res /= 10;
  }
  while (ptr)
    putchar(ch[--ptr]);
  putchar('\n');
#else
  constexpr LL limit = 1000000000;
  LL dig[4] = {0};
  dig[0] = x % limit;
  dig[1] = x / limit;
  dig[0] *= y;
  dig[1] *= y;
  dig[1] += dig[0] / limit;
  dig[0] %= limit;
  dig[2] += dig[1] / limit;
  dig[1] %= limit;
  int pos = 2;
  while (pos > 0) {
    if (dig[pos]) break;
    pos--;
  }
  printf("%d", dig[pos]);
  while (pos > 0) {
    pos--;
    printf("%09d", dig[pos]);
  }
  puts("");
#endif
}
*/

const int N = 100005;

int n;
int a[N], b[N];

priority_queue<P> p, q;

int main()
{
    cin >> n;
    Rep(i, 1, n) {
        int x;
        cin >> x;
        if (i & 1) a[x]++;
        else b[x]++;
    }

    rep(i, 1, N) {
        p.push(P(a[i], i));
        q.push(P(b[i], i));
    }

    P t1 = q.top();
    q.pop();
    P t2 = q.top();
    q.pop();

    P s1 = p.top(); p.pop();
    P s2 = p.top(); p.pop();

    if (t1.second != s1.second) cout << (n - t1.first - s1.first) << endl;
    else cout << min(n - t1.first - s2.first, n - s1.first - t2.first) << endl;

    return 0;
}



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

const ll p = 1e9 + 7;
ll n, m, k, ans;
ll fac[N], inv[N], san[N];

ll fpow(ll a, ll b)
{
    ll ans = 1;
    while(b)
    {
        if(b & 1) ans = ans * a % p;
        a = a * a % p; b >>= 1;
    }
    return ans;
}

ll C(ll n, ll m)
{
    if(n < m || n < 0 || m < 0) return 0;
    return fac[n] * inv[m] % p * inv[n - m] % p;
}

int main()
{
    scanf("%lld%lld%lld", &n, &m, &k);
    ll t = n + m + k;
    fac[0] = inv[0] = san[0] = 1;
    for(int i = 1; i <= t; i ++)
    {
        fac[i] = fac[i - 1] * i % p;
        san[i] = san[i - 1] * 3 % p;
    }
    //for(int i = 1; i <= 5; i ++) printf("%lld %lld %lld", fac[i], inv[i], san[i]), system("pause");
    inv[t] = fpow(fac[t], p - 2);
    for(int i = t - 1; i; i --) inv[i] = inv[i + 1] * (i + 1) % p;
    ll t1 = 0, t2 = 1;
    for(int i = 0; i <= m + k; i ++)
    {
        t = C(n + i - 1, n - 1) * san[m + k - i] % p;
        //printf("%lld", t); system("pause");
        t = t * (t2 - t1 + p) % p;
        t2 = (t2 * 2 % p - C(i, m) + p) % p;
        t1 = ((t1 * 2 % p - C(i, i - k - 1) + p) % p + C(i + 1, i - k)) % p;
        ans = (ans + t) % p; 
        //printf("%lld %lld", ans, t); system("pause");
    }
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 22912
#include <bits/stdc++.h>
using namespace std;
int n,m;
vector <int> A[100002];
int vs[100002],root,fa[100002];
int d[100002],need[100002];
void dfs(int u)
{
    vs[u]=1;
    for (int v:A[u])
        d[v]++;
    for (int v:A[u])
        if (d[v]==need[v]&&vs[v]==0)
        {
            dfs(v);
            fa[v]=u;
        }
}
int main()
{
    cin>>n>>m;
    for (int i=1;i<=n+m-1;i++)
    {
        int a,b;cin>>a>>b;need[b]++;
        A[a].push_back(b);
    }
    for (int i=1;i<=n;i++)
        if (need[i]==0) root=i;
    dfs(root);
    for (int i=1;i<=n;i++)
        cout<<fa[i]<<'\n';
}


Measured memory_bytes: 12544
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;

int main(){
    int n;
    ll k;
    cin >> n >> k;
    vector<ll> v(n);
    for(int i = 0; i < n; i++)  cin >> v[i];
    sort(v.begin(), v.end());
    auto f = [&](ll x)->int{
        return lower_bound(v.begin(),v.end(),x)-v.begin();
    };
    auto g = [&](ll x)->int{
        return upper_bound(v.begin(),v.end(),x)-v.begin();
    };
    ll l = -1e18-1, r = 1e18;
    while(r-l > 1){
        ll mid = (r+l)/2;
        ll tmp = 0;
        for(int i = 0; i < n; i++){
            if(mid <= 0){
                if(v[i] == 0){
                    tmp += (mid==0 ? n-i-1 : 0);
                }else if(v[i] > 0){
                    continue;
                }else if(v[i] < 0){
                    tmp += n-f((abs(mid)+abs(v[i])-1)/abs(v[i]));
                }
            }else if(mid > 0){
                if(v[i] == 0){
                    tmp += n-i-1;
                }else if(v[i] < 0){
                    tmp += n-f(0);
                    tmp += f(0)-max(i+1,f(-(mid/(-v[i]))));
                }else{
                    if(v[i]*v[i] > mid) continue;
                    tmp += g(mid/v[i])-(i+1);
                }
            }
        }
        if(tmp < k) l = mid;
        else        r = mid;
    }
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}

int32_t main()
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);
	// cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

// good and short method....
	string s, t; int q, i, k, f; char c;
	cin >> s >> q;
	zip(i, 0, q)
	{
		cin >> k;
		if (k == 1)
		{
			swap(s, t);
		}
		else
		{
			cin >> f >> c;
			if (f == 1)
				t = t + c;
			else
				s = s + c;
		}
	}
	reverse(all(t));
	t = t + s;
	cout << t << en;

	// string s;
	// cin >> s;
	// string a = "12";
	// int q;
	// cin >> q;
	// int t;
	// int f;
	// char c;
	// string x;
	// int var = 0;
	// //a = s;
	// zip(i, 0, q)
	// {
	// 	cin >> t;
	// 	if (t == 1)
	// 	{
	// 		var++;
	// 	}
	// 	else
	// 	{
	// 		cin >> f >> c;
	// 		if (f == 1)
	// 		{
	// 			x = c;
	// 			if (var % 2)
	// 			{
	// 				a =  a + x;
	// 			}
	// 			else
	// 			{
	// 				a = x + a;
	// 			}
	// 		}
	// 		else
	// 		{
	// 			x = c;
	// 			if (var % 2)
	// 			{
	// 				a = x + a;
	// 			}
	// 			else
	// 			{
	// 				a = a + x;
	// 			}
	// 		}
	// 	}
	// }
	// if (var % 2)
	// {
	// 	reverse(all(a));
	// }
	// //cout << a << en;
	// //return 0;
	// string y = s;
	// reverse(all(y));
	// for (int i = 0; i < a.size(); i++)
	// {
	// 	if (a[i] == '1' || a[i] == '2')
	// 	{
	// 		if (a[i] == '1')
	// 		{
	// 			cout << s;
	// 			i++;
	// 		}
	// 		else
	// 		{
	// 			cout << y;
	// 			i++;
	// 		}
	// 	}
	// 	else
	// 	{
	// 		cout << a[i];
	// 	}
	// }
	// cout << en;


	return 0;
}



Measured memory_bytes: 1708
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

//typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)));
#define Mx(a , b) ((a) > (b) ? (a) : (b))
#define Mn(a , b) ((a) < (b) ? (a) : (b))

const double EPS = 1e-10;
const int INF = 2147483647;

int N , Q , L;
int x[100001];
int dp[100001][20];

int main(){
	scanf("%d" , &N);
	for(int i = 1 ; i <= N ; ++i){
		scanf("%d" , x + i);
	}
	scanf("%d%d" , &L , &Q);
	int y = 1;
	for(int i = 1 ; i <= N ; ++i){
		while(x[y] + L < x[i]){
			dp[y][0] = i - 1;
			++y;
		}
	}
	for(; y <= N ; ++y){
		dp[y][0] = N;
	}
	for(int j = 1 ; j < 20 ; ++j){
		for(int i = 1 ; i <= N ; ++i){
			dp[i][j] = dp[dp[i][j - 1]][j - 1];
		}
	}
	int a , b , c , d;
	for(int i = 0 ; i < Q ; ++i){
		scanf("%d%d" , &a , &b);
		if(a > b){
			a ^= b;
			b ^= a;
			a ^= b;
		}
		c = 0;
		for(int j = 19 ; j >= 0 ; --j){
			if(dp[a][j] < b){
				c += (1 << j);
				a = dp[a][j];
				d = 0;
			} else {
				d = j;
			}
		}
		printf("%d\n" , c + (1 << d));
	}
	return 0;
}


Measured memory_bytes: 8960
#include<stdio.h>
int main(void){
 
int a,b;
scanf("%d %d",&a,&b);
 
if(a<b){
 printf("a < b\n");
}else if(a>b){
 printf("a > b\n");
}else if(a==b){
 printf("a == b\n");
}
 
return 0;
 
}

Measured memory_bytes: 1804
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int MOD = 1e9 + 7;

int add(int a, int b)
{
	a+=b;
	while(a>=MOD) a-=MOD;
	return a;
}

int mult(int a, int b)
{
	return (a*1LL*b)%MOD;
}

int powe[411][411];

int get(int l, int r, int k)
{
	if(l==0) return powe[r][k];
	else return add(powe[r][k],MOD-powe[l-1][k]);
}

int l[411];
int r[411];
int dp[411][411];
int po[411][411];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n, c; cin>>n>>c;
	for(int i=0;i<n;i++) cin>>l[i];
	for(int i=0;i<n;i++) cin>>r[i];
	for(int k=1;k<=400;k++)
	{
		po[k][0]=1;
		for(int z=1;z<=400;z++)
		{
			po[k][z]=mult(po[k][z-1],k);
		}
	}
	for(int k=0;k<=400;k++)
	{
		powe[0][k] = 0;
		for(int i=1;i<=400;i++)
		{
			powe[i][k] = add(powe[i-1][k], po[i][k]);
		}
	}
	for(int i=0;i<=c;i++)
	{
		dp[0][i] = get(l[0],r[0],i);
	}
	for(int i=1;i<n;i++)
	{
		for(int j=0;j<=c;j++)
		{
			for(int k=0;k<=j;k++)
			{
				dp[i][j]=add(dp[i][j], mult(dp[i-1][j-k], get(l[i],r[i],k)));
			}
		}
	}
	cout<<dp[n-1][c]<<'\n';
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	ll n,k;
	ll l=0,r=0;
	ll x[100001]={};
	ll total=100000000000;

	cin>>n>>k;

	for(ll i=1; i<n+1; i++){
		cin>>x[i];
	}

	for(ll i=1; i<n-k+2; i++){
		l=abs(x[i])+abs(x[i]-x[i+(k-1)]);
		r=abs(x[i+(k-1)])+abs(x[i+(k-1)]-x[i]);
		total=min(total,l);
		total=min(total,r);
	}
	cout<<total<<endl;

	return 0;
}


Measured memory_bytes: 1024
n = int(input())
a = []
for i in range(1,n+1):
    cnt = 0
    b = i
    while b % 2 == 0:
        b //= 2
        cnt += 1
    a.append([i,cnt])

a.sort(key=lambda x:x[1],reverse=True)
print(a[0][0])


Measured memory_bytes: 2940
N = int(input())
C = [ 0 for i in range(4) ]
s2num = {"AC":0, "WA":1, "TLE":2, "RE":3}
num2s = {0:"AC", 1:"WA", 2:"TLE", 3:"RE"}
# read
for i in range(N):
    num = s2num[ input() ]
    C[num] += 1
    #print(num)
# print
for i in range(4):
    print("{} x {}".format( num2s[i], C[i] ))




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

typedef long long ll;
#define FOR(i, a, b) for (ll i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl

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

	ll X;	cin>>X;
	FOR(i,-120,120){
		FOR(j,-120,120){
			if(i*i*i*i*i-j*j*j*j*j==X){
				cout<<i<<" "<<j<<endl;
				return 0;
			}
		}
	}
	
	

    return 0;
}




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

using namespace std;

using ll = long long;

const ll INF = 1LL << 60;

int main() {
    int N, L;
    cin >> N >> L;
    vector<int> v(N);
    for (int i = 0; i < N; ++i) v[i] = L + i;
    ll ans = INF;
    for (int i = 0; i < N; ++i) {
        if (abs(v[i]) < abs(ans)) ans = v[i];
    }
    cout << accumulate(v.begin(), v.end(), 0) - ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pb push_back
#define pii pair<long long,long long>
#define endl '\n'
#define N 300001
vector<vector<int>> dp;
int func(vector<int> &wt,vector<int> &val,int i, int w)
{
    if(w<0)
    return LLONG_MIN;
    if(i==val.size() || w==0)
    return 0;
    if(dp[i][w]!=-1)
    return dp[i][w];
    int ans=0;
    ans=max(val[i]+func(wt,val,i+1,w-wt[i]),func(wt,val,i+1,w));
    return dp[i][w]=ans;
}
void solve()
{
    int n; cin>>n;
    int w; cin>>w;
    vector<int> wt(n),val(n);
    for(int i=0;i<n;i++)
    cin>>wt[i]>>val[i];
    dp.assign(n+1,vector<int>(w+1,-1));
    func(wt,val,0,w);
    cout<<dp[0][w]<<endl;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test; test=1;
    while(test--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 80256
N = int(input())
S = list(input())

LARGE = 10 ** 9 + 7

res = 1
arrows = 0

for i in range(2 * N):
    if arrows == 0 and S[i] == "W":
        res = 0
        break
    if S[i] == "B" and arrows % 2 == 0:
        arrows += 1
    elif S[i] == "W" and arrows % 2 == 1:
        arrows += 1
    else:
        res *= arrows
        res %= LARGE
        arrows -= 1

if arrows > 0:
    res = 0


for i in range(1, N + 1):
    res *= i
    res %= LARGE

if __name__ == "__main__":
    print(res)


Measured memory_bytes: 4916
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int p[] = new int[n];
    int sum = 0;
    for(int i = 0 ; i < n ; ++i){
      p[i] = sc.nextInt();
    }
    Arrays.sort(p);
    for(int i = 0 ; i < k ; ++i){
      sum += p[i];
    }
    System.out.println(sum);
    
  }
}


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

using namespace std;

#define int long long
#define endl '\n'
#define MOD 1000000007
#define maxn 100010

vector<int> g[maxn];
int dist[maxn], parent[maxn], n, m, src;
//
//
//void dijkstra(int src) {
//    memset(dist, 63, sizeof dist);
//    int inf = dist[0];
//    dist[src] = 0;
//    set<pair<int, int>> q;
//
////    dist , node
//    q.insert({0, src});
//    while (!q.empty()) {
//        int len = q.begin()->first;
//        int node = q.begin()->second;
//
//        q.erase({len, node});
//        for (auto x: g[node]) {
//            if (dist[x.first] > dist[node] + x.second) {
//                q.erase({dist[x.first], x.first});
//                parent[x.first] = node;
//                dist[x.first] = x.second + dist[node];
//                q.insert({dist[x.first], x.first});
//            }
//        }
//    }
//    for (int i = 0; i < n; i++)
//        if (dist[i] == inf)
//            cout << "INF" << endl;
//        else
//            cout << dist[i] << endl;
//}

vector<pair<pair<int, int>, int>> ed;

void bellman(int src) {
    memset(dist, 63, sizeof dist);
    int inf = dist[0];

    dist[src] = 0;
    int xx;
    for (int i = 0; i < n; i++) {
        xx = -1;
        for (auto x: ed) {
            if (dist[x.first.first] < inf and dist[x.first.first] + x.second < dist[x.first.second]) {
                dist[x.first.second] = x.second + dist[x.first.first];
                xx = 2;
            }
        }
    }
    if (xx == -1) {
        for (int i = 0; i < n; i++)
            if (dist[i] == inf)
                cout << "INF" << endl;
            else
                cout << dist[i] << endl;
    } else
        cout << "NEGATIVE CYCLE" << endl;
}

bool comp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
    return a.second < b.second;
}

int sz[maxn], p[maxn];

void init(int n) {
    for (int i = 0; i <= n; i++)
        p[i] = i, sz[i] = 1;
}

int find(int n) {
    return (n == p[n]) ? n : p[n] = find(p[n]);
}

bool unite(int a, int b) {
    a = find(a);
    b = find(b);

    if (a == b)
        return false;
    if (sz[b] > sz[a])
        swap(a, b);
    sz[a] += sz[b];
    p[b] = a;
    return true;
}

void mst() {
    sort(ed.begin(), ed.end(), comp);
    int ans = 0;
    for (auto x:ed) {
        if (unite(x.first.first, x.first.second))
            ans += x.second;
    }
    cout << ans << endl;
}

deque<int> top;
int visited[maxn];

void dfs(int u) {
    visited[u] = true;
    for (auto x:g[u]) {
        if (!visited[x])
            dfs(x);
    }
    top.push_front(u);
}

void solve() {
    cin >> n >> m;

    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;

        g[a].push_back(b);
    }

    for (int i = 0; i < n; i++) {
        if (!visited[i])
            dfs(i);
    }
    for (auto x:top)
        cout << x << endl;
//    dijkstra(src);
//    bellman(src);
//    init(n + 1);
//    mst();
}

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

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}


Measured memory_bytes: 6164
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const int mod = 1e9 + 7;

const int m = 2019;

int main()
{
    long long n;
    cin >> n;
    int A = -mod, I = mod;
    long long sum = 0;
    for (long long i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        A = max(A, x);
        I = min(I, x);
        sum += x;
    }

    cout << I << " " << A << " " << sum << endl;
    ;

    return 0;
}


Measured memory_bytes: 3120
<?php
  $n = trim(fgets(STDIN));
  $c = trim(fgets(STDIN));
  $cnt = 0;
  for($i=0; $i<$n; $i++){
      if($c[$i] == "R"){
          $cnt++;
      }
  }
  $ans = 0;
  for($j=0; $j<$cnt; $j++){
      if($c[$j] == "W"){
          $ans++;
      }
  }
  echo $ans;

Measured memory_bytes: 16484
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair

using namespace std;

const double EPS = 1e-10;

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef long long ll;

int main(){
    map<int, double> memo;
    for(int i = 1; i <= 1000; i++){
        double valor = 0.0;
        for(int j = i; j > 0; j--){
            if((double)j/i < EPS) break;
            valor += (double)j/i;
        }
        memo[i] = valor;        
    }
    
    int n, k; scanf("%d %d", &n, &k);
    vector<double> vd(n);        
    for(int i = 0; i < n; i++){
        int ent;
        scanf("%d", &ent);        
        vd[i] = memo[ent];
    }
    //for(int i = 0; i < (int)vd.size(); i++)
    //    cout << vd[i] << " ";
    //cout << endl;
    double ans = 0.0;
    double teste = 0.0;
    for(int i = 0; i < n; i++){            
        teste += vd[i];
        if(i >= k){
            teste -= vd[i-k];
            //cout << i << " - " << vd[i-k] << endl;
         }
        //cout << "i - " << teste << endl;
        if( ans+EPS <= teste )
            ans = teste;
    }
    printf("%.12lf\n", ans);
    return 0;
}


Measured memory_bytes: 1920
N = int(input())
#nを因数分解する
#arr = [素因数,個数] のリスト
#n==1 のとき [1,1] となるので注意
arr = []

def factorization(n):
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i ==0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr

for i in range(2,N+1):
    factorization(i)

result = []
for i in range(2,N+1):
    c = 0
    for j in range(len(arr)):
        if i == arr[j][0]:
            c += arr[j][1]
    if c > 0:
        result.append([i,c])

ans = 1
for i in range(len(result)):
    ans *= result[i][1]+1
    ans %= 1000000007

print(ans)

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

int main(void) {
	const double r = 380000.0;
	int N;
	double dx;
	string su;
	cin >> N;
	double ans = 0.0;
	for (int i = 0; i < N; ++i) {
		cin >> dx >> su;
		if (su == "JPY")
			ans += dx;
		else
			ans += dx * r;
	}

	cout << fixed << setprecision(8) << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
#define mp make_pair
using namespace std;
int main(){
	ll n,ans=0;
	cin>>n;
	vector<ll> a;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		a.pb(x);
	}
	sort(a.begin(),a.end());
	map<ll,ll> mp;
	for(int i=0;i<n;i++){
		mp[ a[i] ]++;
	}
	for(int i=0;i<n;i++){
		if( mp[a[i]]<a[i]){
			ans += mp[a[i]];
			mp[a[i]]=0;
		}
		if( mp[a[i]]>a[i]){
			ans += mp[a[i]]-a[i];
			mp[a[i]]=a[i];
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 7028
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node{
    int key;
    Node *r,*l,*p;
};

Node*root,*NIL;

void insert(int k){
    Node *y=NIL;
    Node *x=root;
    Node *z;

    z=(Node *)malloc(sizeof(Node));
    z->key=k;
    z->l=NIL;
    z->r=NIL;
    
    while(x!=NIL){
        y=x;
        if(z->key<x->key){
            x=x->l;
        }
        else {
            x=x->r;
        }
    }
    z->p=y;
    if(y==NIL){
        root=z;
    }
    else {
        if(z->key<y->key){
            y->l=z;
        } 
        else{
            y->r=z;
        }
    }
}
 
void inorder(Node *u){
     if(u==NIL)return;
     inorder(u->l);
     printf(" %d",u->key);
     inorder(u->r);
}
 void preorder(Node *u){
     if(u==NIL)return;
     printf(" %d",u->key);
     preorder(u->l);
     preorder(u->r);
}

int main(){
    int n,i,x;
    string com;
    
    scanf("%d",&n);
    
    for(i=0;i<n;i++){
        cin>>com;
        if(com=="insert"){
            scanf("%d",&x);
            insert(x);
        }
        else if(com=="print"){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 26736
#include <iostream>

using namespace std;

int main()
{
    int n; cin >> n;
    int ans = 0;

    // i: target number
    for (int i = 1; i <= n; i +=2) {
        int divisorCount = 0;
        for (int j = 1; j <= i; j++) {
            if (i % j == 0) divisorCount++;
        }
        if (divisorCount == 8) ans++;
    }

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

Measured memory_bytes: 256
s = list(input())
if s[0]=="A":
  s[0] = "a"
  flag = False
  for i, ele in enumerate(s[2:-1], 2):
    if ele == "C":
      s[i] = "c"
      flag = True
      break
  if flag and str(s).islower():
    print("AC")
  else:
    print("WA")
else:
  print("WA")

Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<math.h>
using namespace std;
int a[107];
int sum[107];
int main()
{
    int n,ans=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    memset(sum,0,sizeof(sum));
    for(int i=1;i<=n;i++)
        ans+=a[i];
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=i;j++)
        {
            sum[i]+=a[j];
        }
        sum[i]=abs(ans-sum[i]-sum[i]);
    }
    for(int i=2;i<=n;i++)
        if(sum[i]<sum[1])
            sum[1]=sum[i];
        printf("%d",sum[1]);
    return 0;
}


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

int main()
{
	double a, b, c, d, e, f, x, y;
	
	while(cin>>a>>b>>c>>d>>e>>f){
		y = (c*d-a*f)/(b*d-a*e);
		x = (c-b*y)/a;

        cout << fixed << setprecision(3) << x << " " << y << "\n";
	}
	
	return 0;
}

Measured memory_bytes: 1284
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

vector<ll> fac(MAX), finv(MAX), inv(MAX);

void comInit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(ll i=2; i<MAX; i++){
        fac[i] = fac[i-1]*i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}


ll com(ll n, ll k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

int main(){
    char c; cin >> c;
    if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'){
        cout << "vowel" << endl;
    }else{
        cout << "consonant" << endl;
    }
}

Measured memory_bytes: 12160
from collections import deque

X, Y, A, B, C = [int(x) for x in input().split()]
p = sorted([int(x) for x in input().split()], reverse=True)[:X]
q = sorted([int(x) for x in input().split()], reverse=True)[:Y]
pq = deque(sorted(p + q, reverse=True))
r = deque(sorted([int(x) for x in input().split()]))

ans = sum(pq)

for i in range(len(r)):
    if r[-1] > pq[-1]:
        ans += r.pop() - pq.pop()

print(ans)

Measured memory_bytes: 109932
n,k = map(int, input().split())
 
ans = 0
mod = 10**9+7
 
for i in range(k,n+2):
    ans += int((n*(n+1)/2 - (n-i)*(n-i+1)/2 - (i-1)*i/2 +1))
 
print(ans%mod)


Measured memory_bytes: 9096
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i < b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	ll H, W;
	cin >> H >> W;

	ll ans = H * W;
	ll s[3];

	for (int i = 0; i < 2; i++)
	{
		for (ll h = 1; h < H; h++)
		{
			//縦割り
			s[0] = h * W;
			s[1] = (H - h) * (W / 2);
			s[2] = H * W - (s[0] + s[1]);
			sort(s, s + 3);
			ans = min(ans, s[2] - s[0]);

			//横割り
			s[0] = h * W;
			s[1] = ((H - h) / 2) * W;
			s[2] = H * W - (s[0] + s[1]);
			sort(s, s + 3);
			ans = min(ans, s[2] - s[0]);
		}
		//90度回転
		swap(H, W);
	}

	out(ans);

	return 0;
}

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

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    ll K,X,Y;
    vector<pair<ll,ll>> ans;
    cin>>K>>X>>Y;
    if(abs(X)+abs(Y)==K){
        cout<<1<<endl;
        cout<<X<<" "<<Y<<endl;
        return 0;
    }
    bool flag_x=false;
    bool flag_y=false;
    bool flag_xy=false;
    if(X<0){
        X=abs(X);
        flag_x=true;
    }

    if(Y<0){
        Y=abs(Y);
        flag_y=true;
    }

    if(X<Y){
        swap(X,Y);
        flag_xy=true;
    }

    if(K%2==0&&(X+Y)%2==1){
        cout<<-1<<endl;
        return 0;
    }

    ll x=0;
    ll y=0;
    ll pos=0;
    ll n;
    ll c=(K-(X+Y)%K)%K;

    if(X+Y<K&&(X+Y)%2==1){
        n=3;
        ll len1=K-X;
        ll len2=X+(K+X-Y)/2;
        ll len3=K-X+Y;
        ll len4=(K+X-Y)/2;
        while(pos<3*K){
            pos+=K;
            if(pos<=len1){
                x=0;
                y=-pos;
            }else if(pos<=len1+len2){
                x=pos-len1;
                y=-len1;
            }else if(pos<=len1+len2+len3){
                x=len2;
                y=pos-(len1+len2)-len1;
            }else if(pos<=len1+len2+len3+len4){
                x=len2-(pos-(len1+len2+len3));
                y=len3-len1;
            }
            ans.push_back(make_pair(x,y));
        }

    }else{
        if(X+Y<K&&(X+Y)%2==0) n=2;
        else if(X+Y>=K&&c%2==0){
            n=(X+Y)/K;
            if((X+Y)%K!=0) n++;
        }else if(X+Y>=K&&c%2==1){
            n=(X+Y)/K+1;
            if((X+Y)%K!=0) n++;
        }

        ll len1=(K*n-X-Y)/2;
        ll len2=X;
        ll len3=(K*n-X+Y)/2;

        while(pos<n*K){
            pos+=K;
            if(pos<=len1){
                x=0;
                y=-pos;
            }else if(pos<=len1+len2){
                x=pos-len1;
                y=-len1;
            }else if(pos<=len1+len2+len3){
                x=len2;
                y=(pos-(len1+len2))-len1;
            }
            ans.push_back(make_pair(x,y));
        }
        
    }

    cout<<ans.size()<<endl;
    REP(i,ans.size()){
        if(flag_xy){
            swap(ans[i].first,ans[i].second);
        }

        if(flag_x){
            ans[i].first*=-1;
        }

        if(flag_y){
            ans[i].second*=-1;
        }
        cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }




}

Measured memory_bytes: 7408
#include <bits/stdc++.h>
#define pb		  push_back
#define pairs	  pair<int, int>
#define vi		  vector<int>
#define vb		  vector<bool>
#define vii		  vector<pairs>
#define lb		  lower_bound
#define ub		  upper_bound
#define lli		  long long int
#define endl	  '\n'
#define FastInput ios_base::sync_with_stdio(false), cin.tie(NULL);
#define Cases	  cout << "Case " << ++Case << ": ";
#define __test    \
	int tt;       \
	int Case = 0; \
	cin >> tt;    \
	while (tt--)
#define read(x)	 freopen(x, "r", stdin)
#define write(x) freopen(x, "w", stdout)
#define InputArray(a, n)        \
	for (int i = 0; i < n; i++) \
		cin >> a[i];
#define CopyArray(a, temp, n)   \
	for (int i = 0; i < n; i++) \
		temp[i] = a[i];
#define PrintArray(a, n)        \
	for (int i = 0; i < n; i++) \
		cout << a[i] << " ";    \
	cout << endl;
using namespace std;

int n, m, q;
vi a, b, c, d;
vi A;
int ans = 0;

int check() {
	int res = 0;
	for (int i = 0; i < q; i++) {
		if (A[b[i]] - A[a[i]] == c[i]) {
			res += d[i];
		}
	}
	return res;
}

void dfs(int i, int cur) {
	if (i >= n) {
		ans = max(ans, check());
		return;
	}
	for (int j = cur; j <= m; j++) {
		A.push_back(j);
		dfs(i + 1, j);
		A.pop_back();
	}
}


int main() {
	cin >> n >> m >> q;
	a = b = c = d = vi(q);
	for (int i = 0; i < q; i++) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--;
		b[i]--;
	}

	dfs(0, 1);

	cout << ans << endl;

	cerr << "time = " << (clock() / CLOCKS_PER_SEC) << " sec" << '\n';
	return 0;
}




Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

void ABC100D()
{
	int N, M;
	cin >> N >> M;
	vector<ll> x(N), y(N), z(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> x[i] >> y[i] >> z[i];
	}

	ll maxVal = 0;
	vector<ll> w(N);
	for (int i = 0; i < (1 << 3); ++i)
	{
		int s1 = (i & 1) * 2 - 1;
		int s2 = ((i >> 1) & 1) * 2 - 1;
		int s3 = ((i >> 2) & 1) * 2 - 1;
		for (int j = 0; j < N; ++j)
		{
			w[j] = s1 * x[j] + s2 * y[j] + s3 * z[j];
		}
		sort(w.begin(), w.end(), greater<ll>());
		maxVal = max(maxVal, abs(accumulate(w.begin(), w.begin() + M, 0LL)));
	}
	cout << maxVal << endl;
}
int main()
{
	ABC100D();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <assert.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <string.h>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;

const int N = 1e3 + 2;
const long long MOD = 1e9 + 7;

int n;
double dp[3000][3000], p[3000];
bool vis[3000][3000];

double calc(int i, int heads)
{
    if (i == n)
    {
        return heads > n / 2;
    }
    double &ret = dp[i][heads];
    if (vis[i][heads])
    {
        return ret;
    }
    vis[i][heads] = true;
    ret = calc(i + 1, heads + 1) * p[i];
    ret += calc(i + 1, heads) * (1 - p[i]);
    return ret;
}

int main()
{
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> p[i];
    }
    cout << setprecision(16) << calc(0, 0) << endl;
    return 0;
}

Measured memory_bytes: 79488
import sys

n = int(input())
for i in range(1, n + 1):
    if i % 3 == 0:
        sys.stdout.write(' ')
        sys.stdout.write(str(i))
    else:
        x = i
        for j in range(0, 5):
            if x % 10 == 3:
                sys.stdout.write(' ')
                sys.stdout.write(str(i))
                break
            x //= 10

print('')

Measured memory_bytes: 7868