akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T>using vv = vector<vector<T>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MOD = int(1e9) + 7; constexpr ll LINF = 1ll << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

struct UnionFind {
    vector<int> parent;
    vector<int> rank;
    void init(int size) { parent.assign(size, -1); rank.assign(size, 0); }
    int operator [](int x) { return find(x); }
    int find(int x) { return parent[x] < 0 ? x : (parent[x] = find(parent[x])); }
    bool same(int x, int y) { return find(x) == find(y); }
    int size(int x) { return -parent[find(x)]; }
    bool unite(int x, int y) {
        if ((x = find(x)) == (y = find(y))) return 0;
        return rank[x] = max(rank[x], rank[y] + 1), parent[x] += parent[y], parent[y] = x, 1;
    }
    bool uniteByRank(int x, int y) {
        if ((x = find(x)) == (y = find(y))) return 0;
        else if (rank[x] < rank[y]) swap(x, y);
        else if (rank[x] == rank[y]) ++rank[x];
        return parent[x] += parent[y], parent[y] = x, 1;
    }
    bool uniteBySize(int x, int y) {
        if ((x = find(x)) == (y = find(y))) return 0;
        else if (size(x) < size(y)) swap(x, y);
        return rank[x] = max(rank[x], rank[y] + 1), parent[x] += parent[y], parent[y] = x, 1;
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    vi p(N);
    rep(i, N) {
        cin >> p[i];
        p[i]--;
    }
    UnionFind uf;
    uf.init(N);
    rep(i, M) {
        int x, y;
        cin >> x >> y;
        uf.uniteByRank(x - 1, y - 1);
    }

    int cnt_diff = 0;
    rep(i, N) {
        if (!uf.same(p[i], i)) {
            cnt_diff++;
        }
    }

    write(N - cnt_diff);
}

Measured memory_bytes: 1408
n = int(input())
l = [int(input()) for _ in range(n)]
l.sort()
if n%2:
  s1 = l[:(n-1)//2]
  b1 = l[(n-1)//2:]
  t1 = sum(b1)*2 - sum(s1)*2 -sum(b1[:2])
  s2 = l[:(n+1)//2]
  b2 = l[(n+1)//2:]
  t2 = sum(b2)*2 - sum(s2)*2 + sum(s2[-2:])
  t = max(t1,t2)
else:
  s = l[:n//2]
  b = l[n//2:]
  t = sum(b)*2 - sum(s)*2 -b[0] + s[-1]
print(t)

Measured memory_bytes: 8532
#include<iostream>
#include<cstdio>
#include<cstring>

typedef long long ll;
int n,k;

int main()
{
	scanf("%d%d",&n,&k);
	ll ans=0;

	for(int i=k+1;i<=n;i++)
	{
		ll cnt=i-k,d=n/i,r=n%i;

		ans+=cnt*d;

		if(k)ans+=std::max(0ll,r-k+1);
		else ans+=r;

	}
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 384
module Main where

import Control.Applicative
import Text.Printf

getInt :: IO Int
getInt = head <$> getInts

getInts :: IO [Int]
getInts = map read . words <$> getLine

main :: IO ()
main = do
  { ss <- getInt
  ; let (q, s) = divMod ss 60
  ; let (h, m) = divMod q 60
  ; putStrLn (show h ++ ":" ++ show m ++ ":" ++ show s)
  }
  


Measured memory_bytes: 3660
import java.util.*;
import java.lang.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        String ans = "AC";
        if(s[0]!='A'){
            ans = "WA";
        }
        if(Character.isUpperCase(s[1])){
            ans = "WA";
        }
        int count = 0;
        for(int i =2;i<s.length;i++){
            if(Character.isUpperCase(s[i])){
                if(count==0&&s[i]=='C'&&i!=s.length-1){
                    count ++;
                } else {
                    ans = "WA";
                }
            }
        }
        if(count==0){
            ans ="WA";
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#include<bitset>
#include<random>
#include<time.h>

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;
const ll INF = 1LL << 60;

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



// Main Code

int main()
{
  int a, b;
  string s;
  cin>>a>>b>>s;
  if(s.length() == (a+b+1) && s[a] == '-')
  {
    int cnt = 0;
    rep(i, 0, s.length()){
      if(s[i] < '0' || s[i] > '9') cnt++;
    }
    if(cnt != 1) puts("No");
    else puts("Yes");
  }
  else puts("No");
}


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

#define INF 2147483647
#define LINF 9223372036854775807

#define MOD 1000000007
#define MOD2 998244353

template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

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

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int n,a,b;
    cin>>n>>a>>b;
    vector<int> h(n);

    rep(i,n)cin>>h[i];


    ll ok = INF;
    ll ng = 0;

    while( abs(ok-ng) > 1 ){

        int mid = (ok+ng)/2;
        //db3(ng,mid,ok);ln;
        
        ll wide = b;wide*=mid;
        ll cent = 0;
        
        rep(i,n){
            cent +=  (( max(0LL,h[i]-wide) )+(a-b-1))/(a-b);
        }

        
        if(  cent <= mid  )ok = mid;
        else ng = mid;
    }

    cout<<ok<<endl;
    //cout <<fixed<<setprecision(16)<< << endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int n;
  cin>>n;
  if(n>=1000) cout<<"ABD"<<endl;
  else cout<<"ABC"<<endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#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 all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#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 show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second)
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) (find(all(v),x)!=v.end())
#define incls(s,c) (s.find(c)!=string::npos)
#define lb(a,x) distance((a).begin(),lower_bound(all(a),(x)))
#define ub(a,x) distance((a).begin(),upper_bound(all(a),(x)))
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(all(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; cin >> x; return x;}
inline ll lin() { ll x; cin >> x; return x;}
inline char chin() { char x; cin >> x; return x;}
inline string stin() { string x; cin >> x; return x;}
inline double din() { double x; cin >> x; return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const vector<T>& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
char itoa(int n) { return n + '0';}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
const int dy[4] = {0, -1,  0,  1};
const int dx[4] = {1,  0, -1,  0};

int main () {
  string s = stin();
  cout << string(s.size(),'x') << endl;
  return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <cstring>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <functional>
#include <ctime>
#include <unordered_map>
#include <sstream>

using namespace std;
typedef long long Long;
typedef long double Double;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
typedef pair<Long,Long> PLL;

int read(int &x) { return scanf("%d", &x); }
int read(int &x, int &y) { return scanf("%d%d", &x, &y); }
int read(int &x, int &y, int &z) { return scanf("%d%d%d", &x, &y, &z); }
int read(Long &x) { return scanf("%lld", &x); }
int read(Long &x, Long &y) { return scanf("%lld%lld", &x, &y); }
int read(double &x) { return scanf("%lf", &x); }
char buff[2000010];
int read(string &s) { int r = scanf("%s", buff); s = buff; return r; }

#define dlog2(n) ((n) == -1 ? 0 : (31-__builtin_clz(n)))

#define sz(a) int(a.size())


int dp(int id, int T, bool lastUsed, VI &A, VI &B) {
	if (id == A.size()) return 0;
	static bool cat[3001][3001][2];
	static Long mem[3001][3001][2];
	int w = 0;
	if (cat[id][T][lastUsed]) return mem[id][T][lastUsed];
	// ignore
	w = max(w, dp(id+1, T, lastUsed, A, B));
	// eat it (NOT LAST)
	if (T >= A[id]) {
		w = max(w, dp(id+1, T - A[id], lastUsed, A, B) + B[id]);
	}
	// eat it last
	if (!lastUsed && T >= 1) {
		w = max(w, dp(id+1, T - 1, 1, A, B) + B[id]);
	}
	cat[id][T][lastUsed] = 1;
	return mem[id][T][lastUsed] = w;
}

int main() {

	int N, T;
	read(N, T);
	VI A(N), B(N);
	for (int i = 0; i < N; ++i) {
		read(A[i], B[i]);
	}
	cout << dp(0, T, 0, A, B) << endl;
}
























Measured memory_bytes: 158720
class Dice:
    def __init__(self, labels):
        self.up = labels[0]
        self.front = labels[1]
        self.right = labels[2]
        self.left = labels[3]
        self.back = labels[4]
        self.down = labels[5]
    def east(self):
        self.up, self.right, self.down, self.left = self.left, self.up, self.right, self.down
    def north(self):
        self.up, self.back, self.down, self.front = self.front, self.up, self.back, self.down
    def south(self):
        self.up, self.front, self.down, self.back = self.back, self.up, self.front, self.down
    def west(self):
        self.up, self.left, self.down, self.right = self.right, self.up, self.left, self.down
    def clockwise(self):
        self.front, self.left, self.back, self.right = self.right, self.front, self.left, self.back
    def counterclockwise(self):
        self.front, self.right, self.back, self.left = self.left, self.front, self.right, self.back
    def set_up(self, up):
        for i in range(6):
            if up == self.up:
                break
            if i % 2:
                self.east()
            else:
                self.north()
    def set_front(self, front):
        while True:
            if front == self.front:
                break
            self.clockwise()

dice = Dice(list(map(int, input().split())))
for _ in range(int(input())):
    up, front = map(int, input().split())
    dice.set_up(up)
    dice.set_front(front)
    print(dice.right)

Measured memory_bytes: 7808
#include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値
#define vl vector<ll>
#define pll pair<ll, ll>
#define F first
#define S second

int main() {
    // input
    ll A, B, C, X;
    cin >> A >> B >> C >> X;
    
    // calculation
    ll now, res = 0;
    for (ll i = 0; i <= A; ++i) {
        now = X - i*500;
        if (now < 0) break;
        else if (now == 0) {
            res++; break;
        } else {
            // 500 を引いた後，正ならば
            for (ll j = 0; j <= B; ++j) {
                now = X - i*500 - j*100;
                if (now < 0) break;
                else if (now == 0) {
                    res++; break;
                } else {
                    if (now%50 == 0 && now/50 <= C) {
                        res++; continue;
                    }
                }
            }
        }
    }
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using iii = pair<int, ii>;
#define vt vector
#define pq priority_queue
#define pb push_back
#define mp make_pair
#define fi first
#define se second
// #define multicase
const int MOD = 1e9 + 7;
const int INF = 2e9;
const int N = 1e3 + 5;

int x;

void solve() {
    int T = 1;
  #ifdef multicase
    cin >> T;
  #endif
    while(T--) {
        cin >> x;
        cout << (x == 0 ? "1\n" : "0\n");
    }
}

int main() {
 
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
 
    solve();
 
}

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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(a==7 && b==5 && c==5)
    cout << "YES" << endl;
  else if(a==5 && b==7 && c==5)
    cout << "YES" << endl;
  else if(a==5 && b==5 && c==7)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 3556
// ----- In the name of ALLAH, the Most Gracious, the Most Merciful -----

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

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define deb(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define memo(a,val) memset(a,val,sizeof(a))
#define NINJA ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(),a.end()
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define dloop(i,n) for(int i=n-1;i>=0;i--)
#define iii tuple<int,int,int>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define int long long
#define ld long double
#define pb push_back
#define endl "\n"
#define setbits __builtin_popcountll
#define mp map<int,int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007
#define inf (int)1e18

int32_t main(){
	NINJA;

	int n; cin >> n;
	vi a(n);
	fo(i,n) cin >> a[i];

	int cnt =0 ;
	int mx = 0;
	for1(i,n-1){
		if(a[i-1] > a[i]){
			cnt += abs(a[i-1]-a[i]);
			a[i] = a[i-1];
		}
	}

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

Measured memory_bytes: 4744
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
const int MOD = 998244353;
struct Mint {
	int val;
	Mint() { val = 0; }
	Mint(const ll& x) {
		val = (-MOD <= x && x < MOD) ? x : x % MOD;
		if (val < 0) val += MOD;
	}
	template <typename U>
	explicit operator U() const { return (U)val; }
	friend bool operator==(const Mint& a, const Mint& b) { return a.val == b.val; }
	friend bool operator!=(const Mint& a, const Mint& b) { return !(a == b); }
	friend bool operator<(const Mint& a, const Mint& b) { return a.val < b.val; }
	Mint& operator+=(const Mint& m) { if ((val += m.val) >= MOD) val -= MOD; return *this; }
	Mint& operator-=(const Mint& m) { if ((val -= m.val) < 0) val += MOD; return *this; }
	Mint& operator*=(const Mint& m) { val = (ll)val * m.val % MOD; return *this; }
	friend Mint modex(Mint a, ll p) {
		assert(p >= 0);
		Mint ans = 1;
		for (; p; p >>= 1, a *= a) if (p & 1) ans *= a;
		return ans;
	}
	Mint& operator/=(const Mint& m) { return *this *= modex(m, MOD - 2); }
	Mint& operator++() { return *this += 1; }
	Mint& operator--() { return *this -= 1; }
	Mint operator++(int) { Mint result(*this); *this += 1; return result; }
	Mint operator--(int) { Mint result(*this); *this -= 1; return result; }
	Mint operator-() const { return Mint(-val); }
	friend Mint operator+(Mint a, const Mint& b) { return a += b; }
	friend Mint operator-(Mint a, const Mint& b) { return a -= b; }
	friend Mint operator*(Mint a, const Mint& b) { return a *= b; }
	friend Mint operator/(Mint a, const Mint& b) { return a /= b; }
	friend ostream& operator<<(ostream& os, const Mint& x) { return os << x.val; }
};
char str[305];
Mint F[305][305], G[305][305], oldF[305][305];
int main() {
	int K;
	scanf("%s%d", str, &K);
	int n = strlen(str);
	K = min(K, n);
	int num1 = 0;
	vector<int> A;
	for (int i = 0; i <= n; ++i) {
		if (i == n || str[i] == '0') {
			A.push_back(num1);
			num1 = 0;
		} else ++num1;
	}
//	dbv(A);
	int m = A.size();
	for (int k = 0; k <= K; ++k) F[k][0] = 1;
	for (int i = m - 1; i >= 0; --i) {
		swap(F, oldF);
		for (int k = K; k >= 0; --k) {
			for (int j = K; j >= 0; --j) {
				G[k][j] = G[k + 1][j + 1] + oldF[k][j];
			}
			Mint sum = 0;
			for (int j = 0; j <= K; ++j) {
				sum += oldF[k][j];
				if (j > A[i]) sum -= oldF[k][j - A[i] - 1];
				F[k][j] = G[k + 1][j + 1] + sum;
			}
		}
	}
	printf("%d\n", F[0][0].val);
}


Measured memory_bytes: 4856
import sys
def input():return sys.stdin.readline()[:-1]
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
k=N()
s=input()
n=len(s)
N=k+n
mod=10**9+7
fac=[1]*(N+3)
inv=[1]*(N+3)
t=1
for i in range(1,N+3):
    t*=i
    t%=mod
    fac[i]=t
t=pow(fac[N+2],mod-2,mod)
for i in range(N+2,0,-1):
    inv[i]=t
    t*=i
    t%=mod
def comb(n,r):
    if r>n or r<0:
        return 0
    return fac[n]*inv[n-r]*inv[r]%mod
pow26=[1]*(k+1)
pow25=[1]*(k+1)
t1=1
t2=1
for i in range(k+1):
    pow25[i]=t1
    pow26[i]=t2
    t1*=25
    t1%=mod
    t2*=26
    t2%=mod
ans=pow26[k]
for i in range(1,k+1):
    ans+=comb(n+i-1,i)*pow25[i]*pow26[k-i]
    ans%=mod
print(ans)


Measured memory_bytes: 117860
n,m=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
lis=[]
for i in range(m-1):
    lis.append(x[i+1]-x[i])
lis.sort()
ans=0
if n<m:
    for i in range(m-n):
        ans+=lis[i]
print(ans)


Measured memory_bytes: 13968
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MAX 10000

using namespace std;



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

    if((int)N%2 == 0){
        cout  << 0.5000000000 << endl;
    }
    else{
        cout << ((N+1)/2)/N << endl;
    }
    return 0;
}

Measured memory_bytes: 760
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

ll ans;
ll k, n, a[200005];

int main(void) {
    cin >> k >> n;
    rep(i, 0, n) {
        scanf("%lld", &a[i]);
    }
    ll d, sum = 0, mx = -1;
    rep(i, 0, n-1) {
        sum += a[i+1]-a[i];
        mx = max(mx, a[i+1]-a[i]);
    }
    d = k - sum;
    mx = max(d, mx);
    

    cout << k - mx << endl;

	return 0;
}


Measured memory_bytes: 1792
n, m = map(int, input().split())
a = list(map(int, input().split()))

dp = [float('inf') for _ in range(n+1)]
dp[0] = 0

for i in range(n):
    for money in a:
        next_money = i + money
        if next_money > n:
            continue
        dp[next_money] = min(dp[i] + 1, dp[next_money])

print(dp[n])


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

int main() {
    string s,t;
    cin >> s>>t;
    for(int i;i<s.size();i++){
        if(s.at(i)!=t.at(i)){
          cout<<"No"<<endl;
          return 0;
        }
    };
    
    cout<<"Yes"<<endl;
  
  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<bool,int> P;

string s;
string t;
int nxt[400005][26];
int n,m;

ll solve(){
	int cnt=0;
	int pos=0;
	ll ans=0;
	for(int i=0;i<m;i++){
		if(nxt[pos][(t[i]-'a')]==(n*2+1))return -1;
		if(nxt[pos][(t[i]-'a')]>=n){
			cnt++;
			ans+=n;
		}
		pos=nxt[pos][(t[i]-'a')]%n;
	}
	ans+=pos;
	return ans;
}

int main(void){
	cin >> s;
	cin >> t;
	n=s.size();
	m=t.size();
	for(int i=0;i<26;i++){
		nxt[n*2][i]=n*2+1;
	}
	for(int i=n*2-1;i>=0;i--){
		for(int j=0;j<26;j++){
			nxt[i][j]=nxt[i+1][j];
		}
		nxt[i][(s[i%n]-'a')]=i+1;
	}
	printf("%lld\n",(ll)solve());
	return 0;
}


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

int main(){
    int k;
    string s;
    cin >> k >> s;
    if(s.size() > k){
        for(int i = 0; i < k; i++){
            cout << s[i];
        }
        cout << "..." << endl;
    }else{
        cout << s << endl;
    }
    return 0;
}

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

int five(int x)
{
    int y=x/5;
    return 5*y;
}
int main()
{
    long long int x;
    cin>>x;
    if(x<500)
    {
        cout<<five(x);
        return 0;
    }
    else
    {
        int z=x/500;
        int y=five(x%500);
        cout<<1000*z+y;
        return 0;
    }


}


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

int main() {
  int A, B;
  cin >> A >> B;
  int count = 0;
  count = count + max(A,B);
  if(A >= B) {
    A--;
  }
  else {
    B--;
  }
  count = count + max(A,B);
  cout << count << endl;
}


Measured memory_bytes: 256
p_ch = [True] * 9
rot = ((0, 1, 2, 3), (1, 2, 3, 0), (2, 3, 0, 1), (3, 0, 1, 2))
adj = ['c'] * 13

# record indices of right and botoom adjacent edge label. 12 is invalid.
rec_adj = [[0, 2], [1, 3], [12, 4], [5, 7], [6, 8], [12, 9], [10, 12],
           [11, 12], [12, 12]]

# refernce indices to top and left adjacent edge label. 12 is invalid.
ref_adj = [[12, 12], [12, 0], [12, 1], [2, 12], [3, 5], [4, 6], [7, 12],
           [8, 10], [9, 11]]

tr = dict(zip("RGBWrgbw", "rgbwRGBW"))

def dfs(i = 0, a = []):
    if i == 9:
        global ans
        ans += 1
    else:
        for j, p in enumerate(pieces):
            if p_ch[j]:
                ati, ali = ref_adj[i]
                for t, r, b, l in rot:
                    if ati == 12 or tr[p[t]] == adj[ati]:
                        if ali == 12 or tr[p[l]] == adj[ali]:
                            ari, abi = rec_adj[i]
                            adj[ari] = p[r]
                            adj[abi] = p[b]
                            p_ch[j] = False
                            dfs(i + 1)
                            p_ch[j] = True

from sys import stdin
file_input = stdin

N = int(file_input.readline())

for line in file_input:
    pieces = line.split()
    ans = 0
    dfs()
    print(ans)


Measured memory_bytes: 5616
function Main(input){
    input = input.split('\n');
    var input2 = input[0].split(' ');
    
    var h = Number(input2[0]);
    var w = Number(input2[1]);

    var igeta = '';
    for(i = 0; i < w + 2;i++) {
        igeta += '#';
    }
    console.log(igeta);

    for(i = 1; i < h + 1;i++) {
        console.log('#' + input[i] + '#');
    }

    console.log(igeta);
  }
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21192
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> P(N), Visited(N, -1);
	for (int i = 0; i < N; i++) {
		int p;
		cin >> p;
		P[i] = p - 1;
	}
	vector<vector<int>> Tree(N);
	for (int i = 0; i < M; i++) {
		int x, y;
		cin >> x >> y;
		Tree[x - 1].push_back(y - 1);
		Tree[y - 1].push_back(x - 1);
	}
	int ans = 0;
	for (int s = 0; s < N; s++) {
		if (Visited[s] >= 0) continue;
		queue<int> Q;
		vector<int> Route;
		Q.push(s);
		while (!Q.empty()) {
			int v = Q.front();
			Q.pop();
			if (Visited[v] >= 0) continue;
			Visited[v] = s;
			Route.push_back(v);
			for (int u : Tree[v]) Q.push(u);
		}
		for (int v : Route) if (Visited[P[v]] == s) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 7164
#include <iostream>
using namespace std;
typedef long long ll;

int tbl[] = {9,26,75,217,629,1826,5307,15438,44941,130900};
int cnt, K;

int rep(int in, int n, ll out) {
	if (n == 0) {
		cnt++;
		if (cnt == K) cout << out << "\n";
		return 1;
	}
	int ans = 0;
	out *= 10;
	if (in != 0) ans += rep(in - 1, n - 1, out + in - 1);
	ans += rep(in, n - 1, out + in);
	if (in != 9) ans += rep(in + 1, n - 1, out + in + 1);
	return ans;
}

int start(int n) {
	int ans = 0;
	ans += rep(1, n - 1, 1);
	ans += rep(2, n - 1, 2);
	ans += rep(3, n - 1, 3);
	ans += rep(4, n - 1, 4);
	ans += rep(5, n - 1, 5);
	ans += rep(6, n - 1, 6);
	ans += rep(7, n - 1, 7);
	ans += rep(8, n - 1, 8);
	ans += rep(9, n - 1, 9);
	return ans;
}

int main() {
  cin >> K;
  int i;
  for (i = 0; i < 11; i++) {
	  if (cnt + tbl[i] >= K) break;
	  cnt += tbl[i];
  }

  start(i+1);

  return 0;
}


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

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> result(m, 0);
    int k = 0;
    for(int i = 0; i < n; i++){
        k = 0;
        cin >> k;
        vector<int> data(k, 0);
        for(int j = 0; j < k; j++){
            cin >> data.at(j);
        }
        for(int j = 0; j < k; j++){
            result.at(data.at(j)-1)++;
        }
    }

    int ans = 0;;
    for(int i = 0;i < m; i++){
        if(n == result.at(i)){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n, a,b = map(int, raw_input().split())
s = raw_input()

in_pass = 0
out_pass = 0
pass_num = 0

for c in s:
    if c == 'a' and pass_num < a + b:
        in_pass = in_pass + 1
        pass_num = pass_num + 1
        print 'Yes'
    elif c == 'b' and pass_num < a + b and out_pass + 1 <= b:
        out_pass = out_pass + 1
        pass_num = pass_num + 1
        print 'Yes'
    else:
        print 'No'

Measured memory_bytes: 3076
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
#define  st first
#define  nd second
void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"
#define int long long

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef cc_hash_table<int, int, hash<int > > ht;

#define maxn 1000000
#define M   1000000007


int32_t main(){

  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  int n ;
  cin >> n ;
  string s ;
  cin >>s ;
  int cnt = 0 ;
  for ( int i = 0 ; i<s.size()-2 ; i++ ){
    if(s[i]=='A' and s[i+1]=='B' and s[i+2]=='C')
        cnt++ ;
  }
  cout << cnt << "\n" ;
  return 0 ;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 //Compiler version g++ 4.9

 int main()
 {
 	int r, g, b;
 	int num;
 	cin >> r >> g >> b;
 	num = r * 100 + g * 10 + b;
 	if(num % 4 == 0){
 		cout << "YES" << endl;
 	}else{
 		cout << "NO" << endl;
 	} 
 }

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

using namespace std;
int main(){
    int N;
    int a;
    double sum;
    cin >> N;
    for(int i = 0; i < N;i++){ 
        cin >> a;
        sum += 1.0/ a;
    }
    cout << 1.0/ sum << endl;
}

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

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define YN(y, n, b) (b? y : n)
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    i32 N;
    cin >> N;
    Vec<i32> p(N);
    for (i32 i = 0; i < N; i++) cin >> p[i];
    i32 s = 0;
    for (i32 i = 0; i < N - 1; i++) {
        bool sw = false;
        i32 min_i = i;
        for (i32 j = i + 1; j < N; j++) {
            if (p[min_i] > p[j]) {
                min_i = j;
                sw = true;
            }
        }
        if (sw) {
            i32 tmp = p[min_i];
            p[min_i] = p[i];
            p[i] = tmp;
            s++;
        }
    }
    cout << YN("YES", "NO", s <= 1) << endl;
}


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

#define en "\n"
#define INF (int) 9e18
#define HELL 998244353LL
#define int long long
#define double long double
#define uint unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fs first
#define sc second
#define size(a) (int) a.size()
#define deb(x) cerr << #x << " => " << x << en
#define deba(x) cerr << #x << en; for (auto a : x) cerr << a << " "; cerr << en;
#define debp(x) cerr << #x << en; for (auto a : x)cerr<<"("<<a.fs<<", "<<a.sc<<") "; cerr << en;
#define debm(x) cerr << #x << en; for (auto a : x){for(auto b : a) cerr << b << " "; cerr << en;}
#define getMat(x, n, m, val) vector<vector<int>> x(n, vector<int> (m, val))
#define fastio ios_base :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pout cout << fixed << setprecision(10)
int fastpow(int a, int b, int m = HELL) { int res = 1; a %= m;
while (b > 0) { if (b & 1) res = (res * a) % m; a = (a * a) % m; b >>= 1; } return res;}
#define inv(a) fastpow(a, HELL - 2)
#define mul(a, b) ((a % HELL) * (b % HELL)) % HELL

const int maxN = 200005;
vector<int> invN(maxN), fact(maxN), invFact(maxN);
void precomp() {
	fact[0] = fact[1] = invFact[0] = invFact[1] = invN[0] = invN[1] = 1;
	for (int i = 2; i < maxN; i++) {
		invN[i] = mul(HELL - (HELL / i), invN[HELL % i] % HELL);
		fact[i] = mul(fact[i - 1], i);
		invFact[i] = mul(invN[i], invFact[i - 1]);
	}
}
int nck(int n, int k) {
	return mul(invFact[n - k], mul(fact[n], invFact[k]));
}

int32_t main() { fastio;
	precomp();
	int n, m, k;
	cin >> n >> m >> k;
	int ans = 0;
	for (int i = 0; i <= k; i++) {
		int curr = mul(mul(nck(n - 1, i), m), fastpow((m - 1), (n - i - 1)));
		ans = (ans + curr) % HELL;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 7864
package main

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

func check(e error) {
	if e != nil {
		log.Fatalf("error: %v", e)
	}
}

func scanNumber(scanner *bufio.Scanner) int {
	scanner.Scan()
	num, err := strconv.Atoi(scanner.Text())
	check(err)
	return num
}

func main() {
	stdin := bufio.NewScanner(os.Stdin)

	a := scanNumber(stdin)
	b := scanNumber(stdin)
	c := scanNumber(stdin)
	x := scanNumber(stdin)

	var count int

	for aCoins := 0; aCoins <= a; aCoins++ {
		for bCoins := 0; bCoins <= b; bCoins++ {
			for cCoins := 0; cCoins <= c; cCoins++ {
				if sum := 500*aCoins + 100*bCoins + 50*cCoins; sum == x {
					count++
				}
			}
		}
	}

	fmt.Println(count)

}

Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

bool compare(const pii &x, const pii &y) { return x.second < y.second; }

int main() {
    int N;
    cin >> N;
    vector<pii> robot(N);
    rep(i, N) { cin >> robot[i].first >> robot[i].second; }
    vector<pii> kukan(N);
    rep(i, N) {
        kukan[i].first = robot[i].first - robot[i].second;
        kukan[i].second = robot[i].first + robot[i].second;
    }
    sort(All(kukan), compare);

    int f = -INF, res = 0;
    for(int i = 0; i < kukan.size(); i++) {
        if(kukan[i].first >= f) {
            res++;
            f = kukan[i].second;
        }
    }
    cout << res << endl;
    return 0;
}

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

int main(){
  string S;
  cin >> S;
  int L=S.size();
  int ans=0;
  for(int i=L; i>0; i=i-2){
    S.erase(i-2,2);
    int cnt=0;
    for(int j=0; j<(i-2)/2; j++){
      if(S.at(j)==S.at(j+(i-2)/2)) cnt++;
    }
    if(cnt==(i-2)/2){
      ans=i-2;
      break;
    }
  }
  cout << ans << endl;
}

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 x; cin >> x;
    ll ans = 0;
    ll rem = (x / 500);
    ans += 1000 * rem;
    ans += 5 * ((x - 500 * rem) / 5);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define dl double long
const int INF=0x3fffffff;
const ll MOD=1000000007;
const ll MODD=998244353;
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
ll gcd(ll a, ll b) { return (b > 0) ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a*b/gcd(a, b); }
using ipair = pair<ll, ll>;

int main()
{
  ll N, X, ans=1, sum=0;
  cin >> N >> X;
  rep(i, N){
    ll a;
    cin >> a;
    sum += a;
    if(sum <= X) ++ans;
  }
  cout << ans << "\n";
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int N;
int A, B, C;
vector<int> l(100);
int dfs( int cur, int a, int b, int c){

	if (cur == N){
	if (min({ a, b, c }) > 0){
		return abs(A - a) + abs(B - b) + abs(C - c) - 30;
	}
	else return 100000000;
	}
	int ret0 = dfs(cur + 1, a, b, c);
	int ret1 = dfs(cur + 1, a + l[cur], b, c)+10;
	int ret2 = dfs(cur + 1, a, b + l[cur], c)+10;
	int ret3 = dfs(cur + 1, a, b, c + l[cur])+10;
	return min({ ret0, ret1, ret2, ret3 });
}
int main(){

	cin >> N >> A >> B >> C;

	for (int i = 0; i < N; i++){
		cin >> l[i];
	}
	cout << dfs(0, 0, 0, 0) << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H,W;
        while(sc.hasNextLine()){
            String[] str = sc.nextLine().split(" ");
            H = Integer.parseInt(str[0]);
            W = Integer.parseInt(str[1]);
            if(H == 0 && W == 0) break;
            for(int y = 0; y < H; y++){
                for(int x = 0;x < W; x++){
                    System.out.print("#");
                }
                System.out.println();
            }
            System.out.println();
        }
    }

}


Measured memory_bytes: 37824
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	string c, s;
	cin >> c;
	cin >> s;
	int i;
	bool f = true;
	for (i = 0; i < 3; i++)
	{
		if (c.at(i) != s.at(2 - i))
			f = false;
	}
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
} 

Measured memory_bytes: 3640
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    from collections import Counter
    n=int(input())
    A=list(Counter(map(int,input().split())).values())
    A.sort()
    m=len(A)
    S=[0]*(m+1) # cumulative distribution
    for i in range(m): S[i+1]=S[i]+A[i]
    # output
    from bisect import bisect_left
    p=n
    i=bisect_left(A,p) # pに応じてiが定まる
    for k in range(1,n+1):
        while(S[i]+p*(m-i)<k*p): # p>=0 and は書かなくてもよい
            p-=1
            i=bisect_left(A,p)
        print(p)
resolve()

Measured memory_bytes: 120604
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h, w, n,m,k; string s,t;
char maze[60][60];
int dis[101][101]; int graph[52][52]; bool vis[52];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);

}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}

int main() {
	cin >> n >> k;
	vector<ll> a(n);
	vector<ll> b(n);
	ll cnt = 0;
	rep(i, n) {
		cin >> a[i];
		b[i] = 0;
	}
	ll pcnt = 0;
	rep(i, n) {
		for (ll j = i+1; j < n; j++) {
			if (a[i] > a[j]) {
				cnt += k * (k + 1) / 2;
				cnt %= ma;
			}
			else if (a[i] < a[j]) {
				cnt += k * (k - 1) / 2;
				cnt %= ma;
			}
		}
	}
	cout << cnt << endl;
}



Measured memory_bytes: 256
import java.util.Scanner

import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val writer = new java.io.PrintWriter(System.out)
    writer.println(solve(sc))
    writer.flush()
  }

  case class Evaluation(num: Int, city: String, score: Int)

  def solve(sc: Scanner): String = {
    val n = sc.nextInt()
    val evaluations = IndexedSeq.fill(n)((sc.next(), sc.nextInt())).zipWithIndex.map { case ((s, p), i) => Evaluation(i + 1, s, p) }
    debug(n, evaluations)

    val cities = evaluations.map(_.city).sorted.distinct

    cities.foldLeft(ArrayBuffer.empty[Int]) { (acc, city) =>
      evaluations.filter(_.city == city).sortBy(_.score).reverse.foreach { evaluation =>
        acc += evaluation.num
      }
      acc
    }.mkString("\n")
  }

  private def debug(x: Any): Unit = {
    if (System.getenv("LOCAL_DEBUG") != null) println(x)
  }
}


Measured memory_bytes: 25784
#include<iostream>
using namespace std;
int main (){
int n,r;
  cin>>n;
  r=n % 1000;
  if(r>0)
  {
    int ans;
    ans=1000-r;
    cout<<ans<<endl;
  }
  else if(r==0)
  {
    cout<<"0"<<endl;
  }
  return 0;
}
  


Measured memory_bytes: 3188
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <string>
#define SIZE 200005
#define INF 1000000005LL

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int n;
ll K;
int G[10000];

int main()
{
	int H,W,N;
	scanf("%d %d",&H,&W);
	scanf("%d",&N);
	int a;
	int k=0;
	for(int i=0;i<N;i++){
		scanf("%d",&a);
		for(int j=0;j<a;j++){
			G[k] = i+1;
			k++;
		}
	}
	for(int i=0;i<H;i++){
		if(i%2==0){
			continue;
		}else{
			reverse(G+i*W,G+(i+1)*W);
		}
	}
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(j!=0)printf(" ");
			printf("%d",G[i*W+j]);
		}
		printf("\n");
	}
	return 0;
}


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

using namespace std;

pair<int, int> a[111111];
int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		scanf("%d%d", &a[i].first, &a[i].second);
	sort(a, a + n);
	long r = 0;
	for (int i = 0; i < n; i++) {
		long x = min(m, a[i].second);
		r += x * a[i].first;
		m -= x;
	}
	cout << r << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
ll N;
int ret =0;
int dfs(ll x){
    if(x>N)return 0;
    int tmp=0;
    string s=to_string(x);
    if(s.find('7')!=string::npos && s.find('5')!=string::npos && s.find('3')!=string::npos)tmp=1;
    ret += dfs(x*10+7);
    ret += dfs(x*10+5);
    ret += dfs(x*10+3);
    return tmp;
}

int main(int argc, char const *argv[])
{
    cin>>N;
    dfs(0);
    cout << ret<<endl;
    return 0;
}


Measured memory_bytes: 256
while True:
    a, op, b=input().split()
    if op == '?':
        break
    a = int(a)
    b = int(b)
    if op == '+':
        ans = a + b
    if op == '-':
        ans = a - b
    if op == '*':
        ans = a * b
    if op == '/':
        ans = a // b
    print(ans)



Measured memory_bytes: 5592
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
#include <iomanip>
#include <limits>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;

#define ALL(a) (a).begin(),(a).end()
#define INF 1e+9
#define MAX_V 300

struct edge {
    int to;
    int cost;
};
using P = pair<ll, ll>;

int main(){
  int n;cin>>n;
  int a=1000-n%1000;
  if(a==1000){cout<<0<<endl;return 0;}
  cout<<a<<endl;
}


Measured memory_bytes: 3188
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int main()
{
	int w,h,c,t,r,a,b;
	cin>>w>>h>>c;
	if(w>h)
	{
		a=w;
		b=h;
	}
	else
	{
		a=h;
		b=w;
	}
	while((r=a%b)!=0)
	{
		a=b;
		b=r;	
	}
	cout<<(w/b)*(h/b)*c<<endl;
	return 0;
}


Measured memory_bytes: 3104