akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
# Your code here!
trout_num = int(input())
height_list = [int(i) for i in input().split(" ")]
if trout_num == 1:
    print("Yes")
else:
    for i in range(0, trout_num - 1):
        heig_dif = height_list[i + 1] - height_list[i]
        if heig_dif != 0:
            if heig_dif >= 1:
                height_list[i + 1] -= 1
            else:
                print("No")
                break
    else:
        print("Yes")


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

int main(){
    int n,t[21],x;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> x;
        t[i] = x;
    }
    for(int i=0;i<n;i++){
        cin >> x;
        t[i] -= x;
    }
    x=0;
    for(int i=0;i<n;i++){
        if(t[i]>0)
            x += t[i];
    }
    cout << x;
}

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

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

		if (N == 0) break;

		int OK = 0;
		int NO = 0;

		for (int i = 0; i < N; i++) {
			int k;
			cin >> k;

			if (k == 1)
				NO++;
			else if (k > 1)
				OK++;
		}

		if (OK == 0)
			cout << "NA" << endl;
		else
			cout << OK+NO + 1 << endl;
	 }
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) (a).begin(),(a).end()

using ll = long long;
constexpr ll INF = 1000000000;

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

using namespace std;

//fixed << setprecision(10)

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

int main() {
	string s,t; cin >> s >> t;

	cout << t << s << endl;
}



Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int N;
    cin >> N;
    int ans = 0;
    for (int i=1; i*i<=N; i++){
        chmax(ans,i*i);
    }
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;

int main(){
        ll a, b;
        char op;
        cin>>a>>op>>b;
        if(op=='+'){
                cout<<a+b<<endl;
        }
        else{
                cout<<a-b<<endl;
        }
        return 0;
}


Measured memory_bytes: 256
//Volume0-0053
import java.util.Scanner;
 
public class Main {
 
	//declare
	private static final int        PRM_MAX   = 104730,
	                                PRM_NUM   =  10001;
	private static       boolean [] prm_table = new boolean[PRM_MAX];
	private static       int     [] prm_sum   = new int    [PRM_NUM];

    public static void main(String[] args) {
    	
    	//initialize
    	init();
    	
    	//input
    	int n;
    	Scanner sc = new Scanner(System.in);
    	while((n = sc.nextInt()) != 0){
    		
    		//output
    		System.out.println(prm_sum[n]);
    	}
    }
    
    private static void init(){
    	
    	//A prime number table is created.
    	prm_table[2] = true;
    	for(int i=3;i<PRM_MAX;i+=2){prm_table[i] = true;}
    	for(int i=3;i<PRM_MAX;i+=2){
    		if(prm_table[i]){
    			for(int j=i*2;j<PRM_MAX;j+=i){
    				prm_table[j] = false;
    			}
    		}
    	}
    	
    	//The table of the sum of a prime number is created.
    	for(int i=2,j=1;i<PRM_MAX;i++){
    		if(prm_table[i]){
    			prm_sum[j] = i + prm_sum[j-1];
    			j++;
    		}
    	}
    }
}

Measured memory_bytes: 20000
#include<bits/stdc++.h>
using namespace std;
#define LL long long


int main()
{
    int te=10,c,r;
    LL a,b;
    cin>>a>>b;
    if(a+b>=10)
    cout<<"error\n";
    else
    cout<<(a+b)<<"\n";
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Linq.Enumerable;
using static System.Math;

class Program
{
    static void Main()
    {
        var (A, B, C, D) = Range(0, 4).Select(i => int.Parse(ReadLine())).ToArray();

        var ans = Min(A, B) + Min(C, D);

        WriteLine(ans);
    }
}

static class ArrayDeconstructExtensions
{
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2) => (i1, i2) = (a[0], a[1]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3) => (i1, i2, i3) = (a[0], a[1], a[2]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4) => (i1, i2, i3, i4) = (a[0], a[1], a[2], a[3]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4, out T i5) => (i1, i2, i3, i4, i5) = (a[0], a[1], a[2], a[3], a[4]);
}


Measured memory_bytes: 28052
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int table[2020];


int main(){

	for(int i = 0; i <= 2018; i++){

		table[i] = 0;
	}

	ll L,R;
	scanf("%lld %lld",&L,&R);

	vector<ll> V;
	for(ll i = L; i <= R; i++){
		if(table[i%2019] == 3)break;
		table[i%2019]++;
		V.push_back(i);
	}

	ll ans = 2019;

	for(int i = 0; i < V.size()-1; i++){
		for(int k = i+1; k < V.size(); k++){

			ans = min(ans,(V[i]*V[k])%2019);
		}
	}

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

	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,n) 				for(int i=0; i<(n); ++i)
#define all(c) 					(c).begin(),(c).end()
#define sortall(x)              sort(all(x))
#define tr(c,i) 				for( typeof( (c).begin() ) i = (c).begin();  i != (c).end(); ++i)
#define pb 						push_back
#define sz(a) 					int((a).size())
#define mp                      make_pair
#define ll                      long long
#define F                       first
#define S                       second
#define PI                      3.1415926535897932384626
// Input macros
#define s(n)                    scanf("%d",&n)
#define sc(n)                   scanf("%c",&n)
#define sl(n)                   scanf("%lld",&n)
#define sf(n)                   scanf("%lf",&n)
#define ss(n)                   scanf("%s",n)

// Others
#define test(t) 				int t; cin>>t; while(t--)
#define endl 					"\n"

using namespace std;

typedef pair<int, int> 			pii;
typedef pair<ll, ll> 	          pll;
typedef vector<int> 			vi;
typedef vector<ll>                 vl;

const int mod = 1000000007;
const ll INF = 1e18L+5;

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

     ll n, W;
     sl(n);
     sl(W);
     
     // here we require to change the approach 
     // instead of taking the mamx value for a weight i
     // think of min weight for a given value
     
	 vector<ll> w(n), v(n);
	 
	 ll max_value = 0;
	 for(ll i=0; i<n; i++){
			sl(w[i]); sl(v[i]);
			max_value += v[i];
	 }
	 
	 vector<ll> dp(max_value+1, INF);
	 
	 dp[0] = 0;
	 
	 
	 for( ll item=0 ; item<n; ++item ){
		 for( ll value_so_far = max_value-v[item] ; value_so_far>=0 ; --value_so_far ){
			 dp[value_so_far + v[item]] = min( dp[value_so_far + v[item]], dp[value_so_far] + w[item] );
		 }
	 }
	 
	 ll answer = 0;
	 for(ll i=max_value ; i>=0 ; --i ){
		 if(dp[i] <= W){
			 answer = i; 
			 break;
		 }
	 } 
	 
	 printf("%lld\n",answer);			 

     return 0;
}
	







Measured memory_bytes: 4052
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    ll s;
    cin>>s;
    ll a,b;
    if(s<1000000000){
        cout<<"0 0 "<<s<<" 0 1000000000 1"<<endl;
    }
    else if(s<1000000000000000000){
        b = s/1000000000+1;
        a = b*1000000000-s;
        cout<<"0 0 "<<a<<" "<<b<<" 1000000000 1"<<endl;
    }
    else{
        cout<<"0 0 1000000000 0 0 1000000000"<<endl;
    }
    // else{
    //     cout<<"0 0 1000000000 0 1 1"
    // }


    return 0;
}


Measured memory_bytes: 256
N=int(input())
a=5
b=2
cnt_a=0
cnt_b=0
while a<N:
    cnt_a+=(N//a)//2
    a*=5
while b<N:
    cnt_b+=(N//b)//2
    b*=2
print(0 if N%2==1 else min(cnt_a,cnt_b))

Measured memory_bytes: 3060
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

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

		int n = scan.nextInt();
		int[] S = new int[n];
		for (int i = 0; i < n; i++) {
			S[i] = scan.nextInt();
		}

		int q = scan.nextInt();
		int[] T = new int[q];
		for (int i = 0; i < q; i++) {
			T[i] = scan.nextInt();
		}

		Set<Integer> C = new HashSet<Integer>();


		for (int i = 0; i < q; i++) {
			int head = 0;
			int tail = n - 1;

			while(head <= tail) {
				int center = (head + tail) / 2;
				if(S[center] == T[i]){
					C.add(i);
					break;
				} else if (S[center] < T[i]) {
					head = center + 1;
				} else {
					tail = center - 1;
				}
			}
		}

		Integer[] afterC = C.toArray(new Integer[0]);
		System.out.println(afterC.length);

		scan.close();
	}

}



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

struct Node{
  int key;
  Node *p, *l, *r;
};

Node *root, *NIL;

void insert(int k){
  Node *y=NIL;
  Node *x=root;
  Node *z;
 
  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->l = NIL;
  z->r = NIL;
  while(x != NIL) {
    y = x;
    if(z->key < x->key) {
      x = x->l;
    }else{
      x = x->r;
    }
  }
 
  z->p = y;
  if(y == NIL) {
    root = z;
  }else{
    if(z->key < y->key){
      y->l = z;
    }else{
      y->r = z;
    }
  }
}

void inorder(Node *k){
  if(k == NIL){
    return;
  }
  inorder(k->l);
  cout << " " << k->key;
  inorder(k->r);
}

void preorder(Node *k){
  if(k == NIL){
    return;
  }
  cout << " " << k->key;
  preorder(k->l);
  preorder(k->r);
}

int main(){
  int n,k;
  string s;

  cin >> n;

  for(int i = 0 ; i < n ; i++){
    cin >> s;
    if(s == "insert"){
      cin >> k;
      insert(k);
    }else if(s == "print"){
      inorder(root);
      cout << endl;
      preorder(root);
      cout << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 24648
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
const int man = 4e3+10;
#define IOS ios::sync_with_stdio(0)
template <typename T>
inline T read(){T sum=0,fl=1;int ch=getchar();
for(;!isdigit(ch);ch=getchar())if(ch=='-')fl=-1;
for(;isdigit(ch);ch=getchar())sum=sum*10+ch-'0';
return sum*fl;}
template <typename T>
inline void write(T x) {static int sta[35];int top=0;
do{sta[top++]= x % 10, x /= 10;}while(x);
while (top) putchar(sta[--top] + 48);}
template<typename T>T gcd(T a, T b) {return b==0?a:gcd(b, a%b);}
template<typename T>T exgcd(T a,T b,T &g,T &x,T &y){if(!b){g = a,x = 1,y = 0;}
else {exgcd(b,a%b,g,y,x);y -= x*(a/b);}}
#ifndef ONLINE_JUDGE
#define debug(fmt, ...) {printf("debug ");printf(fmt,##__VA_ARGS__);puts("");}
#else
#define debug(fmt, ...)
#endif
typedef long long ll;
const ll mod = 1e9+7;
char str[man];
int pre1[man],pre2[man],pre3[man];
int hed1[man],hed2[man],hed3[man];

int main() {
	#ifndef ONLINE_JUDGE
		//freopen("in.txt", "r", stdin);
		//freopen("out.txt","w",stdout);
	#endif
	int n;
	cin >> n;
	cin >> str + 1;
	for(int i = 1;i <= n;i++){
		if(str[i]=='R')pre1[i] = 1;
		else if(str[i]=='G')pre2[i] = 1;
		else pre3[i] = 1;
		pre1[i] += pre1[i-1];
		pre2[i] += pre2[i-1];
		pre3[i] += pre3[i-1];
	}
	ll sum = 0;
	for(int i = 1;i <= n;i++){
		int qr = 0,qg = 0,qb = 0,hr = 0,hb = 0,hg = 0;
		ll ans = 0;
		qr = pre1[i-1];
		qg = pre2[i-1];
		qb = pre3[i-1];
		hr = pre1[n] - pre1[i];
		hg = pre2[n] - pre2[i];
		hb = pre3[n] - pre3[i];
		if(str[i]=='R'){
			ans += 1ll*qg*hb;
			ans += 1ll*hg*qb;
			int tp = 1;
			while(i-tp>=1&&i+tp<=n){
				if(str[i-tp]!='R'&&str[i+tp]!='R'&&str[i+tp]!=str[i-tp])ans--;
				tp++;
			}
		}else if(str[i]=='G'){
			ans += 1ll*qr*hb;
			ans += 1ll*hr*qb;
			int tp = 1;
			while(i-tp>=1&&i+tp<=n){
				if(str[i-tp]!='G'&&str[i+tp]!='G'&&str[i+tp]!=str[i-tp])ans--;
				tp++;
			}
		}else{
			ans += 1ll*qg*hr;
			ans += 1ll*hg*qr;
			int tp = 1;
			while(i-tp>=1&&i+tp<=n){
				if(str[i-tp]!='B'&&str[i+tp]!='B'&&str[i+tp]!=str[i-tp])ans--;
				tp++;
			}
		}
		sum += ans;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3664
#include <iostream>
#include <vector>
#define INF (1 << 28)

using namespace std;

int main(void) {
	int N,M;
	cin >> N >> M;
	vector<int> c(M),d(N);
	for (int i = 0; i < N; ++i) {
		cin >> d[i];
	}
	for (int i = 0; i < M; ++i) {
		cin >> c[i];
	}

	vector< vector<long long> > dp(M+1,vector<long long>(N+1,INF));
	dp[0][0] = 0;
	for (int j = 0; j < M; ++j) {
		for (int i = 0; i < N; ++i) {
			if (dp[j][i] != INF) {
				dp[j+1][i] = min(dp[j+1][i],dp[j][i]);
				dp[j+1][i+1] = min(dp[j+1][i+1],dp[j][i]+(c[j]*d[i]));
			}
		}
	}

	long long res = INF;
	for (int i = 0; i < M+1; ++i) {
		res = min(res,dp[i][N]);
	}
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 9136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

struct Edge {
  ll to, cost;
  Edge(ll to, ll cost) : to(to), cost(cost) {}
};

vector<vector<Edge>> g;

const ll INF = 1e18;
vector<bool> isCycle;
vector<ll> bellman_ford(vector<vector<Edge>>& graph, ll s) {
  ll n = SZ(graph);
  vector<ll> dist(n, INF);
  dist[s] = 0;
  REP(i, n) {
    REP(v, n) {
      if (dist[v] == INF) {
        continue;
      }
      REP(k, SZ(graph[v])) {
        Edge e = graph[v][k];
        ll tmp = dist[v] + e.cost;
        if (dist[e.to] <= tmp) {
          continue;
        }
        dist[e.to] = tmp;
        if (i == n - 1) {
          isCycle[v] = true;
        }
      }
    }
  }
  return dist;
}

bool seen[1010];
ll n, m;

bool dfs(ll cv, ll dst) {
  if (cv == dst) {
    return true;
  }
  bool res = false;
  for (Edge e : g[cv]) {
    ll to = e.to;
    if (seen[to]) {
      continue;
    }
    seen[to] = true;
    res |= dfs(to, dst);
  }

  return res;
}

bool canReach(ll s, ll t) {
  REP(i, n) { seen[i] = false; }
  return dfs(s, t);
}

int main() {
  cin >> n >> m;
  g = vector<vector<Edge>>(n);
  isCycle = vector<bool>(n, false);
  REP(i, m) {
    ll a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    g[a].push_back(Edge(b, -c));
  }
  vector<ll> dist = bellman_ford(g, 0);
  REP(i, n) {
    if (isCycle[i] && canReach(0, i) && canReach(i, n - 1)) {
      cout << "inf"
           << "\n";
      return 0;
    }
  }
  cout << -dist[n - 1] << "\n";
}


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

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

    int n, k;
    cin >> n;
    string s;
    cin >> s;
    cin >> k;

    string ans = "";
    for(int i = 0; i < n; i++){
        if(s[k - 1] != s[i]){
            ans += '*';
        }else{
            ans += s[i];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
/***
coded by adarsh
***/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
typedef long double ld;
typedef vector<ll> vec; 
typedef vector<vector<ll>> vec2;
typedef pair<ll,ll> pair1;
typedef pair<string,ll> pair2;
typedef pair<ll,string> pair3;
typedef pair<string,string> pair4;
#define fl(i,a,b) for(i=a;i<b;i++)
#define rfl(i,a,b) for(i=b-1;i>=a;i--)
#define f first
#define s second

int factorial(int n) 
{ 
    // single line to find factorial 
    return (n==1 || n==0) ? 1: n * factorial(n - 1);  
} 

int main() 
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll i,n,j;cin>>n;
    int a[n],b[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    fl(i,0,n) cin>>b[i];
    ll c=0;
    for(i=0;i<n;i++)
    {
        for(j=i;j<n;j++)
        {
            if(a[i]>a[j])
            c++;
        }
        a[i]=c;c=0;
    }
    for(i=0;i<n;i++)
    {
        for(j=i;j<n;j++)
        {
            if(b[i]>b[j])
            c++;
        }
        b[i]=c;c=0;
    }
    ll sum1=0,sum2=0;
    for(i=0;i<n-1;i++)
    {
        sum1+=a[i]*factorial(n-i-1);
        sum2+=b[i]*factorial(n-i-1);
    }
    cout<<abs(sum1-sum2);
    return 0;
}


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

#define ll long long int
#define pi pair<ll,ll>

const int N = 1e6+3;

void solve(){
    ll n,a,b;
    cin >> n >> a >> b;
    if((b-a)%2==0)
        cout << (b-a+1)/2 << '\n';
    else{
        // cout << min(b-1,n-a) << '\n';
        ll left = (a-1+1) + (b-(a+1)-1+1)/2;
        ll right = (n-b+1) + ((n-a)-(n-b+1)+1)/2;
        cout << min(left,right) << '\n';
        // cout << left << ' ' << right << '\n';
    } 
}

int main(){
    int test=1;
    // cin >> test;
    while(test--)
        solve();

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<ll, ll> p;

#define MOD 1000000007

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

    int N;
    cin >> N;

    int a = N / 1000;

    if(N % 1000 == 0) {
        cout << 0 << endl;
        return 0;
    }

    a++;

    cout << 1000 * a - N << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,a,b) for (int i = (a); i < (b); i++ )
typedef pair<int,int> P;
typedef long long ll;
const int INF = 100000000;

int main() {
    int N,M;
    cin >> N >> M;
    if (M==N) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>

int linearSearch(int S[],int n,int key){
  int i=0;
  S[n] = key;
  while(S[i] != key)i++;
  return i != n;
}

int main(){
  int i,n,S[10000+1],q,key,C=0;
  scanf("%d",&n);
  for(i = 0;i < n;i++)scanf("%d",&S[i]);

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&key);
    if(linearSearch(S,n,key))C++;
  }
  printf("%d\n",C);
  return 0;
}



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

int main(){

    vector<int> a;
    int tmp;

    while (1)
    {
        cin >> tmp;
        if (tmp==0) break;
        else a.push_back(tmp);
    }
    

    for (int i = 0; i < a.size(); i++)
    {
        printf("Case %d: %d\n",i+1,a[i]);
    }
    

    

}




Measured memory_bytes: 3212
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
using namespace std;

int main() {
  int input, height, i, j;
  int n, m;
  int turns_left, turns_right;
  int position, d;

  while (true){
    cin >> n;
    cin >> m;

    if (n == 0 && m == 0) { break; }

    vector<int> cups(15);

    // input
    for (i = 0; i < 3; i++) {
      cin >> height;
      for (j = 0; j < height; j++) {
        cin >> input;
        cups.at(input - 1) = i;
      }
    }

    // left
    position = 0;
    turns_left = 0;
    for (i = 0; i < n; i++) {
      d = position - cups.at(i);
      if (d == 0) {
      } else if (d == 1 || d == -1) {
        turns_left += static_cast<int>(pow(3, (n - 1) - i));
        if (position == 0) {
          position = 2;
        } else if (position == 2) {
          position = 0;
        }
      } else if (d == 2 || d == -2) {
        turns_left += 2 * static_cast<int>(pow(3, (n - 1) - i));
      }
    }

    // right
    position = 2;
    turns_right = 0;
    for (i = 0; i < n; i++) {
      d = position - cups.at(i);
      if (d == 0) {
      } else if (d == 1 || d == -1) {
        turns_right += static_cast<int>(pow(3, (n - 1) - i));
        if (position == 0) {
          position = 2;
        } else if (position == 2) {
          position = 0;
        }
      } else if (d == 2 || d == -2) {
        turns_right += 2 * static_cast<int>(pow(3, (n - 1) - i));
      }
    }

    cout << (min(turns_left, turns_right) <= m ? min(turns_left, turns_right) : -1) << endl;

    cups.clear();
  }

  return 0;
}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const double EPS = 1e-10;

int main() {

    int N, W;
    cin >> N >> W;
    vector<lint> w(N), v(N);
    rep(i, N) cin >> v[i] >> w[i];

    const int MAX_J = 100000;
    vector<vector<lint>> mi(N + 1, vector<lint>(MAX_J, LINF));
    mi[0][0] = 0;
    rep(i, N) rep(j, MAX_J) {
        if (mi[i][j] == LINF) continue;

        mi[i + 1][j] = min(mi[i + 1][j], mi[i][j] + 0);
        if (j + v[i] <= MAX_J)
            mi[i + 1][j + v[i]] = min(mi[i + 1][j + v[i]], mi[i][j] + w[i]);
    }

    lint ans = -1;
    for (int j = 0; j < 100000; j++) {
        if (mi[N][j] <= W) ans = max((lint)j, ans);
    }
    cout << ans << endl;
    // ddump(mi);
    return 0;
}


Measured memory_bytes: 82884
#include <bits/stdc++.h>
#define ALL(x) (x).begin(),(x).end()
#define PB push_back
#define MP make_pair
#define Mod 998244353
#define MOD 1000000007
using namespace std;
using lint = long long;
using vi = vector<lint>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<lint, lint>;

// cout << fixed << setprecision(12)

lint modpow(lint a, lint n, lint m = MOD){
  lint ans = 1;
  while(n>0){
    if(n%2==1) ans *= a; 
    ans %= m;
    a *= a; 
    a %= m;
    n /= 2;
  }
  return ans;
}

lint inv(lint a, lint m = MOD){
  return modpow(a, m-2, m);
}

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

int main(){
  lint N; cin>>N;
  lint ans = modpow(10,N);
  
  ans -= modpow(9,N);
  if(ans<0) ans = ans + MOD;
  ans %= MOD;
  
  ans -= modpow(9,N);
  if(ans<0) ans = ans + MOD;
  ans %= MOD;
  
  ans += modpow(8,N);
  ans %= MOD;
  
  cout << ans << endl;
}
  


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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,a,b;
    cin >> n >> a >> b;
    ll tmp = n/(a+b);
    cout << a * tmp + min(n % (a+b),a) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>
#include <iterator>


#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;


int dp[101][100010], cum[101][100010];
int a[100010];
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	dp[0][0] = 1;
	int N, K; cin >> N >> K;
	REP(i, N) {
		cin >> a[i];
		cum[i][1] = 1;
		dp[i][0] = 1;
	}
	dp[N][0] = 1;
	REP(i, K+1) {
		cum[0][i + 1] = 1;
	}
	FOR(i, 1, N + 1) {
		//REP(j, K + 1)pe(cum[i - 1][j]); cout << endl;
		FOR(j, 1, K + 1) {
			int r = j+1;
			int l = j - min(j,a[i-1]);
			dp[i][j] = cum[i - 1][r] - cum[i - 1][l]+MOD;
			dp[i][j] %= MOD;
			//cum[i][j] += dp[i][j]; cum[i][j] %= MOD;
			//printf("%lld %lld: %lld\n",i, j, dp[i][j]);
		}
		REP(j, K+1) {
			cum[i][j + 1] = cum[i][j] + dp[i][j];
			cum[i][j + 1] %= MOD;
		}
		
	}
	print(dp[N][K] % MOD);
}


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

int main(void)
{
	char str[200];
	int l, r, con, len, flag;
	
	con = 0;
	while (scanf("%s", &str) != EOF){
		len = strlen(str);
		flag = 0;
		for (l = 0, r = len - 1; l <= len - 1; l++, r--){
		//	printf("%d %d\n", l, r);
			if (str[l] != str[r]){
				flag = 1;
		//		puts("N");
				break;
			}
		}
		
		if (flag != 1){
			con++;
		//	puts("Y");
		}
		
	}
	
	printf("%d\n", con);
	
	return (0);
}

Measured memory_bytes: 540
#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K, C = map(int, readline().split())
S = read().rstrip().decode()


def compute(S):
    dp = [0] * N
    for i, x in enumerate(S):
        if i <= C:
            dp[i] = 1
        else:
            if x == 'x':
                dp[i] = dp[i - 1]
            else:
                dp[i] = dp[i - C - 1] + 1
        if dp[i - 1] > dp[i]:
            dp[i] = dp[i - 1]
    return dp


dp1 = compute(S)
dp2 = compute(S[::-1])[::-1]


def get_answers():
    for i in range(N):
        before = dp1[i - 1] if i else 0
        after = dp2[i + 1] if i < N - 1 else 0
        if before + after < K:
            yield i + 1


for x in get_answers():
    print(x)


Measured memory_bytes: 20772
#include<bits/stdc++.h>
using namespace std;
int n,x,a[110],b[110];
int main(){
    cin>>x>>n;
    for (int i=0;i<n;i++) cin>>a[i];
    for (int i=0;i<n;i++) b[a[i]]=1;
    for (int i=0;i<=n;i++){
        if (b[x-i]==0){
            cout<<x-i<<endl;
            return 0;
        }
        if (b[x+i]==0){
            cout<<x+i<<endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int c,o,bisa;
int main () {
	cin >>c;
	
for (int s=1; s<=9;s++){
	for (int d=1; d<=9;d++) {
		if (d*s==c){
			bisa=1;
		}
	}
}
if (bisa==1){
	cout << "Yes"<<endl;
}else {
	cout << "No" << endl;
}
}

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

int main()
{
	int X, Y;

	while( cin >> X >> Y && ( X || Y ) ){
		vector< vector< int > > map( Y + 1, vector< int >( X + 2, 0 ) );
		vector< vector< int > > memo = map;
		for( int i = 1; i < Y + 1; ++i ){
			for( int j = 1; j < X + 1; ++j ){
				cin >> map[ i ][ j ];
			}
		}
		for( int i = 1; i < X + 1; ++i ){
			if( map[ 1 ][ i ] == 0 ){
				memo[ 1 ][ i ] = 1;
			}
		}
		for( int i = 2; i < Y + 1; ++i ){
			for( int j = 1; j < X + 1; ++j ){
				if( map[ i ][ j ] == 1 ) continue;
				if( map[ i ][ j ] == 2 ){
					if( map[ i - 1 ][ j ] == 0 ){
						memo[ i ][ j ] = memo[ i - 1 ][ j ];
					}
				}else{
					for( int k = -1; k < 2; ++k ){
						if( map[ i - 1 ][ j + k ] == 0 ){
							memo[ i ][ j ] += memo[ i - 1 ][ j + k ];
						}
					}
				}
				if( map[ i - 2 ][ j ] == 2 ){
					memo[ i ][ j ] += memo[  i - 2 ][ j ];
				}
			}
		}
		int ans = 0;
		for( int i = 1; i < X + 1; ++i ){
			ans += memo[ Y ][ i ];
			if( map[ Y - 1 ][ i ] == 2 ){
				ans += memo[ Y - 1 ][ i ];
			}
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1224
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<cstring>
#include<sstream>
using namespace std;

typedef long long ll;

int main() {
  int N; cin >> N;
  vector<int>A(N+1);
  vector<ll>sum(N+1);
  sum[0] = 0;
  for ( int i = 1; i <= N; i++ ) cin >> A[i];

  for ( int i = 1; i <= N; i++ ) {
    sum[i] = sum[i-1]+A[i];
  }
  
  sort(sum.begin(),sum.end());
  sum.push_back(1e18);
  ll cnt = 1;
  ll ans = 0;
  for ( int i = 1; i < sum.size(); i++ ) {
    if ( sum[i] == sum[i-1] ) cnt++;
    else {
      ans += cnt*(cnt-1)/2;
      cnt = 1;
    }
  }

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


Measured memory_bytes: 5632
using System;

namespace atcoder1
{
    class problem2
    {
        public static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int N, X;
            N = int.Parse(input[0]);
            X = int.Parse(input[1]);

            string[] L = Console.ReadLine().Split(' ');
            int[] l = new int[L.Length];
            for (int i = 0; i < L.Length; i++)
            {
                l[i] = int.Parse(L[i]);
            }

            int d = 0;
            int counter = 0;
            for (int i = 0; i < N+1; i++)
            {
                if (i > 0)
                {
                    d = d + l[i-1];
                }
                if (d > X)
                {
                    break;
                }
                else
                {
                    counter = i;
                }
            }
            Console.WriteLine(counter+1);
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <list>
#include <iterator>
#include <map>

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define FORCLS(i,a,b) for(int i = (a); i <= (b); i++)
#define REPCLS(i,n) FORCLS(i,1,n)

#define NMAX (200005)
vector<int> edges[2][NMAX];
const int DORO = 0;
const int TETU = 1;
int n;
int kl[2];
//vector<vector<int>> connects[2];
int tosiConnectID[2][NMAX];

void dfs(int dorT){
    vector<int>* eg = edges[dorT];
    //vector<vector<int>>& con = connects[dorT];
    int* tosiID = tosiConnectID[dorT];
    bool visited[NMAX]; fill(visited, visited + n, false);
    int id = 0;
    //con.resize(n);
    REP(i, n){
        if (visited[i]) continue;
        queue<int> q;
        q.push(i);
        while(!q.empty()){
            int j = q.front(); q.pop();
            if (visited[j]) continue;
            visited[j] = true;
            //con[id].push_back(j);
            tosiID[j] = id;
            for(int k : eg[j]){
                if (visited[k]) continue;
                q.push(k);
            }
        }
        id++;
    }
    
}
void solve() {
    cin >> n >> kl[DORO] >> kl[TETU];
    REP(i, 2){
        REP(j, kl[i]){
            int a,b;
            cin >> a >> b;
            a--; b--;
            edges[i][a].push_back(b);
            edges[i][b].push_back(a);
        }
    }
    dfs(DORO);
    dfs(TETU);
    using INT = size_t;
    INT cnts[NMAX]; fill(cnts, cnts + n, -1);
    
//    REP(i,2) for(auto& t : connects[i]){
//        sort(begin(t), end(t));
//    }
//    REP(i, n){
//        if (cnts[i] != -1) continue;
//        vector<int>& a = connects[DORO][tosiConnectID[DORO][i]];
//        vector<int>& b = connects[TETU][tosiConnectID[TETU][i]];
//        vector<int> aAndb;
//        set_intersection(begin(a), end(a), begin(b), end(b), back_inserter(aAndb));
//        INT cnt = aAndb.size();
//        for(int j : aAndb){
//            cnts[j] = cnt;
//        }
//    }

    map<pair<int,int>, INT> tosi2Cnts;
    REP(i, n) {
        tosi2Cnts[make_pair(tosiConnectID[DORO][i], tosiConnectID[TETU][i])]++;
    }
    
    REP(i, n){
        cout << tosi2Cnts[make_pair(tosiConnectID[DORO][i], tosiConnectID[TETU][i])];
        if (i == n -1) cout << endl;
        else cout << " ";
    }
}

#ifdef DEBUG
#define MAIN hoge
#else
#define MAIN main
#endif

int MAIN() {
    solve();
    
    return 0;
}

Measured memory_bytes: 29712
#include "bits/stdc++.h"
using namespace std;

struct Solver {
	Solver() {
		ios::sync_with_stdio( false );
	}

	void solve() {
		int N, K;
		string S;
		cin >> N >> S >> K;

		for( int i = 0; i < N; ++i ) {
			if( S[i] == S[K-1] ) {
				cout << S[i];
			}
			else {
				cout << '*';
			}
		}

		cout << endl;
	}
};

int main() {
	Solver().solve();
	return 0;
}


Measured memory_bytes: 256
N = int(input())
T = list(map(int, input().split()))
M = int(input())
P, X = [], []
for i in range(M):
    p, x = map(int, input().split())
    P.append(p)
    X.append(x)

total_time = sum(T)
abs_diff = 0
for i in range(M):
    index = P[i] - 1
    tmp_diff = X[i] - T[index]
    print(total_time + tmp_diff)

Measured memory_bytes: 38256
#include<stdio.h>
void swap(int *x, int *y){
	int temp = *x;
	*x = *y;
	*y = temp;
}

void sort(int *a, int *b){
	if(*a>*b)
	swap(a,b);
}

int main(void){
	int num[3];
	scanf("%d %d %d",&num[0],&num[1],&num[2]);
	for(int i=0;i<3;i++){
		for(int j=(i+1);j<3;j++){
			sort(&num[i],&num[j]);
		}
	}
	printf("%d %d %d\n",num[0],num[1],num[2]);
	
	return 0;
}


Measured memory_bytes: 2088
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const int INF=1<<17;


int main(){
    int N;
    cin >> N;
    int maxi=0,mini=INF;
    map<int,int> mp;
    for(int i=0;i<N;i++){
        int x;
        cin >> x;
        mp[x]++;
        maxi=max(maxi,x);
        mini=min(mini,x);
    }
    if(maxi-mini>1) puts("No");
    else if(maxi-mini==1){
        if(mp[mini]>mini) puts("No");
        else if(mini-mp[mini]<mp[maxi]/2) puts("Yes");
        else puts("No");
    }
    else{
        if(maxi==N-1) puts("Yes");
        else if(1<=maxi&&maxi<=N/2) puts("Yes");
        else puts("No");
    }
    return 0;
}

Measured memory_bytes: 4992
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		int k = scan.nextInt();
		long[] a = new long[n+1];
		long[] b = new long[m+1];
		
		a[0] = 0;
		for(int i=1;i<=n;i++) {
			a[i] = scan.nextLong()+a[i-1];
		}
		
		b[0] = 0;
		for(int i=1;i<=m;i++) {
			b[i] = scan.nextLong()+b[i-1];
		}
		
		int max = 0;
		int j = m;
		for(int i=0;i<=n;i++) {
			if(a[i] > k) {
				break;
			}
			while(j >= 0 && k < a[i]+b[j]) {
				j--;
			}
			max = Math.max(i+j, max);
		}
		System.out.println(max);

	}

}

Measured memory_bytes: 62920
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
----
-- A
local S, T = read.l():split()
local A, B = read.nnl()
local U = read.l()
if U == S then
    A = A - 1
else
    B = B - 1
end
print(A .. " " .. B)

Measured memory_bytes: 760
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

    L=list(map(int,input().split()))
    prod=L[0]*L[1]*L[2]
    ans=10**20
    for i in L:
        if i%2==0:
            ans= 0
            break
        else:
            ans=min(ans,prod//i)
    print(ans)


resolve()

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

int main() {
  int N,sum,X;
   X=10000000000;
  cin >> N;

  vector<int> A(N);
 
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end()); 
for (int i = A.at(0); i <= A.at(N-1); i++) {
  for(int j=0;j<N;j++){sum+=((i-A.at(j))*(i-A.at(j)));
                                       
                   }
    X=min(X,sum);
  sum=0;}
cout<<X<<endl;
 
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define per(a,b,c) for(int a=b;a>=c;a--)
#define ios; ios::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define ls(x) (x<<1)
#define rs(x) (ls(x)|1)
#define eps 1e-11
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef double db;
mt19937 rnd(random_device{}());
const int mod = 1e9 + 7;
const int N = 1e6 + 5;
const int M = 1e3 + 5;
inline ll gcd(ll a,ll b){ return b?gcd(b,a%b):a; }
inline ll lcm(ll a,ll b){ return a*b/gcd(a,b); }
inline ll ksm(ll x,ll y){ ll res=1; while(y){if(y&1) res=res*x%mod;
x=x*x%mod; y>>=1;} return res; }
int n, m, k;
int a[N], b[4];

bool ok(int i,int j,int k){
    b[1]=a[i], b[2]=a[j], b[3]=a[k];
    if(b[1]==b[2]||b[1]==b[3]||b[2]==b[3]) return 0;
    sort(b+1,b+4);
    if(b[1]+b[2]>b[3]) return 1;
    return 0;
}

int main(){
    scanf("%d",&n);
    rep(i,1,n) scanf("%d",&a[i]);
    int ans=0;
    rep(i,1,n) rep(j,i+1,n) rep(k,j+1,n){
        if(ok(i,j,k)) ++ans;
    }
    printf("%d\n",ans);
    return 0;
}
/*

*/
//
//                            _ooOoo_
//                           o8888888o
//                           88" . "88
//                           (| -_- |)
//                           O\  =  /O
//                        ____/`---'\____
//                      .'  \|     |//  `.
//                     /  \|||  :  |||//  \
//                    /  _||||| -:- |||||-  \
//                    |   | \  -  /// |   |
//                    | \_|  ''\---/''  |   |
//                    \  .-\__  `-`  ___/-. /
//                  ___`. .'  /--.--\  `. . __
//               ."" '<  `.___\_<|>_/___.'  >'"".
//              | | :  `- \`.;`\ _ /`;.`/ - ` : | |
//              \  \ `-.   \_ __\ /__ _/   .-` /  /
//         ======`-.____`-.___\_____/___.-`____.-'======
//                            `=---='
//        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//                     佛祖保佑      永无BUG


Measured memory_bytes: 3744
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	int N;
	
	cin >> N;
	vector<double> x(N), y(N), b(N), p(N),ans(N);
	for (int i = 0; i < N; i++){
		cin >> x[i] >> y[i] >> b[i] >> p[i];
	}
	for (int i = 0; i < N; i++){
		if (b[i] >= 5 && p[i] >= 2){
			ans[i] = (x[i]  *b[i] * 0.8) + (y[i] * p[i] * 0.8);
		}
		else {
			if (b[i] < 5 && p[i] < 2){
				ans[i] = min(x[i] * b[i] + y[i] * p[i], x[i]*0.8 * 5 + y[i]*0.8*2);
			}
			if (b[i] < 5 && p[i] >= 2){
				ans[i] = min(x[i] * b[i] + y[i] * p[i], x[i] * 0.8 * 5 + y[i] * 0.8 * p[i]);
			}
			if (b[i] >= 5 && p[i] < 2){
				ans[i] = min(x[i] * b[i] + y[i] * p[i], x[i] * 0.8 * b[i] + y[i] * 0.8 * 2);
			}
		}
		cout << ans[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 3296
N = int(input())
CSF = [tuple(map(int,input().split())) for _ in range(N-1)]

Ans = []
for i in range(N):
    t = 0
    for j in range(i,N-1):
        (c,s,f) = CSF[j]
        if t <= s:
            t = s+c
        else:
            t = s+((t-s-1)//f+1)*f+c
    Ans.append(t)

for ans in Ans:
    print(ans)



Measured memory_bytes: 3188
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define pye cout << "Yes" << endl;
#define pno cout << "No" << endl;
#define INF 1000000000
#define MOD 1000000007LL
#define MAX 100005
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PA;
typedef priority_queue<ll> PQ;
typedef pair<double, double> doup;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll a[200000];

int main() {
    ll a, b, i;
    string s;
    cin >> a >> b;
    cin >> s;
    for(i=0; i<a; i++) {
        if(s[i]<'0' || '9'<s[i]) {
            pno;
            return 0;
        }
    }

    if(s[a]!='-') {
        pno;
        return 0;
    }
    
    for(i=a+1; i<s.size(); i++) {
        if(s[i]<'0' || '9'<s[i]) {
            pno;
            return 0;
        }
    }
    
    pye;
}


Measured memory_bytes: 256
s = input().rstrip()
N = len(s)
K = int(input())

c = []
for i in range(N):
    for j in range(i+1, N+1):
        if len(c) < K:
            c.append(s[i:j])
            c.sort()
        else:
            if s[i:j] in c:
                continue

            if c[K-1] < s[i:j]:
                break
            else:
                c[K-1] = s[i:j]
                c.sort()

print(c[-1])


Measured memory_bytes: 67904
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.run();
    }
    
    // 変数一覧
    long n;
    int[] h;
    long[] dp;

    public void run() {
        // 入力情報取得
        Scanner sc = new Scanner(System.in);
        n = sc.nextLong();
        h = new int[(int)n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        sc.close();

        // 解答処理
        solve();
    }
    
    private void solve() {
        dp();
        System.out.println(dp[(int)n-1]);
    }
    
    private void dp() {
        dp = new long[(int)n];
        dp[0] = 0;
        for (int i = 1; i < n; i++) {
            if(i>1) {
                dp[i] = Math.min(dp[i-1] + Math.abs(h[i-1] - h[i]), dp[i-2] + Math.abs(h[i-2] - h[i]));
            } else {
                dp[i] = dp[i-1] + Math.abs(h[i-1] - h[i]);
            }
        }
    }
}

Measured memory_bytes: 49820
#include <stdio.h>

int main(void){
  int R, G, B, N;
  int i=0, j=0, ans=0;
  
  scanf("%d %d %d %d",&R ,&G, &B, &N);
  
  for(i=0; i <= N/R; i++){
    for(j=0; j <= (N-R*i)/G; j++){
      if((N-R*i-G*j)%B == 0){
        ans +=1;
      }
    }
  }
  printf("%d",ans);
  return 0;
}

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

#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
#define all(v) (v).begin() , (v).end()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using pii = pair<int , int>;
using pll = pair<long long , long long>;

//プロトタイプ宣言
void faster(void);
template <class T>
T gcd(T , T);
template <class T>
T get_digent(T);
template <class T>
T POW(T , T);



int main(){
  faster();
  ll h;
  cin >> h;
  ll power = (ll)(log2(h))+1;
  ll ans = (ll) POW(2LL,power);
  cout << ans-1 ;
}



























//同期解除
void faster(void){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

//ユークリッドの互除法
template <class T>
T gcd(T a, T b) {
  return (b ? gcd(b, a%b) : a);
} 

//桁数取得
template <class T>
T get_digent(auto x){
  string s;
  s = to_string(x);
  ll digent = s.size();
  return digent;
} 

//べき乗計算
template <class T>
T POW(T x, T y){
  if(y==0) return 1;
  if(y%2 == 1){
    ll temp = POW(x,y-1);
    return (temp*x);
  }
  else{
    ll temp = POW(x,y/2);
    return temp*temp;
  }
} 



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

int main(){
    int n; cin >> n;
    vector<int>price(n);
    for(int i=0;i<n;i++){
        cin >> price.at(i);
    }
    sort(price.begin(), price.end());
    int sum=0;
    for(int i=0;i<n;i++){
        if(i<n-1) sum += price.at(i);
        else sum += price.at(i) / 2;
    }
    cout << sum << endl;
}

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

using namespace std;

const int max_n = 202222, inf = 1000111222;

int n, a[max_n];
long long ans = 1e18, sum1, sum2;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
        a[i] -= i + 1;
    }
    sort(a, a + n);
    int x = a[0];
    for (int i = 0; i < n; ++i) {
        a[i] -= x;
        sum2 += a[i];
    }
    for (int i = 0; i < n; ++i) {
        ans = min(ans, 1LL * a[i] * i - sum1 + sum2 - 1LL * a[i] * (n - i));
        sum1 += a[i];
        sum2 -= a[i];
    }
    cout << ans << "\n";
    return 0;
}


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

using namespace std;
using ll = long long;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int D[10];
int N, K;
int ok(int M) {
    while (M) {
        rep(i, K) if (D[i] == M % 10) return false;
        M /= 10;
    }
    return true;
}
int main() {
    cin >> N >> K;
    rep(i, K) cin >> D[i];
    while (!ok(N)) {
        N++;
    }
    cout << N << endl;
    return 0;
}


Measured memory_bytes: 256
N = input()
a = map(int, raw_input().split())

keys = [i for i in range(N)]


ave = 0
newa = []
for j in range(N):
    ave =  ave + a[j]
    newa.append(a[j]*N)
      
adict = dict(zip(keys, newa))
    
mat =[]
for i in range(N):
    mat.append(abs(newa[i]-ave))
    

amin = min(mat)


keys = [k for k, v in adict.items() if abs(v-ave) == amin]


print(min(keys))



Measured memory_bytes: 2692
#include <bits/stdc++.h>
 
#define ff first
#define ss second
#define mp make_pair
 
using namespace std;

typedef long long ll;

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

	bool flag = false;
	while(n) {
		if(n%10 == 7) flag = true;
		n /= 10;
	}

	printf("%s\n", (flag ? "Yes" : "No"));

	return 0;
}


Measured memory_bytes: 3620
#!/usr/bin/env python3

MOD = 10**9
def make_divisors(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)
    return divisors

N = int(input())
S = input()


ans = S.count('R') * S.count('G') * S.count('B')

SN = []

for s in S:
    if s == 'R': SN.append(-1)
    elif s == 'G': SN.append(0)
    else: SN.append(1)

rem2 = ['RRR', 'GGG', 'BBB']

count = 0
for i in range(1, N-1):
    index = i
    left = i - 1
    right = i + 1
    f = True
    while f:
        if left == -1 or right == N:
            break
        if SN[left] == SN[index] and SN[index] == SN[right] == 0 : pass
        elif SN[left] + SN[index] + SN[right] == 0 :
            count+= 1
        
        left -= 1
        right += 1

print(ans-count)


Measured memory_bytes: 9252