akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		long l=scan.nextLong();
		long r=scan.nextLong();
		long ans=Long.MAX_VALUE;
		for(long i=l;i<=(Math.min(r, l+2018));i++)
		{
			for(long j=i+1;j<=Math.min(r,l+2018);j++)
			{
				ans=Math.min(ans,((i%2019)*(j%2019))%2019);
			}
		}
		System.out.println(ans);
		
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(){
        long long n, m;
        cin>>n>>m;
        long long a[m], sum=0;
        for(long long i=0;i<m;i++){
                cin>>a[i];
                sum+=a[i];
        }if(sum<=n){
                cout<<(n-sum)<<endl;
        }else{
                cout<<"-1"<<endl;
        }
        return 0;
}

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


signed main() {
	int n, d, x; cin >> n >> d >> x;
	rep(i, n) {
		int a; cin >> a;
		x += (d + a - 1) / a;
	}
	cout << x << endl;
}

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

namespace Atcoder
{

    class Atcoderrrrrrr
    {
        static void Main(string[] args)
        {
            string N = Console.ReadLine();
            int obj = 0;
            for (int i = 0; i < N.Length; i++)
            {
                obj += int.Parse(N[i].ToString());
            }
            Console.WriteLine(
                int.Parse(N) % obj == 0?"Yes":"No"
            );
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

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

    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    int mn;
    int ans = -1001001001;
    rep(i, n) {
        if (i == 0) {
            mn = a[i];
            continue;
        }
        chmax(ans, a[i] - mn);
        chmin(mn, a[i]);
    }
    cout << ans << endl;
}



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

using namespace std;
#define rep(i,n) for (int i =0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char s[105];
int main()
{
	cin>>s;
	int judge1=1;
	int judge2=1;
	for(int i=0;i<strlen(s);i+=2)
	{
		if(s[i]=='R'||s[i]=='U'||s[i]=='D')
		{

		}
		else 
		{
			judge1=0;
			break;
		}
	}
	for(int i=1;i<strlen(s);i+=2)
	{
		if(s[i]=='L'||s[i]=='U'||s[i]=='D')
		{

		}
		else 
		{
			judge2=0;
			break;
		}
	}
	if(judge1==1&&judge2==1) cout<<"Yes";
	else cout<<"No";
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; ++i) cin >> A[i];
  vector<int> B(N,0);
  vector<int> C;
  for(int i = N-1; i >= 0; --i){
    int t = 0;
    for(int j = 2; j*(i+1)-1 < N; ++j)
      t += B[(i+1)*j-1];
    if(t%2 != A[i]) B[i] = 1, C.push_back(i+1);
  }
  // for(int i = 0; i < N; ++i){
  //   cout << B[i];
  //   if(i+1 < N) cout << " ";
  //   else cout << endl;
  // }
  reverse(C.begin(), C.end());
  cout << C.size() << endl;
  for(auto c : C)
    cout << c << endl;
}


Measured memory_bytes: 3064
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


using i64 = ::std::int_fast64_t;
using u64 = ::std::uint_fast64_t;
using i32 = ::std::int_fast32_t;
using u32 = ::std::uint_fast32_t;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 a;
  std::cin >> a;
  std::cout << (a == 1 ? 3 * a : a * (a * a * a - 1) / (a - 1)) << std::endl;
  return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	int N;
	cin >> N;
	vector<int> D(N);
	for(int i=0; i<N; i++) cin >> D[i];

	ll ans = 0;
	for(int i=0; i<N; i++){
		for(int j=i+1; j<N; j++){
			ans += D[i]*D[j];
		}
	}
	cout << ans << endl;

	return 0;
}


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

#define fto(i, a, b) for(int i = a; i <= b; ++i)
#define fdto(i, a, b) for(int i = a; i >= b; --i)
#define ff first
#define ss second
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mp make_pair
#define pb push_back
#define oo 1000000007
#define OO 1000000000000000007

using namespace std;

map <int, bool> m;

int main() {
    int n, ans = 0;
    scanf("%d", &n);
    fto(i, 1, n) {
        int x;
        scanf("%d", &x);
        if (!m[x]) m[x] = 1, ++ans;
        else m[x] = 0, --ans;
    }
    printf("%d\n", ans);
    return 0;
}
///12436


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

using namespace std;

typedef long long ll;

vector<int> h;

int main(int, char**)
{
	ll n, ans = 0;
	cin >> n;
	h.resize(n);

	for (int i = 0; i < n; i++) {
		cin >> h[i];
		int j;
		for (j = 0; j < i; ++j) {
			if (h[j] > h[i])
				break;
		}
		if (i == j) ++ans;
	}

	cout << ans << endl;

	return 0;
}


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

int main() {
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0; i < 3; i++) {
		if (s.at(i) == '1') {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;
ll s[300][300];

int main() {
  int h, w, d;
  cin >> h >> w >> d;
  vector<vector<int>> A(h, vector<int>(w));
  vector<int> ra(h*w);
  for (int i = 0; i < h; ++i) { 
    for (int j = 0; j < w; ++j) { 
      int a; cin >> a; --a;
      ra[a] = i*w+j;
    }
  }
  for (int i = 0; i < h*w; ++i) {
    if (i < d) continue;
    int bi = i-d;
    int bx = ra[bi] % w, by = ra[bi] / w;
    int x = ra[i] % w, y = ra[i] / w;
    s[y][x] = s[by][bx] + abs(x-bx) + abs(y-by);
  }
  int q; cin >> q;
  for (int i = 0; i < q; ++i) { 
    int l, r;
    cin >> l >> r; --l; --r;
    int lx = ra[l] % w, ly = ra[l] / w;
    int rx = ra[r] % w, ry = ra[r] / w;
    cout << s[ry][rx]-s[ly][lx] << endl;
  }
}



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

using namespace std;

int main() {
    int l, r, d;
    cin >> l >> r >> d;
    int ans = 0;
    for (int i = l; i <= r; ++i) {
        if (i % d == 0) ans++;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3612
(* O(n) (n = |s|) *)
let string_count f s =
  let count = ref 0 in
  String.iter (fun c -> if f c then incr count) s;
  !count

let solve s = 700 + string_count ((=) 'o') s * 100

let _ = read_line () |> solve |> string_of_int |> print_endline

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

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

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long N, std::vector<long long> A, std::vector<long long> B)
{
}

int main()
{
    long long N;
    scanf("%lld", &N);
    vector<ll> combi(N);
    std::vector<long long> A(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &A[i]);
    }
    std::vector<long long> B(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &B[i]);
    }
    vector<ll> plus;
    ll husoku = 0;
    ll cnt = 0;
    for (int i = 0; i < N; i++)
    {
        ll dif = A[i] - B[i];
        if (dif < 0)
            husoku -= dif, ++cnt;
        else
            plus.push_back(dif);
    }

    if (husoku == 0)
    {
        cout << 0 << endl;
        return 0;
    }
    else
    {
        RSORT(plus);

        ll p = 0;
        for (int i = 0; i < plus.size(); i++)
        {
            p += plus[i];
            ++cnt;
            if(p >= husoku) break;
        }

    if( p>= husoku) cout << cnt << endl;
    else cout << -1 << endl;
    }


    return 0;
}


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

#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define sz size()
#define endl "\n"
#define pb push_back
#define pp pop_back
#define mp make_pair
#define REP(I,n) for(int I = 0; I < n; I++)
#define REP_1(I,n) for(int I = 1; I <= n; I++)
#define w(t) int t; cin>>t; while(t--)

#define MOD 1000000007
#define INF 1e9 + 7

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef map<int,int> mii;
typedef map<string,int> msi;
typedef map<int,string> mis;
typedef set<int> si;
typedef set<string> ss;

typedef long long ll;

template<class T>
istream &operator>>(istream &in,vector<T> &arr) {
	for(auto &x : arr)
		in>>x;
	return in;
}

bool sortbylen(string a,string b) {
	return a.length() < b.length();
}
void solve() {
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	while(true) {
		c = c - b;
		if(c <= 0) {
			cout<<"Yes";
			return;
		}
		a = a - d;
		if(a <= 0) {
			cout<<"No";
			return;
		}
	}

}
int main() {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL); 
	solve();
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define RFOR(i,m,n) for(int i=m;i>=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()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265


int main(){
  int n;
  cin>>n;
  int a[1000000]={};

  rep(i,n+1){
    a[i]=i;
  }

  for(int j=6;j<=n;j*=6){
    rep(i,n+1){
      if(i<j)continue;
      a[i]=min(a[i],a[i-j]+1);
    }
  }

  for(int j=9;j<=n;j*=9){
    rep(i,n+1){
      if(i<j)continue;
      a[i]=min(a[i],a[i-j]+1);
    }
  }

  cout<<a[n]<<endl;
}



Measured memory_bytes: 4096
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>




class MinSegmentTree {
	std::vector<std::vector<int>> vec;
	int inner_min(int depth, int from, int until) const {
		if (from == until) return INT_MAX;
		int length = 1 << depth;
		int mid = (from + length - 1) / length * length;
		if (mid + length <= until) {
			return std::min({ inner_min(depth, from, mid), inner_min(depth, mid + length, until), vec[depth][mid / length] });
		}
		else if (mid < until) {
			return std::min({ inner_min(depth - 1, from, mid), inner_min(depth - 1, mid, until) });
		}
		else {
			return inner_min(depth - 1, from, until);
		}
	}
public:
	MinSegmentTree(const std::vector<int>& initial) : vec{ initial } {
		while (vec.back().size() > 1) {
			vec.emplace_back(vec.back().size() / 2);
		}
		for (auto i = 1; i < vec.size(); ++i) {
			for (auto j = 0; j < vec[i].size(); ++j) {
				vec[i][j] = std::min(vec[i - 1][j * 2], vec[i - 1][j * 2 + 1]);
			}
		}
	}
	int min_of(int from, int until) const {
		return inner_min(vec.size() - 1, from, until);
	}
};
int main() {
	while (true) {
		int r, c, q; std::cin >> r >> c >> q; if (r == 0 && c == 0 && q == 0) return 0;
		std::vector<std::vector<int>> grid(std::min(r, c), std::vector<int>(std::max(r, c)));
		for (auto i = 0; i < r; ++i) for (auto j = 0; j < c; ++j) {
			if (r <= c) std::cin >> grid[i][j];
			else std::cin >> grid[j][i];
		}
		std::vector<MinSegmentTree> seg; for (const auto& g : grid) seg.emplace_back(g);
		for (auto i = 0; i < q; ++i) {
			int left, right, top, bottom;
			if (r <= c) std::cin >> top >> left >> bottom >> right;
			else std::cin >> left >> top >> right >> bottom;
			int min = INT_MAX;
			for (auto i = top; i <= bottom; ++i) {
				min = std::min(seg[i].min_of(left, right + 1), min);
			}
			std::cout << min << std::endl;
		}
	}
}




Measured memory_bytes: 15212
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000
#define NUM 123456

typedef long long ll;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

bool prime[2*NUM+1];

void hurui(void) {
    for (int i = 0; i <= 2*NUM; i++) prime[i] = true;
    prime[0] = prime[1] = false;
    for (int i = 2; i * i <= NUM*2; i++) {
        if (prime[i]) {
            for (int j = 2; i * j <= NUM*2; j++) {
                prime[i*j] = false;
            }
        }
    }
}

int main(void) {
    hurui();
    int n;
    while (1) {
        cin >> n;
        if (n == 0) break;
        int cnt = 0;
        for (int i = n+1; i <= 2*n; i++) {
            if (prime[i]) cnt++;
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

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

typedef long long ll;

ll a[200000];
ll sum[200000], n;
int table[200000];

bool solve(ll x) {
	int l, r = 1; // [l,r)
	REP(i, 2 * n) table[i] = i;
	REP(i, 2 * n) {
		l = i;
		if (l >= r) r = l + 1;
		while (r - l < n && r < 2 * n && sum[r - 1] - sum[l] + a[l] < x) r++;
		if (sum[r - 1] - sum[l] + a[l] >= x) table[l] = r;
	}
	
	REP(i, n) {
		int pos = i;
		REP(j, 3) {
			if (pos == table[pos]) break;
			pos = table[pos];
			if (pos >= i + n + 1) break;
			if (j == 2 && pos <= i + n + 1) return true;
		}
	}
	return false;
}

int main() {
	cin >> n;
	
	REP(i, n) {
		scanf("%lld", &a[i]);
		a[n + i] = a[i];
	}
	sum[0] = a[0];
	FOR(i, 1, 2*n) sum[i] = sum[i - 1] + a[i];
	
	ll l = -1, r = n * 1000000000;
	while (r - l > 1) {
		ll m = (l + r) / 2;
		if (solve(m)) l = m;
		else r = m;
	}
	
	cout << l << endl;
	
	return 0;
}

Measured memory_bytes: 7096
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
 
//#include <x86intrin.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <bitset> 
#include <vector>
#include <cmath>
#include <deque>     
#include <queue>
#include <iomanip>
#include <stack>
#include <map>
#include <set>
//#include <ordered_set>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;
 
const double pi = acos (-1.0);
const double eps = 1e-9;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, a[N];
ll pref[N], k, ans;
ordered_set < pair <ll, int> > s;

inline void boost () {
   ios_base :: sync_with_stdio (0);
   cin.tie (0), cout.tie (0);
}
 
inline void Solve () {
   cin >> n >> k;
   for (int i = 1; i <= n; i ++) {
      cin >> a[i];
      pref[i] = pref[i - 1] + a[i];
   }
   for (int i = 1; i <= n; i ++) {
      s.in ({pref[i - 1] - k * (i - 1), i - 1});
      ans += s.order_of_key ({pref[i] - 1ll * k * i, mod});
   }
   cout << ans;
   //(pref[r] - pref[l - 1]) / (r - l + 1) >= k
   //pref[r] - pref[l - 1] >= k * (r - (l - 1))
   //pref[r] - pref[l - 1] >= k * r - k * (l - 1)
   //pref[r] - k * r >= pref[l - 1] - k * (l - 1)
}               
 
signed main () {                                       
  // #ifdef QWERTY
  //    freopen("input", "r", stdin);
  // #endif
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}                   

Measured memory_bytes: 18508
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1e18;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
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 namespace std;

int A, B;

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1LL << 60;
int Left[100010], Right[100010];
int main(){
    string s;
    cin >> s;
    int n = s.size();

    rep(i,n){
        if(s[i]=='R') Right[i] = i;
        else Right[i] = Right[i-1];
    }
    for(int i=n-1;i>=0; i--){
        if(s[i]=='L') Left[i] = i;
        else Left[i] = Left[i+1];
    }
    map<int,int> mp;
    rep(i,n){
        if(s[i]=='R'){
            int l = Left[i+1];
            if((l-i)%2==0) mp[l]++;
            else mp[l-1]++;
        }else if(s[i]=='L'){
            int r = Right[i-1];
            if((i-r)%2==0) mp[r]++;
            else mp[r+1]++;
        }
    }
    rep(i,n) cout << mp[i] << endl;
    return 0;
}

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

int main(){
    int N, M;  cin >> N >> M;
    
    int ans = 1;
    for(int g=1; g*g<=M; g++){
        if(M%g==0){
            if(M/g >= N){
                ans = max(ans, g);
            }
            int h = M/g;
            if(M/h >= N){
                ans = max(ans, h);
            }
        }
    }
    cout << ans << endl;
}   

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

long f(long n, long x){
  if(n == -1) return 0;
  return n/x + 1;
}

int main(void){
  long a, b, x;
  cin >> a >> b >> x;
  cout << f(b, x) - f(a-1, x) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    string s;
    cin >> s;
    string t = s;
    int resulta = 0;
    FOR(i,1,s.size()){
        if(s[i]==s[i-1]){
            resulta++;
            if(s[i]=='0'){
                s[i] = '1';
            }else{
                s[i] = '0';
            }
        }
    }
    int resultb = 0;
    DEFOR(i,t.size(),1){
        if(t[i]==t[i-1]){
            resultb++;
            if(t[i-1]=='0'){
                t[i-1] = '1';
            }else{
                t[i-1] = '0';
            }
        }
    }
    cout << min(resulta, resultb) << endl;
    return 0;
}


Measured memory_bytes: 512
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;


class Program
{
    public static long Read()
    {
        return long.Parse(Console.ReadLine());
    }

    public static long[] Reads()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }
    
    public static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);

        var n = Read();
        var count = 0;
        var count1 = 0;
        for (int i = 3; i <= n; i+=2)
        {
            count = 0;
            for(int j = 1; j <= i; j++)
            {
                if (i % j == 0)
                    count++;
            }
            if (count == 8)
                count1++;
        }
        Console.WriteLine(count1);

        Console.Out.Flush();
    }
}

Measured memory_bytes: 11092
import  java.util.*;
import java.math.*;

public class Main {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int x = cin.nextInt();
        int y = cin.nextInt();
        int A = cin.nextInt();
        int B = cin.nextInt();
        int C = cin.nextInt();
        Integer[] a = new Integer[A];
        Integer[] b = new Integer[B];
        Integer[] c = new Integer[C+x+y];
        for(int i = 0; i < A; i++){
        	a[i] = cin.nextInt();
        }
        Arrays.sort(a, 0, A, Collections.reverseOrder());
        for(int i = 0; i < B; i++){
        	b[i] = cin.nextInt();
        }
        Arrays.sort(b,0,B,Collections.reverseOrder());
        
        for(int i = 0; i < C; i++){
        	c[i] = cin.nextInt();
        }
        for(int i = C; i < C+x; i++){
        	c[i] = a[i-C];
        }
        for(int i = C+x; i < C+x+y; i++){
        	c[i] = b[i-C-x];
        }
        Arrays.sort(c,0,C+x+y,Collections.reverseOrder());
        
        long ans = 0;
        for(int i = 0; i < x+y; i++){
        	ans += c[i];
        }
        
        System.out.println(ans);
    }
}

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

typedef int integer;
const int NMAX = 1008, WMAX = 10008;

integer weight[NMAX], value[NMAX], dp[NMAX][WMAX];

void init() {
  for (int i = 0; i < NMAX; i++) {
    weight[i] = value[i] = 0;
  }
  for (int i = 0; i < NMAX; i++) {
    for (int j = 0; j < WMAX; j++) {
      dp[i][j] = 0;
    }
  }
}

int main() {
  int W;
  int Case = 0;
  while (cin >> W and W) {
    Case++;
    init();

    int N;
    cin >> N;
    for (int i = 1; i <= N; i++) {
      scanf("%d,%d", &value[i], &weight[i]);
    }
    
    for (int w = 1; w <= W; w++) {
      for (int i = 1; i <= N; i++) {
        if (weight[i] > w) {
          dp[i][w] = dp[i-1][w];
        } else {
          dp[i][w] = max(dp[i-1][w], dp[i-1][w-weight[i]] + value[i]);
        }
      }
    }

    int minW = W, maxV = dp[N][W];
    for (int w = W; w >= 0; w--) {
      if (dp[N][w] == maxV) {
        minW = w;
      }
    }
    cout << "Case " << Case << ":" << endl;
    cout << maxV << endl << minW << endl;
  }
}

Measured memory_bytes: 40652
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>a>>b>>c;
    ans=c;
    rep(i,10){
        ans=ans*a-b;
        Cout(ans);
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
#define SHOWA(x,n) for( int yui = 0; yui < n; yui++ ){ cout << x[yui] << " "; } cout << endl

#define pb emplace_back
#define fi first
#define se second

using namespace std;

typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
     
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-12;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }

ll in(){ long long int x; scanf( "%lld" , &x ); return x; }
char yuyushiki[1000010]; string stin(){ scanf( "%s" , yuyushiki ); return yuyushiki; }

// head

int n;
int d[64];
vi c;

int main(){

  n = in();

  REP( i , n ){
    d[i] = in();
  }

  sort(d, d + n);

  c.pb(0);
  REP( i , n ){
    if( i % 2 == 0 ){
      c.pb( d[i] );
    } else {
      c.pb( 24 - d[i] );
    }
  }

  /*
  YYS( w , c ){
    cout << w << " " ;
  }
  cout << endl;
  */

  SORT(c);
  
  int s = 24 - d[SZ(c)-1];
  REP( i , SZ(c)-1 ){
    chmin(s, c[i+1] - c[i]);
    // cout << c[i+1] - c[i] << endl;
  }

  printf( "%d\n" , s );

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int main()
{
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 0; i <= m; i++)
	{
		for (int j = 0; j <= n; j++)
		{
			if (i*n + j*m - 2*i*j == k)
			{
				printf("Yes\n");
				return 0;
			}
		}
	}
	printf("No\n");
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
int main() {
    int N, T, A;
    scanf("%d", &N);
    scanf("%d", &T);
    scanf("%d", &A);
    float min = 100000000;
    int best;
    for (int i = 0; i < N; ++i){
        int tmp1;
        float tmp2;
        scanf("%d", &tmp1);
        tmp2 = (float)T - ((float)tmp1 * 0.006);
        if(min > fabs(A-tmp2)){
            best = i+1;
            min = fabs(A-tmp2);
        }
    }
    printf("%d\n", best);
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };
	static final int INF = Integer.MAX_VALUE / 3;
	static final long LINF = Long.MAX_VALUE / 3;

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int n = fs.nextInt(), m = fs.nextInt();
		int a[] = fs.nextIntArray(n);

		for(int i=0;i<n;i++) {
			a[i] /= 2;
		}
		
		int cnt = 1;
		while(a[0]%(cnt*2)==0) {
			cnt *= 2;
		}
		for(int i=1;i<n;i++) {
			if(a[i]%cnt!=0||a[i]/cnt%2==0) {
				System.out.println(0);
				return;
			}
		}
		
		long l = 1;
		for(int i=0;i<n;i++) {
			l = lcm(a[i], l);
			if(l>m) {
				System.out.println(0);
				return;
			}
		}
		
		long mp = m / l;
		
		long ans = (mp+1)/2;
		System.out.println(ans);
		
	}

	static long gcd(long x, long y) {
		return y == 0? x : gcd(y, x%y);
	}
	static long lcm(long x, long y) {
		return x / gcd(x, y) * y;
	}
	
	
	//MOD culculations
	static long plus(long x, long y) {
		long res = (x + y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long sub(long x, long y) {
		long res = (x - y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long mul(long x, long y) {
		long res = (x * y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long div(long x, long y) {
		long res = x * pow(y, mod - 2) % mod;
		return res < 0 ? res + mod : res;
	}

	static long pow(long x, long y) {
		if (y < 0)
			return 0;
		if (y == 0)
			return 1;
		if (y % 2 == 1)
			return (x * pow(x, y - 1)) % mod;
		long root = pow(x, y / 2);
		return root * root % mod;
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	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;
	}
}

Measured memory_bytes: 39388
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;

typedef struct x {
    ll num;
    bool U;
} X;

void print(vector<X> &B) {
    FOREACH(e, B) {
        if (e.U) cout << "U";
        cout << e.num << " ";
    }
    cout << endl;
}

int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    vector<ll> t(n), a(n);
    REP(i,n) cin >> t[i];
    REP(i,n) cin >> a[i];
    vector<X> T(n,{0, false}), A(n, {0, false}), B(n, {0, false});
    T[0] = {t[0], false};
    A[n-1] = {a[n-1], false};
    for (int i = 1; i < n; ++i) {
        if (t[i] == t[i-1]) {
            T[i] = {t[i], true};
        }
        else {
            T[i] = {t[i], false};
        }
    }
    for (int i = n-2; i >= 0; --i) {
        if (a[i] == a[i+1]) {
            A[i] = {a[i], true};
        }
        else {
            A[i] = {a[i], false};
        }
    }
    REP(i,n) {
        if ((T[i].num > A[i].num && !T[i].U && A[i].U) || (A[i].num > T[i].num && !A[i].U && T[i].U) || (!T[i].U && !A[i].U && T[i].num != A[i].num)) {
            cout << 0 << endl;
            return 0;
        }
        if (T[i].U && A[i].U) {
            B[i] = {min(t[i], a[i]), true};
        }
        else {
            B[i] = {min(t[i], a[i]), false};
        }
    }
    ll ans = 1ll;
    REP(i,n) {
        if (B[i].U) {
            ans = ans%MOD*B[i].num%MOD;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<string> A(N);
  vector<string> B(M);
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < M; i++) cin >> B[i];

  for (int i = 0; i < N - M + 1; i++) {
    for (int j = 0; j < N - M + 1; j++) {
      bool flag = true;
      for (int k = 0; k < M; k++) {
        for (int l = 0; l < M; l++) {
          if (A[i + k][j + l] != B[k][l]) flag = false;
        }
      }
      if (flag) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#ifdef boost
	#pragma GCC target ("avx2")
	#pragma GCC optimization ("O3")
	#pragma GCC optimization ("unroll-loops")
#endif
#include<bits/stdc++.h>
#define int long long
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
#define __ read()
using namespace std;
const int maxn(1e5+5);
void rda(int *a,int n){for(int i=1;i<=n;++i)a[i]=__;}
void print(int *a,int n){for(int i=1;i<=n;++i)printf("%lld ",a[i]);puts("");}
int T;
signed main()
{
	int s=0;char c='0';
	while(c>='0'&&c<='9')s=s+c-'0',s%=9,c=getchar();
	puts(s%9==0?"Yes":"No");
}




Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> x(n);
  rep(snip_i, n) cin >> x.at(snip_i);
  int ans = 1001001001;
  rep(i, n-k+1){
    int l = x.at(i), r = x.at(i+k-1);
    int add1 = abs(r) + abs(r-l);
    int add2 = abs(l) + abs(l-r);
    int add = min(add1, add2);
    ans = min(ans, add);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
using namespace std;
constexpr int64_t MOD = 2019;

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

  int32_t N, M;
  cin >> N >> M;
  vector<vector<int>> graph(N);
  for (int i = 0; i < M; i++) {
    int a,b;
    cin >> a >> b;
    graph[a-1].push_back(b-1);
    graph[b-1].push_back(a-1);
  }
  vector<int> res(N, -1);
  res[0] = 0;
  queue<pair<int,int>> q;
  int visit_cnt = 1;
  for (auto next : graph[0]) {
    q.push(make_pair(0,next));
  }
  while (!q.empty()) {
    pair<int,int> cp = q.front();
    q.pop();
    if (res[cp.second] != -1) {
      continue;
    }
    visit_cnt++;
    res[cp.second] = cp.first;
    for (auto next : graph[cp.second]) {
      if (res[next] == -1) {
        q.push(make_pair(cp.second,next));
      }
    }
  }
  if (visit_cnt != N) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
    for (int i = 1; i < N; i++) {
      cout << res[i] + 1 << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 10968
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

// ダイクストラ法
// 参照：蟻本　p97
// O(mlogn)
struct edge{
    int to;
    ll cost;
};
typedef pair<int,int> P; // firstは最短距離、secondは頂点の番号
 
vector<edge> G[100010];
ll d[100010];
int n;
 
void dijkstra(int s){
    priority_queue<P,vector<P>, greater<P>> que;
    fill(d,d+n,1LL<<60);
    d[s]=0;
    que.push(P(0,s));
 
    while(!que.empty()){
        P p=que.top(); que.pop();
        int v=p.second;
        if(d[v]<p.first) continue;
        rep(i,G[v].size()){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}
 
int main(){
    cin>>n;
 
    rep(i,n-1){
        int a,b;
        ll c;
        cin>>a>>b>>c;
        a--,b--;
        G[a].push_back({b,c});
        G[b].push_back({a,c});
    }
    
    int q,k;
    cin>>q>>k;
    k--;
    dijkstra(k);
    rep(i,q){
        int x,y;
        cin>>x>>y;
        x--,y--;
        cout<<d[x]+d[y]<<endl;
    }
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll h,w; cin>>h>>w;
  ll n; cin>>n;
  vll a(n); rep(i,n) cin>>a[i];
  
  vvll ans(h, vll(w));
  
  int row=0;
  int col=0;
  rep(i,n){
    ll now=a[i];
    while(now){
      now--;
      ans[row][col]=(i+1);
      if(row%2) col--;
      else col++;
      
      if(col<0 || col>=w){
        row++;
        if(row%2) col=w-1;
        else col=0;
      }
    }
  }
  rep(i,h){
    rep(j,w){
      cout<<ans[i][j]<<" ";
    }
    cout<<endl;
  }
}

Measured memory_bytes: 512
//参考：http://ehafib.hatenablog.com/entry/2015/12/23/164517
//インクルード
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

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

  int n;
	cin >> n;
  ll count = 0;
  FOR(i, 1, n) {
    if (i%3!=0 && i%5!=0) {
      count += i;
    }
  }
	cout << count << "\n";
}


Measured memory_bytes: 3200
/*
  dp[テ」ツ?ゥテ」ツ?禿」ツ?セテ」ツ?ァテゥツ崢?ゥツ?催」ツ?療」ツ?淌」ツ?犠[ティツ按ケテ」ツ?ョテ・ツ?エテヲツ可?テ」ツ?ァDPテ」ツ??
  z[i] -> z[i+1]テ」ツ?ョテァツァツサテ・ツ仰陛」ツ?ョテゥツ堋崚」ツ?ォティツ按ケテ」ツ?ッテ・ツ、ツ堙」ツ?湘」ツ?ヲテ」ツつ?テ・ツ崢榲」ツ?療」ツ?凝、ツケツ療」ツつ嘉」ツ?ェテ」ツ??」ツ?ョテ」ツ?古」ツδ敕」ツつ、テ」ツδウテ」ツδ暗」ツ??」ツ?ィテヲツ?敕」ツ??」ツ??
 */
#include <iostream>
#include <algorithm>
using namespace std;

const int MAXN = 202;
const int MAXR = 1002;
const int INF = 1<<28;

int N, M;
int land[MAXN][MAXN], sea[MAXN][MAXN];
int R;
int Z[MAXR];

int dp[MAXR][MAXN];

void warshallFloyd(int n, int g[MAXN][MAXN]) {
  for(int k = 0; k < n; ++k) {
    for(int i = 0; i < n; ++i) {
      for(int j = 0; j < n; ++j) {
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
}

int main() {
  while(cin >> N >> M && (N|M)) {
    for(int i = 0; i < MAXN; ++i) {
      for(int j = 0; j < MAXN; ++j) {
        land[i][j] = sea[i][j] = (i == j) ? 0 : INF;
      }
    }
    for(int i = 0; i < M; ++i) {
      int x, y, t;
      char sl;
      cin >> x >> y >> t >> sl;
      --x; --y;
      if(sl == 'L') {
        land[x][y] = land[y][x] = min(land[x][y], t);
      } else {
        sea[x][y] = sea[y][x] = min(sea[x][y], t);
      }
    }
    cin >> R;
    for(int i = 0; i < R; ++i) {
      cin >> Z[i];
      --Z[i];
    }

    warshallFloyd(N, land);
    warshallFloyd(N, sea);

    fill(dp[0], dp[MAXR], INF);
    dp[0][Z[0]] = 0;
    for(int i = 0; i+1 < R; ++i) {
      for(int j = 0; j < N; ++j) {
        if(dp[i][j] == INF) continue;
        int a = Z[i];
        int b = Z[i+1];
        dp[i+1][j] = min(dp[i+1][j], dp[i][j] + land[a][b]);
        for(int k = 0; k < N; ++k) {
          dp[i+1][k] = min(dp[i+1][k],
                           dp[i][j] + land[a][j] + sea[j][k] + land[k][b]);
        }
      }
    }

    int res = INF;
    for(int j = 0; j < N; ++j) {
      res = min(res, dp[R-1][j]);
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 2276
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

int main()
{
	int A, B;
	cin >> A >> B;

	if (A >= 13) {
		cout << B << endl;
	}
	else if (6 <= A && A <= 12) {
		cout << B / 2 << endl;
	}
	else {
		cout << 0 << endl;
	}
}


Measured memory_bytes: 3632
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N;
    cin >> N;

    vll A(N);
    REP(i, N) cin >> A[i];

    bool f = false; // utta?
    vector<int> v(N, 0); // 0: no 1: uri 2: kai
    REP(i, N - 1) {
        if (A[i] > A[i + 1]) {
            v[i] = 1;
        } else if(A[i] < A[i + 1]) {
            v[i] = 2;
        }
    }
    v[N-1] = 1;

    ll stock = 0;
    ll ans = 1000;
    f = false;
    REP(i, N) {
        ll c = ans / A[i];
        if(v[i] == 2) {
            // uri
            stock += c;
            ans -= c * A[i];
            f = true;
        } else if(v[i] == 1) {
            ans += A[i] * stock;
            stock = 0;
            f = false;
        } else {
            if (f) {
                stock += c;
                ans -= c * A[i];
            }
        }
    }

    print(ans);
    
}


Measured memory_bytes: 3644