akhauriyash/Code-Regression huggingface dataset:
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>
#include <list>
#include <cassert>
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 998244353
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pNO cout << "NO" << endl
#define pYES cout << "YES" << endl
#define endl "\n"
#define pi 3.14159265358979
using namespace std;
using ll = long long;
#define int ll

signed main() {
	int N, K; cin >> N >> K;
	vector<int> dp(N+1);
	vector<int> acc(N + 1);
	vector<vector<int>> LR(K, vi(2)); // {left,right}
	dp[1] = 1; acc[1] = 1;
	for (int i = 0; i < K; i++) {
		int l, r; cin >> l >> r;
		LR[i] = { l,r };
	}
	//kkまで使ったときの飛び方
	//マスはすべて1-indexed
	for (int pos = 1; pos < N + 1; pos++){
		//逐次累積和
		assert(dp[0] == 0 && acc[0] == 0);

		for (int kk = 0; kk < K; kk++) {
			int Lind = pos - LR[kk][0];
			int Rind = pos - LR[kk][1] - 1;
			Lind = max(Lind, ll(0)); Rind = max(Rind, ll(0));
			int A = acc[Lind] - acc[Rind];
			if (A < 0) A += MOD;
			dp[pos] += A; dp[pos] %= MOD;
			acc[pos] = acc[pos - 1] + dp[pos];
			acc[pos] %= MOD;
		}

	}
	cout << dp[N] << endl;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  
  
  for(int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  int count = 0;
  int current = 1;
  int tmp = 0;
  while(current > 0){
    tmp = vec.at(current-1);
    vec.at(current-1) = 0;
    current = tmp;
    count++;
    
    if(current == 2){
      cout << count << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))

#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s))
#define repiins(x, y, z, s) for ((x) = (z); (x) <= (y); (x) += (s))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define repit2(x) for (__typeof((x).begin()) it2 = (x).begin(); it2 != (x).end(); it2++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)

#define All(x) (x).begin(),(x).end()

#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))

#define Unique(v) v.resize(unique(All(v)) - v.begin())

#define peq(p0, p1)(p0.first == p1.first && p0.second == p1.second)

#define End '\n'
#define Out(x) cout<<(x)<<End
#define OutP(p, sep, end) cout<<p.first<<sep<<p.second<<end

template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define Sort(v) sort(All(v))
#define SortR(v) sort(All(v), std::greater<__typeof(v[0])>())

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lb std::lower_bound
#define ub std::upper_bound

#define lbi(v, x) lb(All(v), (x))-v.begin()
#define ubi(v, x) ub(All(v), (x))-v.begin()

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);
	//std::cout.precision(18);

    int n;
	double t, a;

	cin >> n;
	cin >> t >> a;

	double ans = DBL_MAX;
	double h;
  	int index = 0;

	int i;

	rep(i, n) {
		cin >> h;

		if (Abs(a - (t - h * 0.006)) < ans) {
          	ans = Abs(a - (t - h * 0.006));
          	index = i + 1;
        }
	}

	Out(index);
	
	return 0;
}


Measured memory_bytes: 256
n = int(input())
count = 0
max = 0
for i in range(n):
    dice1,dice2 = [int(a) for a in input().split()]
    if dice1 == dice2:
        count += 1
    else:
        count = 0
        tmp = 0
    if max <= count:
        max = count
if max >= 3:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9164
n,m = list(map(int,input().split()))
path = [list(map(int,input().split())) for _ in range(m)]

graph = [[] for _ in range(n)]
for a,b in path:
    graph[a-1].append(b-1); graph[b-1].append(a-1)

parents = [-1]*n
tmparr = []
children = [0]
flags = [True] * n
flags[0] = False

while any(flags):
    while children:
        tmp = children.pop()
        for node in graph[tmp]:
            if flags[node]:
                flags[node] = False
                parents[node] = tmp
                tmparr.append(node)
    children = tmparr[:]
    tmparr = []
    
print("Yes")
for i in parents[1:]:
    print(i+1)

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

int main() {
	ll n;
	cin >> n;
	vector<ll>a(n);
	for (int i = 0; i < n; i++)cin >> a.at(i);
	ll money = 1000;
	ll stock = 0;
	for (int i = 0; i < n - 1; i++) {
		if (a.at(i) < a.at(i + 1)) {
			stock += money / a.at(i);
			money -= (money / a.at(i)) * a.at(i);
		}
		else if (a.at(i) > a.at(i + 1)) {
			money += stock * a.at(i);
			stock = 0;
		}
	}
	money += stock * a.at(n - 1);
	stock = 0;
	cout << money << endl;
}

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

int main(){
	int A[100][100];
	int B[100];
	int C[100];
	int n=0,m=0;

	cin >> n >> m;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin >> A[i][j];
			}
		}
	for(int j=0;j<m;j++){
		cin >> B[j];
		}
	for(int i=0;i<n;i++){
		C[i]=0;
		for(int j=0;j<m;j++){
			C[i]+=A[i][j] * B[j];
			}
		}
	for(int i=0;i<n;i++){cout<<C[i]<<endl;}
	return 0;
}

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

s = []
for _ in range(n):
	temp = input()
	s.append((len(temp),list(temp)))

s.sort()

checker = sorted(s[0][1])
res = []
for ch in checker:
	truth = True
	for word in s:
		if ch not in word[1]:
			truth = False
			break
	if truth:
		res.append(ch)
		for word in s:
			word[1].remove(ch)

print(''.join(res))

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn ll
#define int ll
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;


signed main() {
	ios::sync_with_stdio(false);
	int i, j;
	int a, b, t;
	cin >> a >> b >> t;
	int ans = 0;
	for (int i = 0; i < t / a; i++) {
		ans += b;
	}
	cout << ans;
		return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long x,y,a,b,c,kotae;
  cin>>x>>y>>a>>b>>c;
  vector<long> red(a);
  vector<long> green(b);
  vector<long> mu(c);
  vector<long> ans(x+y);
  for(int i=0; i<a; i++){
    cin>>red.at(i);
  }
  for(int i=0; i<b; i++){
    cin>>green.at(i);
  }
  for(int i=0; i<c; i++){
    cin>>mu.at(i);
  }
  sort(red.begin(),red.end());
  sort(green.begin(),green.end());
  sort(mu.begin(),mu.end());
  for(int i=0; i<x+y; i++){
    if(i<x){
      ans.at(i)=red.at(a-1-i);
    }
    else{
      ans.at(i)=green.at(b-i+x-1);
    }
  }
  sort(ans.begin(),ans.end());
  for(int i=0; i<c; i++){
    if(i>=x+y){
      break;
    }
    if(ans.at(i)<mu.at(c-i-1)){
      ans.at(i)=mu.at(c-i-1);
    }
    else{
      break;
    }
  }
  kotae=0;
  for(int i=0; i<x+y; i++){
    kotae=ans.at(i)+kotae;
  }
  cout<<kotae;
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn = 1e6 + 10;
int main(){
	ll a,b,c,d;
	ll sum;
	cin>>a>>b>>c>>d;
	sum = max(b * c,b * d);
	sum = max(sum,a * c);
	sum = max(sum,a * d);
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;


int main() {
	int n, l;
	cin >> n >> l;
	int a = 0;
	for (int i = 1; i <= n; i++) {
		a += i;
	}
	int b = (l - 1) * n + a;
	int c = 10000;
	for (int i = 1; i <= n; i++) {
		if (i == 1) {
			c = l;
		}
		else {
			if (l + i - 1 == 0) {
				c = 0;
				break;
			}
			else if (l + i - 1 < 0) {
				if (l + i - 1 > c) {
					c = l + i - 1;
				}
			}
		}
	}
	cout << b - c << endl;
}

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

// コンテスト中のみ
#define int long long

#define ll long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define P pair<ll,ll>
int MOD = 1000000007;
const ll INF = 1LL << 60;


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n; cin >> n;
	vector<int>a(n);
	rep(i, n) {
		cin >> a[i];
	}
	sort(a.rbegin(), a.rend());
	int ans = a[0];
	for (int i = 1; i < n / 2; i++) {
		ans += a[i] * 2;
	}
	if (n % 2 == 1) {
		ans += a[n / 2];
	}
	cout << ans << endl;
	return 0;
}

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

int kaijo(int N){
  int ans=1;
  for(int i=1;i<=N;i++){
    ans*=i;
  }
  return ans;
}


int main() {
long N,M;
cin>>N>>M;
vector<vector<long>> l(N, vector<long>(N));

for(int i=0;i<M;i++){
  int a,b;
  cin>>a>>b;
  a--;
  b--;
  l[a][b]=1;
  l[b][a]=1;
}
vector<int> d(N);
  for(int i=0;i<N;i++) d[i]=i+1;
int ans=0;
  for(int i=0;i<kaijo(N-1);i++){
    bool flg=true;
    int j=0;

    while(j<N-1){
      if(l[d[j+1]-1][d[j]-1]==0) {
        flg=false;
        break;
      }
      j++;
    }

    if(flg) ans++;
    next_permutation(d.begin(),d.end());
  }
cout<<ans<<endl;
}


Measured memory_bytes: 256
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
void times(alias pred)(int n) {
    foreach(i; 0..n) pred();
}
auto rep(alias pred, T = typeof(pred()))(int n) {
    T[] res = new T[n];
    foreach(ref e; res) e = pred();
    return res;
}

void main() {
    bool[] top = readln.chomp.map!(a => a=='p').array;
    int N = top.length.to!int;
    int[] ary = new int[N+1];
    foreach(i, e; top) {
        ary[i+1] = ary[i] + (e ? -1:1);
    }
    writeln(ary.back/2);
}


Measured memory_bytes: 928
#include <bits/stdc++.h>
using namespace std;
 
#define fill(a,val) memset(a, (val), sizeof a)
#define pb push_back
#define lli long long int
#define scantype int
#define endl "\n"
#define unique(x) x.erase(unique(x.begin(),x.end()), x.end())
#define debug(x) cerr << #x " = " << (x) << '\n'
#define what_is(x) cerr << #x << " is " << x << endl;
 
lli MOD  = 1000000007;
lli inf = 1e15;
 
void scan(scantype &x);

lli powermod(lli _a,lli _b,lli _m){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
lli string_to_number(string s){lli x=0; stringstream convert(s); convert>>x; return x;}
lli add(lli a,lli b){lli x = (a+b)%MOD; return x; }
lli mul(lli a,lli b){lli x = (a*b)%MOD; return x; }
lli sub(lli a,lli b){lli x = (a-b+MOD)%MOD; return x; }
lli div(lli a,lli b){lli x = a;lli y = powermod(b,MOD-2,MOD);lli res = (x*y)%MOD;return res;}

bool isprime(long long int n)
{
    if(n ==1 )
        return false;
    if(n == 2)
        return true;
    for(long long int i =2;i<=n/i;i++)
    {
        if(n%i == 0)
            return false;
    }
    return true;
}
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);   
    int t;
    t = 1;
    while(t--)
    {
        lli n,m;

        cin>>n;
        m = n;
        n = 3*n;
        std::vector<lli> v;
        while(n--)
        {
            lli x;
            cin>>x;
            v.pb(x);
        }
        sort(v.rbegin(),v.rend());
        lli ans = 0;
        int c = 0;
        for(int i = 0;i<v.size();i++)
        {
            if(i%2)
            {
                c++;
                ans += v[i];
            } 
            if(c >= m )
                break; 
        }
        cout<<ans;

    }    


    
    return 0;    
}
 

void scan(scantype &x)
{
    register int c = getchar(); //for negative/positive
    x = 0;
    int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = getchar());
    if(c=='-') {neg=1;c=getchar();}
    for(;c>47 && c<58;c = getchar()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}


Measured memory_bytes: 6000
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <cstdlib>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 1044266558
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
int main()
{
    int n;
    cin>>n;
    cout<<48-n<<endl;
    return 0;
}

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

int main()
{
    int n;
  string s;
  cin>>n>>s;
  int dem=0;
  while(s.find("ABC")!=string::npos)
  {
      dem++;
      s.erase(s.find("ABC"),3);
  }
  cout<<dem<<endl;
}



Measured memory_bytes: 256
n,m=map(int,input().split())
p=[[int(input()),0]for _ in range(n)]
q=[[int(input()),1]for _ in range(m)]
a=p+q
a.sort()
pp=n+1
qq=m+1
ans=0
for x,f in a:
  if f==0:
    ans+=x*qq
    pp=max(0,pp-1)
  else:
    ans+=x*pp
    qq=max(0,qq-1)
print(ans)

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

typedef long long ll;
typedef int64_t i6;
typedef std::vector<std::vector<int64_t> > Graph;

#define rep(i, n) for (int64_t i = 0; i < n; ++i)
#define rep2(i, n) for (int64_t i = 1; i <= n; ++i)
#define repb(i, l, n) for (int64_t i = l; i < n; ++i)
#define repb2(i, l, n) for (int64_t i = l; i <= n; ++i)
#define repe(a, b) for (auto&(a) : (b))
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x) Sort(x);reverse(ALL(x))
#define mp(a, b) make_pair((a), (b))
#define Push_back(a, b) push_back( mp( (a), (b) ) )

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;  } return 0;  }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;  } return 0;  }
template<typename V,typename T> bool find_num(V v, T num) { if ( find(ALL(v), num) == v.end() ) { return false; } return true; }

const int inf = 0x3fffffff;
const int64_t INF = 0x3fffffffffffffff;
const int64_t MOD = 1e9+7;

int main() {
  	int n;cin >> n;
  	rep(i, n) {
    	cout << "ACL";
    }
  	cout << endl;
    return 0;
}

Measured memory_bytes: 3580
#include <stdio.h>

int main(void){
	int a,b,sum,p,q=0;
	while(1){
		if(scanf("%d%d",&a,&b) == EOF)
			break;
		sum=a+b;
		p=0;
		while(sum!=0){
			sum/=10;
			p++;
		}
		printf("%d\n",p);
	}
	return 0;
}

Measured memory_bytes: 596
fn main() {
    let v = read_vec::<usize>();
    let n = v[0];
    let _ = v[1];
    let mut ss = vec![];
    for _ in 0..n {
        ss.push(read::<String>());
    }
    ss.sort();
    println!("{}", ss.join(""));
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(ll i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(ll i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n,m;
    cin>>n>>m;
    cout<<(n-1)*(m-1)<<endl;
    return 0;
}

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


int n, x, y, r[2005], visited[2005];
vector<vector<int>> v(2005);


void count(int s) {
	rep(i, n)
		visited[i] = 0;
	visited[s] = 1;
	int d = 1;
	vector<int> vt = v[s];
	while(!vt.empty()) {
		vector<int> vt2;
		for(auto node: vt) {
			if (visited[node]) continue;
			visited[node] = 1;
			r[d] += 1;
			for(auto n2: v[node]) {
				vt2.push_back(n2);
			} 
		}
		vt = vt2;
		d++;
	}
}

int main() {
	cin >> n >> x >> y;
	rep(i, n - 1) {
		v[i].push_back(i + 1);
		v[i + 1].push_back(i);
	}
	v[x - 1].push_back(y - 1);
	v[y - 1].push_back(x - 1);
	rep(i, n) {
		count(i);
	}
	for(int i = 1; i <= n - 1; i++) {
		cout << r[i] / 2 << endl;
	}
}


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

using namespace std;
int binarySearch(vector<int> int_array,int val){
    int key = val;
    int right = int_array.size();
    int left  = 0;
    while(left < right){
        int mid = (left + right)/2;
        if(int_array[mid]==key) return mid;
        else if(key < int_array[mid]) right = mid;
        else left = mid + 1;
    }
    return -1;
}

int main(){
    int len_array1,len_array2;
    
    scanf("%d",&len_array1);
    vector<int> objective_array(len_array1,0);
    for(int i = 0;i < len_array1;i++) scanf("%d",&objective_array[i]);

    scanf("%d",&len_array2);
    vector<int> search_array(len_array2,0);
    for(int i = 0;i < len_array2;i++){
        scanf("%d",&search_array[i]);
        if(binary_search(objective_array.begin(),objective_array.end(),search_array[i])) printf("1\n");
        else printf("0\n");
    }
    return 0;   
}


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

using namespace std;

#define TEMP_T template<typename T>
TEMP_T void sort(T& v){ sort(v.begin(), v.end()); }
TEMP_T void revs(T& v){ reverse(v.begin(), v.end()); }
TEMP_T void uniq(T& v){ sort(v); v.erase(unique(v.begin(), v.end())); }
TEMP_T T    cums(T& v){ T r(v.size()); partial_sum(v.begin(), v.end(), r); return r; }
TEMP_T void show(T& v, char delim=' ', char end='\n'){ for(int i=0; i<v.size()-1; i++) cout << v[i] << delim; cout << v[v.size()-1] << end; }
TEMP_T T    acum(vector<T>& v, T b=0){ return accumulate(v.begin(), v.end(), b); }
TEMP_T vector<T> inpt(int n){ vector<T> v(n); for (int i=0; i<n; i++) cin >> v[i]; return v; }

static inline int in(){ int x; scanf("%d", &x); return x; }

struct Solver {
  Solver(){}
  int solve(){
  }
};

struct Info {
  int kind;
  int times;
  Info(int times, int kind) : times(times), kind(kind) {}
  bool operator<(const Info& x) const {
    return times == x.times ? kind < x.kind : times > x.times;
  }
};

static inline int stoi(const string& s){
  stringstream ss(s);
  int x;
  ss >> x;
  return x;
}

static inline int ttoi(const string& s){
  if (s.size() == 3){
    return stoi(s.substr(0, 1)) * 60 + stoi(s.substr(1));
  }
  return stoi(s.substr(0, 2)) * 60 + stoi(s.substr(2));
}

int main()
{
  int n;
  while (n = in()){
    priority_queue<Info> pQ;
    map<string, int> chs;
    for (int i = 0; i < n; i++){
      string name, times;
      int day;
      cin >> name >> day >> times;
      int ttime = 10000 * day + ttoi(times);
      chs[name] = ttime;
      pQ.push(Info(ttime, 0));
    }
    int p = in();
    for (int i = 0; i < p; i++){
      string name;
      cin >> name;
      int ttime = chs[name];
      pQ.push(Info(ttime, 1));
      pQ.push(Info(ttime - 30, -1));
    }
    int count = 0;
    int state = 0;
    while (!pQ.empty()){
      Info info = pQ.top();
      pQ.pop();
      if (info.kind == 0){
        if (state) continue;
        state++;
        pQ.push(Info(info.times + 30, 3));
        count++;
      }
      else if (info.kind == 1){
        if (state){
          count = -1;
          break;
        }
        state++;
        pQ.push(Info(info.times + 30, 3));
        count++;
      }
      else if (info.kind == -1){
        state++;
        pQ.push(Info(info.times + 30, 3));
      }
      else if (info.kind == 3){
        state--;
      }
    }
    printf("%d\n", count);
  }
  return (0);
}

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

using namespace std;

long long int N,M,L,R,K,H,W;

int main(){
	cin>>W>>H>>N;
	vector<vector<int>>box(H,vector<int>(W,INT_MIN));
	vector<int>x(N);
	vector<int>y(N);
	vector<int>d(N);
	for(int i=0;i<N;i++){
		cin>>x[i]>>y[i]>>d[i];
		x[i]--,y[i]--;
	}
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			for(int k=0;k<N;k++){
				box[i][j]=max(box[i][j],d[k]-abs(i-y[k])-abs(j-x[k]));
			}
		}
	}
	for(int i=0;i<N;i++){
		if(box[y[i]][x[i]]!=d[i]){
			cout<<"No\n";
			return 0;
		}
	}
	int ans=0;
	for(auto i:box)for(auto j:i)ans+=j;
	cout<<ans<<endl;
}


Measured memory_bytes: 3172
# A - Dividing a String
def count_substrings(first_substring):

	arr = [first_substring]
	i = len(first_substring)

	while i < len(S):
		s = S[i]
	
		if s == arr[-1]:
			if i + 1 < len(S):
				i += 1
				s += S[i]
			else:
				arr[-1] += s
				break
	
		arr.append(s)
		i += 1

	return len(arr)


S = input()

ans1 = count_substrings(S[:1])
ans2 = count_substrings(S[:2])

print(max(ans1, ans2))

Measured memory_bytes: 8064
def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()
    
    array_result.append(data.split(" "))

    flg = 1

    try:

        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

            else:

                flg = 0
    finally:

        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])

chkflg=True
for i in range(1,1+n):
    
    t=int(arr_data[i][0])
    x=int(arr_data[i][1])
    y=int(arr_data[i][2])
    
    if not((t%2==0 and (x+y) % 2==0 and t>=x+y) or (t%2!=0 and (x+y) % 2!=0 and t>=x+y)):
        
        chkflg=False
        break
        
print("Yes" if chkflg else "No")        
        

Measured memory_bytes: 32116
import math

A, B, H, M = map(int, input().split())

jishin_length = A

bunshin_length = B

jishin_angle = 30 * H + 360 / (12 * 60) * M

bunshin_angle = 6 * M


tri_angle = max(jishin_angle, bunshin_angle) - min(jishin_angle, bunshin_angle)

if tri_angle >= 180:
    tri_angle = 360 - tri_angle


print(math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(tri_angle))))


Measured memory_bytes: 62388
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(ll i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int const INF = 1000000;
int main(){
    int n;
    cin>>n;
    string s[n];
    rep(i,n){
        cin>>s[i];
    }
    int alpha[26];rep(i,26){alpha[i]=0;}
   
        rep(j,s[0].size()){
            alpha[s[0][j]-'a']++;
        }
    for(int i=1;i<n;i++){
        int al[26];rep(k,26){al[k]=0;}
        rep(j,s[i].size()){al[s[i][j]-'a']++;}
        rep(k,26){if(al[k]<alpha[k]){alpha[k]=al[k];}}
    }
    
    
    string ans;
    rep(i,26){if(alpha[i]!=0){
       /* while(alpha[i]!=0){
            ans+=char(i+'a');
            alpha[i]--;
        }*/
        ans+=string(alpha[i],char(i+'a'));
    }}
    cout<<ans<<endl;
    return 0;
}


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

const int MOD = 1e9 + 7;

int main() {
    int N, K; cin >> N >> K;
    ll ans = 0;
    for (ll i = K; i <= N+1; i++) {
        ll mi = (i-1) * i / 2;
        ll ma = (2*N-i+1) * i / 2;
        ans += ma - mi + 1;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    string ans;
    if(a>b){
        ans="Alice";
    }else if(a<b){
        ans="Bob";
    }
    if(a==1){
        ans="Alice";
    }else if(b==1){
        ans="Bob";
    }
    if(a==b){
        ans="Draw";
    }
cout << ans << endl;
}

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

int main(){
  string S,ans_S;
  cin >> S;

  int n = S.size();

  if(S[n-1]=='s'){
    ans_S=S+"es";
  }else{
    ans_S=S+"s";
  }
  cout<<ans_S;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N, X, i, ans;
    cin >> N >> X;
    vector<int> vec(N);
    for (i = 0; i < N; i++)
    {
        cin >> vec.at(i);
        X -= vec.at(i);
    }
    ans += N;

    sort(vec.begin(), vec.end());
    ans += (X / *vec.begin());
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;



int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll n;
    cin >> n;
    
    REP(i, 1, n + 1){
      ll ans = 0;
      REP(j, 1, 101){
        if(j * j > i) continue;
        REP(k, 1, 101){
          if(j * j + k * k + j * k > i) continue;
          REP(l, 1, 101){
            if(j * j + k * k + l * l + j * k + k * l + l * j > i) break;
            if(j * j + k * k + l * l + j * k + k * l + l * j == i) ans++;
          }
        }
      }
      print(ans);
    }
    

}



Measured memory_bytes: 3636
import numpy as np

N = int(input())
A = [0 for _ in range(N)]
B = [0 for _ in range(N)]

for i in range(N):
    a,b = map(int,input().split())
    A[i],B[i] = a,b

A = np.array(A)
B = np.array(B)

ans = 0
for i in range(N-1,-1,-1):
    a,b = A[i] + ans,B[i]

    if a%b != 0:
        ans += b - a%b

print(ans)


Measured memory_bytes: 29096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed
#define endl '\n'

const ll MOD = 1e9 + 7;

void solve(istream& cin, ostream& cout) {
  int n;
  cin >> n;
  vector<int> d(n);
  REP(i, n) {
    cin >> d[i];
  }
  ll ans = 0;
  REP(i, n) FOR(j, i + 1, n - 1) {
    ans += d[i] * d[j];
  }
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
}
#endif


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MAX_N 100000
#define MAX_M 100000
const int INF = 1e9;
int A[MAX_N];

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

int main(){
  int n,q;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>A[i];
  }
  q=pratition(0,n-1);
  for(int i=0;i<n;i++){
    if(i==q){
      cout<<"["<<A[i]<<"]";
    }
    else{
      cout<<A[i];
    }
    if(1+i<n){
      cout<<" ";
    }
  }
  cout<<endl;
}


Measured memory_bytes: 3460
import Control.Arrow
import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as V
main=print.solve.V.unfoldr(B.readInt.B.dropWhile isSpace)=<<(B.getLine>>B.getLine)
solve=V.maximum.uncurry(V.zipWith gcd).(V.scanl gcd 0&&&V.tail.V.scanr gcd 0)

Measured memory_bytes: 9740
#include<bits/stdc++.h>
#define N 3
using namespace std;
typedef unsigned long long ull;
bool im[1010][1010],pa[110][110];
int w,h,p,ans;
vector<ull> used;

void ppp(){
 ull a=0;
 ull roll[1001][1001]={};
 for(int i=0;i<p;i++)
   for(int j=0;j<p;j++)a=a*N+pa[i][j];
 for(int i=0;i<used.size();i++)
   if(used[i]==a)return;
 used.push_back(a);
 for(int j=0;j<h;j++){
   ull b=0,g=1;
   for(int i=0;i<p;i++)b=b*N+im[j][i],g*=N;
   roll[j][p-1]=b;
   for(int i=p;i<w;i++)
     roll[j][i]=b=b*N+im[j][i]-im[j][i-p]*g;
 }
 for(int j=p-1;j<w;j++){
   ull b=0,g=1,n=1;
   for(int i=0;i<p;i++)n*=N;
   for(int i=0;i<p;i++)b=b*n+roll[i][j],g*=n;
   if(b==a)ans++;
   for(int i=p;i<h;i++){
     b=b*n+roll[i][j]-roll[i-p][j]*g; 
     if(b==a)ans++;
   }
 }
}

void ch(){
 bool npa[110][110];
 for(int i=0;i<p;i++)
   for(int j=0;j<p;j++)npa[i][j]=pa[j][p-i-1];
 for(int i=0;i<p;i++)
   for(int j=0;j<p;j++)pa[i][j]=npa[i][j];
}

void ch1(){
 for(int i=0;i<p;i++)
   for(int j=0;j<p/2;j++)swap(pa[i][j],pa[i][p-j-1]);
}

int main(){
 int D[256];
 for(int i='A';i<='Z';i++)D[i]=i-'A';
 for(int i='a';i<='z';i++)D[i]=i-'a'+26;
 for(int i='0';i<='9';i++)D[i]=i-'0'+52;
 D['+']=62,D['/']=63;
 while(cin>>w>>h>>p,w){
   string s;
   used.clear();
   for(int i=0;i<h;i++){
     cin>>s;
     for(int j=0;j<s.size();j++){
       int t=D[s[j]],a=6;
	while(a--)im[i][j*6+a]=t%2,t/=2;
     }
   }
   for(int i=0;i<p;i++){
     cin>>s;
     for(int j=0;j<s.size();j++){
       int t=D[s[j]],a=6;
	while(a--)pa[i][j*6+a]=t%2,t/=2;
     }
   }
   ans=0;
    for(int i=0;i<4;i++){
     ppp();
     ch1();
     ppp();
     ch1();
     ch();
   }
   cout<<ans<<endl;
 }
 return 0;
}

Measured memory_bytes: 10056
#include "bits/stdc++.h"
using namespace std;

int main(){
	long long int n,m;
	cin>>n>>m;
	
	
	if(n>2&&m>2){
		cout<<n*m-(n+n+m+m-4)<<endl;
		return 0;
	}
	
	if(n==2||m==2){
		cout<<0<<endl;
		return 0;
	}
	
	if(n==1&&m==1){
		cout<<1<<endl;
		return 0;
	}
	
	if(n==1||m==1){
		int ans=max(n,m);
		ans-=2;
		if(ans<0)ans=0;
		cout<<ans<<endl;
		return 0;
	}
	
	
	
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#include<queue>
#include<vector>
#define ll long long
#define pi acos(-1.0)
#define inf 0x3f3f3f3f
using namespace std;
const int maxn = 1e6+5;
int v[maxn];
ll dp[maxn], w[maxn];

int main(){
	memset(dp, 0x3f, sizeof(dp));
	int n, W; cin >> n >> W;
	int sum = 0;
	for(int i = 1; i <= n; i++){
		cin >> w[i] >> v[i];
		sum += v[i];
	}
	dp[0] = 0;
	for(int i = 1; i <= n; i++){
		for(int j = sum; j >= v[i]; j--)
			dp[j] = min(dp[j], dp[j-v[i]] + w[i]);
	}
	for(int i = sum; i >= 0; i--){
		if(dp[i] <= W){
			cout << i << endl;
			break;
		}
	}
}

Measured memory_bytes: 11412
#include <stdio.h>
int main(void){
	int a,b;
	char op;
	for(;;){
		scanf("%d %c %d",&a,&op,&b);
	    if(op=='+'){
      printf("%d\n",a+b);
	    }
	else if(op=='-'){
      printf("%d\n",a-b);
    }
    else if(op=='*'){
      printf("%d\n",a*b);
    }
    else if(op=='/'){
      printf("%d\n",a/b);
    }
    else if(op=='?'){
      break;
    }
  }
return 0;
}


Measured memory_bytes: 1972
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int mod = 998244353;
int N, S, A[3000], dptable[3000][3001];
int dp(int i, int j) {
	if (i == N && j == 0) return 1;
	if (j < 0 || i == N) return 0;
	if (dptable[i][j] != -1) return dptable[i][j];
	return dptable[i][j] = (2 * dp(i + 1, j) % mod + dp(i + 1, j - A[i])) % mod;
}
int main() {
	memset(dptable, -1, sizeof dptable);
	scanf("%d %d", &N, &S);
	for (int i = 0; i < N; ++i) scanf("%d", &A[i]);
	printf("%d", dp(0, S));
	return 0;
}

Measured memory_bytes: 37092
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define ALL(n) begin(n),end(n)

//////////////////////////////////////////////////////////////////////
// 計算幾何学ライブラリ(CGL)　-ここから-
// 現在のカーソル位置にある単語と同じ単語を一括して選択する：［Ctrl］＋［Shift］＋［L］

///////////////////////////////
// 内積：ベクトルaとベクトルbの内積
///////////////////////////////

double Naiseki(vector<double> a,vector<double> b){
    double ip=0;
    for(int i=0; i<a.size(); i++){
        ip+=a[i]*b[i];
    }
    return ip;
}

////////////////////////////////////////////////////////////
// 正射影ベクトル：ベクトルbの，ベクトルaが定める直線に対する正射影ベクトル
////////////////////////////////////////////////////////////

vector<double> Seishaei_vector(vector<double> a,vector<double>b){
    double a_av2=0;
    for(int i=0; i<a.size(); i++){
        a_av2+=a[i]*a[i];
    }

    vector<double> c(a.size());

    for(int i=0; i<a.size(); i++){
        c[i]=c[i]=(Naiseki(a,b)/a_av2)*a[i];
    }

    return c;
}

////////////////////////////////////////////////////////////////////////////
// （未検証）ベクトルのなす角：ベクトルaとベクトルbのなす角（aまたはbが零ベクトルのとき，エラー）
////////////////////////////////////////////////////////////////////////////

// cosバージョン
double Nasukaku_cos(vector<double> a,vector<double>b){
    double cos_theta=0;

    double a_av=0,b_av=0;
    for(int i=0; i<a.size(); i++){
        a_av+=a[i]*a[i];
        b_av+=b[i]*b[i];
    }
    a_av=sqrt(a_av);
    b_av=sqrt(b_av);

    cos_theta=Naiseki(a,b)/(a_av*b_av);

    return cos_theta;
}

// radバージョン
double Nasukaku(vector<double> a,vector<double>b){
    double theta=0;

    double a_av=0,b_av=0;
    for(int i=0; i<a.size(); i++){
        a_av+=a[i]*a[i];
        b_av+=b[i]*b[i];
    }
    a_av=sqrt(a_av);
    b_av=sqrt(b_av);

    theta=Naiseki(a,b)/(a_av*b_av);
    theta=acos(theta);
    
    return theta;
}

// 計算幾何学ライブラリ(CGL)　-ここまで-
///////////////////////////////////

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

    vector<int> ans(q);

    REP(i,q){
        vector<double> x(4),y(4);
        cin>>x[0]>>y[0]>>x[1]>>y[1]>>x[2]>>y[2]>>x[3]>>y[3];
        
        vector<double> A={x[1]-x[0],y[1]-y[0]};
        vector<double> B={x[3]-x[2],y[3]-y[2]};

        if(A[0]/B[0]==A[1]/B[1]||(A[0]==0&&B[0]==0)||(A[1]==0&&B[1]==0)){
            ans[i]=2;
        }else if(Naiseki(A,B)==0){
            ans[i]=1;
        }else{
            ans[i]=0;
        }
    }

    REP(i,q){
        cout<<ans[i]<<endl;
    }
}


Measured memory_bytes: 3220
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;


void main() {
    int n, q;
    scan(n, q);

    while (q--) {
        int vi, wi;
        scan(vi, wi);
        solve(n, vi, wi);
    }
}

void solve(int n, int v, int w) {
    if (n == 1) {
        writeln(min(v, w));
        return;
    }

    auto va = new int[](0);
    va ~= v;

    while (v > 1) {
        if (v % n <= 1) {
            v /= n;
        }
        else {
            v = (v / n) + 1;
        }

        va ~= v;
    }

    va.reverse();

    auto wa = new int[](0);
    wa ~= w;

    while (w > 1) {
        if (w % n <= 1) {
            w /= n;
        }
        else {
            w = (w / n) + 1;
        }

        wa ~= w;
    }

    wa.reverse();

    debug {
        writeln(va);
        writeln(wa);
    }

    int ans = 0;

    while (!va.empty) {
        while (!wa.empty) {
            if (va.front == wa.front) {
                ans = max(ans, va.front);
                va.popFront;
                wa.popFront;
                break;
            }
            else if (va.front < wa.front) {
                va.popFront;
                break;
            }
            else {
                wa.popFront;
            }
        }
    }

    writeln(ans);
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;

const ll linf = 1LL << 62;
const int inf = 999999;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const ll atcoder = int(1e9 + 7);

#define Endl endl
#define pr(x) cout << x << endl
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define all(x) x.begin(),x.end()
#define atcoder(int)1e9+7
#define rep(i,n) for(int i = 0;i<n;i++)
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)


ll gcd(ll a, ll b) {//最大公約数
	if (a%b == 0)return b;
	else gcd(b, a%b);
}

ll lcm(ll a, ll b) {//最小公倍数
	return (a / gcd(a, b))*b;
}

ll dp[1010][1010];

int  main() {
		
	string s;
	cin >> s;
	bool cw = false, cn = false , ce=false, cs=false;
	bool jud;

	rep(i, s.length()) {
		if (s[i] == 'W')cw = true;
		else if (s[i] == 'N')cn = true;
		else if (s[i] == 'E')ce = true;
		else cs = true;
	}

	if (cw) if (!ce) { pr("No"); return 0; }
	if(ce)if(!cw) { pr("No"); return 0; }
	if(cn)if(!cs) { pr("No"); return 0; }
	if(cs) if(!cn) { pr("No"); return 0; }

	pr("Yes");
	return 0;

}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            var NM = ReadSplitInt();
            var N = NM[0];
            var M = NM[1];
            var k = ReadSplitIntLines(M);
            var p = ReadSplitInt();

            long res = 0;
            for (int bit = 0; bit < (1 << N); bit++)
            {
                bool ok = true;
                for (int i = 0; i < M; i++)
                {
                    int con = 0;
                    foreach (var item in k[i].Skip(1))
                    {
                        if ((bit & (1 << (item-1))) != 0)
                        //if ((bit & item) != 0)
                        {
                            con++;
                        }
                    }

                    if (con % 2 != p[i])
                    {
                        ok = false;
                    }
                }

                if (ok)
                {
                    res++;
                }
            }

            Console.WriteLine(res);

            Console.ReadKey();
        }



        #region MyRegion

        public static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }

        /// <summary>
        /// 空白区切の数値を取得する
        /// </summary>
        /// <returns>The read split int.</returns>
        public static int[] ReadSplitInt()
        {
            return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        }

        /// <summary>
        /// 空白区切の数値を取得
        /// </summary>
        /// <returns>The read split long.</returns>
        public static long[] ReadSplitLong()
        {
            return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        }


        public static int[][] ReadSplitIntLines(int n)
        {
            return Enumerable.Range(0, n).Select(x => ReadSplitInt()).ToArray();
        }

        public static long[][] ReadSplitLongLines(int n)
        {
            return Enumerable.Range(0, n).Select(x => ReadSplitLong()).ToArray();
        }

        public static long[][] ReadSplitLongLines(long n)
        {
            var ret = new List<long[]>();
            for (long i = 0; i < n; i++)
            {
                ret.Add(ReadSplitLong().ToArray());
            }

            return ret.ToArray();
        }

        #endregion

    }
}


Measured memory_bytes: 13524
fn solve(a: String) -> String {
    let d = a
        .chars()
        .map(|x| x.to_digit(10).unwrap() as i32)
        .collect::<Vec<_>>();
    let a = a.chars().collect::<Vec<_>>();
    let mut v = vec![];
    for i in 0..8 {
        let mut s = d[0];
        for j in 0..3 {
            if (i >> j) & 1 == 0 {
                s += d[j + 1];
            } else {
                s -= d[j + 1];
            }
        }
        v.push(s);
    }
    for (i, &x) in v.iter().enumerate() {
        if x == 7 {
            let mut s = String::new();
            s.push(a[0]);
            for j in 0..3 {
                if (i >> j) & 1 == 0 {
                    s.push('+');
                } else {
                    s.push('-');
                }
                s.push(a[j + 1]);
            }
            s.push_str("=7");
            return s;
        }
    }
    unreachable!();
}

fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let a = s.trim().to_string();
    let ans = solve(a);
    println!("{}", ans);
}


Measured memory_bytes: 4352
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#if __cplusplus >= 201103L
#include <chrono>
using namespace std::chrono;
#endif
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fi first
#define se second
#ifdef LOCAL
#define prln(x) (cout << #x << ' ' << x << endl)
#define pr(x) (cout << #x << ' ' << x << ' ' )
#define prv(x) (cout << x << ' ')
#else
#define prln(x) 
#define pr(x)
#define prv(x)
#endif
#define clr(x) memset((x), 0, sizeof((x)))
#define clr1(x) memset((x), -1, sizeof((x)))
#define endl "\n"
#define pi acos(-1)
#define rep(i, st, ed) for (int i = (st); i <= (ed); ++i)
#define rep0(i, st, ed) for (int i = (st); i < (ed); ++i)
#define per0(i, st, ed) for (int i = (st); i > ed; --i)
#define per(i, st, ed) for (int i = (st); i >= ed; --i)
#define chmin(a, b) (a = a > b ? b : a)
#define chmax(a, b) (a = a < b ? b : a)
template<class T> void _sf(T &x) {cin >> x;}
void _sf(int &x) {scanf("%d", &x);}
void _sf(ll &x) {scanf("%lld", &x);}
void _sf(double &x) {scanf("%lf", &x);}
void _sf(char &x) {scanf(" %c", &x);}
void _sf(char *x) {scanf("%s", x);}
void sf() {}
template <class T, class...U> void sf(T & head, U&... tail) { _sf(head); sf(tail...);}
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;

int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}


int main(){
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
        #if __cplusplus >= 201103L
        auto start = steady_clock::now();
        #endif
    #endif
    int n = read(), k = read();
    int a[n + 1];
    rep(i, 1, n) a[i] = read();
    int dp[n + 1][k + 1];
    dp[0][0] = 1;
    rep(i, 1, k) dp[0][i] = 0;
    rep(i, 1, n) {
        int sums[k + 1];
        sums[0] = dp[i - 1][0];
        rep(j, 1, k) {
            sums[j] = (sums[j - 1] + dp[i - 1][j]) % mod;
        }
        rep(j, 0, k) {
            int tr = sums[j];
            int unr = j - a[i] - 1;
            if (unr >= 0) {
                tr = (tr - sums[unr] + mod) % mod;
            }
            dp[i][j] = tr;
        }
    }
    cout << dp[n][k];

    #ifdef LOCAL
        #if __cplusplus >= 201103L
        auto end = steady_clock::now();
        duration<double> time_span = duration_cast<duration<double>>(end - start);;
        printf("Total time: %.6fs\n", time_span.count());
        #endif
    #endif
    return 0;
}

Measured memory_bytes: 40064
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, a, b) for (int i = (a); i < (int)(b); i++)
typedef vector<int> VI;
typedef long long ll;
typedef vector<ll> VL;
typedef vector<VL> VVL;

ll Main(int &n, ll &W, VL &w, VI &v) {
    VVL dp(n+1, VL(W+1, 0));
    REP(i, n) {
        REP(j, W+1) {
            dp[i+1][j] = (j < w[i]) ? dp[i][j]
                    : max(dp[i][j], dp[i][j-w[i]] + v[i]);
        }
    }
    return dp[n][W];
}

int main(void) {
    int n;
    ll W;
    cin >> n >> W;
    VL w(n);
    VI v(n);
    REP(i, n) cin >> w[i] >> v[i];
    cout << Main(n, W, w, v) << endl; 
    return 0;
}

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

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

    bool ans[10000] = {};
    while (n != 0) {
        int bit;
      	long long sum;
        if (n > 0) {
            sum = 0b01;
            for (bit = 0; n > sum; bit += 2) sum = (sum << 2) | 0b01;
            n -= (1 << bit);
        } else {
            sum = 0b10;
            for (bit = 0; abs(n) > sum; bit += 2) sum = (sum << 2) | 0b10;
            bit++;
            n -= -1 * (1 << bit);
        }
        ans[bit] = true;
    }

    int i = 10000 - 1;
    while (ans[i] == false && i > 0) i--;
    for (; i >= 0; i--) cout << (ans[i] ? 1 : 0);
    cout << endl;
}

Measured memory_bytes: 256