akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

struct WeightedUnionFind {
    //各要素が属する集合の代表(根)を管理する
    //もし、要素xが根であればdata[x]は負の値を取り、-data[x]はxが属する集合の大きさに等しい
    vector<int> data;
    vector<int> diff_weight;

    WeightedUnionFind(int sz) : data(sz, -1), diff_weight(sz, 0) {}

    // weight(y) - weight(x) = w となるように merge する
    bool unite(int x, int y, int w) {
        w += weight(x);
        w -= weight(y);
        x = find(x);
        y = find(y);
        bool is_union = (x != y);
        if (is_union) {
            if (data[x] > data[y]) {
                swap(x, y);
                w = -w;
            }
            data[x] += data[y];
            data[y] = x;
            diff_weight[y] = w;
        } else {
            if (diff(x, y) == w) return true;
        }
        return is_union;
    }

    int find(int x) {
        if (data[x] < 0) { //要素xが根である
            return x;
        } else {
            int par = data[x];
            data[x] = find(data[x]); //data[x]がxの属する集合の根でない場合、根になるよう更新される
            diff_weight[x] += diff_weight[par];
            return data[x];
        }
    }

    int weight(int x) {
        find(x);
        return diff_weight[x];
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int diff(int x, int y) {
        return weight(y) - weight(x);
    }

    int size(int x) {
        return -data[find(x)];
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    WeightedUnionFind wuf(n);
    for (int i = 0; i < q; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        x--; y--;
        if (!wuf.unite(x, y, z)) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cctype>

#define div 1000000000+7

typedef long long ll;

using namespace std;


int main(){
    string o, e;
    string result;
    cin >> e >> o;
    for(int i = 0; i < o.size()+e.size(); i++){
        if(i % 2 == 1){
            result += o[(i-1)/2];
        }else {
            result += e[i/2];
        }
    }
    cout << result << endl;
}

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


using namespace std ;

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

queue<int> q ;
vector<long long> vect;

   
for( int i = 1 ; i < 10 ; i ++ ) { 
	q.push(i) ; 
	vect.push_back(i) ; 
}
if ( k < 10 ) {
	cout << vect[k-1] << endl ; 
	return 0 ; }
int z =  k ; 
k-= 9 ;
 
while (k != 0 ) {
	long long x = q.front() ; 
	q.pop() ; 
	if(  x % 10 != 0 ){
		long long y =  (10*x) + (x%10)-1 ; 
		q.push(y);
		vect.push_back(y) ; 
		k-- ;  
	}
	if ( k == 0 ) 
		break ; 
	long long y = (10*x) + (x%10) ; 
	q.push(y) ; 
	vect.push_back(y) ; 
	k-- ; 
	if ( k == 0 ) 
		break ; 
	if ( x % 10 != 9 ) {
		y = (10*x) + (x%10)+1 ; 
		q.push(y) ; 
		vect.push_back(y) ;
		k-- ; 
	}
}
cout << vect[z-1] << endl ; 
	
}


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

using namespace std;

struct point {
    int left, right, block, id;
};

bool cmp(const point &lhs, const point &rhs) {
    if (lhs.block < rhs.block)
        return true;
    else if (lhs.block > rhs.block)
        return false;
    else
        return lhs.right < rhs.right;
}

int main(){
    int n, q;
    scanf("%d", &n);
    cin >> q;
    vector<int> A(n);
    for (int i = 0; i < n; i++)
        scanf("%d", &A[i]);

    int block_size = 707;

    vector<point> query(q);
    for (int i = 0; i < q; i++) {
        scanf("%d %d", &query[i].left, &query[i].right);
        query[i].left--, query[i].right--;
        query[i].block = query[i].left / block_size;
        query[i].id = i;
    }

    sort(query.begin(), query.end(), cmp);

    vector<int> solution(q);
    vector<int> hash(1000100);

    int left = 0, right = 0, answer = 1;
    hash[A[0]] = 1;

    for (const point &task : query) {
        while (left < task.left) {
            hash[A[left]]--;
            answer -= (hash[A[left]] == 0);
            left++;
        }
        while (left > task.left) {
            left--;
            hash[A[left]]++;
            answer += (hash[A[left]] == 1);
        }
        while (right < task.right) {
            right++;
            hash[A[right]]++;
            answer += (hash[A[right]] == 1);
        }
        while (right > task.right) {
            hash[A[right]]--;
            answer -= (hash[A[right]] == 0);
            right--;
        }
        solution[task.id] = answer;
    }

    for (int answer : solution)
        printf("%d\n", answer);

    return 0;
}


Measured memory_bytes: 19300
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1<<29;
const ll LINF = 1LL<<58;
const int mod = 1000000007;

int main(){
    int n, m;
    cin >> n >> m;
    int used[100010] = {0};
    for(int i = 0; i < m; i++){
        int a;
        cin >> a;
        used[a] = 1;
    }
    int dp[100010] = {0};
    dp[0] = 1;
    for(int i = 0; i < n; i++){
        if(used[i]) continue;
        dp[i+1] += dp[i] % mod;
        dp[i+2] += dp[i] % mod;
    }
    cout << dp[n] % mod << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <cmath>
#include <vector>
using namespace std;
#define pi M_PI

int main(){
    string a;
    cin >> a;
    
    if(a.at(0) == '9' || a.at(1) == '9'){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
    
    return 0;
}

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

long long a, b, c, k;

int main() {
    ios::sync_with_stdio(false);
    cin >> a >> b >> c;
    cin >> k;
    cout << ((k & 1) ? (b - a) : (a - b)) << endl;
    return 0;
}

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

using namespace std;

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

Measured memory_bytes: 888
#include<stdio.h>
#include<stdlib.h>
#define ll long long
//suffix arrayのO(NlogN)構築
int*makeSA(char*s,int len){
	len++;
	int*SAidx=calloc(len,sizeof(int));
	int*ord=calloc(len,sizeof(int));
	//1文字目
	int cnt1[256]={},cnt2[256]={};
	for(int i=0;i<len;i++)cnt1[s[i]+1]++,cnt2[s[i]+1]|=1;
	for(int i=1;i<256;i++)cnt1[i]+=cnt1[i-1],cnt2[i]+=cnt2[i-1];
	for(int i=0;i<len;i++)SAidx[cnt1[s[i]]++]=i,ord[i]=cnt2[s[i]];
	
	int*cnt=calloc(len+1,sizeof(int));
	int*idx2=calloc(len,sizeof(int));
	int*temp=calloc(len,sizeof(int));
	for(int k=1;k<len;k*=2){
		//2*k文字まで見る
		for(int i=0;i<len;i++)cnt[i]=0;
		for(int i=0;i<len;i++)cnt[ord[i]+1]++;
		for(int i=1;i<len;i++)cnt[i]+=cnt[i-1];
		for(int i=0;i<len;i++)idx2[cnt[ord[(SAidx[i]-k+len)%len]]++]=(SAidx[i]-k+len)%len;
		temp[idx2[0]]=0;
		for(int i=1;i<len;i++)temp[idx2[i]]=temp[idx2[i-1]]+(ord[idx2[i-1]]!=ord[idx2[i]]||ord[(idx2[i-1]+k)%len]!=ord[(idx2[i]+k)%len]);
		for(int i=0;i<len;i++)ord[i]=temp[i],SAidx[i]=idx2[i];
	}
	free(temp);
	free(idx2);
	free(cnt);
	free(ord);
	return SAidx+1;
}

char s[100010];
ll cnt[100010];
ll wei[100010];
int main(){
	ll n,k;
	scanf("%lld%lld %s",&n,&k,s);
	k--;
	ll crr=0;
	for(int i=0;i<n;i++){
		cnt[n-i]+=cnt[n-i+1];
		if(s[i]=='0'){
			cnt[0]+=crr+1;
			crr++;
		}else{
			cnt[n-i]+=crr+1;
			wei[i]=crr+1;
			crr=0;
		}
	}
	
	int keta=0;
	while(k>=cnt[keta])k-=cnt[keta++];
	if(keta==0){
		puts("0");
		return 0;
	}
	//keta桁で、小さい方からk番目
	int*p=makeSA(s,n);

	for(int i=0;i<n;i++){
		if(p[i]+keta<=n){
			k-=wei[p[i]];
			if(k<0){
				for(int j=0;j<keta;j++)putchar(s[p[i]+j]);puts("");
				return 0;
			}
		}
	}
}


Measured memory_bytes: 4976
N = int(input())
# 4/n = 1/h+1/n+1/w
for h in range(1,3501):
  for n in range(h,3501):
    w1 = N*h*n
    w2 = 4*h*n-N*n-N*h
    if w2 == 0:
      continue
    if w1%w2 == 0:
      w = w1//w2
      if w > 0:
        print(h,n,w)
        exit()

Measured memory_bytes: 9144
#include<stdio.h>

int main(){

  int i,n,u,x,y,k,v[101][101],M[101][101];

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    for(x=1;x<=n;x++){
      M[i][x]=0;
    }
  }
  
  for(i=1;i<=n;i++){
    scanf("%d%d%",&u,&k);
    for(x=1;x<=k;x++){
      scanf("%d",&v[i][x]);
      for(y=1;y<=n;y++){
	if(v[i][x]==y)M[i][y]=1;
      }
    }
  }
  
    for(i=1;i<=n;i++){
    for(x=1;x<=n;x++){
      if(x==1){
 printf("%d",M[i][x]);
    }
      else printf(" %d",M[i][x]);
   
    }
    printf("\n");
  }

    return 0;

}



Measured memory_bytes: 2044
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF INT32_MAX / 2
#define PIE 3.14159265358979323

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;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

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

template <class T>
struct UnionFind {
    vector<T> parent;
    vector<T> rank;
    vector<T> size_of;

    UnionFind(T n) : parent(n), rank(n), size_of(n) {
        for (T i = 0; i < n; i++) {
            parent[i] = i;
            rank[i] = 0;
            size_of[i] = 1;
        }
    }

    T root(T x) {
        return parent[x] == x ? x : parent[x] = root(parent[x]);
    }

    bool same(T x, T y) {
        return root(x) == root(y);
    }

    T size(T x) {
        return size_of[root(x)];
    }

    void unite(T x, T y) {
        x = root(x);
        y = root(y);
        if (x == y)
            return;
        if (rank[x] < rank[y]) {
            size_of[y] += size_of[x];
            parent[x] = y;
        }
        else {
            size_of[x] += size_of[y];
            parent[y] = x;
            if (rank[x] == rank[y])
                rank[x]++;
        }
        return;
    }
};

signed main() {
    int n, q, t, u, v;
    cin >> n >> q;
    UnionFind<int> uf(n);
    while (q--) {
        cin >> t >> u >> v;
        if (!t)
            uf.unite(u, v);
        else
            cout << uf.same(u, v) << endl;
    }
}

Measured memory_bytes: 5476
#include<bits/stdc++.h>
#define bye return 0
#define Yes cout << "Yes" << "\n"
#define No  cout << "No" << "\n"
#define YES cout << "YES" << "\n"
#define NO cout << "NO" << "\n"
#define endl cout << "\n"
using namespace std;
int main(){
	ios::sync_with_stdio(false);
    cin.tie(NULL);
    vector<int> v;
    set<int> s;
    int t, a, b, c, cnt=0;
    double d, d1, d2;
    vector < vector<string> > v1;
    string s1, s2;
    cin >> a >> b;
    cout << (a*a) - b << "\n";
    bye;
}

Measured memory_bytes: 256
import sys

def height(a, b, c, d, e):
    return abs(a-d)+abs(b-e)+c

n = int(input())
hint = []
q = 0
for i in range(n):
    a, b, c = map(int, input().split())
    hint.append([c, a, b])
hint.sort(reverse=True)

for i in range(101):
    for j in range(101):
        frag = True
        H = height(hint[0][1], hint[0][2], hint[0][0], i, j)
        for h in hint[1:]:
            if h[0] != max(-abs(h[1]-i)-abs(h[2]-j)+H,0):
                frag = False
                break
        if frag:
            print(i, j, H)
            sys.exit()

Measured memory_bytes: 3064
/*
考虑两个端点都在边界上的线段，如果它们不相交，那么对于剩下的线段一定可以找到一种合法的连接方式使得两两线段不交
所以只要考虑两个端点都在边界上的线段是否相交。把矩形看成一个环，从一点出发按照顺时针的方向标号，直接判断即可
*/

#include <cstdio>
#include <algorithm>

using namespace std;
const int Max_N(100050);

struct line
{
	int x, y;
	void give(int _x, int _y)
	{
		x = _x, y = _y;
	}
};
int R, C, N, M;
line V[Max_N];

inline int getpos(int x, int y)
{
	if (x == 0)
		return y;
	if (y == C)
		return C + x;
	if (x == R)
		return C + R + (C - y);
	if (y == 0)
		return C + R + C + (R - x);
	return -1;
}

#define LCH (segt[cur].lch)
#define RCH (segt[cur].rch)
#define MAX (segt[cur].Max)

struct node
{
	int lch, rch, Max;
};
int tot, root;
node segt[Max_N * 30];

void insert(int &cur, int pos, int v, int LEFT = 1, int RIGHT = 1000000000)
{
	if (!cur)
		segt[++tot] = segt[cur], cur = tot;
	MAX = max(MAX, v);
	if (LEFT == RIGHT)
		return;
	int MID = LEFT + ((RIGHT - LEFT) >> 1);
	pos <= MID ? insert(LCH, pos, v, LEFT, MID) : insert(RCH, pos, v, MID + 1, RIGHT);
}

int query(int cur, int l, int r, int LEFT = 1, int RIGHT = 1000000000)
{
	if (!cur)
		return -1;
	if (LEFT == l && RIGHT == r)
		return MAX;
	int MID = LEFT + ((RIGHT - LEFT) >> 1);
	if (r <= MID)
		return query(LCH, l, r, LEFT, MID);
	else
		if (l > MID)
			return query(RCH, l, r, MID + 1, RIGHT);
		else
			return max(query(LCH, l, MID, LEFT, MID), query(RCH, MID + 1, r, MID + 1, RIGHT));
}

int main()
{
	scanf("%d%d%d", &R, &C, &M);
	for (int x1, y1, x2, y2;M--;)
	{
		scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
		V[++N].give(getpos(x1, y1), getpos(x2, y2));
		if (V[N].x == -1 || V[N].y == -1)
			--N;
		else
		{
			if (V[N].x > V[N].y)
				swap(V[N].x, V[N].y);
			insert(root, V[N].x, V[N].y);
		}
	}
	for (int i = 1;i <= N;++i)
		if (V[i].x + 1 <= V[i].y - 1 && query(root, V[i].x + 1, V[i].y - 1) > V[i].y)
		{
			puts("NO");
			return 0;
		}
	puts("YES");
	return 0;
}

Measured memory_bytes: 15232
#include <cstdio>
#include <vector>
using namespace std;

int N, K, L;
int p, q, r, s;
vector<vector<int> > G1(200010);
vector<vector<int> > G2(200010);
int fa1[200010], fa2[200010];
int res[200010];
vector<vector<int> > GG1(200010);
vector<vector<int> > GG2(200010);

void dfs1(int u, int f)
{
	int i;
	int v;
	for(i=0; i<G1[u].size(); i++){
		v = G1[u][i];
		if(fa1[v] == -1){
			fa1[v] = f;
			dfs1(v, f);
		}
	}
}

void dfs2(int u, int f)
{
	int i;
	int v;
	for(i=0; i<G2[u].size(); i++){
		v = G2[u][i];
		if(fa2[v] == -1){
			fa2[v] = f;
			dfs2(v, f);
		}
	}
}

int main()
{
	//freopen("in.txt", "r", stdin);
	int i, j;
	scanf("%d %d %d", &N, &K, &L);
	for(i=0; i<K; i++){
		scanf("%d%d", &p, &q);
		p--, q--;
		G1[p].push_back(q);
		G1[q].push_back(p);
	}
	for(i=0; i<L; i++){
		scanf("%d%d", &r, &s);
		r--, s--;
		G2[r].push_back(s);
		G2[s].push_back(r);
	}
	for(i=0; i<N; i++){
		fa1[i] = -1;
		fa2[i] = -1;
	}
	for(i=0; i<N; i++){
		if(fa1[i] == -1){
			fa1[i] = i;///
			dfs1(i, i);
		}
	}
	for(i=0; i<N; i++){
		if(fa2[i] == -1){
			fa2[i] = i;
			dfs2(i, i);
		}
	}
	for(i=0; i<N; i++){
		//if(fa1[i] != i)
			GG1[fa1[i]].push_back(i);
	}
	for(i=0; i<N; i++){
		//if(fa2[i] != i)
			GG2[fa2[i]].push_back(i);
	}
	for(i=0; i<N; i++)
		res[i] = -1;
	for(i=0; i<N; i++){
		if(res[i] == -1){
			int f1 = fa1[i];
			int f2 = fa2[i];
			int ans = 0;
			if(GG1[f1].size() < GG2[f2].size() ){
				for(j=0; j<GG1[f1].size(); j++){
					int v = GG1[f1][j];
					if(fa2[v] == f2)
						ans ++;
				}
			}
			else{
				for(j=0; j<GG2[f2].size(); j++){
					int v = GG2[f2][j];
					if(fa1[v] == f1)
						ans ++;
				}
			}
			
			if(GG1[f1].size() < GG2[f2].size() ){
				for(j=0; j<GG1[f1].size(); j++){
					int v = GG1[f1][j];
					if(fa2[v] == f2)
						res[v] = ans;
				}
			}
			else{
				for(j=0; j<GG2[f2].size(); j++){
					int v = GG2[f2][j];
					if(fa1[v] == f1)
						res[v] = ans;
				}
			}
			/*for(j=0; j<GG1[f1].size(); j++){
				int v = GG1[f1][j];
				if(fa2[v] == f2)
					ans ++;
			}
			for(j=0; j<GG2[f2].size(); j++){
				int v = GG2[f2][j];
				if(fa1[v] == f1)
					res[v] = ans;
			}*/
			res[i] = ans;
		}
	}
	printf("%d", res[0]);
	for(i=1; i<N; i++)
		printf(" %d", res[i]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 35712
#include <iostream>

using namespace std;

int main() {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << x2 + y1 - y2
        << " " << y2 + x2 - x1
        << " " << x1 + y1 - y2
        << " " << y1 + x2 - x1
        << endl;
}


Measured memory_bytes: 256
S = input()
num = len(S) - 1
sum = 0

for i in range(2**num):
  k = 0
  for j in range(num):
    if ((i >> j) & 1):
      sum += int(S[k:j+1])
      k = j + 1
  sum += int(S[k:])

print(sum)

Measured memory_bytes: 3060
#include <cstdlib>
#include <iostream>


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

  int r, g, b;
  std::cin >> r >> g >> b;

  std::cout << ((r * 100 + g * 10 + b) % 4 == 0 ? "YES" : "NO") << std::endl;

  return EXIT_SUCCESS;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,M = IL()

data = [0]*N
for i in range(M):
  a,b = IL()
  if a == 1:
    if data[b]==1:
      print("POSSIBLE")
      break
    else:
      data[b]=1
  if b == N:
    if data[a]==1:
      print("POSSIBLE")
      break
    else:
      data[a]=1
else:
  print("IMPOSSIBLE")

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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


signed main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    vector<vector<int>> t(m, vector<int>(2, 0));
    map<int,int> ma;
    for(auto& x : a){
        cin >> x;
        ++ma[x];
    }
    for(auto& elm : ma){
        t[elm.first % m][0] += elm.second;
        t[elm.first % m][1] += elm.second & ~1;
    }
    int ans = 0;
    for(int i = 0; i < (m + 2) / 2; ++i){
        int j = m - i;
        if(!i || i == j){
            ans += t[i][0] / 2;
        }else{
            int mi = min(t[i][0], t[j][0]);
            ans += mi;
            t[i][1] = min(t[i][1], t[i][0] - mi);
            t[j][1] = min(t[j][1], t[j][0] - mi);
            ans += t[i][1] / 2;
            ans += t[j][1] / 2;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 10752
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  if (b <= 0 && d <= 0)
    cout << a * c << endl;
  else if (a >= 0 && c >= 0)
    cout << b * d << endl;
  else if (b <= 0 && c >= 0)
    cout << b * c << endl;
  else if (d <= 0 && a >= 0)
    cout << a * d << endl;
  else
    cout << max(a * c, b * d) << endl;
  return 0;
}

Measured memory_bytes: 3668
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long lli;
typedef pair<int, int> pii;
const int maxn = 55;
int n;
int d[maxn], cnt[maxn];
vector<int> vec, can_rev;

void read_input()
{
    cin >> n;
    ++cnt[0];
    for(int i = 0; i < n; ++i)
    {
        cin >> d[i];
        ++cnt[d[i]];
    }
}

int bit(int k, int x)
{
    return (x >> k & 1);
}

inline int time_gap(int x, int y)
{
    if(x < y) swap(x, y);
    return min(x - y, 24 - x + y);
}

int min_gap(vector<int>&v)
{
    int res = maxn;
    for(int i = 0; i < (int)v.size(); ++i)
        for(int j = i + 1; j < (int)v.size(); ++j)
            res = min(res, time_gap(v[i], v[j]));
    return res;
}

void solve()
{
    for(int i = 0; i <= 12; ++i)
        if(cnt[i] >= 3 || ((i == 0 || i == 12) && cnt[i] >= 2))
        {
            cout << "0\n";
            return;
        }
    for(int i = 1; i < 12; ++i)
    {
        if(cnt[i] == 2)
        {
            vec.push_back(i);
            vec.push_back(24 - i);
        }
        else if(cnt[i] == 1)
            can_rev.push_back(i);
    }
    if(cnt[12] > 0) vec.push_back(12);
    vec.push_back(0);

    int ans = 0;
    for(int mask = 0; mask < (1 << (int)can_rev.size()); ++mask)
    {
        vector<int> all = vec;
        for(int i = 0; i < (int)can_rev.size(); ++i)
            all.push_back(bit(i, mask) ? 24 - can_rev[i] : can_rev[i]);
        ans = max(ans, min_gap(all));
    }
    cout << ans << '\n';
}

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


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int i = 0;
		int sum = 0;
		
		while(sum < X){
			i++;
			sum += i;
		}
		
		System.out.println(i);

	}

}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int N;
  cin >> N;
  vector<P> A(N);
  REP(i, N) { cin >> A[i].second >> A[i].first; }
  sort(A.begin(), A.end());
  ll now = 0;
  bool ok = true;
  REP(i, N) {
    now += A[i].second;
    if (A[i].first < now) {
      ok = false;
    }
  }
  printf(ok ? "Yes" : "No");
  cout << "\n";
}

Measured memory_bytes: 4760
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using ll = long long;
using namespace std;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int A,B,C;
int main(){
    cin >> A >> B >> C;
    if(A + B >= C) pr(yes);
    else pr(no);
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 1ll<<61;
const long double pi = 3.1415926535897932384626433;
typedef pair<int, int> P;
typedef pair<int, P> PP;
struct edge { int to, cost; };

int a[200006], b[200006];

signed main() {
	int n; cin >> n;
	rep(i, n)cin >> a[i];
	rep(i, n)cin >> b[i];
	int ans = 0;

	rep(i, 30) {
		int bit = 0;
		int X = 1ll << (i + 1);
		vector<int>va, vb;
		rep(j, n) va.push_back(a[j] % X);
		rep(j, n)vb.push_back(b[j] % X);
		sort(va.begin(), va.end());
		sort(vb.begin(), vb.end());
		rep(j, n) {
			if (i) {
				int si, sj, ti, tj;
				si = 1ll << i;
				sj = si * 2 - 1;
				ti = si * 3;
				tj = si * 4 - 1;
				si -= va[j];
				sj -= va[j];
				ti -= va[j];
				tj -= va[j];
				bit += upper_bound(vb.begin(), vb.end(), sj) - lower_bound(vb.begin(), vb.end(), si);
				bit += upper_bound(vb.begin(), vb.end(), tj) - lower_bound(vb.begin(), vb.end(), ti);
			}
			else {
				int si = 1;
				si -= va[j];
				bit += upper_bound(vb.begin(), vb.end(), si) - lower_bound(vb.begin(), vb.end(), si);
			}
		}
		if (bit & 1)ans += 1 << i;
	}
	cout << ans << endl;
}

Measured memory_bytes: 8568
n = int(input())
a = list(map(int, input().split()))
ans = "APPROVED"
for i in a:
    if i % 2 == 0:
        if i % 3 == 0 or i % 5 == 0:
            continue
        else:
            ans = "DENIED"
            break
    if ans == "DENIED":
        break

print(ans)

Measured memory_bytes: 38356
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) {

        try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {
            int n = Integer.parseInt(in.readLine());
            int x;

            StringBuilder sb = new StringBuilder();

            for (int i = 1; i <= n; i++) {
                x = i;

                if (x % 3 == 0) {
                    sb.append(" ").append(i);
                    continue;
                }

                do {
                    if (x % 10 == 3) {
                        sb.append(" ").append(i);
                        break;
                    }
                    x /= 10;
                } while (x != 0);
            }

            System.out.println(sb);
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.exit(0);
    }
}



Measured memory_bytes: 25356
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<sstream>
#include<cmath>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n-1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
#define RALL(a) rbegin(a),rend(a)
typedef long long int ll;
typedef long double ld;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
int main(void) {
    string s; int k; cin >> s >> k;
    int dp[110][2][4],n = s.size();
    Fill(dp, 0);
    dp[0][0][0] = 1;
    rep(i, n) {
        rep(j, 2) {
            rep(l, 4) {
                int nm = s[i] - '0';
                rep(d, 10) {
                    int nl = l,nj = j;
                    if (d!=0) nl++;
                    if (nl > k)continue;
                    if (nj == 0) {
                        if (nm < d) continue;
                        if (nm > d) nj = 1;
                    }dp[i + 1][nj][nl] += dp[i][j][l];
                }
            }
        }
    }cout << dp[n][0][k] + dp[n][1][k] << endl;
}

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

ll f[105];

int main() {
  ll N;
  scanf("%lld", &N);

  vector<ll> goal(N);
  for (ll i = 0; i < N; i++) {
    ll v;
    scanf("%lld", &v);
    goal[i] = v;
  }

  ll count = 0;
  for (;;) {
    ll start = -1;
    ll end = -1;
    for (ll i = 0; i < N; i++) {
      if (start == -1) {
        if (f[i] < goal[i]) {
          start = i;
        }
      } else {
        if (f[i] >= goal[i]) {
          end = i - 1;
          break;
        }
      }
    }
    if (start == -1) {
      break;
    }
    if (end == -1) {
      end = N - 1;
    }
    for (ll i = start; i <= end; i++) {
      f[i]++;
    }
    count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
struct V {
	int a[2];
	int depth;
	V() {
		for (int i = 0; i < 2; i++) {
			a[i] = -1;
		}
	}
};
vector<V> vs;
vector<string> ss;
int g = 0;
int N, L;
map<int, int> mp;
int dfs(int k) {
	int c = 0;
	for (int i = 0; i < 2; i++) {
		if (vs[k].a[i] != -1) {
			c++;
			dfs(vs[k].a[i]);
		}
	}
	if (c == 1) {

		c = L - vs[k].depth;
		//cerr << c << endl;
		int t = 1;
		while (c % 2 == 0) {
			c /= 2;
			t++;
		}
		g ^= t;


	}
}

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

	V tmp;

	for (int i = 0; i < 2; i++) {
		tmp.a[i] = -1;
	}


	cin >> N >> L;
	ss.clear();
	ss.resize(N);
	for (int i = 0; i < N; i++) {
		cin >> ss[i];
	}
	int cur;
	vs.clear();
	vs.push_back(tmp);
	vs[0].depth = 0;
	for (int i = 0; i < N; i++) {
		cur = 0;
		for (int j = 0; j < ss[i].size(); j++) {
			if (vs[cur].a[(int)(ss[i][j] - '0')] == -1) {
				vs[cur].a[(int)(ss[i][j] - '0')] = (int)vs.size();
				tmp.depth = j + 1;
				cur = (int)vs.size();
				vs.push_back(tmp);
			}
			else {
				cur = vs[cur].a[(int)(ss[i][j] - '0')];
			}
		}
	}
	mp.clear();
	dfs(0);

	string res = "Bob";
	if (g != 0) {
		res = "Alice";

	}
	cout << res << endl;
}

Measured memory_bytes: 5952
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const ll powll = 1LL<<1;

int main(){
  string s; cin >> s;
  int i = 0;
  while(i < s.size()){
    if(s[i] == 'h' && s[i+1] == 'i'){
      i+=2;
    }else{
      break;
    }
  }
  if(i == s.size()) cout << "Yes\n";
  else cout << "No\n";
}

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

int main(){

long long int n,i,k=0,j,sum=0;
cin>>n;
k=n-1;
long long int a[n];
for(i=1;i<=n;i++)
{
    cin>>a[i];
}
sort(a+1,a+1+n);
sum=sum+a[n];
k--;
for(i=n-1;i>=1;i--)
{
    if(k==0)
    {
        break;
    }
    else if(k>=2)
    {
        sum=sum+(a[i]*2);
        k=k-2;
    }
    else
    {
        sum=sum+a[i];
        break;
    }
}

cout<<sum;

return 0;


}




Measured memory_bytes: 5176
import java.util.*;
public class Main {
	 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int d, tptn = 0;
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] p = new int[n];
        int[][] pattern = new int[n][6];
        for(int i = 0; i < k; i++) {
            d = sc.nextInt();
            p[d-1] = sc.nextInt();
            }
        if(p[0] == 0) {
            for(int i = 0; i < 3; i++) pattern[0][i] = 1;
        }
        else pattern[0][p[0]-1] = 1;
         
        for(int i= 1; i < n; i++) {
            for(int h = 0; h < 6; h++) tptn += pattern[i-1][h]%10000;
 
                if(p[i] == 0) {
                    for(int j = 0; j < 6; j++) {
                    if(j<3) pattern[i][j] = (tptn-pattern[i-1][j]-pattern[i-1][j+3])%10000;
                    else pattern[i][j] = pattern[i-1][j-3];
                    }
                }
                    else {
                        pattern[i][p[i]-1] = (tptn-pattern[i-1][p[i]-1]-pattern[i-1][p[i]+2])%10000;
                        pattern[i][p[i]+2] = pattern[i-1][p[i]-1];
                 
                }
                tptn = 0;
                if(i == n - 1) for(int h = 0; h < 6; h++) tptn += pattern[n-1][h]%10000;
        }
        System.out.println(tptn % 10000);
    }
}

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

using namespace std;
using ll = long long;

template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_V(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_M(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}

int main() {
    int n;
    cin>>n;
    V<pair<int, int>> t(n); // 締め切り, cost
    for (int i = 0; i < n; ++i) {
        int a, b;
        cin>>a>>b;
        t[i]={b, a};
    }
    sort(t.begin(), t.end());

    bool flg = true;
    ll time = 0;
    for (int i = 0; i < n; ++i) {
        time+=t[i].second;
        flg &= (time<=t[i].first);
    }

    if(flg){
        puts("Yes");
    }else{
        puts("No");
    }

    return 0;
}

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

int main(){
    
    int h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    
    int tmp1,tmp2;
    /*
    if(k>=60){
        tmp1=k/60;
    }
    h2=h2-tmp1;
    if(k>m2){
        k=k-m2;
        m2=60;
    }
    m2=m2-k;
    */
    tmp1=(h2*60+m2)-k;
    tmp2=tmp1-(h1*60+m1);
    cout<<tmp2<<"\n";
    
    return 0;
}

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

vector<vector<pair<int,int>>> x;
 
bool judge(int bit, int p){
  rep(i,x[p].size()){
    if(x[p][i].second&&!(bit&1<<x[p][i].first)) return false;
    if(!(x[p][i].second)&&(bit&1<<x[p][i].first)) return false;
  }
  return true;
}

int main() {
  int n;
  cin>>n;
  x.resize(n);
  rep(i,n){
    int a;
    cin>>a;
    x[i].resize(a);
    rep(j,a){
      cin>>x[i][j].first>>x[i][j].second;
      x[i][j].first--;
    }
  }
  int ans = 0;
  rep(i,1<<n){
    bool flag = false;
    int res = 0;
    rep(j,n){
      if(i>>j&1){
        res++;
        if(!judge(i,j)){
          flag = true;
          break;
        }
      }
    }
    if(flag) continue;
    ans = max(ans,res);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define MKP make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int gcd(int a,int b)
{
	return b==0?a:gcd(b,a%b);
}

int fpow(int a,int b,int m)
{
	if(b==0) return 1;
	if(b==1) return a;
	int tmp=fpow(a,b/2,m);
	if(b%2) return a*tmp%m*tmp%m;
	return tmp*tmp%m;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int a,b,c,d,e;
	cin>>a>>b>>c>>d>>e;
	int n; cin>>n;
	if(e-a>n) cout<<":(\n";
	else cout<<"Yay!\n";
	return 0;
}









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




int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  ll a,b,c,k,n,temp,count=0,ans;
  string s;
 // ll arr[n];
  cin>>a>>b>>c;
  cout<<c<<" "<<a<<" "<<b<<endl;
return 0;
}

Measured memory_bytes: 764
import Control.Monad
import Control.Monad.ST
import qualified Data.Array as A
import qualified Data.Array.ST as ST
import qualified Data.Array.Unboxed as AU
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.Int
import qualified Data.IntMap as IM
import Data.List
import qualified Data.Map as M
import Data.Maybe
import Data.Ord
import qualified Data.Set as S
import Data.Time
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

main = do
  [n, k] <- readInt
  a <- readInt
  print $ solve n k a

solve n k a = 1 + m (n - k) (k - 1)
  where
    b = takeWhile (/= 1) a
    c = tail $ dropWhile (/= 1) a
    b' = m (length b) (k - 1)
    c' = m (length c) (k - 1)

m a x
  | a `mod` x == 0 = a `div` x
  | otherwise = a `div` x + 1


Measured memory_bytes: 1660
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

const long long MOD = (long long)1e9 + 7;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int n, k;
vector<vector<int>> e;
vector<int> p;
vector<ll> x;

void dfs(int t){
    int q = k - 1;
    if(p[t] != -1) q--;
    for(auto&& i : e[t]){
        if(i == p[t]) continue;
        p[i] = t;
        x[i] = q;
        q--;
        dfs(i);
    }
}

int main(){
    cin >> n >> k;
    e = vector<vector<int>>(n);
    for(int i = 0; i < n - 1; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    p = vector<int>(n);
    x = vector<ll>(n);
    p[0] = -1;
    x[0] = k;
    dfs(0);
    ll ans = 1;
    for(int i = 0; i < n; i++){
        ans *= x[i];
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10368
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

signed main(){
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n,k,s,t;cin >> n >> k >> s >> t;
    vector<ll> b(n);REP(i,n)cin >> b[i];
    vector<ll> a;
    REP(i,n){
        bool f=true;
        REP(j,18){
            if((s>>j)&1 and !((b[i]>>j)&1)){
                f=false;break;
            }
            if(!((t>>j)&1) and (b[i]>>j)&1){
                f=false;break;
            }
        }
        if(f)a.PB(b[i]);
    }
    n=SIZE(a);
    k=min(n,k);
    //cout << n << endl;
    //cout << n << endl;
    //unordered_mapはpairをキーにできない
    //dp_subを用意すると遅い(用意しないだけで数倍変わる)
    //逆順にやればOK
    vector<map<pair<ll,ll>,ll>> dp(k);
    REP(i,n){
        FORD(j,k-2,0){
            for(auto l=dp[j].begin();l!=dp[j].end();l++){
                dp[j+1][MP((l->F.F)&a[i],(l->F.S)|a[i])]+=(l->S);
            }
        }
        dp[0][MP(a[i],a[i])]=1;
    }
    ll ans=0;
    REP(i,k)ans+=(dp[i][MP(s,t)]);
    cout << ans << endl;
}


Measured memory_bytes: 154052
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using System.IO.Pipes;
using System.ComponentModel;
using System.Drawing;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] Arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int N = Arr[0];
            int D = Arr[1];
            long dist = 0;
            long th = (long)Math.Pow(D,2);
            int ans = 0;


            for (int i = 0; i < N; i++) 
            {
                int[] Point = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                dist = (long)Math.Pow(Point[0], 2) + (long)Math.Pow(Point[1], 2);
                if (dist <= th) 
                {
                    ans++;
                }
            }

            Console.WriteLine(ans);

            return;
        }

    }
}


Measured memory_bytes: 41512
s = input()
t = input()
Ls = len(s)
Lt = len(t)

dp = [[0]*(Ls+1) for i in range(Lt+1)]
Lans = 0

for i in range(1,Lt+1):
  for j in range(1,Ls+1):
    if s[j-1] == t[i-1]:
      dp[i][j] = dp[i-1][j-1] + 1
    else:
      dp[i][j] = max(dp[i-1][j], dp[i][j-1])
    Lans = max(Lans,dp[i][j])
i = Lt
j = Ls
ans = [""]*Lans
count = 0
while Lans > 0:
  if dp[i][j] == dp[i-1][j]:
    i -= 1
  elif dp[i][j] == dp[i][j-1]:
    j -= 1
  else:
    ans[Lans-1] = s[j-1]
    i -= 1
    j -= 1
    Lans -= 1
print("".join(ans))

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

signed main(void)
{
	int n, x;
	long long cnt;
	cin >> n;
	vector<int> a(n);
	bool visited[n];

	rep(i, n)
	{
		cin >> a.at(i);
		a.at(i)--;
		visited[i] = false;
	}
	x = a[0];
	visited[0] = true;
	cnt = 1;
	rep(i, n)
	{
		if (x == 1)
		{
			cout << cnt << endl;
			break;
		}
		x = a[x];
		cnt++;
		if (visited[x])
		{
			cout << -1 << endl;
			break;
		}
		visited[x] = true;
	}
	return 0;
}


Measured memory_bytes: 768
// #define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  int n;
  scanf("%d", &n);
  vector<int64> a(n + 1);
  for (int i = 0; i <= n; ++i) {
    scanf("%lld", &a[i]);
  }
  vector<int64> bound(n + 1);
  bound[0] = 1 - a[0];
  bool found = bound[0] < 0;
  int64 L = 1e14;
  for (int i = 1; i <= n && !found; ++i) {
    bound[i] = min(bound[i - 1] * 2 - a[i], L);
    if (bound[i] < 0) found = true;
  }
  trace(bound);
  int64 ret = 0, sum = 0;
  for (int i = n; i >= 0; --i) {
    int64 cur = min(bound[i], sum) + a[i];
    ret += cur;
    sum += a[i];
  }
  if (found) {
    puts("-1");
  } else {
    printf("%lld\n", ret);
  }
  return 0;
}


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

int main() {
    int N;
    int64_t K;
    cin >> N >> K;
    
    vector<int> A(N+1);
    A.at(0) = 0;
    for (int i=1;i<N+1;i++) {
        cin >> A.at(i);
    }
    
    int x = 1; //start
    vector<int> B(1,x);
    map<int,int> S; //to find loop 
    int index = 1;
    
    while(true){
       x = A.at(x);
       if (S.count(x)) break;
       B.push_back(x);
       S[x] = index++;
    }
    int length = B.size();
    int loopb = S[x]; //index of beginning of loop 
    int loop = length - loopb; //length of loop 
    int ans;
    if (K < length) {
        ans = B.at(K);
    } else {
        ans = B.at((K-loopb)%loop + loopb);
    }
    cout << ans << endl;
    
}

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

int main(){
  int N; cin >> N; 
  vector<int> A(100010, 0);
  for(int i=1; i<=N; i++) cin >> A[i];

  int sum = 0;
  for(int i=1; i<=N+1; i++){
    sum += abs(A[i]-A[i-1]);
  }

  for(int i=1; i<=N; i++){
    if(A[i-1] <= A[i] && A[i] <= A[i+1]){
      cout << sum << endl;
    } else if (A[i-1] >= A[i] && A[i] >= A[i+1]){
      cout << sum << endl;
    } else {
      cout << sum - abs(A[i]-A[i-1]) - abs(A[i]-A[i+1]) + abs(A[i+1]-A[i-1]) << endl;
    }
  }

}


Measured memory_bytes: 1664
#include <iostream>
using namespace std;
int main()
{
	long int x;
	cin >> x;
	long int sum;
	
	long int xa = (x - (x / 10000) * 10000);
	long int xb = (xa - (xa / 1000) * 1000);
	long int xc = (xb - (xb / 100) * 100);
	long int xd = (xc - (xc / 10) * 10);
	
	sum =(x/10000)+ (xa / 1000) + (xb / 100) + (xc / 10) + xd;
	if (sum == 1)sum = 10;

	cout << sum;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
    sort(a,a+n);
  int c=0;
  for(int i=0;i<n-2;i++)
  {
    for(int j=i+1;j<n-1;j++)
    {
     
      { for(int k=j+1;k<n;k++)
      {
       if(a[i]+a[j]>a[k] && a[i]!=a[j] && a[j]!=a[k])
        c++;
      }
      }
     
    }
  }
  cout<<c;
}

Measured memory_bytes: 3608
import sys
readlines = sys.stdin.readlines
write = sys.stdout.write
R = [
    ("light fly", 0),
    ("fly", 48),
    ("bantam", 51),
    ("feather", 54),
    ("light", 57),
    ("light welter", 60),
    ("welter", 64),
    ("light middle", 69),
    ("middle", 75),
    ("light heavy", 81),
    ("heavy", 91),
]
R.reverse()
def solve():
    for line in readlines():
        w = float(line)
        for a, b in R:
            if w > b:
                write("%s\n" % a)
                break
solve()



Measured memory_bytes: 5592
import sys


def solve():
    sys.setrecursionlimit(2000)
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, input().rstrip('\n').split()))
    a = list(map(int, input().rstrip('\n').split()))
    f = list(map(int, input().rstrip('\n').split()))
    a.sort()
    f.sort(reverse=True)

    cor_v = 10 ** 13
    inc_v = -1
    while cor_v - inc_v > 1:
        bin_v = (cor_v + inc_v) // 2
        cost = 0
        #条件を満たすcostを全検索
        for i in range(n):
            cost += max((a[i] * f[i] - bin_v + f[i] - 1) // f[i], 0)
        #costが制約を満たすか
        if cost <= k:
            cor_v = bin_v
        else:
            inc_v = bin_v
    print(cor_v)


if __name__ == '__main__':
    solve()


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

int main() {
  int a, b;
  cin >> a >> b;

  if ( a == b )
    cout << "a == b" << endl;
  if ( a < b )
    cout << "a < b" << endl;
  if ( a > b )
    cout << "a > b" << endl;

  return 0;
}


Measured memory_bytes: 3092
import Data.List
main = interact $ unlines . map (unwords . english_sentence . words) . lines
english_sentence s = [mostfreq, mostlong]
 where
  mostfreq = (head . snd . head . reverse . sort . map (\ws -> (length ws, ws)) . group . sort) s
  mostlong = foldr1 (\s1 s2 -> if length s1 > length s2 then s1 else s2) s

Measured memory_bytes: 3516
while 1:
    a,op,b=raw_input().split()
    if(op=='?'): break
    a,b=map(int,[a,b])
    ans=0
    if op=='+':
        ans=a+b
    elif op=='-':
        ans=a-b
    elif op=='*':
        ans=a*b
    elif op=='/':
        ans=a/b
    print ans

Measured memory_bytes: 4228