akhauriyash/Code-Regression huggingface dataset:
A = int(input())
B = int(input())
C = int(input())
X = int(input())

import itertools
print(len([total for total in map(sum, itertools.product(
    [500 * i for i in range(A + 1)],
    [100 * i for i in range(B + 1)],
    [50 * i for i in range(C + 1)],
)) if total == X]))

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

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

	int happy = (x/500)*1000;
	x = x%500;
	happy += (x/5)*5;

	cout << happy << endl;
	return 0;
}


Measured memory_bytes: 256
program odd_string
  implicit none
  character(100000) :: s
  integer           :: n, i
  read(*,*) s
  s = adjustl(s)
  n = len_trim(s)
  do i = 1, n, 2
    write(*,'(a)',advance='no') s(i:i)
  end do
  write(*,*)
end program odd_string

Measured memory_bytes: 700
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        long mod = 1000000007L;
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt();
        long res1 = n, res2 = m;
        for(int i = 1; i < n; i++) {
            res1 *= i;
            res1 %= mod;
        }
        for(int i = 1; i < m; i++) {
            res2 *= i ;
            res2 %= mod;
        }
        long res = (res1 * res2 * (n == m ? 2 : 1)) % mod;
        if(Math.abs(n - m) > 1) res = 0;
        System.out.println(res);
    }
}


Measured memory_bytes: 22996
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int a;
  cin >> a;
  int answer = a + a * a + a * a * a;
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3692
n=int(input())
a=list(map(int,input().split()))
ans=sum(a)
a=list(map(lambda x: 2*x,a))
odd=0
for i in a[1::2]: odd+=i
k1=ans-odd
print(k1,end=" ")
for i in a[:n-1]:
    k1=i-k1
    print(k1,end=" ")

Measured memory_bytes: 20540
import sys
from collections import deque
input = sys.stdin.readline

H,W = map(int,input().split())
sy, sx = 0,0
gy, gx = H-1,W-1
D = [list(input()) for i in range(H)]
Bs = 0
for i in range(H):
    Bs += D[i].count("#")

Q = deque()
Q.append((sy,sx))
dist = [[-1]*W for i in range(H)]
dist[sy][sx] = 0
dx = [1,0,-1,0]
dy = [0,-1,0,1]

while Q:
    x,y = Q.popleft()
    for i in range(4):
        nx = x+dx[i]
        ny = y+dy[i]
        if 0<=nx<=W-1 and 0<=ny<=H-1 and D[ny][nx]!="#" and dist[ny][nx] == -1:
            Q.append((nx,ny))
            dist[ny][nx] = dist[y][x]+1

print(H*W-Bs-1-dist[gy][gx] if dist[gy][gx]!=-1 else -1)

Measured memory_bytes: 9416
using System;
using System.Collections.Generic;
using System.Linq;

namespace JagArrayTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var inputList = new List<double>();

            for(int count = 0; count < 10; count++)
            {
                inputList.Add(double.Parse(Console.ReadLine()));
            }

            Enumerable.Range(1, 3).ToList().ForEach(d => {
                var maxValue = inputList.Max();
                Console.WriteLine(maxValue.ToString());
                inputList.Remove(maxValue);
            });
        }
    }
}


Measured memory_bytes: 16208
#ifdef _DEBUG
#define _CRT_SECURE_NO_WARNINGS
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define MGN 8
#define LINF (LONG_MAX/2)
using namespace std;
typedef long long ll; typedef unsigned long long ull;
typedef vector<int> vi; typedef vector<vi> vvi;
typedef vector<ll> vl; typedef vector<vl> vvl;
typedef vector<double> vd; typedef vector<string> vs;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
typedef vector<bool> vb; typedef vector<vb> vvb;
template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
    return left.second > right.second;
}
vs split(string str, char sep) {
    vs v; stringstream ss(str); string t;
    while (getline(ss, t, sep)) v.push_back(t);
    return v;}
vs re_search_g(string s, regex re) {
    vs ret; smatch mc; auto it = s.cbegin();
    while (regex_search(it, s.cend(), mc, re)) {
        ret.push_back(mc[0]);
        it += mc.position(0) + mc.length();}
    return ret;}
#endif

void init_global_C() {}


int main_C() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N; cin >> N;
    const int M = 5;
    vl A(M); REP(i, M) cin >> A[i];

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

    ll ans = (N - 1) / A[0] + 5;
    cout << ans << endl;  

    return 0;
}

Measured memory_bytes: 256
def good_number(D, n):
    if n < 10:
        return n % 10 not in D
    return n % 10 not in D and good_number(D, n // 10)

N, K = input().split()
digit_num = len(N)
N = int(N)
K = int(K)
D = list(map(int, input().split()))
ub = int(str(D[0]) * (digit_num + 1))
usable = []
for i in range(10):
    if i not in D:
        usable.append(i)


if usable[0] != 0:
    ub = int(str(usable[0]) * (digit_num + 1))
else:
    ub = int(str(usable[1]) + str("0") * digit_num)
    
for i in range(N, ub + 1):
    if good_number(D, i):
        print(i)
        break

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int da[3001];
int main(){
	int N;
	cin>>N;
	long long int sum=0;
	for(int i=0;i<N;i++){
		cin>>da[i];
		sum+=da[i];
	}
	cout<<sum-N<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

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

#define REP(i, n) for(ll i = 0; i < n; i++)
















int main(){
    string s;
    cin >> s;
    if(s[0] == s[1] && s[1] == s[2]){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
#!usr/bim/python
#! -*- coding: utf-8 -*-

n = raw_input()
n = int(n)

pl = raw_input()
pl = pl.split()
pl = map(int,pl)

c = 0

i = 0
while i < n:
    p = pl[i]
    if i+1 == p:
        c += 1
        i += 2
    else:
        i += 1

print c


Measured memory_bytes: 11304
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;
int main(){
    ll x, y;
    cin >> x >> y;
    int cnt=0;
    while(x <= y){
        x *= 2;
        cnt++;
    }
    out(cnt);

}

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

int main(){
    int N,M;
    vector<int> L(N,0),R(N,0);
    scanf("%d%d",&N,&M);
    for(int i=0; i<M; i++){
        int l,r;
        scanf("%d%d",&l,&r);
        L[i]=l;
        R[i]=r;
    }
    int min=1, max=N;
    for(int i=0; i<M; i++){
        if(L[i]>min) min=L[i];
        if(R[i]<max) max=R[i];
    }
    if(min<=max) printf("%d",max-min+1);
    else printf("0");
    return 0;
}

Measured memory_bytes: 49408
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int r;
  cin >> r;
  r = 3*r*r;
  cout << r << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl;

typedef long long ll;
const ll INF = 99999999999999;
const ll MOD = 1000000007;
const double PI = acos(-1.0);

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll number1, ll number2)
{
    return number1 * number2 / gcd(number1, number2);
}
template <class T>
bool contain(const std::string &s, const T &v)
{
    // contain(to_string(N), '3')
    return s.find(v) != std::string::npos;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
        return c - '0';
    return 0;
}
using namespace std;

unsigned GetDigit(unsigned num)
{
    return std::to_string(num).length();
}

vector<vector<int>> d(10, vector<int>(10));

void warshall_floyd(int n)
{
    for (int k = 0; k < n; k++)
    { // 経由する頂点
        for (int i = 0; i < n; i++)
        { // 始点
            for (int j = 0; j < n; j++)
            { // 終点
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

int main()
{

    int h, w, ans = 0;
    cin >> h >> w;
    rep(i, 10)
    {
        rep(j, 10)
        {
            cin >> d.at(i).at(j);
        }
    }

    warshall_floyd(10);
    int c;
    rep(i, h)
    {
        rep(j, w)
        {
            cin >> c;
            if (c != -1)
            {
                ans += d.at(c).at(1);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
	int a, i, count1 = 0, count2 = 0, count3 = 0, count4 = 0;
	char str[105];
	scanf("%d", &a);
	for(i = 0;i < a;i++){
		scanf("%s", str);
	if(strcmp(str, "AC") == 0){
		count1++;
	}else if(strcmp(str, "WA") == 0){
		count2++;
	}else if(strcmp(str, "TLE") == 0){
		count3++;
	}else if(strcmp(str, "RE") == 0){
		count4++;
	}
}
    printf("AC x %d\n", count1);
    printf("WA x %d\n", count2);
    printf("TLE x %d\n", count3);
    printf("RE x %d\n", count4);
		
	
	
	return 0;
}

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

typedef struct DIFF_DATA {
  int idx;
  int diff;
} ST_D;

int diff_sort( const void * a , const void * b ) {
  return (((ST_D*)b)->diff - ((ST_D*)a)->diff);
}

int int_sort( const void * a , const void * b ) {
  return (*(int*)a - *(int*)b);
}

int main(void) {
  int N, M;
  int X[100000];

  scanf("%d %d", &N, &M);
  for(int i = 0; i < M; i++) {
    scanf("%d", &X[i]);
  }
  qsort((void*)X, M, sizeof(int), int_sort);

  if(N >= M) {
    printf("0\n");
    return 0;
  }

  ST_D D[100000];
  for(int i = 0; i < (M-1); i++) {
    D[i].idx  = i;
    D[i].diff = X[i+1] - X[i];
  }
  qsort((void*)D, (M-1), sizeof(ST_D), diff_sort);

  int CUT[100000];
  for(int i = 0; i < (N-1); i++) {
    CUT[i] = D[i].idx;
  }
  qsort((void*)CUT, (N-1), sizeof(int), int_sort);

  int min = 0;
  int STEP = 0;
  for(int i = 0; i < (N-1); i++) {
    if(min == M-1)
      break;
    STEP += (X[CUT[i]] - X[min]);
    min = CUT[i]+1;
  }
  STEP += (X[M-1] - X[min]);
  
  printf("%d\n", STEP);
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> x(n), y(n), w(n);
    map<P, int> mp;
    rep(i, 0, n){
        cin >> x[i] >> y[i] >> w[i];
        mp[{y[i], x[i]}] += w[i];
    }
    int ans = 0;
    rep(i, 0, n){
        int tmp = 0;
        rep(j, 0, 2){
            rep(k, 0, 2){
                tmp += mp[{y[i] + j, x[i] + k}];
            }
        }
        int tmp2 = 0;
        rep(j, 0, 2){
            rep(k, -1, 1){
                tmp2 += mp[{y[i] + j, x[i] + k}];
            }
        }
        ans = max({ans, tmp, tmp2});
    }
    cout << ans << " / " << 1 << endl;
}


Measured memory_bytes: 41364
import sys
sys.setrecursionlimit(int(1e8))


s = input()
n = len(s)

def rec(op_index, part_s):
    if op_index == n - 1:
        return sum(map(int, part_s.split('+')))
    part_s1 = '{}{}'.format(part_s, s[op_index+1])
    part_s2 = '{}+{}'.format(part_s, s[op_index+1])
    return rec(op_index+1, part_s1) + rec(op_index+1, part_s2)

print(rec(0, s[0]))

Measured memory_bytes: 9172
/*  ex3_3 Digits
    pandacodeb   */

#include <stdio.h>

int main(void){
    int num, base;
    scanf("%d %d", &num, &base);
    int digits = 0;
    while (num > 0){
        num = num / base;    //divide num by base until quotient is 0 (remainder is ignored)
        digits++;            //number of digits is added in every division
    }
    printf("%d\n", digits);
    return 0;
}

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



int main()
{
	int H, W, N;
	int tem[101];
	vector <int> a;
	cin >> H>> W;
	cin >> N;
	int i,temp;
	for (i = 0; i < N; ++i)
	{
		cin >> temp;
		a.push_back(temp);
	}
	
	int tH=1;
	int point=1;

	while (tH<=H)
	{
		if (tH % 2 == 1)
			for (i = 1; i <= W; ++i)
			{
				tem[i] = point;
				--a[point - 1];
				if (a[point - 1] == 0)
					++point;
			}
		else
			for (i = W; i >= 1; --i)
			{
				tem[i] = point;
				--a[point - 1];
				if (a[point - 1] == 0)
					++point;
			}
		++tH;
		for (i = 0; i < W; ++i)
		{
			cout << tem[i+1];
			if (i < W - 1)
				cout << " ";
		}
		cout << endl;
	}


    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define eni(x) template < class c > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
template < class c > struct rge { c b, e; };
template < class c > rge<c> range(c i, c j) { return rge<c>{i, j}; }
template < class c > auto dud(c* x) -> decltype(cerr << *x, 0);
template < class c > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; return * this; }
eni(==) return * this << range(begin(i), end(i)); }
template < class c, class b > debug & operator <<(pair < b, c > d) {
  return * this << "(" << d.first << ", " << d.second << ")";
}
template < class c > debug & operator <<(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  return * this << "]";
}
#else
template < class c > debug & operator <<(const c&) { return * this; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define pll pair<ll,ll>
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define mod 998244353
#define mx 200005
mt19937 myrand(time(0));

int n,q;
ll power[10][mx];

struct lazySegTree{
    int tree[4*mx],lazy[4*mx];
 
    void init(){
        memset(tree,0,sizeof tree);
        memset(lazy,0,sizeof lazy);
    }
    
    void merge(ll pos, ll l, ll r){
        if(!lazy[pos]) return;
        tree[pos]=(power[lazy[pos]][n-l+1]-power[lazy[pos]][n-r])%mod;
        if(tree[pos]<0) tree[pos]+=mod;
        if(l!=r){
            lazy[pos*2]=lazy[pos];
            lazy[pos*2+1]=lazy[pos];
        }
        lazy[pos]=0;
    }

    void update(ll pos, ll l, ll r, ll L, ll R, ll value){
        merge(pos,l,r);
        if(l>R || r<L || L>R) return;
        if(l>=L && r<=R){
            tree[pos]=(power[value][n-l+1]-power[value][n-r])%mod;
            if(tree[pos]<0) tree[pos]+=mod;
            if(l!=r){
                lazy[pos*2]=value;
                lazy[pos*2+1]=value;
            }
            return;
        }
        ll mid=(l+r)/2;
        update(pos*2,l,mid,L,R,value);
        update(pos*2+1,mid+1,r,L,R,value);
        tree[pos]=(tree[pos*2]+tree[pos*2+1])%mod;
    }
 
    ll query(ll pos, ll l, ll r, ll L, ll R){
        merge(pos,l,r);
        if(l>R || r<L){
            return 0;
        }
        if(l>=L && r<=R){
            return tree[pos];
        }
        ll mid=(l+r)/2;
        ll q1=query(pos*2,l,mid,L,R);
        ll q2=query(pos*2+1,mid+1,r,L,R);
        return (q1+q2)%mod;
    }
}seg;


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(),cout.tie();
    for(int j=1;j<10;j++){
        ll c=j;
        for(int i=1;i<mx;i++){
            power[j][i]=(power[j][i-1]+c)%mod;
            c=(c*10)%mod;
        }
    }
    seg.init();
    cin>>n>>q;
    seg.update(1,1,n,1,n,1);
    //debug()<<imie(seg.query(1,1,n,1,n));
    while(q--){
        int l,r,x;
        cin>>l>>r>>x;
        seg.update(1,1,n,l,r,x);
        cout<<seg.query(1,1,n,1,n)<<endl;
    }
    return 0;
}

Measured memory_bytes: 23976
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:https://atcoder.jp/contests/abc118/tasks/abc118_d>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

ll cost[] = {INF,2,5,5,4,5,6,3,7,6};
string dp[10010];
template<class Type>
Type solve(Type res = Type()){
    fill(dp,dp+10010,"#");
    ll N,M; cin >> N >> M;
    vector<ll> A(M); for(auto & in:A) cin >> in;
    dp[0] = "";
    for(int i = 0; i < N;i++){
        if(dp[i]=="#") continue;
        for(int j = 0; j < M;j++){
            string S = dp[i] + to_string(A[j]);
            ll C = cost[A[j]];
            
            if(dp[i+C] == "#"){
                dp[i+C] = S;
            }else{
                if(dp[i+C].length() < S.length()){
                    dp[i+C] = S;
                }else if(dp[i+C].length()==S.length()){
                    dp[i+C] = max(dp[i+C],S);
                }
            }
        }
    }
    res = dp[N];
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<string>() << endl;
    return 0;
}


Measured memory_bytes: 33024
#include<bits/stdc++.h>
//-------------------------------------------------------------
#define FOR(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define FORN(i,b,a)for(int i=(b);_a=(a);i>=_a;i--)
#define REP(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define re return
#define vi vector<int>
#define pb push_back
#define si set<int>
#define in insert
#define fl float
#define db double
#define ld long double
#define X first
#define Y first
#define st string
#define ull unsigned long long
//-------------------------------------------------------------
using namespace std;
//-------------------------------------------------------------
//st ans[2]={"NO","YES"};
//const int maxn=1000100;
//int abs()
//int swap()
//int sort()
//int sqrt()
//-------------------------------------------------------------
/*快排
int partition(int a[],int left,int right);
void quicksort(int a[],int left,int right){
	int q;
	if(left<=right){
		q=partition(a,left,right);
		quicksort(a,left,q-1);
		quicksort(a,q+1,right);
	}
}
int partition(int a[],int left,int right)
{
	int p=a[left];
	int i=left;
	int j=right+1;
	while(1){
		while(a[++i]<p)if(i>=right)break;
		while(a[--j]>p)if(j<=left)break;
		if(i>=j)break;
		else swap(a[i],a[j]);
	}
	if(j==left)return j;
	swap(a[left],a[j]);
	return j;
}
//-------------------------------------------------------------
二分
int binsearch(int x;int v[];int n){
	int low=0,high=n-1;
	int mid;
	while(low<=high){
		mid=(low+high)/2;
		if(x<v[mid]){
			high=mid-1;
		}
		else if(x>v[mid]){
			low=mid+1;
		}
		else return mid;
	}
	return -1;
}*/
//-------------------------------------------------------------
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	string s;
	int ans=0;
	cin>>s;
	for(int i=0;i<s.size()/2;i++)
		if(s[i]!=s[s.size()-1-i])ans++;
	cout<<ans<<endl;
	re 0;
}
//-------------------------------------------------------------


Measured memory_bytes: 256
s=input()
cnt=0
if s=='RRR':
  cnt = 3
elif s== 'RRS':
  cnt = 2
elif s== 'SRR':
  cnt = 2
elif s == 'RSS':
  cnt= 1
elif s == 'RSR':
  cnt=1
elif s == 'SRS':
  cnt=1
elif s=='SSR':
  cnt=1
print(cnt)
    

Measured memory_bytes: 9044
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

template<typename V> struct ConvexHull {
	deque<pair<V,V>> Q;
	V calc(pair<V,V> p, V x) {
		return p.first*x+p.second;
	}
	int dodo(pair<V,V> A,pair<V,V> B, pair<V,V> C) { // max or min
		return ((A.second-C.second)*(B.first-A.first)<=(A.second-B.second)*(C.first-A.first));
	}
    
    // cht.add(a, b);
	void add(V a, V b) { // add ax+b
		Q.push_back({a,b});
		int v;
		while((v=Q.size())>=3 && dodo(Q[v-3],Q[v-2],Q[v-1]))
			Q[v-2]=Q[v-1], Q.pop_back();
	}
	V query(V x) {
		int L=-1,R=Q.size()-1;
		while(R-L>1) {
			int M=(L+R)/2;
			(((calc(Q[M],x)>=calc(Q[M+1],x)))?L:R)=M;
		}
		return calc(Q[R],x);
	}
};

int main() {
    ll n, c;
    cin >> n >> c;
    ll a[n];
    rep(i,n) cin >> a[i];
    ll INF = 1001001001001001001;
    ll dp[n] = {};
    srep(i,1,n) dp[i] = INF;

    ConvexHull<ll> cht;
    cht.add(-2*a[0],a[0]*a[0]+dp[0]+c);

    srep(i,1,n){
        dp[i] = cht.query(a[i]) + a[i]*a[i];
        cht.add(-2*a[i], a[i]*a[i]+dp[i]+c);   
    }


    cout << dp[n-1] << endl;
    return 0;
}




Measured memory_bytes: 9908
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>

#define ALL(a)  (a).begin(),(a).end()

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

int main() {
    ll a, b;
    ll ans = 0;

    vector<int> l;

    cin >> a >> b;

    if (a > 9 || b > 9) ans++;

    (ans == 0) ? (cout << a * b << endl) : (cout << -1 << endl);
    
}


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

using namespace std;

int main(void) {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int count = 0;
    while(a >= b){
        b = b * 2;
        count += 1;
    }
    while(b >= c){
        c = c * 2;
        count += 1;
    }

    if(k >= count){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3632
import sys
input = lambda: sys.stdin.readline().rstrip()

def par(a):
    L = []
    while P[a] >= 0:
        L.append(a)
        a = P[a]
    for l in L:
        P[l] = a
    return a
def unite(a, b):
    if par(a) != par(b):
        if P[par(b)] >= P[par(a)]:
            if P[par(b)] == P[par(a)]: P[par(a)] -= 1
            P[par(b)] = par(a)
        else:
            P[par(a)] = par(b)

N, Q = map(int, input().split())
P = [-1 for i in range(N)]
for _ in range(Q):
    t, u, v = map(int, input().split())
    if t == 0:
        unite(u, v)
    else:
        print(1 if par(u) == par(v) else 0)


Measured memory_bytes: 11712
import sys
import collections as c

input = sys.stdin.readline

def main():
    ans = 0
    N, M = map(int, input().split())
    a = []
    for _ in range(N):
        a += list(map(int, input().split()))[1:]
    co = c.Counter(a)
    for k, v in co.items():
        if v == N:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


ll gcd(ll a,ll b){
    if(b == 0){
        return a;
    }else{
        return gcd(b, a%b);
    }
}

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

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll n, k;
    cin>>n>>k;
    ld ans = 0;
    for(ll i=1;i<=n;++i){
        ll m = i;
        ll index;
        for(ll j=1;j<50;++j){
            if(j == 1 and m >= k){
                index = 0;
                break;
            }
            if(m >= k){
                break;
            }
            m *= 2;
            index = j;
        }
        //cout<<index<<endl;
        ans += 1 / (ld)pow(2, index);
    }
    ans /= n;
    cout<<setprecision(15)<<ans<<endl;

    return 0;
}

Measured memory_bytes: 512
/*
░░░░░░░░░░░░░░░░▄▄█▀▀██▄▄░░░░░░░
░░░░░░░░░░░░░▄█▀▀░░░░░░░▀█░░░░░░
░░░░░░░░░░░▄▀░░░░░░░░░░░░░█░░░░░
░░░░░░░░░▄█░░░░░░░░░░░░░░░█░░░░░
░░░░░░░██▀░░░░░░░▄▄▄░░▄░█▄█▄░░░░
░░░░░▄▀░░░░░░░░░░████░█▄██░▀▄░░░
░░░░█▀░░░░░░░░▄▄██▀░░█████░██░░░
░░░█▀░░░░░░░░░▀█░▀█▀█▀▀▄██▄█▀░░░
░░░██░░░░░░░░░░█░░█░█░░▀▀▄█▀░░░░
░░░░█░░░░░█░░░▀█░░░░▄░░░░░▄█░░░░
░░░░▀█░░░░███▄░█░░░░░░▄▄▄▄█▀█▄░░
░░░░░▀██░░█▄▀▀██░░░░░░░░▄▄█░░▀▄░
░░░░░░▀▀█▄░▀▄▄░▄░░░░░░░███▀░░▄██
░░░░░░░░░▀▀▀███▀█▄░░░░░█▀░▀░░░▀█
░░░░░░░░░░░░▄▀░░░▀█▄░░░░░▄▄░░▄█▀
░░░▄▄▄▀▀▀▀▀█▀░░░░░█▄▀▄▄▄▄▄▄█▀▀░░
░▄█░░░▄██▀░░░░░░░░░█▄░░░░░░░░░░░
█▀▀░▄█░░░░░░░░░░░░░░▀▀█▄░░░░░░░░
█░░░█░░░░░░░░░░░░░░░░░░█▄░░░░░░░
*/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define x first
#define y second
#define pi pair <int, int>
#define pii pair<pair <int, int>, int>
#define vi vector <int>
const ll mod = 1000000007;
const ll nmax=1000003;
#define int ll
int n, m, p, d[50001];
vi g1[2505];
vector<pi> g[50001];
vector<pii> edg;

bool viz[2505], viz1[2505];

void dfs(int nod){
    viz[nod]=1;
    for(int i: g1[nod]){
        if(!viz[i]){
            dfs(i);
        }
    }
}

void dfs1(int nod){
    viz1[nod]=1;
    for(pi i: g[nod]){
        if(!viz1[i.x]){
            dfs1(i.x);
        }
    }
}

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin>>n>>m>>p;
    for(int i=1, x, y, c; i<=m; i++){
        cin>>x>>y>>c;
        g[x].pb({y, p-c});
        g1[y].pb(x);
        //edg.pb({{x, y}, c});
    }

    dfs(n);
    dfs1(1);
    //for(int i=1; i<=n; i++) cout<<viz[i]<<" ";
    vi prev;
    set<int> s;
    prev.pb(1);
    for(int i=2; i<=n; i++) d[i]=1e9;
    for(int i=1; i<=n; i++){
        for(int x : prev){
            for(pi xd: g[x]){
                int y=xd.x, c=xd.y, lol=d[y];
                d[y]=min(d[y], d[x]+c);
                if(i==n && viz[y] && lol!=d[y]) return cout<<-1, 0;
                if(lol!=d[y]) s.insert(y);
            }
        }
        prev.clear();
        for(int nod: s) prev.pb(nod);
        s.clear();
    }
    cout<<max(0LL, -d[n]);
}


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

int main() {
  string C;
  cin >> C;

  if(C=="a") {
    cout << "b" <<endl;
  }
  else if(C=="b") {
    cout << "c" <<endl;
  }
  else if(C=="c") {
    cout << "d" <<endl;
  }
  else if(C=="d") {
    cout << "e" <<endl;
  }
  else if(C=="e") {
    cout << "f" <<endl;
  }
  else if(C=="f") {
    cout << "g" <<endl;
  }
  else if(C=="g") {
    cout << "h" <<endl;
  }
  else if(C=="h") {
    cout << "i" <<endl;
  }
  else if(C=="i") {
    cout << "j" <<endl;
  }
  else if(C=="j") {
    cout << "k" <<endl;
  }
  else if(C=="k") {
    cout << "l" <<endl;
  }
  else if(C=="l") {
    cout << "m" <<endl;
  }
  else if(C=="m") {
    cout << "n" <<endl;
  }
  else if(C=="n") {
    cout << "o" <<endl;
  }
  else if(C=="o") {
    cout << "p" <<endl;
  }
  else if(C=="p") {
    cout << "q" <<endl;
  }
  else if(C=="q") {
    cout << "r" <<endl;
  }
  else if(C=="r") {
    cout << "s" <<endl;
  }
  else if(C=="s") {
    cout << "t" <<endl;
  }
  else if(C=="t") {
    cout << "u" <<endl;
  }
  else if(C=="u") {
    cout << "v" <<endl;
  }
  else if(C=="v") {
    cout << "w" <<endl;
  }
  else if(C=="w") {
    cout << "x" <<endl;
  }
  else if(C=="x") {
    cout << "y" <<endl;
  }
  else if(C=="y") {
    cout << "z" <<endl;
  }
  else {
  }
}


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

int h, w, route[400][400];
bool s[20][20] = {false};

int pack(int i, int j)
{
  return i * w + j;
}

void unpack(int packed, int *i, int *j)
{
  *i = packed / w;
  *j = packed - w * *i;
}

void setroute(int start, int end, int value)
{
  // if (end < start)
  // {
  //   int tmp = start;
  //   start = end;
  //   end = tmp;
  // }
  if (route[start][end] != -1 && route[start][end] <= value)
  {
    return;
  }

  route[start][end] = value;

  value++;

  int i, j;
  // unpack(start, &i, &j);
  // if (h > i + 1 && s[i + 1][j])
  // {
  //   setroute(pack(i + 1, j), end, value);
  // }
  // if (i - 1 >= 0 && s[i - 1][j])
  // {
  //   setroute(pack(i - 1, j), end, value);
  // }
  // if (w > j + 1 && s[i][j + 1])
  // {
  //   setroute(pack(i, j + 1), end, value);
  // }
  // if (j - 1 >= 0 && s[i][j - 1])
  // {
  //   setroute(pack(i, j - 1), end, value);
  // }

  unpack(end, &i, &j);
  if (h > i + 1 && s[i + 1][j])
  {
    setroute(start, pack(i + 1, j), value);
  }
  if (i - 1 >= 0 && s[i - 1][j])
  {
    setroute(start, pack(i - 1, j), value);
  }
  if (w > j + 1 && s[i][j + 1])
  {
    setroute(start, pack(i, j + 1), value);
  }
  if (j - 1 >= 0 && s[i][j - 1])
  {
    setroute(start, pack(i, j - 1), value);
  }
}

int main()
{
  memset(route, -1, sizeof(int) * 400 * 400);
  cin >> h >> w;
  for (int i = 0; i < h; i++)
  {
    for (int j = 0; j < w; j++)
    {
      char tmp;
      cin >> tmp;
      if (tmp == '.')
      {
        s[i][j] = true;
      }
    }
  }

  for (int start = 0; start < h * w; start++)
  {
    int i, j;
    unpack(start, &i, &j);
    if (!s[i][j])
    {
      continue;
    }

    setroute(start, start, 0);
  }

  int max = 0;
  for (int start = 0; start < h * w; start++)
  {
    for (int end = 0; end < h * w; end++)
    {
      if (max < route[start][end])
      {
        max = route[start][end];
      }
      // int i1, j1, i2, j2;
      // unpack(start, &i1, &j1);
      // unpack(end, &i2, &j2);
      // cout << "[" << i1 << ":" << j1 << "] -> [" << i2 << ":" << j2 << "] : " << route[start][end] << endl;
    }
  }
  cout << max << endl;
}


Measured memory_bytes: 896
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
# import statistics
import bisect
import copy
import fractions
import math
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers):
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))
def unite(x, y):
    # それぞれのノードの根を求める
    x = root(x)
    y = root(y)
    if x == y:
        return
    # node[x]の根をyに変更する
    node[x] = y
def same(x,y): return bool(root(x) == root(y))
def root(x):
    if node[x] == x:  # xが根の場合
        return x
    else:
        node[x] = root(node[x])  # 経路圧縮
        return node[x]
def dfs(v):
    # ノードに訪れた
    visited[v] = True
    for v2 in range(n):
        if graph[v][v2] == False:  # そもそもvとv2が辺でつながっていない
            continue
        if visited[v2] == True:  # もう見た
            continue
        dfs(v2)

a, b = MI()
if a <= 5:
    print(0)
elif 6 <= a <= 12:
    print(b//2)
else:
    print(b)



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

using namespace std;

int main(void) {
    int N, T;
    cin >> N >> T;
    vector<int64_t> t(N);
    for(int i=0; i<N; i++) {
        cin >> t[i];
    }

    int64_t ans = T;
    for(int i=1; i<N; i++) {
        if(t[i] > t[i-1] + T) {
            ans += T;
        } else {
            ans += t[i] - t[i-1];
        }
    }

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


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




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



int n, m;
string s;
int a[maxn];
int b[maxn];
ll dp[maxn][maxn];//# ways to fill first i elems, holding j 1's



void add(ll& x, ll y) {
    x %= mod;
    y %= mod;
    x += y;
    x %= mod;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>n>>m;
    cin>>s;
    for (int i=0; i<n; i++) {
	a[i]=(s[i]-'0');
	b[i]=i+1;
    }

    for (int i=0; i<m; i++) {
	int l,r; cin>>l>>r;
	--l; --r;
	b[l]=max(b[l],r+1);
    }

    for (int i=1; i<n; i++) {
	b[i]=max(b[i],b[i-1]);
    }

    dp[0][0]=1;
    for (int i=0, j=0; i<n; i++) {
	int ones = 0;
	while (j<b[i]) ones+=a[j++];

	for (int x=0; x<=n; x++) {
	    if (dp[i][x] == 0) continue;
	    int cur=x+ones;

	    //put 1 at ith index
	    if (cur!=0) {
		add(dp[i+1][cur-1], dp[i][x]);
	    }

	    // put 0 at ith index
	    if (j-i != cur) {
		add(dp[i+1][cur], dp[i][x]);
	    }
	}
    }

    ll ans = dp[n][0];
    ans %= mod;
    ans += mod;
    ans %= mod;
    cout<<ans<<endl;
  

    return 0;
}


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

bool vis[101] = {};
int ans;
vector<int> v[101];

void dfs(int x, int l){
    vis[x] = true;
    ans = max(ans, l);
    for(int j : v[x]){
        if(!vis[j]) dfs(j, l+1);
    }
    vis[x] = false;
}

int main(){
    int n;
    while(cin >> n, n){
        for(int i = 1; i <= 100; i++)   v[i].clear();
        for(int i = 1; i <= n; i++){
            int a, b;
            cin >> a >> b;
            v[a].push_back(b);
            v[b].push_back(a);
        }
        ans = 0;
        for(int i = 1; i <= 100; i++){
            dfs(i, 1);
        }
        cout << ans << endl;
    }
    return 0;
}


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

int getop(char []);
void push(double);
double pop(void);

int main()
{
  char s[100];
  int t;
  double op;

  while((t = getop(s)) != EOF && t < 100) {
    switch (t) {
    case '0':
      push(atof(s));
      break;

    case '+':
      push(pop() + pop());
      break;

    case '*':
      push(pop() * pop());
      break;

    case '-':
      op = pop();
      push(pop() - op);
      break;

    case '\n':
      printf("%.8g\n", pop());
      break;

    default:
      printf("error: unknown command %s\n", s);
      break;
    }
  }
  return 0;
}

double V[100];
int sp = 0;

void push(double f)
{
  if (sp < 100)
    V[sp++] = f;
  else
    printf("error: stack full %g\n", f);
}

double pop(void)
{
  if (sp > 0)
    return V[--sp];
  else {
    printf("error: stack empty\n");
    return 0.0;
  }
}

#include <ctype.h>

int getch(void);
void ungetch(int);

int getop(char s[])
{
  int i;
  int a;

  while ((s[0]= a = getch()) == ' ' || a == '\t')

  s[1] = '\0';
  if (!isdigit(a) && a != '.')
    return a;

  i = 0;
  if (isdigit(a))
    while (isdigit(s[++i] = a = getch()))

  if (a == '.')
    while (isdigit(s[++i] = a = getch()))

  s[i] = '\0';
  if (a != EOF)
    ungetch(a);

  return '0';
}

char buf[100];
int bp = 0;

int getch(void)
{
  return (bp > 0) ? buf[--bp] : getchar();
}

void ungetch(int a)
{
  if (bp >= 100)
    printf("ungetch: too many characters\n");
  else
    buf[bp++] = a;
}


Measured memory_bytes: 2144
main :: IO ()
main = interact (unlines . filter (/="") . map (myShow . calc) . takeWhile (\[_,op,_] -> op /= "?") . map words . lines)

calc :: [String] -> Maybe Int
calc [a, "+", b] = Just (read a + read b)
calc [a, "-", b] = Just (read a - read b)
calc [a, "*", b] = Just (read a * read b)
calc [a, "/", b] = Just (read a `div` read b)
calc _ = Nothing

myShow :: Maybe Int -> String
myShow Nothing = ""
myShow (Just d) = show d

Measured memory_bytes: 3988
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  string S;cin >> S;
  S[3]='8';
  rep(i,S.length()) cout << S[i];
  cout << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int c,q,w;
    int r=0;
 cin>>c>>q>>w;
     if(q==c&&c!=w || w==c&&c!=q || q==w&&w!=c)
  cout<<"Yes" ;
else
  cout<<"No";
         
    return 0 ; 
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
  int n;
  while(cin>>n,n){
    vector<int>in1(n);
    vector<int>in2(n);
    int count=0;
    rep(i,n)cin>>in1[i];
    while(1){
      count++;
      bool h=true;
      rep(i,in1.size()){
	int co=0;
	rep(j,in1.size()){
	  if(in1[j]==in1[i])co++;
	}
	in2[i]=co;
	//cout<<co<<endl;
	if(in1[i]!=co)h=false;
      }
      if(h)break;
      //
      count++;
      h=true;
      rep(i,in2.size()){
	int co=0;
	rep(j,in2.size()){
	  if(in2[j]==in2[i])co++;
	}
	in1[i]=co;
	if(in2[i]!=co)h=false;
      }
      if(h)break;
    }
    cout<<count-1<<endl;
    cout<<in1[0];
    rep(i,in1.size()-1)cout<<" "<<in1[i+1];
    cout<<endl;
  }
}


  /*
  while(cin>>n,n){
    int co=0;
    vector< vector<int> >in(n);
    rep(i,n)cin>>in[0][i];
    do{
      vector<int>n;
      vector<int>num;
      rep(i,in[co].size()){
	bool han=false;
	int a;
	rep(j,n.size())if(num[j]==in[co][i]){a=j;han=true;}
	if(han){
	  n[a]++;
	}else{
	  n.push_back(in[co][a]);
	  num.push_back(1);
	}
      }
      rep(i,in[co].size()){
	rep(i,num.size())if(in[co][i]==num[
	in[co+1][i]=


      bool han1=false;
      
    }while();*/

Measured memory_bytes: 1192
#include<iostream>

using namespace std;

int main(){
  int L, Gain[12], Consume[12], i, saving, month;
  while(cin >> L, L){
    for(i=0; i<12; i++){
      cin >> Gain[i] >> Consume[i];
    }
    saving = 0;
    month = 0;
    for(i=0; i<12; i++){
      if(saving < L){
	month += 1;
      }
      saving += Gain[i] - Consume[i];
    }
    if(month<=12 && saving >= L){
      cout << month << endl;
    }else{
      cout << "NA" << endl;
    }
  }
}

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

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

    double a,b,c,d,e,f;
    cin >> a >> b >> c >> d >> e >> f;
    set<double> water;
    set<double> sugar;

    for(int i = 0 ;; i++){
        if(i * a >= f) break;
        for(int j = 0 ;; j++){
            double sum = a * i * 100 + b * j * 100;
            if(sum >= f) break;
            water.insert(sum);
        }
    }

    for(int i = 0;; i++){
        if(i * c >= f) break;
        for(int j = 0;; j++){
            double sum = i * c + j * d;
            if(sum >= f) break;
            sugar.insert(sum);
        }
    }

    double ratio = 0;
    double ansWater = 0, ansSugar = 0;
    for(auto k : water){
        for(auto l : sugar){
            double res = (100 * l) / (k + l);
            if(k + l > f) continue;
            if(res > (100 * e) / (100 + e)) continue;

            if(res >= ratio) {
                ratio = res;
                ansWater = k + l;
                ansSugar = l;
            }
        }
    }

    cout << ansWater << " " << ansSugar << endl;
}



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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int K;
    Scd(K);

    vector<ll> a(K);
    Rep(i,K){
        Scll(a[i]);
    }

    ll mna = 2;
    ll mxa = 3;

    if( a[K-1] != 2 ) printf ("%d\n", -1 );
    else{
        Rep(i,K-1){
            int j = K-2-i;

            mna = a[j] * ( ( mna - 1 ) / a[j] + 1 );

            if( mxa < mna ){
                printf ("%d\n", -1 );
                return 0;
            }

            mxa = a[j] * ( mxa / a[j] + 1) - 1;

            // printf ("? %llu %llu\n", mna, mxa );
        }
        printf ("%llu %llu\n", mna, mxa );
    }

    return 0;
}



Measured memory_bytes: 1152
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            string w = Console.ReadLine();
            string line;
            int count = 0;

            while ((line=Console.ReadLine()) != "END_OF_TEXT")
            {
                string[] word = line.ToLower().Split();
                foreach (string item in word)
                    if (item == w) count++;
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 15828
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<sstream>

using namespace std;

const double INF=10000000;
double l;
bool flag;
string str;
vector<double> r;
double dp[1<<12][12];

void rec(int x,int bit,double nl,double nh){
	if(dp[bit][x]<nl)return;
	dp[bit][x]=nl;
	if(bit==(1<<r.size())-1){
		if(nl+nh<=l)flag=true;
		return;
	}
	else{
		for(int i=0;i<r.size();i++){
			if(!(bit>>i & 1)){
				double nnh=r[i];
				double nnl=nl+sqrt(pow(nh+nnh,2)-pow(fabs(nh-nnh),2));
				if(nnl<dp[bit | 1<<i][i]){
					dp[bit | 1<<i][i]=nnl;
					rec(i,bit | 1<<i,nnl,nnh);
				}
			}
		}
	}
}


int main(void){
	while(getline(cin,str)){
		flag=false;
		r.clear();
		for(int i=0;i<(1<<12);i++){
			for(int j=0;j<12;j++){
				dp[i][j]=INF;
			}
		}
		stringstream input(str);
		input >> l;
		double a;
		while(input >> a)r.push_back(a);
		for(int i=0;i<r.size();i++){
			rec(i,1<<i,r[i],r[i]);
		}
		if(flag)cout << "OK" << endl;
		else cout << "NA" << endl;
	}
    return 0;
}

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

const int INF = 1000000000;
int main()
{
    std::vector<std::vector<int>> a(3,vector<int>(3));
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++)cin >> a[i][j];
    }
    int n; cin >> n;
    for(int i = 0; i < n; i++){
        int t; cin >> t;
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                if(a[j][k] == t)a[j][k] = -1;
            }
        }
    }
    bool res = false;
    for(int i = 0; i < 3; i++)if(a[i][0] == -1 && a[i][1] == -1 && a[i][2] == -1)res = true;
    for(int i = 0; i < 3; i++)if(a[0][i] == -1 && a[1][i] == -1 && a[2][i] == -1)res = true;
    if(a[0][0] == -1 && a[1][1] == -1 && a[2][2] == -1)res = true;
    if(a[0][2] == -1 && a[1][1] == -1 && a[2][0] == -1)res = true;
    cout << (res ? "Yes" : "No") << endl;

}

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

int main(){
    char s[10];
    cin >> s;

    sort(s, s+4, greater<char>() );

    if(s[0] == s[1] && s[1] != s[2] && s[2] == s[3]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}



Measured memory_bytes: 256
MAX = 10**9 + 7
_, K = map(int, input().split())
a = list(map(int, input().split()))
s = [sum([b > c for c in a]) for b in a]
r = [sum([b > c for c in a[i:]]) for i, b in enumerate(a)]
b = sum(s)*(K-1)*K//2%MAX
print((b+sum(r)*K)%MAX)


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

bool func(vector<int> v){
    int maxp=0;
    for (int i=0; i<v.size(); i++) {
        if(i*10<=maxp){
            maxp=max(maxp,v[i]+i*10);
        }
    }
    return 10*(v.size()-1)<=maxp;
}

int main(){
    int n;
    cin>>n;
    vector<int>d,u;
    for (int i=0; i<n; i++) {
        int x;
        cin>>x;
        d.push_back(x);
    }
    u=d;
    reverse(u.begin(), u.end());
    
    cout<<(func(d)&&func(u)?"yes":"no")<<endl;
}


Measured memory_bytes: 7568