akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
using P = pair<int, int>;

int main() {
    int H, W, M;
    cin >> H >> W >> M;
    map<P, bool> mp;
    vector<int> cntH(H), cntW(W);
    rep(i, M) {
        int h, w;
        cin >> h >> w;
        h--, w--;
        cntH[h]++;
        cntW[w]++;
        mp[{h, w}] = true;
    }
    int mh = *max_element(cntH.begin(), cntH.end());
    int mw = *max_element(cntW.begin(), cntW.end());
    vector<int> idh, idw;
    rep(i, H) if(cntH[i] == mh) idh.push_back(i);
    rep(i, W) if(cntW[i] == mw) idw.push_back(i);
    for(auto &h : idh) for(auto &w : idw) {
        if(!mp[{h, w}]) {
            cout << mh + mw << '\n';
            return 0;
        }
    }
    cout << mh + mw - 1 << '\n';
    return 0;
}


Measured memory_bytes: 28376
n,m=gets.split.map(&:to_i)
a=gets.split.map(&:to_i).sort
bc=[]
m.times{bc<<gets.split.map(&:to_i)}
bc.sort!{|x,y|y[1]<=>x[1]}
sum=0
0.upto(n-1){|i|
  j=0
  if bc.size>0 and a[i]<bc[0][1]
    j=bc[0][1]
    bc[0][0]-=1
    if bc[0][0]==0
      bc.shift
    end
  else
    j=a[i]
  end
  sum+=j
}
puts sum

Measured memory_bytes: 19224
n = int(input())
s = input()

from collections import Counter
rgb = dict(Counter(s))
if len(rgb) < 3:
    print('0')
else:
    p = rgb['R'] * rgb['G'] * rgb['B']
    for i in range(1, (len(s)-1)//2 + 1):
        for j in range(len(s) - 2*i):
            if {s[j], s[j + i], s[j + 2*i]} == {'R', 'G', 'B'}:
                p -= 1
    print(p)

Measured memory_bytes: 68860
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

vector<long long> enum_div(long long n) {
    vector<long long> res;
    for (long long i = 1; i*i <= n; i++) {
        if (n%i) continue;
        res.push_back(i);
        if (i*i != n) res.push_back(n/i);
    }
    sort(res.begin(), res.end());
    return res;
}

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

    ll n;
    cin >> n;

    auto keta = [](ll a) {
                    int res = 0;
                    while (a) {
                        res++;
                        a /= 10;
                    }
                    return res;
                };
    
    auto f = [&](ll a, ll b) {
                 return max(keta(a), keta(b));
             };

    auto d = enum_div(n);
    int ans = 100;
    for (ll x : d) {
        ll y = n / x;
        chmin(ans, f(x, y));
    }
    cout << ans << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int N;
	cin >> N;
	vector<int> ini_data(N);
	vector<int> data(N);

	for (int i = 0; i < N; i++)
	{
		int tmp;
		cin >> tmp;
		ini_data[i] = tmp;
	}

	data = ini_data;
	
	sort(all(data));

	int a = data[(N - 2) / 2];
	int b = data[N / 2];

	for (int i = 0; i < N; i++)
	{
		if (ini_data[i] <= a)
		{
			cout << b << endl;
		}
		else
		{
			cout << a << endl;
		}
	}
	return;
}

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

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 3840
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [[input().split()] for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

s=s0()
if s=="ABC":
    print("ARC")
else:
    print("ABC")

Measured memory_bytes: 9140
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;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	uint[] GU => Strs.Select(uint.Parse).ToArray();
	decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	static ulong One(int k) => 1ul << k;
	static ulong All(int k) => One(k) - 1;
	static bool Has(ulong s, int k) => (s & One(k)) != 0;
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		WriteLine(Min(F, F) + Min(F, F));
	}
}


Measured memory_bytes: 13140
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int N,a[100],Alice=0,Bob=0;
  cin>>N;
  for(int i=0;i<N;i++){cin>>a[i];}

  sort(a,a+N);

  for(int i=N-1;i>=0;i=i-2) {Alice=Alice+a[i];}
  for(int i=N-2;i>=0;i=i-2) {Bob=Bob+a[i];}

  cout<<Alice-Bob<<endl;
  return 0;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define inf 2000000000
#define infLL 2000000000000000000
#define MAX 500005
#define sf(a) scanf("%d", &a)
#define sfl(a) scanf("%lld", &a)
#define pf(a) printf("%d ", a)
#define pfl(a) printf("%lld\n", a)
#define Case(t) printf("Case %d: ", t)
#define pii pair<int, int>
#define MOD 1000000007
#define mod 998244353
#define PI acos(-1.0)
#define eps 1e-9
#define mem(a, b) memset(a, b, sizeof(a))
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

inline int Set(int N, int pos){return N=N | (1<<pos);}
inline int Reset(int N, int pos){return N=N & ~(1<<pos);}
inline bool Check(ll N, ll pos){return (bool)(N & (1LL<<pos));}

inline void normal(ll &a) { a %= mod; (a < 0) && (a += mod); }
inline ll modMul(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a * b) % mod; }
inline ll modAdd(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a + b) % mod; }
inline ll modSub(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while (p) { if (p & 1LL) r = modMul(r, b); b = modMul(b, b); p >>= 1LL; } return r; }
inline ll modInverse(ll a) { return modPow(a, mod - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll fast_exp(ll x, ll n, ll m)
{
    ll res = 1;
    while(n>0)
    {
        if(n%2==1)
            res = (res * x) % m;
        x = (x * x) % m;
        n/=2;
    }
    return res%m;
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

clock_t t_Start;
void Start()
{
    t_Start = clock();
}
void End()
{
    double Time = (double)(clock()-t_Start)/CLOCKS_PER_SEC;
    error(Time);
}

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet;
typedef tree<int,null_type,greater<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet1;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //Start();

    FASTIO;
    int n, k, c;
    string s;
    cin>>n>>k>>c>>s;
    int L[k+5], R[k+5], cnt = 0;
    for(int i = 0; i < n; i++)
    {
        if(s[i]=='o')
        {
            L[cnt++] = i;
            i = i + c;
        }
        if(cnt==k)
            break;
    }
    cnt = 0;
    for(int i = n-1; i >= 0; i--)
    {
        if(s[i]=='o')
        {
            R[cnt++] = i;
            i = i - c;
        }
        if(cnt==k)
            break;
    }
    for(int i = 0; i < k; i++)
    {
        //error(L[i], R[k-1-i]);
        if(L[i]==R[k-i-1])
            cout<<L[i]+1<<endl;
    }

    //End();
    return 0;
}


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

int main(){
  long long A,B,C,K;
  cin >>A >>B >>C >>K;
  
  if(A>=K)
    cout << K << endl;
  
  else{
    K -= A;
    if(B>=K)
      cout << A << endl;
    else{
      K -=B;
      A -=K;
      cout << A << endl;
    }
  }
  
}


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

const int N = 1e5 + 5;
int n, k, h[N], dp[N];
int main() {
    cin >> n >> k;
    for(int i = 0; i < n; i++) cin >> h[i];
    dp[n - 1] = 0;
    for(int i = 0; i < n - 1; i++) dp[i] = 1e9;
    for(int i = n - 2; i > -1; i--) for(int j = 1; j <= k && i + j < n; j++) dp[i] = min(dp[i], abs(h[i] - h[i + j]) + dp[i + j]);
    cout << dp[0];
}

Measured memory_bytes: 1024
using System;


class AOJ
{

    public static void Main()
    {

        while (true)
        {
            string ss = Console.ReadLine();
            if (ss == null) break;

            string[] s = ss.Split(' ');

            int[] a = new int[6];

            for (int i = 0; i < 6; i++)
            {
                a[i] = int.Parse(s[i]);
            }

            double x = (double)(a[2] * a[4] - a[1] * a[5]) / (a[0] * a[4] - a[1] * a[3]);

            double y = (double)(a[0] * a[5] - a[2] * a[3]) / (a[0] * a[4] - a[1] * a[3]);

            Console.WriteLine("{0:f3} {1:f3}", x, y);
        }
    }
}

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

int main(){
  string s; cin >> s;
  int m = 0, d = 0;
  m = s[5] - '0';
  m = 10*m + (s[6] - '0');
  d = s[8] - '0';
  d = 10*d + (s[9] - '0');
  
  if(m <= 4) cout << "Heisei" << endl;
  else cout << "TBD" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
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; }
const long long INF = 1LL <<60;
typedef long long ll;
using namespace std;

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

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

ll choose2(ll n){
    return n*(n-1)/2;
}

int main(){
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k-a<=0) cout<<k<<endl;
    else if(k-(a+b)<=0) cout<<a<<endl;
    if(k-(a+b)>0) cout<<a - (k - (a+b))<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include<cstdio>
#include<algorithm>
#define maxn 200005
#define LL long long
using namespace std;
LL ans;
int n,a[maxn];
inline int read(){
	int ret=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9') ret=ret*10+ch-'0',ch=getchar();
	return ret*f;
}
inline int abs_(int x){return x>0?x:-x;}
int main(){
	n=read();
	for (int i=1;i<=n;i++) a[i]=read()-i;
	sort(a+1,a+n+1);
	int mid=a[(n+1)/2];
	for (int i=1;i<=n;i++) ans+=abs_(a[i]-mid);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 896
N = int(input())
s = input()

count_r = 0
count_b = 0

for i in range(N):
    c = s[i]
    if c == 'R':
        count_r += 1
    elif c == 'B':
        count_b += 1

if count_r > count_b:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var (AB, BC, CA) = Slice3<long>();
            WriteLine(AB * BC / 2);
        }

        static long Mod = 998244353;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static public (T a, T b, T c, T d) Slice4<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)),
            (T)Convert.ChangeType(t[3], typeof(T)));
        }
    }
}

Measured memory_bytes: 27408
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using namespace boost::multiprecision;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(),(x).end()
inline cpp_int between(cpp_int n, cpp_int x) {
  if(n >= 0)
    return (n/x)+1;
  else
    return 0;
}

int main () {
  int n, m, input, input2;
  vector<int> t;
  cin >> n;

  int base_sum = 0;

  REP(i, n) {
    cin >> input;
    t.push_back(input);
    base_sum += input;
  }

  cin >> m;

  REP(i, m) {
    cin >> input >> input2;
    cout << (base_sum - t[input - 1]) + input2 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
int n, t[100010], ans;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++)cin >> t[i];
	sort(t, t + n);
	for (int i = 0; i < n; i++) {
		int s = upper_bound(t, t + n, t[i]) - lower_bound(t, t + n, t[i]);
		if (s < t[i])ans += s;
		else ans += s - t[i];
		i += s - 1;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
  char suit;
  int value;
};

struct Card L[MAX/2+2], R[MAX/2+2];

void merge(struct Card A[], int n, int left, int mid, int right) {
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for(i=0;i<n1;i++) L[i] = A[left + i];
  for(i=0;i<n2;i++) R[i] = A[mid  + i];
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;
  for(k=left; k<right; k++) {
    if(L[i].value <= R[j].value) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(struct Card A[], int n, int left, int right) {
  if(left+1 < right) {
    int mid = (left+right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid, right);
    merge(A,n,left,mid,right);
  }
}

int partition(struct Card A[], int n, int p, int r) {
  int i, j;
  struct Card t, x;
  x = A[r];
  i = p-1;
  for(j=p; j<r; j++) {
    if(A[j].value <= x.value) {
      i++;
      t=A[i]; A[i]=A[j]; A[j]=t;
    }
  }
  t=A[i+1]; A[i+1]=A[r]; A[r]=t;
  return i+1;
}

void quickSort(struct Card A[], int n, int p, int r) {
  int q;
  if(p<r) {
    q = partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}

int main() {
  int n, i, v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d", &n);

  for(i=0;i<n;i++) {
    scanf("%s %d",S,&v);
    A[i].suit =  B[i].suit  = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);

  for(i=0;i<n;i++) {
    if(A[i].suit != B[i].suit) stable = 0;
  }

  if(stable==1) printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++) {
    printf("%c %d\n",B[i].suit,B[i].value);
  }

  return 0;
}


Measured memory_bytes: 4012
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#define SIZE 200010
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define ll long long
#define mp make_pair
#define pi acos(-1.0)
#define eps 1e-6
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
ll n, k, ans, cnt, res;
ll a[SIZE], pre[SIZE];

bool check(ll x) {
	res = cnt = 0;
	rep(i, 1, n) {
		ll pos = lower_bound(a + 1, a + n + 1, x - a[i]) - a;
		cnt += n - pos + 1ll;
		res += pre[n] - pre[pos - 1] + a[i] * (n - pos + 1);
	}
	return cnt >= k;
}

int main() {
	io(); cin >> n >> k;
	rep(i, 1, n) cin >> a[i];
	sort(a + 1, a + 1 + n);
	rep(i, 1, n) pre[i] = pre[i - 1] + a[i];
	ll L = 1, R = 2e5 + 10, md;
	while (L <= R) {
		md = (L + R) >> 1;
		if (check(md)) ans = md, L = md + 1;
		else R = md - 1;
	}
	cout << res - (cnt - k) * ans;
}

Measured memory_bytes: 1792
H,W = map(int,input().split())
L = []
for i in range(H):
  L.append(list(input()))
dy_dx = [[1,0],[-1,0],[0,1],[0,-1]]
cnt = 0
for i in range(H):
  for j in range(W):
    d = 0
    if L[i][j] == '#':
      for p in range(4):
        if 0 <= i+dy_dx[p][0] <= H-1 and 0 <= j+dy_dx[p][1] <= W-1:
          if L[i+dy_dx[p][0]][j+dy_dx[p][1]] == '.':
            d += 1
      if 1 <= i <= H-2 and 1 <= j <= W-2:
        if d == 4:
          cnt += 1
      elif (i == 0 and j == 0) or (i == 0 and j == W-1) or (i == H-1 and j == 0) or (i == H-1 and j == W-1):
        if d == 2:
          cnt += 1
      else:
        if d == 3:
          cnt += 1
if cnt == 0:
  print('Yes')
else:
  print('No')

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(i,s,n) for(int i = (s); i < (n); ++i)
#define ll long long
#define ld long double
#define P pair<ll,ll>
#define all(v) v.begin(),v.end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll a,b,c,x,y; cin>>a>>b>>c>>x>>y;
    ll ans=0;
    rep(i,min(x,y)){
        ans+=min(a+b,2*c);
    }
    if(x>y) rep(i,x-y) ans+=min(a,2*c);
    else rep(i,y-x) ans+=min(b,2*c);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3616
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N, Q;
	cin >> N >> Q;
	vector<long long> A(N);
	for (int i = 0; i < N; ++i) cin >> A[i], A[i] *= 3;
	vector<long long> S(N + 1), chrosum(N + 1);
	for (int i = 0; i < N; ++i) {
		S[i + 1] = S[i] + A[i];
		chrosum[i + 1] = chrosum[i] + (i % 2 != N % 2 ? A[i] : 0);
	}
	for (int i = 0; i < Q; ++i) {
		long long X;
		cin >> X; X = 3 * X - 1;
		long long L = 0, R = 3000000000;
		while (R - L > 1) {
			long long M = (L + R) >> 1;
			int div1 = lower_bound(A.begin(), A.end(), X - M) - A.begin();
			int div2 = lower_bound(A.begin(), A.end(), X + M + 1) - A.begin();
			if (div2 - div1 > N - div2) R = M;
			else L = M;
		}
		int fdiv1 = lower_bound(A.begin(), A.end(), X - L) - A.begin();
		int fdiv2 = lower_bound(A.begin(), A.end(), X + L + 1) - A.begin();
		long long ans = (S[N] - S[fdiv2]) + chrosum[fdiv1];
		cout << ans / 3 << '\n';
	}
	return 0;
}

Measured memory_bytes: 4096
#include <stdio.h>
#define HIRA 100000000 
#define MAX 100
 
int n,s[MAX],pi[MAX][MAX],sco[MAX][MAX],mist[MAX];

void visit(int p, int c){
  int i;
  mist[p] = c;
  for(i=0;i<s[p];i++)
    if(mist[pi[p][i]] > c+sco[p][i])visit(pi[p][i], c+sco[p][i]);
}
main(){
  int i, j;
  scanf("%d", &n);
  for(i=0;i<n;i++){
    int u;
    scanf("%d", &u);
    scanf("%d", &s[u]);
    for(j=0;j<s[u];j++){
      scanf("%d", &pi[u][j]);
      scanf("%d", &sco[u][j]);
    }}
  for(i=0;i<n;i++) mist[i] = HIRA;
  visit(0,0);
  for(i=0;i<n;i++){
    printf("%d %d\n", i, mist[i]);
  }
  return 0;
}

Measured memory_bytes: 680
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n, a, b;
  cin >> n >> a >> b;
  int max, min;
  max = (a < b) ? a : b;
  if (a + b < n) {
    min = 0;
  } else {
    min = a + b - n;
  }

  cout << max << " " << min << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
	int n,a,star,goal;
	while(cin >> n >> a >> star >> goal && n!=0){
		vector<pair<string,pair<int,int> > > g(a);
		for(int i=0;i<a;i++){
			cin >> g[i].second.first >> g[i].second.second >> g[i].first;
		}
		vector<string>dp(n,"{");
		dp[goal] = "";
		int cnt = 0;
		for(int i=0;i<900;i++){
			string k = dp[star];
			for(int j=0;j<a;j++){
				if(dp[g[j].second.second]!="{"){
					dp[g[j].second.first] = min(dp[g[j].second.first],g[j].first+dp[g[j].second.second]);
				}
			}
			if(k!=dp[star]){
				cnt = i;
			}
		}
		if(cnt >=400||dp[star]=="{"){
			cout << "NO" << endl;
		}else{
			cout << dp[star] << endl;
		}
	}
	return 0;	
}


Measured memory_bytes: 6112
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
// typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

ll m, a, r, c, h;
ll P[10]={0 ,0 ,0 ,0 ,0 ,0 ,1 ,1 ,1 ,2};
ll Q[10]={1 ,1 ,1 ,2 ,2 ,3 ,2 ,2 ,3 ,3};
ll R[10]={2 ,3 ,4 ,3 ,4 ,4 ,3 ,4 ,4 ,4};
ll D[5];

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    rep(i, n) {
        string s;
        cin >> s;
        if (s[0] == 'M') D[0]++;
        if (s[0] == 'A') D[1]++;
        if (s[0] == 'R') D[2]++;
        if (s[0] == 'C') D[3]++;
        if (s[0] == 'H') D[4]++;
    }

    ll res = 0;
    rep(i, 10) {
        res += D[P[i]] * D[Q[i]] * D[R[i]];
    }

    cout << res << endl;

    return 0;
}

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

#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>

#include<algorithm>
#include<cmath>
#include<numeric>

using namespace std;
typedef long long ll;
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;}
const ll INF = 1e18+1;

/*
考察1
ビットごとに考える

考察2
kビット目を考える際、2^k+1以降の数は無視できるので
mod 2^(k+1)をとってよい

考察3
すると、ai+bjのとる範囲は 4 * 2^k 未満になり、
kビット目が立つということは
ai+bjが [2^k, 2 * 2^k) [3 * 2^k, 4 * 2^k)
の中に入るということを意味する

すなわち、そのようなai+bjの数を求めるには
各aiについて↑-aiでソートしたbj乗を二分探索する
*/

int main() {
    int N; cin >> N; 
    vector<ll> a(N), b(N),c(N),d(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    for (int i = 0; i < N; i++) cin >> b[i];

    ll res = 0, T = 1;
    for (ll k = 0; k < 29; k++) {
        for (int i = 0; i < N; i++) {
            c[i] = a[i] % (2 * T);
            d[i] = b[i] % (2 * T);
        }
        sort(d.begin(),d.end());
        ll cnt = 0;
        for (int i = 0; i < N; i++) {
            cnt +=
            (lower_bound(d.begin(),d.end(),4*T-c[i]) -
            lower_bound(d.begin(),d.end(),T-c[i])) -
            (lower_bound(d.begin(),d.end(),3*T-c[i])-
            lower_bound(d.begin(),d.end(),2*T-c[i]));
            
        }
        if (cnt % 2 == 1) res ^= T;
        //cout << T << " " << cnt << endl;
        T *= 2;
    }
    cout << res << endl;
}



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

int main(void)
{
    string S;
    cin >> S;

    int len = S.size();
    vector<int> acgt(len, 0);

    for (int i = 0; i < len; i++)
    {
        if(S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T'){
            acgt[i] = 1;
        }
    }

    int maxLen = 0;

    acgt.push_back(0);

    int cntr = 0;
    for (int i = 0; i < len + 1; i++)
    {
        if(acgt[i] == 1){
            cntr++;
        } else {
            if(maxLen < cntr) maxLen = cntr;
            cntr = 0;
        }
    }
    
    cout << maxLen << endl;

    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;

int		main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n, m;
	cin >> n >> m;
	int np = n;
	int mp = m;
	ll cnt = 0;
	rep(i, n) {
		np--;
		rep(j, np) {
			cnt++;
		}
	}
	rep(i, m) {
		mp--;
		rep(j, mp) {
			cnt++;
		}
	}
	cout << cnt << endl;
}


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

#define pb push_back
#define fst first
#define snd second
#define INF 0x7fffffff
#define INFLL 0x7FFFFFFFFFFFFFFF
#define lenA(ar) sizeof(ar)/sizeof(*ar)
#define lenrows(mat) sizeof(mat)/sizeof(*mat)
#define lencols(mat) sizeof(*mat)/sizeof(**mat)
#define fill(a,c) memset(&a, c, sizeof(a))
#define fore(i,x,y) for(ll i=x;i<y;i++)
#define foreI(i,x,y) for(ll i=x-1;i>=y;i--)
#define max2(a,b) max(a, b)
#define max3(a,b,c) max2(max2(a,b),c)
#define min2(a,b) min(a, b)
#define min3(a,b,c) min2(min2(a,b),c)
#define MOD 1000000009
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef long long ll;
typedef unsigned long long ull;

using namespace std;
ll arr[200010];
ll dp[200010];
int n;
ll solve(int pos){
    if(pos==n-1) return 0;
    if(dp[pos]>-1) return dp[pos];
    ll &r = dp[pos];

    ll a=solve(pos+1)+abs(arr[pos]-arr[pos+1]);
    ll b=INFLL;

    if(pos!=n-2){
        b =solve(pos+2)+abs(arr[pos]-arr[pos+2]);
    }
    return r=min(a,b);

}

int main() {
    

    cin>>n; arr[n];
    fill(dp,-1);
    fore(i,0,n)cin>>arr[i];
    cout<<solve(0)<<"\n";
    return 0;
}



Measured memory_bytes: 5760
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class345
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine().Last().ToString());
            if (N == 0 || N == 1 || N == 6 || N == 8) Console.WriteLine("pon");
            else if (N == 3) Console.WriteLine("bon");
            else Console.WriteLine("hon");
        }
    }
}


Measured memory_bytes: 27820
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
vector<long long> houseplace;

int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		int input;
		cin >> input;
		houseplace.insert(houseplace.begin(), input);
	}
	sort(houseplace.begin(), houseplace.end());

	long long totalDistance = 0;
	for (int i = 0; i < N-1; i++)
	{
		totalDistance = houseplace[i + 1] - houseplace[i] + totalDistance;
	}

	cout << totalDistance << endl;

	

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll N;
  cin>>N;
  set<string> S;
 vector<string> vec(N);
  for(ll i=0;i<N;i++) {
cin>>vec[i];
  }
  
for(ll i=0;i<N;i++) {
if(S.count(vec[i])) {
cout<<"No"<<endl;
  return 0;
}
  S.insert(vec[i]);
}
  
  
  for(ll i=0;i<N-1;i++) {
if(vec[i].back()!=vec[i+1][0]) {
cout<<"No"<<endl;
  return 0;
}
  }
  
  
  cout<<"Yes"<<endl;
}


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

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, init, n) for(int i = init; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define fi first
#define se second

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

    int m, f, b;
    cin >> m >> f >> b;

    if(m + f < b)
    {
        cout << "NA" << endl;
    }
    else
    {
        if(b <= m)
        {
            cout << 0 << endl;
        }
        else
        {
            cout << b - m << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
    	using namespace std;
        
    	int main()
    	{
    		
                int a,b,c;
                cin>>a>>b>>c;
                vector<int> v={5,5,7};
                vector<int>ans;
                ans.push_back(a);
                 ans.push_back(b);
                  ans.push_back(c);
                  sort(ans.begin(),ans.end());
                  if(v==ans)
                    cout<<"YES"<<endl;
                else 
                    cout<<"NO"<<endl;
    		return 0;
    	}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>
#include <iomanip>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);

int main() {
    ll W,H,x,y;
    cin >> W >> H >> x >> y;

    cout << fixed << setprecision(10) << (long double)W*H/2 << " ";

    if(H-y==y && W-x==x)cout << 1 << endl;
    else cout << 0 << endl;

    return 0;
}

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

int main() {
	int a, b;
	bool first = true;
	while (cin >> a >> b, a || b) {
		if (!first) {
			cout << endl;
		}
		else first = false;
		bool na = true;
		for (int i = a; i <= b; i++) {
			if (i % 400 == 0 || (i % 4 == 0 && i % 100 != 0)) {
				na = false;
				cout << i << endl;
			}
		}
		if (na) {
			cout << "NA" << endl;
		}
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;

int main()
{
  // 整数の入力
  ll N,K;
  cin >> N >> K;
  vector<ll> A(N);
  vector<ll> visited(N, -1);
  for(int i = 0 ;i < N;i++){
    cin >> A[i];
    A[i]--;
  }
  ll current = 0;
  ll turn = 0;
  map<ll,ll> ikisaki;
  while(visited[current] == -1){
    visited[current] = turn;
    ikisaki[turn] = current;
    // cout << turn << " " << current << endl;
    turn++;
    current = A[current];
  }
  ll base = visited[current];
  ll shuuki = turn - visited[current];
  // cout << base << " " << shuuki << endl;
  if (K < base){
    cout << ikisaki[K] + 1 << endl;
  }else{
    // cout << (K - base) % shuuki + base << endl;
    cout << ikisaki[(K - base) % shuuki + base] + 1<< endl;
  }
  return 0;
}

Measured memory_bytes: 18780
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		FastScanner in= new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		
		int n = in.nextInt();
		int k = in.nextInt();
		int [] a = new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = in.nextInt();
		}
		int [] dp = new int[n];
		dp[0] = 0;
		if(n ==1) {
			System.out.println(0);
			return;
		}
		dp[1] = Math.abs(a[1]-a[0]);
		for (int i = 2; i < dp.length; i++) {
			int cur = Integer.MAX_VALUE/2;
			for (int j = 1; j <= k; j++) {
				if(i - j >= 0) {
					cur = Math.min(cur, dp[i-j] + Math.abs(a[i] - a[i-j]));
				}
			}
			dp[i] = cur;
		}
		System.out.println(dp[n-1]);
	}
	
	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
			st = new StringTokenizer("");
		}

		public String next() throws IOException {
			if (!st.hasMoreTokens()) {
				st = new StringTokenizer(br.readLine());
				return next();
			}
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
		public double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
	}
}
/*
6 4
0 3 4 6 10 12

7 4
0 3 4 6 10 14 16

*/

Measured memory_bytes: 35340
#include<cstdio>
#include<cstring>
#include<algorithm>
using std::max;
const int MAXN=100010;

struct node{
	int a,b,c;
	node(int a=0,int b=0,int c=0){
		this->a=a;
		this->b=b;
		this->c=c;
	}
}p[MAXN];
int n,f[MAXN][3];

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int a,b,c;scanf("%d%d%d",&a,&b,&c);
		p[i]=node(a,b,c);
	}
	for(int i=1;i<=n;i++){
		f[i][0]=max(f[i-1][1],f[i-1][2])+p[i].a;
		f[i][1]=max(f[i-1][0],f[i-1][2])+p[i].b;
		f[i][2]=max(f[i-1][0],f[i-1][1])+p[i].c;
	}
	printf("%d\n",max(f[n][0],max(f[n][1],f[n][2])));
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
#include <queue>
#include <stack>

using namespace std;

int n,m;
const int d[]={0,1,-1};
int table[10][10][100];

bool check(int x, int y, int z)
{
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(i==0 && j==0 && k==0) continue;
                
                int nx=x,ny=y,nz=z;
                const int dx=d[i],dy=d[j],dz=d[k];
                const int color=table[x][y][z];
                int count=1;
                //printf("dx=%d,dy=%d,dz=%d\n",dx,dy,dz);
                //printf("start: (%d,%d,%d)\n",nx,ny,nz);

                // ?????????
                while(0<=nx+dx && nx+dx<n && 0<=ny+dy && ny+dy<n && 0<=nz+dz && nz+dz<n && table[nx+dx][ny+dy][nz+dz]==color){
                //    printf("now: (%d,%d,%d)\n",nx,ny,nz);
                    count++;
                    nx+=dx; ny+=dy; nz+=dz;
                }
                
                nx=x; ny=y; nz=z;
                
                // ?????????
                while(0<=nx-dx && nx-dx<n && 0<=ny-dy && ny-dy<n && 0<=nz-dz && nz-dz<n && table[nx-dx][ny-dy][nz-dz]==color){
                //    printf("now: (%d,%d,%d)\n",nx,ny,nz);
                    count++;
                    nx-=dx; ny-=dy; nz-=dz;
                }
                
                //cout<<"count: "<<count<<endl;

                if(count>=m) return true;
                
            }
        }
    }
    return false;
}

int main()
{
    int p;
    while(cin>>n>>m>>p,n){
        
        int h[10][10]={0};
        
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                for(int k=0;k<100;k++) table[i][j][k]=0;
            }
        }
        
        bool end=false;
        for(int i=0;i<p;i++){
            int x,y;
            cin>>x>>y;
            x--; y--;
            if(i%2) table[x][y][h[x][y]]=2;
            else table[x][y][h[x][y]]=1;
            
            if(!end && check(x,y,h[x][y])){
                end=true;
                if(i%2) cout<<"White "<<i+1<<endl;
                else cout<<"Black "<<i+1<<endl;
            }
                
            h[x][y]++;
        }
        
        if(!end) cout<<"Draw"<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
 
#define int long long
 
// loop
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 	// a ~ b-1	(ascending)
#define REP(i, n) FOR(i, 0, n)							// 0 ~ n-1
#define NREP(i, n) FOR(i, 1, n + 1)						// 1 ~ n
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)	// a ~ b	(descending)
#define RREP(i, n) RFOR(i, n, 0)						// n ~ 0
#define RNREP(i, n) RFOR(i, n, 1)						// n ~ 1
 
// container operation
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define ASORT(c) std::sort((c).begin(), (c).end())
#define DSORT(c) std::sort((c).begin(), (c).end(), std::greater<typeof((c).front())>())
#define SIZE(x) ((int)(x).size())
 
// debug
#define check(x) std::cout << #x << " = " << x << '\n'
 
// print
#define cout(x) std::cout << x << '\n'
 
// type alias
using VI = std::vector<int>;
using VII = std::vector<VI>;
using VB = std::vector<bool>;
using VBB = std::vector<VB>;
using VS = std::vector<std::string>;
using PII = std::pair<int, int>;

std::string yes = "Yes\n";
std::string no = "No\n";
std::string YES = "YES\n";
std::string NO = "NO\n";

void solve();

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

void solve() {
  int a, b, c;
  std::cin >> a >> b >> c;
  if ((a == 7 && b == 5 && c == 5) ||
      (a == 5 && b == 7 && c == 5) ||
      (a == 5 && b == 5 && c == 7)) {
    cout(YES);
  } else {
    cout(NO);
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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() {
    cout << fixed << setprecision(10);
    
    int N; cin >> N;
    vector<int> T(N), A(N);
    rep(i, N) {
        cin >> T[i] >> A[i];
    }
    ll t = 1, a = 1;
    // cout << "out " << endl;
    // ll tc = 1, ac = 1;
    rep(i, N) {
        ll ti = T[i], ai = A[i];
        // cout << "target  t " << ti << " a " << ai << endl;
        // t < t+1, a < a+1 && t+1 : a+1 = T[i] : A[i]となる最小の数を見つける
        if (ti < t) {
            // tiをtp倍すれば >= tになる
            ll tp = (t + T[i] -1) / T[i];
            ti *= tp;
            ai *= tp;
        }
        if (ai < a) {
            ll ap = (a - ai + A[i] -1) / A[i];
            ti += T[i] * ap;
            ai += A[i] * ap;
        }
        t = ti;
        a = ai;
        // cout << t << " " << a << endl;
    }
    cout << t + a << endl;
    return 0;
}

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

int main() {
	int n,m,h,a,b,ans=0;
	cin>>n>>m;
	vector<int> height(n+1);
	for(int i=1;i<=n;i++){
		cin>>h;
		height.at(i)=h;
	}
	vector<int> top(n+1);
	for(int i=0;i<m;i++){
		cin>>a>>b;
		if(height[a]>height[b]){
			top[b]--;
		}else if(height[a]<height[b]){
			top[a]--;
		}else{
			top[a]--;
			top[b]--;
		}
	}
	for(int i=1;i<=n;i++){
		if(top[i]==0){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4028
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int n=scanner.nextInt();
		

		int result=0;

			int buf=getsumofkakuketa(n);

			if(n%buf==0) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}

		



		scanner.close();

	}

	public static int getsumofkakuketa(int n) {

		int result=0;

		while(true) {

			result+=n%10;

			if(n/10!=0) {
				n/=10;
			}else {
				return result;
			}
		}



	}

	public static boolean isMacthed(int a,int b,int sum) {

		if(sum>=a && sum<=b) {
			return true;
		}else {
			return false;
		}

	}



}







Measured memory_bytes: 21844
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();
        long quotient = n / (a + b);
        long mod = n % (a + b);
        if(a<=mod){
            System.out.println(quotient*a + a);
        }else {
            System.out.println(quotient*a + mod);
        }
    }
}

Measured memory_bytes: 23252
#include <iostream>
#include <cstring>
#include <string.h>
using namespace std;

int main()
{
    string S;
    cin>>S;
    if(S[2]==S[3]&&S[4]==S[5])
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    
    int N,K;
    cin >> N >> K;
    vector<int> A(N);
    for ( int i = 0; i < N; i++ ) {
        int a;
        cin >> a;
        A[a]++;
    }
    
    sort( A.begin(), A.end(), greater<int>() );
    
    int sum = 0;
    for ( int i = 0; i < K; i++ ) {
        sum += A[i];
    }
    
    cout << N-sum << endl;
    
    return 0;
}


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

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

int main()
{
	int n, m;
	cin >> n >> m;
	vector<vector<int>> kv(m);
	for (auto& k : kv) {
		int l;
		cin >> l;
		for (int i = 0; i < l; ++i) {
			int j;
			cin >> j;
			k.push_back(j);
		}
	}

	vector<int> pv(m);
	for (auto& p : pv) {
		cin >> p;
	}

	int max = 1;
	for (int i = 1; i < n; ++i) {
		max += 1 << i;
	}

	int ret = 0;
	vector<int> check(n + 1);
	for (int i = 0; i <= max; ++i) {
		for (int j = 1; j <= n; ++j) {
			check[j] = (1 << (j - 1)) & i;
		}

		bool isOk = true;
		for (int j = 0; j < m; ++j) {
			int count = 0;
			for (auto& k : kv[j]) {
				if (check[k]) {
					++count;
				}
			}
			if (count % 2 != pv[j]) {
				isOk = false;
				break;
			}
		}

		if (isOk) {
			++ret;
		}
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <iostream>
#include <cstring>
#include <cstdio>


#define ll long long
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define f(n) for (ll i = 0; i < n; i++)

using namespace std;

int main()
{
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	vi nums(n);
	f(n) cin >> nums[i];
	sort(nums.begin(), nums.end());
	if (nums[n / 2 - 1] == nums[n / 2]) cout << 0 << '\n';
	else cout << nums[n / 2] - nums[n / 2 - 1] << '\n';
}


Measured memory_bytes: 640
def hantei(num,list):
    score = 0
    for i in range(len(list)):
        if list[i] in str(num):
            score = +1
    return score                

N,K = map(int,input().split())

dislike = list(map(str,input().split()))

while True:
    if hantei(N,dislike) == 0:
        break
    N = N + 1
print(N)

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


int main(){
  int H, W, N;
  vector<int> a(10010);
  cin >> H >> W >> N;
  for(int i=1; i<=N; i++) cin >> a[i];

  vector<vector<int>> ans(110, vector<int>(110,0));

  int x = 0, y = 0; bool right = true;
  for(int i=1; i<=N; i++){
    while(a[i] > 0){
      ans[y][x] = i; a[i]--;
      if(right){
        if(x < W-1) { x++; }
        else { y++; right = false; }
      } else {
        if(x > 0) { x--; }
        else { y++; right = true; }
      }
    }
  }

  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cout << ans[i][j] << " ";
    }
    cout << endl;
  }
}

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

const int MAXN = 100005;

int N, M, Li, Ri, Ci;
vector < pair <int, int> > evs[MAXN];

int main(){
	scanf("%d %d", &N, &M);
	while(M--){
		scanf("%d %d %d", &Li, &Ri, &Ci);
		Li--, Ri--;
		
		evs[Li].push_back(make_pair(Ri, Ci));
	}
	
	set < pair <long long, int> > S;
	S.insert(make_pair(0, 0));
	
	for(int i = 0; i < N; i++){
		while(!S.empty() && S.begin()->second < i)
			S.erase(S.begin());
			
		if(S.empty()){
			printf("-1\n");
			return 0;
		}
		
		long long dist = S.begin()->first;
		
		if(i == N - 1){
			printf("%lld\n", dist);
			return 0;
		}
		
		for(pair <int, int> e : evs[i])
			S.insert(make_pair(dist + e.second, e.first));
	}
	
	return 0;
}


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

int main() {
  string S, T, U;
  int number_S, number_T;

  cin >> S >> T;
  cin >> number_S >> number_T;
  cin >> U;

  if(S == U)
    number_S--;

  else
    number_T--;

  cout << number_S << " " << number_T << endl;  
  
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>

using namespace std;

int main(){

  int n,h,i;

  cin >> n >> h;
  int a[n],b[n];

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

  int amax = *max_element(a,a+n);
  sort(b,b+n);
  int count = 0;

  for(i=n-1;i>=0;i--){
    if(h<=0) break;
    else if(h>0 && b[i] > amax){
      h -= b[i];
      count++;
    }
  }

  if(h>0) count += ceil(h/double(amax));

  cout << count << endl;

  return 0;

}


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

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;

const int MX = 1e5 + 5;
const int INF = 1e9;
const int MOD = 1e9 + 7;

#define F0R(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ps(x) cout << x << "\n";
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
#define rall(x) (x).rbegin(), (x).rend() 
#define rsz resize
#define ins insert 

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
		ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
		// cin.exceptions(cin.failbit); 
		// throws exception when do smth illegal
		// ex. try to read letter into int
		if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

int N, M, a[MX];
bool b[MX];

int main() {
	cin >> N >> M;
	b[1] = 1;
	FOR(i, 1, N + 1) a[i] = 1;

	F0R(i, M) {
		int x, y; cin >> x >> y;
		if (b[x]) {
			b[y] = 1;
			if (a[x] <= 1) b[x] = 0;
		}
		a[x]--, a[y]++;
	}

	int cnt = 0;
	FOR(i, 1, N + 1) cnt += b[i];
	ps(cnt);
}







Measured memory_bytes: 4048