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

int main()
{
	ios::sync_with_stdio(false);
	
	int n,k,a;
	int d[10];
	cin>>n>>k;
	
	for(int i=0;i<10;i++)
		d[i]=true;
	for(int i=0;i<k;i++)
	{
		cin>>a;
		d[a]=false;
	}
	
	while(true)
	{
		a=n;
		while(true)
		{
			if(a==0)
			{
				cout<<n<<endl;
				return 0;
			}
			if(d[a%10]==false)
				break;
			a=a/10;
		}
		n++;
	}
	
	return 0;
}

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

int main() {
  int64_t n,k;

  int64_t mi;

  cin >> n >> k;

  if(k == 1){
    cout << 0 << endl;
    return 0;
  }

  int64_t div = n/k;

  n = n - div*k;

  if(n > abs(n-k)){
    cout << abs(n-k) << endl;
  }else{
    cout << n << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0,(i##_len)=(n);(i)<(i##_len);(i)++)
#define rep2(i,a,b) for(ll (i)=(a),(i##_len)=(b);(i)<=(i##_len);(i++))
#define rrep(i,n) ll(i)=(n);ll now=-1;while((i)--&&(now++||1))
#define Yes(n) cout<<((n)?Yes:No)<<"\n"
#define vll vector<ll>
#define pb push_back
using namespace std;
using ll = long long;

static inline void ignore_ret(int x) {}
template<class T> bool chmax(T&a,const T&b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T&a,const T&b){if(a>b){a=b;return true;}return false;}
template<class T> T abs(T x){return max(x,-x);}
template<class T> T gcd_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=gcd(r,v.at(i));return r;}
template<class T> T lcm(T m,T n) {return m*n/gcd(m,n);}
template<class T> T lcm_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=lcm<T>(r,v.at(i));return r;}
template<class T> T factorial(T n){if(n==0)return 1;T r=1;for(T i=2;i<=n;i++)r*=i;return r;}
template<class T> T nCr(T n,T k){return factorial<T>(n)/(factorial<T>(k)*factorial<T>(n-k));}
template<class T> T dot_product(vector<T>u,vector<T>v){T r=0;for(T i=0;i<u.size();i++)r+=u.at(i)*v.at(i);return r;}
template<class T> T sum(vector<T>v){return reduce(all(v),0LL);}

// Template ends here

void solve(ll N, vector<ll> P, vector<ll> Q){
    P.pop_back(); Q.pop_back();
    ll a = 0, b = 0;
    rep(i, N - 1) {
        a += factorial(N - i - 1) * (P.at(i) - 1);
        b += factorial(N - i - 1) * (Q.at(i) - 1);
        rep2(j, i + 1, N - 2) {
            if (P.at(j) > P.at(i)) P.at(j)--;
            if (Q.at(j) > Q.at(i)) Q.at(j)--;
        }
    }
    cout << abs(a - b) << "\n";
}

int main() {
    ll N;
    ignore_ret(scanf("%lld",&N));
    vector<ll> P(N);
    for(int i = 0 ; i < N ; i++){
        ignore_ret(scanf("%lld",&P[i]));
    }
    vector<ll> Q(N);
    for(int i = 0 ; i < N ; i++){
        ignore_ret(scanf("%lld",&Q[i]));
    }
    solve(N, move(P), move(Q));
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

class SCC {
public:
	ll V;
	vector<vector<ll>> G;
	vector<vector<ll>> rG;
	vector<ll> group;
	vector<ll> List;
	vector<int> visited;
	SCC(ll V) :V(V) {
		G.resize(V); rG.resize(V);
		group.assign(V, -1);
	}

	void add_edge(ll u, ll v) {
		G[u].emplace_back(v);
		rG[v].emplace_back(u);
	}

	void dfs1(ll u) {
		visited[u] = 1;
		for (auto next : G[u]) {
			if (visited[next] == 1)continue;
			dfs1(next);
		}
		List.emplace_back(u);
	}

	void dfs2(ll u, ll group_num) {
		visited[u] = 1;
		group[u] = group_num;
		for (auto next : rG[u]) {
			if (visited[next] == 1)continue;
			dfs2(next, group_num);
		}
	}

	void solve() {
		visited.assign(V, 0);
		for (int i = 0; i < V;i++) {
			if (visited[i] == 1)continue;
			dfs1(i);
		}

		reverse(List.begin(), List.end());

		visited.assign(V, 0);
		ll group_num = 0;
		for (auto v : List) {
			if (visited[v] == 1)continue;
			dfs2(v, group_num);
			group_num++;
		}
	}

	bool same(ll u, ll v) {
		return group[u] == group[v];
	}
};

int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
	ll V, E; cin >> V >> E;
	SCC scc(V);
	for (int i = 0; i < E;i++) {
		ll s, t; cin >> s >> t;
		scc.add_edge(s, t);
	}

	scc.solve();

	ll Q; cin >> Q;
	for (int i = 0; i < Q;i++) {
		ll s, t; cin >> s >> t;
		cout << scc.same(s, t) << endl;
	}
	return 0;
}

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

int main() {
  int N; cin >> N;
  vector<int> W(N);
  for (int i = 0; i < N; ++i) {
    cin >> W[i];
  }
  int ans = 1e9;
  
  for (int i = 1; i < N; ++i) {
    int l = 0, r = 0;
    for (int j = 0; j < i; ++j) l += W[j];
    for (int j = i; j < N; ++j) r += W[j];
    ans = min(ans, abs(l-r));
  }
  cout << ans << endl;
  
  return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll N;
ll L[4000];

void input() {
    cin >> N;
    for(int i = 1; i <= N; i++) cin >> L[i];
}

void solve() {
    input();
    vector<ll> v(N);
    for(int i = 0; i < N; i++) v[i] = L[i+1];
    sort(v.begin(), v.end());
//    for(auto x:v)
//    cout<<x<<" ";
//    cout<<endl;
    ll ans = 0;
    
    
    for(ll mid=0;mid<N;mid++){
        for(ll low=0;low<mid;low++) {
            auto itr = lower_bound(v.begin(), v.end(), v[mid] + v[low]);
            ll ng = distance(itr, v.end());
            ans += (N - 1 - mid) - ng;
            //cerr << v[mid] + v[low] << " " << ng << " " << (N-1-mid)-ng << endl;
        }
    }
    cout << ans << endl;
    return;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    lint N;
    cin >> N;
    vec<lint> a_list(N);
    range(i, 0, N) cin >> a_list.at(i);
    sort(a_list.begin(), a_list.end());
    cout << a_list.at(N - 1) - a_list.at(0) << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)    for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define rrep(i, n)   for(int i=(n-1); i>=0; --i)
#define all(v)       v.begin(), v.end()
#define rall(v)      v.rbegin(), v.rend()
#define int          long long
template<typename T>
using vv  = vector<vector<T>>;
using vi  = vector<int>;
using vvi = vector<vector<int>>;
using P   = pair<int, int>;
using ll  = long long;
constexpr ll INF = 1LL << 60;
class Prime{
public:
    int n;
    vector<int> factor, primes;    
    // エラストテネスの篩
    Prime(int n=100000) : n(n), factor(n+1){
        factor[0] = factor[1] = -1;
        for(int i=2; i <= n; ++i){
            if(factor[i]){
                continue;
            }
            primes.push_back(i);
            factor[i] = i;
            for(int j = i*i; j <= n; j += i){
                if(!factor[j]){
                    factor[j] = i;
                }
            }
        }
    }
    // 素数判定
    bool is_prime(int x){
        return factor[x] == x;
    }
    // 約数列挙
    bool factorList(vi &dic, int x){
        if(dic[x] > 1){
            return true;
        }
        for(int i = 2; i * i <= x; ++i){
            if(x % i == 0){
                if(dic[i] || dic[x / i]){
                    return true;
                }
            }
        }
        return false;
    }
};

signed main(){


    int n;
    cin >> n;
    vector<int> a(n);
    vi dic(1e6+1);
    rep(i, n){
        cin >> a[i];
        dic[a[i]]++;
    }

    sort(all(a));
    int ans = 0;
    vi arr(1e6+1);
    rep(i, n){
        int x = a[i];
        if(dic[x] == 1 && !arr[x]){
            ans++;
        }
        if(arr[x]){
            continue;
        }
        for(int i = x; i <= 1e6; i += x){
            arr[i] = 1;
        }
    }
    cout << ans << endl;

    return 0;
}



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

int main() {
  char* line1;
  char* line2;
  int i;
  int n;
  int cnt;
  line1 = (char*)malloc(sizeof(char)*200005);
  line2 = (char*)malloc(sizeof(char)*200005);
  fgets(line1, 200005, stdin);
  fgets(line2, 200005, stdin);
  n = strlen(line1);
  cnt = 0;
  for ( i = 0; i < n; i++ ) {
    if (line1[i] != line2[i]) {
      cnt++;
    }
  }
  printf("%d\n", cnt);
  free(line1);
  free(line2);
  return 0;
}



Measured memory_bytes: 1768
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

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

    cin>>n>>m;

    for(int i=0;i<m;i++){
        cin>>x;
        sum+=x;
    }

    if(n>=sum)cout<<n-sum<<"\n";
    else cout<<"-1\n";

    return 0;
}


Measured memory_bytes: 3692
int main(void)
{
    long i, xx, yy, j;
	long x[3000];
	long y[3000];
	i = 0;
	do{
		scanf("%d%d", &x[i], &y[i]);
		xx = x[i];
		yy = y[i];
		i++;
	} while (xx != 0 || yy != 0);
	i = i - 1;
	for (j = 0; j < i; j++){
		if (x[j] <= y[j]) printf("%d %d\n", x[j], y[j]);
		else			  printf("%d %d\n", y[j], x[j]);
		}
	return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#define IF(i) if(i%400==0|(i%100&&i%4==0))
using namespace std;
int c(int y,int m,int d)
{
	int ct=(m-1)*30+d;
	for(int i=1;i<m;i++) if(!(i==2|i==4|i==6|i==9|i==11)) ct++;
	if(m>2){
		IF(y) ct--;
		else ct-=2;
	}
	return(ct);
}
int main()
{
	int i;
	int y1,m1,d1,y2,m2,d2;
	while (cin>>y1>>m1>>d1>>y2>>m2>>d2){
		if(y1<0) break;
		int o=(y2-y1)*365;
		for (i=y1;i<y2;i++) IF(i) o+=1;
		o = o - c(y1,m1,d1) + c(y2,m2,d2);
		cout<<o<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
import java.io.IOException;
import java.util.NoSuchElementException;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        String S = sc.next();
        String T = sc.next();
        String r = "No";
        T = T.substring(0,T.length()-1);
        if (S.equals(T)) r = "Yes";
        System.out.println(r);
    }
}

class FastScanner {
    private final java.io.InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) return buffer[ptr++];
        else return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    private void skipUnprintable() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
    }

    public boolean hasNext() {
        skipUnprintable();
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return (minus ? -n : n);
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return (int) (minus ? -n : n);
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
}

Measured memory_bytes: 25304
def test():

	while True:
		i = list(map(int,input().split()))
	
		H = i[0]
		W = i[1]

		if H == 0 and W == 0:
			break

		for i in range(H):
			for j in range(W):
				if i == 0 or i == H-1 or j == 0 or j == W-1:
					print("#",end="")
				else:
					print(".",end="")
			print()

		print()

if __name__ == "__main__":
	test()


Measured memory_bytes: 7012
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():
    n = I()
    s = sum([int(c) for c in str(n)])
    if n % s == 0:
        return 'Yes'

    return 'No'



print(main())




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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main() {
    int n,a,b;
    cin>>n>>a>>b;
    vector<int> one,two,three;
    rep(i,0,n){
        int p;
        cin>>p;
        if(p<=a)one.push_back(p);
        else if(a<p&&p<=b)two.push_back(p);
        else three.push_back(p);
    }
    cout<<min({one.size(),two.size(),three.size()})<<endl;
    return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

int main(){
    
    int n;

    cin >> n;

    vector<int> v;

    for(int i = 0; i < n; i++){
        int tmp;
        cin >> tmp;
        v.emplace_back(tmp);
    }

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

    cout << abs(v.front() - v.back()) << endl;
    
    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)

	ans := 0
	for i := 1; i <= N; i += 2 {
		cnt := 0
		for j := 1; j <= N; j += 2 {
			if i%j == 0 {
				cnt++
			}
		}
		if cnt == 8 {
			ans++
		}
	}

	fmt.Println(ans)
}

Measured memory_bytes: 512
//2017-5-6 20:52
//2017-5-6 20:54
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
const int MaxN = 1e5;
int cnt[MaxN + 5];
int n, m;
int main(){
	while(~scanf("%d%d", &n, &m)){
		for(int i = 1; i <= m; i++){
			int u, v;
			scanf("%d %d", &u, &v);
			cnt[u]++, cnt[v]++;
		}
		bool flag = true;
		for(int i = 1; i <= n; i++)
			if(cnt[i] & 1) flag = false;
		if(flag) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}


Measured memory_bytes: 512
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<utility>
#include<queue>
#include<cmath>
#include<cstdio>
using namespace std;
#define REP(i, a,b) for(i=a;i<b;i++) 
#define REP1(i,b,a) for(i=b-1;i>=a;i--)
#define output(x) cout<<x<<endl;
#define pb(x) push_back(x);
typedef long long int ll;


const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i ;
	}

}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	if (k == 0) return 1;
	return n * COM(n - 1, k - 1) / k;
}



int main() {
	COMinit();
	ll i, j, k, l, m, n, sum, flag, cc,N,Ma,Mb,X,A,B;
	sum = 0;
	flag = 0;
	cin >> N >>X;
	ll temp,ans;
	ans = 0;
	if (2*X==N) {
		ans = N * 3 / 2;
		output(ans);
		return 0;
	}
	if (X > N / 2) {
	
		X = N - X;
	}
	ans += N;
	N = N - X;
	
	while (N%X != 0) {
		temp = X;
		ans += X * 2 *(N / X);
		X = N % X;
		N = temp;
		
	}
	ans += X * 2 * N / X;
	ans -= X;
	output(ans);
	
	return 0;
}

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


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(int x = (l);x<=(u);x++)
#define RREP(x,l,u) for(int x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 100010;
const int mod = 1e9+7;
const int MAX = 1000000010;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

int X,n,Q;

int R[maxn],c[maxn],l[maxn],r[maxn];

void Work(){
	read(Q);
	while(Q--){
		int t,a;
		read(t,a);
		int x=upper_bound(R+1,R+n+1,t)-R-1;
		int ans=a+c[x];
		ans=min(ans,r[x]);ans=max(ans,l[x]);
		if(x&1)ans+=t-R[x];else ans-=t-R[x];
		ans=min(ans,X);ans=max(ans,0);
		iout(ans);
	}
}

void Init(){
	read(X);
	read(n);
	REP(i,1,n)read(R[i]);
	l[0]=0;r[0]=X;c[0]=0;
	REP(i,1,n){
		int t;
		if(i&1)t=-1;else t=1;
		t*=(R[i]-R[i-1]);
		c[i]=c[i-1]+t;//c[i]=min(c[i],X);c[i]=max(c[i],-X);
		l[i]=l[i-1]+t;l[i]=min(l[i],X);l[i]=max(l[i],0);
		r[i]=r[i-1]+t;r[i]=min(r[i],X);r[i]=max(r[i],0);
	}
}

int main(){
	Init();
	Work();
	return 0;
}


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

using namespace std;

int main(){
    string x,y;
    cin >> x >> y;
    if(x[0]>y[0])cout << ">" << endl;
    else if(x[0]<y[0])cout << "<" << endl;
    else cout << "=" << endl;
    return 0;
}

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

int main(){
    int N, p, q;
    cin >> N;
	
    vector<int> a(N), b(N), per(N);
    for(int i=0; i<N; i++){
	cin >> a[i] ;
	per[i]=i+1;
    }
    for(int i=0; i<N; i++){
	cin >> b[i] ;
	per[i]=i+1;
    }

    int i=0;
    do {

	if(a==per)
	    p=i;
	if(b==per)
	    q=i;
	
	i++;
    }while (next_permutation(per.begin(), per.end()));

    cout << abs(p-q) << endl;
}



Measured memory_bytes: 764
#pragma GCC optimize(3)
#include <bits/stdc++.h>
#include<unordered_set>
using namespace std;

namespace _ {
	bool rEOF = 1;//为0表示文件结尾
	inline char nc() {
		static char buf[100000], *p1 = buf, *p2 = buf;
		return p1 == p2 && rEOF && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? (rEOF = 0, EOF) : *p1++;
	}
	template<class _T>
	inline bool read(_T &num) {
		char c = nc(), f = 1; num = 0;
		while (c<'0' || c>'9')c == '-' && (f = -1), c = nc();
		while (c >= '0'&&c <= '9')num = num * 10 + c - '0', c = nc();
		return (bool)(num *= f);
	}
	inline bool need(char &c) { return c >= 'a'&&c <= 'z' || c >= '0'&&c <= '9' || c >= 'A'&&c <= 'Z'; }//读入的字符范围
	inline bool read_str(char *a) {
		while ((*a = nc()) && need(*a) && rEOF)++a;
		*a = '\0'; return rEOF;
	}
}using namespace _;

void file(bool opt)
{
	if (opt&&fopen("in.txt", "r"))
	{
		freopen("in.txt", "r", stdin);
		//freopen("out.txt", "w", stdout);
	}
}

int n, m;
struct node {
	long long a, b;
}p[1000000+5];

priority_queue<long long>que;

int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++)
		scanf("%lld%lld", &p[i].a, &p[i].b);
	sort(p + 1, p + 1 + n, [](node a, node b) {
		return a.a < b.a;
	});
	long long ans = 0;
	int s = 0;
	for (int i = 1; i <= m; i++)
	{
		while (s + 1 <= n && p[s + 1].a <= i)s++, que.push(p[s].b);
		if (!que.empty())
		{
			ans += que.top();
			que.pop();
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2936
K = int(input())

L = [1,2,3,4,5,6,7,8,9]

def a(b):
    if b > 3234566667:
        return
    sb = str(b)
    h = int(sb[-1])
    for i in range(0, 10):
        if abs(i-h) <= 1:
            k = int(str(b) + str(i))
            L.append(k)
            a(k)

for i in range(1, 10):
    a(i)
L = sorted(L)

print(L[K-1])

Measured memory_bytes: 18248
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <unordered_map>
using namespace std;


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

Measured memory_bytes: 640
N = int(input())
stones = [int(i) for i in input().split()]

dp = [2e9 for i in range(N)]
dp[0] = 0
for i in range(N):
    if i+1 < N: dp[i+1] = min(abs(stones[i]-stones[i+1])+dp[i], dp[i+1])
    if i+2 < N: dp[i+2] = min(abs(stones[i]-stones[i+2])+dp[i], dp[i+2])

print(dp[N-1])

Measured memory_bytes: 13980
#include<stdio.h>
#include<math.h>
int main(void){
	double x[101],y[101],sum,max;
	int n,i;
	scanf("%d",&n);
	for(i=0;i<n;i++) scanf("%lf",&x[i]);
	for(i=0;i<n;i++) scanf("%lf",&y[i]);
	for(i=0,sum=0;i<n;i++) sum+=fabs(x[i]-y[i]);
	printf("%.8lf\n",sum);
	for(i=0,sum=0;i<n;i++) sum+=pow(x[i]-y[i],2);
	printf("%.8lf\n",sqrt(sum));
	for(i=0,sum=0;i<n;i++) sum+=pow(fabs(x[i]-y[i]),3);
	printf("%.8lf\n",pow(sum,1.0/3));
	for(i=0,max=0;i<n;i++){
		if(max<fabs(x[i]-y[i])) max=fabs(x[i]-y[i]);
	}
	printf("%.8lf\n",max);
	return 0;
}

Measured memory_bytes: 720
/*input
6 15
6 5
5 6
6 4
6 6
3 5
7 2
*/
 
 
#include <bits/stdc++.h>
 
using namespace std;
 
#define ld long double
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vpll vector < pair<long long,long long> >
#define fill(a,val)  memset(a,val, sizeof (a))
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define mp make_pair
#define pb push_back
#define f first
#define se second
#define all(cont) cont.begin(), cont.end()
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MAX   1e9
#define MIN  -1e9
typedef map<long long int, long long int> mpi;
typedef set<long long int> seti;
typedef multiset<long long int> mseti;
typedef priority_queue<long long int> pq;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i, n)    for(long long int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define repn(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define PI 3.14159265
#define dbg(x) cerr << "\n" << (#x) << " = " << (x) << endl ;
//#define cerr if(false)cerr
  
struct node{
    ll val;
};
struct Interval {int start, end;};
bool compare(struct node n1, struct node n2) {
    return (n1.val < n2.val);
}
 
 
 ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 











int main() 
{
	ll N, W; cin>>N>>W;
	vector <ll> dp(W+1,0);

	repA(i,1,N){
		ll wt, value; cin>>wt>>value;
		repD(j,W-wt,0){
			dp[j + wt] = max(dp[j + wt] , dp[j] + value);
		}
	}
	cout<<dp[W]<<endl;
    return 0;  
}



















 

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

using namespace std;

using ll = long long;

struct Point {
   int x, y;
   Point(int x = 0, int y = 0) :
      x(x), y(y) {}
   bool operator < (const Point &p) const {
      return x < p.x || (x == p.x && y < p.y);
   }
   Point operator + (const Point &p) const {
      return Point(x + p.x, y + p.y);
   }
   Point operator - (const Point &p) const {
      return Point(x - p.x, y - p.y);
   }
   ll operator * (const Point &p) const {
      return (ll) x * p.y - (ll) y * p.x;
   }
   ll norm() {
      return (ll) x * x + (ll) y * y;
   }
};

void fix(vector<Point> &ps) {
   int ad = min_element(ps.begin(), ps.end()) - ps.begin();
   vector<Point> nps;
   int sz = ps.size();
   for (int i = 0; i < sz; ++i) {
      nps.emplace_back(ps[(i + ad) % sz]);
   }
   ps = nps;
}

vector<Point> minkowski(vector<vector<Point>> pss) {
   vector<Point> ans(1, Point());
   vector<Point> go;
   for (auto &ps : pss) {
      fix(ps);
      ans[0] = ans[0] + ps[0];
      int sz = ps.size();
      for (int i = 0; i < sz; ++i) {
         go.emplace_back(ps[(i + 1) % sz] - ps[i]);
      }
   }
   sort(go.begin(), go.end(), [&](Point p, Point q) {
      bool fp = p < Point();
      bool fq = q < Point();
      if (fp ^ fq) {
         return fq;
      } else {
         return p * q < 0;
      }
   });
   for (auto p : go) {
      ans.emplace_back(ans.back() + p);
   }
   return ans;
}

int main() {
   ios_base::sync_with_stdio(false);
   int n;
   cin >> n;
   vector<vector<Point>> pss;
   while (n--) {
      int x, y;
      cin >> x >> y;
      if (!x && !y) continue;
      pss.emplace_back(vector<Point> {{0, 0}, {x, y}});
   }
   vector<Point> ps = minkowski(pss);
   ll ans = 0;
   for (auto p : ps) {
      ans = max(ans, p.norm());
   }
   cout << fixed << setprecision(20) << sqrtl(ans) << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,m;
const int maxn=1e5+100;
int a[maxn],b[maxn],c[maxn];
int d[maxn];
int maxv=0;
void work(int x,int y,int z){
	for (int i=1;i<=n;i++){
		d[i]=x*a[i]+y*b[i]+z*c[i];
	}
	sort(d+1,d+1+n);
	int s=0;
	for (int i=n;i>=n-m+1;i--) s+=d[i];
	maxv=max(maxv,s);
}
signed main(){
	cin >> n >> m;
	for (int i=1;i<=n;i++){
		cin >> a[i] >> b[i] >> c[i];
	}
	for (int i=-1;i<=1;i+=2){
		for (int j=-1;j<=1;j+=2){
			for (int k=-1;k<=1;k+=2){
				work(i,j,k);
			}
		}
	}
	cout << maxv << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int,input().split()))

def solve(N, H):
	
	a = 0
	b = abs(H[0] - H[1])
	
	for i in range(2, N):
		temp = b;
		b = min(b + abs(H[i-1]-H[i]), a + abs(H[i-2]-H[i]));
		a = temp
		
	return b

print(solve(N, H))



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

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	
	int n, m;
	cin >> n >> m;
	
	vector<bool> f(n);
	vector<ll> pen(n);
	
	for(int i = 0; i < m; i++){
		int p;
		string s;
		cin >> p >> s;
		p--;
		
		if(s == "AC"){
			f[p] = true;
		}
		else{
			if(!f[p])
				pen[p]++;
		}
		
	}
	
	ll s1 = 0, s2 = 0;
	for(int i = 0; i < n; i++){
		if(f[i]){
			s1++;
			s2 += pen[i];
		}
	}
	
	cout << s1 << " " << s2 << endl;

	return 0;
}


Measured memory_bytes: 1024
n = int(input())
S = [0] * 13
H = [0] * 13
C = [0] * 13
D = [0] * 13

for i in range(n):
    mark, num = input().split()
    num = int(num)
    if mark == 'S':
        S[num-1] = 1
    elif mark == 'H':
        H[num-1] = 1
    elif mark == 'C':
        C[num-1] = 1
    elif mark == 'D':
        D[num-1] = 1

for i in range(13):
    if S[i] == 0:
        print('S {0}' .format(i+1))
for i in range(13):
    if H[i] == 0:
        print('H {0}' .format(i+1))
for i in range(13):
    if C[i] == 0:
        print('C {0}' .format(i+1))
for i in range(13):
    if D[i] == 0:
        print('D {0}' .format(i+1))


Measured memory_bytes: 5608
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<unordered_map>

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

unordered_map<long long int, vector<long long int>> E;
unordered_map<long long int, long long int> dist;

long long int MUL = 1e9;

int main(){
  int N, M;
  cin >> N >> M;
	for(int i = 0; i < M; i++){
		long long int p, q, c;
		cin >> p >> q >> c;
		long long int pos1 = c * MUL + p, pos2 = c * MUL + q;
		E[p].push_back(pos1);
		E[pos1].push_back(p);
		E[q].push_back(pos2);
		E[pos2].push_back(q);
		E[pos1].push_back(pos2);
		E[pos2].push_back(pos1);
	}
	deque<P> que;
	que.push_back(P(1, 0));
	while(que.size() > 0){
		P p = que.front();
		que.pop_front();
		long long int pos = p.first, cost = p.second;
		if(dist.find(pos) != dist.end()){
			continue;
		}
		dist[pos] = cost;
		for(long long int to : E[pos]){
			if(pos < MUL){
				que.push_back(P(to, cost + 1));
			}else{
				que.push_front(P(to, cost));
			}
		}
	}
	if(dist.find(N) == dist.end()){
		cout << -1 << endl;
	}else{
		cout << dist[N] << endl;
	}
  return 0;
}


Measured memory_bytes: 66676
h,w = list(map(int,input().split()))
sx, sy = list(map(int,input().split()))
gx, gy = list(map(int,input().split()))
maze = [list(input()) for _ in range(h)]
sx -= 1; sy -= 1; gx -= 1; gy -= 1

mx = [0,1,0,-1]
my = [1,0,-1,0]
mazemap = [[10**9]*w for _ in range(h)]
from collections import deque
q = deque()
nq = deque()
q.append([sx,sy,0])

while q or nq:
    x,y,z = q.popleft() if q else nq.popleft()
    if x == gx and y == gy:
        ans = z
        break
    for i in range(4):
        nx = x + mx[i]; ny = y + my[i]
        if 0 <= nx < h and 0 <= ny < w and maze[nx][ny] != "#" and mazemap[nx][ny] > z:
            q.append([nx,ny,z])
            mazemap[nx][ny] = z
        for i in range(-2,3):
            for j in range(-2,3):
                nx = x+i; ny = y+j
                if 0 <= nx < h and 0 <= ny < w and maze[nx][ny] != "#" and mazemap[nx][ny] > z+1:
                    nq.append([nx,ny,z+1])
                    mazemap[nx][ny] = z+1
else:
    ans = -1

print(ans)

Measured memory_bytes: 159748
/* In the name of Allah */

#include<bits/stdc++.h>
using namespace std;

int main(){
	
	int  c = 0;
	string a, b;
	cin >> a >> b;
	int n = a.size();
	for(int i = 0; i < n; i++){
		if(a[i] != b[i]){
			c++;
		}
	}
cout << c;	
	return 0;
}

Measured memory_bytes: 3844
/*１つの整数 x を読み込んで、x の３乗を計算し結果を出力するプログラム*/

#include <stdio.h>

int main(){
    
    int x;
    
    do{
        scanf("%d",&x);
    }while(x<1 || x>100); /*1 ≤ x ≤ 100を満たすまで繰り返される*/
    
    printf("%d\n",x*x*x);
    
    return 0;
}


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

#define dbg(x) cerr<<#x": "<<x<<"\n"
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"
#define DMAX 1

using namespace std;

long long n, a, b, v[100008];

bool check(long long k)
{
	long long ans = 0;
	long long A = a-b;
	for(long long i=1;i<=n;i++)
		if(v[i] > k*b)
			ans += (v[i] - k*b + A-1)/A;
	//dbg(ans);
	return ans <= 1LL*k;
}

long long cb(long long l, long long r)
{
	if(l == r) 
		return l;
	long long m = (l+r)/2;
	if(check(m)) return cb(l, m);
	else return cb(m+1, r);
}

int main()
{
	cin >> n;
	cin >> a >> b;
	for(long long i = 1; i <= n; i++)
	{
		cin >> v[i];
	}
	//dbg(check(80000000));
	//dbg(check(80000001));
	cout << cb(1, 1000000000);

}


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

namespace AtCoder
{
    class Abc166C
    {
        public static void Main()
        {
            var nm = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            var n = nm[0];
            var m = nm[1];
            var h = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

            var check = new bool[n];

            for (int i = 0; i < m; i++)
            {
                var ab = Console.ReadLine().Split(' ').Select(j => int.Parse(j) - 1).ToArray();
                if (h[ab[0]] <= h[ab[1]])
                    check[ab[0]] = true;
                if (h[ab[0]] >= h[ab[1]])
                    check[ab[1]] = true;
            }
            Console.WriteLine(check.Count(i => !i));
        }
    }
}

Measured memory_bytes: 49260
#include <iostream>
using namespace std;
int main()
{
    int m, n;
    while(true)
    {
        cin>>m>>n;
        if(m==0&&n==0)break;
        for(int i=0;i<m;i++)
        {
            for(int j=0;j<n;j++)
                cout<<'#';
            cout<<endl;
        }
        cout<<endl;
    }
}


Measured memory_bytes: 3084
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

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

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}


int main()
{
	ll X, Y;
	cin >> X;

	Y = 100;
	ll cnt = 0;
	while (X > Y)
	{
		Y += Y / 100;
		++cnt;
	}

	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int hibo[50];

int fibo(int i)
{	
	if(i==0||i==1)return hibo[i] = 1;
	if(hibo[i]!=0)return hibo[i];
	return hibo[i] = fibo(i-1)+fibo(i-2);
}

int main()
{
	int n;cin >> n;
	cout<<fibo(n)<<endl;
	return 0;
}


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

using namespace std;
vector<long long> a;
int n, k;
long long s, x;
unordered_set<int> m;

int main() {
	cin >> k;
	int i = 1;
	m.insert(k);
	while (true) {
		i++;
		if (k%2) k = 3*k+1; else k = k/2;
		if (m.find(k) != m.end()) {
			cout << i;
			break;
		}
		m.insert(k);
	}

}



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

#define pos first
#define cnt second.first
#define num second.second
#define MP make_pair

const int MaxN = 510;
int n, x[MaxN], a[MaxN * MaxN];
pair <int, pair <int, int>> c[MaxN];
int ind;

int main() {
    ios_base::sync_with_stdio(false);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> x[i];
        x[i]--;
        a[x[i]] = i;
        c[i - 1] = MP(x[i], MP(i - 1, i));
    }
    sort(c, c + n);
    ind = 0;
    for (int i = 0; i < n; i++) {
        for (; ind < c[i].pos && c[i].cnt > 0; ind++) {
            if (a[ind] == 0) {
                a[ind] = c[i].num;
                c[i].cnt--;
            }
        }
        if (c[i].cnt > 0) {
            cout << "No";
            return 0;
        }
    }
    for (int i = 1; i <= n; i++)
        c[i - 1] = MP(x[i], MP(n - i, i));
    sort(c, c + n);
    ind = n*n - 1;
    for (int i = n - 1; i >= 0; i--) {
        for (; ind > c[i].pos && c[i].cnt > 0; ind--) {
            if (a[ind] == 0) {
                a[ind] = c[i].num;
                c[i].cnt--;
            }
        }
        if (c[i].cnt > 0) {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes\n";
    for (int i = 0; i < n * n; i++)
        cout << a[i] << " ";
    return 0;
}


Measured memory_bytes: 2176
#include <stdio.h>

int main(void)
{
    int i, n;
	int ls[10];
    int sum = 0;
  
    scanf("%d", &n);
  
    for(i = 0; i < n; ++i){
        scanf("%d", &ls[i]);
        sum += ls[i];
    }
    
    for(i = 0; i < n; ++i)
        if(sum <= ls[i] * 2)
            break;
    
    if(i == n)
        printf("Yes");
    else
        printf("No");
      
    return 0;
}

Measured memory_bytes: 128
/* Small, Large, or Equal */
#include <stdio.h>

int main()
{
    int a,b;
    scanf("%d %d", &a,&b);

    if(a < b){
        printf("a < b\n");
    }
    else if(a > b){
        printf("a > b\n");
    }
    else{
        printf("a == b\n");
    }
    return 0;
}


Measured memory_bytes: 2040
n,m = [int(x) for x in input().split(' ')]
out = [0 for x in range(n)]
for i in range(m):
    a, b = [int(x) for x in input().split(' ')]
    out[a-1] += 1
    out[b-1] += 1
for i in out:
    print(i)


Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
   int A,B; cin >> A >> B;
   int ans = A*B - A - B + 1;
   cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define pi acos(-1)
#define pii pair<int,int>
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int MAXN = 1e4 + 10;
const int MAXM = 2e6 + 10;
const ll mod = 1e9 + 7;

ll a[MAXN],b[MAXN];
ll numa[2],numb[2];

int main()
{
#ifdef local
    freopen("data.txt","r",stdin);
//    freopen("data.txt","w",stdout);
#endif
    int n;
    scanf("%d",&n);
    ll suma = 0, sumb = 0;
    for(int i=0; i<n; i++) {
        scanf("%lld",&a[i]);
        suma += a[i];
    }
    for(int i=0; i<n; i++) {
        scanf("%lld",&b[i]);
        sumb += b[i];
    }
    if(suma > sumb) {
        puts("No");
        return 0;
    }
    else if(suma == sumb) {
        for(int i=0; i<n; i++) {
            if(a[i] != b[i]) {
                puts("No");
                return 0;
            }
        }
        puts("Yes");
    }
    else if(suma < sumb){
        ll num = sumb - suma;
        ll cnt1 = 0, cnt2 = 0;
        for(int i=0; i<n; i++) {
            if(a[i] == b[i]) continue;
            else if(a[i] > b[i]) cnt2 += a[i] - b[i];
            else {
                if((b[i] - a[i]) % 2 ==0)
                    cnt1 += (b[i] - a[i]) / 2;
                else {
                    cnt1 += (b[i] - a[i]) / 2 + 1;
                    cnt2 ++;
                }
            }
        }
        if(cnt1 > num || cnt2 >num) puts("No");
        else puts("Yes");
    }
    return 0;
}


Measured memory_bytes: 384
import bisect

s=input()
t=input()
n=len(s)

dic={}
for idx,i in enumerate(s*2):
  if i in dic.keys():
    dic[i].append(idx)
  else:
    dic[i]=[idx]

ans,p=0,-1
for i in t:
  if i not in dic.keys():
    print(-1)
    exit()
  p=dic[i][bisect.bisect_left(dic[i], p+1)]
  if p>=n:
    p-=n
    ans+=n
  
print(ans+p+1)

Measured memory_bytes: 17920
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
int main(){
  int h,w;
  while(cin >> h >> w,h){
    REP(i,h){
      REP(j,w) {
        cout << (!((i&1)^(j&1))?'#':'.');
      }
      puts("");
    }
    puts("");
  }
}


Measured memory_bytes: 3100
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define dump(a) (cerr << (#a) << " = " << (a) << endl)
#define FOR(it,c) for(__typeof((c).begin())it=(c).begin(); it!=(c).end();++it)
#define RFOR(it,c) for(__typeof((c).rbegin())it=(c).rbegin(); it!=(c).rend();++it)
#define exist(c, v) (find((c).begin(), (c).end(), (v)) != (c).end())

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

template<typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << '(' << p.first << ", " << p.second << ')';
	return os;
}

template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	copy(v.begin(), v.end(), ostream_iterator<T>(os, " "));
	return os;
}

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

	int n, k, t, u, v, l;
	scanf("%d %d %d %d %d %d", &n, &k, &t, &u, &v, &l);

	vector<bool> carrot(l, false);
	for(int i = 0; i < n; ++i) {
		int d;
		scanf("%d", &d);
		carrot[d] = true;
	}

	int cnt = 0, num = 0, rest = 0;
	for(int i = 0; i < l; ++i) {
		if(carrot[i])
			++num;

		if((num && !rest) || num > k) {
			rest = t * v;
			--num;
		}

		if(rest) {
			--rest;
			++cnt;
		}
	}

	printf("%.15lf\n", (double)cnt / v + (double)(l - cnt) / u);

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1244
N = int(input())
ans = 0
a = b = ba = 0
for i in range(N):
    s = input()
    ans += s.count("AB")
    aa = s[-1] == "A"
    bb = s[0] == "B"
    if aa and bb:
        if ba:
            ans += 1
        else:
            ba = 1
    elif aa:
        a += 1
    elif bb:
        b += 1
if ba:
    if a > 0:
        a -= 1
        ans += 1
    if b > 0:
        b -= 1
        ans += 1
ans += min(a, b)
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>

int main(void){
    int a,b,c;
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    if(a < b && b < c){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 2028
n = int(input())
a_list = list(map(int, input().split())) # list()を忘れずに

n_division = 0

def odd_detector(a_list):
    is_odd = 0
    for a_i in a_list:
        if a_i % 2 == 1:
            is_odd = 1
            break
    return is_odd

while odd_detector(a_list) == 0:
    a_list = [int(a/2) for a in a_list]
    n_division += 1

print(n_division)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

main() {
    int64_t n, m, l;
    cin >> n >> m >> l;

    vector<vector<pair<int64_t, int64_t>>> links(n);
    for (auto _ : irange(0L, m)) {
        int64_t a, b, c;
        cin >> a >> b >> c;
        if (c > l) {
            continue;
        }

        --a;
        --b;
        links[a].emplace_back(b, c);
        links[b].emplace_back(a, c);
    }

    constexpr auto kInfinity = numeric_limits<int64_t>::max() / 4L;

    vector<vector<int64_t>> dist(n, vector<int64_t>(n, kInfinity));
    for (auto i : irange(0L, n)) {
        dist[i][i] = 0;

        for (auto link : links[i]) {
            dist[i][link.first] = link.second;
        }
    }

    for (auto k : irange(0L, n)) {
        for (auto i : irange(0L, n)) {
            for (auto j : irange(0L, n)) {
                if (dist[i][j] > dist[i][k] + dist[k][j]) {
                    dist[i][j] = dist[i][k] + dist[k][j];
                }
            }
        }
    }

    vector<vector<int64_t>> nums(n, vector<int64_t>(n, kInfinity));
    for (auto i : irange(0L, n)) {
        for (auto j : irange(0L, n)) {
            if (i == j) {
                nums[i][j] = 0;
            } else if (dist[i][j] <= l) {
                nums[i][j] = 1;
            }
        }
    }

    for (auto k : irange(0L, n)) {
        for (auto i : irange(0L, n)) {
            for (auto j : irange(0L, n)) {
                if (nums[i][j] > nums[i][k] + nums[k][j]) {
                    nums[i][j] = nums[i][k] + nums[k][j];
                }
            }
        }
    }

    int64_t q;
    cin >> q;
    for (auto _ : irange(0L, q)) {
        int64_t s, t;
        cin >> s >> t;
        --s;
        --t;

        if (nums[s][t] == kInfinity) {
            cout << -1 << "\n";
        } else {
            assert(s != t);
            cout << nums[s][t] - 1 << "\n";
        }
    }
}

Measured memory_bytes: 4224
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
#include <vector>
using namespace std;

const double PI=acos(-1);

int main(){
    int n, k, l[100] = {0}, sum = 0;
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        cin >> l[i];
        if(l[i] < k - l[i]) sum += l[i]*2;
        else if(l[i] > k - l[i]) sum += (k - l[i])*2;
        else if(l[i] == k-l[i]) sum += l[i]*2;
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256