akhauriyash/Code-Regression huggingface dataset:
# import itertools
# import math
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np
# import heapq
# from collections import deque
# import sympy

N = int(input())
# S = input()
# n, *a = map(int, open(0))
# N, M = map(int, input().split())
# A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

# def factorization(n):
#     arr = []
#     temp = n
#     for i in range(2, int(-(-n**0.5//1))+1):
#         if temp%i==0:
#             cnt=0
#             while temp%i==0:
#                 cnt+=1
#                 temp //= i
#             arr.append([i, cnt])
#     if temp!=1:
#         arr.append([temp, 1])
#     if arr==[]:
#         arr.append([n, 1])
#     return arr

ans = 0
for i in range(1, N + 1):
    num = N // i
    ans += i * (num * (num + 1)) // 2
print(ans)


Measured memory_bytes: 9032
import java.util.*;

class C {
    public static void main(String... args) {
        final Scanner sc = new Scanner(System.in);
        final char[] A = sc.next().toCharArray();
        final int N = A.length;
        final int[] next = new int[N];
        final int[] min = new int[N + 1];
        final int[] jump = new int[26];
        final char[] cs = new char[N];
        Arrays.fill(jump, N);
        for (int i = N - 1; i >= 0; i--) {
            int m = Integer.MAX_VALUE;
            int n = -1;
            for (int j = 0; j < 26; j++)
                if (min[jump[j]] + 1 < m) {
                    n = j;
                    m = min[jump[j]] + 1;
                }
            next[i] = jump[n];
            min[i] = m;
            jump[A[i] -'a'] = i;
            cs[i] = (char)(n + 'a');
        }
        int m = Integer.MAX_VALUE;
        int n = -1;
        for (int j = 0; j < 26; j++)
            if (min[jump[j]] + 1 < m) {
                n = j;
                m = min[jump[j]] + 1;
            }
//        System.err.println(m);
        final StringBuilder sb = new StringBuilder().appendCodePoint(n + 'a');
        for(int i = jump[n]; i < N; i = next[i])
            sb.append(cs[i]);
        System.out.println(sb);
    }
}
public class Main {
    public static void main(String... args) {
        C.main(args);
    }
}

Measured memory_bytes: 30256
/*
 * ID: ITP1_6_D
 * Problem: Matrix vector multiplication
 */

#include <stdio.h>

int main(void)
{
    int n, m;
    int a[100 + 1][100 + 1], b[100 + 1];

    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            scanf("%d", &a[i][j]);

    for (int i = 1; i <= m; i++)
        scanf("%d", &b[i]);


    for (int i = 1; i <= n; i++) {
        int sum = 0;
        for (int j = 1; j <= m; j++)
            sum += a[i][j] * b[j];
        printf("%d\n", sum);
    }

    return 0;
}



Measured memory_bytes: 2108
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll N, K;
  cin>>N>>K;
  vector<ll> A(N), F(N);
  for(int i=0;i<N;++i){
    cin>>A[i];
  }
  for(int i=0;i<N;++i){
    cin>>F[i];
  }
  sort(A.begin(), A.end());
  sort(F.begin(), F.end(), greater<ll>());
  ll l=0, r=1e13, m;
  ll tmp;
  while(l<r){
    m = (l+r)/2;
    tmp = 0;
    for(int i=0;i<N;++i){
      if(A[i]-m/F[i]>0) tmp += A[i]-m/F[i];
    }
    if(tmp<=K) r = m;
    else l = m+1;
  }
  cout<<l<<endl;
}



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

using namespace std;

typedef long long ll;

ll D[5050][5050];
ll n, m, k, ans;

int main()
{
	ll i, j, l, t;
	
	scanf("%lld%lld", &n, &m);
	
	k = n >> 1;
	
	if(n & 1){
		for(i = 0; (t = i * (k + 1)) < n; i ++){
			D[0][t] = 1;
		}
	}
	else D[0][0] = 1;
	
	for(i = 1; i <= k; i ++){
		for(j = 0; j < n; j ++){
			for(l = 0; (t = j + l * (k - i + 1)) < n; l ++){
				D[i][t] = (D[i][t] + D[i - 1][j] * (l + 1)) % m;
			}
		}
	}
	
	for(i = 0; i < n; i ++){
		ans = (ans + D[k][i]) % m;
	}
	
	printf("%lld\n", ans);
	
	return 0;
}

Measured memory_bytes: 100608
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n;i++)
using namespace std;
#define int long long
signed main(){
    int a,b; cin>>a>>b;
    if(abs(a-b)>1)return puts("0")*0;
    int MOD=1;
    rep(i,9)MOD*=10;
    MOD+=7;
    int hoge=1;
    for(int i=a; i>=1;i--){hoge*=i; hoge%=MOD;}
    for(int i=b; i>=1;i--){hoge*=i; hoge%=MOD;}
    if(a==b){hoge*=2; hoge%=MOD;}
    cout<<hoge<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <unistd.h>
#include <stdio.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define all(a) (a).begin(),(a).end()
#define vecin(a) rep(i,a.size())cin >> a[i]
#define vecout(a) rep(i,a.size()){cout << a[i];cout << (i == a.size() - 1 ? "\n":" ");}
#define rep(i,x) for(ll i = 0;i<x;i++)
#define REP(i,x) for(ll i = 1;i<=x;i++)
#define mp make_pair
#define debug(x) cerr << #x << ": " << x << "\n"
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const dou pi = 3.14159265358;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T, class U> inline bool chmin(T& a, const U& b){ if(a > b){ a = b; return 1; } return 0; }
template<class T, class U> inline bool chmax(T& a, const U& b){ if(a < b){ a = b; return 1; } return 0; }
template<class T, class U> inline bool change(T& a,U& b){if(a > b){swap(a,b);return 1;}return 0;}
//0の場合のアレンジに注意
template<class T>
T gcd(T a,T b){
    if(a == 0)return b;
    else if(b == 0)return a;
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
template<class T>
T lcm(T a,T b){
    return a / gcd(a,b) * b;
}

//素数判定O(sqrt(N))
template<class T>
inline bool isp(T n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const ll cmax = 1000000;
vector<ll> fac(cmax),finv(cmax),inv(cmax);

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < cmax; 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;
    }
}

// 二項係数計算
ll nCk(ll n, ll k){
    if(fac[0] == 0)COMinit();
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logm)
ll modpow(ll n,ll m,ll MOD){
    if(m == 0)return 1;
    if(m < 0)return -1;
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}
ll mypow(ll n,ll m){
    if(m == 0)return 1;
    if(m < 0)return -1;
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n);
        m >>= 1;
        n *= n;
    }
    return res;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll A,B,T;
    cin >> A >> B >> T;
    cout << T / A * B << "\n";
}

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


int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  string S; cin >> S;

  ll cnt = 0;
  for (int i = 0; i < N; i++) {
    if (S.substr(i, 3) == string("ABC")) cnt++;
  }
  cout << cnt << endl;


  return 0;
}



Measured memory_bytes: 384
#include<iostream>

using namespace std;

int main(){
  int a,b,c,d;
  cin >> a >> b>> c >> d;
  int e,f,g,h;
  e = c + (b-d);
  f = d - (a-c);
  g = e + (a-c);
  h = f + (b-d);
  cout << e << " " <<  f << " " <<  g << " " << h;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include <algorithm>

int main(){
	int n;
  	std::cin>>n;
  
  int ans =0;
  
  
  std::vector<int> v;
  	
  	//std::cout<<a<<b<<c;
  if(n>2){
    for(int i=0; i<n; i++){
      int b;
      std::cin>>b;
      
      v.push_back(b);

    }
  
  
  	for(int i=0; i<n; i++){
      
      for(int i1=i+1; i1<n; i1++){
        
        for(int i2=i1+1; i2<n; i2++){
          
          int sum = v[i]+v[i1]+v[i2];
          int ma = std::max({v[i], v[i1], v[i2]});
          //std::cout<<ma;
          
          if(sum - ma > ma && v[i] != v[i1] && v[i] != v[i2] && v[i1] != v[i2] ){
              ans +=1;
          }
          
        }
        
      }
      
    }
  }
  
  
  	std::cout<<ans;
  
  
	return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <string>
#include <string.h>
using namespace std;
#define pb push_back
#define mp make_pair
bool used[305][305];
int n,w[305],dp[305];
int main(){
	while(1){
		cin >> n; if(n==0) return 0;
		for(int i=1;i<=n;i++) cin>>w[i];
		memset(used,0,sizeof(used));
		for(int i=1;i<=n-1;i++){
			if(abs(w[i]-w[i+1]) <= 1) used[i][i+1] = 1;
		}
		for(int a=4;a<=n;a+=2){
			for(int i=1;i<=n+1-a;i++){
				//used[i][i+a-1]
				for(int k=2;k<a;k+=2){
					if(used[i][i+k-1] && used[i+k][i+a-1]) used[i][i+a-1] = 1;
				}
				if(abs(w[i]-w[i+a-1]) <= 1 && used[i+1][i+a-2]) used[i][i+a-1] = 1;
			}
		}
		//cout << used[1][n] << endl;
		fill(dp,dp+305,-1000000);
		dp[0] = 0;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=i;j++){
				if(dp[j-1] < 0) continue;
				int x = 0;
				if(used[j][i]) x = i-j+1;
				dp[i] = max(dp[i],dp[j-1]+x);
			}
		}
		cout << *max_element(dp+1,dp+n+1) <<endl;
	}
}

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

ans = 0
for x in range(1, int(M ** 0.5) + 1):
    if M % x != 0:
        continue
    else:
        x1, x2 = x, M // x
        if M // x1 >= N:
            ans = max(ans, x1)
        if M // x2 >= N:
            ans = max(ans, x2)

print(ans)


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

int main()
{
	int a1, a2, a3;
	cin >> a1 >> a2 >> a3;

	if (22 <= a1 + a2 + a3) {
		cout << "bust" << endl;
	}
	else {
		cout << "win" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>

using namespace std;

#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v) {std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

#define EPS 1e-8
#define EQ(a, b) (abs((a)-(b)) < EPS)

inline int signum(double x) { return (abs(x) < EPS ? 0 : x > 0 ? 1 : -1); }

typedef complex<double> P;

double cross(P a, P b) {
    return a.real() * b.imag() - a.imag() * b.real();
}

double dot(P a, P b) {
    return a.real() * b.real() + a.imag() * b.imag();
}

int ccw(P p0, P p1, P p2) {
    p1 -= p0;
    p2 -= p0;
    int sign = signum(cross(p1, p2));
    if (sign != 0) return sign;
    if (dot(p1, p2) < -EPS) return 2; //left
    if (abs(p1) < abs(p2)) return -2; //right
    return 0; //mid
}

bool is_parallel(P p0, P p1, P p2, P p3) {
    P x = p1 - p0;
    P y = p3 - p2;
    return EQ(cross(x, y), 0.0);
}

bool is_orthogonal(P p0, P p1, P p2, P p3) {
    P x = p1 - p0;
    P y = p3 - p2;
    return EQ(dot(x, y), 0.0);
}

int main() {
    double xp0, yp0, xp1, yp1;
    cin >> xp0 >> yp0 >> xp1 >> yp1;

    P p0(xp0, yp0);
    P p1(xp1, yp1);

    int Q;
    cin >> Q;

    while (Q--) {

        double xp, yp;
        cin >> xp >> yp;

        P p2(xp, yp);

        int ans = ccw(p0, p1, p2);

        string s = "";
        if (ans == 1) s = "COUNTER_CLOCKWISE";
        if (ans == -1) s = "CLOCKWISE";
        if (ans == 2) s = "ONLINE_BACK";
        if (ans == -2) s = "ONLINE_FRONT";
        if (ans == 0) s = "ON_SEGMENT";

        cout << s << endl;
    }


    return 0;
}














































Measured memory_bytes: 3344
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1ll<<59

ll gcd(ll a,ll b){
  if(a<b) swap(a,b);
  if(a%b==0) return b;
  else return gcd(b,a%b);

}

int main(){
  ll i,j;
  ll n,k;
  cin>>n>>k;
  ll t,d;
  vector<P> v;
  for(i=0;i<n;i++){
    cin>>t>>d;
    v.pb(P(d,t));
  }

  sort(v.begin(),v.end(),greater<P>());

  ll ans=0;
  ll syu=0;

  vector<ll> used(n+1,0);
  for(i=0;i<k;i++){
    P s=v[i];
    if(used[s.se]==0){
      syu++;
      ans+=syu*2-1;
    }
    used[s.se]++;
    ans+=s.fi;
  }
  ll po=k-1;

  vector<ll> v2;
  for(i=k;i<n;i++){
    P s=v[i];
    if(used[s.se]==0){
      v2.pb(s.fi);
      used[s.se]++;
    } 

  }
  sort(v2.begin(),v2.end(),greater<ll>());
  
  ll po2=0; 
  ll temp=ans;

  while(po>=0&&po2<v2.size()){
    if(used[v[po].se]>=2){
      syu++;
      temp+=2*syu-1+v2[po2]-v[po].fi;
      ans=max(ans,temp);
      po2++;
    }
    po--;
  }
  cout<<ans<<endl;


  return 0;
}


Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n,m,c,i,sum=0,j,count=0;
    cin>>n>>m>>c;
    ll arr[n+5][m+5]={},b[m+5]={};
    for(i=0;i<m;i++)
        cin>>b[i];
    for(i=0;i<n;i++){
        sum=0;
        for(j=0;j<m;j++){
            cin>>arr[i][j];
            sum+=(arr[i][j]*b[j]);
        }
        if((sum+c)>0)
            count+=1;
    }
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
 
int main(void){
 int N, M;
 int i, j, k, l;
 int flag;
 char **A, **B;
 scanf("%d%d\n", &N, &M);
 A = (char **)malloc(sizeof(char *)*N);
 for(i = 0; i < N; i++) A[i] = (char *)malloc(N);
 B = (char **)malloc(sizeof(char *)*M);
 for(i = 0; i < M; i++) B[i] = (char *)malloc(M);
 for(i = 0; i < N; i++){
  for(j = 0; j < N; j++) A[i][j] = getchar();
  getchar();
 }
 for(i = 0; i < M; i++){
  for(j = 0; j < M; j++) B[i][j] = getchar();
  getchar();
 }
 
 for(i = 0; i <= N - M; i++){
  for(j = 0; j <= N - M; j++){
   flag = 1;
   for(k = 0; k < M; k++){
    for(l = 0; l < M; l++){
     if(A[k + i][l + j] != B[k][l]) flag = 0;
    }
   }
   if(flag){
    printf("Yes\n");
    return 0;
   }
  }
 }
 printf("No\n");
 return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
	int k,s;
	cin >> k >> s;

	int ans=0;
	int start = 0;
	for (int x=start;x<=k;x++) {
		if (x == s) {
			ans++;
			continue;
		}
		for (int y=start;y<=k;y++){
			if (x+y==s) {ans++; continue;}
			if (x+y>s) break;
			if (x+y+k>=s) {ans++; continue;}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

n=int(input())  #->n=5
a=list(map(int,input().split()))  #->nl=[1,2,-,n]
mod=int(1e9+7)

# Accumulate
pre=[0]*n
pre[0]=a[0]
for i in range(1,n):  pre[i]=pre[i-1]+a[i]
ans=0
for i in range(1,n):  ans=(ans+(a[i-1]*(pre[n-1]-pre[i-1]))%mod)%mod
print(ans)



Measured memory_bytes: 31464
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 55;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
char s[MAXN][MAXN];
ll dp[MAXN][MAXN][MAXN];
ll getans(int l, int r, int m) {
	if (dp[l][r][m] != -1) return dp[l][r][m];
	if (l == r) return dp[l][r][m] = 1;
	if (l == m || r == m) return dp[l][r][m] = 0;
	ll &res = dp[l][r][m]; res = 0;
	for (int i = l; i <= m - 1; i++)
	for (int j = m + 1; j <= r; j++) {
		if (s[i][j] == '0') continue;
		for (int s = i; s <= m - 1; s++)
		for (int t = m + 1; t <= j; t++)
			res += getans(l, s, i) * getans(s + 1, t - 1, m) * getans(t, r, j);
	}
	return res;
}
int main() {
	int n; read(n);
	for (int i = 1; i <= n * 2; i++)
		scanf("\n%s", s[i] + 1);
	memset(dp, -1, sizeof(dp));
	ll ans = 0;
	for (int i = 2; i <= n * 2; i++)
		if (s[1][i] == '1') ans += getans(2, n * 2, i);
	writeln(ans);
	return 0;
}

Measured memory_bytes: 1536
#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> P;

int main(void){
  double l; cin >> l;
  double length = l /3;
  cout << fixed << setprecision(20);
  cout << length*length*length << endl;
  return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> es[n + 1];
    unordered_map<int, unordered_map<int, int> > cs;
    for (int i = 1; i < n; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        cs[a][b] = cs[b][a] = c;
        es[a].push_back(b);
        es[b].push_back(a);
    }

    int q, k;
    cin >> q >> k;

    long d[n + 1];
    fill(d + 1, d + n + 1, -1);
    d[k] = 0;
    queue<int> que;
    que.push(k);
    while (!que.empty()) {
        int t = que.front();
        que.pop();
        for (int x: es[t]) {
            if (d[x] < 0) {
                d[x] = d[t] + cs[t][x];
                que.push(x);
            }
        }
    }

    for (int i = 0; i < q; i++) {
        int x, y;
        cin >> x >> y;
        cout << d[x] + d[y] << endl;
    }
    return 0;
}


Measured memory_bytes: 27812
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

typedef long long ll;
typedef double db;
int read() {
    char ch;
    for(ch=getchar();ch<'0'||ch>'9';ch=getchar());
    int x=ch-'0';
    for(ch=getchar();ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
    return x;
}

const int N=3*1e5+5;
const ll inf=1e16;

int n,m,x,y,a[N],stack[N],top;
ll f[N],g[N],h[N],ans[N],t[N],c[N],tmp[N],sum[N];

db P(int y,int x) {
    return (t[y]+(ll)y*(y-1)/2+sum[y]-t[x]-(ll)x*(x-1)/2-sum[x])*1.0/(y-x);
}

void Dp() {
    fo(i,1,n) sum[i]=sum[i-1]+a[i];stack[top=1]=0;
    fo(i,1,n) {
        while (top>1&&P(stack[top],stack[top-1])<=i) top--;
        int now=stack[top];
        t[i]=max(t[i-1],t[now]+(ll)(i-now)*(i-now+1)/2+sum[now]-sum[i]);
        while (top>1&&P(stack[top],stack[top-1])<P(i,stack[top])) top--;
        stack[++top]=i;
    }
}

void solve(int l,int r) {
    if (l==r) {
        h[l]=max(h[l],g[r+1]+f[l-1]+1-a[l]);
        return;
    }
    int mid=l+r>>1;
    stack[top=1]=l-1;
    fo(i,l,mid-1) {
        while (top>1&&P(stack[top],stack[top-1])<P(i,stack[top])) top--;
        stack[++top]=i;
    }
    fo(i,mid,r) {
        while (top>1&&P(stack[top],stack[top-1])<=i) top--;
        int now=stack[top];
        tmp[i]=t[now]+(ll)(i-now)*(i-now+1)/2+sum[now]-sum[i]+g[i+1];
    }
    fd(i,r-1,mid) tmp[i]=max(tmp[i],tmp[i+1]);
    fo(i,mid,r) h[i]=max(h[i],tmp[i]);
    solve(l,mid);solve(mid+1,r);
}
int main() {
    //freopen("genocide.in","r",stdin);
    //freopen("genocide.out","w",stdout);
    n=read();
    fo(i,1,n) a[i]=read();
    Dp();fo(i,1,n) f[i]=t[i];
    fo(i,1,n/2) swap(a[i],a[n-i+1]);
    Dp();fo(i,1,n) g[i]=t[n-i+1];
    fo(i,1,n) ans[i]=-inf;

    fo(i,1,n/2) swap(a[i],a[n-i+1]);
    fo(i,1,n) t[i]=f[i];
    fo(i,1,n) sum[i]=sum[i-1]+a[i];
    fo(i,1,n) h[i]=-inf;
    solve(1,n);
    fo(i,1,n) ans[i]=max(ans[i],h[i]);

    fo(i,1,n) swap(f[i],g[i]);
    fo(i,1,n/2) {
        swap(a[i],a[n-i+1]);
        swap(f[i],f[n-i+1]);
        swap(g[i],g[n-i+1]);
    }
    fo(i,1,n) t[i]=f[i];
    fo(i,1,n) sum[i]=sum[i-1]+a[i];
    fo(i,1,n) h[i]=-inf;
    solve(1,n);
    fo(i,1,n) ans[i]=max(ans[i],h[n-i+1]);

    fo(i,1,n/2) {
        swap(f[i],f[n-i+1]);
        swap(g[i],g[n-i+1]);
        swap(a[i],a[n-i+1]);
    }
    fo(i,1,n) swap(f[i],g[i]);

    for(m=read();m;m--) x=read(),y=read(),printf("%lld\n",max(f[x-1]+g[x+1],ans[x]+a[x]-y));
    return 0;
}

Measured memory_bytes: 23552
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	string S;
	scan(S);
	if(S.size()==2) prin(S);
	else printf("%c%c%c\n",S[2],S[1],S[0]);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

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

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
using namespace std;
#define LL long long 
#define LD long double
const int mod=1e9+7;
int n,k;
LL ans,a[100005],cheng[100005];
LL poww(LL x,LL nn)
{
	LL res=1;
	while(nn)
	{
		if(nn&1)res=res*x%mod;
		x=x*x%mod;
		nn>>=1;
	}
	return res;
}
LL cm(LL x,LL y)
{
	return cheng[x]*poww(cheng[y],mod-2)%mod*poww(cheng[x-y],mod-2)%mod;
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	cheng[0]=1;
	for(int i=1;i<=n;i++)
		cheng[i]=cheng[i-1]*i%mod;
	for(int i=1;i<=n-k+1;i++)
	{
		ans=(ans-a[i]*cm(n-i,k-1)%mod)%mod;	
	}
	for(int i=k;i<=n;i++)
	{
		ans=(ans+a[i]*cm(i-1,k-1)%mod)%mod;
	}
	cout<<(ans+mod)%mod<<endl;
	return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//modint
template<typename T> T modinv(T a, T m) {
	T b = m, u = 1, v = 0;
	while (b) {
		T t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
template<typename T> T modpow(T x, int k) {
	if (k == 0)return 1;
	if (k % 2 == 0) return modpow(x * x, k / 2);
	else return x * modpow(x, k - 1);
}

template<int mod> class modint {
public:
	ll val;
	modint(ll a) {
		val = a % mod;
	}
	modint operator+(const modint& r) {
		return modint((this->val + r.val) % mod);
	}
	modint operator-(const modint& r) {
		return modint((this->val - r.val) % mod + ((this->val - r.val) % mod < 0) * mod);
	}
	modint operator*(const modint& r) {
		return modint((((this->val % mod) * (r.val % mod))) % mod);
	}
	modint operator/(const modint& r) {
		return modint(this->val * modinv<ll>(r.val, mod) % mod);
	}
	modint& operator+=(const modint& r) {
		*this = *this + r;
		return *this;
	}
	modint& operator-=(const modint& r) {
		*this = *this - r;
		return *this;
	}
	modint& operator*=(const modint& r) {
		*this = *this * r;
		return *this;
	}
	modint& operator/=(const modint& r) {
		*this = *this / r;
		return *this;
	}

};

// 
int main() {
	int N;
	cin >> N;
	vector<int> T(N), A(N), h(N,-1);
	for (int i = 0; i < N; i++)cin >> T[i];
	for (int i = 0; i < N; i++)cin >> A[i];
	bool invalid = false;
	h[0] = T[0]; h[N - 1] = A[N - 1];

	for (int i = 0; i < N-1; i++) {
		if (T[i] != T[i + 1]) {
			if (h[i + 1] != T[i+1] && h[i+1] != -1) {
				invalid = true;
			}
			h[i + 1] = T[i + 1];
		}
	}
	for (int i = N - 1; i >= 1; i--) {
		if (A[i] != A[i - 1]) {
			if (h[i - 1] != A[i-1] && h[i-1] != -1) {
				invalid = true;
			}
			h[i - 1] = A[i - 1];
		}
	}

	vector<int> T2(N), A2(N);
	T2[0] = h[0];
	for (int i = 0; i < N-1; i++) {
		T2[i + 1] = max(T2[i], h[i + 1]);
	}
	A2[N - 1] = h[N - 1];
	for (int i = N - 1; i >= 1; i--) {
		A2[i - 1] = max(A2[i], h[i - 1]);
	}

	if (T != T2 || A != A2)invalid = true;

	modint<MOD> ans = 1;
	if (invalid)ans = 0;
	for (int i = 1; i < N; i++) {
		if (h[i] != -1)continue;
		ans *= min(A[i], T[i]);
	}
	cout << ans.val << endl;
}

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

int main() {
  int H, W, h, w;
  cin >> H >> W >> h >> w;
  // 黒: 0, 白: 1
  // すべて白のH行W列のマス目を作成
  vector<vector<int>> cells(H, vector<int>(W, 1));
  // 上からh行を黒色で塗る
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < W; j++) {
      cells.at(i).at(j) = 0;
    }
  }
  // 左からw列を黒色で塗る
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < w; j++) {
      cells.at(i).at(j) = 0;
    }
  }
  // 白色のマス目を数える
  int white_cells = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      white_cells += cells.at(i).at(j);
    }
  }
  cout << white_cells << endl;
  return 0;
}


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


int main(){
  long double w,h,x,y;
  cin >> w >> h >> x >> y;
  cout << w*h/2.0 << endl;
  if( (x == w/2) && (y == h/2) ) {
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}

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

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;
}
const long long INF=1LL<<60;

int N,K;
long long h[100010];

long long dp[100010];

int main(){
  cin >> N >> K;
  for(int i=0;i<N;i++)  cin >> h[i];
  for(int i=0;i<100010;i++) dp[i]=INF;

  dp[0]=0;
  for(int i=0;i<N;i++){
    for(int k=1;k<=K;k++){
      chmin(dp[i+k],dp[i]+abs(h[i+k]-h[i]));
    }
  }
  cout << dp[N-1] << endl;
}


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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<long> a(n);
    long sum = 0;
    for(int i = 0;i < n;i++){
        cin >> a[i];
        sum += a[i];
    }
    sort(a.begin(),a.end());
    cout << a[0] <<" "<< a[n-1] <<" "<< sum << endl;
}


Measured memory_bytes: 3224
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
pair<vll,vll > prime_factor_decomp(ll n) {
    vll p, e;
    ll m = n;
    for (ll i = 2; i * i <= n; i++) {
        if (m % i != 0) continue;
        int c = 0;
        while (m % i == 0) c++, m /= i;
        p.push_back(i);
        e.push_back(c);
    }
    if (m > 1) {
        p.push_back(m);
        e.push_back(1);
    }
    return mp(p, e);
}
int main(){
	int soinsu[100]={};
	int N;
	scan(N);
	int ans=0;
	for(int i=2;i<=N;i++){
		pair<vll,vll > decomp=prime_factor_decomp(i);
		vll p=decomp.first,e=decomp.second;
		rep(j,p.size()){
			soinsu[p[j]]+=e[j];
		}
	}
	rep(i,98){
		for(int j=i+1;j<99;j++){
			for(int k=j+1;k<100;k++){
				if(soinsu[i]>=2&&soinsu[j]>=4&&soinsu[k]>=4) ans++;
				if(soinsu[i]>=4&&soinsu[j]>=2&&soinsu[k]>=4) ans++;
				if(soinsu[i]>=4&&soinsu[j]>=4&&soinsu[k]>=2) ans++;
			}
		}
	}
	rep(i,99){
		for(int j=i+1;j<100;j++){
			if(soinsu[i]>=14&&soinsu[j]>=4) ans++;
			if(soinsu[i]>=4&&soinsu[j]>=14) ans++;
			if(soinsu[i]>=2&&soinsu[j]>=24) ans++;
			if(soinsu[i]>=24&&soinsu[j]>=2) ans++;
		}
	}
	rep(i,100){
		if(soinsu[i]>=74) ans++;
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const int INF = 2000000000;

string s;

int main(){
  cin >> s;
  s.at(5) = s.at(13) = ' ';
  cout << s <<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>

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

  std::vector<int> A_arr(N+1), ans_arr(N+1);
  for(int i = 0; i < N; i++){
    std::cin >> A_arr[i+1];
  }

  int total_count = 0;
  bool success = true;
  for(int i = N; i > 0; i--){
    int isum = 0;
    for(int j = 2*i; j < N+1; j += i){
      isum = (isum + ans_arr[j])%2;
    }
    if(A_arr[i] > 1){
      success = false;
      break;
    }
    ans_arr[i] = (isum + A_arr[i])%2;
    total_count += ans_arr[i];
  }

  if(success){
    std::cout << total_count << "\n";
    for(int i = 1; i < N+1; i++){
      if(ans_arr[i] == 1){
        std::cout << i << " ";
      }
    }
    std::cout << std::endl;
  }else{
    std::cout << "-1" << std::endl;
  }

  return 0;
}



Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
int a, b, c;
int main(){
    scanf("%d %d %d", &a, &b, &c);
    if((a&b&c)&1) return !printf("%lld", min(1LL*a*b, min(1LL*a*c, 1LL*b*c)));
    puts("0");
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define int long long
#define mod 1000000007
using namespace std;
int n, a[123456], b, ans;
signed main() {
	cin >> n;
	for (int i = 0; i <= n; i++)cin >> a[i];
	for (int i = 0; i < n; i++) {
		cin >> b;
		ans += min(a[i] + a[i + 1], b);
		b = max((int)0, b - a[i]);
		a[i + 1] = max((int)0, a[i + 1] - b);
	}
	cout << ans << endl;
}

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

int main(){
    using namespace std;
    unsigned long N, M;
    cin >> N >> M;
    for(unsigned long i{0}, j{1}, k{N}; i < M; ++i){
        cout << j << " " << k << endl;
        ++j;
        --k;
        if((~N & 1) && (j == (N + 4) / 4))++j;
    }
    return 0;
}

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

const int mod = 1000000007;

int main(){
    ll n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    map<char, ll> mp;
    mp['M'] = 0;
    mp['A'] = 0;
    mp['R'] = 0;
    mp['C'] = 0;
    mp['H'] = 0;
    rep(i, n)
    {
        if(s[i][0]=='M'||s[i][0]=='A'||s[i][0]=='R'||s[i][0]=='C'||s[i][0]=='H'){
            mp[s[i][0]]++;
        }
    }
    ll ans = mp['M'] * mp['A'] * mp['R'] + mp['M'] * mp['A'] * mp['C'] + mp['M'] * mp['A'] * mp['H'] + mp['M'] * mp['R'] * mp['C'] + mp['M'] * mp['R'] * mp['H'] + mp['M'] * mp['C'] * mp['H'] + mp['A'] * mp['R'] * mp['C'] + mp['A'] * mp['R'] * mp['H'] + mp['A'] * mp['C'] * mp['H'] + mp['R'] * mp['C'] * mp['H'];
    cout << ans << endl;
}

Measured memory_bytes: 6144
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    if(n==m)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


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

using namespace std;

typedef long long llint;

llint n, k;
vector<llint> a, f;
bool ok(llint mid, llint kk = k) {
  bool flag = true;
  for (int i = 0; i < n; i++) {
    if (a[i] * f[i] <= mid) continue;
    kk -= a[i] - mid / f[i];
    if (kk < 0) {
      flag = false;
    }
  }
  return flag;
}

int main() {
  cin >> n >> k;
  a.assign(n, 0);
  f.assign(n, 0);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> f[i];
  sort(a.begin(), a.end());
  sort(f.rbegin(), f.rend());
  llint l = -1, r = 1e18 + 10;
  while (l + 1 < r) {
    llint mid = (l + r) / 2;
    if (ok(mid)) {
      r = mid;
    } else {
      l = mid;
    }
  }
  cout << l + 1 << endl;

  return 0;
}

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

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3)                                                \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << endl
#define dump_4(x1, x2, x3, x4)                                            \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5)                                        \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
  CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using namespace std;

using ll = long long;

const long long MOD = 1000000007;

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

vector<vector<ll>> matrixmul(vector<vector<ll>> a, vector<vector<ll>> b, ll N) {
  vector<vector<ll>> ret(N, vector<ll>(N, 0));
  rep(i, N) {
    rep(j, N) {
      rep(k, N) {
        ret.at(i).at(j) += (a.at(i).at(k) * b.at(k).at(j)) % MOD;
        ret.at(i).at(j) %= MOD;
      }
    }
  }
  return ret;
}

vector<vector<ll>> matrixpow(vector<vector<ll>> a, ll N, ll K) {
  if (K == 0) {
    vector<vector<ll>> ret(N, vector<ll>(N, 0));
    rep(i, N) ret.at(i).at(i) = 1;
    return ret;
  }
  if (K % 2 == 0) {
    auto t = matrixpow(a, N, K / 2);
    return matrixmul(t, t, N);
  }
  auto t = matrixpow(a, N, K - 1);
  return matrixmul(a, t, N);
}

void solve(ll N, ll K, std::vector<std::vector<ll>> a) {
  a = matrixpow(a, N, K);

  ll ans = 0;
  rep(i, N) {
    rep(j, N) { ans = (ans + a.at(i).at(j)) % MOD; }
  }
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll N;
  scanf("%lld", &N);
  ll K;
  scanf("%lld", &K);
  std::vector<std::vector<ll>> a(N, std::vector<ll>(N));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      scanf("%lld", &a[i][j]);
    }
  }
  solve(N, K, std::move(a));
  return 0;
}


Measured memory_bytes: 5960
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000000000000


int main(){
	
	int N;
	cin>>N;
	
	map<int,int> mp;
	for(int i=0;i<N;i++){
		int a;
		cin>>a;
		mp[a]++;
	}
	
	int ans = 0;
	
	for(auto a:mp){
		if(a.first>a.second){
			ans += a.second;
		}
		else{
			ans += a.second-a.first;
		}
	}
	
	cout<<ans<<endl;
	
    return 0;
}


Measured memory_bytes: 4736
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

/*==================================================*/
/*variable*/
int c[5][5], d[5][5];

/*==================================================*/
/*function*/

/*==================================================*/

int main() {
    REP(i,0,3){
        REP(j,0,3){
            cin>>c[i][j];
        }
    }

    REP(i,0,3){
        REP(j,0,3){
            if(c[i][j] + c[(i+1)%3][(j+1)%3] != c[i][(j+1) % 3] + c[(i+1)%3][j]){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }

    cout<<"Yes"<<endl;

    return 0;
}


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

main(){
  int i,j,k,n,r,p,c;
  int *A,*B;

  while(1){
    scanf("%d%d",&n,&r);
    if(n==0&r==0) break;

    A=malloc(sizeof(int)*n+1);
    B=malloc(sizeof(int)*n+1);

    for(i=0;i<n;i++) A[i]=n-i;

    for(k=0;k<r;k++){
      scanf("%d%d",&p,&c);

      for(i=0;i<c;i++) B[i]=A[p-1+i];
      
      for(j=0;j<p-1;j++) B[i+j]=A[j];

      for(i=0;i<p-1+c;i++) A[i]=B[i];

    }

    printf("%d\n",A[0]);
    
    free(A);
    free(B);
  }
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9+7;

int main(void){

    int N; cin>>N;
    double ans=0.0;

    for (int i = 0; i < N; ++i) {
        double tmp; cin>>tmp;
        ans += 1.0/tmp;
    }
    ans = 1 / ans;
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
// {{{
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
// }}}

using namespace std;

using ll [[maybe_unused]] = long long;
using ull [[maybe_unused]] = unsigned long long;
using ld [[maybe_unused]] = long double;

[[maybe_unused]] static constexpr int mod = (int)1e9 + 7;
[[maybe_unused]] static constexpr int inf = 100100100;
[[maybe_unused]] static constexpr ll linf = 1e18;
[[maybe_unused]] static constexpr double eps = 1e-9;
[[maybe_unused]] static constexpr double pi = 3.14159265359;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rrep(i, a) for (ll i = a; i >= 0; --i)
#define all(obj) begin(obj), end(obj)
#define rall(obj) rbegin(obj), rend(obj)
#define pb push_back
#define fst first
#define snd second


int main() {
    // cin.tie(0);
    // ios_base::sync_with_stdio(false);
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


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

clock_t present = clock();
void complexiti(){
	present = clock() - present;
	cerr << "TIME : " << float(present)/CLOCKS_PER_SEC << '\n';
}

void solver(){
	//~ type your code here
	multiset<int> ms;
	int n;
	cin >> n;
	vector<int> v(n);
	for(int i = 0 ; i < n ; ++i){
		cin >> v[i];
		ms.insert(v[i]);
	}
	for(int i = 0 ; i < n ; i++){
		ms.erase(ms.find(v[i]));
		cout << *ms.rbegin() << endl;
		ms.insert(v[i]);
	}
	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int queries = 1;
	//~ cin >> queries;
	for(int i = 0 ; i < queries ; ++i){
		solver();
	}
	complexiti();
	return 0;
}


Measured memory_bytes: 11776
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) printf(f,##__VA_ARGS__),fflush(stdout)

typedef long long ll;

const int N=2333;

int main(int argc,char *argv[]){
	int n,a,b;
	cin>>n>>a>>b;	
	if((b-a-1)%2==0)puts("Borys");
	else puts("Alice");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0)
#define scl(n) scanf("%lld", &n)
#define pcl(n) printf("%lld\n", n)
#define pcl1(n) printf("%lld ", n)
#define nln printf("\n")
#define dev(x) cout << #x << " " << x << " ";
#define PTT pair<ll, ll>

map<ll, ll> mp, mp1;
map<ll, ll>::iterator itr;

int main()
{
    ll t, n, x, k, d;
    scl(x);
    scl(k);
    scl(d);
    ll p, z = 1e18;
    ll mn = 1e18;
    if (abs(x) == d)
    {
        if (k & 1)
        {
            cout << "0" << endl;
        }
        else
        {
            if (x < 0)
            {
                x *= (-1LL);
            }
            cout << x << endl;
        }
    }
    else
    {
        if (x < 0)
        {
            x *= (-1LL);
        }
        p = x / d;
        p = min(p, k);
        z = x - p * d;

        if (p < k)
        {
            k -= p;
            if (k % 2 == 0)
            {
                z =  x - p * d;
            }
            else
            {
                z = abs(x - (p + 1) * d);
            }
        }
        pcl(z);
    }

    return 0;
}

Measured memory_bytes: 3816
#include <iostream>
using namespace std;
int main(){
  int a;
  string b;
  cin>>a;
  for(int i=0;i<a;i++){
    cin>>b;
    if(b=="Y"){
      cout<<"Four"<<endl;
      return 0;
    }
  }
  cout<<"Three"<<endl;
}


  
    
  
    

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

struct LCA {
  const vector<vector<int>>& g;
  vector<vector<int>> parent;
  vector<int> depth;
  int k;

  LCA(const vector<vector<int>>& g) : g(g) {}

  void dfs(int v, int p, int d) {
    parent[v][0] = p;
    depth[v] = d;
    for(auto to : g[v]) {
      if(to != p) dfs(to,v,d+1);
    }
  }

  void build() {
    int x = 1; k = 0;
    while(x <= g.size()) {x *= 2, k++;}
    parent = vector<vector<int>>(g.size(),vector<int>(k));
    depth = vector<int>(g.size());
    dfs(0,-1,0);
    rep(i,k-1) {
      rep(v,g.size()) {
        if(parent[v][i] < 0) parent[v][i+1] = -1;
        else parent[v][i+1] = parent[parent[v][i]][i];
      }
    }
  }

  int lca(int u, int v) {
    if(depth[u] > depth[v]) swap(u,v);
    rep(i,k) {
      if((depth[v] - depth[u]) & (1<<i)) v = parent[v][i];
    }
    if(u == v) return u;
    for(int i = k-1; i >= 0; i--){
      if(parent[u][i] != parent[v][i]) {
        u = parent[u][i]; v = parent[v][i];
      }
    }
    return parent[u][0];
  }

  int dist(int u, int v) {
    return depth[u] + depth[v] - 2*depth[lca(u,v)];
  }
};

int main() {
  int n;
  cin >> n;
  vector<vector<int>> g(n);
  rep(i,n) {
    int k;
    cin >> k;
    rep(j,k) {
      int c;
      cin >> c;
      g[i].push_back(c);
      g[c].push_back(i);
    }
  }
  LCA lca(g);
  lca.build();
  int q;
  cin >> q;
  vector<int> ans(q);
  rep(i,q) {
    int u, v;
    cin >> u >> v;
    ans[i] = lca.lca(u,v);
  }
  for(auto x : ans) cout << x << endl;
}



Measured memory_bytes: 22000
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int n, k;
vector<pair<double, double>> p;
double dist(const pair<double, double> &p1, const pair<double, double> &p2) {
  double dx = p1.first - p2.first, dy = p1.second - p2.second;
  return sqrt(dx * dx + dy * dy);
}
double calc(pair<double, double> now) {
  multiset<double> d;
  for(int i=0;i<n;++i) {
    d.insert(dist(now, p[i]));
  }
  int cnt = 0;
  double su = 0.0;
  for(const auto &e: d) {
    if(cnt >= n-k) su += e;
    cnt++;
  }
  return su;
}
double dx[8] = {1, -1, 0, 0, 1, 1, -1, -1};
double dy[8] = {0, 0, 1, -1, 1, -1, 1, -1};
double tmpx[8] = {1, 1, 0, 0, 1.0 / sqrt(2.0), 1.0 / sqrt(2.0), 1.0 / sqrt(2.0), 1.0 / sqrt(2.0)};
double tmpy[8] = {0, 0, 1, 1, 1.0 / sqrt(2.0), 1.0 / sqrt(2.0), 1.0 / sqrt(2.0), 1.0 / sqrt(2.0)};
pair<double, double> clime(pair<double, double> now, double diff) {
  int argmi = 0;
  double mi = INF;
  for(int i=0;i<8;++i) {
    double res = calc({now.first + diff * tmpx[i] * dx[i], now.second + diff * tmpy[i] * dy[i]});
    if(res < mi) {
      argmi = i;
      mi = res;
    }
  }
  return {now.first + diff * tmpx[argmi] * dx[argmi], now.second + diff * tmpy[argmi] * dy[argmi]};
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  cin >> n >> k;
  p.resize(n);
  for(int i=0;i<n;++i) {
    cin >> p[i].first >> p[i].second;
  }
  pair<double, double> now = {0.0, 0.0};
  double diff = 100.0;
  double tmp = 1.0;
  int cnt = 0;
  while(diff > 0.0001) {
    for(int i=0;i<10;++i) {
      now = clime(now, diff);
    }
    diff -= tmp;
    if(diff <= tmp * 10) tmp /= 10;
    cnt++;
  }
  cout << calc(now) << endl;
}



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



int main() {
  int K,S;
  cin>>K>>S;
  int answer=0;
  
    for (int i=0;i<K+1;i++){
      for (int j=0;j<K+1;j++){
        if (0<=S-i-j && S-i-j<=K){
          answer+=1;
        }
      }
    }
  cout<<answer<<endl;
  
  
    
    
  
  
}




Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
# sys.setrecursionlimit(10000)


def main():
    # 入力処理
    N, M = map(int, input().split())

    # アルゴリズム本体
    if (2 * N) >= M:
        K = int(M / 2)
    else:
        K = N + int((M - 2 * N) / 4)

    # 出力
    print(K)


if __name__ == '__main__':
    main()


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

ll N, A, B;
int main(){
  cin >> N >> A >> B;
  ll ans = (N / (A + B)) * A;
  if (N % (A + B) <= A) ans += N % (A + B);
  else ans += A;
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 3632