akhauriyash/Code-Regression huggingface dataset:
def solve(string):
    n, m, *a = map(int, string.split())
    needs = {i + 1: n for i, n in enumerate(map(int, "2 5 5 4 5 6 3 7 6".split()))}
    if 2 in a and 5 in a:
        a.remove(2)
    if 3 in a and 5 in a:
        a.remove(3)
    if 2 in a and 3 in a:
        a.remove(2)
    if 6 in a and 9 in a:
        a.remove(6)
    b = sorted(a, key=lambda x: needs[x])
    index = 0
    base = str(b[0]) * (n // needs[b[0]])
    n %= needs[b[0]]
    while n > 0:
        use = [_b for _b in b if needs[_b] <= needs[b[0]] + n]
        if len(use) == 1:
            base = base[:-1]
            n += needs[b[0]]
        elif max(use) == b[0]:
            tmp_n = use[-1]
            tmp_c = n // (needs[tmp_n] - needs[b[0]])
            base = base[:-tmp_c] + str(tmp_n) * tmp_c
            n -= (needs[tmp_n] - needs[b[0]]) * tmp_c
        else:
            tmp_n = max(use)
            tmp_c = n // (needs[tmp_n] - needs[b[0]])
            base = base[:index] + str(tmp_n) * tmp_c + base[index + tmp_c:]
            n -= (needs[tmp_n] - needs[b[0]]) * tmp_c
            index += tmp_c
    return base


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))
 

Measured memory_bytes: 3064
// 世界は変わらない
#include <bits/stdc++.h>
#define int long long int
#define eb emplace_back
#define vi vector <int>
#define pii pair <int, int>
#define ff first
#define ss second

using namespace std;

void solve()
{
    int n;
    cin >> n;
    cout << ceil(n / 1000.0) * 1000 - n;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 3764
def string_equivalence(n):
    ans = [[]]
    s = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
    for _ in range(n):
        tmp = []
        for a in ans:
            for i in range(len(set(a))+1):
                a_tmp = []
                a_tmp.extend(a)
                a_tmp.append(s[i])
                tmp.append(a_tmp)
        ans = tmp
    for ans_s in ans:
        print(''.join(ans_s))

n = int(input())
string_equivalence(n)

Measured memory_bytes: 31436
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yn(int o){
    if (o == 0) cout << "No" << endl;
    else cout << "Yes" << endl;
}

int cul(int n){
    vector<int> ar(10,0);
    int re = 0;
    rep(i,10){
        ar[i] = n % 10;
        n /= 10;
        re += ar[i];
    }
    return re;
}

int main() {
    int a, b, c; cin >> a >> b >> c;
    if (a == b) cout << c << endl;
    else if (b == c) cout << a << endl;
    else cout << b << endl;
}

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

const int mod=1e9+7;
typedef long long ll;

void U(auto &x,auto y){
    x=(x+y)%mod;
}

int n, N, m, a[22], f[22][101000];

ll K(ll x,ll y=mod-2){
    ll t=1;
    for (;y;y>>=1,x=x*x%mod)
        if (y&1) t=t*x%mod;
    return t;
}

ll jc[101000], inv[101000];
ll C(int x,int y){
    return jc[x]*inv[y]%mod*inv[x-y]%mod;
}

int main(){
    cin>>n>>m; N=1<<n;
    for (int i=0;i<=N;++i){
        jc[i]= i? jc[i-1]*i%mod: 1;
        inv[i]= K(jc[i]);
    }
    for (int i=1;i<=m;++i) cin>>a[i];
    sort(a+1,a+m+1,greater<int>());
    f[0][0]=1;
    for (int i=1;i<=m;++i)
        for (int j=0;j<N;++j)
            if (f[i-1][j]){
                U(f[i][j],f[i-1][j]);
                for (int k=0;k<n;++k)
                    if (!(j>>k&1)){
                        int las=N-a[i]+1-j;
                        if (las<(1<<k)) continue;
                        U(f[i][j|1<<k],mod-f[i-1][j]*C(las-1,(1<<k)-1)%mod);
                    }
            }
    int ans=0;
    for (int j=0;j<N;++j)
        if (f[m][j]){
            ll tmp=f[m][j]; int las=N-1-j;
            for (int k=0;k<n;++k)
                if (!(j>>k&1)){
                    tmp=tmp*C(las,1<<k)%mod;
                    las-=1<<k;
                }
            U(ans,tmp);
        }
    for (int i=0;i<n;++i)
        ans=(ll)ans*jc[1<<i]%mod;
    cout<<(ll)ans*N%mod<<endl;
}

Measured memory_bytes: 7424
/**
 *     author: nayakashutosh9
 *     college: National Institute of Technology, Rourkela
**/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define mod 1000000007
#define inf 1e18
const int N = 200005;

/*******************************************************************/




int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	// int t, z = 1; cin >> t;
	// cin.ignore();
	// while (t--) {

	// }
	char a;cin>>a;
	if(a>=65 && a<=90) cout<<"A\n";
	else cout<<"a\n";
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
 
using namespace std;
 
#define int long long 
#define INF 1e9
#define LINF 1e18
 
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> Pi;
typedef pair<P, P> PP;
 
const int MOD = 1e9 + 7;
const int dy[] = { 0, 0, 1, -1 };
const int dx[] = { 1, -1, 0, 0 };
 
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int fact[200001];
vector<P> prime_counter;

int elePow(int a, int b) {
	int num = 1;
	while(b != 0) {
		if(b & 1) num = num * a % MOD;
		b /= 2;
		a = a * a % MOD;
	}
	return num;
}

int nCr(int n, int r) {
	if(r > n) return 0;
	if(r == 0) return 1;
	int a = fact[n], b = 1ll * fact[r] * fact[n - r] % MOD;
	int res = a * elePow(b, MOD - 2) % MOD;
	return res;
}

void Prime_Factorize(int n) {
    for(int i = 2; i * i <= n; ++i) {
        if(n % i != 0) continue;
        int cnt = 0;
        while(n % i == 0) { ++cnt; n /= i; }
        prime_counter.push_back(P(i, cnt));
    }
    if(n != 1) prime_counter.push_back(P(n, 1));
}

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

    int N, M;
    cin >> N >> M;
    Prime_Factorize(M);
    fact[0] = fact[1] = 1;
    for(int i = 2; i <= 200000; ++i) {
        fact[i] = fact[i - 1] * i;
        fact[i] %= MOD;
    }
    int res = 1;
    for(int i = 0; i < prime_counter.size(); ++i) {
        int latte = prime_counter[i].second;
        int malta = nCr(N + latte - 1, N - 1);
        res = (res * malta) % MOD;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1792
N = int(input())
CSF = [list(map(int,input().split())) for _ in [0]*(N-1)]
for i in range(N-1):
    ans = CSF[i][0] + CSF[i][1]
    for j in range(i+1,N-1):
        c,s,f = CSF[j]
        ans = ((max(s,ans)-1)//f +1 )*f + c
    print(ans)
print(0)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

int main() {
  i64 K;
  cin >> K;
  i64 MAX = 600;
  vector<vector<i64>> dp(MAX, vector<i64>(7, 0));
  rep(i,0,MAX) {
    dp[i][6] = 1;
  }
  for(i64 i = 5; i >= 0; i--) {
    i64 sum = 0;
    for(int j = MAX - 1;j >= 0;j--) {
      sum += dp[j][i + 1];
      dp[j][i] = sum;
    }
  }

  for(i64 i = MAX - 2; i >= 0; i--) {
    dp[i][0] += dp[i + 1][0];
  }

  for(int i = 0;i < MAX;i++) {
    i64 cnt = K / dp[i][0];
    K = K % dp[i][0];
    rep(q, 0, cnt) {
      cout << 'F';
    }
    cout << "ESTIVAL";
  }
  cout << endl;
}


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

int main(void){
  int n,m,sum;
  char s[410];
  
  while (1){
    cin >> s;
    if (s[0]=='-') break;
    n = strlen(s);
    strcpy(s+n, s);
    cin >> m;
    sum=0;
    for (int i=0; i<m; i++){
      int t;
      cin >> t;
      sum += t;
    }
    for (int i=0; i<n; i++) cout<<s[sum%n+i];
    cout << endl;
  }   
   
  return 0;
}



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

int main()
{
	int n;
	std::cin >> n;

	std::vector<int> a(n);
	std::vector<int> r(n);
	for (int i = 0; i < n; ++i)
		std::cin >> a[i];

	int max = 0;
	for (int i = 0; i < n; ++i)
		max = std::max(max, a[i]);

	for (int i = 0;; ++i)
	{
		int tar = 1 << i;
		if (tar > max) break;

		// 0となるものを探す
		int num = 0;
		for (int j = 0; j < n; ++j)
			if (a[j] & tar)
				++num;

		if (num % 2)
		{
			for (int j = 0; j < n; ++j)
				if (!(a[j] & tar)) r[j] += tar;
		}
		else
		{
			for (int j = 0; j < n; ++j)
				if ((a[j] & tar)) r[j] += tar;
		}
	}

	for (int i = 0; i < n; ++i)
		std::cout << r[i] << " ";
}


Measured memory_bytes: 4732
#include <stdio.h>
#include <string.h>

int main(void){
    int i, b;
    char S[105];
    scanf("%s", S);
    b=1;
    for (i=0; i<strlen(S); i++) {
        if ((S[i]=='L' && i%2==0) || (S[i]=='R' && i%2==1)) {
            b=0;
            break;
        }
    }
    if (b==1) printf("Yes");
    else printf("No");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }
template<class T>
ostream &operator<<(ostream &os,const vector<T> &v){
	for(int i = 0;i < v.size();i++) os << (i ? "," : "[") << v[i];
	os << "]";
	return os;
}

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }

const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int a[3][3],flag[3][3] = {};
	for(int i = 0;i < 3;i++){
		for(int j = 0;j < 3;j++) cin >> a[i][j];
	}
	int n,b[100];
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> b[i];
		for(int j = 0;j < 3;j++){
			for(int k = 0;k < 3;k++){
				if(a[j][k] == b[i]) flag[j][k] = 1;
			}
		}
	}
	bool isBingo = false;
	for(int i = 0;i < 3;i++){
		bool isOK = true;
		for(int j = 0;j < 3;j++){
			if(!flag[i][j]) isOK = false;
		}
		isBingo |= isOK;
		isOK = true;
		for(int j = 0;j < 3;j++){
			if(!flag[j][i]) isOK = false;
		}
		isBingo |= isOK;
	}
	isBingo |= (flag[0][0] && flag[1][1] && flag[2][2]) | (flag[0][2] && flag[1][1] && flag[2][0]);
	isYes(isBingo);
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <utility>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define each(e,c) for(auto&e:c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif
template<class T> ostream& operator<<(ostream& os, vector<T> const& v){
    rep(i,v.size()) os << v[i] << (i+1==v.size()?"":" ");
    return os;
}

int main(){
    int N,Q;
    while(cin >> N >> Q && N){
        vi a(1000);
        rep(i,N){
            int m; cin >> m;
            rep(j,m){
                int d; cin >> d;
                a[d]++;
            }
        }

        int ans = max_element(all(a))-a.begin();
        ans = a[ans] >= Q ? ans : 0;
        cout << ans << endl;
    }
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF = 0x3f3f3f3f;
const ll mod  = 1e9 + 7;
const ll N = 1e6 + 5;

ll n,a[N],sum,ans;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n;
    for(int i=1;i<=n;i++){
    	cin>>a[i];
    	sum=(sum+a[i])%mod;
    }
    for(int i=1;i<=n;i++){
    	sum=(sum-a[i]+mod)%mod;
    	ans=(ans+a[i]*sum%mod)%mod;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 5156
s = input()
t = input()

ans = False
for _ in range(len(s)):
    l = list(s)
    c = l.pop(-1)
    l.insert(0, c)
    s = ''.join(l)
    
    # print(s)
    if s == t:
        ans = True
        break
    
if ans:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 8980
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    string S;
    cin >> S;
    const string T = "CODEFESTIVAL2016";
    int cnt = 0;
    rep(i, S.size()) {
        if(S.at(i) != T.at(i)) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
public class Hello{
    static int cmp(string a,string b){
        var hash = new HashSet<char>{};
        for(int i = 0;i < a.Length;i++){
            for(int j = 0;j < b.Length;j++){
                if(a[i] == b[j]){
                    hash.Add(a[i]);
                }
            }
        }
        return hash.Count;
    }
    public static void Main(){
        int n = int.Parse(Console.ReadLine());
        string s = Console.ReadLine();
        int max = 0;
        for(int i = 0;i < n;i++){
            int temp = cmp(s.Substring(0,i),s.Substring(i));
            max = Math.Max(max,temp);
        }
        Console.WriteLine(max);
    }
}


Measured memory_bytes: 13396
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] a = new long[n];
    for(int i = 0; i < n; i++) {
      a[i] = sc.nextLong();
    }
    Arrays.sort(a);
    long ans = a[n - 1];
    for(int i = 4; i < n + 2; i++) {
      int d = n - (i / 2);
      ans += a[d];
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 61580
/*
    Author : DemonStar
*/

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx2,tune=native")

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define ll long long
#define pi pair<int, int>
#define pl pair<long long, long long>
#define pld pair<long double, long double>
#define endl '\n'
#define loop(i, n) for (ll i = 0; i < n; i++)
#define rep(i, begin, end) for (__typeof(begin) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(x) x.begin(), x.end()
#define vl vector<ll>
#define vi vector<int>
#define ml map<ll, ll>
#define vpl vector<pair<ll, ll>>
const ll mod = 1e9 + 7;

template <typename T, typename TT>
ostream &operator<<(ostream &os, const pair<T, TT> &t)
{
    return os << t.first << " " << t.second;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &t)
{
    for (auto &i : t)
        os << i << " ";
    return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
    for (T &t : v)
        is >> t;
    return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, vector<pair<T1, T2>> &v)
{
    for (pair<T1, T2> &t : v)
        is >> t.first >> t.second;
    return is;
}

int main()
{
    fast;
    int n, w;
    cin >> n >> w;
    vpl v(n);
    cin >> v;
    vl dp(w + 1, 0);
    dp[0] = 0;
    loop(i, n)
    {
        for (int j = w; j >= 0; j--)
            if (j - v[i].first >= 0)
                dp[j] = max(dp[j], dp[j - v[i].first] + v[i].second);
    }
    cout << dp[w] << endl;

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

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<set>
#include<queue>
#include<vector>
#include<cstdio>
#include<map>
#include<iomanip>
using namespace std;
int a[11111];
int main()
{
  int n;
  cin>>n;
  for(int i=0;i<n;i++)
    cin>>a[i];
  long long ans=0;
  for(int i=0;i<n;i++)
    while(a[i]%2==0){
      a[i]/=2;
      ans++;
    }
  cout<<ans;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

#define LIM 100000
class UnionFind {
	vector<int>par, sz1,sz2;
public:
	UnionFind() {}
	UnionFind(int n) {
		par = sz1 = sz2= vector<int>(n);
		for (int i = 0; i < n; i++) {
			par[i] = i;
			if(i<LIM)sz1[i] = 1;
			else sz2[i]=1;
		}
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (sz1[x] > sz1[y]) {
			par[y] = x;
			sz1[x] += sz1[y];
			sz2[x]+=sz2[y];
		}
		else {
			par[x] = y;
			sz1[y] += sz1[x];
			sz2[y]+=sz2[x];
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size1(int x) {
		return sz1[find(x)];
	}
	int size2(int x){
		return sz2[find(x)];
	}
};
int main(){
	int n;cin>>n;
	UnionFind uf(300000);
	rep(i,n){
		int x,y;scanf("%d%d",&x,&y);x--;y--;
		uf.unite(x,y+100000);
	}
	ll ans=0;
	rep(i,300000){
		if(uf.find(i)==i){
			ll s1=uf.size1(i),s2=uf.size2(i);
			ans+=s1*s2;
		}
	}
	cout<<ans-n<<endl;
}

Measured memory_bytes: 3712
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    int ans = 0;
    REP(a, A + 1) {
        REP(b, B + 1) {
            REP(c, C + 1) {
                if (a * 500 + b * 100 + c * 50 == X) {
                    ans++;
                }
            }
        }
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 764
def test():

	s_original = input()
	s_string = list(s_original+s_original)
	p_string = list(input())

	for i in range(len(s_string) - len(p_string)):
		
		comp_progress = 0

		for j in range(len(p_string)):
			
			if p_string[comp_progress] == s_string[i+j]:
				comp_progress += 1
			else:
				break
			
		if comp_progress == len(p_string):
			break
	
	if comp_progress == len(p_string):
		print("Yes")
	else:
		print("No")

if __name__ == "__main__":
	test()


Measured memory_bytes: 5564
n = int(input())
L = list(map(int,input().split()))
#h = L[0]
L = [0]+L
h = 0
cnt = 0
for i in range(1,n+1):
    if L[i-1] < L[i]:
        h += L[i] - L[i-1]
        if i == n:
            cnt +=h
    elif L[i-1] >= L[i]:
        cnt +=h
        h = 0

print(cnt)

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

struct Edge {int from, to, weight;};
using Graph = vector<vector<Edge>>;

int D, N;
string TEXT;
vector<string> PIECE;

set<string> OK;

string text;

int DP[43][43];

bool Levenshtein(auto p) {
  for(auto i = p; i <= text.size(); ++i) {
    auto d = D + 1;
    for(auto j = 1; j <= TEXT.size(); ++j) {
      if(text[i-1] == TEXT[j-1]) DP[i][j] = DP[i-1][j-1];
      else                       DP[i][j] = 1 + min({DP[i-1][j], DP[i][j-1], DP[i-1][j-1]});
      d = min(d, DP[i][j]);
    }
    if(D < d) return false;
  }
  return true;
}

void dfs(const auto& G, auto& used, auto cur) {
  if(TEXT.size() + D < text.size()) return;

  if(!Levenshtein(text.size() - PIECE[cur].size() + 1)) return;

  if(used.count(text)) return;
  used.emplace(text);

  if(DP[text.size()][TEXT.size()] <= D) OK.emplace(text);

  auto dup = text;
  for(auto e: G[cur]) {
    text = dup + PIECE[e.to].substr(e.weight);
    dfs(G, used, e.to);
  }
  text = dup;
}

void solve() {
  Graph G(N);
  for(auto i = 0; i < N; ++i) for(auto j = 0; j < N; ++j) {
    auto lhs = PIECE[i];
    auto rhs = PIECE[j];
    for(auto k = 0; k < lhs.size(); ++k) if(lhs.substr(lhs.size() - k) == rhs.substr(0, k)) G[i].push_back({i, j, k});
  }
 
  unordered_set<string> used;
  for(auto i = 0; i < N; ++i) {
    text = PIECE[i];
    dfs(G, used, i);
  }
}

int main() {
  for(auto i = 0; i < 43; ++i) DP[i][0] = DP[0][i] = i;

  while(cin >> D >> N, D | N) {
    cin >> TEXT;
    PIECE = vector<string>(N);
    for(auto& i: PIECE) cin >> i;
 
    sort(begin(PIECE), end(PIECE));
    PIECE.erase(unique(begin(PIECE), end(PIECE)), end(PIECE));
    N = PIECE.size();
 
    OK.clear();
    solve();
    cout << OK.size() << endl;
    if(OK.size() <= 5) for(auto i: OK) cout << i << endl;
  }
}

Measured memory_bytes: 26128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v
#define NUM(x,v) (POSU(x,v)-POSL(x,v))
const ll INF=1e9+7;
const ll N = 100003;
ll n,a[N],ans=0;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	FOR(i,0,n){
		cin>>a[i];
	}
	// start +
	ll w=0;
	FOR(i,0,n){
		if(i%2==1){
			// S < 0
			if(w+a[i]>=0){
				ans+=(w+a[i])+1;
				w=-1;
			}else{
				w+=a[i];
			}
		}else{
			//s>0
			if(w+a[i]<=0){
				ans+=1-(w+a[i]);
				w=1;
			}else{
				w+=a[i];
			}
		}
	}
	// start -
	ll ans2=0;
	w=0;
	FOR(i,0,n){
		if(i%2==0){
			// S < 0
			if(w+a[i]>=0){
				ans2+=(w+a[i])+1;
				w=-1;
			}else{
				w+=a[i];
			}
		}else{
			//s>0
			if(w+a[i]<=0){
				ans2+=1-(w+a[i]);
				w=1;
			}else{
				w+=a[i];
			}
		}
	}
	cout<<min(ans,ans2)<<endl;
	return 0;
}

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

int n,k;
vector<int> c;

void init(){
  c.clear();
}

bool input(){
  cin>>n>>k;
  if(n==0&&k==0)return false;
  for(int i=0;i<n;i++){
    int tmp;
    cin>>tmp;
    c.push_back(tmp);
  }
  return true;
}

int cal(vector<int> cc){
  int res = 0;
  int tmp = 1;
  for(int i=0;i<cc.size();i++){
    if(i<k){
      tmp *= cc[i];
    }else{
      tmp /= cc[i-k];
      tmp *= cc[i];
    }
    res = max(res,tmp);
  }
  return res;
}

int solve(){
  int cc = cal(c);
  
  vector<int> tmp = c;
  int ccc=0;
  for(int i=0;i<tmp.size();i++){
    for(int j=0;j<tmp.size();j++){
      swap(tmp[i],tmp[j]);
      ccc = max(ccc,cal(tmp));
      tmp = c;
    }
  } 
  return ccc - cc;
}

int main(){
  while(init(),input()){
    int ans = solve();
    if(ans<0){
      cout<<"NO GAME"<<endl;
    }else{
      cout<< ans <<endl;
    }
  }
  return 0;
}

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

int main() {
  string S; cin >> S;
  int ans = 0;
  int n = 0;
  for (char s : S) {
    if (s == 'A' || s == 'C' || s == 'G' || s == 'T') n++;
    else n = 0;
    if (ans < n) ans = n;
  }
  cout << ans<< endl;
}


Measured memory_bytes: 256
import scala.io.StdIn

object Main extends App {
  
  case class Card(mark: String, number: Int){
    override def toString: String = f"$mark $number%n"
  }
  val n = StdIn.readLine().trim.toInt
  val ar1 = new Array[Card](n)
  val ar2 = new Array[Card](n)
  (0 until n).foreach{ i =>
    val Array(m, num) = StdIn.readLine().trim.split(' ')
    ar1(i) = Card(m, num.toInt)
    ar2(i) = Card(m, num.toInt)
  } 


  def quickSort(target: Array[Card], partIndex: Int, size: Int): Unit = {

    val last = target(size)

    @inline def swap(from: Int, to: Int): Unit = {
      //println(s"from: $from  to: $to")
      val temp = target(from)
      target(from) = target(to)
      target(to)   = temp
    }

    def partition(arr: Array[Card], p: Int, r: Int): Int = {
      var i = p - 1
      (p until r).foreach{ j =>
        if(arr(j).number <= last.number){
          i += 1
          swap(i, j)
          //println(a.toList.mkString(" "))
        }
      }
      swap(i+1, r)
      //println("last:" + a.toList.mkString(" "))
      i + 1
    }

    if(partIndex < size){
      val newIndex = partition(target, partIndex, size)
      quickSort(target, partIndex, newIndex - 1)
      quickSort(target, newIndex + 1, size)
    }
    
    
  }
  //println(s"num: $partitionIndex")

  final val infity = Int.MaxValue
  def mergeSort(): Unit = {
    var compareCount = 0

    @inline def copyToArray(start: Int, end: Int): Array[Card] = {
      val alsize = end - start + 1
      val ar = new Array[Card](alsize)
      Array.copy(ar2, start, ar, 0, alsize - 1)
      ar(alsize-1) = Card("", infity)
      ar
    }

    def merge(left: Int, mid: Int, right: Int): Unit ={
      //var al = a.slice(left, mid) ++ Array(infity)
      val al = copyToArray(left, mid)

      //var ar = a.slice(mid, right) ++ Array(infity)
      val ar = copyToArray(mid, right)
      var i = 0
      var j = 0
      //println("left:" + al.toList)
      //println("right:" + ar.toList)
      (left until right).foreach{ k =>
        compareCount += 1
        if(al(i).number <= ar(j).number){
          ar2(k) = al(i)
          i += 1
        } else {
          ar2(k) = ar(j)
          j += 1
        }
      }
      //println("all:" + ar2.toList.mkString(" "))
    }

    def innerMergeSort(left: Int, right: Int): Unit ={
      if(left+1 < right){
        val mid = (left + right) / 2
        innerMergeSort(left, mid)
        innerMergeSort(mid, right)
        merge(left, mid, right)
      }
    }

    innerMergeSort(0, ar2.length)

  }



  quickSort(ar1, 0, n - 1)
  mergeSort()
  
  var k = 0
  var same = true
  while(k < n && same) {
    same = ar1(k) == ar2(k)
    k += 1
  }
  
  println(if(same) "Stable" else "Not stable")
  print(ar1.mkString(""))
  //print(ar2.mkString(""))

}


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

int main(){
  int N,ans=0;
  cin >> N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin >> vec[i];
  }
  for(int j=1;j<N-1;j++){
    if(vec[j-1]>vec[j]&&vec[j]>vec[j+1])
      ans++;
    if(vec[j-1]<vec[j]&&vec[j]<vec[j+1])
      ans++;
  }
  cout << ans << endl;
}

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

int main(){
    int n;
    vector<int> a;
    double sum = 0;

    cin >> n;
    a.resize(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }

    for(auto i : a){
        sum += 1.0 / (double)i;
    }
    sum = 1.0 / sum;

    cout << setprecision(16) <<  sum << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.AbstractMap;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		solve(sc,out);

		out.flush();
	}

	public static void solve(FastScanner sc, PrintWriter out) {
		String s  = sc.next();
		int day = s.length();
		
		int cnt  =0;
		for(int i = 0; i < s.length(); i++) {
			if(s.charAt(i) == 'o') cnt++;
		}
		
		int left = 15 - day;
		
		out.println(cnt + left >= 8 ? "YES" : "NO");
	}

	public static int gcd(int a, int b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}

	public static long gcd(long a, long b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(final K key, final V value) {
        super(key, value);
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 21332
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)
int Min(int a, int b, int c) {
	if (a <= b) { return std::min(a, c); }
	else return std::min(b, c);
}
int Max(int a, int b, int c) {
	if (a >= b) { return std::max(a, c); }
	else return std::max(b, c);
}
int main(void) {
	int res = 0;
	int a, b; cin >> a >> b;
	if (b >= a)res++;
	res += a-1;
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> //ABC 163_b
#define ll long long
using namespace std;
int d,n,t;
int main(){
	cin>>d>>n;
	for(int i=1;i<=n;i++){
		cin>>t;
		d-=t;
	}
	if(d>=0)
		cout<<d;
	else
		cout<<-1;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t N,cnt=0;
  cin >> N;
  vector<int> A(N+1), B(N);  
   
  for(int i=0;i<N+1;i++) cin >> A.at(i);
  for(int i=0;i<N;i++) cin >> B.at(i);
  
  for(int i=0;i<N;i++){
    cnt=cnt+min(A.at(i),B.at(i));
    cnt=cnt+min(A.at(i+1),B.at(i)-min(A.at(i),B.at(i)));
    A.at(i+1)=A.at(i+1)-min(A.at(i+1),B.at(i)-min(A.at(i),B.at(i)));
  }
  
  cout << cnt <<endl;

}


Measured memory_bytes: 1024
from collections import Counter

N = int(input())
A = list(map(int, input().split()))

A.sort(reverse=True)
c = Counter(A)
res = 0
for a in A:
    n = 2 ** a.bit_length() - a
    if n in c.keys():
        if a == n and c[a] > 1:
            c[a] -= 2
            res += 1
        elif a != n and c[a] > 0 and c[n] > 0:
            c[a] -= 1
            c[n] -= 1
            res += 1
    
print(res)
    



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

using namespace std;

int main() {

	int a;
	int b;
	cin >> a;
	cin >> b;

	if (a == 0) {
		if (b == 100) cout << 101;
		else cout << b;
	}

	if (a == 1) {
		if (b ==100) cout << 10100;
		else cout << b * 100;
	}

	if (a == 2) {
		if (b == 100) cout << 1010000;
		else cout << b * 10000;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a<b?a:b
#define REP(i,x,n) for(int i=x;i<n;i++)
#define REPR(i,x,n) for(int i=n-1;i>=x;i--)
#define pb  push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLr(obj) (obj).rbegin(), (obj).rend()
#define endl "\n"
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;



int main(){
  int n,x,y;
  cin>>n>>x>>y;
  ll ans[2020]={};
  // rep(i,n+x-y-1){
  //   ans[i]=n+x-y;
  // }
  // REP(i,x,y){
  //   REP(j,i,y){
    
  //   }
  // }
  rep(i,n-1){
    REP(j,i+1,n){
      ans[min(j-i,abs(i+1-x)+abs(j+1-y)+1)]++;
    }
  }
  rep(i,n-1){
    cout<<ans[i+1]<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
using namespace std;
const int INF = 1e9;

int main(void) {
  int h, n;
  cin >> h >> n;
  
  int a[n], b[n];
  for(int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  
  int dp[n+1][h+1];
  for(int i = 0; i <= n; i++) {
    for(int j = 0; j <= h; j++) {
      dp[i][j] = INF;
    }
  }
  dp[0][0] = 0;
  
  for(int i = 0; i < n; i++) {
    for(int j = 0; j <= h; j++) {
      if(dp[i][j] < dp[i+1][j]) {
        dp[i+1][j] = dp[i][j];
      }
      if(j+a[i] < h) {
        if(dp[i+1][j]+b[i] < dp[i+1][j+a[i]]) {
          dp[i+1][j+a[i]] = dp[i+1][j] + b[i];
        }
      } else {
        if(dp[i+1][j]+b[i] < dp[i+1][h]) {
          dp[i+1][h] = dp[i+1][j] + b[i];
        }
      }
    }
  }
  
  /*
  // debug mes
  for(int i = 0; i <= n; i++) {
    for(int j = 0; j <= h; j++) {
      if(dp[i][j] == INF) {
        cout << "INF ";
      } else {
        cout << setw(3) << dp[i][j] << " ";
      }
    }
    cout << endl;
  }
  */
  
  cout << dp[n][h] << endl;
  return 0;
}

Measured memory_bytes: 39296
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl 
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl 
#define no cout<<"no"<<endl
#define vec(a,y,x)  vector<vector<char>> a (y,vector<char>(x))
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};
const in MOD = 1000000007;

int main(){
  in n,k;
  cin>>n>>k;
  in ans=0;
  in ans1=0;
  for(int i=k;i<n+2;i++){
    in a=(1+i*(n-i+1))%MOD;
    ans=(ans+a)%MOD;
    ans1 += 1+i*(n-i+1);
  }
  printf("%ld\n",ans);
  //cout<<220280457-ans<<endl;
}

Measured memory_bytes: 3728
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main() {
    long long int n, ans = 0;
    cin >> n;
    int a[n], b[n], c[n-1], pre_a;
    for(int i = 0; i < n; ++i) cin >> a[i];
    for(int i = 0; i < n; ++i) cin >> b[i];
    for(int i = 0; i < n-1; ++i) cin >> c[i];
    ans += b[a[0]-1];
    pre_a = a[0]-1;
    for(int i = 1; i < n; ++i) {
        if(pre_a + 1 == a[i] - 1) {
            ans += b[a[i]-1] + c[a[i]-2];
        } else {
            ans += b[a[i]-1];
        }
        pre_a = a[i]-1;
    }
    cout << ans << '\n';
}

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

int main(){
    int n;
    int f=0,quo;

    cin >> n;

    quo = n;
    
    while(quo > 0){
        f += quo % 10;
        quo /= 10;
    }

    if(n % f == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @author Pavel Mavrin
 */
public class Main {

    private void solve() throws IOException {
        int n = nextInt();
        init(n);
        for (int i = 0; i < n - 1; i++) {
            int x = nextInt() - 1;
            int y = nextInt() - 1;
            int z = nextInt();
            addEdge(x, y, z);
        }
        dfs(0, -1);
//        System.out.println(res);
        if (!ok) {
            int min = Integer.MAX_VALUE;
            int j = head[centr];
            while (j >= 0) {
                min = Math.min(min, cost[j]);
                j = nx[j];
            }
            res -= min;
        }
        out.println(res);
    }


    void init(int n) {
        this.n = n;
        this.m = (n - 1) * 2;
        last = 0;
        head = new int[n];
        nx = new int[m];
        dst = new int[m];
        cost = new int[m];
        Arrays.fill(head, -1);
    }


    void addEdge(int x, int y, int c) {
        nx[last] = head[x];
        dst[last] = y;
        cost[last] = c;
        head[x] = last;
        last++;
        nx[last] = head[y];
        dst[last] = x;
        cost[last] = c;
        head[y] = last;
        last++;
    }

    long res = 0;
    int centr = -1;
    boolean ok = false;

    private int dfs(int x, int p) {
        int j = head[x];
        int s = 1;
        boolean cc = true;
        while (j >= 0) {
            int y = dst[j];
            if (y != p) {
                int z = dfs(y, x);
                if (2 * z > n) cc = false;
                int xx = z;
                int yy = n - xx;
//                System.out.println(cost[j] + " " + xx + " " + yy);
                if (xx == yy) {
                    res += 1l * cost[j] * (xx * 2 - 1);
                    ok = true;
                } else {
                    res += 1l * cost[j] * Math.min(xx, yy) * 2;
                }
                s += z;
            }
            j = nx[j];
        }
        if (2 * s <= n) {
            cc = false;
        }
        if (cc) {
            centr = x;
        }
        return s;
    }

    int n, m;
    int[] head;
    int[] nx;
    int[] dst;
    int[] cost;
    int last;



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

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;
    PrintWriter out = new PrintWriter(System.out);

    String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    private void run() throws IOException {
        solve();
        out.close();
    }

}


Measured memory_bytes: 58676
#include <iostream>
#include<algorithm>
using namespace std;
int main(void){
    int N, x = 0, max = 0, j = 0;
    
    cin >> N;
    
    int H[N];
    
    for(int i = 0; i < N; i++){
        cin >> H[i];
    }
    
    while(j < N-1){
        if(H[j] >= H[j+1]){
            x++;
            if(max < x)  max = x;
        }else{
            x = 0;
        }
        j++;
    }
    
    cout << max;
    
    return 0;
}
    
    

Measured memory_bytes: 640
program distinct_numbers
  implicit none
  integer :: n, m = 0, i, k, x
  integer, dimension(0:300001) :: a = 0, b = 0, s = 0
  read(*,*) n
  read(*,*) b(1:n)
  do i = 1, n
    a(b(i)) = a(b(i))+1
  end do
  call quick_sort(a(1:n))
  do i = 1, n
    s(i) = s(i-1)+a(i)
  end do
  i = n
  x = n
  do k = 1, n
    do
      do while (i > 0 .and. a(i) >= x)
        i = i-1
      end do
      if (x*(n-i)+s(i) >= x*k) exit
      x = x-1
    end do
    write(*,'(i0)') x
  end do
contains
  recursive subroutine quick_sort(a)
    integer, intent(inout) :: a(:)
    integer :: n, l, r, m
    integer :: p
    n = size(a,1)
    l = 1
    r = n
    m = (n+1)/2
    p = a(l)+a(m)+a(r)-max(a(l),a(m),a(r))-min(a(l),a(m),a(r))
    do
      do while (a(l) < p)
        l = l+1
      end do
      do while (a(r) > p)
        r = r-1
      end do
      if (l >= r) exit
      a(l) = xor(a(l),a(r))
      a(r) = xor(a(l),a(r))
      a(l) = xor(a(l),a(r))
      l = l+1
      r = r-1
    end do
    if (l-1 > 1) call quick_sort(a(1:l-1))
    if (n > r+1) call quick_sort(a(r+1:n))
  end
end program distinct_numbers

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;

int h,w,x;
char s[1000][1000];
bool visited [1000][1000];
pair<int,int> start,goal;
queue<pair<int,pair<int,int>>> q;
vector<pair<int,int>> ino;

int main(){
  //string a,b,c,d;cin>>a>>b>>c>>d;
  int a,b;char o;cin>>a>>o>>b;
  if(o=='+'){
    cout << a+b;
  }else{
    cout << a-b;
  }
}


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


int main()
{
    int a,b,k,n,m;
    scanf("%d",&k);
    scanf("%d %d",&a,&b);

    for(n=a;n<=b;n++)
    {
        if(n%k==0)
        {
            printf("OK");
            return 0;
        }
    }
    printf("NG");
    return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <math.h>
#include <string>
#include <climits>
#include <algorithm>

using namespace std;
int main()
{	
	int ans=0, i, j, k;
	int N, p[10000];
	cin >> N;
	for (i = 0; i < N;i++){
		cin >> p[i];
	}

	sort(p, p+N);
	for (i = 0; i < N-1;i++){
		ans += p[i];
	}

	cout << ans+p[N-1]/2 << endl;
	return 0;
}

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

int main()
{
// #ifndef ONLINE_JUDGE
//     freopen("input.txt","r",stdin);
// #endif
    char ch = '#';
    int n ;
    cin>>n;
    string s;
    cin>>s;
    int ans = 0;
    for(int i = 0 ;i<n;i++)
    {
        if(s[i]!=ch)
        {
            ans++;
            ch=s[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, n) for(int i = 0; i <= (int)(n); i++)
int main(void)
{
   ll ten,fiv,onee;
   ll N,Y;
   cin >> N >> Y;
   Y/=(ll)1000;
   rep2(i,(Y/10))
   {
        rep2(j,(Y-i*10)/5)
        {
            if(N-i-j + i*10 + j*5 == Y)
            {
                cout << i << " " << j << " " << N-i-j << endl;
                return 0;
            }
        }    
   }
   cout << "-1 -1 -1" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<time.h>
#include<string>
#include<cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include <limits>
#include <climits>
#include <numeric>
#include<cassert>
#include<cctype>
#include<iterator>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=c_max(x,a)
#define chmin(x,a) x=c_min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
#define MOD 1000000007
#define INF 1<<30
#define INFTY 1000000000000000001LL
#define MAX_INT INT_MAX
#define Endl '\n'
#define greater greater<int>()
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
using Graph=vector<vector<int> >;//int と P
// g++ -o a a.cpp -Wall -lm -std=c++14

int main(){
    int n,x,y;
    cin>>n>>x>>y;
    --x;--y;
    VI res(n,0);
    rep(i,n){
        for(int j=i+1;j<n;j++){
            int d=min({abs(i-j),abs(i-x)+abs(j-y)+1,abs(i-y)+abs(j-x)+1});
            res[d]++;
        }
    }
    for(int d=1;d<n;d++)cout<<res[d]<<endl;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<string.h>
/*ITP1_8-D*/
int main(void){
	char s[105],p[105],temp[210];

	scanf("%s",s);
	scanf("%s",p);

	strcpy(temp,s);
	strcat(temp,s);

	if(strstr(temp,p)!=NULL){
		printf("Yes\n");
	}else{
		printf("No\n");
	}


	return 0;
}

Measured memory_bytes: 540
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    ll n;
    cin >> n;
    vector<ll> a(n,0);
    ll S = 0;
    rep(i,n){
        cin >> a[i];
        S ^= a[i];
    }
    rep(i,n){
        ll res = S ^ a[i];
        cout << res << " ";
    }
    cout << endl;
    return 0;
}

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

int main(void){
int num=0,count=0,vm=0,cm=0;
int cost[20]={0},v[20]={0};
cin>>num;
for(count=0;count<num;count++){
    cin>>v[count];
}
for(count=0;count<num;count++){
    cin>>cost[count];
}
for(count=0;count<num;count++){
    if(v[count]>cost[count])
        vm+=v[count]-cost[count];
   }
cout<<vm<<endl;

}

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

#define debug(...) fprintf(stderr, __VA_ARGS__)

#define inver(a) power(a, mod - 2)

using namespace std;

inline char nc()
{
//	return getchar();
	static char buf[100000],*l=buf,*r=buf;
	return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void read(T &x)
{
	x=0; int f=1,ch=nc();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
	while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
	x*=f;
}

typedef long long ll;

const int mod = 1e9 + 7;
const int maxn = 6e5 + 50;
int N, M, L, R;

int fac[maxn];
int inv[maxn];
ll power(ll x, ll y)
{
	ll re = 1;
	while(y) 
	{
		if(y & 1) re = re * x % mod;
		x = x * x % mod;
		y >>= 1;
	}
	return re;
}
void binom_init(int n)
{
	fac[0] = 1;
	for(int i = 1; i <= n; ++i)
	{
		fac[i] = (ll)fac[i - 1] * i % mod;
	} 
	inv[n] = inver(fac[n]);
	for(int i = n; i >= 1; --i)
	{
		inv[i - 1] = (ll)inv[i] * i % mod;
	}
}
int binom(int x,int y)
{
	return (ll)fac[x] * inv[y] % mod * inv[x - y] % mod;
}

int cal(int a, int b, int K)
{
	if(K < (ll)a * M) return 0;
	int an = 0;
	K -= a * M;
	for(int i = 0; i <= N - M && K >= 0; ++i)
	{
		int f = i & 1 ? -1 : 1;
		an = (an + (ll)binom(K + N, N) * binom(N - M, i) * f) % mod;
		K -= b + 1;
	}
	an = (ll)an * binom(N, M) % mod;
	return an;
}
int sol(int K)
{
	int an = 0;
	for(int x = 1; x <= K; ++x)
	{
		an = ((ll)an + cal(x, x - 1, K) - cal(x + 1, x - 1, K)) % mod;
	}
	an = (binom(K + N, N) - an) % mod;
	return an;
}

int main()
{
	read(N), read(M), read(L), read(R);
	binom_init(R + N);
	int an = (sol(R) - sol(L - 1)) % mod;
	an = (an + mod) % mod;
	printf("%d\n", an);
	return 0;
}


Measured memory_bytes: 4992