akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=2e5+10;
const int mod=1e9+7;
int l=0;
main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    if(s[0]=='W'||s[2*n-1]=='W'){
        puts("0");
        return 0;
    }
    l++;
    int ans=1;
    int sta=1;
    for(int i=1;s[i];++i){
        if(s[i]==s[i-1])
            sta^=1;
        if(sta)l++;
        else{
            if(l==0){
                puts("0");
                return 0;
            }
            ans=ans*l%mod;
            l--;
        }
    }
    if(l!=0){
        puts("0");
        return 0;
    }
    for(int i=1;i<=n;++i)ans=ans*i%mod;
    cout<<ans<<endl;
}


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

int main()
{
    int n;
    cin>>n;
    int *dist=new int[n];
    for(int i=0;i<n;i++)
    {
        cin>>dist[i];
    }
    vector<int>dp(n,INT_MAX);
    dp[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j:{i+1,i+2})
        {
            if(j<n)
            {
                dp[j]=min(dp[j],dp[i]+abs(dist[i]-dist[j]));
            }
        }
    }
    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 3988
def test():
    n = int(input())
    a = list(map(int,input().split()))
    flag = 0
    alice = 0; bob = 0
    for i in range(n):
        if flag == 0:
            alice += max(a)
            a.remove(max(a))
            flag = 1
        elif flag == 1:
            bob += max(a)
            a.remove(max(a))
            flag = 0
    print(alice-bob)


if __name__ == "__main__":
    test()


Measured memory_bytes: 3064
from collections import deque
n,m=map(int,input().split())
data=[[] for i in range(n+1)]
for i in range(m):
  a,b=map(int,input().split())
  data[a].append(b)
  data[b].append(a)
flag=[0]*(n+1)
cnt=-1
for i in range(1,n+1):
  if flag[i]==0:
    flag[i]=1
    que=deque([i])
    while que:
      h=que.popleft()
      for u in data[h]:
        if flag[u]==0:
          flag[u]=1
          que.append(u)
    cnt+=1
print(cnt)

Measured memory_bytes: 81884
n,k = map(int, input().split())
a = list(map(int, input().split()))

b = len(format(10**12,'b'))

a = [format(x,'0{}b'.format(b)) for x in a]

k = format(k,'0{}b'.format(b))


ans = ''
flag = False
for i in range(b):
    one = 0
    zero = 0
    for j in range(n):
        if a[j][i]=='1':
            one += 1
        else:
            zero += 1
    if one < zero:
        if flag:
            ans += '1'
            continue
        else:
            if k[i]=='1':
                ans += '1'
            else:
                ans += '0'
    else:
        ans += '0'
        if k[i]=='1':
            flag = True

ans = int(ans,2)
ans2 = 0
for i in range(n):
    ans2 += ans^int(a[i],2)

print(ans2)


Measured memory_bytes: 92432
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s1, s2;
	int count=0;
	cin >> s1 >> s2;
for(int i=0; i<s1.size(); i++)
{
	if(s1[i]!=s2[i])
	{
		count++;
	}
}
cout << count << endl;
return 0;
}

Measured memory_bytes: 3860
#include <stdio.h>

int main(void)
{
    int H;
    int W;

    while ( 1 ) {
        scanf("%d %d", &H, &W);
        if ( (H == 0) && (W == 0) ) {
            break;
        }
        for ( int i = 0; i < H; i++ ) {
            for ( int j = 0; j < W; j++ ) {
              if ( (i + j) % 2 == 0 ) {
                  printf("#");
              } else {
                  printf(".");
              }
            }
            printf("\n");
        }
        printf("\n");
    }
    
    return 0;
}


Measured memory_bytes: 2060
h,w,a,b = map(int, input().split())

mod = 10**9 + 7
n = 10**5 * 2 + 1

fact = [1]*(n+1)
rfact = [1]*(n+1)
r = 1
for i in range(1, n+1):
  fact[i] = r = r * i % mod
rfact[n] = r = pow(fact[n], mod-2, mod)
for i in range(n, 0, -1):
  rfact[i-1] = r = r * i % mod

# nPk (mod MOD) を求める
def perm(n, k):
  return fact[n] * rfact[n-k] % mod

# nCk (mod MOD) を求める
def comb(n, k):
  return fact[n] * rfact[k] * rfact[n-k] % mod 
ans = 0
for i in range(b,w):
  ans = (ans + comb(h-a-1+i,i) * comb(w-i+a-2,a-1)) % mod
print(ans)

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

int main() {
  int n, m;
  cin >> n >> m;

  vector<vector<int>> matrix(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> matrix.at(i).at(j);
    }
  }

  vector<int> column_vector(m);
  for (int i = 0; i < m; i++) {
    cin >> column_vector.at(i);
  }

  for (int i = 0; i < n; i++) {
    int ans = 0;
    for (int j = 0; j < m; j++) {
      ans += matrix.at(i).at(j) * column_vector.at(j);
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3168
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include<unordered_map>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
void vdeb(std::vector<T> &da) {
    for (int i = 0;i < da.size();i++) {
        if (i == da.size() - 1) std::cout << da[i];
        else std::cout << da[i] << ' ';
    }
    std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
    for (int i = 0;i < da.size();i++) vdeb(da[i]);
    std::cout << std::endl;
}

using namespace std;
int id = 0;

void dfs(vector<vector<int>> &da, vector<int> &c, vector<int> &used, int now){
    if(used[now] >= 0) return;
    used[now] = c[id];
    ++id;
    rip(i, da[now].size(), 0){
        dfs(da, c, used, da[now][i]);
    }
    return;
}

int main(){
    int n; cin >> n;
    vector<vector<int>> da(n, vector<int>(0));
    rip(i,n-1,0){
        int a,b; cin >> a >> b;
        a--;b--;
        da[a].push_back(b);
        da[b].push_back(a);
    }
    vector<int> c(n);
    rip(i,n,0) cin >> c[i];
    sort(all(c));
    reverse(all(c));
    vector<int> ans(n, -1);
    dfs(da, c, ans, 0);
    ll m = 0;
    rip(i,n,1) m += (ll)ans[i];
    cout << m << endl;
    vdeb(ans);
}

Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
using namespace std;
#define LATTE 10000

int main(){
	int x;
	cin>>x;
	printf("%d\n",x*x*x);
    return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  priority_queue<int64_t> que;
  for (int i = 0; i < N; i++) {
    int64_t a;
    cin >> a;
    que.push(a);
  }
  for (int i = 0; i < M; i++) {
    int64_t a = que.top();
    que.pop();
    que.push(a / 2);
  }
  int64_t res = 0;
  while (!que.empty()) {
    res += que.top();
    que.pop();
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <stdio.h>
#include <string.h>
#define ll long long
using namespace std;

const int MAXN = 1e5+10;
ll a[MAXN], b[MAXN];
ll n, x, y;

bool is_ok(ll mid){
    memcpy(b, a, sizeof(a));
    for(int i=0; i<n; i++){
        b[i] -= mid * y;
    }
    // cout << b[0] << endl;
    for(int i=0; i<n; i++){
        if(b[i] > 0){
            ll cnt = x - y;
            ll cc = b[i]/cnt;
            mid -= cc;
            if(b[i] % cnt) mid -= 1;
            if(mid < 0) return false;
        }
    }
    return true;
}

int main(void){
    scanf("%lld%lld%lld", &n, &x, &y);
    for(int i=0; i<n; i++){
        scanf("%lld", &a[i]);
    }
    ll l=1, r=1e9;
    while(l < r){
        ll mid = (l + r) >> 1;
        if(is_ok(mid) && !is_ok(mid-1)){
            printf("%lld\n", mid);
            return 0;
        }else if(is_ok(mid)){
            r = mid - 1;
        }else{
            l = mid + 1;
        }
    }
    cout << l << endl;
    return 0;
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)
typedef long long lint;

int N, A[100010], B[100010];

int main() {
	cin >> N;
	
	map< int, int > pos;
	for_(i,0,N) {
		cin >> A[i];
		pos[A[i]] = i;
	}
	sort(A, A + N);
	
	int ans = 0;
	for (int i = 0; i < N; i += 2) ans += (pos[A[i]] % 2 == 1);
	cout << ans << endl;
}

Measured memory_bytes: 5376
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int hako[]=new int[n];
		for(int i=0;i<n;i++) {
			hako[i]=sc.nextInt();
		}
		int list=hako[0];
		int ans;
		/////////////////////////////////////
		
		for(int i=k;i<n;i++) {
			ans=hako[i];
			if(ans>list) {
				System.out.println("Yes");
			}
			else {
				System.out.println("No");
			}
			list=hako[i-k+1];//****
		}
		
	}

}


Measured memory_bytes: 60372
#include <iostream>

#include <string>

#include <algorithm>



using namespace std;



int main() {

	int x=0;

	string str1, str2;

	while(cin >> str1){

		str2 = str1;

		reverse(str2.begin(),str2.end());

		if(str1 == str2){

			++x;

		}

	}

	cout << x << endl;

	return 0;

}	

	






Measured memory_bytes: 3056
a,b,c,d = list(input())
n = 2 ** 3
bit_pattern = []
for i in range(n):
    bit_flg = ["+"] * 3
    for j in range(n):
        if(i >> j & 1) == 1:
            bit_flg[j] = "-"
    bit_pattern.append(bit_flg)
for k in range(len(bit_pattern)):
    if eval(a + bit_pattern[k][0] + b + bit_pattern[k][1] + c + bit_pattern[k][2] + d) == 7:
        print(a+bit_pattern[k][0]+b+bit_pattern[k][1]+c+bit_pattern[k][2]+d+"=7")
        break


Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <cmath>

#define mst(a,b)memset(a, b, sizeof(a))
#define repi(a,b)for(int i = a; i < b; i++)
#define repj(a,b)for(int j = a; j < b; j++)
#define pii pair<int,int>

#ifdef LOCAL
#define fre()freopen("in.txt","r",stdin)
#endif
#ifndef LOCAL
#define fre()
#endif

//static int x = []() {
//	std::ios::sync_with_stdio(false);
//	std::cin.tie(NULL);
//	return 0;
//}();

#define FASTIO
#ifdef FASTIO
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
//#define scanf abcabc
//#define printf abcabc
#endif
//#ifndef FASTIO
//#define cin abcabc
//#define cout abcabc
//#endif

typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;

using namespace std;


char s[2010][2010];
int rifa[2010][2010][5];
int main() {
	fre(); IOS;
	int n, m; cin >> n >> m;
	repi(1, n + 1) {
		repj(1, m + 1) {
			cin >> s[i][j];
			if (s[i][j] == '.') {
				rifa[i][j][0] = rifa[i - 1][j][0] + 1;
				rifa[i][j][2] = rifa[i][j - 1][2] + 1;
			}
		}
	}
	int ans = 0;
	for (int i = n; i > 0; i--) {
		for (int j = m; j > 0; j--) {
			if (s[i][j] == '.') {
				rifa[i][j][1] = rifa[i + 1][j][1] + 1;
				rifa[i][j][3] = rifa[i][j + 1][3] + 1;
			}
			ans = max(ans, rifa[i][j][0] + rifa[i][j][1] + rifa[i][j][2] + rifa[i][j][3] - 3);
		}
	}
	cout << ans << endl;
	return 0;
}


/*int f[200010], ff[200010];
vector<int>v, vv;
int main() {
	fre(); IOS;
	int T; cin >> T;
	while (T--) {
		v.clear();
		int n, m; cin >> n >> m;
		repi(1, n + 1)f[i] = ff[i] = 0;
		repi(0, m) {
			int s, t; cin >> s >> t;
			if (s > t)swap(s, t);
			if (!f[s] && !f[t] && (!ff[s] || !ff[t])) {
				v.push_back(s);
				vv.push_back(t);
			}
			ff[s] = ff[t] = 1;
		}
		cout << min(v.size(), vv.size()) << "\n";
		if (v.size() < vv.size())
			repi(0, v.size())cout << v[i] << " ";
		else repi(0, vv.size())cout << vv[i] << " ";
		cout << "\n";
	}
	return 0;
}*/

Measured memory_bytes: 83200
#include <iostream>
#include <vector>
using namespace std;
static const int M = 2011;

int powmod(int a, int n)
{
  if (n == 0) {
    return 1;
  } else if (n & 1) {
    return (a * powmod(a, n-1))%M;
  } else {
    const int e = powmod(a, n>>1);
    return (e * e)%M;
  }
}

struct parser
{
  int i;
  vector<string> src;
  parser() : i(0), src() {}

  int width() const { return src[0].size(); }
  int height() const { return src.size(); }
  int find_base(int top, int bot)
  {
    for (; i < width(); i++) {
      for (int k = top; k < bot; k++) {
        if (src[k][i] != '.') {
          return k;
        }
      }
    }
    throw "find_base";
  }

  int parse(int top, int bot)
  {
    return expr(find_base(top, bot), top, bot);
  }

  int expr(int base, int top, int bot)
  {
    const string& line = src[base];
    int r = term(base, top, bot);
    while (i+2 < width() && line[i] == '.' && (line[i+1] == '+' || line[i+1] == '-') && line[i+2] == '.') {
      const char op = line[i+1];
      i += 3;
      const int t = term(base, top, bot);
      if (op == '+') {
        r = (r + t)%M;
      } else {
        r = ((r - t)%M + M)%M;
      }
    }
    return r;
  }

  int term(int base, int top, int bot)
  {
    const string& line = src[base];
    int r = factor(base, top, bot);
    while (i+2 < width() && line[i] == '.' && line[i+1] == '*' && line[i+2] == '.') {
      i += 3;
      const int t = factor(base, top, bot);
      r = (r * t)%M;
    }
    return r;
  }

  int factor(int base, int top, int bot)
  {
    const string& line = src[base];
    if (line[i] == '-') {
      if (line[i+1] == '.') {
        i += 2;
        const int r = factor(base, top, bot);
        return (-r + M)%M;
      } else {
        const int save = i;
        const int n = parse(top, base);
        i = save;
        const int d = parse(base+1, bot);
        i = save;
        while (i < width() && line[i] == '-') {
          ++i;
        }
        return (n * powmod(d, M-2))%M;
      }
    } else {
      return powexpr(base, top, bot);
    }
  }

  int powexpr(int base, int top, int bot)
  {
    int r = primary(base, top, bot);
    if (base-1 >= top && i < width() && isdigit(src[base-1][i])) {
      const int n = src[base-1][i]-'0';
      i++;
      return powmod(r, n);
    } else {
      return r;
    }
  }

  int primary(int base, int top, int bot)
  {
    const string& line = src[base];
    if (line[i] == '(' && line[i+1] == '.') {
      i += 2;
      const int r = expr(base, top, bot);
      i += 2;
      return r;
    } else {
      const int n = line[i]-'0';
      i++;
      return n;
    }
  }
};

int main()
{
  int N;
  while (cin >> N && N != 0) {
    parser p;
    p.src.resize(N);
    for (int i = 0; i < N; i++) {
      cin >> p.src[i];
    }
    cout << p.parse(0, N) << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<int> vect(3);
  for(int i=0;i<3;i++){
    cin>>vect.at(i);
  }
	sort(vect.begin(),vect.end());
  cout<<vect[0]+vect[1]+10*vect[2]<<endl;
}


Measured memory_bytes: 256
#ifndef ___CLASS_MODINT
#define ___CLASS_MODINT

#include <cstdint>

template<std::uint32_t mod>
class modint {
private:
	std::uint32_t n;
public:
	modint() : n(0) {};
	modint(std::uint64_t n_) : n(n_ % mod) {};
	bool operator==(const modint& m) const { return n == m.n; }
	bool operator!=(const modint& m) const { return n != m.n; }
	std::uint32_t get() const { return n; }
	modint& operator+=(const modint& m) { n += m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator-=(const modint& m) { n += mod - m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator*=(const modint& m) { n = std::uint64_t(n) * m.n % mod; return *this; }
	modint operator+(const modint& m) const { return modint(*this) += m; }
	modint operator-(const modint& m) const { return modint(*this) -= m; }
	modint operator*(const modint& m) const { return modint(*this) *= m; }
	modint binpow(std::uint64_t b) const {
		modint ans = 1, m = modint(*this);
		while (b) {
			if (b & 1) ans *= m;
			m *= m;
			b >>= 1;
		}
		return ans;
	}
	modint inv() { return (*this).binpow(mod - 2); }
};

#endif // ___CLASS_MODINT

#include <vector>
#include <iostream>
using namespace std;
using modulo = modint<1000000007>;
int main() {
	int N, M;
	cin >> N >> M;
	vector<int> A(N), B(M);
	for (int i = 0; i < N; ++i) cin >> A[i], --A[i];
	for (int i = 0; i < M; ++i) cin >> B[i], --B[i];
	vector<int> bit(N * M);
	for (int i = 0; i < N; ++i) bit[A[i]] += 1;
	for (int i = 0; i < M; ++i) bit[B[i]] += 2;
	modulo ans = 1;
	int row = 0, col = 0;
	for (int i = N * M - 1; i >= 0; --i) {
		if (bit[i] == 3) {
			++row;
			++col;
		}
		else if (bit[i] == 2) {
			++col;
			ans *= row;
		}
		else if (bit[i] == 1) {
			++row;
			ans *= col;
		}
		else {
			int rem = row * col - (N * M - i - 1);
			ans *= rem;
		}
		if (ans.get() == 0) break;
	}
	cout << ans.get() << endl;
	return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<ll, ll> pl;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n), x(n+1, 0);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) x[i+1] += x[i]+a[i];
  ll res = 1e18;
  int l= 1, r = 3;
  for (int i = 2; i < n-1; i++) {
    while (abs((x[i]-x[l])-x[l]) >= abs((x[i]-x[l+1])-x[l+1])) {
      if (l+1 >= i) break;
      l++;
    }
    if (r < i) r = i;
    while (abs(x[n]-x[r]*2+x[i]) >= abs(x[n]-x[r+1]*2+x[i])) {
      if (r+1 >= n) break;
      r++;
    }
    ll P = x[l];
    ll Q = x[i]-x[l];
    ll R = x[r]-x[i];
    ll S = x[n]-x[r];
    ll ma = max(P, max(Q, max(R, S)));
    ll mi = min(P, min(Q, min(R, S)));
    res = min(res, abs(ma-mi));
  }
  dump(res);
  return 0;
}


Measured memory_bytes: 3328
#include <iostream>

using namespace std;

int main() {

    int n, k;

    cin >> n >> k;

    int h[n], i;

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

    int cnt=0;

    for (i = 0; i < n; i++) {
        if (h[i] >= k) {
            cnt++;
        };
    }

    cout << cnt;

    return 0;
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b + c || b == c + a || c == a + b)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
from bisect import bisect_left, bisect_right
n = int(input())
s = input()

color = 'RGB'
c_list = [[i for i in range(n) if s[i] == color[j]] for j in range(3)]
# print(*c_list, sep='\n')

ans1 = len(c_list[0]) * len(c_list[1]) * len(c_list[2])
ans2 = 0
for i in range(n):
    for j in range(1, n):
        if i + 2 * j >= n:
            continue
        if s[i] != s[i + j] and s[i + j] != s[i + 2 * j] and s[i +
                                                               2 * j] != s[i]:
            ans2 += 1

# print(ans1, ans2)
ans = ans1 - ans2
print(ans)


Measured memory_bytes: 73724
//  Created by conan1024hao on 2019/11/24.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define PI acos(-1.0)
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //------------------------------
    int n;
    cin>>n;
    vector<vector<int>>a(n);
    vector<pair<int,int>>vp;
    
    for(int i=0;i<n-1;i++){
        int c,d;
        cin>>c>>d;
        c--;d--;
        a[c].push_back(d);
        a[d].push_back(c);
        vp.emplace_back(c,d);
    }
    int cnt=0;
    map<pair<int,int>,int> I;
    vector<int> color(n,0);
    vector<int> used(n,0);
    queue<int> que;
    used[0]=1;
    que.emplace(0);
    for(int i=0;i<n;i++){
        chmax(cnt,a[i].size());
    }
    while(!que.empty()){
        int v=que.front();que.pop();
        int now=1;
        for(auto it=a[v].begin();it!=a[v].end();it++){
            int i=*it;
            if(used[i])
                continue;
            if(now==color[v])
                now++;
            color[i]=I[make_pair(i,v)]=I[make_pair(v,i)]=now++;
            used[i]=1;
            que.emplace(i);
                
        }
    }
    map<int,int>MAP;
    cout<<cnt<<endl;
    for(auto p:vp)cout<<I[p]<<endl;
    //cout<<dp[5][0]<<" "<<dp[4][5]<<endl;
    //cout<<dp[5][0]<<" "<<dp[5][1]<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


Measured memory_bytes: 20088
#include <bits/stdc++.h>
using namespace std;
int n,y,fl=0;
int main(){
	cin>>n>>y;
	y/=1000;
	if(y>n*10||y<n){
		cout<<-1<<" "<<-1<<" "<<-1<<endl;
		return 0;
	}
	for(int i=y%5;i<=n;i+=5){
		int a=y;
		a-=i;
		for(int j=a%2;j<=n-i;j+=2){
			if((a-j*5)/10==n-i-j){
				fl=1;
				cout<<(a-j*5)/10<<" "<<j<<" "<<i<<endl;
			}
			if(fl==1){
				break;
			}
		}
		if(fl==1){
			break;
		}
	}
	if(fl!=1){
		cout<<-1<<" "<<-1<<" "<<-1<<endl;
	}
	return 0;
}

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

#define ALL(a) (a).begin(), (a).end()
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define pp(v) cerr << #v "=" << (v) << endl;
#define ppa(v) cerr << "- " << #v << endl; rep(i,v.size()) cerr << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)
#define UNIQUE(v) v.erase( unique(ALL(v)), v.end() );
#define INF 0x3f3f3f3f
#define LLINF 1000111000111000111LL
#define MOD 1000000007
#define TIME system("date +%M:%S.%N")
using Graph = vector<vector<int>>;
using ll = long long;
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

int main() {
  int n;cin>>n;
  vector<ll> a(n);rep(i,n)cin>>a[i];
  rep(i,n)a[i] -= (i+1);
  sort(ALL(a));
  ll b = a[n/2];
  ll ans = 0;
  rep(i,n) ans += abs(a[i]-b);
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)

string s[401];
ll H , W;
bool did[401][401];
ll a,b;
int dfs(int x,int y){
	did[x][y] = true;
	if(s[x][y]=='#')b++;
	if(s[x][y]=='.')a++;
	if(x>0)if(s[x][y]!=s[x-1][y]&&(not did[x-1][y])){
		dfs(x-1,y);
	}
	if(x<H-1)if(s[x][y]!=s[x+1][y]&&(not did[x+1][y])){
		dfs(x+1,y);
	}
	if(y>0)if(s[x][y]!=s[x][y-1]&&(not did[x][y-1])){
		dfs(x,y-1);
	}
	if(y<W-1)if(s[x][y]!=s[x][y+1]&&(not did[x][y+1])){
		dfs(x,y+1);
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> H >> W;
	FOR(i,0,H){
		cin >> s[i];
	}
	ll ans = 0;
	FOR(i,0,H){
		FOR(j,0,W){
			a=b=0;
			if(not did[i][j]){
				dfs(i,j);
				ans += a*b;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 18048
use std::io;


fn main() {
    let i = read::<String>();
    let a = i[0].parse::<isize>().unwrap();
    let b = i[2].parse::<isize>().unwrap();

    match &*i[1] {
        "+" => { println!("{}", a + b); },
        "-" => { println!("{}", a - b); },
        _   => unreachable!(),
    }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;

const int MOD = 1000000007;

ll modpow(ll a, ll n, ll mod)
{
    ll res = 1;
    while (n)
    {
        if (n & 1)
        {
            res = (res * a) % mod;
        }
        a = (a * a) % mod;
        n /= 2;
    }
    return res;
}

ll modinv(ll a, ll mod)
{
    return modpow(a, mod - 2, mod);
}

ll comb(ll n, ll k, ll mod)
{
    ll a = 1;
    ll b = 1;
    rep(i, k) a = a * (n - i) % mod;
    rep(i, k) b = b * (i+1) % mod;
    return a * modinv(b, mod) % mod;
}
int main()
{
    ll n, a, b;
    cin >> n >> a >> b;

    ll ans = modpow(2, n, MOD);
    ll sub = (comb(n, a, MOD) + comb(n, b, MOD)) % MOD;
    ans = (ans - sub) % MOD;
    if (ans < 0)
    {
        ans += MOD;
    }
    cout << ans - 1 << endl;
  //  system("pause");
    return 0;
}

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

int main(void)
{
	int bell[3];
	scanf("%d%d%d", &bell[0], &bell[1], &bell[2]);
	sort(bell, bell + 3);
	printf("%d", bell[0] + bell[1]);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#define ll long long
using namespace std;

const int N=200005;
const ll inf=1000000000000000ll;

struct ST{
	int l,r;
	ll mn,mn1,mn2,tag;
}t[N<<2];
int n,Q,A,B;
ll w1,w2;
int x[N];

void update(int k){
	t[k].mn=min(t[k<<1].mn,t[k<<1|1].mn);
	t[k].mn1=min(t[k<<1].mn1,t[k<<1|1].mn1);
	t[k].mn2=min(t[k<<1].mn2,t[k<<1|1].mn2);
}

void build(int k,int l,int r){
	t[k].l=l; t[k].r=r;
	t[k].mn=t[k].mn1=t[k].mn2=inf;
	if (l==r) return;
	int mid=(l+r)>>1;
	build(k<<1,l,mid);
	build(k<<1|1,mid+1,r);
}

void add(int k,ll w){
	t[k].mn+=w;
	t[k].mn1+=w;
	t[k].mn2+=w;
	t[k].tag+=w;
}

void pushdown(int k){
	if (t[k].tag){
		add(k<<1,t[k].tag);
		add(k<<1|1,t[k].tag);
		t[k].tag=0;
	}
}

void modify(int k,int p,ll w){
	if (t[k].l==t[k].r){
		t[k].mn=min(t[k].mn,w);
		t[k].mn1=min(t[k].mn1,w-t[k].l);
		t[k].mn2=min(t[k].mn2,w+t[k].l);
		return;
	}
	pushdown(k);
	int mid=(t[k].l+t[k].r)>>1;
	if (p<=mid) modify(k<<1,p,w);
	else modify(k<<1|1,p,w);
	update(k);
}

void modifya(int k,int L,int R,ll w){
	if (L<=t[k].l&&t[k].r<=R){
		add(k,w);
		return;
	}
	pushdown(k);
	int mid=(t[k].l+t[k].r)>>1;
	if (L<=mid) modifya(k<<1,L,R,w);
	if (R>mid) modifya(k<<1|1,L,R,w);
	update(k);
}

ll query1(int k,int L,int R){
	if (L<=t[k].l&&t[k].r<=R) return t[k].mn1;
	pushdown(k);
	int mid=(t[k].l+t[k].r)>>1;
	if (R<=mid) return query1(k<<1,L,R);
	else if (L>mid) return query1(k<<1|1,L,R);
	else return min(query1(k<<1,L,R),query1(k<<1|1,L,R));
}

ll query2(int k,int L,int R){
	if (L<=t[k].l&&t[k].r<=R) return t[k].mn2;
	pushdown(k);
	int mid=(t[k].l+t[k].r)>>1;
	if (R<=mid) return query2(k<<1,L,R);
	else if (L>mid) return query2(k<<1|1,L,R);
	else return min(query2(k<<1,L,R),query2(k<<1|1,L,R));
}

ll query(int k,int p){
	if (t[k].l==t[k].r) return t[k].mn;
	pushdown(k);
	int mid=(t[k].l+t[k].r)>>1;
	if (p<=mid) return query(k<<1,p);
	else return query(k<<1|1,p);
}

int main(){
	int i,j;
	scanf("%d%d%d%d",&n,&Q,&A,&B);
	for (i=1;i<=Q;i++) scanf("%d",&x[i]);
	build(1,1,n);
	modify(1,A,abs(x[1]-B));
	modify(1,B,abs(x[1]-A));
	for (i=2;i<=Q;i++){
		w1=1ll*x[i]+query1(1,1,x[i]);
		w2=query2(1,x[i],n)-1ll*x[i];
		modifya(1,1,n,abs(x[i]-x[i-1]));
		modify(1,x[i-1],min(w1,w2));
	}
	printf("%lld\n",t[1].mn);
	return 0;
}

Measured memory_bytes: 22912
/**
 * File    : C.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-8-5 21:17:59
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int main()
{
  int D, G;
  cin >> D >> G;
  G /= 100;
  vector<int> p;
  vector<int> c;
  for (auto i = 0; i < D; i++)
  {
    int x, y;
    cin >> x >> y;
    p.push_back(x);
    c.push_back(y / 100);
  }
  int ans = 1000000000;
  for (auto i = 0; i < (1 << D); i++)
  {
    int cnt = 0;
    int score = 0;
    for (auto j = 0; j < D; j++)
    {
      if ((i >> j) & 1)
      {
        cnt += p[j];
        score += p[j] * (j + 1) + c[j];
      }
    }
    if (score >= G)
    {
      ans = min(ans, cnt);
      continue;
    }
    for (auto j = D - 1; j >= 0; j--)
    {
      if (!((bool)((i >> j) & 1)))
      {
        int tmp = p[j];
        while (tmp > 0)
        {
          score += j + 1;
          tmp--;
          cnt++;
          if (score >= G)
          {
            ans = min(ans, cnt);
            break;
          }
        }
        break;
      }
    }
  }
  cout << ans << endl;
}

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

using namespace std;


template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s)
{
    return '"' + s + '"';
}

string to_string(const char* s)
{
    return to_string((string) s);
}

string to_string(bool b)
{
    return (b ? "true" : "false");
}

string to_string(vector<bool> v)
{
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++)
    {
        if (!first)
        {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v)
{
    string res = "";
    for (size_t i = 0; i < N; i++)
    {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v)
{
    bool first = true;
    string res = "{";
    for (const auto &x : v)
    {
        if (!first)
        {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p)
{
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p)
{
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p)
{
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out()
{
    cerr << endl;
}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << " " << to_string(H);
    debug_out(T...);
}

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

const double eps = 1e-10;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    int l = 0, r = n - 1;
    int ans = 0;
    while (l < r)
    {
        while (l < r && s[l] == 'R')
        {
            l++;
        }
        if (l >= r)
        {
            break;
        }
        if (s[l] != 'W')
        {
            break;
        }
        while (l < r && s[r] == 'W')
        {
            r--;
        }
        if (l >= r)
        {
            break;
        }
        if (s[r] != 'R')
        {
            break;
        }
        ans++;
        l++;
        r--;
    }
    cout << ans;
    return 0;
}


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

// ref. http://kmjp.hatenablog.jp/entry/2019/10/28/0900

using namespace std;

typedef long long ll;

const ll MAX_A = 1000000LL;
const ll MAX_F = 1000000LL;

bool cond(const vector<ll> &as, const vector<ll> &fs, const ll time, const ll k) {
    ll count = 0;

    for (int i = 0; i < (int) as.size(); i++) {
        ll v = as[i] * fs[i];
        if (v > time) {
            count += (v - time - 1 + fs[i]) / fs[i];
        }
        if (count > k) {
            return false;
        }
    }

    return true;
}

int main(void) {
    ll n, k;

    cin >> n >> k;

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

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

    sort(as.begin(), as.end());
    sort(fs.begin(), fs.end(), [](const int &a, const int &b) { return a > b; });

    // for (int i = 0; i < n; i++) {
    //     cout << as[i] << " ";
    // }
    // cout << endl;

    // for (int i = 0; i < n; i++) {
    //     cout << fs[i] << " ";
    // }
    // cout << endl;

    ll left = -1, right = MAX_A * MAX_F + 1;
    while (right - left > 1) {
        ll mid = (left + right) / 2;
        // cout << left << "," << mid << "," << right << endl;
        if (cond(as, fs, mid, k)) {
            right = mid;
        } else {
            left = mid;
        }
    }

    cout << right << endl;

    return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define F(i,L,R) for(int i=L;i<R;i++)
#define FE(i,L,R) for(int i=L;i<=R;i++)
#define RF(i,l,r) for(int i=r;i>l;i--)
#define RFE(i,l,r) for(int i=r;i>=l;i--)
#define getI(i) scanf("%d",&i)
#define getII(i,j) scanf("%d%d",&i,&j)
#define getIII(i,j,k) scanf("%d%d%d",&i,&j,&k)
#define VgetI(i) int (i);scanf("%d",&(i));
#define VgetII(i,j) int (i),(j);scanf("%d%d",&(i),&(j));
#define VgetIII(i,j,k) int (i),(j),(k);scanf("%d",&(i),&(j),&(k));
#define EoF(n) int(n);while(~getI(n))
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define abs(n) (n>0?n:(-n))
#define INF 2147483647
#define nINF -2147483648
int main(){
	int n,y;
	while(~getII(n,y)){
		int ans1=-1,ans2=-1,ans3=-1;
		FE(i,0,n) FE(j,0,n){
			int now=i*10000+j*5000;
			if(i+j>n||now>y) break;
			if(now+(n-i-j)*1000==y) ans1=i,ans2=j,ans3=n-i-j,j=n+1,i=n+1;
		}
		printf("%d %d %d\n",ans1,ans2,ans3);
	}
}


Measured memory_bytes: 256
n = int(input())
a, b = map(int, input().split())
p = list(map(int, input().split()))
t1 = sum(1 for x in p if x <= a)
t2 = sum(1 for x in p if a+1 <= x and x <= b)
t3 = sum(1 for x in p if x >= b+1)
print(min(t1, t2, t3))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
using namespace std;
//cout << fixed << setprecision(0)
int main() { 
  string s;cin >>s;
  int cnt;
  rep(i,3)if(s[i]=='o')cnt++;
  cout << 700+100*cnt << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void){
	int a;
	int b=512;
	int c[10]={0};
	int d=0;
        while(cin>>a){

            int i=0;
            if (a>=512){
                a-=512;
                c[i]=512;
                i++;
            }
            if (a>=256){
                a-=256;
                c[i]=256;
                i++;
            }
            if (a>=128){
                a-=128;
                c[i]=128;
                i++;
            }
            if (a>=64){
                a-=64;
                c[i]=64;
                i++;
            }
            if (a>=32){
                a-=32;
                c[i]=32;
                i++;
            }
            if (a>=16){
                a-=16;
                c[i]=16;
                i++;
            }
            if (a>=8){
                a-=8;
                c[i]=8;
                i++;
            }
            if (a>=4){
                a-=4;
                c[i]=4;
                i++;
            }
            if (a>=2){
                a-=2;
                c[i]=2;
                i++;
            }
            if (a>=1){
                a-=1;
                c[i]=1;
                i++;
            }

            for(i-=1;i>=0;i--){
                if(i==0){
                    cout<<c[i];
                    break;
                }
                cout<<c[i]<<" ";

            }
            cout<<endl;
        }
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <utility>
using namespace std;
using ll = long long;

int main(){
  int a, b; cin >> a >> b;
  if ( a+ b == 15 ){
    cout << "+" << endl;
  }
  else if (a * b == 15){
    cout << "*" << endl;
  }
  else{
    cout << "x" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>
#include <functional>

using namespace std;
#define ALL(x)              (x).begin(),(x).end()
#define REP(i, n)           for (int (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)       for (int (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF                 (int)2e9
#define MOD                 (1000 * 1000 * 1000 + 7)
#define Ceil(x, n)          (((((x))+((n)-1))/n))
#define CeilN(x, n)         (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)        ((x)-(x)%(n))
#define IsOdd(x)            (((x)&0x01UL) == 0x01UL)
#define IsEven(x)           (!IsOdd((x)))
#define M_PI                3.14159265358979323846
typedef long long           ll;
typedef pair<ll, ll>        P;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
int main()
{
	int N;
	ll A, B;
	cin >> N >> A >> B;
	vector<ll> X(N);
	REP(i, N) cin >> X[i];

	ll walkDist = 0;
	ll ans = 0;
	REP(i, N - 1) {
		ll dist = X[i + 1] - X[i];
		if (dist * A < B) {
			ans += dist * A;
		} else {
			ans += B;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = 1000000007;
	void doIt() {
		int h = sc.nextInt();
		int w = sc.nextInt();
		int K = sc.nextInt();
		int dp[][] = new int[h + 1][w];
		for(int i = 0; i <= h; i++)Arrays.fill(dp[i],0);
		dp[0][0] = 1;
		for(int i = 0; i < h; i++) {
			for(int j = 0; j < w; j++) {
				//kのビットパターン：横棒[w-1...0]（kは整数なので反転）
				for(int k = 0; k < 1 << (w - 1); k++) {
					if(validate(k, w)) {
						//左方向への分岐
						if(j >= 1 && ((k >> (j - 1)) & 1) == 1) {
							dp[i + 1][j - 1] += dp[i][j];
							dp[i + 1][j - 1] %= MOD;
						}
						//右方向への分岐
						else if(j < w - 1 && (k >> j & 1) == 1) {
							dp[i + 1][j + 1] += dp[i][j];
							dp[i + 1][j + 1] %= MOD;
						}
						//分岐無し
						else {
							dp[i + 1][j] += dp[i][j];
							dp[i + 1][j] %= MOD;
						}
					}
				}
			}
		}
		System.out.println(dp[h][K - 1]);
	}
	
	boolean validate(int num, int w) {
		//validであるかどうかを返す。
		int n = num;
		for(int i = 0; i < (w - 1); i++) {
			if(((n >> i) & 1) == 1 && (n >> (i + 1) & 1) == 1){
				return false;
			}
		}
		return true;
	}
	
	Main(){doIt();}
	public static void main(String[] args) {
		new Main();
	}
}

Measured memory_bytes: 23252
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  int N, K; cin >> N >> K;
  vector<ll> x(N); rep(i, N) cin >> x[i];

  ll ans = INF;
  for (int i = 0; i < N; ++i){
    if (i + K - 1 >= N) continue;
    ll tmp = min(abs(x[i]) + abs(x[i + K - 1] - x[i]), abs(x[i + K - 1]) + abs(x[i + K - 1] - x[i]));
    //cout << x[i] << " " << x[i + K] << endl;
    ans = min(ans, tmp);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true; }return false; }
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true; }return false; }
const int INF = 1e18;

signed main(){
    int q; cin >> q;
    priority_queue<int> lowq;
    priority_queue<int,vector<int>,greater<int>> highq;
    int bsum = 0,lowsum = 0, highsum = 0;
    REP(i,q){
        int z; cin >> z;
        if(z == 1){
            int a, b; cin >> a >> b; bsum += b;
            if(highq.size() < lowq.size()){
                if(lowq.top() <= a){
                    highq.push(a);
                    highsum += a;
                }
                else{
                    highq.push(lowq.top());
                    highsum += lowq.top();
                    lowsum += a - lowq.top();
                    lowq.pop();
                    lowq.push(a);
                }
            }
            else{
                if(lowq.empty()){
                    lowq.push(a);
                    lowsum += a;
                }
                else{
                    if(highq.top() >= a){
                        lowq.push(a);
                        lowsum += a;
                    }
                    else{
                        lowq.push(highq.top());
                        lowsum += highq.top();
                        highsum += a - highq.top();
                        highq.pop();
                        highq.push(a);
                    }
                }
            }
        }
        if(z == 2){
            int ans = lowq.top()*(SZ(lowq)-SZ(highq)) -lowsum + highsum + bsum;
            cout << lowq.top() << " " << ans << '\n';
        }
    }
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define mp make_pair
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll INF=1LL<<30;
const ll LINF=1LL<<60;
const double eps=1e-5;
const ll MOD=1000000007LL;
template<typename T>void chmin(T &a,T b){a=min(a,b);};
template<typename T>void chmax(T &a,T b){a=max(a,b);};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
vector<ll> x;
struct UnionFind{
    vector<int> par,siz,co;
    vector<ll> sum;
    UnionFind(int n){
        par.resize(n);
        siz.resize(n,1);
        sum.resize(n);
        co.resize(n);
		for(int i=0;i<n;i++){
            sum[i]=x[i];
            par[i]=i;
        }
    }
    int find(int x){
		if(par[x]==x){
			return x;
		}else{
			return par[x]=find(par[x]);
		}
	}
	bool unite(int u,int v){
		u=find(u),v=find(v);
		if(u==v)return false;
		if(siz[u]<siz[v])swap(u,v);
		par[v]=u;
		siz[u]+=siz[v];
        sum[u]+=sum[v];
        co[u]+=co[v];
		return true;
	}
	bool same(int u,int v){
		return find(u)==find(v);
	}
};
int main(){
    int n,m;cin>>n>>m;
    x.resize(n);
    for(int i=0;i<n;i++)cin>>x[i];
    vector<pair<ll,P>> v;
    for(int i=0;i<m;i++){
        int a,b,y;cin>>a>>b>>y;--a;--b;
        v.push_back(mp(y,mp(a,b)));
    }
    sort(all(v));
    UnionFind uf(n);
    int ans=0;
    for(int i=0;i<m;i++){
        int a=v[i].second.first,b=v[i].second.second;ll y=v[i].first;
        uf.unite(a,b);
        uf.co[uf.find(a)]++;
        if(uf.sum[uf.find(a)]>=y){
            ans+=uf.co[uf.find(a)];
            uf.co[uf.find(a)]=0;
        }
    }
    cout<<m-ans<<endl;
    return 0;
}


Measured memory_bytes: 6000
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 998244353
#define INF2 1000000000000000000
#define int long long


int cnt[100010];
int Mul(int a, int b) {
	return ((a % mod) * (b % mod)) % mod;
}
int square(int x) {
	return (x * x) % mod;
}

int power(int x, int y) {
	if (y == 0) return 1;
	else if (y == 1) return x % mod;
	else if (y % 2 == 0) return square(power(x, y / 2)) % mod;
	else return square(power(x, y / 2)) * x % mod;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int D[100010];
    rep(i, N) cin >> D[i];
    if (D[0] != 0) {cout << 0 << endl; return 0;}
    sort(D, D + N);
    rep(i, N - 1) if (D[i + 1] - D[i] > 1) {cout << 0 << endl; return 0;}
    int ans = 1;
    rep(i, N) cnt[D[i]]++;
    if (cnt[0] != 1) {cout << 0 << endl; return 0;}
    int i = 0;
    while(cnt[i + 1] > 0) {
        ans = Mul(ans, power(cnt[i], cnt[i + 1]));
        i++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <algorithm>

using namespace std;

int main(){
	int n, m;
	cin >> n >> m;

	vector<pair<long long int, long long int> > v(n+m, make_pair(0,0));

	for(int i=0; i<n; i++){
		long long int a;
		cin >> a;
		v[i]=make_pair(a,1);
	}
	for(int i=0; i<m; i++){
		long long int a, b;
		cin >> a >> b;
		v[n+i]=make_pair(b, a);
	}

	sort(v.begin(),v.end(), greater<pair<int, int> >());

	long long int sum=0, cards=0;
	for(auto vi: v){
		if(vi.second<=(n-cards)){
			sum+=vi.first*vi.second;
			cards+=vi.second;
		}else{
			sum+=vi.first*(n-cards);
			break;
		}
	}

	cout << sum << endl;


	return 0;

}





Measured memory_bytes: 3328