akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <map>
#include <cmath>
#include <bitset>
#include <deque>
#define MAX_N 100
#define MAX_T 200
#define INF 4000000000000000000
#define fst first
#define snd second
typedef long long ll;
typedef std::pair<int,int> ii;
using namespace std;

int main(){
  int n,k;
  int x;
  int ans=0;
  cin>>n>>k;
  for(int i=0;i<n;i++){
    cin>>x;
    ans+=min(k-x, x);
  }
  cout<<2*ans<<endl;
  return 0;
}


Measured memory_bytes: 256
h,w,n=map(int,input().split())
sr,sc=map(int,input().split())
s=input()
t=input()

y=sr
for i,j in zip(s,t):
    if i=="U":
        y-=1
        if y==0:
            print("NO")
            exit()
    if j=="D" and y<h:
        y+=1
y=sr
for i,j in zip(s,t):
    if i=="D":
        y+=1
        if y==h+1:
            print("NO")
            exit()
    if j=="U" and y>1:
        y-=1

x=sc
for i,j in zip(s,t):
    if i=="L":
        x-=1
        if x==0:
            print("NO")
            exit()
    if j=="R" and x<w:
        x+=1

x=sc
for i,j in zip(s,t):
    if i=="R":
        x+=1
        if x==w+1:
            print("NO")
            exit()
    if j=="L" and x>1:
        x-=1

print("YES")


Measured memory_bytes: 3888
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
 
int n,m,x,y,X,Y;
vs a;
 
int main(){
	cin>>n>>m>>x>>y;
	a=vs(n,string(m,'.'));
	X=x,Y=y;
	if(n%2==1){
		for(int i=0;i<m-1&&x;i+=2){
			a[n-1][i]='<';
			a[n-1][i+1]='>';
			x--;
		}
	}
	if(m%2==1){
		for(int i=0;i<n-1&&y;i+=2){
			a[i][m-1]='^';
			a[i+1][m-1]='v';
			y--;
		}
	}
	for(int i=0;i+1<n/2*2;i+=2) for(int j=0;j<m/2*2;j+=2){
		if(x){
			a[i][j]='<';a[i][j+1]='>';
			x--;
			if(x){
				a[i+1][j]='<';a[i+1][j+1]='>';
				x--;
			}
		}
		else if(y){
			a[i][j]='^';a[i+1][j]='v';
			y--;
			if(y){
				a[i][j+1]='^';a[i+1][j+1]='v';
				y--;
			}
		}
	}
	bool B=0;
	if(!x&&!y) B=1;
	if(!B&&n%2==1&&m%2==1&&n>=3&&m>=3&&X>=2&&Y>=2){
		a=vs(n,string(m,'.'));
		x=X-2,y=Y-2;
		a[0][0]='<';a[0][1]='>';a[0][2]='^';
		a[1][0]='^';a[1][2]='v';
		a[2][0]='v';a[2][1]='<';a[2][2]='>';
		for(int i=3;i<m-1&&x;i+=2){
			a[0][i]='<';
			a[0][i+1]='>';
			x--;
		}
		for(int i=3;i<n-1&&y;i+=2){
			a[i][0]='^';
			a[i+1][0]='v';
			y--;
		}
		for(int i=1;i<n-1;i+=2) for(int j=1;j<m-1;j+=2) if(i>1||j>1){
			if(x){
				a[i][j]='<';a[i][j+1]='>';
				x--;
				if(x){
					a[i+1][j]='<';a[i+1][j+1]='>';
					x--;
				}
			}
			else if(y){
				a[i][j]='^';a[i+1][j]='v';
				y--;
				if(y){
					a[i][j+1]='^';a[i+1][j+1]='v';
					y--;
				}
			}
		}
		if(x+y==0) B=1;
	}
	if(B){
		cout<<"YES"<<endl;
		for(int i=0;i<n;i++) cout<<a[i]<<endl;
	}
	else cout<<"NO"<<endl;
}

Measured memory_bytes: 2304
import itertools
def readInt():
    return list(map(int,input().split()))
n, k = readInt()
ans = 0
# l = [int(x) for x in range(n+1)]
for i in range(k,n+2):
    smallest = (i-1)*i /2
    largest = n*(n+1)/2 - (n-i)*(n-i+1)/2
    ans += int(largest - smallest + 1)
    ans %= 10**9 + 7
print(ans)


Measured memory_bytes: 71072
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define Max 100001
#define inf 1000000000000000
using namespace std;
int n,m,flag;
int first[Max * 2],nextv[Max * 2],u[Max * 2],v[Max * 2],s[Max * 2];
long long vis[2][Max],l = 0,r = inf,ans;
void dfs(int from,int tag,long long va) {
    if(flag)return;
    int k = first[from];
    while(k != -1) {
        if(flag)return;
        int vtag = (tag == 1);
        int to = v[k];
        long long lva = s[k] - va;
        if(vis[vtag][to] != inf) {
            if(vis[vtag][to] == lva) {
                k = nextv[k];
                continue;
            }
            else {
                flag = 1;
                return;
            }
        }
        vis[vtag][to] = lva;
        if(vtag)r = min(r,lva);
        else l = max(l,-lva);
        if(r - l <= 1){
            flag = 1;
            return;
        }
        dfs(to,-tag,lva);
        k = nextv[k];
    }
}
int main() {
    scanf("%d%d",&n,&m);
    memset(first,-1,sizeof(first));
    for(int i = 1;i <= n;i ++) {
        vis[0][i] = vis[1][i] = inf;
    }
    for(int i = 0;i < m;i ++) {
        scanf("%d%d%d",&u[i],&v[i],&s[i]);
        u[i + m] = v[i];
        v[i + m] = u[i];
        s[i + m] = s[i];
        nextv[i] = first[u[i]];
        first[u[i]] = i;
        nextv[i + m] = first[u[i + m]];
        first[u[i + m]] = i + m;
    }
    dfs(1,1,0);///dfs遍历所有点和第一个点的关系，如果有冲突flag为1 冲突就是说得到于同一点的同一关系的值不同比如a1 + a2 = 3 和 a1 + a2 = 4
    if(!flag) {///遍历后无冲突
        long long temp = -1;
        for(int i = 1;i <= n;i ++) {
            if(vis[0][i] != inf && vis[1][i] != inf) {
                long long d = (vis[1][i] - vis[0][i]) / 2;
                if(temp == -1)temp = d;
                else if(temp != d) {///解不一致
                    putchar('*');
                    flag = 1;
                    break;
                }
            }
        }
        if(temp != -1) {///有环 且各关系无冲突
            if(temp > l && temp < r)ans = 1;
        }
        else if(r - l - 1 > 0)ans = r - l - 1;
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n;
  cin >> n;
  ll res = (n/11)*2;
  n %= 11;
  if (n == 0) cout << res << endl;
  else if (n <= 6) cout << res+1 << endl;
  else cout << res+2 << endl;
}

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

#define mem(arr, i) fill(arr, arr + sizeof(arr), i)
#define MEM(arr, i) memset(arr, i, sizeof(arr))
#define Push push_back
#define Pair make_pair
#define ALL(x) x.begin(), x.end()
#define X first
#define Y second
#define ACCEL ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
typedef unsigned long long ull;
typedef long long lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef pair<pll,lli> p3l;
typedef vector<int> vcI;
typedef vector<lli> vcL;
typedef vector<pii> vPI;
typedef vector<pll> vPL;
typedef vector<p3l> v3L;
typedef vector<vcL> vvL;
//typedef priority_queue<T> prior_S<T>;
//typedef priority_queue< T, vector<T>, greater<T> > prior_B<T>;
const double PI = 3.141592653589793;
const lli I_MAX = 1LL << 60;
      lli   mod = 1000000007;

/// templates ///

const lli maxN = 2E5;

vcL inv(maxN+5, 1);
vcL fac(maxN+5, 1);

void ADD(lli &x, lli y) {
	x += y;
	if (x >= mod) x -= mod;
	if (x < 0) x += mod;
}

void MUL(lli &x, lli y) {
	x *= y;
	x = (x % mod + mod) % mod;
}

lli mypow(lli b, lli e) {
	lli ans = 1;
	while (e) {
		if (e & 1) MUL(ans, b);
		MUL(b, b);
		e >>= 1;
	}
	return ans;
}

lli modinv(lli n) {
	return mypow(n, mod - 2);
}

void calcInv(lli n) {
	for (int i = 2; i <= n; ++i) {
		inv[i] = (mod - mod / i) * inv[mod % i] % mod;
	}
}

void calcFac(lli n) {
	for (int i = 2; i <= n; ++i) {
		fac[i] = fac[i - 1] * i % mod;
	}
}

lli cm(lli a, lli b) {
	lli ans = 1;
	if (a < b) return 0;

	MUL(ans, inv[fac[a - b]]);
	MUL(ans, inv[fac[b]]);
	MUL(ans, fac[a]);

	return ans;
}

lli Lucas(lli n, lli m) {
	if (m == 0) return 1;
	return cm(n % mod, m % mod) * Lucas(n / mod, m / mod) % mod;
}

lli doLucas(lli n, lli m) {
	calcInv(mod);
	calcFac(mod);
	return Lucas(n, m);
}

/// coding area ///

const lli maxn = 3E2;
lli n;
vcL cnt(3, 0);
double dp[maxn + 1][maxn + 1][maxn + 1];
bool tok[maxn + 1][maxn + 1][maxn + 1];

void precal() {

	return;
}

double dfs(int a, int b, int c) {
	if (!(a or b or c)) return 0;
	if (dp[a][b][c] >= 0) return dp[a][b][c];
	
	int d = a + b + c;
	double ans = (double)n / d;
	if (a) ans += dfs(a - 1, b    , c    ) * (double)a / d;
	if (b) ans += dfs(a + 1, b - 1, c    ) * (double)b / d;
	if (c) ans += dfs(a    , b + 1, c - 1) * (double)c / d;
	
	return dp[a][b][c] = ans;
}

void solve() {
	
	cin >> n;
	
	cnt = {0, 0, 0};
	for (int i = 0; i < n; ++i) {
		int tmp;
		cin >> tmp;
		++cnt[tmp - 1];
	}
	
	memset(tok, false, sizeof(tok));
	memset(dp, -1, sizeof(dp));
	
	// dp[i][j][k] -> dp[i][j + 1][k - 1] * (k / n)
	//             -> dp[i + 1][j - 1][k] * (j / n)
	//             -> dp[i - 1][j][k]     * (i / n)
	
	cout << fixed << setprecision(10) << dfs(cnt[0], cnt[1], cnt[2]) << '\n';
}

int main() {
	precal();
	int t = 1;
	#ifdef LOCAL
		t = INT_MAX;
	#else
		ACCEL;
	#endif
//	cin >> t;
	for (int i = 1; i <= t; ++i) {
//		printf("Case #%d: ", i );
		solve();
	}
	return 0;
}




Measured memory_bytes: 243072
#include<bits/stdc++.h>
    using namespace std;
    int main()
    {
      int r,d,x;
      cin>>r>>d>>x;
      for(int i=0;i<10;i++)
      {
        x = r*x-d;
        cout<<x<<endl;
      }
      return 0;
    }

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

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

#define INF 1 << 30
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)



vector<bool> gen_sosuu(vector<bool> sosuu){
  int size = sosuu.size();
  REP(i,size){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(size)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<size;j++){
      sosuu[i*j] =false;
    }
  }
  return sosuu;
}

int n,m;
int p[100000];
int x[100000];
int y[100000];
int par[100001];
int ran[100001];

/*
使い方
ノード数nの要素を持つint型配列par,ranを宣言し、init()を呼ぶ
*/


void init(int n,int par[],int ran[]){
  REP(i,n){
    par[i] = i;
    ran[i] = 0;
  }
}

int find(int x,int par[]){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x], par);
  }
}

void unite(int x, int y, int par[], int ran[]){
  x = find(x,par);
  y = find(y,par);
  if(x == y) return;

  if(ran[x] < ran[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ran[x] == ran[y]) ran[x]++;
  }
}

bool same(int x, int y,int par[]){
  return find(x,par) == find(y,par);
}
int main(){
  cin >> n >> m;
  REP(i,n){
    cin >> p[i];
    p[i]--;
  }
  init(n,par,ran);
  REP(i,m){
    cin >> x[i] >> y[i];
    x[i]--;y[i]--;
    unite(x[i],y[i],par,ran);
  }
  int ans = 0;
  REP(i,n){
    if(find(p[i],par) == find(i,par)) ans++;
  }
  cout << ans <<endl;
}


Measured memory_bytes: 2176
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


# --------------------------------------------

dp = None


def main():
    N, K = li_input()
    A = li_input()

    D = collections.defaultdict(lambda: 0)
    C = []

    for a in A:
        D[a] += 1

    for v in D.values():
        C.append(v)

    C.sort(reverse=True)

    print(sum(C[K:]))


main()


Measured memory_bytes: 32808
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Node{
    int key;
    struct Node *right,*left,*parent;
};

struct Node *root,*NIL;

struct Node *treeMinimum(struct Node *x){
    while(x->left != NIL)
        x=x->left;
    return x;
}

struct Node *find(struct Node *u,int k){
    while(u != NIL && k != u->key){
        if(k < u->key)
            u=u->left;
        else
            u=u->right;
    }
    return u;
}

struct Node *treeSuccessor(struct Node *x){
    if(x->right != NIL)
        return treeMinimum(x->right);
    struct Node *y=x->parent;
    while(y != NIL && x == y->right){
        x=y;
        y=y->parent;
    }
    return y;
}

void treeDelete(struct Node *z){
    struct Node *y;
    struct Node *x;
    
    if(z->left == NIL || z->right == NIL)
        y=z;
    else
        y=treeSuccessor(z);
    if(y->left != NIL)
        x=y->left;
    else
         x=y->right;
    if(x != NIL)
        x->parent = y->parent;
    if(y->parent == NIL)
        root=x;
    else{
        if(y == y->parent->left)
            y->parent->left=x;
        else
            y->parent->right=x;
    }
    if(y != z)
        z->key=y->key;

    free(y);
}


void insert(int k){
    struct Node *y=NIL;
    struct Node *x=root;
    struct Node *z;

    z=(struct Node *)malloc(sizeof(struct Node));
    z->key=k;
    z->left=NIL;
    z->right=NIL;

    while(x != NIL){
        y=x;
        if(z->key < x->key){
            x=x->left;
        }
        else
            x=x->right;
    }
    z->parent=y;
    if(y==NIL)
        root=z;
    else{
        if(z->key < y->key)
            y->left=z;
        else
            y->right=z;
    }
}

void inorder(struct Node *u){
    if(u==NIL)
        return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}
void preorder(struct Node *u){
    if(u==NIL)
        return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}
int main(void){
    int n,i,x;
    char line[7];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%s",line);
        if(!strcmp(line,"insert")){
            scanf("%d",&x);
            insert(x);
        }
        else if(!strcmp(line,"print")){
            inorder(root);
            puts("");
            preorder(root);
            puts("");
        }
        else if(!strcmp(line,"find")){
            scanf("%d",&x);
            struct Node *temp=find(root,x);
            if(temp != NIL)
                puts("yes");
            else puts("no");
        }
        else{
            scanf("%d",&x);
            treeDelete(find(root,x));
        }
    }
    return 0;
}

Measured memory_bytes: 19356
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
#include <string.h>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <string>
using namespace std;

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair
#define PB push_back
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LL MOD = 1000000007;
const int INF = 1e9;
const LL LINF = 1LL * INF * INF;
const int MAXN = 100007;
const LD EPS = 1e-7;

int A[MAXN];
vector <int> G[MAXN];
bool used[MAXN], flag = true;

void dfs(int v)
{
	used[v] = true;
	int cnt = 0, m = 0;
	LL s = 0;
	REP(i, SZ(G[v]))
	{
		int to = G[v][i];
		if (!used[to])
		{
			dfs(to);
			if (A[to])
				++cnt;
			s += A[to];
			m = max(m, A[to]);
		}
	}
	if (cnt)
	{
		if (2 * A[v] < s || A[v] > s || 2 * m + s > 4LL * A[v] || A[v] < s && cnt == 1)
			flag = false;
		A[v] = 2 * A[v] - s;
	}
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	int n, r;
	cin >> n;
	REP(i, n)
		cin >> A[i];
	if (n == 2)
	{
		cout << (A[0] == A[1] ? "YES" : "NO");
		return 0;
	}
	REP(i, n - 1)
	{
		int a, b;
		cin >> a >> b;
		--a; --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	REP(i, n)
		if (SZ(G[i]) > 1)
			r = i;
	dfs(r);
	cout << (flag && A[r] == 0 ? "YES" : "NO");
	//cout << endl; system("pause");
	return 0;
}

Measured memory_bytes: 13312
/**
  *  Worg
  */
#include <vector>
#include <iostream>
#include <algorithm>

int main(int argc, char const *argv[]) {
    int n; std::cin >> n;
    std::vector<int> sticks(n);
    for (int& num : sticks) {
        std::cin >> num;
    }

    std::sort(sticks.begin(), sticks.end());

    int answer = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            int sum = sticks[i] + sticks[j];

            if (sum > sticks.back()) {
                answer += n - j - 1;
            } else {
                int left = j + 1, right = n - 1, index = j;

                while (left <= right) {
                    int mid = (left + right) / 2;

                    if (sticks[mid] < sum) {
                        index = mid; left = mid + 1;
                    } else {
                        right = mid - 1;
                    }
                }

                answer += index - j;
            }
        }
    }

    std::cout << answer << '\n';
    return 0;
}


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

using namespace std;

int fact(int n) 
{
  if (n == 0) return 1;
  return n * fact(n - 1);
}

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

  cout << n - k + 1 << endl; 
  return 0;
}

Measured memory_bytes: 256
n = int(input())

s = []
t = []
tsum = 0

for i in range(n):
    a, b = map(str, input().split())
    b = int(b)
    s = s + [a]
    t = t + [b]
    tsum += t[i]

x = input()
tinter = 0

for j in range(n):
    tinter = tinter + t[j]
    
    if s[j] == x:
        break
        
print(tsum - tinter)


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

int main(){
  int n;
  cin >> n;
  vector<int> A(n);
  rep(i,n) cin >> A[i];
  sort(A.begin(),A.end());
  cout << A[n-1] - A[0] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define MOD 1000000007LL
#define rep(i,a,n) for (int i=a ; i<n ; i++)
#define per(i,a,n) for (int i=n-1 ; i>=a ; i--)
#define LLINF (llong)1e18+5
#define INF 1e9+5

using namespace std;
using llong = long long;
using VI = vector<int>;
using VLL = vector<long long>;
using PII = pair<int, int>;

int n;
vector<int> cur;
vector<vector<vector<double>>> dp;
double dfs(int oneCnt, int twoCnt, int threeCnt)
{
	int cnt = oneCnt + twoCnt + threeCnt;
	if (cnt == 0) return 0;
	if (dp[oneCnt][twoCnt][threeCnt] != -1) return dp[oneCnt][twoCnt][threeCnt];
	double sum = 0;

	if(threeCnt > 0)
		sum += threeCnt * dfs(oneCnt, twoCnt + 1, threeCnt - 1);	
	if(twoCnt > 0)
		sum += twoCnt * dfs(oneCnt + 1, twoCnt - 1, threeCnt);
	if(oneCnt > 0)
		sum += oneCnt * dfs(oneCnt - 1, twoCnt, threeCnt);

	return dp[oneCnt][twoCnt][threeCnt] = (double)n / (double)cnt + (double)sum/(double)cnt;
}

int main()
{
	IOS;

	cin >> n;
	cur.resize(n);
	int one = 0, two = 0, three = 0;
	rep(i, 0, n)
	{
		cin >> cur[i];
		if (cur[i] == 1) one++;
		else if (cur[i] == 2)two++;
		else three++;
	}
	dp.resize(n+1);
	rep(i, 0, n+1) dp[i].resize(n+1);
	rep(i, 0, n + 1) rep(j, 0, n+ 1) dp[i][j].resize(n + 1), fill(all(dp[i][j]), -1);

	cout << fixed;
	cout << setprecision(16);
	cout << dfs(one, two, three);

	return 0;
}


Measured memory_bytes: 219064
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

int n, m, k, x[2], y[2];
string adj[1000000];
vector<vector<int>> dst;
vector<vector<bool>> vis;

bool bounds(int a, int b){
	return (a >= 0 && a < n && b >= 0 && b < m && adj[a][b] == '.' && !vis[a][b]);
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> m >> k;
	for(int i = 0; i < 2; i++) cin >> x[i] >> y[i];
	for(int i = 0; i < n; i++) cin >> adj[i];
	vis.resize(n, vector<bool>(m, false));
	dst.resize(n, vector<int>(m, -1));
	priority_queue<tuple<int, int, int>> que;
	dst[x[0] - 1][y[0] - 1] = 0;
	que.push(make_tuple(0, x[0] - 1, y[0] - 1));
	int xx[] = {-1, 0, 1, 0}, yy[] = {0, -1, 0, 1};
	while(!que.empty()){
		int a, b, c;
		tie(c, a, b) = que.top();
		que.pop();
		if(vis[a][b]) continue;
		vis[a][b] = true;
		for(int i = 0; i < 4; i++){
			int aa = a, bb = b;
			for(int j = 0; j < k; j++){
				aa += xx[i], bb += yy[i];
				if(bounds(aa, bb) && (dst[aa][bb] == -1 || dst[aa][bb] >= dst[a][b] + 1)){
					dst[aa][bb] = dst[a][b] + 1;
					que.push(make_tuple(-dst[aa][bb], aa, bb));
				}else break;
			}
		}
	}
	cout << dst[x[1] - 1][y[1] - 1] << "\n";
	return 0;
}

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

const int INF = 1e9;

int main(){
  int n;
  cin >> n;
  
  bool p = false, m = false;
  int ma = -INF, mi = INF;
  int index1 = 0, index2 = 0;
  rep(i,n) {
    int a;
    cin >> a;
    if (a >= 0) p = true;
    else m = true;

    if (ma < a) ma = a, index1 = i+1;
    if (mi > a) mi = a, index2 = i+1;
  }
  
  if (p && !m) {
    cout << n-1 << endl;
    for (int i = 1; i < n; i++) {
      cout << i << " " << i+1 << endl;
    }
  } else if (!p && m) {
    cout << n-1 << endl;
    for (int i = n; i > 1; i--) {
      cout << i << " " << i-1 << endl;
    }
  } else {
    if (abs(ma) > abs(mi)) {
      cout << 2*n-1 << endl;
      for (int i = 1; i <= n; i++) {
        cout << index1 << " " << i << endl;
      }
      for (int i = 1; i < n; i++) {
      cout << i << " " << i+1 << endl;
    }

    } else {
       cout << 2*n-1 << endl;
      for (int i = 1; i <= n; i++) {
        cout << index2 << " " << i << endl;
      }
      for (int i = n; i > 1; i--) {
      cout << i << " " << i-1 << endl;
      }

    }
  }

  return 0;
}

Measured memory_bytes: 256
N = int(input())
# 初期状態
T = [0]
X = [0]
Y = [0]
for i in range(N):
    t, x, y = map(int, input().split())
    T.append(t)
    X.append(x)
    Y.append(y)

# パリティに着目せよ
count = 0
for i in range(N):
    totalDisplacement = abs(X[i+1]-X[i]) + abs(Y[i+1]-Y[i])
    delta_T = T[i+1]-T[i]
    if (delta_T - totalDisplacement) % 2 == 0 and (delta_T - totalDisplacement) >= 0:
        count += 1

if count == N:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 11816
#include<iostream>
#include<string>
#include <algorithm>
using namespace std;
int main()
{
  int X;
  cin >> X;
  int ans, p;
  ans = 0;
  for(int i=1; i <= X; ++i){
    for(int j=2; j < 10; ++j){
      p = i;
      for(int k=1; k < j; ++k){
        p = p * i;
      }
      if(p <= X){
        if(p > ans){
          ans = p;
        }
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
(function main() {
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());

  let i, j, X, Y, xlen, ylen, maxlen;
  let c;
  while ((X = lines.shift()) && (Y = lines.shift())) {
    xlen = X.length;
    ylen = Y.length;
    c = Array.from(Array(xlen + 1), () => Array.from(Array(ylen + 1), () => 0));

    for (i = 1; i <= xlen; i++) {
      for (j = 1; j <= ylen; j++) {
        if (X[i-1] === Y[j-1]) c[i][j] = c[i - 1][j - 1] + 1;
        else c[i][j] = Math.max(c[i - 1][j], c[i][j - 1]);
      }
    }
    console.log(c[xlen][ylen]);
  }
})();



Measured memory_bytes: 209108
#include <stdio.h>

int main() {
	int K, ans = 0;
	scanf("%d", &K);
	for (int i = 1; i <= K; i++) {
		for (int j = 1; j <= K; j++) {
			for (int l = 1; l <= K; l++) {
				int J = j, I = i, L = l,gc,gcd,N,n;
				//printf("%d %d %d ", I, J, L);
				if (I < J) {
					int t = I;
					I = J;
					J = t;
				}
				//printf("%d %d %d ", I, J, L);
				n = I % J;
				N = J;
				while (n != 0) {
					N = n;
					n = J % n;
					J = N;
				}
				gc = N;
				//printf("%d ", gc);

				if (gc < L) {
					int t = gc;
					gc = L;
					L = t;
				}
				n = gc % L;
				N = L;
				while (n != 0) {
					N = n;
					n = L % n;
					L = N;
				}
				gcd = N;
				//printf("%d\n",gcd);
				ans += gcd;
			}
		}
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using namespace atcoder;
using ll = long long;
using P = pair<int,int>;

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

	dsu d(n);
	rep(_, q){
		int t, u, v;
		cin>>t>>u>>v;

		if(t==0) d.merge(u, v);
		else cout<<d.same(u, v)<<endl;
	}
	return 0;
}


Measured memory_bytes: 3940
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>

ll n,cnt,ans,a,b,c,d,tmp[10],tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

//------ 自分を天才だと信じる ------

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

    rep(i,3)cin>>tmp[i];
    sort(tmp,tmp+3);
    if(tmp[0]==tmp[2])Cout(0);
    else{
        ll tasu=(tmp[2]-tmp[0])/2;
        ans+=tasu;
        tmp[0]+=tasu*2;
        tasu=(tmp[2]-tmp[1])/2;
        ans+=tasu;
        tmp[1]+=tasu*2;
        sort(tmp,tmp+3);
        if(tmp[0]==tmp[2])Cout(ans);
        else{
            if(tmp[0]==tmp[1])Cout(ans+1);
            else Cout(ans+2);
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		long K = sc.nextLong();
		
		int x = 0;
		
		for(int i = 0; i < S.length(); i++) {
			x++;
			if(S.charAt(i) == '1' && x < K) {
				continue;
			} else {
				System.out.println(S.charAt(i));
				break;
			}
		}
	}
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define F(i,s,e) for(int i=s;i<e;++i)
int MOD=1e9+7;

long fact(long index){
    long ans=1;
    F(i,0,index){
        ans=ans*2%MOD;
    }
    return ans;
}

int main(){
    long n;
    cin >> n;
    long a[n];
    F(i,0,n) cin >> a[i];
    int c=0,cnt=0;
    sort(a,a+n);
    int aa=-1;
    F(i,0,n){
        if(a[i]==aa) cnt++;
        else cnt=0;
        if(a[i]==0) c++;
        if(c==2 || cnt==2){
            cout << 0 << endl;
            return 0;
        }
        aa=a[i];
    }
    cout << fact(n/2) << endl;
    return 0;
}


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

int main(){
	int n, a, b, c, x;

	while (std::cin >> n >> a >> b >> c >> x){

		if (n == 0 && a == 0 && b == 0 && c == 0 && x == 0)break;

		std::vector<int>y(n);
		for (int i = 0; i < n; i++)std::cin >> y[i];

		int flam = 0, num = 0;

		while (true){
			if (x == y[num]){
				num++;
				if (num == n)break;
			}
			x = (a*x + b) % c;
			flam++;
			if (flam > 10000){
				flam = -1;
				break;
			}
		}

		std::cout << flam << std::endl;

	}

	return 0;
}

Measured memory_bytes: 1196
N = int(input())
S = input()
sride = 1
count = 0
max_num = 0
for i in range(N-1):
  for j in range(N-sride):
    if S[j] == S[j+sride]:
      count += 1
      max_num = max(max_num, count)
    else:
      count = 0
    if count == sride:
      break
  sride += 1
  count = 0
print(max_num)

Measured memory_bytes: 41564
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))

A = []
B = []
mod = 10**9 + 7

for i in range(N):
    if S[i] in T:
        A.append(S[i])

for i in range(M):
    if T[i] in S:
        B.append(T[i])        
        
l1 = [1] * (N + 1)

for i, t in enumerate(T):
    l2 = l1[:]
    k = 0
    for j, s in enumerate(S):
        if t == s:
            k += l1[j]
        l2[j + 1] = (l1[j + 1] + k) % mod
    l1 = l2
print(l1[-1])

Measured memory_bytes: 3316
//package ABC171;
import java.util.*;
import java.io.*;
import java.lang.*;
class Main {

	public static void main(String[] args) throws IOException{
		
		
		// TODO Auto-generated method stub
		
		BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(br.readLine());
		
		int a[]=new int[n];
		String s[]=br.readLine().split(" ");
		HashMap<Integer,Integer> hm=new HashMap<>();
		long sum=0;
		for(int i=0;i<n;i++)
		{
			a[i]=Integer.parseInt(s[i]);
			hm.put(a[i],hm.getOrDefault(a[i],0)+1);
			sum+=a[i];
			
		}
		int q=Integer.parseInt(br.readLine());
		int qr[]=new int[q];
		for(int i=0;i<q;i++)
		{
			String ss[]=br.readLine().split(" ");
			int b=Integer.parseInt(ss[0]);
			int c=Integer.parseInt(ss[1]);
			
			
			if(hm.containsKey(b)==false)
			{
				System.out.println(sum);
				
			}
			else
			{
				int count=hm.get(b); //occurence of b;
				long change=(c-b)*count;
				sum=sum+change;
				hm.remove(b);
				hm.put(c,hm.getOrDefault(c,0)+count);
				System.out.println(sum);
			}
		}
		

	}

}


Measured memory_bytes: 74564
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll n,k,ans=0; cin>>n>>k;
    ll cnt=k;
    set<ll> c;
    vector<pair<ll,ll>> v(n);
    rep(i,n){
        ll t,d; cin>>t>>d;
        v[i]=mk(d,t);
    }
    sort(al(v)); reverse(al(v));
    vector<vector<ll>> sushi(n+1);
    rep(i,k){
        ans+=v[i].first;
        c.insert(v[i].second);
        sushi[v[i].second].push_back(v[i].first);
    }
    vector<ll> l;
    rep(i,n+1){
        if((ll)sushi[i].size()<=1) continue;
        sort(al(sushi[i]));
        rep(j,(ll)sushi[i].size()-1){
            l.push_back(sushi[i][j]);
        }
    }
    if((ll)l.size()>0) sort(al(l));
    ans+=c.size()*c.size();
    ll cnt2=0,cur=ans;
    while(cnt<n){
        if(c.count(v[cnt].second)){
            cnt++; continue;
        }
        else{
            if(cnt2==(ll)l.size()) break;
            c.insert(v[cnt].second);
            cur-=l[cnt2];
            cnt2++;
            cur+=v[cnt].first;
            cur+=c.size()*2-1;
            cnt++;
            ans=max(ans,cur);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 9728
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin>>s>>t;
  s+=s;
  for(int i=0;i<t.size();i++){
    int tmp=0;
    for(int j=0;j<t.size();j++){
      if(s[i+j]==t[j])continue;
      tmp=1;
    }
    if(tmp)continue;
    cout<<"Yes"<<endl;
    return 0;
  }
  cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define N 100
#define C 99

int main(){
  int flag =1;
  int i=0,b,result=0;
  int a[N],top=0;
  char c[6];

  for(b=0;b<100;b++){
    for(i=0;i<6;i++){
      scanf("%c",&c[i]);
      if(c[i]=='\n'){
        flag = 0;
        break;
      }
      if(c[i]==' '){
        c[i] = '\0';
        break;
      }
    }
    if(c[0]=='+'){
      a[top-2]=a[top-2]+a[top-1];
      top--;
    }
    else if(c[0]=='-'){
      a[top-2]=a[top-2]-a[top-1];
      top--;
    }
    else if(c[0]=='*'){
      a[top-2]=a[top-2] * a[top-1];
      top--;
    }
    else{     
      a[top]=atoi(c);
      top++;
    }
    if(flag==0){
      break;
    }
    
  }
  result=0;
  for(i=0;i!=top;i++){
    result = a[i] + result;
  }
  printf("%d\n",result);
  return 0;
}



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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/
int main(){
    string s;cin>>s;
    int n=(int)s.size()-2;
    cout<<s[0]<<n<<s[n+1]<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
#define int long long
int n,l,r,a[100001],b[100001],f;
main(){
  string s,t;
  cin>>s;
  r(i,s.size()){
    t+=s[i];
    while(t.size()>=2&&t[t.size()-1]=='T'&&t[t.size()-2]=='S'){
      t.erase(t.end()-1);
      t.erase(t.end()-1);
    }
  }
  cout<<t.size()<<endl;
}

Measured memory_bytes: 776
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>

using namespace std;
typedef long long ll;

int main(){
  int n, k, x, y; cin>>n>>k>>x>>y;
  if(n<=k){
    cout<<n*x<<endl;
  }else{
    cout<< x*k+(n-k)*y<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

pint p[200002];
int main(){
    ll w,h;
    cin>>w>>h;
    rep(i,w){
        cin>>p[i].first;
        p[i].second=0;
    }
    rep(i,h) {
        cin>>p[i+w].first;
        p[i+w].second=1;
    }
    sort(p,p+w+h);
    ll a=w+1,b=h+1;
    ll sum=0,cnt=0,cur=0;
    while(1){
        if(cnt>=(w+1)*(h+1)-1) break;
        int c=p[cur].first,f=p[cur].second;
        if(f==0){
            cnt+=b;--a;
            sum+=b*c;++cur;
        }
        else{
            cnt+=a;--b;
            sum+=a*c;++cur;
        }
    }
    cout<<sum<<endl;
    return 0;
}

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

int main(){
    stack<char> str;
    char c;
    while(1){
        scanf("%c",&c);
        if(c=='\n'||c==EOF) break;
        str.push(c);
    }
    while(!str.empty()){
        printf("%c",str.top());
        str.pop();
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 1140
#include<iostream>
#include<vector>
#include<cstdlib>
#include<string>
#include<cmath>
using namespace std;

struct Dice{
  int num[6];
};

int main(){
    string ans="Yes";
    vector<int> gg;
    int a;
    cin>>a;
    vector<Dice> dices(a);//一度数字をさいころの数に戻して計算するべき
    for(int i=0; i<a; i++){
        for(int j=0; j<6; j++){
            cin>>dices[i].num[j];
        }
    }
    
    if(dices[0].num[0]==1 && dices[0].num[1]==2 && dices[0].num[2]==2) ans="No";

    int r[3][4]={{1,2,6,5} , {1,3,6,4} , {2,3,5,4}};
    for(int i=0; i<a; i++){
        for(int j=i+1; j<a; j++){
            int dtop=dices[i].num[0];
            int dbottom=dices[i].num[5];
            int n=dices[i].num[4],e=dices[i].num[2],s=dices[i].num[1],w=dices[i].num[3];
            int top=dices[j].num[0];
            int front=dices[j].num[1];
            if(top==dices[i].num[2]){
                w=dtop;
                dtop=e;
                e=7-w;
            }else if(top==dices[i].num[3]){
                e=dtop;
                dtop=w;
                w=7-e;
            }else{
                for(int k=0; k<4; k++){
                    if(r[0][k]==top) break;
                    n=dtop;
                    dtop=s;
                    s=7-n;
                }
            }
            dbottom=7-dtop;
            int rnum=0;
            for(int k=0; k<3; k++){
                for(int l=0; l<4; l++){
                    if(r[k][l]==top) break;
                    if(l==3) rnum=k;
                }
            }
            for(int k=0; k<4; k++){
                if(front==s) break;
                int tmp=n;
                n=w;
                w=s;
                s=e;
                e=tmp;
            }
            if(e==dices[j].num[2] && w==dices[j].num[3] && n==dices[j].num[4] && dbottom==dices[j].num[5] && dtop==dices[j].num[0] && s==dices[j].num[1]){
                //cout<<i<<" "<<j<<endl;
                ans="No";
            }
            //cout<<"ans="<<ans<<endl;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3232
#include <cstdio>
#include <cmath>

int main()
{
  int a, b, x;
  scanf("%d%d%d", &a, &b, &x);
  
  if (x < a * a * b / 2.)
  {
    printf("%.12f\n", std::atan2(a * b * b, 2 * x) * 180 / M_PI);
  }
  else
  {
    printf("%.12f\n", std::atan2(2 * (a * a * b - x), a * a * a) * 180 / M_PI);
  }
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  
  int cnt = 0;
  while(!(a == b && b == c)){
    if(a == b && a < c){
      a++;
      b++;
      cnt++;
    } else if(a == c && a < b) {
      a++;
      c++;
      cnt++;
    } else if(b == c && b < a) {
      b++;
      c++;
      cnt++;
    } else {
      int mini = min({a, b, c});
      if(a == mini){
        a += 2;
        cnt++;
      }else if(b == mini){
        b += 2;
        cnt++;
      } else {
        c += 2;
        cnt++;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [0] * n
xy = [[]] * n
for i in range(n):
    a[i] = int(input())
    xy[i] = [list(map(int, input().split())) for j in range(a[i])]
ans = 0
for i in range(2**n):
    tf = [False] * n
    for j in range(n):
        if (i>>j) & 1:
            tf[j] = True
    flag = False
    for j in range(n):
        for k in xy[j]:
            if tf[j] and k[1] != tf[k[0]-1]:
                flag = True
                break
        if flag:
            break
    if flag:
        continue
    ans = max(ans, tf.count(True))
print(ans)

Measured memory_bytes: 9136
import numpy as np
N, K = map(int, input().split())
x = np.asarray(list(map(int,input().split())))
ans = 10**9
for i in range(N-K+1):
    ans = min(ans, abs(x[i])+abs(x[i+K-1]-x[i]), abs(x[i+K-1])+abs(x[i]-x[i+K-1]))
print(ans)

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

const ll N = 1e5 + 10, MOD = 1e9 + 7;
vl adj[N];

pll dfs(ll i, ll p) {
	ll w = 1, b = 1;
	for (ll j: adj[i]) if (j != p) {
		ll cw, cb;
		tie(cw,cb) = dfs(j,i);
		w = w * (cw+cb) % MOD;
		b = b * cw % MOD;
	}
	return {w,b};
}

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

	ll n; cin >> n;
	FOR(i,1,n) {
		ll a, b;
		cin >> a >> b;
		adj[a].pb(b);
		adj[b].pb(a);
	}

	pll res = dfs(1,0);
	cout << (res.xx + res.yy) % MOD << endl;
}



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

int main(){
    stack<int> sum;
    stack<pair<int,int>> ds;
    char inp='1';
    int cnt=0;
    int h=0;
    int area=0;

    while(cin >> inp){
        if(inp=='\\'){
            sum.push(cnt);

        }
        if(inp=='/'){
            if(sum.empty()==false){
                int j=sum.top();
                area+=cnt-sum.top();
                sum.pop();
                int a=cnt-j;
                while(ds.size()>0 && ds.top().first>j){
                    a+=ds.top().second;
                    ds.pop();
                }
                ds.push(make_pair(j,a));
            }
        }
        if(inp=='_'){
        }
        cnt++;
    }
    cout << area << endl;
    vector<int> ans;
    while(ds.size()>0){
        ans.push_back(ds.top().second);
        ds.pop();
    }
    reverse(ans.begin(),ans.end());
    cout << ans.size();
    for(auto itr = ans.begin();itr !=ans.end();itr++){
        cout << " " << *itr;
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3240
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int n,k;

int main(){
	cin>>n>>k;
	cout<<(n+k-3)/(k-1)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
 int i,g,n,x;
 cin >> n >> x;
 int a[n];
 for(i=0;i<n;i++)
 {
  cin >> a[i];
  if(i==0)
  g=abs(a[i]-x);
  else
  g=__gcd(g,abs(x-a[i]));
 }
 cout << g;
 return 0;
}

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

int main(){
  int n,m,x,ans;
  ans = 0;
  x = 0;
  pair<int, int> p[300000];
  cin >> n >> m;
  for(int i=0;i<m;i++){
    cin >> p[i].second >> p[i].first;
  }
  sort(p,p+m);
  
  for(int i=0;i<m;i++){
    if(x<p[i].second){
      ans++;
      x = p[i].first-1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
#include <iostream>

using namespace std;

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

	int n, m;
	cin >> n >> m;
	char** mat = new char*[n];
	bool flag = true;
	for (int i=0;i<n && flag;++i){
		mat[i] = new char[m];
		for (int j=0;j<m;++j){
			cin >> mat[i][j];
			if (i && j){
				if ((mat[i-1][j-1] == '#' || mat[i][j] == '#') && mat[i-1][j] == '#' && mat[i][j-1] == '#'){
					flag = false;
					break;
				}
			}
		}
	}
	if (flag){
		cout << "Possible" << endl;
	}
	else{
		cout << "Impossible" << endl;
	}
	return 0;
}

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

public class Main {

	private static int[] face = new int[6];

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		for(int i = 0; i < 6; i++){
			face[i] = scan.nextInt();
		}
		int intLoop = scan.nextInt();
		ArrayList<Integer> list = new ArrayList<Integer>();
		for(int i = 0; i < intLoop; i++){
			int intNum1 = scan.nextInt();
			int intNum2 = scan.nextInt();
			int intAns = face[2];
			int intTemp;
			if(intNum1 == face[1]){
				intTemp = face[0];
				face[0] = face[1];
				face[1] = face[5];
				face[5] = face[4];
				face[4] = intTemp;
			}else if(intNum1 == face[2]){
				intTemp = face[0];
				face[0] = face[2];
				face[2] = face[5];
				face[5] = face[3];
				face[3] = intTemp;
			}else if(intNum1 == face[3]){
				intTemp = face[0];
				face[0] = face[3];
				face[3] = face[5];
				face[5] = face[2];
				face[2] = intTemp;
			}else if(intNum1 == face[4]){
				intTemp = face[0];
				face[0] = face[4];
				face[4] = face[5];
				face[5] = face[1];
				face[1] = intTemp;
			}else if(intNum1 == face[5]){
				intTemp = face[0];
				face[0] = face[5];
				face[5] = intTemp;
				intTemp = face[1];
				face[1] = face[4];
				face[4] = intTemp;
			}
			if(intNum2 == face[1]){
				intAns = face[2];
			}else if(intNum2 == face[2]){
				intAns = face[4];
			}else if(intNum2 == face[3]){
				intAns = face[1];
			}else if(intNum2 == face[4]){
				intAns = face[3];
			}
			list.add(intAns);
		}
		for(int i = 0; i < list.size(); i++){
			System.out.println(list.get(i));
		}
		scan.close();
	}
}

Measured memory_bytes: 17212
X = 10 ** 9

S = int(input())

if S < X * X:
	x1 = X
	y2 = (S // x1) + 1
	y1 = 1
	x2 = x1 * y2 - S
else:
	x1 = X
	y2 = X
	x2 = 0
	y1 = 0

print(0, 0, x1, x2, y1, y2)


Measured memory_bytes: 3064
/* ex3_4
   tamayama　*/

#include<stdio.h>
 int main (void){
     int N;
     int i;
     int input_N;
     int check=0;
     scanf("%d",&N);
     input_N = N;
   
     /*与えられたNを1から9で割り、割り切れるかつ商が9以下のものがあればcheckを増やす*/
     for(i=1; i<10; i++){
         if(input_N / i < 10 && input_N % i == 0){
             check++;
         }
     }

     if(check > 0){  /*checkが0のままなら九九表に無いと判定し、そうでないなら九九表にあると判定*/
         printf("Yes");
     }else{
         printf("No");
     }
     return 0;
 }


Measured memory_bytes: 128
N,P = map(int,input().split())
a_ls = list(map(int, input().split()))

# dp[i][j] := i-1番目のbuiscuitsまでみて、食べた枚数のあまりがjであるような方法の数
dp = [[0,0] for _ in range(N+1)]
dp[0][0] = 1
for i in range(1,N+1):
    next = (a_ls[i-1])%2
    if next == 0:
        dp[i][0] += 2 * dp[i-1][0]
        dp[i][1] += 2 * dp[i-1][1]
    else:
        dp[i][0] += dp[i-1][0] + dp[i-1][1]
        dp[i][1] += dp[i-1][0] + dp[i-1][1]
print(dp[-1][P])
        


Measured memory_bytes: 9136
package main

import (
	"fmt"
)

func main() {
	var n, x int
	var l []int

	fmt.Scanf("%d %d", &n, &x)
	l = make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &l[i])
	}

	d := 0
	cnt := 1

	for ; d <= x && cnt <= n; cnt++ {
		d += l[cnt-1]
		if d > x {
			break
		}
	}

	fmt.Print(cnt)
}


Measured memory_bytes: 512
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define SIZE 100005
#define INF 1e18
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define vec vector
using pint = pair<int,int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


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

    string s;
    cin>>s;
    if(s[s.size()-1]=='s') cout<<s+"es"<<endl;
    else cout<<s+'s'<<endl;
}

Measured memory_bytes: 3648