akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int main () {
  int N, L;
  cin >> N >> L;
  string S[220];
  for (auto i = 0; i < N; ++i) {
    cin >> S[i];
  }
  sort(S, S+N);
  string ans = "";
  for (auto i = 0; i < N; ++i) {
    ans += S[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, N = 2e5 + 5;
int n, k, res, s[N];
inline int Pow (int a, int b) {
    int t = 1;
    while (b) {
        if (b & 1) t = 1ll * t * a % mod;
        a = 1ll * a * a % mod, b >>= 1;
    } return t;
}
inline int C (int n, int m) {
    if (!m) return 1;
    return 1ll * Pow (1ll * s[m] * s[n - m] % mod, mod - 2) * s[n] % mod;
}
signed main() {
    scanf ("%d %d", &n, &k); s[1] = 1;
    for (int i = 2; i <= n; ++i) s[i] = 1ll * s[i - 1] * i % mod;
    for (int i = 1; i <= min (n - 1, k); ++i)
        res = (res + 1ll * C (n, i) * C (n - 1, n - i - 1) % mod) % mod;
    return printf ("%d\n", res + 1), 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
template<class T> T miman_max(set<T> &S, const T &x){
    typename set<T>::iterator it = S.lower_bound(x);
    it--;
    return *it;
}

ll X[101010];
ll L, Q;
ll step[101010][20];

int main(){

    ll N;
    cin >> N;
    set<P>S;
    rep1(i, N){
        cin >> X[i];
        S.insert(P(X[i], i));
    }
    cin >> L;
    step[N][0] = -1;
    for(ll i = 1; i < N; i++){
        step[i][0] = miman_max(S, P(X[i] + L + 1, 0)).second;
    }
    rep(i, 19){
        rep1(j, N){
            ll idx = step[j][i];
            if(idx < 0){
                step[j][i + 1] = -1;
                continue;
            }
            step[j][i + 1] = step[idx][i];
        }
    }

    cin >> Q;
    rep(i, Q){
        ll a, b;
        cin >> a >> b;
        if(a > b)swap(a, b);
        ll ans = 0;
        while(a < b){
            ll nxt = 0;
            for(; ; nxt++){
                if(step[a][nxt + 1] < 0)break;
                if(step[a][nxt + 1] > b)break;
            }
            ans += (1 << nxt);
            a = step[a][nxt];
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 23680
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int A,B,K;
    cin >> A  >> B;
    K = (A + B);
    if( K % 2 == 0 ) {
        cout << K / 2 << endl;
    }
    else {
        cout << "IMPOSSIBLE" << endl;
    }
}


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

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

using namespace std;

int main() {
    int n;
    cin >> n;
    string s;
    priority_queue<string> q; 
    REP(i,n) {
        cin >> s;
        sort(s.begin(), s.end());
        q.push(s);
    }

    long num =1;
    long cnt =0;

    string dum;
    REP(i,n-1) {
        dum = q.top();
        q.pop();
        if (dum == q.top()) num++;
        else {
            cnt += (num * (num-1))/2;
            num = 1;
        }
    }
    cnt += (num * (num-1))/2;
    cout << cnt << endl;
}

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

const long long maxn = 2e5 + 10;

long long n, m;
long long pen, ac;
long long state[maxn];

void in();
void solve();
void out();

int main(){
    in();
    solve();
    out();
}

void in(){
    ios::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    cin >> n >> m;
    for(long long i = 0; i < m; i++){
        long long q;
        string ver;
        cin >> q >> ver;
        if(state[q] != -1 && ver == "WA")
            state[q]++;
        else if(state[q] != -1){
            pen += state[q];
            state[q] = -1;
            ac++;
        }
    }
}

void solve(){

}

void out(){
    cout << ac << ' ' << pen;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <limits.h>
using namespace std;

vector<pair<int,long long>> tree[100010];
long long depth[100010];

void dfs(int v,int p,long long d){
  depth[v]=d;
  for(auto &e:tree[v]){
    if(e.first==p) continue;
    dfs(e.first,v,d+e.second);
  }
}

int main(){
  int n;
  cin>>n;

  for(int i=1;i<n;i++){
    int a,b;
    long long c;
    cin>>a>>b>>c;
    tree[a].push_back(make_pair(b,c));
    tree[b].push_back(make_pair(a,c));
  }

  int q,k;
  cin>>q>>k;

  dfs(k,-1,0);
  for(int i=1;i<=q;i++){
    int x,y;
    cin>>x>>y;
    cout<<depth[x]+depth[y]<<endl;
  }
  return 0;
}


Measured memory_bytes: 14336
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	int N; cin >> N; 
	int A[100010] = {}; 
	int mx = 0; 
	for(int i = 0; i < N; i++){
		cin >> A[i]; 
		mx = max(mx, A[i]); 
	}
	if(mx == 0) cout << "Yes" << endl; 
	else if(N % 3 != 0) cout << "No" << endl; 
	else{
		sort(A, A+N); 
		int M = N / 3; 
		bool possible = true; 
		if(A[0] != A[M-1]) possible = false; 
		if(A[M] != A[M*2-1]) possible = false; 
		if(A[M*2] != A[M*3-1]) possible = false; 
		if((A[0]^A[M]) != A[2*M]) possible = false; 
		if(possible) cout << "Yes" << endl;
		else cout << "No" << endl; 
	}	
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
// typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

const double EPS = 1e-10;

struct P {
    double x, y, z;
    P(){}
    P(double _x, double _y, double _z) : x(_x), y(_y), z(_z) {}
    const P operator+ (const P& p) {
        return P(this->x + p.x, this->y + p.y , this->z + p.z);
    }
    const P operator- (const P &p) {
        return P(this->x - p.x, this->y - p.y , this->z - p.z);
    }
    void print() {
        printf("%.1f %.1f %.1f\n", x, y, z);
    }
};

double dot(const P& p, const P& q) {
    return p.x * q.x + p.y * q.y + p.z * q.z;
}

P cross(P p, P q) {
    return P(p.y * q.z - p.z * q.y, p.z * q.x - p.x * q.z, p.x * q.y - p.y * q.x);
}

struct C {
    P c;
    double r;
    C(){}
    C(P _c, double _r) : c(_c), r(_r) {}
};

struct L {
    P a, b, v;
    L(){}
    L(P _a, P _b) : a(_a), b(_b), v(b - a) {}
};

double distance(P p) {
    return sqrt(p.x * p.x + p.y * p.y + p.z * p.z);
}

double distancePP(P p, P q) {
    return sqrt((p.x - q.x) * (p.x - q.x)
            + (p.y - q.y) * (p.y - q.y)
            + (p.z - q.z) * (p.z - q.z));
}

double distanceLP(L l, P p) {
    return distance(cross(l.v, p - l.a)) / distance(l.v);
}

double distanceSP(L l, P p) {
    if (dot(l.b - l.a, p - l.a) < 0) return distancePP(p, l.a);
    if (dot(l.a - l.b, p - l.b) < 0) return distancePP(p, l.b);
    return distanceLP(l, p);
}

bool intersectSC(L s, C c) {
    // return distanceSP(s, c.c) <= c.r;
    return distanceSP(s, c.c) < c.r + EPS;
}

C readC() {
    double x, y, z, r;
    cin >> x >> y >> z >> r;
    return C(P(x, y, z), r);
}

L readL() {
    double x1, y1, z1, x2, y2, z2;
    cin >> x1 >> y1 >> z1 >> x2 >> y2 >> z2;
    return L(P(x1, y1, z1), P(x2, y2, z2));
}

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

    int N, Q;
    cin >> N >> Q;

    vector<C> circles(N);
    V l(N);
    rep(i, N) {
        circles[i] = readC();
        cin >> l[i];
    }

    while (Q--) {
        L s = readL();
        int ans = 0;
        rep(i, N) {
            if (intersectSC(s, circles[i])) {
                ans += l[i];
            }
        }
        cout << ans << endl;
    }

}

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

// Disjoint Set
template<typename T = int>
class UnionFind {
 private:
  T _size;
  vector<T> _parent; // 親の番号（親自身はー（マイナス）集合要素の個数）

 public:
  // n要素で生成
  explicit UnionFind(T n) : _size{n}, _parent{vector<T>(n, -1)} {}

  // 木の根を求める
  T find(T x) {
    if (x < 0 || x >= _size) {
      return x;
    }

    if (_parent[x] < 0) {
      return x;
    }

    return _parent[x] = find(_parent[x]);
  }

  // xとyの属する集合を併合する
  bool unite(T x, T y) {
    if (x < 0 || x >= _size || y < 0 || y >= _size) {
      return false;
    }

    x = find(x);
    y = find(y);
    if (x == y) {
      return false;
    }

    if (size(x) > size(y)) {
      _parent[x] += _parent[y];
      _parent[y] = x;
    } else {
      _parent[y] += _parent[x];
      _parent[x] = y;
    }

    return true;
  }

  // xとyが同じ集合に属するか
  bool same(T x, T y) {
    return find(x) == find(y);
  }

  // xの属する集合の個数を求める
  T size(T x) {
    if (x < 0 || x >= _size) {
      return 1;
    }

    return -_parent[find(x)];
  }

  // 全体の個数を求める
  T size() {
    return _size;
  }
};

constexpr int MAX_N = 1e5;
constexpr int MAX_M = 1e5;
int A[MAX_M];
int B[MAX_M];
long dp[MAX_M];

int main() {
  int N, M;
  cin >> N >> M;
  for (int i{}; i < M; ++i) {
    cin >> A[i];
    --A[i];
    cin >> B[i];
    --B[i];
  }
  UnionFind<int> uf(N);

  dp[M - 1] = static_cast<long>(N) * (N - 1) / 2;
  for (int i{M - 1}; i > 0; --i) {
    dp[i - 1] = dp[i];
    if (uf.find(A[i]) != uf.find(B[i])) {
      dp[i - 1] -= static_cast<long>(uf.size(A[i])) * uf.size(B[i]);
      uf.unite(A[i], B[i]);
    }
  }

  for (int i{}; i < M; ++i) {
    cout << dp[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 3328
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let x = read::<i64>();
    let mut ans = 1;
    for i in 2..x {
        let mut v = i * i;
        while v <= x {
            ans = std::cmp::max(ans, v);
            v *= i;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
a, b = map(int, input().split())
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x%y)
n = gcd(a, b)
ndiv = n
if n == 1:
    print(1)
else:
    i = 1
    primecount = 0
    divisor = False
    while True:
        i += 1
        while ndiv%i == 0:
            ndiv = ndiv//i
            divisor = True
        if divisor:
            primecount += 1
            divisor = False
            if ndiv == 1:
                break
        if ndiv != 1 and i*i > n:
            primecount += 1
            break
    print(primecount+1)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int n;
int p[100005];

int main(void)
{
	cin >> n;
	for(int i = 0; i < n; i++) cin >> p[i];
	sort(p, p+n);
	
	if(n % 2){
		cout << 0 << endl;
		return 0;
	}
	cout << p[n/2]-p[n/2-1] << endl;
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(void){
	char s[10];
	int max,count;
	count = 0; max = 0;
	for (int i = 0; i < 11; i++)
	{
		scanf("%c",&s[i]);
		if (s[i]=='A' || s[i]=='G' || s[i]== 'C' ||s[i]== 'T'){
			count = count + 1;
		}else{
			if (count > max)
			{
				max = count;
			}
          count = 0;
			
		}
		
	}
	printf("%d\n",max );
	return 0;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int h[] = new int[N];
		int diff = Integer.MAX_VALUE;

		for (int i = 0; i < h.length; i++) {
			h[i] = sc.nextInt();
		}

		Arrays.sort(h);

		for(int i = 0; i < h.length - K + 1; i++) {
			int temp = h[i + K - 1] - h[i];
			if(diff > temp) {
				diff = temp;
			}
		}


		System.out.println(diff);
	}
}

Measured memory_bytes: 62184
#include<iostream>
#include<cstdio>
using namespace std;
int a,b,k[10005];
int main()
{
	int i,j;
    cin>>a>>b;
    for(i=0;i<b;i++)
        cin>>k[i];
    if(b==1)
	{
        cout<<k[0]-1<<endl;
        return 0;
    }
	else
	{
        int ans=0;
        for(i=0;i<b;i++)
		{
            for(int j=0;j<b;j++){
                ans+=k[j];
            }
            ans-=k[i];
            if(ans<k[i]){
                cout<<k[i]-ans-1<<endl;
                return 0;
            }
			else
                ans=0;
        }
    }
    cout<<0<<endl;
    return 0;
}


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

#define V vector
typedef long long ll;
typedef unsigned long long ull;

typedef V<int> vi;
typedef V<ll> vll;
typedef V<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define f(i,a) for(int i = 0 ; i < a ; i++)
#define fll(i,a) for(ll i = 0 ; i < a ;i++)
#define forab(i,a,b) for(int i = a ; i < b ; i++)
#define prec(x) cout<<fixed<<setprecision(x)
#define ff first
#define ss second

#define pb push_back
#define mp make_pair
#define numberofdigits(x) floor(log10(x)) + 1

void solve()
{
	int n;
	cin >> n;

	int a[n] , b[n];

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

	sort(a, a + n);
	sort(b, b + n);

	int  m1 = (n & 1) ? a[(n) / 2] : (a[n / 2] + a[n / 2 - 1]) ;
	int  m2 = (n & 1) ? b[(n) / 2] : (b[n / 2] + b[n / 2 - 1]) ;

	cout << (abs(m2 - m1) + 1) << "\n";


}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int t = 1;
	//cin>>t;

	while (t--)
	{
		solve();
	}

	return 0;
}





Measured memory_bytes: 5192
'use strict';
var data = '';
process.stdin.on('end', function() {
    var inputs = data.toString().trim().split('\n');
    var params = inputs[1].split(' ').map(Number);
    var sum = params.reduce(function(a,b) {
      return a + b;
    });
    var min = params[0];
    var max = params[0];
    for (var i = 0; i < params.length; i++) {
      min = Math.min(min,params[i]);
      max = Math.max(max,params[i]);
    }
 
    console.log(min, max, sum);
 
});
 
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  data += chunk;
});

Measured memory_bytes: 17396
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.Scanner;

/**
 *
 * @author c0117321c5
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c;
        if (a >= 10 || b >= 10) {
            c = -1;
        } else {
            c = a * b;
        }
        System.out.println(c);
    }
}


Measured memory_bytes: 21972
import java.util.*;
import java.io.*;
 
public class Main{
  Scanner sc = new Scanner(System.in);	
 
  public void run(){
    long a = sc.nextLong();
    long b = sc.nextLong();
    long c = sc.nextLong();
    long d = sc.nextLong();
    
    long max = a*c;
    max = Math.max(max, a*d);
    max = Math.max(max, b*c);
    max = Math.max(max, b*d);
    
    System.out.println(max);
  }
  public static void main(String[] args){
    Main m = new Main();
    m.run();
  }
}

Measured memory_bytes: 35936
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<endl
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 2e18;
int dx[4] = { 0,0,-1,1 }, dy[4] = { 1,-1,0,0 };

int H, W;
int dp[303][303];
vector<int>v[2][303];
int calc(const string &S,const string &T) {
	REP(i, 2)REP(j, H)v[i][j].clear();
	REP(i, H) {
		FOR(j, i, H) {
			if (S[i] == T[j]) {
				v[0][j - i].push_back(H - i - 1);
			}
		}
	}
	REP(j, H) {
		FOR(i, j, H) {
			if (T[j] == S[i]) {
				v[1][i - j].push_back(H - j - 1);
			}
		}
	}
	REP(i, H) {
		VSORT(v[0][i]);
		VSORT(v[1][i]);
	}
	REP(i, H + 1) {
		REP(j, H + 1)dp[i][j] = INF;
	}
	dp[0][0] = 0;
	REP(i, H + 1)REP(j, H + 1) {
		if (i >= j) {
			int cnt = 0;
			int M = v[0][i - j].size();
			cnt = v[0][i - j].end() - lb(v[0][i - j], i);
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + cnt);
			dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + cnt);
		}
		else {
			int cnt = 0;
			cnt = v[1][j - i].end() - lb(v[1][j - i], j);
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + cnt);
			dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + cnt);
		}
	}
	return dp[H][H];
}
char C[303][303];
string S[303];
void solve() {
	cin >> H >> W;
	REP(i, H)REP(j, W) {
		cin >> C[i][j];
		S[j] += C[i][j];
	}
	ll ans = 0;
	REP(j, W - 1) {
		//print(calc(S[j], S[j + 1]));
		ans += calc(S[j], S[j + 1]);
	}
	print(ans);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q;cin>>q;
	//while(q--)
	solve();
}




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

ll f(ll b, ll n) {
  if (n < b) return n;
  else return f(b, n / b) + n % b;
}

int main(){
  ll n, s;
  cin >> n >> s;
  for (ll i = 2; i * i <= n; i++) {
    if (f(i, n) == s) {
      cout << i << endl;
      return 0;
    }
  }
  ll ans = -1;
  for (ll i = 1; i * i <= n; i++) {
    ll b = (n - s + i) / i;
    if (b < 2) continue;
    if (f(b, n) == s) {
      if (ans = -1) ans = b;
      else ans = min(ans, b);
    }
  }
  if (ans == -1 && n == s) {
    cout << n + 1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 10000

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

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long


#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)

const int N=1e5+5;
const int mod=1e9+7;
int32_t main() {
    IOS
double k,n;
    cin>>n>>k;
    cout<<1+ceil((n-k)/(k-1));
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
inline char nc()
{
	return getchar();
	static char buf[100000], *l = buf, *r = buf;
	return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void read(T &x)
{
	x = 0; int f = 1, ch = nc();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
	while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
	x *= f;
}
typedef long long ll;
const int maxn = 100000 + 5;
int n, X;
struct data
{
	int b, l, u;
	ll val;
	inline void init()
	{
		val = (ll)l * b + (ll)u * (X - b);
	}
	inline ll F(int x)
	{
		if(x <= b) return (ll)x * l;
		else return (ll)l * b + (ll)(x - b) * u;
	}
	inline bool operator < (const data &other) const
	{
		return val < other.val;
	}
} a[maxn];
inline ll judge(ll k)
{
	int q = k / X, r = k % X;
	if(r == 0) return a[q].val;
	ll re = 0;
	for(int i = 1; i <= n; ++i)
	{
		ll t = a[i].F(r);
		if(i <= q) t += a[i - 1].val + a[q + 1].val - a[i].val;
		else t += a[q].val;
		re = max(re, t);
	}
	return re;
}
int main()
{
	ll sum = 0;
	read(n), read(X);
	for(int i = 1; i <= n; ++i)
	{
		read(a[i].b), read(a[i].l), read(a[i].u);
		sum += (ll)a[i].b * a[i].l;
		a[i].init();
	}
	sort(a + 1, a + n + 1), reverse(a + 1, a + n + 1);
	for(int i = 2; i <= n; ++i)
	{
		a[i].val += a[i - 1].val;
	}
	ll l = 0, r = (ll)n * X, an = -1;
	while(l <= r)
	{
		ll mid = (l + r) >> 1;
		if(judge(mid) < sum) l = mid + 1;
		else r = mid - 1, an = mid;
	}
	printf("%lld\n", an);
	return 0;
}

Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq;

class Program
{
    static Dictionary<int, List<int>> pathDict = new Dictionary<int, List<int>>();
    static Dictionary<int, int> costDict = new Dictionary<int, int>();
    static Dictionary<int, int> dirDict = new Dictionary<int, int>();

    static void Main(string[] args)
    {
        var inputs = Console.ReadLine().Split(' ').Select(c => int.Parse(c)).ToList();
        var N = inputs[0];
        var M = inputs[1];

        for (int i = 1; i <= N; i++)
        {
            pathDict.Add(i, new List<int>());
            costDict.Add(i, int.MaxValue);
            dirDict.Add(i, int.MaxValue);
        }

        costDict[1] = 0;
        dirDict[1] = 0;
        for (int i = 0; i < M; i++)
        {
            var inputs2 = Console.ReadLine().Split(' ').Select(c => int.Parse(c)).ToList();
            var A = inputs2[0];
            var B = inputs2[1];

            pathDict[A].Add(B);
            pathDict[B].Add(A);
        }

        Check(new List<int>() {1}, 0);

        Console.WriteLine("Yes");
        for (int n = 2; n <= N; n++)
        {
            Console.WriteLine(dirDict[n]);
        }
    }

    static void Check(List<int> starts, int currentCost)
    {
        var nexts = new List<int>();
        foreach (var start in starts)
        {
            foreach (var next in pathDict[start])
            {
                if (costDict[next] == int.MaxValue)
                {
                    costDict[next] = currentCost + 1;
                    dirDict[next] = start;
                    nexts.Add(next);
                }
            }
        }

        var nextCost = currentCost + 1;
        if (nexts.Any())
        {
            Check(nexts.Distinct().ToList(), nextCost);
        }
    }
}

Measured memory_bytes: 75340
while True:
    N=int(input())
    k=1000-N
    f=int(k/500)
    h=int((k%500)/100)
    i=int(((k%500)%100)/50)
    t=int((((k%500)%100)%50)/10)
    v=int(((((k%500)%100)%50)%10)/5)
    o=int((((((k%500)%100)%50)%10)%5)/1)

    if N==0:
        break
    print(f+h+i+t+v+o)


Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}


int main(){
  ll s[300000];
  int n;
  cin>>n;
  FOR(i,1,n+1){
    cin>>s[i];
    s[i]+=s[i-1];
  }

  int l=1,r=3;
  ll ans=INF;
  FOR(m,2,n-1){
    while(abs(s[m]-2*s[l+1])<abs(s[m]-2*s[l])) l++;
    while(abs(s[n]-2*s[r+1]+s[m])<abs(s[n]-2*s[r]+s[m])) r++;
    vector<ll> v;
    v.PB(s[l]);
    v.PB(s[m]-s[l]);
    v.PB(s[r]-s[m]);
    v.PB(s[n]-s[r]);
    sort(all(v));
    ans=min(ans,v[3]-v[0]);
  }
  cout<<ans<<endl;
}


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

using str = string;
using ss = stringstream;

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

    str o,e;
    cin>>o>>e;

    for(int i=0;i<e.size();i++)cout<<o[i]<<e[i];

    if(o.size()>e.size())cout<<o[o.size()-1]<<"\n";

    return 0;
}


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

string S;
ll inf = 1e9+7;
ll p3[100010] = {1};
ll p2[100010] = {1};

int main(){
    cin >> S;
    ll N = S.size();
    for(int i=1;i<=N;i++) p3[i] = 3*p3[i-1]%inf;
    for(int i=1;i<=N;i++) p2[i] = 2*p2[i-1]%inf;
    ll ans = 0,cnt = 1;
    for(int i=1;i<=N;i++){
        if(S[i-1]=='1') (ans += p2[cnt-1]*p3[N-i]%inf)%=inf;
        if(i!=N && S[i]=='1') cnt++;
    }
    (ans += p2[cnt])%=inf;
    cout << ans << endl;
}

Measured memory_bytes: 2048
#include <iostream>
#include <string>

using namespace std;

int main() {
    int n, d;
    cin >> n >> d;

    for (int i=1; i<100; i++) {
        n -= 2 * d + 1;
        if (n <= 0) {
            cout << i  << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include<stdio.h>

 int main(void){
 

    int x;

    scanf("%d",&x);
 
    if(1 <= x <= 3000){
       if( x < 1200 ){
       printf("ABC");     
       }
   
       else {
       printf("ARC");
       }
     
    }else{
         printf("error");
     }
 }

Measured memory_bytes: 128
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        x: usize,
        y: usize,
    }

    (x + (y / 2)).to_string()
}

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

using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;

template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

template <class T, class U>
void chmax(T &a, U b) {
    if (a < b) a = b;
}
template <class T, class U>
void chmin(T &a, U b) {
    if (b < a) a = b;
}

#define rep(i, j, k) for (int i = j; i < k; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl;
#define debug3(x, y, z) cerr << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;
#define int ll

const ll mod = 1e9 + 7;
const ll inf = (1LL << 60);

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int N, K;
    cin >> N >> K;

    vi v(K + 1, 0);
    int ans = 0;
    for (int i = K; i > 0; i--) {
        vi pow(30);
        pow[0] = K / i;
        rep(j, 1, 30) {
            pow[j] = pow[j - 1] * pow[j - 1];
            pow[j] %= mod;
        }
        int t = 1;
        int n = N;
        for (int j = 29; j >= 0; j--) {
            if (n >> j & 1) {
                // debug2(n, j);
                t *= pow[j];
                t %= mod;
                n -= (1 << j);
            }
        }
        // rep(j, 0, N) {
        //     t *= K / i;
        //     t %= mod;
        // }
        v[i] = t;
        for (int j = 2 * i; j <= K; j += i) {
            v[i] = (v[i] - v[j] + mod) % mod;
        }
        ans += i * v[i];
        ans %= mod;
    }

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


Measured memory_bytes: 3940
using System;
using System.Linq;

namespace atcoder.abc168.c
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] inputArray = getIntParams();
            double A = (double)inputArray[0];
            double B = (double)inputArray[1];
            double H = (double)inputArray[2];
            double M = (double)inputArray[3];

            double angleA = (H + M / 60) * 30;
            double angleB = M * 6;
            double angle = Math.Abs(angleA - angleB);

            // 予言定理 a2 = b2 + c2 - 2bc * cos(A)
            double ret = Math.Sqrt(Math.Pow(A, 2) + Math.Pow(B, 2) - (2 * A * B * Math.Cos(angle * (Math.PI / 180))));

            Console.WriteLine(ret);
        }

        //↓↓↓ shared function ↓↓↓
        static int getIntParam()
        {
            return int.Parse(Console.ReadLine());
        }
        static int[] getIntParams()
        {
            return Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
        }
        static long getLongParam()
        {
            return long.Parse(Console.ReadLine());
        }
        static long[] getLongParams()
        {
            return Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
        }
        static string getStringParam()
        {
            return Console.ReadLine();
        }
        static string[] getStringParams()
        {
            return Console.ReadLine().Split(' ');
        }
        static decimal getDecimalParam()
        {
            return decimal.Parse(Console.ReadLine());
        }
        static decimal[] getDecimalParams()
        {
            return Console.ReadLine().Split(' ').Select(i => decimal.Parse(i)).ToArray();
        }
    }
}


Measured memory_bytes: 28612
#include <iostream>
//#include <math.h>
#include <set>
#include<iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define space ' '
#define pll pair<ll,ll>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn = 100000;

int main(){
    
    ll n,k;
    ll r,s,p;
    ll ans = 0;
    string t;
    ll point[maxn]={0};
    vector<vector<char >> v(maxn+10);
    
    cin >> n>>k;
    cin >> r>>s>>p;
    cin >> t;
    
    rep(i,k){
        for(int j=i;j<n;j+=k){
            v[i].push_back(t[j]);
        }
    }
    
    rep(i,k){
        char pre='Z';
        rep(j,v[i].size()){
            if(pre==v[i][j]){
                pre = 'Z';
            }else{
                if(v[i][j]=='p'){
                    ans += s;
                }else if(v[i][j]=='r'){
                    ans += p;
                }else if(v[i][j]=='s'){
                    ans += r;
                }
                pre = v[i][j];
            }
        }
    }
    
    cout << ans<<endl;
    
    return 0;
}


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

using namespace std;

# define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<ll, ll> pll;

# define S second
# define F first
# define kill(x) return(cout << x << endl, 0)
# define debug(x) cerr<< #x << " : " << x << endl
# define ddebug(x, y) cerr<< #x << " : " << x  << ", " << #y << " : " << y << endl
# define sz(s) (int)s.size()
# define sq(x) (x) * (x)
# define PB(x) push_back(x)
# define smax(x, y) (x) = max((x), (y))
# define smin(x, y) (x) = min((x), (y))
# define all(x) x.begin(), x.end()
# define SP fixed << setprecision(10)

map <int, int> mp;

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int n;
	cin >> n;
	mp[0] ++;
	int sum = 0, ans = 0;
	for (int i = 0; i < n; i ++)
	{
		int a;
		cin >> a;
		sum += a;
		ans += mp[sum];
		mp[sum] ++;
	}
	cout << ans << endl;


	return 0;
}






Measured memory_bytes: 12800
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>
#include <random>

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

using namespace std;
typedef long long int ll;
const ll INF = 10000000000;
const double PI = acos(-1);
const ll mod = 1000000007;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> a_sorted(n);
    rep(i, n) {
        cin >> a[i];
        a_sorted[i] = a[i];
    }

    sort(a_sorted.rbegin(), a_sorted.rend());
    int first_max = a_sorted[0];
    int second_max = a_sorted[1];
    rep(i, n) {
        if (a[i] == first_max) {
            cout << second_max << endl;
        }
        else {
            cout << first_max << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 4744
package main

import (
	"fmt"
)

func main() {
	var D int
	fmt.Scan(&D)
	
	st := ""
	switch D {
		case 25:
			st = "Christmas"
		case 24:
			st = "Christmas Eve"
		case 23:
			st = "Christmas Eve Eve"
		case 22:
			st = "Christmas Eve Eve Eve"
	}
	fmt.Println(st)

}

Measured memory_bytes: 512
// A

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;

int main(){
  int N,M,K[100];
  cin>>N>>M;
  int ans[40]={0};
  for (int i(0);i<N;i++){
    cin>>K[i];
    for (int j(0);j<K[i];j++){
      int a;
      cin>>a;
      ans[a]++;
    }
  }
  ll cnt(0);
  for (int i(0);i<=M;i++){
    if (ans[i] == N) cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int MAX = 2e3 + 10;
typedef long long i64;
using namespace std;
const double EPS = 1e-6;
const int MOD = 1e9 + 7;
#define mul(a, b) ((i64)(a) * b % MOD)
char ar[MAX][MAX];
vector<int> uu[MAX];
int mat[MAX][MAX] ;

i64 maxHist(int row[], int m){
    stack<int> result;
    i64 max_area = 0;
    int i = 0;
    while (i < m){
        if (result.empty() || row[result.top()] <= row[i])
            result.push(i++);
        else{
            int top_val = row[result.top()]; result.pop();
            i64 area = (i64)(top_val+1) * (i+1);
            if (!result.empty())
                area = (i64)(top_val+1) * (i - result.top() - 1 + 1 );

            max_area = max(area, max_area);
        }
    }
    while (!result.empty())    {
        int top_val = row[result.top()]; result.pop();
        i64 area = (i64)(top_val+1) * (i+1);
        if (!result.empty())
            area = (i64)(top_val+1) * (i - result.top() - 1+1);
        max_area = max(area, max_area);
    }
    return max_area;
}
i64 maxRectangle(int A[][MAX], int n, int m){
    i64 result = maxHist(A[0], m);
    //cout << 0 << " " <<  result << endl;
    for (int i = 1; i < n; i++){
        for (int j = 0; j < m; j++)
            if (A[i][j]) A[i][j] += A[i - 1][j];
        result = max(result, maxHist(A[i], m));
        //cout << i << " " <<  result << endl;
    }
    return result;
}


int main() {

    #ifdef LOCAL_DEBUG
    freopen ("data.in", "r", stdin );
    //freopen ("data.out", "w", stdout );
    #endif
    ios_base::sync_with_stdio(0); cin.tie(0);
    #define endl '\n'


   int n, m;
   cin >> n >> m;
   for(int i = 0; i < n; i++)cin >> ar[i];
   for(int i = 0 ; i < m - 1; i++)
	   mat[0][i] = 0;

   for(int i = 1; i < n; i++){
	   for(int j = 0; j < m-1; j++){
		   if((ar[i][j] != ar[i][j + 1]) == (ar[i - 1][j] != ar[i - 1][j + 1]))
			   mat[i][j] = 1;
	   }

   }
   m -= 1;
   cout << max((i64)n, maxRectangle(mat, n, m));
}



Measured memory_bytes: 19968
#include <iostream>
using namespace std;
#define MAX 100000

int main()
{
	int n;
	int k;
	int h[MAX];
	int cnt = 0;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
		if (h[i] >= k)
			cnt++;
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int Inf = 1e9;
int main()
{
	int N;
	cin >> N;
	vector<long> A(N);
	for(int i = 0; i < N; i++) cin >> A[i];
	long cnt = 0, Sum = 0;
	long Min = Inf;
	for(long& num : A)
	{
		if(num < 0) cnt++;
		Sum += abs(num);
		Min = min(Min, abs(num));
	}
	if(cnt % 2 == 0) cout << Sum << endl;
	else cout << Sum - Min * 2 << endl;

	return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// chmax, chmin
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;
}


vector<int> seq(int N, int X, int D) {
    vector<int> s;
    for (int i = 0; i < N; i++) {
        s.push_back(i * D + X);
    }
    return s;
}

long long solve2(int N, long long X, long long D) {
    if (D == 0) {
        if (X == 0) {
            return 1;
        }
        return N + 1;
    }
    set<long long> S;
    map<long long, vector<pair<ll, ll> > > seqs;

    for (int i = 0; i <= N; i++) {
        long long lb = i * X + D * i * (i - 1) / 2;
        long long ub = i * X + D * (N - 1) * N / 2 - D * (N - i) * (N - i - 1) / 2;
//        long long lb = i * X;
//        long long ub = i * X;



//        for (int j = 0; j < i; j++) {
//            ub += D * (N - j - 1);
//            lb += D * j;
//        }
//        cout << i << " " << lb << " - " << ub << "(" << D << ")" << endl;
//        cout << lb << " " << ub << endl;
        seqs[(lb % D + D) % D].push_back({lb, ub});
    }

    long long ans = 0;
    for (auto p : seqs) {
        auto &v = p.second;
        sort(v.begin(), v.end());
        vector<pair<ll, ll> > m;
        for (int i = 0; i < v.size();) {
            int j = i;
            auto p = v[i];

            while (j < v.size() && v[j].first <= p.second) {
                p.second = max(p.second, v[j].second);
                j++;
            }
            ans += (p.second - p.first) / D + 1;
            i = j;
        }
    }
    return ans;
}

int solve(long long N, long long X, long long D) {
    if (D < 0) D *= -1, X *= -1;
    cout << solve2(N, X, D) << endl;
//    cout << solve2(N, X, D) << " " << solve3(N, X, D) << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    long long X;
    scanf("%lld", &X);
    long long D;
    scanf("%lld", &D);
    solve(N, X, D);
//    for (int i = 1; i <= N; i++) {
//        cout << i << " ";
//        solve(, X, D);
//    }
    return 0;
}


Measured memory_bytes: 22144
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N = get_int
A = get_ints

left = Array.new(N+1, 0)
right = Array.new(N+1, 0)

N.times do |i|
  left[i+1] = left[i].gcd(A[i])
  right[N-2-i] = right[N-2-i+1].gcd(A[N-2-i+1]) if i < N - 1
end

max = 0
N.times do |i|
  stock = left[i].gcd(right[i])
  max = stock if stock > max
end

puts max


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

int main() {
  int N, M;
  while(1){
      cin >> N >> M;
      if(N == 0 && M == 0){
          break;
      }
      for(int i = 0; i < N; i++){
          for(int k = 0; k < M; k++){
              if(i == 0 || i == N-1){
                  cout << "#";
              }
              else {
                  if(k == 0 || k == M-1){
                      cout << "#";
                  }
                  else {
                      cout << ".";
                  }
              }
         }
         cout << endl;
      }
      cout << endl;
  }
}


Measured memory_bytes: 3016
fun main(A: Array<String>) {
    val s = java.util.Scanner(System.`in`)
    val n = s.next()
    val k = s.nextInt()

    val a = Array(n.length) { Array(2) { LongArray(k + 1) { 0L } } }

    a[0][0][1] = (n[0] - '1').toLong()
    a[0][1][1] = 1

    for (i in 1 until n.length) {
        val t = a[i - 1]
        val u = a[i]
        val c = n[i]

        if (c == '0') {
            for (j in 0..k)
                u[1][j] += t[1][j]
        } else {
            for (j in 0..k)
                u[0][j] += t[1][j]
            for (j in 1..k) {
                u[1][j] += t[1][j - 1]
                u[0][j] += t[1][j - 1] * (c - '1')
            }
        }

        for (j in 0..k) {
            u[0][j] += t[0][j]
        }
        for (j in 1..k) {
            u[0][j] += t[0][j - 1] * 9
        }
        u[0][1] += 9L
    }

    println(a.last().map { it[k] }.sum())
}


Measured memory_bytes: 34040
k=0
p gets.to_i.times.with_object(Hash.new{|h,k|h[k]=[]}){|i,h|h[k+=gets.to_i]<<i}.merge({0=>[-1]}){|_,o,n|o+n}.map{|_,v|v.sort}.map{|v|v[-1]-v[0]}.max

Measured memory_bytes: 63232
#include <iostream>
using namespace std;
int main(){
    int n , mountain[11] ;
    for( int i=0 ; i<10 ; i++ )
        cin >> mountain[i] ;
    for( int i=0 ; i<10 ; i++ ){
        for( int j=i+1 ; j<10 ; j++ ){
            if( mountain[i] > mountain[j] )
                swap( mountain[i] , mountain[j] );
        }
    }
    cout << mountain[9] << endl << mountain[8] <<endl << mountain[7] << endl;
}

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

int main() {
  int64_t a, b, k;
  
  cin >> a >> b >> k;
  
  if(k >= a+b) cout << 0 << " " << 0 << endl;
  else if(a < k) cout << 0 << " " << b-(k-a) << endl;
  else cout << a-k << " " << b << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int d, g;
vector<int> p;
vector<int> c;
int main() {
    cin >> d >> g;
    p = vector<int>(d, 0);
    c = vector<int>(d, 0);
    for(int i = 0; i < d; ++i) {
        cin >> p.at(i) >> c.at(i);
    }

    // セットの数Dが高々10までしかないので貪欲で行けると考える。
    // だがそれぞれのセットで解く問題の数を探索するのは流石に間に合わない
    // そこでボーナスを得るセットをどれにするかを探索するのは行ける

    int ans = 100000000;
    for(int s = 0; s < (1 << d); ++s) {
        int solve = 0;
        int score = 0;
        int partial = -1;
        for(int i = 0; i < d; ++i) {
            // ここで1を左に流していくことで1が立っているところをすべてチェックする
            if(s & (1 << i)) {
                solve += p.at(i);
                score += 100*(i+1)*p.at(i) + c.at(i);
            }else {
                // 一番左にある0を探してくれている
                partial = i;
            }
        }

        int less = g - score;
        if(less > 0) {
            int prob_score = 100*(partial+1);
            if(less > prob_score*p.at(partial)) continue;
            solve += min(p.at(partial), (less+(prob_score-1))/prob_score);
        }
        ans = min(ans, solve);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import itertools

n, m, k = map(int, input().split())


def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p


p = 998244353
N = n   # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

ans = 0

l2 = m*(m-1)**(n-k-1)
for _k in range(k, -1, -1):
    # print(_k)

    ncr = cmb(n - 1, _k, p)
    ans += ncr * l2
    ans %= p
    l2 %= p
    l2 *= (m - 1)


print(ans)


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

using namespace std;

int main()
{
	int n, m;
	while (cin >> n >> m, n)
	{
		vector<int> v(n);
		for (int i = 0; i < n; ++i)
		{
			cin >> v[i];
		}
		int ma = 0;
		for (int i = 0; i < n; ++i)
		{
			for (int j = i + 1; j < n; ++j)
			{
				if (v[i] + v[j] > m)
					continue;
				if (ma < v[i] + v[j])
				{
					ma = v[i] + v[j];
				}
			}
		}
		if (ma == 0)
			cout << "NONE" << endl;
		else
			cout << ma << endl;
	}
}


Measured memory_bytes: 3088
#include <cstdio>
#include <cstring>

int n, A[50], dp[21][2001];

int solve(int i, int m)
{
  if (dp[i][m] != -1)
  {
    return dp[i][m];
  }

  if (m == 0)
    dp[i][m] = 1;
  else if (i >= n)
    dp[i][m] = 0;
  else if (solve(i + 1, m))
    dp[i][m] = 1;
  else if (solve(i + 1, m - A[i]))
    dp[i][m] = 1;
  else
    dp[i][m] = 0;

  return dp[i][m];
}

int main()
{
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
  {
    scanf("%d", &A[i]);
  }
  int q, m;
  scanf("%d", &q);
  for (int i = 0; i < q; i++)
  {
    memset(dp, -1, sizeof(dp));
    scanf("%d", &m);
    if (solve(0, m) != 0) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}



Measured memory_bytes: 2776