akhauriyash/Code-Regression huggingface dataset:
//S.G.N.//
#include <bits/stdc++.h>
using namespace std;
typedef vector< long long > vi;
typedef long long ll;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define fr(n) for(ll i=0;i<n;i++)
#define tr(a) for(auto it=a.begin();it!=a.end();it++)
#define N 998244353445 
#define PI 3.1415926535897932384
#define F first
#define S second
#define mp make_pair
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007

void solve()
{
ll n,k;
cin>>n>>k;
ll a[n];
fr(n)
{
  cin>>a[i];
} 
ll dp2[n+1];
dp2[n]=0;
for(ll i=n-1;i>=1;i--)
dp2[i]=dp2[i+1]+a[i];
ll dp[n+1][k+1];
fr(k+1)
dp[0][i]=0;
fr(n+1)
dp[i][0]=1;
fr(n+1)
{
 if(i==0)
 continue; 
ll prev=0;
ll c=0;
rep(j,max(0ll,k-dp2[i]-a[i-1]),k+1)
{
  c++;
  prev+=dp[i-1][j];
  prev=prev%mod;
  if(c>=a[i-1]+2)
  {
    prev-=dp[i-1][j-a[i-1]-1];
    prev=(prev+mod)%mod;
  }
  //cout<<j<<" "<<c<<" "<<prev<<endl;
  if(j>=k-dp2[i]){
    dp[i][j]=prev;
    //cout<<dp[i][j]<<endl;
  }
    
    

}
//cout<<endl;
}
cout<<dp[n][k];
}
int main()
{
  
  #ifndef ONLINE_JUDGE
     * freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
  #endif
  FAST
  ll test;
test=1;
  //cin>>test;
  while(test--)
  {
    solve();
  }
  return 0;
}


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

int main(){
    int n,m=1;
    cin>>n;
    vector<int> h(n);
    for(int i=0;i<n;i++) cin>>h[i];
    for(int i=1;i<n;i++){
        for(int j=0;j<i;j++){
            if(h[j]<=h[i]){
                if(j==i-1) m++;
            }else{
                break;
            }
        }
    }
    cout<<m<<endl;
    return 0;
}

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

int main() {
    string s;
    cin >> s;
    int K;
    cin >> K;
    
    int n = s.size();
    vector<int> vec(n);

    for(int i=0; i<n; i++) {
        if(s[i] == 'a') vec[i] = 0;
        else vec[i] = 26-(int)(s[i] - 'a');
    }
    for(int i=0; i<n-1; i++) {
        if(vec[i] <= K) {
            s[i] = 'a';
            K -= vec[i];
        }
    }
    if(K != 0) {
        if(K>=vec[n-1]) {
            K -= vec[n-1];
            K %= 26;
            s[n-1] = (char)((int)'a' + K);
        } else {
            s[n-1] = (char)((int)s[n-1] + K);
        }
    }

    cout << s;
    return 0;
}

Measured memory_bytes: 896
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
    int N;cin>>N;
    vector<int> h(N);
    REP(i,N){
        cin>>h[i];
    }
    int operation = 0;
    while(count(h.begin(),h.end(),0)==0){
        operation++;
        REP(i,N){
            h[i] = h[i] - 1;
        }
    }
    //cout<<operation<<endl;
    while(count(h.begin(),h.end(),0)!=N){
        int start = 0;
        int end = N+1;
        REP(i,N){
            if(h[i]>0){
                start = i;
                break;
            }
        }
        for(int i = start+1; i < N; i++)
        {
            if(h[i]==0){
                end = i;
                break;
            }
        }
        for(int i = start; i < end; i++)
        {
            h[i] = h[i] - 1;
        }
        //cout<<"start"<<start<<"end"<<end<<endl;
        operation++;
    }
    cout<<operation<<endl;
}

Measured memory_bytes: 256
use proconio::input;
    use proconio::marker::Usize1;
    use std::cmp::{Reverse, min};
    use std::collections::BinaryHeap;
     
    struct Path {
        node: usize,
        cost: usize,
        time: u64,
    }
     
    impl Clone for Path {
        fn clone(&self) -> Path {
            Path{node: (&self).node, cost: (&self).cost, time: (&self).time}
        }
    }
     
    fn main() {
        input!{
            n: usize,
            m: usize,
            s: usize,
            edges: [(Usize1, Usize1, usize, u64); m],
            ex_infos: [(usize, u64);n],
        }
        
        let mut graph: Vec<Vec<Path>> = vec![vec![]; n];
        let mut all_cost = 0;
        for (u, v, cost, time) in edges {
            graph[u].push(Path{node: v, cost, time});
            graph[v].push(Path{node: u, cost, time});
            all_cost += cost;
        }
     
        solve(graph, ex_infos, s, all_cost);
    }
     
    fn solve(graph: Vec<Vec<Path>>, exchange: Vec<(usize, u64)>, s: usize, max_cost: usize) -> () {
        let max_time = std::u64::MAX;
        let s = min(max_cost, s);
        let n = graph.len();
        let mut dp = vec![vec![max_time; max_cost + 1]; n];
        let mut is_fixed = vec![vec![false; max_cost + 1]; n];
     
        // heap(所要時間, 所持銀貨, 都市)
        let mut r_heap: BinaryHeap<(Reverse<u64>, usize, usize)> = BinaryHeap::new();
        
        r_heap.push((Reverse(0), s, 0));
        while !r_heap.is_empty() {
            let (Reverse(time), poss, node) = r_heap.pop().unwrap();
            if is_fixed[node][poss] {continue};
            
            // 確定
            for i in 0..poss + 1 {
                if dp[node][i] > time {
                    dp[node][i] = time; 
                    is_fixed[node][i] = true;
                }
            }
     
            // 両替
            let (rate, ex_time) = exchange[node];
            let (exd_poss, exd_time) = (min(poss + rate, max_cost), time + ex_time);
            //if dp[node][exd_poss] > exd_time {
            if !is_fixed[node][exd_poss] {
                r_heap.push((Reverse(exd_time), exd_poss, node));
            }
            
            // 移動
            for next in &graph[node] {
                let next_time = next.time + dp[node][poss];
                if next.cost > poss 
                    || is_fixed[next.node][poss - next.cost] {continue;} 
                //|| dp[next.node][poss - next.cost] < next_time {continue;};
                r_heap.push((Reverse(next_time), poss - next.cost, next.node));
     
            }
        }
     
        let ans: Vec<_> = dp.iter().map(|v| v.iter().min().unwrap()).collect();
        for a in &ans[1..] {
            println!("{}", a);
        }
    }

Measured memory_bytes: 3432
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define lin puts("");
ll n,x,y,a[300000],b[300000],c=0,t=0,sum=0,z=0,i,j,f=0;
char ch[101],cr,ss[101];
string s;
int main()
{
    double m,n,k;
    cin>>m>>n;
    k=(1/(4*n));

    rep(i,0,m-1)
    {
        cin>>a[i];
        sum+=a[i];
    }
    k=k*sum;
    rep(i,0,m-1)
    {
        if(a[i]>=k)
            c++;
    }
            if(c>=n)
                cout<<"Yes";
            else
                cout<<"No";
    return 0;
}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	double a[n+1];
	string s[n+1];
	double ans;
	for(int i=1;i<=n;i++){
		cin>>a[i]>>s[i];
		if(s[i]=="JPY"){
			ans+=a[i]*1.0;
		}else{
			ans+=a[i]*1.0*380000;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long int a,b,c;
  cin>>a>>b>>c;
  if(c<a)cout<<a-c<<" "<<b;
  else if(c>b+a)cout<<0<<" "<<0;
  else cout<<0<<" "<<b+a-c;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N,D=mi()
    ans = 0
    for i in range(N):
        x,y=mi()
        if x**2+y**2 <= D**2:
            ans += 1

    print(ans)





if __name__ == "__main__":
    main()

Measured memory_bytes: 69856
//#if 1
//#include"pch.h"
//#define _CRT_SECURE_NO_WARNINGS
//#endif
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main() {
	int N, K;
	int h[100000];
	int min = 1e9, tmp;
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> h[i];
	}
	sort(h, h + N);
	for (int i = 0; i < N; i++) {
		if (i + K - 1 == N)break;
		tmp = h[i + K - 1] - h[i];
		min = (min > tmp) ? tmp : min;
	}
	cout << min << endl;



	return(0);
}

Measured memory_bytes: 640
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void *a, const void *b) {
	return *((size_t *)a) < *((size_t *)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static size_t gcdST(size_t m, size_t n) {
	size_t temp;

	while (m%n != 0) {
		temp = n;
		n = m % n;
		m = temp;
	}

	return n;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
	uint64_t temp;

	while (m%n != 0) {
		temp = n;
		n = m % n;
		m = temp;
	}

	return n;
}

int main(void) {
	size_t N;
	size_t result = 1;

	scanf("%zu\n", &N);
	for (size_t i = 0; i < N; i++) {
		size_t A;

		scanf("%zu", &A);
		if (i < N - 1) {
			scanf(" ");
		}

		result = (i == 0) ? A : gcdST(result, A);
	}

	printf("%zu\n", result);

	return 0;
}


Measured memory_bytes: 128
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>
#include <numeric>

using namespace std;


typedef long long ll;
const int maxn = (int) 1e5 + 1;
const int inf = (int)1e9+7;


int m ,b[1111], u[1111], p[1111], a[1111];

int c[1111][13];

int cnt[maxn];

string s, t;

int ans = 0, sum1, sum2, sum3;

ll n, k;

int dp[(1 << 13)];
int main(){
    cin >> n >> m;
    for(int i = 1; i <= m; i++){
        cin >> a[i] >> b[i];
        for(int j = 1; j <= b[i]; j++){
            cin >> c[i][j];
        }
    }
    fill(dp, dp + (1<<12), inf);
    dp[0] = 0;
    for(int mask = 1; mask < (1 << n); mask++){
        for(int i = 1; i <= m; i++){
            int nmask = mask;
            for(int j = 1; j <= b[i]; j++){
                if((nmask >> (c[i][j] - 1)) & 1){
                    nmask &= ~(1 << c[i][j] - 1);
                }
            }
            /*for(int j = 0; j <= nmask; j++){
                cout << ((nmask >> j) % 2);
            }*/
            dp[mask] = min(dp[mask], dp[nmask] + a[i]);
        }
        //cout << dp[mask] << endl;
    }
    if(dp[(1 << n) - 1] == inf){
        cout << -1;
        return 0;
    }
    cout << dp[(1 << n) - 1];
    return 0;
}


Measured memory_bytes: 384
N = int(input())
A = list(map(int,input().split()))
C = [0]*N
a=0
def line(A,N):
    for i in range(N):
        C[A[i]] += 1
    if C[0] == 1:
        if N % 2==1:
            return pow(2,(N-1)//2)
        else:
            return 0
    for i in range(N):
        if C[i] != 2 and C[i]>=1:
            return 0
        elif C[i]==0:
            continue
    if N % 2 ==0:
        return pow(2,N//2)
    else:
        return pow(2,(N-1)//2)
a=line(A,N)
print(a%(pow(10,9)+7))


Measured memory_bytes: 14008
N = int(input())
S = input()

l_blacks = 0
r_whites = 0

for c in S:
    if c == '.':
        r_whites += 1

mins = r_whites
for c in S:
    if c == '.':
        r_whites -= 1
    if c == '#':
        l_blacks += 1
    mins = min(mins, r_whites + l_blacks)
print(mins)

Measured memory_bytes: 9104
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using P = pair<ll, ll>;

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f){
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

//---------------------------

ll MAX = 100010; 
set<ll> lun{1,2,3,4,5,6,7,8,9};
set<ll> tmp;

void search(int d){
    for(auto x : lun){
        int len = to_string(x).size();
        int tail = to_string(x)[len-1] - '0';
        if(abs(d-tail) <= 1){
            ll out = x*10 + d;
            tmp.insert(out);
        }
    }
}

int main(){
    ll k;
    cin >> k;

    ll num = lun.size();
    while(num <= MAX){
        tmp = {};
        rep(i,10){
            search(i);
        }
        for(auto x : tmp){
            lun.insert(x);
        }
        num = lun.size();
    }

    auto itr = lun.begin();
    // cout << lun.size() << endl;
    rep(i,k-1){
        ++itr;
        // if(i < 120) cout << *itr << " ";
    }
    // cout << endl;
    cout << *itr << endl;

    return 0;
}

Measured memory_bytes: 18944
N,K=map(int,input().split())
*P,=map(int,input().split())

ans=(sum(P[:K])+K)/2
now=ans
i=K
while i<N:
    now=now+(P[i]+1)/2-(P[i-K]+1)/2
    ans=max(now,ans)
    i+=1

print(ans)

Measured memory_bytes: 31952
#include <vector>
#include <iostream>
using namespace std;
vector<int> adj[200100];
int c[200100];
long long ans[200100];

void dfs(int i, int p, int acc = 0) {
    acc += c[i];
    for (int j : adj[i]) {
        if (j != p) dfs(j, i, acc);
    }
    ans[i] = acc;
}

int main() {
    int n, q; cin >> n >> q;
    for (int i = 1; i < n; i++) {
        int a, b; cin >> a >> b;
        a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    while (q--) {
        int p, x; cin >> p >> x;
        c[p-1] += x;
    }
    dfs(0, -1);
    for (int i = 0; i < n; i++) cout << ans[i] << ' ';
}


Measured memory_bytes: 27904
<?php
$N = (int)fgets(STDIN);
$S = fgets(STDIN);

$memo = [];
$memo['R'] = [];
$memo['G'] = [];
$memo['B'] = [];
for ($i = 0; $i < $N; $i++) {
    $memo[$S[$i]][$i] = $i;
}

$remove = 0;
foreach ($memo['R'] as $r) {
    foreach ($memo['G'] as $g) {
        if (($r + $g) % 2 === 0 && isset($memo['B'][($r + $g) / 2])) {
            $remove += 1;
        }
        if (isset($memo['B'][2 * $r - $g])) {
            $remove += 1;
        }
        if (isset($memo['B'][2 * $g - $r])) {
            $remove += 1;
        }
    }
}
echo count($memo['R']) * count($memo['G']) * count($memo['B']) - $remove;

Measured memory_bytes: 16288
import java.util.Scanner;


public class Main{
	public static long Knapsack(int W,int n,long[]w,long[]v){
		int i;int j = 0;
		long[][] k=new long[n+1][W+1];
		for(i=0;i<=n;i++){
			for(j=0;j<=W;j++){
		        if(i==0||j==0){
			        k[i][j]= 0;
		        }else{
		        	if(w[i-1]>j){
		        		k[i][j]=k[i-1][j];
		        	}else{
		        		k[i][j]=Math.max(v[i-1]+k[i-1][(int) (j-w[i-1])],k[i-1][j] );
		        	}
		        }
			}
		}return k[i-1][j-1];
	}
	public static void main(String[]args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int W=sc.nextInt();
		long []v=new long[n];
		long []w=new long[n];
		for(int i=0;i<n;i++){
			w[i]=sc.nextLong();
			v[i]=sc.nextLong();
		}
		System.out.print(Knapsack(W,n,w,v));
	}
}


Measured memory_bytes: 127956
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define sz(x) (int)(x.size())
#define mod 1000000007

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

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;

bool check(int m, int d){
    if(d<10){
        return false;
    }
    else{
        int d1=d%10;
        int d2=d/10;
        if(d1>=2 && d2>=2 && ((d1*d2)==m )){
            return true;
        }
        else{
            return false;
        }
    }
}

int32_t main(){
    ios::sync_with_stdio(false);
    int m, d;
    cin>>m>>d;
    int ans=0;
    for(int i=1;i<=m;i++){
        for(int j=1;j<=d;j++){
            if(check(i,j)){
                ans++;
            }
        }
    }
    cout<<ans<<"\n";



    return 0;
}

Measured memory_bytes: 764
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int X = sc.nextInt();
    int ans = 1;
    int loop = 0;
    for (int i=0;i<N;i++){
      loop += sc.nextInt();
      if (loop > X){
        break;
      }else{
        ans++;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 22996
#include <iostream>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
if(1<=a<=13 &&1<=b<=13){
if(a==b){
    cout<<"Draw \n";
}
else if(a==1 ||a>b ){
   if(b!=1){
    cout<<"Alice \n";
}
   else{
    cout<<"Bob \n";
}
}
 else if(b==1 || a<b ){
   if (a!=1){
    cout<<"Bob \n";
}
   else{
    cout<<"Alice \n";
}
}
}
}


Measured memory_bytes: 256
A = list(input())
B = list(input())
C = list(input())

n = A.pop(0)
while True:
  if n == 'a':
    if A == []:
      print('A')
      break
    n = A.pop(0)
  elif n == 'b':
    if B == []:
      print('B')
      break
    n = B.pop(0)
  else:
    if C == []:
      print('C')
      break
    n = C.pop(0)


Measured memory_bytes: 3060
import Control.Applicative
import Control.Monad
import Data.List

main :: IO ()
main = do
    as <- getLine
    bs <- getLine
    case length as `compare` length bs of
        LT -> putStrLn "LESS"
        EQ -> case as `compare` bs of
            LT -> putStrLn "LESS"
            EQ -> putStrLn "EQUAL"
            GT -> putStrLn "GREATER"
        GT -> putStrLn "GREATER"

Measured memory_bytes: 508
import math

def prime(n):
    if n==1:
        return False
    if n==2:
        return True
    if n%2==0:
        return False
    for i in range(3,math.ceil(n**0.5)+1,2):
        if n%i==0:
            return False
    
    return True

X=int(input())
while True:
    if prime(X):
        print(X)
        break
    else:
        X+=1

Measured memory_bytes: 9424
N = int(input())
d = {}
total = 0
for _ in range(N):
    a, b = map(int, input().split())
    d[b] = d.get(b, 0) + a
for t, c in sorted(d.items()):
    total += c
    if total > t:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 41540
# -*- coding: utf-8 -*-
"""
E - Double Factorial
https://atcoder.jp/contests/abc148/tasks/abc148_e

"""
import sys


def solve(N):
    if N % 2:
        return 0
    ans, d = 0, 10
    while True:
        q = N // d
        ans += q
        if q == 0:
            return ans
        d *= 5


def main(args):
    N = int(input())
    ans = solve(N)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N,M; cin >> N >> M;
    map<char,int> m;
    string S="1";
    rep(i,N-1){
        S+='0';
    }
    if(N==1) S="0";
    bool can=true;
    rep(i,M){
        int a,b; cin >> a >> b;
        if(m[a]){
            if(m[a]!=b) can=false;
        }
        else {
            S[a-1]=(char)('0'+b);
            m[a]=b;
        }
    }
    if(can){
        if(N!=1 && S[0]=='0') cout << -1 << endl;
        else cout << S << endl;
    }
    else {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 256
def sameAllMenber(str):
	number = int(str[0])
	for i in str[1:] :
		if number != int(i):
			return False
	return True


n = input()
if len(n) >= 3 and (sameAllMenber(n[1:]) or sameAllMenber(n[:3])):
	print("Yes")
else:
	print("No")


Measured memory_bytes: 2940
from itertools import combinations

def getval():
    n,m = map(int,input().split())
    s = [list(map(int,input().split())) for i in range(m)]
    for i in range(m):
        for j in range(1,s[i][0]+1):
            s[i][j] -= 1
    p = list(map(int,input().split()))
    return n,m,s,p 

def main(n,m,s,p):
    l = [[] for i in range(n)]
    for i in range(m):
        for j in range(1,s[i][0]+1):
            l[s[i][j]].append(i)
    ans = 0
    for i in range(n+1):
        for c in combinations(range(n),i):
            temp = [0 for i in range(m)]
            for j in c:
                for k in l[j]:
                    temp[k] += 1
                    temp[k] %= 2
            if temp==p:
                ans += 1
    print(ans)

if __name__=="__main__":
    n,m,s,p = getval()
    main(n,m,s,p)

Measured memory_bytes: 73916
n = int(input())
p = list(map(float, input().split()))

dp = [[0]*(n+1) for i in range(n+1)]
dp[0][0] = 1
for i in range(n):
    for j in range(n+1):
        if j-1 < 0:
            dp[i+1][j] = (1 - p[i]) * dp[i][j]
        else:
            dp[i+1][j] = p[i] * dp[i][j-1] + (1 - p[i]) * dp[i][j]

print(sum(dp[n][(n+1)//2:]))

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  vector<int> ab(n);
  for(int i=0;i<n;i++){
    ab[i]=max(0,a[i]);
  }
  vector<LL> ruisekia(n+1),ruisekiab(n+1);
  ruisekia[0]=ruisekiab[0]=0;
  for(int i=1;i<=n;i++){
    ruisekia[i]+=ruisekia[i-1]+a[i-1];
    ruisekiab[i]+=ruisekiab[i-1]+ab[i-1];
    // cout << ruisekia[i] << " " << ruisekiab[i] << endl;
  }
  LL ans=-1000000000000000000;
  for(int i=k;i<=n;i++){
    ans=max(ans,max(0,ruisekia[i]-ruisekia[i-k])+ruisekiab[n]-ruisekiab[i]+ruisekiab[i-k]);
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

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

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>

//関数宣言
//int func(int x, int y);

int main(void){

  //スカラー入力
  int N,K;

  scanf("%d %d", &N, &K);

  printf("%d\n", N-K+1);

  return 0;
}


Measured memory_bytes: 128
# DP(配るDP)
INF = float('inf')

N = int(input())

c = [1]
t = 6
while t <= N:
    c.append(t)
    t *= 6
t = 9
while t <= N:
    c.append(t)
    t *= 9

dp = [INF] * (N + 1)
dp[0] = 0
for i in range(N):
    for j in c:
        if i + j <= N:
            dp[i + j] = min(dp[i + j], dp[i] + 1)
        if i + j == N:
            break
print(dp[N])


Measured memory_bytes: 3828
package main

import "fmt"

func main() {
	var c [3][3]int
	for i := 0; i < 3; i++ {
		for j := 0; j< 3; j++ {
			fmt.Scan(&c[i][j])
		}
	}

	var a [3]int
	var b [3]int
	for i := 0; i < 3; i++ {
		b[i] = c[0][i] - a[0]
	}

	for i := 0; i < 3; i++ {
		a[i] = c[i][0] - b[0]
	}

	for i := 0; i < 3; i++ {
		for j := 0; j < 3; j++ {
			if a[i]+b[j] != c[i][j] {
				fmt.Println("No")
				return

			}
		}
	}
	fmt.Println("Yes")
}


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

int main(void){

    int n,k,i,l;
    int x[100000];
    int min=1000000000,kari;

    scanf("%d%d",&n,&k);
    for(i=0;i<n;i++){
        scanf("%d",&x[i]);
    }

    for(l=0;l<=n-k;l++){
        if(abs(x[l])<abs(x[l+k-1])){
            kari=abs(x[l])+abs(x[l+k-1]-x[l]);
        }else{
            kari=abs(x[l+k-1])+abs(x[l+k-1]-x[l]);
        }

        if(min > kari)
        min=kari;
    }
    printf("%d",min);
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define Pr(a) (#a)<<"="<<(a)<<" "
#define pr1(a) cerr<<Pr(a)<<endl
#define pr2(a,b) cerr<<Pr(a)<<Pr(b)<<endl
#define pr3(a,b,c) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<endl
#define pr4(a,b,c,d) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<endl
#define pr5(a,b,c,d,e) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<Pr(e)<<endl
#define pr6(a,b,c,d,e,f) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<Pr(e)<<Pr(f)<<endl
#define int long long
#define double long double
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  deque<int> A;
  int q;
  cin>>q;
  while(q--){
    int cmd;
    cin>>cmd;
    if(cmd == 0){
      int d,x;
      cin>>d>>x;
      if(d == 0) A.insert(A.begin(), x);
      else A.push_back(x);
    }
    if(cmd == 1){
      int p;
      cin>>p;
      cout<<A[p]<<endl;
    }
    if(cmd ==2){
      int d;
      cin>>d;
      if(d==0) A.erase(A.begin());
      else A.pop_back();
    }

  }
  return 0;
}



Measured memory_bytes: 6244
# import bisect
from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():

    S=list(input())
    T=list(input())

    sc=Counter(S)
    tc=Counter(T)

    sl,tl=[],[]
    for i in sc.values():
        sl.append(i)

    for i in tc.values():
        tl.append(i)

    if sorted(sl)==sorted(tl):
        print('Yes')
    else:
        print('No')





resolve()

Measured memory_bytes: 70220
#include "bits/stdc++.h"
using namespace std;
int f(int n) {
	if (n % 2 == 0)
	{
		return n / 2;
	} 
	else {
		return 3 * n + 1;
	}
}
int main() {
	int A;
	cin >> A;
	int i = 1;
	while (A != 4 && A != 2 && A != 1) {
		A = f(A);
		i++;
	}
	cout << i + 3 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
#include<cassert>
#include<algorithm>
using namespace std;

typedef unsigned long long llong;

void factorize( llong x, vector<llong> &factors ){
    llong d, q;
    while ( x >= 4 && x % 2 == 0 ) {
	factors.push_back(2);
	x /= 2;
    }
    d = 3; q = x / d;
    while ( q >= d ){
	if ( x % d == 0 ) {
	    factors.push_back(d);
	    x = q;
	} else {
	    d += 2;
	}
	q = x / d;
    }
    factors.push_back(x);
}

void rec(int p, llong d, vector<llong> &divisors, vector<pair<llong, llong> > &factpairs, llong n){
    if ( p == factpairs.size() ){
	assert( d <= n );
	divisors.push_back(d);
	return;
    }

    llong v = d;
    for ( int i = 0; i <= factpairs[p].second; i++ ){
	rec(p+1, v, divisors, factpairs, n);
	v *= factpairs[p].first;
	//	cout << v << endl;
    }
}



llong gcd( llong x, llong y ){
    llong r;

    if ( x < y ) swap( x, y ); 
    
    while ( y > 0 ){
        r = x % y;
        x = y;
        y = r;
    }

    return x;
}

llong lcm( llong x, llong y ){
    return (x/gcd(x,y))*y;
}

int compute(llong n){
    vector<llong> factors;
    vector<pair<llong, llong> > factpairs;

    factorize(n, factors);
    if ( factors.size() > 0 ) factpairs.push_back(make_pair(factors[0], 1));
    for ( int i = 1; i < factors.size(); i++ ){
	if( factpairs[factpairs.size()-1].first == factors[i] ){
	    factpairs[factpairs.size()-1].second++;
	} else {
	    factpairs.push_back(make_pair(factors[i], 1));
	}
    }
    

    vector<llong> divisors;
    rec(0, 1, divisors, factpairs, n);
    
    if ( divisors.size() >= 2 && divisors[0] == 1 && divisors[1] == 1 ){
	divisors.erase(divisors.begin());
    }


    sort(divisors.begin(), divisors.end());
 


    int cnt = 0;
    for ( int i = 0; i < divisors.size(); i++ ){
	for ( int j = i; j < divisors.size(); j++ ){
	     if ( gcd(divisors[i], divisors[j] ) == 1 ){
		cnt++;
	    }
	}
    }
    return cnt;
}

main(){
    llong n;
    while(1){
	cin >> n;
	if ( n == 0 ) break;

	cout << compute(n) << endl;
    }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=2e5+100;
bool piln(int x){
    int ans=0;
    int m=x;
    while (x){
        ans=ans*10+x%10;
        x/=10;
    }
    return (ans==m);
}
int main()
{
    FASTINOUT;
    int a,b;
    cin>>a>>b;
    int ans=0;
    for (int i=a;i<=b;i++){
        if (piln(i))
            ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
use proconio::input;
use proconio::marker::{Chars, Usize1};
use std::iter::Iterator;
use std::collections::*;
use std::cmp::*;
use itertools::Itertools;

#[allow(unused_macros)]
macro_rules! max {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      max($x,max!($($xs)+))
    };
  }
  
  #[allow(unused_macros)]
  macro_rules! min {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      min($x,min!($($xs)+))
    };
  }

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
    n: usize,
    mut a: [i64; n],
    }

    let mut dp = vec![0;n+1];
    dp[0] = 1000;

    for i in 0..n-1 {
      if a[i] < a[i+1]{
        let cnt = dp[i] / a[i];
        let amari = dp[i] % a[i];
        dp[i + 1] =  a[i + 1] * cnt + amari; 
      }else{
        dp[i+1] = dp[i];
      }
      
      debug!(dp);
    }
     println!("{}", dp[n-1]);
}


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


int main(){
	int a, b, n;
	int s;

	while(s = 0, cin >> a >> b >> n){
		for(int i = 0;i < n;i++){
			a *= 10;
			s += ((int)(a / b)) % 10;
			a %= b;
		}
		cout << s << endl;
	}

	return 0;
}

Measured memory_bytes: 2980
S = str(input())
S_list = list(S)
S_switch = []

for i in range(len(S_list)):
    if S_list[i]=="T" or S_list[i]=="A" or S_list[i]=="G" or S_list[i]=="C":
        S_switch.append(1)
    else:
        S_switch.append(0)

count = 0
max_count = 0
for i in range(len(S_switch)):
    if S_switch[i] == 1:
        count = count + 1
    else:
        if count > max_count:
            max_count = count
        count = 0

if count > max_count:
    max_count = count
count = 0

print(max_count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int> > piii;
#define pb push_back
#define NeedForSpeed ios_base::sync_with_stdio(0), cin.tie(0)
#define PI acos(-1)
#define all(c) c.begin(), c.end()
#define SET(x, y) memset((x), y, sizeof(x))
const int MOD = 1e9 + 7;
const int INF = 1e9 + 5;
const ll INF64 = 1e18;

template <typename T>
string to_string(const vector<T> &v) {
  string ret = "<";
  for (auto it : v)
    ret += to_string(it) + ", ";
  ret.pop_back(); ret.pop_back();
  ret += ">";
  return ret;
}

string to_string(const string &s) {
  return '"' + s + '"';
}

string to_string(bool b) {
  return b ? "true" : "false";
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

void debug_print() { cerr << endl; }

template <typename T, typename ...U>
void debug_print(T t, U... u) {
  cerr << " " << to_string(t);
  debug_print(u...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_print(__VA_ARGS__)
const int N = 1e5 + 5;

vector<ll> v;

int main() {
  ll n;
  cin >> n;
  v.resize(n);
  for (auto &it : v)
    cin >> it;
  ll ans = 0ll;
  ll cur = v.back();
  for (int i = n - 2; i >= 0; i--) {
    ans = (ans + (cur * v[i]) % MOD) % MOD;
    cur = (cur + v[i]) % MOD;
  }
  cout << ans << '\n';
  //If you dont need Flush Stream, dont use endl
  return 0;
}


Measured memory_bytes: 4840
use proconio::{fastout, input};

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[fastout]
fn main() {
    input! {
        n: u32,
    }

    let sn: u32 = n.to_string().chars().map(|a| a.to_digit(10).unwrap()).sum();
    let ans = if n % sn == 0 { "Yes" } else { "No" };
    println!("{}", ans);
}


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

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


    string s="";
    string z="";
    for(int i=1;i<=a;i++)
        s+=b+'0';

    for(int i=1;i<=b;i++)
        z+=a+'0';

    set<string>st;

    st.insert(s);
    st.insert(z);

    set<string>::iterator it;

    it=st.begin();


    cout<<*it<<endl;

    

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

// 入力
int N;
long long a[100010][3]; // a[i], b[i], c[i] をそれぞれまとめて a[i][0], a[i][1], a[i][2] にしてしまう

// DP テーブル
long long dp[100010][3];

int main() {
    int N; cin >> N;
    for (int i = 0; i < N; ++i) for (int j = 0; j < 3; ++j) cin >> a[i][j];

    // 初期化は既に 0 に初期化される
    // 初期条件も既に 0 で OK

    // ループ
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 3; ++j) {     //i日目の遊びの種類
            for (int k = 0; k < 3; ++k) { //i+1日目の遊びの種類
                if (j == k) continue;
                // iからi+1日目への遷移を考える。
                chmax(dp[i + 1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    // N日目にどの遊びをするとmaxとなるか
    long long res = 0;
    for (int j = 0; j < 3; ++j) chmax(res, dp[N][j]);
    cout << res << endl;
}

Measured memory_bytes: 8268
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>




using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const int INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 1000 * 1000 * 1000 + 7;


void solve() {
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int s = 0;
    for (int i = 0; i < n; ++i) {
        s += a[i];
        if (s > x) {
            cout << i << endl;
            return;

        }
    }
    if (s == x)
        cout << n << endl;
    else
        cout << n - 1 << endl;
    
}

//#define LOCAL

int main() {
    ios_base::sync_with_stdio(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    solve();


#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif	
    return 0;
}

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

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

const int mod = 1000000007;
const int inf = 1000000007;

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


Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

int main()
{
    long long A,B,N,ans,r;
    cin>>A>>B>>N;
    if(N<B){
        ans=(A*N)/B;
    }else{
        ans=(A*(B-1))/B;
    }
    cout<<ans<<endl;
}

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

class Main {
  public static void main(String[] args) throws Exception{
    try (Scanner sc = new Scanner(System.in)){
      int N = sc.nextInt();
      int x = sc.nextInt();
      int[] arr = new int[N];
      for (int i = 0; i < N; i++) {
        arr[i] = sc.nextInt();
      }
      Arrays.sort(arr);
      int count = 0;
      int i = 0;
      while (i < N && x - arr[i] >= 0) {
        count++;
        x -= arr[i];
        i++;
      }
      if (i == N || i == 0) {
        if (x > 0) {
          count--;
        }
      } else {
        if (x + arr[i-1] == arr[i]) {
          count--;
        }
      }


      if (count < 0) count = 0;
      System.out.println(count);
    }
  }
}


Measured memory_bytes: 22740
n=int(input())
h=[int(i) for i in input().split()]
dp=[0 for i in range(n)]
for i in range(n):
    if i==n-1:
        dp[i]=0
    else:
        if h[i]>=h[i+1]:
            dp[i]=1
# print(dp)
newlist=[0 for i in range(n)]
for i in range(n):
    i=n-i-1
    if dp[i]==0:
        newlist[i]==0
    else:
        newlist[i]=1+newlist[i+1]
print(max(newlist))

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

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

    
    long long r=0;
    long long g=0;
    long long b=0;
    for(int i=0;i<n;i++)
    {
      if(s[i]=='R')
        r++;
      if(s[i]=='G')
        g++;
      if(s[i]=='B')
        b++;
    
    }    
    
    long long ans=r*g*b;
    
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(j+i+i>n-1)
              break;
            if(s[j]!=s[j+i] and s[j+i]!=s[j+i+i] and s[j]!=s[j+i+i])
               ans--;
        }
        
    }
    
    
    // ans=-1;
    
    

    cout<<ans<<"\n";
    
    
}

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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
#define maxn 200001
typedef pair<pi,int> pii;
int N;
int A[maxn],B[maxn];

int main(){
	fast;
	
	cin>>N;
	vi vect;
	FOR(i,0,N-1){
		cin>>A[i]>>B[i];
	}
	
	sort(A,A+N);
	sort(B,B+N);
	
	if (N % 2 == 0) cout<< 1 - A[N/2 - 1] - A[N/2] + B[N/2 - 1] + B[N/2];
	else cout<<B[N/2] - A[N/2] + 1;
	
	
}



Measured memory_bytes: 5176
#include<bits/stdc++.h>
using namespace std;
const long long INFdesu=2E10;

int main(){
    string S;
    long long K;
    cin >> S >> K;
    int i;
    for(i=0;i<S.size();i++){
        if(S[i]!='1')break;
    }
    int ans;
    if(K<i+1) cout << 1 << endl;
    else cout << S[i] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
typedef long long ll;

using ipair = pair<int, int>;

ll INF = 1e16+7;
ll mod = 1e9+7;

bool operator>(const ipair a,const ipair b){return a.first > b.first;}

pair<vector<char>, vector<int>> compress(string str){
  vector<char> vect_char;
  vector<int> vect_cnt;

  int tmp_cnt = 0;
  int tmp_char;
  rep(i, sz(str)){
    if(i==0){
      tmp_cnt++;
      tmp_char = str[i];
      continue;
    }

    if(tmp_char != str[i]){
      vect_char.push_back(tmp_char);
      vect_cnt.push_back(tmp_cnt);
      tmp_char = str[i];
      tmp_cnt = 1;
    }else{
      tmp_cnt++;
    }
  }

  vect_char.push_back(tmp_char);
  vect_cnt.push_back(tmp_cnt);

  return make_pair(vect_char, vect_cnt);
}

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

  pair<vector<char>, vector<int>> s_p = compress(S);
  pair<vector<char>, vector<int>> t_p = compress(T);

  // 数
  if(sz(s_p.second) != sz(t_p.second)){
    cout << "No" << endl;
    return 0;
  }
  rep(i, sz(s_p.second)){
    if(s_p.second[i] != t_p.second[i]){
      cout << "No" << endl;
      return 0;
    }
  }

  // 文字
  if(sz(s_p.first) != sz(t_p.first)){
    cout << "No" << endl;
    return 0;
  }

  // s_p, t_p
  map<char, char> mp;
  rep(i, sz(s_p.first)){
    if(mp.count(s_p.first[i]) != 0){
      if(mp[s_p.first[i]] != t_p.first[i]){
        cout << "No" << endl;
        return 0;
      }
    }else{
      mp[s_p.first[i]] = t_p.first[i];
    }
  }

  mp.clear();
  rep(i, sz(t_p.first)){
    if(mp.count(t_p.first[i]) != 0){
      if(mp[t_p.first[i]] != s_p.first[i]){
        cout << "No" << endl;
        return 0;
      }
    }else{
      mp[t_p.first[i]] = s_p.first[i];
    }
  }

  cout << "Yes" << endl;

  return 0;
}


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

using namespace std;

using ll = long long;

#define bil ((ll)1e9)
#define mod ((ll)1e9+7)

int main(int argc,char* argv[]){
    vector<int> x(5);
    for(auto &a:x)
        cin >> a;
    
    for(int i=0;i<5;i++){
        if(x.at(i)==0){
            cout << i+1 << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
 
 
int a() {
    int d, t, s;
    cin >> d >> t >> s;
    if(d <= (t * s)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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



Measured memory_bytes: 3616
from sys import exit
import math
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n,d = mi()
xy = [list(map(int, input().split())) for i in range(n)]

ans=0

for i in range(n):
    if xy[i][0]**2 + xy[i][1]**2 <= d**2:
        ans += 1

print(ans)


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

public class AtCoderB
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());

        List<Tuple<int, string, int>> scores = new List<Tuple<int, string, int>>();

        for (int i = 0; i < n; i++)
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            scores.Add(new Tuple<int, string, int>(i + 1, words[0], int.Parse(words[1])));
        }

        scores = scores.OrderBy(s => s.Item2).ThenByDescending(s => s.Item3).ToList();

        foreach (var score in scores)
        {
            Console.WriteLine(score.Item1);
        }
    }
}

Measured memory_bytes: 13664
n = int(input())
s = ['']*n
for i in range(n):
  s[i] = (''.join(sorted(input())))
s.sort()

i=0
c=1
ans = 0
while i < n-1:
  while i+c < n and s[i] == s[i+c]:
    c += 1
  else:
    ans += c*(c-1)//2
    i += c
    c = 1

print(ans)

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

int main()
{
	lint N;
	cin >> N;

	lint ans=0;
	for(lint i=1;i*i<=N;i++)
	{
		lint m;
		if(N%i==0)
		{
			m=i-1;
			if(m!=0 && (N/m)==(N%m))
				ans+=m;
			m=N/i-1;
			if(m!=0 && (N/m)==(N%m))
				ans+=m;
		}
	}

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


Measured memory_bytes: 256