akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(){
    int k, s, ans=0; cin >> k >> s;
    for(int i = 0; i <= k; i++){
        for(int j = 0; j <= k; j++){
            if(i+j <= s && s-i-j <= k) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define hell1 1e9+7
#define hell2 1e9+9
#define pi 3.1415926535
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define ll long long
#define ld long double 
#define no_of_digits(n) floor(log10(n)) + 1
#define see(x) cout << (#x) << " is " << (x) << endl
#define INF 1e9

using namespace std;

ll mult(ll a,ll b, ll p=hell1){   return ((a%p)*(b%p))%p; }
ll multbig(ll a,ll b,ll mod=hell1){   if(a==0 or b==0) return 0;if(a==1 or b==1) return (a*b)%mod;ll cur=multbig(a,b/2,mod);cur=(2*cur)%mod;if(b%2) cur=(cur+a)%mod;return cur;
}
ll add(ll a, ll b, ll p=hell1){ if(a>=p) a%=p; if(b>=p) b%=p; if(a+b>p) return (a + b)%p; else return a+b;}
ll sub(ll a, ll b, ll p=hell1){return (a%p - b%p + p)%p;}
ll fpow(ll n, ll k, ll p = hell1) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = hell1) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = hell1){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
int isPowerof2(ll x) { return (x && !(x & x-1)); } 
ll log2(ll x) { ll res = 0; while (x >>= 1) res++; return res; } 

// max({a, b, c, d})

vector<ll>adj[200005];
ll update[200005];
ll ans[200005];

int binaryToDecimal(string n) 
{ 
    string num = n; 
    int dec_value = 0; 
  
    // Initializing base value to 1, i.e 2^0 
    int base = 1; 
  
    int len = num.length(); 
    for (int i = len - 1; i >= 0; i--) { 
        if (num[i] == '1') 
            dec_value += base; 
        base = base * 2; 
    } 
  
    return dec_value; 
} 

bool isPerfectSquare(long double x) 
{   
  // Find floating point value of  
  // square root of x. 
  long double sr = sqrt(x); 
  
  // If square root is an integer 
  return ((sr - floor(sr)) == 0); 
} 

int main()
{
    ll n, d;
    cin >> n >> d;

    ld a[n][d];
    for(int i=0;i<n;i++)
        for(int j=0;j<d;j++)
            cin >> a[i][j];

    ll cnt = 0;
    for(int i=0;i<n-1;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            ld ans = 0;

            for(int k=0;k<d;k++)
                ans += pow(a[i][k]-a[j][k], 2);

            // see(ans);

            if(isPerfectSquare(ans)) 
            {
                // cout << ":";
                // see(ans);
                cnt++;
            }
        }
    }

    cout << cnt << "\n";
}




Measured memory_bytes: 6016
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
#include<functional>
#include<cassert>
using namespace std;
#define ll long long
int main(){
    ll A,B;
    cin >> A >> B;
    ll t=2;
    ll sum=0;
    while(t<=2*B){
        sum+=((B+1)/t*t/2+max((B+1)%t-t/2,(ll) 0)-A/t*t/2-max(A%t-t/2,(ll) 0))%2*t/2;  
        t=t*2;
    }
    cout << sum << endl;
    return 0;
}

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

vector<string> r(string in, int max) {
  vector<string> result;

  if (in.size() == max) {
    result.emplace_back(in);
    return result;
  }

  char last = in[in.size() - 1];

  char char_to = 'a';
  for (ll i = 0; i < in.size(); i++) {
    if (in[i] > char_to) {
      char_to = in[i];
    }
  }
  char_to++;

  char cur = 'a';
  for (;;) {
    auto plus = r(in + cur, max);
    for (auto e : plus) {
      result.emplace_back(e);
    }
    if (cur == char_to) {
      break;
    }
    cur += 1;
  }

  // auto plus1 = r(in + last, max);
  // for (auto e : plus1) {
  //   result.emplace_back(e);
  // }

  // auto plus2 = r(in + char(last + 1), max);
  // for (auto e : plus2) {
  //   result.emplace_back(e);
  // }

  // if (last > 'a') {
  //   auto plus3 = r(in + char(last - 1), max);
  //   for (auto e : plus3) {
  //     result.emplace_back(e);
  //   }
  // }

  return result;
}

int main() {
  ll N;
  scanf("%lld", &N);

  vector<string> list = r("a", N);

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

  for (ll i = 0; i < list.size(); i++) {
    cout << list[i] << endl;
  }
}

/*
aaa
abc
abb
acc
*/

Measured memory_bytes: 12312
#include<stdio.h>
signed main(){
int a,b,c,d,e,f,g;
int x[25];
e=0;
scanf("%d %d %d",&a,&b,&c);
	for(d=0;d<10;d++){
	if(e==0){
	x[d]=a*c-b;
	f=a*c-b;
	f=f*a;
	e=1;
}
	else{
	x[d]=f-b;
	g=f-b;
	f=g*a;
}
}
	for(d=0;d<10;d++){
	printf("%d\n",x[d]);
}
return (0);
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <unordered_map>
#include <utility>
#include <set>
#include <bitset>

#define mst(a,b) memset(a,b,sizeof(a))
#define scd(x) scanf("%d", &x)
#define scdd(x,y) scanf("%d%d", &x, &y)
#define scddd(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define eb emplace_back

using namespace std;

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

const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double pi = 2*acos(0.0);
const double eps = 1e-6;
const ll mod = 998244353;
const int N = 1e5 + 10;
const int M = 1e5 + 10;

int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
    //freopen("ans.txt","w",stdout);
#endif
    std::ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n, m;
    scdd(n, m);
    printf("%s\n", abs(n-m) <= 1 ? "Brown": "Alice");
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#define re register
using namespace std;
int n,fa[100002],ans,mxd[100002],dep[100002],u,v,a,b,cnt,son[100002],head[100002];
struct edge{
	int to,next;
}e[200002];
inline void add(re int x,re int y){
	e[++cnt].to=y;
	e[cnt].next=head[x];
	head[x]=cnt;
}
inline void dfs(re int x,re int y){
	fa[x]=y;dep[x]=dep[y]+1;
	for(re int i=head[x];i;i=e[i].next){
		if(e[i].to!=y)dfs(e[i].to,x);
	}
}
inline void dfs1(re int x,re int y){ 
	mxd[x]=dep[x];
	for(re int i=head[x];i;i=e[i].next){
		if(e[i].to!=y&&e[i].to!=son[x]){
			dfs1(e[i].to,x);
			mxd[x]=max(mxd[x],mxd[e[i].to]);
		}
	}
	if(son[x])dfs1(son[x],x);
}
inline void find(re int x){
	if(dep[x]>(dep[v])/2)return;
	ans=max(ans,mxd[x]+dep[v]-2*dep[x]);
	if(son[x])find(son[x]);
}
signed main(){
scanf("%d%d%d",&n,&u,&v);
for(re int i=1;i<n;++i){
	scanf("%d%d",&a,&b);
	add(a,b);
	add(b,a);
}
dfs(u,u);
int tmp=v;
while(tmp!=u)son[fa[tmp]]=tmp,tmp=fa[tmp];
dfs1(u,u);
find(u);
--ans;
printf("%d",ans);
}


Measured memory_bytes: 5504
#include<stdio.h>

int main()
{
  int count = 0;
  int n1, n2;
  int t;
  int s=0, l, m;
  scanf("%d", &n1);
  int arr[n1];
  for(int i = 0; i < n1; i++)
    {
      scanf("%d", &arr[i]);
    }
  scanf("%d", &n2);
  for(int i = 0; i < n2; i++)
    {
      scanf("%d", &t);
      l = n1;
      s = 0;
      while(s <= l)
	{
	  m = (s+l)/2;
	  
	  if(arr[m] == t)
	    {
	      count++;
	      break;
	    }
	  else if(arr[m] > t)
	    {
	      l = m-1;
	    }
	  else
	    {
	      s = m+1;
	    }
	}
    }
  printf("%d\n", count);
}



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

using namespace std;

typedef long long LL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>>  vvvi;

const int inf = 1e9+7;
const LL INF = 1e18+5;
const int mod = 1e9+7;
const int mxN = 1e5+5;
const int mxM = 1e5+5;

int main(){
    #ifndef ONLINE_JUDGE
    freopen("E:\\Coding\\Programming\\input.txt", "r", stdin);
    freopen("E:\\Coding\\Programming\\output.txt", "w", stdout);
    #endif
    int n,k;
    cin>>n>>k;
    vi h(n+1);
    vi dp(n+1);

    for(int i=0;i<n;i++) cin>>h[i];
    dp[0] = 0;
    for(int i=1;i<n;i++){
        dp[i] = inf;
        for(int j=1;j<=k;j++){
            if(i-j>=0)  dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
        }
    }
    cout<<dp[n-1]<<endl;
}

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

int main() {
    string s, t;
    cin >> s >> t;
    int i(0), res(0);
    for(i=0; i < s.length(); i++) {
        if(s[i] != t[i]) res++;
    }
    cout << res;
}

Measured memory_bytes: 3896
use proconio::input;

fn main() {
    input! {
        a: [usize]
    }
    let mut count = [0; 1000001];
    for x in a {
        count[x] += 1;
    }
    let mut ans = 0;
    for i in 1..=1000000 {
        if count[i] == 0 {
            continue;
        }

        if count[i] == 1 {
            ans += 1;
        }

        for j in (0..=1000000).step_by(i) {
            count[j] = 0;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 8984
/*
	考虑有复合环的情况 (点双联通)
	只要每一种颜色的数目相同, 就是同构的 
*/
#include <bits/stdc++.h>
#define N 55
#define M 205

using namespace std;

const int mod = 1e9 + 7;

int n, m, k;
int head[N], nex[M], to[M], cntE;
int dfn[N], low[N], clo;
int sizV[N], sizE[N], bcc[N], cntBcc;

int fac[M + 1], ifac[M + 1];

int top;
pair<int, int> stk[M];

inline int perm(int x, int y) { return 1LL * fac[x] * ifac[x - y] % mod; }
inline int comb(int x, int y) { return 1LL * perm(x, y) * ifac[y] % mod; }
inline int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
inline int fpm(int x, int y) {
	int re = 1;
	while(y) {
		if(y & 1) re = 1LL * x * re % mod;
		x = 1LL * x * x % mod, y >>= 1;
	}
	return re;
}
inline void addE(int u, int v) {
	to[++cntE] = v;
	nex[cntE] = head[u], head[u] = cntE;
}

void dfs(int u, int fa) {
	low[u] = dfn[u] = ++clo;
	for(int i = head[u]; i; i = nex[i]) {
		int v = to[i];
		if(v == fa) continue;
		if(!dfn[v]) {
			stk[++top] = make_pair(u, v);
			dfs(v, u);
			low[u] = min(low[u], low[v]);
			if(dfn[u] <= low[v]) {
				++cntBcc;
				int x, y;
				do {
					x = stk[top].first, y = stk[top].second;
					++sizE[cntBcc];
					if(bcc[x] != cntBcc) bcc[x] = cntBcc, ++sizV[cntBcc];
					if(bcc[y] != cntBcc) bcc[y] = cntBcc, ++sizV[cntBcc];
					--top;
				} while(x != u || y != v);
			}
		} else if(dfn[v] < dfn[u]) {
			stk[++top] = make_pair(u, v);
			low[u] = min(low[u], dfn[v]);
		}
	}
}

int main() {
	scanf("%d %d %d", &n, &m, &k);
	for(int i = 1, u, v; i <= m; ++i) {
		scanf("%d %d", &u, &v);
		addE(u, v), addE(v, u);
	}
	
	for(int i = 1; i <= n; ++i)
		if(!dfn[i])
			dfs(i, i);
	
	fac[0] = 1;
	for(int i = 1; i <= M; ++i) fac[i] = 1LL * i * fac[i - 1] % mod;
	ifac[M] = fpm(fac[M], mod - 2);
	for(int i = M; i; --i) ifac[i - 1] = 1LL * i * ifac[i] % mod;
	
	int ans1 = 1, ans2 = 1, ans3 = 1;
	for(int i = 1; i <= cntBcc; ++i) {
		if(sizE[i] == 1) {
			ans1 = 1LL * ans1 * k % mod;
		} else if(sizE[i] == sizV[i]) { // polya
			int res = 0;
			for(int j = 1; j <= sizE[i]; ++j)
				res = (res + fpm(k, gcd(j, sizE[i]))) % mod;
			res = 1LL * res * fpm(sizE[i], mod - 2) % mod;
			ans2 = 1LL * ans2 * res % mod;
		} else {
			ans3 = 1LL * ans3 * comb(sizE[i] + k - 1, k - 1) % mod;
		}
	}
	
	int ans = 1LL * ans1 * ans2 % mod * ans3 % mod;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#include <bits/stdc++.h>
#include <vector>
int main() {
    int n,k;
    cin>>n>>k;
	string s;
	cin>>s;
	int a[n]={0};
	int count=0;
	for(int i=1;i<n;i++){
	        if(s[i]=='C' && s[i-1]=='A'){
	            count++;
	        }
	        a[i]=count;
	}
	while(k--){
	    int l,r;
	    cin>>l>>r;
	    cout<<a[r-1]-a[l-1]<<"\n";
	}
	
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
constexpr int mod = 1e9 + 7;
int main(){
    int n;
    cin >>n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    vector<long long> pref(n);
    for (int i = 0; i < n; i++) {
        if (i == 0) pref[i] = a[i];
        else pref[i] = pref[i - 1] + a[i];
    }
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        ans += a[i] * ((pref[n - 1] - pref[i]) % mod) % mod;
        ans %= mod;
    }
    cout << ans << "\n";
return 0;
}

Measured memory_bytes: 5480
#define BUG
#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fi first
#define se second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fore(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define fort(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define ford(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#ifdef BUG
#define bug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << ": " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " /";
    __f(comma + 1, args...);
}
#endif

template <class T> bool mini(T& a, T b) { return a > b ? (a = b, 1) : 0; }
template <class T> bool maxi(T& a, T b) { return a < b ? (a = b, 1) : 0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vii> vvii;

const int INF = (int)1e9 + 7;

int main() {
#ifdef LOCAL
    freopen("CP.inp", "r", stdin);
//    freopen("CP.out", "w", stdout);
#endif // LOCAL
    ios_base::sync_with_stdio(0); cin.tie(0);
    int h, w, a, b; cin >> h >> w >> a >> b;
    const int N = 2e5 + 3;
    const ll M = 1e9 + 7;
    auto mpow = [&](ll a, ll b) {
        ll res = 1;
        for (a %= M; b; a = a * a % M, b >>= 1) if (b & 1) res = res * a % M;
        return res;
    };
    vi fac(N), inv(N);
    fac[0] = 1;
    fore(i, 1, N) fac[i] = fac[i - 1] * i % M;
    inv[N - 1] = mpow(fac[N - 1], M - 2);
    ford(i, N - 2, 0) inv[i] = inv[i + 1] * (i + 1) % M;
    auto C = [&](int n, int k) {
        return fac[n] * inv[n - k] % M * inv[k] % M;
    };
    ll ans = 0;
    fort(i, b + 1, w) {
        (ans += C(h - a - 1 + i - 1, i - 1) * C(w - i + a - 1, w - i)) %= M;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3328
use std::io;
use std::collections::VecDeque;

fn main() {
    let mut input = Input::new();
    let x = input.next();
    let mut a = 0;
    for c in x.chars () {
        if c == 'S' {
            a = a + 1;
        }
        if a > 0 && c == 'T' {
            a = a - 1;
        } 
    }
    println!("{}", a * 2);
}

struct Input {
    queue: VecDeque<String>,
}

impl Input {
    fn new() -> Input {
        Input { queue: VecDeque::new() }
    }

    fn next(&mut self) -> String {
        if self.queue.is_empty() {
            let mut line = String::new();
            let _ = io::stdin().read_line(&mut line);
            // line.split_whitespace().map(|x| println!("{}", String::from(x)));
            for x in line.split_whitespace() {
                self.queue.push_back(String::from(x));
            }
        }
        return self.queue.pop_front().unwrap();
    }

    fn next_i64(&mut self) -> i64 {
        return self.next().parse::<i64>().unwrap();
    }
}

Measured memory_bytes: 4352
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
	int r;
	while(cin>>r)
	{
		if(r<1200)
		cout<<"ABC"<<endl;
		else if(r>=1200&&r<2800)
		cout<<"ARC"<<endl;
		else
		cout<<"AGC"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<queue>
#include<set>
#include<ctime>
using namespace std;

#define rep(i,m) for(int i=0;i<m;i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define mm1(x) memset(x,-1,sizeof(x))
#define ms(x,n) memset(x,n,sizeof(x))
#define SORT(x) sort((x).begin(),(x).end())
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

const int INF = 100000000;
const int mod = 1e9 + 7;


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

}

int main() {
	int n; cin >> n;
	cout << (n - 30) / 2 << endl;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    int a, b, c;
    cin >> a;
    cin >> b;
    if (a == 1 && b == 2)
        cout << 3;
    else if (a == 1 && b == 3)
        cout << 2;
    else if (a == 2 && b == 1)
        cout << 3;
    else if (a == 2 && b == 3)
        cout << 1;
    else if (a == 3 && b == 1)
        cout << 2;
    else if (a == 3 && b == 2)
        cout << 1;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
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; }
int main(){
    string s; cin>>s;
    ll n=s.size();
    ll r=0, b=0;
    rep(i,n){
        if(s[i]=='0') r++;
        else b++;
    }
    cout<<2*min(r,b)<<endl;
    return 0;
}

Measured memory_bytes: 512
// 2020-08-16 18:45:04
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<ll, ll>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  ll n, x, d;
  cin >> n >> x >> d;
  if(d == 0) {
    if(x == 0) {
      cout << 1 << '\n';
    } else {
      cout << n+1 << '\n';
    }
    return;
  }
  if(d < 0) {
    x += d * (n-1);
    d = -d;
  }
  map<ll, vector<P> > mp;
  repc(i, n) {
    ll k = i;
    ll l = (k-1) * k / 2;
    ll r = (n-k+n-1) * k / 2;
    ll c = k * x + l * d;
    ll r2 = r - l;
    ll g = (c%d+d)%d;
    ll c2 = (c - g) / d;
    mp[g].emplace_back(P(c2, 1));
    mp[g].emplace_back(P(c2+r2+1, -1));
  }
  ll ans = 0;
  for(auto& p : mp) {
    sort(ALL(p.second));
    ll past = -1e18, cnt = 0;
    for(const auto& e : p.second) {
      ll current, delta;
      tie(current, delta) = e;
      if(cnt > 0) ans += current - past;
      cnt += delta;
      past = current;
    }
  }
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 28608
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())



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

	long long n, m;
	cin >> n >> m;

	if (2*m <= n) {
		cout << 0 << endl;
	}
	else if (2*n <= m) {
		cout << 1 << endl;
	}
	else if (m <= n) {
		cout << 2 << endl;
	}
	else if (2 * n <= m + m - ((n + n - m / 2) - m)) {
		cout << 3 << endl;
	}
	else {
		cout << 4 << endl;
	}


	return 0;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

//vc alp(26) ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//cout<<""<<endl;
int main(){
  int A,B,C,K;cin>>A>>B>>C>>K;
  cout<< A+B+C-max(max(A,B),C)+max(max(A,B),C)*(int )pow(2,K)<<endl;
}	





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F(n) for(in ti=;i<n;++i)

int main()
{
    string s;
    cin >> s;
    int a;
    if(s=="SUN") a=7;
    else if(s=="MON") a=6;
    else if(s=="TUE") a=5;
    else if(s=="WED") a=4;
    else if(s=="THU") a=3;
    else if(s=="FRI") a=2;
    else if(s=="SAT") a=1;
    cout << a << endl;
    return 0;
}

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

public class Main{
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] inStr = br.readLine().split(" ");
        int N = Integer.parseInt(inStr[0]);
        int M = Integer.parseInt(inStr[1]);
        int[][] arrSort = new int[M][3];
        int[][] arr = new int[M][3];
        for (int i = 0; i < M; i++) {
            inStr = br.readLine().split(" ");
            arrSort[i][0] = Integer.parseInt(inStr[0]);
            arrSort[i][1] = Integer.parseInt(inStr[1]);
            arrSort[i][2] = i;
        }
        sortArr(arrSort, new int[]{0, 1});
        int key = 0;
        int index = 0;
        for (int i = 0; i < M; i++) {
            if (key != arrSort[i][0]) {
                index = 1;
            } else {
                index++;
            }
            key = arrSort[i][0];
            arr[i][0] = key;
            arr[i][1] = index;
            arr[i][2] = arrSort[i][2];
        }
//        for (int i = 0; i < M; i++) {
//            System.out.println(arr[i][0] + " " + arr[i][1] + " " + arr[i][2]);
//        }
        sortArr(arr, new int[]{2});
//        for (int i = 0; i < M; i++) {
//            System.out.println(arr[i][0] + " " + arr[i][1] + " " + arr[i][2]);
//        }
        for (int i = 0; i < M; i++) {
            System.out.println(getId(arr[i][0]) + getId(arr[i][1]));
        }
    }

    private static String getId(int num) {
        String str = String.valueOf(num);
        String pNum = "";
        if (str.length() < 6) {
            for (int i = 0; i < 6 - str.length(); i++) {
                pNum += "0";
            }
            pNum += str;
        } else {
            pNum = str;
        }
        return pNum;
    }

    public static void sortArr(int[][] arr, int[] sort) {
        Arrays.sort(arr, (first, second) -> {
            for (int i = 0; i < sort.length; i++) {
                int k = sort[i];
                if (first[k] > second[k]) {
                    return 1;
                } else if (first[k] < second[k]) {
                    return -1;
                } else {
                    continue;
                }
            }

            return 0;
        });
    }
}


Measured memory_bytes: 83648
#encoding:utf-8 No.0101 2014.10.8
n = gets.chomp.to_i
sentence = Array.new(n)
n.times do |i|
  sentence[i] = gets.chomp
  if sentence[i] =~ /Hoshino/
    sentence[i].gsub!(/Hoshino/,"Hoshina")
  end
end

puts sentence

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

int main(){
    int a,b;
    cin >> a >> b;
    int tap = (b-1) / (a-1);
    int c = (b-1) % (a-1);
    if(c>0){
        tap++;
    }

    cout << tap << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define X first
#define Y second
#define mp make_pair
using namespace std;
typedef long long ll;
const int N = 100010;
const ll INF = 1e18+10;
const int P = 1e9+7;
typedef pair<ll,ll> PLL;
int n;
ll A,B,s[N];
map<ll,int> S[2];
map<ll,int>::iterator it;
inline void add(int &x,int y){
	x=(x+y)%P;
}
int main(){
	scanf("%d",&n);
	scanf("%lld%lld",&A,&B);
	//cin>>A>>B;
	for(int i=1;i<=n;i++)scanf("%lld",s+i); 
	S[0][-INF]  =1;
	S[1][-INF]  =1;
	int now;
	for(int i=2;i<=n;i++){
		int t1 = 0,t2 = 0;
		if(S[0].begin()->X+B<=s[i]) {
			add(t1,S[0].begin()->Y);
		}
		if(S[1].begin()->X+A<=s[i]){
			add(t2,S[1].begin()->Y);
		}
		if(s[i]-A<s[i-1]){
			S[0].clear();
		}
		if(s[i]-B<s[i-1]){
			S[1].clear();
		}
		add(S[1][s[i-1]],t1);
		add(S[0][s[i-1]],t2);
		if(i<n)while(S[0].size()>1){
			it = S[0].begin();
			it++;
			if(it->X+B<=s[i+1]) {
				add(it->Y,S[0].begin()->Y);
				S[0].erase(S[0].begin());
			} else break;
		}
		if(i<n)while(S[1].size()>1){
			it = S[1].begin();
			it++;
			if(it->X+A<=s[i+1]) {
				add(it->Y,S[1].begin()->Y);
				S[1].erase(S[1].begin());
			} else break;
		}
	}
	int ans =0;
	for(it = S[0].begin();it!=S[0].end();it++) add(ans,it->Y);
	for(it = S[1].begin();it!=S[1].end();it++) add(ans,it->Y);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
typedef tuple<int,int,int> tp;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
int dp[41][501][501];
main(){
    int N,MA,MB;
    cin >> N >> MA >> MB;
    vector<int> A(N),B(N),C(N);
    rep(i,0,N)cin >> A[i] >> B[i] >> C[i];
    rep(i,0,500)rep(j,0,500)rep(k,0,N+1)dp[k][i][j] = INF;
    dp[0][0][0] = 0;
    rep(i,0,N){
        rep(j,0,500)rep(k,0,500)dp[i+1][j][k] = dp[i][j][k];
        rep(j,0,500){
            if(j + A[i] >= 500)break;
            rep(k,0,500){
                if(k + B[i] >= 500)break;
                dp[i+1][j + A[i]][k + B[i]] = min(dp[i+1][j + A[i]][k + B[i]], dp[i][j][k] + C[i]);
            }
        }
    }
    int mini = INF;
    rep(i,1,INF){
        if(i * MA >= 500 || i * MB >= 500)break;
        mini = min(mini, dp[N][i * MA][i * MB]);
    }
    cout << (mini == INF ? -1 : mini) << endl;
}

Measured memory_bytes: 40448
#include <bits/stdc++.h>
#define MAXN 1000009
#define pb push_back
#define ll long long
using namespace std;
int a[MAXN],mobius[MAXN],cnt[MAXN],mul[MAXN];
bool primes[MAXN];
vector<int> prime;

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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	mobius[1]=1;
	primes[1]=true;
	for(int i=2;i<MAXN;i++)
	{
		if(!primes[i])
		{
			mobius[i]=-1;
			prime.pb(i);
		}
		for(int j=0;(j<prime.size())&&(i*prime[j]<MAXN);j++)
		{
			primes[i*prime[j]]=true;
			if(i%prime[j]==0)
			{
				mobius[i*prime[j]]=0;
				break;
			}
			mobius[i*prime[j]]=mobius[i]*-1;
		}
	}
	ll n;
	cin>>n;
	
	
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		
		cnt[a[i]]++;
	}
	
	ll result=a[1];
	
	for(int i=2;i<=n;i++){
	    
	    result=gcd(result,a[i]);
	}
	
// 	if(result==1){
	    
// 	    cout<<"setwise coprime\n";
// 	    return 0;
// 	}
	for(int i=1;i<=1000000;i++)
	{
		for(int j=1;j*i<=1000000;j++)
		{
			mul[i]+=cnt[j*i];
		}
	}
	ll fans=0;
	for(int i=1;i<=1000000;i++)
	{
		ll tans=mul[i];
		tans=tans*(tans-1);
		tans/=2;
		fans+=(mobius[i]*tans);
	}
	ll total=n*(n-1);
	total/=2;
	
	if(total==fans)
	{
	    cout<<"pairwise coprime\n";
	}
	else if(result==1){
	    
	    cout<<"setwise coprime\n";
	    return 0;
	}
	else
	{
	    cout<<"not coprime\n";
	}
//	cout<<(total==fans);
	//cout<<fans<<endl;
}

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

int main()
{
  string n;
  cin >> n;
  if (n[0] == '7' || n[1] == '7' || n[2] == '7')
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}


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

int main(){

int a, b, c;
  cin >> a >> b >> c;
int ma = max({a, b, c});
int mi = min({a, b, c});
int md = a + b + c - ma - mi;   
  
  cout << md - mi + ma - md << endl;
return 0;
  
}

Measured memory_bytes: 256
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let a=read::<i32>();
    let b=read::<i32>();
    let c=read::<i32>();
    let mut m=a;
    if m<b{m=b}
    if m<c{m=c}
    println!("{}",a*b*c/m/2);
}

Measured memory_bytes: 4352
import sys
import itertools

input_lines = sys.stdin.read().splitlines()
N, K = [int(x) for x in input_lines[0].split(' ')]
x_grid = set()
y_grid = set()
d_grid = set()
for line in input_lines[1:]:
    x1, y1, d1, x2, y2, d2 = [int(x) for x in line.split(' ')]
    x_grid.add(x1)
    x_grid.add(x2)
    y_grid.add(y1)
    y_grid.add(y2)
    d_grid.add(d1)
    d_grid.add(d2)

x_grid = sorted(x_grid)
y_grid = sorted(y_grid)
d_grid = sorted(d_grid)
x_grid_index = {x[1]:x[0] for x in enumerate(x_grid)}
y_grid_index = {y[1]:y[0] for y in enumerate(y_grid)}
d_grid_index = {d[1]:d[0] for d in enumerate(d_grid)}

fish_dist = [[[0 for i in range(len(d_grid))] for i in range(len(y_grid))] for i in range(len(x_grid))]

for line in input_lines[1:]:
    x1, y1, d1, x2, y2, d2 = [int(x) for x in line.split(' ')]
    x1_index = x_grid_index[x1]
    x2_index = x_grid_index[x2]
    y1_index = y_grid_index[y1]
    y2_index = y_grid_index[y2]
    d1_index = d_grid_index[d1]
    d2_index = d_grid_index[d2]
    for x, y, d in itertools.product( range(x1_index, x2_index), range(y1_index, y2_index), range(d1_index, d2_index) ):
        fish_dist[x][y][d] += 1

volume = 0
for x_index, y_index, d_index in itertools.product(range(len(x_grid)), range(len(y_grid)), range(len(d_grid))):
    if fish_dist[x_index][y_index][d_index] >= K:
        x_begin = x_grid[x_index]
        y_begin = y_grid[y_index]
        d_begin = d_grid[d_index]
        x_end = x_grid[x_index + 1]
        y_end = y_grid[y_index + 1]
        d_end = d_grid[d_index + 1]
        volume += (x_end - x_begin) * (y_end - y_begin) * (d_end - d_begin)
print(volume)

Measured memory_bytes: 15796
N,M = map(int, input().split())

li = []
for i in range(1, M + 1):
    if i * i > M:
        break
    if M % i == 0:
        li.append(i)
        li.append(M // i)

ans = 1

li.sort(reverse=True)

for i in li:
    if N * i <= M:
        ans = i
        break

print(ans)


Measured memory_bytes: 3060
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left

#======================================================#

def main():
    n, a, b = MII()
    s = IS()
    maxv = a+b
    now = 0
    e_now = 0
    for si in s:
        if si == 'a':
            if now < maxv:
                print('Yes')
                now += 1
                continue
        elif si == 'b':
            if now < maxv and e_now < b:
                print('Yes')
                now += 1
                e_now += 1
                continue
        print('No')

if __name__ == '__main__':
    main()

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

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define P3(a, b, c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main(){
    int N;
    cin >> N;
    string s,first,second;
    cin >> s;
    if(s.size()%2!=0){
        P("No");
    }else{
        bool flag=true;
        REP(i,0,s.size()/2){
            if(s[i]!=s[i+s.size()/2]) flag=false;
        }
        if(flag){
            P("Yes");
        }else{
            P("No");
        }
    }
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  char a, b;
  cin >> a >> b;
  if ((a == 'H' && b == 'H') || (a == 'D' && b == 'D')) {
    cout << 'H' << '\n';
  } else {
    cout << 'D' << '\n';
  }
  return 0;
}

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

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			int sum = 0;
			for (int i = 0; i < n; i++)
				sum += scanner.nextInt();
			int[] js = new int[n - 1];
			for (int i = 0; i < n - 1; i++)
				sum += js[i] = scanner.nextInt();
			Arrays.sort(js);
			long max = sum;
			long jsum = 0;
			for (int i = 0; i < n - 1; i++) {
				jsum += js[i];
				max = Math.max(max, (i + 2) * (sum - jsum));
			}
			System.out.println(max);
		}
	}
}

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

int main(){
	long long a, b, c, d;
	long long e, f, g, h;
	
	cin >> a >> b >> c >> d;
	
	e = a*c;
	f = a*d;
	g = b*c;
	h = b*d;
	
	cout << max(max(e, f), max(h, g)) << endl;
}

Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
using namespace std;
typedef long long ll;
 
int main()
{
    int N; cin >> N;
    ll res=0;
    for(int i=1;i<=N;i++){
        if(i%3!=0 && i%5!=0) res+=i;
    }
    cout << res << endl;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) { a = b; return 1; }
  return 0; }
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) { a = b; return 1; }
  return 0; }
ll MOD = 1000000007;

int main(void){
  int x,n; cin >> x >> n;
  if(n == 0){
    cout << x << endl;
    return 0;
  }
  int p[n];
  int dif = 0;
  rep(i,n) cin >> p[i];
  while(1){
    rep(i,n){
      if(x-dif == p[i]) break;
      else if(i == n-1){
        cout << x - dif << endl;
        return 0;
      }
    }
    rep(i,n){
      if(x + dif == p[i]) break;
      else if(i == n-1){
        cout << x + dif << endl;
        return 0;
      }
    }
    dif++;
  }
  return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(b)-1;i>=(a);--i)
#define ALL(a) a.begin(),a.end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
    if (a < b) { a = b; return true; }
    return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
    if (a > b) { a = b; return true; }
    return false;
}
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "{";
    int a = 0;
    for (auto &tp : mp) {
        if (a) os << ", ";
        a = 1;
        os << tp;
    }
    return os << "}";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << p.first << ":" << p.second;
    return os;
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);


    for (;;) {
        int n, m, t, p;
        cin >> n >> m >> t >> p;
        if (n == 0) break;

        int x = 0, y = 0;

        const int MAX = 700;

        vvi S(MAX, vi(MAX, 0));
        REP(i, m) {
            REP(j, n) {
                S[i][j] = 1;
            }
        }

        REP(q, t) {
            int d, c; cin >> d >> c;
            if (d == 1) {
                for (int j = 0; j < c; ++j) {
                    REP(i, MAX) {
                        S[i][x + c + j] += S[i][x + c - 1 - j];
                        S[i][x + c - 1 - j] = 0;
                    }
                }
                x += c;
            }
            if (d == 2) {
                for (int i = 0; i < c; ++i) {
                    REP(j, MAX) {
                        S[y + c + i][j] += S[y + c - 1 - i][j];
                        S[y + c - 1 - i][j] = 0;
                    }
                }
                y += c;
            }
        }

        REP(q, p) {
            int X, Y; cin >> X >> Y;
            cout << S[Y + y][X + x] << endl;
        }
    }


    return 0;
}



Measured memory_bytes: 4676
<?php
while ($line = fgets(STDIN)) {
    $nums = array_map('intval', explode(" ", trim($line)));
    
    if ($nums[0] === 0 && $nums[1] === 0) {
        exit;
    } elseif ($nums[0] < $nums[1]) {
        echo $nums[0]." ".$nums[1].PHP_EOL;
    } else {
        echo $nums[1]." ".$nums[0].PHP_EOL;
    }
}
?>


Measured memory_bytes: 9236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1000000007;
int q[100009],w[100009];

int main(){
  int a,b;
  cin >> a >> b;
  if(500*a>=b)cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<set>

using namespace std;

int main() {
    set<string> s;
    int n;
    string p;
    cin >> n;
    while (n > 0) {
        cin >> p;
        s.insert(p);
        --n;
    }
    cout << s.size();
    return 0;
}

Measured memory_bytes: 19120
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
const int INF = 1e6;
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using P = pair<int,int>;
const ll mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    string s;
    cin >> s;
    vector<int> count(26,0);
    rep(i,s.size()){
        count[(int)(s[i] - 'a')]++;
    }
    bool check = true;
    rep(i,26){
        if(count[i]%2==1) check = false;
    }
    cout << (check ? "Yes" : "No") << endl;
}

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

#define DeltaCube23 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define minimum(a) *min_element(a.begin(), a.end())
#define maximum(a) *max_element(a.begin(), a.end())
#define MOD 1000000007
#define forf(i,a,b) for(int i = (a); i < (b); i++)
#define forr(i,a,b) for(int i = (a); i >= (b); i--)

typedef long long int lli;

using namespace std;

const int mx=1e5+5;

int main()
{
    DeltaCube23
    int t=1;
    //cin>>t;
    while(t--)
    {
        int n,a,b;
        string s;
        char ch;
        cin>>ch;
        if(ch>=65 && ch<=90)
        cout<<"A";
        else
        cout<<"a";
    }
    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define lli long long int
using namespace std;
int main()
{
	int k,a,b;
	cin>>k>>a>>b;
	int rem=a%k;
	if(rem==0)
	{
		cout<<"OK";
	}
	else
	{
		int temp=a-rem+k;
		if(temp<=b)
		{
			cout<<"OK";
		}
		else
		{
			cout<<"NG";
		}
	}
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
 
using namespace std;
using ull = unsigned long long;
using ll = long long;
using ld = long double;
using D = double;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
 
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define makeunique(x) sort(all(x)), (x).resize(unique(all(x)) - (x).begin())
#define rep(i, x)  for(int i = 0; i < (x); i++)
#define rrep(i, x) for(int i = (x - 1); i >= 0; i--)
#define sqrt(x) sqrt(abs(x))
#define y1 y1_1234413
#define j1 j1_235
#define y0 y0_235
#define j0 j0_256
#define fi first
#define se second
#define re return
#define prev PREV
#define next NEXT
#define sz(x) ((int)x.size())
#define FOR(i,a,n) for (int i=(a);i<(n);++i)
#define MEMS(a, b) memset(a, b, sizeof(a))
 
template<typename T> T sqr(T a) { re a * a; }
template<typename T> T gcd(T a, T b) { re b ? gcd(b, a % b) : a; }
template<typename T> T sgn(T a) { re a > 0 ? 1 : (a < 0 ? -1 : 0); }
template<typename T> T abs(T a) { re a > 0 ? a : -a; }
 
const int inf = 2e9;
const ld st = 0.000001;
const ld pi = acos((ld)-1);
const int MAXN = 100000;
const int mod = 1e9 + 7;
 
 
#define FILENAME ""
                    
map <ll, ll> mr;
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    //  freopen(FILENAME ".in", "r", stdin);
    //  freopen(FILENAME ".out", "w", stdout);
   	ll n, m;
   	cin >> n >> m;
   	vector <ll> dp((1 << n) + 1, inf);
   	dp[0] = 0;
   	for (int i = 0; i < m; i++) {
   	 	ll a, b;
   	 	cin >> a >> b;
   	 	ll c = 0;
   	 	for (int j = 0; j < b; j++) {
   	 		ll x;
   	 		cin >> x;
   	 		c |= (1 << (x - 1));
   	   	}
   	   	for (int j = (1 << n) - 1; ~j; j--) {
   	   	 	dp[c | j] = min(dp[c | j], dp[j] + a); 
   		}
   	} 
   	if (dp[(1 << n) - 1] >= inf) re cout << -1, 0;
    cout << dp[(1 << n) - 1];
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};

int s(int n) {
    return ceil((double)n / 10) * 10;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, y, z, k; cin >> x >> y >> z >> k;
    ll a[x]; rep(i, x) cin >> a[i]; sort(a, a + x, greater<ll>());
    ll b[y]; rep(i, y) cin >> b[i]; sort(b, b + y, greater<ll>());
    ll c[z]; rep(i, z) cin >> c[i]; sort(c, c + z, greater<ll>());
    vector<ll> v;
    rep(i, x) rep(j, y) rep(l, z) {
        if ((i + 1) * (j + 1) * (l + 1) <= k) v.push_back(a[i] + b[j] + c[l]);
    }
    sort(v.begin(), v.end(), greater<ll>());
    rep(i, k) cout << v[i] << endl;
}




Measured memory_bytes: 1528
/*
Dont BLUNDER
*/
#include<bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;


 */
#define d long double
#define int long long
#define pii pair<int,int>
#define pb push_back
#define endl '\n'
#define pi acos(-1)

#define init(x,a) memset(x,a,sizeof(x))
#define all(c) c.begin(),c.end()
int const mod1 = 998244353;
int const mod = 1000000007;
#define l first
#define r second
int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ) {stringstream ss; ss << number; return ss.str();}
#define out(x) cout<<#x<<" = "<<" "<<x<<"\n";
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define haha ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// * Using PBDS *
/*typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
               os; */



int modexp(int x, int n) {
	if (n == 0) {
		return 1;
	}
	else if (n & 1) {
		return (modexp((x * x) % mod, n / 2) % mod * x % mod) % mod;
	}
	else {
		return (modexp((x * x) % mod, n / 2) % mod);
	}
}

int modinv(int n)
{
	return modexp(n, mod - 2);
}

int gcd(int a, int b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}
bool comp(pii a, pii b) {
	return a.second < b.second;

}




signed main()
{
	haha
#ifndef ONLINE_JUDGE

	freopen("inp.txt", "r", stdin);

	freopen("out1.txt", "w", stdout);
#endif
	int h, w, m;
	cin >> h >> w >> m;
	int arr[h + 1];
	int brr[w + 1];
	init(arr, 0);
	init(brr, 0);
	set<pii> s;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		arr[a]++;
		brr[b]++;
		s.insert({a, b});
	}

	int x = *max_element(brr, brr + w + 1);
	int y = *max_element(arr, arr + h + 1);

	set<int> s1, s2;

	for (int i = 1; i <= w; i++) {
		if (brr[i] == x)
			s1.insert(i);
	}

	for (int i = 1; i <= h; i++) {
		if (arr[i] == y)
			s2.insert(i);
	}
	for (auto x1 : s1) {
		for (auto y1 : s2) {
			if (s.find({y1, x1}) == s.end())
			{
				cout << x + y << endl;
				return 0;
			}
		}
	}
	cout << x + y - 1;
















}

Measured memory_bytes: 55156
#include <iostream>

int main()
{
    int x;
    for (int i = 0; i < 10000; i++) {
        std::cin >> x;
        if (x == 0) {
            break;
        } else {
            std::cout << "Case " << (i+1) << ": " << x << std::endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3056