akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
#define modulo 1000000007 // 10^9 + 7
#define MAX 1000000000 // 10^9

int line[501][501];
int sum[501][501];

int main() {
	int N, M, Q;
	cin >> N >> M >> Q;
	int p[Q], q[Q];

	for (int i = 0; i < M; i++) {
		int l, r;
		cin >> l >> r;
		line[l][r]++;
	}

	for (int i = 0; i < Q; i++) cin >> p[i] >> q[i];

	for (int i = 1; i <= N; i++) {
		sum[i][0] = 0;
		sum[i][1] = line[i][1];
		for (int j = 2; j <= N; j++) {
			sum[i][j] = sum[i][j - 1] + line[i][j];
		}
	}

	for (int i = 0; i < Q; i++) {
		int ans = 0;
		for (int j = p[i]; j <= q[i]; j++) {
			ans += (sum[j][q[i]] - sum[j][p[i] - 1]);
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define null NULL
#define mp make_pair
#define pb(a) push_back(a)
#define sz(a) ((int)(a).size())
#define all(a) a.begin() , a.end()
#define fi first
#define se second
#define relaxMin(a , b) (a) = min((a),(b))
#define relaxMax(a , b) (a) = max((a),(b))
#define SQR(a) ((a)*(a))
#define PI 3.14159265358979323846
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

const int MAX = 110;

int n;
int a[MAX], b[MAX];

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

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

  for(int i = 1;i <= n;++i) a[i] += a[i - 1];
  for(int i = 1;i <= n;++i) b[i] += b[i - 1];

  int ans = a[n] + b[n] - b[n - 1];

  for(int bp = 1;bp <= n;++bp){
    int cur = a[bp] + b[n] - b[bp - 1];
    relaxMax(ans, cur);
  }

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

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

class Main {
    int N;
    int cnt, res;
    void input() {
        cin >> N;
        cnt = 0;
        res = 0;
        REP(i, N) {
            int d1, d2;
            cin >> d1 >> d2;
            if (d1 == d2) {
                cnt++;
                res = max(res, cnt);
            } else
                cnt = 0;
        }
    }
    void output() {
        if (res >= 3)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }

public:
    Main() {
        input();
        output();
    }
};

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

    Main();

    return 0;
}


Measured memory_bytes: 3648
#include<stdio.h>
#include<math.h>
int main (void){
    int i,N,a,ans,max,min;
    while(-1){
        ans=0;max=0;min=9999;
        scanf("%d",&N);
        if(N==0){break;}
        for(i=0;i<N;i++){
            scanf("%d",&a);
            ans+=a;
            if(max<a){max=a;}
            if(min>a){min=a;}
        }
        ans-=max+min;
        a=ans/(N-2);
        printf("%d\n",a);
    }
    return 0;
}

Measured memory_bytes: 600
#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++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
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 {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=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 {
        mint res(*this);
        return res/=a;
    }
};

//n -> big, a -> small
mint choose(int n,int a){
    mint x = 1, y = 1;
    rep(i,a){
        x *= n-i;
        y *= i+1;
    }
    return x / y;
}

int main(){
    cout << fixed << setprecision(10);
    ll n,a,b;
    cin >> n >> a >> b;
    mint ans = mint(2).pow(n);
    ans -= 1;
    ans -= choose(n,a);
    ans -= choose(n,b);
    cout << ans.x << endl;
    return 0;
}

Measured memory_bytes: 256
s = input()
t = input()
memo = []

for i in range(len(s)-len(t)+1):
    p = s[i:(i+len(t))]
    flag = True
    for j in range(len(t)):
        if p[j] != "?" and p[j] != t[j]:
            flag = False
            break
    if flag:
        memo.append((s[0:i]+t+s[(i+len(t)):len(s)]).replace("?","a"))

if len(memo) == 0:
    print("UNRESTORABLE")
else:
    print(min(memo))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
const string YES = "Yes";
const int  INF = 1001001001;
vector<int> to[1000005];

void solve(long long N, long long M){
    queue<int> q;
    vector<int> dist(N,INF);
    vector<int> pre(N,-1);
    dist[0] = 0;
    q.push(0);

    while(!q.empty()){
        int v = q.front(); q.pop();
        rep(i,to[v].size()){
            int u = to[v][i];
            if(dist[u] != INF) continue;
            dist[u] = dist[v]+1;
            pre[u] = v;
            q.push(u);
        } 
    }
    cout << "Yes" << endl;
    rep(i,N){
        if(i==0) continue;
        int ans = pre[i];
        ++ans;
        cout << ans << endl;
    }
}

// void solve2(long long N, long long M){
//     queue<int> q;
//     vector<int> dist(N,INF);
//     vector<int> pre(N, -1);
//     dist[0] = 0;
//     q.push(0);
//     while(!q.empty()){
//         int v = q.front; q.pop;
//         for(int u : to[v]){
//             if(dist[u] != INF) continue;
//             dist[u] = dist[v] + 1;
//             pre[u] = v;
//             q.push(v);
//         }
//     }

//     cout << YES << endl;
//     rep(i,N){
//         if(i == 0) continue;
//         int ans = pre[i];
//         ans++;
//         cout << ans << endl;
//     }
// }

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);

    for(int i = 0 ; i < M ; i++){
        int a,b;
        cin >> a >> b;
        --a; --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    solve(N, M);
    return 0;
}


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

ans1 = 0
s = 0
for i,a in enumerate(A):
    s += a
    if i%2:
        if s > -1:
            ans1 += s+1
            s = -1
    else:
        if s < 1:
            ans1 += 1-s
            s = 1

ans2 = 0
s = 0
for i,a in enumerate(A):
    s += a
    if i%2==0:
        if s > -1:
            ans2 += s+1
            s = -1
    else:
        if s < 1:
            ans2 += 1-s
            s = 1

print(min(ans1, ans2))

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

using namespace std;

#define llong long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int MOD = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = 1LL << 31;
const static int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main (int argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<int> D(n);
  int lim = -1;
  rep(i, n) cin >> D[i], lim = max(lim, D[i]);
  sort(all(D));

  int ans = 0;
  for (int k = 1; k <= lim; ++k) {
    int t = lower_bound(all(D), k) - D.begin();
    if (t == n / 2) ++ans;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 768
fun countSame(S: String): Long {
    var same = 0L
    var rep = 0L
    var c = (0).toChar()
    for (s in S) {
        if (s == c) rep++
        else {
            c = s
            same += (rep + 1) / 2
            rep = 0
        }
    }
    same += (rep + 1) / 2
    return same
}
fun main(args: Array<String>) {
    val S = next()
    val K = nextLong()
    val one = countSame(S)
    val two = countSame(S.repeat(2))
    if (S.all { it == S[0] }) {
        println(S.length * K / 2)
    } else {
        println(one + (two - one) * (K - 1))
    }
}
fun next() = readLine()!!
fun nextLong() = next().toLong()

Measured memory_bytes: 33780
#![allow(unused_macros, unused_imports, dead_code, non_snake_case)]

use std::io;

fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s
}

macro_rules! from_line {
    ($($a:ident : $t:ty),+) => {
        $(let $a: $t;)+
        {
            let _line = read_line();
            let mut _it = _line.trim().split_whitespace();
            $($a = _it.next().unwrap().parse().unwrap();)+
            assert!(_it.next().is_none());
        }
    };
}

macro_rules! input {(source = $ s : expr , $ ($ r : tt ) * ) => {let mut iter = $ s . split_whitespace () ; input_inner ! {iter , $ ($ r ) * } } ; ($ ($ r : tt ) * ) => {let mut s = {use std :: io :: Read ; let mut s = String :: new () ; std :: io :: stdin () . read_to_string (& mut s ) . unwrap () ; s } ; let mut iter = s . split_whitespace () ; input_inner ! {iter , $ ($ r ) * } } ; }
macro_rules! input_inner {($ iter : expr ) => {} ; ($ iter : expr , ) => {} ; ($ iter : expr , $ var : ident : $ t : tt $ ($ r : tt ) * ) => {let $ var = read_value ! ($ iter , $ t ) ; input_inner ! {$ iter $ ($ r ) * } } ; ($ iter : expr , mut $ var : ident : $ t : tt $ ($ r : tt ) * ) => {let mut $ var = read_value ! ($ iter , $ t ) ; input_inner ! {$ iter $ ($ r ) * } } ; }
macro_rules! read_value {($ iter : expr , ($ ($ t : tt ) ,* ) ) => {($ (read_value ! ($ iter , $ t ) ) ,* ) } ; ($ iter : expr , [$ t : tt ; $ len : expr ] ) => {(0 ..$ len ) . map (| _ | read_value ! ($ iter , $ t ) ) . collect ::< Vec < _ >> () } ; ($ iter : expr , chars ) => {read_value ! ($ iter , String ) . chars () . collect ::< Vec < char >> () } ; ($ iter : expr , usize1 ) => {read_value ! ($ iter , usize ) - 1 } ; ($ iter : expr , $ t : ty ) => {$ iter . next () . unwrap () . parse ::<$ t > () . expect ("Parse error" ) } ; }

fn main() {
    loop {
        from_line!(n:usize, r:usize);
        if n == 0 { break }
        let mut g = vec![0; n];
        let mut s = r;
        let mut v = n;
        loop {
            for i in 0..n {
                if s > 0 {
                    g[i] += 1;
                    s -= 1;
                    if g[i] == r {
                        v = i;
                        break;
                    }
                } else if g[i] > 0 {
                    s += g[i];
                    g[i] = 0;
                }
            }
            if v < n {
                break;
            }
        }
        println!("{}", v);
    }
}



Measured memory_bytes: 5028
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int ans,hh,x,n,y,z,i,j,mx,k,now,p=1e9+7,f[41][1<<17];
int main(){
	scanf("%d%d%d%d",&n,&x,&y,&z);
	hh=(1<<z-1)|(1<<y+z-1)|(1<<x+y+z-1);
	f[0][0]=1;
	mx=(1<<x+y+z)-1;
	for(i=1;i<=n;i++){
		for(j=0;j<=mx;j++)if(f[i-1][j]){
			for(k=1;k<=10;k++){
				now=(j<<k)|(1<<k-1);
				now&=mx;
				if((now&hh)!=hh)f[i][now]=(f[i][now]+f[i-1][j])%p;
			}
		}
	}
	ans=1;
	for(i=1;i<=n;i++)ans=1ll*ans*10%p;
	for(i=0;i<=mx;i++)ans=(ans-f[n][i]+p)%p;
	printf("%d",ans);
}

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

int a[2][110];

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

    int n;
    cin>>n;

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

    int ans=0;

    for(int i=1;i<=n;i++)
    {
        ans=max(ans,a[0][i]+a[1][n]-a[1][i-1]);
    }

    cout<<ans<<"\n";

    return 0;
}


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

int main() {
	// your code goes here
	string s;
	cin>>s;
	int l=s.length();
	int sum=0;
	for(int i=0;i<l;i++){
		sum=(sum%9+(s[i]-'0')%9)%9;
	}
	if(sum==0){
		cout<<"Yes";
	}
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 3748
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
int d[1000000];
int num[1000000];
int ans[2000+100][2000+100]; 
int main()
{
   int i,j,n,m,l,kk,p; 
	 scanf("%d%d%d",&n,&m,&p);
	for(i=1;i<=n;i++)
	{
	d[i]=i;
	}
	 ans[m][p]=ans[p][m]=1;
	for(i=1;i<=n;i++)
	for(j=i+1;j<=n;j++)
	{
	if(ans[i][j]==0)
	{
	 kk=(abs(p-i)+1+abs(m-j));
	 l=(abs(m-i)+1+abs(p-j));
	 l=min(l,kk);
	 ans[i][j]=min(abs(d[i]-d[j]),l);
	 ans[j][i]=ans[i][j];
	}
    }
	for(i=1;i<=n;i++)
	for(j=i+1;j<=n;j++)
	{
		num[ans[i][j]]++;
	}
	for(i=1;i<=n-1;i++)
	printf("%d\n",num[i]);

}

Measured memory_bytes: 20736
#include <cstdio>
using namespace std;

#define ll long long

int n;
int ans[200005];

int main()
{
    scanf("%d", &n);
    for (int i = 2; i <= n; i++) {
        int a; scanf("%d", &a); ans[a]++;
    }
    for (int i = 1; i <= n; i++) {
        printf("%d\n", ans[i]);
    }
    return 0;
}


Measured memory_bytes: 2508
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9;
const ll mod = 1e9+7;
typedef pair<int,int> P;
#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,m,N) for(int i=m;i<N;i++)
#define mm(n,m) memset(n,m,sizeof(n))

int main(){
  ll n;
  cin>>n;
  ll a[n];
  ll c[n];
  mm(c,0);
  for(int i = 0; i < n; i++){
    cin>>a[i];
    if(i==0){
      c[0] = a[0];
      //cout<<"i:"<<i<<" ci:"<<c[i]<<endl;
      continue;
    }
    c[i] = (a[i]+c[i-1]);
    //cout<<"i:"<<i<<" ci:"<<c[i]<<endl;
  }
  rep(i,n){
    if(c[i]==c[n-1]/2 && c[n-1]%2==0){
      cout<<0<<endl;
      return 0;
    }
  }
  ll ans=1e10+5;
  bool flag = false;
  rep(i,n){
    if(c[i] >= (c[n-1]/2)){
     // cout<<"i:"<<i<<" ci:"<<c[i]<<endl;
     if(i==0){
       flag = true;
       break;
     }
      ans = min(abs(c[i] - (c[n-1]-c[i])),abs(c[i-1] - (c[n-1]-c[i-1])));
      //cout<<abs(c[i] - (c[n-1]-c[i]))<<" "<<abs(c[i-1] - (c[n-1]-c[i-1]))<<endl;
      //ans = min(ans,tmp);
      break;
    }
  }
    if(flag){
      ans = abs(c[0]-(c[n-1]-c[0]));
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

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

int main(){
    int n;
    cin >> n;
    vector<int> h(n),cost(n,0);
    rep(i,n) cin >> h[i];

    int ans = 0;
    cost[1] = abs(h[1]-h[0]);
    
    reps(i,2,n){
        cost[i] = min(cost[i-1]+abs(h[i-1]-h[i]) , cost[i-2]+abs(h[i-2]-h[i]));
    }

    cout << cost[n-1] << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

int main() {
	string S;
	ll K;
	cin >> S >> K;
	ll ans=0;
	ll now=1, he=-1;
	for(int i=1; i<S.size(); ++i){
	    if(S[i-1]==S[i]){
	        ++now;
	    }else{
	        if(he>0){
	            ans += K*(now/2);
	        }else{
	            he=now;
	        }
	        now=1;
	    }
	}
	if(S[0]==S.back()){
	    if(he<0) ans=(K*now)/2;
	    else ans += (K-1)*((he+now)/2)+he/2+now/2;
	}else{
	    ans += K*(he/2 + now/2);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define repp(i,n,s) for (int i= (int)(n); i >= (int)(s); i--)
#define mp make_pair
ll mod = 1000000007;
ll mod2 = 998244353;

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    vector<int> x(n);
    rep(i,0,n) cin>>x[i];
    vector<int> a(n),b(n);
    a[0] = x[0];
    b[n-1] = x[n-1];
    rep(i,1,n){
        a[i] = __gcd(a[i-1],x[i]);
    }
    repp(i,n-2,0){
        b[i] = __gcd(b[i+1],x[i]);
    } 
    int ans = max(b[1],a[n-2]);
    rep(i,1,n-1){
        ans = max(ans,__gcd(a[i-1],b[i+1]));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4468
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int n;
    while(cin>>n,n){
        vector<int>V(n+1);
        for(int i=0;i<=n;i++)cin>>V[i];
        for(int i=0;i<=n;i++){
            vector<int>T=V;
            T.erase(T.begin()+i);

            int dif=T[1]-T[0];
            bool Flag=false;
            for(int i=1;i<T.size();i++){
                if(T[i]-T[i-1]!=dif){
                    Flag=true;
                    break;
                }
            }
            if(!Flag){
                cout<<V[i]<<endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#define rep0(i,n) for (int i = 0; i < (n); ++i)  //0index
#define rep1(i,n) for (int i = 1; i < (n); ++i)  //1index
#define REP(i,a,b) for (int i = a; i < (b); ++i)  //aからb - 1まで
#define mREP(i,a,b) for (int i = a; i > (b); --i)  //逆
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;  //最大値兼MOD
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }  //GCD
ll dp[100010];
ll v[100010];
int main(){
	int n,m;
    cin >> n >> m;
    int temp;
    rep0(i,m){
        cin >> temp;
        v[temp] = 1;
    }
    dp[0] = 1;
    if(v[1] != 1)dp[1] = 1;
    REP(i,2,n+1){
        if(v[i-1] != 1)dp[i] += dp[i-1]; 
        if(v[i-2] != 1)dp[i] += dp[i-2]; 
        dp[i] %= INF;
    }
    cout << dp[n] << endl;
	return 0;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
//#define int ll
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
typedef complex<double> base;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define modsum(a, b) ((a) + (b) >= M ? (a) + (b) - M : (a) + (b))
#define modsubtract(a, b) ((a) - (b) < 0 ? (a) - (b) + M : (a) - (b))
#define modmultiply(a, b) (((a) * (b)) % M)
#define insum(a, b)  a = modsum(a, (b))
#define insubtract(a, b) a = modsubtract(a, (b))
#define inmultiply(a, b) a = modmultiply(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < (int)(n); ++i)
#define cint const int &
#define SZ(a) ((int)(a.size()))
#ifdef MAX_HOME
#define watch(x) cout << (#x) << " = " << x << endl;
#else
#define watch(x) cerr << (#x) << " = " << x << endl;
#endif

const double PI = 2 * acos(0.0);

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";


template<class T>
ostream & operator << (ostream &out, vector<T> &a) {
    out << "{";
    for (auto x : a) out << x << " ";
    return out << "}";
}

template<class T>
ostream & operator << (ostream &out, pair<T, T> &a) {
    out << "{";
    cout << a.first << ", " << a.second;
    return out << "}";
}

void smain();

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

#ifdef MAX_HOME
    freopen("input.txt", "r", stdin);
#endif

    cout << setprecision(12) << fixed;

    smain();
}
/* END OF TEMPLATE ========================================================================================================================================== */;



void smain() {

    int n;
    ll ans = 0;
    cin >> n;
    ll kek = 1e9 + 7;
    bool ok = 1;
    fori (i, n) {
        ll a, b;
        cin >> a >> b;
        ok &= a == b;
        ans += a + b;
        if (a > b) inmin(kek, b);
    }
    if (ok) {cout << "0";return;}
    ans -= kek * 2;
    ans >>= 1;
    cout << ans;
}
     

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define INF 4000000000000000000
int dx8[8]={-1,0,1,1,1,0,-1,-1};
int dy8[8]={1,1,1,0,-1,-1,-1,0};
int dx4[4]={-1,0,1,0};
int dy4[4]={0,-1,0,1};
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int uni[100010];
int root(int a){
    if(uni[a]<0)return a;
    return uni[a]=root(uni[a]); 
}
bool connect(int a,int b){
    a=root(a);
    b=root(b);
    if(a==b)return false;
    if(uni[a]>uni[b]){
        swap(a,b);
    }
    uni[a]=uni[a]+uni[b];
    uni[b]=a;
    return true;
}
signed main(void){
    int n;cin>>n;
    string s;cin>>s;
    
    vector<set<int>>Alpha(26);//26のindex集合
    
    //初めの設定
    rep(i,26)Alpha[i].insert(n+1);
    rep(i,n){
        Alpha[(int)(s[i]-'a')].insert(i);
    }

    int q;cin>>q;
    rep(i,q){
        int judge;cin>>judge;
        if(judge==1){
            int now;char Alphabet;cin>>now>>Alphabet;now--;
            Alpha[(int)(s[now]-'a')].erase(now);
            Alpha[(int)(Alphabet-'a')].insert(now);
            s[now]=Alphabet;
        }else{
            int ans=0;
            int l,r;cin>>l>>r;l--;r--;
            rep(j,26){//各Alphabetについて,それがl~rに含まれるか確認
                int right=*Alpha[j].lower_bound(l);
                if(right<=r)ans++;
            }
            cout<<ans<<endl;
        }
    }
}
        


Measured memory_bytes: 24196
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
typedef pair<int,int> P;

struct edge{int to,cost;};
vector<vector<edge>> G(10000);

int INF=pow(10,9);
//最短距離
vec d(10000);

void dijkstra(int s){
    priority_queue<P,vector<P>,greater<P>> que;
    fill(d.begin(),d.end(),INF);
    d[s]=0;
    que.push(P(0,s));

    while(!que.empty()){
        P p=que.top();que.pop();
        int v=p.second;
        if(d[v]<p.first) continue;
        for(auto e:G[v]){
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}

int main(){
    int N,M;cin>>N>>M;
    mat c(1010);int a[1010],b[1010];
    for(int i=0;i<M;i++){
        cin>>a[i]>>b[i];
        for(int j=0;j<b[i];j++){
            int C;cin>>C;C--;
            c[i].push_back(C);
        }   
    }
    for(int i=0;i<(1<<N);i++){
        for(int j=0;j<M;j++){
            int s=0;
            for(int k=0;k<b[j];k++){
                if(!(i & (1<<c[j][k])))
                    s+=(1<<c[j][k]);
            }
            if(s!=0)
                G[i].push_back((edge){i+s,a[j]});
        }
    }
    dijkstra(0);
    if(d[(1<<N)-1]!=INF)cout<<d[(1<<N)-1]<<endl;
    else cout<<-1<<endl;
    return 0;
}

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

string s1,s2;
int dp[3001][3001];
string sol="";

int main() {
    cin >> s1 >> s2;
    for (int i=1;i<=s1.size();i++) {
        for (int j=1;j<=s2.size();j++) {
            if (s1[i-1]==s2[j-1]) {
                dp[i][j]=dp[i-1][j-1]+1;
            }
            else {
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }

    int i=s1.size();
    int j=s2.size();
    while(i>0 && j>0) {
        if (dp[i][j]==dp[i-1][j]) {i--;}
        else if (dp[i][j]==dp[i][j-1]) {j--;}
        else {
            sol.push_back(s1[i-1]);
            i--;
            j--;
        }
    }
    for (int i=sol.size()-1;i>=0;i--) {cout << sol[i];}
    cout << endl;
}



Measured memory_bytes: 38828
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto s = readln.chomp;
  s[0..$-8].writeln;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define deb(x) cout<<#x<<" "<<x<<endl;  //for debugging variables 
#define check cout<<"check"<<endl; // checking 







void solve(){

int a,b,c;

cin>>a>>b>>c;

int k;
cin>>k;


while(k--){


if(a>=b){

	b = 2*b;
}
else if(b>=c){

	c = 2*c;
}






}


if(a<b&&b<c){

	cout<<"Yes"<<endl;
}
else{

	cout<<"No"<<endl;
}











}






int main(){




int t;
//cin>>t;

t=1;
while(t--){
solve();
}
	return 0;
} 

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};

int N;
ll L, T;
vector<ll> X;
vector<int> W;

int main(){
    scanf("%ld %ld %ld", &N, &L, &T);
    X.resize(N);  W.resize(N);
    rep(i,N) scanf("%ld %ld", &X[i], &W[i]);
//-------------------------------------------
    vector<ll> tmp(N);
    rep(i,N){
        if(W[i]==1) tmp[i] = (X[i]+T)%L;
        else tmp[i] = ((X[i]-T)%L+L)%L; //tmp[i] = (X[i]-T)%L;
    }

    sort(tmp.begin(), tmp.end());

    int cnt = 0;
    rep(i,N){
        if(W[i]==1) cnt += (X[i]+T)/L;
        else{
            if(T > X[i]){
                cnt -= (T-X[i])/L;
                if((X[i]-T)%L<0) cnt--;
            }
        }
    }
    int flag = (cnt%N+N)%N;
//-------------------------------------------
    for(int i = flag; i < N; i++) cout << tmp[i] << endl;
    for(int i = 0; i < flag; i++) cout << tmp[i] << endl;
}

Measured memory_bytes: 3200
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, a, b) for (int i = a; i < (b); i++)
#define FOR(i, n) for (int i = n; i >= 0; i--)
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define SIZE 100001
#define MOD 1000000007
#define INF 100000000
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  int n, p;
  cin >> n >> p;
  int a[51];

  REP(i, n) cin >> a[i];
  int b[51];

  REP(i, n) b[i] = a[i] % 2;

  long long c[51][51];
  c[0][0] = 1;
  c[1][0] = 1;
  c[1][1] = 1;
  for (int i = 1; i < 51; i++) {
    c[i][0] = 1;
    c[i][i] = 1;
    for (int j = 1; j < i; j++) {
      c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
    }
  }

  long long ans1, ans2;
  int count = 0;
  REP(i, n) {
    if (b[i] == 1) count++;
  }

  int other = n - count;

  if (p == 0) {
    ans1 = 0;
    for (int i = 0; i <= other; i++) {
      ans1 += c[other][i];
    }
    ans2 = 0;
    for (int i = 0; i <= count; i += 2) {
      ans2 += c[count][i];
    }

    cout << ans1 * ans2 << endl;
    return 0;
  } else {
    ans1 = 0;
    for (int i = 1; i <= count; i += 2) {
      ans1 += c[count][i];
    }

    ans2 = 0;
    if (count / 2 != 0)
      for (int i = 0; i <= other; i++) ans2 += c[other][i];

    if (count / 2 == 0)
      cout << 0 << endl;
    else
      cout << ans1 * ans2 << endl;
    return 0;
  }

  return 0;
}

Measured memory_bytes: 256
S=input()
T=input()
al=[chr(ord('a')+i) for i in range(26)]
sameS=[]
sameT=[]
 
for k in al:
    indexes=[i for i, x in enumerate(S) if x==k]
    sameS.append(indexes)
 
for k in al:
    indexes=[i for i, x in enumerate(T) if x==k]
    sameT.append(indexes)
 
if all([x in sameS for x in sameT]) and all([x in sameT for x in sameS]):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 19648
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<char>> hw(h, vector<char>(w));
    vector<vector<int>> cnt(h, vector<int>(w, -1));
    queue<pair<int, int>> que;
    rep(i, h) rep(j, w) {
        cin >> hw[i][j];
        if (hw[i][j] == '#') {
            que.push(make_pair(i, j));
            cnt[i][j] = 0;
        }
    }
    int dx[4] = {1, -1, 0, 0};
    int dy[4] = {0, 0, 1, -1};
    while(!que.empty()) {
        pair<int, int> now = que.front(); que.pop();
        rep(ri, 4) {
            int y = now.first + dy[ri];
            int x = now.second + dx[ri];
            if (y < 0 || y >= h || x < 0 || x >= w) continue;
            if (hw[y][x] == '#') continue;
            hw[y][x] = '#';
            cnt[y][x] = cnt[now.first][now.second] + 1;
            que.push(make_pair(y, x));
        }
    }
    int ans = 0;
    rep(i, h) rep(j, w) {
        ans = max(ans, cnt[i][j]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 16188
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(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 INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;

int main(){
    int N; cin >> N;
    
    vector<int> A(N);
    REP(i,N) cin >> A[i];

    vector<int> B(N);
    REP(i, N) cin >> B[i];
    
    vector<int> C(N-1);
    REP(i, N-1) cin >> C[i];

    std::vector<vector<int>> AB;
    int ans=0;
    REP(i,N){
        ans += B[A[i]-1];
        // cout << B[A[i]-1] << endl;
    }

    REP(i,N-1){
        if(A[i+1] - A[i] == 1){
            ans += C[A[i]-1];
        }
    }
    cout << ans << endl;

    // REP(i,N){
    //     ans += AB.at(i+1);
    // }
    // cout << AB.at(3) << endl;


}

Measured memory_bytes: 256
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][2];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < 2; j++) {
				d[i][j] = sc.nextInt();
			}
		}
		int count = 0;
		String s = "No";
		for(int i = 0; i < n; i++) {
			if(d[i][0]==d[i][1]) {
				count++;
			}
			else {
				count = 0;
			}
			if(count>=3) {
				s = "Yes";
			}
		}
		System.out.println(s);
	}
}

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

int main() {
  
  int n,a,b,c,d,x;
  long long la,lb,lc,lx;
  double da,db,dc;
  string s,ss,sss;
  
  double ans = 0;
  string anss = "";
  
  cin >> n >> a;
  vector<int> va(n);
  //vector<int> vb(n);
  //vector<int> vc(n-1);
  vector<vector<int>> data(n, vector<int>(a));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < a; j++) {
      cin >> data.at(i).at(j);
    }
  }
  //rep(i,0,n) cin >> vb.at(i);
  //rep(i,0,n-1) cin >> vc.at(i);
  //int ab [] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
  //int result3 = std::max({a, b, c});
//--------------------------------------------------------------------------------
int count = 0;
  for (int i = 0; i < n-1; i++) {
    for (int k = i+1; k < n; k++) {
      ans = 0;
      for (int j = 0; j < a; j++) {  
        ans += pow(abs(data.at(i).at(j)-data.at(k).at(j)),2);
      }
      ans = sqrt(ans);
      if(floor(ans)==ans) {
        count++;
      }
    }
  }
  cout << count << endl;
 // cout << fixed << setprecision(5) << ans << endl;

}

Measured memory_bytes: 256
//Radhe Radhe
#include<bits/stdc++.h>
#define godspeed  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define rep1(i,a,b)    for(ll i=a; i<=b; i++)
#define repVect(i,n)    for(ll i=0; i<sum.size(); i++)
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(7);
#define yes cout<<"Yes"<<'\n'
#define no cout<<"No"<<'\n'
using namespace std;

int main()
{
    godspeed
    ll  i,j,k,l,n,x,ans=0;
    string s;
    cin>>s;
    if(s[0]==s[1]&&s[2]==s[1])
        cout<<"Yes"<<endl;
    else if(s[3]==s[1]&&s[2]==s[1])
        cout<<"Yes"<<endl;
            else
                cout<<"No"<<endl;
                return 0;
}





Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
vector<string> A;
vector<string> B;
int N, M;
bool flag = false;
string answer = "No";

void search(vector<string> C, int y, int x) {
    int temp_x;
    int temp_y;
    temp_y = y;
    for (int i = 0; i < M; ++i) {
        temp_x = x;
        for (int j = 0; j < M; ++j) {
            if (temp_x < N && temp_y < N) {
                if (C[temp_y][temp_x] == B[i][j]) {
                    flag = true;
                    if (j == M - 1 && i == M - 1 & flag == true) {
                        answer = "Yes";
                    }
                } else {
                    flag = false;
                    break;
                }
            ++temp_x;
            }
        }
        ++temp_y;
        if (flag == false) break;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N >> M;
    A.resize(N);
    B.resize(M);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    for (int i = 0; i < M; ++i) {
        cin >> B[i];
    }

    for (int y = 0; y < N; ++y) {
      for (int x = 0; x < N; ++x) {
          search(A, y, x);
      }
    }
    cout << answer << endl;

    return 0;
}

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

int gcd (int a, int b){
  if(a == 0){
    return b;
  }
  if(b == 0){
    return a;
  }
  return gcd(b, a%b);
}

int main(){
  int n;
  cin >> n;
  vector<int> a(100005);
  for(int i=1; i<=n; i++){
    cin >> a.at(i);
  }
  vector<int> l(100005);
  for(int i=1; i<=n; i++){
    l.at(i) = gcd(l.at(i-1), a.at(i));
  }
  vector<int> r(100005);
  for(int i=n; i>=1; i--){
    r.at(i) = gcd(r.at(i+1), a.at(i));
  }
  int ans=0;
  for(int i=1; i<=n; i++){
    ans = max(ans, gcd(l.at(i-1), r.at(i+1)));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1408
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	static final int INF = (int)1e9 + 7;
	int N,Ma,Mb;
	int[] A,B,C;

	public int gcd(int x,int y){
		return y == 0 ? 1 : gcd(y,x%y);
	}

	public void solve() {
		N = nextInt();
		Ma = nextInt();
		Mb = nextInt();

		A = new int[N];
		B = new int[N];
		C = new int[N];

		for(int i = 0;i < N;i++){
			A[i] = nextInt();
			B[i] = nextInt();
			C[i] = nextInt();
		}

		int[][][] dp = new int[N+1][1000+10][1000+10];
		for(int i = 0;i < N + 1;i++){
			for(int j = 0;j < 1000 + 10;j++){
				for(int k = 0;k < 1000 + 10;k++){
					dp[i][j][k] = INF;
				}
			}
		}

		dp[0][0][0] = 0;
		for(int i = 0;i < N;i++){
			for(int j = 0;j < 1000+1;j++){
				for(int k = 0;k < 1000+1;k++){
					dp[i+1][j][k] = Math.min(dp[i+1][j][k], dp[i][j][k]);
					int a = j + A[i];
					int b = k + B[i];
					if(a >= 1010 || b >= 1010)continue;
					dp[i+1][a][b] = Math.min(dp[i+1][a][b],dp[i][j][k]+C[i]);
				}
			}
		}

		int ans = INF;

		for(int i = 1;i * Math.max(Ma, Mb) <= 1000;i++){
			ans = Math.min(ans,dp[N][i*Ma][i*Mb]);
		}
		if(ans == INF){
			out.println(-1);
		}else{
			out.println(ans);
		}
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 222784
#include<bits/stdc++.h>
using namespace std;
const int ms = 3e2+9;
double dp[ms][ms][ms], n;

double solve(int i, int j, int k){
  double N = n;
  if(i < 0 or j < 0 or k < 0)
    return 0;
  if(!i and !j and !k)
    return 0;

  double &ans = dp[i][j][k];
  if(ans != -1)
    return ans;

  double plates = i+j+k;

  ans = double(n)/plates;

  if(i){
    ans += (double(i)/plates)*solve(i-1,j,k);
  }

  if(j){
    ans += (double(j)/plates)*solve(i+1,j-1,k);
  }

  if(k){
    ans += (double(k)/plates)*solve(i,j+1,k-1);
  }

  return ans;
}
int sushi_plates_count[4], plate_size;
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> plate_size;
    sushi_plates_count[plate_size]++;
  }
  
  for(int i = 0; i < ms; i++)
    for(int j = 0; j < ms; j++)
      for(int k = 0; k < ms; k++)
        dp[i][j][k] = -1;
  
  int i = sushi_plates_count[1], j = sushi_plates_count[2], k = sushi_plates_count[3];

  cout<<setprecision(10)<<fixed<<solve(i, j, k)<<endl;
}

Measured memory_bytes: 230784
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int main(){
  double t,d;
  double t_a,t_b,d_a,d_b;
  cin>>t>>d>>t_a>>t_b>>d_a>>d_b;
  double min=100000;
  for(int i=0;i<=d;i+=d_a){
    for(int j=0;j<=d;j+=d_b){
      if(i+j==0 || i+j>d)continue;
      double nt=(t_a*i+t_b*j)/(i+j);
      if(abs(t-min)>abs(t-nt)){
	min=nt;
      }
    }
  }
  printf("%.10lf\n",abs(t-min));
  return 0;
}

Measured memory_bytes: 1240
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
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; }
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;}
const ll mod = 1000000007;
int main(){
  int N; cin >> N;
  vector<ll> A(N); rep(i,N) cin >> A[i];
  vector<ll> sums(N+1,0);
  rep(i,N) sums[i+1] = (sums[i] + A[i])%mod;
  ll ans = 0;
  rep(i,N){

    ans += A[i]*sums[i]%mod;
    ans %= mod;
  }
  cout << ans%mod << endl;
  return 0;
}


Measured memory_bytes: 6344
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<sstream>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; ++i)
#define per(i, a, n)  for(int i=n-1; i>=a; --i)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 1000000007
using namespace std;
typedef long long ll;

int main(){
  const int size = 5;
  ll N;  cin >> N;
  vector<ll> vehicle(size);
  rep(i, 0, size) cin >> vehicle[i];
  sort(all(vehicle));
  ll mini = vehicle[0];
  ll move = (N-1)/mini;
  ll time = move + 5;
  cout << time << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;

template <class Abel>
class BIT
{
public:
  using F=function<Abel(Abel,Abel)>;
  F f;
  int l;
  vector<Abel> bit;
  Abel m0;
  BIT(int maxidx,F fu,Abel m0):f(fu),l(maxidx),m0(m0)
  {
    bit.assign(l+1,m0);
  }
  void update(int idx,Abel val)
  {
    idx++;
    while(idx<=l)
    {
      bit[idx]=f(bit[idx],val);
      idx+=idx & -idx;
    }
  }
  Abel query(int idx)
  {
    Abel res=m0;
    while(idx>0)
    {
      res=f(bit[idx],res);
      idx-=idx& -idx;
    }
    return res;
  }
};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin>>n;
  vector<ll>h(n),b(n);
  BIT<ll> bit(n+10,[](ll a,ll b){return max(a,b);},0);
  rep(i,n)
  {
    cin>>h[i];
  }
  rep(i,n)
  {
    cin>>b[i];
  }
  rep(i,n)
  {
    bit.update(h[i],bit.query(h[i])+b[i]);
  }
  cout<<bit.query(n+1)<<endl;
  return 0;

}


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

typedef long long ll;

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

int sort(const void *a ,const void *b){
  return *(int*)a - *(int*)b;
}

int main(){

  int n,k,x,y;
  scanf("%d%d%d%d",&n,&k,&x,&y);

  int ans = 0;
  int i = 1;
  while(i <= n){
    if(i<=k) ans += x;
    else ans += y;
    i++;
  }

  printf("%d",ans);

  return 0;

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int mod = 1000000007;

int main() {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    int cnt[3];
    for (int i = 0; i < 3; i++) {
        cnt[i] = 0;
    }

    ll ans = 1;
    for (int i = 0; i < n; i++) {
        int k = 0;
        int m;
        for (int j = 0; j < 3; j++) {
            if (cnt[j] == a[i]) {
                k++;
                m = j;
            }
        }
        if (k == 0) {
            cout << 0 << endl;
            return 0;
        }
        ans = ans * k % mod;
        cnt[m]++;
    }

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

Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <vector>
#include <utility>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <forward_list>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <string>
#include <bitset>
#include <memory>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <cstdint>
#include <iomanip>
#include <tuple>
#include <random>

using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
int main(void) {
    ll n[2][3],k;
    cin >> n[0][0] >> n[0][1] >> n[0][2] >> k;
    for(int i = 0 ; i < k%2;i++) {
        for(int ii = 0;ii < 3;ii++)
            n[1][ii] = n[0][0] + n[0][1] + n[0][2] - n[0][ii];
        for(int ii = 0; ii < 3;ii ++)
            n[0][ii] = n[1][ii];
    }
    if(abs(n[0][0] - n[0][1]) > pow(10,18))
        cout << "Unfair" << endl;
    else
        cout << n[0][0] - n[0][1] << endl;
    return 0;
}


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

int main() {
  priority_queue<int,vector<int>,greater<int> > sort;
  for (int i=0; i<3; i++) {
    int x;
    cin >> x;
    sort.push(x);
  }
  while (!sort.empty()) {
    cout << (sort.size()==3?"":" ") << sort.top() << flush;
    sort.pop();
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3112
#ifndef ___Class_RangeTree
#define ___Class_RangeTree

// ------ Includes ------ //
#include <limits>
#include <vector>
#include <algorithm>

template<typename Type> class RangeTree {
private:
	int size_;
	std::vector<std::vector<Type> > dat;
	std::vector<std::vector<int> > vl;
	inline int query_(int a, int b, Type x, int k, int l, int r, int e) {
		// Find range [a, b) : value < x : Now k-th node and the range is [l, r) and e integers below x in the range
		if (r <= a || b <= l || e == 0) return 0;
		if (a <= l && r <= b) return e;
		int lc = query_(a, b, x, k << 1, l, (l + r) >> 1, vl[k][e - 1]);
		int rc = query_(a, b, x, k << 1 | 1, (l + r) >> 1, r, e - vl[k][e - 1]);
		return lc + rc;
	}
public:
	RangeTree() : size_(0), dat(std::vector<Type>()) {};
	template<class T>
	RangeTree(T begin_, T end_) {
		int n = (end_ - begin_);
		for (size_ = 1; size_ < n; size_ <<= 1);
		dat.resize(size_ << 1);
		vl.resize(size_);
		for (int i = 0; i < n; i++) dat[i + size_].push_back(*(begin_ + i));
		for (int i = size_ - 1; i > 0; i--) {
			dat[i].resize(dat[i << 1].size() + dat[i << 1 | 1].size());
			vl[i].resize(dat[i].size());
			int cl = 0;
			for (int j = 0; j < dat[i].size(); j++) {
				if (j - cl == dat[i << 1 | 1].size() || (cl != dat[i << 1].size() && dat[i << 1][cl] < dat[i << 1 | 1][j - cl])) dat[i][j] = dat[i << 1][cl++];
				else dat[i][j] = dat[i << 1 | 1][j - cl];
				vl[i][j] = cl;
			}
		}
	}
	inline int size() { return size_; }
	inline int query(int l, int r, Type x) {
		// Find range [a, b) : value < x
		int ptr = lower_bound(dat[1].begin(), dat[1].end(), x) - dat[1].begin();
		return query_(l, r, x, 1, 0, size_, ptr);
	}
};

#endif

#include <cstdio>
#include <vector>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int n, q, l, r, e;
int main() {
	scanf("%d", &n);
	vector<int> a(n);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	RangeTree<int> seg(a.begin(), a.end());
	scanf("%d", &q);
	while (q--) {
		scanf("%d%d%d", &l, &r, &e); l--;
		int x1 = seg.query(l, r, min(a[l], a[r - 1]) - e);
		int x2 = seg.query(l, r, max(a[l], a[r - 1]) + e + 1);
		printf("%d\n", (r - l) - (x2 - x1));
	}
	return 0;
}

Measured memory_bytes: 32216