akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const mod = 998244353
const facNum = 300001
const INF = 1001001001

func main() {
	sc := newScanner(os.Stdin)
	N := sc.i()
	gift := map[string]bool{}
	for i := 0; i < N; i++ {
		gift[sc.s()] = true
	}
	fmt.Println(len(gift))

}

// fmt.Println("Yes")
// fmt.Println("No")

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}

//const factorial = new
func Pow(a, n int) int {
	ans := 1
	for n > 0 {
		if (n & 1) == 1 {
			ans = ans * a % mod
		}
		a = a * a % mod
		n = n >> 1
	}
	return ans
}

func Gcd(a, b int) int {
	if a < b {
		return Gcd(b, a)
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func combination(n, k int, fac, ifac []int) int {
	if n < k || n < 0 {
		return 0
	}
	if k == 0 {
		return 1
	}
	//while n != 0
	ans := ifac[k] * ifac[n-k] % mod
	return ans * fac[n] % mod
}

// 階乗: factorial
// コンビネーションを計算する際に前もって計算しておく
// fac[k] => k! (mod M)
// ifac[k] => k!^(M-2) (mod M)
// n: ex. 2 * 10^5 => 200001
// fac, ifac := factorial()
func factorial() (fac []int, ifac []int) {
	fac = make([]int, facNum)
	fac[0] = 1
	ifac = make([]int, facNum)
	ifac[0] = 1
	for i := 1; i < facNum; i++ {
		fac[i] = fac[i-1] * i % mod
		ifac[i] = ifac[i-1] * Pow(i, mod-2) % mod
	}
	return
}

// vs: sorted slice int value
func lowerBound(vs []int, v int) (index int) {
	n := len(vs) / 2
	m := len(vs)
	for m != n {
		if vs[n] < v {
			n = (m-n+1)/2 + n
			//m = m
		} else {
			m = n
			n = n / 2
		}
	}
	return n
}


Measured memory_bytes: 14284
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)

int main(void){
    string s;
    int q;
    bool rev_flag = false;
    cin >> s;
    cin >> q;
    int t, f;
    vector<char> head;
    vector<char> tail;
    char c;
    rep(i,q) {
        cin >> t;
        if (t == 1) {
            rev_flag = !rev_flag;
        } else {
            cin >> f >> c;
            if (f == 1) {
                if (rev_flag) {
                    tail.push_back(c);
                    //s = s + c;
                } else {
                    head.push_back(c);
                    //head.push_front(c);
                    //s = c + s;
                }
            } else {
                if (rev_flag) {
                    head.push_back(c);
                    //head.push_front(c);
                    //s = c + s;
                } else {
                    tail.push_back(c);
                    //s = s + c;
                }
            }
        }
    }
    if (rev_flag) {
        reverse(s.begin(), s.end());
        reverse(tail.begin(), tail.end());
        for (auto& a : tail) {
            cout << a;
        }
        cout << s;
        for (auto& a : head) {
            cout << a;
        }
        cout << endl;
    } else {
        reverse(head.begin(), head.end());
        for (auto& a : head) {
            cout << a;
        }
        cout << s;
        for (auto& a : tail) {
            cout << a;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int n,m,i,j,x,num[100005],cnt[5];
int main()
{
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>x;
		while (x%2==0&&num[i]<2)
		{
			num[i]++;
			x/=2;
		}
		cnt[num[i]]++;
	}
	if (cnt[2]+1>=cnt[0]+((bool)(cnt[1]))) cout<<"Yes"; else cout<<"No";
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(i, a, b)    for (int i = a; i <= b; ++i)
#define ii              pair <int, int>
using namespace std;
const int N = 2e5 + 3;
int n, dsu[N];
long long res;
vector <ii> V;
deque <int> dq;

void init() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("main.inp","r",stdin);
    //freopen("main.out","w",stdout);
}

int root(int x) { return dsu[x] <= 0 ? x : dsu[x] = root(dsu[x]); }
void merge(int u, int v) {
    if (dsu[u] > dsu[v]) swap(u, v);
    dsu[u] += dsu[v], dsu[v] = u;
}

void solve() {
    cin >> n;
    FOR(i, 1, n) { int x; cin >> x; V.push_back({ x, i }); dq.push_back(i); }

    memset(dsu, -1, sizeof dsu);
    sort(V.begin(), V.end());
    for (ii it : V) {
        while (1) {
            int id1 = root(it.second);
            int id2 = root(dq.front()); dq.pop_front();
            if (id2 == id1) break;
            merge(id1, id2);
        }
        int id1 = root(it.second);
        res += 0LL - dsu[id1] - 1; dsu[id1]++;
        if (dsu[id1] < 0) dq.push_back(id1);
    }

    cout << res << '\n';
}

main() {
    init(); solve();
}



Measured memory_bytes: 6224
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    int n,m;    cin >> n >> m;
    vector<double>a(n);
    rep(i, n)   cin >> a[i];
    double sum = 0;
    rep(i, n)   sum += a[i];
    sort(a.rbegin(), a.rend());
    if(a[m-1] >= sum/(4*m)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


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

int main() { /* ここに書く */
  
  int N , M ; 
  cin >> N >> M ;
 
  if( N - M == 0 ){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include<string>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
typedef long long ll;

ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a) {
	long long b = M, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= M;
	if (u < 0) u += M;
	return u;
}
vector<vector<ll>> mul(vector<vector<ll>> a, vector<vector<ll>> b, int n) {
	int i, j, k, t;
	vector<vector<ll>> c(n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			t = 0;
			for (k = 0; k < n; k++)
				t = (t + a[i][k] * b[k][j] % M) % M;
			c[i].push_back(t);
		}
	}
	return c;
}

template< typename Monoid >
struct SegmentTree {

	int sz;
	vector< Monoid > seg;

	const Monoid M1;

	SegmentTree(int n, const Monoid &M1) : M1(M1) {
		sz = 1;
		while (sz < n) sz <<= 1;
		seg.assign(2 * sz, M1);
	}

	void set(int k, const Monoid &x) {
		seg[k + sz] = x;
	}

	void build() {
		for (int k = sz - 1; k > 0; k--) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	void update(int k, const Monoid &x) {
		k += sz;
		seg[k] = x;
		while (k >>= 1) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	Monoid query(int a, int b) {
		Monoid L = M1, R = M1;
		for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
			if (a & 1) L = f(L, seg[a++]);
			if (b & 1) R = f(seg[--b], R);
		}
		return f(L, R);
	}

	Monoid value(const int &k) const {
		return seg[k + sz];
	}

	Monoid f(Monoid a, Monoid b) {
		return a + b;
	}
};

int main() {
	int n, i, a[111111], l, j;
	cin >> n>>l;
	for (i = 1; i <= n; i++)
		cin >> a[i];
	for (i = 1; i < n; i++) {
		if (a[i] + a[i + 1] >= l) {
			cout << "Possible" << endl;
			for (j = 1; j < i; j++)
				cout << j << endl;
			for (j = n - 1; j > i; j--)
				cout << j << endl;
			cout << i << endl;
			return 0;
		}
	}
	cout << "Impossible" << endl;
}

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

vector <long long int> l[26];
vector <long long int> v[26];
vector <long long int> tree[26];

long long int init(int idx,int node, int start, int end)
{
	if (start == end)
	{
		return tree[idx][node] = v[idx][start];
	}
	else
	{
		int mid = (start + end) / 2;
		return tree[idx][node] = init(idx,node * 2, start, mid) + init(idx,node * 2 + 1, mid + 1, end);
	}
}

void lazy(int idx, int node, int start, int end)
{
	if (l[idx][node] != 0)
	{
		tree[idx][node] += (end - start + 1)*l[idx][node];
		if (start != end)
		{
			l[idx][node * 2] += l[idx][node];
			l[idx][node * 2 + 1] += l[idx][node];
		}
		l[idx][node] = 0;
	}
}

void update(int idx, int node, int start, int end, int left, int right, long long int diff)
{
	lazy(idx, node, start, end);
	if (left > end || right < start)
	{
		return;
	}

	if (left <= start && end <= right)
	{
		tree[idx][node] += (end - start + 1)*diff;
		if (start != end)
		{
			l[idx][node * 2] += diff;
			l[idx][node * 2 + 1] += diff;
		}
		return;
	}
	int mid = (start + end) / 2;
	update(idx,node * 2, start, mid, left, right, diff);
	update(idx,node * 2 + 1, mid + 1, end, left, right, diff);
	tree[idx][node] = tree[idx][node * 2] + tree[idx][node * 2 + 1];
}

long long int sum(int idx, int node, int start, int end, int left, int right)
{
	lazy(idx,node, start, end);
	if (left > end || right < start)
	{
		return 0;
	}

	if (left <= start && end <= right)
	{
		return tree[idx][node];
	}

	int mid = (start + end) / 2;
	return sum(idx,node * 2, start, mid, left, right) + sum(idx,node * 2 + 1, mid + 1, end, left, right);
}


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    int n,m,left,right,q;
    char c;
    string s;

    cin >> n;
    cin >> s;

	int h = (int)ceil(log2(n));
	int size = (1 << (h + 1)) - 1;
	for(int i=0;i<26;i++)
	{
		v[i].resize(n);
		l[i].resize(size);
		tree[i].resize(size);
	}

	for(int i=0;i<n;i++)
	{
		int idx = s[i] - 'a';
		v[idx][i] = 1;
	}
	for(int i=0;i<26;i++)
	{
		init(i,1,0,n-1);
	}

	cin >> q;

	for(int i=0;i<q;i++)
	{
		cin >> m;
		if(m==1)
		{
			cin >> left >> c;
			left-=1;
			char iidx = s[left]-'a';
			s[left] = c;
			update(iidx,1,0,n-1,left,left,-1);
			update(c-'a',1,0,n-1,left,left,1);
		}
		else
		{
			cin >> left >> right;
			left-=1;
			right-=1;
			int res = 0;
			for(int j=0;j<26;j++)
			{
				if(sum(j,1,0,n-1,left,right)>0)
				{
					res++;
				}
			}
			cout << res << '\n';
		}
	}
    return 0;
}

Measured memory_bytes: 528796
#include <iostream>

using namespace std;


int main()
{
int n=19;
char gomla[n] ;
//cout<<"enter"<<endl;
for (int i=0 ; i<n ; i++)
{
    cin>>gomla[i];
}

for (int i=0 ; i<n ; i++)
{
    if(gomla[i]==',')
        cout<<" ";
    else
        cout<<gomla[i];
}
    return 0;
}



Measured memory_bytes: 256
from collections import deque

N, M = map(int, input().split())

E = [[int(x) - 1 for x in input().split()] for _ in range(M)]

ans = 0
for i in range(M):
    G = [[] for _ in range(N)]
    for j in range(M):
        if i==j:
            continue
        a, b = E[j]
        G[a].append(b)
        G[b].append(a)


    que = deque([0])

    check = [-1 for _ in range(N)]

    while que:
        v = que.popleft()
        check[v] = 0
        for i in G[v]:
            if check[i] == -1:
                que.append(i)
    if sum(check) < 0:
        ans += 1
print(ans)


Measured memory_bytes: 3316
import numpy as np
A = []
B = 0
N, D = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]
for i in range(N):
  X[i] = np.array(X[i])
for i in range(N):
  for j in range(N):
    if np.linalg.norm(X[i]-X[j]) // 1 == np.linalg.norm(X[i]-X[j]):
      B = B + 1
print((B-N)//2)


Measured memory_bytes: 22728
n=int(input())
A=[int(x) for x in input().split()]

O=[[int(x),0] for x in range(10**5+1)]
E=[[int(x),0] for x in range(10**5+1)]

for i in range(n):
  if i%2==0:
    E[A[i]][1]+=1
  else:
    O[A[i]][1]+=1

O=sorted(O,key=lambda x:-x[1])
E=sorted(E,key=lambda x:-x[1])

if O[0][0]==E[0][0]:
  print(min(n-O[0][1]-E[1][1],n-O[1][1]-E[0][1]))
else:
  print(n-O[0][1]-E[0][1])



Measured memory_bytes: 35820
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;
const int INF=1<<21;
const int maxn=100000+10;
int n,m,q;
int p[maxn];
int rank[maxn];
void init(int n)
{
   for(int i=0;i<n;i++)
   {
       p[i]=i;
       rank[i]=0;
   }
}
int fnd(int x)
{
    if(x==p[x]) return x;
    return fnd(p[x]);
}
bool is_same(int x,int y)
{
   return fnd(x)==fnd(y);
}

void uni(int x,int y)
{
   x=fnd(x);
   y=fnd(y);
   if(rank[x]>rank[y])
   {
       p[y]=x;
   }
   else
   {
       p[x]=y;
       if(rank[x]==rank[y]) rank[y]++;
   }
}

int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d%d",&n,&m);
    int x,y;
    init(n);
    for(int i=0;i<m;i++)
    {
        scanf("%d%d",&x,&y);
        uni(x,y);
    }
    scanf("%d",&q);
    while(q--)
    {
        scanf("%d%d",&x,&y);
        if(is_same(x,y)) printf("yes\n");
        else printf("no\n");
    }


    return 0;
}

Measured memory_bytes: 3932
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=1e6+50;
const int mod=1e9+7;
using namespace std;
int n,k,i;
ll a[nmax],s;
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n>>k;
	for(i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+n+1);
	if(k>=n)rc(0);
	for(i=1;i<=n-k;i++)s+=a[i];
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <iomanip>
//#pragma GCC optimize("Ofast")  //デバッグ時にoptimized-outされて邪魔だった
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  invar(int, A); invar(int, B);
  vector<int> a(3);
  --A; --B;
  a[0] = 1;
  a[1] = 1;
  a[2] = 1;
  a[A] = 0;
  a[B] = 0;
  
  rep(i, 3) {
    if(a[i]){ fin(i+1); return 0;}
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i )

int main(){
  int n; cin >> n;
  vector<int> num(n);
  int c_num = 1,block = 0;
  rep(i,n){
    cin >> num[i];
    if(num[i] == c_num) c_num++;
    else block++;
  }
  if(c_num == 1) cout << -1;
  else cout << block;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
// clang-format off
#define FOR(i, n) for (int i=0; i<(int)n; ++i)
#define RFOR(i, n) for (int i=n-1; i>=0; --i)
#define FORR(x,arr) for(auto& x:arr)
#define OUTV(x) FOR(j,x.size()) cerr<<x[j]<<(x.size()-j-1?' ':'\n');
#define OUTM(x) FOR(i,x.size()) {OUTV(x[i])}
#define DEBUG(x) cerr<<"DEBUG: "<<#x<<" = "<<x<<endl;
#define PB push_back
#define MP make_pair
#define INF 0x3f3f3f3f
int ign;
using namespace std;
typedef signed long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
// clang-format on

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  // std::random_device rd;
  //  std::mt19937 ran(rd());

  int k;
  vi v(5);
  cin >> v[0] >> v[1] >> v[2] >> v[3] >> v[4] >> k;
  sort(v.begin(), v.end());

  if (v[4] - v[0] > k) {
    cout << ":(" << endl;
  } else
    cout << "Yay!\n";

  return 0;
}

Measured memory_bytes: 256
main(N,R,M,m,y,n,t,c,i,d){double r;
	for(scanf("%d",&N);N--;printf("%d\n",R)){
		for(scanf("%d%d%d",&M,&y,&n),R=M;n--;R=m>R?m:R){
			if(m=M,d=0,scanf("%d%lf%d",&t,&r,&c),t){ //fukuri
				for(i=0;i<y;i++){
					d=(int)floor(r*m);
					m=m+d-c;
				}
			}else{ //tanri
				for(i=0;i<y;i++){
					d+=(int)floor(r*m);
					m=m-c;
				}
				m+=d;
			}
		}
	}
exit(0);}

Measured memory_bytes: 0
n,s=map(int,input().split())
a=list(map(int,input().split()))
mod=998244353

dp=[[0]*s for _ in range(n)]    
tmp=1
for i in range(n):
    if a[i]<=s:
        dp[i][a[i]-1]=tmp
    for j in range(s):
        if i>0:
            dp[i][j]+=dp[i-1][j]*2
            dp[i][j]%=mod
            if j+a[i]<s:
                dp[i][j+a[i]]+=dp[i-1][j]
                dp[i][j+a[i]]%=mod
    tmp*=2
    tmp%=mod
            
print(dp[n-1][s-1])

Measured memory_bytes: 139184
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

typedef long double ld;
typedef long long ll;

// Output
template<class T, class S> std::ostream& operator <<(std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator <<(std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }


int main()
{
  ll N;
  std::cin >> N;
  std::vector<ll> va(N, 0LL);
  for (ll i = 0; i < N; ++i) std::cin >> va[i];

  std::string judge = "Yes";
  std::reverse(va.begin(), va.end());
  ll pre = va[0];
  for (ll i = 1; i < N; ++i) {
    ll x = va[i];
    if (x > pre) x--;
    if (x > pre) judge = "No";
    pre = x;
  }

  print(judge);

  return 0;
}


Measured memory_bytes: 1024
#include <cmath>
#include <cstdio>
#include <vector>
#include <iterator>
#include <iostream>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <stdio.h>
#include <functional>
#include <chrono>
using namespace std;

#define rep(i,s,n) for(ll i=s;i<(n);++i)
using ll = long long;
using pll = pair<ll, ll>;
constexpr ll INF = (1LL << 60);
constexpr ll MOD = (1e9 + 7);
//constexpr ll MOD = (998244353);

using vl = vector<ll>;
using vvl = vector<vector<ll>>;

template<class T>
vector<vector<T>> vvt(T init, ll m, ll n) {
	vector<vector<T>> ans = vector<vector<T>>(m, vector<T>(n, init));
	return move(ans);
}

template<class T>
vector<T> vt(T init,ll n) {
	vector<T> ans = vector<T>(n, init);
	return move(ans);
}

template<class T>
T maxVec(vector<T> &v) {
	T ans = -INF;
	rep(i,0, v.size()) {
		ans = max(ans, v[i]);
	}
	return ans;
}

// 素数判定
bool judge(ll n) {
	for (ll i = 2; i * i <= n; i++) if (n %= i)return false;
	return true;
}


template <class C>
void print(const C& c, std::ostream& os = std::cout)
{
	std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, ", "));
	os << std::endl;
}

ll count(ll n,ll r) {
	ll ans = 0,check = 1;
	rep(i,0, r) {
		if ((n & check) > 0) {
			ans++;
		}
		check = check << 1;
	}
	return ans;
}

bool sortreverse(ll a, ll b) {
	return a > b;
}

bool kansu(pll a, pll b) {
	return a.first < b.first;
}

ll kiriage(ll a, ll b) {
	if (a % b == 0)return a / b;
	return a / b + 1;
}

ll dp[410][410];
ll dpcost[410][410];

ll solv(ll i,ll j) {
	if (dpcost[i][j] != -1)return dpcost[i][j];
	ll ref = INF;
	rep(siki, i, j) {
		ref = min(ref, solv(i, siki) + solv(siki + 1, j) + dp[i][j]);
	}
	dpcost[i][j] = ref;
	dpcost[j][i] = ref;
	return ref;
}

int main() {
	ll n;
	cin >> n;
	vl a(n);
	rep(i, 0, n) {
		cin >> a[i];
		dp[i + 1][i + 1] = a[i];
	}

	rep(i, 0, n) {
		rep(j, 0, n) {
			if (i > j)dp[i + 1][j + 1] = dp[i][j + 1] + a[i];
			if (j > i)dp[i + 1][j + 1] = dp[i + 1][j] + a[j];
		}
	}
	rep(i, 0, n+2) {
		rep(j, 0, n+2) {
			if (i != j)dpcost[i][j] = -1;
		}
	}
	printf("%lld\n",solv(1,n));
}

Measured memory_bytes: 2816
import java.util.Scanner;
class Main{
    public static void main(String[] args) {
        //入力
        Scanner scn=new Scanner(System.in);
        int n=scn.nextInt();
        int m=scn.nextInt();
        int c=scn.nextInt();
        int[] b=new int[m];
        int[][] a=new int[n][m];
        for(int i=0;i<m;i++){
            b[i]=scn.nextInt();
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                a[i][j]=scn.nextInt();
            }
        }
        //処理
        int cnt=0;
        int total=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                total+=a[i][j]*b[j];
            }
            if(total+c>0) cnt++;
            total=0;
        }
        //出力
        System.out.println(cnt);
    }
}

Measured memory_bytes: 22996
import itertools

n = int(input())
p_list = list(map(int, input().split()))
q_list = list(map(int, input().split()))
num_list = []
num = 0
a = 0
b = 0

for i in itertools.permutations(range(1,n+1)):
    num_list = list(i)
    num += 1
    if num_list == p_list:
        a = num
    if num_list == q_list:
        b = num

print(abs(a-b))

Measured memory_bytes: 3064
require "set"
n,k = gets.chomp.split(" ").map(&:to_i)
ab_arr = (n-1).times.map{gets.chomp.split(" ").map(&:to_i)}

if n == 1 then
  puts k
  exit 0
end

hash = {}
ab_arr.each do |(a, b)|
  hash[a] ||= []
  hash[a] << b
  hash[b] ||= []
  hash[b] << a
end

perm_hash = {}
perm = lambda {|i, j|
  return 1 if j == 0
  result = 1
  j.times do |t|
    result *= (i - t)
    result %= 1000000007
  end
  perm_hash[[i,j]] = result
  return result
}

a,b = ab_arr[0]
count = k
set = Set.new
set.add(a)
count *= perm.call(k-1, hash[a].length)
stack = hash[a]

while stack.length > 0 do
  c = stack.pop()
  set.add(c)
  children = hash[c].select{|cc|!set.include?(cc)}
  count *= perm_hash[[k-2,children.length]] || perm.call(k-2, children.length)
  count %= 1000000007
  children.each do |cc|
    stack.push(cc)
  end
end
puts count


Measured memory_bytes: 29692
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# 初項s, 交差dのn個の数列の和
def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    N = int(input())
    V = list(map(int, input().split()))
    C = list(map(int, input().split()))

    ans = 0
    for i in range(N):
        if V[i] > C[i]:
            ans += V[i] - C[i]
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3952
import java.util.Scanner;



public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		long a = 1;
		for (int i=0;i<k;i++) {
			System.out.println(a);
			a++;
			double min = a/digitSum(a);
			for (int j=0;j<Math.log10(a)+1;j++) {
				long b = (a/(long)Math.pow(10, j)*(long)Math.pow(10, j)+(long)Math.pow(10, j)-1);
				if (min>b/digitSum(b)) {
					min = b/digitSum(b);
					a=b;
				}
			}
		}
	}
	
	static double digitSum(long x) {
		double ans = 0;
		while (x>0) {
			ans += (x%10);
			x/=10;
		}
		return ans;
	}

}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep_3(i, initial, n) for (int i = (int)(initial); i < (int)(n); ++i)
#define repeat(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int i = (int)(n); i > 0; i--)
#define rep_r_3(i, initial, n) for (int i = (int)(initial); i > (int)(n); i--)
#define repeat_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define variable
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const double EPS = numeric_limits<double>::epsilon();
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main()
{
	ll N, X;
	cin >> N >> X;

	vector<ll> x(N, 0);

	ll max = 0;
	repeat(i, N) {
		ll x = 0;
		cin >> x;

		ll diff = abs(X - x);
		max = gcd(max, diff);
	}

	cout << max << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

//#define P 1000000007
#define P 998244353

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}
int compw(const void *a, const void *b){return (*(int*)a>*(int*)b)-(*(int*)a<*(int*)b);}

uint32_t nextpint(void){
	char c=getchar();
	while(c<'0'||'9'<c) c=getchar();
	uint_fast32_t x=0;
	while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); }
	return x;
}

#define N 200000
inline int max(const int a, const int b){ return a>b?a:b; }
int m;
int dat[524288-1];

void init(int n){
	m=1;
	while(m<n) m*=2;
}

void update(int k, int x){
	k+=m-1;
	dat[k]=x;
	while(k>0){
		k=(k-1)/2;
		dat[k]=max(dat[k*2+1], dat[k*2+2]);
	}
}

// q(a, b, 0, 0, m)
// [a, b)
int query(int a, int b, int k, int l, int r){
	if(r<=a || b<=l) return 0;
	if(a<=l && r<=b) return dat[k];
	int m=(l+r)/2;
	int vl = query(a, b, k*2+1, l, m);
	int vr = query(a, b, k*2+2, m, r);
	return max(vl, vr);
}

int n;
int x[N][2];
int bs(int X){
	int l=0, r=n-1;
	while(l<=r){
		int m=(l+r)/2;
		if(x[m][0]>=X) r=m-1; else l=m+1;
	}
	return l;
}
int d[N+1];
int main(int argc, char *argv[], char *envp[]){
	scanf("%d", &n);
	for(int i=0; i<n; i++){
		scanf("%d%d", &x[i][0], &x[i][1]);
	}
	qsort(x, n, sizeof(int)*2, comp);
	init(n);
	for(int i=n-1; i>=0; i--){
		int l=bs(x[i][0]+x[i][1])-1;
		int r=i;
		if(i<l){
			int j=query(i+1, l+1, 0, 0, m);
			if(j>r) r=j;
		}
		update(i, r);
	}
	d[n]=1;
	for(int i=n-1; i>=0; i--){
		d[i]=(d[i+1]+d[dat[i+m-1]+1])%P;
	}
	printf("%d\n", d[0]);
}


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

int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    ll x[n];
    for(ll i=0;i<n;i++) cin >> x[i];
    ll res=0;
    for(ll i=0;i<n-1;i++){
        if((x[i+1]-x[i])*a<=b) res+=(x[i+1]-x[i])*a;
        else res+=b;
    }
    cout << res << endl;
}


Measured memory_bytes: 4376
package main

import (
	"fmt"
)

func main() {
	var n, m, c int
	fmt.Scan(&n, &m, &c)
	b := make([]int, m)
	var num int
	for i := 0; i < m; i++ {
		fmt.Scan(&num)
		b[i] = num
	}
	a := make([][]int, n)
	for i := 0; i < n; i++ {
		a[i] = make([]int, m)
		for j := 0; j < m; j++ {
			fmt.Scan(&num)
			a[i][j] = num
		}
	}
	counter := 0
	for i := 0; i < n; i++ {
		num = 0
		for j := 0; j < m; j++ {
			num += a[i][j] * b[j]
		}
		if num + c > 0 {
			counter++
		}
	}
	fmt.Println(counter)
}


Measured memory_bytes: 512
use std::io::*;
use std::str::FromStr;
use std::collections::VecDeque;

fn main() {
    let n: usize = read();
    let mut graph = vec![vec![]; n];
    for i in 0..n-1 {
        let a: usize = read();
        let b: usize = read();
        graph[a-1].push((b-1, i));
        graph[b-1].push((a-1, i));
    }

    let mut que = VecDeque::new();
    que.push_back((0, 0));
    let mut color = vec![0; n-1];
    let mut max = 0;
    while let Some(q) = que.pop_front() {
        let (v, c) = q;
        let mut prev = 0;
        for &(po, index) in &graph[v] {
            if color[index] != 0 {
                continue;
            }
            let mut next = prev + 1;
            if next == c {
                next += 1;
            }
            color[index] = next;
            que.push_back((po, next));
            max = std::cmp::max(max, next);
            prev = next;
        }
    }

    println!("{}", max);
    for i in &color {
        println!("{}", i);
    }
}

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


Measured memory_bytes: 14716
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <unordered_map>
#include <queue>
#include <set>

using namespace std;

#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;


int main(){
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int max_length=0, r=0, l=0, count=0;
    char tmp;
    while(r < n){
        while (count < k && r < n){
            if (s[r] == '0') {
                count++;
                while(s[r] == '0' && r < n) r++;
                while(s[r] == '1' && r < n) r++;
            }
            else{
                while(s[r] == '1' && r < n) r++;
            }
        }
        max_length = max(max_length, r - l);
        count--;
        while(s[l] == '1') l++;
        while(s[l] == '0') l++;
    }
    cout << max_length << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int maxn=2e5+10;
int n;
ll T,a[maxn],b[maxn];
int od[maxn];
bool less2(int x,int y)
{
	return a[y]*(b[x]+1)<a[x]*(b[y]+1);
}
ll lft[maxn][50];
void solve(int st)
{
	vector<ll> bs;bs.clear();
	for(int i=st;i<n;i++)
	{
		bs.push_back(b[od[i]]+1);
	}
	sort(bs.begin(),bs.end());
	for(int i=1;i<bs.size();i++)bs[i]+=bs[i-1];
	int ans=0;
	for(int j=0;j<50;j++)
	{
		ll L=lft[st][j];
		if(L>T)break;
		ans=max(ans,j+int(lower_bound(bs.begin(),bs.end(),T-lft[st][j]+1)-bs.begin()));
	}
	printf("%d\n",ans);
	exit(0);
}
int main()
{
	scanf("%d%lld",&n,&T);
	for(int i=0;i<n;i++)
	{
		scanf("%lld%lld",&a[i],&b[i]);
		od[i]=i;
	}
	sort(od,od+n,less2);
	memset(lft,0x3f,sizeof(lft));
	lft[0][0]=0;
	for(int i=0;i<n;i++)
	{
		int k=od[i];
	//	cout<<k<<endl;
		if(!a[k])
		{
			solve(i);
			return 0;
		}
		for(int j=0;j<=i&&j<50;j++)
		{
			if(lft[i][j]>T)break;
		//	cout<<i<<" "<<j<<" "<<lft[i][j]<<endl;
			lft[i+1][j]=min(lft[i+1][j],lft[i][j]);
			if(lft[i][j]+1+(a[k]*(lft[i][j]+1)+b[k])<=T)
			{
				lft[i+1][j+1]=min(lft[i+1][j+1],lft[i][j]+1+(a[k]*(lft[i][j]+1)+b[k]));
			}
		}
	}
	for(int i=49;i>=0;i--)if(lft[n][i]<=T)
	{
		printf("%d\n",i);
		return 0;
	}
}

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

using namespace std;

int main()
{
    long long cnt[10010];
    long long ans = 0;
    string s;
    int n,p;
    
    cin >> n >> p >> s;
    
    if(p == 2 || p == 5)
    {
        for(int i = 0;i < n;i++) 
            if((s[i] - '0') % p == 0) 
                ans += i + 1;
    }
    else
    {
        cnt[0] = 1;
        long long cur = 0,t = 1;
        for(int i = n - 1;i >= 0;i--)
        {
            cur = (cur + (s[i] - '0')*t%p) % p;
            t = t*10%p;
            ans += cnt[cur]++;
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 644
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;
//abc161
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    cout<<a<<' '<<b<<' '<<c<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
(全探索できるなら全探索しろ)
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'\n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え(=でもエラー出ない)
*/

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

using namespace std;
typedef unsigned long long ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
typedef pair<ll, pair<ll, ll > > iip;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;

int main(){

    ll N;
    cin >> N;

    map<ll, ll > mp;

    for(ll i = 0; i < N; i++){
        ll t = 0; cin >> t;
        mp[t]++;
    }

    priority_queue<pi> que;
    auto begin = mp.begin(), end = mp.end();
    for (auto iter = begin; iter != end; iter++) {
        if(iter -> second >= 2){
            que.push(make_pair(iter->first, iter->second));
        }
    }

    if(que.size() < 2){
        cout << 0 << endl;
    }else{
        if(que.top().second >= 4){
            ll a = que.top().first; que.pop();
            cout << a * a << endl;
        }else{
            ll a = que.top().first; que.pop();
            ll b = que.top().first; que.pop();
            cout << a * b << endl;
        }
    }
}

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

using namespace std;

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

    for (int i = 0; 4 * i <= n; ++i) {
        for (int j = 0; 4 * i + 7 * j <= n; ++j) {
            if (4 * i + 7 * j == n) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int X = sc.nextInt();
    int[]m = new int[N];
 
    int all = 0;
    for(int i=0; i<N; i++){
        m[i] = sc.nextInt();
        	all +=  m[i];
}
    int a = X-all;
    Arrays.sort(m);
    
	System.out.println(a/m[0]+N);
    }
}


Measured memory_bytes: 36028
def main():
    N = int(input())
    a = int(input())

    r = N%500

    if r == 0:
        print ('Yes')
    elif a >= r:
        print ('Yes')
    else:
        print ('No')


if __name__ == "__main__":
    # global stime
    # stime = time.clock()
    main()


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

int main(){
  int64_t N;
  cin >> N;

  unordered_set<int64_t> divs;
  // まず2以上であるN-1の約数を追加
  if(N-1 > 1){ divs.insert(N-1); }
  int64_t div= 2;
  while(div*div < N){
    if((N-1)%div==0){
      divs.insert(div);
      divs.insert((N-1)/div);
    }
    div++;
  }

  // Nの約数を(N自身とsqrt(N)以下のものを試して)追加
  divs.insert(N);
  div= 2;
  while(div*div <= N){
    int cnt= 0;
    int64_t tmp= N;
    while(tmp%div==0){
      cnt++;
      tmp/= div;
    }
    if(cnt > 0 && tmp%div==1){
      divs.insert(div);
    }

    div++;
  }
  
  cout << divs.size() << endl;
}

Measured memory_bytes: 384
import java.util.*;
import java.io.*;
class Main{
  public static void main(String args[]){
    StringBuilder bl = new StringBuilder();
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int u = 0;
    int k = 0;
    int v = 0;
    int M[][] = new int[n][n];

    for(int i = 0; i<n; i++){
      for(int j = 0; j<n; j++){
        M[i][j] = 0;
      }
    }

    for(int i = 0; i<n; i++){
      u = sc.nextInt();
      k = sc.nextInt();
      for(int j =0; j<k; j++){
        v = sc.nextInt();
        M[u-1][v-1] = 1;
      }
    }

    for(int i = 0; i<n; i++){
      for(int j = 0; j<n; j++){
        if(j!=0)bl.append(" ");
        bl.append(M[i][j]);
      }
      bl.append("\n");
    }
    System.out.print(bl);
  }
}


Measured memory_bytes: 29072
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#include <time.h>
#include <ctype.h>

int cmp(const void *a, const void *b) { return *(int*)a - *(int*)b; }
int max(int a, int b) { return a >= b ? a : b; }
int min(int a, int b) { return a <= b ? a : b; }
int dsum(int x) { int r=0; while(x){ r+=(x%10); x/=10; } return r;}
void swap(int *a, int *b) { int tmp; tmp = *a; *a = *b; *b = tmp; return; }

int main(void) {
  double r,l;
  int sights[5][3] = {};
  while(scanf("%lf%lf",&r,&l) != EOF) {
    if(l >= 1.1) sights[0][1]++;
    else if(l >= 0.6) sights[1][1]++;
    else if(l >= 0.2) sights[2][1]++;
    else sights[3][1]++;
    if(r >= 1.1) sights[0][0]++;
    else if(r >= 0.6) sights[1][0]++;
    else if(r >= 0.2) sights[2][0]++;
    else sights[3][0]++;
  }
  for(int i=0; i<4; i++) {
    for(int j=0; j<2; j++) {
      if(j == 0) printf("%d ",sights[i][j]);
      else printf("%d\n",sights[i][j]);
    }
  }
  return 0;
}


Measured memory_bytes: 2032
#include <iostream>
#include <string>

using namespace std;

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

  double x;
  string s;
  double y=0.0;
  for(int i=0;i<n;++i) {
    cin >> x >> s;
    if (s=="BTC") y+=x*380000.0;
    else y+=x;
  }
  cout << y << endl;

  return 0;
}


Measured memory_bytes: 256
def resolve():
    def main():
        s=input()
        for i in ['+','-']:
            for m in ['+','-']:
                for n in ['+','-']:
                    a=s[0]+i+s[1]+m+s[2]+n+s[3]
                    if eval(a)==7:
                        return a
    print(main(), '=7',sep='')
resolve()

Measured memory_bytes: 3060
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
 
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define pb push_back
#define pp pop_back
#define F first
#define S second
#define endl "\n"
#define ll long long                                           
#define ld long double
#define lb lower_bound
#define ub upper_bound
#define pii pair<int, int>
#define pss pair<string, string>
#define pll pair<long long, long long> 

//template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

void INeedIT() {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}

int pre[123456];
 
int main () {
	INeedIT();
	int n, m, ans=0;
	cin>>n>>m;
	for (int i=0;i<m;i++) {
		int l, r;
		cin>>l>>r;
		pre[l]++;
		pre[r+1]--;
	}
	pre[0]=0;
	for (int i=1;i<=n;i++) {
		pre[i]+=pre[i-1];
	}
	for (int i=1;i<=n;i++) {
		if (pre[i]==m) {
			ans++;
		}
	}
	cout<<ans;
	return 0;
}	

Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
using namespace std;
char s[110];
int n,pos,maxn;//pos存储当前高度，maxn存储最高高度
int main()
{
    scanf("%d%s",&n,s+1);//读入字符串的长度和字符串
    for(int i=1;i<=n;++i)
    {
        if(s[i]=='I') ++pos;//判断如果是‘I’，高度++
        else --pos;//否则高度--
        maxn=max(maxn,pos);//每次选取最大值
    }
    printf("%d\n",maxn);//输出答案
    return 0;//完美结束
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
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 dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int n;
vector<vector<int>> g;
bool ok = 1;
int x[1005];
int f[1005]; // dp[i] := 部分木iでiと同じ色の重みの和がx[i]になるようにしたときのもう一方の重みの和の最小値


int dfs(int now){
    if(!ok)return 0;
    if(f[now]<1e9+7)return f[now];
    int ret = 1e9 + 7;
    int size = g[now].size();
    vector<vector<int>> dp(size+1,vector<int>(5005,1e9+7));
    // dp[i][j] := i番目まで見てnowと同じ色の重みの和がjとなったときのもう一方の重みの和の最小値
    dp[0][0] = 0;
    for(int i=0;i<size;i++){
        int next = g[now][i];
        rep(j,x[now]+1){
            // next と違う色で塗った場合
            if(j>=dfs(next))chmin(dp[i+1][j],dp[i][j-dfs(next)] + x[next]);
            // next と同じ色で塗った場合
            if(j>=x[next])chmin(dp[i+1][j],dp[i][j-x[next]] + dfs(next));
        }
    }
    rep(j,x[now]+1)ret = min(ret,dp[size][j]);
    if(ret>=1e9+7){
        ok = 0;
        return 1e9+7;
    }
    return f[now] = ret;
}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cin >> n;
    g.resize(n);
    rep(i,n-1){
        int a = i+1;
        int b;
        cin >> b;
        b--;
        g[b].push_back(a);
    }
    rep(i,n)cin >> x[i];
    rep(i,1005)f[i] = 1e9 + 7;
    if(dfs(0)<1e9+7 && ok)cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 20980
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;
vector <ll> v;
int main(){
int n;
cin >> n;
ll a[n];
ll sum=0;
for(int i=0;i<n;i++){
cin >> a[i];
sum+=a[i];
}
double k=(double)sum/(double)n;
double min=10000;
int flag=0;
int ans=0;
for(int i=0;i<n;i++){
  double u=k-a[i];
  if(u<0) u=-u;
  if(u<min){
     min=u;
  }
}
for(int i=0;i<n;i++){
  double u=k-a[i];
  if(u<0) u=-u;
  if(u==min) v.push_back(i);
}
sort(v.begin(),v.end());
cout << v[0]<<endl;
}


Measured memory_bytes: 256
def check(i):
    for s, c in qs:
        if i[s-1] != str(c):
            return False
    return True

N, M = map(int, input().split())
qs = []
for _ in range(M):
    s, c = map(int, input().split())
    qs.append((s,c))

for i in range(0 if N==1 else 10**(N-1), 10**N):
    i = str(i)
    if check(i):
        print(i)
        break
else:
    print(-1)


Measured memory_bytes: 38256
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;

int n;
int a[N];
vector < int > idx;

bool cmp(int x , int y){
    if(a[x] < a[y])
        return 1;
    return 0;
}

int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        idx.push_back(i);
    }
    sort(idx.begin() , idx.end() , cmp);
    for(auto v : idx){
        cout << v << " ";
    }

}

Measured memory_bytes: 1656
#include <bits/stdc++.h>
using namespace std;
bool cmp(int a,int b)
{
    return a<b;
}
int main()
{
   int n,k;
   int a[1005];
   cin>>n>>k;
   for(int i=0;i<n;i++)
    cin>>a[i];
   sort(a,a+n,cmp);
   int sum=0;
   for(int i=0;i<k;i++)
        sum+=a[i];
   cout<<sum;
    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;

void input() {
  ;
  ;
  cin >> N >> M;
}
void solve() {
  ;
  cout << (N == M ? "Yes" : "No");
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sf sacnf
#define pf printf
#define ll long long
#define ull unsigned long long
#define ii pair <int,int>
#define iii pair <int,ii>
#define pll pair <ll,ll>
#define plll pair <ll,pll>
#define Ziru 0
using namespace std;

int main(){
    int a;
    vector <int> v;

    for(int i=0; i<3; i++){
        cin>>a;
        v.push_back(a);
    }
    sort(v.begin(),v.end());
    int len=v.size();

    for(int i=0; i<len-1; i++){
        cout<<v[i]<<" ";
    }
    cout<<v[len-1]<<endl;

    return Ziru;
}






Measured memory_bytes: 3160