akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
const ll INF = 1000000000001010;
int main(){
    ll ans=INF;
    ll n;cin>>n;
    for(ll i=1;i*i<=n;i++){
        ll j=INF;
        if(n%i==0){
            j=n/i;
            ans=min(ans,i+j);
        }
    }
    cout<<ans-2<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
using namespace std;

typedef long long ll;


int main() {
	int n, k; cin >> n >> k;
	vector<int> h(n);
	vector<ll> dp(n + 10, 1e18);
	for (int i = 0; i < n; i++) cin >> h[i];
	dp[0] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 1; j <= k && i + j < n; j++) {
			dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
		}
	}
	cout << dp[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int compare_lld(const void *a, const void *b)
{
  long long int *A = (long long int *)a;
  long long int *B = (long long int *)b;
  if (*A > *B) return 1;
  if (*A < *B) return -1;
  return 0;
}

int main(){
  long long int n,k,i;
  scanf("%lld",&n);
  scanf("%lld",&k);
  long long int h[n];
  for(i=0;i<n;i++) {
    scanf("%lld",&h[i]);
  }
  qsort(h, n, sizeof(long long int), compare_lld);
  long long int ans = h[n-1]-h[0];
  long long int temp = 0;
  for(i=0;i+k-1 < n;i++) {
    temp = h[i+k-1] - h[i];
    if(temp < ans) {
      ans = temp;
    }
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 1788
#include <iostream>
#include <cmath>

typedef long long ll;

using namespace std;

int main(){
    int N;  cin >> N;
    int a[N];
    ll sum = 0LL;
    for(int i=0; i<N; i++){
        cin >> a[i];
        sum += a[i];
    }

    ll sunuke = 0LL;
    ll ans = (ll) 2e10;
    for(int i=0; i<N-1; i++){
        sunuke += a[i];
        ans = min(ans, abs(sum - 2*sunuke));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
/*
ABHIJEET BISWAS
CSE 4th SEM 
MNNIT ALLAHBAD
https://atcoder.jp/contests/dp/tasks/dp_e
*/

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1e12
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pli pair<long long,int>
#define pll pair<long long,long long>
#define MAX 1000009
#define pb push_back
#define mp map<int,int>
#define f first
#define s second
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ld pi=2.0*acos(0.0);
ll arr[105][2];
ll dp[100008];
int main() {
	fastIO
	ll n,W;
	cin>>n>>W;
	ll ans =-1;
	for(int i=1;i<=n;i++)
	cin>>arr[i][0]>>arr[i][1];
	for(int i=1;i<=100000;i++)
	dp[i]=INF;
	for(int i=1;i<=n;i++)
	for(int j=100000;j>=1;j--)
	{
		if(j-arr[i][1]>=0)
		{
			dp[j]=min(dp[j],dp[j-arr[i][1]]+arr[i][0]);
		}
		if(dp[j]<=W)
		ans=max(ans,(ll)j);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
N = int(input())

import collections
l = []
for n in range(N):
  S = input()
  l.append(S)

c = collections.Counter(l)


print("AC x " + str(c['AC']))
print("WA x " + str(c['WA']))
print("TLE x " + str(c['TLE']))
print("RE x " + str(c['RE']))

Measured memory_bytes: 16384
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;

const int maxn = 12345;
int n , a[2][maxn];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(NULL);
	cin >> n;
	for(int j=0;j<2;j++)
		for(int i=0;i<n;i++)
			cin >> a[j][i];
			
	for(int j=0;j<2;j++)
		for(int i=1;i<n;i++)
			a[j][i] += a[j][i-1];
	
	int mx = a[0][0] + a[1][n-1];
	for(int i=1;i<n;i++)
	{
		mx = max(mx , a[0][i] + (a[1][n-1] - a[1][i-1]));
	}
	cout << mx;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

ll mod = 1000000007;

signed main()
{
    int n;
    cin >> n;
    vi c(100000);
    rep(i, 400)
    {
        rep(j, 400)
        {
            rep(k, 400)
            {
                ll a = (i + 1) * (i + 1) + (j + 1) * (j + 1) + (k + 1) * (k + 1) + (i + 1) * (j + 1) + (j + 1) * (k + 1) + (k + 1) * (i + 1);
                if (a < 10001)
                {
                    c[a]++;
                }
            }
        }
    }
    rep(i, n)
    {
        cout << c[i + 1] << endl;
    }
    return 0;
}

Measured memory_bytes: 3780
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;

int h, w, cost[1010][1010];
char c[1010][1010];
int dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0};

bool in(int y, int x) { return 0 <= y && y < h && 0 <= x && x < w; }
void solve()
{
    queue<P> que;
    rep(i, h) rep(j, w) if (c[i][j] == '#')
    {
        que.push(P(i, j));
        cost[i][j] = 0;
    }
    while (!que.empty())
    {
        P p = que.front();
        que.pop();
        int y = p.first, x = p.second;
        int now = cost[y][x];
        rep(i, 4)
        {
            int ny = y + dy[i], nx = x + dx[i];
            if (!in(ny, nx) || cost[ny][nx] != -1)
                continue;
            cost[ny][nx] = now + 1;
            que.push(P(ny, nx));
        }
    }
}

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

    cin >> h >> w;
    rep(i, h) rep(j, w) cin >> c[i][j];
    rep(i, h) rep(j, w) cost[i][j] = -1;
    solve();
    int ans = 0;
    rep(i, h) rep(j, w) ans = max(ans, cost[i][j]);
    cout << ans << endl;
}

Measured memory_bytes: 25524
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
using namespace std;

using VI = vector <int> ;
using VVI = vector <VI> ;

int main() {
    int A;
    int B;
    cin >> A >> B;

    // ceiling(0.08 P) >= A
    // ceiling(0.1 P) >= B
    // => P >= (A/0.08), P >= (B/0.1)

    const double eps = 1e-8;
    int LOW1 = (int)(A / 0.08 + eps);
    int LOW2 = (int)(B / 0.1 + eps);
    int MAXLOW = max(LOW1, LOW2);

    int ans = -1;
    for (int now = MAXLOW; true; ++now) {
        int TA = (int)(now * 0.08);
        int TB = (int)(now * 0.1);

        if (TA == A && TB == B) {
            ans = now;
            break;
        } else if (TA > A || TB > B) {
            break;
        }
    }

    cout << ans << endl;


    return 0;
}

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

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            String[] lines = br.readLine().split(" ");
            int n = Integer.parseInt(lines[0]);
            int x = Integer.parseInt(lines[1]);
            if (n == 0 && x == 0) {
                break;
            }
            int count = 0;
            int m = 0;
            for (int i = Math.max(1, x - n - (n - 1)); i <= Math.min(n - 2, x / 3); i++) {
                for (int j = Math.max(i + 1, x - n - i); j <= Math.min(n - 1, (x - i) / 2); j++) {
                    int k = x - i - j;
                    if (k <= n && k > j) {
                        count++;
                    }
                }
            }
            System.out.println(count);
        }
    }
}

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

flag = 1
counter = 0
while flag:
	flag = 0
	for i in reversed(range(1,N)):
		if A[i] < A[i-1]:
			A[i], A[i-1] = A[i-1], A[i]
			counter += 1
			flag = 1
print(" ".join(map(str, A)))
print(counter)

Measured memory_bytes: 7664
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
#include <numeric>
#include <map>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())
#define fi first
#define se second

void print(bool c)
{
    if (c)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

ll gcdll(ll a, ll b)
{
    while (1)
    {
        if (a < b)
            swap(a, b);
        if (b == 0)
            break;
        a %= b;
    }
    return a;
}

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

bool cmp(const pii &a, const pii &b)
{
    if (a.second != b.second)
        return a.second < b.second;
    return a.first < b.first;
}

int main()
{
    int n;
    cin >> n;
    vi a(n);
    int m1 = 0, m2 = 0;
    rep(i, 0, n)
    {
        cin >> a[i];
        if (a[i] > m1)
        {
            m2 = m1;
            m1 = a[i];
        }
        else if (a[i] > m2)
        {
            m2 = a[i];
        }
    }
    rep(i, 0, n)
    {
        if (a[i] == m1)
            cout << m2 << endl;
        else
            cout << m1 << endl;
    }
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<char> A(N), B(N);
    for(int i = 0; i < N; i++){
        cin >> A.at(i);
    }
    for(int i = 0; i < N; i++){
        cin >> B.at(i);
    }
    for(int i = 0; i < N; i++){
        cout << A.at(i) << B.at(i) ;
    }
}


Measured memory_bytes: 256
MOD=10**9+7
UPPERLIMIT=2*10**5
MODMUL=[1, 1]+[0]*(UPPERLIMIT-1)
for i in range(2, UPPERLIMIT+1):
  MODMUL[i]=MODMUL[i-1]*i%MOD
MODDIV=[1]*UPPERLIMIT+[pow(MODMUL[-1], MOD-2, MOD)]
for i in range(UPPERLIMIT, 0, -1):
  MODDIV[i-1]=MODDIV[i]*i%MOD
def MODCOMB(n, r):
  return (((MODMUL[n]*MODDIV[r])%MOD)*MODDIV[n-r])%MOD

N, M=map(int, input().split())

from collections import defaultdict
def PrimeFactorization(x):
  out=defaultdict(int)
  for i in range(2, int(pow(x, 1/2))+1):
    while x%i==0:
      out[i]+=1
      x//=i
  if x>1:
    out[x]+=1
  return out

primenums=PrimeFactorization(M)
ans=1
for x in primenums.values():
  ans*=MODCOMB(N+x-1, N-1)
  ans%=MOD
  
print(ans)

Measured memory_bytes: 26648
#include<stdio.h>
#include<algorithm>
using namespace std;
char str[30][31];
char val[30][31];
bool kie[30][31];
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	for(int i=0;i<a;i++)scanf("%s",str[i]);
	for(int i=0;i<a;i++){
		for(int j=0;j<b-1;j++){
			if(str[i][j]=='.'&&str[i][j+1]=='.')continue;
			for(int k=0;k<a;k++)
				for(int l=0;l<b;l++){
					val[k][l]=str[k][l];
				}
			char S=val[i][j];
			val[i][j]=val[i][j+1];
			val[i][j+1]=S;
			bool ok=true;
			//bool ze=true;

			for(int k=0;k<b;k++){
				int V=a-1;
				for(int l=a-1;l>=0;l--){
					if(val[l][k]!='.')val[V--][k]=val[l][k];
				}
				for(int l=V;l>=0;l--)val[l][k]='.';
			}
			do{
				//ze=ok;
				for(int k=0;k<a;k++)
					for(int l=0;l<b;l++)
						kie[k][l]=false;
				ok=false;
				for(int k=0;k<a;k++){
					char now=val[k][0];
					int ren=val[k][0]!='.'?1:0;
					for(int l=1;l<b;l++){
						if(val[k][l]=='.'){
							if(ren>=c){
								for(int m=l-ren;m<l;m++)kie[k][m]=true;
							}
							now=val[k][l];
							ren=0;
						}else{
							if(val[k][l]!=now){
								now=val[k][l];
								if(ren>=c){
									for(int m=l-ren;m<l;m++)kie[k][m]=true;
								}
								ren=1;
							}else ren++;
						}
					}
					if(ren>=c){
						for(int m=b-ren;m<b;m++)kie[k][m]=true;
					}
				}
				for(int k=0;k<b;k++){
					char now=val[0][k];
					int ren=val[0][k]!='.'?1:0;
					for(int l=1;l<a;l++){
						if(val[l][k]=='.'){
							if(ren>=c){
								for(int m=l-ren;m<l;m++)kie[m][k]=true;
							}
							now=val[l][k];
							ren=0;
						}else{
							if(val[l][k]!=now){
								now=val[l][k];
								if(ren>=c){
									for(int m=l-ren;m<l;m++)kie[m][k]=true;
								}
								ren=1;
							}else ren++;
						}
					}
					if(ren>=c){
						for(int m=a-ren;m<a;m++)kie[m][k]=true;
					}
				}
				for(int k=0;k<a;k++)
					for(int l=0;l<b;l++)
						if(kie[k][l]){
							val[k][l]='.';
							ok=true;
						}
				for(int k=0;k<b;k++){
					int V=a-1;
					for(int l=a-1;l>=0;l--){
						if(val[l][k]!='.')val[V--][k]=val[l][k];
					}
					for(int l=V;l>=0;l--)val[l][k]='.';
				}
			//	for(int k=0;k<a;k++)
			//	printf("%s\n",val[k]);
			}while(ok);
			ok=true;
			for(int k=0;k<a;k++)
				for(int l=0;l<b;l++)
					if(val[k][l]!='.')ok=false;
			if(ok){
				printf("YES\n");
				return 0;
			}
		}
	}
	printf("NO\n");
}

Measured memory_bytes: 1012
#include<stdio.h>

int main(void){
	int a,b,c,count;
	scanf("%d %d %d", &a,&b,&c);
	count = 3;
	if(a==b||a==c){
		count--;
	}
	if(b==c){
		count--;
	}
	printf("%d\n",count);
	return 0;
}


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

int s[10010], r[10010];

void link(int x, int y){
    if(r[x] > r[y]){
        s[y] = x;
    }else{
        s[x] = y;
        if(r[x] == r[y]){
            r[y] += 1;
        }
    }
}


int findSet(int x){
    if(x != s[x]) s[x] = findSet(s[x]);
    return s[x];
}

void unite(int x, int y){
    link(findSet(x), findSet(y));
}

void same(int x, int y){
    if(findSet(x) == findSet(y)){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }
}

int main(){
    int n, q;
    for(int i = 0; i < 10010; i++) s[i] = 9999999;
    cin >> n >> q;
    for(int i = 0; i < n; i++){
        s[i] = i;
        r[i] = 0;
    }


    int com, x, y;
    for(int i = 0; i < q; i++){
        cin >> com >> x >> y;
        if(com == 0){
            unite(x, y);
        }else{
            same(x, y);
        }
    }

    return 0;
}


Measured memory_bytes: 3160
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cmath>
#include<cstdint>
//#include<>
using namespace std;

#define rep(i,j) for(int i=0;i<(int)(j);i++)
const int INF=1<<30;//=10E10


struct Edge{
  int to,cost;
  Edge(int to_,int cost_):to(to_),cost(cost_){;}
};

vector< vector<Edge> > G;//??\?¶??????????


//???????????????????????????????????´???????´?????????§??????
vector<int> BellmanFord(int start){
  vector<int> dist(G.size(),INF);
  dist[start]=0;
  rep(cnt,G.size()){
    bool update=false;
    rep(i,G.size()){
      for(Edge e : G[i]){
        if(dist[i]!=INF && dist[e.to]>dist[i]+e.cost){
          dist[e.to]=dist[i]+e.cost;
          update=true;
          if(cnt==(int)G.size()-1)return vector<int>(0);
        }
      }
    }
    if(!update)break;
  }
  return dist;
}



int main()
{
  int v,e,r;cin>>v>>e>>r;
  G.resize(v);
  
  rep(i,e){
    int s,t,d;cin>>s>>t>>d;
    G[s].push_back(Edge(t,d));
  }
  
  vector<int> dist=BellmanFord(r);
  if(dist.size()==0)cout<<"NEGATIVE CYCLE"<<endl;
  else{
    for(auto d : dist){
      if(d==INF)cout<<"INF"<<endl;
      else cout<<d<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1264
<?php

$s = explode(' ', trim(fgets(STDIN)));
$n = explode(' ', trim(fgets(STDIN)));

$min = $max = 0;
for($i=0; $i<$s[1]; $i++){
  if ($n[$i] < $s[2]){
    $min++;
  } else if ($n[$i] > $s[2]){
    $max++;
  }
}

echo min($min,$max);

?>

Measured memory_bytes: 4728
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
int main()
{
  int n, d;
  cin >> n >> d;
  vector<vector<int>> x(n, vector<int>(d));
  rep(i, n)
  {
    rep(j, d) cin >> x[i][j];
  }
  int ans = 0;
  rep(i, n)
  {
    rep(j, i)
    {
      int sq = 0;
      rep(k, d)
      {
        int s = x[i][k] - x[j][k];
        sq += s * s;
      }
      int t = sqrt(sq) + 0.5;
      if (t * t == sq)
        ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
local mfl, mce = math.floor, math.ceil
local mmi, mma = math.min, math.max
local bls, brs = bit.lshift, bit.rshift
local bor = bit.bor
local SegTree = {}
SegTree.updateAll = function(self)
  for i = self.stagenum - 1, 1, -1 do
    local cnt = bls(1, i - 1)
    for j = 1, cnt do
      self.stage[i][j] = self.func(self.stage[i + 1][j * 2 - 1], self.stage[i + 1][j * 2])
    end
  end
end
SegTree.create = function(self, n, func, emptyvalue)
  self.func, self.emptyvalue = func, emptyvalue
  local stagenum, mul = 1, 1
  self.stage = {{}}
  while mul < n do
    mul, stagenum = mul * 2, stagenum + 1
    self.stage[stagenum] = {}
  end
  self.stagenum = stagenum
  self.left_stage = {}
  for i = 1, n do
    local sp, sz = 1, bls(1, stagenum - 1)
    while(i - 1) % sz ~= 0 do
      sp, sz = sp + 1, brs(sz, 1)
    end
    self.left_stage[i] = sp
  end
  self.sz_stage = {}
  local tmp, sp = 1, stagenum
  for i = 1, n do
    if tmp * 2 == i then tmp, sp = tmp * 2, sp - 1 end
    self.sz_stage[i] = sp
  end
  for i = 1, mul do self.stage[stagenum][i] = emptyvalue end
  self:updateAll()
end
SegTree.getRange = function(self, left, right)
  if left == right then return self.stage[self.stagenum][left] end
  local stagenum = self.stagenum
  local ret = self.emptyvalue
  while left <= right do
    local stage = mma(self.left_stage[left], self.sz_stage[right - left + 1])
    local sz = bls(1, stagenum - stage)
    ret = self.func(ret, self.stage[stage][1 + brs(left - 1, stagenum - stage)])
    left = left + sz
  end
  return ret
end
SegTree.update = function(self, idx)
  for i = self.stagenum - 1, 1, -1 do
    local dst = brs(idx + 1, 1)
    local rem = dst * 4 - 1 - idx
    self.stage[i][dst] = self.func(self.stage[i + 1][idx], self.stage[i + 1][rem])
    idx = dst
  end
end
SegTree.setValue = function(self, idx, value, silent)
  self.stage[self.stagenum][idx] = value
  if not silent then
    self:update(idx)
  end
end
SegTree.new = function(n, func, emptyvalue)
  local obj = {}
  setmetatable(obj, {__index = SegTree})
  obj:create(n, func, emptyvalue)
  return obj
end

local n = io.read("*n", "*l")
local s = io.read()
local st = SegTree.new(n, bor, 0)
for i = 1, n do
  local v = s:byte(i) - 96
  st:setValue(i, bls(1, v - 1))
end
local q = io.read("*n", "*l")
for iq = 1, q do
  local qstr = io.read()
  if qstr:byte(1) == 49 then
    local _u, pos, val = qstr:match("(%d) (%d+) (%w)")
    pos = tonumber(pos)
    val = val:byte(1) - 96
    st:setValue(pos, bls(1, val - 1))
  else
    local _u, l, r = qstr:match("(%d) (%d+) (%d+)")
    l = tonumber(l)
    r = tonumber(r)
    local v = st:getRange(l, r)
    local c = 0
    for i = 1, 26 do
      if v % 2 == 1 then c = c + 1 end
      v = brs(v, 1)
    end
    print(c)
  end
end


Measured memory_bytes: 21864
import scipy as sp


num_of_CA = 0

N, M, C = list(map(int, input().split()))
B_list = sp.array(list(map(int, input().split())))

for i in range(N):
    A_list = sp.array(list(map(int, input().split())))
    if sp.sum(A_list*B_list)+C > 0:
        num_of_CA += 1

print(num_of_CA)


Measured memory_bytes: 12520
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>
#include <iomanip>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	
	cout << max( {a * c, a * d, b * c, b * d} ) << endl;
	
	return 0;
}


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

namespace ConsoleApp7
{
    class Program
    {
        static void Main(string[] args)
        {
           int a = int.Parse(Console.ReadLine()); //標準入力
            string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得

            int gensuu = 1; //求める数


            int kota = 0;

            for(int i=0; i < a; i++)
            {
                if(int.Parse(str[i]) == gensuu)
                {
                    gensuu++;
                    kota++;
                }
            }
            if(kota == 0)
            {
                Console.WriteLine(-1);
            }
            else
            {
                Console.WriteLine(a - kota);
            }
        }
    }
}


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

int num1[128];
int num2[128];
int n, m;
int sum1;
int sum2;

std::pair<int, int> solve(void) {
  std::pair<int, int> ans(1000, 1000);
  for(int i = 0; i < n; ++i) {
    for(int j = 0; j < m; ++j) {
      if( sum1 - num1[i] + num2[j] == sum2 - num2[j] + num1[i] ) {
	if( ans.first + ans.second > num1[i] + num2[j] ) {
	  ans.first = num1[i]; ans.second = num2[j];
	}
      }
    }
  }
  if( ans.first != 1000 ) { return ans; }
  return std::pair<int, int>(-1, -1);
}
				

int main() {

  
  for(;;) {
    std::cin >> n >> m;

    if( n == 0 and m == 0 ) break;

    sum1 = sum2 = 0;

    for(int i = 0; i < n; ++i) {
      std::cin >> num1[i];
      sum1 += num1[i];
    }
    for(int i = 0; i < m; ++i) {
      std::cin >> num2[i];
      sum2 += num2[i];
    }

    std::pair<int, int> ans = solve();

    if( ans.first == -1 ) {
      std::cout << -1 << std::endl;
    }
    else {
      std::cout << ans.first << " " << ans.second << std::endl;
    }
  }
    
  
  return 0;
}

Measured memory_bytes: 1156
import numpy as np

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

l, r = 0, N + 1
while r - l > 1:
    m = (r + l) // 2
    if np.all(B[N - m:] > A[:m]):
        l = m
    else:
        r = m

if np.all(B[:N - l] < A[l:]):
    print('Yes')
    print(*np.roll(B, l))
else:
    print('No')


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

int main(){
	int n;
	cin >> n;
	int* h = new int[n];
	for(int i=n-1;i>=0;i--){
		cin >> h[i];
	}
	if(n == 1){
		cout << "Yes" << endl;
		return 0;
	}
	for(int i = 1;i<n;i++){
		if(h[i] - h[i-1] <= 0){
			continue;
		}else if(h[i] - h[i-1] == 1){
			h[i]--;
			continue;
		}else{	
			cout << "No" << endl;
			return 0;
		}
	}cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 640
function toNum (str) {
	return parseInt(str, 10);
}

// inputに入力データ全体が入る
function Main(input) {
	var N = toNum(input.split('\n')[0]);
	var T = toNum(input.split('\n')[1].split(' ')[0]);
	var A = toNum(input.split('\n')[1].split(' ')[1]);
	var H = input.split('\n')[2].split(' ');
	H = H.map((val) => toNum(val));
	var result;
	// 地点が1つしかなければ地点1になる
	if ( N == 1 ) {
		console.log('1');
		return;
	}
	// for ( var i = 0; i < N - 1; i++ ) {
	// 	if ( Math.abs(A - (T - H[i] * 0.006)) < Math.abs(A - (T - H[i+1] * 0.006)) ) {
	// 		result = i + 1;
	// 	} else {
	// 		result = i + 2;
	// 	}
	// }
	var absObjArr = [];
	H.forEach((val, i) => {
		absObjArr.push({
			abs: Math.abs(A - (T - val * 0.006)),
			index: i
		});
	});
	var absArr = absObjArr.map((obj) => obj.abs);
	var min = Math.min(...absArr);
	absObjArr.forEach((obj, i) => {
		if ( obj.abs == min ) {
			console.log(i + 1);
			return;
		}
	});
}

// ※この行以降は編集しない (標準入力から一度に読み込みMainを呼び出します)
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21424
#include <bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long ll;
int a[100005];
int Min = 0x3f3f3f3f;

int main(){
    int n,k,sum = 0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        sum += a[i];
    }
    sort(a,a+n);
    sum -= a[n-1]/2;
    printf("%d\n",sum);

    return 0;
}


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

const ll modulo = 1000000007;
const int inf = 0x3f3f3f3f;
const ll ll_inf = 0x3f3f3f3f3f3f3f3f;

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

    int n; cin >> n;
    pair<ll, ll> vals[n];
    ll starts[n], ends[n];
    for(int i = 0; i < n; i++) {
        cin >> vals[i].first >> vals[i].second;
        starts[i] = vals[i].first;
        ends[i] = vals[i].second;
        //max_len = max(vals[i].second - vals[i].first + 1, max_len);
    }
    sort(starts, starts + n);
    sort(ends, ends + n);
    ll max_len = 0;
    for(int i = 0; i < n; i++) {
        ll len = vals[i].second - vals[i].first + 1;
        ll otherstart = (starts[n - 1] == vals[i].first) ? starts[n - 2] : starts[n - 1];
        ll otherend = (ends[0] == vals[i].second) ? ends[1] : ends[0];
        len += max(otherend - otherstart + 1, (ll) 0);
        max_len = max(max_len, len);
    }
    sort(vals, vals + n);
    ll lhappy[n];
    ll lend = inf;
    for(int i = 0; i < n; i++) {
        lend = min(lend, vals[i].second);
        lhappy[i] = max((ll) 0, lend - vals[i].first + 1);
    }

    ll rhappy[n];
    ll rend = inf;
    for(int i = n - 1; i >= 0; i--) {
        rend = min(rend, vals[i].second);
        rhappy[i] = max((ll) 0, rend - vals[n - 1].first + 1);
    }
    for(int i = 0; i < n - 1; i++) {
        max_len = max(max_len, lhappy[i] + rhappy[i + 1]);
    }
    // for(int i = 0; i < n; i++) {
    //     cout << lhappy[i] << " " << rhappy[i] << endl;
    // }
    cout << max_len << endl;
}

Measured memory_bytes: 4992
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    double debt = 100000;
    for (int i = 1; i <= n; i++) {
      debt = (debt * 1.05) / 1000;
      debt = Math.ceil(debt) * 1000;
    }
    System.out.println((int)debt);
  }
}

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

int Monster[100007];
int Power[100007];
int N;

int main()
{
    scanf("%d", &N);
    for (int i = 1; i <= N+1; i++) scanf("%d", &Monster[i]);
    for (int i = 1; i <= N; i++) scanf("%d", &Power[i]);

    ll ans = 0;
    for (int i = 1; i <= N; i++) {
        if (Power[i] > Monster[i]) {
            ans += Monster[i];
            Power[i] -= Monster[i];

            if (Power[i] >= Monster[i+1]) ans += Monster[i+1], Monster[i+1] = 0;
            else ans += Power[i], Monster[i+1] -= Power[i];

        }

        else ans += Power[i];
    }

    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, i, j, k, cnt = 0;
    scanf("%d", &n);
    int a[n];
    for (i=0; i<n; i++) {
        scanf("%d", &a[i]);
    }
    sort(a, a+n);
        for (i=0; i<n-1; i++) {
            for (j = i+1; j < n; j++) {
                for(k=j+1; k<n; k++) if ((a[i]+a[j]) > a[k]) cnt++;
            }
        }
    printf("%d", cnt);
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
const long long MOD = (long long)1e9 + 7;

int tmp, sum, mi = 10;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    for (int i = 0; i < 5; i++) {
        cin >> tmp;
        sum += (tmp/10)*10;
        if (tmp%10) sum += 10;
        if (tmp%10 == 0) continue;
        if (tmp%10 < mi) mi = tmp%10;
    }
    cout << sum - (10 - mi) << "\n";
    //system("pause");
    return 0;
}

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

int main() {
  ll n,k; cin>>n>>k;
  vector<ll> v(n);
  rep(i,n){
    cin>>v[i];
  }
  ll ans=0;ll a=0,d=0;
  rep(i,n){
    
    rep(j,n){
      if(v[i]>v[j]){
        d++;
        if(j>i)a++;
      }
    }
    
  }
  ans+=(a*k)%l +( ( ((k-1)*k)/2) %l)*d; ans%=l;
   cout<<ans<<endl;
 
}

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

int main(){
  int n, m, i, j;
  cin >> n;
  string s[n];
  for(i = 0; i < n; i++) cin >> s[i];
  cin >> m;
  string t[m];
  for(i = 0; i < m; i++) cin >> t[i];
  int num = 0;
  for(i = 0; i < n; i++){
    int score = 0;
    for(int j = 0; j < n; j++) if(s[i] == s[j]) score++;
    for(int j = 0; j < m; j++) if(s[i] == t[j]) score--;
    num = max(num, score);
  }
  cout << num << endl;
  return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        n = I()
        a = []
        while len(a) < n:
            a += LS()
        s = set()
        for i in range(n):
            s.add(int(a[i]))
            for j in range(i+1,min(i+2,n)):
                s.add(int(a[i]+a[j]))
                for k in range(j+1,min(j+2,n)):
                    s.add(int(a[i]+a[j]+a[k]))
        r = -1
        for i in range(1000):
            if not i in s:
                r = i
                break
        rr.append(r)
        break

    return '\n'.join(map(str, rr))


print(main())




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

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

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

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

const double pi = 3.141592653589793;
// -------------------------------------------------------
int N;
map<char, ll> mp;

int main() {
  cin >> N;
  rep(i, 0, N) {
    string s;
    cin >> s;
    mp[s[0]]++;
  }

  char cs[] = {'M', 'A', 'R', 'C', 'H'};
  ll ans = 0;
  for (int i = 0; i < 3; ++i) {
    for (int j = i + 1; j < 4; ++j) {
      for (int k = j + 1; k < 5; ++k) {
        ans += mp[cs[i]] * mp[cs[j]] * mp[cs[k]];
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
int main(){
    int n;
    string s;
    cin>>n>>s;
    int ans=0;
    for(int i=0;i<n-2;i++){
	//string e=s[i]+s[i+1]+s[i+2];
	if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C'){
	    ans++;
	}
    }
    cout<<ans;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int a, b;

	cin >> a >> b;
	if (a < 10 && b < 10)
	{
		cout << a * b;
	}
	else
	{
		cout << -1;
	}
	
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
N, M = list(map(int, input().split()))
SC = []
for i in range(M):
    SC.append(list(map(int, input().split())))

num = 10 ** (N - 1)
if N == 1:
    num = 0
snum = str(num)
while len(snum) == N:
    if all(int(snum[s - 1]) == c for s, c in SC):
        print(num)
        exit(0)
    num += 1
    snum = str(num)
print(-1)


Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <utility>
#include <vector>
#include <list>
#include <algorithm>
#include <unordered_map>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;

int main()
{
    ll N;
    scanf("%lld", &N);
    unordered_map<ll, ll> AMap;
    ll ans = 0;
    for (ll i = 0; i < N; i++)
    {
        ll a;
        scanf("%lld", &a);
        AMap[a]++;
        ans += a;
    }

    ll Q;
    scanf("%lld", &Q);
    for (ll i = 0; i < Q; i++)
    {
        ll b, c;
        scanf("%lld %lld", &b, &c);
        ans -= AMap[b] * b;
        ans += AMap[b] * c;

        AMap[c] += AMap[b];
        AMap[b] = 0;

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


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

int main(){
 string C1,C2,C3;
 char a,b,c;
 getline(cin,C1);
 getline(cin,C2);
 getline(cin,C3);
 a = C1[0]; b = C2[1] ; c = C3[2];
cout << a << b << c <<endl;
}

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

int ans = 0;
vector<int> A;
vector<int> al;
int N, M, Q;
vector<vector<int>> abcd;


void dfs(int i, int tm) {
    if (i == N) {
        /*
        rep(j, N) {
            cout << A[j] << " ";  
        }
        cout << endl;
        */
        int tans = 0;
        rep(j, Q) {
            if (A[abcd[j][1]] - A[abcd[j][0]] == abcd[j][2]) {
                // cout << j << endl;
                tans += abcd[j][3];
            }
        }
        ans = max(tans, ans);
        return;
    }

    repr(j, tm, M+1) {
        A[i] = j;
        dfs(i+1, j);
    }
}

int main() {
    cout << fixed << setprecision(10);
    
    cin >> N >> M >> Q;

    // vector<vector<int>> abcd(Q, vector<int>(4, 0));
    // abcd.resize(Q);
    A.resize(N);
    rep(i, N) {
        A[i] = 1;
    }
    // al.resize(N);
    // cout << "a" << endl;

    
    rep(i, Q) {
        int a, b, c, d; cin >> a >> b >> c >> d;
        a--; b--;
        vector<int> t = {a, b, c, d};
        abcd.push_back(t);
    }
    

    // cout << "b" << endl;

    // sort(abcd.begin(), abcd.end(), [](const vector<int> &alpha,const vector<int> &beta){return alpha[1] < beta[1];});
    // sort(abcd.begin(), abcd.end(), [](const vector<int> &alpha,const vector<int> &beta){return alpha[0] < beta[0];});

    // cout << "d" << endl;
    /*int qi = 0;
    rep(i, N) {
        cout << "i " << i << endl;
        if (abcd[qi][1] > i) {
            // niのbが iより大きいとき
            continue;
        }
        if (qi == Q) {
            break;
        }
        int tni = qi;
        int tmax = 0;
        int maxi = qi;
        while (qi < Q && abcd[qi][1] == i) {
            if (tmax < abcd[qi][3]) {
                tmax = abcd[qi][3];
                maxi = qi;
            }
            qi += 1;
        }
        A[abcd[maxi][1]] = A[abcd[maxi][0]] + abcd[maxi][2];
        cout << "maxi " << maxi << endl;
        cout << "tmax " << tmax << endl;
        ans += tmax;
        repr(j, tni, qi) {
            if (j == maxi) continue;
            if (A[abcd[j][1]] - A[abcd[j][0]] == abcd[j][2]) {
                cout << "j " << j << endl;
                ans += abcd[j][3];
                cout << "+ " << abcd[j][3] << endl;
            }
        }
    }
    */
    dfs(0, 1);

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

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define int long long
#define all(c) (c).begin(),(c).end()
#define pii pair<long long,long long>
#define endl '\n'

using namespace std;

signed main(){
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector <int> A(n,0);
    vector <int> B(n+1,0);
    for(int i=0;i<n;i++){
        cin >> A[i];
        B[A[i]]++;
    }
    int sum=0;
    for(int i=0;i<n+1;i++){
        sum+=(B[i]*(B[i]-1))/2;
    }
    //sort(all(B));
    vector<int> C(n,0);
    for(int i=0;i<n;i++){
        C[i]=sum-B[A[i]]*(B[A[i]]-1)/2+(B[A[i]]-1)*(B[A[i]]-2)/2;
        cout << C[i] << endl;
    }
    
}

Measured memory_bytes: 7296
#define _USE_MATH_DEFINES
#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 < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

int n;
int distF[100005], distS[100005];
vector< vector<int> > graph;

void dfs(int current, int prev, int d, int dist[]){
    dist[current] = d;
    for(auto next : graph[current]){
        if(next != prev) dfs(next, current, d+1, dist);
    }
}

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

    cin >> n;
    graph.resize(n);
    rep(i, n-1){
        int a, b; cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    dfs(0, -1, 0, distF);
    dfs(n-1, -1, 0, distS);

    int cnt = 0;
    rep(i, n){
        if(distF[i] <= distS[i]) cnt++;
        else cnt--; 
    }

    cout << (0 < cnt ? "Fennec" : "Snuke") << endl;

    return 0;
}

Measured memory_bytes: 12800
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    if(b%a == 0) cout << a+b << endl;
    else cout << b-a << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int count5 = 0;
    int count7 = 0;

    int[] data = {a,b,c};

    for (int i = 0; i < 3; i++) {
      if (data[i] == 5) count5++;
      if (data[i] == 7) count7++;
    }
    if (count5 == 2 && count7 == 1) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }

  }

}


Measured memory_bytes: 21716
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <cmath>
#include <map>
#include <algorithm>
#include <stack>
#include <cstring>
 
#define ll long long
#define MP make_pair
#define PB push_back
#define P push
#define f first
#define se second
#define S size()
#define B begin()
#define E end()
#define rB rbegin()
#define rE rend()
#define PI acos(-1)
 
 
const int N = 1e5 + 100;
const int M = 1e6 + 100;
const ll oo = 1e18;
 
ll n, m, k, t, q, h, a, b, d, c, e, w, x, y, z;
using namespace std;

int ai[N][3];
ll dp[N][3];

int main() {
 
	cin >> n;

	vector <int> v(n);

	for(int i = 0; i < n; i++) {
		cin >> ai[i][0] >> ai[i][1] >> ai[i][2];
	}

	dp[0][0] = ai[0][0];
	dp[0][1] = ai[0][1];
	dp[0][2] = ai[0][2];

	for(int i = 1; i < n; i++) {
		for(int j = 0; j < 3; j++) {
			dp[i][j] = max(dp[i - 1][(j + 1) % 3] + ai[i][j], dp[i - 1][(j + 2) % 3] + ai[i][j]);
		}
	}


	cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]});


 
    return 0;
}
 
 

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{
	string S, T="";
	cin >> S;
	fx(S.size()) {
		if (S[x]!='x') {
			T += S[x];
		}
	}
	string T2 = T;
	reverses(T);
	if (T==T2) {
		int ans = 0;
		for (int i = 0; i <= (int)S.size() - i - 1;i++) {
			if (S[i] != S[S.size() - i - 1]) {
				ans++;
				if (S[i]=='x') {
					S.insert(S.begin()+S.size()-i,'x');
				}
				else {
					S.insert(S.begin() + i, 'x');
				}
			}
		}
		ce(ans)
	}
	else {
		ce(-1)
	}

    return 0;
}



Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
#define popcnt(a) __builtin_popcount(a)
#define FastIO() ios::sync_with_stdio(false), cin.tie(0);
#define IO() freopen("palindrome.in","rw",stdin)
#define error(args...)                       \
{                                            \
    cerr<<"LINE "<<__LINE__;                 \
    string _s = #args;                       \
    replace(_s.begin(), _s.end(), ',', ' '); \
    stringstream _ss(_s);                    \
    istream_iterator<string> _it(_ss);       \
    err(_it, args);                          \
    cerr<<endl;                              \
}
void err(istream_iterator<string> it)
{
} 
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
  cerr<<' '<< *it << " = " << a ;
  err(++it, args...);
} 
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e6+9, M = 1e5+9, OO = 0x3f3f3f3f;
int memo[N];
vector<int>adj[N];
int dfs(int p)
{
  int &ret=memo[p];
  if(~ret) return ret;

  ret=0;
  for(auto ch:adj[p]) ret=max(ret,dfs(ch)+1);
  
  return ret;
}
int main()
{
  memset(memo,-1,sizeof memo);
  int n,m,ans=0;
  scanf("%d%d",&n,&m);
  for(int i=0;i<m;++i)
  {
    int u,v;
    scanf("%d%d",&u,&v);
    adj[u].push_back(v);
  }
  for(int i=1;i<=n;++i) ans=max(ans,dfs(i));

  printf("%d\n",ans);
  #ifdef _LOCAL_DEFINE
  cerr << (double)clock() * 1.0 / CLOCKS_PER_SEC << endl;
  #endif
  return 0; 
}

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

#define se second
#define fi first
#define mk(a,b) make_pair(a,b)

typedef long long ll;
typedef pair<ll,ll> pll;

int N,Q;
ll que[100010];
pll mem[100010];
vector<ll> V;
map<ll,ll,greater<ll> > mp;
map<ll,ll,greater<ll> >::iterator ite;
ll ans[100010] = {0};

int main()
{
    scanf("%d%d",&N,&Q);
    for(int i = 0; i < Q; i++)scanf("%lld",que + i);

    pll MIN = mk(que[Q - 1],Q - 1);
    for(int i = Q - 1; i >= 0; i--)
    {
        if(que[i] < MIN.fi)MIN = mk(que[i],i);
        mem[i] = MIN;
    }
    V.push_back(N);
    for(int id = 0; id < Q; id++)
    {
        id = mem[id].se;
        V.push_back(mem[id].fi);
    }

    mp[V.back()] = 1;
    for(int i = V.size() - 1; i >= 0; i--)
    {
        vector<pll> W;
        for(ite = mp.begin(); ite != mp.end(); ite++)
        {
            if(V[i] >= ite->fi)break;
            W.push_back(mk(V[i],ite->fi / V[i] * ite->se));
            W.push_back(mk(ite->fi % V[i],ite->se));
        }
        while(mp.size() && mp.begin()->fi > V[i])mp.erase(mp.begin());
        for(int j = 0; j < W.size(); j++)mp[W[j].fi] += W[j].se;
    }

    for(ite = mp.begin(); ite != mp.end(); ite++)ans[ite->fi] += ite->se;
    for(int i = N - 1; i >= 1; i--)ans[i] += ans[i + 1];

    for(int i = 1; i <= N; i++)printf("%lld\n",ans[i]);
    return 0;
}


Measured memory_bytes: 16020
#include <bits/stdc++.h>
using namespace std;
int main() {
	int64_t n;
	cin >> n;
	//nを素因数分解
	vector<int64_t> factor = {};
	for (int64_t i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			factor.push_back(i);
		}
	}
	//配列ごとにa*b判定→最小を返す
	int64_t result = 10000000000;
	for (int i = 0; i < factor.size(); i++) {
		int64_t a, b;
		a = factor.at(i);
		b = n / a;
		int64_t ans = max(to_string(a).length(),to_string(b).length());
		if (result > ans)result = ans;
	}
	cout << result << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5 + 10;
int n;
int main() {
    cin >> n;
    multiset<int> s;
    for(int i = 0, x; i < n; i++) {
        cin >> x;
        auto it = s.lower_bound(x);
        if(it != s.begin()) {
            it--;
            s.erase(it);
            s.insert(x);
        } else {
            s.insert(x);
        }
    }
    cout << s.size() << '\n';
    return 0;
}

Measured memory_bytes: 4992
K=int(input())
if K>=1 and K<=100:
    S=input()
    S_len=len(S)
    if S.islower() and S_len>=1 and S_len<=100:
        if S_len<=K: print(S)
        else: print(str(S)[:K] + "...")              
    else: print("Sは文字数が1以上100以下であり、全て小文字である必要があります")
else: print("Kは1以上100以下の整数")

Measured memory_bytes: 9084
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <iomanip>
#include <cfloat>
#include <queue>
using namespace std;

#define INF DBL_MAX

struct Circle {
  double x, y, r;
  Circle(int _x, int _y, int _r) {
    x = _x; y = _y; r = _r;
  }
  Circle() : x(0), y(0), r(INF) {}
};
typedef pair<double, int> P;

Circle T[1010];
int xs, ys, xt, yt;
int N;
double D[1010];

double dist(Circle a, Circle b) {
  double l = sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
  return max(l - (a.r + b.r), .0);
}

int main() {
  cin >> xs >> ys >> xt >> yt;
  cin >> N;
  T[0] = Circle(xs, ys, 0);
  T[1] = Circle(xt, yt, 0);
  for (int i=0; i<N; i++) {
    int x, y, r;
    cin >> x >> y >> r;
    T[i+2] = Circle(x, y, r);
  }

  for (int i=0; i<=N+1; i++) D[i] = INF;

  priority_queue< P, vector<P>, greater<P> > q;
  q.push(P(0, 0));
  D[0] = 0;

  while (!q.empty()) {
    double l = q.top().first;
    int s = q.top().second;
    q.pop();
    if (D[s] < l) continue;

    for (int t=0; t<=N+1; t++) {
      if (s == t) continue;
      double x = dist(T[s], T[t]);
      if (D[t] > D[s] + x) {
        D[t] = D[s] + x;
        q.push(P(D[t], t));
      }
    }
  }
  cout << fixed << setprecision(10) << D[1] << "\n";
  return 0;
}


Measured memory_bytes: 4464
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
using namespace std;
int n,m,i,j;
char a[505][505],b[505][505];
int main()
{
	scanf("%d%d",&n,&m);
	fz1(i,n){
		scanf(" ");
		fz1(j,m){
			scanf("%c",&a[i][j]);
			b[i][j]=a[i][j];
		}
	}
	fz1(i,m){
		a[1][i]=b[n][i]='#';
		fz(j,2,n-1){
			(((i&1)?a:b)[j][i])='#';
		}
	}
	fz1(i,n){
		fz1(j,m)putchar(a[i][j]);
		puts("");
	}
	puts("");
	fz1(i,n){
		fz1(j,m)putchar(b[i][j]);
		puts("");
	}
	return 0;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

char b;

char ans;

int main(void) {
  // Here your code !
  scanf("%c", &b);

  if (b == 'A') ans = 'T';
  else if (b == 'C') ans = 'G';
  else if (b == 'G') ans = 'C';
  else ans = 'A';

  printf("%c\n", ans);

  return 0;
}


Measured memory_bytes: 256