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

int main(void) {
  int N, K, Q;
  cin >> N >> K >> Q;
  vector<int> A(N);
  
  int a;
  for(int i=0;i<Q;i++) {
    cin >> a;
    A.at(a-1)+=1;
  }

  for(int i=0;i<N;i++) {
    if(K-Q+A.at(i)>0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }

  return (0);
}


Measured memory_bytes: 1024
function Main(input) {
  input = input.split("\n");
  var n = parseInt(input[0].split(" ")[0]);
  var ans =0;
  for(i=1;i<=n;i++){
    ans+=i;
  }

  console.log('%s', ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

// Function to find the minimum number
// character change required

void change(string s)
{

    // Finding the length of the string
    int n = s.length();

    // To store the number of replacement operations
    int cc = 0;

    for(int i=0;i<n/2;i++)
    {

        // If the characters at location
        // i and n-i-1 are same then
        // no change is required
        if(s[i]== s[n-i-1])
            continue;

        // Counting one change operation
        cc+= 1;

        // Changing the character with higher
        // ascii value with lower ascii value
        if(s[i]<s[n-i-1])
            s[n-i-1]= s[i] ;
        else
            s[i]= s[n-i-1] ;
    }
    printf("%d\n", (cc)) ;
   
}
// Driver code
int main()
{
string s ;
cin>>s;
change((s));
return 0;
}


Measured memory_bytes: 256
k, n = map(int, input().split())
a = [int(x) for x in input().split()]
distance = [0]*n
for i in range(n-1):
    distance[i] = a[i+1]-a[i]
distance[n-1] = (a[0]+k-a[n-1])
print(k-max(distance))

Measured memory_bytes: 26420
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> ii;
#define F first
#define S second
#define sqr(x) (x)*(x)
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,x,y) for(int i=x;i<(y);++i)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

signed main(){
   IOS;
   int n,m; cin >> n >> m;
   vector<vector<int> > g(n+1);
   vector<int> h(n+1);
   rep(i,0,n) cin >> h[i+1];
   rep(i,0,m){
      int a,b;
      cin >> a >> b;
      g[a].pb(b);
      g[b].pb(a);
   }
   int ans = 0;
   rep(i,0,n){
      int ok = 1;
      for(auto u : g[i+1]){
         if(h[i+1]<=h[u]){
            ok = 0;
            break;
         }
      }
      if(ok) ans++;
   }
   cout << ans << '\n';
}

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

class Program
{
    static void Main()
    {
        Console.WriteLine(Solve());
        return;

    }

    public static string Solve()
    {
        int[] inputs = ReadInts();
        int H = inputs[0];
        int W = inputs[1];
        inputs = ReadInts();
        int h = inputs[0];
        int w = inputs[1];
        return ((H-h)*(W-w)).ToString();
    }

    private static string Read() { return Console.ReadLine(); }
    private static int ReadInt() { return int.Parse(Read()); }
    private static long ReadLong() { return long.Parse(Read()); }
    private static double ReadDouble() { return double.Parse(Read()); }
    private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
    private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
    private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
}


Measured memory_bytes: 11220
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		Arrays.setAll(A, i -> sc.nextInt());
		Arrays.sort(A);
		boolean[] t = new boolean[1000001];
		for(int i = 1; i < N; i++)
			if(A[i] == A[i-1])
				if(!t[A[i]])
					for(int j = A[i]; j < 1000001; j+=A[i])
						t[j] = true;
		int ans = 0;
		for(int i = 0; i < N; i++) {
			if(!t[A[i]]) {
				ans++;
				for(int j = A[i]; j < 1000001; j+=A[i])
						t[j] = true;
			}
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 60708
import sys
import itertools
tokens = itertools.chain.from_iterable(map(str.split, sys.stdin))

s = next(tokens)
t = next(tokens)

mn = 999999
for i in range(len(s) - len(t) + 1):
    ss = s[i:i+len(t)]
    sm = sum(1 if a != b else 0 for a, b in zip(ss, t))
    #print(ss, t, sm)
    mn = min(mn, sm)
print(mn)


Measured memory_bytes: 9096
N, M, K = map(int, input().split())
mod = 998244353

inv = [0,1]
for i in range(2, N):
  inv.append((-inv[mod%i]*(mod//i))%mod)

if N == 1:
  print(M)
  exit()

m = [1]
s = 1
for _ in range(N-1):
  s = s*(M-1)%mod
  m.append(s)

ncombi = [1]
c = 1
for k in range(K):
  c = c*(N-1-k)*inv[k+1]
  c %= mod
  ncombi.append(c)

ans = 0
for k in range(K+1):
  ans = ans + m[-k -1]*ncombi[k]
  ans %= mod

ans = ans*M%mod
print(ans)

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

int main() {
	ll X, K, D, num, len, count=0, ans = 0;

	cin >> X >> K >> D;
	
	if (abs(X) - D <= 0){
		if (K % 2 == 0){
			ans = abs(X);
		}
		else{
			ans = abs(abs(X) - D);
		}
	}
	else{
		num = abs(X) / D;
		len = abs(X) - D*num;
		if (num >= K){
			ans = abs(X) - D*K;
		}
		else{
			if ((K - num) % 2 == 0){
				ans = len;
			}
			else{
				ans = abs(len - D);
			}
		}
	}

	cout << ans << endl;

	return 0;
}

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

const long long MOD = (long long)1e9 + 7;

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

    int dat[3]; for (int i=0; i<3; i++) dat[i] = 0;
    long long res = 1;
    for (int i=1; i<=n; i++) {
        int a; scanf("%d", &a);

        long long ret = 0;
        for (int i=0; i<3; i++) {
            if (a == dat[i]) ret += (long long)1;
        }

        for (int i=0; i<3; i++) {
            if (a == dat[i]) {
                dat[i] += 1;
                break;
            }
        }

        res = (res * ret) % MOD;
    }

    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 256
N, Y = map(int, input().split())
ans = [-1, -1, -1]

for i in range(N + 1):
    for j in range(N - i, -1, -1):
        if 10000 * i + 5000 * j + 1000 * (N - i - j) == Y:
            ans[0] = i
            ans[1] = j
            ans[2] = (N - i - j)

print(*ans)

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vst = vector<st>;
using vchar = vector<char>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;


int main(){
  st n;
  cin >> n;
  vll abcd(4);
  rep(i, 0, 4) abcd.at(i) = n.at(i) - '0';
  bitset<3> ans;
  for (int tmp = 0; tmp < (1 << 3); tmp++){
    bitset<3> op(tmp);
    ll sum = abcd.at(0);
    rep(i, 0, 3){
      if(op.test(i)) sum += abcd.at(i + 1);
      else sum -= abcd.at(i + 1);
    }
    if(sum == 7){
      ans = op;
      break;
    }
  }
  cout << abcd.at(0);
  rep(i, 0, 3){
    cout << (ans.test(i) ? "+" : "-" ) << abcd.at(i + 1);
  }
  cout << "=7" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool PN(int x)
{
  if (x <= 1)
    return false;
  if (x == 2)
    return true;
  for (int i = 2; i < sqrt(x) + 1; i++)
    if (x % i == 0)
      return false;
  return true;
}

void solve()
{
  int x; cin >> x;
  int pos = 0;
  int t;
  for(int i = 1; pos < x; ++i){
    pos += i;
    t=i;
  }
  cout << t << endl;

}

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

Measured memory_bytes: 3656
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vb vector<bool>
#define pii pair<int,int>
#define mii map<int,int>
#define all(c)  c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b)  (x/gcd(x,y))*y
#define inf (long long) 1e18
#define F first
#define S second
#define sz(x) ((int)(x).size())
#define rep(i,n)  for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define deb(x) cout << #x << "=" << x <<"\n";
const int N = 1e9 + 7;

int pow(int x, int y) { int res = 1; while (y > 0) { if (y & 1) res = ((res) * (x)); res %= N; y = y >> 1; x = ((x) * (x)); } return res; }
int pow(int x, int y, int p)  {  int res = 1; x = x % p; while (y > 0) {if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p;}   return res; }


void solve()
{
	int n,w;
	cin>>n>>w;
	vector<pii> v(n+1);
	int sum=0;
	rep1(i,n)
	{
		int a,b;
		cin>>a>>b;
		v[i]={a,b};
		sum+=b;
	}
	vector<int> dp(sum+1,inf);
	dp[0]=0;
	for(int j=1;j<=n;j++)
	{
		for(int i=sum-v[j].S;i>=0;i--)
		{
			dp[i+v[j].S]=min(dp[i+v[j].S],dp[i]+v[j].F);
		}
	}	

	int ans=0;
	for(int i=0;i<=sum;i++)
	{
		if(dp[i]<=w)
			ans=max(ans,i);
	}
	cout<<ans;
}	



int32_t main()
{
	// #ifndef ONLINE_JUDGE
 //    freopen("gymnastics.in", "r", stdin);
 //    freopen("gymnastics.out", "w", stdout);
	// #endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
   int t=1;
   	// cin>>t;
   while(t--)
   	solve();
}






//code by-Roshan











//unnecessary
// bool cmp(pair<int,int> &a,pair<int,int> &b)
// {
// 	if(a.F==b.F)
// 		return (a.S<b.S);
// 	else 
// 		return (a.F<b.F);
// 	//< =chota wala pehle
// 	//> =chota wala baad me
// }


//better use this structure
// struct s{
// 	int a;
// 	bool operator <(const s &x) const
// 	{
// 		return (a>x.a);
// 	}
// };



//	priority_queue<int,vector<int>,greater<>> p;(priority queue as min heap)



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

int main(){

    int n;
    cin>>n;
    int a[n+5],b[n+5],c[n+5];
    for(int i=0; i<n; i++)
        cin>>a[i]>>b[i]>>c[i];
    int dp[n+5][3];
    int temp[3];
    for(int i=0; i<n; i++){
        memset(temp,0,sizeof(temp));
        if(i==0){
            temp[0]=a[i];
            temp[1]=b[i];
            temp[2]=c[i];
        }
        else{
            temp[0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
            temp[1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
            temp[2]=c[i]+max(dp[i-1][0],dp[i-1][1]);
        }
        dp[i][0]=temp[0];
        dp[i][1]=temp[1];
        dp[i][2]=temp[2];
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
    return 0;
}


Measured memory_bytes: 5972
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}


const int INF = 1e8;
int levenshteinDistance(string& s, string& t){
	vector<vector<int>> dp(s.size() + 1, vector<int>(t.size() + 1, INF));
	rep(i, s.size() + 1) dp[i][0] = i;
	rep(i, t.size() + 1) dp[0][i] = i;

	range(i,1,s.size() + 1){
		range(j,1,t.size() + 1){
			int cost = s[i - 1] == t[j - 1] ? 0 : 1;
			dp[i][j] = min({
					dp[i - 1][j] + 1,			// Insertion
					dp[i][j - 1] + 1,			// Deletion
					dp[i - 1][j - 1] + cost});	// Replace
		}
	}
	return dp[s.size()][t.size()];
}

int main(){
	string s, t;
	cin >> s >> t;
	cout << levenshteinDistance(s, t) << endl;
	return 0;

	int n;
	while(cin >> n, n){
		int d;
		cin >> d;

		vector<string> s(n);
		rep(i,n){
			cin >> s[i];
		}
	}
}



Measured memory_bytes: 6812
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        long N = in.nextLong();

        Queue<Long> q = new PriorityQueue<>();
        q.add(3L);
        q.add(5L);
        q.add(7L);

        long res = 0;
        while (!q.isEmpty()) {
            long a = q.poll();
            if (a > N) {
                break;
            }

            String s = Long.toString(a);
            if (s.contains("3") && s.contains("5") && s.contains("7")) {
                res += 1;
            }
            q.add(a * 10 + 3);
            q.add(a * 10 + 5);
            q.add(a * 10 + 7);
        }

        System.out.println(res);
    }
}



Measured memory_bytes: 26324
#include<bits/stdc++.h>
using namespace std;
long long a,b[100005],c,ans=999999999999999;
int main()
{
	cin>>a>>c;
	for(int s=0;s<a;s++)cin>>b[s];
	sort(b,b+a);
	for(int s=c-1;s<a;s++)
	ans=min(ans,b[s]-b[s-c+1]);
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
n=int(input())
action=[list(map(int,input().split())) for i in range(n)]
#print(action)
DP=[[0 for j in range(3)] for k in range(n+1)]
DP[1][0]=action[0][0]
DP[1][1]=action[0][1]
DP[1][2]=action[0][2]
for l in range(1,n+1):
  DP[l][0]=DP[l-1][1]+action[l-1][0]
  DP[l][1]=DP[l-1][0]+action[l-1][1]
  DP[l][2]=DP[l-1][0]+action[l-1][2]
  if DP[l][0]<DP[l-1][2]+action[l-1][0]:
    DP[l][0]=DP[l-1][2]+action[l-1][0]
  if DP[l][1]<DP[l-1][2]+action[l-1][1]:
    DP[l][1]=DP[l-1][2]+action[l-1][1]
  if DP[l][2]<DP[l-1][1]+action[l-1][2]:
    DP[l][2]=DP[l-1][1]+action[l-1][2]
print(max(max(DP)))

Measured memory_bytes: 76504
#include <bits/stdc++.h>
using namespace std;
void check(vector<int> &v, int st, int fin){
    vector<int> good;
    set<int> unused;
    for (int i=st; i <= fin; i++) unused.insert(v[i]);
    int ind = fin;
    while (ind >= st){
        set<int>::iterator it = unused.end();
        it--;
        int num = *it;
        while (true){
            unused.erase(unused.find(v[ind]));
            if (v[ind] == num){
                good.push_back(ind);
                ind--;
                break;
            }
            ind--;
        }
    }
    reverse(good.begin(), good.end());
    int u = 0;
    for (int i=st; i <= fin; i++){
        if (u < good.size() && good[u] == i){
            u++;
            continue;
        }
        int L=i, R = i;
        int diff = i - st;
        if (diff%2 == 0) L -= 2*u;
        L++, R++;
        //cout << i << " " << pl << endl;
        if (L <= v[i] && R >= v[i]) continue;
        cout << "No";
        exit(0);
    }
}
void solve(vector<int> &v, int st){
    if (st == v.size()) return;
    set<int> ms;
    for (int i=st; i < v.size(); i++){
        ms.insert(v[i]-st);
        set<int>::iterator it = ms.end();
        it--;
        int mx = *(it);
        if (mx == ms.size()){
            check(v, st, i);
            solve(v, i+1);
            return;
        }
    }
}
signed main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i=0; i < n; i++) cin >> v[i];
    solve(v, 0);
    cout << "Yes";

}


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

using ull = unsigned long long;


struct INIT{INIT(){ios::sync_with_stdio(false);cin.tie(0);}}init;
vector<int> f(int N){
    vector<int> res;res.reserve(N);
    int i;
    for(i = 1; i*i < N; i++){
        if(N%i==0){
            res.push_back(i);
            res.push_back(N/i);
        }
    }
    if(i*i==N)res.push_back(i);
    sort(res.begin(),res.end());
    return res;
}

int main(){
    int N; cin >> N;
    vector<int> S(N);
    for(auto& it : S)cin>>it;
    auto y=f(N);
    int res=1;
    for(auto& it : y){
        int T=N/it;
        bool check=[&](){
            for(int m = 0; m < T; m++){
                int p=S[m];
                for(int i = T+m; i < N; i+=T)
                    if(S[i]!=p)return false;
            }
            return true;
        }();
        if(check)res=max(res,it);
    }
    cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 3860
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, M = mapint()
As = list(mapint())

cnt = 0
ALL = sum(As)
for a in As:
    if 4*M*a>=ALL:
        cnt += 1

if cnt>=M:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 61836
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>
#include<iostream>
#include<cmath>
using namespace std;

int main() {
	int N;
	long long ans = 1;
	cin >> N;
	std::vector<int> D(N), count_D(N);int max_D = 0;
	for (int i = 0; i < N; i++) count_D[i] = 0;
	for (int i = 0; i < N; i++) {
		cin >> D[i];
		count_D[D[i]] += 1;
		if (max_D < D[i]) max_D = D[i];
	}
	if (count_D[0] != 1 || D[0] != 0) {
		cout << 0 << endl;
		return 0;
	}
	else {
		for (int i = 0; i < max_D; i++) {
			for (int j = 0; j < count_D[i + 1]; ++j) {
				ans *= count_D[i];
				ans %= 998244353;
			}
		}
		printf("%lld\n", ans % 998244353);
		return 0;
	}
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; 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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)

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

int inf = 1e9;

struct edge{
  int from, to, cost;
};

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

  ll n, m;
  cin >> n >> m;

  int a, b, c;
  vvi d(n, vi(n, inf));
  vector<edge> es(m);
  REP(i, m){
    cin >> a >> b >> c;
    a--;
    b--;
    d[a][b] = d[b][a] = c;
    es.push_back((edge){a, b, c});
  }

  REP(k, n){
    REP(i, n){
      REP(j, n){
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }

  int ans = 0;
  for(auto e : es){
    if(d[e.from][e.to] < e.cost) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
n,m,x,y = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a_max = max(a)
b_min = min(b)
for i in range(x+1,y+1):
    if a_max < i and b_min >= i:
        print('No War')
        exit()
print('War')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,c=0;
    cin >> a;
    if(a/100==1){
        c++;
    }
    if(a%100==10||a%100==1){
        c++;
    }else if(a%100==11){
        c=c+2;
    }
    cout << c << endl;
    return 0;
    
}


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

struct haku
{
	string str;
	char boin;
	bool m_shiin, sokuin, chouon;
	haku(string str, char boin, bool m_shiin, bool sokuin, bool chouon)
		: str(str), boin(boin), m_shiin(m_shiin), sokuin(sokuin), chouon(chouon) {}
};


string S;
bool is_boin(char v)
{
	return v == 'a' || v == 'i' || v == 'u' || v == 'e' || v == 'o';
}
bool is_shiin(char v)
{
	return !is_boin(v);
}
bool is_chouon(int i)
{
	if (i == S.size() - 1) return false;
	if (S[i] == 'a' && S[i + 1] == 'a')return true;
	if (S[i] == 'i' && S[i + 1] == 'i')return true;
	if (S[i] == 'u' && S[i + 1] == 'u')return true;
	if (S[i] == 'e' && S[i + 1] == 'i')return true;
	if (S[i] == 'o' && S[i + 1] == 'u')return true;
	return false;
}
bool is_m_shiin(char v)
{
	return v == 'k' || v == 's' || v == 't' || v == 'h' || v == 'p';
}

vector<haku> V;
string str;
void go_next(bool chouon)
{
	int N = str.size();
	char boin = str[N - 1];
	if (chouon)boin = str[N - 2];
	bool soku = N >= 2 && is_shiin(str[0]) && str[0] == str[1];

	V.push_back(haku(str, boin, is_m_shiin(str[0]), soku, chouon));
	str = "";
}

int main() {
	while (true) {
		cin >> S;
		if (S[0] == '#')return 0;
		V.clear();
		str = "";
		rep(i, S.size())
		{
			str += S[i];
			if (S[i] == 'n' || S[i] == '\'')
			{
				go_next(false);
			}
			else if (is_boin(S[i]))
			{
				if (is_chouon(i))
				{
					i++;
					str += S[i];
					go_next(true);
				}
				else
				{
					go_next(false);
				}
			}
		}
		 //for(auto e: V)
		 //{
		 //    cout << e.str << " " << e.m_shiin << " " << e.sokuin << " " << e.chouon << " " << e.boin <<  endl;
		 //}

		vector<bool> ans(V.size());
		rep(i, V.size())
		{
			if (i > 0 && ans[i - 1])continue;
			if (!V[i].m_shiin)continue;

			if (V[i].boin == 'i' || V[i].boin == 'u')
			{
				//if(V[i].chouon)continue;

				ans[i] = !V[i].chouon && (i == V.size() - 1 || V[i + 1].m_shiin);
			}
			else if (V[i].boin == 'a' || V[i].boin == 'o')
			{
				if (i + 1 == V.size())continue;
				if (!V[i + 1].m_shiin)continue;
				if (V[i].boin != V[i + 1].boin)continue;
				if (V[i].chouon)continue;
				if (V[i + 1].sokuin)continue;
				ans[i] = true;
			}
		}

		// for(auto e: ans)
		// {
		//     cout << e << endl;
		// }

		rep(i, V.size())
		{
			if (ans[i])
			{
				int kakko = V[i].str.size() - 1;
				if (V[i].chouon)kakko--;
				rep(j, V[i].str.size())
				{
					if (j == kakko)cout << '(';
					cout << V[i].str[j];
					if (j == kakko)cout << ')';
				}
			}
			else
			{
				cout << V[i].str;
			}
		}
		cout << endl;
	}
}


Measured memory_bytes: 3152
s = input()
t = input()
ans = "UNRESTORABLE"
for begin in range(len(s)):#塗り替えるとこの始点
    if begin+len(t) > len(s):
        break
    tmp = list(s)
    ti = 0
    for i in range(begin,begin+len(t)):
        tmp[i] = t[ti]
        ti += 1
    for i in range(len(s)):
        if s[i] != '?':
            if s[i] != tmp[i]:
                break
    else:
        for i in range(len(s)):
            if tmp[i] == "?":
                tmp[i] = 'a'
        ans = "".join(tmp)
print(ans)

Measured memory_bytes: 9088
n=int(input())
F=[int("0b"+"".join(input().split()),0) for _ in range(n)]
P=[list(map(int,input().split())) for _ in range(n)]
ans=-10e9
for i in range(1,2**10):
	m=0
	for f,p in zip(F,P):
		m+=p[bin(i&f).count("1")]
	ans=max(ans,m)
print(ans)

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line

int h, w;
vector<string> fie(50);

const int di[] = {-1,0,0,1};
const int dj[] = {0,-1,1,0};
bool check(int sy, int sx, int k){
	if(sy + di[k] < 0 || sx + dj[k] < 0) return true;
	if(sy + di[k] >= h || sx + dj[k] >= w) return true;
	int ny = sy + di[k];
	int nx = sx + dj[k];
	if(fie[ny][nx] == '#') return true;
	else return false;
}
int main()
{
	cin >> h >> w;
	rep(i, h)cin>>fie[i];

	// 全てのマスに対して、上下左右の4マスに黒があるかみる。
	rep(i,h){
		rep(j,w){
			bool ng = true;
			if(fie[i][j] == '.'){
				continue;
			} else {
				rep(k,4){
					if(check(i,j,k)){
						// ok; 4回のうちどれかしらが通ればいい。
						ng = false;
					}	
				}
				if(ng) {
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d %d %d", $N, $M, $K);
$ans = false;
for ($i = 0; $i <= $N; $i++) {
    for ($j = 0; $j <= $M; $j++) {
        if ($i * $j + ($N - $i) * ($M - $j) === $K) {
            $ans = true;
            break 2;
        }
    }
}
echo $ans ? 'Yes' : 'No';


Measured memory_bytes: 4728
/*******************************\
   Name:    REAJUL HAQUE REAYZ  |
   School:  COMILLA UNIVERSITY  |
            CSE (5TH BATCH)     |
********************************/
#include<bits/stdc++.h>
#define endl "\n"
#define inf 1<<30
#define pi acos(-1.0)
#define pb push_back
#define mp make_pair
#define ss stringstream
#define all(v) v.begin(), v.end()
#define mem(x,y) memset(x , y , sizeof(x))
#define bit_cnt(mask) __builtin_popcount(mask)
using namespace std;
typedef long long ll;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;
const ll MOD = 1000000007; /// 1e9+7
const int MAX = 200005;
ll bigmod(ll n, ll r)
{
    if(r==0) return 1;
    if(r==1) return n;
    if(r%2==0)
    {
        ll ret = bigmod(n, r/2);
        return ((ret%MOD) * (ret%MOD)) % MOD;
    }
    else return ((n%MOD) * (bigmod(n,r-1)%MOD)) % MOD;
}
ll modinverse(ll a){return bigmod(a,MOD-2)%MOD;}
ll lcm(ll a, ll b) {a=abs(a); b=abs(b); return (a/__gcd(a,b))*b;}
ll gcd(ll a, ll b) {a=abs(a); b=abs(b); if(!b) return a; return __gcd(b,a%b);}
//int in() {int x; scanf("%d",&x); return x;}
//ll lin() {ll x; scanf("%lld",&x); return x;}

int cnt[MAX];
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, k; cin>>n>>k;
    set<int>s;
    for(int i=0; i<n; i++) {
        int x; cin>>x;
        cnt[x]++;
        s.insert(x);
    }
    if(s.size()>k){
        vector<int>v;
        for(int i=1; i<=n; i++){
            if(cnt[i]) v.pb(cnt[i]);
        }
        sort(all(v));
        reverse(all(v));
        int sum=0;
        for(int i=k; i<v.size(); i++) sum += v[i];
        cout<<sum<<endl;
    }
    else cout<<0<<endl;
    return 0;
}


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

int dp(vector<int> &atk, vector<int> &mp, int hp)
{
    int n = (int)atk.size();
    vector<vector<int>> mat(n, vector<int>(hp+1));
    for(int i = 0; i < n; ++i)
    {
        for(int j = 1; j <= hp; ++j)
        {
            if(i == 0)
            {
                mat[i][j] = ceil((double)j/atk[i])*mp[i];
            }
            else if(j-atk[i] <= 0)
            {
                mat[i][j] = min(mat[i-1][j], mp[i]);
            }
            else
            {
                mat[i][j] = min(mat[i-1][j],mat[i][j-atk[i]]+mp[i]);   
            }
        }
    }
    return mat[n-1][hp];
}

int main()
{
    int h,n;
    cin >> h >> n;
    vector<int> atk(n);
    vector<int> mp(n);
    for(int i = 0; i < n; ++i)
    {
        int a,b;
        cin >> a >> b;
        atk[i] = a;
        mp[i] = b;
    }
    cout << dp(atk,mp,h) << endl;
}

Measured memory_bytes: 39424
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <string>

using namespace std;

typedef long long LL;
typedef unsigned int UI;

#define rSort(a) 		sort(a.rbegin(),a.rend())
#define Sort(a) 		sort(a.begin(),a.end())
#define Reverse(a) 		reverse(a.begin(),a.end())
#define Sum(a)  		accumulate(a.begin(), a.end(), 0)
#define REP(i, n) 		for(UI i = 0;i < n;i++)
#define REPR(i, n) 		for(UI i = n;i >= 0;i--)
#define FOR(i, m, n) 	for(UI i = m;i < n;i++)
#define pb(i) 			push_back(i)

#define MOD  			(LL)1e9 + 7;
#define INF  			(LL)1 << 62;

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

	cin.tie(0);
	ios::sync_with_stdio(false);

	LL N,sum;

	cin >> N;

	vector<LL> V(N);
	vector<LL> C(N);

	REP(i,N){
		cin >> V[i];
	}

	REP(i,N){
		cin >> C[i];
	}

	sum = 0;
	REP(i,N){
		if(V[i] > C[i]){
			sum += V[i]-C[i];
		}
	}

	cout << sum << endl;

	return 0;

}


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

int main() {
    int k;
    string s;
    cin >> k >> s;
    string ans = "";
    if (s.length() <= k) {
        ans = s;
    } else {
        ans = s.substr(0, k) + "...";
    }
    cout << ans << endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include<cstdio>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
// #define ALLR(obj) (obj).rbegin(), (obj).rend()
#define BIT(n) (1LL << (n))

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  string jpy = "JPY";
  string btc = "BTC";
  
  double oto = 0;
  REP(i, n) {
    double x;
    cin >> x;
    string u;
    cin >> u;
    
    if (u == btc) {
      double a = 380000.0*x;
      oto += a;
    } else {
      oto += x;
    }
  }  
  
  cout << fixed << setprecision(9) << oto;
}


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

using namespace std;
int n,m,s;
string x;
int main()
{
    cin>>x;
    if(x.size()==2&&x[0]==x[1]){
        cout<<"1 2";
        return 0;
    }
    for(int i=2;i<x.size();i++){
        if(x[i]==x[i-1]&&x[i]!=x[i-2]||x[i]==x[i-2]&&x[i]!=x[i-1]||x[i]==x[i-2]&&x[i]==x[i-1]){
            cout<<i-1<<" "<<i+1;
            return 0;
        }
    }
    cout<<"-1 -1";
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

#define MOD 1000000007;

int main(){
	int n;
	cin >> n;
	vector<int> a1(n), a2(n);
	for(int i=0; i<n; i++){
		cin >> a1[i];
		if(i)
			a1[i]+=a1[i-1];
	}
	for(int i=0; i<n; i++){
		cin >> a2[i];
	}
	int maxi = a1[0]+a2[0];
	for(int i=1; i<n; i++){
		maxi = max(maxi,a1[i]);
		maxi += a2[i];
	}
	cout << maxi << endl;
	return 0;
}

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

 class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;
        ArrayList<Integer> al = new ArrayList<Integer>();
        try {
            while((str = br.readLine()) != null) {
                al.add( Integer.parseInt(str) );
            }
        } catch (NumberFormatException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        Collections.sort(al);
        Collections.reverse(al);
        for(int i=0; i<3; i++) {
            System.out.println(al.get(i));
        }
    }
}

Measured memory_bytes: 24044
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b,nb=0,cnt=0;
  string s;
  cin>>n>>a>>b;
  cin>>s;
  for(int i=0;i<n;i++){
    if(s[i]=='a'){
      if(cnt<a+b){
        cout<<"Yes";
        cnt++;
      }
      else cout<<"No";
    }
    else if(s[i]=='b'){
      if(cnt<a+b&&nb<b){
        cout<<"Yes";
        nb++;
        cnt++;
      }
      else cout<<"No";
    }
    else cout<<"No";
    cout<<endl;
  }
}

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

typedef long long ll;

int main(){
  ll a;
  cin>>a;
  ll l;
  for(l=2;l/2*(l/2+1)/2<a;l+=2);
  string s(l,'(');
  for(int i=0;i<=l/2;i++){
    s[i]=')';
  }
  s[0]='(';
  l-=2;
  a-=l/2*(l/2+1)/2;
  // cout<<a<<endl;
  for(int i=0;a>0;i++){
    a--;
    swap(s[i],s[i+1]);
  }
  cout<<s<<endl;








  return 0;
}



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

#define pb push_back

using namespace std;

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

const int maxn=2e5+10;

vector <int> g1[maxn] , g2[maxn];
map <pii , int> mp;
int par1[maxn],t=0,par2[maxn];
bool mark[maxn];

void dfs1(int u)
{
    par1[u]=t;
    mark[u]=1;
    for(auto v:g1[u])
        if(!mark[v])
            dfs1(v);
}

void dfs2(int u)
{
    par2[u]=t;
    mp[{par1[u] , par2[u]}]++;
    mark[u]=1;
    for(auto v:g2[u])
        if(!mark[v])
            dfs2(v);
}

int main()
{
    ios_base::sync_with_stdio(false);
    int n,m,k;
    cin>>n>>m>>k;
    for(int i=0,x,y ; i<m ; i++)
    {
        cin>>x>>y;
        g1[x].pb(y);
        g1[y].pb(x);
    }
    for(int i=0,x,y ; i<k ; i++)
    {
        cin>>x>>y;
        g2[x].pb(y);
        g2[y].pb(x);
    }
    for(int i=1 ; i<=n ; i++)
        if(!mark[i])
            t++ , dfs1(i);
    t=0;
    memset(mark , 0 , sizeof(mark));
    for(int i=1 ; i<=n ; i++)
        if(!mark[i])
            t++ , dfs2(i);
    for(int i=1 ; i<=n ; i++)
        cout<<mp[{par1[i] , par2[i]}]<<" ";
    return 0;
}


Measured memory_bytes: 28160
#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793
#define MOD 1000000007
typedef long long ll;
typedef long double ld;

int main() {
    ll A, B, C, K;
    ll ans;
    cin >> A >> B >> C >> K;
    while(1){

        if(A >= B){
            B *= 2;
            K--;
        }
        else{
            break;
        }

    }

    while(1){

        if(B >= C){
            C *= 2;
            K--;
        }
        else{
            break;
        }

    }

    if(K < 0){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 3620
fn main() {
    let (w, h, x, y, r) = input();

    println!("{}", if x - r >= 0 && x + r <= w && y - r >= 0 && y + r <= h { "Yes" } else { "No" });
}

fn input() -> (i32, i32, i32, i32, i32) {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut i = s.trim().split_whitespace().map(|q| q.parse::<i32>().unwrap());

    (i.next().unwrap(), i.next().unwrap(), i.next().unwrap(), i.next().unwrap(), i.next().unwrap())
}



Measured memory_bytes: 5028
#include<iostream>

using namespace std;

int main(){
  int m,n,sum=0,ct = 0;
  int a[100];
  cin >> n >> m;
  for(int i = 0;i < n;i++){
    cin >> a[i];sum += a[i];
  }
  for(int i = 0;i < n;i++){
    if(4*m*a[i] >= sum){ct++;}
  }
  if(ct >= m){cout << "Yes" << endl;}
  else{cout << "No" << endl;}
  return 0;
}

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

int main ()
{
    char a[6];
    int i,flag=0;
    for(i=0;i<6;i++)
    {
        cin>>a[i];
    }
     for(i=0;i<6;i++)
    {
       if((a[2]==a[3])&&(a[4]==a[5]))
       flag=1;
       else
        flag=0;

    }
    if(flag==0)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
}


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

template <class T>
inline void read(T &res)
{
	res = 0; bool bo = 0; char c;
	while (((c = getchar()) < '0' || c > '9') && c != '-');
	if (c == '-') bo = 1; else res = c - 48;
	while ((c = getchar()) >= '0' && c <= '9')
		res = (res << 3) + (res << 1) + (c - 48);
	if (bo) res = ~res + 1;
}

const int N = 2005;

int n, m, q, sum[N][N], sum1[N][N], sum2[N][N];
char s[N][N];

int main()
{
	int xl, yl, xr, yr;
	read(n); read(m); read(q);
	for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
		{
			sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
			sum1[i][j] = sum1[i - 1][j] + sum1[i][j - 1] - sum1[i - 1][j - 1];
			sum2[i][j] = sum2[i - 1][j] + sum2[i][j - 1] - sum2[i - 1][j - 1];
			if (s[i][j] == '1')
			{
				sum[i][j]++; if (s[i - 1][j] == '1') sum1[i][j]++;
				if (s[i][j - 1] == '1') sum2[i][j]++;
			}
		}
	while (q--)
	{
		read(xl); read(yl); read(xr); read(yr);
		printf("%d\n", sum[xr][yr] - sum[xl - 1][yr] - sum[xr][yl - 1] +
			sum[xl - 1][yl - 1] - sum1[xr][yr] + sum1[xl][yr] + sum1[xr][yl - 1]
				- sum1[xl][yl - 1] - sum2[xr][yr] + sum2[xl - 1][yr]
					+ sum2[xr][yl] - sum2[xl - 1][yl]);
	}
	return 0;
}

Measured memory_bytes: 54724
H, W, A, B = list(map(int, input().split()))

h = -1
w = -1
for i in range(1, H + 1):
  for j in range(1, W + 1):
    if i * A + (H - i) * (W - A) == j * B + (W - j) * (H - B):
      h = i
      w = j
      break
  else:
    continue
  break
if h == -1:
  print("No")
  exit()


L = ["1"] * A + ["0"] * (W - A)
for i in range(B):
  print("".join(L))

L = ["0"] * A + ["1"] * (W - A) 
for i in range(H - B):
  print("".join(L))


Measured memory_bytes: 40688
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace A
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var ab = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var sum = 0;

            sum += ab[0] >= ab[1] ? ab[0]-- : ab[1]--;
            sum += ab[0] >= ab[1] ? ab[0]-- : ab[1]--;
            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 13396
using System;

class Program
{
  public static void Main(string[] args)
  {
    string[] tmp = Console.ReadLine().Split(' ');
    int[] numbers = new int[3];
    for(int i = 0;i < 3;i++)
    {
      numbers[i] = int.Parse(tmp[i]);
    }
    if(numbers[0] > numbers[1]){
      int int_tmp = numbers[0];
      numbers[0] = numbers[1];
      numbers[1] = int_tmp;
    }
    if(numbers[1] > numbers[2]){
      int int_tmp = numbers[1];
      numbers[1] = numbers[2];
      numbers[2] = int_tmp;
    }
    if(numbers[0] > numbers[1]){
      int int_tmp = numbers[0];
      numbers[0] = numbers[1];
      numbers[1] = int_tmp;
    }
    Console.WriteLine("{0} {1} {2}",numbers[0],numbers[1],numbers[2]);
  }
}

Measured memory_bytes: 9124
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define all(uiet) uiet.begin(),uiet.end()
#define read(UIET) for(int i = 0; i < n; ++i) cin >> UIET[i]
#define out(UIET) for(int i = 0; i < n; ++i) cout << UIET[i]
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vpp vector<pair< int, int > >
#define pll pair<int , int >
#define ppll pair < pll , pll >
#define debug(n1) cout << n1 << endl
#define len(a) ((int) (a).size())
#define endl "\n"
#define mod 1000000007
const int INF=(1LL<<60)-1;
const int maxN = 1000001;
int isSubstring(string s1, string s2) { 
    int M = len(s1); 
    int N = len(s2); 
    for (int i = 0; i <= N - M; i++) { 
        int j; 
        for (j = 0; j < M; j++){
            if (s2[i + j] != s1[j]){
                break; 
            }
        }
        if (j == M){
            return 1; 
        }
    } 
    return 0; 
} 
int32_t main(){
    SPEED;
    int n;
    cin >> n;
    int a = -INF, b = INF, c = -INF, d = INF;
    for(int i = 0; i < n; ++i){
        int x, y;
        cin >> x >> y;
        a = max(a, x + y);
        b = min(b, x + y);
        c = max(c , x - y);
        d = min(d, x - y);
    }
    cout << max(a - b, c - d);
}

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if ((b * 10 + c) % 4 == 0) {
		cout << "YES";
	}
	else {
		cout << "NO";
	}
	return 0;
}

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


int main()
{
	ios_base::sync_with_stdio(false);
	int n ; string s;
	cin >> n >> s ;
	for(auto &x : s){
		x =( (x - 'A' + n ) % 26 ) + 'A';
	}
	cout << s << endl ;
    return 0;
}


Measured memory_bytes: 256
import java.io.*;import java.util.*;

public class Main{
    static class FastReader{
        BufferedReader br; 
        StringTokenizer st; 
        public FastReader(){br = new BufferedReader(new InputStreamReader(System.in));} 
        String next(){while (st == null || !st.hasMoreElements()){try{st = new StringTokenizer(br.readLine());}catch (IOException  e){e.printStackTrace();}}return st.nextToken();} 
        int nextInt(){return Integer.parseInt(next());} 
        long nextLong(){return Long.parseLong(next());} 
        double nextDouble(){return Double.parseDouble(next());} 
        int[] readArray(int n){int[] a=new int[n];for (int i=0; i<n; i++) a[i]=nextInt();return a;}
        long[] readLongArray(int n){long[] a=new long[n];for (int i=0; i<n; i++) a[i]=nextLong();return a;}
        String nextLine(){String str = "";try{str = br.readLine();}catch (IOException e){e.printStackTrace();}return str;} 
    }
    static int getgcd(int n1,int n2){
        while(n1 != n2){
            if(n1 > n2) n1 -= n2;
            else n2 -= n1;
        }
        return n1;
    }
    static boolean isSorted(int[] arr, int n){
        for(int i=1;i<n;i++){
            if(arr[i]<arr[i-1]) return false;
        }
        return true;
    }
    static boolean isPrime(long n){
        if(n==2) return true;
        else if(n%2==0) return false;
        for(int i=3;i<=n/2;i+=2){
            if(n%i==0) return false;
        }
        return true;
    }
    static void printArray(int[] arr){
        for(int x:arr){
            System.out.print(x+" ");
        }
        System.out.println();
    }
    public static void main(String[] args) throws NumberFormatException, IOException {
        FastReader s=new FastReader();
        //int t = s.nextInt();
        int[] a = s.readArray(5);
        boolean test;
        //while(t>0){
            //test=true;
            if(a[0]==0) System.out.println("1");
            else if(a[1]==0) System.out.println("2");
            else if(a[2]==0) System.out.println("3");
            else if(a[3]==0) System.out.println("4");
            else if(a[4]==0) System.out.println("5");
            //t--;
       // }
    }
}

Measured memory_bytes: 25064
from bisect import bisect_left
from collections import deque

def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    ans = deque([A[0]])
    for i in range(1,N):
        index = bisect_left(ans,A[i])
        if index == 0:
            ans.appendleft(A[i])
        else:
            ans[index-1] = A[i]

    print(len(ans))



if __name__ == "__main__":
    main()

Measured memory_bytes: 53720
#include<bits/stdc++.h>
#define FOR0(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(ll i=l;i<n;i++)
using namespace std;
#define pi pair<ll,ll>
#define pb push_back
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e14
ll power(ll num,ll g,ll mod){
  if(g==0)return 1;
  if(g%2==1)return (num*power((num*num)%mod,g/2,mod))%mod;
  return power((num*num)%mod,g/2,mod);
}

int main(){
	ll n, W;
	cin >> n >> W;
	ll v[n+1], w[n+1];
	FOR1(i,n){
		cin>>w[i]>>v[i];
	}
	// dp[i][j] = min(dp[i-1][j],dp[i-1][j-v[i]]+w[i])

	ll dp[n+1][100001];
	
	for (ll i = 0; i < n + 1; i++){
		FOR0(j,100001){
			dp[i][j] = 1e15;
		}
		dp[i][0] = 0;
	}
	dp[1][v[1]] = w[1];
	FOR1(i,n){
		FOR1(j,100001){

			if(i == 1 && j == 1)
				continue;

			dp[i][j] = dp[i-1][j];

			if (v[i]<=j){
				dp[i][j] = min(dp[i][j],dp[i-1][j-v[i]]+w[i]);
			} 
		}
	}
	//cout << dp[1][30] sp dp[2][30] sp dp[2][50] sp dp[2][80] sp dp[3][30] sp dp[3][50] sp dp[3][80] sp dp[3][60] sp dp[3][80] sp dp[3][90] sp dp[3][110] sp dp[3][140] << endl;
	// FOR1(i,n){
	// 	FOR1(j,140) cout << dp[i][j] << " ";
	// 	cout << endl;
	// }
	for (int j = 100000; j>=0; j--){
		if (dp[n][j]<=W ) {
			cout << j << endl;
			break;
		}
	}
}


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

#define fec(i, x, y) (int i = head[x], y = g[i].to; i; i = g[i].ne, y = g[i].to)
#define dbg(...) fprintf(stderr, __VA_ARGS__)
#define File(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)
#define fi first
#define se second
#define pb push_back

template<typename A, typename B> inline bool smax(A &a, const B &b) {return a < b ? a = b, 1 : 0;}
template<typename A, typename B> inline bool smin(A &a, const B &b) {return b < a ? a = b, 1 : 0;}

typedef long long ll; typedef unsigned long long ull; typedef std::pair<int, int> pii;

template<typename I> inline void read(I &x) {
	int f = 0, c;
	while (!isdigit(c = getchar())) c == '-' ? f = 1 : 0;
	x = c & 15;
	while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + (c & 15);
	f ? x = -x : 0;
}

const int N = 1e5 + 7;

int n;
int deg[N], ps[N], q[N], ans[N];

struct Edge { int to, ne; } g[N << 1]; int head[N], tot;
inline void addedge(int x, int y) { g[++tot].to = y, g[tot].ne = head[x], head[x] = tot; }
inline void adde(int x, int y) { addedge(x, y), addedge(y, x); }

inline void work() {
	for (int i = 1; i <= n; ++i) {
		for fec(j, i, y) if (deg[y] != 1) ++ps[i];
		if (ps[i] > 2) return (void)puts("-1");
	}
	int cc = 0;
	for (int i = 1; i <= n; ++i) if (deg[i] == 1 && ps[g[head[i]].to] <= 1) { q[++cc] = i; break; }
	for (int x = q[cc]; x; x && (q[++cc] = x)) {
		int w = 0;
		for fec(i, x, y) if (y != q[cc - 1] && deg[y] > 1) w = y;
		if (!w && deg[x] > 1) for fec(i, x, y) if (y != q[cc - 1]) w = y;
//		dbg("x = %d, w = %d\n", x, w);
		x = w;
	}
//	dbg("*q = %d\n", cc);
	bool nd = 0;
	for (int i = 1; i <= cc / 2; ++i) if (deg[q[i]] != deg[q[cc - i + 1]]) { nd = deg[q[i]] > deg[q[cc - i + 1]]; break; }
	if (nd) std::reverse(q + 1, q + cc + 1);
	int cnt1 = 0, cnt2 = 0;
	for (int i = 1; i <= cc; ++i) {
		int x = q[i], kk = ++cnt2;
		for fec(j, x, y) if (y != q[i - 1] && y != q[i + 1]) ans[++cnt1] = ++cnt2;//, dbg("x = %d, y = %d\n", x, y);
		ans[++cnt1] = kk;
	}
	assert(cnt1 == n);
	for (int i = 1; i <= n; ++i) printf("%d%c", ans[i], " \n"[i == n]);
}

inline void init() {
	read(n);
	int x, y;
	for (int i = 1; i < n; ++i) read(x), read(y), adde(x, y), ++deg[x], ++deg[y];
}

int main() {
#ifdef hzhkk
	freopen("hkk.in", "r", stdin);
#endif
	init();
	work();
	fclose(stdin), fclose(stdout);
	return 0;
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define lson root<<1,l,midd
#define rson root<<1|1,midd+1,r
#define pb push_back
typedef long long ll;
const int M=1e6+6;
ll p[M],q[M],r[M],all[M];
bool cmp(ll x,ll y){
    return x>y;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    for(int i=1;i<=a;i++)
        cin>>p[i];
    for(int i=1;i<=b;i++)
        cin>>q[i];
    for(int i=1;i<=c;i++)
        cin>>r[i];
    sort(p+1,p+1+a,cmp);
    sort(q+1,q+1+b,cmp);
    sort(r+1,r+1+c,cmp);

    int tot=0;
    for(int i=1;i<=x;i++)
        all[tot++]=p[i];
    for(int i=1;i<=y;i++)
        all[tot++]=q[i];
    for(int i=1;i<=c;i++)
        all[tot++]=r[i];
    sort(all,all+tot,cmp);
    ll ans=0;
    for(int i=0;i<x+y;i++)
        ans+=all[i];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 14592
import java.io.PrintWriter

val pw = PrintWriter(System.out)
fun main(args: Array<String>) {
    func()
    pw.flush()
}
fun print(value: Any) { pw.print(value) }
fun println(value: Any = "") { pw.println(value) }

//ABC129_D
fun func() {
    val (H, W) = listOfInt()
    var S = Array<String>(H) { next() }
    var WW = Array<IntArray>(H) { IntArray(W) }
    var HH = Array<IntArray>(H) { IntArray(W) }
    for (h in 0 until H) {
        var w = 0
        while (w < W) {
            if (S[h][w] == '.') {
                var c = w
                while (c < W && S[h][c] == '.') c++
                val sum = c - w
                while (w < c) WW[h][w++] = sum
            } else w++
        }
    }

    for (w in 0 until W) {
        var h = 0
        while (h < H) {
            if (S[h][w] == '.') {
                var r = h
                while (r < H && S[r][w] == '.') r++
                val sum = r - h
                while (h < r) HH[h++][w] = sum
            } else h++
        }
    }

    var ans = 0
    for (h in 0 until H)
        for (w in 0 until W)
            ans = Math.max(ans, WW[h][w] + HH[h][w] - 1)
    println("${ans}")
}

fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }


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


int main(){
	while(1){
	int n;
	cin>>n;
	if(n==0)break;
	vector<double> a(n);
	double ave = 0.0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		ave+=a[i];
	}
	sort(a.begin(),a.end());
	ave++;
	ave/=n;
	auto it = lower_bound(a.begin(),a.end(),ave);
	cout<<(int)(it-a.begin())<<endl;

	}
	return 0;
}



Measured memory_bytes: 3320