akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
pair<ll, ll> x[8];

ll n;
ld sum = 0;

void calc(vector<ll> count){
    rep(i, 0, n-1){
        sum += sqrt(pow(x[count[i+1]].first - x[count[i]].first, 2) + pow(x[count[i+1]].second - x[count[i]].second, 2));
    }
}

void dfs(ll dp, vector<ll> count){
    if(dp == n){
        calc(count);
    }else{
        rep(i, 0, n){
            if(find(count.begin(), count.end(), i) == count.end()){
                vector<ll> tmp = count;
                tmp.push_back(i);
                dfs(dp + 1, tmp);
            }
        }
    }
}

int main(void){
    cin >> n;

    rep(i, 0, n){
        cin >> x[i].first >> x[i].second;
    }

    vector<ll> ans;
    dfs(0, ans);

    ld num = 1;
    ll tmp = n;
    rep(i, 0, n-1){
        num *= tmp;
        tmp --;
    }

    printf("%.10Lf", sum / num);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
struct dice
{
	int s[6], b;
	void roll(char c)
	{
		if (c == 'W')
		{
			b = s[0];
			s[0] = s[2];
			s[2] = s[5];
			s[5] = s[3];
			s[3] = b;
		}
		if (c == 'E')
		{
			b = s[0];
			s[0] = s[3];
			s[3] = s[5];
			s[5] = s[2];
			s[2] = b;
		}
		if (c == 'S')
		{
			b = s[0];
			s[0] = s[4];
			s[4] = s[5];
			s[5] = s[1];
			s[1] = b;
			
		}
		if (c == 'N')
		{
			b = s[0];
			s[0] = s[1];
			s[1] = s[5];
			s[5] = s[4];
			s[4] = b;
		}
		if (c == 'R')
		{
			b = s[1];
			s[1] = s[2];
			s[2] = s[4];
			s[4] = s[3];
			s[3] = b;
		}
	}
	int top()
	{
		return s[0];
	}
	int left()
	{
		return s[3];
	}
	int right()
	{
		return s[2];
	}
	int front()
	{
		return s[1];
	}
};
int main()
{
	dice d;

	for (int i = 0; i < 6; i++)
	{
		cin >> d.s[i];
	}
	int a, b, n;
	cin >> n;
	while (n--)
	{
		cin >> a >> b;
		if (d.left() == a)d.roll('E');
		if (d.right()== a)d.roll('W');
		while (d.top() != a)d.roll('N');
		while (d.front() != b)d.roll('R');
		cout << d.right() << endl;		
	}
return 0;
}



Measured memory_bytes: 3080
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {

    int N;
    int A,B;
    private void solve() {
        N = nextInt();
        if(N == 1) {
            out.println("Hello World");
        } else {
            A = nextInt();
            B = nextInt();

            out.println(A + B);
        }
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
int main() {
	int A, B; //A(最初の数)とB(最後の数)の整数型宣言
  	cin >> A >> B; //AとBの値を入力
    	int C = 0; //回文数をカウントするための変数Cの整数型宣言
                 //AからBまで1ずつループ
  	for(int i = A; i <= B; i++){
                     //もし万の位と一の位が等しい場合
    	    if(i / 10000 == i % 10){
                         //さらに千の位と十の位が等しい場合
        	        if(i % 10000 / 1000 == i % 100 / 10){
                         //Cの値を1増やす
            	        C += 1;
                          }
                      }
                  }
                  //Cの値を出力
  	cout << C << endl;
}

Measured memory_bytes: 256
from sys import stdin, setrecursionlimit


class UnionFindTree:
    def __init__(self, n):
        self.parent = [-1] * n

    def find(self, x):
        p = self.parent
        while p[x] >= 0:
            x, p[x] = p[x], p[p[x]]
        return x

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        p = self.parent
        if x != y:
            if x > y:
                x, y = y, x
            p[x], p[y] = p[x] + p[y], x

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.parent[self.find(x)]


def main():
    n, m, k = map(int, stdin.readline().split())

    f = UnionFindTree(n)

    f_or_b = [0] * n

    for _ in range(m):
        a, b = map(int, stdin.readline().split())
        f.union(a - 1, b - 1)
        f_or_b[a - 1] += 1
        f_or_b[b - 1] += 1

    for _ in range(k):
        c, d = map(int, stdin.readline().split())
        if f.same(c - 1, d - 1):
            f_or_b[c - 1] += 1
            f_or_b[d - 1] += 1

    print(*[f.size(i) - f_or_b[i] - 1 for i in range(n)])


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Measured memory_bytes: 60252
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<stack>

using namespace std;
typedef long long ll;
int dig[4];
char op[4];
bool flag = true;
void print(){
	for(int i = 0;i < 4;i++){
		cout << dig[i];
		if(i != 3) cout << op[i];
	}
	cout << "=7" << endl;
}
void dps(int index,int ans)
{
	if(index == 4){
		if(ans == 7){
			print();
			flag = false;
		}
		return;
	}
	if(index == 0){
		ans += dig[0];
	}
	else{
		switch(op[index-1]){
		case '+':
			ans += dig[index];
			break;
		case '-':
			ans -=  dig[index];
			break;
		}
	}
	if(flag){
		op[index] = '+';
		dps(index+1,ans);
	}
	if(flag){
		op[index] = '-';
		dps(index+1,ans);
	}
}

int main(){
	char s[5];
	cin >> s;
	for(int i = 0;i < 4;i++){
		dig[i] = s[i] - '0';
	}
	dps(0,0);
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cassert>
#include <map>
#include <set>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> l4;
#define pb push_back
#define mp make_pair

const int maxn = 1e5+1;
int n, x, y, z;

l4 a[maxn];

int main()
{
  scanf("%d %d %d", &x, &y, &z);
  n = x+y+z;
  ll ans = 0;
  for (int i = 0; i < n; ++i)
    {
      ll c;
      scanf("%lld %lld %lld", &a[i].first, &a[i].second, &c);
      ans += c;
      a[i].first -= c;
      a[i].second -= c;
    }
  sort(a, a+n, [&](const l4 &l, const l4 &r)
       {
	 return l.first-l.second < r.first-r.second;
       });
  multiset<ll> left, right, freeleft, freeright;
  ll lsum = 0, rsum = 0;
  for (int i = 0; i < y; ++i)
    {
      left.insert(a[i].second);
      lsum += a[i].second;
    }
  for (int i = y; i < n; ++i)
    {
      right.insert(a[i].first);
      rsum += a[i].first;
    }
  while (right.size() > x)
    {
      rsum -= *right.begin();
      freeright.insert(*right.begin());
      right.erase(right.begin());
    }
  assert(freeright.size()==z);
  ll tot = lsum+rsum;
  for (int i = y; i < n-x; ++i)
    {
      if (a[i].second > *left.begin())
	{
	  lsum -= *left.begin();
	  left.erase(left.begin());
	  left.insert(a[i].second);
	  lsum += a[i].second;
	}
      multiset<ll>::iterator it = freeright.find(a[i].first);
      if (it != freeright.end())
	freeright.erase(it);
      else
	{
	  rsum -= a[i].first;
	  it = right.find(a[i].first);
	  right.erase(it);
	  it = freeright.end();
	  --it;
	  rsum += *it;
	  right.insert(*it);
	  freeright.erase(it);
	}
      tot = max(lsum+rsum, tot);
    }
  ans += tot;
  printf("%lld\n", ans);
}


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

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")

#define DEBUG(x) cout << ">> " << #x << ": " << x << endl;
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define f first
#define s second

const int MOD = 1000000007;
typedef long long ll;
typedef long double ld;

void setIO(string s) {
  ios_base::sync_with_stdio(0); cin.tie(0);
  freopen((s+".in").c_str(),"r",stdin);
  freopen((s+".out").c_str(),"w",stdout);
}

int main() { _
  ll n; cin >> n;
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    if (i%3 != 0 && i%5 != 0) ans += i;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int N, M;
  long long ans = 0;
  int Flag;

  cin >> N >> M;
  
  vector<int> Switch(N);
  vector<int> k(M);
  vector<int> p(M);
  vector<vector <int>> Sindex(M);  

  for ( int i = 0; i < M; i++ ){
    cin >> k.at(i);
    for ( int j = 0; j < k.at(i); j++ ){
      int s;
      cin >> s;
      Sindex.at(i).push_back(s);
    }
  }
  for ( int i = 0; i < M; i++ ){
    cin >> p.at(i);
  } 

  for ( int j = 0; j < pow(2,N); j++ ){
    int Number = j;
    for ( int i = N; i >= 1; i-- ){
      Switch.at(i-1) = Number % 2;
      Number = Number / 2;
    }
  

    //全ての電球がつくかCheck
    Flag = 0;
    for ( int i = 0; i < M; i++ ){
      int Check = 0;
      if ( p.at(i) == 0 ){
        for ( int j = 0; j < k.at(i); j++ ){
          Check += Switch.at(Sindex.at(i).at(j)-1);
        }
        if ( Check % 2 == 1 ){
          Flag = 1; break;
        }
      }
      else{
        for ( int j = 0; j < k.at(i); j++ )
          Check += Switch.at(Sindex.at(i).at(j)-1);
        if ( Check % 2 == 0 ){
          Flag = 1; break;
        }
      }
    }
    if ( Flag == 0 ){
        ans += 1;
    }
  }

  cout << ans << endl;
  
}

Measured memory_bytes: 256
/*input
4 5
3 2 4 1
*/

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int D = 60; // log(MAX_K)
const int MAX_N = 200005;
int to[D][MAX_N];

int main() {
  int n; ll k;
  cin >> n >> k;
  rep(i, n) {
    cin >> to[0][i];
    to[0][i]--;
  }
  rep(i, D-1) rep(j, n) {
    to[i+1][j] = to[i][to[i][j]];
  }

  int v = 0;
  // for (int D-1; i >= 0; --i) {
  //   ll l = 1LL<<i;
  //   if (l <= k) {
  //     v = to[i][v];
  //     k -= l;
  //   }
  // }
  rep(i, D) {
    if (k>>i&1) v = to[i][v];
  }
  cout << v+1 << endl;
  return 0;
}

Measured memory_bytes: 50452
#include<bits/stdc++.h>
using namespace std;
int gcd(int x,int y){
	if(x%y!=0)
		return gcd(y,x%y);
	return y;
}
int main(){
	int a,b,k;
	while(cin>>a>>b>>k){
		int c=gcd(a,b),sum=0;
		for(int i=c;i>=1;i--){
			if(c%i==0){
				sum++;
			}
			if(sum==k){
				cout<<i<<endl;
				break;
			}
		}
	}
}

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

int main(){
    string s;
    rep(i, 3){
        cin >> s;
        cout << s[0];
    }
    return 0;
}

Measured memory_bytes: 256
import math
from collections import Counter
x=int(input())
a=0
b=0
l=[]
for i in range(0,201):
	l.append(pow(i,5))
f=True
for i in range(len(l)):
	if not f:
		break
	for j in range(len(l)):
		if not f:
			break
		if l[i]-l[j]==x:
			print(i,j)
			f=False
		elif l[i]+l[j]==x:
			print(i,-j)
			f=False
	


Measured memory_bytes: 68096
//
//  main.cpp
//  A
//
//  Created by Knight_F on 2019/8/10.
//  Copyright © 2019年 Knight_F. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <vector>
#define LL long long
using namespace std;
int main(){
    int k,x;cin>>k>>x;
  for(int i=x-k+1;i<=x+k-1;i++)
    cout<<i<<' ';
  return 0;
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair< int, int > P;
typedef pair< int, P > PP;

//-------------------------------------------------

string s;

bool f(string t) {
	if (t[0] != 'A' || t[(int)t.size() - 1] == 'C') return false;
	int C = 0, small = 0;
	if ('A' <= t[1] && t[1] <= 'Z') return false;
    FOR(i, 2, (int)t.size())  {
		if (t[i] == 'C') C++;
		if ('a' <= t[i] && t[i] <= 'z') small++;
	}
	if (C != 1) return false;
	if (small != (int)t.size() - 3) return false;
	return true;
}

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

	cin >> s;
	cout << (f(s) ? "AC" : "WA") << endl;

	return 0;
}



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

bool check(string s) {
    int N = s.length();
    if(N % 2 == 1) {
        return false;
    }
    return (s.substr(0, N/2) == s.substr(N/2));
}
 
int main() {
    string s;
    cin >> s;
    int N = s.length();
    for(int i = N-1; ; i--) {
        if(check(s.substr(0, i))) {
            cout << i << endl;
            return 0;
        }
    }

    cout << endl;
    return 0;
}

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

using namespace std;
typedef pair<int,int> pii;
typedef long long int lli;

int main()
{
	char c;
	scanf(" %c",&c);

	if( 'A' <= c && c <= 'Z' ) printf("A\n");
	else printf("a\n");	
}

Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1000000007;

ll r(ll x, ll y) {
  if (y == 0) return 1;
  else if (y % 2 == 0) return r(x, y/2) * r(x, y/2) % mod;
  else return x * r(x, (y-1)/2) % mod * r(x, (y-1)/2) % mod;
}

ll s(ll x) {
  if (x==0) {
    return 1;
  }
  else {
    return 2 * s(x-1) + 3;
  }
}

ll f(ll x, ll y) {
  if (x == 0) {
    return 1;
  }
  else if (y  == 1) {
    return 0;
  }
  else if (y <= s(x-1)+1){
    return f(x-1, y-1);
  }
  else if (y == s(x-1) + 2) {
    return f(x-1, s(x-1)) + 1;
  }
  else if (y == s(x)) {
    return 2 * f(x-1, s(x-1)) + 1;
  }
  else {
    return f(x-1, s(x-1)) + 1 + f(x-1, y - s(x-1) -2);
  }
}

int main() {
  ll n, p;
  cin >> n >> p;
  printf("%lld\n", f(n, p));
}
              



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+5;
int a[maxn];
int n=0;
ll f[maxn][2];

int main(){
	char p;
	while (p=getchar()){
		if (p=='\n' || p==' ') break;
		a[++n]=(int)p-48;	
	}
	f[1][0]=a[n];
	f[1][1]=10-a[n];
	for (int i=2;i<=n;i++){
		f[i][0]=a[n-i+1]+min(f[i-1][0],f[i-1][1]+1);
		f[i][1]=9-a[n-i+1]+min(f[i-1][0]+1,f[i-1][1]);	
	}
	cout << min(f[n][0],f[n][1]+1);
	return 0;
}

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

int main(){
  int n,k,count=0,h;
  cin >> n >> k;
  while(n--){
    cin >> h;
    if(h>=k)count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

LL r[2][3];
LL dp[5000 * 5001 + 1];

LL f(LL n, int x, int y) {
	
	incII(i, 0, n) { dp[i] = -1; }
	dp[n] = 0;
	
	LL ans = 0;
	vector<int> p = { 0, 1, 2 };
	do {
		inc(i, 3) {
			decII(j, 0, n) {
				if(dp[j] == -1) { continue; }
				if(j >= r[x][p[i]]) { setmax(dp[j - r[x][p[i]]], dp[j] + r[y][p[i]]); }
			}
		}
		incII(j, 0, n) { setmax(ans, j + dp[j]); }
	} while(next_permutation(ALL(p)));
	
	return ans;
}

int main() {
	LL n;
	cin >> n;
	inc(i, 2) {
	inc(j, 3) {
		cin >> r[i][j];
	}
	}
	
	n = f(n, 0, 1);
	n = f(n, 1, 0);
	
	cout << n << endl;
	
	return 0;
}


Measured memory_bytes: 195584
_ = gets.to_i
c = gets.split.map(&:to_i)
x = []
ans = -1
c.each_with_index do |_c, i|
  if _c.positive?
    if x.include?(_c)
      ans = i + 1
      break
    else
      x << _c
    end
  else
    _c *= -1
    if x.include?(_c) && x.last == _c
      x.delete(_c)
    else
      ans = i + 1
      break
    end
  end
end
puts ans == -1 ? 'OK' : ans


Measured memory_bytes: 6884
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
  
int main() {
  int A,B;
  cin >> A >> B;
  int sum=0;
  
  for (int i = A; i < B+1; i++) {
    int x=i;
    if (x%10==x/10000) {
      x = (x/10)%1000;
      if (x%10==x/100) {
        sum++;
      }
    }
  }
  cout << sum;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

int main(void){
    ll n, d, a;
    cin >> n >> d >> a;

    vector<pair<ll, ll>> m(n);
    rep(i, 0, n){
        cin >> m[i].first >> m[i].second;
        m[i].second = (m[i].second + a - 1) / a;
    }

    sort(all(m));
    ll count = 0;
    ll bomb = 0;
    queue<pair<ll, ll>> event;

    rep(i, 0, n){
        while(!event.empty()){
            if(event.front().first < m[i].first){
                bomb -= event.front().second;
                event.pop();
            }else{
                break;
            }
        }

        if(m[i].second <= bomb) continue;
        ll add = m[i].second - bomb;
        event.push(make_pair(m[i].first + 2 * d, add));
        count += add;
        bomb += add;
    }

    cout << count << endl;
    return 0;
}


Measured memory_bytes: 4992
fun main(args: Array<String>) {

    val n = readLine()!!.toInt()

    var summary = 0
    for (i in 0..30) {
        for (j in 0..30) {
            if ((i * 4 + j * 7) == n) {
                println("Yes")
                // main抜けたい時はreturn 2重ループのbreakは自分のループのbreak
                return
            }
        }
    }
    println("No")
}

Measured memory_bytes: 31740
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t n,k;
  cin >> n >> k;
  int64_t a[n];
  for(int64_t i=0;i<n;i++)cin >> a[i];
    int64_t ans=1000000000000000000;
  for(int64_t bit=0;bit<(1<<n);bit++){
    if(__builtin_popcount(bit)<k || bit%2==0)continue;
    vector<int64_t> s;
    for(int64_t i=0;i<n;i++){
      if(bit&(1<<i)){
          s.push_back(i);
      }
    }
    s.push_back(n);
    int64_t l=0,sum=0;
    for(int64_t j=0;j<s.size()-1;j++){
        l=max(l+1,*max_element(a+s[j],a+s[j+1]));
        sum+=l-a[s[j]];
    }
    ans=min(ans,sum);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3572
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

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

		int N = Integer.parseInt(sc.next());
		int Q = Integer.parseInt(sc.next());
		int a,b,p,x;
		int idx;

		// 親⇔子(双方向)リストのマップ
		HashMap<Integer, ArrayList<Integer>> pMap = new HashMap<Integer, ArrayList<Integer>>();
		// 値のマップ
		int[] value = new int[N+1];
		int[] counter = new int[N+1];

		ArrayList<Integer> childs;
		for (idx = 0; idx < N-1; idx++) {
			a = Integer.parseInt(sc.next());
			b = Integer.parseInt(sc.next());

			// a-b
			childs = pMap.get(a);
			if (childs == null) {
				childs = new ArrayList<Integer>();
				pMap.put(a, childs);
			}
			childs.add(b);
			// b-a
			childs = pMap.get(b);
			if (childs == null) {
				childs = new ArrayList<Integer>();
				pMap.put(b, childs);
			}
			childs.add(a);
		}
		for (idx = 0; idx < Q; idx++) {
			p = Integer.parseInt(sc.next());
			x = Integer.parseInt(sc.next());
			counter[p] += x;
		}
		sc.close();

		// 処理するノード、親の1をスタート
		int[] nodes = new int[N];
		nodes[0] = 1;
		// 親フラグ
		boolean[] parentFlg = new boolean[N+1];
		for (idx = 1; idx <= N; idx++) {
			parentFlg[idx] = false;
		}

		int node;
		int pos = 0;
		int tailpos = 1;

		while(true) {
			node = nodes[pos++];
			// 親フラグ立てる
			parentFlg[node] = true;

			// 自身のカウンター足す
			value[node] += counter[node];
			// 子を取得
			childs = pMap.get(node);
			if (childs != null) {
				// 子に親の合計を足す
				for (int ch : childs) {
					if (!parentFlg[ch]) {
						// 親として処理済みでないもののみ足す
						value[ch] += value[node];
						nodes[tailpos++] = ch;
					}
				}
			}

			if (pos >= N) {
				break;
			}
		}

		for (idx = 1; idx < N+1; idx++) {
			System.out.print(value[idx] + " ");
		}

	}

}


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

N = int(input())
A = list(map(int, input().split()))

A = list(map(lambda x: bin(x)[2:].zfill(20),
             A))

admissible = [N-1] * N

def update(i, adm):
    if adm < admissible[i]:
        admissible[i] = adm

for k in range(20):
    # A[*][k]
    prev = []
    curr = []
    for i in range(N):
        # if A[i][k] == "0":
        #     curr.append(i)
        # else:
        curr.append(i)
        if A[i][k] == "1":
            for j in prev:
                update(j, i-1)
            prev = curr
            curr = []


# print(admissible)
ans = 0
for i in range(N):
    ans += admissible[i] - i + 1
print(ans)


Measured memory_bytes: 120984
#include<bits/stdc++.h>
using namespace std;
int main()
{

    int n,m;
    long long an=0;
    cin>>n>>m;
    int a[m];
    for(int i=0;i<m;i++)
    {
        cin>>a[i];
        an+=a[i];
    }
    an=n-an;
    if(an>=0)
    {
        cout<<an<<endl;
    }
    else
        cout<<-1<<endl;
    return 0;
}


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

#define ll long long
#define ll128 __uint128_t
#define ld long double
#define pll pair <ll, ll>

#define vll vector <ll>
#define vld vector<ld>
#define vpll vector<pll>

#define vvll vector <vll>

#define rep(i, a, b) for(ll i = a; i < b; i++)
#define per(i, a, b) for(ll i = (ll)a - 1; i >= b; --i)

#define endl "\n"
#define pb push_back
#define pf push_front

#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

#define sorta(v) sort(all(v))
#define sortd(v) sort(rall(v))

#define debug if (1)
#define log(val) debug {cout << "\n" << #val << ": " << val << "\n";}

#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define file(name) freopen(name".in", "r", stdin); freopen(name".out", "w", stdout);
#define FILE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

#define mod (ll)(1e9 + 7)
#define inf (mod * mod)

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

ostream & operator << (ostream & out, vll & a) {
    for(auto i : a) out << i << " ";
    return out;
}

istream & operator >> (istream & in, vll & a) {
    for(auto &i : a) in >> i;
    return in;
}

int main() {

    ll n;
    cin >> n;
    vll a(n);
    cin >> a;

    vector<pll> inp;
    rep(i, 0, n) {
        inp.pb(make_pair(a[i], i));
    }

    sort(all(inp));

    set<ll> cur;
    cur.insert(-1);
    cur.insert(n);
    ll ans = 0;
    for (auto i : inp) {
        auto nxt = cur.lower_bound(i.second);
        auto it = prev(nxt);

        ans += ((i.second - *it) * (*nxt - i.second)) * i.first;
        cur.insert(i.second);
    }
    cout << ans << endl;

    return 0;
}


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

int main() {
  int A,B,a,b,c,d,e,x;
  int count = 0;
  
  cin >> A >> B;
  
  while(A<=B){
   a = A / 10000;
   b = A % 10000 / 1000;
   c = A % 10000 % 1000 / 100;
   d = A % 10000 % 1000 % 100 / 10;
   e = A % 10000 % 1000 % 100 % 10;
  
   x = e * 10000 + d * 1000 + c * 100 + b * 10 + a;
  
   if(x == A){
     count++;
   }
   A++;
    
  }
  
   cout << count << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }


    // int N = Integer.parseInt(scanner.nextLine());
    // int N = scanner.nextInt(), M = scanner.nextInt();
    // scanner.nextLine();
    // int[] n = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    // long[] n = Arrays.stream(scanner.nextLine().split(" ")).mapToLong(Long::parseLong).toArray();
    static void solve(Scanner scanner) {
        int N = Integer.parseInt(scanner.nextLine());
        System.out.println(N * N);
    }

}


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

using namespace std;

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

using ll = long long;
using vll = vector<long long>;
using vvll = vector<vector<long long>>;

// 1～nのmod逆元を計算する(modは素数), O(n)
void ModInv(int n, vector<ll> &inv, int mod) {
	inv[0] = 0;
	inv[1] = 1;
	for (int i = 2; i <= n; i++) {
		inv[i] = mod - ((mod / i) * inv[mod % i] % mod);
	}
}

// 0!～n!のmod逆元を計算する(modは素数), O(n)
void FacInv(int n, vector<ll> inv, vector<ll> &fac, vector<ll> &facInv, int mod) {
	fac[0] = facInv[0] = 1;
	for (int i = 1; i <= n; i++) {
		fac[i] = (fac[i - 1] * i) % mod;
		facInv[i] = (facInv[i - 1] * inv[i]) % mod;
	}
}

// nCkをmodで割った余りを求める。mod素数限定
// ModInv()とFacInv()が必要
long CombiMod(int n, int k, int mod, const vll &inv, const vll &fac, const vll &facInv) {
	if (n == 0 && k == 0) return 1;
	if (n <= 0 || k < 0 || k > n) return 0;
	if (k == 0) return 1;

	return (((fac[n] * facInv[k]) % mod) * facInv[n - k]) % mod;
}

// 繰り返し二乗法で (x^n)%mod を計算する O(log n)
ll powMod(ll x, ll n, ll mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % mod;
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}

int main() {
	int N, M;
	cin >> N >> M;

	// 階乗逆元の事前計算
	vector<ll> inv(N + 1);
	vector<ll> fac(N + 1);
	vector<ll> facInv(N + 1);
	ModInv(N, inv, M);
	FacInv(N, inv, fac, facInv, M);

	vll ways(N + 1, 0);
	vvll ways2(N + 1, vll(N + 1, 0));
	
	// ways2 の事前計算
	ways2[0][0] = 1;
	repr(i, 1, N + 1) {
		rep(j, N + 1) {
			if (j > i) {
				ways2[i][j] = 0;
			}
			else if (j == 0 || j == i) {
				ways2[i][j] = 1;
			}
			else {
				ways2[i][j] = (((j + 1) * ways2[i - 1][j]) % M + ways2[i - 1][j - 1]) % M;
			}
		}
	}

	/*
	// ways2 のデバッグ用出力
	rep(i, N + 1) {
		rep(j, N + 1) {
			cerr << ways2[i][j] << " ";
		}
		cerr << endl;
	}
	*/

	// ways の事前計算
	rep(i, N + 1) {
		rep(j, i + 1) {
			// ways2(i,j)*2^((N-i)j) を足す
			ways[i] += ways2[i][j] * powMod(2, (ll)(N - i) * j, M);
			ways[i] %= M;
		}
		// 2^(2^(N-i)) を掛ける
		ways[i] *= powMod(2, powMod(2, N - i, M - 1), M);
		ways[i] %= M;
	}

	// 余事象と包除原理に基づいて答えを計算
	ll ans = 0;
	rep(i, N + 1) {
		// 今回足し引きする値（Σの中身）
		ll val = (CombiMod(N, i, M, inv, fac, facInv) * ways[i]) % M;

		// i の偶奇で足し引きを切り替える
		if (i % 2 == 0) {
			ans = (ans + val) % M;
		}
		else {
			ans = (ans - val + M) % M;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;

//逆元(素数MOD)
long long inverse(long long b){
    /*
    Copyright (c) 2020 0214sh7
    https://github.com/0214sh7/library/
    */
  long long r=1,e=MOD-2;
  while(e){
      if(e&1){
          r=(r*b)%MOD;
      }
      b=(b*b)%MOD;
      e >>=1;
  }
  return r;
}

signed main(void){
    
    long long S;
    cin >> S;
    
    //dp[i]:=i桁の数列で条件を満たすものの数
    vector<long long> dp(S+1,0);
    vector<long long> dp_sum(S+1,0);
    
    for(long long i=3;i<=S;i++){
        //dp[i]=sum(dp[0],..,dp[i-3])+1
        
        dp[i] = (dp_sum[i-3]+1)%MOD;
        dp_sum[i] = (dp[i]+dp_sum[i-1])%MOD;
    }
    
    cout << dp[S] << endl;
    
    return 0;
}


Measured memory_bytes: 3640
import math

x,k,d=map(int, input().split())
if abs(x) > k*d:
    Ans = abs(x)-k*d
    print(Ans)
else:
    move = math.floor(abs(x) / d)
    oufuku = k - move
    if oufuku % 2 == 0:
        Ans =abs(abs(x)-d*move)
    else:
        Ans=abs(abs(x)-d*(move+1))
    print(Ans)

Measured memory_bytes: 8832
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, m;
string s, t;

int32_t main(){_
   
   int r;
   cin >> r;
   
   L pi = acosl(-1);
   cout << fixed << setprecision(15);
   cout<<2*pi*r<<endl;


   return 0;
}

Measured memory_bytes: 3828
#include<iostream>
#include<climits>
#include<algorithm>
using namespace std;
int main()
{
    int n, x, m[100], ans = 0, mini = INT_MAX;
    cin >> n >> x;
    for(int i = 0; i < n; i++){
        cin >> m[i];
        mini = min(mini, m[i]);
        x -= m[i];
        ans += 1;
    }
    cout << ans + x / mini << endl;
    return 0;

}

Measured memory_bytes: 256
N, M, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
SUM_A=[0 for _ in range(N+1)]
for i in range(N):
    SUM_A[i+1] = A[i] + SUM_A[i]
    if SUM_A[i+1] > K:
        N=i
        break

SUM_B=[0 for _ in range(M+1)]
for i in range(M):
    SUM_B[i+1] = B[i] + SUM_B[i]
    if SUM_B[i+1] > K:
        M=i
        break

cnt = N
for i in range(N+1)[::-1]:
    V=K-SUM_A[i]
    j = cnt-i
    while j < M+1 and SUM_B[j] <= V:
        j += 1
    j-=1
    if i+j > cnt:
        cnt = i+j
print(cnt)

Measured memory_bytes: 42688
#include<bits/stdc++.h>
using namespace std;
template<class T>inline void init(T&x){
	x=0;char ch=getchar();bool t=0;
	for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') t=1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+(ch-48);
	if(t) x=-x;return;
}
int n;
typedef pair<int,int> PA;
vector<PA>Ans;
const int N=1000;
int bel[N];
int main()
{
	init(n);
	if(n&1) {
		for(int i=1;i<=n;++i) {
			for(int j=i+1;j<=n;++j) {
				if(i+j==n&&j!=n) continue;
				Ans.push_back(PA(i,j));
			}
		}
	}
	else {
		for(int i=1;i<=n;++i) {
			for(int j=i+1;j<=n;++j) {
				if(i+j==n+1) continue;
				Ans.push_back(PA(i,j));
			}
		}
	}
	int num=Ans.size();
	cout<<num<<endl;
	for(int i=0;i<num;++i) {
		printf("%d %d\n",Ans[i].first,Ans[i].second);
	}
	return 0;
}


Measured memory_bytes: 384
for i in range(10**6):
    W,H=map(int,input().split())
    if H==0 and W==0:
        exit()
    L=[]
    l=[0 for j in range(W+2)]
    L.append(l)
    for h in range(H):
        a=list(map(int,input().split()))
        a=[0]+a+[0]
        L.append(a)
    L.append(l)
    
    P=[[-1 for w in range(W+2)]for h in range(H+2)]
    for h in range(1,H+1):
        for w in range(1,W+1):
            P[h][w]=(h-1)*W+(w-1)
    Size=[[0 for w in range(W+2)]for h in range(H+2)]
    #print(P)
    def find(a):
        x=a%W+1
        y=a//W+1
        if P[y][x]==a:
            return a
        else:
            return find(P[y][x])
    def union(b,c):
        B=find(b)
        C=find(c)
        if B!=C:
            P[C//W+1][C%W+1]=P[B//W+1][B%W+1]
    for h in range(1,H+1):
        for w in range(1,W+1):
            if L[h][w]==1:
                if L[h-1][w-1]==1:
                    union(P[h][w],P[h-1][w-1])
                if L[h-1][w]==1:
                    union(P[h][w],P[h-1][w])
                if L[h][w-1]==1:
                    union(P[h][w],P[h][w-1])
                if L[h-1][w+1]==1:
                    union(P[h][w],P[h-1][w+1])
                if L[h+1][w-1]==1:
                    union(P[h][w],P[h+1][w-1])
                
    cnt=0
    for h in range(1,H+1):
        for w in range(1,W+1):
            P[h][w]=find(P[h][w])
            if L[h][w]==1 and P[h][w]==(h-1)*W+(w-1):
                cnt+=1
    #print(L)
    #print(P)
    print(cnt)


Measured memory_bytes: 6256
a,b,c=map(int, input().split())
if a == 0 and b == 0 and c == 0 :
    print("Close")
elif a == 1 and b == 0 and c == 0 :
    print("Close")
elif a == 0 and b == 1 and c == 0 :
    print("Close")
elif a == 1 and b == 1 and c == 0 :
    print("Open")
elif a == 0 and b == 0 and c == 1 :
    print("Open")
else :
    print("")


Measured memory_bytes: 5596
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    int n, p;
    cin >> n >> p;
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    
    if (p == 2 || p == 5) {
        ll ans = 0;
        rep(i, n) {
            int x = s[i] - '0';
            if (x % p == 0) ans += n - i;
        }
        cout << ans << endl;
        return 0;
    }
    
    vector<int> sum(n);
    int mul = 1;
    rep(i, n) {
        int x = s[i] - '0';
        x = (x * mul) % p;
        sum[i] = x;
        mul = (mul * 10) % p;
    }
    rep(i, n-1) sum[i+1] += sum[i], sum[i+1] %= p;
    map<int, int> mp;
    ll ans = 0;
    rep(i, n) {
        ans += mp[sum[i]];
        mp[sum[i]]++;
    }
    ans += mp[0];
    cout << ans << endl;
}


Measured memory_bytes: 4644
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
int main() {
	cin.tie(0);ios::sync_with_stdio(false);
	int n, w, d; 
	while (cin >> n >> w >> d,n|w|d) {
		vector<pi> rec;
		rec.push_back({ w,d });
		for (int i = 0; i < n; i++) {
			int p, s; cin >> p >> s;
			p--;
			int W = rec[p].first, D = rec[p].second;
			rec.erase(rec.begin() + p);
			int len = (W + D);
			s %= len;
			int area1, area2;
			int w1, w2, d1, d2;
			if (s >= 0 && s <= W) {
				w1 = s, d1 = D, w2 = W - s, d2 = D;
			}
			else {
				w1 = W, d1 = s - W, w2 = W, d2 = (W + D) - s;
			}
			area1 = w1*d1, area2 = w2*d2;
			if (area1 < area2) {
				rec.push_back({ w1,d1 });
				rec.push_back({ w2,d2 });
			}
			else {
				rec.push_back({ w2,d2 });
				rec.push_back({ w1,d1 });
			}
		}
		vector<int> ans(rec.size());
		for (int i = 0; i < rec.size();i++) ans[i] = rec[i].first*rec[i].second;
		sort(ans.begin(), ans.end());
		for (int i = 0; i < ans.size();i++) {
			if (i != 0)cout << " ";
			cout << ans[i];
		}
		cout << endl;
	}
}

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

int main() {
  int a, b, h, m;
  cin >> a >> b >> h >> m;
 double PI= 3.141592653589793238;
 double rada = 30*h + 0.5*m;
 double radb = 6*m;
 double rad = rada - radb;
 double coscos = cos(rad*PI/180);
 
 double x = a*a + b*b -2*a*b*coscos;
 double y = sqrt(x);
 cout << fixed << setprecision(20);
 cout << y << endl;
}

Measured memory_bytes: 4224
#include <stdio.h>
#include <string.h>
int main(void)
{
  int l[100],a,b,d,i,j=0,k,n,p,x,y,z=0;
  char s[500],c[500];

  scanf("%d%d",&n,&d);

  z=2*d+1;
  while(n>0){
    n=n-z;
    j++;
  }
  printf("%d\n",j);
  return 0;
}

Measured memory_bytes: 1732
/*Be patient && calm!
All our dreams can come true, if we have the courage to pursue them.
I fear not the man who has practiced 10,000 kicks once, but I fear the man who has practiced one kick 10,000 times.
Do not pray for an easy life, pray for the strength to endure a difficult one.
When something is important enough, you do it even if the odds are not in your favor.
First, solve the problem. Then, write the code.
Fix the cause, not the symptom.
Simplicity is the soul of efficiency.
Make it work, make it right, make it fast.
No matter how hard it gets, NEVER GIVE UP*/

#include <bits/stdc++.h>

#define pb push_back
#define MP make_pair
#define ALL(r) (r).begin(),(r).end()

typedef long long int ll;

#define FOR(i,m,n) for(ll i=(ll)(m) ; i < (ll) (n) ; ++i )
#define FORN(i,m,n) for(ll i=(ll)(m-1) ; i >= (ll) (n) ; --i )

#define RUN_FAST ios::sync_with_stdio(false);

using namespace std;



void solve()
{
    ll a,b,c,d,m,n,p,q,r,x,y,z,aa,bb,cc,dd; //variable
    ll i,j,k,l; //pointer
    ll cnt=0,cnt1=0,cnt2=0,cnt3=0,sum=0,mx=LLONG_MIN,mn=LLONG_MAX; //counter
    ll flag=0,flag2=0; //flag
    vector <ll> vec1,vec2,vec3;
    string s1,s2,s3;

    //PULOK SAHA
    //BMO

    cin >> a >> b >> c >> d;
    x=a*c;
    y=a*d;
    p=b*c;
    q=b*d;

    cout << max(x,max(y,max(p,q))) << endl;

}

int main()
{
    RUN_FAST
    //PULOK SAHA
    //BMO

    ll t=1;//test case

    //cin >> t;
    while(t--)
    {
        solve();
    }

    return 0;
}






//PULOK SAHA

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
constexpr int c[] = { 500, 100, 50, 10, 5, 1 };

int main() {
  int a;
  while (cin >> a, a) {
    int b = 1000 - a;
    int ans = 0;
    for (int i = 0; i < 6; i++) {
      ans += b / c[i];
      b %= c[i];
    }
    cout << ans << "\n";
  }
}


Measured memory_bytes: 3044
#pragma region Include/Defines
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <limits.h>
#include <vector>
#include <stdlib.h>
#include <algorithm>
#include <memory.h>
#include <string.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <functional>
#include <cassert>
#include <map>
#include <set>
#include <iostream>
#include <queue>
#include <time.h>

using namespace std;
typedef long long lli;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef pair<int, int> pii;
typedef pair<lli, lli> pll;
typedef vector<pii> vpii;
typedef vector <pll> vpll;
typedef long double ld;
#define all(a) std::begin(p), std::end(p)

const int INF = 0x3f3f3f3f;
const lli LINF = 0x3f3f3f3f3f3f3f3f;

template<typename T, typename T2> inline void _max(T &a, T2 b) { a = max((T)a, (T)b); }
template<typename T, typename T2> inline void _min(T &a, T2 b) { a = min((T)a, (T)b); }

#ifdef _DEBUG
#define epr(...) fprintf(stderr,__VA_ARGS__)
#else
#define epr(...) 
#endif
#pragma endregion


const int MAX = 1e5 + 10;
int n, p[MAX];

void clear() {
}

void read() {
	for (int i = 0; i < n; i++) scanf("%d", &p[i]);
}

void solve() {
	int tc = 0, res = 0;
	for (int i = 0; i < n; i++)
		if (i + 1 == p[i]) tc++;
		else {
			res += (tc + 1) / 2;
			tc = 0;
		}
	res += (tc + 1) / 2;
	printf("%d\n", res);
}

int main() {
#ifdef _LOCAL_VAN
	freopen("in.txt", "r", stdin);
#endif
	while (scanf("%d", &n) == 1) {
		clear();
		read();
		solve();
#ifndef _LOCAL_VAN
		return 0;
#endif
	}
	return 0;
}

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

const int N = 8000000;

int main() {
    int n, m;
    while (cin >> m >> n and (n or m)) {
        int t = m;
        bool flag[N];
        rep(i, N) flag[i] = false;
        rep(i, n) {
            for (; flag[m]; ++m) {}
            flag[m] = true;
            for (int j=m+m; j<=N; j+=m) {
                flag[j] = true;
            }
        }
        for (int i=t; i<=N; ++i) {
            if (!flag[i]) {
                cout << i << endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 10796
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var count = 0;
            for (var i = 1; i <= N; i++)
            {
                if (i < 10) count++;
                if (i >= 100 && i <= 999) count++;
                if (i >= 10000 && i <= 99999) count++;
            }
            Console.WriteLine(count);
        }
    }
}


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

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

int N;
s64 cand[] = {7, 5, 3};

bool ok(s64 x)
{
    bool t = false, f = false, s = false;
    while (x)
    {
        if (x % 10 == 3) t = true;
        else if (x % 10 == 5) f = true;
        else if (x % 10 == 7) s = true;
        x /= 10;
    }
    return t & f & s;
}

s64 dfs(s64 x)
{
    if (x > N) return 0;

    int ret = 0;
    if (ok(x)) ret = 1;

    rep (i, 3)
    {
        ret += dfs(x * 10 + cand[i]);
    }
    return ret;
}

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

    cin >> N;
    int ans = 0;
    rep (i, 3)
    {
        ans += dfs(cand[i]);
    }
    cout << ans << "\n";
    return 0;
}



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



int main() {
  int a, b, x;
  cin >> a >> b >> x;
  if (x >= a && x <= a + b) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 3564
/**
 *     author: qodjf
 *     created: 04.17.2020 13:05:16
 */
#include <bits/stdc++.h>
using namespace std;

string to_string(string s) { return '"' + s + '"'; }

string to_string(const char *s) { return to_string((string)s); }

string to_string(bool b) { return (b ? "true" : "false"); }

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define dbg(...) 42
#endif

#define mst(x, a) memset(x, a, sizeof(x))

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const ll MOD = 1e9 + 7;

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

int H, W;
vector<string> m;

int dp[110][110];

int main() {
  cin >> H >> W;
  m.resize(H);
  for (int i = 0; i < H; i++) {
    cin >> m[i];
  }

  dp[0][0] = m[0][0] == '#';
  for (int j = 1; j < W; j++) {
    if (m[0][j] == '#') {
      dp[0][j] = dp[0][j - 1] + (m[0][j - 1] == '.');
    } else {
      dp[0][j] = dp[0][j - 1];
    }
  }
  for (int i = 1; i < H; i++) {
    if (m[i][0] == '#') {
      dp[i][0] = dp[i - 1][0] + (m[i - 1][0] == '.');
    } else {
      dp[i][0] = dp[i - 1][0];
    }
  }
  for (int i = 1; i < H; i++) {
    for (int j = 1; j < W; j++) {
      if (m[i][j] == '#') {
        dp[i][j] = min(dp[i - 1][j] + (m[i - 1][j] == '.'),
                       dp[i][j - 1] + (m[i][j - 1] == '.'));
      } else {
        dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]);
      }
    }
  }

  cout << dp[H-1][W-1] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int S,h,m;
  cin>>S;
  h=S/(60*60);
  S%=(60*60);
  m=S/60;
  S%=60;
  cout<<h<<":"<<m<<":"<<S<<endl;
  return 0;
}



Measured memory_bytes: 3100
#include <stdio.h>

int l;
char s[105], t[105];

bool eq() {
  for (int i = 0; i < l; ++i) {
    if (s[i] != t[i]) return false;
  }
  return true;
}

int main() {
  scanf("%s %s", s, t);
  while (s[l]) ++l;
  for (int i = 0; i < l; ++i) {
    if (eq()) {
      puts("Yes");
      return 0;
    }
    char c = s[l - 1];
    for (int j = l - 1; j > 0; --j) {
      s[j] = s[j - 1];
    }
    s[0] = c;
  }
  puts("No");
  return 0;
}



Measured memory_bytes: 128
#include <iostream>
using namespace std;
#include <string>
#include <algorithm>
int main()
{
    char s[20];
    cin>>s;
    for(int i=0;s[i];i++)
    {
        if(s[i]==',')
            s[i]=' ';
    }
    cout<<s;
    return 0;
}



Measured memory_bytes: 256