akhauriyash/Code-Regression huggingface dataset:
N = int(input())
A = list(map(int, input().split()))

bar_length_count = dict()
for a in A:
    bar_length_count[a] = bar_length_count.get(a, 0) + 1

for val in bar_length_count.values():
    pass

count_at_least_2 = 0
for val in bar_length_count.values():
    if val >= 2:
        if val >= 4:
            count_at_least_2 += 2
        else:
            count_at_least_2 += 1

if count_at_least_2 < 2:
    import sys
    print(0)
    sys.exit(0)

else:
    bar_length_count = sorted({k:v for k, v in bar_length_count.items() if v >= 2}.items(), key=lambda x: x[0], reverse=True)
    if bar_length_count[0][1] >= 4:
        print(bar_length_count[0][0]**2)
    else:
        print(bar_length_count[0][0]*bar_length_count[1][0])
        

Measured memory_bytes: 18316
n=int(input())
h=list(map(int,input().split()))
dp=[]
dp.append(0)
dp.append(abs(h[1]-h[0]))
for i in range(2,n):
  dp.append(min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2])))
print(dp[n-1])

Measured memory_bytes: 13928
//Use valgrind once if the submission doesn't go through. It can detect uninitialized variables and see where they could be an issue.
#include <bits/stdc++.h>
using namespace std;
long long powe(long long a,long long b)
{
	if(b==0) return 1;
	else if(b&1) return a*powe(a,b-1);
	else
	{
		long long temp=powe(a,b/2);
		return temp*temp;
	}
}
bool isPrime(long long n)
{
	for(long long i=2;i<=ceil(sqrt(n));i++)
	{
		if(!(n%i))
		{
			return false;
		}
	}
	return n!=1;
}
int main(){

	ios_base::sync_with_stdio(false);
    	cin.tie(NULL);

	long long N;
	cin>>N;
	long long count=0;
	if(isPrime(N))
	{
		cout<<1<<endl;
		return 0;
	}
	for(long long i=2;i<=N;i++)
	{
		if(N%i) continue;
		for(long long j=1;!(N%powe(i,j));j++)
		{
			N/=powe(i,j);
			count++;
		}
		while(!(N%i))
		{
			N/=i;
		}
		if(isPrime(N))
		{
			count++;
			N=1;
		}
	}
	cout<<count<<endl;
	return 0;
}


Measured memory_bytes: 3696
#include<bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
//g++ -std=c++11 

using namespace std;
long long N;
string S;

int main(){
	cin >> N >> S;
	if(N % 2 == 0 && S.substr(0, N/2) == S.substr(N/2, N)) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 3616
import java.util.*;
import java.io.*;
class Main {

	
	
	public static void main(String[] args) throws IOException {
		Scanner sc=new Scanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int n=sc.nextInt(),k=sc.nextInt();
		int []a=new int [n];
		int idx=0;
		for(int i=0;i<n;i++)
		{
			a[i]=sc.nextInt();
			if(a[i]==1)
				idx=i;
		}
		int ans=n;
		int x=k-1;
		for(int i=Math.max(idx-k, 1)-1;i<Math.min(idx+k, n);i++)
		{
			int curr=1+(i+x-1)/x;
			int tmp=n-(i+k);
			curr+=(tmp+x-1)/x;
			ans=Math.min(ans, curr);
		}
		pw.println(ans);
		pw.close();
	}
	
	static class Scanner {
        StringTokenizer st;
        BufferedReader br;
 
        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }
 
        public Scanner(FileReader s) {
            br = new BufferedReader(s);
        }
 
        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }
 
        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
 
        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }
 
        public String nextLine() throws IOException {
            return br.readLine();
        }
        public boolean ready() throws IOException {return br.ready();}
        public double nextDouble() throws IOException {return Double.parseDouble(next());}
       
    }

}

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

mx = max(A)
cnt = [0] * 200

for i in A:
  cnt[i] += 1

inc = []
NN = mx + 1
while NN > 0:
  tm = min(2, NN)
  cnt[mx] -= tm
  # print(NN, cnt)
  if cnt[mx] < 0:
    print("Impossible")
    exit(0)
  inc.append(mx)
  mx -= 1
  NN -= tm

for i in inc[:-1]:
  cnt[i] = 0

for i in cnt:
  if i > 0:
    print("Impossible")
    exit(0)

print("Possible")


Measured memory_bytes: 3064
# include "iostream"
# include "cstdio"

using namespace std;

const int maxm=3000+10; 
int num[maxm],n,ans;

int main(){
	register int i; 
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&num[i]); 
		ans+=num[i]==0?0:num[i]-1; 
	}
	printf("%d",ans); 
	return 0; 
} 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.12f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 1010101;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dx[8] = { 1,-1,0,0,1,1,-1,-1 };
ll dy[8] = { 0,0,1,-1,1,-1,1,-1 };
char c[2010][2010];
ll sum[2010][2010];
ll sum2[2010][2010];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll h, w;
	cin >> h >> w;
	rep(i, h) {
		rep(j, w) {
			cin >> c[i][j];
		}
	}
	rep(i, h) {
		vector<ll>done(w);
		rep(j, w) {
			if (c[i][j] == '#')continue;
			if (done[j])continue;
			ll l = 0;
			while (l + j < w) {
				if (c[i][l + j] == '#')break;
				l++;
			}
			rep(k, l) {
				sum[i][j + k] += l;
				done[j + k] = 1;
			}
		}
	}
	rep(j, w) {
		vector<ll>done(h);
		rep(i, h) {
			if (c[i][j] == '#')continue;
			if (done[i])continue;
			ll l = 0;
			while (l + i < h) {
				if (c[i+l][j] == '#')break;
				l++;
			}
			rep(k, l) {
				sum[i + k][j] += l;
				done[i + k] = 1;
			}
		}
	}
	ll ans = 0;
	rep(i, h) {
		rep(j, w) {
			ans = max(ans, sum[i][j] - 1);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 38936
import sys

def solve():
    for line in sys.stdin:
        a, b = map(int, line.split())

        c = a + b

        if c == 0:
            print(1)
        else:
            ans = 0

            while c > 0:
                ans += 1
                c //= 10

            print(ans)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 7572
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long int
#define pb push_back
#define mk make_pair
#define flp(i, k, n) for(int i=k; i<n; i++)
#define rev(i, k) for(int i=k; i>=0; i--)
#define F first
#define S second
#define pi pair<int, int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int dx[4] = {-1,1,0,0};
int dy[4] = {0,0,-1,1};

bool sortcol( const vector<int>& v1, 
               const vector<int>& v2 ) { 
 return v1[1] < v2[1]; 
} 

int32_t main(void)
{
    int n, m, x;
    cin>>n>>m>>x;
    vector<vector<int>> a(n);
    flp(i, 0, n)
    {
        flp(j, 0, m+1)
        {
            int x;
            cin>>x;
            a[i].pb(x);
        }
    }

    sort(a.begin(), a.end(), sortcol);
    int ans=LLONG_MAX;
    for(int mask=1; mask<(1<<n); mask++)
    {
        int know[m]={0};
        int cur=0;
        for(int i=0; i<n; i++)
        {
            if(mask&(1<<i))
            {
                cur+=a[i][0];
                flp(j, 0, m)
                {
                    know[j]+=a[i][j+1];
                }
            }
        }

        int ct=0;
        flp(i, 0, m) 
        {
            if(know[i]>=x) ct++;
        }

        if(ct==m)
        {
            ans=min(ans, cur);
        }
    }
    if(ans==LLONG_MAX) ans=-1;
    cout<<ans<<"\n";
    
    return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

// j番目のホテルから2^i日以内に到達可能な最も右のホテル番号
// 2^17 = 131072
int r[18][100000];

int main()
{
    int n,L;
    cin >>n;
    vector<int> x(n);
    rep(i,n) scanf(" %d", &x[i]);
    cin >>L;

    rep(i,n) r[0][i]=upper_bound(all(x), x[i]+L)-x.begin()-1;
    for(int i=1; i<18; ++i)rep(j,n) r[i][j]=r[i-1][r[i-1][j]];

    int Q;
    cin >>Q;
    rep(q,Q)
    {
        int a,b;
        scanf(" %d %d", &a, &b);
        --a;
        --b;
        if(a>b) swap(a,b);

        int ans=0;
        int now=a;
        for(int i=17; i>=0; --i)
        {
            if(r[i][now]<b)
            {
                now=r[i][now];
                ans+=1<<i;
            }
        }
        if(now<b)
        {
            now=r[0][now];
            ++ans;
        }

        printf("%d\n", ans);
    }

    return 0;
}


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

using namespace std;

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

int main(){
    int n,v[10000];
    while(cin >> n){
        rep(i,n) cin >> v[i];
        sort(v,v+n,[](int x, int y){
                return y<x;
            });
        unsigned long long ans = 1;
        rep(i,n){
            ans += max(0,v[i]-i/4);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1172
S = input()

N = len(S)-1

for i in range(2**N):
    binary = bin(i)
    binary = binary[2:].zfill(N)
    
    sumsum = int(S[0])
    for j in range(N):
        if binary[j] == '0':
            sumsum -= int(S[j+1])
        else:
            sumsum += int(S[j+1])
        
            
    if sumsum == 7:
        ans = S[0]
        for j in range(N):
            if binary[j] == '0':
                ans += '-'
            else:
                ans += '+'
            ans += S[j+1]
        
        ans += '=7'
        break
    
print(ans)

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

public class Main {

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

		String s = br.readLine();
		String[] array = s.split("");

		for (int i = 0; i < s.length(); i++) {
			String x = array[i];
			if (x.equals(",")) {
				System.out.print(" ");
			} else {
				System.out.print(x);
			}
		}
		System.out.println("");
	}
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 998244353
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int sum=0,N,M,K;
DV(G,int,50,4,1);
Vec(Q,int,10,1);
void dfs(int C,vector<int>&Q){
  if(!C)rep(i,1,M+1){
    Q[C]=i;
    dfs(C+1,Q);
  }
  else if(N>C){
    rep(i,Q[C-1],M+1){
      Q[C]=i;
      dfs(C+1,Q);
    }
  }
  else{
    int num=0;
    rep(i,0,K)if(Q[G[i][1]-1]-Q[G[i][0]-1]==G[i][2])num+=G[i][3];
    chmax(sum,num);
  }
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,F,L,X,Y,Z,H,W,num=0,flag=0;string S,T;
  cin >> N >> M >> K;
  rep(i,0,K)rep(j,0,4)cin >> G[i][j];
  dfs(0,Q);
  Out(sum);
}

Measured memory_bytes: 3636
import java.util.*;
 
public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s=sc.next();
        for(int i=s.length()/2-1;i>0;i--){
            if(s.substring(0,i).equals(s.substring(i, i*2))){
                System.out.println(i*2);
                return;
            }
        }
    }
}

Measured memory_bytes: 23124
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<iomanip>
using namespace std;
int N;
vector<pair<int,int> >A;
double f(int x1,int y1,int x2,int y2)
{
	double a=atan2(y1,x1);
	double b=atan2(y2,x2);
	double x=abs(a-b)*180/M_PI;
	if(x>180)x=360-x;
	//cout<<"("<<x1<<", "<<y1<<") , ("<<x2<<", "<<y2<<") = "<<x<<endl;
	return x;
}
int main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		int a,b;cin>>a>>b;
		A.push_back(make_pair(a,b));
	}
	sort(A.begin(),A.end());
	double ans=1e9;
	do{
		double now=0;
		int px=A[0].first;
		int py=A[0].second;
		now+=f(1,0,px,py);
		for(int i=1;i<N;i++)
		{
			int x=A[i].first-A[i-1].first;
			int y=A[i].second-A[i-1].second;
			now+=f(px,py,x,y);
			px=x;
			py=y;
		}
		int x2=-A[N-1].first;
		int y2=-A[N-1].second;
		now+=f(px,py,x2,y2);
		ans=min(ans,now);
	}while(next_permutation(A.begin(),A.end()));
	cout<<fixed<<setprecision(16)<<ans<<endl;
}



Measured memory_bytes: 3540
n = int(input())
n_word = [input() for nesya in range(n)]
m = int(input())
m_word = [input() for motsu in range(m)]
ans = 0
for nn in n_word:
  point = n_word.count(nn) - m_word.count(nn)
  if point > ans:
    ans = point
print(ans)

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

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    int n;
    cin >> n;
    vector<ll> segments(n);
    rep(i, n) cin >> segments[i];
    ll total = accumulate(segments.begin(), segments.end(), 0ll);
    ll mi = INF;
    rep(i, n) {
        if (i != 0) segments[i] += segments[i - 1];

        ll a = segments[i];
        ll b = total - a;
        ll k = abs(a - b);
        cmin(mi, k);
    }
    cout << mi << endl;

}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 2147483647
#include <math.h> /* M_PI */
int main()
{
    ll a;
    long double b;
    cin >> a >> b;
    //double g = b * 100;
    //unsigned long long c = a * (ll)g;
    //unsigned long long data = floor(c / 100.0);
    long double data = a * b;
    //cout << (ll)floor(data) << endl;
    cout << (ll)floor(b * a) << endl;
}


Measured memory_bytes: 3732
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8

vector<LL> flg;
queue<int> que;
vector<int> vs;
inline void check(LL t){
	int u = t & 0xfffff;
	if((flg[u] >> 40) > (t >> 40)){
		vs.push_back(u);
	}
	if((flg[u] >> 40) >= (t >> 40) && flg[u] != t){
		flg[u] = t;
		que.push(u);
	}
}

void mainmain(){
	int n, m;
	scanf("%d%d", &n, &m);
	VV(LL) G(n + 1);
	for(int i = 0; i < m; ++i){
		LL p, q, c;
		scanf("%lld%lld%lld", &p, &q, &c);
		G[p].push_back(c << 20 | q);
		G[q].push_back(c << 20 | p);
	}
	for(int i = 1; i <= n; ++i){
		sort(ALL(G[i]));
	}

	flg.assign(n + 1, LLONG_MAX);
	flg[1] = 1;
	vector<LL> nxt;
	vs.push_back(1);
	for(LL tm = 1; !vs.empty(); ++tm){
		nxt.clear();
		for(int u : vs){
			for(LL e : G[u]){
				nxt.push_back(tm << 40 | e);
			}
		}
		sort(ALL(nxt));
		vs.clear();
		for(LL t : nxt){
			LL comflag = t & 0xfffff00000;
			check(t);
			while(!que.empty()){
				int u = que.front();
				que.pop();
				auto it = lower_bound(ALL(G[u]), comflag);
				for(; it != G[u].end(); ++it){
					if((*it & 0xfffff00000) != comflag){ break; }
					LL f = tm << 40 | *it;
					check(f);
				}
			}
		}
	}
	LL ans = (flg[n] == LLONG_MAX ? -1LL : flg[n] >> 40);
	cout << ans << endl;
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


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

int main(){
    int n, p;
    cin >> n;
    int a[n];
    int sum = 0;
    for(int i = 0; i < n; i ++){
        cin >> a[i];
        sum += a[i];
    }
    cin >> p;
    for(int i = 0; i < p; i++){
        int j, v;
        cin >> j >> v;
        cout << sum - a[j - 1] + v << endl;
    }
    return 0;
}

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

vector<long>v;
long long n,k,x,ans;

int main(){
//	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>x;
		v.push_back(x);
	}
	sort(v.rbegin(), v.rend());
	for(int i=k;i<n;i++){
		ans+=v[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate nPm
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n, k, x, y; cin >> n >> k >> x >> y;
    k--;
    int ans = 0;
    rep(i, n) {
        if (i <= k) ans += x;
        else ans += y;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  ll N;
  cin >> N;
  cout << N*N*N << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int i;
    int a, b;
    long ans = 1;
    scanf("%d%d", &a, &b);
    i = 2;
    while(1){
        if(a % i == 0 || b % i == 0){
            if(a % i == 0) a /= i;
            if(b % i == 0) b /= i;
            ans *= i;
        }else{
            i++;
        }
        if(a == 1 && b == 1) break;
    }
    printf("%ld\n", ans);
    return 0;
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 1
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

#define P pair<lli,lli>

signed main(){

	lli n,k;
	cin>>n>>k;

	vector<lli> a(n);
	lli sum = 0;
	REP(i,0,n){
		cin>>a[i];
		sum+=a[i];
	}

	priority_queue<lli> yaku;
	for(lli i=1;i*i <= sum;i++){
		if(sum%i==0){
			yaku.push(i);
			if(sum/i!=i)yaku.push(sum/i);
		}
	}

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

	lli small=1,large = 1e10;

	while(yaku.size()){
		lli top = yaku.top();
		yaku.pop();
		vector<lli> b(n);
		REP(i,0,n)b[i] = a[i]%top;
		sort(b.begin(),b.end());

		lli cnt = 0;
		lli left = 0,right = n-1;
		while(left<right){
			lli num = b[left];
			b[left] = 0;
			cnt += num;
			left++;
			while(num > top - b[right]){
				num -= (top-b[right]);
				b[right] = 0;
				right--;
			}
			b[right] += num;
		}
		if(cnt <= k){
			cout<<top<<endl;
			return 0;
		}
	}
	cout<<1<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int main() {
  int t, x;
  cin >> t >> x;
  printf("%.10f\n", (double)t / x);

  return 0;
}

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

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int N;
	cin >> N;
	N++;
	int tab[N];
	for (int i = 0 ; i < N ; i++)
	{
		cin >> tab[i];
	}
	int nbActu = 0;
	int tot = 1;
	for (int i = N -1 ; i >= 0 ; i--)
	{
		nbActu = (nbActu + 1)/ 2 + tab[i];
		tot += nbActu;
	}
	if (nbActu > 1)
	{
		cout<<-1<<endl;
	}
	else
	{
		int nbMax[N];
		int actu = 0;
		for (int i = N - 1 ; i >= 0 ; i--)
		{
			actu += tab[i];
			nbMax[i] = actu;
		}
		actu = 1;
		nbMax[0] = 1;
		for (int i = 1 ; i  < N ; i++)
		{
			actu *= 2;
			nbMax[i] = min(nbMax[i] , actu);

			actu -= tab[i];
			if (actu >= 1e16) break;
		}
		int nb = 0;
		for (int i = 0 ; i < N ; i++) nb += nbMax[i];
		cout<<nb<<endl;
	}
}

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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int>> G(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    rep(i, n) {
        cout << G.at(i).size() << endl;
    }
    return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <cstring>
# include <vector>
# include <cmath>
# include <sstream>
# include <algorithm>
using namespace std;

int main(){
	vector<long long> v(3);
	for(int i=0;i<v.size();i++)
		cin >> v[i];

	sort(v.begin(), v.end());
	for(int i=0;i<v.size();i++){
		if(v[i] % 2 == 0){
			cout << 0 << endl;
			return 0;
		}
	}
	cout << v[0]*v[1] << endl;
	return 0;
}

Measured memory_bytes: 256
#!python3.8
# -*- coding: utf-8 -*-
# abc175/abc175_a
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    S = i2s()
    if 'RRR' == S:
        print(3)
    elif 'RR' in S:
        print(2)
    elif 'R' in S:
        print(1)
    else:
        print(0)
    return


main()


Measured memory_bytes: 9020
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    int ans = 0;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        ans += min(2*x, 2*abs(x-k));
    }
    cout << ans << endl;
    return 0;
}


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


int main(){
  int a,b,c,x,y;
  cin >> a >> b >> c >> x >> y;
  ll ansab=0;
  ll ansabc=0;
  ll ansc=0;
  ansab=a*x+b*y;
  int mi=min(x,y);
  ansabc=mi*2*c;
  if(x>mi){
    ansabc+=(x-mi)*a;
  }else{
    ansabc+=(y-mi)*b;
  }
  int ma=max(x,y);
  ansc=ma*2*c;
  ll ansmi=min(ansab,ansabc);
  ll cal=min(ansmi,ansc);
  cout << cal << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
import math
def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
n = II()
a = LI()
s = a[0]
for i in a[1:]:
	s^=i
ans = []
for i in range(n):
	ans.append(s^a[i])
print(*ans)

Measured memory_bytes: 31608
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
vector<int>vec;
int dp[1000005][2];
int main(){
    for(int i=1;;i++){
        int x = i*(i+1)*(i+2)/6;
        if(x > 1000000) break;
        vec.push_back(x);
    }
    rep(i,1000005) dp[i][0] = dp[i][1] = 1e9;
    dp[0][0] = dp[0][1] = 0;
    for(int i=0;i<vec.size();i++){
        for(int j=0;j<=1000000;j++){
            if(j+vec[i] <= 1000000) dp[j+vec[i]][0] = min(dp[j+vec[i]][0],dp[j][0]+1);
            if(vec[i]%2==1 && j+vec[i] <= 1000000) dp[j+vec[i]][1] = min(dp[j+vec[i]][1],dp[j][1]+1);
        }
    }
    while(1){
        int n; cin>>n; if(n==0) return 0;
        cout << dp[n][0] << " " << dp[n][1] << endl;
    }
}



Measured memory_bytes: 10940
#! /usr/bin/env python3
import math
N, M = map(int, input().split())
n = math.factorial(N)
m = math.factorial(M)
if N == M:
    print(n * m * 2 % (10**9+7))
elif abs(N - M) > 1:
    print(0)
else:
    print(n * m % (10**9+7))

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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
typedef vector<vector<int>> VV;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define PRALL(a) a.begin(),a.end(),greater<pair<int,int>>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/

int main(){
    int n;
    string s;cin>>s;
    n=(int)s.size();
    int even=0;
    rep(i,n){
        if(i%2==0){
            if(s[i]!='1')even++;
        }else{
            if(s[i]!='0')even++;
        }
    }
    int odd=0;
    rep(i,n){
        if(i%2==0){
            if(s[i]!='0')odd++;
        }else{
            if(s[i]!='1')odd++;
        }
    }
    cout<<min(even,odd)<<endl;
}


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

int n;
int g[200][200];

int main(){
	cin >> n;
	for (int i = 0; i < n; i++){
		int a, b;
		string s;
		cin >> a >> s >> b;
		a--; b += 99;
		if (s == "lock") g[a][b] = 1;
		if (s == "wait") g[b][a] = 1;
	}

	for (int k = 0; k < 200; k++){
		for (int i = 0; i < 200; i++){
			for (int j = 0; j < 200; j++){
				g[i][j] |= g[i][k] & g[k][j];
			}
		}
	}

	int res = 0;
	for (int i = 0; i < 200; i++) res |= g[i][i];

	cout << res << endl;
}

Measured memory_bytes: 3356
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);

			while (sc.hasNext()) {
				int price = sc.nextInt();
					if (price == 0) break;
					
				System.out.println(CountChange(1000 - price));
			}


	}

	public static int CountChange(int p) {
		int[] coins = {500, 100, 50, 10, 5, 1};
		int cntcng = 0;
		
			for (int c : coins) {
				cntcng += p / c;
				p %= c;
			}

		return cntcng;

	}

}



Measured memory_bytes: 26056
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;


    void solve()
    {
        int N = cin.nextint;
        var C = new int[N];

        var J = new bool[N];
        var A = new int[N + 1];
        var B = new int[N];


        for (int i = 0; i < N; i++)
        {
            C[i] = cin.nextint;
            A[C[i]] = A[C[i] - 1] + 1;
        }

        //WriteLine(string.Join(" ", A));

        WriteLine(N - A.Max());


        //var X = lis(C);
        //Array.Reverse(C);
        //var Y = lis(C);

        //WriteLine(X + " " + Y);


        //WriteLine(N - lis(C));
    }

    int lis(int[] A)
    {
        var dp = new int[A.Length];
        for (int i = 0; i < A.Length; i++)
        {
            dp[i] = int.MaxValue;
        }
        foreach (var i in A)
        {
            dp[lower_bound(dp, i)] = i;
        }

        return lower_bound(dp, int.MaxValue);
    }
    int lower_bound(int[] arr, int val)
    {
        int low = 0, high = arr.Count();
        int mid;

        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (arr[mid] < val) low = mid + 1;
            else high = mid;
        }
        return low;
    }
}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}


Measured memory_bytes: 17736
import scala.io.StdIn.{readInt, readLine};
import scala.reflect.ClassTag;
object Main {
    def main(args: Array[String]): Unit = {
        val n = readInt;
        val set = new OriginalSet[String](1000000);
        (0 until n).foreach { i =>
            readLine.split(" ") match {
                case Array("insert", key) => set.insert(key);
                case Array("find", key) => if (set.find(key) == true) println("yes") else println("no");
            }
        }
    }
}

class OriginalSet[A](size: Int)(implicit m: ClassTag[List[A]]) {
    val set = m.newArray(size);
    def insert(key: A): Unit = {
        val index = (key.hashCode & Int.MaxValue) % size;
        if (set(index) == null) {
            set(index) = List(key);
        } else {
            if (! set(index).exists(_ == key)) set(index) = key :: set(index);
        }
    }
    
    def find(key: A): Boolean = {
        val index = (key.hashCode & Int.MaxValue) % size;
        if (set(index) == null) {
            false;
        } else {
            if (set(index).exists(_ == key)) true else false;
        }
    }
}


Measured memory_bytes: 506092
MOD = 10**9+7
N,K = map(int, input().split())
red, blue = N-K, K
ai = red+1
print(ai)
for i in range(2,blue+1):
    ai = ai * (red-i+2) * (blue-i+1) // (i*(i-1))
    print(ai%MOD)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N; cin>>N;
    vector<int> A(N);
    rep(n,0,N) cin>>A.at(n);

    int64_t ans=1;
    vector<int> V(3,0);
    rep(i,0,N){
        int cnt=0,idx;
        rep(j,0,3){
            if(A.at(i)==V.at(j)){
                cnt++;
                idx=j;
            }
        }

        if(!cnt){
            cout<<0<<endl;
            return 0;
        }

        ans*=cnt;
        ans%=MOD;
        V.at(idx)++;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 640
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#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>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
//typedef pair<ll, ll> P;
//typedef pair<ll, pair<ll, ll>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
const ll MOD = 1e9 + 7;
//ll MOD  = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll x, ll y){return x / gcd(x, y) * y;};


int main(void){
  int a;
  cin >> a;
  cout << 3 * a * a << endl;






}


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

ll mod = 1e9+7;

int main(){
	
	ll n;
	cin >> n;

	vector<ll> v(n);

	ll sum = 0, ans = 0;
	for(int i = 0; i < n; i++){
		cin >> v[i];
		sum += v[i];
	} 


	for(int i = 0; i < n; i++){
		ans += ((sum - v[i])%mod * v[i]%mod)%mod; 
		sum -= v[i];
	}

	cout << ans%mod << "\n";
	
}

Measured memory_bytes: 4824
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
ll N;

int main() {
  cin >> N;

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

  ll X = N / 2;
  ll ans = 0;
  while (X / 5 > 0) {
    ans += X / 5;
    X /= 5;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<node> li = new ArrayList<node>();
        for(int i = 0; i < n; i++){
            int x = sc.nextInt();
            int y = sc.nextInt();
            node nd = new node(x,y);
            li.add(nd);
        }
        Boolean[] bools = new Boolean[n];
        Arrays.fill(bools,false);
        double ans = 0;
        for(int i = 0 ; i < n; i++){
            bools[i] = true;
            ans += totalLength(li,bools,i,(double)0);
            bools[i] = false;
        }
        System.out.println(ans/totalDivide(n));
    }
    
    private static double totalLength(List<node> li, Boolean[] bools, int now, double len){
        if(!Arrays.asList(bools).contains(false)){
            return len;
        }
        double ans = 0;
        for(int i = 0; i < li.size(); i++){
            if(bools[i]){
                continue;
            }
            double tmp = Calc2Roads(li.get(now), li.get(i));
            bools[i] = true;
            len += tmp;
            ans += totalLength(li,bools,i,len);
            bools[i] = false;
            len -= tmp;
        }
        return ans;
    }

    private static double totalDivide(int n){
        double ret = 1;
        for(int i = 1; i <= n; i++){
            ret *= i;
        }
        return ret;
    }

    private static double Calc2Roads(node n1,node n2){
        double x = Math.abs(n1.getX()-n2.getX());
        double y = Math.abs(n1.getY()-n2.getY());
        double len = Math.pow(x,2) + Math.pow(y,2);
        return Math.pow(len, 0.5);
    }
}

class node{
    private int x,y;
    public node(int x, int y){
        this.x = x;
        this.y = y;
    } 
    public int getX(){
        return this.x;
    }
    public int getY(){
        return this.y;
    }
}

Measured memory_bytes: 25260
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace TestApp
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var str = int.Parse(Console.ReadLine());
                var str2 = int.Parse(Console.ReadLine());
                var i = Math.Pow(str, 2);
                var j = Math.Pow(Math.Pow(str2, 2) + Math.Pow(0.5*str, 2),0.5) * str * 0.5;
                if (str == 0 && str2 == 0)
                    break;
                Console.WriteLine(i + 4*j);
            }
        }
         
    }
 
}




Measured memory_bytes: 9476
def main():
  data = []

  for _ in range(5):
    data.append(int(input()))

  # 10の倍数から1番離れてる数がどれか
  min = 99
  margin = []
  for d in data:
    tmp = d % 10
    if tmp != 0:
      margin.append(10 - tmp)
    if tmp != 0 and min > tmp:
      min = tmp

  # 0対策
  if min == 99:
    print(sum(data) + sum(margin))
    return

  # print(data)
  # print(margin)
  # print(min)
  print(sum(data) + sum(margin) - (10-min))

if __name__ == "__main__":
  main()


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

        if(a.equals("Sunny")){
            System.out.println("Cloudy");
        }
        if(a.equals("Cloudy")){
            System.out.println("Rainy");
        }
        if(a.equals("Rainy")){
            System.out.println("Sunny");
        }


    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
const ll inf=174417444174;
vector<ll> wn,tn,w_s,ts;
ll cn[15],bn[15];
ll dp[1<<15]={0};
ll m,n;

ll get_ans(int count,int idx){
  ll c_max=cn[idx]+w_s[count];
  int a1=upper_bound(w_s.begin(),w_s.end(),c_max)-w_s.begin()-1;
  ll b_max=bn[idx]+ts[count];
  int a2=upper_bound(ts.begin(),ts.end(),b_max)-ts.begin()-1;
  return min(a1,a2);
}

int main(){
  cin>>m>>n;
  wn.push_back(0);
  tn.push_back(0);
  w_s.push_back(0);
  ts.push_back(0);
  for(int i=1;i<=m;i++){
    ll w,t;
    cin>>w>>t;
    wn.push_back(w);
    tn.push_back(t);
    w_s.push_back(w_s[i-1]+w);
    ts.push_back(ts[i-1]+t);
  }
  w_s.push_back(inf);
  ts.push_back(inf);

/*
  int k,cc;
  cin>>k>>cc;
  cout<<upper_bound(w_s.begin(),w_s.end(),k+w_s[cc])-w_s.begin()<<endl;
  return 0;
  */

  for(int i=0;i<n;i++){
    cin>>cn[i]>>bn[i];
  }

  for(int i=0;i<(1<<n)-1;i++){
    for(int j=0;j<n;j++){
      if(((i>>j)&1)==0){
        int nb=(i|(1<<j));
      //  cout<<i<<" "<<j<<" "<<nb<<endl;
        dp[nb]=max(dp[nb],get_ans(dp[i],j));
      }
    }
  //  cout<<i<<" "<<dp[i]<<endl;
  }
  cout<<dp[(1<<n)-1]<<endl;
}



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

int main(){
  int N;
  cin>>N;
  int sum=0;
  vector<int> B(N-1);
  for(int i=0;i<N-1;i++){
    cin>>B.at(i);
  	if(i==0)
      sum+=B.at(i);
    else
      sum+=min(B.at(i),B.at(i-1));
  }
  sum+=B.at(N-2);
  cout<<sum<<endl;
}

Measured memory_bytes: 256
S = input()
Q = int(input())
reverseFlag = False
forwardList = []
backwardList = []
for i in range(Q):
    tmp = input()
    if tmp[0] == '1':
        reverseFlag = not reverseFlag
    else:
        tmpt, tmpf, tmpc = tmp.split(' ')
        if tmpf == '1' and reverseFlag == False or tmpf == '2' and reverseFlag == True:
            forwardList.append(tmpc) 
        else:
            backwardList.append(tmpc)

if reverseFlag == True:
    S = ''.join(reversed(backwardList)) + S[::-1] + ''.join(forwardList)
else:
    S = ''.join(reversed(forwardList)) + S + ''.join(backwardList)
print(S)

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

int main()
{
  string s;
  string t;
  int count=0;
  
  cin>>s>>t;
  
  for(int i=0;i<3;i++)
  {
    if(s[i]==t[i])
    {
      count++;
    }
  }
  
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<iomanip>

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

#define debug(x) cout<<(#x)<<"="<<(x)<<", ";
#define debug1(x) debug(x) cout<<'\n';
#define debug2(x1, x2) debug(x1) debug(x2) cout<<'\n';
#define debug3(x1, x2, x3) debug(x1) debug(x2) debug(x3) cout<<'\n';
#define debug4(x1, x2, x3, x4) debug(x1) debug(x2) debug(x3) debug(x4) cout<<'\n';
#define debug5(x1, x2, x3, x4, x5) debug(x1) debug(x2) debug(x3) debug(x4) debug(x5) cout<<'\n';

#define fcout cout<<fixed<<setprecision(15)
#define repp(i,j,k) for(int i=j; i<k; ++i)
#define rep(i,j) repp(i,0,j)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<int, int, lli> tiil;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;

int main(){
	fast_io
	string s,t; cin>>s>>t;
	int k=0;
	rep(i,3){
		if(s[i]==t[i]) k++;
	}
	cout<<k;
	return 0;
}

Measured memory_bytes: 256
import sys

s = list(sys.stdin.readline().strip())
K = int(sys.stdin.readline().strip())

i = 0
while i < len(s):
    if K == 0:
        break

    # 最後の文字の場合は限界まで操作する
    if i == len(s) - 1:
        n = (ord(s[i]) - ord("a") + K) % 26
        # print(n)
        s[i] = chr(ord("a") + n)
        break

    if s[i] == "a":
        i += 1
        continue

    # それ以外の場合、aにできるなら操作する
    # aに変換するまでの操作回数
    n = 26 - (ord(s[i]) - ord("a"))
    # print(n)
    if n <= K:
        s[i] = "a"
        K -= n

    i += 1

print("".join(s))

Measured memory_bytes: 71940
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include <fstream>
using namespace std;
typedef long long ll;
const ll INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int mod = 1e9+7;
const int maxn = 200005;
ll T,n,m;
int main() {
	cin>>n>>m;
	if(n*500>=m)
		cout<<"Yes\n";
	else 
		cout<<"No\n"; 
    return 0;
}



Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int ans=0;
    for(int i=1;i<n;i++)
        {
        	int cnt=0;
        	for(char c='a';c<='z';c++)
        	      {
        	      	bool L=false,R=false;
        	      	for(int j=0;j<i;j++)
        	      	    if(s[j]==c)
        	      	        L=true;
        	      	for(int j=i;j<n;j++)
        	      	    if(s[j]==c)
        	      	        R=true;
        	      	if(L&&R)
        	      	    cnt++;
				  }
			if(ans<cnt)
			    ans=cnt;
		}
    cout<<ans<<endl;
}


Measured memory_bytes: 256