akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using vll = vector<ll>;
using vi = vector<int>;
using vb = vector<bool>;
using pii = pair<int, int>;

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

//pow(llpow,modpow)
template <class T>
ll llpow(ll x, T n)
{
    ll ans = 1;
    if (x == 0)
        ans = 0;
    while (n)
    {
        if (n & 1)
            ans *= x;
        x *= x;
        n >>= 1;
    }
    return ans;
}
long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
template <class T>
inline T gcd(T x, T y)
{
    if (y == 0)
        return x;
    else
    {
        return gcd(y, x % y);
    }
}
//最小公倍数
template <class T>
inline T lcm(T x, T y) { return x / gcd(x, y) * y; }
//逆元
long long modinv(long long a, long long m)
{
    long long b = m, u = 1, v = 0;
    while (b)
    {
        long long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
#define white 0
#define gray 1
#define black 2

long long INF = 1LL << 60;
int main()
{
    int n;
    cin >> n;
    vector<pii> t[n];
    using plli = pair<ll, int>;
    rep(i, 0, n)
    {
        int u, k;
        cin >> u;
        cin >> k;
        rep(j, 0, k)
        {
            int v, c;
            cin >> v >> c;
            pii in = make_pair(v, c);
            t[u].push_back(in);
        }
    }
    vi state(n,white);
    vector<int> res(n, 1<<30);
    res[0]=0;
    priority_queue<plli, vector<plli>, greater<plli>> q; //cost,index
    q.emplace(0, 0);
    rep(i, 1, n)
    {
        q.emplace(1 << 30, i);

    }
    while (!(q.empty()))
    {
        pii node = q.top();
        q.pop();
        int index = node.second;
        int v = node.first;
        state[index]=black;
        if(res[index]<v)continue;
        res[index]=v;
        for (pii to : t[index])
        {
            if (state[to.first] != black && to.second + v < res[to.first] )
            {
                state[to.first]=gray;
                res[to.first]=to.second+v;
                q.emplace(res[to.first],to.first);
            }
        }
    }
    rep(i, 0, n) cout << i << " " << res[i] << endl;
    return 0;
}



Measured memory_bytes: 7916
#include<stdio.h>

int main(){
	
	int A,B,C,D;
	scanf("%d %d %d %d",&A,&B,&C,&D);
	
	
	if(D<=A||B<=C){
		printf("0");
		return 0;
	}else {
		if(C<A&&A<=D&&D<=B){
			printf("%d",D-A);
			return 0;
		}else if(C<A&&B<=D){
			printf("%d",B-A);
			return 0;
		}else if(A<=C&&D<=B){
			printf("%d",D-C);
			return 0;
		}else if(A<=C&&B<=D){
			printf("%d",B-C);
			return 0;
		}
	}
	
	
	
	return 0;
}

Measured memory_bytes: 128
from heapq import heappush, heappop

K = int(input())
hq = []
for i in range(1,10):
  heappush(hq,i)
cnt = 0
while(cnt < K):
  x = heappop(hq)
  cnt += 1
  for i in [-1,0,1]:
    d = (x%10)+i
    if 0 <= d <= 9:
      heappush(hq,x*10+d)
print(x)


Measured memory_bytes: 52048
/**
 * Author RDP
 * 
**/
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <bitset>
#include <iomanip>
#include <assert.h>
using namespace std;
#define endl '\n'
#define bp(x) __builtin_popcount(x)
#define zf(x) __builtin_clz(x)
#define zl(x) __builtin_ctz(x)
#define par(x) __bultin_parity(x)
#define all(x) (x).begin(), (x).end()
#define FAST_IO ios::sync_with_stdio(0); std::cin.tie(0);
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) 
{
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
typedef long long ll;
/* **************************************************************************************** */

void test_case()
{
	FAST_IO 
	ll n;
	cin >> n;
	vector <ll> a(n);
	for(ll &x : a) cin >> x;
	ll ans = 1;
	if(*min_element(all(a)) == 0)
	{
		cout << "0" << endl;
		return;
	}
	for(ll x : a) 
	{
		ans *= x;
		if(ans > 1000000000000000000LL || ans <= 0)
		{
			cout << "-1" <<endl;
			return;
		}
	}
	cout << ans << endl;
 	return ;
}
int main()
{
	FAST_IO
        test_case();
	return 0;
}

Measured memory_bytes: 3992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define vb vector <bool>
#define vvb vector <vb>
#define mp make_pair
#define vvll vector <vll>
#define vsi vector <si>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define MANX MAXN
#define itn int
#define in(x); { for (auto &to : x) cin>>to;}
#define out(x); { for (auto &to : x) cout<<to<<" ";cout<<'\n'; }

const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;

void solve()
{
    int n;
    cin>>n;
    vector <int> a(n),b(n);
    rep(i,n)
    cin>>a[i]>>b[i];
    bool ok=false;
    for (int i=0;i+2<n;i++)
    {
        int cnt=0;
        for (int j=0;j<3;j++)
        {
            cnt+=a[i+j]==b[i+j];
        }
        ok|=cnt==3;
    }
    cout<<(ok?"Yes":"No");

}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef Mip182
    freopen("a.in","r",stdin);
    #endif
    int _t;
    _t=1;
 //   cin>>_t;
    while (_t--)
        solve();
    //n=1 ?
    //recursion - matrix exponential
    //linear algebra - just a joke
    //check ios_base, MAXN, mod1 before submit
    //if debug more than 15 minutes - write stress
    //compression
}

Measured memory_bytes: 3644
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		str = str.replaceAll("apple", "aaaaa");
		str = str.replaceAll("peach", "apple");
		str = str.replaceAll("aaaaa", "peach");
		System.out.println(str);
	}
}

Measured memory_bytes: 25804
#include<stdio.h>
int main()
{
    int n,i,j,c1,c2;
    scanf("%d",&n);
    for(i=1,c1=0;i<=n;i=i+2)
    {
        for(j=2,c2=1;j<i;j++)
        {
            if(i%j==0) c2++;
        }
        c2++;
        if(c2==8) {c1++;};
    }
    printf("%d\n",c1);
    return 0;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline

def linput():
    return [int(x) for x in input().split()]

n, m = linput()
a = linput()

cnt = 0

for i in a:
    if sum(a) <= 4*m*i:
        cnt += 1

if cnt >= m:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38512
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next().toUpperCase();
        char a[] = s.toCharArray();
         int count = 0 ;
        for(int j = 0 ; j<a.length -1 ; j++)
        {
        
              if(a[j+1]==a[j]){
                 count++;
                   break ;
              }  
             
              }
        
          
        
        if(count>0)System.out.println("Bad");
        else System.out.println("Good");
    }
    
    
    
}


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

int main() {
  long long ans;
  long long x;
  long long k;
  long long d;
  cin >> x >> k >> d;
  if (abs(x) / d > k || ((abs(x) / d == k) && ((abs(x) % d) > 0))) {
    //cout << "A" << endl;
    ans = abs(x) - (k * d);
  } else {
    //cout << "B" << endl;
    long long n;
    n = abs(x) / d;
    if ((k - n) % 2) {
      ans = abs(x) - ((n + 1) * d);
    } else {
      ans = abs(x) - (n * d);
    }
  }
  cout << abs(ans) << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;

int main(){
	int i, n;
	cin >> n;
	int a[n];

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

	int max = 0;
	int max2 = 0;

	for(i = 0; i < n; i++){
		if (a[i] > max) {
			max = a[i];
		} else if (a[i] > max2 && max >= a[i]) {
			max2 = a[i];
		} else {
		}
	}

	if (max == max2) {
		for(i = 0; i < n; i++){
			cout << max << endl;
		}
		return 0;
	}

	for(i = 0; i < n; i++){
		if (a[i] == max) {
			cout << max2 << endl;
		} else {
			cout << max << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>

//ある差をミニマムで毎回その繰り返しの中で評価してあげればいい。別に、ミニマムだけだからね。必要なのは。おもしろ
//こうやって、どういう発想がとな、学んでいけ。もちろん考えることも。一体なんだとこれ自身はなんなのかと考えていくこと。
//別の視点でやってみよう。逆にすべての和をだして、それを引いていけば早くね？

int sa(int w[],int n) {

	int i,j;
	int goukei;
	int min, total=0;
	int henkawa=0;
	int syokiti=0;
	

	for (i = 1; i <= n; i++) {

		total = total + w[i];

	}
	
	min = (total - w[1])-w[1];
	syokiti = w[1];

	for (i = 2; i <= n; i++) {
		syokiti = syokiti + w[i];
		if ((total - syokiti) > syokiti) {
			henkawa = (total - syokiti) - syokiti;
		}
		else if ((total-syokiti<syokiti)){
			henkawa = syokiti - (total - syokiti);
		}

		else {
			henkawa = 0;
		}

	


		
		if (min > henkawa) {
			min = henkawa;
		}
	}

	return min;

}


int main()
{
	int N;
	int i;
	int W[100];

	scanf("%d", &N);

	for (i = 1; i <= N; i++) {
		scanf("%d", &W[i]);
	}

	printf("%d\n", sa(W, N));

	return 0;


}

Measured memory_bytes: 128
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n, m, q = readline() |> split |> parseMap
	nn = zeros(Int, n, n)
	for i in 1:m
		l,r = readline() |> split |> parseMap
		nn[l,r] += 1
	end
	sn = zeros(Int, n, n)
	for i in 1:n
		sn[i,1] = nn[i,1]
		for j in 2:n
			sn[i,j] = sn[i,j-1]+nn[i,j]
		end
	end
	for i in 1:q
		s,t = readline() |> split |> parseMap
		sum = 0
		for i in s:t
			if s == 1
				sum += sn[i,t]
			else
				sum += sn[i,t]-sn[i,s-1]
			end
		end
		println(sum)
	end
end

main()

Measured memory_bytes: 155256
n,m = map(int,input().split())
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

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

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
uf = UnionFind(n)
people = [[]for i in range(m)]
for i in range(n):
    a = list(map(int,input().split()))
    n1 = a.pop(0)
    for j in range(n1):
        if len(people[a[j]-1]) == 0:
            people[a[j]-1].append(i)
        else:
            uf.union(people[a[j]-1][0],i)
if uf.group_count() == 1:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 14616
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>

#pragma region _define

#define f(i,a,b) for(LL i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n,option) f(i,0,n)cout<<v[i]<<option;
#define all(a) a.begin(),a.end()
#define size(s) s.size()
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl
#define INF 1<<29

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using si = stack<LL>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using v_pi = vector<pi>;

#pragma endregion

#pragma region _graph

#define node 50  //グラフの最大位数　適宜変更
//bool graph[node][node]; bool visited[node] = { false };
#define link(a,b,m) f(i,0,m){cin>>a[i]>>b[i]; a[i]--; b[i]--; graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;}

#pragma endregion

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b)*b);
}

//階乗計算
LL factorial(LL n) {
	LL a = 1, ret = 1;
	while (a < n) {
		a++;
		ret *= a;
		//ret %= 1000000007;
	}
	return ret;
}

#pragma endregion

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

	int H, W, h, w;
	cin >> H >> W >> h >> w;
	cout << H * W - (w*H + h * W - h * w);
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

int N,D;
string s,prevs;
int crtd;
bool used[1001];

int main(){
  cin>>N>>s>>D;
  prevs=s;
  rep(i,N){
    if(crtd<D&&s[i]=='0'){
      crtd++;
      used[i]=true;
      s[i]='1';
    }
  }
  if(crtd==D){
    cout<<s<<endl;
    return 0;
  }
  s=prevs;
  rep(i,N)s[i]='0'+'1'-s[i];
  crtd=N;
  rep(i,N){
    if(crtd>D&&s[i]=='0'){
      s[i]='1';
      crtd--;
    }
  }
  cout<<s<<endl;
  return 0;
}



Measured memory_bytes: 3212
#pragma region

#include "bits/stdc++.h"
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;

using namespace std;
using ll = long long;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "vec[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

ll func(ll a) {
  if (a == 0) return 0;
  return func(a / 2) + 1;
}

int main() {
  init();

  ll H;
  cin >> H;

  ll a = func(H);

  out((1LL << a) - 1);
}


Measured memory_bytes: 256
#

import sys
input=sys.stdin.readline

def main():
    A,B=map(int,input().split())
    for i in range(1,1001):
        if int(i*0.08)==A and int(i*0.1)==B:
            print(i)
            exit()
    print(-1)
    
if __name__=="__main__":
    main()


Measured memory_bytes: 61692
#include<iostream> 
#include<cstdio>
#include<cstring>
#include<math.h>
using namespace std; 
long long s[87];
int main() 
{ 
	s[0]=2;
	s[1]=1;
	int n;
	cin>>n;
	for(int i=2;i<=n;i++)
	{
		s[i]=s[i-1]+s[i-2];
	}
	cout<<s[n];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define db double
using namespace std;
 
const int MAXN = 200200;
const int MAXE = 400400;
const int INF = 0x3f3f3f3f;
 
template<typename T> inline void CheckMax(T &A, T B) {
	A < B ? A = B : A;
}
 
template<typename T> inline void CheckMin(T &A, T B) {
	A > B ? A = B : A;
}
 
template <typename T> inline void read(T &x) {
    int c = getchar();
    bool f = false;
    for (x = 0; !isdigit(c); c = getchar()) {
        if (c == '-') {
            f = true;
        }
    }
    for (; isdigit(c); c = getchar()) {
        x = x * 10 + c - '0';
    }
    if (f) {
        x = -x;
    }
}
 
int n;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
#define X first
#define Y second
 
signed main() {
	read(n);
	if(n == 25) puts("Christmas");
	else if(n == 24) puts("Christmas Eve");
	else if(n == 23) puts("Christmas Eve Eve");
	else puts("Christmas Eve Eve Eve");
	return 0;
}

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

using namespace std;

int main(){
  int n;
  int m;
  int x;
  cin >> n >> m >> x;
  vector<vector<int>> c(n, vector<int>(m+1));
  vector<int> ans;
  ans.push_back(1000000000);
  vector<int> a(m+1);
  for(int i=0;i<n;i++){
    for(int j=0;j<m+1;j++){
      cin >> c.at(i).at(j);
    }
  }

  for(int tmp=0;tmp < (1<<12); tmp++){
    bitset<12> bit(tmp);
    for(int j=0;j<m+1;j++){
      a.at(j)=0;
    }
    bool flag=false;
    for(int i=0;i<n;i++){
      if(bit.test(i)){
        for(int j=0;j<m+1;j++){
          a.at(j) += c.at(i).at(j);
        }
      }
    }
    for(int j=1;j<m+1;j++){
      if(a.at(j)<x){
        flag=true;
      }
    }
    if(!flag){
      ans.push_back(a.at(0));
    }
  }
  sort(ans.begin(), ans.end());
  if(ans.at(0)==1000000000){
    cout << -1 << endl;
  }
  else{
    cout << ans.at(0) << endl;
  }
  return 0;
}


Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define en "\n"
#define pair <int, int> pii
#define all(x) x.begin(),x.end()
#define loop(i,q,n) for(int i=q;i<n;i++)
#define dloop(i,a,b) for(int i=a;i>=b;i--)
#define speed ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
const ld PI = 3.14159265358979323;
const ll mod = 1e9+7;
const int N=1000001;
//******************************************************************************             
int gcd(int a,int b)
{
	if(b==0)return a;
	else return gcd(b,a%b);
}
int dp[1001][1001];
int main()
{
	speed;
	int a,b;
	cin>>a>>b;
	char grid[a+1][b+1];
	loop(i,1,a+1)loop(j,1,b+1)cin>>grid[i][j];
	dp[1][1]=0;
	loop(i,1,a+1)
	{
	    if(grid[i][1]=='#')break;
	    else dp[i][1]=1;
	}
	loop(i,1,b+1)
	{
	    if(grid[1][i]=='#')break;
	    else dp[1][i]=1;
	}
	loop(i,2,a+1)loop(j,2,b+1)
	{
	    if(grid[i][j]=='#')dp[i][j]=0;
	    if(grid[i][j-1]!='#')dp[i][j]+=dp[i][j-1];
        if(grid[i-1][j]!='#')dp[i][j]+=dp[i-1][j];
        if(dp[i][j]>=mod)dp[i][j]-=mod;
	}
	cout<<dp[a][b];
	return 0;
}

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

int main()
{
    string s;

    cin >> s;

    if (s == "SUN")
    {
        cout << 7 << endl;
    }
    else if (s == "MON")
    {
        cout << 6 << endl;
    }
    else if (s == "TUE")
    {
        cout << 5 << endl;
    }
    else if (s == "WED")
    {
        cout << 4 << endl;
    }
    else if (s == "THU")
    {
        cout << 3 << endl;
    }
    else if (s == "FRI")
    {
        cout << 2 << endl;
    }
    else if (s == "SAT")
    {
        cout << 1 << endl;
    }
}


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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

//===


const int INF = int(1e9 + 7);


int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, M;
	cin >> N >> M;
	vector<Vi> to(N);
	for (int i = 0; i < M; ++i) {
		int u, v;
		cin >> u >> v;
		--u, --v;
		to[u].push_back(v);
	}
	int S, T;
	cin >> S >> T;
	--S; --T;

	auto pdist = new array<array<int, 3>, 100005>;
	auto& dist = *pdist;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < 3; ++j) {
			dist[i][j] = INF;
		}
	}

	queue<Pii> q;
	q.emplace(S, 0);
	dist[S][0] = 0;
	while (!q.empty()) {
		int v = q.front().first;
		int l = q.front().second;
		q.pop();
		for (const auto& u : to[v]) {
			int nl = (l + 1) % 3;
			if (dist[u][nl] != INF) continue;
			dist[u][nl] = dist[v][l] + 1;
			q.emplace(u, nl);
		}
	}

	int ans = dist[T][0];
	delete pdist;
	if (ans == INF) ans = -1;
	else ans /= 3;
	cout << ans << endl;
}


Measured memory_bytes: 6912
#include <stdio.h>
#include <iostream>

using namespace std;

int main(){
    int n,q;
    int s[100010];
    int t[50010];
    int ans=0;
    cin>>n;
    for(int i=0;i<n;i++) cin>>s[i];
    cin>>q;
    for(int i=0;i<q;i++) cin>>t[i];

    for(int ti=0;ti<q;ti++){
        int left=0;int right=n-1;
        while(1)
        {
            int mid=(left+right)/2;
            if(t[ti]<s[mid]) right=mid;
            if(t[ti]>s[mid]) left=mid+1;
            if(t[ti]==s[mid]){ans++;break;}
            if(left==right){if(s[left]==t[ti]){ans++;}break;}
        }
        
    }
    
    cout<<ans<<endl;
    return 0;
}

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

ll N;
void dfs(string s, char mx) {
  if (s.size() == N) {
    cout << s << '\n';
    return;
  }
  
  for (char c = 'a'; c <= mx + 1; c++) {
    dfs(s + c , max(c+0, mx+0));
  }
}

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

  cin >> N;
  dfs("", 'a' - 1);
  return 0;
}

Measured memory_bytes: 1536
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi

using namespace std;

int main() {
    int m, f, r;
    char score;
    for (auto i=0; i<50; i++) {
        cin >> m >> f >> r;
        if (m == -1 && f == -1 && r == -1) break;
        else if (m == -1 || f == -1) score = 'F';
        else if (m+f >= 80) score = 'A';
        else if (m+f >= 65) score = 'B';
        else if (m+f >= 50) score = 'C';
        else if (m+f >= 30 && r >= 50) score = 'C';
        else if (m+f >= 30 && r < 50) score = 'D';
        else if (m+f < 30) score = 'F';
        
        cout << score << endl;
    }
    return 0;
}


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n;
  cin >> n;
  vector<vl> node(n,vl(3));
  REP(i,n){
    node[i][0] = i;
    cin >> node[i][1];
    cin >> node[i][2];
  }
  vector<vl> edge(n,vl(9,0));
  sort(node.begin(),node.end(),[](vl a,vl b){return a[1]<b[1];});
  REP(i,n-1){
    //edge[node[i][0]].push_back(node[i+1][0]);
    //edge[node[i][0]].push_back(node[i+1][1]-node[i][1]);
    edge[node[i][0]][++edge[node[i][0]][0]] = node[i+1][0];
    edge[node[i][0]][++edge[node[i][0]][0]] = node[i+1][1]-node[i][1];
    //edge[node[i+1][0]].push_back(node[i][0]);
    //edge[node[i+1][0]].push_back(node[i+1][1]-node[i][1]);
    edge[node[i+1][0]][++edge[node[i+1][0]][0]] = node[i][0];
    edge[node[i+1][0]][++edge[node[i+1][0]][0]] = node[i+1][1]-node[i][1];
  }
  sort(node.begin(),node.end(),[](vl a,vl b){return a[2]<b[2];});
  REP(i,n-1){
    //edge[node[i][0]].push_back(node[i+1][0]);
    //edge[node[i][0]].push_back(node[i+1][2]-node[i][2]);
    edge[node[i][0]][++edge[node[i][0]][0]] = node[i+1][0];
    edge[node[i][0]][++edge[node[i][0]][0]] = node[i+1][2]-node[i][2];
    //edge[node[i+1][0]].push_back(node[i][0]);
    //edge[node[i+1][0]].push_back(node[i+1][2]-node[i][2]);
    edge[node[i+1][0]][++edge[node[i+1][0]][0]] = node[i][0];
    edge[node[i+1][0]][++edge[node[i+1][0]][0]] = node[i+1][2]-node[i][2];
  }

  // construct minimum spanning tree
  vector<bool> incl(n,false);
  auto cp = [](vl a,vl b){return a[1]>b[1];};
  ll ans = 0;
  ll cnt = 1;
  priority_queue<vl,vector<vl>,decltype(cp)> cand(cp);
  incl[0] = true;
  REP(j,edge[0][0]/2){
    cand.push({edge[0][2*j+1],edge[0][2*j+2]});
  }

  while(cnt<n){
    vl eg = cand.top();
    cand.pop();
    if(!incl[eg[0]]){
      incl[eg[0]] = true;
      cnt ++;
      REP(i,edge[eg[0]][0]/2){
        if(incl[edge[eg[0]][2*i+1]]) continue;
        cand.push({edge[eg[0]][2*i+1],edge[eg[0]][2*i+2]});
      }
      ans += eg[1];
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 23088
#include<stdio.h>
int main() {
	int W, H, x, y, r;
	int cx = 0, cy = 0;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	if (x - r >= 0 && x + r <= W) cx++;
	if (y - r >= 0 && y + r <= H) cy++;
	if (cx==1&&cy==1) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 2692
#include<iostream>
        using namespace std;
         
        int main(){
          int N,K,A[100000];
          cin>>N>>K;
          for(int i=0;i<N;i++){
            cin>>A[i];
          }
          
          if(N==K){
              cout<<1<<endl;
          }else cout<<(N-1)/(K-1)+!((N-1)%(K-1)==0)<<endl;
          
          return 0;
        }

Measured memory_bytes: 640
from collections import deque

s=input()
s=deque(s)
q=int(input())
ans=''
flg=0
for _ in range(q):
	query=list(map(str,input().split()))
	if query[0]=='1':
		flg=1-flg
	else:
		if flg:
			if query[1]=='1':
				s.append(query[2])
			else:
				s.appendleft(query[2])
		else:
			if query[1]=='1':
				s.appendleft(query[2])
			else:
				s.append(query[2])
if flg:
	t=[]
	for i in range(len(s)):
		t.append(s.pop())
	print(''.join(t))
else:
    print(''.join(s))

Measured memory_bytes: 8692
n = int(input())
lst = []

for i in range(n):
    s,p = input().split()
    p = int(p)
    lst.append([i+1,s,p])
    
lst = sorted(lst,key=lambda x:(x[1],-(x[2])))

for i in range(n):
    print(lst[i][0])

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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
//constexpr int INF = 1001001001;
constexpr ll INF = 1001001001001001001ll;
constexpr double EPS = 1e-10;
using number = long long;



int main() {
    int N, K; cin >> N >> K;
    vll h(N);
    rep(i, N) cin >> h[i];
    vll dp(N, INF);
    dp[0] = 0;
    rep(i, N) {
        for (int j = i + 1; j < min(i + K + 1, N); j++) {
            chmin(dp[j], dp[i] + abs(h[j] - h[i]));
        }
    }

    cout << dp[N - 1] << endl;
}


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

int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main() {
	static int N, A[100000], L[100010], R[100010], MAX = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	L[0] = A[0], R[N - 1] = A[N - 1];
	for (int i = 0; i < N - 1; i++) {
		L[i + 1] = gcd(L[i], A[i + 1]);
	}
	for (int i = N - 1; i > 0; i--) {
		R[i - 1] = gcd(R[i], A[i - 1]);
	}
	for (int i = 1; i < N; i++) {
		MAX = max(MAX, gcd(L[i - 1], R[i + 1]));
	}
	MAX = max(MAX, L[N - 2]);
	MAX = max(MAX, R[1]);
	cout << MAX << endl;
}

Measured memory_bytes: 1536
#include <iostream>
#include <string>

std::string solve(int a, int b, int c)
{
  const auto result = a == b && b == c;
  return result ? "Yes" : "No";
}

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

  std::cout << solve(a, b, c) << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>

using namespace std;

//#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

//ostream& operator << (ostream &a, const vector<int> &b) {
//    for (auto k : b) cout << k << " ";
//    return a;
//}

#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 10;
//    const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 179;
//    const ld PI = 3.1415926535;
#endif

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,sse3,sse4")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("fast-math")
//#pragma GCC target("avx2")
//#pragma GCC optimize("section-anchors")
//#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
//#pragma GCC optimize("vpt")
//#pragma GCC optimize("rename-registers")
//#pragma GCC optimize("move-loop-invariants")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC optimize("function-sections")
//#pragma GCC optimize("data-sections")

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(all(a));
    for (int i = 1; i < n; i++) {
        if (a[i] == a[i - 1]) {
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES";
}
/*

*/


Measured memory_bytes: 1024
lis = map(int, raw_input().split())

for i in range(len(lis)):
    j = i + 1
    for j in range(j, len(lis)):
        if lis[j] < lis[i]:
            tmp = lis[j]
            lis[j] = lis[i]
            lis[i] = tmp
print "%s %s %s" %(lis[0], lis[1],lis[2])

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

using namespace std;

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, N) for(int i=0; i<(N); i++)

using Graph = vector<vector<int>>;

int euqlid(int a, int b){
    if(b > a) swap(a,b);
    int r = 1;
    while(r=a%b){
        a = b;
        b = r;
    }
    return b;
}

int main(){
    int a, b, c, k, ans=0; cin >> k;
    REP(i,k){
        REP(j,k){
            REP(l,k){
                ans += euqlid(i+1,euqlid(j+1,l+1));
            }
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

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

    int a = 0;
    for(unsigned i=0; i<s.size(); ++i){
        if('0' <= s[i] && s[i] <= '9')
            a |= 1;
        else if('a' <= s[i] && s[i] <= 'z')
            a |= 2;
        else
            a |= 4;
    }

    if(a == 7 && s.size() >= 6)
        cout << "VALID" << endl;
    else
        cout << "INVALID" << endl;

    return 0;

}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

int main(){

    int N;cin>>N;
    int p[N];REP(i,N)cin>>p[i];
    REP(i,N)p[i]--;

    int cnt=0;
    REP(i,N){
        if(p[i]==i){
            cnt++;
            if(i<N-1)swap(p[i],p[i+1]);
        }
    }
    cout<<cnt<<endl;
    return 0;
}

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

long long dp[100010][3];

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, k; cin >> n >> k;
    int r, s, p; cin >> r >> s >> p;
    string t; cin >> t;
    long long ans = 0;
    for (int i = 0; i < k; i++) {
        if (t[i] == 'r') dp[i][2] = p;
        else if (t[i] == 's') dp[i][0] = r;
        else dp[i][1] = s;
        for (int j = i+k; j < n; j += k) {
            for (int x = 0; x < 3; x++) {
                for (int y = 0; y < 3; y++) {
                    if (x == y) continue;
                    if (t[j] == 'r') {
                        dp[j][y] = max(dp[j][y], dp[j-k][x] + (y == 2) * p);
                    } else if (t[j] == 's') {
                        dp[j][y] = max(dp[j][y], dp[j-k][x] + (y == 0) * r);
                    } else {
                        dp[j][y] = max(dp[j][y], dp[j-k][x] + (y == 1) * s);
                    }
                }
            }
        }
    }
    for (int i = 0; i < k; i++) {
        ans += max({dp[n-i-1][0], dp[n-i-1][1], dp[n-i-1][2]});
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 2768
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);

		int A[] = new int[3];

		A[0] = scan.nextInt();
		A[1] = scan.nextInt();
		A[2] = scan.nextInt();

		Arrays.sort(A);

		int sum;
		sum = A[2] - A[1];
		sum += A[1] - A[0];

		System.out.println(sum);
	}

	//***********************以下共通関数************************************************
	/**
	 * 文字列を反転して返す
	 * @param pStr 文字列
	 * @return 反転した文字列
	 */
	public static String myReverse(String pStr) {
		if (pStr.length() < 1) {
			return "";
		}

		StringBuffer sb = new StringBuffer(pStr);
		return sb.reverse().toString();
	}

	/**
	 * 余りを求める。
	 * @param a
	 * @param b
	 * @return 余り。余りがマイナスの時はプラスで返す。
	 */
	public static long myMod(long a, long b) {
		long ret = 0;

		ret = a % b;

		if (ret < 0) {
			ret += b;
		}

		return ret;
	}

	/**
	 * 乗数を求める ※mod対応
	 * @param kisu 基数
	 * @param josu 乗数
	 * @param primeNumMod_0 法 mod値 使わない場合は「0」
	 * @return
	 */
	public static long myPowWithMod(long kisu, long josu, long primeNumMod_0) {

		long ans = 1;

		//乗数が0の場合→1
		if (josu == 0)
			return 1;

		if (primeNumMod_0 == 0) {
			//modを使わないとき

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= kisu;
					josu = josu / 2;
				} else {
					//累乗が奇数の時
					ans *= kisu;
					josu--;
				}
			}

			return ans;

		} else {
			//modを使うとき

			//初めに桁を落とす
			kisu = myMod(kisu, primeNumMod_0);

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= myMod(kisu, primeNumMod_0);
					josu = josu / 2;

				} else {
					//累乗が奇数の時
					ans *= myMod(kisu, primeNumMod_0);
					josu--;

				}
			}

			return myMod(ans, primeNumMod_0);

		}

	}

}


Measured memory_bytes: 27092
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=998244353;
int main()
{
	int h, w, k;
    cin>>h>>w>>k;
    string s[11];
    for(int i=0; i<h; i++) cin>>s[i];
    int ans=h-1+w-1;
    for(int i=0; i<(1<<(h-1)); i++){
        vector<int> v(1);
        for(int j=0; j<h-1; j++){
            if(i&(1<<j)) v.push_back(j+1);
        }
        v.push_back(h);
        int sum=0;
        int cnt[11]={};
        int m=v.size()-1;
        bool nuee=0;
        for(int j=0; j<w; j++){
            int cnt1[11]={};
            bool dame=0;
            for(int l=0; l<m; l++){
                for(int p=v[l]; p<v[l+1]; p++){
                    if(s[p][j]=='1') cnt1[l]++;
                }
                if(cnt1[l]>k){
                    nuee=1;
                }
                if(cnt[l]+cnt1[l]>k) dame=1;
            }
            if(dame){
                sum++;
                for(int l=0; l<m; l++) cnt[l]=cnt1[l];
            }else{
                for(int l=0; l<m; l++) cnt[l]+=cnt1[l];
            }
        }
        if(nuee) continue;
        ans=min(ans, sum+m-1);
    }
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

# uneven numbers

if __name__ == "__main__":
    n = int(input())
    if n<10:
        print(n)
    elif n<100:
        print(9)
    elif n<1000:
        print(n-99+9)
    elif n<10000:
        print(909)
    elif n<100000:
        print(n-9999+909)
    elif n<1000000:
        print(90909)




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

int n, s, e, d;
char line[10][31];

bool right(int x, int y)
{
    return x < n - 1 && line[x][y] == '1';
}

bool left(int x, int y)
{
    return 0 < x && line[x-1][y] == '1';
}

int simulation()
{
    int x = s - 1;
    for(int y = 0; y < d; ++y){
        if(left(x, y)){
            x--;
        } else if(right(x, y)){
            x++;
        } 
    }
    return x + 1;
}

bool canAdd(int i, int j)
{
    if(line[i][j] == '1') return false;
    int l = i - 1, r = i + 1;
    if(0 <= l && line[l][j] == '1'){
        return false;
    }
    if(r < n - 1 && line[r][j] == '1'){
        return false;
    }
    return true;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    while(cin >> n, n){
        cin >> s >> e >> d;
        bool end = false;
        for(int j = 0; j < d; ++j){
            for(int i = 0; i < n - 1; ++i){
                cin >> line[i][j];
            }
        }
        
        if(simulation() == e) {
            cout << 0 << endl;
            continue;
        } 
        for(int j = 0; j < d && !end; ++j){
            for(int i = 0; i < n - 1 && !end; ++i){
                if(canAdd(i, j)){
                    line[i][j] = '1';
                    if(simulation() == e){
                        cout << j + 1 << ' ' << i + 1 << endl;
                        end = true;
                    }
                    line[i][j] = '0';
                }
            }
        }
        if(!end){
            cout << 1 << endl;
        }
    }
}

Measured memory_bytes: 1192
//
// Created by WUOG on 2020/9/13.
//



#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
typedef long long ll;
using namespace  std;
int main() {
  ll a,b,c,d;cin>>a>>b>>c>>d;
  // a<0 b>0
  if(a<=0&&b>=0&&c<=0&&d>=0)cout<<max(a*c,b*d)<<endl;
  else if(a<=0&&b>=0&&c<=0&&d<=0)cout<<a*c<<endl;
  else if(a<=0&&b>=0&&c>=0&&d>=0)cout<<b*d<<endl;
  //a<0 b<0
  else if(a<=0&&b<=0&&c>=0&&d>=0)cout<<b*c<<endl;
  else if(a<=0&&b<=0&&c<=0&&d>=0)cout<<a*c<<endl;
  else if(a<=0&&b<=0&&c<=0&&d<=0)cout<<a*c<<endl;
 // a>0 b>0
  else if(a>=0&&b>=0&&c<=0&&d<=0)cout<<a*d<<endl;
  else if(a>=0&&b>=0&&c<=0&&d>=0)cout<<b*d<<endl;
  else if(a>=0&&b>=0&&c>=0&&d>=0)cout<<b*d<<endl;
  return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int maxM = 1e5+7;
const int maxV = 90010;
 
const int MOD = 1e9+7;
 
int T;
const int maxN = 1e5+8;
const ll INF = 1000000000000000010LL;
const int K = 15;
ll a[maxN];
ll b[maxN];
int n;



int main() {
	string s;
	cin>>s;
	n = s.size();
	set<int> HL;
	set<int> HR;
	for(int i=0;i<n-1;i++)
	{
		if(s[i] == 'R' && s[i+1] =='L')
		{
			HR.insert(i);
			HL.insert(-(i+1));
			
		}
	}
	vector<int> v(n);
	for(int i=0;i<n;i++)
	{
		if(s[i] == 'R')
		{
			auto it = HR.lower_bound(i);
			int x = *it;
			int y = x - i;
			if(y%2 == 0)
			{
				v[x]++;
			}
			else
			{
				v[x+1]++;
			}
		}
		else if(s[i] == 'L')
		{
			auto it = HL.lower_bound(-i);
			int x = - (*it);
			int y = i-x;
			if(y%2 == 0)
			{
				v[x]++;
			}
			else
			{
				v[x-1]++;
			}
		}
	}
	for(int i=0;i<n-1;i++)
	{
		printf("%d ",v[i]);
	}
	printf("%d\n",v[n-1]);
    return 0;
}

Measured memory_bytes: 5632
//Step 

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define YN(flag) (flag?"Yes":"No")
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll,ll>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    nvarep(n,a);
    int t = a[0];
    int ans = 0;
    rep(i,1,n){
        if(t<a[i])t=a[i];
        else {
            ans += t - a[i];
        }
    }
    cout<<ans<<nnn;
    return 0;
}

Measured memory_bytes: 4832
n = int(input())
a = [0 for _ in range(n)]
b = list(map(int, input().split()))
a[0] = b[0]
for i in range(n - 2):
    if b[i] > b[i + 1]:
        a[i + 1] = b[i + 1]
    else:
        a[i + 1] = b[i]
a[n - 1] = b[n - 2]
print(sum(a))


Measured memory_bytes: 3064
#include<bits/stdc++.h>                          
using namespace std;
int n,a[105],b[105],num,ans;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    num+=a[1];
    for(int i=1;i<=n;i++) cin>>b[i],num+=b[i];
    ans=num;
    for(int i=1;i<n;i++)
    {
    	num-=b[i];
    	num+=a[i+1];
    	ans=max(ans,num);
	}
	cout<<ans;
    return 0;
}
//68871358
//76140264
//25446011
//200841159
//914174775

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T>
using vec = vector<T>;

#define FOR(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define all(x) (x).begin(),(x).end()

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

  int ans=0;
  for(int i=1;i<n+1;i++){
    int wa=0,g=i;
    while(g != 0){
      wa += g%10;
      g /= 10;
    }
    if(wa >= a && wa <= b) ans += i;
  }

  cout <<ans <<endl;
}


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

void check(vector<vector<int>> &a, vector<vector<int>> &checked, int num) {
    for (int i=0; i<3; i++) {
        for (int j=0; j<3; j++) {
            if (num == a.at(i).at(j)) {
                checked.at(i).at(j)++;
                return;
            }
        }
    }
    return;
}

bool bingo(vector<vector<int>> &checked) {
    if (checked.at(0).at(0)==1 && checked.at(1).at(1)==1 && checked.at(2).at(2)==1) {
        return true;
    }
    if (checked.at(0).at(2)==1 && checked.at(1).at(1)==1 && checked.at(2).at(0)==1) {
        return true;
    }
    for (int i=0; i<3; i++) {
        if (checked.at(i).at(0)==1 && checked.at(i).at(1)==1 && checked.at(i).at(2) == 1) {
            return true;
        }
        if (checked.at(0).at(i)==1 && checked.at(1).at(i)==1 && checked.at(2).at(i) == 1) {
            return true;
        }
    }
    return false;
}

int main() {
    vector<vector<int>> a(3, vector<int>(3));
    vector<vector<int>> checked(3, vector<int>(3, 0));
    for (int i=0; i<3; i++) {
        for (int j=0; j<3; j++) {
            cin >> a.at(i).at(j);
        }
    }
    int n;
    cin >> n;
    vector<int> b(n);
    for (int i=0; i<n; i++) {
        cin >> b.at(i);
        check(a, checked, b.at(i));
    }
    if (bingo(checked)==1) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define eps 1e-7
#define PI acos(-1)
#define de(x) cout<<#x<<'='<<x<<" , "
#define dee(x) cout<<#x<<'='<<x<<endl
#define sz(x) x.size()
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define mset(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
typedef long long LL;
typedef pair<int,int> pii;
typedef vector<int> vi;
///-------------------------------------------
const int MAXN=255,INF=0x3f3f3f3f;

int dis[MAXN],vis[MAXN];
vector<int> town;
vector<pii> G[MAXN];
int N,M,R;
queue<int> q;
LL best=9999999999;
bool m_vis[MAXN];

int m_dis[MAXN][MAXN];
LL SPFA(int st){
    mset(vis,0),mset(dis,INF);
    while(!q.empty()) q.pop();
    dis[st]=0,vis[st]=1;
    q.push(st);
    while(!q.empty()){
        int v=q.front(); q.pop();
        vis[v]=0;
        rep(i,0,G[v].size()){
            int nx=G[v][i].fi,d=G[v][i].se;
            if(dis[nx]>dis[v]+d){
                dis[nx]=dis[v]+d;
                if(!vis[nx]){
                    vis[nx]=1;
                    q.push(nx);
                }
            }
        }
    }
    LL ret=0;
    rep(i,0,town.size()) m_dis[town[i]][st]=m_dis[st][town[i]]=min(dis[town[i]],m_dis[st][town[i]]);
    return ret;
}

void dfs(int pos,LL t){
    bool ok=0;
    rep(i,0,town.size()) if(!m_vis[town[i]]) ok=1;
    if(!ok){
        best=min(best,t);
        return;
    }
    rep(i,0,town.size()){
        if(m_vis[town[i]]) continue;
        m_vis[town[i]]=1;
        dfs(town[i],t+m_dis[pos][town[i]]);
        m_vis[town[i]]=0;
    }
}

int main(){
    scanf("%d %d %d",&N,&M,&R);
    int x,y,d;
    rep(i,0,R) {
        scanf("%d",&x);
        town.pb(x);
    }
    rep(i,0,M){
        scanf("%d %d %d",&x,&y,&d);
        G[x].pb(pii(y,d));
        G[y].pb(pii(x,d));
    }
    mset(m_dis,INF);
    //LL best=SPFA(town[0]);
    rep(i,0,town.size()){
        SPFA(town[i]);
    }
    rep(i,0,town.size()){
        m_vis[town[i]]=1;
        dfs(town[i],0);
        m_vis[town[i]]=0;
    }
    cout<<best<<endl;
}





















Measured memory_bytes: 896