akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.buffer.readline

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict
from itertools import combinations, permutations
from itertools import accumulate
from math import ceil, sqrt, pi

N, M = map(int, input().split())
A = list(map(int, input().split()))

S = sum(A)
cnt = 0

for a in A:
    if a / S >= 1 / 4 / M:
        cnt += 1

print("Yes" if cnt >= M else "No")

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

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

  unsigned N = 0;
  std::cin >> N;
  std::vector<int> vec(N, 0); 
  for (unsigned i = 0; i < N; ++i)
  {
    std::cin >> vec[i];
  }
  std::vector<int> cache(vec.size(), 0); 
  cache[0] = 0;
  cache[1] = abs(vec[1] - vec[0]);
  for (size_t i = 2; i < vec.size(); ++i)
  {
    cache[i] = std::min(cache[i-2] + abs(vec[i-2] - vec[i]), cache[i-1] + abs(vec[i-1] - vec[i]));
  }
  std::cout << cache.back();

  return 0;
}

Measured memory_bytes: 1024
import queue
n,m=map(int,input().split())
road_list=[set() for i in range(n)]
mitisirube=[0]*n
mitisirube[0]=1
for i in range(m):
    a,b=map(int,input().split())
    road_list[a-1].add(b)
    road_list[b-1].add(a)

q = queue.Queue()

counter_set=set()
counter_set.add(1)
for i in road_list[0]:
    q.put(i)
    mitisirube[i-1]=1
    counter_set.add(i)

while not q.empty():
    tmp=q.get()
    for i in road_list[tmp-1]:
        if i not in counter_set:
            q.put(i)
            counter_set.add(i)
            if mitisirube[i-1]==0:
                mitisirube[i-1]=tmp
print("Yes")
for i in range(1,len(mitisirube)):
    print(mitisirube[i])

Measured memory_bytes: 132024
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - Exam and Wizard
 */

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

using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef long long ll;

/* global variables */

int as[MAX_N], bs[MAX_N], ps[MAX_N];

/* subroutines */

/* main */

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

  ll asum = 0, bsum = 0;
  for (int i = 0; i < n; i++) scanf("%d", as + i), asum += as[i];
  for (int i = 0; i < n; i++) scanf("%d", bs + i), bsum += bs[i];

  if (asum < bsum) {
    puts("-1");
    return 0;
  }

  ll msum = 0;
  int m = 0, k = 0;
  for (int i = 0; i < n; i++) {
    if (as[i] < bs[i]) msum += bs[i] - as[i], m++;
    else if (as[i] > bs[i]) ps[k++] = as[i] - bs[i];
  }
  sort(ps, ps + k);
  //printf("msum=%lld, k=%d\n", msum, k);

  for (int i = k - 1; i >= 0 && msum > 0; i--)
    msum -= ps[i], m++;

  printf("%d\n", m);
  return 0;
}


Measured memory_bytes: 1280
def gcd(a,b):
    if a<b:
        a,b=b,a
    if (a%b)==0:
        return b
    else:
        return gcd(b,a%b)

n=int(input())
a=[int(i) for i in input().split()]
l=[None for i in range(n)]
l[0]=a[0]
for i in range(1,n):
    l[i]=gcd(l[i-1],a[i])
r=[None for i in range(n)]
r[-1]=a[-1]
for i in range(n-2,-1,-1):
    r[i]=gcd(r[i+1],a[i])
res=max(r[1],l[-2])
for i in range(1,n-1):
    res=max(res,gcd(l[i-1],r[i+1]))
print(res)


Measured memory_bytes: 67044
import java.util.Scanner;
import java.util.Arrays;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] x = new int[n];
    int[] rx = new int[n];
    for (int i = 0; i < n; i++) {
      x[i] = sc.nextInt();
      rx[i] = x[i];
    }
    Arrays.sort(rx);
    int h = rx[n / 2];
    int l = rx[(n - 1) / 2];
    int r = rx[(n - 1) / 2 + 1];
    for (int i = 0; i < n; i++) {
      if (x[i] >= h) {
        System.out.println(l);
      } else {
        System.out.println(r);
      }
    }
  }
}


Measured memory_bytes: 94408
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma comment(linker, "/STACK:16777216")
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <random>
#include <bitset>
#include <time.h>
#include <string>
#include <cstdio>
#include <vector>
#include <cassert>
#include <iomanip>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
//#define endl '\n'
#define mp make_pair
#define pbc push_back
#define pob pop_back()
#define empb emplace_back
#define sp system("pause")
#define queuel queue<long long>
#define all(x) (x).begin(), (x).end()
#define matrix vector<vector<ll>>
#define pin(p) cin >> p.first >> p.second;
#define rev(v) reverse(v.begin(), v.end());
#define mx(a) max_element(a.begin(), a.end());
#define mn(v) min_element(v.begin(), v.end());
#define sout(s, c) for (auto i : s) cout << i << c;
#define pout(p) cout << p.first << " " << p.second;
#define er(v, l, r) erase(v.begin() + l, v.begin() + r);
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vout(v, c) for (ll i = 0; i < v.size(); ++i) cout << v[i] << c;
#define pushi(v, a) for (ll i = 0; i < a.size(); ++i) v.push_back(a[i]);
#define sin(s, n) for (ll i = 0; i < n; ++i){ll a; cin >> a; s.insert(a);}
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
using namespace std;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<vector<char> > fd;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
const ll INF = 1e18;
const ll inf = 1e9;
const ld PI = acos(-1.0);
const ll mod1 = inf + 7;
const ll mod2 = inf + 9;
const ll MAXN = 200001;
const ld EPS = 1e-7;
signed main()
{
	fastio();
	int n, t;
	cin >> n >> t;
	int mx = inf;
	vector<pair<int, int>> a(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i].first >> a[i].second;
		if (a[i].second <= t)
		{
			mx = min(mx, a[i].first);
		}
	}
	if (mx == inf)
	{
		cout << "TLE";
	}
	else
	{
		cout << mx;
	}
	sp;
}


Measured memory_bytes: 504
#include<iostream>
#include<bitset>
using namespace std;
typedef long long ll;

const ll MOD = 1e9 + 7;

bitset<64> L, R;
ll memo[60][2][2][2];

ll dfs(int pos, int flagX, int flagY, int flagZ) {
    if (pos == -1) return 1;
    if (memo[pos][flagX][flagY][flagZ] != -1) {
        return memo[pos][flagX][flagY][flagZ];
    }
    ll ret = 0;
    if (flagX || L[pos] == 0) {
        ret = (ret + dfs(pos - 1, flagX, (R[pos] == 1 ? 1 : flagY), flagZ)) % MOD;
    }
    if ((flagX || L[pos] == 0) && (flagY || R[pos] == 1) && flagZ) {
        ret = (ret + dfs(pos - 1, flagX, flagY, flagZ)) % MOD;
    }
    if (flagY || R[pos] == 1) {
        ret = (ret + dfs(pos - 1, (L[pos] == 0 ? 1 : flagX), flagY, 1)) % MOD;
    }
    return memo[pos][flagX][flagY][flagZ] = ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll l, r;
    cin >> l >> r;
    L = bitset<64>(l);
    R = bitset<64>(r);
    for (int i = 0; i < 60; ++i) {
        for (int j = 0; j < 2; ++j) {
            for (int k = 0; k < 2; ++k) {
                for (int l = 0; l < 2; ++l) {
                    memo[i][j][k][l] = -1;
                }
            }
        }
    }
    cout << dfs(59, 0, 0, 0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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; }
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    ll n; ll m;
    cin>>n>>m;
    vector<ll> si_cnt(n);
    vector<pair<ll,ll>> box;
    vector<pair<ll,ll>> box2;
    rep(i,0,m){
        ll p,y;
        cin>>p>>y;
        box.push_back(make_pair(p,y));
        box2.push_back(make_pair(p,y));
        p--;
        si_cnt[p]++;
    }
    map<pair<ll,ll>,string> hyo;
    sort(all(box2));
    ll index=0;
    rep(i,0,n){
        rep(j,0,si_cnt[i]){
        string ken=to_string(i+1);
        string si=to_string(j+1);
        while(ken.size()<6) ken = '0'+ken;
        while(si.size()<6) si='0'+si;
        string id=ken+si;
        hyo[box2[index]]=id;
        index++;
        }
    }
    for(auto x:box){
        cout<<hyo[x]<<endl;
    }
}

Measured memory_bytes: 16356
//go:generate echo "https://atcoder.jp/contests/dp/tasks/dp_d"
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

type scanner struct{ *bufio.Scanner }

func newScanner(r io.Reader) *scanner {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	s.Buffer(nil, 100000000)
	return &scanner{s}
}

func (s *scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *scanner) IntSlice(l int) []int {
	if l == 0 {
		return []int{}
	}
	sl := make([]int, l, l)
	for i := range sl {
		sl[i] = s.Int()
	}
	return sl
}

func chmax(x *int, v int) {
	if *x < v {
		*x = v
	}
}

func solve(N, W int, wvs [][]int) int {
	t := make([][]int, N+1, N+1) // t[item_index][weight]
	for i := range t {
		t[i] = make([]int, W+1, W+1)
	}
	for i, wv := range wvs {
		weight, value := wv[0], wv[1]
		for sumWeight := 0; sumWeight <= W; sumWeight++ {
			if sumWeight-weight >= 0 {
				chmax(&t[i+1][sumWeight], t[i][sumWeight-weight]+value)
			}
			chmax(&t[i+1][sumWeight], t[i][sumWeight])
		}
	}
	return t[N][W]
}

func main() {
	scan := newScanner(os.Stdin)
	N, W := scan.Int(), scan.Int()
	wvs := make([][]int, N, N)
	for i := 0; i < N; i++ {
		wvs[i] = []int{scan.Int(), scan.Int()}
	}
	fmt.Println(solve(N, W, wvs))
}


Measured memory_bytes: 82596
#include <bits/stdc++.h>
using namespace std;
int main(){	
	string X;
	cin >> X;
	int ans=X.length();
	int cnt=0,i;
	for(auto i:X){
		if (i=='S'){
			++cnt;
		} 
		else{
			if (cnt>0){
				--cnt;
				ans-=2;
			}
			else{
				cnt=0;
			}
		}
	}	
	cout<<ans<<endl;
	return 0;
}
 

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a[100],b,c;
int main()
{
    for(register int i=1;i<=3;i++)scanf("%lld",&a[i]);
    sort(a+1,a+4);
    if(a[2]-a[1]==a[3]-a[2])puts("YES");
    else puts("NO");
    return 0;
}

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

#define N 3
#define N2 9

struct Puzzle {
    int f[N2];
    int space;
    string path;

    bool operator < (const Puzzle &p) const {
        for (int i = 0; i != N2; ++i) {
            if ( f[i] == p.f[i] ) continue;
            return f[i] > p.f[i];
        }
        return false;
    }
};

static const int dx[4] = {-1, 0, 1, 0};
static const int dy[4] = {0, -1, 0, 1};
static const char dir[4] = {'u', 'l', 'd', 'r'};

bool isTarget(Puzzle s) {
    for (int i = 0; i != N2; ++i) {
        if ( s.f[i] == i + 1 ) continue;
        return false;
    }
    return true;
}

string bfs(Puzzle s) {
    queue<Puzzle> Q;
    Puzzle u, v;
    map<Puzzle, bool> V;
    V[s] = true;
    s.path = "";
    Q.push(s);
    
    while ( !Q.empty() ) {
        u = Q.front(); Q.pop();
        if ( isTarget(u) ) return u.path;
        int sx = u.space / N;
        int sy = u.space % N;
        for (int r = 0; r != 4; ++r) {
            int tx = sx + dx[r];
            int ty = sy + dy[r];
            if ( tx < 0 || ty < 0 || tx >= N || ty >= N ) continue;
            v = u;
            swap(v.f[u.space], v.f[tx * N + ty]);
            v.space = tx * N + ty;
            if ( !V[v] ) {
                V[v] = true;
                v.path += dir[r];
                Q.push(v);
            }
        }
    }
    return "unsolvable";
}

int main()
{
    Puzzle in;
    
    for (int i = 0; i != N2; ++i) {
        cin >> in.f[i];
        if ( in.f[i] == 0 ) {
            in.f[i] = N2;
            in.space = i;
        }
    }
    string ans = bfs(in);
    cout << ans.size() << endl;
    return 0;
}


Measured memory_bytes: 30616
import sys
from heapq import heappop, heappush
input = sys.stdin.readline


class Data :
    def __init__():
        pass
    def __init__(self, pos, step, cost):
        self.pos = pos
        self.step = step
        self.cost = cost
    def __lt__(self, right):
        return self.cost < right.cost

def dijkstra(N, S, T, edges):
    inf = 10 ** 9 + 7
    dis = []
    for i in range(N + 1):
        dis.append([inf, inf, inf])

    que = []
    dis[S][0] = 0
    heappush(que, Data(S, 0, 0))
    while (len(que)):
        now_d = heappop(que)
        if dis[now_d.pos][now_d.step] < now_d.cost:
            continue

        for edge in edges[now_d.pos] :
            next_d = Data(edge[0], (now_d.step + 1) % 3, now_d.cost + edge[1])
            if dis[next_d.pos][next_d.step] > next_d.cost:
                dis[next_d.pos][next_d.step] = next_d.cost
                heappush(que, next_d)
    
    if (dis[T][0] == 10 ** 9 + 7):
        return -1
    else :
        return dis[T][0] // 3

N, M = map(int, input().split())
edges = []
for i in range(N+1):
    edges.append([])
for i in range(M):
    u, v = map(int, input().split())
    edges[u].append((v, 1))
S, T = map(int, input().split())
print(dijkstra(N, S, T, edges))

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

int main() {
    int k,s,l=0,c=0;
    cin>>k>>s;

    for (int i=0;i<=k;i++){
      for (int j=0 ;j<= k;j++){
      l=s-i ;
      l=l-j;
        if(0<= l && l <= k )
            c++;
      }
    }
  cout <<c<<"\n";
  return 0;
}

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

s = a[0]
t = sum(a) - a[0]

i = 0
ans = abs(s - t)
for i in range(1, n-1):
    s += a[i]
    t -= a[i]
    ans = min(ans, abs(s - t))
    i += 1
print(ans)


Measured memory_bytes: 30584
#include <bits/stdc++.h>
using namespace std;
int main () {
  int n;
  cin >> n;
  vector<int> vec(101,0);
  for (int i=0; i<n; i++){
      int a;
      cin>> a;
      vec.at(a)++;
  }
  int count;
  for (int i=0; i<101; i++){
      if (vec.at(i)>0)count++;
  }
  cout << count <<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
long long int a[5];
long long int mn;
long long int n;
cin >> n;
for(int i=0;i<5;i++)cin >> a[i];
mn = min({a[0],a[1],a[2],a[3],a[4]});
cout << (n + mn - 1)/ mn + 4 << endl;
return 0;
}

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

using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string str; cin >> str; reverse(str.begin(), str.end());
    
    string ptr[4] = {"dream", "dreamer", "erase", "eraser"};

    for (int i=0; i<4; i++) reverse(ptr[i].begin(), ptr[i].end());

    bool can = true;
    for (ll i=0; i<str.length();)
    {
        bool can2 = false;
        for (int j=0; j<4; j++)
        {
            string p = ptr[j];
            if (str.substr(i, p.length()) == p)
            {
                can2 = true;
                i += p.length();
            }

        }

        if (can2==false) 
        {
            cout << "NO" << "\n";
            return 0;
        }
    }
    
    cout << "YES" << "\n";
    
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
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 ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
const int MOD=998244353;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin >> n;
    string s;cin >> s;
    vector<int> l(n+1),r(n+1);
    for(int i=0;i<n;i++){
        int p=s[i]-'a';
        l[i+1]=l[i]|(1<<p);
    }
    for(int i=n-1;i>=0;i--){
        int p=s[i]-'a';
        r[i]=r[i+1]|(1<<p);
    }
    int ans=0;
    for(int i=0;i<=n;i++){
        int t=l[i]&r[i];
        int res=0;
        for(int j=0;j<26;j++){
            if(t&(1<<j)){
                res++;
            }
        }
        chmax(ans,res);
    }
    cout << ans << endl;
}

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

using lint = long long;
constexpr lint INF = 1LL << 60;

void solve() {
    int n, k;
    std::cin >> n >> k;

    lint ans = n;
    k -= n;

    std::vector<lint> segs;
    lint prevt = -INF;
    while (n--) {
        lint t;
        std::cin >> t;
        segs.push_back(t - prevt);
        prevt = t + 1;
    }
    std::sort(segs.begin(), segs.end());

    for (auto s : segs) {
        if (k >= 0) break;
        ans += s;
        ++k;
    }

    std::cout << ans << std::endl;
}

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

    solve();

    return 0;
}



Measured memory_bytes: 3904
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
// #include<unordered_map>
#include<set>
// #include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
#include<functional>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
#define wl() cout << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
};
struct point {
	ll x, y, idx;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

template<typename T>
T minT(T a, T b) {
	if (a < b) return a;
	else return b;
}

template<typename T>
T maxT(T a, T b) {
	if (a > b) return a;
	else return b;
}

template<typename T>
T absT(T a) {
	if (a < 0) a *= -1;
	return a;
}

template<typename T>
T powT(T a, T x) {
	T res = 1;
	while (x > 0) {
		if (x & 1) res = res*a;
		a = a*a;
		x >>= 1;
	}
	return res;
}

ll StoLL(string str) {
	ll ret = 0, ini = 0;
	if (str[0] == '-') ini = 1;
	repi(i, ini, str.length()) {
		ret *= 10;
		ret += (ll)(str[i] - '0');
	}
	if (ini) ret *= -1;
	return ret;
}

///////////////////////////////////////////////////////////////////////////////////////



int main() {
	ll a, b;
	cin >> a >> b;
	ll ans = max(a + b, max(a - b, a*b));
	wrln(ans);
	return 0;
}


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

using namespace std;
using LL = long long;
using P = pair<int,int>;

int main(){
	int N, K;
	cin >> N >> K;
	int R, S, P;
	cin >> R >> S >> P;
	string T;
	cin >> T;
	int ans=0;
	rep(i,N){
		if(i>=K && T[i]==T[i-K]){
			T[i]='0';
			continue;
		}
		if(T[i]=='r') ans+=P;
		if(T[i]=='s') ans+=R;
		if(T[i]=='p') ans+=S;
	}
	cout << ans << endl;

	return 0;
}

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

int A[2005];

int main() {
    int N, Z, W;
    scanf("%d %d %d", &N, &Z, &W);
    for (int i = 0; i < N; i++) scanf("%d", &A[i]);
    int ans;
    if (N == 1) ans = abs(A[0] - W);
    else ans = max(abs(A[N-1] - W), abs(A[N-1] - A[N-2]));
    printf("%d\n", ans);
    return 0;
}

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

//flagを用いたバブルソート//
int bubbleSort(int A[], int N) {
    int sw = 0;
    bool flag = 1;
    for ( int i = 0; flag; i++ ) {
        flag = 0;
        for ( int j = N - 1; j >= i + 1; j-- ) {
            if ( A[j] < A[j - 1] ) {
            //隣接要素を交換する
            swap(A[j], A[j - 1]);
            flag = 1;
            sw++;
        }
    }
}
return sw;
}

int main() {
    int A[100], N, sw;
    cin >> N;
    for ( int i = 0; i < N; i++ ) cin >> A[i];

    sw = bubbleSort(A, N);

    for ( int i = 0; i < N; i++ ) {
        if (i) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << sw << endl;

    return 0;
}


Measured memory_bytes: 3124
import java.util.Scanner;

class Main{
	public static void main(String[] args){
	
	Scanner sc = new Scanner (System.in);
	
	int a = sc.nextInt();
	int b = sc.nextInt();
	int c = sc.nextInt();
	int count = 0;
	
	for(int i = a; i <= b; i++){
		if(c % i == 0){
			count++;
		}
	}
	System.out.println(count);
	sc.close();
	}
}


Measured memory_bytes: 26220
#include<bits/stdc++.h>
using namespace std;
int n,k;
int x[100005];
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>x[i];
	int ans=1e9;
	for(int l=1;l<=n;l++)
	{
		int r=l+k-1;
		if(r>n) continue;
		int mn=0,mx=0;
		if(x[l]<=0)
			mn=x[l];
		if(x[r]>=0)
			mx=x[r];
		ans=min(ans,min(2*abs(mn)+mx,2*mx+abs(mn)));
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
typedef long long ll;
#define tr(container, it) \
    for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define ill(_x)  ll _x;scanf("%lld",&_x);
#define idb(_x)  double _x;scanf("%lf",&_x);
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vs vector<string>
#define in0(x, a, b)((x)>=a && (x)<=b    )
#define in1(x, a, b)((x)>a && (x)<b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const double pi = 3.14159265358979323846;
const int INF = 0x3f3f3f3f;
const int X10=1024,X11=2048,X12=4096,X13=8196,X14=16392,X15=32786,X16=65536,X17=131072,X18=262144,X19=524288,X20=1048576;

ll CalcMHWScore(vector<ll> scores)
{
    size_t size = scores.size();

    if (size == 0)
    {
        return 0;  // Undefined, really.
    }
    else
    {
        sort(scores.begin(), scores.end());
        if (size % 2 == 0)
        {
            return (scores[size / 2 - 1] + scores[size / 2]) / 2;
        }
        else
        {
            return scores[size / 2];
        }
    }
}
int n;
vector<ll> A;
void _() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        ll a;
        cin >> a;
        A.push_back(a-(i+1));
    }
    ll me=CalcMHWScore(A);
    ll s=0,mi=LLONG_MAX;
    for (int i = 0; i < n; ++i) {
        s+=abs(A[i]-me);
    }
    mi=min(s,mi);
    s=0;
    for (int i = 0; i < n; ++i) {
        s+=abs(A[i]-me-1);
    }
    mi=min(s,mi);
    s=0;
    for (int i = 0; i < n; ++i) {
        s+=abs(A[i]-me+1);
    }
    mi=min(s,mi);
    s=0;


    cout << mi ;

}


int main() {
#if __MINGW32__
    freopen("E:\\Workspace\\Desktop\\cpp\\IO\\Input.txt", "r", stdin);
    freopen("E:\\Workspace\\Desktop\\cpp\\IO\\Output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    _();
    return 0;

}








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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  if (v.size() == 0) {
    os << "(empty)";
    return os;
  }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

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

int main() {

  for (int e;cin>>e,e;) {
    int m = INF;
    for (int z = 0; z * z * z <= e; ++z) {
      for (int y = 0; y*y + z*z*z <= e; ++y) {
        int x = e - y*y - z*z*z;
        m = min(m, x + y + z);
      }
    }
    cout << m << endl;
  }



  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#include<string>
#include<vector>
#define ll long long
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
 


int main(){
    fast;
    int n;
    cin >> n;
    map<string, int> p;

    for (int i = 0; i < n; i++)
    {
        string s;
        cin >> s;

        p[s]++;
    }

    cout << p.size() << endl;

    return 0;
}




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

using namespace std;

int main(){
    ios_base::sync_with_stdio(false) ;
    cin.tie(0) ;
    int n , m ;
    cin >> n >> m ;
    bool done[n + 1] = {0};
    int cnt[n + 1] = {0} ;

    for(int i = 0; i < m; i++){
        int p ;
        string s ;
        cin >> p >> s ;
        if ( s == "WA" ){
            if ( !done[p] ){
                cnt[p]++ ;
            }
        }
        else{
            done[p] = true ;
        }
    }
    int ans = 0 ;
    int pen = 0 ;
    for(int i = 1; i < n + 1; i++){
        if ( done[i] ) {
            ans++;
            pen += cnt[i] ;
        }
    }
    cout << ans << ' ' << pen << endl;
    return 0 ;
}


Measured memory_bytes: 768
import java.util.Scanner;

public class Main {
	  
	public static void main(String args[]) {
		    Scanner sc = new Scanner(System.in);
		    
		    long N = sc.nextLong();
		    int waru = 0;
		    for(int i = 1; i <= Math.sqrt(N); i++) {
		    	if(N % i == 0) {
		    		waru = i;
		    	}
		    	else {
		    	}
		    }
		    long shou = N / waru;
		    int kotae = 0;
		    
		    while(shou != 0){
		    	shou = shou/10;
		    	kotae++;
		    }
		    System.out.println(kotae);
		    
		    sc.close(); }
		  }


Measured memory_bytes: 21588
// created by mtnshh
 
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;

#define ll long long
#define ld long double
 
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define err() cout<<"--------------------------"<<endl; 
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>
 
#define endl "\n"
 
const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e18;
#define PI 3.14159265
 
const ll N = 100005;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n;
    cin >> n;
    ll A[n+1];
    rep(i,0,n+1)	A[i] = 0;
    rep(i,1,101)	rep(j,1,101)	rep(k,1,101){
    	ll cnt = i*i + j*j + k*k + i*j + j*k + i*k;
    	if(cnt <= n)	A[cnt]++;
    }	
    rep(i,1,n+1)	cout<<A[i]<<endl;
    return 0;
}

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

Measured memory_bytes: 35856
s = int(input())

ans = 0

def f(n):
    if n % 2:
        return 3 * n + 1
    else:
        return n // 2
    

exist = set()
while True:
    if s in exist:
        break
    exist.add(s)
    ans += 1
    s = f(s)

print(ans+1)

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <functional>
using namespace std;

template< typename Monoid, typename F >
struct SegmentTree {

  int sz;
  vector< Monoid > seg;

  const F f;
  const Monoid M1;

  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }

  void set(int k, const Monoid &x) {
    seg[k + sz] = x;
  }

  void build() {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  Monoid query(int a, int b) {
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }

  Monoid operator[](const int &k) const {
    return seg[k + sz];
  }
};

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

int main()
{
  int N;
  cin>>N;
  SegmentTree< int, function< int(int, int) > > seg(N, [](int a, int b) { return gcd(a, b); }, 0);
  for(int i=1;i<=N;i++){
    int a;cin>>a;
    seg.update(i,a);
  }
  int ans=max(seg.query(2,N+1),seg.query(1,N));
  for(int i=2;i<N;i++){
    ans=max(gcd(seg.query(1,i),seg.query(i+1,N+1)),ans);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1280
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n, t[2], x[2], y[2];
	cin >> n;
	t[0] = x[0] = y[0] = 0;
	while (n--) {
		cin >> t[1] >> x[1] >> y[1];
		if (t[1] - t[0] < abs(x[1] - x[0]) + abs(y[1] - y[0]) || (abs(t[1] - t[0]) - (abs(x[1] - x[0]) + abs(y[1] - y[0]))) % 2 != 0) {
			cout << "No" << endl;
			return 0;
		}
		t[0] = t[1], x[0] = x[1], y[0] = y[1];
	}
 
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    long long r , d ;
    cin>>r>>d ;
    long long arr[12] ;
    cin>>arr[0] ;
    for(int i = 1 ; i <= 10 ; ++i)
    {
        arr[i] = r * arr[i-1] - d ;
        cout<<arr[i]<<"\n";
    }
    return 0 ;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 30
using namespace std;
int dy[4]={0,-1,0,1};
int dx[4]={1,0,-1,0};
int w,h,ans,cnt,sum;
bool used[N][N];
string s[N];


void Change_dir(){
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(!('0'<=s[i][j]&&s[i][j]<='3'))continue;
      int dir=s[i][j]-'0';
      for(int k=3;k<=6;k++){
	int ndir=(dir+k)%4;
	int ny=i+dy[ndir],nx=j+dx[ndir];
	if(ny<0||nx<0||h<=ny||w<=nx)continue;
	if(s[ny][nx]=='.'||s[ny][nx]=='X'){
	  s[i][j]=ndir+'0';
	  break;
	}
      }
    }
  }
}

void Change_pls(){
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(!(s[i][j]=='.'||s[i][j]=='X'))continue;
      if(used[i][j])continue;
      for(int k=0;k<4;k++){
	int ny=i+dy[k],nx=j+dx[k];
	if(ny<0||nx<0||h<=ny||w<=nx)continue;
	if(used[ny][nx])continue;
	if('0'<=s[ny][nx]&&s[ny][nx]<='3'){
	  if(s[ny][nx]!=(k+2)%4+'0')continue;
	  used[i][j]=used[ny][nx]=true;
	  if(s[i][j]=='.')s[i][j]=s[ny][nx];
	  else cnt++;
	  s[ny][nx]='.';
	  break;
	}
      }
    }
  }
}

int main(){
  while(1){
    cin>>w>>h;
    if(!w&&!h)break;
    ans=cnt=sum=0;
    for(int i=0;i<h;i++)cin>>s[i];
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++){
	if(s[i][j]=='E')s[i][j]='0',sum++;
	if(s[i][j]=='N')s[i][j]='1',sum++;
	if(s[i][j]=='W')s[i][j]='2',sum++;
	if(s[i][j]=='S')s[i][j]='3',sum++;
      }
    while(1){
      ans++;
      if(ans>180)break;
      Change_dir();
      memset(used,0,sizeof(used));
      Change_pls();
      if(cnt==sum)break;
    }
    if(ans>180)cout<<"NA"<<endl;
    else cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
// define #Asukaminato is cute
#define ll long long
#define rep(i, m) for (int i = 0; i < (int)(m); i++)
 
int main(){
	int N;
	cin>>N;
 cout<<setprecision(15)<<2*N*M_PI;
	
}

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


Measured memory_bytes: 23124
class UnionFindNode(object):
    """
    Union-Find構造
    ノードのグループ併合や、所属グループ判定を高速に処理する
    """

    def __init__(self, group_id, parent=None, value=None):
        self.group_id_ = group_id
        self.parent_ = parent
        self.value = value
        self.size_ = 1

    def __str__(self):
        template = "UnionFindNode(group_id: {}, \n\tparent: {}, value: {}, size: {})"
        return template.format(self.group_id_, self.parent_, self.value, self.size_)

    def is_root(self):
        return not self.parent_

    def root(self):
        parent = self
        while not parent.is_root():
            parent = parent.parent_
            self.parent_ = parent
        return parent

    def find(self):
        parent = self.root()
        return parent.group_id_

    def size(self):
        parent = self.root()
        return parent.size_

    def unite(self, unite_node):
        parent = self.root()
        unite_parent = unite_node.root()

        if parent.group_id_ != unite_parent.group_id_:
            if parent.size() > unite_parent.size():
                unite_parent.parent_ = parent
                parent.size_ = parent.size_ + unite_parent.size_
            else:
                parent.parent_ = unite_parent
                unite_parent.size_ = parent.size_ + unite_parent.size_
    def is_group(self,other):#selfとotherが同じグループに属するか
        return self.root()==other.root()
n,q=map(int,input().split())
U=[UnionFindNode(i) for i in range(n)]
for i in range(q):
    com,x,y=map(int,input().split())
    x-=1
    y-=1
    if com==0:
        U[x].unite(U[y])
    else:
        if U[x].is_group(U[y]):
            print(1)
        else:
            print(0)



Measured memory_bytes: 7616
from sys import stdin
s = (stdin.readline().rstrip())
l = 0
r = 1
ans = 0

for i in range(len(s)):

    if l+r >= len(s):
        break

    if s[l] == s[-r]:
        l += 1
        r += 1

    elif s[l] == "x" and s[-r] != "x":
        ans += 1
        l += 1

    elif s[l] != "x" and s[-r] == "x":
        ans += 1
        r += 1

    else:
        ans = -1
        break

print(ans)

Measured memory_bytes: 3316
#include<stdio.h>
long long int modpow(long long int a, long long int n, long long int p)
{
	if (n < 0)
		return 0;
	long long int res = 1;
	while (n > 0)
	{
		if (n % 2 > 0)
			res = res * a % p;
		n /= 2;
		a = a * a % p;
	}
	return res;
}
int main()
{
	int x, y;
	scanf("%d %d", &x, &y);
	long long int p = 1000000007;
	int a, b;
	if (2 * y - x < 0)
	{
		printf("0\n");
		return 0;
	}
	if ((2 * y - x) % 3 > 0)
	{
		printf("0\n");
		return 0;
	}
	a = (2 * y - x) / 3;
	if (2 * x - y < 0)
	{
		printf("0\n");
		return 0;
	}
	if ((2 * x - y) % 3 > 0)
	{
		printf("0\n");
		return 0;
	}
	b = (2 * x - y) / 3;
	long long int i;
	long long int k[2000006];
	k[0] = 1;
	for (i = 1; i < 2000006; i++)
		k[i] = k[i - 1] * i % p;
	long long int ans = k[a + b];
	ans = ans * modpow(k[a], p - 2, p) % p;
	ans = ans * modpow(k[b], p - 2, p) % p;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 15744
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int main(void){
	ll n;
	cin>>n;
	if(n%2==0)cout<<n<<endl;
	else cout<<n*2<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> void pr_vec(vector<T> &v, char ep=' '){int n=v.size();REP(ni,n){cout<<v[ni];if(ni!=n-1)cout<<ep;}cout<<endl;};
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    ll N;
    cin >> N;
    vector<int> d(N+1, 1);
    Rep(i,2,N+1){
        Rep(j,1,N+1){
            if((ll)i*j>N) break;
            d[i*j]++;
        }
    }
    ll ans = 0;
    Rep(i,1,N+1){
        ans += (ll)i*d[i];
    }
    pr(ans);
}


Measured memory_bytes: 42324
def main():
    S = input()
    N = len(S) + 1
    cc_s = [0] * N
    cc_d = [0] * N
    for i in range(N-1):
        if S[i] == '<':
            cc_s[i+1] = cc_s[i] + 1
    iS = S[::-1]
    for i in range(N-1):
        if iS[i] == '>':
            cc_d[i+1] = cc_d[i] + 1
    cc_d = cc_d[::-1]
    output = 0
    for a, b in zip(cc_s, cc_d):
        output += max(a, b)
    print(output)
    return

if __name__ == '__main__':
    main()


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

void solve()
{
    int s=0,n;
    cin>>n;
    int a[n+1];
    for(int i=0;i<n;i++)
    cin>>a[i];
    for(int i=0;i<n-1;i++)
        for(int j=i+1;j<n;j++)
        s+=(a[i]*a[j]);
    cout<<s<<endl;
}


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


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

int main() {
    int n, d, x;
    cin >> n >> d >> x;
    int ans = x;
    --d;
    for (int i = 0; i < n; ++i) {
        int num; cin >> num;
        ans += d / num;
    }
    ans += n;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<string>
#include<utility>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)

int inf=1000200000;

int t;
int n,k;
int x[100001];
int dx[100001];


int main() {
	cin>>t;
	rep(hoge,t){
		cin>>n>>k;
		rep(i,n) cin>>x[i];
		rep(i,n-1) dx[i] =x[i+1]-x[i];
		sort(dx+1,dx+n);
		int sum = 0;
		rep(i,n-k) sum+= dx[i];
		cout<<sum<<endl;
	}
	
	return 0;
}



Measured memory_bytes: 3936
n = int(input())
m = list(map(int, input().split()))

def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

def lcm(a,b):
  return a*b//gcd(a,b)

t = m[0]
for i in m[1:]:
  t = lcm(t,i)

ans=0
for i in m:
  ans += t//i
print(ans%(10**9+7))

Measured memory_bytes: 4084
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static final Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	int N;
	long[] A;

	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		N = nextInt();
		A = nextLongArray(N);

		long sumL = 0,sumR = 0;
		for(int i=0,j=N-1;i<=j;) {
			if(sumL <= sumR) {
				sumL+=A[i];
				i++;
			}else{
				sumR+=A[j];
				j--;
			}
		}

		out.println(Math.abs(sumL-sumR));
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}

	long gcd(long m,long n) {
		if (m<n) return gcd(n,m);
		if (n==0)return m;
		return gcd(n,m%n);
	}
}

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

int main(){
  double N, D;
  cin >> N >> D;
  vector<double> X(N), Y(N);
  vector<double> dist(N);
  int ans = 0;
  for(int i=0; i<N; i++){
    cin >> X.at(i) >> Y.at(i);
    dist.at(i) = pow(X.at(i)*X.at(i)+Y.at(i)*Y.at(i),0.5);
    if(dist.at(i)<=D){
      ans++;
    }
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 8068
X='abcdefghijklmnopqrstuvwxyz'*2
S=input()
k=int(input())
N=[]
for s in S:
    if s=='a':
        N.append(0)
    else:
        N.append(26-X.index(s))
ans=''
for i in range(len(S)):
    if N[i]<=k :
        k-=N[i]
        ans+='a'
    else:
        ans+=S[i]
ans=ans[:-1]+X[X.index(ans[-1])+k%26]

print(ans)

Measured memory_bytes: 4212
#include <stdio.h>

int main(){
  int i,j,n,q,count=0;
  scanf("%d",&n);
  int A[n];
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  int B[q];
  for(i=0;i<q;i++){
    scanf("%d",&B[i]);
  }
  for(j=0;j<q;j++){
    for(i=0;i<n;i++){
	if(A[i]==B[j]){
	  count++;
	  break;
	}
      }
    }
  printf("%d\n",count);
  return 0;
}



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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef pair<int, int> pi;

int n;
int m;
string s;
const int mod = 1e9 + 7;

const int maxn = 2e5 + 5;
int f[maxn];
int pre[maxn];

void add(int &a, int b){
    a += b;
    if(a >= mod)
        a -= mod;
}

void single(){
    f[0] = 1;
    f[1] = 2;
    for(int i = 2;i <= n;i++){
        f[i] = (f[i - 1] + f[i - 2]) % mod;
    }
    int ans = (2 * f[n - 1] - f[n - 2]) % mod;
    ans = (ans + mod) % mod;
    cout << ans << endl;
}

void solve(int v){
    v /= 2, n /= 2; 
    v = min(v, n);
    f[0] = 1;
    pre[0] = 1;
    for(int i = 1;i <= v;i++){
        f[i] = pre[i - 1];
        pre[i] = pre[i - 1];
        add(pre[i], f[i]);
    }
    for(int i = v + 1;i <= n;i++){
        f[i] = (pre[i - 1] - pre[i - v - 1] + mod) % mod;
        pre[i] = pre[i - 1];
        add(pre[i], f[i]);
    }
    int ans = 0;
    for(int i = 1;i <= v;i++){
        int r = n - i;
        int l = n - v;
        int tmp;
        if(l == 0){
            tmp = pre[r];
        }else{
            tmp = (pre[r] - pre[l - 1] + mod) % mod;
        }
        add(ans, tmp);
    }
    ans = ans * 2 % mod;
    cout << ans << endl;
}


int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> m;
    cin >> s; 
    if(s[0] == 'B'){
        for(int i = 0;i < m;i++){
            if(s[i] == 'R')
                s[i] = 'B';
            else
                s[i] = 'R';
        }
    } 
    int first = -1, last = -1;
    for(int i = 0;i < m;i++){
        if(s[i] == 'B'){
            if(first == -1)
                first = i;
            last = max(last, i);
        }
    }
    if(first == -1){
        single();
    }else{
        if(n & 1){
            cout << 0 << endl;
        }else{
            string s1 = s.substr(0, last + 1);
            int len = s1.length();
            if(first == 1){
                cout << 2 << endl;
            }else{
                int val = first / 2 * 2 + 2;
                int pre = first;
                for(int i = first + 1;i < len;i++){
                    if(s[i] == 'B'){
                        int x = i - pre;
                        pre = i;
                        if(x % 2 == 0){
                            val = min(val, x);
                        }
                    } 
                }
                solve(val);
            }
        }
    }    
    return 0;
}


Measured memory_bytes: 1556
d,g = map(int,input().split())
q={}
comp={}
p={}
minsolve=0
for i in range(d):
    a,b=map(int,input().split())
    q[i]=a
    p[i]=100*(i+1)
    comp[i]=100*(i+1)*a+b
    minsolve+=a
    
solve=[0 for _ in range(d)]
def roop(s,check,point,solved,minsolve):
    solve=s.copy()
    solve2=s.copy()
    if check==d:
        if point>g:
            minsolve=min(minsolve,solved)
            return minsolve
        if 0 in solve:
            solverev=solve.copy()
            solverev.reverse()
            idx=d-solverev.index(0)-1
            shold=1+(g-point-1)//p[idx]
            if q[idx]>shold and shold>=0:
                solved+=shold
                minsolve=min(minsolve,solved)
        return minsolve

    minsolve=roop(solve,check+1,point,solved,minsolve)
    solve2[check]+=1
    minsolve=roop(solve2,check+1,point+comp[check],solved+q[check],minsolve)
    return minsolve

print(roop(solve,0,0,0,minsolve))

Measured memory_bytes: 3064
var input = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
    input += chunk;
});
process.stdin.on('end', function() {
    main(input)
});

function main(input){
    var args = input.trim().split('\n');

    args.forEach(function(data){
        data = data.split(' ').map(Number);
        solve(data);
    })
}

function solve(numbers){
    var a = numbers[0], b = numbers[1], p = numbers[2];
    var c = numbers[3], d = numbers[4], q = numbers[5];

    var z = a * d - b * c;

    var x = (d * p - b * q) / z;
    var y = (a * q - c * p) / z;

    console.log(x.toFixed(3) + ' ' + y.toFixed(3));
}

Measured memory_bytes: 15604
n = int(input())
a = [int(x) for x in input().split()]

init = a[0]
for i in a[1:]:
    if init >= i:
        x = init
        y = i
    else:
        x = i
        y = init
    z = x % y
    while z:
        x = y
        y = z
        z = x % y
    init = y

print(y)


Measured memory_bytes: 14252
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>
#include<utility>
#include<numeric>

#define PB push_back
#define all(a)  (a).begin(),(a).end()
#define ALL(v) begin(v), end(v)
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define V vector<int>
#define VV vector<V>
#define VVV vector<VV>

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int inf = (int)1e9;
const ll INF = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };
const long double EPS = 1e-10;

int n, m;
int d[200010], t[200010];
map<int, int> mapd, mapt;

int main() {
	cin >> n;
	rep(i, n) cin >> d[i];
	cin >> m;
	rep(i, m) cin >> t[i];

	rep(i, n) mapd[d[i]]++;
	rep(i, m) mapt[t[i]]++;

	rep(i, n) {
		if (mapt[t[i]] > mapd[t[i]]) {
			cout << "NO" << endl;
			return 0;
		}
	}

	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 20608
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main() {
    ios_base::sync_with_stdio(0);
    string s, t; cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());

    cout << (s<t? "Yes": "No") << endl;
}


Measured memory_bytes: 3636