akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long

const int MAXN = 1E5+2;
const int MOD = 1e9+7;

int n, m;
int s, t;

vector<pair<int, int> > g[MAXN];
vector<int> ds(MAXN, -1), dt(MAXN, -1), cnts(MAXN, 0), cntt(MAXN, 0);

priority_queue<pair<int, int> > pq;

void SP(int src, vector<int>& dist, vector<int>& cnt){
    dist[src] = 0; cnt[src] = 1;
    pq.push({0, src});
    while(!pq.empty()){
        int d = -pq.top().first,  u= pq.top().second; pq.pop();
        if(d > dist[u]) continue;
        for(pair<int, int> coup : g[u]){
            int v = coup.first, w = coup.second;
            if(dist[v] == -1 || (dist[v] > dist[u]+w)){
                dist[v] = dist[u]+w;
                cnt[v] = cnt[u];
                pq.push({-dist[v], v});
            }
            else if(dist[v] == dist[u]+w){
                cnt[v] += cnt[u];
                cnt[v] %= MOD;
            }
        }
    }
}

signed main()
{
		//freopen("input.txt", "r", stdin);
    cin >>n >> m;
    cin >> s >> t;
    for(int i=1;i <= m; ++i){
        int u, v, w; cin >> u >> v >> w;
        g[u].push_back({v, w});
        g[v].push_back({u, w});
    }
    SP(s, ds, cnts); SP(t, dt, cntt);
    int ans = (cnts[t]*cntt[s])%MOD;
    for(int u=1; u<= n; ++u){
        for(pair<int, int> v : g[u]){
            if(ds[u] + dt[v.first] + v.second == ds[t] && abs(ds[u] - dt[v.first]) < v.second){
                ans += MOD-(((cnts[u]*cntt[v.first])%MOD)*((cnts[u]*cntt[v.first])%MOD)%MOD);
                ans %= MOD;
            }
        }
        if(ds[u] + dt[u] == ds[t] && ds[u] == dt[u]){
            ans += MOD-(((cnts[u]*cntt[u])%MOD)*((cnts[u]*cntt[u])%MOD)%MOD);
            ans %= MOD;
        }
    }
    cout << ans;
}

Measured memory_bytes: 18288
import sys

n = int(input())
s = tuple(map(int, sys.stdin.readline().split()))   # 昇順にソート済み
q = int(input())
t = tuple(map(int, sys.stdin.readline().split()))

result = 0
for x in t:
    first = 0
    last = n - 1
    while first <= last:
        middle = first + (last - first) // 2
        if x == s[middle]:
            result += 1
            break
        elif x < s[middle]:
            last = middle - 1
        else:
            first = middle + 1
print(result)


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

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

  int half = total / 2;

  int a = 0;
  int halfIndex = 0;

  for(int i=0;i<n;i++) {
    a += vec[i];
    if(a > half) {
      halfIndex = i;
      break;
    }
  }

  int b = a - vec[halfIndex];

  if(abs(total-a-a) > abs(total-b-b)) {
    cout << abs(total-b-b) << endl;
  } else {
    cout << abs(total-a-a) << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std;
vector<string>s(10);
int n, sx, sy;

void dfs(int x, int y) {
	s[x][y] = '0';
	for (int i = -3; i <= 3; i++) {
		if (x + i >= 0&&x+i<=7) {
			if (s[x + i][y] == '1') {
				dfs(x + i, y);
			}
		}
	}
	for (int i = -3; i <= 3; i++) {
		if (y + i >= 0&&y+i<=7) {
			if (s[x][y + i] == '1') {
				dfs(x, y + i);
			}
		}
	}
	return;
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 8; j++) {
			cin >> s[j];
		}
		cin >> sx >> sy;
		dfs(sy - 1, sx - 1);
		cout << "Data "<<i+1<<":"<< endl;
		for (int j = 0; j < 8; j++) {
			cout << s[j] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3160
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

#ifdef DEBUG
#else
    #define cerr if (false) cerr
#endif

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int x;
    cin >> x;
    if (x >= 30)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}

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

int main(){

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

	int n;
	cin>>n;

	vector<int> a(n) , b(n) , c(n);
	int ia=0 , ib=0;

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

	for(int i=0 ; i<n ; ++i)
		cin>>b[i];
	
	for(int i=0 ; i<n ; ++i)
		c[i] = i+1;

	int cnt=0;
	while( next_permutation(c.begin(),c.end()) ){
		cnt++;
		if( a == c )
			ia = cnt;
		if( b == c )
			ib = cnt;
	}

	cout<< abs(ia-ib) << '\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>
#include <set>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n;
    cin >> n;
    vector<int> v(static_cast<unsigned long>(n + 1));
    for (int i = 0; i < n; ++i) {
        int k;
        scanf("%d", &k);
        v[k] = i+1;
    }
    ll ans = 0;
    set<ll> s = {0, n+1};
    for (int i = 1; i <= n; ++i) {
        auto iter = s.lower_bound(v[i]);
        ll r = *iter;
        ll l = *(--iter);
        ans += i*(v[i]-l)*(r-v[i]);
        s.insert(v[i]);
    }
    cout << ans << "\n";
    return 0;
}


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

if sum(A) % (N * (N+1) // 2) != 0:
  print("NO")
  exit(0)

k = sum(A) // (N * (N+1) / 2)
judge = True
for i, a in enumerate(A):
  x = A[(i+1)%N] - a - k
  if x % N != 0 or x > 0:
    judge = False
print("YES" if judge else "NO")


Measured memory_bytes: 14244
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

  for (int i = 1; i <= 1100; i ++) {
    int x = i * 0.08;
    int y = i * 0.1;
    if (a == x && b == y) {
      cout << i << endl;
      return 0;
    }
  }

  cout << -1 << endl;
}


Measured memory_bytes: 256
n, k = gets.strip.split.map(&:to_i)
v = gets.strip.split.map(&:to_i)

actions = []
(0..k).each do |l|
  (0..(k-l)).each do |r|
    t = k-r-l
    actions << [l, r, t]
  end
end

def calc_v(stones, left, right, trash)
  c_s = stones.dup
  get_stones = []

  if c_s.length < left+right
    get_stones = c_s
  else
    left.times { get_stones << c_s.shift}
    right.times { get_stones << c_s.pop}
  end

  get_stones = get_stones.sort
  trash.times {
    get_stones.shift if !get_stones.empty? && get_stones.first<0
  }

  get_stones.inject(0, :+)
end

#p actions.map {|l,r,t| calc_v(v, l, r, t) }
p actions.map {|l,r,t| calc_v(v, l, r, t) }.max


Measured memory_bytes: 2684
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()

    if S[-1] != 's':
        print(S + 's')
    else:
        print(S + 'es')

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 61700
//set many funcs
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define inf 1145141919
#define llinf 1145141919810364364
#define mod 1000000007

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=r;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}

int main(void){
    long long n,a,b,c,d,sg,i;
    long long umax,umin,smax,smin;
    scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
    sg = a-b;
    for(i=0;i<=(n-1);i++){
        umax = d*i;umin = c*i;
        smax = d*(n-i-1);smin = c*(n-i-1);
        if(umin-smax <= sg && sg <= umax-smin){
            printf("YES\n");return 0;
        }
    }
    printf("NO\n");
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    
    int ans_a = 0;
    int ans_b = 0;
    
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) {
            ans_a += a.at(i);
        }
        else {
            ans_b += a.at(i);
        }
    }
    
    cout << ans_a - ans_b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
int main(int argc, char const *argv[]) {

    std::string S;
    std::cin >> S;
    ll ans = 0;
    ll add;
    int n = S.size() - 1;

    for (int bit = 0; bit < (1 << n); ++bit) {

        std::vector<int> partition_list;
        for (int i = 0; i < n; ++i) {
            if (bit & (1 << i)) { // i が bit に入るかどうか
                partition_list.push_back(i);
            }
        }
        int start = 0;
        std::string substr;
        // std::cout << "bit" << bit << '\n';
        for (int i = 0; i < partition_list.size(); ++i) {
            substr = S.substr(start, partition_list[i] - start + 1);
            start = partition_list[i] + 1;
            add = std::atol(substr.c_str());
            ans += add;
            // std::cout << add << '\n';
        }
        substr = S.substr(start, S.size() - start + 1);
        add = std::atol(substr.c_str());
        // std::cout << add << '\n';
        ans += add;
    }
    std::cout << ans << '\n';

    return 0;
}


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

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

  // NOTE: A=1, B=1, A<B, A>B, A=B

  int a=std::min(A, B), b=std::max(A, B);
  int G[100][100]={};
  int y=1, x=1;
  for (int i=0; i+1<a; ++i) {
    y = i/25*4+1;
    x = i%25*4+1;

    G[y-1][x-1] = G[y-1][x] = G[y-1][x+1] = 1;
    G[y][x-1] = G[y][x+1] = 1;
    G[y+1][x-1] = G[y+1][x] = G[y+1][x+1] = 1;
  }

  if (A == B) {
    G[99][99] = 1;
  } else {
    b -= a;
    x = y = 99;
    while (b--) {
      G[y-1][x-1] = G[y-1][x] = G[y][x-1] = 1;
      if ((x -= 2) < 0) {
        y -= 2;
        x = 99;
      }
    }
  }

  printf("100 100\n");

  char ch[]=".#";
  if (A < B) std::swap(ch[0], ch[1]);
  for (int i=0; i<100; ++i)
    for (int j=0; j<100; ++j)
      printf("%c%s", ch[G[i][j]], j<99? "":"\n");
}


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

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

int main(){
    ll n;
    cin >> n;
    ll a[n];
    rep(i, n) cin >> a[i];
    ll gl[n], gr[n];
    gl[0] = a[0], gr[n - 1] = a[n - 1];
    
    ll tmpl = a[0], tmpr = a[n - 1];
    for (int i = 1; i < n; i++){
        tmpl = gcd(tmpl, a[i]);
        gl[i] = tmpl;
    }

    for (int i = n - 2; i >= 0; i--){
        tmpr = gcd(tmpr, a[i]);
        gr[i] = tmpr;
    }

    ll ans = 1;
    rep(i, n - 2){
        ans = max(ans, gcd(gl[i], gr[i+2]));
    }
    ans = max(gl[n - 2], ans);
    ans = max(gr[1], ans);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
r = 10001
sqrt = int(r**0.5)
p = [1]*r
twin = [0]*r
p[0] = 0
p[1::2] = [0 for x in range(1,r,2)]
for i in range(2,r,2):
	if p[i]:
		p[2*i+1::i+1] = [0 for x in range(2*i+1,r,i+1)]
		if p[i-2]:
			twin[i:i+300] = [i+1 for x in range(i,i+300)]
		
while True:
	n = int(raw_input())
	if n == 0: break
	print twin[n-1]-2,twin[n-1]

Measured memory_bytes: 4752
def printArrLine( arr ):
    print(' '.join(list(map(str,arr))))
    
def inputArrLine():
    return [int(i) for i in input().split()]

def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)

ar = inputArrLine()
a = ar[0]
b = ar[1]

print(gcd(a,b))


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

struct point{
    int x,y,h;
};

int main(void){
    int N; cin >> N;
    point A[N];
    point base;
    for(int i=0; i<N; i++){
        cin >> A[i].x >> A[i].y >> A[i].h;
        if(A[i].h!=0){
            base.x=A[i].x; base.y=A[i].y; base.h=A[i].h;
        }
    }

    for(int i=0; i<=100; i++){
        for(int j=0; j<=100; j++){
            bool flg=true;
            int h=base.h+abs(base.x-i)+abs(base.y-j);

            for(int k=0; k<N; k++){
                if(A[k].h!=max(h-abs(A[k].x-i)-abs(A[k].y-j),0)){
                    flg=false; break;
                }
            }

            if(flg){
                printf("%d %d %d\n", i, j, h);
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N, M int
	fmt.Scan(&N, &M)
	if N >= M {
		fmt.Println(0)
		return
	}
	A := make([]int, M)
	for i := 0; i < M; i++ {
		fmt.Scan(&A[i])
	}
	sort.Ints(A)
	difs := make([]int, M-1)
	for i := 1; i < M; i++ {
		difs[i-1] = abs(A[i-1] - A[i])
	}
	sort.Ints(difs)
	ans := 0
	for i := 0; i < M-N; i++ {
		ans += difs[i]
	}
	fmt.Println(ans)
}

func abs(x int) int {
	if x < 0 {
		x *= -1
	}
	return x
}


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

int main(){
 int n,k;
  cin >> n >> k ;
  vector<ll> h(n);
  rep(i,n){
	cin >> h.at(i);
  }
  sort(h.begin(),h.end());
  ll mindiff=1000000000;
  vector<ll> diff(n-k+1);
  rep(i,n-k+1){
	diff.at(i)=h.at(i+k-1)-h.at(i);
    mindiff= min(mindiff,diff.at(i));
  }
  cout << mindiff <<endl;
  
}

Measured memory_bytes: 1792
using System;
using System.IO;

class Solve{
    static void Main(string[] args){
        var N = int.Parse(Console.ReadLine());
        var arr = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var D = arr[0];
        var answer = arr[1];
        for (int i = 0; i < N; i++){
            var A = int.Parse(Console.ReadLine());
            for (int day = 1; day <= D; day += A){
                answer++;}}
        var writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();}}

Measured memory_bytes: 27500
import bisect

def sieve(n):
	ret = []
	divlis = [-1]*(n+1)  # 何で割ったかのリスト(初期値は-1)
	flag = [True]*(n+1)
	flag[0] = False
	flag[1] = False
	ind = 2
	while ind <= n:
		if flag[ind]:
			ret.append(ind)
			ind2 = ind**2
			while ind2 <= n:
				flag[ind2] = False
				divlis[ind2] = ind
				ind2 += ind
		ind += 1
	#何で割ったかのリストを取得したいとき, divlisも出力する
	return ret

svl = set(sieve(10**5))
ansl = []

for i in svl:
	if i * 2 - 1 in svl:
		ansl.append(i*2-1)

ansl.sort()

q = int(input())

for _ in range(q):
	l, r = map(int,input().split())
	ans = bisect.bisect_right(ansl, r) - bisect.bisect_left(ansl, l)
	print(ans)

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

int main(){
  	string S,T;
  	int A,B;
  	string U;
  	cin >> S >> T >> A >> B >> U;
  	if(U==S){
      cout << A-1 << " " << B << endl;
    }
 	else {
		cout << A << " " << B-1 << endl;
    }
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a,b,c;
    cin >>a>>b>>c;
    if(a==b){
      cout<<c<<endl;
    }
    else if(c==b){
      cout<<a<<endl;
    }
    else if(a==c){
      cout<<b<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define ld long double
using namespace std;
int32_t main()
{
    IOS;
    int n,m=0;
    cin>>n;
    if(n%1000==0)
    	cout << "0" << endl;
    else
    cout << 1000-(n%1000) << endl;
}

Measured memory_bytes: 3672
#include <stdio.h>

int main(){
	int x,ans;
	int a,b,c;

	scanf("%d",&x);
	
	a = x / 500;
	
	ans = a * 1000;
	
	b = x - (500 * a);
	c = b / 5 * 5;
		
	ans = ans + c;
	
	printf("%d",ans);
	
	return 0;
}


Measured memory_bytes: 128
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
b.append(0)
ans = min(a[0],b[0])
b[0] = max(0,b[0]-a[0]) 
for i in range(n):
    ans += min(a[i+1],b[i])
    a[i+1] = max(0,a[i+1]-b[i])
    ans += min(a[i+1],b[i+1])    
    b[i+1] = max(0,b[i+1]-a[i+1]) 
print(ans)

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

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

using ll = long long;
using ull = unsigned long long;

int main() {
    int h, w, k, s[10][1000];
    cin >> h >> w >> k;
    char c;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> c;
            s[i][j] = c - '0';
        }
    }
    int ans = INF;
    for (int l = 0; l < 1 << (h - 1); ++l) {
        int cnt[10] = { 0 };
        int sum = 0;
        for (int j = 0, bj = 0; j < w; ++j) {
            int suf = 0;
            for (int i = 0, lt = l; i < h; ++i, lt >>= 1) {
                cnt[suf] += s[i][j];
                if (cnt[suf] > k) {
                    if (j == bj) {
                        j = w;
                        sum = INF;
                        break;
                    }
                    fill(cnt, cnt + h, 0);
                    sum++;
                    bj = j;
                    j--;
                    break;
                }
                if (lt & 1) {
                    if (j == 0)
                        sum++;
                    suf++;
                }
            }
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()

typedef long long int ll;

//ll num[50];
//ll num2[50];
ll num[11];
stack<char> stk;
//set<ll> sll;
//map<string,ll> mp,mp1;
//map<string,ll>::iterator iter;
//deque<char> deq;



int main(void)
{
    double ans=0.0,d,d1,d2;
    //float f,g,h;
    long long int m,n,i,j,k=1;
    long long int a,a1=0,a2=0,a3=0;
    string s,s1,s2,s11,s22;
    char c,c1;
    a=a1=a2=a3=0;
    cin>>s;
    n=s.size();
    s1.assign(s,0,(n-1)/2);
    s11=s1;
    s2.assign(s,n/2+1,(n-1)/2);
    s22=s2;
    reverse(all(s2));
    if(s1==s2)
    {
        reverse(all(s11));
        if(s1==s11 && s2==s22)
            cout<<"Yes";
        else cout<<"No";
    }
    else
        cout<<"No";
    return 0;
}





Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] l = new int[n];
		int[] r = new int[n];
		int num = 0;
		for(int i=0; i<n; i++){
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
			num += r[i] - l[i] + 1;
		}
		System.out.println(num);
	}
}

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

#define rep(i,n) for(int i=0;i<(n);i++)

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

	int N;
	cin >> N;

	int P[N];
	rep(i,N)
		cin >> P[i];

	int t = 0;
	for(int i = 1; i < N-1; i++) {
		if ((min({P[i-1], P[i], P[i+1]}) != P[i]) && (max({P[i-1], P[i], P[i+1]}) != P[i]))
			t++;
	}

	cout << t << endl;

	return 0;
}



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

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second > b.second;
    }
}

bool compare(pair<int, int> a, pair<int, int> b) {
    return a.first < b.first;
}

int main()
{
    int n,m;
    int a[100001],b[100001];
    cin>>n>>m;
    vector<pair<int,int>> p(n);
    ll ans=0;
    for (int i = 0; i < n; i++)
    {
        cin>>a[i]>>b[i];
        p[i] = make_pair(a[i], b[i]);
    }
    sort(p.begin(), p.end(), compare_by_b);
    // for (int i = 0; i < n; i++)
    // {
    //     cout<<p[i].first<<" "<<p[i].second<<endl;
    // }
    
    std::priority_queue<ll> q;
    int j=0;
    for (int i = 1; i <= m; i++)
    {
        for(;p[j].first==i;j++){
            q.push(p[j].second);
        }
        if (!q.empty()){
            ans+=q.top();
            q.pop();
        }
        //cout<<i<<" "<<p[i].first<<" "<<p[i].second<<" "<<ans<<endl;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 2936
#include<bits/stdc++.h>
    using namespace std;
    # define ll long long 
   
    
    const int mxN=2e5;
    int n, m;
    ll k;
    
    int main(){
        #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin);
            freopen("output.txt","w",stdout);
        #endif
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        

        ll n,m,k;
        cin>>n>>m>>k;
        vector<ll>a(n+1);
        vector<ll>b(m+1);

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

        for(ll i=0;i<m;i++){
            ll x; cin>>x;
            b[i+1]=b[i]+x;
        }
         
       
        ll ans=0; 
      
        for(ll i=0;i<=n;i++){

            ll left=k-a[i];
           
            if(left < 0)
                continue;
           
            ll j=lower_bound(b.begin() ,b.end(), left) - b.begin();
           
            if(  j>m || b[j] > left ){
               j--;
            } 

            ans=max(ans,(i+j));

        }  

        cout<<ans<<endl;

    }


Measured memory_bytes: 6356
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

num = sum(a)

for i in range(n):
    if a[i]+a[i+1] >= b[i]:
        if a[i] >= b[i]:
            a[i] -= b[i]
        else:
            a[i+1] += a[i]-b[i]
            a[i] = 0
    else:
        a[i] = 0
        a[i+1] = 0

print(num -sum(a))

Measured memory_bytes: 82020
fn main() {
    let v = read_vec::<u64>();
    let n = v[0];
    let a = v[1];
    let b = v[2];

    let mut ans = (n / (a + b)) * a;
    let x = n % (a + b);
    ans += std::cmp::min(x, a);
    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
def rec(s, i, m, ans)
  if i == N
    flag = true
    M.times do |i|
      on = 0
      m[i].each do |j|
        on += s[j-1]
      end
      if P[i] != (on%2)
        flag = false
        break
      end
    end
    ans += 1 if flag
    return ans
  end

  ans = rec(s, i+1, m, ans) # スイッチそのまま
  s[i] = 1
  ans = rec(s, i+1, m, ans) # スイッチ・オン
  s[i] = 0

  return ans
end

N, M = gets.split.map(&:to_i)
m = []
M.times do
  x = gets.split.map(&:to_i)
  x.shift
  m << x
end
P = gets.split.map(&:to_i)

s = [0]*N

puts rec(s, 0, m, 0)

Measured memory_bytes: 1788
// ABC170 - B
function main(input) {
  var inputs = input.trim().split('\n');
  var X = inputs[0].split(' ')[0] - 0;
  var Y = inputs[0].split(' ')[1] - 0;

  for (var cr = 0; cr <= X; cr++) {
    tu = X - cr;
    if (cr * 2 + tu * 4 === Y) {
      console.log('Yes');
      return;
    }
  }

  console.log('No');
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29620
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
int n,m;
vector<int>con[100111];
bool f[100111];
int col[100111];
bool dfs(int x,int c=2)
{
	bool ret=1;
	col[x]=c;
	for(int i=0;i<con[x].size();i++)
	{
		if(col[con[x][i]]!=0)
		{
			if(col[con[x][i]]!=(c^1))ret=0;
			continue;
		}
		if(!dfs(con[x][i],c^1))ret=0;
	}
	return ret;
}
int main()
{
	getii(n,m);
	for(int i=1;i<=m;i++)
	{
		int x,y;
		getii(x,y);
		con[x].PB(y);
		con[y].PB(x);
		f[x]=f[y]=1;
	}
	ll ans=0;
	int useless=0;
	for(int i=1;i<=n;i++)useless+=!f[i];
	int bi=0,nbi=0;
	for(int i=1;i<=n;i++)
	{
		if(f[i]&&!col[i])
		{
			int type=dfs(i);
			if(type==1)bi++;else nbi++;
		}
	}
//	cout<<useless<<" "<<bi<<" "<<nbi<<endl;
	ans+=1ll*n*useless*2-1ll*useless*useless;
	n-=useless;
	ans+=1ll*bi*bi*2+2ll*nbi*bi+1ll*nbi*nbi;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 10112
#include <iostream>

using namespace std;

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

  int x = 0;
  int ans = 0;
  for (int i=0; i < N; i++) {
    if (S[i] == 'I')
      x++;
    else if (S[i] == 'D')
      x--;

    ans = max(ans, x);
  }

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


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



int main(){
	ull n,temp = 0,ans = 1;
	cin >> n;
	ull prime_num[1001] = {0};
	
	rep(i,2,n+1){
		temp = i;
		while(temp > 1){
			rep(j,2,1001){
				if(temp % j == 0){
					prime_num[j]++;
					temp /= j;
					break;
				}
			}
			
		}
	}
	
	rep(i,1,1001){
		if(prime_num[i]){
			ans *= (prime_num[i]+1) % 1000000007;;
			ans %= 1000000007;
		}
	}
	
	cout << ans << endl;
	
  	return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int w, a, b; cin >> w >> a >> b;
    if (a+w < b) cout << b-(a+w) << endl;
    else if (b+w < a) cout << a-(b+w) << endl;
    else cout << 0 << endl;
}

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

from functools import reduce
from operator import mul
from collections import defaultdict, Counter
from heapq import heappush, heappop
import sys
from math import sqrt, floor

sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
INF = 10 ** 9 + 1  # sys.maxsize # float("inf")


def debug(*x):
    print(*x)


def solve(N):
    ret = 0
    for i in range(1, N + 1):
        num = N // i
        end = num * i
        ret += (i + end) * num // 2
    print(ret)


def main():
    N = int(input())
    solve(N)


def _test():
    """
    >>> solve(4)
    23

    >>> solve(100)
    26879

    >>> solve(10000000)
    838627288460105
    """
    import doctest
    doctest.testmod()


def as_input(s):
    "use in test, use given string as input file"
    import io
    global read, input
    f = io.StringIO(s.strip())
    input = f.readline
    read = f.read


USE_NUMBA = False
if (USE_NUMBA and sys.argv[-1] == 'ONLINE_JUDGE') or sys.argv[-1] == '-c':
    print("compiling")
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', solve.__doc__.strip().split()[0])(solve)
    cc.compile()
    exit()
else:
    input = sys.stdin.buffer.readline
    read = sys.stdin.buffer.read

    if (USE_NUMBA and sys.argv[-1] != '-p') or sys.argv[-1] == "--numba":
        # -p: pure python mode
        # if not -p, import compiled module
        from my_module import solve  # pylint: disable=all
    elif sys.argv[-1] == "-t":
        _test()
        sys.exit()
    elif sys.argv[-1] != '-p' and len(sys.argv) == 2:
        # input given as file
        input_as_file = open(sys.argv[1])
        input = input_as_file.buffer.readline
        read = input_as_file.buffer.read

    main()


Measured memory_bytes: 9628
#include <iostream>

int main()
{
  	int X, A, B;
  	std::cin >> X >> A >> B;
  	if(A >= B){
      	std::cout << "delicious";
    }else if(B - A <= X){
      	std::cout << "safe";
    }else{
      	std::cout << "dangerous";
    }
  	return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N; cin >> N;
    int ans = 1;
    while(ans*2 <= N){
        ans *= 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

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 mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)
long long calc(long long  k,long long  m){
	if(m==0)return 1;
	if(m==1)return k%mod;
	long long s = calc(k,m/2);
	if(m%2==0){
		return (s*s)%mod;
	}else{
		long long ans;
		ans = (s*s)%mod;
		return (k*ans)%mod;
	}
}
int main(){
    ll h,w,k;
    cin >> h >> w >> k;
    ll ans = 0; 
    if(k>=2){
        ll tmp = 0;
        tmp = k*(k-1)%mod;
        tmp *=h;
        tmp %= mod;
        tmp *=w;
        tmp %= mod;
        tmp *=(k+1);
        tmp %= mod;
        tmp *=calc(3,mod-2);
        tmp %= mod;
        rep(i,k-2){
            tmp *= (h+w-2-i)%mod;
            tmp %= mod;
        }
        ans += tmp;
        ans %= mod;
    }
    //cerr << ans << endl;
    ll tmp = h+w;
    tmp *=(k*(k+1))/2%mod;
    tmp %= mod;
    rep(i,k-1){
        tmp *= (h+w-1-i)%mod;
        tmp %= mod;
    }
    ans += tmp;
    ans %= mod;
    //cerr << ans << endl;
    tmp = 1;
    rep(i,k){
        tmp *= (h+w-i)%mod;
        tmp %= mod;
    }
    tmp *=k;
    tmp %= mod;
    ans += tmp;
    ans %= mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;

int main(){
    int N,tmp;
    cin >> N;
    vector<int> a(N);

    rep(i,N-1){
        cin >> tmp;
        a[tmp-1]++;
    }

    rep (i,N){
        cout << a[i] << endl;
    }

    return 0;
}

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

int N, M;
vector<int> par;

void init_union_find(int n) {
	par.resize(n, -1);
}

int find(int x) {
	if (par[x] < 0) return x;
	return par[x] = find(par[x]);
}

bool same(int x, int y) {
	return find(x) == find(y);
}

int get_size(int x) {
	return -par[find(x)];
}

bool unite(int x, int y) {
	x = find(x); y = find(y);
	if (x == y) return false;
	if (get_size(x) < get_size(y)) swap(x, y);
	par[x] += par[y];
	par[y] = x;
	return true;
}

void input_init(void) {
	cin >> N >> M;
	init_union_find(N + 1);
}

void solve(void) {
	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b;
		unite(a, b);
	}
}

int get_ans(void) {
	int max_cnt = 0;
	for (int i = 1; i <= N; ++i) {
		int cnt = get_size(i);
		max_cnt = max(cnt, max_cnt);
	}
	return max_cnt;
}

int main(void) {
	input_init();
	solve();
	int ans = get_ans();
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 3996
#include<bits/stdc++.h>
#define mod (long)(1e9 + 7)
using namespace std;

long dp[3000][3000];

long solve(int curr, int howManyLessLeft, string &s) {
	if(curr == s.size()) {
		return 1;
	}
	if(dp[curr][howManyLessLeft] != -1) return dp[curr][howManyLessLeft];
	long res = 0;
	if(s[curr] == '<') {
		int howManyHighLeft = (int)s.size() + 1 - (curr + 1 + howManyLessLeft);
		
		for(int i = 1; i <= howManyHighLeft; ++i) {
			res = (res + solve(curr + 1, howManyLessLeft + i - 1, s)) % mod;
		}
	}
	else {
		for(int i = 1; i <= howManyLessLeft; ++i) {
			res = (res + solve(curr + 1, i - 1, s)) % mod;
		}
	}
	return dp[curr][howManyLessLeft] = res;

}

int main() {
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	
	int n;
	cin >> n;
	if(n == 1) {
		cout << 1;
		return 0;
	}
	string s;
	cin >> s;
	long res = 0;
	memset(dp, 0, sizeof dp);
	for(int i = 0; i <= n - 1; ++i) {
		dp[n - 1][i] = i + 1;
	}
	for(int i = n - 2; i >= 0; --i) {		// curr
		for(int j = 0; j <= n - 1; ++j) {	// lessCount
			if(s[i] == '<') {
				// cerr << "j:" <<j<<endl;
				int howManyHighLeft = n - (i + 1 + j);
				// cerr << i <<" " <<j << ":" << howManyHighLeft << endl;
				if(howManyHighLeft > 0) {
					dp[i][j] = (dp[i + 1][j + howManyHighLeft - 1] - 
						(j - 1 >= 0 ? dp[i + 1][j - 1] : 0) + mod) % mod;
				}
				// cerr<<"new j:" << j << endl;
			}
			else {
				if(j == 0) continue;
				dp[i][j] = dp[i + 1][j - 1];
			}
		}
		for(int j = 1; j <= n - 1; ++j) {
			dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
		}
	}
	cout << dp[0][n - 1];

	return 0;
}

Measured memory_bytes: 73916
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n) ;i++)

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

int main() {
  string s;
  cin >> s;
  if(s=="AAA"||s=="BBB"){
    cout << "No" <<endl;
  }
  else{
    cout << "Yes" << endl;
  }
  
    
  return 0;

}

Measured memory_bytes: 3628
n=int(input())
al=[0]*n
bl=[0]*n
cl=[0]*n
for i in range(n):
    a,b,c=map(int,input().split())
    if i==0:
        al[0]=a;bl[0]=b;cl[0]=c
    else:
        al[i]=max(bl[i-1],cl[i-1])+a
        bl[i]=max(al[i-1],cl[i-1])+b
        cl[i]=max(al[i-1],bl[i-1])+c
print(max(al[-1],bl[-1],cl[-1]))

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

using namespace std;

typedef long long ll;
// typedef pair<ll, ll> P;
typedef pair<int, int> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  cin >> n;
  vector<int> l(n), r(n);
  REP(i, n) {
    cin >> l[i] >> r[i];
    r[i]++;
  }
  int l_max = l[0], r_min = r[0];
  REP(i, n) {
    l_max = max(l_max, l[i]);
    r_min = min(r_min, r[i]);
  }
  int len_max = 0;
  REP(i, n) len_max = max(len_max, r[i] - l[i]);
  int ans = len_max + max(0, r_min - l_max);
  vector<P> vec;
  REP(i, n) {
    int a = max(0, r[i] - l_max);
    int b = max(0, r_min - l[i]);
    vec.push_back(P(-a, b));
  }
  sort(ALL(vec));
  vector<int> s(n), t(n);
  REP(i, n) {
    if (i == 0) {
      s[i] = -vec[i].first;
    } else {
      s[i] = min(s[i - 1], -vec[i].first);
    }
  }
  RREP(i, n) {
    if (i == n - 1) {
      t[i] = vec[i].second;
    } else {
      t[i] = min(t[i + 1], vec[i].second);
    }
  }
  REP(i, n - 1) ans = max(ans, s[i] + t[i + 1]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2548
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  if (S[0] == S[1] )cout << "Bad" << endl;
  else if (S[1] == S[2])cout << "Bad" << endl;
  else if (S[2] == S[3])cout << "Bad" << endl;
  else cout<<"Good"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define pb push_back
#define f first
#define s second
#define mp make_pair
#define SZ(x) ((int)(x.size()))
#define FOI(i, a, n) for(int i = int(a); i <= int(n); i++)
#define FOD(i, a, n) for(int i = int(a); i >= int(n); i--)
#define IN(x, y) ((y).find(x) != (y).end())
#define ALL(t) t.begin(),t.end()
#define MSET(tabl,i) memset(tabl, i, sizeof(tabl))
#define PSET(x,y) fixed<<setprecision(y)<<lf(x)
#define DBG(c) cout << #c << " = " << c << endl;
#define Rtime1 ((double)clock()/(double)CLOCKS_PER_SEC)
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);


typedef long long ll;
typedef long double lf;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef vector < int > vi;
typedef vector<vi> vvi;
typedef complex<double> base;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << std::endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const int N = 3e5 + 5;
const int lgN = 1e6+5;
const ll MOD = 1e9+7;
const ll MOD2 = 1299709;
const ll MOD3 = 1e9 + 9;
const lf pi = 3.141592653589793238462643383;
const ll IMAX = 4e18 + 5; 
const double PI = 3.141592653589793;


template<class T>
using max_pq = priority_queue<T>;
template<class T>
using min_pq = priority_queue<T,vector<T>,greater<T>>; 
template<class T>
using OST = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ll x,y;
template<class T> T gcd(T a,T b){ if(a==0) {x=0,y=1; return b;}T gc=gcd(b%a,a);T temp;temp=x;x=y-(b/a)*temp;y=temp;return gc;}

//(a^x)%m   
ll po(ll a, ll x,ll m){ if(x==0){return 1;}ll ans=1;ll k=1;  while(k<=x) {if(x&k){ans=((ans*a)%m);} k<<=1; a*=a; a%=m; }return ans; } 

int dp[N],h[N];

int main(){
    sync
    int n,k;
    cin>>n>>k;
    FOI(i,1,n)
    cin>>h[i];
    h[0] = h[1];
    FOI(i,2,n)
    {
        dp[i] = dp[i-1] + abs(h[i]-h[i-1]);
        int r = max(i-k, 0);
        FOD(j, i-2, r){
            dp[i] = min(dp[i], dp[j] + abs(h[i]- h[j]));
        }
    }
    cout<<dp[n]<<endl;
}


Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;

public class Program{
    public static void Main(){
        var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int w = input[0], a = input[1], b = input[2];
        if(a>b+w)Console.WriteLine(a-(b+w));
        else if(b>a+w)Console.WriteLine(b-(a+w));
        else Console.WriteLine(0);
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
int main(){
  stringstream ss;
  while(true){
    int h,w,i,j;
    cin>>h>>w;
    if(h+w==0)break;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
        ss<<((i==0||i==h-1||j==0||j==w-1)?"#":".");
      }
      ss<<endl;
    }
    ss<<endl;
  }
  cout<<ss.str();
}


Measured memory_bytes: 3224
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val d = readLine()!!.split(" ").map(String::toInt)

    var sum = 0
    for (i in 0 until d.size - 1) {
        for (j in i+1 until d.size) {
            sum += d[i] * d[j]
        }
    }
    println(sum)
}




Measured memory_bytes: 36084
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,f,e) for(int (i)=(f); (i)<(e); (i)++)
#define repr(i,e,f) for(int (i)=(e-1); (i)>=(f); (i)--)

const ll MOD = 1e9+7;
const int INF = (int)1e9+7;

// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
//   for( int i = 0; i < N; i++ ){
//     cin >> v >> w;
//     items.push_back( make_tuple(v, w) ); // item : (value, weight)
//   }

int main(){
    int N;
    cin >> N;
    int ans = 0;
    if(N%2==0) ans = N/2;
    else if(N%2==1) ans = N/2+1;
    cout << ans; 
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#include<cassert>

using namespace std;

#define sz(x) (int)(x.size())
#define fi(a, b) for(int i=a;i<b;++i)
#define fj(a, b) for(int j=a;j<b;++j)
#define fk(a, b) for(int k=a;k<b;++k)
#define pb push_back
#define mp make_pair
typedef long long ll;
///////////////////////
int const N = 1e5 + 41;

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

ll gcd(ll a, ll b){
	if(!a){
		return b;
	}
	return gcd(b % a, a);
}

void read(){
	scanf("%d",&n);
	fi(0, n){
		scanf("%d %d",&a[i],&b[i]);
	}
}

void solve(){
	ll ans = 0;
	for(int i=n-1;i>=0;--i){
		ans += (b[i] - ((ans + a[i]) % b[i])) % b[i];
	}

	printf("%lld\n",ans);
}


int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	read();
	solve();




	return 0;
}

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

lint n, d, a;
vector<pair<lint, lint>> xh;

int main() {
    cin >> n >> d >> a;
    xh.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> xh[i].first >> xh[i].second;
    }
    sort(xh.begin(), xh.end());
    vector<lint> x(n), h(n);
    for (int i = 0; i < n; i++) {
        x[i] = xh[i].first, h[i] = xh[i].second;
    }
    // right[i]:[i,right[i])を攻撃できる
    vector<lint> right(n);
    for (int i = 0; i < n; i++) {
        right[i] = upper_bound(x.begin(), x.end(), x[i] + 2 * d) - x.begin();
    }
    vector<lint> damage(n, 0);
    lint dmg_now = 0;
    lint ans = 0;
    for (int i = 0; i < n; i++) {
        dmg_now -= damage[i];
        if (h[i] - dmg_now <= 0) {
            continue;
        } else {
            lint rem = h[i] - dmg_now;
            lint num = (rem + a - 1) / a;
            dmg_now += num * a;
            if (right[i] < n) {
                damage[right[i]] += num * a;
            }
            ans += num;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 9600
while True:
    n = int(input())
    if n == 0:
        break
    scores = [int(line) for line in input().split()]
    scores.sort()
    c = scores[1] - scores[0]
    for i in range(2, n):
        if scores[i] - scores[i - 1] < c:
            c = scores[i] - scores[i - 1]
    print(c)



Measured memory_bytes: 5632
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long int ll;
int main(){
	int q,h,s,d,n;
	scanf("%d%d%d%d%d",&q,&h,&s,&d,&n);
	int x = min(min(8*q,4*h),min(2*s,d));
	int y = min(4*q,min(2*h,s));
	ll ans = (ll)n/2*x;
	if(n%2==1) ans += y;
	printf("%lld\n",ans);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int n;
int x[105];
int main(){
	cin >> n;
	int sum = 0;
	for(int i = 0 ; i < n ; i++){
		scanf("%d", &x[i]);
		sum += x[i];
	}
	int cor = sum / n ;
	int cor1 = cor + 1;
	int res = 0, res1 = 0;
	for(int i = 0 ; i < n ; i++){
		res += (cor - x[i]) * (cor - x[i]);
		res1 += (cor1 - x[i]) * (cor1 - x[i]);
	}
	res = min(res, res1);	
	cout << res << "\n";
	return 0;
} 

Measured memory_bytes: 256
//Utkarsh-raj

#include<bits/stdc++.h>

#define ll long long int
#define vc vector
#define mod 100000000007
#define mp make_pair
#define pb push_back
#define nl cout<<endl;
#define ff first
#define ss second

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ifstream myFile("task.in");
    if(!myFile.fail())
    {
        assert(freopen("task.in", "r", stdin));
    }

    int n;
    cin>>n;

    vector<ll> v(n);

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

    vector<ll> dp(n, 0);
    for(int i=1; i<n; i++){
        dp[i] = dp[i-1] + abs(v[i] - v[i-1]);

        if(i-2 >= 0){
            dp[i] = min(dp[i], dp[i-2] + abs(v[i] - v[i-2]));
        }
    }

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

    return 0;
}


Measured memory_bytes: 4712