akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <math.h>

using namespace std;

class STACK{
public:
	STACK(){
		index = 0;
	}

	void push(int data){
		array[index] = data;
		index++;
	}
	int pop(){
		index--;
		return array[index];
	}
	bool isEmpty(){
		return index == 0;
	}

private:
	int array[100];
	int index;
};

int main(){

	STACK stack;
	int tmp;
	while(scanf("%d",&tmp) != EOF){
		if(tmp == 0){
			printf("%d\n",stack.pop());
		}else{
			stack.push(tmp);
		}
	}
    return 0;
}

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

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

    cin >> a >> b >> c >> d;

    ll ans = a*c;
    ans = max(ans, a*d);
    ans = max(ans, b*c);
    ans = max(ans, b*d);

    cout << ans << endl;

	return 0;
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int main() {
  int N; cin >> N;
  vector<int> A, B;
  rep(_, N) {
    int a, b; cin >> a >> b;
    A.push_back(a);
    B.push_back(b);
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  if (N % 2) cout << (B[N/2] - A[N/2] + 1) << "\n";
  else cout << (B[N/2-1] + B[N/2] - A[N/2-1] - A[N/2] + 1) << "\n";
}


Measured memory_bytes: 5100
var
	n,k,s,a:int64;
begin
	read(n,k);
	a:=n div k;
	inc(s,a*a*a);
	if (k mod 2=0)and((k div 2)<=n) then begin
		a:=(n-k div 2)div k+1;
		inc(s,a*a*a);
	end;
	write(s);
end.


Measured memory_bytes: 128
from collections import deque
INF = 10**9

class Dinic:
    def __init__(self, n):
        self.n = n
        self.edge = [[] for _ in range(n)]
        self.level = [None] * self.n 
        self.it = [None] * self.n 

    def add_edge(self, fr, to, cap):
        # edge consists of [dest, cap, id of reverse edge]
        forward = [to, cap, None]
        backward = [fr, 0, forward]
        forward[2] = backward
        self.edge[fr].append(forward)
        self.edge[to].append(backward)

    def add_bidirect_edge(self, v1, v2, cap1, cap2):
        edge1 = [v2, cap1, None]
        edge2 = [v1, cap2, edge1]
        edge1[2] = edge2
        self.edge[v1].append(edge1)
        self.edge[v2].append(edge2)

    # takes start node and terminal node
    # create new self.level, return you can flow more or not 
    def bfs(self, s, t):
        self.level = [None] * self.n
        dq = deque([s])
        self.level[s] = 0
        while dq:
            v = dq.popleft()
            lv = self.level[v] + 1
            for dest, cap, _ in self.edge[v]: 
                if cap > 0 and self.level[dest] is None:
                    self.level[dest] = lv
                    dq.append(dest)
        return self.level[t] is not None

    # takes vertex, terminal, flow in vertex
    def dfs(self, v, t, f):
        if v == t:
            return f
        for e in self.it[v]:
            to, cap, rev = e
            if cap and self.level[v] < self.level[to]:
                ret = self.dfs(to, t, min(f, cap))
                # find flow
                if ret:
                    e[1] -= ret
                    rev[1] += ret
                    return ret
        # no more flow
        return 0

    def flow(self, s, t):
        flow = 0
        while self.bfs(s, t):
            for i in range(self.n):
                self.it[i] = iter(self.edge[i])
            # *self.it, = map(iter, self.edge)
            f = INF
            while f > 0:
                f = self.dfs(s, t, INF)
                flow += f
        return flow

N, M = [int(item) for item in input().split()]
n = N + M + 2
dinic = Dinic(n)
for i in range(N):
    line = input().rstrip()
    for j, ch in enumerate(line):
        if ch == ".":
            pass
        elif ch == "o":
            v1 = i + 1
            v2 = N + j + 1
            dinic.add_bidirect_edge(v1, v2, 1, 1)
        elif ch == "S":
            v1 = i + 1
            v2 = N + j + 1
            dinic.add_edge(0, v1, INF)
            dinic.add_edge(0, v2, INF)
        elif ch == "T":
            v1 = i + 1
            v2 = N + j + 1
            dinic.add_edge(v1, n-1, INF)
            dinic.add_edge(v2, n-1, INF)
ans = dinic.flow(0, n-1)
if ans >= INF:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 5492
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    string S;
    cin >> S;
    if(S == "keyence") {
        cout << "YES" << endl;
        return 0;
    }
    for(int i = 0; i < S.size(); i++) {
        for(int j = i + 1; j < S.size(); j++) {
            //[i,j)を消す
            string n = S.substr(0, i);
            n += S.substr(j);
            if(n == "keyence") {
                cout << "YES" << endl;
                return 0;
            }
        }
    }

    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long lli;

main(){
  lli n, s, ans = 0;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> s;
    bool f = true;
    for(lli t=1;2*t*(t+1)<=s;t++){
      if((s - 2 * t * (t + 1)) % (2 * t + 1) == 0) f = false;
    }
    ans += f;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1156
import java.util.*;

public class Main {
 public static void main(String... args) {
   Scanner scan = new Scanner(System.in);
   String[] line = scan.nextLine().split(" ");
   int N = Integer.parseInt(line[0]);
   int M = Integer.parseInt(line[1]);
   
   PriorityQueue<Integer> A = new PriorityQueue<Integer>(Collections.reverseOrder());
   for(int i=0; i<N; i++) {
     A.add(scan.nextInt());
   }
   
   for(int i=0; i<M; i++) {
     A.add(A.poll()/2);
    }

   long sum=0;
   for(int elm : A) {
     sum += elm;
   }
   System.out.println(sum);
 }
}

Measured memory_bytes: 51000
#include <stdio.h>

int main(){
	int H,W;
	int i,j;

	while(1){
		scanf("%d %d", &H,&W);
		if(H==0 && W==0)
			break;
		for(i=0; i<H; i++){
			for(j=0; j<W; j++){
				if(i==0 || j==0 || i==H-1 || j==W-1)
					printf("#");
				else
					printf(".");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    ll N, M;
    cin >> N >> M;
    ll ans = min(N,M/2);
    M -= ans *2;
    if (M > 0) ans += M / 4;
    cout << ans << '\n';


    return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
    ll n;cin >>n;
    vector<ll>a(n,0);
    vector<ll>b(n,0);
    for (int i = 0; i < n; ++i) {
        cin >>a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    reverse(all(b));
    for (int i = 0; i < n-1; ++i) {
        a[i + 1] += a[i];
        b[i + 1] += b[i];
    }
    reverse(all(b));
    ll ans=0;
    for (int i = 0; i < n ; ++i) {
        ans=max(ans,a[i]+b[i]);
    }
    cout <<ans<<endl;
    return 0;
}



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

#define ll long long
#define pb push_back
#define eb emplace_back
//#define st first
#define sc second

using namespace std;

const ll mod = 1e9 + 7;
const int e = 50 + 69;
const int base = 311;

// dung inverse module de tinh nCk
// beginer 74
// mbeginer
// cach tao hoan vi tu n so : n*(n+1)/2;

//vector<pair<ll,ll>>adj[e];
vector<ll>adj[e];

ll Pow(ll n, ll dem)
{
    if(dem == 0) return 1;
    if(dem == 1) return n ;
    ll t = Pow(n, dem/2);
    if(dem % 2 == 0) return (t*t);
    else return ((t * t) * n);
}

/*ll C(ll k, ll n)
{
    if(k == 0) return 1;
    if(n < k) return 0;
    return (gt[n]%mod * (igt[k]%mod * igt[n-k]%mod)%mod)%mod;
}*/

int n, m, k;

bool vs[e], chk;

void dfs(ll i, ll n, ll par)
{
    vs[i] = false;
    if(chk == true) return ;
    for(auto j : adj[i])
    {
        if(j == par && j != n && vs[j] == false)
        {
            chk = true;
        }
        if(chk == true) return ;
        if(vs[j] == true)
        {
            dfs(j, i, par);
        }
    }
}

int main()
{
   cin >> n >> m;
   //for(int i=1; i<=n; i++) vs[i] = true;
   for(int i=1; i<=m; i++)
   {
       ll u, v;
       cin >> u >> v;
       adj[u].pb(v);
       adj[v].pb(u);
   }
   ll ans = 0;
   for(int i=1; i<=n; i++)
   {
       chk = false;
       memset(vs, true, 2*n);
       dfs(i, i, i);
       if(chk == false) ans ++;
   }
   if(ans == n) ans --;
   cout << ans;
}
/*

*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mod 1000000007
int32_t main()
{
	fast;
	int n;
	double pi = 3.14159;
	cin >> n;
	cout << 2 * n*pi;



}

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

using namespace std;

int main() {
  int d, n;
  cin >> d >> n;
  for (int i = 1;; i++) {
    int c = 0;
    int t = i;
    while (t % 100 == 0) {
      t /= 100;
      c++;
    }
    if (c == d) {
      n--;
      if (n == 0) {
        cout << i << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
using namespace std;
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
//     tree_order_statistics_node_update>;
 
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")
typedef long long int ll;
typedef long double ld;

const ll N = 2e5 + 9;
// const ll m = 1e9 + 7;
const ll INF = 1e14;
const ll mod =1e9+7;
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define pld pair<ld,ld>
ll powm(ll a, ll b) { a = a%mod;ll res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; }
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout); 
    freopen("error.txt", "w", stderr); 
    #endif      
    int T = 1;
    // cin>>t;
    while(T--){
        ll n,x,t;cin>>n>>x>>t;
        ll ans = n/x + !!(n%x);
        cout<<(ans*t)<<'\n';
    }
}

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

vector<vector<vector<bool>>> done(11, vector<vector<bool>>(1001, vector<bool>(101, false)));
vector<vector<vector<int>>> memo(11, vector<vector<int>>(1001, vector<int>(101, 0)));

int dp(int &D, vector<int> &p, vector<int> &c, int n, int w, int k) {
  int out = 0;
  if (done.at(n).at(w).at(k) == true)  return memo.at(n).at(w).at(k);
  if ( w <= 0 || n <= 0 || n > D || k > p.at(n) )  out = 0;
  else if (k <= 0) {
    out = dp(D, p, c, n - 1, w, p.at(n - 1));
  }
  else if (k > w) {
    out = dp(D, p, c, n, w, k - 1);
  }
  else {
    out = max(dp(D, p, c, n, w, k - 1), dp(D, p, c, n - 1, w - k, p.at(n-1)) 
                                       + k * 100 * n + (k == p.at(n)) * c.at(n));
  }
  done.at(n).at(w).at(k) = true; memo.at(n).at(w).at(k) = out;
  return out;
}

int main() {
  int D, G;
  cin >> D >> G;
  vector<int> p(D + 1), c(D + 1);
  for (int i=1; i <= D; i++) {
    cin >> p.at(i) >> c.at(i);
  }
  int pa = 0;
  for (int j=0; j <= 1000; j++) {
    pa = dp(D, p, c, D, j, p.at(D));
  // 検証用  cout << j << " " << pa << endl;
    if (pa >= G) {
      cout << j << endl;
      return 0;
    }
  }
}


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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define bb begin()
#define ee end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);
#define eps 1e-9



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;





int arr[g_size];



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

	int n,m,T,res;

	int maxi=-mx,mini=mx,count=0;

	int i,j,k;

	bool flag;

	string s1,s2;

	char s[100000];

	int ara[n_size],ara2[n_size];

	sc st;

	cin>>s;

	f(i,0,2) st.insert(s[i]);

	if(st.size()==3) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;



}


Measured memory_bytes: 256
from collections import Counter
import math

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

    cnt = Counter(A)
    # print(cnt)
    def comb(n, r):
        if n - r < 0: return 0
        if n - r < r: r = n - r
        if r == 0: return 1
        if r == 1: return n

        numerator = [n - r + k + 1 for k in range(r)]
        denominator = [k + 1 for k in range(r)]

        for p in range(2, r + 1):
            pivot = denominator[p - 1]
            if pivot > 1:
                offset = (n - r) % p
                for k in range(p - 1, r, p):
                    numerator[k - offset] /= pivot
                    denominator[k] /= pivot

        result = 1
        for k in range(r):
            if numerator[k] > 1:
                result *= int(numerator[k])

        return result
    cnt_comb = {}
    sm = 0
    for key, val in cnt.items():
        tmp = comb(val, 2)
        cnt_comb[key] = tmp
        sm = sm + tmp
    # print(cnt_comb)

    # print(list(A))
    for a in A:
        comb_val = cnt_comb.get(a)
        cmb = comb(cnt.get(a) - 1, 2)
        print(sm - comb_val + cmb)



if __name__ == '__main__':
    solver()


Measured memory_bytes: 32156
# include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, m, a=0, b=0, f=1;
    scanf("%d",&n);
    while(n--)
    {
        scanf("%d",&m);
        if(m%4 == 0) ++a;
        else
        {
            if(m%2 == 0)
            {
                b += f;
                f = 0;
            }
            else ++b;
        }
    }
    if(a >= b-1) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int i,N,K,a{1};
int main(){
    cin>>N>>K;
    for(;i<N&&a<K;++i)
        a*=2;
    for(;i<N;++i)
        a+=K;
    cout<<a<<endl;
}


Measured memory_bytes: 256
import collections
import sys
import time
sys.setrecursionlimit(10 ** 5)
N, M, P = map(int, input().split())
e = collections.defaultdict(list)
st = time.time()
for _ in range(M):
  u, v, c = map(int, input().split())
  e[u].append((v, c))
def isConnected(n):
  if n == N:
    return True
  vis = [0] * (N + 1)
  que = collections.deque([])
  que.append(n)
  while que:
    nc = que.popleft()
    vis[nc] = 1
    for o in e[nc]:
      if o[0] == N:
        return True
      if vis[o[0]] == 0:
        que.append(o[0])
  return False
inf = 10 ** 10
visited = [0] * (N + 1)
earn = [-inf] * (N + 1)
earn[1] = 0
def dfs(now):
  global visited
  global earn
  nt = time.time() - st
  if nt > 1.95:
    print(max(earn[N], 0))
    exit(0)
  visited[now] = 1
  for n in e[now]:
    if visited[n[0]] == 0:
      if n[1] + earn[now] - P > earn[n[0]]:
        earn[n[0]] = n[1] + earn[now] - P
        dfs(n[0])
        visited[n[0]] = 0
    else:
      if earn[n[0]] < n[1] + earn[now] - P:
        if isConnected(n[0]) == True:
          print(-1)
          exit(0)
dfs(1)
print(max(earn[N], 0))




Measured memory_bytes: 6812
n = gets.to_i # 数列Aの長さ int
A = gets.split(" ").map(&:to_i) # 数列A [int] [1 5 7 10 21]
q = gets.to_i # 与えられる整数の個数 int
M = gets.split(" ").map(&:to_i) # q 個の整数 [int] [2 4 17 8]


def finded_match(array, m)
  if array.sum < m
    return false
  end
  array = array.select { |a| a <= m }
  (1..array.length).each do |i|
    if array.combination(i).to_a.map(&:sum).any? {|s| s == m}
      return true
    end
  end
  return false
end

M.each do |m|
  puts finded_match(A, m) ? "yes" : "no"
end



Measured memory_bytes: 82360
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

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

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


int main()
{
	ll n, p;
	cin >> n >> p;

	vector<ll> a(n);
	ll even = 0;
	ll odd = 0;
	for (ll i = 0; i < n; i++)
	{
		cin >> a[i];

		if (a[i] % 2 == 0)
		{
			even++;
		}
		else
		{
			odd++;
		}
	}

	ull res = 1;
	if (p == 0)
	{
		for (ll i = 0; i < even; i++)
		{
			res *= 2;
		}

		for (ll i = 0; i < odd - 1; i++)
		{
			res *= 2;
		}
	}
	else
	{
		if (odd == 0)
		{
			res = 0;
		}
		for (ll i = 0; i < even; i++)
		{
			res *= 2;
		}

		for (ll i = 0; i < odd - 1; i++)
		{
			res *= 2;
		}
	}

	println(res);
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>
#include <complex>
 
 
using namespace std;
 
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
 
 
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
 
const int MOD =  1e9 + 7; 
 
 
 
ll power(ll a, ll b){
	if(b == 0) return 1;
	else {
		ll x = power(a,b/2);
		x = (x*x)%MOD;
		if(b&1) return (x*a)%MOD;
		else return x;
	}
}
 
 
ll& Mod(ll& a) {
    if (a >= MOD) {
        return Mod(a -= MOD);
    } else if (a < 0) {
        return Mod(a += MOD);
    } else {
        return a;
    }
}
 
ll gcd(ll a, ll b) { 
	// b < a
    if (b == 0) 
        return a; 
    return gcd(b, a % b); 
} 
 
 
const int N = 200000 + 10;
double a[N];
 
 
int main() {
	fast_cin();	
	
	int n, k;
	cin >> n >> k;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		a[i] = (a[i] + 1)/2;
	}
	
	double ans = 0;
	double curSum = 0;
	for(int i = 0; i < k; i++){
		ans += a[i];
	}
	curSum = ans;
	
	int toRem = 0;
	for(int i = k; i < n; i++){
		curSum -= a[toRem++];
		curSum += a[i];
		ans = max(curSum, ans);
	}
	
	cout << setprecision(8) << ans << '\n';
	
	
		
}


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

int main() {
	string a;
	while (getline(cin,a),a!=".") {
		vector<int>s;
		for (int b = 0; b < a.length(); b++) {
			if (a[b] == '(' || a[b] == '[') { s.push_back(a[b]); }
			else if (a[b] == ')') {
				if (s.size() == 0 || s[s.size() - 1] !='(') { goto l; }
				s.pop_back();
			}
			else if (a[b] == ']') {
				if (s.size() == 0 || s[s.size() - 1] != '[') { goto l; }
				s.pop_back();
			}
		}
		if (s.size() != 0)goto l;
		cout << "yes" << endl;
		goto r;
	l:;
		cout << "no" << endl;
	r:;
	}
}

Measured memory_bytes: 3160
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

#ifdef LOCAL
#include "../ACL.hpp"
#else
#include <atcoder/all>
#endif

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    LL n,m;
    cin >> n  >> m;
    int a,b;
    atcoder::dsu d(n);
    REP(i,0,m) {
        cin >> a >> b;
        --a;--b;
        d.merge(a,b);
    }
    set<int> s;
    REP(i,0,n) s.insert(d.leader(i));
    cout << s.size() - 1 << endl;
}

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

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

int main() {
  int N;
  cin >> N;
  
  vector<int> function(N);
  for (int i = 0; i < N; i++) {
    cin >> function.at(i);
  }
  
  int ball = 0;
  
  for (int i = 0; i < N; i++) {
    ball = function.at(ball) - 1;
    if (ball == 1) {
      cout << i + 1 << endl;
      break;
    }
    if (i == N - 1)
      cout << -1 << endl;
  }
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  while(cin>>n&&n){
    int c=0,m=n;
    vector<int> d(n);
    for(int i=0;i<n;++i) cin>>d[i];
    sort(d.begin(),d.end());
    while(d[c]==0){
      ++c; --m;
    }
    if(m==0||d[n-1]<=1) cout<<"NA"<<endl;
    else cout<<m+1<<endl;
  }
  return 0;
}



Measured memory_bytes: 3204
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> H >> W;
	vector< string > S(H);
	rep(i, H) cin >> S[i];
	vector< vector< int > > D(H * W, vector< int >(H * W, LINF));
	int N = H * W;
	rep(i, N) D[i][i] = 0;
	rep(k, N) {
		int i = k / W;
		int j = k % W;
		if (S[i][j] == '#')
			continue;
		rep(l, 4) {
			int ni = i + di[l];
			int nj = j + dj[l];
			if (0 <= ni && ni < H && 0 <= nj && nj < W && S[ni][nj] == '.') {
				D[k][ni * W + nj] = 1;
			}
		}
	}
	rep(k, N) rep(i, N) rep(j, N) chmin(D[i][j], D[i][k] + D[k][j]);
	int ans = 0;
	rep(i, N) rep(j, N) if (D[i][j] != LINF) chmax(ans, D[i][j]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
int main(){
	vector<int> cnt(2,0);
	string s;
	cin>>s;
	rep(i,s.size()){
		cnt.at(s.at(i)-'0')++;
	}
	cout<<(2*min(cnt.at(0),cnt.at(1)))<<endl;
	return 0;
}

Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

class UnionFind {
    int cnt;
    vector<int> par, rank, size;
public:
    UnionFind() {}
    UnionFind(int _n) :cnt(_n), par(_n), rank(_n), size(_n, 1) {
        for (int i = 0; i<_n; ++i) par[i] = i;
    }
    int find(int k) {
        return (k == par[k]) ? k : (par[k] = find(par[k]));
    }
    int operator[](int k) {
        return find(k);
    }
    int getSize(int k) {
        return size[find(k)];
    }
    void unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return;
        --cnt;
        if (rank[x] < rank[y]) {
            par[x] = y;
            size[y] += size[x];
        } else {
            par[y] = x;
            size[x] += size[y];
            if (rank[y] == rank[x]) ++rank[x];
        }
    }
    int count() {
        return cnt;
    }
};

void solve() {
    int N, M, K;
    cin >> N >> M >> K;
    int L = K;
    vi C(N);
    rep(i, N) {
        cin >> C[i];
        --C[i];
        if (C[i] == -1) {
            C[i] = L++;
        }
    }
    using E = tuple<int, int, int>;
    vector<E> ed(M);
    rep(i, M) {
        int a, b, w;
        cin >> a >> b >> w;
        --a; --b;
        ed[i] = tie(w, C[a], C[b]);
    }
    sort(all(ed));
    UnionFind uf(L);
    ll ans = 0;
    int ne = 0;
    each(e, ed) {
        int w, u, v;
        tie(w, u, v) = e;
        if (uf[u] != uf[v]) {
            ans += w;
            uf.unite(u, v);
            if (++ne == K - 1) {
                break;
            }
        }
    }
    if (ne < K - 1)ans = -1;
    cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}

Measured memory_bytes: 4224
#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    int b[n-1];
    for (int i = 0; i < n-1; i++)
    {
        scanf("%d",&b[i]);
    }
    int sum=b[0];
    for (int i = 0; i < n-2; i++)
    {
        if (b[i]<b[i+1])
        {
            sum+=b[i];
        }else{
            sum+=b[i+1];
        }
    }
    sum+=b[n-2];
    printf("%d",sum);
    return 0;
}

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

int main(){
  ll mod=1e9+7;
  ll n,m;
  cin>>n>>m;
  if(abs(n-m)==0){
    ll ans=2;
    for(ll i=1;i<=n;i++){
      ans*=i;
      ans%=mod;
      ans*=i;
      ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
  }
  if(abs(n-m)==1){
    ll ans=1;
    for(ll i=1;i<=min(n,m);i++){
      ans*=i;
      ans%=mod;
      ans*=i;
      ans%=mod;
    }
    ans*=max(n,m);
    ans%=mod;
    cout<<ans<<endl;
    return 0;
  }
  cout<<0<<endl;
  return 0;
}

Measured memory_bytes: 3616
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

#define chmax(a, b) (a) = max(a, b)
#define chmin(a, b) (a) = min(a, b)

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

  vector<int> encode(26);
  encode['R' - 'A'] = 0;
  encode['U' - 'A'] = 1;
  encode['L' - 'A'] = 2;
  encode['D' - 'A'] = 3;

  using D = tuple<int, int, int>;
  vector<D> data;
  rep(i, N) {
    int x, y;
    char d;
    cin >> x >> y >> d;

    data.push_back(D(x, y, encode[d - 'A']));
  }

  constexpr int INF = numeric_limits<int>::max();
  int result = INF;

  constexpr int MAX = 200'000;
  vector<vector<vector<int>>> tbl(4, vector<vector<int>>(MAX + 1));
  rep(i, N) {
    int x, y, d;
    tie(x, y, d) = data[i];

    if (d % 2 == 1) {
      swap(x, y);
    }
    tbl[d][y].push_back(x);
  }
  rep(i, 4) irep(j, MAX) { sort(tbl[i][j].begin(), tbl[i][j].end()); }

  rep(i, 2) {
    irep(j, MAX) {
      for (int elm : tbl[i][j]) {
        const auto &tmp = tbl[i + 2][j];
        auto iter = lower_bound(tmp.begin(), tmp.end(), elm);
        if (iter != tmp.end()) {
          // cerr << i << " " << j << " " << v << " " << *iter << "\n";
          chmin(result, 5 * (*iter - elm));
        }
      }
    }
  }

  rep(i, 4) {
    vector<vector<int>> hori(2 * MAX + 1), vert(2 * MAX + 1);

    rep(j, N) {
      int x, y, d;
      tie(x, y, d) = data[j];

      // assert(0 <= x + y && x + y <= 2 * MAX);
      if (d == i) {
        hori[x + y].push_back(x - y);
      } else if (d == (i + 1) % 4) {
        vert[x + y].push_back(x - y);
      }
      data[j] = D(y, -x + MAX, d);
    }

    irep(j, 2 * MAX) {
      auto &h = hori[j], &v = vert[j];
      sort(h.begin(), h.end());
      sort(v.begin(), v.end());
      for (int elm : h) {
        auto iter = lower_bound(v.begin(), v.end(), elm);
        if (iter != v.end()) {
          chmin(result, 5 * (*iter - elm));
        }
      }
    }
  }

  if (result == INF) {
    cout << "SAFE" << endl;
  } else {
    cout << result << endl;
  }
  return 0;
}

Measured memory_bytes: 54944
#include<stdio.h>
#include<string.h>

int main(void)
{
    char s[10],t[10],u[10];
    int a,b;

    scanf("%s %s",&s,&t);
    scanf("%d %d",&a,&b);
    scanf("%s",&u);
    
    if(strcmp(s,u)==0){
        a--;
    }
    if(strcmp(t,u)==0){
        b--;
    }

    printf("%d %d",a,b);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll n;
  string s;
  cin >> n >> s;
  ll ans=n;
  rep(i,n-1){
    if(s[i]==s[i+1]){
      ans--;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
using ll = long long;

int main() {
    int n; cin>>n;
    string s;cin >> s;
    int id = -1;
    for (int i=0;i<n;i++) {
        if (s[i]=='#') {id = i;break;}
    }
    if (id==-1) cout << 0 << endl;
    else {
        vector<int> ls(n-id,0),rd(n-id,0),cl(n-id+1,999999999);
        auto ns = s.substr(id);
        auto ns_length = ns.length();
        ls[0] = (ns[0]=='#' ? 1 : 0);
        for (int i=1;i<ns_length;i++) {
            ls[i] = ls[i-1];
            if (ns[i]=='#') ls[i]++;
        }
        rd[ns_length-1] = (ns[ns_length-1]=='.' ? 1 : 0);
        for (int j=ns_length-2;j>=0;j--) {
            rd[j] = rd[j+1];
            if (ns[j]=='.') rd[j]++;
        }

        for (int i=0;i<ns_length+1;i++) {
            if (i==0) cl[i] = rd[i];
            else if (i==ns_length) cl[i] = ls[i-1];
            else cl[i] = rd[i]+ls[i-1];
        }

        auto mini = min_element(cl.begin(),cl.end());
        //cout << "smallest: " << *mini << endl;
        cout << *min_element(cl.begin(),cl.end()) << endl;
    }
    return 0;
}

Measured memory_bytes: 3076
package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	h := make([]int, n + 1)
	for i := 1; i <= n; i++ {
		fmt.Scan(&h[i])
	}
	a := make([]int, m + 1)
	b := make([]int, m + 1)
	for i := 1; i <= m; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	hismax := make([]bool, n + 1)
	for i := 1; i <= n; i++ {
		hismax[i] = true
	}
	for i := 1; i <= m; i++ {
		if h[a[i]] <= h[b[i]] {
			hismax[a[i]] = false
		}
		if h[b[i]] <= h[a[i]] {
			hismax[b[i]] = false
		}
	}
	result := 0
	for i := 1; i <= n; i++ {
		if hismax[i] {
			result++
		}
	}
	fmt.Println(result)
}

Measured memory_bytes: 7308
#include<stdio.h>

int N,s[100000];

int solve(int i,int m){
  int res;
  if(m==0)return 1;
  if(i>=N)return 0;
  res=solve(i+1,m)||solve(i+1,m-s[i]);
  return res;
}

int main(){

  int i,j,N2,flag=0,m;

  scanf("%d",&N);

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

  scanf("%d",&N2);

  for(j=0;j<N2;j++){
    scanf("%d",&m);
    flag=solve(0,m);
    if(flag==1)printf("yes\n");
    else printf("no\n");
  }

  return 0;
}


Measured memory_bytes: 2108
a,b,k=map(int,input().split())
c=i=0
l=[]
while i<min(a,b):
    while i<min(a,b)and(a%-~i or b%-~i):
        i+=1
    i+=1
    if a%i<1and b%i<1:
        l.append(i)
print(l[-k])

Measured memory_bytes: 3060
A,B,Q=list(map(int,input().split()))
s=[0]*(A+2)
t=[0]*(B+2)
X=[0]*Q
s[0] = -float('inf')
s[A+1] = float('inf')
t[0] = -float('inf')
t[B+1] = float('inf')
for i in range(1,A+1):
    s[i] = int(input())
for i in range(1,B+1):
    t[i] = int(input())
for i in range(Q):
    X[i] = int(input())

import bisect

for x in X:
    s_i = bisect.bisect_left(s,x)
    t_i = bisect.bisect_left(t,x)
    s_l = abs(s[s_i-1]-x)
    s_r = s[s_i]-x
    t_l = abs(t[t_i-1]-x)
    t_r = t[t_i]-x
    ans = min([max(s_l,t_l),s_l+t_r+min(s_l,t_r),s_r+t_l+min(s_r,t_l),max(s_r,t_r)])

    print(ans)




Measured memory_bytes: 113724
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;


int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

    vector<int> h(n),l(n),r(n);
    int i;
    for(i=0; i<n; i++) {
        scanf("%d", &h[i]);
    }

    vector<int> v;
    for(i=0; i<n; i++) {
        while(!v.empty() && h[v.back()]>=h[i]) {
            v.pop_back();
        }
        l[i]=(v.empty()? 0: v.back()+1);
        v.push_back(i);
    }

    v.clear();
    for(i=n-1; i>=0; i--) {
        while(!v.empty() && h[v.back()]>=h[i]) {
            v.pop_back();
        }
        r[i]=(v.empty()? n-1: v.back()-1);
        v.push_back(i);
    }

    ll S=0;
    for(i=0; i<n; i++) {
        ll tmp=(ll)h[i]*(r[i]-l[i]+1);
        S=MAX(S,tmp);
    }
    printf("%lld\n", S);

    return 0;
}



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

using namespace std;

typedef unsigned long long ull; 
ull firstDigit(ull n) 
{ 
    while (n >= 10)  
        n /= 10; 
      
    return n; 
} 
  
int lastDigit(int n) 
{ 
    return (n % 10); 
} 

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

    int n;
    cin >> n;
    vector<vector<ull>> arr = vector<vector<ull>>(10, vector<ull>(10, 0));

    for (int i = 1; i <= n; i ++) {
        arr[firstDigit(i)][lastDigit(i)] ++;
    }

    unsigned long long sum = 0;
    for (int i = 0; i < 9; i ++) {
        for (int j = 0; j < 9; j ++) {
            sum += arr[i + 1][j + 1] * arr[j + 1][i+1];
        }
    }

    cout << sum;

    return 0;
}

Measured memory_bytes: 256
O=str(input())
E=str(input())
passwords=str()

if len(O)==len(E):
    for i in range(0,len(O)):
        passwords=passwords+O[i]
        passwords=passwords+E[i]
elif len(O)>len(E):
    for i in range(0,len(E)):
        passwords=passwords+O[i]
        passwords=passwords+E[i]
    passwords=passwords+O[-1]
else:
    for i in range(0,len(O)):
        passwords=passwords+O[i]
        passwords=passwords+E[i]
    passwords=passwords+E[-1]
    
print(passwords)

Measured memory_bytes: 3064
public class Main {

  private static void solve() {
    int n = ni();
    int m = ni();
    
    if (n > m) {
      int tmp = n;
      n = m; 
      m = tmp;
    }
    
    //n <= m
    if (n == 1 && m == 1) {
      System.out.println(1);
    } else if (n == 1) {
      System.out.println(Math.max(0, m - 2));
    } else {
      System.out.println((long)(n - 2) * (m - 2));
    }
  }

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

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

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

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

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

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

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

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

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

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

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

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


Measured memory_bytes: 21204
#include<iostream>

using namespace std;

struct t_num_;
typedef struct t_num_ t_num;

typedef struct t_num_{
	int m10,m50,m100,m500;
	t_num operator+(const t_num&obj){
		t_num_ t;
		t.m10=this->m10+obj.m10;
		t.m50=this->m50+obj.m50;
		t.m100=this->m100+obj.m100;
		t.m500=this->m500+obj.m500;
		return t;
	}
	t_num operator-(const t_num&obj){
		t_num t;
		t.m10=this->m10-obj.m10;
		t.m50=this->m50-obj.m50;
		t.m100=this->m100-obj.m100;
		t.m500=this->m500-obj.m500;
		return t;
	}
	int sumn(){
		return m10+m50+m100+m500;
	}
	int summoney(){
		return m10*10+m50*50+m100*100+m500*500;
	}
	void print(){
		cout<<m10<<" "<<m50<<" "<<m100<<" "<<m500<<endl;
	}
}t_num;

t_num nturi(int money){
	t_num t;
	t.m500=money/500;
	money%=500;
	t.m100=money/100;
	money%=100;
	t.m50=money/50;
	money%=50;
	t.m10=money/10;
	return t;
}

int main(){
	int n,start_flag=1;
	
	while(cin>>n){
		if(!n)break;
		if(!start_flag)cout<<endl;
		start_flag=0;
		int e10,e50,e100,e500;
		cin>>e10>>e50>>e100>>e500;
		
		t_num mai={e10,e50,e100,e500};
		t_num mint={100,100,100,100};
		t_num ans;
		
		
		for(int i=0;i<=e500;i++){
			for(int j=0;j<=e100;j++){
				for(int k=0;k<=e50;k++){
					for(int l=0;l<=e10;l++){
						t_num watasu={l,k,j,i};
						if(n>watasu.summoney())continue;
						t_num ttemoto=mai-watasu;
						if(mint.sumn()>nturi(watasu.summoney()-n).sumn()+ttemoto.sumn()){
							mint=nturi(watasu.summoney()-n)+ttemoto;
							ans=watasu;
						}
					}
				}
			}
		}
		if(ans.m10)cout<<10<<' '<<ans.m10<<endl;
		if(ans.m50)cout<<50<<' '<<ans.m50<<endl;
		if(ans.m100)cout<<100<<' '<<ans.m100<<endl;
		if(ans.m500)cout<<500<<' '<<ans.m500<<endl;
	}
	return 0;
}

Measured memory_bytes: 864
#include<bits/stdc++.h>
using namespace std;
const int N=2e5,inf=1e9;
int x[N],y[N],n;char dr[N],d[]="URDL";
void rotate(){
	int t;
	for(int i=0;i<n;i++){
		t=y[i],y[i]=N-x[i],x[i]=t;
		for(int j=3;~j;j--)if(dr[i]==d[j]){dr[i]=d[(j+1)%4];break;}
	}
}
vector<pair<int,char> >v[N*2+5];pair<int,char>pre;
int calc(){
	int ret=inf;
	for(int i=N<<1;~i;i--)v[i].clear();
	for(int i=0;i<n;i++)
		if(dr[i]=='R'||dr[i]=='U')v[x[i]+y[i]].push_back(make_pair(x[i],dr[i]));
	for(int i=N<<1;~i;i--){
		sort(v[i].begin(),v[i].end());pre.second='D';
		for(auto x:v[i]){
			if(pre.second=='R'&&x.second=='U')ret=min(ret,(x.first-pre.first)*10);
			pre=x;
		}
	}
	return ret;
}
int calc1(){
	int ret=inf;
	for(int i=N;~i;i--)v[i].clear();
	for(int i=0;i<n;i++)
		if(dr[i]=='R'||dr[i]=='L')v[y[i]].push_back(make_pair(x[i],dr[i]));
	for(int i=N;~i;i--){
		sort(v[i].begin(),v[i].end());pre.second='D';
		for(auto x:v[i]){
			if(pre.second=='R'&&x.second=='L')ret=min(ret,(x.first-pre.first)*5);
			pre=x;
		}
	}
	return ret;
}
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d%d%s",x+i,y+i,dr+i);
	int ans=inf;
	for(int i=0;i<4;i++){
		ans=min(ans,min(calc(),calc1()));
		rotate();
	}
	if(ans==inf)puts("SAFE");
	else printf("%d",ans);
	return 0;
} 

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

using namespace std;

struct node{
	vector<int> cld;
	bool vis;
	int as;
	node(){
		vis = 0;
		as = 0;
	}
}a[100005];

void dfs(int n){
	if(a[n].vis) return;
	a[n].vis = 1;
	for(int i : a[n].cld){
		dfs(i);
		a[n].as = max(a[n].as , a[i].as + 1);
	}
}

int main(){
	int n , m;
	cin>>n>>m;
	for(int i = 0 ; i < m ; i++){
		int aa , b;
		cin>>aa>>b;
		aa-- , b--;
		a[aa].cld.push_back(b);
	}
	for(int i = 0 ; i < n ; i++){
		dfs(i);
	}
	int ans = 0;
	for(int i = 0 ; i < n ; i++) ans = max(ans , a[i].as);
	cout<<ans<<endl;
}

Measured memory_bytes: 11892