akhauriyash/Code-Regression huggingface dataset:
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum long mod = 10^^9 + 7;

void main() {
    string s = readln.chomp;
    string abc = "ABC";
    int n = s.length.to!int;

    auto dp = new long[][](n + 1, 4);
    dp[0][0] = 1;

    foreach (i ; 1 .. n + 1) {
        foreach (j ; 0 .. 4) {
            dp[i][j] = dp[i-1][j];
            if (s[i-1] == '?') {
                dp[i][j] *= 3;
                dp[i][j] %= mod;
            }

            if (j > 0 && (s[i-1] == '?' || s[i-1] == abc[j-1])) {
                dp[i][j] += dp[i-1][j-1];
                dp[i][j] %= mod;
            }
        }
    }

    debug {
        writeln(dp);
    }

    writeln(dp[n][3]);
}




























void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 11800
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
//const ll MOD=(ll)998244353;
const ll INF=(ll)1e18+10;
const double PI = 2.0*acos(0);

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

struct BIT{ //sample add
    vector<int> data;
    int nodes;

    BIT(int N){
        nodes=N;
        data.resize(nodes*2+1);
        for(auto i:data) i=0; //initialize;
    }

    void add(int k,int a){ //add a to element k
        k++;
        int tmp=0;
        while(k<=nodes){
            data[k]+=a;
            k += k & -k;
            //cout<<k<<endl;
            if(tmp>10) break;
        }
    }

    ll sum(int i){ //calc sum of [0,i)
        //i++;
        ll ret = 0ll;
        while(i>0){
            ret+=data[i];
            i -= i & -i;
        }
        return ret;
    }

    ll sum(int a,int b){ //[a,b)
        if(a>=b) return 0;
        return sum(b+1);
    }
};

void solve(int ca){
    int N; cin>>N;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) {
        cin>>a[i];
    }
    vector<int> sorted=a,zaatsu(N);
    sort(sorted.begin(),sorted.end());
    for (int i = 0; i < N; ++i) {
        zaatsu[i]=lower_bound(sorted.begin(), sorted.end(), a[i]) - sorted.begin();
        //cout<<zaatsu[i]<<endl;
    }
    BIT bit = BIT(N+10);
    ll ans = 0ll;
    for (int i = 0; i < N; ++i) {
        bit.add(zaatsu[i],1);
        ans+=(ll)i-bit.sum(zaatsu[i]);
        //cout<<i<<" "<<ans<<endl;
    }
    cout<<ans<<endl;
}

//#define MULTI
int main() {
#ifdef MULTI
    int N; cin>>N;
    for (int i = 0; i < N; ++i) {
        solve(i+1);
    }
#else
    solve(0);
#endif
    return 0;
}



Measured memory_bytes: 6824
/*
    ~A_Pessimist~:)
*/

#include<bits/stdc++.h>
#define ll long long int
using namespace std;

const int sz=1e5+10;
ll ar[sz][4],dp[sz][4],n;

ll find_max(int day, int flag)
{
    if(day==n) return 0;

    if(~dp[day][flag]) return dp[day][flag];

    ll mx=0;

    if(flag==0)
    {
        mx=max(mx, ar[day][1] + find_max(day+1, 1));
        mx=max(mx, ar[day][2] + find_max(day+1, 2));
        mx=max(mx, ar[day][3] + find_max(day+1, 3));
    }
    else if(flag==1)
    {
        mx=max(mx, ar[day][2] + find_max(day+1, 2));
        mx=max(mx, ar[day][3] + find_max(day+1, 3));
    }
    else if(flag==2)
    {
        mx=max(mx, ar[day][1] + find_max(day+1, 1));
        mx=max(mx, ar[day][3] + find_max(day+1, 3));
    }
    else
    {
        mx=max(mx, ar[day][1] + find_max(day+1, 1));
        mx=max(mx, ar[day][2] + find_max(day+1, 2));
    }

    return dp[day][flag] = mx;
}

void solve()
{
    cin>>n;
    memset(dp, -1, sizeof dp);

    for(int i=0;i<n;i++)
    {
        for(int j=1;j<=3;j++)
        {
            cin>>ar[i][j];
        }
    }
    cout<<find_max(0,0)<<endl;
}

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

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

    while(t--)
    {
        solve();
    }
}


Measured memory_bytes: 17612
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

/*
  箱とボールは区別できるが、箱に入れられるボールの数は1つまで
  つまり、n > kなら答えは0
  そうでない場合, kPnが答え
*/

int main() {
  ll n, k;
  cin >> n >> k;
  if (n > k) cout << 0 << endl;
  else {
    ll ans = 1;
    for (int i = 0; i < n; ++i) {
      ans *= k--;
      ans %= MOD;
    }
    cout << ans << endl;
  }

  
}



Measured memory_bytes: 3108
N = int(input())
H = list(map(int, input().split()))
ans = "Yes"

for i in range(N-1):
    if H[i] < H[i+1]:
        H[i+1] -= 1

for j in range(N-1):
    if H[j] > H[j+1]:
        ans = "No"
    

print(ans)  

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

int main()
{
    int a[11] = {};
    int x, y, z;
    cin >> x >> y >> z;

    a[x]++;
    a[y]++;
    a[z]++;

    if (a[5] == 2 && a[7] == 1) cout << "YES";
    else cout << "NO";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

int main() {
    string s;
    cin >> s;
    ll ans = 0;
    int ctr = 0;
    bool prevc = false;
    reverse(all(s));
    rep (i, s.size()) {
        switch (s[i]){
            case 'A':
                if (prevc) {
                    ctr = 0;
                    prevc = false;
                }
                ans += ctr;
                break;
            case 'B':
                if (prevc) {
                    ctr++;
                } else {
                    ctr = 0;
                }
                prevc = false;
                break;
            case 'C':
                if (prevc) {
                    ctr = 0;
                }
                prevc = true;
                break;
        }
    }
    cout << ans << endl;
}

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

#define F first 
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 1010;

int n, m;
struct Pro
{
	int s, t, c;
	bool operator<(const Pro &t) const
	{
		return s < t.s;
	}
}pro[N];
PII rec[M];

int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i ++ )
	{
		int s, t, c;
		scanf("%d%d%d", &s, &t, &c);
		pro[i] = {s, t, c};
	}
	sort(pro, pro + n);
	
	int cnt = 0;
	for (int i = 0; i < n; i ++ )
	{
		sort(rec, rec + cnt);
		bool flag = false;
		for (int j = cnt - 1; j >= 0; j -- )
			if (rec[j].F == pro[i].s && rec[j].S == pro[i].c || rec[j].F < pro[i].s)
			{
				rec[j] = {pro[i].t, pro[i].c};
				flag = true;
				break;
			}
		if (!flag) rec[cnt ++ ] = {pro[i].t, pro[i].c};
	}
	
	printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 4984
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace ABC126
{
    public class UnionFind
    {
        int[] par;
        int[] size;

        public UnionFind(int N)
        {
            par = new int[N];
            size = new int[N];
            for (int i = 0; i < N; i++)
            {
                par[i] = i;
                size[i] = 1;
            }
        }

        public int Root(int x)
        {
            if (par[x] == x) return x;
            return par[x] = Root(par[x]);
        }

        public void Unite(int x, int y)
        {
            int rootX = Root(x);
            int rootY = Root(y);
            if (rootX == rootY) return;
            par[rootX] = rootY;
            size[rootY] += size[rootX];
        }

        public bool Same(int x, int y)
        {
            int rootX = Root(x);
            int rootY = Root(y);
            return rootX == rootY;
        }

        public int Size(int x)
        {
            return size[Root(x)];
        }
    }
    
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int N = int.Parse(s[0]);
            int M = int.Parse(s[1]);
            int[] X = new int[M];
            int[] Y = new int[M];
            int[] Z = new int[M];
            Dictionary<int, int> D = new Dictionary<int, int>();
            UnionFind U = new UnionFind(N);
            for (int i = 0; i < M; i++)
            {
                s = Console.ReadLine().Split();
                X[i] = int.Parse(s[0]);
                Y[i] = int.Parse(s[1]);
                Z[i] = int.Parse(s[2]);
                U.Unite(X[i] - 1, Y[i] - 1);
            }
            int res = 0;
            for (int i = 0; i < N; i++)
            {
                if (!D.Keys.Contains(U.Root(i)))
                {
                    D[U.Root(i)] = 1;
                    res++;
                }
            }
            Console.WriteLine(res);
        }
    }
}

Measured memory_bytes: 22980
#include<stdio.h>

static const int MAX = 500;
static const int INFTY = (1<<21);

main(){
  int n, i, j, e, sum;
  int M[MAX][MAX];
  int u, v;
  int minv;
  int d[MAX];
  int p[MAX];
  int vis[MAX];

  scanf("%d", &n);

  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      scanf("%d", &e);
      M[i][j] = (e==-1)?INFTY:e;
    }
  }

  for ( i = 0; i < n; i++ ) {
    d[i] = INFTY;
    p[i] = -1;
    vis[i] = 0;
  }

  d[0] = 0;

  while(1){
    minv = INFTY;
    u = -1;
    for ( i = 0; i < n; i++ ){
      if ( minv > d[i] && !vis[i] ){
	u = i;
	minv = d[i];
      }
    }
    if ( u == -1 ) break;
    vis[u] = 1;
    for ( v = 0; v < n; v++ ){
      if ( !vis[v] && M[u][v] != INFTY ){
	if ( d[v] > M[u][v] ){
	  d[v] =  M[u][v];
	  p[v] = u;
	}
      }
    }
  }

  sum = 0;

  for ( i = 0; i < n; i++ ){
    if ( p[i] != -1 ) sum += M[i][p[i]];
  }

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

  return 0;
}



Measured memory_bytes: 2112
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
using namespace std;

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

	string s;
	cin >> s;
	for(int i = 0; i < 4; i++) {
		cout << s[i];
	}
	cout << " ";
	for(int i = 4; i < 12; i++) {
		cout << s[i];
	}
	cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
double hoge(double x1,double y1,double x2, double y2){
  double a,b,c;
  a=max(x1,x2)-min(x1,x2);
  b=max(y1,y2)-min(y1,y2);
  c=(a*a)+(b*b);
  c=sqrt(c);
  return c;
}
double heron(double a,double b,double c){
  double s,S;
  s=(a+b+c)/2;
  S=s*(s-a)*(s-b)*(s-c);
  S=sqrt(S);
  return S;
}
int main(void){
  double x1,x2,x3,y1,y2,y3,xp,yp,ab,bc,ac,ap,bp,cp,abc,apb,bpc,apc,sum;
  while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp){
    ab=hoge(x1,y1,x2,y2);
    bc=hoge(x2,y2,x3,y3);
    ac=hoge(x1,y1,x3,y3);
    ap=hoge(x1,y1,xp,yp);
    bp=hoge(x2,y2,xp,yp);
    cp=hoge(x3,y3,xp,yp);
    abc=heron(ab,bc,ac);
    apb=heron(ap,bp,ab);
    bpc=heron(bp,cp,bc);
    apc=heron(ap,cp,ac);
    sum=apb+bpc+apc;
    if(max(abc,sum)-min(abc,sum)<=0.000000001) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}


Measured memory_bytes: 1216
#p gets.to_i ** 3

n = gets.to_i

a = gets.split(" ").map{|x| x.to_i}
b = gets.split(" ").map{|x| x.to_i}
c = gets.split(" ").map{|x| x.to_i}

temp = -1
sum = 0
n.times do |i|
  sum += c[a[i] - 2] if a[i] == temp + 1
  temp = a[i]
  sum += b[a[i] - 1]
end
p sum


Measured memory_bytes: 1788
import sys
input = sys.stdin.readline


def read():
    N = int(input().strip())
    CSF = []
    for i in range(N-1):
        c, s, f = map(int, input().strip().split())
        CSF.append((c, s, f))
    return N, CSF


def solve(N, CSF, SMAX=200000):
    A = []
    for c, s, f in CSF:
        for i in range(len(A)):
            if A[i] % f == 0:
                A[i] = max(A[i], s) + c
            else:
                A[i] = max(A[i] - A[i] % f + f, s) + c
        A.append(s + c)
    A.append(0)
    for a in A:
        print(a)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Measured memory_bytes: 3188
#include<iostream>
#include<string>

int sum[26];

int main(){
	std::string str;
	while (std::getline(std::cin, str)){

		for (int i = 0; i < str.size(); i++){
			if ('a' <= str[i] && str[i] <= 'z')sum[str[i] - 'a']++;
			else if ('A' <= str[i] && str[i] <= 'Z')sum[str[i] - 'A']++;
		}
	}

	for (int i = 0; i < 26; i++){
		std::cout << (char)(i + 'a') << " : " << sum[i] << std::endl;
	}

	return 0;
}

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

map<char,int>m;

int main()
{
  int n;
  scanf("%d",&n);
  int cnt=0;
  while(n--)
  {
    char x;
    cin>>x;
    m[x]++;
  }
  
  for(auto it: m) cnt++;
  if(cnt==3) printf("Three");
  else if(cnt==4) printf("Four");
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n,x,y,d[42][402][402],m=1000000000;
    cin>>n>>x>>y;
    
    for(int i=0;i<=n;i++){
        for(int j=0;j<402;j++){
            for(int k=0;k<402;k++){
                d[i][j][k]=1000000000;
            }
        }
    }
    d[0][0][0]=0;
    for(int i=1;i<=n;i++){
        int a,b,c;
        cin>>a>>b>>c;
        for(int j=0;j<=400;j++){
            for(int k=0;k<=400;k++){
                if(j-a>=0&&k-b>=0){
                    d[i][j][k]=min(d[i-1][j][k],d[i-1][j-a][k-b]+c);
                }else{
                    d[i][j][k]=d[i-1][j][k];
                }
            }
        }
    }
    
    for(int i=1;i*x<=400&&i*y<=400;i++){
        m=min(m,d[n][i*x][i*y]);
    }
    if(m>=1000000000)m=-1;
    cout<<m<<endl;
}


Measured memory_bytes: 26368
import sys
import  math
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))


N=int(input())
min_l=[]
max_l=[]
for k in range(N):
    A,B=nm()
    min_l.append(A)
    max_l.append(B)

min_l.sort()
max_l.sort()

if(N%2==0):
    print(int(((max_l[N//2-1]+max_l[N//2])/2-(min_l[N//2-1]+min_l[N//2])/2)*2+1))    
else:
    print(((max_l[(N-1)//2])-(min_l[(N-1)//2]))+1)

Measured memory_bytes: 26704
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;
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; }
// const ll INF = 1LL <<60;
// const int INF = 10000;

//最大公約数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

const int MAX = 1e6+1;
const int MOD = 1e9+7;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int 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;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}

long long modpow(long long res,long long a, long long n, long long mod) {
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//sieve(MAX);でベクトルIsPrimeに「MAXまでの数値の素数の真偽」を格納する。
vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > IsPrime.size()){     // resizeで要素数が減らないように
        IsPrime.resize(max+1,true); // IsPrimeに必要な要素数を確保
    } 
    IsPrime[0] = false; // 0は素数ではない
    IsPrime[1] = false; // 1は素数ではない

    for(size_t i=2; i*i<=max; ++i) // 0からsqrt(max)まで調べる
        if(IsPrime[i]) // iが素数ならば
            for(size_t j=2; i*j<=max; ++j) // (max以下の)iの倍数は
                IsPrime[i*j] = false;      // 素数ではない
}
// ここから開始

int main(){
    string s;
    cin>>s;
    if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I') cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vec(k) vector<k>
#define vecvec(k) vector<vector<k> >
#define pai(k) pair<k,k>
#define mod 1000000007
#define mpai make_pair
#define p1 first
#define p2 second
#define umap(x,y) unordered_map<x,y>
int solve(char mat[1001][1001], int n, int m)
{
	int dp[n+1][m+1];
	memset(dp,0,sizeof(dp));
	for(int i=1;i<=n;i++)
		{if(mat[i-1][0]=='#')
			break;
		dp[i][1]=1;
	}
	for(int i=1;i<=m;i++)
	{
		if(mat[0][i-1]=='#')
			break;
		dp[1][i]=1;

	}

	for(int i=2;i<=n;i++)
	{
		for(int j=2;j<=m;j++)
		{
			if(mat[i-1][j-1]=='.')
				dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
			else
				dp[i][j]=0;
		}
	}
	// for(int i=0;i<=n;i++)
	// {
	// 	for(int j=0;j<=m;j++)
	// 		cout<<dp[i][j]<<" ";
	// 	cout<<"\n";
	// }
	return dp[n][m]%mod;
}

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


    ll n,x,m;
    cin>>n>>m;
    char mat[1001][1001];
    for(int i=0;i<n;i++)
    {
    	for(int j=0;j<m;j++)
    		cin>>mat[i][j];
    }
    int ans=solve(mat, n, m);
    cout<<ans<<"\n";
   
return 0;
}


Measured memory_bytes: 5120
#include <iostream>
#include <vector>
#include <typeinfo>
using namespace std;
int main(void){
    int n;
    cin >> n;
    double p;
    if(n%2==0){
        p = 1.0/2;
    }else{
        p = ((n-1)/2+1.0)/n;
    }
    cout << p << endl;
}

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

int main()
{
	list<unsigned int> int_list;
	unsigned int command_num;
	unsigned int num;
	cin >> command_num;
	string cmd;
	// load data & write to list
	for (int i = 0; i < command_num; ++i) {
		cmd.clear();
		cin >> cmd;
		if (cmd == "insert") {
			cin >> num;
			int_list.push_front(num);
		}
		else if (cmd == "delete") {
			cin >> num;
			decltype(int_list)::iterator iter = int_list.begin();
			while (iter != int_list.end()) {
				if (*iter == num) {
					int_list.erase(iter);
					break;
				}
				++iter;
			}

		}
		else if (cmd == "deleteFirst") {
			int_list.pop_front();
		}
		else{
			int_list.pop_back();
		}
	}

	// write to console
	decltype(int_list)::iterator iter = int_list.begin();
	decltype(int_list)::iterator iter_l = int_list.end();
	iter_l--;
	while (iter != iter_l) {
		cout << *iter << " ";
		++iter;
	}
	cout << *iter << endl;
}



Measured memory_bytes: 34388
import itertools
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

l = list(itertools.permutations(list(range(1, N+1)), N))
a = l.index(P) + 1
b = l.index(Q) + 1
print(abs(a - b))

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

void dfs(int count,string s) {
	if (N == s.size()) {
		cout << s <<endl;
		return;
	}
	for (int i = 0;i<=count; ++i) {
		string newS = s;
		newS += (char)(i + 'a');
		if (i != count) {
			dfs(count,newS);
		}
		else {
			dfs(count + 1,newS);
		}
	}
}

int main() {
	cin >> N;
	dfs(0,"");
	return 0;
}

Measured memory_bytes: 3612
# -*- coding: utf-8 -*-

import sys
import math


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    (a, b, c) = [int(e) for e in lines[0].split(' ')]

    return (a, b, c)


def solve(a, b, c):
    
    result = 'No'
    if a == b and a != c:
        result = 'Yes'
    if b == c and b != a:
        result = 'Yes'
    if c == a and c != b:
        result = 'Yes'
        
    return result
    


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()
	

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

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

constexpr ll INF = 1ll<<60;

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; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N, x;
ll a[110];
std::map<ll, ll> dp[110];

int main()
{
  std::cin >> N >> x;

  rep( i, N )
    std::cin >> a[i];

  std::sort( a, a+N );

  ll S = 0, ans = 0;

  rep( i, N )
  {
    S += a[i];

    if( S <= x )
    {
      chmax( ans, (i==N-1 && S != x ? i : i+1) );
    }
  }

  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<random>
#include<deque>
#include<cstdio>
#include<fstream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 2000100;
const int mod = (int)pow(10, 9) + 7;
const ll INF = 1LL << 60;
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define ppp pair<pp,ll>
#define fi first
#define se second
#define pb push_back
#define fix(n) fixed<<setprecision(n)
#define itr vector<ll>::iterator
#define print(s) cout<<s<<endl
#define inp(s) cin>>s
string yn(bool b) { return (b ? "Yes" : "No"); }
string YN(bool b) { return (b ? "YES" : "NO"); }
ll a, b, n;
bool ans = 0;
int main(){
	cin >> a >> b>>n;
	ll l, r;
	rep(i, n) {
		cin >> l >> r;
		if (r <=a || l>=b)continue;
		ans = 1;
	}
	cout << ans << endl;
	return 0;
}


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

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

	ll n;
	cin>>n;
	string s;
	cin>>s;

	unordered_map<char,vector<ll>> data;

	for(ll i=0; i<n; ++i){
		data[s[i]].push_back(i);
	}

	ll rs = data['R'].size();
	ll gs = data['G'].size();
	ll bs = data['B'].size();

	auto get_less = [&](char item, ll id){
		auto get = upper_bound(data[item].begin(), data[item].end(), id);
		ll val = distance(data[item].begin(), get);
		return val;
	};

	auto ch = [&](char item, ll val){
		return binary_search(data[item].begin(), data[item].end(), val);
	};

	ll ans = 0;
	for(ll i=1; i<n-1; ++i){
		ll v1 = -1, v2 = -1, v3 = -1;
		if( s[i] != 'R' ){ v1 = get_less('R', i); }
		if( s[i] != 'G' ){ v2 = get_less('G', i); }
		if( s[i] != 'B' ){ v3 = get_less('B', i); }
		ll o1 = -1, o2 = -1, o3 = -1;
		if( v1 != -1 ){ o1 = rs - v1; }
		if( v2 != -1 ){ o2 = gs - v2; }
		if( v3 != -1 ){ o3 = bs - v3; }

		if( v1 == -1 ){
			ans += (v2 * o3) + (o2 * v3);
		}else if( v2 == -1 ){
			ans += (v1 * o3) + (o1 * v3);
		}else if( v3 == -1 ){
			ans += (v1 * o2) + (o1 * v2);
		}

		for(ll check=0; check<=min(i,n-i+1); ++check){
			if( s[i] == 'R' ){
				if( ch('G', i-check) && ch('B', i+check) ){ ans--; }
				if( ch('B', i-check) && ch('G', i+check) ){ ans--; }
			}else if( s[i] == 'G' ){
				if( ch('R', i-check) && ch('B', i+check) ){ ans--; }
				if( ch('B', i-check) && ch('R', i+check) ){ ans--; }
			}else if( s[i] == 'B' ){
				if( ch('G', i-check) && ch('R', i+check) ){ ans--; }
				if( ch('R', i-check) && ch('G', i+check) ){ ans--; }
			}
		}
	}

	cout << ans << '\n';


	return 0;
}


Measured memory_bytes: 3692
x, y = map(int, input().split())

if x * y == 0:
    if x <= y:
        print(y - x)
    elif x > y:
        print(x - y + 1)
elif x * y > 0:
    if x <= y:
        print(y - x)
    elif x > y:
        print(x - y + 2)
elif x * y < 0:
    if abs(x) <= abs(y):
        print(abs(y) - abs(x) + 1)
    elif abs(x) > abs(y):
        print(abs(x) - abs(y) + 1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define x first
#define y second
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ve vector
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define pb push_back
#define sz(a) (int)(a.size())
//using namespace __gnu_pbds;
using namespace std;

// // // functions: find_by_order  & order_of_key
// typedef tree<
// int,
// null_type,
// less<int>,
// rb_tree_tag,
// tree_order_statistics_node_update>
// ordered_set;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

const int inf=(int)2e9;
const long long mod=1000000007; //1E9+7
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};

ll powmod(ll a,ll p){
	ll ans=1;
	while(p){
		if(p&1) ans*=a;
		p/=2;a*=a; ans%=mod;a%=mod;
	}
	return ans;
}
ll modinv(ll a){return powmod(a,mod-2); }

int tmp[55][55];
const int N=52;
void mul(vvi& a,vvi& b){
	forn(i,N) forn(j,N) tmp[i][j]=0;
	forn(i,N){
		forn(j,N){
			forn(k,N){
				tmp[i][j]+=a[i][k]*b[k][j]%mod;
				if(tmp[i][j]>=mod)
					tmp[i][j]-=mod;
			}
		}
	}
	forn(i,N) forn(j,N) a[i][j]=tmp[i][j];
}
vvi mat(55,vi(55,0));
vvi ans(mat);

signed main(){
	IOS
	int n;cin>>n;int k;cin>>k;
	forn(i,n) forn(j,n) cin>>mat[i][j];
	forn(i,n) ans[i][i]=1;
	while(k){
		if(k&1) mul(ans,mat);
		mul(mat,mat);
		k/=2;
	}
	int h=0;
	forn(i,n) forn(j,n){
		h+=ans[i][j];
		if(h>=mod) h-=mod;
	}
	cout<<h;
}


Measured memory_bytes: 384
#include<stdio.h>

int main() {
	int num;
	int max = 0, sum = 0;
	int count;

	scanf("%d", &num);
	int* price = new int[num];
	for (int i = 0; i < num; i++) {
		scanf("%d", &price[i]);
		if (max < price[i]) {
			max = price[i];
			count = i;
		}
		sum += price[i];
	}
	
	sum -= price[count] / 2;

	printf("%d\n",sum);
	return 0;
}

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

#define ll long long int
#define mp make_pair
#define ff first
#define ss second
#define fr(i,l,r) for (long long int i = l; i < r; ++i)
#define frr(i,l,r) for (long long int i = r; i >= l; --i) 
#define sortarr sort(arr,arr+n) //sorts array in asc order
#define sortarr_r sort(arr, arr+n, greater<long long int>()) //sorts array in desc order
#define make_set set<long long int>s //Set arranges in asc order
#define make_set_r set<long long int, greater <long long int>>s ////Set arranges in desc order
#define make_vector vector<long long int>v; 
#define pb push_back


// string size = str.size()

// stack <int> s; 
// queue <int> gquiz; 
// __gcd(m, n) 

// ll arr[10e5 + 5];
// char arr[10e5 + 5];

// printf ("%.9f\n",x);

bool compare(string &s1,string &s2) 
{ 
    return s1.size() < s2.size(); 
} 
void yes()
{
    cout << "YES" << endl;
}
void no()
{
    cout << "NO" << endl;
}


int main(void)
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n,m,sum = 0,x;
    cin >> n >> m;
    for(ll i = 1; i<=m; i++)
    {
        cin >> x;
        sum+=x;
    }
    if(n - sum >=0)
    {
        cout << n-sum << endl;
    }
    else
    {
        cout << "-1" << endl;
    }
    
    return 0;
}   

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
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 (b<a) {a=b; return 1;} return 0;}


int main(){
    int n, k, r, s, p;
    cin >> n >> k >> r >> s >> p;
    string t;
    cin >> t;
    int ans = 0;
    vector<int> flag(n, 0);
    rep(i, n) {
        if (i-k >= 0 && t[i-k] == t[i] && !flag[i-k]) {
            flag[i] = 1;
            continue;
        }
        if (t[i] == 'r') ans += p;
        if (t[i] == 's') ans += r;
        if (t[i] == 'p') ans += s;
    }
    cout << ans << endl;
}


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

int main() {
  int a,b;
  cin >> a >> b;
  int ans,plus,minus,times;
  plus = a+b;
  minus = a-b;
  times = a*b;
  ans = max({plus,minus,times});
  cout << ans << endl;
}

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


namespace ACprac
{
    class Program
    {
        static void Main(string[] args)
        {
            // 何行何列
            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);

            if(a < 9 && b < 9)
            {
                Console.WriteLine("Yay!");
            }
            else
            {
                Console.WriteLine(":(");
            }
        }
    }
}


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

int main()
{	
	string s;
	cin >> s;
	int a[100005] = {0};
	int ans[100005] = {0};
	
	int k = s.size() - 1;
	for(int i = s.size() - 1;i >= 0;i--){
		if(s[i] == 'L') k = i;
		if(s[i] == 'R') a[i] = k;
	}
	k = 0;
	for(int i = 0;i < s.size();i++){
		if(s[i] == 'R') k = i;
		if(s[i] == 'L') a[i] = k;
	}	
	
	for(int i = 0;i < s.size();i++){
		if(s[i] == 'R'){
			if((a[i] - i) % 2 == 0) ans[a[i]]++;
			if((a[i] - i) % 2 != 0) ans[a[i] - 1]++;
		}
		if(s[i] == 'L'){
			if((i - a[i]) % 2 != 0) ans[a[i] + 1]++;
			if((i - a[i]) % 2 == 0) ans[a[i]]++;
		}
	}
	
	cout << ans[0];
	for(int i = 1;i < s.size();i++){
		cout << ' ' << ans[i];
	}
	cout << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> a;
int main()
{
   
    scanf("%d",&n);
    a.clear();
    for(int i=1;i<=n;i++)
    {
        int x=i;
        if (x%3==0)
            a.push_back(x);
        else
        while (x)
        {
            if (x%10 == 3)
            {
                a.push_back(i);
                break;
            }
            x/=10;
        }
    }
    for(int i=0;i<a.size();i++)
        printf(" %d",a[i]);
    printf("\n");
   // printf("%d",a[a.size()-1]);
}



Measured memory_bytes: 3264
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
    ll T1, T2, A1, A2, B1, B2;
    cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;
    ll p1 = A1 * T1 + A2 * T2;
    ll p2 = B1 * T1 + B2 * T2;
    if (p1 == p2) {
        cout << "infinity" << endl;
    } else {
        if (p1 < p2) {
            swap(A1, B1);
            swap(A2, B2);
            swap(p1, p2);
        }
        ll ans = 0;
        if (B1 > A1) {
            ll maxd = (B1 - A1) * T1;
            ans = 1 + 2 * (maxd / (p1 - p2));
            if (maxd % (p1 - p2) == 0) {
                --ans;
            }
        }
        cout << ans << endl;        
    }
 
    return 0;
}

Measured memory_bytes: 256
import fractions
import numpy as np


n = int(input())
a = list(map(int, input().split()))

left_gcd_array = np.array([0] * n)
left_gcd_array[0] = a[0]

right_gcd_array = np.array([0] * n)
right_gcd_array[n - 1] = a[n - 1]

for i in range(1, n):
    left_gcd_array[i] = fractions.gcd(a[i], left_gcd_array[i - 1])
    right_gcd_array[n - 1 - i] = fractions.gcd(a[n - 1 - i], right_gcd_array[n - i])

print(max([left_gcd_array[n - 2]] +
          [fractions.gcd(left_gcd_array[i], right_gcd_array[i + 2]) for i in range(0, n - 2)] +
          [right_gcd_array[1]]))


if __name__ == '__main__':
    pass


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


#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define FILL(A,val) memset(A,val,sizeof(A))
#define ITER(it,a) for(__typeof(a.begin()) it=a.begin();it!=a.end();++it)
#define DBG1(a) cerr<<#a<<"="<<(a)<<"\n"
#define DBG2(a,b) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"

#define ALL(V) V.begin(),V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000*1000*1000 + 7;
const LL LINF = 1LL*INF*INF;

const LL MOD = 1000000007;

const int MAX = 200005;

int a[MAX];

void fail()
{
	cout<<"Impossible";
	exit(0);
}

int cnt[MAX];
int main()
{
	//freopen("in.txt","r",stdin);
	//ios::sync_with_stdio(false);cin.tie(0);
	int n;
	cin>>n;

	FOR(i,0,n)cin>>a[i];

	sort(a,a+n);

	reverse(a,a+n);
	int d = a[0];

	int mn;


	if(d%2 == 0)
		mn = d/2;
	else mn = (d+1)/2;

	FOR(i,0,n)
	{
		int x = a[i];
		cnt[x]++;
	}


	FOR(i,0,n)
	{
		if(i<mn && cnt[i])
			fail();
		if(i == mn)
		{
			if(d%2 == 0 && cnt[i]!=1)
			{
				fail();
			}

			if(d%2 == 1 && cnt[i]!=2)fail();
		}

		if(i>mn && i<=d)
		{
			if (cnt[i]<2)fail();
		}
	}

	cout<<"Possible";

	return 0;
}


Measured memory_bytes: 256
H, W = gets.chomp.split.map(&:to_i)
s = []
s[0] = Array.new(W+2, '.')
1.upto(H) do |h|
  s[h] = gets.chomp.split('')
  s[h].unshift('.')
  s[h].push('.')
end
s[H+1] = Array.new(W+2, '.')

ans = Array.new(H+2) { Array.new(W+2, nil) }

1.upto(H) do |h|
  1.upto(W) do |w|
    if s[h][w] == '#'
      ans[h][w] = '#'
      next
    end

    tmp = 0
    [-1, 0, 1].each do |y|
      [-1, 0, 1].each do |x|
        next if x.zero? && y.zero?

        tmp += 1 if s[h+y][w+x] == '#'
      end
    end
    ans[h][w] = tmp
  end
end

1.upto(H) do |h|
  puts ans[h].join('')
end


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

#define ll long long
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int mod = 1e9 + 7;
const int MAX = 2e5 + 1;
int a[MAX], b[MAX];

void solve()
{
	int n;
	cin >> n;
	for(int i = 1; i <= n; ++i)
	{
		cin >> a[i];
		b[i] = a[i];
	}
	ll ans = 0;
	int mxm = b[1];
	for(int i = 2; i <= n; ++i)
	{
		if(b[i] < mxm)
		{
			ans += (mxm - b[i]);
			b[i] = mxm;
		}
		mxm = max(mxm, b[i]);
	}
	cout << ans;
}


int main()
{
	IOS
	int t = 1;
	//cin >> t;
	while(t--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 5128
H,W,K = map(int,input().split())
S = [[int(i) for i in input()] for _ in range(H)]
ans = float("inf")

# bit全探索
for i in range(2**(H-1)): 
    start = [0]
    end = []
    for j in range(H-1):
        if i >> j & 1 == 1:
            j += 1
            start.append(j)
            end.append(j)
    end.append(H)
    L = len(end)
    # 横に割った回数
    divcnt = L-1
    # 横に割った区割りごとの白チョコの個数
    wcnt = [0]*L
    # 探索列の横に割った区割りごとの白チョコの個数
    tmp = [0]*L
    for w in range(W):
        # 探索列の直前で縦に割ったか
        flag = False
        for idx in range(L):
            cnt = 0
            for h in range(start[idx],end[idx]):
                cnt += S[h][w]
                if cnt > K: break
            else:
                tmp[idx] = cnt
                wcnt[idx] += cnt
                if wcnt[idx] > K: flag = True
                continue
            break
        else:
            if flag:
                # 縦に割ったらその列から数え直し
                wcnt = tmp[:]
                divcnt += 1
            continue
        break
    else:
        ans = min(ans,divcnt)

print(ans)

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, k;
  cin >> n >> k;
  
  vector<vector<int>> black(k, vector<int>(k)), white(k, vector<int>(k));
  for (int i = 0; i < n; i++) {
    int x, y, z;
    char c;
    cin >> x >> y >> c;
    z = (c == 'B' ? 0 : 1);
    x %= 2 * k;
    y %= 2 * k;
    if (x >= k && y >= k) {
      x %= k;
      y %= k;
    }
    else if (x >= k || y >= k) {
      x %= k;
      y %= k;
      z ^= 1;
    }
    if (z == 0) black.at(x).at(y)++;
    else white.at(x).at(y)++;
  }
  
  for (int i = 0; i < k; i++) {
    for (int j = 1; j < k; j++) {
      black.at(i).at(j) += black.at(i).at(j - 1);
      white.at(i).at(j) += white.at(i).at(j - 1);
    }
  }
  for (int j = 0; j < k; j++) {
    for (int i = 1; i < k; i++) {
      black.at(i).at(j) += black.at(i - 1).at(j);
      white.at(i).at(j) += white.at(i - 1).at(j);
    }
  }
  
  int ans = 0;
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < k; j++) {
      int keep1 = 0, keep2 = 0;
      keep1 += black[k - 1][k - 1] - black[i][k - 1] - black[k - 1][j] + 2 * black[i][j];
      keep1 += white[k - 1][j] + white[i][k - 1] - 2 * white[i][j];
      keep2 += white[k - 1][k - 1] - white[i][k - 1] - white[k - 1][j] + 2 * white[i][j];
      keep2 += black[k - 1][j] + black[i][k - 1] - 2 * black[i][j];
      ans = max({ans, keep1, keep2});
    }
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 8192
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		
		if(x == 0) System.out.println("1");
		else System.out.println("0");
		
		
	}

}


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

const int mod=1e9+7;

struct P{
  int A,T,G,C;
  P(int a,int b,int c,int d){
    A=a;T=b;
    G=c;C=d;
  }
};

int A,T,G,C,n;
string s[51],t,name;
map<string,string>M;
int dp[55][55][55][55];
int CNT[222][4],cnt;

void END(){
  cout<<0<<endl;
  exit(0);
}

int main(){
  cin>>A>>T>>G>>C>>n;
  getline(cin,s[0]);
  r(i,n)getline(cin,s[n-i-1]);
  r(i,n){
    stringstream ss(s[i]);
    ss>>name;
    string arr;
    while(ss>>t){
      if(t[0]=='[')arr+=t;
      else arr+=M[t+':'];
    }
    M[name]=arr;
    if(arr.size()>200*6)END();
  }
  t=M[name];
  set<char>st;
  r(i,t.size()){
    if(t[i]==']'){
      if(st.count('A'))CNT[cnt][0]=1;
      if(st.count('T'))CNT[cnt][1]=1;
      if(st.count('G'))CNT[cnt][2]=1;
      if(st.count('C'))CNT[cnt][3]=1;
      st.clear();
      cnt++;
    }
    else st.insert(t[i]);
  }
  n=A+T+C+G;
  if(n!=cnt)END();
  queue<P>q;
  q.push(P(A,T,G,C));
  dp[A][T][G][C]=1;
  while(!q.empty()){
    P p=q.front();q.pop();
    A=p.A;
    T=p.T;
    G=p.G;
    C=p.C;
    cnt=dp[A][T][G][C];
    int idx=n-(A+T+G+C);
    if(A&&CNT[idx][0]){
      if(!dp[A-1][T][G][C]) q.push(P(A-1,T,G,C));
      dp[A-1][T][G][C]+=cnt;
      dp[A-1][T][G][C]%=mod;
    }
    if(T&&CNT[idx][1]){
      if(!dp[A][T-1][G][C]) q.push(P(A,T-1,G,C));
      dp[A][T-1][G][C]+=cnt;
      dp[A][T-1][G][C]%=mod;
    }
    if(G&&CNT[idx][2]){
      if(!dp[A][T][G-1][C]) q.push(P(A,T,G-1,C));
      dp[A][T][G-1][C]+=cnt;
      dp[A][T][G-1][C]%=mod;
    }
    if(C&&CNT[idx][3]){
      if(!dp[A][T][G][C-1]) q.push(P(A,T,G,C-1));
      dp[A][T][G][C-1]+=cnt;
      dp[A][T][G][C-1]%=mod;

    }
  }
  cout<<dp[0][0][0][0]<<endl;
}


Measured memory_bytes: 34352
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication9
{
    class Program
    {
        static void Main(string[] args)
        {
            
            
            String[] str = Console.ReadLine().Split(' ');
            int H = int.Parse(str[0]);
            int W = int.Parse(str[1]);
            while (H != 0 || W != 0)
            {
                for (int i = 0; i < H; i++)
                {
                    for (int j = 0; j < W; j++)
                    {
                        if (i % 2 == 0)
                        {
                            if (j % 2 == 0)
                            {
                                Console.Write("#");
                            }
                            else
                            {
                                Console.Write(".");
                            }
                           
                        }
                        else
                        {
                            if (j % 2 == 0)
                            {
                                Console.Write(".");
                            }
                            else
                            {
                                Console.Write("#");
                            }
                        }

                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
                str = Console.ReadLine().Split(' ');
                H = int.Parse(str[0]);
                W = int.Parse(str[1]);

            }



        }
    }
}

Measured memory_bytes: 17588
#include <bits/stdc++.h>
//#include <iostream>
//#include <string>
//#include <algorithm>
//#include <stdio>
using namespace std;
typedef long long ll;
const int maxn = (int)1e5 +10;
const int MOD = 1e9 + 7;

ll qpow(ll a, ll n)
{
    ll re = 1;
    while(n)
    {
        if(a&1) re = (re*a)%13;
        n = n>>1;
        a = (a*a)%13;
    }
    return re;

}

int mod[maxn][10];//第i位值为j的数对13取余的值
ll dp[maxn][20];//第i位对j取余的个数
void init()
{
    ll num = 1;
    for(int i = 1; i < maxn; i++)
    {
        for(int j = 0; j < 10; j++)
            mod[i][j] = j * num % 13;
        num = num * 10 % 13;
    }
}
int main()
{
//    while(1)
//    {
        string s;
        cin>>s;
        reverse(s.begin(),s.end());
        init();
        memset(dp, 0, sizeof dp);
        dp[0][0] = 1;
        for(int i = 0; i < s.length(); i++)
        {
            if(isdigit(s[i]))
            {
                for(int j = 0; j < 13; j++)
                {
                    dp[i+1][(mod[i+1][s[i] - '0'] + j)%13] = dp[i][j];
                }
            }
            else
            {
                for(int j = 0; j < 10; j++)
                {
                    for(int k = 0; k < 13; k++)
                    {
                        ll x = (mod[i+1][j] + k)%13;
                        dp[i+1][x] = (dp[i+1][x] +dp[i][k])%MOD;
                    }
                }
            }
        }
        cout<<dp[s.length()][5]<<endl;
//    }



    return 0;
}




Measured memory_bytes: 19968
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	int n; string s;
	cin >> n >> s;
	puts(count(all(s), 'R') > count(all(s), 'B') ? "Yes" : "No");
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
using namespace std;


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


int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int left = a + b;
  int right = c + d;

  if(left > right)  cout << "Left" << endl;
  else if(left < right) cout << "Right" << endl;
  else cout << "Balanced" << endl;


}


Measured memory_bytes: 256
def C_pushpush(x):
    from collections import deque
    # insertをリストの先頭に行うと、リストの要素の再配置に時間がかかる
    n = int(x[0])
    a = deque(x[1:])
    b = deque([])
    n_parity = n & 1
    for i in range(n):
        if n_parity == (i + 1) & 1:
            # n,iのパリティが一致
            b.appendleft(a[i])
        else:
            b.append(a[i])
    print(' '.join(b))

n = input()
l = [i for i in input().split()]
x = [n]+l
C_pushpush(x)

Measured memory_bytes: 29764
#include<cstdio>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;
const int N=202202;
int a[N];
int n,m,sum=0;
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1; i<=n; i++)
		scanf("%d",&a[i]);
	if (m>=n){
		printf("%d",0);
		return 0;
	}
	sort(a+1,a+1+n);
	ll ans=0;
	for (int i=1; i<=n-m; i++)
		ans=ans+a[i];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 896