akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll cnt = 0;
    while(a>=b){
        b *= 2;
        cnt++;
    }
    while(b>=c){
        c *= 2;
        cnt++;
    }

    cout << (cnt <= k ? "Yes" : "No") << endl;
}

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

int main() {
   int k;
   string s;
   cin >> k >> s;

   if (s.length() > k) {
       cout << s.substr(0, k) << "..." <<endl;
   } else {
       cout << s << endl;
   }
}

Measured memory_bytes: 3584
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class t>
using table = vector<vector<t>>;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"
  
long long int gcd(long long int l, long long int r) {
	if (l > r)return gcd(r, l);
	else {
		if (r%l) {
			return gcd(l, r%l);

		}
		else {
			return l;
		}
	}
}

int main() {
	cout << setprecision(11) << fixed;
	while (1) {
		int N, M; cin >> N >> M;
		ld sum = 0;
		ld year = 0;
		if (!N)break;
		vector<long long int>nums(M);
		for (int i = 0; i < M; ++i)cin >> nums[i];
		for (int i = 0; i < (1 << M); ++i) {
			bitset<20>bs(i);
			long long int anum = 1;
			for (int j = 0; j < M; ++j) {
				if (bs[j]) {
					anum = anum*nums[j] / gcd(anum, nums[j]);
				}
			}
			ld asum = N / anum;
			ld ayear= (anum + N)*(N / anum) / 2;
			if (bs.count() % 2) {

				sum -= asum;
				year -= ayear;
			}
			else {

				sum += asum;
				year+= ayear;
			}
		}
		if (sum < eps)cout << 0 << endl;
		else 	cout << year/ sum << endl;
	
	}
	return 0;
}

Measured memory_bytes: 3288
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cstdio>
#include<set>
using namespace std;
int a[10000000];
inline int read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
int main(){
    int T=read();
    for(int i=0;i<2*T;i++){
    	a[i]=read();
	}
	sort(a,a+2*T);
	long long ans=0;
	for(int i=0;i<2*T;i=i+2)
	{
		ans=ans+min(a[i],a[i+1]);
	}
	cout<<ans<<endl;
 	return 0;
} 

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		try {
			String s = sc.next();

			int idx = s.indexOf("A");
			int lstIdx = s.lastIndexOf("Z");

			System.out.println(lstIdx - idx + 1);

		} finally {
			sc.close();
		}
	}
}

Measured memory_bytes: 26720
// Never let them see you bleed...

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, int> pli;

const int maxn = 2e5 + 10, mod = 1e9 + 7, inf = 1e9 + 10;

vector<ll> v[maxn];
vector<pli> a;
int cnt[maxn];
int pt[maxn];
ll bst[maxn], indiv[maxn];

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

    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++){
	int a, b;
	cin >> a >> b;
	v[--a].PB(2*b);
    }
    for(int i = 0; i < k; i++){
	sort(v[i].begin(), v[i].end(), greater<ll>());
	assert(sz(v[i]) >= 2);
	ll avg = (v[i][0] + v[i][1]) / 2;
	v[i][0] = v[i][1] = avg;
	for(ll x : v[i])
	    a.PB({x, i});
    }
    sort(a.begin(), a.end(), greater<pli>());
    for(int i = 0; i < k; i++){
	v[i].clear();
    }
    bst[n] = -1;
    for(int i = n-1; i >= 0; i--){
	int c = a[i].S;
	ll num = -1;
	v[c].PB(a[i].F);
	if(sz(v[c]) >= 3)
	    num = v[c][sz(v[c])-1] + v[c][sz(v[c])-2] + v[c][sz(v[c])-3];
	bst[i] = max(bst[i+1], num);
    }
    for(int i = 0; i < k; i++){
	reverse(v[i].begin(), v[i].end());
    }
    
    multiset<ll> st;
    for(int i = 0; i < n; i++){
	int c = a[i].S;
	if(st.empty())
	    indiv[i] = -1;
	else
	    indiv[i] = *st.rbegin();
	if(++pt[c] >= 2){
	    if(pt[c] != 2)
		st.erase(st.find(v[c][pt[c]-1]));
	    if(pt[c] != sz(v[c]))
		st.insert(v[c][pt[c]]);
	}
    }
    
    ll sum = 0, lst = -1;
    for(int i = 0; i < n; i++){
	cnt[a[i].S]++;
	sum+= a[i].F;
	ll ans = -2;
	if(cnt[a[i].S] > 2){
	    lst = a[i].F;
	}
	if(cnt[a[i].S] == 1){
	    if(lst != -1)
		ans = max(ans, sum + a[i].F - lst);
	    if(i > 1 && cnt[ a[i-1].S ] == 2 && a[i-1].S == a[i-2].S && bst[i-2] != -1)
		ans = max(ans, sum - a[i].F - a[i-1].F - a[i-2].F + bst[i-2]);
	    if(indiv[i] != -1)
		ans = max(ans, sum - a[i].F + indiv[i]);
	}
	else{
	    ans = sum;
	}
	cout << ans/2 << "\n";
    }
    return 0;    
}


Measured memory_bytes: 21228
r,c = gets.chomp.split(" ").map{|x| x.to_i}
t = []
t[r] = [0]*(c+1)
for i in 1..r do
  t[i-1] = gets.chomp.split(" ").map{|x| x.to_i}
  t[i-1][c] = t[i-1].inject(:+)
  for j in 0..c do
    t[r][j] += t[i-1][j]
  end
  printf("%s\n",t[i-1].join(" "))
end
printf("%s\n",t[r].join(" "))


Measured memory_bytes: 7044
N,K = map(int,input().split())
D = {}
for i in range(N) :
    a,b = map(int,input().split())
    if a not in D :
        D[a] = b
    else :
        D[a] += b
D = sorted(D.items(),key=lambda x:x[0])
for i in D :
    K -= i[1]
    if K <= 0 :
        ans = i[0]
        break
print(ans)


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


int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	vector<pair<int,int>> aaas;
	rep(i,n){
		cin >> a[i];
		aaas.push_back( make_pair(a[i], i));
	}
	sort(aaas.begin(), aaas.end());

	rep(i,n) cout << aaas[i].second + 1 << " ";
	return 0;
}

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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

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

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;
typedef vector<int>				V;
typedef vector<V>				VV;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define MAX 		100050

const ll LINF = (ll)1e18+7;		//
const int INF = 1e9+7;			//2,147,483,647 (Max int)
const int MOD = 1e9+7;
// テンプレ終了
//====================================================================//

ll DIGIT[MAX][13];

//
int main(){
	string S;
	cin >> S;
	int N = S.size();

	V M(N+1);
	M[1] = 1;
	REPS(i,2,N+1){
		M[i] = (M[i-1]*10)%13;
	}

	DIGIT[0][0] = 1;

	REP(i,N){
		REP(j,13){
			if(S[N-i-1]=='?'){
				REP(k,10){
				//	cout << " " << ((j+M[i+1]*k)%13);
					DIGIT[i+1][(j+M[i+1]*k)%13] += DIGIT[i][j];
					DIGIT[i+1][(j+M[i+1]*k)%13] %= MOD;
				}
				//cout << endl;
			}else{
				//printf("%d [%d:%d]\n",((j+M[i+1]*(S[N-i-1]-'0'))%13) ,j, DIGIT[i][j] );
				DIGIT[i+1][(j+M[i+1]*(S[N-i-1]-'0'))%13] += DIGIT[i][j];
				DIGIT[i+1][(j+M[i+1]*(S[N-i-1]-'0'))%13] %= MOD;
			}
		}
	}

	cout << DIGIT[N][5]  << endl;

	return 0;
}




Measured memory_bytes: 11008
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dd;
#define PI 3.14159
#define Mod 998244353
#define pi acos(-1)


int main()
{
    int n;
    cin >> n;
    double p = (double)(n*n*n)/27.0;
    printf("%0.12f\n", p);
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

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

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var n int
	con.Scan(&n)
	m := make([]int, 26)
	for i := 0; i < 26; i++ {
		m[i] = 100
	}
	for i := 0; i < n; i++ {
		var s string
		con.Scan(&s)
		d := make([]int, 26)
		for _, c := range s {
			d[c-'a']++
		}
		for j := 0; j < 26; j++ {
			if d[j] < m[j] {
				m[j] = d[j]
			}
		}
	}
	for i := 0; i < 26; i++ {
		for j := 0; j < m[i]; j++ {
			con.Printf("%c", 'a'+i)
		}
	}
	con.Println()
	return nil
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cout << "[" << #var << "] " << var << endl
const ll mod = 1000000007;


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

    int ans = 0;
    if (k<=a) {
        ans = k;
    }
    else if (k>a && k<=a+b) {
        ans = a;
    }
    else {
        ans = a - (k-a-b);
    }

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


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

int main(){
  	int a,b,c;
	cin >> a >> b >> c;
  	if(22 <= a+b+c)
    {
      cout << "bust" << endl;
    }
  	else if(a+b+c <= 21)
  	{
    	cout << "win" << endl;
    }
  	else
  	{
      
  	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>//printf("%.15f\n",*********);
#include<vector>//文字列.erase(n),vector
#include<algorithm>//next_permutation
#include<set>
#include<string>//char(小文字-32=大文字)
                //to_string,string,substr
#include<sstream>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>//min,max
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)//start==1
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)//end==1
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())//反転
#define str string
#define please return
#define AC 0
#define rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define pi 3.1415926535897932384626//pi
#define nine 1000000000//10^9

using namespace std;
typedef vector<int> vint;
typedef long double ldouble;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef vector<double> vdouble;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

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

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int KETA(int n) { //Sum of Each Digit
	int sum = 0;
	while (n > 0) {
		sum += n % 10; n /= 10;
	}
	return sum;
}

unsigned ND(unsigned num) {//Number of Digits
	return std::to_string(num).length();//outmax=10
}//stringのほうが効率よくないか？

bool KIBN(string s) {
	rep(i, s.size() / 2) {
		if (s[i] != s[s.size() - 1 - i])return false;
	}
	return true;
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */


int main(void) {
	rapid_pleaseAC_fast;
	
	int n, m;
	cin >> n >> m;
	
	cout << (n - 1) * (m - 1) << rt;

	please AC;
}
//参考：---

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int A,B,C,D;
int main(){
    cin >> A >> B >> C >> D;
    if(A+B > C+D){
        cout << "Left" << endl;
    }else if(A+B == C+D){
        cout << "Balanced" << endl;
    }else{
        cout << "Right" << endl;
    }
}

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

int main()
{
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    int ans = 0;
    if (2 * C < A + B)
    {
        int m = min(X, Y);
        ans += C * m * 2;
        X -= m;
        Y -= m;

        if ((X == 0 && B < 2 * C) || (Y == 0 && A < 2 * C))
        {
            ans += X * A + Y * B;
        }
        else
        {
            ans += (X + Y) * 2 * C;
        }
    }
    else
    {
        ans += X * A + Y * B;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
s = input()
if s[0] == s[1] and s[1] == s[2] and s[1] =='R':
    print('3')
elif (s[0] == s[1] or s[1] == s[2]) and s[1]=='R':
    print('2')
elif s[0] == 'R' or s[1] =='R' or s[2] == 'R':
    print('1')
else:
    print('0')

Measured memory_bytes: 9076
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}


int main(){
  string s1,s2,s3;
  cin>>s1>>s2>>s3;
  cout<<(char)(s1[0]-'a'+'A')<<(char)(s2[0]-'a'+'A')<<(char)(s3[0]-'a'+'A')<<endl;
  return 0;
}

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())
ans = 0
for i in range(A+1):
  for j in range(B+1):
    for k in range(C+1):
      if(500*i+100*j+50*k)==X:
        ans += 1
print(ans)

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

int main() {
    string s;
    int answer = 0;
    cin >> s;
    if (s[0] == '1') answer++;
    if (s[1] == '1') answer++;
    if (s[2] == '1') answer++;
    cout << answer << endl; 
    return 0;
}


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

#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;
const int INF = 2e16;
const int MOD = 1e9 + 7;
const int MB = 20;

vector<vector<int>> g;

void dfs(int v, vector<int>& h, int pr = -1) {
	for (int u : g[v]) {
		if (u != pr) {
			h[u] = h[v] + 1;
			dfs(u, h, v);
		}
	}
}

void solve() {
	int n, v, u;
	cin >> n >> v >> u;
	v--; u--;
	g.resize(n);
	for (int i = 0; i < n - 1; i++) {
		int from, to;
		cin >> from >> to;
		from--; to--;
		g[from].pb(to);
		g[to].pb(from);
	}

	vector<int> h1(n), h2(n);
	dfs(v, h1);
	dfs(u, h2);

	int ans = 0;
	
	bool good = false;
	for (int i : g[v]) {
		if (i != u) good = true;
	}
	if (good) ans = 1;

	for (int i = 0; i < n; i++) {
		if (h1[i] < h2[i]) {
			ans = max(ans, h1[i] + (h2[i] - h1[i]) / 2 * 2 - 1 + (h2[i] - h1[i]) % 2);
		}
	}


	cout << ans;
}

signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	solve();
}

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

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
typedef pair<int, int> P;
struct TV{
  P time;
  int r1, r2;
  bool operator < (const TV& t) const{
    return time < t.time;
  }
  TV() {}
  TV(int f) { time = P(f, 0); }
};
void update(int& x, int y){
  if(x < y) x = y;
}

int main(){
  int N;
  while(cin >> N && N){
    int dp[1001][1001] = {};
    vector<TV> tv(N);
    REP(i, N){
      char tmp[100];
      int a, b, c, d;
      scanf("%s %d:%d %d:%d %d %d", tmp, &a, &b, &c, &d, &tv[i].r1, &tv[i].r2);
      tv[i].time = P(a * 60 + b , c * 60 + d);
    }
    sort(tv.begin(), tv.end());
    for(int i = 0; i <= N; i++){
      for(int j = 0; j <= N; j++){
        if(i < N){
          int ni = lower_bound(tv.begin(), tv.end(), TV(tv[i].time.second)) - tv.begin();
          update(dp[ni][max(i + 1, j)], dp[i][j] + tv[i].r1);
          update(dp[i + 1][j], dp[i][j]);
        }
        if(j < N){
          int nj = lower_bound(tv.begin(), tv.end(), TV(tv[j].time.second)) - tv.begin();
          update(dp[max(j + 1, i)][nj], dp[i][j] + tv[j].r2);
          update(dp[i][j + 1], dp[i][j]);
        }
      }
    }
    cout << dp[N][N] << endl;
  }
  return 0;
}

Measured memory_bytes: 5184
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

/*
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()
*/

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-9;

struct ConvexHullTrick {
    struct Line {
        ll a, b;
        Line(ll a, ll b) : a(a), b(b) {}
        ll get(ll x) { return a * x + b; }
    };
    deque<Line> que;
    bool check(Line& l1, Line& l2, Line& l3) {
        return (l3.b - l2.b) * (l2.a - l1.a) >= (l2.b - l1.b) * (l3.a - l2.a);
    }
    void add(ll a, ll b) {
        Line l(a, b);
        while(que.size() > 1 && check(que[que.size() - 2], que.back(), l))
            que.pop_back();
        que.push_back(l);
    }
    ll query(ll x) {
        if(que.empty()) return INFL;
        while(que.size() > 1 && que[0].get(x) >= que[1].get(x))
            que.pop_front();
        return que[0].get(x);
    }
};

void solve() {
    ll n, c;
    cin >> n >> c;
    vll h(n);
    for(ll i = 0; i < n; i++) cin >> h[i];
    vll dp(n);
    dp[0];
    ConvexHullTrick cht;
    cht.add(-2 * h[0], h[0] * h[0]);
    for(ll i = 1; i <= n - 1; i++) {
        dp[i] = cht.query(h[i]) + h[i] * h[i] + c;
        cht.add(-2 * h[i], dp[i] + h[i] * h[i]);
    }
    cout << dp[n - 1] << endl;
    return;
}

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


Measured memory_bytes: 5632
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.max

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val n = readInteger()
    val map = mutableMapOf<Int, Map<Int, Int>>()
    repeat(n) {
        val a = readInteger()
        val tmp = mutableMapOf<Int, Int>()
        repeat(a) {
            val (x, y) = readIntegerList()
            tmp[x - 1] = y
        }
        map[it] = tmp
    }

    var ans = 0
    for (state in 0 until (1 shl n)) {
        if (check(state, n, map)) {
            ans = max(ans, Integer.bitCount(state))
        }
    }
    out.println(ans)
}

fun check(state: Int, n: Int, map: MutableMap<Int, Map<Int, Int>>): Boolean {
    for (i in 0 until n) {
        if (((state shr i) and 1) == 1) {
            for (j in map[i]!!) {
                if (((state shr j.key) and 1) != j.value) {
                    return false
                }
            }
        }
    }
    return true
}



fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 41004
let () =
    let log2 n =
        let rec loop i acc =
            if i = 0 then acc - 1 else loop (i lsr 1) (acc + 1)
        in
        loop n 0
    in
    let main () =
        let n = int_of_string (read_line ()) in
        if n land (n - 1) = 0 then print_endline "No" else (
            print_endline "Yes";
            for i = 1 to (n - 1) / 2 do
                Printf.printf "%d %d\n" 1 (2 * i);
                Printf.printf "%d %d\n" (2 * i) (2 * i + 1);
                Printf.printf "%d %d\n" 1 (2 * i + 1 + n);
                Printf.printf "%d %d\n" (2 * i + n) (2 * i + 1 + n);
            done;
            Printf.printf "%d %d\n" 3 (n + 1);
            if n mod 2 = 0 then (
                let k = 1 lsl (log2 n) in
                let a = k + 1 + n in
                let b = k lxor n in
                Printf.printf "%d %d\n" a (n + n);
                Printf.printf "%d %d\n" b n
            )
        )
    in
    main ()

Measured memory_bytes: 4736
# スペース区切りの整数の入力
a,b,c,d=gets.chomp.split(" ").map(&:to_i);

duprecate = (c * d) / c.gcd(d)
#puts duprecate

#puts (b - a + 1)
##puts (b / c - (a - 1) / c)
#puts (b / d - (a -1 ) / d)
#puts  (b / duprecate - a / duprecate)

count = (b - a + 1) - (b / c - (a - 1) / c) - (b / d - (a - 1) / d) + (b / duprecate - (a - 1) / duprecate)



print("#{count}\n")


Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <algorithm>

int main(){
    std::string S, T;
    std::cin >> S >> T;

    T.erase(T.size() - 1);

    std::string ans = S == T ? "Yes" : "No";

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 3632
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const double EPS = 1e-12;
const double INF = 1e12;

long d[100001];
int main(){
	LL D,n,m;
	while(cin>>D){
		if(D==0)break;
		cin>>n>>m;
		CLR(d);
		d[0]=0;
		FOR(i,1,n)cin>>d[i];
		d[n]=D;
		sort(d,d+n+1);
		LL k,res=0;
		
		REP(i,m){
			cin>>k;
			long *pos=upper_bound(d,d+n+1,k);
			long p=(long)(pos-d);
			if(p!=0){
				res+=min(abs(d[p]-k),abs(d[p-1]-k));
			}else{
				res+=min(abs(d[0]-k),abs(k+D-d[n-1]));
			}
		}
		
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 1968
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second
#define endl "\n"

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<string, int> P;


class Graph{
    struct edge{
        int vertice;
        ll weight;
    };

    vector<vector<edge>> g;
    unsigned int n;

public:
    Graph(unsigned int n): n{n}{
        g.resize(n);
    }

    void add_edge(int u, int v){
        g[u].emplace_back(edge{v, 1});
    };

    void add_edge(int u, int v, ll w){
        g[u].emplace_back(edge{v, w});
    }

    vector<edge>& get_edge(int v){
        return g[v];
    }

    unsigned int size(){
        return n;
    }

    vector<edge>& operator[](int v){
        return get_edge(v);
    }
};


int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int x = (c + b - 1) / b;
    int y = (a + d - 1) / d;

    if(x <= y){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }


    return 0;
}


Measured memory_bytes: 3640
X,Y,Z,K = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse=True)
B = sorted(list(map(int,input().split())),reverse=True)
C = sorted(list(map(int,input().split())),reverse=True)

L = []
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if (i+1)*(j+1)*(k+1) <= K:
                L.append(A[i]+B[j]+C[k])
            else:
                break

L = sorted(L,reverse=True)[:K]
for l in L:
    print(l)

Measured memory_bytes: 9564
import java.util.Scanner;

public class Main {
    static int sum; // 消した石の数値の合計
    public static void main(String[] args) {
        final int ROW = 5; // 列の数
        final int MINREMOVE = 3; // 消すのに必要な個数
        Scanner sc = new Scanner(System.in);
        
        while (true) {
            int H = sc.nextInt();
            if (H == 0) {
                break;
            }
            
            int[][] field = new int[H][ROW+1];
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < ROW; j++) {
                    field[i][j] = sc.nextInt();
                }
                field[i][ROW] = 0;
            }
            sum = 0;
            
            //printField(field);
            //System.out.println();
            while (removeField(field, MINREMOVE)) {
                //printField(field);
                //System.out.println();
                fallField(field);
                //printField(field);
                //System.out.println();
            }
            
            System.out.println(sum);
        }
    }
    
    public static boolean removeField(int[][] field, int n) {
        boolean isRemove = false; // 1回以上消したかどうか
        
        for (int i = 0; i < field.length; i++) {
            int num = 0; // num連続
            for (int j = 0; j < field[i].length; j++) {
                if (j == 0) {
                    num = 1;
                } else {
                    //System.out.println(i + " " + j);
                    if (field[i][j-1] == field[i][j] && field[i][j] != 0) {
                        num++;
                    } else {
                        if (num >= n) {
                            removeStone(field, j - num, i, num);
                            isRemove = true;
                        }
                        num = 1;
                    }
                }
            }
        }
        return isRemove;
    }
    
    public static void removeStone(int[][] field, int x, int y, int n) {
        for (int i = 0; i < n; i++) {
            sum += field[y][x+i];
            field[y][x+i] = 0;
        }
    }
    
    public static void fallField(int[][] field) {
        // 下から2段目以上にある石を落とす
        for (int i = field.length - 2; i >= 0; i--) {
            for (int j = 0; j < field[i].length; j++) {
                if (field[i][j] != 0) {
                    int x = j;
                    int y = i;
                    while (y < field.length - 1&& field[y+1][x] == 0) {
                        field[y+1][x] = field[y][x];
                        field[y][x] = 0;
                        y++;
                    }
                }
            }
        }
    }
    
    public static void printField(int[][] field) {
        for (int i = 0; i < field.length; i++) {
            for (int j = 0; j < field[i].length; j++) {
                System.out.print(field[i][j] + " ");
            }
            System.out.println();
        }
    }
}

Measured memory_bytes: 49960
#include <bits/stdc++.h>
using namespace std;
#define FAST  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int 

//power of 2 ...n&(n-1)==0

int main()
{
	FAST;
	//#ifndef ONLINE_JUDGE
	//	freopen("input.txt","r",stdin);
	//	freopen("output.txt","w",stdout);
	//#endif
	 //ll testcase;
	 //cin>>testcase;
	 //for(ll t=0;t<testcase;t++)
	{
		// use long long
		//donot memeset other than 0 or 1 or -1
		//segmentation fault-> check for uninitialized global variable or out of bounds
		//always check for bottle neck (whether original constraints can be reduced by introducing some condition)
		//dont rush to writing code think through the logic	
		int n;
		cin>>n;
		int a[n];
		int all_xor=0;
		for(int i=0;i<n;i++)
		{
			cin>>a[i];
			all_xor^=a[i];
		}
		for(int i=0;i<n;i++)
		{
			cout<<(all_xor^a[i])<<' ';
		}
		cout<<'\n';
			
			
		
		
		
		
		
		
		
		
		
		
		
	}
	return 0;
}





























































Measured memory_bytes: 4336
#!/usr/bin/env python3
import sys
import math
import decimal
import itertools
from itertools import product
from functools import reduce
def input():
    return sys.stdin.readline()[:-1]
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
def sort_zip(a:list, b:list):
    z = zip(a, b)
    z = sorted(z)
    a, b = zip(*z)
    a = list(a)
    b = list(b)
    return a, b
def ceil(x):
    return math.ceil(x)
def floor(x):
    return math.floor(x)

def main():
    M, D = map(int, input().split())

    ans = 0
    for m in range(1, M + 1):
        for d in range(22, D + 1):
            if int(str(d)[1]) > 1 and int(str(d)[0]) * int(str(d)[1]) == m:
                ans += 1
    print(ans)




if __name__ == '__main__':
    main()


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

#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).rbegin(),(a).rend())
#define ll long long
#define pb(a) push_back(a)

#define PRINTV(v) {for(ll deB=0; deB<(v).size(); deB++){cout << (v)[deB] << " ";}cout << endl;}

#define MOD 1000000007

int main(){
	
	ll N,K;
	cin >> N >> K;
	vector<ll> p(N,0);
	vector<ll> n(N,0);
	ll ps=0, ns=0;
	REP(i,N){
		ll t;
		cin >> t;
		if(t<0) n[ns++] = -t;
		else p[ps++] = t;
	}
	ll ret = 1;
	if(N==K){
		if((ns%2)==1){
			ret = -1;
		}
		REP(i,ps){
			ret = (ret * p[i]) % MOD;
		}
		REP(i,ns){
			ret = (ret * n[i]) % MOD;
		}
		ret = (ret+MOD) % MOD;
		cout << ret << endl;
		
		return 0;
	}
	if(ps==0 && (K%2)==1){
		sort(n.begin(), n.end());
		ret = -1;
		REP(i,K){
			ret = (ret * n[i]) % MOD;
		}
		ret = (ret+MOD) % MOD;
		cout << ret << endl;
		
		return 0;
	}
	sort(p.begin(), p.end(), greater<ll>());
	sort(n.begin(), n.end(), greater<ll>());

	ll np=0, pp=0;

	while (np+pp < K-1){
		ll pt = (pp < (ps-1))?p[pp]*p[pp+1]:-1;
		ll nt = (np < (ns-1))?n[np]*n[np+1]:-1;
		if(pt>=nt){
			ret = (ret * p[pp]) % MOD;
			pp += 1;
		}else{
			ret = (ret * n[np]) % MOD;
			ret = (ret * n[np+1]) % MOD;
			np += 2;
		}
	}
	if(np+pp != K){
		ret = (ret * p[pp]) % MOD;
	}

	cout << ret << endl;
	
	return 0;
}

Measured memory_bytes: 6428
import sys

def input():
    return sys.stdin.readline()[:-1]

N = int(input())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def func1(lst, value):
    return [i for i, x in enumerate(lst) if x <= value]

if N == 1:
	print(0)
else:
	
	ans_ = factorization(N)
	nums = []
	index_list = []
	
	ans = 0
	for i in range(1, 100):
		ans += i
		index_list.append(ans)
		
	for a in ans_:
		#nums.append(int(format(a[1], 'b')))
		nums.append(a[1])
		
		#print(nums)
			
	ans = 0
	for i in nums:
		index = func1(index_list, i)
		#print(max(index)+1)
		ans += max(index)+1
	
	print(ans)


Measured memory_bytes: 63980
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll MOD=1000000007;

 
int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if ((c-1)/b<=(a-1)/d) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3632
import Control.Applicative
import Data.List

main :: IO ()
main = solve <$> f >>= print
  where
    f = map read <$> words <$> getLine

solve :: [Int] -> Int
solve [m, d] = foldl' f 0 [22 .. d]
  where
    f c x = let (q, r) = x `divMod` 10
                y = q * r
            in if q >= 2 && r >= 2 && y <= m
               then c + 1
               else c


Measured memory_bytes: 508
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
#define vi vector<int>
#define pb push_back
#define bi_s binary_search
#define lb lower_bound
#define ub upper_bound
using namespace std;

int h;
int w;
char a[103][103];
vi v;

int main(){
	cin >>h >>w;
  	int cnt=0;
  	rep(i,h){
      	bool flag=0;
    	rep(j,w){
        	cin >>a[cnt][j];
          	if(a[cnt][j]=='#') flag=1; 
        }
      if(flag) cnt++;
    }
  //cout <<cnt <<endl;	
  
  rep(i,w){
    bool flag=1;
  	rep(j,cnt){
    	if(a[j][i]=='#') flag=0;
    }
  	if(flag) v.pb(i);
  }
  v.pb(1000);
  
  	rep(i,cnt){
    	rep(j,w){
          if(!bi_s(v.begin(),v.end(),j))
        	cout<<a[i][j];
        }
      	cout <<"\n";
    }
	  	
  
  
  	return 0;

}

Measured memory_bytes: 256
#import<iostream>
#import<string>
#import<map>
using namespace std;int main(){map<string,int>m;string s,t,u;for(;cin>>s;s.length()>u.length()?u=s:u)++m[s]>m[t]?t=s:s;cout<<t<<" "<<u<<"\n";}

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

int main()
{
  int n;
  long long money=1000,chicket=0;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  rep(i,n-1){
    money+=chicket*a[i];
    chicket=0;
    if(a[i]<a[i+1]){
      chicket=money/a[i];
      money=money%a[i];
    }
  }
  money+=chicket*a[n-1];
  cout << money << endl;
  return 0;
}

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

void solve(long long X, long long Y, long long Z)
{
    printf("%d %d %d", Z, X, Y);
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long X;
    scanf("%lld", &X);
    long long Y;
    scanf("%lld", &Y);
    long long Z;
    scanf("%lld", &Z);
    solve(X, Y, Z);
    return 0;
}

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

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

  if(a == b) {
    cout << c << endl;
  } else if (b == c) {
    cout << a << endl;
  } else {
    cout << b << endl;
  }
}

Measured memory_bytes: 384
n,a = gets.split.map(&:to_i)
x = gets.split.map{|t| t.to_i - a}

count = {0 => 1}
x.each do |e|
    d = Hash.new(0)
    count.each do |key,value|
        d[key] += value
        d[key+e] += value
    end
    count.clear
    count = d
    #p count
end

puts count[0] - 1

Measured memory_bytes: 1916
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n, a[200008];
string str;

int main(){
	cin >> n;
	for(ll i = 1; i <= n; i++){
		cin >> a[i];
	}
	
	ll max = 0;
	ll max2 = 0; 
	for(ll i = 1; i <= n; i++){
		if(a[i] > max){
			max2 = max;
			max = a[i];
		}
		else{
			if(a[i] > max2){max2 = a[i];}
		}
	}
	
	for(ll i = 1; i <= n; i++){
		if(a[i] == max){cout << max2 << endl;}
		else{cout << max << endl;}
	}
	return 0;
}

Measured memory_bytes: 3200
import java.util.Scanner;

public class Main{
	
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String in = sc.nextLine();
		sc.close();
		
		System.out.println(count(in));
	}
	
	static int count(String str){
		char now = str.charAt(0);
		int result = 0;
		for(char c: str.toCharArray()){
			if(now != c){
				now = c;
				result++;
			}
		}
		return result;
	}
}


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

typedef long long ll;
ll N, M;
ll Q;
vector<pair<ll, ll>> Black;

const ll MAX_N = 100000;
ll Parent[MAX_N], Rank[MAX_N], NGroups;
void init() {
  fill(Parent, Parent + N, -1);
  fill(Rank, Rank + N, 1);
  NGroups = N;
}
ll root(ll x) {
  if (Parent[x] == -1) return x;
  return Parent[x] = root(Parent[x]);
}
void unite(ll x, ll y) {
  x = root(x);
  y = root(y);
  if (x == y) return;
  --NGroups;
  if (Rank[x] > Rank[y]) {
    Parent[y] = x;
  } else {
    Parent[x] = y;
    if (Rank[x] == Rank[y]) {
      ++Rank[y];
    }
  }
}
bool same(ll x, ll y) { return root(x) == root(y); }

bool solve() {
  for (ll i = 0; i < Q; ++i) {
    ll a, b, c;
    cin >> a >> b >> c;
    if (c == 0) {
      unite(a, b);
    } else {
      Black.push_back(make_pair(a, b));
    }
  }
  for (auto pair : Black) {
    if (M == N - 1) return false;
    if (same(pair.first, pair.second)) return false;
  }
  return M - N <= NGroups * (NGroups - 3) / 2;
}
int main() {
  cin >> N >> M >> Q;
  init();
  cout << (solve() ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 3956
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
 
#define endl "\n"
 
const ll INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);
 
mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());

const int N = 3e5 + 5;

vector<int> G[N];
int h, w, m, r[N], c[N];

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

    cin >> h >> w >> m;
    vector<pii> p;
    for (int i = 0; i < m; ++i) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        p.emplace_back(x, y);
        ++r[x];
        ++c[y];
    }

    int maxx = 0, maxy = 0;
    for (int i = 0; i < N; ++i) {
        maxx = max(maxx, r[i]);
        maxy = max(maxy, c[i]);
    }

    for (int i = 0; i < m; ++i) {
        int x = p[i].first;
        int y = p[i].second;
        if (c[y] == maxy)
            G[x].push_back(y);
    }

    set<int> have;
    for (int i = 0; i < N; ++i)
        if (c[i] == maxy)
            have.insert(i);

    int ans = maxx + maxy - 1;
    for (int i = 0; i < N; ++i) {
        if (r[i] != maxx)
            continue;
        for (auto y : G[i]) {
            have.erase(y);
        }
        if (!have.empty()) {
            ans = maxx + maxy;
        }
        for (auto y : G[i])
            have.insert(y);
    }
    cout << ans << endl;
}


Measured memory_bytes: 38436
// Link : https://atcoder.jp/contests/abc147/tasks/abc147_a
#include <iostream>
using namespace std;

int main(int argc, char const *argv[])
{
    int a1, a2, a3;
    cin>>a1>>a2>>a3;
    int total = a1 + a2 + a3;
    if (total >= 22)
    {
        cout<<"bust";
    }
    else
    {
        cout<<"win";
    }
    
    return 0;
}


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

lst_A = []

for i in range(N):
    lst_A.append(L)
    L += 1

eat = 999

for i in range(N):
    if abs(lst_A[i]) < abs(eat):
        eat = lst_A[i]

i = 0
while 1:
    if lst_A[i] == eat:
        del lst_A[i]
        break
    i += 1

print(sum(lst_A))

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

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		String[] tmpArray = br.readLine().split(" ");
		
		int[] input = new int[n];
		
		for(int i = 0; i < n; i++){
			input[i] = Integer.parseInt(tmpArray[i]);
		}
		
		String result = "Yes";
		for(int i = n - 2; i >= 0; i--){
			if(input[i] > input[i + 1]){
				input[i]--;
			}
			if(input[i] > input[i + 1]){
				result = "No";
				break;
			}
		}
		
		System.out.println(result);
	}

}


Measured memory_bytes: 46036
#include <iostream>
#include <string>
using namespace std;
 
int main() {
	string S;
	cin>>S;
	if(S=="MON"){
		cout<<6;
	}else if(S=="TUE"){
		cout<<5;
	}else if(S=="WED"){
		cout<<4;
	}else if(S=="THU"){
		cout<<3;
	}else if(S=="FRI"){
		cout<<2;
	}else if(S=="SAT"){
		cout<<1;
	}else{
		cout<<7;
	}
}

Measured memory_bytes: 3564
a, b = map(int, input().split())
string = []
strA = ""
strB = ""
for i in range(b):
    strA = strA + str(a)
string.append(strA)
for i in range(a):
    strB = strB + str(b)
string.append(strB)
string.sort()
print(string[0])


Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
n=int(input())
S=[input().strip() for _ in range(n)]
a=[]

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


from collections import Counter
for s in S:
    if s[0] in ["M","A","R","C","H"]:
        a.append(s[0])

if len(a)<=2:
    print(0)
    exit()

a=Counter(a)
#print(a)

asum=sum(a.values())
b=0
c=0
for i in a.values():
    if i ==1:
        continue
    if i==2:
        b+=asum-i
    if i>=3:
        b+=cmb(i,2)*(asum-i)
        c+=cmb(i,3)
print(cmb(asum,3)-b-c)


Measured memory_bytes: 57948
import java.util.Scanner;

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

        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();

        int divNum = 0;

        for (int i=a; i<=b; i++){
            if (c % i == 0)
                divNum += 1;
        }

        System.out.println(divNum);
    }
}

Measured memory_bytes: 26280
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace _0052
{
    class Program
    {
        static void Main(string[] args)
        {
            Factorial factorial = new Factorial();
            BigInteger n = 0;
            while ((n = BigInteger.Parse(Console.ReadLine())) != 0)
            {
                BigInteger numTotal = factorial.Factrial_N(n);
                Console.WriteLine(factorial.CountZero(numTotal));
            }
        }
    }
    class Factorial
    {
        public BigInteger Factrial_N(BigInteger n)
        {
            BigInteger answer = 1;
            if (n == 0)
            {
                return answer;
            }
            else
            {
                answer = n * Factrial_N(n - 1);
                return answer;
            }
        }
        public int CountZero(BigInteger answer)
        {
            int count = 0;
            while(answer%10==0)
            {
               answer = answer / 10;
               count++;
            }
            return count;
        }
    }
}



Measured memory_bytes: 45772
from itertools import permutations
import math
N = int(input())
xy = [tuple(map(int,input().split())) for _ in range(N)]
city = list(permutations(xy))
all_len = 0
for i in city:
  sum_len = 0
  for j in range(1,N):
    sum_len += ((i[j][0]-i[j-1][0])**2 +(i[j][1]-i[j-1][1])**2)**0.5
  all_len += sum_len
print(all_len/len(city))

Measured memory_bytes: 13996