akhauriyash/Code-Regression huggingface dataset:
import os, sys, re, math

N = input()

def get_count(s, count):
    z = s.find('*')
    t = s
    for c in '7530':
        if c == '0' and len(t[:z].replace('0', '')) > 0:
            continue
        t = t[:z] + c + t[z + 1:]
        if z < len(s) - 1:
            count = get_count(t, count)
        else:
            if int(t) <= int(N) and t.find('7') >= 0 and t.find('5') >= 0 and t.find('3') >= 0 and t.find('0') <= 0:
                count += 1
    return count

count = get_count('*' * len(N), 0)
print (count)

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

int main(){
    while(true){
        std::string s;
        std::cin>>s;
        if(s=="#")break;
        int y,m,d;
        std::cin>>y>>m>>d;
        if(y>31){s="?";y-=30;}
        else if(y==31&&m>4){s="?";y-=30;}
        std::cout<<s<<" "<<y<<" "<<m<<" "<<d<<std::endl;
    }
    return 0;
}



Measured memory_bytes: 3136
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i = 0; i < n; i++)

int main(void)
{
    string s,t;
    cin >> s >> t;
    REP(i, s.length()) {
        if(s==t) {
            cout << "Yes" << endl;
            return 0;
        }
        s = s[s.length()-1] + s.substr(0,s.length()-1);
//        cout << s << endl;
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) {
    
    new Main().run();
  }

  public void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      String op;
      String[] words;
      Tree tree = new Tree();

      for(int i=0,k=0; i<n; i++,k=0){
        words = br.readLine().split(" ");
        op  = words[k++];
        if ( op.equals("insert") ) { 
          tree.insert(Integer.parseInt(words[k++]));
        }
        else {
          tree.dispRoundPath();
        }
      }

    }
    catch(IOException e) {
      System.out.println("IOException!");
    }
  }
}

class Tree {

  static final BTreeNode NIL = new BTreeNode(-1);
  BTreeNode root;
  StringBuilder buf;

  public Tree() {
    root = NIL;
    buf = new StringBuilder();
  }

  public void insert(int val) {
    BTreeNode y = NIL;
    BTreeNode x = root;
    BTreeNode z = new BTreeNode(val);

    while( !x.equals(NIL) ) {
      y = x;
      if( z.key < x.key )
        x = x.left;
      else
        x = x.right;
    }
    z.parent = y;

    if( y.equals(NIL) ){
      root = z;
    }
    else if( z.key < y.key )
      y.left = z;
    else
      y.right = z;
  } 
  void preParse(BTreeNode u) {
    if( !u.equals(NIL) ) {
      buf.append(" ").append(u.key);
      preParse(u.left);
      preParse(u.right);
    }
  }
  void inParse(BTreeNode u) {
    if( !u.equals(NIL) ) {
      inParse(u.left);
      buf.append(" ").append(u.key);
      inParse(u.right);
    }
  }

  void dispRoundPath() {

    inParse(root);
    buf.append("\n");
    preParse(root);
    buf.append("\n");

    System.out.print(buf);
    buf.setLength(0);
  }
}

class BTreeNode {
  int key;
  BTreeNode parent,left,right;

  public BTreeNode(int key) {
    this.key = key;
    this.parent =
    this.left =
    this.right = Tree.NIL;
  }

  @Override
  public boolean equals(Object o) {
    if(o == this) return true;
    if(o == null) return false;
    if(!(o instanceof BTreeNode)) return false;

    BTreeNode node = (BTreeNode)o;
    if(!(this.key == node.key)) return false;

    return true;
  }
}


Measured memory_bytes: 125708
//解説みました。思わず笑った。
#include<stdio.h>
typedef long long int ll;

int main(void){
    int n;
    scanf("%d\n", &n);
    ll a[n];
    ll m = 0;
    for(int i = 0; i < n; i++){scanf("%lld", &a[i]); m+= a[i];}
    printf("%lld\n", m-n);
    return 0; 
}

Measured memory_bytes: 128
# Problem: https://atcoder.jp/contests/abc085/tasks/abc085_c
# Python 1st Try

import sys
# from collections import defaultdict
# import heapq,copy
# import pprint as pp
# from collections import deque
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(givenPieces, total_sum):
    #   result = 0
    # algorithm
    for x in range(0, givenPieces+1, +1):
        for y in range(0, givenPieces+1-x, +1):
            remained_money = total_sum - (x * 10000 + y * 5000)
#            remained_pieces = givenPieces - x - y
#            if remained_pieces < 0:
            z = givenPieces - (x + y)
            total = x * 10000 + y * 5000 + z * 1000
            if total_sum == total:
                return [x, y, (remained_money // 1000)]
    return [-1, -1, -1]


if __name__ == "__main__":
    N, Y = MI()
    result = solver(N, Y)
    print("{} {} {}".format(result[0], result[1], result[2]))


Measured memory_bytes: 9216
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<deque>
using namespace std;
typedef pair<int, int>P;
typedef pair<string, pair<int, int>>PP;
typedef long long ll;

int main() {
	string s; cin >> s;
	int count = 0;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == 'o') {
			count++;
		}
	}
	if (8 - count > 15 - s.length()) {
		cout << "NO" << endl;
	}
	else {
		cout << "YES" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
int a=1,b=2,c=3,n,x,z;
while(1){
	z=0;
scanf("%d %d",&n,&x);
if(n==0&&x==0)
break;
for(a=1;a<=n;a++){
for(b=2;b<=n;b++){
for(c=3;c<=n;c++){
if(a<b&&a<c&&b<c&&x==a+b+c)
z+=1;
}
}
}
printf("%d\n",z);
}
return 0;
}

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

int main() {
    int n;
    cin >> n;
    int a[n];
    for (int i=0; i<n; i++){
        cin >> a[i];
    }
    int sum_of_operate = 0;
    bool could_operate = true;
    while(could_operate) {
        for (int i = 0; i < n; i++) {
            if (a[i] % 2 == 0) {
                a[i] /= 2;
            } else {
                could_operate = false;
                break;
            }
        }
        if (could_operate){
            sum_of_operate++;
        } else{
            break;
        }
    }
    cout << sum_of_operate << endl;
}


Measured memory_bytes: 3600
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

class Main{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int n;
	int w;
	int[] h;

	void run(){
		for(;;){
			n=sc.nextInt();
			w=sc.nextInt();
			if((n|w)==0){
				break;
			}
			h=new int[20];
			int vMax=0;
			int hMax=0;
			for(int i=0; i<n; i++){
				int v=sc.nextInt();
				h[v/w]++;
				vMax=Math.max(vMax, v);
				hMax=Math.max(hMax, h[v/w]);
			}
			int m=vMax/w+1;
			double ans=0;
			for(int i=0; i<m; i++){
				double a=(double)(m-1-i)/(m-1);
				double b=(double)h[i]/hMax;
				ans+=a*b;
			}
			ans+=0.01;
			println(""+ans);
		}
	}

	void debug(Object... os){
	// System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 12000
s = input()
dic = {}
for i in s:
  if i not in dic:
    dic[i] = 1
  else:
    dic[i] += 1
    if dic[i] >= 3:
      print("No")
      exit()
  
if len(dic) >= 3 or len(dic) <= 1:
  print("No")
  exit()
for i in s:
  if dic[i] != 2:
    print("No")
    exit()
print("Yes")
  

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007

using namespace std;

void input() {
	int n;
	cin>>n;
	
	int a[n][2];
	
	for(int i=0;i<n;i++) {
		cin>>a[i][0]>>a[i][1];
	}
	
	int x=0;
	for(int i=0;i<n;i++) {
		if(a[i][0] == a[i][1]) {
			x+=1;
			if(x == 3) {
				cout<<"Yes";
				return;
			}
		}
		else {
			if(x == 3) {
				cout<<"Yes";
				return;
			}
			x=0;
		}
	}
	
	if(x == 3) {
		cout<<"Yes";
		return;
	}
	
	cout<<"No";
}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	input();

	return 0;
}



Measured memory_bytes: 3640
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>

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

int main()
{
	int N;
	cin >> N;
	int mx = 0, mi = 1000000;

	for (int i = 0; i < N; i++) {
		int a; cin >> a;
		if (a > mx) 
			mx = a;
		if (a < mi) 
			mi = a;		
	}
	cout << mx - mi << endl;
	return	0;
}

Measured memory_bytes: 256
d,n = map(int,input().split())
if d == 0:
    if n != 100:
        print(n)
    else:
        print(101)
elif d == 1:
    if n != 100:
        print(n*100)
    else:
        print(10100)
else:
    if n != 100:
        print(n*100**2)
    else:
        print(1010000)

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main()
{
    int n, ans = 0;
    cin >> n;
    int a[n], b[n], c[n];
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        --a[i];
    }
    for(int i = 0; i < n; i++)
    {
        cin >> b[i];
    }
    for(int i = 0; i < n - 1; i++)
    {
        cin >> c[i];
    }
    for(int i = 0; i < n; i++)
    {
            ans += b[a[i]];
        if(i > 0 && a[i] == a[i-1] + 1)
        {
            ans += c[a[i - 1]];
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
    int iPerW = 0;
    int iPerH = 0;
    bool bFlag = false;
    
    while (cin >> iPerH >> iPerW)
    {
        if ((0 == iPerH) && (0 == iPerW))
        {
            break;
        }
        
        for (int i = 0; i < iPerH; i++)
        {
            if (0 == i % 2)
            {
                bFlag = false;
            }
            else
            {
                bFlag = true;
            }
            
            for (int j = 0; j < iPerW; j++)
            {
                if (false == bFlag)
                {
                    if (0 == j % 2)
                    {
                        cout << "#";
                    }
                    else
                    {
                        cout << ".";
                    }
                }
                else
                {
                    if (0 == j % 2)
                    {
                        cout << ".";
                    }
                    else
                    {
                        cout << "#";
                    }
                }
            }
    
            cout << endl;
        }
        
        cout << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define lpin(a,i,n) for(int i=0;i<n;i++){cin>>a[i];}
int main(){
  int c,d,n;
  cin>>c>>d>>n;
  int a[1001],b[1001];
  lp(i,1001){
    a[i]=0;
    b[i]=0;
  }
  lp(i,n){
    int x,y;
    cin>>x>>y;
    b[x]=1;
    b[y]=2;
    a[x]+=1;
    a[y]-=1;
  }
  for(int i=1;i<=1000;i++){
    a[i]+=a[i-1];
  }
  int check=0;
  for(int i=c;i<=d;i++){
    if(i==c){
      if(a[i]!=0 && b[i]!=2){
	check=1;
	break;
      }
    }
    else if(i==d){
      if(a[i]!=0 && b[i]!=1){
	check=1;
	break;
      }
    }
    else if(a[i]!=0){
      check=1;
      break;
    }
  }
  cout<<check<<endl;
    
  return 0;
  
}


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int ball[11];

bool bfs(int b, int c, int sum){
    if(sum == 10){
        return true;
    }
    if(b < ball[sum]){
        return bfs(ball[sum], c, sum+1);
    }
    if(c < ball[sum]){
        return bfs(b, ball[sum], sum + 1);
    }
    if(c > ball[sum] && b > ball[sum]){
        return false;
    }
}
int main(void){
    int n;
    cin >> n;
    for(int i=0; i<n ;i++){
        for(int j=0;j<10;j++){
            cin >> ball[j];
        }
        if(bfs(0, 0, 0)){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3040
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
#include <iomanip>
#include <limits>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
typedef priority_queue<ll> PQ_HIGH;
typedef priority_queue<ll,VL,greater<ll>> PQ_LOW;//昇順

int main(){
  int N,M;cin>>N>>M;
  VL H(N,0);
  VI a(M,0),b(M,0);
  REP(i,N){cin>>H[i];}
  REP(i,M){cin>>a[i]>>b[i];a[i]--,b[i]--;}
  VI ans(N,0);
  for(int i=0;i<M;i++){
    if(H[a[i]]>=H[b[i]]){
      ans[b[i]]=1;
    }
    if(H[a[i]]<=H[b[i]]){
      ans[a[i]]=1;
    }
  }
  int count=0;
  REP(i,N){
    if(ans[i]==0){
      count++;
    }
  }
  cout<<count<<endl;
}


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



  
int main(){
  
  
  int n;
  cin>>n;
  
  vector<int> data(n+1);
  
  data.at(0)=0;
  data.at(1)=0;
  
  for (int i=2;i<n+1;i++){
    int tmp;
    cin>>tmp;
    data.at(i)=tmp;
  }
  
  
  vector<int> answer(n+1,0);
  
  for (int i=2;i<n+1;i++){
    answer.at(data.at(i))++;
  }
  
  for (int i=1;i<n+1;i++){
    cout<<answer.at(i)<<endl;
  }
  
  
    
        
}

    











Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

i64 N;
vector<int> V;
vector<int> W;
i64 Q;

int main() {
  cin >> N;
  V.resize(N + 1);
  W.resize(N + 1);
  rep(i,0,N) {
    cin >> V[i + 1] >> W[i + 1];
  }
  vector<int> dist(N + 1, -1);
  i64 L = 1e5 + 1;
  vector<vector<int>> dp(1, vector<int>(L, 0));
  dist[0] = 0;
  for(int i = 1; dist[i >> 1] + 1 < 10 && i < N; i++) {
    dist[i] = dist[i >> 1] + 1;
    vector<int> next = dp[i >> 1];
    rep(k,W[i],L) {
      next[k] = std::max(next[k], dp[i >> 1][k - W[i]] + V[i]);
      next[k] = std::max(next[k], next[k - 1]);
    }
    dp.emplace_back(std::move(next));
  }
  
  cin >> Q;
  rep(i,0,Q) {
    i64 v, L;
    cin >> v >> L;
    vector<int> vs;
    while(dist[v] == -1) {
      vs.push_back(v);
      v >>= 1;
    }
    int ans = dp[v][L];
    for(int s = 0;s < (1 << vs.size()); s++) {
      int val = 0;
      int wei = 0;
      rep(j,0,vs.size()) {
        if(s & (1 << j)) {
          val += V[vs[j]];
          wei += W[vs[j]];
        }
      }
      if(L - wei >= 0) {
        ans = std::max(ans, val + dp[v][L - wei]);
      }
    }
    cout << ans << "\n";
  }
}



Measured memory_bytes: 206404
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] stick = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[m];
		for (int i = 0; i < m; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		int[] dp = new int[n + 1];
		for (int i = 1; i < n + 1; i++) {
			dp[i] = -10000000;
		}
		for (int i = 1; i <= n; i++) {
			for (int j = 0; j < m; j++) {
				if (i - stick[a[j]] >= 0) {
					dp[i] = Math.max(dp[i], dp[i - stick[a[j]]] + 1);
				}
			}
		}
		StringBuilder sb = new StringBuilder();
		int index = n;
		while (index > 0) {
			for (int i = m - 1; i >= 0; i--) {
				if (index - stick[a[i]] >= 0 && dp[index - stick[a[i]]] == dp[index] - 1) {
					sb.append(a[i]);
					index -= stick[a[i]];
					break;
				}
			}
		}
		System.out.println(sb);
	}
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int a[100010];
int b[100010];

const ll mod=1000000007LL;

int main(void){
	int n;
	cin >> n;
	rep(i,n){
		cin >> a[i];
		int l=i,r=n-1-i;
		b[i]=abs(r-l);
	}

	sort(a,a+n);
	sort(b,b+n);

	bool zero=false;
	rep(i,n) if(a[i]!=b[i]) zero=true;

	if(zero){
		puts("0");
		return 0;
	}

	ll num=n/2;
	ll ans=1LL;
	rep(loop,num) ans=2LL*ans%mod;
	cout << ans << endl;

	return 0;
}

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

#include <atcoder/all>

using namespace std;
using namespace atcoder;
using ll = long long;

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

    for (int i = 0; i < T; i++) {
        int N, M, A, B;
        cin >> N >> M >> A >> B;
        cout << floor_sum(N, M, A, B) << endl;
    }

    return 0;
}


Measured memory_bytes: 3652
n = int(input())
num = [[0 for j in range(10)] for i in range(10)]
for i in range(1, n+1):
    X = str(i)
    num[int(X[0])][int(X[-1])] += 1

ans = 0
print(sum(num[i][j]*num[j][i] for i in range(10) for j in range(10)))


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

#define ll long long
#define T int t, q=0; cin>>t; while(q++<t)

int main()
{
    int n, x, y;
    cin>>n>>x>>y;
    int ans[n+1]={};
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            int z=min(j-i, min(abs(x-i)+1+abs(j-y), abs(y-i)+1+abs(x-j)));
//            cout<<z<<" ";
            ans[min(j-i, abs(x-i)+1+abs(j-y))]++;

        }
    }
    for(int i=1;i<n;i++)
        cout<<ans[i]<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) ((int)(x).size())
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N,C,K; cin>>N>>C>>K;
    vint t(N);
    REP(i,N) cin>>t[i];
    sort(ALL(t));

    int ans=0;
    for(int i=0;i<N;){
        int j=i;
        while(j<N and j-i+1<=C and t[j]<=t[i]+K) j++;
        ans++; i=j;
    }
    cout<<ans<<endl;
}


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

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

  cout << ((max({a,b,c})==7 && min({a,b,c})==5 && a+b+c==17) ? "YES" : "NO") << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void) {
	int n,x,i,j,tmp,count;
	int a[101];
	scanf("%d %d",&n,&x);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(i=0;i<n;i++){
		for(j=0;j<i;j++){
			if(a[i]<a[j]){
				tmp=a[j];
				a[j]=a[i];
				a[i]=tmp;
			}
		}
	}
	a[n]=999999;
	count=0;
	while(1){
		if(x>=a[count]){
			x=x-a[count];
			count++;
		}else{
			break;
		}
	}
	if((x!=0)&&(count>0)&&(a[count]==999999)){
		count=count-1;
	}
	printf("%d",count);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		doIt();

	}
	
	public static void doIt(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i = 0; i < n; i++){
			int[] num = new int[10];
			for(int j = 0; j < 10; j++){
				num[j] = sc.nextInt();
			}
			int left = 0;
			int right = 0;
			boolean bOK = true;
			for(int j = 0; j < 10; j++){
				if(right > left){
					if(num[j] > right){
						right = num[j];
					}
					else if(num[j] > left){
						left = num[j];
					}
					else{
						bOK = false;
						break;
					}
				}
				else{
					if(num[j] > left){
						left = num[j];
					}
					else if(num[j] > right){
						right = num[j];
					}
					else{
						bOK = false;
						break;
					}
				}
			}
			if(bOK){
				System.out.println("YES");
			}
			else{
				System.out.println("NO");
			}
		}
	}
}

Measured memory_bytes: 11000
/*
 * Problem Description: Matrix Chain Multiplication
 * Category: Dynamic Programming
 * Author: Khan
 * Date: 20th October, 2017
 */

#include <iostream>
#include <algorithm>

using namespace std;

#define N 100

int main(int argc, char const *argv[])
{
    //freopen("sample.txt", "r", stdin);
    int n, p[N + 1], m[N + 1][N + 1];
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> p[i - 1] >> p[i];
    for (int i = 1; i <= n; ++i)
        m[i][i] = 0;
    for (int l = 2; l <= n; ++l)
    {
        for (int i = 1; i <= n - l + 1; ++i)
        {
            int j = i + l - 1;
            m[i][j] = (1 << 21);
            for (int k = i; k <= j - 1; ++k)
                m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
        }
    }
    cout << m[1][n] << endl;
    return 0;
}

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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define fst first
#define snd second
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18;
const int INF = 1e9;
const double EPS = 0.000000001;
struct edge {ll to, cost; };
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

bool pC(const P& pair1, const P& pair2) {
    return pair1.second > pair2.second;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<vector<edge> > E(n, vector<edge>());
  VL d(n, LINF);
  VI a(n), b(n), c(n);
  REP(i, n-1){
    cin >> a[i] >> b[i] >> c[i];
    a[i]--; b[i]--;
    edge e1 = {b[i], c[i]};
    edge e2 = {a[i], c[i]};
    E[a[i]].push_back(e1);
    E[b[i]].push_back(e2);
  }
  int q, k;
  cin >> q >> k;
  k--;
  VI x(q), y(q);
  REP(i, q){
    cin >> x[i] >> y[i];
    x[i]--; y[i]--;
  }

  priority_queue<PL, vector<PL>, greater<PL> > que;
  d[k] = 0;
  que.push(P(0, k));
  while(!que.empty()){
    P p = que.top();
    que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    for (int i = 0; i < E[v].size() ; i++) {
      edge e = E[v][i];
      if(d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }

  REP(i, q){
    out(d[x[i]] + d[y[i]]);
  }

  return 0;
}


Measured memory_bytes: 14576
#include<cstdio>
using namespace std;
int main(){
	bool bj=0;
	int n,x,y,sum=0;
	scanf("%d",&n);
	for (int i=1;i<=n;++i){
		scanf("%d%d",&x,&y);
		if (x==y) ++sum;
		else sum=0;
		if (sum==3) bj=1;
	}
	if (bj) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 1624
#include<bits/stdc++.h>
using namespace std;
struct node{
	int r=0,g=0,b=0;
};
int main(){
	long long n;
	cin>>n;
	string s;
	cin>>s;
	int a,b,c;
	int y=0;
	long long ans = 0;
	node N[50000]={};
	if(s[n-1]=='R'){
		N[n-1].r++;
	}else if(s[n-1] == 'G'){
		N[n-1].g++;
	}else if(s[n-1] == 'B'){
		N[n-1].b++;
	}
	for(int i=n-2;i>=0;i--){
		if(s[i]=='R'){
			N[i] = N[i+1];
			N[i].r++;
		}else if(s[i] == 'B'){
			N[i] = N[i+1];
			N[i].b++;
		}else if(s[i] == 'G'){
			N[i] = N[i+1];
			N[i].g++;
		}
	}

	for(int i=0;i<n-2;i++){
		for(int j=i+1;j<n-1;j++){
				if(s[i] == 'R' && s[j] == 'G'){
					ans+=N[j+1].b;
					if(s[j-i+j] == 'B')ans--;
 				}else if(s[i] == 'R' && s[j] == 'B'){
					ans+=N[j+1].g;
					if(s[j-i+j] == 'G')ans--;
				}else if(s[i] == 'G' && s[j] == 'R'){
					ans+=N[j+1].b;
					if(s[j-i+j] == 'B')ans--;
				}else if(s[i] == 'G' && s[j] == 'B'){
					ans+=N[j+1].r;
					if(s[j-i+j] == 'R')ans--;
				}else if(s[i] == 'B' && s[j] == 'G'){
					ans+=N[j+1].r;
					if(s[j-i+j] == 'R' )ans--;
				}else if(s[i] == 'B' && s[j] == 'R'){
					ans+=N[j+1].g;
					if(s[j-i+j] == 'G')ans--;
				}
		}
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 4224
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>

using namespace std;

int solve(string s1,string s2){
  if((s1[0] == '0' && s1.size() > 1 )||
     (s2[0] == '0' && s2.size() > 1 ) )return 0;
  int a = atoi(s1.c_str());
  int b = atoi(s2.c_str());
  if((a + b)%2 == 1)return 0;
  if((b - a)%2 == 1)return 0;
  if(b - a < 0)return 0;
  return 1;
}

int main(){
  string s;
  cin >> s;
  int res = 0;
  for(int i = 0 ; i < (int)s.size() ; i++ ){
    res += solve(s.substr(0,i),s.substr(i,s.size() - i));
  }
  cout << res << endl;
}

Measured memory_bytes: 1204
import java.io.IOException;
import java.io.InputStream;

public class Main {
    public static void main(String[] args)throws Exception {
        StringBuilder sb=new StringBuilder();
        FastReader in=new FastReader(System.in);
        int i,j;
        int h1=in.nextInt();
        int s1=in.nextInt();
        int h2=in.nextInt();
        int s2=in.nextInt();
        while(h1>0 && h2>0){
            h2=h2-s1;
            if(h2<=0)
                break;
            h1=h1-s2;
        }
        if(h1>0)
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}

class FastReader {

    byte[] buf = new byte[2048];
    int index, total;
    InputStream in;

    FastReader(InputStream is) {
        in = is;
    }

    int scan() throws IOException {
        if (index >= total) {
            index = 0;
            total = in.read(buf);
            if (total <= 0) {
                return -1;
            }
        }
        return buf[index++];
    }

    String next() throws IOException {
        int c;
        for (c = scan(); c <= 32; c = scan()) ;
        StringBuilder sb = new StringBuilder();
        for (; c > 32; c = scan()) {
            sb.append((char) c);
        }
        return sb.toString();
    }

    int nextInt() throws IOException {
        int c, val = 0;
        for (c = scan(); c <= 32; c = scan()) ;
        boolean neg = c == '-';
        if (c == '-' || c == '+') {
            c = scan();
        }
        for (; c >= '0' && c <= '9'; c = scan()) {
            val = (val << 3) + (val << 1) + (c & 15);
        }
        return neg ? -val : val;
    }

    long nextLong() throws IOException {
        int c;
        long val = 0;
        for (c = scan(); c <= 32; c = scan()) ;
        boolean neg = c == '-';
        if (c == '-' || c == '+') {
            c = scan();
        }
        for (; c >= '0' && c <= '9'; c = scan()) {
            val = (val << 3) + (val << 1) + (c & 15);
        }
        return neg ? -val : val;
    }
}





Measured memory_bytes: 32392
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iomanip>
using namespace std;
struct info
{
    int l,r,d;
}s[400005];
int n,m;
int flag = 1;
int dis[100005],visited[100005];
int first[400005],nexti[400005];
void dfs(int t)
{
    if(!flag)return;
    int k = first[t];
    while(k != -1)
    {
        if(!flag)return;
        if(!visited[s[k].r])
        {
            dis[s[k].r] = dis[s[k].l] + s[k].d;
            visited[s[k].r] = 1;
            dfs(s[k].r);
        }
        else if(s[k].d != (dis[s[k].r] - dis[s[k].l]))
        {
            flag = 0;
            return;
        }
        k = nexti[k];
    }
}
int main()
{
    scanf("%d%d",&n,&m);
    memset(first,-1,sizeof(first));
    for(int i = 0;i < m;i ++)
    {
        scanf("%d%d%d",&s[i].l,&s[i].r,&s[i].d);
        nexti[i] = first[s[i].l];
        first[s[i].l] = i;
        s[i + m].r = s[i].l;
        s[i + m].l = s[i].r;
        s[i + m].d = -s[i].d;
        nexti[i + m] = first[s[i + m].l];
        first[s[i + m].l] = i + m;
    }
    for(int i = 1;i <= n;i ++)
    {
        if(!visited[i])
        {
            visited[i] = 1;
            dfs(i);
        }
    }
    if(flag)printf("Yes");
    else printf("No");
}

Measured memory_bytes: 9728
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int H,W;
        while(true){
           H=sc.nextInt();
           W=sc.nextInt();
           if(H==0 && W==0){
               break;
           }else{
            for(int i=0;i<H;i++){
             for(int j=0;j<W;j++){
                System.out.print("#");
             }
             System.out.println("");
            }
            System.out.println("");
           }
            
        }
        
    }
}


Measured memory_bytes: 33620
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

void solve(){
    int n;cin>>n;
    set<string> st;
    for(int i=0;i<n;i++){
        string s;cin>>s;
        st.insert(s);
    }
    cout<<st.size()<<"\n";
}

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

    solve();
    return 0;
}

Measured memory_bytes: 19284
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(g);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()


typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;

#ifdef TESTING
#define DEBUG fprintf(stderr,"====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define DEBUG 
#define VALUE(x)
#define debug(...)
#endif
/*
inline string IntToString(ll a) {
	char x[100];
	sprintf_s(x, "%lld", a); string s = x;
	return s;
}

inline ll StringToInt(string a) {
	char x[100]; ll res;
	strcpy_s(x, a.c_str()); sscanf_s(x, "%lld", &res);
	return res;
}
*/

inline string uppercase(string s) {
	int n = SIZE(s);
	rep(i, n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
	return s;
}

inline string lowercase(string s) {
	int n = SIZE(s);
	rep(i, n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
	return s;
}


int main()
{
	string s;
	int ans = 0;
	cin >> s;
	rep(i, s.size() - 1) {
		if (s[i] != s[i + 1]) ans++;
	}
	cout << ans << endl;
	return 0;
}


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

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
#define sbp(p, n) rep(i, n) { int a, b; scanf("%d %d", &a, &b); p[i] = make_pair(a, b); }
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
	int l, ans[2] = {};
	string s;
	cin >> s;
	l = s.size();
	rep(i, l){
		if(s[i] == (char)(i % 2 + '0')) ans[0]++;
		else ans[1]++;
	}
	cout << min(ans[0], ans[1]) << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#define ll long long
using namespace std;


int A[1111];
int main() {
    int N;
    cin>>N;
    for(int i=0;i<N;i++)
        cin>>A[i];
    
    
    vector<pair<int,int> > colors;
    colors.push_back(make_pair(1,399));
    colors.push_back(make_pair(400,799));
    colors.push_back(make_pair(800,1199));
    colors.push_back(make_pair(1200,1599));
    colors.push_back(make_pair(1600,1999));
    colors.push_back(make_pair(2000,2399));
    colors.push_back(make_pair(2400,2799));
    colors.push_back(make_pair(2800,3199));
    
    set<int> dist_colors;
    int num_free = 0;
    for(int i=0;i<N;i++) {
        bool found=false;
        for(int j=0;j<colors.size();j++) {
            if (A[i]>=colors[j].first && A[i]<=colors[j].second) {
                dist_colors.insert(j);
                found=true;
                break;
            }
        }
        if (!found)
            num_free++;
    }
    
    printf("%lu %lu\n",max(1ul,dist_colors.size()), dist_colors.size()+num_free);

}

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

int main()
{
    string s;
    cin>>s;
    bool ans=1;
    int n=s.size();
    for(int i=0;i<n;i++)
        if(s[i]!=s[n-1-i]) ans=0;
    for(int i=0;i<n/2-1;i++)
        if(s[i]!=s[n/2-1-i]) ans=0;
    for(int i=n/2+1;i<n;i++)
        if(s[i]!=s[n/2+n-i]) ans=0;
    if(ans) cout<<"Yes\n";
    else cout<<"No\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mst(a,b) memset(a,b,sizeof(a))
#define lowbit(x) (x&(-x))
#define lson        (rt<<1)
#define rson        (rt<<1|1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const int mod = 1e9+7;
template<class T>
inline bool scan(T&res){
    char c;int sgn;
    if(c=getchar(),c==EOF)return false;
    while(c!='-' and (c<'0' or c>'9'))c=getchar();
    sgn=(c=='-')?-1:1;
    res=(c=='-')?0:(c-'0');
    while(c=getchar(),c>='0' and c<='9')res=res*10+(c-'0');
    res*=sgn;
    return true;
}
template<class T>
inline void out(T x){
    if(x>9)out(x/10);
    putchar(x%10+'0');
}

const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int maxn = 1e5+50;
int res[500][500];
int solve(int n,int m){
    if(res[n][m]!=-1)return res[n][m];
    res[n][m]=0;
    for(int i=2;i<=n and !res[n][m];i+=2){
        if(!solve(n-i,m+i/2))
            res[n][m]=1;
    }
    for(int i=2;i<=m and !res[n][m];i+=2){
        if(!solve(n+i/2,m-i))
            res[n][m]=1;
    }
    return res[n][m];
}
int main() {
#ifdef local
    freopen("in.txt","r",stdin);
//
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll x,y;
    while(cin>>x>>y){
        if(abs(x-y)<=1)cout<<"Brown\n";
        else cout<<"Alice\n";
    }
    return 0;
}


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

int main(void){
    string cards;
    int m, h;
    int i;
    string unders, tops;
    
    while(true){
    cin >> cards;
    if(cards == "-") break;
    cin >> m;
    for(i = 0; i < m; i++){
        cin >> h;
 //       cout << cards << " ";
        unders = cards.substr(0, h);
        tops = cards.substr(h, cards.length() - h);
        cards = tops + unders;
//        cout << cards << endl;
    }
    cout << cards << endl;
    }
    return 0;
}

Measured memory_bytes: 3176
def solve():
    can_positive = False
    if len(P) > 0:
        if k < n: can_positive = True
        else: can_positive = len(M)%2 == 0
    else: can_positive = k%2 == 0

    if not can_positive: return sorted(P+M, key=lambda x:abs(x))[:k]

    P.sort()
    M.sort(reverse = True)
    p, m = [], []
    while len(p) + len(m) < k:
        if len(P) > 0 and len(M) <= 0: p.append(P.pop())
        elif len(P) <= 0 and len(M) > 0: m.append(M.pop())
        elif P[-1] < -M[-1]: m.append(M.pop())
        else: p.append(P.pop())
    if len(m)%2:
        Mi = M.pop() if len(p)*len(M) else 1  #  1 is no data
        Pi = P.pop() if len(m)*len(P) else -1 # -1 is no data
        if Mi < 0 and Pi >= 0:
            if abs(p[-1] * Pi) < abs(m[-1] * Mi):
                p.pop()
                m.append(Mi)
            else:
                m.pop()
                p.append(Pi)
        elif Mi < 0:
            p.pop()
            m.append(Mi)
        elif Pi >= 0:
            m.pop()
            p.append(Pi)
    return p + m

n, k = map(int, input().split())
P, M = [], [] # plus, minus
for a in map(int, input().split()):
    if a < 0: M.append(a)
    else: P.append(a)
ans, MOD = 1, 10**9 + 7
for a in solve(): ans *= a; ans %= MOD
ans += MOD; ans %= MOD
print(ans)


Measured memory_bytes: 32548
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;

int main(int argc, char *argv[]) {

	//int D = 365;
	int D; cin >> D;

	vector<int> c(26,0);
	vector<vector<int>> s(D,vector<int>(26,0));
	vector<int> t(D,0);

	for (int i = 0; i < 26; i++) {
		cin >> c[i];
	}

	for (int i = 0; i < D; i++) {
		for (int j = 0; j < 26; j++) {
			cin >> s[i][j];	
		}
	}

	//for (int i = 0; i < D; i++) {
	//	cin >> t[i];
	//}

	//int M; cin >> M;
	//int cnt = 1;
	//for (int k = 0; k < M; k++) {
	//	cin >> d[k] >> q[k];
	//	vector<int> last(26,0);
	//	int d,q; cin >> d >> q;
	//	t[d-1] = q;
	//	int ans = 0;
	//	for (int i = 0; i < D; i++) {
	//		ans += s[i][t[i]-1];	
	//		last[t[i]-1] = i+1;
	//		for (int j = 0; j < 26; j++) {
	//			ans -=	c[j] * ((i+1) - last[j]) ;
	//		}
	//	}
	//	cout << ans << endl;
	//}

	vector<int> MAX(D,0);
	vector<int> last(26,0);
	for (int i = 0; i < D; i++) {
		int ans =0;
		int idx = 0;

		for (int j = 0; j < 26; j++) {
			if (MAX[i] < s[i][j]) {
				MAX[i] = s[i][j];	
				idx = j;	
			}
		}
		cout << (rand() % 26) + 1 << endl;
	}

	return 0;
}


Measured memory_bytes: 3676
#include<stdio.h>

int main(){
  int a, b; scanf("%d %d", &a, &b);
  int total = 0;
  if(a < b) total += 2 * b - 1;
  if(a > b) total += 2 * a - 1;
  if(a == b) total += a + b;
  printf("%d\n", total);

  return 0;
}


Measured memory_bytes: 128
n, a, b = map(int, input().split())
s = input()
ca, cb = 0, 0
for i in s:
    if i == 'c':
        print('No')
    elif i == 'a' and (ca+cb) < (a+b):
        ca += 1
        print('Yes')
    elif (i == 'b' and (ca+cb) < (a+b) and cb < b):
        cb += 1
        print('Yes')
    else:
        print('No')

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	auto no=[](){cout<<"No\n";exit(0);};
	auto yes=[](){cout<<"Yes\n";exit(0);};
	int n; cin>>n;
	vector<pair<int,int>> a(n),b(n);
	for(int i=0;i<n;i++) cin>>a[i].first;
	for(int i=0;i<n;i++) cin>>b[i].first;
	for(int i=0;i<n;i++) a[i].second=b[i].second=i;
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	for(int i=0;i<n;i++)
		if(a[i].first>b[i].first) no();
	for(int i=1;i<n;i++)
		if(a[i].first<=b[i-1].first) yes();
	vector<int>to(n);
	for(int i=0;i<n;i++)
		to[a[i].second]=b[i].second;
	vector<bool> vis(n,false);
	function<int(int)> dfs=[&](int x){
		if(vis[x])return 0;
		vis[x]=true;
		return 1+dfs(to[x]);
	};
	if(dfs(0)==n) no();
	else yes();
	return 0;
} 

Measured memory_bytes: 5376
import sys

import numba as nb
import numpy as np

input = sys.stdin.readline
INF = float("inf")


@nb.njit("i8(i8,i8,i8[:])")
def solve(N, K, h):
    dp = np.zeros(N, dtype=np.int64)
    for i in range(1, N):
        k = min(K, i)
        dp[i] = np.min(dp[i - k:i] + np.abs(h[i] - h[i - k:i]))
    return dp[-1]


def main():
    N, K = map(int, input().split())
    h = np.array(input().split(), dtype=np.int64)

    ans = solve(N, K, h)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 127836
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;
int main()
{
	boost;
	int n, i;
	cin >> n;
	int h[n];
	fo(i, 0, n)
	cin >> h[i];
	
	map <int, int> mp;
	ll ans = 0;
	fo(i, 0, n) {
		ans += mp[i - h[i]];
		mp[i + h[i]]++;
	}
	cout << ans;
}


Measured memory_bytes: 21388
#include<bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y);
int main(){
    long long a,b;
    cin>>a>>b;
    long long v=gcd(a,b);
    long long ans=1;
    for(long long i=2;i<=sqrt(v);i++){
        bool flag=false;
        while(v%i==0){
            v/=i;
            flag=true;
        }
        if(flag)ans++;
    }
    if(v!=1)ans++;
    cout<<ans<<endl;
    return 0;
}
long long gcd(long long x, long long y){
    if(y==0)return x;
    else return gcd(y,x%y);
}

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

int N;
bool endow[1000];
int tm[1000], tt[1000];

pair<int, int> separete(string s)
{
    stringstream ss(s);
    int a,b;
    char c;

    ss >> a >> c >> b;

    return make_pair(a,b);
}

int transMin(string s)
{
    pair<int, int> ms = separete(s);
    int m = ms.first;
    int d = ms.second;

    return m*60+d;
}

int solve()
{
    memset(endow, 0, sizeof(endow));
    memset(tt, 0, sizeof(tt));
    
    while(N--){
	string a,b,c;
	int mn, id;

	cin >> a >> b >> c >> id;
	mn = transMin(b);

	if(c == "I") {
	    endow[id] = true;
	    tm[id] = mn;
	}

	if(c == "O") {
	    endow[id] = false;
	    if(id != 0) {
		if(endow[0]) tt[id] += mn - max(tm[id], tm[0]);
	    }
	    else {
		for(int i=1; i<1000; i++)
		    if(endow[i]) tt[i] += mn - max(tm[i], tm[0]);
	    }
	}
    }

    int res = 0;
    for(int i=1; i<1000; i++)
	res = max(res, tt[i]);

    return res;
}

    
    

int main()
{
    while(cin >> N, N)
	cout << solve() << endl;
    
}

Measured memory_bytes: 0
#include<stdio.h>
int main()
{
    int i, max=0,n,m,j,x,k,flag;
    char s[101][11], t[101][11],a[11];
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        for (j = 0; j < 10; j++)
            a[j] = '\0';
        scanf("%s", a);
        for (j = 0; j < 10; j++)
            s[i][j] = a[j];
    }
    scanf("%d", &m);
    for (i = 0; i < m; i++) {
        for (j = 0; j < 10; j++)
            a[j] = '\0';
        scanf("%s", a);
        for (j = 0; j < 10; j++)
            t[i][j] = a[j];
    }
    for (i = 0; i < n; i++)
    {
        x = 0;
        for (j = 0; j < n; j++)
        {
            flag = 1;
            for (k = 0; k < 10; k++) {
                if (s[i][k] != s[j][k])
                    flag = 0;
            }
            if(flag==1)
                x++;
        }
        for (j = 0; j < m; j++)
        {
            flag = 1;
            for (k = 0; k < 10; k++) {
                if (s[i][k] != t[j][k])
                    flag = 0;
            }
            if (flag == 1)
                x--;
        }
        if (x > max)
            max = x;
    }
    printf("%d", max);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl '\n'
#define rep(i,n) for(int i=0;i<n;i++) 
#define all(v) v.begin(),v.end()
#define F first
#define S second

void solve()
{
	long double n,x,t;
	cin>>n>>x>>t;
	ll val=ceil(n/x);
	ll res=t*val;
	cout<<res<<endl;
}
int main()
{
//	ios_base::sync_with_stdio(false); 
  //  cin.tie(NULL);  
	int t;
	t=1;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 3720
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        v: [i64; n]
    }
    let mut w = v;
    w.sort();
    let ans1 = solve(&w);
    w.reverse();
    let ans2 = solve(&w);
    println!("{}", std::cmp::max(ans1,ans2));
}

fn solve(v: &Vec<i64>) -> i64 {
    let n = v.len();
    let mut ret = 0;
    let mut i = 1;
    let mut j = n-1;
    let mut l = v[0];
    let mut r = v[0];
    while i <= j {
        ret += (v[j] - r).abs();
        r = v[j];
        j -= 1;
        if i > j {
            break;
        }

        ret += (v[j] - l).abs();
        l = v[j];
        j -= 1;
        if i > j {
            break;
        }

        ret += (v[i] - r).abs();
        r = v[i];
        i += 1;
        if i > j {
            break;
        }

        ret += (v[i] - l).abs();
        l = v[i];
        i += 1;
    }
    ret
}


Measured memory_bytes: 4352
fun main(args: Array<String>) {
    abc095c()
}

fun abc095c() {
    val (aPrice, bPrice, mixPrice, aNeeded, bNeeded) = readLine()!!.split(" ").map { it.toInt() }

    val noMix = aPrice * aNeeded + bPrice * bNeeded

    val neededDiff = Math.abs(aNeeded - bNeeded)
    val withMix = (if (aNeeded == bNeeded) 0 else if (aNeeded > bNeeded) aPrice * neededDiff else bPrice * neededDiff) +
            Math.min(aNeeded, bNeeded) * 2 * mixPrice

    val onlyMix = Math.max(aNeeded, bNeeded) * 2 * mixPrice

    println(Math.min(Math.min(noMix, withMix), onlyMix))
}


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


signed main(){

    // omajinai
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    // omajinai

    int a,b,c;
    cin >> a >> b >> c;
    if(a+b+c > 21) cout << "bust" << endl;
    else cout << "win" << endl;
}



Measured memory_bytes: 256