akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

const int N = 110 ;

int noNum , noCandy ;
int v [ N ];

int main()
{
    scanf("%d%d",&noNum,&noCandy);

    for ( int i = 0 ; i < noNum ; i++ ){
        scanf("%d",&v [ i ] );
    }

    sort ( v , v + noNum );

    for ( int i = 0 ; i < noNum ; i++ ){
        if ( noCandy >= v [ i ] ){
            noCandy -= v [ i ];
        }else {
            printf("%d",i);
            return 0 ;
        }
    }
    if ( noCandy ){
        noNum -- ;
    }

    printf("%d",noNum);

    return 0;
}


Measured memory_bytes: 256
n = int(input())
s = list(input())
global data
data = [[0 for i in range(n)] for j in range(2)]

for i in range(n):
    data[0][i] = s[i]
    #data[i][1]はペアがいるかどうかの判定
    data[1][i] = 0
#左向きに探していく
#ペアが見つからなければ挿入する。
def Lsearch(index):
    while index >= 0:
        if data[0][index] == '(' and data[1][index] == 0:
            data[1][index] = 1
            return False
        index -= 1
    return True
#右向きに探しに行く
def Rsearch(index):
    if index >= len(data[0]):
        data[0].insert(len(data[0]), ')')
        data[1].insert(len(data[0]), 1)
        return
    elif data[0][index] == ')' and data[1][index] == 0:
        data[1][index] = 1
    else:
        Rsearch(index + 1)
i = 0
while i < len(data[0]):
    #print(data[1])
    #相手が見つかっていれば終わり
    # ) で、相手が見つかっていなければ左側を探す
    if data[0][i] == ')' and data[1][i] == 0:
        if Lsearch(i - 1):
            data[1][i] = 1
            data[0].insert(0, '(')
            data[1].insert(0, 1)
    # ( で、相手が見つかっていなければ、右側を探す
    elif data[0][i] == '(' and data[1][i] == 0:
        Rsearch(i + 1)
        data[1][i] = 1
    i += 1
print("".join(data[0]))
#再帰の書き方はたぶんあってるはずだが、なぜかindexが184やら311やらに初期化されてしまう

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

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

  double t, x; cin >> t >> x;
  cout << t / x << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<tuple<string, int, int>> x;
  for (int i = 1; i <= N; i++) {
    string s;
    int p;
    cin >> s >> p;
    p = -p;
    x.push_back(tie(s, p, i));
  }

  sort(x.begin(), x.end());

  for (int i = 0; i < N; i++) {
    string s;
    int p;
    int id;
    tie(s, p, id) = x[i];
    cout << id << endl;
  }
}

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

int main()
{
    int X, Y;
    cin >> X >> Y;
    for (int i = 0; i <= X; ++i)
    {
        if (Y == 2 * i + 4 * (X - i))
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 3644
/**
 *    author:  Saurav Paul 
 *    created: Jun 06 2020 7:46 PM
**/
#include<bits/stdc++.h>
using namespace std;

#define ll 					  long long int
#define boost		          ios_base::sync_with_stdio(0);
#pragma GCC optimize("O3")
#define loop(i,a,b)           for(ll i=a;i<=b;++i)
#define eb                    emplace_back
#define itoc(c)               ((char)(((int)'0')+c))
#define ctoi(c)               ((int)(((int)c)-'0'))
#define all(p)                p.begin(),p.end()
#define bug()				  debug() <<

///////////////////////

#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 PAUL
~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 dbg(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#ifdef ONLINE_JUDGE
#define cerr if (false) cerr
#endif

///////////////////////
const int INF = 1e9 + 90;
const ll LINF = 1e18 + 90 ;
using pii = pair<int,int >;
using vec = vector<int> ;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    long long int n , k ; cin >> n >> k;

    vector<long long int> v(n+1) ;
    for(int i = 1 ; i <= n ; i++){
        cin >> v[i] ;
    }
    vector<long long int> path ;
    bool rem[n+1] = {} ;

    long long int x = 1, pos = 1 ;
    long long int reoc = -1 ;
    for(int i = 1 ; i <= k ; i++){
        pos = v[x] ;
        if(rem[pos]){
            reoc = pos ;
            break ;
        }
        rem[pos] = true ;
        path.emplace_back(pos) ;
        x = pos ;
    }
    long long int p = -1 ;
    if(reoc != -1){
        for(int i = 0 ; ; i++){
            if(path[i] == reoc){
                p = i ;
                break ;
            }
        }
    }
    if( k < p){
        cout << path[k-1] << endl ;
    }
    else{
        k -= p ;
        long long int pth = path.size() - p ;
        long long int mod = k % pth ;
        if(mod == 0){
            mod = pth ;
        }
        cout << path[p+mod - 1] << endl ;
    }

    bug() dbg(path) dbg(p) dbg(reoc);

    return 0;
}


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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    string s;
    int n;
    cin >> s;
    n = s.size();
    static int xs[200001];
    for(int i=0;i<n;++i) xs[i+1] = 1 << (s[i]-'a');
    for(int i=0;i<n;++i) xs[i+1] ^= xs[i];
    if(__builtin_popcount(xs[n]) <= 1){ cout << 1 << endl; return 0; }
    static int dp[1<<26];
    for(int i=0;i<(1<<26);++i) dp[i] = INT32_MAX / 2;
    dp[0] = 0;
    for(int i=1;i<=n;++i){
        for(int j=0;j<='z'-'a';++j) dp[xs[i]] = min(dp[xs[i]], dp[xs[i]^(1<<j)]+1);
    }
    cout << dp[xs[n]] << endl;
   
    return 0;
}

Measured memory_bytes: 263572
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int n;
	string s;
	cin >> n >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] + n > 90) {
			s[i] = s[i] - 26;
		}
		s[i] = s[i] + n;
	}
	cout << s << endl;
}

Measured memory_bytes: 3640
#include <vector>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>

using namespace std;


int main(void){
  
  string S,ans = "NG";


  cin >> S;

  if(S == "ABC"){
    cout << "ARC" << endl;
  }else{
   cout << "ABC" << endl; 
  }
 
 
  return 0;
}




Measured memory_bytes: 3596
n=int(input())
gold=1000
kabu=0
lst=list(map(int,input().split()))
for i in range(n-1):
    if lst[i]<lst[i+1]:
        tmp,gold=divmod(gold,lst[i])
        kabu+=tmp
    if lst[i]>lst[i+1]:
        gold+=kabu*lst[i]
        kabu=0
gold+=kabu*lst[-1]
print(gold)

Measured memory_bytes: 61940
#include <iostream>

using namespace std;

int fib(int n) {
    int a = 1;
    int b = 1;

    int i = 0;
    while (i < n) {
        int tmp = a;
        a = b;
        b += tmp;
        ++i;
    }
    return a;
}

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

    cout << fib(n) << endl;

    return 0;
}

Measured memory_bytes: 3068
//
// Created by myabu on 2020/02/03.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;


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

    vector<int> L(M);
    vector<int> R(M);

    for (int i = 0; i < M; ++i) {
        cin>>L[i]>>R[i];
    }

    int ans = 0;
//    for (int i = 1; i <= N; ++i) {
//        bool tuuka = true;
//        for (int k = 0; k < M; ++k) {
//            if(!(L[k] <= i && i<=R[k])){
//                tuuka = false;
//                break;
//            }
//        }
//        if(tuuka)ans++;
//    }
//
//

    sort(L.begin(), L.end());
    sort(R.begin(), R.end());

    for (int i = 1; i <= N; ++i) {
        if(L[M-1] <= i && R[0] >= i)ans++;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
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; }
typedef long long ll;
const ll INF = 1e18;
const int mod = 1e9 + 7;
const int MAX = 200002;
ll fact[MAX], invfact[MAX];

#define MAX_V 1000000

ll mod_pow(ll a, ll n, ll mod) {
	ll res = 1;
	while(n > 0) {
		if(n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}

	return res;
}

ll mod_inverse(ll a, ll m) {
	return mod_pow(a, m - 2, m);
}

ll nCr(ll n, ll r) {
	return fact[n] * invfact[r] % mod * invfact[n - r] % mod;
}

void init() {
	fact[0] = invfact[0] = 1;
	rep(i, 1, MAX) {
		fact[i] = (fact[i - 1] * i) % mod;
		invfact[i] = mod_inverse(fact[i], mod);
	}
}

map<ll, ll> prime_factor(ll n) {
	map<ll, ll> res;
	for(ll i = 2; i * i <= n; i++) {
		while(n % i == 0) {
			++res[i];
			n /= i;
		}
	}
	if(n != 1) res[n] = 1;
	return res;
}

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

  ll n, m;
  cin >> n >> m;
  map<ll, ll> p = prime_factor(m);
  ll rsl = 1;
  ll mod = 1e9 + 7;
  for(map<ll, ll>::iterator itr = p.begin(); itr != p.end(); ++itr) {
    (rsl *= nCr(itr->second + n - 1, itr->second) % mod) %= mod;
  }
  cout << rsl << endl;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000],cnt[1000000],vis[1000000];
vector <long long > v[1000000];
long long int dfs (long long int x)
{
	long long i,j,k,y,z;
	vis[x]=1;
	y=1;
	for (i=0;i<v[x].size();i++)
	{
		if (vis[v[x][i]]==0)
		{
			y=y+dfs(v[x][i]);
		}
	}
	return y;
}
map <pair <int, int > , int > a;
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);   
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    long long n,m,i,j,k,x,y,z;
    pair <int, int > p,p1;
    cin>>n>>m;
    for (i=0;i<m;i++)
    {
    	cin>>x>>y;
    	if (a[make_pair(x,y)]==1)
    	{
    		continue;
		}
    	v[x].push_back(y);
    	v[y].push_back(x);
    	a[make_pair(x,y)]=1;
    	a[make_pair(y,x)]=1;
	}
	z=-1;
	for (i=1;i<=n;i++)
	{
		if (vis[i]==0)
		{
			z=max(z,dfs(i));
		}
	}
	cout<<z<<endl;
}

Measured memory_bytes: 69104
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[])
{
    ll a, b, c;
    cin >> a >> b >> c;
    ll ans;
    if (a == b)
    {
        ans = c;
    }
    else if (a == c)
    {
        ans = b;
    }
    else
    {
        ans = a;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
s = [0] * m
c = [0] * m
for i in range(m):
    s[i],c[i]  = map(int,input().split())

x = [-1] * n

f = 0

for i in range(m):
    if x[s[i] - 1] == -1:
        x[s[i] - 1] = c[i]

    elif x[s[i] - 1] != c[i]:
        f = 1
        break

if f == 1:
    print(-1)

else:
    if n == 1:
        if x[0] == -1:
            x[0] = 0
        print(x[0])

    else:
        if x[0] == 0:
            print(-1)
        else:

            if x[0] == -1:
                x[0] = 1
            for i in range(1,n):
                if x[i] == -1:
                    x[i] = 0
        

            s = ""
            for i in range(n):
                s += str(x[i])
            print(s)

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

using namespace std;
#define ll long long

int main()
{
  ll n;
  cin >> n;
  int ans[n+1];
  memset (ans, 0, sizeof ans);
  int i, j, k;
  for (i=1; i<=sqrt(n); i++)
    {
      for (j=1; j<=sqrt(n); j++)
	{
	  for (k=1; k<=sqrt(n); k++)
	    {
	      ll val=i*i+j*j+k*k+i*j+i*k+j*k;
	      if (val<=n)
		ans[val]++;
	    }
	}
    }
  for (i=1; i<=n; i++)
    {
      cout << ans[i] << endl;
    }
  return 0;
}
	  


Measured memory_bytes: 3564
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <utility>
#include <cstdio>
#include <stack>
#include <set>
#include <deque>
using namespace std;
int a,b,x;
int main()
{
	cin>>a>>b>>x;
	if (a+b>=x && a<=x)
		cout<<"YES"<<endl;
	if (a>x || a+b<x)
		cout<<"NO"<<endl;
	system("pause");
    return 0;
}

Measured memory_bytes: 504
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 4523372036854775807;
const ld pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct S {//辺の情報を入れる変数
	int from, to, cost;
};
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld radian(ld a, ld b, ld c, ld d) {
	return sqrt(pow(a - c, 2) + pow(b - d, 2));
}
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	string a;
	cin >> a;
	if (a[0] == a[2])
		cout << "Yes\n";
	else
		cout << "No\n";
	getchar(); getchar();
}

Measured memory_bytes: 256
// date: 22/08/20 17:38:43 // 
#include <bits/stdc++.h>
using namespace std;

#define iterall(x) x.begin(), x.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define endl '\n'

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <bool> vb;
typedef vector <double> vd;
typedef vector <ll> vll;
typedef vector <vector <int>> vvi;
typedef vector <vector <long long>> vvll;
typedef vector <vd> vvd;
typedef vector <long long> vll;
typedef pair <int, int> pii;
typedef pair<ll , ll> pll;
typedef vector <pair <int, int>> vpii;
typedef vector <pll> vpll;

const ll INF = 1e9+5;
const double EPS = 1e-9;


int main()
{
    ll n;
    cin >> n;
    vll a(n);
    for(auto &i: a)
        cin >> i;
    
    ll res =  0; 
    for(int i = 1; i < n; i++)
        if(a[i] < a[i-1])
        {
            res += a[i-1] - a[i];
            a[i] = a[i-1];
        }
    
    cout << res << endl;

}

Measured memory_bytes: 4816
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int i,j,n,m,arr[1000000];
  cin>>n;
  for(i=0;i<n;i++)
    cin>>arr[i];
  long long int dp[1000000];
  dp[0]=0;
  dp[1]=0;
  dp[2]=abs(arr[0]-arr[1]);
  for(i=3;i<=n;i++)
  {
    dp[i]=min(dp[i-1]+abs(arr[i-1]-arr[i-2]),dp[i-2]+abs(arr[i-1]-arr[i-3]));
  }
  cout<<dp[n];
  return 0;
}

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

string seg[]={"1111110","0110000","1101101","1111001","0110011","1011011","1011111","1110010","1111111","1111011"};

int str2int(string str)
{
	int ret=0,dig=1;
	for(int i=0; i<7; i++)
	{
		ret+=(str[i]-'0')*dig;
		dig*=2;
	}

	return ret;
}

void output(int a)
{
	int dig=(1<<6);
	string ret;
	for(int i=0; i<7; i++)
	{
		ret+=(a/dig + '0');
		a%=dig;
		dig/=2;
	}

	cout << ret  << endl;
}

int main()
{
	int N;
	while(cin >> N, N!=-1)
	{
		int stat=0;
		while(N--)
		{
			int t;
			cin >> t;
			output(stat^str2int(seg[t]));
			stat = str2int(seg[t]);
		}

	}
}

Measured memory_bytes: 0
N,M,*xyzs=$<.read.split.map(&:to_i)
arr = Array.new(N+1) { Array.new }
xyzs.each_slice(3).each do |x,y,z|
  arr[x] << y
  arr[y] << x
end

# p arr

i = 1
ret = 0
while i <= N
  if arr[i]
    ret += 1

    q = [arr[i]]
    arr[i] = nil
    while !q.empty?
      q.pop.each do |t|
        q << arr[t] if arr[t]
        arr[t] = nil
      end
    end
  end
  i += 1
end

p ret




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

using namespace std;

using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORE(i, a, b) for (int i = (a); i <= (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define SP cout << fixed << setprecision(15)
typedef pair<int, int> P;
const int inf = (int)1e9;
const int mod = (int)1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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

    int n, k;
    cin >> n >> k;

    double sum = 0;
    FORE(i, 1, n) {
        double p = 1.0 / n;
        int now = i;
        while (now < k) {
            now *= 2;
            p /= 2;
        }
        sum += p;
    }

    SP;
    cout << sum << endl;

    return 0;
}

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

int n, p, now = 0;
string m;

void management();

int main() {
  cin >> n;
  for(int i = 0; i < n; ++i) {
    cin >> p >> m;
    management();
  }
  if(now == 0)
    cout << "lose" << endl;
  else
    cout << "win" << endl;
  return 0;
}

void management() {
  int tennum = 0, cnt = 0;
  for(int i = 0; i < m.size(); ++i) {
    tennum *= p;
    if(m[i] >= '0' && m[i] <= '9')
      tennum += m[i] - '0';
    else if(m[i] >= 'A' && m[i] <= 'Z')
      tennum += m[i] - 'A' + 10;
    else
      tennum += m[i] - 'a' + 36;
  }
  for(int i = 0; (1 << i) <= tennum; ++i) {
    if(((1 << i) & tennum) == (1 << i))
      now ^= (1 << cnt++);
    else
      cnt = 0;
  }
}


Measured memory_bytes: 3192
import Control.Monad.State

type Memo = State [(Int, Int)] Int


memo :: (Int -> Memo) -> Int -> Memo 
memo f n =
  state $ \s ->
    case lookup n s of
      Nothing -> 
        let 
          (a, s') = runState (f n) $ s
        in 
          (a, (n, a) : s')
      Just a ->
        (a, s)

ret :: Int -> Memo
ret n = 
  if n == 1 then
    return 1
  else
    (memo ret (n `div` 2) >>= (\a -> return (2 * a + 1)))








main = do
  h <- read <$> getLine
  putStrLn $ show $ evalState (ret h) []


Measured memory_bytes: 508
import java.util.Scanner;
public class Main {
	static int mod=1000000007;
	static Scanner scan=new Scanner(System.in);
	static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
	static long lcm (int a, int b) {return a*b/gcd(a,b);}
	static int max(int a,int b) {return a>b?a:b;}
	static int min(int a,int b) {return a<b?a:b;}
	static long factorial(int i) {return i==1?1:i*factorial(i-1);}
	static int lower_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static int upper_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	}
	static int upper_division(int a,int b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lupper_division(long a,long b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lmax(long a,long b) {return Math.max(a, b);}
	static long lmin(long a,long b) {return Math.min(a, b);}
	static int[] setArray(int a) {
		int b[]=new int[a];
		for(int i=0;i<a;i++) {
			b[i]=scan.nextInt();
		}
		return b;
	}
	static String reverce(String str) {
		String strr="";
		for(int i=str.length()-1;i>=0;i--) {
			strr+=str.charAt(i);
		}
		return strr;
	}
	static int combination(int a,int b) {
		long ans=1;
		for(int i=a,cnt=0;cnt<b;cnt++,i--)ans*=i;
		for(int i=1;i<=b;i++)ans/=i;
		return (int)ans;
	}
	public static void main(String[]args){
		String str=scan.next();
		int a=0;
		int b=0;
		int c=0;
		for(int i=0;i<str.length();i++) {
			char ch=str.charAt(i);
			if(ch=='a')a++;
			if(ch=='b')b++;
			if(ch=='c')c++;
		}
		int max=max(a,b);max=max(max,c);
		int min=min(a,b);min=min(min,c);
		if(min==max||min+1==max)System.out.println("YES");
		else System.out.println("NO");
	}
}

Measured memory_bytes: 24920
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int a, b; cin >> a >> b;
	if (a <= 0 && 0 <= b) {
		cout << "Zero" << endl;
		return;
	}
	if (0 < a && 0 < b) {
		cout << "Positive" << endl;
		return;
	}
	int diff = b - a;
	if (diff % 2 == 0) cout << "Negative" << endl;
	else cout << "Positive" << endl;
}

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


Measured memory_bytes: 256
import java.util.Scanner;

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

    private void run() {
        Scanner scanner = new Scanner(System.in);
        String X = scanner.next();
        if(X.equals("SUN")) {
            System.out.println(7);
            return;
        }
        if(X.equals("MON")) {
            System.out.println(6);
            return;
        }
        if(X.equals("TUE")) {
            System.out.println(5);
            return;
        }
        if(X.equals("WED")) {
            System.out.println(4);
            return;
        }
        if(X.equals("THU")) {
            System.out.println(3);
            return;
        }
        if(X.equals("FRI")) {
            System.out.println(2);
            return;
        }
        if(X.equals("SAT")) {
            System.out.println(1);
            return;
        }
        return;


    }
}


Measured memory_bytes: 25044
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;
		str = br.readLine();
		int w = Integer.parseInt(str);
		str = br.readLine();
		int n = Integer.parseInt(str);

		int array[] = new int[w];

		for(int i=0; i<w; i++){
			array[i] = i+1;
		}

		for(int i=0; i<n; i++){
			str = br.readLine();
			int a = Integer.parseInt(str.substring(0, str.indexOf(",")));
			int b = Integer.parseInt(str.substring(str.indexOf(",")+1, str.length()));

			swap(array,a-1,b-1);

		}

		for(int i=0; i<array.length; i++){
			System.out.println(array[i]);
		}

	}


	static int[] swap(int[] list,int a, int b){
		int temp = list[a];
		list[a] = list[b];
		list[b] = temp;

		return list;
	}

}

Measured memory_bytes: 15024
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

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)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

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

int main(void) {
    string s;
    cin >> s;
    const string k = "keyence";
    if (k == s) {
        cout << "YES" << endl;
        return 0;
    }
    REP(i, s.size()) {
        FOR(j, i + 1, s.size()) {
            string tmp = s.substr(0, i) + s.substr(j);
            if (k == tmp) {
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
}


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

int main() {
	int n, a[305];
	scanf("%d", &n); n <<= 1;
	for(int i = 1; i <= n; ++i) scanf("%d", a + i);
	std::sort(a + 1, a + n + 1);
	int ans = 0;
	for(int i = 1; i <= n; i += 2) ans += a[i];
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 256
//
// ~oisín~ C++ Template
//

#include                <bits/stdc++.h>
#define MX_N            5001
#define mp              make_pair
#define mod7            1000000007
#define modpi           314159
#define PI              3.141592653589793238
#define pb              push_back
#define FastIO          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define All(a)          a.begin(),a.end()
#define fi              first
#define se              second
#define ll              long long int
#define ull             unsigned long long int

int kx[8]  =            {+2, +2, -2, -2, +1, +1, -1, -1};
int ky[8]  =            {+1, -1, +1, -1, +2, -2, +2, -2};
int d9x[9] =            {+1, +1, +1, +0, +0, +0, -1, -1, -1};
int d9y[9] =            {+1, +0, -1, +1, +0, -1, +1, +0, -1};
int dx4[4] =            {+0, +0, +1, -1};
int dy4[4] =            {+1, -1, +0, +0};

ll gcd(ull a, ull b){
    return (a==0)?b:gcd(b%a,a);
}

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

const long long INF = 1e18;

using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    int a[n];
    int sum = 0;
    for(int i=0;i<n;++i){
        cin >> a[i];
    }
    sort(a, a+n);
    for(int i=0;i<k;++i){
        sum += a[i];
    }
    cout << sum << endl;
}


Measured memory_bytes: 3600
s = input()
t = input()
ns = len(s)
nt = len(t)
mn = nt
for i in range(ns-nt+1):
    cnt = 0
    for j in range(nt):
        if(s[i+j] == t[j]):
            cnt += 1

    mn = min(mn,nt-cnt)
print(mn)


Measured memory_bytes: 9052
using System;

namespace ABC094B
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int ret = 0;

            string s1 = Console.ReadLine();
            string s2 = Console.ReadLine();

            string[] ss = s1.Split(' ');

            int N = int.Parse(ss[0]);
            int M = int.Parse(ss[1]);
            int X = int.Parse(ss[2]);

            string[] costPosAry = s2.Split(' ');

            int[] pos = new int[N];

            foreach (var s in costPosAry)
            {
                pos[int.Parse(s)] = 1;
            }

            int cnt = 0;
            int mae = 0;
            for (int i = 0; i < N; i++)
            {
                if (i < X)
                {
                    cnt += pos[i];
                }
                if (i == X)
                {
                    mae = cnt;
                    cnt = 0;
                }
                if (i > X)
                {
                    cnt += pos[i];
                }
            }

            if (mae < cnt)
            {
                ret = mae;
            }
            else
            {
                ret = cnt;
            }

            Console.WriteLine(ret);
        }
    }
}


Measured memory_bytes: 13140
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

ll dp[333][333][333];

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n,m;
  cin>>n>>m;
  dp[0][1][0]=1;
  rep(t,m)rep(i,n+1)rep(j,n+1-i){
    (dp[t+1][i][j]+=dp[t][i][j]*j%MOD)%=MOD;
    (dp[t+1][i][j+1]+=dp[t][i][j]*(n-i-j)%MOD)%=MOD;
    (dp[t+1][i+j][0]+=dp[t][i][j]*i%MOD)%=MOD;
  }
  cout<<dp[m][n][0]<<endl;
  return 0;
}


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

string s;
int K;
map<string, bool> visited;
vector<string> vstring;

int main()
{
    cin>>s;
    cin>>K;

    for (int i=0; i<s.size(); i++)
    {
        for (int j=1; j<=min((int)s.size()-i, K); j++)
        {
            if (!visited[s.substr(i,j)])
            {
                vstring.push_back(s.substr(i,j));
                visited[s.substr(i,j)]=true;
            }
        }
    }

    sort(vstring.begin(), vstring.end());

    cout<<vstring[K-1]<<endl;
}

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

using namespace std;
using ll=long long;
using vi=vector<int>;
using vl=vector<ll>;
using vs=vector<string>;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define rep(i, a, n) for (int i = (n); i < (a); ++i)
#define repr(i, a, n) for (int i = (n); i >= (a); --i)

template<typename T,typename U>
void Inparray(T &f,U n){
  for(int i=0;i<n;i++) cin>>f[i];
}

template<typename T,typename U>
void Printarray(T f,U n){
  for(int i=0;i<n;i++) i!=n ? cout<<f[i]<<" " : cout<<f[i];
}

void flagfunc(bool flag,string A,string B){
  flag ? cout<<A<<endl : cout<<B<<endl;
}

void flag2func(bool flag){
  flag ? cout<<"Yes"<<endl : cout<<"No"<<endl;
}

void flag3func(bool flag){
  flag ? cout<<"YES"<<endl : cout<<"NO"<<endl;
}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int a,b;cin>>a>>b;
  a+b<10 ? cout<<a+b<<endl : cout<<"error"<<endl;
}

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

using namespace std;

int main()
{
	long n, k;
	cin >> n >> k;
	
	long point, pattern;
	long double ans = 0;
	if(n >= k)
		ans = (n - k + 1.0L) / n;
	
	for(int i = 1; i < k and i <= n; i++) {
		point = i;
		pattern = n;
		while(point < k) {
			point *= 2; pattern *= 2;
		}
		ans += 1.0L / pattern;
	}	
	
	cout << setprecision(12) << ans;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<limits>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
template<typename TypeInt>
std::string Itoa(const TypeInt v, int base)
{
    static const char table[] = "0357ZZ";
    string ret;
    static numeric_limits<TypeInt> t;
    TypeInt n = v;
    if (t.is_signed) {
        if (v < 0) n *= -1;
    }

    while (n >= base) {
        ret += table[n%base];
        n /= base;
    }
    ret += table[n];
    if (t.is_signed) {
        if (v < 0 && base == 10) ret += '-';
    }
    // 文字列の順番を逆にする
    std::reverse(ret.begin(), ret.end());

    return ret;
}
bool ok(int n){
	int count[10]={};
	while(n){
		if(n%10==3||n%10==5||n%10==7){
			count[n%10]++;
		}
		else{
			return false;
		}
		n/=10;
	}
	if(count[3]*count[5]*count[7]>0) return true;
	else return false;
}
int main(){
	ll N;
	scan(N);
	int ans=0;
	ll kazu=0;
	for(int i=1;kazu<=N;i++){
		kazu=stol(Itoa(i,4));
		if(ok(kazu)&&kazu<=N) ans++;
		//printf("i:%d kazu:%lld ok:%d\n",i,kazu,ok(kazu));
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 256
red, green, blue = map(int, input().split())

magic = int(input())

for i in range(magic) :
    if red >= green :
        green = green * 2
    elif green >= blue :
        blue = blue * 2
    
    if blue > green and green > red :
        break

if blue > green and green >red :
    print("Yes")
else :
    print("No")

Measured memory_bytes: 9180
require 'pp'

k, n = gets.split.map(&:to_i)
a_n = gets.split.map(&:to_i).sort

diff = []
a_n.each_cons(2) do |x, y|
    diff << y - x
end
diff.push(k - a_n[-1] + a_n[0])

puts diff.inject(&:+) - diff.max


Measured memory_bytes: 20968
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,ans=0;
int a[105];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++){
		if(m>=a[i])m-=a[i],ans++;
		else break;
	}
	if(m>0 && ans==n)printf("%d",n-1);
	else printf("%d",ans);
}

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

typedef unsigned long long uLL;
typedef long long int LL;
typedef pair <int,int> pii;
typedef pair <int,pii> piii;
typedef pair <long long,long long> pll;
typedef pair <long long,pll> plll;
const int N = 1e5 + 5;
const int inf = 1e9;
const long long INF = 1e18;
const double PI = acos(-1.0);
const double EPS = 1e-8;
const int MOD = 1000000007;

int n;
LL a[ N ];
LL dp[ 3005 ][ 3005 ];

LL solve( int x , int y ) {
        if( x > y ) return 0;
        if( x == y ) return a[x];
        if( dp[x][y] != -INF ) return dp[x][y];
        LL ret = -INF;
        ret = max( ret , a[x] - solve( x+1 , y ) );
        ret = max( ret , a[y] - solve( x , y-1 ) );
        return dp[x][y] = ret;
}
int main( int argc , char const *argv[] ) {
        ios_base::sync_with_stdio( false ); cin.tie( NULL );
        cin >> n;
        for( int i = 1; i <= n; i++ ) cin >> a[i];
        for( int i = 1; i <= n; i++ ) for( int j = 1; j <= n; j++ ) dp[i][j] = -INF;
        cout << solve( 1 , n ) << endl;
        return 0;
}












Measured memory_bytes: 70912
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    int C[3][3];
    for ( int i = 0; i < 3; i++ ) {
    for ( int j = 0; j < 3; j++ ) {
        cin >> C[i][j];
    }
    }
    bool ans = true;
    for ( int i = 0; i < 3; i++ ) {
        int X[3];
        for ( int j = 0; j < 3; j++ ) {
            X[j] = C[i][j] - C[(i+1)%3][j];            
        }
        for ( int j = 1; j < 3; j++ ) {
            if ( X[j] != X[j-1] ) { ans = false; }
        }
    }
    for ( int j = 0; j < 3; j++ ) {
        int X[3];
        for ( int i = 0; i < 3; i++ ) {
            X[i] = C[i][j] - C[i][(j+1)%3];            
        }        
        for ( int i = 1; i < 3; i++ ) {
            if ( X[i] != X[i-1] ) { ans = false; }
        }
    }
    cout << ( ans ? "Yes" : "No" ) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
int main(void){
    
    int m;
    int d;
    int ten=0;
    int one=0;
    int seki=0;
    int ans=0;
    
    scanf("%d %d", &m, &d);
    
    for(int i=1; i<=d; i++){
        
        if(i>=22){
            
            ten = i / 10;
            one = i % 10;
            seki = ten * one;
            
            if(ten>=2){
                
                
                if(one>=2){
                    
                    if(seki<=m){
                    
                        ans += 1;
                    
                    }
                    
                }
                
                
            }
            
        }
        
    }
    
    printf("%d", ans);
    
    return 0;
    
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,b) for(i=0;i<b;++i)
#define repp(i,a,b) for(i=a;i<b;++i)
#define endl "\n"
//#define LLONG_MAX 99999999999999
typedef long long int lli;
int main(){
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    lli n,i,j,b,a,q,m;
    lli t=1;
    //cin>>t;
    while(t--){
        cin>>n;
        repp(i,1,1000){
            if((i*n)%360==0){
                cout<<i<<endl;
                break;
            }

        }
    }


}



Measured memory_bytes: 3620
n, y = map(int, input().split())

for i in range(n+1):
    for j in range(n-i+1):
        if 10000*i + 5000*j + 1000*(n-i-j) == y:
            print(i, j, n-i-j)
            exit()

a = -1
print(a, a, a)

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

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

  vector<int>button(N);
  
  for (int i=0; i<N; i++) cin >> button.at(i);
    
  int temp = button.at(0);
  int count=1;
  
  if (temp == 2) cout << 1 << endl;
  
  else {
    for (int i=1; i<N; i++) 
    {
      temp = button.at(temp-1);
      count++;
      if (temp == 2)
      {
        cout << count << endl;
        return 0;
      }
    }
    cout<< -1 << endl;   
  }
}


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

int main(){
    int N;
    cin >> N;
    int ans = N % 1000;
    if (ans > 0)
        ans = 1000 - ans;
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

#define ff first
#define ss second
#define pb push_back
#define sz size()
#define mp make_pair
#ifndef ONLINE_JUDGE 
#include "/home/asif/Codes/Library/debug.h"
#endif
/*--------------------------------------------------------------------*/

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;

int main() {

  set<int> st;
  for(int i = 0; i <= 200; i++){
    st.insert(-i);
    st.insert(i);
  }

  int k, x, n;
  cin >> k >> n;
  for(int i = 0; i < n; i++){
    cin >> x;
    if(st.find(x) != st.end()) st.erase(st.find(x));
  }
  int cur = 10000;
  for(auto x : st){
    if(abs(x - k) < abs(cur - k)){
      cur = x;
    }
    else if(abs(x - k) == abs(cur - k) and x < cur){
      cur = x;
    }
  } 
  cout << cur << endl;

  return 0;
}

Measured memory_bytes: 3648
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
	int n, m;
	while (cin >> n >> m, n){
		vector<int> point(n);
		REP(i, n){
			cin >> point[i];
		}
		point.push_back(0);
		vector<int> sum = point;
		REP(i, n + 1){
			REP(j, n + 1){
					sum.push_back(sum[i] + sum[j]);
			}
		}
		SORT(sum);
		int ma = 0;
		REP(i, sum.size()){
			int left = 0;
			int right = sum.size() - 1;
			while (left < right){
				if (sum[left + (right - left) / 2] + sum[i] <= m){
					ma = max(sum[left + (right - left) / 2] + sum[i], ma);
					left = left + (right - left) / 2 + 1;

				}
				else{
					right = left + (right - left) / 2 - 1;
				}
			}
			
		}
		cout << ma << endl;
	}
}

Measured memory_bytes: 9008
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF = 1 << 29;
const double EPS = 1e-9;
const ll MOD = 1000000007LL;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int N,M;
const int MAX_N = 100010;
vector<ll> X,Y;
vector<ll> diff_X,diff_Y;
ll sum_X[MAX_N];
ll sum_Y[MAX_N];
int main() {
  cin >> N >> M;
  X.resize(N);
  Y.resize(M);
  for (auto &val : X){
    cin >> val;
  }
  for (auto &val : Y){
    cin >> val;
  }
  for (int i = 0; i < N - 1; i++){
    ll val = X[i + 1] - X[i];
    int left = i + 1;
    int right = (N - 1 - i);
    diff_X.push_back(left % MOD * right % MOD * val % MOD);
    diff_X[i] %= MOD;
  }
  ////////////////////////
  for (int i = 0; i < M - 1; i++){
      ll val = Y[i + 1] - Y[i];
      int left = i + 1;
      int right = (M - 1 - i);
      diff_Y.push_back(left % MOD * right % MOD * val % MOD);
      diff_Y[i] %= MOD;
  }

  for (int i = 0; i < N - 1; i++){
    if (i - 1 >= 0){
        sum_X[i] += sum_X[i - 1];
    }
    sum_X[i] += diff_X[i];
    sum_X[i] %= MOD;
  }
  for (int i = 0; i < M - 1; i++){
    if (i - 1 >= 0){
        sum_Y[i] += sum_Y[i - 1];
    }
    sum_Y[i] += diff_Y[i];
    sum_Y[i] %= MOD;
  }
  cout << sum_X[N - 2] % MOD * sum_Y[M - 2] % MOD << endl;
}


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

using namespace std;

#define prr pair<int,int>
#define ll long long
#define pb push_back
#define int long long
#define ld long double
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 //   cout<<"here";
   int arr[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
   int k;
   cin>>k;
   cout<<arr[k-1];
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> c(m, 0), a(m);
    rep(i, m){
        int x, b;
        cin >> x >> b;
        a[i] = x;
        rep(j, b){
            int y;
            cin >> y;
            c[i] += 1<<(y-1);
        }
    }

    vector<int> dp(1<<n, INT32_MAX);
    rep(i, m){
        dp[c[i]] = min(dp[c[i]], a[i]);
        rep(j, 1<<n){
            if(dp[j]!=INT32_MAX&&j!=c[i]){
                dp[j | c[i]] = min(dp[j | c[i]], dp[j] + dp[c[i]]);
            }
        }
    }

    if(dp[(1<<n)-1]==INT32_MAX){
        cout << -1 << endl;
    }else{
        cout << dp[(1 << n) - 1] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3524