akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
using namespace std;

int main(){
    int n;
    char num[5];
    char ans[8][5];
    bool judge = false;
    while(cin >> n){
        if(judge) cout << endl;
        sprintf(num,"%05d",n);
        for(int i=0;i<5;i++){
            ans[0][i] = '*';
            ans[1][i] = ' ';
            if(num[i] >= '5' && num[i] <= '9') swap(ans[0][i],ans[1][i]);
            ans[2][i] = '=';
            for(int j=3;j<8;j++) ans[j][i] = '*';
            ans[3+((num[i]-'0')%5)][i] = ' ';
        }
        for(int i=0;i<8;i++){
            for(int j=0;j<5;j++){
                cout << ans[i][j];
            }
            cout << endl;
        }
        judge = true;
    }
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 	int s1,s2,s3; 
  	int input;
  	cin >> input;
  	s1 = input/100;
  	s2 = (input-100*s1)/10;
  	s3 = input - 100*s1 - 10*s2;
  	cout << s1+s2+s3 << endl;
}


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

int main(void)
{
    // Your code here!
    char* s,*t;
    
    s=(char*)malloc(sizeof(char)*2*100000);
    t=(char*)malloc(sizeof(char)*2*100000);
    
    scanf("%s",s);
    scanf("%s",t);
    
    int a = 0;
    
    int b=strlen(s);
    
    for(int i=0;i!=b;i++)
    {
        if(s[i]!=t[i])
        {
            a++;
        }
    }
    printf("%d",a);
    
    return 0;
}


Measured memory_bytes: 2076
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

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

using namespace std;

int dig(int n) {
  if(n<10)return 1;
  else return dig(n/10)+1;
}

int main() {
  while(1){
    int t,n;
    cin>>t>>n;
    if(!n)break;
    t=min(t,n);
    int s=dig(n);
    string ns=to_string(n);
    vector<vector<int>> dp(s+1,vector<int>(n+1));
    dp[0][0] = 1;
    REP(i,s+1){
      REP(j,i){
        auto sub=ns.substr(j,i-j);
        int m=stoi(sub);
        REP(k,n-m+1){
          if (dp[i][k+m] == 0 && dp[j][k] > 0)
            dp[i][k+m] = j+1;
          else if ((dp[i][k+m] != 0 && dp[j][k] != 0) || dp[j][k] < 0)
            dp[i][k+m] = -1;
        }
      }
    }
    bool ok=false;
    for (int u=t;u>0;--u) {
      if (dp[s][u] > 0) {
        vector<int> res;
        int i=s;
        int j=u;
        do {
          int oldi=i;
          i=dp[i][j]-1;
          auto sub=ns.substr(i,oldi-i);
          res.push_back(stoi(sub));
          j-=stoi(sub);
        } while(i>0);
        reverse(begin(res),end(res));
        cout<<u;
        for(int v:res) cout<<' '<<v;
        cout<<endl;
        ok = true;
        break;
      } else if (dp[s][u] < 0) {
        cout<<"rejected"<<endl;
        ok = true;
        break;
      }
    }
    if (!ok)
      cout<<"error"<<endl;
  }
  return 0;
}

Measured memory_bytes: 35300
#include <stdio.h>
   
int main(){
   
  int W = 0;
  int H = 0;
  int x = 0;
  int y = 0;
  int r = 0;

  bool judge = true;

  scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

  if ((x - r) < 0 || (x + r) > W){
    judge = false;
  }

  if ((y - r) < 0 || (y + r) > H){
    judge = false;
  }

  printf("%s\n", (judge ? "Yes" : "No"));

  return 0;

}

Measured memory_bytes: 1012
/**
 * B - Some Sums
 */

#include <iostream>

using namespace std;

int N, A, B;

int rec(int p, int n, int s) {

    if (n > N) return 0;

    if (p == 0) {
        if (s >= A && s <= B) {
            return n;
        } else {
            return 0;
        }
    }

    int ret = 0;

    for (int i = 0; i <= 9; i++) {
        ret += rec(p - 1, n * 10 + i, s + i);
    }

    return ret;
}

int main() {
    cin >> N >> A >> B;
    cout << rec(to_string(N).length(), 0, 0) << endl;
}

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

typedef long long int ll;
typedef long double ld;
const ll m=1e9+7;
#define pb push_back

#define all(n) n.begin(),n.end()
long long binpow(ll a, ll b) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll mod(ll a)
{
	if(a<m)return a;
	else return a%m;
}
void solve()
{
				
	
ll n;
	cin>>n;
	if(n==1)
	{
		cout<<0;
		return;
	}
	if(n==2)
	{
		cout<<2;
		return;
	}

		ll p=(mod(binpow(10,n)));
		ll q=mod(binpow(9,n)-binpow(8,n)+m);
		ll r=mod(binpow(8,n));
		
		ll x=mod(p-2*q+m-r+m);
	
		cout<<x;
	
}

int main()
{
	
solve();
		
	
	
}

Measured memory_bytes: 3572
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val x = readLine()!!.split(" ").map{it.toLong()}

    val MOD = 1e9.toLong() + 7
    val ONE = ModInt(1L, MOD)

    var res = ModInt(0L, MOD)
    var sum = ModInt(0L, MOD)

    for (m in 1 .. N - 1) {
        val d = x[m] - x[m - 1]

        sum += ONE / m.toLong()
        res += sum * d
    }

    for (i in 1 .. N - 1) {
        res *= i.toLong()
    }

    println(res.value)
}


class ModInt (value: Long, val mod: Long) {
    val value: Long

    init {
        if (mod <= 0) {
            throw IllegalArgumentException("ModInt cannot be created for non-positive modulus: $mod")
        }
        this.value = (value % mod + mod) % mod
    }

    private fun assertSameMod(other: ModInt) {
        if (mod != other.mod) {
            throw IllegalArgumentException(
                    "You cannot operate summation, subtraction and multiplication for ModInts with different moduli: $mod, ${other.mod}"
            )
        }
    }

    operator fun unaryMinus() = ModInt(mod - value, mod)

    operator fun plus(other: ModInt): ModInt {
        assertSameMod(other)

        return ModInt((value + other.value) % mod, mod)
    }

    operator fun plus(other: Long) = plus(ModInt(other, mod))

    operator fun minus(other: ModInt): ModInt {
        assertSameMod(other)

        return plus(-other)
    }

    operator fun minus(other: Long) = minus(ModInt(other, mod))

    operator fun times(other: ModInt): ModInt {
        assertSameMod(other)

        return ModInt((value * other.value) % mod, mod)
    }

    operator fun times(other: Long) = times(ModInt(other, mod))

    fun pow(k: Long): ModInt {
        var res = 1L
        var a = value
        var l = k

        while (l > 0) {
            if ((l and 1L) == 1L) {
                res = (res * a) % mod
            }

            a = a * a % mod
            l /= 2L
        }

        return ModInt(res, mod)
    }

    /**
     * Returns an inverse element of the value.
     * To ensure `m * m.inv() = 1`, the modulus should be prime, since it uses Fermat's little theorem.
     */
    fun inv() = pow(mod - 2)

    operator fun div(other: ModInt): ModInt {
        assertSameMod(other)
        if (other.value == 0L) {
            throw ArithmeticException()
        }

        return times(other.inv())
    }

    operator fun div(other: Long) = div(ModInt(other, mod))
}

class ModCombination(val n: Long, val mod: Long) {
    val fact = Array(n.toInt() + 1) { ModInt(1, mod) }
    val invfact = Array(n.toInt() + 1) { ModInt(1, mod) }

    init {
        for (i in 2..n.toInt()) {
            fact[i] = fact[i - 1] * i.toLong()
            invfact[i] = fact[i].inv()
        }
    }

    operator fun get(n: Long, m: Long): ModInt {
        if (m > n || n < 0 || m < 0) {
            return ModInt(0, mod)
        }

        return fact[n.toInt()] * invfact[m.toInt()] * invfact[(n - m).toInt()]
    }
}


Measured memory_bytes: 57784
#include <iostream>

using namespace std;

int main()
{
    string a;
    getline(cin, a);
    if(a[0]==a[1] || a[1]==a[2] || a[0]==a[2]) {
        cout<< "No";
    }
    else{
        cout<< "Yes";
    }
    return 0;
}


Measured memory_bytes: 3624
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#

def main():
    N=ii()
    m = INF
    ans = 0
    for val in mis():
        if m >= val:
            ans += 1
            m = val
    print(ans)

main()


Measured memory_bytes: 20464
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

class SegmentTree:
    def __init__(self, N, func, I):
        self.func = func
        self.I = I
        self.N = N
        self.sz = 2**(N-1).bit_length()
        self.seg = [I] * (self.sz * 2)
 
    def assign(self, k, x):
        self.seg[k + self.sz] = x
 
    def build(self):
        for i in reversed(range(1,self.sz)):
            self.seg[i] = self.func(self.seg[2 * i], self.seg[2 * i + 1])
 
    def update(self, k, x):
        k += self.sz
        self.seg[k] = x
        while k > 1:
            k >>= 1
            self.seg[k] = self.func(self.seg[2 * k], self.seg[2 * k + 1])

    def query(self, a, b):
        L = self.I
        R = self.I
        a += self.sz
        b += self.sz
        while a < b:
            if a & 1:
                L = self.func(L, self.seg[a])
                a += 1
            if b & 1:
                b -= 1
                R = self.func(self.seg[b], R)
            a >>= 1
            b >>= 1
        return self.func(L, R)

def main():
    def gcd(a, b):
        while b:
            a, b = b, a % b
        return a
    N = int(readline())
    L = list(map(int,readline().split()))
    seg = SegmentTree(N , gcd , 0)
    for i,n in enumerate(L):
        seg.assign(i , n)
    seg.build()
    ans = 1
    for i in range(N):
        ans = max(ans,gcd(seg.query(0,i) , seg.query(i+1,N)))
    print(ans)

main()


Measured memory_bytes: 58224
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
//inline int in() { int x; scanf("%d",&x); return x;}
inline ll in() { ll x; cin >> x; return x; }
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

vector<int> to[2505];
vector<int> rto[2505];
bool reachablefrom1[2505];
bool reachableToN[2505];
bool ok[2505];

void dfs(int v) {
  if (reachablefrom1[v]) return;
  reachablefrom1[v] = true;
  for (int u : to[v]) {
    dfs(u);
  }
}
void rdfs(int v) {
  if (reachableToN[v]) return;
  reachableToN[v] = true;
  for (int u : rto[v]) {
    rdfs(u);
  }
}

int main() {
  int n = in();
  int ans = n * n * n;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <set>
#include <map>
#include <deque>
#define WMAX 10000
#define HMAX 10000
#define INF (int )(1e9+7)

//コメントアウトするとdebug()を実行しない
#define DEBUG

using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

ll A,B,C,N,W,H,ans = 1,dp[HMAX][WMAX];
string S;
static const int dx[8] = {0,1,1,1,0,-1,-1,-1},
					dy[8] = {1,1,0,-1,-1,-1,0,1};

void solve(){
	for (int i = 1; i < N; ++i)
	{
		ans *= (i+1);
		ans %= INF;
	}
}

void debug(){

}

void answer(){
	cout << ans << "\n";
}

int main(){
	cin >> N;
	
	solve();
	#ifdef DEBUG
	debug();
	#endif
	answer();

	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.io.Serializable;

public class Main {
	public static void main(final String[] args){
    
        Scanner sc = new Scanner(System.in);

        int x = sc.nextInt();
        if(x == 3 || x == 5 || x == 7){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
        

        


    }
}

Measured memory_bytes: 23124
#pragma GCC optimize(2)
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue> //priority_queue<int, vector<int>, greater<int> > q;
#include <map>
#include <set> //multiset set<int,greater<int>>大到小
#include <vector>// vector<int>().swap(v);清空释放内存
#include <stack>
#include <cmath> // auto &Name : STLName  Name.
#include <utility>
#include <sstream>
#include <string>//__builtin_popcount(ans);//获取某个数二进制位1的个数
#define mod 1000000007
#define mod9 998244353
#define ld long double
#define ull unsigned long long
#define db double
#define ll long long
const db eps=1e-7;
//const db pi=acos(-1);
const int INF = 0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
#define rep(i,be,en) for (ll i=be;i<=en;i++)
#define per(i,be,en) for (int i=en;i>=be;i--)
using namespace std;
const int N=1e5+7;

int t,n,m,k,fl=0,ans=0;
int a[N];
int main() {
    scanf("%d%d",&n,&k);
    ans=n;
    rep(i,1,k){
        scanf("%d",&m);
        rep(i,1,m){
            scanf("%d",&fl);
            if(a[fl]==0) ans--;
            a[fl]++;
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 3228
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> 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().expect("failed to parse token")
}

const M: i64 = 1_000_000_007;

fn modinv(mut x: i64, m: i64) -> i64 {
    let mut y = m;
    let mut u = 1;
    let mut v = 0;

    while y != 0 {
        let t = x / y;
        x -= t * y;
        u -= t * v;

        std::mem::swap(&mut x, &mut y);
        std::mem::swap(&mut u, &mut v);
    }

    (u + m) % m
}

#[derive(Debug, Clone)]
struct Edge {
    n: usize,
    s: i64,
    v: i64,
}

#[derive(Debug, Clone)]
struct Node {
    e: Vec<Edge>,
    v: i64,
}

fn dfs1(nodes: &mut [Node], idx: usize, pidx: usize, facts: &[i64], finvs: &[i64]) -> (i64, i64) {
    let mut size = 1;
    let mut value = 1;

    for i in 0..nodes[idx].e.len() {
        if nodes[idx].e[i].n != pidx {
            let n = nodes[idx].e[i].n;
            let (s, v) = dfs1(nodes, n, idx, facts, finvs);
            nodes[idx].e[i].s = s;
            nodes[idx].e[i].v = v;
            size += s;
            value = (value * v) % M;
            value = (value * finvs[s as usize]) % M;
        }
    }

    value = (value * facts[(size - 1) as usize]) % M;

    (size, value)
}

fn dfs2(
    nodes: &mut [Node],
    idx: usize,
    pidx: usize,
    size: i64,
    value: i64,
    facts: &[i64],
    finvs: &[i64],
) {
    let mut s = 0;
    let mut v = 1;

    for i in 0..nodes[idx].e.len() {
        if nodes[idx].e[i].n == pidx {
            nodes[idx].e[i].v = value;
            nodes[idx].e[i].s = size;
        }

        s += nodes[idx].e[i].s;
        v = (v * finvs[nodes[idx].e[i].s as usize]) % M;
        v = (v * nodes[idx].e[i].v) % M;
    }

    nodes[idx].v = (facts[s as usize] * v) % M;

    for i in 0..nodes[idx].e.len() {
        if nodes[idx].e[i].n != pidx {
            let ns = s - nodes[idx].e[i].s + 1;
            let mut nv = (v * modinv(nodes[idx].e[i].v, M)) % M;

            nv = (nv * facts[(ns - 1) as usize]) % M;
            nv = (nv * facts[nodes[idx].e[i].s as usize]) % M;

            let n = nodes[idx].e[i].n;
            dfs2(nodes, n, idx, ns, nv, facts, finvs);
        }
    }
}

fn main() {
    let in_n: usize = read();
    let mut nodes = vec![Node { e: vec![], v: 1 }; in_n];
    let mut facts = vec![1; in_n];
    let mut finvs = vec![1; in_n];

    for _ in 0..in_n - 1 {
        let mut a: usize = read();
        let mut b: usize = read();

        a -= 1;
        b -= 1;

        nodes[a].e.push(Edge { n: b, s: 0, v: 1 });
        nodes[b].e.push(Edge { n: a, s: 0, v: 1 });
    }

    for i in 2..in_n {
        facts[i] = (facts[i - 1] * i as i64) % M;
        finvs[i] = modinv(facts[i], M);
    }

    dfs1(&mut nodes, 0, 0, &facts, &finvs);
    dfs2(&mut nodes, 0, 0, 0, 0, &facts, &finvs);

    for n in &nodes {
        println!("{}", n.v);
    }
}


Measured memory_bytes: 43080
#include<stdio.h>
int main()
{
	int A,B;
	scanf("%d%d",&A,&B);
	if(A<=5&&A>=0)
		printf("%d",0); 
	else if(A>=13)
		printf("%d",B);
	else  printf("%d",B/2);
	
	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const int NIL = -1;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
struct Point {
	int x, y, id;
	Point(){}
	Point(int x, int y, int id = 0) :id(id), x(x), y(y) {}
	bool operator<(const Point &p)const {
		return id < p.id;
	}
	void print() { printf("%d\n", id); }
};
bool lessX(const Point &p1, const Point &p2) { return (p1.x == p2.x) ? (p1.y < p2.y) : (p1.x < p2.x); }
bool lessY(const Point &p1, const Point &p2) { return (p1.y == p2.y) ? (p1.x < p2.x) : (p1.y < p2.y); }

struct KDTree {
	struct Node {
		int index, l, r;
		Node() :index(NIL), l(NIL), r(NIL) {}
	};
	int n, np, root; vector<Point>points; vector<Node>nodes;

	bool inrange(const Point &p, const Point &s, const Point &t) {
		return (s.x <= p.x&&p.x <= t.x) && (s.y <= p.y&&p.y <= t.y);
	}
	KDTree(const vector<Point>&ps) :points(ps), n(ps.size()), np(0), nodes(n) {
		root = makeKDTree(0, n, true);
	}
	int makeKDTree(int l, int r, bool is_x_base) {
		if (!(l < r))return NIL;
		int mid = (l + r) / 2;
		int t = np++;
		vector<Point>::iterator first = points.begin() + l,
			nth = points.begin() + mid, last = points.begin() + r;
		if (is_x_base)nth_element(first, nth, last, lessX);
		else nth_element(first, nth, last, lessY);
		nodes[t].index = mid;
		nodes[t].l = makeKDTree(l, mid, !is_x_base);
		nodes[t].r = makeKDTree(mid + 1, r, !is_x_base);
		return t;
	}
	vector<Point>ret;
	vector<Point> find(Point s, Point t) {
		ret.clear();
		return find(s, t, root, true);
	}
	vector<Point> find(Point s, Point t, int v, bool is_x_base = true) {
		auto p = points[nodes[v].index];
		if (inrange(p, s, t))ret.emplace_back(p);
		if (is_x_base) {
			if (nodes[v].l != NIL && s.x <= p.x)find(s, t, nodes[v].l, !is_x_base);
			if (nodes[v].r != NIL && p.x <= t.x)find(s, t, nodes[v].r, !is_x_base);
		}
		else {
			if (nodes[v].l != NIL && s.y <= p.y)find(s, t, nodes[v].l, !is_x_base);
			if (nodes[v].r != NIL && p.y <= t.y)find(s, t, nodes[v].r, !is_x_base);
		}
		return ret;
	}

};

signed main() {

	int N; scanf("%d", &N);
	vector<Point>v(N);
	rep(i, 0, N) {
		int x, y; cin >> x >> y;
		v[i] = (Point(x, y, i));
	}
	KDTree tree(v);
	int q; scanf("%d", &q);
	rep(i, 0, q) {
		int sx, tx, sy, ty; scanf("%d%d%d%d", &sx, &tx, &sy, &ty);
		Point s(sx, sy), t(tx, ty);
		auto ans = tree.find(s, t);
		sort(all(ans));
		rep(j, 0, ans.size())ans[j].print();
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 20032
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	if(s=="RRR") cout<<'3';
	if(s=="SRR") cout<<'2';
	if(s=="RRS") cout<<'2';
	if(s=="RSR") cout<<'1';
	if(s=="SSS") cout<<'0';
	if(s=="SSR") cout<<'1';
	if(s=="RSS") cout<<'1';
	if(s=="SRS") cout<<'1';
	return 0;
} 

Measured memory_bytes: 3628
#include<iostream>

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

using namespace std;

int main(){
    int n, sum = 0; cin >> n;
    int former; cin >> former;
    bool array[n]; REP(i, n) array[i] = 0;
    REP(i, n - 1){
        int x; cin >> x;
        if(x - former == 1) array[former - 1] = 1;
        former = x;
    }

    REP(i, n){
        int x; cin >> x;
        sum += x;
    }
                                                                       
    REP(i, n - 1){
        int x; cin >> x;
        if(array[i]) sum += x;
    }cout << sum;
}


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

int main(){
    ll n, m;
    cin >> n >> m;
    vector<bool> in(n, false);
    vector<ll> ke(n, 0);
    vector<ll> s(n), c(n);
    rep(i, 0, m) cin >> s[i] >> c[i];

    rep(i, 0, m){
        if(in[s[i]-1] && ke[s[i]-1] != c[i]){
            cout << "-1" << endl;
            return 0;
        }else{
            ke[s[i]-1] = c[i];
            in[s[i]-1] = true;
        } 
    }

    if(n != 1 && in[0] && ke[0] == 0){
        cout << "-1" << endl;
        return 0;
    }else if(n != 1 && !in[0]){
        ke[0] = 1;
    }

    rep(i, 0, n){
        cout << ke[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [0] * n
b = [0] * n
c = [0] * n

for i in range(n):
  a[i], b[i], c[i] = map(int, input().split())

dp = [[]] * (n+1)
for i in range(n+1):
  dp[i] = [0, 0, 0]

for i in range(n):
  dp[i+1][0] = max(dp[i][1] + a[i], dp[i][2] + a[i])
  dp[i+1][1] = max(dp[i][0] + b[i], dp[i][2] + b[i])
  dp[i+1][2] = max(dp[i][0] + c[i], dp[i][1] + c[i])
print(max(dp[n]))

Measured memory_bytes: 60376
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, sum[5001] = {};
  while(cin >> n, n){
    for(int i = 0; i < n; i++){
      int a;
      cin >> a;
      sum[i + 1] = sum[i] + a;
    }
    int ret = sum[1];
    for(int i = 0; i <= n; i++){
      for(int j = i + 1; j <= n; j++){
        ret = max( ret, sum[j] - sum[i]);
      }
    }
    cout << ret << endl;
  }
}


Measured memory_bytes: 3092
#include<iostream>

using namespace std;
int main() {
  int n, TH_P, H_P, T_P, O_P;
  cin >> n;
  for(int i=3; i<=n; i++) {
    TH_P = i/1000;
    H_P = (i%1000)/100;
    T_P = (i%100)/10;
    O_P = i%10;
    if(i%3==0||TH_P==3||H_P==3||T_P==3||O_P==3){ cout << ' ' << i ; continue;}
  }
  cout << endl;
  return 0;
}



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

int main(){
    int n[10];
    for(int i=0; i<4; ++i){
        int a; cin >> a; n[a] = 1;
    }
    if(n[1] == 1 && n[9] == 1 && n[7] == 1 && n[4] == 1){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N=int(input())
xy=[[] for _ in range(N)]
for _ in range(N):
    A = int(input())
    for __ in range(A):
        x, y = map(int, input().split())
        xy[_].append((x-1,y))

ans = 0
for p in range(1<<N):
    h = []
    judge = True
    for i in range(N):
        h.append(p&1)
        p>>=1
    for i in range(N):
        for x, y in xy[i]:
            if h[i] and y != h[x]:
                judge = False
                break
        if not judge: break
    if not judge: continue
    ans = max(ans,sum(h))

print(ans)


Measured memory_bytes: 43868
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
typedef long long ll;
#define sz(a) int((a).size());
#define pb push_back;
#define all(c) c.begin(),c.end();
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++);
#define present(c,x) (c.find(x) != c.end());
#define cpresent(c,x) (find(all(c),x) != c.end());


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll x;
    cin>>x;
    int a,b;
    int f=0;
    for(ll i=0;i<=64;i++){
        for(int j=0;j<=i;j++){
            if((ll)pow(i,5)+(ll)pow(j,5)==x){
                a=i;
                b=-j;
                f=1;
                break;
            }
        }
        if(f){
            break;
        }
    }
    if(f!=1){
        for(ll i=0;i<=120;i++){
            for(ll j=0;j<=i;j++){
                if((ll)pow(i,5)-(ll)pow(j,5)==x){
                    a=i;
                    b=j;
                    f=1;
                    break;
                }
            }
            if(f){
                break;
            }
        }
    }
    cout<<a<<" "<<b;
	return 0;
}


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

#define BIG 2000000007

#define MOD 1000000007
typedef unsigned long long ull;
typedef   signed long long sll;


#define N_MAX 100
#define M_MAX 20

ull n, m, k;
ull h, w;
ull a[N_MAX];
// ull b[M_MAX][N_MAX];
ull dp[N_MAX][M_MAX + 1];
// char s[N_MAX][M_MAX + 1];

void swap_adj(ull *a, ull *b){
	ull tmp = *b;
	*b = *a;
	*a = tmp;
	return;
}

int comp(const void *a, const void *b){
	if (*(ull*)a > *(ull*)b) {
		return -1;
	} else if (*(ull*)a < *(ull*)b) {
		return +1;
	} else {
		return 0;
	}
}

ull divide(ull a, ull b){
	ull x = MOD - 2;
	ull ans = 1;
	while (x) {
		if (x & 1) ans = (ans * b) % MOD;
		b = (b * b) % MOD;
		x /= 2;
	}
	return (a * ans) % MOD;
}

int digits(ull x){
	int i = 1;
	while (x >= 10) {
		x /= 10;
		i++;
	}
	return i;
}

int min(ull x, ull y){
	return (x < y) ? x : y;
}

ull solve(){
	int i, j;

	i = n / 100;
	j = n % 10;

	if (i == j) {
		puts("Yes");
	} else {
		puts("No");
	}

}

int main(void){
	ull i, j;
	int a, b, c, d;

	scanf("%d%d%d%d", &a, &b, &c, &d);

	if (a < c) a = c;
	if (b > d) b = d;

	if (a > b) a = b;
	printf("%d\n", b - a);

	// solve();

	return 0;
}


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

int main() 
{
    string s;
    cin >> s;
    int sum = 0;
    for (int i=0; i<s.size(); i++)
        sum += (int)s[i] - 48;
    cout << (stoi(s)%sum==0?"Yes":"No");
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  
  int ans = -1;
  for(int i=0; i<n; i++){
  	int x; cin >> x;
    ans = (ans == -1) ? x : __gcd(ans, x);
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1 LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

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

    LL ct = 0;
    for(LL i = 1;i < N;i++){
        ct += (N-1)/i;
    }
    cout << ct << endl;
}

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

#define reverse_array(type, arr, n)       \
    do {                                  \
        for (int i = 0; i < n / 2; i++) { \
            type __t = arr[i];            \
            arr[i] = arr[n - i - 1];      \
            arr[n - i - 1] = __t;         \
        }                                 \
    } while (0)

int main(void)
{
    char s[100001];
    scanf("%s", s);

    int s_len = strlen(s);
    int* child_num = calloc(s_len, sizeof(int));

    for (int direction = 0; direction < 2; direction++) {
        int count = 0;
        for (int i = 0; i < s_len; i++) {
            if (s[i] == 'R') {
                count++;
            } else {
                child_num[i - 1] += (count + 1) / 2;
                child_num[i] += count / 2;
                count = 0;
            }
        }

        reverse_array(char, s, s_len);
        reverse_array(int, child_num, s_len);

        for (int i = 0; i < s_len; i++) {
            s[i] = (s[i] == 'R' ? 'L' : 'R');
        }
    }

    for (int i = 0; i < s_len; i++) {
        printf("%d ", child_num[i]);
    }
    putchar('\n');

    free(child_num);
    return 0;
}


Measured memory_bytes: 896
a,b,c,d=[int(s) for s in list(str(input()))]
x=(a+b+c+d-7)/2
op=["+","+","+"]
for i in range(3):
    if [b,c,d][i]==x:
        op[i]="-"
        break
    elif [b,c,d][i]==b+c+d-x:
        op=["-","-","-"] 
        op[i]="+"
        break
print(str(a)+op[0]+str(b)+op[1]+str(c)+op[2]+str(d)+"=7")

Measured memory_bytes: 3064
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>

using namespace std;

int main() {
    int N;
    int x = 0;
    int y = 0;
    cin >> N;

    for (int i = 1; i <= N; i++) {
        x += 800;
        if ((i % 15) == 0) {
            y += 200;
        }
    }

    cout << x - y << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = str(input())

ret_left = 0

left = 0
for s in S:
    if s == ")":
        if left == 0:
            ret_left += 1
        else:
            left -= 1
    else:
        left += 1
        
ret_right = left

for i in range(ret_left):
    print("(", end = "")
print(S, end = "")
for i in range(ret_right):
    print(")", end = "")

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vd=vector<double>;
using vvd=vector<vd>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using vs=vector<string>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.141592653589793

template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	int n,k;
	cin>>n>>k;
	vl a(n),b(n,0),c(n,0);
	rep(i,n)cin>>a[i];
	b[0]=a[0];
	c[0]=max(a[0],0ll);
	rep(i,n-1){
	    b[i+1]=b[i]+a[i+1];
	    c[i+1]=c[i]+max(a[i+1],0ll);
	}
	ll ans=0;
	rep(i,n-k+1){
	    ll cal=max(b[i+k-1]-(i>0?b[i-1]:0),0ll);
	    cal+=(i>0?c[i-1]:0);
	    cal+=c[n-1]-c[i+k-1];
	    ans=max(ans,cal);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 2560
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin >> n;
    
    long long int sum = 0;
    for(int i=1;i<=n;i++){
        if((i%3 == 0 || i%5==0)){}
      	else {
            sum += i;
        }
    }
    cout << sum << endl;
    
    return 0;
}

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

class Graph{
    list<int> *l;
    int v;
    public:
       Graph(int v)
       {
           this->v=v;
           l=new list<int>[v];
       }
       void addEdge(int p,int q)
       {
           l[p].push_back(q);
       }
       void dfs_helper(int curr,int path[])
       {
           if(path[curr]!=INT_MIN)
           {
               return ;
           }
           path[curr]=0;
           for(auto nbr:l[curr])
           {
               dfs_helper(nbr,path);
               path[curr]=max(path[curr],path[nbr]+1);
           }
       }
       int dfs()
       {
               int path[v];
               for(int i=0;i<v;i++)
               {
                   path[i]=INT_MIN;
               }
               for(int i=0;i<v;i++)
               {
                   if(path[i]==INT_MIN)
                   {
                          dfs_helper(i,path);
                   }
               }
               int max_val=INT_MIN;
               for(int i=0;i<v;i++)
               {
                     max_val=max(path[i],max_val);
               }
               return max_val;
            
       }
};

int main()
{
    int v,e;
    cin>>v>>e;
    Graph G(v);
    for(int i=0;i<e;i++)
    {
        int a,b;
        cin>>a>>b;
        a--; b--;
        G.addEdge(a,b);
    }
    cout<<G.dfs();
}

Measured memory_bytes: 12092
/*input
9 20
.....***....***.....
....*...*..*...*....
...*.....**.....*...
...*.....*......*...
....*.....*....*....
.....**..*...**.....
.......*..*.*.......
........**.*........
.........**.........
*/

#include <iostream>

using namespace std;

int main()
{
	int H, W;
	cin >> H >> W;

	for(int i=0;i<H;i++){
		string temp;
		cin >> temp;
		cout << temp << endl;
		cout << temp << endl;
	}

	return 0;
}


Measured memory_bytes: 256
def dfs(s):
	if not visited[s]:
		visited[s] = True
		active[s] = True
		for t in con[s]:
			if active[t] or dfs(t):
				return True
	active[s] = False

v, e, *L = map(int, open(0).read().split())
con = [[] for _ in range(v)]
visited = [False] * v
active = [False] * v
for s, t in zip(*[iter(L)] * 2):
	con[s - 1].append(t - 1)
for i in range(v):
	if dfs(i):
		print(1)
		exit()
print(0)


Measured memory_bytes: 5644
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: usize = s.next().unwrap().parse().unwrap();
	let aoki = s.next().unwrap().parse::<usize>().unwrap() - 1;
	let takh = s.next().unwrap().parse::<usize>().unwrap() - 1;
	let mut edges = vec![vec![]; n];
	for _ in 0..n - 1 {
		let a = s.next().unwrap().parse::<usize>().unwrap() - 1;
		let b = s.next().unwrap().parse::<usize>().unwrap() - 1;
		edges[a].push(b);
		edges[b].push(a);
	}
	let tree = Tree::new(&edges, takh);
	let ans = edges.iter().enumerate().fold(0, |r, (i, l)|{
		if l.len() == 1 {
			let a = tree.lca(aoki, i);
			if tree.depth[aoki] - tree.depth[a] < tree.depth[a] {
				return std::cmp::max(r, tree.depth[i] - 1);
			}
		}
		r
	});
	println!("{}", ans);
}

struct Tree {
	parent: Vec<Vec<usize>>,
	depth: Vec<u32>,
}

impl Tree {
	fn new(edges: &Vec<Vec<usize>>, root: usize) -> Self {
		let n = edges.len();
		let log = (n as f64).log(2.).floor() as usize;
		let mut parent = vec![vec![std::usize::MAX; n]; log + 1];
		let mut depth = vec![0; n];
		let mut st = std::collections::VecDeque::new();
		st.push_front((root, std::usize::MAX, 0));
		while let Some((v, p, d)) = st.pop_back() {
			parent[0][v] = p;
			depth[v] = d;
			for e in edges[v].iter() {
				if *e != p {
					st.push_back((*e, v, d + 1));
				}
			}
		}
		for k in 0..parent.len() - 1 {
			for v in 0..n {
				if parent[k][v] != std::usize::MAX {
					parent[k + 1][v] = parent[k][parent[k][v]];
				}
			}
		}
		Tree { parent: parent, depth: depth }
	}

	fn lca(&self, u: usize, v: usize) -> usize {
		let (mut u, mut v) = if self.depth[u] > self.depth[v] { (v, u) } else { (u, v) };
		for k in 0..self.parent.len() {
			if ((self.depth[v] - self.depth[u]) >> k) & 1 != 0 {
				v = self.parent[k][v];
			}
		}
		if u == v {
			u
		} else {
			for k in (0..self.parent.len()).rev() {
				if self.parent[k][u] != self.parent[k][v] {
					u = self.parent[k][u];
					v = self.parent[k][v];
				}
			}
			self.parent[0][u]
		}
	}
}


Measured memory_bytes: 33020
#include<bits/stdc++.h>
typedef  long long int ll;
typedef  long double ld;
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define mod 1000000007
#define F first
#define S second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
//recursions\
#pragma comment(linker, "/stack:200000000")
//loops\
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;
const int N = 1e6 + 5;
ll row[N], col[N], cnt[N], val[N];
int main()
{
	sync;
	ll h, w, m;
	cin >> h >> w >> m;
	vector<pair<ll,ll> > v;
	for(ll i = 1; i <= m ; i++)
	{
		ll x, y;
		cin >> x >> y;
		v.push_back({x, y});
		row[x]++;
		col[y]++;
	}
	ll maxm = *max_element(row, row + N), maxy = *max_element(col, col + N) ;
	set<ll> s;
	for(ll i = 0; i < m; i++)
	{
		if(row[v[i].F] == maxm)
			s.insert(v[i].F), val[v[i].F] = 1;
	}
	for(ll i = 0; i < m; i++)
		cnt[v[i].S] += val[v[i].F];
	ll sz =  s.size(), ans = maxm + maxy - 1;
	for(ll i = 0; i < m; i++)
		if(col[v[i].S] == maxy && cnt[v[i].S] != sz)
			ans = maxm + maxy;
	cout << ans;
}
	
	

Measured memory_bytes: 31448
#include <cstdio>
#include <cstdlib>

template <typename T>
class stack{
  T a[101];
  unsigned n;
public:
  stack():a(),n(0){}
  T& top(){return a[n-1];}
  T pop(){return a[--n];}
  void push(T in){a[n++]=in;}
};

int main(){
  stack<int> s;
  char buf[100];

  while(scanf("%s",buf) != EOF){
    int a;
    switch(buf[0]){
      case '+' : a = s.pop(); s.top() += a; break;
      case '-' : a = s.pop(); s.top() -= a; break;
      case '*' : a = s.pop(); s.top() *= a; break;
      default  : s.push(atoi(buf));
    }
  }
  printf("%d\n",s.top());
}

Measured memory_bytes: 976
import sys
input=sys.stdin.buffer.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
#import itertools
import itertools
n = int(input())
t = [i+1 for i in range(n)]
li = list(itertools.permutations(t))
p = list(map(int,input().split()))
q = list(map(int,input().split()))
p = tuple(p)
q = tuple(q)
pp = li.index(p)
qq = li.index(q)
print(abs(pp-qq))     
       

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

int main(){
  int a, b;
  vector<int> hoge;
  cin >> a >> b;
  hoge.push_back(a*b);
  hoge.push_back(a+b);
  hoge.push_back(a-b);
  int c = *max_element(hoge.begin(), hoge.end());
  cout << c << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

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

#define INF 1000000000

int main(){
  int n, m;
  while(scanf("%d %d", &n, &m), n|m){
    priority_queue<pii> q; //<p,d> sorted by p

    rep(i,n){
      int d,p;
      scanf("%d %d", &d, &p);
      q.push(mp(p,d));
    }

    while(true){
      if(q.empty()) break;
      if(q.top().second > m) break;
      m -= q.top().second;
      q.pop();
    }

    int res=0;
    if(m>0 && !q.empty()){
      pii p = q.top(); q.pop();
      res += (p.second-m)*p.first;
    }
    
    while(!q.empty()){
      pii p = q.top(); q.pop();
      res += p.first * p.second;
    }

    cout << res << endl;

  }

  return 0;
}

Measured memory_bytes: 1340
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

ll n,x,S=0;
vl a;

int main(){
	cin>>n>>x;
	a=vl(n);
	for(int i=0;i<n;i++){
		ll A;
		cin>>A;
		S+=A;
		a[i]=A;
	}
	if(S==x) cout<<n<<endl;
	else{
		sort(a.begin(),a.end());
		for(int i=0;i<n;i++){
			x-=a[i];
			if(x<0){
				cout<<i<<endl;
				return 0;
			}
		}
		cout<<n-1<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

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

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

LL dfs(int id, VVLL &memo, VLL &s, LL x) {
    if (id == 0) return x % s[id];
    if (memo[id][x] > -1) return memo[id][x];
    LL ret = (dfs(id-1, memo, s, x % s[id]) + dfs(id-1, memo, s, x) * (id)) % MOD;
    //dump(ret);
    return memo[id][x] = ret;
}

void solve() {
    LL n,x;
    cin >> n >> x;
    VLL s(n);
    REP(i,0,n) cin >> s[i];
    sort(all(s));
    VVLL memo(n, VLL(x+1, -1));
    LL ans = 0;
    REP(i,0,x+1) memo[0][i] = i % s[0];

    cout << dfs(n-1, memo, s, x) << endl;
}

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

Measured memory_bytes: 157824
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif
template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static void tp_swap(_T& right, _T& left) {
	//	usage:  tp_swap<type name>(a, b);
	_T tmp = right;
	right = left;
	left = tmp;
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}

static void ABC088C_TakahashisInfomation();

#if 1
int main()
{
	ABC088C_TakahashisInfomation();
	fflush(stdout);
	return 0;
}
#endif

static void ABC088C_TakahashisInfomation()
{
	int cNum[3][3] = { 0 };
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			get1int(cNum[i][j]);
		}
	}
	
	int csum1[3] = { 0 };
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			csum1[i] += cNum[j][i];
		}
	}

	for (int i = 0; i <= 100; i++) {
		for (int j = 0; j <= 100; j++) {
			for (int k = 0; k <= 100; k++) {
				if (((3 * i - 3 * j) == (csum1[0] - csum1[1])) &&
					((3 * i - 3 * k) == (csum1[0] - csum1[2]))) {
					printf("Yes\n");
					return;
				}
			}
		}
	}
	printf("No\n");
}


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

using namespace std;
using ll = long long;
using ld = long double;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(20);
  cout << fixed;
  ll n , k;
  cin >> n >> k;
  ld res = 0, den = 0;
  for(int i = 1; i <= n; ++i) {
    int x = i;
    int p = 1;
    while(x < k) x *= 2, p *= 2;
    // cout << (1 / (ld) n) * pow(0.5, p) << ' ' << p << '\n';
    res += (1 / (ld) n) * (1 / (ld)p);
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define loops(i, s, n) for (int i = s; i < n; i++)
#define loop(i, n) for (int i = 0; i < n; i++)
#define eps 1e-9
#define loopitr(mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define even_set 0xAAAAAAAA ... 1010101010
#define odd_set 0x55555555 ... 01010101
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define vall(v) v.begin(), v.end()
#define mkp make_pair
#define ret return
#define cont continue
#define ff first
#define ss second
#define cnt_bits __builtin_popcount
const int mod = 1000000007;

int main()
{

    fastio;

    int n, k;
    cin >> n >> k;
    ll arr[n];
    loop(j, n)
    {
        cin >> arr[j];
    }

    ll dp[n];
    for(int i =0;i<n;i++)
       dp[i] = INT64_MAX;

    dp[0] = 0;
    for (int i = 1; i < n; i++)
    {
        for (int j = 1; j <= k; j++)
        {
            if (i - j >= 0)
                dp[i] = min(dp[i], dp[i - j] + abs(arr[i] - arr[i - j]));
        }
    }

    cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1792