akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main(void)
{
	int n,i,m,f,r;
	scanf("%d %d %d",&m,&f,&r);
	while(m != -1 || f != -1 || r != -1)
	{
		if(m == -1 || f == -1)
		{
			printf("F\n");
		}
		else
		{
			n = m + f;
			if(n >= 80)
			{
				printf("A\n");
			}
			else if(n >= 65)
			{
				printf("B\n");
			}
			else if(n >= 50)
			{
				printf("C\n");
			}
			else if(n >= 30)
			{
				if(r >= 50)
				{
					printf("C\n");
				}
				else
				{
					printf("D\n");
				}
			}
			else
			{
				printf("F\n");
			}
		}
		scanf("%d %d %d",&m,&f,&r);
	}
	return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

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

    int dp[MAX];
    dp[0] = 0;
    For(i, 1, MAX) dp[i] = 1 + dp[i % __builtin_popcount(i)];

    int p = count_if(s.begin(), s.end(), [](char c){return c == '1';}) + 1;
    int q = p - 2;
    int pow2_p[n], pow2_q[n], x = 0, y = 0;
    pow2_p[0] = pow2_q[0] = 1;
    For(i, 1, n){
        pow2_p[i] = pow2_p[i-1]*2 % p;
        if(q > 0) pow2_q[i] = pow2_q[i-1]*2 % q;
    }
    rep(i, n){
        x = (x*2 + (s[i]-'0')) % p;
        if(q > 0) y = (y*2 + (s[i]-'0')) % q;
    }

    rep(i, n){
        if(s[i] == '0'){
            int tmp = (x + pow2_p[n-1-i]) % p;
            printf("%d\n", 1 + dp[tmp]);
        }
        else{
            if(q == 0) printf("%d\n", 0);
            else{
                int tmp = (y + q - pow2_q[n-1-i]) % q;
                printf("%d\n", 1 + dp[tmp]);
            }
        }
    }
}

Measured memory_bytes: 6112
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  ll k;
  cin >> n >> k;
  int a[n];
  REP(i, n) cin >> a[i];
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (a[i] > a[j]) {
        ans += k * (k + 1) / 2;
        ans %= MOD;
      } else if (a[i] < a[j]) {
        ans += k * (k - 1) / 2;
        ans %= MOD;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << ": " << x << '\n';

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n; cin >> n;
  int sum = 0;
  vector<long long> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec[i];
    sum += vec[i];
  }
  int m; cin >> m;
  for (int i = 0; i < m; i++) {
    int p, x;
    cin >> p >> x;
    int ans = sum;
    ans -= vec[p - 1];
    ans += x;
    cout << ans << '\n';
  }

}


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

int main(){
  int m1,d1,m2,d2;
  cin>>m1 >>d1 >>m2 >>d2;
  
  if(m1!=m2){
    cout<<1<<endl;
  }
  else
    cout<<0<<endl;
  return(0);
  


}

Measured memory_bytes: 256
// practice with Dukkha
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 200000;

int aa[N], ff[N];

int main() {
	int n; cin >> n;
	long long k; cin >> k;
	for (int i = 0; i < n; i++)
		cin >> aa[i];
	for (int i = 0; i < n; i++)
		cin >> ff[i];
	sort(aa, aa + n);
	sort(ff, ff + n);
	long long lower = -1, upper = (long long) aa[n - 1] * ff[n - 1];
	while (upper - lower > 1) {
		long long x = (lower + upper) / 2;
		long long sum = 0;
		for (int i = 0; i < n; i++) {
			int a = aa[i], f = ff[n - 1 - i];
			sum += max(a - x / f, 0LL);
		}
		if (sum <= k)
			upper = x;
		else
			lower = x;
	}
	cout << upper << '\n';
	return 0;
}


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

int main() {
  char c;
  cin >> c;

  string ans;
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
    ans = "vowel";
  } else {
    ans = "consonant";
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var sc *bufio.Scanner

const BufferSize = 1024

func nextInt() int {
	if !sc.Scan() {
		panic(nil)
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var production bool

func debugf(format string, v ...interface{}) {
	if !production {
		fmt.Printf(format, v...)
	}
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, 1e+6)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	w := make([]int, n)
	r := make([]int, n)
	l := make([]int, n)

	for i := range w {
		w[i] = nextInt()
	}
	for i := range w {
		if i > 0 {
			r[i] = r[i-1] + w[i]
			l[i] = l[i-1] + w[len(w)-i-1]
		} else {
			r[0] = w[0]
			l[0] = w[len(w)-1]
		}
	}
	ans := 100 * 100 * 100
	for i := 0; i < len(w)-1; i++ {
		dif := l[i] - r[len(w)-i-2]
		if dif < 0 {
			dif = -dif
		}
		ans = min(ans, dif)
		debugf("%d: r:%d, l:%d, dif:%d, ans:%d\n", i, r[len(w)-i-2], l[i], dif, ans)
	}

	_, _ = fmt.Fprintf(writer, "%d", ans)
}

func main() {
	production = true
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<55;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int n,q,res=0;
vi a,b;
map<int,int> m;

void f(int x,bool t){
	int A=m[x];
	if(t){
		m[x]=A+1;
		if(!A&&x>=0) res--;
	}
	else{
		m[x]=A-1;
		if(A==1&&x>=0) res++;
	}
}

int main(){
	cin>>n>>q;
	a=b=vi(n);
	res=n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		b[--a[i]]++;
	}
	for(int i=0;i<n;i++) for(int j=0;j<b[i];j++) f(i-j,1);
	for(int i=0;i<q;i++){
		int x,y;
		cin>>x>>y;
		x--;y--;
		b[a[x]]--;
		f(a[x]-b[a[x]],0);
		a[x]=y;
		f(y-b[y],1);
		b[y]++;
		cout<<res<<endl;
	}
}

Measured memory_bytes: 21760
A,B,M = map(int,input().rstrip().split())
a = list(map(int, input().rstrip().split()))
b = list(map(int, input().rstrip().split()))
x = [list(map(int,input().rstrip().split())) for _ in range(M)]
Low_price = min(a) + min(b)
disc_prices = []
for i in range(M):
	disc_prices.append(a[x[i][0]-1] + b[x[i][1]-1] - x[i][2])
if Low_price <= min(disc_prices):
	print(Low_price)
else:
  	print(min(disc_prices))

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

int main() {
  int a,b,c,d;
  cin >>a>>b>>c>>d;
  
  int x = max(a,c);
  int y = min(b,d);
  
  cout << max(0,y-x) << endl;
  
  return 0;
}

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

using namespace std;

void solve(string S) {
  int ans = 0;
  int len = 0;
  rep(i, S.length()) {
    if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
      len++;
      ans = max(ans, len);
    } else {
      len = 0;
    }
  }
  cout << ans << endl;
}

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

  string S;
  cin >> S;
  solve(S);
  return 0;
}


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

using namespace std;

#define debug(x) cout << #x << "==" << x << endl;

const int mod = 1e+9 + 7;

typedef long long ll;


inline ll add(ll a, ll b) {
  return (a + b) % mod;
}

inline ll sub(ll a, ll b) {
  return (a - b + mod) % mod;
}

inline ll mul(ll a, ll b) {
  return (a * b) % mod;
}


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

  int n, m;
  cin >> n >> m;

  vector<ll> x(n), y(m);
  for(int i = 0; i < n; i++) { cin >> x[i]; }
  for(int i = 0; i < m; i++) { cin >> y[i]; }

  ll x_sum = 0;
  for(int k = 0; k < n; k++) {
    ll t1 = mul(k, x[k]);
    ll t2 = mul(n-k-1, x[k]);
    ll t3 = sub( t1, t2 );
    x_sum = add(x_sum, t3);
    // x_sum += k * x[k] - (n-k-1) * x[k];
    // x_sum %= mod;
  }

  ll y_sum = 0;
  for(int k = 0; k < m; k++) {
    ll t1 = mul(k, y[k]);
    ll t2 = mul(m-k-1, y[k]);
    ll t3 = sub( t1, t2 );
    y_sum = add(y_sum, t3);
    // y_sum += k * y[k] - (m-k-1) * y[k];
    // y_sum %= mod;
  }
  cout << mul(x_sum, y_sum) << "\n";



  return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
#define show(x) cout << #x << " is " << x << "\n";
typedef vector<ll> vi;
#define fi first
#define se second
const ll inf = 9e18;
const ll mod = 1e9 + 7;

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y, ll M = inf){
    ll ans = 1;
    x %= M;
    while(y){
        if(y&1)
            ans = (x * ans) % M;

        x = (x * x) % M;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2, mod);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

//const ll N = 1e5 + 1;
//vector<ll> adj[N];
//bool visited[N];

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

	ll n, a, b, c;
	cin>>n>>a>>b>>c;
	string s[n+5];
	for(int i=0;i<n;i++){
		cin>>s[i];
	}
	vector<char> v;
	for(int i=0;i<n;i++){
		if(s[i] == "AB"){
			if(a==0 && b==0){
				cout<<"No";
				return 0;
			}
			if(a < b){
				a++;
				b--;
				v.pb('A');
			}
			else if(a > b){
				a--;
				b++;
				v.pb('B');
			}
			else{
				if(s[i+1]=="BC"){
					a--;
					b++;
					v.pb('B');
				}
				else {
					a++;
					b--;
					v.pb('A');
				}
			}

		}
		else if(s[i] == "BC"){
			if(c==0 && b==0){
				cout<<"No";
				return 0;
			}
			if(c < b){
				c++;
				b--;
				v.pb('C');
			}
			else if(c > b){
				c--;
				b++;
				v.pb('B');
			}
			else{
				if(s[i+1]=="AC"){
					b--;
					c++;
					v.pb('C');
				}
				else {
					c--;
					b++;
					v.pb('B');
				}
			}
		}
		else{
			if(a==0 && c==0){
				cout<<"No";
				return 0;
			}
			if(a < c){
				a++;
				c--;
				v.pb('A');
			}
			else if(a > c){
				a--;
				c++;
				v.pb('C');
			}
			else{
				if(s[i+1]=="AB"){
					a++;
					c--;
					v.pb('A');
				}
				else {
					c++;
					a--;
					v.pb('C');
				}
			}
		}
	}
	cout<<"Yes\n";
	for(int i=0;i<n;i++){
		cout<<v[i]<<"\n";
	}
	return 0;
}


Measured memory_bytes: 6920
import math
from decimal import *
getcontext().prec = 28
a,b=map(str, input().split())
a_ = Decimal(a)
b_ = Decimal(b)
#b = b*100
#print(round(Decimal(Decimal(a)*Decimal(b))))
print(math.floor(a_*b_))
#print(math.floor(Decimal(a)*Decimal(b)/Decimal(100.0)))

Measured memory_bytes: 10084
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define rep(i,j,k) for(int i=j;i<k;i++)
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
const int  COMMAX = 510000;

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

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

struct UnionFind {
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
  vector<int> rank;
  int num;
  UnionFind(int N) : par(N) , rank(N) { //最初は全てが根であるとして初期化
    num = N;
    for(int i = 0; i < N; i++){
      par[i] = i;
      rank[i] = 0;
    }
  }

  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
    if(rank[rx] < rank[ry]){
      par[rx] = ry;  
    }else{
      par[ry] = rx;
      if(rank[rx] == rank[ry])rank[rx]++;
    }
    num--;
  }

  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    return root(x) == root(y);
  }
};

const int MS = 2;
const long long mod[] = {999999937LL, 1000000007LL}, base = 9973;
struct rolling_hash {
    int n;
    vector<long long> hs[MS], pw[MS];
    rolling_hash(){}
    rolling_hash(const string &s) {
        n = s.size();
        for (int i = 0; i < MS; i++) {
            hs[i].assign(n+1,0);
            pw[i].assign(n+1,0);
            hs[i][0] = 0;
            pw[i][0] = 1;
            for (int j = 0; j < n; j++) {
                pw[i][j+1] = pw[i][j]*base%mod[i];
                hs[i][j+1] = (hs[i][j]*base+s[j])%mod[i];
            }
        }
    }

    long long hash(int l, int r, int i) { return ((hs[i][r]-hs[i][l]*pw[i][r-l])%mod[i]+mod[i])%mod[i]; }

    bool match(int l1, int r1, int l2, int r2) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l1,r1,i)==hash(l2,r2,i);
        return ret;
    }

    bool match(int l, int r, long long h[]) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l,r,i)==h[i];
        return ret;
    }
};

int main(){
  ULL a;
  cin >> a;
  ULL b = sqrt(a);
  if(b * b == a){
    cout << 0 << " " << 0 << " " << b << " " << 0 << " " << 0 << " " << b << endl;
  }else{
    cout << 0 << " " << 0 << " " << b+1 << " " <<  ((b+1)*(b+1) - a)  << " " << 1 << " " << b+1 << endl;
  
  }
  return 0;
}



Measured memory_bytes: 256
#include<cstdio>

int n;
int h[101];
int arr[100];

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

		if( n == 0 ) break;
		
		for( int i = 0; i < n + 1; ++i ) {
			scanf("%d", &h[i]);
		}
		
		int ans = -1;
		for( int i = 0; i < n + 1; ++i ) {
			for( int j = 0; j < n + 1; ++j ) {
				if( i==j ) continue;
				arr[j - (j>i)] = h[j];
			}
			int d = arr[1] - arr[0];
			bool flag = true;
			for( int j = 1; j < n; ++j ) {
				flag &= (arr[j]-arr[j-1])==d;
			}
			if(flag) {
				// 3
				// 1 2 3 5
				printf("%d\n", h[i]);
				break;
				//ans = h[i];
			}
		}
		
		//printf("%d\n", ans);
	}

	return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <cmath>
#include <iomanip>

using namespace std;

using ll = long long;
using vl = vector<long long>;
using vi = vector<int>;
using vvl = vector<vl>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using ld = long double;

ll mod = 1e9 + 7;

struct M
{
    vvl m;

    M(int r, int c, ll va = 0)
    {
        m = vvl(r, vl(c, va));
    }

    vl& operator[](int i)
    {
        return m[i];
    }

    M operator*(M &b)
    {
        M res(m.size(), b[0].size());
        for (int r = 0; r < res.m.size(); r++)
            for (int c = 0; c < res[0].size(); c++)
                for (int j = 0; j < m[0].size(); j++)
                    res[r][c] = (res[r][c] + (m[r][j] * b[j][c]) % mod) % mod;
        return res;
    }
};

int main()
{
    int n;
    ll k;
    cin >> n >> k;
    M ex(n, n);
    for (auto &v : ex.m)
        for (auto &e : v)
            cin >> e;
    M res_m(n, n);
    for (int i = 0; i < n; i++)
        res_m[i][i] = 1;
    while(k)
    {
        if (k % 2)
            res_m = res_m * ex;
        ex = ex * ex;
        k /= 2;
    }
    ll res = 0;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            res = (res + res_m[i][j]) % mod;
    cout << res;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define For(i,j,k) for(int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for(int i=(int)(j);i>=(int)(k);i--)
inline ll read(){
	ll x=0;char ch=getchar();bool f=0;
	for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=1;
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return f?-x:x;
}
void write(ll x){
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);putchar(x%10+'0');
}
void writeln(ll x){write(x);puts("");}
void writep(ll x){write(x);putchar(' ');}

int const N=1e5+3;
int n,m,kk,p,ans,sum,b[N],a[N];

bool cmp(int x,int y){
	return x>y;
}
signed main(){
	n=read();m=read();kk=read();ans=p=read();
	for (int i=1;i<=n;i++) a[i]=read();
	sort(a+1,a+n+1,cmp);
	for (int i=1;i<=n;i++) b[i]=b[i-1]+a[i];
	for (int i=1;i<p;i++) sum+=a[i];
	int k=1;
	for (int i=p+1;i<=n;i++){
		while (a[i]+m<a[k]) sum-=a[k],k++;
		if (k>p) break;
		if ((a[i]+m)*(i-k)-(b[i-1]-b[k-1])+(n-i+k-1)*m+sum-a[i]*(p-k)>=(kk-1)*m) ans++;
	}
	writeln(ans);
	return 0;
}

Measured memory_bytes: 1792
L, R = map(int, input().split())
MOD = 10 ** 9 + 7
l = '{:060b}'.format(L)[::-1]
r = '{:060b}'.format(R)[::-1]

memo = [[[[-1 for l in range(2)] for k in range(2)] for j in range(2)] for i in range(60)]

def f(pos, flagX, flagY, flagZ):
    if pos == -1:
        return 1
    if memo[pos][flagX][flagY][flagZ] != -1:
        return memo[pos][flagX][flagY][flagZ]
    ret = 0
    # x 0, y 0
    if flagX or l[pos] == '0':
        ret += f(pos - 1, flagX, 1 if r[pos] == '1' else flagY, flagZ)
    # x 0, y 1
    if (flagX or l[pos] == '0') and (flagY or r[pos] == '1') and flagZ:
        ret += f(pos - 1, flagX, flagY, flagZ)
    # x 1, y 1
    if flagY or r[pos] == '1':
        ret += f(pos - 1, 1 if l[pos] == '0' else flagX, flagY, 1)
    ret %= MOD
    memo[pos][flagX][flagY][flagZ] = ret
    return ret

ans = f(59, 0, 0, 0)
print(ans)


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

int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  for (int i = 0; i < tx - sx; i++) cout << 'R';
  for (int i = 0; i < ty - sy; i++) cout << 'U';
  for (int i = 0; i < tx - sx; i++) cout << 'L';
  for (int i = 0; i < ty - sy; i++) cout << 'D';

  cout << 'D';
  for (int i = 0; i < tx - sx + 1; i++) cout << 'R';
  for (int i = 0; i < ty - sy + 1; i++) cout << 'U';
  cout << "LU";
  for (int i = 0; i < tx - sx + 1; i++) cout << 'L';
  for (int i = 0; i < ty - sy + 1; i++) cout << 'D';
  cout << 'R' << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <utility>
#define pii pair<int,int>
#define F first
#define S second
using namespace std;

const int INF = 1e7;

int dp[(1LL << 12) + 10], n, m, a, b, c;
pii keys[1010];

int main(){
    cin >> n >> m;
    int seed = 0;
    for(int i = 0; i < m; i++){
        cin >> keys[i].F >> b;
        seed = 0;
        for(int i = 0; i < b; i++){
            cin >> c;
            c--;
            seed |= (1LL << c);
        }
        keys[i].S = seed;
        //cout << "Cost of " << i << " th key is " << keys[i].F << ", and seed = " << keys[i].S << endl;
    }
    for(int i = 0; i < (1LL << n); i++){
        dp[i] = INF;
    }
    dp[0] = 0;
    //for(int i = 0; i < (1LL << n); i++){
    //    cout << "dp[" << i << "] = " << dp[i] << endl;
    //}

    int nv;

    for(int i = 0; i < (1LL << n); i++){
        if(dp[i] == INF) continue;
        for(int j = 0; j < m; j++){
            //cout << "dp[" << (i | keys[j].S) << "] = " << dp[(i | keys[j].S)] << endl;
            //cout << "Cost of " << j << "th key = " << keys[i].F << endl;
            //cout << "Newvl = " << dp[i] + keys[j].F << endl;
            dp[(i | keys[j].S)] = min(dp[(i | keys[j].S)], dp[i] + keys[j].F);
            //cout << "dp[" << (i | keys[j].S) << "] = " << dp[(i | keys[j].F)] << endl;
        }
    }
    cout << (dp[(1LL << n) - 1] == INF ? -1 : dp[(1LL << n) - 1]) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll MOD=1e9 + 7 ;
const ll dx[4] = { -1,1,0,0 };
const ll dy[4] = { 0,0,-1,1 };
const ll MAX =  1e3 ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
long long gcd(long long  a, long long  b) { return (b == 0 ? a : gcd(b, a % b)); }
ll n , m  , k , Q , l , x , y, ans; string s;
char mat[MAX][MAX];
bool vis[MAX][MAX];
ll nbw,nbb;
  ll h,w;
bool valid(int i , int j){

    return i < h && i>=0 && j < w && j>=0;
}
void dfs(int i , int j , char prev){

    if(!valid(i,j) || mat[i][j] == prev || vis[i][j]) return;

    vis[i][j] = true;

    if(mat[i][j] == '#')
        nbb++;
    else
        nbw++;

    for(int k = 0 ; k < 4 ; ++k)
        dfs(i + dx[k],j + dy[k],mat[i][j]);


}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
   // freopen("test.in","r",stdin);



    cin>>h>>w;

    for(int i = 0 ; i < h ; ++i){
        cin>>s;
        for(int j = 0 ; j < w ; ++j)
            mat[i][j] = s[j];
    }

    for(int i = 0 ; i < h ; ++i)
        for(int j = 0 ; j < w ; ++j)
            if(!vis[i][j] && mat[i][j]=='#'){
            vis[i][j] = true;
            nbb = 1; nbw = 0;
            for(int k = 0 ; k < 4 ; ++k)
                dfs(i + dx[k],j + dy[k],'#');

            ans+=nbb*nbw;
            }

        cout<<ans<<'\n';

        return 0;
}


Measured memory_bytes: 8576
#include <iostream>
using namespace std;
int main(){

int a,b    ;

//変数を宣言

cin >> a >> b	;

//外部入力を変数を2つ読み込む

cout <<a*b<<" "<<2*(a+b)<< endl;	

//面積・空白スペース・州の長さ・改行を出力
//ここに処理を記述していきます（この行は残しておいても、消しても大丈夫です）


return 0;
}


Measured memory_bytes: 3032
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll N, P;
  cin >> N >> P;
  if (N == 1) {
     cout << P << endl;
     return 0;
  }
  ll ans = 1;
  for (ll i = 2; i * i <= P; ++i) {
    ll temp = P;
    if (P % i == 0) {
      ll cnt = 0;
      while (temp % i == 0) {
        temp /= i;
        cnt += 1;
      }
      if (cnt >= N) {
        ans = i;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <cassert>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
long gcd(long a, long b) {return b % a ? gcd(b % a, a) : a;}
long lcm(long a, long b) {return a / gcd(a, b) * b;}
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

long pos[202020];
long dp[202020];

int main() {
    long n;
    cin >> n;
    REP(i,n) {
        long p;
        cin >> p;
        pos[p] = i;
    }
    
    long prepos = pos[n];
    dp[n] = 0;
    
    for (long i = n - 1; i > 0; i--) {
        long nowpos = pos[i];
        if (nowpos < prepos) {
            dp[i] = dp[i+1] + 1;
        } else {
            dp[i] = 0;
        }
        prepos = nowpos;
    }
    
    long m = -1;
    REPI(i,1,n+1) {
        m = max(m, dp[i]);
    }
    cout << n - m - 1 << endl;
}


Measured memory_bytes: 3456
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
#define ll long long
int main(void) {
ll count=0;
int sMax;;
int bnum=0;
string str;
char tmp;
cin>>str;
sMax=str.size();
for(int i=sMax-1;i>=0;i--){
  if(str[i]=='B'){
    count+=(sMax-1-bnum-i);
    bnum++;
    }
}
printf("%lld\n",count);
}

/*
for(int i=sMax-1;i>=0;i--){
  if(str[i]=='B'){
    for(int j=1;i+j<=sMax-1;j++){
      if(str[i+j]=='W'){
      tmp=str[i+j];
      str[i+j]=str[i+j-1];
      str[i+j-1]=tmp;
      count++;
      }
      else
      break;
    }
  }
}
*/


Measured memory_bytes: 640
n,m = map(int, input().split())
master = [True] * m
for i in range(n):
    d = map(int, input().split())
    d = list(d)
    num = int(d[0])
    d = d[1:]
    table = [False] * (m + 1)
    for j in range(num):
        table[ d[j] - 1 ] = True
    for j in range(m):
        master[j] = master[j] and table[j]

count = 0
for j in range(m):
    if master[j]:
        count += 1
print(count)

Measured memory_bytes: 38256
#include<stdio.h>
int main()
{
	int n,pm,pe,pj,i;
	scanf("%d",&n);
	while(n!=0){
		for(i=0;i<n;i++){
			scanf("%d %d %d",&pm,&pe,&pj);
			if(pm==100||pj==100||pe==100||(pe+pm)/2>=90||(pe+pm+pj)/3>=80){
				printf("A\n");
			}
			else if((pe+pm+pj)/3>=70)
				printf("B\n");
			else if((pe+pm+pj)/3>=50&&(pm>=80||pe>=80)){
					printf("B\n");
			}
			else{
				printf("C\n");
			}
		}
		scanf("%d",&n);
	}
	return 0;
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
using namespace std;
int n,p,a[20005],b[20005],lp; 
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    return x*f;
}
int main(){
	n=read(),p=read(),lp=p;
	a[p]=p*n,b[p]=(n-p+1)*n;
	for(int i=1;i<n;++i){
		p=read();
		a[p]=p*n+i;
		b[p]=(n-p+1)*n;
	}
	for(int i=1;i<=n;++i) printf("%d ",a[i]); puts("");
	for(int i=1;i<=n;++i) printf("%d ",b[i]);
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
long long i,hhh=10,aaa,l,j,n; 
int main()
{
	scanf("%lld",&n);
	if(n%2==1)
	{
		printf("0");
		return 0;
    }
    aaa=n/10;
    while(hhh<=n)
    {
    	hhh*=5;
    	aaa+=n/hhh;
	}
	printf("%lld",aaa); 
	return 0;
}

Measured memory_bytes: 256
import sys


def input():
    return sys.stdin.readline()[:-1]

# N = int(input())
# A = [int(x) for x in input().split()]
# a, b, c = map(int, input().split())
# name1 = str(input())
# alph = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}


a,b=map(int,input().split())
print(a-b+1)

Measured memory_bytes: 2940
H, W, N = (int(x) for x in input().split())
X = []
Y = []
Xobslist =  [[] for i in range(H)]
Xobsnum = []
ans = H
for i in range(H):
    Xobsnum.append(0)
for i in range(N):
    x, y = (int(x) for x in input().split())
    x -= 1
    y -= 1
    Xobslist[x].append(y)
    Xobsnum[x] += 1
can_go_to_Y = 0 #Y方向到達可能範囲 : 0 <= y <= can_go_to_Y
for x in range(H): #上から順に見る
    if (x == 0):
        continue
    xobsnum = Xobsnum[x]
    can_stop = False
    can_go_to_Y_will_inc = True #(x, can_go_to_Y + 1)に障害物がなければY方向到達可能範囲が1増える
    for i in range(xobsnum):
        y = Xobslist[x][i]
        if (y <= can_go_to_Y):
            can_stop = True
            break
        elif (y == can_go_to_Y + 1):
            can_go_to_Y_will_inc = False
    if can_stop:
        ans = x
        break
    if can_go_to_Y_will_inc:
        can_go_to_Y += 1
print(ans)

Measured memory_bytes: 34548
s=input()[::-1]
n=len(s)
a=[0]*2019
a[0]=1
x=1
p=0

for i in range(n):
    p+=x*int(s[i])
    p%=2019
    a[p]+=1
    x=(x*10)%2019
ans=0
for i in range(2019):
    ans+=a[i]*(a[i]-1)//2
print(ans)


Measured memory_bytes: 68468
#import random, string

#def randomname(n):
#    candidate_text = ["W","B"]
#    randlst = [random.choice(candidate_text) for i in range(n)] #()の中身を string.ascii_letters + string.digits とすると大小英数字
#    return ''.join(randlst)

S = [0] + list(input())
#S = [0] + list(randomname(2*10**5))

N = len(S) - 1

#頭のWは無視
i = 1
while 1:
    #print(i,S[i])

    if i == N:
        print(0)
        break
    elif S[i] == "W":
        i += 1
    else:
        #print("BW pattern")

        ans = 0
        start = i
        B_count = 1

        for j in range(start+1,N+1):
            if S[j] == "W":
                ans += B_count
            elif S[j] == "B":
                B_count += 1
        print(ans)
        break


Measured memory_bytes: 11848
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D, L, R;
  cin >> A >> B >> C >> D;
  
  L = A + B, R = C + D;
  
  if (L == R)
    cout << "Balanced" << endl;
  
  else if (L > R)
    cout << "Left" << endl;
  
  else
    cout << "Right" << endl;
}
 
  

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18

priority_queue<int,vector<int>,greater<int>> que;
int n,y;

void solve(){
	cin >> n >> y;
	for(int i=0;i<=n;i++){
		int a=y-10000*i;
		if(a<0)break;
		for(int j=0;j<=n-i;j++){
			int b=a-5000*j;
			if(b<0)break;
			int k=b/1000;
			if(i+j+k==n){
				printf("%d %d %d\n",i,j,n-j-i);
				return;
			}
		}
	}
	printf("-1 -1 -1\n");
}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


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

int main() {
  int n;
  cin >>n;
  vector<int>a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  sort(a.begin(),a.end());
  int saishou=a[0];
  int saidai=a[n-1];
  int kotae=INT_MAX;
  for(int j=saishou;j<=saidai;j++){
    int wa=0;
    for(int i=0;i<n;i++){
      wa+=(j-a[i])*(j-a[i]);
    }
    kotae=min(kotae,wa);
  }
  cout<<kotae<<endl;
  return 0;
}
    

  

Measured memory_bytes: 3560
from bisect import *
from collections import *
N=int(input())
AB=[map(int,input().split()) for i in range(N-1)]
data=[[] for i in range(N+1)]
for a,b in AB:
    data[a].append(b)
    data[b].append(a)
stack=deque([[1,0]])
visited=set([1])
flag=0
while stack :
    a,m=stack.popleft()
    for p in data[a]:
        if p==N:
            flag=1
            break
        if not p in visited:
            visited.add(p)
            stack.append([p,m+1])
    if flag:
        break

M=m//2
countFennec=0
countSnuke=0
visited=set([1,N])
stackSnuke=deque([[N,0]])
while stackSnuke:
    a,m=stackSnuke.popleft()
    if m>=M:
        stackSnuke.append([a,m])
        break
    for p in data[a]:
        if not p in visited:
            countSnuke+=1
            visited.add(p)
            stackSnuke.append([p,m+1])

stackFennec=deque([[1,0]])
while stackFennec:
    a,m=stackFennec.popleft()
    for p in data[a]:
        if not p in visited:
            countFennec+=1
            visited.add(p)
            stackFennec.append([p,m+1])

while stackSnuke:
    a,m=stackSnuke.popleft()
    for p in data[a]:
        if not p in visited:
            countSnuke+=1
            visited.add(p)
            stackSnuke.append([p,m+1])


if countFennec>countSnuke:
    print("Fennec")
else:
    print("Snuke")


Measured memory_bytes: 109656
use proconio::input;
use proconio::marker::Chars;

// WA
fn main() {
    input! {
        s: Chars,
        t: Chars,
    };
    let ls = s.len();
    let lt = t.len();
    let mut cnt = lt;
    for i in 0..ls-lt+1 {
        let x = s[i..].iter().zip(t.iter()).filter(|(x,y)| x != y).count();
        if x < cnt {
            cnt = x;
        }
    }
    println!("{}", cnt);
}


Measured memory_bytes: 2120
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc(), f;
  while ((ch < '0' || ch > '9') && (ch != '-')) ch = gc();
  f = (ch == '-' ? ch = gc(), -1 : 1);
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
  n *= f;
}

int const MAXN = 1e5 + 5;
LL a[MAXN], x[MAXN], p[MAXN];

int main() {

#ifdef LOCAL
  FILEIO("a");
#endif

  int n, S; read(n), read(S);
  for (RI i = 1; i <= n; ++i)
    read(x[i]), read(p[i]);
  int l = 1, r = n, cnt = 0;
  while (x[l] <= S && x[r] >= S) {
    if (p[l] < p[r]) a[++cnt] = l, p[r] += p[l], ++l;
    else a[++cnt] = r, p[l] += p[r], --r;
  }
  if (x[r] <= S) for (RI i = l; i <= r; ++i) a[++cnt] = i;
  else for (RI i = r; i >= l; --i) a[++cnt] = i;
  a[cnt + 1] = n + 1, x[n + 1] = S;
  LL ans = 0;
  for (RI i = 1; i <= cnt; ++i) ans += abs(x[a[i]] - x[a[i + 1]]);
  printf("%lld\n", ans);

  cerr << (double)(clock()) / CLOCKS_PER_SEC * 1000 << "ms" << endl;

  return 0;
}

// created by Daniel yuan

Measured memory_bytes: 3584
# import math
# import fractions
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a = sorted(a)

div = a[0]
for i in range(1, n):
    div = gcd(div, a[i])

if k % div == 0 and k <= a[-1]:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


Measured memory_bytes: 14252
A,B=map(int, input().split())

def f(x):
    D=1
    res=0
    while True:
        d,m=divmod(x+1,D<<1)
        if (d*D + max(0, m-D))&1: res+=D
        if d==0: break
        D<<=1
    return res

ans=f(B)
if A: ans^=f(A-1)
print(ans)


Measured memory_bytes: 38516
N, Y = map(int, input().split())

a = 0

for i in range(N+1):

    for ii in range(N+1 - i):

        iii = N - i - ii

        ans = 10000 * i + 5000 * ii + 1000 * iii
        if ans == Y:
                print(i,ii,iii)
                a += 1
                break

    if a != 0:
        break

if a == 0:
    print(-1,-1,-1)


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

const int INF = 1001001001;
const int mod = 1000000007;

ll pow(ll base, ll order) {
	ll ans = 1;
	rep(i,order - 1) ans *= base;
	return ans;
}

int gcd(int a, int b) {
	if (a < b) {
		int c = a;
		a = b;
		b = c;
	}
	if (b == 0) return a;
	return gcd (b, a % b);
}

ll sum(ll x) { // sum of subsequent numbers from 0 to x
	return x*(x + 1)/2;
}

int main() {
	int n, k;
	cin >> n >> k;
	vector<bool> have(n, false);
	rep(i, k) {
		int d;
		cin >> d;
		rep(j, d) {
			int A;
			cin >> A; A--;
			have[A] = true;
		}
	}
	int ans = 0;
	rep(i, n) {
		//cout << have[i] << endl;
		if (!have[i]) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3628
#include <iostream>
using namespace std;
const int mod = 1000000007;
int N, M, dp[309][309][309]; bool vis[309][309][309];
int solve(int t, int terr, int half) {
	if (t == M) return (terr == N ? 1 : 0);
	if (vis[t][terr][half]) return dp[t][terr][half];
	int ret = 0;
	if (half == 0) {
		ret = (ret + 1LL * solve(t + 1, terr, half) * terr) % mod;
		if(terr < N) ret = (ret + solve(t + 1, terr, half + 1)) % mod;
	}
	else {
		ret = (ret + 1LL * solve(t + 1, terr, half) * half) % mod;
		ret = (ret + 1LL * solve(t + 1, terr + half, 0) * terr) % mod;
		if(terr + half < N) ret = (ret + 1LL * solve(t + 1, terr, half + 1)) % mod;
	}
	vis[t][terr][half] = true;
	dp[t][terr][half] = ret;
	return ret;
}
int main() {
	cin >> N >> M;
	int ret = solve(0, 1, 0);
	for (int i = 1; i < N; i++) ret = 1LL * ret * i % mod;
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 139648
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define SIZE 100005

using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
long long int MOD = 1000000007;
int H,W,h,w;
int main()
{
	cin>>H>>W>>h>>w;
	if(H%h==0&&W%w==0){
		cout<<"No"<<endl;
	}else{
		cout<<"Yes"<<endl;
		int Bsum,Wsum;
		Bsum=((H-1)/h+1)*((W-1)/w+1);
		Wsum=H*W-Bsum;
		//cout<<Bsum<<" "<<Wsum<<endl;
		int x=1;
		while(Bsum*((h*w-1)*x-1)<=Wsum*x)x++;
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if(i%h==0&&j%w==0)cout<<(h*w-1)*x-1;
				else cout<<-x;
				if(j!=W-1)cout<<" ";
			}
			cout<<endl;
		}
	}
	
}

Measured memory_bytes: 1280
using System;

class InsertionSort
{
  public static void Main()
  {
    int n = int.Parse(Console.ReadLine().Trim());
    var input = Console.ReadLine().Trim().Split(' ');
    var A = new int[n];
    for (int i = 0; i < n; i++)
    {
      A[i] = int.Parse(input[i]);
    }
    Sort(A, n);
  }

  static void Sort(int[] A, int n)
  {
    Trace(A);
    int i, j, tmp;
    for (i = 1; i < n; i++)
    {
      tmp = A[i];
      j = i - 1;
      while (j >= 0 && A[j] > tmp)
      {
        A[j + 1] = A[j];
        j--;
      }
      A[j + 1] = tmp;
      Trace(A);
    }
  }

  static void Trace(int[] A)
  {
    string tmp = "";
    foreach (int a in A)
    {
      tmp += a.ToString() + " ";
    }
    tmp = tmp.Trim();
    Console.WriteLine(tmp);
  }

}



Measured memory_bytes: 9704
# import string
import unittest
from io import StringIO
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    N, K = map(int, input().split())
    V = list(map(int, input().split()))
    ans = 0
    for l in range(K+1):
        for r in range(K-l+1):
            if l+r > N:
                continue
            now = []
            val = 0
            for i in range(l):
                now.append(V[i])
                val += V[i]
            for j in range(r):
                now.append(V[-j-1])
                val += V[-j-1]

            d = K-l-r
            now.sort()
            for i in range(d):
                if i >= len(now):
                    break
                if now[i] > 0:
                    break
                val -= now[i]
            ans=max(ans,val)

    print(ans)

resolve()

Measured memory_bytes: 54508
#include <cstdlib>
#include <iostream>
#include <string>
std::string B="4141212141412121";
int main(){
	int i,j,C[8]={},x[8]={},s,m,p,tmp;
	for(i=0;i<8;i++)C[i]=atoi(B.substr(i,8).c_str());
	while(std::cin>>x[0]){
		m=x[0];
		for(i=1;i<8;i++){
			std::cin>>x[i];
			m+=x[i];
		}
		for(i=0;i<8;i++){
			s=0;
			for(j=0;j<8;j++){
				tmp=x[j]-B[i+j]+'0';
				s+=(tmp>0?tmp:0);
			}
			if(s<m){
				m=s;
				p=i;
			}
			else if(m==s&&C[i]<C[p])p=i;
		}
		for(i=0;i<8;i++)std::cout<<B[p+i]<<" \n"[i==7];
	}
}

Measured memory_bytes: 1188
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <ctime>
#include <list>
#include <numeric>
#include <fstream>

using namespace std;
static const double EPS = 1e-8;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> PI;
#ifndef M_PI
const double M_PI=acos(-1.0);
#endif
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FORR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int((a).size()))
#define F first
#define S second
void pkuassert(bool b){if(!b){int a=0;cout << 1/a << endl;}};
int dx[]={0,-1,0,1,1,1,-1,-1},dy[]={1,0,-1,0,1,-1,1,-1};

int N,T,L,B;

bool lose[300];
bool back[300];
double dp[2][300];
double dp2[2][300];

void solve(){
  memset(lose,0,sizeof(lose));
  memset(back,0,sizeof(back));

  rep(i,L){
    int t;
    cin >> t;
    lose[t]=1;
  }
  rep(i,B){
    int t;
    cin >> t;
    back[t]=1;
  }
  memset(dp,0,sizeof(dp));
  memset(dp2,0,sizeof(dp2));
  dp[0][0]=1;
  double ans=0;
  rep(i,T){
    memset(dp[(i+1)&1],0,sizeof(dp[0]));
    memset(dp2[(i+1)&1],0,sizeof(dp[0]));
    int ns=(i+1)&1;
    for(int j=0;j<N;++j){
      dp[ns][j]+=dp2[!ns][j];
      rep(k,6){
        int nv=j+k+1;
        if(nv>N) nv=2*N-nv;
        if(back[nv]) nv=0;
        if(lose[nv]){
          dp2[ns][nv]+=dp[!ns][j]/6;
        }else{
          dp[ns][nv]+=dp[!ns][j]/6;
        }
      }
    }
    ans += dp[ns][N];
  }
  printf("%.8f\n",ans);
}

int main(){
  while(cin >> N >> T >> L >> B && N) solve();
}

Measured memory_bytes: 1192
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

int main(void) {
    int X, A;
    cin >> X >> A;
    if (X<A) cout << 0 << endl;
    else cout << 10 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>

using namespace std;

int top = 0;

int main() {
	char s[11];
	char t[11];
	cin >> s;

	int len = strlen(s);

	for (int i = 0; i < len; i++) {
		if (s[i] == 'B') {
			if (top != 0)
				top--;
			else
				continue;
		}
		else {
			t[top] = s[i];
			top++;
		}
	}
	for (int i = 0; i < top; i++)
		cout << t[i];
	cout << endl;
}

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

using namespace std;
 
int main() {
    int n;cin>>n;
    int renzoku = 0;
    for(int i= 0;i<n;i++){
     int d1,d2;cin>>d1>>d2;
     if(d1 == d2){
     	renzoku+=1;
     }
     else{
       renzoku = 0;
     }
     if(renzoku >= 3){
      cout<<"Yes";
      return 0;
     }
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 3128
from sys import stdin
import sys
import itertools
import array
import textwrap
import math

N = int(input())
X = input()
temp = X.count("1")
t = [0, 0, 0]

t[0] = int(X, 2) % (temp-1) if temp != 1 else 0
t[2] = int(X, 2) % (temp+1)
cnt = 0
for i in range(N):
    if X[i] == "1" and temp == 1:
        print(0)
        continue
    if X[i] == "1":
        # p = (1 << (N-i-1)) % (temp-1)
        p = pow(2, N-1-i, temp-1)
        a = (t[0]-p) % (temp-1)
    elif X[i] == "0":
        # m = (1 << (N-i-1)) % (temp+1)
        m = pow(2, N-1-i, temp+1)
        a = (t[2]+m) % (temp+1)
    cnt = 1
    while a > 0:
        a = a % format(a, 'b').count("1")
        cnt += 1
    print(cnt)


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

int main(){
    int N,A,B,C,D;
    string S;
    A = 0;
    B = 0;
    C = 0;
    D = 0;

    cin >> N;

    for(int i = 0; i < N ;i++){
        cin >> S;
        if(S == "AC") A++;
        else if(S =="WA")B++;
        else if(S == "TLE")C++;
        else D++;
    }

    cout <<"AC x "<< A << endl;
    cout <<"WA x "<< B << endl;
    cout <<"TLE x "<< C << endl;
    cout <<"RE x "<< D << endl;

}

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

typedef long long ll;
int n, a[233333];
int main() {
  int i, j;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  ll l = 2, r = 2;
  for (i = n; i; i--) {
    ll L = 1 + (l - 1) / a[i], R = r / a[i];
    if (L > R) return printf("-1"), 0;
    L = L * a[i]; R = R * a[i];
    l = L; r = R + a[i] - 1;
  }
  cout << l << " " << r << endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int n,x,cnt;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        if(x^i)cnt++;
    }
    if(cnt<=2)printf("YES");else printf("NO");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <stdio.h>

using namespace std;

int n, u, k, v;
int adjList[101][101];
int adjNum[101];
bool visited[101];

int lv[101];

queue<int> q;

void bfs(int entry_node) {
    lv[entry_node] = 0;
    q.push(entry_node);

    while (!q.empty()) {
        u = q.front(); q.pop();
        visited[u] = true;

        for (int i = 0; i < adjNum[u]; i++) {
            if (!visited[adjList[u][i]]) {
                if (lv[adjList[u][i]] == -1) {
                    lv[adjList[u][i]] = lv[u] + 1;
                }
                q.push(adjList[u][i]);
            }
        }
    }

}

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

    for (int i = 0; i < n; ++i) {
        scanf("%d %d", &u, &k);
        adjNum[u-1] = k;
        for (int j = 0; j < k; ++j) {
            scanf("%d", &v);
            adjList[u-1][j] = v-1; // all IDs start from 1
        }

        visited[u-1] = false;
        lv[u-1] = -1; // set lv to -1 by default
    }

    bfs(0);
    for (int u = 0; u < n; ++u) {
        cout << u+1 << " " << lv[u] << "\n";
    }

	return 0;
}


Measured memory_bytes: 3384
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define msp multiset < pair < long long , long long > > S;
#define pll pair<lli, lli>
#define mll map<lli, lli>            //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x) // also valid for set and multiset
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
int main()
{
 	ios::sync_with_stdio(0);
    cin.tie(0);
 	lli n,n1=0;
 	cin>>n;
 	lli arr[n];
 	for(lli i=0;i<n;i++){lli x;cin>>x;if(x<0)n1++;arr[i]=abs(x);}
 	lli mini=arr[0],sum=0;
 	for(lli i=1;i<10;i++);
 	for(lli i=0;i<n;i++){sum+=arr[i];mini=min(arr[i],mini);}
 		if(n1%2==0)cout<<sum;
 	else cout<<sum-2*mini;


   	return 0;
 }

Measured memory_bytes: 1024