akhauriyash/Code-Regression huggingface dataset:
function bomb(y,x){
   var dy=[0,0,-1,1];
   var dx=[-1,1,0,0];
   for(var i=0;i<4;i++){
      var yy=y+dy[i];
      var xx=x+dx[i];
      if(yy<0 || yy>=H || xx<0 || xx>=W)continue;
      if(yx[yy][xx]=="."){cnt++;yx[yy][xx]=cnt;bomb(yy,xx);}
   }
}

var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var WH=(Arr.shift()).split(" ").map(Number);
   var W=WH[0];
   var H=WH[1];
   if(W==0 && H==0)break;
      var yx=[];
      var Y,X;
      for(var i=0;i<H;i++){
         var arr=(Arr.shift()).split("");
         if(arr.indexOf("@")!=-1){Y=i;X=arr.indexOf("@");}
         yx.push(arr);
      }
      var cnt=1;
      bomb(Y,X);
      console.log(cnt);
}

Measured memory_bytes: 11036
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	string a;
	cin>>a;
	for(register int i=0;i<4;i++) putchar(a[i]);
	putchar(' ');
	for(register int i=4;i<12;i++) putchar(a[i]);
	puts("");
	return 0;
}


Measured memory_bytes: 256
def v():
 from collections import deque
 H,W,N=map(int,input().split())
 e='X'*(W+2)
 M=e+''.join('X'+input()+'X'for _ in[0]*H)+e
 m=(1,-1,W+2,-W-2)
 def f(s,g):
  p,t=s,0
  q=deque()
  b=[1]*len(M);b[s]=0
  while 1:
   for d in m:
    n=p+d
    if'X'!=M[n]and b[n]:
     if M[n]==g:return(n,t+1)
     b[n]=0;q.append([n,t+1])
   p,t=q.popleft()
 s=M.find('S')
 a=0
 for i in range(1,N+1):
  s,t=f(s,str(i))
  a+=t
 print(a)
if'__main__'==__name__:v()


Measured memory_bytes: 14948
#include <bits/stdc++.h>
#include<vector>
using namespace std;
int n;
char s[3000],t[3000];
vector<char> rs;
int slen,tlen;
void read()
{
cin>>s;
cin>>t;
slen=strlen(s);
tlen=strlen(t);
}
int dp[3005][3005];
int solve()
{
int i,j;
for(i=0;i<=strlen(s);i++)
{
    dp[i][0]=0;
}
for(i=0;i<=strlen(t);i++)
{
    dp[0][i]=0;
}
for(i=1;i<=strlen(s);i++)
{
    for(j=1;j<=strlen(t);j++)
    {
        if(s[i-1]==t[j-1])
        {
            dp[i][j]=1+dp[i-1][j-1];
        }
        else
        {
            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
}

int k=dp[strlen(s)][strlen(t)];
int cnt=k;
i=slen;
j=tlen;
while(cnt>0)
{
    if(dp[i][j]==dp[i-1][j])
    {
        i--;
    }
    else if(dp[i][j]==dp[i][j-1])
    {
        j--;
    }
    else if(dp[i][j]!=dp[i-1][j-1])
    {
        rs.push_back(s[i-1]);
        i--;
        j--;
        cnt--;
    }
}
for(i=k-1;i>=0;i--)
cout<<rs[i];
return 0;
}
int main() {
	read();
	solve();
	
	return 0;
}


Measured memory_bytes: 35456
#include <stdio.h> 

int main() 
{ 
  int h, n, soma, s, i;
  scanf("%d %d", &h, &n); 
  
  for(i = 0; i < n; i++) 
  { 
    scanf("%d", &s); 
    soma += s;
  } 
  if(soma >= h) 
  { 
    printf("Yes"); 
  } 
  else 
  { 
    printf("No"); 
  } 
  return 0; 
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll inf = numeric_limits<ll>::max()/3;

int main(void){
  ll n;
  cin >> n;
  vector< ll > num(n);
  for(int i = 0;i < n;++i){
    cin >> num[i];
  }
  num.push_back(0);
  if(num[0] != 0){
    cout << -1 << endl;
    return 0;
  }
  ll res = 0;
  for(int i = n-1;i >= 0;--i){
    if(num[i] >= num[i+1]){
      res += num[i];
    }else if(num[i+1] - num[i] > 1){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << res << endl;
  return 0;
}



Measured memory_bytes: 4864
#include <stdio.h>

int main(void)
{
	int count;
	int i;
	int n;
	
	while (scanf("%d", &n) != EOF){
		count = 0;
		i = 0;
		while (i < 10000){
			if (((i / 1000) + ((i / 100) % 10) + ((i / 10) % 10) + (i % 10)) == n) count++;
			i++;
		}
		
		printf("%d\n", count);
	}
	
	return (0);
}

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

ll dp[11000][110][2];

int main(){
    int D;
    string K;
    cin>>K>>D;
    dp[0][0][0]=1;
    int N=(int)K.size();
    for(int i=0;i<N;i++){
        for(int j=0;j<D;j++){
            for(int k=0;k<2;k++){

                if(k==0){
                    int a=K[i]-'0';
                    for(int l=0;l<a;l++){
                        dp[i+1][(j+l)%D][1]+=dp[i][j][k];
                        dp[i+1][(j+l)%D][1]%=MOD;
                    }
                    dp[i+1][(j+a)%D][0]+=dp[i][j][k];
                    dp[i+1][(j+a)%D][0]%=MOD;
                }else{
                    for(int l=0;l<=9;l++){
                        dp[i+1][(j+l)%D][k]+=dp[i][j][k];
                        dp[i+1][(j+l)%D][k]%=MOD;                        
                    }
                }

            }
        }
    }
    cout<<(dp[N][0][1] + dp[N][0][0] -1 +MOD)%MOD<<endl; 
}



Measured memory_bytes: 18816
#include <stdio.h>
#include <stdlib.h>

typedef struct{
  long price;
  long stock;
}drink;

int compare(const void *a,const void *b){
  drink *A = (drink *)a;
  drink *B = (drink *)b;
  if(A->price == B->price){
    return 0;
  }else if(A->price > B->price){
    return 1;
  }else{
    return -1;
  }
}

int main(){
  int N,M;
  scanf("%d %d",&N,&M);
  drink *D = (drink *)malloc(sizeof(drink)*N);
  for(int i=0;i<N;i++){
    scanf("%ld %ld",&D[i].price,&D[i].stock);
  }
  qsort(D,N,sizeof(drink),compare);
  
  long sum = 0;
  long item = 0;
  for(int j=0;j<N;j++){
    if(item + D[j].stock < M){
      sum += D[j].price * D[j].stock;
      item += D[j].stock;
    }else{
      sum += D[j].price * (M - item);
      item = M;
      j = N + 1;
    }
  }
  printf("%ld",sum);
  return 0;
}

Measured memory_bytes: 3324
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

/*
 N = i * m + i;
 N = i * (m + 1);

 i < m
*/

int main(void) {
  long N;
  cin >> N;
  long result = 0;
  for (long i = 1; i * i <= N; i++) {
    long tmp = N - i;
    if (tmp % i != 0) continue;
    long m = tmp / i;
    if (m <= i) continue;
    result += m;
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<map>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
int table[100000];
int main() {
	int n, c = 0;
	scanf("%d", &n);
	vector<int> l(n);
	rep(i, 0, n)scanf("%d", &l[i]);
	sort(all(l));
	rep(a, 0, n) {
		rep(b, a + 1, n) {
			c += lower_bound(all(l), l[a] + l[b]) - l.begin() - b - 1;
		}
	}
	printf("%d\n", c);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if(a + b == c or a + c == b or a == b + c) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    set<int> s;
    int n,a,i;
    cin>>n;
    for (i=0;i<n;i++)
    {
        cin>>a;
        s.insert(a);
    }
    cout<<s.size()<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
const int N_MAX = pow(10, 5);
int main (void) {
    int N;
    int cnt[N_MAX] = {0};
    int ans = 0;

    cin >> N;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        cnt[a - 1]++;
        cnt[a]++;
        cnt[a + 1]++;
    }

    for (int i = 0; i < N_MAX; i++) ans = max(ans, cnt[i]);

    cout << ans << endl;

    return 0;
}

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

int main()
{
  string S;
  int res=0;
  bool reiwa = true;
  cin >> S;

  int year = atoi(S.substr(0,4).c_str());
  int month = atoi(S.substr(5,2).c_str());
  int day = atoi(S.substr(8,2).c_str());

  //cout << year << month << day << endl;                                       
  if(year<2019) reiwa = false;
  else if(month<5) reiwa = false;

  if(reiwa) cout << "TBD" <<endl;
  else cout << "Heisei" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1<<30;
const ll MOD = 1000000007;

int check(string s) {
    rep (i, s.size()) {
        if (!(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T')) return -1;
    }
    return s.size();
}

int main(void) {

    string s; cin >> s;
    int ans = 0;
    for (int i = 0; i < s.size(); i++) {
        for (int j = 1; j <= s.size() - i; j++) {
            string str = s.substr(i, j);
            ans = max(ans, check(str));
            // cout << str << " " << check(str) << endl;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    char[][] A = new char[N][N];
    char[][] B = new char[M][M];
    for (int i = 0; i < N; i++) {
      A[i] = sc.next().toCharArray();
    }
    for (int i = 0; i < M; i++) {
      B[i] = sc.next().toCharArray();
    }
    int count = 0;
    for (int i = 0; i < N - M + 1; i++) {
      for (int j = 0; j < N - M + 1; j++) {
        boolean contain = true;
        for (int k = 0; k < M; k++) {
          for (int l = 0; l < M; l++) {
            if (A[i + k][j + l] != B[k][l]) {
              contain = false;
            }
          }
        }
        if (contain) {
          count++;
        }
      }
    }
    if (count > 0) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 21716
N,K=map(int,input().split())
x=[None]
x.extend(list(map(int,input().split())))

ans=10**9
for i in range(1,N-K+2):
    a,b=x[i],x[i+K-1]
    if b<=0:
        d=-a
    elif 0<=a:
        d=b
    elif a<0<b:
        d=-a+b+min(-a,b)
    ans=min(ans,d)

print(ans)

Measured memory_bytes: 62576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll h,w;
	cin>>h>>w;
	ll dx[4]={1,0,-1,0};
	ll dy[4]={0,1,0,-1};
	char ch[22][22];
	for(ll i=0;i<h;i++){
		for(ll j=0;j<w;j++){
			cin>>ch[i][j];
		}
	}
	ll ans=0;
	for(ll i=0;i<h;i++){
		for(ll j=0;j<w;j++){
			ll cnt[22][22];
			for(ll i=0;i<h;i++){
				for(ll j=0;j<w;j++){
					cnt[i][j]=0;
				}
			}
			if(ch[i][j]=='#'){
				continue;
			}
			cnt[i][j]=1;
			queue<pair<ll,ll>>q;
			q.push(make_pair(i,j));
			while(q.size()!=0){
				ll nowx=q.front().first;
				ll nowy=q.front().second;
				q.pop();
				for(ll i=0;i<4;i++){
					ll nexx=nowx+dx[i];
					ll nexy=nowy+dy[i];
					if(nexx<0||nexx>=h||nexy<0||nexy>=w){
						continue;
					}
					if(ch[nexx][nexy]=='#'){
						continue;
					}
					if(cnt[nexx][nexy]!=0){
						continue;
					}
					cnt[nexx][nexy]=cnt[nowx][nowy]+1;
					q.push(make_pair(nexx,nexy));
				}
			}
			for(ll i=0;i<h;i++){
				for(ll j=0;j<w;j++){
					ans=max(ans,cnt[i][j]);
				}
			}
		}
	}
	cout <<ans-1;
	// your code goes here
	return 0;
}

Measured memory_bytes: 3560
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	string n; cin >> n;
    rep(i, 3) {
        if(n[i] == '7') {
            cout << "Yes" << endl;
            return;
        }
    }
    cout << "No" << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 3600
import java.util.*;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n];
        int res[] = new int[n];
        for(int i=0;i<n;i++){
            a[i] = sc.nextInt();
            res[a[i] - 1] = i + 1;
        }
        for(int i=0;i<n-1;i++){
            System.out.print(res[i] + " ");
        }
        System.out.println(res[n-1]);
    }
}


Measured memory_bytes: 62440
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SORT(x) sort(rng(x))
#define RSORT(x) sort(rrng(x))
#define SUM(x) accumulate(rng(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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 () {
  int n, m;
  cin >> n >> m;
  vvi jobs(m);
  rep(i,n) {
    int a, b;
    cin >> a >> b;
    if (a > m) continue;
    jobs[m-a].pb(b);
  }
  priority_queue<int> pq;
  int ans = 0;
  for (int i = m-1; i >= 0; i--) {
    for (int b : jobs[i]) {
      pq.push(b);
    }
    if (!pq.empty()) {
      ans += pq.top();
      pq.pop();
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5632
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
const int MOD = 1000000007;

int main() {
    int N;
    cin>>N;
    string S, T;
    cin >> S >> T;
    rep(i, 0, N) { cout << S[i] << T[i]; }
    cout << endl;
}

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

int main(){
	int N;
	int sosu[168] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997 };
	int yakusu[168];
	int i;
	int loop;
	long long int ans = 1;
	for (loop = 0; loop < 168; loop++)yakusu[loop] = 0;
	cin >> N;

	for (loop = 0; loop < 168; loop++){
		for (i = 1; N / i > 0; i++){
			yakusu[loop] += N / (int)pow(sosu[loop], i);
		}
		ans *= yakusu[loop] + 1;
		ans %= (int)pow(10, 9) + 7;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

int main(void) {
  
  int x, a, b;
  scanf("%d", &x);
  scanf("%d", &a);
  scanf("%d", &b);
  
  x -= a;
  while (x >= b)
    x -= b;
  printf("%d\n", x);
  return 0;
}

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

dp = [float("inf")] * N
dp[0] = 0
for i in range(N+1):
    try:
        dp[i+1] = min(dp[i+1], dp[i]+abs(H[i+1]-H[i]))
        dp[i+1] = min(dp[i+1], dp[i-1]+abs(H[i+1]-H[i-1]))
    except:
        continue

print(dp[-1])

Measured memory_bytes: 13928
#pragma GCC optimize("Ofast")
#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;
using ll = long long;
using u64 = uint_fast64_t;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

void solve() {
    int N; cin >> N;
    vector<u64> A(N);
    rep(i,N) cin >> A[i];
    reverse(all(A));
    string S; cin >> S;
    reverse(all(S));
    vector<u64> basis;
    rep(i,N) {
        if (S[i]=='1') {
            for (auto e : basis) {
                chmin(A[i],e^A[i]);
            }
            if (A[i]) {
                cout << 1 << ln;
                return;
            }
        } else {
            for (auto e : basis) {
                chmin(A[i],e^A[i]);
            }
            if (A[i]) {
                basis.emplace_back(A[i]);
            }
        }
    }

    cout << 0 << ln;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int Q; cin >> Q;
    while (Q--) {
        solve();
    }
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000


int main(){

	int N;
	cin>>N;
	
	string s1,s2;
	cin>>s1>>s2;
	
	int ans = 1;
	int now = 0;
	
	while(true){
		if(now>=N)break;
		if(s1[now]==s2[now]){
			if(now==0){
				ans = mod(ans * 3);
			}
			else{
				if(s1[now-1]==s2[now-1]){
					ans = mod(ans * 2);
				}
			}
			now++;
		}
		else{
			if(now==0){
				ans = mod(ans * 6);
			}
			else{
				if(s1[now-1]==s2[now-1]){
					ans = mod(ans * 2);
				}
				else{
					ans = mod(ans * 3);
				}
			}
			now+=2;
		}
	}
	
	cout<<ans<<endl;
		
	
    return 0;
}



Measured memory_bytes: 256
n,k = map(int,input().split())
s=list(input())
if(s[k-1]=="A"):
    s[k-1]="a"
elif(s[k-1]=="B"):
    s[k-1]="b"
elif(s[k-1]=="C"):
    s[k-1]="c"
print(''.join(s))

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

using namespace std;

using int64 = long long;
const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
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...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}


template< typename T >
T knapsack_01_2(const vector< T > &w, const vector< int > &v, const T &W) {
  const int N = (int) w.size();
  const int sum = accumulate(begin(v), end(v), 0);
  vector< T > dp(sum + 1, W + 1);
  dp[0] = T();
  for(int i = 0; i < N; i++) {
    for(int j = sum; j >= v[i]; j--) {
      dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
    }
  }
  int ret = 0;
  for(int i = 0; i <= sum; i++) {
    if(dp[i] <= W) ret = i;
  }
  return ret;
}


int main() {
  int N, W;
  cin >> N >> W;
  vector< int > v(N), w(N);
  for(int i = 0; i < N; i++) cin >> v[i] >> w[i];
  cout << knapsack_01_2(w, v, W) << endl;
}



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

using namespace std;
using ll = long long;
using ld = long double;
using pi = pair<ll, ll>;

int n;
int A[100005];
void input() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> A[i];
}

void calc() {
    if (n % 3 != 0) {
        for (int i = 1; i <= n; i++) {
            if (A[i] != 0) {
                cout << "No";
                return;
            }
        }
        cout << "Yes";
    }
    else {
        map<int, int> mp;
        for (int i = 1; i <= n; i++) {
            mp[A[i]]++;
        }
        int x = 0;
        for (auto i : mp) {
            int v = i.second;
            while (v >= n / 3) {
                x ^= i.first;
                v -= n / 3;
            }
            if (v > 0) {
                cout << "No";
                return;
            }
        }
        if (x != 0) {
            cout << "No";
        }
        else cout << "Yes";
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    input();
    calc();
    return 0;
}

Measured memory_bytes: 4224
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

S = input()[:-1]

D = {"SUN": 7, "MON": 6, "TUE": 5, "WED": 4, "THU": 3, "FRI": 2, "SAT": 1}
print(D[S])


Measured memory_bytes: 38256
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<functional>
using namespace std;
const long long int mod = 1000000007;
const long long int big = 1152921504606846976;



int main(void) {
	long long int N, i,A,B,zen,now,ans=0;
	long long int X[100010];
	scanf("%lld %lld %lld", &N,&A,&B);
	scanf("%lld", &zen);
	for (i = 1; i < N; i++) {
		scanf("%lld", &now);
		X[i] = now - zen;
		zen = now;
	}
	for (i = 1; i < N ; i++) {
		if (B < A*X[i]) { ans += B; }
		else { ans += A*X[i]; }
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N,M;
  cin >> N >> M;
  vector<int> vec(31);
  rep(i,N)
  {
    int K;
    cin >> K;
    rep(j,K)
    {
      int x;
      cin >> x;
      vec[x] ++;
    }
  }
  int count = 0;
  rep(i,31)
  {
    if(vec[i]==N)
    {
      count ++;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 3624
# -*- coding: utf-8 -*-
# D

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

class Mint(object):
    def cmb(self, n, r, mod: int = 10 ** 9 + 7):
        if (r < 0) or (r > n):
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n - r] % mod

    def cmb_prep(self, N: int, mod: int = 10 ** 9 + 7):
        self.g1 = [1, 1]  # 元テーブル
        self.g2 = [1, 1]  # 逆元テーブル
        inverse = [0, 1]  # 逆元テーブル計算用テーブル

        for i in range(2, N + 1):
            self.g1.append((self.g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            self.g2.append((self.g2[-1] * inverse[-1]) % mod)

    def cmb_(n, r):
        """ 普通にnCrを求める
        >>> p = Mint()
        >>> p.cmb_(10, 2)
        45
        """
        from operator import mul
        from functools import reduce

        r = min(n - r, r)
        if r == 0:
            return 1
        over = reduce(mul, range(n, n - r, -1))
        under = reduce(mul, range(1, r + 1))
        return over // under


mod = 10**9 + 7
x, y = map(int, input().split())

if (2 * y -x) % 3 != 0:
    print(0)
    sys.exit()

if (2 * x -y) % 3 != 0:
    print(0)
    sys.exit()

n = (2 * y -x) // 3
m = (2* x -y) // 3

mint = Mint()
mint.cmb_prep(n + m, mod)

print(mint.cmb(n+m, n, mod))


Measured memory_bytes: 118764
#include <iostream>

using namespace std;

int main() {
    // ios_base::sync_with_stdio(false); 
    // cin.tie(NULL); 
    int K, cont = 0;
    cin >> K;
    for (int i = 2; i <= K; i += 2) {
        for (int j = 1; j <= K; j += 2) {
            cont++;
        }
    }
    cout << cont << endl;
    return 0;
}

Measured memory_bytes: 3192
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int p = 0;
    String s[] = new String[n];
    String sa[] = new String[n];
    
    for (int i=0; i<n; i++){ 
      s[i] = sc.next();
      p = Integer.parseInt(sc.next());
      for (int j=0; j<100-p; j++){
        s[i] = s[i] + "-";
      }
    }

    for (int i=0; i<n; i++){
      sa[i] = s[i];
    }
    Arrays.sort(sa);
    //System.out.println(Arrays.asList(s));
    
    for (int i=0; i<n; i++){
      
      for (int j=0; j<n; j++){
        if(s[j].equals(sa[i])){
          System.out.println(j+1);
        }
      }

    }
    
    //System.out.println(ans);
  }
}


Measured memory_bytes: 25428
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;

int main(){
    int n,k;cin>>n>>k;vector<int> h(n);
    for(int i=0;i<n;i++) cin>>h[i];
    sort(h.begin(),h.end());
    ll ans=0;
    for(int i=0;i<n-k;i++) ans+=h[i];
    cout<<ans<<endl;
}

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

int main() {
    int n,m,q;cin>>n>>m>>q;
    vector<int> a(q+1),b(q+1),c(q+1),d(q+1);

    for(int i=1;i<=q;i++){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
    }

    queue<vector<int>> qq;
    qq.push({1});
    int ans=0;
    while(qq.size()){
        vector<int> v=qq.front();qq.pop();
        if(v.size()==n+1){
            int res=0;
            for(int i=1;i<=q;i++){
                if(v[b[i]]-v[a[i]]==c[i]){
                    res+=d[i];
                }
            }
            ans=max(ans,res);
        }
        else{
            for(int i=v.back();i<=m;i++){
                v.emplace_back(i);
                qq.push(v);
                v.pop_back();
            }
        }
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 11452
<?php
$num = trim(fgets(STDIN));
$pointsN = trim(fgets(STDIN));
$pointsC = trim(fgets(STDIN));
$arrN = explode(" ", $pointsN);  //半角スペース区切りの要素を格納
$arrC = explode(" ", $pointsC);  //半角スペース区切りの要素を格納
$sum = 0;
for($i=0; $i<$num; $i++){
  if($arrN[$i] > $arrC[$i]){
    $sum += $arrN[$i]  -  $arrC[$i];
  }
}
echo $sum."\n";
?>

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

int main()
{
  int a,n,b=0;
  cin>>a>>n;
  while(n--)
  {
    int t;
    cin>>t;
    b+=t;
  }
  if(b>=a) cout<<"Yes";
  else cout<<"No";
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
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 main(void) {
    int a,b,c;
    cin>>a>>b>>c;
    int tmp=min(a-b,c);
    cout<<c-tmp<<endl;
}

Measured memory_bytes: 256
s = input()
f = 1 
if s[0] == s[1] == s[2] == s[3]:
        f = 1 
elif (s[0] == s[1] and s[2] == s[3]) or (s[:2] == s[2:] or s[1::-1] == s[2:]):
        f = 0 
print('YNeos'[f::2])

Measured memory_bytes: 3064
from queue import Queue

def main():
	K = int(input())
	count = 0
	ans = 0

	q = Queue()
	q.put(-1)


	while(not q.empty()):
		next_loop = True
		v = q.get()

		if(v == -1):
			for i in range(1, 10):
				q.put(i)
				count += 1

				if(count == K):
					ans = i
					next_loop = False
				
		else:
		
			for i in range(0, 10):
				d1 = v%10
				
				if(not (d1-1 <= i <= d1+1)):
					continue

				count += 1

				if(count == K):
					ans = v * 10 + i
					next_loop = False
					break

				q.put(v * 10 + i)
		
		if(not next_loop):
			break

	print(ans)


if __name__ == "__main__":
	main()

Measured memory_bytes: 6768
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int num = in.nextInt();
		for(int i = 1;i <= num;i++){
			int n = in.nextInt();
			System.out.println("Case "+i+":");
			for(int j = 0;j < 10;j++){
				n = ((n * n)%1000000)/100;
				System.out.println(n);
			}	
		}
	}
}

Measured memory_bytes: 17184
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int n;
void dfs(string s,char mx){
  if(sz(s) == n){
    cout<<s<<endl;
    return;
  }
  for(char c = 'a';c<=mx+1;c++){
    string t = s;
    t+=c;
    dfs(t,max(mx,c));
  }
}
int main() { 
  cin >> n;
  string s = "";
  dfs(s,'a'-1);
  return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

int v[100000];
int memo[100000];
int N;
int ans;

void simulate(int pos, int dice, int turn, queue<int> &q) {
    int next = pos+dice;
    if(next >= N-1) {
        ans = min(ans, turn);
        return;
    } 
    if(memo[next] <= turn) return; // already visited
    memo[next] = turn;
    if(v[next] == 0) {
        // テヲツャツ。テ」ツ?ョテゥツ鳴凝・ツァツ凝ァツつケテ」ツ?ィテ」ツ?療」ツ?ヲテ、ツスツソテァツ板ィテ・ツ渉ッティツδス
        q.push(next);
    } else {
        simulate(next, v[next], turn, q);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> N;
    for(int i = 0; i < N; ++i) {
        cin >> v[i];
        memo[i] = N;
    }
    ans = N;
    memo[0] = 0;
    queue<int> q;
    q.push(0);
    while(!q.empty()) {
        int pos = q.front();
        q.pop();
        for(int dice = 1; dice <= 6; ++dice) {
            simulate(pos, dice, memo[pos]+1, q);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 2004
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    int a,s,d,f,g;
    cin>>a>>s>>d>>f>>g;
    if(a==0){
        cout<<1<<endl;
    }
    if(s==0){
        cout<<2<<endl;
    }
    if(d==0){
        cout<<3<<endl;
    }
    if(f==0){
        cout<<4<<endl;
    }
    if(g==0){
        cout<<5<<endl;
    }

}

Measured memory_bytes: 3588
#include <stdio.h>
#include <math.h>

int main( void ) {
	int e, ee, y, z, min;

	for ( ; scanf( "%d", &e ), e; printf( "%d\n", min ) ) {
		min = e;
		for ( z = 0; y = sqrt( ee = e - z * z * z ), ee >= 0; z++ )
			if ( ee - y * y + y + z < min )
				min = ee - y * y + y + z;
	}

	return 0;
}

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

#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int s[10],c[10];
int ans[10];
int main()
{
	int N,M;
	cin>>N>>M;
	for (int i=0;i<M;i++){
		cin >> s[i] >> c[i];
		s[i]--;
	}
	
	for (int j = 0; j < 3; j++){
		int num = mod;
		for (int i = 0; i < M; i++){
			if (j == s[i]){
				if (num == mod) 
					num = c[i];
				else if (num != c[i]){
					cout << -1 << endl;
					return 0;
				}
			}
		}
		
		if (num == mod){
			if (j == 0) 
				ans[j] = 1;
			else 
				ans[j] = 0;
		}
		else 
			ans[j] = num;
	}
	
	if (N == 1) {
		if (M == 0) 
			cout << 0 << endl;
		else 
			cout << ans[0] << endl;
		return 0;
	}
	
	if (ans[0] == 0) {
		cout << -1 << endl;
		return 0;
	}
	
	for (int i = 0; i < N; i++) 
		cout << ans[i];
	cout << endl;
	
	return 0;
}

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

int main(){
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5]){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  ll A,B,C;
  ll cnt=0;
  cin>>A>>B>>C;
  if(A==B) cnt++;
  if(A==C) cnt++;
  if(B==C) cnt++;
  if(cnt==3) cout<<1<<endl; 
  else cout<<3-cnt<<endl;
}
	


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <ctime>

#define Rep(i, n) for (int i = 1; i <= n; i ++)
#define Rep0(i, n) for (int i = 0; i <= n; i ++)
#define RepG(i, x) for (int i = head[x]; i; i = edge[i].next)
#define v edge[i].to
#define mp(a, b) make_pair(a, b)

using namespace std;

const int N = 5010;

struct Edge{ int to, next;} edge[N];
int head[N], num, c[N];
void add_edge(int a, int b) { edge[++ num] = (Edge){b, head[a]}, head[a] = num;}

int fb[N], fw[N], tfb[N], tfw[N];

void dfs(int x)
{
	RepG(i, x) dfs(v);
	Rep(i, c[x]) tfb[i] = tfb[i] = 1e9;
	tfb[0] = tfw[0] = 0;
	RepG(i, x) {
		for (int j = c[x]; j >= 0; j --) {
			int tmpb = 1e9, tmpw = 1e9;
			if (j >= c[v]){
				tmpb = min(tfb[j - c[v]] + fb[v], tmpb);
				tmpw = min(tfw[j - c[v]] + fw[v], tmpw);
			}
			if (j >= fw[v]){ tmpb = min(tmpb, tfb[j - fw[v]] + c[v]);}
			if (j >= fb[v]){ tmpw = min(tmpw, tfw[j - fb[v]] + c[v]);}
			tfb[j] = tmpb, tfw[j] = tmpw;
		}
	}
	fw[x] = fb[x] = 1e9;
	Rep0(i, c[x]) fw[x] = min(fw[x], tfw[i]), fb[x] = min(fb[x], tfb[i]);
	//printf("%d %d %d\n", x, fw[x], fb[x]);
}

int main()
{
	
//	freopen("e.in", "r", stdin);
	  
	int n;
	scanf("%d", &n);
	Rep(i, n - 1) {
		int a;
		scanf("%d", &a);
		add_edge(a, i + 1);
	}
	Rep(i, n) scanf("%d", &c[i]);
	//printf("*");
	dfs(1);
	if (fw[1] < 1e9 || fb[1] < 1e9) printf("POSSIBLE\n");
	else printf("IMPOSSIBLE\n");
	
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <array>
#include <deque>
#include <bitset>
typedef long long ll;
using namespace std;
#define trace(x) cerr << #x << " is " << x << endl;
int v[200001];

int main() {
    ios::sync_with_stdio(0);
	cin.tie(0);
    int n, k;
    cin >> n >> k;
    int t;
    for (int i = 0; i < n; i++) {
        cin >> v[i + 1];
        v[i + 1] += v[i];
    }

    int res = 0;
    for (int i = k; i <= n; i++) {
        res = max(res, v[i] - v[i - k]);
    }
    printf("%.12lf\n", (double)(res + k) / 2);
    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
using namespace std;

#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)

// const int kMaxN;

int a, b;
int ans = 0;

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

  if ((a%2 == 1 && b%2 == 0) || (a%2 == 0 && b%2 == 1)) {
    ans = (a+b)/2 + 1;
  } else {
    ans = (a+b)/2;
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef long long ll;
const ll maxn = 1e5+100,mod = 1e9+7,INF = 1ll<<62;
ll a[maxn];
bool mark[maxn];
int main(){
	ll n,t=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]==i){
			mark[i]=1;
		}
	}
	for(int i=1;i<=n;i++){
		if(mark[i]==1){
			mark[i]=0;
			t++;
			if(i==1){
				swap(a[1],a[2]);
				if(mark[2]==1){
					mark[2]=0;
				}
			}
			else{
				if(mark[i+1]==1){
					mark[i+1]=0;
				}
			}
		}
	}
	cout<<t;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
long long n,W,dp[110][101000],v[110],w[110];
long long Min(long long x,long long y)
{
    if(x>y) return y;
    else return x;
}
int main()
{
    scanf("%lld%lld",&n,&W);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld%lld",&w[i],&v[i]);
    }

    for(int i=0;i<=n;i++)
    {
        for(int j=1;j<=100000;j++)
        {
            dp[i][j]=1e16;
        }
    }

    for(int i=1;i<=n;i++)
    {
        dp[i][0]=0;
    }
    dp[0][0]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=100000;j++)
        {
            //cout<<dp[i][j]<<" ";
            dp[i][j]=dp[i-1][j];
            if(v[i]>j) continue;
            dp[i][j]=Min(dp[i-1][j],dp[i-1][j-v[i]]+w[i]);
        }
        //cout<<endl;
    }
        //cout<<dp[n][85]<<endl;

    for(int i=100000;i>=0;i--)
    {
        if(dp[n][i]<=W)
        {
            //cout<<dp[n][i]<<" ";
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}


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

int main() {
    int N, K;
    string S;
    cin >> N >> S >> K;
    for (int i = 0; i < S.size(); ++i) {
        if(S[i] != S[K-1]) S[i] = '*';
    }
    cout << S;
    return 0;
}

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

#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
#define endl '\n'
// #define int long long

typedef pair<int,int> pii;
const int N = 50+5;
const int K = 105;
const int INF = 1e9;
const int MOD = 1e9+7;

int n, k;
int v[N];
int mem[N][N][K];
int solve(int l, int r, int k){
	if (k < 0) return -INF; //can't
	if (k == 0 || l > r) return 0;
	int &ret(mem[l][r][k]);
	if (ret != -1) return ret;
	int choice1 = solve(l+1, r, k-1) + v[l];
	int choice2 = solve(l, r-1, k-1) + v[r];
	int choice3 = solve(l+1, r, k-2);
	int choice4 = solve(l, r-1, k-2);
	int choice5 = 0;
	ret = max({choice1, choice2, choice3, choice4, choice5});
	return ret;
}
int32_t main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> n >> k;
	for(int i=0; i<n; i++) cin >> v[i];
	memset(mem, -1, sizeof mem);
	int ans = solve(0, n-1, k);
	cout << ans << endl;
	return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define REP(i,k,n) for(int i = k; i < n; i++)
#define mmax(start, end) *max_element(start, end)
#define mmin(start, end) *min_element(start, end)
#define argmax max_element
#define argmin min_element
#define push push_back
#define pop pop_back
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef string str;

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

template<class T = ll> T in() {
    T _in;
    cin >> _in;
    return _in;
}

#define EMAX 10000000

int cost[101][101];

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

    ll n=in();
    ll d[101];

    rep(i, n) {
        rep(j, n) {
            cost[i][j] = EMAX;
        }
        d[i] = EMAX;
    }

    rep(i, n) {
        int u=in<int>(), k=in<int>();
        rep(j, k) {
            int v=in<int>(), c=in<int>();
            cost[u][v] = c;
        }
    }

    // ノード0からの距離を調べる
    d[0] = 0;
    bool flag = true;
    while(flag) {
        flag=false;
        // 移動する方法のある全ノードからの，次のノードへの移動コストを考える
        rep(i, n) {
            if(d[i] != EMAX) {
                rep(j, n) {
                    if(i == j)
                        continue;
                    int next_c = d[i] + cost[i][j];

                    // 更新できる場合更新
                    if(d[j] > next_c) {
                        d[j] = next_c;
                        flag=true;
                    }
                }
            }
        }
    }

    rep(i, n) {
        cout << i << " " << d[i] << endl;
        // rep(j, n) {
        //     cout << cost[i][j] << " ";
        // }
        // cout << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3180
# -*- coding: utf-8 -*-

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, initial=1)
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, X = MAP()
aN = LIST()

aN.sort()
sm = sum(aN)
if sm < X:
    print(N-1)
elif sm == X:
    print(N)
else:
    x = X
    for i in range(N):
        x -= aN[i]
        if x < 0:
            print(i)
            exit()


Measured memory_bytes: 5276