akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
#define endl "\n"
using namespace std;
const ll N=500010;

ll n;
vector<ll> adj[N];
ll val[N];

vector<ll> ans;
vector<ll> lis;

void dfs(ll v,ll p)
{
    if(lis.size()==0){
        lis.pb(val[v]);
        ans[v]=lis.size();
        for(auto u:adj[v]){
            if(u==p){continue;}
            dfs(u,v);
        }
        lis.pop_back();
    }
    else if(val[v]<lis[0]){
        ll oldvalue=lis[0];
        lis[0]=val[v];
        ans[v]=lis.size();
        for(auto u:adj[v]){
            if(u==p){continue;}
            dfs(u,v);
        }
        lis[0]=oldvalue;
    }
    else if(val[v]>lis.back()){
        lis.pb(val[v]);
        ans[v]=lis.size();
        for(auto u:adj[v]){
            if(u==p){continue;}
            dfs(u,v);
        }
        lis.pop_back();
    }
    else{
        ll idx=lower_bound(lis.begin(),lis.end(),val[v])-lis.begin();
        ll oldvalue=lis[idx];
        lis[idx]=val[v];
        ans[v]=lis.size();
        for(auto u:adj[v]){
            if(u==p){continue;}
            dfs(u,v);
        }
        lis[idx]=oldvalue;
    }
}

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

    cin>>n;
    for(ll i=1;i<=n;++i){cin>>val[i];}
    for(ll i=0;i<n-1;++i){
        ll a,b;
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }

    ans.resize(n+1,0);

    dfs(1,1);

    for(ll i=1;i<=n;++i){
        cout<<ans[i]<<endl;
    }

    return (0);
}


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

 
int main() {
  int m;
  cin >> m;
  ll now = 0;
  ll d = 0;
  rep(i,m){
    ll a,b;
    cin >> a >> b;
    d += b;
    now += a * b;

  }
  
  cout << (now-1)/9 + d - 1 << endl;  

  return 0;
}




Measured memory_bytes: 256
def fib(n):
    fib.cache = vars(fib).setdefault("cache", {})

    def f(n):
        if n <= 1:
            return 1
        else:
            return fib(n - 1) + fib(n - 2)

    if n not in fib.cache:
        fib.cache[n] = f(n)
    return fib.cache[n]


def main():
    print(fib(int(input())))


if __name__ == '__main__':
    main()


Measured memory_bytes: 5612
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int m=0,p=0;
	char a;
	for(int i=0;i<4;i++)
	{
		scanf("%c",&a);
		if(a=='+')
			p++;
		else if(a=='-')
			m++;
	}
	printf("%d",p-m);
	return 0;
}

Measured memory_bytes: 256
/**
*  author: rits1272
*  created: Aug 29, 2020
**/
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define print(x) cout << "[" << #x << ":" << x << "] "; 
#define println(x) cout << "[" << #x << ":" << x << "]\n";

const int mxN = 2e5 + 5;
vector<bool> vis(mxN, false);
vector<int> adj[mxN];

int n, m, sz = 0;

void dfs(int u){
    vis[u] = true;
    sz++;
    for(int v: adj[u]){
	if(!vis[v])
	    dfs(v);
    }
}

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;	
    set<pair<int, int>> s;
    for(int i=0; i<m; i++){
	int u, v; cin >> u >> v;
	if(s.count({u, v}) || s.count({v, u}))
	    continue;
	adj[u].push_back(v);
	adj[v].push_back(u);
	s.insert({u, v});
	s.insert({v, u});
    }
    int cap = 0;
    for(int i=1; i<=n; i++){
	if(!vis[i]){
	    dfs(i);
	    cap = max(cap, sz);
	    sz = 0;
	}
    }
    cout << cap << "\n";
    return 0;
}


Measured memory_bytes: 45772
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<pair<ll, ll>> pll;
 
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}


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

  ll n, x, y;
  cin >> n >> x >> y;

  vector<ll> ans(n);
  for(ll i = 1; i <= n; i++){
    for(ll j = i+1; j <= n; j++){
      if(i < x){
        if(j <= x) ans[j-i]++;
        else if(j <= y) ans[min(j-i, (x-i)+1+(y-j))]++;
        else ans[(x-i)+1+(j-y)]++;
      }else if(i < y){
        if(j <= y) ans[min(j-i, (i-x)+1+(y-j))]++;
        else ans[min(j-i, (i-x)+1+(j-y))]++;
      }else{
        ans[j-i]++;
      }
    }
  }

  for(ll i = 1; i < n; i++){
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a=[int(i) for i in input().split()]
a=sorted(a)
max = a[-1]
tmp = 0
for i in range(len(a)):
    if a[i] > max/2:
        tmp=i-1
        break
if max/2-a[tmp] <= -max/2+a[tmp+1]:
    print("{} {}".format(max, a[tmp]))
else:
    print("{} {}".format(max, a[tmp+1]))
    


Measured memory_bytes: 14052
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,d,r;
double f;
cin >> a>>b;
d=(a/b);
r=a;
r%=b;
f=a;
f/=b;
f*=1.00000;
printf("%d %d %.5lf\n",d, r, f);
return 0;
}


Measured memory_bytes: 3232
import math
N,D = map(int,input().split(" "))
c = 0
def ds(one,two):
    temp = 0
    for i in range(D):
        temp += abs(one[i] - two[i])**2
    return math.sqrt(temp)

list = []
for i in range(N):
    X = input().split(" ")
    X = [int(i) for i in X]
    list.append(X)
#print(list)
dist_mt = []
for i in range(N):
    temp = []
    for j in range(N):
        if i == j:
            el = 0
        else:
            el = ds(list[i],list[j]) 
        temp.append(el)     
    dist_mt.append(temp)
#print(dist_mt)
for i in range(N):
    for j in range(N):
        if i != j and dist_mt[i][j].is_integer() == True:
            c += 1
print(int(c/2))

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
 
signed compare(const void *a, const void *b){
	return *(int *)a - *(int *)b;
}
 
int main(){
	int N, M, i;
	scanf("%d %d", &N, &M);
	int *X = (int *)malloc(sizeof(int) * M);
	for(i = 0; i < M; i++){
		scanf("%d", &X[i]);
	}
	if(N >= M){
		printf("0\n");
		return 0;
	}
	qsort(X, M, sizeof(int), compare);
	int *sub = (int *)malloc(sizeof(int) * (M - 1));
	for(i = 1; i < M; i++){
		sub[i - 1] = X[i] - X[i - 1];
	}
	qsort(sub, M - 1, sizeof(int), compare);
	int ans = 0;
	for(i = 0; i < M - N; i++){
		ans += sub[i];
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1396
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <utility>
#include <cmath>
using namespace std;

typedef long long ll;

const int limit=100;
char grid[limit+1][limit+1];

void solve(int, int);
int main(){
  int a, b; cin >> a >> b;

  solve(a, b);

  return 0;
}

void solve(int a, int b){
  int wh=1, bl=1;
  for(int i=1; i<=limit; i++){
    for(int j=1; j<=limit; j++){
      if(i<=limit/2) grid[i][j]='.';
      else grid[i][j]='#';
    }
  }

  for(int i=1; i<limit/2; i+=2){
    for(int j=1; j<=limit && bl<b; j++){
      if(j%2) {
        grid[i][j] = '#';
        bl++;
      }
    }
  }

  for(int i=limit; i>limit/2+1; i-=2){
    for(int j=1; j<=limit && wh<a; j++){
      if(j%2) {
        grid[i][j] = '.';
        wh++;
      }
    }
  }

  cout << limit << " " << limit << endl;
  for(int i=1; i<=limit; i++){
    for(int j=1; j<=limit; j++) cout << grid[i][j];
    cout << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>

int main(){
   int N, T;
   std::cin >> N >> T;
   int c, t;
   int min = 1001;
   int mint = T + 1;
   for(int i=0; i<N; ++i){
      std::cin >> c >> t;
      if(t>T) continue;
      if(min>c) {
	min = c;
	mint = t;
      }
   }
   if(mint>T) std::cout << "TLE" << std::endl;
   else std::cout << min << std::endl;

   return 0; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const int mod = 1e9 + 7;

const int m = 2019;

int main()
{

    int a, b;
    cin >> a >> b;
    int area, length;
    area = a * b;
    length = 2 * a + 2 * b;
    cout << area << " " << length << endl;

    return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define ll long long
#define tmp(x) std::cout<<"& "<<(x)<<" &\n"
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;

const int maxn=1e6+100;
const int mo=998244353;
 
 int a[120]; 
int main(){
//	freopen("in.txt","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,ans=0;
    cin>>n;
    rep(i,1,n){
    	cin>>a[i];
    	if((a[i]&1)&&(i&1))++ans;
    	
	}
    cout<<ans;
    
    
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  while(cin >> n,n){
    int k,s=0,f=0;
    for(int i=0;i<n;i++){
      cin >> k;
      if(k>=1)s++;
      if(k>1)f=1;
    }
    if(!f)cout << "NA" << endl;
    else cout << s+1 << endl;
  }
}


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

#define ll long long
#define mod 1000000007

ll solve(vector<int> &v, int n, int k){

    ll dp[n+2][k+2];

    for(int j=0;j<=k;j++){
        dp[1][j] = (j > v[1]) ? 0 : 1;
    }

    for(int i=2;i<=n;i++){
        for(int j=0;j<=k;j++){
            if(j==0)
                dp[i][j] = dp[i-1][j];
            else
                dp[i][j] = (mod + dp[i][j-1] + dp[i-1][j] - ((j-v[i]-1 >= 0) ? dp[i-1][j-v[i]-1] : 0))%mod;
        }
    }

    return dp[n][k];
}

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

    vector<int> v(n+1);
    for(int i=1;i<=n;i++){
        cin>>v[i];
    }

    cout<<solve(v,n,k);

    return 0;
}


Measured memory_bytes: 81692
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

    int[] d = new int[n];

    for (int i = 0; i < n; ++i)
      d[i] = sc.nextInt();

    Arrays.sort(d);

    int mid = n / 2;

    System.out.println(d[mid] - d[mid - 1]);

  }
}

Measured memory_bytes: 50324
/*
TASK: Kagami Mochi
LANG: C++
*/
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define EPS 1e-9
#define ALL(x) (x).begin(),(x).end()
#define mp(x,y) make_pair((x),(y))
#define pb(x) push_back((x))
#define FOR(i,st,ed) for(int (i)=(st);(i)<(ed);(i)++)
typedef pair<int,int> PII;
typedef vector<int> vi;
typedef vector<pair<int,int> > vii;
typedef long long LL;

int N,M,T;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//freopen("xxx.in","r",stdin);
	//freopen("xxx.out","w",stdout);
	int i,j,k;
	cin >> T;
	set<int> s;
	while(T--)
	{
	    cin >> k;
	    s.insert(k);
	}
	cout << s.size() << endl;
	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);
		// 整数の入力
		String S = sc.nextLine();
		int result = 9999;
		int temp;
		for(int i=0; i<S.length()-2;i++){
			temp = Math.abs(Integer.parseInt(S.substring(i, i+3))-753);
			if(temp < result){
				result = temp;
			}
		}
		System.out.println(result);
		sc.close();
	}

}

Measured memory_bytes: 21460
#include<iostream>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b;
    c=a+b;
    if((a%3==0)||(b%3==0)||(c%3==0))
    {
        cout<<"Possible";
    }
    else
    {
        cout<<"Impossible";
    }

    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl

const int MAX = 333;

ll N, A[MAX];

ll solve() {
    ll s = A[0] + A[1], x = 0;
    FOR (i, 2, N) x ^= A[i];
    if ((s-x)&1) return -1;
    ll d = (s-x)/2;
    if ((d&x) != 0) return -1;

    vi cands;
    cands.push_back(d);
    REP (b, 50) if (x&(1ll<<b)) {
        int l = cands.size();
        REP (i, l) {
            cands.push_back(cands[i] | (1ll<<b));
        }
    }
    ll ret = -1;
    FORE (c, cands) {
        if (c > 0 && c <= A[0]) CHMAX(ret, c);
    }
    if (ret != -1) ret = A[0] - ret;
    return ret;
}

int main() {
    cout << fixed << setprecision(15);
    cin >> N;
    REP (i, N) cin >> A[i];
    cout << solve() << endl;
}

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

typedef long long int lli;

const lli INF = (1LL<<55);
lli P[20], A[20][50], B[20][50];

lli calcCost(int c, lli dis){
    lli ans = 0;
    for(int i=0;i<P[c]-1;i++){
        if(B[c][i] <= dis && dis <= B[c][i+1]){
            return ans + A[c][i] * (dis - B[c][i]);
        }
        ans += A[c][i] * (B[c][i+1] - B[c][i]);
    }
    return ans + A[c][P[c]-1] * (dis - B[c][P[c]-1]);
}

int main(){
    int n,m,c,s,g;
    while(cin >> n >> m >> c >> s >> g && (n|m|c|s|g)){
        s--;
        g--;
        lli dis[20][100][100], cost[100][100];
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                cost[i][j] = (i == j) ? 0 : INF;
                for(int k=0;k<c;k++) dis[k][i][j] = (i == j) ? 0 : INF;
            }
        }

        for(int i=0;i<m;i++){
            int a,b,d;
            lli co;
            cin >> a >> b >> co >> d;
            a--;
            b--;
            d--;
            dis[d][a][b] = dis[d][b][a] = min(dis[d][a][b],co);
        }

        for(int i=0;i<c;i++) cin >> P[i];
        for(int i=0;i<c;i++){
            B[i][0] = 0;
            for(int j=1;j<P[i];j++) cin >> B[i][j];
            for(int j=0;j<P[i];j++) cin >> A[i][j];
        }

        for(int l=0;l<c;l++){
            for(int k=0;k<n;k++){
                for(int i=0;i<n;i++){
                    for(int j=0;j<n;j++){
                        if(dis[l][i][k] < INF && dis[l][k][j] < INF){
                            dis[l][i][j] = min(dis[l][i][j], dis[l][i][k]+dis[l][k][j]);
                            cost[i][j] = min(cost[i][j], calcCost(l, dis[l][i][j]));
                        }
                    }
                }
            }
        }

        for(int k=0;k<n;k++)
            for(int i=0;i<n;i++)
                for(int j=0;j<n;j++)
                    if(cost[i][k] < INF && cost[k][j] < INF)
                        cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j]);

        if(cost[s][g] >= INF) cout << -1 << endl;
        else cout << cost[s][g] << endl;
    }
}

Measured memory_bytes: 2528
#include <iostream>
#include <vector>
#include <cmath>
#include <string> 
#include <cstdint>
#include <cstring>
//https://qiita.com/ofutonfuton/items/92b1a6f4a7775f00b6ae
 
using namespace std;
typedef long long ll;
bool** connection;
ll N, M;
int result = 0;

void saiki(bool* searched, int current){
    searched[current] = true;
    bool completed = true;
    for(ll i = 0; i < N; i ++){
        if(searched[i] == false){
            completed = false;
            break;
        }
    }   
    if(completed){
        result ++;
        return;
    }

    for(ll i = 0; i < N; i ++){
        if(connection[current][i] == true && searched[i] == false){
            bool* newSearched = new bool[N];
            for(ll i = 0; i < N; i ++){
                newSearched[i] = searched[i];
            }
            saiki(newSearched, i);
        }
    }
}

int main()
{
    cin >> N >> M;
    ll* a = new ll[M];
    ll* b = new ll[M];
    connection = new bool*[N];
    for(ll i = 0; i < N; i ++){
        connection[i] = new bool[N];
        for(ll n = 0; n < N; n ++){
            connection[i][n] = false;
        }
    }
    for(ll i = 0; i < M; i ++){
        cin >> a[i] >> b[i];
        a[i] --;
        b[i] --;
        connection[a[i]][b[i]] = true;
        connection[b[i]][a[i]] = true;
    }

    bool* newSearched = new bool[N];
    for(ll i = 0; i < N; i ++){
        newSearched[i] = false;
    }
    saiki(newSearched, 0);


    cout << result;
    
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    ll n; cin >> n;
    vector<ll> num(n);
    REP(i, n) cin >> num[i];
    int ans = 0;
    REP(i, n){
        int tmp = num[i];
        while(true){
            if(num[i] % 2 == 0) ans++;
            else break;
            num[i] /= 2;
        }
    }
    cout << ans << endl;
}

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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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; }

//INT_MAX	2,147,483,647 = 2*1.0e9

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

    if(S == "Sunny") cout << "Cloudy" << endl;
    else if(S == "Cloudy") cout << "Rainy" << endl;
    else cout << "Sunny" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
main(){
  int n;
  while(cin>>n && n){
    int mini=10000,maxi=-10000;
    for(int i=0;i<n;i++){
      int now=0,t;
      for(int j=0;j<5;j++){
	cin>>t;
	now+=t;
      }
      maxi=max(maxi,now);
      mini=min(mini,now);
    }
    cout << maxi<<" " << mini << endl;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int N;
    cin >> N;
    vector<ll> a(3 * N);
    priority_queue<ll, vector<ll>, greater<ll>> pq;
    vector<pair<ll, int>> v;
    ll frontSum = 0;
    rep(i, 0, 3 * N)
    {
        cin >> a[i];

        if (i < N)
        {
            pq.push(a[i]);
            frontSum += a[i];
        }
        else
        {
            v.push_back(make_pair(a[i], i));
        }
    }

    assert(pq.size() == N);
    assert(v.size() == 2 * N);

    sort(v.begin(), v.end());
    
    ll backSum = 0;
    rep(i, 0, N)
    {
        backSum += v[i].first;
    }

    ll ans = frontSum - backSum;

    int backVecNextCursor = N;

    set<pair<ll, int>> backPendingRemoveSet;

    rep(i, N, 2 * N)
    {
        if (a[i] > pq.top())
        {
            frontSum -= pq.top();
            frontSum += a[i];
            pq.pop();
            pq.push(a[i]);
            assert(pq.size() == N);
        }

        const auto it = lower_bound(v.begin(), v.end(), make_pair(a[i], i));
        assert(it != v.end());

        // N-th smallest
        if (it - v.begin() < backVecNextCursor)
        {
            backSum -= a[i];
            while (backPendingRemoveSet.find(make_pair(v[backVecNextCursor].first, v[backVecNextCursor].second)) != backPendingRemoveSet.end())
            {
                ++backVecNextCursor;
            }
            backSum += v[backVecNextCursor].first;
            ++backVecNextCursor;
        }
        // Pending remove
        else
        {
            backPendingRemoveSet.insert(make_pair(a[i], i));
        }

        chmax(ans, frontSum - backSum);
    }

    cout << ans << endl;
}


Measured memory_bytes: 13164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;

map<int,int> prime;

void factor(int x){
    for (ll i = 2; i<=sqrt(x); i++) {
        if(x%i==0){
            x /= i;
            prime[i]++;
            i--;
        }
        if(x==1)break;
    }
    if(x != 1) prime[x]++;
}

int main(){
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) factor(i);
    ll ans = 1;
    for(auto p:prime){
        //cout << p.first << " " << p.second << endl;
        ans *= p.second+1;
        ans %= mod;
    }

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

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const ll mod = 1e9+7;

ll mod_pow(ll x, ll n){
    ll ret = 1;
    while(n){
        if(n&1) (ret*=x)%=mod;
        (x*=x)%=mod;
        n>>=1;
    }
    return ret;
}

ll mod_inv(ll x){
    return mod_pow(x,mod-2);
}

const int N = 2222222;
ll f[N];
ll invf[N];
ll C(int n, int m){
    ll ret = f[n];
    (ret*=invf[m])%=mod;
    (ret*=invf[n-m])%=mod;
    return ret;
}

int main(){
    f[0] = 1;
    for(int i=1; i<N; ++i) f[i] = (f[i-1]*i)%mod;
    rep(i,N) invf[i] = mod_inv(f[i]);

    int x,y;
    cin >>x >>y;

    ll ans = 0;
    rep(i,x+1){
        int rx = x-i, ry = y-2*i;
        if(2*ry == rx){
            (ans += C(i+ry,i)) %= mod;
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 34944
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,X,D,F;
  int a,r,tmp;
  cin >> N >> X;
  int W,P[N];
  cin >> W;
  P[0] = abs(W - X);

  for(int i=1;i<N;i++){
    cin >> W;
    P[i] = abs(W - X);
  }

  D=P[0];
  if(N!=1){
    for(int i=1;i<N;i++){
      if(P[i]<D){
        tmp=P[i];
        P[i]=D;
        D=tmp;
      }
      r = P[i] % D;
      while(r!=0){
        P[i] = D;
        D = r;
        r = P[i] % D;
      }
    }
  }
  cout << D << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
#define M 1000003
using namespace std;

typedef long long ll;

const int mod = M;

ll mod_pow(ll a,ll x){
  ll res=1;
  while(x){
    if(x%2) res=res*a%mod;
    a=a*a%mod;
    x/=2;
  }
  return res;
}

ll inv(ll x){
  return mod_pow( x, mod - 2 );
}

int X[M], invX[M];

void init(){
  
  int num = 1;
  
  for(int i=1;i<M;i++){
    num *= i;
    num %= mod;
    X[i] = num;
  }
  
  for(int i=0;i<M;i++) invX[i] = inv( X[i] );
  
}

int cal(int x, int d, int n){
  
  if( d == 0 ) return mod_pow( x, n );
  
  int R = ( x * inv( d ) + ( n - 1 ) ) % mod;
  int L = ( x * inv( d ) - 1 + mod ) % mod;
  
  int l = ( R - ( n - 1 ) - 1 );
  if( L + ( n - 1 ) >= mod ) return 0;
  
  return ( ( X[R] * invX[L] ) % mod * mod_pow( d, n ) ) % mod;
}

signed main(){
  
  init();
  
  int q;
  cin >> q;
  
  while( q-- ){
    
    int x, d, n;
    cin >> x >> d >> n;
    
    cout << cal( x, d, n ) << endl;
    
  }
  
  return 0;
}


Measured memory_bytes: 16512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
   int a[3];
   rep(i,3){
      cin>>a[i];
   }
   sort(a,a+3);
   cout<<abs(a[1]-a[0])+abs(a[2]-a[1])<<endl;
   
   
   }
   


Measured memory_bytes: 256
import math
a,b,h,m = map(int,input().split())

#degree
h_degree = h*30+m*0.5
m_degree = m*6
degree = min(360-abs(h_degree-m_degree),abs(h_degree-m_degree))

ans = (a**2+b**2-2*a*b*math.cos(math.radians(degree)))**0.5
print(ans)

Measured memory_bytes: 9508
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int n = sc.nextInt();
		int[] numberInfo =  new int[102];
		for(int i=0;i <n;i ++) {
			numberInfo[sc.nextInt()]++;
		}
		if(numberInfo[x] ==0) {
			System.out.println(x);
			return;
		}
		int right = 0;
		for(int i =x+1; i <=101;i++) {
			if(numberInfo[i] ==0) {
				right = i;
				break;
			}
		}
		int left = 0;
		for(int i =x-1; i >=0;i--) {
			if(numberInfo[i] ==0) {
				left = i;
				break;
			}
		}
		if((right -x) >= (x - left)) {
			System.out.println(left);
		}else {
			System.out.println(right);
		}

	}
}

Measured memory_bytes: 36008
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
const double PI = 3.141592653589793;

//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long A, B, H, M;
    cin >> A >> B >> H >> M;
    //A は１分 0.5
    //B は 1分 6
    //A Bの間の角度を出す
    double _A = H * 30 + M * 0.5;
    double _B = M * 6.0;
    double c = min(_A - _B, 360 - (_A - _B));
    // A と B に対応する辺の角度の和
    cout << fixed << setprecision(10) << sqrt(A*A + B*B - 2* A*B*cos(c*PI/180.0)) << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 4120
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int M,D; cin >> M >> D;
    int out=0;
    for(int i=1;i<=M;i++){
        for(int j=1;j<=D;j++){
            if(j/10>=2 && j%10>=2 && (j/10)*(j%10)==i) out++;
        }
    }
    cout << out << endl;
    return 0;
}


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

string query(int n) {
	cout << n << '\n' << flush;
	string s; cin >> s;
	if (s == "Vacant") exit(0);
	return s;
}

int main() {
	int n; cin >> n;
	int l = 0;
	int r = n - 1;
	string L = query(l);
	string R = query(r);
	while (true) {
		int m = (l + r) / 2;
		R = query(m);
		if ((L == R) ^ (m % 2)) l = m;
		else r = m;
	}
	return 0;
}

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

using namespace std;

int main()
{
//    freopen("TEST.INP", "r", stdin);
    string s, t;
    cin >> s >> t;
    int ans = 0;
    for (int i = 0; i < s.size(); ++i)
        ans += s[i] != t[i];
    cout << ans;
    return 0;
}


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

int main(){
  int n; cin>>n;
  vector<ll> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  
  ll sum=0;
  int m=(n+1)/2;
  if(n%2==0){
    for(int i=0;i<m-1;i++){
      sum-=2*a[i];
    }sum-=a[m-1];
    for(int i=m+1;i<n;i++){
      sum+=2*a[i];
    }
    sum+=a[m];
    cout<<sum<<endl;
    return 0;
  }ll ma;
  for(int i=m;i<n;i++)sum+=2*a[i];
  sum-=a[m-1]+a[m-2];
  for(int i=0;i<m-2;i++)sum-=2*a[i];
  ma=sum;sum=0;
  sum+=a[m-1]+a[m];
  for(int i=m+1;i<n;i++)sum+=2*a[i];
  for(int i=0;i<m-1;i++)sum-=2*a[i];
  cout<<max(ma,sum)<<endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define INF 1000000007
using namespace std;

int main(void) {
	int h,w;cin >> h >> w;
	char grid[55][55];for(int i=0; i<55; i++)for(int j=0; j<55; j++)grid[i][j]='.';
	for(int i=1; i<=h; i++){
		for(int j=1; j<=w; j++){
			cin >> grid[i][j];
		}
	}
	for(int i=1; i<=h; i++){
		for(int j=1; j<=w; j++){
			if(grid[i][j]=='#'){
				if(grid[i-1][j]!='#' && grid[i+1][j]!='#' && grid[i][j-1]!='#' && grid[i][j+1]!='#'){
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
int_n = int(input())

li_words = list()
for i in range(int_n):
    li_words.append(input())

ends = "".join([e[-1] for e in li_words[:-1]])
starts = "".join([s[0] for s in li_words[1:]])

if starts == ends and len(set(li_words)) == int_n:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
 
int main() {
	ios::sync_with_stdio(false);
	ll n, a, b, h[100005], l = 0, r = 1000000000;
	cin >> n >> a >> b;
	for ( int i = 0 ; i < n ; i++ ) cin >> h[i];
	while (l + 1 < r) {
		ll m = (l + r) / 2, c[100005], d = 0;
		for ( int i = 0 ; i < n ; i++ ) c[i] = max( (ll)0, h[i] - m * b);
		for ( int i = 0 ; i < n ; i++ ) if (c[i]) d += (c[i] - 1) / (a - b) + 1;
		if (d <= m) r = m;
		else l = m;
	}
	cout << r;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define int long long int
#define ld long double
#define getFaster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define rev(i,n,init) for(int i=n;i>=init;i--)
#define MAXN 200005
#define MOD2 998244353
#define MOD1 1e9+7
#define f first
#define s second
#define endl '\n'
#define pii pair<int,int>
#define piii pair<pii,int>
#define precise(i) cout<<fixed<<setprecision(i)
#define codejam cout<<"Case #"<<ii+1<<": ";
#define impossible cout<<"IMPOSSIBLE"<<endl;
#define error(s) throw runtime_error(s)
using namespace std;
const long double PI = atan(1.0)*4;
const int64_t INF=8e18;
const int32_t LOG=21;
const int MOD=MOD2;

int a[55],b[55],c[55],d[55];
int n,m,q;
int ans=0;

void solve(vector<int>& v)
{
      int sum=0;
      rep(i,0,q)
      {
           if(v[b[i]]-v[a[i]]==c[i])
           sum+=d[i];
      }
      ans=max(ans,sum);  
}


void generate(vector<int> v)
{
      int siz=v.size();
      int cur=1;
      if(siz!=0)cur=v.back();
      if(siz==n)
      {
          solve(v);
          return;
      }
      rep(i,cur,m+1)
      {
          vector<int> v1=v;
          v1.push_back(i);
          generate(v1);
      }
}

int32_t main()
{ 
      getFaster;
      int tests=1;
      //cin>>tests;
      rep(ii,0,tests)
      {
           cin>>n>>m>>q;
           rep(i,0,q)
           {
               cin>>a[i]>>b[i]>>c[i]>>d[i]; 
               a[i]--;b[i]--;
           }
           vector<int> v;
           generate(v);
           cout<<ans<<endl;
      }

      return 0;                         
}

/*
 TIPS:
 1.) Check for corner cases (like 0 is exception case)
 2.) Check for global memory sizes,memory refreshments and its complexity 
 3.) Check for sorting criteria (if used 1-based indexing)
 4.) Check for numbers overflow (while multiplying and doing MOD)
 5.) Check for typecasting issues like int to float( while dividing numbers)
*/

Measured memory_bytes: 3664
n, k, q = map(int, input().split())
l = ["No"]*n
l1 = [0]*n
s = 0
lol=0
for i in range(q):
    ip=int(input())
    s+=1
    l1[ip-1]+=1
for i in range(n):
    if l1[i]+k>s:
        l[i]="Yes"
for i in l:
    print(i)

Measured memory_bytes: 51544
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<string>
#include<vector>
#include<iomanip>
#define rep(i,n) for(int i=0;i<((int)n);i++)
#define Rep(i,n0,n) for(int i=n0;i<((int)n);i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<((int)n);j++)
#define W(x) cout<<x<<endl;
#define Debug(x) cout<<"#DEBUG "<<x<<endl;
#define INF (1<<29)
#define INF2 (long long)8*(long long)INF*(long long)INF
typedef long long ll;

using namespace std;


int min(int x,int y){if(y<x)return y;else return x;}
int max(int x,int y){if(y>x)return y;else return x;}
int fact(int x){int i=1;rep(j,x){i*=(j+1);} return i;}
long long fact(long long x){long long i=1;rep(j,x){i*=(j+1);} return i;}
int n;
long long max1,max2;
int main()
{
    cin>>n;
    int a[n];
    rep(i,n)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    int flag=-1,cnt=0;
    for(int i=n-1;i>=0;i--)
    {
        if(a[i]==flag)
        {
            cnt++;
        }
        else
        {
            if(cnt>3)
            {
                if(flag>max1)
                {
                    max1=flag;
                    max2=flag;
                }
                else if(flag>max2)
                {
                    max2=flag;
                }
            }
            else if(cnt>1)
            {
                if(flag>max1)
                {
                    max2=max1;
                    max1=flag;
                }
                else if(flag>max2)
                {
                    max2=flag;
                }
            }
            flag=a[i];
            cnt=1;
        }
    }
    if(cnt>3)
    {
        if(flag>max1)
        {
            max1=flag;
            max2=flag;
        }
        else if(flag>max2)
        {
            max2=flag;
        }
    }
    else if(cnt>1)
    {
        if(flag>max1)
        {
            max2=max1;
            max1=flag;
        }
        else if(flag>max2)
        {
            max2=flag;
        }
    }
    W(max1*max2)
    return 0;
}

Measured memory_bytes: 640
import heapq
from bisect import bisect_left, bisect_right

n = int(input())
a = int(input())
q = [a*(-1)]
# ans = 1

for _ in range(n-1):
    a = int(input())
    # bより大きい最小要素のindex/value
    ind = bisect_right(q, a*(-1))
    ind = ind if 0 <= ind < len(q) else None
    if ind is None:
        q.append(a*(-1))
    else:
        q[ind] = a*(-1)

print(len(q))

Measured memory_bytes: 76144
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
	public static void main(String [] args) {
		Scanner stdIn = new Scanner(System.in);
		double S, cir;
		double r = stdIn.nextDouble();
		
		while(0 > r || r > 10000f) {
			r = stdIn.nextDouble();
		}
		
		cir = Math.PI * 2 * r;
		S = Math.PI * r * r;
		
		System.out.println(BigDecimal.valueOf(S).toPlainString() + " " + BigDecimal.valueOf(cir).toPlainString());
		
		
	}
}



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

long long a,b,c,d,i,gc,gd,cd,gcd;

int main(){
	cin>>a>>b>>c>>d;
	gc=b/c-(a-1)/c;
	gd=b/d-(a-1)/d;
	cd=(c*d)/__gcd(c,d);
	gcd=b/cd-(a-1)/cd;
	i=gc+gd-gcd;
	cout<<(b-a+1)-i;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define F first
#define S second
#define pb emplace_back
#define mt make_tuple
#define mp make_pair
#define gcd __gcd
#define PI 3.141592653589
// Input
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define llin(a) cin >> a
#define inl(a) scanf("%lld",&a)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
// Output
#define pr(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d\n",a,b)
#define pr3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out(a) printf("%d\n",a)
#define outl(a) printf("%lld\n",a)
#define llpr(a) cout << a << " "
#define llout(a) cout << a << "\n"
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
// Iterator
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
// Debug
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define what(x) cerr << #x << " : " << x << "\n"
#define ck printf("continue\n")
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
	cerr << *it << " = " << a << "\n";
	err(++it, args...);
}
// Data Type
#define ll long long int
#define ii pair<int,int>
#define pli pair<ll,int>
#define triple tuple<int,int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define M 1000000007
#define N 1000005  //check the limits, man
const ll INF = 1e18;
int main()
{
    ll x;
    llin(x);
    ll a=(x/11);
    x%=11;
    a*=2;
    if(x>0 && x<=6)
        a++;
    else if(x>6)
        a+=2;
    llout(a);
}






Measured memory_bytes: 256
max_V = 100010
N,W = map(int, input().split())
lis = [[float('inf')] *(max_V) for _ in range(N+1)]
lis[0][0] = 0 #初期条件の入力が必要　Edu_Dでは初期化とともに初期条件入力済んでいたがこれは違う
item = []
for i in range(N):
    w,v = map(int, input().split())
    item.append((w,v))
for i in range(1,N+1):
    for j in range(max_V):
        lis[i][j] = min(lis[i-1][j], (lis[i-1][j-item[i-1][1]] + item[i-1][0]))
ans = 0
for i in range(N+1):
    for j in range(max_V):
        if lis[i][j] <= W:
            ans = max(j, ans)
print(ans)


Measured memory_bytes: 312432
#include<stdio.h>
double max(double a, double b)
{
    if (a > b)
        return a;
    else
        return b;
}
double min(double a, double b)
{
    if (a < b)
        return a;
    else
        return b;
}
double abs(double a)
{
    if (a >= 0)
        return a;
    else
        return -a;
}
int main()
{
    long long int h, w;
    scanf("%lld %lld", &h, &w);
    if (h % 3 == 0 || w % 3 == 0)
    {
        printf("0\n");
        return 0;
    }
    long long int i;
    unsigned long long int ans = 2000000000;
    i = h / 3;
    ans = min(ans, min(w*(h + 1 - i) / 2, (h - i)*((w + 1) / 2)) - (i*w));
    i++;
    ans = min(ans, (w*i) - max(w*((h - i) / 2), (h - i)*(w / 2)));
    i = w / 3;
    ans = min(ans, min(h*(w + 1 - i) / 2, (w - i)*((h + 1) / 2)) - (i*h));
    i++;
    ans = min(ans, (h*i) - max(h*((w - i) / 2), (w - i)*(h / 2)));
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 128
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MODA 1000000007 

//つねに10億7などの剰余をとる構造体
//参考: https://www.youtube.com/watch?v=L8grWxBlIZ4&t=9858
//参考: https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a#4-%E7%B4%AF%E4%B9%97-an
int mod  = MODA;
struct modint {
	ll x;
	modint (ll x):x(x%mod){}
	modint& operator+=(const modint a){
		(x += a.x ) %= mod;
		return *this;
	}
	modint& operator-=(const modint a){
		(x -= a.x ) %= mod;
		if (x < 0) x += mod;
		return *this;
	}
	modint& operator*=(const modint a){
		(x *= a.x ) %= mod;
		return *this;
	}
	modint& operator/=(modint a){
		ll exp = mod - 2;
		while(exp > 0){
			if(exp & 1) *this *= a.x;
			a *= a.x;
			exp >>= 1;
		}
		return *this;
	}
	modint operator+(const modint a) const{
		modint res(*this);
		return res+=a;
	}
	modint operator-(const modint a) const{
		modint res(*this);
		return res-=a;
	}
	modint operator*(const modint a) const{
		modint res(*this);
		return res*=a;
	}
	modint operator/(const modint a) const{
		modint res(*this);
		return res/=a;
	}
};
modint modpow(modint x, ll n){
	modint res=1;
	while(n > 0){
		if(n & 1) res = res * x.x;
		x = x * x;
		n >>= 1;
	}
	return res;
}

int main() {
    modint ans = 0;
    modint tmp = 0;
    modint now = 0;
    int n, k;
    cin >> n >> k;
    ll a[200001];
    for(int i = k; i >= 1; i--){
        tmp = (ll) k/i;
        now = modpow(tmp, (ll)n);
        for(int j = 2*i; j <= k; j+= i){
            now -= a[j];
        }
        a[i] = now.x;
        //cout << i << " " << a[i] << endl;
    }
    REP1(i, k){
        ans += i * a[i];
    }
    cout << ans.x << endl;
}

Measured memory_bytes: 4356
#include <algorithm>
#include <cassert>
#include <iostream>
#include <stack>
#include <string>
#include <utility>
#include <numeric>
#include <vector>

using namespace std;

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

    stack<size_t> st;
    stack<pair<int, int>> sp;
    for (size_t i = 0; i < s.size(); ++i) {
        auto&& c = s[i];
        switch (c) {
        case '\\':
            st.push(i);
            break;
        case '/':
            if (!st.empty()) {
                auto d = st.top();
                st.pop();
                auto v = i - d;
                while (!sp.empty() && sp.top().first > d) {
                    v += sp.top().second;
                    sp.pop();
                }
                sp.push(make_pair(d, v));
            }
            break;
        case '_':
            break;
        default:
            assert(false);
        }
    }
    vector<int> v;
    while (!sp.empty()) {
        v.push_back(sp.top().second);
        sp.pop();
    }
    reverse(begin(v), end(v));
    cout << accumulate(begin(v), end(v), 0) << endl;
    cout << v.size();
    for (auto&& i : v) {
        cout << ' ' << i;
    }
    cout << endl;
}

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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

using ll = long long;
using namespace std;

int main() {
    ll n, m;
    unordered_map<ll, ll> mp;
    
    cin >> n >> m;

    ll p;
    ll ans[100010] = {0};
    string s;
    REP(i, m){
        cin >> p >> s;
      	if (s == "AC"){
            ans[p]++;
        } else if (ans[p] == 0){
            mp[p]++;
        }
    }

    ll penalty = 0;
    ll ac = 0;
    REP(i, n){
      	if(ans[i+1] > 0){
            ac++;
            penalty += mp[i+1];
        }
    }

    cout << ac << " " << penalty << endl;

    return 0;
}

Measured memory_bytes: 5156
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
 
using namespace std;
using ll = long long;
using pii = pair<int, int>;
 
const int oo = 1e9 + 7;
const int mod = 1e9 + 7, maxn = 100100;
const long double PI = acos(-1);
 
int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    set<int>st;
    vector<int> v(n);

    for (auto& x: v) cin >> x, st.insert(x);

    if (st.size() == n) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 998244353;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint &operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) {
    return is >> a.x;
}
ostream &operator<<(ostream &os, const mint &a) {
    return os << a.x;
}

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i)
            fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i)
            ifact[i - 1] = ifact[i] * i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
} c(200005);

int main(int argc, char const *argv[]) {
    int n, m, k;
    cin >> n >> m >> k;

    mint ans = 0;
    mint col = m;
    for (int x = n - 1; x >= 0; --x) {
        mint now = col;
        now *= c(n - 1, x);
        if (x <= k) ans += now;
        col *= m - 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6240
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int N;
  cin >> N;
  unordered_map<string, int> uo{};
  REP(i, N) {
    string s;
    cin >> s;
    uo[s]++;
  }
  cout << "AC x " << uo["AC"] << endl;
  cout << "WA x " << uo["WA"] << endl;
  cout << "TLE x " << uo["TLE"] << endl;
  cout << "RE x " << uo["RE"] << endl;
}

Measured memory_bytes: 3636