akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var cin = new Scanner2();
			int n = cin.Int();
			int k = cin.Int();
			int[] pi = cin.ArrayInt(n);

			int m = 1001;
			double[] exp = new double[m];
			for (int i = 1; i < m; i++) {
				double temp = 0;
				for (int j = 1; j <= i; j++) {
					temp += j;
				}

				exp[i] = temp / i;
			}

			double sum = 0;
			for (int i = 0; i < k; i++) {
				sum += exp[pi[i]];
			}

			double ans = sum;
			for (int i = k; i < n; i++) {
				sum -= exp[pi[i - k]];
				sum += exp[pi[i]];
				ans = Math.Max(ans, sum);
			}

			Console.WriteLine(ans);
		}
	}

	public class Scanner2
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private readonly string filePath_;
		private readonly Func<string> reader_;
		private string[] buf_;
		private int index_;

		public Scanner2(string file = "")
		{
			if (string.IsNullOrWhiteSpace(file)) {
				reader_ = Console.ReadLine;
			} else {
				filePath_ = file;
				var fs = new StreamReader(file);
				reader_ = fs.ReadLine;
			}
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = reader_();
			while (st == "") {
				st = reader_();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}

		public void Save(string text)
		{
			if (string.IsNullOrWhiteSpace(filePath_)) {
				return;
			}

			File.WriteAllText(filePath_ + "_output.txt", text);
		}
	}
}

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

int main() {
    int A, B;
    cin >> A >> B;
    
    int count = A + A - 1;
    count = max(count, A + B);
    count = max(count, B + B - 1);

    cout << count << endl;
    return 0;  

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#define max(a,b)((a)>=(b)?(a):(b))
int dp[1001],w[1000],v[1000],W,N;
int main() {
	for(int Case=1;scanf("%d",&W),W;Case++) {
		memset(dp,0,sizeof(dp));
		scanf("%d",&N);
		for(int i=0;i<N;i++) {
			scanf("%d,%d",&v[i],&w[i]);
		}
		for(int i=0;i<N;i++) {
			for(int j=W;j>=w[i];j--) {
				dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
			}
		}
		int _w;
		for(_w=W-1;_w>=0;_w--) {
			if(dp[_w]!=dp[W]) break;
		}
		printf("Case %d:\n",Case);
		printf("%d\n%d\n",dp[W],_w+1);
	}
}

Measured memory_bytes: 1040
# div2019B - RGB Boxes
r, g, b, n = list(map(int, input().rstrip().split()))
cnt = 0
for i in range(n // r + 1):
    for j in range((n - r * i) // g + 1):
        if (n - i * r - j * g) % b == 0:
            cnt += 1
print(cnt)

Measured memory_bytes: 2940
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    map<string, ll> ma;
    for (int i = 0; i < n; ++i) {
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
        ma[s[i]]++;
    }
    ll ret = 0;
    for (auto &p : ma) {
        ret += p.second * (p.second - 1LL) / 2LL;
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 18176
/*  -*- coding: utf-8 -*-
 *
 * e.cc: E - Gluttony
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;
const long long MAX_D = 1000000000000LL;

/* typedef */

typedef long long ll;

/* global variables */

int as[MAX_N], fs[MAX_N];

/* subroutines */

ll check_k(int n, ll maxd) {
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    ll af = (ll)as[i] * fs[i];
    if (af > maxd) sum += as[i] - maxd / fs[i];
  }
  return sum;
}

/* main */

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

  for (int i = 0; i < n; i++) scanf("%d", as + i);
  for (int i = 0; i < n; i++) scanf("%d", fs + i);

  sort(as, as + n);
  sort(fs, fs + n, greater<int>());

  ll l = -1, r = MAX_D;
  while (l + 1 < r) {
    ll d = (l + r) / 2;
    if (check_k(n, d) <= k) r = d;
    else l = d;
  }

  printf("%lld\n", r);
  return 0;
}


Measured memory_bytes: 1792
//Love and Freedom.
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#define ll long long
#define db double
#define inf 20021225
#define N 1000010
using namespace std;
int read()
{
	int s=0,t=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')	t=-1; ch=getchar();}
	while(ch>='0' && ch<='9')	s=s*10+ch-'0',ch=getchar();
	return s*t;
}
struct node{int l; db t;}w[N];
int t[N],v[N],n,L,sum; db T;
int main()
{
	n=read(),L=read(); int l=1,r=0;
	for(int i=1;i<=n;i++)
	{
		t[i]=read(),v[i]=read();
		while(sum+v[i]>L)
		{
			int tmp=min(w[l].l,sum+v[i]-L);
			sum-=tmp; T-=w[l].t*tmp; w[l].l-=tmp;
			if(!w[l].l)	l++;
		}
		w[++r]=(node){v[i],(db)t[i]};
		T+=(db)v[i]*t[i]; sum+=v[i];
		while(l<r&&w[r].t<w[r-1].t)
		{
			w[r-1].t=(w[r-1].l*w[r-1].t+w[r].l*w[r].t)/(w[r-1].l+w[r].l);
			w[r-1].l+=w[r].l; r--;
		}
		printf("%lf\n",T/sum);
	}
	return 0;
}


Measured memory_bytes: 24704
"""AtCoder Grand Contest 016 - Shrinking.

https://agc016.contest.atcoder.jp/tasks/agc016_a

"""


import string

def solve(s):
    ans = float('inf')
    for char in string.ascii_lowercase:
        new_str = s
        count = 0
        while len(set(new_str)) > 1:
            tmp = ''
            for j in range(len(new_str) - 1):
                tmp += char if char in new_str[j:j+2] else new_str[j]
            new_str = tmp
            count += 1
        ans = min(ans, count)
    return ans


def main():
    s = input().strip()
    result = solve(s)
    print(result)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3772
#include <iostream>
#include <string>
#include <vector>

bool check1(const std::string s)
{
    // sは回文であるか
    const int l = s.length();
    
    for (int i = 0; i < l / 2; i++) {
        if (s[i] != s[l - i - 1]) {return false;}
    }

    return true;
}

bool check2(const std::string s)
{
    // 1文字目から(N-1)/2文字目が回文である
    const int n = s.size();
    const std::string trim = s.substr(0, (n - 1) / 2);

    return check1(trim);
}

bool check3(const std::string s)
{
    const int n = s.size();
    const int start = (n + 3) / 2 - 1;
    const std::string trim = s.substr(start, n - start);

    return check1(trim);
}

int main(int argc, char *argv[])
{
    std::string s;

    std::cin >> s;

    const bool ans = check1(s) && check2(s) && check3(s);

    if (ans) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
import sys

mod = 10**9 + 7

n = int(input())
li = list(map(int,input().split()))
li.sort()
cnt = 0

if n % 2 == 1:
    for i,s in enumerate(li):
        if i == 0 :
            if s != 0:
                print(0)
                sys.exit()
        else:
            if i % 2 == 1:
                if i + 1 != s:
                    print(0)
                    sys.exit()
            else:
                if i != s:
                    print(0)
                    sys.exit()
    res = (n-1)//2
    print((2**res)%mod)
    
else:
    for i,s in enumerate(li):
        if i % 2 == 1:
            if i != s:
                print(0)
                sys.exit()
        else:
            if i + 1 != s:
                print(0)
                sys.exit()

    res = n//2
    print((2**res)%mod)


Measured memory_bytes: 14008
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
#include <chrono>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

#define _ << " " <<
#define all(v) v.begin(), v.end()
#define sp(n) fixed << setprecision(n)
#define ff first
#define ss second

using namespace std;
//using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const ll mod = 998244353;
const double eps = DBL_EPSILON;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef LOCAL_DEBUG
    freopen("input.txt", "r", stdin);
#endif
    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    for (int& i : a) cin >> i;
    int ans = k;
    for (int i = 0; i < n; i++) ans = min(ans, k - (a[(i + 1) % n] - a[i] + k) % k);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int n = s.size();
    if(s[0] == '0' || s[n-1] == '1' || s[n-2] == '0')
    {
        cout << -1 << endl;
        return 0;
    }
    int j = n-3;
    for(int i = 1; i < n-3; i++)
    {
      if(s[i] != s[j])
      {
        cout << -1 << endl;
        return 0;
      }
      j--;
    }
      

    int now = 1;
    for(int i = 0; i < n-1; i++)
    {
        cout << now << " " << i+2 << endl;
        if(s[i] == '1')
        {
            now = i+2;
        }
    }
}



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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define inn(x, y) int x,y;cin>>x>>y
#define innn(x, y, z) int x,y,z;cin>>x>>y>>z
#define bit(n) (1<<(n))

#define out(x) cout<<(x)<<endl;
#define err(x) cerr<<(x)<<endl;
#define errr(x,y) cerr<<(x)<<" "<<(y)<<endl;
#define errrr(x,y,z) cerr<<(x)<<" "<<(y)<<" "<<(z)<<endl;

#define rep(i,n) for (int i=0;i<(n);i++)
#define repp(i,n) for (int i=1;i<=(n);i++)
#define reppp(j, i, n) for (int j=i+1; j<n; j++)

#define lim5 200002
#define lim9 1000000002

#define deg(rad) (((rad)/2/M_PI)*360)
#define mid(min, max) ((min + max) / 2)

int main() {
	ll h = 0, cnt = 0, n = 1;
	cin >> h;

	for (;;) {
		if (!h) {
			out(cnt);
			return 0;
		}

		h /= 2;
		cnt += n;
		n *= 2;
	}

	return 0;
}


Measured memory_bytes: 256
nums = [int(n) for n in input().split()]
nums = sorted(nums)

step = 0

if (3 * max(nums) % 2) != (sum(nums) % 2):
    nums[1] += 1
    nums[2] += 1 
    step += 1

d1 = (nums[2] - nums[1])
d2 = nums[2] - (nums[0] + d1)

if d2 % 2 == 0:
    d2 = d2 // 2
else:
    d2 =  d2 // 2 + 1
step += (d1 + d2)

print(step)

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){
    char s[200];
    int a=0;
    scanf("%s",s);
    for(int i=0;s[i]!='\0';i++){
        if(i>=strlen(s)-i-1){break;}
        if(s[i]!=s[strlen(s)-i-1]){a++;}
    }
    printf("%d",a);
}


Measured memory_bytes: 128
def main():
    n = int(input())
    results = {"AC": 0, "WA": 0, "TLE": 0, "RE": 0}
    for i in range(n):
        s = input()
        results[s] += 1

    for result, num in results.items():
        print("{} x {}".format(result, num))


if __name__ == "__main__":
    main()


Measured memory_bytes: 9180
from sys import stdin


def main():
    _ = input()
    T, A = [int(x) for x in stdin.readline().split()]
    H = [int(x) for x in stdin.readline().split()]
    h_list = []

    for h in H:
        h_list.append(abs(T - h * 0.006 - A))

    print(h_list.index(min(h_list)) + 1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    random_device seed_gen;
    mt19937_64 rnd(seed_gen());
    uniform_int_distribution<int> dist_d(0, 364), dist_q(0, 25);

    int d;
    cin >> d;
    vector<int> c(26);
    rep(i, 26)cin >> c[i];
    vector<vector<int>> s(d, vector<int>(26));
    rep(i, d)rep(j, 26)cin >> s[i][j];

    vector<int> t(d);
    rep(i, d){
        t[i] = dist_q(rnd);
    }

    int m = 50000;

    vector<set<int>> last(26);
    rep(i, 26){
        last[i].insert(-1);
        last[i].insert(d);
    }
    rep(i, d)last[t[i]].insert(i);
    int sum = 0;
    rep(i, d){
        sum += s[i][t[i]];
        rep(j, 26){
            if(last[j].find(i) == last[j].end()){
                auto itr = lower_bound(last[j].begin(), last[j].end(), i);
                itr--;
                int day = i - *itr;
                sum -= c[j] * day;
            }
        }
    }
    
    rep(i, m){
        int day = dist_d(rnd);
        int que = dist_q(rnd);
        int diff = 0;
        
        int cont;
        rep(j, 26){
            if(last[j].find(day) != last[j].end()){
                cont = j;
                break;
            }
        }
        diff += s[day][que] - s[day][cont];
        auto itr1 = last[cont].find(day);
        auto itr2 = lower_bound(last[que].begin(), last[que].end(), day);
        int x = *itr1;
        int y = *itr2;
        int dx = day - *(--itr1);
        int dy = day - *(--itr2);
        itr1++; itr1++;
        itr2++;
        diff -= c[cont] * dx * (*itr1 - day);
        diff += c[que] * dy * (*itr2 - day);
        if(diff > 0){
            last[cont].erase(day);
            last[que].insert(day);
            t[day] = que;
            sum += diff;
        }
    }
    
    rep(i, d){
        cout << t[i] + 1 << endl;
    }
    
    
}

Measured memory_bytes: 3708
N=int(input())
A=input()
B=input()
C=input()
ans=0
for i in range(N):
    S=set([A[i],B[i],C[i]])
    if len(S)==1:
        continue
    elif len(S)==2:
        ans+=1
    else:
        ans+=2
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
	int m,f,r;
	string a;
	while(1)
	{
		cin>>m>>f>>r;
		if(m==-1&&f==-1&&r==-1) break;
		if(m==-1 || f==-1) a="F";
		else if (m+f>=80) a="A";
		else if (m+f>=65) a="B";
		else if (m+f>=50) a="C";
		else if (m+f<30) a="F";
		else if (r>=50) a="C";
		else a="D";
		cout<<a<<endl;
	}	
	return 0;
}


Measured memory_bytes: 3140
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
using namespace std;



int main() {
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    int ans = 0;
    set<int> st;
    for (int i = 0; i < n; i++) {
    	int x;
    	cin >> x;
    	if (x < 3200) st.insert(x / 400);
    	else ans++;
	}
	int mmin;
	if (st.size() == 0) mmin = 1;
	else {
	    mmin = st.size();
	}
	cout << mmin << " " << (int)st.size() + ans;
	
    return 0;
}


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

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def main():
    a, b = map(int, input().split())
    if (a * b) % 2 == 0:
        print("Even")
    else:
        print("Odd")


if __name__ == '__main__':
    main()


Measured memory_bytes: 4080
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;


int N, M;

long long int MOD = 1000000007;

long long int p[1000005];

long long int POW(long long int a, long long int k) {
	if (k == 0) { return 1; }
	if (k == 1) { return a; }

	if (k % 2 == 1) { return (POW(a, k - 1)*a) % MOD; }

	long long int tmp = POW(a, k / 2);

	return (tmp*tmp) % MOD;
}

long long int inv_p[1000006];

long long int C(int n, int m) {
	long long int ret;
	ret = (p[n] * inv_p[m]) % MOD;

	ret *= inv_p[n-m];
	ret %= MOD;
	return ret;
}

long long int P(int n, int m) {
	return (p[n] * inv_p[n-m]) % MOD;
}


int main(void) {

	cin >> N >> M;

	

	p[0] = 1;
	p[1] = 1;
	for (long long int i = 1; i <= N+M; i++) {
		p[(int) i] = p[(int)i - 1] * i; p[(int)i] %= MOD;
	}

	for (long long int i = 0; i <= N+M; i++) {
		inv_p[i] = POW(p[i], MOD - 2);
	}

	

	long long int ans = (P(M, N)*P(M, N)) % MOD;

	for (int k = 1; k <= N; k++) {
		
		long long int tmp = (C(N, k)*P(M, k)) % MOD;

		tmp *= P(M - k, N - k); tmp %= MOD;
		tmp *= P(M - k, N - k); tmp %= MOD;

		if (k % 2 == 1) {
			ans += MOD - tmp; ans %= MOD;
		}
		else {
			ans += tmp; ans %= MOD;
		}
		
	}

	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 19148
// Best practice

#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// #include <functional> // for less

#define int         long long
#define pb          push_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define pii 		pair<int,int>
#define psi 		pair<string,int>
#define vi 			vector<int>
#define vpii  		vector<pii>
#define vvi 		vector<vi>
#define sz(x)	    (int)(x).size()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD         1000000007
#define hell        998244353
#define output(x)   cout << (x ? "YES" : "NO")<<endl;
using namespace std;
// using namespace __gnu_pbds;

// typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> pbds;

// #define fbo find_by_order
// #define ook order_of_key

// Code from Here -------------------------------------------------------------------------------


signed main() {
	tezz

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;
	cin >> n;
	for (int a = -1000; a <= 1000; a++) {
		for (int b = -1000; b <= 1000; b++) {
			if ( (a * a * a * a * a - b * b * b * b * b)  == n) {
				cout << a << " " << b << endl;
				return 0;
			}
		}
	}

	return 0;
}


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

int main(){
    int h,w;
    
    while(1){
        cin >> h >> w;
        if(h==0 && w==0) break;
        for(int i=1; i<=h; i++){
            for(int j=1; j<=w; j++)
                cout << '#';
            cout << endl;
        }
        cout << endl;
    };
    return 0;
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n,a[100000],b[100000],as,bs,ans;
bool memo[100000], f;
vector<pair<int,int>> v;

signed main() {
    cin >> n;
    rep(i,n) {
        cin >> a[i] >> b[i];
        v.pb(mp(a[i],i));
        v.pb(mp(b[i],i));
        as += a[i];
        bs += b[i];
    }
    sort(all(v));
    rep(i,n) {
        int k = v[i].se;
        ans += v[i].fi;
        if (memo[k]) f=true;
        memo[k] = true;
    }
    if (!f) {
        if (v[n-1].se == v[n].se) {
            int hoge = v[n+1].fi - v[n-1].fi;
            int huga = v[n].fi - v[n-2].fi;
            ans += min(hoge, huga);
        }
        else ans += v[n].fi - v[n-1].fi;
    }
    cout << min(ans, min(as,bs)) << endl;
}





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

using namespace std;

const int Mod = 1e9 + 7, Nmax = 2e5 + 5, inv2 = 5e8 + 4;
typedef long long ll;

struct state
{
    int a, b, c;
};

deque<state> dp[Nmax];
vector<int> v[Nmax];
int n, dad, ans = 0;

void add_to(int &a, int b) { a+=b; if(a>=Mod) a-=Mod; }
void inm_to(int &a, int b) { a = (ll) a*b%Mod; }

void update(deque<state> &A, deque<state> &B)
{
    int n, m;
    ll x, y, z;
    for(n = m = 0; m < B.size(); ++n, ++m)
    {
        x = (ll) A[n].a * B[m].a; x %= Mod;
        y = (ll) A[n].a * B[m].b + (ll) A[n].b * B[m].a; y %= Mod;
        z = (ll) A[n].c + (ll) A[n].b * B[m].b; z %= Mod;

        A[n] = {x, y, z};
    }
}

void dfs(int node)
{
    if(v[node].empty())
    {
        dp[node].push_front({inv2, inv2, 0});
        return;
    }

    int xson = n+1;
    for(auto son : v[node])
    {
        dfs(son);
        if(dp[son].size() > dp[xson].size()) xson = son;
    }

    swap(dp[node], dp[xson]);

    int cat = 0, i;
    for(auto son : v[node])
        if(son != xson)
        {
            cat = max(cat, (int)dp[son].size());
            update(dp[node], dp[son]);
        }

    for(i=0; i<cat; ++i)
        add_to(dp[node][i].a, dp[node][i].c), dp[node][i].c = 0;

    dp[node].push_front({inv2, inv2, 0});
}

int main()
{
    cin.sync_with_stdio(false);

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

    dfs(0);
    for(auto el : dp[0]) add_to(ans, el.b);
    for(i=0; i<=n; ++i) inm_to(ans, 2);

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 237044
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(ReadLine());
        var A = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        var ans = A.Distinct().Count() == A.Length;

        WriteLine(ans ? "YES" : "NO");
    }
}


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

int H,W,N;
int X[200010],Y[200010],inf = 1e9;
vector<vector<int>> v(200010);

int main(){
	cin >> H >> W >> N;
	for(int i=1;i<=N;i++){
		cin >> X[i] >> Y[i];
		v[Y[i]].push_back(X[i]);
	}
	for(int i=1;i<=W;i++){
		v[i].push_back(H+1); v[i].push_back(1);
		sort(v[i].begin(),v[i].end());
	}
	int ans = inf,y[W+2] = {};
	y[1] = 1;
	for(int i=1;i<=W;i++){
		for(int j=0;j<v[i].size()-1;j++){
			if(v[i][j]<=y[i] && y[i]<v[i][j+1]){
				ans =  min(ans,v[i][j+1]-1);
				break;
			}
		}
		if(i==W) continue;
		y[i+1] = H;
		for(int j=1;j<v[i+1].size();j++){
			if(y[i]+1<v[i+1][j]){
				y[i+1] = y[i]+1;
				break;
			}else y[i] = max(v[i+1][j],y[i]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 13824
#include <iostream>

using namespace std;

int cnt;
int dp[100][100];

void rec(int left){
    if (left < 0){
        return;
    }
    if (left == 0){
        cnt++;
        return;
    }

    rec(left-1);
    rec(left-2);
    rec(left-3);

}

int main(int argc, char const *argv[]){
    int n;

    while (cin>>n, n){
        cnt = 0;
        int ans = 0;
        rec(n);
        ans = cnt / 3650;
        cout<<ans+1<<endl;       
    }

    return 0;
}

Measured memory_bytes: 3008
#include <cstdio>
#include <cstdlib>
#include <iostream>

using namespace std;

int main() {
	char s[3];
	cin >> s[0] >> s[1] >> s[2];

	switch (atoi(s)) {
		case 110:
		case 001:
			printf("Open\n");
			break;
		default:
			printf("Close\n");
	}
}

Measured memory_bytes: 1104
#include<iostream>
using namespace std;
int main(){
  int a,ans=0;
  cin>>a;
  int b[a];
  for(int i=0;i<a;i++)
    cin>>b[i];
  int c;
  cin>>c;
  for(int i=0;i<c;i++){
    int d,e,f;
    cin>>d>>e;
    f=b[d-1];
    b[d-1]=e;
    for(int i=0;i<a;i++)
      ans+=b[i];
    cout<<ans<<endl;
    ans=0;
    b[d-1]=f;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void serch(int n,int now)
{
    if(n==1)cout<<now<<endl;
    else if(n%2==0)serch(n/2,now+1);
    else serch(n*3+1,now+1);
}
int main()
{
    int n;
    while(cin>>n,n)serch(n,0);
}

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

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define EPS (1e-5)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")



signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int K, A, B;
	
	cin>>K>>A>>B;
	
	 if(A < B){
		int ans = 0;
		
		if(K < A){
			cout<<1+K<<endl;
			return 0;
		}
		K -= A-1;
		if(K%2) ans++;
		// cout<<ans<<" K = "<<K<<" "<<(K/2)<<" "<<B-A<<" + "<<A<<endl;
		ans += (K/2)*(B-A)+A;
		cout<<max(ans,1+K+A-1)<<endl;
	} else {
		cout<<1+K<<endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long; 
using vpii = vector<pair<int, int>>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep1(i, n) for (int i = 1; i < (int)n; i++)
ll inf = 1e9+7;

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

ll lcm(ll a, ll b){
  return (a/gcd(a,b))*b;
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  ll x;
  cin >> x;
  auto f = [](int n){ return n*(n+1)/2;};
  for(ll i = 1; i <= x; ++i){
    if(f(i) >= x){cout << i << "\n"; return 0;}
  }
  
  return 0;
}   

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

// GCD, LCM
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;}

int main()
{
    int ans=0;
    string S,T;
    cin>>S>>T;

    for(int i=0;i<S.length();i++){
        if(S[i]!=T[i])ans++;
    }
    cout<<ans<<endl;
    
    return 0;
}

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

typedef long long ll;

int main() {

// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    
    int h = 0, w = 0, k = 0;
    cin >> h >> w >> k;

    char arr[h][w];
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            cin >> arr[i][j];
        }
    }

    int ans = 0;
    for(int i = 0; i < pow(2, h); i++) {
        for(int j = 0; j < pow(2, w); j++) {
            int cnt = 0;
            for(int k = 0; k < h; k++) {
                if(i >> k & 1) continue;
                for(int l = 0; l < w; l++) {
                    if(j >> l & 1) continue;
                    if(arr[k][l] == '#') cnt++;
                }
            }
            if(cnt == k) ans++;
        }
    }

    cout << ans << endl;


    return 0;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j

static const int MAX = 1000007;
static const int WHITE = 0;
static const int BLACK = 1;

vector<int> adj[MAX];
int color[MAX];

int H, W;

queue<int> que;
queue<int> que2;

int solve() {
  int ans = -1;

  while(!que.empty() || !que2.empty()) {
    ans++;
    if (que2.empty()) {
      while(!que.empty()) {
        int u = que.front();
        que.pop();
        rep(i, 0, adj[u].size()) {
          int v = adj[u][i];
          if (color[v] == BLACK) continue;
          color[v] = BLACK;
          que2.push(v);
        }
      }
    } else {
      while(!que2.empty()) {
        int u = que2.front();
        que2.pop();
        rep(i, 0, adj[u].size()) {
          int v = adj[u][i];
          if (color[v] == BLACK) continue;
          color[v] = BLACK;
          que.push(v);
        }
      }
    }
  }
  return ans;
};

int main() {
  cin >> H >> W;
  char A;
  rep(i, 0, H) {
    rep(j, 0, W) {
      cin >> A;
      int nodeNum = i * W + j;
      if ((nodeNum + 1) % W != 0) adj[nodeNum].pb(nodeNum + 1);
      if (nodeNum % W != 0) adj[nodeNum].pb(nodeNum - 1);
      if (nodeNum >= W) adj[nodeNum].pb(nodeNum - W);
      if (nodeNum < (H - 1) * W) adj[nodeNum].pb(nodeNum + W);

      if (A == '.') {
        color[nodeNum] = WHITE;
      }
      if (A == '#') {
        color[nodeNum] = BLACK;
        que.push(nodeNum);
      }
    }
  }
  int ans = solve();
  cout << ans << endl;
};


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

struct edge{
	int u , v , w ;
};

vector<edge> E ;
int n , p[100010] ;

bool operator < (edge A , edge B){
	return A.w < B.w ;
} 

int Find(int x)
{
	if(p[x] == x)return x ;
	return p[x] = Find(p[x]) ;
}

void Union(int x , int y){
	p[Find(x)] = p[y] ;
}

long long int kruskal()
{
	long long int ret = 0 ;

	for(int i = 0 ; i <= n ; i++)p[i] = i ;

	for (edge x : E){
		if(Find(x.u) == Find(x.v))continue ;

		Union(x.u , x.v) ;
		ret += (long long)x.w ;
	}
	return ret ;
}

int main(int argc, char const *argv[])
{
	pair<int , int> x[100010] , y[100010] ;

	scanf("%d" , &n) ;

	for(int i = 0 ; i < n ; i++){
		scanf("%d %d" , &x[i].first , &y[i].first) ;
		x[i].second = y[i].second = i+1 ; 
	}

	sort(x , x+n) ;
	sort(y , y+n) ;

	edge a ;

	for (int i = 0 ; i < n-1 ; i++){
		a.u = x[i].second ;
		a.v = x[i+1].second ;
		a.w = x[i+1].first-x[i].first ;
		E.push_back(a) ;
	}

	for (int i = 0 ; i < n-1 ; i++){
		a.u = y[i].second ;
		a.v = y[i+1].second ;
		a.w = y[i+1].first-y[i].first ;
		E.push_back(a) ;
	}

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

	printf("%lld\n", kruskal());

	return 0;
}


Measured memory_bytes: 6516
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Y = sc.nextInt();
		sc.close();
		
		int k;
		for(int i=0; i<=N; i++) {
			for(int j=0; j<=N-i; j++) {
				k = N - i - j;
				if(10000*i + 5000*j + 1000*k == Y) {
					System.out.println(i+" "+j+" "+k);
					return;
				}
			}
		}

		System.out.println("-1 -1 -1");
	}
}

Measured memory_bytes: 22868
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long ll;
const ll M=998244353;
int h[1000005],n,i;
int main(){
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d",&h[i]);
	h[1]--;
	for(i=2;i<=n;i++)
		if(h[i]>h[i-1])
			h[i]--;
	for(i=1;i<n;i++)
		if(h[i]>h[i+1])
		{
			printf("No");
			return 0;
		}
	printf("Yes");
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ull unsigned ll
#define pb push_back
#define popb pop_back
#define mt make_tuple
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair <int,int>
#define piii pair <pii,int>
#define piiii pair <pii,pii>
#define plll pair <pair <ll, ll>, ll>
#define rep0(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(i,n) for(ll i=1;i<=(ll)n;i++)
#define rep(i,x,y) for(ll i=(ll)x;i<=(ll)y;i++)
#define reprev(i,n) for(ll i=(ll)n;i>=0;i--)
#define all(c) c.begin(),c.end()
#define print(a) rep0(i,a.size()) cout << a[i] << " "
#define hi() cout << "\nHello, I am error. Can you find me? :):):)\n"
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_eppoch().count())
 
using namespace __gnu_pbds;
using namespace std;
using ordered_set =  tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>;

const int mod = 1e9+9;
const long double pi = acos(-1);

// FOR DEBUGGING
vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}

void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", ";
	else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifndef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

ll power(ll x, ll y){
	x %= mod;
	ll ans = 1;
	while(y){
		if(y&1) ans = (ans*x)%mod;
		y /= 2;
		x = (x*x)%mod;
	}
	return ans;
}

void solve(){

	int a,b,c,d;
	cin >> a >> b >> c >> d;
	while(a>0 && c>0){
		c -= b;
		if(c<=0){
			cout << "Yes";
			break;
		}
		a -= d;
		if(a<=0){
			cout << "No";
			break;
		}
	}

	return;
}

int main(){

	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int TC = 1,t = 0;
	// cin >> TC;
	while(t++ < TC){
		// cout << "Case #" << t << ": ";
		solve();
		// cout << "\n";
	}

	cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

	return 0; 
}

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

int main() {
    int x,t;
    cin >> x >> t;
    if(x>t) cout << x - t;
    else cout << 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <limits.h>
int main() {
  int a[3];
  for (int i = 0; i < 3; i++) scanf("%d", a + i);
  int min_a = INT_MAX;
  int max_a = INT_MIN;
  for (int i = 0; i < 3; i++) {
    if (min_a > a[i]) min_a = a[i];
    if (max_a < a[i]) max_a = a[i];
  }
  printf("%d\n", max_a - min_a);
  return 0;
}

Measured memory_bytes: 128
a = gets.chomp.to_i
b = gets.chomp.to_i
c = gets.chomp.to_i
d = gets.chomp.to_i
e = gets.chomp.to_i

x = 10
a2 = a%10
if a2 != 0 && a2 < x
  x = a2
end
b2 = b%10
if b2 != 0 && b2 < x
  x = b2
end
c2 = c%10
if c2 != 0 && c2 < x
  x = c2
end
d2 = d%10
if d2 != 0 && d2 < x
  x = d2
end
e2 = e%10
if e2 != 0 && e2 < x
  x = e2
end
answer = (a+9)/10*10 + (b+9)/10*10 + (c+9)/10*10 + (d+9)/10*10 + (e+9)/10*10 - 10 + x
puts answer

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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()

using ll = std::int64_t;
using vint = std::vector<int>;
using vll = std::vector<ll>;
using pint = std::pair<int, int>;

constexpr std::int32_t INF = 1001001001;

void Main() {
    ll n;
    cin >> n;

    if (n == 1) {
        cout << 0 << endl;
        return;
    }
    else {
        cout << n * (n - 1) / 2 << endl;
        return;
    }
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}



Measured memory_bytes: 256
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

int n, m;

const int Max = 2e5 + 10;
int fa[Max], num[Max];
bool vis[Max];
vector<int> root, son[Max];

int findfather(int x) {
	int a = x;
	while (x != fa[x]) {
		x = fa[x];
	}
	while (a != x) {
		int z = fa[a];
		fa[a] = x;
		a = z;
	}
	return x;
}

void Un(int a, int b) {
	int fa1 = findfather(a);
	int fa2 = findfather(b);
	if (fa1 != fa2) {
		fa[fa1] = fa2;
	}

}
void findroot(int k) {
    if (fa[k] == k) {
        num[k]++;
        return;
    }
    vis[k] = true;
    findroot(fa[k]);
}

int dfs(int k) {
    if (fa[k] == k) return k;
    if (fa[k] != k) fa[k] = dfs(fa[k]);
    return fa[k];
}

int main() {
    scanf ("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) fa[i] = i;
    for (int i = 0; i < m; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        Un(a, b);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        dfs(i);
    }
    for (int i = 1; i <= n; i++) {
        findroot(i);
    }
    for (int i = 1; i <= n; i++) ans = max(ans, num[i]);
    printf("%d", ans);
    // for (int i = 1; i <= n; i++) printf("\n%d %d", i, fa[i]);
    return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

#define INF 1LL<<60

// graph by adjacency list
template <typename T>
struct Edge {
  int dst; T weight;
  Edge(int dst, T weight) : dst(dst), weight(weight) { }
  bool operator < (const Edge<T> &e) const {
    return weight > e.weight;
  }
};

template <typename T>
struct Graph {
  int V;
  vector<vector<Edge<T>>> E;

  Graph(int V) : V(V) { E.resize(V); }

  void add_edge(int src, int dst, T weight) {
    E[src].push_back(Edge<T>(dst, weight));
  }
};

template <typename T>
struct Node {
  int v; T dist;
  Node(int v, T dist) : v(v), dist(dist) { };
  bool operator < (const Node<T> &n) const {
    return dist > n.dist; // reverse
  }
};

template <typename T>
struct ShortestPath {
  const Graph<T> g;
  vector<T> dist;
  vector<int> prev;

  ShortestPath(const Graph<T> g) : g(g) { dist.resize(g.V), prev.resize(g.V); }

  void dijkstra(int start) {
    priority_queue<Node<T>> que;
    dist.assign(g.V, INF);
    dist[start] = 0;
    que.push(Node<T>(start, 0));
    prev[0] = -1;

    while (!que.empty()) {
      Node<T> n = que.top(); que.pop();
      int v = n.v; T cost = n.dist;
      if (dist[v] < cost) continue;
      for (Edge<T> e : g.E[v]) {
	if (dist[v] + e.weight < dist[e.dst]) {
	  dist[e.dst] = dist[v] + e.weight;
	  prev[e.dst] = v;
	  que.push(Node<T>(e.dst, dist[e.dst]));
	}
      }
    }
  }

  vector<int> build_path(int goal) {
    vector<int> path;
    for (int v = goal; v != -1; v = prev[v]) {
      path.push_back(v);
    }
    reverse(path.begin(), path.end());
    return path;
  }
};

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int V, E, r; cin >> V >> E >> r;
  Graph<ll> g(V);
  REP(i, E) {
    int s, t, d; cin >> s >> t >> d;
    g.add_edge(s, t, d);
  }
  ShortestPath<ll> sp(g);
  sp.dijkstra(r);
  REP(i, g.V) {
    if (sp.dist[i] == INF) {
      cout << "INF" << endl;
    } else {
      cout << sp.dist[i] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 40404
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    int n;cin >> n;
    int t[n];
    int cur = 0;
    rep(i,n){
        cin >> t[i];
        cur += t[i];
    }
    int m;cin >> m;
    int p[m],x[m];

    rep(i,m){
        cin >> p[i] >> x[i];
        int past = cur;
        cur -= t[p[i]-1];
        cur += x[i];
        cout << cur << endl;
        cur = past;
        


    }

    return 0;
}

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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }

void solve() {
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    vector<ll> acc(N + 1);
    for (int i = 0; i < N; i++) {
        acc[i + 1] = acc[i] + A[i];
        acc[i + 1] %= M;
    }

    map<ll,ll> cnt;
    ll ans = 0;
    cnt[0]++;
    for (int i = 0; i < N; i++) {
        cnt[acc[i + 1]]++;
        ans += cnt[acc[i + 1]];
    }
    cout << ans - N << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define ll long long
#define ar array
#define AC ios_base::sync_with_stdio(0); cin.tie(NULL);
using namespace std;
const int M = 1e9+7;
const int N = 2*1e5;

struct Node{
    int l, r, comfort;
    Node(int left, int right, int cc):l(left),r(right),comfort(cc){}
};

struct CompareComfort{
    bool operator()(const Node& a, const Node& b){
        return a.comfort < b.comfort;
    }
};

int n;
vector<int> arr;
priority_queue<Node, vector<Node>, CompareComfort> PQ;

int main(){
    AC
    cin>>n;
    arr.resize(n);
    for(int i=0; i<n; i++){
        int x;
        cin>>x;
        arr[i] = x;
    }

    sort(arr.rbegin(), arr.rend());
    PQ.push(Node(arr[0], arr[1], min(arr[0],arr[1])));
    PQ.push(Node(arr[0], arr[1], min(arr[0],arr[1])));
    ll ans = arr[0];
    for(int i=2; i<n; i++){
        Node n = PQ.top();
        PQ.pop();
        ans+=n.comfort;
        PQ.push(Node(n.l, arr[i], min(n.l, arr[i])));
        PQ.push(Node(n.r, arr[i], min(n.r, arr[i])));
    }
    cout<<ans<<endl;
}

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

using namespace std;

void solve(void)
{
	int n;
	cin >> n;
	vector<int> xs(n), as, bs;
	int pc = 0, nc = 0;
	for (int& x : xs)
	{
		cin >> x;
		if (x>=0) pc++;
		else nc++;
	}
	sort(xs.begin(), xs.end());
	if (pc==0)
	{
		nc--;
		pc++;
	}
	else if(nc==0)
	{
		pc--;
		nc++;
	}
	int res = xs[0], res2 = xs[n-1];
	for (int i = nc; i < n-1; i++)
	{
		as.push_back(res);
		bs.push_back(xs[i]);
		res -= xs[i];
	}
	for (int i = 1; i < nc; i++)
	{
		as.push_back(res2);
		bs.push_back(xs[i]);
		res2 -= xs[i];
	}
	as.push_back(res2);
	bs.push_back(res);
	res2 -= res;
	cout << res2 << '\n';
	for (int i = 0; i < n-1; i++)
	{
		cout << as[i] << ' ' << bs[i] << '\n';
	}
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


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

using namespace std;

int main()
{
    int A,B,C,D;
    cin >> A >> B >>C >>D;
    int counter = 0;
    int counter2 = 0;
    while(A > 0){
        A -= D;
        counter++;
    }
    while(C > 0){
        C -= B;
        counter2++;
    }
    if(counter2 <= counter)
        cout << "Yes";
    else 
        cout << "No";
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int (i)=0;(i) < (N); (i)++)
#define all(V) V.begin(), V.end()
using i64 = long long;
using P = pair<int,int>;


int main(){
    int A,B;
    cin >> A >> B;
    int p = 1;
    int ans = 0;
    while(p < B){
        p--;
        p += A;
        ans++;
    } 
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>   
#include<algorithm>
#include<vector> 
#include<string.h>
#include<stack>
using namespace std;
typedef long long ll;
const int MAX = 1e3 + 5;
ll n;
int main()
{
	ios::sync_with_stdio(false);
	while (cin >> n)
	{
		int flag = 0;
		for (ll h = 1; h < 3505; h++)
		{
			for (ll k = 1 ; k < 3505; k++)
			{
				if ((4 * h*k - n*k - n*h) != 0)
				{
					ll  w = (n*h*k) / (4 * h*k - n*k - n*h);
					if (w > 0 && (n*h*k) % (4 * h*k - n*k - n*h) == 0)
					{
						flag = 1;
						cout << h << " " << k << " " << w << endl;
						break;
					}
				}
			}
			if (flag) break;
		}
	}
	return 0;
}

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

int main()
{
  int A[9];
  for (auto & a : A)
    cin >> a;
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i)
  {
    int b;
    cin >> b;
    for (auto & a : A)
    {
      if (b == a)
      {
        a = 0;
        break;
      }
    }
  }
  for (int r = 0; r < 3; ++r)
  {
    if (0 == A[r*3 + 0] + A[r*3 + 1] + A[r*3 + 2])
    {
      cout << "Yes";
      return 0;
    }
  }
  for (int c = 0; c < 3; ++c)
  {
    if (0 == A[0*3 + c] + A[1*3 + c] + A[2*3 + c])
    {
      cout << "Yes";
      return 0;
    }
  }
  if (0 == A[0] + A[4] + A[8])
  {
    cout << "Yes";
    return 0;
  }
  if (0 == A[2] + A[4] + A[6])
  {
    cout << "Yes";
    return 0;
  }
  cout << "No";
  return 0;
}


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

int main(){
    int A, B, ans;
    cin >> A >> B;
    if(A % 2 == 0){
        ans = A * 25 / 2;
    }
    else{
        ans = A * 25 / 2 + 1;
    }
    bool flag = false;
    while(ans * 8 / 100 == A){
        if(ans / 10 == B){
            flag = true;
            break;
        }
        ans++;
    }
    if(flag){
        cout << ans << endl;
    }
    else{
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>
#include <set>
#include <map>

typedef long long ll;

using namespace std;

//素因数分解
void factoring(ll n, map<ll, ll>& mp) {
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			mp[i]++;
			n /= i;
		}
	}
	if (n != 1) mp[n]++;
}

int main(){

    ll x,y,z;
    cin>>x>>y>>z;

    cout<<z<<endl;
    cout<<x<<endl;
    cout<<y<<endl;



    return 0;
}


Measured memory_bytes: 256