akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
const int INF =100100100;
const int MOD = (int)1e9+7;
const double EPS = 1e-9;
typedef long long ll;
typedef long li;
#define pb push_back 
#define mp make_pair

signed main (){	
	int temp;
	cin >> temp;
	if(temp<=111){
		cout << 111;
	}
	else if (temp<=222){
		cout << 222;
	}
	else if (temp<=333){
		cout << 333;
	}
	else if (temp<=444){
		cout << 444;
	}
	else if (temp<=555){
		cout << 555;
	}
	else if (temp<=666){
		cout << 666;
	}
	else if (temp<=777){
		cout << 777;
	}
	else if (temp<=888){
		cout << 888;
	}
	else if (temp<=999){
		cout << 999;
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
 
const ll mod = 1e9+7;
 
 
int num[2000+10];
int a[2000+10];
int b[2000+10];
 
int main()
{
	ll n,k;
	cin>>n>>k;
	for(int i=0; i<n; i++)
		cin>>num[i];
	for(int i=0; i<n; i++)
	{
		int j=i+1;
		while(j < n) 
		{
			if(num[j] < num[i]) a[i]++;	
			j++;		
		}
		if(!b[num[i]])
			{
				for(int k=0; k<n; k++)
				{
					if(num[k] < num[i])
					b[num[i]]++;
				}
			}
	}
//	for(int i=0; i<n; i++) cout<<a[i]<<' '<<b[num[i]]<<endl;
 
	ll ans=0;
	ll sum=(k-1)*k/2;//放在下面的求ans语句中就会wa,求逆元也不行,遇到除法还是单独运算比较好.
	sum = sum % mod;
	for(int i=0; i<n; i++)
	{
//		ans += b[num[i]]*sum%mod;
//		ans += k*a[i]%mod;
		
		ans=(ans+k*a[i]%mod+b[num[i]]*sum%mod)%mod;
	}
	cout<<ans%mod;
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int count = 0;
		int preHeight = sc.nextInt();
		int max = 0;
		for(int i=0;i<n-1;i++) {
			int height = sc.nextInt();
			if(height<=preHeight) {
				count++;
				if(count>=max) {
					max = count;
				}
			// 移動できなかった場合、カウンタをリセット
			}else {
				count = 0;
			}
			preHeight = height;
		}
		sc.close();
		System.out.println(max);
	}

}


Measured memory_bytes: 48572
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define mp make_pair
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

const ll MOD=1e9+7;

ll ad(ll x,ll y=0){
  return (x+y)%MOD;
}

ll mlt(ll x,ll y=1){
  return (x*y)%MOD;
}

int main(){
  ll h,w,k,dp[10][110]={};
  bool vis[10];
  cin>>h>>w>>k;
  dp[0][0]=1;
  Fr(k,h){
    fr(i,1<<(w-1)){
      if((i&(i<<1))!=0) continue;
      fr(j,w) vis[j]=0;
      fr(j,w-1){
        if((i>>j)&1){
          dp[j][k]=ad(dp[j][k],dp[j+1][k-1]);
          dp[j+1][k]=ad(dp[j+1][k],dp[j][k-1]);
          vis[j]=1;vis[j+1]=1;
        }
      }
      fr(j,w) if(!vis[j]) dp[j][k]=ad(dp[j][k],dp[j][k-1]);
    }
  }
  cout<<dp[k-1][h]<<endl;
}

Measured memory_bytes: 256
# import sys
# input = sys.stdin.readline
# import re
import itertools

def main():
    n, k = input_list()
    p = input_list()

    p.sort()
    print(sum(p[:k]))

def count_tento(l, cur):
    count = 0
    for v in l:
        if v > cur:
            count += 1
    return count

def input_list():
    return list(map(int, input().split()))

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

if __name__ == '__main__':
    main()


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

using namespace std;
int main(void) {
    int n;
    cin >> n;

    vector<int> a(n);
    for(auto &x: a) cin >> x;

    sort(a.begin(), a.end());

    int b = a[(n-1)/2];
    int c = a[(n-0)/2];

    cout << c-b << endl;
}


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

int main() {
	int N;
	cin >> N;
	vector<int> a(N+1, 0);
	for (int i = 1; i <= N; i++) cin >> a[i];
	int now = 1;
	int ans = 0;
	while (a[now] > 0) {
		if (now == 2) {
			cout << ans;
			return 0;
		}
		ans++;
		int old = now;
		now = a[now];
		a[old] = -1;
	}
	cout << -1;
}

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

int N, A[200];

int main()
{
	int dmin = 100;
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) {
		int A;
		scanf("%d", &A);
		int d = 0;
		while (A % 2 == 0) {
			A /= 2;
			++d;
		}
		dmin = min(dmin, d);
	}
	printf("%d\n", dmin);
	return 0;
}


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

int main()
{
    long long int n;
    scanf("%lld",&n);
    if(n%2==0)
    {
        printf("%lld\n",n/2-1);
    }
    else
        printf("%lld\n",n/2);
    return 0;
}


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

long long int tempDiff(const long long int left, const long long int right, const int s, const int t) {
	return (left > right) ? (left - right) * t : (left - right) * s;
}
class SegmentTree {
	std::vector<long long int> vec;
	const unsigned int size;
	void set(const int from, const int to, const long long int value) {
		if (from == to) vec[from] += value;
		else if (from < to) {
			if (from % 2 == 1) vec[from] += value;
			if (to % 2 == 0) vec[to] += value;
			set((from + 1) / 2, (to - 1) / 2, value);
		}
	}
	long long int get(const int index) const {
		return (index == 0) ? 0 : (vec[index] + get(index / 2));
	}
public:
	SegmentTree(const std::vector<long long int> &origin) : vec(origin.size() * 2, 0), size(origin.size()) {
		for (auto i = size; i < vec.size(); ++i) {
			vec[i] = origin[i - size];
		}
	}
	void add(const int from, const int to, const long long int value) {
		set(from + size, to + size, value);
	}
	long long int operator[](const int index) const {
		return get(index + size);
	}
};
int main() {
	int n, q, s, t;
	std::cin >> n >> q >> s >> t;
	std::vector<long long int> init(n + 1);
	for (auto &a : init) std::cin >> a;
	SegmentTree state(init);
	long long int current = 0;
	for (auto i = 1; i < init.size(); ++i)  current += tempDiff(init[i - 1], init[i], s, t);
	int l, r, x;
	for (auto i = 0; i < q; ++i) {
		std::cin >> l >> r >> x;
		if (r != n) {
			auto rl = state[r];
			auto rr = state[r + 1];
			current += tempDiff(rl + x, rr, s, t) - tempDiff(rl, rr, s, t);
		}
		auto ll = state[l - 1];
		auto lr = state[l];
		current += tempDiff(ll, lr + x, s, t) - tempDiff(ll, lr, s, t);
		state.add(l, r, x);
		std::cout << current << '\n';
	}
}


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

int main(){
  int A,B,K;
  cin >> A >> B >> K;
  for(int i=A;i<=min(B,A+K-1);i++)cout << i << endl;
  for(int i=max(B-K+1,A+K);i<=B;i++)cout << i << endl;
  return 0;
}


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

using namespace std;

int main(){
    int n;
    cin >> n;
    int a[n], max = 0;
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++){
        for(int j = i; j < n; j++){
            if( max < abs(a[i] - a[j]) ) max = abs(a[i]- a[j]);
        }     
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  int hanoi[16][3][3];
  REP(j,3) REP(k,3) hanoi[0][j][k] = 0;
  REP(i,15) {
    REP(j,3) {
      REP(k,3) {
        if (k==j) {
          hanoi[i+1][j][k] = 0;
          continue;
        }
        if (abs(k-j)==2) {
          hanoi[i+1][j][k] = hanoi[i][j][k] + 1 + hanoi[i][k][j] + 1 + hanoi[i][j][k];
          continue;
        }
        bool hoge[3] ={};
        hoge[j] = hoge[k] = 1;
        int a;
        REP(l,3) if (!hoge[l]) a = l;
        hanoi[i+1][j][k] = hanoi[i][j][a] + 1 + hanoi[i][a][k];
        //      printf("%d,%d,%d %d\n",i,j,k,hanoi[i][j][k]);
      }
    }
  }
//  cout << "OK" << endl;
  
  int n, m;
  while(cin>>n>>m, n||m) {
    typedef pair<int, int> pii;
    vector<pii> v; // size, pos
    REP(i, 3) {
      int a;
      cin >> a;
      REP(j, a) {
        int size;
        cin >> size;
        v.push_back(pii(size,i));
      }
    }
    sort(ALL(v), greater<pii>());
    
    int dp[n][3];               // dp[i][j] : å«¢û©çi ÔÚÜÅÌJbvðj ÉÚ®·éè
    // REP(i,m+1) REP(j,3)
    //   dp[i][j] = INF;
    REP(i, 3) dp[0][i] = 0;
    
    REP(i, n) {
      REP(j, 3) {
//        printf("i=%d, j=%d\n",i,j);
        int aa = v[i].second;
        if (aa==j) {
          dp[i+1][j] = dp[i][j];
          continue;
        }
        if (abs(aa-j)==2) {
          dp[i+1][j] = dp[i][j] + 1 + hanoi[i][j][aa] + 1 + hanoi[i][aa][j];
          continue;
        }

        bool hoge[3] ={};
        hoge[j] = hoge[aa] = 1;
        int a;
        REP(l,3) if (!hoge[l]) a = l;
        dp[i+1][j] = dp[i][a] + abs(aa-j) + hanoi[i][a][j];
      }
    }

    int res = min(dp[n][0], dp[n][2]);
    if (res<=m) cout << res << endl;
    else cout << -1 << endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	int a,b;
	char c;
	cin >> a >> c >> b;
	if(c=='+')
		cout << a+b;
	else
		cout << a-b;	

	return 0;
}


Measured memory_bytes: 3544
#include <stdio.h>  /*入出力*/
#include <stdlib.h> /*標準ライブラリ*/
#include <string.h> /*文字列*/
#include <math.h>   /*計算*/
#include <assert.h> /*確認*/
#include <ctype.h>  /*文字操作*/
#include <stdbool.h>/*bool型の利用*/

#define rep(i, n) for(int  i = 0; i < (n); i++)
#define max(a,b) ((a>b)?a:b)
#define ABS(a) (((a)>(0))?a:-(a))

//date 03/07
//abc158

int main(void)
{
  long N;
  long A;
  long B;
  long c;
  long ans = 0;
  scanf("%ld %ld %ld", &N, &A, &B);
  c = N % (A+B);
  if (c >= 0 && c <= A) {
    ans = (N/(A+B)) * A + c ;
  }else{
    ans = (N/(A+B) +1) * A;
  }
  printf("%ld\n", ans);
  return 0;
}


Measured memory_bytes: 128
import kotlin.math.abs

fun main() {
    val (x, n) = nextIntList()
    val values = (if (n > 0) {
        nextIntList()
    } else {
        emptyList()
    }).sorted()
    var index = 0
    var MIN = x
    var res = 0
    (1..101).forEach {
        if (values.size > index && it == values[index]) {
            index++
            return@forEach
        }
        if (MIN > abs(x - it)) {
            MIN = abs(x - it)
            res = it
        }
    }
    println(res)
}

// # Utils
// ## Input
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map(String::toInt)
fun nextLongList() = next().split(" ").map(String::toLong)
fun nextDoubleList() = next().split(" ").map(String::toDouble)


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

int main(){
    int n, m, p;
    int a, sum, tmp, ans;
    
    while(1){
        cin >> n >> m >> p;
        sum=0;
        if(n+m+p==0) break;
        for(int i=1; i<=n; i++){
            cin >> a;
            sum+=a;
            if(i==m) tmp=a;
        }
        if(tmp==0) ans = 0;
        else ans = sum * (100-p) / tmp;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
def divisor(n):
    i = 1
    ans_div = []
    while i * i <= n:
        if n%i == 0:
            ans_div.append(i)
            ans_div.append(n // i)
        i += 1
    ans_div = list(set(ans_div))
    return ans_div
import sys
input = sys.stdin.readline
N = int(input())
count = 0
if N < 105:
    print(0)
else:
    for odd in range(105, N+1, 2):
        li = divisor(odd)
        if len(li) == 8:
            count += 1
    print(count)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<set>
#include<tuple>
using namespace std;
#define INF 11000000000
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> p;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)

int ans[11000];


int main(){
    int N;
    cin>>N;
    vector<int> V[11000];
    ll c[11000];
    for(int i=0;i<N-1;i++){
        int a,b;
        cin>>a>>b; a--; b--;
        V[a].push_back(b);
        V[b].push_back(a);
    }
    for(int i=0;i<N;i++){
        cin>>c[i];
    }
    sort(c,c+N,greater<ll>());
    ll sum=0;
    for(int i=1;i<N;i++){
        sum+=c[i];
    }
    cout<<sum<<endl;
    queue<int> que;
    ans[0]=c[0];
    int count=0;
    que.push(0);
    while(!que.empty()){
        int now=que.front();
        que.pop();
        for(int i=0;i<(int)V[now].size();i++){
            int next=V[now][i];
            if(ans[next]==0){
                que.push(next);
                count++;
                ans[next]=c[count];
            }
        }
    }
    for(int i=0;i<N;i++){
        if(i) cout<<" ";
        cout<<ans[i];
    }
    cout<<endl;
}



Measured memory_bytes: 1024
#include <iostream>
using namespace std;
#define MAX 100005
#define NIL -1

typedef struct{
	int p, l, r;
}Node;

Node T[MAX];
int n, D[MAX];

void print(int u)
{
	int i, c;
	cout << "node " << u << ": ";
	cout << "parent = " << T[u].p << ", ";
	cout << "depth = " << D[u] << ", ";

	if (T[u].p == NIL){
		cout << "root, ";
	}
	else if (T[u].l == NIL){
		cout << "leaf, ";
	}
	else{
		cout << "internal node, ";
	}

	cout << "[";

	for (i = 0, c = T[u].l; c != NIL; i++, c = T[c].r){
		if (i){
			cout << ", ";
		}
		cout << c;
	}
	cout << "]" << endl;
}

void rec(int u, int p)
{
	D[u] = p;
	if (T[u].r != NIL){
		rec(T[u].r, p);
	}
	if (T[u].l != NIL){
		rec(T[u].l, p + 1);
	}
}

int main()
{
	cin >> n;

	for (int i = 0; i < n; i++){
		T[i].p = T[i].l = T[i].r = NIL;
	}

	int v, d, c, l, r;
	for (int i = 0; i < n; i++){
		cin >> v >> d;
		for (int j = 0; j < d; j++){
			cin >> c;
			if (j == 0){
				T[v].l = c;
			}
			else{
				T[l].r = c;
			}
			l = c;
			T[c].p = v;
		}
	}
	for (int i = 0; i < n; i++){
		if (T[i].p == NIL){
			r = i;
		}
	}

	rec(r, 0);

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

	return 0;
}

Measured memory_bytes: 7684
s = list(input())
cnt_c = 0

for i in range(2, len(s) - 1):
    if s[i] == "C":
        cnt_c += 1

if s[0] == "A":
    s.remove("A")
    if cnt_c > 0:
        s.remove("C")
    if cnt_c == 1 and str(s).islower():
        print("AC")
    else:
        print("WA")
else:
    print("WA")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;

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

    int count = 0;

    for (int i = 0; i < 1000; i++){
        vector<int> a{ i /100, (i / 10) % 10, i % 10};
        
        int digits = 0;
        for(int j = 0; j < n; j++){
            if(s[j] == (a[digits] + '0'))digits++;
            if(digits == 3){
                count++;
                break;
            }
        }
    }
    print(count);
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 16
#define G_OF_BEFORE 200
#define G_OF_AFTER 300
int main(void){
	int i;
	char className[MAX];
	int before,after; 
	for(i = 0; i < 9; i++){
		scanf("%s%d%d",className,&before,&after);
		printf(
			"%s %d %d\n",
			className, before + after,
			before*G_OF_BEFORE + after*G_OF_AFTER
		);
		
	}
	
	return 0;
}

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

#define FOR(i, l, r) for(ll i = l; i < r; i++)
#define rep(i, N) FOR(i, 0, N)

#define MOD 1000000007
#define INF 1000000000

using ll = long long int;
using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

int main() {
    int X, Y; cin >> X >> Y;
    bool ans = true;

    if(Y < 2*X || Y > 4*X || Y%2 == 1) ans = false;
    
    cout << (ans?"Yes":"No") << endl;
    return 0;
}


Measured memory_bytes: 3624
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    if (k <= a) cout << k;
    else if (k <= a + b) cout << a;
    else cout << a - (k - a - b);
    return 0;
}


Measured memory_bytes: 3648
import sys
sys.setrecursionlimit(10**9)

N = int(input())
As = list(map(int, input().split()))
adjL = [[] for _ in range(N)]
for _ in range(N-1):
    A, B = map(int, input().split())
    adjL[A-1].append(B-1)
    adjL[B-1].append(A-1)

def dfsTree(vNow):
    useds[vNow] = True
    for v2 in adjL[vNow]:
        if not useds[v2]:
            chlds[vNow].append(v2)
            dfsTree(v2)

vRoot = 0
chlds = [[] for v in range(N)]
useds = [False] * N
dfsTree(vRoot)

def dfs(vNow):
    if not chlds[vNow]:
        return As[vNow]
    cs = []
    for chld in chlds[vNow]:
        c = dfs(chld)
        if c == -1:
            return -1
        cs.append(c)
    sumC = sum(cs)
    T = 2*As[vNow] - sumC
    if T < 0:
        return -1
    cs.append(T)
    sumC += T
    if max(cs) <= sumC/2:
        return T
    else:
        return -1

ans = dfs(vRoot)
isLeaf = len(chlds[vRoot]) == 1
if (isLeaf and ans == As[vRoot]) or (not isLeaf and ans == 0):
    print('YES')
else:
    print('NO')


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

int main() {
  int s, x, y;
  cin >> s;
  x = s / 100;
  y = s % 100;
  if (x <= 12 && x != 00) {
    if (y <= 12 && y != 00){
      cout << "AMBIGUOUS" <<endl;
    }
    else {
      cout << "MMYY" <<endl;
    }
  }
  else {
    if (y <= 12 && y != 00) {
      cout << "YYMM" <<endl;
    }
    else {
      cout << "NA" <<endl;
    }
  }
}
  


Measured memory_bytes: 256
N,X,M=map(int,input().split())

seen=[-2]*M
seen[X]
A=[X]
i=1
while(i<N):
    T=A[-1]**2%M
    if seen[T]!=-2:
        Roop=i-seen[T]
        Left,Right=seen[T],i
        break
    A.append(T)
    seen[T]=i
    i+=1

if i==N:
    print(sum(A))
    exit()

Roopsum=0
for i in range(Left,Right):
    Roopsum+=A[i]

Rest=N-len(A)

ans=sum(A)

ans+=Rest//Roop*Roopsum

for i in range(Rest%Roop):
    ans+=T
    T=T**2%M
print(ans)

Measured memory_bytes: 71220
#include <stdio.h>

int main(int argc, char **argv)
{
    int r, g, b;
    scanf("%d %d %d", &r, &g, &b);

    if ((100*r + 10*g + b) % 4 == 0) {
        puts("YES");
    } else {
        puts("NO");
    }
    return 0;
}

Measured memory_bytes: 128
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::cmp;

fn find_min_max(x: &[i64]) -> (i64, i64) {
    let mut min: i64 = x[0];
    let mut max: i64 = x[0];
    let mut x_iter = x.iter();
    while let Some(i) = x_iter.next() {
        min = cmp::min(*i, min);
        max = cmp::max(*i, max);
    }
    return (min, max)
}

fn main() {
    input!(
      n: i64,
      mat: [i64; n],
    );
    let mat2 = mat.clone();
    let mut w = 0;
    for x in mat {
        w += x
    }
    let p = w/n;
    let p2 = w/n + 1;

    let mut cost = 0;
    let mut cost2 = 0;
    for x in mat2 {
        cost += (x - p) * (x - p);
        cost2 += (x - p2) * (x - p2);
    }

    if cost < cost2 {
        println!("{}", cost);
    }else {
        println!("{}", cost2);
    }
}


Measured memory_bytes: 4352
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] hist = new int[M];
 
        for (int i =0; i<N; i++) {
            int K = sc.nextInt();

            for (int j =0; j<K; j++) {
              int index = sc.nextInt() - 1;
                hist[index]++;
            }
        }

        int result = 0;
        for (int i = 0; i<M; i++) {
            if (hist[i] == N) {
                result++;
            }
        }

        System.out.println(result);
    }
}

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

using namespace std;

char sa[3000], sb[3000];
int a[3000], b[3000];
int lft[3000], rght[3000];
int ll[3000];
int lrmax[3000];
int rr[3000];
int rlmax[3000];

int main()
{
    cin >> sa >> sb;
    int n = strlen(sa);
    for(int i = 0; i < n; i++){
        a[i] = sa[i] - '0';
        b[i] = sb[i] - '0';
    }
    int l = n - 1;
    while (b[l] != 1 && l >= 0)
        l--;
    if (l == -1){
        bool isone = false;
        for(int i = 0; i < n; i++) {
            if (a[i] == 1) {
                isone = true;
                break;
            }
        }
        if (isone)
        {
            cout << -1 << endl;
            exit(0);
        }
    }
    l -= n;
    //cout << l << endl;
    for(int i = 0; i < n; i++){
        if (b[i] == 1) {
            l = i;
        }
        lft[i] = i - l;
    }
    int r = 0;
    while (b[r] != 1 && r < n)
        r++;
    r += n;
    //cout << r << endl;
    for (int i = n - 1; i >= 0; i--){
        if (b[i] == 1) {
            r = i;
        }
        rght[i] = r - i;
    }
    //cout << n << endl;
    int m = 1e9;
    for(int i = 0; i < n; i++){
        int maxl = 0, maxr = 0, diff = 0;
        int minl = 1e9, minr = 1e9;
        for(int i = 0; i < 3000; i++)
            ll[i] = rr[i] = 0;
        for(int j = 0; j < n; j++){
            int id = (i + j) % n;
            if (a[id] == b[j])
                continue;
            diff++;
            maxl = max(maxl, lft[id]);
            maxr = max(maxr, rght[id]);
            ll[lft[id]] = max(ll[lft[id]], rght[id]);
            rr[rght[id]] = max(rr[rght[id]], lft[id]);
        }
        //cout << "diff: " << diff << endl;
        //cout << i << " " << maxl << " " << maxr << endl;
        int mx = -1;
        for(int i = n - 1; i >= 0; i--){
            if (ll[i] != 0)
                mx = max(ll[i], mx);
            lrmax[i] = mx;
        }
        mx = -1;
        for(int i = n - 1; i >= 0; i--){
            if (rr[i] != 0)
                mx = max(rr[i], mx);
            rlmax[i] = mx;
        }
        int ans = 1e9;
        int mv, pos;
        mv = maxl;
        pos = (i - maxl + n) % n;
        ans = min(ans, mv + min(pos, n - pos));
        //cout << ans << endl;
        mv = maxr;
        pos = (i + maxr + n) % n;
        ans = min(ans, mv + min(pos, n - pos));
        //cout << ans << endl;
        for(int l = 0; l < n; l++){
            if (lrmax[l + 1] == -1)
                continue;
            mv = l + l + lrmax[l + 1];
            pos = (i + lrmax[l + 1] + n) % n;
            ans = min(ans, mv + min(pos, n - pos));
            //cout << l << ": " << ans << endl;
        }
        for(int r = 0; r < n; r++){
            if (rlmax[r + 1] == -1)
                continue;
            mv = r + r + rlmax[r + 1];
            pos = (i - rlmax[r + 1] + n) % n;
            ans = min(ans, mv + min(pos, n - pos));
            //cout << r << ": " << ans << endl;
        }
        ans += diff;
        if (ans < m)
            m = ans;
    }
    cout << m << endl;
    return 0;
}


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

int main() {
	int n;
	cin >> n;
	pair<int, int> p(1, 0);
	for (int i = 1; i <= n; i++) {
		int a;
		cin >> a;
		if (abs(p.second) < abs(a)) {
			p = {i, a};
		}
	}
	cout << 2 * n - 1 << endl;
	for (int i = 1; i <= n; i++) {
		cout << p.first << ' ' << i << endl;
	}
	if (0 <= p.second) {
		for (int i = 2; i <= n; i++) {
			cout << i - 1 << ' ' << i << endl;
		}
	} else {
		for (int i = n; 1 < i; i--) {
			cout << i << ' ' << i - 1 << endl;
		}
	}
	return 0;
}

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

int X,Y,w,h,n,x,y,m,a;

int main(){
	cin>>m;
	for(int i=0;i<m;i++){
		a=0;
		cin>>X>>Y>>w>>h>>n;
		for(int j=0;j<n;j++){
			cin>>x>>y;
			if(X<=x&&x<=X+w&&Y<=y&&y<=Y+h)a++;
		}
		cout<<a<<endl;
	}
}

Measured memory_bytes: 0
#include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;
long long n,s;
int a[1010],b[1010];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i]>>b[i];
		s+=b[i]-a[i]+1;
	}
	cout<<s;
return 0;
}


Measured memory_bytes: 256
a = []
for i in range(5):
    a.append(int(input()))

def kiriage(x):
    n = x % 10
    if n == 0:
        return x
    else:
        return x + 10 - n

n = 0
for i in range(5):
    n += kiriage(a[i])

p = 10
for i in range(5):
    if a[i] % 10 != 0:
        p = min(p, a[i] % 10)

print(n - 10 + p)

Measured memory_bytes: 3064
n=int(input())
a,b,c=map(int,input().split())
ref=[a,b,c]
for i in range(n-1):
 a,b,c=map(int,input().split())
 ref1=[0,0,0]
 ref1[0]=max(ref[1]+a,ref[2]+a)
 ref1[1]=max(ref[0]+b,ref[2]+b)
 ref1[2]=max(ref[0]+c,ref[1]+c)
 ref=ref1
print(max(ref))


Measured memory_bytes: 3064
/* Author: Newbie Abhishek Pandey */
                                       
#include<bits/stdc++.h>
#define Abhi_921 ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ll long long
#define ld long double
#define fi(i,j,n) for(int i=j;i<n;i++)
#define fd(i,j,n) for(int i=j;i>n;i--)
#define print(a,n) for(int i=0;i<n;i++){cout<<a[i]<<' ';}cout<<endl;
#define inp(a,n) for(int i=0;i<n;i++) cin>>a[i]
#define printe(v) for(auto &i:v){cout<<i<<' ';}cout<<endl;
#define deb(n1) cout<<n1<<endl;
#define pb push_back
#define eb emplace_back
#define vi vector<ll>
#define vll vector<pair<ll,ll>>
#define umap unordered_map<ll,ll>
using namespace std;
const long long mod=1e9+7;
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
Abhi_921;
int t;
t=1;
while(t--){
int d,t,s;
cin>>d>>t>>s;
double a=((double)d)/s;
if(a<=t) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return 0;
}

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

template<typename T>
struct imos2d{
	int n,m;
	T mod;
	vector<vector<T>>sum;
	bool flag=false;

	imos2d(){}
	imos2d(int n,int m,T mod=-1)
		:n(n),m(m),mod(mod),sum(vector<vector<T>>(n+2,vector<T>(m+2))){}
	
	void add(int x1,int y1,int x2,int y2,T t){
		assert(!flag);
		x1++;y1++;x2++;y2++;
		sum[x1][y1]+=t;
		sum[x1][y2+1]-=t;
		sum[x2+1][y1]-=t;
		sum[x2+1][y2+1]+=t;
		if(mod!=-1){
			sum[x1][y1]%=mod;
			(sum[x1][y2+1]+=mod)%=mod;
			(sum[x2+1][y1]+=mod)%=mod;
			sum[x2+1][y2+1]%=mod;
		}
	}
	
	void calc(){
		flag=true;
		rep(i,n+1)for(int j=1;j<=m;j++){
			sum[i][j]+=sum[i][j-1];
			if(mod!=-1)sum[i][j]%=mod;
		}
		rep(i,m+1)for(int j=1;j<=n;j++){
			sum[j][i]+=sum[j-1][i];
			if(mod!=-1)sum[j][i]%=mod;
		}
	}

	T get(int x,int y){
		if(!flag)calc();
		x++;y++;
		return sum[x][y];
	}
};
P dat[20000];
int N;
void init(int n){
	N=1;while(N<n)N<<=1;
	for(int i=N;i<2*N;i++)dat[i].second=i-N;
}
void update(int k,int x){
	k+=N;
	dat[k].first=x;
	while(k>1){
		k=(k-1)/2;
		dat[k]=max(dat[k*2],dat[k*2+1]);
	}
}
P query(int l,int r){
	P res=P(0,0);
	for(l+=N,r+=N;l<r;l>>=1,r>>=1){
		if(l&1)res=max(res,dat[l++]);
		if(r&1)res=max(res,dat[--r]);
	}
	return res;
}

ll a[6000],b[6000][300];
ll asum[6000];

imos2d<ll>sum;

void dfs(int l,int r){//[l,r]
	if(l>r)return;
	P p=query(l,r+1);
	sum.add(l,p.second,p.second,r,p.first);
	dfs(l,p.second-1);
	dfs(p.second+1,r);
}

int main(){
	int n,m;scanf("%d%d",&n,&m);
	rep(i,n-1){
		scanf("%lld",&a[i]);
		asum[i+1]=asum[i]+a[i];
	}
	rep(i,n)rep(j,m)scanf("%lld",&b[i][j]);
	sum=imos2d<ll>(n,n);
	init(n);
	rep(i,m){
		rep(j,n)update(j,b[j][i]);
		dfs(0,n-1);
	}
	ll Max=0;
	rep(i,n)for(int j=i;j<n;j++){
		Max=max(Max,sum.get(i,j)-(asum[j]-asum[i]));
	}
	cout<<Max<<endl;
}

Measured memory_bytes: 208384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

//最大公約数,最小公倍数
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a; }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

int main(void){
    ll n, k;
    cin >> n >> k;

    ll a[n];
    rep(i, 0, n){
        cin >> a[i];
    }

    ll gc = a[0];
    rep(i, 1, n){
        gc = gcd(gc, a[i]);
    }

    rep(i, 0, n){
        if(a[i] >= k){
            if((a[i] - k) % gc == 0){
                cout << "POSSIBLE" << endl;
                return 0;
            }
        }
    }
    cout << "IMPOSSIBLE" << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;


typedef long long i64;
const int inf = (int)1.05e9;


int main()
{
	int n, q;
	char str[1000005];
	vector<int> ks;

	scanf("%d%s", &n, str);
	scanf("%d", &q);
	ks.resize(q);
	for(int i = 0; i < q; ++i)
		scanf("%d", &ks[i]);

	for(int query_idx = 0; query_idx < q; ++query_idx) {

		int k = ks[query_idx];
		i64 ans = 0;

		i64 d2c_sum = 0;

		int d_num = 0, d_it = 0;
		int c_l = 0, c_r = 0, c_num = 0;

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

			char ch = str[it];

			if(ch == 'D') {

				while(c_l < it) {
					if(str[c_l] == 'C') {
						c_num -= 1;
					}
					c_l += 1;
				}
				while(c_r < min(it + k, n)) {
					if(str[c_r] == 'C') {
						c_num += 1;
					}
					c_r += 1;
				}

				d_num += 1;
				d2c_sum += c_num;
			}

			if(ch == 'M') {
				ans += d2c_sum;
			}

			if(ch == 'C') {

				while(d_it <= it - k) {
					if(str[d_it] == 'D') {
						d_num -= 1;
					}
					d_it += 1;
				}

				d2c_sum -= d_num;
			}
		}

		printf("%lld\n", ans);
	}

	return 0;
}

/* waffle */


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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    while (1) {
        int n;
        cin >> n;
        if (n == 0) break;
        vi w(n);
        rep(i, n) cin >> w[i];
        vector<vi> dp(n, vi(n, 0));
        for (int wi=2; wi<=n; ++wi) rep(l, n) {
            int r = l + wi - 1;
            if (r >= n) continue;
            if (abs(w[l]-w[r])<=1&&dp[l+1][r-1]==wi-2) dp[l][r] = wi;
            else {
                for (int k=l+1; k<=r; ++k) {
                    dp[l][r] = max(dp[l][r], dp[l][k-1]+dp[k][r]);
                }
            }
        }
        cout << dp[0][n-1] << endl;
    }
    return 0;
}



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

long long findNextPrime(long long n);   //given a number n, find the next closest prime number above n
bool isPrime(long long n);        //given a number n, determine if it is prime

int main()
{
    int input;
    cin >> input;

    cout << findNextPrime(input)  << endl;
}

//given a number n, find the next closest prime number above n
long long findNextPrime(long long n)
{
    long long nextPrime = n;
    bool found = false;

    //loop continuously until isPrime returns true for a number above n
    while (true)
    {
        if (isPrime(nextPrime)==true)break;
        nextPrime++;
    }

    return nextPrime;
}

//given a number n, determine if it is prime
bool isPrime(long long  n)
{
    if(n==2 || n==3)return true;
    for (long long i = 2; i<= n/2; i++)
    {
        if (n % i == 0)     //found a factor that isn't 1 or n, therefore not prime
            return false;
    }

    return true;
}


Measured memory_bytes: 256
def floor(y):
	f=1
	height=0
	while True:
		if y<height and y-height<5:
			return f
		else:
			f+=1
			height+=5

while True:
	try:
		v=float(input())
		y=v**2/(2*9.8)
		print(floor(y))
	except EOFError:
		break

Measured memory_bytes: 7488
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, m = map(int, readline().split())
ka = []
ans = set(str(i+1) for i in range(m))

for _ in range(n):
    ka = input().split()
    ans = ans & set(ka[1:])
    
print(len(ans))

Measured memory_bytes: 9244
#include<bits/stdc++.h>
using namespace std;
#define p pair<int,int>
int N, M;
char A[10];
int num[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
string dp[10010];

int main(){
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        cin >> A[i];
        if(dp[num[A[i] - '0']] == ""){
            dp[num[A[i] - '0']] = A[i];
        }else if(dp[num[A[i] - '0']][0] - '0' < A[i] - '0'){
            dp[num[A[i] - '0']] = A[i];
        }
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < M; j++){
            if(dp[i] == "") continue;
            string str1 = dp[i] + A[j];
            string& str2 = dp[i + num[A[j] - '0']];
            if(str2.size() < str1.size()){
                str2 = str1;
            } else if(str2.size() == str1.size() && str1 > str2){
                str2 = str1;
            }
        }
    }
    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 43648
//otoshodama
#include <iostream>
#include <string>
using namespace std;
int main(){
    int N, Y;
    cin >> N >> Y;

    int a,b,c;
    a = b = c = -1;
    //10000の枚数を全探索して残りは鶴亀
    for(int i=0; i<N+1; i++){
        int A = N - i;
        int B = Y - i*10000;
        int k = (A*5000-B)/4000;
        if((A*5000-B)%4000 != 0){continue;}
        int j = A-k;
        if(k>=0 && j>=0){
            a = i;
            b = j;
            c = k;
            break;
        }
    }
    cout << a << " " << b << " " << c <<"\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
const int maxn=1e5+7;
int cnt[maxn];
ll lcm(ll a,ll b)
{
    return a/__gcd(a,b)*b;
}
int main()
{
    int n,m;
    cin>>n>>m;
    vi a(n);
    for(int i=0;i<n;i++) cin>>a[i],a[i]/=2;
    sort(a.begin(),a.end());
    ll l=1;
    for(int i=0;i<n;i++)
    {
        int cur=a[i];
        while(cur%2==0)
        {
            cur/=2;
            cnt[i]++;
        }
        l=lcm(l,a[i]);
        if(i)
        {
            if(cnt[i]!=cnt[i-1]||l>m)
            {
                cout<<0<<'\n';
                exit(0);
            }
        }
    }
    cout<<((m/l)+1)/2<<'\n';

}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

ll dp[109][10];

void add(ll &x,ll y){
    x=(x+y)%MOD;
}

bool is(int bit,int i){
    return (bit&(1<<i));
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int H,W,K;
    cin>>H>>W>>K;
    
    dp[0][0]=1;
    rep(i,H)rep(j,W){
        rep(bit,pow(2,W-1)){
            bool f=false;
            rep(k,W-2)if(is(bit,k)&&is(bit,k+1)) f=true;
            if(f) continue;
            
            if(j<W-1&&is(bit,j)){
                add(dp[i+1][j+1],dp[i][j]);
            }else if(j>0&&is(bit,j-1)){
                add(dp[i+1][j-1],dp[i][j]);
            }else{
                add(dp[i+1][j],dp[i][j]);
            }
        }
    }
    cout1(dp[H][K-1])
}

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

void getToppings(int number);
int NumOfToppings;
int priceOfCrust = 1;
int priceOfTopiings;
int caloryCrust;
int caloryToppings[100];
double bestCalory;
int bestToppings = 0;
int n;
double bestCombo;
double tempCalory;
double tempBest;

int pop_max(){
    
    for(int i = 0; i < n-1; i++){
        if (caloryToppings[i] > caloryToppings[i+1])
            swap(caloryToppings[i], caloryToppings[i+1]);
    }

    n--;
    return caloryToppings[n];
}


int main(){
    //get info from a user.
    cin >> NumOfToppings;
    cin >> priceOfCrust;
    cin >> priceOfTopiings;
    cin >> caloryCrust;
    
    bestCalory= caloryCrust;
    
    for(int i = 0; i < NumOfToppings; i++)
        cin >> caloryToppings[i];
    
    n = NumOfToppings;

    int popedMax;
    bestCombo = bestCalory/priceOfCrust;
    
    for (int i = 0; i< NumOfToppings; i++){
        
        tempCalory = bestCalory + pop_max();
        popedMax = NumOfToppings - n;
        tempBest = tempCalory/(priceOfCrust + popedMax * priceOfTopiings);
        
        if(bestCombo < tempBest){
            bestCalory = tempCalory;
            bestCombo = tempBest;
        }else
            break;
    }
    
    cout << (int)bestCombo << endl;
}

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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const double eps = 1e-9;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, string s = "\n") { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ")
{ if (!v.size()) puts(""); rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }

int n, w, t;
vi u, v;

int dp[110][110][440];

int dfs(int i = 0, int cnt = 0, int sum = 0) {
  if (i == n) {
    return 0;
  }

  int &ret = dp[i][cnt][sum];
  if (~ret) return ret;

  ret = dfs(i + 1, cnt, sum);
  if (w - (cnt + 1) * t - (u[i] + sum) >= 0) {
    ret = max(ret, dfs(i + 1, cnt + 1, sum + u[i]) + v[i]);
  }

  return ret;
}

signed main() {
  cin >> n >> w;
  rep(i, n) {
    u.pb(in());
    v.pb(in());
  }

  t = u[0];
  rep(i, n) u[i] -= t;

  memset(dp, -1, sizeof(dp));
  
  cout << dfs() << endl;
}


Measured memory_bytes: 20992
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long LL;
LL vis[200001];
char s[200010];
int main() {
	scanf("%s",s);
	int len=strlen(s);
	for (int i=0;i<len;i++) vis[s[i]-97]++;
	LL ans=0;
	for (int i=0;i<26;i++)
		ans+=vis[i]*(len-vis[i]);
	ans/=2;
	ans++;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

string s;

int calc(char c) {
    int res = -1;
    for (int i = 0; i < s.size(); i++) {
        int j;
        for (j = i; j < s.size(); j++) {
            if (s[j] == c) {
                break;
            }
        }
        res = max(res, j - i);
    }
    return res;
}

int solve() {
    int res = inf;
    for (char c = 'a'; c <= 'z'; c++) {
        res = min(res, calc(c));
    }
    return res;
}

void input() {
    cin >> s;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


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

int partition(vector<int> &A, int p, int r){
  int x = A[r];
  int i = p-1;
  for(int j = p; j < r; j++){
    if(A[j] <= x){
      i++;
      swap(A[i], A[j]);
    }
  }
  swap(A[i+1], A[r]);
  return i+1;
}

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> A(n);
  for(int i = 0; i < n; i++) cin >> A[i];
  int idx = partition(A, 0, n-1);
  for(int i = 0; i < n; i++){
    if(i == idx) cout << "[" << A[i] << "]";
    else cout << A[i];
    if(i == n-1) cout << '\n';
    else cout << ' ';
  }
}

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

using ll = long long;
// #define int long long
using P = pair<int, int>;
using PP = pair<P,int>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))

/***** MAIN *****/
signed main() {
  int n;
  cin >> n;
  vector<PP> v(n);
  PP base;
  REP(i,n) {
    int x, y, h;
    cin >> x >> y >> h;
    v[i] = PP(P(x,y),h);
    if(h > 0) base = v[i];
  }
  REP(y,101) {
    REP(x,101) {
      int base_height = base.second + abs(base.first.first - x) + abs(base.first.second - y);
      bool flag = true;
      REP(i,n) {
        PP tmp = v[i];
        int tmp_height = base_height - abs(x-tmp.first.first) - abs(y-tmp.first.second);
        tmp_height = max(tmp_height, 0);
        if(tmp_height != tmp.second) {
          flag = false;
          break;
        }
      }
      if(flag) {
        COUTS(x); COUTS(y); COUTB(base_height);
        return 0;
      }
    }
  }
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 256
object Main extends App {
  val in = scala.io.Source.stdin.getLines.toSeq
  val ls = in.head //in.map(_.split(' ').map(_.toInt).toIndexedSeq).head
  val S = ls
  //println(S)
  val c0 = S.count(_ == '0')
  val c1 = S.size - c0
  val ret = Math.min(c0, c1) * 2
  println(ret)
}


Measured memory_bytes: 27396