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

const int INF = 1e+18;

template<class T>
struct Edge{
	int from,to;
	T cost;
	Edge(int to,T cost) : to(to),cost(cost){}
	Edge(int from,int to,T cost) : from(from),to(to),cost(cost){}
	operator int() const noexcept { return to; }
};

template<class T>
using WeightedGraph = vector<vector<Edge<T>>>;
using Graph = vector<vector<int>>;
template<class T>
using Matrix = vector<vector<T>>;

template<class T>
vector<T> dijkstra(const WeightedGraph<T> &G,int source = 0){
	using P = pair<T,int>;
	vector<T> dist(G.size(),INF);
	priority_queue<P,vector<P>,greater<P>> que;
	dist[source] = 0;
	que.emplace(dist[source],source);
	while(!que.empty()){
		P p = que.top();que.pop();
		int v = p.second;
		if(dist[v] < p.first) continue;
		for(const auto &e : G[v]){
			if(dist[e.to] > dist[v] + e.cost){
				dist[e.to] = dist[v] + e.cost;
				que.emplace(dist[e.to],e.to);
			}
		}
	}
	return dist;
}

template<class T>
struct TwoEdgeConnectedComponents{
	T G;
	Graph nG;
	vector<int> cmp,depth,s;
	vector<vector<int>> tecc;
	stack<int> vs;
	vector<pair<int,int>> bridge;

	int operator[](int i) const{ return cmp[i]; }

	TwoEdgeConnectedComponents(const T &G) : G(G),cmp(G.size()),depth(G.size(),-1),s(G.size()){}

	void dfs(int v,int par,int d){
		depth[v] = d;
		vs.push(v);
		for(const auto &e : G[v]){
			int to = (int)e;
			if(depth[to] == -1){
				dfs(to,v,d + 1);
				s[v] += s[to];
			}else if(to != par && depth[v] > depth[to]) s[to]--,s[v]++;
		}
		if(!s[v]){
			if(par != -1) bridge.push_back(minmax(v,par));
			tecc.emplace_back();
			while(1){
				int u = vs.top(); vs.pop();
				tecc.back().push_back(u);
				cmp[u] = tecc.size() - 1;
				if(u == v) break;
			}
		}
	}

	void build(){
		for(int i = 0;i < G.size();i++) if(depth[i] == -1) dfs(i,-1,0);
		nG.resize(tecc.size());
		for(const auto &e : bridge){
			int x = cmp[e.first],y = cmp[e.second];
			nG[x].push_back(y);
			nG[y].push_back(x);
		}
	}
};

signed main(){
	int n,m,a[100010],b[100010],c[100010];
	cin >> n >> m;
	WeightedGraph<int> G(n),rG(n);
	for(int i = 0;i < m;i++){
		cin >> a[i] >> b[i] >> c[i];
		a[i]--; b[i]--;
		G[a[i]].emplace_back(b[i],c[i]);
		rG[b[i]].emplace_back(a[i],c[i]);
	}
	auto dist0 = dijkstra(G,0),dist1 = dijkstra(rG,1);
	Graph saitan(n);
	for(int i = 0;i < m;i++){
		if(dist0[a[i]] + c[i] + dist1[b[i]] == dist0[1]){
			saitan[a[i]].push_back(b[i]);
			saitan[b[i]].push_back(a[i]);
		}
	}
	TwoEdgeConnectedComponents<Graph> tecc(saitan);
	tecc.build();
	for(int i = 0;i < m;i++){
		if(dist0[a[i]] + c[i] + dist1[b[i]] == dist0[1]){
			if(tecc[a[i]] != tecc[b[i]]) cout << "SAD" << endl;
			else cout << "SOSO" << endl;
		}else{
			if(dist0[b[i]] + c[i] + dist1[a[i]] < dist0[1]) cout << "HAPPY" << endl;
			else cout << "SOSO" << endl;
		}
	}
}


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

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

int main() {
    int N, L;
    cin >> N >> L;
    vector<int> a(N + 2);
    for(int i = 1; i <= N; ++i) {
        cin >> a[i];
    }

    ll ans = 0;
    priority_queue<pii> que;
    for(int i = 1; i <= N; ++i) {
        if(a[i - 1] < a[i] && a[i] > a[i + 1]) {
            que.emplace(a[i], i);
        }
    }
    while(!que.empty()) {
        auto p = que.top(); que.pop();
        ans += L - (p.first + ans);
        a[p.second] = 0;
        for(int d = -1; d <= 1; d += 2) {
            if(a[p.second + d] != 0 && a[p.second + 2 * d] < a[p.second + d]) {
                que.emplace(a[p.second + d] - ans, p.second + d);
            }
        }
    }
    cout << ans << endl;
}


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

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
pair<LL, int> A[200111];

void MAIN() {
    scanf("%d", &N);
    REP (i, N) scanf("%lld", &A[i].first);
    sort(A, A+N);

    int ans = 0;
    for (int i=N; i--;) {
	if (A[i].second) continue;
	LL t = 2LL<<__lg(A[i].first);
	int k = upper_bound(A, A+i, make_pair(t - A[i].first, 0)) - A;
	if (0 < k && k <= i && A[i].first + A[k-1].first == t) {
	    ans++;
	    A[k-1].second = 1;
	}
    }
    printf("%d\n", ans);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 3328
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e10;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

int main(){
    ll N; cin >> N;
    vl v(N, 0), c(N, 0); REP(i, N) cin >> v[i]; REP(i, N) cin >> c[i];
    ll ans = 0;
    REP(i, N){
        if(v[i] > c[i]) ans += v[i] - c[i];
    }
    cout << ans << endl;
    return 0;
}


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

const int N = 5e5 + 100;

int n, a[N];

bool chk(int x) {
  for (int i = 1; i < n; i++) {
    if ((a[n + i - 1] <= x) == (a[n + i] <= x)) {
      return a[n + i] > x;
    }
    if ((a[n - i + 1] <= x) == (a[n - i] <= x)) {
      return a[n - i + 1] > x;
    }
  }
  return a[1] > x;
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= 2 * n - 1; i++) {
    scanf("%d", &a[i]);
  }
  int l = 1, r = 2 * n - 1;
  int ans = 0;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (chk(mid)) {
      l = mid + 1;
    } else {
      r = mid - 1;
      ans = mid;
    }
  }
  printf("%d\n", ans);
  return 0;
}

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

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
const int MAXN = 1e6+ 2, mod = 1e9 + 7;

int spf[MAXN]; 
  
// Calculating SPF (Smallest Prime Factor) for every 
// number till MAXN. 
// Time Complexity : O(nloglogn) 
void sieve() 
{ 
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++) 
  
        // marking smallest prime factor for every 
        // number to be itself. 
        spf[i] = i; 
  
    // separately marking spf for every even 
    // number as 2 
    for (int i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
  
    for (int i=3; i*i<MAXN; i++) 
    { 
        // checking if i is prime 
        if (spf[i] == i) 
        { 
            // marking SPF for all numbers divisible by i 
            for (int j=i*i; j<MAXN; j+=i) 
  
                // marking spf[j] if it is not  
                // previously marked 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 
  
// A O(log n) function returning primefactorization 
// by dividing by smallest prime factor at every step 
vector<int> getFactorization(int x) 
{ 
    vector<int> ret; 
    while (x != 1) 
    { 
        ret.push_back(spf[x]); 
        x = x / spf[x]; 
    } 
    return ret; 
} 


void solve() {
    sieve();
    int n;
    cin >> n;
    vector<bool> chk(MAXN);
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int g = a[0];
    for (int i = 1; i < n; i++) {
        g = __gcd(g, a[i]);
    }
    bool ok1 = 1, ok2 = 0;
    if (g == 1) {
        ok2 = 1;
    }
    for (int i = n - 1; i >= 0; i--) {
        vector<int> p = getFactorization(a[i]);
        for (int j : p) {
            if (chk[j]) {
                ok1 = 0;
                break;
            }
        }
        if (!ok1) {
            break;
        }
        for (int j : p)
        chk[j] = 1;
    }
    if (ok1) {
        cout << "pairwise coprime\n";
    } else if (ok2) {
        cout << "setwise coprime\n";
    } else {
        cout << "not coprime\n";
    }
}

int main() {
	// reopen("input.txt", "r", stdin); 
 //    freopen("output.txt", "w", stdout); 
	int tt = 1;
	// cin >> tt;
	for (int tc = 1; tc <= tt; tc++) {
		// cout << "Case #:" << tc << " ";
		solve();
	}
}

Measured memory_bytes: 11104
#include <stdio.h>
int main(void){
    int i, ii,  n, x, y;
    int a[9] = {400, 600, 800, 1000, 1200, 1400, 1600, 1800, 100000};
    scanf("%d", &n);
    i = 0;
    while (a[i] <= n)
        i++;
    printf("%d", 9 - i);
}


Measured memory_bytes: 1732
#include <iostream>
#include <vector>

using namespace std;

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

    long long sum = 0;
    for (size_t i = 0; i < n; ++i) {
        size_t x;
        cin >> x;
        sum += min(x, k - x) * 2;
    }
    cout << sum << endl;
    return EXIT_SUCCESS;
}

Measured memory_bytes: 256
N = int(input())
A = [int(input()) for _ in range(N)]

L = [0] * (N+1)
R = [0] * (N+2)
A.append(0)

for i in range(1, N+1):
    if i == 1:
        L[1] = 0
        R[N+1] = 0
    L[i] = max(L[i-1], A[i-2])
    R[N-i+1] = max(R[N-i+2], A[N-i+1])

for i in range(1, N+1):
    print(max(L[i], R[i]))

Measured memory_bytes: 15636
#include <bits/stdc++.h>
#include <time.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define ld          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define pi          3.14159265358979323

ll n, a, b, c, d;
string s;

void solve()
{
     string s;
     cin>>s;
     n=s.size();
     c=0,a=0;
     ll i=0;
     while(i<n-1)
     {
            if(s[i]=='A') { c++; i++; }
            else if(s[i]=='B' && s[i+1]=='C') {a+=c; i+=2;}
            else
            {
                   c=0; i++;
            }
     }
     cout<<a<<endl;
}

int main()
{
       speed_up;
       //pre();
       ll T=1;
       //cin>>T;
       while(T--) solve();
	return 0;
}


Measured memory_bytes: 720
n = gets.chomp.to_i

count = Array.new(n+1, 10000000000000)

count[0] = 0
1.upto(n) do |i|
  u = count[i-1] + 1
  count[i] = u if u < count[i]
  1.upto(6) do |t|
    a = 6 ** t
    if a <= i
      b = count[i-a] + 1
      count[i] = b if b < count[i]
    end
    c = 9 ** t
    if c <= i
      d = count[i-c] + 1
      count[i] = d if d < count[i]
    end
  end
end
p count[n]


Measured memory_bytes: 2556
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    int k=0;
    for (int i=0;i<s.length();i++)
    {
        if (s[i]!=t[i]) k++;
    }
    cout<<k<<endl;
}

Measured memory_bytes: 3912
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

//#include <tuple>

//#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int main() {
  int A, B, T;
  cin >> A >> B >> T;
  cout << B*(T/A) << endl;
  
}


Measured memory_bytes: 256
// AtCoder Regular Contest 075
// F - Mirrored

#include <cstdio>
#include <cmath>
using namespace std;
typedef long long int ll;


const int MAX_K = 9;

ll D;
ll pow_dec[2 * MAX_K + 1];
ll ans;

ll count_n(int l, int r, ll d) {
    if (l - r < 0) {
        return (d == 0) ? 1 : 0;
    }

    ll cnt = 0;
    int k;
    for (int i = (d / pow_dec[r] % 10 + 10) % 10; i > -10; i -= 10) {
        if (r == 0 && i > 0) {
            continue;
        }
        k = 10 - abs(i);
        if (r == 0 && -i >= 0) {
            k--;
        }
        cnt += k * count_n(l - 1, r + 1, d + i * pow_dec[l] - i * pow_dec[r]);
    }

    return cnt;
}

int main() {

    pow_dec[0] = 1;
    for (int i = 1; i <= 2 * MAX_K; i++) {
        pow_dec[i] = pow_dec[i - 1] * 10;
    }

    scanf("%lld", &D);

    ans = 0;
    for (int i = 0; i <= 2 * MAX_K; i++) {
        ans += count_n(i, 0, D);
    }

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

    return 0;

}


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

#define lli long long int 

bool compare ( pair<lli,lli> p1, pair<lli,lli> p2)
{
    if (p1.second == p2.second) return p1.first < p2.first;
    return p1.second > p2.second;
}

int main () {
  int N;
  cin >> N;
  vector<pair<lli,lli> > v(N);

  for (int i = 0; i < N; ++i)
  {
    cin >> v[i].first >> v[i].second;
  }

  sort(v.begin(), v.end(), compare);

  lli last = v[0].second;

  for (int i = 0; i < N; ++i)
  {
    last = min (last, v[i].second);
    last -=  v[i].first;
  }
  
  if (last >= 0 ) cout << "Yes\n";
  else cout << "No\n";
   
  return 0;
}


Measured memory_bytes: 3328
#include <stdio.h>
#include <math.h>

char c[1001][1001];
int dp[1001][1000];

int main(void) {
    int n, i, j, k, h, w, size, maximum;

    
    while (scanf("%d", &n) == 1 && n) {
        for (i = 1; i <= n; i++) {
            scanf("%s", c[i]);
        }
        for (i = 0; i <= n; i++) {
            dp[0][i] = 0;
        }
        for (i = 1; i <= n; i++) {
            for (j = 0; j < n; j++) {
                if (c[i][j] == '.') {
                    dp[i][j] = dp[i-1][j] + 1;
                }
                else {
                    dp[i][j] = 0;
                }
            }
        }
        for (i = n, maximum = 0; i > maximum; i--) {
            for (j = 0; j < n; j++) {
                h = dp[i][j];
                for (k = j, w = 1; k < n && w <= h; k++, w++) {
                    if (dp[i][k] < h) h = dp[i][k];
                    size = h < w ? h : w;
                    if (maximum < size) maximum = size;
                }
            }
        }
        printf("%d\n", maximum);
    }
    return 0;
}

Measured memory_bytes: 5492
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int x;
  cin>>x;
  ll sum=0;
  REP(i,1,1000000){
    sum+=i;
    if(sum>=x){
      cout<<i<<'\n';
      break;
    }
  }
  return(0);
}


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

const string YES = "Yes";
const string NO = "No";

void solve(std::string N){
    int s = 0;
    for (int i = 0; i < N.size(); i++) {
        s += N[i] - '0';
    }
    string ans = (s % 9) == 0 ? YES : NO;
    cout << ans << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string N;
    std::cin >> N;
    solve(N);
    return 0;
}


Measured memory_bytes: 3808
import qualified Data.List as List

main = do
    s <- getLine
    p <- getLine
    putStrLn $ if elemFromRing (List.elemIndices (head p) s) s p then "Yes" else "No"

elemFromRing :: [Int] -> String -> String -> Bool
elemFromRing [] _  _ = False
elemFromRing (x:xs) s p
    | pickFromRing [x..(x + length p - 1)] s == p = True
    | otherwise                                   = elemFromRing xs s p

pickFromRing :: [Int] -> String -> String
pickFromRing [] _ = []
pickFromRing (n:ns) xs = xs !! (n `mod` length xs) : pickFromRing ns xs

Measured memory_bytes: 3584
#include <stdio.h>
int main(void)
{
int W, H, i, j;

while(1){
scanf("%d %d",&H,&W);

if(H == 0 && W == 0)
break;

for(i = 0; H > i; i++){
   for(j = 0; W > j; j++)
putchar('#');
printf("\n");
}
printf("\n");
}
return 0;
}

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

#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}

int N,Q,A,B;
const int all = 1<<18;
const int b = 1<<9;
const int bb =all/b;
const LL INF = 1e15;
LL L[bb];
LL R[bb];
LL lazy[bb];
LL cost[all];
inline void push(int id){
    if(lazy[id]==0)return;
    L[id]=R[id]=INF;
    REP(i,b){
        int p = id*b+i;
        chmin(cost[p]+=lazy[id],INF);
        chmin(L[id],cost[p]+i);
        chmin(R[id],cost[p]+b-i);
        
    }
    lazy[id]=0;
}
inline void ins(int x,LL val){
    push(x/b);
    chmin(cost[x],val);
    chmin(L[x/b],val+x%b);
    chmin(R[x/b],val+b-x%b);
}
inline LL getmin(int x){
    int id = 0;
    LL res=INF;
    while(id<bb&&(id+1)*b<=x){
        chmin(res,lazy[id]+R[id]+(x-(id+1)*b));
        //if(x==10)cout<<R[id]+lazy[id]<<endl;

        id++;
    }
    
    {
        push(id);
        REP(i,b){
            int p =id*b+i;
            chmin(res,cost[p]+abs(x-p));
        }
        id++;
    }
    while(id<bb){
        chmin(res,lazy[id]+L[id]+(id*b-x));
        id++;
    }
    
    return res;
}
int main(){
    scanf("%d %d %d %d",&N,&Q,&A,&B);
    A--;B--;
    REP(i,all)cost[i]=INF;
    REP(i,bb)L[i]=R[i]=INF,lazy[i]=0;
    int x;        
    {
        scanf("%d",&x);
        x--;
        ins(A,abs(B-x));
        ins(B,abs(A-x));
    }
    FOR(q,1,Q){
        int y;
        scanf("%d",&y);
        y--;
        int diff = abs(x-y);
        LL z = getmin(y);
        REP(i,bb)lazy[i]+=diff;
                
        ins(x,z);
        //cout<<y<<" "<<z<<endl;
        x=y;
        //REP(j,N)cout<<cost[j]+lazy[j/b]<<" ";cout<<endl;
    }
    LL res = INF;
    REP(i,N)chmin(res,cost[i]+lazy[i/b]);
    printf("%lld\n",res);
    return 0;
}


Measured memory_bytes: 2432
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict, Counter
from math import factorial

sys.setrecursionlimit(10**7)
H, W = map(int, input().split())
ahw = [list(map(int, input().split())) for _ in range(H)]

cnt = 0
query = []
for i in range(H):
    for j in range(W):
        if i==H-1 and j==W-1:
            continue

        if ahw[i][j]%2 and j!=W-1:
            query.append([i+1, j+1, i+1, j+2])
            ahw[i][j+1] += 1
            cnt += 1
        elif ahw[i][j]%2 and j==W-1:
            query.append([i+1, j+1, i+2, j+1])
            ahw[i+1][j] += 1
            cnt += 1

print(cnt)
for q in query:
    print(*q)


Measured memory_bytes: 72284
#include<bits/stdc++.h>
using namespace std;
int a[100001],b[100001];
int main()
{
	int n,sum1=0,sum2=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
	scanf("%d",&a[i]);
	if(a[i]%4==0)
	{
	b[i]=2;
	sum1++;
	}
	else if(a[i]%2==0)
	{
	b[i]=1;
	sum2++;
}
	else
	b[i]=0;
	}
   int sum3=n-sum1-sum2;
   if(sum2==0&&sum3<=sum1+1)
   printf("Yes\n");
   else if(sum1>=sum3)
   printf("Yes\n");
   else
   printf("No\n");	 
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
 
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int x,y,z,k;
ll a[1010],b[1010],c[1010];
ll ans;
bool is_used[1010][1010][1010];
int s[3];

int main() {
    cin >> x >> y >> z >> k;

    for (int i=0;i<x;i++) cin >> a[i];
    for (int i=0;i<y;i++) cin >> b[i];
    for (int i=0;i<z;i++) cin >> c[i];
    
    sort(a,a+x,greater<ll>());
    sort(b,b+y,greater<ll>());
    sort(c,c+z,greater<ll>());

    vector<ll> v{a[0]+b[0]+c[0],0,0,0};
    is_used[0][0][0] = true;
    
    priority_queue<vector<ll>> pq;

    pq.push(v);
    for (int i=0;i<k;i++) {
        ans = pq.top()[0];
        cout << ans << endl;

        for (int j=0;j<3;j++) {
            s[j] = pq.top()[j+1];
        }
        pq.pop();   // ここにないとダメ？

        if(!is_used[s[0]+1][s[1]][s[2]] && s[0]+1 < x) {
            pq.push({a[s[0]+1]+b[s[1]]+c[s[2]],s[0]+1,s[1],s[2]});
            is_used[s[0]+1][s[1]][s[2]] = true;
        }
        if(!is_used[s[0]][s[1]+1][s[2]] && s[1]+1 < y) {
            pq.push({a[s[0]]+b[s[1]+1]+c[s[2]],s[0],s[1]+1,s[2]});
            is_used[s[0]][s[1]+1][s[2]] = true;
        }
        if(!is_used[s[0]][s[1]][s[2]+1] && s[2]+1 < z) {
            pq.push({a[s[0]]+b[s[1]]+c[s[2]+1],s[0],s[1],s[2]+1});
            is_used[s[0]][s[1]][s[2]+1] = true;
        }
    }
}


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

int main(){
	int N;
	cin>>N;
	int A[N];
	for(int i=0;i<N;i++)cin>>A[i];
	
	long long ans = 0;
	
	for(int i=0;i<N;i++){
		ans+=(long long)A[i]/2;
		A[i]%=2;
		if(A[i]&&i!=N-1){
			if(A[i+1]>0){
				A[i+1]--;
				A[i]=0;
				ans++;
			}
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define RALL(a)     (a).rbegin(),(a).rend()
#define PRINT(a)   cout << (a) << endl

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

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

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

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 int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

int main(){
  int n;
  cin >> n;
  vi s(n),t(n);
  REP(i,n){
    int x,y;
    cin >> x >> y;
    s[i] = x+y;
    t[i] = x-y;
  }
  sort(ALL(s)); sort(ALL(t));

  cout << max(s.back()-s[0], t.back()-t[0]) << endl;
}



Measured memory_bytes: 4808
require 'pp'

$stdin.gets.chomp.to_i.times do
  line = $stdin.gets.chomp
  puts a = if (line =~ /^>'(=+)#(=+)~$/ and $1.length == $2.length) then
    'A'
  elsif (line =~ /^>\^(:?Q=)+~~$/) then
    'B'
  else
    'NA'
  end
end

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

int gcd(int x, int y){
	if(y == 0) return x;
	else       return gcd(y, x % y);
}

int main(void){
	int k; //a,b,c [MAX]
	cin >> k;

	int array[201][201]; //gcd(x,y) result
	int sum = 0; //合計

	/* arrayの初期化 */
	for(int i = 0; i<201; i++){
		for(int j = 0; j<201; j++){
			array[i][j] = 0;
		}
	}

	int num;
	for(int a = 1; a <= k; a++){
		for(int b = 1; b <= k; b++){
			num  = gcd(a,b);
			for(int c = 1; c <= k; c++){
				sum += gcd(num,c);
			}
		}
	}

	cout << sum;
	return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    static int n;
    static int[] a = {0, 0};
    static int[] b = {0, 0};
    static int[] c = {0, 0};
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();

        for (int i = 0; i < n; i++) {
            int ai = sc.nextInt();
            int bi = sc.nextInt();
            int ci = sc.nextInt();
            a[i%2] = ai + Math.max(b[(i+1)%2], c[(i+1)%2]);
            b[i%2] = bi + Math.max(a[(i+1)%2], c[(i+1)%2]);
            c[i%2] = ci + Math.max(a[(i+1)%2], b[(i+1)%2]);
        }
        System.out.println(IntStream.of(a[(n+1)%2], b[(n+1)%2], c[(n+1)%2]).max().getAsInt());
     }

}


Measured memory_bytes: 89228
using System;

namespace _1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] c = Console.ReadLine().Split();
            int a =int.Parse(c[0]);
            int b =int.Parse(c[1]);
            Console.WriteLine("{0} {1}", a * b ,2*(a + b));
        }
    }
}


Measured memory_bytes: 15944
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int k,x;
	cin >> k >> x;

	cout << (500*k>=x ? "Yes" : "No") << '\n';
	return 0;
}



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

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	vector<long long> B(N + 1, 0); //累積和テーブル
	int mod = 1000000007;

	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
		B[i + 1] = B[i] + A[i];
	}

	long ans = 0;

	//i について全探索する
	for (int i = 0; i < N; i++)
	{
		//累積和を使ってA[i+1] + ... + A[N] を求める
		long long sum = (B[N] - B[i + 1]) % mod;

		ans += A[i] * sum;
		ans %= mod;
	}

	cout << ans << endl;
}



Measured memory_bytes: 5592
#include <iostream>
#include <cstring>
#include <cstdio>
#include <stdio.h>
#include <cstdlib>
#include <string>
#include <math.h>
#include <algorithm>


//My Answer；
using namespace std;

//B

int main()
{
    char S[101];
    int len;
    cin >> S;
    
    len = strlen(S);
    for (int i = 0; i < len; i++)
    {
        S[i] = 'x';
    }
    cout << S << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 20 16:39:29 2018

@author: Yuya
"""

import numpy
#N = range(1, 100001, 2)

N =list(range(3, 100001, 2))

for i in range(49999):
    flag = -1
    Len_N = len(N)
    for j in range(Len_N-1, i, -1):
        if N[j]%N[i] == 0:
            del N[j]
            flag = 1
    if flag < 0:
        break

N = [2]+N

for i in range(len(N)-1, 0, -1):
    if not (N[i]+1)//2 in N:
        del N[i]
    
N_2017 = N[1:]


Sum_N = [0]*100000

for i in range(len(N_2017)):
    Sum_N[N_2017[i-1]] = 1
    
res = list(numpy.cumsum(Sum_N))

Q = int(input())

L_Q = [0]*Q
R_Q = [0]*Q

for i in range(Q):
    L, R = map(int,input().split())
    L_Q[i] = L
    R_Q[i] = R

for i in range(Q):
    print(res[R_Q[i]]-res[L_Q[i]-1])

Measured memory_bytes: 25504
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <valarray>
#include <utility>
#include <cctype>
#include <numeric>
#include <memory>
#include <functional>
using namespace std;
int n,m,c,cnt;
int a[10005],ans[105][105];
bool b[105][105];
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
inline void next(int &x,int &y)
{
	b[x][y]=true;
	for (int i=0;i<4;++i)
	{
		int nx=x+dx[i],ny=y+dy[i];
		if (nx>=0 && nx<n && ny>=0 && ny<m)
		{
			if (!b[nx][ny])
			{
				x=nx,y=ny;
				return;
			}
		}
	}
}
int main()
{
	scanf("%d%d%d",&n,&m,&c);
	for (int i=0;i<c;++i)
	{
		scanf("%d",a+i);
	}
	int x=0,y=0;
	for (int i=0;i<c;++i)
	{
		while (a[i]--)
		{
			ans[x][y]=i+1;
			next(x,y);
		}
	}
	for (int i=0;i<n;++i)
	{
		for (int j=0;j<m;++j)
		{
			printf("%d%c",ans[i][j]," \n"[j==m-1]);
		}
	}
	return 0;
}

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

#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
struct Grid{int x,y,t;};
struct Edge{int to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=1010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(int from,int to,int cost){E[from-1].pb({to-1,cost});}
};
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,x;cin>>n>>x;
  if(x==1||x==2*n-1){
    cout<<"No"<<endl;
    return 0;
  }
  cout<<"Yes"<<endl;
  vector<int>ans(2*n-1);
  ans[n-1]=x;ans[n-2]=x-1;ans[n]=x+1;
  int ri=2*n-1,le=1;
  int cnt=0;
  for(int i=0;i<n-2;i++){
    while(le==x||le==x-1||le==x+1)le++;
    ans[i]=le;
    le++;
  }
  for(int i=n+1;i<2*n-1;i++){
    while(ri==x||ri==x-1||ri==x+1)ri--;
    ans[i]=ri;
    ri--;
  }
  for(int i:ans){
    cout<<i<<endl;
  }
  return 0;
}


Measured memory_bytes: 2304
//============================================================================
// Name        : template.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <bits/stdc++.h>
using namespace std;
#define _CRT_SECURE_NO_DEPRECATE // suppress some compilation warning messages (for VC++ users)
// Shortcuts for "common" data types in contests
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
// To simplify repetitions/loops, Note: define your loop style and stick with it!
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
#define forn(i,n) \
for (int i =0; i<(n); i++)
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define INF 2000000000 // 2 billion
// If you need to recall how to use memset:
#define MEMSET_INF 127 // about 2B
#define MEMSET_HALF_INF 63 // about 1B
//memset(dist, MEMSET_INF, sizeof dist); // useful to initialize shortest path distances
//memset(dp_memo, -1, sizeof dp_memo); // useful to initialize DP memoization table
//memset(arr, 0, sizeof arr); // useful to clear array of integers

int main() {
	ios::sync_with_stdio(false);
 cin.tie(0);
 int n,x,t; cin >> n >> x >> t;
 int ans = ((n + x -1) / x) * t;
 cout << ans << "\n";
return 0;
}


Measured memory_bytes: 3604
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    s = S()
    l = len(s)
    a = [c == '1' for c in s]
    r = l//2 + l%2
    b = l//2 - 1
    c = l//2 + l%2
    for i in range(b+1):
        if a[b-i] != a[b-i+1] or a[c+i] != a[c+i-1]:
            break
        r += 1

    return r



print(main())




Measured memory_bytes: 8904
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b;
    cin>>a>>b;
    int x=a,y=b;
    for(int i=1;i<b;i++)
    {
        a=a*10+x;
    }
    for(int i=1;i<x;i++)
    {
        b=b*10+y;
    }
    if(a>b)
    {
        cout<<a;
    }
    else
    {
        cout<<b;
    }
    return 0;
}









Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <iostream>
#include <set>
#include <string>
#include <unordered_map>

using namespace std;

int main() {
  int s, w;

  cin >> s >> w;

  if (w >= s) {
    cout << "unsafe" << endl;
  } else {
    cout << "safe" << endl;
  }

  return 0;
}

Measured memory_bytes: 3620
import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int sum1[] = new int[n + 1];
        int sum2[] = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            sum1[i] = sum1[i - 1] + sc.nextInt();
        }
        for (int i = 1; i <= n; i++) {
            sum2[i] = sum2[i - 1] + sc.nextInt();
        }
        int max = 0;
        for (int i = 1; i <= n; i++) {
            max = Math.max(max, sum1[i] + sum2[n] - sum2[i - 1]);
        }
        System.out.println(max);
    }
}

Measured memory_bytes: 23764
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int main(){
  int n, x[100], y[100];
cin >> n;
for ( int i = 0; i < n; i++ ) cin >> x[i];
for ( int i = 0; i < n; i++ ) cin >> y[i];
 
 double d[4];
 for ( int i = 0; i < 4; i++ ) d[i] = 0.0;

 for ( int p = 1; p <= 3; p++ ){
  for ( int i = 0; i < n; i++ ){
    d[p] += pow(fabs(x[i] - y[i]), p);
  }
   d[p] = pow(d[p], 1.0/p);
 }

 for ( int i = 0; i < n; i++ ){
  d[0] = (d[0] < fabs(x[i] - y[i])?fabs(x[i] - y[i]):d[0]);
 }

  printf("%lf\n", d[1]);
  printf("%lf\n", d[2]);
  printf("%lf\n", d[3]);
  printf("%lf\n", d[0]);

  return 0;
}




Measured memory_bytes: 3352
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 9999999999;
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
  T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }


int D; ll G;
vector<int> p;
vector<ll> c;

int main() {
  // 入力
  cin >>D >>G;
  p.assign(D, 0);
  c.assign(D, 0);
  rep(i, D) cin >>p.at(i) >>c.at(i);
  int res = 10 * 100+1;

  // 完全に解き切る100i点の問題を全探索
  for (int bit=0; bit<(1<<D); bit++){
    ll score = 0;
    int pros = 0;
    bool ok = true;
    for (int i=0; i<D; i++){
      if (bit & (1<<i)) score += 100 * (i+1) * p.at(i) + c.at(i), pros += p.at(i);
    }
    if (score < G){
      for (int i=D-1; i>=0; i--){
        if (bit & (1<<i)) continue;
        int onepro = 100 * (i+1);
        int buf = (G - score + onepro - 1) / onepro;
        if (buf > p.at(i)) ok = false;
        pros += buf;
        break;
      }
    }
    if (ok) res = min(res, pros);
  }

  cout <<res <<endl;
}

Measured memory_bytes: 256
S = input()
K = int(input())

cond = True
a = []
ind = 0
while ind <= min(K-1,len(list(set(S)))-1):
	temp = sorted(list(set(S)))[ind]

	for i in range(len(S)):
		if S[i] == temp:
			a.append(S[i:min(i+K,len(S))])

	ind += 1

a = sorted(a)

ans = []
j = 0
k = 1
while len(ans) < K:
	if a[j][:k] not in ans:
		ans.append(a[j][:k])
	k += 1
	if k > len(a[j]):
		k = 1
		j += 1

print(ans[-1])

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

int main(){
    ll H, W, h, w;
    cin >> H >> W >> h >> w;

    put(H*W-h*W-w*H+h*w);
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <bitset>
#include <set>
#include <algorithm>
#include <queue>
#include <map>
#include <assert.h>
 
 
using namespace std;
 
#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e9 + 7;
const int maxN = 2e6 + 5;
const ll MOD = 1e9 + 7;

int n, m, a, b, deg[maxN], dist[maxN];
vi graph[maxN];
queue<int> Q;

void topo() {
	while (!Q.empty()) {
		int u = Q.front(); Q.pop();
		for (auto v: graph[u]) {
			deg[v]--;
			if (deg[v] == 0) {
				dist[v] = dist[u] + 1;
				Q.push(v);
			}
		}
	}
}
int main() {
	ios_base::sync_with_stdio(0);
	cin >> n >> m;
	REP(i, m) {
		cin >> a >> b;
		graph[a].pb(b);
		deg[b]++;
	}
	RI(i, n) {
		if (deg[i] == 0) Q.push(i);
	}
	topo();
	int ans = 0;
	RI(i, n) ans = max(ans, dist[i]);
	cout << ans;
	return 0;
}


Measured memory_bytes: 54528
N,M,Q=map(int,input().split())
L=[0 for i in range(M)]
R=[0 for i in range(M)]
p=[0 for i in range(Q)]
q=[0 for i in range(Q)]
ans=[0 for i in range(Q)]
B=[[0 for i in range(N+1)] for i in range(N+1)]
C=[[0 for i in range(N+1)] for i in range(N+1)]
D=[[0 for i in range(N+1)] for i in range(N+1)]
for i in range(M):
    L[i],R[i]=map(int,input().split())
    L[i]-=1
    R[i]-=1
for i in range(Q):
    p[i],q[i]=map(int,input().split())
    p[i]-=1
    q[i]-=1
for i in range(M):
    B[R[i]][0]+=1
    B[R[i]][L[i]+1]-=1
    B[N][0]-=1
    B[N][L[i]+1]+=1
for i in range(N+1):
    for j in range(N+1):
        if i==0:
            C[i][j]=B[i][j]
        else:
            C[i][j]=B[i][j]+C[i-1][j]
for i in range(N+1):
    for j in range(N+1):
        if j==0:
            D[i][j]=C[i][j]
        else:
            D[i][j]=C[i][j]+D[i][j-1]
for i in range(Q):
    ans[i]=D[q[i]][p[i]]

for line in ans:
    print(line)


Measured memory_bytes: 32748
#include<bits/stdc++.h> 
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#define mod 1000000007
#define mod2 998244353
#define int long long
#define endl "\n"
#define p_b push_back
#define m_p make_pair
#define fastIO ios_base::sync_with_stdio(false),cin.tie(NULL)
using namespace std;
using namespace __gnu_pbds;
template <class T> 
using _ost = tree<
		T, 
		null_type, 
		less<T>, 
		rb_tree_tag, 
        tree_order_statistics_node_update>;

// char alphabet[26] = {'a','b','c','d','e','f','g','h','i',
//        'j','k','l','m','n','o','p','q','r','s','t','u','v',
//        'w','x','y','z'};

struct no{
	int a,b,c,d;
};
int32_t main(){
 	fastIO;
	int a,b,n;
	cin>>a>>b>>n;
	cout<<(min(n,b-1)*a)/b<<endl;
}		



Measured memory_bytes: 3608
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
int n, a, b, c, s;
int g[11][11];
int main() {
    while ((~scanf("%d", &n)) && n) {
        for (int i = 0; i < 11; ++i)
            for (int j = 0; j < 11; ++j)
                if (i == j) g[i][i] = 0;
                else g[i][j] = 1000000;
        s = 0;
        for (int i = 0; i < n; ++i) {
            scanf("%d%d%d", &a, &b, &c);
            //printf("%d %d %d\n", a, b, c);
            g[a][b] = c;
            g[b][a] = c;
            s = max(s, max(a, b));
        }
        for (int k = 0; k <= s; ++k)
            for (int i = 0; i <= s; ++i)
                for (int j = 0; j <= s; ++j)
                    g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
        int ans = 10000000, id = -1;
        for (int i = 0; i <= s; ++i) {
            int t = 0;
            for (int j = 0; j <= s; ++j) t += g[i][j];
            if (ans > t) {
                id = i;
                ans = t;
            }
        }
        printf("%d %d\n", id, ans);
    }
    return 0;
}



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

const ll maxs = 2e5+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

#define IOS ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'

void pre(){

}

void solve(){

    ll k,q;
    cin >> k >> q;
    ll d[k];
    for(ll i=0;i<k;i++)
        cin >> d[i];
    
    while(q--){
        ll n,x,m;
        cin >> n >> x >> m;
        x%=m;
        ll zero = 0;
        ll sum = x;
        for(ll i=0;i<k;i++){
            ll val = d[i]%m;
            ll timer = (n-1)/k;
            if((n-1)%k > i)
                timer++;
            if(val == 0){
                zero += timer;
            }
            else{
                sum += timer*val;
            }
        }

        ll out = (sum/m);
        ll ans = (n-1) - (out + zero);

        cout << ans << endl;
    }
}

int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;   
    //cin>>T;
    while(T--){
        solve();
    }
    return 0;
}

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

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  
  if(A == B && B == C && A == C){
    cout << "No" << endl;
  }
  else if(A != B && B != C && A != C){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 256
#define __USE_MINGW_ANSI_STDIO
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef long long ll;
typedef long long ull;
typedef pair<int, int> ii;

#define all(v)		((v).begin()), ((v).end())
#define sz(v)		((int)((v).size()))
#define endl		"\n"
#define fx(n)		fixed<<setprecision(n)
#define mk			make_pair	

void fast()
{
	ios::sync_with_stdio(NULL);
	cout.tie(NULL);
	cin.tie(NULL);
/*#ifndef ONLINE_JUDGE
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
#endif
#ifdef ONLINE_JUDGE
	freopen("output.txt", "w", stdout);
	freopen("pyramid.in", "r", stdin);
#endif*/
}
const double pi = 2 * acos(0.0);
const ll oo = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int nn = 1e6 + 15;
int dx[8] = { -1, 0, 0, 1, 1, -1, 1, -1 };
int dy[8] = { 0, -1, 1, 0, 1, -1, -1, 1 };


int main()
{
	fast();
	string s;
	cin >> s;
	int n = sz(s);
	int a = -1, b = -1;
	vector<int> arr[30];
	for (int i = 0; i < n; i++)
	{
		arr[s[i] - 'a'].push_back(i);
	}
	for (int i = 0; i < 26; i++)
	{
		for (int j = 0; j < sz(arr[i]); j++)
		{
			for (int k = j+1, x = 2; k < sz(arr[i]); k++,x++)
			{
				if (x>(arr[i][k] - arr[i][j]+1)/2)
				{
					a = arr[i][j] + 1;
					b = arr[i][k] + 1;
					break;
				}
			}
			if (a != -1)
				break;
		}
		if (a != -1)
			break;
	}
	if (a != -1)
		cout << a << " " << b << endl;
	else
		cout << a << " " << b << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 1104
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){

	long long int n, vma = 0;
	long long int ans=1;
	vector<long long int> v, w;

	cin>> n;
	v.resize(n);
	w.resize(n);
	for (int i = 0;i < n;i++) w[i] = 0;

	for (int i = 0;i < n;i++) {
		cin >> v[i];
		if (v[0] != 0) {
			cout << "0" << endl;
			return 0;
		}
		if(i!=0 && v[i]==0) {
			cout << "0" << endl;
			return 0;
		}
		vma = max(vma, v[i]);
		w[v[i]]++;

	}
	//for (int i = 0;i < 10;i++) cout << w[i] << endl;

	sort(v.begin(), v.end());

	for (int i = 2;i < vma+1;i++) {
		for(int j=0;j<w[i];j++) {
			ans *= w[i-1];
			ans = ans % 998244353;
		}
		if (w[i] == 0) ans = 0;
	}

	cout<< ans << endl;



}


Measured memory_bytes: 1920
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
// #include <bits/stdc++.h>

using namespace std;
typedef long long ll; //64bit型

const int INF = 1050000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

const int N_MAX = 2010;

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

int main() //input->compute->output
{
    while (1)
    {
        int x,y;
        cin >> x>>y;
        if (x == 0 && y==0)
            break;
        printf("%d %d\n", min(x,y), max(x,y));
    }

    return 0;
}



Measured memory_bytes: 3152
count5 = 0
count7 = 0

arr = $stdin.gets.chomp.split(/\s+/).map(&:to_i)

arr.map do |str|
  if str == 5
    count5 += 1
  end
  if str == 7
    count7 += 1
  end
end

answer = (count5 == 2 && count7 == 1) ? "YES" : "NO"

puts answer


Measured memory_bytes: 1916
from sys import setrecursionlimit
setrecursionlimit(10**7)
N=int(input())
#0がスタート,1-Nがあか、N+1-2Nが青,2N+1がゴール
table=[[0]*(2*N+2) for i in range(2*N+2)]
for i in range(1,N+1):
    table[0][i]=1
    table[i+N][2*N+1]=1    
red=[]
blue=[]
for i in range(1,N+1):
    a,b=map(int,input().split())
    red.append((i,a,b))
for i in range(1,N+1):
    a,b=map(int,input().split())
    blue.append((i,a,b))
for i,a,b in red:
    for j,x,y in blue:
        if a<x and b<y:
            table[i][N+j]=1
def fk(x):
    visit[x]=True
    if x==2*N+1:
        return True
    for i in range(2*N+2):
        if (not visit[i]) and table[x][i]>0:
            if fk(i):
                table[x][i]-=1
                table[i][x]+=1
                return True
    return False

ans=0
while True:
    visit=[False]*(2*N+2)
    if fk(0):
        ans+=1
    else:
        break

print(ans)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	if(a==1&&b==1) {printf("1"); return 0;}
	if(a==1) {printf("%d",b-2); return 0;}
	if(b==1) {printf("%d",a-2); return 0;}
	printf("%lld",1ll*a*b-2ll*(a-1+b-1));
}

Measured memory_bytes: 256
// Try Educational DP Contest
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
	std::io::Read::read_to_string(
		&mut std::io::stdin(),
		&mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
	let mut get = || stdin.next().unwrap();
	macro_rules! get {
		($t:ty) => (get().parse::<$t>().unwrap());
		() => (get!(i64));
	}
	
	let n = get!(usize);
	let w = get!(usize);
	let mut dp = vec![0; w + 1];
	for _ in 0..n {
		let wi = get!(usize);
		let vi = get!();
		for j in 0..w-wi+1 {
			let j = w-wi-j;
			dp[j+wi] = std::cmp::max(
				dp[j+wi], dp[j]+vi);
		}
	}
	let ans = dp.iter().max().unwrap();
	println!("{}", ans);
}

Measured memory_bytes: 4352