akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const ll mod = 1e9 + 7;

vector<ll> dx = {1, -1, 0, 0};
vector<ll> dy = {0, 0, 1, -1};

vector<string> g;

int main() {
    
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    
    ll n, d, a;
    cin >> n >> d >> a;
    
    vector<P> m(n);
    vector<ll> c(n + 1);
    for (int i = 0; i < n; ++i)
    {
        cin >> m[i].first >> m[i].second;
    }
    
    sort(m.begin(), m.end());
    
    ll ret = 0;
    for (int i = 0; i < n; ++i)
    {
        if (i != 0)
        {
            c[i] += c[i - 1];
        }
        ll cur = m[i].second + c[i];
        if (cur > 0)
        {
            ll use = (cur + a - 1) / a;
            ret += use;
            c[i] -= use * a;
            auto itr = upper_bound(m.begin() + i, m.end(), P(m[i].first + 2ll * d, mod));
            c[itr - m.begin()] += use * a;
        }
    }
    
    cout << ret << endl;
    
    return 0;
}

Measured memory_bytes: 4992
use std::cmp::min;

fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: usize = read(&mut stdin_lock, &mut buf, b'\n');
    let mut av = vec![0i64; n + 1];
    for i in 0..n {
        av[i] = read(&mut stdin_lock, &mut buf, b' ');
    }
    av[n] = read(&mut stdin_lock, &mut buf, b'\n');
    let mut bv = vec![0i64; n];
    for i in 0..n - 1 {
        bv[i] = read(&mut stdin_lock, &mut buf, b' ');
    }
    bv[n - 1] = read(&mut stdin_lock, &mut buf, b'\n');

    let mut ans = 0i64;
    for i in 0..n {
        let l = min(av[i], bv[i]);
        let r = min(av[i + 1], bv[i] - l);
        av[i + 1] -= r;
        ans += l + r;
    }
    println!("{}", ans);
}


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

using namespace std;

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back

typedef unsigned int uint;
typedef long long ll;
typedef pair<int,int> pii;

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

ll a[2000],m[2000][2000];

int main(){
	int n=read();
	ll x=read();
	REP(i,n)
		a[i]=read();
	REP(i,n)
		REP(j,n)
			m[i][j]=min((j>0?m[i][j-1]:1145141919),a[(i-j+n)%n]);
	ll ans=LLONG_MAX;
	REP(i,n){
		ll cost=x*i;
		REP(j,n)
			cost+=m[j][i];
		ans=min(ans,cost);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 31488
N, M = map(int, input().split())
cakes = [[] for i in range(N)]
for i in range(N):
    cakes[i] = list(map(int, input().split()))

def calc(c):
    x, y, z = 0, 0, 0
    for i in range(M):
        x += c[i][0]
        y += c[i][1]
        z += c[i][2]
    return abs(x) + abs(y) + abs(z)

ans = 0
for i in (-1, 1):
    for j in (-1, 1):
        for k in (-1, 1):
            cakes.sort(key=lambda x: x[0]*i + x[1]*j + x[2]*k)
            ans = max(ans, calc(cakes))

print(ans)


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

namespace abc100b
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(Solve(Console.In));
        }

        internal static uint Solve(System.IO.TextReader reader)
        {
            var s = reader.ReadLine().Split();
            var d = uint.Parse(s[0]);
            var n = uint.Parse(s[1]);
            return Power(100, d) * (n % 100 == 0 ? n + 1 : n);
        }

        internal static uint Power(uint baseNumber, uint exponent)
        {
            if (exponent == 0)
                return 1;

            return Power(baseNumber, exponent - 1) * baseNumber;
        }
    }
}


Measured memory_bytes: 13140
#include<stdio.h>
#include<stdlib.h>
int cmp(const void *a,const void *b)
{
	return *(int *)a-*(int *)b;
}
int main()
{
	int n,a[100005]={},flag=0,count=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	qsort(a,n,sizeof(a[0]),cmp);
	for(int i=0;i<n-1;i++){ //寻找重复的牌的数量
		if(a[i]==a[i+1]){
			flag=1;
			count++;
		}
		else flag=0;
	}
	if(count%2) count++; //如果重复的牌为单数必须再弃一张正常牌
	printf("%d\n",n-count); //贪心策略 每次都弃重复的牌即可
	return 0;
}

Measured memory_bytes: 892
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#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,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define rn return
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;

int main(){
    int N,K; cin >> N >> K;
    cout << (N%K == 0? 0:1);
    rn 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T & a, T b) { if (a < b)a = b; }
template<class T>void chmin(T & a, T b) { if (a > b)a = b; }
constexpr int INF = 1000000000000000000;
constexpr int mod = 1000000007;
int dx[] = { 0,1,0,-1 }, dy[] = { 1,0,-1,0 };
int kaijo[2000010];
struct edge { int to, cost; };
int gcd(int a, int b) {
    if (b == 0)return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a / gcd(a, b) * b;
}
bool prime(int a) {
    if (a == 1)return false;
    for (int i = 2; i * i <= a; i++) {
        if (a % i == 0)return false;
    }
    return true;
}
void init_fact() {
    kaijo[0] = 1;
    for (int i = 1; i <= 2000000; i++) {
        kaijo[i] = kaijo[i - 1] * i;
        kaijo[i] %= mod;
    }
}
int modpow(int a, int b) {
    if (b == 0)return 1;
    if (b % 2)return modpow(a, b - 1) * a % mod;
    int memo = modpow(a, b / 2);
    return memo * memo % mod;
}
int comb(int a, int b) {
    if (!kaijo[0])init_fact();
    return kaijo[a] * modpow(kaijo[a - b], mod - 2) % mod * modpow(kaijo[b], mod - 2) % mod;
}
int inv(int x) {
    x = modpow(x, mod - 2);
    return x;
}
bool kosa(double ax, double ay, double bx, double by, double cx, double cy, double dx, double dy) {
    double ta = (cx - dx) * (ay - cy) + (cy - dy) * (cx - ax);
    double tb = (cx - dx) * (by - cy) + (cy - dy) * (cx - bx);
    double tc = (ax - bx) * (cy - ay) + (ay - by) * (ax - cx);
    double td = (ax - bx) * (dy - ay) + (ay - by) * (ax - dx);
    return tc * td < 0 && ta * tb < 0;
}
double dist(double ax, double ay, double bx, double by) {
    return sqrt((bx - ax) * (bx - ax) + (ay - by) * (ay - by));
}
int n, m, k, a[100010], b[100010], c[100010], d[100010], ans[100010], fri[100010];
int par[100010], siz[100010];
void init(int x) {
    rep(i, x) {
        par[i] = i;
        siz[i] = 1;
    }
}
int find(int x) {
    if (par[x] == x)return x;
    return par[x] = find(par[x]);
}
void unite(int x, int y) {
    x = find(x), y = find(y);
    if (x == y)return;
    if (siz[x] < siz[y])swap(x, y);
    par[y] = x;
    siz[x] += siz[y];
}
bool same(int x, int y) {
    return find(x) == find(y);
}
int size(int x) {
    return siz[find(x)];
}
signed main() {
    cin >> n >> m >> k;
    init(n);
    rep(i, m) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
        unite(a[i], b[i]);
        fri[a[i]]++;
        fri[b[i]]++;
    }
    rep(i, n) {
        ans[i] = size(i) - 1;
        ans[i] -= fri[i];
    }
    rep(i, k) {
        cin >> c[i] >> d[i];
        c[i]--, d[i]--;
        if (same(c[i], d[i])) {
            ans[c[i]]--;
            ans[d[i]]--;
        }
    }
    rep(i, n)cout << ans[i] << (i == n - 1 ? "\n":" ");
    return 0;
}

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

vector<int> parse(int n, string& s) {
    char c = s[0];
    int tmp = 1;
    vector<int> res;
    for (int i = 1; i < n; i++) {
        if (s[i] != c) {
            c = s[i];
            res.push_back(tmp);
            tmp = 1;
        } else {
            tmp++;
        }
    }
    res.push_back(tmp);
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    string s;
    cin >> n >> k >> s;
    vector<int> v = parse(n, s);
    int ans = 0, cnt = 0, seq = 0;
    queue<int> q;
    if(s[0] == '0'){
        if(v.size()%2 != 0) v.push_back(0);
    }
    else{
        ans += v[0];
        if(v.size()%2 == 0) v.push_back(0);
    }
    for(int i = (s[0] == '0') ? 0 : 1; i < v.size(); i+=2){
        if(seq >= k){
            int p = q.front();
            q.pop();
            cnt -= p;
            if(seq != k){
                p = q.front();
                q.pop();
                cnt -= p;
            }
        }
        q.push(v[i]);
        q.push(v[i+1]);
        cnt += v[i]+v[i+1];
        ans = max(ans, cnt);
        seq++;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  string str;
  cin >> str;

  int count = 0;
  for (int i = 0; i < str.size(); i++) {
    if (str.at(i) == '1') {
      count++;
    }
  }

  cout << count << endl;
}


Measured memory_bytes: 3568
#include "bits/stdc++.h"

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

using LL = long long int;
using LD = long double;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
LL gcd(LL x, LL y) { return y ? gcd(y, x % y) : x; }

const int n = 8;

int row[n], col[n], dpos[2 * n - 1], dneg[2 * n - 1];
bool x[n][n];

void printBoard() {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (x[i][j] && row[i] != j) {
				return;
			}
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cout << ((row[i] == j) ? "Q" : ".");
		}
		cout << endl;
	}
}

void recursive(int i) {
	if (i == n) {
		printBoard();
		return;
	}
	
	for (int j = 0; j < n; j++) {
		if (1 == col[j] || 1 == dpos[i + j] || 1 == dneg[i - j + n - 1]) continue;

		row[i] = j;
		col[j] = dpos[i + j] = dneg[i - j + n - 1] = 1;

		recursive(i + 1);

		row[i] = col[j] = dpos[i + j] = dneg[i - j + n - 1] = -1;
	}
}

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

	for (int i = 0; i < n; i++) {
		row[i] = -1;
		col[i] = -1;
	}
	for (int i = 0; i < 2 * n - 1; i++) {
		dpos[i] = -1;
		dneg[i] = -1;
	}

	int k;
	cin >> k;

	for (int i = 0; i < k; i++) {
		int r, c; cin >> r >> c;
		x[r][c] = true;
	}

	recursive(0);
	return 0;
}

Measured memory_bytes: 3140
//SiR
#include<iostream>
using namespace std;

int main()
{
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	if ((W >= x+r && H >= y+r) && (x-r >= 0 && y-r >= 0))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


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

using namespace std;

int dirs[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
//int dirs[8][2]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};

int main()
{
    //ios::sync_with_stdio(false);
    //freopen("inp.in","r",stdin);
    //freopen("outp.out","w",stdout);
    long long N, K;
    cin >> N >> K;
    vector<long long> v(N);
    for(int i=0; i<N; i++) cin >> v[i];
    if(K==1)
    {
        cout << 0 << endl;
        return 0;
    }
    vector<long long> part_sum(N,0);
    for(int i=0; i<N; i++)
    {
        part_sum[i]+=v[i];
        if(i-1>=0) part_sum[i]=(part_sum[i-1]+part_sum[i]);
        part_sum[i]%=K;
    }
    long long ans=0;
    map<long long, long long> ma;
    queue<long long> q;
    q.push(0);
    ma[0]++;
    long long counter=1;
    for(int i=0; i<N; i++)
    {
        if(i+1>=K)
        {
            long long fro=q.front();
            q.pop();
            ma[fro]--;
        }
        long long to_look=(part_sum[i]-counter+K)%K;
        ans+=ma[to_look];
        ma[to_look]++;
        q.push(to_look);
        counter=(counter+1)%K;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 17536
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#include <bitset>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  ll n,k,q,ans=0;
  cin>>n>>k>>q;
  vector<ll>v(q,0);
  vector<ll>vv(n,0);
  for(ll i=0;i<q;i++){
    cin>>v[i];
    vv[v[i]-1]++;
  }
  for(ll i=0;i<n;i++){
    if(k-(q-vv[i])>0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }

}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>

template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}
void comb(vector<vector<ll>> &v) //v{n][k] == nCk
{
	for (int i = 0; i < v.size(); i++)
	{
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int k = 1; k < v.size(); k++)
	{
		for (int j = 1; j < k; j++)
		{
			v[k][j] = v[k - 1][j - 1] + v[k - 1][j];
		}
	}
}
string RunLengthEncoding(string str)
{
	int itr = 0;
	std::string res;
	while (itr < int(str.size()))
	{
		char tmp = str[itr++];
		int length = 1;
		while (itr < int(str.size()) && str[itr] == tmp)
		{
			++itr;
			++length;
		}
		res.push_back(tmp);
		res += to_string(length);
	}
	return res;
}

int a[101][101]={0};

int main()
{
	int n, m;
	cin >> n >> m;
	veci h(n);
	rep(i,n){
		cin >> h[i];
	}
	vector<bool> h_(n,true);
	rep(i,m){
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		if(h[a]<h[b]){
			h_[a] = false;
		}
		else if(h[a]>h[b]){
			h_[b] = false;
		}
		else{
			h_[a] = h_[b] = false;
		}
	}
	ll ans = 0;
	rep(i,n){
		if(h_[i]){
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3736
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip> // for /* << std::fixed << std::setprecision(k) << */
using namespace std;

//defines

#define forn(n) for(int i = 0; i < n; i++)
#define pb push_back
#define int long long

int32_t main() {
	int h, n;
	
	cin >> h >> n;
	
	vector<int> a(n), b(n);
	
	for (int i = 0; i < n; i++)
		cin >> a[i] >> b[i];
		
	vector<int> dp(h+1, 1e18);
	
	dp[0] = 0;
		
	for (int i = 0; i < h; i++) 
		for (int j = 0; j < n; j++) {
			int hit = i + a[j];
			
			if (hit > h)
				hit = h;
			
			dp[hit] = min(dp[i]+b[j], dp[hit]); 
		}
	
	cout << dp[h];
}



Measured memory_bytes: 3736
/*
Original problem: https://atcoder.jp/contests/abc137/tasks/abc137_c
Author: sammochen
*/

#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;

#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)

#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef vector<ll> VLL;
typedef vector<int> VI;

const ll mod = 1e9+7;

namespace SOLVE {
    void main() {
        int n;
		cin >> n;
		map<VI,ll> cnt;

		string s;
		ll ans = 0;
		REP(i,0,n){
			cin >> s;
			VI f(26);
			for (char c : s) {
				f[c - 'a']++;
			}
			ans += (cnt[f]);
			cnt[f]++;
		}
		cout << ans << endl;
    }
}


signed main() {
	int t;
	t = 1;
	// cin >> t;
	while (t--) {
		SOLVE::main();
	}

	return 0;
}

Measured memory_bytes: 18944
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int main() {
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<int> as(a), bs(b), cs(c);
    for (int i = 0; i < a; ++i)
        cin >> as[i];
    for (int i = 0; i < b; ++i)
        cin >> bs[i];
    for (int i = 0; i < c; ++i)
        cin >> cs[i];
    sort(as.rbegin(), as.rend());
    sort(bs.rbegin(), bs.rend());
    sort(cs.rbegin(), cs.rend());
    priority_queue<long long, vector<long long>, greater<long long>> apq, bpq;
    for (int i = 0; i < x; ++i)
        apq.push(as[i]);
    for (int i = 0; i < y; ++i)
        bpq.push(bs[i]);
    for (int i = 0; i < min(c, x + y); ++i) {
        int r = cs[i];
        if (apq.top() >= r && bpq.top() >= r) break;
        if (apq.top() < bpq.top()) {
            apq.pop();
            apq.push(r);
        } else {
            bpq.pop();
            bpq.push(r);
        }
    }
    long long ans = 0;
    while (!apq.empty()) {
        ans += apq.top();
        apq.pop();
    }
    while (!bpq.empty()) {
        ans += bpq.top();
        bpq.pop();
    }
    cout << ans << endl;
    return 0;
}


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

#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define DEBUG_PRINT(...) fprintf(stderr, __VA_ARGS__)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
void print_pair(pi a){
  cerr<<"("<<a.first<<", "<<a.second<<") ";
}
template<int T1, int T2>
void print_2d(int a[T1][T2], int x, int y){
  For(i, x){
    For(j, y){
      cerr<<a[i][j]<<" ";
    }
    cerr<<endl;
  }
}

template<typename T>
int sgn(T val){
  return (T(0)<val)-(val<T(0));
}

tuple<long long,long long,long long> egcd(long long a,long long b){
  if(a==0||b==0)return std::make_tuple(0LL,0LL,0LL);
  long long sa=sgn(a),sb=sgn(b);
  a=std::abs(a);b=std::abs(b);
  long long p=1,q=0,r=0,s=1;
  while(b>0){
    long long c=a/b;
    long long d;
    d=a;a=b;b=d%b;
    d=p;p=q;q=d-c*q;
    d=r;r=s;s=d-c*s;
  }
  return std::make_tuple(a,p*sa,r*sb);
}

long long inverse(long long a,long long m){
  auto b=egcd(a,m);
  if(std::get<0>(b)!=1)return 0;
  return (std::get<1>(b)<0)?std::get<1>(b)+m:std::get<1>(b);
}

long long factorial(long long a,long long m){
  long long ret=1;
  for (long long i = 1; i <= a; i++) {
    ret*=(i%m);
    ret%=m;
  }
  return ret;
}
long long partial_factorial(long long a,long long n,long long m){
  long long ret=1;
  for (long long i = 0; i < n; i++) {
    ret*=(a-i)%m;
    ret%=m;
  }
  return ret;
}
long long combination_prime(long long n,long long r,long long m){
  long long ret;
  long long fact_r=factorial(r,m);
  ret=inverse(fact_r,m);
  long long pfact_n=partial_factorial(n,r,m);
  ret*=pfact_n;
  ret%=m;
  return ret;
}
long long cache_cmb[1000000],cache_inv_fact[1000000];
bool cached=false;
long long combination_cached(long long n,long long r,long long m){
  if(cached==false){
    cached=true;
    cache_inv_fact[1]=1;
    for (long long i = 2; i <= n; i++) {
      cache_inv_fact[i]=(m-m/i)*cache_inv_fact[m%i]%m;
    }
    cache_cmb[0]=1;
    for (long long i = 1; i <= n/2; i++) {
      cache_cmb[i]=cache_cmb[i-1]*(n-i+1)%m*cache_inv_fact[i]%m;
    }
  }
  r=min(r,n-r);
  return cache_cmb[r];
}

ll N,A,B,K;
vector<pair<ll,ll> > pat;
const long long mod=998244353;
int main()
{
        ll n,a,b,k,ans=0;
  cin>>n>>a>>b>>k;
  for(ll i=0,j;i<=n;i++)
  {
    if(a*i>k) break;
    if((k-a*i)%b==0) j=(k-a*i)/b; else continue;
    if(j>n) continue;
    ans+=combination_cached(n,i,mod)*combination_cached(n,j,mod)%mod;
    ans%=mod;
  }
        printf("%lld\n",ans);
        return 0;
}


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

int main()
{
  int n, d;

  cin >> n >> d;
  int ans = 0;

  double x, y;
  rep(i, n)
  {
    cin >> x >> y;
    double dis = sqrt(x * x + y * y);
    if (d >= dis)
      ans++;
  }
  cout << ans;
}


Measured memory_bytes: 3780
#include<bits/stdc++.h>
#include<iomanip>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007
#define KETA 40

using namespace std;

typedef long long  ll;
typedef pair<ll,ll> P1;
typedef pair<string,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<Pi,int> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	char c1,c2,c3,c4;

	cin>>c1>>c2>>c3>>c4;

	if(c1==c2&&c3==c4&&c2!=c3)cout<<"Yes"<<endl;
	else if(c1==c3&&c2==c4&&c1!=c2)cout<<"Yes"<<endl;
	else if(c1==c4&&c2==c3&&c1!=c2)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
typedef long long ll;
typedef pair<int,int> P;
int n,w;
int a[114],b[114];
int mi=1145141919;
vector<int>v[5];
int cnt=0;
signed main(){
	cin>>n>>w;
	rep(i,n){
		cin>>a[i]>>b[i];
		mi=min(a[i],mi);
	}
	rep(i,n){
		v[a[i]-mi].push_back(b[i]);
	}
	sort(v[0].begin(),v[0].end());
	sort(v[1].begin(),v[1].end());
	sort(v[2].begin(),v[2].end());
	sort(v[3].begin(),v[3].end());
	reverse(v[0].begin(),v[0].end());
	reverse(v[1].begin(),v[1].end());
	reverse(v[2].begin(),v[2].end());
	reverse(v[3].begin(),v[3].end());
	rep(i,v[0].size()+1){
		rep(j,v[1].size()+1){
			rep(k,v[2].size()+1){
				rep(l,v[3].size()+1){
					if((i*mi)+(j*(mi+1))+(k*(mi+2))+(l*(mi+3))>w)continue;
					int ans=0;
					rep(m,i)ans+=v[0][m];
					rep(m,j)ans+=v[1][m];
					rep(m,k)ans+=v[2][m];
					rep(m,l)ans+=v[3][m];
					cnt=max(ans,cnt);
				}
			}	
		}
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 256
N=int(input())
#sum[k:1 to N]floor(N/K)
ans=0
j=1
while(j*(j*1)<=N):
    b=1+(N//j)
    a=1+(N//(j+1))
    tmp=((N//a)*((N//a)+1))//2
    tmpa=(a*(a-1))//2
    tmpb=(b*(b-1))//2
    ans+=(tmpb-tmpa)*tmp
    j+=1
for i in range(1,a):
    ans+=i*((N//i)*((N//i)+1))//2
print(ans)


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            long N = long.Parse(input[0]);
            long D = long.Parse(input[1]);
            long num = N / (D * 2 + 1);
            if (N % (D * 2 + 1) > 0) num++;
            Console.WriteLine(num.ToString());
        }
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
int mp[505][505],dp[505][505];
int main()
{
	int n,m,q,l,r;
	scanf("%d%d%d",&n,&m,&q);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&l,&r);
		mp[l][r]++;
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			dp[i][j]=dp[i][j-1]+mp[i][j];
		}
	}
	for(int i=1;i<=q;i++)
	{
		int ans=0;
		scanf("%d%d",&l,&r);
		for(int i=l;i<=r;i++)
		{
			ans+=dp[i][r]-dp[i][l-1];
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 2944
S = [int(s) for s in list(input())]
K = int(input())

first_char = S[0]
if len(S) == 1:
    print(first_char)
elif first_char == 1:
    cnt = 0
    prev = 1
    i = 0
    while i < len(S) and prev == S[i]:
        prev = S[i]
        i += 1
    if K <= i:
        print(1)
    else:
        print(S[i])
else:
    print(first_char)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int k,n;
    scanf("%d %d",&k,&n);
    int a[n];
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    int mldis = a[0]+k-a[n-1];
    int start = 0;
    for(int i=1;i<n;i++){
        if(mldis < a[i]-a[i-1]){
            mldis = a[i]-a[i-1];
            start = i;
        }
    }
    printf("%d\n",k-mldis);
    return(0);
}

Measured memory_bytes: 1024
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    intmax_t N, K;
    intmax_t d = 1;

    scanf("%jd%jd", &N, &K);

    for (size_t i = 1; i < 64; i++) {
        d *= K;
        if (d > N) {
            printf("%jd\n", i);
            break;
        }
    }

    return 0;
}


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

using namespace std;

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

typedef pair<int, int> ii;

const int N = 3e3 + 5;

int n, mod, f[N][N], c[N][N], pw[N * N], pw2[N], dp[N], ans;

void calc() {
    //f[i][j]:the number of ways to "put" j guys in i bowl
    for(int i = 0; i <= N - 5; i++)
        f[i][0] = 1;
    for(int i = 1; i <= N - 5; i++) {
        for(int j = 1; j <= i; j++)
            f[i][j] = ((1ll * (j + 1) * f[i - 1][j]) % mod + f[i - 1][j - 1]) % mod;
    }
    c[0][0] = 1;
    for(int i = 1; i <= N - 5; i++) {
        c[i][0] = 1;
        for(int j = 1; j <= i; j++)
            c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;
    }
    pw[0] = 1;
    for(int i = 1; i <= (N - 5) * (N - 5); i++)
        pw[i] = (1ll * pw[i - 1] * 2) % mod;
    pw2[0] = 2;
    for(int i = 1; i <= N - 5; i++)
        pw2[i] = (1ll * pw2[i - 1] * pw2[i - 1]) % mod;
    ans = pw2[n] - 1;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= i; j++) {
            //cout << f[i][j] << " " << i << " " << j << "\n";
            int val = (1ll * f[i][j] * pw[(n - i) * j]) % mod;
            if(j == 0)
                dp[i] += (1ll * val * (pw2[n - i] - 1)) % mod;
            else
                dp[i] += (1ll * val * pw2[n - i]) % mod;
            dp[i] %= mod;
        }
        if(i % 2 == 0)
            ans = (ans + (1ll * dp[i] * c[n][i]) % mod) % mod;
        else
            ans = (ans - (1ll * dp[i] * c[n][i]) % mod) % mod;
        ans = (ans + mod) % mod;
    }
    cout << ans;
    exit(0);
}

int main() {
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> n >> mod;
    calc();
}


Measured memory_bytes: 106112
#include <iostream> 
#include <sstream> // istringstream
#include <string> // 文字列
#include <algorithm> // アルゴリズム
#include <cmath> // 
#include <vector> // vector
#include <set> // set
#include <map> // map

using namespace std;

#define rep(i,n) for(int i = 0; i < n; i++) // for文の省略

int main()
{   
    // input sample
    int N; 
    cin >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; ++i) cin >> A.at(i);
    sort(A.begin(), A.end(), greater<long long>());

    long long res = 0;
    for (int i = 0; i < (N-1)/2; ++i) {
        res += A[i]; // 高い方を追加する際
        res += A[i+1]; // 低い方を間に差し込む
    }

    // 偶数の場合最後に余る
    if (N % 2 == 0) {
        res += A[N/2-1];
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4840
#include <iostream>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <iomanip>
#include <math.h>
#include <algorithm>
#define M_PI 3.14159265358979323846264338327950288
#define oo 1000000007
#define maxN 3007
using namespace std;


int main() {
    string s;
    cin >> s;

    if (s[(int)s.size()-1] == 's') cout << s+"es" << endl;
    else cout << s+"s" << endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a;
  for(int i=0;i<N;i++){
    int tmp;
    cin >> tmp;
    a.push_back(tmp);
  }
  sort(a.begin(), a.end());
  cout << a.at(N-1) - a.at(0) << endl;
  return 0;
}

Measured memory_bytes: 256
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>


using namespace std;

    int main() {
        int x,y;
        cin>>x>>y;

        int z,o;
        if(x==1){
            z=300000;
        }
        else if(x==2){
            z=200000;
        }
        else if(x==3){
            z=100000;
        }
        else{
            z=0;
        }

        if(y==1){
            o=300000;
        }
        else if (y==2){
            o=200000;
        }
        else if(y==3){
            o=100000;
        }
        else{
            o=0;
        }

        if(x==1&&y==1){
            cout<<o+z+400000<<endl;
        }
        else{
            cout<<o+z<<endl;
        }





    }


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

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

int main()
{
	int N;
	std::cin >> N;

	int ans = 1;
	int cnt_max = 0;
	for(int i = 1; i <= N; i++)
	{
		int num = i;
		int cnt = 0;
//		printf("%d:", num / 2);
		while(((num % 2) == 0) && (num != 0) && (num != 1))
		{
			num /= 2;
			cnt++;
//			printf("+");
		}
//		printf("[%d}%d\n", i, cnt);
		if(cnt > cnt_max)
		{
			ans = i;
			cnt_max = cnt;
		}
		cnt = 0;
	}

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

    return 0;
}


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

int main() {
  string s;
  cin >> s;
  bool easy = true;
  for (int i = 0; i < s.length(); i++) {
    if (i % 2 == 0) {
      if (!(s[i] == 'R' || s[i] == 'U' || s[i] == 'D'))
        easy = false;
    } else {
      if (!(s[i] == 'L' || s[i] == 'U' || s[i] == 'D'))
        easy = false;
    }
  }
  if (easy)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}

char s[100001];
int a[100000];
int main(void){
	scanf("%s", s);
	int n=strlen(s), i;

	int f, g;
	f=0;
	for(i=0; i<n; i++){
		if(s[i]=='L'){
			if(f==0){
				f=1;
				g=i;
				a[g]=1;
			}else{
				a[g]++;
			}
		}else{
			f=0;
		}
	}
	f=0;
	for(i=n-1; i>=0; i--){
		if(s[i]=='R'){
			if(f==0){
				f=1;
				g=i;
				a[g]=1;
			}else{
				a[g]++;
			}
		}else{
			f=0;
		}
	}
	for(i=0; i<n; i++){
		if(a[i]!=0){
			int R=a[i];
			int L=a[i+1];
			a[i]=(R+1)/2+L/2;
			a[i+1]=(L+1)/2+R/2;
			i++;
		}
	}
	for(i=0; i<n; i++){
		printf("%d ", a[i]);
	}
	putchar(10);
}


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



int main() {
  bool flag;
  string ans = "Yes";

  int h, w;
  cin >> h >> w;

  string board[50];

  for (int i = 0; i < h; i++) cin >> board[i];

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

  for (int i = 0; i < h; i++) {
    flag = false;
    for (int j = 0; j < w; j++) {
      if (board[i][j] == '.') {
        flag = true;
        continue;
      }

      int num = 0;
      bool hoge = false;
      for (int d = 0; d < 4; d++) {
        const int ni = i + dy[d];
        const int nj = j + dx[d];

        if (ni < 0 or h <= ni) continue;
        if (nj < 0 or w <= nj) continue;
        if (board[ni][nj] == '#') num++;

      }

      if (num == 0) {
        flag = false;
        break;
      } else {
        flag = true;
      }

    }
    if (!flag) {
      ans = "No";
      break;
    }
  }

  cout << ans << endl;


}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
int main() {
  int a,b,c,x,r=0;
  std::cin >> a>> b >> c >> x;
  for(int i=0; i < a+1; ++i){
    for(int j=0; j < b+1; ++j){
      for(int k=0; k < c+1; ++k) {
        (i*500+j*100+k*50-x?0:++r);
      }
    }
  }
  std::cout << r;
}
    

Measured memory_bytes: 256
n,m=map(int,input().split())
a=[input()for _ in range(n)]
b=[input()for _ in range(m)]
x=n-~-m
C=0
for i in range(x):
    for j in range(x):
        c=0
        for k in range(m):
            if a[i+k][j:j+m]==b[k]:
                c+=1
        if c==m:
            C+=1
print('YNeos'[C<1::2])

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

int main(){
    int n,m;
    cin >> n >> m;
    string a[n];
    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 u=0;u<m;u++){
                    if(a[i+k][j+u]!=b[k][u]){
                        flag = false;
                        break;
                    }
                }
            }
            if(flag){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

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

#pragma region  // {{{

#define all(x) std::begin(x), std::end(x)
#define rall(x) std::rbegin(x), std::rend(x)
#define rep(i, begin, end) for (int64_t i{begin}, i##_end{end}; i < i##_end; ++i)
#define repc(i, begin, last) for (int64_t i{begin}, i##_last{last}; i <= i##_last; ++i)
#define repr(i, begin, last) for (int64_t i{begin}, i##_last{last}; i >= i##_last; --i)
#define let const auto
using i64 = std::int64_t;
using u64 = std::uint64_t;

constexpr int32_t INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;

void ioSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(11);
    std::cerr << std::fixed << std::setprecision(11);
    std::clog << std::fixed << std::setprecision(11);
}

template <class T>
std::istream& operator,(std::istream& is, T& rhs) {
    return is >> rhs;
}

#define var(type, ...) \
    type __VA_ARGS__;  \
    std::cin >> __VA_ARGS__

inline void println() {
    std::cout << '\n';
}
template <class Head, class... Tail>
inline void println(Head&& head, Tail&&... tail) {
    std::cout << head << " " + (!sizeof...(tail));
    println(std::forward<Tail>(tail)...);
}

template <class T, class U>
inline bool chmin(T& a, const U& b) {
    return b < a && (a = b, true);
}

template <class T, class U>
inline bool chmax(T& a, const U& b) {
    return b > a && (a = b, true);
}

#pragma endregion  // }}}

constexpr int MOD = int(1e9) + 7;
// constexpr int MOD = 998244353;

i64 S;

i64 dp(int i, int sum) {
    if (sum == S) return 1;
    if (sum > S) return 0;

    i64 ret = 0;
    repc(a, 3, S - sum) { ret += dp(i + 1, int(sum + a)); }

    return ret;
}

signed main() {
    ioSetup();

    cin >> S;
    if (S == 1) {
        println(0);
        return 0;
    }

    vector<vector<i64>> dp(S, vector<i64>(S + 5, 0));
    rep(i, 0, S) { dp[i][S] = 1; }

    repr(i, S / 3, 0) {
        repr(j, S - 1, 0) { (dp[i + 1][j] += dp[i + 1][j + 1]) %= MOD; }
        rep(j, 0, S) { dp[i][j] = dp[i + 1][j + 3]; }
    }
    println(dp[0][0]);

    return 0;
}


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

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


#define REP(i, n) for(int i = 0; i < n; i++) //普通のループ
#define REPTO(i, n) for(int i = 0; i <= n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--) //逆ループ
#define FOR(i, m, n) for(int i = m; i < n; i++) //最初の数値を指定

int main(){
    int S,W;
    cin >> S >> W;
    if(W>=S) cout << "unsafe" << endl;
    else cout << "safe" << endl;
    return 0;
}

Measured memory_bytes: 3600
const input=require("fs").readFileSync("/dev/stdin","utf8"),lines=input.trim().split("\n");let array,n,m,index=0,answers=[];for(;line=lines.shift();)if(0===index){const e=line.split(" ").map(Number);n=e[0],m=e[1],index++}else{array=line.split(" ").map(Number);let e=0;for(let i=0;i<n;i++)for(let r=0;r<n;r++){if(i===r)continue;const n=array[i]+array[r];n>e&&n<=m&&(e=n)}index=0,answers.push(e)}answers.forEach(e=>console.log(e||"NONE"));


Measured memory_bytes: 18228
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<limits.h>
int n;
long count=0;

void merge(int *A,int left,int mid,int right){
  int *L,*R;
  L=malloc(sizeof(int)*(mid-left+1));
  R=malloc(sizeof(int)*(right-mid+1));
  
  int i;
  for(i=0;i<mid-left;i++) L[i]=A[left+i];
  L[mid-left]=INT_MAX;
  for(i=0;i<right-mid;i++) R[i]=A[mid+i];
  R[right-mid]=INT_MAX;//どの不等式にもかつ数字を、配列の最後尾に入れる
  
  int l,r;
  l=0;
  r=0;
  for(i=0;i<right-left;i++){
    if(L[l] <= R[r]){
      A[left+i]=L[l];
      l+=1;
     }
    else{
      count+=mid-left-l;
      A[left+i]=R[r];
      r+=1;
    }
  }
  free(L);
  free(R);
}




void mergesort(int *A,int left,int right){
  if(left +1 < right){//整列させる要素が２つ以上ある場合は、分割する
    int mid;
    mid=(left+right)/2;
    mergesort(A,left,mid);
    mergesort(A,mid,right);
    merge(A,left,mid,right);
  }
}
//A[left]からA[right-1]まで整列させる



int main(){
  int *A;
  scanf("%d",&n);
  A=malloc(n*sizeof(int));
  int i;
  for(i=0;i<n;i++) scanf("%d",&A[i]);

  mergesort(A,0,n);
  
  printf("%ld\n",count);
  return 0;
}
  


//どの不等式にも勝つ数字を入れたいときは、INT_MAX。limits.hをインクルードする必要あり




Measured memory_bytes: 2944
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
    int h, w, ch, dh, cw, dw;
    cin >> h >> w;
    cin >> ch >> cw;
    cin >> dh >> dw;
    vector<string> m(h, "");
    for (int i = 0; i < h; i++) {
        cin >> m[i];
    }

    vvi done(h, vi(w, 0));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (m[i][j] == '#') {
                done[i][j] = -2;
            } else{
                done[i][j] = -1;
            }
        }
    }
    done[ch-1][cw-1] = 0;
    deque<vi> q, r;
    q.emplace_back(vi{ch-1, cw-1});
    q.emplace_back(vi{-1,-1});
    int ans = 0;
    vvi l_nxt = vvi{vi{-1,0}, vi{1,0}, vi{0,-1}, vi{0,1}};
    vi n, s;
    while (true) {
        n = q.front();
        // cout << ans << " pos=" << n[0] << " " << n[1] << endl;
        r.emplace_front(n);
        q.pop_front();
        if (n[0] == dh-1 && n[1] == dw-1) {
            cout << ans << endl;
            return 0;
        } else if (n[0] == -1 && n[1] == -1) {
            r.pop_front();
            ans++;
            while (r.size() > 0) {
                s = r.front();
                r.pop_front();
                for (int i = -2; i < 3; i++) {
                    for (int j = -2; j < 3; j++) {
                        if (s[0]+i >= 0 && s[0]+i < h && s[1]+j >= 0 && s[1]+j < w) {
                            if (done[s[0]+i][s[1]+j] == -1) {
                                done[s[0]+i][s[1]+j] = ans;
                                q.emplace_front(vi{s[0]+i, s[1]+j});
                            }
                        }
                    }
                }
            }
            q.emplace_back(vi{-1,-1});
            if (q.size() == 1) {
                cout << -1 << endl;
                return 0;
            }
        }
        
        for (vi nxt: l_nxt) {
            if (n[0]+nxt[0] >= 0 && n[0]+nxt[0] < h && n[1]+nxt[1] >= 0 && n[1]+nxt[1] < w) {
                if (done[n[0]+nxt[0]][n[1]+nxt[1]] == -1) {
                    done[n[0]+nxt[0]][n[1]+nxt[1]] = ans;
                    q.emplace_front(vi{n[0]+nxt[0], n[1]+nxt[1]});
                }
            }
        }
    }
    // cout << ans << endl;
}


Measured memory_bytes: 10336
#include<bits/stdc++.h>
using namespace std;
int n,m;
std::vector<vector<bool>> edge;
std::vector<bool> used;
int dfs(int now,int depth){
	if(used[now]) return 0;
	if(depth==n) return 1;
	int ans=0;
	used[now]=true;
	for (int i = 0; i < n; ++i)
	{
		if(edge[now][i]){
			ans+=dfs(i,depth+1);
		}
	}
	used[now]=false;
	return ans;
}

int main()
{
	cin>>n>>m;
	used=std::vector<bool>(n,false);
	edge.resize(n);
	for (int i = 0; i < n; ++i)
	{
		edge[i].resize(n);
	}
	for (int i = 0; i < m; ++i)
	{
		int a,b;
		cin>>a>>b;
		a--;b--;
		edge[a][b]=edge[b][a]=true;
	}
	cout<<dfs(0,1);
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
bool leap(int Y){
  if(Y%4==0)
    return( (Y%100==0)?( (Y%400==0)?true:false ):true ); 
  else return false;
}
 
int main(){
  int Y,aY;
  int cont=0;
  int n=0;
  while(cin>>Y>>aY){
    if(Y==0 && aY==0) break;
    if(n) cout<<endl;
    for(int i=Y;i<=aY;i++) if(leap(i)){
        cout<<i<<endl;
        cont++;
      }
    if(cont==0) cout<<"NA"<<endl;
    n++;
    cont=0;
  }
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main(void) {
    long long int n, ans=0, keta;
    scanf("%lld", &n);
    if (n%2==1) {
        ans=0;
    } else {
        long long int five=2;
        while (1) {
            five*=5;
            if (n < five) {
                break;
            }
            ans += (n - n%five)/five;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  
  char x;
  bool ylw = false;
  for(int i=0; i<n; i++) {
    cin >> x;
    if(x=='Y') ylw = true;
  }
  if(ylw) cout << "Four" << endl;
  else cout << "Three" << endl;
  return 0;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n=sc.nextInt();
			if(n==0) break;
			int[] data = new int[n];
			for(int i=0;i<n;++i){
				data[i]=sc.nextInt();
			}
			Arrays.sort(data);
			int min=1000000;
			for(int i=n-1;i>0;--i){
				int num=data[i]-data[i-1];
				if(min>num) min=num;
			}
			System.out.println(min);
		}
	}
}


Measured memory_bytes: 48056
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n,k;
  cin>>n>>k;
  int a[n];
  rep(i,n) cin>>a[i];
  repi(i,k,n){
    if(a[i-k]<a[i]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  

  return 0;
}


Measured memory_bytes: 5196
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
int main() {
    int x_1,x_2,y_1,y_2;
    cin >> x_1 >> y_1 >> x_2 >> y_2;
    int dx,dy;
    dx = x_2 - x_1;
    dy = y_2 - y_1;
    cout << x_2  - dy << " " << y_2 + dx  << " " << x_1 - dy << " " << y_1 + dx << endl; 
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
typedef pair<int, int> P;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  int H, W, K;
  cin >> H >> W >> K;

  vector<bitset<6>> mass(6);

  rep(i,6){
    mass.at(i).reset();
  }

  string tmp;
  rep(i, H){
    cin >> tmp;
    rep(j, W){
      if(tmp[j] == '#'){
        mass.at(i).set(j);
      }
    }
  }

  int ans = 0;
  rep(i, (1<<H)){
    bitset<6> h(i);

    rep(j, (1<<W)){
      bitset<6> w(j);
      int count = 0;

      rep(k,H){

        rep(l, W){
          bool cond1 = ((!h.test(k)&&(!w.test(l))) && (mass.at(k).test(l)));
          if(cond1){
            count++;
          }
        }

      }
      if(count == K) ans++;

    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 3620
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] sl = new int[n];
        int total = 0;
        for(int i = 0 ; i < n; i++){
            sl[i] = sc.nextInt();
            total += sl[i];
        }
        if(total % 10 != 0){
            System.out.println(total);
        }else{
            Arrays.sort(sl);
            int ans = 0;
            for(int s : sl){
                if(s % 10 != 0){
                    ans = total - s;
                    break;
                }
            }
            System.out.println(ans);
        }
    }
}


Measured memory_bytes: 21972
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
import queue
import copy

# 最大公約数
def gcd(m,n):
  x = max(m,n)
  y = min(m,n)
  if x%y == 0:
    return y
  else:
    while x%y != 0:
      z = x%y
      x = y
      y = z
    else:
      return z

# 幅優先探索(BFS)でスタート座標(x, y)からの最大距離返す
def bfs(SS, x, y, H, W):#入力(座標系(迷路), x, y, xの端, yの端)
  x_next = [0, 0, -1, 1]
  y_next = [1, -1, 0, 0]
  tempx = x
  tempy = y
  mlength = 0
  q = deque()
  xytuple = (x, y, 0)
  q.append(xytuple)


  while q:
    xytuple = q.popleft()
    SS[xytuple[0]][xytuple[1]] = "x" #探索した場所は探索できないようにする
    for i in range(4): #このforで上下左右を調べてる
      tempx = xytuple[0] + x_next[i]
      tempy = xytuple[1] + y_next[i]
      #print(tempx, tempy, xytuple[2])
      #print(S)
      if(0 <= tempx and tempx < H and 0 <= tempy and tempy < W and SS[tempx][tempy] == "."):
        temptuple = (tempx, tempy, xytuple[2]+1)
        SS[temptuple[0]][temptuple[1]] = "x" #探索した場所は探索できないようにする
        mlength = max(mlength, xytuple[2] +1)
        q.append(temptuple)
      #print(q)
  return mlength


#X = str(input()).split()
#a = [int(x) for x in input().split()]

NM = str(input()).split()
N = int(NM[0])
M = int(NM[1])
A = []
ans = 0

for i in range(N):
  AB = str(input()).split()
  A.append([int(AB[0]),int(AB[1])])


A.sort()

#print(A[1])
count = 0

while True:
  if (M==0):
    break
  if not(A[count][1] == 0):
    ans += A[count][0]
    A[count][1] -= 1
    M -= 1
  else:
    count+=1



print(ans)


Measured memory_bytes: 59220
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n;
	cin >> n;
	vector<int> c(n - 1), s(n - 1), f(n - 1);
	for (int i = 0; i < n - 1; i++) {
		cin >> c[i] >> s[i] >> f[i];
	}

	for (int i = 0; i < n; i++) {
		int timer = 0;
		for (int j = i; j < n - 1; j++) {
			if (timer < s[j]) {
				timer = s[j];
			} else if (timer % f[j] == 0) {
				timer = timer;
			} else {
				timer = timer + f[j] - (timer % f[j]);
			}
			timer += c[j];
		}
		cout << timer << endl;
	}
	return 0;
}


Measured memory_bytes: 256