akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, T;
  cin >> N >> T;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  vector<int> Cmax(N);
  Cmax[N - 1] = A[N - 1];
  for (int i = N - 2; i >= 0; i--){
    Cmax[i] = max(Cmax[i + 1], A[i]);
  }
  int M = 0;
  /*
  for (int i = 0; i < N; i++){
    cout << Cmax[i] <<  ' ';
  }
  cout << endl;
  */
  for (int i = 0; i < N; i++){
    M = max(M, Cmax[i] - A[i]);
  }
  //cout << M << endl;
  int count = 0;
  for (int i = 0; i < N; i++){
    if (Cmax[i] - A[i] == M){
      count++;
    }
  }
  cout << count << endl;
}

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

int main()
{

	double x1, x2, y1, y2;
	cin >> x1 >> y1 >> x2 >> y2;

	double r = sqrt(pow(x1-x2, 2) + pow(y1-y2, 2));

	//cout << r << endl;
	printf("%.8f", r);
	cout << endl;

    return 0;
}

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

const int MAX = 100000;

bool is_prime(int n) {
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return n != 1;
}

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

    vector<bool> x(MAX + 1, false);
    for (int i = 2; i <= MAX; i++)
    {
        x.at(i) = (is_prime(i) && is_prime((i + 1) / 2));
    }
    
    vector<int> sum(MAX + 2);
    for (int i = 0; i <= MAX; i++)
    {
        sum.at(i + 1) = sum.at(i) + x.at(i);
    }
    

    int l, r;
    for (int i = 0; i < q; i++)
    {
        cin >> l >> r;

        cout << sum.at(r + 1) - sum.at(l) << endl;
    }
    
}


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

int h,w;

int main(){
 while(true){
  cin>>h>>w;
  if(h==0&&w==0){
   break;
  }
  for(int j=0;j<h;j++){
   for( int i=0;i<w;i++){
    cout<<"#";
   }
   cout<<endl;
  }
  cout<<endl;
 }
}

Measured memory_bytes: 1152
using System;
using System.Linq;

namespace A
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			var line = Console.ReadLine().Split().Select(int.Parse).ToArray();
			var a = line[0];
			var b = line[1];
			Console.WriteLine(b % a == 0 ? a + b : b - a);
		}
	}
}

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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}


int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  int ans=0;
  string s;
  cin>>s;
  rep(i,s.size()) if(s[i]=='1') ans++;
  cout<<ans<<endl;
}
///////////////////////////

Measured memory_bytes: 256
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let N: usize = read();
    use std::collections::HashMap;
    let mut starts: HashMap<i32, usize> = HashMap::new();
    let mut ends: HashMap<i32, usize> = HashMap::new();
    for i in 0..N {
        let a: i32 = read();
        let se = starts.entry(i as i32 - a).or_insert(0);
        *se += 1;
        let ee = ends.entry(i as i32 + a).or_insert(0);
        *ee += 1;
    }
    let mut ans = 0;
    for (k, v) in ends {
        match starts.get(&(k)) {
            Some(a) => {
                ans += a * v;
            }
            None => continue,
        }
    }
    println!("{}", ans)
}


Measured memory_bytes: 12976
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      cin.tie(0);
      ios::sync_with_stdio(false);
      
      int n;
    	cin >> n;
    	int count = 0;
    	auto f = [&](int c) {
    		int digit = 0;
    		while(c > 0) {
    			c = c / 10;
    			digit++;
    		}
    		return digit;
    	};
    	for(int i = 1; i <= n; i++) {
    		if(f(i) % 2 != 0) {
    			count++;
    		}
    	}
    	cout << count << endl;
    }

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
typedef long long ll;
const int MAX_N=100;
int N;

struct Vector{
	ll x,y;
	Vector(ll x=0,ll y=0):x(x),y(y){}
	Vector operator + (const Vector &v){
		return Vector(x+v.x,y+v.y);
	}
	Vector operator - (const Vector &v){
		return Vector(x-v.x,y-v.y);
	}
};
typedef Vector Point;
Point hol[MAX_N];
double lb[MAX_N],ub[MAX_N];

int main(){
	cin>>N;
	REP(i,N){
		ll x,y;
		cin>>x>>y;
		hol[i]=Point(x,y);
	}
	REP(i,N){
		vector<double> ang;
		REP(j,N){
			if (i==j) continue;
			Point v=hol[i]-hol[j];
			swap(v.x,v.y);
			v.x*=-1;
			double theta=atan2((double)v.y,(double)v.x);
			if (theta<0.0){
				theta+=2*M_PI;
			}
			ang.push_back(theta);
		}
		sort(ang.begin(),ang.end());
		lb[i]=ang[0],ub[i]=lb[i]+M_PI;
		FOR(j,1,N-1){
			if (ang[j]<=ub[i]){
				lb[i]=ang[j];
			}else{
				ub[i]=min(ub[i],ang[j]-M_PI);
			}
		}
	}
	double s=0;
	REP(i,N){
		s+=max(ub[i]-lb[i],0.0);
	}
	REP(i,N){
		printf("%.8f\n",max(ub[i]-lb[i],0.0)/s);
	}
	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);

        String t, p;
        p = scanner.next();
        int counter = 0;

        while(true){
            t = scanner.next();
            if(t.equals("END_OF_TEXT")) break;

            if(t.equalsIgnoreCase(p)){
                counter ++;
            }
        }
        System.out.println(counter);
    }
}


Measured memory_bytes: 26336
#include <iostream>
#include <vector>

using namespace std;

int w, h;
int cnt;
vector<vector<int>> vvi;

void dfs(int x, int y) {
    vvi[y][x] = 0;
    for (int j = -1; j <= 1; j++) {
        for (int i = -1; i <= 1; i++) {
            if (x+i < 0 || w <= x+i || y+j < 0 || h <= y+j)
                continue;
            if (vvi[y+j][x+i]) {
                dfs(x+i, y+j);
            }
        }
    }
}

int main()
{
    while (cin >> w >> h, w|h) {
        // input
        vvi.clear();
        cnt = 0;
        for (int j = 0; j < h; j++) {
            vector<int> vi;
            for (int i = 0; i < w; i++) {
                int c;
                cin >> c;
                vi.push_back(c);
            }
            vvi.push_back(vi);
        }

        // dfs
        for (int y = 0; y < h; y++) {
            for (int x = 0; x < w; x++) {
                if (vvi[y][x]) {
                    dfs(x, y);
                    cnt++;
                }
            }
        }

        // output
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 3192
# -*- coding: utf-8 -*-
"""
Created on Mon Sep  7 18:05:47 2020

@author: liang
"""

N, K = map(int, input().split())
A = [int(x) for x in input().split()]
visited = [-1]*N
loop = list()

cur = 1
cnt = 0
while visited[cur-1] == -1:
#while True:
    visited[cur-1] = cnt
    loop.append(cur)
    cnt += 1
    cur = A[cur-1]
    if cnt == K:
        print(cur)
        #print(loop)
        break
else:
    #print(loop)
    loop = loop[visited[cur-1]:]
    T = cnt -visited[cur-1]
    #print(loop, T)
    ans = loop[(K - cnt)%T]
    print(ans)

Measured memory_bytes: 31032
import java.util.Scanner;


class Main 
{ 
  public static void main(String[] args)

{
	Scanner stdIn=new Scanner(System.in);
	int a = stdIn.nextInt();
	int b = stdIn.nextInt();
	int c = a*b;
	int d = 2*(a+b);
	System.out.println(c + " " + d);
}
}

Measured memory_bytes: 25784
#include <iostream>
#include <string>
#include <vector>

using namespace std;

struct Card {
  char suite;
  int num;
};

vector<Card> selectionSort(vector<Card> A) {
  for (size_t i = 0; i < A.size() - 1; i++) {
    size_t minj = i;
    for (size_t k = i + 1; k < A.size(); k++) {
      if (A[k].num < A[minj].num) {
        minj = k;
      }
    }
    if (minj != i) {
      swap(A[minj], A[i]);
    }
  }

  return A;
}

vector<Card> bubbleSort(vector<Card> A) {
  bool flag = true;

  while (flag) {
    flag = false;
    for (size_t k = A.size() - 1; k > 0; --k) {
      if (A[k].num < A[k - 1].num) {
        swap(A[k], A[k - 1]);
        flag = true;
      }
    }
  }

  return A;
}

void printCards(vector<Card> v) {
  for (size_t i = 0; i < v.size(); i++) {
    if (i > 0) cout << " ";
    cout << v[i].suite << v[i].num;
  }
  cout << endl;
}

bool isStable(vector<Card> original, vector<Card> sorted) {
  for (size_t i = 0; i < sorted.size() - 1; i++) {
    for (size_t j = i + 1; j < sorted.size(); j++) {
      if (sorted[i].num != sorted[j].num) {
        break;
      }

      // Now we know sorted[i].num == sorted[j].num
      // Let's check the original positions of them

      size_t original_i, original_j;
      for (size_t k = 0; k < original.size(); k++) {
        if (sorted[i].suite == original[k].suite && sorted[i].num == original[k].num) {
          original_i = k;
          break;
        }
      }
      for (size_t k = 0; k < original.size(); k++) {
        if (sorted[j].suite == original[k].suite && sorted[j].num == original[k].num) {
          original_j = k;
          break;
        }
      }

      // Because i < j, if original_i > original_j, then it's not stable
      if (original_i > original_j) {
        return false;
      }
    }
  }
  return true;
}

void printStability(vector<Card> original, vector<Card> sorted) {
  if (isStable(original, sorted)) {
    cout << "Stable" << endl;
  } else {
    cout << "Not stable" << endl;
  }
}

int main(int argc, char** argv) {
  vector<Card> A;

  size_t N;
  cin >> N;

  for (size_t i = 0; i < N; i++) {
    Card c;
    cin >> c.suite >> c.num;
    A.push_back(c);
  }
  // printCards(A);

  vector<Card> C = bubbleSort(A);
  printCards(C);
  printStability(A, C);

  vector<Card> B = selectionSort(A);
  printCards(B);
  printStability(A, B);

  return 0;
}



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

int n, Q;
int a[500500];
int bit[500500];
int pre[500500];
void update(int pos, int val){
	while(pos <= n){
		bit[pos] += val;
		pos += (pos & -pos);
	}
}
int query(int pos){
	int sum = 0;
	while(pos > 0){
		sum += bit[pos];
		pos -= (pos & -pos);
	}
	return sum;
}
pair<int, int> qs[500500];
vector<int> q[500500];
int ans[500500];

int main(){
	cin >> n >> Q; 
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 0; i < Q; i++){
		cin >> qs[i].first >> qs[i].second;
		q[qs[i].first].push_back(i);
	}
	memset(pre, -1, sizeof(pre));
	for(int i = n; i >= 1; i--){
		update(i, 1);
		if(pre[a[i]] >= 0) update(pre[a[i]], -1);
		pre[a[i]] = i;
		for(int j = 0; j < q[i].size(); j++){
			ans[q[i][j]] = query(qs[q[i][j]].second);
		}
	}
	for(int i = 0; i < Q; i++) cout << ans[i] << endl;
	return 0;
} 

Measured memory_bytes: 36220
#include <bits/stdc++.h>
using namespace std;
 
double p[6], q[6];
 
inline double sq(double x) {
    return x * x;
}
 
double getVal(double P) {
    double ans = 0;
    for(int i = 0; i < 6; ++i) {
        if(P * p[i] > (1 - P) * q[i])
            ans += P * p[i];
        else
            ans += (1 - P) * q[i];
    }
 
    return ans;
}
 
int main() {
 
    for(int i = 0; i < 6; ++i) {
        scanf("%lf", &p[i]);
        p[i] /= 100.0;
    }
 
    for(int i = 0; i < 6; ++i) {
        scanf("%lf", &q[i]);
        q[i] /= 100.0;
    }
 
    double left = 0, right = 1, mid1, mid2;
    double sol = 1;
 
    for(int i = 0; i < 100; ++i) {
        mid1 = left + (right - left) / 3;
        mid2 = right - (right - left) / 3;
 
        double val1 = getVal(mid1), val2 = getVal(mid2);
        sol = min(sol, val1);
        sol = min(sol, val2);
 
        if(val1 < val2) right = mid2;
        else left = mid1;
    }
 
    printf("%.20f\n", sol);
 
    return 0;
}

Measured memory_bytes: 256
from bisect import bisect

X, N = [int(n) for n in input().split()]
if N==0:
    print(X)
else:
    P = sorted([int(n) for n in input().split()])
    if X not in P:
        print(X)
        exit()
    idx = bisect(P, X)
    ans_r = 101
    ans_l = 0
    for i in range(P[idx-1], 101):
        if i not in P:
            ans_r = i
            break
    for j in range(1, P[idx-1]):
        if j not in P:
            ans_l = j
    if abs(X-ans_l) == abs(ans_r-X):
        print(min([ans_l, ans_r]))
    else:
        print(ans_l if abs(X-ans_l) < abs(ans_r-X) else ans_r)


Measured memory_bytes: 9232
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	s := nextStr()
	cnt := 0

	for i := 0; i < 1000; i++ {
		key := fmt.Sprintf("%03d", i)
		// 1桁目探索
		idx1 := -1
		for j := 0; j < n; j++ {
			if s[j] == key[0] {
				idx1 = j
				break
			}
		}
		if idx1 == -1 {
			continue
		}

		// 2桁目探索
		idx2 := -1
		for j := idx1 + 1; j < n; j++ {
			if s[j] == key[1] {
				idx2 = j
				break
			}
		}
		if idx2 == -1 {
			continue
		}

		// 3桁目探索
		for j := idx2 + 1; j < n; j++ {
			if s[j] == key[2] {
				cnt++
				break
			}
		}
	}

	fmt.Println(cnt)

}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1880
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forna(i,a,n) for(int i =a; i < n; i++)
#define fornd(i,a) for (int i = (a)-1; i >= 0; i--)
#define endl '\n'
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);
#define all(x) x.begin(), x.end()
typedef long long int unsigned lliu;
typedef long long int lli;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<lli> vlli;
typedef vector<vi> vvi;
typedef vector<pi> vpi;

int main(){
	fastIO
	int n, k, d;
	cin>>n>>k;
	vi v(n+1);
	int contador=0, aux;
	forn(i, k){
		cin>>d;
		forn(j, d){
			cin>>aux;
			v[aux]=1;
		}
	}
	
	forna(i, 1, n+1){
		if(!v[i])
			contador++;
	}

	cout<<contador<<endl;

	return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

ll A[100010];
ll gcd(ll a, ll b)
{
	if (a < b) swap(a, b);
	if (b == 0) return a;
	else return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
	return a * (b / gcd(a, b));
}

int R[32];
int main()
{
	int N;
	ll M;
	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		int tmp = A[i];
		int cnt = 0;
		while (tmp % 2 == 0) {
			tmp /= 2;
			cnt++;
		}
		R[cnt]++;
	}
	int cnt = 0;
	for (int i = 0; i < 32; i++) {
		if (R[i] > 0) cnt++;
	}
	if (cnt >= 2) {
		cout << 0 << endl;
		return 0;
	}
	ll num = A[0] / 2;
	for (int i = 1; i < N; i++) {
		num = lcm(num, A[i] / 2);
		if (num > M) {
			cout << 0 << endl;
			return 0;
		}
	}
	cout << (M / num + 1) / 2 << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
typedef long long ll;

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

    char S[N];
    scanf("%s", S);

    int ans = 0;
    for(int i = 0; i < N - 2; ++i) {
        if(S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') {
            ans ++;
            i += 2;
        }
    }
    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 1692
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n,sum=0;
	cin>>n;
	for(long long i=1;i<=n;i++){
		if(i%3!=0&&i%5!=0) sum+=i;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template<class T> bool chmin(T& a,T b){if(a>b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b){if(a<b) {a = b; return true;} return false;}
#define all(x) (x).begin(),(x).end()
#define debug(x)  cerr << #x << " = " << (x) << endl;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    ll ans = 0;
    for(int a=1;a<=N;a++){
        ans += (N-1)/a;
    }
    cout << ans << "\n";
}

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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    int a, b, c;
    cin >> a >> b >> c;

    // 処理
    // 出力
    cout << (c >= a && c <= b ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
abilities=sorted(list(map(int,input().split())))
foods=sorted(list(map(int,input().split())),reverse=True)

if sum(abilities)<=k:
  print(0)
  exit()
  
def check(score):
  ret=0
  for a,f in zip(abilities,foods):
    ret+=max(0,(a*f-score+f-1)//f)
  return ret<=k

ok=10**12+1
ng=0
for _ in range(50):
  mid=(ok+ng)//2
  if check(mid):
    ok=mid
  else:
    ng=mid
print(ok)
  
       


Measured memory_bytes: 117376
package main

import "fmt"

type Position struct {
	Time, X, Y int
}

func main() {
	var n int
	fmt.Scan(&n)

	schedule := make([]Position, n)
	for i := 0; i < n; i++ {
		var time, x, y int
		fmt.Scan(&time, &x, &y)
		schedule[i] = Position{Time: time, X: x, Y: y}
	}

	res := true
	position := Position{Time: 0, X: 0, Y: 0}

	for i := 0; i < len(schedule); i++ {
		destination := schedule[i]

		// 移動
		for j := position.Time + 1; j <= destination.Time; j++ {
			position.Time = j
			if position.X != destination.X {
				if position.X < destination.X {
					position.X++
				} else {
					position.X--
				}
			} else if position.Y != destination.Y {
				if position.Y < destination.Y {
					position.Y++
				} else {
					position.Y--
				}
			} else {
				position.X++
			}
		}

		if position.X != destination.X || position.Y != destination.Y {
			res = false
			break
		}
	}

	if res {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	ll N;
	cin >> N;
    vector<ll> A(N);
    rep(i,N){
        cin >>A[i];
    }

    ll tmp_min = N+1;
    ll ans = 0;
    rep(i,N){
        if(tmp_min>=A[i]){
            ++ans;
            tmp_min = A[i];
        }
    }

    cout<<ans<<"\n";

	return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

void Get_Val(int &Ret)
{
	Ret = 0;
	bool Neg(false);
	char ch;
	while (ch = getchar(), (ch > '9' || ch < '0') && ch != '-')
		;
	if (ch == '-')
	{
		Neg = true;
		while (ch = getchar(), ch > '9' || ch < '0')
			;
	}
	do
	{
		(Ret *= 10) += ch - '0';
	}
	while (ch = getchar(), ch >= '0' && ch <= '9');
	Ret = (Neg ? -Ret : Ret);
}

const int Max_N(200050);
const int Max_H(20);

int N, V, H, X[Max_N], D[Max_N];
int L[Max_H][Max_N], R[Max_H][Max_N];

void init()
{
	Get_Val(N), Get_Val(V);
	for (int i = 1;i <= N;++i)
		Get_Val(X[i]);
	for (int i = 2;i <= N;++i)
		D[i] = X[i] - X[i - 1];
	int TV = V;
	while (TV)
		++H, TV >>= 1;
}

void prepare()
{
	for (int i = 1;i <= N;++i)
		L[0][i] = i;
	for (int i = 2, last = 1;i <= N;++i)
	{
		if (D[i] > V)
			last = i;
		L[0][i] = last;
	}
	for (int i = 1;i <= N;++i)
		R[0][i] = i;
	for (int i = N - 1, last = N;i >= 1;--i)
	{
		if (D[i + 1] > V)
			last = i;
		R[0][i] = last;
	}
	for (int j = 1, TV;j <= H;++j)
	{
		TV = (V >> j);
		for (int i = 1;i <= N;++i)
			L[j][i] = R[j][i] = i;
		for (int i = 2, last = 1;i <= N;++i)
		{
			if (D[i] > TV)
				L[j][last] = i - 1, last = i;
			if (i == N)
				L[j][last] = N;
		}
		for (int i = 2;i <= N;++i)
			L[j][i] = max(L[j][i], L[j][i - 1]);
		L[j][N + 1] = L[j][N];
		for (int i = N - 1, last = N;i >= 1;--i)
		{
			if (D[i + 1] > TV)
				R[j][last] = i + 1, last = i;
			if (i == 1)
				R[j][last] = 1;
		}
		for (int i = N - 1;i >= 1;--i)
			R[j][i] = min(R[j][i], R[j][i + 1]);
		R[j][0] = R[j][1];
	}
}

int F[1 << Max_H], G[1 << Max_H], P[Max_N];
void dp()
{
	for (int S = 0;S < (1 << (H + 1));++S)
		F[S] = 0, G[S] = N + 1;
	for (int S = 1;S < (1 << (H + 1));++S)
		for (int j = 0;j <= H;++j)
			if (S & (1 << j))
			{
				F[S] = max(F[S], L[j][F[S - (1 << j)] + 1]);
				G[S] = min(G[S], R[j][G[S - (1 << j)] - 1]);
			}
	int AllS = (1 << (H + 1)) - 1 - 1;
	memset(P, -1, sizeof(P));
	for (int S1 = 0, S2;S1 <= AllS;++S1)
		if ((AllS & S1) == S1)
		{
			S2 = AllS - S1;
			P[G[S2]] = max(P[G[S2]], F[S1]);
		}
	for (int i = 1;i <= N + 1;++i)
		P[i] = max(P[i], P[i - 1]);
}

void work()
{
	for (int i = 1, l, r;i <= N;++i)
	{
		l = L[0][i], r = R[0][i];
		if (P[r + 1] >= l - 1)
			printf("Possible\n");
		else
			printf("Impossible\n");
	}
}

int main()
{
	init();
	prepare();
	dp();
	work();
	return 0;
}

Measured memory_bytes: 44160
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#define ll long long
using namespace std;
int main(){
    string s;
    cin>>s;
    vector<int> ans(s.length());
    int rcnt=0;
    for(int i=0;i<s.length();i++){
        if(s[i]=='R'){
            rcnt++;
        }else{
            int evenr=rcnt/2;
            int oddr=rcnt-evenr;
            ans[i]+=evenr;
            ans[i-1]+=oddr;
            rcnt=0;
        }
    }
    int lcnt=0;
    for(int i=s.length();i>=0;i--){
        if(s[i]=='L'){
            lcnt++;
        }else{
            int evenl=lcnt/2;
            int oddl=lcnt-evenl;
            ans[i]+=evenl;
            ans[i+1]+=oddl;
            lcnt=0;
        }
    }

    for(int i=0;i<ans.size();i++){
        cout<<ans[i]<<" ";
    }
    cout<<endl;
    return 0;
}

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

int main() {
  int N, L;
  std::cin >> N >> L;
  std::vector<std::string> data(N);
  for (int i=0; i<N; i++) {
    std::cin >> data.at(i);
  }
  std::sort(data.begin(), data.end());
  for (int i=0; i<N; i++) {
    std::cout << data.at(i);
  }
  std::cout << std::endl;
}
  

Measured memory_bytes: 256
n,k = map(int,input().split())
p = list(map(int,input().split()))
c = list(map(int,input().split()))

ans=-10**18
for i in range(n):
    start,count=i,1
    val=c[start]
    while p[start]-1 != i:
        start = p[start]-1
        count += 1
        val += c[start]
    start = i
    if val > 0:
        a = (k//count-1)*val
        ans=max(a,ans)
        num=count+k%count
    else:
        a=0
        num=min(k,count)
    for _ in range(num):
        a += c[start]
        start=p[start]-1
        ans=max(a,ans)
print(ans)

Measured memory_bytes: 74036
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

struct Edge
{
	int from;
	int to;
	ll cost;
};

bool calcShortest(vector<Edge>& list, int s, int maxV, vector<ll>& d)
{
	for (auto i = 0; i < maxV; ++i)
	{
		d.push_back(LLONG_MAX);
	}
	d[s] = 0;

	auto isLoop = false;
	for (auto i = 0; i <= 2 * maxV; ++i)
	{
		auto isUpdate = false;
		for (auto& e : list)
		{
			if (d[e.from] < LLONG_MAX && d[e.to] > d[e.from] + e.cost)
			{
				d[e.to] = d[e.from] + e.cost;
				isUpdate = true;
				if (i >= maxV && e.to == maxV - 1)
				{
					isLoop = true;
				}
			}
		}
		if (!isUpdate)
		{
			break;
		}
	}

	return isLoop;
}


int main()
{
	int N, M;
	cin >> N >> M;

	vector<Edge> list;
	for (auto i = 0; i < M; ++i)
	{
		int a, b;
		ll c;
		cin >> a >> b >> c;
		--a;
		--b;
		list.push_back({ a, b, -c });
	}

	vector<ll> d;
	if (calcShortest(list, 0, N, d) != false)
	{
		cout << "inf" << endl;
	}
	else
	{
		cout << -d[N - 1] << endl;
	}

	return 0;
}

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

int main() {
  int N, sum=0;
  cin >> N;
 vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin >> vec.at(i);
  }
  for(int x:vec){
   for(int y:vec){
     sum += x*y;
   }
  }
  for(int x:vec){
    sum -= x*x;
  }
  sum /=2;
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;
using ll=long long;


int main() {
  int n;cin >> n;
  string p,q;
  rep(i,n){char x;cin >> x;p.pb(x);}
  rep(i,n){char y;cin >> y;q.pb(y);}
  int a=0;
  int b=0;
  do {a++;}
  while(next_permutation(ALL(p)));
  do {b++;}
  while(next_permutation(ALL(q)));

  cout <<abs(a-b);
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;


long long int N, M, K, H, W, L, R;

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

	cin >> N >> M >> L >> R;
	K = N + M + L + R;
	cout << K / 60 << endl << K % 60 << endl;
	return 0;
}


Measured memory_bytes: 3144
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9

def main():
    a,b,k = map(int,input().split())

    num = min(a,k)
    a -= num
    k -= num
    b -= min(b,k)
    print(a,b)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    String A = S.substring(0,2);
    String B = S.substring(2,4);
    int AA = Integer.parseInt(A);
    int BB = Integer.parseInt(B);
    if(AA >=1 && AA <= 12) {
      if(BB >=1 && BB <= 12) {
        System.out.println("AMBIGUOUS");
      } else {
        System.out.println("MMYY");
      }
    } else {
      if (BB >=1 && BB <= 12) {
        System.out.println("YYMM");
      } else {
        System.out.println("NA");
      }
    }      
  }
}

Measured memory_bytes: 20948
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define print(v) for(auto &z:v) cout<<z<<' ';cout<<'\n'
#define db cout<<"db: "
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define all(v) v.B,v.E
#define sz(v) (int)((v).size())
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define clk1 clock_t start_time=clock()
#define clk2 cout<<(clock()-start_time)/(double)CLOCKS_PER_SEC
#define clean(arr) memset(arr,0,sizeof(arr))
#define mod 1000000007
#define mod2 998244353
#define space 100005
//<<fixed << setprecision(9)

int main()
{
    int n,i,j,t;
    boost;

    int arr[5];
    
    rep(i,0,5)cin>>arr[i];
    
    rep(i,0,5)
    {
        if(arr[i]==0)
        {
            cout<<i+1;
            return 0;
        }
    }

    return 0;
}



Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main() {
	int n; cin >> n;
	vector<vector<int>>dp(n + 1, vector<int>(3));
	for (int i = 1; i <= n; i++) {
		vector<int>today(3); for (int j = 0; j < 3; j++)cin >> today[j];
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (j == k)continue;
				dp[i][j] = max(dp[i][j], dp[i - 1][k] + today[j]);
			}
		}
	}
	int ret = 0;
	for (int i = 0; i < 3; i++)ret = max(ret, dp[n][i]);
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <stdio.h>
#include <iomanip>
using namespace std;

int main()
{
	int nA, nB;
	cin >> nA >> nB;
	int nD, nR;
	double dF;
	nD = nA / nB;
	nR = nA%nB;
	dF = nA / (double)nB;
	cout << nD << " " << nR << " ";
	printf("%.8f\n", dF);

	//system("pause");
	return 0;
}

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

using namespace std;

int main(){
        int a, b, k;
        cin>>a>>b>>k;
        for(int i=a;i<=b;i++){
                if(i<a+k||b-k<i){
                        cout<<i<<endl;
                }
        }
        return 0;
}


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

int Abs(int n){
  return n < 0 ? -n : n;
}

int main(){
  string s;
  const int NUM = 753;
  int a100, a10, a, n;
  cin >> s;
  vector<int> ans(s.length()-2, 0);

  for(int i = 2; i < s.length(); i++){
    a100 = s[i-2]-'0';
    a10 = s[i-1]-'0';
    a = s[i]-'0';
    n = a100*100 + a10*10 + a;
    ans[i-2] = Abs(n-NUM);
  }
  sort( ans.begin(), ans.end() );
  cout << ans[0] << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
vector<string> split(string s, char p){vector<string>v;stringstream m(s);string b;while(getline(m,b,p))v.push_back(b);return v;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;

int main(){
    ll A, V, B, W, T; cin >> A >> V >> B >> W >> T;
    if (V > W) {
        REP(i, T) {
            ll addA, addB;
            bool isASC;
            if (A < B) {
                addA = V;
                addB = W;
                isASC = true;
            } else {
                addA = -V;
                addB = -W;
                isASC = false;
            }
            A += addA;
            B += addB;
            if (A == B) {
                cout << "YES\n";
                return 0;
            } else if ((A<B) != isASC) {
                cout << "YES\n";
                return 0;
            }
        }
    }
    cout << "NO\n";
}


Measured memory_bytes: 3628
import sys
input=sys.stdin.readline
n,k=map(int,input().split())
array=[]
for i in range(n):
    a,b=map(int,input().split())
    array.append((a,b))
array.sort()
i=0
import sys
while True:
    if array[i][1]<k:
        k-=array[i][1]
        i+=1
    else:
        print(array[i][0])
        sys.exit()









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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N + 1);
  for(int i = 0; i < M; i++){
    int a, b;
    cin >> a >> b;
    A.at(a)++;
    A.at(b)++;
  }
  for(int i = 1; i <= N; i++){
    cout << A.at(i) << endl;
  }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
//#define m 1000000000000000007
/*vector<ll>prime(10000001,1);
vector<ll>sdf(10000001);
ll C[101][101];
int isprime(ll n)
{
    ll i;
    for(i=2;i*i<=n;i++)
    {
        if(n%i==0)
            {//cout<<i<<endl;
            return 0;}
    }
    return 1;
}
int isperfectsq(ll n)
{


    long double x;
    x=(long double)(sqrt((long double )(n)));
    ll y=sqrt(n);
    if(x==y)
        return 1;
        else
            return 0;
}
void ncr()
{
    C[0][0] = 1;
    for (int n = 1; n <= 100; ++n) {
        C[n][0] = C[n][n] = 1;
        for (int k = 1; k < n; ++k)
            C[n][k] = C[n - 1][k - 1] + C[n - 1][k];
    }
}
void sieve()
{
    //cout<<"in1";
    ll i;
    for(i=0;i<=10000000;i++)
        sdf[i]=i;
    ll j;
    prime[0]=prime[1]=0;
    for(i=2;i*i<=10000000;i++)
    {
        if(prime[i]==1)
        {
            //isprime.push_back(i);
            for(j=i*i;j<=10000000;j+=i)
            {
                prime[j]=0;
                if(sdf[j]==j)
                {
                    sdf[j]=i;
                }
            }
        }
    }
}
long long modular_expo(long long x,long long y)
{

    if(y==0)
        return 1;
    if(y%2==0)
        return modular_expo(x*x,y/2);
    if(y%2==1)
        return x*modular_expo(x*x,(y-1)/2);


}*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);


    ll n,i;
    cin>>n;
    //n--;
    //cout<<n<<endl;
    string ans;
    map<int,char>m;
    for(i=0;i<26;i++)
        m[i]=char(97+i);
    //m[0]='z';
   // ans+=m[(n%26)];
    //n=26*(n/26);
    while(n)
    {
        n--;


              //  cout<<n%26<<" "<<m[(n%26)]<<endl;
        ans+=m[(n%26)];

        n=(n/26);

    }
    reverse(ans.begin(),ans.end());
    cout<<ans;


}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%lld",&x)

int main(){
    ll n, a, b, c, d, e, ans;
    sc(n), sc(a), sc(b), sc(c), sc(d), sc(e);
    vector<ll> w = {a, b, c, d, e};
    sort(w.begin(), w.end());
    if (n <= w[0]) ans = 5;
    else if (n % w[0] == 0) ans = 4 + n/w[0];
    else ans = 5 + n/w[0];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define rep(i, a) for (int i = 0; i < (a); i++)
#define repd(i, a) for (int i = (a)-1; i >= 0; i--)
#define reps(i, a, j) for (int i = (j); i < (a); i++)
#define deb(x) cout << #x << " " << x << endl;
#define debs(x) cout << #x << " " << x << " ";
#define deba(x) for (auto _i:x) cout << _i << " "; cout << endl;
#define ms(a) memset(a,0,sizeof(a));
#define mp make_pair
#define eb emplace_back
#define FastOpen freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define pii pair < int , int >
#define all(a) a.begin(),a.end() 
//int power(int x,int p){if(p==0)return 1;if(p==1)return x;if(p%2)return x*power(x,p-1);int y=power(x,p/2);return y*y;}
/*
*/

void solve() {
    string s,t,res;
    cin >> s >> t;
    int n = s.length(),m = t.length();
    int dp[n][m];
    ms(dp);
    rep(i,n) {
        rep(j,m) {
            if (s[i] == t[j]) dp[i][j] = (i>0 && j>0 ? dp[i-1][j-1]:0) + 1;
            else dp[i][j] = max(i>0?dp[i-1][j]:0,j>0?dp[i][j-1]:0);
        }
    }
    int i=n-1,j=m-1;
    // rep(i,n) {deba(dp[i]); cout << endl;}
    while (i>=0 && j>=0) {
        if (s[i] == t[j]) {
            res.push_back(s[i]);
            i--; j--;
        }else {
            if (i == 0 || j ==0) {
                if (i == 0) j--;
                else i--;
            }else {
                if (dp[i-1][j] > dp[i][j-1]) i--;
                else j--;
            }
            
        }
    }
    reverse(all(res));
    cout << res << endl;
}

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





Measured memory_bytes: 73940
import sys
from collections import deque

H,W=map(int,input().split())
maze=[input() for i in range(H)]

def bfs(sy,sx):
    queue = deque([[sy,sx]])
    log = [[0 for i in range(W)] for j in range(H)]
    while queue:
        p = queue.popleft()

        for i,j in [1,0],[-1,0],[0,1],[0,-1]:
            next_p = [p[0]+i,p[1]+j]
            
            if 0 <= next_p[0] < H and 0 <= next_p[1] < W:
                if next_p[0] == sy and next_p[1] == sx:
                    continue

                if maze[next_p[0]][next_p[1]] == '.'\
                    and log[next_p[0]][next_p[1]] == 0:
                    log[next_p[0]][next_p[1]] = log[p[0]][p[1]] + 1
                    queue.append([next_p[0],next_p[1]])
    
    return log

for i in range(H):
    for j in range(W):
        if maze[i][j] == '.':
            tmp_i = i
            tmp_j = j
            break

tmplog = bfs(tmp_i,tmp_j)
max_v = 0

for i in range(H):
    for j in range(W):
        if tmplog[i][j] > max_v:
            max_v = tmplog[i][j]
            tmp_i = i
            tmp_j = j

tmplog = bfs(tmp_i,tmp_j)
max_v = 0

for i in range(H):
    for j in range(W):
        if tmplog[i][j] > max_v:
            max_v = tmplog[i][j]
            s_y = i
            s_x = j

finlog = bfs(s_y,s_x)

for i in range(H):
    for j in range(W):
        if finlog[i][j] > max_v:
            max_v = finlog[i][j]

print(max_v)

Measured memory_bytes: 3316
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as MV
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

main :: IO ()
main = do
  [n, m] <- map read . words <$> getLine
  q <- V.replicateM m $ do
    [x, y] <- map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
    return (x-1, y-1)
  let
    ans = V.create $ do
      v <- MV.replicate n (1, False)
      MV.write v 0 (1, True)
      V.forM_ q $ \(x, y) -> do
        red <- snd <$> MV.read v x
        MV.modify v (\(l, b) -> (l+1, if red then red else b)) y
        MV.modify v (\(l, b) -> if l == 1 then (0, False) else (l-1, b)) x
      return v
  print $ V.length $ V.filter snd ans


Measured memory_bytes: 46972
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    int n, a, b, c;
    cin >> n >> a >> b>> c;
    vi l(n);
    rep(i, n) {
        cin >> l[i];
    }

    ll ans = LINF;
    rep(i, 1<<(n<<1)) {
        vector<bool> ch(3);
        rep(j, n) {
            rep(k, 3) {
                if((i>>(j<<1))%4 == k+1) {
                    ch[k] = true;
                }
            }
        }
        bool ss = true;
        rep(j, 3) {
            if(!ch[j]) {
                ss = false;
            }
        }

        if(ss) {
            int now = 0;
            vvi gg(3);
            rep(j, n) {
                rep(k, 3) {
                    if((i>>(j<<1))%4 == k+1) {
                        gg[k].push_back(j);
                    }
                }
            }
            now += gg[0].size() + gg[1].size() + gg[2].size() - 3;
            now *= 10;
            vi si(3);
            rep(j, 3) {
                rep(k, gg[j].size()) {
                    si[j] += l[gg[j][k]];
                }
            }
            
            now += abs(si[0] - a);
            now += abs(si[1] - b);
            now += abs(si[2] - c);
            ans = min(ans, (ll)now);
            //cout << now << endl;
            //cout << bitset<8> (i) << endl;
        }
    }

    cout << ans << endl;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	int64 x;
	cin >> n >> x;
	vector<int64> a(n);
	REP(i, n){
		cin >> a[i];
	}
	sort(all(a));
	int64 sum = 0;
	REP(i, n){
		if(sum+a[i] <= x){
			sum += a[i];
		}else{
			cout << i << endl;
			return 0;
		}
	}
	if(sum == x)
		cout << n << endl;
	else
		cout << n-1 << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 100000

int A[N];
char C[N];
char C1[N];
int A1[N];

int Partition(int p,int r){
    int x,i,j;
    int tmp,tmpc;
    
    x=A[r];
    i = p-1;
    
    for(j=p;j<r;j++){
        if (A[j] <= x){
            i=i+1;
            tmp=A[j];
            tmpc=C[j];
            A[j]=A[i];
            C[j]=C[i];
            A[i]=tmp;
            C[i]=tmpc;
        }
    }
    
    tmp=A[i+1];
    tmpc=C[i+1];
    A[i+1]=A[r];
    C[i+1]=C[r];
    A[r]=tmp;
    C[r]=tmpc;
    
    
    return i+1;
}

void Quicksort(p,r){
    int q;
    if(p<r){
        q=Partition(p,r);
        Quicksort(p,q-1);
        Quicksort(q+1,r);
    }
}

/* Merge */
void Merge(int l,int m,int r){
    int n1,n2;
    int i,j,k;
    int L[N],R[N];
    char LC[N],RC[N];
    
    n1=m-l;
    n2=r-m;
    
    for(i=0;i<n1;i++){
        L[i]=A1[l+i];
        LC[i]=C1[l+i];
    }
    for(j=0;j<n2;j++){
        R[j]=A1[m+j];
        RC[j]=C1[m+j];
    }
    
    L[n1] = 2147483647;
    R[n2] = 2147483647;
    
    i=0;
    j=0;
    
    for(k=l;k<r;k++){
        if(L[i]<=R[j]){
            A1[k]=L[i];
            C1[k]=LC[i];
            i++;
        }else{
            A1[k]=R[j];
            C1[k]=RC[j];
            j++;
        }
    }
    
}
/* Merge Sort */
void Merge_Sort(int left,int right){
    int mid;
    if(left+1<right){
        mid = (left + right)/2;
        Merge_Sort(left,mid);
        Merge_Sort(mid,right);
        Merge(left,mid,right);
    }
}// End Merge-Sort



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

    int n,i,x,j,k=0;
    char null;
    int tmp;
    char tmpc;
    
    scanf("%d%c",&n,&null);
    if(1>n || n>100000)return 0;
    
    for(i=0;i<n;i++){
        scanf("%c%d%c",&C[i],&A[i],&null);
        C1[i]=C[i];
        A1[i]=A[i];
    }
    
    
    Quicksort(0,n-1);
    
    
    Merge_Sort(0,n);
    
    
/*    for(i=0;i<n;i++){
        for(j=1;j<n;j++){
            
            if(A1[j]<A1[j-1]){
                tmp=A1[j];
                tmpc=C1[j];
                A1[j]=A1[j-1];
                C1[j]=C1[j-1];
                A1[j-1]=tmp;
                C1[j-1]=tmpc;
            }
        }
    }
    
  */
    for(i=0;i<n;i++){
        if(C1[i]!=C[i]){
        k=1;
    }
    }
    

    
    
    if(k==1)printf("Not stable\n");
    else printf("Stable\n");
    
    
    for(i=0;i<n-1;i++){
        printf("%c %d\n",C[i],A[i]);
    }

    printf("%c %d\n",C[n-1],A[n-1]);
    
    
    
    
    return 0;
}

Measured memory_bytes: 2092
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
const int mx = 505;
int n, k, a[mx], s, p[20], m[20], c, i, ans;
void dfs(int t, int s){
	if(t < c) for(int i = 0; i <= m[t]; i++, s*= p[t]) dfs(t+1, s);
	else{
		int ps = 0, cl = 0, temp[505] = {};
		rep(i,n) ps += (temp[i] = a[i] % s);
		sort(temp, temp+n);
		ps /= s;
		rep(i,n-ps) cl += temp[i];
		if(cl <= k) ans = max(ans, s);
	}
}
int main(){
	scanf("%d%d", &n, &k);
	rep(i,n){
		scanf("%d", a+i);
		s += a[i];
	}
	for(i = 2; i*i <= s; i++){
		if(!(s%i)){
			for(p[c]=i; !(s%i); m[c]++, s/=i);
			c++;
		}
	}
	if(s>1){
		p[c] = s;
		m[c++]++;
	}
	dfs(0,1);
	printf("%d\n", ans);
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define itn int
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define sortt(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=2e9;
const ll lnf=9e18;

int main(){
  ll t1,t2,a1,a2,b1,b2;
  cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
  if(a1*t1+a2*t2==b1*t1+b2*t2){
    cout << "infinity" << endl;
    return 0;
  }
  if((a1>b1&&a2>b2)||(a1<b1&&a2<b2)){
    cout << "0" << endl;
    return 0;
  }
  ll fd=abs(a1-b1)*t1;
  ll sd=abs(a2-b2)*t2;
  if(fd>sd){
    cout << "0" << endl;
    return 0;
  }
  ll fsd=abs(fd-sd);
  ll ans=fd/fsd*2+1;
  if(fd%fsd==0) ans--;
  cout << ans << endl;
}

Measured memory_bytes: 3600
#!/usr/bin/env python3


def main():
    n, a, b = map(int,input().split())
    s = input()
    sanka = 0
    sankaigai = 0

    for hito in s:
        if hito is "c":
            print("No")
        elif hito is "a":
            if sanka < a+b:
                print("Yes")
                sanka+=1
            else:
                print("No")
        elif hito is "b":
            if sanka < a+b:
                if sankaigai < b:
                    print("Yes")
                    sanka+=1
                    sankaigai+=1
                else:
                    print("No")
            else:
                print("No")
        else:
            print("No")


if __name__ == '__main__':
    main()

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

int main(){
  ll n; cin>>n;
  ll c2=0,c4=0;
  for(int i=0; i<n; i++) {
    ll x; cin>>x;
    if(x%4==0) c4++;
    else if(x%2==0) c2++;
  }
  cout << (c4 + c2/2 >= n/2 ? "Yes" : "No");
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	char a[200001];int i=0;
	cin>>a;
	for(;;)
	{
		if(a[i]=='\0')
		break;
		if(a[i]=='?')
		cout<<'D',i++;
		else
		cout<<a[i++];
	}
		return 0;
}

Measured memory_bytes: 3240