akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void) {

	int r, c, rcsum = 0;
	int rc[101][101] = { 0 };

	scanf("%d %d", &r, &c);
	
	for (int r_i = 0; r_i < r; r_i++) {
		int csum = 0;
		for (int c_i = 0; c_i < c; c_i++) {
			scanf("%d", &rc[r_i][c_i]);
			printf("%d ", rc[r_i][c_i]);
			csum += rc[r_i][c_i];
			rcsum += rc[r_i][c_i];
			if (c_i == c - 1) {
				rc[r_i][c] = csum;
				printf("%d\n", csum);
 			}
		}
	}

	rc[r][c] = rcsum;

	int rsum = 0;

	for (int c_i = 0; c_i < c; c_i++) {
		int rsum = 0;
		for (int r_i = 0; r_i < r; r_i++) {
			rsum += rc[r_i][c_i];
			if (r_i == r - 1) {
				rc[r][c_i] = rsum;
				printf("%d ", rsum);
			}
		}
	}

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

	return 0;
}




Measured memory_bytes: 2092
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        var nk = ReadLine().Split().Select(int.Parse).ToArray();
        int N = nk[0];
        int K = nk[1];
        var A = ReadLine().Split().Select(long.Parse).ToArray();
        
        for (int i = 0; i < N-K; i++)
        {
            if (A[i] < A[K + i]) WriteLine("Yes");
            else WriteLine("No");
            
        }
        
    }
}


Measured memory_bytes: 46948
N = int(input())
A = list(map(int,input().split()))
e_list = [[] for i in range(N)]
for i in range(N-1):
    a,b = list(map(int,input().split()))
    a,b = a-1,b-1
    e_list[a].append(b)
    e_list[b].append(a)

from collections import deque

vi = 0  #change
INF = float('inf')

Q = deque([vi])

DP = [INF]*(N+1)
ans = [-1]*(N)
l = [0]

def bisect(DP,a,l):
    if DP[0] >= a:
        if DP[0]==INF:
            l[0]+=1
        b = DP[0]
        DP[0] = a        
        return (0,b) 
    ok = 0
    ng = N
    while ng-ok>1:
        if DP[(ok+ng)//2]>=a:
            ng = (ok+ng)//2
        else:
            ok = (ok+ng)//2
    if DP[ng]==INF:
        l[0]+=1
    b = DP[ng]
    DP[ng] = a
    return (ng,b)


checked_list = [False]*N
checked_list[vi]=True

while len(Q)>0:
    v = Q.pop()
    if type(v)==type(0):
        Q.append(bisect(DP, A[v], l))
        ans[v] = l[0]
        for v1 in e_list[v]:
            if not checked_list[v1]:
                checked_list[v1]=True
                Q.append(v1)
    else:
        i,a = v
        DP[i] = a
        if a==INF:
            l[0]-=1
        
print(*ans, sep = "\n")

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

const int N=55;
int g[N][N];
int main() {
  int n,m;
  cin >> n >> m;
  for ( int i=0; i<m; i++ ) {
    int a,b;
    cin >> a >> b;
    --a;--b;
    g[a][b]++;
    g[b][a]++;
  }
  for ( int i=0; i<n; i++ ) {
    int ans=0;
    for ( int j=0; j<n; j++ ) {
      ans+=g[i][j];
    }
    cout << ans << '\n';
  }
  return 0; 
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define int long long
using vec_int = vector<int>;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

signed main(){
    int H, W, K; cin>>H>>W>>K;
    vector<string> S(H);
    rep(i,H)cin>>S.at(i);

    // Hの最大値が小さいので、H方向の切り方を全探索する。
    int min_num=INT_MAX;
    for(int i=0;i<(1<<H-1);i++){
        bitset<10> s(i);

        int hol_div = 1;
        for(int j=0;j<H-1;j++){
            if(s[j]==1){
                hol_div++;
            }
        }

        // 切り方は貪欲法で良い
        int flag=1;
        for(int j=0;j<W;j++){
            // この領域でKをそもそも超えていないかをチェックする
            int temp = 0;
            for(int k=0;k<H;k++){
                if(k>0){
                    if(s[k-1]==1){
                        //ここで切れ目になっている
                        if(temp>K){
                            flag=0;
                            goto OUT;
                        }
                        temp=0;
                    }
                }
                if(S.at(k).at(j)=='1'){
                    temp += 1;
                }
                if(k==H-1){
                    if(temp>K){
                        flag=0;
                        goto OUT;
                    }
                }
            }
        }
        OUT:
            if(flag==0)continue;
        
        // これで適切な切り方をすればKいかに抑えられることが分かった
        // 次に切り方を数える
        int cut_num = 0;
        vec_int region_white_num(hol_div,0);
        int index=0;
        for(int k=0;k<H;k++){
            if(k>0){
                if(s[k-1]==1){
                    index++;
                }
            }
            if(S.at(k).at(0)=='1'){
                region_white_num.at(index)+=1;
            }
        }


        int cutnum = 0;
        for(int j=1;j<W;j++){

            index=0;

            //カットを入れる必要があるかをチェックする
            for(int k=0;k<H;k++){
                if(k>0){
                    if(s[k-1]==1){
                        index++;
                    }
                }
                if(S.at(k).at(j)=='1'){
                    region_white_num.at(index)+=1;
                }
            }

            int flag=0;
            for(int k=0;k<hol_div;k++){
                if(region_white_num[k]>K){
                    flag=1;
                    break;
                }
            }

            if(flag==1){
                cutnum+=1;
            for(int k=0;k<hol_div;k++){
                region_white_num[k]=0;
            }
            index=0;
            for(int k=0;k<H;k++){
                if(k>0){
                    if(s[k-1]==1){
                        index++;
                    }
                }
                if(S.at(k).at(j)=='1'){
                    region_white_num.at(index)+=1;
                }
            }
            }
        }
        if(cutnum+hol_div-1<min_num)min_num=cutnum+hol_div-1;

        }

    cout<<min_num<<endl;



    return 0;
}

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


#define M 1000000007
#define pb push_back
#define mp make_pair
#define s second
#define f first
#define mod 998244353
#define sz(v) (int)(v).size()

#define pii pair<int, int>
#define vi vector<int>
#define ll long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)

ll add(ll a,ll b)
{
	a%=M;
	b%=M;
	ll p = (a+b)%M;
	return (p+M)%M;
}

ll mul(ll a,ll b)
{
	a%=M;
	b%=M;
	ll p = (a*b)%M;
	return (p+M)%M;
}


int main()
{
	fastio;
	ll i,n;
	cin>>n;
	if(n%2)
	{
		cout<<"0"<<endl;
		return 0;
	}
	n/=2;
	ll ans=0;
	while(n)
	{
		ans+=n/5;
		n/=5;
	}
	cout<<ans<<endl;
    return 0;
}





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

using std::cin;
using std::cout;
using std::endl;
using std::string;

int main()
{
  int K, S;
  int cnt = 0;
  int z = 0;

  cin >> K >> S;

  for(int x = 0; x <= K; x++) {
    for(int y = 0; y <= K; y++) {
      z = S - x - y;
      if(z >= 0 && z <= K) {
        cnt++;
      }
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
#define for_(i, s, e) for (int i = s; i < e; i++)
#define for__(i, s, e) for (ull i = s; i < e; i++)
#define SSTR(x) static_cast<std::ostringstream&>((std::ostringstream() << std::dec << x)).str()
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define endl "\n"


int main() {
    #ifndef ONLINE_JUDGE
	freopen("test.in", "r", stdin);
    #endif
    
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n; cin >> n;
    vector<ll> ans(n+1);
    for__(i, 1, n+1) {
        ll s = i*i;
        if (s > n) break;
        for__(j, i, n+1) {
            ll prevv = s;
            s += j*j + i*j;
            if (s > n) {
                s = prevv;
                break;
            }
            for__(k, j, n+1) {
                ll prev = s;
                s += k*k + k*i + k*j;
                if (s > n) {
                    s = prev;
                    break;
                }
                int v = 6;
                int same = 0;
                if (i == j) same += 1;
                if (j == k) same += 1;
                if (i == k) same += 1;
                if (same == 3) v = 1;
                else if (same == 1) v = 3;
                ans[s] += v;
                // cout << i << ' ' << j << " " << k << " => " << s << "..." << v << endl;
                s = prev;
            }
            s = prevv;
        }
    }

    for_(i, 1, n+1) cout << ans[i] << " ";
    cout << endl;

    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<ll, II> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 110;
const int MAXK = 510;

int n;
ll dp[MAXN][5][5][5];

bool check3(int i, int j, int k) {
    if (i == 1 && j == 3 && k == 2) return false;
    swap(i, j);
    if (i == 1 && j == 3 && k == 2) return false;
    swap(i, j);
    swap(j, k);
    if (i == 1 && j == 3 && k == 2) return false;
    return true;
}

bool check4(int i, int j, int k, int l) {
    if (i == 1 && j == 3 && k == 2) return false;
    if (j == 1 && k == 3 && l == 2) return false;
    swap(i, j);
    if (i == 1 && j == 3 && k == 2) return false;
    if (j == 1 && k == 3 && l == 2) return false;
    swap(i, j);
    swap(j, k);
    if (i == 1 && j == 3 && k == 2) return false;
    if (j == 1 && k == 3 && l == 2) return false;
    swap(j, k);
    swap(k, l);
    if (i == 1 && j == 3 && k == 2) return false;
    if (j == 1 && k == 3 && l == 2) return false;
    return true;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,4) FOR(j,1,4) FOR(k,1,4) 
        if (check3(i, j, k)) dp[3][i][j][k] = 1;
    FOR(it,3,n-1)
        FOR(i,1,4) FOR(j,1,4) FOR(k,1,4)
            FOR(l,1,4)
                if (check4(i, j, k, l)) dp[it+1][j][k][l] = (dp[it+1][j][k][l] + dp[it][i][j][k]) % MODBASE;
    ll res = 0;
    FOR(i,1,4) FOR(j,1,4) FOR(k,1,4) res = (res + dp[n][i][j][k]) % MODBASE;
    cout << res;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ss(x) (int) x.size()
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)
#define all(x) x.begin(), x.end()
 
using namespace std;

const int N = 3100;
const int MOD = 998244353;

int a, b, c, d;
int dp[N][N];
int s[N];

ll pt(ll a, ll b) {
	if (!b) return 1;
	if (b & 1) return a * pt(a, b - 1) % MOD;
	return pt(a * a % MOD, b / 2);
}

ll rev(ll a) {
	return pt(a, MOD - 2);
}

int main() {
	scanf ("%d%d%d%d", &a, &b, &c, &d);
	rep(h, 1, c) {
		int root = 1, odw = rev(h);
		rep(w, 1, d) {
			s[w] = (s[w - 1] + 1LL * dp[h - 1][w] * w % MOD * root) % MOD;
			root = 1LL * root * odw % MOD;
		}
		
		root = 1;
		rep(w, 1, d) {
			if (h < a || w < b) {
				dp[h][w] = 0;
			}
			if (h == a && w >= b) {
				dp[h][w] = pt(h, w - b);
				continue;
			}
			if (w == b && h >= a) {
				dp[h][w] = pt(w, h - a);
				continue;
			}
			dp[h][w] = (1LL * s[w - 1] * root + 1LL * w * dp[h - 1][w]) % MOD;
			root = 1LL * root * h % MOD;
		}
		
		//rep(w, 1, d) {
		//	printf ("%d %d %d\n", h, w, dp[h][w]);
		//}
	}
	printf ("%d\n", dp[c][d]);
			
	
	return 0;
}	


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

using namespace std;

int main()
{
  int N, X;
  cin >> N >> X;
  vector <int> m(N, 0);
  for( int i=0;i<N;i++ )
    cin >> m[i];
  
  sort(m.begin(), m.end());

  int s = 0;
  int n = N;
  for( int i=0;i<N;i++ )
    s += m[i];
  X-=s;

  
  cout << N+X/m[0] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<=(b);++i)
#define ROF(i,a,b) for (int i=(a);i>=(b);--i)
typedef long long ll;
inline int read() {
	int x=0,s=1; char ch=getchar();
	while (ch<'0'||ch>'9') { if (ch=='-') s=-1; ch=getchar(); }
	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
	return s*x;
}

const int MAXN=800005,Mo=1000000007;
multiset<int> S;
vector<pair<int,int> >Q;
int n,m,q,a[MAXN],b[MAXN];
void build(int x,int l,int r){
	if (l==r) { a[x]=0; b[x]=l; return; }
	int mid=(l+r)/2;
	build(x<<1,l,mid); build(x<<1|1,mid+1,r);
	b[x]=min(b[x<<1],b[x<<1|1]);
}
void pushdown(int x){
	if (a[x]) {
		b[x<<1]-=a[x]; b[x<<1|1]-=a[x];
		a[x<<1]+=a[x]; a[x<<1|1]+=a[x];
		a[x]=0;
	}
}
void change(int x,int l,int r,int k){
	if (k<=l) { b[x]--,a[x]++; return; }
	int mid=(l+r)/2;
	pushdown(x);
	if (k<=mid) change(x<<1,l,mid,k);
	if (k<=r) change(x<<1|1,mid+1,r,k);
	b[x]=min(b[x<<1],b[x<<1|1]);
}
int query(int x,int l,int r){
	if (l==r) return l;
	int mid=(l+r)/2;
	pushdown(x);
	if (b[x<<1|1]==0) return query(x<<1|1,mid+1,r);
	else return query(x<<1,l,mid);
}
int main(){
	n=read(); m=read();
	int tot1=0,tot2=0;
	build(1,0,m);
	FOR(i,1,n) {
		int x=read(),y=read();
		if (x==0) {
			int M=m+1-y;
			if (query(1,0,m)<M) tot2++,change(1,0,m,M);
		}
		else Q.push_back(make_pair(x,y));
	}
	sort(Q.begin(),Q.end());
	int Qsize=Q.size(); S.clear();
	//FOR(i,0,Qsize-1) printf("(%d,%d)\n",Q[i].first,Q[i].second);
	int ans=tot1+tot2;
	FOR(i,0,Qsize-1) {
		int x=Q[i].first,y=Q[i].second;
		if (tot1<x) tot1++,S.insert(y);
		else {
			S.insert(y);
			auto tmp=S.begin();
			int M=m+1-(*tmp); S.erase(tmp);
			if (query(1,0,m)<M) tot2++,change(1,0,m,M);
		}
		ans=max(ans,tot1+tot2);
	}
	ans=min(ans,m);
	printf("%d\n",n-ans);
	
	return 0;
}

/*
*/

Measured memory_bytes: 17264
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
   int a;
   int b;
   int c;
   int d;
  
   cin >> a;
   cin >> b;
   cin >> c;
  
   d=a;
   a=b;
   b=d;
   d=a;
   a=c;
   c=d;
  
   cout << a << endl;
   cout << b << endl;
   cout << c << endl;
  
  }

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

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

int main(int argc, char **argv)
{
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    int l[Q], r[Q];
    REP(i, Q) cin >> l[i] >> r[i];

    int c[N + 1];
    c[0] = 0;
    c[1] = 0;
    FOR(i, 2, N + 1) {
        int t = (S[i-1] == 'C' && S[i - 2] == 'A')? 1 : 0;
        c[i] = c[i - 1] + t;
    }
    REP(i, Q) {
        cout << c[r[i]] - c[l[i]] << endl;
    }
    return 0;
}


Measured memory_bytes: 2176
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;

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

    int mini = 1000;
    for (int i = 0; i < str.length() - 2; i++)
    {
        int candi = abs(753 - stoi(str.substr(i, 3)));
        mini = min(mini, candi);
    }

    cout << mini << '\n';
}

Measured memory_bytes: 256
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

N = int(input())
A = input()
B = input()
C = input()

ans = 0
for a, b, c in zip(A, B, C):
  ans += len(set((a,b,c)))-1

print(ans)



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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;


int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    int a, b;
    a = 800*n;
    n/=15;
    b = 200*n;
    cout << a-b << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using i8 = std::int8_t;
using u8 = std::uint8_t;
using i16 = std::int16_t;
using u16 = std::uint16_t;
using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;
using i128 = __int128_t;
using u128 = __uint128_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

constexpr i64 MOD = 1000000007;

i64 dp[101][100001];

auto main() -> i32 {
	i32 n, k;
	scanf("%d%d", &n, &k);
	i32 a[n];
	for (i32 i = 0; i < n; ++i) {
		scanf("%d", a + i);
	}

	dp[0][0] = 1;
	for (i32 i = 0; i < n; ++i) {
		for (i32 l = 0; l <= k; ++l) {
			dp[i + 1][l] += dp[i][l];
			i32 ub = l + a[i] + 1;
			if (ub <= k) {
				dp[i + 1][ub] -= dp[i][l];
			}
		}
		dp[i + 1][0] %= MOD;
		for (i32 j = 1; j <= k; ++j) {
			dp[i + 1][j] += dp[i + 1][j - 1];
			dp[i + 1][j] %= MOD;
		}
	}
	printf("%ld\n", (MOD + dp[n][k]) % MOD);
	return 0;
}


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

using namespace std;

int main(){
while(1){
int n,a,tp,hp;
bool flg=true;
int t[201]={0},h[201]={0};
cin >> n;
if(n==0)return 0;
for(int i=1;i<=n;i++){
cin >> a;
t[a]=1;}

for(int i=1;i<=2*n;i++){
if(t[i]==0)
h[i]=1;}

tp=hp=n;

while(1){

if(tp==0 || hp==0){
cout << tp << endl << hp << endl;
break;
}
for(int i=1;i<=2*n;i++){
if(flg){
if(t[i]==1){
hp--;t[i]=69;flg=!flg;}}
else if(!flg){
if(h[i]==1){
tp--;h[i]=69;flg=!flg;}}
if(tp==0 || hp==0){
break;
}
}
flg=!flg;
}
}
return 0;
}


Measured memory_bytes: 3088
def examA():
    A, B = LI()
    ans = A+B
    if ans>=10:
        ans = str("error")
    print(ans)


import sys
import copy
import bisect
import heapq
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examA()

Measured memory_bytes: 38256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        //List<int> values = new List<int>(Console.ReadLine().Split(' ').Select(s => int.Parse(s)));
        //List<int> values = new List<int>();

        string input = Console.ReadLine();
        //int n = int.Parse(input.Split(' ')[0]);
        //int m = int.Parse(input.Split(' ')[1]);
        //int k = int.Parse(input.Split(' ')[2]);

        int a = 0;
        foreach (var item in input)
        {
            if(item == '2')
            {
                a++;
            }
        }

        Console.WriteLine(a); return;



    }
}

Measured memory_bytes: 13140
#include <stdio.h>

#define INFTY 100000
#define max 100

int m[max+1][max+1];
int p[max+1];
int n;

int min(int a,int b){
  return (a<b)?a:b;
}

void matrix(){
  int i,j,l,k;
  for(i=1;i<=n;i++) m[i][i]=0;

  for(j=2;j<=n;j++){
    for(i=1;i<=n-j+1;i++){
      l=i+j-1;
      m[i][l]=INFTY;
      for (k=i;k<l;k++) m[i][l]=min(m[i][l],m[i][k]+m[k+1][l]+p[i-1]*p[k]*p[l]);
    }
  }
}

void input(){
  int i;
  for(i=1;i<=n;i++){
    scanf("%d %d",&p[i-1],&p[i]);
  }
}

int main(int argc, char const *argv[]) {
  scanf("%d",&n);
  input();
  matrix();
  printf("%d\n",m[1][n]);
  return 0;
}

Measured memory_bytes: 636
N = int(input())

res = []

if N % 2 == 0:
    for i in range(1, N + 1):
        for j in range(1, i):
            if j != N + 1 - i:
                res.append("{:d} {:d}".format(i, j))
else:
    for i in range(1, N):
        res.append("{:d} {:d}".format(N, i))
    for i in range(1, N):
        for j in range(1, i):
            if j != N - i:
                res.append("{:d} {:d}".format(i, j))

print(len(res))
for m in res:
    print(m)


Measured memory_bytes: 3600
import sys

sys.setrecursionlimit(10 ** 9)

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

A.sort()

MOD = 10 ** 9 + 7


# aの-1乗をmで割ったときの商を求める
def mod_inv(a, m=10 ** 9 + 7):
    b = m
    u = 1
    v = 0
    while b > 0:
        t = a // b
        a -= t * b
        c = a
        a = b
        b = c

        u -= t * v
        c = u
        u = v
        v = c
    u %= m
    return u


max_X = 0
min_X = 0

combinations = 1

count = K - 1

for i in range(N - K + 1):
    max_X += combinations * A[count + i]
    min_X += combinations * A[N - count - 1 - i]
    max_X %= MOD
    min_X %= MOD
    combinations = (combinations * (K + i) * mod_inv(i + 1)) % MOD

ans = max_X - min_X

while ans < 0:
    ans += MOD

print(ans % MOD)


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

int main(){
	int n;
  	cin >> n;
  vector<int> l(n);
  for(int i = 0;i < n;i++) cin >> l[i];
  sort(l.begin(), l.end());
  
  long long ans = 0;
  
  for(int i = 0;i < n;i++){
	for(int j = i+1;j < n;j++){
		auto ll = upper_bound(l.begin()+j+1, l.end(), l[j]-l[i]);
     	auto r = lower_bound(l.begin()+j+1, l.end(), l[j]+l[i]);
      	ans += r-ll;
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

class Main {

	public static final int mod=(int)1e9+7;
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		out=new PrintWriter (new BufferedOutputStream(System.out));
		FastReader s=new FastReader();
		int n=s.nextInt();
		int m=s.nextInt();
		long[][] arr=new long[n][m];
		for(int i=0;i<n;i++) {
			String str=s.next();
			for(int j=0;j<str.length();j++) {
				if(str.charAt(j)=='#') {
					arr[i][j]=-1;
				}
			}
		}
		arr[0][0]=1;
		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				if(arr[i][j]==-1) {
					continue;
				}
				if(i-1>=0 && arr[i-1][j]!=-1) {
					arr[i][j]=(arr[i][j]+arr[i-1][j])%mod;
				}
				if(j-1>=0 && arr[i][j-1]!=-1) {
					arr[i][j]=(arr[i][j]%mod+arr[i][j-1]%mod)%mod;
				}
			}
		}
		out.println(arr[n-1][m-1]);
		out.close();
	}

	public static PrintWriter out;
	
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
		//it reads the data about the specified point and divide the data about it ,it is quite fast
		//than using direct 

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception e) {
				e.printStackTrace();
			}
			return str;
		}
	}
	
}


Measured memory_bytes: 35204
#include <bits/stdc++.h>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 100010, LOG=20;

int n, m, k, u, v, x, y, t, a, b, ans;
int A[MAXN];

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n>>m;
	cout<<max(0, n-2*m)<<'\n';
	
	
	return 0;
}



Measured memory_bytes: 256
n, a, b = map(int, input().split())
ls = sorted([int(input()) for _ in range(n)])
lo = (ls[-1] + a - 1) // a
hi = (ls[-1] + b - 1) // b + 1
mi = (hi + lo) // 2
while hi > lo + 1:
    mi = (hi + lo) // 2
    if sum([(max(x - mi * b, 0) + a - b - 1) // (a - b) for x in ls]) <= mi:
        hi = mi
    else:
        lo = mi
if sum([(max(x - lo * b, 0) + a - b - 1) // (a - b) for x in ls]) <= lo:
    print(lo)
else:
    print(hi)

Measured memory_bytes: 10940
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int a,b,c,d,ans;
            string[] str = Console.ReadLine().Split(' ');
            a = int.Parse(str[0]);
            b = int.Parse(str[1]);
            c = int.Parse(str[2]);
            d = int.Parse(Console.ReadLine());
            ans = 0;
            for(int i = 0; i <= d; i++)
            {
                for(int j = 0; j <= d; j++)
                {
                    for(int k = 0; k <= d; k++)
                    {
                        int ans_a = a;
                        int ans_b = b;
                        int ans_c = c;
                        ans_a *= (int)Math.Pow(2,i);
                        ans_b *= (int)Math.Pow(2,j);
                        ans_c *= (int)Math.Pow(2,k);
                        if(ans_b > ans_a && ans_c > ans_b && (i+j+k) <= d)
                        {
                            ans = 1;
                        }
                    }
                }
            }
            if(ans == 1)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 27680
N = int(input())
d = list(map(int, input().split()))

D = sorted(d)

answer = 0
length = len(d)

if D[length//2-1] == D[length//2]:
    print(answer)
else:
    l = []
    i = D[length//2-1]
    while i+1 <= D[length//2]:
        l.append(i+1)
        i +=1
    answer = len(l)
    print(answer)


Measured memory_bytes: 53744
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;

int main(){
string S;
cin>>S;
map<char,int>num;
if(S.size()!=26){
rep(i,S.size()){
  num[S[i]]++;
}
rep(i,26){
  if(num[(char)(i+'a')]==0){
    S+=string(1,(char)(i+'a'));
    break;
  }
}
}
else{
  if(S[0]=='z'){
    cout<<-1<<endl;
    return 0;
  }
  else{
    int p=S.size()-1;
    repr(i,S.size()-1){
      if(S[i]<S[i+1]){
        p=i;
        break;
      }
      
      
    }
    char c='z'+1;
    rep2(i,p+1,26){
      if((S[p]<S[i])&&(c>S[i])){
        c=S[i];
      }

    }
    S=S.substr(0,p)+string(1,c);


  }
  
}
cout<<S<<endl;
return 0;
}

Measured memory_bytes: 3604
#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>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}

int main()
{
	int d;
	cin >> d;
	str ans = "Christmas";
	for (size_t i = 0; i < abs(d - 25); i++)
	{
		ans += " Eve";
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3588
#include <iostream>

using namespace std;
#define rep(i, n) repi(i,0,n)
#define repi(i, a, b) for(int i=int(a);i<int(b);++i)

const int N = 3010;
long mod;

long ifact[N] = {1, 1};
int stir[N][N] = {1};

void prepare() {
  static long inv[N] = {0, 1};
  repi(i, 2, N) {
    inv[i] = inv[mod % i] * (mod - mod / i) % mod;
    ifact[i] = ifact[i - 1] * inv[i] % mod;
  }
  repi(i, 1, N) repi(j, 1, N) {
      stir[i][j] = (stir[i - 1][j - 1] + long(i - 1) * stir[i - 1][j]) % mod;
    }
  rep(i, N) {
    for(int j = ~i & 1; j < N; j += 2) {
      stir[i][j] = -stir[i][j];
    }
  }
}

int n, a[N], x;

void input() {
  cin >> n;
  mod = n;
  n--;
  rep(i, n + 1) cin >> a[i];
}

long c[N];

void solve() {
  if(n > 3000) return;
  rep(i, n + 1) {
    long t = 1;
    rep(j, i) {
      c[i] = (c[i] + c[j] * t) % mod;
      t = t * i % mod;
    }
    c[i] = (a[i] + mod - c[i]) * ifact[i] % mod;
    rep(j, i) {
      c[j] = (c[j] + c[i] * stir[i][j]) % mod;
    }
  }
  long ans = 0, t = 1;
  rep(i, n + 1) {
    c[i] = ((c[i] % mod) + mod) % mod;
    ans = (ans + c[i] * t) % mod;
    cout << c[i] << " ";
  }
  cout << endl;
}

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

  input();
  prepare();
  solve();
}


Measured memory_bytes: 35840
N = int(input())

p = [0]*(N+1)

def pf(n):
    x = 2
    done = False
    while done == False:
        if n == 1:
            done = True
        if n % x == 0:
            n = n // x
            p[x] += 1
        else:
            x += 1
    
for i in range(1,N+1):
    pf(i)

ans = 1
for i in p:
    ans *= i+1
    ans %= 10**9 + 7
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ll = long long int;
using vec = vector<int>;
using P = pair<int,int>;
const int INF = 1e9+7;

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

  int b = (s[0]-'0') * 100 + (s[2]-'0') * 10 + (s[3]-'0');

  cout << a * b / 100 << endl;
}


Measured memory_bytes: 3624
n = int(input())
a = [[]]*2
for i in range(2):
  a[i] = list(map(int,input().split()))
cand = 0
nowcand = 0
for i in range(n):
  nowcand += a[0][i]
cand = max(cand,nowcand+a[1][n-1])
nowcand = 0
for i in range(n):
  nowcand += a[1][i]
cand = max(cand,nowcand+a[0][0])
if n>2:
  for k in range(1,n-1):
    nowcand = 0
    for i in range(k+1):
      nowcand += a[0][i]
    for j in range(k,n):
      nowcand += a[1][j]
    cand = max(cand,nowcand)
print(cand)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int main(){
    int K;
    cin >> K;
    int ans = 0;
    for(int a = 1; a <= K; a++){
        for(int b = 1; b <= K; b++){
            for(int c = 1; c <= K; c++){
                ans += gcd(a, gcd(b, c));
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
long long a, b, k = 1, ans;
int main()
{
	cin >> a >> b;
	if (b == 1)
	{
		cout << 0;
		return 0;
	}
	while (true)
	{
		k = k + a - 1;
		ans ++;
		if (k >= b)
		{
			cout << ans;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<bitset>
using namespace std;
typedef long long ll;
signed main(){
  ll n,ans=0,cnt=0,addt,xort,l=0,r=0;
  cin >> n;
  ll a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  addt=xort=a[0];
  while(l<n){
    if(addt==xort){
      if(r<n-1){
        r++;
        addt+=a[r];
        xort^=a[r];
      }else{
        ans += r-l+1;
        addt -= a[l];
        xort ^= a[l];
        l++;
      }
    }else{
      ans += r-l;
      addt-=a[l];
      xort^=a[l];
      l++;
      
    }
  }
  cout << ans<<endl;
}


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

int main(void) {
	int a[10] = { 0 };
	for (int i = 0; i < 10; i++) {
		cin >> a[i];
	}
	for (int j = 0; j < 3; j++) {
		int max = 0, label = 0;
		for (int i = 0; i < 10; i++) {
			if (a[i] > max) {
				max = a[i];
				label = i;
			}
		}
		cout << max << endl;
		a[label] = 0;
	}
	return 0;
}

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

int main(){
    int n,a,max;
    cin>>n;
    vector<int> vec,arr;
    for(int i=0;i<n;i++){
        cin>>a;
        vec.push_back(a);
        arr.push_back(a);
    }
    sort(vec.begin(),vec.end());
    max=vec[n-1];
    for(int i=0;i<n;i++){
        if(max==arr[i]){
            cout<<vec[n-2]<<endl;;
        }else{
            cout<<max<<endl;
        }
    }
    return 0;
}






Measured memory_bytes: 3436
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t N, count, a, sum;
  sum=1;
  count=1;
  cin >> N;
  
  while (N>1) {
    N/=2;
    count++;
  }
  
  for (int i=0; i<count; i++) {
    if (i==0) {
      a=1;
    }
    else {
      sum=sum+a*2;
      a*=2;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

int main() {
  int n, sum = 0;
  for(int i=0; i<10; ++i) {
    cin >> n;
    sum += n;
  }
  cout << sum << endl;
}




Measured memory_bytes: 3096
/*---------------------------*\
____________Mari000____________         
________Mostafa  Shehab________    
\*---------------------------*/

#include <bits/stdc++.h>
using namespace std;
 
#define PI  3.14159265  // PI = acos(-1)
#define EPS (1e-10)
#define endl "\n"
typedef long long ll;
typedef long double ld;
//template <class Type>

ll power(ll x,ll y,ll p);
int Bit(ll x);
 
inline int D(){
	int t;
	scanf("%d",&t);
	return t;
}
inline ll llD(){
	ll t;
	scanf("%lld",&t);
	return t;
}

const int N=1e5 + 5;
unordered_map<int,int> mp;
int n;
ll cnt=1e18,m;

void div(int n){
	m=0;
	while(!(n&1))
		n=(n>>1),++m;
	cnt=min(cnt,m);
}

int a,b,c,d;

int main(){
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if(c>=a && c<=b)
		printf("%d",min(b-c,d-c));
	else if(a>=c && a<=d)
		printf("%d",min(b-a,d-a));
	else
		printf("0");

}










ll power(ll x,ll y,ll p){ 
    ll res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or  
                // equal to p 
    while (y > 0){ 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p;
    }
    return res; 
}


int Bit(ll x){
	if(!x)
		return 0;
	return 1+Bit(x>>1);
}


















Measured memory_bytes: 256
using System;

namespace Sound_A
{
    class Program
    {
        static void Main(string[] args)
        {
			string[] acs = Console.ReadLine().Split(' ');
			int A = int.Parse(acs[0]);
			int B = int.Parse(acs[1]);
			if (A + B == 15)
			{
				Console.WriteLine("+");
			}
			else if (A * B == 15)
			{
				Console.WriteLine("*");
			}
			else
			Console.WriteLine("x");
		}
	}
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
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; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  ll A,B; cin >>A >>B;
  int K; cin >>K;
  for (int i=0; i<K; i++){
    A = A/2*2;
    B += A/2;
    A /= 2;
    swap(A,B);
  }
  if (K%2==1) swap(A,B);
  cout <<A <<" " <<B <<endl;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    if((n%1000)%111==0||(n/10)%111==0){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# coding: utf-8

import itertools

def main():
    N, A, B, C = list(map(int, input().split()))
    ll = []
    for _ in range(N):
        ll.append(int(input()))

    cand = []
    ids = set(range(N))
    for a in range(1, N-1):
        for b in range(1, N-a):
            for c in range(1, N-a-b+1):
                cand.append((a, b, c))
    best_cost = -1
    for a, b, c in cand:
        la = itertools.combinations(ids, a)
        for a_ in la:
            lb = itertools.combinations(ids-set(a_), b)
            for b_ in lb:
                lc = itertools.combinations(ids-set(a_)-set(b_), c)
                for c_ in lc:
                    cost = (len(a_)-1)*10 + abs(sum(ll[e] for e in a_)-A)
                    cost += (len(b_)-1)*10 + abs(sum(ll[e] for e in b_)-B)
                    cost += (len(c_)-1)*10 + abs(sum(ll[e] for e in c_)-C)
                    if best_cost == -1 or cost < best_cost:
                        best_cost = cost
    print(best_cost)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int n,m,t;
  cin>>n>>m>>t;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];
  sort(a.rbegin(),a.rend());
  Int INF=100000000000;
  vector<Int> w(t,INF);
  w[a[0]%t]=a[0];
  for(Int i=0;i<n;i++)
    w[(a[0]-a[i])%t]=min(w[(a[0]-a[i])%t],a[0]-a[i]);
  
  vector<Int> dist(t,INF),used(t,0);
  dist[0]=0;
  while(1){
    Int u=-1;
    for(Int i=0;i<t;i++){
      if(used[i]) continue;
      if(u<0||dist[i]<dist[u]) u=i;
    }
    if(u<0) break;
    used[u]=1;
    for(Int i=0;i<t;i++)
      dist[(u+i)%t]=min(dist[(u+i)%t],dist[u]+w[i]);
  }
  vector<Int> res(t,INF);
  for(Int i=0;i<t;i++)
    res[(a[0]*m+(t-i))%t]=a[0]*m-dist[i];
  for(int i=t-2;i>=0;i--) res[i]=max(res[i],res[i+1]);
  
  Int q;
  cin>>q;
  
  while(q--){
    Int A,B;
    cin>>A>>B;
    if(res[A]>=B*t) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3768
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<string>
#include<vector>
using namespace std;
const double PI = acos(-1);  // PI = 3.141593...

void print(int a[], int n) {
    for(int i = 0; i < n; ++i) {
        if(i) cout << " ";
        cout << a[i];
    }
    cout << endl;
}
void insertion_sort(int a[], int n) {
    for(int i = 1; i < n; ++i) {
        int v = a[i];
        int j = i - 1;
        while(j >= 0 && a[j] > v) {
            a[j+1] = a[j];
            --j;
        }
        a[j+1] = v;
        print(a, n);
    }
}
int main() {
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    print(a, n);
    insertion_sort(a, n);
    return 0;
}


Measured memory_bytes: 3084
n=int(input())

ans=[0]*(n+1)

for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            f= x**2 + y**2 + z**2 + x*y + y*z + z*x
            if f<=n:
                ans[f]+=1

for i in range(1,n+1):
    print(ans[i])


Measured memory_bytes: 9168
#include <iostream>
using namespace std;
int main(void) {
	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	int min_price = 1e9;
	for (int i = 0; i <= 100000; ++i) {
		int price = i * 2 * c + max(0, x - i) * a + max(0, y - i) * b;
		min_price = min(min_price, price);
	}
	cout << min_price << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<vector>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
typedef long long ll;
const int N = 2001;
const ll inf = (1LL<<62);
ll dp[N][N];
ll compute(int a,int b,const vector<ll> &sum,const ll l){
  if (a < b)swap(a,b);
  return (sum[a]-sum[b-1])/l;
}

//a > b should be satisfied: a,b is index
ll solve(int n,const ll l,int a,int b,const vector<int> &all,const vector<ll> &sum){
  //cout << a << " " << b << " " << n <<" " << endl;
  if (a+1 == n || b+1 == n){
    ll ret=0;
    if (b == 0){//circular
      ret=compute(all[a],all[1],sum,l);
    }else {
      ret=compute(all[a],all[b],sum,l);
    }
    return ret;
  }
  if (a < b)swap(a,b);
  int now=max(a,b)+1;

  ll &ret=dp[a][b];
  if (dp[a][b] != -1)return ret;
  ret=inf;
  //right//
  ret=min(ret,compute(all[now],all[a],sum,l)+solve(n,l,now,b,all,sum));

  //left//b->now
  if (b == 0){
    ret=min(ret,compute(all[1],all[now],sum,l)+solve(n,l,a,now,all,sum));
  }else {
    ret=min(ret,compute(all[now],all[b],sum,l)+solve(n,l,a,now,all,sum));
  }
  return ret;
}



main(){
  int n,m;
  ll l;
  while(cin>>n>>m>>l){
    vector<ll> sum(m+1);
    vector<int> all(n+1);
    rep(i,n){
      cin>>all[i];
      //all[i]--;
    }
    sum[0]=0;
    rep(i,m){
      int in;
      cin>>in;
      sum[i+1]=in+sum[i];
    }
    sort(all.begin(),all.end());
    rep(i,n+1)rep(j,n+1)dp[i][j]=-1;
    n++;
    cout << solve(n,l,1,0,all,sum) << endl;
  }
  return 0;
}

  

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

int main() {
    int k  = 15, win = 0;
    string s, msg = "NO";

    cin >> s;

    for (int i = 0; i < s.length(); i++) {
        if (s[i] == 'o') {
            win++;
        }
    }
 
    if (k - s.length() + win >= 8) {
        msg = "YES";
    }

    cout << msg << endl;
}

Measured memory_bytes: 256
S = input().strip()

ans = float("inf")

for i in range(26):
    tmp = 0
    current = 0
    for s in S:
        if s == chr(ord('a') + i):
            tmp = max(tmp, current)
            current = 0
        else:
            current += 1

    tmp = max(tmp, current)
    ans = min(ans, tmp)

print(ans)



Measured memory_bytes: 8888
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
#define ll long long
#define mem(x) memset(x,0,sizeof(x))
#define sca(x) scanf("%d",&x)
#define scall(x) scanf("%lld",&x)
ll a[200005];
int main()
{
	int n;cin>>n;
	for(int i=1;i<=n;i++)
	cin>>a[i];
	a[0]=210;
	a[n+1]=0;
	ll num=0;
	ll mon=1000;
	for(int i=1;i<=n;i++)
	{
		if(a[i]>=a[i-1]&&a[i]>=a[i+1])
		{
			mon+=(num*a[i]);
			num=0;
		}
		if(a[i]<=a[i-1]&&a[i]<=a[i+1])
		{
			{
			num+=(mon/a[i]);
			mon-=(mon/a[i]*a[i]);
			}
		}
		//cout<<num<<endl;
	}
	cout<<mon<<endl;
}

Measured memory_bytes: 3628
n=int(input())
a=[]
for i in range(n):
	a.append(int(input()))
a.sort()

now=a[0]
odd=0
ans=0
for i in range(n):
	#前の文字と一緒の時
	if a[i]==now:
		odd=(odd+1)%2
	#前の文字と違う時
	else:
		#前の文字の個数の偶奇を判定し、奇数ならansをインクリメント
		ans+=odd
		#注目する文字を今の文字にする
		now=a[i]
		odd=1
#最後の文字をきちんと処理するためにoddを加える
print(ans+odd)

Measured memory_bytes: 7388
import numpy as np

def main():
    n, s = map(int, input().split())
    a = [int(i) for i in input().split()]
    mod = 998244353
    dp = np.zeros((n + 1, s + 1), dtype=int)
    dp[0][0] = 1
    for i in range(n):
        ai = a[i]
        dp[i + 1] = dp[i] * 2 % mod
        dp[i + 1, ai:] = (dp[i + 1, ai:] + dp[i, :-ai]) % mod
    print(dp[n][s])

if __name__ == '__main__':
    main()

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

const string YES = "Yes";

VI G[100000];

void solve(long long N, long long M, std::vector<long long> A, std::vector<long long> B){
    VI ans(N, -1);

    REP(i, M) {
        G[A[i]-1].PB(B[i]-1);
        G[B[i]-1].PB(A[i]-1);
    }

    queue<LL> now, next;
    now.push(0);

    while(!now.empty()) {
        while(!now.empty()) {
            LL n = now.front(); now.pop();
            REP(i, G[n].size()) {
                if(ans[G[n][i]] == -1) {
                    ans[G[n][i]] = n + 1;
                    next.push(G[n][i]);
                }
            }
        }
        swap(now, next);
    }
    cout << "Yes" << endl;
    REP1(i, N) {
        cout << ans[i] << endl;
    }
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(M);
    std::vector<long long> B(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    solve(N, M, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 13628