akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10**6+1) #再帰関数の上限,10**5以上の場合python


def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None


#N, Q = map(int, input().split())
N, Q = map(int, input().split())
#A = tuple(map(int, input().split())) #1行ベクトル
#L = tuple(int(input()) for i in range(N)) #改行ベクトル
#S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

edge = [[] for i in range(N)]
for i in range(N-1):#木の場合M=N-1
    a,b,c,w = map(int,input().split())
    edge[a-1].append((b-1,c-1,w))
    edge[b-1].append((a-1,c-1,w)) #有向のばあいコメントアウト



#ダブリングによるLCA, 前処理NlogN, 呼び出しlogN, 安定  
def dfs(start):
    q=[(start,-1,0,0)]
    pars=[-1]*N
    depth=[-1]*N
    dist=[-1]*N
    while len(q):
        e,p,d,dis=q.pop()#ここをpopleftにすると幅優先探索BFSになる
        if depth[e]!=-1:continue
        pars[e]=p
        depth[e]=d
        dist[e]=dis
        for ne,c,w in edge[e]:
            q.append((ne,e,d+1,dis+w))
    return pars,depth,dist
pars,d,dist=dfs(0)
ln=N.bit_length()
dp=[[-1]*N for _ in range(ln+1)]
dp[0]=pars
for i in range(1,ln+1):
    for j in range(N):
        dp[i][j]=dp[i-1][dp[i-1][j]]


# LCAの計算
def lca(u, v):
    du = d[u]; dv = d[v]
    if du > dv:
        du, dv = dv, du
        u,v=v,u
    dif=dv-du
    for i in range(ln+1):
        if (dif>>i)&1:
            v=dp[i][v]
    if u==v:return u
    for i in range(ln,-1,-1):
        pu=dp[i][u];pv=dp[i][v]
        if pu!=pv:
            u,v=pu,pv
    return pars[u]

q=Q
qs = tuple(tuple(map(int, input().split())) for i in range(Q)) #改行行列
ans=[0]*Q
qn=[[] for _ in range(N)]
for i,(x,y,u,v) in enumerate(qs):
    ans[i]=dist[u-1]+dist[v-1]-2*dist[lca(u-1,v-1)]
    qn[u-1].append((i,x-1,y,1))
    qn[v-1].append((i,x-1,y,1))
    qn[lca(u-1,v-1)].append((i,x-1,y,-2))
cnt=[0]*Q
#printe(qn)

qc=[[0,0] for _ in range(Q)]
cc=[[0,0] for _ in range(N-1)]

dfq=[(0,None,0,-1)]
def dfs2(e):
    for qi,x,y,sgn in qn[e]:
        ans[qi]+=(y*cc[x][0]-cc[x][1])*sgn
    for ne,c,nd in edge[e]:
        if ne==pars[e]:continue
        if c!=None:
            cc[c][0]+=1
            cc[c][1]+=nd
        dfs2(ne)
        if c!=None:
            cc[c][0]-=1
            cc[c][1]-=nd
dfs2(0)
printl(ans)

# n=N
# A = [0]*q
# C = [[] for _ in range(n)]
# num = [0]*n
# cum = [0]*n
# for i in range(q):
#   x, y, u, v = map(int, input().split())
#   u -= 1
#   v -= 1
#   a = lca(u, v)
#   C[u].append((i, x, y, 1))
#   C[v].append((i, x, y, 1))
#   C[a].append((i, x, y, -2))
# dist = 0
# stack = [0]
# def dfs2(v):
#   global dist
#   for i, x, y, b in C[v]:
#     A[i] += (dist + num[x]*y - cum[x]) * b
#   for nv, c, d in edge[v]:
#     c+=1
#     if nv ==pars[v]:continue
#     dist += d
#     num[c] += 1
#     cum[c] += d
#     dfs2(nv)
#     dist -= d
#     num[c] -= 1
#     cum[c] -= d
# dfs2(0)
# print(*A, sep="\n")

Measured memory_bytes: 228948
#include<iostream>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
  int value;
  string str;
  int flag;
  map<string,vector<int>> book;

  while(cin>>str>>value){
    book[str].push_back(value);
  }
  for(map<string,vector<int>>::iterator it=book.begin();it!=book.end();++it){
    cout<<it->first<<endl;
    sort(it->second.begin(),it->second.end());
    flag=0;
    for(auto i:it->second){
      if(flag) cout<<" ";
      flag=1;
      cout<<i;
	}
    cout<<endl;
  }
}

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

int main(void)
{
  int n;
  cin >> n;
  int cnt = 0;
  for(int i = 0; i < n; i++)
  {
    for(int j = 0; j < n; j++)
    {
      for(int k = 0; k < n; k++)
      {
        cnt++;
      }
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, Q;
    cin >> A >> B >> Q;
    vector<int> v[2];
    v[0].push_back(-INF2);
    v[1].push_back(-INF2);
    rep(i, A) {
        int s; cin >> s;
        v[0].push_back(s);
    }
    rep(i, B) {
        int t; cin >> t;
        v[1].push_back(t);
    }
    v[0].push_back(INF2);
    v[1].push_back(INF2);
    rep(i, Q) {
        int x; cin >> x;
        int ans = INF2;
        int L[2];
        int R[2];
        rep(j, 2) {
            R[j] = *lower_bound(v[j == 1].begin(), v[j == 1].end(), x);
            L[j] = *(lower_bound(v[(j == 1)].begin(), v[(j == 1)].end(), x) - 1);
        }
        rep(s, 2) {
            rep(j, 2) {
                int tmp1 = abs(x - L[j == 1]) + abs(L[j == 1] - R[j == 0]);
                int tmp2 = abs(x - L[j == 1]) + abs(L[j == 1] - L[j == 0]);
                ans = min({ans, tmp1, tmp2});
            }
            swap(L, R);
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3060
N,M = map(int, input().split())

if N == 1 or M == 1:    
    if N+M == 2:
        print(1)
    else:
        print(max(N,M)-2)

elif N == 2 or M == 2:
    print(0)
    
else:
    print(N*M - ((N-2)*2+(M-2)*2+4))

Measured memory_bytes: 3064
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};



int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n,k;
    string s;
    cin>>n>>s>>k;
    char x=s[k-1];
    rep(i,n){
        if(s[i]==x) cout<<x;
        else cout<<'*';
    }
    cout<<endl;
}

Measured memory_bytes: 256
// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

int h, w;
int n;
int[] a;

void main() {
    scan(h, w);
    scan(n);
    a = readln.split.to!(int[]);

    auto c = new int[][](h, w);

    int y, x;
    bool sw;

    foreach (i, ai ; a) {
        while (ai--) {
            c[y][x] = i.to!int + 1;

            if (sw) {
                x--;
                if (x < 0) {
                    x = 0;
                    y++;
                    sw = false;
                }
            }
            else {
                x++;
                if (x == w) {
                    x = w - 1;
                    y++;
                    sw = true;
                }
            }
        }
    }

    writefln("%(%(%s %)\n%)", c);
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 2428
from collections import deque
s = deque(input())
cnt = 0
while len(s) > 1:
  if s[0] == s[-1]:
    s.pop()
    s.popleft()
  elif s[0] == "x" and s[-1] != "x":
    s.append("x")
    cnt += 1
  elif s[0] != "x" and s[-1] == "x":
    s.appendleft("x")
    cnt += 1
  else:
    print(-1)
    exit()
print(cnt)

Measured memory_bytes: 4212
#include<bits/stdc++.h>
using namespace std;
vector<vector<int> > adjik;
int main()
{
int n;
cin>>n;
long long int sum(0),arr[n];
map<long long int,int>erm;
for(int i=0; i<n; ++i)
cin>>arr[i];
for(int i=0; i<n; ++i)
++erm[i+arr[i]];
for(int i=0; i<n; ++i)
sum+=erm[i-arr[i]];
cout<<sum;
}


Measured memory_bytes: 27728
//A
/*==========================================================*/
/*    Template ver 2017-0401    |   Created by AVM.Martin   */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<ctime>
#include<cassert>
#include<algorithm>
#include<cmath>

#include<cstring>
#include<string>
#include<cctype>
#include<utility>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<list>

typedef long long ll;
typedef std::pair<int,int> pii;
typedef std::pair<ll,ll> pll;
typedef std::vector<int> vi;

const int OO=(int)2e9;
const ll INF=(ll)4e18;
const double EPS=(double)1e-12;

#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front

#define INL(i,a,b) ((a<=i)&&(i<=b))
#define EXL(i,a,b) ((a< i)&&(i< b))
#define REPP(i,a,b,c) for(int i=a;i<=b;i+=c)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,c) for(int i=a;i>=b;i-=c)
#define REV(i,a,b) REVV(i,a,b,1)
using namespace std;

int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	if((a+b)%3==0||a%3==0||b%3==0)puts("Possible");
	else puts("Impossible");
	return 0;
}

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

void solve()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    rep(i, m) cin >> a[i] >> b[i];
    vector<vector<bool>> g(n, vector<bool>(n, false));
    rep(i, m)
    {
        g[a[i] - 1][b[i] - 1] = true;
        g[b[i] - 1][a[i] - 1] = true;
    }
    vector<int> p(n);
    rep(i, n) p[i] = i;
    int ans = 0;
    do
    {
        if (p[0] != 0)
            break;
        bool ok = true;
        rep(i, n - 1)
        {
            if (!g[p[i]][p[i + 1]])
                ok = false;
        }
        if (ok)
            ans++;
    } while (next_permutation(p.begin(), p.end()));
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int N; cin >> N; 
	bool A[110] = {}; 
	for(int i = 0; i < N; i++){
		int a, b; cin >> a >> b; 
		if(a == b) A[i] = true; 
	}
	bool ok = false; 
	for(int i = 0; i < N-2; i++){
		if(A[i] && A[i+1] && A[i+2]) ok = true; 
	}
	cout << (ok ? "Yes" : "No") << "\n"; 
}

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

const int MAXN = 3e5 + 10;
const int MAXM = 1e5 + 10;

int n, m, bit[MAXM];
struct Triple {
	int l, r, len;
	
	Triple() {}
	Triple(int _l, int _r, int _len) : l(_l), r(_r), len(_len) {}
} a[MAXN];

inline bool cmp(const Triple &x, const Triple &y) {
	return x.len < y.len;
}

void add(int x, int v) {
	for (; x <= m; x += x & -x)
		bit[x] += v;
}

int get(int x) {
	int r = 0;
	for (; x; x -= x & -x)
		r += bit[x];
	return r;
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) {
		int l, r;
		scanf("%d%d", &l, &r);
		a[i] = Triple(l, r, r - l + 1);
	}
	sort(a + 1, a + n + 1, cmp);
	int ptr = 1;
	for (int i = 1; i <= m; ++i) {
		for (; ptr <= n && a[ptr].len < i; ++ptr) {
			add(a[ptr].l, 1);
			add(a[ptr].r + 1, -1);
		}
		int ans = n - ptr + 1;
		for (int j = i; j <= m; j += i)
			ans += get(j);
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 4864
def INT():
    return int(input())

def MI():
    return map(int, input().split())

def LI():
    return list(map(int, input().split()))

N = INT()
a = LI()
ans = 0

for i in range(N):
    if (i + 1) % 2 != 0 and a[i] % 2 != 0:
        ans += 1

print(ans)

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll MOD = 1000000007;

int main() {
    ll N, M; cin >> N >> M;
    vector<ll> S(N), T(M); cin >> S >> T;
    vector<vector<ll>> dp(N + 1, vector<ll>(M + 1));

    rep(n, N) {
        rep(m, M) {
            dp[n + 1][m + 1] = (dp[n + 1][m] + dp[n][m + 1] - dp[n][m] + MOD) % MOD;

            if(S[n] == T[m])
                dp[n + 1][m + 1] = (dp[n + 1][m + 1] + dp[n][m] + 1) % MOD;
        }
    }
    cout << dp[N][M] + 1 << endl;
    return 0;
}


Measured memory_bytes: 31616
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    set<int> se;
    int add = 0;
    rep(i,n){
        if(a[i]>=3200) add++;
        else se.insert(a[i]/400);
    }
    int MIN = se.size();
    if(MIN==0 && add > 0) MIN = 1;
    int MAX = se.size() + add;
    cout << MIN << " " << MAX << endl;
}

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

using namespace std;

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

    int r;
    cin>>r;

    cout<<fixed<<setprecision(10)<<2.0*3.1415926535*double(r)<<"\n";


    return 0;
}


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

using namespace std;

typedef long long ll;

const int N_MAX = 52;

int n;

string s[N_MAX];
int t[N_MAX];

map <string, int> mp;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> s[i] >> t[i];
        mp[s[i]] = i;
    }
    string x;
    cin >> x;
    int sum = 0;
    for(int i = mp[x] + 1; i <= n; i++)
        sum += t[i];
    cout << sum << "\n";
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	
	

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

		int w = sc.nextInt();
		int h = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		
		System.out.println((double)w*h/2+" "+((x*2==w && y*2==h) ? "1" : "0"));
	}
}

Measured memory_bytes: 23764
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
if h == 1 and w == 1:
    print("Yes")
    exit()

for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            f = False
            if 0 <= i+1 < h and 0 <= j < w and s[i+1][j] == "#":
                f = True
            if 0 <= i-1 < h and 0 <= j < w and s[i-1][j] == "#":
                f = True
            if 0 <= i < h and 0 <= j+1 < w and s[i][j+1] == "#":
                f = True
            if 0 <= i < h and 0 <= j-1 < w and s[i][j-1] == "#":
                f = True
            if not f:
                print("No")
                exit()
print("Yes")


Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
    string a, b, c;
    cin >> a >> b >> c;
    int diff = 'A' - 'a';
    printf("%c%c%c\n", a[0] + diff, b[0] + diff, c[0] + diff);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

using ll = long long;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define input(...) __VA_ARGS__; in(__VA_ARGS__)

template<class T>
void print(vector<T> a) {
  cout << "[ ";
  REP(i, a.size()) cout << a[i] << " ";
  cout << "]" << endl;
}

void print() {
  std::cout << std::endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...);
}

void in() { }

template <class Head, class... Tail>
void in(Head&& head, Tail&&... tail) {
  cin >> head;
  in(std::forward<Tail>(tail)...);
}

int main() {
  ll input(a, b);
  cout << a * b << endl;
}


Measured memory_bytes: 3588
#include<stdio.h>
int dp[301][301];
int w[301] = {};

int abs(int num) {
  if(num <= -1) {
    return num * -1;
  }
  return num;
}

int max(int a, int b) {
  if (a > b) {
    return a;
  }
  return b;
}

int rec(int l,int r){
    //既に計算済み？
    if(dp[l][r] != -1) return dp[l][r];

    //これ以上取り除けない？
    if(abs(l - r) <= 1) return 0;

    int res = 0;
    //パターン1.
    if(abs(w[l] - w[r - 1]) <= 1 && rec(l + 1,r - 1) == r - l - 2)
    {
        //[l , r)がはじき出せるので
        res = r - l;
    }

    //パターン２.区間を分ける
    for(int mid = l + 1;mid <= r - 1;mid++)
    {
        res = max(res , rec(l,mid) + rec(mid,r));
    }
    return dp[l][r] = res;
};

int main(void) {
  while(1) {
    int n;
    scanf("%d", &n);

    if (n == 0) {
      return 0;
    }

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

    for (int i = 0; i < n + 1; i++) {
      for (int j = 0; j < n + 1; j++) {
        dp[i][j] = -1;
      }
    }

    int ans = rec(0, n);
    printf("%d\n", ans);
  }
  return 0;
}



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

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

	int tmp = n;
	int sum = 0;
	while (true) {
		if (tmp == 0) break;
		sum += tmp % 10;
		tmp /= 10;
	}

	string ans = "No";

	if (n % sum == 0) ans = "Yes";

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#define INF 1e9
#define MOD 1000000007
#define MAX_N 100001
#define MAX_S 5001
#define mod(x) ((x % MOD) + MOD) % MOD

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
vector<string> s_list;

int main() {
    string s;
    int K;
    cin >> s >> K;
    
    int len = (int)s.size();
    
    string top_5[] = {"", "", "", "", ""};
    
    
    for (int i = 0; i < len; ++i) {
        for (int j = i+1; j <= min(i + 5, len); ++j) {
            string sub_s = s.substr(i, j-i);
            int insert_pos = -1;
            for (int k = 0; k < 5; ++k) {
                if (top_5[k] == sub_s) break;
                if (top_5[k] == "" || top_5[k] > sub_s) {
                    insert_pos = k;
                    break;
                }
            }
            if (insert_pos != -1) {
                for (int k = 4; k > insert_pos; --k) {
                    top_5[k] = top_5[k-1];
                }
                top_5[insert_pos] = sub_s;
            }
        }
    }
    
    cout << top_5[K-1] << endl;
    
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

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

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
void judgement(int a){
  if(a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  if(a){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

int main(){
  startupcpp();
  ll N,T,x=inf,i,j;
  cin>>N>>T;
  while(N--){
    cin>>i>>j;
    if(j<=T)chmin(x,i);
  }
  if(x!=inf)cout<<x<<endl;
  else puts("TLE");
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>
#include <bitset>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int n;
  cin>>n;
  std::vector<int> x(n);
  for(int i=0;i<n;i++){
    cin>>x[i];
  }
  int l,q;
  cin>>l>>q;

  std::vector<int> next_node(n);
  int left=0;
  int right=1;
  while(left<n){
    if(right==n-1||x[right+1]-x[left]>l){
      next_node[left]=right;
      left++;
    }else{
      right++;
    }
  }


  int log_n=floor(log2(n));
  std::vector<std::vector<int>> next(log_n+1,std::vector<int>(n));

  for(int i=0;i<n;i++){
    next[0][i] = next_node[i];
  }

  for(int k=0;k<log_n;k++){
    for(int i=0;i<n;i++){
      if(next[k][i]==-1){
        next[k+1][i]=-1;
      }else{
        next[k+1][i]=next[k][next[k][i]];
      }
    }
  }
  std::vector<int> qa(q),qb(q);
  for(int i=0;i<q;i++){
    cin>>qa[i]>>qb[i];
  }

  for(int qi=0;qi<q;qi++){
    int a=qa[qi],b=qb[qi];

    a--;
    b--;
    if(a>b) std::swap(a,b);
    int min=0;
    int max=n;
    int mid=n/2;

    while(max-min>1){
      std::bitset<30> day_bs(mid);
      int node=a;
      for(int bi=0;bi<log_n+1;bi++){
        if(day_bs[bi]){
          node=next[bi][node];
          if(node==n-1) break;
        }
      }
      if(node>=b){
        max=mid;
        mid=(max-min)/2+min;
      }else{
        min=mid;
        mid=(max-min)/2+min;
      }

    }
    cout<<max<<endl;
  }




  return 0;
}

Measured memory_bytes: 9080
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key){
    return u;
  }
  
  if(k<u->key){
    return treeSearch(u->left,k);
  }else{
    return treeSearch(u->right,k);
  }
}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key){
      x=x->left;
    }else{
      x=x->right;
    }
  }

  z->parent=y;

  if(y==NIL){
    root=z;
  }else if(z->key<y->key){
    y->left=z;
  }else{
    y->right=z;
  }
}

void inorder(Node u){
  if(u!=NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);

  }
}
void preorder(Node u){
  if(u!=NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 19364
n,k = map(int,input().split())
h = sorted(list(map(int, [input() for i in range(n)])))
print(min(h[j+k-1]-h[j] for j in range(n-k+1)))
#for j in range(n-k):
    #ans = min(ans, (h[j+k-1]-h[j]))
#print(ans)


Measured memory_bytes: 14236
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    ll n;
    cin >> n;
    string s;
    while(n > 0) {
        --n;
        s += ('a' + n %26);
        n /= 26;
    }
    reverse(all(s));
    cout << s << '\n';
    return 0;
}

Measured memory_bytes: 3624
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std;
int n,m;
double b[20][20];
int c[20];
double fn(int p,int q,double r){
  int i,j;
  double mx=0;
  if(p==m){
    mx=r;
  }else{
    for(i=q;i<n+p-m+1;++i){
      c[p]=i;
      double sm=0;
      for(j=0;j<p;++j)
	sm+=b[i][c[j]];
      mx=max(mx,fn(p+1,i+1,r+sm));
    }
  }
  return mx;
}
int main(){
  int i,j,k;
  while(cin>>n>>m){
    double a[20][3];
    memset(b,0,sizeof(b));
    for(i=0;i<n;++i){
      for(j=0;j<3;++j)
	cin>>a[i][j];
      for(j=0;j<i;++j){
	for(k=0;k<3;++k)
	  b[i][j]+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
      }
    }
    printf("%lf\n",fn(0,0,0));
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn =1e5+10;
const int mod=1e9+7;

int n;

void dfs(string s,int num)
{
    if(s.size()==n)
    {
        cout<<s<<'\n';
        return;
    }
    for(int i=0;i<=num;i++)
    {
        char d=('a'+i);
        string k=s;
        k+=d;
        if(i!=num)
            dfs(k,num);
        else
            dfs(k,num+1);
    }

}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    string s;
    dfs(s,0);




}


Measured memory_bytes: 3632
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        HashSet<Integer> hs = new HashSet<>();
        int ans = 0;
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            if (!hs.contains(a)) {
                ans++;
                hs.add(a);
            }
        }
        if ((ans & 1) == 0) {
            ans--;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 60040
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>

using namespace std;

int main()
{
	int w, h, n, xs, xl, ys, yl, x, y, a;
	cin >> w >> h >> n;
	xs = 0;
	xl = w;
	ys = 0;
	yl = h;
	for (int i = 0; i < n; ++i)
	{
		cin >> x >> y >> a;
		switch (a)
		{
		case 1:
			xs = max(xs, x);
			break;
		case 2:
			xl = min(xl, x);
			break;
		case 3:
			ys = max(ys, y);
			break;
		case 4:
			yl = min(yl, y);
			break;
		}
	}
	if (yl - ys < 0 || xl - xs < 0)
	{
		cout << 0 << endl;
	}
	else
	{
		cout << (yl - ys) * (xl - xs) << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, a;
  cin >> n;
  cin >> a;
 
  n %= 500;
  
  if(n <= a)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

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

int main() {
	int N, a, f;
	int count = 0;

	cin >> N;

	for (int i = 0; i < N; i++) {
		f = 0;
		for (int j = 0; j < N; j++) {
			if (f == 1) {
				break;
			}
			a = (i + 1) * (j + 1);
			if (a < N) {
				count += 1;
			}
			else {
				f = 1;
			}
		}
	}
	cout << count << endl;
}


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


int main(){

    int x, n;
    vector<int> p;
    cin >> x;

    cout << (x == 1? 0: 1);
    cout << endl;

    return 0;
    
}

Measured memory_bytes: 3648
import java.util.Scanner;

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 d = sc.nextInt();
		int p = sc.nextInt();
		int x,y;
		
		x = p * a;
		if(p < c)
			y = b;
		else
			y = b + (p - c) * d;
		
		System.out.println(Math.min(x, y));
		
		sc.close();
	}
}

Measured memory_bytes: 17360
# -*- coding: utf-8 -*-
"""
Created on Sun Feb  3 21:15:56 2019

@author: doppe
"""

A, B = map(int, input().split())
L = [int(i) for i in input().split()]

if (A >= B):
    print(0)
else:
    saList = []
    L.sort()    
    for i in range(0, len(L) -1):
        saList.append(L[i + 1] - L[i])
    li1 = sorted(range(len(saList)), key=lambda k: saList[k])

    splitChiten = []
    for i in range(0, A - 1):
        splitChiten.append(li1[len(li1) - 1 - i])
    splitChiten.sort()
    sum = 0
    j = 0
    for i in range(0, len(splitChiten)):
        sum += (L[splitChiten[i]] - L[j])
        j = splitChiten[i] + 1
    
    sum += (L[len(L) - 1] - L[j])
    print(sum)

Measured memory_bytes: 13704
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
string s,t;
ll ans;
void check(string _s){
	ll n=_s.size()/2,m=_s.size();
	string s1=_s.substr(0,n);
	string s2=_s.substr(n,n);
	if(s1==s2) ans=max(ans,m);
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>s;int n=(s.size()-1);
	for(int i=0;i<n;i++){
		t+=s[i];if(i&1)check(t);
	}
	cout<<ans;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second 
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
//#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
inline void out(int x){
	if(x>=10)out(x/10);
	putchar(x%10+'0');
}
int n;
pair<ll,int> a[2020];
ll dp[2020][2020];
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	cin>>n;
	fo(i,0,n){
		cin>>a[i].fi;
		a[i].fi=-a[i].fi;
		a[i].se=i;
	}
	sort(a,a+n);
	dp[0][0]=0;
	fo(i,0,n) fo(j,0,i+2)dp[i+1][j]=max((j==0?0:dp[i][j-1]-(ll)abs(a[i].se-j+1)*a[i].fi),
	(j==i+1?0:dp[i][j]-(ll)abs(n-(i-j)-1-a[i].se)*a[i].fi));
	ll ans=0;
	fo(i,0,n+1)ans=max(ans,dp[n][i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 26340
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    int N;
    cin >> N;
    vector<pair<pair<string,int>,int>> SP(N);
    string S;
    int P;
    REP(int,i,0,N){
        cin >> S >> P;
        SP.at(i) = make_pair(make_pair(S,-P),i+1);
    }
    sort(SP.begin(),SP.end());

    REP(int,i,0,N) cout << SP.at(i).second << endl;
    return 0;
}

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

int t(int to) {
    int ret = 0;
    int cur = 0;
    for(int i=N-1;i>=0;i--) {
        if((int)S[i] == to) {
            cur = 0;
        } else {
            cur++;
        }
        ret = max(ret, cur);
    }
    return ret;
}

int main() {
    cin >> S;
    N = S.size();
    int ans = 1e9;
    for(int i='a';i<='z'; i++) {
        ans = min(ans, t(i)); 
    } 
    printf("%d\n", ans);
}

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

using namespace std;

typedef long long ll;


bool isPrime(ll x){
    for(ll i=2;i*i<=x;i++) if(x%i==0) return false;
    return true;
}

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

    int n;cin>>n;
    int res=0;
    for(int i=0;i<n;i++){
        ll x;cin>>x;
        if(isPrime(x)) res++;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3132
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans,a,b,c,d;
    cin >>a>>b>>c>>d;

        if(a!=c)cout <<"1"<<endl;
        else cout <<"0"<<endl;


    return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;

int main(){
    double n,x[100],y[100],sum,max=0.0,D,p;
    int i;

    cout << fixed << setprecision(12);
    cin >> n;
    for(i=0;i<n;i++) cin >> x[i];
    for(i=0;i<n;i++) cin >> y[i];

    for(p=1.0;p<=3.0;p+=1.0){
        sum = 0.0;
        for(i=0;i<n;i++){
            sum += pow(fabs(x[i] - y[i]), p);
        }
        D = pow(sum, 1.0 / p);
        cout << D << endl;
    }

    for(i=0;i<n;i++){
        if(max < fabs(x[i] - y[i])) max = fabs(x[i] - y[i]);
    }

    D = max;
    cout << D << endl;
    return 0;
}



Measured memory_bytes: 3480
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define debug(n) cout << "DEBUG1 " << n << "\n";
#define debug2(n, m) cout << "DEBUG2 " << n << ' ' << m << "\n";
#define debug3(n, m, x) cout << "DEBUG3 " << n << ' ' << m << ' ' << x << "\n";
#define ss_def stringstream ss // stringstream, do ss_def(str), then ss >> n (n is int)
#define upzero(n) if (n < 0) n = 0
#pragma GCC optimize("Ofast")
using namespace std;
ll int BtoPmodM(ll int b, ll int p, ll int m) { // (b ^ p) % m (Big Mod)
    b %= m;
    if (p == 0) return 1;
    else if (p % 2 == 0) return (BtoPmodM(b, p / 2, m) * BtoPmodM(b, p / 2, m)) % m; // a^(p/2) * a^(p/2) = a^p
    else if (p % 2 == 1) return (BtoPmodM(b, (p - 1) / 2, m) * BtoPmodM(b, (p - 1) / 2, m) * b) % m; // +1
    else return 0; // a function must return something
}
ll int euclid_algo(ll int a, ll int b) { // Euclidean Algorithm
    if (b == 0) return a;
    else return euclid_algo(b,a % b);
}
bool coprime(ll int a, ll int b) {
    if (euclid_algo(a, b) == 1) return true;
    else return false;
}
ll int factModP(ll int n, ll int p) {
    ll int fac[n - 1];
    fac[0] = 1;
    for (ll int i = 1;i <= n;i++) {
        fac[i] = fac[i - 1] * i % p;
    }
    return fac[n];
}
ll int power(ll int x, ll int y, ll int p) { // x ^ y % p
    ll int res = 1;
    x = x % p;
    while (y > 0) { 
        if (y & 1) res = (res * x) % p; 
        y /= 2; 
        x = (x * x) % p; 
    } 
    return res; 
}
ll int modInverse(ll int n, ll int p) {
    return power(n, p - 2, p); 
}
ll int nCrModP(ll int n, ll int r, ll int p) {
    if (r == 0) return 1;
    else if (r > n) return 0;
    ll int fac[n + 1]; 
    fac[0] = 1; 
    for (ll int i = 1;i <= n;i++) {
        fac[i] = fac[i - 1] * i % p; 
    }
    return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; 
}
ll int nCr(ll int n, ll int r) {
    ll int ans = 1;
     if (r >= n - r) {
         for (ll int i = r + 1;i <= n;i++) ans *= i;
         for (ll int i = 1;i <= n - r;i++) ans /= i;
     } else {
         for (ll int i = n - r + 1;i <= n;i++) ans *= i;
         for (ll int i = 1;i <= r;i++) ans /= i;
     }
     return ans;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // implementation
    int n;
    cin >> n;
    ll int sum = 0;
    for (int i = 1;i <= n;i++) {
    	for (int j = 1;j <= n;j++) {
    		for (int k = 1;k <= n;k++) {
    			sum += euclid_algo(euclid_algo(i, j), k);
			}
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fr(i,n) for(int i=0;i<n;i++)
int gcd(int n,int m){
  if(n>m) return gcd(m,n);
  else if(n==0) return m;
  else return gcd(m-n*(m/n),n);
}
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  cout<<(c%gcd(a,b)>0?"NO":"YES")<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long a,b,c,d;
	cin>>a>>b>>c>>d;
	
	long long ans=a*c;
	if (ans<a*d){
		ans=a*d;
	}
	if (ans<b*c){
		ans=b*c;
	}
	if (ans<b*d){
		ans=b*d;
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3632
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = int(input())
aa = inpl()

def calc(x):
	aa_dush = [-1]*N
	for i in range(N):
		if aa[i] >= x:
			aa_dush[i] = 1
	#aa_dush = [1, 1, 1, 1, 1, 1, -1, 1, -1, -1]

	S = [0] #S_0 = 0を忘れずにつける
	tmp = 0
	MIN = MAX = 0
	for i in range(N):
		tmp += aa_dush[i]
		MIN = min(tmp,MIN)
		MAX = max(tmp,MAX)
		S.append(tmp)
	#S = [0, 1, 2, 3, 4, 5, 6, 5, 6, 5, 4]
	#MIN = 0 , MAX = 6

	L = (MAX-MIN+1) #BITのサイズ L=6
	bit = [0]*(L+1) #1indexで扱うのでL+1の長さで取る
	ans = 0
	for S_i in S:
		S_i -= (MIN-1) #S_iの最小値が1となるように調整

		#BITで既出の要素のうちS_i以下の要素数をカウント
		tmp = 0
		x = S_i
		while x > 0:
			tmp += bit[x]
			x -= x & -x
		ans += tmp

		#BITのS_iに1を加算して更新
		x = S_i
		while x <= L:
			bit[x] += 1
			x += x & -x

	return ans #中央値がx以上となる(l,r)の組の数

border = ( (N+1)*N//2 +1 )//2
OK = 0
NG = 10**9+3

while NG - OK > 1:
	mid = (OK+NG)//2
	if calc(mid) >= border:
		OK = mid
	else:
		NG = mid

print(OK)


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

int main()
{
    int n,a[201]={},l,b[201]={},small=1000,total=0,c[201]={},small2=0;
    cin>>n;
    for (int i=1; i<=n; i++)
    {
        a[i]=i;
    }
    cin>>l;
    for (int i=1; i<=n; i++)
    {
        if (a[i]+l-1 <0)
        {
            b[i]=-1*(a[i]+l-1);
            c[i]=a[i]+l-1;
        }
        if (a[i]+l-1 >=0)
        {
            b[i]=a[i]+l-1;
            c[i]=a[i]+l-1;
        }
    }
    for (int i=1; i<=n; i++)
       {
           total=c[i]+total;
       }
    for (int i=1; i<=n; i++)
       {
           if (b[i]<small)
           {
               small=b[i];
               small2=c[i];
           }
       }
   
    cout<<total-small2;
    return 0;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    nums = [2] * (N+1)


    # nums[1] = 2
    # nums[1]
    ans = 1
    # for i in range(2,int(N**0.5)+1):
    for i in range(2,N+1):
        # nums[i] += 1
        ans += i * nums[i]
        tmp_i = i * 2
        while tmp_i<= N:
            nums[tmp_i] += 1
            tmp_i += i
            # print(nums[tmp_i],tmp_i)


    # print(nums)
    print(ans)





main()

Measured memory_bytes: 145604
#include<stdio.h>
int main(){
	int n,a,b,x,y,i;
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		a=0;
		b=0;
		for(i=0;i<n;i++){
			scanf("%d%d",&x,&y);
			if(x>y)a=a+x+y;
			else if(x<y)b=b+x+y;
			else{
				a=a+x;
				b=b+y;
			}
		}
		printf("%d %d\n",a,b);
	}
	return 0;
}


Measured memory_bytes: 2056
#include<bits/stdc++.h>
#define int long long
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;


const int maxn = 21 , MOD = 1e9 + 7;
int dp[maxn+1][1LL<<maxn];
int n;
int32_t main()
{
	IOS
	memset(dp,0,sizeof(dp));
	dp[0][0]=1;
	cin >> n;
	
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			int x;cin>>x;
			if( !x ) continue;
			for(int k=0;k<(1LL<<n);k++)
			{
				if( (((k>>j)&1)^1) )
				{
					dp[i+1][ k | (1LL<<j) ]+=dp[i][k];
					dp[i+1][ k | (1LL<<j) ]%=MOD;
				}
			}
		}
	}
	
	cout << dp[n][(1LL<<(n))-1] << endl;
	
	
}


Measured memory_bytes: 360832
import java.util.Scanner;

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

	int N = sc.nextInt();
	String S = sc.next();
	char C[] = S.toCharArray();

	for (int i = 0; i < C.length; i++) {
	    if ((char)(C[i] + N) <= 'Z')
		System.out.print((char)(C[i] + N));
	    else {
		int M = (char)(C[i] + N) - 'Z' - 1;
		System.out.print((char)('A' + M));
	    }
	}
	System.out.println();
    }
}

Measured memory_bytes: 25424
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

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

  cout << (regex_match(S, regex("^A[a-z]+C[a-z]+$")) ? "AC" : "WA") << endl;
  return 0;
}


Measured memory_bytes: 3828
package main

import (
	"bufio"
	"flag"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"sort"
	"strconv"
	"strings"
)

var abc = "abcdefghijklmnopqrstuvwxyz"

func (p *problem) solve() {
	s := p.Next()
	K := p.NextInt()
	max := len(s)

	subm := make(map[string]bool)
	for i := 0; i < max; i++ {
		for j := 1; j <= K && (i+j) <= max; j++ {
			subm[s[i:i+j]] = false
		}
	}

	var sub []string
	for k := range subm {
		sub = append(sub, k)
	}
	sort.Strings(sub)
	p.Printf("%v", sub[K-1])
}

var (
	debug  bool
	output string
)

func main() {
	flag.BoolVar(&debug, "debug", false, "Print debug logs")
	flag.BoolVar(&debug, "d", false, "Print debug logs")
	flag.StringVar(&output, "output", "stdout", "Specify output target (Default: stdout)")
	flag.StringVar(&output, "o", "stdout", "Specify output target (Default: stdout)")
	flag.Parse()

	if debug {
		out := os.Stdout
		if output != "stdout" {
			logfile, err := os.OpenFile(output, os.O_CREATE|os.O_WRONLY, 0666)
			if err != nil {
				panic(err)
			}
			defer logfile.Close()
			out = logfile
		}
		log.SetOutput(out)
	} else {
		log.SetOutput(ioutil.Discard)
	}

	p := problem{
		in:  bufio.NewReader(os.Stdin),
		out: bufio.NewWriter(os.Stdout),
	}
	p.solve()

	if err := p.out.Flush(); err != nil {
		panic(err)
	}
}

type problem struct {
	in  *bufio.Reader
	out *bufio.Writer
}

func (p *problem) PrintInt(d int) {
	p.Printf("%d\n", d)
}

func (p *problem) Printf(format string, a ...interface{}) {
	if _, err := fmt.Fprintf(p.out, format, a...); err != nil {
		panic(err)
	}
}

func (p *problem) Printfln(format string, a ...interface{}) {
	if _, err := fmt.Fprintf(p.out, fmt.Sprintf("%v\n", format), a...); err != nil {
		panic(err)
	}
}

func (p *problem) NextInt() int {
	return stoi(p.Next())
}

func (p *problem) NextInts() []int {
	line := p.NextSSLine()
	ds := make([]int, len(line))
	for i, s := range line {
		ds[i] = stoi(s)
	}
	return ds
}

func (p *problem) NextSSLine() []string {
	return strings.Split(p.Next(), " ")
}

// Next reads line and return string.
func (p *problem) Next() string {
	var b []byte
	for {
		l, pre, err := p.in.ReadLine()
		if err != nil {
			panic(err)
		}
		b = append(b, l...)
		if !pre {
			break
		}
	}
	return string(b)
}

func stoi(s string) int {
	i, err := strconv.Atoi(s)
	if err != nil {
		fmt.Println(i)
		fmt.Println(err)
	}
	return i
}


Measured memory_bytes: 3200
#include<stdio.h>
int main(void){
    int w, h, x, y, r;
    scanf("%d %d %d %d %d", &w, &h, &x, &y, &r);
    if(x >= 0 && y >= 0){
        if((w - x) >= r && (h - y) >= r){
            printf("Yes\n");
        }else{
            printf("No\n");
        }
    }else{
        printf("No\n");
    }
    return 0;
}

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

using ll = long long;

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

int main(int argc, char **argv)
{
	ll N, K; cin >> N >> K;
	vector<ll> S(N);
	REP(i, N)
	{
		char c; cin >> c;
		if (c == 'L')
			S[i] = 0;
		else
			S[i] = 1;
	}

	ll t{S[0]};
	for (ll i = 0; i < N; ++i)
	{
		if (i+1 < N && S[i] != t && S[i+1] == t)
			--K;
		S[i] = t;
		if (K == 0) break;
	}

	ll res{0};
	for (ll i = 0; i < N;)
	{
		ll j = i + 1;
		while (j < N && S[i] == S[j])
		{
			++j;
		}
		res += j - i - 1;
		i = j;
	}

	std::cout << res << std::endl;
}


Measured memory_bytes: 1024
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val max = Math.sqrt(n.toDouble()).toInt()

    for (i in 1..max) {
        if (n % i == 0 && n / i <= 9) {
            println("Yes")
            return
        }
    }

    println("No")
}

Measured memory_bytes: 33532
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, A;
  cin >> N >> A;
  cout << N * N - A << endl;
  return 0;
}

Measured memory_bytes: 256