akhauriyash/Code-Regression huggingface dataset:
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.List
import Data.Vector.Unboxed ((!))
import qualified Data.Vector.Unboxed as VU

solve :: Int -> [Int] -> Int
solve n as = (fact n) `mMul` (mSum lst)
  where
    revsum = mkRevsum n
    lst = [a `mMul` (1 `mAdd` (revsum ! (n-i+1)) `mAdd` (revsum ! i))
          | (i, a) <- zip [1..] as]

mkRevsum n = VU.fromListN (n+1) $ 0 : (scanl' mAdd 0 (unfoldr f 2))
  where f n = Just (mInv n, n + 1)

fact n = foldl' mMul 1 [1..n]

mSum = foldl' mAdd 0

-------------------------------------------------------------------------------

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> Int
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_n]:remLines1 = remLines0
      n = readBInt bs_n
      line2:remLines2 = remLines1
      as = map readBInt line2
  in solve n as

outAnswer :: Int -> IO ()
outAnswer = putStrLn . show

main :: IO ()
main = outAnswer . tmain =<< B.getContents

-------------------------------------------------------------------------------

mPrime = 10^9 + 7

mAdd :: Int -> Int -> Int
mAdd x y = (x + y) `mod` mPrime

mSub :: Int -> Int -> Int
mSub x y = (x - y) `mod` mPrime    -- ok even if x < y

mMul :: Int -> Int -> Int
mMul x y = (x * y) `mod` mPrime

mInv :: Int -> Int
mInv x = let (_, a, _) = eGCD x mPrime in if a < 0 then a + mPrime else a

eGCD :: Int -> Int -> (Int,Int,Int)
eGCD 0 b = (b, 0, 1)
eGCD a b = let (g, s, t) = eGCD (b `mod` a) a
           in (g, t - (b `div` a) * s, s)

-------------------------------------------------------------------------------

inp1 = "2\n1 2\n"
inp2 = "4\n1 1 1 1\n"
inp3 = "10\n1 2 4 8 16 32 64 128 256 512\n"
tv1 = tmain $ B.pack inp1
tv2 = tmain $ B.pack inp2
tv3 = tmain $ B.pack inp3
test1 = tv1 == 9
test2 = tv2 == 212
test3 = tv3 == 880971923
alltest = test1 && test2 && test3


Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    ll x, y, a, b, c; cin >> x >> y >> a >> b >> c;
    deque<ll> p(a), q(b), r(c); cin >> p >> q >> r;

    SORT(p), SORT(q), SORT(r);
    PQ<ll> que;
    FOR(i, 0, x) {
        que.push(p.back());
        p.pop_back();
    }
    FOR(i, 0, y) {
        que.push(q.back());
        q.pop_back();
    }

    each(i, r) {
        ll s = que.top();
        que.pop();
        que.push(max(s, i));
    }

    ll ans = 0;
    while (!que.empty()) {
        ans += que.top();
        que.pop();
    }
    cout << ans << "\n";
}

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

int main()
{
    int N;
    cin >> N;
    if (N % 111 == 0)
    {
        cout << 111 * (N / 111);
    }
    else
    {
        cout << 111 * (1 + (N / 111));
    }

    return 0;
}

Measured memory_bytes: 256
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));
		StringBuilder sb = new StringBuilder();

		while(true){
			String[] inputData = br.readLine().split(" ");
			int h = Integer.parseInt(inputData[0]);
			int w = Integer.parseInt(inputData[1]);

			if(h == 0 && w == 0){
				break;
			}
			for(int i = 0; i < h; i ++){
				for(int j = 0; j < w; j ++){
					int count = 0;
					if(i%2 == 0){
						count ++;
					}
					if(j%2 == 0){
						count ++;
					}

					if(count % 2 == 0){
						sb.append("#");
					}else{
						sb.append(".");
					}
				}
				sb.append("\n");
			}
			sb.append("\n");
		}
		System.out.print(sb);
	}

}

Measured memory_bytes: 25424
#include <bits/stdc++.h>
#define Phuong_ ios_base::sync_with_stdio(0); cin.tie(0);
#define REP(i,a,b) for(int i=a; i<=b; ++i)

/// easy access -------------
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
typedef pair<int,int> pi;
typedef tuple<int, int, int> tp;
typedef vector<vector<int>> vv;
///-------------------------

int main()
{
    Phuong_; /// <3333
    int a,b,c;
    cin >> a >> b >> c;
    a = (a+c-1)/c;
    if (a<=b) cout << "Yes"; else cout << "No";
    return 0;
}


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

int main()
{
	int n, m, c = 0;
	char x;
	cin >> n >> m;
	queue<pair<int, int>>q;
	vector<vector<int>>a(n, vector<int>(m, 0)), d(n, vector<int>(m, 0));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> x;
			if (x == '#') {
				a[i][j] = 1;
				q.push({ i, j });
			}
		}
	}
	while (!q.empty()) {
		int i = q.front().first, j = q.front().second;
		q.pop();
		c = max(c, d[i][j]);
		if (i > 0 && a[i - 1][j] == 0) {
			a[i - 1][j] = 1;
			d[i - 1][j] = d[i][j] + 1;
			q.push({ i - 1, j });
		}
		if (j > 0 && a[i][j-1] == 0) {
			a[i][j - 1] = 1;
			d[i][j - 1] = d[i][j] + 1;
			q.push({ i, j-1 });
		}
		if (j < m-1 && a[i][j + 1] == 0) {
			a[i][j + 1] = 1;
			d[i][j + 1] = d[i][j] + 1;
			q.push({ i, j + 1 });
		}
		if (i < n - 1 && a[i+1][j] == 0) {
			a[i + 1][j] = 1;
			d[i + 1][j] = d[i][j] + 1;
			q.push({ i+1, j });
		}
	}
	cout << c;
	//system("pause");
	return 0;
}

Measured memory_bytes: 16272
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
typedef vector<int> vi;
//const int MAX=;
const int MOD=1e9+7;

int main(){
	string S;
	cin>>S;
	int l=S.size();
	int p[3];
	rep(i,3)p[i]=0;
	rep(i,l){
		char x=S[i];
		int a=x-'a';
		p[a]++;
	}
	
	bool ok=true;
	if(abs(p[0]-p[1])>1)ok=false;
	if(abs(p[1]-p[2])>1)ok=false;
	if(abs(p[2]-p[0])>1)ok=false;
	if(ok)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}

Measured memory_bytes: 512
import java.util.*;

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

    int a = sc.nextInt();  //時針長さ
    int b = sc.nextInt();  //分針長さ
    int h = sc.nextInt()*60;  //時
    int w = sc.nextInt();  //分
    
    double radA = 2*Math.PI/(12*60);  //時針角速度(rad/min)
    double radB = 2*Math.PI/60;  //分針角速度(rad/min)
    double x = Math.abs(w*radB-(h+w)*radA);
    
    double ans2 = Math.pow(a, 2)+Math.pow(b, 2)-2*a*b*Math.cos(x);
    double ans = Math.sqrt(ans2);
    System.out.println(ans);
  }
}

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

using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define f first
#define s second
#define pii pair<int,int>
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int MAX_N = 2e6 + 1;

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int col = 1;
    int sum = 0;
    while (sum < n) {
        int x = 1;
        for (int i = 0; i < col; ++i) {
            x *= 26;
        }
        sum += x;
        col++;
    }
    col--;
    int x = 1;
    for (int j = 0; j < col; ++j) {
        x *= 26;
    }
    sum -= x;
    n -= sum;
    for (int i = 0; i < col; ++i) {
        for (int j = 1; j <= 26; ++j) {
            int left = 1;
            for (int k = 0; k < col - i - 1; ++k) {
                left *= 26;
            }
            if (j * left >= n) {
                cout << (char)('a' + j - 1);
                n -= (j - 1) * left;
                break;
            }
        }
    }
}

Measured memory_bytes: 3616
//#pragma GCC optimize "trapv"
#include<bits/stdc++.h>
#define ll long long int
#define fab(a,b,i) for(int i=a;i<b;i++)
#define pb push_back
#define db double
#define mp make_pair
#define endl "\n"
#define f first
#define se second
#define all(x) x.begin(),x.end()
#define MOD 1000000007
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
db n,a[3005];
db dp[3005][3005];
void builddp()
{
	cout<<setprecision(12);
	dp[0][0]=1-a[0];
	dp[0][1]=a[0];
	for(int i=1;i<n;i++)
	{
		dp[i][0]=dp[i-1][0]*(1-a[i]);
		fab(1,i+2,j)
		{
			dp[i][j]=dp[i-1][j]*(1-a[i])+dp[i-1][j-1]*a[i];
		
		//cout<<dp[i][j]<<" ";
		}
		//cout<<endl;
	}

	db ans=0;

	fab(n/2+1,n+1,i)
	ans+=(dp[int(n-1)][i]);
	cout<<setprecision(12)<<ans<<endl;
}


int main()
{ quick;

	cin>>n;
	fab(0,n,i)
	cin>>a[i];
	//memset(dp,-1,sizeof(dp));
	builddp();
	return 0;
}

Measured memory_bytes: 68992
def div(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

N, M = map(int, input().split())
for i in reversed(div(M)):
    if i <= M//N:
        print(i)
        break    

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define MAX 100000000
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main() {
  int N,K;
  cin >> N >> K;
  //dp[0]は何もしてない状態
  vector<ll> h(N), dp(N+1);
  for(int i=0;i<N;i++) cin >> h[i];
  dp[0]=0,dp[1]=0;

  for(int i=2;i<=N;i++) {
    ll min=dp[i-1]+abs(h[i-1]-h[i-2]);
    for(int num=2;i-1-num>=0&&num<=K;num++) {
      if(min > dp[i-num]+abs(h[i-1]-h[i-1-num]) )
        min = dp[i-num]+abs(h[i-1]-h[i-1-num]);
    }
    dp[i]=min;
  }
  cout << dp[N] << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
static const int INF = 1000010000;
static const int MOD = 1000000007;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue

//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge {
	int u, v;
	ll cost;
};

bool comp(const edge& e1, const edge& e2) {
	return e1.cost < e2.cost;
}

#define N 100010

int par[N];
int urank[N];

void init(int n) {
	REP(i, n) {
		par[i] = i;
		urank[i] = 0;
	}
}

int find(int x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y) return;

	if (urank[x] < urank[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (urank[x] == urank[y]) urank[x]++;
	}
}

bool same(int x, int y) {
	return find(x) == find(y);
}

edge es[N];

bool used[N];
int V, E;

ll kruskal() {
	sort(es, es + E, comp);
	init(V);
	ll res = 0;
	REP(i, E) {
		edge e = es[i];
		if (!same(e.u, e.v) && !used[e.u] && !used[e.v]) {
			unite(e.u, e.v);
			res += e.cost;
			used[e.u] = used[e.v] = true;
		}
	}
	return res;
}

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int ans = a + b + c;
	cout << ans - max(a, max(b, c)) << endl;
}


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

#define mod 1000000007

using namespace std;
typedef long long ll; 
 
int main(void){
	
	int N;
	
	cin >> N;
	
	int C[N-1], S[N-1], F[N-1], ans[N] = {};
	
	for(int i=0; i<N-1; i++)
		cin >> C[i] >> S[i] >> F[i];
	
	for(int i=0; i<N-1; i++){
		for(int j=i; j<N-1; j++){
			if(ans[i] < S[j])
				ans[i] = S[j];
			else if(ans[i] % F[j] == 0);
			else
				ans[i] += F[j] - ans[i]%F[j];
			ans[i] += C[j];
		}
		cout << ans[i] << endl;
	}
	cout << 0 << endl;

	return 0;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL)
    x = x->left;
  return x;
}

Node treeSearch(Node u, int k){
  while(u!=NIL && k!=u->key){
    if(k<u->key)
      u = u->left;
    else u = u->right;
  }
  return u;
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right!=NIL)
    return treeMinimum(x->right);
  y = x->parent;
  while(y!=NIL && x==y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left==NIL)
    transPlant(z,z->right);
  else if(z->right==NIL)
    transPlant(z,z->left);
  else {
    y = treeMinimum(z->right);
    if(y->parent!=z){
      transPlant(y,y->right);
      y->right = z->right;
      y->right->parent = y;
    }
    transPlant(z,y);
    y->left = z->left;
    y->left->parent = y;
  }
}

void transPlant(Node u,Node v){
  if(u->parent==NIL)
    root = v;
  else if(u==u->parent->left)
    u->parent->left = v;
  else u->parent->right = v;
  if(v!=NIL)
    v->parent = u->parent;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y = x;
    if(z->key<x->key)
      x = x->left;
    else x = x->right;
  }

  z->parent = y;
  
  if(y==NIL)
    root = z;
  else if(z->key<y->key)
    y->left = z;
  else y->right = z;
}

void inorder(Node u){
  if(u!=NIL){
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  if(u!=NIL){
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  Node T;
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      T = treeSearch(root, x);
      if ( T != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
  
  return 0;
}

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

int main(){
  ll n,a,b;
  cin >> n >> a >> b;
  ll ans = (n/(a+b))*a;
  if(n%(a+b)>a) ans += a;
  else ans += n%(a+b);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    map<long long,int> m;
    
    int n,q;
    cin>>n;
    
    int a[n];
    
    for(int i=0; i<n; i++){
        cin>>a[i];
        m[a[i]]++;
    }
    
    long long sum = 0;
    
    for(auto it: m){
         sum+=(it.first*it.second);
    }
    
    cin>>q;
    
    while(q--){
        int a,b;
        
        cin>>a>>b;
        
        sum += m[a] * (b-a);
        
        m[b]+=m[a];
        m[a]=0;
        
        cout<<sum<<endl;
    }

}


Measured memory_bytes: 9804
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
ll mod=1e9+7;
#define PI acos(-1)
struct edge{int from, to;};

int main(){
    int n,m;
    cin>>n>>m;
    int L[m], R[m];
    int l=0,r=1001001;
    rep(i,m) {
        cin>>L[i]>>R[i];
        l=max(l, L[i]);
        r=min(r, R[i]);
    }
    if(r-l+1<0) cout<<0<<endl;
    else cout<<r-l+1<<endl;
    return 0;
}

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

typedef long long int LL;
#define REP(n) for(LL i = 0; i < (n); i++)
#define COUT(val) cout << (val) << endl
#define CIN(val) cin >> (val)
#define SORT(vec) sort(vec.begin(), vec.end())
#define SORT_GRE(vec) sort(vec.begin(), vec.end(), greater<LL>())

int main(){
    int s;
    cin >> s;
    if(s == 1){
        cout << 4 << endl;
        return 0;
    } else if(s == 2){
        cout << 4 << endl;
        return 0;
    } else if(s == 4){
        cout << 4 << endl;
        return 0;
    }
    vector<int> a(1000000);
    a[0] = s;
    for(int i = 1; i < 1000001; i++){
        if(a[i-1] % 2 == 0){
            a[i] = a[i-1] / 2;
        } else {
            a[i] = a[i-1]*3 +1;
        }
    }
    vector<pair<bool, pair<int, int>>> keeper;
    bool exists;
    int pos;
    for(int i = 2; i < a.size(); i++){
        if(a[i-2] == 4 && a[i-1] == 2 && a[i] == 1){
            cout << i+2 << endl;
            break;
        }
    }
    return 0;
}

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

public class Main{
	
	static int[] daruma;
	static int[][] memo;
	static int max(int i, int j) {//番目
		if(memo[i][j]==-1) {
			int n=j-i;
			if(n==1) {
				memo[i][j]=0;
			}//個数が1個の時
			else if(n==2) {
				assert(j-1==i+1);
				memo[i][j]=(Math.abs(daruma[i]-daruma[i+1])<=1)? 2:0;
			}//個数が2個の時
			else {
				int lmax=0;
				if(n>=4) {//両端のやつが消せるかどうか
					lmax=max(i+1, j-1);
					lmax+=(lmax==n-2)?(Math.abs(daruma[i]-daruma[j-1])<=1? 2:0):0;
				}//両端以外が消えていたら、両端が条件満たすとき加え、消えてないときは0
				for(int k=i+1; k+1<j; k++) {//二つのブロックにわけていく
					int top=max(i, k);
					int bot=max(k, j);
					if(lmax<top+bot) {
						lmax=top+bot;
					}
				}
				memo[i][j]=lmax;
			}
		}
		return memo[i][j];
	}
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			while(sc.hasNext()) {
				int n=sc.nextInt();
				if(n==0) break;
				daruma=new int[n];
				memo=new int[n][n+1];
				for(int i=0; i<n; i++) {
					daruma[i]=sc.nextInt();
					Arrays.fill(memo[i], -1);
				}
				System.out.println(max(0,n));
			}
		}
	}
}


Measured memory_bytes: 58940
#include <stdio.h>

int main(void)
{
	int a, b;
	int ret1, ret2, ret3;
	fscanf(stdin, "%d %d\n", &a, &b);
	
	ret1 = a %3;
	ret2 = b %3;
	ret3 = (a + b) % 3;
	
	if (ret1 == 0 || ret2 == 0 || ret3 == 0) {
		printf("Possible\n");
	} else {
		printf("Impossible\n");
	}

	return 0;
}

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

using namespace std;

int main(){
  string s,t;
  cin>>s;
  cin>>t;
  int conv_s[26];
  int conv_t[26];
  for(int i = 0;i<26;i++){
    conv_s[i] = -1;
    conv_t[i] = -1;
  }
  for(int i = 0;i<s.size();i++){
    int a = s[i] - 'a';
    int b = t[i] - 'a';

    if(conv_s[a] != -1 || conv_t[b] != -1){
      if(conv_s[a] != b || conv_t[b] != a){
	//	cout<<i<<" "<<conv_s[a]<<" "<<conv_t[b]<<endl;
	//	cout<<a<<"\t"<<b<<"\t"<<s[i]<<"\t"<<t[i]<<endl;
	cout<<"No"<<endl;
	return 0;
      }
    }else{
      conv_s[a] = b;
      conv_t[b] = a;
    }
  }
  cout<<"Yes"<<endl;
 
  return 0;
}


Measured memory_bytes: 776
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>
#include <deque>
#include <bitset>
#include <cassert>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int dy[]={-1,0,1,0},dx[]={0,1,0,-1};
// adjust problem by problem
const double EPS=1e-8;
const double PI=acos(-1.0);
#ifdef __GNUC__
int popcount(int n){return __builtin_popcount(n);}
int popcount(ll n){return __builtin_popcountll(n);}
#endif
#ifndef __GNUC__
template<class T> int popcount(T n){int cnt=0;while(n){if(n%2)cnt++;n/=2;}return cnt;}
#endif
template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> void PrintSeq(T &a,int sz){for(int i=0;i<sz;i++){cout<<a[i];if(sz==i+1)cout<<endl;else cout<<' ';}}
bool EQ(double a,double b){return abs(a-b)<EPS;}
void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}
vector<string> split(string str,char del){
  vector<string> res;
  for(int i=0,s=0;i<SIZE(str);i++){
    if(str[i]==del){if(i-s!=0)res.push_back(str.substr(s,i-s));s=i+1;}
    else if(i==SIZE(str)-1){res.push_back(str.substr(s));}
  }
  return res;
}

int N;
string store;

bool solve(string &str){
  for(int j=0;j<(int)str.size();j++){
    if(str[j]==store[0]){
      for(int k=j+1;k<(int)str.size();k++){
        if(str[k]==store[1]){
          const int sz=k-j;
          int pos=2;
          vector<int> v;
          v.push_back(j);
          v.push_back(k);
          for(int l=k+sz;l<(int)str.size();l+=sz){
            if(pos<(int)store.size()&&store[pos]==str[l]){
              pos++;
              v.push_back(l);
            }
          }
          bool ok=true;
          for(int j=2;j<(int)v.size();j++)
            if(v[1]-v[0]!=v[j]-v[j-1])ok=false;
          ok&=(pos==(int)store.size());
          if(ok){
            return true;
          }
        }
      }
    }
  }
  return false;
}

int main(){

  cin>>N;
  cin>>store;
  int cnt=0;
  for(int i=0;i<N;i++){
    string str;
    cin>>str;
    cnt+=solve(str);
  }
  cout<<cnt<<endl;

  return 0;
}

Measured memory_bytes: 1232
#include <iostream>
#include <cstdio>
#include  <cmath>
using namespace std;
int main(){
	int a,b;
	scanf("%d %d",&a, &b);
	if(a+b >= a-b && a+b >= a* b){
		printf("%d\n",a+b);
		return 0;
	}
	if(a-b >= a+b && a-b >= a * b){
		printf("%d\n",a-b);
		return 0;
	}
	if(a*b >= a-b && a*b >= a + b){
		printf("%d\n",a*b);
		return 0;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define MAX 105
#define WMAX 10005

struct Item
{
    int v,w;
};

Item item[MAX];

int main(){
    int N,W; cin >> N >> W;
    for(int i = 1; i <= N; i++){
        cin >> item[i].v >> item[i].w;
    }
    
    bool t[MAX][WMAX];
    int table[MAX][WMAX];
    for(int i = 0; i <= N; i++){
        for(int j = 0; j <= W; j++){
            t[i][j] = false;
            table[i][j] = 0;
        }
    }

    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= W; j++){
            table[i][j] = table[i-1][j];
            if(j < item[i].w){
                continue;
            }
            table[i][j] = max(table[i][j], table[i-1][j-item[i].w]+item[i].v);
        }
    }
    cout << table[N][W] << endl;

    return 0;
}


Measured memory_bytes: 7032
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Arrays;

public class Main {

	static FastScanner sc = new FastScanner();

	public static void main(String[] args) throws Exception {
		int[] hist = new int[256];
		while (true) {
			int N = sc.nextInt();
			if (N == 0) break;
			int[] I = new int[N];
			double[] en = new double[N + 1];
			for (int i = 0; i < N; ++i) {
				double v = 1.0 * (i + 1) / N;
				en[i + 1] = -v * Math.log(v);
				I[i] = sc.nextInt();
			}
			double best = Double.MAX_VALUE;
			int bs = 0;
			int ba = 0;
			int bc = 0;
			for (int s = 0; s < 16; ++s) {
				for (int a = 0; a < 16; ++a) {
					OUT: for (int c = 0; c < 16; ++c) {
						Arrays.fill(hist, 0);
						int r = s;
						for (int i = 0; i < N; ++i) {
							r = (a * r + c) & 0xFF;
							hist[(I[i] + r) & 0xFF]++;
						}
						double e = 0;
						for (int i = 0; i < 256; ++i) {
							if (hist[i] != 0) {
								e += en[hist[i]];
								if (e > best) continue OUT;
							}
						}
						if (e < best - 1e-10) {
							best = e;
							bs = s;
							ba = a;
							bc = c;
						}
					}
				}
			}
			System.out.println(bs + " " + ba + " " + bc);
		}
	}

	static class FastScanner {
		Reader input;

		FastScanner() {
			this.input = new BufferedReader(new InputStreamReader(System.in));
		}

		int nextInt() throws IOException {
			int sign = 1;
			int b = input.read();
			while ((b < '0' || '9' < b) && b != '-' && b != '+') {
				b = input.read();
			}
			if (b == '-') {
				sign = -1;
				b = input.read();
			} else if (b == '+') {
				b = input.read();
			}
			int ret = b - '0';
			while (true) {
				b = input.read();
				if (b < '0' || '9' < b) return ret * sign;
				ret *= 10;
				ret += b - '0';
			}
		}
	}

}

Measured memory_bytes: 21840
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
#include <set>
#include <random>
using namespace std;
int main() {
  long long a, b, c;
  cin >> a >> b >> c;
  cout << min(b + c, a + 2 * b + 1) << endl;
  return 0;
}


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

// Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

// Type / Class / Struct Definitions:
using namespace std;

using ll = long long;
using ull = unsigned long long;

// Constants:
const int INF = (1ll << 30) - 1;  // approx 1.07e9
const ll INFLL = 1ll << 60;       // approx 1.15e18
const int MOD = 1e9 + 7;          // 998244353
const long double EPS = 1.0e-14;

// Global Variables:

// Prototype Declarations:
int gcd(int, int);
template <class T>
inline bool chmin(T&, T);
template <class T>
inline bool chmax(T&, T);

// ================ Main Loop ================
int main() {
    int x, y;
    cin >> x >> y;
    rep(i, x + 1) {
        if(y == i * 2 + (x - i) * 4) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}
// ===========================================

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

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


Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cstdio>
#define LL long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int a,b,c,m,cnt;
int main(){
	cin>>a>>b>>c>>m;
	while(b<=a)b<<=1,cnt++;
	while(c<=b)c<<=1,cnt++;
	cout<<(cnt>m?"No\n":"Yes\n");
	return 0;
}


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

int main(){
	int A,B,x;
  cin>> A>> B;
  for(int i=A;i<B+1;i++){
  	 if(i/10000 == i%10 && i/1000%10 == i%100/10) x++;
     }
  	  cout << x;
}

Measured memory_bytes: 380
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <queue>

using namespace std;

class Node{
    public:
        int id;
        int parent;
        int depth;
        int degree;
        int sibling;
        int high;
        string type;
        Node* right;
        Node*  left;
        Node():id(-1),parent(-1),depth(-1),degree(0),sibling(-1),high(0),type(""){}
};

vector<Node> root;

int dfs(int id,int d){

    int h;
    root[id].high=0;
      
    if(root[id].depth<d)
        root[id].depth=d;
    if(root[id].right->id!=-1){
        root[id].right->sibling=root[id]. left->id;
    }
    if(root[id]. left->id!=-1){
        root[id]. left->sibling=root[id].right->id;
    }

    if(root[id].right->id!=-1){
        h=dfs(root[id].right->id,d+1);
    }
    if(root[id].high<h)
        root[id].high=h;

    if(root[id]. left->id!=-1){
        h=dfs(root[id].left->id,d+1);
    }
    if(root[id].high<h)
        root[id].high=h;
    //return h+1;
    return root[id].high+1;
}


void pro(int id){
    if(root[id].id!=-1){
        cout<<" "<<root[id].id;
        if(root[id]. left->id!=-1)
            pro(root[id]. left->id);
        if(root[id].right->id!=-1)
            pro(root[id].right->id);
    }
}

void ino(int id){
    if(root[id].id!=-1){
        if(root[id]. left->id!=-1)
            ino(root[id].left->id);
        cout<<" "<<root[id].id;
        if(root[id].right->id!=-1)
            ino(root[id].right->id);
    }
}


void pos(int id){
    if(root[id].id!=-1){
        if(root[id]. left->id!=-1)
            pos(root[id]. left->id);
        if(root[id].right->id!=-1)
            pos(root[id].right->id);
        cout<<" "<<root[id].id;
    }
}                         




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

    int n, l, r;
    cin>>n;
    for(int i=0;i<n;i++){
        Node node;
        cin>>node.id>>l>>r;
        node.left=new Node();
        node.right=new Node();
        node.left->id=l;
        node.right->id=r;
        root.push_back(node);
    }

    sort(begin(root),end(root),
            [](const Node &r, const Node &l){
            return r.id < l.id;
    });

   for(int i=0; i<n; i++){
        root[root[i].right->id].parent=root[i].id;
        root[root[i].left->id].parent=root[i].id;
        /*親をセット*/
   }
   for(int i=0;i<n;i++){
       if(root[i].parent==-1)
            root[i].high=dfs(i,0);
       if(root[i]. left->id!=-1){
            root[i].degree++;
       }
       if(root[i].right->id!=-1){
            root[i].degree++;
       }
   }
   for(int i=0;i<n;i++){
         root[root[i].right->id].sibling=root[root[i]. left->id].id;
         root[root[i]. left->id].sibling=root[root[i].right->id].id;
   }

   int p;
   for(int i=0;i<n;i++){  
         if(root[i].parent==-1){
            p=i;
        }
    }
    cout<<"Preorder"<<endl;
    pro(p);
    cout<<"\nInorder"<<endl;
    ino(p);
    cout<<"\nPostorder"<<endl;
    pos(p);
    cout<<endl;

    for(int i=0;i<root.size();i++){
        delete root[i].right;
        delete root[i].left;
    }
    return 0; 
}

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

int main() {
  int N,number=1,count=0;
  cin >> N;
  vector<int> S(N);
  for(int i=0;i<N;i++){
    cin >> S.at(i);
  }
  
  for(int i=0;i<N;i++){
    if(S.at(i)!= number){
      count++;
    }
    else{
      number++;
    }
  }
  if(count == N){
    cout << -1 << endl;
  }
  else{
    cout << count << endl;
  }
  
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
 
template<class T> bool find(T v,int a){
  for (auto b :v){
    if (a==b){
      return true;
    }
  }
  return false;
}
int main(){
  string s;
  int x,y;
  cin >>s;
  cin >>x>>y;
  int tmp=0;
  bool T=true;
  int asize=0,bsize=0;
  vector<int> a(8000,0),b(8000,0);
  for(auto i:s){
    if (i=='T') {
      tmp=1-tmp;
      T=true;
    }
    else if (tmp==0){
      if (T){
        asize+=1;
        T=false;
      }
      a[asize-1]+=1;
    }
    else{
      if (T) {
        bsize+=1;
        T=false;
      }
      b[bsize-1]+=1;
    }
  }
  unordered_set<int> c={0};
  for (int i=0;i<asize;++i){
    unordered_set<int> d;
    if (i==0){
      if (s[0]=='T') d.insert(-a[i]);
      d.insert(a[i]);
    }
    else{
      for(auto j :c){
        d.insert(j+a[i]);
        d.insert(j-a[i]);
      }
    }
    c=d;
  }
  if (!(find(c,x))){
    cout << "No"<<endl;
    exit(0);
  }
  c={0};
  for(int i=0;i<bsize;++i){
    unordered_set<int> d;
    for (auto j:c){
      d.insert(j+b[i]);
      d.insert(j-b[i]);
    }
    c=d;
  }
  if (!(find(c,y))){
    cout << "No"<<endl;
    exit(0);
  }
  cout << "Yes"<<endl;
}

Measured memory_bytes: 768
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    cin >> N;
    if (N == 1) {
        write("1\n0");
    }
    else if (N == 2) {
        write("2\n0\n11");
    }
    else {
        write(N - 1);
        rep(i, N - 1) {
            write("0" + string(i, '1') + "0");
        }
    }
}


Measured memory_bytes: 3236
N  = int(input())
A  = list(map(int,input().split()))

ttl = sum(A)
ttl -= A[0]

ans = 0
mod= 10**9+7
for i in range(len(A)-1):
    ans += A[i]*ttl
    ttl %= mod
    ans %= mod
    ttl -= A[i+1]
    # print(ans,ttl)
print(ans)




Measured memory_bytes: 105180
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kishan Sairam Adapa
 */

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define ll long long int
#define MOD ((int)(1e9) + 7)

using namespace std;

class AFairness {
public:
    void solve(istream& cin, ostream& cout) {
        int a, b, c; ll k;
        cin >> a >> b >> c >> k;
        cout << ((k %2 == 0) ? a - b : b-a) << '\n';
    }
};


int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    AFairness solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
from sys import stdin
import itertools

n, m, x = [int(x) for x in stdin.readline().rstrip().split()]
c = [[int(y) for y in x.rstrip().split()] for x in stdin.readlines()]
c.sort()
mi = -1
r = 0

for j in range(1, m + 1):
    li = [x[j] for x in c]
    li.sort(reverse=True)
    for i in range(1, len(li) + 1):
        if sum(li[:i]) >= x:
            r = max(r, i)
            break

for h in range(r, n + 1):
    for i in itertools.combinations(c, h):
        cnt = [0] * m
        mon = 0
        for j in i:
            cnt = [cnt[k]+j[k+1] for k in range(len(cnt))]
            mon += j[0]
            if sum(1 for k in cnt if k >= x) == m:
                if mi > mon or mi == -1:

                    mi = mon
                break

print(mi)


Measured memory_bytes: 9168
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

    llint a, b;
    cin >> a >> b;
    llint ans=a;
    if(ans%b == 0) cout << "-1" << "\n";
    else cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
typedef long long LL;
const int N = 203, mod = 998244353;
int n, x[N], y[N], fac[N], inv[N], po[N], ans;
inline int sub(int a, int b){int c = a - b; if(c < 0) c += mod; return c;}
inline int add(int a, int b){int c = a + b; if(c >= mod) c -= mod; return c;}
inline void upd(int &a, int b){a += b; if(a >= mod) a -= mod;}
inline int kasumi(int a, int b){
	int res = 1;
	while(b){
		if(b & 1) res = (LL) res * a % mod;
		a = (LL) a * a % mod;
		b >>= 1;
	}
	return res;
}
inline bool check(int i, int j, int k){
	return (x[j] - x[i]) * (y[k] - y[i]) == (x[k] - x[i]) * (y[j] - y[i]);
}
int main(){
	scanf("%d", &n); ans = n + 1;
	fac[0] = po[0] = 1;
	for(Rint i = 1;i <= n;i ++) fac[i] = (LL) i * fac[i - 1] % mod, po[i] = add(po[i - 1], po[i - 1]);
	inv[n] = kasumi(fac[n], mod - 2);
	for(Rint i = n;i;i --) inv[i - 1] = (LL) inv[i] * i % mod;
	for(Rint i = 1;i <= n;i ++) scanf("%d %d", x + i, y + i);
	for(Rint i = 1;i <= n;i ++)
		for(Rint j = i + 1;j <= n;j ++){
			int sum = 0;
			for(Rint k = 1;k <= n;k ++) sum += check(i, j, k);
			upd(ans, (LL) (po[sum] - sum - 1) * fac[sum - 2] % mod * inv[sum] % mod * 2ll % mod);
		}
	printf("%d\n", sub(po[n], ans));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	long long int n;
	cin >> n;
	long long int a[n]; 
	for(int i=0;i<n;i++){
    cin >> a[i];
}  
	long long int b;
	b=0;
	if(a[0] != 0){
	b=b+1;
	}for(int i=1;i<n;i++){
	if((a[i-1])<(a[i]-1)){
	b=b+1;
}
}
	if(b != 0){
	cout << -1 << endl;
}
	if(b == 0){
	long long int c;
	c=a[n-1];
	for(int i=n-2;i>0;i=i-1){
	if(a[i] != (a[i+1]-1)){
	c=c+a[i];
}
}
	cout << c << endl;
}
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>

using namespace std;

inline int gi()
{
    int f = 1, x = 0;
    char c = getchar();
    while (c < '0' || c > '9')
    {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9')
    {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return f * x;
}

int a, b;

int main()
{
	a = gi(), b = gi();
	if (a < b) puts("0");
	else puts("10");
	return 0;
 } 

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int a, b;
  scanf("%d %d", &a, &b);
  char s[a + b + 2];
  scanf("%s\n", s);
  for(int i = 0; i < a+b+1; i++){
	if((i == a && s[i] != '-') ||  ((i != a) && (s[i] < '0' || s[i] > '9'))){
      printf("%s\n", "No");
      return 0;
    }
  }
  printf("%s\n", "Yes");
  return 0;
}

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

int main()
{
    long long n, a, b, c, d, e;
    cin >> n;
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> d;
    cin >> e;

    long long min_move = min({a, b, c, d, e});
    long long answer = (n + min_move - 1) / min_move + 4;
    cout << answer << endl;
}

Measured memory_bytes: 256
S,d=gets.chomp.split(' ')

if(S == "zyxwvutsrqponmlkjihgfedcba")
	puts -1
	exit(0)
end
s = S.split('')
alf = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

cand = alf.reject{|a| s.include?(a)}
if(!cand.empty?)
	sel = cand[0]
	puts S + sel
else
	cl = [s[-1]]
	s = s[0..-2]
	while(cl.select{|c| c > s[-1]}.empty?)
		cl << s[-1]
		s = s[0..-2]
	end
	c = cl.select{|c| c > s[-1]}[0]
	s = s[0..-2] + [c]
	puts s.join("")
end


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

int main(){
    char ar[4];
    for(int i=0;i<4;i++){
        cin>>ar[i];
    }

    int x=0;
    for(int i=0;i<3;i++){
       if(ar[i]==ar[i+1]) {
        x++;
       }
    }
    if(x>0){
        cout<<"Bad"<<endl;
    }
    else{
        cout<<"Good"<<endl;
    }

}



Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ip;
#define MOD 1000000007
#define N 1000001


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n,i,j,k,m,G;
    cin>>n;
    vector<ll>A(n),B(N);
    for(i=0;i<n;i++){
        cin>>A[i];
        B[A[i]]++;
    }

    G=A[0];

    for(i=0;i<n;i++){
        G=__gcd(G,A[i]);
    }

    ll pw=1,sw=1;

    if(G!=1)
    sw=0;


    vector<bool>C(N,0);
    ll v;
    for(i=2;i<=N;i++){
        v=0;
        if(!C[i]){
            j=1;
            while(i*j<=N){
                v+=B[i*j];
                C[i*j]=1;
                j++;
            }
        }
        if(v>1){
            pw=0;
            break;
        }
    }

    if(pw)
    cout<<"pairwise coprime"<<"\n";
    else if(sw)
    cout<<"setwise coprime"<<"\n";
    else
    cout<<"not coprime";

    
    
    return 0;
}

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

int main() {
	string n;
	string ans = "No";
	cin >> n;
	int size = n.size();
	vector<int> num(size);
	int total = 0;
	for (int i = 0; i < size; i++) {
		num[i] = n[i] - '0';
	}
	for (int i = 0; i < size; i++) {
		total += num[i];
	}
	if (total%9 == 0) {
		ans = "Yes";
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4364
#include<bits/stdc++.h>
using namespace std;
int main(void){
    vector<int>x(5);
    int ans;
    for(int i =0;i<5;i++){
        cin>>x[i];
        if(x[i] == 0)ans = i+1;
    }
    cout<<ans<<endl;
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    ll ans = 0;
    for (int b = k + 1; b <= n; b++) {
        ans += (ll)(n / b) * (b - k);
        int tmp = n % b;
        ans += max(tmp - k + (k != 0), 0);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        _n: usize,
        m: usize,
        py: [(usize, usize); m],
    }
    let mut pyi = py.iter().enumerate().map(|(i, &(pi, yi))| (pi, yi, i, String::new())).collect::<Vec<_>>();
    pyi.sort();
    let mut count = 0;
    for i in 0..m {
        if i == 0 || pyi[i - 1].0 != pyi[i].0 {
            count = 0;
        }
        count += 1;
        pyi[i].3 = format!("{:06}{:06}", pyi[i].0, count);
    }
    pyi.sort_by_key(|row| row.2);
    for i in 0..m {
        println!("{}", pyi[i].3);
    }
}


Measured memory_bytes: 14588
from sys import stdin
from collections import deque
n = int(input())
d = [-1] * (n + 1)
def bfs():
    d[1] = 0
    dq = deque([1])
    while len(dq) != 0:
        v = dq.popleft()
        for c in G[v]:
            if d[c] != -1 : continue
            d[c] = d[v] + 1
            dq.append(c)
    for i, x in enumerate(d[1:], start=1):
        print(i, x)
G = [0] + [list(map(int, input().split()[2:])) for i in range(n)]
bfs()

Measured memory_bytes: 8076
N,M,C = map(int, input().split())
*B, = map(int, input().split())
A = [
        list(map(int, input().split()))
        for _ in range(N)
    ]

ans = 0

for a in A:
    if sum([x*y for x,y in zip(a, B)]) + C > 0:
        ans += 1

print(ans)

Measured memory_bytes: 9160
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>


int main(){
  std::string str;
  int n, cmd1, cmd2;
  char c;
  bool reverse = false;
  std::cin >> str >> n;
  for(int i=0;i<n;i++)
  {
    std::cin >> cmd1;
    if(cmd1 == 1)
    {
      reverse = !reverse;
    }
    if(cmd1 == 2)
    {
      std::cin >> cmd2 >> c;
      if((cmd2 == 1 && !reverse) || (cmd2 == 2 && reverse)) { str.insert(str.begin(), c); }
      if((cmd2 == 1 && reverse) || (cmd2 == 2 && !reverse)) { str += c; }
    }
  }
  if(reverse)
  {
    for(int i=0;i<str.size();i++)
    {
      std::cout << str[str.size()-1-i];
    }
    std::cout << std::endl;
  }
  else
  {
    std::cout << str << std::endl;
  }
  return 0;
}


Measured memory_bytes: 900
a, b, c, d = input()
a = int(a)
b = int(b)
c = int(c)
d = int(d)
output = ""

def ope(i):
    if i == 0:
        return "+"
    else:
        return "-"

for i in range(2):
    if output != "":
        break
    for j in range(2):
        if output != "":
            break
        for k in range(2):
            result = a
            if i == 0:
                result += b
            else:
                result -= b
            if j == 0:
                result += c
            else:
                result -= c
            if k == 0:
                result += d
            else:
                result -= d
            if result == 7:
                output = "{}{}{}{}{}{}{}=7".format(a, ope(i), b, ope(j), c, ope(k), d)
                break

print(output)


Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <ctype.h>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define ENDL '\n'
#define FOR(i, n) for (int i = 0; i < n; i++)
#define FOR_EACH(i, v) for (auto&& i : v)

long long X;
long long Y;

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

	cin >> X >> Y;

	int ans = 0;
	while (X <= Y) {
		X *= 2;
		ans++;
	}

	cout << ans << ENDL;

	return 0;
}

Measured memory_bytes: 3600