akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _1_10_D
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] str_xList = Console.ReadLine().Split(' ');
            string[] str_yList = Console.ReadLine().Split(' ');
            double[] xList = new double[n];
            double[] yList = new double[n];
            double[] answer = new double[4];
            double[] sumList = new double[n];
            double sum;
            double sumAnswer = 0;
            for(int i = 0; i < n; i++)
            {
                xList[i] = double.Parse(str_xList[i]);
                yList[i] = double.Parse(str_yList[i]);
            }
            for (int i = 0; i < n; i++)
            {
                sum = Math.Sqrt((xList[i] - yList[i])* (xList[i] - yList[i]));
                sumList[i] = sum;
                answer[0] += sum; 
            }
            for (int i = 0; i < n; i++)
            {
                sum = (xList[i] - yList[i]) * (xList[i] - yList[i]);
                sumAnswer += sum;
            }
            answer[1] = Math.Sqrt(sumAnswer);
            sumAnswer = 0;
            for (int i = 0; i < n; i++)
            {
                sum = (xList[i] - yList[i]) * (xList[i] - yList[i]) * (xList[i] - yList[i]);
                sumAnswer += Math.Sqrt(sum * sum);
            }
            answer[2] = Math.Pow(sumAnswer, 1.0 / 3.0);
            answer[3] = sumList.Max();
            for (int i = 0; i < 4; i++)
            Console.WriteLine(answer[i]);

        }
    }
}



Measured memory_bytes: 20288
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1 << 29;
const int N = 1e6 + 10;
 
struct IOsetup{
  IOsetup(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); 
    cout.tie(nullptr);
    cout << fixed << setprecision(20);
  }
}IO;


int32_t main(){
 string a, b;
 cin >> a >> b;
 cout << b + a << endl;
}

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

#define ll long long
#define mp make_pair
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)

using namespace std;

typedef pair<int, int> pii;
typedef double db;
const int N = 1e6 + 50;
int n, a[N], ans = 0, p;
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^48); ch = getchar();}
	return x*f;
}
void init(){
	n = read(); 
	rep(i, 1, n) a[i] = read();
	sort(a+1, a+n+1);
	rep(i, 1, n) {
		int l = i+1, r = l+1;
		while(l <= r && l < n) {
			while(a[i] + a[l] > a[r] && r <= n) r++;
			ans += r-l-1; 
			l++;
		} 
	}
	printf("%d\n", ans);
}
int main(){
//	freopen("input.in","r",stdin);
//	freopen("output.out","w",stdout);
	init();
	return 0;
}


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

int main() {
  int n, k;
  int i;
  int sum;
  cin >> n >> k;
  
  sum = 0;
  for (i = n; i <= k; i++) {
    if (((i / 10000) == (i % 10)) && (((i % 10000) / 1000) == ((i % 100) / 10))) {
//      cout << i << endl;
      sum++;
    }
    
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
lr = []
for _ in range(m):
    l, r = map(int, input().split())
    lr.append((l, r))

max_l = max(lr[i][0] for i in range(m))
min_r = min(lr[i][1] for i in range(m))

if min_r - max_l >= 0:
    print(min_r - max_l + 1)
else:
    print(0)


Measured memory_bytes: 16612
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<vi> vvi;
typedef std::vector<ll> vll;
typedef std::vector<vll> vvll;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

int main() {
  ll k, a, b;
  scan(k, a, b);
  if (b - a < 2) {
    print(k + 1);
    return 0;
  }
  if (k + 1 < a) {
    print(k + 1);
    return 0;
  }
  ll ans = a;
  k -= (a - 1);
  ans += (b - a) * (k / 2);
  k -= (k / 2 * 2);
  ans += k;
  print(ans);

  return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int N,L,i,j;
string s[101];

int main()
{
    cin >> N >> L, cin.get();
    for(i = 1; i <= N; ++i)
        cin >> s[i];
    for(i = 1; i < N; ++i)
        for(j = i + 1; j <= N; ++j)
            if(s[i] > s[j])
                swap(s[i],s[j]);
    for(i = 1; i <= N; ++i)
        cout << s[i];
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}




int main(void) {
  ll N, M;
  cin >> N >> M;
  ll T=1900*M+100*(N-M);
  
  pt(T*pow(2, M));
  
}














Measured memory_bytes: 512
// AUTHOR : Kishan Srivastav
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main() {
	ios
#ifndef ONLINE_JUDGE
	in;
	out;
#endif
	int n;
	cin>>n;
	int arr[n];
	int count = 0;
	for (int i = 1; i <= n; i++){
		cin>>arr[i];
		if(i % 2 != 0 && arr[i] % 2 != 0){
			count++;
		}
	}
	cout<<count<<endl;
}

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

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"
#define debug(x) cout<<#x<<" = "<<x<<endl;

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

li n,k;

vi a;

bool check(li val)
{
    li cnt=0;

    f(i,0,n-1)
    {
        cnt+=((a[i]-1)/val);
    }

    return cnt<=k;
}

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

    a.resize(n);

    // li a[n];

    li mx=0;

    f(i,0,n-1)
    {
        cin>>a[i];
        mx=max(a[i],mx);
    }

    li l=0,r=mx;

    while(l+1<r)
    {
        li md=(l+r)/2;

        if(check(md))
        {
            r=md;
        }
        else
        {
            l=md;
        }
    }

    cout<<r<<endl;
}

int main()
{    
   

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

    li t=1;

    // cin>>t;

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

    return 0;
}

Measured memory_bytes: 4652
use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::HashSet;
use std::cmp;
use std::f64::consts;

fn main() {
    let d: i64 = read();
    let n: i64 = read();

    let mut ans: i64 = 0;
    if d == 0 {
        if n == 100 {
            ans = n + 1;
        } else {
            ans = n;
        }
    } else {
        let waru = i64::pow(100, d as u32);

        if n == 100 {
            ans = waru * n + waru;
        }else {
            ans = waru * n;
        }
    }

    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// 最大公約数
fn gcd(a: i32, b: i32) -> i32 {
    match b {
        0 => a,
        _ => gcd(b, a % b)
    }
}

// 最小公倍数
fn lcm(a: i32, b: i32) -> i32 {
    a * b / gcd(a, b)
}

// 階乗
fn kaijou(n: i32)->i32 {
    if n == 1 {
        return n;
    }
    return n * kaijou(n-1);
}

Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <math.h>
#include <bitset>

#define X first
#define Y second
#define vsort(v) sort(v.begin(), v.end())
#define vrev(v) reverse(v.begin(), v.end())
#define vmax_p(v) max_element(v.begin(), v.end())
#define vmin_p(v) min_element(v.begin(), v.end())
#define vmax_idx(v) distance(v.begin(), vmax_p(v))
#define vmin_idx(v) distance(v.begin(), vmin_p(v))
#define vcopy(src, dst) copy(src.begin(), src.end(), back_inserter(dst))
#define P pair

// stoi(s): string to int
// stod(s): string to double

// INT_MAX
// INT_MIN
// LLONG_MAX
// LLONG_MIN
// DBL_MIN
// DBL_MAX
// LDBL_MIN
// LDBL_MAX

// A-Z: 65~90
// a-z: 97~122
// |a-z| = 26

// floor(x): truncate

// 2進数変換
// string s = bitset<20>(x).to_string();

using namespace std;
using ll = long long;

int main(int argc, const char *argv[])
{
    int r, g, b, n;
    cin >> r >> g >> b >> n;

    int ans = 0;
    for (int i = 0; r * i <= n; i++)
    {
        for (int j = 0; r * i + g * j <= n; j++)
        {
            if ((n - (r * i + g * j)) % b == 0)
            {
                ans++;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()

{
  int A1,A2,A3,x;
  scanf("%d %d %d",&A1,&A2,&A3);
  x=A1+A2+A3;
  if( x>=22)
  {
      printf("bust\n");
  }
  else
  {
      printf("win\n");
  }

  return 0;
}


Measured memory_bytes: 1624
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
    int n , m;
    cin>>n>>m;
    getchar();
    string str;
    getline( cin , str );
    
    int cnt[n];
    fill( cnt , cnt + n , 0 );
    for( int i = 1 ; i < str.length() ; i++ ){
    	if( str[i] == 'C' ){
    		if( str[i - 1] == 'A' ){
    			cnt[i] += cnt[i - 1] + 1;
			}
			else{
				cnt[i] += cnt[i - 1];
			}
		}
		else cnt[i] += cnt[i - 1];
	}
	
//	for( int i = 0 ; i < n ; i++ ){
//		cout<<cnt[i]<<" ";
//		if( i == n - 1 ) cout<<'\n';
//	}
    for( int i = 0 ; i < m ; i++ ){
    	int l , r;
    	cin>>l>>r;
    	cout<<cnt[r - 1] - cnt[l - 1]<<'\n';
	}
    
    return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<random>
#include<ctime>
#include<cstdlib>
#include<unordered_map>
#include<string.h>
#include<iostream>
#define mod 1000000007
#define int long long
#define P pair<int,int>//距離　頂点
using namespace std;

int dp[100000];
int p[100000];
vector<P>V[100000];
vector<P>S;
int l[100000];
int r[100000];
signed main() {
	int n, m; cin >> n >> m;
	int a, b; cin >> a >> b; a--; b--;
	for (int i = 0; i < m; i++) {
		int x, y, z; cin >> x >> y >> z; x--; y--; z *= 2;
		V[x].push_back({ z,y });
		V[y].push_back({ z,x });
	}
	priority_queue<P, vector<P>, greater<P>>Q;
	memset(l, 0x3f, sizeof(l));
	memset(r, 0x3f, sizeof(r));
	l[a] = 0; r[b] = 0;
	Q.push({ 0,a });
	while (Q.size()) {
		P i = Q.top(); Q.pop();
		if (l[i.second] < i.first)continue;
		for (P t : V[i.second]) {
			if (i.first + t.first < l[t.second]) {
				l[t.second] = i.first + t.first;
				Q.push({ l[t.second],t.second });
			}
		}
	}
	Q.push({ 0,b });
	while (Q.size()) {
		P i = Q.top(); Q.pop();
		if (r[i.second] < i.first)continue;
		for (P t : V[i.second]) {
			if (i.first + t.first < r[t.second]) {
				r[t.second] = i.first + t.first;
				Q.push({ r[t.second],t.second });
			}
		}
	}
	for (int i = 0; i < n; i++) {
		if (l[i] + r[i] == l[b]) {
			S.push_back({ l[i], i });
		}
	}
	dp[a] = 1;
	sort(S.begin(), S.end());
	for (P k : S) {
		for (P u : V[k.second]) {
			if (k.first + u.first == l[u.second]) {
				dp[u.second] += dp[k.second];
				dp[u.second] %= mod;
			}
		}
	}
	S.clear();
	for (int i = 0; i < n; i++) {
		if (l[i] + r[i] == l[b]) {
			S.push_back({ r[i], i });
		}
	}
	p[b] = 1;
	sort(S.begin(), S.end());
	for (P k : S) {
		for (P u : V[k.second]) {
			if (k.first + u.first == r[u.second]) {
				p[u.second] += p[k.second];
				p[u.second] %= mod;
			}
		}
	}
	int ans = dp[b] * dp[b] % mod;
	for (int i = 0; i < n; i++) {
		if (l[i] + r[i] != l[b])continue;
		if (l[i] == l[b] / 2) {
			ans -= (dp[i] * p[i] % mod)*(dp[i] * p[i] % mod)%mod;
			ans %= mod;
		}
		else if(l[i]<l[b]/2){
			for (P j : V[i]) {
				if (l[i] +j.first+ r[j.second] == l[b]) {
					if (l[j.second] > l[b] / 2) {
						ans -= (dp[i] * p[j.second] % mod)*(dp[i] * p[j.second] % mod)%mod;
						ans %= mod;
					}
				}
			}
		}
	}
	while (ans < 0) {
		ans += mod;
	}
	ans %= mod;
	cout << ans << endl;
}

Measured memory_bytes: 18420
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
//typedef __int64 LL;
//typedef long long int LL;
typedef pair<int,int> P;

const int MOD=1000000007;

int main()
{
	int n;
	int x[110];
	int ans=MOD;
	cin>>n;
	for(int i=0;i<n;i++)cin>>x[i];
	
	for(int i=1;i<=100;i++)
	{
		int hp=0;
		for(int j=0;j<n;j++)
		{
			hp+=(i-x[j])*(i-x[j]);
		}
		ans=min(ans,hp);
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
char col[100005];
int D[100005];
vector<int> F[100005], E[100005];
bool used[100005];
void go(int x, int w = 0) {
	if (col[x]) return;
	col[x] = "BW"[w];
	used[x] = true;
	for (int y : F[x]) {
		go(y, 1 - w);
	}
}
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; ++i) scanf("%d", &D[i]);
	vector<pair<int, int>> edges;
	for (int i = 0; i < m; ++i) {
		int u, v;
		scanf("%d%d", &u, &v);
		--u;
		--v;
		edges.emplace_back(u, v);
		E[u].push_back(v);
		E[v].push_back(u);
	}
	vector<int> nex(n, -1);
	for (int i = 0; i < n; ++i) {
		for (int j : E[i]) {
			if (D[j] <= D[i]) {
				nex[i] = j;
				F[j].push_back(i);
				break;
			}
		}
		if (nex[i] == -1) {
			printf("-1\n");
			return 0;
		}
	}
	for (int i = 0; i < n; ++i) {
		if (used[i]) continue;
		int x = i;
		while (!used[x]) {
			used[x] = true;
			x = nex[x];
		}
		go(x);
	}
	col[n] = '\0';
	printf("%s\n", col);
	for (auto& e : edges) {
		int u, v;
		tie(u, v) = e;
		printf("%d\n", max(D[u], D[v]));
	}
}


Measured memory_bytes: 15088
import java.util.Scanner;
 
public class Main {

	public static final MyScanner in = new MyScanner();
	public static int[][][][] memo;

	public static void main(String[] args) {

		int N = in.nextInt();
		int R = in.nextInt();
		int a = N >= 10 ? 0 : 100 * (10 - N);
		System.out.println(R+a);

	}


	public static class MyScanner{
		Scanner sc = new Scanner(System.in);
		String nextLine() {return sc.nextLine();}
		String next() {return sc.next();}
		int nextInt() {return Integer.valueOf(sc.next());}
		long nextLong() { return Long.valueOf(sc.next());}
	}
}

Measured memory_bytes: 21588
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
    long n = long.Parse(Console.ReadLine());
    long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
		long[] answers = new long[100002];
    long answer = 0;
    for(int i = 0; i < n; i++)
    {
      answers[nums[i]]++;
      answers[nums[i]+1]++;
      answers[nums[i]+2]++;
    }
    for(int i = 0; i < 100002; i++)
    {
      answer = Math.Max(answer, answers[i]);
    }
		Console.WriteLine(answer);//WriteLineをWriteとすると、改行なしで出力。
	}
}

Measured memory_bytes: 20064
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);

int H, W, N;

int main(){
  FAST_IO
  cin >> H >> W >> N;
  if(H < W) swap(H, W);

  cout << N / H + (N % H > 0) << '\n';
  return 0;
}


Measured memory_bytes: 256
from sys import stdin
import heapq

def make_ST(n,first): #firstで初期化された、葉がn要素を超えるように2のべき乗個用意されたリストを返す

    i = 0
    ret = []
    while 2 ** (i-1) < n:

        for j in range(2 ** i):
            ret.append(first)

        i += 1

    return ret

def RMQ_update_point(num,point,tree): #葉のindex(0-origin)がpointの要素をnumにする/treeはセグ木

    i = (len(tree) - 1) // 2 + point
    tree[i] = num
    while i > 0:
        i = (i - 1) // 2
        tree[i] = min(tree[i * 2 + 2] , tree[i * 2 + 1])

    return

def RMQ_query(a,b,k,l,r,tree): #query区間左,右,注目ノード番号,担当範囲左,担当範囲右,木

    if r <= a or b <= l: #区間が完全にかぶらない場合inf
        return (float("inf"),float("inf"))
    
    if a <= l and r <= b: #区間が完全に含まれる場合自分
        return tree[k]

    c1 = RMQ_query(a,b,2*k+1,l,(l+r)//2,tree)
    c2 = RMQ_query(a,b,2*k+2,(l+r)//2,r,tree)   

    return min(c1,c2)
        

def want(L,R):

    if L >= R:
        return
    elif L + 1 == R:
        heapq.heappush( q, (p[L],p[R],float("inf"),float("-inf"),float("inf"),float("-inf")) )
        return

    if L % 2 == 0:
        nx,xind = RMQ_query(L,R+1,0,0,(len(emin)+1)//2,emin)
        ny,yind = RMQ_query(xind+1,R+1,0,0,(len(omin)+1)//2,omin)
    else:
        nx,xind = RMQ_query(L,R+1,0,0,(len(omin)+1)//2,omin)
        ny,yind = RMQ_query(xind+1,R+1,0,0,(len(emin)+1)//2,emin)

    #print (L,R,xind,yind)

    heapq.heappush( q , (nx,ny,xind,yind,L,R) )
    return

N = int(input())
p = list(map(int, stdin.readline().split()))


omin = make_ST(N, (float("inf") , float("inf")) )
emin = make_ST(N, (float("inf") , float("inf")) )

for i in range(N):
    if i % 2 == 0:
        RMQ_update_point( (p[i],i) ,i,emin)
    else:
        RMQ_update_point( (p[i],i) ,i,omin)

q = []
want(0,N-1)
ans = []

while len(q) > 0:

    x,y,xi,yi,NL,NR = heapq.heappop(q)
    ans.append(x)
    ans.append(y)

    want(NL,xi-1)
    want(xi+1,yi-1)
    want(yi+1,NR)

print (*ans)



Measured memory_bytes: 176956
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<cmath>
#include<limits>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
using namespace std;
#define int ll
class Schedule {
private:
    vector<int> C;//size 26
    vector<vector<int>> S; //size Dx26
    vector<int> LastDay;//size 26
    vector<int> MasterType;// size D
public:
    void Input(int D) {
        C.resize(26);
        S.resize(D);
        LastDay.resize(26);
        MasterType.resize(D);
        for (int i = 0; i < D; i++) {
            S[i].resize(26);
        }

        for (int i = 0; i < C.size(); i++) {
            cin >> C[i];
        }
        for (int i = 0; i < S.size(); i++) {
            for (int j = 0; j < S[i].size(); j++) {
                cin >> S[i][j];
            }
        }
    }

    void Test_date() {
        for (int i = 0; i < MasterType.size(); i++) {
            int t; cin >> t; t--;
            MasterType[i] = t;
        }
    }
    ll Satisfaction(int day) {
        int dayscore = S[day-1][MasterType[day-1]];
        int decrease = 0;
        LastDay[MasterType[day-1]] = day;
        for (int i = 0; i < 26; i++) {
            decrease += C[i] * (day - LastDay[i]);
        }

        dayscore -= decrease;
        return dayscore;
    }
};

signed main() {
    int D; cin >> D;
    Schedule Scd; Scd.Input(D);
    Scd.Test_date();
    int ans = 0;
    for (int i = 1; i < D+1; i++) {
        ans += Scd.Satisfaction(i);
        cout << ans << endl;
    }
}

Measured memory_bytes: 3688
#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
using ll = long long;
const ll mod = 1e9+7;
const int mxn = 3003;
ll dp[mxn][mxn];

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

	int N; cin>>N;
	char s[mxn];
	cin>>s;

	if(s[0]=='<') dp[0][2] = 1ll;
	else dp[0][1] = 1ll;

	for(int idx = 1; idx<N-1; idx++)
		if(s[idx]=='<')
			for(int j=2; j<=idx+2; j++) {
				dp[idx][j] = dp[idx][j-1]+dp[idx-1][j-1];
				if(dp[idx][j]>=mod) dp[idx][j]-=mod;
			}
		else 
			for(int j=idx+1; j>=1; j--) {
				dp[idx][j] = dp[idx][j+1]+dp[idx-1][j];
				if(dp[idx][j]>=mod) dp[idx][j]-=mod;
		}

	ll ans = 0ll;
	for(int i=1; i<=N; i++) {
		ans+=dp[N-2][i];
		if(ans>=mod)ans-=mod;
	}

	cout << ans << '\n';


	return 0;
}

Measured memory_bytes: 68992
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define iton for(int i=0;i<n;i++)
#define itok for(int i=0;i<k;i++)
#define i1ton for(int i=1;i<n;i++)
#define jtom for(int j=0;j<m;j++)
#define ktom for(int k=0;k<m;k++)
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n,m;
    cin>>n;
    m=3;
    vector<vector<int>> holidays;
    iton
    {   
        vector<int> fill(m,0);
        for(int j=0;j<m;j++)
        cin>>fill[j];
        holidays.push_back(fill);
    }
    vector<vector<int>> dp;
    iton
    {   
        vector<int> fill(m,0);
        dp.push_back(fill);
    }
    for(int i=0;i<n;i++)
    {
        dp[0][i]=  holidays[0][i];
    }
    for(int i=1;i<n;i++)
    {   
        dp[i][0]= max(dp[i-1][1],dp[i-1][2]) + holidays[i][0];
        dp[i][1]= max(dp[i-1][0],dp[i-1][2]) + holidays[i][1];
        dp[i][2]= max(dp[i-1][1],dp[i-1][0]) + holidays[i][2];
    }
    int ans= INT_MIN;
    for(int j=0;j<m;j++)
    {
        ans = max(ans, dp[n-1][j]);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 12208
#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second

typedef long long lli;
typedef pair<int, int> pii;

const int maxn = 2e5 + 5;
const int lim = 1e9;

int n, k;
int a[maxn];

lli pre[maxn];

void read_input()
{
    cin >> n >> k;
    for(int i = 1; i <= n; ++i)
        cin >> a[i];
}

lli sum(int l, int r)
{
    return pre[r] - pre[l - 1];
}

void solve()
{
    pre[0] = 0;
    for(int i = 1; i <= n; ++i)
        pre[i] = pre[i - 1] + (lli)(log(a[i]) * lim);
    for(int i = k + 1; i <= n; ++i)
    {
        if(sum(i - k + 1, i) > sum(i - k, i - 1)) cout << "Yes\n";
        else cout << "No\n";
    }
}

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



Measured memory_bytes: 6292
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n;
  while(cin >>n,n){
    vector<int> num;
    for(int i=0,a; i<n; i++){
      cin >>a;
      num.push_back(a);
    }
    sort(num.begin(),num.end());
    int sum = 0;
    for(int i=1; i<n-1; i++) sum+=num[i];
    cout <<sum/(n-2)<<endl;
  }
  return 0;
}

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

int main(){
  int N;
  cin >> N;
  int A[2][N];
  int sum;
  int array = 0;
  for(int i=0;i<2;i++){
    for(int j=0;j<N;j++){
      cin >> A[i][j];
    }
  }

  for(int i=0;i<N;i++){
    int a = 0;
    sum = 0;
    for(int j=0;j<N;j++){
      sum += A[a][j];
      if(j == i){
        a += 1;
        sum += A[a][j];
      }
    }
    if(sum > array) array = sum;
  }
  cout <<  array << endl;
}

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

int n, m, ans, fa[N], siz[N];

inline int read(){
	int s = 0, w = 1;
	char ch = getchar();
	for (; ch < '0' || ch > '9'; ch = getchar()) w *= ch == '-' ? -1 : 1;
	for (; ch >= '0' && ch <= '9'; ch = getchar()) s = s * 10 + ch - '0';
	return s * w;
}

int findf(int x){
	return x == fa[x] ? x : fa[x] = findf(fa[x]);
}

int main(){
	n = read(), m = read();
	for (int i = 1; i <= n; ++i) fa[i] = i, siz[i] = 1;
	for (int i = 1; i <= m; ++i){
		int x = read(), y = read();
		x = findf(x), y = findf(y);
		if (x == y) continue;
		fa[x] = y, siz[y] += siz[x];
	}
	for (int i = 1; i <= n; ++i)
		if (fa[i] == i) ans = max(ans, siz[i]);
	printf("%d\n", ans);
	return 0;
}

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

Measured memory_bytes: 600
n, m = map(int, input().split())
edge = [[] for _ in range(n)]
used = [False for _ in range(n)]


def reach(cur, par, goal):
    if cur == goal:
        return True
    if used[cur]:
        return False
    used[cur] = True
    for e in edge[cur]:
        if e == par:
            continue
        if reach(e, cur, goal):
            used[cur] = False
            return True
    used[cur] = False
    return False


for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)

counter = 0
for i in range(n):
    for e in edge[i]:
        if not reach(i, e, e):
            counter += 1

print(counter // 2)


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

typedef long long ll;
typedef long double ld;

#define X first
#define Y second
#define all(x) x.begin(), x.end()

using namespace std;

inline int tmin(int a, int b, int c){
    b = min(a, b);
    c = min(b, c);
    return c;
}

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

    int n, cnt = 0;
    string s;
    cin >> n >> s;
    for (int i = 0; i < n - 2; i++){
        if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') cnt++;
    }
    cout << cnt;
    return 0;
}


Measured memory_bytes: 256
using System;
namespace aizu
{
    class No0015
    {
        public static void Main()
        {
            int count = int.Parse(Console.ReadLine());
            string[] input = new string[2];
            for(int i=0; i < count;++i){
                for(int j=0;j < 2;++j){
                    input[j] = Console.ReadLine();
                }
                Console.WriteLine(SumString(input[0], input[1]));
            }
        }
        public static string SumString(string str1, string str2)
        {
            string result = "";
            int carry = 0;
            int len1 = str1.Length;
            int len2 = str2.Length;
            while(len1 > 0 || len2 > 0){
                int val1 = (len1 > 0 ? int.Parse(str1.Substring(--len1, 1)) : 0);
                int val2 = (len2 > 0 ? int.Parse(str2.Substring(--len2, 1)) : 0);
                result = ((val1 + val2 + carry) % 10).ToString() + result;
                carry = ((val1 + val2 + carry) / 10);
            }
            if(carry > 0){
                result = carry.ToString() + result;
            }
            if(result.Length > 80){
                result = "overflow";
            }
            return result;
        }
    }
}

Measured memory_bytes: 5844
<?php 
  $n = fgets(STDIN);
  $array = explode(" ", trim(fgets(STDIN)));
  foreach($array as $i => &$val){
     $val -= $i + 1; 
  }
$cv = median($array);
  $sum = 0;
  foreach($array as $v){
    $sum += abs($v - $cv);
  }
  echo $sum;

function median(array $values){
	sort($values);
	if (count($values) % 2 == 0){
		return (($values[(count($values)/2)-1]+$values[((count($values)/2))])/2);
	}else{
		return ($values[floor(count($values)/2)]);
	}
}

Measured memory_bytes: 33268
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long N = sc.nextLong();
    long M = sc.nextLong();
    
    long ans = 0;
    if(N*2 <= M){
      ans += N;
      M -= N*2;
      ans += M/4;
    }else{
      ans += M/2;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
#include <stdio.h>

int main() {
  char S[4];
  scanf("%s", S);

  if(S[1] == 'B') {
    S[1] = 'R';
  }
  else if(S[1] == 'R') {
    S[1] = 'B';
  }
  printf("%s", S);
  return 0;
}

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

int main(){
  int n, t;
  int a[100010];
  int amax[100010];
  cin >> n >> t;

  for(int i = 0;i < n;i++){
    cin >> a[i];
  }

  amax[n-1] = a[n-1];
  for(int i = n-2;i >= 0;i--){
    amax[i] = max(amax[i+1],a[i]);
  }

  int now_max = 0;
  int ans = 0;
  for(int i = 0;i < n;i++){
    if(now_max < amax[i]-a[i]){
      now_max = amax[i]-a[i];
      ans = 1;
    }else if(now_max == amax[i]-a[i]){
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
package main

import (
	"fmt"
)

type dice struct {
	t, s, e, w, n, b int
}

func (d *dice) rotate(s string) {
	switch s {
	case "E":
		d.t, d.e, d.w, d.b = d.w, d.t, d.b, d.e
	case "W":
		d.t, d.e, d.w, d.b = d.e, d.b, d.t, d.w
	case "S":
		d.t, d.s, d.b, d.n = d.n, d.t, d.s, d.b
	case "N":
		d.t, d.s, d.b, d.n = d.s, d.b, d.n, d.t
	}
}

// サイコロ2
func main() {
	var t, s, e, w, n, b int
	fmt.Scan(&t, &s, &e, &w, &n, &b)
	d := dice{t: t, s: s, e: e, w: w, n: n, b: b}

	var q int
	fmt.Scan(&q)

	// dirs := []string{"E", "W", "S", "N"}
	for i := 0; i < q; i++ {
		var qt, qs int
		fmt.Scan(&qt, &qs)
		for _, v := range "EEENEEENEEESEEESEEENEEEN" {
			if d.t == qt && d.s == qs {
				fmt.Println(d.e)
				break
			}
			// rand.Seed(time.Now().UnixNano())
			// dir := dirs[rand.Intn(3)]
			dir := string(v)
			d.rotate(dir)
		}
	}
}



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

int main(){
  vector<int> A(5);
  for(int i=0;i<5;i++){
    cin>>A.at(i);
  }
  for(int i=0;i<5;i++){
    if(A.at(i)==0){
      cout<<i+1<<endl;
      break;
    }
  }
}

Measured memory_bytes: 3588
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n, k;
    cin >> n >> k;

    int a[n + 1];
    for (int i = 1; i <= n; i++) cin >> a[i];

    vector <vector<ll>> dp(n + 1, vector<ll>(k + 1, 0LL));
    // dp[i][j]: i人にちょうどj個の飴を配る方法が何通りあるか

    dp[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        dp[i][0] = 1LL;
        for (int j = 1; j <= k; j++) {
            dp[i][j] += dp[i][j - 1] + dp[i - 1][j];
            if (j > a[i]) dp[i][j] -= dp[i - 1][j - a[i] - 1];
            dp[i][j] = (dp[i][j] + MOD) % MOD;
        }
    }

    cout << dp[n][k] << "\n";
    return 0;
}

Measured memory_bytes: 80256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import heapq


def dijkstra_heap(s):
    # 始点sから各頂点への最短距離
    d = [float("inf")] * n
    used = [True] * n  # True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist, e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        # まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist, [e[0] + d[v], e[1]])
    return d


n = int(readline())
edge = [[] for i in range(n)]
for i in range(n - 1):
    u, v, w = map(int, readline().split())
    if i == 0:
        s = [u, v]
    edge[u - 1].append([w, v - 1])
    edge[v - 1].append([w, u - 1])
d = dijkstra_heap(0)
for k in d:
    if k % 2 == 0:
        print('0')
    else:
        print('1')


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

public class Main {
    private static long MOD =  1000000007;
    private static long[][] dp;
    private static long calculate(int x, int y, char[][] grid){
        if(x == grid.length - 1 && y == grid[0].length - 1) return 1;
        if(x >= grid.length || y >= grid[0].length) return 0;
        if(grid[x][y] == '#') return 0;
        if(dp[x][y] != -1) return dp[x][y];
        long a = calculate(x + 1, y, grid) % MOD;
        long b = calculate(x, y + 1, grid) % MOD;
        dp[x][y] = (a + b) % MOD;
        return dp[x][y];
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        // code goes here
        int[] in = nextIntArray(br, 2);
        int h = in[0];
        int w = in[1];
        char[][] grid = new char[h][w];
        dp = new long[h][w];
        for(int i = 0; i < h; i++){
            Arrays.fill(dp[i], -1);
        }
        for(int i = 0; i < h; i++){
            grid[i] = br.readLine().toCharArray();
        }
        sb.append(calculate(0, 0, grid));
        System.out.print(sb.toString());
    }

    private static int nextInt(BufferedReader br) throws IOException{
        return Integer.parseInt(br.readLine());
    }

    private static int[] nextIntArray(BufferedReader br, int n) throws IOException{
        StringTokenizer st = new StringTokenizer(br.readLine());
        int[] arr = new int[n];
        for(int i = 0; i < n; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        return arr;
    }

    static class Pair<A, B>{
        A first;
        B second;
        public Pair(A first, B second){
            this.first = first;
            this.second = second;
        }
    }
}


Measured memory_bytes: 49248
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=2000005,mod=1000000007;
ll fac[N],ni[N];
int x[6],y[6],ans;
inline ll q(int x,int y){
//cout<<x<<" "<<y<<endl<<" "<<fac[x+y]<<" "<<ni[x]<<" "<<ni[y]<<endl;
	return fac[x+y]*ni[x]%mod*ni[y]%mod;
}
inline int ksm(ll a,int b){
	int ans=1;
	for(;b;b>>=1){
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
	}
	return ans;
}
int cal(int sx,int sy,int tx,int ty){
	int ans=0;
	for(int i=x[2]+1;i<=x[3];i++)ans=(ans-q(i-sx,(y[2]-1)-sy)*q(tx-i,ty-y[2])%mod*(i+y[2]))%mod;
	for(int i=y[2]+1;i<=y[3];i++)ans=(ans-q((x[2]-1)-sx,i-sy)*q(tx-x[2],ty-i)%mod*(i+x[2]))%mod;
	for(int i=x[2];i<x[3];i++)ans=(ans+q(tx-i,ty-(y[3]+1))*q(i-sx,y[3]-sy)%mod*(i+y[3]+1))%mod;
	for(int i=y[2];i<y[3];i++)ans=(ans+q(tx-(x[3]+1),ty-i)*q(x[3]-sx,i-sy)%mod*(i+x[3]+1))%mod; 
	ans=(ans-q(x[2]-sx,y[2]-sy)*q(tx-x[2],ty-y[2])%mod*(x[2]+y[2]))%mod;
	ans=(ans+q(tx-x[3],ty-y[3])*q(x[3]-sx,y[3]-sy)%mod*(x[3]+y[3]+1))%mod;
	return ans;
}
signed main(){
	for(int i=0;i<6;i++)x[i]=read();
	for(int i=0;i<6;i++)y[i]=read();
	for(int i=fac[0]=1;i<N;i++)fac[i]=fac[i-1]*i%mod; ni[N-1]=ksm(fac[N-1],mod-2); for(int i=N-1;i;i--)ni[i-1]=ni[i]*i%mod;
	for(int j=0;j<4;j++){
		int sx,tx,sy,ty;
		if(j==0)sx=x[0]-1,sy=y[0]-1;
		else if(j==1)sx=x[1],sy=y[0]-1;
		else if(j==2)sx=x[0]-1,sy=y[1];
		else sx=x[1],sy=y[1];
		for(int k=0;k<4;k++){
			if(k==0)tx=x[5]+1,ty=y[5]+1;
			else if(k==1)tx=x[4],ty=y[5]+1;
			else if(k==2)tx=x[5]+1,ty=y[4];
			else tx=x[4],ty=y[4];
			int id=1;
			if(j==1||j==2)id*=-1;
			if(k==1||k==2)id*=-1;
			ans=(ans+id*cal(sx,sy,tx,ty))%mod;
			//cout<<sx<<" "<<sy<<" "<<tx<<" "<<ty<<" "<<cal(sx,sy,tx,ty)<<" "<<ans<<endl;
		}
	}
	cout<<(ans+mod)%mod<<endl;
}


Measured memory_bytes: 31488
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

int main(){
    int h, w, a, b; cin >> h >> w >> a >> b;
    REP(i, h) {
        REP(j, w){
            int x = (i<b)^(j<a);
            cout << x;
        }
        cout << endl;
    }
}

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

ll a(ll n) {
    if (n == 0) return 1;
    return 2 * a(n-1) + 3;
}

ll p(ll n) {
    if (n == 0) return 1;
    return 2 * p(n-1) + 1;
}

ll f(ll n, ll x) {
    if (n == 0 && x == 1) return 1;
    else if (n == 0 && x == 0) return 0;
    else if (x == 0) return 0;
    else if (x == 1) return 0;
    else if (2 <= x && x <= 1+a(n-1)) {
        return f(n-1, x-1);
    }
    else if (x == 2+a(n-1)) return p(n-1) + 1;
    else if (3+a(n-1) <= x && x <= 2+2*a(n-1)) {
        return p(n-1) + 1 + f(n-1, x-2-a(n-1));
    }
    else if (x == 3+2*a(n-1)) {
        return 2*p(n-1) + 1;
    }
    return 0;
}

int main() {
    ll n, x;
    cin >> n >> x;
    cout << f(n, x) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 20
int main()
{
  char c[MAX][MAX];
  int checked[MAX][MAX];
  int able[MAX][MAX];
  int x,y;
  int checkingx,checkingy;
  int i,j;
  int flag;
  int result;
  while(1)
    {
      for(i=0;i<MAX;i++)
	for(j=0;j<MAX;j++)
	  checked[i][j]=able[i][j]=0;
      scanf("%d%d",&x,&y);
      if((!x)&&(!y)) break;
      for(i=0;i<y;i++)
	for(j=0;j<x;j++)
	  {
	    scanf("%c",&c[j][i]);
	    if(c[j][i]=='@')
	      {
		checkingx=j;
		checkingy=i;
		checked[j][i]=1;
		able[j][i]=1;
	      }
	    if(c[j][i]=='\n')
	      {
		j--;
		continue;
	      }
	  }
      

      
      while(1)
	{
	  /*
	  for(i=0;i<y;i++)
	    {
	      for(j=0;j<x;j++)
		{
		  printf("%c",c[j][i]);
		}
	      printf("\n");
	    }
	  */
	  if((checkingx>0)&&(c[checkingx-1][checkingy]=='.'))
	    {
	      able[checkingx-1][checkingy]=1;
	      //printf("able: %d,%d\n",checkingx-1,checkingy);
	    }
	  if((checkingx<x-1)&&(c[checkingx+1][checkingy]=='.'))
	    {
	      able[checkingx+1][checkingy]=1;
	      //printf("able: %d,%d\n",checkingx+1,checkingy);
	    }
	  if((checkingy>0)&&(c[checkingx][checkingy-1]=='.'))
	    {
	      able[checkingx][checkingy-1]=1;
	      //printf("able: %d,%d\n",checkingx,checkingy-1);
	    }
	  if((checkingy<y-1)&&(c[checkingx][checkingy+1]=='.'))
	    {
	      able[checkingx][checkingy+1]=1;
	      //printf("able: %d,%d\n",checkingx,checkingy+1);
	    }
	  flag=0;
	  for(i=0;i<y;i++)
	    {
	      for(j=0;j<x;j++)
		{
		  if((checked[j][i]==0)&&(able[j][i]==1))
		    {
		      checkingx=j;
		      checkingy=i;
		      checked[j][i]=1;
		      flag=1;
		      //printf("NEXT: %d,%d\n",j,i);
		      break;
		    }
		}
	      if(flag) break;
	    }
	  if(!flag) break;
	}
      result=0;
      for(i=0;i<y;i++)
	for(j=0;j<x;j++)
	  if(checked[j][i]==1) result++;
      printf("%d\n",result);
    }
  return 0;
}

Measured memory_bytes: 1744
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
int main(){
    int k;
    cin >> k;
    string s;
    cin >> s;
    if(s.size() <= k){
        cout << s;
    }else{
        cout << s.substr(0, k) << "...";
    }
    cout << endl;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

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

    int n,z,w;
    cin >> n >> z >> w;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
    }
    int ans = 0;
    int b,c,d,e,f;

    if (n==1){
        ans=abs(a[0]-w);
        cout << ans;
        return 0;
    }
    if (a[n-2]-a[n-1]!=0){
        c=abs(a[n-2]-a[n-1]);
    }
    else{
        c=0;
    }
    if(w-a[n-1]!=0){
        b=abs(w-a[n-1]);
    }
    else{
        b=0;
    }

    ans=max(c,b);

    cout << ans;



    return 0;
}

Measured memory_bytes: 256
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  Name:- OMHARI 
  Institution:- UNIVERSIT OF CALCUTTA(INFORMATION TECHNOLOGY)
  Email:- omharicu@gmail.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#include<bits/stdc++.h>
using namespace std; 

#define F               first
#define S               second
#define ull             unsigned long long
#define ll              long long
#define ul              unsigned long
#define db              double
#define ST              string
#define pb              push_back
#define mp              make_pair
#define el              "\n"
#define vll             vector <ll>
#define vl              vector <long int>
#define vi              vector <int>
#define all(v)          (v.begin(), v.end()) 
#define rall(v)         (v.rbegin(), v.rend()) 
#define is_sort(v)      is_sorted all(v)
#define max_of(v)       *max_element all(v)
#define min_of(v)       *min_element all(v)
#define itos(s)         to_string(s)
#define cntone(x)       __builtin_popcountll(x)
#define cntzro(x)       __builtin_clz(x)
#define For(i, a, b)    for(int i=a; i<b; i++)
#define Forr(i, a, b)    for(int i=a; i>=b; i--)
const ll mod = 1e9+7;

void solve()
{
    ll n, ans=0;
    cin>>n;
    vll v(n+1), sum(n+1);
    For(i, 1, n+1) cin>>v[i], sum[i]=v[i];

    For(i, 1, n+1)
    sum[i]=(sum[i-1]+sum[i]);

    For(i, 1, n)
    {
        ll tt = ((v[i]%mod)*((sum[n]-sum[i])%mod))%mod;
        ans=ans+tt;
    }
    //ans=(ans%mod+((v[i]%mod)*((sum[n]-sum[i])%mod))%mod)%mod;

    cout<<(ll)ans%mod;
}

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

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    /***************-Code starts from here-***************/
    // int t;
    // cin>>t;
    // while(t--)
    solve();
    return 0; 
} 

Measured memory_bytes: 6348
import java.util.*;
import static java.lang.Math.*;
public class Main {
	final Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main().init();
	}
	char[] c;
	int p=0;
	void init(){
		int N=sc.nextInt();
		while(--N>=0){
			c=(sc.next()+"#").toCharArray();
			p=0;
			int ans=dfs();
			System.out.println(ans);
		}
	}
	
	int dfs(){
//		System.out.println(p+" "+c[p]);
		if(c[p]=='['){
			int ret=0;
			++p;
			if(c[p]=='['){
				ArrayList<Integer> tmp=new ArrayList<Integer>();
				while(c[p]=='['){
					tmp.add(dfs());
//					++p;
//					System.out.println(tmp+" "+p+" "+c[p]);
				}
				Collections.sort(tmp);
				for(int i=0; i<(tmp.size()/2)+1; ++i)	ret+=tmp.get(i);
				++p;
				return ret;
			}else if(Character.isDigit(c[p])){
				ArrayList<Integer> tmp = new ArrayList<Integer>();
				while(Character.isDigit(c[p])){
					int n=c[p]-'0';
					++p;
					while(Character.isDigit(c[p])){
						n=n*10+(c[p]-'0');
						++p;
					}
					tmp.add(n);
//					System.out.println("NUMBER "+n);
					++p;
					if(c[p]=='[')	++p;
				}
				Collections.sort(tmp);
//				System.out.println(tmp);
				for(int i=0; i<(tmp.size()/2)+1; ++i)	ret+=tmp.get(i)/2+1;
				return ret;
			}
		}
		return 0;
	}

}

Measured memory_bytes: 47200