akhauriyash/Code-Regression huggingface dataset:
def calc(h)
    stack = []
    h.each_char do |char|
        stack << char
        while stack.size >= 3 && stack[-3] =~ /\W/ && stack[-2] =~ /\w/ && stack[-1] =~ /\w/
            op, x, y = stack[-3..-1]
            3.times { stack.pop }
            case op
            when ?+ then stack << (x.to_i | y.to_i).to_s
            when ?* then stack << (x.to_i & y.to_i).to_s
            when ?^ then stack << (x.to_i ^ y.to_i).to_s
            end
        end
    end
    stack[0]
end

while 1
    h = gets.chomp.gsub(/[\[\]]/, '')
    break if h =~ /\./
    x = calc(h.tr('abcd', gets.chomp))
    n = (0..9999).count{|i| calc(h.tr('abcd', sprintf("%04d", i))) == x}
    puts "#{x} #{n}"
end



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

int main() {
  int a,b,c,d;
  //string s;
  cin >> a >> b ; 
  c = (a+b)%2;
  if(c==0){
    d = (a+b)/2 ;}
  else{
    d = (a+b)/2 +1;
      }
    
  cout <<d <<endl;
}


Measured memory_bytes: 256
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int main(){
	string a,b,c,d;
	cin>>a>>b>>c>>d;
	string s=a+b+c+d;
	sort(All(s));
	if(s=="1479") cout<<"YES"<<endl;else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.sqrt;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int x[] = new int[n];
    int y[] = new int[n];
    double total = 0;
    for(int i=0 ; i<n ; i++){
      x[i] = sc.nextInt();
      y[i] = sc.nextInt();
    }
    for(int i=0 ; i<n-1 ; i++){
      for (int j=i+1 ; j<n ; j++) {
        total = total + sqrt(((x[i]-x[j])*(x[i]-x[j]))+((y[i]-y[j])*(y[i]-y[j])));
      }
    }
    System.out.println(total*2/n);
  }
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N, K;
  cin >> N >> K;
  vector<long> data(N);
  for(int i = 0; i < N; i++){
    cin >> data.at(i);
  }
  sort(data.begin(), data.end());
  long sum = 0;
  for(int i = 0; i < N - K; i++){
    sum += data.at(i);
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 1792
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end
x, y = gets_i_list
i = 1

loop do
  if x * 2 > y
    puts i
    break
  end
  x = x * 2
  i += 1
end

Measured memory_bytes: 14524
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

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(b < a){
        a = b;
        return true;
    }
    return false;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int ans = -1;
    reps(i, 5){
        int x;
        cin >> x;
        if(x == 0){
            ans = i;
        }
    }

    cout << ans << endl;

    cout << flush;

    return 0;
}

Measured memory_bytes: 3540
#include<iostream>
#include<string>
#include<cmath>

int main(){
    std::string a, b;
    std::cin >> a >> b;
    a += b;
    int num = std::stoi(a);
    int sqrt = std::sqrt(num);
    if(num == sqrt * sqrt) std::cout << "Yes" << std::endl;
    else std::cout << "No" << std::endl;
    return 0;
}


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

using namespace std;

int main(){

    int a,b,c;

    cin>>a>>b>>c;

    int tmp = a-b;
    if(tmp<0){
        cout<<c<<endl;
    }else{
        if(c-tmp<=0){
            cout<<0<<endl;
        }else{
            cout<<c-tmp<<endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mkp make_pair
#define rep(i,s,f) for(i=s;i<f;i++)
#define db cout<<'h'<<'i'<<endl 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define PI 3.14159265
#define mod 1000000007
#define mod2 998244353
#define space 100005
#define lg 18
//<<fixed << setprecision(9)

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

    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll l=__gcd(c,d);
    l=c*d/l;
    ll ans=(b/d+b/c-b/l) -((a-1)/d+(a-1)/c-(a-1)/l);
    cout<<b-a+1-ans;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int N, M, C, ans = 0;
    cin >> N >> M >> C;
    vector<int> B(M);
    for(int i = 0; i < M; i++) cin >> B[i];
    for(int i = 0; i < N; i++) {
        int acc = C;
        for(int j = 0; j < M; j++) {
            int tmp;
            cin >> tmp;
            acc += B[j] * tmp;
        }
        if(acc > 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int llint
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define PI (acos(-1))
#define EPS (1e-10)
#define INF INT_MAX
#define INFLL LLONG_MAX
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using MCI = std::map<char, int>;
using VPII = std::vector<PII>;
using Complex = std::complex<double>;
using namespace std;


int N;


int gcd(int a, int b){
	return a%b ? gcd(b, a%b) : b;
}


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


signed main(){
	cin >> N;

	int ans = 1;
	rep(i, 0, N){
		int T;
		cin >> T;
		ans = lcm(ans, T);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007


int main() {
	ll n;
	string s;
	cin>>n>>s;
	cout <<( n>=3200 ? s:"red");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) cout << (x) << endl;
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
 
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};



int main(void){
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int a,b;
    cin >> a >> b;
    if((a >= 1 && a <= 9) && (b >= 1 && b <= 9)) print(a * b)
    else print(-1);
}


Measured memory_bytes: 256
#include <stdio.h>

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

	int c = 0;
	int l = strlen(s);
	for ( int i = 0 ; i < l/2 ; i++ ) {
		if ( s[i] != s[l-i-1] ) {
			c++;
		}
	}

	printf("%i",c);
}


Measured memory_bytes: 128
import sys
from fractions import gcd
from functools import reduce
from itertools import combinations

import numpy as np

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def is_MM(s):
    num = int(s)
    return 0 < num <= 12


def solve():
    N, M = il()
    L_max = 0
    R_min = float("inf")
    for m in range(M):
        lr = il()
        L_max = max(L_max, lr[0])
        R_min = min(R_min, lr[1])
    return R_min - L_max + 1 if L_max <= R_min else 0


if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 13568
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	string O, E;
	cin >> O >> E;
	for (int i = 0; i < min(O.length(),E.length()); i++) {
		cout << O[i] << E[i];
	}
	if (O.length() < E.length()) {
		cout << E[E.length() - 1] << endl;
	}
	else if (O.length() == E.length()) {
		cout << endl;
	}
	else {
		cout << O[O.length() - 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const int mod = 1e5;
const int MAX = 1e7;

int main() {
    int n, m; cin >> n >> m;
    int sum = 0;
    rep(i,m) {
        int x; cin >> x;
        sum += x;
    }
    if (n < sum) cout << -1 << endl;
    else cout << n - sum << endl;
}

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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;

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; }

const int INF = 1e18;
const int MOD = 1e9 + 7;

signed main(){
    int N; cin >> N;
    vector<int> a( N );
    REP( i, N ) cin >> a[i];
    sort( ALL( a ) );

    double ans = a[0];
    FOR( i, 1, N ){
        ans = ( ans + a[i] ) / 2;
    }

    cout << ans << endl;

}

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

using namespace std;

int main(){
    int n, m;
    cin >> n;
    vector<int> ti(n,0);
    for(int i = 0; i < n; i++){
        cin >> ti[i];
    }

    cin >> m;
    vector<int> pi(m);
    vector<int> xi(m);
    for(int i = 0; i < m; i++){
        cin >> pi[i] >> xi[i];
    }

    for(int i = 0; i < m; i++){
        int r = 0;
        for(int j = 0; j < n; j++){
            if(j + 1 == pi[i]){
                r += xi[i];
            }else{
                r += ti[j];
            }
        }
        cout << r << endl;
    }
}

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

#define ll long long

#define pii pair < int, int >
#define pll pair < ll, ll >

#define vi vector < int >
#define vs vector < string >

#define pb push_back

using namespace std;

const int N = 1e5 + 50;

int a[N], b[N];
bool vis[N];

int main()
{
    int a[6], pos = 0;

    for(int i = 1; i <= 5; i++){
        cin >> a[i];

        if(a[i] == 0) pos = i;
    }

    cout << pos << endl;

    return 0;
}


Measured memory_bytes: 3636
n = int(input())
s = input()

l = 0
r = 0
for i in range(n):
    if s[i] == "(":
        l += 1
    else:
        l = max(0, l-1)
for i in range(n-1, -1, -1):
    if s[i] == ")":
        r += 1
    else:
        r = max(0, r-1)

print("(" * r + s + ")" * l)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const int mod = 1000000007;
const int MAXV =  3502;

int main() {
  int n, m;
  cin >> n >> m;
  int ans = pow(2, m) * m * 1900 + pow(2, m) * (n - m) * 100;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

struct Data
{
	int p;
	int y;
	int i;
};

int P[100005];
int Y[100005];
string ID[100005];

vector<Data> D[100005];

string getID(int p, int y)
{
	string ps, ys;
	REP(i, 6)
	{
		if (p != 0)
		{
			ps = (char)(p % 10 + '0') + ps;
			p /= 10;
		}
		else
		{
			ps = '0' + ps;
		}

		if (y != 0)
		{
			ys = (char)(y % 10 + '0') + ys;
			y /= 10;
		}
		else
		{
			ys = '0'+ys;
		}
	}
	return ps + ys;
}

int main()
{
	int N, M;
	cin >> N >> M;
	REP(i, M)
	{
		int p, y;
		cin >> p >> y;
		p--; y--;
		Data d;
		d.p = p; d.y = y; d.i = i;
		D[p].push_back(d);

	}
	REP(i, N)
	{
		sort(D[i].begin(), D[i].end(), [](Data a, Data b) {return a.y < b.y; });
		REP(j, D[i].size())
		{
			ID[D[i][j].i] = getID(D[i][j].p + 1, j + 1);
		}
	}

	REP(i, M)
	{
		cout << ID[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 12416
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    long long int n, k;
    cin >> n >> k;
    vector<pair<int, int>> vp;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        vp.push_back(make_pair(a, b));
    }
    sort(vp.begin(), vp.end());
    for (auto p : vp) {
        k -= p.second;
        if (k <= 0) {
            cout << p.first << endl;
            return 0;
        }
    }
}




Measured memory_bytes: 4264
###
# 二分木
###

import sys

class Node:
    def __init__(self, val):
        self.val = val
        self.parent = None
        self.left = None
        self.right = None
        self.depth = 0
    
    def get_depth(self):
        if not self.parent:
            return 0
        else:
            return self.parent.get_depth()+1
    
    def get_sibling(self):
        if not self.parent:
            return - 1
        else:
            if self.parent.right and self.parent.right.val == self.val:
                if self.parent.left:
                    return self.parent.left.val
                else:
                    return - 1
            elif self.parent.left and self.parent.left.val == self.val:
                if self.parent.right:
                    return self.parent.right.val
                else:
                    return - 1
    
    def get_parent(self):
        if not self.parent:
            return -1
        return self.parent.val
    
    def get_degree(self):
        degree = 0
        if self.left:
            degree += 1
        if self.right:
            degree += 1
        return degree
    
    def get_type(self):
        if not self.parent:
            return "root"
        elif self.left or self.right:
            return "internal node"
        else:
            return "leaf"
    
    def get_height(self):
        if not self.left and not self.right:
            return 0
        l,r = 0,0
        if self.left:
            l = self.left.get_height()
        if self.right:
            r = self.right.get_height()
        return max(l + 1,r + 1)


def main():
    n = int(input().strip())
    nodes = [Node(i) for i in range(n)]
    for _ in range(n):
        val, left, right = [int(i) for i in input().strip().split()]
        if left != -1:
            nodes[val].left,nodes[left].parent = nodes[left],nodes[val]
        if right != -1:
            nodes[val].right,nodes[right].parent = nodes[right],nodes[val]

    for id in range(n):
        p = nodes[id].get_parent()
        s = nodes[id].get_sibling()
        deg = nodes[id].get_degree()
        dep = nodes[id].get_depth()
        h = nodes[id].get_height()
        _type = nodes[id].get_type()
        print("node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}".format(id, p, s, deg, dep, h, _type))


if __name__ == "__main__":
    main()


Measured memory_bytes: 5640
S = list(input())

acgt = ['A', 'C', 'G', 'T']
maxs = 0

ans = 0
for i in range(len(S)):
  for j in range(i, len(S)):
    temp = S[i: j+1]
    if all('ACGT'.count(c) for c in temp):
      ans = max(ans, j - i + 1)

print(ans)

Measured memory_bytes: 3060
n = int(input())
mod = 10**9+7
f = lambda x: int(x)%mod
a = list(map(f,input().split()))
kei = sum(a[1:])%mod
ans = 0
for i in range(n-1):
  ans += a[i]*(kei)
  ans %= mod
  kei -= a[i+1]
print(ans)

Measured memory_bytes: 94156
n,l = map(int,input().split())
def apple(a,b):
    if a == 0:
        return 0
    return apple(a-1,b)+ b+a-1

cor = apple(n,l)
wro = apple(n-1,l)
for i in range(1,n):
    if abs(l+i-1) < abs(wro-cor) :
        wro = cor -(l+i-1)
    else:
        wro += 0

print(wro)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i = 0; i < n; i++)
#define CloseIO std::ios::sync_with_stdio(false)
const int N = 4000 + 200;
const ll Mod = 100;
const ll INF = pow(2,32)-1;
int main(){
  int n,k;
  cin>>n>>k;
  int t1,t2 = n/k;
  t1 = t2;
  if(n%k != 0){
    t2+=n%k;
  }
  cout<<abs(t1-t2)<<endl;


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long long,long long> ii; 	
typedef complex<long double> com;

const ll mod = 1e9+7;

vector <ll> dp;
vector <ll> f;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll n;
    cin >> n;
    dp.resize(ll(1) << n);
    f.resize(ll(1) << n);
    vector <vector<ll>> grid(n,vector<ll>(n));
    for (int z=0;z<n;z++){
        for (int x=0;x<n;x++){
            cin >> grid[z][x];
        }
    }
    for (ll z=1;z<ll(1) << n;z++){
        for (int x=0;x<17;x++){
            if (z & ll(1) << x){
                for (int y=x+1;y<17;y++){
                    if (z & ll(1) << y){
                        dp[z] += grid[x][y];
                    }
                }
            }
        }
        f[z] = dp[z];
    }
    for (int i = 0; i < (1 << n); i++)
        for (int j = i; j; j = (j - 1) & i) f[i] = max(f[i], f[i ^ j] + dp[j]);
    cout << f[(ll(1) << n) -1] << endl;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define ford(i,a,b) for(int i=(a);i>=b;i--)
#define rep(i,a,b) for(int i=(a);(i)<=(b);(i)++)
#define ll long long
#define re return
#define mp map<int,int>
#define N 200005
#define prqu priority_queue< pair<ll,ll> >
using namespace std;
prqu pq; 
ll ans=0,n,m;
int main() {
	cin>>n>>m;
	rep(i,1,n){
		int a;
		cin>>a;
		pq.push({a, 1});
	}
	rep(i,1,m){
		int a,b;
		cin>>a>>b;
		pq.push({b,a});
	}
	while(n--) {
		int x=pq.top().first;
		int y=pq.top().second;
		pq.pop();
		ans+=x;
		if(y>1) pq.push({x,y-1});
	}
	cout<<ans;
	re 0;
}


Measured memory_bytes: 6256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL n;
    cin>>n;
    LL ans = n-1;
    for(LL i = 2; i * i <= n;i++ ){
        if(n % i == 0){
            LL x = n / i;
            ans = min(ans, (i - 1) + (x - 1));
        }
    }
    PUTS(ans);
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	static int[][] yobo;
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();		//sima
		int M=sc.nextInt();		//yobo

		yobo=new int[M][2];
		int[] range=new int[2];
		int hashi=1;

		for(int i=0; i<M; i++) {
			yobo[i][0]=sc.nextInt();
			yobo[i][1]=sc.nextInt();
		}

		//sort(yobo);
		quick_sort(yobo, 0, M-1);
		for(int i=0; i<M; i++) {
			if(i==0) {
				range[0]=yobo[0][0];
				range[1]=yobo[0][1];
			}
			else {
				if(Math.min(range[1],yobo[i][1])-Math.max(yobo[i][0], range[0])>=1) {
					range[0]=Math.max(yobo[i][0], range[0]);
					range[1]=Math.min(yobo[i][1], range[1]);
				}
				else {
					hashi++;
					range[0]=yobo[i][0];
					range[1]=yobo[i][1];
				}
			}
		}


		/*for(int i=0; i<M; i++) {
			System.out.println(yobo[i][0]+" "+yobo[i][1]);
		}*/
		System.out.println(hashi);
	}

	/*
	static int pivot(int[][] a,int i,int j){
		int k=i+1;
		while(k<=j && a[i]==a[k]) k++;
		if(k>j) return -1;
		if(a[i][0]>=a[k][0]) return i;
		return k;
	}


	static int partition(int[][] a,int i,int j,int x){
		int tmp1=0;
		int tmp2=0;
		int l=i,r=j;

		// 検索が交差するまで繰り返します
		while(l<=r){

			// 軸要素以上のデータを探します
			while(l<=j && a[l][0]<x)  l++;

			// 軸要素未満のデータを探します
			while(r>=i && a[r][0]>=x) r--;

			if(l>r) break;
			tmp1=a[l][1];
			tmp2=a[r][1];
			a[l][1]=tmp2;
			a[r][1]=tmp1;
			int t=a[l][0];
			a[l][0]=a[r][0];
			a[r][0]=t;
			l++; r--;
		}
		return l;
	}

	public static void quickSort(int[][] a,int i,int j){
		if(i==j) return;
		int p=pivot(a,i,j);
		if(p!=-1){
			int k=partition(a,i,j,a[p][0]);
			quickSort(a,i,k-1);
			quickSort(a,k,j);
		}
	}


	public static void sort(int[][] a){
		quickSort(a,0,a.length-1);
	}
	*/





	    // 配列dのleftからrightまでの間のデータ列をクイックソートする
	    static void quick_sort(int[][] d, int left, int right) {
	        if (left>=right) {
	            return;
	        }
	        int p = d[(left+right)/2][0];
	        int l = left, r = right, tmp,tmp1,tmp2;
	        while(l<=r) {
	            while(d[l][0] < p) { l++; }
	            while(d[r][0] > p) { r--; }
	            if (l<=r) {
	                tmp = d[l][0]; d[l][0] = d[r][0]; d[r][0] = tmp;
	                tmp1=d[l][1]; tmp2=d[r][1]; d[l][1]=tmp2; d[r][1]=tmp1;
	                l++; r--;
	            }
	        }
	        quick_sort(d, left, r);  // ピボットより左側をクイックソート
	        quick_sort(d, l, right); // ピボットより右側をクイックソート
	    }
	    // 配列内のデータ列を表示する
	    static void print_data(int[] d) {
	        for(int i = 0; i < d.length; i++) System.out.print(d[i] + " ");
	        //System.out.println();
	    }

}

Measured memory_bytes: 88408
<?php
 fscanf(STDIN, "%d %d %d", $a, $b, $c); 
  if ($a<=$b){
 	 if($b/$a >= $c){
 		  echo $c;
 		 }else if($b/$a <= $c){
    	  echo floor($b/$a);
  	}
  }else {echo 0;}
  ?>

Measured memory_bytes: 16052
use proconio::input;

fn main() {
    input! {
        n: usize,
        p: [f64; n],
    };

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

    for i in 0..n {
        for j in 0..=i {
            dp[i+1][j] += dp[i][j]*(1.-p[i]);
            dp[i+1][j+1] += dp[i][j]*p[i];
        }
    }

    let mut ans = 0.;
    for j in (n/2+1)..=n {
        ans += dp[n][j];
    }

    println!("{}", ans);
}


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



int main() {
    int x;
    cin >> x;
    
    if(x >= 30)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    
    
    
    return 0;
}




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

#define eps 1e-7


int main(){

    ll n;
    cin>>n;

    ll a[n+1];



    for(int i=1;i<=n;i++){
        cin>>a[i];
        a[i] = a[i]-(i);
    }


    sort(a+1,a+n+1);
    
    
    ll b = 0;
    
    if(n%2 == 1){
        b = a[(n+1)/2];
    }else {
        b = (a[n/2]+a[n/2+1])/2;
    }

    
    ll sad = 0;
    for(int i=1;i<=n;i++){
        sad += abs(a[i]-b);
    }
    
    cout<<sad<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << - 1 << endl;}
void unhap() {cout << ":(" << endl;}

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> x(m);
  for (int i = 0; i < m; i++) cin >> x.at(i);
  if (n >= m) cout << 0 << endl;
  else {
    priority_queue<int, vector<int>, greater<int>> xx;
    sort(x.begin(), x.end());
    for (int i = 0; i < m - 1; i++) xx.push(x.at(i + 1) - x.at(i));
    ll sum = 0;
    for (int i = 0; i < m - n; i++) {
      sum += xx.top();
      xx.pop();
    }
    cout << sum << endl;
  }
}

Measured memory_bytes: 1276
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
   int a[3],flag=1,sum=0;
   for(int i=0;i<3;i++) cin>>a[i];
   sort(a,a+3);
   while(flag!=0)
   {
       if(a[0]==a[1]&&a[1]==a[2]) break;
       if(a[2]!=a[1])
       {a[0]++;a[1]++;sum++;}
       else
        {a[0]+=2;sort(a,a+3);sum++;}

       if(a[0]==a[1]&&a[1]==a[2]) flag=0;
   }
   cout<<sum;
}


Measured memory_bytes: 256
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>

#define N 1000000
#define N2 1000
#define N_PRIME 78500

int
main(int argc, char** argv)
{
	bool f[N + 1];
	int prime[N_PRIME];
	int n_prime;
	int n;
	int i, j;

	for (i = 0; i <= N; ++i)
		f[i] = true;

	n_prime = 0;
	for (i = 2; i <= N2; ++i)
	{
		if (f[i])
		{
			prime[n_prime++] = i;
			for(j = i + i; j <= N; j += i)
				f[j] = false;
		}
	}

	for (; i <= N; ++i)
	{
		if (f[i])
			prime[n_prime++] = i;
	}

	while (scanf("%d", &n) != EOF)
	{
		int count;
		if (n <= 500)
		{
			for (i = 0; prime[i] <= n; ++i)
				;
			count = i;
		}
		else
		{
			int lb = 0, ub = n_prime;
			while (ub - lb > 1)
			{
				int mid = (lb + ub) / 2;
				if (prime[mid] >= n + 1)
					ub = mid;
				else
					lb = mid;
			}

			count = ub;
		}

		printf("%d\n", count);
	}

	return 0;
}

Measured memory_bytes: 1876
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int q = sc.nextInt();

		int[] p = new int[n]; // players
		for (int i = 0; i < q; i++) {
			int a = sc.nextInt();
			p[a - 1]++;
		}

		StringBuilder sb = new StringBuilder(n * 3);
		for (int num : p) {
			if (num + k - q > 0) {
				sb.append("Yes\n");
			} else {
				sb.append("No\n");
			}
		}

		System.out.println(sb);

		sc.close();
	}
}


Measured memory_bytes: 48884
#include <stdio.h>
#include <iostream>
#include <vector>
using namespace std;

#define N_MAX 10000
#define NIL -1

struct Node{
    int value;
    int parent;
};

struct Node node[N_MAX];

void init(int n){
    for(int i = 0; i <= n; i++){
        node[i].value = i;
        node[i].parent = NIL;
    }
}

int find(int x){
    struct Node target_node = node[x];
    vector<int> v;
    while(target_node.parent != NIL){
        v.push_back(target_node.value);
        target_node = node[target_node.parent];
    }

    for(int i = 0; i < v.size(); i++){
        node[v[i]].parent = target_node.value;
    }

    return target_node.value;
}

void unite(int x, int y){
    if(find(x) != find(y)){
        node[find(x)].parent = y;
    }
}

void same(int x, int y){
    if(find(x) == find(y)){
        printf("1\n");
    }else{
        printf("0\n");
    }
}

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

    init(n);

    for(int i = 0; i < q; i++){
        int com, x, y;
        scanf("%d", &com);
        scanf("%d", &x);
        scanf("%d", &y);

        if(com == 0){
            unite(x, y);
        }else{
            same(x, y);
        }
    }

}



Measured memory_bytes: 3260
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 10000000000000000
#define mod 2019

int main(){
	ll l,r;cin>>l>>r;
	
	ll ans=INF;
		
	if(r-l>=2019 || l%mod>r%mod){cout<<0<<endl;return 0;}//余り全パターンある

	for(ll i=l%mod;i<=r%mod;i++){
		for(ll j=l%mod;j<=r%mod;j++){
			if(i!=j) ans=min(ans,i*j%mod);
		}
	}

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

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)//初期値a,i<bの範囲でループ
#define REP(i,n) FOR(i,0,n)//初期値0,i<nの範囲でループ
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;

int a[5];
int p;
int main(){
    //REP(i,4)cin>>a[i];
    cin>>p;
    REP(i,4){
        int r=p%10;
        a[3-i]=r;
        p=(p-r)/10;
    }
    int i;

    for(i=0;i<(1<<3);i++){
        int sum=a[0];
        //cout<<"a";
        REP(j,3){
            //cout<<"a";
            //cout<<(i>>j&1);
            if((i>>j&1)==1)sum+=a[j+1];
            else sum-=a[j+1];
        }
        //cout<<sum<<endl;
        if(sum==7){
            //cout<<"AC";
            break;
        }
    }
    

    REP(j,3){
        cout<<a[j];
        if((i>>j&1)==1)cout<<"+";
        else cout<<"-";
    }
    cout<<a[3]<<"=7"<<endl;
    

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
bool ok(int a, int b, int c) {
    if (a*a+b*b<c*c) return true;
    else return false;
}
int main() 
{
    int row,col,high;
    int n;
    int dir;
    while (scanf("%d%d%d",&row,&col,&high)) {
        if (row==0&&col==0&&high==0) break;
        scanf("%d",&n);
        for (int i=0; i<n; i++) {
            scanf("%d",&dir);
            dir*=2;
            if (ok(row,col,dir)||ok(row,high,dir)||ok(col,high,dir)) {
                printf("OK\n");
            }
            else {
                printf("NA\n");
            }
        }
    }
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N; cin >> N;
    vector<PII> p;
    REP(i,N){
        int t; cin >> t;
        p.eb(t,i+1);
    }
    sort(p.begin(),p.end());
    for(auto tp : p){
        cout << tp.second << " ";
    }
    cout << endl;

}


Measured memory_bytes: 1780
import re

def validate(a, b, s):
    pattern = "\\d{%d}-\\d{%d}"%(a, b)
    #print(pattern)
    m = re.match(pattern, s)
    return m is not None



if __name__ == "__main__":
    a, b = map(int, input().split())
    s = input()
    if validate(a, b, s):
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3188
import sys
abcdf=list(input()) #　a1
abcd=[int(i) for i in abcdf]


for i in range(2 ** 3):
  nsum=abcd[0]
  op=[]
  for j in range(3):  # このループが一番のポイント
    if ((i >> j) & 1):
      nsum+=abcd[j+1]
      op.append('+')
    else:
      nsum-=abcd[j+1]
      op.append('-')
  if nsum==7:
    print(abcdf[0]+op[0]+abcdf[1]+op[1]+abcdf[2]+op[2]+abcdf[3]+'=7')
    sys.exit(0)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX/2
using namespace std;
using ll = long long;
using R = double;
using Data = pair<ll, vector<int>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 50;
struct edge { ll from; ll to; ll cost; };
typedef tuple<ll, ll, ll>T;
typedef pair<int, int>pint;

int main() {
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;

	string s1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	string s2 = "abcdefghijklmnopqrstuvwxyz";

	s[k - 1] = (s[k - 1] - 'A') + 'a';
	cout << s << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int llint;
typedef long long ll;
typedef long int lint;
typedef vector<char> vchar;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
#define vsort(v) sort((v).begin(), (v).end())
#define vrsort(v) sort((v).rbegin(), (v).rend())
#define vreverse(v) reverse((v).begin(), (v).end())
#define pb(a) push_back(a)
#define INF 2000000009
#define MOD 1000000007
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //input
  int n,i,f;cin>>n;vint a(n);f=0;
  vector<bool> r(8,false);
  for(i=0;i<n;i++){
    cin>>a[i];
    if(a[i]<3200){r[(a[i]/400)]=true;}
    else{f++;}
  }
  //caricurate
  int yk=0;
  for(i=0;i<8;i++){
    if(r[i]){yk++;}
  }
  //output
  cout<<max(yk,1)<<" "<<yk+f<<endl;
  
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int i,j,N,A[100],minj,count=0,tmp;
  
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  
  for(i=0;i<N;i++){
    minj=i;
    for(j=i;j<N;j++){
      if(A[j]<A[minj]) minj=j;
    }
    if(minj!=i){
    tmp=A[i];
    A[i]=A[minj];
    A[minj]=tmp;
    count++;
    }
  }
  for(i=0;i<N-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[N-1]);
  printf("%d\n",count);
  
  return 0;
}

Measured memory_bytes: 600
N, M = map(int, input().split())
sc = []

def check(num, sc):
  ret = True
  snum = str(num)
  if len(str(int(snum))) != N:
    ret = False
    return(ret)
  
  for tmp in sc:
    s = tmp[0]
    c = tmp[1]
    
    if snum[s-1] != str(c):
      ret = False
  return(ret)

for i in range(M):
  sc.append(list(map(int,input().split())))
  
ret = -1
for num in range(1000):
  if check(num, sc):
    ret = num
    break

print(ret)


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

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;

template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


template <i64 mod = MOD>
struct ModInt{
    i64 p;

    ModInt() : p(0){}
    ModInt(i64 x){p = x >= 0 ? x % mod : x + (-x + mod - 1) / mod * mod;}

    ModInt& operator+=(const ModInt& y){p = p + *y - ((p + *y) >= mod ? mod : 0); return *this;}
    ModInt& operator-=(const ModInt& y){p = p - *y + (p - *y < 0 ? mod : 0); return *this;}
    ModInt& operator*=(const ModInt& y){p = (p * *y) % mod; return *this;}
    ModInt& operator%=(const ModInt& y){if(y)p %= *y; return *this;}

    ModInt operator+(const ModInt& y) const{ModInt x = *this; return x += y;}
    ModInt operator-(const ModInt& y) const{ModInt x = *this; return x -= y;}
    ModInt operator*(const ModInt& y) const{ModInt x = *this; return x *= y;}
    ModInt operator%(const ModInt& y) const{ModInt x = *this; return x %= y;}

    friend ostream& operator<<(ostream& stream, const ModInt<mod>& x){
        stream << *x;
        return stream;
    }

    friend ostream& operator>>(ostream& stream, const ModInt<mod>& x){
        stream >> *x;
        return stream;
    }

    ModInt& operator++(){p = (p + 1) % mod; return *this;}
    ModInt& operator--(){p = (p - 1 + mod) % mod; return *this;}

    bool operator==(const ModInt& y) const{return p == *y;}
    bool operator!=(const ModInt& y) const{return p != *y;}

    const i64& operator*() const{return p;}
    i64& operator*(){return p;}

};

using mint = ModInt<>;


bool solve(){
    int n, w;
    cin >> n >> w;
    vector<int> a(n);
    for(int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a.begin(), a.end());
    vector<vector<mint>> dp(n, vector<mint>(w + 1, 0));
    int sum = 0;
    for(int i = 0; i < n; ++i){
        dp[i][sum] = 1;
        if(i == n)
            break;
        sum += a[i];
        if(sum > w)
            break;
    }
    for(int i = 0; i < n; ++i){
        for(int j = i + 1; j < n; ++j){
            vector<mint> nex(w + 1, 0);
            for(int k = 0; k <= w; ++k){
                nex[k] += dp[i][k];
                if(k + a[j] <= w)
                    nex[k + a[j]] += dp[i][k];
            }
            dp[i] = move(nex);
        }
    }
    mint ans = 0;
    if(accumulate(a.begin(), a.end(), 0LL) <= w)
        ans = 1;
    for(int i = 0; i < n; ++i){
        for(int k = 0; k <= w; ++k){
            if(w - k >= a[i])
                continue;
            ans += dp[i][k];
        }
    }
    cout << ans << endl;
    return false;
}

signed main(){
    while(solve());
}



Measured memory_bytes: 18684
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		int [] h = new int [n];
		
		for (int i=0; i<n; i++) 
			h[i] = sc.nextInt();
		
		int [] dp = new int [n];
		Arrays.fill(dp, Integer.MAX_VALUE);
		
		dp[0] = 0;
		
		for (int a=0; a<n; a++)
			for (int i=1; i<=k; i++) 
				if (a+i<n)
					dp[a+i] = Math.min(dp[a+i], dp[a] + Math.abs(h[a+i]-h[a]));
		
		System.out.println(dp[n-1]);
	}

}

Measured memory_bytes: 50976
#include<iostream>
#include<vector>
#include <unordered_map>  
#include <algorithm>
#include <functional>
#include <map>
#include <string>
#include <sstream>
#include <cmath>
#include <float.h>
using namespace std;

int main(){
	int a, b, x;
	string result;
	cin >> a >> b >> x;
	if (a <= x && x <= a + b) {
		result = "YES";
	}
	else {
		result = "NO";
	}
	cout << result << endl;
	return 0;
}

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

int main(){
	int X, N;
	cin >> X >> N;
	vector<int> p(N);
	set<int> s;
	int a;
	for(int i=0; i<N; i++){
		cin >> p.at(i);
		a = p.at(i);
		s.insert(a);
	}

	if( !s.count(X) ){
		cout << X << endl;
		return 0;
	}

	for(int i=1; i<100; i++){
		if( !s.count(X-i)){
			//if( X-i > 0 ){
				cout << X-i << endl;
				return 0;
			//}
		}
		else if( !s.count(X+i)){
			//if( X+i < 101 ){
				cout << X+i << endl;
				return 0;
			//}
		}
	}


}


Measured memory_bytes: 3636
//
// Created by rajshah9914 on 28/03/20.
//

#include <bits/stdc++.h>
using namespace std;

long long max(long long a,long long b)
{
    if(a>=b)
        return a;
    return b;
}
int main()
{
    priority_queue<long long>pq1,pq2,pq3;
    long long x,y,a,b,c,r[100000],g[100000],n[100000];
    cin>>x>>y>>a>>b>>c;
    for(long long i=0;i<a;i++)
        cin>>r[i];
    for(long long i=0;i<b;i++)
        cin>>g[i];
    for(long long i=0;i<c;i++)
        cin>>n[i];
    long long k=x+y;
    sort(r,r+a);
    sort(g,g+b);
    sort(n,n+c);
    long long ans=0;
    for(int i=a-1;i>=max(0,a-x);i--)
    {
        pq1.push(r[i]);
    }
    for(int i=b-1;i>=max(0,b-y);i--)
        pq1.push(g[i]);
    for(int i=c-1;i>=max(0,c-(x+y));i--)
        pq1.push(n[i]);
    long long sum=0;
    while(k--)
    {
//        cout<<pq1.top();
        sum+=pq1.top();
        pq1.pop();
    }
    cout<<sum<<endl;

}

Measured memory_bytes: 8688
#include<bits/stdc++.h>
#define For(i,l,r) for(int i = (l),i##end = (r);i <= i##end;i++)
#define Fordown(i,r,l) for(int i = (r),i##end = (l);i >= i##end;i--)
#define debug(x) cout << #x << " = " << x << endl

using namespace std;

typedef long long ll;

template <typename T> inline bool chkmin(T &x,T y) { return y < x ? x = y,1 : 0; }
template <typename T> inline bool chkmax(T &x,T y) { return x < y ? x = y,1 : 0; }

const int INF = 0x3f3f3f3f;
const int N = 70 + 10,mod = 1e9 + 7;

int a[N],vis[N],fac[N << 1],inv[N << 1],Pos[N];
char str[N];

int n,k,ans = 0;

inline int read() {
	int x = 0,flag = 1;
	char ch = getchar();
	while(!isdigit(ch) && ch != '-')ch = getchar();
	if(ch == '-')flag = -1,ch = getchar();
	while(isdigit(ch))x = (x << 3) + (x << 1) + (ch - '0'),ch = getchar();
	return x * flag;
}

inline int fpm(int A,int b) {
	int res = 1;
	while(b) {
		if(b & 1) res = 1ll * res * A % mod;
		A = 1ll * A * A % mod,b /= 2;
	}
	return res;
}

inline int C(int A,int B) {
	return 1ll * fac[A] * inv[B] % mod * inv[A - B] % mod;
}

inline void Calc(int len,int sum) {
	memset(vis,0,sizeof(vis)),memset(Pos,0,sizeof(Pos));
	int lasr = 0,lasb = 0;
	For(i,1,len) {
		int pos = 0;
		For(j,lasr + 1,k) if(!vis[j] && str[j] == 'r') {
			vis[j] = true;
			pos = lasr = j;break;
		}
		if(!pos) return;
		if(a[i] < 2) continue;
		For(j,max(pos,lasb) + 1,k) if(!vis[j] && str[j] == 'b') {
			vis[j] = true;
			Pos[i] = lasb = j;break;
		}
		if(!Pos[i]) return;
	}
	int Las = 0;
	For(i,1,len) {
		if(a[i] < 3) continue;
		int cnt = 0;
		For(j,max(Pos[i],Las) + 1,k) {
			if(!vis[j]) cnt++,vis[j] = true;
			Las = j;
			if(cnt == a[i] - 2) break;
		}
		if(cnt < a[i] - 2) return;
	}
	int Inv = fac[len],tot = len + 1;
	for(int i = 1,j = 1;i <= len;i = j + 1) {
		for(j = i;j < len && a[j + 1] == a[i];j++);
		Inv = 1ll * Inv * inv[j - i + 1] % mod;
		tot += (j - i + 1) * (a[i] * 2 - 1);
	}
	ans = (ans + 1ll * Inv * C(n - sum + tot - 1,tot - 1)) % mod;
}

inline void dfs(int res,int Mn,int cur) {
	if(res < 0) return;
	Calc(cur - 1,n - res);
	if(res == 0) return;
	For(i,1,min(res + 1,Mn)) a[cur] = i,dfs(res - (i == 1 ? 1 : i * 2 - 3) - (cur > 1),i,cur + 1);
}

inline void init(int Lim) {
	fac[0] = 1;
	For(i,1,Lim) fac[i] = 1ll * fac[i - 1] * i % mod;
	inv[Lim] = fpm(fac[Lim],mod - 2);
	Fordown(i,Lim,1) inv[i - 1] = 1ll * inv[i] * i % mod;
}

int main() {

	n = read(),k = read();
	init(150);
	scanf("%s",str + 1);

	dfs(n,70,1);

	printf("%d\n",ans);

	return 0;
}

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

int main()
{
	int N;
	cin >> N;
	vector<vector<int>> v(2, vector<int>(N + 1));
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < N; j++) {
			int A;
			cin >> A;
			v[i][j + 1] = v[i][j] + A;
		}
	}
	int res = 0;
	for (int i = 0; i < N; i++) {
		res = max(res, (v[0][i + 1] - v[0][0]) + (v[1][N] - v[1][i]));
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256