akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main()
{
    long long n, m, k;
    int res=0;
    
    cin >> n >> m >> k;
    
    vector<long long> a(n+1, 0), b(m+1, 0);
    
    for (int i=1; i<=n; i++)
    {
        cin >> a[i];
        a[i]+=a[i-1];
    }
    
    for (int i=1; i<=m; i++)
    {
        cin >> b[i];
        b[i]+=b[i-1];
    }
    
    int j=m;
    for (int i=0; i<=n; i++)
    {
        if (a[i]>k)  break; 
        
        while (a[i]+b[j]>k)  j--;
        
        res=max(res, i+j);
    }
    
    cout << res << endl;
 
    return 0;
}

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

#ifdef PRINTERS
#include "printers.hpp"
using namespace printers;
#define tr(a)		cerr<<#a<<" : "<<a<<endl
#else
#define tr(a)    
#endif

#define ll          long long
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b)	for(int i=a;i<b;i++)
using namespace std;

void solve(){
	int H,W;
	cin>>H>>W;
	vi cnt(26);
	rep(i,0,H){
		string s;
		cin>>s;
		rep(j,0,W){
			cnt[s[j]-'a']++;
		}
	}
	int s4=(H/2)*(W/2);
	int s2=(H/2)*(W%2)+(W/2)*(H%2);
	int s1=(H%2)and(W%2);
	rep(i,0,26){
		int cur4=min(s4,cnt[i]/4);
		s4-=cur4;
		cnt[i]-=4*cur4;
		int cur2=min(s2,cnt[i]/2);
		s2-=cur2;
		cnt[i]-=2*cur2;
		int cur1=min(s1,cnt[i]/1);
		s1-=cur1;
		cnt[i]-=1*cur4;
	}
	if(s4+s2+s1){
		cout<<"No";
	}
	else{
		cout<<"Yes";
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
//	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int heights[n];
	for(int i = 0;i < n;++i)
		cin >> heights[i];
	int dp[n];
	dp[0] = 0;
	dp[1] = abs(heights[1] - heights[0]);
	for(int i = 2;i < n;++i)
		dp[i] = min(abs(heights[i]-heights[i-1]) + dp[i-1],abs(heights[i]-heights[i-2]) + dp[i-2]);
	cout << dp[n-1] << endl;
	return 0;
}

Measured memory_bytes: 1024
from collections import Counter
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    n = gete(int)
    s = []
    for _ in range(n):
        s.append(gete())

    c = Counter(s)

    for v in ['AC', 'WA', 'TLE', 'RE']:
        print(v, "x", c[v])


if __name__ == "__main__":
    main()


Measured memory_bytes: 16580
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define rg register
#define il inline
#define ll int
using namespace std;
il ll gi() {
    ll res=0; char ch=0;
    while(ch<'0'|| ch>'9'){ ch=getchar(); }
    while(ch>='0'&&ch<='9') res=res*10+ch-'0',ch=getchar();
    return res;
}
il void we(ll x) {
    if(x<0) putchar('-'),x=-x;
    if(x>9) we(x/10);
    putchar(x%10+'0');
}
struct st{
    ll num,cnt;
}a1[100088],a2[100088];
int cmp(st a,st b){
    return(a.cnt>b.cnt);
}
ll n,m,sum;
ll v[100088],m1=0,m2=0,b1[100088],b2[100088];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n/2;i++){
        v[i*2]=gi();
        a1[v[i*2]].cnt++;
        a1[v[i*2]].num=v[i*2];
        v[i*2+1]=gi();
        a2[v[i*2+1]].cnt++;
        a2[v[i*2+1]].num=v[i*2+1];
    }
    sort(a1,a1+100088,cmp);
    sort(a2,a2+100088,cmp);
    if(a1[0].num!=a2[0].num)we(n-a1[0].cnt-a2[0].cnt);
    else we(min(n-a1[1].cnt-a2[0].cnt,n-a1[0].cnt-a2[1].cnt));
    return 0;
}

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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;

  if (A+B < C+D) {
    cout << "Right" << endl;
  }else if (A+B > C+D) {
    cout << "Left" << endl;
  }else {
    cout << "Balanced" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
ll mod =  1000000007;
ll maxn = 1000000000;
 
//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------
 
int main(){
   int n,m,nans=0;
   
   cin>>n>>m;
   vvi skk(m,vector<int>(n));
   vi k(m),p(m);
   rep(i,m){
       cin>>k.at(i);
       rep(j,k.at(i))cin>>skk.at(i).at(j);
   }
   rep(i,m)cin>>p.at(i);
   
   for (int tmp = 0; tmp < (1 << n); tmp++) {
    bool ans=true;
    bitset<10> s(tmp);
    
    rep(i,m){
       int ns=0;
       
       rep(j,k.at(i)){
           int ws=skk.at(i).at(j)-1;
           if(s.test(ws))ns+=1;
       }
       
       if((ns%2)!=p.at(i)){
           ans=false;
           break;
       }
   }
    if(ans)nans++;
   }
   cout<<nans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

const ll mod = 1e9 + 7;
const ll IMF = 1LL<<29;
const double PI = 3.14159265358979323846;


// ***************************CODE**********************//





int n;
int f[101][11];
int p[101][11];

int main(){
        scanf("%d", &n);

        for(int i = 0; i < n ;i++){
                for(int j = 0; j < 10; j++){
                        cin >> f[i][j];
                }
        }

        for(int i = 0; i < n; i++){
                for(int j = 0; j <= 10; j++){
                        cin >> p[i][j];
                }
        }

        int ans = -1e9;
        for(int mask = 1; mask < (1 << 10); mask++){

                int tmp = 0;

                for(int i = 0; i < n; i++){
                        int num = 0;
                        for(int j = 0; j < 10; j++){
                                if(mask & (1 << j) && f[i][j] == 1){
                                        num++;
                                }
                        }
                        tmp += p[i][num];
                }

                chmax(ans,tmp);
        }

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


Measured memory_bytes: 256
import sys
n,m=map(int,input().split())
number=[[int(i) for i in l.split()] for l in sys.stdin]
visit=[0]*(n+1)
visit[1]=1
node=[[] for i in range(n+1)]
for i in number:
  node[i[0]].append(i[1])
  node[i[1]].append(i[0])
ans=0
def dfs(x):
  global ans
  if visit.count(1)==n:
    ans+=1
    return 0
  for i in node[x]:
    if visit[i]==0:
      visit[i]=1
      dfs(i)
      visit[i]=0
  return 0
dfs(1)
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
using namespace std;
const int N = 3e2+10;
int dp[N][N][N];
main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;cin>>s;
    int k;cin>>k;
    int n=s.length();
    for(int i=0;i<n;i++)
        for(int j=i+1;j<=n;j++)
            for(int ch=0;ch<=k;ch++){
                int curr=j-i;
                //cout<<curr;
                if(curr!=j){
                    if(s[curr-1]!=s[j-1]){
                        dp[j][curr][ch]=max(dp[j-1][curr][ch],dp[j][curr+1][ch]);
                        if(ch>0)
                            dp[j][curr][ch]=max(2+dp[j-1][curr+1][ch-1],dp[j][curr][ch]);
                        continue;
                    }
                    else
                        dp[j][curr][ch]=2+dp[j-1][curr+1][ch];
                }
                else
                    dp[j][curr][ch]=1;
            }
    cout<<dp[n][1][k];
}



Measured memory_bytes: 225536
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	while(1){
		ll n,P; cin >> n >> P;
		if(n==0 && P==0) break;
		vl v(n,0);
		ll now = 0;
		ll step = 0;
		ll p = P;
		while(1){
			if(p){
				p--;
				v[now]++;
			}else{
				p += v[now];
				v[now] = 0;
			}
			if(v[now]==P){
				cout << now << endl;
				break;
			}
			now = (now + 1) % n;
			step++;
		}
	}
}


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

void solve() {
    ll n, m;
    cin >> n >> m;
    Vl a(n);
    rep(i, 0, n) cin >> a[i];
    ll sum = 0;
    rep(i, 0, n) sum += a[i];
    ll cnt = 0;
    rep(i, 0, n) if(a[i] >= sum * (double)(1/(double)(4*m))) cnt++;
    if(cnt >= m) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

    solve();
    return 0;
}
 


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()
const long long INF = 1e18;
using namespace std;
typedef long long ll;
int main() {
  ll N;
  cin >> N;
  ll n_odd = 0;
  REP(i, N) {
    ll A;
    cin >> A;
    if (A % 2 != 0) {
      n_odd++;
    }
  }

  if (n_odd % 2 == 0) {
    cout << "YES";
  } else {
    cout << "NO";
  }

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll ;
typedef double db;
typedef long double ldb;
typedef unsigned long long ull ;
const double PI = acos(-1) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define for0(i,n)          for(int i=0;i<n;i++)
#define for1(i,n)          for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
//#define gcd(a, b)     __gcd(a, b)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
//#define abs(x)		fabs(x)
#define pcase(z,x)     cout<<"Case "<<z<<": "<<x<<"\n"
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)
#define max 1000000007

using namespace std;
//int n,m,y,x,h,e,l,o,i,j;

int main()
{
	CIN;
	char s,t;
	cin>>s;
	t=toupper(s);
	if(t==s)cout<<"A"<<nw;
	else cout<<"a"<<nw;

	//cout<<t<<nw;


	
}


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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  while(true) {
    c -= b;
    if(c <= 0) break;
    a -= d;
    if(a <= 0) break;
  }
  if(a > 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

using namespace std;

int main(){
	string s;
	string s1;
	cin>>s>>s1;
	for(int i=0;i<s.length();i++){
		if(s[i] != s1[i]){
			cout<<"No"<<endl;
			return 0; 
		}
	}
	cout<<"Yes"<<endl;
	return 0;
} 

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll aa[100000];
int main()
{
	ll a,b,c,d=0,e=0,f=0,g;
	cin>>a>>b>>c;
	for(ll i=0;i<a;i++){
		cin>>g;
		if(g<=b){
			d++;
		}else if(b+1<=g&&g<=c){
			e++;
		}else{
			f++;
		}
	}
	cout<<min({d,e,f});
}

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

int main() {
    string a, b;
    cin >> a >> b;
    if (a.size() > b.size()) cout << "GREATER" << endl;
    if (a.size() < b.size()) cout << "LESS" << endl;
    if (a.size() == b.size()) {
        for (int i = 0; i < a.size(); i++) {
            if (a[i] > b[i]) {
                cout << "GREATER" << endl;
                return 0;
            } else if (a[i] < b[i]) {
                cout << "LESS" << endl;
                return 0;
            }
        }
        cout << "EQUAL" << endl;
    }
    return 0;
}

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

int main() {
    int n;
    cin >> n;
   
   int max=0;
   int ans=1;
   for(int i=1; i<=n; i++){
       int cnt=0;
       int a=i;
   while (a%2==0){
       a/=2;
       cnt++;
   }
   if(cnt>max){
        max=cnt;
        ans=i;
   }
   }
   cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include <iterator>
#include <map>
#include<cmath>
using namespace std;


int main (){
  string r,y,u;
  int a,b;
  cin>>r>>y>>a>>b>>u;
  if(u==r)
    cout<<--a<<" "<<b<<endl;
  else
    cout<<a<<" "<<--b<<endl;
 

return 0;
}

















Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var rdx = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var r = rdx[0];
        var d = rdx[1];
        var x2000 = rdx[2];

        var xx = x2000;
        for (int i = 2001; i <= 2010; i++)
        {
            xx = r * xx - d;
            Console.WriteLine(xx);
        }
    }
}


Measured memory_bytes: 13396
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    if(a+b<10){
      System.out.println(a+b);
    }else{
      System.out.println("error");
    }
  } 
}

Measured memory_bytes: 20564
#include<bits/stdc++.h>
using namespace std;
typedef pair< int , int > Pi;

bool judge(int area){
  //式変形だね!!
  //area - y = (2y + 1)x
  //(area - y) % (2y + 1)
  //適当に50000でどう？
  for(int y = 1; y < min< int >(50000, area); y++){ 
    if((area - y) % (2 * y + 1) == 0) return true;
  }
  return false;
}

int main(){
  int N, room[100000];

  scanf("%d", &N);
  for(int i = 0; i < N; i++){
    scanf("%d", &room[i]);
  }
  int ret = 0;
  for(int i = 0; i < N; i++){
    ret += !judge(room[i]);
  }
  printf("%d\n", ret);
}

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

int n;
double p[3003], dp[3003][3003];

int main() {
	memset(dp, 0, sizeof(dp));
	scanf("%d", &n);
	for(int i = 1;i <= n; i++) {
		scanf("%lf", &p[i]);
	}
	
	dp[1][1] = p[1];
	dp[1][0] = 1.0-p[1];
	for(int i = 2;i <= n; i++) {
		for(int j = 0;j <= i; j++) {
			if(j == 0) dp[i][j] = dp[i-1][j]*(1-p[i]);
			else dp[i][j] = dp[i-1][j-1]*p[i] + dp[i-1][j]*(1-p[i]);
		}
	}
	
	double ans = 0;
	for(int i = (n+1)/2;i <= n; i++) {
		ans += dp[n][i];
	}
	
	printf("%.10lf\n", ans);
}

Measured memory_bytes: 74292
import math


def merge(S, left, mid, right) -> int:
    # n1 = mid - left
    # n2 = right - mid
    L = S[left: mid]
    R = S[mid: right]

    # for i in range(n1):
    #     L.append(S[left + i])
    L.append(math.inf)

    # for i in range(n2):
    #     R.append(S[mid + i])
    R.append(math.inf)

    i = 0
    j = 0

    for k in range(left, right):
        if L[i] <= R[j]:
            S[k] = L[i]
            i += 1
        else:
            S[k] = R[j]
            j += 1

    return right - left


def merge_sort(S, left, right):
    count = 0

    if left + 1 < right:
        mid = int((left + right) / 2)
        count += merge_sort(S, left, mid)
        count += merge_sort(S, mid, right)
        count += merge(S, left, mid, right)

    return count


def main():
    n = int(input())
    S = list(map(int, input().split()))
    count = 0

    count = merge_sort(S, 0, n)

    print(*S)
    print(count)


if __name__ == "__main__":
    main()



Measured memory_bytes: 67876
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>

#define barsik ios::sync_with_stdio(false)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)

typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair <int, int> pii;
typedef std::unordered_set <int> u_si;

using namespace std;

void solve(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << c - min(a - b, c);
}

int main(){
    barsik;
    int q = 1;
    //cin >> q;
    while(q--) solve();
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(int (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
const ll MOD=1e9+7;
using namespace std;

int main(){
  int N,M,C;
  cin >> N >> M >> C;
  vector<int> b(M);
  vector< vector<int> > a(N, vector<int>(M));
  int ans=0;
  rep(i,M) cin >> b[i];
  rep(i,N){
    int sum=0;
    rep(j,M){
      int a;
      cin >> a;
      sum+=(a*b[j]);
    }
    if(sum+C>0) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[1000];
int main()
{
	long long n,tmp=1,len=1;
	cin >> n;
	while (n>0)
	{
		len++;
		tmp*=26;
		n-=tmp;
	}
	n+=tmp;
	len--;
	n--;
	for (int i=1;i<=len;i++)
	{
		a[i]='a'+n%26;
		n/=26; 
	}
	for (int i=len;i>=1;i--)
	{
		cout << a[i]; 
	}
	return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
int main (void)
{
  int m,f,r;
  while(1){ 
    scanf("%d%d%d",&m,&f,&r);
    if((m==-1)&&(f==-1)&&(r==-1))break;
    if((m==-1||f==-1)||((m+f)<30)){
      printf("F\n");
    }else if(80<=(m+f)){
      printf("A\n");
    
    }else if(65<=(m+f)){
      if((m+f)<80){
	printf("B\n");
      }
    }else if(50<=(m+f)){
      if((m+f)<65){
	printf("C\n");
      }
    }else if(30<=(m+f)){
      if(50<=r){
	printf("C\n");
      }else if((m+f)<50){
	printf("D\n");
      }
    }
  }
    return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define MOD 1000000007
#define INF 1000000000000000007LL

const int N = 100005;
 
// it's swapnil07 ;)
 
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif

vector<int> vect;
bool dp[N];
bool vis[N];

bool calc(int x){
	if(vis[x])
		return dp[x];
	vis[x]=true;
	bool fl = false;
	for(int v: vect){
		if(v <= x)
			fl = fl | (1-calc(x-v));
	}
	dp[x]=fl;
	return fl;
}

signed main()
{
    fast
    #ifdef SWAPNIL07
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    int n, k; cin>>n>>k;
    vect.resize(n);
    For(i, 0, n){
    	cin>>vect[i];
    }
    if(calc(k)){
    	cout<<"First";
    }
    else{
    	cout<<"Second";
    }
    return 0;
}




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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

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;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

vector< pair<ll,ll> > prime_factorize(ll n){
    vector<pair<ll, ll> > res;
    for (ll p = 2; p*p<=n; ++p){
        if(n%p != 0) continue;
        int num = 0;
        while(n%p == 0){
            ++num; 
            n /= p; 
        }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n,1));
    return res;
}

void solve(long long A, long long B){
    int n=gcd(A,B);
    auto v=prime_factorize(n);
    cout<<v.size()+1<<endl;
}

// Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
signed main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


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

int main() {
	long a,b,v,w,t;
	cin>>a>>v>>b>>w>>t;
	if(a>b) swap(a,b);
	if(a+v*t>=b+w*t) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}

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

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC targett("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define endl        '\n'
#define ll          long long int
#define pb          push_back
#define sz(x)       (int)(x).size()
const ll mod = 1e9 + 7;

ll gcd(ll a, ll b) {
	if (b == 0)  return a;
	return gcd(b , a % b);
}


ll powm(ll a, ll b) {
	ll res = 1;
	while (b) {
		if (b & 1)
			res = (res * 1LL * a) % mod;
		b >>= 1LL;
		a = (a * 1LL * a) % mod;
	}
	return res;
}

//--------------------------------------------------------------------------------------------------------------------------//
const int N = 1e5 + 5;
vector<int> g[N];
int dp[N];
int solve(int v) {
	if (dp[v] != -1)
		return dp[v];
	dp[v] = 0;
	for (int u : g[v]) {
		dp[v] = max(dp[v] , solve(u) + 1);
	}
	return dp[v];
}

int main() {
	fast
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n, m;
	cin >> n >> m;

	for (int i = 0, a, b; i < m; i++) {
		cin >> a >> b;
		g[a].pb(b);
	}
	memset(dp, -1, sizeof dp);
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		ans = max(solve(i), ans);
	}
	cout << ans << endl;
	return 0;

}





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

x4 = 0
x2 = 0
x0 = 0
for a in A:
    if a % 4 == 0:
        x4 += 1
    elif a % 2 == 0:
        x2 += 1
    else:
        x0 += 1

if x2==0:
    if x4 >= x0 - 1:
        ans = 'Yes'
    else:
        ans = 'No'
else:
    if x4 >= x0:
        ans = 'Yes'
    else:
        ans = 'No'
print(ans)

Measured memory_bytes: 14224
#include<iostream>
using namespace std;
#define ll long long
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll a,b,c,d,cc,dd,e,ff;
int main()
{
	cin>>a>>b>>c>>d;
	cc=(b-b%c-(a%c==0?a:a-a%c+c))/c+1;
	dd=(b-b%d-(a%d==0?a:a-a%d+d))/d+1;
	e=c*d/gcd(c,d);
	ff=(b-b%e-(a%e==0?a:a-a%e+e))/e+1;
	cout<<b-a+1-cc-dd+ff;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
class DisjointSet{
private:
  vector< int > rank, p;
  void link(int x,int y){
    if(rank[x] > rank[y]){
      p[y] = x;
    } else {
      p[x] = y;
      if(rank[x] == rank[y]) rank[y]++;
    }
  }
public:
  DisjointSet(int size){
    rank.resize(size,0);
    p.resize(size,0);
    for(int i = 0; i < size; i++) p[i] = i, rank[i] = 0;
  }
  void Union(int x,int y){
    if(Find(x) != Find(y)) link(Find(x),Find(y));
  }
  int Find(int x){
    return( x != p[x] ? p[x] = Find(p[x]) : p[x]);
  }
};

struct edge{
  int u, v, cost;
  bool operator<(const edge& e) const {
    return cost < e.cost;
  }
};

int main(){
  int n, m;
  while(cin >> n >> m, n){
    vector< edge > edges;
    for(int i = 0; i < m; i++){
      int s, t, c;
      cin >> s >> t >> c;
      edges.push_back((edge){ s - 1, t - 1, c});
    }
    sort(edges.begin(), edges.end());
    DisjointSet UnionFind(n);
    int mid = 0, sz = 0;
    for(int i = 0; i < edges.size(); i++){
      edge& e = edges[i];
      if(UnionFind.Find(e.u) != UnionFind.Find(e.v)){
        UnionFind.Union( e.u, e.v);
        if((n - 1) / 2 == sz) mid = e.cost;
        if((n - 1) % 2 == 0 && sz == (n - 1) / 2 + 1) mid = (mid + e.cost) / 2;
        ++sz;
      }
    }
    cout << mid << endl;
  } 
}

Measured memory_bytes: 1440
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl "\n"
using namespace std;


int32_t main() {

    fast
    int x,k,d;
    cin>>x>>k>>d;

    x=abs(x);
    int pos;
    if(d>=((x+k-1)/k) && ((k+d-1)>=(x/d))){
        int rightMoves=(x/d);
        int leftMoves=rightMoves+1;

        int left=k-rightMoves;
        if(left%2==0){
            pos=x-rightMoves*d;
        }
        else{
            pos=leftMoves*d-x;
        }
    }
    else{
        pos=x-k*d;
    }
    cout<<pos<<endl;


    return 0;
}



Measured memory_bytes: 3644
<?php
list($n, $m, $r) = ints();
$rr = ints();
$dk = new Dijkstra($n);
for ($i = 0; $i < $m; ++$i) {
    list($a, $b, $c) = ints();
    $a--;
    $b--;
    $dk->connect($a, $b, $c);
    $dk->connect($b, $a, $c);
}
for ($i = 0; $i < $r; ++$i) {
    $rr[$i]--;
    $dk->solve($rr[$i]);
}
echo dfs();

function dfs($d = 0, $p = 0, $used = [])
{
    global $r, $rr, $dk;

    if ($d >= $r) return 0;
    foreach ($rr as $next) {
        if (array_search($next, $used) !== false) continue;
        if ($d > 0) {
            $res[] = $dk->dist($p, $next) + dfs($d + 1, $next, array_merge($used, [$next]));
        } else {
            $res[] = dfs($d + 1, $next, array_merge($used, [$next]));
        }
    }
    return min($res);
}
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}

class Dijkstra
{
    private $n;
    private $d; // 最短距離を格納
    private $cost; // ノード間の距離を格納
    private $root; // 最短経路を格納

    function __construct($n)
    {
        $this->n = $n;
        $this->cost = array_fill(0, $this->n, array_fill(0, $this->n, INF));
    }

    function connect($x, $y, $w)
    {
        $this->cost[$x][$y] = $w;
    }

    function solve($s = 0)
    {
        $this->d[$s] = array_fill(0, $this->n, INF);
        $this->d[$s][$s] = 0;
        $this->root[$s] = array_fill(0, $this->n, [$s]); // 各ノードまでの最短経路を格納
        $used = array_fill(0, $this->n, false);
        while (true) {
            $v = -1;
            // 残りのノードのうち最短で到達出来るノードを選択
            for ($i = 0; $i < $this->n; ++$i) {
                if (!$used[$i] && $v === -1) $v = $i;
                elseif (!$used[$i] && $this->d[$s][$i] < $this->d[$s][$v]) $v = $i;
            }
            if ($v === -1) break;
            for ($i = 0; $i < $this->n; ++$i) {
                if ($this->d[$s][$i] > $this->d[$s][$v] + $this->cost[$v][$i]) {
                    $this->d[$s][$i] = $this->d[$s][$v] + $this->cost[$v][$i];
                    $this->root[$s][$i] = array_merge($this->root[$s][$v], [$i]);
                }
            }
            $used[$v] = true;
        }
    }

    function dist($x, $y)
    {
        return $this->d[$x][$y];
    }

    function root($x, $y)
    {
        return $this->root[$x][$y];
    }
}


Measured memory_bytes: 10744
# coding: utf-8
n = int(input())

syogen = []
for i in range(n):
    a = int(input())
    tmp = []
    for j in range(a):
        x, y = map(int, input().split())
        tmp.append([x,y])
    syogen.append(tmp)

result = 0
for i in range(2**n):
    katei = []
    is_out = 0
    ninzu = 0
    for j in range(n):
        if int(i / (2**(j))) % 2:
            katei.append(1)
            ninzu += 1
        else:
            katei.append(0)
    if ninzu <= result:
        continue
    for j in range(n):
        if katei[j] == 1:
            for gen in syogen[j]:
                if katei[gen[0]-1] != gen[1]:
                    is_out = 1
    if is_out == 0:
        result = ninzu

print(result)

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

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

typedef long long ll;
typedef pair<int, int> P;

#define MAX 100005
#define INF 1001001001

int main(int, char**)
{
  multimap<string, int> a;
  int q;
  cin >> q;
  vector<string> ans;
  rep(i,q) {
    int command; cin >> command;
    if (command == 0) {
      string key;
      int x;
       cin >> key >> x;
      a.emplace(key,x);
    } else if (command == 1) {
      string key; cin >> key;
      auto itre = a.equal_range(key);
      for (auto itr = itre.first; itr != itre.second; itr++) {
        stringstream ss;
        ss << (*itr).second;
        ans.push_back(ss.str());
      }
    } else if (command == 2) {
      string key; cin >> key;
      a.erase(key);
    } else if (command == 3) {
      string l, r; cin >> l >> r;
      auto itr1 = a.lower_bound(l);
      auto itr2 = a.upper_bound(r);
      for (auto itr = itr1; itr != itr2; itr++) {
        stringstream ss;
        ss << (*itr).first << " " << (*itr).second;
        ans.push_back(ss.str());
      }
    }
  }

  for (auto a : ans) cout << a << endl;

  return 0;
}



Measured memory_bytes: 53468
//https://atcoder.jp/contests/abc153/tasks/abc153_d
#include <bits/stdc++.h>
#define in cin >> 
#define out cout <<
#define Vi vector<long int>
#define FOR(i,k,l) for(int i(k); i<l;i++)
#define M 100002
#define heck unsigned long long int

using namespace std;

heck rec(heck H) {
    if (H == 1) return 1;
    else {
        return 2 * rec(H/2) + 1;
    }
}

int main(void) {
    heck H = 0;
    in(H);
    
    out(rec(H));
}


Measured memory_bytes: 256
import numpy as np

H, W = map(int, input().split())
a = [list(input()) for _ in range(H)]

a = [a[idx] for idx in range(len(a)) if a[idx].count(".") < len(a[idx])]
a = np.array(a).T.tolist()
a = [a[idx] for idx in range(len(a)) if a[idx].count(".") < len(a[idx])]
a = np.array(a).T.tolist()

for row in range(len(a)):
    print("".join(a[row]))

Measured memory_bytes: 12520
package main

import (
  "bufio"
  "bytes"
  "fmt"
  "os"
  "strings"
  "strconv"
)

func main() {
  br := bufio.NewReader(os.Stdin)
  var buffer bytes.Buffer

  for {
    line, isPrefix, err := br.ReadLine()
    if err != nil {
      panic(err)
    }
    buffer.Write(line)
    if !isPrefix {
      break
    }
  }

  sli := strings.Split(buffer.String(), " ")
  A, _ := strconv.Atoi(sli[0])
  B, _ := strconv.Atoi(sli[1])
  K, _ := strconv.Atoi(sli[3])
  if A < K {
    if A + B > K {
      fmt.Println(A)
    }else{
      fmt.Println(2*A+B-K)
    }
  }else{
    fmt.Println(K)
  }
}


Measured memory_bytes: 1760
#include <stdlib.h>
#include <math.h>

int main(void)
{
  int K,i,j;
  long int A[100000] = {1,2,3,4,5,6,7,8,9};
  long int N;
  scanf("%d",&K);

  j = 0;

  for(i=9;i<100000;i++)
  {
    if(A[j]%10 == 0)
    {
      A[i] = A[j]*10;
      A[i+1] = A[i]+1;
    }
    else if(A[j]%10 == 9)
    {
      A[i] = A[j]*10+8;
      A[i+1] = A[i]+1;
    }
    else
    {
      A[i] = A[j]*10 + A[j]%10 - 1;
      A[i+1] = A[i]+1;
      A[i+2] = A[i]+2;
      i++;
    }
    i++;
    j++;
  }

  printf("%ld\n",A[K-1]);

  return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

int main()
{
	int N;
	int H[100]={};

	cin >> N;
	for(int i=0;i<N;i++)
		cin >> H[i];
	
	int ans=0;
	for(int i=0;i<N;i++)
	{
		bool ok=true;
		for(int j=0;j<i;j++)
		{
			if(H[j]>H[i])ok=false;
		}
		if(ok)
			ans++;
	}

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr char OP[] = {'+', '-', '*'};
int p[] = {0, 0, 0};
ll Plus(const ll a, const ll b) { return a + b; }
ll Minus(const ll a, const ll b) { return a - b; }
ll Prod(const ll a, const ll b) { return a * b; }
using Func = ll (*)(const ll, const ll);
Func f[] = {Plus, Minus, Prod};
string S;
int pos;

ll expr();
ll number()
{
    ll ans = 0;
    for (; pos < S.size() and isdigit(S[pos]); pos++) { ans = ans * 10LL + S[pos] - '0'; }
    return ans;
}
ll atom()
{
    const char c = S[pos];
    if (c == '(') {
        pos++;
        const ll sub = expr();
        return pos++, sub;
    } else {
        return number();
    }
}
ll factor()
{
    ll ans = atom();
    for (bool fin = false; not fin and pos < S.size();) {
        fin = true;
        for (int i = 0; i < 3; i++) {
            if (S[pos] == OP[i] and p[i] == 2) {
                pos++;
                const ll sub = atom();
                fin = false, ans = f[i](ans, sub);
            }
        }
    }
    return ans;
}
ll term()
{
    ll ans = factor();
    for (bool fin = false; not fin and pos < S.size();) {
        fin = true;
        for (int i = 0; i < 3; i++) {
            if (S[pos] == OP[i] and p[i] == 1) {
                pos++;
                const ll sub = factor();
                fin = false, ans = f[i](ans, sub);
            }
        }
    }
    return ans;
}
ll expr()
{
    ll ans = term();
    for (bool fin = false; not fin and pos < S.size();) {
        fin = true;
        for (int i = 0; i < 3; i++) {
            if (S[pos] == OP[i] and p[i] == 0) {
                pos++;
                const ll sub = term();
                fin = false, ans = f[i](ans, sub);
            }
        }
    }
    return ans;
}
int main()
{
    cin >> S;
    ll ans = numeric_limits<ll>::min();
    for (p[0] = 0; p[0] < 3; p[0]++) {
        for (p[1] = 0; p[1] < 3; p[1]++) {
            for (p[2] = 0; p[2] < 3; p[2]++) {
                pos = 0;
                const ll sub = expr();
                ans = max(ans, sub);
            }
        }
    }
    cout << ans << endl;
    return 0;
}



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

int main() {
    int a, b;
    cin >> a >> b;
    cout << (a == b ? "Yes" : "No") << '\n';
    return 0;
}


Measured memory_bytes: 256
N, L = map(int, input().split())
a = list(map(int, input().split()))
S = sum(a)

t = 0
m = 0
for k in range(len(a)-1):
    if a[k]+a[k+1]>=L:
        t = 1
        m = k+1
        break
if t == 0:
    print("Impossible")
    exit()
else:
    print("Possible")
    for k in range(1,m):
        print(k)
    for l in range(len(a)-(k+2)):
        print(len(a)-l-1)
    print(m)

Measured memory_bytes: 72940
const line = require('fs').readFileSync('/dev/stdin', 'utf-8').split('\n');

const merge = (arr1, arr2) => {
    if (arr1.length === 0) return arr2;
    if (arr2.length === 0) return arr1;
    const head1 = arr1[0];
    const tail1 = arr1.slice(1);
    const head2 = arr2[0];
    const tail2 = arr2.slice(1);

    if (head1[1] <= head2[1]) return [head1, ...merge(tail1, arr2)];
    else return [head2, ...merge(arr1, tail2)];
};

const msort = arr => {
    if (arr.length <= 1) return arr;
    const n = Math.floor(arr.length / 2);
    const t = arr.slice(0, n);
    const b = arr.slice(n);
    return merge(msort(t), msort(b));
};


const partition = arr => {
    const x = arr[arr.length-1][1];
    const result = [...arr];
    let i = -1;
    for (let j = 0; j < arr.length - 1; j++) {
        if (result[j][1] <= x) {
            i++;
            const tmp = result[i];
            result[i] = result[j];
            result[j] = tmp;
        }
    }
    const tmp = result[i+1];
    result[i+1] = result[arr.length-1];
    result[arr.length-1] = tmp;

    return [i+1, result];
}

const qsort = arr => {
    if (arr.length <= 1) return arr;
    const newArr = partition(arr);
    const mid = newArr[1][newArr[0]];
    const l = newArr[1].slice(0, newArr[0]);
    const r = newArr[1].slice(newArr[0]+1);
    return [...qsort(l), mid, ...qsort(r)];
};

const check = target => {
    for (let i = 1; i < target.length; i++) {
        if (target[i][1] === target[i-1][1] && target[i][2] < target[i-1][2]) {
            return false;
        }
    }
    return true;
};

const data = line.slice(1, parseInt(line[0])+1)
                 .map(x => x.split(' '))
                 .map((xs, i) => [xs[0], Number(xs[1]), i]);

const qsorted = qsort(data);

console.log(check(qsorted) ? 'Stable' : 'Not stable');
qsorted.map(x => x.slice(0, 2))
       .map(x => x.join(' '))
       .forEach(x => console.log(x));



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

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef set<ll> si;
typedef map<string, ll> msi;
#define hell 1000000007
#define MAX 1000000000
#define max_int 1000000
#define F first
#define re 15000000
#define S second
#define pb push_back
#define all(a)  (a).begin(),(a).end()
#define rep(i,a,b) for(ll i = a;i<b;i++)
#define pi 3.1415926536
#define r0 return 0
#define rep(i,a,b) for(ll i = a;i<b;i++)



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n,m,x;
    cin>>n>>m>>x;
    ll c[n],a[n][m];
    for(int i=0;i<n;i++)
    {
        cin>>c[i];
        for(int j=0;j<m;j++)
            cin>>a[i][j];
    }
    vector<string>v;
    v.pb("0");
    v.pb("1");
    int lst=0,cur=2;
    while(1)
    {
        for(int i=lst;i<cur;i++)
        {
            v.pb(v[i]+'0');
            v.pb(v[i]+'1');
        }
        lst=cur;
        cur=v.size();
        if(v[cur-1].size()>n)
            break;
    }
    ll min_cost=1e9;
    for(int i=0;i<v.size();i++)
    {
        //cout<<v[i].size()<<endl;
        if(v[i].size()<n)
            continue;
        else if(v[i].size()>n)
            break;
        ll cost=0, algo[m]={0};
        for(int j=0;j<v[i].size();j++)
        {
            if(v[i][j]=='1')
            {
                cost+=c[j];
                for(int k=0;k<m;k++)
                {
                    algo[k]+=a[j][k];
                }
            }
        }
        bool f=0;
        for(int j=0;j<m;j++)
        {
            if(algo[j]<x)
            {
                f=1;
                break;
            }
        }
        if(!f)
            min_cost=min(min_cost,cost);
        else continue;
    }
    if(min_cost==1e9)
        cout<<-1;
    else cout<<min_cost;


}
 

Measured memory_bytes: 3844
import sys

n = int(input())
d = list(map(int, input().split( )))

if d[0]!= 0:
    print(0)
    sys.exit()

d.sort()
if n >=2:
    if d[1] == 0:
        print(0)
        sys.exit()

for i in range(n-1):
    if d[i]>d[i+1] or d[i]+1<d[i]:
        print(0)
        sys.exit()

m = max(d)

cnt = {i:0 for i in range(1,m+1)}

for i in range(1,n):
    cnt[d[i]] += 1
mod = 998244353

ans = 1

for i in range(2,m+1):
    ans *= pow(cnt[i-1],cnt[i],mod)
    ans %=mod

print(ans)

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

using namespace std;

typedef long long LL;
typedef double LF;

#define clr(x, y) memset(x, y, sizeof(x))

inline LL read(){
	LL r = 0, z = 1; char ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-') z = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9'){r = r * 10 + ch - '0'; ch = getchar();}
	return r * z;
}

LL n, a, b, c;

void work(){
	n = read();
	while(n --){
		a = read(), b = read();
		if(a == b) printf("%lld\n", 2 * a - 2);
		else if(a + 1 == b) printf("%lld\n", 2 * a - 2);
		else {
			c = sqrt(a * b); if(c * c == a * b) c --;
			if(c * (c + 1) < a * b) printf("%lld\n", 2 * c - 1);
			else printf("%lld\n", 2 * c - 2);
		}
	}
}

int main(){
	work();
	return 0;
}

Measured memory_bytes: 256
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define MOD 1000000007

char c[1010][1010];
vector<vector<pair<int, int>>> graph(1010 * 1010);

int main()
{
    int h, w;
    cin >> h >> w;
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    sx--;
    sy--;
    tx--;
    ty--;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin >> c[i][j];
        }
    }
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (c[i][j] == '#')
                continue;
            for (int l = max(0, i - 2); l < min(h, i + 3); l++)
            {
                for (int k = max(0, j - 2); k < min(w, j + 3); k++)
                {
                    if ((l == i && k == j) || c[l][k] == '#')
                        continue;
                    if (abs(l - i) + abs(k - j) == 1)
                    {
                        graph[w * i + j].push_back(make_pair(w * l + k, 0));
                    }
                    else
                    {
                        graph[w * i + j].push_back(make_pair(w * l + k, 1));
                    }
                }
            }
        }
    }
    priority_queue<pair<int, int>> qu;
    qu.push(make_pair(0, w * sx + sy));
    vector<int> res(h * w, MOD);
    while (!qu.empty())
    {
        int now = (qu.top()).second;
        int cost = -(qu.top()).first;
        qu.pop();
        if (cost > res[now])
            continue;
        for (int i = 0; i < graph[now].size(); i++)
        {
            int next = graph[now][i].first;
            int nextc = cost + graph[now][i].second;
            if (res[next] > nextc)
            {
                res[next] = nextc;
                qu.push(make_pair(-nextc, next));
            }
        }
    }
    if (res[w * tx + ty] == MOD)
        cout << -1 << endl;
    else
        cout << res[w * tx + ty] << endl;
}

Measured memory_bytes: 101940
#include<bits/stdc++.h>
using namespace std;
string s, t;
int cnt = 0, ans = 2147483647;
int main() {
	cin >> t;
	for (char c = 'a'; c <= 'z'; c ++) {
		s = t;
		cnt = 0;
		while(1) {
			int flag = 0;
			for (int i = 0; i < s.length(); i ++) if (s[i] != c) flag = 1;
			if (!flag) {
				ans = min(ans, cnt); break;
			}
			cnt ++;
			for (int i = 0; i < s.length() - 1; i ++) {
				if (s[i] == c || s[i + 1] == c) s[i] = c;
			}
			s.erase(s.length() - 1);
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
	int n,k;
	cin>>k;
	ll ans=0; 

	for(int a=1; a<=k; a++)
	{
		for(int b=1; b<=k; b++)
		{
			for(int c=1; c<=k; c++)
			{
				ans=ans+__gcd(a,__gcd(b,c)); 

			}
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long ll;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
ll gcd(ll a, ll b){
    if(b==0) return a;
    else return gcd(b, a%b);
}
ll A,B,C,D;
ll lcmcd;
ll func(ll N){
    ll xd=N/D;
    ll xc=N/C;
    ll xcd=N/lcmcd;
    return N-xc-xd+xcd;
}
signed main(){
    cin>>A>>B>>C>>D;
    lcmcd =  C*D/gcd(C,D);
    cout << func(B)-func(A-1) << endl;
    return 0;
}

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

int main() {
    //input
    int k,s;
    cin >> k >> s;

    int count=0;
    for(int i=0;i<=k;i++){
        for(int j=0;j<=k;j++){
            int z = s - i - j;
            if(0 <= z && z <= k){
                count++;
            }
        }
    }
    cout << count << endl;

    return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll,ll> P;

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9*1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}


int main()
{
	ll n,m,l;
	cin>>n>>m>>l;
	vector<vector<P>> g(n);
	rep(i,m){
		ll a,b,c;
		cin>>a>>b>>c;
		a--;b--;
		if(c<=l){
			g[a].push_back(P(b,c));
			g[b].push_back(P(a,c));
		}
	}

	ll q;
	cin>>q;
	vector<ll>s(q),t(q);
	rep(i,q){
		cin>>s[i]>>t[i];
		s[i]--;t[i]--;
	}
	vector<vector<ll>> dist(n,vector<ll>(n,INF));
	rep(i,n)dist[i][i]=0;
	rep(i,n){
		rep(j,g[i].size())dist[i][g[i][j].first] = g[i][j].second;
	}

	rep(k,n){
		rep(i,n){
			rep(j,n){
				dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);
			}
		}
	}

	vector<vector<ll>> gg(n);
	rep(i,n){
		repi(j,i+1,n){
			if(i==j)continue;
			if(dist[i][j]<=l){
				gg[i].push_back(j);
				gg[j].push_back(i);
			}
		}
	}
	vector<vector<ll>> dist2(n,vector<ll>(n,INF));
	rep(i,n)dist2[i][i]=0;
	rep(i,n){
		rep(j,gg[i].size())dist2[i][gg[i][j]] = 1;
	}

	rep(k,n){
		rep(i,n){
			rep(j,n){
				dist2[i][j] = min(dist2[i][j],dist2[i][k]+dist2[k][j]);
			}
		}
	}

	rep(i,q){
		cout<<(dist2[s[i]][t[i]]==INF?-1:dist2[s[i]][t[i]]-1)<<endl;
	}



	return 0;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define INF 999999999
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define Vecpr vector<pair<lli,lli>>
int main() {
  lli N,A,X;
  cin >> N>>A>>X;
  if(N>X)Out("NO");
  else if(N+A<X)Out("NO");
  else Out("YES");
}


Measured memory_bytes: 256