akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a,b = map(int,input().split())
x = 0
y = 0
z = 0
P = list(map(int,input().split()))

for i in range(n):
    if P[i]<= a:
        x += 1
    elif P[i] <= b:
        y += 1
    else:
        z += 1

print(min(x,y,z))

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

int main() {
  int A, B;
  cin >> A >> B;
  if (A >= 13) {
    cout << B << endl;
  } else if (A >= 6) {
    cout << B/2 << endl;
  } else {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 3632
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;

#define house second
#define time first
const int INF = 0xfffffff;

template<class T> inline void chmin(T& a, T b) { if(b < a) a = b; }

struct edge {
	int to, cap, rev;
	edge(int t, int c, int r):to(t), cap(c), rev(r){}
};

vector<vector<edge> > G;
vector<int> level;
vector<int> iter;

void init(int n) {
	G.clear();
	G.resize(n);
	level.clear();
	level.resize(n);
	iter.clear();
	iter.resize(n);
}

void add_edge(int from, int to, int cap) {
	G[from].push_back(edge(to, cap, G[to].size()));
	G[to].push_back(edge(from, 0, G[from].size() - 1));
}

void bfs(int s) {
	fill(level.begin(), level.end(), -1);
	queue<int> que;
	level[s] = 0;
	que.push(s);

	while(!que.empty()) {
		int v = que.front();
		que.pop();

		for(int i = 0; i < G[v].size(); ++i) {
			const edge& e = G[v][i];
			if(e.cap > 0 && level[e.to] < 0) {
				level[e.to] = level[v] + 1;
				que.push(e.to);
			}
		}
	}
}

int dfs(int v, int t, int f) {
	if(v == t)
		return f;

	for(int& i = iter[v]; i < G[v].size(); ++i) {
		edge& e = G[v][i];
		if(e.cap > 0 && level[v] < level[e.to]) {
			int d = dfs(e.to, t, min(f, e.cap));
			if(d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}

	return 0;
}

int max_flow(int s, int t) {
	int flow = 0;

	for(;;) {
		bfs(s);
		if(level[t] < 0)
			return flow;

		fill(iter.begin(), iter.end(), 0);
		int f;
		while((f = dfs(s, t, INF)) > 0)
			flow += f;
	}
}

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

	for(int n, m, l; cin >> n >> m >> l, n | m | l;) {
		vector<vector<int> > mat(n, vector<int>(n, INF));
		for(int i = 0; i < n; ++i)
			mat[i][i] = 0;
			
		for(int i = 0; i < m; ++i) {
			int u, v, d;
			cin >> u >> v >> d;
			mat[u][v] = mat[v][u] = d;
		}

		for(int i = 0; i < n; ++i)
			for(int j = 0; j < n; ++j)
				for(int k = 0; k < n; ++k)
					chmin(mat[j][k], mat[j][i] + mat[i][k]);

		vector<pair<int, int> > p(l);
		for(int i = 0; i < l; ++i)
			cin >> p[i].house >> p[i].time;

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

		init(l * 2 + 2);
		const int s = l * 2, t = l * 2 + 1;
		for(int i = 0; i < l; ++i) {
			add_edge(s, i, 1);
			add_edge(i + l, t, 1);

			for(int j = i + 1; j < l; ++j) {
				if(p[i].time + mat[p[i].house][p[j].house] <= p[j].time)
					add_edge(i, j + l, 1);
			}
		}

		cout << l - max_flow(s, t) << endl;
	}

	return EXIT_SUCCESS;
}

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

int main(){
  int h,w;
  cin >> h >> w;
  char f[50][50];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> f[i][j];
    }
  }
  string ans;
  int count;
  int houkou[8][2]={
    {-1,-1},
    {-1,0},
    {-1,1},
    {0,-1},
    {0,1},
    {1,-1},
    {1,0},
    {1,1}
  };
  int x,y;
  for(int i=0;i<h;i++){
    ans="";
    for(int j=0;j<w;j++){
      if(f[i][j]=='.'){
        count = 0;
        for(int k=0;k<8;k++){
          x=i+houkou[k][0];
          y=j+houkou[k][1];
          if(x<0||x>=h||y<0||y>=w){
            x=i;
            y=j;
          }
          if(f[x][y]=='#'){
            count++;
          }
        }
        ans.push_back('0'+count);
      }else{
        ans.push_back('#');
      }
    }
    cout << ans << endl;
  }


  return 0;
}


Measured memory_bytes: 256
n = input()

if n[-1] == '2' or n[-1] == '4' or n[-1] == '5' or n[-1] == '7' or n[-1] == '9':
    print('hon')
elif n[-1] == '0' or n[-1] == '1' or n[-1] == '6' or n[-1] == '8':
    print('pon')
else:
    print('bon')
    


Measured memory_bytes: 9044
N,K,Q=map(int,input().split())
Qlist = [int(input()) for i in range(Q)]
Plist = [0]*N

for i in range(Q):  
  Plist[Qlist[i]-1] += 1

for i in range(N):
  if Plist[i]-Q+K > 0:
    print('Yes')
  else:
    print('No')
  

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

using namespace std;

int main() {
    int k=0;
    char x,y,z;
    cin>>x>>y>>z;
    if((x=='A' && y=='A' && z=='A')||(x=='B'&& y=='B'&&z=='B'))
    {
        cout<<"No";
    }
    else{
        cout<<"Yes";
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const ll MOD = 1e9 + 7;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")


int main() {

    ll n,k; cin >> n >> k;
    string s; cin >> s;
    ll ans = 0,count = 0;

    rep(i,n-1){
        if(s[i] == s[i+1]) ans ++;
        else if(s[i] == 'R' && s[i+1] == 'L')count ++;
    }

    if(count == 1) cout << ans + 1;
    else if(k >= count + 1) cout << (ans + 2*(count) + ((s[0] != s[n-1])?1:0));
    else cout << ans + 2*(k);

}


Measured memory_bytes: 3768
#include <iostream>
#include <iomanip>
#include <fstream>

#include <cmath>
#include <string>

#include <algorithm>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

vector<int> poss;
int dp[100005];

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

	int n, k, a, m;
	cin >> k >> n;
	m = n+1;
	for (int i = 0; i < k; i++) {
		cin >> a;
		poss.push_back(a);
		m = min(m, a);
	}

	for (int i = 0; i < m; i++) dp[i] = 0;

	for (int i = m; i < n+1; i++) {
		dp[i] = 0;
		for (int j = 0; j < k; j++) {
			if (i - poss[j] >= 0) {
				if (dp[i - poss[j]] == 0) dp[i] |= 1;
			}
		}
	}

	if (dp[n]) cout << "First" << endl;
	else cout << "Second" << endl;

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

signed main() {
    int N, X, Y;
    cin >> N >> X >> Y;

    cout << min(X, Y) << " " << max(0LL, X + Y - N) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
# define pb push_back
# define FOR(i,a,n) for(int i=a;i<n;i++)
# define mp make_pair
# define RFOR(i,a,n) for(int i=n;i>a;i--)
# define pii pair<long long int,long long int>
#define ub upper_bound
#define lb lower_bound
#define MOD 1000000007
typedef long long int ll;
ll g[100009][3];
ll vec[100009][3];
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll n;
	cin>>n;
	ll a;
	
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
		{
			cin>>a;
			vec[i][j]=a;
		}
	}
	for(int j=0;j<3;j++)
	g[n-1][j]=vec[n-1][j];
	for(int i=n-1;i>=0;i--)
	{
		for(int j=0;j<3;j++)
		{
			if(j==0)
			{
				g[i][j]=max(vec[i][j]+g[i+1][1],vec[i][j]+g[i+1][2]);
			}
			else if(j==1)
			{
				g[i][j]=max(vec[i][j]+g[i+1][0],vec[i][j]+g[i+1][2]);
			}
			else if(j==2)
			{
				g[i][j]=max(vec[i][j]+g[i+1][1],vec[i][j]+g[i+1][0]);
			}
		}
	}
	cout<<max(g[0][1],max(g[0][2],g[0][0]))<<endl;
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;


void lower_atc()
{
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; ++i) cin >> h[i];

  int tmp = 0, v_max = 0;
  for (int i = 0; i < n; ++i)
  {
    if ((i != n - 1) && h[i] >= h[i + 1]) ++tmp;
    else
    {
      v_max = max(v_max, tmp);
      tmp = 0;
    }
  }

  cout << v_max << "\n";
}


void maximal_value()
{
  int n;
  cin >> n;
  vector<int> b(n - 1);
  for (int i = 0; i < n - 1; ++i) cin >> b[i];

  vector<int> a(n);
  for (int i = 0; i < n; ++i)
  {
    if (i == 0)          a[i] = b[i];
    else if (i == n - 1) a[i] = b[i - 1];
    else                 a[i] = min(b[i - 1], b[i]);
  }

  cout << accumulate(a.begin(), a.end(), 0) << "\n";
}

int main()
{
  lower_atc();
  //maximal_value();
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include<cstring>
#include<stdio.h>
using namespace std;
const int MAX = 200000 + 5;
int X[MAX]; int minN = 9999999;
int cmp(const void *a, const void *b)
{
	return *(char *)a - *(int *)b;
}
int  main() {
	int N = 0, cnt = 0; int num = 0;
	cin >> N;
	while (N--) {
		cin >> X[++cnt];
	}
	for (int i=1;i<=cnt;i++)
	{
		if (X[i] < minN) {
			num++; minN = X[i];

		}

	}
	cout << num;
	return 0;

}

Measured memory_bytes: 1024
import java.io.PrintWriter

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val n = readInteger()
    val aList = readLongList()

    if (aList.contains(0L)) {
        println(0)
        return
    }

    var tmp = 1000000000000000000
    var ans = 1L
    for (a in aList) {
        if (tmp / ans < a) {
            println(-1)
            return
        } else {
            ans *= a
        }
    }

    println(ans)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)
// while (getline(cin, S)) {}

// cout <<fixed <<setprecision(10)

// priority_queue<int> q;
// priority_queue<int, vector<int>, less<int>> q; // Default: vector, less
// priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> q;

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

//
// Notes
//
// When specified less than N, try full scan.
// RE: empty vector
// Check Qs
// long/int
// xor -> count each bit
// Check values
// 	1,000,000 -> Loop
// 	100,000	-> vector(int:400KB, long:800KB) 

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

#define	Rep0(i, n)	for (int i=0; i<n; i++)
#define	Rep1(i, n)	for (int i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	string a, b, c;
	cin >>a >>b >>c;
	cout <<(char)(a.at(0)-'a'+'A') <<(char)(b.at(0)-'a'+'A') <<(char)(c.at(0)-'a'+'A') <<endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
	int n;
	cin >> n;
	cout<<800 * n - 200 * (n / 15)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define pi acos(-1)
#define pii pair<int,int>
const int INF = 0x3f3f3f3f;
const double eps = 1e-12;
const int MAXN = 1e5 + 10;
const int MAXM = 1e6 + 10;
const ll mod = 1e9 + 7;



int main()
{
#ifdef local
    freopen("data.txt","r",stdin);
//    freopen("data.txt","w",stdout);
#endif
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    printf("%d\n",min(a,b)+min(c,d));
    return 0;
}


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

#define int long long
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()

const int mod = 1e9+7;
const int inf = 2e18;

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

	int k;
	cin>>k;
	int sum = 0;

	for(int i=1;i<=k;i++)
	{
		for(int j=1;j<=k;j++)
		{
			for(int l=1;l<=k;l++)
			{
				sum+=(__gcd(i,__gcd(j,l)));
			}
		}
	}
	cout<<sum<<'\n';
	return 0;
}	

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < (int)n;i++)
#define repb(i, n) for(int i = (int)n;i >= 0;i--)
#define reps(i, m, n) for(int i = (int)m;i < (int)n;i++)
#define repsb(i, m, n) for(int i = (int)m;i >= (int)n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long ll;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
using namespace std;
int main(int argc, char const *argv[]) {
  int n,temp;
  cin>>n;
  temp=n;
  rep(i,n+1){
      int t=i,ans=0;
      while(t>0)  ans+=t%6,t/=6;
      t=n-i;
      while(t>0)  ans+=t%9,t/=9;
      temp=min(temp,ans);
  }
  cout << temp << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int N,count=1,k;
	cin>>N;
	int A[N];
	for(int i=0;i<N;i++){
		cin>>A[i];
	}
	k=A[0];
	for(int i=0;i<N-1;i++){
		if(A[i+1]>=k){
			k=A[i+1];  
			count=count+1;
		}
	}
	cout<<count<<endl;
}

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

int main(){
  int n,k,q;
  cin >> n >> k >> q;

  int sum = max(0,q-k+1);
  vector<int> vec(n);

  for (int i = 0; i < q; i++)
  {
    int a;
    cin >> a;

    vec[a-1]++;
  }

  for (int i = 0; i < n; i++)
  {
    if(vec[i]>=sum) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  
  
}

Measured memory_bytes: 1024
// " In the Name of God, the Beneficent, the Merciful "
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 10;
int n, a[N];
bool isOk;

void input() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}				
	sort(a, a + n);
}

void check1() {
	int t = a[0];
	if (t == n - 1 || 2 * t <= n)
		isOk = true;	
}

void check2() {
	int minn = a[0], maxx = a[n - 1];
	
	if (maxx - minn > 1) {
		cout << "No";
		exit(0);
	}
	
	int cmax = 0, cmin = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] == maxx)
			cmax++;
		else
			cmin++;	
	}
	
	if ((2 * (maxx - cmin)) <= cmax && maxx - cmin > 0)
		isOk = true;
	
}

int main() {
	ios:: sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
	
	input();
	if (a[n - 1] == a[0])
		check1();
	else
		check2();	
	
	if(isOk)
		cout << "Yes";
	else
		cout << "No";	
		
	
	return 0;
}


Measured memory_bytes: 768
#include <stdio.h>
#include <iostream>
#include <cstring>
#define lch (x<<1)
#define rch ((x<<1)|1)
typedef long long ll;
const int N=100005;
int n,m;
ll mn[N<<2],tag[N<<2];
using namespace std;

void modify(int x,ll v){tag[x]+=v,mn[x]+=v;}
void updtag(int x){if (tag[x]) modify(lch,tag[x]),modify(rch,tag[x]),tag[x]=0;}
int find(int x,int L,int R,int l,int r,ll v)
{
	if (L<R) updtag(x);
	if (L==R) return L;
	int mid=L+R>>1;
	if (mid>=r) return find(lch,L,mid,l,r,v);
	if (mn[lch]<=v) return find(lch,L,mid,l,r,v);
	return find(rch,mid+1,R,l,r,v);
}
ll query(int x,int l,int r,int p)
{
	if (l<r) updtag(x);
	if (l==r) return mn[x];
	int mid=l+r>>1;
	if (mid>=p) return query(lch,l,mid,p);
	return query(rch,mid+1,r,p);
}
void update(int x,int L,int R,int l,int r,ll v)
{
	if (L<R) updtag(x);
	if (L>=l && R<=r){modify(x,v);return;}
	if (L>r || R<l) return;
	int mid=L+R>>1;
	update(lch,L,mid,l,r,v);
	update(rch,mid+1,R,l,r,v);
	mn[x]=mn[rch];
}
void calc(int x,int l,int r)
{
	if (l<r) updtag(x);
	if (l==r){printf ("%lld\n",mn[x]);return;}
	int mid=l+r>>1;
	calc(lch,l,mid),calc(rch,mid+1,r);
}
int main()
{
	#ifdef Kay
		freopen ("s8pc_3_f.in","r",stdin);
		freopen ("s8pc_3_f.out","w",stdout);
	#endif
	scanf ("%d %d",&n,&m);
	int pos;ll tot;
	while (m--)
	{
		scanf ("%d %lld",&pos,&tot);
		while (tot)
		{
			ll val=query(1,1,n,pos);
			int las=find(1,1,n,1,pos,val);
			if (las==1)
			{
				update(1,1,n,1,pos,tot/pos),tot%=pos;
				if (tot) update(1,1,n,1,tot,1);
				break;
			}
			ll lv=query(1,1,n,las-1);
			ll add=min(lv-val,tot/(pos-las+1));
			update(1,1,n,las,pos,add),tot-=add*(pos-las+1);
			val+=add;
			if (val<lv && tot){update(1,1,n,las,las+tot-1,1);break;}
		}
	}
	calc(1,1,n);
	return 0;
}


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

int main() 
{
	long long int n,W,i,j;
	cin >> n>>W;
	long long int w[n],v[n];
	for(i=0;i<n;i++)
	cin >> w[i]>>v[i];
	long long int dp[W+1][n+1];
	for(i=0;i<=W;i++)
	for(j=0;j<=n;j++)
	dp[i][j]=0;
	
	for(i=1;i<=W;i++)
	{
		for(j=1;j<=n;j++)
		{
			if(w[j-1]<=i)
			dp[i][j]=max(dp[i-w[j-1]][j-1]+v[j-1],dp[i][j-1]);
			else
			dp[i][j]=dp[i][j-1];
		}
	}
	
	cout << dp[W][n] << endl;
	return 0;
}

Measured memory_bytes: 79104
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;


int main(){
    ll n; cin >> n;
    vl h(n); rep(i,n) cin >> h[i];
    ll ans = 0;
    stack<P> st;
    rep(i,n){
        if(st.empty()) st.emplace(h[i],i);
        else{
            ll mn = inf;
            while(!st.empty()){
                P p = st.top();
                if(h[i] > p.first) break;
                st.pop();
                chmax(ans, p.first * (i-p.second));
                chmin(mn,p.second);
            }
            st.emplace(h[i],min(i,mn));
        }
    }
    while(!st.empty()){
        P p = st.top();
        chmax(ans, p.first * (n-p.second));
        st.pop();
    }
    cout << ans << endl;
}


Measured memory_bytes: 5224
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

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

static const double PI=6*asin(0.5);
typedef complex<double> P;
typedef long long ll;


bool prime[50050];
vector <int> pri;

int main(){
	memset(prime,0,sizeof(prime));
	rep(i,50050){
		prime[i]=true;
	}
	prime[1]=false;
	prime[0]=false;
	for(int i=1;i*i<50050;i++){
		if(prime[i]){
			//cout<<i<<" ";
			for(int j=i*i;j<50050;j+=i){
				prime[j]=false;
			}
		}
	}
	rep(i,50050){
		if(prime[i]) pri.push_back(i);
	}
	int n;
	while(cin>>n){
		int smo,lar;
		rep(i,pri.size()){
			if(pri[i]<n){
			}
			else{
				if(prime[n]==true){
					smo=pri[i-1];
					lar=pri[i+1];
				}
				else{
					smo=pri[i-1];
					lar=pri[i];
				}
				break;
			}
		}
		cout<<smo<<" "<<lar<<endl;
	}
	
	return 0;
}
		

Measured memory_bytes: 1324
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {
            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }


        public static long gcd(long x, long y)
        {
            if (y < x) gcd(y, x);
            while (y != 0)
            {
                var z = x % y;
                x = y;
                y = z;
            }
            return x;
        }
        public static long keta(long x)
        {
            var z = 1;
            while (x > 0)
            {
                x /= 10;
                z++;
            }
            return z;
        }
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);


            var s = ReadLine();
            var memo = s;
            var t = "keyence";
           
            bool ans = false;

            for (int i = 0; i < s.Length; i++)
            {
                for (int j = 0; j < s.Length - i; j++)
                {
                    memo = s;
                    var r=memo.Remove(j, i);
                    if (r == t) ans = true;
         
                }

            }
            WriteLine(ans? "YES":"NO");

            Console.Out.Flush();
        }
    }
}



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

using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;

const ll linf = 1LL << 62;
const int inf = 99999999;
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };
const ll atcoder = 1e9 + 7;

#define Endl endl
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pb push_back
#define pr(x) cout << x << endl
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define rep(i,n) for(int i= 0;i<n;i++)
#define FOR(i,a,b) for(int i = a;i<b;i++)

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

ll gcd(ll a, ll b) {//最大公約数
	if (a < b)swap(a, b);
	if (a%b == 0)return b;
	else gcd(b, a%b);
}

ll lcm(ll a, ll b) {//最小公倍数
	if (a < b)swap(a, b);
	return (a / gcd(a, b))*b;
}

int main() {

	string s = "";

	rep(i, 3) {
		rep(j, 3) {
			char c;
			cin >> c;
			if (i == j)s += c;
		}
	}
	pr(s);

	//system("pause");
	return 0;
}



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

int main(void) {
  long long i, j, cnt = 1, ans = 1;
  char s[100010];
  scanf("%s", s);
  long long a[strlen(s)][3];
  for(i = 0; i < strlen(s); ++i) for(j = 0; j < 3; ++j) a[i][j] = 0;
  a[0][0] = ((s[0] == 'A' || s[0] == '?') ? 1 : 0);
  ans = (s[0] == '?' ? 3 : 1);
  for(i = 1; i < strlen(s); ++i) {
    for(j = 0; j < 3; ++j) a[i][j] = a[i - 1][j];
    if(s[i] == 'A') a[i][0] += ans;
    else if(s[i] == 'B') a[i][1] += a[i - 1][0];
    else if(s[i] == 'C') a[i][2] += a[i - 1][1];
    else {
      a[i][2] = a[i - 1][2] * 3 + a[i - 1][1];
      a[i][1] = a[i - 1][1] * 3 + a[i - 1][0];
      a[i][0] = a[i - 1][0] * 3 + ans;
      ans *= 3;
      ans %= mod;
    }
    for(j = 0; j < 3; ++j) a[i][j] %= mod;
  }
  printf("%lld", a[strlen(s) - 1][2]);
  return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <complex>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define EQ(a,b) (abs((a)-(b))<eps)

using namespace std;

typedef long double ld;
typedef complex<ld> P;
typedef vector<P> VP;
const ld eps = 1e-8, pi = acos(-1.0);

ld dot (P a, P b) { return real(conj(a) * b); }
ld cross (P a, P b) { return imag(conj(a) * b); }

namespace std {
  bool operator<(const P &lhs, const P &rhs) {
    return lhs.real() == rhs.real() ? lhs.imag() < rhs.imag() : lhs.real() < rhs.real();
  }
}

// Line
class L{
public:
  P a, b;
  L (P aa, P bb) { a = aa; b = bb; }
  L (ld ax, ld ay, ld bx, ld by) { a = P(ax, ay); b = P(bx, by); }
};

// 直線lと直線mが交点を持つか
bool isis_ll(L l, L m) {
  return abs(cross(l.b - l.a, m.b - m.a)) > eps ||
    abs(cross(l.b - l.a, m.a - l.a)) < eps;
}

// 点pから直線lに下ろした垂線の足
P proj(L l, P p) {
  ld t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b);
  return l.a + t * (l.a - l.b);
}

// 直線lと点pの距離
ld dist_lp(L l, P p) {
  return abs(p - proj(l, p));
}

// 直線sと直線lの交点
VP is_ll(L s, L t){
  VP v;
  P sv = s.b - s.a, tv = t.b - t.a;
  if (abs(cross(sv,tv)) > 0)
    v.push_back(s.a + sv * cross(tv, t.a - s.a) / cross(tv, sv));
  return v;
}

// 点pが線分s上に存在するか
bool isis_sp(L s, P p) {
  return abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a) < eps;
}

// 頂点から内心を求める
P ic(P a, P b, P c) {
  ld la = abs(b-c);
  ld lb = abs(c-a);
  ld lc = abs(a-b);
  return 1/(la+lb+lc)*(la*a+lb*b+lc*c);
}

// 3辺から内心を求める
P ic_l(L a,L b,L c) {
  if(!isis_ll(a,b)) {
    ld r = dist_lp(a,b.a) / 2.0;
    L m((a.a + b.a)/P(2,0),(a.a + b.b)/P(2,0));
    P ar = c.a - c.b;
    ar /= abs(ar);
    P p1 = ar * P(0,r);
    P p2 = ar * P(0,-r);
    L c1(c.a+p1, c.b+p1);
    L c2(c.a+p2, c.b+p2);
    VP cx1 = is_ll(m,c1);
    VP cx2 = is_ll(m,c2);
    P h=proj(c,cx1[0]);
    if(isis_sp(c1,h)) return cx1[0];
    return cx2[0];
  } else if (!isis_ll(b,c)) {
    return ic_l(b,c,a);
  } else if (!isis_ll(c,a)) {
    return ic_l(c,a,b);
  }
  P pa = is_ll(b,c)[0];
  P pb = is_ll(c,a)[0];
  P pc = is_ll(a,b)[0];
  return ic(pa,pb,pc);
}

int main() {
  while(1){
    int n;
    cin >> n;
    if(!n) break;
    VP vp;
    REP(i,n) {
      ld x,y;
      cin >> x >> y;
      vp.emplace_back(x,y);
    }
    ld rmax = 0.0;
    REP(i,n)REP(j,n)REP(k,n){
      if(i==j)break;
      if(i==k||j==k)continue;
      L l1(vp[i],vp[(i+1)%vp.size()]);
      L l2(vp[j],vp[(j+1)%vp.size()]);
      L l3(vp[k],vp[(k+1)%vp.size()]);
      P ip = ic_l(l1,l2,l3);
      if(!(isis_sp(l1,proj(l1,ip)) && isis_sp(l2,proj(l2,ip)) && isis_sp(l3,proj(l3,ip))))continue;
      if(dist_lp(l1, ip) < rmax) continue;
      bool valid = true;
      REP(l,n){
        L l4(vp[l], vp[(l+1)%vp.size()]);
        if(dist_lp(l4, ip) < dist_lp(l1, ip)) {
          valid = false;
          break;
        }
      }
      if(valid) rmax = dist_lp(l1,ip);
    }
    cout << fixed << setprecision(6) << rmax << endl;
  }
  return 0;
}

Measured memory_bytes: 1332
#include<cstdio>

int main()
{
	long long a,b,c,d;
	scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
	long long ans1 = a * b;
	long long ans2 = c * d;
	if(ans1 >= ans2)
		printf("%lld\n", ans1);
	else
		printf("%lld",ans2);
	
	
	return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

ll n;

ll dfs(ll num, ll sum, vector<ll> v){
  ll now = 10 * sum;
  now += num;
  if(now == sum)
    return inf;

  if(now >= n){
    return now;
  }

  ll ans = dfs(v[0], now, v);
  REP1(i, v.size())
    ans = min(ans, dfs(v[i], now, v));
  
  return ans;
}

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

  ll k;
  cin >> n >> k;

  vector<ll> d(n);
  REP(i, n)
    cin >> d[i];

  vector<ll> likenum;
  REP(i, 10){
    bool sflag = true;
    REP(j, k){
      if(i == d[j])
        sflag = false;
    }
    if(sflag){
      //cout << i << endl;
      likenum.push_back(i);
    }
  }

  ll ans = 9999999;
  REP(i, likenum.size())
    ans = min(ans, dfs(likenum[i], 0, likenum));
  
  cout << ans << endl;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
     
int main(void) {
   char str[4];
   int count = 0;
   scanf("%s", str);
   for(int i = 0; i < 3 - 1; i++) {
      if(str[i] != str[i+1]) {
         count++;
      }
   }
   if(str[3-1] != str[0]) {
      count++;
   }
   if(count > 0) {
      printf("Yes");
   } else {
      printf("No");
   }
   return 0;
}


Measured memory_bytes: 1736
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    ll x,y;
    cin >> x >> y;
    ll res = 1LL<<40;
    if(x<=y)res=min(res,y-x);
    if(-x<=y)res=min(res,y+x+1);
    if(x<=-y)res=min(res,-y-x+1);
    if(-x<=-y)res=min(res,-y+x+2);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,m,p[100005]={},y[100005]={},itr;
  cin >> n >> m;
  vector<int> x[100005]={};
  for(int i=0; i<m; i++) {
    cin >> p[i] >> y[i];
    x[p[i]].push_back(y[i]);
  }
  for(int i=0; i<n; i++) {
    sort(x[i+1].begin(),x[i+1].end());
  }
  for(int i=0; i<m; i++) {
    itr=lower_bound(x[p[i]].begin(),x[p[i]].end(),y[i])-x[p[i]].begin()+1;
    cout << setw(6) << setfill('0') << p[i];
    cout << setw(6) << setfill('0');
    cout << itr << "\n";
  }
}

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

bool IsPrime(int n) {
    for(int i = 2; i*i <= n; i++) {
        if(n % i == 0) {
            return false;
        }
    }
    return true;
}

int main(void){
   int count = 0, n;
   cin >> n; 
   for(int i = 0; i < n; i++) {
       int p;
       cin >> p;
       if(IsPrime(p)) {
          count++;
       }
   }
   cout << count << endl;
   return 0;
}



Measured memory_bytes: 3096
import sys
N,Y=list(map(int,input().split()))
for i in range(Y//10000+1):
    for j in range(Y//5000+1):
        k=N-i-j
        if(k<0):    break
        if(10000*i+5000*j+1000*k==Y):
            print("{} {} {}".format(i,j,k))
            sys.exit(0)
print("-1 -1 -1")

Measured memory_bytes: 3060
def merge(A, left, mid, right):
    global cnt
    L = A[left:mid] + [1000000001]
    R = A[mid:right] + [1000000001]
    i = j = 0
    for k in range(left,right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
        cnt += 1


def mergeSort(A, left, right):
    if left + 1 < right:
        mid = (right + left) // 2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)


if __name__ == '__main__':
    n = int(input())
    S = list(map(int, input().split()))
    cnt = 0
    mergeSort(S, 0, n)
    print(*S)
    print(cnt)

Measured memory_bytes: 63776
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
long double pi = 2 * acos(0.0);
const ll mod = 998244353;

ll h, w, k, xi, yi, x2, y2;
vector<vector<ll>> cost;
vector<string> mat;
vector<set<ll>> urc, ucc;

void dijkstra() {
    set<pair<ll, pair<ll, ll>>> s;
    s.emplace(make_pair(0, make_pair(xi - 1, yi - 1)));
    cost[xi - 1][yi - 1] = 0;
    while(!s.empty()) {
        pair<ll, pair<ll, ll>> node = *s.begin();
        s.erase(s.begin());
        ll r = node.second.first, c = node.second.second, d = node.first;
        for(ll i = 1; i <= k; i++) {
            if(c + i < w && mat[r][c + i] != '@') {
                if(cost[r][c + i] == INT_MAX) {
                    s.emplace(make_pair(d + 1, make_pair(r, c + i)));
                    cost[r][c + i] = d + 1;
                }
                else if(d + 1 > cost[r][c + i]) break;
            }
            else break;
        }
        for(ll i = 1; i <= k; i++) {
            if(c - i >= 0 && mat[r][c - i] != '@') {
                if(cost[r][c - i] == INT_MAX) {
                    s.emplace(make_pair(d + 1, make_pair(r, c - i)));
                    cost[r][c - i] = d + 1;
                }
                else if(d + 1 > cost[r][c - i]) break;
            }
            else break;
        }
        for(ll i = 1; i <= k; i++) {
            if(r + i < h && mat[r + i][c] != '@') {
                if(cost[r + i][c] == INT_MAX) {
                    s.emplace(make_pair(d + 1, make_pair(r + i, c)));
                    cost[r + i][c] = d + 1;
                }
                else if(d + 1 > cost[r + i][c]) break;
            }
            else break;
        }
        for(ll i = 1; i <= k; i++) {
            if(r - i >= 0 && mat[r - i][c] != '@') {
                if(cost[r - i][c] == INT_MAX) {
                    s.emplace(make_pair(d + 1, make_pair(r - i, c)));
                    cost[r - i][c] = d + 1;
                }
                else if(d + 1 > cost[r - i][c]) break;
            }
            else break;
        }
    }
}

void solve() {
    cin >> h >> w >> k;
    cin >> xi >> yi >> x2 >> y2;
    mat.resize(h); cost.resize(h); urc.resize(h); ucc.resize(w);
    
    for(ll i = 0; i < h; i++) cost[i].resize(w);
    for(ll i = 0; i < h; i++) {
        cin >> mat[i];
        for(ll j = 0; j < w; j++) {
            cost[i][j] = INT_MAX;
        }
    }
    dijkstra();
    if(cost[x2 - 1][y2 - 1] != INT_MAX) cout << cost[x2 - 1][y2 - 1];
    else cout << "-1";
}

int main() {
    ios_base :: sync_with_stdio(false); 
    cin.tie(nullptr);   
    ll t = 1;   
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 58888
import math
import fractions
import copy
import numpy as np
def j(q):
    if q==1: print("Bad")
    elif q == 0:print("Good")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def printrow(a):
    for i in a:
        print(i)
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

#n = ip()                                     #入力整数1つ
n,l= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(m)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#a.pop(0)は10^5あるときTLEしやすい!注意!抜くなら逆ソート!
a = [l+i for i in range(n)]
if min(a)>=0:
    a.pop(0)
elif max(a) < 0:
    a.pop(-1)
print(sum(a))

Measured memory_bytes: 23052
macro_rules! read {
	() => {{
		let mut buf = String::new();
		std::io::stdin().read_line(&mut buf).unwrap();
		buf
	}};
	( Vec<$t:ty> ) => {
		read!()
			.trim()
			.split_whitespace()
			.map(|x| x.parse::<$t>().unwrap())
			.collect::<Vec<_>>()
	};
	( $( $t:ty ),* ) => {{
		let buf = read!();
		let mut iter = buf.split_whitespace().collect::<Vec<_>>().into_iter();
		( $( iter.next().unwrap().parse::<$t>().unwrap() ),* )
	}};
}

const MOD: i64 = 1000000007;

fn main() {
	let (n, k) = read!(i64, i64);

	let mut min = k * (k - 1) / 2;
	let mut max = k * (n + (n - k + 1)) / 2;
	let mut ans = 0;

	for i in k..(n + 2) {
		ans += max - min + 1;
		ans %= MOD;

		min += i;
		max += n - i;
	}

	println!("{}", ans)
}


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

char c[3][3];
bool f = true;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	for(int i=0;i<2;i++){
		for(int j=0;j<3;j++){
			cin>>c[i][j];
		}
	}
	for(int i=0;i<3;i++){
		if(c[0][i] != c[1][3-i-1]){
			f = false;
			break;
		}
	}
	if(f)
		cout<<"YES";
	else
		cout<<"NO";
	return 0;
}

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



int main(){
	ios::sync_with_stdio(false);
  	cin.tie(0);
	int a[4];
	int d;
  	cin>>a[0]>>a[1]>>a[2]>>a[3];
  	sort(a,a+4);
  	d=1000*a[0]+100*a[1]+10*a[2]+a[3];
  	if(d==1479)	cout<<"YES";
  	else	cout<<"NO";
  	
}


Measured memory_bytes: 256
a, b, c = map(int,input().split())
k = 1
ans = 0

for i in range(40):
    if a % 2 == 0 and b % 2 == 0 and c % 2 == 0:
        d = a // 2
        e = b // 2
        f = c // 2
        a = e + f
        b = d + f
        c = d + e
        ans += 1
    else:
        k = 0
        break

if k == 1:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9192
#include<iostream>
#include<queue>

using namespace std;

const int MAX = 101;
const int INF = (1<<25);

struct State{
  int x,y,t;
  State(int a,int b, int c):x(a),y(b),t(c){}
  bool operator < (const State& s) const {return t>s.t;}
};

int T[MAX][MAX];
char M[MAX][MAX];
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int n,m;
int sx,sy;

void print(){
  for(int i = 0; i < m; i++){
    for(int j = 0; j < n; j++) cout << T[i][j];
    cout << endl;
  }
}

void init(){
  for(int i = 0; i < MAX; i++)
    for(int j = 0; j < MAX; j++)
      T[i][j] = INF;
}

void input(){
  for(int i = 0; i < m; i++)
    for(int j = 0; j < n; j++){
      cin >> M[i][j];
      if(M[i][j] == '&'){
	sx = j;
	sy = i;
      }
    }
}

bool isInside(int x, int y){return 0<=x&&x<n&&0<=y&&y<m;}

void solve(){

  T[sy][sx] = 0;

  priority_queue<State> Q;

  Q.push(State(sx,sy,0));

  while(!Q.empty()){
    State s = Q.top();
    Q.pop();

    if(T[s.y][s.x] < s.t) continue;

    for(int i = 0; i < 4; i++){
      int nx = s.x+dx[i];
      int ny = s.y+dy[i];
      if(!isInside(nx,ny)) continue;

      /*   if(M[ny][nx] == '#' && T[ny][nx] > s.t+1){
	T[ny][nx] = s.t+1;
	Q.push(State(nx,ny,s.t+1));
      }

      if(M[ny][nx] != '#' && T[ny][nx] > s.t){
	T[ny][nx] = s.t;
	Q.push(State(nx,ny,s.t));
	}*/

      if(M[ny][nx] == '#'){

	if(M[s.y][s.x] == '#' && T[ny][nx] > s.t){
	  T[ny][nx] = s.t;
	  Q.push(State(nx,ny,s.t));
	}
	if(M[s.y][s.x] != '#' && T[ny][nx] > s.t+1){
	  T[ny][nx] = s.t+1;
	  Q.push(State(nx,ny,s.t+1));
	}

      }else if(T[ny][nx] > s.t){
	T[ny][nx] = s.t;
	Q.push(State(nx,ny,s.t));
      }
    }
  }

  int ans = INF;

  for(int i = 0; i < n; i++) ans = min(ans,min(T[0][i],T[m-1][i]));
  for(int i = 0; i < m; i++) ans = min(ans,min(T[i][0],T[i][n-1]));

  cout << ans << endl;
  //  print();
}
int main(){

  while(cin >> n >> m && n+m){
    init();
    input();
    solve();
  }
  return 0;
}

Measured memory_bytes: 1376
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
using namespace std;

#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)

typedef long long ll;

const int kMaxH = 50;
const int kMaxW = 50;
const int kInf = 1000000000;

int H, W;
string s[kMaxH];
int ans = 0;

int cost[kMaxH][kMaxW];
int mincost = kInf;
int d[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

int WhiteCount() {
  int c = 0;
  REP(i, H) { c += count(s[i].begin(), s[i].end(), '.'); }
  return c;
}

int main() {
  cin >> H >> W;
  REP(i, H) { cin >> s[i]; }

  fill(cost[0], cost[H], kInf);
  cost[0][0] = 0;
  queue<pair<int, int>> q;
  q.push(make_pair(0, 0));
  bool f = true;
  while (!q.empty() && f) {
    pair<int, int> p = q.front();
    q.pop();
    int x = p.first;
    int y = p.second;
    REP(i, 4) {
      int nx = x+d[i][0], ny = y+d[i][1];
      if (0<=nx && nx <= H-1 && 0<=ny && ny <= W-1 && s[nx][ny] != '#') {
        if (cost[nx][ny] > cost[x][y]+1) {
          cost[nx][ny] = cost[x][y]+1;
          if (nx == H-1 && ny == W-1) {
            mincost = cost[nx][ny];
            f = false;
            break;
          }
          q.push(make_pair(nx, ny));
        } else {
          continue;
        }
      }
    }
  }
  if (f) {
    ans = -1;
  } else {
    ans = WhiteCount() - (cost[H-1][W-1]+1);
  }

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


Measured memory_bytes: 256
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline



def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [P, Q, R] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2])]
    print min(P + Q, P + R, R + Q)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2932
#include<cstdio>
#include<cstdlib>
#include<math.h>
#include<iostream>
using namespace std;

int cmpsub(int d[],int pd[],int m){
	int i;
	if(d[0]==pd[0]){
		for(i=1;i<m;i++) if(d[i]!=pd[i]) break;
		if(i==m) return 1;
		for(i=1;i<m;i++) if(d[i]!=-pd[m-i]) break;
		if(i==m) return 1;
	}
	else if(m%2==1){
		for(i=1;i<m;i++) if(d[i]!=-pd[m-i]) break;
		if(i==m) return 1;
	}
	return 0;
}

int cmp(int d[],int pd[],int m){
	int i;
	if(cmpsub(d,pd,m)) return 1;
	for(i=0;i<m;i++) if(i%2==0) pd[i]=-pd[i];
	if(cmpsub(d,pd,m)) return 1;
	pd[0]=-pd[0];
	for(i=0;i<m;i++) if(i%2==1) pd[i]=-pd[i];
	if(cmpsub(d,pd,m)) return 1;
	for(i=0;i<m;i++) if(i%2==0) pd[i]=-pd[i];
	if(cmpsub(d,pd,m)) return 1;
	return 0;
}

int main(){
	int i,j;
	int n;
	int m;
	int x0,y0,x1,y1;
	int *d;
	int pm;
	int *pd;
	while(true){
		cin>>n;
		//cout<<"  "<<n<<endl;
		if(n==0) break;
		cin>>m;
		d=new int[m];
		cin>>x0>>y0;
		cin>>x1>>y1;
		if(x1-x0!=0) d[0]=1;
		else d[0]=-1;
		d[1]=x1-x0+y1-y0;
		x0=x1;
		y0=y1;
		for(i=2;i<m;i++){
			cin>>x1>>y1;
			d[i]=x1-x0+y1-y0;
			x0=x1;
			y0=y1;
		}
		for(i=1;i<=n;i++){
			cin>>pm;
			pd=new int[pm];
			cin>>x0>>y0;
			cin>>x1>>y1;
			if(x1-x0!=0) pd[0]=1;
			else pd[0]=-1;
			pd[1]=x1-x0+y1-y0;
			x0=x1;
			y0=y1;
			for(j=2;j<pm;j++){
				cin>>x1>>y1;
				pd[j]=x1-x0+y1-y0;
				x0=x1;
				y0=y1;
			}
			if(m!=pm){
				delete []pd;
				continue;
			}
			if(cmp(d,pd,m)){
				cout<<i<<endl;
				delete []pd;
				continue;
			}
			delete []pd;
		}
		cout<<"+++++"<<endl;
		delete []d;
	}
	return 0;
}

Measured memory_bytes: 0
N, A, B = map(int, input().split())
C = N // (A + B) * A + N % (A + B)
D = N // (A + B) * A + A
if A == 0:
    print(0)
elif B == 0:
    print(N)
elif N % (A + B) > A:
    print(D)
else:
    print(C)

Measured memory_bytes: 3060
#include <math.h>
int main()
{
  int a, b, h, m;
  scanf("%d %d %d %d", &a, &b, &h, &m);
  
  double l, s;
  l = h * 30 + (double)m / 2;
  s = 6 * m;
  double tmp;
  tmp = fabs(l - s);
  double c;
  c = sqrt(a * a + b * b - 2 * a * b * cos(tmp * M_PI / 180));
  printf("%.10lf", c);
}


Measured memory_bytes: 2664
public class Main {


  private static void solve() {
    int n = ni();
    int l = ni();
    
    int min = Integer.MAX_VALUE;
    int minArg = -1;
    long sum = 0;
    for (int i = 0; i < n; i ++) {
      int v = Math.abs(l + i);
      if (min > v) {
        minArg = i;
        min = v;
      }
      sum += l + i;
    }
    System.out.println(sum - (l + minArg));
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


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

      String S = sc.next();
      
      if(S.charAt(0) == S.charAt(1) && S.charAt(1) == S.charAt(2)){

      System.out.print("No");

      }else{
 
      System.out.print("Yes");
     }
   }
 }

Measured memory_bytes: 35576