akhauriyash/Code-Regression huggingface dataset:
from itertools import accumulate
from sys import exit
N = int(input())
S = input()
if S == '#'*N:
    print(0)
    exit()
W = [int(s == '.') for s in S]
W = list(accumulate(W))
W += [W[-1]]
w = W[-1]
B = [int(s == '#') for s in S]
B = list(accumulate(B))
print(min(w,min(w-i+j for i, j in zip(W, B))))


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

int L[120];
int main (){
    int  N , X, D = 0, res = 0,tmp;
    cin >> N >> X;
    for(int i=0;i<N;i++) cin >> L[i];
int j=0; 
while (true){
if(D >X) break;
        D = D + L[j]; 
++res; 
if(j == N) break;
++j;
}
cout <<endl<< res;

} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long int ll;
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector<int > a(N, 0);
  REP(i, N){cin >> a[i];}
  int ans = 0;
  int tmp = 0;
  int tmp2 = 0;
  REP(i, N){
    tmp = a[i];
    tmp2 = 0;
    while(tmp%2 == 0){
      tmp /= 2;
      tmp2 ++;
    }
    ans += tmp2;
  }
  cout << ans << endl;

}


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

int main() {
  int n=0;
  cin >> n;
  
  vector<int> vec(n);
  for (int i=0; i<n; i++) {
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  int ans=1, prev=vec.at(0);
  
  for (int i=1; i<n; i++) {
    if (prev > vec.at(i)) {
      prev = vec.at(i);
      ans++;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vs = vector<string>;
using vvs = vector<vs>;
using pli = pair<long long, int>;
using vpli = vector<pli>;

int main() {
  ll N, ans = 0, i = 1, tmp_five = 0;
  cin >> N;
  
  if (N % 2 == 1) cout << 0 << endl;
  else {
    ans += (N / 10); 
    tmp_five = pow(5, i);
    while (tmp_five <= N) {
      ans += (N / (tmp_five * 10));
      i++;
      tmp_five = pow(5, i);
    }
    
    cout << ans << endl;
  }
  
}

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

int main(){
  ll n,k,sum=0;
  cin>>n>>k;
  vector<ll> h(n);
  rep(i,n){
    cin>>h[i];
  }
  sort(h.begin(),h.end());
  rep(i,k){
    h.pop_back();
  }
  ll b=n-k;
  rep(i,b){
    sum+=h[i];
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};


vi mk_bits(int bit,int n){
    vi S;
    rep(i,n){
        if(bit & (1 << i)){
            S.pb(1);
        }
        else{S.pb(0);}
    }
    return S;
}

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

	int n,m,x;
	cin >> n >> m >> x;
	vi cost(n);
	vvi r(n,vi(m));
	vi ans;
	rep(i,n){
		cin >> cost[i];
		rep(j,m){
			cin >> r[i][j];
		}
	}

	for(int bit = 0;bit < (1<<n);++bit){
		vi bits = mk_bits(bit,n); //n bitの01からなる数列
		ll tmp = 0 ; // 値段
		vi sum(m,0);	//それぞれの習熟度
		bool ok =true;
		rep(i,n){
			if(bits[i]==1){
				tmp += cost[i];
				rep(j,m){
					sum[j] += r[i][j];
				}
			}
		}
		
		rep(j,m){
			if(sum[j]<x) ok = false;
		}
		if(ok) ans.pb(tmp);
	}
	if(ans.empty()) dame;
	
	cout << minel(ans) << endl;

	return 0;
}


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

int main(){
    long long r,d,x; cin >> r>>d>>x;
    rep(i,10){
        x = r*x-d;
        cout << x << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#from random import randint
import numpy as np


def f(h,w,m,ins):
    yp = np.zeros(h,dtype=np.int32)
    xp = np.zeros(w,dtype=np.int32)
    s = set()
    for hi,wi in ins:
        s.add((hi-1,wi-1))
        yp[hi-1] += 1
        xp[wi-1] += 1
    ypm = yp.max()
    xpm = xp.max()
    yps = np.where(yp == ypm)[0].tolist()
    xps = np.where(xp == xpm)[0].tolist()
    ans = yp[yps[0]]+xp[xps[0]]
    for ypsi in yps:
        for xpsi in xps:
            if not (ypsi,xpsi) in s:
                return ans
    return ans-1

if __name__ == "__main__":
    if False:
        while True:
            h,w = randint(1,10**5*3),randint(10**5,10**5*3)
            m = randint(1,min(h*w,10**5*3))
            ins = [(randint(1,h),randint(1,w)) for i in range(m)]
            ans = f(h,w,m,ins)
            print(ans)
    else:
        h,w,m = map(int,input().split())
        ans = f(h,w,m,[list(map(int,input().split())) for i in range(m)])
        print(ans)


Measured memory_bytes: 156420
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pii pair<int,int>
#define pll pair<long long, long long>
#define rep(i,l,r) for(int i = l;i<r;i++)

#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()

#define fastout  ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
using namespace __gnu_pbds;

typedef tree<pll,null_type,less<pll>,rb_tree_tag,tree_order_statistics_node_update> order_set;

const int INF = (int)1e9 + 7;
const long long LLINF = (long long)1e18 + 7;

int main() {
    int n;
    cin >> n;
    vector<int> ans;
    while (n != 0 && n != 1) {
        //out << n << endl;
        if (n < 0) {
            if ((-n) % 2 == 0)
                ans.push_back(0);
            else {
                ans.push_back(1);
            }
            if ((-n) % 2 == 0) {
                n = n / (-2);
            }
            else{
                n = (n / (-2))+ 1;
            }
        }
        else {
            if ((n) % 2 == 0)
                ans.push_back(0);
            else {
                ans.push_back(1);
            }
            n = -(n / 2);
        }
    }
    ans.push_back(n);
    for (auto it = ans.rbegin(); it != ans.rend(); it++) {
        cout << *it;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public Main(){
		Scanner sc = new Scanner(System.in);
		String[] str = ((sc.nextLine()).replace(",", "").replace(".", "")).split(" ");
		int flag = 0;
		for(String s: str){
			int l = s.length();
			if(l >= 3 && l <= 6){
				if(flag == 1){
					System.out.print(" ");
				}
					System.out.print(s);
				flag = 1;
			}
		}
		
		System.out.println();
	}
	
	public static void main(String[] args){
		Main test = new Main();
	}
}

Measured memory_bytes: 12000
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
//素因数分解O(√n)
map<ll,ll>prime_factor(ll n){
  map<ll,ll>res;
  for(ll i=2;i*i<=n;i++){
    while(n%i==0){
      res[i]++;
      n/=i;
    }
  }
  if(n!=1)res[n]=1;
  return res;
}
int main(){
  ll n,p;cin>>n>>p;
  ll ans=1;
  map<ll,ll>M=prime_factor(p);
  for(auto p:M){
    ans*=pow(p.first,p.second/n);
  }
  cout<<ans<<endl;
}
  
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)

int main()
{
    int N;
    cin >> N;
    int abc[N+10][3];
    ll dp[N+10][3];
    rep(i,N)
    {
        cin >> abc[i][0] >> abc[i][1] >> abc[i][2];
        rep(j,3)
        {
            dp[i][j] = 0;
        }
    }
    rep(i,3) dp[0][i] = abc[0][i];

    rep(i,N-1)
    {
        dp[i+1][0] = max(dp[i][1], dp[i][2]) + abc[i+1][0];
        dp[i+1][1] = max(dp[i][2], dp[i][0]) + abc[i+1][1];
        dp[i+1][2] = max(dp[i][0], dp[i][1]) + abc[i+1][2];
    }
    ll ans = max(dp[N-1][0], max(dp[N-1][1], dp[N-1][2]));
    
    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll from;
	ll to;
	ll cost;
};
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define RES(a, n) (a).resize(n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 2.0 * asin(1.0);
const ll INF = 1L<<60;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = (ll)pow(10,7);
/****** define constant end ********/
/****** define variable start ******/
ll n;
vector<string> s;
/******* define variable end *******/
int solve() {
	cin >> n;
	ll ac = 0, wa = 0, tle = 0, re = 0;
	RES(s, n);
	REP(i, n){
		cin >> s[i];
		if(s[i] == "AC") ac++;
		else if(s[i] =="WA") wa++;
		else if(s[i] == "TLE") tle++;
		else if(s[i] =="RE") re++;
	}
	cout << "AC x " << ac << endl;
	cout << "WA x " << wa << endl;
	cout << "TLE x " << tle << endl;
	cout << "RE x " << re << endl;
	return 0;
}

int main() {
	//clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


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

long long n, a, m=1, e=1e18, fl;
int main() {
	cin >> n;
	while(n--) {
		cin >> a;
		if(a <= e/m) m *= a;
		else fl = 1;
		if(m==0) break;
	}
	if(m==0) cout << 0;
	else if(fl) cout << -1;
	else cout << m;
	return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <chrono>

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define pii pair<ll,pi >
#define ppi pair<pi,ll>
#define ppp pair<pi,pi >
#define ex(str,a,b) str.substr((int)(a),min((int)str.size()-a,(int)(b-a+1))) 
#define all(X) X.begin(),X.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   __builtin_popcount(n) : no. of set bits in n.
*/

const int M = (1<<20)+5;
const int md = 1e9+7;

priority_queue<pi,vector<pi >,greater<pi > > pq;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

ll ax[M],ay[M];
set<pii > px,py,nx,ny;
bool mrk[M];

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

	ll n,i,x,y,d,cost = 0;

	cin >> n;
	for(i=1;i<=n;++i)
	{
		cin >> x >> y;
		px.insert(pii(x,pi(y,i)));
		nx.insert(pii(-1*x,pi(y,i)));
		py.insert(pii(y,pi(x,i)));
		ny.insert(pii(-1*y,pi(x,i)));
		ax[i] = x;
		ay[i] = y;
	}

	pq.push(pi(0,1));

	while(!pq.empty())
	{
		pi ed = pq.top();
		pq.pop();
		d = ed.ff;
		i = ed.ss;
		if(mrk[i])
			continue;
		mrk[i] = 1;
		cost += d;
		px.erase(pii(ax[i],pi(ay[i],i)));
		nx.erase(pii(-1*ax[i],pi(ay[i],i)));
		py.erase(pii(ay[i],pi(ax[i],i)));
		ny.erase(pii(-1*ay[i],pi(ax[i],i)));

		auto gx = px.upper_bound(pii(ax[i],pi(-1,-1)));
		if(gx != px.end())
			pq.push(pi(min(abs((*gx).ff-ax[i]),abs((*gx).ss.ff-ay[i])),(*gx).ss.ss));
		gx = nx.upper_bound(pii(-1*ax[i],pi(-1,-1)));
		if(gx != nx.end())
			pq.push(pi(min(abs(-1*((*gx).ff)-ax[i]),abs((*gx).ss.ff-ay[i])),(*gx).ss.ss));
		gx = py.upper_bound(pii(ay[i],pi(-1,-1)));
		if(gx != py.end())
			pq.push(pi(min(abs((*gx).ff-ay[i]),abs((*gx).ss.ff-ax[i])),(*gx).ss.ss));
		gx = ny.upper_bound(pii(-1*ay[i],pi(-1,-1)));
		if(gx != ny.end())
			pq.push(pi(min(abs((*gx).ss.ff-ax[i]),abs(-1*((*gx).ff)-ay[i])),(*gx).ss.ss));
	}

	cout << cost << "\n";
}

Measured memory_bytes: 34124
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<functional>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    string s;
    cin>>s;
    rep(i,s.size()){
        if(i%2==0) cout<<s[i];
    }cout<<endl;
    return 0;
}

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

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<"\n"


int main(){
    int n;
    cin >> n;
    COUT(n*800-(n/15)*200);
    return 0;
}

Measured memory_bytes: 256
'''
1の位が2,4,5,7,9のとき'hon'
1の位が0,1,6,8のとき'pon'
1の位が3のとき'bon'
を出力する．
'''

def kazoekata_enpitsu(N):
    if(N%10==3):
        print('bon')
    elif(N%10==0 or N%10==1 or N%10==6 or N%10==8):
        print('pon')
    else:
        print('hon')

N = int(input())
kazoekata_enpitsu(N)

Measured memory_bytes: 9108
object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    
    def printRect(h:Int, w:Int):Unit = {
      if(w==0&&h==0){}
      else {
        for( i <- 1 to h) {
          println("#"*w)
        }
        println
        printRect(sc.nextInt,sc.nextInt)
      }
    }

    printRect(sc.nextInt,sc.nextInt)

  }
}

Measured memory_bytes: 46240
#include<bits/stdc++.h>
using namespace std;
int l[10],a[10],b[10],c[10],A,B,C,la,lb,lc,n,bb[10];
int worka()
{
	if (la==0) return A;
	int dd=2e8;
	for (int i=0;i<(1<<la);i++)
	{
		int ss=0,cnt=0;
		for (int j=0;j<la;j++)
			if ((i>>j)&1) ss+=a[j],cnt++;
		if (cnt>=1) dd=min(dd,abs(ss-A)+(cnt-1)*10); //else dd=min(dd,abs(ss-A));
	}
	return dd;
}

int workb()
{
	if (lb==0) return B;
	int dd=2e8;
	for (int i=0;i<(1<<lb);i++)
	{
		int ss=0,cnt=0;
		for (int j=0;j<lb;j++)
			if ((i>>j)&1) ss+=b[j],cnt++;
		//printf("ss=%d ans=%d\n",ss,abs(ss-B)+(cnt-1)*10);
		if (cnt>=1) dd=min(dd,abs(ss-B)+(cnt-1)*10); //else dd=min(dd,abs(ss-B));
	}
	return dd;
}

int workc()
{
	if (lc==0) return C;
	int dd=2e8;
	for (int i=0;i<(1<<lc);i++)
	{
		int ss=0,cnt=0;
		for (int j=0;j<lc;j++)
			if ((i>>j)&1) ss+=c[j],cnt++;
		if (cnt>=1) dd=min(dd,abs(ss-C)+(cnt-1)*10); //else dd=min(dd,abs(ss-C));
	}
	return dd;
}

int main()
{
	scanf("%d%d%d%d",&n,&A,&B,&C);
	int mi=2e9;
	for (int i=0;i<n;i++) scanf("%d",&l[i]);
	bb[0]=1;
	for (int i=1;i<=n;i++) bb[i]=bb[i-1]*3;
	//printf("%d\n",bb[0]);
	for (int i=0;i<=bb[n];i++)
	{
		la=lb=lc=0;
		for (int j=0;j<n;j++) 
		{
			if ((i/bb[j])%3==0) a[la++]=l[j];
			if ((i/bb[j])%3==1) b[lb++]=l[j];
			if ((i/bb[j])%3==2) c[lc++]=l[j];
		}
		if (la==0 || lb==0 || lc==0) continue;
		int sum=worka()+workb()+workc();
		if (mi>sum) mi=sum;
	}
	printf("%d\n",mi);
	return 0;
}

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

int main() {
    ll n, k;
    cin >> n >> k;
    ll p[n], c[n];
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
        p[i]--;
    }
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
    }

    ll ans = -1e18;
    for (int st = 0; st < n; ++st) {
        int running = p[st];
        ll cycscore = c[running], cyclen = 1;
        while(running != st) {
            running = p[running];
            cycscore += c[running];
            cyclen++;
        }

        ll runningscore = 0;
        for(int r = 1; r <= n; r++) {
            running = p[running];
            runningscore += c[running];
            if(r <= k) {
                ans = max(ans, runningscore);
                if(cycscore > 0) ans = max(ans, runningscore + (k - r) / cyclen * cycscore);
            }
        }
    }
    cout << ans << endl;
}


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

long long oddsolve(long long a) { return (a+1)/2 % 2; }
long long solve(long long a) {
    if (a % 2 == 1) return oddsolve(a);
    else return oddsolve(a+1) ^ (a+1);
}

int main() {
    long long A, B; cin >> A >> B;
    cout << (solve(B) ^ solve(A-1)) << endl;
}

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

int n;
ll ara[100000 + 5];

ll check(ll k) {
    for(int i = 0; i < n; i++)
        k -= k % ara[i];
    return k;
}

int main() {
    cin >> n;
    for(int i = 0; i < n; i++) 
        cin >> ara[i];
    ll lo = 0, hi = 100000000000000, ans = -1;
    while(lo <= hi) {
        ll mid = (lo + hi) / 2;
        ll k = check(mid);
        if(k == 2) {
            ans = mid;
            hi = mid - 1;
        }
        else if(k > 2)
            hi = mid - 1;
        else
            lo = mid + 1;
    }
    
    if(ans != -1)
        cout << ans << " ";
    else {
        cout << -1 << endl;
        return 0;
    }
    
    lo = 0, hi = 100000000000000, ans = -1;
    while(lo <= hi) {
        ll mid = (lo + hi) / 2;
        ll k = check(mid);
        if(k == 2) {
            ans = mid;
            lo = mid + 1;
        }
        else if(k > 2)
            hi = mid - 1;
        else
            lo = mid + 1;
    }
    
    if(ans != -1)
        cout << ans << endl;
    else {
        cout << -1 << endl;
        return 0;
    }
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  char c;
  cin >> c;
  cout << (char)(c + 1);
  return 0;
}


Measured memory_bytes: 3552
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let a=read::<i32>();
    let b=read::<i32>();
    let c=read::<i32>();
    println!("{}",if a==5&&b==5&&c==7||a==5&&b==7&&c==5||a==7&&b==5&&c==5{"YES"}else{"NO"})
}

Measured memory_bytes: 4352
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    Int N, K;
    vector<Int> A, B;

    Int calc(Int n) {
        if (n < 0) {
            Int mask = K;

            Int ret = 0;
            for (int i = 0; i < N; ++i) {
                if ((mask | A[i]) == mask) {
                    ret += B[i];
                }
            }
            return ret;
        }

        if (!(K >> n & 1)) {
            Int ret = 0;
            for (int i = 0; i < N; ++i) {
                if (A[i] == 0) {
                    ret += B[i];
                }
            }
            return ret;
        }

        Int mask = ((K >> (n + 1)) << 1);
        for (int i = 0; i < n; ++i) {
            mask <<= 1;
            mask++;
        }

        Int ret = 0;
        for (int i = 0; i < N; ++i) {
            if ((mask | A[i]) == mask) {
                ret += B[i];
            }
        }
        return ret;
    }

    void solve() {
        cin >> N >> K;
        A.resize(N);
        B.resize(N);
        for (int i = 0; i < N; ++i) {
            cin >> A[i] >> B[i];
        }

        Int ans = 0;
        for (int i = -1; i <= 30; ++i) {
            chmax(ans, calc(i));
        }

        cout << ans << endl;

    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 2424
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int ans = 0,tt = n;
	while(n != 0){
		ans += n % 10;
		n /= 10;
	}
	if(tt % ans == 0)printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL K, N; cin >> N >> K;
		vector<double> P(N);
		rep(i, N) cin >> P[i];
		rep(i, N - 1) P[i + 1] += P[i];
		for (UL i = N - 1; i >= K; i--) P[i] -= P[i - K];
		double ans = 0;
		rep(i, N) ans = max(ans, P[i]);
		cout << ((ans + K) / 2) << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int n,a[100],b[100],c[100];
void solve(){
	cin>>n;
	for(int i=1;i<=n;++i)
		cin>>a[i];
	for(int i=1;i<=n;++i)
		cin>>b[i];
	for(int i=1;i<n;++i)
		cin>>c[i];
	int ans=0;
	for(int i=1,ls=0;i<=n;++i){
		ans+=b[a[i]];
		if(ls&&ls==a[i]-1)
			ans+=c[a[i]-1];
		ls=a[i];
	}
	cout<<ans<<endl;
}
int main(){
	solve();
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	int a,b,s;
	cin>>s>>a>>b;
	for(int i=1;i<=b;i++)
	{
		if(i*s>=a&&i*s<=b)
		{
			cout<<"OK";
			return 0;
		}
		if(i*s>b)  break;
	}
	cout<<"NG";
    return 0;
}

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

const int N = 100050;
int n,arr[N][4];
int dp[N][4];

int rec(int pos,int p)
{
    if(pos==n+1) return 0;
    int &ret=dp[pos][p];
    if(ret!=-1) return ret;
    ret=0;
    for(int i=1; i<=3; i++)
    {
        if(p==i) continue;
        ret=max(ret,arr[pos][i]+rec(pos+1,i));
    }
    return ret;
}

int main()
{
    memset(dp,-1,sizeof dp);
    scanf("%d",&n);
    for(int i=1; i<=n; i++) scanf("%d %d %d",&arr[i][1],&arr[i][2],&arr[i][3]);
    printf("%d\n",rec(1,0));

}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
//関数
const long INF=1000000000000000;

int main(void){
    long N,D;
    cin>>N>>D;
    
    vector<vector<long>> X(N,vector<long>(D));
    for(int i=0;i<N;i++){
        for(int j=0;j<D;j++){
            cin>>X.at(i).at(j);
        }
    }
    
    long ans=0;
    
    for(int i=1;i<N;i++){
        for(int j=0;j<i;j++){
            long distance=0;
            for(int k=0;k<D;k++){
                distance+=(X.at(i).at(k)-X.at(j).at(k))*(X.at(i).at(k)-X.at(j).at(k));
            }
            
            long root=0;
            while(root*root<distance) root++;
            
            if(root*root==distance) ans++;
        }
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<(n);i++)
#define P pair<int,int>
#define mod 1000000007
#define S second
#define F first
#define int long long
using namespace std;
int x[500],y[500];
signed main(){
	int a,b,c,ans=0;
	cin>>a>>b;
	for(int i=0;i<a;i++){
		if(i==0) x[i]=a;
		else x[i]=x[i-1]+a-i*2;
	}
	for(int i=0;i<b;i++){
		if(i==0) y[i]=b;
		else y[i]=y[i-1]+b-i*2;
	}
	f(i,a){
		f(j,b){
			cin>>c;
			ans+=c*x[i]*y[j];
		}
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
long long int n;
int main(){
    cin>>n;
    for(int i=sqrt(n);i>=1;i--){
        if(n%i==0){
            int t=i,l=n/i;
            int s=1;
            while(l>=10){
                s++;
                l/=10;
            }
        cout<<s;
        return 0;
        }
    }
    return 0;
}

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

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }
        public void Solve(ConsoleInput cin)
        {
            var _s = cin.Read;
            var S = _s.ToCharArray();
            for(int i = 0; i < S.Length; i++)
            {
                if(i % 2 == 0)
                {
                    Write(S[i]);
                }
            }
            WriteLine("");
        }
        
        /*public long C(long n, long r)
        {
            if (r == 0 || r == n) return 1L;
            if (n < r) return 0L;
            long[,] Pascal = new long[n + 1, n + 1];
            Pascal[0, 0] = 1;
            for (long i = 1; i <= n; i++)
            {
                Pascal[i, 0] = 1;
                Pascal[i, i] = 1;
                for (long j = 1; j < n; j++)
                {
                    Pascal[i, j] = Pascal[i - 1, j] + Pascal[i - 1, j - 1];
                }
            }
            return Pascal[n, r];
        }*/

        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
#define MAX 999999999

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

typedef long long ll;

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

    int n;
    cin >> n;

    int cnt_max = -1, max_i = 0;
    repi(i, 1, n+1){
        int cnt = 0, tmp = i;
        while(tmp % 2 == 0){
            tmp /= 2;
            cnt ++;
        }

        if(cnt > cnt_max){
            cnt_max = cnt;
            max_i = i;
        }
    }

    cout << max_i << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>
#include <cstdlib>
#include <numeric>
#include <queue>
#include <complex>
#include <sstream>
#include <stack>

using namespace std;

#define reep(i, f, n) for (int i = f; i < n; ++i)
#define rep(i, n) reep(i, 0, n)

int main()
{
    int qa = 200;
    int qb = 300;
    int qc = 500;
    int pa = 380;
    int pb = 550;
    int pc = 850;
    int ua = 5;
    int ub = 4;
    int uc = 3;
    int ra = 20;
    int rb = 15;
    int rc = 12;

    int n;
    int tmp;
    while (scanf("%d", &n),n)
    {
        int ret = 10000;
        rep(i, n / qa + 1)
            rep(j, n / qb + 1)
                rep(k, n / qc + 1)
                    if (i * qa + j * qb + k * qc == n)
                    {
                        tmp = i * pa + j * pb + k * pc;
                        tmp -= ((i / ua) * ua * pa * ra) / 100;
                        tmp -= ((j / ub) * ub * pb * rb) / 100;
                        tmp -= ((k / uc) * uc * pc * rc) / 100;
                        ret = min(ret, tmp);
                    }
        printf("%d\n", ret);
    }
    return 0;
}


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

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

    std::string s;
    std::unordered_map<std::string, int> m;
    int max = 1;
    for (int i = 0; i < N; ++i) {
        std::cin >> s;
        if (m.count(s) == 0) {
            m[s] = 1;
        } else {
            m[s] = m[s] + 1;
            max = std::max(max, m[s]);
        }
    }

    std::vector<std::string> strs;
    strs.reserve(N);
    for (const auto& p : m) {
        if (p.second == max) {
            strs.push_back(p.first);
        }
    }

    std::sort(strs.begin(), strs.end());

    for (const std::string& s : strs) {
        std::cout << s << std::endl;
    }

    return 0;
}


Measured memory_bytes: 25672
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);    
    int N; cin >> N;
    
    int M; cin >> M;
    
    ll P; cin >> P;
    vector<vpl > graph(N);
    vector<vi > graph2(N);
    F0R(i, M) {
		int A, B, C; cin >> A >> B >> C; A--; B--; C-=P;
		graph[A].pb(mp(B, C)); 
		graph2[B].pb(A);
	}
	
	bool foundEnd[N]; F0R(i, N) foundEnd[i] = false;
	queue<int> q;
	q.push(N-1);
	foundEnd[N-1] = true;
	while (!q.empty()) {
		int cur = q.front(); q.pop();
		F0R(i, sz(graph2[cur])) {
			int nxt = graph2[cur][i];
			if (!foundEnd[nxt]) {
				foundEnd[nxt] = true;
				q.push(nxt);
			}
		}
	}
	
	ll dist[N];
	F0R(i, N) {
		dist[i] = -1000000000000;
	}
	dist[0] = 0;
	
	bool found[N]; F0R(i, N) found[i] = false;
	
	found[0] = true;
	
	F0R(i, N) {
		F0R(j, N) {
			if (dist[j] == -1000000000000) continue;
			F0R(k, sz(graph[j])) {
				int nxt = graph[j][k].f;
				found[nxt] = true;
				if (dist[nxt] < dist[j] + graph[j][k].s) {
					dist[nxt] = dist[j]+graph[j][k].s;
				}
			
			}
		}
	}
	
	/*F0R(i, N) {
		cout << dist[i] << " ";
	} cout << endl;*/
	
	F0R(i, N) {
		F0R(j, sz(graph[i])) {
		
			int k = graph[i][j].f;
			if (dist[k] == -1000000000000 || dist[i] == -1000000000000) continue;
			if (dist[k] < dist[i] + graph[i][j].s && foundEnd[k]) {
				cout << -1 << endl; return 0;
			}
		}
	}
	
	cout << max(0LL, dist[N-1]) << endl;
	
    return 0;
}

// read the question correctly (ll vs int)
// template by bqi343


Measured memory_bytes: 768
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.PriorityQueue;
import java.util.StringTokenizer;


//Main
public class  Main{
	




	public static void main(String[] args) throws IOException {
		
		
		FastScanner sc=new FastScanner();
		String str = sc.next();
		int sum = 0;
		for(char e : str.toCharArray()) {
			sum+=(e-'0');
		}
		if(sum%9 == 0)
			System.out.println("Yes");
		else
			System.out.println("No");
		
		
	}
	
	
	
	
 
	static void sort(int[] a) {
		ArrayList<Integer> l=new ArrayList<>();
		for (int i:a) l.add(i);
		Collections.sort(l);
		for (int i=0; i<a.length; i++) a[i]=l.get(i);
	}
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long[] readArrayLong(int n) {
        	long[] a=new long[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
        }
		long nextLong() {
			return Long.parseLong(next());
		}
		String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
	}
}


Measured memory_bytes: 36484
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,y;
    cin>>x>>y;
    int a,b,flag=0;
    
     b=x-a;
     for(int a=0;a<=x;a++)
     {
     if ((2 * a) + (4 * (x-a)) == y)
        flag=1;
     }
     
     if(flag==1)
     {
        cout<<"Yes"<<"\n";
     }
     else
     {
         cout<<"No"<<"\n";
     }
    return 0;
}


Measured memory_bytes: 3592
#include <map>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

//abbreviations
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>
#define vb vector<bool>
#define vvi vector<vector<int>>

using namespace std;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    int A, B;
    cin >> A >> B;
    if(A<=B){
        rep(i, B) cout << A;
    }else{
        rep(i,A) cout << B;
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n, x, y;
    std::cin >> n >> x >> y;

    std::vector<std::vector<int>> g(n);
    std::vector<int> ret(n);

    for (int i = 1; i < n; i++) {
        g[i].push_back(i - 1);
        g[i - 1].push_back(i);
    }

    --x; --y;
    g[x].push_back(y);
    g[y].push_back(x);

    for (int i = 0; i < n; i++) {
        std::deque<int> q { i };
        std::vector<int> d(n, -1);
        d[i] = 0;
        while (!q.empty()) {
            const int v = q.front();
            q.pop_front();
            for (const int to : g[v]) {
                if (d[to] < 0) {
                    d[to] = d[v] + 1;
                    q.push_back(to);
                }
            }
        }
        for (int v = 0; v < i; v++) ret[d[v]]++;
    }

    for (int i = 1; i < n; i++) std::cout << ret[i] << '\n';

    return 0;
}


Measured memory_bytes: 384
n, k, s = map(int, input().split())
 
ans = []
for i in range(k):
  ans.append(s)
if s != 10**9:
  for j in range(n-k):
    ans.append(s+1)
else:
  for j in range(n-k):
    ans.append(1)
 
print(*ans)

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<62;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

int myrand(){
	static random_device rd;
	static mt19937 eng(rd());
	return eng();
}

double pw,vw[100000],pf[100000],vf[100000],th[100000];

void solve(int n){
    scanf("%lf",&pw);
    rep(i,0,n) scanf("%lf%lf%lf%lf",vw+i,pf+i,vf+i,th+i);

    vector<double> v={0};
    rep(i,0,n) if(vw[i]!=0 and th[i]/vw[i]>=0) v.push_back(th[i]/vw[i]);

    double ans=inf;
    for(double w:v){
        double d=w*pw;
        rep(i,0,n){
            if(d>=ans) break;
            d+=pf[i]*max(0.,(th[i]-w*vw[i])/vf[i]);
        }
        ans=min(ans,d);
    }
    printf("%f\n",ans);
}

int main(){
    while(true){
        int n;
        scanf("%d",&n);
        if(!n) break;
        solve(n);
    }
    return 0;
}

Measured memory_bytes: 7892
from sys import stdin

def main():

    input = stdin.readline

    X,K,D = map(int,input().split())

    X = abs(X)

    sho = X // D
    if sho >= K:
        ans = abs(X - D * K)
    elif (K - sho) % 2 == 0:
        ans = abs(X % D)
    else:
        ans = abs(abs(X % D) - D)

    print(ans)

if __name__ == "__main__":
    main()

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	string s;
	cin >> s;
	vi l, r;
	REP(i, s.size()) {
		if (s[i] == '<')l.push_back(i);
		else r.push_back(i);
	}
	vi lcntl(n), lcntr(n), rcntl(n), rcntr(n);
	REP(i, n) {
		if (s[i] == '<') {
			lcntl[i]++;
			rcntl[i]++;
		}
		else {
			lcntr[i]++;
			rcntr[i]++;
		}
	}
	REP(i, n - 1) {
		lcntl[i + 1] += lcntl[i];
		lcntr[i + 1] += lcntr[i];
	}
	RREP(i, n - 1) {
		rcntl[i] += rcntl[i + 1];
		rcntr[i] += rcntr[i + 1];
	}
	int ans = 0;
	REP(i, n) {
		if (s[i] == '<') {
			int a = lcntr[i], b = rcntl[i];

			if (a < b) {
				int c = lower_bound(rcntl.rbegin(), rcntl.rend(), b - a ) - rcntl.rbegin();

				ans = max(ans, n - c);
			}
			else {
				int c = lower_bound(ALL(lcntr), a - b + 1) - lcntr.begin();
	
				ans = max(ans, n - c);
			}
		}
		else {
			int a = lcntr[i], b = rcntl[i];
			if (a <= b) {
				int c = lower_bound(rcntl.rbegin(), rcntl.rend(), b - a + 1) - rcntl.rbegin();

				ans = max(ans, n - c);
			}
			else {
				int c = lower_bound(ALL(lcntr), a - b ) - lcntr.begin();
	
				ans = max(ans, n - c);
			}
		}
	}
	cout << ans << endl;

}



Measured memory_bytes: 5212
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P; //ペア　タイプでふ

int main()
{
    int A, B, T;
    cin >> A;
    cin >> B;
    cin >> T;
    cout << (int)(B * ((T - T % A) / A));
    // int A, B, C;
    // cin >> A >> B >> C;
    // if (A < C && C < B)
    // {
    //     cout << "Yes";
    // }
    // else
    // {
    //     cout << "No";
    // }
}

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,29)-1;


int main() {
  string S; cin >> S;
  int len = S.length();
  int l[len+1]={}, r[len+1] = {};

  int ltmp = 0, rtmp = 0;
  rep(i,len) {
    ltmp = (S[i]=='<') ? ltmp+1 : 0;
    l[i+1] = ltmp;
  }
  for (int i=len; i>=1; i--) {
    rtmp = (S[i-1]=='>') ? rtmp+1 : 0;
    r[i-1] = rtmp;
  }
  // rep(i, len+1) cout << l[i] << "-" << r[i] << endl;
  ll result = 0;
  rep(i,len+1) result += max(l[i], r[i]);
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 4868
using System;


namespace _119_ABC
{
    class Program01
    {
        static void Main(string[] args)
        {
            string Input = Console.ReadLine();

            if (Input.CompareTo("2019/04/30") > 0)
            {
                Console.WriteLine("TBD");
            }
            else
            {
                Console.WriteLine("Heisei");
            }


        }
    }
}


Measured memory_bytes: 13280
#include <iostream>
using namespace std;
int main() {
  	string x;
  	cin >> x;
  	int num = atoi(x.c_str());
  	int a = num/100;
  	int b = num%100;
  	string y;
  	if(a<13 && a>0){
  	    if(b<13 &&b>0){
  	        y="AMBIGUOUS";
  	    }else if(b<100 && b>=0){
  	        y="MMYY";
  	    }else{
  	        y="NA";
  	    }
  	}else if(b<13 && b>0){
  	    if(a<13 && a>0){
  	        y="AMBIGUOUS";
  	    }else if(a<100 && a>=0){
  	        y="YYMM";
  	    }else{
  	        y="NA";
  	    }
    }else{
  	    y = "NA";
    }
  	cout << y <<endl;
}


Measured memory_bytes: 256
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 

const ll inf = (ll)(1e17 + 17);
const ll mod = (ll)(1e9 + 7);


int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  char c;
  cin >> c;
  cout << char(c + 1);
  return 0;
} //good night.

Measured memory_bytes: 764
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    char s; cin>>s;
    for(char a='a';a<='z';a++){
        if(a==s){
            cout<<'a'<<endl;
            return 0;
        }
    }
    cout<<'A'<<endl;
}




























































































Measured memory_bytes: 3628
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int a = sc.nextInt();
   int b = sc.nextInt();
   int c = sc.nextInt();

   if(a+b==c||a+c==b||b+c==a)System.out.println("Yes");
   else System.out.println("No");
 }
}

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

using namespace std;
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 Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1 << 30;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};

int main(void){
	int a, b, c; cin>>a>>b>>c;

	if(a == b && a == c) cout<< "Yes" <<endl;
	else cout<< "No" <<endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        ArrayList<Character>  ary = new ArrayList<Character>();
        StringBuilder str = new StringBuilder(s);
        for(int i = 0; i < str.length(); ++i){
            ary.add(str.charAt(i));
        }
        Collections.sort(ary);
        if(ary.get(0) == ary.get(1) && ary.get(2) == ary.get(3) && ary.get(0) != ary.get(2)) {
            System.out.print("Yes");
        } else  {
            System.out.print("No");
        }
     }
}

Measured memory_bytes: 23764